Skip to content

Commit

Permalink
selftest/bpf: Add...
Browse files Browse the repository at this point in the history
  # ./vmtest.sh -- ./test_progs -t tc_opts
  [...]
  ./test_progs -t tc_opts
  [    1.185325] bpf_testmod: loading out-of-tree module taints kernel.
  [    1.186826] bpf_testmod: module verification failed: signature and/or required key missing - tainting kernel
  [    1.270123] tsc: Refined TSC clocksource calibration: 3407.988 MHz
  [    1.272428] clocksource: tsc: mask: 0xffffffffffffffff max_cycles: 0x311fc932722, max_idle_ns: 440795381586 ns
  [    1.276408] clocksource: Switched to clocksource tsc
  torvalds#252     tc_opts_after:OK
  torvalds#253     tc_opts_append:OK
  torvalds#254     tc_opts_basic:OK
  torvalds#255     tc_opts_before:OK
  torvalds#256     tc_opts_chain_classic:OK
  torvalds#257     tc_opts_chain_mixed:OK
  torvalds#258     tc_opts_delete_empty:OK
  torvalds#259     tc_opts_demixed:OK
  torvalds#260     tc_opts_detach:OK
  torvalds#261     tc_opts_detach_after:OK
  torvalds#262     tc_opts_detach_before:OK
  torvalds#263     tc_opts_dev_cleanup:OK
  torvalds#264     tc_opts_invalid:OK
  torvalds#265     tc_opts_max:OK
  torvalds#266     tc_opts_mixed:OK
  torvalds#267     tc_opts_prepend:OK
  torvalds#268     tc_opts_replace:OK
  torvalds#269     tc_opts_revision:OK
  Summary: 18/0 PASSED, 0 SKIPPED, 0 FAILED

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
  • Loading branch information
borkmann committed Sep 29, 2023
1 parent 5dc8a0d commit 575753a
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions tools/testing/selftests/bpf/prog_tests/tc_opts.c
Original file line number Diff line number Diff line change
Expand Up @@ -2378,3 +2378,86 @@ void serial_test_tc_opts_chain_mixed(void)
test_tc_chain_mixed(BPF_TCX_INGRESS);
test_tc_chain_mixed(BPF_TCX_EGRESS);
}

static int generate_dummy_prog(void)
{
const struct bpf_insn prog_insns[] = {
BPF_MOV64_IMM(BPF_REG_0, 0),
BPF_EXIT_INSN(),
};
const size_t prog_insn_cnt = sizeof(prog_insns) / sizeof(struct bpf_insn);
LIBBPF_OPTS(bpf_prog_load_opts, opts);
const size_t log_buf_sz = 256;
char *log_buf;
int fd = -1;

log_buf = malloc(log_buf_sz);
if (!ASSERT_OK_PTR(log_buf, "log_buf_alloc"))
return fd;
opts.log_buf = log_buf;
opts.log_size = log_buf_sz;

log_buf[0] = '\0';
opts.log_level = 0;
fd = bpf_prog_load(BPF_PROG_TYPE_SCHED_CLS, "tcx_prog", "GPL",
prog_insns, prog_insn_cnt, &opts);
ASSERT_STREQ(log_buf, "", "log_0");
ASSERT_GE(fd, 0, "prog_fd");
free(log_buf);
return fd;
}

static void test_tc_opts_max_target(int target, int flags, bool relative)
{
int err, ifindex, i, prog_fd, last_fd = -1;
LIBBPF_OPTS(bpf_prog_attach_opts, opta);

ASSERT_OK(system("ip link add dev tcx_opts1 type veth peer name tcx_opts2"), "add veth");
ifindex = if_nametoindex("tcx_opts1");
ASSERT_NEQ(ifindex, 0, "non_zero_ifindex");

assert_mprog_count_ifindex(ifindex, target, 0);

for (i = 0; i < 63; i++) {
prog_fd = generate_dummy_prog();
if (!ASSERT_GE(prog_fd, 0, "dummy_prog"))
goto cleanup;
err = bpf_prog_attach_opts(prog_fd, ifindex, target, &opta);
if (!ASSERT_EQ(err, 0, "prog_attach"))
goto cleanup;
assert_mprog_count_ifindex(ifindex, target, i + 1);
if (i == 62 && relative) {
last_fd = prog_fd;
} else {
close(prog_fd);
}
}

prog_fd = generate_dummy_prog();
if (!ASSERT_GE(prog_fd, 0, "dummy_prog"))
goto cleanup;
opta.flags = flags;
if (last_fd > 0)
opta.relative_fd = last_fd;
err = bpf_prog_attach_opts(prog_fd, ifindex, target, &opta);
ASSERT_EQ(err, -ENOMEM, "prog_64_attach");
close(prog_fd);
if (last_fd > 0)
close(last_fd);
cleanup:
ASSERT_OK(system("ip link del dev tcx_opts1"), "del veth");
ASSERT_EQ(if_nametoindex("tcx_opts1"), 0, "dev1_removed");
ASSERT_EQ(if_nametoindex("tcx_opts2"), 0, "dev2_removed");
}

void serial_test_tc_opts_max(void)
{
test_tc_opts_max_target(BPF_TCX_INGRESS, 0, false);
test_tc_opts_max_target(BPF_TCX_EGRESS, 0, false);

test_tc_opts_max_target(BPF_TCX_INGRESS, BPF_F_BEFORE, false);
test_tc_opts_max_target(BPF_TCX_EGRESS, BPF_F_BEFORE, true);

test_tc_opts_max_target(BPF_TCX_INGRESS, BPF_F_AFTER, true);
test_tc_opts_max_target(BPF_TCX_EGRESS, BPF_F_AFTER, false);
}

0 comments on commit 575753a

Please sign in to comment.