aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/bpf/prog_tests/bpf_qdisc.c
diff options
context:
space:
mode:
authorJakub Kicinski <kuba@kernel.org>2025-05-05 13:22:58 -0700
committerJakub Kicinski <kuba@kernel.org>2025-05-05 13:22:58 -0700
commitb4cd2ee54ca47c4575e30419f39a31249c1ee9b0 (patch)
tree07bdf715b5a4c923268346e7626f5d715378ada0 /tools/testing/selftests/bpf/prog_tests/bpf_qdisc.c
parentipv4: Honor "ignore_routes_with_linkdown" sysctl in nexthop selection (diff)
parentMerge branch 'fix-bpf-qdisc-bugs-and-clean-up' (diff)
downloadlinux-b4cd2ee54ca47c4575e30419f39a31249c1ee9b0.tar.gz
linux-b4cd2ee54ca47c4575e30419f39a31249c1ee9b0.zip
Merge tag 'for-netdev' of https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next
Martin KaFai Lau says: ==================== pull-request: bpf-next 2025-05-02 We've added 14 non-merge commits during the last 10 day(s) which contain a total of 13 files changed, 740 insertions(+), 121 deletions(-). The main changes are: 1) Avoid skipping or repeating a sk when using a UDP bpf_iter, from Jordan Rife. 2) Fixed a crash when a bpf qdisc is set in the net.core.default_qdisc, from Amery Hung. 3) A few other fixes in the bpf qdisc, from Amery Hung. - Always call qdisc_watchdog_init() in the .init prologue such that the .reset/.destroy epilogue can always call qdisc_watchdog_cancel() without issue. - bpf_qdisc_init_prologue() was incorrectly returning an error when the bpf qdisc is set as the default_qdisc and the mq is creating the default_qdisc. It is now fixed. * tag 'for-netdev' of https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next: selftests/bpf: Cleanup bpf qdisc selftests selftests/bpf: Test attaching a bpf qdisc with incomplete operators bpf: net_sched: Make some Qdisc_ops ops mandatory selftests/bpf: Test setting and creating bpf qdisc as default qdisc bpf: net_sched: Fix bpf qdisc init prologue when set as default qdisc selftests/bpf: Add tests for bucket resume logic in UDP socket iterators selftests/bpf: Return socket cookies from sock_iter_batch progs bpf: udp: Avoid socket skips and repeats during iteration bpf: udp: Use bpf_udp_iter_batch_item for bpf_udp_iter_state batch items bpf: udp: Get rid of st_bucket_done bpf: udp: Make sure iter->batch always contains a full bucket snapshot bpf: udp: Make mem flags configurable through bpf_iter_udp_realloc_batch bpf: net_sched: Fix using bpf qdisc as default qdisc selftests/bpf: Fix compilation errors ==================== Link: https://patch.msgid.link/20250503010755.4030524-1-martin.lau@linux.dev Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'tools/testing/selftests/bpf/prog_tests/bpf_qdisc.c')
-rw-r--r--tools/testing/selftests/bpf/prog_tests/bpf_qdisc.c119
1 files changed, 85 insertions, 34 deletions
diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_qdisc.c b/tools/testing/selftests/bpf/prog_tests/bpf_qdisc.c
index c9a54177c84e..730357cd0c9a 100644
--- a/tools/testing/selftests/bpf/prog_tests/bpf_qdisc.c
+++ b/tools/testing/selftests/bpf/prog_tests/bpf_qdisc.c
@@ -7,6 +7,7 @@
#include "network_helpers.h"
#include "bpf_qdisc_fifo.skel.h"
#include "bpf_qdisc_fq.skel.h"
+#include "bpf_qdisc_fail__incompl_ops.skel.h"
#define LO_IFINDEX 1
@@ -49,42 +50,32 @@ done:
static void test_fifo(void)
{
struct bpf_qdisc_fifo *fifo_skel;
- struct bpf_link *link;
fifo_skel = bpf_qdisc_fifo__open_and_load();
if (!ASSERT_OK_PTR(fifo_skel, "bpf_qdisc_fifo__open_and_load"))
return;
- link = bpf_map__attach_struct_ops(fifo_skel->maps.fifo);
- if (!ASSERT_OK_PTR(link, "bpf_map__attach_struct_ops")) {
- bpf_qdisc_fifo__destroy(fifo_skel);
- return;
- }
+ if (!ASSERT_OK(bpf_qdisc_fifo__attach(fifo_skel), "bpf_qdisc_fifo__attach"))
+ goto out;
do_test("bpf_fifo");
-
- bpf_link__destroy(link);
+out:
bpf_qdisc_fifo__destroy(fifo_skel);
}
static void test_fq(void)
{
struct bpf_qdisc_fq *fq_skel;
- struct bpf_link *link;
fq_skel = bpf_qdisc_fq__open_and_load();
if (!ASSERT_OK_PTR(fq_skel, "bpf_qdisc_fq__open_and_load"))
return;
- link = bpf_map__attach_struct_ops(fq_skel->maps.fq);
- if (!ASSERT_OK_PTR(link, "bpf_map__attach_struct_ops")) {
- bpf_qdisc_fq__destroy(fq_skel);
- return;
- }
+ if (!ASSERT_OK(bpf_qdisc_fq__attach(fq_skel), "bpf_qdisc_fq__attach"))
+ goto out;
do_test("bpf_fq");
-
- bpf_link__destroy(link);
+out:
bpf_qdisc_fq__destroy(fq_skel);
}
@@ -96,18 +87,14 @@ static void test_qdisc_attach_to_mq(void)
.handle = 0x11 << 16,
.qdisc = "bpf_fifo");
struct bpf_qdisc_fifo *fifo_skel;
- struct bpf_link *link;
int err;
fifo_skel = bpf_qdisc_fifo__open_and_load();
if (!ASSERT_OK_PTR(fifo_skel, "bpf_qdisc_fifo__open_and_load"))
return;
- link = bpf_map__attach_struct_ops(fifo_skel->maps.fifo);
- if (!ASSERT_OK_PTR(link, "bpf_map__attach_struct_ops")) {
- bpf_qdisc_fifo__destroy(fifo_skel);
- return;
- }
+ if (!ASSERT_OK(bpf_qdisc_fifo__attach(fifo_skel), "bpf_qdisc_fifo__attach"))
+ goto out;
SYS(out, "ip link add veth0 type veth peer veth1");
hook.ifindex = if_nametoindex("veth0");
@@ -120,7 +107,6 @@ static void test_qdisc_attach_to_mq(void)
SYS(out, "tc qdisc delete dev veth0 root mq");
out:
- bpf_link__destroy(link);
bpf_qdisc_fifo__destroy(fifo_skel);
}
@@ -132,18 +118,14 @@ static void test_qdisc_attach_to_non_root(void)
.handle = 0x11 << 16,
.qdisc = "bpf_fifo");
struct bpf_qdisc_fifo *fifo_skel;
- struct bpf_link *link;
int err;
fifo_skel = bpf_qdisc_fifo__open_and_load();
if (!ASSERT_OK_PTR(fifo_skel, "bpf_qdisc_fifo__open_and_load"))
return;
- link = bpf_map__attach_struct_ops(fifo_skel->maps.fifo);
- if (!ASSERT_OK_PTR(link, "bpf_map__attach_struct_ops")) {
- bpf_qdisc_fifo__destroy(fifo_skel);
- return;
- }
+ if (!ASSERT_OK(bpf_qdisc_fifo__attach(fifo_skel), "bpf_qdisc_fifo__attach"))
+ goto out;
SYS(out, "tc qdisc add dev lo root handle 1: htb");
SYS(out_del_htb, "tc class add dev lo parent 1: classid 1:1 htb rate 75Kbit");
@@ -155,18 +137,82 @@ static void test_qdisc_attach_to_non_root(void)
out_del_htb:
SYS(out, "tc qdisc delete dev lo root htb");
out:
- bpf_link__destroy(link);
bpf_qdisc_fifo__destroy(fifo_skel);
}
-void test_bpf_qdisc(void)
+static void test_incompl_ops(void)
+{
+ struct bpf_qdisc_fail__incompl_ops *skel;
+ struct bpf_link *link;
+
+ skel = bpf_qdisc_fail__incompl_ops__open_and_load();
+ if (!ASSERT_OK_PTR(skel, "bpf_qdisc_fifo__open_and_load"))
+ return;
+
+ link = bpf_map__attach_struct_ops(skel->maps.test);
+ if (!ASSERT_ERR_PTR(link, "bpf_map__attach_struct_ops"))
+ bpf_link__destroy(link);
+
+ bpf_qdisc_fail__incompl_ops__destroy(skel);
+}
+
+static int get_default_qdisc(char *qdisc_name)
{
- struct netns_obj *netns;
+ FILE *f;
+ int num;
+
+ f = fopen("/proc/sys/net/core/default_qdisc", "r");
+ if (!f)
+ return -errno;
+
+ num = fscanf(f, "%s", qdisc_name);
+ fclose(f);
+
+ return num == 1 ? 0 : -EFAULT;
+}
+
+static void test_default_qdisc_attach_to_mq(void)
+{
+ char default_qdisc[IFNAMSIZ] = {};
+ struct bpf_qdisc_fifo *fifo_skel;
+ struct netns_obj *netns = NULL;
+ int err;
+
+ fifo_skel = bpf_qdisc_fifo__open_and_load();
+ if (!ASSERT_OK_PTR(fifo_skel, "bpf_qdisc_fifo__open_and_load"))
+ return;
+
+ if (!ASSERT_OK(bpf_qdisc_fifo__attach(fifo_skel), "bpf_qdisc_fifo__attach"))
+ goto out;
+
+ err = get_default_qdisc(default_qdisc);
+ if (!ASSERT_OK(err, "read sysctl net.core.default_qdisc"))
+ goto out;
+
+ err = write_sysctl("/proc/sys/net/core/default_qdisc", "bpf_fifo");
+ if (!ASSERT_OK(err, "write sysctl net.core.default_qdisc"))
+ goto out;
netns = netns_new("bpf_qdisc_ns", true);
if (!ASSERT_OK_PTR(netns, "netns_new"))
- return;
+ goto out;
+
+ SYS(out, "ip link add veth0 type veth peer veth1");
+ SYS(out, "tc qdisc add dev veth0 root handle 1: mq");
+ ASSERT_EQ(fifo_skel->bss->init_called, true, "init_called");
+
+ SYS(out, "tc qdisc delete dev veth0 root mq");
+out:
+ netns_free(netns);
+ if (default_qdisc[0])
+ write_sysctl("/proc/sys/net/core/default_qdisc", default_qdisc);
+
+ bpf_qdisc_fifo__destroy(fifo_skel);
+}
+
+void test_ns_bpf_qdisc(void)
+{
if (test__start_subtest("fifo"))
test_fifo();
if (test__start_subtest("fq"))
@@ -175,6 +221,11 @@ void test_bpf_qdisc(void)
test_qdisc_attach_to_mq();
if (test__start_subtest("attach to non root"))
test_qdisc_attach_to_non_root();
+ if (test__start_subtest("incompl_ops"))
+ test_incompl_ops();
+}
- netns_free(netns);
+void serial_test_bpf_qdisc_default(void)
+{
+ test_default_qdisc_attach_to_mq();
}