0001
0002 #include <test_progs.h>
0003 #include <network_helpers.h>
0004
0005 void serial_test_flow_dissector_load_bytes(void)
0006 {
0007 struct bpf_flow_keys flow_keys;
0008 struct bpf_insn prog[] = {
0009
0010
0011 BPF_MOV64_IMM(BPF_REG_2, 0),
0012
0013 BPF_ALU64_REG(BPF_MOV, BPF_REG_3, BPF_REG_10),
0014 BPF_ALU64_IMM(BPF_ADD, BPF_REG_3, -1),
0015
0016 BPF_MOV64_IMM(BPF_REG_4, 1),
0017
0018 BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
0019 BPF_FUNC_skb_load_bytes),
0020 BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, 2),
0021
0022 BPF_MOV64_IMM(BPF_REG_0, BPF_DROP),
0023 BPF_EXIT_INSN(),
0024
0025 BPF_MOV64_IMM(BPF_REG_0, BPF_OK),
0026 BPF_EXIT_INSN(),
0027 };
0028 int fd, err;
0029 LIBBPF_OPTS(bpf_test_run_opts, topts,
0030 .data_in = &pkt_v4,
0031 .data_size_in = sizeof(pkt_v4),
0032 .data_out = &flow_keys,
0033 .data_size_out = sizeof(flow_keys),
0034 .repeat = 1,
0035 );
0036
0037
0038
0039 fd = bpf_test_load_program(BPF_PROG_TYPE_FLOW_DISSECTOR, prog,
0040 ARRAY_SIZE(prog), "GPL", 0, NULL, 0);
0041 ASSERT_GE(fd, 0, "bpf_test_load_program good fd");
0042
0043 err = bpf_prog_test_run_opts(fd, &topts);
0044 ASSERT_OK(err, "test_run");
0045 ASSERT_EQ(topts.data_size_out, sizeof(flow_keys),
0046 "test_run data_size_out");
0047 ASSERT_EQ(topts.retval, 1, "test_run retval");
0048
0049 if (fd >= -1)
0050 close(fd);
0051 }