rtnl: export physical port id via RT netlink
authorJiri Pirko <jiri@resnulli.us>
Mon, 29 Jul 2013 16:16:50 +0000 (18:16 +0200)
committerDavid S. Miller <davem@davemloft.net>
Wed, 31 Jul 2013 00:31:24 +0000 (17:31 -0700)
Signed-off-by: Jiri Pirko <jiri@resnulli.us>
Acked-by: Ben Hutchings <bhutchings@solarflare.com>
Signed-off-by: Narendra K <narendra_k@dell.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/uapi/linux/if_link.h
net/core/rtnetlink.c

index 03f6170ab3372f443c0989c7c5a503b00ef0c308..04c0e7a5d48421645ee23016064d143918a08ca3 100644 (file)
@@ -143,6 +143,7 @@ enum {
        IFLA_NUM_TX_QUEUES,
        IFLA_NUM_RX_QUEUES,
        IFLA_CARRIER,
+       IFLA_PHYS_PORT_ID,
        __IFLA_MAX
 };
 
index 3de740834d1ffcfa35fe31735b41d5a0dcb58c3a..0b2972c59b97824f24a96c899e906a9371ea84ab 100644 (file)
@@ -767,7 +767,8 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev,
               + rtnl_vfinfo_size(dev, ext_filter_mask) /* IFLA_VFINFO_LIST */
               + rtnl_port_size(dev) /* IFLA_VF_PORTS + IFLA_PORT_SELF */
               + rtnl_link_get_size(dev) /* IFLA_LINKINFO */
-              + rtnl_link_get_af_size(dev); /* IFLA_AF_SPEC */
+              + rtnl_link_get_af_size(dev) /* IFLA_AF_SPEC */
+              + nla_total_size(MAX_PHYS_PORT_ID_LEN); /* IFLA_PHYS_PORT_ID */
 }
 
 static int rtnl_vf_ports_fill(struct sk_buff *skb, struct net_device *dev)
@@ -846,6 +847,24 @@ static int rtnl_port_fill(struct sk_buff *skb, struct net_device *dev)
        return 0;
 }
 
+static int rtnl_phys_port_id_fill(struct sk_buff *skb, struct net_device *dev)
+{
+       int err;
+       struct netdev_phys_port_id ppid;
+
+       err = dev_get_phys_port_id(dev, &ppid);
+       if (err) {
+               if (err == -EOPNOTSUPP)
+                       return 0;
+               return err;
+       }
+
+       if (nla_put(skb, IFLA_PHYS_PORT_ID, ppid.id_len, ppid.id))
+               return -EMSGSIZE;
+
+       return 0;
+}
+
 static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
                            int type, u32 pid, u32 seq, u32 change,
                            unsigned int flags, u32 ext_filter_mask)
@@ -913,6 +932,9 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
                        goto nla_put_failure;
        }
 
+       if (rtnl_phys_port_id_fill(skb, dev))
+               goto nla_put_failure;
+
        attr = nla_reserve(skb, IFLA_STATS,
                        sizeof(struct rtnl_link_stats));
        if (attr == NULL)
@@ -1113,6 +1135,7 @@ const struct nla_policy ifla_policy[IFLA_MAX+1] = {
        [IFLA_PROMISCUITY]      = { .type = NLA_U32 },
        [IFLA_NUM_TX_QUEUES]    = { .type = NLA_U32 },
        [IFLA_NUM_RX_QUEUES]    = { .type = NLA_U32 },
+       [IFLA_PHYS_PORT_ID]     = { .type = NLA_BINARY, .len = MAX_PHYS_PORT_ID_LEN },
 };
 EXPORT_SYMBOL(ifla_policy);