Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'nexthop-nexthop-dump-fixes'

Ido Schimmel says:

====================
nexthop: Nexthop dump fixes

Patches #1 and #3 fix two problems related to nexthops and nexthop
buckets dump, respectively. Patch #2 is a preparation for the third
patch.

The pattern described in these patches of splitting the NLMSG_DONE to a
separate response is prevalent in other rtnetlink dump callbacks. I
don't know if it's because I'm missing something or if this was done
intentionally to ensure the message is delivered to user space. After
commit 0642840b8bb0 ("af_netlink: ensure that NLMSG_DONE never fails in
dumps") this is no longer necessary and I can improve these dump
callbacks assuming this analysis is correct.

No regressions in existing tests:

# ./fib_nexthops.sh
[...]
Tests passed: 230
Tests failed: 0
====================

Link: https://lore.kernel.org/r/20230808075233.3337922-1-idosch@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+17 -21
+7 -21
net/ipv4/nexthop.c
··· 3221 3221 &rtm_dump_nexthop_cb, &filter); 3222 3222 if (err < 0) { 3223 3223 if (likely(skb->len)) 3224 - goto out; 3225 - goto out_err; 3224 + err = skb->len; 3226 3225 } 3227 3226 3228 - out: 3229 - err = skb->len; 3230 - out_err: 3231 3227 cb->seq = net->nexthop.seq; 3232 3228 nl_dump_check_consistent(cb, nlmsg_hdr(skb)); 3233 3229 return err; ··· 3363 3367 dd->filter.res_bucket_nh_id != nhge->nh->id) 3364 3368 continue; 3365 3369 3370 + dd->ctx->bucket_index = bucket_index; 3366 3371 err = nh_fill_res_bucket(skb, nh, bucket, bucket_index, 3367 3372 RTM_NEWNEXTHOPBUCKET, portid, 3368 3373 cb->nlh->nlmsg_seq, NLM_F_MULTI, 3369 3374 cb->extack); 3370 - if (err < 0) { 3371 - if (likely(skb->len)) 3372 - goto out; 3373 - goto out_err; 3374 - } 3375 + if (err) 3376 + return err; 3375 3377 } 3376 3378 3377 3379 dd->ctx->done_nh_idx = dd->ctx->nh.idx + 1; 3378 - bucket_index = 0; 3380 + dd->ctx->bucket_index = 0; 3379 3381 3380 - out: 3381 - err = skb->len; 3382 - out_err: 3383 - dd->ctx->bucket_index = bucket_index; 3384 - return err; 3382 + return 0; 3385 3383 } 3386 3384 3387 3385 static int rtm_dump_nexthop_bucket_cb(struct sk_buff *skb, ··· 3424 3434 3425 3435 if (err < 0) { 3426 3436 if (likely(skb->len)) 3427 - goto out; 3428 - goto out_err; 3437 + err = skb->len; 3429 3438 } 3430 3439 3431 - out: 3432 - err = skb->len; 3433 - out_err: 3434 3440 cb->seq = net->nexthop.seq; 3435 3441 nl_dump_check_consistent(cb, nlmsg_hdr(skb)); 3436 3442 return err;
+10
tools/testing/selftests/net/fib_nexthops.sh
··· 1981 1981 1982 1982 run_cmd "$IP link set dev lo up" 1983 1983 1984 + # Dump should not loop endlessly when maximum nexthop ID is configured. 1985 + run_cmd "$IP nexthop add id $((2**32-1)) blackhole" 1986 + run_cmd "timeout 5 $IP nexthop" 1987 + log_test $? 0 "Maximum nexthop ID dump" 1988 + 1984 1989 # 1985 1990 # groups 1986 1991 # ··· 2205 2200 2206 2201 run_cmd "$IP nexthop bucket list fdb" 2207 2202 log_test $? 255 "Dump all nexthop buckets with invalid 'fdb' keyword" 2203 + 2204 + # Dump should not loop endlessly when maximum nexthop ID is configured. 2205 + run_cmd "$IP nexthop add id $((2**32-1)) group 1/2 type resilient buckets 4" 2206 + run_cmd "timeout 5 $IP nexthop bucket" 2207 + log_test $? 0 "Maximum nexthop ID dump" 2208 2208 2209 2209 # 2210 2210 # resilient nexthop buckets get requests