Skip to content

Commit 7c74b0b

Browse files
dsaherndavem330
authored andcommitted
ipv4: Update fib_select_default to handle nexthop objects
A user reported [0] hitting the WARN_ON in fib_info_nh: [ 8633.839816] ------------[ cut here ]------------ [ 8633.839819] WARNING: CPU: 0 PID: 1719 at include/net/nexthop.h:251 fib_select_path+0x303/0x381 ... [ 8633.839846] RIP: 0010:fib_select_path+0x303/0x381 ... [ 8633.839848] RSP: 0018:ffffb04d407f7d00 EFLAGS: 00010286 [ 8633.839850] RAX: 0000000000000000 RBX: ffff9460b9897ee8 RCX: 00000000000000fe [ 8633.839851] RDX: 0000000000000000 RSI: 00000000ffffffff RDI: 0000000000000000 [ 8633.839852] RBP: ffff946076049850 R08: 0000000059263a83 R09: ffff9460840e4000 [ 8633.839853] R10: 0000000000000014 R11: 0000000000000000 R12: ffffb04d407f7dc0 [ 8633.839854] R13: ffffffffa4ce3240 R14: 0000000000000000 R15: ffff9460b7681f60 [ 8633.839857] FS: 00007fcac2e02700(0000) GS:ffff9460bdc00000(0000) knlGS:0000000000000000 [ 8633.839858] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 8633.839859] CR2: 00007f27beb77e28 CR3: 0000000077734000 CR4: 00000000000006f0 [ 8633.839867] Call Trace: [ 8633.839871] ip_route_output_key_hash_rcu+0x421/0x890 [ 8633.839873] ip_route_output_key_hash+0x5e/0x80 [ 8633.839876] ip_route_output_flow+0x1a/0x50 [ 8633.839878] __ip4_datagram_connect+0x154/0x310 [ 8633.839880] ip4_datagram_connect+0x28/0x40 [ 8633.839882] __sys_connect+0xd6/0x100 ... The WARN_ON is triggered in fib_select_default which is invoked when there are multiple default routes. Update the function to use fib_info_nhc and convert the nexthop checks to use fib_nh_common. Add test case that covers the affected code path. [0] FRRouting/frr#6089 Fixes: 493ced1 ("ipv4: Allow routes to use nexthop objects") Signed-off-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c025966 commit 7c74b0b

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

net/ipv4/fib_semantics.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,7 +2014,7 @@ static void fib_select_default(const struct flowi4 *flp, struct fib_result *res)
20142014

20152015
hlist_for_each_entry_rcu(fa, fa_head, fa_list) {
20162016
struct fib_info *next_fi = fa->fa_info;
2017-
struct fib_nh *nh;
2017+
struct fib_nh_common *nhc;
20182018

20192019
if (fa->fa_slen != slen)
20202020
continue;
@@ -2037,8 +2037,8 @@ static void fib_select_default(const struct flowi4 *flp, struct fib_result *res)
20372037
fa->fa_type != RTN_UNICAST)
20382038
continue;
20392039

2040-
nh = fib_info_nh(next_fi, 0);
2041-
if (!nh->fib_nh_gw4 || nh->fib_nh_scope != RT_SCOPE_LINK)
2040+
nhc = fib_info_nhc(next_fi, 0);
2041+
if (!nhc->nhc_gw_family || nhc->nhc_scope != RT_SCOPE_LINK)
20422042
continue;
20432043

20442044
fib_alias_accessed(fa);

tools/testing/selftests/net/fib_nexthops.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,29 @@ ipv4_fcnal_runtime()
749749
run_cmd "ip netns exec me ping -c1 -w1 172.16.101.1"
750750
log_test $? 0 "Ping - multipath"
751751

752+
run_cmd "$IP ro delete 172.16.101.1/32 nhid 122"
753+
754+
#
755+
# multiple default routes
756+
# - tests fib_select_default
757+
run_cmd "$IP nexthop add id 501 via 172.16.1.2 dev veth1"
758+
run_cmd "$IP ro add default nhid 501"
759+
run_cmd "$IP ro add default via 172.16.1.3 dev veth1 metric 20"
760+
run_cmd "ip netns exec me ping -c1 -w1 172.16.101.1"
761+
log_test $? 0 "Ping - multiple default routes, nh first"
762+
763+
# flip the order
764+
run_cmd "$IP ro del default nhid 501"
765+
run_cmd "$IP ro del default via 172.16.1.3 dev veth1 metric 20"
766+
run_cmd "$IP ro add default via 172.16.1.2 dev veth1 metric 20"
767+
run_cmd "$IP nexthop replace id 501 via 172.16.1.3 dev veth1"
768+
run_cmd "$IP ro add default nhid 501 metric 20"
769+
run_cmd "ip netns exec me ping -c1 -w1 172.16.101.1"
770+
log_test $? 0 "Ping - multiple default routes, nh second"
771+
772+
run_cmd "$IP nexthop delete nhid 501"
773+
run_cmd "$IP ro del default"
774+
752775
#
753776
# IPv4 with blackhole nexthops
754777
#

0 commit comments

Comments
 (0)