Skip to content

Commit

Permalink
Merge branch 'nh-flushing'
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
David S. Miller committed Apr 19, 2021
2 parents 56aa7b2 + bf5eb67 commit c589fa1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
14 changes: 6 additions & 8 deletions net/ipv4/nexthop.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
15 changes: 15 additions & 0 deletions tools/testing/selftests/net/fib_nexthops.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit c589fa1

Please sign in to comment.