1 #include <linux/bpf.h>
2 #include <bpf/bpf_helpers.h>
3 #include <bpf/bpf_endian.h>
4 
5 int _version SEC("version") = 1;
6 
7 SEC("sk_skb1")
8 int bpf_prog1(struct __sk_buff *skb)
9 {
10 	void *data_end = (void *)(long) skb->data_end;
11 	void *data = (void *)(long) skb->data;
12 	__u32 lport = skb->local_port;
13 	__u32 rport = skb->remote_port;
14 	__u8 *d = data;
15 	int err;
16 
17 	if (data + 10 > data_end) {
18 		err = bpf_skb_pull_data(skb, 10);
19 		if (err)
20 			return SK_DROP;
21 
22 		data_end = (void *)(long)skb->data_end;
23 		data = (void *)(long)skb->data;
24 		if (data + 10 > data_end)
25 			return SK_DROP;
26 	}
27 
28 	/* This write/read is a bit pointless but tests the verifier and
29 	 * strparser handler for read/write pkt data and access into sk
30 	 * fields.
31 	 */
32 	d = data;
33 	d[7] = 1;
34 	return skb->len;
35 }
36 
37 char _license[] SEC("license") = "GPL";
38