blob: 3b428be35e4bb43371b905b6abbe45fc584417b8 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
2 * decap.c: vxlan tunnel decap packet processing
3 *
4 * Copyright (c) 2013 Cisco and/or its affiliates.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#include <vlib/vlib.h>
19#include <vnet/pg/pg.h>
20#include <vnet/vxlan/vxlan.h>
21
Eyal Baria5679e82018-08-26 15:20:07 +030022#ifndef CLIB_MARCH_VARIANT
John Lo13e3d452016-08-09 19:20:51 -040023vlib_node_registration_t vxlan4_input_node;
24vlib_node_registration_t vxlan6_input_node;
Eyal Baria5679e82018-08-26 15:20:07 +030025#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -070026
Eyal Bari7d92c092018-07-24 15:15:37 +030027typedef struct
28{
Ed Warnickecb9cada2015-12-08 15:45:58 -070029 u32 next_index;
30 u32 tunnel_index;
31 u32 error;
32 u32 vni;
33} vxlan_rx_trace_t;
34
Eyal Bari7d92c092018-07-24 15:15:37 +030035static u8 *
36format_vxlan_rx_trace (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -070037{
38 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
39 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
Eyal Bari7d92c092018-07-24 15:15:37 +030040 vxlan_rx_trace_t *t = va_arg (*args, vxlan_rx_trace_t *);
Ed Warnickecb9cada2015-12-08 15:45:58 -070041
Eyal Bari7d92c092018-07-24 15:15:37 +030042 if (t->tunnel_index == ~0)
43 return format (s, "VXLAN decap error - tunnel for vni %d does not exist",
44 t->vni);
45 return format (s, "VXLAN decap from vxlan_tunnel%d vni %d next %d error %d",
46 t->tunnel_index, t->vni, t->next_index, t->error);
Ed Warnickecb9cada2015-12-08 15:45:58 -070047}
48
Eyal Baridd47eca2018-07-08 08:15:56 +030049typedef vxlan4_tunnel_key_t last_tunnel_cache4;
Eyal Bari0f4b1842018-04-12 12:39:51 +030050
Eyal Bariefd9cf32018-10-02 12:23:06 +030051static const vxlan_decap_info_t decap_not_found = {
52 .sw_if_index = ~0,
53 .next_index = VXLAN_INPUT_NEXT_DROP,
54 .error = VXLAN_ERROR_NO_SUCH_TUNNEL
55};
56
57static const vxlan_decap_info_t decap_bad_flags = {
58 .sw_if_index = ~0,
59 .next_index = VXLAN_INPUT_NEXT_DROP,
60 .error = VXLAN_ERROR_BAD_FLAGS
61};
62
63always_inline vxlan_decap_info_t
Eyal Bari0f4b1842018-04-12 12:39:51 +030064vxlan4_find_tunnel (vxlan_main_t * vxm, last_tunnel_cache4 * cache,
Eyal Bari7d92c092018-07-24 15:15:37 +030065 u32 fib_index, ip4_header_t * ip4_0,
Eyal Bariefd9cf32018-10-02 12:23:06 +030066 vxlan_header_t * vxlan0, u32 * stats_sw_if_index)
Eyal Bari0f4b1842018-04-12 12:39:51 +030067{
Eyal Bariefd9cf32018-10-02 12:23:06 +030068 if (PREDICT_FALSE (vxlan0->flags != VXLAN_FLAGS_I))
69 return decap_bad_flags;
Eyal Bari0f4b1842018-04-12 12:39:51 +030070
Eyal Bariefd9cf32018-10-02 12:23:06 +030071 /* Make sure VXLAN tunnel exist according to packet S/D IP, VRF, and VNI */
72 u32 dst = ip4_0->dst_address.as_u32;
73 u32 src = ip4_0->src_address.as_u32;
74 vxlan4_tunnel_key_t key4 = {
75 .key[0] = ((u64) dst << 32) | src,
76 .key[1] = ((u64) fib_index << 32) | vxlan0->vni_reserved,
77 };
78
79 if (PREDICT_TRUE
Eyal Bari9be7c6d2018-10-17 17:13:42 +030080 (key4.key[0] == cache->key[0] && key4.key[1] == cache->key[1]))
Eyal Bari7d92c092018-07-24 15:15:37 +030081 {
Eyal Bariefd9cf32018-10-02 12:23:06 +030082 /* cache hit */
83 vxlan_decap_info_t di = {.as_u64 = cache->value };
84 *stats_sw_if_index = di.sw_if_index;
85 return di;
86 }
Eyal Bari0f4b1842018-04-12 12:39:51 +030087
Eyal Bariefd9cf32018-10-02 12:23:06 +030088 int rv = clib_bihash_search_inline_16_8 (&vxm->vxlan4_tunnel_by_key, &key4);
89 if (PREDICT_TRUE (rv == 0))
90 {
Eyal Bari7d92c092018-07-24 15:15:37 +030091 *cache = key4;
Eyal Bariefd9cf32018-10-02 12:23:06 +030092 vxlan_decap_info_t di = {.as_u64 = key4.value };
93 *stats_sw_if_index = di.sw_if_index;
94 return di;
Eyal Bari7d92c092018-07-24 15:15:37 +030095 }
Eyal Bari0f4b1842018-04-12 12:39:51 +030096
Eyal Bariefd9cf32018-10-02 12:23:06 +030097 /* try multicast */
98 if (PREDICT_TRUE (!ip4_address_is_multicast (&ip4_0->dst_address)))
99 return decap_not_found;
100
101 /* search for mcast decap info by mcast address */
102 key4.key[0] = dst;
103 rv = clib_bihash_search_inline_16_8 (&vxm->vxlan4_tunnel_by_key, &key4);
104 if (rv != 0)
105 return decap_not_found;
106
107 /* search for unicast tunnel using the mcast tunnel local(src) ip */
108 vxlan_decap_info_t mdi = {.as_u64 = key4.value };
109 key4.key[0] = ((u64) mdi.local_ip.as_u32 << 32) | src;
110 rv = clib_bihash_search_inline_16_8 (&vxm->vxlan4_tunnel_by_key, &key4);
111 if (PREDICT_FALSE (rv != 0))
112 return decap_not_found;
113
114 /* mcast traffic does not update the cache */
115 *stats_sw_if_index = mdi.sw_if_index;
116 vxlan_decap_info_t di = {.as_u64 = key4.value };
117 return di;
Eyal Bari0f4b1842018-04-12 12:39:51 +0300118}
119
Eyal Bari0fa56782018-06-04 12:25:05 +0300120typedef vxlan6_tunnel_key_t last_tunnel_cache6;
121
Eyal Bariefd9cf32018-10-02 12:23:06 +0300122always_inline vxlan_decap_info_t
Eyal Bari0f4b1842018-04-12 12:39:51 +0300123vxlan6_find_tunnel (vxlan_main_t * vxm, last_tunnel_cache6 * cache,
Eyal Bari7d92c092018-07-24 15:15:37 +0300124 u32 fib_index, ip6_header_t * ip6_0,
Eyal Bariefd9cf32018-10-02 12:23:06 +0300125 vxlan_header_t * vxlan0, u32 * stats_sw_if_index)
Eyal Bari0f4b1842018-04-12 12:39:51 +0300126{
Eyal Bariefd9cf32018-10-02 12:23:06 +0300127 if (PREDICT_FALSE (vxlan0->flags != VXLAN_FLAGS_I))
128 return decap_bad_flags;
129
Eyal Bari0f4b1842018-04-12 12:39:51 +0300130 /* Make sure VXLAN tunnel exist according to packet SIP and VNI */
Eyal Bari0fa56782018-06-04 12:25:05 +0300131 vxlan6_tunnel_key_t key6 = {
Eyal Bariefd9cf32018-10-02 12:23:06 +0300132 .key[0] = ip6_0->src_address.as_u64[0],
133 .key[1] = ip6_0->src_address.as_u64[1],
134 .key[2] = (((u64) fib_index) << 32) | vxlan0->vni_reserved,
Eyal Bari0f4b1842018-04-12 12:39:51 +0300135 };
136
Eyal Bari7d92c092018-07-24 15:15:37 +0300137 if (PREDICT_FALSE
138 (clib_bihash_key_compare_24_8 (key6.key, cache->key) == 0))
139 {
140 int rv =
141 clib_bihash_search_inline_24_8 (&vxm->vxlan6_tunnel_by_key, &key6);
142 if (PREDICT_FALSE (rv != 0))
Eyal Bariefd9cf32018-10-02 12:23:06 +0300143 return decap_not_found;
Eyal Bari0f4b1842018-04-12 12:39:51 +0300144
Eyal Bari7d92c092018-07-24 15:15:37 +0300145 *cache = key6;
146 }
147 vxlan_tunnel_t *t0 = pool_elt_at_index (vxm->tunnels, cache->value);
Eyal Bari0f4b1842018-04-12 12:39:51 +0300148
149 /* Validate VXLAN tunnel SIP against packet DIP */
150 if (PREDICT_TRUE (ip6_address_is_equal (&ip6_0->dst_address, &t0->src.ip6)))
Eyal Bariefd9cf32018-10-02 12:23:06 +0300151 *stats_sw_if_index = t0->sw_if_index;
Eyal Bari0f4b1842018-04-12 12:39:51 +0300152 else
Eyal Bari7d92c092018-07-24 15:15:37 +0300153 {
154 /* try multicast */
155 if (PREDICT_TRUE (!ip6_address_is_multicast (&ip6_0->dst_address)))
Eyal Bariefd9cf32018-10-02 12:23:06 +0300156 return decap_not_found;
Eyal Bari0f4b1842018-04-12 12:39:51 +0300157
Eyal Bari7d92c092018-07-24 15:15:37 +0300158 /* Make sure mcast VXLAN tunnel exist by packet DIP and VNI */
159 key6.key[0] = ip6_0->dst_address.as_u64[0];
160 key6.key[1] = ip6_0->dst_address.as_u64[1];
161 int rv =
162 clib_bihash_search_inline_24_8 (&vxm->vxlan6_tunnel_by_key, &key6);
163 if (PREDICT_FALSE (rv != 0))
Eyal Bariefd9cf32018-10-02 12:23:06 +0300164 return decap_not_found;
Eyal Bari0fa56782018-06-04 12:25:05 +0300165
Eyal Bariefd9cf32018-10-02 12:23:06 +0300166 vxlan_tunnel_t *mcast_t0 = pool_elt_at_index (vxm->tunnels, key6.value);
167 *stats_sw_if_index = mcast_t0->sw_if_index;
Eyal Bari7d92c092018-07-24 15:15:37 +0300168 }
Eyal Bari0f4b1842018-04-12 12:39:51 +0300169
Eyal Bariefd9cf32018-10-02 12:23:06 +0300170 vxlan_decap_info_t di = {
171 .sw_if_index = t0->sw_if_index,
172 .next_index = t0->decap_next_index,
173 };
174 return di;
Eyal Bari0f4b1842018-04-12 12:39:51 +0300175}
176
Chris Luke99cb3352016-04-26 10:49:53 -0400177always_inline uword
Ed Warnickecb9cada2015-12-08 15:45:58 -0700178vxlan_input (vlib_main_t * vm,
Eyal Bari7d92c092018-07-24 15:15:37 +0300179 vlib_node_runtime_t * node,
180 vlib_frame_t * from_frame, u32 is_ip4)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700181{
Eyal Bari7d92c092018-07-24 15:15:37 +0300182 vxlan_main_t *vxm = &vxlan_main;
183 vnet_main_t *vnm = vxm->vnet_main;
184 vnet_interface_main_t *im = &vnm->interface_main;
185 vlib_combined_counter_main_t *rx_counter =
186 im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_RX;
Eyal Baridd47eca2018-07-08 08:15:56 +0300187 last_tunnel_cache4 last4;
Eyal Bari0fa56782018-06-04 12:25:05 +0300188 last_tunnel_cache6 last6;
Eyal Baria5679e82018-08-26 15:20:07 +0300189 u32 pkts_dropped = 0;
Eyal Bari7d92c092018-07-24 15:15:37 +0300190 u32 thread_index = vlib_get_thread_index ();
Ed Warnickecb9cada2015-12-08 15:45:58 -0700191
Dave Barachf9c231e2016-08-05 10:10:18 -0400192 if (is_ip4)
Dave Barachb7b92992018-10-17 10:38:51 -0400193 clib_memset (&last4, 0xff, sizeof last4);
Dave Barachf9c231e2016-08-05 10:10:18 -0400194 else
Dave Barachb7b92992018-10-17 10:38:51 -0400195 clib_memset (&last6, 0xff, sizeof last6);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700196
Eyal Bari7d92c092018-07-24 15:15:37 +0300197 u32 *from = vlib_frame_vector_args (from_frame);
Eyal Barifb663012017-10-19 15:27:51 +0300198 u32 n_left_from = from_frame->n_vectors;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700199
Eyal Baria5679e82018-08-26 15:20:07 +0300200 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs;
201 vlib_get_buffers (vm, from, bufs, n_left_from);
202
Eyal Bariefd9cf32018-10-02 12:23:06 +0300203 u32 stats_if0 = ~0, stats_if1 = ~0;
Eyal Baria5679e82018-08-26 15:20:07 +0300204 u16 nexts[VLIB_FRAME_SIZE], *next = nexts;
205 while (n_left_from >= 4)
206 {
207 /* Prefetch next iteration. */
208 vlib_prefetch_buffer_header (b[2], LOAD);
209 vlib_prefetch_buffer_header (b[3], LOAD);
210
211 /* udp leaves current_data pointing at the vxlan header */
212 void *cur0 = vlib_buffer_get_current (b[0]);
213 void *cur1 = vlib_buffer_get_current (b[1]);
214 vxlan_header_t *vxlan0 = cur0;
215 vxlan_header_t *vxlan1 = cur1;
216
Eyal Baria5679e82018-08-26 15:20:07 +0300217
218 ip4_header_t *ip4_0, *ip4_1;
219 ip6_header_t *ip6_0, *ip6_1;
220 if (is_ip4)
221 {
222 ip4_0 = cur0 - sizeof (udp_header_t) - sizeof (ip4_header_t);
223 ip4_1 = cur1 - sizeof (udp_header_t) - sizeof (ip4_header_t);
224 }
225 else
226 {
227 ip6_0 = cur0 - sizeof (udp_header_t) - sizeof (ip6_header_t);
228 ip6_1 = cur1 - sizeof (udp_header_t) - sizeof (ip6_header_t);
229 }
230
231 /* pop vxlan */
232 vlib_buffer_advance (b[0], sizeof *vxlan0);
233 vlib_buffer_advance (b[1], sizeof *vxlan1);
234
Nick Zavaritsky27518c22020-02-27 15:54:58 +0000235 u32 fi0 = vlib_buffer_get_ip_fib_index (b[0], is_ip4);
236 u32 fi1 = vlib_buffer_get_ip_fib_index (b[1], is_ip4);
Eyal Baria5679e82018-08-26 15:20:07 +0300237
Eyal Bariefd9cf32018-10-02 12:23:06 +0300238 vxlan_decap_info_t di0 = is_ip4 ?
239 vxlan4_find_tunnel (vxm, &last4, fi0, ip4_0, vxlan0, &stats_if0) :
240 vxlan6_find_tunnel (vxm, &last6, fi0, ip6_0, vxlan0, &stats_if0);
241 vxlan_decap_info_t di1 = is_ip4 ?
242 vxlan4_find_tunnel (vxm, &last4, fi1, ip4_1, vxlan1, &stats_if1) :
243 vxlan6_find_tunnel (vxm, &last6, fi1, ip6_1, vxlan1, &stats_if1);
Eyal Baria5679e82018-08-26 15:20:07 +0300244
245 /* Prefetch next iteration. */
246 CLIB_PREFETCH (b[2]->data, CLIB_CACHE_LINE_BYTES, LOAD);
247 CLIB_PREFETCH (b[3]->data, CLIB_CACHE_LINE_BYTES, LOAD);
248
249 u32 len0 = vlib_buffer_length_in_chain (vm, b[0]);
250 u32 len1 = vlib_buffer_length_in_chain (vm, b[1]);
251
Eyal Bariefd9cf32018-10-02 12:23:06 +0300252 next[0] = di0.next_index;
253 next[1] = di1.next_index;
Eyal Baria5679e82018-08-26 15:20:07 +0300254
Eyal Bariefd9cf32018-10-02 12:23:06 +0300255 u8 any_error = di0.error | di1.error;
256 if (PREDICT_TRUE (any_error == 0))
257 {
258 /* Required to make the l2 tag push / pop code work on l2 subifs */
259 vnet_update_l2_len (b[0]);
260 vnet_update_l2_len (b[1]);
261 /* Set packet input sw_if_index to unicast VXLAN tunnel for learning */
262 vnet_buffer (b[0])->sw_if_index[VLIB_RX] = di0.sw_if_index;
263 vnet_buffer (b[1])->sw_if_index[VLIB_RX] = di1.sw_if_index;
264 vlib_increment_combined_counter (rx_counter, thread_index,
265 stats_if0, 1, len0);
266 vlib_increment_combined_counter (rx_counter, thread_index,
267 stats_if1, 1, len1);
Eyal Baria5679e82018-08-26 15:20:07 +0300268 }
269 else
270 {
Eyal Bariefd9cf32018-10-02 12:23:06 +0300271 if (di0.error == 0)
Eyal Baria5679e82018-08-26 15:20:07 +0300272 {
Eyal Bariefd9cf32018-10-02 12:23:06 +0300273 vnet_update_l2_len (b[0]);
274 vnet_buffer (b[0])->sw_if_index[VLIB_RX] = di0.sw_if_index;
275 vlib_increment_combined_counter (rx_counter, thread_index,
276 stats_if0, 1, len0);
Eyal Baria5679e82018-08-26 15:20:07 +0300277 }
Eyal Bariefd9cf32018-10-02 12:23:06 +0300278 else
279 {
280 b[0]->error = node->errors[di0.error];
281 pkts_dropped++;
282 }
Eyal Baria5679e82018-08-26 15:20:07 +0300283
Eyal Bariefd9cf32018-10-02 12:23:06 +0300284 if (di1.error == 0)
285 {
286 vnet_update_l2_len (b[1]);
287 vnet_buffer (b[1])->sw_if_index[VLIB_RX] = di1.sw_if_index;
288 vlib_increment_combined_counter (rx_counter, thread_index,
289 stats_if1, 1, len1);
290 }
291 else
292 {
293 b[1]->error = node->errors[di1.error];
294 pkts_dropped++;
295 }
Eyal Baria5679e82018-08-26 15:20:07 +0300296 }
297
298 if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED))
299 {
300 vxlan_rx_trace_t *tr =
301 vlib_add_trace (vm, node, b[0], sizeof (*tr));
302 tr->next_index = next[0];
Eyal Bariefd9cf32018-10-02 12:23:06 +0300303 tr->error = di0.error;
304 tr->tunnel_index = di0.sw_if_index == ~0 ?
305 ~0 : vxm->tunnel_index_by_sw_if_index[di0.sw_if_index];
Eyal Baria5679e82018-08-26 15:20:07 +0300306 tr->vni = vnet_get_vni (vxlan0);
307 }
308 if (PREDICT_FALSE (b[1]->flags & VLIB_BUFFER_IS_TRACED))
309 {
310 vxlan_rx_trace_t *tr =
311 vlib_add_trace (vm, node, b[1], sizeof (*tr));
312 tr->next_index = next[1];
Eyal Bariefd9cf32018-10-02 12:23:06 +0300313 tr->error = di1.error;
314 tr->tunnel_index = di1.sw_if_index == ~0 ?
315 ~0 : vxm->tunnel_index_by_sw_if_index[di1.sw_if_index];
Eyal Baria5679e82018-08-26 15:20:07 +0300316 tr->vni = vnet_get_vni (vxlan1);
317 }
318 b += 2;
319 next += 2;
320 n_left_from -= 2;
321 }
322
Ed Warnickecb9cada2015-12-08 15:45:58 -0700323 while (n_left_from > 0)
324 {
Eyal Baria5679e82018-08-26 15:20:07 +0300325 /* udp leaves current_data pointing at the vxlan header */
326 void *cur0 = vlib_buffer_get_current (b[0]);
327 vxlan_header_t *vxlan0 = cur0;
Eyal Baria5679e82018-08-26 15:20:07 +0300328 ip4_header_t *ip4_0;
329 ip6_header_t *ip6_0;
330 if (is_ip4)
331 ip4_0 = cur0 - sizeof (udp_header_t) - sizeof (ip4_header_t);
332 else
333 ip6_0 = cur0 - sizeof (udp_header_t) - sizeof (ip6_header_t);
Eyal Barifb663012017-10-19 15:27:51 +0300334
Eyal Baria5679e82018-08-26 15:20:07 +0300335 /* pop (ip, udp, vxlan) */
336 vlib_buffer_advance (b[0], sizeof (*vxlan0));
337
Nick Zavaritsky27518c22020-02-27 15:54:58 +0000338 u32 fi0 = vlib_buffer_get_ip_fib_index (b[0], is_ip4);
Eyal Baria5679e82018-08-26 15:20:07 +0300339
Eyal Bariefd9cf32018-10-02 12:23:06 +0300340 vxlan_decap_info_t di0 = is_ip4 ?
341 vxlan4_find_tunnel (vxm, &last4, fi0, ip4_0, vxlan0, &stats_if0) :
342 vxlan6_find_tunnel (vxm, &last6, fi0, ip6_0, vxlan0, &stats_if0);
Eyal Baria5679e82018-08-26 15:20:07 +0300343
Eyal Baria5679e82018-08-26 15:20:07 +0300344 uword len0 = vlib_buffer_length_in_chain (vm, b[0]);
345
Eyal Bariefd9cf32018-10-02 12:23:06 +0300346 next[0] = di0.next_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700347
Eyal Bariefd9cf32018-10-02 12:23:06 +0300348 /* Validate VXLAN tunnel encap-fib index against packet */
349 if (di0.error == 0)
350 {
351 /* Required to make the l2 tag push / pop code work on l2 subifs */
352 vnet_update_l2_len (b[0]);
353
354 /* Set packet input sw_if_index to unicast VXLAN tunnel for learning */
355 vnet_buffer (b[0])->sw_if_index[VLIB_RX] = di0.sw_if_index;
356
357 vlib_increment_combined_counter (rx_counter, thread_index,
358 stats_if0, 1, len0);
Eyal Baria5679e82018-08-26 15:20:07 +0300359 }
360 else
361 {
Eyal Bariefd9cf32018-10-02 12:23:06 +0300362 b[0]->error = node->errors[di0.error];
363 pkts_dropped++;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700364 }
365
Eyal Baria5679e82018-08-26 15:20:07 +0300366 if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700367 {
Eyal Baria5679e82018-08-26 15:20:07 +0300368 vxlan_rx_trace_t *tr
369 = vlib_add_trace (vm, node, b[0], sizeof (*tr));
370 tr->next_index = next[0];
Eyal Bariefd9cf32018-10-02 12:23:06 +0300371 tr->error = di0.error;
372 tr->tunnel_index = di0.sw_if_index == ~0 ?
373 ~0 : vxm->tunnel_index_by_sw_if_index[di0.sw_if_index];
Eyal Baria5679e82018-08-26 15:20:07 +0300374 tr->vni = vnet_get_vni (vxlan0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700375 }
Eyal Baria5679e82018-08-26 15:20:07 +0300376 b += 1;
377 next += 1;
378 n_left_from -= 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700379 }
Eyal Baria5679e82018-08-26 15:20:07 +0300380 vlib_buffer_enqueue_to_next (vm, node, from, nexts, from_frame->n_vectors);
Eyal Barifb663012017-10-19 15:27:51 +0300381 /* Do we still need this now that tunnel tx stats is kept? */
382 u32 node_idx = is_ip4 ? vxlan4_input_node.index : vxlan6_input_node.index;
383 vlib_node_increment_counter (vm, node_idx, VXLAN_ERROR_DECAPSULATED,
Eyal Baria5679e82018-08-26 15:20:07 +0300384 from_frame->n_vectors - pkts_dropped);
Eyal Barifb663012017-10-19 15:27:51 +0300385
Ed Warnickecb9cada2015-12-08 15:45:58 -0700386 return from_frame->n_vectors;
387}
388
Eyal Baria5679e82018-08-26 15:20:07 +0300389VLIB_NODE_FN (vxlan4_input_node) (vlib_main_t * vm,
390 vlib_node_runtime_t * node,
391 vlib_frame_t * from_frame)
Chris Luke99cb3352016-04-26 10:49:53 -0400392{
Eyal Bari7d92c092018-07-24 15:15:37 +0300393 return vxlan_input (vm, node, from_frame, /* is_ip4 */ 1);
Chris Luke99cb3352016-04-26 10:49:53 -0400394}
395
Eyal Baria5679e82018-08-26 15:20:07 +0300396VLIB_NODE_FN (vxlan6_input_node) (vlib_main_t * vm,
397 vlib_node_runtime_t * node,
398 vlib_frame_t * from_frame)
Chris Luke99cb3352016-04-26 10:49:53 -0400399{
Eyal Bari7d92c092018-07-24 15:15:37 +0300400 return vxlan_input (vm, node, from_frame, /* is_ip4 */ 0);
Chris Luke99cb3352016-04-26 10:49:53 -0400401}
402
Eyal Bari7d92c092018-07-24 15:15:37 +0300403static char *vxlan_error_strings[] = {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700404#define vxlan_error(n,s) s,
405#include <vnet/vxlan/vxlan_error.def>
406#undef vxlan_error
Ed Warnickecb9cada2015-12-08 15:45:58 -0700407};
408
Eyal Bari7d92c092018-07-24 15:15:37 +0300409/* *INDENT-OFF* */
410VLIB_REGISTER_NODE (vxlan4_input_node) =
411{
Chris Luke99cb3352016-04-26 10:49:53 -0400412 .name = "vxlan4-input",
Chris Luke99cb3352016-04-26 10:49:53 -0400413 .vector_size = sizeof (u32),
Chris Luke99cb3352016-04-26 10:49:53 -0400414 .n_errors = VXLAN_N_ERROR,
415 .error_strings = vxlan_error_strings,
Chris Luke99cb3352016-04-26 10:49:53 -0400416 .n_next_nodes = VXLAN_INPUT_N_NEXT,
Eyal Bari7d92c092018-07-24 15:15:37 +0300417 .format_trace = format_vxlan_rx_trace,
Chris Luke99cb3352016-04-26 10:49:53 -0400418 .next_nodes = {
419#define _(s,n) [VXLAN_INPUT_NEXT_##s] = n,
420 foreach_vxlan_input_next
421#undef _
422 },
Chris Luke99cb3352016-04-26 10:49:53 -0400423};
Damjan Marion1c80e832016-05-11 23:07:18 +0200424
Eyal Bari7d92c092018-07-24 15:15:37 +0300425VLIB_REGISTER_NODE (vxlan6_input_node) =
426{
Chris Luke99cb3352016-04-26 10:49:53 -0400427 .name = "vxlan6-input",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700428 .vector_size = sizeof (u32),
Ed Warnickecb9cada2015-12-08 15:45:58 -0700429 .n_errors = VXLAN_N_ERROR,
430 .error_strings = vxlan_error_strings,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700431 .n_next_nodes = VXLAN_INPUT_N_NEXT,
432 .next_nodes = {
433#define _(s,n) [VXLAN_INPUT_NEXT_##s] = n,
434 foreach_vxlan_input_next
435#undef _
436 },
Ed Warnickecb9cada2015-12-08 15:45:58 -0700437 .format_trace = format_vxlan_rx_trace,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700438};
Eyal Bari7d92c092018-07-24 15:15:37 +0300439/* *INDENT-ON* */
Damjan Marion1c80e832016-05-11 23:07:18 +0200440
Eyal Bari7d92c092018-07-24 15:15:37 +0300441typedef enum
442{
John Lo37682e12016-11-30 12:51:39 -0500443 IP_VXLAN_BYPASS_NEXT_DROP,
444 IP_VXLAN_BYPASS_NEXT_VXLAN,
445 IP_VXLAN_BYPASS_N_NEXT,
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700446} ip_vxlan_bypass_next_t;
John Lo37682e12016-11-30 12:51:39 -0500447
448always_inline uword
449ip_vxlan_bypass_inline (vlib_main_t * vm,
John Lo2b81eb82017-01-30 13:12:10 -0500450 vlib_node_runtime_t * node,
Eyal Bari7d92c092018-07-24 15:15:37 +0300451 vlib_frame_t * frame, u32 is_ip4)
John Lo37682e12016-11-30 12:51:39 -0500452{
Eyal Bari7d92c092018-07-24 15:15:37 +0300453 vxlan_main_t *vxm = &vxlan_main;
454 u32 *from, *to_next, n_left_from, n_left_to_next, next_index;
455 vlib_node_runtime_t *error_node =
456 vlib_node_get_runtime (vm, ip4_input_node.index);
Nick Zavaritsky27518c22020-02-27 15:54:58 +0000457 vtep4_key_t last_vtep4; /* last IPv4 address / fib index
458 matching a local VTEP address */
459 vtep6_key_t last_vtep6; /* last IPv6 address / fib index
460 matching a local VTEP address */
John Lo37682e12016-11-30 12:51:39 -0500461
462 from = vlib_frame_vector_args (frame);
463 n_left_from = frame->n_vectors;
464 next_index = node->cached_next_index;
465
466 if (node->flags & VLIB_NODE_FLAG_TRACE)
467 ip4_forward_next_trace (vm, node, frame, VLIB_TX);
468
Eyal Bari7d92c092018-07-24 15:15:37 +0300469 if (is_ip4)
Nick Zavaritsky27518c22020-02-27 15:54:58 +0000470 vtep4_key_init (&last_vtep4);
Eyal Bari7d92c092018-07-24 15:15:37 +0300471 else
Nick Zavaritsky27518c22020-02-27 15:54:58 +0000472 vtep6_key_init (&last_vtep6);
John Lo37682e12016-11-30 12:51:39 -0500473
474 while (n_left_from > 0)
475 {
476 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
477
478 while (n_left_from >= 4 && n_left_to_next >= 2)
Eyal Bari7d92c092018-07-24 15:15:37 +0300479 {
480 vlib_buffer_t *b0, *b1;
481 ip4_header_t *ip40, *ip41;
482 ip6_header_t *ip60, *ip61;
483 udp_header_t *udp0, *udp1;
484 u32 bi0, ip_len0, udp_len0, flags0, next0;
485 u32 bi1, ip_len1, udp_len1, flags1, next1;
486 i32 len_diff0, len_diff1;
487 u8 error0, good_udp0, proto0;
488 u8 error1, good_udp1, proto1;
John Lo37682e12016-11-30 12:51:39 -0500489
490 /* Prefetch next iteration. */
491 {
Eyal Bari7d92c092018-07-24 15:15:37 +0300492 vlib_buffer_t *p2, *p3;
John Lo37682e12016-11-30 12:51:39 -0500493
494 p2 = vlib_get_buffer (vm, from[2]);
495 p3 = vlib_get_buffer (vm, from[3]);
496
497 vlib_prefetch_buffer_header (p2, LOAD);
498 vlib_prefetch_buffer_header (p3, LOAD);
499
Eyal Bari7d92c092018-07-24 15:15:37 +0300500 CLIB_PREFETCH (p2->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
501 CLIB_PREFETCH (p3->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
John Lo37682e12016-11-30 12:51:39 -0500502 }
503
Eyal Bari7d92c092018-07-24 15:15:37 +0300504 bi0 = to_next[0] = from[0];
505 bi1 = to_next[1] = from[1];
506 from += 2;
507 n_left_from -= 2;
508 to_next += 2;
509 n_left_to_next -= 2;
John Lo37682e12016-11-30 12:51:39 -0500510
511 b0 = vlib_get_buffer (vm, bi0);
512 b1 = vlib_get_buffer (vm, bi1);
John Lo2b81eb82017-01-30 13:12:10 -0500513 if (is_ip4)
514 {
515 ip40 = vlib_buffer_get_current (b0);
516 ip41 = vlib_buffer_get_current (b1);
517 }
518 else
519 {
520 ip60 = vlib_buffer_get_current (b0);
521 ip61 = vlib_buffer_get_current (b1);
522 }
John Lo37682e12016-11-30 12:51:39 -0500523
524 /* Setup packet for next IP feature */
Eyal Bari7d92c092018-07-24 15:15:37 +0300525 vnet_feature_next (&next0, b0);
526 vnet_feature_next (&next1, b1);
John Lo37682e12016-11-30 12:51:39 -0500527
John Lo2b81eb82017-01-30 13:12:10 -0500528 if (is_ip4)
529 {
530 /* Treat IP frag packets as "experimental" protocol for now
Eyal Bari7d92c092018-07-24 15:15:37 +0300531 until support of IP frag reassembly is implemented */
532 proto0 = ip4_is_fragment (ip40) ? 0xfe : ip40->protocol;
533 proto1 = ip4_is_fragment (ip41) ? 0xfe : ip41->protocol;
John Lo2b81eb82017-01-30 13:12:10 -0500534 }
535 else
536 {
537 proto0 = ip60->protocol;
538 proto1 = ip61->protocol;
539 }
John Lo37682e12016-11-30 12:51:39 -0500540
541 /* Process packet 0 */
542 if (proto0 != IP_PROTOCOL_UDP)
Eyal Bari7d92c092018-07-24 15:15:37 +0300543 goto exit0; /* not UDP packet */
John Lo37682e12016-11-30 12:51:39 -0500544
John Lo2b81eb82017-01-30 13:12:10 -0500545 if (is_ip4)
546 udp0 = ip4_next_header (ip40);
547 else
548 udp0 = ip6_next_header (ip60);
549
John Lo37682e12016-11-30 12:51:39 -0500550 if (udp0->dst_port != clib_host_to_net_u16 (UDP_DST_PORT_vxlan))
Eyal Bari7d92c092018-07-24 15:15:37 +0300551 goto exit0; /* not VXLAN packet */
John Lo37682e12016-11-30 12:51:39 -0500552
Eyal Bari7d92c092018-07-24 15:15:37 +0300553 /* Validate DIP against VTEPs */
Eyal Bari0f4b1842018-04-12 12:39:51 +0300554 if (is_ip4)
John Lo37682e12016-11-30 12:51:39 -0500555 {
Nick Zavaritsky27518c22020-02-27 15:54:58 +0000556 if (!vtep4_check (&vxm->vtep_table, b0, ip40, &last_vtep4))
557 goto exit0; /* no local VTEP for VXLAN packet */
John Lo37682e12016-11-30 12:51:39 -0500558 }
John Lo2b81eb82017-01-30 13:12:10 -0500559 else
560 {
Nick Zavaritsky27518c22020-02-27 15:54:58 +0000561 if (!vtep6_check (&vxm->vtep_table, b0, ip60, &last_vtep6))
562 goto exit0; /* no local VTEP for VXLAN packet */
John Lo2b81eb82017-01-30 13:12:10 -0500563 }
John Lo37682e12016-11-30 12:51:39 -0500564
565 flags0 = b0->flags;
Damjan Marion213b5aa2017-07-13 21:19:27 +0200566 good_udp0 = (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
John Lo37682e12016-11-30 12:51:39 -0500567
568 /* Don't verify UDP checksum for packets with explicit zero checksum. */
569 good_udp0 |= udp0->checksum == 0;
570
571 /* Verify UDP length */
John Lo2b81eb82017-01-30 13:12:10 -0500572 if (is_ip4)
573 ip_len0 = clib_net_to_host_u16 (ip40->length);
574 else
575 ip_len0 = clib_net_to_host_u16 (ip60->payload_length);
John Lo37682e12016-11-30 12:51:39 -0500576 udp_len0 = clib_net_to_host_u16 (udp0->length);
John Lo37682e12016-11-30 12:51:39 -0500577 len_diff0 = ip_len0 - udp_len0;
578
579 /* Verify UDP checksum */
580 if (PREDICT_FALSE (!good_udp0))
581 {
Damjan Marion213b5aa2017-07-13 21:19:27 +0200582 if ((flags0 & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0)
Eyal Bari7d92c092018-07-24 15:15:37 +0300583 {
John Lo2b81eb82017-01-30 13:12:10 -0500584 if (is_ip4)
585 flags0 = ip4_tcp_udp_validate_checksum (vm, b0);
586 else
587 flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, b0);
588 good_udp0 =
Damjan Marion213b5aa2017-07-13 21:19:27 +0200589 (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
Eyal Bari7d92c092018-07-24 15:15:37 +0300590 }
John Lo37682e12016-11-30 12:51:39 -0500591 }
592
John Lo2b81eb82017-01-30 13:12:10 -0500593 if (is_ip4)
594 {
595 error0 = good_udp0 ? 0 : IP4_ERROR_UDP_CHECKSUM;
596 error0 = (len_diff0 >= 0) ? error0 : IP4_ERROR_UDP_LENGTH;
597 }
598 else
599 {
600 error0 = good_udp0 ? 0 : IP6_ERROR_UDP_CHECKSUM;
601 error0 = (len_diff0 >= 0) ? error0 : IP6_ERROR_UDP_LENGTH;
602 }
John Lo37682e12016-11-30 12:51:39 -0500603
Eyal Bari0f4b1842018-04-12 12:39:51 +0300604 next0 = error0 ?
John Lo37682e12016-11-30 12:51:39 -0500605 IP_VXLAN_BYPASS_NEXT_DROP : IP_VXLAN_BYPASS_NEXT_VXLAN;
606 b0->error = error0 ? error_node->errors[error0] : 0;
607
John Lo2b81eb82017-01-30 13:12:10 -0500608 /* vxlan-input node expect current at VXLAN header */
609 if (is_ip4)
Eyal Bari7d92c092018-07-24 15:15:37 +0300610 vlib_buffer_advance (b0,
611 sizeof (ip4_header_t) +
612 sizeof (udp_header_t));
John Lo2b81eb82017-01-30 13:12:10 -0500613 else
Eyal Bari7d92c092018-07-24 15:15:37 +0300614 vlib_buffer_advance (b0,
615 sizeof (ip6_header_t) +
616 sizeof (udp_header_t));
John Lo2b81eb82017-01-30 13:12:10 -0500617
John Lo37682e12016-11-30 12:51:39 -0500618 exit0:
619 /* Process packet 1 */
620 if (proto1 != IP_PROTOCOL_UDP)
Eyal Bari7d92c092018-07-24 15:15:37 +0300621 goto exit1; /* not UDP packet */
John Lo37682e12016-11-30 12:51:39 -0500622
John Lo2b81eb82017-01-30 13:12:10 -0500623 if (is_ip4)
624 udp1 = ip4_next_header (ip41);
625 else
626 udp1 = ip6_next_header (ip61);
627
John Lo37682e12016-11-30 12:51:39 -0500628 if (udp1->dst_port != clib_host_to_net_u16 (UDP_DST_PORT_vxlan))
Eyal Bari7d92c092018-07-24 15:15:37 +0300629 goto exit1; /* not VXLAN packet */
John Lo37682e12016-11-30 12:51:39 -0500630
Eyal Bari7d92c092018-07-24 15:15:37 +0300631 /* Validate DIP against VTEPs */
Eyal Bari0f4b1842018-04-12 12:39:51 +0300632 if (is_ip4)
John Lo37682e12016-11-30 12:51:39 -0500633 {
Nick Zavaritsky27518c22020-02-27 15:54:58 +0000634 if (!vtep4_check (&vxm->vtep_table, b1, ip41, &last_vtep4))
635 goto exit1; /* no local VTEP for VXLAN packet */
John Lo37682e12016-11-30 12:51:39 -0500636 }
John Lo2b81eb82017-01-30 13:12:10 -0500637 else
638 {
Nick Zavaritsky27518c22020-02-27 15:54:58 +0000639 if (!vtep6_check (&vxm->vtep_table, b1, ip61, &last_vtep6))
640 goto exit1; /* no local VTEP for VXLAN packet */
John Lo2b81eb82017-01-30 13:12:10 -0500641 }
John Lo37682e12016-11-30 12:51:39 -0500642
643 flags1 = b1->flags;
Damjan Marion213b5aa2017-07-13 21:19:27 +0200644 good_udp1 = (flags1 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
John Lo37682e12016-11-30 12:51:39 -0500645
646 /* Don't verify UDP checksum for packets with explicit zero checksum. */
647 good_udp1 |= udp1->checksum == 0;
648
649 /* Verify UDP length */
John Lo2b81eb82017-01-30 13:12:10 -0500650 if (is_ip4)
651 ip_len1 = clib_net_to_host_u16 (ip41->length);
652 else
653 ip_len1 = clib_net_to_host_u16 (ip61->payload_length);
John Lo37682e12016-11-30 12:51:39 -0500654 udp_len1 = clib_net_to_host_u16 (udp1->length);
John Lo37682e12016-11-30 12:51:39 -0500655 len_diff1 = ip_len1 - udp_len1;
656
657 /* Verify UDP checksum */
658 if (PREDICT_FALSE (!good_udp1))
659 {
Damjan Marion213b5aa2017-07-13 21:19:27 +0200660 if ((flags1 & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0)
Eyal Bari7d92c092018-07-24 15:15:37 +0300661 {
John Lo2b81eb82017-01-30 13:12:10 -0500662 if (is_ip4)
663 flags1 = ip4_tcp_udp_validate_checksum (vm, b1);
664 else
665 flags1 = ip6_tcp_udp_icmp_validate_checksum (vm, b1);
666 good_udp1 =
Damjan Marion213b5aa2017-07-13 21:19:27 +0200667 (flags1 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
Eyal Bari7d92c092018-07-24 15:15:37 +0300668 }
John Lo37682e12016-11-30 12:51:39 -0500669 }
670
John Lo2b81eb82017-01-30 13:12:10 -0500671 if (is_ip4)
672 {
673 error1 = good_udp1 ? 0 : IP4_ERROR_UDP_CHECKSUM;
674 error1 = (len_diff1 >= 0) ? error1 : IP4_ERROR_UDP_LENGTH;
675 }
676 else
677 {
Eyal Baria93ea422017-02-01 13:36:15 +0200678 error1 = good_udp1 ? 0 : IP6_ERROR_UDP_CHECKSUM;
679 error1 = (len_diff1 >= 0) ? error1 : IP6_ERROR_UDP_LENGTH;
John Lo2b81eb82017-01-30 13:12:10 -0500680 }
John Lo37682e12016-11-30 12:51:39 -0500681
Eyal Bari0f4b1842018-04-12 12:39:51 +0300682 next1 = error1 ?
John Lo37682e12016-11-30 12:51:39 -0500683 IP_VXLAN_BYPASS_NEXT_DROP : IP_VXLAN_BYPASS_NEXT_VXLAN;
684 b1->error = error1 ? error_node->errors[error1] : 0;
Eyal Bari0f4b1842018-04-12 12:39:51 +0300685
John Lo2b81eb82017-01-30 13:12:10 -0500686 /* vxlan-input node expect current at VXLAN header */
687 if (is_ip4)
Eyal Bari7d92c092018-07-24 15:15:37 +0300688 vlib_buffer_advance (b1,
689 sizeof (ip4_header_t) +
690 sizeof (udp_header_t));
John Lo2b81eb82017-01-30 13:12:10 -0500691 else
Eyal Bari7d92c092018-07-24 15:15:37 +0300692 vlib_buffer_advance (b1,
693 sizeof (ip6_header_t) +
694 sizeof (udp_header_t));
John Lo2b81eb82017-01-30 13:12:10 -0500695
John Lo37682e12016-11-30 12:51:39 -0500696 exit1:
697 vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
698 to_next, n_left_to_next,
699 bi0, bi1, next0, next1);
700 }
701
702 while (n_left_from > 0 && n_left_to_next > 0)
703 {
Eyal Bari7d92c092018-07-24 15:15:37 +0300704 vlib_buffer_t *b0;
705 ip4_header_t *ip40;
706 ip6_header_t *ip60;
707 udp_header_t *udp0;
708 u32 bi0, ip_len0, udp_len0, flags0, next0;
John Lo37682e12016-11-30 12:51:39 -0500709 i32 len_diff0;
710 u8 error0, good_udp0, proto0;
711
712 bi0 = to_next[0] = from[0];
713 from += 1;
714 n_left_from -= 1;
715 to_next += 1;
716 n_left_to_next -= 1;
717
718 b0 = vlib_get_buffer (vm, bi0);
John Lo2b81eb82017-01-30 13:12:10 -0500719 if (is_ip4)
720 ip40 = vlib_buffer_get_current (b0);
721 else
722 ip60 = vlib_buffer_get_current (b0);
John Lo37682e12016-11-30 12:51:39 -0500723
724 /* Setup packet for next IP feature */
Eyal Bari7d92c092018-07-24 15:15:37 +0300725 vnet_feature_next (&next0, b0);
John Lo37682e12016-11-30 12:51:39 -0500726
John Lo2b81eb82017-01-30 13:12:10 -0500727 if (is_ip4)
728 /* Treat IP4 frag packets as "experimental" protocol for now
729 until support of IP frag reassembly is implemented */
Eyal Bari7d92c092018-07-24 15:15:37 +0300730 proto0 = ip4_is_fragment (ip40) ? 0xfe : ip40->protocol;
John Lo2b81eb82017-01-30 13:12:10 -0500731 else
732 proto0 = ip60->protocol;
John Lo37682e12016-11-30 12:51:39 -0500733
734 if (proto0 != IP_PROTOCOL_UDP)
Eyal Bari7d92c092018-07-24 15:15:37 +0300735 goto exit; /* not UDP packet */
John Lo37682e12016-11-30 12:51:39 -0500736
John Lo2b81eb82017-01-30 13:12:10 -0500737 if (is_ip4)
738 udp0 = ip4_next_header (ip40);
739 else
740 udp0 = ip6_next_header (ip60);
741
John Lo37682e12016-11-30 12:51:39 -0500742 if (udp0->dst_port != clib_host_to_net_u16 (UDP_DST_PORT_vxlan))
Eyal Bari7d92c092018-07-24 15:15:37 +0300743 goto exit; /* not VXLAN packet */
John Lo37682e12016-11-30 12:51:39 -0500744
Eyal Bari7d92c092018-07-24 15:15:37 +0300745 /* Validate DIP against VTEPs */
Eyal Bari0f4b1842018-04-12 12:39:51 +0300746 if (is_ip4)
John Lo37682e12016-11-30 12:51:39 -0500747 {
Nick Zavaritsky27518c22020-02-27 15:54:58 +0000748 if (!vtep4_check (&vxm->vtep_table, b0, ip40, &last_vtep4))
749 goto exit; /* no local VTEP for VXLAN packet */
John Lo37682e12016-11-30 12:51:39 -0500750 }
John Lo2b81eb82017-01-30 13:12:10 -0500751 else
752 {
Nick Zavaritsky27518c22020-02-27 15:54:58 +0000753 if (!vtep6_check (&vxm->vtep_table, b0, ip60, &last_vtep6))
754 goto exit; /* no local VTEP for VXLAN packet */
John Lo2b81eb82017-01-30 13:12:10 -0500755 }
John Lo37682e12016-11-30 12:51:39 -0500756
757 flags0 = b0->flags;
Damjan Marion213b5aa2017-07-13 21:19:27 +0200758 good_udp0 = (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
John Lo37682e12016-11-30 12:51:39 -0500759
760 /* Don't verify UDP checksum for packets with explicit zero checksum. */
761 good_udp0 |= udp0->checksum == 0;
762
763 /* Verify UDP length */
John Lo2b81eb82017-01-30 13:12:10 -0500764 if (is_ip4)
765 ip_len0 = clib_net_to_host_u16 (ip40->length);
766 else
767 ip_len0 = clib_net_to_host_u16 (ip60->payload_length);
John Lo37682e12016-11-30 12:51:39 -0500768 udp_len0 = clib_net_to_host_u16 (udp0->length);
John Lo37682e12016-11-30 12:51:39 -0500769 len_diff0 = ip_len0 - udp_len0;
770
771 /* Verify UDP checksum */
772 if (PREDICT_FALSE (!good_udp0))
773 {
Damjan Marion213b5aa2017-07-13 21:19:27 +0200774 if ((flags0 & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0)
Eyal Bari7d92c092018-07-24 15:15:37 +0300775 {
John Lo2b81eb82017-01-30 13:12:10 -0500776 if (is_ip4)
777 flags0 = ip4_tcp_udp_validate_checksum (vm, b0);
778 else
779 flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, b0);
780 good_udp0 =
Damjan Marion213b5aa2017-07-13 21:19:27 +0200781 (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
Eyal Bari7d92c092018-07-24 15:15:37 +0300782 }
John Lo37682e12016-11-30 12:51:39 -0500783 }
784
John Lo2b81eb82017-01-30 13:12:10 -0500785 if (is_ip4)
786 {
787 error0 = good_udp0 ? 0 : IP4_ERROR_UDP_CHECKSUM;
788 error0 = (len_diff0 >= 0) ? error0 : IP4_ERROR_UDP_LENGTH;
789 }
790 else
791 {
792 error0 = good_udp0 ? 0 : IP6_ERROR_UDP_CHECKSUM;
793 error0 = (len_diff0 >= 0) ? error0 : IP6_ERROR_UDP_LENGTH;
794 }
John Lo37682e12016-11-30 12:51:39 -0500795
Eyal Bari0f4b1842018-04-12 12:39:51 +0300796 next0 = error0 ?
John Lo37682e12016-11-30 12:51:39 -0500797 IP_VXLAN_BYPASS_NEXT_DROP : IP_VXLAN_BYPASS_NEXT_VXLAN;
798 b0->error = error0 ? error_node->errors[error0] : 0;
799
John Lo2b81eb82017-01-30 13:12:10 -0500800 /* vxlan-input node expect current at VXLAN header */
801 if (is_ip4)
Eyal Bari7d92c092018-07-24 15:15:37 +0300802 vlib_buffer_advance (b0,
803 sizeof (ip4_header_t) +
804 sizeof (udp_header_t));
John Lo2b81eb82017-01-30 13:12:10 -0500805 else
Eyal Bari7d92c092018-07-24 15:15:37 +0300806 vlib_buffer_advance (b0,
807 sizeof (ip6_header_t) +
808 sizeof (udp_header_t));
John Lo2b81eb82017-01-30 13:12:10 -0500809
John Lo37682e12016-11-30 12:51:39 -0500810 exit:
811 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
812 to_next, n_left_to_next,
813 bi0, next0);
814 }
815
816 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
817 }
818
819 return frame->n_vectors;
820}
821
Eyal Baria5679e82018-08-26 15:20:07 +0300822VLIB_NODE_FN (ip4_vxlan_bypass_node) (vlib_main_t * vm,
823 vlib_node_runtime_t * node,
824 vlib_frame_t * frame)
John Lo37682e12016-11-30 12:51:39 -0500825{
826 return ip_vxlan_bypass_inline (vm, node, frame, /* is_ip4 */ 1);
827}
828
Eyal Bari7d92c092018-07-24 15:15:37 +0300829/* *INDENT-OFF* */
830VLIB_REGISTER_NODE (ip4_vxlan_bypass_node) =
831{
John Lo37682e12016-11-30 12:51:39 -0500832 .name = "ip4-vxlan-bypass",
833 .vector_size = sizeof (u32),
John Lo37682e12016-11-30 12:51:39 -0500834 .n_next_nodes = IP_VXLAN_BYPASS_N_NEXT,
835 .next_nodes = {
Eyal Bari7d92c092018-07-24 15:15:37 +0300836 [IP_VXLAN_BYPASS_NEXT_DROP] = "error-drop",
837 [IP_VXLAN_BYPASS_NEXT_VXLAN] = "vxlan4-input",
John Lo37682e12016-11-30 12:51:39 -0500838 },
John Lo37682e12016-11-30 12:51:39 -0500839 .format_buffer = format_ip4_header,
840 .format_trace = format_ip4_forward_next_trace,
841};
842
Eyal Bari7d92c092018-07-24 15:15:37 +0300843/* *INDENT-ON* */
John Lo37682e12016-11-30 12:51:39 -0500844
John Lo37682e12016-11-30 12:51:39 -0500845/* Dummy init function to get us linked in. */
Eyal Baria5679e82018-08-26 15:20:07 +0300846static clib_error_t *
Eyal Bari7d92c092018-07-24 15:15:37 +0300847ip4_vxlan_bypass_init (vlib_main_t * vm)
848{
849 return 0;
850}
John Lo37682e12016-11-30 12:51:39 -0500851
852VLIB_INIT_FUNCTION (ip4_vxlan_bypass_init);
John Lo2b81eb82017-01-30 13:12:10 -0500853
Eyal Baria5679e82018-08-26 15:20:07 +0300854VLIB_NODE_FN (ip6_vxlan_bypass_node) (vlib_main_t * vm,
855 vlib_node_runtime_t * node,
856 vlib_frame_t * frame)
John Lo2b81eb82017-01-30 13:12:10 -0500857{
858 return ip_vxlan_bypass_inline (vm, node, frame, /* is_ip4 */ 0);
859}
860
Eyal Bari7d92c092018-07-24 15:15:37 +0300861/* *INDENT-OFF* */
862VLIB_REGISTER_NODE (ip6_vxlan_bypass_node) =
863{
John Lo2b81eb82017-01-30 13:12:10 -0500864 .name = "ip6-vxlan-bypass",
865 .vector_size = sizeof (u32),
John Lo2b81eb82017-01-30 13:12:10 -0500866 .n_next_nodes = IP_VXLAN_BYPASS_N_NEXT,
867 .next_nodes = {
868 [IP_VXLAN_BYPASS_NEXT_DROP] = "error-drop",
869 [IP_VXLAN_BYPASS_NEXT_VXLAN] = "vxlan6-input",
870 },
John Lo2b81eb82017-01-30 13:12:10 -0500871 .format_buffer = format_ip6_header,
872 .format_trace = format_ip6_forward_next_trace,
873};
874
Eyal Bari7d92c092018-07-24 15:15:37 +0300875/* *INDENT-ON* */
John Lo2b81eb82017-01-30 13:12:10 -0500876
877/* Dummy init function to get us linked in. */
Eyal Baria5679e82018-08-26 15:20:07 +0300878static clib_error_t *
Eyal Bari7d92c092018-07-24 15:15:37 +0300879ip6_vxlan_bypass_init (vlib_main_t * vm)
880{
881 return 0;
882}
John Lo2b81eb82017-01-30 13:12:10 -0500883
884VLIB_INIT_FUNCTION (ip6_vxlan_bypass_init);
eyal bariaf86a482018-04-17 11:20:27 +0300885
886#define foreach_vxlan_flow_input_next \
887_(DROP, "error-drop") \
888_(L2_INPUT, "l2-input")
889
890typedef enum
891{
892#define _(s,n) VXLAN_FLOW_NEXT_##s,
893 foreach_vxlan_flow_input_next
894#undef _
Eyal Bari7d92c092018-07-24 15:15:37 +0300895 VXLAN_FLOW_N_NEXT,
eyal bariaf86a482018-04-17 11:20:27 +0300896} vxlan_flow_input_next_t;
897
898#define foreach_vxlan_flow_error \
899 _(NONE, "no error") \
900 _(IP_CHECKSUM_ERROR, "Rx ip checksum errors") \
901 _(IP_HEADER_ERROR, "Rx ip header errors") \
902 _(UDP_CHECKSUM_ERROR, "Rx udp checksum errors") \
903 _(UDP_LENGTH_ERROR, "Rx udp length errors")
904
905typedef enum
906{
907#define _(f,s) VXLAN_FLOW_ERROR_##f,
908 foreach_vxlan_flow_error
909#undef _
910 VXLAN_FLOW_N_ERROR,
911} vxlan_flow_error_t;
912
913static char *vxlan_flow_error_strings[] = {
914#define _(n,s) s,
915 foreach_vxlan_flow_error
916#undef _
917};
918
919
920static_always_inline u8
Eyal Bari7d92c092018-07-24 15:15:37 +0300921vxlan_validate_udp_csum (vlib_main_t * vm, vlib_buffer_t * b)
eyal bariaf86a482018-04-17 11:20:27 +0300922{
923 u32 flags = b->flags;
Eyal Bari7d92c092018-07-24 15:15:37 +0300924 enum
925 { offset =
926 sizeof (ip4_header_t) + sizeof (udp_header_t) + sizeof (vxlan_header_t),
927 };
eyal bariaf86a482018-04-17 11:20:27 +0300928
929 /* Verify UDP checksum */
930 if ((flags & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0)
Eyal Bari7d92c092018-07-24 15:15:37 +0300931 {
932 vlib_buffer_advance (b, -offset);
933 flags = ip4_tcp_udp_validate_checksum (vm, b);
934 vlib_buffer_advance (b, offset);
935 }
eyal bariaf86a482018-04-17 11:20:27 +0300936
937 return (flags & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
938}
939
940static_always_inline u8
Eyal Bari7d92c092018-07-24 15:15:37 +0300941vxlan_check_udp_csum (vlib_main_t * vm, vlib_buffer_t * b)
eyal bariaf86a482018-04-17 11:20:27 +0300942{
Eyal Bari7d92c092018-07-24 15:15:37 +0300943 ip4_vxlan_header_t *hdr = vlib_buffer_get_current (b) - sizeof *hdr;
944 udp_header_t *udp = &hdr->udp;
eyal bariaf86a482018-04-17 11:20:27 +0300945 /* Don't verify UDP checksum for packets with explicit zero checksum. */
946 u8 good_csum = (b->flags & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0 ||
947 udp->checksum == 0;
948
949 return !good_csum;
950}
951
952static_always_inline u8
Eyal Bari7d92c092018-07-24 15:15:37 +0300953vxlan_check_ip (vlib_buffer_t * b, u16 payload_len)
eyal bariaf86a482018-04-17 11:20:27 +0300954{
Eyal Bari7d92c092018-07-24 15:15:37 +0300955 ip4_vxlan_header_t *hdr = vlib_buffer_get_current (b) - sizeof *hdr;
eyal bariaf86a482018-04-17 11:20:27 +0300956 u16 ip_len = clib_net_to_host_u16 (hdr->ip4.length);
957 u16 expected = payload_len + sizeof *hdr;
Eyal Bari7d92c092018-07-24 15:15:37 +0300958 return ip_len > expected || hdr->ip4.ttl == 0
959 || hdr->ip4.ip_version_and_header_length != 0x45;
eyal bariaf86a482018-04-17 11:20:27 +0300960}
961
962static_always_inline u8
Eyal Bari7d92c092018-07-24 15:15:37 +0300963vxlan_check_ip_udp_len (vlib_buffer_t * b)
eyal bariaf86a482018-04-17 11:20:27 +0300964{
Eyal Bari7d92c092018-07-24 15:15:37 +0300965 ip4_vxlan_header_t *hdr = vlib_buffer_get_current (b) - sizeof *hdr;
eyal bariaf86a482018-04-17 11:20:27 +0300966 u16 ip_len = clib_net_to_host_u16 (hdr->ip4.length);
967 u16 udp_len = clib_net_to_host_u16 (hdr->udp.length);
968 return udp_len > ip_len;
969}
970
971static_always_inline u8
972vxlan_err_code (u8 ip_err0, u8 udp_err0, u8 csum_err0)
973{
974 u8 error0 = VXLAN_FLOW_ERROR_NONE;
975 if (ip_err0)
Eyal Bari7d92c092018-07-24 15:15:37 +0300976 error0 = VXLAN_FLOW_ERROR_IP_HEADER_ERROR;
eyal bariaf86a482018-04-17 11:20:27 +0300977 if (udp_err0)
Eyal Bari7d92c092018-07-24 15:15:37 +0300978 error0 = VXLAN_FLOW_ERROR_UDP_LENGTH_ERROR;
eyal bariaf86a482018-04-17 11:20:27 +0300979 if (csum_err0)
Eyal Bari7d92c092018-07-24 15:15:37 +0300980 error0 = VXLAN_FLOW_ERROR_UDP_CHECKSUM_ERROR;
eyal bariaf86a482018-04-17 11:20:27 +0300981 return error0;
982}
983
Eyal Bari93a6f252018-06-14 08:57:39 +0300984VLIB_NODE_FN (vxlan4_flow_input_node) (vlib_main_t * vm,
Eyal Bari7d92c092018-07-24 15:15:37 +0300985 vlib_node_runtime_t * node,
986 vlib_frame_t * f)
eyal bariaf86a482018-04-17 11:20:27 +0300987{
Eyal Bari7d92c092018-07-24 15:15:37 +0300988 enum
989 { payload_offset = sizeof (ip4_vxlan_header_t) };
eyal bariaf86a482018-04-17 11:20:27 +0300990
Eyal Bari7d92c092018-07-24 15:15:37 +0300991 vxlan_main_t *vxm = &vxlan_main;
992 vnet_interface_main_t *im = &vnet_main.interface_main;
993 vlib_combined_counter_main_t *rx_counter[VXLAN_FLOW_N_NEXT] = {
994 [VXLAN_FLOW_NEXT_DROP] =
995 im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_DROP,
996 [VXLAN_FLOW_NEXT_L2_INPUT] =
997 im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_RX,
eyal bariaf86a482018-04-17 11:20:27 +0300998 };
Eyal Bari7d92c092018-07-24 15:15:37 +0300999 u32 thread_index = vlib_get_thread_index ();
eyal bariaf86a482018-04-17 11:20:27 +03001000
Eyal Bari7d92c092018-07-24 15:15:37 +03001001 u32 *from = vlib_frame_vector_args (f);
eyal bariaf86a482018-04-17 11:20:27 +03001002 u32 n_left_from = f->n_vectors;
1003 u32 next_index = VXLAN_FLOW_NEXT_L2_INPUT;
1004
1005 while (n_left_from > 0)
eyal bariaf86a482018-04-17 11:20:27 +03001006 {
Eyal Bari7d92c092018-07-24 15:15:37 +03001007 u32 n_left_to_next, *to_next;
eyal bariaf86a482018-04-17 11:20:27 +03001008
Eyal Bari7d92c092018-07-24 15:15:37 +03001009 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
eyal bariaf86a482018-04-17 11:20:27 +03001010
Eyal Bari7d92c092018-07-24 15:15:37 +03001011 while (n_left_from > 3 && n_left_to_next > 3)
eyal bariaf86a482018-04-17 11:20:27 +03001012 {
Eyal Bari7d92c092018-07-24 15:15:37 +03001013 u32 bi0 = to_next[0] = from[0];
1014 u32 bi1 = to_next[1] = from[1];
1015 u32 bi2 = to_next[2] = from[2];
1016 u32 bi3 = to_next[3] = from[3];
1017 from += 4;
1018 n_left_from -= 4;
1019 to_next += 4;
1020 n_left_to_next -= 4;
eyal bariaf86a482018-04-17 11:20:27 +03001021
Eyal Bari7d92c092018-07-24 15:15:37 +03001022 vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
1023 vlib_buffer_t *b1 = vlib_get_buffer (vm, bi1);
1024 vlib_buffer_t *b2 = vlib_get_buffer (vm, bi2);
1025 vlib_buffer_t *b3 = vlib_get_buffer (vm, bi3);
1026
1027 vlib_buffer_advance (b0, payload_offset);
1028 vlib_buffer_advance (b1, payload_offset);
1029 vlib_buffer_advance (b2, payload_offset);
1030 vlib_buffer_advance (b3, payload_offset);
1031
1032 u16 len0 = vlib_buffer_length_in_chain (vm, b0);
1033 u16 len1 = vlib_buffer_length_in_chain (vm, b1);
1034 u16 len2 = vlib_buffer_length_in_chain (vm, b2);
1035 u16 len3 = vlib_buffer_length_in_chain (vm, b3);
1036
1037 u32 next0 = VXLAN_FLOW_NEXT_L2_INPUT, next1 =
1038 VXLAN_FLOW_NEXT_L2_INPUT, next2 =
1039 VXLAN_FLOW_NEXT_L2_INPUT, next3 = VXLAN_FLOW_NEXT_L2_INPUT;
1040
1041 u8 ip_err0 = vxlan_check_ip (b0, len0);
1042 u8 ip_err1 = vxlan_check_ip (b1, len1);
1043 u8 ip_err2 = vxlan_check_ip (b2, len2);
1044 u8 ip_err3 = vxlan_check_ip (b3, len3);
1045 u8 ip_err = ip_err0 | ip_err1 | ip_err2 | ip_err3;
1046
1047 u8 udp_err0 = vxlan_check_ip_udp_len (b0);
1048 u8 udp_err1 = vxlan_check_ip_udp_len (b1);
1049 u8 udp_err2 = vxlan_check_ip_udp_len (b2);
1050 u8 udp_err3 = vxlan_check_ip_udp_len (b3);
1051 u8 udp_err = udp_err0 | udp_err1 | udp_err2 | udp_err3;
1052
1053 u8 csum_err0 = vxlan_check_udp_csum (vm, b0);
1054 u8 csum_err1 = vxlan_check_udp_csum (vm, b1);
1055 u8 csum_err2 = vxlan_check_udp_csum (vm, b2);
1056 u8 csum_err3 = vxlan_check_udp_csum (vm, b3);
1057 u8 csum_err = csum_err0 | csum_err1 | csum_err2 | csum_err3;
1058
1059 if (PREDICT_FALSE (csum_err))
1060 {
1061 if (csum_err0)
1062 csum_err0 = !vxlan_validate_udp_csum (vm, b0);
1063 if (csum_err1)
1064 csum_err1 = !vxlan_validate_udp_csum (vm, b1);
1065 if (csum_err2)
1066 csum_err2 = !vxlan_validate_udp_csum (vm, b2);
1067 if (csum_err3)
1068 csum_err3 = !vxlan_validate_udp_csum (vm, b3);
1069 csum_err = csum_err0 | csum_err1 | csum_err2 | csum_err3;
1070 }
1071
1072 if (PREDICT_FALSE (ip_err || udp_err || csum_err))
1073 {
1074 if (ip_err0 || udp_err0 || csum_err0)
1075 {
1076 next0 = VXLAN_FLOW_NEXT_DROP;
1077 u8 error0 = vxlan_err_code (ip_err0, udp_err0, csum_err0);
1078 b0->error = node->errors[error0];
1079 }
1080 if (ip_err1 || udp_err1 || csum_err1)
1081 {
1082 next1 = VXLAN_FLOW_NEXT_DROP;
1083 u8 error1 = vxlan_err_code (ip_err1, udp_err1, csum_err1);
1084 b1->error = node->errors[error1];
1085 }
1086 if (ip_err2 || udp_err2 || csum_err2)
1087 {
1088 next2 = VXLAN_FLOW_NEXT_DROP;
1089 u8 error2 = vxlan_err_code (ip_err2, udp_err2, csum_err2);
1090 b2->error = node->errors[error2];
1091 }
1092 if (ip_err3 || udp_err3 || csum_err3)
1093 {
1094 next3 = VXLAN_FLOW_NEXT_DROP;
1095 u8 error3 = vxlan_err_code (ip_err3, udp_err3, csum_err3);
1096 b3->error = node->errors[error3];
1097 }
1098 }
1099
1100 vnet_update_l2_len (b0);
1101 vnet_update_l2_len (b1);
1102 vnet_update_l2_len (b2);
1103 vnet_update_l2_len (b3);
1104
1105 ASSERT (b0->flow_id != 0);
1106 ASSERT (b1->flow_id != 0);
1107 ASSERT (b2->flow_id != 0);
1108 ASSERT (b3->flow_id != 0);
1109
1110 u32 t_index0 = b0->flow_id - vxm->flow_id_start;
1111 u32 t_index1 = b1->flow_id - vxm->flow_id_start;
1112 u32 t_index2 = b2->flow_id - vxm->flow_id_start;
1113 u32 t_index3 = b3->flow_id - vxm->flow_id_start;
1114
1115 vxlan_tunnel_t *t0 = &vxm->tunnels[t_index0];
1116 vxlan_tunnel_t *t1 = &vxm->tunnels[t_index1];
1117 vxlan_tunnel_t *t2 = &vxm->tunnels[t_index2];
1118 vxlan_tunnel_t *t3 = &vxm->tunnels[t_index3];
1119
1120 /* flow id consumed */
1121 b0->flow_id = 0;
1122 b1->flow_id = 0;
1123 b2->flow_id = 0;
1124 b3->flow_id = 0;
1125
1126 u32 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX] =
1127 t0->sw_if_index;
1128 u32 sw_if_index1 = vnet_buffer (b1)->sw_if_index[VLIB_RX] =
1129 t1->sw_if_index;
1130 u32 sw_if_index2 = vnet_buffer (b2)->sw_if_index[VLIB_RX] =
1131 t2->sw_if_index;
1132 u32 sw_if_index3 = vnet_buffer (b3)->sw_if_index[VLIB_RX] =
1133 t3->sw_if_index;
1134
1135 vlib_increment_combined_counter (rx_counter[next0], thread_index,
1136 sw_if_index0, 1, len0);
1137 vlib_increment_combined_counter (rx_counter[next1], thread_index,
1138 sw_if_index1, 1, len1);
1139 vlib_increment_combined_counter (rx_counter[next2], thread_index,
1140 sw_if_index2, 1, len2);
1141 vlib_increment_combined_counter (rx_counter[next3], thread_index,
1142 sw_if_index3, 1, len3);
1143
1144 u32 flags = b0->flags | b1->flags | b2->flags | b3->flags;
1145
1146 if (PREDICT_FALSE (flags & VLIB_BUFFER_IS_TRACED))
1147 {
1148 if (b0->flags & VLIB_BUFFER_IS_TRACED)
1149 {
1150 vxlan_rx_trace_t *tr =
1151 vlib_add_trace (vm, node, b0, sizeof *tr);
1152 u8 error0 = vxlan_err_code (ip_err0, udp_err0, csum_err0);
1153 tr->next_index = next0;
1154 tr->error = error0;
1155 tr->tunnel_index = t_index0;
1156 tr->vni = t0->vni;
1157 }
1158 if (b1->flags & VLIB_BUFFER_IS_TRACED)
1159 {
1160 vxlan_rx_trace_t *tr =
1161 vlib_add_trace (vm, node, b1, sizeof *tr);
1162 u8 error1 = vxlan_err_code (ip_err1, udp_err1, csum_err1);
1163 tr->next_index = next1;
1164 tr->error = error1;
1165 tr->tunnel_index = t_index1;
1166 tr->vni = t1->vni;
1167 }
1168 if (b2->flags & VLIB_BUFFER_IS_TRACED)
1169 {
1170 vxlan_rx_trace_t *tr =
1171 vlib_add_trace (vm, node, b2, sizeof *tr);
1172 u8 error2 = vxlan_err_code (ip_err2, udp_err2, csum_err2);
1173 tr->next_index = next2;
1174 tr->error = error2;
1175 tr->tunnel_index = t_index2;
1176 tr->vni = t2->vni;
1177 }
1178 if (b3->flags & VLIB_BUFFER_IS_TRACED)
1179 {
1180 vxlan_rx_trace_t *tr =
1181 vlib_add_trace (vm, node, b3, sizeof *tr);
1182 u8 error3 = vxlan_err_code (ip_err3, udp_err3, csum_err3);
1183 tr->next_index = next3;
1184 tr->error = error3;
1185 tr->tunnel_index = t_index3;
1186 tr->vni = t3->vni;
1187 }
1188 }
1189 vlib_validate_buffer_enqueue_x4
1190 (vm, node, next_index, to_next, n_left_to_next,
1191 bi0, bi1, bi2, bi3, next0, next1, next2, next3);
1192 }
1193 while (n_left_from > 0 && n_left_to_next > 0)
1194 {
1195 u32 bi0 = to_next[0] = from[0];
1196 from++;
1197 n_left_from--;
1198 to_next++;
1199 n_left_to_next--;
1200
1201 vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
1202 vlib_buffer_advance (b0, payload_offset);
1203
1204 u16 len0 = vlib_buffer_length_in_chain (vm, b0);
1205 u32 next0 = VXLAN_FLOW_NEXT_L2_INPUT;
1206
1207 u8 ip_err0 = vxlan_check_ip (b0, len0);
1208 u8 udp_err0 = vxlan_check_ip_udp_len (b0);
1209 u8 csum_err0 = vxlan_check_udp_csum (vm, b0);
1210
1211 if (csum_err0)
1212 csum_err0 = !vxlan_validate_udp_csum (vm, b0);
1213 if (ip_err0 || udp_err0 || csum_err0)
1214 {
1215 next0 = VXLAN_FLOW_NEXT_DROP;
1216 u8 error0 = vxlan_err_code (ip_err0, udp_err0, csum_err0);
1217 b0->error = node->errors[error0];
1218 }
1219
1220 vnet_update_l2_len (b0);
1221
1222 ASSERT (b0->flow_id != 0);
1223 u32 t_index0 = b0->flow_id - vxm->flow_id_start;
1224 vxlan_tunnel_t *t0 = &vxm->tunnels[t_index0];
1225 b0->flow_id = 0;
1226
1227 u32 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX] =
1228 t0->sw_if_index;
1229 vlib_increment_combined_counter (rx_counter[next0], thread_index,
1230 sw_if_index0, 1, len0);
1231
1232 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1233 {
1234 vxlan_rx_trace_t *tr =
1235 vlib_add_trace (vm, node, b0, sizeof *tr);
1236 u8 error0 = vxlan_err_code (ip_err0, udp_err0, csum_err0);
1237 tr->next_index = next0;
1238 tr->error = error0;
1239 tr->tunnel_index = t_index0;
1240 tr->vni = t0->vni;
1241 }
1242 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
1243 to_next, n_left_to_next,
1244 bi0, next0);
1245 }
1246
1247 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1248 }
eyal bariaf86a482018-04-17 11:20:27 +03001249
1250 return f->n_vectors;
1251}
1252
1253/* *INDENT-OFF* */
1254#ifndef CLIB_MULTIARCH_VARIANT
1255VLIB_REGISTER_NODE (vxlan4_flow_input_node) = {
1256 .name = "vxlan-flow-input",
eyal bariaf86a482018-04-17 11:20:27 +03001257 .type = VLIB_NODE_TYPE_INTERNAL,
1258 .vector_size = sizeof (u32),
1259
1260 .format_trace = format_vxlan_rx_trace,
1261
1262 .n_errors = VXLAN_FLOW_N_ERROR,
1263 .error_strings = vxlan_flow_error_strings,
1264
1265 .n_next_nodes = VXLAN_FLOW_N_NEXT,
1266 .next_nodes = {
1267#define _(s,n) [VXLAN_FLOW_NEXT_##s] = n,
1268 foreach_vxlan_flow_input_next
1269#undef _
1270 },
1271};
1272#endif
1273/* *INDENT-ON* */
Eyal Bari7d92c092018-07-24 15:15:37 +03001274
1275/*
1276 * fd.io coding-style-patch-verification: ON
1277 *
1278 * Local Variables:
1279 * eval: (c-set-style "gnu")
1280 * End:
1281 */