Loading...
1#include <linux/bpf.h>
2#include <bpf/bpf_helpers.h>
3#include <bpf/bpf_endian.h>
4#include "bpf_misc.h"
5
6struct {
7 __uint(type, BPF_MAP_TYPE_SOCKMAP);
8 __uint(max_entries, 20);
9 __type(key, int);
10 __type(value, int);
11} sock_map_rx SEC(".maps");
12
13struct {
14 __uint(type, BPF_MAP_TYPE_SOCKMAP);
15 __uint(max_entries, 20);
16 __type(key, int);
17 __type(value, int);
18} sock_map_tx SEC(".maps");
19
20struct {
21 __uint(type, BPF_MAP_TYPE_SOCKMAP);
22 __uint(max_entries, 20);
23 __type(key, int);
24 __type(value, int);
25} sock_map_msg SEC(".maps");
26
27struct {
28 __uint(type, BPF_MAP_TYPE_ARRAY);
29 __uint(max_entries, 20);
30 __type(key, int);
31 __type(value, int);
32} sock_map_break SEC(".maps");
33
34SEC("sk_skb2")
35int bpf_prog2(struct __sk_buff *skb)
36{
37 void *data_end = (void *)(long) skb->data_end;
38 void *data = (void *)(long) skb->data;
39 __u32 lport = skb->local_port;
40 __u32 rport = skb->remote_port;
41 __u8 *d = data;
42 __u8 sk, map;
43
44 __sink(lport);
45 __sink(rport);
46
47 if (data + 8 > data_end)
48 return SK_DROP;
49
50 map = d[0];
51 sk = d[1];
52
53 d[0] = 0xd;
54 d[1] = 0xe;
55 d[2] = 0xa;
56 d[3] = 0xd;
57 d[4] = 0xb;
58 d[5] = 0xe;
59 d[6] = 0xe;
60 d[7] = 0xf;
61
62 if (!map)
63 return bpf_sk_redirect_map(skb, &sock_map_rx, sk, 0);
64 return bpf_sk_redirect_map(skb, &sock_map_tx, sk, 0);
65}
66
67char _license[] SEC("license") = "GPL";
1#include <linux/bpf.h>
2#include <bpf/bpf_helpers.h>
3#include <bpf/bpf_endian.h>
4
5int _version SEC("version") = 1;
6
7struct {
8 __uint(type, BPF_MAP_TYPE_SOCKMAP);
9 __uint(max_entries, 20);
10 __uint(key_size, sizeof(int));
11 __uint(value_size, sizeof(int));
12} sock_map_rx SEC(".maps");
13
14struct {
15 __uint(type, BPF_MAP_TYPE_SOCKMAP);
16 __uint(max_entries, 20);
17 __uint(key_size, sizeof(int));
18 __uint(value_size, sizeof(int));
19} sock_map_tx SEC(".maps");
20
21struct {
22 __uint(type, BPF_MAP_TYPE_SOCKMAP);
23 __uint(max_entries, 20);
24 __uint(key_size, sizeof(int));
25 __uint(value_size, sizeof(int));
26} sock_map_msg SEC(".maps");
27
28struct {
29 __uint(type, BPF_MAP_TYPE_ARRAY);
30 __uint(max_entries, 20);
31 __type(key, int);
32 __type(value, int);
33} sock_map_break SEC(".maps");
34
35SEC("sk_skb2")
36int bpf_prog2(struct __sk_buff *skb)
37{
38 void *data_end = (void *)(long) skb->data_end;
39 void *data = (void *)(long) skb->data;
40 __u32 lport = skb->local_port;
41 __u32 rport = skb->remote_port;
42 __u8 *d = data;
43 __u8 sk, map;
44
45 if (data + 8 > data_end)
46 return SK_DROP;
47
48 map = d[0];
49 sk = d[1];
50
51 d[0] = 0xd;
52 d[1] = 0xe;
53 d[2] = 0xa;
54 d[3] = 0xd;
55 d[4] = 0xb;
56 d[5] = 0xe;
57 d[6] = 0xe;
58 d[7] = 0xf;
59
60 if (!map)
61 return bpf_sk_redirect_map(skb, &sock_map_rx, sk, 0);
62 return bpf_sk_redirect_map(skb, &sock_map_tx, sk, 0);
63}
64
65char _license[] SEC("license") = "GPL";