1
2#include <test_progs.h>
3#include <network_helpers.h>
4#include "test_xdp_noinline.skel.h"
5
6void 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 __u32 duration = 0, retval, size;
29 int err, i;
30 __u64 bytes = 0, pkts = 0;
31 char buf[128];
32 u32 *magic = (u32 *)buf;
33
34 skel = test_xdp_noinline__open_and_load();
35 if (CHECK(!skel, "skel_open_and_load", "failed\n"))
36 return;
37
38 bpf_map_update_elem(bpf_map__fd(skel->maps.vip_map), &key, &value, 0);
39 bpf_map_update_elem(bpf_map__fd(skel->maps.ch_rings), &ch_key, &real_num, 0);
40 bpf_map_update_elem(bpf_map__fd(skel->maps.reals), &real_num, &real_def, 0);
41
42 err = bpf_prog_test_run(bpf_program__fd(skel->progs.balancer_ingress_v4),
43 NUM_ITER, &pkt_v4, sizeof(pkt_v4),
44 buf, &size, &retval, &duration);
45 CHECK(err || retval != 1 || size != 54 ||
46 *magic != MAGIC_VAL, "ipv4",
47 "err %d errno %d retval %d size %d magic %x\n",
48 err, errno, retval, size, *magic);
49
50 err = bpf_prog_test_run(bpf_program__fd(skel->progs.balancer_ingress_v6),
51 NUM_ITER, &pkt_v6, sizeof(pkt_v6),
52 buf, &size, &retval, &duration);
53 CHECK(err || retval != 1 || size != 74 ||
54 *magic != MAGIC_VAL, "ipv6",
55 "err %d errno %d retval %d size %d magic %x\n",
56 err, errno, retval, size, *magic);
57
58 bpf_map_lookup_elem(bpf_map__fd(skel->maps.stats), &stats_key, stats);
59 for (i = 0; i < nr_cpus; i++) {
60 bytes += stats[i].bytes;
61 pkts += stats[i].pkts;
62 }
63 CHECK(bytes != MAGIC_BYTES * NUM_ITER * 2 || pkts != NUM_ITER * 2,
64 "stats", "bytes %lld pkts %lld\n",
65 (unsigned long long)bytes, (unsigned long long)pkts);
66 test_xdp_noinline__destroy(skel);
67}
68