d91f9907752a8f07bcbaad7f83722c2e87c5296c
[vpp.git] / src / vnet / lisp-cp / lisp_api.c
1 /*
2  *------------------------------------------------------------------
3  * lisp_api.c - lisp 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/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_remote_locator_t_endian vl_noop_handler
31 #define vl_api_remote_locator_t_print vl_noop_handler
32 #define vl_api_local_locator_t_endian vl_noop_handler
33 #define vl_api_local_locator_t_print vl_noop_handler
34
35 #define vl_api_lisp_add_del_locator_set_t_endian vl_noop_handler
36 #define vl_api_lisp_add_del_locator_set_t_print vl_noop_handler
37 #define vl_api_lisp_add_del_remote_mapping_t_endian vl_noop_handler
38 #define vl_api_lisp_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_typedefs             /* define message structures */
46 #include <vnet/vnet_all_api_h.h>
47 #undef vl_typedefs
48
49 #define vl_endianfun            /* define message structures */
50 #include <vnet/vnet_all_api_h.h>
51 #undef vl_endianfun
52
53 /* instantiate all the print functions we know about */
54 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
55 #define vl_printfun
56 #include <vnet/vnet_all_api_h.h>
57 #undef vl_printfun
58
59 #include <vlibapi/api_helper_macros.h>
60
61 #define foreach_vpe_api_msg                             \
62 _(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set)                   \
63 _(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator)                           \
64 _(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid)                       \
65 _(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver)                 \
66 _(LISP_ADD_DEL_MAP_SERVER, lisp_add_del_map_server)                     \
67 _(LISP_ENABLE_DISABLE, lisp_enable_disable)                             \
68 _(LISP_RLOC_PROBE_ENABLE_DISABLE, lisp_rloc_probe_enable_disable)       \
69 _(LISP_MAP_REGISTER_ENABLE_DISABLE, lisp_map_register_enable_disable)   \
70 _(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping)             \
71 _(LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency)                       \
72 _(LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set)                 \
73 _(LISP_MAP_REQUEST_MODE, lisp_map_request_mode)                         \
74 _(LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map)               \
75 _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump)                         \
76 _(LISP_LOCATOR_DUMP, lisp_locator_dump)                                 \
77 _(LISP_EID_TABLE_DUMP, lisp_eid_table_dump)                             \
78 _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump)                       \
79 _(LISP_MAP_SERVER_DUMP, lisp_map_server_dump)                           \
80 _(LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump)                     \
81 _(LISP_EID_TABLE_VNI_DUMP, lisp_eid_table_vni_dump)                     \
82 _(LISP_ADJACENCIES_GET, lisp_adjacencies_get)                           \
83 _(SHOW_LISP_RLOC_PROBE_STATE, show_lisp_rloc_probe_state)               \
84 _(SHOW_LISP_MAP_REGISTER_STATE, show_lisp_map_register_state)           \
85 _(SHOW_LISP_STATUS, show_lisp_status)                                   \
86 _(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS,                                   \
87   lisp_add_del_map_request_itr_rlocs)                                   \
88 _(LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs)       \
89 _(SHOW_LISP_PITR, show_lisp_pitr)                                       \
90 _(SHOW_LISP_MAP_REQUEST_MODE, show_lisp_map_request_mode)               \
91 _(LISP_USE_PETR, lisp_use_petr)                                         \
92 _(SHOW_LISP_USE_PETR, show_lisp_use_petr)                               \
93
94 static locator_t *
95 unformat_lisp_locs (vl_api_remote_locator_t * rmt_locs, u32 rloc_num)
96 {
97   u32 i;
98   locator_t *locs = 0, loc;
99   vl_api_remote_locator_t *r;
100
101   for (i = 0; i < rloc_num; i++)
102     {
103       /* remote locators */
104       r = &rmt_locs[i];
105       memset (&loc, 0, sizeof (loc));
106       gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
107
108       loc.priority = r->priority;
109       loc.weight = r->weight;
110
111       vec_add1 (locs, loc);
112     }
113   return locs;
114 }
115
116 static void
117 vl_api_lisp_add_del_locator_set_t_handler (vl_api_lisp_add_del_locator_set_t *
118                                            mp)
119 {
120   vl_api_lisp_add_del_locator_set_reply_t *rmp;
121   int rv = 0;
122   vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
123   locator_t locator;
124   vl_api_local_locator_t *ls_loc;
125   u32 ls_index = ~0, locator_num;
126   u8 *locator_name = NULL;
127   int i;
128
129   memset (a, 0, sizeof (a[0]));
130
131   locator_name = format (0, "%s", mp->locator_set_name);
132
133   a->name = locator_name;
134   a->is_add = mp->is_add;
135   a->local = 1;
136   locator_num = clib_net_to_host_u32 (mp->locator_num);
137
138   memset (&locator, 0, sizeof (locator));
139   for (i = 0; i < locator_num; i++)
140     {
141       ls_loc = &mp->locators[i];
142       VALIDATE_SW_IF_INDEX (ls_loc);
143
144       locator.sw_if_index = htonl (ls_loc->sw_if_index);
145       locator.priority = ls_loc->priority;
146       locator.weight = ls_loc->weight;
147       locator.local = 1;
148       vec_add1 (a->locators, locator);
149     }
150
151   rv = vnet_lisp_add_del_locator_set (a, &ls_index);
152
153   BAD_SW_IF_INDEX_LABEL;
154
155   vec_free (locator_name);
156   vec_free (a->locators);
157
158   /* *INDENT-OFF* */
159   REPLY_MACRO2 (VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY,
160   ({
161     rmp->ls_index = clib_host_to_net_u32 (ls_index);
162   }));
163   /* *INDENT-ON* */
164 }
165
166 static void
167 vl_api_lisp_add_del_locator_t_handler (vl_api_lisp_add_del_locator_t * mp)
168 {
169   vl_api_lisp_add_del_locator_reply_t *rmp;
170   int rv = 0;
171   locator_t locator, *locators = NULL;
172   vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
173   u32 ls_index = ~0;
174   u8 *locator_name = NULL;
175
176   memset (&locator, 0, sizeof (locator));
177   memset (a, 0, sizeof (a[0]));
178
179   locator.sw_if_index = ntohl (mp->sw_if_index);
180   locator.priority = mp->priority;
181   locator.weight = mp->weight;
182   locator.local = 1;
183   vec_add1 (locators, locator);
184
185   locator_name = format (0, "%s", mp->locator_set_name);
186
187   a->name = locator_name;
188   a->locators = locators;
189   a->is_add = mp->is_add;
190   a->local = 1;
191
192   rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
193
194   vec_free (locators);
195   vec_free (locator_name);
196
197   REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
198 }
199
200 static int
201 unformat_lisp_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
202                        u8 len)
203 {
204   switch (type)
205     {
206     case 0:                     /* ipv4 */
207       gid_address_type (dst) = GID_ADDR_IP_PREFIX;
208       gid_address_ip_set (dst, src, IP4);
209       gid_address_ippref_len (dst) = len;
210       ip_prefix_normalize (&gid_address_ippref (dst));
211       break;
212     case 1:                     /* ipv6 */
213       gid_address_type (dst) = GID_ADDR_IP_PREFIX;
214       gid_address_ip_set (dst, src, IP6);
215       gid_address_ippref_len (dst) = len;
216       ip_prefix_normalize (&gid_address_ippref (dst));
217       break;
218     case 2:                     /* l2 mac */
219       gid_address_type (dst) = GID_ADDR_MAC;
220       clib_memcpy (&gid_address_mac (dst), src, 6);
221       break;
222     default:
223       /* unknown type */
224       return VNET_API_ERROR_INVALID_VALUE;
225     }
226
227   gid_address_vni (dst) = vni;
228
229   return 0;
230 }
231
232 static void
233 vl_api_lisp_add_del_local_eid_t_handler (vl_api_lisp_add_del_local_eid_t * mp)
234 {
235   vl_api_lisp_add_del_local_eid_reply_t *rmp;
236   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
237   int rv = 0;
238   gid_address_t _eid, *eid = &_eid;
239   uword *p = NULL;
240   u32 locator_set_index = ~0, map_index = ~0;
241   vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
242   u8 *name = NULL, *key = NULL;
243   memset (a, 0, sizeof (a[0]));
244   memset (eid, 0, sizeof (eid[0]));
245
246   rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
247                               mp->eid_type, mp->eid, mp->prefix_len);
248   if (rv)
249     goto out;
250
251   name = format (0, "%s", mp->locator_set_name);
252   p = hash_get_mem (lcm->locator_set_index_by_name, name);
253   if (!p)
254     {
255       rv = VNET_API_ERROR_INVALID_VALUE;
256       goto out;
257     }
258   locator_set_index = p[0];
259
260   if (*mp->key)
261     key = format (0, "%s", mp->key);
262
263   /* XXX treat batch configuration */
264   a->is_add = mp->is_add;
265   gid_address_copy (&a->eid, eid);
266   a->locator_set_index = locator_set_index;
267   a->local = 1;
268   a->key = key;
269   a->key_id = clib_net_to_host_u16 (mp->key_id);
270
271   rv = vnet_lisp_add_del_local_mapping (a, &map_index);
272
273 out:
274   vec_free (name);
275   vec_free (key);
276   gid_address_free (&a->eid);
277
278   REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
279 }
280
281 static void
282   vl_api_lisp_eid_table_add_del_map_t_handler
283   (vl_api_lisp_eid_table_add_del_map_t * mp)
284 {
285   vl_api_lisp_eid_table_add_del_map_reply_t *rmp;
286   int rv = 0;
287   rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
288                                 clib_net_to_host_u32 (mp->dp_table),
289                                 mp->is_l2, mp->is_add);
290 REPLY_MACRO (VL_API_LISP_EID_TABLE_ADD_DEL_MAP_REPLY)}
291
292 static void
293 vl_api_lisp_add_del_map_server_t_handler (vl_api_lisp_add_del_map_server_t
294                                           * mp)
295 {
296   vl_api_lisp_add_del_map_server_reply_t *rmp;
297   int rv = 0;
298   ip_address_t addr;
299
300   memset (&addr, 0, sizeof (addr));
301
302   ip_address_set (&addr, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
303   rv = vnet_lisp_add_del_map_server (&addr, mp->is_add);
304
305   REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_SERVER_REPLY);
306 }
307
308 static void
309 vl_api_lisp_add_del_map_resolver_t_handler (vl_api_lisp_add_del_map_resolver_t
310                                             * mp)
311 {
312   vl_api_lisp_add_del_map_resolver_reply_t *rmp;
313   int rv = 0;
314   vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
315
316   memset (a, 0, sizeof (a[0]));
317
318   a->is_add = mp->is_add;
319   ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
320
321   rv = vnet_lisp_add_del_map_resolver (a);
322
323   REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
324 }
325
326 static void
327   vl_api_lisp_map_register_enable_disable_t_handler
328   (vl_api_lisp_map_register_enable_disable_t * mp)
329 {
330   vl_api_lisp_map_register_enable_disable_reply_t *rmp;
331   int rv = 0;
332
333   vnet_lisp_map_register_enable_disable (mp->is_enabled);
334   REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
335 }
336
337 static void
338   vl_api_lisp_rloc_probe_enable_disable_t_handler
339   (vl_api_lisp_rloc_probe_enable_disable_t * mp)
340 {
341   vl_api_lisp_rloc_probe_enable_disable_reply_t *rmp;
342   int rv = 0;
343
344   vnet_lisp_rloc_probe_enable_disable (mp->is_enabled);
345   REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
346 }
347
348 static void
349 vl_api_lisp_enable_disable_t_handler (vl_api_lisp_enable_disable_t * mp)
350 {
351   vl_api_lisp_enable_disable_reply_t *rmp;
352   int rv = 0;
353
354   vnet_lisp_enable_disable (mp->is_en);
355   REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
356 }
357
358 static void
359   vl_api_show_lisp_map_request_mode_t_handler
360   (vl_api_show_lisp_map_request_mode_t * mp)
361 {
362   int rv = 0;
363   vl_api_show_lisp_map_request_mode_reply_t *rmp;
364
365   /* *INDENT-OFF* */
366   REPLY_MACRO2(VL_API_SHOW_LISP_MAP_REQUEST_MODE_REPLY,
367   ({
368     rmp->mode = vnet_lisp_get_map_request_mode ();
369   }));
370   /* *INDENT-ON* */
371 }
372
373 static void
374 vl_api_lisp_map_request_mode_t_handler (vl_api_lisp_map_request_mode_t * mp)
375 {
376   vl_api_lisp_map_request_mode_reply_t *rmp;
377   int rv = 0;
378
379   rv = vnet_lisp_set_map_request_mode (mp->mode);
380
381   REPLY_MACRO (VL_API_LISP_MAP_REQUEST_MODE_REPLY);
382 }
383
384 static void
385 vl_api_lisp_pitr_set_locator_set_t_handler (vl_api_lisp_pitr_set_locator_set_t
386                                             * mp)
387 {
388   vl_api_lisp_pitr_set_locator_set_reply_t *rmp;
389   int rv = 0;
390   u8 *ls_name = 0;
391
392   ls_name = format (0, "%s", mp->ls_name);
393   rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
394   vec_free (ls_name);
395
396   REPLY_MACRO (VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY);
397 }
398
399 static void
400 vl_api_lisp_use_petr_t_handler (vl_api_lisp_use_petr_t * mp)
401 {
402   vl_api_lisp_use_petr_reply_t *rmp;
403   int rv = 0;
404   ip_address_t addr;
405
406   ip_address_set (&addr, &mp->address, mp->is_ip4 ? IP4 : IP6);
407   rv = vnet_lisp_use_petr (&addr, mp->is_add);
408
409   REPLY_MACRO (VL_API_LISP_USE_PETR_REPLY);
410 }
411
412 static void
413 vl_api_show_lisp_use_petr_t_handler (vl_api_show_lisp_use_petr_t * mp)
414 {
415   unix_shared_memory_queue_t *q = NULL;
416   vl_api_show_lisp_use_petr_reply_t *rmp = NULL;
417   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
418   mapping_t *m;
419   locator_set_t *ls = 0;
420   int rv = 0;
421   locator_t *loc = 0;
422   u8 status = 0;
423   gid_address_t addr;
424
425   q = vl_api_client_index_to_input_queue (mp->client_index);
426   if (q == 0)
427     {
428       return;
429     }
430
431   memset (&addr, 0, sizeof (addr));
432   status = lcm->flags & LISP_FLAG_USE_PETR;
433   if (status)
434     {
435       m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index);
436       if (~0 != m->locator_set_index)
437         {
438           ls =
439             pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
440           loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]);
441           gid_address_copy (&addr, &loc->address);
442         }
443     }
444
445   /* *INDENT-OFF* */
446   REPLY_MACRO2 (VL_API_SHOW_LISP_USE_PETR_REPLY,
447   {
448       rmp->status = status;
449       gid_address_put (rmp->address, &addr);
450       rmp->is_ip4 = (gid_address_ip_version (&addr) == IP4);
451   });
452   /* *INDENT-ON* */
453 }
454
455 static void
456   vl_api_lisp_add_del_map_request_itr_rlocs_t_handler
457   (vl_api_lisp_add_del_map_request_itr_rlocs_t * mp)
458 {
459   vl_api_lisp_add_del_map_request_itr_rlocs_reply_t *rmp;
460   int rv = 0;
461   u8 *locator_set_name = NULL;
462   vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
463
464   locator_set_name = format (0, "%s", mp->locator_set_name);
465
466   a->is_add = mp->is_add;
467   a->locator_set_name = locator_set_name;
468
469   rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
470
471   vec_free (locator_set_name);
472
473   REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
474 }
475
476 static void
477   vl_api_lisp_add_del_remote_mapping_t_handler
478   (vl_api_lisp_add_del_remote_mapping_t * mp)
479 {
480   locator_t *rlocs = 0;
481   vl_api_lisp_add_del_remote_mapping_reply_t *rmp;
482   int rv = 0;
483   gid_address_t _eid, *eid = &_eid;
484   u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
485
486   memset (eid, 0, sizeof (eid[0]));
487
488   rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
489                               mp->eid_type, mp->eid, mp->eid_len);
490   if (rv)
491     goto send_reply;
492
493   rlocs = unformat_lisp_locs (mp->rlocs, rloc_num);
494
495   if (!mp->is_add)
496     {
497       vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
498       gid_address_copy (&a->reid, eid);
499       a->is_add = 0;
500       rv = vnet_lisp_add_del_adjacency (a);
501       if (rv)
502         {
503           goto out;
504         }
505     }
506
507   /* NOTE: for now this works as a static remote mapping, i.e.,
508    * not authoritative and ttl infinite. */
509   rv = vnet_lisp_add_del_mapping (eid, rlocs, mp->action, 0, ~0,
510                                   mp->is_add, 1 /* is_static */ , 0);
511
512   if (mp->del_all)
513     vnet_lisp_clear_all_remote_adjacencies ();
514
515 out:
516   vec_free (rlocs);
517 send_reply:
518   REPLY_MACRO (VL_API_LISP_ADD_DEL_REMOTE_MAPPING_REPLY);
519 }
520
521 static void
522 vl_api_lisp_add_del_adjacency_t_handler (vl_api_lisp_add_del_adjacency_t * mp)
523 {
524   vl_api_lisp_add_del_adjacency_reply_t *rmp;
525   vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
526
527   int rv = 0;
528   memset (a, 0, sizeof (a[0]));
529
530   rv = unformat_lisp_eid_api (&a->leid, clib_net_to_host_u32 (mp->vni),
531                               mp->eid_type, mp->leid, mp->leid_len);
532   rv |= unformat_lisp_eid_api (&a->reid, clib_net_to_host_u32 (mp->vni),
533                                mp->eid_type, mp->reid, mp->reid_len);
534
535   if (rv)
536     goto send_reply;
537
538   a->is_add = mp->is_add;
539   rv = vnet_lisp_add_del_adjacency (a);
540
541 send_reply:
542   REPLY_MACRO (VL_API_LISP_ADD_DEL_ADJACENCY_REPLY);
543 }
544
545 static void
546 send_lisp_locator_details (lisp_cp_main_t * lcm,
547                            locator_t * loc,
548                            unix_shared_memory_queue_t * q, u32 context)
549 {
550   vl_api_lisp_locator_details_t *rmp;
551
552   rmp = vl_msg_api_alloc (sizeof (*rmp));
553   memset (rmp, 0, sizeof (*rmp));
554   rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_DETAILS);
555   rmp->context = context;
556
557   rmp->local = loc->local;
558   if (loc->local)
559     {
560       rmp->sw_if_index = ntohl (loc->sw_if_index);
561     }
562   else
563     {
564       rmp->is_ipv6 = gid_address_ip_version (&loc->address);
565       ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
566     }
567   rmp->priority = loc->priority;
568   rmp->weight = loc->weight;
569
570   vl_msg_api_send_shmem (q, (u8 *) & rmp);
571 }
572
573 static void
574 vl_api_lisp_locator_dump_t_handler (vl_api_lisp_locator_dump_t * mp)
575 {
576   u8 *ls_name = 0;
577   unix_shared_memory_queue_t *q = 0;
578   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
579   locator_set_t *lsit = 0;
580   locator_t *loc = 0;
581   u32 ls_index = ~0, *locit = 0;
582   uword *p = 0;
583
584   q = vl_api_client_index_to_input_queue (mp->client_index);
585   if (q == 0)
586     {
587       return;
588     }
589
590   if (mp->is_index_set)
591     ls_index = htonl (mp->ls_index);
592   else
593     {
594       /* make sure we get a proper C-string */
595       mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
596       ls_name = format (0, "%s", mp->ls_name);
597       p = hash_get_mem (lcm->locator_set_index_by_name, ls_name);
598       if (!p)
599         goto out;
600       ls_index = p[0];
601     }
602
603   if (pool_is_free_index (lcm->locator_set_pool, ls_index))
604     return;
605
606   lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
607
608   vec_foreach (locit, lsit->locator_indices)
609   {
610     loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
611     send_lisp_locator_details (lcm, loc, q, mp->context);
612   };
613 out:
614   vec_free (ls_name);
615 }
616
617 static void
618 send_lisp_locator_set_details (lisp_cp_main_t * lcm,
619                                locator_set_t * lsit,
620                                unix_shared_memory_queue_t * q,
621                                u32 context, u32 ls_index)
622 {
623   vl_api_lisp_locator_set_details_t *rmp;
624   u8 *str = 0;
625
626   rmp = vl_msg_api_alloc (sizeof (*rmp));
627   memset (rmp, 0, sizeof (*rmp));
628   rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_SET_DETAILS);
629   rmp->context = context;
630
631   rmp->ls_index = htonl (ls_index);
632   if (lsit->local)
633     {
634       ASSERT (lsit->name != NULL);
635       strncpy ((char *) rmp->ls_name, (char *) lsit->name,
636                vec_len (lsit->name));
637     }
638   else
639     {
640       str = format (0, "<remote-%d>", ls_index);
641       strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str));
642       vec_free (str);
643     }
644
645   vl_msg_api_send_shmem (q, (u8 *) & rmp);
646 }
647
648 static void
649 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t * mp)
650 {
651   unix_shared_memory_queue_t *q = NULL;
652   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
653   locator_set_t *lsit = NULL;
654   u8 filter;
655
656   q = vl_api_client_index_to_input_queue (mp->client_index);
657   if (q == 0)
658     {
659       return;
660     }
661
662   filter = mp->filter;
663   /* *INDENT-OFF* */
664   pool_foreach (lsit, lcm->locator_set_pool,
665   ({
666     if (filter && !((1 == filter && lsit->local) ||
667                     (2 == filter && !lsit->local)))
668       {
669         continue;
670       }
671     send_lisp_locator_set_details (lcm, lsit, q, mp->context,
672                                    lsit - lcm->locator_set_pool);
673   }));
674   /* *INDENT-ON* */
675 }
676
677 static void
678 lisp_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length)
679 {
680   ASSERT (prefix_length);
681   ip_prefix_t *ippref = &fid_addr_ippref (src);
682
683   switch (fid_addr_type (src))
684     {
685     case FID_ADDR_IP_PREF:
686       if (ip_prefix_version (ippref) == IP4)
687         clib_memcpy (dst, &ip_prefix_v4 (ippref), 4);
688       else
689         clib_memcpy (dst, &ip_prefix_v6 (ippref), 16);
690       prefix_length[0] = ip_prefix_len (ippref);
691       break;
692
693     case FID_ADDR_MAC:
694       prefix_length[0] = 0;
695       clib_memcpy (dst, fid_addr_mac (src), 6);
696       break;
697
698     default:
699       clib_warning ("Unknown FID type %d!", fid_addr_type (src));
700       break;
701     }
702 }
703
704 static u8
705 fid_type_to_api_type (fid_address_t * fid)
706 {
707   ip_prefix_t *ippref;
708
709   switch (fid_addr_type (fid))
710     {
711     case FID_ADDR_IP_PREF:
712       ippref = &fid_addr_ippref (fid);
713       if (ip_prefix_version (ippref) == IP4)
714         return 0;
715       else if (ip_prefix_version (ippref) == IP6)
716         return 1;
717       else
718         return ~0;
719
720     case FID_ADDR_MAC:
721       return 2;
722     case FID_ADDR_NSH:
723       return 3;
724     }
725
726   return ~0;
727 }
728
729 static void
730 send_lisp_eid_table_details (mapping_t * mapit,
731                              unix_shared_memory_queue_t * q,
732                              u32 context, u8 filter)
733 {
734   fid_address_t *fid;
735   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
736   locator_set_t *ls = 0;
737   vl_api_lisp_eid_table_details_t *rmp = NULL;
738   gid_address_t *gid = NULL;
739   u8 *mac = 0;
740   ip_prefix_t *ip_prefix = NULL;
741
742   switch (filter)
743     {
744     case 0:                     /* all mappings */
745       break;
746
747     case 1:                     /* local only */
748       if (!mapit->local)
749         return;
750       break;
751     case 2:                     /* remote only */
752       if (mapit->local)
753         return;
754       break;
755     default:
756       clib_warning ("Filter error, unknown filter: %d", filter);
757       return;
758     }
759
760   /* don't send PITR generated mapping */
761   if (mapit->pitr_set)
762     return;
763
764   gid = &mapit->eid;
765   ip_prefix = &gid_address_ippref (gid);
766   mac = gid_address_mac (gid);
767
768   rmp = vl_msg_api_alloc (sizeof (*rmp));
769   memset (rmp, 0, sizeof (*rmp));
770   rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_DETAILS);
771
772   ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
773   if (vec_len (ls->locator_indices) == 0)
774     rmp->locator_set_index = ~0;
775   else
776     rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
777
778   rmp->is_local = mapit->local;
779   rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
780   rmp->action = mapit->action;
781   rmp->authoritative = mapit->authoritative;
782
783   switch (gid_address_type (gid))
784     {
785     case GID_ADDR_SRC_DST:
786       rmp->is_src_dst = 1;
787       fid = &gid_address_sd_src (gid);
788       rmp->eid_type = fid_type_to_api_type (fid);
789       lisp_fid_put_api (rmp->seid, &gid_address_sd_src (gid),
790                         &rmp->seid_prefix_len);
791       lisp_fid_put_api (rmp->eid, &gid_address_sd_dst (gid),
792                         &rmp->eid_prefix_len);
793       break;
794     case GID_ADDR_IP_PREFIX:
795       rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
796       if (ip_prefix_version (ip_prefix) == IP4)
797         {
798           rmp->eid_type = 0;    /* ipv4 type */
799           clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
800                        sizeof (ip_prefix_v4 (ip_prefix)));
801         }
802       else
803         {
804           rmp->eid_type = 1;    /* ipv6 type */
805           clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
806                        sizeof (ip_prefix_v6 (ip_prefix)));
807         }
808       break;
809     case GID_ADDR_MAC:
810       rmp->eid_type = 2;        /* l2 mac type */
811       clib_memcpy (rmp->eid, mac, 6);
812       break;
813     default:
814       ASSERT (0);
815     }
816   rmp->context = context;
817   rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
818   rmp->key_id = clib_host_to_net_u16 (mapit->key_id);
819   memcpy (rmp->key, mapit->key, vec_len (mapit->key));
820   vl_msg_api_send_shmem (q, (u8 *) & rmp);
821 }
822
823 static void
824 vl_api_lisp_eid_table_dump_t_handler (vl_api_lisp_eid_table_dump_t * mp)
825 {
826   u32 mi;
827   unix_shared_memory_queue_t *q = NULL;
828   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
829   mapping_t *mapit = NULL;
830   gid_address_t _eid, *eid = &_eid;
831
832   q = vl_api_client_index_to_input_queue (mp->client_index);
833   if (q == 0)
834     {
835       return;
836     }
837
838   if (mp->eid_set)
839     {
840       memset (eid, 0, sizeof (*eid));
841
842       unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
843                              mp->eid_type, mp->eid, mp->prefix_length);
844
845       mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
846       if ((u32) ~ 0 == mi)
847         return;
848
849       mapit = pool_elt_at_index (lcm->mapping_pool, mi);
850       send_lisp_eid_table_details (mapit, q, mp->context,
851                                    0 /* ignore filter */ );
852     }
853   else
854     {
855       /* *INDENT-OFF* */
856       pool_foreach (mapit, lcm->mapping_pool,
857       ({
858         send_lisp_eid_table_details(mapit, q, mp->context,
859                                     mp->filter);
860       }));
861       /* *INDENT-ON* */
862     }
863 }
864
865 static void
866 send_lisp_map_server_details (ip_address_t * ip,
867                               unix_shared_memory_queue_t * q, u32 context)
868 {
869   vl_api_lisp_map_server_details_t *rmp = NULL;
870
871   rmp = vl_msg_api_alloc (sizeof (*rmp));
872   memset (rmp, 0, sizeof (*rmp));
873   rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_SERVER_DETAILS);
874
875   switch (ip_addr_version (ip))
876     {
877     case IP4:
878       rmp->is_ipv6 = 0;
879       clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
880                    sizeof (ip_addr_v4 (ip)));
881       break;
882
883     case IP6:
884       rmp->is_ipv6 = 1;
885       clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
886                    sizeof (ip_addr_v6 (ip)));
887       break;
888
889     default:
890       ASSERT (0);
891     }
892   rmp->context = context;
893
894   vl_msg_api_send_shmem (q, (u8 *) & rmp);
895 }
896
897 static void
898 vl_api_lisp_map_server_dump_t_handler (vl_api_lisp_map_server_dump_t * mp)
899 {
900   unix_shared_memory_queue_t *q = NULL;
901   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
902   lisp_msmr_t *mr;
903
904   q = vl_api_client_index_to_input_queue (mp->client_index);
905   if (q == 0)
906     {
907       return;
908     }
909
910   vec_foreach (mr, lcm->map_servers)
911   {
912     send_lisp_map_server_details (&mr->address, q, mp->context);
913   }
914 }
915
916 static void
917 send_lisp_map_resolver_details (ip_address_t * ip,
918                                 unix_shared_memory_queue_t * q, u32 context)
919 {
920   vl_api_lisp_map_resolver_details_t *rmp = NULL;
921
922   rmp = vl_msg_api_alloc (sizeof (*rmp));
923   memset (rmp, 0, sizeof (*rmp));
924   rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_RESOLVER_DETAILS);
925
926   switch (ip_addr_version (ip))
927     {
928     case IP4:
929       rmp->is_ipv6 = 0;
930       clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
931                    sizeof (ip_addr_v4 (ip)));
932       break;
933
934     case IP6:
935       rmp->is_ipv6 = 1;
936       clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
937                    sizeof (ip_addr_v6 (ip)));
938       break;
939
940     default:
941       ASSERT (0);
942     }
943   rmp->context = context;
944
945   vl_msg_api_send_shmem (q, (u8 *) & rmp);
946 }
947
948 static void
949 vl_api_lisp_map_resolver_dump_t_handler (vl_api_lisp_map_resolver_dump_t * mp)
950 {
951   unix_shared_memory_queue_t *q = NULL;
952   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
953   lisp_msmr_t *mr;
954
955   q = vl_api_client_index_to_input_queue (mp->client_index);
956   if (q == 0)
957     {
958       return;
959     }
960
961   vec_foreach (mr, lcm->map_resolvers)
962   {
963     send_lisp_map_resolver_details (&mr->address, q, mp->context);
964   }
965 }
966
967 static void
968 send_eid_table_map_pair (hash_pair_t * p,
969                          unix_shared_memory_queue_t * q, u32 context)
970 {
971   vl_api_lisp_eid_table_map_details_t *rmp = NULL;
972
973   rmp = vl_msg_api_alloc (sizeof (*rmp));
974   memset (rmp, 0, sizeof (*rmp));
975   rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_MAP_DETAILS);
976
977   rmp->vni = clib_host_to_net_u32 (p->key);
978   rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
979   rmp->context = context;
980   vl_msg_api_send_shmem (q, (u8 *) & rmp);
981 }
982
983 static void
984 vl_api_lisp_eid_table_map_dump_t_handler (vl_api_lisp_eid_table_map_dump_t *
985                                           mp)
986 {
987   unix_shared_memory_queue_t *q = NULL;
988   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
989   hash_pair_t *p;
990   uword *vni_table = 0;
991
992   q = vl_api_client_index_to_input_queue (mp->client_index);
993   if (q == 0)
994     {
995       return;
996     }
997
998   if (mp->is_l2)
999     {
1000       vni_table = lcm->bd_id_by_vni;
1001     }
1002   else
1003     {
1004       vni_table = lcm->table_id_by_vni;
1005     }
1006
1007   /* *INDENT-OFF* */
1008   hash_foreach_pair (p, vni_table,
1009   ({
1010     send_eid_table_map_pair (p, q, mp->context);
1011   }));
1012   /* *INDENT-ON* */
1013 }
1014
1015 static void
1016 send_eid_table_vni (u32 vni, unix_shared_memory_queue_t * q, u32 context)
1017 {
1018   vl_api_lisp_eid_table_vni_details_t *rmp = 0;
1019
1020   rmp = vl_msg_api_alloc (sizeof (*rmp));
1021   memset (rmp, 0, sizeof (*rmp));
1022   rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_VNI_DETAILS);
1023   rmp->context = context;
1024   rmp->vni = clib_host_to_net_u32 (vni);
1025   vl_msg_api_send_shmem (q, (u8 *) & rmp);
1026 }
1027
1028 static void
1029 lisp_adjacency_copy (vl_api_lisp_adjacency_t * dst, lisp_adjacency_t * adjs)
1030 {
1031   lisp_adjacency_t *adj;
1032   vl_api_lisp_adjacency_t a;
1033   u32 i, n = vec_len (adjs);
1034
1035   for (i = 0; i < n; i++)
1036     {
1037       adj = vec_elt_at_index (adjs, i);
1038       memset (&a, 0, sizeof (a));
1039
1040       switch (gid_address_type (&adj->reid))
1041         {
1042         case GID_ADDR_IP_PREFIX:
1043           a.reid_prefix_len = gid_address_ippref_len (&adj->reid);
1044           a.leid_prefix_len = gid_address_ippref_len (&adj->leid);
1045           if (gid_address_ip_version (&adj->reid) == IP4)
1046             {
1047               a.eid_type = 0;   /* ipv4 type */
1048               clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 4);
1049               clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 4);
1050             }
1051           else
1052             {
1053               a.eid_type = 1;   /* ipv6 type */
1054               clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 16);
1055               clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 16);
1056             }
1057           break;
1058         case GID_ADDR_MAC:
1059           a.eid_type = 2;       /* l2 mac type */
1060           mac_copy (a.reid, gid_address_mac (&adj->reid));
1061           mac_copy (a.leid, gid_address_mac (&adj->leid));
1062           break;
1063         default:
1064           ASSERT (0);
1065         }
1066       dst[i] = a;
1067     }
1068 }
1069
1070 static void
1071   vl_api_show_lisp_rloc_probe_state_t_handler
1072   (vl_api_show_lisp_rloc_probe_state_t * mp)
1073 {
1074   vl_api_show_lisp_rloc_probe_state_reply_t *rmp = 0;
1075   int rv = 0;
1076
1077   /* *INDENT-OFF* */
1078   REPLY_MACRO2 (VL_API_SHOW_LISP_RLOC_PROBE_STATE_REPLY,
1079   {
1080     rmp->is_enabled = vnet_lisp_rloc_probe_state_get ();
1081   });
1082   /* *INDENT-ON* */
1083 }
1084
1085 static void
1086   vl_api_show_lisp_map_register_state_t_handler
1087   (vl_api_show_lisp_map_register_state_t * mp)
1088 {
1089   vl_api_show_lisp_map_register_state_reply_t *rmp = 0;
1090   int rv = 0;
1091
1092   /* *INDENT-OFF* */
1093   REPLY_MACRO2 (VL_API_SHOW_LISP_MAP_REGISTER_STATE_REPLY,
1094   {
1095     rmp->is_enabled = vnet_lisp_map_register_state_get ();
1096   });
1097   /* *INDENT-ON* */
1098 }
1099
1100 static void
1101 vl_api_lisp_adjacencies_get_t_handler (vl_api_lisp_adjacencies_get_t * mp)
1102 {
1103   vl_api_lisp_adjacencies_get_reply_t *rmp = 0;
1104   lisp_adjacency_t *adjs = 0;
1105   int rv = 0;
1106   u32 size = ~0;
1107   u32 vni = clib_net_to_host_u32 (mp->vni);
1108
1109   adjs = vnet_lisp_adjacencies_get_by_vni (vni);
1110   size = vec_len (adjs) * sizeof (vl_api_lisp_adjacency_t);
1111
1112   /* *INDENT-OFF* */
1113   REPLY_MACRO4 (VL_API_LISP_ADJACENCIES_GET_REPLY, size,
1114   {
1115     rmp->count = clib_host_to_net_u32 (vec_len (adjs));
1116     lisp_adjacency_copy (rmp->adjacencies, adjs);
1117   });
1118   /* *INDENT-ON* */
1119
1120   vec_free (adjs);
1121 }
1122
1123 static void
1124 vl_api_lisp_eid_table_vni_dump_t_handler (vl_api_lisp_eid_table_vni_dump_t *
1125                                           mp)
1126 {
1127   hash_pair_t *p;
1128   u32 *vnis = 0;
1129   unix_shared_memory_queue_t *q = 0;
1130   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1131
1132   q = vl_api_client_index_to_input_queue (mp->client_index);
1133   if (q == 0)
1134     {
1135       return;
1136     }
1137
1138   /* *INDENT-OFF* */
1139   hash_foreach_pair (p, lcm->table_id_by_vni,
1140   ({
1141     hash_set (vnis, p->key, 0);
1142   }));
1143
1144   hash_foreach_pair (p, lcm->bd_id_by_vni,
1145   ({
1146     hash_set (vnis, p->key, 0);
1147   }));
1148
1149   hash_foreach_pair (p, vnis,
1150   ({
1151     send_eid_table_vni (p->key, q, mp->context);
1152   }));
1153   /* *INDENT-ON* */
1154
1155   hash_free (vnis);
1156 }
1157
1158 static void
1159 vl_api_show_lisp_status_t_handler (vl_api_show_lisp_status_t * mp)
1160 {
1161   unix_shared_memory_queue_t *q = NULL;
1162   vl_api_show_lisp_status_reply_t *rmp = NULL;
1163   int rv = 0;
1164
1165   q = vl_api_client_index_to_input_queue (mp->client_index);
1166   if (q == 0)
1167     {
1168       return;
1169     }
1170
1171   /* *INDENT-OFF* */
1172   REPLY_MACRO2(VL_API_SHOW_LISP_STATUS_REPLY,
1173   ({
1174     rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
1175     rmp->feature_status = vnet_lisp_enable_disable_status ();
1176   }));
1177   /* *INDENT-ON* */
1178 }
1179
1180 static void
1181   vl_api_lisp_get_map_request_itr_rlocs_t_handler
1182   (vl_api_lisp_get_map_request_itr_rlocs_t * mp)
1183 {
1184   unix_shared_memory_queue_t *q = NULL;
1185   vl_api_lisp_get_map_request_itr_rlocs_reply_t *rmp = NULL;
1186   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1187   locator_set_t *loc_set = 0;
1188   u8 *tmp_str = 0;
1189   int rv = 0;
1190
1191   q = vl_api_client_index_to_input_queue (mp->client_index);
1192   if (q == 0)
1193     {
1194       return;
1195     }
1196
1197   if (~0 == lcm->mreq_itr_rlocs)
1198     {
1199       tmp_str = format (0, " ");
1200     }
1201   else
1202     {
1203       loc_set =
1204         pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
1205       tmp_str = format (0, "%s", loc_set->name);
1206     }
1207
1208   /* *INDENT-OFF* */
1209   REPLY_MACRO2(VL_API_LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
1210   ({
1211     strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1212             ARRAY_LEN(rmp->locator_set_name) - 1);
1213   }));
1214   /* *INDENT-ON* */
1215
1216   vec_free (tmp_str);
1217 }
1218
1219 static void
1220 vl_api_show_lisp_pitr_t_handler (vl_api_show_lisp_pitr_t * mp)
1221 {
1222   unix_shared_memory_queue_t *q = NULL;
1223   vl_api_show_lisp_pitr_reply_t *rmp = NULL;
1224   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1225   mapping_t *m;
1226   locator_set_t *ls = 0;
1227   u8 *tmp_str = 0;
1228   int rv = 0;
1229
1230   q = vl_api_client_index_to_input_queue (mp->client_index);
1231   if (q == 0)
1232     {
1233       return;
1234     }
1235
1236   if (!lcm->lisp_pitr)
1237     {
1238       tmp_str = format (0, "N/A");
1239     }
1240   else
1241     {
1242       m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
1243       if (~0 != m->locator_set_index)
1244         {
1245           ls =
1246             pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
1247           tmp_str = format (0, "%s", ls->name);
1248         }
1249       else
1250         {
1251           tmp_str = format (0, "N/A");
1252         }
1253     }
1254   vec_add1 (tmp_str, 0);
1255
1256   /* *INDENT-OFF* */
1257   REPLY_MACRO2(VL_API_SHOW_LISP_PITR_REPLY,
1258   ({
1259     rmp->status = lcm->lisp_pitr;
1260     strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1261             ARRAY_LEN(rmp->locator_set_name) - 1);
1262   }));
1263   /* *INDENT-ON* */
1264 }
1265
1266 /*
1267  * lisp_api_hookup
1268  * Add vpe's API message handlers to the table.
1269  * vlib has alread mapped shared memory and
1270  * added the client registration handlers.
1271  * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
1272  */
1273 #define vl_msg_name_crc_list
1274 #include <vnet/vnet_all_api_h.h>
1275 #undef vl_msg_name_crc_list
1276
1277 static void
1278 setup_message_id_table (api_main_t * am)
1279 {
1280 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
1281   foreach_vl_msg_name_crc_lisp;
1282 #undef _
1283 }
1284
1285 static clib_error_t *
1286 lisp_api_hookup (vlib_main_t * vm)
1287 {
1288   api_main_t *am = &api_main;
1289
1290 #define _(N,n)                                                  \
1291     vl_msg_api_set_handlers(VL_API_##N, #n,                     \
1292                            vl_api_##n##_t_handler,              \
1293                            vl_noop_handler,                     \
1294                            vl_api_##n##_t_endian,               \
1295                            vl_api_##n##_t_print,                \
1296                            sizeof(vl_api_##n##_t), 1);
1297   foreach_vpe_api_msg;
1298 #undef _
1299
1300   /*
1301    * Set up the (msg_name, crc, message-id) table
1302    */
1303   setup_message_id_table (am);
1304
1305   return 0;
1306 }
1307
1308 VLIB_API_INIT_FUNCTION (lisp_api_hookup);
1309
1310 /*
1311  * fd.io coding-style-patch-verification: ON
1312  *
1313  * Local Variables:
1314  * eval: (c-set-style "gnu")
1315  * End:
1316  */