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;
780 case 0: /* all mappings */
783 case 1: /* local only */
787 case 2: /* remote only */
792 clib_warning ("Filter error, unknown filter: %d", filter);
797 ip_prefix = &gid_address_ippref (gid);
798 mac = gid_address_mac (gid);
800 rmp = vl_msg_api_alloc (sizeof (*rmp));
801 memset (rmp, 0, sizeof (*rmp));
802 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_DETAILS);
804 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
805 if (vec_len (ls->locator_indices) == 0)
806 rmp->locator_set_index = ~0;
808 rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
810 rmp->is_local = mapit->local;
811 rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
812 rmp->action = mapit->action;
813 rmp->authoritative = mapit->authoritative;
815 switch (gid_address_type (gid))
817 case GID_ADDR_SRC_DST:
819 fid = &gid_address_sd_src (gid);
820 rmp->eid_type = fid_type_to_api_type (fid);
821 one_fid_put_api (rmp->seid, &gid_address_sd_src (gid),
822 &rmp->seid_prefix_len);
823 one_fid_put_api (rmp->eid, &gid_address_sd_dst (gid),
824 &rmp->eid_prefix_len);
826 case GID_ADDR_IP_PREFIX:
827 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
828 if (ip_prefix_version (ip_prefix) == IP4)
830 rmp->eid_type = 0; /* ipv4 type */
831 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
832 sizeof (ip_prefix_v4 (ip_prefix)));
836 rmp->eid_type = 1; /* ipv6 type */
837 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
838 sizeof (ip_prefix_v6 (ip_prefix)));
842 rmp->eid_type = 2; /* l2 mac type */
843 clib_memcpy (rmp->eid, mac, 6);
848 rmp->context = context;
849 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
850 rmp->key_id = clib_host_to_net_u16 (mapit->key_id);
851 memcpy (rmp->key, mapit->key, vec_len (mapit->key));
852 vl_msg_api_send_shmem (q, (u8 *) & rmp);
856 vl_api_one_eid_table_dump_t_handler (vl_api_one_eid_table_dump_t * mp)
859 unix_shared_memory_queue_t *q = NULL;
860 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
861 mapping_t *mapit = NULL;
862 gid_address_t _eid, *eid = &_eid;
864 q = vl_api_client_index_to_input_queue (mp->client_index);
872 memset (eid, 0, sizeof (*eid));
874 unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
875 mp->eid_type, mp->eid, mp->prefix_length);
877 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
881 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
882 send_one_eid_table_details (mapit, q, mp->context,
883 0 /* ignore filter */ );
888 pool_foreach (mapit, lcm->mapping_pool,
890 send_one_eid_table_details(mapit, q, mp->context,
898 send_one_map_server_details (ip_address_t * ip,
899 unix_shared_memory_queue_t * q, u32 context)
901 vl_api_one_map_server_details_t *rmp = NULL;
903 rmp = vl_msg_api_alloc (sizeof (*rmp));
904 memset (rmp, 0, sizeof (*rmp));
905 rmp->_vl_msg_id = ntohs (VL_API_ONE_MAP_SERVER_DETAILS);
907 switch (ip_addr_version (ip))
911 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
912 sizeof (ip_addr_v4 (ip)));
917 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
918 sizeof (ip_addr_v6 (ip)));
924 rmp->context = context;
926 vl_msg_api_send_shmem (q, (u8 *) & rmp);
930 vl_api_one_map_server_dump_t_handler (vl_api_one_map_server_dump_t * mp)
932 unix_shared_memory_queue_t *q = NULL;
933 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
936 q = vl_api_client_index_to_input_queue (mp->client_index);
942 vec_foreach (mr, lcm->map_servers)
944 send_one_map_server_details (&mr->address, q, mp->context);
949 send_one_map_resolver_details (ip_address_t * ip,
950 unix_shared_memory_queue_t * q, u32 context)
952 vl_api_one_map_resolver_details_t *rmp = NULL;
954 rmp = vl_msg_api_alloc (sizeof (*rmp));
955 memset (rmp, 0, sizeof (*rmp));
956 rmp->_vl_msg_id = ntohs (VL_API_ONE_MAP_RESOLVER_DETAILS);
958 switch (ip_addr_version (ip))
962 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
963 sizeof (ip_addr_v4 (ip)));
968 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
969 sizeof (ip_addr_v6 (ip)));
975 rmp->context = context;
977 vl_msg_api_send_shmem (q, (u8 *) & rmp);
981 vl_api_one_map_resolver_dump_t_handler (vl_api_one_map_resolver_dump_t * mp)
983 unix_shared_memory_queue_t *q = NULL;
984 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
987 q = vl_api_client_index_to_input_queue (mp->client_index);
993 vec_foreach (mr, lcm->map_resolvers)
995 send_one_map_resolver_details (&mr->address, q, mp->context);
1000 send_eid_table_map_pair (hash_pair_t * p,
1001 unix_shared_memory_queue_t * q, u32 context)
1003 vl_api_one_eid_table_map_details_t *rmp = NULL;
1005 rmp = vl_msg_api_alloc (sizeof (*rmp));
1006 memset (rmp, 0, sizeof (*rmp));
1007 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_MAP_DETAILS);
1009 rmp->vni = clib_host_to_net_u32 (p->key);
1010 rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
1011 rmp->context = context;
1012 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1016 vl_api_one_eid_table_map_dump_t_handler (vl_api_one_eid_table_map_dump_t * mp)
1018 unix_shared_memory_queue_t *q = NULL;
1019 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1021 uword *vni_table = 0;
1023 q = vl_api_client_index_to_input_queue (mp->client_index);
1031 vni_table = lcm->bd_id_by_vni;
1035 vni_table = lcm->table_id_by_vni;
1039 hash_foreach_pair (p, vni_table,
1041 send_eid_table_map_pair (p, q, mp->context);
1047 send_eid_table_vni (u32 vni, unix_shared_memory_queue_t * q, u32 context)
1049 vl_api_one_eid_table_vni_details_t *rmp = 0;
1051 rmp = vl_msg_api_alloc (sizeof (*rmp));
1052 memset (rmp, 0, sizeof (*rmp));
1053 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_VNI_DETAILS);
1054 rmp->context = context;
1055 rmp->vni = clib_host_to_net_u32 (vni);
1056 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1060 one_adjacency_copy (vl_api_one_adjacency_t * dst, lisp_adjacency_t * adjs)
1062 lisp_adjacency_t *adj;
1063 vl_api_one_adjacency_t a;
1064 u32 i, n = vec_len (adjs);
1066 for (i = 0; i < n; i++)
1068 adj = vec_elt_at_index (adjs, i);
1069 memset (&a, 0, sizeof (a));
1071 switch (gid_address_type (&adj->reid))
1073 case GID_ADDR_IP_PREFIX:
1074 a.reid_prefix_len = gid_address_ippref_len (&adj->reid);
1075 a.leid_prefix_len = gid_address_ippref_len (&adj->leid);
1076 if (gid_address_ip_version (&adj->reid) == IP4)
1078 a.eid_type = 0; /* ipv4 type */
1079 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 4);
1080 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 4);
1084 a.eid_type = 1; /* ipv6 type */
1085 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 16);
1086 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 16);
1090 a.eid_type = 2; /* l2 mac type */
1091 mac_copy (a.reid, gid_address_mac (&adj->reid));
1092 mac_copy (a.leid, gid_address_mac (&adj->leid));
1102 vl_api_show_one_rloc_probe_state_t_handler
1103 (vl_api_show_one_rloc_probe_state_t * mp)
1105 vl_api_show_one_rloc_probe_state_reply_t *rmp = 0;
1109 REPLY_MACRO2 (VL_API_SHOW_ONE_RLOC_PROBE_STATE_REPLY,
1111 rmp->is_enabled = vnet_lisp_rloc_probe_state_get ();
1117 vl_api_show_one_map_register_state_t_handler
1118 (vl_api_show_one_map_register_state_t * mp)
1120 vl_api_show_one_map_register_state_reply_t *rmp = 0;
1124 REPLY_MACRO2 (VL_API_SHOW_ONE_MAP_REGISTER_STATE_REPLY,
1126 rmp->is_enabled = vnet_lisp_map_register_state_get ();
1132 vl_api_one_adjacencies_get_t_handler (vl_api_one_adjacencies_get_t * mp)
1134 vl_api_one_adjacencies_get_reply_t *rmp = 0;
1135 lisp_adjacency_t *adjs = 0;
1138 u32 vni = clib_net_to_host_u32 (mp->vni);
1140 adjs = vnet_lisp_adjacencies_get_by_vni (vni);
1141 size = vec_len (adjs) * sizeof (vl_api_one_adjacency_t);
1144 REPLY_MACRO4 (VL_API_ONE_ADJACENCIES_GET_REPLY, size,
1146 rmp->count = clib_host_to_net_u32 (vec_len (adjs));
1147 one_adjacency_copy (rmp->adjacencies, adjs);
1155 vl_api_one_eid_table_vni_dump_t_handler (vl_api_one_eid_table_vni_dump_t * mp)
1159 unix_shared_memory_queue_t *q = 0;
1160 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1162 q = vl_api_client_index_to_input_queue (mp->client_index);
1169 hash_foreach_pair (p, lcm->table_id_by_vni,
1171 hash_set (vnis, p->key, 0);
1174 hash_foreach_pair (p, lcm->bd_id_by_vni,
1176 hash_set (vnis, p->key, 0);
1179 hash_foreach_pair (p, vnis,
1181 send_eid_table_vni (p->key, q, mp->context);
1189 vl_api_show_one_status_t_handler (vl_api_show_one_status_t * mp)
1191 unix_shared_memory_queue_t *q = NULL;
1192 vl_api_show_one_status_reply_t *rmp = NULL;
1195 q = vl_api_client_index_to_input_queue (mp->client_index);
1202 REPLY_MACRO2(VL_API_SHOW_ONE_STATUS_REPLY,
1204 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
1205 rmp->feature_status = vnet_lisp_enable_disable_status ();
1211 vl_api_one_get_map_request_itr_rlocs_t_handler
1212 (vl_api_one_get_map_request_itr_rlocs_t * mp)
1214 unix_shared_memory_queue_t *q = NULL;
1215 vl_api_one_get_map_request_itr_rlocs_reply_t *rmp = NULL;
1216 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1217 locator_set_t *loc_set = 0;
1221 q = vl_api_client_index_to_input_queue (mp->client_index);
1227 if (~0 == lcm->mreq_itr_rlocs)
1229 tmp_str = format (0, " ");
1234 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
1235 tmp_str = format (0, "%s", loc_set->name);
1239 REPLY_MACRO2(VL_API_ONE_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
1241 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1242 ARRAY_LEN(rmp->locator_set_name) - 1);
1250 vl_api_show_one_pitr_t_handler (vl_api_show_one_pitr_t * mp)
1252 unix_shared_memory_queue_t *q = NULL;
1253 vl_api_show_one_pitr_reply_t *rmp = NULL;
1254 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1256 locator_set_t *ls = 0;
1260 q = vl_api_client_index_to_input_queue (mp->client_index);
1266 if (!lcm->lisp_pitr)
1268 tmp_str = format (0, "N/A");
1272 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
1273 if (~0 != m->locator_set_index)
1276 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
1277 tmp_str = format (0, "%s", ls->name);
1281 tmp_str = format (0, "N/A");
1284 vec_add1 (tmp_str, 0);
1287 REPLY_MACRO2(VL_API_SHOW_ONE_PITR_REPLY,
1289 rmp->status = lcm->lisp_pitr;
1290 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1291 ARRAY_LEN(rmp->locator_set_name) - 1);
1297 vl_api_show_one_stats_enable_disable_t_handler
1298 (vl_api_show_one_stats_enable_disable_t * mp)
1300 vl_api_show_one_stats_enable_disable_reply_t *rmp = NULL;
1301 vnet_api_error_t rv = 0;
1304 REPLY_MACRO2 (VL_API_SHOW_ONE_STATS_ENABLE_DISABLE_REPLY,
1306 rmp->is_en = vnet_lisp_stats_enable_disable_state ();
1312 vl_api_one_stats_enable_disable_t_handler
1313 (vl_api_one_stats_enable_disable_t * mp)
1315 vl_api_one_enable_disable_reply_t *rmp = NULL;
1317 vnet_api_error_t rv = vnet_lisp_stats_enable_disable (mp->is_en);
1318 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
1322 lisp_fid_addr_to_api (fid_address_t * fid, u8 * dst, u8 * api_eid_type,
1325 switch (fid_addr_type (fid))
1327 case FID_ADDR_IP_PREF:
1328 *prefix_length = fid_addr_prefix_length (fid);
1329 if (fid_addr_ip_version (fid) == IP4)
1331 *api_eid_type = 0; /* ipv4 type */
1332 clib_memcpy (dst, &fid_addr_ippref (fid), 4);
1336 *api_eid_type = 1; /* ipv6 type */
1337 clib_memcpy (dst, &fid_addr_ippref (fid), 16);
1341 *api_eid_type = 2; /* l2 mac type */
1342 mac_copy (dst, fid_addr_mac (fid));
1350 vl_api_one_stats_dump_t_handler (vl_api_one_stats_dump_t * mp)
1352 vl_api_one_stats_details_t *rmp;
1353 lisp_api_stats_t *stats, *stat;
1356 stats = vnet_lisp_get_stats ();
1357 vec_foreach (stat, stats)
1360 REPLY_DETAILS (VL_API_ONE_STATS_DETAILS,
1362 lisp_fid_addr_to_api (&stat->deid, rmp->deid, &rmp->eid_type,
1363 &rmp->deid_pref_len);
1364 lisp_fid_addr_to_api (&stat->seid, rmp->seid, &rmp->eid_type,
1365 &rmp->seid_pref_len);
1366 rmp->vni = clib_host_to_net_u32 (stat->vni);
1368 rmp->is_ip4 = ip_addr_version (&stat->rmt_rloc) == IP4 ? 1 : 0;
1369 ip_address_copy_addr (rmp->rloc, &stat->rmt_rloc);
1370 ip_address_copy_addr (rmp->lloc, &stat->loc_rloc);
1372 rmp->pkt_count = clib_host_to_net_u32 (stat->stats.pkt_count);
1373 rmp->bytes = clib_host_to_net_u32 (stat->stats.bytes);
1381 * Add vpe's API message handlers to the table.
1382 * vlib has alread mapped shared memory and
1383 * added the client registration handlers.
1384 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
1386 #define vl_msg_name_crc_list
1387 #include <vnet/vnet_all_api_h.h>
1388 #undef vl_msg_name_crc_list
1391 setup_message_id_table (api_main_t * am)
1393 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
1394 foreach_vl_msg_name_crc_one;
1398 static clib_error_t *
1399 one_api_hookup (vlib_main_t * vm)
1401 api_main_t *am = &api_main;
1404 vl_msg_api_set_handlers(VL_API_##N, #n, \
1405 vl_api_##n##_t_handler, \
1407 vl_api_##n##_t_endian, \
1408 vl_api_##n##_t_print, \
1409 sizeof(vl_api_##n##_t), 1);
1410 foreach_vpe_api_msg;
1414 * Set up the (msg_name, crc, message-id) table
1416 setup_message_id_table (am);
1421 VLIB_API_INIT_FUNCTION (one_api_hookup);
1424 * fd.io coding-style-patch-verification: ON
1427 * eval: (c-set-style "gnu")