Patchwork [net-next,2/3] rtnl: export physical port id via RT netlink

login
register
mail settings
Submitter Jiri Pirko
Date July 19, 2013, 1:55 p.m.
Message ID <1374242152-10325-3-git-send-email-jiri@resnulli.us>
Download mbox | patch
Permalink /patch/260270/
State Superseded
Delegated to: David Miller
Headers show

Comments

Jiri Pirko - July 19, 2013, 1:55 p.m.
Signed-off-by: Jiri Pirko <jiri@resnulli.us>
---
 include/uapi/linux/if_link.h |  1 +
 net/core/rtnetlink.c         | 25 ++++++++++++++++++++++++-
 2 files changed, 25 insertions(+), 1 deletion(-)
Ben Hutchings - July 19, 2013, 4:07 p.m.
On Fri, 2013-07-19 at 15:55 +0200, Jiri Pirko wrote:
> Signed-off-by: Jiri Pirko <jiri@resnulli.us>
> ---
>  include/uapi/linux/if_link.h |  1 +
>  net/core/rtnetlink.c         | 25 ++++++++++++++++++++++++-
>  2 files changed, 25 insertions(+), 1 deletion(-)
> 
> diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h
> index 03f6170..04c0e7a 100644
> --- a/include/uapi/linux/if_link.h
> +++ b/include/uapi/linux/if_link.h
[...]
> @@ -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;
> +
> +	if (!dev->netdev_ops->ndo_get_phys_port_id)
> +		return 0;
> +
> +	err = dev->netdev_ops->ndo_get_phys_port_id(dev, &ppid);
> +	if (err)
> +		return err;
[...]

I can imagine a driver only sometimes being able to get the physical
port ID, depending on hardware variant or firmware version.  That
shouldn't require defining another instance of net_device_ops.  So if
the error is -EOPNOTSUPP this should return 0, same as if the function
pointer is NULL.  

Ben.
Jiri Pirko - July 19, 2013, 5:13 p.m.
Fri, Jul 19, 2013 at 06:07:10PM CEST, bhutchings@solarflare.com wrote:
>On Fri, 2013-07-19 at 15:55 +0200, Jiri Pirko wrote:
>> Signed-off-by: Jiri Pirko <jiri@resnulli.us>
>> ---
>>  include/uapi/linux/if_link.h |  1 +
>>  net/core/rtnetlink.c         | 25 ++++++++++++++++++++++++-
>>  2 files changed, 25 insertions(+), 1 deletion(-)
>> 
>> diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h
>> index 03f6170..04c0e7a 100644
>> --- a/include/uapi/linux/if_link.h
>> +++ b/include/uapi/linux/if_link.h
>[...]
>> @@ -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;
>> +
>> +	if (!dev->netdev_ops->ndo_get_phys_port_id)
>> +		return 0;
>> +
>> +	err = dev->netdev_ops->ndo_get_phys_port_id(dev, &ppid);
>> +	if (err)
>> +		return err;
>[...]
>
>I can imagine a driver only sometimes being able to get the physical
>port ID, depending on hardware variant or firmware version.  That
>shouldn't require defining another instance of net_device_ops.  So if
>the error is -EOPNOTSUPP this should return 0, same as if the function
>pointer is NULL.  

Makes sense. I will adjust this. Thanks Ben.

>
>Ben.
>
>-- 
>Ben Hutchings, Staff Engineer, Solarflare
>Not speaking for my employer; that's the marketing department's job.
>They asked us to note that Solarflare product names are trademarked.
>
>--
>To unsubscribe from this list: send the line "unsubscribe netdev" in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h
index 03f6170..04c0e7a 100644
--- a/include/uapi/linux/if_link.h
+++ b/include/uapi/linux/if_link.h
@@ -143,6 +143,7 @@  enum {
 	IFLA_NUM_TX_QUEUES,
 	IFLA_NUM_RX_QUEUES,
 	IFLA_CARRIER,
+	IFLA_PHYS_PORT_ID,
 	__IFLA_MAX
 };
 
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 3de7408..2bd0e67 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -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;
+
+	if (!dev->netdev_ops->ndo_get_phys_port_id)
+		return 0;
+
+	err = dev->netdev_ops->ndo_get_phys_port_id(dev, &ppid);
+	if (err)
+		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);