libbpf: Fix bpf_xdp_query() in old kernels
authorYonghong Song <yhs@fb.com>
Mon, 27 Feb 2023 22:49:43 +0000 (14:49 -0800)
committerAndrii Nakryiko <andrii@kernel.org>
Mon, 27 Feb 2023 23:26:12 +0000 (15:26 -0800)
commitc8ee37bde4021a275d2e4f33bd48d54912bb00c4
tree442ecafd51e79a65816658a9e659b42988533240
parent0a504fa1a780332760f2a4369a1adc3ee9f620d0
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
tools/lib/bpf/netlink.c