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 	__u32 lport = skb->local_port;
11 	__u32 rport = skb->remote_port;
12 	__u8 *d = data;
13 	int err;
14 
15 	if (data + 10 > data_end) {
16 		err = bpf_skb_pull_data(skb, 10);
17 		if (err)
18 			return SK_DROP;
19 
20 		data_end = (void *)(long)skb->data_end;
21 		data = (void *)(long)skb->data;
22 		if (data + 10 > data_end)
23 			return SK_DROP;
24 	}
25 
26 	/* This write/read is a bit pointless but tests the verifier and
27 	 * strparser handler for read/write pkt data and access into sk
28 	 * fields.
29 	 */
30 	d = data;
31 	d[7] = 1;
32 	return skb->len;
33 }
34 
35 char _license[] SEC("license") = "GPL";
36