Skip to content

Commit 24bdfdd

Browse files
nvmmaxanakryiko
authored andcommitted
selftests/bpf: Fix xdp_synproxy build failure if CONFIG_NF_CONNTRACK=m/n
When CONFIG_NF_CONNTRACK=m, struct bpf_ct_opts and enum member BPF_F_CURRENT_NETNS are not exposed. This commit allows building the xdp_synproxy selftest in such cases. Note that nf_conntrack must be loaded before running the test if it's compiled as a module. This commit also allows this selftest to be successfully compiled when CONFIG_NF_CONNTRACK is disabled. One unused local variable of type struct bpf_ct_opts is also removed. Fixes: fb5cd0c ("selftests/bpf: Add selftests for raw syncookie helpers") Reported-by: Yauheni Kaliuta <[email protected]> Signed-off-by: Maxim Mikityanskiy <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 06cd4e9 commit 24bdfdd

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

tools/testing/selftests/bpf/progs/xdp_synproxy_kern.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,30 @@ struct {
7777
__uint(max_entries, MAX_ALLOWED_PORTS);
7878
} allowed_ports SEC(".maps");
7979

80+
/* Some symbols defined in net/netfilter/nf_conntrack_bpf.c are unavailable in
81+
* vmlinux.h if CONFIG_NF_CONNTRACK=m, so they are redefined locally.
82+
*/
83+
84+
struct bpf_ct_opts___local {
85+
s32 netns_id;
86+
s32 error;
87+
u8 l4proto;
88+
u8 dir;
89+
u8 reserved[2];
90+
} __attribute__((preserve_access_index));
91+
92+
#define BPF_F_CURRENT_NETNS (-1)
93+
8094
extern struct nf_conn *bpf_xdp_ct_lookup(struct xdp_md *xdp_ctx,
8195
struct bpf_sock_tuple *bpf_tuple,
8296
__u32 len_tuple,
83-
struct bpf_ct_opts *opts,
97+
struct bpf_ct_opts___local *opts,
8498
__u32 len_opts) __ksym;
8599

86100
extern struct nf_conn *bpf_skb_ct_lookup(struct __sk_buff *skb_ctx,
87101
struct bpf_sock_tuple *bpf_tuple,
88102
u32 len_tuple,
89-
struct bpf_ct_opts *opts,
103+
struct bpf_ct_opts___local *opts,
90104
u32 len_opts) __ksym;
91105

92106
extern void bpf_ct_release(struct nf_conn *ct) __ksym;
@@ -393,7 +407,7 @@ static __always_inline int tcp_dissect(void *data, void *data_end,
393407

394408
static __always_inline int tcp_lookup(void *ctx, struct header_pointers *hdr, bool xdp)
395409
{
396-
struct bpf_ct_opts ct_lookup_opts = {
410+
struct bpf_ct_opts___local ct_lookup_opts = {
397411
.netns_id = BPF_F_CURRENT_NETNS,
398412
.l4proto = IPPROTO_TCP,
399413
};
@@ -714,10 +728,6 @@ static __always_inline int syncookie_handle_ack(struct header_pointers *hdr)
714728
static __always_inline int syncookie_part1(void *ctx, void *data, void *data_end,
715729
struct header_pointers *hdr, bool xdp)
716730
{
717-
struct bpf_ct_opts ct_lookup_opts = {
718-
.netns_id = BPF_F_CURRENT_NETNS,
719-
.l4proto = IPPROTO_TCP,
720-
};
721731
int ret;
722732

723733
ret = tcp_dissect(data, data_end, hdr);

0 commit comments

Comments
 (0)