l2fib: MAC: Fix uint64 to u8 byte array
[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
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
49 #include <vlibapi/api_helper_macros.h>
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 _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del)             \
62 _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump)                   \
63 _(BRIDGE_FLAGS, bridge_flags)                               \
64 _(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite) \
65 _(L2_INTERFACE_PBB_TAG_REWRITE, l2_interface_pbb_tag_rewrite) \
66 _(BRIDGE_DOMAIN_SET_MAC_AGE, bridge_domain_set_mac_age)
67
68 static void
69 send_l2_xconnect_details (unix_shared_memory_queue_t * q, u32 context,
70                           u32 rx_sw_if_index, u32 tx_sw_if_index)
71 {
72   vl_api_l2_xconnect_details_t *mp;
73
74   mp = vl_msg_api_alloc (sizeof (*mp));
75   memset (mp, 0, sizeof (*mp));
76   mp->_vl_msg_id = ntohs (VL_API_L2_XCONNECT_DETAILS);
77   mp->context = context;
78   mp->rx_sw_if_index = htonl (rx_sw_if_index);
79   mp->tx_sw_if_index = htonl (tx_sw_if_index);
80
81   vl_msg_api_send_shmem (q, (u8 *) & mp);
82 }
83
84 static void
85 vl_api_l2_xconnect_dump_t_handler (vl_api_l2_xconnect_dump_t * mp)
86 {
87   unix_shared_memory_queue_t *q;
88   vnet_main_t *vnm = vnet_get_main ();
89   vnet_interface_main_t *im = &vnm->interface_main;
90   l2input_main_t *l2im = &l2input_main;
91   vnet_sw_interface_t *swif;
92   l2_input_config_t *config;
93
94   q = vl_api_client_index_to_input_queue (mp->client_index);
95   if (q == 0)
96     return;
97
98   /* *INDENT-OFF* */
99   pool_foreach (swif, im->sw_interfaces,
100   ({
101     config = vec_elt_at_index (l2im->configs, swif->sw_if_index);
102     if (config->xconnect)
103       send_l2_xconnect_details (q, mp->context, swif->sw_if_index,
104                                 config->output_sw_if_index);
105   }));
106   /* *INDENT-ON* */
107 }
108
109 static void
110 vl_api_l2_fib_clear_table_t_handler (vl_api_l2_fib_clear_table_t * mp)
111 {
112   int rv = 0;
113   vl_api_l2_fib_clear_table_reply_t *rmp;
114
115   /* Clear all MACs including static MACs  */
116   l2fib_clear_table ();
117
118   REPLY_MACRO (VL_API_L2_FIB_CLEAR_TABLE_REPLY);
119 }
120
121 static void
122 send_l2fib_table_entry (vpe_api_main_t * am,
123                         unix_shared_memory_queue_t * q,
124                         l2fib_entry_key_t * l2fe_key,
125                         l2fib_entry_result_t * l2fe_res, u32 context)
126 {
127   vl_api_l2_fib_table_details_t *mp;
128
129   mp = vl_msg_api_alloc (sizeof (*mp));
130   memset (mp, 0, sizeof (*mp));
131   mp->_vl_msg_id = ntohs (VL_API_L2_FIB_TABLE_DETAILS);
132
133   mp->bd_id =
134     ntohl (l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
135
136   clib_memcpy (mp->mac, l2fe_key->fields.mac, 6);
137   mp->sw_if_index = ntohl (l2fe_res->fields.sw_if_index);
138   mp->static_mac = l2fe_res->fields.static_mac;
139   mp->filter_mac = l2fe_res->fields.filter;
140   mp->bvi_mac = l2fe_res->fields.bvi;
141   mp->context = context;
142
143   vl_msg_api_send_shmem (q, (u8 *) & mp);
144 }
145
146 static void
147 vl_api_l2_fib_table_dump_t_handler (vl_api_l2_fib_table_dump_t * mp)
148 {
149   vpe_api_main_t *am = &vpe_api_main;
150   bd_main_t *bdm = &bd_main;
151   l2fib_entry_key_t *l2fe_key = NULL;
152   l2fib_entry_result_t *l2fe_res = NULL;
153   u32 ni, bd_id = ntohl (mp->bd_id);
154   u32 bd_index;
155   unix_shared_memory_queue_t *q;
156   uword *p;
157
158   q = vl_api_client_index_to_input_queue (mp->client_index);
159   if (q == 0)
160     return;
161
162   /* see l2fib_table_dump: ~0 means "any" */
163   if (bd_id == ~0)
164     bd_index = ~0;
165   else
166     {
167       p = hash_get (bdm->bd_index_by_bd_id, bd_id);
168       if (p == 0)
169         return;
170
171       bd_index = p[0];
172     }
173
174   l2fib_table_dump (bd_index, &l2fe_key, &l2fe_res);
175
176   vec_foreach_index (ni, l2fe_key)
177   {
178     send_l2fib_table_entry (am, q, vec_elt_at_index (l2fe_key, ni),
179                             vec_elt_at_index (l2fe_res, ni), mp->context);
180   }
181   vec_free (l2fe_key);
182   vec_free (l2fe_res);
183 }
184
185 static void
186 vl_api_l2fib_add_del_t_handler (vl_api_l2fib_add_del_t * mp)
187 {
188   bd_main_t *bdm = &bd_main;
189   l2input_main_t *l2im = &l2input_main;
190   vl_api_l2fib_add_del_reply_t *rmp;
191   int rv = 0;
192   u32 bd_id = ntohl (mp->bd_id);
193   uword *p = hash_get (bdm->bd_index_by_bd_id, bd_id);
194
195   if (!p)
196     {
197       rv = VNET_API_ERROR_NO_SUCH_ENTRY;
198       goto bad_sw_if_index;
199     }
200   u32 bd_index = p[0];
201
202   u8 mac[6];
203
204   clib_memcpy (mac, mp->mac, 6);
205   if (mp->is_add)
206     {
207       if (mp->filter_mac)
208         l2fib_add_filter_entry (mac, bd_index);
209       else
210         {
211           u32 sw_if_index = ntohl (mp->sw_if_index);
212           VALIDATE_SW_IF_INDEX (mp);
213           if (vec_len (l2im->configs) <= sw_if_index)
214             {
215               rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
216               goto bad_sw_if_index;
217             }
218           else
219             {
220               l2_input_config_t *config;
221               config = vec_elt_at_index (l2im->configs, sw_if_index);
222               if (config->bridge == 0)
223                 {
224                   rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
225                   goto bad_sw_if_index;
226                 }
227             }
228           u8 static_mac = mp->static_mac ? 1 : 0;
229           u8 bvi_mac = mp->bvi_mac ? 1 : 0;
230           l2fib_add_fwd_entry (mac, bd_index, sw_if_index, static_mac,
231                                bvi_mac);
232         }
233     }
234   else
235     {
236       l2fib_del_entry (mac, bd_index);
237     }
238
239   BAD_SW_IF_INDEX_LABEL;
240
241   REPLY_MACRO (VL_API_L2FIB_ADD_DEL_REPLY);
242 }
243
244 static void
245 vl_api_want_l2_macs_events_t_handler (vl_api_want_l2_macs_events_t * mp)
246 {
247   int rv = 0;
248   vl_api_want_l2_macs_events_reply_t *rmp;
249   l2learn_main_t *lm = &l2learn_main;
250   l2fib_main_t *fm = &l2fib_main;
251   u32 pid = ntohl (mp->pid);
252   u32 learn_limit = ntohl (mp->learn_limit);
253
254   if (mp->enable_disable)
255     {
256       if (lm->client_pid == 0)
257         {
258           lm->client_pid = pid;
259           lm->client_index = mp->client_index;
260
261           if (mp->max_macs_in_event)
262             fm->max_macs_in_event = mp->max_macs_in_event * 10;
263           else
264             fm->max_macs_in_event = L2FIB_EVENT_MAX_MACS_DEFAULT;
265
266           if (mp->scan_delay)
267             fm->event_scan_delay = (f64) (mp->scan_delay) * 10e-3;
268           else
269             fm->event_scan_delay = L2FIB_EVENT_SCAN_DELAY_DEFAULT;
270
271           /* change learn limit and flush all learned MACs */
272           if (learn_limit && (learn_limit < L2LEARN_DEFAULT_LIMIT))
273             lm->global_learn_limit = learn_limit;
274           else
275             lm->global_learn_limit = L2FIB_EVENT_LEARN_LIMIT_DEFAULT;
276
277           l2fib_flush_all_mac (vlib_get_main ());
278         }
279       else if (lm->client_pid != pid)
280         {
281           rv = VNET_API_ERROR_L2_MACS_EVENT_CLINET_PRESENT;
282           goto exit;
283         }
284     }
285   else if (lm->client_pid)
286     {
287       lm->client_pid = 0;
288       lm->client_index = 0;
289       if (learn_limit && (learn_limit < L2LEARN_DEFAULT_LIMIT))
290         lm->global_learn_limit = learn_limit;
291       else
292         lm->global_learn_limit = L2LEARN_DEFAULT_LIMIT;
293     }
294
295 exit:
296   REPLY_MACRO (VL_API_WANT_L2_MACS_EVENTS_REPLY);
297 }
298
299 static void
300 vl_api_l2fib_flush_int_t_handler (vl_api_l2fib_flush_int_t * mp)
301 {
302   int rv = 0;
303   vlib_main_t *vm = vlib_get_main ();
304   vl_api_l2fib_flush_int_reply_t *rmp;
305
306   VALIDATE_SW_IF_INDEX (mp);
307
308   u32 sw_if_index = ntohl (mp->sw_if_index);
309   l2fib_flush_int_mac (vm, sw_if_index);
310
311   BAD_SW_IF_INDEX_LABEL;
312   REPLY_MACRO (VL_API_L2FIB_FLUSH_INT_REPLY);
313 }
314
315 static void
316 vl_api_l2fib_flush_all_t_handler (vl_api_l2fib_flush_all_t * mp)
317 {
318   int rv = 0;
319   vl_api_l2fib_flush_all_reply_t *rmp;
320
321   l2fib_flush_all_mac (vlib_get_main ());
322   REPLY_MACRO (VL_API_L2FIB_FLUSH_ALL_REPLY);
323 }
324
325 static void
326 vl_api_l2fib_flush_bd_t_handler (vl_api_l2fib_flush_bd_t * mp)
327 {
328   int rv = 0;
329   vlib_main_t *vm = vlib_get_main ();
330   bd_main_t *bdm = &bd_main;
331   vl_api_l2fib_flush_bd_reply_t *rmp;
332
333   u32 bd_id = ntohl (mp->bd_id);
334   uword *p = hash_get (bdm->bd_index_by_bd_id, bd_id);
335   if (p == 0)
336     {
337       rv = VNET_API_ERROR_NO_SUCH_ENTRY;
338       goto out;
339     }
340   l2fib_flush_bd_mac (vm, *p);
341 out:
342   REPLY_MACRO (VL_API_L2FIB_FLUSH_BD_REPLY);
343 }
344
345 static void
346 vl_api_l2_flags_t_handler (vl_api_l2_flags_t * mp)
347 {
348   vl_api_l2_flags_reply_t *rmp;
349   int rv = 0;
350   u32 rbm = 0;
351
352   VALIDATE_SW_IF_INDEX (mp);
353
354   u32 sw_if_index = ntohl (mp->sw_if_index);
355   u32 flags = ntohl (mp->feature_bitmap);
356   u32 bitmap = 0;
357
358   if (flags & L2_LEARN)
359     bitmap |= L2INPUT_FEAT_LEARN;
360
361   if (flags & L2_FWD)
362     bitmap |= L2INPUT_FEAT_FWD;
363
364   if (flags & L2_FLOOD)
365     bitmap |= L2INPUT_FEAT_FLOOD;
366
367   if (flags & L2_UU_FLOOD)
368     bitmap |= L2INPUT_FEAT_UU_FLOOD;
369
370   if (flags & L2_ARP_TERM)
371     bitmap |= L2INPUT_FEAT_ARP_TERM;
372
373   rbm = l2input_intf_bitmap_enable (sw_if_index, bitmap, mp->is_set);
374
375   BAD_SW_IF_INDEX_LABEL;
376
377   /* *INDENT-OFF* */
378   REPLY_MACRO2(VL_API_L2_FLAGS_REPLY,
379   ({
380     rmp->resulting_feature_bitmap = ntohl(rbm);
381   }));
382   /* *INDENT-ON* */
383 }
384
385 static void
386 vl_api_bridge_domain_set_mac_age_t_handler (vl_api_bridge_domain_set_mac_age_t
387                                             * mp)
388 {
389   vlib_main_t *vm = vlib_get_main ();
390   bd_main_t *bdm = &bd_main;
391   vl_api_bridge_domain_set_mac_age_reply_t *rmp;
392   int rv = 0;
393   u32 bd_id = ntohl (mp->bd_id);
394   uword *p;
395
396   if (bd_id == 0)
397     {
398       rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
399       goto out;
400     }
401
402   p = hash_get (bdm->bd_index_by_bd_id, bd_id);
403   if (p == 0)
404     {
405       rv = VNET_API_ERROR_NO_SUCH_ENTRY;
406       goto out;
407     }
408   bd_set_mac_age (vm, *p, mp->mac_age);
409 out:
410   REPLY_MACRO (VL_API_BRIDGE_DOMAIN_SET_MAC_AGE_REPLY);
411 }
412
413 static void
414 vl_api_bridge_domain_add_del_t_handler (vl_api_bridge_domain_add_del_t * mp)
415 {
416   l2_bridge_domain_add_del_args_t a = {
417     .is_add = mp->is_add,
418     .flood = mp->flood,
419     .uu_flood = mp->uu_flood,
420     .forward = mp->forward,
421     .learn = mp->learn,
422     .arp_term = mp->arp_term,
423     .mac_age = mp->mac_age,
424     .bd_id = ntohl (mp->bd_id),
425     .bd_tag = mp->bd_tag
426   };
427
428   int rv = bd_add_del (&a);
429
430   vl_api_bridge_domain_add_del_reply_t *rmp;
431   REPLY_MACRO (VL_API_BRIDGE_DOMAIN_ADD_DEL_REPLY);
432 }
433
434 static void
435 send_bridge_domain_details (l2input_main_t * l2im,
436                             unix_shared_memory_queue_t * q,
437                             l2_bridge_domain_t * bd_config,
438                             u32 n_sw_ifs, u32 context)
439 {
440   vl_api_bridge_domain_details_t *mp;
441   l2_flood_member_t *m;
442   vl_api_bridge_domain_sw_if_t *sw_ifs;
443   l2_input_config_t *input_cfg;
444
445   mp = vl_msg_api_alloc (sizeof (*mp) +
446                          (n_sw_ifs * sizeof (vl_api_bridge_domain_sw_if_t)));
447   memset (mp, 0, sizeof (*mp));
448   mp->_vl_msg_id = ntohs (VL_API_BRIDGE_DOMAIN_DETAILS);
449   mp->bd_id = ntohl (bd_config->bd_id);
450   mp->flood = bd_feature_flood (bd_config);
451   mp->uu_flood = bd_feature_uu_flood (bd_config);
452   mp->forward = bd_feature_forward (bd_config);
453   mp->learn = bd_feature_learn (bd_config);
454   mp->arp_term = bd_feature_arp_term (bd_config);
455   mp->bvi_sw_if_index = ntohl (bd_config->bvi_sw_if_index);
456   mp->mac_age = bd_config->mac_age;
457   if (bd_config->bd_tag)
458     {
459       strncpy ((char *) mp->bd_tag, (char *) bd_config->bd_tag,
460                ARRAY_LEN (mp->bd_tag) - 1);
461       mp->bd_tag[ARRAY_LEN (mp->bd_tag) - 1] = 0;
462     }
463
464   mp->context = context;
465
466   sw_ifs = (vl_api_bridge_domain_sw_if_t *) mp->sw_if_details;
467   vec_foreach (m, bd_config->members)
468   {
469     sw_ifs->sw_if_index = ntohl (m->sw_if_index);
470     input_cfg = vec_elt_at_index (l2im->configs, m->sw_if_index);
471     sw_ifs->shg = input_cfg->shg;
472     sw_ifs++;
473     mp->n_sw_ifs++;
474   }
475   mp->n_sw_ifs = htonl (mp->n_sw_ifs);
476
477   vl_msg_api_send_shmem (q, (u8 *) & mp);
478 }
479
480 static void
481 vl_api_bridge_domain_dump_t_handler (vl_api_bridge_domain_dump_t * mp)
482 {
483   bd_main_t *bdm = &bd_main;
484   l2input_main_t *l2im = &l2input_main;
485
486   unix_shared_memory_queue_t *q =
487     vl_api_client_index_to_input_queue (mp->client_index);
488   if (q == 0)
489     return;
490
491   u32 bd_id = ntohl (mp->bd_id);
492   if (bd_id == 0)
493     return;
494
495   u32 bd_index, end;
496   if (bd_id == ~0)
497     bd_index = 0, end = vec_len (l2im->bd_configs);
498   else
499     {
500       bd_index = bd_find_index (bdm, bd_id);
501       if (bd_index == ~0)
502         return;
503
504       end = bd_index + 1;
505     }
506
507   for (; bd_index < end; bd_index++)
508     {
509       l2_bridge_domain_t *bd_config =
510         l2input_bd_config_from_index (l2im, bd_index);
511       /* skip dummy bd_id 0 */
512       if (bd_config && (bd_config->bd_id > 0))
513         send_bridge_domain_details (l2im, q, bd_config,
514                                     vec_len (bd_config->members),
515                                     mp->context);
516     }
517 }
518
519 static void
520 vl_api_bridge_flags_t_handler (vl_api_bridge_flags_t * mp)
521 {
522   vlib_main_t *vm = vlib_get_main ();
523   bd_main_t *bdm = &bd_main;
524   vl_api_bridge_flags_reply_t *rmp;
525   int rv = 0;
526
527   u32 flags = ntohl (mp->feature_bitmap);
528   u32 bd_id = ntohl (mp->bd_id);
529   if (bd_id == 0)
530     {
531       rv = VNET_API_ERROR_BD_NOT_MODIFIABLE;
532       goto out;
533     }
534
535   u32 bd_index = bd_find_index (bdm, bd_id);
536   if (bd_index == ~0)
537     {
538       rv = VNET_API_ERROR_NO_SUCH_ENTRY;
539       goto out;
540     }
541
542   u32 bitmap = bd_set_flags (vm, bd_index, flags, mp->is_set);
543
544 out:
545   /* *INDENT-OFF* */
546   REPLY_MACRO2(VL_API_BRIDGE_FLAGS_REPLY,
547   ({
548     rmp->resulting_feature_bitmap = ntohl(bitmap);
549   }));
550   /* *INDENT-ON* */
551 }
552
553 static void
554   vl_api_l2_interface_vlan_tag_rewrite_t_handler
555   (vl_api_l2_interface_vlan_tag_rewrite_t * mp)
556 {
557   int rv = 0;
558   vl_api_l2_interface_vlan_tag_rewrite_reply_t *rmp;
559   vnet_main_t *vnm = vnet_get_main ();
560   vlib_main_t *vm = vlib_get_main ();
561   u32 vtr_op;
562
563   VALIDATE_SW_IF_INDEX (mp);
564
565   vtr_op = ntohl (mp->vtr_op);
566
567   /* The L2 code is unsuspicious */
568   switch (vtr_op)
569     {
570     case L2_VTR_DISABLED:
571     case L2_VTR_PUSH_1:
572     case L2_VTR_PUSH_2:
573     case L2_VTR_POP_1:
574     case L2_VTR_POP_2:
575     case L2_VTR_TRANSLATE_1_1:
576     case L2_VTR_TRANSLATE_1_2:
577     case L2_VTR_TRANSLATE_2_1:
578     case L2_VTR_TRANSLATE_2_2:
579       break;
580
581     default:
582       rv = VNET_API_ERROR_INVALID_VALUE;
583       goto bad_sw_if_index;
584     }
585
586   rv = l2vtr_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
587                         ntohl (mp->push_dot1q), ntohl (mp->tag1),
588                         ntohl (mp->tag2));
589
590   BAD_SW_IF_INDEX_LABEL;
591
592   REPLY_MACRO (VL_API_L2_INTERFACE_VLAN_TAG_REWRITE_REPLY);
593 }
594
595 static void
596   vl_api_l2_interface_pbb_tag_rewrite_t_handler
597   (vl_api_l2_interface_pbb_tag_rewrite_t * mp)
598 {
599   vl_api_l2_interface_pbb_tag_rewrite_reply_t *rmp;
600   vnet_main_t *vnm = vnet_get_main ();
601   vlib_main_t *vm = vlib_get_main ();
602   u32 vtr_op;
603   int rv = 0;
604
605   VALIDATE_SW_IF_INDEX (mp);
606
607   vtr_op = ntohl (mp->vtr_op);
608
609   switch (vtr_op)
610     {
611     case L2_VTR_DISABLED:
612     case L2_VTR_PUSH_2:
613     case L2_VTR_POP_2:
614     case L2_VTR_TRANSLATE_2_1:
615       break;
616
617     default:
618       rv = VNET_API_ERROR_INVALID_VALUE;
619       goto bad_sw_if_index;
620     }
621
622   rv = l2pbb_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
623                         mp->b_dmac, mp->b_smac, ntohs (mp->b_vlanid),
624                         ntohl (mp->i_sid), ntohs (mp->outer_tag));
625
626   BAD_SW_IF_INDEX_LABEL;
627
628   REPLY_MACRO (VL_API_L2_INTERFACE_PBB_TAG_REWRITE_REPLY);
629 }
630
631 /*
632  * l2_api_hookup
633  * Add vpe's API message handlers to the table.
634  * vlib has alread mapped shared memory and
635  * added the client registration handlers.
636  * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
637  */
638 #define vl_msg_name_crc_list
639 #include <vnet/vnet_all_api_h.h>
640 #undef vl_msg_name_crc_list
641
642 static void
643 setup_message_id_table (api_main_t * am)
644 {
645 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
646   foreach_vl_msg_name_crc_l2;
647 #undef _
648 }
649
650 static clib_error_t *
651 l2_api_hookup (vlib_main_t * vm)
652 {
653   api_main_t *am = &api_main;
654
655 #define _(N,n)                                                  \
656     vl_msg_api_set_handlers(VL_API_##N, #n,                     \
657                            vl_api_##n##_t_handler,              \
658                            vl_noop_handler,                     \
659                            vl_api_##n##_t_endian,               \
660                            vl_api_##n##_t_print,                \
661                            sizeof(vl_api_##n##_t), 1);
662   foreach_vpe_api_msg;
663 #undef _
664
665   /*
666    * Set up the (msg_name, crc, message-id) table
667    */
668   setup_message_id_table (am);
669
670   return 0;
671 }
672
673 VLIB_API_INIT_FUNCTION (l2_api_hookup);
674
675 /*
676  * fd.io coding-style-patch-verification: ON
677  *
678  * Local Variables:
679  * eval: (c-set-style "gnu")
680  * End:
681  */