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_remote_locator_t_endian vl_noop_handler
31 #define vl_api_remote_locator_t_print vl_noop_handler
32 #define vl_api_local_locator_t_endian vl_noop_handler
33 #define vl_api_local_locator_t_print vl_noop_handler
35 #define vl_api_one_add_del_locator_set_t_endian vl_noop_handler
36 #define vl_api_one_add_del_locator_set_t_print vl_noop_handler
37 #define vl_api_one_add_del_remote_mapping_t_endian vl_noop_handler
38 #define vl_api_one_add_del_remote_mapping_t_print vl_noop_handler
40 #define vl_api_one_add_del_locator_set_t_endian vl_noop_handler
41 #define vl_api_one_add_del_locator_set_t_print vl_noop_handler
42 #define vl_api_one_add_del_remote_mapping_t_endian vl_noop_handler
43 #define vl_api_one_add_del_remote_mapping_t_print vl_noop_handler
45 #define vl_typedefs /* define message structures */
46 #include <vnet/vnet_all_api_h.h>
49 #define vl_endianfun /* define message structures */
50 #include <vnet/vnet_all_api_h.h>
53 /* instantiate all the print functions we know about */
54 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
56 #include <vnet/vnet_all_api_h.h>
59 #include <vlibapi/api_helper_macros.h>
61 #define foreach_vpe_api_msg \
62 _(ONE_ADD_DEL_LOCATOR_SET, one_add_del_locator_set) \
63 _(ONE_ADD_DEL_LOCATOR, one_add_del_locator) \
64 _(ONE_ADD_DEL_LOCAL_EID, one_add_del_local_eid) \
65 _(ONE_ADD_DEL_MAP_RESOLVER, one_add_del_map_resolver) \
66 _(ONE_ADD_DEL_MAP_SERVER, one_add_del_map_server) \
67 _(ONE_ENABLE_DISABLE, one_enable_disable) \
68 _(ONE_RLOC_PROBE_ENABLE_DISABLE, one_rloc_probe_enable_disable) \
69 _(ONE_MAP_REGISTER_ENABLE_DISABLE, one_map_register_enable_disable) \
70 _(ONE_ADD_DEL_REMOTE_MAPPING, one_add_del_remote_mapping) \
71 _(ONE_ADD_DEL_ADJACENCY, one_add_del_adjacency) \
72 _(ONE_PITR_SET_LOCATOR_SET, one_pitr_set_locator_set) \
73 _(ONE_MAP_REQUEST_MODE, one_map_request_mode) \
74 _(ONE_EID_TABLE_ADD_DEL_MAP, one_eid_table_add_del_map) \
75 _(ONE_LOCATOR_SET_DUMP, one_locator_set_dump) \
76 _(ONE_LOCATOR_DUMP, one_locator_dump) \
77 _(ONE_EID_TABLE_DUMP, one_eid_table_dump) \
78 _(ONE_MAP_RESOLVER_DUMP, one_map_resolver_dump) \
79 _(ONE_MAP_SERVER_DUMP, one_map_server_dump) \
80 _(ONE_EID_TABLE_MAP_DUMP, one_eid_table_map_dump) \
81 _(ONE_EID_TABLE_VNI_DUMP, one_eid_table_vni_dump) \
82 _(ONE_ADJACENCIES_GET, one_adjacencies_get) \
83 _(SHOW_ONE_RLOC_PROBE_STATE, show_one_rloc_probe_state) \
84 _(SHOW_ONE_MAP_REGISTER_STATE, show_one_map_register_state) \
85 _(SHOW_ONE_STATUS, show_one_status) \
86 _(ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \
87 one_add_del_map_request_itr_rlocs) \
88 _(ONE_GET_MAP_REQUEST_ITR_RLOCS, one_get_map_request_itr_rlocs) \
89 _(SHOW_ONE_PITR, show_one_pitr) \
90 _(SHOW_ONE_MAP_REQUEST_MODE, show_one_map_request_mode) \
91 _(ONE_USE_PETR, one_use_petr) \
92 _(SHOW_ONE_USE_PETR, show_one_use_petr) \
95 unformat_one_locs (vl_api_remote_locator_t * rmt_locs, u32 rloc_num)
98 locator_t *locs = 0, loc;
99 vl_api_remote_locator_t *r;
101 for (i = 0; i < rloc_num; i++)
103 /* remote locators */
105 memset (&loc, 0, sizeof (loc));
106 gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
108 loc.priority = r->priority;
109 loc.weight = r->weight;
111 vec_add1 (locs, loc);
117 vl_api_one_add_del_locator_set_t_handler (vl_api_one_add_del_locator_set_t *
120 vl_api_one_add_del_locator_set_reply_t *rmp;
122 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
124 vl_api_local_locator_t *ls_loc;
125 u32 ls_index = ~0, locator_num;
126 u8 *locator_name = NULL;
129 memset (a, 0, sizeof (a[0]));
131 locator_name = format (0, "%s", mp->locator_set_name);
133 a->name = locator_name;
134 a->is_add = mp->is_add;
136 locator_num = clib_net_to_host_u32 (mp->locator_num);
138 memset (&locator, 0, sizeof (locator));
139 for (i = 0; i < locator_num; i++)
141 ls_loc = &mp->locators[i];
142 VALIDATE_SW_IF_INDEX (ls_loc);
144 locator.sw_if_index = htonl (ls_loc->sw_if_index);
145 locator.priority = ls_loc->priority;
146 locator.weight = ls_loc->weight;
148 vec_add1 (a->locators, locator);
151 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
153 BAD_SW_IF_INDEX_LABEL;
155 vec_free (locator_name);
156 vec_free (a->locators);
159 REPLY_MACRO2 (VL_API_ONE_ADD_DEL_LOCATOR_SET_REPLY,
161 rmp->ls_index = clib_host_to_net_u32 (ls_index);
167 vl_api_one_add_del_locator_t_handler (vl_api_one_add_del_locator_t * mp)
169 vl_api_one_add_del_locator_reply_t *rmp;
171 locator_t locator, *locators = NULL;
172 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
174 u8 *locator_name = NULL;
176 memset (&locator, 0, sizeof (locator));
177 memset (a, 0, sizeof (a[0]));
179 locator.sw_if_index = ntohl (mp->sw_if_index);
180 locator.priority = mp->priority;
181 locator.weight = mp->weight;
183 vec_add1 (locators, locator);
185 locator_name = format (0, "%s", mp->locator_set_name);
187 a->name = locator_name;
188 a->locators = locators;
189 a->is_add = mp->is_add;
192 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
195 vec_free (locator_name);
197 REPLY_MACRO (VL_API_ONE_ADD_DEL_LOCATOR_REPLY);
201 unformat_one_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
207 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
208 gid_address_ip_set (dst, src, IP4);
209 gid_address_ippref_len (dst) = len;
210 ip_prefix_normalize (&gid_address_ippref (dst));
213 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
214 gid_address_ip_set (dst, src, IP6);
215 gid_address_ippref_len (dst) = len;
216 ip_prefix_normalize (&gid_address_ippref (dst));
219 gid_address_type (dst) = GID_ADDR_MAC;
220 clib_memcpy (&gid_address_mac (dst), src, 6);
224 return VNET_API_ERROR_INVALID_VALUE;
227 gid_address_vni (dst) = vni;
233 vl_api_one_add_del_local_eid_t_handler (vl_api_one_add_del_local_eid_t * mp)
235 vl_api_one_add_del_local_eid_reply_t *rmp;
236 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
238 gid_address_t _eid, *eid = &_eid;
240 u32 locator_set_index = ~0, map_index = ~0;
241 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
242 u8 *name = NULL, *key = NULL;
243 memset (a, 0, sizeof (a[0]));
244 memset (eid, 0, sizeof (eid[0]));
246 rv = unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
247 mp->eid_type, mp->eid, mp->prefix_len);
251 name = format (0, "%s", mp->locator_set_name);
252 p = hash_get_mem (lcm->locator_set_index_by_name, name);
255 rv = VNET_API_ERROR_INVALID_VALUE;
258 locator_set_index = p[0];
261 key = format (0, "%s", mp->key);
263 /* XXX treat batch configuration */
264 a->is_add = mp->is_add;
265 gid_address_copy (&a->eid, eid);
266 a->locator_set_index = locator_set_index;
269 a->key_id = clib_net_to_host_u16 (mp->key_id);
271 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
276 gid_address_free (&a->eid);
278 REPLY_MACRO (VL_API_ONE_ADD_DEL_LOCAL_EID_REPLY);
282 vl_api_one_eid_table_add_del_map_t_handler
283 (vl_api_one_eid_table_add_del_map_t * mp)
285 vl_api_one_eid_table_add_del_map_reply_t *rmp;
287 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
288 clib_net_to_host_u32 (mp->dp_table),
289 mp->is_l2, mp->is_add);
290 REPLY_MACRO (VL_API_ONE_EID_TABLE_ADD_DEL_MAP_REPLY)}
293 vl_api_one_add_del_map_server_t_handler (vl_api_one_add_del_map_server_t * mp)
295 vl_api_one_add_del_map_server_reply_t *rmp;
299 memset (&addr, 0, sizeof (addr));
301 ip_address_set (&addr, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
302 rv = vnet_lisp_add_del_map_server (&addr, mp->is_add);
304 REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_SERVER_REPLY);
308 vl_api_one_add_del_map_resolver_t_handler (vl_api_one_add_del_map_resolver_t
311 vl_api_one_add_del_map_resolver_reply_t *rmp;
313 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
315 memset (a, 0, sizeof (a[0]));
317 a->is_add = mp->is_add;
318 ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
320 rv = vnet_lisp_add_del_map_resolver (a);
322 REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_RESOLVER_REPLY);
326 vl_api_one_map_register_enable_disable_t_handler
327 (vl_api_one_map_register_enable_disable_t * mp)
329 vl_api_one_map_register_enable_disable_reply_t *rmp;
332 vnet_lisp_map_register_enable_disable (mp->is_enabled);
333 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
337 vl_api_one_rloc_probe_enable_disable_t_handler
338 (vl_api_one_rloc_probe_enable_disable_t * mp)
340 vl_api_one_rloc_probe_enable_disable_reply_t *rmp;
343 vnet_lisp_rloc_probe_enable_disable (mp->is_enabled);
344 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
348 vl_api_one_enable_disable_t_handler (vl_api_one_enable_disable_t * mp)
350 vl_api_one_enable_disable_reply_t *rmp;
353 vnet_lisp_enable_disable (mp->is_en);
354 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
358 vl_api_show_one_map_request_mode_t_handler
359 (vl_api_show_one_map_request_mode_t * mp)
362 vl_api_show_one_map_request_mode_reply_t *rmp;
365 REPLY_MACRO2(VL_API_SHOW_ONE_MAP_REQUEST_MODE_REPLY,
367 rmp->mode = vnet_lisp_get_map_request_mode ();
373 vl_api_one_map_request_mode_t_handler (vl_api_one_map_request_mode_t * mp)
375 vl_api_one_map_request_mode_reply_t *rmp;
378 rv = vnet_lisp_set_map_request_mode (mp->mode);
380 REPLY_MACRO (VL_API_ONE_MAP_REQUEST_MODE_REPLY);
384 vl_api_one_pitr_set_locator_set_t_handler (vl_api_one_pitr_set_locator_set_t
387 vl_api_one_pitr_set_locator_set_reply_t *rmp;
391 ls_name = format (0, "%s", mp->ls_name);
392 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
395 REPLY_MACRO (VL_API_ONE_PITR_SET_LOCATOR_SET_REPLY);
399 vl_api_one_use_petr_t_handler (vl_api_one_use_petr_t * mp)
401 vl_api_one_use_petr_reply_t *rmp;
405 ip_address_set (&addr, &mp->address, mp->is_ip4 ? IP4 : IP6);
406 rv = vnet_lisp_use_petr (&addr, mp->is_add);
408 REPLY_MACRO (VL_API_ONE_USE_PETR_REPLY);
412 vl_api_show_one_use_petr_t_handler (vl_api_show_one_use_petr_t * mp)
414 unix_shared_memory_queue_t *q = NULL;
415 vl_api_show_one_use_petr_reply_t *rmp = NULL;
416 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
418 locator_set_t *ls = 0;
424 q = vl_api_client_index_to_input_queue (mp->client_index);
430 memset (&addr, 0, sizeof (addr));
431 status = lcm->flags & LISP_FLAG_USE_PETR;
434 m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index);
435 if (~0 != m->locator_set_index)
438 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
439 loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]);
440 gid_address_copy (&addr, &loc->address);
445 REPLY_MACRO2 (VL_API_SHOW_ONE_USE_PETR_REPLY,
447 rmp->status = status;
448 gid_address_put (rmp->address, &addr);
449 rmp->is_ip4 = (gid_address_ip_version (&addr) == IP4);
455 vl_api_one_add_del_map_request_itr_rlocs_t_handler
456 (vl_api_one_add_del_map_request_itr_rlocs_t * mp)
458 vl_api_one_add_del_map_request_itr_rlocs_reply_t *rmp;
460 u8 *locator_set_name = NULL;
461 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
463 locator_set_name = format (0, "%s", mp->locator_set_name);
465 a->is_add = mp->is_add;
466 a->locator_set_name = locator_set_name;
468 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
470 vec_free (locator_set_name);
472 REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
476 vl_api_one_add_del_remote_mapping_t_handler
477 (vl_api_one_add_del_remote_mapping_t * mp)
479 locator_t *rlocs = 0;
480 vl_api_one_add_del_remote_mapping_reply_t *rmp;
482 gid_address_t _eid, *eid = &_eid;
483 u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
485 memset (eid, 0, sizeof (eid[0]));
487 rv = unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
488 mp->eid_type, mp->eid, mp->eid_len);
492 rlocs = unformat_one_locs (mp->rlocs, rloc_num);
496 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
497 gid_address_copy (&a->reid, eid);
499 rv = vnet_lisp_add_del_adjacency (a);
506 /* NOTE: for now this works as a static remote mapping, i.e.,
507 * not authoritative and ttl infinite. */
508 rv = vnet_lisp_add_del_mapping (eid, rlocs, mp->action, 0, ~0,
509 mp->is_add, 1 /* is_static */ , 0);
512 vnet_lisp_clear_all_remote_adjacencies ();
517 REPLY_MACRO (VL_API_ONE_ADD_DEL_REMOTE_MAPPING_REPLY);
521 vl_api_one_add_del_adjacency_t_handler (vl_api_one_add_del_adjacency_t * mp)
523 vl_api_one_add_del_adjacency_reply_t *rmp;
524 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
527 memset (a, 0, sizeof (a[0]));
529 rv = unformat_one_eid_api (&a->leid, clib_net_to_host_u32 (mp->vni),
530 mp->eid_type, mp->leid, mp->leid_len);
531 rv |= unformat_one_eid_api (&a->reid, clib_net_to_host_u32 (mp->vni),
532 mp->eid_type, mp->reid, mp->reid_len);
537 a->is_add = mp->is_add;
538 rv = vnet_lisp_add_del_adjacency (a);
541 REPLY_MACRO (VL_API_ONE_ADD_DEL_ADJACENCY_REPLY);
545 send_one_locator_details (lisp_cp_main_t * lcm,
547 unix_shared_memory_queue_t * q, u32 context)
549 vl_api_one_locator_details_t *rmp;
551 rmp = vl_msg_api_alloc (sizeof (*rmp));
552 memset (rmp, 0, sizeof (*rmp));
553 rmp->_vl_msg_id = ntohs (VL_API_ONE_LOCATOR_DETAILS);
554 rmp->context = context;
556 rmp->local = loc->local;
559 rmp->sw_if_index = ntohl (loc->sw_if_index);
563 rmp->is_ipv6 = gid_address_ip_version (&loc->address);
564 ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
566 rmp->priority = loc->priority;
567 rmp->weight = loc->weight;
569 vl_msg_api_send_shmem (q, (u8 *) & rmp);
573 vl_api_one_locator_dump_t_handler (vl_api_one_locator_dump_t * mp)
576 unix_shared_memory_queue_t *q = 0;
577 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
578 locator_set_t *lsit = 0;
580 u32 ls_index = ~0, *locit = 0;
583 q = vl_api_client_index_to_input_queue (mp->client_index);
589 if (mp->is_index_set)
590 ls_index = htonl (mp->ls_index);
593 /* make sure we get a proper C-string */
594 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
595 ls_name = format (0, "%s", mp->ls_name);
596 p = hash_get_mem (lcm->locator_set_index_by_name, ls_name);
602 if (pool_is_free_index (lcm->locator_set_pool, ls_index))
605 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
607 vec_foreach (locit, lsit->locator_indices)
609 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
610 send_one_locator_details (lcm, loc, q, mp->context);
617 send_one_locator_set_details (lisp_cp_main_t * lcm,
618 locator_set_t * lsit,
619 unix_shared_memory_queue_t * q,
620 u32 context, u32 ls_index)
622 vl_api_one_locator_set_details_t *rmp;
625 rmp = vl_msg_api_alloc (sizeof (*rmp));
626 memset (rmp, 0, sizeof (*rmp));
627 rmp->_vl_msg_id = ntohs (VL_API_ONE_LOCATOR_SET_DETAILS);
628 rmp->context = context;
630 rmp->ls_index = htonl (ls_index);
633 ASSERT (lsit->name != NULL);
634 strncpy ((char *) rmp->ls_name, (char *) lsit->name,
635 vec_len (lsit->name));
639 str = format (0, "<remote-%d>", ls_index);
640 strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str));
644 vl_msg_api_send_shmem (q, (u8 *) & rmp);
648 vl_api_one_locator_set_dump_t_handler (vl_api_one_locator_set_dump_t * mp)
650 unix_shared_memory_queue_t *q = NULL;
651 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
652 locator_set_t *lsit = NULL;
655 q = vl_api_client_index_to_input_queue (mp->client_index);
663 pool_foreach (lsit, lcm->locator_set_pool,
665 if (filter && !((1 == filter && lsit->local) ||
666 (2 == filter && !lsit->local)))
670 send_one_locator_set_details (lcm, lsit, q, mp->context,
671 lsit - lcm->locator_set_pool);
677 one_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length)
679 ASSERT (prefix_length);
680 ip_prefix_t *ippref = &fid_addr_ippref (src);
682 switch (fid_addr_type (src))
684 case FID_ADDR_IP_PREF:
685 if (ip_prefix_version (ippref) == IP4)
686 clib_memcpy (dst, &ip_prefix_v4 (ippref), 4);
688 clib_memcpy (dst, &ip_prefix_v6 (ippref), 16);
689 prefix_length[0] = ip_prefix_len (ippref);
693 prefix_length[0] = 0;
694 clib_memcpy (dst, fid_addr_mac (src), 6);
698 clib_warning ("Unknown FID type %d!", fid_addr_type (src));
704 fid_type_to_api_type (fid_address_t * fid)
708 switch (fid_addr_type (fid))
710 case FID_ADDR_IP_PREF:
711 ippref = &fid_addr_ippref (fid);
712 if (ip_prefix_version (ippref) == IP4)
714 else if (ip_prefix_version (ippref) == IP6)
729 send_one_eid_table_details (mapping_t * mapit,
730 unix_shared_memory_queue_t * q,
731 u32 context, u8 filter)
734 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
735 locator_set_t *ls = 0;
736 vl_api_one_eid_table_details_t *rmp = NULL;
737 gid_address_t *gid = NULL;
739 ip_prefix_t *ip_prefix = NULL;
743 case 0: /* all mappings */
746 case 1: /* local only */
750 case 2: /* remote only */
755 clib_warning ("Filter error, unknown filter: %d", filter);
760 ip_prefix = &gid_address_ippref (gid);
761 mac = gid_address_mac (gid);
763 rmp = vl_msg_api_alloc (sizeof (*rmp));
764 memset (rmp, 0, sizeof (*rmp));
765 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_DETAILS);
767 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
768 if (vec_len (ls->locator_indices) == 0)
769 rmp->locator_set_index = ~0;
771 rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
773 rmp->is_local = mapit->local;
774 rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
775 rmp->action = mapit->action;
776 rmp->authoritative = mapit->authoritative;
778 switch (gid_address_type (gid))
780 case GID_ADDR_SRC_DST:
782 fid = &gid_address_sd_src (gid);
783 rmp->eid_type = fid_type_to_api_type (fid);
784 one_fid_put_api (rmp->seid, &gid_address_sd_src (gid),
785 &rmp->seid_prefix_len);
786 one_fid_put_api (rmp->eid, &gid_address_sd_dst (gid),
787 &rmp->eid_prefix_len);
789 case GID_ADDR_IP_PREFIX:
790 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
791 if (ip_prefix_version (ip_prefix) == IP4)
793 rmp->eid_type = 0; /* ipv4 type */
794 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
795 sizeof (ip_prefix_v4 (ip_prefix)));
799 rmp->eid_type = 1; /* ipv6 type */
800 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
801 sizeof (ip_prefix_v6 (ip_prefix)));
805 rmp->eid_type = 2; /* l2 mac type */
806 clib_memcpy (rmp->eid, mac, 6);
811 rmp->context = context;
812 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
813 rmp->key_id = clib_host_to_net_u16 (mapit->key_id);
814 memcpy (rmp->key, mapit->key, vec_len (mapit->key));
815 vl_msg_api_send_shmem (q, (u8 *) & rmp);
819 vl_api_one_eid_table_dump_t_handler (vl_api_one_eid_table_dump_t * mp)
822 unix_shared_memory_queue_t *q = NULL;
823 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
824 mapping_t *mapit = NULL;
825 gid_address_t _eid, *eid = &_eid;
827 q = vl_api_client_index_to_input_queue (mp->client_index);
835 memset (eid, 0, sizeof (*eid));
837 unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
838 mp->eid_type, mp->eid, mp->prefix_length);
840 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
844 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
845 send_one_eid_table_details (mapit, q, mp->context,
846 0 /* ignore filter */ );
851 pool_foreach (mapit, lcm->mapping_pool,
853 send_one_eid_table_details(mapit, q, mp->context,
861 send_one_map_server_details (ip_address_t * ip,
862 unix_shared_memory_queue_t * q, u32 context)
864 vl_api_one_map_server_details_t *rmp = NULL;
866 rmp = vl_msg_api_alloc (sizeof (*rmp));
867 memset (rmp, 0, sizeof (*rmp));
868 rmp->_vl_msg_id = ntohs (VL_API_ONE_MAP_SERVER_DETAILS);
870 switch (ip_addr_version (ip))
874 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
875 sizeof (ip_addr_v4 (ip)));
880 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
881 sizeof (ip_addr_v6 (ip)));
887 rmp->context = context;
889 vl_msg_api_send_shmem (q, (u8 *) & rmp);
893 vl_api_one_map_server_dump_t_handler (vl_api_one_map_server_dump_t * mp)
895 unix_shared_memory_queue_t *q = NULL;
896 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
899 q = vl_api_client_index_to_input_queue (mp->client_index);
905 vec_foreach (mr, lcm->map_servers)
907 send_one_map_server_details (&mr->address, q, mp->context);
912 send_one_map_resolver_details (ip_address_t * ip,
913 unix_shared_memory_queue_t * q, u32 context)
915 vl_api_one_map_resolver_details_t *rmp = NULL;
917 rmp = vl_msg_api_alloc (sizeof (*rmp));
918 memset (rmp, 0, sizeof (*rmp));
919 rmp->_vl_msg_id = ntohs (VL_API_ONE_MAP_RESOLVER_DETAILS);
921 switch (ip_addr_version (ip))
925 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
926 sizeof (ip_addr_v4 (ip)));
931 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
932 sizeof (ip_addr_v6 (ip)));
938 rmp->context = context;
940 vl_msg_api_send_shmem (q, (u8 *) & rmp);
944 vl_api_one_map_resolver_dump_t_handler (vl_api_one_map_resolver_dump_t * mp)
946 unix_shared_memory_queue_t *q = NULL;
947 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
950 q = vl_api_client_index_to_input_queue (mp->client_index);
956 vec_foreach (mr, lcm->map_resolvers)
958 send_one_map_resolver_details (&mr->address, q, mp->context);
963 send_eid_table_map_pair (hash_pair_t * p,
964 unix_shared_memory_queue_t * q, u32 context)
966 vl_api_one_eid_table_map_details_t *rmp = NULL;
968 rmp = vl_msg_api_alloc (sizeof (*rmp));
969 memset (rmp, 0, sizeof (*rmp));
970 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_MAP_DETAILS);
972 rmp->vni = clib_host_to_net_u32 (p->key);
973 rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
974 rmp->context = context;
975 vl_msg_api_send_shmem (q, (u8 *) & rmp);
979 vl_api_one_eid_table_map_dump_t_handler (vl_api_one_eid_table_map_dump_t * mp)
981 unix_shared_memory_queue_t *q = NULL;
982 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
984 uword *vni_table = 0;
986 q = vl_api_client_index_to_input_queue (mp->client_index);
994 vni_table = lcm->bd_id_by_vni;
998 vni_table = lcm->table_id_by_vni;
1002 hash_foreach_pair (p, vni_table,
1004 send_eid_table_map_pair (p, q, mp->context);
1010 send_eid_table_vni (u32 vni, unix_shared_memory_queue_t * q, u32 context)
1012 vl_api_one_eid_table_vni_details_t *rmp = 0;
1014 rmp = vl_msg_api_alloc (sizeof (*rmp));
1015 memset (rmp, 0, sizeof (*rmp));
1016 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_VNI_DETAILS);
1017 rmp->context = context;
1018 rmp->vni = clib_host_to_net_u32 (vni);
1019 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1023 one_adjacency_copy (vl_api_one_adjacency_t * dst, lisp_adjacency_t * adjs)
1025 lisp_adjacency_t *adj;
1026 vl_api_one_adjacency_t a;
1027 u32 i, n = vec_len (adjs);
1029 for (i = 0; i < n; i++)
1031 adj = vec_elt_at_index (adjs, i);
1032 memset (&a, 0, sizeof (a));
1034 switch (gid_address_type (&adj->reid))
1036 case GID_ADDR_IP_PREFIX:
1037 a.reid_prefix_len = gid_address_ippref_len (&adj->reid);
1038 a.leid_prefix_len = gid_address_ippref_len (&adj->leid);
1039 if (gid_address_ip_version (&adj->reid) == IP4)
1041 a.eid_type = 0; /* ipv4 type */
1042 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 4);
1043 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 4);
1047 a.eid_type = 1; /* ipv6 type */
1048 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 16);
1049 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 16);
1053 a.eid_type = 2; /* l2 mac type */
1054 mac_copy (a.reid, gid_address_mac (&adj->reid));
1055 mac_copy (a.leid, gid_address_mac (&adj->leid));
1065 vl_api_show_one_rloc_probe_state_t_handler
1066 (vl_api_show_one_rloc_probe_state_t * mp)
1068 vl_api_show_one_rloc_probe_state_reply_t *rmp = 0;
1072 REPLY_MACRO2 (VL_API_SHOW_ONE_RLOC_PROBE_STATE_REPLY,
1074 rmp->is_enabled = vnet_lisp_rloc_probe_state_get ();
1080 vl_api_show_one_map_register_state_t_handler
1081 (vl_api_show_one_map_register_state_t * mp)
1083 vl_api_show_one_map_register_state_reply_t *rmp = 0;
1087 REPLY_MACRO2 (VL_API_SHOW_ONE_MAP_REGISTER_STATE_REPLY,
1089 rmp->is_enabled = vnet_lisp_map_register_state_get ();
1095 vl_api_one_adjacencies_get_t_handler (vl_api_one_adjacencies_get_t * mp)
1097 vl_api_one_adjacencies_get_reply_t *rmp = 0;
1098 lisp_adjacency_t *adjs = 0;
1101 u32 vni = clib_net_to_host_u32 (mp->vni);
1103 adjs = vnet_lisp_adjacencies_get_by_vni (vni);
1104 size = vec_len (adjs) * sizeof (vl_api_one_adjacency_t);
1107 REPLY_MACRO4 (VL_API_ONE_ADJACENCIES_GET_REPLY, size,
1109 rmp->count = clib_host_to_net_u32 (vec_len (adjs));
1110 one_adjacency_copy (rmp->adjacencies, adjs);
1118 vl_api_one_eid_table_vni_dump_t_handler (vl_api_one_eid_table_vni_dump_t * mp)
1122 unix_shared_memory_queue_t *q = 0;
1123 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1125 q = vl_api_client_index_to_input_queue (mp->client_index);
1132 hash_foreach_pair (p, lcm->table_id_by_vni,
1134 hash_set (vnis, p->key, 0);
1137 hash_foreach_pair (p, lcm->bd_id_by_vni,
1139 hash_set (vnis, p->key, 0);
1142 hash_foreach_pair (p, vnis,
1144 send_eid_table_vni (p->key, q, mp->context);
1152 vl_api_show_one_status_t_handler (vl_api_show_one_status_t * mp)
1154 unix_shared_memory_queue_t *q = NULL;
1155 vl_api_show_one_status_reply_t *rmp = NULL;
1158 q = vl_api_client_index_to_input_queue (mp->client_index);
1165 REPLY_MACRO2(VL_API_SHOW_ONE_STATUS_REPLY,
1167 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
1168 rmp->feature_status = vnet_lisp_enable_disable_status ();
1174 vl_api_one_get_map_request_itr_rlocs_t_handler
1175 (vl_api_one_get_map_request_itr_rlocs_t * mp)
1177 unix_shared_memory_queue_t *q = NULL;
1178 vl_api_one_get_map_request_itr_rlocs_reply_t *rmp = NULL;
1179 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1180 locator_set_t *loc_set = 0;
1184 q = vl_api_client_index_to_input_queue (mp->client_index);
1190 if (~0 == lcm->mreq_itr_rlocs)
1192 tmp_str = format (0, " ");
1197 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
1198 tmp_str = format (0, "%s", loc_set->name);
1202 REPLY_MACRO2(VL_API_ONE_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
1204 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1205 ARRAY_LEN(rmp->locator_set_name) - 1);
1213 vl_api_show_one_pitr_t_handler (vl_api_show_one_pitr_t * mp)
1215 unix_shared_memory_queue_t *q = NULL;
1216 vl_api_show_one_pitr_reply_t *rmp = NULL;
1217 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1219 locator_set_t *ls = 0;
1223 q = vl_api_client_index_to_input_queue (mp->client_index);
1229 if (!lcm->lisp_pitr)
1231 tmp_str = format (0, "N/A");
1235 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
1236 if (~0 != m->locator_set_index)
1239 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
1240 tmp_str = format (0, "%s", ls->name);
1244 tmp_str = format (0, "N/A");
1247 vec_add1 (tmp_str, 0);
1250 REPLY_MACRO2(VL_API_SHOW_ONE_PITR_REPLY,
1252 rmp->status = lcm->lisp_pitr;
1253 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1254 ARRAY_LEN(rmp->locator_set_name) - 1);
1261 * Add vpe's API message handlers to the table.
1262 * vlib has alread mapped shared memory and
1263 * added the client registration handlers.
1264 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
1266 #define vl_msg_name_crc_list
1267 #include <vnet/vnet_all_api_h.h>
1268 #undef vl_msg_name_crc_list
1271 setup_message_id_table (api_main_t * am)
1273 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
1274 foreach_vl_msg_name_crc_lisp;
1278 static clib_error_t *
1279 one_api_hookup (vlib_main_t * vm)
1281 api_main_t *am = &api_main;
1284 vl_msg_api_set_handlers(VL_API_##N, #n, \
1285 vl_api_##n##_t_handler, \
1287 vl_api_##n##_t_endian, \
1288 vl_api_##n##_t_print, \
1289 sizeof(vl_api_##n##_t), 1);
1290 foreach_vpe_api_msg;
1294 * Set up the (msg_name, crc, message-id) table
1296 setup_message_id_table (am);
1301 VLIB_API_INIT_FUNCTION (one_api_hookup);
1304 * fd.io coding-style-patch-verification: ON
1307 * eval: (c-set-style "gnu")