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