aboutsummaryrefslogtreecommitdiffstats
path: root/net/core
diff options
context:
space:
mode:
authorDavid Ahern <dsahern@gmail.com>2015-03-17 22:23:15 -0400
committerDavid S. Miller <davem@davemloft.net>2015-03-18 22:30:35 -0400
commitdb24a9044ee191c397dcd1c6574f56d67d7c8df5 (patch)
tree5d15e7aed127d9c211b5b2dc2d69607cef0d6d8d /net/core
parent56ef9c909b40483d2c8cb63fcbf83865f162d5ec (diff)
net: add support for phys_port_name
Similar to port id allow netdevices to specify port names and export the name via sysfs. Drivers can implement the netdevice operation to assist udev in having sane default names for the devices using the rule: $ cat /etc/udev/rules.d/80-net-setup-link.rules SUBSYSTEM=="net", ACTION=="add", ATTR{phys_port_name}!="", NAME="$attr{phys_port_name}" Use of phys_name versus phys_id was suggested-by Jiri Pirko. Signed-off-by: David Ahern <dsahern@gmail.com> Acked-by: Jiri Pirko <jiri@resnulli.us> Acked-by: Scott Feldman <sfeldma@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core')
-rw-r--r--net/core/dev.c18
-rw-r--r--net/core/net-sysfs.c23
-rw-r--r--net/core/rtnetlink.c21
3 files changed, 62 insertions, 0 deletions
diff --git a/net/core/dev.c b/net/core/dev.c
index 39fe369b46ad..a1f24151db5b 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -5912,6 +5912,24 @@ int dev_get_phys_port_id(struct net_device *dev,
5912EXPORT_SYMBOL(dev_get_phys_port_id); 5912EXPORT_SYMBOL(dev_get_phys_port_id);
5913 5913
5914/** 5914/**
5915 * dev_get_phys_port_name - Get device physical port name
5916 * @dev: device
5917 * @name: port name
5918 *
5919 * Get device physical port name
5920 */
5921int dev_get_phys_port_name(struct net_device *dev,
5922 char *name, size_t len)
5923{
5924 const struct net_device_ops *ops = dev->netdev_ops;
5925
5926 if (!ops->ndo_get_phys_port_name)
5927 return -EOPNOTSUPP;
5928 return ops->ndo_get_phys_port_name(dev, name, len);
5929}
5930EXPORT_SYMBOL(dev_get_phys_port_name);
5931
5932/**
5915 * dev_new_index - allocate an ifindex 5933 * dev_new_index - allocate an ifindex
5916 * @net: the applicable net namespace 5934 * @net: the applicable net namespace
5917 * 5935 *
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index 7e58bd7ec232..cc5cf689809c 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -418,6 +418,28 @@ static ssize_t phys_port_id_show(struct device *dev,
418} 418}
419static DEVICE_ATTR_RO(phys_port_id); 419static DEVICE_ATTR_RO(phys_port_id);
420 420
421static ssize_t phys_port_name_show(struct device *dev,
422 struct device_attribute *attr, char *buf)
423{
424 struct net_device *netdev = to_net_dev(dev);
425 ssize_t ret = -EINVAL;
426
427 if (!rtnl_trylock())
428 return restart_syscall();
429
430 if (dev_isalive(netdev)) {
431 char name[IFNAMSIZ];
432
433 ret = dev_get_phys_port_name(netdev, name, sizeof(name));
434 if (!ret)
435 ret = sprintf(buf, "%s\n", name);
436 }
437 rtnl_unlock();
438
439 return ret;
440}
441static DEVICE_ATTR_RO(phys_port_name);
442
421static ssize_t phys_switch_id_show(struct device *dev, 443static ssize_t phys_switch_id_show(struct device *dev,
422 struct device_attribute *attr, char *buf) 444 struct device_attribute *attr, char *buf)
423{ 445{
@@ -465,6 +487,7 @@ static struct attribute *net_class_attrs[] = {
465 &dev_attr_tx_queue_len.attr, 487 &dev_attr_tx_queue_len.attr,
466 &dev_attr_gro_flush_timeout.attr, 488 &dev_attr_gro_flush_timeout.attr,
467 &dev_attr_phys_port_id.attr, 489 &dev_attr_phys_port_id.attr,
490 &dev_attr_phys_port_name.attr,
468 &dev_attr_phys_switch_id.attr, 491 &dev_attr_phys_switch_id.attr,
469 NULL, 492 NULL,
470}; 493};
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 25b4b5d23485..6abe634c666c 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -982,6 +982,24 @@ static int rtnl_phys_port_id_fill(struct sk_buff *skb, struct net_device *dev)
982 return 0; 982 return 0;
983} 983}
984 984
985static int rtnl_phys_port_name_fill(struct sk_buff *skb, struct net_device *dev)
986{
987 char name[IFNAMSIZ];
988 int err;
989
990 err = dev_get_phys_port_name(dev, name, sizeof(name));
991 if (err) {
992 if (err == -EOPNOTSUPP)
993 return 0;
994 return err;
995 }
996
997 if (nla_put(skb, IFLA_PHYS_PORT_NAME, strlen(name), name))
998 return -EMSGSIZE;
999
1000 return 0;
1001}
1002
985static int rtnl_phys_switch_id_fill(struct sk_buff *skb, struct net_device *dev) 1003static int rtnl_phys_switch_id_fill(struct sk_buff *skb, struct net_device *dev)
986{ 1004{
987 int err; 1005 int err;
@@ -1072,6 +1090,9 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
1072 if (rtnl_phys_port_id_fill(skb, dev)) 1090 if (rtnl_phys_port_id_fill(skb, dev))
1073 goto nla_put_failure; 1091 goto nla_put_failure;
1074 1092
1093 if (rtnl_phys_port_name_fill(skb, dev))
1094 goto nla_put_failure;
1095
1075 if (rtnl_phys_switch_id_fill(skb, dev)) 1096 if (rtnl_phys_switch_id_fill(skb, dev))
1076 goto nla_put_failure; 1097 goto nla_put_failure;
1077 1098