1 /* Copyright (c) 2016 VMware
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of version 2 of the GNU General Public
5 * License as published by the Free Software Foundation.
7 #include <uapi/linux/bpf.h>
8 #include <uapi/linux/if_ether.h>
9 #include <uapi/linux/if_packet.h>
10 #include <uapi/linux/ip.h>
11 #include <uapi/linux/in.h>
12 #include <uapi/linux/tcp.h>
13 #include <uapi/linux/filter.h>
14 #include <uapi/linux/pkt_cls.h>
15 #include "bpf_helpers.h"
17 #define ERROR(ret) do {\
18 char fmt[] = "ERROR line:%d ret:%d\n";\
19 bpf_trace_printk(fmt, sizeof(fmt), __LINE__, ret); \
29 u8 opt_data
[8]; /* hard-coded to 8 byte */
32 struct vxlan_metadata
{
37 int _gre_set_tunnel(struct __sk_buff
*skb
)
40 struct bpf_tunnel_key key
;
42 __builtin_memset(&key
, 0x0, sizeof(key
));
43 key
.remote_ipv4
= 0xac100164; /* 172.16.1.100 */
48 ret
= bpf_skb_set_tunnel_key(skb
, &key
, sizeof(key
), BPF_F_ZERO_CSUM_TX
);
58 int _gre_get_tunnel(struct __sk_buff
*skb
)
61 struct bpf_tunnel_key key
;
62 char fmt
[] = "key %d remote ip 0x%x\n";
64 ret
= bpf_skb_get_tunnel_key(skb
, &key
, sizeof(key
), 0);
70 bpf_trace_printk(fmt
, sizeof(fmt
), key
.tunnel_id
, key
.remote_ipv4
);
74 SEC("vxlan_set_tunnel")
75 int _vxlan_set_tunnel(struct __sk_buff
*skb
)
78 struct bpf_tunnel_key key
;
79 struct vxlan_metadata md
;
81 __builtin_memset(&key
, 0x0, sizeof(key
));
82 key
.remote_ipv4
= 0xac100164; /* 172.16.1.100 */
87 ret
= bpf_skb_set_tunnel_key(skb
, &key
, sizeof(key
), BPF_F_ZERO_CSUM_TX
);
93 md
.gbp
= 0x800FF; /* Set VXLAN Group Policy extension */
94 ret
= bpf_skb_set_tunnel_opt(skb
, &md
, sizeof(md
));
103 SEC("vxlan_get_tunnel")
104 int _vxlan_get_tunnel(struct __sk_buff
*skb
)
107 struct bpf_tunnel_key key
;
108 struct vxlan_metadata md
;
109 char fmt
[] = "key %d remote ip 0x%x vxlan gbp 0x%x\n";
111 ret
= bpf_skb_get_tunnel_key(skb
, &key
, sizeof(key
), 0);
117 ret
= bpf_skb_get_tunnel_opt(skb
, &md
, sizeof(md
));
123 bpf_trace_printk(fmt
, sizeof(fmt
),
124 key
.tunnel_id
, key
.remote_ipv4
, md
.gbp
);
129 SEC("geneve_set_tunnel")
130 int _geneve_set_tunnel(struct __sk_buff
*skb
)
133 struct bpf_tunnel_key key
;
134 struct geneve_opt gopt
;
136 __builtin_memset(&key
, 0x0, sizeof(key
));
137 key
.remote_ipv4
= 0xac100164; /* 172.16.1.100 */
142 __builtin_memset(&gopt
, 0x0, sizeof(gopt
));
143 gopt
.opt_class
= 0x102; /* Open Virtual Networking (OVN) */
148 gopt
.length
= 2; /* 4-byte multiple */
149 *(int *) &gopt
.opt_data
= 0xdeadbeef;
151 ret
= bpf_skb_set_tunnel_key(skb
, &key
, sizeof(key
), BPF_F_ZERO_CSUM_TX
);
157 ret
= bpf_skb_set_tunnel_opt(skb
, &gopt
, sizeof(gopt
));
166 SEC("geneve_get_tunnel")
167 int _geneve_get_tunnel(struct __sk_buff
*skb
)
170 struct bpf_tunnel_key key
;
171 struct geneve_opt gopt
;
172 char fmt
[] = "key %d remote ip 0x%x geneve class 0x%x\n";
174 ret
= bpf_skb_get_tunnel_key(skb
, &key
, sizeof(key
), 0);
180 ret
= bpf_skb_get_tunnel_opt(skb
, &gopt
, sizeof(gopt
));
186 bpf_trace_printk(fmt
, sizeof(fmt
),
187 key
.tunnel_id
, key
.remote_ipv4
, gopt
.opt_class
);
191 char _license
[] SEC("license") = "GPL";
This page took 0.034913 seconds and 5 git commands to generate.