bpf: selftest: Ensure the child sk inherited all bpf_sock_ops_cb_flags
This patch adds a test to ensure the child sk inherited everything from the bpf_sock_ops_cb_flags of the listen sk: 1. Sets one more cb_flags (BPF_SOCK_OPS_STATE_CB_FLAG) to the listen sk in test_tcp_hdr_options.c 2. Saves the skops->bpf_sock_ops_cb_flags when handling the newly established passive connection 3. CHECK() it is the same as the listen sk This also covers the fastopen case as the existing test_tcp_hdr_options.c does. Signed-off-by: Martin KaFai Lau <kafai@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20201002013454.2542367-1-kafai@fb.com
This commit is contained in:
parent
82f45c6c4a
commit
96d46c5085
@ -264,9 +264,19 @@ static int check_error_linum(const struct sk_fds *sk_fds)
|
||||
|
||||
static void check_hdr_and_close_fds(struct sk_fds *sk_fds)
|
||||
{
|
||||
const __u32 expected_inherit_cb_flags =
|
||||
BPF_SOCK_OPS_PARSE_UNKNOWN_HDR_OPT_CB_FLAG |
|
||||
BPF_SOCK_OPS_WRITE_HDR_OPT_CB_FLAG |
|
||||
BPF_SOCK_OPS_STATE_CB_FLAG;
|
||||
|
||||
if (sk_fds_shutdown(sk_fds))
|
||||
goto check_linum;
|
||||
|
||||
if (CHECK(expected_inherit_cb_flags != skel->bss->inherit_cb_flags,
|
||||
"Unexpected inherit_cb_flags", "0x%x != 0x%x\n",
|
||||
skel->bss->inherit_cb_flags, expected_inherit_cb_flags))
|
||||
goto check_linum;
|
||||
|
||||
if (check_hdr_stg(&exp_passive_hdr_stg, sk_fds->passive_fd,
|
||||
"passive_hdr_stg"))
|
||||
goto check_linum;
|
||||
@ -321,6 +331,8 @@ static void reset_test(void)
|
||||
memset(&skel->bss->active_estab_in, 0, optsize);
|
||||
memset(&skel->bss->active_fin_in, 0, optsize);
|
||||
|
||||
skel->bss->inherit_cb_flags = 0;
|
||||
|
||||
skel->data->test_kind = TCPOPT_EXP;
|
||||
skel->data->test_magic = 0xeB9F;
|
||||
|
||||
|
@ -304,10 +304,10 @@ int misc_estab(struct bpf_sock_ops *skops)
|
||||
passive_lport_n = __bpf_htons(passive_lport_h);
|
||||
bpf_setsockopt(skops, SOL_TCP, TCP_SAVE_SYN,
|
||||
&true_val, sizeof(true_val));
|
||||
set_hdr_cb_flags(skops);
|
||||
set_hdr_cb_flags(skops, 0);
|
||||
break;
|
||||
case BPF_SOCK_OPS_TCP_CONNECT_CB:
|
||||
set_hdr_cb_flags(skops);
|
||||
set_hdr_cb_flags(skops, 0);
|
||||
break;
|
||||
case BPF_SOCK_OPS_PARSE_HDR_OPT_CB:
|
||||
return handle_parse_hdr(skops);
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
__u8 test_kind = TCPOPT_EXP;
|
||||
__u16 test_magic = 0xeB9F;
|
||||
__u32 inherit_cb_flags = 0;
|
||||
|
||||
struct bpf_test_option passive_synack_out = {};
|
||||
struct bpf_test_option passive_fin_out = {};
|
||||
@ -467,6 +468,8 @@ static int handle_passive_estab(struct bpf_sock_ops *skops)
|
||||
struct tcphdr *th;
|
||||
int err;
|
||||
|
||||
inherit_cb_flags = skops->bpf_sock_ops_cb_flags;
|
||||
|
||||
err = load_option(skops, &passive_estab_in, true);
|
||||
if (err == -ENOENT) {
|
||||
/* saved_syn is not found. It was in syncookie mode.
|
||||
@ -600,10 +603,10 @@ int estab(struct bpf_sock_ops *skops)
|
||||
case BPF_SOCK_OPS_TCP_LISTEN_CB:
|
||||
bpf_setsockopt(skops, SOL_TCP, TCP_SAVE_SYN,
|
||||
&true_val, sizeof(true_val));
|
||||
set_hdr_cb_flags(skops);
|
||||
set_hdr_cb_flags(skops, BPF_SOCK_OPS_STATE_CB_FLAG);
|
||||
break;
|
||||
case BPF_SOCK_OPS_TCP_CONNECT_CB:
|
||||
set_hdr_cb_flags(skops);
|
||||
set_hdr_cb_flags(skops, 0);
|
||||
break;
|
||||
case BPF_SOCK_OPS_PARSE_HDR_OPT_CB:
|
||||
return handle_parse_hdr(skops);
|
||||
|
@ -110,12 +110,13 @@ static inline void clear_hdr_cb_flags(struct bpf_sock_ops *skops)
|
||||
BPF_SOCK_OPS_WRITE_HDR_OPT_CB_FLAG));
|
||||
}
|
||||
|
||||
static inline void set_hdr_cb_flags(struct bpf_sock_ops *skops)
|
||||
static inline void set_hdr_cb_flags(struct bpf_sock_ops *skops, __u32 extra)
|
||||
{
|
||||
bpf_sock_ops_cb_flags_set(skops,
|
||||
skops->bpf_sock_ops_cb_flags |
|
||||
BPF_SOCK_OPS_PARSE_UNKNOWN_HDR_OPT_CB_FLAG |
|
||||
BPF_SOCK_OPS_WRITE_HDR_OPT_CB_FLAG);
|
||||
BPF_SOCK_OPS_WRITE_HDR_OPT_CB_FLAG |
|
||||
extra);
|
||||
}
|
||||
static inline void
|
||||
clear_parse_all_hdr_cb_flags(struct bpf_sock_ops *skops)
|
||||
|
Loading…
Reference in New Issue
Block a user