c555a17d5eaad833ceb120552b598151c9fb4818
[vpp.git] / src / vnet / l2 / l2_api.c
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>
33 #include <vnet/ethernet/ethernet_types_api.h>
34
35 #include <vnet/format_fns.h>
36 #include <vnet/l2/l2.api_enum.h>
37 #include <vnet/l2/l2.api_types.h>
38
39 #define REPLY_MSG_ID_BASE l2input_main.msg_id_base
40 #include <vlibapi/api_helper_macros.h>
41
42 static void
43 send_l2_xconnect_details (vl_api_registration_t * reg, u32 context,
44                           u32 rx_sw_if_index, u32 tx_sw_if_index)
45 {
46   vl_api_l2_xconnect_details_t *mp;
47
48   mp = vl_msg_api_alloc (sizeof (*mp));
49   clib_memset (mp, 0, sizeof (*mp));
50   mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_L2_XCONNECT_DETAILS);
51   mp->context = context;
52   mp->rx_sw_if_index = htonl (rx_sw_if_index);
53   mp->tx_sw_if_index = htonl (tx_sw_if_index);
54
55   vl_api_send_msg (reg, (u8 *) mp);
56 }
57
58 static void
59 vl_api_l2_xconnect_dump_t_handler (vl_api_l2_xconnect_dump_t * mp)
60 {
61   vl_api_registration_t *reg;
62   l2input_main_t *l2im = &l2input_main;
63   u32 sw_if_index;
64   l2_input_config_t *config;
65
66   reg = vl_api_client_index_to_registration (mp->client_index);
67   if (!reg)
68     return;
69
70   /* *INDENT-OFF* */
71   vec_foreach_index (sw_if_index, l2im->configs)
72     {
73       config = vec_elt_at_index (l2im->configs, sw_if_index);
74       if (l2_input_is_xconnect (config))
75         send_l2_xconnect_details (reg, mp->context, sw_if_index,
76                                   config->output_sw_if_index);
77     }
78   /* *INDENT-ON* */
79 }
80
81 static void
82 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t * mp)
83 {
84   int rv = 0;
85   vl_api_l2_fib_clear_table_reply_t *rmp;
86
87   /* Clear all MACs including static MACs  */
88   l2fib_clear_table ();
89
90   REPLY_MACRO (VL_API_L2_FIB_CLEAR_TABLE_REPLY);
91 }
92
93 static void
94 send_l2fib_table_entry (vpe_api_main_t * am,
95                         vl_api_registration_t * reg,
96                         l2fib_entry_key_t * l2fe_key,
97                         l2fib_entry_result_t * l2fe_res, u32 context)
98 {
99   vl_api_l2_fib_table_details_t *mp;
100
101   mp = vl_msg_api_alloc (sizeof (*mp));
102   clib_memset (mp, 0, sizeof (*mp));
103   mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_L2_FIB_TABLE_DETAILS);
104
105   mp->bd_id =
106     ntohl (l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
107
108   mac_address_encode ((mac_address_t *) l2fe_key->fields.mac, mp->mac);
109   mp->sw_if_index = ntohl (l2fe_res->fields.sw_if_index);
110   mp->static_mac = (l2fib_entry_result_is_set_STATIC (l2fe_res) ? 1 : 0);
111   mp->filter_mac = (l2fib_entry_result_is_set_FILTER (l2fe_res) ? 1 : 0);
112   mp->bvi_mac = (l2fib_entry_result_is_set_BVI (l2fe_res) ? 1 : 0);
113   mp->context = context;
114
115   vl_api_send_msg (reg, (u8 *) mp);
116 }
117
118 static void
119 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t * mp)
120 {
121   vpe_api_main_t *am = &vpe_api_main;
122   bd_main_t *bdm = &bd_main;
123   l2fib_entry_key_t *l2fe_key = NULL;
124   l2fib_entry_result_t *l2fe_res = NULL;
125   u32 ni, bd_id = ntohl (mp->bd_id);
126   u32 bd_index;
127   vl_api_registration_t *reg;
128   uword *p;
129
130   reg = vl_api_client_index_to_registration (mp->client_index);
131   if (!reg)
132     return;
133
134   /* see l2fib_table_dump: ~0 means "any" */
135   if (bd_id == ~0)
136     bd_index = ~0;
137   else
138     {
139       p = hash_get (bdm->bd_index_by_bd_id, bd_id);
140       if (p == 0)
141         return;
142
143       bd_index = p[0];
144     }
145
146   l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
147
148   vec_foreach_index (ni, l2fe_key)
149   {
150     send_l2fib_table_entry (am, reg, vec_elt_at_index (l2fe_key, ni),
151                             vec_elt_at_index (l2fe_res, ni), mp->context);
152   }
153   vec_free (l2fe_key);
154   vec_free (l2fe_res);
155 }
156
157 static void
158 vl_api_l2fib_add_del_t_handler (vl_api_l2fib_add_del_t * mp)
159 {
160   bd_main_t *bdm = &bd_main;
161   l2input_main_t *l2im = &l2input_main;
162   vl_api_l2fib_add_del_reply_t *rmp;
163   int rv = 0;
164   u32 bd_id = ntohl (mp->bd_id);
165   uword *p = hash_get (bdm->bd_index_by_bd_id, bd_id);
166
167   if (!p)
168     {
169       rv = VNET_API_ERROR_NO_SUCH_ENTRY;
170       goto bad_sw_if_index;
171     }
172   u32 bd_index = p[0];
173
174   mac_address_t mac;
175
176   mac_address_decode (mp->mac, &mac);
177   if (mp->is_add)
178     {
179       if (mp->filter_mac)
180         l2fib_add_filter_entry (mac.bytes, bd_index);
181       else
182         {
183           l2fib_entry_result_flags_t flags = L2FIB_ENTRY_RESULT_FLAG_NONE;
184           u32 sw_if_index = ntohl (mp->sw_if_index);
185           VALIDATE_SW_IF_INDEX (mp);
186           if (vec_len (l2im->configs) <= sw_if_index)
187             {
188               rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
189               goto bad_sw_if_index;
190             }
191           else
192             {
193               l2_input_config_t *config;
194               config = vec_elt_at_index (l2im->configs, sw_if_index);
195               if (!l2_input_is_bridge (config))
196                 {
197                   rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
198                   goto bad_sw_if_index;
199                 }
200             }
201           if (mp->static_mac)
202             flags |= L2FIB_ENTRY_RESULT_FLAG_STATIC;
203           if (mp->bvi_mac)
204             flags |= L2FIB_ENTRY_RESULT_FLAG_BVI;
205           l2fib_add_entry (mac.bytes, bd_index, sw_if_index, flags);
206         }
207     }
208   else
209     {
210       u32 sw_if_index = ntohl (mp->sw_if_index);
211       if (l2fib_del_entry (mac.bytes, bd_index, sw_if_index))
212         rv = VNET_API_ERROR_NO_SUCH_ENTRY;
213     }
214
215   BAD_SW_IF_INDEX_LABEL;
216
217   REPLY_MACRO (VL_API_L2FIB_ADD_DEL_REPLY);
218 }
219
220 static void
221 vl_api_want_l2_macs_events2_t_handler (vl_api_want_l2_macs_events2_t *mp)
222 {
223   int rv = 0;
224   vl_api_want_l2_macs_events2_reply_t *rmp;
225   l2learn_main_t *lm = &l2learn_main;
226   l2fib_main_t *fm = &l2fib_main;
227   u32 pid = ntohl (mp->pid);
228
229   if (mp->enable_disable)
230     {
231       if ((lm->client_pid == 0) || (lm->client_pid == pid))
232         {
233           if (mp->max_macs_in_event)
234             fm->max_macs_in_event = mp->max_macs_in_event * 10;
235           else
236             {
237               rv = VNET_API_ERROR_INVALID_VALUE;
238               goto exit;
239             }
240
241           /* if scan_delay was not set before */
242           if (fm->event_scan_delay == 0.0)
243             fm->event_scan_delay = (f64) (10) * 10e-3;
244
245           lm->client_pid = pid;
246           lm->client_index = mp->client_index;
247           l2fib_flush_all_mac (vlib_get_main ());
248         }
249       else if (lm->client_pid != pid)
250         {
251           rv = VNET_API_ERROR_L2_MACS_EVENT_CLINET_PRESENT;
252           goto exit;
253         }
254     }
255   else if (lm->client_pid)
256     {
257       lm->client_pid = 0;
258       lm->client_index = 0;
259     }
260
261 exit:
262   REPLY_MACRO (VL_API_WANT_L2_MACS_EVENTS2_REPLY);
263 }
264
265 static void
266 vl_api_want_l2_macs_events_t_handler (vl_api_want_l2_macs_events_t *mp)
267 {
268   int rv = 0;
269   vl_api_want_l2_macs_events_reply_t *rmp;
270   l2learn_main_t *lm = &l2learn_main;
271   l2fib_main_t *fm = &l2fib_main;
272   u32 pid = ntohl (mp->pid);
273   u32 learn_limit = ntohl (mp->learn_limit);
274
275   if (mp->enable_disable)
276     {
277       if ((lm->client_pid == 0) || (lm->client_pid == pid))
278         {
279           if ((mp->max_macs_in_event == 0) || (mp->scan_delay == 0) ||
280               (learn_limit == 0) || (learn_limit > L2LEARN_DEFAULT_LIMIT))
281             {
282               rv = VNET_API_ERROR_INVALID_VALUE;
283               goto exit;
284             }
285           lm->client_pid = pid;
286           lm->client_index = mp->client_index;
287
288           fm->max_macs_in_event = mp->max_macs_in_event * 10;
289           fm->event_scan_delay = (f64) (mp->scan_delay) * 10e-3;
290
291           /* change learn limit and flush all learned MACs */
292           lm->global_learn_limit = learn_limit;
293           l2fib_flush_all_mac (vlib_get_main ());
294         }
295       else if (lm->client_pid != pid)
296         {
297           rv = VNET_API_ERROR_L2_MACS_EVENT_CLINET_PRESENT;
298           goto exit;
299         }
300     }
301   else if (lm->client_pid)
302     {
303       lm->client_pid = 0;
304       lm->client_index = 0;
305       if (learn_limit && (learn_limit <= L2LEARN_DEFAULT_LIMIT))
306         lm->global_learn_limit = learn_limit;
307       else
308         lm->global_learn_limit = L2LEARN_DEFAULT_LIMIT;
309     }
310
311 exit:
312   REPLY_MACRO (VL_API_WANT_L2_MACS_EVENTS_REPLY);
313 }
314
315 static void
316 vl_api_l2fib_flush_int_t_handler (vl_api_l2fib_flush_int_t * mp)
317 {
318   int rv = 0;
319   vlib_main_t *vm = vlib_get_main ();
320   vl_api_l2fib_flush_int_reply_t *rmp;
321
322   VALIDATE_SW_IF_INDEX (mp);
323
324   u32 sw_if_index = ntohl (mp->sw_if_index);
325   l2fib_flush_int_mac (vm, sw_if_index);
326
327   BAD_SW_IF_INDEX_LABEL;
328   REPLY_MACRO (VL_API_L2FIB_FLUSH_INT_REPLY);
329 }
330
331 static void
332 vl_api_l2fib_flush_all_t_handler (vl_api_l2fib_flush_all_t * mp)
333 {
334   int rv = 0;
335   vl_api_l2fib_flush_all_reply_t *rmp;
336
337   l2fib_flush_all_mac (vlib_get_main ());
338   REPLY_MACRO (VL_API_L2FIB_FLUSH_ALL_REPLY);
339 }
340
341 static void
342 vl_api_l2fib_flush_bd_t_handler (vl_api_l2fib_flush_bd_t * mp)
343 {
344   int rv = 0;
345   vlib_main_t *vm = vlib_get_main ();
346   bd_main_t *bdm = &bd_main;
347   vl_api_l2fib_flush_bd_reply_t *rmp;
348
349   u32 bd_id = ntohl (mp->bd_id);
350   uword *p = hash_get (bdm->bd_index_by_bd_id, bd_id);
351   if (p == 0)
352     {
353       rv = VNET_API_ERROR_NO_SUCH_ENTRY;
354       goto out;
355     }
356   l2fib_flush_bd_mac (vm, *p);
357 out:
358   REPLY_MACRO (VL_API_L2FIB_FLUSH_BD_REPLY);
359 }
360
361 static void
362 vl_api_l2fib_set_scan_delay_t_handler (vl_api_l2fib_set_scan_delay_t *mp)
363 {
364   int rv = 0;
365   l2fib_main_t *fm = &l2fib_main;
366   vl_api_l2fib_set_scan_delay_reply_t *rmp;
367   u16 scan_delay = ntohs (mp->scan_delay);
368
369   if (mp->scan_delay)
370     {
371       fm->event_scan_delay = (f64) (scan_delay) *10e-3;
372       l2fib_flush_all_mac (vlib_get_main ());
373     }
374   else
375     {
376       rv = VNET_API_ERROR_INVALID_VALUE;
377       goto exit;
378     }
379
380 exit:
381   REPLY_MACRO (VL_API_L2FIB_SET_SCAN_DELAY_REPLY);
382 }
383
384 static void
385 vl_api_l2_flags_t_handler (vl_api_l2_flags_t * mp)
386 {
387   vl_api_l2_flags_reply_t *rmp;
388   int rv = 0;
389   u32 rbm = 0;
390
391   VALIDATE_SW_IF_INDEX (mp);
392
393   u32 sw_if_index = ntohl (mp->sw_if_index);
394   u32 flags = ntohl (mp->feature_bitmap);
395   u32 bitmap = 0;
396
397   if (flags & L2_LEARN)
398     bitmap |= L2INPUT_FEAT_LEARN;
399
400   if (flags & L2_FWD)
401     bitmap |= L2INPUT_FEAT_FWD;
402
403   if (flags & L2_FLOOD)
404     bitmap |= L2INPUT_FEAT_FLOOD;
405
406   if (flags & L2_UU_FLOOD)
407     bitmap |= L2INPUT_FEAT_UU_FLOOD;
408
409   if (flags & L2_ARP_TERM)
410     bitmap |= L2INPUT_FEAT_ARP_TERM;
411
412   rbm = l2input_intf_bitmap_enable (sw_if_index, bitmap, mp->is_set);
413
414   BAD_SW_IF_INDEX_LABEL;
415
416   /* *INDENT-OFF* */
417   REPLY_MACRO2(VL_API_L2_FLAGS_REPLY,
418   ({
419     rmp->resulting_feature_bitmap = ntohl(rbm);
420   }));
421   /* *INDENT-ON* */
422 }
423
424 static void
425 vl_api_bridge_domain_set_default_learn_limit_t_handler (
426   vl_api_bridge_domain_set_default_learn_limit_t *mp)
427 {
428   vl_api_bridge_domain_set_default_learn_limit_reply_t *rmp;
429   int rv = 0;
430
431   l2learn_main.bd_default_learn_limit = ntohl (mp->learn_limit);
432   REPLY_MACRO (VL_API_BRIDGE_DOMAIN_SET_DEFAULT_LEARN_LIMIT_REPLY);
433 }
434
435 static void
436 vl_api_bridge_domain_set_learn_limit_t_handler (
437   vl_api_bridge_domain_set_learn_limit_t *mp)
438 {
439   vlib_main_t *vm = vlib_get_main ();
440   bd_main_t *bdm = &bd_main;
441   vl_api_bridge_domain_set_learn_limit_reply_t *rmp;
442   int rv = 0;
443   u32 bd_id = ntohl (mp->bd_id);
444   uword *p;
445
446   if (bd_id == 0)
447     {
448       rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
449       goto out;
450     }
451
452   p = hash_get (bdm->bd_index_by_bd_id, bd_id);
453   if (p == 0)
454     {
455       rv = VNET_API_ERROR_NO_SUCH_ENTRY;
456       goto out;
457     }
458   bd_set_learn_limit (vm, *p, ntohl (mp->learn_limit));
459 out:
460   REPLY_MACRO (VL_API_BRIDGE_DOMAIN_SET_LEARN_LIMIT_REPLY);
461 }
462
463 static void
464 vl_api_bridge_domain_set_mac_age_t_handler (vl_api_bridge_domain_set_mac_age_t
465                                             * mp)
466 {
467   vlib_main_t *vm = vlib_get_main ();
468   bd_main_t *bdm = &bd_main;
469   vl_api_bridge_domain_set_mac_age_reply_t *rmp;
470   int rv = 0;
471   u32 bd_id = ntohl (mp->bd_id);
472   uword *p;
473
474   if (bd_id == 0)
475     {
476       rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
477       goto out;
478     }
479
480   p = hash_get (bdm->bd_index_by_bd_id, bd_id);
481   if (p == 0)
482     {
483       rv = VNET_API_ERROR_NO_SUCH_ENTRY;
484       goto out;
485     }
486   bd_set_mac_age (vm, *p, mp->mac_age);
487 out:
488   REPLY_MACRO (VL_API_BRIDGE_DOMAIN_SET_MAC_AGE_REPLY);
489 }
490
491 static void
492 vl_api_bridge_domain_add_del_t_handler (vl_api_bridge_domain_add_del_t * mp)
493 {
494   l2_bridge_domain_add_del_args_t a = {
495     .is_add = mp->is_add,
496     .flood = mp->flood,
497     .uu_flood = mp->uu_flood,
498     .forward = mp->forward,
499     .learn = mp->learn,
500     .arp_term = mp->arp_term,
501     .arp_ufwd = mp->arp_ufwd,
502     .mac_age = mp->mac_age,
503     .bd_id = ntohl (mp->bd_id),
504     .bd_tag = mp->bd_tag
505   };
506
507   int rv = bd_add_del (&a);
508
509   vl_api_bridge_domain_add_del_reply_t *rmp;
510   REPLY_MACRO (VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
511 }
512
513 static void
514 send_bridge_domain_details (l2input_main_t * l2im,
515                             vl_api_registration_t * reg,
516                             l2_bridge_domain_t * bd_config,
517                             u32 n_sw_ifs, u32 context)
518 {
519   vl_api_bridge_domain_details_t *mp;
520   l2_flood_member_t *m;
521   vl_api_bridge_domain_sw_if_t *sw_ifs;
522   l2_input_config_t *input_cfg;
523
524   mp = vl_msg_api_alloc (sizeof (*mp) +
525                          (n_sw_ifs * sizeof (vl_api_bridge_domain_sw_if_t)));
526   clib_memset (mp, 0, sizeof (*mp));
527   mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_BRIDGE_DOMAIN_DETAILS);
528   mp->bd_id = ntohl (bd_config->bd_id);
529   mp->flood = bd_feature_flood (bd_config);
530   mp->uu_flood = bd_feature_uu_flood (bd_config);
531   mp->forward = bd_feature_forward (bd_config);
532   mp->learn = bd_feature_learn (bd_config);
533   mp->arp_term = bd_feature_arp_term (bd_config);
534   mp->arp_ufwd = bd_feature_arp_ufwd (bd_config);
535   mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
536   mp->uu_fwd_sw_if_index = ntohl (bd_config->uu_fwd_sw_if_index);
537   mp->mac_age = bd_config->mac_age;
538   if (bd_config->bd_tag)
539     {
540       strncpy ((char *) mp->bd_tag, (char *) bd_config->bd_tag,
541                ARRAY_LEN (mp->bd_tag) - 1);
542       mp->bd_tag[ARRAY_LEN (mp->bd_tag) - 1] = 0;
543     }
544
545   mp->context = context;
546
547   sw_ifs = (vl_api_bridge_domain_sw_if_t *) mp->sw_if_details;
548   vec_foreach (m, bd_config->members)
549   {
550     sw_ifs->sw_if_index = ntohl (m->sw_if_index);
551     input_cfg = vec_elt_at_index (l2im->configs, m->sw_if_index);
552     sw_ifs->shg = input_cfg->shg;
553     sw_ifs++;
554     mp->n_sw_ifs++;
555   }
556   mp->n_sw_ifs = htonl (mp->n_sw_ifs);
557
558   vl_api_send_msg (reg, (u8 *) mp);
559 }
560
561 static void
562 vl_api_bridge_domain_dump_t_handler (vl_api_bridge_domain_dump_t * mp)
563 {
564   bd_main_t *bdm = &bd_main;
565   l2input_main_t *l2im = &l2input_main;
566   vl_api_registration_t *reg;
567   u32 bd_id, bd_index, end, filter_sw_if_index;
568
569   reg = vl_api_client_index_to_registration (mp->client_index);
570   if (!reg)
571     return;
572
573   filter_sw_if_index = ntohl (mp->sw_if_index);
574   if (filter_sw_if_index != ~0)
575     return;                     /* UNIMPLEMENTED */
576
577   bd_id = ntohl (mp->bd_id);
578   if (bd_id == 0)
579     return;
580
581   if (bd_id == ~0)
582     bd_index = 0, end = vec_len (l2im->bd_configs);
583   else
584     {
585       bd_index = bd_find_index (bdm, bd_id);
586       if (bd_index == ~0)
587         return;
588
589       end = bd_index + 1;
590     }
591
592   for (; bd_index < end; bd_index++)
593     {
594       l2_bridge_domain_t *bd_config =
595         l2input_bd_config_from_index (l2im, bd_index);
596       /* skip placeholder bd_id 0 */
597       if (bd_config && (bd_config->bd_id > 0))
598         send_bridge_domain_details (l2im, reg, bd_config,
599                                     vec_len (bd_config->members),
600                                     mp->context);
601     }
602 }
603
604 static bd_flags_t
605 bd_flags_decode (vl_api_bd_flags_t v)
606 {
607   bd_flags_t f = L2_NONE;
608
609   v = ntohl (v);
610
611   if (v & BRIDGE_API_FLAG_LEARN)
612     f |= L2_LEARN;
613   if (v & BRIDGE_API_FLAG_FWD)
614     f |= L2_FWD;
615   if (v & BRIDGE_API_FLAG_FLOOD)
616     f |= L2_FLOOD;
617   if (v & BRIDGE_API_FLAG_UU_FLOOD)
618     f |= L2_UU_FLOOD;
619   if (v & BRIDGE_API_FLAG_ARP_TERM)
620     f |= L2_ARP_TERM;
621   if (v & BRIDGE_API_FLAG_ARP_UFWD)
622     f |= L2_ARP_UFWD;
623
624   return (f);
625 }
626
627 static void
628 vl_api_bridge_flags_t_handler (vl_api_bridge_flags_t * mp)
629 {
630   vlib_main_t *vm = vlib_get_main ();
631   bd_main_t *bdm = &bd_main;
632   vl_api_bridge_flags_reply_t *rmp;
633   u32 bitmap = 0;
634   int rv = 0;
635
636   bd_flags_t flags = bd_flags_decode (mp->flags);
637   u32 bd_id = ntohl (mp->bd_id);
638   if (bd_id == 0)
639     {
640       rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
641       goto out;
642     }
643
644   u32 bd_index = bd_find_index (bdm, bd_id);
645   if (bd_index == ~0)
646     {
647       rv = VNET_API_ERROR_NO_SUCH_ENTRY;
648       goto out;
649     }
650
651   bitmap = bd_set_flags (vm, bd_index, flags, mp->is_set);
652
653 out:
654   /* *INDENT-OFF* */
655   REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
656   ({
657     rmp->resulting_feature_bitmap = ntohl(bitmap);
658   }));
659   /* *INDENT-ON* */
660 }
661
662 static void
663   vl_api_l2_interface_vlan_tag_rewrite_t_handler
664   (vl_api_l2_interface_vlan_tag_rewrite_t * mp)
665 {
666   int rv = 0;
667   vl_api_l2_interface_vlan_tag_rewrite_reply_t *rmp;
668   vnet_main_t *vnm = vnet_get_main ();
669   vlib_main_t *vm = vlib_get_main ();
670   u32 vtr_op;
671
672   VALIDATE_SW_IF_INDEX (mp);
673
674   vtr_op = ntohl (mp->vtr_op);
675
676   /* The L2 code is unsuspicious */
677   switch (vtr_op)
678     {
679     case L2_VTR_DISABLED:
680     case L2_VTR_PUSH_1:
681     case L2_VTR_PUSH_2:
682     case L2_VTR_POP_1:
683     case L2_VTR_POP_2:
684     case L2_VTR_TRANSLATE_1_1:
685     case L2_VTR_TRANSLATE_1_2:
686     case L2_VTR_TRANSLATE_2_1:
687     case L2_VTR_TRANSLATE_2_2:
688       break;
689
690     default:
691       rv = VNET_API_ERROR_INVALID_VALUE;
692       goto bad_sw_if_index;
693     }
694
695   rv = l2vtr_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
696                         ntohl (mp->push_dot1q), ntohl (mp->tag1),
697                         ntohl (mp->tag2));
698
699   BAD_SW_IF_INDEX_LABEL;
700
701   REPLY_MACRO (VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
702 }
703
704 static void
705   vl_api_l2_interface_pbb_tag_rewrite_t_handler
706   (vl_api_l2_interface_pbb_tag_rewrite_t * mp)
707 {
708   vl_api_l2_interface_pbb_tag_rewrite_reply_t *rmp;
709   vnet_main_t *vnm = vnet_get_main ();
710   vlib_main_t *vm = vlib_get_main ();
711   u32 vtr_op;
712   int rv = 0;
713   mac_address_t b_dmac, b_smac;
714
715   VALIDATE_SW_IF_INDEX (mp);
716
717   vtr_op = ntohl (mp->vtr_op);
718
719   switch (vtr_op)
720     {
721     case L2_VTR_DISABLED:
722     case L2_VTR_PUSH_2:
723     case L2_VTR_POP_2:
724     case L2_VTR_TRANSLATE_2_1:
725       break;
726
727     default:
728       rv = VNET_API_ERROR_INVALID_VALUE;
729       goto bad_sw_if_index;
730     }
731
732   mac_address_decode (mp->b_dmac, &b_dmac);
733   mac_address_decode (mp->b_smac, &b_smac);
734
735   rv = l2pbb_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
736                         b_dmac.bytes, b_smac.bytes, ntohs (mp->b_vlanid),
737                         ntohl (mp->i_sid), ntohs (mp->outer_tag));
738
739   BAD_SW_IF_INDEX_LABEL;
740
741   REPLY_MACRO (VL_API_L2_INTERFACE_PBB_TAG_REWRITE_REPLY);
742 }
743
744 static void
745   vl_api_sw_interface_set_l2_xconnect_t_handler
746   (vl_api_sw_interface_set_l2_xconnect_t * mp)
747 {
748   vl_api_sw_interface_set_l2_xconnect_reply_t *rmp;
749   int rv = 0;
750   u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
751   u32 tx_sw_if_index = ntohl (mp->tx_sw_if_index);
752   vlib_main_t *vm = vlib_get_main ();
753   vnet_main_t *vnm = vnet_get_main ();
754
755   VALIDATE_RX_SW_IF_INDEX (mp);
756
757   if (mp->enable)
758     {
759       VALIDATE_TX_SW_IF_INDEX (mp);
760       rv = set_int_l2_mode (vm, vnm, MODE_L2_XC,
761                             rx_sw_if_index, 0,
762                             L2_BD_PORT_TYPE_NORMAL, 0, tx_sw_if_index);
763     }
764   else
765     {
766       rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0,
767                             L2_BD_PORT_TYPE_NORMAL, 0, 0);
768     }
769
770   switch (rv)
771     {
772     case MODE_ERROR_ETH:
773       rv = VNET_API_ERROR_NON_ETHERNET;
774       break;
775     case MODE_ERROR_BVI_DEF:
776       rv = VNET_API_ERROR_BD_ALREADY_HAS_BVI;
777       break;
778     }
779
780   BAD_RX_SW_IF_INDEX_LABEL;
781   BAD_TX_SW_IF_INDEX_LABEL;
782
783   REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_XCONNECT_REPLY);
784 }
785
786 static int
787 l2_bd_port_type_decode (vl_api_l2_port_type_t v, l2_bd_port_type_t * l)
788 {
789   v = clib_net_to_host_u32 (v);
790
791   switch (v)
792     {
793     case L2_API_PORT_TYPE_NORMAL:
794       *l = L2_BD_PORT_TYPE_NORMAL;
795       return 0;
796     case L2_API_PORT_TYPE_BVI:
797       *l = L2_BD_PORT_TYPE_BVI;
798       return 0;
799     case L2_API_PORT_TYPE_UU_FWD:
800       *l = L2_BD_PORT_TYPE_UU_FWD;
801       return 0;
802     }
803
804   return (VNET_API_ERROR_INVALID_VALUE);
805 }
806
807 static void
808   vl_api_sw_interface_set_l2_bridge_t_handler
809   (vl_api_sw_interface_set_l2_bridge_t * mp)
810 {
811   bd_main_t *bdm = &bd_main;
812   vl_api_sw_interface_set_l2_bridge_reply_t *rmp;
813   int rv = 0;
814   vlib_main_t *vm = vlib_get_main ();
815   vnet_main_t *vnm = vnet_get_main ();
816   l2_bd_port_type_t pt;
817
818   VALIDATE_RX_SW_IF_INDEX (mp);
819   u32 rx_sw_if_index = ntohl (mp->rx_sw_if_index);
820   rv = l2_bd_port_type_decode (mp->port_type, &pt);
821
822   if (0 != rv)
823     goto out;
824   if (mp->enable)
825     {
826       VALIDATE_BD_ID (mp);
827       u32 bd_id = ntohl (mp->bd_id);
828       u32 bd_index = bd_find_or_add_bd_index (bdm, bd_id);
829
830       rv = set_int_l2_mode (vm, vnm, MODE_L2_BRIDGE,
831                             rx_sw_if_index, bd_index, pt, mp->shg, 0);
832     }
833   else
834     {
835       rv = set_int_l2_mode (vm, vnm, MODE_L3, rx_sw_if_index, 0, pt, 0, 0);
836     }
837
838   switch (rv)
839     {
840     case MODE_ERROR_ETH:
841       rv = VNET_API_ERROR_NON_ETHERNET;
842       break;
843     case MODE_ERROR_BVI_DEF:
844       rv = VNET_API_ERROR_BD_ALREADY_HAS_BVI;
845       break;
846     }
847
848   BAD_RX_SW_IF_INDEX_LABEL;
849   BAD_BD_ID_LABEL;
850 out:
851   REPLY_MACRO (VL_API_SW_INTERFACE_SET_L2_BRIDGE_REPLY);
852 }
853
854 static void
855 send_bd_ip_mac_entry (vpe_api_main_t * am,
856                       vl_api_registration_t * reg,
857                       u32 bd_id,
858                       const ip46_address_t * ip,
859                       ip46_type_t itype,
860                       const mac_address_t * mac, u32 context)
861 {
862   vl_api_bd_ip_mac_details_t *mp;
863
864   mp = vl_msg_api_alloc (sizeof (*mp));
865   clib_memset (mp, 0, sizeof (*mp));
866   mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_BD_IP_MAC_DETAILS);
867
868   mp->context = context;
869   mp->entry.bd_id = ntohl (bd_id);
870
871   ip_address_encode (ip, itype, &mp->entry.ip);
872   mac_address_encode (mac, mp->entry.mac);
873
874   vl_api_send_msg (reg, (u8 *) mp);
875 }
876
877 static void
878 vl_api_bd_ip_mac_dump_t_handler (vl_api_bd_ip_mac_dump_t * mp)
879 {
880   vpe_api_main_t *am = &vpe_api_main;
881   bd_main_t *bdm = &bd_main;
882   l2_bridge_domain_t *bd_config;
883   u32 bd_id = ntohl (mp->bd_id);
884   u32 bd_index, start, end;
885   vl_api_registration_t *reg;
886   uword *p;
887
888   reg = vl_api_client_index_to_registration (mp->client_index);
889   if (!reg)
890     return;
891
892   /* see bd_id: ~0 means "any" */
893   if (bd_id == ~0)
894     {
895       start = 1;
896       end = vec_len (l2input_main.bd_configs);
897     }
898   else
899     {
900       p = hash_get (bdm->bd_index_by_bd_id, bd_id);
901       if (p == 0)
902         return;
903
904       bd_index = p[0];
905       vec_validate (l2input_main.bd_configs, bd_index);
906       start = bd_index;
907       end = start + 1;
908     }
909
910   for (bd_index = start; bd_index < end; bd_index++)
911     {
912       bd_config = vec_elt_at_index (l2input_main.bd_configs, bd_index);
913       if (bd_is_valid (bd_config))
914         {
915           ip4_address_t ip4_addr;
916           ip6_address_t *ip6_addr;
917           mac_address_t mac;
918           u64 mac64;
919           bd_id = bd_config->bd_id;
920
921          /* *INDENT-OFF* */
922          hash_foreach (ip4_addr.as_u32, mac64, bd_config->mac_by_ip4,
923          ({
924            ip46_address_t ip = {
925              .ip4 = ip4_addr,
926            };
927            mac_address_from_u64(&mac, mac64);
928
929            send_bd_ip_mac_entry (am, reg, bd_id, &ip, IP46_TYPE_IP4,
930                                  &mac, mp->context);
931          }));
932
933          hash_foreach_mem (ip6_addr, mac64, bd_config->mac_by_ip6,
934          ({
935            ip46_address_t ip = {
936              .ip6 = *ip6_addr,
937            };
938            mac_address_from_u64(&mac, mac64);
939
940            send_bd_ip_mac_entry (am, reg, bd_id, &ip, IP46_TYPE_IP6,
941                                  &mac, mp->context);
942          }));
943          /* *INDENT-ON* */
944         }
945     }
946 }
947
948 static void
949 vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp)
950 {
951   ip46_address_t ip_addr = ip46_address_initializer;
952   vl_api_bd_ip_mac_add_del_reply_t *rmp;
953   bd_main_t *bdm = &bd_main;
954   u32 bd_index, bd_id;
955   mac_address_t mac;
956   ip46_type_t type;
957   int rv = 0;
958   uword *p;
959
960   bd_id = ntohl (mp->entry.bd_id);
961
962   if (bd_id == 0)
963     {
964       rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
965       goto out;
966     }
967
968   p = hash_get (bdm->bd_index_by_bd_id, bd_id);
969   if (p == 0)
970     {
971       rv = VNET_API_ERROR_NO_SUCH_ENTRY;
972       goto out;
973     }
974   bd_index = p[0];
975
976   type = ip_address_decode (&mp->entry.ip, &ip_addr);
977   mac_address_decode (mp->entry.mac, &mac);
978
979   if (bd_add_del_ip_mac (bd_index, type, &ip_addr, &mac, mp->is_add))
980     rv = VNET_API_ERROR_UNSPECIFIED;
981
982 out:
983   REPLY_MACRO (VL_API_BD_IP_MAC_ADD_DEL_REPLY);
984 }
985
986 static void
987 vl_api_bd_ip_mac_flush_t_handler (vl_api_bd_ip_mac_flush_t * mp)
988 {
989   vl_api_bd_ip_mac_flush_reply_t *rmp;
990   bd_main_t *bdm = &bd_main;
991   u32 bd_index, bd_id;
992   int rv = 0;
993   uword *p;
994
995   bd_id = ntohl (mp->bd_id);
996
997   if (bd_id == 0)
998     {
999       rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
1000       goto out;
1001     }
1002
1003   p = hash_get (bdm->bd_index_by_bd_id, bd_id);
1004   if (p == 0)
1005     {
1006       rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1007       goto out;
1008     }
1009   bd_index = p[0];
1010
1011   bd_flush_ip_mac (bd_index);
1012
1013 out:
1014   REPLY_MACRO (VL_API_BD_IP_MAC_FLUSH_REPLY);
1015 }
1016
1017 extern void l2_efp_filter_configure (vnet_main_t * vnet_main,
1018                                      u32 sw_if_index, u8 enable);
1019
1020 static void
1021 vl_api_l2_interface_efp_filter_t_handler (vl_api_l2_interface_efp_filter_t *
1022                                           mp)
1023 {
1024   int rv;
1025   vl_api_l2_interface_efp_filter_reply_t *rmp;
1026   vnet_main_t *vnm = vnet_get_main ();
1027
1028   VALIDATE_SW_IF_INDEX (mp);
1029
1030   // enable/disable the feature
1031   l2_efp_filter_configure (vnm, ntohl (mp->sw_if_index), mp->enable_disable);
1032   rv = vnm->api_errno;
1033
1034   BAD_SW_IF_INDEX_LABEL;
1035   REPLY_MACRO (VL_API_L2_INTERFACE_EFP_FILTER_REPLY);
1036 }
1037
1038 static void
1039 vl_api_l2_patch_add_del_t_handler (vl_api_l2_patch_add_del_t * mp)
1040 {
1041   extern int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
1042                                     int is_add);
1043   vl_api_l2_patch_add_del_reply_t *rmp;
1044   int vnet_l2_patch_add_del (u32 rx_sw_if_index, u32 tx_sw_if_index,
1045                              int is_add);
1046   int rv = 0;
1047
1048   VALIDATE_RX_SW_IF_INDEX (mp);
1049   VALIDATE_TX_SW_IF_INDEX (mp);
1050
1051   rv = vnet_l2_patch_add_del (ntohl (mp->rx_sw_if_index),
1052                               ntohl (mp->tx_sw_if_index),
1053                               (int) (mp->is_add != 0));
1054
1055   BAD_RX_SW_IF_INDEX_LABEL;
1056   BAD_TX_SW_IF_INDEX_LABEL;
1057
1058   REPLY_MACRO (VL_API_L2_PATCH_ADD_DEL_REPLY);
1059 }
1060
1061 static void
1062 vl_api_sw_interface_set_vpath_t_handler (vl_api_sw_interface_set_vpath_t * mp)
1063 {
1064   vl_api_sw_interface_set_vpath_reply_t *rmp;
1065   int rv = 0;
1066   u32 sw_if_index = ntohl (mp->sw_if_index);
1067
1068   VALIDATE_SW_IF_INDEX (mp);
1069
1070   l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_VPATH, mp->enable);
1071   vnet_feature_enable_disable ("ip4-unicast", "vpath-input-ip4",
1072                                sw_if_index, mp->enable, 0, 0);
1073   vnet_feature_enable_disable ("ip4-multicast", "vpath-input-ip4",
1074                                sw_if_index, mp->enable, 0, 0);
1075   vnet_feature_enable_disable ("ip6-unicast", "vpath-input-ip6",
1076                                sw_if_index, mp->enable, 0, 0);
1077   vnet_feature_enable_disable ("ip6-multicast", "vpath-input-ip6",
1078                                sw_if_index, mp->enable, 0, 0);
1079
1080   BAD_SW_IF_INDEX_LABEL;
1081
1082   REPLY_MACRO (VL_API_SW_INTERFACE_SET_VPATH_REPLY);
1083 }
1084
1085 static void
1086 vl_api_bvi_create_t_handler (vl_api_bvi_create_t * mp)
1087 {
1088   vl_api_bvi_create_reply_t *rmp;
1089   mac_address_t mac;
1090   u32 sw_if_index;
1091   int rv;
1092
1093   mac_address_decode (mp->mac, &mac);
1094
1095   rv = l2_bvi_create (ntohl (mp->user_instance), &mac, &sw_if_index);
1096
1097   /* *INDENT-OFF* */
1098   REPLY_MACRO2(VL_API_BVI_CREATE_REPLY,
1099   ({
1100     rmp->sw_if_index = ntohl (sw_if_index);
1101   }));
1102   /* *INDENT-ON* */
1103 }
1104
1105 static void
1106 vl_api_bvi_delete_t_handler (vl_api_bvi_delete_t * mp)
1107 {
1108   vl_api_bvi_delete_reply_t *rmp;
1109   int rv;
1110
1111   rv = l2_bvi_delete (ntohl (mp->sw_if_index));
1112
1113   REPLY_MACRO (VL_API_BVI_DELETE_REPLY);
1114 }
1115
1116 static bool
1117 l2_arp_term_publish_event_is_equal (const l2_arp_term_publish_event_t * e1,
1118                                     const l2_arp_term_publish_event_t * e2)
1119 {
1120   if (e1 == NULL || e2 == NULL)
1121     return false;
1122   return (ip46_address_is_equal (&e1->ip, &e2->ip) &&
1123           (e1->sw_if_index == e2->sw_if_index) &&
1124           (mac_address_equal (&e1->mac, &e2->mac)));
1125 }
1126
1127 static uword
1128 l2_arp_term_process (vlib_main_t * vm, vlib_node_runtime_t * rt,
1129                      vlib_frame_t * f)
1130 {
1131   /* These cross the longjmp boundary (vlib_process_wait_for_event)
1132    * and need to be volatile - to prevent them from being optimized into
1133    * a register - which could change during suspension */
1134   volatile f64 last = vlib_time_now (vm);
1135   volatile l2_arp_term_publish_event_t last_event = { };
1136
1137   l2_arp_term_main_t *l2am = &l2_arp_term_main;
1138
1139   while (1)
1140     {
1141       uword event_type = L2_ARP_TERM_EVENT_PUBLISH;
1142       vpe_client_registration_t *reg;
1143       f64 now;
1144
1145       vlib_process_wait_for_event (vm);
1146
1147       vlib_process_get_event_data (vm, &event_type);
1148       now = vlib_time_now (vm);
1149
1150       if (event_type == L2_ARP_TERM_EVENT_PUBLISH)
1151         {
1152           l2_arp_term_publish_event_t *event;
1153
1154           vec_foreach (event, l2am->publish_events)
1155           {
1156             /* dampen duplicate events - cast away volatile */
1157             if (l2_arp_term_publish_event_is_equal
1158                 (event, (l2_arp_term_publish_event_t *) & last_event) &&
1159                 (now - last) < 10.0)
1160               {
1161                 continue;
1162               }
1163             last_event = *event;
1164             last = now;
1165
1166             pool_foreach (reg, vpe_api_main.l2_arp_term_events_registrations)
1167               {
1168                 vl_api_registration_t *vl_reg;
1169                 vl_reg =
1170                   vl_api_client_index_to_registration (reg->client_index);
1171                 ALWAYS_ASSERT (vl_reg != NULL);
1172
1173                 if (vl_reg && vl_api_can_send_msg (vl_reg))
1174                   {
1175                     vl_api_l2_arp_term_event_t *vevent;
1176                     vevent = vl_msg_api_alloc (sizeof *vevent);
1177                     clib_memset (vevent, 0, sizeof *vevent);
1178                     vevent->_vl_msg_id =
1179                       htons (REPLY_MSG_ID_BASE + VL_API_L2_ARP_TERM_EVENT);
1180                     vevent->client_index = reg->client_index;
1181                     vevent->pid = reg->client_pid;
1182                     ip_address_encode (&event->ip, event->type, &vevent->ip);
1183                     vevent->sw_if_index = htonl (event->sw_if_index);
1184                     mac_address_encode (&event->mac, vevent->mac);
1185                     vl_api_send_msg (vl_reg, (u8 *) vevent);
1186                   }
1187               }
1188           }
1189           vec_reset_length (l2am->publish_events);
1190         }
1191     }
1192
1193   return 0;
1194 }
1195
1196 /* *INDENT-OFF* */
1197 VLIB_REGISTER_NODE (l2_arp_term_process_node) = {
1198   .function = l2_arp_term_process,
1199   .type = VLIB_NODE_TYPE_PROCESS,
1200   .name = "l2-arp-term-publisher",
1201 };
1202 /* *INDENT-ON* */
1203
1204 static void
1205 vl_api_want_l2_arp_term_events_t_handler (vl_api_want_l2_arp_term_events_t *
1206                                           mp)
1207 {
1208   vl_api_want_l2_arp_term_events_reply_t *rmp;
1209   vpe_api_main_t *am = &vpe_api_main;
1210   vpe_client_registration_t *rp;
1211   int rv = 0;
1212   uword *p;
1213
1214   p = hash_get (am->l2_arp_term_events_registration_hash, mp->client_index);
1215
1216   if (p)
1217     {
1218       if (mp->enable)
1219         {
1220           clib_warning ("pid %d: already enabled...", mp->pid);
1221           rv = VNET_API_ERROR_INVALID_REGISTRATION;
1222           goto reply;
1223         }
1224       else
1225         {
1226           rp = pool_elt_at_index (am->l2_arp_term_events_registrations, p[0]);
1227           pool_put (am->l2_arp_term_events_registrations, rp);
1228           hash_unset (am->l2_arp_term_events_registration_hash,
1229                       mp->client_index);
1230           if (pool_elts (am->l2_arp_term_events_registrations) == 0)
1231             l2_arp_term_set_publisher_node (false);
1232           goto reply;
1233         }
1234     }
1235   if (mp->enable == 0)
1236     {
1237       clib_warning ("pid %d: already disabled...", mp->pid);
1238       rv = VNET_API_ERROR_INVALID_REGISTRATION;
1239       goto reply;
1240     }
1241   pool_get (am->l2_arp_term_events_registrations, rp);
1242   rp->client_index = mp->client_index;
1243   rp->client_pid = mp->pid;
1244   hash_set (am->l2_arp_term_events_registration_hash, rp->client_index,
1245             rp - am->l2_arp_term_events_registrations);
1246   l2_arp_term_set_publisher_node (true);
1247
1248 reply:
1249   REPLY_MACRO (VL_API_WANT_L2_ARP_TERM_EVENTS_REPLY);
1250 }
1251
1252 static clib_error_t *
1253 want_l2_arp_term_events_reaper (u32 client_index)
1254 {
1255   vpe_client_registration_t *rp;
1256   vpe_api_main_t *am;
1257   uword *p;
1258
1259   am = &vpe_api_main;
1260
1261   /* remove from the registration hash */
1262   p = hash_get (am->l2_arp_term_events_registration_hash, client_index);
1263
1264   if (p)
1265     {
1266       rp = pool_elt_at_index (am->l2_arp_term_events_registrations, p[0]);
1267       pool_put (am->l2_arp_term_events_registrations, rp);
1268       hash_unset (am->l2_arp_term_events_registration_hash, client_index);
1269       if (pool_elts (am->l2_arp_term_events_registrations) == 0)
1270         l2_arp_term_set_publisher_node (false);
1271     }
1272   return (NULL);
1273 }
1274
1275 VL_MSG_API_REAPER_FUNCTION (want_l2_arp_term_events_reaper);
1276
1277 #include <vnet/l2/l2.api.c>
1278 static clib_error_t *
1279 l2_api_hookup (vlib_main_t * vm)
1280 {
1281   api_main_t *am = vlibapi_get_main ();
1282
1283   /* Mark VL_API_BRIDGE_DOMAIN_DUMP as mp safe */
1284   vl_api_set_msg_thread_safe (am, VL_API_BRIDGE_DOMAIN_DUMP, 1);
1285
1286   /*
1287    * Set up the (msg_name, crc, message-id) table
1288    */
1289   REPLY_MSG_ID_BASE = setup_message_id_table ();
1290
1291   return 0;
1292 }
1293
1294 VLIB_API_INIT_FUNCTION (l2_api_hookup);
1295
1296 /*
1297  * fd.io coding-style-patch-verification: ON
1298  *
1299  * Local Variables:
1300  * eval: (c-set-style "gnu")
1301  * End:
1302  */