Commit db24a904 authored by David Ahern's avatar David Ahern Committed by David S. Miller

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: default avatarDavid Ahern <dsahern@gmail.com>
Acked-by: default avatarJiri Pirko <jiri@resnulli.us>
Acked-by: default avatarScott Feldman <sfeldma@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 56ef9c90
...@@ -188,6 +188,14 @@ Description: ...@@ -188,6 +188,14 @@ Description:
Indicates the interface unique physical port identifier within Indicates the interface unique physical port identifier within
the NIC, as a string. the NIC, as a string.
What: /sys/class/net/<iface>/phys_port_name
Date: March 2015
KernelVersion: 4.0
Contact: netdev@vger.kernel.org
Description:
Indicates the interface physical port name within the NIC,
as a string.
What: /sys/class/net/<iface>/speed What: /sys/class/net/<iface>/speed
Date: October 2009 Date: October 2009
KernelVersion: 2.6.33 KernelVersion: 2.6.33
......
...@@ -1164,6 +1164,8 @@ struct net_device_ops { ...@@ -1164,6 +1164,8 @@ struct net_device_ops {
bool new_carrier); bool new_carrier);
int (*ndo_get_phys_port_id)(struct net_device *dev, int (*ndo_get_phys_port_id)(struct net_device *dev,
struct netdev_phys_item_id *ppid); struct netdev_phys_item_id *ppid);
int (*ndo_get_phys_port_name)(struct net_device *dev,
char *name, size_t len);
void (*ndo_add_vxlan_port)(struct net_device *dev, void (*ndo_add_vxlan_port)(struct net_device *dev,
sa_family_t sa_family, sa_family_t sa_family,
__be16 port); __be16 port);
...@@ -2947,6 +2949,8 @@ int dev_set_mac_address(struct net_device *, struct sockaddr *); ...@@ -2947,6 +2949,8 @@ int dev_set_mac_address(struct net_device *, struct sockaddr *);
int dev_change_carrier(struct net_device *, bool new_carrier); int dev_change_carrier(struct net_device *, bool new_carrier);
int dev_get_phys_port_id(struct net_device *dev, int dev_get_phys_port_id(struct net_device *dev,
struct netdev_phys_item_id *ppid); struct netdev_phys_item_id *ppid);
int dev_get_phys_port_name(struct net_device *dev,
char *name, size_t len);
struct sk_buff *validate_xmit_skb_list(struct sk_buff *skb, struct net_device *dev); struct sk_buff *validate_xmit_skb_list(struct sk_buff *skb, struct net_device *dev);
struct sk_buff *dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev, struct sk_buff *dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,
struct netdev_queue *txq, int *ret); struct netdev_queue *txq, int *ret);
......
...@@ -147,6 +147,7 @@ enum { ...@@ -147,6 +147,7 @@ enum {
IFLA_CARRIER_CHANGES, IFLA_CARRIER_CHANGES,
IFLA_PHYS_SWITCH_ID, IFLA_PHYS_SWITCH_ID,
IFLA_LINK_NETNSID, IFLA_LINK_NETNSID,
IFLA_PHYS_PORT_NAME,
__IFLA_MAX __IFLA_MAX
}; };
......
...@@ -5911,6 +5911,24 @@ int dev_get_phys_port_id(struct net_device *dev, ...@@ -5911,6 +5911,24 @@ int dev_get_phys_port_id(struct net_device *dev,
} }
EXPORT_SYMBOL(dev_get_phys_port_id); EXPORT_SYMBOL(dev_get_phys_port_id);
/**
* dev_get_phys_port_name - Get device physical port name
* @dev: device
* @name: port name
*
* Get device physical port name
*/
int dev_get_phys_port_name(struct net_device *dev,
char *name, size_t len)
{
const struct net_device_ops *ops = dev->netdev_ops;
if (!ops->ndo_get_phys_port_name)
return -EOPNOTSUPP;
return ops->ndo_get_phys_port_name(dev, name, len);
}
EXPORT_SYMBOL(dev_get_phys_port_name);
/** /**
* dev_new_index - allocate an ifindex * dev_new_index - allocate an ifindex
* @net: the applicable net namespace * @net: the applicable net namespace
......
...@@ -418,6 +418,28 @@ static ssize_t phys_port_id_show(struct device *dev, ...@@ -418,6 +418,28 @@ static ssize_t phys_port_id_show(struct device *dev,
} }
static DEVICE_ATTR_RO(phys_port_id); static DEVICE_ATTR_RO(phys_port_id);
static ssize_t phys_port_name_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct net_device *netdev = to_net_dev(dev);
ssize_t ret = -EINVAL;
if (!rtnl_trylock())
return restart_syscall();
if (dev_isalive(netdev)) {
char name[IFNAMSIZ];
ret = dev_get_phys_port_name(netdev, name, sizeof(name));
if (!ret)
ret = sprintf(buf, "%s\n", name);
}
rtnl_unlock();
return ret;
}
static DEVICE_ATTR_RO(phys_port_name);
static ssize_t phys_switch_id_show(struct device *dev, static ssize_t phys_switch_id_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
...@@ -465,6 +487,7 @@ static struct attribute *net_class_attrs[] = { ...@@ -465,6 +487,7 @@ static struct attribute *net_class_attrs[] = {
&dev_attr_tx_queue_len.attr, &dev_attr_tx_queue_len.attr,
&dev_attr_gro_flush_timeout.attr, &dev_attr_gro_flush_timeout.attr,
&dev_attr_phys_port_id.attr, &dev_attr_phys_port_id.attr,
&dev_attr_phys_port_name.attr,
&dev_attr_phys_switch_id.attr, &dev_attr_phys_switch_id.attr,
NULL, NULL,
}; };
......
...@@ -982,6 +982,24 @@ static int rtnl_phys_port_id_fill(struct sk_buff *skb, struct net_device *dev) ...@@ -982,6 +982,24 @@ static int rtnl_phys_port_id_fill(struct sk_buff *skb, struct net_device *dev)
return 0; return 0;
} }
static int rtnl_phys_port_name_fill(struct sk_buff *skb, struct net_device *dev)
{
char name[IFNAMSIZ];
int err;
err = dev_get_phys_port_name(dev, name, sizeof(name));
if (err) {
if (err == -EOPNOTSUPP)
return 0;
return err;
}
if (nla_put(skb, IFLA_PHYS_PORT_NAME, strlen(name), name))
return -EMSGSIZE;
return 0;
}
static int rtnl_phys_switch_id_fill(struct sk_buff *skb, struct net_device *dev) static int rtnl_phys_switch_id_fill(struct sk_buff *skb, struct net_device *dev)
{ {
int err; int err;
...@@ -1072,6 +1090,9 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev, ...@@ -1072,6 +1090,9 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
if (rtnl_phys_port_id_fill(skb, dev)) if (rtnl_phys_port_id_fill(skb, dev))
goto nla_put_failure; goto nla_put_failure;
if (rtnl_phys_port_name_fill(skb, dev))
goto nla_put_failure;
if (rtnl_phys_switch_id_fill(skb, dev)) if (rtnl_phys_switch_id_fill(skb, dev))
goto nla_put_failure; goto nla_put_failure;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment