2 *------------------------------------------------------------------
3 * lisp_api.c - lisp api
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:
10 * http://www.apache.org/licenses/LICENSE-2.0
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 *------------------------------------------------------------------
20 #include <vnet/vnet.h>
21 #include <vlibmemory/api.h>
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 #include <vnet/ip/ip_types_api.h>
28 #include <vnet/ethernet/ethernet_types_api.h>
29 #include <vnet/lisp-cp/lisp_types_api.h>
31 #include <vnet/vnet_msg_enum.h>
34 #define vl_api_lisp_add_del_locator_set_t_endian vl_noop_handler
35 #define vl_api_lisp_add_del_locator_set_t_print vl_noop_handler
36 #define vl_api_lisp_add_del_remote_mapping_t_endian vl_noop_handler
37 #define vl_api_lisp_add_del_remote_mapping_t_print vl_noop_handler
39 #define vl_api_one_add_del_locator_set_t_endian vl_noop_handler
40 #define vl_api_one_add_del_locator_set_t_print vl_noop_handler
41 #define vl_api_one_add_del_remote_mapping_t_endian vl_noop_handler
42 #define vl_api_one_add_del_remote_mapping_t_print vl_noop_handler
44 #define vl_typedefs /* define message structures */
45 #include <vnet/vnet_all_api_h.h>
48 #define vl_endianfun /* define message structures */
49 #include <vnet/vnet_all_api_h.h>
52 /* instantiate all the print functions we know about */
53 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
55 #include <vnet/vnet_all_api_h.h>
58 #include <vlibapi/api_helper_macros.h>
60 #define foreach_vpe_api_msg \
61 _(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set) \
62 _(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator) \
63 _(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid) \
64 _(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver) \
65 _(LISP_ADD_DEL_MAP_SERVER, lisp_add_del_map_server) \
66 _(LISP_ENABLE_DISABLE, lisp_enable_disable) \
67 _(LISP_RLOC_PROBE_ENABLE_DISABLE, lisp_rloc_probe_enable_disable) \
68 _(LISP_MAP_REGISTER_ENABLE_DISABLE, lisp_map_register_enable_disable) \
69 _(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping) \
70 _(LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency) \
71 _(LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set) \
72 _(LISP_MAP_REQUEST_MODE, lisp_map_request_mode) \
73 _(LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map) \
74 _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \
75 _(LISP_LOCATOR_DUMP, lisp_locator_dump) \
76 _(LISP_EID_TABLE_DUMP, lisp_eid_table_dump) \
77 _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump) \
78 _(LISP_MAP_SERVER_DUMP, lisp_map_server_dump) \
79 _(LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump) \
80 _(LISP_EID_TABLE_VNI_DUMP, lisp_eid_table_vni_dump) \
81 _(LISP_ADJACENCIES_GET, lisp_adjacencies_get) \
82 _(SHOW_LISP_RLOC_PROBE_STATE, show_lisp_rloc_probe_state) \
83 _(SHOW_LISP_MAP_REGISTER_STATE, show_lisp_map_register_state) \
84 _(SHOW_LISP_STATUS, show_lisp_status) \
85 _(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \
86 lisp_add_del_map_request_itr_rlocs) \
87 _(LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs) \
88 _(SHOW_LISP_PITR, show_lisp_pitr) \
89 _(SHOW_LISP_MAP_REQUEST_MODE, show_lisp_map_request_mode) \
90 _(LISP_USE_PETR, lisp_use_petr) \
91 _(SHOW_LISP_USE_PETR, show_lisp_use_petr) \
94 unformat_lisp_locs (vl_api_remote_locator_t * rmt_locs, u32 rloc_num)
97 locator_t *locs = 0, loc;
98 vl_api_remote_locator_t *r;
100 for (i = 0; i < rloc_num; i++)
102 /* remote locators */
104 clib_memset (&loc, 0, sizeof (loc));
105 ip_address_decode2 (&r->ip_address, &loc.address.ippref.addr);
106 loc.address.ippref.len =
107 ip_address_max_len (loc.address.ippref.addr.version);
109 loc.priority = r->priority;
110 loc.weight = r->weight;
112 vec_add1 (locs, loc);
118 vl_api_lisp_add_del_locator_set_t_handler (vl_api_lisp_add_del_locator_set_t *
121 vl_api_lisp_add_del_locator_set_reply_t *rmp;
123 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
125 vl_api_local_locator_t *ls_loc;
126 u32 ls_index = ~0, locator_num;
127 u8 *locator_name = NULL;
130 clib_memset (a, 0, sizeof (a[0]));
132 mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0;
133 locator_name = format (0, "%s", mp->locator_set_name);
134 vec_terminate_c_string (locator_name);
136 a->name = locator_name;
137 a->is_add = mp->is_add;
139 locator_num = clib_net_to_host_u32 (mp->locator_num);
141 clib_memset (&locator, 0, sizeof (locator));
142 for (i = 0; i < locator_num; i++)
144 ls_loc = &mp->locators[i];
145 VALIDATE_SW_IF_INDEX (ls_loc);
147 locator.sw_if_index = htonl (ls_loc->sw_if_index);
148 locator.priority = ls_loc->priority;
149 locator.weight = ls_loc->weight;
151 vec_add1 (a->locators, locator);
154 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
156 BAD_SW_IF_INDEX_LABEL;
158 vec_free (locator_name);
159 vec_free (a->locators);
162 REPLY_MACRO2 (VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY,
164 rmp->ls_index = clib_host_to_net_u32 (ls_index);
170 vl_api_lisp_add_del_locator_t_handler (vl_api_lisp_add_del_locator_t * mp)
172 vl_api_lisp_add_del_locator_reply_t *rmp;
174 locator_t locator, *locators = NULL;
175 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
177 u8 *locator_name = NULL;
179 clib_memset (&locator, 0, sizeof (locator));
180 clib_memset (a, 0, sizeof (a[0]));
182 locator.sw_if_index = ntohl (mp->sw_if_index);
183 locator.priority = mp->priority;
184 locator.weight = mp->weight;
186 vec_add1 (locators, locator);
188 mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0;
189 locator_name = format (0, "%s", mp->locator_set_name);
190 vec_terminate_c_string (locator_name);
192 a->name = locator_name;
193 a->locators = locators;
194 a->is_add = mp->is_add;
197 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
200 vec_free (locator_name);
202 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
206 vl_api_lisp_add_del_local_eid_t_handler (vl_api_lisp_add_del_local_eid_t * mp)
208 vl_api_lisp_add_del_local_eid_reply_t *rmp;
209 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
211 gid_address_t _gid, *gid = &_gid;
213 u32 locator_set_index = ~0, map_index = ~0;
214 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
215 u8 *name = NULL, *key = NULL;
216 clib_memset (a, 0, sizeof (a[0]));
217 clib_memset (gid, 0, sizeof (gid[0]));
219 rv = unformat_lisp_eid_api (gid, mp->vni, &mp->eid);
223 mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0;
224 name = format (0, "%s", mp->locator_set_name);
225 vec_terminate_c_string (name);
226 p = hash_get_mem (lcm->locator_set_index_by_name, name);
229 rv = VNET_API_ERROR_INVALID_VALUE;
232 locator_set_index = p[0];
235 key = format (0, "%s", mp->key.key);
237 /* XXX treat batch configuration */
238 a->is_add = mp->is_add;
239 gid_address_copy (&a->eid, gid);
240 a->locator_set_index = locator_set_index;
243 a->key_id = clib_net_to_host_u16 (mp->key.id);
245 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
250 gid_address_free (&a->eid);
252 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
256 vl_api_lisp_eid_table_add_del_map_t_handler
257 (vl_api_lisp_eid_table_add_del_map_t * mp)
259 vl_api_lisp_eid_table_add_del_map_reply_t *rmp;
261 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
262 clib_net_to_host_u32 (mp->dp_table),
263 mp->is_l2, mp->is_add);
264 REPLY_MACRO (VL_API_LISP_EID_TABLE_ADD_DEL_MAP_REPLY)}
267 vl_api_lisp_add_del_map_server_t_handler (vl_api_lisp_add_del_map_server_t
270 vl_api_lisp_add_del_map_server_reply_t *rmp;
274 clib_memset (&addr, 0, sizeof (addr));
276 ip_address_decode2 (&mp->ip_address, &addr);
277 rv = vnet_lisp_add_del_map_server (&addr, mp->is_add);
279 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_SERVER_REPLY);
283 vl_api_lisp_add_del_map_resolver_t_handler (vl_api_lisp_add_del_map_resolver_t
286 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
288 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
290 clib_memset (a, 0, sizeof (a[0]));
292 a->is_add = mp->is_add;
293 ip_address_decode2 (&mp->ip_address, &a->address);
295 rv = vnet_lisp_add_del_map_resolver (a);
297 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
301 vl_api_lisp_map_register_enable_disable_t_handler
302 (vl_api_lisp_map_register_enable_disable_t * mp)
304 vl_api_lisp_map_register_enable_disable_reply_t *rmp;
307 vnet_lisp_map_register_enable_disable (mp->is_enable);
308 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
312 vl_api_lisp_rloc_probe_enable_disable_t_handler
313 (vl_api_lisp_rloc_probe_enable_disable_t * mp)
315 vl_api_lisp_rloc_probe_enable_disable_reply_t *rmp;
318 vnet_lisp_rloc_probe_enable_disable (mp->is_enable);
319 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
323 vl_api_lisp_enable_disable_t_handler (vl_api_lisp_enable_disable_t * mp)
325 vl_api_lisp_enable_disable_reply_t *rmp;
328 vnet_lisp_enable_disable (mp->is_enable);
329 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
333 vl_api_show_lisp_map_request_mode_t_handler
334 (vl_api_show_lisp_map_request_mode_t * mp)
337 vl_api_show_lisp_map_request_mode_reply_t *rmp;
340 REPLY_MACRO2(VL_API_SHOW_LISP_MAP_REQUEST_MODE_REPLY,
342 rmp->is_src_dst = vnet_lisp_get_map_request_mode ();
348 vl_api_lisp_map_request_mode_t_handler (vl_api_lisp_map_request_mode_t * mp)
350 vl_api_lisp_map_request_mode_reply_t *rmp;
353 rv = vnet_lisp_set_map_request_mode (mp->is_src_dst);
355 REPLY_MACRO (VL_API_LISP_MAP_REQUEST_MODE_REPLY);
359 vl_api_lisp_pitr_set_locator_set_t_handler (vl_api_lisp_pitr_set_locator_set_t
362 vl_api_lisp_pitr_set_locator_set_reply_t *rmp;
366 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
367 ls_name = format (0, "%s", mp->ls_name);
368 vec_terminate_c_string (ls_name);
369 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
372 REPLY_MACRO (VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY);
376 vl_api_lisp_use_petr_t_handler (vl_api_lisp_use_petr_t * mp)
378 vl_api_lisp_use_petr_reply_t *rmp;
382 ip_address_decode2 (&mp->ip_address, &addr);
383 rv = vnet_lisp_use_petr (&addr, mp->is_add);
385 REPLY_MACRO (VL_API_LISP_USE_PETR_REPLY);
389 vl_api_show_lisp_use_petr_t_handler (vl_api_show_lisp_use_petr_t * mp)
391 vl_api_show_lisp_use_petr_reply_t *rmp = NULL;
392 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
394 locator_set_t *ls = 0;
400 clib_memset (&addr, 0, sizeof (addr));
401 status = lcm->flags & LISP_FLAG_USE_PETR;
404 m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index);
405 if (~0 != m->locator_set_index)
408 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
409 loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]);
410 gid_address_copy (&addr, &loc->address);
415 REPLY_MACRO2 (VL_API_SHOW_LISP_USE_PETR_REPLY,
417 rmp->is_petr_enable = status;
418 ip_address_encode2 (&gid_address_ip (&addr), &rmp->ip_address);
424 vl_api_lisp_add_del_map_request_itr_rlocs_t_handler
425 (vl_api_lisp_add_del_map_request_itr_rlocs_t * mp)
427 vl_api_lisp_add_del_map_request_itr_rlocs_reply_t *rmp;
429 u8 *locator_set_name = NULL;
430 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
432 mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0;
433 locator_set_name = format (0, "%s", mp->locator_set_name);
434 vec_terminate_c_string (locator_set_name);
436 a->is_add = mp->is_add;
437 a->locator_set_name = locator_set_name;
439 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
441 vec_free (locator_set_name);
443 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
447 vl_api_lisp_add_del_remote_mapping_t_handler
448 (vl_api_lisp_add_del_remote_mapping_t * mp)
450 locator_t *rlocs = 0;
451 vl_api_lisp_add_del_remote_mapping_reply_t *rmp;
453 gid_address_t _eid, *eid = &_eid;
454 u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
456 clib_memset (eid, 0, sizeof (eid[0]));
458 rv = unformat_lisp_eid_api (eid, mp->vni, &mp->deid);
462 rlocs = unformat_lisp_locs (mp->rlocs, rloc_num);
466 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
467 clib_memset (a, 0, sizeof (*a));
468 gid_address_copy (&a->reid, eid);
470 rv = vnet_lisp_add_del_adjacency (a);
477 /* NOTE: for now this works as a static remote mapping, i.e.,
478 * not authoritative and ttl infinite. */
481 vnet_lisp_add_del_mapping_args_t _m_args, *m_args = &_m_args;
482 clib_memset (m_args, 0, sizeof (m_args[0]));
483 gid_address_copy (&m_args->eid, eid);
484 m_args->action = mp->action;
485 m_args->is_static = 1;
487 m_args->authoritative = 0;
488 rv = vnet_lisp_add_mapping (m_args, rlocs, NULL, NULL);
492 rv = vnet_lisp_del_mapping (eid, NULL);
496 vnet_lisp_clear_all_remote_adjacencies ();
501 REPLY_MACRO (VL_API_LISP_ADD_DEL_REMOTE_MAPPING_REPLY);
505 vl_api_lisp_add_del_adjacency_t_handler (vl_api_lisp_add_del_adjacency_t * mp)
507 vl_api_lisp_add_del_adjacency_reply_t *rmp;
508 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
511 clib_memset (a, 0, sizeof (a[0]));
513 rv = unformat_lisp_eid_api (&a->leid, mp->vni, &mp->leid);
514 rv = unformat_lisp_eid_api (&a->reid, mp->vni, &mp->reid);
519 a->is_add = mp->is_add;
520 rv = vnet_lisp_add_del_adjacency (a);
523 REPLY_MACRO (VL_API_LISP_ADD_DEL_ADJACENCY_REPLY);
527 send_lisp_locator_details (lisp_cp_main_t * lcm,
528 locator_t * loc, vl_api_registration_t * reg,
531 vl_api_lisp_locator_details_t *rmp;
533 rmp = vl_msg_api_alloc (sizeof (*rmp));
534 clib_memset (rmp, 0, sizeof (*rmp));
535 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_DETAILS);
536 rmp->context = context;
538 rmp->local = loc->local;
541 rmp->sw_if_index = ntohl (loc->sw_if_index);
545 ip_address_encode2 (&gid_address_ip (&loc->address), &rmp->ip_address);
547 rmp->priority = loc->priority;
548 rmp->weight = loc->weight;
550 vl_api_send_msg (reg, (u8 *) rmp);
554 vl_api_lisp_locator_dump_t_handler (vl_api_lisp_locator_dump_t * mp)
557 vl_api_registration_t *reg = 0;
558 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
559 locator_set_t *lsit = 0;
561 u32 ls_index = ~0, *locit = 0;
564 reg = vl_api_client_index_to_registration (mp->client_index);
568 if (mp->is_index_set)
569 ls_index = htonl (mp->ls_index);
572 /* make sure we get a proper C-string */
573 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
574 ls_name = format (0, "%s", mp->ls_name);
575 vec_terminate_c_string (ls_name);
576 p = hash_get_mem (lcm->locator_set_index_by_name, ls_name);
582 if (pool_is_free_index (lcm->locator_set_pool, ls_index))
585 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
587 vec_foreach (locit, lsit->locator_indices)
589 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
590 send_lisp_locator_details (lcm, loc, reg, mp->context);
597 send_lisp_locator_set_details (lisp_cp_main_t * lcm,
598 locator_set_t * lsit,
599 vl_api_registration_t * reg, u32 context,
602 vl_api_lisp_locator_set_details_t *rmp;
605 rmp = vl_msg_api_alloc (sizeof (*rmp));
606 clib_memset (rmp, 0, sizeof (*rmp));
607 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_SET_DETAILS);
608 rmp->context = context;
610 rmp->ls_index = htonl (ls_index);
613 ASSERT (lsit->name != NULL);
614 strncpy ((char *) rmp->ls_name, (char *) lsit->name,
615 vec_len (lsit->name));
619 str = format (0, "<remote-%d>", ls_index);
620 strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str));
624 vl_api_send_msg (reg, (u8 *) rmp);
628 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t * mp)
630 vl_api_registration_t *reg;
631 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
632 locator_set_t *lsit = NULL;
635 reg = vl_api_client_index_to_registration (mp->client_index);
641 pool_foreach (lsit, lcm->locator_set_pool,
643 if (filter && !((1 == filter && lsit->local) ||
644 (2 == filter && !lsit->local)))
648 send_lisp_locator_set_details (lcm, lsit, reg, mp->context,
649 lsit - lcm->locator_set_pool);
655 send_lisp_eid_table_details (mapping_t * mapit,
656 vl_api_registration_t * reg, u32 context,
659 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
660 locator_set_t *ls = 0;
661 vl_api_lisp_eid_table_details_t *rmp = NULL;
662 gid_address_t *gid = NULL;
666 case 0: /* all mappings */
669 case 1: /* local only */
673 case 2: /* remote only */
678 clib_warning ("Filter error, unknown filter: %d", filter);
682 /* don't send PITR generated mapping */
688 rmp = vl_msg_api_alloc (sizeof (*rmp));
689 clib_memset (rmp, 0, sizeof (*rmp));
690 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_DETAILS);
692 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
693 if (vec_len (ls->locator_indices) == 0)
694 rmp->locator_set_index = ~0;
696 rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
698 rmp->is_local = mapit->local;
699 rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
700 rmp->action = mapit->action;
701 rmp->authoritative = mapit->authoritative;
702 switch (gid_address_type (gid))
704 case GID_ADDR_SRC_DST:
705 lisp_fid_put_api (&rmp->seid, &gid_address_sd_src (gid));
706 lisp_fid_put_api (&rmp->deid, &gid_address_sd_dst (gid));
709 case GID_ADDR_IP_PREFIX:
710 lisp_gid_put_api (&rmp->seid, gid);
713 lisp_gid_put_api (&rmp->seid, gid);
718 rmp->context = context;
719 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
720 rmp->key.id = clib_host_to_net_u16 (mapit->key_id);
721 memcpy (rmp->key.key, mapit->key, vec_len (mapit->key));
722 vl_api_send_msg (reg, (u8 *) rmp);
726 vl_api_lisp_eid_table_dump_t_handler (vl_api_lisp_eid_table_dump_t * mp)
729 vl_api_registration_t *reg;
730 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
731 mapping_t *mapit = NULL;
732 gid_address_t _eid, *eid = &_eid;
734 reg = vl_api_client_index_to_registration (mp->client_index);
740 clib_memset (eid, 0, sizeof (*eid));
742 unformat_lisp_eid_api (eid, mp->vni, &mp->eid);
744 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
748 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
749 send_lisp_eid_table_details (mapit, reg, mp->context,
750 0 /* ignore filter */ );
755 pool_foreach (mapit, lcm->mapping_pool,
757 send_lisp_eid_table_details(mapit, reg, mp->context,
765 send_lisp_map_server_details (ip_address_t * ip, vl_api_registration_t * reg,
768 vl_api_lisp_map_server_details_t *rmp = NULL;
770 rmp = vl_msg_api_alloc (sizeof (*rmp));
771 clib_memset (rmp, 0, sizeof (*rmp));
772 rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_SERVER_DETAILS);
774 ip_address_encode2 (ip, &rmp->ip_address);
775 rmp->context = context;
777 vl_api_send_msg (reg, (u8 *) rmp);
781 vl_api_lisp_map_server_dump_t_handler (vl_api_lisp_map_server_dump_t * mp)
783 vl_api_registration_t *reg;
784 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
787 reg = vl_api_client_index_to_registration (mp->client_index);
791 vec_foreach (mr, lcm->map_servers)
793 send_lisp_map_server_details (&mr->address, reg, mp->context);
798 send_lisp_map_resolver_details (ip_address_t * ip,
799 vl_api_registration_t * reg, u32 context)
801 vl_api_lisp_map_resolver_details_t *rmp = NULL;
803 rmp = vl_msg_api_alloc (sizeof (*rmp));
804 clib_memset (rmp, 0, sizeof (*rmp));
805 rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_RESOLVER_DETAILS);
807 ip_address_encode2 (ip, &rmp->ip_address);
808 rmp->context = context;
810 vl_api_send_msg (reg, (u8 *) rmp);
814 vl_api_lisp_map_resolver_dump_t_handler (vl_api_lisp_map_resolver_dump_t * mp)
816 vl_api_registration_t *reg;
817 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
820 reg = vl_api_client_index_to_registration (mp->client_index);
824 vec_foreach (mr, lcm->map_resolvers)
826 send_lisp_map_resolver_details (&mr->address, reg, mp->context);
831 send_eid_table_map_pair (hash_pair_t * p, vl_api_registration_t * reg,
834 vl_api_lisp_eid_table_map_details_t *rmp = NULL;
836 rmp = vl_msg_api_alloc (sizeof (*rmp));
837 clib_memset (rmp, 0, sizeof (*rmp));
838 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_MAP_DETAILS);
840 rmp->vni = clib_host_to_net_u32 (p->key);
841 rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
842 rmp->context = context;
843 vl_api_send_msg (reg, (u8 *) rmp);
847 vl_api_lisp_eid_table_map_dump_t_handler (vl_api_lisp_eid_table_map_dump_t *
850 vl_api_registration_t *reg;
851 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
853 uword *vni_table = 0;
855 reg = vl_api_client_index_to_registration (mp->client_index);
861 vni_table = lcm->bd_id_by_vni;
865 vni_table = lcm->table_id_by_vni;
869 hash_foreach_pair (p, vni_table,
871 send_eid_table_map_pair (p, reg, mp->context);
877 send_eid_table_vni (u32 vni, vl_api_registration_t * reg, u32 context)
879 vl_api_lisp_eid_table_vni_details_t *rmp = 0;
881 rmp = vl_msg_api_alloc (sizeof (*rmp));
882 clib_memset (rmp, 0, sizeof (*rmp));
883 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_VNI_DETAILS);
884 rmp->context = context;
885 rmp->vni = clib_host_to_net_u32 (vni);
886 vl_api_send_msg (reg, (u8 *) rmp);
890 lisp_adjacency_copy (vl_api_lisp_adjacency_t * dst, lisp_adjacency_t * adjs)
892 lisp_adjacency_t *adj;
893 vl_api_lisp_adjacency_t a;
894 u32 i, n = vec_len (adjs);
896 for (i = 0; i < n; i++)
898 adj = vec_elt_at_index (adjs, i);
899 clib_memset (&a, 0, sizeof (a));
901 lisp_gid_put_api (&a.reid, &adj->reid);
902 lisp_gid_put_api (&a.leid, &adj->leid);
909 vl_api_show_lisp_rloc_probe_state_t_handler
910 (vl_api_show_lisp_rloc_probe_state_t * mp)
912 vl_api_show_lisp_rloc_probe_state_reply_t *rmp = 0;
916 REPLY_MACRO2 (VL_API_SHOW_LISP_RLOC_PROBE_STATE_REPLY,
918 rmp->is_enabled = vnet_lisp_rloc_probe_state_get ();
924 vl_api_show_lisp_map_register_state_t_handler
925 (vl_api_show_lisp_map_register_state_t * mp)
927 vl_api_show_lisp_map_register_state_reply_t *rmp = 0;
931 REPLY_MACRO2 (VL_API_SHOW_LISP_MAP_REGISTER_STATE_REPLY,
933 rmp->is_enabled = vnet_lisp_map_register_state_get ();
939 vl_api_lisp_adjacencies_get_t_handler (vl_api_lisp_adjacencies_get_t * mp)
941 vl_api_lisp_adjacencies_get_reply_t *rmp = 0;
942 lisp_adjacency_t *adjs = 0;
945 u32 vni = clib_net_to_host_u32 (mp->vni);
947 adjs = vnet_lisp_adjacencies_get_by_vni (vni);
948 size = vec_len (adjs) * sizeof (vl_api_lisp_adjacency_t);
951 REPLY_MACRO4 (VL_API_LISP_ADJACENCIES_GET_REPLY, size,
953 rmp->count = clib_host_to_net_u32 (vec_len (adjs));
954 lisp_adjacency_copy (rmp->adjacencies, adjs);
962 vl_api_lisp_eid_table_vni_dump_t_handler (vl_api_lisp_eid_table_vni_dump_t *
967 vl_api_registration_t *reg = 0;
968 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
970 reg = vl_api_client_index_to_registration (mp->client_index);
975 hash_foreach_pair (p, lcm->table_id_by_vni,
977 hash_set (vnis, p->key, 0);
980 hash_foreach_pair (p, lcm->bd_id_by_vni,
982 hash_set (vnis, p->key, 0);
985 hash_foreach_pair (p, vnis,
987 send_eid_table_vni (p->key, reg, mp->context);
995 vl_api_show_lisp_status_t_handler (vl_api_show_lisp_status_t * mp)
997 vl_api_show_lisp_status_reply_t *rmp = NULL;
1001 REPLY_MACRO2(VL_API_SHOW_LISP_STATUS_REPLY,
1003 rmp->is_gpe_enabled = vnet_lisp_gpe_enable_disable_status ();
1004 rmp->is_lisp_enabled = vnet_lisp_enable_disable_status ();
1010 vl_api_lisp_get_map_request_itr_rlocs_t_handler
1011 (vl_api_lisp_get_map_request_itr_rlocs_t * mp)
1013 vl_api_lisp_get_map_request_itr_rlocs_reply_t *rmp = NULL;
1014 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1015 locator_set_t *loc_set = 0;
1019 if (~0 == lcm->mreq_itr_rlocs)
1021 tmp_str = format (0, " ");
1026 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
1027 tmp_str = format (0, "%s", loc_set->name);
1031 REPLY_MACRO2(VL_API_LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
1033 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1034 ARRAY_LEN(rmp->locator_set_name) - 1);
1042 vl_api_show_lisp_pitr_t_handler (vl_api_show_lisp_pitr_t * mp)
1044 vl_api_show_lisp_pitr_reply_t *rmp = NULL;
1045 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1047 locator_set_t *ls = 0;
1051 u8 is_enabled = (lcm->flags & LISP_FLAG_PITR_MODE)
1052 && lcm->pitr_map_index != ~0;
1056 tmp_str = format (0, "N/A");
1060 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
1061 if (~0 != m->locator_set_index)
1064 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
1065 tmp_str = format (0, "%s", ls->name);
1069 tmp_str = format (0, "N/A");
1072 vec_add1 (tmp_str, 0);
1075 REPLY_MACRO2(VL_API_SHOW_LISP_PITR_REPLY,
1077 rmp->is_enabled = lcm->flags & LISP_FLAG_PITR_MODE;
1078 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1079 ARRAY_LEN(rmp->locator_set_name) - 1);
1086 * Add vpe's API message handlers to the table.
1087 * vlib has already mapped shared memory and
1088 * added the client registration handlers.
1089 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
1091 #define vl_msg_name_crc_list
1092 #include <vnet/vnet_all_api_h.h>
1093 #undef vl_msg_name_crc_list
1096 setup_message_id_table (api_main_t * am)
1098 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
1099 foreach_vl_msg_name_crc_lisp;
1103 static clib_error_t *
1104 lisp_api_hookup (vlib_main_t * vm)
1106 api_main_t *am = vlibapi_get_main ();
1109 vl_msg_api_set_handlers(VL_API_##N, #n, \
1110 vl_api_##n##_t_handler, \
1112 vl_api_##n##_t_endian, \
1113 vl_api_##n##_t_print, \
1114 sizeof(vl_api_##n##_t), 1);
1115 foreach_vpe_api_msg;
1119 * Set up the (msg_name, crc, message-id) table
1121 setup_message_id_table (am);
1126 VLIB_API_INIT_FUNCTION (lisp_api_hookup);
1129 * fd.io coding-style-patch-verification: ON
1132 * eval: (c-set-style "gnu")