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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/prog_tests/xdp_noinline.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 #include "test_xdp_noinline.skel.h"
  5 
  6 void test_xdp_noinline(void)
  7 {
  8         unsigned int nr_cpus = bpf_num_possible_cpus();
  9         struct test_xdp_noinline *skel;
 10         struct vip key = {.protocol = 6};
 11         struct vip_meta {
 12                 __u32 flags;
 13                 __u32 vip_num;
 14         } value = {.vip_num = VIP_NUM};
 15         __u32 stats_key = VIP_NUM;
 16         struct vip_stats {
 17                 __u64 bytes;
 18                 __u64 pkts;
 19         } stats[nr_cpus];
 20         struct real_definition {
 21                 union {
 22                         __be32 dst;
 23                         __be32 dstv6[4];
 24                 };
 25                 __u8 flags;
 26         } real_def = {.dst = MAGIC_VAL};
 27         __u32 ch_key = 11, real_num = 3;
 28         int err, i;
 29         __u64 bytes = 0, pkts = 0;
 30         char buf[128];
 31         u32 *magic = (u32 *)buf;
 32         LIBBPF_OPTS(bpf_test_run_opts, topts,
 33                 .data_in = &pkt_v4,
 34                 .data_size_in = sizeof(pkt_v4),
 35                 .data_out = buf,
 36                 .data_size_out = sizeof(buf),
 37                 .repeat = NUM_ITER,
 38         );
 39 
 40         skel = test_xdp_noinline__open_and_load();
 41         if (!ASSERT_OK_PTR(skel, "skel_open_and_load"))
 42                 return;
 43 
 44         bpf_map_update_elem(bpf_map__fd(skel->maps.vip_map), &key, &value, 0);
 45         bpf_map_update_elem(bpf_map__fd(skel->maps.ch_rings), &ch_key, &real_num, 0);
 46         bpf_map_update_elem(bpf_map__fd(skel->maps.reals), &real_num, &real_def, 0);
 47 
 48         err = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.balancer_ingress_v4), &topts);
 49         ASSERT_OK(err, "ipv4 test_run");
 50         ASSERT_EQ(topts.retval, 1, "ipv4 test_run retval");
 51         ASSERT_EQ(topts.data_size_out, 54, "ipv4 test_run data_size_out");
 52         ASSERT_EQ(*magic, MAGIC_VAL, "ipv4 test_run magic");
 53 
 54         topts.data_in = &pkt_v6;
 55         topts.data_size_in = sizeof(pkt_v6);
 56         topts.data_out = buf;
 57         topts.data_size_out = sizeof(buf);
 58 
 59         err = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.balancer_ingress_v6), &topts);
 60         ASSERT_OK(err, "ipv6 test_run");
 61         ASSERT_EQ(topts.retval, 1, "ipv6 test_run retval");
 62         ASSERT_EQ(topts.data_size_out, 74, "ipv6 test_run data_size_out");
 63         ASSERT_EQ(*magic, MAGIC_VAL, "ipv6 test_run magic");
 64 
 65         bpf_map_lookup_elem(bpf_map__fd(skel->maps.stats), &stats_key, stats);
 66         for (i = 0; i < nr_cpus; i++) {
 67                 bytes += stats[i].bytes;
 68                 pkts += stats[i].pkts;
 69         }
 70         ASSERT_EQ(bytes, MAGIC_BYTES * NUM_ITER * 2, "stats bytes");
 71         ASSERT_EQ(pkts, NUM_ITER * 2, "stats pkts");
 72         test_xdp_noinline__destroy(skel);
 73 }
 74 

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