summaryrefslogtreecommitdiff
path: root/tools/testing
diff options
context:
space:
mode:
authorFeng Yang <yangfeng@kylinos.cn>2026-03-04 12:44:29 +0300
committerMartin KaFai Lau <martin.lau@kernel.org>2026-03-05 03:44:29 +0300
commite8ae16d65ac629bcdebf685b9ad9b008648b08b0 (patch)
tree895b34a2a47129455a60cc1a10a3ca6a14b3049b /tools/testing
parent972787479ee73006fddb5e59ab5c8e733810ff42 (diff)
downloadlinux-e8ae16d65ac629bcdebf685b9ad9b008648b08b0.tar.xz
selftests/bpf: Add selftests for the invocation of bpf_lwt_xmit_push_encap
Calling bpf_lwt_xmit_push_encap will not cause a crash when dst is missing. Signed-off-by: Feng Yang <yangfeng@kylinos.cn> Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org> Link: https://patch.msgid.link/20260304094429.168521-3-yangfeng59949@163.com
Diffstat (limited to 'tools/testing')
-rw-r--r--tools/testing/selftests/bpf/prog_tests/lwt_misc.c9
-rw-r--r--tools/testing/selftests/bpf/progs/lwt_misc.c22
2 files changed, 31 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/prog_tests/lwt_misc.c b/tools/testing/selftests/bpf/prog_tests/lwt_misc.c
new file mode 100644
index 000000000000..6940fca38512
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/lwt_misc.c
@@ -0,0 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <test_progs.h>
+#include "lwt_misc.skel.h"
+
+void test_lwt_misc(void)
+{
+ RUN_TESTS(lwt_misc);
+}
diff --git a/tools/testing/selftests/bpf/progs/lwt_misc.c b/tools/testing/selftests/bpf/progs/lwt_misc.c
new file mode 100644
index 000000000000..b392317088d2
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/lwt_misc.c
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include "vmlinux.h"
+#include <bpf/bpf_helpers.h>
+#include "bpf_misc.h"
+
+SEC("lwt_xmit")
+__success __retval(0)
+int test_missing_dst(struct __sk_buff *skb)
+{
+ struct iphdr iph;
+
+ __builtin_memset(&iph, 0, sizeof(struct iphdr));
+ iph.ihl = 5;
+ iph.version = 4;
+
+ bpf_lwt_push_encap(skb, BPF_LWT_ENCAP_IP, &iph, sizeof(struct iphdr));
+
+ return 0;
+}
+
+char _license[] SEC("license") = "GPL";