Commit 8cac7a59 authored by Martin KaFai Lau's avatar Martin KaFai Lau Committed by Andrii Nakryiko

selftests/bpf: Test skops->skb_hwtstamp

This patch tests reading the skops->skb_hwtstamp field.

A local test was also done such that the shinfo hwtstamp was temporary
set to a non zero value in the kernel bpf_skops_parse_hdr()
and the same value can be read by the skops test.

An adjustment is needed to the btf_dump selftest because
the changes in the 'struct bpf_sock_ops'.
Signed-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Acked-by: default avatarYonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20221107230420.4192307-4-martin.lau@linux.dev
parent 52929912
...@@ -791,11 +791,11 @@ static void test_btf_dump_struct_data(struct btf *btf, struct btf_dump *d, ...@@ -791,11 +791,11 @@ static void test_btf_dump_struct_data(struct btf *btf, struct btf_dump *d,
TEST_BTF_DUMP_DATA_OVER(btf, d, "struct", str, struct bpf_sock_ops, TEST_BTF_DUMP_DATA_OVER(btf, d, "struct", str, struct bpf_sock_ops,
sizeof(struct bpf_sock_ops) - 1, sizeof(struct bpf_sock_ops) - 1,
"(struct bpf_sock_ops){\n\t.op = (__u32)1,\n", "(struct bpf_sock_ops){\n\t.op = (__u32)1,\n",
{ .op = 1, .skb_tcp_flags = 2}); { .op = 1, .skb_hwtstamp = 2});
TEST_BTF_DUMP_DATA_OVER(btf, d, "struct", str, struct bpf_sock_ops, TEST_BTF_DUMP_DATA_OVER(btf, d, "struct", str, struct bpf_sock_ops,
sizeof(struct bpf_sock_ops) - 1, sizeof(struct bpf_sock_ops) - 1,
"(struct bpf_sock_ops){\n\t.op = (__u32)1,\n", "(struct bpf_sock_ops){\n\t.op = (__u32)1,\n",
{ .op = 1, .skb_tcp_flags = 0}); { .op = 1, .skb_hwtstamp = 0});
} }
static void test_btf_dump_var_data(struct btf *btf, struct btf_dump *d, static void test_btf_dump_var_data(struct btf *btf, struct btf_dump *d,
......
...@@ -505,6 +505,8 @@ static void misc(void) ...@@ -505,6 +505,8 @@ static void misc(void)
ASSERT_EQ(misc_skel->bss->nr_fin, 1, "unexpected nr_fin"); ASSERT_EQ(misc_skel->bss->nr_fin, 1, "unexpected nr_fin");
ASSERT_EQ(misc_skel->bss->nr_hwtstamp, 0, "nr_hwtstamp");
check_linum: check_linum:
ASSERT_FALSE(check_error_linum(&sk_fds), "check_error_linum"); ASSERT_FALSE(check_error_linum(&sk_fds), "check_error_linum");
sk_fds_close(&sk_fds); sk_fds_close(&sk_fds);
......
...@@ -27,6 +27,7 @@ unsigned int nr_pure_ack = 0; ...@@ -27,6 +27,7 @@ unsigned int nr_pure_ack = 0;
unsigned int nr_data = 0; unsigned int nr_data = 0;
unsigned int nr_syn = 0; unsigned int nr_syn = 0;
unsigned int nr_fin = 0; unsigned int nr_fin = 0;
unsigned int nr_hwtstamp = 0;
/* Check the header received from the active side */ /* Check the header received from the active side */
static int __check_active_hdr_in(struct bpf_sock_ops *skops, bool check_syn) static int __check_active_hdr_in(struct bpf_sock_ops *skops, bool check_syn)
...@@ -146,6 +147,9 @@ static int check_active_hdr_in(struct bpf_sock_ops *skops) ...@@ -146,6 +147,9 @@ static int check_active_hdr_in(struct bpf_sock_ops *skops)
if (th->ack && !th->fin && tcp_hdrlen(th) == skops->skb_len) if (th->ack && !th->fin && tcp_hdrlen(th) == skops->skb_len)
nr_pure_ack++; nr_pure_ack++;
if (skops->skb_hwtstamp)
nr_hwtstamp++;
return CG_OK; return CG_OK;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment