FD.io VPP  v18.07.1-19-g511ce25
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 
30 #include <vnet/vnet_msg_enum.h>
31 
32 #define vl_typedefs /* define message structures */
33 #include <vnet/vnet_all_api_h.h>
34 #undef vl_typedefs
35 
36 #define vl_endianfun /* define message structures */
37 #include <vnet/vnet_all_api_h.h>
38 #undef vl_endianfun
39 
40 #define vl_api_bridge_domain_details_t_endian vl_noop_handler
41 #define vl_api_bridge_domain_details_t_print vl_noop_handler
42 
43 /* instantiate all the print functions we know about */
44 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
45 #define vl_printfun
46 #include <vnet/vnet_all_api_h.h>
47 #undef vl_printfun
48 
50 
51 #define foreach_vpe_api_msg \
52 _(L2_XCONNECT_DUMP, l2_xconnect_dump) \
53 _(L2_FIB_CLEAR_TABLE, l2_fib_clear_table) \
54 _(L2_FIB_TABLE_DUMP, l2_fib_table_dump) \
55 _(L2FIB_FLUSH_ALL, l2fib_flush_all) \
56 _(L2FIB_FLUSH_INT, l2fib_flush_int) \
57 _(L2FIB_FLUSH_BD, l2fib_flush_bd) \
58 _(L2FIB_ADD_DEL, l2fib_add_del) \
59 _(WANT_L2_MACS_EVENTS, want_l2_macs_events) \
60 _(L2_FLAGS, l2_flags) \
61 _(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect) \
62 _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \
63 _(L2_PATCH_ADD_DEL, l2_patch_add_del) \
64 _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \
65 _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
66 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \
67 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \
68 _(BRIDGE_FLAGS, bridge_flags) \
69 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
70 _(L2_INTERFACE_PBB_TAG_REWRITE, l2_interface_pbb_tag_rewrite) \
71 _(BRIDGE_DOMAIN_SET_MAC_AGE, bridge_domain_set_mac_age) \
72 _(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath)
73 
74 static void
76  u32 rx_sw_if_index, u32 tx_sw_if_index)
77 {
79 
80  mp = vl_msg_api_alloc (sizeof (*mp));
81  memset (mp, 0, sizeof (*mp));
82  mp->_vl_msg_id = ntohs (VL_API_L2_XCONNECT_DETAILS);
83  mp->context = context;
84  mp->rx_sw_if_index = htonl (rx_sw_if_index);
85  mp->tx_sw_if_index = htonl (tx_sw_if_index);
86 
87  vl_api_send_msg (reg, (u8 *) mp);
88 }
89 
90 static void
92 {
94  vnet_main_t *vnm = vnet_get_main ();
97  vnet_sw_interface_t *swif;
98  l2_input_config_t *config;
99 
101  if (!reg)
102  return;
103 
104  /* *INDENT-OFF* */
105  pool_foreach (swif, im->sw_interfaces,
106  ({
107  config = vec_elt_at_index (l2im->configs, swif->sw_if_index);
108  if (config->xconnect)
109  send_l2_xconnect_details (reg, mp->context, swif->sw_if_index,
110  config->output_sw_if_index);
111  }));
112  /* *INDENT-ON* */
113 }
114 
115 static void
117 {
118  int rv = 0;
119  vl_api_l2_fib_clear_table_reply_t *rmp;
120 
121  /* Clear all MACs including static MACs */
123 
124  REPLY_MACRO (VL_API_L2_FIB_CLEAR_TABLE_REPLY);
125 }
126 
127 static void
129  vl_api_registration_t * reg,
130  l2fib_entry_key_t * l2fe_key,
131  l2fib_entry_result_t * l2fe_res, u32 context)
132 {
134 
135  mp = vl_msg_api_alloc (sizeof (*mp));
136  memset (mp, 0, sizeof (*mp));
137  mp->_vl_msg_id = ntohs (VL_API_L2_FIB_TABLE_DETAILS);
138 
139  mp->bd_id =
140  ntohl (l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
141 
142  clib_memcpy (mp->mac, l2fe_key->fields.mac, 6);
143  mp->sw_if_index = ntohl (l2fe_res->fields.sw_if_index);
144  mp->static_mac = l2fe_res->fields.static_mac;
145  mp->filter_mac = l2fe_res->fields.filter;
146  mp->bvi_mac = l2fe_res->fields.bvi;
147  mp->context = context;
148 
149  vl_api_send_msg (reg, (u8 *) mp);
150 }
151 
152 static void
154 {
156  bd_main_t *bdm = &bd_main;
157  l2fib_entry_key_t *l2fe_key = NULL;
158  l2fib_entry_result_t *l2fe_res = NULL;
159  u32 ni, bd_id = ntohl (mp->bd_id);
160  u32 bd_index;
162  uword *p;
163 
165  if (!reg)
166  return;
167 
168  /* see l2fib_table_dump: ~0 means "any" */
169  if (bd_id == ~0)
170  bd_index = ~0;
171  else
172  {
173  p = hash_get (bdm->bd_index_by_bd_id, bd_id);
174  if (p == 0)
175  return;
176 
177  bd_index = p[0];
178  }
179 
180  l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
181 
182  vec_foreach_index (ni, l2fe_key)
183  {
184  send_l2fib_table_entry (am, reg, vec_elt_at_index (l2fe_key, ni),
185  vec_elt_at_index (l2fe_res, ni), mp->context);
186  }
187  vec_free (l2fe_key);
188  vec_free (l2fe_res);
189 }
190 
191 static void
193 {
194  bd_main_t *bdm = &bd_main;
195  l2input_main_t *l2im = &l2input_main;
196  vl_api_l2fib_add_del_reply_t *rmp;
197  int rv = 0;
198  u32 bd_id = ntohl (mp->bd_id);
199  uword *p = hash_get (bdm->bd_index_by_bd_id, bd_id);
200 
201  if (!p)
202  {
203  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
204  goto bad_sw_if_index;
205  }
206  u32 bd_index = p[0];
207 
208  u8 mac[6];
209 
210  clib_memcpy (mac, mp->mac, 6);
211  if (mp->is_add)
212  {
213  if (mp->filter_mac)
214  l2fib_add_filter_entry (mac, bd_index);
215  else
216  {
217  u32 sw_if_index = ntohl (mp->sw_if_index);
219  if (vec_len (l2im->configs) <= sw_if_index)
220  {
221  rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
222  goto bad_sw_if_index;
223  }
224  else
225  {
226  l2_input_config_t *config;
227  config = vec_elt_at_index (l2im->configs, sw_if_index);
228  if (config->bridge == 0)
229  {
230  rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
231  goto bad_sw_if_index;
232  }
233  }
234  u8 static_mac = mp->static_mac ? 1 : 0;
235  u8 bvi_mac = mp->bvi_mac ? 1 : 0;
236  l2fib_add_fwd_entry (mac, bd_index, sw_if_index, static_mac,
237  bvi_mac);
238  }
239  }
240  else
241  {
242  u32 sw_if_index = ntohl (mp->sw_if_index);
243  if (l2fib_del_entry (mac, bd_index, sw_if_index))
244  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
245  }
246 
248 
249  REPLY_MACRO (VL_API_L2FIB_ADD_DEL_REPLY);
250 }
251 
252 static void
254 {
255  int rv = 0;
256  vl_api_want_l2_macs_events_reply_t *rmp;
258  l2fib_main_t *fm = &l2fib_main;
259  u32 pid = ntohl (mp->pid);
260  u32 learn_limit = ntohl (mp->learn_limit);
261 
262  if (mp->enable_disable)
263  {
264  if (lm->client_pid == 0)
265  {
266  lm->client_pid = pid;
267  lm->client_index = mp->client_index;
268 
269  if (mp->max_macs_in_event)
270  fm->max_macs_in_event = mp->max_macs_in_event * 10;
271  else
273 
274  if (mp->scan_delay)
275  fm->event_scan_delay = (f64) (mp->scan_delay) * 10e-3;
276  else
278 
279  /* change learn limit and flush all learned MACs */
280  if (learn_limit && (learn_limit < L2LEARN_DEFAULT_LIMIT))
281  lm->global_learn_limit = learn_limit;
282  else
284 
286  }
287  else if (lm->client_pid != pid)
288  {
289  rv = VNET_API_ERROR_L2_MACS_EVENT_CLINET_PRESENT;
290  goto exit;
291  }
292  }
293  else if (lm->client_pid)
294  {
295  lm->client_pid = 0;
296  lm->client_index = 0;
297  if (learn_limit && (learn_limit < L2LEARN_DEFAULT_LIMIT))
298  lm->global_learn_limit = learn_limit;
299  else
301  }
302 
303 exit:
304  REPLY_MACRO (VL_API_WANT_L2_MACS_EVENTS_REPLY);
305 }
306 
307 static void
309 {
310  int rv = 0;
312  vl_api_l2fib_flush_int_reply_t *rmp;
313 
315 
316  u32 sw_if_index = ntohl (mp->sw_if_index);
317  l2fib_flush_int_mac (vm, sw_if_index);
318 
320  REPLY_MACRO (VL_API_L2FIB_FLUSH_INT_REPLY);
321 }
322 
323 static void
325 {
326  int rv = 0;
327  vl_api_l2fib_flush_all_reply_t *rmp;
328 
330  REPLY_MACRO (VL_API_L2FIB_FLUSH_ALL_REPLY);
331 }
332 
333 static void
335 {
336  int rv = 0;
338  bd_main_t *bdm = &bd_main;
339  vl_api_l2fib_flush_bd_reply_t *rmp;
340 
341  u32 bd_id = ntohl (mp->bd_id);
342  uword *p = hash_get (bdm->bd_index_by_bd_id, bd_id);
343  if (p == 0)
344  {
345  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
346  goto out;
347  }
348  l2fib_flush_bd_mac (vm, *p);
349 out:
350  REPLY_MACRO (VL_API_L2FIB_FLUSH_BD_REPLY);
351 }
352 
353 static void
355 {
357  int rv = 0;
358  u32 rbm = 0;
359 
361 
362  u32 sw_if_index = ntohl (mp->sw_if_index);
363  u32 flags = ntohl (mp->feature_bitmap);
364  u32 bitmap = 0;
365 
366  if (flags & L2_LEARN)
367  bitmap |= L2INPUT_FEAT_LEARN;
368 
369  if (flags & L2_FWD)
370  bitmap |= L2INPUT_FEAT_FWD;
371 
372  if (flags & L2_FLOOD)
373  bitmap |= L2INPUT_FEAT_FLOOD;
374 
375  if (flags & L2_UU_FLOOD)
376  bitmap |= L2INPUT_FEAT_UU_FLOOD;
377 
378  if (flags & L2_ARP_TERM)
379  bitmap |= L2INPUT_FEAT_ARP_TERM;
380 
381  rbm = l2input_intf_bitmap_enable (sw_if_index, bitmap, mp->is_set);
382 
384 
385  /* *INDENT-OFF* */
386  REPLY_MACRO2(VL_API_L2_FLAGS_REPLY,
387  ({
388  rmp->resulting_feature_bitmap = ntohl(rbm);
389  }));
390  /* *INDENT-ON* */
391 }
392 
393 static void
395  * mp)
396 {
398  bd_main_t *bdm = &bd_main;
399  vl_api_bridge_domain_set_mac_age_reply_t *rmp;
400  int rv = 0;
401  u32 bd_id = ntohl (mp->bd_id);
402  uword *p;
403 
404  if (bd_id == 0)
405  {
406  rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
407  goto out;
408  }
409 
410  p = hash_get (bdm->bd_index_by_bd_id, bd_id);
411  if (p == 0)
412  {
413  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
414  goto out;
415  }
416  bd_set_mac_age (vm, *p, mp->mac_age);
417 out:
418  REPLY_MACRO (VL_API_BRIDGE_DOMAIN_SET_MAC_AGE_REPLY);
419 }
420 
421 static void
423 {
425  .is_add = mp->is_add,
426  .flood = mp->flood,
427  .uu_flood = mp->uu_flood,
428  .forward = mp->forward,
429  .learn = mp->learn,
430  .arp_term = mp->arp_term,
431  .mac_age = mp->mac_age,
432  .bd_id = ntohl (mp->bd_id),
433  .bd_tag = mp->bd_tag
434  };
435 
436  int rv = bd_add_del (&a);
437 
438  vl_api_bridge_domain_add_del_reply_t *rmp;
439  REPLY_MACRO (VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
440 }
441 
442 static void
444  vl_api_registration_t * reg,
445  l2_bridge_domain_t * bd_config,
446  u32 n_sw_ifs, u32 context)
447 {
451  l2_input_config_t *input_cfg;
452 
453  mp = vl_msg_api_alloc (sizeof (*mp) +
454  (n_sw_ifs * sizeof (vl_api_bridge_domain_sw_if_t)));
455  memset (mp, 0, sizeof (*mp));
456  mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
457  mp->bd_id = ntohl (bd_config->bd_id);
458  mp->flood = bd_feature_flood (bd_config);
459  mp->uu_flood = bd_feature_uu_flood (bd_config);
460  mp->forward = bd_feature_forward (bd_config);
461  mp->learn = bd_feature_learn (bd_config);
462  mp->arp_term = bd_feature_arp_term (bd_config);
463  mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
464  mp->mac_age = bd_config->mac_age;
465  if (bd_config->bd_tag)
466  {
467  strncpy ((char *) mp->bd_tag, (char *) bd_config->bd_tag,
468  ARRAY_LEN (mp->bd_tag) - 1);
469  mp->bd_tag[ARRAY_LEN (mp->bd_tag) - 1] = 0;
470  }
471 
472  mp->context = context;
473 
475  vec_foreach (m, bd_config->members)
476  {
477  sw_ifs->sw_if_index = ntohl (m->sw_if_index);
478  input_cfg = vec_elt_at_index (l2im->configs, m->sw_if_index);
479  sw_ifs->shg = input_cfg->shg;
480  sw_ifs++;
481  mp->n_sw_ifs++;
482  }
483  mp->n_sw_ifs = htonl (mp->n_sw_ifs);
484 
485  vl_api_send_msg (reg, (u8 *) mp);
486 }
487 
488 static void
490 {
491  bd_main_t *bdm = &bd_main;
492  l2input_main_t *l2im = &l2input_main;
494  u32 bd_id, bd_index, end;
495 
497  if (!reg)
498  return;
499 
500  bd_id = ntohl (mp->bd_id);
501  if (bd_id == 0)
502  return;
503 
504  if (bd_id == ~0)
505  bd_index = 0, end = vec_len (l2im->bd_configs);
506  else
507  {
508  bd_index = bd_find_index (bdm, bd_id);
509  if (bd_index == ~0)
510  return;
511 
512  end = bd_index + 1;
513  }
514 
515  for (; bd_index < end; bd_index++)
516  {
517  l2_bridge_domain_t *bd_config =
518  l2input_bd_config_from_index (l2im, bd_index);
519  /* skip dummy bd_id 0 */
520  if (bd_config && (bd_config->bd_id > 0))
521  send_bridge_domain_details (l2im, reg, bd_config,
522  vec_len (bd_config->members),
523  mp->context);
524  }
525 }
526 
527 static void
529 {
531  bd_main_t *bdm = &bd_main;
533  int rv = 0;
534 
535  u32 flags = ntohl (mp->feature_bitmap);
536  u32 bd_id = ntohl (mp->bd_id);
537  if (bd_id == 0)
538  {
539  rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
540  goto out;
541  }
542 
543  u32 bd_index = bd_find_index (bdm, bd_id);
544  if (bd_index == ~0)
545  {
546  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
547  goto out;
548  }
549 
550  u32 bitmap = bd_set_flags (vm, bd_index, flags, mp->is_set);
551 
552 out:
553  /* *INDENT-OFF* */
554  REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
555  ({
556  rmp->resulting_feature_bitmap = ntohl(bitmap);
557  }));
558  /* *INDENT-ON* */
559 }
560 
561 static void
564 {
565  int rv = 0;
566  vl_api_l2_interface_vlan_tag_rewrite_reply_t *rmp;
567  vnet_main_t *vnm = vnet_get_main ();
569  u32 vtr_op;
570 
572 
573  vtr_op = ntohl (mp->vtr_op);
574 
575  /* The L2 code is unsuspicious */
576  switch (vtr_op)
577  {
578  case L2_VTR_DISABLED:
579  case L2_VTR_PUSH_1:
580  case L2_VTR_PUSH_2:
581  case L2_VTR_POP_1:
582  case L2_VTR_POP_2:
587  break;
588 
589  default:
590  rv = VNET_API_ERROR_INVALID_VALUE;
591  goto bad_sw_if_index;
592  }
593 
594  rv = l2vtr_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
595  ntohl (mp->push_dot1q), ntohl (mp->tag1),
596  ntohl (mp->tag2));
597 
599 
600  REPLY_MACRO (VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
601 }
602 
603 static void
606 {
607  vl_api_l2_interface_pbb_tag_rewrite_reply_t *rmp;
608  vnet_main_t *vnm = vnet_get_main ();
610  u32 vtr_op;
611  int rv = 0;
612 
614 
615  vtr_op = ntohl (mp->vtr_op);
616 
617  switch (vtr_op)
618  {
619  case L2_VTR_DISABLED:
620  case L2_VTR_PUSH_2:
621  case L2_VTR_POP_2:
623  break;
624 
625  default:
626  rv = VNET_API_ERROR_INVALID_VALUE;
627  goto bad_sw_if_index;
628  }
629 
630  rv = l2pbb_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
631  mp->b_dmac, mp->b_smac, ntohs (mp->b_vlanid),
632  ntohl (mp->i_sid), ntohs (mp->outer_tag));
633 
635 
636  REPLY_MACRO (VL_API_L2_INTERFACE_PBB_TAG_REWRITE_REPLY);
637 }
638 
639 static void
642 {
643  vl_api_sw_interface_set_l2_xconnect_reply_t *rmp;
644  int rv = 0;
645  u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
646  u32 tx_sw_if_index = ntohl (mp->tx_sw_if_index);
648  vnet_main_t *vnm = vnet_get_main ();
649 
651 
652  if (mp->enable)
653  {
655  rv = set_int_l2_mode (vm, vnm, MODE_L2_XC,
656  rx_sw_if_index, 0, 0, 0, tx_sw_if_index);
657  }
658  else
659  {
660  rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
661  }
662 
665 
666  REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
667 }
668 
669 static void
672 {
673  bd_main_t *bdm = &bd_main;
674  vl_api_sw_interface_set_l2_bridge_reply_t *rmp;
675  int rv = 0;
677  vnet_main_t *vnm = vnet_get_main ();
678 
680  u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
681 
682 
683  if (mp->enable)
684  {
685  VALIDATE_BD_ID (mp);
686  u32 bd_id = ntohl (mp->bd_id);
687  u32 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
688  u32 bvi = mp->bvi;
689  u8 shg = mp->shg;
690  rv = set_int_l2_mode (vm, vnm, MODE_L2_BRIDGE,
691  rx_sw_if_index, bd_index, bvi, shg, 0);
692  }
693  else
694  {
695  rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, 0, 0, 0);
696  }
697 
700 
701  REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
702 }
703 
704 static void
706 {
707  bd_main_t *bdm = &bd_main;
708  vl_api_bd_ip_mac_add_del_reply_t *rmp;
709  int rv = 0;
710  u32 bd_id = ntohl (mp->bd_id);
711  u32 bd_index;
712  uword *p;
713 
714  if (bd_id == 0)
715  {
716  rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
717  goto out;
718  }
719 
720  p = hash_get (bdm->bd_index_by_bd_id, bd_id);
721  if (p == 0)
722  {
723  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
724  goto out;
725  }
726 
727  bd_index = p[0];
728  if (bd_add_del_ip_mac (bd_index, mp->ip_address,
729  mp->mac_address, mp->is_ipv6, mp->is_add))
730  rv = VNET_API_ERROR_UNSPECIFIED;
731 
732 out:
733  REPLY_MACRO (VL_API_BD_IP_MAC_ADD_DEL_REPLY);
734 }
735 
736 extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
737  u32 sw_if_index, u32 enable);
738 
739 static void
741  mp)
742 {
743  int rv;
744  vl_api_l2_interface_efp_filter_reply_t *rmp;
745  vnet_main_t *vnm = vnet_get_main ();
746 
747  // enable/disable the feature
749  rv = vnm->api_errno;
750 
751  REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
752 }
753 
754 static void
756 {
757  extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
758  int is_add);
759  vl_api_l2_patch_add_del_reply_t *rmp;
760  int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
761  int is_add);
762  int rv = 0;
763 
766 
767  rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
768  ntohl (mp->tx_sw_if_index),
769  (int) (mp->is_add != 0));
770 
773 
774  REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
775 }
776 
777 static void
779 {
780  vl_api_sw_interface_set_vpath_reply_t *rmp;
781  int rv = 0;
782  u32 sw_if_index = ntohl (mp->sw_if_index);
783 
785 
786  l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
787  vnet_feature_enable_disable ("ip4-unicast", "vpath-input-ip4",
788  sw_if_index, mp->enable, 0, 0);
789  vnet_feature_enable_disable ("ip4-multicast", "vpath-input-ip4",
790  sw_if_index, mp->enable, 0, 0);
791  vnet_feature_enable_disable ("ip6-unicast", "vpath-input-ip6",
792  sw_if_index, mp->enable, 0, 0);
793  vnet_feature_enable_disable ("ip6-multicast", "vpath-input-ip6",
794  sw_if_index, mp->enable, 0, 0);
795 
797 
798  REPLY_MACRO (VL_API_SW_INTERFACE_SET_VPATH_REPLY);
799 }
800 
801 /*
802  * l2_api_hookup
803  * Add vpe's API message handlers to the table.
804  * vlib has alread mapped shared memory and
805  * added the client registration handlers.
806  * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
807  */
808 #define vl_msg_name_crc_list
809 #include <vnet/vnet_all_api_h.h>
810 #undef vl_msg_name_crc_list
811 
812 static void
814 {
815 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
816  foreach_vl_msg_name_crc_l2;
817 #undef _
818 }
819 
820 static clib_error_t *
822 {
823  api_main_t *am = &api_main;
824 
825 #define _(N,n) \
826  vl_msg_api_set_handlers(VL_API_##N, #n, \
827  vl_api_##n##_t_handler, \
828  vl_noop_handler, \
829  vl_api_##n##_t_endian, \
830  vl_api_##n##_t_print, \
831  sizeof(vl_api_##n##_t), 1);
833 #undef _
834 
835  /* Mark VL_API_BRIDGE_DOMAIN_DUMP as mp safe */
836  am->is_mp_safe[VL_API_BRIDGE_DOMAIN_DUMP] = 1;
837 
838  /*
839  * Set up the (msg_name, crc, message-id) table
840  */
842 
843  return 0;
844 }
845 
847 
848 /*
849  * fd.io coding-style-patch-verification: ON
850  *
851  * Local Variables:
852  * eval: (c-set-style "gnu")
853  * End:
854  */
static_always_inline u8 bd_feature_forward(l2_bridge_domain_t *bd_config)
Definition: l2_input.h:174
static void vl_api_l2_fib_table_dump_t_handler(vl_api_l2_fib_table_dump_t *mp)
Definition: l2_api.c:153
#define BAD_RX_SW_IF_INDEX_LABEL
u32 bd_set_flags(vlib_main_t *vm, u32 bd_index, u32 flags, u32 enable)
Set the learn/forward/flood flags for the bridge domain.
Definition: l2_bd.c:243
#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:66
Set bridge flags response.
Definition: l2.api:338
#define VALIDATE_TX_SW_IF_INDEX(mp)
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
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:671
u32 bvi_sw_if_index
Definition: l2_bd.h:64
static void vl_api_l2_patch_add_del_t_handler(vl_api_l2_patch_add_del_t *mp)
Definition: l2_api.c:755
static void vl_api_l2_flags_t_handler(vl_api_l2_flags_t *mp)
Definition: l2_api.c:354
vnet_interface_main_t interface_main
Definition: vnet.h:56
#define REPLY_MACRO2(t, body)
#define NULL
Definition: clib.h:55
#define L2_FLOOD
Definition: l2_bd.h:134
static void vl_api_send_msg(vl_api_registration_t *rp, u8 *elem)
Definition: api.h:34
#define L2_FWD
Definition: l2_bd.h:133
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:70
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:422
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:75
u32 max_macs_in_event
Definition: l2_fib.h:59
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:1138
Definition: l2_fib.h:108
static_always_inline u8 bd_feature_uu_flood(l2_bridge_domain_t *bd_config)
Definition: l2_input.h:167
static void vl_api_l2fib_add_del_t_handler(vl_api_l2fib_add_del_t *mp)
Definition: l2_api.c:192
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
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:32
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:443
#define MODE_L2_BRIDGE
Definition: l2_input.h:207
L2 bridge domain sw interface operational state response.
Definition: l2.api:282
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:187
static void vl_api_l2_fib_clear_table_t_handler(vl_api_l2_fib_clear_table_t *mp)
Definition: l2_api.c:116
#define L2_UU_FLOOD
Definition: l2_bd.h:135
L2 FIB flush bridge domain entries.
Definition: l2.api:96
void l2_efp_filter_configure(vnet_main_t *vnet_main, u32 sw_if_index, u32 enable)
Enable/disable the EFP Filter check on the subinterface.
u32 l2fib_del_entry(u8 *mac, u32 bd_index, u32 sw_if_index)
Delete an entry from the l2fib.
Definition: l2_fib.c:662
struct l2fib_entry_result_t::@245::@247 fields
unsigned int u32
Definition: types.h:88
uword * bd_index_by_bd_id
Definition: l2_bd.h:27
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:551
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:160
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
Set interface L2 flags response.
Definition: l2.api:217
Set bridge domain ip to mac entry request.
Definition: l2.api:451
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:791
static void vl_api_bd_ip_mac_add_del_t_handler(vl_api_bd_ip_mac_add_del_t *mp)
Definition: l2_api.c:705
#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:802
static clib_error_t * l2_api_hookup(vlib_main_t *vm)
Definition: l2_api.c:821
static void l2fib_add_fwd_entry(u8 *mac, u32 bd_index, u32 sw_if_index, u8 static_mac, u8 bvi_mac)
Definition: l2_fib.h:393
#define L2FIB_EVENT_MAX_MACS_DEFAULT
Definition: l2_fib.h:37
l2fib_main_t l2fib_main
Definition: l2_fib.c:55
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:201
u32 flags
Definition: vhost_user.h:110
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:287
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:443
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:91
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:734
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:339
#define foreach_vpe_api_msg
Definition: l2_api.c:51
static_always_inline u8 bd_feature_learn(l2_bridge_domain_t *bd_config)
Definition: l2_input.h:180
#define clib_memcpy(a, b, c)
Definition: string.h:75
static void setup_message_id_table(api_main_t *am)
Definition: l2_api.c:813
void l2fib_clear_table(void)
Definition: l2_fib.c:317
#define ARRAY_LEN(x)
Definition: clib.h:59
static vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
Definition: api.h:56
#define VALIDATE_RX_SW_IF_INDEX(mp)
#define L2FIB_EVENT_SCAN_DELAY_DEFAULT
Definition: l2_fib.h:34
Set L2 XConnect between two interfaces request.
Definition: l2.api:413
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:174
static_always_inline l2_bridge_domain_t * l2input_bd_config_from_index(l2input_main_t *l2im, u32 bd_index)
Definition: l2_input.h:81
Definition: l2_fib.h:71
static void l2fib_add_filter_entry(u8 *mac, u32 bd_index)
Definition: l2_fib.h:400
Register to recive L2 MAC events for leanred and aged MAC.
Definition: l2.api:147
#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:208
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:563
Interface bridge mode request.
Definition: l2.api:431
#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:641
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:334
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define L2_ARP_TERM
Definition: l2_bd.h:136
static void vl_api_want_l2_macs_events_t_handler(vl_api_want_l2_macs_events_t *mp)
Definition: l2_api.c:253
u64 uword
Definition: types.h:112
L2 interface ethernet flow point filtering enable/disable request.
Definition: l2.api:468
static void vl_api_bridge_flags_t_handler(vl_api_bridge_flags_t *mp)
Definition: l2_api.c:528
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:802
static void vl_api_l2_interface_efp_filter_t_handler(vl_api_l2_interface_efp_filter_t *mp)
Definition: l2_api.c:740
L2 interface vlan tag rewrite configure request.
Definition: l2.api:354
static void vl_api_l2fib_flush_all_t_handler(vl_api_l2fib_flush_all_t *mp)
Definition: l2_api.c:324
struct l2fib_entry_key_t::@237::@239 fields
l2_bridge_domain_t * bd_configs
Definition: l2_input.h:69
static void vl_api_bridge_domain_set_mac_age_t_handler(vl_api_bridge_domain_set_mac_age_t *mp)
Definition: l2_api.c:394
L2 interface patch add / del request.
Definition: l2.api:397
void l2fib_table_dump(u32 bd_index, l2fib_entry_key_t **l2fe_key, l2fib_entry_result_t **l2fe_res)
Definition: l2_fib.c:86
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:128
Interface set vpath request.
Definition: l2.api:482
u8 * is_mp_safe
Message is mp safe vector.
Definition: api_common.h:224
L2 interface pbb tag rewrite configure request.
Definition: l2.api:377
u32 sw_if_index
Definition: l2.api:207
#define vec_foreach(var, vec)
Vector iterator.
Set bridge flags (such as L2_LEARN, L2_FWD, L2_FLOOD, L2_UU_FLOOD, or L2_ARP_TERM bits) request...
Definition: l2.api:324
vl_api_bridge_domain_sw_if_t sw_if_details[n_sw_ifs]
Definition: l2.api:313
u32 sw_if_index
Definition: l2_bd.h:46
u32 bd_find_index(bd_main_t *bdm, u32 bd_id)
Get a bridge domain.
Definition: l2_bd.c:68
bd_main_t bd_main
Definition: l2_bd.c:44
vpe_api_main_t vpe_api_main
Definition: pipe_api.c:39
#define L2_LEARN
Definition: l2_bd.h:132
api_main_t api_main
Definition: api_shared.c:35
u32 client_pid
Definition: l2_learn.h:38
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:781
static void vl_api_l2fib_flush_int_t_handler(vl_api_l2fib_flush_int_t *mp)
Definition: l2_api.c:308
static void vl_api_l2_interface_pbb_tag_rewrite_t_handler(vl_api_l2_interface_pbb_tag_rewrite_t *mp)
Definition: l2_api.c:605
#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:206
static void vl_api_bridge_domain_dump_t_handler(vl_api_bridge_domain_dump_t *mp)
Definition: l2_api.c:489
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:778