aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorScott Feldman <sfeldma@gmail.com>2015-05-10 12:47:49 -0400
committerDavid S. Miller <davem@davemloft.net>2015-05-12 18:43:53 -0400
commitf8e20a9f87d33865cc1d67f13da0db8d457fc3c9 (patch)
tree0072db71330af1215e78c1def9033d62156a4183 /net
parent3094333d9089d43e8b8f0418676fa6ae06c27b51 (diff)
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>
Diffstat (limited to 'net')
-rw-r--r--net/core/net-sysfs.c10
-rw-r--r--net/core/rtnetlink.c9
-rw-r--r--net/dsa/slave.c16
-rw-r--r--net/switchdev/switchdev.c38
4 files changed, 35 insertions, 38 deletions
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index be86a7ce9282..5a9ce96f6d27 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -458,11 +458,15 @@ static ssize_t phys_switch_id_show(struct device *dev,
458 return restart_syscall(); 458 return restart_syscall();
459 459
460 if (dev_isalive(netdev)) { 460 if (dev_isalive(netdev)) {
461 struct netdev_phys_item_id ppid; 461 struct switchdev_attr attr = {
462 .id = SWITCHDEV_ATTR_PORT_PARENT_ID,
463 .flags = SWITCHDEV_F_NO_RECURSE,
464 };
462 465
463 ret = switchdev_parent_id_get(netdev, &ppid); 466 ret = switchdev_port_attr_get(netdev, &attr);
464 if (!ret) 467 if (!ret)
465 ret = sprintf(buf, "%*phN\n", ppid.id_len, ppid.id); 468 ret = sprintf(buf, "%*phN\n", attr.ppid.id_len,
469 attr.ppid.id);
466 } 470 }
467 rtnl_unlock(); 471 rtnl_unlock();
468 472
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index fcd41fcd7e70..c6c6b2c34926 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -1004,16 +1004,19 @@ static int rtnl_phys_port_name_fill(struct sk_buff *skb, struct net_device *dev)
1004static int rtnl_phys_switch_id_fill(struct sk_buff *skb, struct net_device *dev) 1004static int rtnl_phys_switch_id_fill(struct sk_buff *skb, struct net_device *dev)
1005{ 1005{
1006 int err; 1006 int err;
1007 struct netdev_phys_item_id psid; 1007 struct switchdev_attr attr = {
1008 .id = SWITCHDEV_ATTR_PORT_PARENT_ID,
1009 .flags = SWITCHDEV_F_NO_RECURSE,
1010 };
1008 1011
1009 err = switchdev_parent_id_get(dev, &psid); 1012 err = switchdev_port_attr_get(dev, &attr);
1010 if (err) { 1013 if (err) {
1011 if (err == -EOPNOTSUPP) 1014 if (err == -EOPNOTSUPP)
1012 return 0; 1015 return 0;
1013 return err; 1016 return err;
1014 } 1017 }
1015 1018
1016 if (nla_put(skb, IFLA_PHYS_SWITCH_ID, psid.id_len, psid.id)) 1019 if (nla_put(skb, IFLA_PHYS_SWITCH_ID, attr.ppid.id_len, attr.ppid.id))
1017 return -EMSGSIZE; 1020 return -EMSGSIZE;
1018 1021
1019 return 0; 1022 return 0;
diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index 1546acf6ebd3..de705b674ac9 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -382,14 +382,20 @@ static int dsa_slave_bridge_port_leave(struct net_device *dev)
382 return ret; 382 return ret;
383} 383}
384 384
385static int dsa_slave_parent_id_get(struct net_device *dev, 385static int dsa_slave_port_attr_get(struct net_device *dev,
386 struct netdev_phys_item_id *psid) 386 struct switchdev_attr *attr)
387{ 387{
388 struct dsa_slave_priv *p = netdev_priv(dev); 388 struct dsa_slave_priv *p = netdev_priv(dev);
389 struct dsa_switch *ds = p->parent; 389 struct dsa_switch *ds = p->parent;
390 390
391 psid->id_len = sizeof(ds->index); 391 switch (attr->id) {
392 memcpy(&psid->id, &ds->index, psid->id_len); 392 case SWITCHDEV_ATTR_PORT_PARENT_ID:
393 attr->ppid.id_len = sizeof(ds->index);
394 memcpy(&attr->ppid.id, &ds->index, attr->ppid.id_len);
395 break;
396 default:
397 return -EOPNOTSUPP;
398 }
393 399
394 return 0; 400 return 0;
395} 401}
@@ -676,7 +682,7 @@ static const struct net_device_ops dsa_slave_netdev_ops = {
676}; 682};
677 683
678static const struct switchdev_ops dsa_slave_switchdev_ops = { 684static const struct switchdev_ops dsa_slave_switchdev_ops = {
679 .switchdev_parent_id_get = dsa_slave_parent_id_get, 685 .switchdev_port_attr_get = dsa_slave_port_attr_get,
680 .switchdev_port_stp_update = dsa_slave_stp_update, 686 .switchdev_port_stp_update = dsa_slave_stp_update,
681}; 687};
682 688
diff --git a/net/switchdev/switchdev.c b/net/switchdev/switchdev.c
index 8f47187dc185..117fd0797abd 100644
--- a/net/switchdev/switchdev.c
+++ b/net/switchdev/switchdev.c
@@ -19,24 +19,6 @@
19#include <net/switchdev.h> 19#include <net/switchdev.h>
20 20
21/** 21/**
22 * switchdev_parent_id_get - Get ID of a switch
23 * @dev: port device
24 * @psid: switch ID
25 *
26 * Get ID of a switch this port is part of.
27 */
28int switchdev_parent_id_get(struct net_device *dev,
29 struct netdev_phys_item_id *psid)
30{
31 const struct switchdev_ops *ops = dev->switchdev_ops;
32
33 if (!ops || !ops->switchdev_parent_id_get)
34 return -EOPNOTSUPP;
35 return ops->switchdev_parent_id_get(dev, psid);
36}
37EXPORT_SYMBOL_GPL(switchdev_parent_id_get);
38
39/**
40 * switchdev_port_attr_get - Get port attribute 22 * switchdev_port_attr_get - Get port attribute
41 * 23 *
42 * @dev: port device 24 * @dev: port device
@@ -414,11 +396,10 @@ static struct net_device *switchdev_get_lowest_dev(struct net_device *dev)
414 struct list_head *iter; 396 struct list_head *iter;
415 397
416 /* Recusively search down until we find a sw port dev. 398 /* Recusively search down until we find a sw port dev.
417 * (A sw port dev supports switchdev_parent_id_get). 399 * (A sw port dev supports switchdev_port_attr_get).
418 */ 400 */
419 401
420 if (dev->features & NETIF_F_HW_SWITCH_OFFLOAD && 402 if (ops && ops->switchdev_port_attr_get)
421 ops && ops->switchdev_parent_id_get)
422 return dev; 403 return dev;
423 404
424 netdev_for_each_lower_dev(dev, lower_dev, iter) { 405 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)
432 413
433static struct net_device *switchdev_get_dev_by_nhs(struct fib_info *fi) 414static struct net_device *switchdev_get_dev_by_nhs(struct fib_info *fi)
434{ 415{
435 struct netdev_phys_item_id psid; 416 struct switchdev_attr attr = {
436 struct netdev_phys_item_id prev_psid; 417 .id = SWITCHDEV_ATTR_PORT_PARENT_ID,
418 };
419 struct switchdev_attr prev_attr;
437 struct net_device *dev = NULL; 420 struct net_device *dev = NULL;
438 int nhsel; 421 int nhsel;
439 422
@@ -449,17 +432,18 @@ static struct net_device *switchdev_get_dev_by_nhs(struct fib_info *fi)
449 if (!dev) 432 if (!dev)
450 return NULL; 433 return NULL;
451 434
452 if (switchdev_parent_id_get(dev, &psid)) 435 if (switchdev_port_attr_get(dev, &attr))
453 return NULL; 436 return NULL;
454 437
455 if (nhsel > 0) { 438 if (nhsel > 0) {
456 if (prev_psid.id_len != psid.id_len) 439 if (prev_attr.ppid.id_len != attr.ppid.id_len)
457 return NULL; 440 return NULL;
458 if (memcmp(prev_psid.id, psid.id, psid.id_len)) 441 if (memcmp(prev_attr.ppid.id, attr.ppid.id,
442 attr.ppid.id_len))
459 return NULL; 443 return NULL;
460 } 444 }
461 445
462 prev_psid = psid; 446 prev_attr = attr;
463 } 447 }
464 448
465 return dev; 449 return dev;