1 // SPDX-License-Identifier: GPL-2.0
6 #include <linux/stddef.h>
7 #include <linux/pkt_cls.h>
9 #include <bpf/bpf_helpers.h>
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),
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
)
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";