blob: fae3b96c3aa48d0f69a0acca800b424d4fd04336 [file] [log] [blame]
John Fastabend6f6d33f2017-08-15 22:34:22 -07001#include <linux/bpf.h>
2#include "bpf_helpers.h"
3#include "bpf_util.h"
4#include "bpf_endian.h"
5
6int _version SEC("version") = 1;
7
8#define bpf_printk(fmt, ...) \
9({ \
10 char ____fmt[] = fmt; \
11 bpf_trace_printk(____fmt, sizeof(____fmt), \
12 ##__VA_ARGS__); \
13})
14
15SEC("sk_skb1")
16int bpf_prog1(struct __sk_buff *skb)
17{
18 void *data_end = (void *)(long) skb->data_end;
19 void *data = (void *)(long) skb->data;
20 __u32 lport = skb->local_port;
21 __u32 rport = skb->remote_port;
John Fastabend6fd28862017-08-28 07:11:05 -070022 __u8 *d = data;
John Fastabend6f6d33f2017-08-15 22:34:22 -070023
John Fastabend6fd28862017-08-28 07:11:05 -070024 if (data + 10 > data_end)
John Fastabend6f6d33f2017-08-15 22:34:22 -070025 return skb->len;
26
27 /* This write/read is a bit pointless but tests the verifier and
28 * strparser handler for read/write pkt data and access into sk
29 * fields.
30 */
John Fastabend6fd28862017-08-28 07:11:05 -070031 d[7] = 1;
John Fastabend6f6d33f2017-08-15 22:34:22 -070032
John Fastabend464bc0f2017-08-28 07:10:04 -070033 bpf_printk("parse: data[0] = (%u): local_port %i remote %i\n",
John Fastabend6f6d33f2017-08-15 22:34:22 -070034 d[0], lport, bpf_ntohl(rport));
35 return skb->len;
36}
37
38char _license[] SEC("license") = "GPL";