Skip to content

Commit

Permalink
selftests/net: Add test for loading devbound XDP program in generic mode
Browse files Browse the repository at this point in the history
Add a test to bpf_offload.py for loading a devbound XDP program in
generic mode, checking that it fails correctly.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
Acked-by: Stanislav Fomichev <sdf@fomichev.me>
Link: https://patch.msgid.link/20250127131344.238147-2-toke@redhat.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Toke Høiland-Jørgensen authored and Jakub Kicinski committed Jan 30, 2025
1 parent 3595599 commit f7bf624
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion tools/testing/selftests/net/bpf_offload.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,14 @@ def bpftool_map_list_wait(expected=0, n_retry=20, ns=""):
raise Exception("Time out waiting for map counts to stabilize want %d, have %d" % (expected, nmaps))

def bpftool_prog_load(sample, file_name, maps=[], prog_type="xdp", dev=None,
fail=True, include_stderr=False):
fail=True, include_stderr=False, dev_bind=None):
args = "prog load %s %s" % (os.path.join(bpf_test_dir, sample), file_name)
if prog_type is not None:
args += " type " + prog_type
if dev is not None:
args += " dev " + dev
elif dev_bind is not None:
args += " xdpmeta_dev " + dev_bind
if len(maps):
args += " map " + " map ".join(maps)

Expand Down Expand Up @@ -980,6 +982,16 @@ def test_multi_prog(simdev, sim, obj, modename, modeid):
rm("/sys/fs/bpf/offload")
sim.wait_for_flush()

bpftool_prog_load("sample_ret0.bpf.o", "/sys/fs/bpf/devbound",
dev_bind=sim['ifname'])
devbound = bpf_pinned("/sys/fs/bpf/devbound")
start_test("Test dev-bound program in generic mode...")
ret, _, err = sim.set_xdp(devbound, "generic", fail=False, include_stderr=True)
fail(ret == 0, "devbound program in generic mode allowed")
check_extack(err, "Can't attach device-bound programs in generic mode.", args)
rm("/sys/fs/bpf/devbound")
sim.wait_for_flush()

start_test("Test XDP load failure...")
sim.dfs["dev/bpf_bind_verifier_accept"] = 0
ret, _, err = bpftool_prog_load("sample_ret0.bpf.o", "/sys/fs/bpf/offload",
Expand Down

0 comments on commit f7bf624

Please sign in to comment.