2 *------------------------------------------------------------------
3 * one_api.c - Overlay Network Engine API
5 * Copyright (c) 2016-2017 Cisco and/or its affiliates.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
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_one_remote_locator_t_endian vl_noop_handler
31 #define vl_api_one_remote_locator_t_print vl_noop_handler
32 #define vl_api_one_local_locator_t_endian vl_noop_handler
33 #define vl_api_one_local_locator_t_print vl_noop_handler
35 #define vl_api_one_add_del_locator_set_t_endian vl_noop_handler
36 #define vl_api_one_add_del_locator_set_t_print vl_noop_handler
37 #define vl_api_one_add_del_remote_mapping_t_endian vl_noop_handler
38 #define vl_api_one_add_del_remote_mapping_t_print vl_noop_handler
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
45 #define vl_typedefs /* define message structures */
46 #include <vnet/vnet_all_api_h.h>
49 #define vl_endianfun /* define message structures */
50 #include <vnet/vnet_all_api_h.h>
53 /* instantiate all the print functions we know about */
54 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
56 #include <vnet/vnet_all_api_h.h>
59 #include <vlibapi/api_helper_macros.h>
61 #define foreach_vpe_api_msg \
62 _(ONE_ADD_DEL_LOCATOR_SET, one_add_del_locator_set) \
63 _(ONE_ADD_DEL_LOCATOR, one_add_del_locator) \
64 _(ONE_ADD_DEL_LOCAL_EID, one_add_del_local_eid) \
65 _(ONE_ADD_DEL_MAP_RESOLVER, one_add_del_map_resolver) \
66 _(ONE_ADD_DEL_MAP_SERVER, one_add_del_map_server) \
67 _(ONE_ENABLE_DISABLE, one_enable_disable) \
68 _(ONE_RLOC_PROBE_ENABLE_DISABLE, one_rloc_probe_enable_disable) \
69 _(ONE_MAP_REGISTER_ENABLE_DISABLE, one_map_register_enable_disable) \
70 _(ONE_ADD_DEL_REMOTE_MAPPING, one_add_del_remote_mapping) \
71 _(ONE_ADD_DEL_ADJACENCY, one_add_del_adjacency) \
72 _(ONE_PITR_SET_LOCATOR_SET, one_pitr_set_locator_set) \
73 _(ONE_MAP_REQUEST_MODE, one_map_request_mode) \
74 _(ONE_EID_TABLE_ADD_DEL_MAP, one_eid_table_add_del_map) \
75 _(ONE_LOCATOR_SET_DUMP, one_locator_set_dump) \
76 _(ONE_LOCATOR_DUMP, one_locator_dump) \
77 _(ONE_EID_TABLE_DUMP, one_eid_table_dump) \
78 _(ONE_MAP_RESOLVER_DUMP, one_map_resolver_dump) \
79 _(ONE_MAP_SERVER_DUMP, one_map_server_dump) \
80 _(ONE_EID_TABLE_MAP_DUMP, one_eid_table_map_dump) \
81 _(ONE_EID_TABLE_VNI_DUMP, one_eid_table_vni_dump) \
82 _(ONE_ADJACENCIES_GET, one_adjacencies_get) \
83 _(SHOW_ONE_RLOC_PROBE_STATE, show_one_rloc_probe_state) \
84 _(SHOW_ONE_MAP_REGISTER_STATE, show_one_map_register_state) \
85 _(SHOW_ONE_STATUS, show_one_status) \
86 _(ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \
87 one_add_del_map_request_itr_rlocs) \
88 _(ONE_GET_MAP_REQUEST_ITR_RLOCS, one_get_map_request_itr_rlocs) \
89 _(SHOW_ONE_PITR, show_one_pitr) \
90 _(SHOW_ONE_MAP_REQUEST_MODE, show_one_map_request_mode) \
91 _(ONE_USE_PETR, one_use_petr) \
92 _(SHOW_ONE_USE_PETR, show_one_use_petr) \
93 _(SHOW_ONE_STATS_ENABLE_DISABLE, show_one_stats_enable_disable) \
94 _(ONE_STATS_ENABLE_DISABLE, one_stats_enable_disable) \
95 _(ONE_STATS_DUMP, one_stats_dump) \
99 unformat_one_locs (vl_api_one_remote_locator_t * rmt_locs, u32 rloc_num)
102 locator_t *locs = 0, loc;
103 vl_api_one_remote_locator_t *r;
105 for (i = 0; i < rloc_num; i++)
107 /* remote locators */
109 memset (&loc, 0, sizeof (loc));
110 gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
112 loc.priority = r->priority;
113 loc.weight = r->weight;
115 vec_add1 (locs, loc);
121 vl_api_one_add_del_locator_set_t_handler (vl_api_one_add_del_locator_set_t *
124 vl_api_one_add_del_locator_set_reply_t *rmp;
126 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
128 vl_api_one_local_locator_t *ls_loc;
129 u32 ls_index = ~0, locator_num;
130 u8 *locator_name = NULL;
133 memset (a, 0, sizeof (a[0]));
135 locator_name = format (0, "%s", mp->locator_set_name);
137 a->name = locator_name;
138 a->is_add = mp->is_add;
140 locator_num = clib_net_to_host_u32 (mp->locator_num);
142 memset (&locator, 0, sizeof (locator));
143 for (i = 0; i < locator_num; i++)
145 ls_loc = &mp->locators[i];
146 VALIDATE_SW_IF_INDEX (ls_loc);
148 locator.sw_if_index = htonl (ls_loc->sw_if_index);
149 locator.priority = ls_loc->priority;
150 locator.weight = ls_loc->weight;
152 vec_add1 (a->locators, locator);
155 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
157 BAD_SW_IF_INDEX_LABEL;
159 vec_free (locator_name);
160 vec_free (a->locators);
163 REPLY_MACRO2 (VL_API_ONE_ADD_DEL_LOCATOR_SET_REPLY,
165 rmp->ls_index = clib_host_to_net_u32 (ls_index);
171 vl_api_one_add_del_locator_t_handler (vl_api_one_add_del_locator_t * mp)
173 vl_api_one_add_del_locator_reply_t *rmp;
175 locator_t locator, *locators = NULL;
176 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
178 u8 *locator_name = NULL;
180 memset (&locator, 0, sizeof (locator));
181 memset (a, 0, sizeof (a[0]));
183 locator.sw_if_index = ntohl (mp->sw_if_index);
184 locator.priority = mp->priority;
185 locator.weight = mp->weight;
187 vec_add1 (locators, locator);
189 locator_name = format (0, "%s", mp->locator_set_name);
191 a->name = locator_name;
192 a->locators = locators;
193 a->is_add = mp->is_add;
196 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
199 vec_free (locator_name);
201 REPLY_MACRO (VL_API_ONE_ADD_DEL_LOCATOR_REPLY);
205 unformat_one_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
211 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
212 gid_address_ip_set (dst, src, IP4);
213 gid_address_ippref_len (dst) = len;
214 ip_prefix_normalize (&gid_address_ippref (dst));
217 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
218 gid_address_ip_set (dst, src, IP6);
219 gid_address_ippref_len (dst) = len;
220 ip_prefix_normalize (&gid_address_ippref (dst));
223 gid_address_type (dst) = GID_ADDR_MAC;
224 clib_memcpy (&gid_address_mac (dst), src, 6);
228 return VNET_API_ERROR_INVALID_VALUE;
231 gid_address_vni (dst) = vni;
237 vl_api_one_add_del_local_eid_t_handler (vl_api_one_add_del_local_eid_t * mp)
239 vl_api_one_add_del_local_eid_reply_t *rmp;
240 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
242 gid_address_t _eid, *eid = &_eid;
244 u32 locator_set_index = ~0, map_index = ~0;
245 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
246 u8 *name = NULL, *key = NULL;
247 memset (a, 0, sizeof (a[0]));
248 memset (eid, 0, sizeof (eid[0]));
250 rv = unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
251 mp->eid_type, mp->eid, mp->prefix_len);
255 name = format (0, "%s", mp->locator_set_name);
256 p = hash_get_mem (lcm->locator_set_index_by_name, name);
259 rv = VNET_API_ERROR_INVALID_VALUE;
262 locator_set_index = p[0];
265 key = format (0, "%s", mp->key);
267 /* XXX treat batch configuration */
268 a->is_add = mp->is_add;
269 gid_address_copy (&a->eid, eid);
270 a->locator_set_index = locator_set_index;
273 a->key_id = clib_net_to_host_u16 (mp->key_id);
275 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
280 gid_address_free (&a->eid);
282 REPLY_MACRO (VL_API_ONE_ADD_DEL_LOCAL_EID_REPLY);
286 vl_api_one_eid_table_add_del_map_t_handler
287 (vl_api_one_eid_table_add_del_map_t * mp)
289 vl_api_one_eid_table_add_del_map_reply_t *rmp;
291 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
292 clib_net_to_host_u32 (mp->dp_table),
293 mp->is_l2, mp->is_add);
294 REPLY_MACRO (VL_API_ONE_EID_TABLE_ADD_DEL_MAP_REPLY)}
297 vl_api_one_add_del_map_server_t_handler (vl_api_one_add_del_map_server_t * mp)
299 vl_api_one_add_del_map_server_reply_t *rmp;
303 memset (&addr, 0, sizeof (addr));
305 ip_address_set (&addr, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
306 rv = vnet_lisp_add_del_map_server (&addr, mp->is_add);
308 REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_SERVER_REPLY);
312 vl_api_one_add_del_map_resolver_t_handler (vl_api_one_add_del_map_resolver_t
315 vl_api_one_add_del_map_resolver_reply_t *rmp;
317 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
319 memset (a, 0, sizeof (a[0]));
321 a->is_add = mp->is_add;
322 ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
324 rv = vnet_lisp_add_del_map_resolver (a);
326 REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_RESOLVER_REPLY);
330 vl_api_one_map_register_enable_disable_t_handler
331 (vl_api_one_map_register_enable_disable_t * mp)
333 vl_api_one_map_register_enable_disable_reply_t *rmp;
336 vnet_lisp_map_register_enable_disable (mp->is_enabled);
337 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
341 vl_api_one_rloc_probe_enable_disable_t_handler
342 (vl_api_one_rloc_probe_enable_disable_t * mp)
344 vl_api_one_rloc_probe_enable_disable_reply_t *rmp;
347 vnet_lisp_rloc_probe_enable_disable (mp->is_enabled);
348 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
352 vl_api_one_enable_disable_t_handler (vl_api_one_enable_disable_t * mp)
354 vl_api_one_enable_disable_reply_t *rmp;
357 vnet_lisp_enable_disable (mp->is_en);
358 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
362 vl_api_show_one_map_request_mode_t_handler
363 (vl_api_show_one_map_request_mode_t * mp)
366 vl_api_show_one_map_request_mode_reply_t *rmp;
369 REPLY_MACRO2(VL_API_SHOW_ONE_MAP_REQUEST_MODE_REPLY,
371 rmp->mode = vnet_lisp_get_map_request_mode ();
377 vl_api_one_map_request_mode_t_handler (vl_api_one_map_request_mode_t * mp)
379 vl_api_one_map_request_mode_reply_t *rmp;
382 rv = vnet_lisp_set_map_request_mode (mp->mode);
384 REPLY_MACRO (VL_API_ONE_MAP_REQUEST_MODE_REPLY);
388 vl_api_one_pitr_set_locator_set_t_handler (vl_api_one_pitr_set_locator_set_t
391 vl_api_one_pitr_set_locator_set_reply_t *rmp;
395 ls_name = format (0, "%s", mp->ls_name);
396 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
399 REPLY_MACRO (VL_API_ONE_PITR_SET_LOCATOR_SET_REPLY);
403 vl_api_one_use_petr_t_handler (vl_api_one_use_petr_t * mp)
405 vl_api_one_use_petr_reply_t *rmp;
409 ip_address_set (&addr, &mp->address, mp->is_ip4 ? IP4 : IP6);
410 rv = vnet_lisp_use_petr (&addr, mp->is_add);
412 REPLY_MACRO (VL_API_ONE_USE_PETR_REPLY);
416 vl_api_show_one_use_petr_t_handler (vl_api_show_one_use_petr_t * mp)
418 unix_shared_memory_queue_t *q = NULL;
419 vl_api_show_one_use_petr_reply_t *rmp = NULL;
420 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
422 locator_set_t *ls = 0;
428 q = vl_api_client_index_to_input_queue (mp->client_index);
434 memset (&addr, 0, sizeof (addr));
435 status = lcm->flags & LISP_FLAG_USE_PETR;
438 m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index);
439 if (~0 != m->locator_set_index)
442 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
443 loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]);
444 gid_address_copy (&addr, &loc->address);
449 REPLY_MACRO2 (VL_API_SHOW_ONE_USE_PETR_REPLY,
451 rmp->status = status;
452 ip_address_t *ip = &gid_address_ip (&addr);
453 switch (ip_addr_version (ip))
456 clib_memcpy (rmp->address, &ip_addr_v4 (ip),
457 sizeof (ip_addr_v4 (ip)));
461 clib_memcpy (rmp->address, &ip_addr_v6 (ip),
462 sizeof (ip_addr_v6 (ip)));
468 rmp->is_ip4 = (gid_address_ip_version (&addr) == IP4);
474 vl_api_one_add_del_map_request_itr_rlocs_t_handler
475 (vl_api_one_add_del_map_request_itr_rlocs_t * mp)
477 vl_api_one_add_del_map_request_itr_rlocs_reply_t *rmp;
479 u8 *locator_set_name = NULL;
480 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
482 locator_set_name = format (0, "%s", mp->locator_set_name);
484 a->is_add = mp->is_add;
485 a->locator_set_name = locator_set_name;
487 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
489 vec_free (locator_set_name);
491 REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
495 vl_api_one_add_del_remote_mapping_t_handler
496 (vl_api_one_add_del_remote_mapping_t * mp)
498 locator_t *rlocs = 0;
499 vl_api_one_add_del_remote_mapping_reply_t *rmp;
501 gid_address_t _eid, *eid = &_eid;
502 u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
504 memset (eid, 0, sizeof (eid[0]));
506 rv = unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
507 mp->eid_type, mp->eid, mp->eid_len);
511 rlocs = unformat_one_locs (mp->rlocs, rloc_num);
515 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
516 gid_address_copy (&a->reid, eid);
518 rv = vnet_lisp_add_del_adjacency (a);
525 /* NOTE: for now this works as a static remote mapping, i.e.,
526 * not authoritative and ttl infinite. */
527 rv = vnet_lisp_add_del_mapping (eid, rlocs, mp->action, 0, ~0,
528 mp->is_add, 1 /* is_static */ , 0);
531 vnet_lisp_clear_all_remote_adjacencies ();
536 REPLY_MACRO (VL_API_ONE_ADD_DEL_REMOTE_MAPPING_REPLY);
540 vl_api_one_add_del_adjacency_t_handler (vl_api_one_add_del_adjacency_t * mp)
542 vl_api_one_add_del_adjacency_reply_t *rmp;
543 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
546 memset (a, 0, sizeof (a[0]));
548 rv = unformat_one_eid_api (&a->leid, clib_net_to_host_u32 (mp->vni),
549 mp->eid_type, mp->leid, mp->leid_len);
550 rv |= unformat_one_eid_api (&a->reid, clib_net_to_host_u32 (mp->vni),
551 mp->eid_type, mp->reid, mp->reid_len);
556 a->is_add = mp->is_add;
557 rv = vnet_lisp_add_del_adjacency (a);
560 REPLY_MACRO (VL_API_ONE_ADD_DEL_ADJACENCY_REPLY);
564 send_one_locator_details (lisp_cp_main_t * lcm,
566 unix_shared_memory_queue_t * q, u32 context)
568 vl_api_one_locator_details_t *rmp;
570 rmp = vl_msg_api_alloc (sizeof (*rmp));
571 memset (rmp, 0, sizeof (*rmp));
572 rmp->_vl_msg_id = ntohs (VL_API_ONE_LOCATOR_DETAILS);
573 rmp->context = context;
575 rmp->local = loc->local;
578 rmp->sw_if_index = ntohl (loc->sw_if_index);
582 rmp->is_ipv6 = gid_address_ip_version (&loc->address);
583 ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
585 rmp->priority = loc->priority;
586 rmp->weight = loc->weight;
588 vl_msg_api_send_shmem (q, (u8 *) & rmp);
592 vl_api_one_locator_dump_t_handler (vl_api_one_locator_dump_t * mp)
595 unix_shared_memory_queue_t *q = 0;
596 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
597 locator_set_t *lsit = 0;
599 u32 ls_index = ~0, *locit = 0;
602 q = vl_api_client_index_to_input_queue (mp->client_index);
608 if (mp->is_index_set)
609 ls_index = htonl (mp->ls_index);
612 /* make sure we get a proper C-string */
613 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
614 ls_name = format (0, "%s", mp->ls_name);
615 p = hash_get_mem (lcm->locator_set_index_by_name, ls_name);
621 if (pool_is_free_index (lcm->locator_set_pool, ls_index))
624 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
626 vec_foreach (locit, lsit->locator_indices)
628 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
629 send_one_locator_details (lcm, loc, q, mp->context);
636 send_one_locator_set_details (lisp_cp_main_t * lcm,
637 locator_set_t * lsit,
638 unix_shared_memory_queue_t * q,
639 u32 context, u32 ls_index)
641 vl_api_one_locator_set_details_t *rmp;
644 rmp = vl_msg_api_alloc (sizeof (*rmp));
645 memset (rmp, 0, sizeof (*rmp));
646 rmp->_vl_msg_id = ntohs (VL_API_ONE_LOCATOR_SET_DETAILS);
647 rmp->context = context;
649 rmp->ls_index = htonl (ls_index);
652 ASSERT (lsit->name != NULL);
653 strncpy ((char *) rmp->ls_name, (char *) lsit->name,
654 vec_len (lsit->name));
658 str = format (0, "<remote-%d>", ls_index);
659 strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str));
663 vl_msg_api_send_shmem (q, (u8 *) & rmp);
667 vl_api_one_locator_set_dump_t_handler (vl_api_one_locator_set_dump_t * mp)
669 unix_shared_memory_queue_t *q = NULL;
670 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
671 locator_set_t *lsit = NULL;
674 q = vl_api_client_index_to_input_queue (mp->client_index);
682 pool_foreach (lsit, lcm->locator_set_pool,
684 if (filter && !((1 == filter && lsit->local) ||
685 (2 == filter && !lsit->local)))
689 send_one_locator_set_details (lcm, lsit, q, mp->context,
690 lsit - lcm->locator_set_pool);
696 one_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length)
698 ASSERT (prefix_length);
699 ip_prefix_t *ippref = &fid_addr_ippref (src);
701 switch (fid_addr_type (src))
703 case FID_ADDR_IP_PREF:
704 if (ip_prefix_version (ippref) == IP4)
705 clib_memcpy (dst, &ip_prefix_v4 (ippref), 4);
707 clib_memcpy (dst, &ip_prefix_v6 (ippref), 16);
708 prefix_length[0] = ip_prefix_len (ippref);
712 prefix_length[0] = 0;
713 clib_memcpy (dst, fid_addr_mac (src), 6);
717 clib_warning ("Unknown FID type %d!", fid_addr_type (src));
723 fid_type_to_api_type (fid_address_t * fid)
727 switch (fid_addr_type (fid))
729 case FID_ADDR_IP_PREF:
730 ippref = &fid_addr_ippref (fid);
731 if (ip_prefix_version (ippref) == IP4)
733 else if (ip_prefix_version (ippref) == IP6)
748 send_one_eid_table_details (mapping_t * mapit,
749 unix_shared_memory_queue_t * q,
750 u32 context, u8 filter)
753 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
754 locator_set_t *ls = 0;
755 vl_api_one_eid_table_details_t *rmp = NULL;
756 gid_address_t *gid = NULL;
758 ip_prefix_t *ip_prefix = NULL;
762 case 0: /* all mappings */
765 case 1: /* local only */
769 case 2: /* remote only */
774 clib_warning ("Filter error, unknown filter: %d", filter);
779 ip_prefix = &gid_address_ippref (gid);
780 mac = gid_address_mac (gid);
782 rmp = vl_msg_api_alloc (sizeof (*rmp));
783 memset (rmp, 0, sizeof (*rmp));
784 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_DETAILS);
786 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
787 if (vec_len (ls->locator_indices) == 0)
788 rmp->locator_set_index = ~0;
790 rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
792 rmp->is_local = mapit->local;
793 rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
794 rmp->action = mapit->action;
795 rmp->authoritative = mapit->authoritative;
797 switch (gid_address_type (gid))
799 case GID_ADDR_SRC_DST:
801 fid = &gid_address_sd_src (gid);
802 rmp->eid_type = fid_type_to_api_type (fid);
803 one_fid_put_api (rmp->seid, &gid_address_sd_src (gid),
804 &rmp->seid_prefix_len);
805 one_fid_put_api (rmp->eid, &gid_address_sd_dst (gid),
806 &rmp->eid_prefix_len);
808 case GID_ADDR_IP_PREFIX:
809 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
810 if (ip_prefix_version (ip_prefix) == IP4)
812 rmp->eid_type = 0; /* ipv4 type */
813 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
814 sizeof (ip_prefix_v4 (ip_prefix)));
818 rmp->eid_type = 1; /* ipv6 type */
819 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
820 sizeof (ip_prefix_v6 (ip_prefix)));
824 rmp->eid_type = 2; /* l2 mac type */
825 clib_memcpy (rmp->eid, mac, 6);
830 rmp->context = context;
831 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
832 rmp->key_id = clib_host_to_net_u16 (mapit->key_id);
833 memcpy (rmp->key, mapit->key, vec_len (mapit->key));
834 vl_msg_api_send_shmem (q, (u8 *) & rmp);
838 vl_api_one_eid_table_dump_t_handler (vl_api_one_eid_table_dump_t * mp)
841 unix_shared_memory_queue_t *q = NULL;
842 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
843 mapping_t *mapit = NULL;
844 gid_address_t _eid, *eid = &_eid;
846 q = vl_api_client_index_to_input_queue (mp->client_index);
854 memset (eid, 0, sizeof (*eid));
856 unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
857 mp->eid_type, mp->eid, mp->prefix_length);
859 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
863 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
864 send_one_eid_table_details (mapit, q, mp->context,
865 0 /* ignore filter */ );
870 pool_foreach (mapit, lcm->mapping_pool,
872 send_one_eid_table_details(mapit, q, mp->context,
880 send_one_map_server_details (ip_address_t * ip,
881 unix_shared_memory_queue_t * q, u32 context)
883 vl_api_one_map_server_details_t *rmp = NULL;
885 rmp = vl_msg_api_alloc (sizeof (*rmp));
886 memset (rmp, 0, sizeof (*rmp));
887 rmp->_vl_msg_id = ntohs (VL_API_ONE_MAP_SERVER_DETAILS);
889 switch (ip_addr_version (ip))
893 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
894 sizeof (ip_addr_v4 (ip)));
899 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
900 sizeof (ip_addr_v6 (ip)));
906 rmp->context = context;
908 vl_msg_api_send_shmem (q, (u8 *) & rmp);
912 vl_api_one_map_server_dump_t_handler (vl_api_one_map_server_dump_t * mp)
914 unix_shared_memory_queue_t *q = NULL;
915 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
918 q = vl_api_client_index_to_input_queue (mp->client_index);
924 vec_foreach (mr, lcm->map_servers)
926 send_one_map_server_details (&mr->address, q, mp->context);
931 send_one_map_resolver_details (ip_address_t * ip,
932 unix_shared_memory_queue_t * q, u32 context)
934 vl_api_one_map_resolver_details_t *rmp = NULL;
936 rmp = vl_msg_api_alloc (sizeof (*rmp));
937 memset (rmp, 0, sizeof (*rmp));
938 rmp->_vl_msg_id = ntohs (VL_API_ONE_MAP_RESOLVER_DETAILS);
940 switch (ip_addr_version (ip))
944 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
945 sizeof (ip_addr_v4 (ip)));
950 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
951 sizeof (ip_addr_v6 (ip)));
957 rmp->context = context;
959 vl_msg_api_send_shmem (q, (u8 *) & rmp);
963 vl_api_one_map_resolver_dump_t_handler (vl_api_one_map_resolver_dump_t * mp)
965 unix_shared_memory_queue_t *q = NULL;
966 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
969 q = vl_api_client_index_to_input_queue (mp->client_index);
975 vec_foreach (mr, lcm->map_resolvers)
977 send_one_map_resolver_details (&mr->address, q, mp->context);
982 send_eid_table_map_pair (hash_pair_t * p,
983 unix_shared_memory_queue_t * q, u32 context)
985 vl_api_one_eid_table_map_details_t *rmp = NULL;
987 rmp = vl_msg_api_alloc (sizeof (*rmp));
988 memset (rmp, 0, sizeof (*rmp));
989 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_MAP_DETAILS);
991 rmp->vni = clib_host_to_net_u32 (p->key);
992 rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
993 rmp->context = context;
994 vl_msg_api_send_shmem (q, (u8 *) & rmp);
998 vl_api_one_eid_table_map_dump_t_handler (vl_api_one_eid_table_map_dump_t * mp)
1000 unix_shared_memory_queue_t *q = NULL;
1001 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1003 uword *vni_table = 0;
1005 q = vl_api_client_index_to_input_queue (mp->client_index);
1013 vni_table = lcm->bd_id_by_vni;
1017 vni_table = lcm->table_id_by_vni;
1021 hash_foreach_pair (p, vni_table,
1023 send_eid_table_map_pair (p, q, mp->context);
1029 send_eid_table_vni (u32 vni, unix_shared_memory_queue_t * q, u32 context)
1031 vl_api_one_eid_table_vni_details_t *rmp = 0;
1033 rmp = vl_msg_api_alloc (sizeof (*rmp));
1034 memset (rmp, 0, sizeof (*rmp));
1035 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_VNI_DETAILS);
1036 rmp->context = context;
1037 rmp->vni = clib_host_to_net_u32 (vni);
1038 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1042 one_adjacency_copy (vl_api_one_adjacency_t * dst, lisp_adjacency_t * adjs)
1044 lisp_adjacency_t *adj;
1045 vl_api_one_adjacency_t a;
1046 u32 i, n = vec_len (adjs);
1048 for (i = 0; i < n; i++)
1050 adj = vec_elt_at_index (adjs, i);
1051 memset (&a, 0, sizeof (a));
1053 switch (gid_address_type (&adj->reid))
1055 case GID_ADDR_IP_PREFIX:
1056 a.reid_prefix_len = gid_address_ippref_len (&adj->reid);
1057 a.leid_prefix_len = gid_address_ippref_len (&adj->leid);
1058 if (gid_address_ip_version (&adj->reid) == IP4)
1060 a.eid_type = 0; /* ipv4 type */
1061 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 4);
1062 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 4);
1066 a.eid_type = 1; /* ipv6 type */
1067 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 16);
1068 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 16);
1072 a.eid_type = 2; /* l2 mac type */
1073 mac_copy (a.reid, gid_address_mac (&adj->reid));
1074 mac_copy (a.leid, gid_address_mac (&adj->leid));
1084 vl_api_show_one_rloc_probe_state_t_handler
1085 (vl_api_show_one_rloc_probe_state_t * mp)
1087 vl_api_show_one_rloc_probe_state_reply_t *rmp = 0;
1091 REPLY_MACRO2 (VL_API_SHOW_ONE_RLOC_PROBE_STATE_REPLY,
1093 rmp->is_enabled = vnet_lisp_rloc_probe_state_get ();
1099 vl_api_show_one_map_register_state_t_handler
1100 (vl_api_show_one_map_register_state_t * mp)
1102 vl_api_show_one_map_register_state_reply_t *rmp = 0;
1106 REPLY_MACRO2 (VL_API_SHOW_ONE_MAP_REGISTER_STATE_REPLY,
1108 rmp->is_enabled = vnet_lisp_map_register_state_get ();
1114 vl_api_one_adjacencies_get_t_handler (vl_api_one_adjacencies_get_t * mp)
1116 vl_api_one_adjacencies_get_reply_t *rmp = 0;
1117 lisp_adjacency_t *adjs = 0;
1120 u32 vni = clib_net_to_host_u32 (mp->vni);
1122 adjs = vnet_lisp_adjacencies_get_by_vni (vni);
1123 size = vec_len (adjs) * sizeof (vl_api_one_adjacency_t);
1126 REPLY_MACRO4 (VL_API_ONE_ADJACENCIES_GET_REPLY, size,
1128 rmp->count = clib_host_to_net_u32 (vec_len (adjs));
1129 one_adjacency_copy (rmp->adjacencies, adjs);
1137 vl_api_one_eid_table_vni_dump_t_handler (vl_api_one_eid_table_vni_dump_t * mp)
1141 unix_shared_memory_queue_t *q = 0;
1142 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1144 q = vl_api_client_index_to_input_queue (mp->client_index);
1151 hash_foreach_pair (p, lcm->table_id_by_vni,
1153 hash_set (vnis, p->key, 0);
1156 hash_foreach_pair (p, lcm->bd_id_by_vni,
1158 hash_set (vnis, p->key, 0);
1161 hash_foreach_pair (p, vnis,
1163 send_eid_table_vni (p->key, q, mp->context);
1171 vl_api_show_one_status_t_handler (vl_api_show_one_status_t * mp)
1173 unix_shared_memory_queue_t *q = NULL;
1174 vl_api_show_one_status_reply_t *rmp = NULL;
1177 q = vl_api_client_index_to_input_queue (mp->client_index);
1184 REPLY_MACRO2(VL_API_SHOW_ONE_STATUS_REPLY,
1186 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
1187 rmp->feature_status = vnet_lisp_enable_disable_status ();
1193 vl_api_one_get_map_request_itr_rlocs_t_handler
1194 (vl_api_one_get_map_request_itr_rlocs_t * mp)
1196 unix_shared_memory_queue_t *q = NULL;
1197 vl_api_one_get_map_request_itr_rlocs_reply_t *rmp = NULL;
1198 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1199 locator_set_t *loc_set = 0;
1203 q = vl_api_client_index_to_input_queue (mp->client_index);
1209 if (~0 == lcm->mreq_itr_rlocs)
1211 tmp_str = format (0, " ");
1216 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
1217 tmp_str = format (0, "%s", loc_set->name);
1221 REPLY_MACRO2(VL_API_ONE_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
1223 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1224 ARRAY_LEN(rmp->locator_set_name) - 1);
1232 vl_api_show_one_pitr_t_handler (vl_api_show_one_pitr_t * mp)
1234 unix_shared_memory_queue_t *q = NULL;
1235 vl_api_show_one_pitr_reply_t *rmp = NULL;
1236 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1238 locator_set_t *ls = 0;
1242 q = vl_api_client_index_to_input_queue (mp->client_index);
1248 if (!lcm->lisp_pitr)
1250 tmp_str = format (0, "N/A");
1254 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
1255 if (~0 != m->locator_set_index)
1258 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
1259 tmp_str = format (0, "%s", ls->name);
1263 tmp_str = format (0, "N/A");
1266 vec_add1 (tmp_str, 0);
1269 REPLY_MACRO2(VL_API_SHOW_ONE_PITR_REPLY,
1271 rmp->status = lcm->lisp_pitr;
1272 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1273 ARRAY_LEN(rmp->locator_set_name) - 1);
1279 vl_api_show_one_stats_enable_disable_t_handler
1280 (vl_api_show_one_stats_enable_disable_t * mp)
1282 vl_api_show_one_stats_enable_disable_reply_t *rmp = NULL;
1283 vnet_api_error_t rv = 0;
1286 REPLY_MACRO2 (VL_API_SHOW_ONE_STATS_ENABLE_DISABLE_REPLY,
1288 rmp->is_en = vnet_lisp_stats_enable_disable_state ();
1294 vl_api_one_stats_enable_disable_t_handler
1295 (vl_api_one_stats_enable_disable_t * mp)
1297 vl_api_one_enable_disable_reply_t *rmp = NULL;
1299 vnet_api_error_t rv = vnet_lisp_stats_enable_disable (mp->is_en);
1300 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
1304 vl_api_one_stats_dump_t_handler (vl_api_one_stats_dump_t * mp)
1311 * Add vpe's API message handlers to the table.
1312 * vlib has alread mapped shared memory and
1313 * added the client registration handlers.
1314 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
1316 #define vl_msg_name_crc_list
1317 #include <vnet/vnet_all_api_h.h>
1318 #undef vl_msg_name_crc_list
1321 setup_message_id_table (api_main_t * am)
1323 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
1324 foreach_vl_msg_name_crc_one;
1328 static clib_error_t *
1329 one_api_hookup (vlib_main_t * vm)
1331 api_main_t *am = &api_main;
1334 vl_msg_api_set_handlers(VL_API_##N, #n, \
1335 vl_api_##n##_t_handler, \
1337 vl_api_##n##_t_endian, \
1338 vl_api_##n##_t_print, \
1339 sizeof(vl_api_##n##_t), 1);
1340 foreach_vpe_api_msg;
1344 * Set up the (msg_name, crc, message-id) table
1346 setup_message_id_table (am);
1351 VLIB_API_INIT_FUNCTION (one_api_hookup);
1354 * fd.io coding-style-patch-verification: ON
1357 * eval: (c-set-style "gnu")