aboutsummaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--Documentation/ABI/testing/sysfs-class-net8
-rw-r--r--include/linux/netdevice.h4
-rw-r--r--include/uapi/linux/if_link.h1
-rw-r--r--net/core/dev.c18
-rw-r--r--net/core/net-sysfs.c23
-rw-r--r--net/core/rtnetlink.c21
6 files changed, 75 insertions, 0 deletions
diff --git a/Documentation/ABI/testing/sysfs-class-net b/Documentation/ABI/testing/sysfs-class-net
index beb8ec4dabbc..5ecfd72ba684 100644
--- a/Documentation/ABI/testing/sysfs-class-net
+++ b/Documentation/ABI/testing/sysfs-class-net
@@ -188,6 +188,14 @@ Description:
188 Indicates the interface unique physical port identifier within 188 Indicates the interface unique physical port identifier within
189 the NIC, as a string. 189 the NIC, as a string.
190 190
191What: /sys/class/net/<iface>/phys_port_name
192Date: March 2015
193KernelVersion: 4.0
194Contact: netdev@vger.kernel.org
195Description:
196 Indicates the interface physical port name within the NIC,
197 as a string.
198
191What: /sys/class/net/<iface>/speed 199What: /sys/class/net/<iface>/speed
192Date: October 2009 200Date: October 2009
193KernelVersion: 2.6.33 201KernelVersion: 2.6.33
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 76c5de4978a8..ec8f9b5f6500 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -1164,6 +1164,8 @@ struct net_device_ops {
1164 bool new_carrier); 1164 bool new_carrier);
1165 int (*ndo_get_phys_port_id)(struct net_device *dev, 1165 int (*ndo_get_phys_port_id)(struct net_device *dev,
1166 struct netdev_phys_item_id *ppid); 1166 struct netdev_phys_item_id *ppid);
1167 int (*ndo_get_phys_port_name)(struct net_device *dev,
1168 char *name, size_t len);
1167 void (*ndo_add_vxlan_port)(struct net_device *dev, 1169 void (*ndo_add_vxlan_port)(struct net_device *dev,
1168 sa_family_t sa_family, 1170 sa_family_t sa_family,
1169 __be16 port); 1171 __be16 port);
@@ -2947,6 +2949,8 @@ int dev_set_mac_address(struct net_device *, struct sockaddr *);
2947int dev_change_carrier(struct net_device *, bool new_carrier); 2949int dev_change_carrier(struct net_device *, bool new_carrier);
2948int dev_get_phys_port_id(struct net_device *dev, 2950int dev_get_phys_port_id(struct net_device *dev,
2949 struct netdev_phys_item_id *ppid); 2951 struct netdev_phys_item_id *ppid);
2952int dev_get_phys_port_name(struct net_device *dev,
2953 char *name, size_t len);
2950struct sk_buff *validate_xmit_skb_list(struct sk_buff *skb, struct net_device *dev); 2954struct sk_buff *validate_xmit_skb_list(struct sk_buff *skb, struct net_device *dev);
2951struct sk_buff *dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev, 2955struct sk_buff *dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,
2952 struct netdev_queue *txq, int *ret); 2956 struct netdev_queue *txq, int *ret);
diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h
index 756436e1ce89..7158fd00a109 100644
--- a/include/uapi/linux/if_link.h
+++ b/include/uapi/linux/if_link.h
@@ -147,6 +147,7 @@ enum {
147 IFLA_CARRIER_CHANGES, 147 IFLA_CARRIER_CHANGES,
148 IFLA_PHYS_SWITCH_ID, 148 IFLA_PHYS_SWITCH_ID,
149 IFLA_LINK_NETNSID, 149 IFLA_LINK_NETNSID,
150 IFLA_PHYS_PORT_NAME,
150 __IFLA_MAX 151 __IFLA_MAX
151}; 152};
152 153
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