1 // SPDX-License-Identifier: GPL-2.0
2 #define BPF_NO_PRESERVE_ACCESS_INDEX
4 #include <bpf/bpf_core_read.h>
5 #include <bpf/bpf_helpers.h>
7 #define INLINE __always_inline
9 #define skb_shorter(skb, len) ((void *)(long)(skb)->data + (len) > (void *)(long)skb->data_end)
11 #define ETH_IPV4_TCP_SIZE (14 + sizeof(struct iphdr) + sizeof(struct tcphdr))
13 static INLINE struct iphdr *get_iphdr(struct __sk_buff *skb)
15 struct iphdr *ip = NULL;
18 if (skb_shorter(skb, ETH_IPV4_TCP_SIZE))
21 eth = (void *)(long)skb->data;
22 ip = (void *)(eth + 1);
29 int main_prog(struct __sk_buff *skb)
31 struct iphdr *ip = NULL;
35 if (!(ip = get_iphdr(skb)))
40 if (proto != IPPROTO_TCP)
43 tcp = (void*)(ip + 1);
53 char _license[] SEC("license") = "GPL";