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_api_one_l2_arp_entry_t_endian vl_noop_handler
46 #define vl_api_one_l2_arp_entry_t_print vl_noop_handler
47 #define vl_api_one_add_del_l2_arp_entry vl_noop_handler
48 #define vl_api_one_l2_arp_bd_get vl_noop_handler
50 #define vl_typedefs /* define message structures */
51 #include <vnet/vnet_all_api_h.h>
54 #define vl_endianfun /* define message structures */
55 #include <vnet/vnet_all_api_h.h>
58 /* instantiate all the print functions we know about */
59 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
61 #include <vnet/vnet_all_api_h.h>
64 #include <vlibapi/api_helper_macros.h>
66 #define REPLY_DETAILS(t, body) \
68 unix_shared_memory_queue_t * q; \
69 rv = vl_msg_api_pd_handler (mp, rv); \
70 q = vl_api_client_index_to_input_queue (mp->client_index); \
74 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
75 rmp->_vl_msg_id = ntohs((t)); \
76 rmp->context = mp->context; \
77 do {body;} while (0); \
78 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
81 #define foreach_vpe_api_msg \
82 _(ONE_ADD_DEL_LOCATOR_SET, one_add_del_locator_set) \
83 _(ONE_ADD_DEL_LOCATOR, one_add_del_locator) \
84 _(ONE_ADD_DEL_LOCAL_EID, one_add_del_local_eid) \
85 _(ONE_ADD_DEL_MAP_RESOLVER, one_add_del_map_resolver) \
86 _(ONE_ADD_DEL_MAP_SERVER, one_add_del_map_server) \
87 _(ONE_ENABLE_DISABLE, one_enable_disable) \
88 _(ONE_RLOC_PROBE_ENABLE_DISABLE, one_rloc_probe_enable_disable) \
89 _(ONE_MAP_REGISTER_ENABLE_DISABLE, one_map_register_enable_disable) \
90 _(ONE_ADD_DEL_REMOTE_MAPPING, one_add_del_remote_mapping) \
91 _(ONE_ADD_DEL_ADJACENCY, one_add_del_adjacency) \
92 _(ONE_PITR_SET_LOCATOR_SET, one_pitr_set_locator_set) \
93 _(ONE_MAP_REQUEST_MODE, one_map_request_mode) \
94 _(ONE_EID_TABLE_ADD_DEL_MAP, one_eid_table_add_del_map) \
95 _(ONE_LOCATOR_SET_DUMP, one_locator_set_dump) \
96 _(ONE_LOCATOR_DUMP, one_locator_dump) \
97 _(ONE_EID_TABLE_DUMP, one_eid_table_dump) \
98 _(ONE_MAP_RESOLVER_DUMP, one_map_resolver_dump) \
99 _(ONE_MAP_SERVER_DUMP, one_map_server_dump) \
100 _(ONE_EID_TABLE_MAP_DUMP, one_eid_table_map_dump) \
101 _(ONE_EID_TABLE_VNI_DUMP, one_eid_table_vni_dump) \
102 _(ONE_ADJACENCIES_GET, one_adjacencies_get) \
103 _(SHOW_ONE_RLOC_PROBE_STATE, show_one_rloc_probe_state) \
104 _(SHOW_ONE_MAP_REGISTER_STATE, show_one_map_register_state) \
105 _(SHOW_ONE_STATUS, show_one_status) \
106 _(ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \
107 one_add_del_map_request_itr_rlocs) \
108 _(ONE_GET_MAP_REQUEST_ITR_RLOCS, one_get_map_request_itr_rlocs) \
109 _(SHOW_ONE_PITR, show_one_pitr) \
110 _(SHOW_ONE_MAP_REQUEST_MODE, show_one_map_request_mode) \
111 _(ONE_USE_PETR, one_use_petr) \
112 _(SHOW_ONE_USE_PETR, show_one_use_petr) \
113 _(SHOW_ONE_STATS_ENABLE_DISABLE, show_one_stats_enable_disable) \
114 _(ONE_STATS_ENABLE_DISABLE, one_stats_enable_disable) \
115 _(ONE_STATS_DUMP, one_stats_dump) \
116 _(ONE_STATS_FLUSH, one_stats_flush) \
117 _(ONE_L2_ARP_BD_GET, one_l2_arp_bd_get) \
118 _(ONE_L2_ARP_ENTRIES_GET, one_l2_arp_entries_get) \
119 _(ONE_ADD_DEL_L2_ARP_ENTRY, one_add_del_l2_arp_entry) \
123 unformat_one_locs (vl_api_one_remote_locator_t * rmt_locs, u32 rloc_num)
126 locator_t *locs = 0, loc;
127 vl_api_one_remote_locator_t *r;
129 for (i = 0; i < rloc_num; i++)
131 /* remote locators */
133 memset (&loc, 0, sizeof (loc));
134 gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
136 loc.priority = r->priority;
137 loc.weight = r->weight;
139 vec_add1 (locs, loc);
145 vl_api_one_add_del_locator_set_t_handler (vl_api_one_add_del_locator_set_t *
148 vl_api_one_add_del_locator_set_reply_t *rmp;
150 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
152 vl_api_one_local_locator_t *ls_loc;
153 u32 ls_index = ~0, locator_num;
154 u8 *locator_name = NULL;
157 memset (a, 0, sizeof (a[0]));
159 locator_name = format (0, "%s", mp->locator_set_name);
161 a->name = locator_name;
162 a->is_add = mp->is_add;
164 locator_num = clib_net_to_host_u32 (mp->locator_num);
166 memset (&locator, 0, sizeof (locator));
167 for (i = 0; i < locator_num; i++)
169 ls_loc = &mp->locators[i];
170 VALIDATE_SW_IF_INDEX (ls_loc);
172 locator.sw_if_index = htonl (ls_loc->sw_if_index);
173 locator.priority = ls_loc->priority;
174 locator.weight = ls_loc->weight;
176 vec_add1 (a->locators, locator);
179 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
181 BAD_SW_IF_INDEX_LABEL;
183 vec_free (locator_name);
184 vec_free (a->locators);
187 REPLY_MACRO2 (VL_API_ONE_ADD_DEL_LOCATOR_SET_REPLY,
189 rmp->ls_index = clib_host_to_net_u32 (ls_index);
195 vl_api_one_add_del_locator_t_handler (vl_api_one_add_del_locator_t * mp)
197 vl_api_one_add_del_locator_reply_t *rmp;
199 locator_t locator, *locators = NULL;
200 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
202 u8 *locator_name = NULL;
204 memset (&locator, 0, sizeof (locator));
205 memset (a, 0, sizeof (a[0]));
207 locator.sw_if_index = ntohl (mp->sw_if_index);
208 locator.priority = mp->priority;
209 locator.weight = mp->weight;
211 vec_add1 (locators, locator);
213 locator_name = format (0, "%s", mp->locator_set_name);
215 a->name = locator_name;
216 a->locators = locators;
217 a->is_add = mp->is_add;
220 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
223 vec_free (locator_name);
225 REPLY_MACRO (VL_API_ONE_ADD_DEL_LOCATOR_REPLY);
229 unformat_one_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
235 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
236 gid_address_ip_set (dst, src, IP4);
237 gid_address_ippref_len (dst) = len;
238 ip_prefix_normalize (&gid_address_ippref (dst));
241 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
242 gid_address_ip_set (dst, src, IP6);
243 gid_address_ippref_len (dst) = len;
244 ip_prefix_normalize (&gid_address_ippref (dst));
247 gid_address_type (dst) = GID_ADDR_MAC;
248 clib_memcpy (&gid_address_mac (dst), src, 6);
252 return VNET_API_ERROR_INVALID_VALUE;
255 gid_address_vni (dst) = vni;
261 vl_api_one_add_del_local_eid_t_handler (vl_api_one_add_del_local_eid_t * mp)
263 vl_api_one_add_del_local_eid_reply_t *rmp;
264 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
266 gid_address_t _eid, *eid = &_eid;
268 u32 locator_set_index = ~0, map_index = ~0;
269 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
270 u8 *name = NULL, *key = NULL;
271 memset (a, 0, sizeof (a[0]));
272 memset (eid, 0, sizeof (eid[0]));
274 rv = unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
275 mp->eid_type, mp->eid, mp->prefix_len);
279 name = format (0, "%s", mp->locator_set_name);
280 p = hash_get_mem (lcm->locator_set_index_by_name, name);
283 rv = VNET_API_ERROR_INVALID_VALUE;
286 locator_set_index = p[0];
289 key = format (0, "%s", mp->key);
291 /* XXX treat batch configuration */
292 a->is_add = mp->is_add;
293 gid_address_copy (&a->eid, eid);
294 a->locator_set_index = locator_set_index;
297 a->key_id = clib_net_to_host_u16 (mp->key_id);
299 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
304 gid_address_free (&a->eid);
306 REPLY_MACRO (VL_API_ONE_ADD_DEL_LOCAL_EID_REPLY);
310 vl_api_one_eid_table_add_del_map_t_handler
311 (vl_api_one_eid_table_add_del_map_t * mp)
313 vl_api_one_eid_table_add_del_map_reply_t *rmp;
315 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
316 clib_net_to_host_u32 (mp->dp_table),
317 mp->is_l2, mp->is_add);
318 REPLY_MACRO (VL_API_ONE_EID_TABLE_ADD_DEL_MAP_REPLY)}
321 vl_api_one_add_del_map_server_t_handler (vl_api_one_add_del_map_server_t * mp)
323 vl_api_one_add_del_map_server_reply_t *rmp;
327 memset (&addr, 0, sizeof (addr));
329 ip_address_set (&addr, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
330 rv = vnet_lisp_add_del_map_server (&addr, mp->is_add);
332 REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_SERVER_REPLY);
336 vl_api_one_add_del_map_resolver_t_handler (vl_api_one_add_del_map_resolver_t
339 vl_api_one_add_del_map_resolver_reply_t *rmp;
341 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
343 memset (a, 0, sizeof (a[0]));
345 a->is_add = mp->is_add;
346 ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
348 rv = vnet_lisp_add_del_map_resolver (a);
350 REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_RESOLVER_REPLY);
354 vl_api_one_map_register_enable_disable_t_handler
355 (vl_api_one_map_register_enable_disable_t * mp)
357 vl_api_one_map_register_enable_disable_reply_t *rmp;
360 vnet_lisp_map_register_enable_disable (mp->is_enabled);
361 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
365 vl_api_one_rloc_probe_enable_disable_t_handler
366 (vl_api_one_rloc_probe_enable_disable_t * mp)
368 vl_api_one_rloc_probe_enable_disable_reply_t *rmp;
371 vnet_lisp_rloc_probe_enable_disable (mp->is_enabled);
372 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
376 vl_api_one_enable_disable_t_handler (vl_api_one_enable_disable_t * mp)
378 vl_api_one_enable_disable_reply_t *rmp;
381 vnet_lisp_enable_disable (mp->is_en);
382 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
386 vl_api_show_one_map_request_mode_t_handler
387 (vl_api_show_one_map_request_mode_t * mp)
390 vl_api_show_one_map_request_mode_reply_t *rmp;
393 REPLY_MACRO2(VL_API_SHOW_ONE_MAP_REQUEST_MODE_REPLY,
395 rmp->mode = vnet_lisp_get_map_request_mode ();
401 vl_api_one_map_request_mode_t_handler (vl_api_one_map_request_mode_t * mp)
403 vl_api_one_map_request_mode_reply_t *rmp;
406 rv = vnet_lisp_set_map_request_mode (mp->mode);
408 REPLY_MACRO (VL_API_ONE_MAP_REQUEST_MODE_REPLY);
412 vl_api_one_pitr_set_locator_set_t_handler (vl_api_one_pitr_set_locator_set_t
415 vl_api_one_pitr_set_locator_set_reply_t *rmp;
419 ls_name = format (0, "%s", mp->ls_name);
420 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
423 REPLY_MACRO (VL_API_ONE_PITR_SET_LOCATOR_SET_REPLY);
427 vl_api_one_use_petr_t_handler (vl_api_one_use_petr_t * mp)
429 vl_api_one_use_petr_reply_t *rmp;
433 ip_address_set (&addr, &mp->address, mp->is_ip4 ? IP4 : IP6);
434 rv = vnet_lisp_use_petr (&addr, mp->is_add);
436 REPLY_MACRO (VL_API_ONE_USE_PETR_REPLY);
440 vl_api_show_one_use_petr_t_handler (vl_api_show_one_use_petr_t * mp)
442 unix_shared_memory_queue_t *q = NULL;
443 vl_api_show_one_use_petr_reply_t *rmp = NULL;
444 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
446 locator_set_t *ls = 0;
452 q = vl_api_client_index_to_input_queue (mp->client_index);
458 memset (&addr, 0, sizeof (addr));
459 status = lcm->flags & LISP_FLAG_USE_PETR;
462 m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index);
463 if (~0 != m->locator_set_index)
466 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
467 loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]);
468 gid_address_copy (&addr, &loc->address);
473 REPLY_MACRO2 (VL_API_SHOW_ONE_USE_PETR_REPLY,
475 rmp->status = status;
476 ip_address_t *ip = &gid_address_ip (&addr);
477 switch (ip_addr_version (ip))
480 clib_memcpy (rmp->address, &ip_addr_v4 (ip),
481 sizeof (ip_addr_v4 (ip)));
485 clib_memcpy (rmp->address, &ip_addr_v6 (ip),
486 sizeof (ip_addr_v6 (ip)));
492 rmp->is_ip4 = (gid_address_ip_version (&addr) == IP4);
498 vl_api_one_add_del_map_request_itr_rlocs_t_handler
499 (vl_api_one_add_del_map_request_itr_rlocs_t * mp)
501 vl_api_one_add_del_map_request_itr_rlocs_reply_t *rmp;
503 u8 *locator_set_name = NULL;
504 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
506 locator_set_name = format (0, "%s", mp->locator_set_name);
508 a->is_add = mp->is_add;
509 a->locator_set_name = locator_set_name;
511 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
513 vec_free (locator_set_name);
515 REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
519 vl_api_one_add_del_remote_mapping_t_handler
520 (vl_api_one_add_del_remote_mapping_t * mp)
522 locator_t *rlocs = 0;
523 vl_api_one_add_del_remote_mapping_reply_t *rmp;
525 gid_address_t _eid, *eid = &_eid;
526 u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
528 memset (eid, 0, sizeof (eid[0]));
530 rv = unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
531 mp->eid_type, mp->eid, mp->eid_len);
535 rlocs = unformat_one_locs (mp->rlocs, rloc_num);
539 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
540 gid_address_copy (&a->reid, eid);
542 rv = vnet_lisp_add_del_adjacency (a);
549 /* NOTE: for now this works as a static remote mapping, i.e.,
550 * not authoritative and ttl infinite. */
551 rv = vnet_lisp_add_del_mapping (eid, rlocs, mp->action, 0, ~0,
552 mp->is_add, 1 /* is_static */ , 0);
555 vnet_lisp_clear_all_remote_adjacencies ();
560 REPLY_MACRO (VL_API_ONE_ADD_DEL_REMOTE_MAPPING_REPLY);
564 vl_api_one_add_del_adjacency_t_handler (vl_api_one_add_del_adjacency_t * mp)
566 vl_api_one_add_del_adjacency_reply_t *rmp;
567 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
570 memset (a, 0, sizeof (a[0]));
572 rv = unformat_one_eid_api (&a->leid, clib_net_to_host_u32 (mp->vni),
573 mp->eid_type, mp->leid, mp->leid_len);
574 rv |= unformat_one_eid_api (&a->reid, clib_net_to_host_u32 (mp->vni),
575 mp->eid_type, mp->reid, mp->reid_len);
580 a->is_add = mp->is_add;
581 rv = vnet_lisp_add_del_adjacency (a);
584 REPLY_MACRO (VL_API_ONE_ADD_DEL_ADJACENCY_REPLY);
588 send_one_locator_details (lisp_cp_main_t * lcm,
590 unix_shared_memory_queue_t * q, u32 context)
592 vl_api_one_locator_details_t *rmp;
594 rmp = vl_msg_api_alloc (sizeof (*rmp));
595 memset (rmp, 0, sizeof (*rmp));
596 rmp->_vl_msg_id = ntohs (VL_API_ONE_LOCATOR_DETAILS);
597 rmp->context = context;
599 rmp->local = loc->local;
602 rmp->sw_if_index = ntohl (loc->sw_if_index);
606 rmp->is_ipv6 = gid_address_ip_version (&loc->address);
607 ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
609 rmp->priority = loc->priority;
610 rmp->weight = loc->weight;
612 vl_msg_api_send_shmem (q, (u8 *) & rmp);
616 vl_api_one_locator_dump_t_handler (vl_api_one_locator_dump_t * mp)
619 unix_shared_memory_queue_t *q = 0;
620 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
621 locator_set_t *lsit = 0;
623 u32 ls_index = ~0, *locit = 0;
626 q = vl_api_client_index_to_input_queue (mp->client_index);
632 if (mp->is_index_set)
633 ls_index = htonl (mp->ls_index);
636 /* make sure we get a proper C-string */
637 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
638 ls_name = format (0, "%s", mp->ls_name);
639 p = hash_get_mem (lcm->locator_set_index_by_name, ls_name);
645 if (pool_is_free_index (lcm->locator_set_pool, ls_index))
648 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
650 vec_foreach (locit, lsit->locator_indices)
652 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
653 send_one_locator_details (lcm, loc, q, mp->context);
660 send_one_locator_set_details (lisp_cp_main_t * lcm,
661 locator_set_t * lsit,
662 unix_shared_memory_queue_t * q,
663 u32 context, u32 ls_index)
665 vl_api_one_locator_set_details_t *rmp;
668 rmp = vl_msg_api_alloc (sizeof (*rmp));
669 memset (rmp, 0, sizeof (*rmp));
670 rmp->_vl_msg_id = ntohs (VL_API_ONE_LOCATOR_SET_DETAILS);
671 rmp->context = context;
673 rmp->ls_index = htonl (ls_index);
676 ASSERT (lsit->name != NULL);
677 strncpy ((char *) rmp->ls_name, (char *) lsit->name,
678 vec_len (lsit->name));
682 str = format (0, "<remote-%d>", ls_index);
683 strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str));
687 vl_msg_api_send_shmem (q, (u8 *) & rmp);
691 vl_api_one_locator_set_dump_t_handler (vl_api_one_locator_set_dump_t * mp)
693 unix_shared_memory_queue_t *q = NULL;
694 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
695 locator_set_t *lsit = NULL;
698 q = vl_api_client_index_to_input_queue (mp->client_index);
706 pool_foreach (lsit, lcm->locator_set_pool,
708 if (filter && !((1 == filter && lsit->local) ||
709 (2 == filter && !lsit->local)))
713 send_one_locator_set_details (lcm, lsit, q, mp->context,
714 lsit - lcm->locator_set_pool);
720 one_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length)
722 ASSERT (prefix_length);
723 ip_prefix_t *ippref = &fid_addr_ippref (src);
725 switch (fid_addr_type (src))
727 case FID_ADDR_IP_PREF:
728 if (ip_prefix_version (ippref) == IP4)
729 clib_memcpy (dst, &ip_prefix_v4 (ippref), 4);
731 clib_memcpy (dst, &ip_prefix_v6 (ippref), 16);
732 prefix_length[0] = ip_prefix_len (ippref);
736 prefix_length[0] = 0;
737 clib_memcpy (dst, fid_addr_mac (src), 6);
741 clib_warning ("Unknown FID type %d!", fid_addr_type (src));
747 fid_type_to_api_type (fid_address_t * fid)
751 switch (fid_addr_type (fid))
753 case FID_ADDR_IP_PREF:
754 ippref = &fid_addr_ippref (fid);
755 if (ip_prefix_version (ippref) == IP4)
757 else if (ip_prefix_version (ippref) == IP6)
772 send_one_eid_table_details (mapping_t * mapit,
773 unix_shared_memory_queue_t * q,
774 u32 context, u8 filter)
777 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
778 locator_set_t *ls = 0;
779 vl_api_one_eid_table_details_t *rmp = NULL;
780 gid_address_t *gid = NULL;
782 ip_prefix_t *ip_prefix = NULL;
789 case 0: /* all mappings */
792 case 1: /* local only */
796 case 2: /* remote only */
801 clib_warning ("Filter error, unknown filter: %d", filter);
806 ip_prefix = &gid_address_ippref (gid);
807 mac = gid_address_mac (gid);
809 rmp = vl_msg_api_alloc (sizeof (*rmp));
810 memset (rmp, 0, sizeof (*rmp));
811 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_DETAILS);
813 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
814 if (vec_len (ls->locator_indices) == 0)
815 rmp->locator_set_index = ~0;
817 rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
819 rmp->is_local = mapit->local;
820 rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
821 rmp->action = mapit->action;
822 rmp->authoritative = mapit->authoritative;
824 switch (gid_address_type (gid))
826 case GID_ADDR_SRC_DST:
828 fid = &gid_address_sd_src (gid);
829 rmp->eid_type = fid_type_to_api_type (fid);
830 one_fid_put_api (rmp->seid, &gid_address_sd_src (gid),
831 &rmp->seid_prefix_len);
832 one_fid_put_api (rmp->eid, &gid_address_sd_dst (gid),
833 &rmp->eid_prefix_len);
835 case GID_ADDR_IP_PREFIX:
836 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
837 if (ip_prefix_version (ip_prefix) == IP4)
839 rmp->eid_type = 0; /* ipv4 type */
840 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
841 sizeof (ip_prefix_v4 (ip_prefix)));
845 rmp->eid_type = 1; /* ipv6 type */
846 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
847 sizeof (ip_prefix_v6 (ip_prefix)));
851 rmp->eid_type = 2; /* l2 mac type */
852 clib_memcpy (rmp->eid, mac, 6);
857 rmp->context = context;
858 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
859 rmp->key_id = clib_host_to_net_u16 (mapit->key_id);
860 memcpy (rmp->key, mapit->key, vec_len (mapit->key));
861 vl_msg_api_send_shmem (q, (u8 *) & rmp);
865 vl_api_one_eid_table_dump_t_handler (vl_api_one_eid_table_dump_t * mp)
868 unix_shared_memory_queue_t *q = NULL;
869 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
870 mapping_t *mapit = NULL;
871 gid_address_t _eid, *eid = &_eid;
873 q = vl_api_client_index_to_input_queue (mp->client_index);
881 memset (eid, 0, sizeof (*eid));
883 unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
884 mp->eid_type, mp->eid, mp->prefix_length);
886 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
890 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
891 send_one_eid_table_details (mapit, q, mp->context,
892 0 /* ignore filter */ );
897 pool_foreach (mapit, lcm->mapping_pool,
899 send_one_eid_table_details(mapit, q, mp->context,
907 send_one_map_server_details (ip_address_t * ip,
908 unix_shared_memory_queue_t * q, u32 context)
910 vl_api_one_map_server_details_t *rmp = NULL;
912 rmp = vl_msg_api_alloc (sizeof (*rmp));
913 memset (rmp, 0, sizeof (*rmp));
914 rmp->_vl_msg_id = ntohs (VL_API_ONE_MAP_SERVER_DETAILS);
916 switch (ip_addr_version (ip))
920 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
921 sizeof (ip_addr_v4 (ip)));
926 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
927 sizeof (ip_addr_v6 (ip)));
933 rmp->context = context;
935 vl_msg_api_send_shmem (q, (u8 *) & rmp);
939 vl_api_one_map_server_dump_t_handler (vl_api_one_map_server_dump_t * mp)
941 unix_shared_memory_queue_t *q = NULL;
942 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
945 q = vl_api_client_index_to_input_queue (mp->client_index);
951 vec_foreach (mr, lcm->map_servers)
953 send_one_map_server_details (&mr->address, q, mp->context);
958 send_one_map_resolver_details (ip_address_t * ip,
959 unix_shared_memory_queue_t * q, u32 context)
961 vl_api_one_map_resolver_details_t *rmp = NULL;
963 rmp = vl_msg_api_alloc (sizeof (*rmp));
964 memset (rmp, 0, sizeof (*rmp));
965 rmp->_vl_msg_id = ntohs (VL_API_ONE_MAP_RESOLVER_DETAILS);
967 switch (ip_addr_version (ip))
971 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
972 sizeof (ip_addr_v4 (ip)));
977 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
978 sizeof (ip_addr_v6 (ip)));
984 rmp->context = context;
986 vl_msg_api_send_shmem (q, (u8 *) & rmp);
990 vl_api_one_map_resolver_dump_t_handler (vl_api_one_map_resolver_dump_t * mp)
992 unix_shared_memory_queue_t *q = NULL;
993 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
996 q = vl_api_client_index_to_input_queue (mp->client_index);
1002 vec_foreach (mr, lcm->map_resolvers)
1004 send_one_map_resolver_details (&mr->address, q, mp->context);
1009 send_eid_table_map_pair (hash_pair_t * p,
1010 unix_shared_memory_queue_t * q, u32 context)
1012 vl_api_one_eid_table_map_details_t *rmp = NULL;
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_MAP_DETAILS);
1018 rmp->vni = clib_host_to_net_u32 (p->key);
1019 rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
1020 rmp->context = context;
1021 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1025 vl_api_one_eid_table_map_dump_t_handler (vl_api_one_eid_table_map_dump_t * mp)
1027 unix_shared_memory_queue_t *q = NULL;
1028 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1030 uword *vni_table = 0;
1032 q = vl_api_client_index_to_input_queue (mp->client_index);
1040 vni_table = lcm->bd_id_by_vni;
1044 vni_table = lcm->table_id_by_vni;
1048 hash_foreach_pair (p, vni_table,
1050 send_eid_table_map_pair (p, q, mp->context);
1056 send_eid_table_vni (u32 vni, unix_shared_memory_queue_t * q, u32 context)
1058 vl_api_one_eid_table_vni_details_t *rmp = 0;
1060 rmp = vl_msg_api_alloc (sizeof (*rmp));
1061 memset (rmp, 0, sizeof (*rmp));
1062 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_VNI_DETAILS);
1063 rmp->context = context;
1064 rmp->vni = clib_host_to_net_u32 (vni);
1065 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1069 one_adjacency_copy (vl_api_one_adjacency_t * dst, lisp_adjacency_t * adjs)
1071 lisp_adjacency_t *adj;
1072 vl_api_one_adjacency_t a;
1073 u32 i, n = vec_len (adjs);
1075 for (i = 0; i < n; i++)
1077 adj = vec_elt_at_index (adjs, i);
1078 memset (&a, 0, sizeof (a));
1080 switch (gid_address_type (&adj->reid))
1082 case GID_ADDR_IP_PREFIX:
1083 a.reid_prefix_len = gid_address_ippref_len (&adj->reid);
1084 a.leid_prefix_len = gid_address_ippref_len (&adj->leid);
1085 if (gid_address_ip_version (&adj->reid) == IP4)
1087 a.eid_type = 0; /* ipv4 type */
1088 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 4);
1089 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 4);
1093 a.eid_type = 1; /* ipv6 type */
1094 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 16);
1095 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 16);
1099 a.eid_type = 2; /* l2 mac type */
1100 mac_copy (a.reid, gid_address_mac (&adj->reid));
1101 mac_copy (a.leid, gid_address_mac (&adj->leid));
1111 vl_api_show_one_rloc_probe_state_t_handler
1112 (vl_api_show_one_rloc_probe_state_t * mp)
1114 vl_api_show_one_rloc_probe_state_reply_t *rmp = 0;
1118 REPLY_MACRO2 (VL_API_SHOW_ONE_RLOC_PROBE_STATE_REPLY,
1120 rmp->is_enabled = vnet_lisp_rloc_probe_state_get ();
1126 vl_api_show_one_map_register_state_t_handler
1127 (vl_api_show_one_map_register_state_t * mp)
1129 vl_api_show_one_map_register_state_reply_t *rmp = 0;
1133 REPLY_MACRO2 (VL_API_SHOW_ONE_MAP_REGISTER_STATE_REPLY,
1135 rmp->is_enabled = vnet_lisp_map_register_state_get ();
1141 vl_api_one_adjacencies_get_t_handler (vl_api_one_adjacencies_get_t * mp)
1143 vl_api_one_adjacencies_get_reply_t *rmp = 0;
1144 lisp_adjacency_t *adjs = 0;
1147 u32 vni = clib_net_to_host_u32 (mp->vni);
1149 adjs = vnet_lisp_adjacencies_get_by_vni (vni);
1150 size = vec_len (adjs) * sizeof (vl_api_one_adjacency_t);
1153 REPLY_MACRO4 (VL_API_ONE_ADJACENCIES_GET_REPLY, size,
1155 rmp->count = clib_host_to_net_u32 (vec_len (adjs));
1156 one_adjacency_copy (rmp->adjacencies, adjs);
1164 vl_api_one_eid_table_vni_dump_t_handler (vl_api_one_eid_table_vni_dump_t * mp)
1168 unix_shared_memory_queue_t *q = 0;
1169 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1171 q = vl_api_client_index_to_input_queue (mp->client_index);
1178 hash_foreach_pair (p, lcm->table_id_by_vni,
1180 hash_set (vnis, p->key, 0);
1183 hash_foreach_pair (p, lcm->bd_id_by_vni,
1185 hash_set (vnis, p->key, 0);
1188 hash_foreach_pair (p, vnis,
1190 send_eid_table_vni (p->key, q, mp->context);
1198 vl_api_show_one_status_t_handler (vl_api_show_one_status_t * mp)
1200 unix_shared_memory_queue_t *q = NULL;
1201 vl_api_show_one_status_reply_t *rmp = NULL;
1204 q = vl_api_client_index_to_input_queue (mp->client_index);
1211 REPLY_MACRO2(VL_API_SHOW_ONE_STATUS_REPLY,
1213 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
1214 rmp->feature_status = vnet_lisp_enable_disable_status ();
1220 vl_api_one_get_map_request_itr_rlocs_t_handler
1221 (vl_api_one_get_map_request_itr_rlocs_t * mp)
1223 unix_shared_memory_queue_t *q = NULL;
1224 vl_api_one_get_map_request_itr_rlocs_reply_t *rmp = NULL;
1225 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1226 locator_set_t *loc_set = 0;
1230 q = vl_api_client_index_to_input_queue (mp->client_index);
1236 if (~0 == lcm->mreq_itr_rlocs)
1238 tmp_str = format (0, " ");
1243 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
1244 tmp_str = format (0, "%s", loc_set->name);
1248 REPLY_MACRO2(VL_API_ONE_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
1250 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1251 ARRAY_LEN(rmp->locator_set_name) - 1);
1259 vl_api_show_one_pitr_t_handler (vl_api_show_one_pitr_t * mp)
1261 unix_shared_memory_queue_t *q = NULL;
1262 vl_api_show_one_pitr_reply_t *rmp = NULL;
1263 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1265 locator_set_t *ls = 0;
1269 q = vl_api_client_index_to_input_queue (mp->client_index);
1275 if (!lcm->lisp_pitr)
1277 tmp_str = format (0, "N/A");
1281 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
1282 if (~0 != m->locator_set_index)
1285 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
1286 tmp_str = format (0, "%s", ls->name);
1290 tmp_str = format (0, "N/A");
1293 vec_add1 (tmp_str, 0);
1296 REPLY_MACRO2(VL_API_SHOW_ONE_PITR_REPLY,
1298 rmp->status = lcm->lisp_pitr;
1299 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1300 ARRAY_LEN(rmp->locator_set_name) - 1);
1306 vl_api_show_one_stats_enable_disable_t_handler
1307 (vl_api_show_one_stats_enable_disable_t * mp)
1309 vl_api_show_one_stats_enable_disable_reply_t *rmp = NULL;
1310 vnet_api_error_t rv = 0;
1313 REPLY_MACRO2 (VL_API_SHOW_ONE_STATS_ENABLE_DISABLE_REPLY,
1315 rmp->is_en = vnet_lisp_stats_enable_disable_state ();
1321 vl_api_one_stats_enable_disable_t_handler
1322 (vl_api_one_stats_enable_disable_t * mp)
1324 vl_api_one_enable_disable_reply_t *rmp = NULL;
1326 vnet_api_error_t rv = vnet_lisp_stats_enable_disable (mp->is_en);
1327 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
1331 lisp_fid_addr_to_api (fid_address_t * fid, u8 * dst, u8 * api_eid_type,
1334 switch (fid_addr_type (fid))
1336 case FID_ADDR_IP_PREF:
1337 *prefix_length = fid_addr_prefix_length (fid);
1338 if (fid_addr_ip_version (fid) == IP4)
1340 *api_eid_type = 0; /* ipv4 type */
1341 clib_memcpy (dst, &fid_addr_ippref (fid), 4);
1345 *api_eid_type = 1; /* ipv6 type */
1346 clib_memcpy (dst, &fid_addr_ippref (fid), 16);
1350 *api_eid_type = 2; /* l2 mac type */
1351 mac_copy (dst, fid_addr_mac (fid));
1359 vl_api_one_stats_flush_t_handler (vl_api_one_stats_flush_t * mp)
1361 vl_api_one_stats_flush_reply_t *rmp;
1364 rv = vnet_lisp_flush_stats ();
1365 REPLY_MACRO (VL_API_ONE_STATS_FLUSH_REPLY);
1369 vl_api_one_stats_dump_t_handler (vl_api_one_stats_dump_t * mp)
1371 vl_api_one_stats_details_t *rmp;
1372 lisp_api_stats_t *stats, *stat;
1375 stats = vnet_lisp_get_stats ();
1376 vec_foreach (stat, stats)
1379 REPLY_DETAILS (VL_API_ONE_STATS_DETAILS,
1381 lisp_fid_addr_to_api (&stat->deid, rmp->deid, &rmp->eid_type,
1382 &rmp->deid_pref_len);
1383 lisp_fid_addr_to_api (&stat->seid, rmp->seid, &rmp->eid_type,
1384 &rmp->seid_pref_len);
1385 rmp->vni = clib_host_to_net_u32 (stat->vni);
1387 rmp->is_ip4 = ip_addr_version (&stat->rmt_rloc) == IP4 ? 1 : 0;
1388 ip_address_copy_addr (rmp->rloc, &stat->rmt_rloc);
1389 ip_address_copy_addr (rmp->lloc, &stat->loc_rloc);
1391 rmp->pkt_count = clib_host_to_net_u32 (stat->counters.packets);
1392 rmp->bytes = clib_host_to_net_u32 (stat->counters.bytes);
1399 vl_api_one_add_del_l2_arp_entry_t_handler
1400 (vl_api_one_add_del_l2_arp_entry_t * mp)
1402 vl_api_one_add_del_l2_arp_entry_reply_t *rmp;
1404 gid_address_t _arp, *arp = &_arp;
1405 memset (arp, 0, sizeof (*arp));
1407 gid_address_type (arp) = GID_ADDR_ARP;
1408 gid_address_arp_bd (arp) = clib_net_to_host_u32 (mp->bd);
1410 /* vpp keeps ip4 addresses in network byte order */
1411 clib_memcpy (&gid_address_arp_ip4 (arp), &mp->ip4, 4);
1413 rv = vnet_lisp_add_del_l2_arp_entry (arp, mp->mac, mp->is_add);
1415 REPLY_MACRO (VL_API_ONE_ADD_DEL_L2_ARP_ENTRY_REPLY);
1419 vl_api_one_l2_arp_bd_get_t_handler (vl_api_one_l2_arp_bd_get_t * mp)
1421 vl_api_one_l2_arp_bd_get_reply_t *rmp;
1426 u32 *bds = vnet_lisp_l2_arp_bds_get ();
1427 u32 size = hash_elts (bds) * sizeof (u32);
1430 REPLY_MACRO4 (VL_API_ONE_L2_ARP_BD_GET_REPLY, size,
1432 rmp->count = clib_host_to_net_u32 (hash_elts (bds));
1433 hash_foreach_pair (p, bds,
1435 rmp->bridge_domains[i++] = clib_host_to_net_u32 (p->key);
1444 vl_api_one_l2_arp_entries_get_t_handler (vl_api_one_l2_arp_entries_get_t * mp)
1446 vl_api_one_l2_arp_entries_get_reply_t *rmp;
1447 lisp_api_l2_arp_entry_t *entries = 0, *e;
1451 u32 bd = clib_net_to_host_u32 (mp->bd);
1453 entries = vnet_lisp_l2_arp_entries_get_by_bd (bd);
1454 u32 size = vec_len (entries) * sizeof (u32);
1457 REPLY_MACRO4 (VL_API_ONE_L2_ARP_ENTRIES_GET_REPLY, size,
1459 rmp->count = clib_host_to_net_u32 (vec_len (entries));
1460 vec_foreach (e, entries)
1462 mac_copy (rmp->entries[i].mac, e->mac);
1463 rmp->entries[i].ip4 = e->ip4;
1474 * Add vpe's API message handlers to the table.
1475 * vlib has alread mapped shared memory and
1476 * added the client registration handlers.
1477 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
1479 #define vl_msg_name_crc_list
1480 #include <vnet/vnet_all_api_h.h>
1481 #undef vl_msg_name_crc_list
1484 setup_message_id_table (api_main_t * am)
1486 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
1487 foreach_vl_msg_name_crc_one;
1491 static clib_error_t *
1492 one_api_hookup (vlib_main_t * vm)
1494 api_main_t *am = &api_main;
1497 vl_msg_api_set_handlers(VL_API_##N, #n, \
1498 vl_api_##n##_t_handler, \
1500 vl_api_##n##_t_endian, \
1501 vl_api_##n##_t_print, \
1502 sizeof(vl_api_##n##_t), 1);
1503 foreach_vpe_api_msg;
1507 * Set up the (msg_name, crc, message-id) table
1509 setup_message_id_table (am);
1514 VLIB_API_INIT_FUNCTION (one_api_hookup);
1517 * fd.io coding-style-patch-verification: ON
1520 * eval: (c-set-style "gnu")