Re: [PATCH bpf-next 2/2] selftests/bpf: add tcx netns cookie tests

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 10/2/24 6:01 PM, Mahe Tardy wrote:
Add netns cookie test that verifies the helper is now supported and work
in the context of tc programs.

Signed-off-by: Mahe Tardy <mahe.tardy@xxxxxxxxx>
---
  tools/testing/selftests/bpf/prog_tests/netns_cookie.c | 7 +++++++
  tools/testing/selftests/bpf/progs/netns_cookie_prog.c | 9 +++++++++
  2 files changed, 16 insertions(+)

diff --git a/tools/testing/selftests/bpf/prog_tests/netns_cookie.c b/tools/testing/selftests/bpf/prog_tests/netns_cookie.c
index 71d8f3ba7d6b..233fd66f59ee 100644
--- a/tools/testing/selftests/bpf/prog_tests/netns_cookie.c
+++ b/tools/testing/selftests/bpf/prog_tests/netns_cookie.c
@@ -12,6 +12,7 @@ static int duration;

  void test_netns_cookie(void)
  {
+	LIBBPF_OPTS(bpf_prog_attach_opts, opta);
  	int server_fd = -1, client_fd = -1, cgroup_fd = -1;
  	int err, val, ret, map, verdict;
  	struct netns_cookie_prog *skel;
@@ -38,6 +39,11 @@ void test_netns_cookie(void)
  	if (!ASSERT_OK(err, "prog_attach"))
  		goto done;

+	verdict = bpf_program__fd(skel->progs.get_netns_cookie_tcx);
+	err = bpf_prog_attach_opts(verdict, 1, BPF_TCX_INGRESS, &opta);
+	if (!ASSERT_EQ(err, 0, "prog_attach"))
+		goto done;
+
  	server_fd = start_server(AF_INET6, SOCK_STREAM, "::1", 0, 0);
  	if (CHECK(server_fd < 0, "start_server", "errno %d\n", errno))
  		goto done;
@@ -68,6 +74,7 @@ void test_netns_cookie(void)
  		goto done;

  	ASSERT_EQ(val, cookie_expected_value, "cookie_value");
+	ASSERT_EQ(skel->bss->tcx_netns_cookie, cookie_expected_value, "cookie_value");

  done:
  	if (server_fd != -1)

Looks like CI fails, as this is missing a bpf_prog_detach_opts().

diff --git a/tools/testing/selftests/bpf/progs/netns_cookie_prog.c b/tools/testing/selftests/bpf/progs/netns_cookie_prog.c
index aeff3a4f9287..207f0e6c20b7 100644
--- a/tools/testing/selftests/bpf/progs/netns_cookie_prog.c
+++ b/tools/testing/selftests/bpf/progs/netns_cookie_prog.c
@@ -27,6 +27,8 @@ struct {
  	__type(value, __u64);
  } sock_map SEC(".maps");

+int tcx_netns_cookie;
+
  SEC("sockops")
  int get_netns_cookie_sockops(struct bpf_sock_ops *ctx)
  {
@@ -81,4 +83,11 @@ int get_netns_cookie_sk_msg(struct sk_msg_md *msg)
  	return 1;
  }

+SEC("tcx/ingress")
+int get_netns_cookie_tcx(struct __sk_buff *skb)
+{
+	tcx_netns_cookie = bpf_get_netns_cookie(skb);
+	return TCX_PASS;
+}
+
  char _license[] SEC("license") = "GPL";
--
2.34.1





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux