1 // SPDX-License-Identifier: GPL-2.0 2 /* Copyright (c) 2023 Isovalent */ 3 #include <stdbool.h> 4 5 #include <linux/bpf.h> 6 #include <linux/if_ether.h> 7 8 #include <bpf/bpf_endian.h> 9 #include <bpf/bpf_helpers.h> 10 11 char LICENSE[] SEC("license") = "GPL"; 12 13 bool seen_tc1; 14 bool seen_tc2; 15 bool seen_tc3; 16 bool seen_tc4; 17 bool seen_tc5; 18 bool seen_tc6; 19 bool seen_eth; 20 21 SEC("tc/ingress") 22 int tc1(struct __sk_buff *skb) 23 { 24 struct ethhdr eth = {}; 25 26 if (skb->protocol != __bpf_constant_htons(ETH_P_IP)) 27 goto out; 28 if (bpf_skb_load_bytes(skb, 0, ð, sizeof(eth))) 29 goto out; 30 seen_eth = eth.h_proto == bpf_htons(ETH_P_IP); 31 out: 32 seen_tc1 = true; 33 return TCX_NEXT; 34 } 35 36 SEC("tc/egress") 37 int tc2(struct __sk_buff *skb) 38 { 39 seen_tc2 = true; 40 return TCX_NEXT; 41 } 42 43 SEC("tc/egress") 44 int tc3(struct __sk_buff *skb) 45 { 46 seen_tc3 = true; 47 return TCX_NEXT; 48 } 49 50 SEC("tc/egress") 51 int tc4(struct __sk_buff *skb) 52 { 53 seen_tc4 = true; 54 return TCX_NEXT; 55 } 56 57 SEC("tc/egress") 58 int tc5(struct __sk_buff *skb) 59 { 60 seen_tc5 = true; 61 return TCX_PASS; 62 } 63 64 SEC("tc/egress") 65 int tc6(struct __sk_buff *skb) 66 { 67 seen_tc6 = true; 68 return TCX_PASS; 69 } 70