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) \
114 unformat_one_locs (vl_api_one_remote_locator_t * rmt_locs, u32 rloc_num)
117 locator_t *locs = 0, loc;
118 vl_api_one_remote_locator_t *r;
120 for (i = 0; i < rloc_num; i++)
122 /* remote locators */
124 memset (&loc, 0, sizeof (loc));
125 gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
127 loc.priority = r->priority;
128 loc.weight = r->weight;
130 vec_add1 (locs, loc);
136 vl_api_one_add_del_locator_set_t_handler (vl_api_one_add_del_locator_set_t *
139 vl_api_one_add_del_locator_set_reply_t *rmp;
141 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
143 vl_api_one_local_locator_t *ls_loc;
144 u32 ls_index = ~0, locator_num;
145 u8 *locator_name = NULL;
148 memset (a, 0, sizeof (a[0]));
150 locator_name = format (0, "%s", mp->locator_set_name);
152 a->name = locator_name;
153 a->is_add = mp->is_add;
155 locator_num = clib_net_to_host_u32 (mp->locator_num);
157 memset (&locator, 0, sizeof (locator));
158 for (i = 0; i < locator_num; i++)
160 ls_loc = &mp->locators[i];
161 VALIDATE_SW_IF_INDEX (ls_loc);
163 locator.sw_if_index = htonl (ls_loc->sw_if_index);
164 locator.priority = ls_loc->priority;
165 locator.weight = ls_loc->weight;
167 vec_add1 (a->locators, locator);
170 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
172 BAD_SW_IF_INDEX_LABEL;
174 vec_free (locator_name);
175 vec_free (a->locators);
178 REPLY_MACRO2 (VL_API_ONE_ADD_DEL_LOCATOR_SET_REPLY,
180 rmp->ls_index = clib_host_to_net_u32 (ls_index);
186 vl_api_one_add_del_locator_t_handler (vl_api_one_add_del_locator_t * mp)
188 vl_api_one_add_del_locator_reply_t *rmp;
190 locator_t locator, *locators = NULL;
191 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
193 u8 *locator_name = NULL;
195 memset (&locator, 0, sizeof (locator));
196 memset (a, 0, sizeof (a[0]));
198 locator.sw_if_index = ntohl (mp->sw_if_index);
199 locator.priority = mp->priority;
200 locator.weight = mp->weight;
202 vec_add1 (locators, locator);
204 locator_name = format (0, "%s", mp->locator_set_name);
206 a->name = locator_name;
207 a->locators = locators;
208 a->is_add = mp->is_add;
211 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
214 vec_free (locator_name);
216 REPLY_MACRO (VL_API_ONE_ADD_DEL_LOCATOR_REPLY);
220 unformat_one_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
226 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
227 gid_address_ip_set (dst, src, IP4);
228 gid_address_ippref_len (dst) = len;
229 ip_prefix_normalize (&gid_address_ippref (dst));
232 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
233 gid_address_ip_set (dst, src, IP6);
234 gid_address_ippref_len (dst) = len;
235 ip_prefix_normalize (&gid_address_ippref (dst));
238 gid_address_type (dst) = GID_ADDR_MAC;
239 clib_memcpy (&gid_address_mac (dst), src, 6);
243 return VNET_API_ERROR_INVALID_VALUE;
246 gid_address_vni (dst) = vni;
252 vl_api_one_add_del_local_eid_t_handler (vl_api_one_add_del_local_eid_t * mp)
254 vl_api_one_add_del_local_eid_reply_t *rmp;
255 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
257 gid_address_t _eid, *eid = &_eid;
259 u32 locator_set_index = ~0, map_index = ~0;
260 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
261 u8 *name = NULL, *key = NULL;
262 memset (a, 0, sizeof (a[0]));
263 memset (eid, 0, sizeof (eid[0]));
265 rv = unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
266 mp->eid_type, mp->eid, mp->prefix_len);
270 name = format (0, "%s", mp->locator_set_name);
271 p = hash_get_mem (lcm->locator_set_index_by_name, name);
274 rv = VNET_API_ERROR_INVALID_VALUE;
277 locator_set_index = p[0];
280 key = format (0, "%s", mp->key);
282 /* XXX treat batch configuration */
283 a->is_add = mp->is_add;
284 gid_address_copy (&a->eid, eid);
285 a->locator_set_index = locator_set_index;
288 a->key_id = clib_net_to_host_u16 (mp->key_id);
290 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
295 gid_address_free (&a->eid);
297 REPLY_MACRO (VL_API_ONE_ADD_DEL_LOCAL_EID_REPLY);
301 vl_api_one_eid_table_add_del_map_t_handler
302 (vl_api_one_eid_table_add_del_map_t * mp)
304 vl_api_one_eid_table_add_del_map_reply_t *rmp;
306 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
307 clib_net_to_host_u32 (mp->dp_table),
308 mp->is_l2, mp->is_add);
309 REPLY_MACRO (VL_API_ONE_EID_TABLE_ADD_DEL_MAP_REPLY)}
312 vl_api_one_add_del_map_server_t_handler (vl_api_one_add_del_map_server_t * mp)
314 vl_api_one_add_del_map_server_reply_t *rmp;
318 memset (&addr, 0, sizeof (addr));
320 ip_address_set (&addr, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
321 rv = vnet_lisp_add_del_map_server (&addr, mp->is_add);
323 REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_SERVER_REPLY);
327 vl_api_one_add_del_map_resolver_t_handler (vl_api_one_add_del_map_resolver_t
330 vl_api_one_add_del_map_resolver_reply_t *rmp;
332 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
334 memset (a, 0, sizeof (a[0]));
336 a->is_add = mp->is_add;
337 ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
339 rv = vnet_lisp_add_del_map_resolver (a);
341 REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_RESOLVER_REPLY);
345 vl_api_one_map_register_enable_disable_t_handler
346 (vl_api_one_map_register_enable_disable_t * mp)
348 vl_api_one_map_register_enable_disable_reply_t *rmp;
351 vnet_lisp_map_register_enable_disable (mp->is_enabled);
352 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
356 vl_api_one_rloc_probe_enable_disable_t_handler
357 (vl_api_one_rloc_probe_enable_disable_t * mp)
359 vl_api_one_rloc_probe_enable_disable_reply_t *rmp;
362 vnet_lisp_rloc_probe_enable_disable (mp->is_enabled);
363 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
367 vl_api_one_enable_disable_t_handler (vl_api_one_enable_disable_t * mp)
369 vl_api_one_enable_disable_reply_t *rmp;
372 vnet_lisp_enable_disable (mp->is_en);
373 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
377 vl_api_show_one_map_request_mode_t_handler
378 (vl_api_show_one_map_request_mode_t * mp)
381 vl_api_show_one_map_request_mode_reply_t *rmp;
384 REPLY_MACRO2(VL_API_SHOW_ONE_MAP_REQUEST_MODE_REPLY,
386 rmp->mode = vnet_lisp_get_map_request_mode ();
392 vl_api_one_map_request_mode_t_handler (vl_api_one_map_request_mode_t * mp)
394 vl_api_one_map_request_mode_reply_t *rmp;
397 rv = vnet_lisp_set_map_request_mode (mp->mode);
399 REPLY_MACRO (VL_API_ONE_MAP_REQUEST_MODE_REPLY);
403 vl_api_one_pitr_set_locator_set_t_handler (vl_api_one_pitr_set_locator_set_t
406 vl_api_one_pitr_set_locator_set_reply_t *rmp;
410 ls_name = format (0, "%s", mp->ls_name);
411 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
414 REPLY_MACRO (VL_API_ONE_PITR_SET_LOCATOR_SET_REPLY);
418 vl_api_one_use_petr_t_handler (vl_api_one_use_petr_t * mp)
420 vl_api_one_use_petr_reply_t *rmp;
424 ip_address_set (&addr, &mp->address, mp->is_ip4 ? IP4 : IP6);
425 rv = vnet_lisp_use_petr (&addr, mp->is_add);
427 REPLY_MACRO (VL_API_ONE_USE_PETR_REPLY);
431 vl_api_show_one_use_petr_t_handler (vl_api_show_one_use_petr_t * mp)
433 unix_shared_memory_queue_t *q = NULL;
434 vl_api_show_one_use_petr_reply_t *rmp = NULL;
435 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
437 locator_set_t *ls = 0;
443 q = vl_api_client_index_to_input_queue (mp->client_index);
449 memset (&addr, 0, sizeof (addr));
450 status = lcm->flags & LISP_FLAG_USE_PETR;
453 m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index);
454 if (~0 != m->locator_set_index)
457 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
458 loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]);
459 gid_address_copy (&addr, &loc->address);
464 REPLY_MACRO2 (VL_API_SHOW_ONE_USE_PETR_REPLY,
466 rmp->status = status;
467 ip_address_t *ip = &gid_address_ip (&addr);
468 switch (ip_addr_version (ip))
471 clib_memcpy (rmp->address, &ip_addr_v4 (ip),
472 sizeof (ip_addr_v4 (ip)));
476 clib_memcpy (rmp->address, &ip_addr_v6 (ip),
477 sizeof (ip_addr_v6 (ip)));
483 rmp->is_ip4 = (gid_address_ip_version (&addr) == IP4);
489 vl_api_one_add_del_map_request_itr_rlocs_t_handler
490 (vl_api_one_add_del_map_request_itr_rlocs_t * mp)
492 vl_api_one_add_del_map_request_itr_rlocs_reply_t *rmp;
494 u8 *locator_set_name = NULL;
495 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
497 locator_set_name = format (0, "%s", mp->locator_set_name);
499 a->is_add = mp->is_add;
500 a->locator_set_name = locator_set_name;
502 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
504 vec_free (locator_set_name);
506 REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
510 vl_api_one_add_del_remote_mapping_t_handler
511 (vl_api_one_add_del_remote_mapping_t * mp)
513 locator_t *rlocs = 0;
514 vl_api_one_add_del_remote_mapping_reply_t *rmp;
516 gid_address_t _eid, *eid = &_eid;
517 u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
519 memset (eid, 0, sizeof (eid[0]));
521 rv = unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
522 mp->eid_type, mp->eid, mp->eid_len);
526 rlocs = unformat_one_locs (mp->rlocs, rloc_num);
530 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
531 gid_address_copy (&a->reid, eid);
533 rv = vnet_lisp_add_del_adjacency (a);
540 /* NOTE: for now this works as a static remote mapping, i.e.,
541 * not authoritative and ttl infinite. */
542 rv = vnet_lisp_add_del_mapping (eid, rlocs, mp->action, 0, ~0,
543 mp->is_add, 1 /* is_static */ , 0);
546 vnet_lisp_clear_all_remote_adjacencies ();
551 REPLY_MACRO (VL_API_ONE_ADD_DEL_REMOTE_MAPPING_REPLY);
555 vl_api_one_add_del_adjacency_t_handler (vl_api_one_add_del_adjacency_t * mp)
557 vl_api_one_add_del_adjacency_reply_t *rmp;
558 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
561 memset (a, 0, sizeof (a[0]));
563 rv = unformat_one_eid_api (&a->leid, clib_net_to_host_u32 (mp->vni),
564 mp->eid_type, mp->leid, mp->leid_len);
565 rv |= unformat_one_eid_api (&a->reid, clib_net_to_host_u32 (mp->vni),
566 mp->eid_type, mp->reid, mp->reid_len);
571 a->is_add = mp->is_add;
572 rv = vnet_lisp_add_del_adjacency (a);
575 REPLY_MACRO (VL_API_ONE_ADD_DEL_ADJACENCY_REPLY);
579 send_one_locator_details (lisp_cp_main_t * lcm,
581 unix_shared_memory_queue_t * q, u32 context)
583 vl_api_one_locator_details_t *rmp;
585 rmp = vl_msg_api_alloc (sizeof (*rmp));
586 memset (rmp, 0, sizeof (*rmp));
587 rmp->_vl_msg_id = ntohs (VL_API_ONE_LOCATOR_DETAILS);
588 rmp->context = context;
590 rmp->local = loc->local;
593 rmp->sw_if_index = ntohl (loc->sw_if_index);
597 rmp->is_ipv6 = gid_address_ip_version (&loc->address);
598 ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
600 rmp->priority = loc->priority;
601 rmp->weight = loc->weight;
603 vl_msg_api_send_shmem (q, (u8 *) & rmp);
607 vl_api_one_locator_dump_t_handler (vl_api_one_locator_dump_t * mp)
610 unix_shared_memory_queue_t *q = 0;
611 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
612 locator_set_t *lsit = 0;
614 u32 ls_index = ~0, *locit = 0;
617 q = vl_api_client_index_to_input_queue (mp->client_index);
623 if (mp->is_index_set)
624 ls_index = htonl (mp->ls_index);
627 /* make sure we get a proper C-string */
628 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
629 ls_name = format (0, "%s", mp->ls_name);
630 p = hash_get_mem (lcm->locator_set_index_by_name, ls_name);
636 if (pool_is_free_index (lcm->locator_set_pool, ls_index))
639 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
641 vec_foreach (locit, lsit->locator_indices)
643 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
644 send_one_locator_details (lcm, loc, q, mp->context);
651 send_one_locator_set_details (lisp_cp_main_t * lcm,
652 locator_set_t * lsit,
653 unix_shared_memory_queue_t * q,
654 u32 context, u32 ls_index)
656 vl_api_one_locator_set_details_t *rmp;
659 rmp = vl_msg_api_alloc (sizeof (*rmp));
660 memset (rmp, 0, sizeof (*rmp));
661 rmp->_vl_msg_id = ntohs (VL_API_ONE_LOCATOR_SET_DETAILS);
662 rmp->context = context;
664 rmp->ls_index = htonl (ls_index);
667 ASSERT (lsit->name != NULL);
668 strncpy ((char *) rmp->ls_name, (char *) lsit->name,
669 vec_len (lsit->name));
673 str = format (0, "<remote-%d>", ls_index);
674 strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str));
678 vl_msg_api_send_shmem (q, (u8 *) & rmp);
682 vl_api_one_locator_set_dump_t_handler (vl_api_one_locator_set_dump_t * mp)
684 unix_shared_memory_queue_t *q = NULL;
685 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
686 locator_set_t *lsit = NULL;
689 q = vl_api_client_index_to_input_queue (mp->client_index);
697 pool_foreach (lsit, lcm->locator_set_pool,
699 if (filter && !((1 == filter && lsit->local) ||
700 (2 == filter && !lsit->local)))
704 send_one_locator_set_details (lcm, lsit, q, mp->context,
705 lsit - lcm->locator_set_pool);
711 one_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length)
713 ASSERT (prefix_length);
714 ip_prefix_t *ippref = &fid_addr_ippref (src);
716 switch (fid_addr_type (src))
718 case FID_ADDR_IP_PREF:
719 if (ip_prefix_version (ippref) == IP4)
720 clib_memcpy (dst, &ip_prefix_v4 (ippref), 4);
722 clib_memcpy (dst, &ip_prefix_v6 (ippref), 16);
723 prefix_length[0] = ip_prefix_len (ippref);
727 prefix_length[0] = 0;
728 clib_memcpy (dst, fid_addr_mac (src), 6);
732 clib_warning ("Unknown FID type %d!", fid_addr_type (src));
738 fid_type_to_api_type (fid_address_t * fid)
742 switch (fid_addr_type (fid))
744 case FID_ADDR_IP_PREF:
745 ippref = &fid_addr_ippref (fid);
746 if (ip_prefix_version (ippref) == IP4)
748 else if (ip_prefix_version (ippref) == IP6)
763 send_one_eid_table_details (mapping_t * mapit,
764 unix_shared_memory_queue_t * q,
765 u32 context, u8 filter)
768 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
769 locator_set_t *ls = 0;
770 vl_api_one_eid_table_details_t *rmp = NULL;
771 gid_address_t *gid = NULL;
773 ip_prefix_t *ip_prefix = NULL;
777 case 0: /* all mappings */
780 case 1: /* local only */
784 case 2: /* remote only */
789 clib_warning ("Filter error, unknown filter: %d", filter);
794 ip_prefix = &gid_address_ippref (gid);
795 mac = gid_address_mac (gid);
797 rmp = vl_msg_api_alloc (sizeof (*rmp));
798 memset (rmp, 0, sizeof (*rmp));
799 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_DETAILS);
801 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
802 if (vec_len (ls->locator_indices) == 0)
803 rmp->locator_set_index = ~0;
805 rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
807 rmp->is_local = mapit->local;
808 rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
809 rmp->action = mapit->action;
810 rmp->authoritative = mapit->authoritative;
812 switch (gid_address_type (gid))
814 case GID_ADDR_SRC_DST:
816 fid = &gid_address_sd_src (gid);
817 rmp->eid_type = fid_type_to_api_type (fid);
818 one_fid_put_api (rmp->seid, &gid_address_sd_src (gid),
819 &rmp->seid_prefix_len);
820 one_fid_put_api (rmp->eid, &gid_address_sd_dst (gid),
821 &rmp->eid_prefix_len);
823 case GID_ADDR_IP_PREFIX:
824 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
825 if (ip_prefix_version (ip_prefix) == IP4)
827 rmp->eid_type = 0; /* ipv4 type */
828 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
829 sizeof (ip_prefix_v4 (ip_prefix)));
833 rmp->eid_type = 1; /* ipv6 type */
834 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
835 sizeof (ip_prefix_v6 (ip_prefix)));
839 rmp->eid_type = 2; /* l2 mac type */
840 clib_memcpy (rmp->eid, mac, 6);
845 rmp->context = context;
846 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
847 rmp->key_id = clib_host_to_net_u16 (mapit->key_id);
848 memcpy (rmp->key, mapit->key, vec_len (mapit->key));
849 vl_msg_api_send_shmem (q, (u8 *) & rmp);
853 vl_api_one_eid_table_dump_t_handler (vl_api_one_eid_table_dump_t * mp)
856 unix_shared_memory_queue_t *q = NULL;
857 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
858 mapping_t *mapit = NULL;
859 gid_address_t _eid, *eid = &_eid;
861 q = vl_api_client_index_to_input_queue (mp->client_index);
869 memset (eid, 0, sizeof (*eid));
871 unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
872 mp->eid_type, mp->eid, mp->prefix_length);
874 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
878 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
879 send_one_eid_table_details (mapit, q, mp->context,
880 0 /* ignore filter */ );
885 pool_foreach (mapit, lcm->mapping_pool,
887 send_one_eid_table_details(mapit, q, mp->context,
895 send_one_map_server_details (ip_address_t * ip,
896 unix_shared_memory_queue_t * q, u32 context)
898 vl_api_one_map_server_details_t *rmp = NULL;
900 rmp = vl_msg_api_alloc (sizeof (*rmp));
901 memset (rmp, 0, sizeof (*rmp));
902 rmp->_vl_msg_id = ntohs (VL_API_ONE_MAP_SERVER_DETAILS);
904 switch (ip_addr_version (ip))
908 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
909 sizeof (ip_addr_v4 (ip)));
914 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
915 sizeof (ip_addr_v6 (ip)));
921 rmp->context = context;
923 vl_msg_api_send_shmem (q, (u8 *) & rmp);
927 vl_api_one_map_server_dump_t_handler (vl_api_one_map_server_dump_t * mp)
929 unix_shared_memory_queue_t *q = NULL;
930 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
933 q = vl_api_client_index_to_input_queue (mp->client_index);
939 vec_foreach (mr, lcm->map_servers)
941 send_one_map_server_details (&mr->address, q, mp->context);
946 send_one_map_resolver_details (ip_address_t * ip,
947 unix_shared_memory_queue_t * q, u32 context)
949 vl_api_one_map_resolver_details_t *rmp = NULL;
951 rmp = vl_msg_api_alloc (sizeof (*rmp));
952 memset (rmp, 0, sizeof (*rmp));
953 rmp->_vl_msg_id = ntohs (VL_API_ONE_MAP_RESOLVER_DETAILS);
955 switch (ip_addr_version (ip))
959 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
960 sizeof (ip_addr_v4 (ip)));
965 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
966 sizeof (ip_addr_v6 (ip)));
972 rmp->context = context;
974 vl_msg_api_send_shmem (q, (u8 *) & rmp);
978 vl_api_one_map_resolver_dump_t_handler (vl_api_one_map_resolver_dump_t * mp)
980 unix_shared_memory_queue_t *q = NULL;
981 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
984 q = vl_api_client_index_to_input_queue (mp->client_index);
990 vec_foreach (mr, lcm->map_resolvers)
992 send_one_map_resolver_details (&mr->address, q, mp->context);
997 send_eid_table_map_pair (hash_pair_t * p,
998 unix_shared_memory_queue_t * q, u32 context)
1000 vl_api_one_eid_table_map_details_t *rmp = NULL;
1002 rmp = vl_msg_api_alloc (sizeof (*rmp));
1003 memset (rmp, 0, sizeof (*rmp));
1004 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_MAP_DETAILS);
1006 rmp->vni = clib_host_to_net_u32 (p->key);
1007 rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
1008 rmp->context = context;
1009 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1013 vl_api_one_eid_table_map_dump_t_handler (vl_api_one_eid_table_map_dump_t * mp)
1015 unix_shared_memory_queue_t *q = NULL;
1016 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1018 uword *vni_table = 0;
1020 q = vl_api_client_index_to_input_queue (mp->client_index);
1028 vni_table = lcm->bd_id_by_vni;
1032 vni_table = lcm->table_id_by_vni;
1036 hash_foreach_pair (p, vni_table,
1038 send_eid_table_map_pair (p, q, mp->context);
1044 send_eid_table_vni (u32 vni, unix_shared_memory_queue_t * q, u32 context)
1046 vl_api_one_eid_table_vni_details_t *rmp = 0;
1048 rmp = vl_msg_api_alloc (sizeof (*rmp));
1049 memset (rmp, 0, sizeof (*rmp));
1050 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_VNI_DETAILS);
1051 rmp->context = context;
1052 rmp->vni = clib_host_to_net_u32 (vni);
1053 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1057 one_adjacency_copy (vl_api_one_adjacency_t * dst, lisp_adjacency_t * adjs)
1059 lisp_adjacency_t *adj;
1060 vl_api_one_adjacency_t a;
1061 u32 i, n = vec_len (adjs);
1063 for (i = 0; i < n; i++)
1065 adj = vec_elt_at_index (adjs, i);
1066 memset (&a, 0, sizeof (a));
1068 switch (gid_address_type (&adj->reid))
1070 case GID_ADDR_IP_PREFIX:
1071 a.reid_prefix_len = gid_address_ippref_len (&adj->reid);
1072 a.leid_prefix_len = gid_address_ippref_len (&adj->leid);
1073 if (gid_address_ip_version (&adj->reid) == IP4)
1075 a.eid_type = 0; /* ipv4 type */
1076 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 4);
1077 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 4);
1081 a.eid_type = 1; /* ipv6 type */
1082 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 16);
1083 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 16);
1087 a.eid_type = 2; /* l2 mac type */
1088 mac_copy (a.reid, gid_address_mac (&adj->reid));
1089 mac_copy (a.leid, gid_address_mac (&adj->leid));
1099 vl_api_show_one_rloc_probe_state_t_handler
1100 (vl_api_show_one_rloc_probe_state_t * mp)
1102 vl_api_show_one_rloc_probe_state_reply_t *rmp = 0;
1106 REPLY_MACRO2 (VL_API_SHOW_ONE_RLOC_PROBE_STATE_REPLY,
1108 rmp->is_enabled = vnet_lisp_rloc_probe_state_get ();
1114 vl_api_show_one_map_register_state_t_handler
1115 (vl_api_show_one_map_register_state_t * mp)
1117 vl_api_show_one_map_register_state_reply_t *rmp = 0;
1121 REPLY_MACRO2 (VL_API_SHOW_ONE_MAP_REGISTER_STATE_REPLY,
1123 rmp->is_enabled = vnet_lisp_map_register_state_get ();
1129 vl_api_one_adjacencies_get_t_handler (vl_api_one_adjacencies_get_t * mp)
1131 vl_api_one_adjacencies_get_reply_t *rmp = 0;
1132 lisp_adjacency_t *adjs = 0;
1135 u32 vni = clib_net_to_host_u32 (mp->vni);
1137 adjs = vnet_lisp_adjacencies_get_by_vni (vni);
1138 size = vec_len (adjs) * sizeof (vl_api_one_adjacency_t);
1141 REPLY_MACRO4 (VL_API_ONE_ADJACENCIES_GET_REPLY, size,
1143 rmp->count = clib_host_to_net_u32 (vec_len (adjs));
1144 one_adjacency_copy (rmp->adjacencies, adjs);
1152 vl_api_one_eid_table_vni_dump_t_handler (vl_api_one_eid_table_vni_dump_t * mp)
1156 unix_shared_memory_queue_t *q = 0;
1157 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1159 q = vl_api_client_index_to_input_queue (mp->client_index);
1166 hash_foreach_pair (p, lcm->table_id_by_vni,
1168 hash_set (vnis, p->key, 0);
1171 hash_foreach_pair (p, lcm->bd_id_by_vni,
1173 hash_set (vnis, p->key, 0);
1176 hash_foreach_pair (p, vnis,
1178 send_eid_table_vni (p->key, q, mp->context);
1186 vl_api_show_one_status_t_handler (vl_api_show_one_status_t * mp)
1188 unix_shared_memory_queue_t *q = NULL;
1189 vl_api_show_one_status_reply_t *rmp = NULL;
1192 q = vl_api_client_index_to_input_queue (mp->client_index);
1199 REPLY_MACRO2(VL_API_SHOW_ONE_STATUS_REPLY,
1201 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
1202 rmp->feature_status = vnet_lisp_enable_disable_status ();
1208 vl_api_one_get_map_request_itr_rlocs_t_handler
1209 (vl_api_one_get_map_request_itr_rlocs_t * mp)
1211 unix_shared_memory_queue_t *q = NULL;
1212 vl_api_one_get_map_request_itr_rlocs_reply_t *rmp = NULL;
1213 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1214 locator_set_t *loc_set = 0;
1218 q = vl_api_client_index_to_input_queue (mp->client_index);
1224 if (~0 == lcm->mreq_itr_rlocs)
1226 tmp_str = format (0, " ");
1231 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
1232 tmp_str = format (0, "%s", loc_set->name);
1236 REPLY_MACRO2(VL_API_ONE_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
1238 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1239 ARRAY_LEN(rmp->locator_set_name) - 1);
1247 vl_api_show_one_pitr_t_handler (vl_api_show_one_pitr_t * mp)
1249 unix_shared_memory_queue_t *q = NULL;
1250 vl_api_show_one_pitr_reply_t *rmp = NULL;
1251 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1253 locator_set_t *ls = 0;
1257 q = vl_api_client_index_to_input_queue (mp->client_index);
1263 if (!lcm->lisp_pitr)
1265 tmp_str = format (0, "N/A");
1269 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
1270 if (~0 != m->locator_set_index)
1273 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
1274 tmp_str = format (0, "%s", ls->name);
1278 tmp_str = format (0, "N/A");
1281 vec_add1 (tmp_str, 0);
1284 REPLY_MACRO2(VL_API_SHOW_ONE_PITR_REPLY,
1286 rmp->status = lcm->lisp_pitr;
1287 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1288 ARRAY_LEN(rmp->locator_set_name) - 1);
1294 vl_api_show_one_stats_enable_disable_t_handler
1295 (vl_api_show_one_stats_enable_disable_t * mp)
1297 vl_api_show_one_stats_enable_disable_reply_t *rmp = NULL;
1298 vnet_api_error_t rv = 0;
1301 REPLY_MACRO2 (VL_API_SHOW_ONE_STATS_ENABLE_DISABLE_REPLY,
1303 rmp->is_en = vnet_lisp_stats_enable_disable_state ();
1309 vl_api_one_stats_enable_disable_t_handler
1310 (vl_api_one_stats_enable_disable_t * mp)
1312 vl_api_one_enable_disable_reply_t *rmp = NULL;
1314 vnet_api_error_t rv = vnet_lisp_stats_enable_disable (mp->is_en);
1315 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
1319 lisp_fid_addr_to_api (fid_address_t * fid, u8 * dst, u8 * api_eid_type,
1322 switch (fid_addr_type (fid))
1324 case FID_ADDR_IP_PREF:
1325 *prefix_length = fid_addr_prefix_length (fid);
1326 if (fid_addr_ip_version (fid) == IP4)
1328 *api_eid_type = 0; /* ipv4 type */
1329 clib_memcpy (dst, &fid_addr_ippref (fid), 4);
1333 *api_eid_type = 1; /* ipv6 type */
1334 clib_memcpy (dst, &fid_addr_ippref (fid), 16);
1338 *api_eid_type = 2; /* l2 mac type */
1339 mac_copy (dst, fid_addr_mac (fid));
1347 vl_api_one_stats_dump_t_handler (vl_api_one_stats_dump_t * mp)
1349 vl_api_one_stats_details_t *rmp;
1350 lisp_api_stats_t *stats, *stat;
1353 stats = vnet_lisp_get_stats ();
1354 vec_foreach (stat, stats)
1357 REPLY_DETAILS (VL_API_ONE_STATS_DETAILS,
1359 lisp_fid_addr_to_api (&stat->deid, rmp->deid, &rmp->eid_type,
1360 &rmp->deid_pref_len);
1361 lisp_fid_addr_to_api (&stat->seid, rmp->seid, &rmp->eid_type,
1362 &rmp->seid_pref_len);
1363 rmp->vni = clib_host_to_net_u32 (stat->vni);
1365 rmp->is_ip4 = ip_addr_version (&stat->rmt_rloc) == IP4 ? 1 : 0;
1366 ip_address_copy_addr (rmp->rloc, &stat->rmt_rloc);
1367 ip_address_copy_addr (rmp->lloc, &stat->loc_rloc);
1369 rmp->pkt_count = clib_host_to_net_u32 (stat->stats.pkt_count);
1370 rmp->bytes = clib_host_to_net_u32 (stat->stats.bytes);
1378 * Add vpe's API message handlers to the table.
1379 * vlib has alread mapped shared memory and
1380 * added the client registration handlers.
1381 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
1383 #define vl_msg_name_crc_list
1384 #include <vnet/vnet_all_api_h.h>
1385 #undef vl_msg_name_crc_list
1388 setup_message_id_table (api_main_t * am)
1390 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
1391 foreach_vl_msg_name_crc_one;
1395 static clib_error_t *
1396 one_api_hookup (vlib_main_t * vm)
1398 api_main_t *am = &api_main;
1401 vl_msg_api_set_handlers(VL_API_##N, #n, \
1402 vl_api_##n##_t_handler, \
1404 vl_api_##n##_t_endian, \
1405 vl_api_##n##_t_print, \
1406 sizeof(vl_api_##n##_t), 1);
1407 foreach_vpe_api_msg;
1411 * Set up the (msg_name, crc, message-id) table
1413 setup_message_id_table (am);
1418 VLIB_API_INIT_FUNCTION (one_api_hookup);
1421 * fd.io coding-style-patch-verification: ON
1424 * eval: (c-set-style "gnu")