Linux Audio

Check our new training course

Loading...
v6.13.7
 1// SPDX-License-Identifier: GPL-2.0
 2#ifndef BPF_NO_PRESERVE_ACCESS_INDEX
 3#define BPF_NO_PRESERVE_ACCESS_INDEX
 4#endif
 5#include <vmlinux.h>
 6#include <bpf/bpf_core_read.h>
 7#include <bpf/bpf_helpers.h>
 8
 9#define INLINE __always_inline
10
11#define skb_shorter(skb, len) ((void *)(long)(skb)->data + (len) > (void *)(long)skb->data_end)
12
13#define ETH_IPV4_TCP_SIZE (14 + sizeof(struct iphdr) + sizeof(struct tcphdr))
14
15static INLINE struct iphdr *get_iphdr(struct __sk_buff *skb)
16{
17	struct iphdr *ip = NULL;
18	struct ethhdr *eth;
19
20	if (skb_shorter(skb, ETH_IPV4_TCP_SIZE))
21		goto out;
22
23	eth = (void *)(long)skb->data;
24	ip = (void *)(eth + 1);
25
26out:
27	return ip;
28}
29
30SEC("tc")
31int main_prog(struct __sk_buff *skb)
32{
33	struct iphdr *ip = NULL;
34	struct tcphdr *tcp;
35	__u8 proto = 0;
36	int urg_ptr;
37	u32 offset;
38
39	if (!(ip = get_iphdr(skb)))
40		goto out;
41
42	proto = ip->protocol;
43
44	if (proto != IPPROTO_TCP)
45		goto out;
46
47	tcp = (void*)(ip + 1);
48	if (tcp->dest != 0)
49		goto out;
50	if (!tcp)
51		goto out;
52
53	urg_ptr = tcp->urg_ptr;
54
55	/* Checksum validation part */
56	proto++;
57	offset = sizeof(struct ethhdr) + offsetof(struct iphdr, protocol);
58	bpf_skb_store_bytes(skb, offset, &proto, sizeof(proto), BPF_F_RECOMPUTE_CSUM);
59
60	return urg_ptr;
61out:
62	return -1;
63}
64char _license[] SEC("license") = "GPL";
v6.8
 1// SPDX-License-Identifier: GPL-2.0
 
 2#define BPF_NO_PRESERVE_ACCESS_INDEX
 
 3#include <vmlinux.h>
 4#include <bpf/bpf_core_read.h>
 5#include <bpf/bpf_helpers.h>
 6
 7#define INLINE __always_inline
 8
 9#define skb_shorter(skb, len) ((void *)(long)(skb)->data + (len) > (void *)(long)skb->data_end)
10
11#define ETH_IPV4_TCP_SIZE (14 + sizeof(struct iphdr) + sizeof(struct tcphdr))
12
13static INLINE struct iphdr *get_iphdr(struct __sk_buff *skb)
14{
15	struct iphdr *ip = NULL;
16	struct ethhdr *eth;
17
18	if (skb_shorter(skb, ETH_IPV4_TCP_SIZE))
19		goto out;
20
21	eth = (void *)(long)skb->data;
22	ip = (void *)(eth + 1);
23
24out:
25	return ip;
26}
27
28SEC("tc")
29int main_prog(struct __sk_buff *skb)
30{
31	struct iphdr *ip = NULL;
32	struct tcphdr *tcp;
33	__u8 proto = 0;
 
 
34
35	if (!(ip = get_iphdr(skb)))
36		goto out;
37
38	proto = ip->protocol;
39
40	if (proto != IPPROTO_TCP)
41		goto out;
42
43	tcp = (void*)(ip + 1);
44	if (tcp->dest != 0)
45		goto out;
46	if (!tcp)
47		goto out;
48
49	return tcp->urg_ptr;
 
 
 
 
 
 
 
50out:
51	return -1;
52}
53char _license[] SEC("license") = "GPL";