FD.io VPP  v18.10-32-g1161dda
Vector Packet Processing
l2_api.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * l2_api.c - layer 2 forwarding api
4  *
5  * Copyright (c) 2016 Cisco and/or its affiliates.
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at:
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *------------------------------------------------------------------
18  */
19 
20 #include <vnet/vnet.h>
21 #include <vlibmemory/api.h>
22 
23 #include <vnet/interface.h>
24 #include <vnet/api_errno.h>
25 #include <vnet/l2/l2_input.h>
26 #include <vnet/l2/l2_fib.h>
27 #include <vnet/l2/l2_vtr.h>
28 #include <vnet/l2/l2_learn.h>
29 #include <vnet/l2/l2_bd.h>
30 
31 #include <vnet/vnet_msg_enum.h>
32 
33 #define vl_typedefs /* define message structures */
34 #include <vnet/vnet_all_api_h.h>
35 #undef vl_typedefs
36 
37 #define vl_endianfun /* define message structures */
38 #include <vnet/vnet_all_api_h.h>
39 #undef vl_endianfun
40 
41 #define vl_api_bridge_domain_details_t_endian vl_noop_handler
42 #define vl_api_bridge_domain_details_t_print vl_noop_handler
43 
44 /* instantiate all the print functions we know about */
45 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
46 #define vl_printfun
47 #include <vnet/vnet_all_api_h.h>
48 #undef vl_printfun
49 
51 
52 #define foreach_vpe_api_msg \
53 _(L2_XCONNECT_DUMP, l2_xconnect_dump) \
54 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
55 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
56 _(L2FIB_FLUSH_ALL, l2fib_flush_all) \
57 _(L2FIB_FLUSH_INT, l2fib_flush_int) \
58 _(L2FIB_FLUSH_BD, l2fib_flush_bd) \
59 _(L2FIB_ADD_DEL, l2fib_add_del) \
60 _(WANT_L2_MACS_EVENTS, want_l2_macs_events) \
61 _(L2_FLAGS, l2_flags) \
62 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
63 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
64 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
65 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
66 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
67 _(BD_IP_MAC_DUMP, bd_ip_mac_dump) \
68 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
69 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
70 _(BRIDGE_FLAGS, bridge_flags) \
71 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
72 _(L2_INTERFACE_PBB_TAG_REWRITE, l2_interface_pbb_tag_rewrite) \
73 _(BRIDGE_DOMAIN_SET_MAC_AGE, bridge_domain_set_mac_age) \
74 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath)
75 
76 static void
78  u32 rx_sw_if_index, u32 tx_sw_if_index)
79 {
81 
82  mp = vl_msg_api_alloc (sizeof (*mp));
83  memset (mp, 0, sizeof (*mp));
84  mp->_vl_msg_id = ntohs (VL_API_L2_XCONNECT_DETAILS);
85  mp->context = context;
86  mp->rx_sw_if_index = htonl (rx_sw_if_index);
87  mp->tx_sw_if_index = htonl (tx_sw_if_index);
88 
89  vl_api_send_msg (reg, (u8 *) mp);
90 }
91 
92 static void
94 {
96  vnet_main_t *vnm = vnet_get_main ();
99  vnet_sw_interface_t *swif;
100  l2_input_config_t *config;
101 
103  if (!reg)
104  return;
105 
106  /* *INDENT-OFF* */
107  pool_foreach (swif, im->sw_interfaces,
108  ({
109  config = vec_elt_at_index (l2im->configs, swif->sw_if_index);
110  if (config->xconnect)
111  send_l2_xconnect_details (reg, mp->context, swif->sw_if_index,
112  config->output_sw_if_index);
113  }));
114  /* *INDENT-ON* */
115 }
116 
117 static void
119 {
120  int rv = 0;
121  vl_api_l2_fib_clear_table_reply_t *rmp;
122 
123  /* Clear all MACs including static MACs */
125 
126  REPLY_MACRO (VL_API_L2_FIB_CLEAR_TABLE_REPLY);
127 }
128 
129 static void
131  vl_api_registration_t * reg,
132  l2fib_entry_key_t * l2fe_key,
133  l2fib_entry_result_t * l2fe_res, u32 context)
134 {
136 
137  mp = vl_msg_api_alloc (sizeof (*mp));
138  memset (mp, 0, sizeof (*mp));
139  mp->_vl_msg_id = ntohs (VL_API_L2_FIB_TABLE_DETAILS);
140 
141  mp->bd_id =
142  ntohl (l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
143 
144  clib_memcpy (mp->mac, l2fe_key->fields.mac, 6);
145  mp->sw_if_index = ntohl (l2fe_res->fields.sw_if_index);
146  mp->static_mac = (l2fib_entry_result_is_set_STATIC (l2fe_res) ? 1 : 0);
147  mp->filter_mac = (l2fib_entry_result_is_set_FILTER (l2fe_res) ? 1 : 0);
148  mp->bvi_mac = (l2fib_entry_result_is_set_BVI (l2fe_res) ? 1 : 0);
149  mp->context = context;
150 
151  vl_api_send_msg (reg, (u8 *) mp);
152 }
153 
154 static void
156 {
158  bd_main_t *bdm = &bd_main;
159  l2fib_entry_key_t *l2fe_key = NULL;
160  l2fib_entry_result_t *l2fe_res = NULL;
161  u32 ni, bd_id = ntohl (mp->bd_id);
162  u32 bd_index;
164  uword *p;
165 
167  if (!reg)
168  return;
169 
170  /* see l2fib_table_dump: ~0 means "any" */
171  if (bd_id == ~0)
172  bd_index = ~0;
173  else
174  {
175  p = hash_get (bdm->bd_index_by_bd_id, bd_id);
176  if (p == 0)
177  return;
178 
179  bd_index = p[0];
180  }
181 
182  l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
183 
184  vec_foreach_index (ni, l2fe_key)
185  {
186  send_l2fib_table_entry (am, reg, vec_elt_at_index (l2fe_key, ni),
187  vec_elt_at_index (l2fe_res, ni), mp->context);
188  }
189  vec_free (l2fe_key);
190  vec_free (l2fe_res);
191 }
192 
193 static void
195 {
196  bd_main_t *bdm = &bd_main;
197  l2input_main_t *l2im = &l2input_main;
198  vl_api_l2fib_add_del_reply_t *rmp;
199  int rv = 0;
200  u32 bd_id = ntohl (mp->bd_id);
201  uword *p = hash_get (bdm->bd_index_by_bd_id, bd_id);
202 
203  if (!p)
204  {
205  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
206  goto bad_sw_if_index;
207  }
208  u32 bd_index = p[0];
209 
210  u8 mac[6];
211 
212  clib_memcpy (mac, mp->mac, 6);
213  if (mp->is_add)
214  {
215  if (mp->filter_mac)
216  l2fib_add_filter_entry (mac, bd_index);
217  else
218  {
220  u32 sw_if_index = ntohl (mp->sw_if_index);
222  if (vec_len (l2im->configs) <= sw_if_index)
223  {
224  rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
225  goto bad_sw_if_index;
226  }
227  else
228  {
229  l2_input_config_t *config;
230  config = vec_elt_at_index (l2im->configs, sw_if_index);
231  if (config->bridge == 0)
232  {
233  rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
234  goto bad_sw_if_index;
235  }
236  }
237  if (mp->static_mac)
238  flags |= L2FIB_ENTRY_RESULT_FLAG_STATIC;
239  if (mp->bvi_mac)
240  flags |= L2FIB_ENTRY_RESULT_FLAG_BVI;
241  l2fib_add_entry (mac, bd_index, sw_if_index, flags);
242  }
243  }
244  else
245  {
246  u32 sw_if_index = ntohl (mp->sw_if_index);
247  if (l2fib_del_entry (mac, bd_index, sw_if_index))
248  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
249  }
250 
252 
253  REPLY_MACRO (VL_API_L2FIB_ADD_DEL_REPLY);
254 }
255 
256 static void
258 {
259  int rv = 0;
260  vl_api_want_l2_macs_events_reply_t *rmp;
263  u32 pid = ntohl (mp->pid);
264  u32 learn_limit = ntohl (mp->learn_limit);
265 
266  if (mp->enable_disable)
267  {
268  if (lm->client_pid == 0)
269  {
270  lm->client_pid = pid;
271  lm->client_index = mp->client_index;
272 
273  if (mp->max_macs_in_event)
274  fm->max_macs_in_event = mp->max_macs_in_event * 10;
275  else
277 
278  if (mp->scan_delay)
279  fm->event_scan_delay = (f64) (mp->scan_delay) * 10e-3;
280  else
282 
283  /* change learn limit and flush all learned MACs */
284  if (learn_limit && (learn_limit < L2LEARN_DEFAULT_LIMIT))
285  lm->global_learn_limit = learn_limit;
286  else
288 
290  }
291  else if (lm->client_pid != pid)
292  {
293  rv = VNET_API_ERROR_L2_MACS_EVENT_CLINET_PRESENT;
294  goto exit;
295  }
296  }
297  else if (lm->client_pid)
298  {
299  lm->client_pid = 0;
300  lm->client_index = 0;
301  if (learn_limit && (learn_limit < L2LEARN_DEFAULT_LIMIT))
302  lm->global_learn_limit = learn_limit;
303  else
305  }
306 
307 exit:
308  REPLY_MACRO (VL_API_WANT_L2_MACS_EVENTS_REPLY);
309 }
310 
311 static void
313 {
314  int rv = 0;
316  vl_api_l2fib_flush_int_reply_t *rmp;
317 
319 
320  u32 sw_if_index = ntohl (mp->sw_if_index);
321  l2fib_flush_int_mac (vm, sw_if_index);
322 
324  REPLY_MACRO (VL_API_L2FIB_FLUSH_INT_REPLY);
325 }
326 
327 static void
329 {
330  int rv = 0;
331  vl_api_l2fib_flush_all_reply_t *rmp;
332 
334  REPLY_MACRO (VL_API_L2FIB_FLUSH_ALL_REPLY);
335 }
336 
337 static void
339 {
340  int rv = 0;
342  bd_main_t *bdm = &bd_main;
343  vl_api_l2fib_flush_bd_reply_t *rmp;
344 
345  u32 bd_id = ntohl (mp->bd_id);
346  uword *p = hash_get (bdm->bd_index_by_bd_id, bd_id);
347  if (p == 0)
348  {
349  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
350  goto out;
351  }
352  l2fib_flush_bd_mac (vm, *p);
353 out:
354  REPLY_MACRO (VL_API_L2FIB_FLUSH_BD_REPLY);
355 }
356 
357 static void
359 {
361  int rv = 0;
362  u32 rbm = 0;
363 
365 
366  u32 sw_if_index = ntohl (mp->sw_if_index);
367  u32 flags = ntohl (mp->feature_bitmap);
368  u32 bitmap = 0;
369 
370  if (flags & L2_LEARN)
371  bitmap |= L2INPUT_FEAT_LEARN;
372 
373  if (flags & L2_FWD)
374  bitmap |= L2INPUT_FEAT_FWD;
375 
376  if (flags & L2_FLOOD)
377  bitmap |= L2INPUT_FEAT_FLOOD;
378 
379  if (flags & L2_UU_FLOOD)
380  bitmap |= L2INPUT_FEAT_UU_FLOOD;
381 
382  if (flags & L2_ARP_TERM)
383  bitmap |= L2INPUT_FEAT_ARP_TERM;
384 
385  rbm = l2input_intf_bitmap_enable (sw_if_index, bitmap, mp->is_set);
386 
388 
389  /* *INDENT-OFF* */
390  REPLY_MACRO2(VL_API_L2_FLAGS_REPLY,
391  ({
392  rmp->resulting_feature_bitmap = ntohl(rbm);
393  }));
394  /* *INDENT-ON* */
395 }
396 
397 static void
399  * mp)
400 {
402  bd_main_t *bdm = &bd_main;
403  vl_api_bridge_domain_set_mac_age_reply_t *rmp;
404  int rv = 0;
405  u32 bd_id = ntohl (mp->bd_id);
406  uword *p;
407 
408  if (bd_id == 0)
409  {
410  rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
411  goto out;
412  }
413 
414  p = hash_get (bdm->bd_index_by_bd_id, bd_id);
415  if (p == 0)
416  {
417  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
418  goto out;
419  }
420  bd_set_mac_age (vm, *p, mp->mac_age);
421 out:
422  REPLY_MACRO (VL_API_BRIDGE_DOMAIN_SET_MAC_AGE_REPLY);
423 }
424 
425 static void
427 {
429  .is_add = mp->is_add,
430  .flood = mp->flood,
431  .uu_flood = mp->uu_flood,
432  .forward = mp->forward,
433  .learn = mp->learn,
434  .arp_term = mp->arp_term,
435  .mac_age = mp->mac_age,
436  .bd_id = ntohl (mp->bd_id),
437  .bd_tag = mp->bd_tag
438  };
439 
440  int rv = bd_add_del (&a);
441 
442  vl_api_bridge_domain_add_del_reply_t *rmp;
443  REPLY_MACRO (VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
444 }
445 
446 static void
448  vl_api_registration_t * reg,
449  l2_bridge_domain_t * bd_config,
450  u32 n_sw_ifs, u32 context)
451 {
455  l2_input_config_t *input_cfg;
456 
457  mp = vl_msg_api_alloc (sizeof (*mp) +
458  (n_sw_ifs * sizeof (vl_api_bridge_domain_sw_if_t)));
459  memset (mp, 0, sizeof (*mp));
460  mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
461  mp->bd_id = ntohl (bd_config->bd_id);
462  mp->flood = bd_feature_flood (bd_config);
463  mp->uu_flood = bd_feature_uu_flood (bd_config);
464  mp->forward = bd_feature_forward (bd_config);
465  mp->learn = bd_feature_learn (bd_config);
466  mp->arp_term = bd_feature_arp_term (bd_config);
467  mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
468  mp->uu_fwd_sw_if_index = ntohl (bd_config->uu_fwd_sw_if_index);
469  mp->mac_age = bd_config->mac_age;
470  if (bd_config->bd_tag)
471  {
472  strncpy ((char *) mp->bd_tag, (char *) bd_config->bd_tag,
473  ARRAY_LEN (mp->bd_tag) - 1);
474  mp->bd_tag[ARRAY_LEN (mp->bd_tag) - 1] = 0;
475  }
476 
477  mp->context = context;
478 
480  vec_foreach (m, bd_config->members)
481  {
482  sw_ifs->sw_if_index = ntohl (m->sw_if_index);
483  input_cfg = vec_elt_at_index (l2im->configs, m->sw_if_index);
484  sw_ifs->shg = input_cfg->shg;
485  sw_ifs++;
486  mp->n_sw_ifs++;
487  }
488  mp->n_sw_ifs = htonl (mp->n_sw_ifs);
489 
490  vl_api_send_msg (reg, (u8 *) mp);
491 }
492 
493 static void
495 {
496  bd_main_t *bdm = &bd_main;
497  l2input_main_t *l2im = &l2input_main;
499  u32 bd_id, bd_index, end;
500 
502  if (!reg)
503  return;
504 
505  bd_id = ntohl (mp->bd_id);
506  if (bd_id == 0)
507  return;
508 
509  if (bd_id == ~0)
510  bd_index = 0, end = vec_len (l2im->bd_configs);
511  else
512  {
513  bd_index = bd_find_index (bdm, bd_id);
514  if (bd_index == ~0)
515  return;
516 
517  end = bd_index + 1;
518  }
519 
520  for (; bd_index < end; bd_index++)
521  {
522  l2_bridge_domain_t *bd_config =
523  l2input_bd_config_from_index (l2im, bd_index);
524  /* skip dummy bd_id 0 */
525  if (bd_config && (bd_config->bd_id > 0))
526  send_bridge_domain_details (l2im, reg, bd_config,
527  vec_len (bd_config->members),
528  mp->context);
529  }
530 }
531 
532 static bd_flags_t
533 bd_flags_decode (vl_api_bd_flags_t v)
534 {
535  bd_flags_t f = L2_NONE;
536 
537  v = ntohl (v);
538 
539  if (v & BRIDGE_API_FLAG_LEARN)
540  f |= L2_LEARN;
541  if (v & BRIDGE_API_FLAG_FWD)
542  f |= L2_FWD;
543  if (v & BRIDGE_API_FLAG_FLOOD)
544  f |= L2_FLOOD;
545  if (v & BRIDGE_API_FLAG_UU_FLOOD)
546  f |= L2_UU_FLOOD;
547  if (v & BRIDGE_API_FLAG_ARP_TERM)
548  f |= L2_ARP_TERM;
549 
550  return (f);
551 }
552 
553 static void
555 {
557  bd_main_t *bdm = &bd_main;
559  int rv = 0;
560 
562  u32 bd_id = ntohl (mp->bd_id);
563  if (bd_id == 0)
564  {
565  rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
566  goto out;
567  }
568 
569  u32 bd_index = bd_find_index (bdm, bd_id);
570  if (bd_index == ~0)
571  {
572  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
573  goto out;
574  }
575 
576  u32 bitmap = bd_set_flags (vm, bd_index, flags, mp->is_set);
577 
578 out:
579  /* *INDENT-OFF* */
580  REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
581  ({
582  rmp->resulting_feature_bitmap = ntohl(bitmap);
583  }));
584  /* *INDENT-ON* */
585 }
586 
587 static void
590 {
591  int rv = 0;
592  vl_api_l2_interface_vlan_tag_rewrite_reply_t *rmp;
593  vnet_main_t *vnm = vnet_get_main ();
595  u32 vtr_op;
596 
598 
599  vtr_op = ntohl (mp->vtr_op);
600 
601  /* The L2 code is unsuspicious */
602  switch (vtr_op)
603  {
604  case L2_VTR_DISABLED:
605  case L2_VTR_PUSH_1:
606  case L2_VTR_PUSH_2:
607  case L2_VTR_POP_1:
608  case L2_VTR_POP_2:
613  break;
614 
615  default:
616  rv = VNET_API_ERROR_INVALID_VALUE;
617  goto bad_sw_if_index;
618  }
619 
620  rv = l2vtr_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
621  ntohl (mp->push_dot1q), ntohl (mp->tag1),
622  ntohl (mp->tag2));
623 
625 
626  REPLY_MACRO (VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
627 }
628 
629 static void
632 {
633  vl_api_l2_interface_pbb_tag_rewrite_reply_t *rmp;
634  vnet_main_t *vnm = vnet_get_main ();
636  u32 vtr_op;
637  int rv = 0;
638 
640 
641  vtr_op = ntohl (mp->vtr_op);
642 
643  switch (vtr_op)
644  {
645  case L2_VTR_DISABLED:
646  case L2_VTR_PUSH_2:
647  case L2_VTR_POP_2:
649  break;
650 
651  default:
652  rv = VNET_API_ERROR_INVALID_VALUE;
653  goto bad_sw_if_index;
654  }
655 
656  rv = l2pbb_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
657  mp->b_dmac, mp->b_smac, ntohs (mp->b_vlanid),
658  ntohl (mp->i_sid), ntohs (mp->outer_tag));
659 
661 
662  REPLY_MACRO (VL_API_L2_INTERFACE_PBB_TAG_REWRITE_REPLY);
663 }
664 
665 static void
668 {
669  vl_api_sw_interface_set_l2_xconnect_reply_t *rmp;
670  int rv = 0;
671  u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
672  u32 tx_sw_if_index = ntohl (mp->tx_sw_if_index);
674  vnet_main_t *vnm = vnet_get_main ();
675 
677 
678  if (mp->enable)
679  {
681  rv = set_int_l2_mode (vm, vnm, MODE_L2_XC,
682  rx_sw_if_index, 0,
683  L2_BD_PORT_TYPE_NORMAL, 0, tx_sw_if_index);
684  }
685  else
686  {
687  rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0,
688  L2_BD_PORT_TYPE_NORMAL, 0, 0);
689  }
690 
691  switch (rv)
692  {
693  case MODE_ERROR_ETH:
694  rv = VNET_API_ERROR_NON_ETHERNET;
695  break;
696  case MODE_ERROR_BVI_DEF:
697  rv = VNET_API_ERROR_BD_ALREADY_HAS_BVI;
698  break;
699  }
700 
703 
704  REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
705 }
706 
707 static int
708 l2_bd_port_type_decode (vl_api_l2_port_type_t v, l2_bd_port_type_t * l)
709 {
710  v = clib_net_to_host_u32 (v);
711 
712  switch (v)
713  {
716  return 0;
718  *l = L2_BD_PORT_TYPE_BVI;
719  return 0;
722  return 0;
723  }
724 
725  return (VNET_API_ERROR_INVALID_VALUE);
726 }
727 
728 static void
731 {
732  bd_main_t *bdm = &bd_main;
733  vl_api_sw_interface_set_l2_bridge_reply_t *rmp;
734  int rv = 0;
736  vnet_main_t *vnm = vnet_get_main ();
738 
740  u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
741  rv = l2_bd_port_type_decode (mp->port_type, &pt);
742 
743  if (0 != rv)
744  goto out;
745  if (mp->enable)
746  {
747  VALIDATE_BD_ID (mp);
748  u32 bd_id = ntohl (mp->bd_id);
749  u32 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
750 
751  rv = set_int_l2_mode (vm, vnm, MODE_L2_BRIDGE,
752  rx_sw_if_index, bd_index, pt, mp->shg, 0);
753  }
754  else
755  {
756  rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, pt, 0, 0);
757  }
758 
759  switch (rv)
760  {
761  case MODE_ERROR_ETH:
762  rv = VNET_API_ERROR_NON_ETHERNET;
763  break;
764  case MODE_ERROR_BVI_DEF:
765  rv = VNET_API_ERROR_BD_ALREADY_HAS_BVI;
766  break;
767  }
768 
771 out:
772  REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
773 }
774 
775 static void
777  vl_api_registration_t * reg,
778  u32 bd_id, u8 is_ipv6,
779  u8 * ip_address, u8 * mac_address, u32 context)
780 {
782 
783  mp = vl_msg_api_alloc (sizeof (*mp));
784  memset (mp, 0, sizeof (*mp));
785  mp->_vl_msg_id = ntohs (VL_API_BD_IP_MAC_DETAILS);
786 
787  mp->bd_id = ntohl (bd_id);
788 
789  clib_memcpy (mp->mac_address, mac_address, 6);
790  mp->is_ipv6 = is_ipv6;
791  clib_memcpy (mp->ip_address, ip_address, (is_ipv6) ? 16 : 4);
792  mp->context = context;
793 
794  vl_api_send_msg (reg, (u8 *) mp);
795 }
796 
797 static void
799 {
801  bd_main_t *bdm = &bd_main;
802  l2_bridge_domain_t *bd_config;
803  u32 bd_id = ntohl (mp->bd_id);
804  u32 bd_index, start, end;
806  uword *p;
807 
809  if (!reg)
810  return;
811 
812  /* see bd_id: ~0 means "any" */
813  if (bd_id == ~0)
814  {
815  start = 1;
817  }
818  else
819  {
820  p = hash_get (bdm->bd_index_by_bd_id, bd_id);
821  if (p == 0)
822  return;
823 
824  bd_index = p[0];
826  start = bd_index;
827  end = start + 1;
828  }
829 
830  for (bd_index = start; bd_index < end; bd_index++)
831  {
832  bd_config = vec_elt_at_index (l2input_main.bd_configs, bd_index);
833  if (bd_is_valid (bd_config))
834  {
835  ip4_address_t ip4_addr;
836  ip6_address_t *ip6_addr;
837  u64 mac_addr;
838  bd_id = bd_config->bd_id;
839 
840  /* *INDENT-OFF* */
841  hash_foreach (ip4_addr.as_u32, mac_addr, bd_config->mac_by_ip4,
842  ({
843  send_bd_ip_mac_entry (am, reg, bd_id, 0, (u8 *) &(ip4_addr.as_u8), (u8 *) &mac_addr, mp->context);
844  }));
845 
846  hash_foreach_mem (ip6_addr, mac_addr, bd_config->mac_by_ip6,
847  ({
848  send_bd_ip_mac_entry (am, reg, bd_id, 1, (u8 *) &(ip6_addr->as_u8), (u8 *) &mac_addr, mp->context);
849  }));
850  /* *INDENT-ON* */
851  }
852  }
853 }
854 
855 static void
857 {
858  bd_main_t *bdm = &bd_main;
859  vl_api_bd_ip_mac_add_del_reply_t *rmp;
860  int rv = 0;
861  u32 bd_id = ntohl (mp->bd_id);
862  u32 bd_index;
863  uword *p;
864 
865  if (bd_id == 0)
866  {
867  rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
868  goto out;
869  }
870 
871  p = hash_get (bdm->bd_index_by_bd_id, bd_id);
872  if (p == 0)
873  {
874  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
875  goto out;
876  }
877 
878  bd_index = p[0];
879  if (bd_add_del_ip_mac (bd_index, mp->ip_address,
880  mp->mac_address, mp->is_ipv6, mp->is_add))
881  rv = VNET_API_ERROR_UNSPECIFIED;
882 
883 out:
884  REPLY_MACRO (VL_API_BD_IP_MAC_ADD_DEL_REPLY);
885 }
886 
887 extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
888  u32 sw_if_index, u8 enable);
889 
890 static void
892  mp)
893 {
894  int rv;
895  vl_api_l2_interface_efp_filter_reply_t *rmp;
896  vnet_main_t *vnm = vnet_get_main ();
897 
899 
900  // enable/disable the feature
901  l2_efp_filter_configure (vnm, ntohl (mp->sw_if_index), mp->enable_disable);
902  rv = vnm->api_errno;
903 
905  REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
906 }
907 
908 static void
910 {
911  extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
912  int is_add);
913  vl_api_l2_patch_add_del_reply_t *rmp;
914  int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
915  int is_add);
916  int rv = 0;
917 
920 
921  rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
922  ntohl (mp->tx_sw_if_index),
923  (int) (mp->is_add != 0));
924 
927 
928  REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
929 }
930 
931 static void
933 {
934  vl_api_sw_interface_set_vpath_reply_t *rmp;
935  int rv = 0;
936  u32 sw_if_index = ntohl (mp->sw_if_index);
937 
939 
940  l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
941  vnet_feature_enable_disable ("ip4-unicast", "vpath-input-ip4",
942  sw_if_index, mp->enable, 0, 0);
943  vnet_feature_enable_disable ("ip4-multicast", "vpath-input-ip4",
944  sw_if_index, mp->enable, 0, 0);
945  vnet_feature_enable_disable ("ip6-unicast", "vpath-input-ip6",
946  sw_if_index, mp->enable, 0, 0);
947  vnet_feature_enable_disable ("ip6-multicast", "vpath-input-ip6",
948  sw_if_index, mp->enable, 0, 0);
949 
951 
952  REPLY_MACRO (VL_API_SW_INTERFACE_SET_VPATH_REPLY);
953 }
954 
955 /*
956  * l2_api_hookup
957  * Add vpe's API message handlers to the table.
958  * vlib has already mapped shared memory and
959  * added the client registration handlers.
960  * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
961  */
962 #define vl_msg_name_crc_list
963 #include <vnet/vnet_all_api_h.h>
964 #undef vl_msg_name_crc_list
965 
966 static void
968 {
969 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
970  foreach_vl_msg_name_crc_l2;
971 #undef _
972 }
973 
974 static clib_error_t *
976 {
977  api_main_t *am = &api_main;
978 
979 #define _(N,n) \
980  vl_msg_api_set_handlers(VL_API_##N, #n, \
981  vl_api_##n##_t_handler, \
982  vl_noop_handler, \
983  vl_api_##n##_t_endian, \
984  vl_api_##n##_t_print, \
985  sizeof(vl_api_##n##_t), 1);
987 #undef _
988 
989  /*
990  * Set up the (msg_name, crc, message-id) table
991  */
993 
994  return 0;
995 }
996 
998 
999 /*
1000  * fd.io coding-style-patch-verification: ON
1001  *
1002  * Local Variables:
1003  * eval: (c-set-style "gnu")
1004  * End:
1005  */
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:437
static_always_inline u8 bd_feature_forward(l2_bridge_domain_t *bd_config)
Definition: l2_input.h:170
static void vl_api_l2_fib_table_dump_t_handler(vl_api_l2_fib_table_dump_t *mp)
Definition: l2_api.c:155
#define BAD_RX_SW_IF_INDEX_LABEL
static bd_flags_t bd_flags_decode(vl_api_bd_flags_t v)
Definition: l2_api.c:533
#define vec_foreach_index(var, v)
Iterate over vector indices.
L2 FIB add entry request.
Definition: l2.api:125
l2_input_config_t * configs
Definition: l2_input.h:61
Set bridge flags response.
Definition: l2.api:348
#define VALIDATE_TX_SW_IF_INDEX(mp)
u32 uu_fwd_sw_if_index
Definition: l2_bd.h:78
l2 fib table details structure
Definition: l2.api:49
a
Definition: bitmap.h:538
u32 l2vtr_configure(vlib_main_t *vlib_main, vnet_main_t *vnet_main, u32 sw_if_index, u32 vtr_op, u32 push_dot1q, u32 vtr_tag1, u32 vtr_tag2)
Configure vtag tag rewrite on the given interface.
Definition: l2_vtr.c:136
vl_api_l2_port_type_t port_type
Definition: l2.api:463
vnet_main_t * vnet_get_main(void)
Definition: misc.c:47
static void vl_api_sw_interface_set_l2_bridge_t_handler(vl_api_sw_interface_set_l2_bridge_t *mp)
Definition: l2_api.c:730
u32 bvi_sw_if_index
Definition: l2_bd.h:72
static void vl_api_l2_patch_add_del_t_handler(vl_api_l2_patch_add_del_t *mp)
Definition: l2_api.c:909
static void vl_api_l2_flags_t_handler(vl_api_l2_flags_t *mp)
Definition: l2_api.c:358
vnet_interface_main_t interface_main
Definition: vnet.h:56
unsigned long u64
Definition: types.h:89
#define REPLY_MACRO2(t, body)
#define NULL
Definition: clib.h:57
static void vl_api_send_msg(vl_api_registration_t *rp, u8 *elem)
Definition: api.h:34
Definition: l2_bd.h:149
VLIB_API_INIT_FUNCTION(l2_api_hookup)
L2 bridge domain set mac age.
Definition: l2.api:230
l2_flood_member_t * members
Definition: l2_bd.h:84
Dump L2 XConnects.
Definition: l2.api:35
static void vl_api_bridge_domain_add_del_t_handler(vl_api_bridge_domain_add_del_t *mp)
Definition: l2_api.c:426
static void send_l2_xconnect_details(vl_api_registration_t *reg, u32 context, u32 rx_sw_if_index, u32 tx_sw_if_index)
Definition: l2_api.c:77
static void vl_api_bd_ip_mac_dump_t_handler(vl_api_bd_ip_mac_dump_t *mp)
Definition: l2_api.c:798
u32 max_macs_in_event
Definition: l2_fib.h:59
enum l2fib_entry_result_flags_t_ l2fib_entry_result_flags_t
L2 bridge domain request operational state details.
Definition: l2.api:270
int bd_add_del(l2_bridge_domain_add_del_args_t *a)
Definition: l2_bd.c:1159
bridge domain IP to MAC entry details structure
Definition: l2.api:494
static_always_inline u8 bd_feature_uu_flood(l2_bridge_domain_t *bd_config)
Definition: l2_input.h:163
static void vl_api_l2fib_add_del_t_handler(vl_api_l2fib_add_del_t *mp)
Definition: l2_api.c:194
void * vl_msg_api_alloc(int nbytes)
unsigned char u8
Definition: types.h:56
u32 client_index
Definition: l2_learn.h:39
double f64
Definition: types.h:142
#define fm
Definition: l2_fib.h:135
Reply to l2_xconnect_dump.
Definition: l2.api:24
L2 bridge domain operational state response.
Definition: l2.api:300
l2learn_main_t l2learn_main
Definition: l2_learn.c:33
memset(h->entries, 0, sizeof(h->entries[0])*entries)
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:443
struct l2fib_entry_result_t_::@243::@245 fields
#define MODE_L2_BRIDGE
Definition: l2_input.h:206
L2 bridge domain sw interface operational state response.
Definition: l2.api:282
#define hash_foreach(key_var, value_var, h, body)
Definition: hash.h:442
u32 feature_bitmap
Definition: l2.api:209
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
static_always_inline u8 bd_feature_arp_term(l2_bridge_domain_t *bd_config)
Definition: l2_input.h:183
static void vl_api_l2_fib_clear_table_t_handler(vl_api_l2_fib_clear_table_t *mp)
Definition: l2_api.c:118
L2 FIB flush bridge domain entries.
Definition: l2.api:96
static void send_bd_ip_mac_entry(vpe_api_main_t *am, vl_api_registration_t *reg, u32 bd_id, u8 is_ipv6, u8 *ip_address, u8 *mac_address, u32 context)
Definition: l2_api.c:776
void l2fib_add_entry(const u8 *mac, u32 bd_index, u32 sw_if_index, l2fib_entry_result_flags_t flags)
Add an entry to the l2fib.
Definition: l2_fib.c:379
unsigned int u32
Definition: types.h:88
uword * bd_index_by_bd_id
Definition: l2_bd.h:34
Dump l2 fib (aka bridge domain) table.
Definition: l2.api:64
static_always_inline u8 bd_feature_flood(l2_bridge_domain_t *bd_config)
Definition: l2_input.h:156
vnet_api_error_t api_errno
Definition: vnet.h:78
#define hash_get(h, key)
Definition: hash.h:249
f64 event_scan_delay
Definition: l2_fib.h:56
Set interface L2 flags (such as L2_LEARN, L2_FWD, L2_FLOOD, L2_UU_FLOOD, or L2_ARP_TERM bits)...
Definition: l2.api:203
L2 FIB flush all entries.
Definition: l2.api:85
L2 fib clear table request, clear all mac entries in the l2 fib.
Definition: l2.api:75
#define v
Definition: acl.c:496
Set interface L2 flags response.
Definition: l2.api:217
Set bridge domain ip to mac entry request.
Definition: l2.api:477
void l2fib_flush_bd_mac(vlib_main_t *vm, u32 bd_index)
Flush all non static MACs in a bridge domain.
Definition: l2_fib.c:793
enum l2_bd_port_type_t_ l2_bd_port_type_t
static void vl_api_bd_ip_mac_add_del_t_handler(vl_api_bd_ip_mac_add_del_t *mp)
Definition: l2_api.c:856
#define REPLY_MACRO(t)
#define BAD_TX_SW_IF_INDEX_LABEL
void l2fib_flush_all_mac(vlib_main_t *vm)
Flush all non static MACs - flushes all valid BDs.
Definition: l2_fib.c:804
#define hash_foreach_mem(key_var, value_var, h, body)
Definition: hash.h:461
static clib_error_t * l2_api_hookup(vlib_main_t *vm)
Definition: l2_api.c:975
#define L2FIB_EVENT_MAX_MACS_DEFAULT
Definition: l2_fib.h:37
l2fib_main_t l2fib_main
Definition: l2_fib.c:55
static u32 bd_is_valid(l2_bridge_domain_t *bd_config)
Definition: l2_bd.h:131
Definition: l2_bd.h:147
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:201
u32 flags
Definition: vhost_user.h:115
u32 l2pbb_configure(vlib_main_t *vlib_main, vnet_main_t *vnet_main, u32 sw_if_index, u32 vtr_op, u8 *b_dmac, u8 *b_smac, u16 b_vlanid, u32 i_sid, u16 vlan_outer_tag)
Definition: l2_vtr.c:54
typedef mac_address
void bd_set_mac_age(vlib_main_t *vm, u32 bd_index, u8 age)
Set the mac age for the bridge domain.
Definition: l2_bd.c:288
An API client registration, only in vpp/vlib.
Definition: api_common.h:44
#define BAD_SW_IF_INDEX_LABEL
static void send_bridge_domain_details(l2input_main_t *l2im, vl_api_registration_t *reg, l2_bridge_domain_t *bd_config, u32 n_sw_ifs, u32 context)
Definition: l2_api.c:447
u32 l2fib_del_entry(const u8 *mac, u32 bd_index, u32 sw_if_index)
Delete an entry from the l2fib.
Definition: l2_fib.c:663
vlib_main_t * vm
Definition: buffer.c:294
static void vl_api_l2_xconnect_dump_t_handler(vl_api_l2_xconnect_dump_t *mp)
Definition: l2_api.c:93
u32 bd_add_del_ip_mac(u32 bd_index, u8 *ip_addr, u8 *mac_addr, u8 is_ip6, u8 is_add)
Add/delete IP address to MAC address mapping.
Definition: l2_bd.c:735
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:339
#define foreach_vpe_api_msg
Definition: l2_api.c:52
u32 bd_set_flags(vlib_main_t *vm, u32 bd_index, bd_flags_t flags, u32 enable)
Set the learn/forward/flood flags for the bridge domain.
Definition: l2_bd.c:244
#define MODE_ERROR_ETH
Definition: l2_input.h:210
static_always_inline u8 bd_feature_learn(l2_bridge_domain_t *bd_config)
Definition: l2_input.h:176
#define clib_memcpy(a, b, c)
Definition: string.h:75
static void setup_message_id_table(api_main_t *am)
Definition: l2_api.c:967
void l2fib_clear_table(void)
Definition: l2_fib.c:321
#define ARRAY_LEN(x)
Definition: clib.h:61
uword * mac_by_ip6
Definition: l2_bd.h:100
static vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
Definition: api.h:56
#define VALIDATE_RX_SW_IF_INDEX(mp)
Dump bridge domain IP to MAC entries.
Definition: l2.api:507
struct l2fib_entry_key_t::@235::@237 fields
#define L2FIB_EVENT_SCAN_DELAY_DEFAULT
Definition: l2_fib.h:34
Set L2 XConnect between two interfaces request.
Definition: l2.api:423
static u32 bd_find_or_add_bd_index(bd_main_t *bdm, u32 bd_id)
Get or create a bridge domain.
Definition: l2_bd.h:192
static_always_inline l2_bridge_domain_t * l2input_bd_config_from_index(l2input_main_t *l2im, u32 bd_index)
Definition: l2_input.h:76
Definition: l2_fib.h:71
Register to receive L2 MAC events for learned and aged MAC.
Definition: l2.api:147
u32 set_int_l2_mode(vlib_main_t *vm, vnet_main_t *vnet_main, u32 mode, u32 sw_if_index, u32 bd_index, l2_bd_port_type_t port_type, u32 shg, u32 xc_sw_if_index)
Set the subinterface to run in l2 or l3 mode.
Definition: l2_input.c:572
#define BAD_BD_ID_LABEL
u32 global_learn_limit
Definition: l2_learn.h:35
#define VALIDATE_BD_ID(mp)
#define MODE_L2_XC
Definition: l2_input.h:207
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
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:520
u32 resulting_feature_bitmap
Definition: l2.api:221
static void vl_api_l2_interface_vlan_tag_rewrite_t_handler(vl_api_l2_interface_vlan_tag_rewrite_t *mp)
Definition: l2_api.c:589
Interface bridge mode request.
Definition: l2.api:457
#define L2FIB_EVENT_LEARN_LIMIT_DEFAULT
Definition: l2_fib.h:40
static void vl_api_sw_interface_set_l2_xconnect_t_handler(vl_api_sw_interface_set_l2_xconnect_t *mp)
Definition: l2_api.c:667
l2input_main_t l2input_main
Definition: l2_input.c:113
L2 FIB flush interface entries.
Definition: l2.api:108
static void vl_api_l2fib_flush_bd_t_handler(vl_api_l2fib_flush_bd_t *mp)
Definition: l2_api.c:338
vl_api_bd_flags_t flags
Definition: l2.api:340
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static void vl_api_want_l2_macs_events_t_handler(vl_api_want_l2_macs_events_t *mp)
Definition: l2_api.c:257
u64 uword
Definition: types.h:112
L2 interface ethernet flow point filtering enable/disable request.
Definition: l2.api:520
static void vl_api_bridge_flags_t_handler(vl_api_bridge_flags_t *mp)
Definition: l2_api.c:554
int vnet_l2_patch_add_del(u32 rx_sw_if_index, u32 tx_sw_if_index, int is_add)
Definition: l2_patch.c:247
vnet_sw_interface_t * sw_interfaces
Definition: interface.h:846
static void vl_api_l2_interface_efp_filter_t_handler(vl_api_l2_interface_efp_filter_t *mp)
Definition: l2_api.c:891
L2 interface vlan tag rewrite configure request.
Definition: l2.api:364
static void vl_api_l2fib_flush_all_t_handler(vl_api_l2fib_flush_all_t *mp)
Definition: l2_api.c:328
l2_bridge_domain_t * bd_configs
Definition: l2_input.h:64
static void l2fib_add_filter_entry(const u8 *mac, u32 bd_index)
Definition: l2_fib.h:448
static void vl_api_bridge_domain_set_mac_age_t_handler(vl_api_bridge_domain_set_mac_age_t *mp)
Definition: l2_api.c:398
L2 interface patch add / del request.
Definition: l2.api:407
void l2fib_table_dump(u32 bd_index, l2fib_entry_key_t **l2fe_key, l2fib_entry_result_t **l2fe_res)
Definition: l2_fib.c:110
static void send_l2fib_table_entry(vpe_api_main_t *am, vl_api_registration_t *reg, l2fib_entry_key_t *l2fe_key, l2fib_entry_result_t *l2fe_res, u32 context)
Definition: l2_api.c:130
Interface set vpath request.
Definition: l2.api:534
#define MODE_ERROR_BVI_DEF
Definition: l2_input.h:211
static int l2_bd_port_type_decode(vl_api_l2_port_type_t v, l2_bd_port_type_t *l)
Definition: l2_api.c:708
L2 interface pbb tag rewrite configure request.
Definition: l2.api:387
u32 sw_if_index
Definition: l2.api:207
#define vec_foreach(var, vec)
Vector iterator.
uword * mac_by_ip4
Definition: l2_bd.h:99
Set bridge flags request.
Definition: l2.api:334
vl_api_bridge_domain_sw_if_t sw_if_details[n_sw_ifs]
Definition: l2.api:314
u32 sw_if_index
Definition: l2_bd.h:53
u32 bd_find_index(bd_main_t *bdm, u32 bd_id)
Get a bridge domain.
Definition: l2_bd.c:69
bd_main_t bd_main
Definition: l2_bd.c:44
vpe_api_main_t vpe_api_main
Definition: pipe_api.c:39
void l2_efp_filter_configure(vnet_main_t *vnet_main, u32 sw_if_index, u8 enable)
Enable/disable the EFP Filter check on the subinterface.
api_main_t api_main
Definition: api_shared.c:35
u32 client_pid
Definition: l2_learn.h:38
vl_api_mac_address_t mac
Definition: gbp.api:31
void l2fib_flush_int_mac(vlib_main_t *vm, u32 sw_if_index)
Flush all non static MACs from an interface.
Definition: l2_fib.c:783
static void vl_api_l2fib_flush_int_t_handler(vl_api_l2fib_flush_int_t *mp)
Definition: l2_api.c:312
static void vl_api_l2_interface_pbb_tag_rewrite_t_handler(vl_api_l2_interface_pbb_tag_rewrite_t *mp)
Definition: l2_api.c:631
#define L2LEARN_DEFAULT_LIMIT
Definition: l2_learn.h:49
int vnet_feature_enable_disable(const char *arc_name, const char *node_name, u32 sw_if_index, int enable_disable, void *feature_config, u32 n_feature_config_bytes)
Definition: feature.c:233
#define VALIDATE_SW_IF_INDEX(mp)
#define MODE_L3
Definition: l2_input.h:205
enum bd_flags_t_ bd_flags_t
static void vl_api_bridge_domain_dump_t_handler(vl_api_bridge_domain_dump_t *mp)
Definition: l2_api.c:494
L2 bridge domain add or delete request.
Definition: l2.api:250
static void vl_api_sw_interface_set_vpath_t_handler(vl_api_sw_interface_set_vpath_t *mp)
Definition: l2_api.c:932