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