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

Configure Feed

Select the types of activity you want to include in your feed.

libbpf: Fix bpf_xdp_query() in old kernels

Commit 04d58f1b26a4("libbpf: add API to get XDP/XSK supported features")
added feature_flags to struct bpf_xdp_query_opts. If a user uses
bpf_xdp_query_opts with feature_flags member, the bpf_xdp_query()
will check whether 'netdev' family exists or not in the kernel.
If it does not exist, the bpf_xdp_query() will return -ENOENT.

But 'netdev' family does not exist in old kernels as it is
introduced in the same patch set as Commit 04d58f1b26a4.
So old kernel with newer libbpf won't work properly with
bpf_xdp_query() api call.

To fix this issue, if the return value of
libbpf_netlink_resolve_genl_family_id() is -ENOENT, bpf_xdp_query()
will just return 0, skipping the rest of xdp feature query.
This preserves backward compatibility.

Fixes: 04d58f1b26a4 ("libbpf: add API to get XDP/XSK supported features")
Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20230227224943.1153459-1-yhs@fb.com

authored by

Yonghong Song and committed by
Andrii Nakryiko
c8ee37bd 0a504fa1

+7 -1
+7 -1
tools/lib/bpf/netlink.c
··· 468 468 return 0; 469 469 470 470 err = libbpf_netlink_resolve_genl_family_id("netdev", sizeof("netdev"), &id); 471 - if (err < 0) 471 + if (err < 0) { 472 + if (err == -ENOENT) { 473 + opts->feature_flags = 0; 474 + goto skip_feature_flags; 475 + } 472 476 return libbpf_err(err); 477 + } 473 478 474 479 memset(&req, 0, sizeof(req)); 475 480 req.nh.nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN); ··· 494 489 495 490 opts->feature_flags = md.flags; 496 491 492 + skip_feature_flags: 497 493 return 0; 498 494 } 499 495