blob: 2811215307f8a9229f3e3150a534a65787202dd8 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
2 * l2_output.c : layer 2 output 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/vnet.h>
20#include <vnet/pg/pg.h>
21#include <vnet/ethernet/ethernet.h>
22#include <vlib/cli.h>
23
24#include <vppinfra/error.h>
25#include <vppinfra/hash.h>
26#include <vnet/l2/feat_bitmap.h>
27#include <vnet/l2/l2_output.h>
28
29
Damjan Marion812b32d2018-05-28 21:26:47 +020030#ifndef CLIB_MARCH_VARIANT
Dave Barach97d8dc22016-08-15 15:31:15 -040031/* Feature graph node names */
32static char *l2output_feat_names[] = {
Ed Warnickecb9cada2015-12-08 15:45:58 -070033#define _(sym,name) name,
34 foreach_l2output_feat
35#undef _
36};
37
Dave Barach97d8dc22016-08-15 15:31:15 -040038char **
39l2output_get_feat_names (void)
40{
Ed Warnickecb9cada2015-12-08 15:45:58 -070041 return l2output_feat_names;
42}
43
Eyal Bari942402b2017-07-26 11:57:04 +030044u8 *
45format_l2_output_features (u8 * s, va_list * args)
46{
47 static char *display_names[] = {
48#define _(sym,name) #sym,
49 foreach_l2output_feat
50#undef _
51 };
52 u32 feature_bitmap = va_arg (*args, u32);
53
54 if (feature_bitmap == 0)
55 {
56 s = format (s, " none configured");
57 return s;
58 }
59
60 int i;
61 for (i = L2OUTPUT_N_FEAT - 1; i >= 0; i--)
62 if (feature_bitmap & (1 << i))
63 s = format (s, "%10s (%s)\n", display_names[i], l2output_feat_names[i]);
64 return s;
65}
66
Ed Warnickecb9cada2015-12-08 15:45:58 -070067l2output_main_t l2output_main;
Damjan Marionf3b27462018-05-15 19:51:38 +020068#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -070069
Dave Barach97d8dc22016-08-15 15:31:15 -040070typedef struct
71{
72 /* per-pkt trace data */
Ed Warnickecb9cada2015-12-08 15:45:58 -070073 u8 src[6];
74 u8 dst[6];
75 u32 sw_if_index;
Pavel Kotucek65e84572017-01-16 17:01:56 +010076 u8 raw[12]; /* raw data */
Ed Warnickecb9cada2015-12-08 15:45:58 -070077} l2output_trace_t;
78
79/* packet trace format function */
Dave Barach97d8dc22016-08-15 15:31:15 -040080static u8 *
81format_l2output_trace (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -070082{
83 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
84 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
Dave Barach97d8dc22016-08-15 15:31:15 -040085 l2output_trace_t *t = va_arg (*args, l2output_trace_t *);
86
Pavel Kotucek65e84572017-01-16 17:01:56 +010087 s = format (s, "l2-output: sw_if_index %d dst %U src %U data "
88 "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
Ed Warnickecb9cada2015-12-08 15:45:58 -070089 t->sw_if_index,
Dave Barach97d8dc22016-08-15 15:31:15 -040090 format_ethernet_address, t->dst,
Pavel Kotucek65e84572017-01-16 17:01:56 +010091 format_ethernet_address, t->src,
92 t->raw[0], t->raw[1], t->raw[2], t->raw[3], t->raw[4],
93 t->raw[5], t->raw[6], t->raw[7], t->raw[8], t->raw[9],
94 t->raw[10], t->raw[11]);
95
Ed Warnickecb9cada2015-12-08 15:45:58 -070096 return s;
97}
98
99
Dave Barach97d8dc22016-08-15 15:31:15 -0400100static char *l2output_error_strings[] = {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700101#define _(sym,string) string,
102 foreach_l2output_error
103#undef _
104};
105
Dave Barach97d8dc22016-08-15 15:31:15 -0400106/**
Chris Luke16bcf7d2016-09-01 14:31:46 -0400107 * Check for split horizon violations.
108 * Return 0 if split horizon check passes, otherwise return non-zero.
Dave Barach97d8dc22016-08-15 15:31:15 -0400109 * Packets should not be transmitted out an interface with the same
Chris Luke16bcf7d2016-09-01 14:31:46 -0400110 * split-horizon group as the input interface, except if the @c shg is 0
Dave Barach97d8dc22016-08-15 15:31:15 -0400111 * in which case the check always passes.
112 */
John Lobeb0b2e2017-07-22 00:21:36 -0400113static_always_inline void
Damjan Marionf3b27462018-05-15 19:51:38 +0200114split_horizon_violation (vlib_node_runtime_t * node, u8 shg,
115 vlib_buffer_t * b, u16 * next)
John Lobeb0b2e2017-07-22 00:21:36 -0400116{
Damjan Marionf3b27462018-05-15 19:51:38 +0200117 if (shg != vnet_buffer (b)->l2.shg)
118 return;
119 next[0] = L2OUTPUT_NEXT_DROP;
120 b->error = node->errors[L2OUTPUT_ERROR_SHG_DROP];
John Lobeb0b2e2017-07-22 00:21:36 -0400121}
122
Damjan Mariondc5252b2016-11-24 19:25:01 -0800123static_always_inline void
Damjan Marionf3b27462018-05-15 19:51:38 +0200124l2output_process_batch_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
125 l2_output_config_t * config,
126 vlib_buffer_t ** b, i16 * cdo, u16 * next,
127 u32 n_left, int l2_efp, int l2_vtr, int l2_pbb,
128 int shg_set, int update_feature_bitmap)
Damjan Mariondc5252b2016-11-24 19:25:01 -0800129{
Damjan Marionf3b27462018-05-15 19:51:38 +0200130 while (n_left >= 8)
Damjan Mariondc5252b2016-11-24 19:25:01 -0800131 {
Damjan Marionf3b27462018-05-15 19:51:38 +0200132 vlib_prefetch_buffer_header (b[4], LOAD);
133 vlib_prefetch_buffer_header (b[5], LOAD);
134 vlib_prefetch_buffer_header (b[6], LOAD);
135 vlib_prefetch_buffer_header (b[7], LOAD);
Damjan Mariondc5252b2016-11-24 19:25:01 -0800136
Damjan Marionf3b27462018-05-15 19:51:38 +0200137 /* prefetch eth headers only if we need to touch them */
138 if (l2_vtr || l2_pbb || shg_set)
139 {
140 CLIB_PREFETCH (b[4]->data + cdo[4], CLIB_CACHE_LINE_BYTES, LOAD);
141 CLIB_PREFETCH (b[5]->data + cdo[5], CLIB_CACHE_LINE_BYTES, LOAD);
142 CLIB_PREFETCH (b[6]->data + cdo[6], CLIB_CACHE_LINE_BYTES, LOAD);
143 CLIB_PREFETCH (b[7]->data + cdo[7], CLIB_CACHE_LINE_BYTES, LOAD);
144 }
145
146 if (update_feature_bitmap)
147 {
148 vnet_buffer (b[0])->l2.feature_bitmap = config->feature_bitmap;
149 vnet_buffer (b[1])->l2.feature_bitmap = config->feature_bitmap;
150 vnet_buffer (b[2])->l2.feature_bitmap = config->feature_bitmap;
151 vnet_buffer (b[3])->l2.feature_bitmap = config->feature_bitmap;
152 }
153
154 if (l2_vtr)
155 {
156 int i;
157 for (i = 0; i < 4; i++)
158 {
159 u32 failed1 = l2_efp &&
160 l2_efp_filter_process (b[i], &(config->input_vtr));
161 u32 failed2 = l2_vtr_process (b[i], &(config->output_vtr));
162 if (PREDICT_FALSE (failed1 | failed2))
163 {
164 next[i] = L2OUTPUT_NEXT_DROP;
165 if (failed2)
166 b[i]->error = node->errors[L2OUTPUT_ERROR_VTR_DROP];
167 if (failed1)
168 b[i]->error = node->errors[L2OUTPUT_ERROR_EFP_DROP];
169 }
170 }
171 }
172
173 if (l2_pbb)
174 {
175 int i;
176 for (i = 0; i < 4; i++)
177 if (l2_pbb_process (b[i], &(config->output_pbb_vtr)))
178 {
179 next[i] = L2OUTPUT_NEXT_DROP;
180 b[i]->error = node->errors[L2OUTPUT_ERROR_VTR_DROP];
181 }
182 }
183
184 if (shg_set)
185 {
186 split_horizon_violation (node, config->shg, b[0], next);
187 split_horizon_violation (node, config->shg, b[1], next + 1);
188 split_horizon_violation (node, config->shg, b[2], next + 2);
189 split_horizon_violation (node, config->shg, b[3], next + 3);
190 }
191 /* next */
192 n_left -= 4;
193 b += 4;
194 next += 4;
195 cdo += 4;
196 }
197
198 while (n_left)
199 {
200 if (update_feature_bitmap)
201 vnet_buffer (b[0])->l2.feature_bitmap = config->feature_bitmap;
202
203 if (l2_vtr)
204 {
205 u32 failed1 = l2_efp &&
206 l2_efp_filter_process (b[0], &(config->input_vtr));
207 u32 failed2 = l2_vtr_process (b[0], &(config->output_vtr));
Damjan Mariondc5252b2016-11-24 19:25:01 -0800208 if (PREDICT_FALSE (failed1 | failed2))
209 {
210 *next = L2OUTPUT_NEXT_DROP;
211 if (failed2)
Damjan Marionf3b27462018-05-15 19:51:38 +0200212 b[0]->error = node->errors[L2OUTPUT_ERROR_VTR_DROP];
Damjan Mariondc5252b2016-11-24 19:25:01 -0800213 if (failed1)
Damjan Marionf3b27462018-05-15 19:51:38 +0200214 b[0]->error = node->errors[L2OUTPUT_ERROR_EFP_DROP];
Damjan Mariondc5252b2016-11-24 19:25:01 -0800215 }
216 }
Damjan Marionf3b27462018-05-15 19:51:38 +0200217
218 if (l2_pbb && l2_pbb_process (b[0], &(config->output_pbb_vtr)))
Damjan Mariondc5252b2016-11-24 19:25:01 -0800219 {
Damjan Marionf3b27462018-05-15 19:51:38 +0200220 next[0] = L2OUTPUT_NEXT_DROP;
221 b[0]->error = node->errors[L2OUTPUT_ERROR_VTR_DROP];
Damjan Mariondc5252b2016-11-24 19:25:01 -0800222 }
Damjan Marionf3b27462018-05-15 19:51:38 +0200223
224 if (shg_set)
225 split_horizon_violation (node, config->shg, b[0], next);
226
227 /* next */
228 n_left -= 1;
229 b += 1;
230 next += 1;
Damjan Mariondc5252b2016-11-24 19:25:01 -0800231 }
232}
233
Damjan Marionf3b27462018-05-15 19:51:38 +0200234static_always_inline void
235l2output_set_buffer_error (vlib_buffer_t ** b, u32 n_left, vlib_error_t error)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700236{
Damjan Marionf3b27462018-05-15 19:51:38 +0200237 while (n_left >= 8)
238 {
239 vlib_prefetch_buffer_header (b[4], LOAD);
240 vlib_prefetch_buffer_header (b[5], LOAD);
241 vlib_prefetch_buffer_header (b[6], LOAD);
242 vlib_prefetch_buffer_header (b[7], LOAD);
243 b[0]->error = b[1]->error = b[2]->error = b[3]->error = error;
244 b += 4;
245 n_left -= 4;
246 }
247 while (n_left)
248 {
249 b[0]->error = error;
250 b += 1;
251 n_left -= 1;
252 }
253}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700254
Damjan Marionf3b27462018-05-15 19:51:38 +0200255static_always_inline void
256l2output_process_batch (vlib_main_t * vm, vlib_node_runtime_t * node,
257 l2_output_config_t * config, vlib_buffer_t ** b,
258 i16 * cdo, u16 * next, u32 n_left, int l2_efp,
259 int l2_vtr, int l2_pbb)
260{
261 u32 feature_bitmap = config->feature_bitmap & ~L2OUTPUT_FEAT_OUTPUT;
262 if (config->shg == 0 && feature_bitmap == 0)
263 l2output_process_batch_inline (vm, node, config, b, cdo, next, n_left,
264 l2_efp, l2_vtr, l2_pbb, 0, 0);
265 else if (config->shg == 0)
266 l2output_process_batch_inline (vm, node, config, b, cdo, next, n_left,
267 l2_efp, l2_vtr, l2_pbb, 0, 1);
268 else if (feature_bitmap == 0)
269 l2output_process_batch_inline (vm, node, config, b, cdo, next, n_left,
270 l2_efp, l2_vtr, l2_pbb, 1, 0);
271 else
272 l2output_process_batch_inline (vm, node, config, b, cdo, next, n_left,
273 l2_efp, l2_vtr, l2_pbb, 1, 1);
274}
275
Damjan Marion812b32d2018-05-28 21:26:47 +0200276VLIB_NODE_FN (l2output_node) (vlib_main_t * vm,
277 vlib_node_runtime_t * node,
278 vlib_frame_t * frame)
Damjan Marionf3b27462018-05-15 19:51:38 +0200279{
280 u32 n_left, *from;
281 l2output_main_t *msm = &l2output_main;
282 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b;
283 u16 nexts[VLIB_FRAME_SIZE];
284 u32 sw_if_indices[VLIB_FRAME_SIZE], *sw_if_index;
285 i16 cur_data_offsets[VLIB_FRAME_SIZE], *cdo;
286 l2_output_config_t *config;
287 u32 feature_bitmap;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700288
289 from = vlib_frame_vector_args (frame);
Damjan Marionf3b27462018-05-15 19:51:38 +0200290 n_left = frame->n_vectors; /* number of packets to process */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700291
Damjan Marionf3b27462018-05-15 19:51:38 +0200292 vlib_get_buffers (vm, from, bufs, n_left);
293 b = bufs;
294 sw_if_index = sw_if_indices;
295 cdo = cur_data_offsets;
296
297 /* extract data from buffer metadata */
298 while (n_left >= 8)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700299 {
Damjan Marionf3b27462018-05-15 19:51:38 +0200300 /* Prefetch the buffer header for the N+2 loop iteration */
301 vlib_prefetch_buffer_header (b[4], LOAD);
302 vlib_prefetch_buffer_header (b[5], LOAD);
303 vlib_prefetch_buffer_header (b[6], LOAD);
304 vlib_prefetch_buffer_header (b[7], LOAD);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700305
Damjan Marionf3b27462018-05-15 19:51:38 +0200306 sw_if_index[0] = vnet_buffer (b[0])->sw_if_index[VLIB_TX];
307 cdo[0] = b[0]->current_data;
308 sw_if_index[1] = vnet_buffer (b[1])->sw_if_index[VLIB_TX];
309 cdo[1] = b[1]->current_data;
310 sw_if_index[2] = vnet_buffer (b[2])->sw_if_index[VLIB_TX];
311 cdo[2] = b[2]->current_data;
312 sw_if_index[3] = vnet_buffer (b[3])->sw_if_index[VLIB_TX];
313 cdo[3] = b[3]->current_data;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700314
Damjan Marionf3b27462018-05-15 19:51:38 +0200315 /* next */
316 sw_if_index += 4;
317 n_left -= 4;
318 b += 4;
319 cdo += 4;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700320 }
Damjan Marionf3b27462018-05-15 19:51:38 +0200321 while (n_left)
322 {
323 sw_if_index[0] = vnet_buffer (b[0])->sw_if_index[VLIB_TX];
324 cdo[0] = b[0]->current_data;
325
326 /* next */
327 sw_if_index += 1;
328 n_left -= 1;
329 b += 1;
330 cdo += 1;
331 }
332
333 n_left = frame->n_vectors;
334 while (n_left)
335 {
336 u16 count, new_next, *next;
337 u16 off = frame->n_vectors - n_left;
338 b = bufs + off;
339
340 if (n_left >= 4)
341 {
342 vlib_prefetch_buffer_header (b[0], LOAD);
343 vlib_prefetch_buffer_header (b[1], LOAD);
344 vlib_prefetch_buffer_header (b[2], LOAD);
345 vlib_prefetch_buffer_header (b[3], LOAD);
346 }
347
348 sw_if_index = sw_if_indices + off;
349 cdo = cur_data_offsets + off;
350 next = nexts + off;
351
352 count = clib_count_equal_u32 (sw_if_index, n_left);
353 n_left -= count;
354
355 config = vec_elt_at_index (msm->configs, sw_if_index[0]);
356 feature_bitmap = config->feature_bitmap;
357 if (PREDICT_FALSE ((feature_bitmap & ~L2OUTPUT_FEAT_OUTPUT) != 0))
358 new_next = feat_bitmap_get_next_node_index
359 (l2output_main.l2_out_feat_next, feature_bitmap);
360 else
361 new_next = vec_elt (l2output_main.output_node_index_vec,
362 sw_if_index[0]);
363 clib_memset_u16 (nexts + off, new_next, count);
364
365 if (new_next == L2OUTPUT_NEXT_DROP)
366 {
367 l2output_set_buffer_error
368 (b, count, node->errors[L2OUTPUT_ERROR_MAPPING_DROP]);
369 continue;
370 }
371
372 /* VTR */
373 if (config->out_vtr_flag && config->output_vtr.push_and_pop_bytes)
374 {
375 if (feature_bitmap & L2OUTPUT_FEAT_EFP_FILTER)
376 l2output_process_batch (vm, node, config, b, cdo, next, count,
377 /* l2_efp */ 1,
378 /* l2_vtr */ 1,
379 /* l2_pbb */ 0);
380 else
381 l2output_process_batch (vm, node, config, b, cdo, next, count,
382 /* l2_efp */ 0,
383 /* l2_vtr */ 1,
384 /* l2_pbb */ 0);
385 }
386 else if (config->out_vtr_flag &&
387 config->output_pbb_vtr.push_and_pop_bytes)
388 l2output_process_batch (vm, node, config, b, cdo, next, count,
389 /* l2_efp */ 0,
390 /* l2_vtr */ 0,
391 /* l2_pbb */ 1);
392 else
393 l2output_process_batch (vm, node, config, b, cdo, next, count,
394 /* l2_efp */ 0,
395 /* l2_vtr */ 0,
396 /* l2_pbb */ 0);
397 }
398
399
400 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)))
401 {
402 n_left = frame->n_vectors; /* number of packets to process */
403 b = bufs;
404
405 while (n_left)
406 {
407 if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED))
408 {
409 ethernet_header_t *h;
410 l2output_trace_t *t =
411 vlib_add_trace (vm, node, b[0], sizeof (*t));
412 t->sw_if_index = vnet_buffer (b[0])->sw_if_index[VLIB_TX];
413 h = vlib_buffer_get_current (b[0]);
414 clib_memcpy (t->src, h->src_address, 6);
415 clib_memcpy (t->dst, h->dst_address, 6);
416 clib_memcpy (t->raw, &h->type, sizeof (t->raw));
417 }
418 /* next */
419 n_left--;
420 b++;
421 }
422 }
423
424 vlib_buffer_enqueue_to_next (vm, node, from, nexts, frame->n_vectors);
425 vlib_node_increment_counter (vm, l2output_node.index,
426 L2OUTPUT_ERROR_L2OUTPUT, frame->n_vectors);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700427
428 return frame->n_vectors;
429}
430
Dave Barach97d8dc22016-08-15 15:31:15 -0400431/* *INDENT-OFF* */
Eyal Bari001fd402017-07-16 09:34:53 +0300432VLIB_REGISTER_NODE (l2output_node) = {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700433 .name = "l2-output",
434 .vector_size = sizeof (u32),
435 .format_trace = format_l2output_trace,
436 .type = VLIB_NODE_TYPE_INTERNAL,
Dave Barach97d8dc22016-08-15 15:31:15 -0400437
Ed Warnickecb9cada2015-12-08 15:45:58 -0700438 .n_errors = ARRAY_LEN(l2output_error_strings),
439 .error_strings = l2output_error_strings,
440
441 .n_next_nodes = L2OUTPUT_N_NEXT,
442
443 /* edit / add dispositions here */
444 .next_nodes = {
445 [L2OUTPUT_NEXT_DROP] = "error-drop",
John Lo0fc9bc12016-10-27 11:17:02 -0400446 [L2OUTPUT_NEXT_BAD_INTF] = "l2-output-bad-intf",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700447 },
448};
Dave Barach97d8dc22016-08-15 15:31:15 -0400449/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700450
John Lo3ef822e2016-06-07 09:14:07 -0400451
John Lo0fc9bc12016-10-27 11:17:02 -0400452#define foreach_l2output_bad_intf_error \
453_(DROP, "L2 output to interface not in L2 mode or deleted")
John Lo3ef822e2016-06-07 09:14:07 -0400454
John Lo0fc9bc12016-10-27 11:17:02 -0400455static char *l2output_bad_intf_error_strings[] = {
John Lo3ef822e2016-06-07 09:14:07 -0400456#define _(sym,string) string,
John Lo0fc9bc12016-10-27 11:17:02 -0400457 foreach_l2output_bad_intf_error
John Lo3ef822e2016-06-07 09:14:07 -0400458#undef _
459};
460
Dave Barach97d8dc22016-08-15 15:31:15 -0400461typedef enum
462{
John Lo0fc9bc12016-10-27 11:17:02 -0400463#define _(sym,str) L2OUTPUT_BAD_INTF_ERROR_##sym,
464 foreach_l2output_bad_intf_error
John Lo3ef822e2016-06-07 09:14:07 -0400465#undef _
John Lo0fc9bc12016-10-27 11:17:02 -0400466 L2OUTPUT_BAD_INTF_N_ERROR,
467} l2output_bad_intf_error_t;
John Lo3ef822e2016-06-07 09:14:07 -0400468
469
Dave Barach97d8dc22016-08-15 15:31:15 -0400470/**
John Lo0fc9bc12016-10-27 11:17:02 -0400471 * Output node for interfaces/tunnels which was in L2 mode but were changed
472 * to L3 mode or possibly deleted thereafter. On changing forwarding mode
473 * of any tunnel/interface from L2 to L3, its entry in l2_output_main table
474 * next_nodes.output_node_index_vec[sw_if_index] MUST be set to the value of
475 * L2OUTPUT_NEXT_BAD_INTF. Thus, if there are stale entries in the L2FIB for
476 * this sw_if_index, l2-output will send packets for this sw_if_index to the
477 * l2-output-bad-intf node which just setup the proper drop reason before
478 * sending packets to the error-drop node to drop the packet. Then, stale L2FIB
479 * entries for delted tunnels won't cause possible packet or memory corrpution.
Dave Barach97d8dc22016-08-15 15:31:15 -0400480 */
John Lo3ef822e2016-06-07 09:14:07 -0400481
Damjan Marion6e363512018-08-10 22:39:11 +0200482VLIB_NODE_FN (l2output_bad_intf_node) (vlib_main_t * vm,
483 vlib_node_runtime_t * node,
484 vlib_frame_t * frame)
John Lo3ef822e2016-06-07 09:14:07 -0400485{
Dave Barach97d8dc22016-08-15 15:31:15 -0400486 u32 n_left_from, *from, *to_next;
John Lo3ef822e2016-06-07 09:14:07 -0400487 l2output_next_t next_index = 0;
488
489 from = vlib_frame_vector_args (frame);
Dave Barach97d8dc22016-08-15 15:31:15 -0400490 n_left_from = frame->n_vectors; /* number of packets to process */
John Lo3ef822e2016-06-07 09:14:07 -0400491
492 while (n_left_from > 0)
493 {
494 u32 n_left_to_next;
495
Dave Barach97d8dc22016-08-15 15:31:15 -0400496 /* get space to enqueue frame to graph node "next_index" */
497 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
John Lo3ef822e2016-06-07 09:14:07 -0400498
499 while (n_left_from >= 4 && n_left_to_next >= 2)
500 {
Dave Barach97d8dc22016-08-15 15:31:15 -0400501 u32 bi0, bi1;
502 vlib_buffer_t *b0, *b1;
John Lo3ef822e2016-06-07 09:14:07 -0400503
Dave Barach97d8dc22016-08-15 15:31:15 -0400504 to_next[0] = bi0 = from[0];
John Lo3ef822e2016-06-07 09:14:07 -0400505 to_next[1] = bi1 = from[1];
506 from += 2;
507 to_next += 2;
508 n_left_from -= 2;
509 n_left_to_next -= 2;
510 b0 = vlib_get_buffer (vm, bi0);
511 b1 = vlib_get_buffer (vm, bi1);
John Lo0fc9bc12016-10-27 11:17:02 -0400512 b0->error = node->errors[L2OUTPUT_BAD_INTF_ERROR_DROP];
513 b1->error = node->errors[L2OUTPUT_BAD_INTF_ERROR_DROP];
Dave Barach97d8dc22016-08-15 15:31:15 -0400514 }
515
John Lo3ef822e2016-06-07 09:14:07 -0400516 while (n_left_from > 0 && n_left_to_next > 0)
517 {
Dave Barach97d8dc22016-08-15 15:31:15 -0400518 u32 bi0;
519 vlib_buffer_t *b0;
John Lo3ef822e2016-06-07 09:14:07 -0400520
Dave Barach97d8dc22016-08-15 15:31:15 -0400521 bi0 = from[0];
John Lo3ef822e2016-06-07 09:14:07 -0400522 to_next[0] = bi0;
523 from += 1;
524 to_next += 1;
525 n_left_from -= 1;
526 n_left_to_next -= 1;
527 b0 = vlib_get_buffer (vm, bi0);
John Lo0fc9bc12016-10-27 11:17:02 -0400528 b0->error = node->errors[L2OUTPUT_BAD_INTF_ERROR_DROP];
John Lo3ef822e2016-06-07 09:14:07 -0400529 }
530
531 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
532 }
533
534 return frame->n_vectors;
535}
536
Dave Barach97d8dc22016-08-15 15:31:15 -0400537/* *INDENT-OFF* */
Damjan Marion6e363512018-08-10 22:39:11 +0200538VLIB_REGISTER_NODE (l2output_bad_intf_node) = {
John Lo0fc9bc12016-10-27 11:17:02 -0400539 .name = "l2-output-bad-intf",
John Lo3ef822e2016-06-07 09:14:07 -0400540 .vector_size = sizeof (u32),
541 .type = VLIB_NODE_TYPE_INTERNAL,
Dave Barach97d8dc22016-08-15 15:31:15 -0400542
John Lo0fc9bc12016-10-27 11:17:02 -0400543 .n_errors = ARRAY_LEN(l2output_bad_intf_error_strings),
544 .error_strings = l2output_bad_intf_error_strings,
John Lo3ef822e2016-06-07 09:14:07 -0400545
546 .n_next_nodes = 1,
547
548 /* edit / add dispositions here */
549 .next_nodes = {
550 [0] = "error-drop",
551 },
552};
Dave Barach97d8dc22016-08-15 15:31:15 -0400553/* *INDENT-ON* */
John Lo3ef822e2016-06-07 09:14:07 -0400554
Eyal Bari001fd402017-07-16 09:34:53 +0300555static clib_error_t *
556l2output_init (vlib_main_t * vm)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700557{
Dave Barach97d8dc22016-08-15 15:31:15 -0400558 l2output_main_t *mp = &l2output_main;
559
Ed Warnickecb9cada2015-12-08 15:45:58 -0700560 mp->vlib_main = vm;
Dave Barach97d8dc22016-08-15 15:31:15 -0400561 mp->vnet_main = vnet_get_main ();
Ed Warnickecb9cada2015-12-08 15:45:58 -0700562
Dave Barach97d8dc22016-08-15 15:31:15 -0400563 /* Create the config vector */
564 vec_validate (mp->configs, 100);
565 /* Until we hook up the CLI config, just create 100 sw interface entries and zero them */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700566
Dave Barach97d8dc22016-08-15 15:31:15 -0400567 /* Initialize the feature next-node indexes */
568 feat_bitmap_init_next_nodes (vm,
569 l2output_node.index,
570 L2OUTPUT_N_FEAT,
571 l2output_get_feat_names (),
John Lobeb0b2e2017-07-22 00:21:36 -0400572 mp->l2_out_feat_next);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700573
Dave Barach97d8dc22016-08-15 15:31:15 -0400574 /* Initialize the output node mapping table */
John Lobeb0b2e2017-07-22 00:21:36 -0400575 vec_validate_init_empty (mp->output_node_index_vec, 100,
John Lob2fd6cb2017-07-12 19:56:45 -0400576 L2OUTPUT_NEXT_DROP);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700577
578 return 0;
579}
580
581VLIB_INIT_FUNCTION (l2output_init);
582
Ed Warnickecb9cada2015-12-08 15:45:58 -0700583
Damjan Marion6e363512018-08-10 22:39:11 +0200584#ifndef CLIB_MARCH_VARIANT
Chris Luke16bcf7d2016-09-01 14:31:46 -0400585/** Create a mapping in the next node mapping table for the given sw_if_index. */
John Lob2fd6cb2017-07-12 19:56:45 -0400586void
587l2output_create_output_node_mapping (vlib_main_t * vlib_main,
588 vnet_main_t * vnet_main, u32 sw_if_index)
Dave Barach97d8dc22016-08-15 15:31:15 -0400589{
John Lob2fd6cb2017-07-12 19:56:45 -0400590 vnet_hw_interface_t *hw0 =
591 vnet_get_sup_hw_interface (vnet_main, sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700592
Dave Barach97d8dc22016-08-15 15:31:15 -0400593 /* dynamically create graph node arc */
John Lob2fd6cb2017-07-12 19:56:45 -0400594 u32 next = vlib_node_add_next (vlib_main, l2output_node.index,
595 hw0->output_node_index);
John Lobeb0b2e2017-07-22 00:21:36 -0400596 l2output_main.output_node_index_vec[sw_if_index] = next;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700597}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700598
Dave Barach97d8dc22016-08-15 15:31:15 -0400599/* Get a pointer to the config for the given interface */
600l2_output_config_t *
601l2output_intf_config (u32 sw_if_index)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700602{
Dave Barach97d8dc22016-08-15 15:31:15 -0400603 l2output_main_t *mp = &l2output_main;
604
605 vec_validate (mp->configs, sw_if_index);
606 return vec_elt_at_index (mp->configs, sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700607}
608
Chris Luke16bcf7d2016-09-01 14:31:46 -0400609/** Enable (or disable) the feature in the bitmap for the given interface. */
Dave Barach97d8dc22016-08-15 15:31:15 -0400610void
611l2output_intf_bitmap_enable (u32 sw_if_index, u32 feature_bitmap, u32 enable)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700612{
Dave Barach97d8dc22016-08-15 15:31:15 -0400613 l2output_main_t *mp = &l2output_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700614 l2_output_config_t *config;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700615
Dave Barach97d8dc22016-08-15 15:31:15 -0400616 vec_validate (mp->configs, sw_if_index);
617 config = vec_elt_at_index (mp->configs, sw_if_index);
618
619 if (enable)
620 {
621 config->feature_bitmap |= feature_bitmap;
622 }
623 else
624 {
625 config->feature_bitmap &= ~feature_bitmap;
626 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700627}
Damjan Marionf3b27462018-05-15 19:51:38 +0200628#endif
Dave Barach97d8dc22016-08-15 15:31:15 -0400629
630/*
631 * fd.io coding-style-patch-verification: ON
632 *
633 * Local Variables:
634 * eval: (c-set-style "gnu")
635 * End:
636 */