Linux Audio

Check our new training course

Loading...
v6.13.7
 1// SPDX-License-Identifier: GPL-2.0
 2#include <test_progs.h>
 3#include <network_helpers.h>
 4
 5void test_pkt_access(void)
 6{
 7	const char *file = "./test_pkt_access.bpf.o";
 8	struct bpf_object *obj;
 
 9	int err, prog_fd;
10	LIBBPF_OPTS(bpf_test_run_opts, topts,
11		.data_in = &pkt_v4,
12		.data_size_in = sizeof(pkt_v4),
13		.repeat = 100000,
14	);
15
16	err = bpf_prog_test_load(file, BPF_PROG_TYPE_SCHED_CLS, &obj, &prog_fd);
17	if (CHECK_FAIL(err))
18		return;
19
20	err = bpf_prog_test_run_opts(prog_fd, &topts);
21	ASSERT_OK(err, "ipv4 test_run_opts err");
22	ASSERT_OK(topts.retval, "ipv4 test_run_opts retval");
23
24	topts.data_in = &pkt_v6;
25	topts.data_size_in = sizeof(pkt_v6);
26	topts.data_size_out = 0; /* reset from last call */
27	err = bpf_prog_test_run_opts(prog_fd, &topts);
28	ASSERT_OK(err, "ipv6 test_run_opts err");
29	ASSERT_OK(topts.retval, "ipv6 test_run_opts retval");
30
 
 
 
 
 
31	bpf_object__close(obj);
32}
v5.9
 1// SPDX-License-Identifier: GPL-2.0
 2#include <test_progs.h>
 3#include <network_helpers.h>
 4
 5void test_pkt_access(void)
 6{
 7	const char *file = "./test_pkt_access.o";
 8	struct bpf_object *obj;
 9	__u32 duration, retval;
10	int err, prog_fd;
 
 
 
 
 
11
12	err = bpf_prog_load(file, BPF_PROG_TYPE_SCHED_CLS, &obj, &prog_fd);
13	if (CHECK_FAIL(err))
14		return;
15
16	err = bpf_prog_test_run(prog_fd, 100000, &pkt_v4, sizeof(pkt_v4),
17				NULL, NULL, &retval, &duration);
18	CHECK(err || retval, "ipv4",
19	      "err %d errno %d retval %d duration %d\n",
20	      err, errno, retval, duration);
 
 
 
 
 
21
22	err = bpf_prog_test_run(prog_fd, 100000, &pkt_v6, sizeof(pkt_v6),
23				NULL, NULL, &retval, &duration);
24	CHECK(err || retval, "ipv6",
25	      "err %d errno %d retval %d duration %d\n",
26	      err, errno, retval, duration);
27	bpf_object__close(obj);
28}