diff options
author | Scott Feldman <sfeldma@gmail.com> | 2015-05-10 12:48:06 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-05-12 18:43:55 -0400 |
commit | 58c2cb16b116d7feace621bd6b647bbabacfa225 (patch) | |
tree | 01dba341543ad33607c95eee011fded948a755e0 /net/switchdev/switchdev.c | |
parent | 85fdb956726ff2af609e2f6ea7be781e4db74a07 (diff) |
switchdev: convert fib_ipv4_add/del over to switchdev_port_obj_add/del
The IPv4 FIB ops convert nicely to the switchdev objs and we're left with
only four switchdev ops: port get/set and port add/del. Other objs will
follow, such as FDB. So go ahead and convert IPv4 FIB over to switchdev
obj for consistency, anticipating more objs to come.
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/switchdev/switchdev.c')
-rw-r--r-- | net/switchdev/switchdev.c | 49 |
1 files changed, 31 insertions, 18 deletions
diff --git a/net/switchdev/switchdev.c b/net/switchdev/switchdev.c index 9210355ec965..65d49d4477b9 100644 --- a/net/switchdev/switchdev.c +++ b/net/switchdev/switchdev.c | |||
@@ -641,8 +641,19 @@ static struct net_device *switchdev_get_dev_by_nhs(struct fib_info *fi) | |||
641 | int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi, | 641 | int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi, |
642 | u8 tos, u8 type, u32 nlflags, u32 tb_id) | 642 | u8 tos, u8 type, u32 nlflags, u32 tb_id) |
643 | { | 643 | { |
644 | struct switchdev_obj fib_obj = { | ||
645 | .id = SWITCHDEV_OBJ_IPV4_FIB, | ||
646 | .ipv4_fib = { | ||
647 | .dst = htonl(dst), | ||
648 | .dst_len = dst_len, | ||
649 | .fi = fi, | ||
650 | .tos = tos, | ||
651 | .type = type, | ||
652 | .nlflags = nlflags, | ||
653 | .tb_id = tb_id, | ||
654 | }, | ||
655 | }; | ||
644 | struct net_device *dev; | 656 | struct net_device *dev; |
645 | const struct switchdev_ops *ops; | ||
646 | int err = 0; | 657 | int err = 0; |
647 | 658 | ||
648 | /* Don't offload route if using custom ip rules or if | 659 | /* Don't offload route if using custom ip rules or if |
@@ -660,15 +671,10 @@ int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi, | |||
660 | dev = switchdev_get_dev_by_nhs(fi); | 671 | dev = switchdev_get_dev_by_nhs(fi); |
661 | if (!dev) | 672 | if (!dev) |
662 | return 0; | 673 | return 0; |
663 | ops = dev->switchdev_ops; | 674 | |
664 | 675 | err = switchdev_port_obj_add(dev, &fib_obj); | |
665 | if (ops->switchdev_fib_ipv4_add) { | 676 | if (!err) |
666 | err = ops->switchdev_fib_ipv4_add(dev, htonl(dst), dst_len, | 677 | fi->fib_flags |= RTNH_F_EXTERNAL; |
667 | fi, tos, type, nlflags, | ||
668 | tb_id); | ||
669 | if (!err) | ||
670 | fi->fib_flags |= RTNH_F_EXTERNAL; | ||
671 | } | ||
672 | 678 | ||
673 | return err; | 679 | return err; |
674 | } | 680 | } |
@@ -689,8 +695,19 @@ EXPORT_SYMBOL_GPL(switchdev_fib_ipv4_add); | |||
689 | int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi, | 695 | int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi, |
690 | u8 tos, u8 type, u32 tb_id) | 696 | u8 tos, u8 type, u32 tb_id) |
691 | { | 697 | { |
698 | struct switchdev_obj fib_obj = { | ||
699 | .id = SWITCHDEV_OBJ_IPV4_FIB, | ||
700 | .ipv4_fib = { | ||
701 | .dst = htonl(dst), | ||
702 | .dst_len = dst_len, | ||
703 | .fi = fi, | ||
704 | .tos = tos, | ||
705 | .type = type, | ||
706 | .nlflags = 0, | ||
707 | .tb_id = tb_id, | ||
708 | }, | ||
709 | }; | ||
692 | struct net_device *dev; | 710 | struct net_device *dev; |
693 | const struct switchdev_ops *ops; | ||
694 | int err = 0; | 711 | int err = 0; |
695 | 712 | ||
696 | if (!(fi->fib_flags & RTNH_F_EXTERNAL)) | 713 | if (!(fi->fib_flags & RTNH_F_EXTERNAL)) |
@@ -699,14 +716,10 @@ int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi, | |||
699 | dev = switchdev_get_dev_by_nhs(fi); | 716 | dev = switchdev_get_dev_by_nhs(fi); |
700 | if (!dev) | 717 | if (!dev) |
701 | return 0; | 718 | return 0; |
702 | ops = dev->switchdev_ops; | ||
703 | 719 | ||
704 | if (ops->switchdev_fib_ipv4_del) { | 720 | err = switchdev_port_obj_del(dev, &fib_obj); |
705 | err = ops->switchdev_fib_ipv4_del(dev, htonl(dst), dst_len, | 721 | if (!err) |
706 | fi, tos, type, tb_id); | 722 | fi->fib_flags &= ~RTNH_F_EXTERNAL; |
707 | if (!err) | ||
708 | fi->fib_flags &= ~RTNH_F_EXTERNAL; | ||
709 | } | ||
710 | 723 | ||
711 | return err; | 724 | return err; |
712 | } | 725 | } |