~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/prog_tests/netns_cookie.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 
  3 #include <test_progs.h>
  4 #include "netns_cookie_prog.skel.h"
  5 #include "network_helpers.h"
  6 
  7 #ifndef SO_NETNS_COOKIE
  8 #define SO_NETNS_COOKIE 71
  9 #endif
 10 
 11 static int duration;
 12 
 13 void test_netns_cookie(void)
 14 {
 15         int server_fd = -1, client_fd = -1, cgroup_fd = -1;
 16         int err, val, ret, map, verdict;
 17         struct netns_cookie_prog *skel;
 18         uint64_t cookie_expected_value;
 19         socklen_t vallen = sizeof(cookie_expected_value);
 20         static const char send_msg[] = "message";
 21 
 22         skel = netns_cookie_prog__open_and_load();
 23         if (!ASSERT_OK_PTR(skel, "skel_open"))
 24                 return;
 25 
 26         cgroup_fd = test__join_cgroup("/netns_cookie");
 27         if (CHECK(cgroup_fd < 0, "join_cgroup", "cgroup creation failed\n"))
 28                 goto done;
 29 
 30         skel->links.get_netns_cookie_sockops = bpf_program__attach_cgroup(
 31                 skel->progs.get_netns_cookie_sockops, cgroup_fd);
 32         if (!ASSERT_OK_PTR(skel->links.get_netns_cookie_sockops, "prog_attach"))
 33                 goto done;
 34 
 35         verdict = bpf_program__fd(skel->progs.get_netns_cookie_sk_msg);
 36         map = bpf_map__fd(skel->maps.sock_map);
 37         err = bpf_prog_attach(verdict, map, BPF_SK_MSG_VERDICT, 0);
 38         if (!ASSERT_OK(err, "prog_attach"))
 39                 goto done;
 40 
 41         server_fd = start_server(AF_INET6, SOCK_STREAM, "::1", 0, 0);
 42         if (CHECK(server_fd < 0, "start_server", "errno %d\n", errno))
 43                 goto done;
 44 
 45         client_fd = connect_to_fd(server_fd, 0);
 46         if (CHECK(client_fd < 0, "connect_to_fd", "errno %d\n", errno))
 47                 goto done;
 48 
 49         ret = send(client_fd, send_msg, sizeof(send_msg), 0);
 50         if (CHECK(ret != sizeof(send_msg), "send(msg)", "ret:%d\n", ret))
 51                 goto done;
 52 
 53         err = bpf_map_lookup_elem(bpf_map__fd(skel->maps.sockops_netns_cookies),
 54                                   &client_fd, &val);
 55         if (!ASSERT_OK(err, "map_lookup(sockops_netns_cookies)"))
 56                 goto done;
 57 
 58         err = getsockopt(client_fd, SOL_SOCKET, SO_NETNS_COOKIE,
 59                          &cookie_expected_value, &vallen);
 60         if (!ASSERT_OK(err, "getsockopt"))
 61                 goto done;
 62 
 63         ASSERT_EQ(val, cookie_expected_value, "cookie_value");
 64 
 65         err = bpf_map_lookup_elem(bpf_map__fd(skel->maps.sk_msg_netns_cookies),
 66                                   &client_fd, &val);
 67         if (!ASSERT_OK(err, "map_lookup(sk_msg_netns_cookies)"))
 68                 goto done;
 69 
 70         ASSERT_EQ(val, cookie_expected_value, "cookie_value");
 71 
 72 done:
 73         if (server_fd != -1)
 74                 close(server_fd);
 75         if (client_fd != -1)
 76                 close(client_fd);
 77         if (cgroup_fd != -1)
 78                 close(cgroup_fd);
 79         netns_cookie_prog__destroy(skel);
 80 }
 81 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php