api: refactor vlibmemory
[vpp.git] / src / vnet / lisp-cp / one_api.c
1 /*
2  *------------------------------------------------------------------
3  * one_api.c - Overlay Network Engine API
4  *
5  * Copyright (c) 2016-2017 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/lisp-cp/control.h>
26 #include <vnet/lisp-gpe/lisp_gpe.h>
27
28 #include <vnet/vnet_msg_enum.h>
29
30 #define vl_api_one_remote_locator_t_endian vl_noop_handler
31 #define vl_api_one_remote_locator_t_print vl_noop_handler
32 #define vl_api_one_local_locator_t_endian vl_noop_handler
33 #define vl_api_one_local_locator_t_print vl_noop_handler
34
35 #define vl_api_one_add_del_locator_set_t_endian vl_noop_handler
36 #define vl_api_one_add_del_locator_set_t_print vl_noop_handler
37 #define vl_api_one_add_del_remote_mapping_t_endian vl_noop_handler
38 #define vl_api_one_add_del_remote_mapping_t_print vl_noop_handler
39
40 #define vl_api_one_add_del_locator_set_t_endian vl_noop_handler
41 #define vl_api_one_add_del_locator_set_t_print vl_noop_handler
42 #define vl_api_one_add_del_remote_mapping_t_endian vl_noop_handler
43 #define vl_api_one_add_del_remote_mapping_t_print vl_noop_handler
44
45 #define vl_api_one_l2_arp_entry_t_endian vl_noop_handler
46 #define vl_api_one_l2_arp_entry_t_print vl_noop_handler
47 #define vl_api_one_add_del_l2_arp_entry vl_noop_handler
48 #define vl_api_one_l2_arp_bd_get vl_noop_handler
49
50 #define vl_api_one_ndp_entry_t_endian vl_noop_handler
51 #define vl_api_one_ndp_entry_t_print vl_noop_handler
52 #define vl_api_one_ndp_entries_get_reply_t_endian vl_noop_handler
53 #define vl_api_one_ndp_entries_get_reply_t_print vl_noop_handler
54
55 #define vl_typedefs             /* define message structures */
56 #include <vnet/vnet_all_api_h.h>
57 #undef vl_typedefs
58
59 #define vl_endianfun            /* define message structures */
60 #include <vnet/vnet_all_api_h.h>
61 #undef vl_endianfun
62
63 /* instantiate all the print functions we know about */
64 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
65 #define vl_printfun
66 #include <vnet/vnet_all_api_h.h>
67 #undef vl_printfun
68
69 #include <vlibapi/api_helper_macros.h>
70
71 #define REPLY_DETAILS(t, body)                                  \
72 do {                                                            \
73     svm_queue_t * q;                             \
74     rv = vl_msg_api_pd_handler (mp, rv);                        \
75     q = vl_api_client_index_to_input_queue (mp->client_index);  \
76     if (!q)                                                     \
77         return;                                                 \
78                                                                 \
79     rmp = vl_msg_api_alloc (sizeof (*rmp));                     \
80     rmp->_vl_msg_id = ntohs((t));                               \
81     rmp->context = mp->context;                                 \
82     do {body;} while (0);                                       \
83     vl_msg_api_send_shmem (q, (u8 *)&rmp);                      \
84 } while(0);
85
86 #define foreach_vpe_api_msg                             \
87 _(ONE_ADD_DEL_LOCATOR_SET, one_add_del_locator_set)                     \
88 _(ONE_ADD_DEL_LOCATOR, one_add_del_locator)                             \
89 _(ONE_ADD_DEL_LOCAL_EID, one_add_del_local_eid)                         \
90 _(ONE_ADD_DEL_MAP_RESOLVER, one_add_del_map_resolver)                   \
91 _(ONE_ADD_DEL_MAP_SERVER, one_add_del_map_server)                       \
92 _(ONE_ENABLE_DISABLE, one_enable_disable)                               \
93 _(ONE_RLOC_PROBE_ENABLE_DISABLE, one_rloc_probe_enable_disable)         \
94 _(ONE_MAP_REGISTER_ENABLE_DISABLE, one_map_register_enable_disable)     \
95 _(ONE_MAP_REGISTER_FALLBACK_THRESHOLD,                                  \
96   one_map_register_fallback_threshold)                                  \
97 _(ONE_ADD_DEL_REMOTE_MAPPING, one_add_del_remote_mapping)               \
98 _(ONE_ADD_DEL_ADJACENCY, one_add_del_adjacency)                         \
99 _(ONE_PITR_SET_LOCATOR_SET, one_pitr_set_locator_set)                   \
100 _(ONE_NSH_SET_LOCATOR_SET, one_nsh_set_locator_set)                     \
101 _(ONE_MAP_REQUEST_MODE, one_map_request_mode)                           \
102 _(ONE_EID_TABLE_ADD_DEL_MAP, one_eid_table_add_del_map)                 \
103 _(ONE_LOCATOR_SET_DUMP, one_locator_set_dump)                           \
104 _(ONE_LOCATOR_DUMP, one_locator_dump)                                   \
105 _(ONE_EID_TABLE_DUMP, one_eid_table_dump)                               \
106 _(ONE_MAP_RESOLVER_DUMP, one_map_resolver_dump)                         \
107 _(ONE_MAP_SERVER_DUMP, one_map_server_dump)                             \
108 _(ONE_EID_TABLE_MAP_DUMP, one_eid_table_map_dump)                       \
109 _(ONE_EID_TABLE_VNI_DUMP, one_eid_table_vni_dump)                       \
110 _(ONE_ADJACENCIES_GET, one_adjacencies_get)                             \
111 _(ONE_MAP_REGISTER_SET_TTL, one_map_register_set_ttl)                   \
112 _(SHOW_ONE_NSH_MAPPING, show_one_nsh_mapping)                           \
113 _(SHOW_ONE_RLOC_PROBE_STATE, show_one_rloc_probe_state)                 \
114 _(SHOW_ONE_MAP_REGISTER_STATE, show_one_map_register_state)             \
115 _(SHOW_ONE_MAP_REGISTER_TTL, show_one_map_register_ttl)                 \
116 _(SHOW_ONE_MAP_REGISTER_FALLBACK_THRESHOLD,                             \
117   show_one_map_register_fallback_threshold)                             \
118 _(SHOW_ONE_STATUS, show_one_status)                                     \
119 _(ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS,                                    \
120   one_add_del_map_request_itr_rlocs)                                    \
121 _(ONE_GET_MAP_REQUEST_ITR_RLOCS, one_get_map_request_itr_rlocs)         \
122 _(SHOW_ONE_PITR, show_one_pitr)                                         \
123 _(SHOW_ONE_MAP_REQUEST_MODE, show_one_map_request_mode)                 \
124 _(ONE_USE_PETR, one_use_petr)                                           \
125 _(SHOW_ONE_USE_PETR, show_one_use_petr)                                 \
126 _(SHOW_ONE_STATS_ENABLE_DISABLE, show_one_stats_enable_disable)         \
127 _(ONE_STATS_ENABLE_DISABLE, one_stats_enable_disable)                   \
128 _(ONE_STATS_DUMP, one_stats_dump)                                       \
129 _(ONE_STATS_FLUSH, one_stats_flush)                                     \
130 _(ONE_L2_ARP_BD_GET, one_l2_arp_bd_get)                                 \
131 _(ONE_L2_ARP_ENTRIES_GET, one_l2_arp_entries_get)                       \
132 _(ONE_ADD_DEL_L2_ARP_ENTRY, one_add_del_l2_arp_entry)                   \
133 _(ONE_ADD_DEL_NDP_ENTRY, one_add_del_ndp_entry)                         \
134 _(ONE_NDP_BD_GET, one_ndp_bd_get)                                       \
135 _(ONE_NDP_ENTRIES_GET, one_ndp_entries_get)                             \
136 _(ONE_SET_TRANSPORT_PROTOCOL, one_set_transport_protocol)               \
137 _(ONE_GET_TRANSPORT_PROTOCOL, one_get_transport_protocol)               \
138 _(ONE_ENABLE_DISABLE_XTR_MODE, one_enable_disable_xtr_mode)             \
139 _(ONE_SHOW_XTR_MODE, one_show_xtr_mode)                                 \
140 _(ONE_ENABLE_DISABLE_PITR_MODE, one_enable_disable_pitr_mode)           \
141 _(ONE_SHOW_PITR_MODE, one_show_pitr_mode)                               \
142 _(ONE_ENABLE_DISABLE_PETR_MODE, one_enable_disable_petr_mode)           \
143 _(ONE_SHOW_PETR_MODE, one_show_petr_mode)                               \
144
145
146 static locator_t *
147 unformat_one_locs (vl_api_one_remote_locator_t * rmt_locs, u32 rloc_num)
148 {
149   u32 i;
150   locator_t *locs = 0, loc;
151   vl_api_one_remote_locator_t *r;
152
153   for (i = 0; i < rloc_num; i++)
154     {
155       /* remote locators */
156       r = &rmt_locs[i];
157       memset (&loc, 0, sizeof (loc));
158       gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
159
160       loc.priority = r->priority;
161       loc.weight = r->weight;
162
163       vec_add1 (locs, loc);
164     }
165   return locs;
166 }
167
168 static void
169 vl_api_one_map_register_set_ttl_t_handler (vl_api_one_map_register_set_ttl_t *
170                                            mp)
171 {
172   vl_api_one_map_register_set_ttl_reply_t *rmp;
173   int rv = 0;
174
175   mp->ttl = clib_net_to_host_u32 (mp->ttl);
176   rv = vnet_lisp_map_register_set_ttl (mp->ttl);
177
178   REPLY_MACRO (VL_API_ONE_MAP_REGISTER_SET_TTL_REPLY);
179 }
180
181 static void
182   vl_api_show_one_map_register_ttl_t_handler
183   (vl_api_show_one_map_register_ttl_t * mp)
184 {
185   vl_api_show_one_map_register_ttl_reply_t *rmp;
186   int rv = 0;
187
188   u32 ttl = vnet_lisp_map_register_get_ttl ();
189   /* *INDENT-OFF* */
190   REPLY_MACRO2 (VL_API_SHOW_ONE_MAP_REGISTER_TTL_REPLY,
191   ({
192     rmp->ttl = clib_host_to_net_u32 (ttl);
193   }));
194   /* *INDENT-ON* */
195 }
196
197 static void
198 vl_api_one_add_del_locator_set_t_handler (vl_api_one_add_del_locator_set_t *
199                                           mp)
200 {
201   vl_api_one_add_del_locator_set_reply_t *rmp;
202   int rv = 0;
203   vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
204   locator_t locator;
205   vl_api_one_local_locator_t *ls_loc;
206   u32 ls_index = ~0, locator_num;
207   u8 *locator_name = NULL;
208   int i;
209
210   memset (a, 0, sizeof (a[0]));
211
212   mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0;
213   locator_name = format (0, "%s", mp->locator_set_name);
214   vec_terminate_c_string (locator_name);
215
216   a->name = locator_name;
217   a->is_add = mp->is_add;
218   a->local = 1;
219   locator_num = clib_net_to_host_u32 (mp->locator_num);
220
221   memset (&locator, 0, sizeof (locator));
222   for (i = 0; i < locator_num; i++)
223     {
224       ls_loc = &mp->locators[i];
225       VALIDATE_SW_IF_INDEX (ls_loc);
226
227       locator.sw_if_index = htonl (ls_loc->sw_if_index);
228       locator.priority = ls_loc->priority;
229       locator.weight = ls_loc->weight;
230       locator.local = 1;
231       vec_add1 (a->locators, locator);
232     }
233
234   rv = vnet_lisp_add_del_locator_set (a, &ls_index);
235
236   BAD_SW_IF_INDEX_LABEL;
237
238   vec_free (locator_name);
239   vec_free (a->locators);
240
241   /* *INDENT-OFF* */
242   REPLY_MACRO2 (VL_API_ONE_ADD_DEL_LOCATOR_SET_REPLY,
243   ({
244     rmp->ls_index = clib_host_to_net_u32 (ls_index);
245   }));
246   /* *INDENT-ON* */
247 }
248
249 static void
250 vl_api_one_add_del_locator_t_handler (vl_api_one_add_del_locator_t * mp)
251 {
252   vl_api_one_add_del_locator_reply_t *rmp;
253   int rv = 0;
254   locator_t locator, *locators = NULL;
255   vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
256   u32 ls_index = ~0;
257   u8 *locator_name = NULL;
258
259   memset (&locator, 0, sizeof (locator));
260   memset (a, 0, sizeof (a[0]));
261
262   locator.sw_if_index = ntohl (mp->sw_if_index);
263   locator.priority = mp->priority;
264   locator.weight = mp->weight;
265   locator.local = 1;
266   vec_add1 (locators, locator);
267
268   mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0;
269   locator_name = format (0, "%s", mp->locator_set_name);
270   vec_terminate_c_string (locator_name);
271
272   a->name = locator_name;
273   a->locators = locators;
274   a->is_add = mp->is_add;
275   a->local = 1;
276
277   rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
278
279   vec_free (locators);
280   vec_free (locator_name);
281
282   REPLY_MACRO (VL_API_ONE_ADD_DEL_LOCATOR_REPLY);
283 }
284
285 typedef struct
286 {
287   u32 spi;
288   u8 si;
289 } __attribute__ ((__packed__)) lisp_nsh_api_t;
290
291 static int
292 unformat_one_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
293                       u8 len)
294 {
295   lisp_nsh_api_t *nsh;
296
297   switch (type)
298     {
299     case 0:                     /* ipv4 */
300       gid_address_type (dst) = GID_ADDR_IP_PREFIX;
301       gid_address_ip_set (dst, src, IP4);
302       gid_address_ippref_len (dst) = len;
303       ip_prefix_normalize (&gid_address_ippref (dst));
304       break;
305     case 1:                     /* ipv6 */
306       gid_address_type (dst) = GID_ADDR_IP_PREFIX;
307       gid_address_ip_set (dst, src, IP6);
308       gid_address_ippref_len (dst) = len;
309       ip_prefix_normalize (&gid_address_ippref (dst));
310       break;
311     case 2:                     /* l2 mac */
312       gid_address_type (dst) = GID_ADDR_MAC;
313       clib_memcpy (&gid_address_mac (dst), src, 6);
314       break;
315     case 3:                     /* NSH */
316       gid_address_type (dst) = GID_ADDR_NSH;
317       nsh = src;
318       gid_address_nsh_spi (dst) = clib_net_to_host_u32 (nsh->spi);
319       gid_address_nsh_si (dst) = nsh->si;
320       break;
321     default:
322       /* unknown type */
323       return VNET_API_ERROR_INVALID_VALUE;
324     }
325
326   gid_address_vni (dst) = vni;
327
328   return 0;
329 }
330
331 static void
332 vl_api_one_add_del_local_eid_t_handler (vl_api_one_add_del_local_eid_t * mp)
333 {
334   vl_api_one_add_del_local_eid_reply_t *rmp;
335   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
336   int rv = 0;
337   gid_address_t _eid, *eid = &_eid;
338   uword *p = NULL;
339   u32 locator_set_index = ~0, map_index = ~0;
340   vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
341   u8 *name = NULL, *key = NULL;
342   memset (a, 0, sizeof (a[0]));
343   memset (eid, 0, sizeof (eid[0]));
344
345   rv = unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
346                              mp->eid_type, mp->eid, mp->prefix_len);
347   if (rv)
348     goto out;
349
350   if (gid_address_type (eid) == GID_ADDR_NSH)
351     {
352       rv = VNET_API_ERROR_INVALID_VALUE;
353       goto out;
354     }
355
356   mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0;
357   name = format (0, "%s", mp->locator_set_name);
358   vec_terminate_c_string (name);
359   p = hash_get_mem (lcm->locator_set_index_by_name, name);
360   if (!p)
361     {
362       rv = VNET_API_ERROR_INVALID_VALUE;
363       goto out;
364     }
365   locator_set_index = p[0];
366
367   if (*mp->key)
368     key = format (0, "%s", mp->key);
369
370   /* XXX treat batch configuration */
371   a->is_add = mp->is_add;
372   gid_address_copy (&a->eid, eid);
373   a->locator_set_index = locator_set_index;
374   a->local = 1;
375   a->key = key;
376   a->key_id = clib_net_to_host_u16 (mp->key_id);
377
378   rv = vnet_lisp_add_del_local_mapping (a, &map_index);
379
380 out:
381   vec_free (name);
382   vec_free (key);
383   gid_address_free (&a->eid);
384
385   REPLY_MACRO (VL_API_ONE_ADD_DEL_LOCAL_EID_REPLY);
386 }
387
388 static void
389   vl_api_one_eid_table_add_del_map_t_handler
390   (vl_api_one_eid_table_add_del_map_t * mp)
391 {
392   vl_api_one_eid_table_add_del_map_reply_t *rmp;
393   int rv = 0;
394   rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
395                                 clib_net_to_host_u32 (mp->dp_table),
396                                 mp->is_l2, mp->is_add);
397 REPLY_MACRO (VL_API_ONE_EID_TABLE_ADD_DEL_MAP_REPLY)}
398
399 static void
400 vl_api_one_add_del_map_server_t_handler (vl_api_one_add_del_map_server_t * mp)
401 {
402   vl_api_one_add_del_map_server_reply_t *rmp;
403   int rv = 0;
404   ip_address_t addr;
405
406   memset (&addr, 0, sizeof (addr));
407
408   ip_address_set (&addr, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
409   rv = vnet_lisp_add_del_map_server (&addr, mp->is_add);
410
411   REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_SERVER_REPLY);
412 }
413
414 static void
415 vl_api_one_add_del_map_resolver_t_handler (vl_api_one_add_del_map_resolver_t
416                                            * mp)
417 {
418   vl_api_one_add_del_map_resolver_reply_t *rmp;
419   int rv = 0;
420   vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
421
422   memset (a, 0, sizeof (a[0]));
423
424   a->is_add = mp->is_add;
425   ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
426
427   rv = vnet_lisp_add_del_map_resolver (a);
428
429   REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_RESOLVER_REPLY);
430 }
431
432 static void
433   vl_api_one_map_register_enable_disable_t_handler
434   (vl_api_one_map_register_enable_disable_t * mp)
435 {
436   vl_api_one_map_register_enable_disable_reply_t *rmp;
437   int rv = 0;
438
439   vnet_lisp_map_register_enable_disable (mp->is_enabled);
440   REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
441 }
442
443 static void
444   vl_api_one_rloc_probe_enable_disable_t_handler
445   (vl_api_one_rloc_probe_enable_disable_t * mp)
446 {
447   vl_api_one_rloc_probe_enable_disable_reply_t *rmp;
448   int rv = 0;
449
450   vnet_lisp_rloc_probe_enable_disable (mp->is_enabled);
451   REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
452 }
453
454 static void
455 vl_api_one_enable_disable_t_handler (vl_api_one_enable_disable_t * mp)
456 {
457   vl_api_one_enable_disable_reply_t *rmp;
458   int rv = 0;
459
460   vnet_lisp_enable_disable (mp->is_en);
461   REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
462 }
463
464 static void
465   vl_api_show_one_map_request_mode_t_handler
466   (vl_api_show_one_map_request_mode_t * mp)
467 {
468   int rv = 0;
469   vl_api_show_one_map_request_mode_reply_t *rmp;
470
471   /* *INDENT-OFF* */
472   REPLY_MACRO2(VL_API_SHOW_ONE_MAP_REQUEST_MODE_REPLY,
473   ({
474     rmp->mode = vnet_lisp_get_map_request_mode ();
475   }));
476   /* *INDENT-ON* */
477 }
478
479 static void
480 vl_api_one_map_request_mode_t_handler (vl_api_one_map_request_mode_t * mp)
481 {
482   vl_api_one_map_request_mode_reply_t *rmp;
483   int rv = 0;
484
485   rv = vnet_lisp_set_map_request_mode (mp->mode);
486
487   REPLY_MACRO (VL_API_ONE_MAP_REQUEST_MODE_REPLY);
488 }
489
490 static void
491 vl_api_one_nsh_set_locator_set_t_handler (vl_api_one_nsh_set_locator_set_t
492                                           * mp)
493 {
494   vl_api_one_nsh_set_locator_set_reply_t *rmp;
495   int rv = 0;
496   u8 *ls_name = 0;
497
498   mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
499   ls_name = format (0, "%s", mp->ls_name);
500   vec_terminate_c_string (ls_name);
501   rv = vnet_lisp_nsh_set_locator_set (ls_name, mp->is_add);
502   vec_free (ls_name);
503
504   REPLY_MACRO (VL_API_ONE_PITR_SET_LOCATOR_SET_REPLY);
505 }
506
507 static void
508 vl_api_one_pitr_set_locator_set_t_handler (vl_api_one_pitr_set_locator_set_t
509                                            * mp)
510 {
511   vl_api_one_pitr_set_locator_set_reply_t *rmp;
512   int rv = 0;
513   u8 *ls_name = 0;
514
515   mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
516   ls_name = format (0, "%s", mp->ls_name);
517   vec_terminate_c_string (ls_name);
518   rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
519   vec_free (ls_name);
520
521   REPLY_MACRO (VL_API_ONE_PITR_SET_LOCATOR_SET_REPLY);
522 }
523
524 static void
525 vl_api_one_use_petr_t_handler (vl_api_one_use_petr_t * mp)
526 {
527   vl_api_one_use_petr_reply_t *rmp;
528   int rv = 0;
529   ip_address_t addr;
530
531   ip_address_set (&addr, &mp->address, mp->is_ip4 ? IP4 : IP6);
532   rv = vnet_lisp_use_petr (&addr, mp->is_add);
533
534   REPLY_MACRO (VL_API_ONE_USE_PETR_REPLY);
535 }
536
537 static void
538 vl_api_show_one_use_petr_t_handler (vl_api_show_one_use_petr_t * mp)
539 {
540   svm_queue_t *q = NULL;
541   vl_api_show_one_use_petr_reply_t *rmp = NULL;
542   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
543   mapping_t *m;
544   locator_set_t *ls = 0;
545   int rv = 0;
546   locator_t *loc = 0;
547   u8 status = 0;
548   gid_address_t addr;
549
550   q = vl_api_client_index_to_input_queue (mp->client_index);
551   if (q == 0)
552     {
553       return;
554     }
555
556   memset (&addr, 0, sizeof (addr));
557   status = lcm->flags & LISP_FLAG_USE_PETR;
558   if (status)
559     {
560       m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index);
561       if (~0 != m->locator_set_index)
562         {
563           ls =
564             pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
565           loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]);
566           gid_address_copy (&addr, &loc->address);
567         }
568     }
569
570   /* *INDENT-OFF* */
571   REPLY_MACRO2 (VL_API_SHOW_ONE_USE_PETR_REPLY,
572   {
573     rmp->status = status;
574     ip_address_t *ip = &gid_address_ip (&addr);
575     switch (ip_addr_version (ip))
576       {
577       case IP4:
578         clib_memcpy (rmp->address, &ip_addr_v4 (ip),
579                      sizeof (ip_addr_v4 (ip)));
580         break;
581
582       case IP6:
583         clib_memcpy (rmp->address, &ip_addr_v6 (ip),
584                      sizeof (ip_addr_v6 (ip)));
585         break;
586
587       default:
588         ASSERT (0);
589       }
590     rmp->is_ip4 = (gid_address_ip_version (&addr) == IP4);
591   });
592   /* *INDENT-ON* */
593 }
594
595 static void
596   vl_api_one_add_del_map_request_itr_rlocs_t_handler
597   (vl_api_one_add_del_map_request_itr_rlocs_t * mp)
598 {
599   vl_api_one_add_del_map_request_itr_rlocs_reply_t *rmp;
600   int rv = 0;
601   u8 *locator_set_name = NULL;
602   vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
603
604   mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0;
605   locator_set_name = format (0, "%s", mp->locator_set_name);
606   vec_terminate_c_string (locator_set_name);
607
608   a->is_add = mp->is_add;
609   a->locator_set_name = locator_set_name;
610
611   rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
612
613   vec_free (locator_set_name);
614
615   REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
616 }
617
618 static void
619   vl_api_one_add_del_remote_mapping_t_handler
620   (vl_api_one_add_del_remote_mapping_t * mp)
621 {
622   locator_t *rlocs = 0;
623   vl_api_one_add_del_remote_mapping_reply_t *rmp;
624   int rv = 0;
625   gid_address_t _eid, *eid = &_eid;
626   u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
627
628   memset (eid, 0, sizeof (eid[0]));
629
630   rv = unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
631                              mp->eid_type, mp->eid, mp->eid_len);
632   if (rv)
633     goto send_reply;
634
635   rlocs = unformat_one_locs (mp->rlocs, rloc_num);
636
637   if (!mp->is_add)
638     {
639       vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
640       memset (a, 0, sizeof (a[0]));
641       gid_address_copy (&a->reid, eid);
642       a->is_add = 0;
643       rv = vnet_lisp_add_del_adjacency (a);
644       if (rv)
645         {
646           goto out;
647         }
648     }
649
650   /* NOTE: for now this works as a static remote mapping, i.e.,
651    * not authoritative and ttl infinite. */
652   if (mp->is_add)
653     {
654       vnet_lisp_add_del_mapping_args_t _m_args, *m_args = &_m_args;
655       memset (m_args, 0, sizeof (m_args[0]));
656       gid_address_copy (&m_args->eid, eid);
657       m_args->action = mp->action;
658       m_args->is_static = 1;
659       m_args->ttl = ~0;
660       m_args->authoritative = 0;
661       rv = vnet_lisp_add_mapping (m_args, rlocs, NULL, NULL);
662     }
663   else
664     rv = vnet_lisp_del_mapping (eid, NULL);
665
666   if (mp->del_all)
667     vnet_lisp_clear_all_remote_adjacencies ();
668
669 out:
670   vec_free (rlocs);
671 send_reply:
672   REPLY_MACRO (VL_API_ONE_ADD_DEL_REMOTE_MAPPING_REPLY);
673 }
674
675 static void
676 vl_api_one_add_del_adjacency_t_handler (vl_api_one_add_del_adjacency_t * mp)
677 {
678   vl_api_one_add_del_adjacency_reply_t *rmp;
679   vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
680
681   int rv = 0;
682   memset (a, 0, sizeof (a[0]));
683
684   rv = unformat_one_eid_api (&a->leid, clib_net_to_host_u32 (mp->vni),
685                              mp->eid_type, mp->leid, mp->leid_len);
686   rv |= unformat_one_eid_api (&a->reid, clib_net_to_host_u32 (mp->vni),
687                               mp->eid_type, mp->reid, mp->reid_len);
688
689   if (rv)
690     goto send_reply;
691
692   a->is_add = mp->is_add;
693   rv = vnet_lisp_add_del_adjacency (a);
694
695 send_reply:
696   REPLY_MACRO (VL_API_ONE_ADD_DEL_ADJACENCY_REPLY);
697 }
698
699 static void
700 send_one_locator_details (lisp_cp_main_t * lcm,
701                           locator_t * loc, svm_queue_t * q, u32 context)
702 {
703   vl_api_one_locator_details_t *rmp;
704
705   rmp = vl_msg_api_alloc (sizeof (*rmp));
706   memset (rmp, 0, sizeof (*rmp));
707   rmp->_vl_msg_id = ntohs (VL_API_ONE_LOCATOR_DETAILS);
708   rmp->context = context;
709
710   rmp->local = loc->local;
711   if (loc->local)
712     {
713       rmp->sw_if_index = ntohl (loc->sw_if_index);
714     }
715   else
716     {
717       rmp->is_ipv6 = gid_address_ip_version (&loc->address);
718       ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
719     }
720   rmp->priority = loc->priority;
721   rmp->weight = loc->weight;
722
723   vl_msg_api_send_shmem (q, (u8 *) & rmp);
724 }
725
726 static void
727 vl_api_one_locator_dump_t_handler (vl_api_one_locator_dump_t * mp)
728 {
729   u8 *ls_name = 0;
730   svm_queue_t *q = 0;
731   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
732   locator_set_t *lsit = 0;
733   locator_t *loc = 0;
734   u32 ls_index = ~0, *locit = 0;
735   uword *p = 0;
736
737   q = vl_api_client_index_to_input_queue (mp->client_index);
738   if (q == 0)
739     {
740       return;
741     }
742
743   if (mp->is_index_set)
744     ls_index = htonl (mp->ls_index);
745   else
746     {
747       /* make sure we get a proper C-string */
748       mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
749       ls_name = format (0, "%s", mp->ls_name);
750       vec_terminate_c_string (ls_name);
751       p = hash_get_mem (lcm->locator_set_index_by_name, ls_name);
752       if (!p)
753         goto out;
754       ls_index = p[0];
755     }
756
757   if (pool_is_free_index (lcm->locator_set_pool, ls_index))
758     return;
759
760   lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
761
762   vec_foreach (locit, lsit->locator_indices)
763   {
764     loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
765     send_one_locator_details (lcm, loc, q, mp->context);
766   };
767 out:
768   vec_free (ls_name);
769 }
770
771 static void
772 send_one_locator_set_details (lisp_cp_main_t * lcm,
773                               locator_set_t * lsit,
774                               svm_queue_t * q, u32 context, u32 ls_index)
775 {
776   vl_api_one_locator_set_details_t *rmp;
777   u8 *str = 0;
778
779   rmp = vl_msg_api_alloc (sizeof (*rmp));
780   memset (rmp, 0, sizeof (*rmp));
781   rmp->_vl_msg_id = ntohs (VL_API_ONE_LOCATOR_SET_DETAILS);
782   rmp->context = context;
783
784   rmp->ls_index = htonl (ls_index);
785   if (lsit->local)
786     {
787       ASSERT (lsit->name != NULL);
788       strncpy ((char *) rmp->ls_name, (char *) lsit->name,
789                vec_len (lsit->name));
790     }
791   else
792     {
793       str = format (0, "<remote-%d>", ls_index);
794       strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str));
795       vec_free (str);
796     }
797
798   vl_msg_api_send_shmem (q, (u8 *) & rmp);
799 }
800
801 static void
802 vl_api_one_locator_set_dump_t_handler (vl_api_one_locator_set_dump_t * mp)
803 {
804   svm_queue_t *q = NULL;
805   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
806   locator_set_t *lsit = NULL;
807   u8 filter;
808
809   q = vl_api_client_index_to_input_queue (mp->client_index);
810   if (q == 0)
811     {
812       return;
813     }
814
815   filter = mp->filter;
816   /* *INDENT-OFF* */
817   pool_foreach (lsit, lcm->locator_set_pool,
818   ({
819     if (filter && !((1 == filter && lsit->local) ||
820                     (2 == filter && !lsit->local)))
821       {
822         continue;
823       }
824     send_one_locator_set_details (lcm, lsit, q, mp->context,
825                                    lsit - lcm->locator_set_pool);
826   }));
827   /* *INDENT-ON* */
828 }
829
830 static void
831 one_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length)
832 {
833   ASSERT (prefix_length);
834   ip_prefix_t *ippref = &fid_addr_ippref (src);
835
836   switch (fid_addr_type (src))
837     {
838     case FID_ADDR_IP_PREF:
839       if (ip_prefix_version (ippref) == IP4)
840         clib_memcpy (dst, &ip_prefix_v4 (ippref), 4);
841       else
842         clib_memcpy (dst, &ip_prefix_v6 (ippref), 16);
843       prefix_length[0] = ip_prefix_len (ippref);
844       break;
845
846     case FID_ADDR_MAC:
847       prefix_length[0] = 0;
848       clib_memcpy (dst, fid_addr_mac (src), 6);
849       break;
850
851     default:
852       clib_warning ("Unknown FID type %d!", fid_addr_type (src));
853       break;
854     }
855 }
856
857 static u8
858 fid_type_to_api_type (fid_address_t * fid)
859 {
860   ip_prefix_t *ippref;
861
862   switch (fid_addr_type (fid))
863     {
864     case FID_ADDR_IP_PREF:
865       ippref = &fid_addr_ippref (fid);
866       if (ip_prefix_version (ippref) == IP4)
867         return 0;
868       else if (ip_prefix_version (ippref) == IP6)
869         return 1;
870       else
871         return ~0;
872
873     case FID_ADDR_MAC:
874       return 2;
875     case FID_ADDR_NSH:
876       return 3;
877     }
878
879   return ~0;
880 }
881
882 static void
883 send_one_eid_table_details (mapping_t * mapit,
884                             svm_queue_t * q, u32 context, u8 filter)
885 {
886   fid_address_t *fid;
887   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
888   locator_set_t *ls = 0;
889   vl_api_one_eid_table_details_t *rmp = NULL;
890   gid_address_t *gid = NULL;
891   u8 *mac = 0;
892   ip_prefix_t *ip_prefix = NULL;
893
894   if (mapit->pitr_set || mapit->nsh_set)
895     return;
896
897   switch (filter)
898     {
899     case 0:                     /* all mappings */
900       break;
901
902     case 1:                     /* local only */
903       if (!mapit->local)
904         return;
905       break;
906     case 2:                     /* remote only */
907       if (mapit->local)
908         return;
909       break;
910     default:
911       clib_warning ("Filter error, unknown filter: %d", filter);
912       return;
913     }
914
915   gid = &mapit->eid;
916   ip_prefix = &gid_address_ippref (gid);
917   mac = gid_address_mac (gid);
918
919   rmp = vl_msg_api_alloc (sizeof (*rmp));
920   memset (rmp, 0, sizeof (*rmp));
921   rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_DETAILS);
922
923   ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
924   if (vec_len (ls->locator_indices) == 0)
925     rmp->locator_set_index = ~0;
926   else
927     rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
928
929   rmp->is_local = mapit->local;
930   rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
931   rmp->action = mapit->action;
932   rmp->authoritative = mapit->authoritative;
933
934   switch (gid_address_type (gid))
935     {
936     case GID_ADDR_SRC_DST:
937       rmp->is_src_dst = 1;
938       fid = &gid_address_sd_src (gid);
939       rmp->eid_type = fid_type_to_api_type (fid);
940       one_fid_put_api (rmp->seid, &gid_address_sd_src (gid),
941                        &rmp->seid_prefix_len);
942       one_fid_put_api (rmp->eid, &gid_address_sd_dst (gid),
943                        &rmp->eid_prefix_len);
944       break;
945     case GID_ADDR_IP_PREFIX:
946       rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
947       if (ip_prefix_version (ip_prefix) == IP4)
948         {
949           rmp->eid_type = 0;    /* ipv4 type */
950           clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
951                        sizeof (ip_prefix_v4 (ip_prefix)));
952         }
953       else
954         {
955           rmp->eid_type = 1;    /* ipv6 type */
956           clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
957                        sizeof (ip_prefix_v6 (ip_prefix)));
958         }
959       break;
960     case GID_ADDR_MAC:
961       rmp->eid_type = 2;        /* l2 mac type */
962       clib_memcpy (rmp->eid, mac, 6);
963       break;
964     case GID_ADDR_NSH:
965       rmp->eid_type = 3;        /* NSH type */
966       lisp_nsh_api_t nsh;
967       nsh.spi = clib_host_to_net_u32 (gid_address_nsh_spi (gid));
968       nsh.si = gid_address_nsh_si (gid);
969       clib_memcpy (rmp->eid, &nsh, sizeof (nsh));
970       break;
971     default:
972       ASSERT (0);
973     }
974   rmp->context = context;
975   rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
976   rmp->key_id = clib_host_to_net_u16 (mapit->key_id);
977   memcpy (rmp->key, mapit->key, vec_len (mapit->key));
978   vl_msg_api_send_shmem (q, (u8 *) & rmp);
979 }
980
981 static void
982 vl_api_one_eid_table_dump_t_handler (vl_api_one_eid_table_dump_t * mp)
983 {
984   u32 mi;
985   svm_queue_t *q = NULL;
986   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
987   mapping_t *mapit = NULL;
988   gid_address_t _eid, *eid = &_eid;
989
990   q = vl_api_client_index_to_input_queue (mp->client_index);
991   if (q == 0)
992     {
993       return;
994     }
995
996   if (mp->eid_set)
997     {
998       memset (eid, 0, sizeof (*eid));
999
1000       unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
1001                             mp->eid_type, mp->eid, mp->prefix_length);
1002
1003       mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
1004       if ((u32) ~ 0 == mi)
1005         return;
1006
1007       mapit = pool_elt_at_index (lcm->mapping_pool, mi);
1008       send_one_eid_table_details (mapit, q, mp->context,
1009                                   0 /* ignore filter */ );
1010     }
1011   else
1012     {
1013       /* *INDENT-OFF* */
1014       pool_foreach (mapit, lcm->mapping_pool,
1015       ({
1016         send_one_eid_table_details(mapit, q, mp->context,
1017                                     mp->filter);
1018       }));
1019       /* *INDENT-ON* */
1020     }
1021 }
1022
1023 static void
1024 send_one_map_server_details (ip_address_t * ip, svm_queue_t * q, u32 context)
1025 {
1026   vl_api_one_map_server_details_t *rmp = NULL;
1027
1028   rmp = vl_msg_api_alloc (sizeof (*rmp));
1029   memset (rmp, 0, sizeof (*rmp));
1030   rmp->_vl_msg_id = ntohs (VL_API_ONE_MAP_SERVER_DETAILS);
1031
1032   switch (ip_addr_version (ip))
1033     {
1034     case IP4:
1035       rmp->is_ipv6 = 0;
1036       clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
1037                    sizeof (ip_addr_v4 (ip)));
1038       break;
1039
1040     case IP6:
1041       rmp->is_ipv6 = 1;
1042       clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
1043                    sizeof (ip_addr_v6 (ip)));
1044       break;
1045
1046     default:
1047       ASSERT (0);
1048     }
1049   rmp->context = context;
1050
1051   vl_msg_api_send_shmem (q, (u8 *) & rmp);
1052 }
1053
1054 static void
1055 vl_api_one_map_server_dump_t_handler (vl_api_one_map_server_dump_t * mp)
1056 {
1057   svm_queue_t *q = NULL;
1058   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1059   lisp_msmr_t *mr;
1060
1061   q = vl_api_client_index_to_input_queue (mp->client_index);
1062   if (q == 0)
1063     {
1064       return;
1065     }
1066
1067   vec_foreach (mr, lcm->map_servers)
1068   {
1069     send_one_map_server_details (&mr->address, q, mp->context);
1070   }
1071 }
1072
1073 static void
1074 send_one_map_resolver_details (ip_address_t * ip,
1075                                svm_queue_t * q, u32 context)
1076 {
1077   vl_api_one_map_resolver_details_t *rmp = NULL;
1078
1079   rmp = vl_msg_api_alloc (sizeof (*rmp));
1080   memset (rmp, 0, sizeof (*rmp));
1081   rmp->_vl_msg_id = ntohs (VL_API_ONE_MAP_RESOLVER_DETAILS);
1082
1083   switch (ip_addr_version (ip))
1084     {
1085     case IP4:
1086       rmp->is_ipv6 = 0;
1087       clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
1088                    sizeof (ip_addr_v4 (ip)));
1089       break;
1090
1091     case IP6:
1092       rmp->is_ipv6 = 1;
1093       clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
1094                    sizeof (ip_addr_v6 (ip)));
1095       break;
1096
1097     default:
1098       ASSERT (0);
1099     }
1100   rmp->context = context;
1101
1102   vl_msg_api_send_shmem (q, (u8 *) & rmp);
1103 }
1104
1105 static void
1106 vl_api_one_map_resolver_dump_t_handler (vl_api_one_map_resolver_dump_t * mp)
1107 {
1108   svm_queue_t *q = NULL;
1109   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1110   lisp_msmr_t *mr;
1111
1112   q = vl_api_client_index_to_input_queue (mp->client_index);
1113   if (q == 0)
1114     {
1115       return;
1116     }
1117
1118   vec_foreach (mr, lcm->map_resolvers)
1119   {
1120     send_one_map_resolver_details (&mr->address, q, mp->context);
1121   }
1122 }
1123
1124 static void
1125 send_eid_table_map_pair (hash_pair_t * p, svm_queue_t * q, u32 context)
1126 {
1127   vl_api_one_eid_table_map_details_t *rmp = NULL;
1128
1129   rmp = vl_msg_api_alloc (sizeof (*rmp));
1130   memset (rmp, 0, sizeof (*rmp));
1131   rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_MAP_DETAILS);
1132
1133   rmp->vni = clib_host_to_net_u32 (p->key);
1134   rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
1135   rmp->context = context;
1136   vl_msg_api_send_shmem (q, (u8 *) & rmp);
1137 }
1138
1139 static void
1140 vl_api_one_eid_table_map_dump_t_handler (vl_api_one_eid_table_map_dump_t * mp)
1141 {
1142   svm_queue_t *q = NULL;
1143   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1144   hash_pair_t *p;
1145   uword *vni_table = 0;
1146
1147   q = vl_api_client_index_to_input_queue (mp->client_index);
1148   if (q == 0)
1149     {
1150       return;
1151     }
1152
1153   if (mp->is_l2)
1154     {
1155       vni_table = lcm->bd_id_by_vni;
1156     }
1157   else
1158     {
1159       vni_table = lcm->table_id_by_vni;
1160     }
1161
1162   /* *INDENT-OFF* */
1163   hash_foreach_pair (p, vni_table,
1164   ({
1165     send_eid_table_map_pair (p, q, mp->context);
1166   }));
1167   /* *INDENT-ON* */
1168 }
1169
1170 static void
1171 send_eid_table_vni (u32 vni, svm_queue_t * q, u32 context)
1172 {
1173   vl_api_one_eid_table_vni_details_t *rmp = 0;
1174
1175   rmp = vl_msg_api_alloc (sizeof (*rmp));
1176   memset (rmp, 0, sizeof (*rmp));
1177   rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_VNI_DETAILS);
1178   rmp->context = context;
1179   rmp->vni = clib_host_to_net_u32 (vni);
1180   vl_msg_api_send_shmem (q, (u8 *) & rmp);
1181 }
1182
1183 static void
1184 one_adjacency_copy (vl_api_one_adjacency_t * dst, lisp_adjacency_t * adjs)
1185 {
1186   lisp_adjacency_t *adj;
1187   vl_api_one_adjacency_t a;
1188   u32 i, n = vec_len (adjs);
1189   lisp_nsh_api_t nsh;
1190
1191   for (i = 0; i < n; i++)
1192     {
1193       adj = vec_elt_at_index (adjs, i);
1194       memset (&a, 0, sizeof (a));
1195
1196       switch (gid_address_type (&adj->reid))
1197         {
1198         case GID_ADDR_IP_PREFIX:
1199           a.reid_prefix_len = gid_address_ippref_len (&adj->reid);
1200           a.leid_prefix_len = gid_address_ippref_len (&adj->leid);
1201           if (gid_address_ip_version (&adj->reid) == IP4)
1202             {
1203               a.eid_type = 0;   /* ipv4 type */
1204               clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 4);
1205               clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 4);
1206             }
1207           else
1208             {
1209               a.eid_type = 1;   /* ipv6 type */
1210               clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 16);
1211               clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 16);
1212             }
1213           break;
1214         case GID_ADDR_MAC:
1215           a.eid_type = 2;       /* l2 mac type */
1216           mac_copy (a.reid, gid_address_mac (&adj->reid));
1217           mac_copy (a.leid, gid_address_mac (&adj->leid));
1218           break;
1219         case GID_ADDR_NSH:
1220           a.eid_type = 3;       /* NSH type */
1221           nsh.spi = clib_host_to_net_u32 (gid_address_nsh_spi (&adj->reid));
1222           nsh.si = gid_address_nsh_si (&adj->reid);
1223           clib_memcpy (a.reid, &nsh, sizeof (nsh));
1224
1225           nsh.spi = clib_host_to_net_u32 (gid_address_nsh_spi (&adj->leid));
1226           nsh.si = gid_address_nsh_si (&adj->leid);
1227           clib_memcpy (a.leid, &nsh, sizeof (nsh));
1228           break;
1229         default:
1230           ASSERT (0);
1231         }
1232       dst[i] = a;
1233     }
1234 }
1235
1236 static void
1237   vl_api_show_one_rloc_probe_state_t_handler
1238   (vl_api_show_one_rloc_probe_state_t * mp)
1239 {
1240   vl_api_show_one_rloc_probe_state_reply_t *rmp = 0;
1241   int rv = 0;
1242
1243   /* *INDENT-OFF* */
1244   REPLY_MACRO2 (VL_API_SHOW_ONE_RLOC_PROBE_STATE_REPLY,
1245   {
1246     rmp->is_enabled = vnet_lisp_rloc_probe_state_get ();
1247   });
1248   /* *INDENT-ON* */
1249 }
1250
1251 static void
1252   vl_api_show_one_map_register_state_t_handler
1253   (vl_api_show_one_map_register_state_t * mp)
1254 {
1255   vl_api_show_one_map_register_state_reply_t *rmp = 0;
1256   int rv = 0;
1257
1258   /* *INDENT-OFF* */
1259   REPLY_MACRO2 (VL_API_SHOW_ONE_MAP_REGISTER_STATE_REPLY,
1260   {
1261     rmp->is_enabled = vnet_lisp_map_register_state_get ();
1262   });
1263   /* *INDENT-ON* */
1264 }
1265
1266 static void
1267 vl_api_one_adjacencies_get_t_handler (vl_api_one_adjacencies_get_t * mp)
1268 {
1269   vl_api_one_adjacencies_get_reply_t *rmp = 0;
1270   lisp_adjacency_t *adjs = 0;
1271   int rv = 0;
1272   u32 size = ~0;
1273   u32 vni = clib_net_to_host_u32 (mp->vni);
1274
1275   adjs = vnet_lisp_adjacencies_get_by_vni (vni);
1276   size = vec_len (adjs) * sizeof (vl_api_one_adjacency_t);
1277
1278   /* *INDENT-OFF* */
1279   REPLY_MACRO4 (VL_API_ONE_ADJACENCIES_GET_REPLY, size,
1280   {
1281     rmp->count = clib_host_to_net_u32 (vec_len (adjs));
1282     one_adjacency_copy (rmp->adjacencies, adjs);
1283   });
1284   /* *INDENT-ON* */
1285
1286   vec_free (adjs);
1287 }
1288
1289 static void
1290 vl_api_one_eid_table_vni_dump_t_handler (vl_api_one_eid_table_vni_dump_t * mp)
1291 {
1292   hash_pair_t *p;
1293   u32 *vnis = 0;
1294   svm_queue_t *q = 0;
1295   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1296
1297   q = vl_api_client_index_to_input_queue (mp->client_index);
1298   if (q == 0)
1299     {
1300       return;
1301     }
1302
1303   /* *INDENT-OFF* */
1304   hash_foreach_pair (p, lcm->table_id_by_vni,
1305   ({
1306     hash_set (vnis, p->key, 0);
1307   }));
1308
1309   hash_foreach_pair (p, lcm->bd_id_by_vni,
1310   ({
1311     hash_set (vnis, p->key, 0);
1312   }));
1313
1314   hash_foreach_pair (p, vnis,
1315   ({
1316     send_eid_table_vni (p->key, q, mp->context);
1317   }));
1318   /* *INDENT-ON* */
1319
1320   hash_free (vnis);
1321 }
1322
1323 static void
1324 vl_api_show_one_status_t_handler (vl_api_show_one_status_t * mp)
1325 {
1326   vl_api_show_one_status_reply_t *rmp = NULL;
1327   int rv = 0;
1328
1329   /* *INDENT-OFF* */
1330   REPLY_MACRO2(VL_API_SHOW_ONE_STATUS_REPLY,
1331   ({
1332     rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
1333     rmp->feature_status = vnet_lisp_enable_disable_status ();
1334   }));
1335   /* *INDENT-ON* */
1336 }
1337
1338 static void
1339   vl_api_one_get_map_request_itr_rlocs_t_handler
1340   (vl_api_one_get_map_request_itr_rlocs_t * mp)
1341 {
1342   vl_api_one_get_map_request_itr_rlocs_reply_t *rmp = NULL;
1343   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1344   locator_set_t *loc_set = 0;
1345   u8 *tmp_str = 0;
1346   int rv = 0;
1347
1348   if (~0 == lcm->mreq_itr_rlocs)
1349     {
1350       tmp_str = format (0, " ");
1351     }
1352   else
1353     {
1354       loc_set =
1355         pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
1356       tmp_str = format (0, "%s", loc_set->name);
1357     }
1358
1359   /* *INDENT-OFF* */
1360   REPLY_MACRO2(VL_API_ONE_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
1361   ({
1362     strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1363             ARRAY_LEN(rmp->locator_set_name) - 1);
1364   }));
1365   /* *INDENT-ON* */
1366
1367   vec_free (tmp_str);
1368 }
1369
1370 static void
1371 vl_api_show_one_nsh_mapping_t_handler (vl_api_show_one_nsh_mapping_t * mp)
1372 {
1373   svm_queue_t *q = NULL;
1374   vl_api_show_one_nsh_mapping_reply_t *rmp = NULL;
1375   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1376   mapping_t *m;
1377   locator_set_t *ls = 0;
1378   u8 *tmp_str = 0;
1379   u8 is_set = 0;
1380   int rv = 0;
1381
1382   q = vl_api_client_index_to_input_queue (mp->client_index);
1383   if (q == 0)
1384     {
1385       return;
1386     }
1387
1388   if (lcm->nsh_map_index == (u32) ~ 0)
1389     {
1390       tmp_str = format (0, "N/A");
1391     }
1392   else
1393     {
1394       m = pool_elt_at_index (lcm->mapping_pool, lcm->nsh_map_index);
1395       if (~0 != m->locator_set_index)
1396         {
1397           ls =
1398             pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
1399           tmp_str = format (0, "%s", ls->name);
1400           is_set = 1;
1401         }
1402       else
1403         {
1404           tmp_str = format (0, "N/A");
1405         }
1406     }
1407   vec_add1 (tmp_str, 0);
1408
1409   /* *INDENT-OFF* */
1410   REPLY_MACRO2(VL_API_SHOW_ONE_NSH_MAPPING_REPLY,
1411   ({
1412     rmp->is_set = is_set;
1413     strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1414             ARRAY_LEN(rmp->locator_set_name) - 1);
1415   }));
1416   /* *INDENT-ON* */
1417 }
1418
1419 static void
1420 vl_api_show_one_pitr_t_handler (vl_api_show_one_pitr_t * mp)
1421 {
1422   svm_queue_t *q = NULL;
1423   vl_api_show_one_pitr_reply_t *rmp = NULL;
1424   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1425   mapping_t *m;
1426   locator_set_t *ls = 0;
1427   u8 *tmp_str = 0;
1428   int rv = 0;
1429
1430   q = vl_api_client_index_to_input_queue (mp->client_index);
1431   if (q == 0)
1432     {
1433       return;
1434     }
1435
1436   u8 is_enabled = (lcm->flags & LISP_FLAG_PITR_MODE)
1437     && lcm->pitr_map_index != ~0;
1438
1439   if (!is_enabled)
1440     {
1441       tmp_str = format (0, "N/A");
1442     }
1443   else
1444     {
1445       m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
1446       if (~0 != m->locator_set_index)
1447         {
1448           ls =
1449             pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
1450           tmp_str = format (0, "%s", ls->name);
1451         }
1452       else
1453         {
1454           tmp_str = format (0, "N/A");
1455         }
1456     }
1457   vec_add1 (tmp_str, 0);
1458
1459   /* *INDENT-OFF* */
1460   REPLY_MACRO2(VL_API_SHOW_ONE_PITR_REPLY,
1461   ({
1462     rmp->status = lcm->flags & LISP_FLAG_PITR_MODE;
1463     strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1464             ARRAY_LEN(rmp->locator_set_name) - 1);
1465   }));
1466   /* *INDENT-ON* */
1467 }
1468
1469 static void
1470   vl_api_show_one_stats_enable_disable_t_handler
1471   (vl_api_show_one_stats_enable_disable_t * mp)
1472 {
1473   vl_api_show_one_stats_enable_disable_reply_t *rmp = NULL;
1474   vnet_api_error_t rv = 0;
1475
1476   /* *INDENT-OFF* */
1477   REPLY_MACRO2 (VL_API_SHOW_ONE_STATS_ENABLE_DISABLE_REPLY,
1478   ({
1479     rmp->is_en = vnet_lisp_stats_enable_disable_state ();
1480   }));
1481   /* *INDENT-ON* */
1482 }
1483
1484 static void
1485   vl_api_one_stats_enable_disable_t_handler
1486   (vl_api_one_stats_enable_disable_t * mp)
1487 {
1488   vl_api_one_enable_disable_reply_t *rmp = NULL;
1489
1490   vnet_api_error_t rv = vnet_lisp_stats_enable_disable (mp->is_en);
1491   REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
1492 }
1493
1494 static void
1495 lisp_fid_addr_to_api (fid_address_t * fid, u8 * dst, u8 * api_eid_type,
1496                       u8 * prefix_length)
1497 {
1498   switch (fid_addr_type (fid))
1499     {
1500     case FID_ADDR_IP_PREF:
1501       *prefix_length = fid_addr_prefix_length (fid);
1502       if (fid_addr_ip_version (fid) == IP4)
1503         {
1504           *api_eid_type = 0;    /* ipv4 type */
1505           clib_memcpy (dst, &fid_addr_ippref (fid), 4);
1506         }
1507       else
1508         {
1509           *api_eid_type = 1;    /* ipv6 type */
1510           clib_memcpy (dst, &fid_addr_ippref (fid), 16);
1511         }
1512       break;
1513     case FID_ADDR_MAC:
1514       *api_eid_type = 2;        /* l2 mac type */
1515       mac_copy (dst, fid_addr_mac (fid));
1516       break;
1517     default:
1518       ASSERT (0);
1519     }
1520 }
1521
1522 static void
1523 vl_api_one_stats_flush_t_handler (vl_api_one_stats_flush_t * mp)
1524 {
1525   vl_api_one_stats_flush_reply_t *rmp;
1526   u8 rv;
1527
1528   rv = vnet_lisp_flush_stats ();
1529   REPLY_MACRO (VL_API_ONE_STATS_FLUSH_REPLY);
1530 }
1531
1532 static void
1533 vl_api_one_stats_dump_t_handler (vl_api_one_stats_dump_t * mp)
1534 {
1535   vl_api_one_stats_details_t *rmp;
1536   lisp_api_stats_t *stats, *stat;
1537   u8 rv = 0;
1538
1539   stats = vnet_lisp_get_stats ();
1540   vec_foreach (stat, stats)
1541   {
1542       /* *INDENT-OFF* */
1543       REPLY_DETAILS (VL_API_ONE_STATS_DETAILS,
1544       ({
1545         lisp_fid_addr_to_api (&stat->deid, rmp->deid, &rmp->eid_type,
1546                               &rmp->deid_pref_len);
1547         lisp_fid_addr_to_api (&stat->seid, rmp->seid, &rmp->eid_type,
1548                               &rmp->seid_pref_len);
1549         rmp->vni = clib_host_to_net_u32 (stat->vni);
1550
1551         rmp->is_ip4 = ip_addr_version (&stat->rmt_rloc) == IP4 ? 1 : 0;
1552         ip_address_copy_addr (rmp->rloc, &stat->rmt_rloc);
1553         ip_address_copy_addr (rmp->lloc, &stat->loc_rloc);
1554
1555         rmp->pkt_count = clib_host_to_net_u32 (stat->counters.packets);
1556         rmp->bytes = clib_host_to_net_u32 (stat->counters.bytes);
1557       }));
1558       /* *INDENT-ON* */
1559   }
1560 }
1561
1562 static void
1563   vl_api_one_add_del_l2_arp_entry_t_handler
1564   (vl_api_one_add_del_l2_arp_entry_t * mp)
1565 {
1566   vl_api_one_add_del_l2_arp_entry_reply_t *rmp;
1567   int rv = 0;
1568   gid_address_t _arp, *arp = &_arp;
1569   memset (arp, 0, sizeof (*arp));
1570
1571   gid_address_type (arp) = GID_ADDR_ARP;
1572   gid_address_arp_bd (arp) = clib_net_to_host_u32 (mp->bd);
1573
1574   /* vpp keeps ip4 addresses in network byte order */
1575   ip_address_set (&gid_address_arp_ndp_ip (arp), &mp->ip4, IP4);
1576
1577   rv = vnet_lisp_add_del_l2_arp_ndp_entry (arp, mp->mac, mp->is_add);
1578
1579   REPLY_MACRO (VL_API_ONE_ADD_DEL_L2_ARP_ENTRY_REPLY);
1580 }
1581
1582 static void
1583 vl_api_one_add_del_ndp_entry_t_handler (vl_api_one_add_del_ndp_entry_t * mp)
1584 {
1585   vl_api_one_add_del_ndp_entry_reply_t *rmp;
1586   int rv = 0;
1587   gid_address_t _g, *g = &_g;
1588   memset (g, 0, sizeof (*g));
1589
1590   gid_address_type (g) = GID_ADDR_NDP;
1591   gid_address_ndp_bd (g) = clib_net_to_host_u32 (mp->bd);
1592   ip_address_set (&gid_address_arp_ndp_ip (g), mp->ip6, IP6);
1593
1594   rv = vnet_lisp_add_del_l2_arp_ndp_entry (g, mp->mac, mp->is_add);
1595
1596   REPLY_MACRO (VL_API_ONE_ADD_DEL_NDP_ENTRY_REPLY);
1597 }
1598
1599 static void
1600 vl_api_one_ndp_bd_get_t_handler (vl_api_one_ndp_bd_get_t * mp)
1601 {
1602   vl_api_one_ndp_bd_get_reply_t *rmp;
1603   int rv = 0;
1604   u32 i = 0;
1605   hash_pair_t *p;
1606
1607   u32 *bds = vnet_lisp_ndp_bds_get ();
1608   u32 size = hash_elts (bds) * sizeof (u32);
1609
1610   /* *INDENT-OFF* */
1611   REPLY_MACRO4 (VL_API_ONE_NDP_BD_GET_REPLY, size,
1612   {
1613     rmp->count = clib_host_to_net_u32 (hash_elts (bds));
1614     hash_foreach_pair (p, bds,
1615     ({
1616       rmp->bridge_domains[i++] = clib_host_to_net_u32 (p->key);
1617     }));
1618   });
1619   /* *INDENT-ON* */
1620
1621   hash_free (bds);
1622 }
1623
1624 static void
1625 vl_api_one_l2_arp_bd_get_t_handler (vl_api_one_l2_arp_bd_get_t * mp)
1626 {
1627   vl_api_one_l2_arp_bd_get_reply_t *rmp;
1628   int rv = 0;
1629   u32 i = 0;
1630   hash_pair_t *p;
1631
1632   u32 *bds = vnet_lisp_l2_arp_bds_get ();
1633   u32 size = hash_elts (bds) * sizeof (u32);
1634
1635   /* *INDENT-OFF* */
1636   REPLY_MACRO4 (VL_API_ONE_L2_ARP_BD_GET_REPLY, size,
1637   {
1638     rmp->count = clib_host_to_net_u32 (hash_elts (bds));
1639     hash_foreach_pair (p, bds,
1640     ({
1641       rmp->bridge_domains[i++] = clib_host_to_net_u32 (p->key);
1642     }));
1643   });
1644   /* *INDENT-ON* */
1645
1646   hash_free (bds);
1647 }
1648
1649 static void
1650 vl_api_one_l2_arp_entries_get_t_handler (vl_api_one_l2_arp_entries_get_t * mp)
1651 {
1652   vl_api_one_l2_arp_entries_get_reply_t *rmp;
1653   lisp_api_l2_arp_entry_t *entries = 0, *e;
1654   u32 i = 0;
1655   int rv = 0;
1656
1657   u32 bd = clib_net_to_host_u32 (mp->bd);
1658
1659   entries = vnet_lisp_l2_arp_entries_get_by_bd (bd);
1660   u32 size = vec_len (entries) * sizeof (vl_api_one_l2_arp_entry_t);
1661
1662   /* *INDENT-OFF* */
1663   REPLY_MACRO4 (VL_API_ONE_L2_ARP_ENTRIES_GET_REPLY, size,
1664   {
1665     rmp->count = clib_host_to_net_u32 (vec_len (entries));
1666     vec_foreach (e, entries)
1667       {
1668         mac_copy (rmp->entries[i].mac, e->mac);
1669         rmp->entries[i].ip4 = e->ip4;
1670         i++;
1671       }
1672   });
1673   /* *INDENT-ON* */
1674
1675   vec_free (entries);
1676 }
1677
1678 static void
1679   vl_api_one_map_register_fallback_threshold_t_handler
1680   (vl_api_one_map_register_fallback_threshold_t * mp)
1681 {
1682   vl_api_one_map_register_fallback_threshold_reply_t *rmp;
1683   int rv = 0;
1684
1685   mp->value = clib_net_to_host_u32 (mp->value);
1686   rv = vnet_lisp_map_register_fallback_threshold_set (mp->value);
1687   REPLY_MACRO (VL_API_ONE_MAP_REGISTER_FALLBACK_THRESHOLD_REPLY);
1688 }
1689
1690 static void
1691   vl_api_show_one_map_register_fallback_threshold_t_handler
1692   (vl_api_show_one_map_register_fallback_threshold_t * mp)
1693 {
1694   vl_api_show_one_map_register_fallback_threshold_reply_t *rmp;
1695   int rv = 0;
1696
1697   u32 value = vnet_lisp_map_register_fallback_threshold_get ();
1698
1699   /* *INDENT-OFF* */
1700   REPLY_MACRO2 (VL_API_SHOW_ONE_MAP_REGISTER_FALLBACK_THRESHOLD_REPLY,
1701   ({
1702     rmp->value = clib_host_to_net_u32 (value);
1703   }));
1704   /* *INDENT-ON* */
1705 }
1706
1707 static void
1708   vl_api_one_set_transport_protocol_t_handler
1709   (vl_api_one_set_transport_protocol_t * mp)
1710 {
1711   vl_api_one_set_transport_protocol_reply_t *rmp;
1712   int rv = 0;
1713
1714   rv = vnet_lisp_set_transport_protocol (mp->protocol);
1715
1716   REPLY_MACRO (VL_API_ONE_SET_TRANSPORT_PROTOCOL_REPLY);
1717 }
1718
1719 static void
1720   vl_api_one_get_transport_protocol_t_handler
1721   (vl_api_one_get_transport_protocol_t * mp)
1722 {
1723   vl_api_one_get_transport_protocol_reply_t *rmp;
1724   int rv = 0;
1725   u8 proto = (u8) vnet_lisp_get_transport_protocol ();
1726
1727   /* *INDENT-OFF* */
1728   REPLY_MACRO2 (VL_API_ONE_GET_TRANSPORT_PROTOCOL_REPLY,
1729   ({
1730     rmp->protocol = proto;
1731   }));
1732   /* *INDENT-ON* */
1733 }
1734
1735 static void
1736 vl_api_one_ndp_entries_get_t_handler (vl_api_one_ndp_entries_get_t * mp)
1737 {
1738   vl_api_one_ndp_entries_get_reply_t *rmp = 0;
1739   lisp_api_ndp_entry_t *entries = 0, *e;
1740   u32 i = 0;
1741   int rv = 0;
1742
1743   u32 bd = clib_net_to_host_u32 (mp->bd);
1744
1745   entries = vnet_lisp_ndp_entries_get_by_bd (bd);
1746   u32 size = vec_len (entries) * sizeof (vl_api_one_ndp_entry_t);
1747
1748   /* *INDENT-OFF* */
1749   REPLY_MACRO4 (VL_API_ONE_NDP_ENTRIES_GET_REPLY, size,
1750   {
1751     rmp->count = clib_host_to_net_u32 (vec_len (entries));
1752     vec_foreach (e, entries)
1753       {
1754         mac_copy (rmp->entries[i].mac, e->mac);
1755         clib_memcpy (rmp->entries[i].ip6, e->ip6, 16);
1756         i++;
1757       }
1758   });
1759   /* *INDENT-ON* */
1760
1761   vec_free (entries);
1762 }
1763
1764 static void
1765   vl_api_one_enable_disable_xtr_mode_t_handler
1766   (vl_api_one_enable_disable_xtr_mode_t * mp)
1767 {
1768   vl_api_one_enable_disable_xtr_mode_reply_t *rmp = 0;
1769   int rv = vnet_lisp_enable_disable_xtr_mode (mp->is_en);
1770
1771   REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_XTR_MODE_REPLY);
1772 }
1773
1774 static void
1775 vl_api_one_show_xtr_mode_t_handler (vl_api_one_show_xtr_mode_t * mp)
1776 {
1777   vl_api_one_show_xtr_mode_reply_t *rmp = 0;
1778   int rv = 0;
1779
1780   /* *INDENT-OFF* */
1781   REPLY_MACRO2 (VL_API_ONE_SHOW_XTR_MODE_REPLY,
1782   {
1783     rmp->is_en = vnet_lisp_get_xtr_mode ();
1784   });
1785   /* *INDENT-ON* */
1786 }
1787
1788 static void
1789   vl_api_one_enable_disable_pitr_mode_t_handler
1790   (vl_api_one_enable_disable_pitr_mode_t * mp)
1791 {
1792   vl_api_one_enable_disable_pitr_mode_reply_t *rmp = 0;
1793   int rv = vnet_lisp_enable_disable_pitr_mode (mp->is_en);
1794
1795   REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_PITR_MODE_REPLY);
1796 }
1797
1798 static void
1799 vl_api_one_show_pitr_mode_t_handler (vl_api_one_show_pitr_mode_t * mp)
1800 {
1801   vl_api_one_show_pitr_mode_reply_t *rmp = 0;
1802   int rv = 0;
1803
1804   /* *INDENT-OFF* */
1805   REPLY_MACRO2 (VL_API_ONE_SHOW_PITR_MODE_REPLY,
1806   {
1807     rmp->is_en = vnet_lisp_get_pitr_mode ();
1808   });
1809   /* *INDENT-ON* */
1810 }
1811
1812 static void
1813   vl_api_one_enable_disable_petr_mode_t_handler
1814   (vl_api_one_enable_disable_petr_mode_t * mp)
1815 {
1816   vl_api_one_enable_disable_petr_mode_reply_t *rmp = 0;
1817   int rv = vnet_lisp_enable_disable_petr_mode (mp->is_en);
1818
1819   REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_PETR_MODE_REPLY);
1820 }
1821
1822 static void
1823 vl_api_one_show_petr_mode_t_handler (vl_api_one_show_petr_mode_t * mp)
1824 {
1825   vl_api_one_show_petr_mode_reply_t *rmp = 0;
1826   int rv = 0;
1827
1828   /* *INDENT-OFF* */
1829   REPLY_MACRO2 (VL_API_ONE_SHOW_PETR_MODE_REPLY,
1830   {
1831     rmp->is_en = vnet_lisp_get_petr_mode ();
1832   });
1833   /* *INDENT-ON* */
1834 }
1835
1836 /*
1837  * one_api_hookup
1838  * Add vpe's API message handlers to the table.
1839  * vlib has alread mapped shared memory and
1840  * added the client registration handlers.
1841  * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
1842  */
1843 #define vl_msg_name_crc_list
1844 #include <vnet/vnet_all_api_h.h>
1845 #undef vl_msg_name_crc_list
1846
1847 static void
1848 setup_message_id_table (api_main_t * am)
1849 {
1850 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
1851   foreach_vl_msg_name_crc_one;
1852 #undef _
1853 }
1854
1855 static clib_error_t *
1856 one_api_hookup (vlib_main_t * vm)
1857 {
1858   api_main_t *am = &api_main;
1859
1860 #define _(N,n)                                                  \
1861     vl_msg_api_set_handlers(VL_API_##N, #n,                     \
1862                            vl_api_##n##_t_handler,              \
1863                            vl_noop_handler,                     \
1864                            vl_api_##n##_t_endian,               \
1865                            vl_api_##n##_t_print,                \
1866                            sizeof(vl_api_##n##_t), 1);
1867   foreach_vpe_api_msg;
1868 #undef _
1869
1870   /*
1871    * Set up the (msg_name, crc, message-id) table
1872    */
1873   setup_message_id_table (am);
1874
1875   return 0;
1876 }
1877
1878 VLIB_API_INIT_FUNCTION (one_api_hookup);
1879
1880 /*
1881  * fd.io coding-style-patch-verification: ON
1882  *
1883  * Local Variables:
1884  * eval: (c-set-style "gnu")
1885  * End:
1886  */