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>
28 #include <vnet/vnet_msg_enum.h>
30 #define vl_typedefs /* define message structures */
31 #include <vnet/vnet_all_api_h.h>
34 #define vl_endianfun /* define message structures */
35 #include <vnet/vnet_all_api_h.h>
38 /* instantiate all the print functions we know about */
39 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
41 #include <vnet/vnet_all_api_h.h>
44 #include <vlibapi/api_helper_macros.h>
46 #define foreach_vpe_api_msg \
47 _(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set) \
48 _(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator) \
49 _(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid) \
50 _(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver) \
51 _(LISP_ADD_DEL_MAP_SERVER, lisp_add_del_map_server) \
52 _(LISP_ENABLE_DISABLE, lisp_enable_disable) \
53 _(LISP_RLOC_PROBE_ENABLE_DISABLE, lisp_rloc_probe_enable_disable) \
54 _(LISP_MAP_REGISTER_ENABLE_DISABLE, lisp_map_register_enable_disable) \
55 _(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping) \
56 _(LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency) \
57 _(LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set) \
58 _(LISP_MAP_REQUEST_MODE, lisp_map_request_mode) \
59 _(LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map) \
60 _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \
61 _(LISP_LOCATOR_DUMP, lisp_locator_dump) \
62 _(LISP_EID_TABLE_DUMP, lisp_eid_table_dump) \
63 _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump) \
64 _(LISP_MAP_SERVER_DUMP, lisp_map_server_dump) \
65 _(LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump) \
66 _(LISP_EID_TABLE_VNI_DUMP, lisp_eid_table_vni_dump) \
67 _(LISP_ADJACENCIES_GET, lisp_adjacencies_get) \
68 _(SHOW_LISP_RLOC_PROBE_STATE, show_lisp_rloc_probe_state) \
69 _(SHOW_LISP_MAP_REGISTER_STATE, show_lisp_map_register_state) \
70 _(SHOW_LISP_STATUS, show_lisp_status) \
71 _(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \
72 lisp_add_del_map_request_itr_rlocs) \
73 _(LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs) \
74 _(SHOW_LISP_PITR, show_lisp_pitr) \
75 _(SHOW_LISP_MAP_REQUEST_MODE, show_lisp_map_request_mode) \
77 /** Used for transferring locators via VPP API */
79 typedef CLIB_PACKED (struct {
80 u8 is_ip4; /**< is locator an IPv4 address */
81 u8 priority; /**< locator priority */
82 u8 weight; /**< locator weight */
83 u8 addr[16]; /**< IPv4/IPv6 address */
87 /** Used for transferring locators via VPP API */
89 typedef CLIB_PACKED (struct {
90 u32 sw_if_index; /**< locator sw_if_index */
91 u8 priority; /**< locator priority */
92 u8 weight; /**< locator weight */
97 unformat_lisp_locs (void *rmt_locs, u32 rloc_num)
100 locator_t *locs = 0, loc;
103 for (i = 0; i < rloc_num; i++)
105 /* remote locators */
106 r = &((rloc_t *) rmt_locs)[i];
107 memset (&loc, 0, sizeof (loc));
108 gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
110 loc.priority = r->priority;
111 loc.weight = r->weight;
113 vec_add1 (locs, loc);
119 vl_api_lisp_add_del_locator_set_t_handler (vl_api_lisp_add_del_locator_set_t *
122 vl_api_lisp_add_del_locator_set_reply_t *rmp;
124 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
126 ls_locator_t *ls_loc;
127 u32 ls_index = ~0, locator_num;
128 u8 *locator_name = NULL;
131 memset (a, 0, sizeof (a[0]));
133 locator_name = format (0, "%s", mp->locator_set_name);
135 a->name = locator_name;
136 a->is_add = mp->is_add;
138 locator_num = clib_net_to_host_u32 (mp->locator_num);
140 memset (&locator, 0, sizeof (locator));
141 for (i = 0; i < locator_num; i++)
143 ls_loc = &((ls_locator_t *) mp->locators)[i];
144 VALIDATE_SW_IF_INDEX (ls_loc);
146 locator.sw_if_index = htonl (ls_loc->sw_if_index);
147 locator.priority = ls_loc->priority;
148 locator.weight = ls_loc->weight;
150 vec_add1 (a->locators, locator);
153 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
155 BAD_SW_IF_INDEX_LABEL;
157 vec_free (locator_name);
158 vec_free (a->locators);
161 REPLY_MACRO2 (VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY,
163 rmp->ls_index = clib_host_to_net_u32 (ls_index);
169 vl_api_lisp_add_del_locator_t_handler (vl_api_lisp_add_del_locator_t * mp)
171 vl_api_lisp_add_del_locator_reply_t *rmp;
173 locator_t locator, *locators = NULL;
174 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
176 u8 *locator_name = NULL;
178 memset (&locator, 0, sizeof (locator));
179 memset (a, 0, sizeof (a[0]));
181 locator.sw_if_index = ntohl (mp->sw_if_index);
182 locator.priority = mp->priority;
183 locator.weight = mp->weight;
185 vec_add1 (locators, locator);
187 locator_name = format (0, "%s", mp->locator_set_name);
189 a->name = locator_name;
190 a->locators = locators;
191 a->is_add = mp->is_add;
194 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
197 vec_free (locator_name);
199 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
203 unformat_lisp_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
209 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
210 gid_address_ip_set (dst, src, IP4);
211 gid_address_ippref_len (dst) = len;
212 ip_prefix_normalize (&gid_address_ippref (dst));
215 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
216 gid_address_ip_set (dst, src, IP6);
217 gid_address_ippref_len (dst) = len;
218 ip_prefix_normalize (&gid_address_ippref (dst));
221 gid_address_type (dst) = GID_ADDR_MAC;
222 clib_memcpy (&gid_address_mac (dst), src, 6);
226 return VNET_API_ERROR_INVALID_VALUE;
229 gid_address_vni (dst) = vni;
235 vl_api_lisp_add_del_local_eid_t_handler (vl_api_lisp_add_del_local_eid_t * mp)
237 vl_api_lisp_add_del_local_eid_reply_t *rmp;
238 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
240 gid_address_t _eid, *eid = &_eid;
242 u32 locator_set_index = ~0, map_index = ~0;
243 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
244 u8 *name = NULL, *key = NULL;
245 memset (a, 0, sizeof (a[0]));
246 memset (eid, 0, sizeof (eid[0]));
248 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
249 mp->eid_type, mp->eid, mp->prefix_len);
253 name = format (0, "%s", mp->locator_set_name);
254 p = hash_get_mem (lcm->locator_set_index_by_name, name);
257 rv = VNET_API_ERROR_INVALID_VALUE;
260 locator_set_index = p[0];
263 key = format (0, "%s", mp->key);
265 /* XXX treat batch configuration */
266 a->is_add = mp->is_add;
267 gid_address_copy (&a->eid, eid);
268 a->locator_set_index = locator_set_index;
271 a->key_id = clib_net_to_host_u16 (mp->key_id);
273 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
278 gid_address_free (&a->eid);
280 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
284 vl_api_lisp_eid_table_add_del_map_t_handler
285 (vl_api_lisp_eid_table_add_del_map_t * mp)
287 vl_api_lisp_eid_table_add_del_map_reply_t *rmp;
289 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
290 clib_net_to_host_u32 (mp->dp_table),
291 mp->is_l2, mp->is_add);
292 REPLY_MACRO (VL_API_LISP_EID_TABLE_ADD_DEL_MAP_REPLY)}
295 vl_api_lisp_add_del_map_server_t_handler (vl_api_lisp_add_del_map_server_t
298 vl_api_lisp_add_del_map_server_reply_t *rmp;
302 memset (&addr, 0, sizeof (addr));
304 ip_address_set (&addr, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
305 rv = vnet_lisp_add_del_map_server (&addr, mp->is_add);
307 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_SERVER_REPLY);
311 vl_api_lisp_add_del_map_resolver_t_handler (vl_api_lisp_add_del_map_resolver_t
314 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
316 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
318 memset (a, 0, sizeof (a[0]));
320 a->is_add = mp->is_add;
321 ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
323 rv = vnet_lisp_add_del_map_resolver (a);
325 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
329 vl_api_lisp_map_register_enable_disable_t_handler
330 (vl_api_lisp_map_register_enable_disable_t * mp)
332 vl_api_lisp_map_register_enable_disable_reply_t *rmp;
335 vnet_lisp_map_register_enable_disable (mp->is_enabled);
336 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
340 vl_api_lisp_rloc_probe_enable_disable_t_handler
341 (vl_api_lisp_rloc_probe_enable_disable_t * mp)
343 vl_api_lisp_rloc_probe_enable_disable_reply_t *rmp;
346 vnet_lisp_rloc_probe_enable_disable (mp->is_enabled);
347 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
351 vl_api_lisp_enable_disable_t_handler (vl_api_lisp_enable_disable_t * mp)
353 vl_api_lisp_enable_disable_reply_t *rmp;
356 vnet_lisp_enable_disable (mp->is_en);
357 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
361 vl_api_show_lisp_map_request_mode_t_handler
362 (vl_api_show_lisp_map_request_mode_t * mp)
365 vl_api_show_lisp_map_request_mode_reply_t *rmp;
368 REPLY_MACRO2(VL_API_SHOW_LISP_MAP_REQUEST_MODE_REPLY,
370 rmp->mode = vnet_lisp_get_map_request_mode ();
376 vl_api_lisp_map_request_mode_t_handler (vl_api_lisp_map_request_mode_t * mp)
378 vl_api_lisp_map_request_mode_reply_t *rmp;
381 rv = vnet_lisp_set_map_request_mode (mp->mode);
383 REPLY_MACRO (VL_API_LISP_MAP_REQUEST_MODE_REPLY);
387 vl_api_lisp_pitr_set_locator_set_t_handler (vl_api_lisp_pitr_set_locator_set_t
390 vl_api_lisp_pitr_set_locator_set_reply_t *rmp;
394 ls_name = format (0, "%s", mp->ls_name);
395 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
398 REPLY_MACRO (VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY);
402 vl_api_lisp_add_del_map_request_itr_rlocs_t_handler
403 (vl_api_lisp_add_del_map_request_itr_rlocs_t * mp)
405 vl_api_lisp_add_del_map_request_itr_rlocs_reply_t *rmp;
407 u8 *locator_set_name = NULL;
408 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
410 locator_set_name = format (0, "%s", mp->locator_set_name);
412 a->is_add = mp->is_add;
413 a->locator_set_name = locator_set_name;
415 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
417 vec_free (locator_set_name);
419 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
423 vl_api_lisp_add_del_remote_mapping_t_handler
424 (vl_api_lisp_add_del_remote_mapping_t * mp)
426 locator_t *rlocs = 0;
427 vl_api_lisp_add_del_remote_mapping_reply_t *rmp;
429 gid_address_t _eid, *eid = &_eid;
430 u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
432 memset (eid, 0, sizeof (eid[0]));
434 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
435 mp->eid_type, mp->eid, mp->eid_len);
439 rlocs = unformat_lisp_locs (mp->rlocs, rloc_num);
443 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
444 gid_address_copy (&a->reid, eid);
446 rv = vnet_lisp_add_del_adjacency (a);
453 /* NOTE: for now this works as a static remote mapping, i.e.,
454 * not authoritative and ttl infinite. */
455 rv = vnet_lisp_add_del_mapping (eid, rlocs, mp->action, 0, ~0,
456 mp->is_add, 1 /* is_static */ , 0);
459 vnet_lisp_clear_all_remote_adjacencies ();
464 REPLY_MACRO (VL_API_LISP_ADD_DEL_REMOTE_MAPPING_REPLY);
468 vl_api_lisp_add_del_adjacency_t_handler (vl_api_lisp_add_del_adjacency_t * mp)
470 vl_api_lisp_add_del_adjacency_reply_t *rmp;
471 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
474 memset (a, 0, sizeof (a[0]));
476 rv = unformat_lisp_eid_api (&a->leid, clib_net_to_host_u32 (mp->vni),
477 mp->eid_type, mp->leid, mp->leid_len);
478 rv |= unformat_lisp_eid_api (&a->reid, clib_net_to_host_u32 (mp->vni),
479 mp->eid_type, mp->reid, mp->reid_len);
484 a->is_add = mp->is_add;
485 rv = vnet_lisp_add_del_adjacency (a);
488 REPLY_MACRO (VL_API_LISP_ADD_DEL_ADJACENCY_REPLY);
492 send_lisp_locator_details (lisp_cp_main_t * lcm,
494 unix_shared_memory_queue_t * q, u32 context)
496 vl_api_lisp_locator_details_t *rmp;
498 rmp = vl_msg_api_alloc (sizeof (*rmp));
499 memset (rmp, 0, sizeof (*rmp));
500 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_DETAILS);
501 rmp->context = context;
503 rmp->local = loc->local;
506 rmp->sw_if_index = ntohl (loc->sw_if_index);
510 rmp->is_ipv6 = gid_address_ip_version (&loc->address);
511 ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
513 rmp->priority = loc->priority;
514 rmp->weight = loc->weight;
516 vl_msg_api_send_shmem (q, (u8 *) & rmp);
520 vl_api_lisp_locator_dump_t_handler (vl_api_lisp_locator_dump_t * mp)
523 unix_shared_memory_queue_t *q = 0;
524 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
525 locator_set_t *lsit = 0;
527 u32 ls_index = ~0, *locit = 0;
530 q = vl_api_client_index_to_input_queue (mp->client_index);
536 if (mp->is_index_set)
537 ls_index = htonl (mp->ls_index);
540 /* make sure we get a proper C-string */
541 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
542 ls_name = format (0, "%s", mp->ls_name);
543 p = hash_get_mem (lcm->locator_set_index_by_name, ls_name);
549 if (pool_is_free_index (lcm->locator_set_pool, ls_index))
552 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
554 vec_foreach (locit, lsit->locator_indices)
556 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
557 send_lisp_locator_details (lcm, loc, q, mp->context);
564 send_lisp_locator_set_details (lisp_cp_main_t * lcm,
565 locator_set_t * lsit,
566 unix_shared_memory_queue_t * q,
567 u32 context, u32 ls_index)
569 vl_api_lisp_locator_set_details_t *rmp;
572 rmp = vl_msg_api_alloc (sizeof (*rmp));
573 memset (rmp, 0, sizeof (*rmp));
574 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_SET_DETAILS);
575 rmp->context = context;
577 rmp->ls_index = htonl (ls_index);
580 ASSERT (lsit->name != NULL);
581 strncpy ((char *) rmp->ls_name, (char *) lsit->name,
582 vec_len (lsit->name));
586 str = format (0, "<remote-%d>", ls_index);
587 strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str));
591 vl_msg_api_send_shmem (q, (u8 *) & rmp);
595 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t * mp)
597 unix_shared_memory_queue_t *q = NULL;
598 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
599 locator_set_t *lsit = NULL;
602 q = vl_api_client_index_to_input_queue (mp->client_index);
610 pool_foreach (lsit, lcm->locator_set_pool,
612 if (filter && !((1 == filter && lsit->local) ||
613 (2 == filter && !lsit->local)))
617 send_lisp_locator_set_details (lcm, lsit, q, mp->context,
618 lsit - lcm->locator_set_pool);
624 lisp_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length)
626 ASSERT (prefix_length);
627 ip_prefix_t *ippref = &fid_addr_ippref (src);
629 switch (fid_addr_type (src))
631 case FID_ADDR_IP_PREF:
632 if (ip_prefix_version (ippref) == IP4)
633 clib_memcpy (dst, &ip_prefix_v4 (ippref), 4);
635 clib_memcpy (dst, &ip_prefix_v6 (ippref), 16);
636 prefix_length[0] = ip_prefix_len (ippref);
640 prefix_length[0] = 0;
641 clib_memcpy (dst, fid_addr_mac (src), 6);
645 clib_warning ("Unknown FID type %d!", fid_addr_type (src));
651 fid_type_to_api_type (fid_address_t * fid)
655 switch (fid_addr_type (fid))
657 case FID_ADDR_IP_PREF:
658 ippref = &fid_addr_ippref (fid);
659 if (ip_prefix_version (ippref) == IP4)
661 else if (ip_prefix_version (ippref) == IP6)
674 send_lisp_eid_table_details (mapping_t * mapit,
675 unix_shared_memory_queue_t * q,
676 u32 context, u8 filter)
679 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
680 locator_set_t *ls = 0;
681 vl_api_lisp_eid_table_details_t *rmp = NULL;
682 gid_address_t *gid = NULL;
684 ip_prefix_t *ip_prefix = NULL;
688 case 0: /* all mappings */
691 case 1: /* local only */
695 case 2: /* remote only */
700 clib_warning ("Filter error, unknown filter: %d", filter);
705 ip_prefix = &gid_address_ippref (gid);
706 mac = gid_address_mac (gid);
708 rmp = vl_msg_api_alloc (sizeof (*rmp));
709 memset (rmp, 0, sizeof (*rmp));
710 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_DETAILS);
712 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
713 if (vec_len (ls->locator_indices) == 0)
714 rmp->locator_set_index = ~0;
716 rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
718 rmp->is_local = mapit->local;
719 rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
720 rmp->action = mapit->action;
721 rmp->authoritative = mapit->authoritative;
723 switch (gid_address_type (gid))
725 case GID_ADDR_SRC_DST:
727 fid = &gid_address_sd_src (gid);
728 rmp->eid_type = fid_type_to_api_type (fid);
729 lisp_fid_put_api (rmp->seid, &gid_address_sd_src (gid),
730 &rmp->seid_prefix_len);
731 lisp_fid_put_api (rmp->eid, &gid_address_sd_dst (gid),
732 &rmp->eid_prefix_len);
734 case GID_ADDR_IP_PREFIX:
735 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
736 if (ip_prefix_version (ip_prefix) == IP4)
738 rmp->eid_type = 0; /* ipv4 type */
739 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
740 sizeof (ip_prefix_v4 (ip_prefix)));
744 rmp->eid_type = 1; /* ipv6 type */
745 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
746 sizeof (ip_prefix_v6 (ip_prefix)));
750 rmp->eid_type = 2; /* l2 mac type */
751 clib_memcpy (rmp->eid, mac, 6);
756 rmp->context = context;
757 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
758 rmp->key_id = clib_host_to_net_u16 (mapit->key_id);
759 memcpy (rmp->key, mapit->key, vec_len (mapit->key));
760 vl_msg_api_send_shmem (q, (u8 *) & rmp);
764 vl_api_lisp_eid_table_dump_t_handler (vl_api_lisp_eid_table_dump_t * mp)
767 unix_shared_memory_queue_t *q = NULL;
768 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
769 mapping_t *mapit = NULL;
770 gid_address_t _eid, *eid = &_eid;
772 q = vl_api_client_index_to_input_queue (mp->client_index);
780 memset (eid, 0, sizeof (*eid));
782 unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
783 mp->eid_type, mp->eid, mp->prefix_length);
785 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
789 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
790 send_lisp_eid_table_details (mapit, q, mp->context,
791 0 /* ignore filter */ );
796 pool_foreach (mapit, lcm->mapping_pool,
798 send_lisp_eid_table_details(mapit, q, mp->context,
806 send_lisp_map_server_details (ip_address_t * ip,
807 unix_shared_memory_queue_t * q, u32 context)
809 vl_api_lisp_map_server_details_t *rmp = NULL;
811 rmp = vl_msg_api_alloc (sizeof (*rmp));
812 memset (rmp, 0, sizeof (*rmp));
813 rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_SERVER_DETAILS);
815 switch (ip_addr_version (ip))
819 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
820 sizeof (ip_addr_v4 (ip)));
825 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
826 sizeof (ip_addr_v6 (ip)));
832 rmp->context = context;
834 vl_msg_api_send_shmem (q, (u8 *) & rmp);
838 vl_api_lisp_map_server_dump_t_handler (vl_api_lisp_map_server_dump_t * mp)
840 unix_shared_memory_queue_t *q = NULL;
841 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
844 q = vl_api_client_index_to_input_queue (mp->client_index);
850 vec_foreach (mr, lcm->map_servers)
852 send_lisp_map_server_details (&mr->address, q, mp->context);
857 send_lisp_map_resolver_details (ip_address_t * ip,
858 unix_shared_memory_queue_t * q, u32 context)
860 vl_api_lisp_map_resolver_details_t *rmp = NULL;
862 rmp = vl_msg_api_alloc (sizeof (*rmp));
863 memset (rmp, 0, sizeof (*rmp));
864 rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_RESOLVER_DETAILS);
866 switch (ip_addr_version (ip))
870 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
871 sizeof (ip_addr_v4 (ip)));
876 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
877 sizeof (ip_addr_v6 (ip)));
883 rmp->context = context;
885 vl_msg_api_send_shmem (q, (u8 *) & rmp);
889 vl_api_lisp_map_resolver_dump_t_handler (vl_api_lisp_map_resolver_dump_t * mp)
891 unix_shared_memory_queue_t *q = NULL;
892 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
895 q = vl_api_client_index_to_input_queue (mp->client_index);
901 vec_foreach (mr, lcm->map_resolvers)
903 send_lisp_map_resolver_details (&mr->address, q, mp->context);
908 send_eid_table_map_pair (hash_pair_t * p,
909 unix_shared_memory_queue_t * q, u32 context)
911 vl_api_lisp_eid_table_map_details_t *rmp = NULL;
913 rmp = vl_msg_api_alloc (sizeof (*rmp));
914 memset (rmp, 0, sizeof (*rmp));
915 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_MAP_DETAILS);
917 rmp->vni = clib_host_to_net_u32 (p->key);
918 rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
919 rmp->context = context;
920 vl_msg_api_send_shmem (q, (u8 *) & rmp);
924 vl_api_lisp_eid_table_map_dump_t_handler (vl_api_lisp_eid_table_map_dump_t *
927 unix_shared_memory_queue_t *q = NULL;
928 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
930 uword *vni_table = 0;
932 q = vl_api_client_index_to_input_queue (mp->client_index);
940 vni_table = lcm->bd_id_by_vni;
944 vni_table = lcm->table_id_by_vni;
948 hash_foreach_pair (p, vni_table,
950 send_eid_table_map_pair (p, q, mp->context);
956 send_eid_table_vni (u32 vni, unix_shared_memory_queue_t * q, u32 context)
958 vl_api_lisp_eid_table_vni_details_t *rmp = 0;
960 rmp = vl_msg_api_alloc (sizeof (*rmp));
961 memset (rmp, 0, sizeof (*rmp));
962 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_VNI_DETAILS);
963 rmp->context = context;
964 rmp->vni = clib_host_to_net_u32 (vni);
965 vl_msg_api_send_shmem (q, (u8 *) & rmp);
969 lisp_adjacency_copy (vl_api_lisp_adjacency_t * dst, lisp_adjacency_t * adjs)
971 lisp_adjacency_t *adj;
972 vl_api_lisp_adjacency_t a;
973 u32 i, n = vec_len (adjs);
975 for (i = 0; i < n; i++)
977 adj = vec_elt_at_index (adjs, i);
978 memset (&a, 0, sizeof (a));
980 switch (gid_address_type (&adj->reid))
982 case GID_ADDR_IP_PREFIX:
983 a.reid_prefix_len = gid_address_ippref_len (&adj->reid);
984 a.leid_prefix_len = gid_address_ippref_len (&adj->leid);
985 if (gid_address_ip_version (&adj->reid) == IP4)
987 a.eid_type = 0; /* ipv4 type */
988 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 4);
989 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 4);
993 a.eid_type = 1; /* ipv6 type */
994 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 16);
995 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 16);
999 a.eid_type = 2; /* l2 mac type */
1000 mac_copy (a.reid, gid_address_mac (&adj->reid));
1001 mac_copy (a.leid, gid_address_mac (&adj->leid));
1011 vl_api_show_lisp_rloc_probe_state_t_handler
1012 (vl_api_show_lisp_rloc_probe_state_t * mp)
1014 vl_api_show_lisp_rloc_probe_state_reply_t *rmp = 0;
1018 REPLY_MACRO2 (VL_API_SHOW_LISP_RLOC_PROBE_STATE_REPLY,
1020 rmp->is_enabled = vnet_lisp_rloc_probe_state_get ();
1026 vl_api_show_lisp_map_register_state_t_handler
1027 (vl_api_show_lisp_map_register_state_t * mp)
1029 vl_api_show_lisp_map_register_state_reply_t *rmp = 0;
1033 REPLY_MACRO2 (VL_API_SHOW_LISP_MAP_REGISTER_STATE_REPLY,
1035 rmp->is_enabled = vnet_lisp_map_register_state_get ();
1041 vl_api_lisp_adjacencies_get_t_handler (vl_api_lisp_adjacencies_get_t * mp)
1043 vl_api_lisp_adjacencies_get_reply_t *rmp = 0;
1044 lisp_adjacency_t *adjs = 0;
1046 vl_api_lisp_adjacency_t a;
1048 u32 vni = clib_net_to_host_u32 (mp->vni);
1050 adjs = vnet_lisp_adjacencies_get_by_vni (vni);
1051 size = vec_len (adjs) * sizeof (a);
1054 REPLY_MACRO4 (VL_API_LISP_ADJACENCIES_GET_REPLY, size,
1056 rmp->count = clib_host_to_net_u32 (vec_len (adjs));
1057 lisp_adjacency_copy (rmp->adjacencies, adjs);
1065 vl_api_lisp_eid_table_vni_dump_t_handler (vl_api_lisp_eid_table_vni_dump_t *
1070 unix_shared_memory_queue_t *q = 0;
1071 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1073 q = vl_api_client_index_to_input_queue (mp->client_index);
1080 hash_foreach_pair (p, lcm->table_id_by_vni,
1082 hash_set (vnis, p->key, 0);
1085 hash_foreach_pair (p, lcm->bd_id_by_vni,
1087 hash_set (vnis, p->key, 0);
1090 hash_foreach_pair (p, vnis,
1092 send_eid_table_vni (p->key, q, mp->context);
1100 vl_api_show_lisp_status_t_handler (vl_api_show_lisp_status_t * mp)
1102 unix_shared_memory_queue_t *q = NULL;
1103 vl_api_show_lisp_status_reply_t *rmp = NULL;
1106 q = vl_api_client_index_to_input_queue (mp->client_index);
1113 REPLY_MACRO2(VL_API_SHOW_LISP_STATUS_REPLY,
1115 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
1116 rmp->feature_status = vnet_lisp_enable_disable_status ();
1122 vl_api_lisp_get_map_request_itr_rlocs_t_handler
1123 (vl_api_lisp_get_map_request_itr_rlocs_t * mp)
1125 unix_shared_memory_queue_t *q = NULL;
1126 vl_api_lisp_get_map_request_itr_rlocs_reply_t *rmp = NULL;
1127 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1128 locator_set_t *loc_set = 0;
1132 q = vl_api_client_index_to_input_queue (mp->client_index);
1138 if (~0 == lcm->mreq_itr_rlocs)
1140 tmp_str = format (0, " ");
1145 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
1146 tmp_str = format (0, "%s", loc_set->name);
1150 REPLY_MACRO2(VL_API_LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
1152 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1153 ARRAY_LEN(rmp->locator_set_name) - 1);
1161 vl_api_show_lisp_pitr_t_handler (vl_api_show_lisp_pitr_t * mp)
1163 unix_shared_memory_queue_t *q = NULL;
1164 vl_api_show_lisp_pitr_reply_t *rmp = NULL;
1165 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1167 locator_set_t *ls = 0;
1171 q = vl_api_client_index_to_input_queue (mp->client_index);
1177 if (!lcm->lisp_pitr)
1179 tmp_str = format (0, "N/A");
1183 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
1184 if (~0 != m->locator_set_index)
1187 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
1188 tmp_str = format (0, "%s", ls->name);
1192 tmp_str = format (0, "N/A");
1195 vec_add1 (tmp_str, 0);
1198 REPLY_MACRO2(VL_API_SHOW_LISP_PITR_REPLY,
1200 rmp->status = lcm->lisp_pitr;
1201 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1202 ARRAY_LEN(rmp->locator_set_name) - 1);
1209 * Add vpe's API message handlers to the table.
1210 * vlib has alread mapped shared memory and
1211 * added the client registration handlers.
1212 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
1214 #define vl_msg_name_crc_list
1215 #include <vnet/vnet_all_api_h.h>
1216 #undef vl_msg_name_crc_list
1219 setup_message_id_table (api_main_t * am)
1221 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
1222 foreach_vl_msg_name_crc_lisp;
1226 static clib_error_t *
1227 lisp_api_hookup (vlib_main_t * vm)
1229 api_main_t *am = &api_main;
1232 vl_msg_api_set_handlers(VL_API_##N, #n, \
1233 vl_api_##n##_t_handler, \
1235 vl_api_##n##_t_endian, \
1236 vl_api_##n##_t_print, \
1237 sizeof(vl_api_##n##_t), 1);
1238 foreach_vpe_api_msg;
1242 * Set up the (msg_name, crc, message-id) table
1244 setup_message_id_table (am);
1249 VLIB_API_INIT_FUNCTION (lisp_api_hookup);
1252 * fd.io coding-style-patch-verification: ON
1255 * eval: (c-set-style "gnu")