switchdev: convert parent_id_get to switchdev attr get

Switch ID is just a gettable port attribute.  Convert switchdev op
switchdev_parent_id_get to a switchdev attr.

Note: for sysfs and netlink interfaces, SWITCHDEV_ATTR_PORT_PARENT_ID is
called with SWITCHDEV_F_NO_RECUSE to limit switch ID user-visiblity to only
port netdevs.  So when a port is stacked under bond/bridge, the user can
only query switch id via the switch ports, but not via the upper devices

Signed-off-by: Scott Feldman <sfeldma@gmail.com>
Acked-by: Jiri Pirko <jiri@resnulli.us>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Scott Feldman 2015-05-10 09:47:49 -07:00 committed by David S. Miller
parent 3094333d90
commit f8e20a9f87
6 changed files with 51 additions and 57 deletions

View file

@ -18,24 +18,6 @@
#include <net/ip_fib.h>
#include <net/switchdev.h>
/**
* switchdev_parent_id_get - Get ID of a switch
* @dev: port device
* @psid: switch ID
*
* Get ID of a switch this port is part of.
*/
int switchdev_parent_id_get(struct net_device *dev,
struct netdev_phys_item_id *psid)
{
const struct switchdev_ops *ops = dev->switchdev_ops;
if (!ops || !ops->switchdev_parent_id_get)
return -EOPNOTSUPP;
return ops->switchdev_parent_id_get(dev, psid);
}
EXPORT_SYMBOL_GPL(switchdev_parent_id_get);
/**
* switchdev_port_attr_get - Get port attribute
*
@ -414,11 +396,10 @@ static struct net_device *switchdev_get_lowest_dev(struct net_device *dev)
struct list_head *iter;
/* Recusively search down until we find a sw port dev.
* (A sw port dev supports switchdev_parent_id_get).
* (A sw port dev supports switchdev_port_attr_get).
*/
if (dev->features & NETIF_F_HW_SWITCH_OFFLOAD &&
ops && ops->switchdev_parent_id_get)
if (ops && ops->switchdev_port_attr_get)
return dev;
netdev_for_each_lower_dev(dev, lower_dev, iter) {
@ -432,8 +413,10 @@ static struct net_device *switchdev_get_lowest_dev(struct net_device *dev)
static struct net_device *switchdev_get_dev_by_nhs(struct fib_info *fi)
{
struct netdev_phys_item_id psid;
struct netdev_phys_item_id prev_psid;
struct switchdev_attr attr = {
.id = SWITCHDEV_ATTR_PORT_PARENT_ID,
};
struct switchdev_attr prev_attr;
struct net_device *dev = NULL;
int nhsel;
@ -449,17 +432,18 @@ static struct net_device *switchdev_get_dev_by_nhs(struct fib_info *fi)
if (!dev)
return NULL;
if (switchdev_parent_id_get(dev, &psid))
if (switchdev_port_attr_get(dev, &attr))
return NULL;
if (nhsel > 0) {
if (prev_psid.id_len != psid.id_len)
if (prev_attr.ppid.id_len != attr.ppid.id_len)
return NULL;
if (memcmp(prev_psid.id, psid.id, psid.id_len))
if (memcmp(prev_attr.ppid.id, attr.ppid.id,
attr.ppid.id_len))
return NULL;
}
prev_psid = psid;
prev_attr = attr;
}
return dev;