FD.io VPP  v21.01.1
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 #include <vnet/l2/l2_bvi.h>
31 #include <vnet/l2/l2_arp_term.h>
32 #include <vnet/ip/ip_types_api.h>
34 
35 #include <vnet/vnet_msg_enum.h>
36 
37 #define vl_typedefs /* define message structures */
38 #include <vnet/vnet_all_api_h.h>
39 #undef vl_typedefs
40 
41 #define vl_endianfun /* define message structures */
42 #include <vnet/vnet_all_api_h.h>
43 #undef vl_endianfun
44 
45 /* instantiate all the print functions we know about */
46 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
47 #define vl_printfun
48 #include <vnet/vnet_all_api_h.h>
49 #undef vl_printfun
50 
52 
53 #define foreach_vpe_api_msg \
54 _(L2_XCONNECT_DUMP, l2_xconnect_dump) \
55 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
56 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
57 _(L2FIB_FLUSH_ALL, l2fib_flush_all) \
58 _(L2FIB_FLUSH_INT, l2fib_flush_int) \
59 _(L2FIB_FLUSH_BD, l2fib_flush_bd) \
60 _(L2FIB_ADD_DEL, l2fib_add_del) \
61 _(WANT_L2_MACS_EVENTS, want_l2_macs_events) \
62 _(L2_FLAGS, l2_flags) \
63 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
64 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
65 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
66 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
67 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
68 _(BD_IP_MAC_FLUSH, bd_ip_mac_flush) \
69 _(BD_IP_MAC_DUMP, bd_ip_mac_dump) \
70 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
71 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
72 _(BRIDGE_FLAGS, bridge_flags) \
73 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
74 _(L2_INTERFACE_PBB_TAG_REWRITE, l2_interface_pbb_tag_rewrite) \
75 _(BRIDGE_DOMAIN_SET_MAC_AGE, bridge_domain_set_mac_age) \
76 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath) \
77 _(BVI_CREATE, bvi_create) \
78 _(BVI_DELETE, bvi_delete) \
79 _(WANT_L2_ARP_TERM_EVENTS, want_l2_arp_term_events)
80 
81 static void
83  u32 rx_sw_if_index, u32 tx_sw_if_index)
84 {
86 
87  mp = vl_msg_api_alloc (sizeof (*mp));
88  clib_memset (mp, 0, sizeof (*mp));
89  mp->_vl_msg_id = ntohs (VL_API_L2_XCONNECT_DETAILS);
90  mp->context = context;
91  mp->rx_sw_if_index = htonl (rx_sw_if_index);
92  mp->tx_sw_if_index = htonl (tx_sw_if_index);
93 
94  vl_api_send_msg (reg, (u8 *) mp);
95 }
96 
97 static void
99 {
101  l2input_main_t *l2im = &l2input_main;
103  l2_input_config_t *config;
104 
106  if (!reg)
107  return;
108 
109  /* *INDENT-OFF* */
110  vec_foreach_index (sw_if_index, l2im->configs)
111  {
112  config = vec_elt_at_index (l2im->configs, sw_if_index);
113  if (l2_input_is_xconnect (config))
114  send_l2_xconnect_details (reg, mp->context, sw_if_index,
115  config->output_sw_if_index);
116  }
117  /* *INDENT-ON* */
118 }
119 
120 static void
122 {
123  int rv = 0;
124  vl_api_l2_fib_clear_table_reply_t *rmp;
125 
126  /* Clear all MACs including static MACs */
128 
129  REPLY_MACRO (VL_API_L2_FIB_CLEAR_TABLE_REPLY);
130 }
131 
132 static void
134  vl_api_registration_t * reg,
135  l2fib_entry_key_t * l2fe_key,
136  l2fib_entry_result_t * l2fe_res, u32 context)
137 {
139 
140  mp = vl_msg_api_alloc (sizeof (*mp));
141  clib_memset (mp, 0, sizeof (*mp));
142  mp->_vl_msg_id = ntohs (VL_API_L2_FIB_TABLE_DETAILS);
143 
144  mp->bd_id =
145  ntohl (l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
146 
147  mac_address_encode ((mac_address_t *) l2fe_key->fields.mac, mp->mac);
148  mp->sw_if_index = ntohl (l2fe_res->fields.sw_if_index);
149  mp->static_mac = (l2fib_entry_result_is_set_STATIC (l2fe_res) ? 1 : 0);
150  mp->filter_mac = (l2fib_entry_result_is_set_FILTER (l2fe_res) ? 1 : 0);
151  mp->bvi_mac = (l2fib_entry_result_is_set_BVI (l2fe_res) ? 1 : 0);
152  mp->context = context;
153 
154  vl_api_send_msg (reg, (u8 *) mp);
155 }
156 
157 static void
159 {
161  bd_main_t *bdm = &bd_main;
162  l2fib_entry_key_t *l2fe_key = NULL;
163  l2fib_entry_result_t *l2fe_res = NULL;
164  u32 ni, bd_id = ntohl (mp->bd_id);
165  u32 bd_index;
167  uword *p;
168 
170  if (!reg)
171  return;
172 
173  /* see l2fib_table_dump: ~0 means "any" */
174  if (bd_id == ~0)
175  bd_index = ~0;
176  else
177  {
178  p = hash_get (bdm->bd_index_by_bd_id, bd_id);
179  if (p == 0)
180  return;
181 
182  bd_index = p[0];
183  }
184 
185  l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
186 
187  vec_foreach_index (ni, l2fe_key)
188  {
189  send_l2fib_table_entry (am, reg, vec_elt_at_index (l2fe_key, ni),
190  vec_elt_at_index (l2fe_res, ni), mp->context);
191  }
192  vec_free (l2fe_key);
193  vec_free (l2fe_res);
194 }
195 
196 static void
198 {
199  bd_main_t *bdm = &bd_main;
200  l2input_main_t *l2im = &l2input_main;
201  vl_api_l2fib_add_del_reply_t *rmp;
202  int rv = 0;
203  u32 bd_id = ntohl (mp->bd_id);
204  uword *p = hash_get (bdm->bd_index_by_bd_id, bd_id);
205 
206  if (!p)
207  {
208  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
209  goto bad_sw_if_index;
210  }
211  u32 bd_index = p[0];
212 
214 
215  mac_address_decode (mp->mac, &mac);
216  if (mp->is_add)
217  {
218  if (mp->filter_mac)
219  l2fib_add_filter_entry (mac.bytes, bd_index);
220  else
221  {
223  u32 sw_if_index = ntohl (mp->sw_if_index);
225  if (vec_len (l2im->configs) <= sw_if_index)
226  {
227  rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
228  goto bad_sw_if_index;
229  }
230  else
231  {
232  l2_input_config_t *config;
233  config = vec_elt_at_index (l2im->configs, sw_if_index);
234  if (!l2_input_is_bridge (config))
235  {
236  rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
237  goto bad_sw_if_index;
238  }
239  }
240  if (mp->static_mac)
241  flags |= L2FIB_ENTRY_RESULT_FLAG_STATIC;
242  if (mp->bvi_mac)
243  flags |= L2FIB_ENTRY_RESULT_FLAG_BVI;
244  l2fib_add_entry (mac.bytes, bd_index, sw_if_index, flags);
245  }
246  }
247  else
248  {
249  u32 sw_if_index = ntohl (mp->sw_if_index);
250  if (l2fib_del_entry (mac.bytes, bd_index, sw_if_index))
251  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
252  }
253 
255 
256  REPLY_MACRO (VL_API_L2FIB_ADD_DEL_REPLY);
257 }
258 
259 static void
261 {
262  int rv = 0;
263  vl_api_want_l2_macs_events_reply_t *rmp;
266  u32 pid = ntohl (mp->pid);
267  u32 learn_limit = ntohl (mp->learn_limit);
268 
269  if (mp->enable_disable)
270  {
271  if (lm->client_pid == 0)
272  {
273  lm->client_pid = pid;
274  lm->client_index = mp->client_index;
275 
276  if (mp->max_macs_in_event)
277  fm->max_macs_in_event = mp->max_macs_in_event * 10;
278  else
279  {
280  rv = VNET_API_ERROR_INVALID_VALUE;
281  goto exit;
282  }
283 
284  if (mp->scan_delay)
285  fm->event_scan_delay = (f64) (mp->scan_delay) * 10e-3;
286  else
287  {
288  rv = VNET_API_ERROR_INVALID_VALUE;
289  goto exit;
290  }
291 
292  /* change learn limit and flush all learned MACs */
293  if (learn_limit && (learn_limit < L2LEARN_DEFAULT_LIMIT))
294  lm->global_learn_limit = learn_limit;
295  else
296  {
297  rv = VNET_API_ERROR_INVALID_VALUE;
298  goto exit;
299  }
300 
302  }
303  else if (lm->client_pid != pid)
304  {
305  rv = VNET_API_ERROR_L2_MACS_EVENT_CLINET_PRESENT;
306  goto exit;
307  }
308  }
309  else if (lm->client_pid)
310  {
311  lm->client_pid = 0;
312  lm->client_index = 0;
313  if (learn_limit && (learn_limit < L2LEARN_DEFAULT_LIMIT))
314  lm->global_learn_limit = learn_limit;
315  else
316  lm->global_learn_limit = L2LEARN_DEFAULT_LIMIT;
317  }
318 
319 exit:
320  REPLY_MACRO (VL_API_WANT_L2_MACS_EVENTS_REPLY);
321 }
322 
323 static void
325 {
326  int rv = 0;
328  vl_api_l2fib_flush_int_reply_t *rmp;
329 
331 
332  u32 sw_if_index = ntohl (mp->sw_if_index);
333  l2fib_flush_int_mac (vm, sw_if_index);
334 
336  REPLY_MACRO (VL_API_L2FIB_FLUSH_INT_REPLY);
337 }
338 
339 static void
341 {
342  int rv = 0;
343  vl_api_l2fib_flush_all_reply_t *rmp;
344 
346  REPLY_MACRO (VL_API_L2FIB_FLUSH_ALL_REPLY);
347 }
348 
349 static void
351 {
352  int rv = 0;
354  bd_main_t *bdm = &bd_main;
355  vl_api_l2fib_flush_bd_reply_t *rmp;
356 
357  u32 bd_id = ntohl (mp->bd_id);
358  uword *p = hash_get (bdm->bd_index_by_bd_id, bd_id);
359  if (p == 0)
360  {
361  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
362  goto out;
363  }
364  l2fib_flush_bd_mac (vm, *p);
365 out:
366  REPLY_MACRO (VL_API_L2FIB_FLUSH_BD_REPLY);
367 }
368 
369 static void
371 {
373  int rv = 0;
374  u32 rbm = 0;
375 
377 
378  u32 sw_if_index = ntohl (mp->sw_if_index);
379  u32 flags = ntohl (mp->feature_bitmap);
380  u32 bitmap = 0;
381 
382  if (flags & L2_LEARN)
383  bitmap |= L2INPUT_FEAT_LEARN;
384 
385  if (flags & L2_FWD)
386  bitmap |= L2INPUT_FEAT_FWD;
387 
388  if (flags & L2_FLOOD)
389  bitmap |= L2INPUT_FEAT_FLOOD;
390 
391  if (flags & L2_UU_FLOOD)
392  bitmap |= L2INPUT_FEAT_UU_FLOOD;
393 
394  if (flags & L2_ARP_TERM)
395  bitmap |= L2INPUT_FEAT_ARP_TERM;
396 
397  rbm = l2input_intf_bitmap_enable (sw_if_index, bitmap, mp->is_set);
398 
400 
401  /* *INDENT-OFF* */
402  REPLY_MACRO2(VL_API_L2_FLAGS_REPLY,
403  ({
404  rmp->resulting_feature_bitmap = ntohl(rbm);
405  }));
406  /* *INDENT-ON* */
407 }
408 
409 static void
411  * mp)
412 {
414  bd_main_t *bdm = &bd_main;
415  vl_api_bridge_domain_set_mac_age_reply_t *rmp;
416  int rv = 0;
417  u32 bd_id = ntohl (mp->bd_id);
418  uword *p;
419 
420  if (bd_id == 0)
421  {
422  rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
423  goto out;
424  }
425 
426  p = hash_get (bdm->bd_index_by_bd_id, bd_id);
427  if (p == 0)
428  {
429  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
430  goto out;
431  }
432  bd_set_mac_age (vm, *p, mp->mac_age);
433 out:
434  REPLY_MACRO (VL_API_BRIDGE_DOMAIN_SET_MAC_AGE_REPLY);
435 }
436 
437 static void
439 {
441  .is_add = mp->is_add,
442  .flood = mp->flood,
443  .uu_flood = mp->uu_flood,
444  .forward = mp->forward,
445  .learn = mp->learn,
446  .arp_term = mp->arp_term,
447  .arp_ufwd = mp->arp_ufwd,
448  .mac_age = mp->mac_age,
449  .bd_id = ntohl (mp->bd_id),
450  .bd_tag = mp->bd_tag
451  };
452 
453  int rv = bd_add_del (&a);
454 
455  vl_api_bridge_domain_add_del_reply_t *rmp;
456  REPLY_MACRO (VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
457 }
458 
459 static void
461  vl_api_registration_t * reg,
462  l2_bridge_domain_t * bd_config,
463  u32 n_sw_ifs, u32 context)
464 {
467  vl_api_bridge_domain_sw_if_t *sw_ifs;
468  l2_input_config_t *input_cfg;
469 
470  mp = vl_msg_api_alloc (sizeof (*mp) +
471  (n_sw_ifs * sizeof (vl_api_bridge_domain_sw_if_t)));
472  clib_memset (mp, 0, sizeof (*mp));
473  mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
474  mp->bd_id = ntohl (bd_config->bd_id);
475  mp->flood = bd_feature_flood (bd_config);
476  mp->uu_flood = bd_feature_uu_flood (bd_config);
477  mp->forward = bd_feature_forward (bd_config);
478  mp->learn = bd_feature_learn (bd_config);
479  mp->arp_term = bd_feature_arp_term (bd_config);
480  mp->arp_ufwd = bd_feature_arp_ufwd (bd_config);
481  mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
482  mp->uu_fwd_sw_if_index = ntohl (bd_config->uu_fwd_sw_if_index);
483  mp->mac_age = bd_config->mac_age;
484  if (bd_config->bd_tag)
485  {
486  strncpy ((char *) mp->bd_tag, (char *) bd_config->bd_tag,
487  ARRAY_LEN (mp->bd_tag) - 1);
488  mp->bd_tag[ARRAY_LEN (mp->bd_tag) - 1] = 0;
489  }
490 
491  mp->context = context;
492 
493  sw_ifs = (vl_api_bridge_domain_sw_if_t *) mp->sw_if_details;
494  vec_foreach (m, bd_config->members)
495  {
496  sw_ifs->sw_if_index = ntohl (m->sw_if_index);
497  input_cfg = vec_elt_at_index (l2im->configs, m->sw_if_index);
498  sw_ifs->shg = input_cfg->shg;
499  sw_ifs++;
500  mp->n_sw_ifs++;
501  }
502  mp->n_sw_ifs = htonl (mp->n_sw_ifs);
503 
504  vl_api_send_msg (reg, (u8 *) mp);
505 }
506 
507 static void
509 {
510  bd_main_t *bdm = &bd_main;
511  l2input_main_t *l2im = &l2input_main;
513  u32 bd_id, bd_index, end, filter_sw_if_index;
514 
516  if (!reg)
517  return;
518 
519  filter_sw_if_index = ntohl (mp->sw_if_index);
520  if (filter_sw_if_index != ~0)
521  return; /* UNIMPLEMENTED */
522 
523  bd_id = ntohl (mp->bd_id);
524  if (bd_id == 0)
525  return;
526 
527  if (bd_id == ~0)
528  bd_index = 0, end = vec_len (l2im->bd_configs);
529  else
530  {
531  bd_index = bd_find_index (bdm, bd_id);
532  if (bd_index == ~0)
533  return;
534 
535  end = bd_index + 1;
536  }
537 
538  for (; bd_index < end; bd_index++)
539  {
540  l2_bridge_domain_t *bd_config =
541  l2input_bd_config_from_index (l2im, bd_index);
542  /* skip placeholder bd_id 0 */
543  if (bd_config && (bd_config->bd_id > 0))
544  send_bridge_domain_details (l2im, reg, bd_config,
545  vec_len (bd_config->members),
546  mp->context);
547  }
548 }
549 
550 static bd_flags_t
551 bd_flags_decode (vl_api_bd_flags_t v)
552 {
553  bd_flags_t f = L2_NONE;
554 
555  v = ntohl (v);
556 
557  if (v & BRIDGE_API_FLAG_LEARN)
558  f |= L2_LEARN;
559  if (v & BRIDGE_API_FLAG_FWD)
560  f |= L2_FWD;
561  if (v & BRIDGE_API_FLAG_FLOOD)
562  f |= L2_FLOOD;
563  if (v & BRIDGE_API_FLAG_UU_FLOOD)
564  f |= L2_UU_FLOOD;
565  if (v & BRIDGE_API_FLAG_ARP_TERM)
566  f |= L2_ARP_TERM;
567  if (v & BRIDGE_API_FLAG_ARP_UFWD)
568  f |= L2_ARP_UFWD;
569 
570  return (f);
571 }
572 
573 static void
575 {
577  bd_main_t *bdm = &bd_main;
579  u32 bitmap = 0;
580  int rv = 0;
581 
583  u32 bd_id = ntohl (mp->bd_id);
584  if (bd_id == 0)
585  {
586  rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
587  goto out;
588  }
589 
590  u32 bd_index = bd_find_index (bdm, bd_id);
591  if (bd_index == ~0)
592  {
593  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
594  goto out;
595  }
596 
597  bitmap = bd_set_flags (vm, bd_index, flags, mp->is_set);
598 
599 out:
600  /* *INDENT-OFF* */
601  REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
602  ({
603  rmp->resulting_feature_bitmap = ntohl(bitmap);
604  }));
605  /* *INDENT-ON* */
606 }
607 
608 static void
611 {
612  int rv = 0;
613  vl_api_l2_interface_vlan_tag_rewrite_reply_t *rmp;
614  vnet_main_t *vnm = vnet_get_main ();
616  u32 vtr_op;
617 
619 
620  vtr_op = ntohl (mp->vtr_op);
621 
622  /* The L2 code is unsuspicious */
623  switch (vtr_op)
624  {
625  case L2_VTR_DISABLED:
626  case L2_VTR_PUSH_1:
627  case L2_VTR_PUSH_2:
628  case L2_VTR_POP_1:
629  case L2_VTR_POP_2:
634  break;
635 
636  default:
637  rv = VNET_API_ERROR_INVALID_VALUE;
638  goto bad_sw_if_index;
639  }
640 
641  rv = l2vtr_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
642  ntohl (mp->push_dot1q), ntohl (mp->tag1),
643  ntohl (mp->tag2));
644 
646 
647  REPLY_MACRO (VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
648 }
649 
650 static void
653 {
654  vl_api_l2_interface_pbb_tag_rewrite_reply_t *rmp;
655  vnet_main_t *vnm = vnet_get_main ();
657  u32 vtr_op;
658  int rv = 0;
659  mac_address_t b_dmac, b_smac;
660 
662 
663  vtr_op = ntohl (mp->vtr_op);
664 
665  switch (vtr_op)
666  {
667  case L2_VTR_DISABLED:
668  case L2_VTR_PUSH_2:
669  case L2_VTR_POP_2:
671  break;
672 
673  default:
674  rv = VNET_API_ERROR_INVALID_VALUE;
675  goto bad_sw_if_index;
676  }
677 
678  mac_address_decode (mp->b_dmac, &b_dmac);
679  mac_address_decode (mp->b_smac, &b_smac);
680 
681  rv = l2pbb_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
682  b_dmac.bytes, b_smac.bytes, ntohs (mp->b_vlanid),
683  ntohl (mp->i_sid), ntohs (mp->outer_tag));
684 
686 
687  REPLY_MACRO (VL_API_L2_INTERFACE_PBB_TAG_REWRITE_REPLY);
688 }
689 
690 static void
693 {
694  vl_api_sw_interface_set_l2_xconnect_reply_t *rmp;
695  int rv = 0;
696  u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
697  u32 tx_sw_if_index = ntohl (mp->tx_sw_if_index);
699  vnet_main_t *vnm = vnet_get_main ();
700 
702 
703  if (mp->enable)
704  {
706  rv = set_int_l2_mode (vm, vnm, MODE_L2_XC,
707  rx_sw_if_index, 0,
708  L2_BD_PORT_TYPE_NORMAL, 0, tx_sw_if_index);
709  }
710  else
711  {
712  rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0,
713  L2_BD_PORT_TYPE_NORMAL, 0, 0);
714  }
715 
716  switch (rv)
717  {
718  case MODE_ERROR_ETH:
719  rv = VNET_API_ERROR_NON_ETHERNET;
720  break;
721  case MODE_ERROR_BVI_DEF:
722  rv = VNET_API_ERROR_BD_ALREADY_HAS_BVI;
723  break;
724  }
725 
728 
729  REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
730 }
731 
732 static int
733 l2_bd_port_type_decode (vl_api_l2_port_type_t v, l2_bd_port_type_t * l)
734 {
735  v = clib_net_to_host_u32 (v);
736 
737  switch (v)
738  {
741  return 0;
743  *l = L2_BD_PORT_TYPE_BVI;
744  return 0;
747  return 0;
748  }
749 
750  return (VNET_API_ERROR_INVALID_VALUE);
751 }
752 
753 static void
756 {
757  bd_main_t *bdm = &bd_main;
758  vl_api_sw_interface_set_l2_bridge_reply_t *rmp;
759  int rv = 0;
761  vnet_main_t *vnm = vnet_get_main ();
763 
765  u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
766  rv = l2_bd_port_type_decode (mp->port_type, &pt);
767 
768  if (0 != rv)
769  goto out;
770  if (mp->enable)
771  {
772  VALIDATE_BD_ID (mp);
773  u32 bd_id = ntohl (mp->bd_id);
774  u32 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
775 
776  rv = set_int_l2_mode (vm, vnm, MODE_L2_BRIDGE,
777  rx_sw_if_index, bd_index, pt, mp->shg, 0);
778  }
779  else
780  {
781  rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, pt, 0, 0);
782  }
783 
784  switch (rv)
785  {
786  case MODE_ERROR_ETH:
787  rv = VNET_API_ERROR_NON_ETHERNET;
788  break;
789  case MODE_ERROR_BVI_DEF:
790  rv = VNET_API_ERROR_BD_ALREADY_HAS_BVI;
791  break;
792  }
793 
796 out:
797  REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
798 }
799 
800 static void
802  vl_api_registration_t * reg,
803  u32 bd_id,
804  const ip46_address_t * ip,
805  ip46_type_t itype,
806  const mac_address_t * mac, u32 context)
807 {
809 
810  mp = vl_msg_api_alloc (sizeof (*mp));
811  clib_memset (mp, 0, sizeof (*mp));
812  mp->_vl_msg_id = ntohs (VL_API_BD_IP_MAC_DETAILS);
813 
814  mp->context = context;
815  mp->entry.bd_id = ntohl (bd_id);
816 
817  ip_address_encode (ip, itype, &mp->entry.ip);
818  mac_address_encode (mac, mp->entry.mac);
819 
820  vl_api_send_msg (reg, (u8 *) mp);
821 }
822 
823 static void
825 {
827  bd_main_t *bdm = &bd_main;
828  l2_bridge_domain_t *bd_config;
829  u32 bd_id = ntohl (mp->bd_id);
830  u32 bd_index, start, end;
832  uword *p;
833 
835  if (!reg)
836  return;
837 
838  /* see bd_id: ~0 means "any" */
839  if (bd_id == ~0)
840  {
841  start = 1;
843  }
844  else
845  {
846  p = hash_get (bdm->bd_index_by_bd_id, bd_id);
847  if (p == 0)
848  return;
849 
850  bd_index = p[0];
852  start = bd_index;
853  end = start + 1;
854  }
855 
856  for (bd_index = start; bd_index < end; bd_index++)
857  {
858  bd_config = vec_elt_at_index (l2input_main.bd_configs, bd_index);
859  if (bd_is_valid (bd_config))
860  {
861  ip4_address_t ip4_addr;
862  ip6_address_t *ip6_addr;
864  u64 mac64;
865  bd_id = bd_config->bd_id;
866 
867  /* *INDENT-OFF* */
868  hash_foreach (ip4_addr.as_u32, mac64, bd_config->mac_by_ip4,
869  ({
870  ip46_address_t ip = {
871  .ip4 = ip4_addr,
872  };
873  mac_address_from_u64(&mac, mac64);
874 
875  send_bd_ip_mac_entry (am, reg, bd_id, &ip, IP46_TYPE_IP4,
876  &mac, mp->context);
877  }));
878 
879  hash_foreach_mem (ip6_addr, mac64, bd_config->mac_by_ip6,
880  ({
881  ip46_address_t ip = {
882  .ip6 = *ip6_addr,
883  };
884  mac_address_from_u64(&mac, mac64);
885 
886  send_bd_ip_mac_entry (am, reg, bd_id, &ip, IP46_TYPE_IP6,
887  &mac, mp->context);
888  }));
889  /* *INDENT-ON* */
890  }
891  }
892 }
893 
894 static void
896 {
897  ip46_address_t ip_addr = ip46_address_initializer;
898  vl_api_bd_ip_mac_add_del_reply_t *rmp;
899  bd_main_t *bdm = &bd_main;
900  u32 bd_index, bd_id;
903  int rv = 0;
904  uword *p;
905 
906  bd_id = ntohl (mp->entry.bd_id);
907 
908  if (bd_id == 0)
909  {
910  rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
911  goto out;
912  }
913 
914  p = hash_get (bdm->bd_index_by_bd_id, bd_id);
915  if (p == 0)
916  {
917  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
918  goto out;
919  }
920  bd_index = p[0];
921 
922  type = ip_address_decode (&mp->entry.ip, &ip_addr);
923  mac_address_decode (mp->entry.mac, &mac);
924 
925  if (bd_add_del_ip_mac (bd_index, type, &ip_addr, &mac, mp->is_add))
926  rv = VNET_API_ERROR_UNSPECIFIED;
927 
928 out:
929  REPLY_MACRO (VL_API_BD_IP_MAC_ADD_DEL_REPLY);
930 }
931 
932 static void
934 {
935  vl_api_bd_ip_mac_flush_reply_t *rmp;
936  bd_main_t *bdm = &bd_main;
937  u32 bd_index, bd_id;
938  int rv = 0;
939  uword *p;
940 
941  bd_id = ntohl (mp->bd_id);
942 
943  if (bd_id == 0)
944  {
945  rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
946  goto out;
947  }
948 
949  p = hash_get (bdm->bd_index_by_bd_id, bd_id);
950  if (p == 0)
951  {
952  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
953  goto out;
954  }
955  bd_index = p[0];
956 
957  bd_flush_ip_mac (bd_index);
958 
959 out:
960  REPLY_MACRO (VL_API_BD_IP_MAC_FLUSH_REPLY);
961 }
962 
964  u32 sw_if_index, u8 enable);
965 
966 static void
968  mp)
969 {
970  int rv;
971  vl_api_l2_interface_efp_filter_reply_t *rmp;
972  vnet_main_t *vnm = vnet_get_main ();
973 
975 
976  // enable/disable the feature
977  l2_efp_filter_configure (vnm, ntohl (mp->sw_if_index), mp->enable_disable);
978  rv = vnm->api_errno;
979 
981  REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
982 }
983 
984 static void
986 {
987  extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
988  int is_add);
989  vl_api_l2_patch_add_del_reply_t *rmp;
990  int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
991  int is_add);
992  int rv = 0;
993 
996 
997  rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
998  ntohl (mp->tx_sw_if_index),
999  (int) (mp->is_add != 0));
1000 
1003 
1004  REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
1005 }
1006 
1007 static void
1009 {
1010  vl_api_sw_interface_set_vpath_reply_t *rmp;
1011  int rv = 0;
1012  u32 sw_if_index = ntohl (mp->sw_if_index);
1013 
1014  VALIDATE_SW_IF_INDEX (mp);
1015 
1016  l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1017  vnet_feature_enable_disable ("ip4-unicast", "vpath-input-ip4",
1018  sw_if_index, mp->enable, 0, 0);
1019  vnet_feature_enable_disable ("ip4-multicast", "vpath-input-ip4",
1020  sw_if_index, mp->enable, 0, 0);
1021  vnet_feature_enable_disable ("ip6-unicast", "vpath-input-ip6",
1022  sw_if_index, mp->enable, 0, 0);
1023  vnet_feature_enable_disable ("ip6-multicast", "vpath-input-ip6",
1024  sw_if_index, mp->enable, 0, 0);
1025 
1027 
1028  REPLY_MACRO (VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1029 }
1030 
1031 static void
1033 {
1036  u32 sw_if_index;
1037  int rv;
1038 
1039  mac_address_decode (mp->mac, &mac);
1040 
1041  rv = l2_bvi_create (ntohl (mp->user_instance), &mac, &sw_if_index);
1042 
1043  /* *INDENT-OFF* */
1044  REPLY_MACRO2(VL_API_BVI_CREATE_REPLY,
1045  ({
1046  rmp->sw_if_index = ntohl (sw_if_index);
1047  }));
1048  /* *INDENT-ON* */
1049 }
1050 
1051 static void
1053 {
1054  vl_api_bvi_delete_reply_t *rmp;
1055  int rv;
1056 
1057  rv = l2_bvi_delete (ntohl (mp->sw_if_index));
1058 
1059  REPLY_MACRO (VL_API_BVI_DELETE_REPLY);
1060 }
1061 
1062 static bool
1064  const l2_arp_term_publish_event_t * e2)
1065 {
1066  if (e1 == NULL || e2 == NULL)
1067  return false;
1068  return (ip46_address_is_equal (&e1->ip, &e2->ip) &&
1069  (e1->sw_if_index == e2->sw_if_index) &&
1070  (mac_address_equal (&e1->mac, &e2->mac)));
1071 }
1072 
1073 static uword
1075  vlib_frame_t * f)
1076 {
1077  /* These cross the longjmp boundary (vlib_process_wait_for_event)
1078  * and need to be volatile - to prevent them from being optimized into
1079  * a register - which could change during suspension */
1080  volatile f64 last = vlib_time_now (vm);
1081  volatile l2_arp_term_publish_event_t last_event = { };
1082 
1084 
1085  while (1)
1086  {
1087  uword event_type = L2_ARP_TERM_EVENT_PUBLISH;
1089  f64 now;
1090 
1092 
1093  vlib_process_get_event_data (vm, &event_type);
1094  now = vlib_time_now (vm);
1095 
1096  if (event_type == L2_ARP_TERM_EVENT_PUBLISH)
1097  {
1099 
1100  vec_foreach (event, l2am->publish_events)
1101  {
1102  /* dampen duplicate events - cast away volatile */
1104  (event, (l2_arp_term_publish_event_t *) & last_event) &&
1105  (now - last) < 10.0)
1106  {
1107  continue;
1108  }
1109  last_event = *event;
1110  last = now;
1111 
1112  /* *INDENT-OFF* */
1113  pool_foreach (reg, vpe_api_main.l2_arp_term_events_registrations)
1114  {
1115  vl_api_registration_t *vl_reg;
1117  ALWAYS_ASSERT (vl_reg != NULL);
1118 
1119  if (reg && vl_api_can_send_msg (vl_reg))
1120  {
1121  vl_api_l2_arp_term_event_t * vevent;
1122  vevent = vl_msg_api_alloc (sizeof *vevent);
1123  clib_memset (vevent, 0, sizeof *vevent);
1124  vevent->_vl_msg_id = htons (VL_API_L2_ARP_TERM_EVENT);
1125  vevent->client_index = reg->client_index;
1126  vevent->pid = reg->client_pid;
1127  ip_address_encode(&event->ip,
1128  event->type,
1129  &vevent->ip);
1130  vevent->sw_if_index = htonl(event->sw_if_index);
1131  mac_address_encode(&event->mac, vevent->mac);
1132  vl_api_send_msg (vl_reg, (u8 *) vevent);
1133  }
1134  }
1135  /* *INDENT-ON* */
1136  }
1138  }
1139  }
1140 
1141  return 0;
1142 }
1143 
1144 /* *INDENT-OFF* */
1146  .function = l2_arp_term_process,
1147  .type = VLIB_NODE_TYPE_PROCESS,
1148  .name = "l2-arp-term-publisher",
1149 };
1150 /* *INDENT-ON* */
1151 
1152 static void
1154  mp)
1155 {
1156  vl_api_want_l2_arp_term_events_reply_t *rmp;
1159  int rv = 0;
1160  uword *p;
1161 
1162  p = hash_get (am->l2_arp_term_events_registration_hash, mp->client_index);
1163 
1164  if (p)
1165  {
1166  if (mp->enable)
1167  {
1168  clib_warning ("pid %d: already enabled...", mp->pid);
1169  rv = VNET_API_ERROR_INVALID_REGISTRATION;
1170  goto reply;
1171  }
1172  else
1173  {
1174  rp = pool_elt_at_index (am->l2_arp_term_events_registrations, p[0]);
1175  pool_put (am->l2_arp_term_events_registrations, rp);
1176  hash_unset (am->l2_arp_term_events_registration_hash,
1177  mp->client_index);
1178  if (pool_elts (am->l2_arp_term_events_registrations) == 0)
1180  goto reply;
1181  }
1182  }
1183  if (mp->enable == 0)
1184  {
1185  clib_warning ("pid %d: already disabled...", mp->pid);
1186  rv = VNET_API_ERROR_INVALID_REGISTRATION;
1187  goto reply;
1188  }
1189  pool_get (am->l2_arp_term_events_registrations, rp);
1190  rp->client_index = mp->client_index;
1191  rp->client_pid = mp->pid;
1192  hash_set (am->l2_arp_term_events_registration_hash, rp->client_index,
1193  rp - am->l2_arp_term_events_registrations);
1195 
1196 reply:
1197  REPLY_MACRO (VL_API_WANT_L2_ARP_TERM_EVENTS_REPLY);
1198 }
1199 
1200 static clib_error_t *
1202 {
1204  vpe_api_main_t *am;
1205  uword *p;
1206 
1207  am = &vpe_api_main;
1208 
1209  /* remove from the registration hash */
1210  p = hash_get (am->l2_arp_term_events_registration_hash, client_index);
1211 
1212  if (p)
1213  {
1214  rp = pool_elt_at_index (am->l2_arp_term_events_registrations, p[0]);
1215  pool_put (am->l2_arp_term_events_registrations, rp);
1216  hash_unset (am->l2_arp_term_events_registration_hash, client_index);
1217  if (pool_elts (am->l2_arp_term_events_registrations) == 0)
1219  }
1220  return (NULL);
1221 }
1222 
1224 
1225 /*
1226  * l2_api_hookup
1227  * Add vpe's API message handlers to the table.
1228  * vlib has already mapped shared memory and
1229  * added the client registration handlers.
1230  * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
1231  */
1232 #define vl_msg_name_crc_list
1233 #include <vnet/vnet_all_api_h.h>
1234 #undef vl_msg_name_crc_list
1235 
1236 static void
1238 {
1239 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
1240  foreach_vl_msg_name_crc_l2;
1241 #undef _
1242 }
1243 
1244 static clib_error_t *
1246 {
1247  api_main_t *am = vlibapi_get_main ();
1248 
1249 #define _(N,n) \
1250  vl_msg_api_set_handlers(VL_API_##N, #n, \
1251  vl_api_##n##_t_handler, \
1252  vl_noop_handler, \
1253  vl_api_##n##_t_endian, \
1254  vl_api_##n##_t_print, \
1255  sizeof(vl_api_##n##_t), 1);
1257 #undef _
1258 
1259  /* Mark VL_API_BRIDGE_DOMAIN_DUMP as mp safe */
1260  am->is_mp_safe[VL_API_BRIDGE_DOMAIN_DUMP] = 1;
1261 
1262  /*
1263  * Set up the (msg_name, crc, message-id) table
1264  */
1266 
1267  return 0;
1268 }
1269 
1271 
1272 /*
1273  * fd.io coding-style-patch-verification: ON
1274  *
1275  * Local Variables:
1276  * eval: (c-set-style "gnu")
1277  * End:
1278  */
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:509
static void vl_api_want_l2_arp_term_events_t_handler(vl_api_want_l2_arp_term_events_t *mp)
Definition: l2_api.c:1153
static_always_inline u8 bd_feature_forward(l2_bridge_domain_t *bd_config)
Definition: l2_input.h:207
static void vl_api_l2_fib_table_dump_t_handler(vl_api_l2_fib_table_dump_t *mp)
Definition: l2_api.c:158
#define BAD_RX_SW_IF_INDEX_LABEL
static bd_flags_t bd_flags_decode(vl_api_bd_flags_t v)
Definition: l2_api.c:551
#define vec_foreach_index(var, v)
Iterate over vector indices.
vl_api_mac_address_t b_smac
Definition: l2.api:416
vl_api_mac_address_t mac
Definition: l2.api:57
L2 FIB add entry request.
Definition: l2.api:130
vl_api_address_t ip
Definition: l2.api:640
struct l2fib_entry_result_t_::@471::@473 fields
#define hash_set(h, key, value)
Definition: hash.h:255
l2_input_config_t * configs
Definition: l2_input.h:90
Set bridge flags response.
Definition: l2.api:369
#define VALIDATE_TX_SW_IF_INDEX(mp)
u32 uu_fwd_sw_if_index
Definition: l2_bd.h:80
l2 fib table details structure
Definition: l2.api:53
static void vl_api_bvi_delete_t_handler(vl_api_bvi_delete_t *mp)
Definition: l2_api.c:1052
vl_api_bd_ip_mac_t entry
Definition: l2.api:533
vl_api_mac_address_t mac
Definition: l2.api:502
vlib_node_registration_t l2_arp_term_process_node
(constructor) VLIB_REGISTER_NODE (l2_arp_term_process_node)
Definition: l2_api.c:1145
#define hash_unset(h, key)
Definition: hash.h:261
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105
u32 user_instance[default=0xffffffff]
Definition: l2.api:586
a
Definition: bitmap.h:544
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
static uword * vlib_process_wait_for_event(vlib_main_t *vm)
Definition: node_funcs.h:656
vl_api_l2_port_type_t port_type
Definition: l2.api:484
vl_api_mac_address_t mac
Definition: l2.api:642
#define ntohs(x)
Definition: af_xdp.bpf.c:29
l2_arp_term_publish_event_t * publish_events
Definition: l2_arp_term.h:38
u32 bd_add_del_ip_mac(u32 bd_index, ip46_type_t type, const ip46_address_t *ip, const mac_address_t *mac, u8 is_add)
Add/delete IP address to MAC address mapping.
Definition: l2_bd.c:852
vl_api_interface_index_t sw_if_index
Definition: l2.api:598
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
static void vl_api_sw_interface_set_l2_bridge_t_handler(vl_api_sw_interface_set_l2_bridge_t *mp)
Definition: l2_api.c:755
Create BVI interface instance request.
Definition: l2.api:581
u32 bvi_sw_if_index
Definition: l2_bd.h:74
void mac_address_encode(const mac_address_t *in, u8 *out)
#define pool_foreach(VAR, POOL)
Iterate through pool.
Definition: pool.h:527
static void vl_api_l2_patch_add_del_t_handler(vl_api_l2_patch_add_del_t *mp)
Definition: l2_api.c:985
static void vl_api_l2_flags_t_handler(vl_api_l2_flags_t *mp)
Definition: l2_api.c:370
bool is_add[default=true]
Definition: l2.api:434
unsigned long u64
Definition: types.h:89
#define REPLY_MACRO2(t, body)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vl_api_interface_index_t sw_if_index
Definition: l2.api:557
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:334
static void vl_api_send_msg(vl_api_registration_t *rp, u8 *elem)
Definition: api.h:35
Definition: l2_bd.h:151
VLIB_API_INIT_FUNCTION(l2_api_hookup)
bool is_add[default=true]
Definition: l2.api:276
static heap_elt_t * last(heap_header_t *h)
Definition: heap.c:53
L2 bridge domain set mac age.
Definition: l2.api:242
bool is_add[default=true]
Definition: l2.api:509
vl_api_interface_index_t rx_sw_if_index
Definition: l2.api:31
l2_flood_member_t * members
Definition: l2_bd.h:86
Dump L2 XConnects.
Definition: l2.api:39
static void vl_api_bridge_domain_add_del_t_handler(vl_api_bridge_domain_add_del_t *mp)
Definition: l2_api.c:438
vl_api_interface_index_t sw_if_index
Definition: l2.api:412
vl_api_interface_index_t rx_sw_if_index
Definition: l2.api:482
void l2_arp_term_set_publisher_node(bool on)
Definition: l2_arp_term.c:103
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:82
vlib_main_t * vm
Definition: in2out_ed.c:1580
static void vl_api_bd_ip_mac_dump_t_handler(vl_api_bd_ip_mac_dump_t *mp)
Definition: l2_api.c:824
u32 max_macs_in_event
Definition: l2_fib.h:65
enum l2fib_entry_result_flags_t_ l2fib_entry_result_flags_t
u32 bd_id[default=0xffffffff]
Definition: l2.api:289
L2 bridge domain request operational state details.
Definition: l2.api:285
int bd_add_del(l2_bridge_domain_add_del_args_t *a)
Definition: l2_bd.c:1268
bridge domain IP to MAC entry details structure
Definition: l2.api:530
static_always_inline u8 bd_feature_uu_flood(l2_bridge_domain_t *bd_config)
Definition: l2_input.h:200
static void vl_api_l2fib_add_del_t_handler(vl_api_l2fib_add_del_t *mp)
Definition: l2_api.c:197
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:251
void * vl_msg_api_alloc(int nbytes)
unsigned char u8
Definition: types.h:56
u32 client_index
Definition: l2_learn.h:40
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
double f64
Definition: types.h:142
#define fm
Definition: l2_fib.h:160
Reply to l2_xconnect_dump.
Definition: l2.api:28
u8 max_macs_in_event[default=10]
Definition: l2.api:158
static_always_inline u8 bd_feature_arp_ufwd(l2_bridge_domain_t *bd_config)
Definition: l2_input.h:227
static int vl_api_can_send_msg(vl_api_registration_t *rp)
Definition: api.h:48
vl_api_interface_index_t sw_if_index[default=0xffffffff]
Definition: l2.api:290
L2 bridge domain operational state response.
Definition: l2.api:318
l2learn_main_t l2learn_main
Definition: l2_learn.c:32
static void vl_api_bd_ip_mac_flush_t_handler(vl_api_bd_ip_mac_flush_t *mp)
Definition: l2_api.c:933
u32 output_sw_if_index
Definition: l2_input.h:56
#define MODE_L2_BRIDGE
Definition: l2_input.h:283
bool enable[default=true]
Definition: l2.api:450
#define hash_foreach(key_var, value_var, h, body)
Definition: hash.h:442
u32 feature_bitmap
Definition: l2.api:221
#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:220
static void vl_api_l2_fib_clear_table_t_handler(vl_api_l2_fib_clear_table_t *mp)
Definition: l2_api.c:121
vl_api_interface_index_t sw_if_index
Definition: l2.api:641
L2 FIB flush bridge domain entries.
Definition: l2.api:100
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:443
#define ALWAYS_ASSERT(truth)
unsigned int u32
Definition: types.h:88
vl_api_interface_index_t tx_sw_if_index
Definition: l2.api:32
l2input_main_t l2input_main
Definition: l2_input_node.c:78
uword * bd_index_by_bd_id
Definition: l2_bd.h:36
ip46_type_t ip_address_decode(const vl_api_address_t *in, ip46_address_t *out)
Decode/Encode for struct/union types.
Definition: ip_types_api.c:186
vl_api_mac_address_t mac
Definition: l2.api:134
Dump l2 fib (aka bridge domain) table.
Definition: l2.api:68
vl_api_fib_path_type_t type
Definition: fib_types.api:123
bool enable_disable[default=true]
Definition: l2.api:558
static_always_inline u8 bd_feature_flood(l2_bridge_domain_t *bd_config)
Definition: l2_input.h:193
vnet_api_error_t api_errno
Definition: vnet.h:90
vl_api_interface_index_t sw_if_index
Definition: l2.api:389
#define hash_get(h, key)
Definition: hash.h:249
f64 event_scan_delay
Definition: l2_fib.h:62
Set interface L2 flags (such as L2_LEARN, L2_FWD, L2_FLOOD, L2_UU_FLOOD, or L2_ARP_TERM bits)...
Definition: l2.api:215
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:546
L2 FIB flush all entries.
Definition: l2.api:89
L2 fib clear table request, clear all mac entries in the l2 fib.
Definition: l2.api:79
vl_api_interface_index_t uu_fwd_sw_if_index
Definition: l2.api:331
vl_api_interface_index_t sw_if_index
Definition: l2.api:571
bool enable_disable[default=true]
Definition: l2.api:159
u32 bd_id
Definition: gbp.api:188
Set interface L2 flags response.
Definition: l2.api:229
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:301
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:865
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:895
#define REPLY_MACRO(t)
#define BAD_TX_SW_IF_INDEX_LABEL
vnet_main_t vnet_main
Definition: misc.c:43
void l2fib_flush_all_mac(vlib_main_t *vm)
Flush all non static MACs - flushes all valid BDs.
Definition: l2_fib.c:876
static_always_inline void mac_address_from_u64(mac_address_t *mac, u64 u)
Definition: mac_address.h:122
bool enable[default=true]
Definition: l2.api:486
Tell client about an IP4 ARP resolution event or MAC/IP info from ARP requests in L2 BDs...
Definition: l2.api:636
vl_api_interface_index_t sw_if_index
Definition: l2.api:116
VL_MSG_API_REAPER_FUNCTION(want_l2_arp_term_events_reaper)
static_always_inline int mac_address_equal(const mac_address_t *a, const mac_address_t *b)
Definition: mac_address.h:140
vl_api_interface_index_t tx_sw_if_index
Definition: l2.api:449
Create BVI interface instance response.
Definition: l2.api:594
#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:1245
l2fib_main_t l2fib_main
Definition: l2_fib.c:54
static u32 bd_is_valid(l2_bridge_domain_t *bd_config)
Definition: l2_bd.h:134
static u8 ip46_address_is_equal(const ip46_address_t *ip46_1, const ip46_address_t *ip46_2)
Definition: ip46_address.h:93
Definition: l2_bd.h:149
vl_api_interface_index_t sw_if_index
Definition: l2.api:219
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:227
vl_api_interface_index_t sw_if_index
Definition: l2.api:610
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
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:339
An API client registration, only in vpp/vlib.
Definition: api_common.h:47
#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:460
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:170
u32 l2fib_del_entry(const u8 *mac, u32 bd_index, u32 sw_if_index)
Delete an entry from the l2fib.
Definition: l2_fib.c:732
int l2_bvi_delete(u32 sw_if_index)
Definition: l2_bvi.c:210
vl_api_interface_index_t sw_if_index
Definition: l2.api:58
static void send_bd_ip_mac_entry(vpe_api_main_t *am, vl_api_registration_t *reg, u32 bd_id, const ip46_address_t *ip, ip46_type_t itype, const mac_address_t *mac, u32 context)
Definition: l2_api.c:801
static void vl_api_l2_xconnect_dump_t_handler(vl_api_l2_xconnect_dump_t *mp)
Definition: l2_api.c:98
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:380
#define foreach_vpe_api_msg
Definition: l2_api.c:53
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:289
#define MODE_ERROR_ETH
Definition: l2_input.h:287
static_always_inline u8 bd_feature_learn(l2_bridge_domain_t *bd_config)
Definition: l2_input.h:213
#define clib_warning(format, args...)
Definition: error.h:59
static void setup_message_id_table(api_main_t *am)
Definition: l2_api.c:1237
vl_api_interface_index_t bvi_sw_if_index
Definition: l2.api:330
vl_api_interface_index_t tx_sw_if_index
Definition: l2.api:433
void l2fib_clear_table(void)
Definition: l2_fib.c:384
static clib_error_t * want_l2_arp_term_events_reaper(u32 client_index)
Definition: l2_api.c:1201
#define ARRAY_LEN(x)
Definition: clib.h:67
uword * mac_by_ip6
Definition: l2_bd.h:102
static vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
Definition: api.h:79
u8 scan_delay[default=10]
Definition: l2.api:157
static bool l2_arp_term_publish_event_is_equal(const l2_arp_term_publish_event_t *e1, const l2_arp_term_publish_event_t *e2)
Definition: l2_api.c:1063
#define VALIDATE_RX_SW_IF_INDEX(mp)
static bool l2_input_is_bridge(const l2_input_config_t *input)
Definition: l2_input.h:234
vl_api_interface_index_t rx_sw_if_index
Definition: l2.api:432
Dump bridge domain IP to MAC entries.
Definition: l2.api:540
bool enable[default=0xffffffff]
Definition: l2.api:572
void bd_flush_ip_mac(u32 bd_index)
Flush IP address to MAC address mapping tables in a BD.
Definition: l2_bd.c:929
Set L2 XConnect between two interfaces request.
Definition: l2.api:444
vl_api_interface_index_t rx_sw_if_index
Definition: l2.api:448
vl_api_interface_index_t tx_sw_if_index
Definition: ip.api:441
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:195
bool is_add[default=true]
Definition: l2.api:137
static_always_inline l2_bridge_domain_t * l2input_bd_config_from_index(l2input_main_t *l2im, u32 bd_index)
Definition: l2_input.h:105
Definition: l2_fib.h:77
Register to receive L2 MAC events for learned and aged MAC.
Definition: l2.api:152
static bool l2_input_is_xconnect(const l2_input_config_t *input)
Definition: l2_input.h:240
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:256
u32 l2input_intf_bitmap_enable(u32 sw_if_index, l2input_feat_masks_t feature_bitmap, u32 enable)
Enable (or disable) the feature in the bitmap for the given interface.
Definition: l2_input.c:177
#define BAD_BD_ID_LABEL
u32 global_learn_limit
Definition: l2_learn.h:36
#define VALIDATE_BD_ID(mp)
#define MODE_L2_XC
Definition: l2_input.h:284
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
u32 resulting_feature_bitmap
Definition: l2.api:233
static void vl_api_l2_interface_vlan_tag_rewrite_t_handler(vl_api_l2_interface_vlan_tag_rewrite_t *mp)
Definition: l2_api.c:610
Interface bridge mode request.
Definition: l2.api:478
vl_api_interface_index_t sw_if_index
Definition: l2.api:136
static void vl_api_sw_interface_set_l2_xconnect_t_handler(vl_api_sw_interface_set_l2_xconnect_t *mp)
Definition: l2_api.c:692
static void vl_api_bvi_create_t_handler(vl_api_bvi_create_t *mp)
Definition: l2_api.c:1032
L2 FIB flush interface entries.
Definition: l2.api:112
static void * vlib_process_get_event_data(vlib_main_t *vm, uword *return_event_type_opaque)
Definition: node_funcs.h:526
static void vl_api_l2fib_flush_bd_t_handler(vl_api_l2fib_flush_bd_t *mp)
Definition: l2_api.c:350
vl_api_address_t ip
Definition: l2.api:501
vl_api_bd_flags_t flags
Definition: l2.api:361
#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:260
Register for IP4 ARP resolution event on receiving ARP reply or MAC/IP info from ARP requests in L2 B...
Definition: l2.api:620
u64 uword
Definition: types.h:112
L2 interface ethernet flow point filtering enable/disable request.
Definition: l2.api:553
u32 pid
Definition: dhcp.api:164
static void vl_api_bridge_flags_t_handler(vl_api_bridge_flags_t *mp)
Definition: l2_api.c:574
int vnet_l2_patch_add_del(u32 rx_sw_if_index, u32 tx_sw_if_index, int is_add)
Definition: l2_patch.c:232
static void vl_api_l2_interface_efp_filter_t_handler(vl_api_l2_interface_efp_filter_t *mp)
Definition: l2_api.c:967
vl_api_mac_address_t b_dmac
Definition: l2.api:415
L2 interface vlan tag rewrite configure request.
Definition: l2.api:385
static void vl_api_l2fib_flush_all_t_handler(vl_api_l2fib_flush_all_t *mp)
Definition: l2_api.c:340
l2_bridge_domain_t * bd_configs
Definition: l2_input.h:93
static void l2fib_add_filter_entry(const u8 *mac, u32 bd_index)
Definition: l2_fib.h:453
static void vl_api_bridge_domain_set_mac_age_t_handler(vl_api_bridge_domain_set_mac_age_t *mp)
Definition: l2_api.c:410
void ip_address_encode(const ip46_address_t *in, ip46_type_t type, vl_api_address_t *out)
Definition: ip_types_api.c:220
L2 interface patch add / del request.
Definition: l2.api:428
void l2fib_table_dump(u32 bd_index, l2fib_entry_key_t **l2fe_key, l2fib_entry_result_t **l2fe_res)
Definition: l2_fib.c:133
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:133
static api_main_t * vlibapi_get_main(void)
Definition: api_common.h:389
Interface set vpath request.
Definition: l2.api:567
#define MODE_ERROR_BVI_DEF
Definition: l2_input.h:288
static int l2_bd_port_type_decode(vl_api_l2_port_type_t v, l2_bd_port_type_t *l)
Definition: l2_api.c:733
u8 * is_mp_safe
Message is mp safe vector.
Definition: api_common.h:250
L2 interface pbb tag rewrite configure request.
Definition: l2.api:408
u32 learn_limit[default=1000]
Definition: l2.api:156
#define vec_foreach(var, vec)
Vector iterator.
uword * mac_by_ip4
Definition: l2_bd.h:101
Set bridge flags request.
Definition: l2.api:355
f64 end
end of the time range
Definition: mactime.api:44
Delete BVI interface request.
Definition: l2.api:606
vl_api_bridge_domain_sw_if_t sw_if_details[n_sw_ifs]
Definition: l2.api:333
u32 sw_if_index
Definition: l2_bd.h:55
struct l2fib_entry_key_t::@467::@469 fields
u32 bd_find_index(bd_main_t *bdm, u32 bd_id)
Get a bridge domain.
Definition: l2_bd.c:70
vl_api_bd_ip_mac_t entry
Definition: l2.api:510
bd_main_t bd_main
Definition: l2_bd.c:44
vpe_api_main_t vpe_api_main
Definition: interface_api.c:54
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.
u32 client_pid
Definition: l2_learn.h:39
l2_arp_term_main_t l2_arp_term_main
Definition: l2_arp_term.c:33
void mac_address_decode(const u8 *in, mac_address_t *out)
Conversion functions to/from (decode/encode) API types to VPP internal types.
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:855
static void vl_api_l2fib_flush_int_t_handler(vl_api_l2fib_flush_int_t *mp)
Definition: l2_api.c:324
Flush bridge domain IP to MAC entries.
Definition: l2.api:517
#define ip46_address_initializer
Definition: ip46_address.h:52
static uword l2_arp_term_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
Definition: l2_api.c:1074
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
static void vl_api_l2_interface_pbb_tag_rewrite_t_handler(vl_api_l2_interface_pbb_tag_rewrite_t *mp)
Definition: l2_api.c:652
vl_api_mac_address_t mac
Definition: l2.api:585
#define L2LEARN_DEFAULT_LIMIT
Definition: l2_learn.h:50
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:303
int l2_bvi_create(u32 user_instance, const mac_address_t *mac_in, u32 *sw_if_indexp)
Definition: l2_bvi.c:136
#define VALIDATE_SW_IF_INDEX(mp)
#define MODE_L3
Definition: l2_input.h:282
enum bd_flags_t_ bd_flags_t
ip46_type_t
Definition: ip46_address.h:22
static void vl_api_bridge_domain_dump_t_handler(vl_api_bridge_domain_dump_t *mp)
Definition: l2_api.c:508
L2 bridge domain add or delete request.
Definition: l2.api:263
static void vl_api_sw_interface_set_vpath_t_handler(vl_api_sw_interface_set_vpath_t *mp)
Definition: l2_api.c:1008
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:127