• Yonghong Song's avatar
    libbpf: Fix bpf_xdp_query() in old kernels · c8ee37bd
    Yonghong Song authored
    Commit 04d58f1b("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 04d58f1b.
    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: 04d58f1b ("libbpf: add API to get XDP/XSK supported features")
    Signed-off-by: default avatarYonghong Song <yhs@fb.com>
    Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
    Link: https://lore.kernel.org/bpf/20230227224943.1153459-1-yhs@fb.com
    c8ee37bd
netlink.c 21.4 KB