diff options
author | Jiri Pirko <jiri@mellanox.com> | 2015-10-01 05:03:45 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-10-03 07:49:39 -0400 |
commit | 648b4a995a057187ddd77cdb181e6a0b24ab2959 (patch) | |
tree | 28535b6300765d1411c7a7e4a30015de227cb947 /net/switchdev | |
parent | 52ba57cfdc4c90da3bf996dfbe0c5feb731eb477 (diff) |
switchdev: bring back switchdev_obj and use it as a generic object param
Replace "void *obj" with a generic structure. Introduce couple of
helpers along that.
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Acked-by: Scott Feldman <sfeldma@gmail.com>
Reviewed-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/switchdev')
-rw-r--r-- | net/switchdev/switchdev.c | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/net/switchdev/switchdev.c b/net/switchdev/switchdev.c index 250d013d64c6..0402b3633100 100644 --- a/net/switchdev/switchdev.c +++ b/net/switchdev/switchdev.c | |||
@@ -270,7 +270,8 @@ int switchdev_port_attr_set(struct net_device *dev, struct switchdev_attr *attr) | |||
270 | EXPORT_SYMBOL_GPL(switchdev_port_attr_set); | 270 | EXPORT_SYMBOL_GPL(switchdev_port_attr_set); |
271 | 271 | ||
272 | static int __switchdev_port_obj_add(struct net_device *dev, | 272 | static int __switchdev_port_obj_add(struct net_device *dev, |
273 | enum switchdev_obj_id id, const void *obj, | 273 | enum switchdev_obj_id id, |
274 | const struct switchdev_obj *obj, | ||
274 | struct switchdev_trans *trans) | 275 | struct switchdev_trans *trans) |
275 | { | 276 | { |
276 | const struct switchdev_ops *ops = dev->switchdev_ops; | 277 | const struct switchdev_ops *ops = dev->switchdev_ops; |
@@ -309,7 +310,7 @@ static int __switchdev_port_obj_add(struct net_device *dev, | |||
309 | * rtnl_lock must be held. | 310 | * rtnl_lock must be held. |
310 | */ | 311 | */ |
311 | int switchdev_port_obj_add(struct net_device *dev, enum switchdev_obj_id id, | 312 | int switchdev_port_obj_add(struct net_device *dev, enum switchdev_obj_id id, |
312 | const void *obj) | 313 | const struct switchdev_obj *obj) |
313 | { | 314 | { |
314 | struct switchdev_trans trans; | 315 | struct switchdev_trans trans; |
315 | int err; | 316 | int err; |
@@ -361,7 +362,7 @@ EXPORT_SYMBOL_GPL(switchdev_port_obj_add); | |||
361 | * @obj: object to delete | 362 | * @obj: object to delete |
362 | */ | 363 | */ |
363 | int switchdev_port_obj_del(struct net_device *dev, enum switchdev_obj_id id, | 364 | int switchdev_port_obj_del(struct net_device *dev, enum switchdev_obj_id id, |
364 | const void *obj) | 365 | const struct switchdev_obj *obj) |
365 | { | 366 | { |
366 | const struct switchdev_ops *ops = dev->switchdev_ops; | 367 | const struct switchdev_ops *ops = dev->switchdev_ops; |
367 | struct net_device *lower_dev; | 368 | struct net_device *lower_dev; |
@@ -395,7 +396,8 @@ EXPORT_SYMBOL_GPL(switchdev_port_obj_del); | |||
395 | * @cb: function to call with a filled object | 396 | * @cb: function to call with a filled object |
396 | */ | 397 | */ |
397 | int switchdev_port_obj_dump(struct net_device *dev, enum switchdev_obj_id id, | 398 | int switchdev_port_obj_dump(struct net_device *dev, enum switchdev_obj_id id, |
398 | void *obj, int (*cb)(void *obj)) | 399 | struct switchdev_obj *obj, |
400 | switchdev_obj_dump_cb_t *cb) | ||
399 | { | 401 | { |
400 | const struct switchdev_ops *ops = dev->switchdev_ops; | 402 | const struct switchdev_ops *ops = dev->switchdev_ops; |
401 | struct net_device *lower_dev; | 403 | struct net_device *lower_dev; |
@@ -521,9 +523,9 @@ static int switchdev_port_vlan_dump_put(struct switchdev_vlan_dump *dump) | |||
521 | return 0; | 523 | return 0; |
522 | } | 524 | } |
523 | 525 | ||
524 | static int switchdev_port_vlan_dump_cb(void *obj) | 526 | static int switchdev_port_vlan_dump_cb(struct switchdev_obj *obj) |
525 | { | 527 | { |
526 | struct switchdev_obj_port_vlan *vlan = obj; | 528 | struct switchdev_obj_port_vlan *vlan = SWITCHDEV_OBJ_PORT_VLAN(obj); |
527 | struct switchdev_vlan_dump *dump = | 529 | struct switchdev_vlan_dump *dump = |
528 | container_of(vlan, struct switchdev_vlan_dump, vlan); | 530 | container_of(vlan, struct switchdev_vlan_dump, vlan); |
529 | int err = 0; | 531 | int err = 0; |
@@ -585,7 +587,7 @@ static int switchdev_port_vlan_fill(struct sk_buff *skb, struct net_device *dev, | |||
585 | if ((filter_mask & RTEXT_FILTER_BRVLAN) || | 587 | if ((filter_mask & RTEXT_FILTER_BRVLAN) || |
586 | (filter_mask & RTEXT_FILTER_BRVLAN_COMPRESSED)) { | 588 | (filter_mask & RTEXT_FILTER_BRVLAN_COMPRESSED)) { |
587 | err = switchdev_port_obj_dump(dev, SWITCHDEV_OBJ_ID_PORT_VLAN, | 589 | err = switchdev_port_obj_dump(dev, SWITCHDEV_OBJ_ID_PORT_VLAN, |
588 | &dump.vlan, | 590 | &dump.vlan.obj, |
589 | switchdev_port_vlan_dump_cb); | 591 | switchdev_port_vlan_dump_cb); |
590 | if (err) | 592 | if (err) |
591 | goto err_out; | 593 | goto err_out; |
@@ -700,11 +702,11 @@ static int switchdev_port_br_afspec(struct net_device *dev, | |||
700 | struct nlattr *afspec, | 702 | struct nlattr *afspec, |
701 | int (*f)(struct net_device *dev, | 703 | int (*f)(struct net_device *dev, |
702 | enum switchdev_obj_id id, | 704 | enum switchdev_obj_id id, |
703 | const void *obj)) | 705 | const struct switchdev_obj *obj)) |
704 | { | 706 | { |
705 | struct nlattr *attr; | 707 | struct nlattr *attr; |
706 | struct bridge_vlan_info *vinfo; | 708 | struct bridge_vlan_info *vinfo; |
707 | struct switchdev_obj_port_vlan vlan = { 0 }; | 709 | struct switchdev_obj_port_vlan vlan = { {}, 0 }; |
708 | int rem; | 710 | int rem; |
709 | int err; | 711 | int err; |
710 | 712 | ||
@@ -725,7 +727,7 @@ static int switchdev_port_br_afspec(struct net_device *dev, | |||
725 | vlan.vid_end = vinfo->vid; | 727 | vlan.vid_end = vinfo->vid; |
726 | if (vlan.vid_end <= vlan.vid_begin) | 728 | if (vlan.vid_end <= vlan.vid_begin) |
727 | return -EINVAL; | 729 | return -EINVAL; |
728 | err = f(dev, SWITCHDEV_OBJ_ID_PORT_VLAN, &vlan); | 730 | err = f(dev, SWITCHDEV_OBJ_ID_PORT_VLAN, &vlan.obj); |
729 | if (err) | 731 | if (err) |
730 | return err; | 732 | return err; |
731 | memset(&vlan, 0, sizeof(vlan)); | 733 | memset(&vlan, 0, sizeof(vlan)); |
@@ -734,7 +736,7 @@ static int switchdev_port_br_afspec(struct net_device *dev, | |||
734 | return -EINVAL; | 736 | return -EINVAL; |
735 | vlan.vid_begin = vinfo->vid; | 737 | vlan.vid_begin = vinfo->vid; |
736 | vlan.vid_end = vinfo->vid; | 738 | vlan.vid_end = vinfo->vid; |
737 | err = f(dev, SWITCHDEV_OBJ_ID_PORT_VLAN, &vlan); | 739 | err = f(dev, SWITCHDEV_OBJ_ID_PORT_VLAN, &vlan.obj); |
738 | if (err) | 740 | if (err) |
739 | return err; | 741 | return err; |
740 | memset(&vlan, 0, sizeof(vlan)); | 742 | memset(&vlan, 0, sizeof(vlan)); |
@@ -824,7 +826,7 @@ int switchdev_port_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], | |||
824 | .vid = vid, | 826 | .vid = vid, |
825 | }; | 827 | }; |
826 | 828 | ||
827 | return switchdev_port_obj_add(dev, SWITCHDEV_OBJ_ID_PORT_FDB, &fdb); | 829 | return switchdev_port_obj_add(dev, SWITCHDEV_OBJ_ID_PORT_FDB, &fdb.obj); |
828 | } | 830 | } |
829 | EXPORT_SYMBOL_GPL(switchdev_port_fdb_add); | 831 | EXPORT_SYMBOL_GPL(switchdev_port_fdb_add); |
830 | 832 | ||
@@ -848,7 +850,7 @@ int switchdev_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[], | |||
848 | .vid = vid, | 850 | .vid = vid, |
849 | }; | 851 | }; |
850 | 852 | ||
851 | return switchdev_port_obj_del(dev, SWITCHDEV_OBJ_ID_PORT_FDB, &fdb); | 853 | return switchdev_port_obj_del(dev, SWITCHDEV_OBJ_ID_PORT_FDB, &fdb.obj); |
852 | } | 854 | } |
853 | EXPORT_SYMBOL_GPL(switchdev_port_fdb_del); | 855 | EXPORT_SYMBOL_GPL(switchdev_port_fdb_del); |
854 | 856 | ||
@@ -860,9 +862,9 @@ struct switchdev_fdb_dump { | |||
860 | int idx; | 862 | int idx; |
861 | }; | 863 | }; |
862 | 864 | ||
863 | static int switchdev_port_fdb_dump_cb(void *obj) | 865 | static int switchdev_port_fdb_dump_cb(struct switchdev_obj *obj) |
864 | { | 866 | { |
865 | struct switchdev_obj_port_fdb *fdb = obj; | 867 | struct switchdev_obj_port_fdb *fdb = SWITCHDEV_OBJ_PORT_FDB(obj); |
866 | struct switchdev_fdb_dump *dump = | 868 | struct switchdev_fdb_dump *dump = |
867 | container_of(fdb, struct switchdev_fdb_dump, fdb); | 869 | container_of(fdb, struct switchdev_fdb_dump, fdb); |
868 | u32 portid = NETLINK_CB(dump->cb->skb).portid; | 870 | u32 portid = NETLINK_CB(dump->cb->skb).portid; |
@@ -926,7 +928,7 @@ int switchdev_port_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb, | |||
926 | .idx = idx, | 928 | .idx = idx, |
927 | }; | 929 | }; |
928 | 930 | ||
929 | switchdev_port_obj_dump(dev, SWITCHDEV_OBJ_ID_PORT_FDB, &dump.fdb, | 931 | switchdev_port_obj_dump(dev, SWITCHDEV_OBJ_ID_PORT_FDB, &dump.fdb.obj, |
930 | switchdev_port_fdb_dump_cb); | 932 | switchdev_port_fdb_dump_cb); |
931 | return dump.idx; | 933 | return dump.idx; |
932 | } | 934 | } |
@@ -1033,7 +1035,8 @@ int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi, | |||
1033 | if (!dev) | 1035 | if (!dev) |
1034 | return 0; | 1036 | return 0; |
1035 | 1037 | ||
1036 | err = switchdev_port_obj_add(dev, SWITCHDEV_OBJ_ID_IPV4_FIB, &ipv4_fib); | 1038 | err = switchdev_port_obj_add(dev, SWITCHDEV_OBJ_ID_IPV4_FIB, |
1039 | &ipv4_fib.obj); | ||
1037 | if (!err) | 1040 | if (!err) |
1038 | fi->fib_flags |= RTNH_F_OFFLOAD; | 1041 | fi->fib_flags |= RTNH_F_OFFLOAD; |
1039 | 1042 | ||
@@ -1075,7 +1078,8 @@ int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi, | |||
1075 | if (!dev) | 1078 | if (!dev) |
1076 | return 0; | 1079 | return 0; |
1077 | 1080 | ||
1078 | err = switchdev_port_obj_del(dev, SWITCHDEV_OBJ_ID_IPV4_FIB, &ipv4_fib); | 1081 | err = switchdev_port_obj_del(dev, SWITCHDEV_OBJ_ID_IPV4_FIB, |
1082 | &ipv4_fib.obj); | ||
1079 | if (!err) | 1083 | if (!err) |
1080 | fi->fib_flags &= ~RTNH_F_OFFLOAD; | 1084 | fi->fib_flags &= ~RTNH_F_OFFLOAD; |
1081 | 1085 | ||