1 // SPDX-License-Identifier: GPL-2.0
2 #ifndef BPF_NO_PRESERVE_ACCESS_INDEX
3 #define BPF_NO_PRESERVE_ACCESS_INDEX
6 #include <bpf/bpf_core_read.h>
7 #include <bpf/bpf_helpers.h>
9 #define INLINE __always_inline
11 #define skb_shorter(skb, len) ((void *)(long)(skb)->data + (len) > (void *)(long)skb->data_end)
13 #define ETH_IPV4_TCP_SIZE (14 + sizeof(struct iphdr) + sizeof(struct tcphdr))
15 static INLINE struct iphdr *get_iphdr(struct __sk_buff *skb)
17 struct iphdr *ip = NULL;
20 if (skb_shorter(skb, ETH_IPV4_TCP_SIZE))
23 eth = (void *)(long)skb->data;
24 ip = (void *)(eth + 1);
31 int main_prog(struct __sk_buff *skb)
33 struct iphdr *ip = NULL;
39 if (!(ip = get_iphdr(skb)))
44 if (proto != IPPROTO_TCP)
47 tcp = (void*)(ip + 1);
53 urg_ptr = tcp->urg_ptr;
55 /* Checksum validation part */
57 offset = sizeof(struct ethhdr) + offsetof(struct iphdr, protocol);
58 bpf_skb_store_bytes(skb, offset, &proto, sizeof(proto), BPF_F_RECOMPUTE_CSUM);
64 char _license[] SEC("license") = "GPL";