2 #include "bpf_helpers.h"
4 #include "bpf_endian.h"
6 int _version
SEC("version") = 1;
8 #define bpf_printk(fmt, ...) \
10 char ____fmt[] = fmt; \
11 bpf_trace_printk(____fmt, sizeof(____fmt), \
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),
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),
29 struct bpf_map_def
SEC("maps") sock_map_msg
= {
30 .type
= BPF_MAP_TYPE_SOCKMAP
,
31 .key_size
= sizeof(int),
32 .value_size
= sizeof(int),
36 struct bpf_map_def
SEC("maps") sock_map_break
= {
37 .type
= BPF_MAP_TYPE_ARRAY
,
38 .key_size
= sizeof(int),
39 .value_size
= sizeof(int),
44 int bpf_prog2(struct __sk_buff
*skb
)
46 void *data_end
= (void *)(long) skb
->data_end
;
47 void *data
= (void *)(long) skb
->data
;
48 __u32 lport
= skb
->local_port
;
49 __u32 rport
= skb
->remote_port
;
53 if (data
+ 8 > data_end
)
69 return bpf_sk_redirect_map(skb
, &sock_map_rx
, sk
, 0);
70 return bpf_sk_redirect_map(skb
, &sock_map_tx
, sk
, 0);
73 char _license
[] SEC("license") = "GPL";