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>
This commit is contained in:
committed by
David S. Miller
parent
56ef9c909b
commit
db24a9044e
@@ -982,6 +982,24 @@ static int rtnl_phys_port_id_fill(struct sk_buff *skb, struct net_device *dev)
|
||||
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)
|
||||
{
|
||||
int err;
|
||||
@@ -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))
|
||||
goto nla_put_failure;
|
||||
|
||||
if (rtnl_phys_port_name_fill(skb, dev))
|
||||
goto nla_put_failure;
|
||||
|
||||
if (rtnl_phys_switch_id_fill(skb, dev))
|
||||
goto nla_put_failure;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user