libbpf: Add support for BPF XDP link
Sync UAPI header and add support for using bpf_link-based XDP attachment. Make xdp/ prog type set expected attach type. Kernel didn't enforce attach_type for XDP programs before, so there is no backwards compatiblity issues there. Also fix section_names selftest to recognize that xdp prog types now have expected attach type. Signed-off-by: Andrii Nakryiko <andriin@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20200722064603.3350758-8-andriin@fb.com
This commit is contained in:

committed by
Alexei Starovoitov

parent
c1931c9784
commit
dc8698cac7
@@ -230,6 +230,7 @@ enum bpf_attach_type {
|
||||
BPF_CGROUP_INET_SOCK_RELEASE,
|
||||
BPF_XDP_CPUMAP,
|
||||
BPF_SK_LOOKUP,
|
||||
BPF_XDP,
|
||||
__MAX_BPF_ATTACH_TYPE
|
||||
};
|
||||
|
||||
@@ -242,6 +243,7 @@ enum bpf_link_type {
|
||||
BPF_LINK_TYPE_CGROUP = 3,
|
||||
BPF_LINK_TYPE_ITER = 4,
|
||||
BPF_LINK_TYPE_NETNS = 5,
|
||||
BPF_LINK_TYPE_XDP = 6,
|
||||
|
||||
MAX_BPF_LINK_TYPE,
|
||||
};
|
||||
@@ -614,7 +616,10 @@ union bpf_attr {
|
||||
|
||||
struct { /* struct used by BPF_LINK_CREATE command */
|
||||
__u32 prog_fd; /* eBPF program to attach */
|
||||
__u32 target_fd; /* object to attach to */
|
||||
union {
|
||||
__u32 target_fd; /* object to attach to */
|
||||
__u32 target_ifindex; /* target ifindex */
|
||||
};
|
||||
__u32 attach_type; /* attach type */
|
||||
__u32 flags; /* extra flags */
|
||||
} link_create;
|
||||
@@ -4064,6 +4069,9 @@ struct bpf_link_info {
|
||||
__u32 netns_ino;
|
||||
__u32 attach_type;
|
||||
} netns;
|
||||
struct {
|
||||
__u32 ifindex;
|
||||
} xdp;
|
||||
};
|
||||
} __attribute__((aligned(8)));
|
||||
|
||||
|
Reference in New Issue
Block a user