2 *------------------------------------------------------------------
3 * lisp_api.c - lisp api
5 * Copyright (c) 2016 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_lisp_add_del_locator_set_t_endian vl_noop_handler
36 #define vl_api_lisp_add_del_locator_set_t_print vl_noop_handler
37 #define vl_api_lisp_add_del_remote_mapping_t_endian vl_noop_handler
38 #define vl_api_lisp_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 _(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set) \
63 _(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator) \
64 _(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid) \
65 _(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver) \
66 _(LISP_ADD_DEL_MAP_SERVER, lisp_add_del_map_server) \
67 _(LISP_ENABLE_DISABLE, lisp_enable_disable) \
68 _(LISP_RLOC_PROBE_ENABLE_DISABLE, lisp_rloc_probe_enable_disable) \
69 _(LISP_MAP_REGISTER_ENABLE_DISABLE, lisp_map_register_enable_disable) \
70 _(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping) \
71 _(LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency) \
72 _(LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set) \
73 _(LISP_MAP_REQUEST_MODE, lisp_map_request_mode) \
74 _(LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map) \
75 _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \
76 _(LISP_LOCATOR_DUMP, lisp_locator_dump) \
77 _(LISP_EID_TABLE_DUMP, lisp_eid_table_dump) \
78 _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump) \
79 _(LISP_MAP_SERVER_DUMP, lisp_map_server_dump) \
80 _(LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump) \
81 _(LISP_EID_TABLE_VNI_DUMP, lisp_eid_table_vni_dump) \
82 _(LISP_ADJACENCIES_GET, lisp_adjacencies_get) \
83 _(SHOW_LISP_RLOC_PROBE_STATE, show_lisp_rloc_probe_state) \
84 _(SHOW_LISP_MAP_REGISTER_STATE, show_lisp_map_register_state) \
85 _(SHOW_LISP_STATUS, show_lisp_status) \
86 _(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \
87 lisp_add_del_map_request_itr_rlocs) \
88 _(LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs) \
89 _(SHOW_LISP_PITR, show_lisp_pitr) \
90 _(SHOW_LISP_MAP_REQUEST_MODE, show_lisp_map_request_mode) \
91 _(LISP_USE_PETR, lisp_use_petr) \
92 _(SHOW_LISP_USE_PETR, show_lisp_use_petr) \
95 unformat_lisp_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_lisp_add_del_locator_set_t_handler (vl_api_lisp_add_del_locator_set_t *
120 vl_api_lisp_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 mp->locator_set_name[63] = 0;
132 locator_name = format (0, "%s", mp->locator_set_name);
133 vec_terminate_c_string (locator_name);
135 a->name = locator_name;
136 a->is_add = mp->is_add;
138 locator_num = clib_net_to_host_u32 (mp->locator_num);
140 memset (&locator, 0, sizeof (locator));
141 for (i = 0; i < locator_num; i++)
143 ls_loc = &mp->locators[i];
144 VALIDATE_SW_IF_INDEX (ls_loc);
146 locator.sw_if_index = htonl (ls_loc->sw_if_index);
147 locator.priority = ls_loc->priority;
148 locator.weight = ls_loc->weight;
150 vec_add1 (a->locators, locator);
153 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
155 BAD_SW_IF_INDEX_LABEL;
157 vec_free (locator_name);
158 vec_free (a->locators);
161 REPLY_MACRO2 (VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY,
163 rmp->ls_index = clib_host_to_net_u32 (ls_index);
169 vl_api_lisp_add_del_locator_t_handler (vl_api_lisp_add_del_locator_t * mp)
171 vl_api_lisp_add_del_locator_reply_t *rmp;
173 locator_t locator, *locators = NULL;
174 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
176 u8 *locator_name = NULL;
178 memset (&locator, 0, sizeof (locator));
179 memset (a, 0, sizeof (a[0]));
181 locator.sw_if_index = ntohl (mp->sw_if_index);
182 locator.priority = mp->priority;
183 locator.weight = mp->weight;
185 vec_add1 (locators, locator);
187 mp->locator_set_name[63] = 0;
188 locator_name = format (0, "%s", mp->locator_set_name);
189 vec_terminate_c_string (locator_name);
191 a->name = locator_name;
192 a->locators = locators;
193 a->is_add = mp->is_add;
196 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
199 vec_free (locator_name);
201 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
205 unformat_lisp_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
211 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
212 gid_address_ip_set (dst, src, IP4);
213 gid_address_ippref_len (dst) = len;
214 ip_prefix_normalize (&gid_address_ippref (dst));
217 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
218 gid_address_ip_set (dst, src, IP6);
219 gid_address_ippref_len (dst) = len;
220 ip_prefix_normalize (&gid_address_ippref (dst));
223 gid_address_type (dst) = GID_ADDR_MAC;
224 clib_memcpy (&gid_address_mac (dst), src, 6);
228 return VNET_API_ERROR_INVALID_VALUE;
231 gid_address_vni (dst) = vni;
237 vl_api_lisp_add_del_local_eid_t_handler (vl_api_lisp_add_del_local_eid_t * mp)
239 vl_api_lisp_add_del_local_eid_reply_t *rmp;
240 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
242 gid_address_t _eid, *eid = &_eid;
244 u32 locator_set_index = ~0, map_index = ~0;
245 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
246 u8 *name = NULL, *key = NULL;
247 memset (a, 0, sizeof (a[0]));
248 memset (eid, 0, sizeof (eid[0]));
250 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
251 mp->eid_type, mp->eid, mp->prefix_len);
255 mp->locator_set_name[63] = 0;
256 name = format (0, "%s", mp->locator_set_name);
257 vec_terminate_c_string (name);
258 p = hash_get_mem (lcm->locator_set_index_by_name, name);
261 rv = VNET_API_ERROR_INVALID_VALUE;
264 locator_set_index = p[0];
267 key = format (0, "%s", mp->key);
269 /* XXX treat batch configuration */
270 a->is_add = mp->is_add;
271 gid_address_copy (&a->eid, eid);
272 a->locator_set_index = locator_set_index;
275 a->key_id = clib_net_to_host_u16 (mp->key_id);
277 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
282 gid_address_free (&a->eid);
284 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
288 vl_api_lisp_eid_table_add_del_map_t_handler
289 (vl_api_lisp_eid_table_add_del_map_t * mp)
291 vl_api_lisp_eid_table_add_del_map_reply_t *rmp;
293 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
294 clib_net_to_host_u32 (mp->dp_table),
295 mp->is_l2, mp->is_add);
296 REPLY_MACRO (VL_API_LISP_EID_TABLE_ADD_DEL_MAP_REPLY)}
299 vl_api_lisp_add_del_map_server_t_handler (vl_api_lisp_add_del_map_server_t
302 vl_api_lisp_add_del_map_server_reply_t *rmp;
306 memset (&addr, 0, sizeof (addr));
308 ip_address_set (&addr, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
309 rv = vnet_lisp_add_del_map_server (&addr, mp->is_add);
311 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_SERVER_REPLY);
315 vl_api_lisp_add_del_map_resolver_t_handler (vl_api_lisp_add_del_map_resolver_t
318 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
320 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
322 memset (a, 0, sizeof (a[0]));
324 a->is_add = mp->is_add;
325 ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
327 rv = vnet_lisp_add_del_map_resolver (a);
329 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
333 vl_api_lisp_map_register_enable_disable_t_handler
334 (vl_api_lisp_map_register_enable_disable_t * mp)
336 vl_api_lisp_map_register_enable_disable_reply_t *rmp;
339 vnet_lisp_map_register_enable_disable (mp->is_enabled);
340 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
344 vl_api_lisp_rloc_probe_enable_disable_t_handler
345 (vl_api_lisp_rloc_probe_enable_disable_t * mp)
347 vl_api_lisp_rloc_probe_enable_disable_reply_t *rmp;
350 vnet_lisp_rloc_probe_enable_disable (mp->is_enabled);
351 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
355 vl_api_lisp_enable_disable_t_handler (vl_api_lisp_enable_disable_t * mp)
357 vl_api_lisp_enable_disable_reply_t *rmp;
360 vnet_lisp_enable_disable (mp->is_en);
361 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
365 vl_api_show_lisp_map_request_mode_t_handler
366 (vl_api_show_lisp_map_request_mode_t * mp)
369 vl_api_show_lisp_map_request_mode_reply_t *rmp;
372 REPLY_MACRO2(VL_API_SHOW_LISP_MAP_REQUEST_MODE_REPLY,
374 rmp->mode = vnet_lisp_get_map_request_mode ();
380 vl_api_lisp_map_request_mode_t_handler (vl_api_lisp_map_request_mode_t * mp)
382 vl_api_lisp_map_request_mode_reply_t *rmp;
385 rv = vnet_lisp_set_map_request_mode (mp->mode);
387 REPLY_MACRO (VL_API_LISP_MAP_REQUEST_MODE_REPLY);
391 vl_api_lisp_pitr_set_locator_set_t_handler (vl_api_lisp_pitr_set_locator_set_t
394 vl_api_lisp_pitr_set_locator_set_reply_t *rmp;
398 ls_name = format (0, "%s", mp->ls_name);
399 vec_terminate_c_string (ls_name);
400 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
403 REPLY_MACRO (VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY);
407 vl_api_lisp_use_petr_t_handler (vl_api_lisp_use_petr_t * mp)
409 vl_api_lisp_use_petr_reply_t *rmp;
413 ip_address_set (&addr, &mp->address, mp->is_ip4 ? IP4 : IP6);
414 rv = vnet_lisp_use_petr (&addr, mp->is_add);
416 REPLY_MACRO (VL_API_LISP_USE_PETR_REPLY);
420 vl_api_show_lisp_use_petr_t_handler (vl_api_show_lisp_use_petr_t * mp)
422 unix_shared_memory_queue_t *q = NULL;
423 vl_api_show_lisp_use_petr_reply_t *rmp = NULL;
424 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
426 locator_set_t *ls = 0;
432 q = vl_api_client_index_to_input_queue (mp->client_index);
438 memset (&addr, 0, sizeof (addr));
439 status = lcm->flags & LISP_FLAG_USE_PETR;
442 m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index);
443 if (~0 != m->locator_set_index)
446 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
447 loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]);
448 gid_address_copy (&addr, &loc->address);
453 REPLY_MACRO2 (VL_API_SHOW_LISP_USE_PETR_REPLY,
455 rmp->status = status;
456 ip_address_t *ip = &gid_address_ip (&addr);
457 switch (ip_addr_version (ip))
460 clib_memcpy (rmp->address, &ip_addr_v4 (ip),
461 sizeof (ip_addr_v4 (ip)));
465 clib_memcpy (rmp->address, &ip_addr_v6 (ip),
466 sizeof (ip_addr_v6 (ip)));
472 rmp->is_ip4 = (gid_address_ip_version (&addr) == IP4);
478 vl_api_lisp_add_del_map_request_itr_rlocs_t_handler
479 (vl_api_lisp_add_del_map_request_itr_rlocs_t * mp)
481 vl_api_lisp_add_del_map_request_itr_rlocs_reply_t *rmp;
483 u8 *locator_set_name = NULL;
484 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
486 mp->locator_set_name[63] = 0;
487 locator_set_name = format (0, "%s", mp->locator_set_name);
488 vec_terminate_c_string (locator_set_name);
490 a->is_add = mp->is_add;
491 a->locator_set_name = locator_set_name;
493 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
495 vec_free (locator_set_name);
497 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
501 vl_api_lisp_add_del_remote_mapping_t_handler
502 (vl_api_lisp_add_del_remote_mapping_t * mp)
504 locator_t *rlocs = 0;
505 vl_api_lisp_add_del_remote_mapping_reply_t *rmp;
507 gid_address_t _eid, *eid = &_eid;
508 u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
510 memset (eid, 0, sizeof (eid[0]));
512 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
513 mp->eid_type, mp->eid, mp->eid_len);
517 rlocs = unformat_lisp_locs (mp->rlocs, rloc_num);
521 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
522 memset (a, 0, sizeof (*a));
523 gid_address_copy (&a->reid, eid);
525 rv = vnet_lisp_add_del_adjacency (a);
532 /* NOTE: for now this works as a static remote mapping, i.e.,
533 * not authoritative and ttl infinite. */
536 vnet_lisp_add_del_mapping_args_t _m_args, *m_args = &_m_args;
537 memset (m_args, 0, sizeof (m_args[0]));
538 gid_address_copy (&m_args->eid, eid);
539 m_args->action = mp->action;
540 m_args->is_static = 1;
542 m_args->authoritative = 0;
543 rv = vnet_lisp_add_mapping (m_args, rlocs, NULL, NULL);
547 rv = vnet_lisp_del_mapping (eid, NULL);
551 vnet_lisp_clear_all_remote_adjacencies ();
556 REPLY_MACRO (VL_API_LISP_ADD_DEL_REMOTE_MAPPING_REPLY);
560 vl_api_lisp_add_del_adjacency_t_handler (vl_api_lisp_add_del_adjacency_t * mp)
562 vl_api_lisp_add_del_adjacency_reply_t *rmp;
563 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
566 memset (a, 0, sizeof (a[0]));
568 rv = unformat_lisp_eid_api (&a->leid, clib_net_to_host_u32 (mp->vni),
569 mp->eid_type, mp->leid, mp->leid_len);
570 rv |= unformat_lisp_eid_api (&a->reid, clib_net_to_host_u32 (mp->vni),
571 mp->eid_type, mp->reid, mp->reid_len);
576 a->is_add = mp->is_add;
577 rv = vnet_lisp_add_del_adjacency (a);
580 REPLY_MACRO (VL_API_LISP_ADD_DEL_ADJACENCY_REPLY);
584 send_lisp_locator_details (lisp_cp_main_t * lcm,
586 unix_shared_memory_queue_t * q, u32 context)
588 vl_api_lisp_locator_details_t *rmp;
590 rmp = vl_msg_api_alloc (sizeof (*rmp));
591 memset (rmp, 0, sizeof (*rmp));
592 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_DETAILS);
593 rmp->context = context;
595 rmp->local = loc->local;
598 rmp->sw_if_index = ntohl (loc->sw_if_index);
602 rmp->is_ipv6 = gid_address_ip_version (&loc->address);
603 ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
605 rmp->priority = loc->priority;
606 rmp->weight = loc->weight;
608 vl_msg_api_send_shmem (q, (u8 *) & rmp);
612 vl_api_lisp_locator_dump_t_handler (vl_api_lisp_locator_dump_t * mp)
615 unix_shared_memory_queue_t *q = 0;
616 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
617 locator_set_t *lsit = 0;
619 u32 ls_index = ~0, *locit = 0;
622 q = vl_api_client_index_to_input_queue (mp->client_index);
628 if (mp->is_index_set)
629 ls_index = htonl (mp->ls_index);
632 /* make sure we get a proper C-string */
633 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
634 ls_name = format (0, "%s", mp->ls_name);
635 vec_terminate_c_string (ls_name);
636 p = hash_get_mem (lcm->locator_set_index_by_name, ls_name);
642 if (pool_is_free_index (lcm->locator_set_pool, ls_index))
645 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
647 vec_foreach (locit, lsit->locator_indices)
649 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
650 send_lisp_locator_details (lcm, loc, q, mp->context);
657 send_lisp_locator_set_details (lisp_cp_main_t * lcm,
658 locator_set_t * lsit,
659 unix_shared_memory_queue_t * q,
660 u32 context, u32 ls_index)
662 vl_api_lisp_locator_set_details_t *rmp;
665 rmp = vl_msg_api_alloc (sizeof (*rmp));
666 memset (rmp, 0, sizeof (*rmp));
667 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_SET_DETAILS);
668 rmp->context = context;
670 rmp->ls_index = htonl (ls_index);
673 ASSERT (lsit->name != NULL);
674 strncpy ((char *) rmp->ls_name, (char *) lsit->name,
675 vec_len (lsit->name));
679 str = format (0, "<remote-%d>", ls_index);
680 strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str));
684 vl_msg_api_send_shmem (q, (u8 *) & rmp);
688 vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t * mp)
690 unix_shared_memory_queue_t *q = NULL;
691 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
692 locator_set_t *lsit = NULL;
695 q = vl_api_client_index_to_input_queue (mp->client_index);
703 pool_foreach (lsit, lcm->locator_set_pool,
705 if (filter && !((1 == filter && lsit->local) ||
706 (2 == filter && !lsit->local)))
710 send_lisp_locator_set_details (lcm, lsit, q, mp->context,
711 lsit - lcm->locator_set_pool);
717 lisp_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length)
719 ASSERT (prefix_length);
720 ip_prefix_t *ippref = &fid_addr_ippref (src);
722 switch (fid_addr_type (src))
724 case FID_ADDR_IP_PREF:
725 if (ip_prefix_version (ippref) == IP4)
726 clib_memcpy (dst, &ip_prefix_v4 (ippref), 4);
728 clib_memcpy (dst, &ip_prefix_v6 (ippref), 16);
729 prefix_length[0] = ip_prefix_len (ippref);
733 prefix_length[0] = 0;
734 clib_memcpy (dst, fid_addr_mac (src), 6);
738 clib_warning ("Unknown FID type %d!", fid_addr_type (src));
744 fid_type_to_api_type (fid_address_t * fid)
748 switch (fid_addr_type (fid))
750 case FID_ADDR_IP_PREF:
751 ippref = &fid_addr_ippref (fid);
752 if (ip_prefix_version (ippref) == IP4)
754 else if (ip_prefix_version (ippref) == IP6)
769 send_lisp_eid_table_details (mapping_t * mapit,
770 unix_shared_memory_queue_t * q,
771 u32 context, u8 filter)
774 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
775 locator_set_t *ls = 0;
776 vl_api_lisp_eid_table_details_t *rmp = NULL;
777 gid_address_t *gid = NULL;
779 ip_prefix_t *ip_prefix = NULL;
783 case 0: /* all mappings */
786 case 1: /* local only */
790 case 2: /* remote only */
795 clib_warning ("Filter error, unknown filter: %d", filter);
799 /* don't send PITR generated mapping */
804 ip_prefix = &gid_address_ippref (gid);
805 mac = gid_address_mac (gid);
807 rmp = vl_msg_api_alloc (sizeof (*rmp));
808 memset (rmp, 0, sizeof (*rmp));
809 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_DETAILS);
811 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
812 if (vec_len (ls->locator_indices) == 0)
813 rmp->locator_set_index = ~0;
815 rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
817 rmp->is_local = mapit->local;
818 rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
819 rmp->action = mapit->action;
820 rmp->authoritative = mapit->authoritative;
822 switch (gid_address_type (gid))
824 case GID_ADDR_SRC_DST:
826 fid = &gid_address_sd_src (gid);
827 rmp->eid_type = fid_type_to_api_type (fid);
828 lisp_fid_put_api (rmp->seid, &gid_address_sd_src (gid),
829 &rmp->seid_prefix_len);
830 lisp_fid_put_api (rmp->eid, &gid_address_sd_dst (gid),
831 &rmp->eid_prefix_len);
833 case GID_ADDR_IP_PREFIX:
834 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
835 if (ip_prefix_version (ip_prefix) == IP4)
837 rmp->eid_type = 0; /* ipv4 type */
838 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
839 sizeof (ip_prefix_v4 (ip_prefix)));
843 rmp->eid_type = 1; /* ipv6 type */
844 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
845 sizeof (ip_prefix_v6 (ip_prefix)));
849 rmp->eid_type = 2; /* l2 mac type */
850 clib_memcpy (rmp->eid, mac, 6);
855 rmp->context = context;
856 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
857 rmp->key_id = clib_host_to_net_u16 (mapit->key_id);
858 memcpy (rmp->key, mapit->key, vec_len (mapit->key));
859 vl_msg_api_send_shmem (q, (u8 *) & rmp);
863 vl_api_lisp_eid_table_dump_t_handler (vl_api_lisp_eid_table_dump_t * mp)
866 unix_shared_memory_queue_t *q = NULL;
867 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
868 mapping_t *mapit = NULL;
869 gid_address_t _eid, *eid = &_eid;
871 q = vl_api_client_index_to_input_queue (mp->client_index);
879 memset (eid, 0, sizeof (*eid));
881 unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
882 mp->eid_type, mp->eid, mp->prefix_length);
884 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
888 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
889 send_lisp_eid_table_details (mapit, q, mp->context,
890 0 /* ignore filter */ );
895 pool_foreach (mapit, lcm->mapping_pool,
897 send_lisp_eid_table_details(mapit, q, mp->context,
905 send_lisp_map_server_details (ip_address_t * ip,
906 unix_shared_memory_queue_t * q, u32 context)
908 vl_api_lisp_map_server_details_t *rmp = NULL;
910 rmp = vl_msg_api_alloc (sizeof (*rmp));
911 memset (rmp, 0, sizeof (*rmp));
912 rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_SERVER_DETAILS);
914 switch (ip_addr_version (ip))
918 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
919 sizeof (ip_addr_v4 (ip)));
924 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
925 sizeof (ip_addr_v6 (ip)));
931 rmp->context = context;
933 vl_msg_api_send_shmem (q, (u8 *) & rmp);
937 vl_api_lisp_map_server_dump_t_handler (vl_api_lisp_map_server_dump_t * mp)
939 unix_shared_memory_queue_t *q = NULL;
940 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
943 q = vl_api_client_index_to_input_queue (mp->client_index);
949 vec_foreach (mr, lcm->map_servers)
951 send_lisp_map_server_details (&mr->address, q, mp->context);
956 send_lisp_map_resolver_details (ip_address_t * ip,
957 unix_shared_memory_queue_t * q, u32 context)
959 vl_api_lisp_map_resolver_details_t *rmp = NULL;
961 rmp = vl_msg_api_alloc (sizeof (*rmp));
962 memset (rmp, 0, sizeof (*rmp));
963 rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_RESOLVER_DETAILS);
965 switch (ip_addr_version (ip))
969 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
970 sizeof (ip_addr_v4 (ip)));
975 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
976 sizeof (ip_addr_v6 (ip)));
982 rmp->context = context;
984 vl_msg_api_send_shmem (q, (u8 *) & rmp);
988 vl_api_lisp_map_resolver_dump_t_handler (vl_api_lisp_map_resolver_dump_t * mp)
990 unix_shared_memory_queue_t *q = NULL;
991 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
994 q = vl_api_client_index_to_input_queue (mp->client_index);
1000 vec_foreach (mr, lcm->map_resolvers)
1002 send_lisp_map_resolver_details (&mr->address, q, mp->context);
1007 send_eid_table_map_pair (hash_pair_t * p,
1008 unix_shared_memory_queue_t * q, u32 context)
1010 vl_api_lisp_eid_table_map_details_t *rmp = NULL;
1012 rmp = vl_msg_api_alloc (sizeof (*rmp));
1013 memset (rmp, 0, sizeof (*rmp));
1014 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_MAP_DETAILS);
1016 rmp->vni = clib_host_to_net_u32 (p->key);
1017 rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
1018 rmp->context = context;
1019 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1023 vl_api_lisp_eid_table_map_dump_t_handler (vl_api_lisp_eid_table_map_dump_t *
1026 unix_shared_memory_queue_t *q = NULL;
1027 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1029 uword *vni_table = 0;
1031 q = vl_api_client_index_to_input_queue (mp->client_index);
1039 vni_table = lcm->bd_id_by_vni;
1043 vni_table = lcm->table_id_by_vni;
1047 hash_foreach_pair (p, vni_table,
1049 send_eid_table_map_pair (p, q, mp->context);
1055 send_eid_table_vni (u32 vni, unix_shared_memory_queue_t * q, u32 context)
1057 vl_api_lisp_eid_table_vni_details_t *rmp = 0;
1059 rmp = vl_msg_api_alloc (sizeof (*rmp));
1060 memset (rmp, 0, sizeof (*rmp));
1061 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_VNI_DETAILS);
1062 rmp->context = context;
1063 rmp->vni = clib_host_to_net_u32 (vni);
1064 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1068 lisp_adjacency_copy (vl_api_lisp_adjacency_t * dst, lisp_adjacency_t * adjs)
1070 lisp_adjacency_t *adj;
1071 vl_api_lisp_adjacency_t a;
1072 u32 i, n = vec_len (adjs);
1074 for (i = 0; i < n; i++)
1076 adj = vec_elt_at_index (adjs, i);
1077 memset (&a, 0, sizeof (a));
1079 switch (gid_address_type (&adj->reid))
1081 case GID_ADDR_IP_PREFIX:
1082 a.reid_prefix_len = gid_address_ippref_len (&adj->reid);
1083 a.leid_prefix_len = gid_address_ippref_len (&adj->leid);
1084 if (gid_address_ip_version (&adj->reid) == IP4)
1086 a.eid_type = 0; /* ipv4 type */
1087 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 4);
1088 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 4);
1092 a.eid_type = 1; /* ipv6 type */
1093 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 16);
1094 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 16);
1098 a.eid_type = 2; /* l2 mac type */
1099 mac_copy (a.reid, gid_address_mac (&adj->reid));
1100 mac_copy (a.leid, gid_address_mac (&adj->leid));
1110 vl_api_show_lisp_rloc_probe_state_t_handler
1111 (vl_api_show_lisp_rloc_probe_state_t * mp)
1113 vl_api_show_lisp_rloc_probe_state_reply_t *rmp = 0;
1117 REPLY_MACRO2 (VL_API_SHOW_LISP_RLOC_PROBE_STATE_REPLY,
1119 rmp->is_enabled = vnet_lisp_rloc_probe_state_get ();
1125 vl_api_show_lisp_map_register_state_t_handler
1126 (vl_api_show_lisp_map_register_state_t * mp)
1128 vl_api_show_lisp_map_register_state_reply_t *rmp = 0;
1132 REPLY_MACRO2 (VL_API_SHOW_LISP_MAP_REGISTER_STATE_REPLY,
1134 rmp->is_enabled = vnet_lisp_map_register_state_get ();
1140 vl_api_lisp_adjacencies_get_t_handler (vl_api_lisp_adjacencies_get_t * mp)
1142 vl_api_lisp_adjacencies_get_reply_t *rmp = 0;
1143 lisp_adjacency_t *adjs = 0;
1146 u32 vni = clib_net_to_host_u32 (mp->vni);
1148 adjs = vnet_lisp_adjacencies_get_by_vni (vni);
1149 size = vec_len (adjs) * sizeof (vl_api_lisp_adjacency_t);
1152 REPLY_MACRO4 (VL_API_LISP_ADJACENCIES_GET_REPLY, size,
1154 rmp->count = clib_host_to_net_u32 (vec_len (adjs));
1155 lisp_adjacency_copy (rmp->adjacencies, adjs);
1163 vl_api_lisp_eid_table_vni_dump_t_handler (vl_api_lisp_eid_table_vni_dump_t *
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_lisp_status_t_handler (vl_api_show_lisp_status_t * mp)
1200 unix_shared_memory_queue_t *q = NULL;
1201 vl_api_show_lisp_status_reply_t *rmp = NULL;
1204 q = vl_api_client_index_to_input_queue (mp->client_index);
1211 REPLY_MACRO2(VL_API_SHOW_LISP_STATUS_REPLY,
1213 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
1214 rmp->feature_status = vnet_lisp_enable_disable_status ();
1220 vl_api_lisp_get_map_request_itr_rlocs_t_handler
1221 (vl_api_lisp_get_map_request_itr_rlocs_t * mp)
1223 unix_shared_memory_queue_t *q = NULL;
1224 vl_api_lisp_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_LISP_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_lisp_pitr_t_handler (vl_api_show_lisp_pitr_t * mp)
1261 unix_shared_memory_queue_t *q = NULL;
1262 vl_api_show_lisp_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_LISP_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);
1307 * Add vpe's API message handlers to the table.
1308 * vlib has alread mapped shared memory and
1309 * added the client registration handlers.
1310 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
1312 #define vl_msg_name_crc_list
1313 #include <vnet/vnet_all_api_h.h>
1314 #undef vl_msg_name_crc_list
1317 setup_message_id_table (api_main_t * am)
1319 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
1320 foreach_vl_msg_name_crc_lisp;
1324 static clib_error_t *
1325 lisp_api_hookup (vlib_main_t * vm)
1327 api_main_t *am = &api_main;
1330 vl_msg_api_set_handlers(VL_API_##N, #n, \
1331 vl_api_##n##_t_handler, \
1333 vl_api_##n##_t_endian, \
1334 vl_api_##n##_t_print, \
1335 sizeof(vl_api_##n##_t), 1);
1336 foreach_vpe_api_msg;
1340 * Set up the (msg_name, crc, message-id) table
1342 setup_message_id_table (am);
1347 VLIB_API_INIT_FUNCTION (lisp_api_hookup);
1350 * fd.io coding-style-patch-verification: ON
1353 * eval: (c-set-style "gnu")