1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2023 Isovalent */
6 #include <linux/if_ether.h>
7 #include <linux/stddef.h>
8 #include <linux/if_packet.h>
9 #include <bpf/bpf_endian.h>
10 #include <bpf/bpf_helpers.h>
11 #include <bpf/bpf_core_read.h>
13 char LICENSE[] SEC("license") = "GPL";
31 unsigned short headroom, tailroom;
34 int tc1(struct __sk_buff *skb)
36 struct ethhdr eth = {};
38 if (skb->protocol != __bpf_constant_htons(ETH_P_IP))
40 if (bpf_skb_load_bytes(skb, 0, ð, sizeof(eth)))
42 seen_eth = eth.h_proto == bpf_htons(ETH_P_IP);
43 seen_host = skb->pkt_type == PACKET_HOST;
44 if (seen_host && set_type) {
46 if (bpf_skb_store_bytes(skb, 0, ð, sizeof(eth), 0))
48 bpf_skb_change_type(skb, PACKET_MULTICAST);
57 int tc2(struct __sk_buff *skb)
64 int tc3(struct __sk_buff *skb)
71 int tc4(struct __sk_buff *skb)
78 int tc5(struct __sk_buff *skb)
85 int tc6(struct __sk_buff *skb)
92 int tc7(struct __sk_buff *skb)
94 struct ethhdr eth = {};
96 if (skb->protocol != __bpf_constant_htons(ETH_P_IP))
98 if (bpf_skb_load_bytes(skb, 0, ð, sizeof(eth)))
100 if (eth.h_dest[0] == 4 && set_type) {
101 seen_mcast = skb->pkt_type == PACKET_MULTICAST;
102 bpf_skb_change_type(skb, PACKET_HOST);
110 struct net_device *dev;
114 unsigned short needed_headroom;
115 unsigned short needed_tailroom;
119 int tc8(struct __sk_buff *skb)
121 struct net_device *dev = BPF_CORE_READ((struct sk_buff *)skb, dev);
125 prio = skb->priority;
126 headroom = BPF_CORE_READ(dev, needed_headroom);
127 tailroom = BPF_CORE_READ(dev, needed_tailroom);