Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/882/?format=api
{ "id": 882, "url": "http://patchwork.ozlabs.org/api/patches/882/?format=api", "web_url": "http://patchwork.ozlabs.org/project/netdev/patch/1222098445-26175-2-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-2-git-send-email-remi.denis-courmont@nokia.com>", "list_archive_url": null, "date": "2008-09-22T15:47:16", "name": "[02/11] Phonet: PF_PHONET protocol family support", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": true, "hash": "fc6c5b195c3000b10b7b160aa94ba1aa85d2c622", "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-2-git-send-email-remi.denis-courmont@nokia.com/mbox/", "series": [], "comments": "http://patchwork.ozlabs.org/api/patches/882/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/882/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 6C3F8DDF0C\n\tfor <patchwork-incoming@ozlabs.org>;\n\tTue, 23 Sep 2008 01:47:49 +1000 (EST)", "(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1753337AbYIVPrm (ORCPT <rfc822;patchwork-incoming@ozlabs.org>);\n\tMon, 22 Sep 2008 11:47:42 -0400", "(majordomo@vger.kernel.org) by vger.kernel.org id S1753272AbYIVPrm\n\t(ORCPT <rfc822; netdev-outgoing>); Mon, 22 Sep 2008 11:47:42 -0400", "from smtp.nokia.com ([192.100.122.233]:52997 \"EHLO\n\tmgw-mx06.nokia.com\" rhost-flags-OK-OK-OK-OK) by vger.kernel.org\n\twith ESMTP id S1753159AbYIVPrl (ORCPT\n\t<rfc822;netdev@vger.kernel.org>); Mon, 22 Sep 2008 11:47:41 -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\tm8MFlZFT027641\n\tfor <netdev@vger.kernel.org>; Mon, 22 Sep 2008 18:47:39 +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 02/11] Phonet: PF_PHONET protocol family support", "Date": "Mon, 22 Sep 2008 18:47:16 +0300", "Message-Id": "<1222098445-26175-2-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.0272 (UTC)\n\tFILETIME=[82F33C00: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 is the basis for the Phonet protocol families, and introduces\nthe ETH_P_PHONET packet type and the PF_PHONET socket family.\n\nSigned-off-by: Remi Denis-Courmont <remi.denis-courmont@nokia.com>\n---\n include/net/phonet/phonet.h | 74 +++++++++++++++\n net/phonet/af_phonet.c | 216 +++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 290 insertions(+), 0 deletions(-)\n create mode 100644 include/net/phonet/phonet.h\n create mode 100644 net/phonet/af_phonet.c", "diff": "diff --git a/include/net/phonet/phonet.h b/include/net/phonet/phonet.h\nnew file mode 100644\nindex 0000000..c53f2ab\n--- /dev/null\n+++ b/include/net/phonet/phonet.h\n@@ -0,0 +1,74 @@\n+/*\n+ * File: af_phonet.h\n+ *\n+ * Phonet sockets kernel definitions\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 AF_PHONET_H\n+#define AF_PHONET_H\n+\n+/*\n+ * The lower layers may not require more space, ever. Make sure it's\n+ * enough.\n+ */\n+#define MAX_PHONET_HEADER\t8\n+\n+static inline struct phonethdr *pn_hdr(struct sk_buff *skb)\n+{\n+\treturn (struct phonethdr *)skb_network_header(skb);\n+}\n+\n+/*\n+ * Get the other party's sockaddr from received skb. The skb begins\n+ * with a Phonet header.\n+ */\n+static inline\n+void pn_skb_get_src_sockaddr(struct sk_buff *skb, struct sockaddr_pn *sa)\n+{\n+\tstruct phonethdr *ph = pn_hdr(skb);\n+\tu16 obj = pn_object(ph->pn_sdev, ph->pn_sobj);\n+\n+\tsa->spn_family = AF_PHONET;\n+\tpn_sockaddr_set_object(sa, obj);\n+\tpn_sockaddr_set_resource(sa, ph->pn_res);\n+\tmemset(sa->spn_zero, 0, sizeof(sa->spn_zero));\n+}\n+\n+static inline\n+void pn_skb_get_dst_sockaddr(struct sk_buff *skb, struct sockaddr_pn *sa)\n+{\n+\tstruct phonethdr *ph = pn_hdr(skb);\n+\tu16 obj = pn_object(ph->pn_rdev, ph->pn_robj);\n+\n+\tsa->spn_family = AF_PHONET;\n+\tpn_sockaddr_set_object(sa, obj);\n+\tpn_sockaddr_set_resource(sa, ph->pn_res);\n+\tmemset(sa->spn_zero, 0, sizeof(sa->spn_zero));\n+}\n+\n+/* Protocols in Phonet protocol family. */\n+struct phonet_protocol {\n+\tstruct proto\t\t*prot;\n+\tint\t\t\tsock_type;\n+};\n+\n+int phonet_proto_register(int protocol, struct phonet_protocol *pp);\n+void phonet_proto_unregister(int protocol, struct phonet_protocol *pp);\n+\n+#endif\ndiff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c\nnew file mode 100644\nindex 0000000..0cfea9b\n--- /dev/null\n+++ b/net/phonet/af_phonet.c\n@@ -0,0 +1,216 @@\n+/*\n+ * File: af_phonet.c\n+ *\n+ * Phonet protocols family\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/module.h>\n+#include <asm/unaligned.h>\n+#include <net/sock.h>\n+\n+#include <linux/if_phonet.h>\n+#include <linux/phonet.h>\n+#include <net/phonet/phonet.h>\n+\n+static struct net_proto_family phonet_proto_family;\n+static struct phonet_protocol *phonet_proto_get(int protocol);\n+static inline void phonet_proto_put(struct phonet_protocol *pp);\n+\n+/* protocol family functions */\n+\n+static int pn_socket_create(struct net *net, struct socket *sock, int protocol)\n+{\n+\tstruct phonet_protocol *pnp;\n+\tint err;\n+\n+\tif (net != &init_net)\n+\t\treturn -EAFNOSUPPORT;\n+\n+\tif (!capable(CAP_SYS_ADMIN))\n+\t\treturn -EPERM;\n+\n+\tif (protocol == 0) {\n+\t\t/* Default protocol selection */\n+\t\tswitch (sock->type) {\n+\t\tcase SOCK_DGRAM:\n+\t\t\tprotocol = PN_PROTO_PHONET;\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\treturn -EPROTONOSUPPORT;\n+\t\t}\n+\t}\n+\n+\tpnp = phonet_proto_get(protocol);\n+\tif (pnp == NULL)\n+\t\treturn -EPROTONOSUPPORT;\n+\tif (sock->type != pnp->sock_type) {\n+\t\terr = -EPROTONOSUPPORT;\n+\t\tgoto out;\n+\t}\n+\n+\t/* TODO: create and init the struct sock */\n+\terr = -EPROTONOSUPPORT;\n+\n+out:\n+\tphonet_proto_put(pnp);\n+\treturn err;\n+}\n+\n+static struct net_proto_family phonet_proto_family = {\n+\t.family = AF_PHONET,\n+\t.create = pn_socket_create,\n+\t.owner = THIS_MODULE,\n+};\n+\n+/* packet type functions */\n+\n+/*\n+ * Stuff received packets to associated sockets.\n+ * On error, returns non-zero and releases the skb.\n+ */\n+static int phonet_rcv(struct sk_buff *skb, struct net_device *dev,\n+\t\t\tstruct packet_type *pkttype,\n+\t\t\tstruct net_device *orig_dev)\n+{\n+\tstruct phonethdr *ph;\n+\tstruct sockaddr_pn sa;\n+\tu16 len;\n+\n+\tif (dev_net(dev) != &init_net)\n+\t\tgoto out;\n+\n+\t/* check we have at least a full Phonet header */\n+\tif (!pskb_pull(skb, sizeof(struct phonethdr)))\n+\t\tgoto out;\n+\n+\t/* check that the advertised length is correct */\n+\tph = pn_hdr(skb);\n+\tlen = get_unaligned_be16(&ph->pn_length);\n+\tif (len < 2)\n+\t\tgoto out;\n+\tlen -= 2;\n+\tif ((len > skb->len) || pskb_trim(skb, len))\n+\t\tgoto out;\n+\tskb_reset_transport_header(skb);\n+\n+\tpn_skb_get_dst_sockaddr(skb, &sa);\n+\tif (pn_sockaddr_get_addr(&sa) == 0)\n+\t\tgoto out; /* currently, we cannot be device 0 */\n+\n+\t/* TODO: put packets to sockets backlog */\n+\n+out:\n+\tkfree_skb(skb);\n+\treturn NET_RX_DROP;\n+}\n+\n+static struct packet_type phonet_packet_type = {\n+\t.type = __constant_htons(ETH_P_PHONET),\n+\t.dev = NULL,\n+\t.func = phonet_rcv,\n+};\n+\n+/* Transport protocol registration */\n+static struct phonet_protocol *proto_tab[PHONET_NPROTO] __read_mostly;\n+static DEFINE_SPINLOCK(proto_tab_lock);\n+\n+int __init_or_module phonet_proto_register(int protocol,\n+\t\t\t\t\t\tstruct phonet_protocol *pp)\n+{\n+\tint err = 0;\n+\n+\tif (protocol >= PHONET_NPROTO)\n+\t\treturn -EINVAL;\n+\n+\terr = proto_register(pp->prot, 1);\n+\tif (err)\n+\t\treturn err;\n+\n+\tspin_lock(&proto_tab_lock);\n+\tif (proto_tab[protocol])\n+\t\terr = -EBUSY;\n+\telse\n+\t\tproto_tab[protocol] = pp;\n+\tspin_unlock(&proto_tab_lock);\n+\n+\treturn err;\n+}\n+EXPORT_SYMBOL(phonet_proto_register);\n+\n+void phonet_proto_unregister(int protocol, struct phonet_protocol *pp)\n+{\n+\tspin_lock(&proto_tab_lock);\n+\tBUG_ON(proto_tab[protocol] != pp);\n+\tproto_tab[protocol] = NULL;\n+\tspin_unlock(&proto_tab_lock);\n+\tproto_unregister(pp->prot);\n+}\n+EXPORT_SYMBOL(phonet_proto_unregister);\n+\n+static struct phonet_protocol *phonet_proto_get(int protocol)\n+{\n+\tstruct phonet_protocol *pp;\n+\n+\tif (protocol >= PHONET_NPROTO)\n+\t\treturn NULL;\n+\n+\tspin_lock(&proto_tab_lock);\n+\tpp = proto_tab[protocol];\n+\tif (pp && !try_module_get(pp->prot->owner))\n+\t\tpp = NULL;\n+\tspin_unlock(&proto_tab_lock);\n+\n+\treturn pp;\n+}\n+\n+static inline void phonet_proto_put(struct phonet_protocol *pp)\n+{\n+\tmodule_put(pp->prot->owner);\n+}\n+\n+/* Module registration */\n+static int __init phonet_init(void)\n+{\n+\tint err;\n+\n+\terr = sock_register(&phonet_proto_family);\n+\tif (err) {\n+\t\tprintk(KERN_ALERT\n+\t\t\t\"phonet protocol family initialization failed\\n\");\n+\t\treturn err;\n+\t}\n+\n+\tdev_add_pack(&phonet_packet_type);\n+\treturn 0;\n+}\n+\n+static void __exit phonet_exit(void)\n+{\n+\tsock_unregister(AF_PHONET);\n+\tdev_remove_pack(&phonet_packet_type);\n+}\n+\n+module_init(phonet_init);\n+module_exit(phonet_exit);\n+MODULE_DESCRIPTION(\"Phonet protocol stack for Linux\");\n+MODULE_LICENSE(\"GPL\");\n", "prefixes": [ "02/11" ] }