FD.io VPP  v16.12-rc0-308-g931be3a
Vector Packet Processing
l2_input.c
Go to the documentation of this file.
1 /*
2  * l2_input.c : layer 2 input 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 <vnet/ethernet/packet.h>
23 #include <vnet/ip/ip_packet.h>
24 #include <vnet/ip/ip4_packet.h>
25 #include <vnet/ip/ip6_packet.h>
26 #include <vlib/cli.h>
27 #include <vnet/l2/l2_input.h>
28 #include <vnet/l2/l2_output.h>
29 #include <vnet/l2/feat_bitmap.h>
30 #include <vnet/l2/l2_bvi.h>
31 #include <vnet/l2/l2_fib.h>
32 
33 #include <vppinfra/error.h>
34 #include <vppinfra/hash.h>
35 #include <vppinfra/cache.h>
36 
37 /**
38  * @file
39  * @brief Interface Input Mode (Layer 2 Cross-Connect or Bridge / Layer 3).
40  *
41  * This file contains the CLI Commands that modify the input mode of an
42  * interface. For interfaces in a Layer 2 cross-connect, all packets
43  * received on one interface will be transmitted to the other. For
44  * interfaces in a bridge-domain, packets will be forwarded to other
45  * interfaces in the same bridge-domain based on destination mac address.
46  * For interfaces in Layer 3 mode, the packets will be routed.
47  */
48 
49 /* Feature graph node names */
50 static char *l2input_feat_names[] = {
51 #define _(sym,name) name,
53 #undef _
54 };
55 
56 char **
58 {
59  return l2input_feat_names;
60 }
61 
62 
63 typedef struct
64 {
65  /* per-pkt trace data */
66  u8 src[6];
67  u8 dst[6];
71 
72 /* packet trace format function */
73 static u8 *
74 format_l2input_trace (u8 * s, va_list * args)
75 {
76  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
77  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
78  l2input_trace_t *t = va_arg (*args, l2input_trace_t *);
79 
80  s = format (s, "l2-input: sw_if_index %d dst %U src %U",
81  t->sw_if_index,
84  return s;
85 }
86 
88 
89 #define foreach_l2input_error \
90 _(L2INPUT, "L2 input packets") \
91 _(DROP, "L2 input drops")
92 
93 typedef enum
94 {
95 #define _(sym,str) L2INPUT_ERROR_##sym,
97 #undef _
100 
101 static char *l2input_error_strings[] = {
102 #define _(sym,string) string,
104 #undef _
105 };
106 
107 typedef enum
108 { /* */
114 
115 
118  vlib_node_runtime_t * node,
119  u32 cpu_index,
120  l2input_main_t * msm, vlib_buffer_t * b0, u32 * next0)
121 {
122  /*
123  * Load L2 input feature struct
124  * Load bridge domain struct
125  * Parse ethernet header to determine unicast/mcast/broadcast
126  * take L2 input stat
127  * classify packet as IP/UDP/TCP, control, other
128  * mask feature bitmap
129  * go to first node in bitmap
130  * Later: optimize VTM
131  *
132  * For L2XC,
133  * set tx sw-if-handle
134  */
135 
136  u8 mcast_dmac;
137  __attribute__ ((unused)) u8 l2bcast;
138  __attribute__ ((unused)) u8 l2mcast;
139  __attribute__ ((unused)) u8 l2_stat_kind;
140  u16 ethertype;
141  u8 protocol;
142  l2_input_config_t *config;
143  l2_bridge_domain_t *bd_config;
144  u16 bd_index0;
145  u32 feature_bitmap;
146  u32 feat_mask;
147  ethernet_header_t *h0;
148  u8 *l3h0;
149  u32 sw_if_index0;
150 
151 #define get_u32(addr) ( *((u32 *)(addr)) )
152 #define get_u16(addr) ( *((u16 *)(addr)) )
153 #define STATS_IF_LAYER2_UCAST_INPUT_CNT 0
154 #define STATS_IF_LAYER2_MCAST_INPUT_CNT 1
155 #define STATS_IF_LAYER2_BCAST_INPUT_CNT 2
156 
157  sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
158 
159  h0 = vlib_buffer_get_current (b0);
160  l3h0 = (u8 *) h0 + vnet_buffer (b0)->l2.l2_len;
161 
162  /*
163  * Determine L3 packet type. Only need to check the common types.
164  * Used to filter out features that don't apply to common packets.
165  */
166  ethertype = clib_net_to_host_u16 (get_u16 (l3h0 - 2));
167  if (ethertype == ETHERNET_TYPE_IP4)
168  {
169  protocol = ((ip4_header_t *) l3h0)->protocol;
170  if ((protocol == IP_PROTOCOL_UDP) || (protocol == IP_PROTOCOL_TCP))
171  {
172  feat_mask = IP_UDP_TCP_FEAT_MASK;
173  }
174  else
175  {
176  feat_mask = IP4_FEAT_MASK;
177  }
178  }
179  else if (ethertype == ETHERNET_TYPE_IP6)
180  {
181  protocol = ((ip6_header_t *) l3h0)->protocol;
182  /* Don't bother checking for extension headers for now */
183  if ((protocol == IP_PROTOCOL_UDP) || (protocol == IP_PROTOCOL_TCP))
184  {
185  feat_mask = IP_UDP_TCP_FEAT_MASK;
186  }
187  else
188  {
189  feat_mask = IP6_FEAT_MASK;
190  }
191  }
192  else if (ethertype == ETHERNET_TYPE_MPLS_UNICAST)
193  {
194  feat_mask = IP6_FEAT_MASK;
195  }
196  else
197  {
198  /* allow all features */
199  feat_mask = ~0;
200  }
201 
202  /* determine layer2 kind for stat and mask */
203  mcast_dmac = ethernet_address_cast (h0->dst_address);
204  l2bcast = 0;
205  l2mcast = 0;
206  l2_stat_kind = STATS_IF_LAYER2_UCAST_INPUT_CNT;
207  if (PREDICT_FALSE (mcast_dmac))
208  {
209  u32 *dsthi = (u32 *) & h0->dst_address[0];
210  u32 *dstlo = (u32 *) & h0->dst_address[2];
211  protocol = ((ip6_header_t *) l3h0)->protocol;
212 
213  /* Disable bridge forwarding (flooding will execute instead if not xconnect) */
214  feat_mask &= ~(L2INPUT_FEAT_FWD | L2INPUT_FEAT_UU_FLOOD);
215 
216  /* Disable ARP-term for non-ARP and non-ICMP6 packet */
217  if (ethertype != ETHERNET_TYPE_ARP &&
218  (ethertype != ETHERNET_TYPE_IP6 || protocol != IP_PROTOCOL_ICMP6))
219  feat_mask &= ~(L2INPUT_FEAT_ARP_TERM);
220 
221  /* dest mac is multicast or broadcast */
222  if ((*dstlo == 0xFFFFFFFF) && (*dsthi == 0xFFFFFFFF))
223  {
224  /* dest mac == FF:FF:FF:FF:FF:FF */
225  l2_stat_kind = STATS_IF_LAYER2_BCAST_INPUT_CNT;
226  l2bcast = 1;
227  }
228  else
229  {
230  l2_stat_kind = STATS_IF_LAYER2_MCAST_INPUT_CNT;
231  l2mcast = 1;
232  }
233  }
234  /* TODO: take l2 stat */
235 
236  /* Get config for the input interface */
237  config = vec_elt_at_index (msm->configs, sw_if_index0);
238 
239  /* Save split horizon group */
240  vnet_buffer (b0)->l2.shg = config->shg;
241 
242  if (config->xconnect)
243  {
244  /* Set the output interface */
245  vnet_buffer (b0)->sw_if_index[VLIB_TX] = config->output_sw_if_index;
246 
247  }
248  else
249  {
250  /*
251  * Check for from-BVI processing - set SHG of unicast packets from BVI
252  * to 0 so it is not dropped for VXLAN tunnels or other ports with the
253  * same SHG as that of the BVI.
254  */
255  if (PREDICT_FALSE (vnet_buffer (b0)->sw_if_index[VLIB_TX] == L2INPUT_BVI
256  && !mcast_dmac))
257  vnet_buffer (b0)->l2.shg = 0;
258 
259  /* Do bridge-domain processing */
260  bd_index0 = config->bd_index;
261  /* save BD ID for next feature graph nodes */
262  vnet_buffer (b0)->l2.bd_index = bd_index0;
263 
264  /* Get config for the bridge domain interface */
265  bd_config = vec_elt_at_index (msm->bd_configs, bd_index0);
266 
267  /*
268  * Process bridge domain feature enables.
269  * To perform learning/flooding/forwarding, the corresponding bit
270  * must be enabled in both the input interface config and in the
271  * bridge domain config. In the bd_bitmap, bits for features other
272  * than learning/flooding/forwarding should always be set.
273  */
274  feat_mask = feat_mask & bd_config->feature_bitmap;
275  }
276 
277  /* mask out features from bitmap using packet type and bd config */
278  feature_bitmap = config->feature_bitmap & feat_mask;
279 
280  /* save for next feature graph nodes */
281  vnet_buffer (b0)->l2.feature_bitmap = feature_bitmap;
282 
283  /* Determine the next node */
285  feature_bitmap);
286 }
287 
288 
289 static uword
291  vlib_node_runtime_t * node, vlib_frame_t * frame)
292 {
293  u32 n_left_from, *from, *to_next;
294  l2input_next_t next_index;
296  vlib_node_t *n = vlib_get_node (vm, l2input_node.index);
297  u32 node_counter_base_index = n->error_heap_index;
298  vlib_error_main_t *em = &vm->error_main;
299  u32 cpu_index = os_get_cpu_number ();
300 
301  from = vlib_frame_vector_args (frame);
302  n_left_from = frame->n_vectors; /* number of packets to process */
303  next_index = node->cached_next_index;
304 
305  while (n_left_from > 0)
306  {
307  u32 n_left_to_next;
308 
309  /* get space to enqueue frame to graph node "next_index" */
310  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
311 
312  while (n_left_from >= 6 && n_left_to_next >= 2)
313  {
314  u32 bi0, bi1;
315  vlib_buffer_t *b0, *b1;
316  u32 next0, next1;
317  u32 sw_if_index0, sw_if_index1;
318 
319  /* Prefetch next iteration. */
320  {
321  vlib_buffer_t *p2, *p3, *p4, *p5;
322  u32 sw_if_index2, sw_if_index3;
323 
324  p2 = vlib_get_buffer (vm, from[2]);
325  p3 = vlib_get_buffer (vm, from[3]);
326  p4 = vlib_get_buffer (vm, from[4]);
327  p5 = vlib_get_buffer (vm, from[5]);
328 
329  /* Prefetch the buffer header and packet for the N+2 loop iteration */
330  vlib_prefetch_buffer_header (p4, LOAD);
331  vlib_prefetch_buffer_header (p5, LOAD);
332 
335 
336  /*
337  * Prefetch the input config for the N+1 loop iteration
338  * This depends on the buffer header above
339  */
340  sw_if_index2 = vnet_buffer (p2)->sw_if_index[VLIB_RX];
341  sw_if_index3 = vnet_buffer (p3)->sw_if_index[VLIB_RX];
342  CLIB_PREFETCH (&msm->configs[sw_if_index2], CLIB_CACHE_LINE_BYTES,
343  LOAD);
344  CLIB_PREFETCH (&msm->configs[sw_if_index3], CLIB_CACHE_LINE_BYTES,
345  LOAD);
346 
347  /*
348  * Don't bother prefetching the bridge-domain config (which
349  * depends on the input config above). Only a small number of
350  * bridge domains are expected. Plus the structure is small
351  * and several fit in a cache line.
352  */
353  }
354 
355  /* speculatively enqueue b0 and b1 to the current next frame */
356  /* bi is "buffer index", b is pointer to the buffer */
357  to_next[0] = bi0 = from[0];
358  to_next[1] = bi1 = from[1];
359  from += 2;
360  to_next += 2;
361  n_left_from -= 2;
362  n_left_to_next -= 2;
363 
364  b0 = vlib_get_buffer (vm, bi0);
365  b1 = vlib_get_buffer (vm, bi1);
366 
367  if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)))
368  {
369  /* RX interface handles */
370  sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
371  sw_if_index1 = vnet_buffer (b1)->sw_if_index[VLIB_RX];
372 
373  if (b0->flags & VLIB_BUFFER_IS_TRACED)
374  {
376  l2input_trace_t *t =
377  vlib_add_trace (vm, node, b0, sizeof (*t));
378  t->sw_if_index = sw_if_index0;
379  clib_memcpy (t->src, h0->src_address, 6);
380  clib_memcpy (t->dst, h0->dst_address, 6);
381  }
382  if (b1->flags & VLIB_BUFFER_IS_TRACED)
383  {
385  l2input_trace_t *t =
386  vlib_add_trace (vm, node, b1, sizeof (*t));
387  t->sw_if_index = sw_if_index1;
388  clib_memcpy (t->src, h1->src_address, 6);
389  clib_memcpy (t->dst, h1->dst_address, 6);
390  }
391  }
392 
393  em->counters[node_counter_base_index + L2INPUT_ERROR_L2INPUT] += 2;
394 
395  classify_and_dispatch (vm, node, cpu_index, msm, b0, &next0);
396 
397  classify_and_dispatch (vm, node, cpu_index, msm, b1, &next1);
398 
399  /* verify speculative enqueues, maybe switch current next frame */
400  /* if next0==next1==next_index then nothing special needs to be done */
401  vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
402  to_next, n_left_to_next,
403  bi0, bi1, next0, next1);
404  }
405 
406  while (n_left_from > 0 && n_left_to_next > 0)
407  {
408  u32 bi0;
409  vlib_buffer_t *b0;
410  u32 next0;
411  u32 sw_if_index0;
412 
413  /* speculatively enqueue b0 to the current next frame */
414  bi0 = from[0];
415  to_next[0] = bi0;
416  from += 1;
417  to_next += 1;
418  n_left_from -= 1;
419  n_left_to_next -= 1;
420 
421  b0 = vlib_get_buffer (vm, bi0);
422 
424  && (b0->flags & VLIB_BUFFER_IS_TRACED)))
425  {
427  l2input_trace_t *t = vlib_add_trace (vm, node, b0, sizeof (*t));
428  sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
429  t->sw_if_index = sw_if_index0;
430  clib_memcpy (t->src, h0->src_address, 6);
431  clib_memcpy (t->dst, h0->dst_address, 6);
432  }
433 
434  em->counters[node_counter_base_index + L2INPUT_ERROR_L2INPUT] += 1;
435 
436  classify_and_dispatch (vm, node, cpu_index, msm, b0, &next0);
437 
438  /* verify speculative enqueue, maybe switch current next frame */
439  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
440  to_next, n_left_to_next,
441  bi0, next0);
442  }
443 
444  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
445  }
446 
447  return frame->n_vectors;
448 }
449 
450 
451 /* *INDENT-OFF* */
453  .function = l2input_node_fn,
454  .name = "l2-input",
455  .vector_size = sizeof (u32),
456  .format_trace = format_l2input_trace,
457  .format_buffer = format_ethernet_header_with_length,
459 
460  .n_errors = ARRAY_LEN(l2input_error_strings),
461  .error_strings = l2input_error_strings,
462 
463  .n_next_nodes = L2INPUT_N_NEXT,
464 
465  /* edit / add dispositions here */
466  .next_nodes = {
467  [L2INPUT_NEXT_LEARN] = "l2-learn",
468  [L2INPUT_NEXT_FWD] = "l2-fwd",
469  [L2INPUT_NEXT_DROP] = "error-drop",
470  },
471 };
472 /* *INDENT-ON* */
473 
476 {
478 
479  mp->vlib_main = vm;
480  mp->vnet_main = vnet_get_main ();
481 
482  /* Get packets RX'd from L2 interfaces */
484 
485  /* Create the config vector */
486  vec_validate (mp->configs, 100);
487  /* create 100 sw interface entries and zero them */
488 
489  /* Initialize the feature next-node indexes */
491  l2input_node.index,
495 
496  return 0;
497 }
498 
500 
501 
502 /** Get a pointer to the config for the given interface. */
505 {
507 
508  vec_validate (mp->configs, sw_if_index);
509  return vec_elt_at_index (mp->configs, sw_if_index);
510 }
511 
512 /** Enable (or disable) the feature in the bitmap for the given interface. */
513 u32
514 l2input_intf_bitmap_enable (u32 sw_if_index, u32 feature_bitmap, u32 enable)
515 {
517  l2_input_config_t *config;
518 
519  vec_validate (mp->configs, sw_if_index);
520  config = vec_elt_at_index (mp->configs, sw_if_index);
521 
522  if (enable)
523  {
524  config->feature_bitmap |= feature_bitmap;
525  }
526  else
527  {
528  config->feature_bitmap &= ~feature_bitmap;
529  }
530 
531  return config->feature_bitmap;
532 }
533 
534 u32
535 l2input_set_bridge_features (u32 bd_index, u32 feat_mask, u32 feat_value)
536 {
537  l2_bridge_domain_t *bd_config;
538  vec_validate (l2input_main.bd_configs, bd_index);
539  bd_config = vec_elt_at_index (l2input_main.bd_configs, bd_index);
540  bd_validate (bd_config);
541  bd_config->feature_bitmap =
542  (bd_config->feature_bitmap & ~feat_mask) | feat_value;
543  return bd_config->feature_bitmap;
544 }
545 
546 /**
547  * Set the subinterface to run in l2 or l3 mode.
548  * For L3 mode, just the sw_if_index is specified.
549  * For bridged mode, the bd id and bvi flag are also specified.
550  * For xconnect mode, the peer sw_if_index is also specified.
551  * Return 0 if ok, or non-0 if there was an error.
552  */
553 
554 u32
555 set_int_l2_mode (vlib_main_t * vm, vnet_main_t * vnet_main, u32 mode, u32 sw_if_index, u32 bd_index, /* for bridged interface */
556  u32 bvi, /* the bridged interface is the BVI */
557  u32 shg, /* the bridged interface's split horizon group */
558  u32 xc_sw_if_index) /* peer interface for xconnect */
559 {
562  vnet_main_t *vnm = vnet_get_main ();
564  l2_output_config_t *out_config;
565  l2_input_config_t *config;
566  l2_bridge_domain_t *bd_config;
567  l2_flood_member_t member;
568  u64 mac;
569  i32 l2_if_adjust = 0;
570  u32 slot;
571 
572  hi = vnet_get_sup_hw_interface (vnet_main, sw_if_index);
573 
574  vec_validate (mp->configs, sw_if_index);
575  config = vec_elt_at_index (mp->configs, sw_if_index);
576 
577  if (config->bridge)
578  {
579  /* Interface is already in bridge mode. Undo the existing config. */
580  bd_config = vec_elt_at_index (mp->bd_configs, config->bd_index);
581 
582  /* remove interface from flood vector */
583  bd_remove_member (bd_config, sw_if_index);
584 
585  /* undo any BVI-related config */
586  if (bd_config->bvi_sw_if_index == sw_if_index)
587  {
588  bd_config->bvi_sw_if_index = ~0;
589  config->bvi = 0;
590 
591  /* delete the l2fib entry for the bvi interface */
592  mac = *((u64 *) hi->hw_address);
593  l2fib_del_entry (mac, config->bd_index);
594 
595  /* Make loop output node send packet back to ethernet-input node */
596  slot =
598  "ethernet-input",
601  }
602  l2_if_adjust--;
603  }
604  else if (config->xconnect)
605  {
606  l2_if_adjust--;
607  }
608 
609  /*
610  * Directs the l2 output path to work out the interface
611  * output next-arc itself. Needed when recycling a sw_if_index.
612  */
614  sw_if_index, ~0);
615  l2om->next_nodes.output_node_index_vec[sw_if_index] = ~0;
616 
617  /* Initialize the l2-input configuration for the interface */
618  if (mode == MODE_L3)
619  {
620  /* Set L2 config to BD index 0 so that if any packet accidentally
621  * came in on L2 path, it will be dropped in BD 0 */
622  config->xconnect = 0;
623  config->bridge = 0;
624  config->shg = 0;
625  config->bd_index = 0;
626  config->feature_bitmap = L2INPUT_FEAT_DROP;
627 
628  /* Make sure any L2-output packet to this interface now in L3 mode is
629  * dropped. This may happen if L2 FIB MAC entry is stale */
630  l2om->next_nodes.output_node_index_vec[sw_if_index] =
632  }
633  else if (mode == MODE_L2_CLASSIFY)
634  {
635  config->xconnect = 1;
636  config->bridge = 0;
637  config->output_sw_if_index = xc_sw_if_index;
638 
639  /* Make sure last-chance drop is configured */
640  config->feature_bitmap |=
641  L2INPUT_FEAT_DROP | L2INPUT_FEAT_INPUT_CLASSIFY;
642 
643  /* Make sure bridging features are disabled */
644  config->feature_bitmap &=
645  ~(L2INPUT_FEAT_LEARN | L2INPUT_FEAT_FWD | L2INPUT_FEAT_FLOOD);
646  shg = 0; /* not used in xconnect */
647 
648  /* Insure all packets go to ethernet-input */
649  ethernet_set_rx_redirect (vnet_main, hi, 1);
650  }
651  else
652  {
653 
654  if (mode == MODE_L2_BRIDGE)
655  {
656  /*
657  * Remove a check that the interface must be an Ethernet.
658  * Specifically so we can bridge to L3 tunnel interfaces.
659  * Here's the check:
660  * if (hi->hw_class_index != ethernet_hw_interface_class.index)
661  *
662  */
663  if (!hi)
664  return MODE_ERROR_ETH; /* non-ethernet */
665 
666  config->xconnect = 0;
667  config->bridge = 1;
668  config->bd_index = bd_index;
669 
670  /*
671  * Enable forwarding, flooding, learning and ARP termination by default
672  * (note that ARP term is disabled on BD feature bitmap by default)
673  */
674  config->feature_bitmap |= L2INPUT_FEAT_FWD | L2INPUT_FEAT_UU_FLOOD |
675  L2INPUT_FEAT_FLOOD | L2INPUT_FEAT_LEARN | L2INPUT_FEAT_ARP_TERM;
676 
677  /* Make sure last-chance drop is configured */
678  config->feature_bitmap |= L2INPUT_FEAT_DROP;
679 
680  /* Make sure xconnect is disabled */
681  config->feature_bitmap &= ~L2INPUT_FEAT_XCONNECT;
682 
683  /* Set up bridge domain */
684  vec_validate (mp->bd_configs, bd_index);
685  bd_config = vec_elt_at_index (mp->bd_configs, bd_index);
686  bd_validate (bd_config);
687 
688  /* TODO: think: add l2fib entry even for non-bvi interface? */
689 
690  /* Do BVI interface initializations */
691  if (bvi)
692  {
693  /* ensure BD has no bvi interface (or replace that one with this??) */
694  if (bd_config->bvi_sw_if_index != ~0)
695  {
696  return MODE_ERROR_BVI_DEF; /* bd already has a bvi interface */
697  }
698  bd_config->bvi_sw_if_index = sw_if_index;
699  config->bvi = 1;
700 
701  /* create the l2fib entry for the bvi interface */
702  mac = *((u64 *) hi->hw_address);
703  l2fib_add_entry (mac, bd_index, sw_if_index, 1, 0, 1); /* static + bvi */
704 
705  /* Disable learning by default. no use since l2fib entry is static. */
706  config->feature_bitmap &= ~L2INPUT_FEAT_LEARN;
707 
708  /* Make loop output node send packet to l2-input node */
709  slot =
711  "l2-input",
714  }
715 
716  /* Add interface to bridge-domain flood vector */
717  member.sw_if_index = sw_if_index;
719  member.shg = shg;
720  bd_add_member (bd_config, &member);
721 
722  }
723  else
724  {
725  config->xconnect = 1;
726  config->bridge = 0;
727  config->output_sw_if_index = xc_sw_if_index;
728 
729  /* Make sure last-chance drop is configured */
730  config->feature_bitmap |= L2INPUT_FEAT_DROP;
731 
732  /* Make sure bridging features are disabled */
733  config->feature_bitmap &=
734  ~(L2INPUT_FEAT_LEARN | L2INPUT_FEAT_FWD | L2INPUT_FEAT_FLOOD);
735 
736  config->feature_bitmap |= L2INPUT_FEAT_XCONNECT;
737  shg = 0; /* not used in xconnect */
738  }
739 
740  /* set up split-horizon group */
741  config->shg = shg;
742  out_config = l2output_intf_config (sw_if_index);
743  out_config->shg = shg;
744 
745  /*
746  * Test: remove this when non-IP features can be configured.
747  * Enable a non-IP feature to test IP feature masking
748  * config->feature_bitmap |= L2INPUT_FEAT_CTRL_PKT;
749  */
750 
751  l2_if_adjust++;
752  }
753 
754  /* Adjust count of L2 interfaces */
755  hi->l2_if_count += l2_if_adjust;
756 
758  {
759  if ((hi->l2_if_count == 1) && (l2_if_adjust == 1))
760  {
761  /* Just added first L2 interface on this port */
762 
763  /* Set promiscuous mode on the l2 interface */
764  ethernet_set_flags (vnet_main, hi->hw_if_index,
766 
767  /* ensure all packets go to ethernet-input */
768  ethernet_set_rx_redirect (vnet_main, hi, 1);
769 
770  }
771  else if ((hi->l2_if_count == 0) && (l2_if_adjust == -1))
772  {
773  /* Just removed only L2 subinterface on this port */
774 
775  /* Disable promiscuous mode on the l2 interface */
776  ethernet_set_flags (vnet_main, hi->hw_if_index, 0);
777 
778  /* Allow ip packets to go directly to ip4-input etc */
779  ethernet_set_rx_redirect (vnet_main, hi, 0);
780  }
781  }
782 
783  /* Set up the L2/L3 flag in the interface parsing tables */
784  ethernet_sw_interface_set_l2_mode (vnm, sw_if_index, (mode != MODE_L3));
785 
786  return 0;
787 }
788 
789 /**
790  * Set subinterface in bridging mode with a bridge-domain ID.
791  * The CLI format is:
792  * set interface l2 bridge <interface> <bd> [bvi] [split-horizon-group]
793  */
794 static clib_error_t *
796  unformat_input_t * input, vlib_cli_command_t * cmd)
797 {
798  vnet_main_t *vnm = vnet_get_main ();
799  clib_error_t *error = 0;
800  u32 bd_index, bd_id;
801  u32 sw_if_index;
802  u32 bvi;
803  u32 rc;
804  u32 shg;
805 
806  if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
807  {
808  error = clib_error_return (0, "unknown interface `%U'",
809  format_unformat_error, input);
810  goto done;
811  }
812 
813  if (!unformat (input, "%d", &bd_id))
814  {
815  error = clib_error_return (0, "expected bridge domain ID `%U'",
816  format_unformat_error, input);
817  goto done;
818  }
819 
820  bd_index = bd_find_or_add_bd_index (&bd_main, bd_id);
821 
822  /* optional bvi */
823  bvi = unformat (input, "bvi");
824 
825  /* optional split horizon group */
826  shg = 0;
827  (void) unformat (input, "%d", &shg);
828 
829  /* set the interface mode */
830  if ((rc =
831  set_int_l2_mode (vm, vnm, MODE_L2_BRIDGE, sw_if_index, bd_index, bvi,
832  shg, 0)))
833  {
834  if (rc == MODE_ERROR_ETH)
835  {
836  error = clib_error_return (0, "bridged interface must be ethernet",
837  format_unformat_error, input);
838  }
839  else if (rc == MODE_ERROR_BVI_DEF)
840  {
841  error =
842  clib_error_return (0, "bridge-domain already has a bvi interface",
843  format_unformat_error, input);
844  }
845  else
846  {
847  error = clib_error_return (0, "invalid configuration for interface",
848  format_unformat_error, input);
849  }
850  goto done;
851  }
852 
853 done:
854  return error;
855 }
856 
857 /*?
858  * Use this command put an interface into Layer 2 bridge domain. If a
859  * bridge-domain with the provided bridge-domain-id does not exist, it
860  * will be created. Interfaces in a bridge-domain forward packets to
861  * other interfaces in the same bridge-domain based on destination mac
862  * address. To remove an interface from a the Layer 2 bridge domain,
863  * put the interface in a different mode, for example Layer 3 mode.
864  *
865  * Optionally, an interface can be added to a Layer 2 bridge-domain as
866  * a Bridged Virtual Interface (bvi). Only one interface in a Layer 2
867  * bridge-domain can be a bvi.
868  *
869  * Optionally, a split-horizon group can also be specified. This defaults
870  * to 0 if not specified.
871  *
872  * @cliexpar
873  * Example of how to configure a Layer 2 bridge-domain with three
874  * interfaces (where 200 is the bridge-domain-id):
875  * @cliexcmd{set interface l2 bridge GigabitEthernet0/8/0.200 200}
876  * This interface is added a BVI interface:
877  * @cliexcmd{set interface l2 bridge GigabitEthernet0/9/0.200 200 bvi}
878  * This interface also has a split-horizon group of 1 specified:
879  * @cliexcmd{set interface l2 bridge GigabitEthernet0/a/0.200 200 1}
880  * Example of how to remove an interface from a Layer2 bridge-domain:
881  * @cliexcmd{set interface l3 GigabitEthernet0/a/0.200}
882 ?*/
883 /* *INDENT-OFF* */
884 VLIB_CLI_COMMAND (int_l2_bridge_cli, static) = {
885  .path = "set interface l2 bridge",
886  .short_help = "set interface l2 bridge <interface> <bridge-domain-id> [bvi] [shg]",
887  .function = int_l2_bridge,
888 };
889 /* *INDENT-ON* */
890 
891 /**
892  * Set subinterface in xconnect mode with another interface.
893  * The CLI format is:
894  * set interface l2 xconnect <interface> <peer interface>
895  */
896 static clib_error_t *
898  unformat_input_t * input, vlib_cli_command_t * cmd)
899 {
900  vnet_main_t *vnm = vnet_get_main ();
901  clib_error_t *error = 0;
902  u32 sw_if_index;
903  u32 xc_sw_if_index;
904 
905  if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
906  {
907  error = clib_error_return (0, "unknown interface `%U'",
908  format_unformat_error, input);
909  goto done;
910  }
911 
912  if (!unformat_user
913  (input, unformat_vnet_sw_interface, vnm, &xc_sw_if_index))
914  {
915  error = clib_error_return (0, "unknown peer interface `%U'",
916  format_unformat_error, input);
917  goto done;
918  }
919 
920  /* set the interface mode */
921  if (set_int_l2_mode
922  (vm, vnm, MODE_L2_XC, sw_if_index, 0, 0, 0, xc_sw_if_index))
923  {
924  error = clib_error_return (0, "invalid configuration for interface",
925  format_unformat_error, input);
926  goto done;
927  }
928 
929 done:
930  return error;
931 }
932 
933 /*?
934  * Use this command put an interface into Layer 2 cross-connect mode.
935  * Both interfaces must be in this mode for bi-directioal traffic. All
936  * packets received on one interface will be transmitted to the other.
937  * To remove the Layer 2 cross-connect, put the interface in a different
938  * mode, for example Layer 3 mode.
939  *
940  * @cliexpar
941  * Example of how to configure a Layer2 cross-connect between two interfaces:
942  * @cliexcmd{set interface l2 xconnect GigabitEthernet0/8/0.300 GigabitEthernet0/9/0.300}
943  * @cliexcmd{set interface l2 xconnect GigabitEthernet0/9/0.300 GigabitEthernet0/8/0.300}
944  * Example of how to remove a Layer2 cross-connect:
945  * @cliexcmd{set interface l3 GigabitEthernet0/8/0.300}
946  * @cliexcmd{set interface l3 GigabitEthernet0/9/0.300}
947 ?*/
948 /* *INDENT-OFF* */
949 VLIB_CLI_COMMAND (int_l2_xc_cli, static) = {
950  .path = "set interface l2 xconnect",
951  .short_help = "set interface l2 xconnect <interface> <peer interface>",
952  .function = int_l2_xc,
953 };
954 /* *INDENT-ON* */
955 
956 /**
957  * Set subinterface in L3 mode.
958  * The CLI format is:
959  * set interface l3 <interface>
960  */
961 static clib_error_t *
963 {
964  vnet_main_t *vnm = vnet_get_main ();
965  clib_error_t *error = 0;
966  u32 sw_if_index;
967 
968  if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
969  {
970  error = clib_error_return (0, "unknown interface `%U'",
971  format_unformat_error, input);
972  goto done;
973  }
974 
975  /* set the interface mode */
976  if (set_int_l2_mode (vm, vnm, MODE_L3, sw_if_index, 0, 0, 0, 0))
977  {
978  error = clib_error_return (0, "invalid configuration for interface",
979  format_unformat_error, input);
980  goto done;
981  }
982 
983 done:
984  return error;
985 }
986 
987 /*?
988  * Modify the packet processing mode of the interface to Layer 3, which
989  * implies packets will be routed. This is the default mode of an interface.
990  * Use this command to remove an interface from a Layer 2 cross-connect or a
991  * Layer 2 bridge.
992  *
993  * @cliexpar
994  * Example of how to set the mode of an interface to Layer 3:
995  * @cliexcmd{set interface l3 GigabitEthernet0/8/0.200}
996 ?*/
997 /* *INDENT-OFF* */
998  VLIB_CLI_COMMAND (int_l3_cli, static) = {
999  .path = "set interface l3",
1000  .short_help = "set interface l3 <interface>",
1001  .function = int_l3,
1002 };
1003 /* *INDENT-ON* */
1004 
1005 /**
1006  * Show interface mode.
1007  * The CLI format is:
1008  * show mode [<if-name1> <if-name2> ...]
1009  */
1010 static clib_error_t *
1012  unformat_input_t * input, vlib_cli_command_t * cmd)
1013 {
1014  vnet_main_t *vnm = vnet_get_main ();
1015  clib_error_t *error = 0;
1016  char *mode;
1017  u8 *args;
1019  vnet_sw_interface_t *si, *sis = 0;
1021  l2_input_config_t *config;
1022 
1023  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1024  {
1025  u32 sw_if_index;
1026 
1027  /* See if user wants to show specific interface */
1028  if (unformat
1029  (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
1030  {
1031  si = pool_elt_at_index (im->sw_interfaces, sw_if_index);
1032  vec_add1 (sis, si[0]);
1033  }
1034  else
1035  {
1036  error = clib_error_return (0, "unknown input `%U'",
1037  format_unformat_error, input);
1038  goto done;
1039  }
1040 
1041  }
1042 
1043  if (vec_len (sis) == 0) /* Get all interfaces */
1044  {
1045  /* Gather interfaces. */
1047  _vec_len (sis) = 0;
1048  /* *INDENT-OFF* */
1049  pool_foreach (si, im->sw_interfaces, ({ vec_add1 (sis, si[0]); }));
1050  /* *INDENT-ON* */
1051  }
1052 
1053  vec_foreach (si, sis)
1054  {
1055  vec_validate (mp->configs, si->sw_if_index);
1056  config = vec_elt_at_index (mp->configs, si->sw_if_index);
1057  if (config->bridge)
1058  {
1059  u32 bd_id;
1060  mode = "l2 bridge";
1061  bd_id = l2input_main.bd_configs[config->bd_index].bd_id;
1062 
1063  args = format (0, "bd_id %d%s%d", bd_id,
1064  config->bvi ? " bvi shg " : " shg ", config->shg);
1065  }
1066  else if (config->xconnect)
1067  {
1068  mode = "l2 xconnect";
1069  args = format (0, "%U",
1071  vnm, config->output_sw_if_index);
1072  }
1073  else
1074  {
1075  mode = "l3";
1076  args = format (0, " ");
1077  }
1078  vlib_cli_output (vm, "%s %U %v\n",
1079  mode,
1081  vnm, si->sw_if_index, args);
1082  vec_free (args);
1083  }
1084 
1085 done:
1086  vec_free (sis);
1087 
1088  return error;
1089 }
1090 
1091 /*?
1092  * Show the packet processing mode (Layer2 xcross-onnect, Layer 2 bridge,
1093  * Layer 3 routed) of all interfaces and sub-interfaces, or limit the
1094  * output to just the provided list of interfaces and sub-interfaces.
1095  * The output shows the mode, the interface, and if the interface is
1096  * a member of a bridge, the bridge-domain-id and the split horizen group (shg).
1097  *
1098  * @cliexpar
1099  * Example of displaying the mode of all interfaces:
1100  * @cliexstart{show mode}
1101  * l3 local0
1102  * l3 GigabitEthernet0/8/0
1103  * l3 GigabitEthernet0/9/0
1104  * l3 GigabitEthernet0/a/0
1105  * l2 bridge GigabitEthernet0/8/0.200 bd_id 200 shg 0
1106  * l2 bridge GigabitEthernet0/9/0.200 bd_id 200 shg 0
1107  * l2 bridge GigabitEthernet0/a/0.200 bd_id 200 shg 0
1108  * l2 xconnect GigabitEthernet0/8/0.300 GigabitEthernet0/9/0.300
1109  * l2 xconnect GigabitEthernet0/9/0.300 GigabitEthernet0/8/0.300
1110  * @cliexend
1111  * Example of displaying the mode of a seleted list of interfaces:
1112  * @cliexstart{show mode GigabitEthernet0/8/0 GigabitEthernet0/8/0.200}
1113  * l3 GigabitEthernet0/8/0
1114  * l2 bridge GigabitEthernet0/8/0.200 bd_id 200 shg 0
1115  * @cliexend
1116 ?*/
1117 /* *INDENT-OFF* */
1118 VLIB_CLI_COMMAND (show_l2_mode, static) = {
1119  .path = "show mode",
1120  .short_help = "show mode [<if-name1> <if-name2> ...]",
1121  .function = show_int_mode,
1122 };
1123 /* *INDENT-ON* */
1124 
1125 #define foreach_l2_init_function \
1126 _(feat_bitmap_drop_init) \
1127 _(l2fib_init) \
1128 _(l2_input_classify_init) \
1129 _(l2bd_init) \
1130 _(l2fwd_init) \
1131 _(l2_inacl_init) \
1132 _(l2input_init) \
1133 _(l2_vtr_init) \
1134 _(l2_invtr_init) \
1135 _(l2_efp_filter_init) \
1136 _(l2learn_init) \
1137 _(l2flood_init) \
1138 _(l2_outacl_init) \
1139 _(l2output_init) \
1140 _(l2_patch_init) \
1141 _(l2_xcrw_init)
1142 
1143 clib_error_t *
1145 {
1146  clib_error_t *error;
1147 
1148 #define _(a) do { \
1149  if ((error = vlib_call_init_function (vm, a))) return error; } \
1150 while (0);
1152 #undef _
1153  return 0;
1154 }
1155 
1157 
1158 /*
1159  * fd.io coding-style-patch-verification: ON
1160  *
1161  * Local Variables:
1162  * eval: (c-set-style "gnu")
1163  * End:
1164  */
void bd_validate(l2_bridge_domain_t *bd_config)
Init bridge domain if not done already.
Definition: l2_bd.c:50
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:396
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
Definition: main.c:457
static char * l2input_feat_names[]
Definition: l2_input.c:50
vmrglw vmrglh hi
static clib_error_t * int_l3(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Set subinterface in L3 mode.
Definition: l2_input.c:962
u32 error_heap_index
Definition: node.h:278
l2_input_config_t * configs
Definition: l2_input.h:66
#define L2_FLOOD_MEMBER_NORMAL
Definition: l2_bd.h:41
#define CLIB_UNUSED(x)
Definition: clib.h:79
uword unformat(unformat_input_t *i, char *fmt,...)
Definition: unformat.c:966
bad routing header type(not 4)") sr_error (NO_MORE_SEGMENTS
static vnet_hw_interface_t * vnet_get_sup_hw_interface(vnet_main_t *vnm, u32 sw_if_index)
u32 bvi_sw_if_index
Definition: l2_bd.h:65
vnet_interface_main_t interface_main
Definition: vnet.h:72
u32 l2input_set_bridge_features(u32 bd_index, u32 feat_mask, u32 feat_value)
Definition: l2_input.c:535
l2_input_config_t * l2input_intf_config(u32 sw_if_index)
Get a pointer to the config for the given interface.
Definition: l2_input.c:504
#define UNFORMAT_END_OF_INPUT
Definition: format.h:143
u8 src_address[6]
Definition: packet.h:54
u32 l2fib_del_entry(u64 mac, u32 bd_index)
Delete an entry from the l2fib.
Definition: l2_fib.c:596
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:482
vlib_node_registration_t l2input_node
(constructor) VLIB_REGISTER_NODE (l2input_node)
Definition: l2_input.c:452
#define STATS_IF_LAYER2_BCAST_INPUT_CNT
unformat_function_t unformat_vnet_sw_interface
#define STATS_IF_LAYER2_MCAST_INPUT_CNT
u32 bd_remove_member(l2_bridge_domain_t *bd_config, u32 sw_if_index)
Definition: l2_bd.c:147
#define L2_FLOOD_MEMBER_BVI
Definition: l2_bd.h:42
static clib_error_t * int_l2_bridge(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Set subinterface in bridging mode with a bridge-domain ID.
Definition: l2_input.c:795
l2_output_next_nodes_st next_nodes
Definition: l2_output.h:81
format_function_t format_vnet_sw_if_index_name
l2input_error_t
Definition: l2_input.c:93
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
#define static_always_inline
Definition: clib.h:85
u8 * format_ethernet_address(u8 *s, va_list *args)
Definition: format.c:44
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:348
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:111
static uword ethernet_address_cast(u8 *a)
Definition: packet.h:65
u32 output_sw_if_index
Definition: l2_input.h:35
#define MODE_L2_BRIDGE
Definition: l2_input.h:219
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:190
#define vec_new(T, N)
Create new vector of given type and length (unspecified alignment, no header).
Definition: vec.h:270
u8 dst_address[6]
Definition: packet.h:53
void bd_add_member(l2_bridge_domain_t *bd_config, l2_flood_member_t *member)
Definition: l2_bd.c:118
int i32
Definition: types.h:81
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
unsigned long u64
Definition: types.h:89
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:977
u32 set_int_l2_mode(vlib_main_t *vm, vnet_main_t *vnet_main, u32 mode, u32 sw_if_index, u32 bd_index, u32 bvi, u32 shg, u32 xc_sw_if_index)
Set the subinterface to run in l2 or l3 mode.
Definition: l2_input.c:555
void ethernet_set_rx_redirect(vnet_main_t *vnm, vnet_hw_interface_t *hi, u32 enable)
#define foreach_l2input_error
Definition: l2_input.c:89
l2_output_config_t * l2output_intf_config(u32 sw_if_index)
Get a pointer to the config for the given interface.
Definition: l2_output.c:698
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:369
vnet_main_t * vnet_main
Definition: l2_input.h:73
vlib_error_main_t error_main
Definition: main.h:124
uword os_get_cpu_number(void)
Definition: unix-misc.c:224
#define PREDICT_FALSE(x)
Definition: clib.h:97
vnet_main_t vnet_main
Definition: misc.c:43
l2output_main_t l2output_main
Definition: l2_output.c:43
#define vlib_validate_buffer_enqueue_x2(vm, node, next_index, to_next, n_left_to_next, bi0, bi1, next0, next1)
Finish enqueueing two buffers forward in the graph.
Definition: buffer_node.h:70
u32 feat_next_node_index[32]
Definition: l2_input.h:63
static u32 feat_bitmap_get_next_node_index(u32 *next_nodes, u32 bitmap)
Return the graph node index for the feature corresponding to the first set bit in the bitmap...
Definition: feat_bitmap.h:79
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
Definition: buffer_node.h:216
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
Definition: node_funcs.h:350
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:575
static clib_error_t * int_l2_xc(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Set subinterface in xconnect mode with another interface.
Definition: l2_input.c:897
#define L2INPUT_BVI
Definition: l2_input.h:90
vnet_hw_interface_class_t ethernet_hw_interface_class
u64 * counters
Definition: error.h:78
u8 * format_ethernet_header_with_length(u8 *s, va_list *args)
Definition: format.c:115
#define foreach_l2_init_function
Definition: l2_input.c:1125
u16 n_vectors
Definition: node.h:344
#define CLIB_PREFETCH(addr, size, type)
Definition: cache.h:82
static_always_inline void classify_and_dispatch(vlib_main_t *vm, vlib_node_runtime_t *node, u32 cpu_index, l2input_main_t *msm, vlib_buffer_t *b0, u32 *next0)
Definition: l2_input.c:117
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:300
static void feat_bitmap_init_next_nodes(vlib_main_t *vm, u32 node_index, u32 num_features, char **feat_names, u32 *next_nodes)
Initialize the feature next-node indexes of a graph node.
Definition: feat_bitmap.h:43
#define MODE_ERROR_ETH
Definition: l2_input.h:223
void ethernet_register_l2_input(vlib_main_t *vm, u32 node_index)
Definition: node.c:1211
#define clib_memcpy(a, b, c)
Definition: string.h:64
#define VNET_SIMULATED_ETHERNET_TX_NEXT_ETHERNET_INPUT
#define ETHERNET_INTERFACE_FLAG_ACCEPT_ALL
Definition: ethernet.h:113
#define ARRAY_LEN(x)
Definition: clib.h:59
#define IP6_FEAT_MASK
Definition: l2_input.h:184
void l2fib_add_entry(u64 mac, u32 bd_index, u32 sw_if_index, u32 static_mac, u32 filter_mac, u32 bvi_mac)
Add an entry to the l2fib.
Definition: l2_fib.c:298
char ** l2input_get_feat_names(void)
Return an array of strings containing graph node names of each feature.
Definition: l2_input.c:57
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:154
u16 cached_next_index
Definition: node.h:463
#define ASSERT(truth)
unsigned int u32
Definition: types.h:88
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
#define vnet_buffer(b)
Definition: buffer.h:333
#define IP_UDP_TCP_FEAT_MASK
Definition: l2_input.h:190
static clib_error_t * show_int_mode(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Show interface mode.
Definition: l2_input.c:1011
#define VLIB_NODE_FLAG_TRACE
Definition: node.h:259
#define MODE_L2_XC
Definition: l2_input.h:220
#define VLIB_BUFFER_IS_TRACED
Definition: buffer.h:95
clib_error_t * l2_init(vlib_main_t *vm)
Definition: l2_input.c:1144
static uword l2input_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: l2_input.c:290
u64 uword
Definition: types.h:112
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace_funcs.h:55
u32 l2input_intf_bitmap_enable(u32 sw_if_index, u32 feature_bitmap, u32 enable)
Enable (or disable) the feature in the bitmap for the given interface.
Definition: l2_input.c:514
static u8 * format_l2input_trace(u8 *s, va_list *args)
Definition: l2_input.c:74
clib_error_t * l2input_init(vlib_main_t *vm)
Definition: l2_input.c:475
Definition: defs.h:47
unsigned short u16
Definition: types.h:57
l2input_main_t l2input_main
Definition: l2_input.c:87
void ethernet_sw_interface_set_l2_mode(vnet_main_t *vnm, u32 sw_if_index, u32 l2)
Definition: node.c:852
u32 bd_find_or_add_bd_index(bd_main_t *bdm, u32 bd_id)
Get or create a bridge domain.
Definition: l2_bd.c:64
u32 feature_bitmap
Definition: l2_bd.h:57
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
unsigned char u8
Definition: types.h:56
static char * l2input_error_strings[]
Definition: l2_input.c:101
vnet_sw_interface_t * sw_interfaces
Definition: interface.h:568
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:253
l2_bridge_domain_t * bd_configs
Definition: l2_input.h:69
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
Definition: buffer.h:166
#define VLIB_NODE_FUNCTION_MULTIARCH(node, fn)
Definition: node.h:158
#define MODE_ERROR_BVI_DEF
Definition: l2_input.h:224
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:169
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:143
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:418
#define IP4_FEAT_MASK
Masks for eliminating features that do not apply to a packet.
Definition: l2_input.h:178
u8 data[0]
Packet data.
Definition: buffer.h:154
static vlib_node_t * vlib_get_node(vlib_main_t *vm, u32 i)
Get vlib node by index.
Definition: node_funcs.h:58
#define MODE_L2_CLASSIFY
Definition: l2_input.h:221
#define vec_foreach(var, vec)
Vector iterator.
#define get_u16(addr)
u32 sw_if_index
Definition: l2_bd.h:46
#define STATS_IF_LAYER2_UCAST_INPUT_CNT
#define clib_error_return(e, args...)
Definition: error.h:111
struct _unformat_input_t unformat_input_t
l2input_next_t
Definition: l2_input.c:107
uword vlib_node_add_named_next_with_slot(vlib_main_t *vm, uword node, char *name, uword slot)
Definition: node.c:213
#define vec_validate_init_empty(V, I, INIT)
Make sure vector is long enough for given index and initialize empty space (no header, unspecified alignment)
Definition: vec.h:445
bd_main_t bd_main
Definition: l2_bd.c:43
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:67
u32 flags
buffer flags: VLIB_BUFFER_IS_TRACED: trace this buffer.
Definition: buffer.h:85
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:69
Definition: defs.h:46
#define MODE_L3
Definition: l2_input.h:218
vlib_main_t * vlib_main
Definition: l2_input.h:72
u32 ethernet_set_flags(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
Definition: interface.c:298
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:109