1 // SPDX-License-Identifier: GPL-2.0
6 #include <linux/stddef.h>
7 #include <linux/pkt_cls.h>
8 #include <linux/if_ether.h>
11 #include <bpf/bpf_helpers.h>
13 volatile const __u32 IFINDEX_SRC;
14 volatile const __u32 IFINDEX_DST;
16 static const __u8 src_mac[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55};
17 static const __u8 dst_mac[] = {0x00, 0x22, 0x33, 0x44, 0x55, 0x66};
20 int tc_chk(struct __sk_buff *skb)
26 int tc_dst(struct __sk_buff *skb)
28 return bpf_redirect_peer(IFINDEX_SRC, 0);
32 int tc_src(struct __sk_buff *skb)
34 return bpf_redirect_peer(IFINDEX_DST, 0);
38 int tc_dst_l3(struct __sk_buff *skb)
40 return bpf_redirect(IFINDEX_SRC, 0);
44 int tc_src_l3(struct __sk_buff *skb)
46 __u16 proto = skb->protocol;
48 if (bpf_skb_change_head(skb, ETH_HLEN, 0) != 0)
51 if (bpf_skb_store_bytes(skb, 0, &src_mac, ETH_ALEN, 0) != 0)
54 if (bpf_skb_store_bytes(skb, ETH_ALEN, &dst_mac, ETH_ALEN, 0) != 0)
57 if (bpf_skb_store_bytes(skb, ETH_ALEN + ETH_ALEN, &proto, sizeof(__u16), 0) != 0)
60 return bpf_redirect_peer(IFINDEX_DST, 0);
63 char __license[] SEC("license") = "GPL";