mirror of
https://github.com/torvalds/linux.git
synced 2026-06-01 11:03:43 +02:00
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
This commit is contained in:
parent
972787479e
commit
e8ae16d65a
9
tools/testing/selftests/bpf/prog_tests/lwt_misc.c
Normal file
9
tools/testing/selftests/bpf/prog_tests/lwt_misc.c
Normal file
|
|
@ -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);
|
||||
}
|
||||
22
tools/testing/selftests/bpf/progs/lwt_misc.c
Normal file
22
tools/testing/selftests/bpf/progs/lwt_misc.c
Normal file
|
|
@ -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";
|
||||
Loading…
Reference in New Issue
Block a user