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 gid_address_put (rmp->address, &addr);
453 rmp->is_ip4 = (gid_address_ip_version (&addr) == IP4);
459 vl_api_one_add_del_map_request_itr_rlocs_t_handler
460 (vl_api_one_add_del_map_request_itr_rlocs_t * mp)
462 vl_api_one_add_del_map_request_itr_rlocs_reply_t *rmp;
464 u8 *locator_set_name = NULL;
465 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
467 locator_set_name = format (0, "%s", mp->locator_set_name);
469 a->is_add = mp->is_add;
470 a->locator_set_name = locator_set_name;
472 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
474 vec_free (locator_set_name);
476 REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
480 vl_api_one_add_del_remote_mapping_t_handler
481 (vl_api_one_add_del_remote_mapping_t * mp)
483 locator_t *rlocs = 0;
484 vl_api_one_add_del_remote_mapping_reply_t *rmp;
486 gid_address_t _eid, *eid = &_eid;
487 u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
489 memset (eid, 0, sizeof (eid[0]));
491 rv = unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
492 mp->eid_type, mp->eid, mp->eid_len);
496 rlocs = unformat_one_locs (mp->rlocs, rloc_num);
500 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
501 gid_address_copy (&a->reid, eid);
503 rv = vnet_lisp_add_del_adjacency (a);
510 /* NOTE: for now this works as a static remote mapping, i.e.,
511 * not authoritative and ttl infinite. */
512 rv = vnet_lisp_add_del_mapping (eid, rlocs, mp->action, 0, ~0,
513 mp->is_add, 1 /* is_static */ , 0);
516 vnet_lisp_clear_all_remote_adjacencies ();
521 REPLY_MACRO (VL_API_ONE_ADD_DEL_REMOTE_MAPPING_REPLY);
525 vl_api_one_add_del_adjacency_t_handler (vl_api_one_add_del_adjacency_t * mp)
527 vl_api_one_add_del_adjacency_reply_t *rmp;
528 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
531 memset (a, 0, sizeof (a[0]));
533 rv = unformat_one_eid_api (&a->leid, clib_net_to_host_u32 (mp->vni),
534 mp->eid_type, mp->leid, mp->leid_len);
535 rv |= unformat_one_eid_api (&a->reid, clib_net_to_host_u32 (mp->vni),
536 mp->eid_type, mp->reid, mp->reid_len);
541 a->is_add = mp->is_add;
542 rv = vnet_lisp_add_del_adjacency (a);
545 REPLY_MACRO (VL_API_ONE_ADD_DEL_ADJACENCY_REPLY);
549 send_one_locator_details (lisp_cp_main_t * lcm,
551 unix_shared_memory_queue_t * q, u32 context)
553 vl_api_one_locator_details_t *rmp;
555 rmp = vl_msg_api_alloc (sizeof (*rmp));
556 memset (rmp, 0, sizeof (*rmp));
557 rmp->_vl_msg_id = ntohs (VL_API_ONE_LOCATOR_DETAILS);
558 rmp->context = context;
560 rmp->local = loc->local;
563 rmp->sw_if_index = ntohl (loc->sw_if_index);
567 rmp->is_ipv6 = gid_address_ip_version (&loc->address);
568 ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
570 rmp->priority = loc->priority;
571 rmp->weight = loc->weight;
573 vl_msg_api_send_shmem (q, (u8 *) & rmp);
577 vl_api_one_locator_dump_t_handler (vl_api_one_locator_dump_t * mp)
580 unix_shared_memory_queue_t *q = 0;
581 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
582 locator_set_t *lsit = 0;
584 u32 ls_index = ~0, *locit = 0;
587 q = vl_api_client_index_to_input_queue (mp->client_index);
593 if (mp->is_index_set)
594 ls_index = htonl (mp->ls_index);
597 /* make sure we get a proper C-string */
598 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
599 ls_name = format (0, "%s", mp->ls_name);
600 p = hash_get_mem (lcm->locator_set_index_by_name, ls_name);
606 if (pool_is_free_index (lcm->locator_set_pool, ls_index))
609 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
611 vec_foreach (locit, lsit->locator_indices)
613 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
614 send_one_locator_details (lcm, loc, q, mp->context);
621 send_one_locator_set_details (lisp_cp_main_t * lcm,
622 locator_set_t * lsit,
623 unix_shared_memory_queue_t * q,
624 u32 context, u32 ls_index)
626 vl_api_one_locator_set_details_t *rmp;
629 rmp = vl_msg_api_alloc (sizeof (*rmp));
630 memset (rmp, 0, sizeof (*rmp));
631 rmp->_vl_msg_id = ntohs (VL_API_ONE_LOCATOR_SET_DETAILS);
632 rmp->context = context;
634 rmp->ls_index = htonl (ls_index);
637 ASSERT (lsit->name != NULL);
638 strncpy ((char *) rmp->ls_name, (char *) lsit->name,
639 vec_len (lsit->name));
643 str = format (0, "<remote-%d>", ls_index);
644 strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str));
648 vl_msg_api_send_shmem (q, (u8 *) & rmp);
652 vl_api_one_locator_set_dump_t_handler (vl_api_one_locator_set_dump_t * mp)
654 unix_shared_memory_queue_t *q = NULL;
655 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
656 locator_set_t *lsit = NULL;
659 q = vl_api_client_index_to_input_queue (mp->client_index);
667 pool_foreach (lsit, lcm->locator_set_pool,
669 if (filter && !((1 == filter && lsit->local) ||
670 (2 == filter && !lsit->local)))
674 send_one_locator_set_details (lcm, lsit, q, mp->context,
675 lsit - lcm->locator_set_pool);
681 one_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length)
683 ASSERT (prefix_length);
684 ip_prefix_t *ippref = &fid_addr_ippref (src);
686 switch (fid_addr_type (src))
688 case FID_ADDR_IP_PREF:
689 if (ip_prefix_version (ippref) == IP4)
690 clib_memcpy (dst, &ip_prefix_v4 (ippref), 4);
692 clib_memcpy (dst, &ip_prefix_v6 (ippref), 16);
693 prefix_length[0] = ip_prefix_len (ippref);
697 prefix_length[0] = 0;
698 clib_memcpy (dst, fid_addr_mac (src), 6);
702 clib_warning ("Unknown FID type %d!", fid_addr_type (src));
708 fid_type_to_api_type (fid_address_t * fid)
712 switch (fid_addr_type (fid))
714 case FID_ADDR_IP_PREF:
715 ippref = &fid_addr_ippref (fid);
716 if (ip_prefix_version (ippref) == IP4)
718 else if (ip_prefix_version (ippref) == IP6)
733 send_one_eid_table_details (mapping_t * mapit,
734 unix_shared_memory_queue_t * q,
735 u32 context, u8 filter)
738 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
739 locator_set_t *ls = 0;
740 vl_api_one_eid_table_details_t *rmp = NULL;
741 gid_address_t *gid = NULL;
743 ip_prefix_t *ip_prefix = NULL;
747 case 0: /* all mappings */
750 case 1: /* local only */
754 case 2: /* remote only */
759 clib_warning ("Filter error, unknown filter: %d", filter);
764 ip_prefix = &gid_address_ippref (gid);
765 mac = gid_address_mac (gid);
767 rmp = vl_msg_api_alloc (sizeof (*rmp));
768 memset (rmp, 0, sizeof (*rmp));
769 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_DETAILS);
771 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
772 if (vec_len (ls->locator_indices) == 0)
773 rmp->locator_set_index = ~0;
775 rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
777 rmp->is_local = mapit->local;
778 rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
779 rmp->action = mapit->action;
780 rmp->authoritative = mapit->authoritative;
782 switch (gid_address_type (gid))
784 case GID_ADDR_SRC_DST:
786 fid = &gid_address_sd_src (gid);
787 rmp->eid_type = fid_type_to_api_type (fid);
788 one_fid_put_api (rmp->seid, &gid_address_sd_src (gid),
789 &rmp->seid_prefix_len);
790 one_fid_put_api (rmp->eid, &gid_address_sd_dst (gid),
791 &rmp->eid_prefix_len);
793 case GID_ADDR_IP_PREFIX:
794 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
795 if (ip_prefix_version (ip_prefix) == IP4)
797 rmp->eid_type = 0; /* ipv4 type */
798 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
799 sizeof (ip_prefix_v4 (ip_prefix)));
803 rmp->eid_type = 1; /* ipv6 type */
804 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
805 sizeof (ip_prefix_v6 (ip_prefix)));
809 rmp->eid_type = 2; /* l2 mac type */
810 clib_memcpy (rmp->eid, mac, 6);
815 rmp->context = context;
816 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
817 rmp->key_id = clib_host_to_net_u16 (mapit->key_id);
818 memcpy (rmp->key, mapit->key, vec_len (mapit->key));
819 vl_msg_api_send_shmem (q, (u8 *) & rmp);
823 vl_api_one_eid_table_dump_t_handler (vl_api_one_eid_table_dump_t * mp)
826 unix_shared_memory_queue_t *q = NULL;
827 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
828 mapping_t *mapit = NULL;
829 gid_address_t _eid, *eid = &_eid;
831 q = vl_api_client_index_to_input_queue (mp->client_index);
839 memset (eid, 0, sizeof (*eid));
841 unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
842 mp->eid_type, mp->eid, mp->prefix_length);
844 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
848 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
849 send_one_eid_table_details (mapit, q, mp->context,
850 0 /* ignore filter */ );
855 pool_foreach (mapit, lcm->mapping_pool,
857 send_one_eid_table_details(mapit, q, mp->context,
865 send_one_map_server_details (ip_address_t * ip,
866 unix_shared_memory_queue_t * q, u32 context)
868 vl_api_one_map_server_details_t *rmp = NULL;
870 rmp = vl_msg_api_alloc (sizeof (*rmp));
871 memset (rmp, 0, sizeof (*rmp));
872 rmp->_vl_msg_id = ntohs (VL_API_ONE_MAP_SERVER_DETAILS);
874 switch (ip_addr_version (ip))
878 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
879 sizeof (ip_addr_v4 (ip)));
884 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
885 sizeof (ip_addr_v6 (ip)));
891 rmp->context = context;
893 vl_msg_api_send_shmem (q, (u8 *) & rmp);
897 vl_api_one_map_server_dump_t_handler (vl_api_one_map_server_dump_t * mp)
899 unix_shared_memory_queue_t *q = NULL;
900 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
903 q = vl_api_client_index_to_input_queue (mp->client_index);
909 vec_foreach (mr, lcm->map_servers)
911 send_one_map_server_details (&mr->address, q, mp->context);
916 send_one_map_resolver_details (ip_address_t * ip,
917 unix_shared_memory_queue_t * q, u32 context)
919 vl_api_one_map_resolver_details_t *rmp = NULL;
921 rmp = vl_msg_api_alloc (sizeof (*rmp));
922 memset (rmp, 0, sizeof (*rmp));
923 rmp->_vl_msg_id = ntohs (VL_API_ONE_MAP_RESOLVER_DETAILS);
925 switch (ip_addr_version (ip))
929 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
930 sizeof (ip_addr_v4 (ip)));
935 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
936 sizeof (ip_addr_v6 (ip)));
942 rmp->context = context;
944 vl_msg_api_send_shmem (q, (u8 *) & rmp);
948 vl_api_one_map_resolver_dump_t_handler (vl_api_one_map_resolver_dump_t * mp)
950 unix_shared_memory_queue_t *q = NULL;
951 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
954 q = vl_api_client_index_to_input_queue (mp->client_index);
960 vec_foreach (mr, lcm->map_resolvers)
962 send_one_map_resolver_details (&mr->address, q, mp->context);
967 send_eid_table_map_pair (hash_pair_t * p,
968 unix_shared_memory_queue_t * q, u32 context)
970 vl_api_one_eid_table_map_details_t *rmp = NULL;
972 rmp = vl_msg_api_alloc (sizeof (*rmp));
973 memset (rmp, 0, sizeof (*rmp));
974 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_MAP_DETAILS);
976 rmp->vni = clib_host_to_net_u32 (p->key);
977 rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
978 rmp->context = context;
979 vl_msg_api_send_shmem (q, (u8 *) & rmp);
983 vl_api_one_eid_table_map_dump_t_handler (vl_api_one_eid_table_map_dump_t * mp)
985 unix_shared_memory_queue_t *q = NULL;
986 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
988 uword *vni_table = 0;
990 q = vl_api_client_index_to_input_queue (mp->client_index);
998 vni_table = lcm->bd_id_by_vni;
1002 vni_table = lcm->table_id_by_vni;
1006 hash_foreach_pair (p, vni_table,
1008 send_eid_table_map_pair (p, q, mp->context);
1014 send_eid_table_vni (u32 vni, unix_shared_memory_queue_t * q, u32 context)
1016 vl_api_one_eid_table_vni_details_t *rmp = 0;
1018 rmp = vl_msg_api_alloc (sizeof (*rmp));
1019 memset (rmp, 0, sizeof (*rmp));
1020 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_VNI_DETAILS);
1021 rmp->context = context;
1022 rmp->vni = clib_host_to_net_u32 (vni);
1023 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1027 one_adjacency_copy (vl_api_one_adjacency_t * dst, lisp_adjacency_t * adjs)
1029 lisp_adjacency_t *adj;
1030 vl_api_one_adjacency_t a;
1031 u32 i, n = vec_len (adjs);
1033 for (i = 0; i < n; i++)
1035 adj = vec_elt_at_index (adjs, i);
1036 memset (&a, 0, sizeof (a));
1038 switch (gid_address_type (&adj->reid))
1040 case GID_ADDR_IP_PREFIX:
1041 a.reid_prefix_len = gid_address_ippref_len (&adj->reid);
1042 a.leid_prefix_len = gid_address_ippref_len (&adj->leid);
1043 if (gid_address_ip_version (&adj->reid) == IP4)
1045 a.eid_type = 0; /* ipv4 type */
1046 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 4);
1047 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 4);
1051 a.eid_type = 1; /* ipv6 type */
1052 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 16);
1053 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 16);
1057 a.eid_type = 2; /* l2 mac type */
1058 mac_copy (a.reid, gid_address_mac (&adj->reid));
1059 mac_copy (a.leid, gid_address_mac (&adj->leid));
1069 vl_api_show_one_rloc_probe_state_t_handler
1070 (vl_api_show_one_rloc_probe_state_t * mp)
1072 vl_api_show_one_rloc_probe_state_reply_t *rmp = 0;
1076 REPLY_MACRO2 (VL_API_SHOW_ONE_RLOC_PROBE_STATE_REPLY,
1078 rmp->is_enabled = vnet_lisp_rloc_probe_state_get ();
1084 vl_api_show_one_map_register_state_t_handler
1085 (vl_api_show_one_map_register_state_t * mp)
1087 vl_api_show_one_map_register_state_reply_t *rmp = 0;
1091 REPLY_MACRO2 (VL_API_SHOW_ONE_MAP_REGISTER_STATE_REPLY,
1093 rmp->is_enabled = vnet_lisp_map_register_state_get ();
1099 vl_api_one_adjacencies_get_t_handler (vl_api_one_adjacencies_get_t * mp)
1101 vl_api_one_adjacencies_get_reply_t *rmp = 0;
1102 lisp_adjacency_t *adjs = 0;
1105 u32 vni = clib_net_to_host_u32 (mp->vni);
1107 adjs = vnet_lisp_adjacencies_get_by_vni (vni);
1108 size = vec_len (adjs) * sizeof (vl_api_one_adjacency_t);
1111 REPLY_MACRO4 (VL_API_ONE_ADJACENCIES_GET_REPLY, size,
1113 rmp->count = clib_host_to_net_u32 (vec_len (adjs));
1114 one_adjacency_copy (rmp->adjacencies, adjs);
1122 vl_api_one_eid_table_vni_dump_t_handler (vl_api_one_eid_table_vni_dump_t * mp)
1126 unix_shared_memory_queue_t *q = 0;
1127 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1129 q = vl_api_client_index_to_input_queue (mp->client_index);
1136 hash_foreach_pair (p, lcm->table_id_by_vni,
1138 hash_set (vnis, p->key, 0);
1141 hash_foreach_pair (p, lcm->bd_id_by_vni,
1143 hash_set (vnis, p->key, 0);
1146 hash_foreach_pair (p, vnis,
1148 send_eid_table_vni (p->key, q, mp->context);
1156 vl_api_show_one_status_t_handler (vl_api_show_one_status_t * mp)
1158 unix_shared_memory_queue_t *q = NULL;
1159 vl_api_show_one_status_reply_t *rmp = NULL;
1162 q = vl_api_client_index_to_input_queue (mp->client_index);
1169 REPLY_MACRO2(VL_API_SHOW_ONE_STATUS_REPLY,
1171 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
1172 rmp->feature_status = vnet_lisp_enable_disable_status ();
1178 vl_api_one_get_map_request_itr_rlocs_t_handler
1179 (vl_api_one_get_map_request_itr_rlocs_t * mp)
1181 unix_shared_memory_queue_t *q = NULL;
1182 vl_api_one_get_map_request_itr_rlocs_reply_t *rmp = NULL;
1183 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1184 locator_set_t *loc_set = 0;
1188 q = vl_api_client_index_to_input_queue (mp->client_index);
1194 if (~0 == lcm->mreq_itr_rlocs)
1196 tmp_str = format (0, " ");
1201 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
1202 tmp_str = format (0, "%s", loc_set->name);
1206 REPLY_MACRO2(VL_API_ONE_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
1208 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1209 ARRAY_LEN(rmp->locator_set_name) - 1);
1217 vl_api_show_one_pitr_t_handler (vl_api_show_one_pitr_t * mp)
1219 unix_shared_memory_queue_t *q = NULL;
1220 vl_api_show_one_pitr_reply_t *rmp = NULL;
1221 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1223 locator_set_t *ls = 0;
1227 q = vl_api_client_index_to_input_queue (mp->client_index);
1233 if (!lcm->lisp_pitr)
1235 tmp_str = format (0, "N/A");
1239 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
1240 if (~0 != m->locator_set_index)
1243 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
1244 tmp_str = format (0, "%s", ls->name);
1248 tmp_str = format (0, "N/A");
1251 vec_add1 (tmp_str, 0);
1254 REPLY_MACRO2(VL_API_SHOW_ONE_PITR_REPLY,
1256 rmp->status = lcm->lisp_pitr;
1257 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1258 ARRAY_LEN(rmp->locator_set_name) - 1);
1264 vl_api_show_one_stats_enable_disable_t_handler
1265 (vl_api_show_one_stats_enable_disable_t * mp)
1267 vl_api_show_one_stats_enable_disable_reply_t *rmp = NULL;
1268 vnet_api_error_t rv = 0;
1271 REPLY_MACRO2 (VL_API_SHOW_ONE_STATS_ENABLE_DISABLE_REPLY,
1273 rmp->is_en = vnet_lisp_stats_enable_disable_state ();
1279 vl_api_one_stats_enable_disable_t_handler
1280 (vl_api_one_stats_enable_disable_t * mp)
1282 vl_api_one_enable_disable_reply_t *rmp = NULL;
1284 vnet_api_error_t rv = vnet_lisp_stats_enable_disable (mp->is_en);
1285 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
1289 vl_api_one_stats_dump_t_handler (vl_api_one_stats_dump_t * mp)
1296 * Add vpe's API message handlers to the table.
1297 * vlib has alread mapped shared memory and
1298 * added the client registration handlers.
1299 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
1301 #define vl_msg_name_crc_list
1302 #include <vnet/vnet_all_api_h.h>
1303 #undef vl_msg_name_crc_list
1306 setup_message_id_table (api_main_t * am)
1308 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
1309 foreach_vl_msg_name_crc_one;
1313 static clib_error_t *
1314 one_api_hookup (vlib_main_t * vm)
1316 api_main_t *am = &api_main;
1319 vl_msg_api_set_handlers(VL_API_##N, #n, \
1320 vl_api_##n##_t_handler, \
1322 vl_api_##n##_t_endian, \
1323 vl_api_##n##_t_print, \
1324 sizeof(vl_api_##n##_t), 1);
1325 foreach_vpe_api_msg;
1329 * Set up the (msg_name, crc, message-id) table
1331 setup_message_id_table (am);
1336 VLIB_API_INIT_FUNCTION (one_api_hookup);
1339 * fd.io coding-style-patch-verification: ON
1342 * eval: (c-set-style "gnu")