Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/885/?format=api
{ "id": 885, "url": "http://patchwork.ozlabs.org/api/patches/885/?format=api", "web_url": "http://patchwork.ozlabs.org/project/netdev/patch/1222098445-26175-5-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-5-git-send-email-remi.denis-courmont@nokia.com>", "list_archive_url": null, "date": "2008-09-22T15:47:19", "name": "[05/11] Phonet: Netlink interface", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": true, "hash": "b0a67985ae4cf962f5a3141c1732a0401811c347", "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-5-git-send-email-remi.denis-courmont@nokia.com/mbox/", "series": [], "comments": "http://patchwork.ozlabs.org/api/patches/885/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/885/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 480E2DDF35\n\tfor <patchwork-incoming@ozlabs.org>;\n\tTue, 23 Sep 2008 01:48:30 +1000 (EST)", "(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1753609AbYIVPrs (ORCPT <rfc822;patchwork-incoming@ozlabs.org>);\n\tMon, 22 Sep 2008 11:47:48 -0400", "(majordomo@vger.kernel.org) by vger.kernel.org id S1753573AbYIVPrr\n\t(ORCPT <rfc822; netdev-outgoing>); Mon, 22 Sep 2008 11:47:47 -0400", "from smtp.nokia.com ([192.100.122.233]:53001 \"EHLO\n\tmgw-mx06.nokia.com\" rhost-flags-OK-OK-OK-OK) by vger.kernel.org\n\twith ESMTP id S1753412AbYIVPro (ORCPT\n\t<rfc822;netdev@vger.kernel.org>); Mon, 22 Sep 2008 11:47:44 -0400", "from vaebh105.NOE.Nokia.com (vaebh105.europe.nokia.com\n\t[10.160.244.31])\n\tby mgw-mx06.nokia.com (Switch-3.2.6/Switch-3.2.6) with ESMTP id\n\tm8MFlZFX027641\n\tfor <netdev@vger.kernel.org>; Mon, 22 Sep 2008 18:47:41 +0300", "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 05/11] Phonet: Netlink interface", "Date": "Mon, 22 Sep 2008 18:47:19 +0300", "Message-Id": "<1222098445-26175-5-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>", "X-OriginalArrivalTime": "22 Sep 2008 15:47:26.0600 (UTC)\n\tFILETIME=[83254880: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 configuring Phonet addresses, notifying\nPhonet configuration changes, and dumping the configuration.\n\nSigned-off-by: Remi Denis-Courmont <remi.denis-courmont@nokia.com>\n---\n include/net/phonet/phonet.h | 1 +\n net/phonet/Makefile | 1 +\n net/phonet/af_phonet.c | 1 +\n net/phonet/pn_netlink.c | 186 +++++++++++++++++++++++++++++++++++++++++++\n 4 files changed, 189 insertions(+), 0 deletions(-)\n create mode 100644 net/phonet/pn_netlink.c", "diff": "diff --git a/include/net/phonet/phonet.h b/include/net/phonet/phonet.h\nindex c53f2ab..8b77794 100644\n--- a/include/net/phonet/phonet.h\n+++ b/include/net/phonet/phonet.h\n@@ -71,4 +71,5 @@ struct phonet_protocol {\n int phonet_proto_register(int protocol, struct phonet_protocol *pp);\n void phonet_proto_unregister(int protocol, struct phonet_protocol *pp);\n \n+void phonet_netlink_register(void);\n #endif\ndiff --git a/net/phonet/Makefile b/net/phonet/Makefile\nindex 980a386..4143c3e 100644\n--- a/net/phonet/Makefile\n+++ b/net/phonet/Makefile\n@@ -2,4 +2,5 @@ obj-$(CONFIG_PHONET) += phonet.o\n \n phonet-objs := \\\n \tpn_dev.o \\\n+\tpn_netlink.o \\\n \taf_phonet.o\ndiff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c\nindex a8ba6f1..5c729ba 100644\n--- a/net/phonet/af_phonet.c\n+++ b/net/phonet/af_phonet.c\n@@ -203,6 +203,7 @@ static int __init phonet_init(void)\n \n \tphonet_device_init();\n \tdev_add_pack(&phonet_packet_type);\n+\tphonet_netlink_register();\n \treturn 0;\n }\n \ndiff --git a/net/phonet/pn_netlink.c b/net/phonet/pn_netlink.c\nnew file mode 100644\nindex 0000000..b1ea19a\n--- /dev/null\n+++ b/net/phonet/pn_netlink.c\n@@ -0,0 +1,186 @@\n+/*\n+ * File: pn_netlink.c\n+ *\n+ * Phonet netlink interface\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/netlink.h>\n+#include <linux/phonet.h>\n+#include <net/sock.h>\n+#include <net/phonet/pn_dev.h>\n+\n+static int fill_addr(struct sk_buff *skb, struct net_device *dev, u8 addr,\n+\t\t u32 pid, u32 seq, int event);\n+\n+static void rtmsg_notify(int event, struct net_device *dev, u8 addr)\n+{\n+\tstruct sk_buff *skb;\n+\tint err = -ENOBUFS;\n+\n+\tskb = nlmsg_new(NLMSG_ALIGN(sizeof(struct ifaddrmsg)) +\n+\t\t\tnla_total_size(1), GFP_KERNEL);\n+\tif (skb == NULL)\n+\t\tgoto errout;\n+\terr = fill_addr(skb, dev, addr, 0, 0, event);\n+\tif (err < 0) {\n+\t\tWARN_ON(err == -EMSGSIZE);\n+\t\tkfree_skb(skb);\n+\t\tgoto errout;\n+\t}\n+\terr = rtnl_notify(skb, dev_net(dev), 0,\n+\t\t\t RTNLGRP_PHONET_IFADDR, NULL, GFP_KERNEL);\n+errout:\n+\tif (err < 0)\n+\t\trtnl_set_sk_err(dev_net(dev), RTNLGRP_PHONET_IFADDR, err);\n+}\n+\n+static int newaddr_doit(struct sk_buff *skb, struct nlmsghdr *nlm, void *attr)\n+{\n+\tstruct rtattr **rta = attr;\n+\tstruct ifaddrmsg *ifm = NLMSG_DATA(nlm);\n+\tstruct net_device *dev;\n+\tint err;\n+\tu8 pnaddr;\n+\n+\tif (!capable(CAP_SYS_ADMIN))\n+\t\treturn -EPERM;\n+\n+\tASSERT_RTNL();\n+\n+\tif (rta[IFA_LOCAL - 1] == NULL)\n+\t\treturn -EINVAL;\n+\n+\tdev = __dev_get_by_index(&init_net, ifm->ifa_index);\n+\tif (dev == NULL)\n+\t\treturn -ENODEV;\n+\n+\tif (ifm->ifa_prefixlen > 0)\n+\t\treturn -EINVAL;\n+\n+\tmemcpy(&pnaddr, RTA_DATA(rta[IFA_LOCAL - 1]), 1);\n+\n+\terr = phonet_address_add(dev, pnaddr);\n+\tif (!err)\n+\t\trtmsg_notify(RTM_NEWADDR, dev, pnaddr);\n+\treturn err;\n+}\n+\n+static int deladdr_doit(struct sk_buff *skb, struct nlmsghdr *nlm, void *attr)\n+{\n+\tstruct rtattr **rta = attr;\n+\tstruct ifaddrmsg *ifm = NLMSG_DATA(nlm);\n+\tstruct net_device *dev;\n+\tint err;\n+\tu8 pnaddr;\n+\n+\tif (!capable(CAP_SYS_ADMIN))\n+\t\treturn -EPERM;\n+\n+\tASSERT_RTNL();\n+\n+\tif (rta[IFA_LOCAL - 1] == NULL)\n+\t\treturn -EINVAL;\n+\n+\tdev = __dev_get_by_index(&init_net, ifm->ifa_index);\n+\tif (dev == NULL)\n+\t\treturn -ENODEV;\n+\n+\tif (ifm->ifa_prefixlen > 0)\n+\t\treturn -EADDRNOTAVAIL;\n+\n+\tmemcpy(&pnaddr, RTA_DATA(rta[IFA_LOCAL - 1]), 1);\n+\n+\terr = phonet_address_del(dev, pnaddr);\n+\tif (!err)\n+\t\trtmsg_notify(RTM_DELADDR, dev, pnaddr);\n+\treturn err;\n+}\n+\n+static int fill_addr(struct sk_buff *skb, struct net_device *dev, u8 addr,\n+\t\t\tu32 pid, u32 seq, int event)\n+{\n+\tstruct ifaddrmsg *ifm;\n+\tstruct nlmsghdr *nlh;\n+\tunsigned int orig_len = skb->len;\n+\n+\tnlh = NLMSG_PUT(skb, pid, seq, event, sizeof(struct ifaddrmsg));\n+\tifm = NLMSG_DATA(nlh);\n+\tifm->ifa_family = AF_PHONET;\n+\tifm->ifa_prefixlen = 0;\n+\tifm->ifa_flags = IFA_F_PERMANENT;\n+\tifm->ifa_scope = RT_SCOPE_HOST;\n+\tifm->ifa_index = dev->ifindex;\n+\tRTA_PUT(skb, IFA_LOCAL, 1, &addr);\n+\tnlh->nlmsg_len = skb->len - orig_len;\n+\n+\treturn 0;\n+\n+nlmsg_failure:\n+rtattr_failure:\n+\tskb_trim(skb, orig_len);\n+\n+\treturn -1;\n+}\n+\n+static int getaddr_dumpit(struct sk_buff *skb, struct netlink_callback *cb)\n+{\n+\tstruct phonet_device *pnd;\n+\tint dev_idx = 0, dev_start_idx = cb->args[0];\n+\tint addr_idx = 0, addr_start_idx = cb->args[1];\n+\n+\tspin_lock_bh(&pndevs.lock);\n+\tlist_for_each_entry(pnd, &pndevs.list, list) {\n+\t\tu8 addr;\n+\n+\t\tif (dev_idx > dev_start_idx)\n+\t\t\taddr_start_idx = 0;\n+\t\tif (dev_idx++ < dev_start_idx)\n+\t\t\tcontinue;\n+\n+\t\taddr_idx = 0;\n+\t\tfor (addr = find_first_bit(pnd->addrs, 64); addr < 64;\n+\t\t\taddr = find_next_bit(pnd->addrs, 64, 1+addr)) {\n+\t\t\tif (addr_idx++ < addr_start_idx)\n+\t\t\t\tcontinue;\n+\n+\t\t\tif (fill_addr(skb, pnd->netdev, addr << 2,\n+\t\t\t\t\t NETLINK_CB(cb->skb).pid,\n+\t\t\t\t\tcb->nlh->nlmsg_seq, RTM_NEWADDR))\n+\t\t\t\tgoto out;\n+\t\t}\n+\t}\n+\n+out:\n+\tspin_unlock_bh(&pndevs.lock);\n+\tcb->args[0] = dev_idx;\n+\tcb->args[1] = addr_idx;\n+\n+\treturn skb->len;\n+}\n+\n+void __init phonet_netlink_register(void)\n+{\n+\trtnl_register(PF_PHONET, RTM_NEWADDR, newaddr_doit, NULL);\n+\trtnl_register(PF_PHONET, RTM_DELADDR, deladdr_doit, NULL);\n+\trtnl_register(PF_PHONET, RTM_GETADDR, NULL, getaddr_dumpit);\n+}\n", "prefixes": [ "05/11" ] }