1
0
Fork 0
mirror of synced 2025-03-06 20:59:54 +01:00
linux/tools/testing/selftests/bpf/progs/empty_skb.c
Stanislav Fomichev 68f8e3d4b9 selftests/bpf: Make sure zero-len skbs aren't redirectable
LWT_XMIT to test L3 case, TC to test L2 case.

v2:
- s/veth_ifindex/ipip_ifindex/ in two places (Martin)
- add comment about which condition triggers the rejection (Martin)

Signed-off-by: Stanislav Fomichev <sdf@google.com>
Link: https://lore.kernel.org/r/20221121180340.1983627-2-sdf@google.com
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
2022-11-21 12:47:04 -08:00

37 lines
692 B
C

// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_endian.h>
char _license[] SEC("license") = "GPL";
int ifindex;
int ret;
SEC("lwt_xmit")
int redirect_ingress(struct __sk_buff *skb)
{
ret = bpf_clone_redirect(skb, ifindex, BPF_F_INGRESS);
return 0;
}
SEC("lwt_xmit")
int redirect_egress(struct __sk_buff *skb)
{
ret = bpf_clone_redirect(skb, ifindex, 0);
return 0;
}
SEC("tc")
int tc_redirect_ingress(struct __sk_buff *skb)
{
ret = bpf_clone_redirect(skb, ifindex, BPF_F_INGRESS);
return 0;
}
SEC("tc")
int tc_redirect_egress(struct __sk_buff *skb)
{
ret = bpf_clone_redirect(skb, ifindex, 0);
return 0;
}