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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/prog_tests/socket_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 // Copyright (c) 2020 Google LLC.
  3 // Copyright (c) 2018 Facebook
  4 
  5 #include <test_progs.h>
  6 #include "socket_cookie_prog.skel.h"
  7 #include "network_helpers.h"
  8 
  9 static int duration;
 10 
 11 struct socket_cookie {
 12         __u64 cookie_key;
 13         __u32 cookie_value;
 14 };
 15 
 16 void test_socket_cookie(void)
 17 {
 18         int server_fd = 0, client_fd = 0, cgroup_fd = 0, err = 0;
 19         socklen_t addr_len = sizeof(struct sockaddr_in6);
 20         struct socket_cookie_prog *skel;
 21         __u32 cookie_expected_value;
 22         struct sockaddr_in6 addr;
 23         struct socket_cookie val;
 24 
 25         skel = socket_cookie_prog__open_and_load();
 26         if (!ASSERT_OK_PTR(skel, "skel_open"))
 27                 return;
 28 
 29         cgroup_fd = test__join_cgroup("/socket_cookie");
 30         if (CHECK(cgroup_fd < 0, "join_cgroup", "cgroup creation failed\n"))
 31                 goto out;
 32 
 33         skel->links.set_cookie = bpf_program__attach_cgroup(
 34                 skel->progs.set_cookie, cgroup_fd);
 35         if (!ASSERT_OK_PTR(skel->links.set_cookie, "prog_attach"))
 36                 goto close_cgroup_fd;
 37 
 38         skel->links.update_cookie_sockops = bpf_program__attach_cgroup(
 39                 skel->progs.update_cookie_sockops, cgroup_fd);
 40         if (!ASSERT_OK_PTR(skel->links.update_cookie_sockops, "prog_attach"))
 41                 goto close_cgroup_fd;
 42 
 43         skel->links.update_cookie_tracing = bpf_program__attach(
 44                 skel->progs.update_cookie_tracing);
 45         if (!ASSERT_OK_PTR(skel->links.update_cookie_tracing, "prog_attach"))
 46                 goto close_cgroup_fd;
 47 
 48         server_fd = start_server(AF_INET6, SOCK_STREAM, "::1", 0, 0);
 49         if (CHECK(server_fd < 0, "start_server", "errno %d\n", errno))
 50                 goto close_cgroup_fd;
 51 
 52         client_fd = connect_to_fd(server_fd, 0);
 53         if (CHECK(client_fd < 0, "connect_to_fd", "errno %d\n", errno))
 54                 goto close_server_fd;
 55 
 56         err = bpf_map_lookup_elem(bpf_map__fd(skel->maps.socket_cookies),
 57                                   &client_fd, &val);
 58         if (!ASSERT_OK(err, "map_lookup(socket_cookies)"))
 59                 goto close_client_fd;
 60 
 61         err = getsockname(client_fd, (struct sockaddr *)&addr, &addr_len);
 62         if (!ASSERT_OK(err, "getsockname"))
 63                 goto close_client_fd;
 64 
 65         cookie_expected_value = (ntohs(addr.sin6_port) << 8) | 0xFF;
 66         ASSERT_EQ(val.cookie_value, cookie_expected_value, "cookie_value");
 67 
 68 close_client_fd:
 69         close(client_fd);
 70 close_server_fd:
 71         close(server_fd);
 72 close_cgroup_fd:
 73         close(cgroup_fd);
 74 out:
 75         socket_cookie_prog__destroy(skel);
 76 }
 77 

~ [ 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