SPAN:add l2 mirror
[vpp.git] / src / vnet / l2 / l2_output.c
1 /*
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
30 /* Feature graph node names */
31 static char *l2output_feat_names[] = {
32 #define _(sym,name) name,
33   foreach_l2output_feat
34 #undef _
35 };
36
37 char **
38 l2output_get_feat_names (void)
39 {
40   return l2output_feat_names;
41 }
42
43 l2output_main_t l2output_main;
44
45 typedef struct
46 {
47   /* per-pkt trace data */
48   u8 src[6];
49   u8 dst[6];
50   u32 sw_if_index;
51   u8 raw[12];                   /* raw data */
52 } l2output_trace_t;
53
54 /* packet trace format function */
55 static u8 *
56 format_l2output_trace (u8 * s, va_list * args)
57 {
58   CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
59   CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
60   l2output_trace_t *t = va_arg (*args, l2output_trace_t *);
61
62   s = format (s, "l2-output: sw_if_index %d dst %U src %U data "
63               "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
64               t->sw_if_index,
65               format_ethernet_address, t->dst,
66               format_ethernet_address, t->src,
67               t->raw[0], t->raw[1], t->raw[2], t->raw[3], t->raw[4],
68               t->raw[5], t->raw[6], t->raw[7], t->raw[8], t->raw[9],
69               t->raw[10], t->raw[11]);
70
71   return s;
72 }
73
74
75 static char *l2output_error_strings[] = {
76 #define _(sym,string) string,
77   foreach_l2output_error
78 #undef _
79 };
80
81 /**
82  * Check for split horizon violations.
83  * Return 0 if split horizon check passes, otherwise return non-zero.
84  * Packets should not be transmitted out an interface with the same
85  * split-horizon group as the input interface, except if the @c shg is 0
86  * in which case the check always passes.
87  */
88 static_always_inline u32
89 split_horizon_violation (u8 shg1, u8 shg2)
90 {
91   if (PREDICT_TRUE (shg1 == 0))
92     {
93       return 0;
94     }
95   else
96     {
97       return shg1 == shg2;
98     }
99 }
100
101 /** Determine the next L2 node based on the output feature bitmap */
102 static_always_inline void
103 l2_output_dispatch (vlib_buffer_t * b0, vlib_node_runtime_t * node,
104                     u32 * cached_sw_if_index, u32 * cached_next_index,
105                     u32 sw_if_index, u32 feature_bitmap, u32 * next0)
106 {
107   /*
108    * The output feature bitmap always have at least the L2 output bit set
109    * for a normal L2 interface (or 0 if the interface is changed from L2
110    * to L3 mode). So if the feature bitmap is 0 or just have L2 output bits set,
111    * we know there is no more feature and will just output packets on interface.
112    * Otherwise, get the index of the next feature node.
113    */
114   if (PREDICT_FALSE ((feature_bitmap & ~L2OUTPUT_FEAT_OUTPUT) != 0))
115     {
116       /* Save bitmap for the next feature graph nodes */
117       vnet_buffer (b0)->l2.feature_bitmap = feature_bitmap;
118
119       /* Determine the next node */
120       *next0 =
121         feat_bitmap_get_next_node_index (l2output_main.l2_out_feat_next,
122                                          feature_bitmap);
123     }
124   else
125     {
126       /*
127        * There are no features. Send packet to TX node for sw_if_index0
128        * This is a little tricky in that the output interface next node indexes
129        * are not precomputed at init time.
130        */
131
132       if (sw_if_index == *cached_sw_if_index)
133         {
134           /* We hit in the one-entry cache. Use it. */
135           *next0 = *cached_next_index;
136         }
137       else
138         {
139           /* Look up the output TX node for the sw_if_index */
140           *next0 = vec_elt (l2output_main.output_node_index_vec, sw_if_index);
141
142           if (PREDICT_FALSE (*next0 == L2OUTPUT_NEXT_DROP))
143             b0->error = node->errors[L2OUTPUT_ERROR_MAPPING_DROP];
144
145           /* Update the one-entry cache */
146           *cached_sw_if_index = sw_if_index;
147           *cached_next_index = *next0;
148         }
149     }
150 }
151
152 static_always_inline void
153 l2output_vtr (vlib_node_runtime_t * node, l2_output_config_t * config,
154               u32 feature_bitmap, vlib_buffer_t * b, u32 * next)
155 {
156   if (PREDICT_FALSE (config->out_vtr_flag))
157     {
158       /* Perform pre-vtr EFP filter check if configured */
159       if (config->output_vtr.push_and_pop_bytes)
160         {
161           /*
162            * Perform output vlan tag rewrite and the pre-vtr EFP filter check.
163            * The EFP Filter only needs to be run if there is an output VTR
164            * configured. The flag for the post-vtr EFP Filter node is used
165            * to trigger the pre-vtr check as well.
166            */
167           u32 failed1 = (feature_bitmap & L2OUTPUT_FEAT_EFP_FILTER)
168             && (l2_efp_filter_process (b, &(config->input_vtr)));
169           u32 failed2 = l2_vtr_process (b, &(config->output_vtr));
170
171           if (PREDICT_FALSE (failed1 | failed2))
172             {
173               *next = L2OUTPUT_NEXT_DROP;
174               if (failed2)
175                 {
176                   b->error = node->errors[L2OUTPUT_ERROR_VTR_DROP];
177                 }
178               if (failed1)
179                 {
180                   b->error = node->errors[L2OUTPUT_ERROR_EFP_DROP];
181                 }
182             }
183         }
184       // perform the PBB rewrite
185       else if (config->output_pbb_vtr.push_and_pop_bytes)
186         {
187           u32 failed = l2_pbb_process (b, &(config->output_pbb_vtr));
188           if (PREDICT_FALSE (failed))
189             {
190               *next = L2OUTPUT_NEXT_DROP;
191               b->error = node->errors[L2OUTPUT_ERROR_VTR_DROP];
192             }
193         }
194     }
195 }
196
197
198 static_always_inline uword
199 l2output_node_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
200                       vlib_frame_t * frame, int do_trace)
201 {
202   u32 n_left_from, *from, *to_next;
203   l2output_next_t next_index;
204   l2output_main_t *msm = &l2output_main;
205   u32 cached_sw_if_index;
206   u32 cached_next_index;
207
208   /* Invalidate cache */
209   cached_sw_if_index = ~0;
210   cached_next_index = ~0;       /* warning be gone */
211
212   from = vlib_frame_vector_args (frame);
213   n_left_from = frame->n_vectors;       /* number of packets to process */
214   next_index = node->cached_next_index;
215
216   while (n_left_from > 0)
217     {
218       u32 n_left_to_next;
219
220       /* get space to enqueue frame to graph node "next_index" */
221       vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
222
223       while (n_left_from >= 8 && n_left_to_next >= 4)
224         {
225           u32 bi0, bi1, bi2, bi3;
226           vlib_buffer_t *b0, *b1, *b2, *b3;
227           u32 next0, next1, next2, next3;
228           u32 sw_if_index0, sw_if_index1, sw_if_index2, sw_if_index3;
229           ethernet_header_t *h0, *h1, *h2, *h3;
230           l2_output_config_t *config0, *config1, *config2, *config3;
231           u32 feature_bitmap0, feature_bitmap1;
232           u32 feature_bitmap2, feature_bitmap3;
233
234           /* Prefetch next iteration. */
235           {
236             vlib_buffer_t *p4, *p5, *p6, *p7;
237
238             p4 = vlib_get_buffer (vm, from[4]);
239             p5 = vlib_get_buffer (vm, from[5]);
240             p6 = vlib_get_buffer (vm, from[6]);
241             p7 = vlib_get_buffer (vm, from[7]);
242
243             /* Prefetch the buffer header for the N+2 loop iteration */
244             vlib_prefetch_buffer_header (p4, LOAD);
245             vlib_prefetch_buffer_header (p5, LOAD);
246             vlib_prefetch_buffer_header (p6, LOAD);
247             vlib_prefetch_buffer_header (p7, LOAD);
248           }
249
250           /* speculatively enqueue b0 and b1 to the current next frame */
251           /* bi is "buffer index", b is pointer to the buffer */
252           to_next[0] = bi0 = from[0];
253           to_next[1] = bi1 = from[1];
254           to_next[2] = bi2 = from[2];
255           to_next[3] = bi3 = from[3];
256           from += 4;
257           to_next += 4;
258           n_left_from -= 4;
259           n_left_to_next -= 4;
260
261           b0 = vlib_get_buffer (vm, bi0);
262           b1 = vlib_get_buffer (vm, bi1);
263           b2 = vlib_get_buffer (vm, bi2);
264           b3 = vlib_get_buffer (vm, bi3);
265
266           /* TX interface handles */
267           sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_TX];
268           sw_if_index1 = vnet_buffer (b1)->sw_if_index[VLIB_TX];
269           sw_if_index2 = vnet_buffer (b2)->sw_if_index[VLIB_TX];
270           sw_if_index3 = vnet_buffer (b3)->sw_if_index[VLIB_TX];
271
272           vlib_node_increment_counter (vm, l2output_node.index,
273                                        L2OUTPUT_ERROR_L2OUTPUT, 4);
274
275           /* Get config for the output interface */
276           config0 = vec_elt_at_index (msm->configs, sw_if_index0);
277           config1 = vec_elt_at_index (msm->configs, sw_if_index1);
278           config2 = vec_elt_at_index (msm->configs, sw_if_index2);
279           config3 = vec_elt_at_index (msm->configs, sw_if_index3);
280
281           /*
282            * Get features from the config
283            * TODO: mask out any non-applicable features
284            */
285           feature_bitmap0 = config0->feature_bitmap;
286           feature_bitmap1 = config1->feature_bitmap;
287           feature_bitmap2 = config2->feature_bitmap;
288           feature_bitmap3 = config3->feature_bitmap;
289
290           /* Determine next node */
291           l2_output_dispatch (b0, node, &cached_sw_if_index,
292                               &cached_next_index, sw_if_index0,
293                               feature_bitmap0, &next0);
294           l2_output_dispatch (b1, node, &cached_sw_if_index,
295                               &cached_next_index, sw_if_index1,
296                               feature_bitmap1, &next1);
297           l2_output_dispatch (b2, node, &cached_sw_if_index,
298                               &cached_next_index, sw_if_index2,
299                               feature_bitmap2, &next2);
300           l2_output_dispatch (b3, node, &cached_sw_if_index,
301                               &cached_next_index, sw_if_index3,
302                               feature_bitmap3, &next3);
303
304           l2output_vtr (node, config0, feature_bitmap0, b0, &next0);
305           l2output_vtr (node, config1, feature_bitmap1, b1, &next1);
306           l2output_vtr (node, config2, feature_bitmap2, b2, &next2);
307           l2output_vtr (node, config3, feature_bitmap3, b3, &next3);
308
309           if (do_trace)
310             {
311               h0 = vlib_buffer_get_current (b0);
312               h1 = vlib_buffer_get_current (b1);
313               h2 = vlib_buffer_get_current (b2);
314               h3 = vlib_buffer_get_current (b3);
315               if (b0->flags & VLIB_BUFFER_IS_TRACED)
316                 {
317                   l2output_trace_t *t =
318                     vlib_add_trace (vm, node, b0, sizeof (*t));
319                   t->sw_if_index = sw_if_index0;
320                   clib_memcpy (t->src, h0->src_address, 6);
321                   clib_memcpy (t->dst, h0->dst_address, 6);
322                   clib_memcpy (t->raw, &h0->type, sizeof (t->raw));
323                 }
324               if (b1->flags & VLIB_BUFFER_IS_TRACED)
325                 {
326                   l2output_trace_t *t =
327                     vlib_add_trace (vm, node, b1, sizeof (*t));
328                   t->sw_if_index = sw_if_index1;
329                   clib_memcpy (t->src, h1->src_address, 6);
330                   clib_memcpy (t->dst, h1->dst_address, 6);
331                   clib_memcpy (t->raw, &h1->type, sizeof (t->raw));
332                 }
333               if (b2->flags & VLIB_BUFFER_IS_TRACED)
334                 {
335                   l2output_trace_t *t =
336                     vlib_add_trace (vm, node, b2, sizeof (*t));
337                   t->sw_if_index = sw_if_index2;
338                   clib_memcpy (t->src, h2->src_address, 6);
339                   clib_memcpy (t->dst, h2->dst_address, 6);
340                   clib_memcpy (t->raw, &h2->type, sizeof (t->raw));
341                 }
342               if (b3->flags & VLIB_BUFFER_IS_TRACED)
343                 {
344                   l2output_trace_t *t =
345                     vlib_add_trace (vm, node, b3, sizeof (*t));
346                   t->sw_if_index = sw_if_index3;
347                   clib_memcpy (t->src, h3->src_address, 6);
348                   clib_memcpy (t->dst, h3->dst_address, 6);
349                   clib_memcpy (t->raw, &h3->type, sizeof (t->raw));
350                 }
351             }
352
353           /*
354            * Perform the split horizon check
355            * The check can only fail for non-zero shg's
356            */
357           if (PREDICT_FALSE (config0->shg + config1->shg +
358                              config2->shg + config3->shg))
359             {
360               /* one of the checks might fail, check both */
361               if (split_horizon_violation
362                   (config0->shg, vnet_buffer (b0)->l2.shg))
363                 {
364                   next0 = L2OUTPUT_NEXT_DROP;
365                   b0->error = node->errors[L2OUTPUT_ERROR_SHG_DROP];
366                 }
367               if (split_horizon_violation
368                   (config1->shg, vnet_buffer (b1)->l2.shg))
369                 {
370                   next1 = L2OUTPUT_NEXT_DROP;
371                   b1->error = node->errors[L2OUTPUT_ERROR_SHG_DROP];
372                 }
373               if (split_horizon_violation
374                   (config2->shg, vnet_buffer (b2)->l2.shg))
375                 {
376                   next2 = L2OUTPUT_NEXT_DROP;
377                   b2->error = node->errors[L2OUTPUT_ERROR_SHG_DROP];
378                 }
379               if (split_horizon_violation
380                   (config3->shg, vnet_buffer (b3)->l2.shg))
381                 {
382                   next3 = L2OUTPUT_NEXT_DROP;
383                   b3->error = node->errors[L2OUTPUT_ERROR_SHG_DROP];
384                 }
385             }
386
387           /* verify speculative enqueues, maybe switch current next frame */
388           /* if next0==next1==next_index then nothing special needs to be done */
389           vlib_validate_buffer_enqueue_x4 (vm, node, next_index,
390                                            to_next, n_left_to_next,
391                                            bi0, bi1, bi2, bi3,
392                                            next0, next1, next2, next3);
393         }
394
395       while (n_left_from > 0 && n_left_to_next > 0)
396         {
397           u32 bi0;
398           vlib_buffer_t *b0;
399           u32 next0;
400           u32 sw_if_index0;
401           ethernet_header_t *h0;
402           l2_output_config_t *config0;
403           u32 feature_bitmap0;
404
405           /* speculatively enqueue b0 to the current next frame */
406           bi0 = from[0];
407           to_next[0] = bi0;
408           from += 1;
409           to_next += 1;
410           n_left_from -= 1;
411           n_left_to_next -= 1;
412
413           b0 = vlib_get_buffer (vm, bi0);
414
415           sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_TX];
416
417           vlib_node_increment_counter (vm, l2output_node.index,
418                                        L2OUTPUT_ERROR_L2OUTPUT, 1);
419
420           /* Get config for the output interface */
421           config0 = vec_elt_at_index (msm->configs, sw_if_index0);
422
423           /*
424            * Get features from the config
425            * TODO: mask out any non-applicable features
426            */
427           feature_bitmap0 = config0->feature_bitmap;
428
429           /* Determine next node */
430           l2_output_dispatch (b0, node, &cached_sw_if_index,
431                               &cached_next_index, sw_if_index0,
432                               feature_bitmap0, &next0);
433
434           l2output_vtr (node, config0, feature_bitmap0, b0, &next0);
435
436           if (do_trace && PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
437             {
438               l2output_trace_t *t =
439                 vlib_add_trace (vm, node, b0, sizeof (*t));
440               t->sw_if_index = sw_if_index0;
441               h0 = vlib_buffer_get_current (b0);
442               clib_memcpy (t->src, h0->src_address, 6);
443               clib_memcpy (t->dst, h0->dst_address, 6);
444               clib_memcpy (t->raw, &h0->type, sizeof (t->raw));
445             }
446
447           /* Perform the split horizon check */
448           if (PREDICT_FALSE
449               (split_horizon_violation
450                (config0->shg, vnet_buffer (b0)->l2.shg)))
451             {
452               next0 = L2OUTPUT_NEXT_DROP;
453               b0->error = node->errors[L2OUTPUT_ERROR_SHG_DROP];
454             }
455
456           /* verify speculative enqueue, maybe switch current next frame */
457           vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
458                                            to_next, n_left_to_next,
459                                            bi0, next0);
460         }
461
462       vlib_put_next_frame (vm, node, next_index, n_left_to_next);
463     }
464
465   return frame->n_vectors;
466 }
467
468 static uword
469 l2output_node_fn (vlib_main_t * vm,
470                   vlib_node_runtime_t * node, vlib_frame_t * frame)
471 {
472   if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)))
473     return l2output_node_inline (vm, node, frame, 1 /* do_trace */ );
474   return l2output_node_inline (vm, node, frame, 0 /* do_trace */ );
475 }
476
477 /* *INDENT-OFF* */
478 VLIB_REGISTER_NODE (l2output_node) = {
479   .function = l2output_node_fn,
480   .name = "l2-output",
481   .vector_size = sizeof (u32),
482   .format_trace = format_l2output_trace,
483   .type = VLIB_NODE_TYPE_INTERNAL,
484
485   .n_errors = ARRAY_LEN(l2output_error_strings),
486   .error_strings = l2output_error_strings,
487
488   .n_next_nodes = L2OUTPUT_N_NEXT,
489
490   /* edit / add dispositions here */
491   .next_nodes = {
492         [L2OUTPUT_NEXT_DROP] = "error-drop",
493         [L2OUTPUT_NEXT_BAD_INTF] = "l2-output-bad-intf",
494   },
495 };
496
497 VLIB_NODE_FUNCTION_MULTIARCH (l2output_node, l2output_node_fn);
498 /* *INDENT-ON* */
499
500
501 #define foreach_l2output_bad_intf_error \
502 _(DROP,     "L2 output to interface not in L2 mode or deleted")
503
504 static char *l2output_bad_intf_error_strings[] = {
505 #define _(sym,string) string,
506   foreach_l2output_bad_intf_error
507 #undef _
508 };
509
510 typedef enum
511 {
512 #define _(sym,str) L2OUTPUT_BAD_INTF_ERROR_##sym,
513   foreach_l2output_bad_intf_error
514 #undef _
515     L2OUTPUT_BAD_INTF_N_ERROR,
516 } l2output_bad_intf_error_t;
517
518
519 /**
520  * Output node for interfaces/tunnels which was in L2 mode but were changed
521  * to L3 mode or possibly deleted thereafter. On changing forwarding mode
522  * of any tunnel/interface from L2 to L3, its entry in l2_output_main table
523  * next_nodes.output_node_index_vec[sw_if_index] MUST be set to the value of
524  * L2OUTPUT_NEXT_BAD_INTF. Thus, if there are stale entries in the L2FIB for
525  * this sw_if_index, l2-output will send packets for this sw_if_index to the
526  * l2-output-bad-intf node which just setup the proper drop reason before
527  * sending packets to the error-drop node to drop the packet. Then, stale L2FIB
528  * entries for delted tunnels won't cause possible packet or memory corrpution.
529  */
530 static vlib_node_registration_t l2output_bad_intf_node;
531
532 static uword
533 l2output_bad_intf_node_fn (vlib_main_t * vm,
534                            vlib_node_runtime_t * node, vlib_frame_t * frame)
535 {
536   u32 n_left_from, *from, *to_next;
537   l2output_next_t next_index = 0;
538
539   from = vlib_frame_vector_args (frame);
540   n_left_from = frame->n_vectors;       /* number of packets to process */
541
542   while (n_left_from > 0)
543     {
544       u32 n_left_to_next;
545
546       /* get space to enqueue frame to graph node "next_index" */
547       vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
548
549       while (n_left_from >= 4 && n_left_to_next >= 2)
550         {
551           u32 bi0, bi1;
552           vlib_buffer_t *b0, *b1;
553
554           to_next[0] = bi0 = from[0];
555           to_next[1] = bi1 = from[1];
556           from += 2;
557           to_next += 2;
558           n_left_from -= 2;
559           n_left_to_next -= 2;
560           b0 = vlib_get_buffer (vm, bi0);
561           b1 = vlib_get_buffer (vm, bi1);
562           b0->error = node->errors[L2OUTPUT_BAD_INTF_ERROR_DROP];
563           b1->error = node->errors[L2OUTPUT_BAD_INTF_ERROR_DROP];
564         }
565
566       while (n_left_from > 0 && n_left_to_next > 0)
567         {
568           u32 bi0;
569           vlib_buffer_t *b0;
570
571           bi0 = from[0];
572           to_next[0] = bi0;
573           from += 1;
574           to_next += 1;
575           n_left_from -= 1;
576           n_left_to_next -= 1;
577           b0 = vlib_get_buffer (vm, bi0);
578           b0->error = node->errors[L2OUTPUT_BAD_INTF_ERROR_DROP];
579         }
580
581       vlib_put_next_frame (vm, node, next_index, n_left_to_next);
582     }
583
584   return frame->n_vectors;
585 }
586
587 /* *INDENT-OFF* */
588 VLIB_REGISTER_NODE (l2output_bad_intf_node,static) = {
589   .function = l2output_bad_intf_node_fn,
590   .name = "l2-output-bad-intf",
591   .vector_size = sizeof (u32),
592   .type = VLIB_NODE_TYPE_INTERNAL,
593
594   .n_errors =  ARRAY_LEN(l2output_bad_intf_error_strings),
595   .error_strings = l2output_bad_intf_error_strings,
596
597   .n_next_nodes = 1,
598
599   /* edit / add dispositions here */
600   .next_nodes = {
601         [0] = "error-drop",
602   },
603 };
604
605 VLIB_NODE_FUNCTION_MULTIARCH (l2output_bad_intf_node, l2output_bad_intf_node_fn);
606 /* *INDENT-ON* */
607
608 static clib_error_t *
609 l2output_init (vlib_main_t * vm)
610 {
611   l2output_main_t *mp = &l2output_main;
612
613   mp->vlib_main = vm;
614   mp->vnet_main = vnet_get_main ();
615
616   /* Create the config vector */
617   vec_validate (mp->configs, 100);
618   /* Until we hook up the CLI config, just create 100 sw interface entries  and zero them */
619
620   /* Initialize the feature next-node indexes */
621   feat_bitmap_init_next_nodes (vm,
622                                l2output_node.index,
623                                L2OUTPUT_N_FEAT,
624                                l2output_get_feat_names (),
625                                mp->l2_out_feat_next);
626
627   /* Initialize the output node mapping table */
628   vec_validate_init_empty (mp->output_node_index_vec, 100,
629                            L2OUTPUT_NEXT_DROP);
630
631   return 0;
632 }
633
634 VLIB_INIT_FUNCTION (l2output_init);
635
636
637 /** Create a mapping in the next node mapping table for the given sw_if_index. */
638 void
639 l2output_create_output_node_mapping (vlib_main_t * vlib_main,
640                                      vnet_main_t * vnet_main, u32 sw_if_index)
641 {
642   vnet_hw_interface_t *hw0 =
643     vnet_get_sup_hw_interface (vnet_main, sw_if_index);
644
645   /* dynamically create graph node arc  */
646   u32 next = vlib_node_add_next (vlib_main, l2output_node.index,
647                                  hw0->output_node_index);
648   l2output_main.output_node_index_vec[sw_if_index] = next;
649 }
650
651 /* Get a pointer to the config for the given interface */
652 l2_output_config_t *
653 l2output_intf_config (u32 sw_if_index)
654 {
655   l2output_main_t *mp = &l2output_main;
656
657   vec_validate (mp->configs, sw_if_index);
658   return vec_elt_at_index (mp->configs, sw_if_index);
659 }
660
661 /** Enable (or disable) the feature in the bitmap for the given interface. */
662 void
663 l2output_intf_bitmap_enable (u32 sw_if_index, u32 feature_bitmap, u32 enable)
664 {
665   l2output_main_t *mp = &l2output_main;
666   l2_output_config_t *config;
667
668   vec_validate (mp->configs, sw_if_index);
669   config = vec_elt_at_index (mp->configs, sw_if_index);
670
671   if (enable)
672     {
673       config->feature_bitmap |= feature_bitmap;
674     }
675   else
676     {
677       config->feature_bitmap &= ~feature_bitmap;
678     }
679 }
680
681 /*
682  * fd.io coding-style-patch-verification: ON
683  *
684  * Local Variables:
685  * eval: (c-set-style "gnu")
686  * End:
687  */