Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / tools / testing / selftests / bpf / sockmap_verdict_prog.c
blobd7bea972cb21bf09c84b38938df9951a0eedf5fc
1 #include <linux/bpf.h>
2 #include "bpf_helpers.h"
3 #include "bpf_util.h"
4 #include "bpf_endian.h"
6 int _version SEC("version") = 1;
8 #define bpf_printk(fmt, ...) \
9 ({ \
10 char ____fmt[] = fmt; \
11 bpf_trace_printk(____fmt, sizeof(____fmt), \
12 ##__VA_ARGS__); \
15 struct bpf_map_def SEC("maps") sock_map_rx = {
16 .type = BPF_MAP_TYPE_SOCKMAP,
17 .key_size = sizeof(int),
18 .value_size = sizeof(int),
19 .max_entries = 20,
22 struct bpf_map_def SEC("maps") sock_map_tx = {
23 .type = BPF_MAP_TYPE_SOCKMAP,
24 .key_size = sizeof(int),
25 .value_size = sizeof(int),
26 .max_entries = 20,
29 struct bpf_map_def SEC("maps") sock_map_break = {
30 .type = BPF_MAP_TYPE_ARRAY,
31 .key_size = sizeof(int),
32 .value_size = sizeof(int),
33 .max_entries = 20,
36 SEC("sk_skb2")
37 int bpf_prog2(struct __sk_buff *skb)
39 void *data_end = (void *)(long) skb->data_end;
40 void *data = (void *)(long) skb->data;
41 __u32 lport = skb->local_port;
42 __u32 rport = skb->remote_port;
43 __u8 *d = data;
44 __u8 sk, map;
46 if (data + 8 > data_end)
47 return SK_DROP;
49 map = d[0];
50 sk = d[1];
52 d[0] = 0xd;
53 d[1] = 0xe;
54 d[2] = 0xa;
55 d[3] = 0xd;
56 d[4] = 0xb;
57 d[5] = 0xe;
58 d[6] = 0xe;
59 d[7] = 0xf;
61 if (!map)
62 return bpf_sk_redirect_map(skb, &sock_map_rx, sk, 0);
63 return bpf_sk_redirect_map(skb, &sock_map_tx, sk, 0);
66 char _license[] SEC("license") = "GPL";