1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Copyright (c) 2017 Facebook
7 #include <linux/if_ether.h>
8 #include <linux/if_packet.h>
10 #include <linux/ipv6.h>
12 #include <linux/tcp.h>
13 #include <linux/pkt_cls.h>
14 #include "bpf_helpers.h"
15 #include "bpf_endian.h"
17 #define barrier() __asm__ __volatile__("": : :"memory")
18 int _version
SEC("version") = 1;
21 int process(struct __sk_buff
*skb
)
23 void *data_end
= (void *)(long)skb
->data_end
;
24 void *data
= (void *)(long)skb
->data
;
25 struct ethhdr
*eth
= (struct ethhdr
*)(data
);
26 struct tcphdr
*tcp
= NULL
;
30 if (eth
+ 1 > data_end
)
33 if (eth
->h_proto
== bpf_htons(ETH_P_IP
)) {
34 struct iphdr
*iph
= (struct iphdr
*)(eth
+ 1);
36 if (iph
+ 1 > data_end
)
38 ihl_len
= iph
->ihl
* 4;
39 proto
= iph
->protocol
;
40 tcp
= (struct tcphdr
*)((void *)(iph
) + ihl_len
);
41 } else if (eth
->h_proto
== bpf_htons(ETH_P_IPV6
)) {
42 struct ipv6hdr
*ip6h
= (struct ipv6hdr
*)(eth
+ 1);
44 if (ip6h
+ 1 > data_end
)
46 ihl_len
= sizeof(*ip6h
);
47 proto
= ip6h
->nexthdr
;
48 tcp
= (struct tcphdr
*)((void *)(ip6h
) + ihl_len
);
52 if (((void *)(tcp
) + 20) > data_end
|| proto
!= 6)
54 barrier(); /* to force ordering of checks */
55 if (((void *)(tcp
) + 18) > data_end
)
57 if (tcp
->urg_ptr
== 123)