libbpf: Fix XDP program load regression for old kernels
authorAndrii Nakryiko <andriin@fb.com>
Thu, 24 Sep 2020 17:17:05 +0000 (10:17 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 24 Sep 2020 17:33:02 +0000 (10:33 -0700)
commit87f92ac4c12758c4da3bbe4393f1d884b610b8a6
treec29e50b1a386a9fb5ceb6d7de735f21712ecb819
parent1245008122d7311683d70c05b2eea167a314fb5f
libbpf: Fix XDP program load regression for old kernels

Fix regression in libbpf, introduced by XDP link change, which causes XDP
programs to fail to be loaded into kernel due to specified BPF_XDP
expected_attach_type. While kernel doesn't enforce expected_attach_type for
BPF_PROG_TYPE_XDP, some old kernels already support XDP program, but they
don't yet recognize expected_attach_type field in bpf_attr, so setting it to
non-zero value causes program load to fail.

Luckily, libbpf already has a mechanism to deal with such cases, so just make
expected_attach_type optional for XDP programs.

Fixes: dc8698cac7aa ("libbpf: Add support for BPF XDP link")
Reported-by: Nikita Shirokov <tehnerd@tehnerd.com>
Reported-by: Udip Pant <udippant@fb.com>
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20200924171705.3803628-1-andriin@fb.com
tools/lib/bpf/libbpf.c