devlink: Return physical port fields only for applicable port flavours
authorParav Pandit <parav@mellanox.com>
Tue, 9 Jul 2019 04:17:36 +0000 (23:17 -0500)
committerDavid S. Miller <davem@davemloft.net>
Tue, 9 Jul 2019 19:02:13 +0000 (12:02 -0700)
Physical port number and split group fields are applicable only to
physical port flavours such as PHYSICAL, CPU and DSA.
Hence limit returning those values in netlink response to such port
flavours.

Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Parav Pandit <parav@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/core/devlink.c

index eacaf37b5108f8e93eb4e45800ed565dffcacf9a..a9c4e5d8a99c50612f3dcc0e9ffc697bd9366012 100644 (file)
@@ -515,6 +515,10 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg,
                return 0;
        if (nla_put_u16(msg, DEVLINK_ATTR_PORT_FLAVOUR, attrs->flavour))
                return -EMSGSIZE;
+       if (devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_PHYSICAL &&
+           devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_CPU &&
+           devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_DSA)
+               return 0;
        if (nla_put_u32(msg, DEVLINK_ATTR_PORT_NUMBER,
                        attrs->phys.port_number))
                return -EMSGSIZE;