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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/prog_tests/l4lb_all.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 #include <test_progs.h>
  3 #include <network_helpers.h>
  4 
  5 static void test_l4lb(const char *file)
  6 {
  7         unsigned int nr_cpus = bpf_num_possible_cpus();
  8         struct vip key = {.protocol = 6};
  9         struct vip_meta {
 10                 __u32 flags;
 11                 __u32 vip_num;
 12         } value = {.vip_num = VIP_NUM};
 13         __u32 stats_key = VIP_NUM;
 14         struct vip_stats {
 15                 __u64 bytes;
 16                 __u64 pkts;
 17         } stats[nr_cpus];
 18         struct real_definition {
 19                 union {
 20                         __be32 dst;
 21                         __be32 dstv6[4];
 22                 };
 23                 __u8 flags;
 24         } real_def = {.dst = MAGIC_VAL};
 25         __u32 ch_key = 11, real_num = 3;
 26         int err, i, prog_fd, map_fd;
 27         __u64 bytes = 0, pkts = 0;
 28         struct bpf_object *obj;
 29         char buf[128];
 30         u32 *magic = (u32 *)buf;
 31         LIBBPF_OPTS(bpf_test_run_opts, topts,
 32                 .data_out = buf,
 33                 .data_size_out = sizeof(buf),
 34                 .repeat = NUM_ITER,
 35         );
 36 
 37         err = bpf_prog_test_load(file, BPF_PROG_TYPE_SCHED_CLS, &obj, &prog_fd);
 38         if (CHECK_FAIL(err))
 39                 return;
 40 
 41         map_fd = bpf_find_map(__func__, obj, "vip_map");
 42         if (map_fd < 0)
 43                 goto out;
 44         bpf_map_update_elem(map_fd, &key, &value, 0);
 45 
 46         map_fd = bpf_find_map(__func__, obj, "ch_rings");
 47         if (map_fd < 0)
 48                 goto out;
 49         bpf_map_update_elem(map_fd, &ch_key, &real_num, 0);
 50 
 51         map_fd = bpf_find_map(__func__, obj, "reals");
 52         if (map_fd < 0)
 53                 goto out;
 54         bpf_map_update_elem(map_fd, &real_num, &real_def, 0);
 55 
 56         topts.data_in = &pkt_v4;
 57         topts.data_size_in = sizeof(pkt_v4);
 58 
 59         err = bpf_prog_test_run_opts(prog_fd, &topts);
 60         ASSERT_OK(err, "test_run");
 61         ASSERT_EQ(topts.retval, 7 /*TC_ACT_REDIRECT*/, "ipv4 test_run retval");
 62         ASSERT_EQ(topts.data_size_out, 54, "ipv4 test_run data_size_out");
 63         ASSERT_EQ(*magic, MAGIC_VAL, "ipv4 magic");
 64 
 65         topts.data_in = &pkt_v6;
 66         topts.data_size_in = sizeof(pkt_v6);
 67         topts.data_size_out = sizeof(buf); /* reset out size */
 68 
 69         err = bpf_prog_test_run_opts(prog_fd, &topts);
 70         ASSERT_OK(err, "test_run");
 71         ASSERT_EQ(topts.retval, 7 /*TC_ACT_REDIRECT*/, "ipv6 test_run retval");
 72         ASSERT_EQ(topts.data_size_out, 74, "ipv6 test_run data_size_out");
 73         ASSERT_EQ(*magic, MAGIC_VAL, "ipv6 magic");
 74 
 75         map_fd = bpf_find_map(__func__, obj, "stats");
 76         if (map_fd < 0)
 77                 goto out;
 78         bpf_map_lookup_elem(map_fd, &stats_key, stats);
 79         for (i = 0; i < nr_cpus; i++) {
 80                 bytes += stats[i].bytes;
 81                 pkts += stats[i].pkts;
 82         }
 83         if (CHECK_FAIL(bytes != MAGIC_BYTES * NUM_ITER * 2 ||
 84                        pkts != NUM_ITER * 2))
 85                 printf("test_l4lb:FAIL:stats %lld %lld\n", bytes, pkts);
 86 out:
 87         bpf_object__close(obj);
 88 }
 89 
 90 void test_l4lb_all(void)
 91 {
 92         if (test__start_subtest("l4lb_inline"))
 93                 test_l4lb("test_l4lb.bpf.o");
 94         if (test__start_subtest("l4lb_noinline"))
 95                 test_l4lb("test_l4lb_noinline.bpf.o");
 96         if (test__start_subtest("l4lb_noinline_dynptr"))
 97                 test_l4lb("test_l4lb_noinline_dynptr.bpf.o");
 98 }
 99 

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