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 REPLY_DETAILS(t, body) \
63 unix_shared_memory_queue_t * q; \
64 rv = vl_msg_api_pd_handler (mp, rv); \
65 q = vl_api_client_index_to_input_queue (mp->client_index); \
69 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
70 rmp->_vl_msg_id = ntohs((t)); \
71 rmp->context = mp->context; \
72 do {body;} while (0); \
73 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
76 #define foreach_vpe_api_msg \
77 _(ONE_ADD_DEL_LOCATOR_SET, one_add_del_locator_set) \
78 _(ONE_ADD_DEL_LOCATOR, one_add_del_locator) \
79 _(ONE_ADD_DEL_LOCAL_EID, one_add_del_local_eid) \
80 _(ONE_ADD_DEL_MAP_RESOLVER, one_add_del_map_resolver) \
81 _(ONE_ADD_DEL_MAP_SERVER, one_add_del_map_server) \
82 _(ONE_ENABLE_DISABLE, one_enable_disable) \
83 _(ONE_RLOC_PROBE_ENABLE_DISABLE, one_rloc_probe_enable_disable) \
84 _(ONE_MAP_REGISTER_ENABLE_DISABLE, one_map_register_enable_disable) \
85 _(ONE_ADD_DEL_REMOTE_MAPPING, one_add_del_remote_mapping) \
86 _(ONE_ADD_DEL_ADJACENCY, one_add_del_adjacency) \
87 _(ONE_PITR_SET_LOCATOR_SET, one_pitr_set_locator_set) \
88 _(ONE_MAP_REQUEST_MODE, one_map_request_mode) \
89 _(ONE_EID_TABLE_ADD_DEL_MAP, one_eid_table_add_del_map) \
90 _(ONE_LOCATOR_SET_DUMP, one_locator_set_dump) \
91 _(ONE_LOCATOR_DUMP, one_locator_dump) \
92 _(ONE_EID_TABLE_DUMP, one_eid_table_dump) \
93 _(ONE_MAP_RESOLVER_DUMP, one_map_resolver_dump) \
94 _(ONE_MAP_SERVER_DUMP, one_map_server_dump) \
95 _(ONE_EID_TABLE_MAP_DUMP, one_eid_table_map_dump) \
96 _(ONE_EID_TABLE_VNI_DUMP, one_eid_table_vni_dump) \
97 _(ONE_ADJACENCIES_GET, one_adjacencies_get) \
98 _(SHOW_ONE_RLOC_PROBE_STATE, show_one_rloc_probe_state) \
99 _(SHOW_ONE_MAP_REGISTER_STATE, show_one_map_register_state) \
100 _(SHOW_ONE_STATUS, show_one_status) \
101 _(ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \
102 one_add_del_map_request_itr_rlocs) \
103 _(ONE_GET_MAP_REQUEST_ITR_RLOCS, one_get_map_request_itr_rlocs) \
104 _(SHOW_ONE_PITR, show_one_pitr) \
105 _(SHOW_ONE_MAP_REQUEST_MODE, show_one_map_request_mode) \
106 _(ONE_USE_PETR, one_use_petr) \
107 _(SHOW_ONE_USE_PETR, show_one_use_petr) \
108 _(SHOW_ONE_STATS_ENABLE_DISABLE, show_one_stats_enable_disable) \
109 _(ONE_STATS_ENABLE_DISABLE, one_stats_enable_disable) \
110 _(ONE_STATS_DUMP, one_stats_dump) \
111 _(ONE_STATS_FLUSH, one_stats_flush) \
115 unformat_one_locs (vl_api_one_remote_locator_t * rmt_locs, u32 rloc_num)
118 locator_t *locs = 0, loc;
119 vl_api_one_remote_locator_t *r;
121 for (i = 0; i < rloc_num; i++)
123 /* remote locators */
125 memset (&loc, 0, sizeof (loc));
126 gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
128 loc.priority = r->priority;
129 loc.weight = r->weight;
131 vec_add1 (locs, loc);
137 vl_api_one_add_del_locator_set_t_handler (vl_api_one_add_del_locator_set_t *
140 vl_api_one_add_del_locator_set_reply_t *rmp;
142 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
144 vl_api_one_local_locator_t *ls_loc;
145 u32 ls_index = ~0, locator_num;
146 u8 *locator_name = NULL;
149 memset (a, 0, sizeof (a[0]));
151 locator_name = format (0, "%s", mp->locator_set_name);
153 a->name = locator_name;
154 a->is_add = mp->is_add;
156 locator_num = clib_net_to_host_u32 (mp->locator_num);
158 memset (&locator, 0, sizeof (locator));
159 for (i = 0; i < locator_num; i++)
161 ls_loc = &mp->locators[i];
162 VALIDATE_SW_IF_INDEX (ls_loc);
164 locator.sw_if_index = htonl (ls_loc->sw_if_index);
165 locator.priority = ls_loc->priority;
166 locator.weight = ls_loc->weight;
168 vec_add1 (a->locators, locator);
171 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
173 BAD_SW_IF_INDEX_LABEL;
175 vec_free (locator_name);
176 vec_free (a->locators);
179 REPLY_MACRO2 (VL_API_ONE_ADD_DEL_LOCATOR_SET_REPLY,
181 rmp->ls_index = clib_host_to_net_u32 (ls_index);
187 vl_api_one_add_del_locator_t_handler (vl_api_one_add_del_locator_t * mp)
189 vl_api_one_add_del_locator_reply_t *rmp;
191 locator_t locator, *locators = NULL;
192 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
194 u8 *locator_name = NULL;
196 memset (&locator, 0, sizeof (locator));
197 memset (a, 0, sizeof (a[0]));
199 locator.sw_if_index = ntohl (mp->sw_if_index);
200 locator.priority = mp->priority;
201 locator.weight = mp->weight;
203 vec_add1 (locators, locator);
205 locator_name = format (0, "%s", mp->locator_set_name);
207 a->name = locator_name;
208 a->locators = locators;
209 a->is_add = mp->is_add;
212 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
215 vec_free (locator_name);
217 REPLY_MACRO (VL_API_ONE_ADD_DEL_LOCATOR_REPLY);
221 unformat_one_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
227 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
228 gid_address_ip_set (dst, src, IP4);
229 gid_address_ippref_len (dst) = len;
230 ip_prefix_normalize (&gid_address_ippref (dst));
233 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
234 gid_address_ip_set (dst, src, IP6);
235 gid_address_ippref_len (dst) = len;
236 ip_prefix_normalize (&gid_address_ippref (dst));
239 gid_address_type (dst) = GID_ADDR_MAC;
240 clib_memcpy (&gid_address_mac (dst), src, 6);
244 return VNET_API_ERROR_INVALID_VALUE;
247 gid_address_vni (dst) = vni;
253 vl_api_one_add_del_local_eid_t_handler (vl_api_one_add_del_local_eid_t * mp)
255 vl_api_one_add_del_local_eid_reply_t *rmp;
256 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
258 gid_address_t _eid, *eid = &_eid;
260 u32 locator_set_index = ~0, map_index = ~0;
261 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
262 u8 *name = NULL, *key = NULL;
263 memset (a, 0, sizeof (a[0]));
264 memset (eid, 0, sizeof (eid[0]));
266 rv = unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
267 mp->eid_type, mp->eid, mp->prefix_len);
271 name = format (0, "%s", mp->locator_set_name);
272 p = hash_get_mem (lcm->locator_set_index_by_name, name);
275 rv = VNET_API_ERROR_INVALID_VALUE;
278 locator_set_index = p[0];
281 key = format (0, "%s", mp->key);
283 /* XXX treat batch configuration */
284 a->is_add = mp->is_add;
285 gid_address_copy (&a->eid, eid);
286 a->locator_set_index = locator_set_index;
289 a->key_id = clib_net_to_host_u16 (mp->key_id);
291 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
296 gid_address_free (&a->eid);
298 REPLY_MACRO (VL_API_ONE_ADD_DEL_LOCAL_EID_REPLY);
302 vl_api_one_eid_table_add_del_map_t_handler
303 (vl_api_one_eid_table_add_del_map_t * mp)
305 vl_api_one_eid_table_add_del_map_reply_t *rmp;
307 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
308 clib_net_to_host_u32 (mp->dp_table),
309 mp->is_l2, mp->is_add);
310 REPLY_MACRO (VL_API_ONE_EID_TABLE_ADD_DEL_MAP_REPLY)}
313 vl_api_one_add_del_map_server_t_handler (vl_api_one_add_del_map_server_t * mp)
315 vl_api_one_add_del_map_server_reply_t *rmp;
319 memset (&addr, 0, sizeof (addr));
321 ip_address_set (&addr, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
322 rv = vnet_lisp_add_del_map_server (&addr, mp->is_add);
324 REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_SERVER_REPLY);
328 vl_api_one_add_del_map_resolver_t_handler (vl_api_one_add_del_map_resolver_t
331 vl_api_one_add_del_map_resolver_reply_t *rmp;
333 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
335 memset (a, 0, sizeof (a[0]));
337 a->is_add = mp->is_add;
338 ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
340 rv = vnet_lisp_add_del_map_resolver (a);
342 REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_RESOLVER_REPLY);
346 vl_api_one_map_register_enable_disable_t_handler
347 (vl_api_one_map_register_enable_disable_t * mp)
349 vl_api_one_map_register_enable_disable_reply_t *rmp;
352 vnet_lisp_map_register_enable_disable (mp->is_enabled);
353 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
357 vl_api_one_rloc_probe_enable_disable_t_handler
358 (vl_api_one_rloc_probe_enable_disable_t * mp)
360 vl_api_one_rloc_probe_enable_disable_reply_t *rmp;
363 vnet_lisp_rloc_probe_enable_disable (mp->is_enabled);
364 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
368 vl_api_one_enable_disable_t_handler (vl_api_one_enable_disable_t * mp)
370 vl_api_one_enable_disable_reply_t *rmp;
373 vnet_lisp_enable_disable (mp->is_en);
374 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
378 vl_api_show_one_map_request_mode_t_handler
379 (vl_api_show_one_map_request_mode_t * mp)
382 vl_api_show_one_map_request_mode_reply_t *rmp;
385 REPLY_MACRO2(VL_API_SHOW_ONE_MAP_REQUEST_MODE_REPLY,
387 rmp->mode = vnet_lisp_get_map_request_mode ();
393 vl_api_one_map_request_mode_t_handler (vl_api_one_map_request_mode_t * mp)
395 vl_api_one_map_request_mode_reply_t *rmp;
398 rv = vnet_lisp_set_map_request_mode (mp->mode);
400 REPLY_MACRO (VL_API_ONE_MAP_REQUEST_MODE_REPLY);
404 vl_api_one_pitr_set_locator_set_t_handler (vl_api_one_pitr_set_locator_set_t
407 vl_api_one_pitr_set_locator_set_reply_t *rmp;
411 ls_name = format (0, "%s", mp->ls_name);
412 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
415 REPLY_MACRO (VL_API_ONE_PITR_SET_LOCATOR_SET_REPLY);
419 vl_api_one_use_petr_t_handler (vl_api_one_use_petr_t * mp)
421 vl_api_one_use_petr_reply_t *rmp;
425 ip_address_set (&addr, &mp->address, mp->is_ip4 ? IP4 : IP6);
426 rv = vnet_lisp_use_petr (&addr, mp->is_add);
428 REPLY_MACRO (VL_API_ONE_USE_PETR_REPLY);
432 vl_api_show_one_use_petr_t_handler (vl_api_show_one_use_petr_t * mp)
434 unix_shared_memory_queue_t *q = NULL;
435 vl_api_show_one_use_petr_reply_t *rmp = NULL;
436 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
438 locator_set_t *ls = 0;
444 q = vl_api_client_index_to_input_queue (mp->client_index);
450 memset (&addr, 0, sizeof (addr));
451 status = lcm->flags & LISP_FLAG_USE_PETR;
454 m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index);
455 if (~0 != m->locator_set_index)
458 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
459 loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]);
460 gid_address_copy (&addr, &loc->address);
465 REPLY_MACRO2 (VL_API_SHOW_ONE_USE_PETR_REPLY,
467 rmp->status = status;
468 ip_address_t *ip = &gid_address_ip (&addr);
469 switch (ip_addr_version (ip))
472 clib_memcpy (rmp->address, &ip_addr_v4 (ip),
473 sizeof (ip_addr_v4 (ip)));
477 clib_memcpy (rmp->address, &ip_addr_v6 (ip),
478 sizeof (ip_addr_v6 (ip)));
484 rmp->is_ip4 = (gid_address_ip_version (&addr) == IP4);
490 vl_api_one_add_del_map_request_itr_rlocs_t_handler
491 (vl_api_one_add_del_map_request_itr_rlocs_t * mp)
493 vl_api_one_add_del_map_request_itr_rlocs_reply_t *rmp;
495 u8 *locator_set_name = NULL;
496 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
498 locator_set_name = format (0, "%s", mp->locator_set_name);
500 a->is_add = mp->is_add;
501 a->locator_set_name = locator_set_name;
503 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
505 vec_free (locator_set_name);
507 REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
511 vl_api_one_add_del_remote_mapping_t_handler
512 (vl_api_one_add_del_remote_mapping_t * mp)
514 locator_t *rlocs = 0;
515 vl_api_one_add_del_remote_mapping_reply_t *rmp;
517 gid_address_t _eid, *eid = &_eid;
518 u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
520 memset (eid, 0, sizeof (eid[0]));
522 rv = unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
523 mp->eid_type, mp->eid, mp->eid_len);
527 rlocs = unformat_one_locs (mp->rlocs, rloc_num);
531 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
532 gid_address_copy (&a->reid, eid);
534 rv = vnet_lisp_add_del_adjacency (a);
541 /* NOTE: for now this works as a static remote mapping, i.e.,
542 * not authoritative and ttl infinite. */
543 rv = vnet_lisp_add_del_mapping (eid, rlocs, mp->action, 0, ~0,
544 mp->is_add, 1 /* is_static */ , 0);
547 vnet_lisp_clear_all_remote_adjacencies ();
552 REPLY_MACRO (VL_API_ONE_ADD_DEL_REMOTE_MAPPING_REPLY);
556 vl_api_one_add_del_adjacency_t_handler (vl_api_one_add_del_adjacency_t * mp)
558 vl_api_one_add_del_adjacency_reply_t *rmp;
559 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
562 memset (a, 0, sizeof (a[0]));
564 rv = unformat_one_eid_api (&a->leid, clib_net_to_host_u32 (mp->vni),
565 mp->eid_type, mp->leid, mp->leid_len);
566 rv |= unformat_one_eid_api (&a->reid, clib_net_to_host_u32 (mp->vni),
567 mp->eid_type, mp->reid, mp->reid_len);
572 a->is_add = mp->is_add;
573 rv = vnet_lisp_add_del_adjacency (a);
576 REPLY_MACRO (VL_API_ONE_ADD_DEL_ADJACENCY_REPLY);
580 send_one_locator_details (lisp_cp_main_t * lcm,
582 unix_shared_memory_queue_t * q, u32 context)
584 vl_api_one_locator_details_t *rmp;
586 rmp = vl_msg_api_alloc (sizeof (*rmp));
587 memset (rmp, 0, sizeof (*rmp));
588 rmp->_vl_msg_id = ntohs (VL_API_ONE_LOCATOR_DETAILS);
589 rmp->context = context;
591 rmp->local = loc->local;
594 rmp->sw_if_index = ntohl (loc->sw_if_index);
598 rmp->is_ipv6 = gid_address_ip_version (&loc->address);
599 ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
601 rmp->priority = loc->priority;
602 rmp->weight = loc->weight;
604 vl_msg_api_send_shmem (q, (u8 *) & rmp);
608 vl_api_one_locator_dump_t_handler (vl_api_one_locator_dump_t * mp)
611 unix_shared_memory_queue_t *q = 0;
612 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
613 locator_set_t *lsit = 0;
615 u32 ls_index = ~0, *locit = 0;
618 q = vl_api_client_index_to_input_queue (mp->client_index);
624 if (mp->is_index_set)
625 ls_index = htonl (mp->ls_index);
628 /* make sure we get a proper C-string */
629 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
630 ls_name = format (0, "%s", mp->ls_name);
631 p = hash_get_mem (lcm->locator_set_index_by_name, ls_name);
637 if (pool_is_free_index (lcm->locator_set_pool, ls_index))
640 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
642 vec_foreach (locit, lsit->locator_indices)
644 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
645 send_one_locator_details (lcm, loc, q, mp->context);
652 send_one_locator_set_details (lisp_cp_main_t * lcm,
653 locator_set_t * lsit,
654 unix_shared_memory_queue_t * q,
655 u32 context, u32 ls_index)
657 vl_api_one_locator_set_details_t *rmp;
660 rmp = vl_msg_api_alloc (sizeof (*rmp));
661 memset (rmp, 0, sizeof (*rmp));
662 rmp->_vl_msg_id = ntohs (VL_API_ONE_LOCATOR_SET_DETAILS);
663 rmp->context = context;
665 rmp->ls_index = htonl (ls_index);
668 ASSERT (lsit->name != NULL);
669 strncpy ((char *) rmp->ls_name, (char *) lsit->name,
670 vec_len (lsit->name));
674 str = format (0, "<remote-%d>", ls_index);
675 strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str));
679 vl_msg_api_send_shmem (q, (u8 *) & rmp);
683 vl_api_one_locator_set_dump_t_handler (vl_api_one_locator_set_dump_t * mp)
685 unix_shared_memory_queue_t *q = NULL;
686 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
687 locator_set_t *lsit = NULL;
690 q = vl_api_client_index_to_input_queue (mp->client_index);
698 pool_foreach (lsit, lcm->locator_set_pool,
700 if (filter && !((1 == filter && lsit->local) ||
701 (2 == filter && !lsit->local)))
705 send_one_locator_set_details (lcm, lsit, q, mp->context,
706 lsit - lcm->locator_set_pool);
712 one_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length)
714 ASSERT (prefix_length);
715 ip_prefix_t *ippref = &fid_addr_ippref (src);
717 switch (fid_addr_type (src))
719 case FID_ADDR_IP_PREF:
720 if (ip_prefix_version (ippref) == IP4)
721 clib_memcpy (dst, &ip_prefix_v4 (ippref), 4);
723 clib_memcpy (dst, &ip_prefix_v6 (ippref), 16);
724 prefix_length[0] = ip_prefix_len (ippref);
728 prefix_length[0] = 0;
729 clib_memcpy (dst, fid_addr_mac (src), 6);
733 clib_warning ("Unknown FID type %d!", fid_addr_type (src));
739 fid_type_to_api_type (fid_address_t * fid)
743 switch (fid_addr_type (fid))
745 case FID_ADDR_IP_PREF:
746 ippref = &fid_addr_ippref (fid);
747 if (ip_prefix_version (ippref) == IP4)
749 else if (ip_prefix_version (ippref) == IP6)
764 send_one_eid_table_details (mapping_t * mapit,
765 unix_shared_memory_queue_t * q,
766 u32 context, u8 filter)
769 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
770 locator_set_t *ls = 0;
771 vl_api_one_eid_table_details_t *rmp = NULL;
772 gid_address_t *gid = NULL;
774 ip_prefix_t *ip_prefix = NULL;
781 case 0: /* all mappings */
784 case 1: /* local only */
788 case 2: /* remote only */
793 clib_warning ("Filter error, unknown filter: %d", filter);
798 ip_prefix = &gid_address_ippref (gid);
799 mac = gid_address_mac (gid);
801 rmp = vl_msg_api_alloc (sizeof (*rmp));
802 memset (rmp, 0, sizeof (*rmp));
803 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_DETAILS);
805 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
806 if (vec_len (ls->locator_indices) == 0)
807 rmp->locator_set_index = ~0;
809 rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
811 rmp->is_local = mapit->local;
812 rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
813 rmp->action = mapit->action;
814 rmp->authoritative = mapit->authoritative;
816 switch (gid_address_type (gid))
818 case GID_ADDR_SRC_DST:
820 fid = &gid_address_sd_src (gid);
821 rmp->eid_type = fid_type_to_api_type (fid);
822 one_fid_put_api (rmp->seid, &gid_address_sd_src (gid),
823 &rmp->seid_prefix_len);
824 one_fid_put_api (rmp->eid, &gid_address_sd_dst (gid),
825 &rmp->eid_prefix_len);
827 case GID_ADDR_IP_PREFIX:
828 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
829 if (ip_prefix_version (ip_prefix) == IP4)
831 rmp->eid_type = 0; /* ipv4 type */
832 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
833 sizeof (ip_prefix_v4 (ip_prefix)));
837 rmp->eid_type = 1; /* ipv6 type */
838 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
839 sizeof (ip_prefix_v6 (ip_prefix)));
843 rmp->eid_type = 2; /* l2 mac type */
844 clib_memcpy (rmp->eid, mac, 6);
849 rmp->context = context;
850 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
851 rmp->key_id = clib_host_to_net_u16 (mapit->key_id);
852 memcpy (rmp->key, mapit->key, vec_len (mapit->key));
853 vl_msg_api_send_shmem (q, (u8 *) & rmp);
857 vl_api_one_eid_table_dump_t_handler (vl_api_one_eid_table_dump_t * mp)
860 unix_shared_memory_queue_t *q = NULL;
861 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
862 mapping_t *mapit = NULL;
863 gid_address_t _eid, *eid = &_eid;
865 q = vl_api_client_index_to_input_queue (mp->client_index);
873 memset (eid, 0, sizeof (*eid));
875 unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
876 mp->eid_type, mp->eid, mp->prefix_length);
878 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
882 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
883 send_one_eid_table_details (mapit, q, mp->context,
884 0 /* ignore filter */ );
889 pool_foreach (mapit, lcm->mapping_pool,
891 send_one_eid_table_details(mapit, q, mp->context,
899 send_one_map_server_details (ip_address_t * ip,
900 unix_shared_memory_queue_t * q, u32 context)
902 vl_api_one_map_server_details_t *rmp = NULL;
904 rmp = vl_msg_api_alloc (sizeof (*rmp));
905 memset (rmp, 0, sizeof (*rmp));
906 rmp->_vl_msg_id = ntohs (VL_API_ONE_MAP_SERVER_DETAILS);
908 switch (ip_addr_version (ip))
912 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
913 sizeof (ip_addr_v4 (ip)));
918 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
919 sizeof (ip_addr_v6 (ip)));
925 rmp->context = context;
927 vl_msg_api_send_shmem (q, (u8 *) & rmp);
931 vl_api_one_map_server_dump_t_handler (vl_api_one_map_server_dump_t * mp)
933 unix_shared_memory_queue_t *q = NULL;
934 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
937 q = vl_api_client_index_to_input_queue (mp->client_index);
943 vec_foreach (mr, lcm->map_servers)
945 send_one_map_server_details (&mr->address, q, mp->context);
950 send_one_map_resolver_details (ip_address_t * ip,
951 unix_shared_memory_queue_t * q, u32 context)
953 vl_api_one_map_resolver_details_t *rmp = NULL;
955 rmp = vl_msg_api_alloc (sizeof (*rmp));
956 memset (rmp, 0, sizeof (*rmp));
957 rmp->_vl_msg_id = ntohs (VL_API_ONE_MAP_RESOLVER_DETAILS);
959 switch (ip_addr_version (ip))
963 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
964 sizeof (ip_addr_v4 (ip)));
969 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
970 sizeof (ip_addr_v6 (ip)));
976 rmp->context = context;
978 vl_msg_api_send_shmem (q, (u8 *) & rmp);
982 vl_api_one_map_resolver_dump_t_handler (vl_api_one_map_resolver_dump_t * mp)
984 unix_shared_memory_queue_t *q = NULL;
985 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
988 q = vl_api_client_index_to_input_queue (mp->client_index);
994 vec_foreach (mr, lcm->map_resolvers)
996 send_one_map_resolver_details (&mr->address, q, mp->context);
1001 send_eid_table_map_pair (hash_pair_t * p,
1002 unix_shared_memory_queue_t * q, u32 context)
1004 vl_api_one_eid_table_map_details_t *rmp = NULL;
1006 rmp = vl_msg_api_alloc (sizeof (*rmp));
1007 memset (rmp, 0, sizeof (*rmp));
1008 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_MAP_DETAILS);
1010 rmp->vni = clib_host_to_net_u32 (p->key);
1011 rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
1012 rmp->context = context;
1013 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1017 vl_api_one_eid_table_map_dump_t_handler (vl_api_one_eid_table_map_dump_t * mp)
1019 unix_shared_memory_queue_t *q = NULL;
1020 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1022 uword *vni_table = 0;
1024 q = vl_api_client_index_to_input_queue (mp->client_index);
1032 vni_table = lcm->bd_id_by_vni;
1036 vni_table = lcm->table_id_by_vni;
1040 hash_foreach_pair (p, vni_table,
1042 send_eid_table_map_pair (p, q, mp->context);
1048 send_eid_table_vni (u32 vni, unix_shared_memory_queue_t * q, u32 context)
1050 vl_api_one_eid_table_vni_details_t *rmp = 0;
1052 rmp = vl_msg_api_alloc (sizeof (*rmp));
1053 memset (rmp, 0, sizeof (*rmp));
1054 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_VNI_DETAILS);
1055 rmp->context = context;
1056 rmp->vni = clib_host_to_net_u32 (vni);
1057 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1061 one_adjacency_copy (vl_api_one_adjacency_t * dst, lisp_adjacency_t * adjs)
1063 lisp_adjacency_t *adj;
1064 vl_api_one_adjacency_t a;
1065 u32 i, n = vec_len (adjs);
1067 for (i = 0; i < n; i++)
1069 adj = vec_elt_at_index (adjs, i);
1070 memset (&a, 0, sizeof (a));
1072 switch (gid_address_type (&adj->reid))
1074 case GID_ADDR_IP_PREFIX:
1075 a.reid_prefix_len = gid_address_ippref_len (&adj->reid);
1076 a.leid_prefix_len = gid_address_ippref_len (&adj->leid);
1077 if (gid_address_ip_version (&adj->reid) == IP4)
1079 a.eid_type = 0; /* ipv4 type */
1080 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 4);
1081 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 4);
1085 a.eid_type = 1; /* ipv6 type */
1086 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 16);
1087 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 16);
1091 a.eid_type = 2; /* l2 mac type */
1092 mac_copy (a.reid, gid_address_mac (&adj->reid));
1093 mac_copy (a.leid, gid_address_mac (&adj->leid));
1103 vl_api_show_one_rloc_probe_state_t_handler
1104 (vl_api_show_one_rloc_probe_state_t * mp)
1106 vl_api_show_one_rloc_probe_state_reply_t *rmp = 0;
1110 REPLY_MACRO2 (VL_API_SHOW_ONE_RLOC_PROBE_STATE_REPLY,
1112 rmp->is_enabled = vnet_lisp_rloc_probe_state_get ();
1118 vl_api_show_one_map_register_state_t_handler
1119 (vl_api_show_one_map_register_state_t * mp)
1121 vl_api_show_one_map_register_state_reply_t *rmp = 0;
1125 REPLY_MACRO2 (VL_API_SHOW_ONE_MAP_REGISTER_STATE_REPLY,
1127 rmp->is_enabled = vnet_lisp_map_register_state_get ();
1133 vl_api_one_adjacencies_get_t_handler (vl_api_one_adjacencies_get_t * mp)
1135 vl_api_one_adjacencies_get_reply_t *rmp = 0;
1136 lisp_adjacency_t *adjs = 0;
1139 u32 vni = clib_net_to_host_u32 (mp->vni);
1141 adjs = vnet_lisp_adjacencies_get_by_vni (vni);
1142 size = vec_len (adjs) * sizeof (vl_api_one_adjacency_t);
1145 REPLY_MACRO4 (VL_API_ONE_ADJACENCIES_GET_REPLY, size,
1147 rmp->count = clib_host_to_net_u32 (vec_len (adjs));
1148 one_adjacency_copy (rmp->adjacencies, adjs);
1156 vl_api_one_eid_table_vni_dump_t_handler (vl_api_one_eid_table_vni_dump_t * mp)
1160 unix_shared_memory_queue_t *q = 0;
1161 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1163 q = vl_api_client_index_to_input_queue (mp->client_index);
1170 hash_foreach_pair (p, lcm->table_id_by_vni,
1172 hash_set (vnis, p->key, 0);
1175 hash_foreach_pair (p, lcm->bd_id_by_vni,
1177 hash_set (vnis, p->key, 0);
1180 hash_foreach_pair (p, vnis,
1182 send_eid_table_vni (p->key, q, mp->context);
1190 vl_api_show_one_status_t_handler (vl_api_show_one_status_t * mp)
1192 unix_shared_memory_queue_t *q = NULL;
1193 vl_api_show_one_status_reply_t *rmp = NULL;
1196 q = vl_api_client_index_to_input_queue (mp->client_index);
1203 REPLY_MACRO2(VL_API_SHOW_ONE_STATUS_REPLY,
1205 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
1206 rmp->feature_status = vnet_lisp_enable_disable_status ();
1212 vl_api_one_get_map_request_itr_rlocs_t_handler
1213 (vl_api_one_get_map_request_itr_rlocs_t * mp)
1215 unix_shared_memory_queue_t *q = NULL;
1216 vl_api_one_get_map_request_itr_rlocs_reply_t *rmp = NULL;
1217 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1218 locator_set_t *loc_set = 0;
1222 q = vl_api_client_index_to_input_queue (mp->client_index);
1228 if (~0 == lcm->mreq_itr_rlocs)
1230 tmp_str = format (0, " ");
1235 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
1236 tmp_str = format (0, "%s", loc_set->name);
1240 REPLY_MACRO2(VL_API_ONE_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
1242 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1243 ARRAY_LEN(rmp->locator_set_name) - 1);
1251 vl_api_show_one_pitr_t_handler (vl_api_show_one_pitr_t * mp)
1253 unix_shared_memory_queue_t *q = NULL;
1254 vl_api_show_one_pitr_reply_t *rmp = NULL;
1255 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1257 locator_set_t *ls = 0;
1261 q = vl_api_client_index_to_input_queue (mp->client_index);
1267 if (!lcm->lisp_pitr)
1269 tmp_str = format (0, "N/A");
1273 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
1274 if (~0 != m->locator_set_index)
1277 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
1278 tmp_str = format (0, "%s", ls->name);
1282 tmp_str = format (0, "N/A");
1285 vec_add1 (tmp_str, 0);
1288 REPLY_MACRO2(VL_API_SHOW_ONE_PITR_REPLY,
1290 rmp->status = lcm->lisp_pitr;
1291 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1292 ARRAY_LEN(rmp->locator_set_name) - 1);
1298 vl_api_show_one_stats_enable_disable_t_handler
1299 (vl_api_show_one_stats_enable_disable_t * mp)
1301 vl_api_show_one_stats_enable_disable_reply_t *rmp = NULL;
1302 vnet_api_error_t rv = 0;
1305 REPLY_MACRO2 (VL_API_SHOW_ONE_STATS_ENABLE_DISABLE_REPLY,
1307 rmp->is_en = vnet_lisp_stats_enable_disable_state ();
1313 vl_api_one_stats_enable_disable_t_handler
1314 (vl_api_one_stats_enable_disable_t * mp)
1316 vl_api_one_enable_disable_reply_t *rmp = NULL;
1318 vnet_api_error_t rv = vnet_lisp_stats_enable_disable (mp->is_en);
1319 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
1323 lisp_fid_addr_to_api (fid_address_t * fid, u8 * dst, u8 * api_eid_type,
1326 switch (fid_addr_type (fid))
1328 case FID_ADDR_IP_PREF:
1329 *prefix_length = fid_addr_prefix_length (fid);
1330 if (fid_addr_ip_version (fid) == IP4)
1332 *api_eid_type = 0; /* ipv4 type */
1333 clib_memcpy (dst, &fid_addr_ippref (fid), 4);
1337 *api_eid_type = 1; /* ipv6 type */
1338 clib_memcpy (dst, &fid_addr_ippref (fid), 16);
1342 *api_eid_type = 2; /* l2 mac type */
1343 mac_copy (dst, fid_addr_mac (fid));
1351 vl_api_one_stats_flush_t_handler (vl_api_one_stats_flush_t * mp)
1353 vl_api_one_stats_flush_reply_t *rmp;
1356 rv = vnet_lisp_flush_stats ();
1357 REPLY_MACRO (VL_API_ONE_STATS_FLUSH_REPLY);
1361 vl_api_one_stats_dump_t_handler (vl_api_one_stats_dump_t * mp)
1363 vl_api_one_stats_details_t *rmp;
1364 lisp_api_stats_t *stats, *stat;
1367 stats = vnet_lisp_get_stats ();
1368 vec_foreach (stat, stats)
1371 REPLY_DETAILS (VL_API_ONE_STATS_DETAILS,
1373 lisp_fid_addr_to_api (&stat->deid, rmp->deid, &rmp->eid_type,
1374 &rmp->deid_pref_len);
1375 lisp_fid_addr_to_api (&stat->seid, rmp->seid, &rmp->eid_type,
1376 &rmp->seid_pref_len);
1377 rmp->vni = clib_host_to_net_u32 (stat->vni);
1379 rmp->is_ip4 = ip_addr_version (&stat->rmt_rloc) == IP4 ? 1 : 0;
1380 ip_address_copy_addr (rmp->rloc, &stat->rmt_rloc);
1381 ip_address_copy_addr (rmp->lloc, &stat->loc_rloc);
1383 rmp->pkt_count = clib_host_to_net_u32 (stat->counters.packets);
1384 rmp->bytes = clib_host_to_net_u32 (stat->counters.bytes);
1392 * Add vpe's API message handlers to the table.
1393 * vlib has alread mapped shared memory and
1394 * added the client registration handlers.
1395 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
1397 #define vl_msg_name_crc_list
1398 #include <vnet/vnet_all_api_h.h>
1399 #undef vl_msg_name_crc_list
1402 setup_message_id_table (api_main_t * am)
1404 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
1405 foreach_vl_msg_name_crc_one;
1409 static clib_error_t *
1410 one_api_hookup (vlib_main_t * vm)
1412 api_main_t *am = &api_main;
1415 vl_msg_api_set_handlers(VL_API_##N, #n, \
1416 vl_api_##n##_t_handler, \
1418 vl_api_##n##_t_endian, \
1419 vl_api_##n##_t_print, \
1420 sizeof(vl_api_##n##_t), 1);
1421 foreach_vpe_api_msg;
1425 * Set up the (msg_name, crc, message-id) table
1427 setup_message_id_table (am);
1432 VLIB_API_INIT_FUNCTION (one_api_hookup);
1435 * fd.io coding-style-patch-verification: ON
1438 * eval: (c-set-style "gnu")