Commit 82f2841291cfaf4d225aa1766424280254d3e3b2

Authored by Jiri Pirko
Committed by David S. Miller
1 parent 007f790c82

rtnl: expose physical switch id for particular device

The netdevice represents a port in a switch, it will expose
IFLA_PHYS_SWITCH_ID value via rtnl. Two netdevices with the same value
belong to one physical switch.

Signed-off-by: Jiri Pirko <jiri@resnulli.us>
Reviewed-by: Thomas Graf <tgraf@suug.ch>
Acked-by: John Fastabend <john.r.fastabend@intel.com>
Acked-by: Andy Gospodarek <gospo@cumulusnetworks.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

Showing 2 changed files with 26 additions and 1 deletions Side-by-side Diff

include/uapi/linux/if_link.h
... ... @@ -145,6 +145,7 @@
145 145 IFLA_CARRIER,
146 146 IFLA_PHYS_PORT_ID,
147 147 IFLA_CARRIER_CHANGES,
  148 + IFLA_PHYS_SWITCH_ID,
148 149 __IFLA_MAX
149 150 };
150 151  
net/core/rtnetlink.c
... ... @@ -44,6 +44,7 @@
44 44  
45 45 #include <linux/inet.h>
46 46 #include <linux/netdevice.h>
  47 +#include <net/switchdev.h>
47 48 #include <net/ip.h>
48 49 #include <net/protocol.h>
49 50 #include <net/arp.h>
... ... @@ -869,7 +870,8 @@
869 870 + rtnl_port_size(dev, ext_filter_mask) /* IFLA_VF_PORTS + IFLA_PORT_SELF */
870 871 + rtnl_link_get_size(dev) /* IFLA_LINKINFO */
871 872 + rtnl_link_get_af_size(dev) /* IFLA_AF_SPEC */
872   - + nla_total_size(MAX_PHYS_ITEM_ID_LEN); /* IFLA_PHYS_PORT_ID */
  873 + + nla_total_size(MAX_PHYS_ITEM_ID_LEN) /* IFLA_PHYS_PORT_ID */
  874 + + nla_total_size(MAX_PHYS_ITEM_ID_LEN); /* IFLA_PHYS_SWITCH_ID */
873 875 }
874 876  
875 877 static int rtnl_vf_ports_fill(struct sk_buff *skb, struct net_device *dev)
... ... @@ -968,6 +970,24 @@
968 970 return 0;
969 971 }
970 972  
  973 +static int rtnl_phys_switch_id_fill(struct sk_buff *skb, struct net_device *dev)
  974 +{
  975 + int err;
  976 + struct netdev_phys_item_id psid;
  977 +
  978 + err = netdev_switch_parent_id_get(dev, &psid);
  979 + if (err) {
  980 + if (err == -EOPNOTSUPP)
  981 + return 0;
  982 + return err;
  983 + }
  984 +
  985 + if (nla_put(skb, IFLA_PHYS_SWITCH_ID, psid.id_len, psid.id))
  986 + return -EMSGSIZE;
  987 +
  988 + return 0;
  989 +}
  990 +
971 991 static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
972 992 int type, u32 pid, u32 seq, u32 change,
973 993 unsigned int flags, u32 ext_filter_mask)
... ... @@ -1040,6 +1060,9 @@
1040 1060 if (rtnl_phys_port_id_fill(skb, dev))
1041 1061 goto nla_put_failure;
1042 1062  
  1063 + if (rtnl_phys_switch_id_fill(skb, dev))
  1064 + goto nla_put_failure;
  1065 +
1043 1066 attr = nla_reserve(skb, IFLA_STATS,
1044 1067 sizeof(struct rtnl_link_stats));
1045 1068 if (attr == NULL)
... ... @@ -1199,6 +1222,7 @@
1199 1222 [IFLA_NUM_RX_QUEUES] = { .type = NLA_U32 },
1200 1223 [IFLA_PHYS_PORT_ID] = { .type = NLA_BINARY, .len = MAX_PHYS_ITEM_ID_LEN },
1201 1224 [IFLA_CARRIER_CHANGES] = { .type = NLA_U32 }, /* ignored */
  1225 + [IFLA_PHYS_SWITCH_ID] = { .type = NLA_BINARY, .len = MAX_PHYS_ITEM_ID_LEN },
1202 1226 };
1203 1227  
1204 1228 static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX+1] = {