nexthop: Add support for active-backup nexthop type
Subsystems (4)
David Ahern
maintainercover nexthop: Add support for active-backup nexthop type
This set adds support for a new nexthop group - active-backup. The intent is that the group describes a primary nexthop with a backup option if the primary is not available. Since nexthop code removes entries on carrier or admin down this really means the backup applies when the neighbor entry for the active becomes invalid. In that case, the lookup atomically switches to use the backup. I mentioned this use case at LPC2019[0] as a follow on use case for the nexthop code.
The first 6 patches refactor existing code to get ready for a new group type. The a-b group is added in patch 7 with selftests in patch 8.
[0] https://linuxplumbersconf.org/event/4/contributions/434/attachments/251/436/nexthop-objects-talk.pdf
David Ahern (8):
nexthop: Rename nexthop_free_mpath
nexthop: Refactor nexthop_select_path
nexthop: Refactor nexthop_for_each_fib6_nh
nexthop: Move nexthop_get_nhc_lookup to nexthop.c
nexthop: Move nexthop_uses_dev to nexthop.c
nexthop: Add primary_only argument to nexthop_for_each_fib6_nh
nexthop: Add support for active-backup nexthop type
selftests: Add active-backup nexthop tests
include/net/nexthop.h | 106 +++--- include/uapi/linux/nexthop.h | 1 + net/ipv4/fib_semantics.c | 6 +- net/ipv4/nexthop.c | 356 +++++++++++++++++--- net/ipv6/ip6_fib.c | 4 +- net/ipv6/route.c | 37 +- tools/testing/selftests/net/fib_nexthops.sh | 334 +++++++++++++++++- 7 files changed, 713 insertions(+), 131 deletions(-)
Signature · 1 line
2.21.1 (Apple Git-122.3)
David Ahern
maintainerRFC PATCH 1/8 nexthop: Rename nexthop_free_mpath
nexthop_free_mpath really should be nexthop_free_group. Rename it.
--- net/ipv4/nexthop.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/ipv4/nexthop.c +2 -2
@@ -69,7 +69,7 @@ static void nexthop_devhash_add(struct net *net, struct nh_info *nhi)hlist_add_head (&nhi->dev_hash, head); } -static void nexthop_free_mpath (struct nexthop *nh) +static void nexthop_free_group (struct nexthop *nh) {struct nh_group *nhg;int i;
@@ -109,7 +109,7 @@ void nexthop_free_rcu(struct rcu_head *head) struct nexthop *nh = container_of(head, struct nexthop, rcu);if (nh->is_group) -nexthop_free_mpath (nh); +nexthop_free_group (nh);else nexthop_free_single (nh);
Signature · 1 line
2.21.1 (Apple Git-122.3)
David Ahern
maintainerRFC PATCH 2/8 nexthop: Refactor nexthop_select_path
In reply to David AhernMove the ipv{4,6}_good_nh calls to a separate helper.
--- net/ipv4/nexthop.c | 47 +++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-)
net/ipv4/nexthop.c +28 -19
@@ -536,6 +536,29 @@ static bool ipv4_good_nh(const struct fib_nh *nh)return !!(state &NUD_VALID ); } +/* nexthops always check if it is good and does +* not rely on a sysctl for this behavior +*/ +static bool good_nh (struct nexthop *nh) +{ +struct nh_info *nhi; +bool rc = false; + + nhi =rcu_dereference (nh->nh_info); +switch (nhi->family) { +case AF_INET : +if (ipv4_good_nh (&nhi->fib_nh)) + rc = true; +break ; +case AF_INET6 : +if (ipv6_good_nh (&nhi->fib6_nh)) + rc = true; +break ; + } + +return rc; +} +struct nexthop *nexthop_select_path (struct nexthop *nh,int hash) {struct nexthop *rc =NULL ;
@@ -548,31 +571,17 @@ struct nexthop *nexthop_select_path(struct nexthop *nh, int hash) nhg =rcu_dereference (nh->nh_grp);for (i =0 ; i < nhg->num_nh; ++i) {struct nh_grp_entry *nhge = &nhg->nh_entries[i]; -struct nh_info *nhi; +struct nexthop *nh;if (hash >atomic_read (&nhge->upper_bound))continue ; -if (nhge->nh->is_fdb_nh) -return nhge->nh; - -/* nexthops always check if it is good and does -* not rely on a sysctl for this behavior -*/ - nhi =rcu_dereference (nhge->nh->nh_info); -switch (nhi->family) { -case AF_INET : -if (ipv4_good_nh (&nhi->fib_nh)) -return nhge->nh; -break ; -case AF_INET6 : -if (ipv6_good_nh (&nhi->fib6_nh)) -return nhge->nh; -break ; - } + nh = nhge->nh; +if (nh->is_fdb_nh ||good_nh (nh)) +return nh;if (!rc) - rc = nhge->nh; + rc = nh; }return rc;
Signature · 1 line
2.21.1 (Apple Git-122.3)
David Ahern
maintainerRFC PATCH 3/8 nexthop: Refactor nexthop_for_each_fib6_nh
In reply to David AhernRefactor nexthop_for_each_fib6_nh moving standalone and group processing into helpers. Prepatory patch for adding active-backup group.
--- net/ipv4/nexthop.c | 48 +++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-)
net/ipv4/nexthop.c +33 -15
@@ -588,34 +588,52 @@ struct nexthop *nexthop_select_path(struct nexthop *nh, int hash) }EXPORT_SYMBOL_GPL (nexthop_select_path); +static int nexthop_fib6_nh_cb (struct nexthop *nh, +int (*cb)(struct fib6_nh *nh,void *arg), +void *arg) +{ +struct nh_info *nhi; + + nhi =rcu_dereference_rtnl (nh->nh_info); + +return cb (&nhi->fib6_nh, arg); +} + +static int nexthop_fib6_nhg_cb (struct nh_group *nhg, +int (*cb)(struct fib6_nh *nh,void *arg), +void *arg) +{ +int err; +int i; + +for (i =0 ; i < nhg->num_nh; i++) { +struct nh_grp_entry *nhge = &nhg->nh_entries[i]; +struct nexthop *nh = nhge->nh; + + err =nexthop_fib6_nh_cb (nh, cb, arg); +if (err) +return err; + } + +return 0 ; +} +int nexthop_for_each_fib6_nh (struct nexthop *nh,int (*cb)(struct fib6_nh *nh,void *arg),void *arg) { -struct nh_info *nhi;int err;if (nh->is_group) {struct nh_group *nhg; -int i; nhg =rcu_dereference_rtnl (nh->nh_grp); -for (i =0 ; i < nhg->num_nh; i++) { -struct nh_grp_entry *nhge = &nhg->nh_entries[i]; - - nhi =rcu_dereference_rtnl (nhge->nh->nh_info); - err =cb (&nhi->fib6_nh, arg); -if (err) -return err; - } + err =nexthop_fib6_nhg_cb (nhg, cb, arg); }else { - nhi =rcu_dereference_rtnl (nh->nh_info); - err =cb (&nhi->fib6_nh, arg); -if (err) -return err; + err =nexthop_fib6_nh_cb (nh, cb, arg); } -return 0 ; +return err; }EXPORT_SYMBOL_GPL (nexthop_for_each_fib6_nh);
Signature · 1 line
2.21.1 (Apple Git-122.3)
David Ahern
maintainerRFC PATCH 4/8 nexthop: Move nexthop_get_nhc_lookup to nexthop.c
In reply to David Ahernnexthop_get_nhc_lookup is long enough for an inline and the a-b checks are going to make it worse. Move to nexthop.c and in the process refactor so that mpath code reuses single nh lookup. Prepatory patch for adding active-backup group.
--- include/net/nexthop.h | 29 +------------------------ net/ipv4/nexthop.c | 50 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 28 deletions(-)
include/net/nexthop.h +1 -28
@@ -261,37 +261,10 @@ struct fib_nh_common *nexthop_fib_nhc(struct nexthop *nh, int nhsel) }/* called from fib_table_lookup with rcu_lock */ -static inline struct fib_nh_common *nexthop_get_nhc_lookup (const struct nexthop *nh,int fib_flags,const struct flowi4 *flp, -int *nhsel) -{ -struct nh_info *nhi; - -if (nh->is_group) { -struct nh_group *nhg =rcu_dereference (nh->nh_grp); -int i; - -for (i =0 ; i < nhg->num_nh; i++) { -struct nexthop *nhe = nhg->nh_entries[i].nh; - - nhi =rcu_dereference (nhe->nh_info); -if (fib_lookup_good_nhc (&nhi->fib_nhc, fib_flags, flp)) { - *nhsel = i; -return &nhi->fib_nhc; - } - } - }else { - nhi =rcu_dereference (nh->nh_info); -if (fib_lookup_good_nhc (&nhi->fib_nhc, fib_flags, flp)) { - *nhsel =0 ; -return &nhi->fib_nhc; - } - } - -return NULL ; -} +int *nhsel);static inline bool nexthop_uses_dev (const struct nexthop *nh,const struct net_device *dev)
net/ipv4/nexthop.c +50 -0
56 lines not on this page · raw message
Signature · 1 line
2.21.1 (Apple Git-122.3)
David Ahern
maintainerRFC PATCH 5/8 nexthop: Move nexthop_uses_dev to nexthop.c
In reply to David Ahernnexthop_uses_dev is long enough for an inline and the a-b checks are going to make it worse. Move to nexthop.c and in the process refactor so that mpath code reuses single nh lookup. Prepatory patch for adding active-backup group.
--- include/net/nexthop.h | 25 +------------------------ net/ipv4/nexthop.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 24 deletions(-)
include/net/nexthop.h +1 -24
@@ -266,30 +266,7 @@ struct fib_nh_common *nexthop_get_nhc_lookup(const struct nexthop *nh,const struct flowi4 *flp, int *nhsel); -static inline bool nexthop_uses_dev (const struct nexthop *nh, -const struct net_device *dev) -{ -struct nh_info *nhi; - -if (nh->is_group) { -struct nh_group *nhg =rcu_dereference (nh->nh_grp); -int i; - -for (i =0 ; i < nhg->num_nh; i++) { -struct nexthop *nhe = nhg->nh_entries[i].nh; - - nhi =rcu_dereference (nhe->nh_info); -if (nhc_l3mdev_matches_dev (&nhi->fib_nhc, dev)) -return true; - } - }else { - nhi =rcu_dereference (nh->nh_info); -if (nhc_l3mdev_matches_dev (&nhi->fib_nhc, dev)) -return true; - } - -return false; -} +bool nexthop_uses_dev (const struct nexthop *nh,const struct net_device *dev);static inline unsigned int fib_info_num_path (const struct fib_info *fi) {
net/ipv4/nexthop.c +35 -0
@@ -638,6 +638,41 @@ struct fib_nh_common *nexthop_get_nhc_lookup(const struct nexthop *nh,return nhc_lookup_single (nh, fib_flags, flp, nhsel); } +static bool nh_uses_dev_single (const struct nexthop *nh, +const struct net_device *dev) +{ +const struct nh_info *nhi; + + nhi =rcu_dereference (nh->nh_info); +return nhc_l3mdev_matches_dev (&nhi->fib_nhc, dev); +} + +static bool nh_uses_dev_mpath (const struct nh_group *nhg, +const struct net_device *dev) +{ +int i; + +for (i =0 ; i < nhg->num_nh; i++) { +struct nexthop *nhe = nhg->nh_entries[i].nh; + +if (nh_uses_dev_single (nhe, dev)) +return true; + } + +return false; +} + +bool nexthop_uses_dev (const struct nexthop *nh,const struct net_device *dev) +{ +if (nh->is_group) { +const struct nh_group *nhg =rcu_dereference (nh->nh_grp); + +return nh_uses_dev_mpath (nhg, dev); + } + +return nh_uses_dev_single (nh, dev); +} +static int nexthop_fib6_nh_cb (struct nexthop *nh,int (*cb)(struct fib6_nh *nh,void *arg),void *arg)
Signature · 1 line
2.21.1 (Apple Git-122.3)
David Ahern
maintainerRFC PATCH 6/8 nexthop: Add primary_only argument to nexthop_for_each_fib6_nh
In reply to David AhernFollow on patch adds support for active-backup nexthops. Control planes needs to always analyze all legs of the nexthops, but datapath only wants to consider the primary.
--- include/net/nexthop.h | 2 +- net/ipv4/nexthop.c | 6 +++--- net/ipv6/ip6_fib.c | 4 ++-- net/ipv6/route.c | 37 ++++++++++++++++++++----------------- 4 files changed, 26 insertions(+), 23 deletions(-)
include/net/nexthop.h +1 -1
@@ -346,7 +346,7 @@ static inline void nexthop_path_fib6_result(struct fib6_result *res, int hash) } } -int nexthop_for_each_fib6_nh (struct nexthop *nh, +int nexthop_for_each_fib6_nh (struct nexthop *nh,bool primary_only,int (*cb)(struct fib6_nh *nh,void *arg),void *arg);
net/ipv4/nexthop.c +3 -3
@@ -684,7 +684,7 @@ static int nexthop_fib6_nh_cb(struct nexthop *nh,return cb (&nhi->fib6_nh, arg); } -static int nexthop_fib6_nhg_cb (struct nh_group *nhg, +static int nexthop_fib6_nhg_cb (struct nh_group *nhg,bool primary_only,int (*cb)(struct fib6_nh *nh,void *arg),void *arg) {
@@ -703,7 +703,7 @@ static int nexthop_fib6_nhg_cb(struct nh_group *nhg,return 0 ; } -int nexthop_for_each_fib6_nh (struct nexthop *nh, +int nexthop_for_each_fib6_nh (struct nexthop *nh,bool primary_only,int (*cb)(struct fib6_nh *nh,void *arg),void *arg) {
@@ -713,7 +713,7 @@ int nexthop_for_each_fib6_nh(struct nexthop *nh,struct nh_group *nhg; nhg =rcu_dereference_rtnl (nh->nh_grp); - err =nexthop_fib6_nhg_cb (nhg, cb, arg); + err =nexthop_fib6_nhg_cb (nhg, primary_only, cb, arg); }else { err =nexthop_fib6_nh_cb (nh, cb, arg); }
net/ipv6/ip6_fib.c +2 -2
@@ -1009,8 +1009,8 @@ static void fib6_drop_pcpu_from(struct fib6_info *f6i, .table = table }; -nexthop_for_each_fib6_nh (f6i->nh, fib6_nh_drop_pcpu_from, - &arg); +nexthop_for_each_fib6_nh (f6i->nh, false, + fib6_nh_drop_pcpu_from, &arg); }else {struct fib6_nh *fib6_nh;
net/ipv6/route.c +20 -17
@@ -526,7 +526,7 @@ static struct fib6_nh *rt6_nh_dev_match(struct net *net, struct nexthop *nh,if (nexthop_is_blackhole (nh))return NULL ; -if (nexthop_for_each_fib6_nh (nh, __rt6_nh_dev_match, &arg)) +if (nexthop_for_each_fib6_nh (nh, true, __rt6_nh_dev_match, &arg))return arg.nh;return NULL ;
@@ -827,7 +827,8 @@ static void __find_rr_leaf(struct fib6_info *f6i_start, res->nh =nexthop_fib6_nh (f6i->nh);return ; } -if (nexthop_for_each_fib6_nh (f6i->nh, rt6_nh_find_match, +if (nexthop_for_each_fib6_nh (f6i->nh, true, + rt6_nh_find_match, &arg)) { matched = true; nh = arg.nh;
@@ -1774,8 +1775,8 @@ static int rt6_nh_flush_exceptions(struct fib6_nh *nh, void *arg)void rt6_flush_exceptions (struct fib6_info *f6i) {if (f6i->nh) -nexthop_for_each_fib6_nh (f6i->nh, rt6_nh_flush_exceptions, - f6i); +nexthop_for_each_fib6_nh (f6i->nh, false, + rt6_nh_flush_exceptions, f6i);else fib6_nh_flush_exceptions (f6i->fib6_nh, f6i); }
@@ -1897,7 +1898,7 @@ static int rt6_remove_exception_rt(struct rt6_info *rt)int rc;/* rc = 1 means an entry was found */ - rc =nexthop_for_each_fib6_nh (from->nh, + rc =nexthop_for_each_fib6_nh (from->nh, false, rt6_nh_remove_exception_rt, &arg);return rc ?0 : -ENOENT ;
@@ -1973,7 +1974,8 @@ static void rt6_update_exception_stamp_rt(struct rt6_info *rt) .gw = &rt->rt6i_gateway, }; -nexthop_for_each_fib6_nh (from->nh, fib6_nh_find_match, &arg); +nexthop_for_each_fib6_nh (from->nh, false, fib6_nh_find_match, + &arg);if (!arg.match) goto unlock;
@@ -2166,8 +2168,8 @@ void rt6_age_exceptions(struct fib6_info *f6i, .now = now }; -nexthop_for_each_fib6_nh (f6i->nh, rt6_nh_age_exceptions, - &arg); +nexthop_for_each_fib6_nh (f6i->nh, false, + rt6_nh_age_exceptions, &arg); }else {fib6_nh_age_exceptions (f6i->fib6_nh, gc_args, now); }
@@ -2768,7 +2770,7 @@ static void __ip6_rt_update_pmtu(struct dst_entry *dst, const struct sock *sk, .gw = &rt6->rt6i_gateway, }; -nexthop_for_each_fib6_nh (res.f6i->nh, +nexthop_for_each_fib6_nh (res.f6i->nh, true, fib6_nh_find_match, &arg);/* fib6_info uses a nexthop that does not have fib6_nh
@@ -2959,7 +2961,7 @@ static struct rt6_info *__ip6_route_redirect(struct net *net,if (nexthop_is_blackhole (rt->nh))continue ;/* on match, res->nh is filled in and potentially ret */ -if (nexthop_for_each_fib6_nh (rt->nh, +if (nexthop_for_each_fib6_nh (rt->nh, true, fib6_nh_redirect_match, &arg)) goto out;
@@ -3906,7 +3908,8 @@ static int ip6_del_cached_rt_nh(struct fib6_config *cfg, struct fib6_info *f6i) .f6i = f6i }; -return nexthop_for_each_fib6_nh (f6i->nh, fib6_nh_del_cached_rt, &arg); +return nexthop_for_each_fib6_nh (f6i->nh, false, + fib6_nh_del_cached_rt, &arg); } static int ip6_route_del(struct fib6_config *cfg,
@@ -4096,7 +4099,7 @@ static void rt6_do_redirect(struct dst_entry *dst, struct sock *sk, struct sk_bu .gw = &rt->rt6i_gateway, }; -nexthop_for_each_fib6_nh (res.f6i->nh, +nexthop_for_each_fib6_nh (res.f6i->nh, true, fib6_nh_find_match, &arg);/* fib6_info uses a nexthop that does not have fib6_nh
@@ -4835,8 +4838,8 @@ static int rt6_mtu_change_route(struct fib6_info *f6i, void *p_arg) arg->f6i = f6i;if (f6i->nh) {/* fib6_nh_mtu_change only returns 0, so this is safe */ -return nexthop_for_each_fib6_nh (f6i->nh, fib6_nh_mtu_change, - arg); +return nexthop_for_each_fib6_nh (f6i->nh, false, + fib6_nh_mtu_change, arg); }return fib6_nh_mtu_change (f6i->fib6_nh, arg);
@@ -5381,7 +5384,7 @@ static size_t rt6_nlmsg_size(struct fib6_info *f6i)if (f6i->nh) { nexthop_len =nla_total_size (4 );/* RTA_NH_ID */ -nexthop_for_each_fib6_nh (f6i->nh, rt6_nh_nlmsg_size, +nexthop_for_each_fib6_nh (f6i->nh, false, rt6_nh_nlmsg_size, &nexthop_len); }else {struct fib6_nh *nh = f6i->fib6_nh;
@@ -5636,7 +5639,7 @@ static bool fib6_info_uses_dev(const struct fib6_info *f6i,if (f6i->nh) {struct net_device *_dev = (struct net_device *)dev; -return !!nexthop_for_each_fib6_nh (f6i->nh, +return !!nexthop_for_each_fib6_nh (f6i->nh, true, fib6_info_nh_uses_dev, _dev); }
@@ -5769,7 +5772,7 @@ int rt6_dump_route(struct fib6_info *rt, void *p_arg, unsigned int skip)rcu_read_lock ();if (rt->nh) { - err =nexthop_for_each_fib6_nh (rt->nh, + err =nexthop_for_each_fib6_nh (rt->nh, false, rt6_nh_dump_exceptions, &w); }else {
Signature · 1 line
2.21.1 (Apple Git-122.3)
David Ahern
maintainerRFC PATCH 7/8 nexthop: Add support for active-backup nexthop type
In reply to David AhernAdd new active-backup group type. The intent is that the group describes a primary nexthop with a backup option if the primary is not available. Since nexthop code removes entries on carrier or admin down this really means the backup applies when the neighbor entry for the active becomes invalid. In that case the lookup atomically switches to use the backup.
Conceptually, the linkage is like this. For single path routes, a FIB entry references a nexthop that is a an active-backup pair:
nexthop active
{ prefix } -> a-b nexthop -<
nexthop backup
Alternatively, an active-backup nexthop can be one more entries in a multipath route:
nexthop active
nexthop 1 (ab) -< { prefix } -> mpath nexthop -< ... nexthop backup
nexthop N
The intent is to provide a fast failover option for routing daemons - the primary goes down, notification is sent to userspace, and the backup takes over until the daemon can adjust the routes.
For multipath routes this has the added benefit of providing an option to limit the flows affected by a carrier or admin down event. Currently, flows are hashed over the N-paths of a multipath route. If a path goes dead, the leg is effectively removed and all flows are potentially affected as the hashing consides now N-1 paths. With active-backup nexthops an admin can setup a backup for each leg to minimize the affected flows.
Most of this change is updating the group handling to account for the a-b pair, especially in nexthop groups. Datapath lookups should only consider the active nexthop unless it is determined bad. Route notifications and lookups will only show the existence of the active nexthop.
--- include/net/nexthop.h | 50 ++++++++-- include/uapi/linux/nexthop.h | 1 + net/ipv4/fib_semantics.c | 6 +- net/ipv4/nexthop.c | 186 ++++++++++++++++++++++++++++++++--- 4 files changed, 217 insertions(+), 26 deletions(-)
include/net/nexthop.h +42 -8
@@ -76,6 +76,7 @@ struct nh_group {struct nh_group *spare;/* spare group for removals */ u16 num_nh;bool mpath; +bool active_backup;bool has_v4;struct nh_grp_entry nh_entries[]; };
@@ -158,6 +159,17 @@ static inline bool nexthop_is_multipath(const struct nexthop *nh)return false; } +static inline bool nexthop_is_active_backup (const struct nexthop *nh) +{ +if (nh->is_group) { +struct nh_group *nh_grp; + + nh_grp =rcu_dereference_rtnl (nh->nh_grp); +return nh_grp->active_backup; + } +return false; +} +struct nexthop *nexthop_select_path (struct nexthop *nh,int hash);static inline unsigned int nexthop_num_path (const struct nexthop *nh)
@@ -168,8 +180,7 @@ static inline unsigned int nexthop_num_path(const struct nexthop *nh)struct nh_group *nh_grp; nh_grp =rcu_dereference_rtnl (nh->nh_grp); -if (nh_grp->mpath) - rc = nh_grp->num_nh; + rc = nh_grp->num_nh; }return rc;
@@ -196,9 +207,18 @@ int nexthop_mpath_fill_node(struct sk_buff *skb, struct nexthop *nh,for (i =0 ; i < nhg->num_nh; i++) {struct nexthop *nhe = nhg->nh_entries[i].nh; -struct nh_info *nhi =rcu_dereference_rtnl (nhe->nh_info); -struct fib_nh_common *nhc = &nhi->fib_nhc;int weight = nhg->nh_entries[i].weight; +struct fib_nh_common *nhc; +struct nh_info *nhi; + +if (nhe->is_group) { +struct nh_group *nhg_ab =rtnl_dereference (nhe->nh_grp); + +/* group in group is active-backup. take primary */ + nhe = nhg_ab->nh_entries[0 ].nh; + } + nhi =rcu_dereference_rtnl (nhe->nh_info); + nhc = &nhi->fib_nhc;if (fib_add_nexthop (skb, nhc, weight, rt_family) <0 )return -EMSGSIZE ;
@@ -216,7 +236,7 @@ static inline bool nexthop_is_blackhole(const struct nexthop *nh)struct nh_group *nh_grp; nh_grp =rcu_dereference_rtnl (nh->nh_grp); -if (nh_grp->num_nh >1 ) +if (nh_grp->active_backup || nh_grp->num_nh >1 )return false; nh = nh_grp->nh_entries[0 ].nh;
@@ -253,6 +273,16 @@ struct fib_nh_common *nexthop_fib_nhc(struct nexthop *nh, int nhsel) nh =nexthop_mpath_select (nh_grp, nhsel);if (!nh)return NULL ; + +/* multipath with a-b path */ +if (nh->is_group) { + nh_grp =rcu_dereference_rtnl (nh->nh_grp); + nh = nh_grp->nh_entries[0 ].nh; + } + }else if (nh_grp->active_backup) { +if (nhsel >0 ) +return NULL ; + nh = nh_grp->nh_entries[0 ].nh; } }
@@ -309,9 +339,13 @@ static inline struct fib6_nh *nexthop_fib6_nh(struct nexthop *nh)struct nh_group *nh_grp; nh_grp =rcu_dereference_rtnl (nh->nh_grp); - nh =nexthop_mpath_select (nh_grp,0 ); -if (!nh) -return NULL ; + nh = nh_grp->nh_entries[0 ].nh; + +/* mpath with active-backup path */ +if (nh->is_group) { + nh_grp =rcu_dereference_rtnl (nh->nh_grp); + nh = nh_grp->nh_entries[0 ].nh; + } } nhi =rcu_dereference_rtnl (nh->nh_info);
include/uapi/linux/nexthop.h +1 -0
@@ -22,6 +22,7 @@ struct nexthop_grp {enum {NEXTHOP_GRP_TYPE_MPATH ,/* default type if not specified */ +NEXTHOP_GRP_TYPE_ACTIVE_BACKUP , __NEXTHOP_GRP_TYPE_MAX, };
net/ipv4/fib_semantics.c +4 -2
@@ -480,10 +480,10 @@ static inline size_t fib_nlmsg_size(struct fib_info *fi) nhsize +=2 *nla_total_size (4 );/* grab encap info */ -for (i =0 ; i <fib_info_num_path (fi); i++) { +for (i =0 ; i < nhs; i++) {struct fib_nh_common *nhc =fib_info_nhc (fi, i); -if (nhc->nhc_lwtstate) { +if (nhc && nhc->nhc_lwtstate) {/* RTA_ENCAP_TYPE */ nh_encapsize +=lwtunnel_get_encap_size ( nhc->nhc_lwtstate);
@@ -1780,6 +1780,8 @@ int fib_dump_info(struct sk_buff *skb, u32 portid, u32 seq, int event, goto nla_put_failure;if (nexthop_is_blackhole (fi->nh)) rtm->rtm_type =RTN_BLACKHOLE ; +else if (nexthop_is_active_backup (fi->nh)) + nhs =1 ;if (!fi->fib_net->ipv4.sysctl_nexthop_compat_mode) goto offload; }
net/ipv4/nexthop.c +170 -16
325 lines not on this page · raw message
Signature · 1 line
2.21.1 (Apple Git-122.3)
David Ahern
maintainerRFC PATCH 8/8 selftests: Add active-backup nexthop tests
In reply to David Ahern--- tools/testing/selftests/net/fib_nexthops.sh | 334 +++++++++++++++++++- 1 file changed, 330 insertions(+), 4 deletions(-)
tools/testing/selftests/net/fib_nexthops.sh +330 -4
@@ -5,11 +5,21 @@ # 2001:db8:91::1 | 2001:db8:91::2 | # 172.16.1.1 | 172.16.1.2 | # veth1 <---|---> veth2 | -# | veth5 <--|--> veth6 172.16.101.1 +# | veth6 <--|--> veth5 172.16.101.1 # veth3 <---|---> veth4 | 2001:db8:101::1 # 172.16.2.1 | 172.16.2.2 | # 2001:db8:92::1 | 2001:db8:92::2 | # +# For active/backup testing: +# ns: me | ns: peer2 | ns: remote +# 2001:db8:81::1 | 2001:db8:81::2 | +# 172.16.81.1 | 172.16.81.2 | +# veth21 <---|---> veth22 | +# | veth26 <--|--> veth25 <--> br +# veth23 <---|---> veth24 | +# 172.16.82.1 | 172.16.82.2 | +# 2001:db8:82::1 | 2001:db8:82::2 | +# # This test is for checking IPv4 and IPv6 FIB behavior with nexthop # objects. Device reference counts and network namespace cleanup tested # by use of network namespace for peer.
@@ -19,8 +29,8 @@ ret=0 ksft_skip=4 # all tests in this script. Can be overridden with -t option -IPV4_TESTS="ipv4_fcnal ipv4_grp_fcnal ipv4_withv6_fcnal ipv4_fcnal_runtime ipv4_large_grp ipv4_compat_mode ipv4_fdb_grp_fcnal ipv4_torture" -IPV6_TESTS="ipv6_fcnal ipv6_grp_fcnal ipv6_fcnal_runtime ipv6_large_grp ipv6_compat_mode ipv6_fdb_grp_fcnal ipv6_torture" +IPV4_TESTS="ipv4_fcnal ipv4_grp_fcnal ipv4_withv6_fcnal ipv4_fcnal_runtime ipv4_large_grp ipv4_compat_mode ipv4_fdb_grp_fcnal ipv4_torture ipv4_ab_group" +IPV6_TESTS="ipv6_fcnal ipv6_grp_fcnal ipv6_fcnal_runtime ipv6_large_grp ipv6_compat_mode ipv6_fdb_grp_fcnal ipv6_torture ipv6_ab_group" ALL_TESTS="basic ${IPV4_TESTS} ${IPV6_TESTS}" TESTS="${ALL_TESTS}"
@@ -179,11 +189,60 @@ setup() set +e } +setup_ab() +{ + create_ns peer2 + + set -e + $IP li add veth21 type veth peer name veth22 + $IP li set veth21 up + $IP addr add 172.16.81.1/24 dev veth21 + $IP -6 addr add 2001:db8:81::1/64 dev veth21 nodad + + $IP li add veth23 type veth peer name veth24 + $IP li set veth23 up + $IP addr add 172.16.82.1/24 dev veth23 + $IP -6 addr add 2001:db8:82::1/64 dev veth23 nodad + + $IP li set veth22 netns peer2 up + ip -netns peer2 addr add 172.16.81.2/24 dev veth22 + ip -netns peer2 -6 addr add 2001:db8:81::2/64 dev veth22 nodad + + $IP li set veth24 netns peer2 up + ip -netns peer2 addr add 172.16.82.2/24 dev veth24 + ip -netns peer2 -6 addr add 2001:db8:82::2/64 dev veth24 nodad + + ip -netns remote li set veth5 down + ip -netns remote addr flush dev veth5 + ip -netns remote li add br0 type bridge + ip -netns remote li add veth25 type veth peer name veth26 + ip -netns remote li set veth25 master br0 up + ip -netns remote li set veth5 master br0 up + ip -netns remote li set br0 up + + ip -netns remote addr add dev br0 172.16.101.1/24 + ip -netns remote -6 addr add dev br0 2001:db8:101::1/64 nodad + + ip -netns remote li set veth26 netns peer2 up + ip -netns peer2 addr add dev veth26 172.16.101.3/24 + ip -netns peer2 -6 addr add dev veth26 2001:db8:101::3/64 nodad + + ip -netns remote ro add 172.16.1.0/24 nexthop via 172.16.101.2 + ip -netns remote ro add 172.16.2.0/24 nexthop via 172.16.101.2 + ip -netns remote ro add 172.16.81.0/24 nexthop via 172.16.101.3 + ip -netns remote ro add 172.16.82.0/24 nexthop via 172.16.101.3 + ip -netns remote -6 ro add 2001:db8:91::/64 nexthop via 2001:db8:101::2 + ip -netns remote -6 ro add 2001:db8:92::/64 nexthop via 2001:db8:101::2 + ip -netns remote -6 ro add 2001:db8:81::/64 nexthop via 2001:db8:101::3 + ip -netns remote -6 ro add 2001:db8:82::/64 nexthop via 2001:db8:101::3 + set +e +} + cleanup() { local ns - for ns in me peer remote; do + for ns in me peer peer2 remote; do ip netns del ${ns} 2>/dev/null done }
@@ -335,6 +394,273 @@ stop_ip_monitor() return $rc } +################################################################################ +# active-backup nexthops + +check_nexthop_ab_support() +{ + $IP nexthop help 2>&1 | grep -q active-backup + if [ $? -ne 0 ]; then + echo "SKIP: iproute2 too old, missing active-backup nexthop support" + return $ksft_skip + fi +} + +ipv6_ab_group() +{ + local rc + + echo + echo "IPv6 active-backup groups" + echo "-------------------------" + + check_nexthop_ab_support + if [ $? -eq $ksft_skip ]; then + return $ksft_skip + fi + + setup_ab + + run_cmd "$IP nexthop add id 11 via 2001:db8:91::2 dev veth1" + run_cmd "$IP nexthop add id 12 via 2001:db8:81::2 dev veth21" + run_cmd "$IP nexthop add id 101 group 11/12 active-backup" + check_nexthop "id 101" "id 101 group 11/12 active-backup" + log_test $? 0 "Create active-backup group" + + run_cmd "$IP ro add 2001:db8:101::/64 nhid 101" + check_route6 "2001:db8:101::1" "2001:db8:101::/64 nhid 101 via 2001:db8:91::2 dev veth1 metric 1024" + log_test $? 0 "Route list shows active device" + + $IP -o ro get 2001:db8:101::1 2>/dev/null | grep -q "dev veth1" + log_test $? 0 "Route get shows active device" + + # carrier down or admin down on nexthop device removes that entry + run_cmd "ip -netns peer li set veth2 down" + check_nexthop "id 101" "id 101 group 12 active-backup" + log_test $? 0 "Carrier down removes active" + + $IP -o ro get 2001:db8:101::1 2>/dev/null | grep -q "dev veth21" + log_test $? 0 "Route get shows backup device" + + run_cmd "$IP li set veth21 down" + $IP nexthop sh id 101 2>/dev/null + log_test $? 2 "Link down on backup removes nexthop" + + check_route "2001:db8:101::1" "" + log_test $? 0 "Route removed after a-b nexthop removed" + + # restore device state + run_cmd "ip -netns peer li set veth2 up" + run_cmd "$IP li set veth21 up" + + # a/b with mpath + run_cmd "$IP nexthop flush" + run_cmd "$IP nexthop add id 11 via 2001:db8:91::2 dev veth1" + run_cmd "$IP nexthop add id 12 via 2001:db8:92::2 dev veth3" + run_cmd "$IP nexthop add id 21 via 2001:db8:81::2 dev veth21" + run_cmd "$IP nexthop add id 22 via 2001:db8:82::2 dev veth23" + run_cmd "$IP nexthop add id 101 group 11/21 active-backup" + run_cmd "$IP nexthop add id 102 group 12/22 active-backup" + run_cmd "$IP nexthop add id 103 group 101/102" + log_test $? 0 "Multipath with active-backup paths" + + run_cmd "$IP nexthop ls" + run_cmd "$IP ro add 2001:db8:101::/64 nhid 103" + run_cmd "ip netns exec me ping -c1 -w1 2001:db8:101::1" + log_test $? 0 "ping with multipath containing active-backup paths" + + run_cmd "ip -netns peer li set veth2 down" + check_nexthop "id 103" "id 103 group 101/102" + log_test $? 0 "Multipath still shows 2 paths after carrier down in a/b" + + run_cmd "ip netns exec me ping -c1 -w1 2001:db8:101::1" + log_test $? 0 "ping with still works after carrier down" + + run_cmd "ip -netns peer li set veth2 up" + run_cmd "$IP nexthop ls" + run_cmd "$IP -6 ro ls" + + run_cmd "$IP li set veth21 down" + check_nexthop "id 103" "id 103 group 102" + log_test $? 0 "Multipath shows 1 path after admin down on new active" + run_cmd "ip netns exec me ping -c1 -w1 2001:db8:101::1" + log_test $? 0 "ping with still works after mpath loss of a-b path" + + run_cmd "$IP li set veth21 up" + run_cmd "$IP nexthop ls" + run_cmd "$IP -6 ro ls" + + # + # negative tests + # + # active points to invalid gw + run_cmd "$IP nexthop flush" + run_cmd "$IP nexthop add id 11 via 2001:db8:91::3 dev veth1" + run_cmd "$IP nexthop add id 12 via 2001:db8:81::2 dev veth21" + run_cmd "$IP nexthop add id 101 group 11/12 active-backup" + run_cmd "$IP ro add 2001:db8:101::/64 nhid 101" + + # failed neigh for gateway - should fallback to backup + run_cmd "${IP} -6 neigh add 2001:db8:91::3 dev veth1 nud failed" + $IP -o ro get 2001:db8:101::1 2>/dev/null | grep -q "dev veth21" + log_test $? 0 "Route get shows backup device with invalid neigh" + + run_cmd "$IP nexthop flush" + run_cmd "$IP nexthop add id 11 via 2001:db8:91::2 dev veth1" + run_cmd "$IP nexthop add id 12 via 2001:db8:92::2 dev veth3" + run_cmd "$IP nexthop add id 13 blackhole" + run_cmd "$IP nexthop add id 21 via 2001:db8:81::2 dev veth21" + run_cmd "$IP nexthop add id 22 via 2001:db8:82::2 dev veth23" + + # must have 2 entries of equal weight + run_cmd "$IP nexthop add id 101 group 11 active-backup" + log_test $? 2 "Active-backup nexthop can not have 1 entry" + run_cmd "$IP nexthop add id 101 group 11/12/21 active-backup" + log_test $? 2 "Active-backup nexthop can not have more than 2 entries" + run_cmd "$IP nexthop add id 101 group 11,5/21,4 active-backup" + log_test $? 2 "Active-backup nexthops must have equal weight" + run_cmd "$IP nexthop add id 101 group 11,3/21,3 active-backup" + log_test $? 2 "Active-backup nexthops must have default weight" + + # can not replace a/b group with mpath + run_cmd "$IP nexthop add id 101 group 11/21 active-backup" + run_cmd "$IP nexthop replace id 101 group 11/21 mpath" + log_test $? 2 "Can not change group type" + + # a/b group can not have blackhole + run_cmd "$IP nexthop add id 102 group 11/13 active-backup" + log_test $? 2 "Active-backup can use blackhole as a path" +} + +ipv4_ab_group() +{ + local rc + + echo + echo "IPv4 active-backup groups" + echo "-------------------------" + + check_nexthop_ab_support + if [ $? -eq $ksft_skip ]; then + return $ksft_skip + fi + + setup_ab + + run_cmd "$IP nexthop add id 11 via 172.16.1.2 dev veth1" + run_cmd "$IP nexthop add id 12 via 172.16.81.2 dev veth21" + run_cmd "$IP nexthop add id 101 group 11/12 active-backup" + check_nexthop "id 101" "id 101 group 11/12 active-backup" + log_test $? 0 "Create active-backup group" + + run_cmd "$IP ro add 172.16.101.0/24 nhid 101" + check_route "172.16.101.1" "172.16.101.0/24 nhid 101 via 172.16.1.2 dev veth1" + log_test $? 0 "Route list shows active device" + + $IP -o ro get 172.16.101.1 2>/dev/null | grep -q "dev veth1" + log_test $? 0 "Route get shows active device" + + # carrier down or admin down on nexthop device removes that entry + run_cmd "ip -netns peer li set veth2 down" + check_nexthop "id 101" "id 101 group 12 active-backup" + log_test $? 0 "Carrier down removes active" + + $IP -o ro get 172.16.101.1 2>/dev/null | grep -q "dev veth21" + log_test $? 0 "Route get shows backup device" + + run_cmd "$IP li set veth21 down" + $IP nexthop sh id 101 2>/dev/null + log_test $? 2 "Link down on backup removes nexthop" + + check_route "172.16.101.1" "" + log_test $? 0 "Route removed after a-b nexthop removed" + + # restore device state + run_cmd "ip -netns peer li set veth2 up" + run_cmd "$IP li set veth21 up" + + # a/b with mpath + run_cmd "$IP nexthop flush" + run_cmd "$IP nexthop add id 11 via 172.16.1.2 dev veth1" + run_cmd "$IP nexthop add id 12 via 172.16.2.2 dev veth3" + run_cmd "$IP nexthop add id 21 via 172.16.81.2 dev veth21" + run_cmd "$IP nexthop add id 22 via 172.16.82.2 dev veth23" + run_cmd "$IP nexthop add id 101 group 11/21 active-backup" + run_cmd "$IP nexthop add id 102 group 12/22 active-backup" + run_cmd "$IP nexthop add id 103 group 101/102" + log_test $? 0 "Multipath with active-backup paths" + + run_cmd "$IP nexthop ls" + run_cmd "$IP ro add 172.16.101.0/24 nhid 103" + run_cmd "ip netns exec me ping -c1 -w1 172.16.101.1" + log_test $? 0 "ping with multipath containing active-backup paths" + + run_cmd "ip -netns peer li set veth2 down" + check_nexthop "id 103" "id 103 group 101/102" + log_test $? 0 "Multipath still shows 2 paths after carrier down in a/b" + + run_cmd "ip netns exec me ping -c1 -w1 172.16.101.1" + log_test $? 0 "ping with still works after carrier down" + + run_cmd "ip -netns peer li set veth2 up" + run_cmd "$IP nexthop ls" + run_cmd "$IP ro ls" + + run_cmd "$IP li set veth21 down" + check_nexthop "id 103" "id 103 group 102" + log_test $? 0 "Multipath shows 1 path after admin down on new active" + run_cmd "ip netns exec me ping -c1 -w1 172.16.101.1" + log_test $? 0 "ping with still works after mpath loss of a-b path" + + run_cmd "$IP li set veth21 up" + run_cmd "$IP nexthop ls" + run_cmd "$IP ro ls" + + # + # negative tests + # + # active points to invalid gw + run_cmd "$IP nexthop flush" + run_cmd "$IP nexthop add id 11 via 172.16.1.3 dev veth1" + run_cmd "$IP nexthop add id 12 via 172.16.81.2 dev veth21" + run_cmd "$IP nexthop add id 101 group 11/12 active-backup" + run_cmd "$IP ro add 172.16.101.0/24 nhid 101" + + # failed neigh for gateway - should fallback to backup + run_cmd "${IP} neigh add 172.16.1.3 dev veth1 nud failed" + $IP -o ro get 172.16.101.1 2>/dev/null | grep -q "dev veth21" + log_test $? 0 "Route get shows backup device with invalid neigh" + + run_cmd "$IP nexthop flush" + run_cmd "$IP nexthop add id 11 via 172.16.1.2 dev veth1" + run_cmd "$IP nexthop add id 12 via 172.16.2.2 dev veth3" + run_cmd "$IP nexthop add id 13 blackhole" + run_cmd "$IP nexthop add id 21 via 172.16.81.2 dev veth21" + run_cmd "$IP nexthop add id 22 via 172.16.82.2 dev veth23" + + # must have 2 entries of equal weight + run_cmd "$IP nexthop add id 101 group 11 active-backup" + log_test $? 2 "Active-backup nexthop can not have 1 entry" + run_cmd "$IP nexthop add id 101 group 11/12/21 active-backup" + log_test $? 2 "Active-backup nexthop can not have more than 2 entries" + run_cmd "$IP nexthop add id 101 group 11,5/21,4 active-backup" + log_test $? 2 "Active-backup nexthops must have equal weight" + run_cmd "$IP nexthop add id 101 group 11,3/21,3 active-backup" + log_test $? 2 "Active-backup nexthops must have default weight" + + # can not replace a/b group with mpath + run_cmd "$IP nexthop add id 101 group 11/21 active-backup" + run_cmd "$IP nexthop replace id 101 group 11/21 mpath" + log_test $? 2 "Can not change group type" + + # a/b group can not have blackhole + run_cmd "$IP nexthop add id 102 group 11/13 active-backup" + log_test $? 2 "Active-backup can use blackhole as a path" +} + +################################################################################ +# fdb nexthops + check_nexthop_fdb_support() { $IP nexthop help 2>&1 | grep -q fdb
Signature · 1 line
2.21.1 (Apple Git-122.3)