diff options
author | David S. Miller <davem@davemloft.net> | 2021-04-20 01:20:35 +0300 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2021-04-20 01:20:35 +0300 |
commit | c589fa10f1ed2d963c3ceaa40005d30231a0e556 (patch) | |
tree | 88e81aa6a5ae89f4deb0f71177ca939fbcc3b052 | |
parent | 56aa7b21a5a7d30484ab5833641cb172356225f1 (diff) | |
parent | bf5eb67dc80a75e0756269084b087c06f0360b78 (diff) | |
download | linux-c589fa10f1ed2d963c3ceaa40005d30231a0e556.tar.xz |
Merge branch 'nh-flushing'
Ido Schimmel says:
====================
nexthop: Support large scale nexthop flushing
Patch #1 fixes a day-one bug in the nexthop code and allows "ip nexthop
flush" to work correctly with large number of nexthops that do not fit
in a single-part dump.
Patch #2 adds a test case.
Targeting at net-next since this use case never worked, the flow is
pretty obscure and such a large number of nexthops is unlikely to be
used in any real-world scenario.
Tested with fib_nexthops.sh:
Tests passed: 219
Tests failed: 0
====================
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | net/ipv4/nexthop.c | 14 | ||||
-rwxr-xr-x | tools/testing/selftests/net/fib_nexthops.sh | 15 |
2 files changed, 21 insertions, 8 deletions
diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c index 5a2fc8798d20..4075230b14c6 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -3140,26 +3140,24 @@ static int rtm_dump_walk_nexthops(struct sk_buff *skb, void *data) { struct rb_node *node; - int idx = 0, s_idx; + int s_idx; int err; s_idx = ctx->idx; for (node = rb_first(root); node; node = rb_next(node)) { struct nexthop *nh; - if (idx < s_idx) - goto cont; - nh = rb_entry(node, struct nexthop, rb_node); - ctx->idx = idx; + if (nh->id < s_idx) + continue; + + ctx->idx = nh->id; err = nh_cb(skb, cb, nh, data); if (err) return err; -cont: - idx++; } - ctx->idx = idx; + ctx->idx++; return 0; } diff --git a/tools/testing/selftests/net/fib_nexthops.sh b/tools/testing/selftests/net/fib_nexthops.sh index 56dd0c6f2e96..49774a8a7736 100755 --- a/tools/testing/selftests/net/fib_nexthops.sh +++ b/tools/testing/selftests/net/fib_nexthops.sh @@ -1933,6 +1933,21 @@ basic() log_test $? 2 "Nexthop group and blackhole" $IP nexthop flush >/dev/null 2>&1 + + # Test to ensure that flushing with a multi-part nexthop dump works as + # expected. + local batch_file=$(mktemp) + + for i in $(seq 1 $((64 * 1024))); do + echo "nexthop add id $i blackhole" >> $batch_file + done + + $IP -b $batch_file + $IP nexthop flush >/dev/null 2>&1 + [[ $($IP nexthop | wc -l) -eq 0 ]] + log_test $? 0 "Large scale nexthop flushing" + + rm $batch_file } check_nexthop_buckets_balance() |