diff options
author | Alexei Starovoitov <ast@fb.com> | 2016-09-15 16:00:31 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2016-09-17 10:13:07 -0400 |
commit | a1c82704d13fd0d0ab0eb10d33a9bb7af83c90e3 (patch) | |
tree | 8bb3712f82068641c1eddb710b445841c97f0845 | |
parent | 8d79266bc48c6ab6477d04e159cabf1e7809cb72 (diff) |
samples/bpf: extend test_tunnel_bpf.sh with IPIP test
extend existing tests for vxlan, geneve, gre to include IPIP tunnel.
It tests both traditional tunnel configuration and
dynamic via bpf helpers.
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | samples/bpf/tcbpf2_kern.c | 58 | ||||
-rwxr-xr-x | samples/bpf/test_tunnel_bpf.sh | 56 |
2 files changed, 106 insertions, 8 deletions
diff --git a/samples/bpf/tcbpf2_kern.c b/samples/bpf/tcbpf2_kern.c index 7a15289da6cc..c1917d968fb4 100644 --- a/samples/bpf/tcbpf2_kern.c +++ b/samples/bpf/tcbpf2_kern.c | |||
@@ -1,4 +1,5 @@ | |||
1 | /* Copyright (c) 2016 VMware | 1 | /* Copyright (c) 2016 VMware |
2 | * Copyright (c) 2016 Facebook | ||
2 | * | 3 | * |
3 | * This program is free software; you can redistribute it and/or | 4 | * 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 | * modify it under the terms of version 2 of the GNU General Public |
@@ -188,4 +189,61 @@ int _geneve_get_tunnel(struct __sk_buff *skb) | |||
188 | return TC_ACT_OK; | 189 | return TC_ACT_OK; |
189 | } | 190 | } |
190 | 191 | ||
192 | SEC("ipip_set_tunnel") | ||
193 | int _ipip_set_tunnel(struct __sk_buff *skb) | ||
194 | { | ||
195 | struct bpf_tunnel_key key = {}; | ||
196 | void *data = (void *)(long)skb->data; | ||
197 | struct iphdr *iph = data; | ||
198 | struct tcphdr *tcp = data + sizeof(*iph); | ||
199 | void *data_end = (void *)(long)skb->data_end; | ||
200 | int ret; | ||
201 | |||
202 | /* single length check */ | ||
203 | if (data + sizeof(*iph) + sizeof(*tcp) > data_end) { | ||
204 | ERROR(1); | ||
205 | return TC_ACT_SHOT; | ||
206 | } | ||
207 | |||
208 | key.tunnel_ttl = 64; | ||
209 | if (iph->protocol == IPPROTO_ICMP) { | ||
210 | key.remote_ipv4 = 0xac100164; /* 172.16.1.100 */ | ||
211 | } else { | ||
212 | if (iph->protocol != IPPROTO_TCP || iph->ihl != 5) | ||
213 | return TC_ACT_SHOT; | ||
214 | |||
215 | if (tcp->dest == htons(5200)) | ||
216 | key.remote_ipv4 = 0xac100164; /* 172.16.1.100 */ | ||
217 | else if (tcp->dest == htons(5201)) | ||
218 | key.remote_ipv4 = 0xac100165; /* 172.16.1.101 */ | ||
219 | else | ||
220 | return TC_ACT_SHOT; | ||
221 | } | ||
222 | |||
223 | ret = bpf_skb_set_tunnel_key(skb, &key, sizeof(key), 0); | ||
224 | if (ret < 0) { | ||
225 | ERROR(ret); | ||
226 | return TC_ACT_SHOT; | ||
227 | } | ||
228 | |||
229 | return TC_ACT_OK; | ||
230 | } | ||
231 | |||
232 | SEC("ipip_get_tunnel") | ||
233 | int _ipip_get_tunnel(struct __sk_buff *skb) | ||
234 | { | ||
235 | int ret; | ||
236 | struct bpf_tunnel_key key; | ||
237 | char fmt[] = "remote ip 0x%x\n"; | ||
238 | |||
239 | ret = bpf_skb_get_tunnel_key(skb, &key, sizeof(key), 0); | ||
240 | if (ret < 0) { | ||
241 | ERROR(ret); | ||
242 | return TC_ACT_SHOT; | ||
243 | } | ||
244 | |||
245 | bpf_trace_printk(fmt, sizeof(fmt), key.remote_ipv4); | ||
246 | return TC_ACT_OK; | ||
247 | } | ||
248 | |||
191 | char _license[] SEC("license") = "GPL"; | 249 | char _license[] SEC("license") = "GPL"; |
diff --git a/samples/bpf/test_tunnel_bpf.sh b/samples/bpf/test_tunnel_bpf.sh index 4956589a83ae..1ff634f187b7 100755 --- a/samples/bpf/test_tunnel_bpf.sh +++ b/samples/bpf/test_tunnel_bpf.sh | |||
@@ -9,15 +9,13 @@ | |||
9 | # local 172.16.1.200 remote 172.16.1.100 | 9 | # local 172.16.1.200 remote 172.16.1.100 |
10 | # veth1 IP: 172.16.1.200, tunnel dev <type>11 | 10 | # veth1 IP: 172.16.1.200, tunnel dev <type>11 |
11 | 11 | ||
12 | set -e | ||
13 | |||
14 | function config_device { | 12 | function config_device { |
15 | ip netns add at_ns0 | 13 | ip netns add at_ns0 |
16 | ip link add veth0 type veth peer name veth1 | 14 | ip link add veth0 type veth peer name veth1 |
17 | ip link set veth0 netns at_ns0 | 15 | ip link set veth0 netns at_ns0 |
18 | ip netns exec at_ns0 ip addr add 172.16.1.100/24 dev veth0 | 16 | ip netns exec at_ns0 ip addr add 172.16.1.100/24 dev veth0 |
19 | ip netns exec at_ns0 ip link set dev veth0 up | 17 | ip netns exec at_ns0 ip link set dev veth0 up |
20 | ip link set dev veth1 up | 18 | ip link set dev veth1 up mtu 1500 |
21 | ip addr add dev veth1 172.16.1.200/24 | 19 | ip addr add dev veth1 172.16.1.200/24 |
22 | } | 20 | } |
23 | 21 | ||
@@ -67,6 +65,19 @@ function add_geneve_tunnel { | |||
67 | ip addr add dev $DEV 10.1.1.200/24 | 65 | ip addr add dev $DEV 10.1.1.200/24 |
68 | } | 66 | } |
69 | 67 | ||
68 | function add_ipip_tunnel { | ||
69 | # in namespace | ||
70 | ip netns exec at_ns0 \ | ||
71 | ip link add dev $DEV_NS type $TYPE local 172.16.1.100 remote 172.16.1.200 | ||
72 | ip netns exec at_ns0 ip link set dev $DEV_NS up | ||
73 | ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24 | ||
74 | |||
75 | # out of namespace | ||
76 | ip link add dev $DEV type $TYPE external | ||
77 | ip link set dev $DEV up | ||
78 | ip addr add dev $DEV 10.1.1.200/24 | ||
79 | } | ||
80 | |||
70 | function attach_bpf { | 81 | function attach_bpf { |
71 | DEV=$1 | 82 | DEV=$1 |
72 | SET_TUNNEL=$2 | 83 | SET_TUNNEL=$2 |
@@ -85,6 +96,7 @@ function test_gre { | |||
85 | attach_bpf $DEV gre_set_tunnel gre_get_tunnel | 96 | attach_bpf $DEV gre_set_tunnel gre_get_tunnel |
86 | ping -c 1 10.1.1.100 | 97 | ping -c 1 10.1.1.100 |
87 | ip netns exec at_ns0 ping -c 1 10.1.1.200 | 98 | ip netns exec at_ns0 ping -c 1 10.1.1.200 |
99 | cleanup | ||
88 | } | 100 | } |
89 | 101 | ||
90 | function test_vxlan { | 102 | function test_vxlan { |
@@ -96,6 +108,7 @@ function test_vxlan { | |||
96 | attach_bpf $DEV vxlan_set_tunnel vxlan_get_tunnel | 108 | attach_bpf $DEV vxlan_set_tunnel vxlan_get_tunnel |
97 | ping -c 1 10.1.1.100 | 109 | ping -c 1 10.1.1.100 |
98 | ip netns exec at_ns0 ping -c 1 10.1.1.200 | 110 | ip netns exec at_ns0 ping -c 1 10.1.1.200 |
111 | cleanup | ||
99 | } | 112 | } |
100 | 113 | ||
101 | function test_geneve { | 114 | function test_geneve { |
@@ -107,21 +120,48 @@ function test_geneve { | |||
107 | attach_bpf $DEV geneve_set_tunnel geneve_get_tunnel | 120 | attach_bpf $DEV geneve_set_tunnel geneve_get_tunnel |
108 | ping -c 1 10.1.1.100 | 121 | ping -c 1 10.1.1.100 |
109 | ip netns exec at_ns0 ping -c 1 10.1.1.200 | 122 | ip netns exec at_ns0 ping -c 1 10.1.1.200 |
123 | cleanup | ||
124 | } | ||
125 | |||
126 | function test_ipip { | ||
127 | TYPE=ipip | ||
128 | DEV_NS=ipip00 | ||
129 | DEV=ipip11 | ||
130 | config_device | ||
131 | tcpdump -nei veth1 & | ||
132 | cat /sys/kernel/debug/tracing/trace_pipe & | ||
133 | add_ipip_tunnel | ||
134 | ethtool -K veth1 gso off gro off rx off tx off | ||
135 | ip link set dev veth1 mtu 1500 | ||
136 | attach_bpf $DEV ipip_set_tunnel ipip_get_tunnel | ||
137 | ping -c 1 10.1.1.100 | ||
138 | ip netns exec at_ns0 ping -c 1 10.1.1.200 | ||
139 | ip netns exec at_ns0 iperf -sD -p 5200 > /dev/null | ||
140 | sleep 0.2 | ||
141 | iperf -c 10.1.1.100 -n 5k -p 5200 | ||
142 | cleanup | ||
110 | } | 143 | } |
111 | 144 | ||
112 | function cleanup { | 145 | function cleanup { |
146 | set +ex | ||
147 | pkill iperf | ||
113 | ip netns delete at_ns0 | 148 | ip netns delete at_ns0 |
114 | ip link del veth1 | 149 | ip link del veth1 |
115 | ip link del $DEV | 150 | ip link del ipip11 |
151 | ip link del gretap11 | ||
152 | ip link del geneve11 | ||
153 | pkill tcpdump | ||
154 | pkill cat | ||
155 | set -ex | ||
116 | } | 156 | } |
117 | 157 | ||
158 | cleanup | ||
118 | echo "Testing GRE tunnel..." | 159 | echo "Testing GRE tunnel..." |
119 | test_gre | 160 | test_gre |
120 | cleanup | ||
121 | echo "Testing VXLAN tunnel..." | 161 | echo "Testing VXLAN tunnel..." |
122 | test_vxlan | 162 | test_vxlan |
123 | cleanup | ||
124 | echo "Testing GENEVE tunnel..." | 163 | echo "Testing GENEVE tunnel..." |
125 | test_geneve | 164 | test_geneve |
126 | cleanup | 165 | echo "Testing IPIP tunnel..." |
127 | echo "Success" | 166 | test_ipip |
167 | echo "*** PASS ***" | ||