WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / bpf / progs / test_tc_peer.c
blobfc84a7685aa2cc3b35a5a7e5a94896e3913d0117
1 // SPDX-License-Identifier: GPL-2.0
2 #include <stdint.h>
3 #include <stdbool.h>
5 #include <linux/bpf.h>
6 #include <linux/stddef.h>
7 #include <linux/pkt_cls.h>
9 #include <bpf/bpf_helpers.h>
11 enum {
12 dev_src,
13 dev_dst,
16 struct bpf_map_def SEC("maps") ifindex_map = {
17 .type = BPF_MAP_TYPE_ARRAY,
18 .key_size = sizeof(int),
19 .value_size = sizeof(int),
20 .max_entries = 2,
23 static __always_inline int get_dev_ifindex(int which)
25 int *ifindex = bpf_map_lookup_elem(&ifindex_map, &which);
27 return ifindex ? *ifindex : 0;
30 SEC("chk_egress") int tc_chk(struct __sk_buff *skb)
32 return TC_ACT_SHOT;
35 SEC("dst_ingress") int tc_dst(struct __sk_buff *skb)
37 return bpf_redirect_peer(get_dev_ifindex(dev_src), 0);
40 SEC("src_ingress") int tc_src(struct __sk_buff *skb)
42 return bpf_redirect_peer(get_dev_ifindex(dev_dst), 0);
45 char __license[] SEC("license") = "GPL";