Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/892/?format=api
{ "id": 892, "url": "http://patchwork.ozlabs.org/api/patches/892/?format=api", "web_url": "http://patchwork.ozlabs.org/project/netdev/patch/1222098445-26175-4-git-send-email-remi.denis-courmont@nokia.com/", "project": { "id": 7, "url": "http://patchwork.ozlabs.org/api/projects/7/?format=api", "name": "Linux network development", "link_name": "netdev", "list_id": "netdev.vger.kernel.org", "list_email": "netdev@vger.kernel.org", "web_url": null, "scm_url": null, "webscm_url": null, "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<1222098445-26175-4-git-send-email-remi.denis-courmont@nokia.com>", "list_archive_url": null, "date": "2008-09-22T15:47:18", "name": "[04/11] Phonet: network device and address handling", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": true, "hash": "e53eb0b8403578089baa890c096a3115df2602d5", "submitter": { "id": 204, "url": "http://patchwork.ozlabs.org/api/people/204/?format=api", "name": "Rémi Denis-Courmont", "email": "remi.denis-courmont@nokia.com" }, "delegate": { "id": 34, "url": "http://patchwork.ozlabs.org/api/users/34/?format=api", "username": "davem", "first_name": "David", "last_name": "Miller", "email": "davem@davemloft.net" }, "mbox": "http://patchwork.ozlabs.org/project/netdev/patch/1222098445-26175-4-git-send-email-remi.denis-courmont@nokia.com/mbox/", "series": [], "comments": "http://patchwork.ozlabs.org/api/patches/892/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/892/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<netdev-owner@vger.kernel.org>", "X-Original-To": "patchwork-incoming@ozlabs.org", "Delivered-To": "patchwork-incoming@ozlabs.org", "Received": [ "from vger.kernel.org (vger.kernel.org [209.132.176.167])\n\tby ozlabs.org (Postfix) with ESMTP id BC873DDF25\n\tfor <patchwork-incoming@ozlabs.org>;\n\tTue, 23 Sep 2008 01:48:36 +1000 (EST)", "(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1753942AbYIVPsQ (ORCPT <rfc822;patchwork-incoming@ozlabs.org>);\n\tMon, 22 Sep 2008 11:48:16 -0400", "(majordomo@vger.kernel.org) by vger.kernel.org id S1753887AbYIVPsP\n\t(ORCPT <rfc822; netdev-outgoing>); Mon, 22 Sep 2008 11:48:15 -0400", "from smtp.nokia.com ([192.100.105.134]:34623 \"EHLO\n\tmgw-mx09.nokia.com\" rhost-flags-OK-OK-OK-OK) by vger.kernel.org\n\twith ESMTP id S1753419AbYIVPrn (ORCPT\n\t<rfc822;netdev@vger.kernel.org>); Mon, 22 Sep 2008 11:47:43 -0400", "from vaebh105.NOE.Nokia.com (vaebh105.europe.nokia.com\n\t[10.160.244.31])\n\tby mgw-mx09.nokia.com (Switch-3.2.6/Switch-3.2.6) with ESMTP id\n\tm8MFlIhZ008928\n\tfor <netdev@vger.kernel.org>; Mon, 22 Sep 2008 10:47:41 -0500", "from vaebh102.NOE.Nokia.com ([10.160.244.23]) by\n\tvaebh105.NOE.Nokia.com with Microsoft SMTPSVC(6.0.3790.3959); \n\tMon, 22 Sep 2008 18:47:35 +0300", "from localhost.localdomain ([172.21.41.115]) by\n\tvaebh102.NOE.Nokia.com with Microsoft SMTPSVC(6.0.3790.3959); \n\tMon, 22 Sep 2008 18:47:26 +0300" ], "From": "=?utf-8?q?R=C3=A9mi=20Denis-Courmont?= <remi.denis-courmont@nokia.com>", "To": "netdev@vger.kernel.org", "Subject": "[PATCH 04/11] Phonet: network device and address handling", "Date": "Mon, 22 Sep 2008 18:47:18 +0300", "Message-Id": "<1222098445-26175-4-git-send-email-remi.denis-courmont@nokia.com>", "X-Mailer": "git-send-email 1.5.4.3", "In-Reply-To": "<200809221845.54736.remi.denis-courmont@nokia.com>", "References": "<200809221845.54736.remi.denis-courmont@nokia.com>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=utf-8", "Content-Transfer-Encoding": "8bit", "X-OriginalArrivalTime": "22 Sep 2008 15:47:26.0366 (UTC)\n\tFILETIME=[830193E0:01C91CCA]", "X-Nokia-AV": "Clean", "Sender": "netdev-owner@vger.kernel.org", "Precedence": "bulk", "List-ID": "<netdev.vger.kernel.org>", "X-Mailing-List": "netdev@vger.kernel.org" }, "content": "This provides support for adding Phonet addresses to and removing\nPhonet addresses from network devices.\n\nSigned-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>\n---\n include/net/phonet/pn_dev.h | 50 ++++++++++\n net/phonet/Makefile | 1 +\n net/phonet/af_phonet.c | 3 +\n net/phonet/pn_dev.c | 208 +++++++++++++++++++++++++++++++++++++++++++\n 4 files changed, 262 insertions(+), 0 deletions(-)\n create mode 100644 include/net/phonet/pn_dev.h\n create mode 100644 net/phonet/pn_dev.c", "diff": "diff --git a/include/net/phonet/pn_dev.h b/include/net/phonet/pn_dev.h\nnew file mode 100644\nindex 0000000..bbd2a83\n--- /dev/null\n+++ b/include/net/phonet/pn_dev.h\n@@ -0,0 +1,50 @@\n+/*\n+ * File: pn_dev.h\n+ *\n+ * Phonet network device\n+ *\n+ * Copyright (C) 2008 Nokia Corporation.\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * version 2 as published by the Free Software Foundation.\n+ *\n+ * This program is distributed in the hope that it will be useful, but\n+ * WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ * General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n+ * 02110-1301 USA\n+ */\n+\n+#ifndef PN_DEV_H\n+#define PN_DEV_H\n+\n+struct phonet_device_list {\n+\tstruct list_head list;\n+\tspinlock_t lock;\n+};\n+\n+extern struct phonet_device_list pndevs;\n+\n+struct phonet_device {\n+\tstruct list_head list;\n+\tstruct net_device *netdev;\n+\tDECLARE_BITMAP(addrs, 64);\n+};\n+\n+void phonet_device_init(void);\n+void phonet_device_exit(void);\n+struct net_device *phonet_device_get(struct net *net);\n+\n+int phonet_address_add(struct net_device *dev, u8 addr);\n+int phonet_address_del(struct net_device *dev, u8 addr);\n+u8 phonet_address_get(struct net_device *dev, u8 addr);\n+int phonet_address_lookup(u8 addr);\n+\n+#define PN_NO_ADDR\t0xff\n+\n+#endif\ndiff --git a/net/phonet/Makefile b/net/phonet/Makefile\nindex 5dbff68..980a386 100644\n--- a/net/phonet/Makefile\n+++ b/net/phonet/Makefile\n@@ -1,4 +1,5 @@\n obj-$(CONFIG_PHONET) += phonet.o\n \n phonet-objs := \\\n+\tpn_dev.o \\\n \taf_phonet.o\ndiff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c\nindex 0cfea9b..a8ba6f1 100644\n--- a/net/phonet/af_phonet.c\n+++ b/net/phonet/af_phonet.c\n@@ -31,6 +31,7 @@\n #include <linux/if_phonet.h>\n #include <linux/phonet.h>\n #include <net/phonet/phonet.h>\n+#include <net/phonet/pn_dev.h>\n \n static struct net_proto_family phonet_proto_family;\n static struct phonet_protocol *phonet_proto_get(int protocol);\n@@ -200,6 +201,7 @@ static int __init phonet_init(void)\n \t\treturn err;\n \t}\n \n+\tphonet_device_init();\n \tdev_add_pack(&phonet_packet_type);\n \treturn 0;\n }\n@@ -208,6 +210,7 @@ static void __exit phonet_exit(void)\n {\n \tsock_unregister(AF_PHONET);\n \tdev_remove_pack(&phonet_packet_type);\n+\tphonet_device_exit();\n }\n \n module_init(phonet_init);\ndiff --git a/net/phonet/pn_dev.c b/net/phonet/pn_dev.c\nnew file mode 100644\nindex 0000000..53be9fc\n--- /dev/null\n+++ b/net/phonet/pn_dev.c\n@@ -0,0 +1,208 @@\n+/*\n+ * File: pn_dev.c\n+ *\n+ * Phonet network device\n+ *\n+ * Copyright (C) 2008 Nokia Corporation.\n+ *\n+ * Contact: Remi Denis-Courmont <remi.denis-courmont@nokia.com>\n+ * Original author: Sakari Ailus <sakari.ailus@nokia.com>\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * version 2 as published by the Free Software Foundation.\n+ *\n+ * This program is distributed in the hope that it will be useful, but\n+ * WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ * General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n+ * 02110-1301 USA\n+ */\n+\n+#include <linux/kernel.h>\n+#include <linux/net.h>\n+#include <linux/netdevice.h>\n+#include <linux/phonet.h>\n+#include <net/sock.h>\n+#include <net/phonet/pn_dev.h>\n+\n+/* when accessing, remember to lock with spin_lock(&pndevs.lock); */\n+struct phonet_device_list pndevs = {\n+\t.list = LIST_HEAD_INIT(pndevs.list),\n+\t.lock = __SPIN_LOCK_UNLOCKED(pndevs.lock),\n+};\n+\n+/* Allocate new Phonet device. */\n+static struct phonet_device *__phonet_device_alloc(struct net_device *dev)\n+{\n+\tstruct phonet_device *pnd = kmalloc(sizeof(*pnd), GFP_ATOMIC);\n+\tif (pnd == NULL)\n+\t\treturn NULL;\n+\tpnd->netdev = dev;\n+\tbitmap_zero(pnd->addrs, 64);\n+\n+\tlist_add(&pnd->list, &pndevs.list);\n+\treturn pnd;\n+}\n+\n+static struct phonet_device *__phonet_get(struct net_device *dev)\n+{\n+\tstruct phonet_device *pnd;\n+\n+\tlist_for_each_entry(pnd, &pndevs.list, list) {\n+\t\tif (pnd->netdev == dev)\n+\t\t\treturn pnd;\n+\t}\n+\treturn NULL;\n+}\n+\n+static void __phonet_device_free(struct phonet_device *pnd)\n+{\n+\tlist_del(&pnd->list);\n+\tkfree(pnd);\n+}\n+\n+struct net_device *phonet_device_get(struct net *net)\n+{\n+\tstruct phonet_device *pnd;\n+\tstruct net_device *dev;\n+\n+\tspin_lock_bh(&pndevs.lock);\n+\tlist_for_each_entry(pnd, &pndevs.list, list) {\n+\t\tdev = pnd->netdev;\n+\t\tBUG_ON(!dev);\n+\n+\t\tif (dev_net(dev) == net &&\n+\t\t\t(dev->reg_state == NETREG_REGISTERED) &&\n+\t\t\t((pnd->netdev->flags & IFF_UP)) == IFF_UP)\n+\t\t\tbreak;\n+\t\tdev = NULL;\n+\t}\n+\tif (dev)\n+\t\tdev_hold(dev);\n+\tspin_unlock_bh(&pndevs.lock);\n+\treturn dev;\n+}\n+\n+int phonet_address_add(struct net_device *dev, u8 addr)\n+{\n+\tstruct phonet_device *pnd;\n+\tint err = 0;\n+\n+\tspin_lock_bh(&pndevs.lock);\n+\t/* Find or create Phonet-specific device data */\n+\tpnd = __phonet_get(dev);\n+\tif (pnd == NULL)\n+\t\tpnd = __phonet_device_alloc(dev);\n+\tif (unlikely(pnd == NULL))\n+\t\terr = -ENOMEM;\n+\telse if (test_and_set_bit(addr >> 2, pnd->addrs))\n+\t\terr = -EEXIST;\n+\tspin_unlock_bh(&pndevs.lock);\n+\treturn err;\n+}\n+\n+int phonet_address_del(struct net_device *dev, u8 addr)\n+{\n+\tstruct phonet_device *pnd;\n+\tint err = 0;\n+\n+\tspin_lock_bh(&pndevs.lock);\n+\tpnd = __phonet_get(dev);\n+\tif (!pnd || !test_and_clear_bit(addr >> 2, pnd->addrs))\n+\t\terr = -EADDRNOTAVAIL;\n+\tif (bitmap_empty(pnd->addrs, 64))\n+\t\t__phonet_device_free(pnd);\n+\tspin_unlock_bh(&pndevs.lock);\n+\treturn err;\n+}\n+\n+/* Gets a source address toward a destination, through a interface. */\n+u8 phonet_address_get(struct net_device *dev, u8 addr)\n+{\n+\tstruct phonet_device *pnd;\n+\n+\tspin_lock_bh(&pndevs.lock);\n+\tpnd = __phonet_get(dev);\n+\tif (pnd) {\n+\t\tBUG_ON(bitmap_empty(pnd->addrs, 64));\n+\n+\t\t/* Use same source address as destination, if possible */\n+\t\tif (!test_bit(addr >> 2, pnd->addrs))\n+\t\t\taddr = find_first_bit(pnd->addrs, 64) << 2;\n+\t} else\n+\t\taddr = PN_NO_ADDR;\n+\tspin_unlock_bh(&pndevs.lock);\n+\treturn addr;\n+}\n+\n+int phonet_address_lookup(u8 addr)\n+{\n+\tstruct phonet_device *pnd;\n+\n+\tspin_lock_bh(&pndevs.lock);\n+\tlist_for_each_entry(pnd, &pndevs.list, list) {\n+\t\t/* Don't allow unregistering devices! */\n+\t\tif ((pnd->netdev->reg_state != NETREG_REGISTERED) ||\n+\t\t\t\t((pnd->netdev->flags & IFF_UP)) != IFF_UP)\n+\t\t\tcontinue;\n+\n+\t\tif (test_bit(addr >> 2, pnd->addrs)) {\n+\t\t\tspin_unlock_bh(&pndevs.lock);\n+\t\t\treturn 0;\n+\t\t}\n+\t}\n+\tspin_unlock_bh(&pndevs.lock);\n+\treturn -EADDRNOTAVAIL;\n+}\n+\n+/* notify Phonet of device events */\n+static int phonet_device_notify(struct notifier_block *me, unsigned long what,\n+\t\t\t\tvoid *arg)\n+{\n+\tstruct net_device *dev = arg;\n+\n+\tif (what == NETDEV_UNREGISTER) {\n+\t\tstruct phonet_device *pnd;\n+\n+\t\t/* Destroy phonet-specific device data */\n+\t\tspin_lock_bh(&pndevs.lock);\n+\t\tpnd = __phonet_get(dev);\n+\t\tif (pnd)\n+\t\t\t__phonet_device_free(pnd);\n+\t\tspin_unlock_bh(&pndevs.lock);\n+\t}\n+\treturn 0;\n+\n+}\n+\n+static struct notifier_block phonet_device_notifier = {\n+\t.notifier_call = phonet_device_notify,\n+\t.priority = 0,\n+};\n+\n+/* Initialize Phonet devices list */\n+void phonet_device_init(void)\n+{\n+\tregister_netdevice_notifier(&phonet_device_notifier);\n+}\n+\n+void phonet_device_exit(void)\n+{\n+\tstruct phonet_device *pnd, *n;\n+\n+\trtnl_unregister_all(PF_PHONET);\n+\trtnl_lock();\n+\tspin_lock_bh(&pndevs.lock);\n+\n+\tlist_for_each_entry_safe(pnd, n, &pndevs.list, list)\n+\t\t__phonet_device_free(pnd);\n+\n+\tspin_unlock_bh(&pndevs.lock);\n+\trtnl_unlock();\n+\tunregister_netdevice_notifier(&phonet_device_notifier);\n+}\n", "prefixes": [ "04/11" ] }