1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2 #include <linux/bpf.h>
3 #include <bpf/bpf_helpers.h>
4 #include <bpf/bpf_endian.h>
5 
6 char _license[] SEC("license") = "GPL";
7 
8 int ifindex;
9 int ret;
10 
11 SEC("lwt_xmit")
redirect_ingress(struct __sk_buff * skb)12 int redirect_ingress(struct __sk_buff *skb)
13 {
14 	ret = bpf_clone_redirect(skb, ifindex, BPF_F_INGRESS);
15 	return 0;
16 }
17 
18 SEC("lwt_xmit")
redirect_egress(struct __sk_buff * skb)19 int redirect_egress(struct __sk_buff *skb)
20 {
21 	ret = bpf_clone_redirect(skb, ifindex, 0);
22 	return 0;
23 }
24 
25 SEC("tc")
tc_redirect_ingress(struct __sk_buff * skb)26 int tc_redirect_ingress(struct __sk_buff *skb)
27 {
28 	ret = bpf_clone_redirect(skb, ifindex, BPF_F_INGRESS);
29 	return 0;
30 }
31 
32 SEC("tc")
tc_redirect_egress(struct __sk_buff * skb)33 int tc_redirect_egress(struct __sk_buff *skb)
34 {
35 	ret = bpf_clone_redirect(skb, ifindex, 0);
36 	return 0;
37 }
38