Skip to content

Commit 91134d8

Browse files
iamkafaiborkmann
authored andcommitted
bpf: Test BPF_PROG_TYPE_SK_REUSEPORT
This patch add tests for the new BPF_PROG_TYPE_SK_REUSEPORT. The tests cover: - IPv4/IPv6 + TCP/UDP - TCP syncookie - TCP fastopen - Cases when the bpf_sk_select_reuseport() returning errors - Cases when the bpf prog returns SK_DROP - Values from sk_reuseport_md - outer_map => reuseport_array The test depends on commit 3eee1f7 ("bpf: fix bpf_skb_load_bytes_relative pkt length check") Signed-off-by: Martin KaFai Lau <[email protected]> Acked-by: Alexei Starovoitov <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]>
1 parent 6bc8529 commit 91134d8

File tree

7 files changed

+912
-2
lines changed

7 files changed

+912
-2
lines changed

tools/lib/bpf/bpf.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ int bpf_create_map_xattr(const struct bpf_create_map_attr *create_attr)
9292
attr.btf_key_type_id = create_attr->btf_key_type_id;
9393
attr.btf_value_type_id = create_attr->btf_value_type_id;
9494
attr.map_ifindex = create_attr->map_ifindex;
95+
attr.inner_map_fd = create_attr->inner_map_fd;
9596

9697
return sys_bpf(BPF_MAP_CREATE, &attr, sizeof(attr));
9798
}

tools/lib/bpf/bpf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ struct bpf_create_map_attr {
3939
__u32 btf_key_type_id;
4040
__u32 btf_value_type_id;
4141
__u32 map_ifindex;
42+
__u32 inner_map_fd;
4243
};
4344

4445
int bpf_create_map_xattr(const struct bpf_create_map_attr *create_attr);

tools/testing/selftests/bpf/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ $(TEST_CUSTOM_PROGS): $(OUTPUT)/%: %.c
2323
TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test_progs \
2424
test_align test_verifier_log test_dev_cgroup test_tcpbpf_user \
2525
test_sock test_btf test_sockmap test_lirc_mode2_user get_cgroup_id_user \
26-
test_socket_cookie test_cgroup_storage
26+
test_socket_cookie test_cgroup_storage test_select_reuseport
2727

2828
TEST_GEN_FILES = test_pkt_access.o test_xdp.o test_l4lb.o test_tcp_estats.o test_obj_id.o \
2929
test_pkt_md_access.o test_xdp_redirect.o test_xdp_meta.o sockmap_parse_prog.o \
@@ -34,7 +34,7 @@ TEST_GEN_FILES = test_pkt_access.o test_xdp.o test_l4lb.o test_tcp_estats.o test
3434
test_btf_haskv.o test_btf_nokv.o test_sockmap_kern.o test_tunnel_kern.o \
3535
test_get_stack_rawtp.o test_sockmap_kern.o test_sockhash_kern.o \
3636
test_lwt_seg6local.o sendmsg4_prog.o sendmsg6_prog.o test_lirc_mode2_kern.o \
37-
get_cgroup_id_kern.o socket_cookie_prog.o
37+
get_cgroup_id_kern.o socket_cookie_prog.o test_select_reuseport_kern.o
3838

3939
# Order correspond to 'make run_tests' order
4040
TEST_PROGS := test_kmod.sh \

tools/testing/selftests/bpf/bpf_helpers.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ static int (*bpf_xdp_adjust_tail)(void *ctx, int offset) =
111111
static int (*bpf_skb_get_xfrm_state)(void *ctx, int index, void *state,
112112
int size, int flags) =
113113
(void *) BPF_FUNC_skb_get_xfrm_state;
114+
static int (*bpf_sk_select_reuseport)(void *ctx, void *map, void *key, __u32 flags) =
115+
(void *) BPF_FUNC_sk_select_reuseport;
114116
static int (*bpf_get_stack)(void *ctx, void *buf, int size, int flags) =
115117
(void *) BPF_FUNC_get_stack;
116118
static int (*bpf_fib_lookup)(void *ctx, struct bpf_fib_lookup *params,
@@ -173,6 +175,8 @@ struct bpf_map_def {
173175

174176
static int (*bpf_skb_load_bytes)(void *ctx, int off, void *to, int len) =
175177
(void *) BPF_FUNC_skb_load_bytes;
178+
static int (*bpf_skb_load_bytes_relative)(void *ctx, int off, void *to, int len, __u32 start_header) =
179+
(void *) BPF_FUNC_skb_load_bytes_relative;
176180
static int (*bpf_skb_store_bytes)(void *ctx, int off, void *from, int len, int flags) =
177181
(void *) BPF_FUNC_skb_store_bytes;
178182
static int (*bpf_l3_csum_replace)(void *ctx, int off, int from, int to, int flags) =

0 commit comments

Comments
 (0)