This source file includes following definitions.
- test_flow_dissector_load_bytes
1
2 #include <test_progs.h>
3
4 void test_flow_dissector_load_bytes(void)
5 {
6 struct bpf_flow_keys flow_keys;
7 __u32 duration = 0, retval, size;
8 struct bpf_insn prog[] = {
9
10
11 BPF_MOV64_IMM(BPF_REG_2, 0),
12
13 BPF_ALU64_REG(BPF_MOV, BPF_REG_3, BPF_REG_10),
14 BPF_ALU64_IMM(BPF_ADD, BPF_REG_3, -1),
15
16 BPF_MOV64_IMM(BPF_REG_4, 1),
17
18 BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
19 BPF_FUNC_skb_load_bytes),
20 BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, 2),
21
22 BPF_MOV64_IMM(BPF_REG_0, BPF_DROP),
23 BPF_EXIT_INSN(),
24
25 BPF_MOV64_IMM(BPF_REG_0, BPF_OK),
26 BPF_EXIT_INSN(),
27 };
28 int fd, err;
29
30
31
32 fd = bpf_load_program(BPF_PROG_TYPE_FLOW_DISSECTOR, prog,
33 ARRAY_SIZE(prog), "GPL", 0, NULL, 0);
34 CHECK(fd < 0,
35 "flow_dissector-bpf_skb_load_bytes-load",
36 "fd %d errno %d\n",
37 fd, errno);
38
39 err = bpf_prog_test_run(fd, 1, &pkt_v4, sizeof(pkt_v4),
40 &flow_keys, &size, &retval, &duration);
41 CHECK(size != sizeof(flow_keys) || err || retval != 1,
42 "flow_dissector-bpf_skb_load_bytes",
43 "err %d errno %d retval %d duration %d size %u/%zu\n",
44 err, errno, retval, duration, size, sizeof(flow_keys));
45
46 if (fd >= -1)
47 close(fd);
48 }