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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/prog_tests/load_bytes_relative.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-only
  2 
  3 /*
  4  * Copyright 2020 Google LLC.
  5  */
  6 
  7 #include <test_progs.h>
  8 #include <network_helpers.h>
  9 
 10 void test_load_bytes_relative(void)
 11 {
 12         int server_fd, cgroup_fd, prog_fd, map_fd, client_fd;
 13         int err;
 14         struct bpf_object *obj;
 15         struct bpf_program *prog;
 16         struct bpf_map *test_result;
 17         __u32 duration = 0;
 18 
 19         __u32 map_key = 0;
 20         __u32 map_value = 0;
 21 
 22         cgroup_fd = test__join_cgroup("/load_bytes_relative");
 23         if (CHECK_FAIL(cgroup_fd < 0))
 24                 return;
 25 
 26         server_fd = start_server(AF_INET, SOCK_STREAM, NULL, 0, 0);
 27         if (CHECK_FAIL(server_fd < 0))
 28                 goto close_cgroup_fd;
 29 
 30         err = bpf_prog_test_load("./load_bytes_relative.bpf.o", BPF_PROG_TYPE_CGROUP_SKB,
 31                                  &obj, &prog_fd);
 32         if (CHECK_FAIL(err))
 33                 goto close_server_fd;
 34 
 35         test_result = bpf_object__find_map_by_name(obj, "test_result");
 36         if (CHECK_FAIL(!test_result))
 37                 goto close_bpf_object;
 38 
 39         map_fd = bpf_map__fd(test_result);
 40         if (map_fd < 0)
 41                 goto close_bpf_object;
 42 
 43         prog = bpf_object__find_program_by_name(obj, "load_bytes_relative");
 44         if (CHECK_FAIL(!prog))
 45                 goto close_bpf_object;
 46 
 47         err = bpf_prog_attach(prog_fd, cgroup_fd, BPF_CGROUP_INET_EGRESS,
 48                               BPF_F_ALLOW_MULTI);
 49         if (CHECK_FAIL(err))
 50                 goto close_bpf_object;
 51 
 52         client_fd = connect_to_fd(server_fd, 0);
 53         if (CHECK_FAIL(client_fd < 0))
 54                 goto close_bpf_object;
 55         close(client_fd);
 56 
 57         err = bpf_map_lookup_elem(map_fd, &map_key, &map_value);
 58         if (CHECK_FAIL(err))
 59                 goto close_bpf_object;
 60 
 61         CHECK(map_value != 1, "bpf", "bpf program returned failure");
 62 
 63 close_bpf_object:
 64         bpf_object__close(obj);
 65 
 66 close_server_fd:
 67         close(server_fd);
 68 
 69 close_cgroup_fd:
 70         close(cgroup_fd);
 71 }
 72 

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