brintos

brintos / linux-shallow public Read only

0
0
Text · 705 B · c9abfe3 Raw
34 lines · c
1#include <linux/bpf.h>2#include <bpf/bpf_helpers.h>3#include <bpf/bpf_endian.h>4 5SEC("sk_skb1")6int 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 and25	 * strparser handler for read/write pkt data and access into sk26	 * fields.27	 */28	d = data;29	d[7] = 1;30	return skb->len;31}32 33char _license[] SEC("license") = "GPL";34