b3537a355cf860fc09a64bd815ef7b3e15d8331b
[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 vlib_node_registration_t l2output_node;
199
200 static_always_inline uword
201 l2output_node_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
202                       vlib_frame_t * frame, int do_trace)
203 {
204   u32 n_left_from, *from, *to_next;
205   l2output_next_t next_index;
206   l2output_main_t *msm = &l2output_main;
207   u32 cached_sw_if_index;
208   u32 cached_next_index;
209
210   /* Invalidate cache */
211   cached_sw_if_index = ~0;
212   cached_next_index = ~0;       /* warning be gone */
213
214   from = vlib_frame_vector_args (frame);
215   n_left_from = frame->n_vectors;       /* number of packets to process */
216   next_index = node->cached_next_index;
217
218   while (n_left_from > 0)
219     {
220       u32 n_left_to_next;
221
222       /* get space to enqueue frame to graph node "next_index" */
223       vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
224
225       while (n_left_from >= 8 && n_left_to_next >= 4)
226         {
227           u32 bi0, bi1, bi2, bi3;
228           vlib_buffer_t *b0, *b1, *b2, *b3;
229           u32 next0, next1, next2, next3;
230           u32 sw_if_index0, sw_if_index1, sw_if_index2, sw_if_index3;
231           ethernet_header_t *h0, *h1, *h2, *h3;
232           l2_output_config_t *config0, *config1, *config2, *config3;
233           u32 feature_bitmap0, feature_bitmap1;
234           u32 feature_bitmap2, feature_bitmap3;
235
236           /* Prefetch next iteration. */
237           {
238             vlib_buffer_t *p4, *p5, *p6, *p7;
239
240             p4 = vlib_get_buffer (vm, from[4]);
241             p5 = vlib_get_buffer (vm, from[5]);
242             p6 = vlib_get_buffer (vm, from[6]);
243             p7 = vlib_get_buffer (vm, from[7]);
244
245             /* Prefetch the buffer header for the N+2 loop iteration */
246             vlib_prefetch_buffer_header (p4, LOAD);
247             vlib_prefetch_buffer_header (p5, LOAD);
248             vlib_prefetch_buffer_header (p6, LOAD);
249             vlib_prefetch_buffer_header (p7, LOAD);
250           }
251
252           /* speculatively enqueue b0 and b1 to the current next frame */
253           /* bi is "buffer index", b is pointer to the buffer */
254           to_next[0] = bi0 = from[0];
255           to_next[1] = bi1 = from[1];
256           to_next[2] = bi2 = from[2];
257           to_next[3] = bi3 = from[3];
258           from += 4;
259           to_next += 4;
260           n_left_from -= 4;
261           n_left_to_next -= 4;
262
263           b0 = vlib_get_buffer (vm, bi0);
264           b1 = vlib_get_buffer (vm, bi1);
265           b2 = vlib_get_buffer (vm, bi2);
266           b3 = vlib_get_buffer (vm, bi3);
267
268           /* TX interface handles */
269           sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_TX];
270           sw_if_index1 = vnet_buffer (b1)->sw_if_index[VLIB_TX];
271           sw_if_index2 = vnet_buffer (b2)->sw_if_index[VLIB_TX];
272           sw_if_index3 = vnet_buffer (b3)->sw_if_index[VLIB_TX];
273
274           vlib_node_increment_counter (vm, l2output_node.index,
275                                        L2OUTPUT_ERROR_L2OUTPUT, 4);
276
277           /* Get config for the output interface */
278           config0 = vec_elt_at_index (msm->configs, sw_if_index0);
279           config1 = vec_elt_at_index (msm->configs, sw_if_index1);
280           config2 = vec_elt_at_index (msm->configs, sw_if_index2);
281           config3 = vec_elt_at_index (msm->configs, sw_if_index3);
282
283           /*
284            * Get features from the config
285            * TODO: mask out any non-applicable features
286            */
287           feature_bitmap0 = config0->feature_bitmap;
288           feature_bitmap1 = config1->feature_bitmap;
289           feature_bitmap2 = config2->feature_bitmap;
290           feature_bitmap3 = config3->feature_bitmap;
291
292           /* Determine next node */
293           l2_output_dispatch (b0, node, &cached_sw_if_index,
294                               &cached_next_index, sw_if_index0,
295                               feature_bitmap0, &next0);
296           l2_output_dispatch (b1, node, &cached_sw_if_index,
297                               &cached_next_index, sw_if_index1,
298                               feature_bitmap1, &next1);
299           l2_output_dispatch (b2, node, &cached_sw_if_index,
300                               &cached_next_index, sw_if_index2,
301                               feature_bitmap2, &next2);
302           l2_output_dispatch (b3, node, &cached_sw_if_index,
303                               &cached_next_index, sw_if_index3,
304                               feature_bitmap3, &next3);
305
306           l2output_vtr (node, config0, feature_bitmap0, b0, &next0);
307           l2output_vtr (node, config1, feature_bitmap1, b1, &next1);
308           l2output_vtr (node, config2, feature_bitmap2, b2, &next2);
309           l2output_vtr (node, config3, feature_bitmap3, b3, &next3);
310
311           if (do_trace)
312             {
313               h0 = vlib_buffer_get_current (b0);
314               h1 = vlib_buffer_get_current (b1);
315               h2 = vlib_buffer_get_current (b2);
316               h3 = vlib_buffer_get_current (b3);
317               if (b0->flags & VLIB_BUFFER_IS_TRACED)
318                 {
319                   l2output_trace_t *t =
320                     vlib_add_trace (vm, node, b0, sizeof (*t));
321                   t->sw_if_index = sw_if_index0;
322                   clib_memcpy (t->src, h0->src_address, 6);
323                   clib_memcpy (t->dst, h0->dst_address, 6);
324                   clib_memcpy (t->raw, &h0->type, sizeof (t->raw));
325                 }
326               if (b1->flags & VLIB_BUFFER_IS_TRACED)
327                 {
328                   l2output_trace_t *t =
329                     vlib_add_trace (vm, node, b1, sizeof (*t));
330                   t->sw_if_index = sw_if_index1;
331                   clib_memcpy (t->src, h1->src_address, 6);
332                   clib_memcpy (t->dst, h1->dst_address, 6);
333                   clib_memcpy (t->raw, &h1->type, sizeof (t->raw));
334                 }
335               if (b2->flags & VLIB_BUFFER_IS_TRACED)
336                 {
337                   l2output_trace_t *t =
338                     vlib_add_trace (vm, node, b2, sizeof (*t));
339                   t->sw_if_index = sw_if_index2;
340                   clib_memcpy (t->src, h2->src_address, 6);
341                   clib_memcpy (t->dst, h2->dst_address, 6);
342                   clib_memcpy (t->raw, &h2->type, sizeof (t->raw));
343                 }
344               if (b3->flags & VLIB_BUFFER_IS_TRACED)
345                 {
346                   l2output_trace_t *t =
347                     vlib_add_trace (vm, node, b3, sizeof (*t));
348                   t->sw_if_index = sw_if_index3;
349                   clib_memcpy (t->src, h3->src_address, 6);
350                   clib_memcpy (t->dst, h3->dst_address, 6);
351                   clib_memcpy (t->raw, &h3->type, sizeof (t->raw));
352                 }
353             }
354
355           /*
356            * Perform the split horizon check
357            * The check can only fail for non-zero shg's
358            */
359           if (PREDICT_FALSE (config0->shg + config1->shg +
360                              config2->shg + config3->shg))
361             {
362               /* one of the checks might fail, check both */
363               if (split_horizon_violation
364                   (config0->shg, vnet_buffer (b0)->l2.shg))
365                 {
366                   next0 = L2OUTPUT_NEXT_DROP;
367                   b0->error = node->errors[L2OUTPUT_ERROR_SHG_DROP];
368                 }
369               if (split_horizon_violation
370                   (config1->shg, vnet_buffer (b1)->l2.shg))
371                 {
372                   next1 = L2OUTPUT_NEXT_DROP;
373                   b1->error = node->errors[L2OUTPUT_ERROR_SHG_DROP];
374                 }
375               if (split_horizon_violation
376                   (config2->shg, vnet_buffer (b2)->l2.shg))
377                 {
378                   next2 = L2OUTPUT_NEXT_DROP;
379                   b2->error = node->errors[L2OUTPUT_ERROR_SHG_DROP];
380                 }
381               if (split_horizon_violation
382                   (config3->shg, vnet_buffer (b3)->l2.shg))
383                 {
384                   next3 = L2OUTPUT_NEXT_DROP;
385                   b3->error = node->errors[L2OUTPUT_ERROR_SHG_DROP];
386                 }
387             }
388
389           /* verify speculative enqueues, maybe switch current next frame */
390           /* if next0==next1==next_index then nothing special needs to be done */
391           vlib_validate_buffer_enqueue_x4 (vm, node, next_index,
392                                            to_next, n_left_to_next,
393                                            bi0, bi1, bi2, bi3,
394                                            next0, next1, next2, next3);
395         }
396
397       while (n_left_from > 0 && n_left_to_next > 0)
398         {
399           u32 bi0;
400           vlib_buffer_t *b0;
401           u32 next0;
402           u32 sw_if_index0;
403           ethernet_header_t *h0;
404           l2_output_config_t *config0;
405           u32 feature_bitmap0;
406
407           /* speculatively enqueue b0 to the current next frame */
408           bi0 = from[0];
409           to_next[0] = bi0;
410           from += 1;
411           to_next += 1;
412           n_left_from -= 1;
413           n_left_to_next -= 1;
414
415           b0 = vlib_get_buffer (vm, bi0);
416
417           sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_TX];
418
419           vlib_node_increment_counter (vm, l2output_node.index,
420                                        L2OUTPUT_ERROR_L2OUTPUT, 1);
421
422           /* Get config for the output interface */
423           config0 = vec_elt_at_index (msm->configs, sw_if_index0);
424
425           /*
426            * Get features from the config
427            * TODO: mask out any non-applicable features
428            */
429           feature_bitmap0 = config0->feature_bitmap;
430
431           /* Determine next node */
432           l2_output_dispatch (b0, node, &cached_sw_if_index,
433                               &cached_next_index, sw_if_index0,
434                               feature_bitmap0, &next0);
435
436           l2output_vtr (node, config0, feature_bitmap0, b0, &next0);
437
438           if (do_trace && PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
439             {
440               l2output_trace_t *t =
441                 vlib_add_trace (vm, node, b0, sizeof (*t));
442               t->sw_if_index = sw_if_index0;
443               h0 = vlib_buffer_get_current (b0);
444               clib_memcpy (t->src, h0->src_address, 6);
445               clib_memcpy (t->dst, h0->dst_address, 6);
446               clib_memcpy (t->raw, &h0->type, sizeof (t->raw));
447             }
448
449           /* Perform the split horizon check */
450           if (PREDICT_FALSE
451               (split_horizon_violation
452                (config0->shg, vnet_buffer (b0)->l2.shg)))
453             {
454               next0 = L2OUTPUT_NEXT_DROP;
455               b0->error = node->errors[L2OUTPUT_ERROR_SHG_DROP];
456             }
457
458           /* verify speculative enqueue, maybe switch current next frame */
459           vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
460                                            to_next, n_left_to_next,
461                                            bi0, next0);
462         }
463
464       vlib_put_next_frame (vm, node, next_index, n_left_to_next);
465     }
466
467   return frame->n_vectors;
468 }
469
470 static uword
471 l2output_node_fn (vlib_main_t * vm,
472                   vlib_node_runtime_t * node, vlib_frame_t * frame)
473 {
474   if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)))
475     return l2output_node_inline (vm, node, frame, 1 /* do_trace */ );
476   return l2output_node_inline (vm, node, frame, 0 /* do_trace */ );
477 }
478
479 /* *INDENT-OFF* */
480 VLIB_REGISTER_NODE (l2output_node,static) = {
481   .function = l2output_node_fn,
482   .name = "l2-output",
483   .vector_size = sizeof (u32),
484   .format_trace = format_l2output_trace,
485   .type = VLIB_NODE_TYPE_INTERNAL,
486
487   .n_errors = ARRAY_LEN(l2output_error_strings),
488   .error_strings = l2output_error_strings,
489
490   .n_next_nodes = L2OUTPUT_N_NEXT,
491
492   /* edit / add dispositions here */
493   .next_nodes = {
494         [L2OUTPUT_NEXT_DROP] = "error-drop",
495         [L2OUTPUT_NEXT_BAD_INTF] = "l2-output-bad-intf",
496   },
497 };
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 /* *INDENT-ON* */
605
606
607 VLIB_NODE_FUNCTION_MULTIARCH (l2output_node, l2output_node_fn)
608      clib_error_t *l2output_init (vlib_main_t * vm)
609 {
610   l2output_main_t *mp = &l2output_main;
611
612   mp->vlib_main = vm;
613   mp->vnet_main = vnet_get_main ();
614
615   /* Create the config vector */
616   vec_validate (mp->configs, 100);
617   /* Until we hook up the CLI config, just create 100 sw interface entries  and zero them */
618
619   /* Initialize the feature next-node indexes */
620   feat_bitmap_init_next_nodes (vm,
621                                l2output_node.index,
622                                L2OUTPUT_N_FEAT,
623                                l2output_get_feat_names (),
624                                mp->l2_out_feat_next);
625
626   /* Initialize the output node mapping table */
627   vec_validate_init_empty (mp->output_node_index_vec, 100,
628                            L2OUTPUT_NEXT_DROP);
629
630   return 0;
631 }
632
633 VLIB_INIT_FUNCTION (l2output_init);
634
635
636 /** Create a mapping in the next node mapping table for the given sw_if_index. */
637 void
638 l2output_create_output_node_mapping (vlib_main_t * vlib_main,
639                                      vnet_main_t * vnet_main, u32 sw_if_index)
640 {
641   vnet_hw_interface_t *hw0 =
642     vnet_get_sup_hw_interface (vnet_main, sw_if_index);
643
644   /* dynamically create graph node arc  */
645   u32 next = vlib_node_add_next (vlib_main, l2output_node.index,
646                                  hw0->output_node_index);
647   l2output_main.output_node_index_vec[sw_if_index] = next;
648 }
649
650 /* Get a pointer to the config for the given interface */
651 l2_output_config_t *
652 l2output_intf_config (u32 sw_if_index)
653 {
654   l2output_main_t *mp = &l2output_main;
655
656   vec_validate (mp->configs, sw_if_index);
657   return vec_elt_at_index (mp->configs, sw_if_index);
658 }
659
660 /** Enable (or disable) the feature in the bitmap for the given interface. */
661 void
662 l2output_intf_bitmap_enable (u32 sw_if_index, u32 feature_bitmap, u32 enable)
663 {
664   l2output_main_t *mp = &l2output_main;
665   l2_output_config_t *config;
666
667   vec_validate (mp->configs, sw_if_index);
668   config = vec_elt_at_index (mp->configs, sw_if_index);
669
670   if (enable)
671     {
672       config->feature_bitmap |= feature_bitmap;
673     }
674   else
675     {
676       config->feature_bitmap &= ~feature_bitmap;
677     }
678 }
679
680 /*
681  * fd.io coding-style-patch-verification: ON
682  *
683  * Local Variables:
684  * eval: (c-set-style "gnu")
685  * End:
686  */