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