Both IFINDEX_SRC and IFINDEX_DST are set from the userspace
and it won't work once bpf merges with bpf-next.
Fixes: 096eccdef0 ("selftests/bpf: Rewrite test_tc_redirect.sh as prog_tests/tc_redirect.c")
Signed-off-by: Stanislav Fomichev <sdf@google.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20210514170528.3750250-1-sdf@google.com
33 lines
608 B
C
33 lines
608 B
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
|
|
#include <linux/bpf.h>
|
|
#include <linux/stddef.h>
|
|
#include <linux/pkt_cls.h>
|
|
|
|
#include <bpf/bpf_helpers.h>
|
|
|
|
volatile const __u32 IFINDEX_SRC;
|
|
volatile const __u32 IFINDEX_DST;
|
|
|
|
SEC("classifier/chk_egress")
|
|
int tc_chk(struct __sk_buff *skb)
|
|
{
|
|
return TC_ACT_SHOT;
|
|
}
|
|
|
|
SEC("classifier/dst_ingress")
|
|
int tc_dst(struct __sk_buff *skb)
|
|
{
|
|
return bpf_redirect_peer(IFINDEX_SRC, 0);
|
|
}
|
|
|
|
SEC("classifier/src_ingress")
|
|
int tc_src(struct __sk_buff *skb)
|
|
{
|
|
return bpf_redirect_peer(IFINDEX_DST, 0);
|
|
}
|
|
|
|
char __license[] SEC("license") = "GPL";
|