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_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
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
40 #define vl_typedefs /* define message structures */
41 #include <vnet/vnet_all_api_h.h>
44 #define vl_endianfun /* define message structures */
45 #include <vnet/vnet_all_api_h.h>
48 /* instantiate all the print functions we know about */
49 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
51 #include <vnet/vnet_all_api_h.h>
54 #include <vlibapi/api_helper_macros.h>
56 #define foreach_vpe_api_msg \
57 _(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set) \
58 _(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator) \
59 _(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid) \
60 _(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver) \
61 _(LISP_ADD_DEL_MAP_SERVER, lisp_add_del_map_server) \
62 _(LISP_ENABLE_DISABLE, lisp_enable_disable) \
63 _(LISP_RLOC_PROBE_ENABLE_DISABLE, lisp_rloc_probe_enable_disable) \
64 _(LISP_MAP_REGISTER_ENABLE_DISABLE, lisp_map_register_enable_disable) \
65 _(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping) \
66 _(LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency) \
67 _(LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set) \
68 _(LISP_MAP_REQUEST_MODE, lisp_map_request_mode) \
69 _(LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map) \
70 _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \
71 _(LISP_LOCATOR_DUMP, lisp_locator_dump) \
72 _(LISP_EID_TABLE_DUMP, lisp_eid_table_dump) \
73 _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump) \
74 _(LISP_MAP_SERVER_DUMP, lisp_map_server_dump) \
75 _(LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump) \
76 _(LISP_EID_TABLE_VNI_DUMP, lisp_eid_table_vni_dump) \
77 _(LISP_ADJACENCIES_GET, lisp_adjacencies_get) \
78 _(SHOW_LISP_RLOC_PROBE_STATE, show_lisp_rloc_probe_state) \
79 _(SHOW_LISP_MAP_REGISTER_STATE, show_lisp_map_register_state) \
80 _(SHOW_LISP_STATUS, show_lisp_status) \
81 _(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \
82 lisp_add_del_map_request_itr_rlocs) \
83 _(LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs) \
84 _(SHOW_LISP_PITR, show_lisp_pitr) \
85 _(SHOW_LISP_MAP_REQUEST_MODE, show_lisp_map_request_mode) \
86 _(LISP_USE_PETR, lisp_use_petr) \
87 _(SHOW_LISP_USE_PETR, show_lisp_use_petr) \
90 unformat_lisp_locs (vl_api_remote_locator_t * rmt_locs, u32 rloc_num)
93 locator_t *locs = 0, loc;
94 vl_api_remote_locator_t *r;
96 for (i = 0; i < rloc_num; i++)
100 memset (&loc, 0, sizeof (loc));
101 gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
103 loc.priority = r->priority;
104 loc.weight = r->weight;
106 vec_add1 (locs, loc);
112 vl_api_lisp_add_del_locator_set_t_handler (vl_api_lisp_add_del_locator_set_t *
115 vl_api_lisp_add_del_locator_set_reply_t *rmp;
117 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
119 vl_api_local_locator_t *ls_loc;
120 u32 ls_index = ~0, locator_num;
121 u8 *locator_name = NULL;
124 memset (a, 0, sizeof (a[0]));
126 locator_name = format (0, "%s", mp->locator_set_name);
128 a->name = locator_name;
129 a->is_add = mp->is_add;
131 locator_num = clib_net_to_host_u32 (mp->locator_num);
133 memset (&locator, 0, sizeof (locator));
134 for (i = 0; i < locator_num; i++)
136 ls_loc = &mp->locators[i];
137 VALIDATE_SW_IF_INDEX (ls_loc);
139 locator.sw_if_index = htonl (ls_loc->sw_if_index);
140 locator.priority = ls_loc->priority;
141 locator.weight = ls_loc->weight;
143 vec_add1 (a->locators, locator);
146 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
148 BAD_SW_IF_INDEX_LABEL;
150 vec_free (locator_name);
151 vec_free (a->locators);
154 REPLY_MACRO2 (VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY,
156 rmp->ls_index = clib_host_to_net_u32 (ls_index);
162 vl_api_lisp_add_del_locator_t_handler (vl_api_lisp_add_del_locator_t * mp)
164 vl_api_lisp_add_del_locator_reply_t *rmp;
166 locator_t locator, *locators = NULL;
167 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
169 u8 *locator_name = NULL;
171 memset (&locator, 0, sizeof (locator));
172 memset (a, 0, sizeof (a[0]));
174 locator.sw_if_index = ntohl (mp->sw_if_index);
175 locator.priority = mp->priority;
176 locator.weight = mp->weight;
178 vec_add1 (locators, locator);
180 locator_name = format (0, "%s", mp->locator_set_name);
182 a->name = locator_name;
183 a->locators = locators;
184 a->is_add = mp->is_add;
187 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
190 vec_free (locator_name);
192 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
196 unformat_lisp_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
202 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
203 gid_address_ip_set (dst, src, IP4);
204 gid_address_ippref_len (dst) = len;
205 ip_prefix_normalize (&gid_address_ippref (dst));
208 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
209 gid_address_ip_set (dst, src, IP6);
210 gid_address_ippref_len (dst) = len;
211 ip_prefix_normalize (&gid_address_ippref (dst));
214 gid_address_type (dst) = GID_ADDR_MAC;
215 clib_memcpy (&gid_address_mac (dst), src, 6);
219 return VNET_API_ERROR_INVALID_VALUE;
222 gid_address_vni (dst) = vni;
228 vl_api_lisp_add_del_local_eid_t_handler (vl_api_lisp_add_del_local_eid_t * mp)
230 vl_api_lisp_add_del_local_eid_reply_t *rmp;
231 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
233 gid_address_t _eid, *eid = &_eid;
235 u32 locator_set_index = ~0, map_index = ~0;
236 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
237 u8 *name = NULL, *key = NULL;
238 memset (a, 0, sizeof (a[0]));
239 memset (eid, 0, sizeof (eid[0]));
241 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
242 mp->eid_type, mp->eid, mp->prefix_len);
246 name = format (0, "%s", mp->locator_set_name);
247 p = hash_get_mem (lcm->locator_set_index_by_name, name);
250 rv = VNET_API_ERROR_INVALID_VALUE;
253 locator_set_index = p[0];
256 key = format (0, "%s", mp->key);
258 /* XXX treat batch configuration */
259 a->is_add = mp->is_add;
260 gid_address_copy (&a->eid, eid);
261 a->locator_set_index = locator_set_index;
264 a->key_id = clib_net_to_host_u16 (mp->key_id);
266 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
271 gid_address_free (&a->eid);
273 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
277 vl_api_lisp_eid_table_add_del_map_t_handler
278 (vl_api_lisp_eid_table_add_del_map_t * mp)
280 vl_api_lisp_eid_table_add_del_map_reply_t *rmp;
282 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
283 clib_net_to_host_u32 (mp->dp_table),
284 mp->is_l2, mp->is_add);
285 REPLY_MACRO (VL_API_LISP_EID_TABLE_ADD_DEL_MAP_REPLY)}
288 vl_api_lisp_add_del_map_server_t_handler (vl_api_lisp_add_del_map_server_t
291 vl_api_lisp_add_del_map_server_reply_t *rmp;
295 memset (&addr, 0, sizeof (addr));
297 ip_address_set (&addr, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
298 rv = vnet_lisp_add_del_map_server (&addr, mp->is_add);
300 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_SERVER_REPLY);
304 vl_api_lisp_add_del_map_resolver_t_handler (vl_api_lisp_add_del_map_resolver_t
307 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
309 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
311 memset (a, 0, sizeof (a[0]));
313 a->is_add = mp->is_add;
314 ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
316 rv = vnet_lisp_add_del_map_resolver (a);
318 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
322 vl_api_lisp_map_register_enable_disable_t_handler
323 (vl_api_lisp_map_register_enable_disable_t * mp)
325 vl_api_lisp_map_register_enable_disable_reply_t *rmp;
328 vnet_lisp_map_register_enable_disable (mp->is_enabled);
329 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
333 vl_api_lisp_rloc_probe_enable_disable_t_handler
334 (vl_api_lisp_rloc_probe_enable_disable_t * mp)
336 vl_api_lisp_rloc_probe_enable_disable_reply_t *rmp;
339 vnet_lisp_rloc_probe_enable_disable (mp->is_enabled);
340 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
344 vl_api_lisp_enable_disable_t_handler (vl_api_lisp_enable_disable_t * mp)
346 vl_api_lisp_enable_disable_reply_t *rmp;
349 vnet_lisp_enable_disable (mp->is_en);
350 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
354 vl_api_show_lisp_map_request_mode_t_handler
355 (vl_api_show_lisp_map_request_mode_t * mp)
358 vl_api_show_lisp_map_request_mode_reply_t *rmp;
361 REPLY_MACRO2(VL_API_SHOW_LISP_MAP_REQUEST_MODE_REPLY,
363 rmp->mode = vnet_lisp_get_map_request_mode ();
369 vl_api_lisp_map_request_mode_t_handler (vl_api_lisp_map_request_mode_t * mp)
371 vl_api_lisp_map_request_mode_reply_t *rmp;
374 rv = vnet_lisp_set_map_request_mode (mp->mode);
376 REPLY_MACRO (VL_API_LISP_MAP_REQUEST_MODE_REPLY);
380 vl_api_lisp_pitr_set_locator_set_t_handler (vl_api_lisp_pitr_set_locator_set_t
383 vl_api_lisp_pitr_set_locator_set_reply_t *rmp;
387 ls_name = format (0, "%s", mp->ls_name);
388 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
391 REPLY_MACRO (VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY);
395 vl_api_lisp_use_petr_t_handler (vl_api_lisp_use_petr_t * mp)
397 vl_api_lisp_use_petr_reply_t *rmp;
401 ip_address_set (&addr, &mp->address, mp->is_ip4 ? IP4 : IP6);
402 rv = vnet_lisp_use_petr (&addr, mp->is_add);
404 REPLY_MACRO (VL_API_LISP_USE_PETR_REPLY);
408 vl_api_show_lisp_use_petr_t_handler (vl_api_show_lisp_use_petr_t * mp)
410 unix_shared_memory_queue_t *q = NULL;
411 vl_api_show_lisp_use_petr_reply_t *rmp = NULL;
412 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
414 locator_set_t *ls = 0;
420 q = vl_api_client_index_to_input_queue (mp->client_index);
426 memset (&addr, 0, sizeof (addr));
427 status = lcm->flags & LISP_FLAG_USE_PETR;
430 m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index);
431 if (~0 != m->locator_set_index)
434 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
435 loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]);
436 gid_address_copy (&addr, &loc->address);
441 REPLY_MACRO2 (VL_API_SHOW_LISP_USE_PETR_REPLY,
443 rmp->status = status;
444 gid_address_put (rmp->address, &addr);
445 rmp->is_ip4 = (gid_address_ip_version (&addr) == IP4);
451 vl_api_lisp_add_del_map_request_itr_rlocs_t_handler
452 (vl_api_lisp_add_del_map_request_itr_rlocs_t * mp)
454 vl_api_lisp_add_del_map_request_itr_rlocs_reply_t *rmp;
456 u8 *locator_set_name = NULL;
457 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
459 locator_set_name = format (0, "%s", mp->locator_set_name);
461 a->is_add = mp->is_add;
462 a->locator_set_name = locator_set_name;
464 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
466 vec_free (locator_set_name);
468 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
472 vl_api_lisp_add_del_remote_mapping_t_handler
473 (vl_api_lisp_add_del_remote_mapping_t * mp)
475 locator_t *rlocs = 0;
476 vl_api_lisp_add_del_remote_mapping_reply_t *rmp;
478 gid_address_t _eid, *eid = &_eid;
479 u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
481 memset (eid, 0, sizeof (eid[0]));
483 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
484 mp->eid_type, mp->eid, mp->eid_len);
488 rlocs = unformat_lisp_locs (mp->rlocs, rloc_num);
492 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
493 gid_address_copy (&a->reid, eid);
495 rv = vnet_lisp_add_del_adjacency (a);
502 /* NOTE: for now this works as a static remote mapping, i.e.,
503 * not authoritative and ttl infinite. */
504 rv = vnet_lisp_add_del_mapping (eid, rlocs, mp->action, 0, ~0,
505 mp->is_add, 1 /* is_static */ , 0);
508 vnet_lisp_clear_all_remote_adjacencies ();
513 REPLY_MACRO (VL_API_LISP_ADD_DEL_REMOTE_MAPPING_REPLY);
517 vl_api_lisp_add_del_adjacency_t_handler (vl_api_lisp_add_del_adjacency_t * mp)
519 vl_api_lisp_add_del_adjacency_reply_t *rmp;
520 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
523 memset (a, 0, sizeof (a[0]));
525 rv = unformat_lisp_eid_api (&a->leid, clib_net_to_host_u32 (mp->vni),
526 mp->eid_type, mp->leid, mp->leid_len);
527 rv |= unformat_lisp_eid_api (&a->reid, clib_net_to_host_u32 (mp->vni),
528 mp->eid_type, mp->reid, mp->reid_len);
533 a->is_add = mp->is_add;
534 rv = vnet_lisp_add_del_adjacency (a);
537 REPLY_MACRO (VL_API_LISP_ADD_DEL_ADJACENCY_REPLY);
541 send_lisp_locator_details (lisp_cp_main_t * lcm,
543 unix_shared_memory_queue_t * q, u32 context)
545 vl_api_lisp_locator_details_t *rmp;
547 rmp = vl_msg_api_alloc (sizeof (*rmp));
548 memset (rmp, 0, sizeof (*rmp));
549 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_DETAILS);
550 rmp->context = context;
552 rmp->local = loc->local;
555 rmp->sw_if_index = ntohl (loc->sw_if_index);
559 rmp->is_ipv6 = gid_address_ip_version (&loc->address);
560 ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
562 rmp->priority = loc->priority;
563 rmp->weight = loc->weight;
565 vl_msg_api_send_shmem (q, (u8 *) & rmp);
569 vl_api_lisp_locator_dump_t_handler (vl_api_lisp_locator_dump_t * mp)
572 unix_shared_memory_queue_t *q = 0;
573 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
574 locator_set_t *lsit = 0;
576 u32 ls_index = ~0, *locit = 0;
579 q = vl_api_client_index_to_input_queue (mp->client_index);
585 if (mp->is_index_set)
586 ls_index = htonl (mp->ls_index);
589 /* make sure we get a proper C-string */
590 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
591 ls_name = format (0, "%s", mp->ls_name);
592 p = hash_get_mem (lcm->locator_set_index_by_name, ls_name);
598 if (pool_is_free_index (lcm->locator_set_pool, ls_index))
601 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
603 vec_foreach (locit, lsit->locator_indices)
605 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
606 send_lisp_locator_details (lcm, loc, q, mp->context);
613 send_lisp_locator_set_details (lisp_cp_main_t * lcm,
614 locator_set_t * lsit,
615 unix_shared_memory_queue_t * q,
616 u32 context, u32 ls_index)
618 vl_api_lisp_locator_set_details_t *rmp;
621 rmp = vl_msg_api_alloc (sizeof (*rmp));
622 memset (rmp, 0, sizeof (*rmp));
623 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_SET_DETAILS);
624 rmp->context = context;
626 rmp->ls_index = htonl (ls_index);
629 ASSERT (lsit->name != NULL);
630 strncpy ((char *) rmp->ls_name, (char *) lsit->name,
631 vec_len (lsit->name));
635 str = format (0, "<remote-%d>", ls_index);
636 strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str));
640 vl_msg_api_send_shmem (q, (u8 *) & rmp);
644 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t * mp)
646 unix_shared_memory_queue_t *q = NULL;
647 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
648 locator_set_t *lsit = NULL;
651 q = vl_api_client_index_to_input_queue (mp->client_index);
659 pool_foreach (lsit, lcm->locator_set_pool,
661 if (filter && !((1 == filter && lsit->local) ||
662 (2 == filter && !lsit->local)))
666 send_lisp_locator_set_details (lcm, lsit, q, mp->context,
667 lsit - lcm->locator_set_pool);
673 lisp_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length)
675 ASSERT (prefix_length);
676 ip_prefix_t *ippref = &fid_addr_ippref (src);
678 switch (fid_addr_type (src))
680 case FID_ADDR_IP_PREF:
681 if (ip_prefix_version (ippref) == IP4)
682 clib_memcpy (dst, &ip_prefix_v4 (ippref), 4);
684 clib_memcpy (dst, &ip_prefix_v6 (ippref), 16);
685 prefix_length[0] = ip_prefix_len (ippref);
689 prefix_length[0] = 0;
690 clib_memcpy (dst, fid_addr_mac (src), 6);
694 clib_warning ("Unknown FID type %d!", fid_addr_type (src));
700 fid_type_to_api_type (fid_address_t * fid)
704 switch (fid_addr_type (fid))
706 case FID_ADDR_IP_PREF:
707 ippref = &fid_addr_ippref (fid);
708 if (ip_prefix_version (ippref) == IP4)
710 else if (ip_prefix_version (ippref) == IP6)
725 send_lisp_eid_table_details (mapping_t * mapit,
726 unix_shared_memory_queue_t * q,
727 u32 context, u8 filter)
730 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
731 locator_set_t *ls = 0;
732 vl_api_lisp_eid_table_details_t *rmp = NULL;
733 gid_address_t *gid = NULL;
735 ip_prefix_t *ip_prefix = NULL;
739 case 0: /* all mappings */
742 case 1: /* local only */
746 case 2: /* remote only */
751 clib_warning ("Filter error, unknown filter: %d", filter);
756 ip_prefix = &gid_address_ippref (gid);
757 mac = gid_address_mac (gid);
759 rmp = vl_msg_api_alloc (sizeof (*rmp));
760 memset (rmp, 0, sizeof (*rmp));
761 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_DETAILS);
763 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
764 if (vec_len (ls->locator_indices) == 0)
765 rmp->locator_set_index = ~0;
767 rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
769 rmp->is_local = mapit->local;
770 rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
771 rmp->action = mapit->action;
772 rmp->authoritative = mapit->authoritative;
774 switch (gid_address_type (gid))
776 case GID_ADDR_SRC_DST:
778 fid = &gid_address_sd_src (gid);
779 rmp->eid_type = fid_type_to_api_type (fid);
780 lisp_fid_put_api (rmp->seid, &gid_address_sd_src (gid),
781 &rmp->seid_prefix_len);
782 lisp_fid_put_api (rmp->eid, &gid_address_sd_dst (gid),
783 &rmp->eid_prefix_len);
785 case GID_ADDR_IP_PREFIX:
786 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
787 if (ip_prefix_version (ip_prefix) == IP4)
789 rmp->eid_type = 0; /* ipv4 type */
790 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
791 sizeof (ip_prefix_v4 (ip_prefix)));
795 rmp->eid_type = 1; /* ipv6 type */
796 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
797 sizeof (ip_prefix_v6 (ip_prefix)));
801 rmp->eid_type = 2; /* l2 mac type */
802 clib_memcpy (rmp->eid, mac, 6);
807 rmp->context = context;
808 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
809 rmp->key_id = clib_host_to_net_u16 (mapit->key_id);
810 memcpy (rmp->key, mapit->key, vec_len (mapit->key));
811 vl_msg_api_send_shmem (q, (u8 *) & rmp);
815 vl_api_lisp_eid_table_dump_t_handler (vl_api_lisp_eid_table_dump_t * mp)
818 unix_shared_memory_queue_t *q = NULL;
819 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
820 mapping_t *mapit = NULL;
821 gid_address_t _eid, *eid = &_eid;
823 q = vl_api_client_index_to_input_queue (mp->client_index);
831 memset (eid, 0, sizeof (*eid));
833 unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
834 mp->eid_type, mp->eid, mp->prefix_length);
836 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
840 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
841 send_lisp_eid_table_details (mapit, q, mp->context,
842 0 /* ignore filter */ );
847 pool_foreach (mapit, lcm->mapping_pool,
849 send_lisp_eid_table_details(mapit, q, mp->context,
857 send_lisp_map_server_details (ip_address_t * ip,
858 unix_shared_memory_queue_t * q, u32 context)
860 vl_api_lisp_map_server_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_SERVER_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_server_dump_t_handler (vl_api_lisp_map_server_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_servers)
903 send_lisp_map_server_details (&mr->address, q, mp->context);
908 send_lisp_map_resolver_details (ip_address_t * ip,
909 unix_shared_memory_queue_t * q, u32 context)
911 vl_api_lisp_map_resolver_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_MAP_RESOLVER_DETAILS);
917 switch (ip_addr_version (ip))
921 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
922 sizeof (ip_addr_v4 (ip)));
927 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
928 sizeof (ip_addr_v6 (ip)));
934 rmp->context = context;
936 vl_msg_api_send_shmem (q, (u8 *) & rmp);
940 vl_api_lisp_map_resolver_dump_t_handler (vl_api_lisp_map_resolver_dump_t * mp)
942 unix_shared_memory_queue_t *q = NULL;
943 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
946 q = vl_api_client_index_to_input_queue (mp->client_index);
952 vec_foreach (mr, lcm->map_resolvers)
954 send_lisp_map_resolver_details (&mr->address, q, mp->context);
959 send_eid_table_map_pair (hash_pair_t * p,
960 unix_shared_memory_queue_t * q, u32 context)
962 vl_api_lisp_eid_table_map_details_t *rmp = NULL;
964 rmp = vl_msg_api_alloc (sizeof (*rmp));
965 memset (rmp, 0, sizeof (*rmp));
966 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_MAP_DETAILS);
968 rmp->vni = clib_host_to_net_u32 (p->key);
969 rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
970 rmp->context = context;
971 vl_msg_api_send_shmem (q, (u8 *) & rmp);
975 vl_api_lisp_eid_table_map_dump_t_handler (vl_api_lisp_eid_table_map_dump_t *
978 unix_shared_memory_queue_t *q = NULL;
979 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
981 uword *vni_table = 0;
983 q = vl_api_client_index_to_input_queue (mp->client_index);
991 vni_table = lcm->bd_id_by_vni;
995 vni_table = lcm->table_id_by_vni;
999 hash_foreach_pair (p, vni_table,
1001 send_eid_table_map_pair (p, q, mp->context);
1007 send_eid_table_vni (u32 vni, unix_shared_memory_queue_t * q, u32 context)
1009 vl_api_lisp_eid_table_vni_details_t *rmp = 0;
1011 rmp = vl_msg_api_alloc (sizeof (*rmp));
1012 memset (rmp, 0, sizeof (*rmp));
1013 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_VNI_DETAILS);
1014 rmp->context = context;
1015 rmp->vni = clib_host_to_net_u32 (vni);
1016 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1020 lisp_adjacency_copy (vl_api_lisp_adjacency_t * dst, lisp_adjacency_t * adjs)
1022 lisp_adjacency_t *adj;
1023 vl_api_lisp_adjacency_t a;
1024 u32 i, n = vec_len (adjs);
1026 for (i = 0; i < n; i++)
1028 adj = vec_elt_at_index (adjs, i);
1029 memset (&a, 0, sizeof (a));
1031 switch (gid_address_type (&adj->reid))
1033 case GID_ADDR_IP_PREFIX:
1034 a.reid_prefix_len = gid_address_ippref_len (&adj->reid);
1035 a.leid_prefix_len = gid_address_ippref_len (&adj->leid);
1036 if (gid_address_ip_version (&adj->reid) == IP4)
1038 a.eid_type = 0; /* ipv4 type */
1039 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 4);
1040 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 4);
1044 a.eid_type = 1; /* ipv6 type */
1045 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 16);
1046 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 16);
1050 a.eid_type = 2; /* l2 mac type */
1051 mac_copy (a.reid, gid_address_mac (&adj->reid));
1052 mac_copy (a.leid, gid_address_mac (&adj->leid));
1062 vl_api_show_lisp_rloc_probe_state_t_handler
1063 (vl_api_show_lisp_rloc_probe_state_t * mp)
1065 vl_api_show_lisp_rloc_probe_state_reply_t *rmp = 0;
1069 REPLY_MACRO2 (VL_API_SHOW_LISP_RLOC_PROBE_STATE_REPLY,
1071 rmp->is_enabled = vnet_lisp_rloc_probe_state_get ();
1077 vl_api_show_lisp_map_register_state_t_handler
1078 (vl_api_show_lisp_map_register_state_t * mp)
1080 vl_api_show_lisp_map_register_state_reply_t *rmp = 0;
1084 REPLY_MACRO2 (VL_API_SHOW_LISP_MAP_REGISTER_STATE_REPLY,
1086 rmp->is_enabled = vnet_lisp_map_register_state_get ();
1092 vl_api_lisp_adjacencies_get_t_handler (vl_api_lisp_adjacencies_get_t * mp)
1094 vl_api_lisp_adjacencies_get_reply_t *rmp = 0;
1095 lisp_adjacency_t *adjs = 0;
1098 u32 vni = clib_net_to_host_u32 (mp->vni);
1100 adjs = vnet_lisp_adjacencies_get_by_vni (vni);
1101 size = vec_len (adjs) * sizeof (vl_api_lisp_adjacency_t);
1104 REPLY_MACRO4 (VL_API_LISP_ADJACENCIES_GET_REPLY, size,
1106 rmp->count = clib_host_to_net_u32 (vec_len (adjs));
1107 lisp_adjacency_copy (rmp->adjacencies, adjs);
1115 vl_api_lisp_eid_table_vni_dump_t_handler (vl_api_lisp_eid_table_vni_dump_t *
1120 unix_shared_memory_queue_t *q = 0;
1121 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1123 q = vl_api_client_index_to_input_queue (mp->client_index);
1130 hash_foreach_pair (p, lcm->table_id_by_vni,
1132 hash_set (vnis, p->key, 0);
1135 hash_foreach_pair (p, lcm->bd_id_by_vni,
1137 hash_set (vnis, p->key, 0);
1140 hash_foreach_pair (p, vnis,
1142 send_eid_table_vni (p->key, q, mp->context);
1150 vl_api_show_lisp_status_t_handler (vl_api_show_lisp_status_t * mp)
1152 unix_shared_memory_queue_t *q = NULL;
1153 vl_api_show_lisp_status_reply_t *rmp = NULL;
1156 q = vl_api_client_index_to_input_queue (mp->client_index);
1163 REPLY_MACRO2(VL_API_SHOW_LISP_STATUS_REPLY,
1165 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
1166 rmp->feature_status = vnet_lisp_enable_disable_status ();
1172 vl_api_lisp_get_map_request_itr_rlocs_t_handler
1173 (vl_api_lisp_get_map_request_itr_rlocs_t * mp)
1175 unix_shared_memory_queue_t *q = NULL;
1176 vl_api_lisp_get_map_request_itr_rlocs_reply_t *rmp = NULL;
1177 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1178 locator_set_t *loc_set = 0;
1182 q = vl_api_client_index_to_input_queue (mp->client_index);
1188 if (~0 == lcm->mreq_itr_rlocs)
1190 tmp_str = format (0, " ");
1195 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
1196 tmp_str = format (0, "%s", loc_set->name);
1200 REPLY_MACRO2(VL_API_LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
1202 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1203 ARRAY_LEN(rmp->locator_set_name) - 1);
1211 vl_api_show_lisp_pitr_t_handler (vl_api_show_lisp_pitr_t * mp)
1213 unix_shared_memory_queue_t *q = NULL;
1214 vl_api_show_lisp_pitr_reply_t *rmp = NULL;
1215 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1217 locator_set_t *ls = 0;
1221 q = vl_api_client_index_to_input_queue (mp->client_index);
1227 if (!lcm->lisp_pitr)
1229 tmp_str = format (0, "N/A");
1233 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
1234 if (~0 != m->locator_set_index)
1237 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
1238 tmp_str = format (0, "%s", ls->name);
1242 tmp_str = format (0, "N/A");
1245 vec_add1 (tmp_str, 0);
1248 REPLY_MACRO2(VL_API_SHOW_LISP_PITR_REPLY,
1250 rmp->status = lcm->lisp_pitr;
1251 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1252 ARRAY_LEN(rmp->locator_set_name) - 1);
1259 * Add vpe's API message handlers to the table.
1260 * vlib has alread mapped shared memory and
1261 * added the client registration handlers.
1262 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
1264 #define vl_msg_name_crc_list
1265 #include <vnet/vnet_all_api_h.h>
1266 #undef vl_msg_name_crc_list
1269 setup_message_id_table (api_main_t * am)
1271 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
1272 foreach_vl_msg_name_crc_lisp;
1276 static clib_error_t *
1277 lisp_api_hookup (vlib_main_t * vm)
1279 api_main_t *am = &api_main;
1282 vl_msg_api_set_handlers(VL_API_##N, #n, \
1283 vl_api_##n##_t_handler, \
1285 vl_api_##n##_t_endian, \
1286 vl_api_##n##_t_print, \
1287 sizeof(vl_api_##n##_t), 1);
1288 foreach_vpe_api_msg;
1292 * Set up the (msg_name, crc, message-id) table
1294 setup_message_id_table (am);
1299 VLIB_API_INIT_FUNCTION (lisp_api_hookup);
1302 * fd.io coding-style-patch-verification: ON
1305 * eval: (c-set-style "gnu")