Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/996/?format=api
{ "id": 996, "url": "http://patchwork.ozlabs.org/api/patches/996/?format=api", "web_url": "http://patchwork.ozlabs.org/project/netdev/patch/20080922174346.2ad15d26@extreme/", "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": "<20080922174346.2ad15d26@extreme>", "list_archive_url": null, "date": "2008-09-23T00:43:46", "name": "net: network device name ifalias support", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": true, "hash": "c011624dc44c5afcb2ef064fa33780f83f76e0ab", "submitter": { "id": 423, "url": "http://patchwork.ozlabs.org/api/people/423/?format=api", "name": "stephen hemminger", "email": "shemminger@vyatta.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/20080922174346.2ad15d26@extreme/mbox/", "series": [], "comments": "http://patchwork.ozlabs.org/api/patches/996/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/996/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 2FFAADDEED\n\tfor <patchwork-incoming@ozlabs.org>;\n\tTue, 23 Sep 2008 10:43:54 +1000 (EST)", "(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1753603AbYIWAnt (ORCPT <rfc822;patchwork-incoming@ozlabs.org>);\n\tMon, 22 Sep 2008 20:43:49 -0400", "(majordomo@vger.kernel.org) by vger.kernel.org id S1753556AbYIWAnt\n\t(ORCPT <rfc822; netdev-outgoing>); Mon, 22 Sep 2008 20:43:49 -0400", "from mail.vyatta.com ([76.74.103.46]:44209 \"EHLO mail.vyatta.com\"\n\trhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP\n\tid S1753496AbYIWAns (ORCPT <rfc822;netdev@vger.kernel.org>);\n\tMon, 22 Sep 2008 20:43:48 -0400", "from localhost (localhost.localdomain [127.0.0.1])\n\tby mail.vyatta.com (Postfix) with ESMTP id 9DB0A4F46E3;\n\tMon, 22 Sep 2008 17:43:47 -0700 (PDT)", "from mail.vyatta.com ([127.0.0.1])\n\tby localhost (mail.vyatta.com [127.0.0.1]) (amavisd-new, port 10024)\n\twith ESMTP id kSaVkjgADNhS; Mon, 22 Sep 2008 17:43:47 -0700 (PDT)", "from extreme (pool-71-182-88-81.ptldor.fios.verizon.net\n\t[71.182.88.81])\n\tby mail.vyatta.com (Postfix) with ESMTP id 291674F46C0;\n\tMon, 22 Sep 2008 17:43:47 -0700 (PDT)" ], "X-Virus-Scanned": "amavisd-new at ", "Date": "Mon, 22 Sep 2008 17:43:46 -0700", "From": "Stephen Hemminger <shemminger@vyatta.com>", "To": "David Miller <davem@davemloft.net>", "Cc": "netdev@vger.kernel.org", "Subject": "[PATCH] net: network device name ifalias support", "Message-ID": "<20080922174346.2ad15d26@extreme>", "Organization": "Vyatta", "X-Mailer": "Claws Mail 3.3.1 (GTK+ 2.12.9; x86_64-pc-linux-gnu)", "Mime-Version": "1.0", "Content-Type": "text/plain; charset=US-ASCII", "Content-Transfer-Encoding": "7bit", "Sender": "netdev-owner@vger.kernel.org", "Precedence": "bulk", "List-ID": "<netdev.vger.kernel.org>", "X-Mailing-List": "netdev@vger.kernel.org" }, "content": "This patch add support for keeping an additional character alias associated with\nan network interface. This is useful for maintaining the SNMP ifAlias value\nwhich is a user defined value. Routers use this to hold information like which\ncircuit or line it is connected to. It is just an arbitrary text label\non the network device.\n\nThere are two exposed interfaces with this patch, the value can be read/written\neither via netlink or sysfs.\n\nThis could be maintained just by the snmp daemon, but it is more generally\nuseful for other management tools, and the kernel is good place to act as\nan agreed upon interface to store it.\n\nSigned-off-by: Stephen Hemminger <shemminger@vyatta.com>\n\n---\nNote: this is not IP alias which is something completely different.\n\n\n--\nTo unsubscribe from this list: send the line \"unsubscribe netdev\" in\nthe body of a message to majordomo@vger.kernel.org\nMore majordomo info at http://vger.kernel.org/majordomo-info.html", "diff": "--- a/include/linux/if.h\t2008-09-22 11:54:10.000000000 -0700\n+++ b/include/linux/if.h\t2008-09-22 16:22:24.000000000 -0700\n@@ -24,6 +24,7 @@\n #include <linux/compiler.h>\t\t/* for \"__user\" et al */\n \n #define\tIFNAMSIZ\t16\n+#define\tIFALIASZ\t256\n #include <linux/hdlc/ioctl.h>\n \n /* Standard interface flags (netdevice->flags). */\n--- a/include/linux/if_link.h\t2008-09-22 11:50:28.000000000 -0700\n+++ b/include/linux/if_link.h\t2008-09-22 11:54:32.000000000 -0700\n@@ -79,6 +79,7 @@ enum\n \tIFLA_LINKINFO,\n #define IFLA_LINKINFO IFLA_LINKINFO\n \tIFLA_NET_NS_PID,\n+\tIFLA_IFALIAS,\n \t__IFLA_MAX\n };\n \n--- a/include/linux/netdevice.h\t2008-09-22 11:46:10.000000000 -0700\n+++ b/include/linux/netdevice.h\t2008-09-22 16:04:24.000000000 -0700\n@@ -471,6 +471,8 @@ struct net_device\n \tchar\t\t\tname[IFNAMSIZ];\n \t/* device name hash chain */\n \tstruct hlist_node\tname_hlist;\n+\t/* snmp alias */\n+\tchar \t\t\t*ifalias;\n \n \t/*\n \t *\tI/O specific fields\n@@ -1224,6 +1226,7 @@ extern int\t\tdev_ethtool(struct net *net,\n extern unsigned\t\tdev_get_flags(const struct net_device *);\n extern int\t\tdev_change_flags(struct net_device *, unsigned);\n extern int\t\tdev_change_name(struct net_device *, char *);\n+extern int\t\tdev_set_alias(struct net_device *, const char *, size_t);\n extern int\t\tdev_change_net_namespace(struct net_device *,\n \t\t\t\t\t\t struct net *, const char *);\n extern int\t\tdev_set_mtu(struct net_device *, int);\n--- a/net/core/dev.c\t2008-09-22 11:58:17.000000000 -0700\n+++ b/net/core/dev.c\t2008-09-22 17:26:57.000000000 -0700\n@@ -954,6 +954,29 @@ rollback:\n }\n \n /**\n+ *\tdev_set_alias - change ifalias of a device\n+ *\t@dev: device\n+ *\t@alias: name up to IFALIASZ\n+ *\n+ *\tSet ifalias for a device,\n+ */\n+int dev_set_alias(struct net_device *dev, const char *alias, size_t len)\n+{\n+\tASSERT_RTNL();\n+\n+\tif (len >= IFALIASZ)\n+\t\treturn -EINVAL;\n+\n+\tdev->ifalias = krealloc(dev->ifalias, len+1, GFP_KERNEL);\n+\tif (!dev->ifalias)\n+\t\treturn -ENOMEM;\n+\n+\tstrlcpy(dev->ifalias, alias, len+1);\n+\treturn len;\n+}\n+\n+\n+/**\n *\tnetdev_features_change - device changes features\n *\t@dev: device to cause notification\n *\n--- a/net/core/net-sysfs.c\t2008-09-22 12:03:34.000000000 -0700\n+++ b/net/core/net-sysfs.c\t2008-09-22 17:27:14.000000000 -0700\n@@ -209,9 +209,44 @@ static ssize_t store_tx_queue_len(struct\n \treturn netdev_store(dev, attr, buf, len, change_tx_queue_len);\n }\n \n+static ssize_t store_ifalias(struct device *dev, struct device_attribute *attr,\n+\t\t\t const char *buf, size_t len)\n+{\n+\tstruct net_device *netdev = to_net_dev(dev);\n+\tsize_t count = len;\n+\tssize_t ret;\n+\n+\tif (!capable(CAP_NET_ADMIN))\n+\t\treturn -EPERM;\n+\n+\t/* ignore trailing newline */\n+\tif (len > 0 && buf[len - 1] == '\\n')\n+\t\t--count;\n+\n+\trtnl_lock();\n+\tret = dev_set_alias(netdev, buf, count);\n+\trtnl_unlock();\n+\n+\treturn ret < 0 ? ret : len;\n+}\n+\n+static ssize_t show_ifalias(struct device *dev,\n+\t\t\t struct device_attribute *attr, char *buf)\n+{\n+\tconst struct net_device *netdev = to_net_dev(dev);\n+\tssize_t ret = 0;\n+\n+\trtnl_lock();\n+\tif (netdev->ifalias)\n+\t\tret = sprintf(buf, \"%s\\n\", netdev->ifalias);\n+\trtnl_unlock();\n+\treturn ret;\n+}\n+\n static struct device_attribute net_class_attributes[] = {\n \t__ATTR(addr_len, S_IRUGO, show_addr_len, NULL),\n \t__ATTR(dev_id, S_IRUGO, show_dev_id, NULL),\n+\t__ATTR(ifalias, S_IRUGO | S_IWUSR, show_ifalias, store_ifalias),\n \t__ATTR(iflink, S_IRUGO, show_iflink, NULL),\n \t__ATTR(ifindex, S_IRUGO, show_ifindex, NULL),\n \t__ATTR(features, S_IRUGO, show_features, NULL),\n@@ -418,6 +453,7 @@ static void netdev_release(struct device\n \n \tBUG_ON(dev->reg_state != NETREG_RELEASED);\n \n+\tkfree(dev->ifalias);\n \tkfree((char *)dev - dev->padded);\n }\n \n--- a/net/core/rtnetlink.c\t2008-09-22 11:48:30.000000000 -0700\n+++ b/net/core/rtnetlink.c\t2008-09-22 16:23:56.000000000 -0700\n@@ -586,6 +586,7 @@ static inline size_t if_nlmsg_size(const\n {\n \treturn NLMSG_ALIGN(sizeof(struct ifinfomsg))\n \t + nla_total_size(IFNAMSIZ) /* IFLA_IFNAME */\n+\t + nla_total_size(IFALIASZ) /* IFLA_IFALIAS */\n \t + nla_total_size(IFNAMSIZ) /* IFLA_QDISC */\n \t + nla_total_size(sizeof(struct rtnl_link_ifmap))\n \t + nla_total_size(sizeof(struct rtnl_link_stats))\n@@ -640,6 +641,9 @@ static int rtnl_fill_ifinfo(struct sk_bu\n \tif (txq->qdisc_sleeping)\n \t\tNLA_PUT_STRING(skb, IFLA_QDISC, txq->qdisc_sleeping->ops->id);\n \n+\tif (dev->ifalias)\n+\t\tNLA_PUT_STRING(skb, IFLA_IFALIAS, dev->ifalias);\n+\n \tif (1) {\n \t\tstruct rtnl_link_ifmap map = {\n \t\t\t.mem_start = dev->mem_start,\n@@ -713,6 +717,7 @@ const struct nla_policy ifla_policy[IFLA\n \t[IFLA_LINKMODE]\t\t= { .type = NLA_U8 },\n \t[IFLA_LINKINFO]\t\t= { .type = NLA_NESTED },\n \t[IFLA_NET_NS_PID]\t= { .type = NLA_U32 },\n+\t[IFLA_IFALIAS]\t = { .type = NLA_STRING, .len = IFALIASZ-1 },\n };\n \n static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX+1] = {\n@@ -853,6 +858,14 @@ static int do_setlink(struct net_device \n \t\tmodified = 1;\n \t}\n \n+\tif (tb[IFLA_IFALIAS]) {\n+\t\terr = dev_set_alias(dev, nla_data(tb[IFLA_IFALIAS]),\n+\t\t\t\t nla_len(tb[IFLA_IFALIAS]));\n+\t\tif (err < 0)\n+\t\t\tgoto errout;\n+\t\tmodified = 1;\n+\t}\n+\n \tif (tb[IFLA_BROADCAST]) {\n \t\tnla_memcpy(dev->broadcast, tb[IFLA_BROADCAST], dev->addr_len);\n \t\tsend_addr_notify = 1;\n", "prefixes": [] }