xref: /linux/tools/testing/selftests/bpf/progs/test_tc_peer.c (revision a8deba8547e39f26440101164a3bbc2899c5b305)
1 // SPDX-License-Identifier: GPL-2.0
2 #include <stdint.h>
3 #include <stdbool.h>
4 
5 #include <linux/bpf.h>
6 #include <linux/stddef.h>
7 #include <linux/pkt_cls.h>
8 
9 #include <bpf/bpf_helpers.h>
10 
11 volatile const __u32 IFINDEX_SRC;
12 volatile const __u32 IFINDEX_DST;
13 
14 SEC("classifier/chk_egress")
15 int tc_chk(struct __sk_buff *skb)
16 {
17 	return TC_ACT_SHOT;
18 }
19 
20 SEC("classifier/dst_ingress")
21 int tc_dst(struct __sk_buff *skb)
22 {
23 	return bpf_redirect_peer(IFINDEX_SRC, 0);
24 }
25 
26 SEC("classifier/src_ingress")
27 int tc_src(struct __sk_buff *skb)
28 {
29 	return bpf_redirect_peer(IFINDEX_DST, 0);
30 }
31 
32 char __license[] SEC("license") = "GPL";
33