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_NSH_SET_LOCATOR_SET, one_nsh_set_locator_set) \
94 _(ONE_MAP_REQUEST_MODE, one_map_request_mode) \
95 _(ONE_EID_TABLE_ADD_DEL_MAP, one_eid_table_add_del_map) \
96 _(ONE_LOCATOR_SET_DUMP, one_locator_set_dump) \
97 _(ONE_LOCATOR_DUMP, one_locator_dump) \
98 _(ONE_EID_TABLE_DUMP, one_eid_table_dump) \
99 _(ONE_MAP_RESOLVER_DUMP, one_map_resolver_dump) \
100 _(ONE_MAP_SERVER_DUMP, one_map_server_dump) \
101 _(ONE_EID_TABLE_MAP_DUMP, one_eid_table_map_dump) \
102 _(ONE_EID_TABLE_VNI_DUMP, one_eid_table_vni_dump) \
103 _(ONE_ADJACENCIES_GET, one_adjacencies_get) \
104 _(SHOW_ONE_NSH_MAPPING, show_one_nsh_mapping) \
105 _(SHOW_ONE_RLOC_PROBE_STATE, show_one_rloc_probe_state) \
106 _(SHOW_ONE_MAP_REGISTER_STATE, show_one_map_register_state) \
107 _(SHOW_ONE_STATUS, show_one_status) \
108 _(ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \
109 one_add_del_map_request_itr_rlocs) \
110 _(ONE_GET_MAP_REQUEST_ITR_RLOCS, one_get_map_request_itr_rlocs) \
111 _(SHOW_ONE_PITR, show_one_pitr) \
112 _(SHOW_ONE_MAP_REQUEST_MODE, show_one_map_request_mode) \
113 _(ONE_USE_PETR, one_use_petr) \
114 _(SHOW_ONE_USE_PETR, show_one_use_petr) \
115 _(SHOW_ONE_STATS_ENABLE_DISABLE, show_one_stats_enable_disable) \
116 _(ONE_STATS_ENABLE_DISABLE, one_stats_enable_disable) \
117 _(ONE_STATS_DUMP, one_stats_dump) \
118 _(ONE_STATS_FLUSH, one_stats_flush) \
119 _(ONE_L2_ARP_BD_GET, one_l2_arp_bd_get) \
120 _(ONE_L2_ARP_ENTRIES_GET, one_l2_arp_entries_get) \
121 _(ONE_ADD_DEL_L2_ARP_ENTRY, one_add_del_l2_arp_entry) \
125 unformat_one_locs (vl_api_one_remote_locator_t * rmt_locs, u32 rloc_num)
128 locator_t *locs = 0, loc;
129 vl_api_one_remote_locator_t *r;
131 for (i = 0; i < rloc_num; i++)
133 /* remote locators */
135 memset (&loc, 0, sizeof (loc));
136 gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
138 loc.priority = r->priority;
139 loc.weight = r->weight;
141 vec_add1 (locs, loc);
147 vl_api_one_add_del_locator_set_t_handler (vl_api_one_add_del_locator_set_t *
150 vl_api_one_add_del_locator_set_reply_t *rmp;
152 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
154 vl_api_one_local_locator_t *ls_loc;
155 u32 ls_index = ~0, locator_num;
156 u8 *locator_name = NULL;
159 memset (a, 0, sizeof (a[0]));
161 locator_name = format (0, "%s", mp->locator_set_name);
163 a->name = locator_name;
164 a->is_add = mp->is_add;
166 locator_num = clib_net_to_host_u32 (mp->locator_num);
168 memset (&locator, 0, sizeof (locator));
169 for (i = 0; i < locator_num; i++)
171 ls_loc = &mp->locators[i];
172 VALIDATE_SW_IF_INDEX (ls_loc);
174 locator.sw_if_index = htonl (ls_loc->sw_if_index);
175 locator.priority = ls_loc->priority;
176 locator.weight = ls_loc->weight;
178 vec_add1 (a->locators, locator);
181 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
183 BAD_SW_IF_INDEX_LABEL;
185 vec_free (locator_name);
186 vec_free (a->locators);
189 REPLY_MACRO2 (VL_API_ONE_ADD_DEL_LOCATOR_SET_REPLY,
191 rmp->ls_index = clib_host_to_net_u32 (ls_index);
197 vl_api_one_add_del_locator_t_handler (vl_api_one_add_del_locator_t * mp)
199 vl_api_one_add_del_locator_reply_t *rmp;
201 locator_t locator, *locators = NULL;
202 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
204 u8 *locator_name = NULL;
206 memset (&locator, 0, sizeof (locator));
207 memset (a, 0, sizeof (a[0]));
209 locator.sw_if_index = ntohl (mp->sw_if_index);
210 locator.priority = mp->priority;
211 locator.weight = mp->weight;
213 vec_add1 (locators, locator);
215 locator_name = format (0, "%s", mp->locator_set_name);
217 a->name = locator_name;
218 a->locators = locators;
219 a->is_add = mp->is_add;
222 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
225 vec_free (locator_name);
227 REPLY_MACRO (VL_API_ONE_ADD_DEL_LOCATOR_REPLY);
234 } __attribute__ ((__packed__)) lisp_nsh_api_t;
237 unformat_one_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
245 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
246 gid_address_ip_set (dst, src, IP4);
247 gid_address_ippref_len (dst) = len;
248 ip_prefix_normalize (&gid_address_ippref (dst));
251 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
252 gid_address_ip_set (dst, src, IP6);
253 gid_address_ippref_len (dst) = len;
254 ip_prefix_normalize (&gid_address_ippref (dst));
257 gid_address_type (dst) = GID_ADDR_MAC;
258 clib_memcpy (&gid_address_mac (dst), src, 6);
261 gid_address_type (dst) = GID_ADDR_NSH;
263 gid_address_nsh_spi (dst) = clib_net_to_host_u32 (nsh->spi);
264 gid_address_nsh_si (dst) = nsh->si;
268 return VNET_API_ERROR_INVALID_VALUE;
271 gid_address_vni (dst) = vni;
277 vl_api_one_add_del_local_eid_t_handler (vl_api_one_add_del_local_eid_t * mp)
279 vl_api_one_add_del_local_eid_reply_t *rmp;
280 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
282 gid_address_t _eid, *eid = &_eid;
284 u32 locator_set_index = ~0, map_index = ~0;
285 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
286 u8 *name = NULL, *key = NULL;
287 memset (a, 0, sizeof (a[0]));
288 memset (eid, 0, sizeof (eid[0]));
290 rv = unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
291 mp->eid_type, mp->eid, mp->prefix_len);
295 if (gid_address_type (eid) == GID_ADDR_NSH)
297 rv = VNET_API_ERROR_INVALID_VALUE;
301 name = format (0, "%s", mp->locator_set_name);
302 p = hash_get_mem (lcm->locator_set_index_by_name, name);
305 rv = VNET_API_ERROR_INVALID_VALUE;
308 locator_set_index = p[0];
311 key = format (0, "%s", mp->key);
313 /* XXX treat batch configuration */
314 a->is_add = mp->is_add;
315 gid_address_copy (&a->eid, eid);
316 a->locator_set_index = locator_set_index;
319 a->key_id = clib_net_to_host_u16 (mp->key_id);
321 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
326 gid_address_free (&a->eid);
328 REPLY_MACRO (VL_API_ONE_ADD_DEL_LOCAL_EID_REPLY);
332 vl_api_one_eid_table_add_del_map_t_handler
333 (vl_api_one_eid_table_add_del_map_t * mp)
335 vl_api_one_eid_table_add_del_map_reply_t *rmp;
337 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
338 clib_net_to_host_u32 (mp->dp_table),
339 mp->is_l2, mp->is_add);
340 REPLY_MACRO (VL_API_ONE_EID_TABLE_ADD_DEL_MAP_REPLY)}
343 vl_api_one_add_del_map_server_t_handler (vl_api_one_add_del_map_server_t * mp)
345 vl_api_one_add_del_map_server_reply_t *rmp;
349 memset (&addr, 0, sizeof (addr));
351 ip_address_set (&addr, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
352 rv = vnet_lisp_add_del_map_server (&addr, mp->is_add);
354 REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_SERVER_REPLY);
358 vl_api_one_add_del_map_resolver_t_handler (vl_api_one_add_del_map_resolver_t
361 vl_api_one_add_del_map_resolver_reply_t *rmp;
363 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
365 memset (a, 0, sizeof (a[0]));
367 a->is_add = mp->is_add;
368 ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
370 rv = vnet_lisp_add_del_map_resolver (a);
372 REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_RESOLVER_REPLY);
376 vl_api_one_map_register_enable_disable_t_handler
377 (vl_api_one_map_register_enable_disable_t * mp)
379 vl_api_one_map_register_enable_disable_reply_t *rmp;
382 vnet_lisp_map_register_enable_disable (mp->is_enabled);
383 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
387 vl_api_one_rloc_probe_enable_disable_t_handler
388 (vl_api_one_rloc_probe_enable_disable_t * mp)
390 vl_api_one_rloc_probe_enable_disable_reply_t *rmp;
393 vnet_lisp_rloc_probe_enable_disable (mp->is_enabled);
394 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
398 vl_api_one_enable_disable_t_handler (vl_api_one_enable_disable_t * mp)
400 vl_api_one_enable_disable_reply_t *rmp;
403 vnet_lisp_enable_disable (mp->is_en);
404 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
408 vl_api_show_one_map_request_mode_t_handler
409 (vl_api_show_one_map_request_mode_t * mp)
412 vl_api_show_one_map_request_mode_reply_t *rmp;
415 REPLY_MACRO2(VL_API_SHOW_ONE_MAP_REQUEST_MODE_REPLY,
417 rmp->mode = vnet_lisp_get_map_request_mode ();
423 vl_api_one_map_request_mode_t_handler (vl_api_one_map_request_mode_t * mp)
425 vl_api_one_map_request_mode_reply_t *rmp;
428 rv = vnet_lisp_set_map_request_mode (mp->mode);
430 REPLY_MACRO (VL_API_ONE_MAP_REQUEST_MODE_REPLY);
434 vl_api_one_nsh_set_locator_set_t_handler (vl_api_one_nsh_set_locator_set_t
437 vl_api_one_nsh_set_locator_set_reply_t *rmp;
441 ls_name = format (0, "%s", mp->ls_name);
442 rv = vnet_lisp_nsh_set_locator_set (ls_name, mp->is_add);
445 REPLY_MACRO (VL_API_ONE_PITR_SET_LOCATOR_SET_REPLY);
449 vl_api_one_pitr_set_locator_set_t_handler (vl_api_one_pitr_set_locator_set_t
452 vl_api_one_pitr_set_locator_set_reply_t *rmp;
456 ls_name = format (0, "%s", mp->ls_name);
457 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
460 REPLY_MACRO (VL_API_ONE_PITR_SET_LOCATOR_SET_REPLY);
464 vl_api_one_use_petr_t_handler (vl_api_one_use_petr_t * mp)
466 vl_api_one_use_petr_reply_t *rmp;
470 ip_address_set (&addr, &mp->address, mp->is_ip4 ? IP4 : IP6);
471 rv = vnet_lisp_use_petr (&addr, mp->is_add);
473 REPLY_MACRO (VL_API_ONE_USE_PETR_REPLY);
477 vl_api_show_one_use_petr_t_handler (vl_api_show_one_use_petr_t * mp)
479 unix_shared_memory_queue_t *q = NULL;
480 vl_api_show_one_use_petr_reply_t *rmp = NULL;
481 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
483 locator_set_t *ls = 0;
489 q = vl_api_client_index_to_input_queue (mp->client_index);
495 memset (&addr, 0, sizeof (addr));
496 status = lcm->flags & LISP_FLAG_USE_PETR;
499 m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index);
500 if (~0 != m->locator_set_index)
503 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
504 loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]);
505 gid_address_copy (&addr, &loc->address);
510 REPLY_MACRO2 (VL_API_SHOW_ONE_USE_PETR_REPLY,
512 rmp->status = status;
513 ip_address_t *ip = &gid_address_ip (&addr);
514 switch (ip_addr_version (ip))
517 clib_memcpy (rmp->address, &ip_addr_v4 (ip),
518 sizeof (ip_addr_v4 (ip)));
522 clib_memcpy (rmp->address, &ip_addr_v6 (ip),
523 sizeof (ip_addr_v6 (ip)));
529 rmp->is_ip4 = (gid_address_ip_version (&addr) == IP4);
535 vl_api_one_add_del_map_request_itr_rlocs_t_handler
536 (vl_api_one_add_del_map_request_itr_rlocs_t * mp)
538 vl_api_one_add_del_map_request_itr_rlocs_reply_t *rmp;
540 u8 *locator_set_name = NULL;
541 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
543 locator_set_name = format (0, "%s", mp->locator_set_name);
545 a->is_add = mp->is_add;
546 a->locator_set_name = locator_set_name;
548 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
550 vec_free (locator_set_name);
552 REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
556 vl_api_one_add_del_remote_mapping_t_handler
557 (vl_api_one_add_del_remote_mapping_t * mp)
559 locator_t *rlocs = 0;
560 vl_api_one_add_del_remote_mapping_reply_t *rmp;
562 gid_address_t _eid, *eid = &_eid;
563 u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
565 memset (eid, 0, sizeof (eid[0]));
567 rv = unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
568 mp->eid_type, mp->eid, mp->eid_len);
572 rlocs = unformat_one_locs (mp->rlocs, rloc_num);
576 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
577 gid_address_copy (&a->reid, eid);
579 rv = vnet_lisp_add_del_adjacency (a);
586 /* NOTE: for now this works as a static remote mapping, i.e.,
587 * not authoritative and ttl infinite. */
588 rv = vnet_lisp_add_del_mapping (eid, rlocs, mp->action, 0, ~0,
589 mp->is_add, 1 /* is_static */ , 0);
592 vnet_lisp_clear_all_remote_adjacencies ();
597 REPLY_MACRO (VL_API_ONE_ADD_DEL_REMOTE_MAPPING_REPLY);
601 vl_api_one_add_del_adjacency_t_handler (vl_api_one_add_del_adjacency_t * mp)
603 vl_api_one_add_del_adjacency_reply_t *rmp;
604 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
607 memset (a, 0, sizeof (a[0]));
609 rv = unformat_one_eid_api (&a->leid, clib_net_to_host_u32 (mp->vni),
610 mp->eid_type, mp->leid, mp->leid_len);
611 rv |= unformat_one_eid_api (&a->reid, clib_net_to_host_u32 (mp->vni),
612 mp->eid_type, mp->reid, mp->reid_len);
617 a->is_add = mp->is_add;
618 rv = vnet_lisp_add_del_adjacency (a);
621 REPLY_MACRO (VL_API_ONE_ADD_DEL_ADJACENCY_REPLY);
625 send_one_locator_details (lisp_cp_main_t * lcm,
627 unix_shared_memory_queue_t * q, u32 context)
629 vl_api_one_locator_details_t *rmp;
631 rmp = vl_msg_api_alloc (sizeof (*rmp));
632 memset (rmp, 0, sizeof (*rmp));
633 rmp->_vl_msg_id = ntohs (VL_API_ONE_LOCATOR_DETAILS);
634 rmp->context = context;
636 rmp->local = loc->local;
639 rmp->sw_if_index = ntohl (loc->sw_if_index);
643 rmp->is_ipv6 = gid_address_ip_version (&loc->address);
644 ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
646 rmp->priority = loc->priority;
647 rmp->weight = loc->weight;
649 vl_msg_api_send_shmem (q, (u8 *) & rmp);
653 vl_api_one_locator_dump_t_handler (vl_api_one_locator_dump_t * mp)
656 unix_shared_memory_queue_t *q = 0;
657 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
658 locator_set_t *lsit = 0;
660 u32 ls_index = ~0, *locit = 0;
663 q = vl_api_client_index_to_input_queue (mp->client_index);
669 if (mp->is_index_set)
670 ls_index = htonl (mp->ls_index);
673 /* make sure we get a proper C-string */
674 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
675 ls_name = format (0, "%s", mp->ls_name);
676 p = hash_get_mem (lcm->locator_set_index_by_name, ls_name);
682 if (pool_is_free_index (lcm->locator_set_pool, ls_index))
685 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
687 vec_foreach (locit, lsit->locator_indices)
689 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
690 send_one_locator_details (lcm, loc, q, mp->context);
697 send_one_locator_set_details (lisp_cp_main_t * lcm,
698 locator_set_t * lsit,
699 unix_shared_memory_queue_t * q,
700 u32 context, u32 ls_index)
702 vl_api_one_locator_set_details_t *rmp;
705 rmp = vl_msg_api_alloc (sizeof (*rmp));
706 memset (rmp, 0, sizeof (*rmp));
707 rmp->_vl_msg_id = ntohs (VL_API_ONE_LOCATOR_SET_DETAILS);
708 rmp->context = context;
710 rmp->ls_index = htonl (ls_index);
713 ASSERT (lsit->name != NULL);
714 strncpy ((char *) rmp->ls_name, (char *) lsit->name,
715 vec_len (lsit->name));
719 str = format (0, "<remote-%d>", ls_index);
720 strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str));
724 vl_msg_api_send_shmem (q, (u8 *) & rmp);
728 vl_api_one_locator_set_dump_t_handler (vl_api_one_locator_set_dump_t * mp)
730 unix_shared_memory_queue_t *q = NULL;
731 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
732 locator_set_t *lsit = NULL;
735 q = vl_api_client_index_to_input_queue (mp->client_index);
743 pool_foreach (lsit, lcm->locator_set_pool,
745 if (filter && !((1 == filter && lsit->local) ||
746 (2 == filter && !lsit->local)))
750 send_one_locator_set_details (lcm, lsit, q, mp->context,
751 lsit - lcm->locator_set_pool);
757 one_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length)
759 ASSERT (prefix_length);
760 ip_prefix_t *ippref = &fid_addr_ippref (src);
762 switch (fid_addr_type (src))
764 case FID_ADDR_IP_PREF:
765 if (ip_prefix_version (ippref) == IP4)
766 clib_memcpy (dst, &ip_prefix_v4 (ippref), 4);
768 clib_memcpy (dst, &ip_prefix_v6 (ippref), 16);
769 prefix_length[0] = ip_prefix_len (ippref);
773 prefix_length[0] = 0;
774 clib_memcpy (dst, fid_addr_mac (src), 6);
778 clib_warning ("Unknown FID type %d!", fid_addr_type (src));
784 fid_type_to_api_type (fid_address_t * fid)
788 switch (fid_addr_type (fid))
790 case FID_ADDR_IP_PREF:
791 ippref = &fid_addr_ippref (fid);
792 if (ip_prefix_version (ippref) == IP4)
794 else if (ip_prefix_version (ippref) == IP6)
809 send_one_eid_table_details (mapping_t * mapit,
810 unix_shared_memory_queue_t * q,
811 u32 context, u8 filter)
814 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
815 locator_set_t *ls = 0;
816 vl_api_one_eid_table_details_t *rmp = NULL;
817 gid_address_t *gid = NULL;
819 ip_prefix_t *ip_prefix = NULL;
821 if (mapit->pitr_set || mapit->nsh_set)
826 case 0: /* all mappings */
829 case 1: /* local only */
833 case 2: /* remote only */
838 clib_warning ("Filter error, unknown filter: %d", filter);
843 ip_prefix = &gid_address_ippref (gid);
844 mac = gid_address_mac (gid);
846 rmp = vl_msg_api_alloc (sizeof (*rmp));
847 memset (rmp, 0, sizeof (*rmp));
848 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_DETAILS);
850 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
851 if (vec_len (ls->locator_indices) == 0)
852 rmp->locator_set_index = ~0;
854 rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
856 rmp->is_local = mapit->local;
857 rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
858 rmp->action = mapit->action;
859 rmp->authoritative = mapit->authoritative;
861 switch (gid_address_type (gid))
863 case GID_ADDR_SRC_DST:
865 fid = &gid_address_sd_src (gid);
866 rmp->eid_type = fid_type_to_api_type (fid);
867 one_fid_put_api (rmp->seid, &gid_address_sd_src (gid),
868 &rmp->seid_prefix_len);
869 one_fid_put_api (rmp->eid, &gid_address_sd_dst (gid),
870 &rmp->eid_prefix_len);
872 case GID_ADDR_IP_PREFIX:
873 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
874 if (ip_prefix_version (ip_prefix) == IP4)
876 rmp->eid_type = 0; /* ipv4 type */
877 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
878 sizeof (ip_prefix_v4 (ip_prefix)));
882 rmp->eid_type = 1; /* ipv6 type */
883 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
884 sizeof (ip_prefix_v6 (ip_prefix)));
888 rmp->eid_type = 2; /* l2 mac type */
889 clib_memcpy (rmp->eid, mac, 6);
892 rmp->eid_type = 3; /* NSH type */
894 nsh.spi = clib_host_to_net_u32 (gid_address_nsh_spi (gid));
895 nsh.si = gid_address_nsh_si (gid);
896 clib_memcpy (rmp->eid, &nsh, sizeof (nsh));
901 rmp->context = context;
902 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
903 rmp->key_id = clib_host_to_net_u16 (mapit->key_id);
904 memcpy (rmp->key, mapit->key, vec_len (mapit->key));
905 vl_msg_api_send_shmem (q, (u8 *) & rmp);
909 vl_api_one_eid_table_dump_t_handler (vl_api_one_eid_table_dump_t * mp)
912 unix_shared_memory_queue_t *q = NULL;
913 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
914 mapping_t *mapit = NULL;
915 gid_address_t _eid, *eid = &_eid;
917 q = vl_api_client_index_to_input_queue (mp->client_index);
925 memset (eid, 0, sizeof (*eid));
927 unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
928 mp->eid_type, mp->eid, mp->prefix_length);
930 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
934 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
935 send_one_eid_table_details (mapit, q, mp->context,
936 0 /* ignore filter */ );
941 pool_foreach (mapit, lcm->mapping_pool,
943 send_one_eid_table_details(mapit, q, mp->context,
951 send_one_map_server_details (ip_address_t * ip,
952 unix_shared_memory_queue_t * q, u32 context)
954 vl_api_one_map_server_details_t *rmp = NULL;
956 rmp = vl_msg_api_alloc (sizeof (*rmp));
957 memset (rmp, 0, sizeof (*rmp));
958 rmp->_vl_msg_id = ntohs (VL_API_ONE_MAP_SERVER_DETAILS);
960 switch (ip_addr_version (ip))
964 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
965 sizeof (ip_addr_v4 (ip)));
970 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
971 sizeof (ip_addr_v6 (ip)));
977 rmp->context = context;
979 vl_msg_api_send_shmem (q, (u8 *) & rmp);
983 vl_api_one_map_server_dump_t_handler (vl_api_one_map_server_dump_t * mp)
985 unix_shared_memory_queue_t *q = NULL;
986 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
989 q = vl_api_client_index_to_input_queue (mp->client_index);
995 vec_foreach (mr, lcm->map_servers)
997 send_one_map_server_details (&mr->address, q, mp->context);
1002 send_one_map_resolver_details (ip_address_t * ip,
1003 unix_shared_memory_queue_t * q, u32 context)
1005 vl_api_one_map_resolver_details_t *rmp = NULL;
1007 rmp = vl_msg_api_alloc (sizeof (*rmp));
1008 memset (rmp, 0, sizeof (*rmp));
1009 rmp->_vl_msg_id = ntohs (VL_API_ONE_MAP_RESOLVER_DETAILS);
1011 switch (ip_addr_version (ip))
1015 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
1016 sizeof (ip_addr_v4 (ip)));
1021 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
1022 sizeof (ip_addr_v6 (ip)));
1028 rmp->context = context;
1030 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1034 vl_api_one_map_resolver_dump_t_handler (vl_api_one_map_resolver_dump_t * mp)
1036 unix_shared_memory_queue_t *q = NULL;
1037 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1040 q = vl_api_client_index_to_input_queue (mp->client_index);
1046 vec_foreach (mr, lcm->map_resolvers)
1048 send_one_map_resolver_details (&mr->address, q, mp->context);
1053 send_eid_table_map_pair (hash_pair_t * p,
1054 unix_shared_memory_queue_t * q, u32 context)
1056 vl_api_one_eid_table_map_details_t *rmp = NULL;
1058 rmp = vl_msg_api_alloc (sizeof (*rmp));
1059 memset (rmp, 0, sizeof (*rmp));
1060 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_MAP_DETAILS);
1062 rmp->vni = clib_host_to_net_u32 (p->key);
1063 rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
1064 rmp->context = context;
1065 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1069 vl_api_one_eid_table_map_dump_t_handler (vl_api_one_eid_table_map_dump_t * mp)
1071 unix_shared_memory_queue_t *q = NULL;
1072 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1074 uword *vni_table = 0;
1076 q = vl_api_client_index_to_input_queue (mp->client_index);
1084 vni_table = lcm->bd_id_by_vni;
1088 vni_table = lcm->table_id_by_vni;
1092 hash_foreach_pair (p, vni_table,
1094 send_eid_table_map_pair (p, q, mp->context);
1100 send_eid_table_vni (u32 vni, unix_shared_memory_queue_t * q, u32 context)
1102 vl_api_one_eid_table_vni_details_t *rmp = 0;
1104 rmp = vl_msg_api_alloc (sizeof (*rmp));
1105 memset (rmp, 0, sizeof (*rmp));
1106 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_VNI_DETAILS);
1107 rmp->context = context;
1108 rmp->vni = clib_host_to_net_u32 (vni);
1109 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1113 one_adjacency_copy (vl_api_one_adjacency_t * dst, lisp_adjacency_t * adjs)
1115 lisp_adjacency_t *adj;
1116 vl_api_one_adjacency_t a;
1117 u32 i, n = vec_len (adjs);
1120 for (i = 0; i < n; i++)
1122 adj = vec_elt_at_index (adjs, i);
1123 memset (&a, 0, sizeof (a));
1125 switch (gid_address_type (&adj->reid))
1127 case GID_ADDR_IP_PREFIX:
1128 a.reid_prefix_len = gid_address_ippref_len (&adj->reid);
1129 a.leid_prefix_len = gid_address_ippref_len (&adj->leid);
1130 if (gid_address_ip_version (&adj->reid) == IP4)
1132 a.eid_type = 0; /* ipv4 type */
1133 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 4);
1134 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 4);
1138 a.eid_type = 1; /* ipv6 type */
1139 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 16);
1140 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 16);
1144 a.eid_type = 2; /* l2 mac type */
1145 mac_copy (a.reid, gid_address_mac (&adj->reid));
1146 mac_copy (a.leid, gid_address_mac (&adj->leid));
1149 a.eid_type = 3; /* NSH type */
1150 nsh.spi = clib_host_to_net_u32 (gid_address_nsh_spi (&adj->reid));
1151 nsh.si = gid_address_nsh_si (&adj->reid);
1152 clib_memcpy (a.reid, &nsh, sizeof (nsh));
1154 nsh.spi = clib_host_to_net_u32 (gid_address_nsh_spi (&adj->leid));
1155 nsh.si = gid_address_nsh_si (&adj->leid);
1156 clib_memcpy (a.leid, &nsh, sizeof (nsh));
1166 vl_api_show_one_rloc_probe_state_t_handler
1167 (vl_api_show_one_rloc_probe_state_t * mp)
1169 vl_api_show_one_rloc_probe_state_reply_t *rmp = 0;
1173 REPLY_MACRO2 (VL_API_SHOW_ONE_RLOC_PROBE_STATE_REPLY,
1175 rmp->is_enabled = vnet_lisp_rloc_probe_state_get ();
1181 vl_api_show_one_map_register_state_t_handler
1182 (vl_api_show_one_map_register_state_t * mp)
1184 vl_api_show_one_map_register_state_reply_t *rmp = 0;
1188 REPLY_MACRO2 (VL_API_SHOW_ONE_MAP_REGISTER_STATE_REPLY,
1190 rmp->is_enabled = vnet_lisp_map_register_state_get ();
1196 vl_api_one_adjacencies_get_t_handler (vl_api_one_adjacencies_get_t * mp)
1198 vl_api_one_adjacencies_get_reply_t *rmp = 0;
1199 lisp_adjacency_t *adjs = 0;
1202 u32 vni = clib_net_to_host_u32 (mp->vni);
1204 adjs = vnet_lisp_adjacencies_get_by_vni (vni);
1205 size = vec_len (adjs) * sizeof (vl_api_one_adjacency_t);
1208 REPLY_MACRO4 (VL_API_ONE_ADJACENCIES_GET_REPLY, size,
1210 rmp->count = clib_host_to_net_u32 (vec_len (adjs));
1211 one_adjacency_copy (rmp->adjacencies, adjs);
1219 vl_api_one_eid_table_vni_dump_t_handler (vl_api_one_eid_table_vni_dump_t * mp)
1223 unix_shared_memory_queue_t *q = 0;
1224 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1226 q = vl_api_client_index_to_input_queue (mp->client_index);
1233 hash_foreach_pair (p, lcm->table_id_by_vni,
1235 hash_set (vnis, p->key, 0);
1238 hash_foreach_pair (p, lcm->bd_id_by_vni,
1240 hash_set (vnis, p->key, 0);
1243 hash_foreach_pair (p, vnis,
1245 send_eid_table_vni (p->key, q, mp->context);
1253 vl_api_show_one_status_t_handler (vl_api_show_one_status_t * mp)
1255 unix_shared_memory_queue_t *q = NULL;
1256 vl_api_show_one_status_reply_t *rmp = NULL;
1259 q = vl_api_client_index_to_input_queue (mp->client_index);
1266 REPLY_MACRO2(VL_API_SHOW_ONE_STATUS_REPLY,
1268 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
1269 rmp->feature_status = vnet_lisp_enable_disable_status ();
1275 vl_api_one_get_map_request_itr_rlocs_t_handler
1276 (vl_api_one_get_map_request_itr_rlocs_t * mp)
1278 unix_shared_memory_queue_t *q = NULL;
1279 vl_api_one_get_map_request_itr_rlocs_reply_t *rmp = NULL;
1280 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1281 locator_set_t *loc_set = 0;
1285 q = vl_api_client_index_to_input_queue (mp->client_index);
1291 if (~0 == lcm->mreq_itr_rlocs)
1293 tmp_str = format (0, " ");
1298 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
1299 tmp_str = format (0, "%s", loc_set->name);
1303 REPLY_MACRO2(VL_API_ONE_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
1305 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1306 ARRAY_LEN(rmp->locator_set_name) - 1);
1314 vl_api_show_one_nsh_mapping_t_handler (vl_api_show_one_nsh_mapping_t * mp)
1316 unix_shared_memory_queue_t *q = NULL;
1317 vl_api_show_one_nsh_mapping_reply_t *rmp = NULL;
1318 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1320 locator_set_t *ls = 0;
1325 q = vl_api_client_index_to_input_queue (mp->client_index);
1331 if (lcm->nsh_map_index == (u32) ~ 0)
1333 tmp_str = format (0, "N/A");
1337 m = pool_elt_at_index (lcm->mapping_pool, lcm->nsh_map_index);
1338 if (~0 != m->locator_set_index)
1341 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
1342 tmp_str = format (0, "%s", ls->name);
1347 tmp_str = format (0, "N/A");
1350 vec_add1 (tmp_str, 0);
1353 REPLY_MACRO2(VL_API_SHOW_ONE_NSH_MAPPING_REPLY,
1355 rmp->is_set = is_set;
1356 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1357 ARRAY_LEN(rmp->locator_set_name) - 1);
1363 vl_api_show_one_pitr_t_handler (vl_api_show_one_pitr_t * mp)
1365 unix_shared_memory_queue_t *q = NULL;
1366 vl_api_show_one_pitr_reply_t *rmp = NULL;
1367 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1369 locator_set_t *ls = 0;
1373 q = vl_api_client_index_to_input_queue (mp->client_index);
1379 if (!lcm->lisp_pitr)
1381 tmp_str = format (0, "N/A");
1385 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
1386 if (~0 != m->locator_set_index)
1389 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
1390 tmp_str = format (0, "%s", ls->name);
1394 tmp_str = format (0, "N/A");
1397 vec_add1 (tmp_str, 0);
1400 REPLY_MACRO2(VL_API_SHOW_ONE_PITR_REPLY,
1402 rmp->status = lcm->lisp_pitr;
1403 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1404 ARRAY_LEN(rmp->locator_set_name) - 1);
1410 vl_api_show_one_stats_enable_disable_t_handler
1411 (vl_api_show_one_stats_enable_disable_t * mp)
1413 vl_api_show_one_stats_enable_disable_reply_t *rmp = NULL;
1414 vnet_api_error_t rv = 0;
1417 REPLY_MACRO2 (VL_API_SHOW_ONE_STATS_ENABLE_DISABLE_REPLY,
1419 rmp->is_en = vnet_lisp_stats_enable_disable_state ();
1425 vl_api_one_stats_enable_disable_t_handler
1426 (vl_api_one_stats_enable_disable_t * mp)
1428 vl_api_one_enable_disable_reply_t *rmp = NULL;
1430 vnet_api_error_t rv = vnet_lisp_stats_enable_disable (mp->is_en);
1431 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
1435 lisp_fid_addr_to_api (fid_address_t * fid, u8 * dst, u8 * api_eid_type,
1438 switch (fid_addr_type (fid))
1440 case FID_ADDR_IP_PREF:
1441 *prefix_length = fid_addr_prefix_length (fid);
1442 if (fid_addr_ip_version (fid) == IP4)
1444 *api_eid_type = 0; /* ipv4 type */
1445 clib_memcpy (dst, &fid_addr_ippref (fid), 4);
1449 *api_eid_type = 1; /* ipv6 type */
1450 clib_memcpy (dst, &fid_addr_ippref (fid), 16);
1454 *api_eid_type = 2; /* l2 mac type */
1455 mac_copy (dst, fid_addr_mac (fid));
1463 vl_api_one_stats_flush_t_handler (vl_api_one_stats_flush_t * mp)
1465 vl_api_one_stats_flush_reply_t *rmp;
1468 rv = vnet_lisp_flush_stats ();
1469 REPLY_MACRO (VL_API_ONE_STATS_FLUSH_REPLY);
1473 vl_api_one_stats_dump_t_handler (vl_api_one_stats_dump_t * mp)
1475 vl_api_one_stats_details_t *rmp;
1476 lisp_api_stats_t *stats, *stat;
1479 stats = vnet_lisp_get_stats ();
1480 vec_foreach (stat, stats)
1483 REPLY_DETAILS (VL_API_ONE_STATS_DETAILS,
1485 lisp_fid_addr_to_api (&stat->deid, rmp->deid, &rmp->eid_type,
1486 &rmp->deid_pref_len);
1487 lisp_fid_addr_to_api (&stat->seid, rmp->seid, &rmp->eid_type,
1488 &rmp->seid_pref_len);
1489 rmp->vni = clib_host_to_net_u32 (stat->vni);
1491 rmp->is_ip4 = ip_addr_version (&stat->rmt_rloc) == IP4 ? 1 : 0;
1492 ip_address_copy_addr (rmp->rloc, &stat->rmt_rloc);
1493 ip_address_copy_addr (rmp->lloc, &stat->loc_rloc);
1495 rmp->pkt_count = clib_host_to_net_u32 (stat->counters.packets);
1496 rmp->bytes = clib_host_to_net_u32 (stat->counters.bytes);
1503 vl_api_one_add_del_l2_arp_entry_t_handler
1504 (vl_api_one_add_del_l2_arp_entry_t * mp)
1506 vl_api_one_add_del_l2_arp_entry_reply_t *rmp;
1508 gid_address_t _arp, *arp = &_arp;
1509 memset (arp, 0, sizeof (*arp));
1511 gid_address_type (arp) = GID_ADDR_ARP;
1512 gid_address_arp_bd (arp) = clib_net_to_host_u32 (mp->bd);
1514 /* vpp keeps ip4 addresses in network byte order */
1515 clib_memcpy (&gid_address_arp_ip4 (arp), &mp->ip4, 4);
1517 rv = vnet_lisp_add_del_l2_arp_entry (arp, mp->mac, mp->is_add);
1519 REPLY_MACRO (VL_API_ONE_ADD_DEL_L2_ARP_ENTRY_REPLY);
1523 vl_api_one_l2_arp_bd_get_t_handler (vl_api_one_l2_arp_bd_get_t * mp)
1525 vl_api_one_l2_arp_bd_get_reply_t *rmp;
1530 u32 *bds = vnet_lisp_l2_arp_bds_get ();
1531 u32 size = hash_elts (bds) * sizeof (u32);
1534 REPLY_MACRO4 (VL_API_ONE_L2_ARP_BD_GET_REPLY, size,
1536 rmp->count = clib_host_to_net_u32 (hash_elts (bds));
1537 hash_foreach_pair (p, bds,
1539 rmp->bridge_domains[i++] = clib_host_to_net_u32 (p->key);
1548 vl_api_one_l2_arp_entries_get_t_handler (vl_api_one_l2_arp_entries_get_t * mp)
1550 vl_api_one_l2_arp_entries_get_reply_t *rmp;
1551 lisp_api_l2_arp_entry_t *entries = 0, *e;
1555 u32 bd = clib_net_to_host_u32 (mp->bd);
1557 entries = vnet_lisp_l2_arp_entries_get_by_bd (bd);
1558 u32 size = vec_len (entries) * sizeof (u32);
1561 REPLY_MACRO4 (VL_API_ONE_L2_ARP_ENTRIES_GET_REPLY, size,
1563 rmp->count = clib_host_to_net_u32 (vec_len (entries));
1564 vec_foreach (e, entries)
1566 mac_copy (rmp->entries[i].mac, e->mac);
1567 rmp->entries[i].ip4 = e->ip4;
1578 * Add vpe's API message handlers to the table.
1579 * vlib has alread mapped shared memory and
1580 * added the client registration handlers.
1581 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
1583 #define vl_msg_name_crc_list
1584 #include <vnet/vnet_all_api_h.h>
1585 #undef vl_msg_name_crc_list
1588 setup_message_id_table (api_main_t * am)
1590 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
1591 foreach_vl_msg_name_crc_one;
1595 static clib_error_t *
1596 one_api_hookup (vlib_main_t * vm)
1598 api_main_t *am = &api_main;
1601 vl_msg_api_set_handlers(VL_API_##N, #n, \
1602 vl_api_##n##_t_handler, \
1604 vl_api_##n##_t_endian, \
1605 vl_api_##n##_t_print, \
1606 sizeof(vl_api_##n##_t), 1);
1607 foreach_vpe_api_msg;
1611 * Set up the (msg_name, crc, message-id) table
1613 setup_message_id_table (am);
1618 VLIB_API_INIT_FUNCTION (one_api_hookup);
1621 * fd.io coding-style-patch-verification: ON
1624 * eval: (c-set-style "gnu")