blob: 3053611c61171d3ffad7bb7a90ec893bef737ccb [file] [log] [blame]
Pavel Kotucekcfb7be82016-12-21 14:15:37 +01001/*
2 *------------------------------------------------------------------
3 * lisp_api.c - lisp api
4 *
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:
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
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 *------------------------------------------------------------------
18 */
19
20#include <vnet/vnet.h>
21#include <vlibmemory/api.h>
22
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>
27
28#include <vnet/vnet_msg_enum.h>
29
Filip Tehlar05a057b2017-02-01 08:50:31 +010030#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
34
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
39
Filip Tehlar694396d2017-02-17 14:29:11 +010040#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
44
Pavel Kotucekcfb7be82016-12-21 14:15:37 +010045#define vl_typedefs /* define message structures */
46#include <vnet/vnet_all_api_h.h>
47#undef vl_typedefs
48
49#define vl_endianfun /* define message structures */
50#include <vnet/vnet_all_api_h.h>
51#undef vl_endianfun
52
53/* instantiate all the print functions we know about */
54#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
55#define vl_printfun
56#include <vnet/vnet_all_api_h.h>
57#undef vl_printfun
58
59#include <vlibapi/api_helper_macros.h>
60
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) \
Florin Corasba888e42017-01-24 11:38:18 -080091_(LISP_USE_PETR, lisp_use_petr) \
92_(SHOW_LISP_USE_PETR, show_lisp_use_petr) \
Pavel Kotucekcfb7be82016-12-21 14:15:37 +010093
Pavel Kotucekcfb7be82016-12-21 14:15:37 +010094static locator_t *
Filip Tehlar05a057b2017-02-01 08:50:31 +010095unformat_lisp_locs (vl_api_remote_locator_t * rmt_locs, u32 rloc_num)
Pavel Kotucekcfb7be82016-12-21 14:15:37 +010096{
97 u32 i;
98 locator_t *locs = 0, loc;
Filip Tehlar05a057b2017-02-01 08:50:31 +010099 vl_api_remote_locator_t *r;
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100100
101 for (i = 0; i < rloc_num; i++)
102 {
103 /* remote locators */
Filip Tehlar05a057b2017-02-01 08:50:31 +0100104 r = &rmt_locs[i];
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100105 memset (&loc, 0, sizeof (loc));
106 gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
107
108 loc.priority = r->priority;
109 loc.weight = r->weight;
110
111 vec_add1 (locs, loc);
112 }
113 return locs;
114}
115
116static void
117vl_api_lisp_add_del_locator_set_t_handler (vl_api_lisp_add_del_locator_set_t *
118 mp)
119{
120 vl_api_lisp_add_del_locator_set_reply_t *rmp;
121 int rv = 0;
122 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
123 locator_t locator;
Filip Tehlar05a057b2017-02-01 08:50:31 +0100124 vl_api_local_locator_t *ls_loc;
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100125 u32 ls_index = ~0, locator_num;
126 u8 *locator_name = NULL;
127 int i;
128
129 memset (a, 0, sizeof (a[0]));
130
Dave Barach59b25652017-09-10 15:04:27 -0400131 mp->locator_set_name[63] = 0;
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100132 locator_name = format (0, "%s", mp->locator_set_name);
133
134 a->name = locator_name;
135 a->is_add = mp->is_add;
136 a->local = 1;
137 locator_num = clib_net_to_host_u32 (mp->locator_num);
138
139 memset (&locator, 0, sizeof (locator));
140 for (i = 0; i < locator_num; i++)
141 {
Filip Tehlar05a057b2017-02-01 08:50:31 +0100142 ls_loc = &mp->locators[i];
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100143 VALIDATE_SW_IF_INDEX (ls_loc);
144
145 locator.sw_if_index = htonl (ls_loc->sw_if_index);
146 locator.priority = ls_loc->priority;
147 locator.weight = ls_loc->weight;
148 locator.local = 1;
149 vec_add1 (a->locators, locator);
150 }
151
152 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
153
154 BAD_SW_IF_INDEX_LABEL;
155
156 vec_free (locator_name);
157 vec_free (a->locators);
158
159 /* *INDENT-OFF* */
160 REPLY_MACRO2 (VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY,
161 ({
162 rmp->ls_index = clib_host_to_net_u32 (ls_index);
163 }));
164 /* *INDENT-ON* */
165}
166
167static void
168vl_api_lisp_add_del_locator_t_handler (vl_api_lisp_add_del_locator_t * mp)
169{
170 vl_api_lisp_add_del_locator_reply_t *rmp;
171 int rv = 0;
172 locator_t locator, *locators = NULL;
173 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
174 u32 ls_index = ~0;
175 u8 *locator_name = NULL;
176
177 memset (&locator, 0, sizeof (locator));
178 memset (a, 0, sizeof (a[0]));
179
180 locator.sw_if_index = ntohl (mp->sw_if_index);
181 locator.priority = mp->priority;
182 locator.weight = mp->weight;
183 locator.local = 1;
184 vec_add1 (locators, locator);
185
Dave Barach59b25652017-09-10 15:04:27 -0400186 mp->locator_set_name[63] = 0;
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100187 locator_name = format (0, "%s", mp->locator_set_name);
188
189 a->name = locator_name;
190 a->locators = locators;
191 a->is_add = mp->is_add;
192 a->local = 1;
193
194 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
195
196 vec_free (locators);
197 vec_free (locator_name);
198
199 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
200}
201
202static int
203unformat_lisp_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
204 u8 len)
205{
206 switch (type)
207 {
208 case 0: /* ipv4 */
209 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
210 gid_address_ip_set (dst, src, IP4);
211 gid_address_ippref_len (dst) = len;
212 ip_prefix_normalize (&gid_address_ippref (dst));
213 break;
214 case 1: /* ipv6 */
215 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
216 gid_address_ip_set (dst, src, IP6);
217 gid_address_ippref_len (dst) = len;
218 ip_prefix_normalize (&gid_address_ippref (dst));
219 break;
220 case 2: /* l2 mac */
221 gid_address_type (dst) = GID_ADDR_MAC;
222 clib_memcpy (&gid_address_mac (dst), src, 6);
223 break;
224 default:
225 /* unknown type */
226 return VNET_API_ERROR_INVALID_VALUE;
227 }
228
229 gid_address_vni (dst) = vni;
230
231 return 0;
232}
233
234static void
235vl_api_lisp_add_del_local_eid_t_handler (vl_api_lisp_add_del_local_eid_t * mp)
236{
237 vl_api_lisp_add_del_local_eid_reply_t *rmp;
238 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
239 int rv = 0;
240 gid_address_t _eid, *eid = &_eid;
241 uword *p = NULL;
242 u32 locator_set_index = ~0, map_index = ~0;
243 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
244 u8 *name = NULL, *key = NULL;
245 memset (a, 0, sizeof (a[0]));
246 memset (eid, 0, sizeof (eid[0]));
247
248 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
249 mp->eid_type, mp->eid, mp->prefix_len);
250 if (rv)
251 goto out;
252
Dave Barach59b25652017-09-10 15:04:27 -0400253 mp->locator_set_name[63] = 0;
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100254 name = format (0, "%s", mp->locator_set_name);
255 p = hash_get_mem (lcm->locator_set_index_by_name, name);
256 if (!p)
257 {
258 rv = VNET_API_ERROR_INVALID_VALUE;
259 goto out;
260 }
261 locator_set_index = p[0];
262
263 if (*mp->key)
264 key = format (0, "%s", mp->key);
265
266 /* XXX treat batch configuration */
267 a->is_add = mp->is_add;
268 gid_address_copy (&a->eid, eid);
269 a->locator_set_index = locator_set_index;
270 a->local = 1;
271 a->key = key;
272 a->key_id = clib_net_to_host_u16 (mp->key_id);
273
274 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
275
276out:
277 vec_free (name);
278 vec_free (key);
279 gid_address_free (&a->eid);
280
281 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
282}
283
284static void
285 vl_api_lisp_eid_table_add_del_map_t_handler
286 (vl_api_lisp_eid_table_add_del_map_t * mp)
287{
288 vl_api_lisp_eid_table_add_del_map_reply_t *rmp;
289 int rv = 0;
290 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
291 clib_net_to_host_u32 (mp->dp_table),
292 mp->is_l2, mp->is_add);
293REPLY_MACRO (VL_API_LISP_EID_TABLE_ADD_DEL_MAP_REPLY)}
294
295static void
296vl_api_lisp_add_del_map_server_t_handler (vl_api_lisp_add_del_map_server_t
297 * mp)
298{
299 vl_api_lisp_add_del_map_server_reply_t *rmp;
300 int rv = 0;
301 ip_address_t addr;
302
303 memset (&addr, 0, sizeof (addr));
304
305 ip_address_set (&addr, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
306 rv = vnet_lisp_add_del_map_server (&addr, mp->is_add);
307
308 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_SERVER_REPLY);
309}
310
311static void
312vl_api_lisp_add_del_map_resolver_t_handler (vl_api_lisp_add_del_map_resolver_t
313 * mp)
314{
315 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
316 int rv = 0;
317 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
318
319 memset (a, 0, sizeof (a[0]));
320
321 a->is_add = mp->is_add;
322 ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
323
324 rv = vnet_lisp_add_del_map_resolver (a);
325
326 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
327}
328
329static void
330 vl_api_lisp_map_register_enable_disable_t_handler
331 (vl_api_lisp_map_register_enable_disable_t * mp)
332{
333 vl_api_lisp_map_register_enable_disable_reply_t *rmp;
334 int rv = 0;
335
336 vnet_lisp_map_register_enable_disable (mp->is_enabled);
337 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
338}
339
340static void
341 vl_api_lisp_rloc_probe_enable_disable_t_handler
342 (vl_api_lisp_rloc_probe_enable_disable_t * mp)
343{
344 vl_api_lisp_rloc_probe_enable_disable_reply_t *rmp;
345 int rv = 0;
346
347 vnet_lisp_rloc_probe_enable_disable (mp->is_enabled);
348 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
349}
350
351static void
352vl_api_lisp_enable_disable_t_handler (vl_api_lisp_enable_disable_t * mp)
353{
354 vl_api_lisp_enable_disable_reply_t *rmp;
355 int rv = 0;
356
357 vnet_lisp_enable_disable (mp->is_en);
358 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
359}
360
361static void
362 vl_api_show_lisp_map_request_mode_t_handler
363 (vl_api_show_lisp_map_request_mode_t * mp)
364{
365 int rv = 0;
366 vl_api_show_lisp_map_request_mode_reply_t *rmp;
367
368 /* *INDENT-OFF* */
369 REPLY_MACRO2(VL_API_SHOW_LISP_MAP_REQUEST_MODE_REPLY,
370 ({
371 rmp->mode = vnet_lisp_get_map_request_mode ();
372 }));
373 /* *INDENT-ON* */
374}
375
376static void
377vl_api_lisp_map_request_mode_t_handler (vl_api_lisp_map_request_mode_t * mp)
378{
379 vl_api_lisp_map_request_mode_reply_t *rmp;
380 int rv = 0;
381
382 rv = vnet_lisp_set_map_request_mode (mp->mode);
383
384 REPLY_MACRO (VL_API_LISP_MAP_REQUEST_MODE_REPLY);
385}
386
387static void
388vl_api_lisp_pitr_set_locator_set_t_handler (vl_api_lisp_pitr_set_locator_set_t
389 * mp)
390{
391 vl_api_lisp_pitr_set_locator_set_reply_t *rmp;
392 int rv = 0;
393 u8 *ls_name = 0;
394
395 ls_name = format (0, "%s", mp->ls_name);
396 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
397 vec_free (ls_name);
398
399 REPLY_MACRO (VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY);
400}
401
402static void
Florin Corasba888e42017-01-24 11:38:18 -0800403vl_api_lisp_use_petr_t_handler (vl_api_lisp_use_petr_t * mp)
404{
405 vl_api_lisp_use_petr_reply_t *rmp;
406 int rv = 0;
407 ip_address_t addr;
408
409 ip_address_set (&addr, &mp->address, mp->is_ip4 ? IP4 : IP6);
410 rv = vnet_lisp_use_petr (&addr, mp->is_add);
411
412 REPLY_MACRO (VL_API_LISP_USE_PETR_REPLY);
413}
414
415static void
416vl_api_show_lisp_use_petr_t_handler (vl_api_show_lisp_use_petr_t * mp)
417{
418 unix_shared_memory_queue_t *q = NULL;
419 vl_api_show_lisp_use_petr_reply_t *rmp = NULL;
420 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
421 mapping_t *m;
422 locator_set_t *ls = 0;
423 int rv = 0;
Florin Coras2743cc42017-01-29 16:42:20 -0800424 locator_t *loc = 0;
425 u8 status = 0;
426 gid_address_t addr;
Florin Corasba888e42017-01-24 11:38:18 -0800427
428 q = vl_api_client_index_to_input_queue (mp->client_index);
429 if (q == 0)
430 {
431 return;
432 }
433
Florin Coras2743cc42017-01-29 16:42:20 -0800434 memset (&addr, 0, sizeof (addr));
435 status = lcm->flags & LISP_FLAG_USE_PETR;
436 if (status)
Florin Corasba888e42017-01-24 11:38:18 -0800437 {
438 m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index);
439 if (~0 != m->locator_set_index)
440 {
441 ls =
442 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
443 loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]);
Florin Coras2743cc42017-01-29 16:42:20 -0800444 gid_address_copy (&addr, &loc->address);
Florin Corasba888e42017-01-24 11:38:18 -0800445 }
446 }
447
Florin Coras2743cc42017-01-29 16:42:20 -0800448 /* *INDENT-OFF* */
449 REPLY_MACRO2 (VL_API_SHOW_LISP_USE_PETR_REPLY,
450 {
Filip Tehlar67a99f82017-03-10 13:18:02 +0100451 rmp->status = status;
452 ip_address_t *ip = &gid_address_ip (&addr);
453 switch (ip_addr_version (ip))
454 {
455 case IP4:
456 clib_memcpy (rmp->address, &ip_addr_v4 (ip),
457 sizeof (ip_addr_v4 (ip)));
458 break;
459
460 case IP6:
461 clib_memcpy (rmp->address, &ip_addr_v6 (ip),
462 sizeof (ip_addr_v6 (ip)));
463 break;
464
465 default:
466 ASSERT (0);
467 }
468 rmp->is_ip4 = (gid_address_ip_version (&addr) == IP4);
Florin Coras2743cc42017-01-29 16:42:20 -0800469 });
470 /* *INDENT-ON* */
Florin Corasba888e42017-01-24 11:38:18 -0800471}
472
473static void
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100474 vl_api_lisp_add_del_map_request_itr_rlocs_t_handler
475 (vl_api_lisp_add_del_map_request_itr_rlocs_t * mp)
476{
477 vl_api_lisp_add_del_map_request_itr_rlocs_reply_t *rmp;
478 int rv = 0;
479 u8 *locator_set_name = NULL;
480 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
481
Dave Barach59b25652017-09-10 15:04:27 -0400482 mp->locator_set_name[63] = 0;
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100483 locator_set_name = format (0, "%s", mp->locator_set_name);
484
485 a->is_add = mp->is_add;
486 a->locator_set_name = locator_set_name;
487
488 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
489
490 vec_free (locator_set_name);
491
492 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
493}
494
495static void
496 vl_api_lisp_add_del_remote_mapping_t_handler
497 (vl_api_lisp_add_del_remote_mapping_t * mp)
498{
499 locator_t *rlocs = 0;
500 vl_api_lisp_add_del_remote_mapping_reply_t *rmp;
501 int rv = 0;
502 gid_address_t _eid, *eid = &_eid;
503 u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
504
505 memset (eid, 0, sizeof (eid[0]));
506
507 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
508 mp->eid_type, mp->eid, mp->eid_len);
509 if (rv)
510 goto send_reply;
511
512 rlocs = unformat_lisp_locs (mp->rlocs, rloc_num);
513
514 if (!mp->is_add)
515 {
516 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
Dave Barach59b25652017-09-10 15:04:27 -0400517 memset (a, 0, sizeof (*a));
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100518 gid_address_copy (&a->reid, eid);
519 a->is_add = 0;
520 rv = vnet_lisp_add_del_adjacency (a);
521 if (rv)
522 {
523 goto out;
524 }
525 }
526
527 /* NOTE: for now this works as a static remote mapping, i.e.,
528 * not authoritative and ttl infinite. */
Filip Tehlar809bc742017-08-14 19:15:36 +0200529 if (mp->is_add)
530 {
531 vnet_lisp_add_del_mapping_args_t _m_args, *m_args = &_m_args;
532 memset (m_args, 0, sizeof (m_args[0]));
533 gid_address_copy (&m_args->eid, eid);
534 m_args->action = mp->action;
535 m_args->is_static = 1;
536 m_args->ttl = ~0;
537 m_args->authoritative = 0;
538 rv = vnet_lisp_add_mapping (m_args, rlocs, NULL, NULL);
539 }
540 else
Dave Barach59b25652017-09-10 15:04:27 -0400541 {
542 rv = vnet_lisp_del_mapping (eid, NULL);
543 }
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100544
545 if (mp->del_all)
546 vnet_lisp_clear_all_remote_adjacencies ();
547
548out:
549 vec_free (rlocs);
550send_reply:
551 REPLY_MACRO (VL_API_LISP_ADD_DEL_REMOTE_MAPPING_REPLY);
552}
553
554static void
555vl_api_lisp_add_del_adjacency_t_handler (vl_api_lisp_add_del_adjacency_t * mp)
556{
557 vl_api_lisp_add_del_adjacency_reply_t *rmp;
558 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
559
560 int rv = 0;
561 memset (a, 0, sizeof (a[0]));
562
563 rv = unformat_lisp_eid_api (&a->leid, clib_net_to_host_u32 (mp->vni),
564 mp->eid_type, mp->leid, mp->leid_len);
565 rv |= unformat_lisp_eid_api (&a->reid, clib_net_to_host_u32 (mp->vni),
566 mp->eid_type, mp->reid, mp->reid_len);
567
568 if (rv)
569 goto send_reply;
570
571 a->is_add = mp->is_add;
572 rv = vnet_lisp_add_del_adjacency (a);
573
574send_reply:
575 REPLY_MACRO (VL_API_LISP_ADD_DEL_ADJACENCY_REPLY);
576}
577
578static void
579send_lisp_locator_details (lisp_cp_main_t * lcm,
580 locator_t * loc,
581 unix_shared_memory_queue_t * q, u32 context)
582{
583 vl_api_lisp_locator_details_t *rmp;
584
585 rmp = vl_msg_api_alloc (sizeof (*rmp));
586 memset (rmp, 0, sizeof (*rmp));
587 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_DETAILS);
588 rmp->context = context;
589
590 rmp->local = loc->local;
591 if (loc->local)
592 {
593 rmp->sw_if_index = ntohl (loc->sw_if_index);
594 }
595 else
596 {
597 rmp->is_ipv6 = gid_address_ip_version (&loc->address);
598 ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
599 }
600 rmp->priority = loc->priority;
601 rmp->weight = loc->weight;
602
603 vl_msg_api_send_shmem (q, (u8 *) & rmp);
604}
605
606static void
607vl_api_lisp_locator_dump_t_handler (vl_api_lisp_locator_dump_t * mp)
608{
609 u8 *ls_name = 0;
610 unix_shared_memory_queue_t *q = 0;
611 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
612 locator_set_t *lsit = 0;
613 locator_t *loc = 0;
614 u32 ls_index = ~0, *locit = 0;
615 uword *p = 0;
616
617 q = vl_api_client_index_to_input_queue (mp->client_index);
618 if (q == 0)
619 {
620 return;
621 }
622
623 if (mp->is_index_set)
624 ls_index = htonl (mp->ls_index);
625 else
626 {
627 /* make sure we get a proper C-string */
628 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
629 ls_name = format (0, "%s", mp->ls_name);
630 p = hash_get_mem (lcm->locator_set_index_by_name, ls_name);
631 if (!p)
632 goto out;
633 ls_index = p[0];
634 }
635
636 if (pool_is_free_index (lcm->locator_set_pool, ls_index))
637 return;
638
639 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
640
641 vec_foreach (locit, lsit->locator_indices)
642 {
643 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
644 send_lisp_locator_details (lcm, loc, q, mp->context);
645 };
646out:
647 vec_free (ls_name);
648}
649
650static void
651send_lisp_locator_set_details (lisp_cp_main_t * lcm,
652 locator_set_t * lsit,
653 unix_shared_memory_queue_t * q,
654 u32 context, u32 ls_index)
655{
656 vl_api_lisp_locator_set_details_t *rmp;
657 u8 *str = 0;
658
659 rmp = vl_msg_api_alloc (sizeof (*rmp));
660 memset (rmp, 0, sizeof (*rmp));
661 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_SET_DETAILS);
662 rmp->context = context;
663
664 rmp->ls_index = htonl (ls_index);
665 if (lsit->local)
666 {
667 ASSERT (lsit->name != NULL);
668 strncpy ((char *) rmp->ls_name, (char *) lsit->name,
669 vec_len (lsit->name));
670 }
671 else
672 {
673 str = format (0, "<remote-%d>", ls_index);
674 strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str));
675 vec_free (str);
676 }
677
678 vl_msg_api_send_shmem (q, (u8 *) & rmp);
679}
680
681static void
682vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t * mp)
683{
684 unix_shared_memory_queue_t *q = NULL;
685 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
686 locator_set_t *lsit = NULL;
687 u8 filter;
688
689 q = vl_api_client_index_to_input_queue (mp->client_index);
690 if (q == 0)
691 {
692 return;
693 }
694
695 filter = mp->filter;
696 /* *INDENT-OFF* */
697 pool_foreach (lsit, lcm->locator_set_pool,
698 ({
699 if (filter && !((1 == filter && lsit->local) ||
700 (2 == filter && !lsit->local)))
701 {
702 continue;
703 }
704 send_lisp_locator_set_details (lcm, lsit, q, mp->context,
705 lsit - lcm->locator_set_pool);
706 }));
707 /* *INDENT-ON* */
708}
709
710static void
711lisp_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length)
712{
713 ASSERT (prefix_length);
714 ip_prefix_t *ippref = &fid_addr_ippref (src);
715
716 switch (fid_addr_type (src))
717 {
718 case FID_ADDR_IP_PREF:
719 if (ip_prefix_version (ippref) == IP4)
720 clib_memcpy (dst, &ip_prefix_v4 (ippref), 4);
721 else
722 clib_memcpy (dst, &ip_prefix_v6 (ippref), 16);
723 prefix_length[0] = ip_prefix_len (ippref);
724 break;
725
726 case FID_ADDR_MAC:
727 prefix_length[0] = 0;
728 clib_memcpy (dst, fid_addr_mac (src), 6);
729 break;
730
731 default:
732 clib_warning ("Unknown FID type %d!", fid_addr_type (src));
733 break;
734 }
735}
736
737static u8
738fid_type_to_api_type (fid_address_t * fid)
739{
740 ip_prefix_t *ippref;
741
742 switch (fid_addr_type (fid))
743 {
744 case FID_ADDR_IP_PREF:
745 ippref = &fid_addr_ippref (fid);
746 if (ip_prefix_version (ippref) == IP4)
747 return 0;
748 else if (ip_prefix_version (ippref) == IP6)
749 return 1;
750 else
751 return ~0;
752
753 case FID_ADDR_MAC:
754 return 2;
Florin Corasce1b4c72017-01-26 14:25:34 -0800755 case FID_ADDR_NSH:
756 return 3;
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100757 }
758
759 return ~0;
760}
761
762static void
763send_lisp_eid_table_details (mapping_t * mapit,
764 unix_shared_memory_queue_t * q,
765 u32 context, u8 filter)
766{
767 fid_address_t *fid;
768 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
769 locator_set_t *ls = 0;
770 vl_api_lisp_eid_table_details_t *rmp = NULL;
771 gid_address_t *gid = NULL;
772 u8 *mac = 0;
773 ip_prefix_t *ip_prefix = NULL;
774
775 switch (filter)
776 {
777 case 0: /* all mappings */
778 break;
779
780 case 1: /* local only */
781 if (!mapit->local)
782 return;
783 break;
784 case 2: /* remote only */
785 if (mapit->local)
786 return;
787 break;
788 default:
789 clib_warning ("Filter error, unknown filter: %d", filter);
790 return;
791 }
792
Filip Tehlar38206ee2017-02-20 17:31:57 +0100793 /* don't send PITR generated mapping */
794 if (mapit->pitr_set)
795 return;
796
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100797 gid = &mapit->eid;
798 ip_prefix = &gid_address_ippref (gid);
799 mac = gid_address_mac (gid);
800
801 rmp = vl_msg_api_alloc (sizeof (*rmp));
802 memset (rmp, 0, sizeof (*rmp));
803 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_DETAILS);
804
805 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
806 if (vec_len (ls->locator_indices) == 0)
807 rmp->locator_set_index = ~0;
808 else
809 rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
810
811 rmp->is_local = mapit->local;
812 rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
813 rmp->action = mapit->action;
814 rmp->authoritative = mapit->authoritative;
815
816 switch (gid_address_type (gid))
817 {
818 case GID_ADDR_SRC_DST:
819 rmp->is_src_dst = 1;
820 fid = &gid_address_sd_src (gid);
821 rmp->eid_type = fid_type_to_api_type (fid);
822 lisp_fid_put_api (rmp->seid, &gid_address_sd_src (gid),
823 &rmp->seid_prefix_len);
824 lisp_fid_put_api (rmp->eid, &gid_address_sd_dst (gid),
825 &rmp->eid_prefix_len);
826 break;
827 case GID_ADDR_IP_PREFIX:
828 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
829 if (ip_prefix_version (ip_prefix) == IP4)
830 {
831 rmp->eid_type = 0; /* ipv4 type */
832 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
833 sizeof (ip_prefix_v4 (ip_prefix)));
834 }
835 else
836 {
837 rmp->eid_type = 1; /* ipv6 type */
838 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
839 sizeof (ip_prefix_v6 (ip_prefix)));
840 }
841 break;
842 case GID_ADDR_MAC:
843 rmp->eid_type = 2; /* l2 mac type */
844 clib_memcpy (rmp->eid, mac, 6);
845 break;
846 default:
847 ASSERT (0);
848 }
849 rmp->context = context;
850 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
851 rmp->key_id = clib_host_to_net_u16 (mapit->key_id);
852 memcpy (rmp->key, mapit->key, vec_len (mapit->key));
853 vl_msg_api_send_shmem (q, (u8 *) & rmp);
854}
855
856static void
857vl_api_lisp_eid_table_dump_t_handler (vl_api_lisp_eid_table_dump_t * mp)
858{
859 u32 mi;
860 unix_shared_memory_queue_t *q = NULL;
861 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
862 mapping_t *mapit = NULL;
863 gid_address_t _eid, *eid = &_eid;
864
865 q = vl_api_client_index_to_input_queue (mp->client_index);
866 if (q == 0)
867 {
868 return;
869 }
870
871 if (mp->eid_set)
872 {
873 memset (eid, 0, sizeof (*eid));
874
875 unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
876 mp->eid_type, mp->eid, mp->prefix_length);
877
878 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
879 if ((u32) ~ 0 == mi)
880 return;
881
882 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
883 send_lisp_eid_table_details (mapit, q, mp->context,
884 0 /* ignore filter */ );
885 }
886 else
887 {
888 /* *INDENT-OFF* */
889 pool_foreach (mapit, lcm->mapping_pool,
890 ({
891 send_lisp_eid_table_details(mapit, q, mp->context,
892 mp->filter);
893 }));
894 /* *INDENT-ON* */
895 }
896}
897
898static void
899send_lisp_map_server_details (ip_address_t * ip,
900 unix_shared_memory_queue_t * q, u32 context)
901{
902 vl_api_lisp_map_server_details_t *rmp = NULL;
903
904 rmp = vl_msg_api_alloc (sizeof (*rmp));
905 memset (rmp, 0, sizeof (*rmp));
906 rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_SERVER_DETAILS);
907
908 switch (ip_addr_version (ip))
909 {
910 case IP4:
911 rmp->is_ipv6 = 0;
912 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
913 sizeof (ip_addr_v4 (ip)));
914 break;
915
916 case IP6:
917 rmp->is_ipv6 = 1;
918 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
919 sizeof (ip_addr_v6 (ip)));
920 break;
921
922 default:
923 ASSERT (0);
924 }
925 rmp->context = context;
926
927 vl_msg_api_send_shmem (q, (u8 *) & rmp);
928}
929
930static void
931vl_api_lisp_map_server_dump_t_handler (vl_api_lisp_map_server_dump_t * mp)
932{
933 unix_shared_memory_queue_t *q = NULL;
934 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
935 lisp_msmr_t *mr;
936
937 q = vl_api_client_index_to_input_queue (mp->client_index);
938 if (q == 0)
939 {
940 return;
941 }
942
943 vec_foreach (mr, lcm->map_servers)
944 {
945 send_lisp_map_server_details (&mr->address, q, mp->context);
946 }
947}
948
949static void
950send_lisp_map_resolver_details (ip_address_t * ip,
951 unix_shared_memory_queue_t * q, u32 context)
952{
953 vl_api_lisp_map_resolver_details_t *rmp = NULL;
954
955 rmp = vl_msg_api_alloc (sizeof (*rmp));
956 memset (rmp, 0, sizeof (*rmp));
957 rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_RESOLVER_DETAILS);
958
959 switch (ip_addr_version (ip))
960 {
961 case IP4:
962 rmp->is_ipv6 = 0;
963 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
964 sizeof (ip_addr_v4 (ip)));
965 break;
966
967 case IP6:
968 rmp->is_ipv6 = 1;
969 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
970 sizeof (ip_addr_v6 (ip)));
971 break;
972
973 default:
974 ASSERT (0);
975 }
976 rmp->context = context;
977
978 vl_msg_api_send_shmem (q, (u8 *) & rmp);
979}
980
981static void
982vl_api_lisp_map_resolver_dump_t_handler (vl_api_lisp_map_resolver_dump_t * mp)
983{
984 unix_shared_memory_queue_t *q = NULL;
985 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
986 lisp_msmr_t *mr;
987
988 q = vl_api_client_index_to_input_queue (mp->client_index);
989 if (q == 0)
990 {
991 return;
992 }
993
994 vec_foreach (mr, lcm->map_resolvers)
995 {
996 send_lisp_map_resolver_details (&mr->address, q, mp->context);
997 }
998}
999
1000static void
1001send_eid_table_map_pair (hash_pair_t * p,
1002 unix_shared_memory_queue_t * q, u32 context)
1003{
1004 vl_api_lisp_eid_table_map_details_t *rmp = NULL;
1005
1006 rmp = vl_msg_api_alloc (sizeof (*rmp));
1007 memset (rmp, 0, sizeof (*rmp));
1008 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_MAP_DETAILS);
1009
1010 rmp->vni = clib_host_to_net_u32 (p->key);
1011 rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
1012 rmp->context = context;
1013 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1014}
1015
1016static void
1017vl_api_lisp_eid_table_map_dump_t_handler (vl_api_lisp_eid_table_map_dump_t *
1018 mp)
1019{
1020 unix_shared_memory_queue_t *q = NULL;
1021 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1022 hash_pair_t *p;
1023 uword *vni_table = 0;
1024
1025 q = vl_api_client_index_to_input_queue (mp->client_index);
1026 if (q == 0)
1027 {
1028 return;
1029 }
1030
1031 if (mp->is_l2)
1032 {
1033 vni_table = lcm->bd_id_by_vni;
1034 }
1035 else
1036 {
1037 vni_table = lcm->table_id_by_vni;
1038 }
1039
1040 /* *INDENT-OFF* */
1041 hash_foreach_pair (p, vni_table,
1042 ({
1043 send_eid_table_map_pair (p, q, mp->context);
1044 }));
1045 /* *INDENT-ON* */
1046}
1047
1048static void
1049send_eid_table_vni (u32 vni, unix_shared_memory_queue_t * q, u32 context)
1050{
1051 vl_api_lisp_eid_table_vni_details_t *rmp = 0;
1052
1053 rmp = vl_msg_api_alloc (sizeof (*rmp));
1054 memset (rmp, 0, sizeof (*rmp));
1055 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_VNI_DETAILS);
1056 rmp->context = context;
1057 rmp->vni = clib_host_to_net_u32 (vni);
1058 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1059}
1060
1061static void
1062lisp_adjacency_copy (vl_api_lisp_adjacency_t * dst, lisp_adjacency_t * adjs)
1063{
1064 lisp_adjacency_t *adj;
1065 vl_api_lisp_adjacency_t a;
1066 u32 i, n = vec_len (adjs);
1067
1068 for (i = 0; i < n; i++)
1069 {
1070 adj = vec_elt_at_index (adjs, i);
1071 memset (&a, 0, sizeof (a));
1072
1073 switch (gid_address_type (&adj->reid))
1074 {
1075 case GID_ADDR_IP_PREFIX:
1076 a.reid_prefix_len = gid_address_ippref_len (&adj->reid);
1077 a.leid_prefix_len = gid_address_ippref_len (&adj->leid);
1078 if (gid_address_ip_version (&adj->reid) == IP4)
1079 {
1080 a.eid_type = 0; /* ipv4 type */
1081 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 4);
1082 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 4);
1083 }
1084 else
1085 {
1086 a.eid_type = 1; /* ipv6 type */
1087 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 16);
1088 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 16);
1089 }
1090 break;
1091 case GID_ADDR_MAC:
1092 a.eid_type = 2; /* l2 mac type */
1093 mac_copy (a.reid, gid_address_mac (&adj->reid));
1094 mac_copy (a.leid, gid_address_mac (&adj->leid));
1095 break;
1096 default:
1097 ASSERT (0);
1098 }
1099 dst[i] = a;
1100 }
1101}
1102
1103static void
1104 vl_api_show_lisp_rloc_probe_state_t_handler
1105 (vl_api_show_lisp_rloc_probe_state_t * mp)
1106{
1107 vl_api_show_lisp_rloc_probe_state_reply_t *rmp = 0;
1108 int rv = 0;
1109
1110 /* *INDENT-OFF* */
1111 REPLY_MACRO2 (VL_API_SHOW_LISP_RLOC_PROBE_STATE_REPLY,
1112 {
1113 rmp->is_enabled = vnet_lisp_rloc_probe_state_get ();
1114 });
1115 /* *INDENT-ON* */
1116}
1117
1118static void
1119 vl_api_show_lisp_map_register_state_t_handler
1120 (vl_api_show_lisp_map_register_state_t * mp)
1121{
1122 vl_api_show_lisp_map_register_state_reply_t *rmp = 0;
1123 int rv = 0;
1124
1125 /* *INDENT-OFF* */
1126 REPLY_MACRO2 (VL_API_SHOW_LISP_MAP_REGISTER_STATE_REPLY,
1127 {
1128 rmp->is_enabled = vnet_lisp_map_register_state_get ();
1129 });
1130 /* *INDENT-ON* */
1131}
1132
1133static void
1134vl_api_lisp_adjacencies_get_t_handler (vl_api_lisp_adjacencies_get_t * mp)
1135{
1136 vl_api_lisp_adjacencies_get_reply_t *rmp = 0;
1137 lisp_adjacency_t *adjs = 0;
1138 int rv = 0;
Pavel Kotucekcfb7be82016-12-21 14:15:37 +01001139 u32 size = ~0;
1140 u32 vni = clib_net_to_host_u32 (mp->vni);
1141
1142 adjs = vnet_lisp_adjacencies_get_by_vni (vni);
Filip Tehlar5fae99c2017-01-18 12:57:37 +01001143 size = vec_len (adjs) * sizeof (vl_api_lisp_adjacency_t);
Pavel Kotucekcfb7be82016-12-21 14:15:37 +01001144
1145 /* *INDENT-OFF* */
1146 REPLY_MACRO4 (VL_API_LISP_ADJACENCIES_GET_REPLY, size,
1147 {
1148 rmp->count = clib_host_to_net_u32 (vec_len (adjs));
1149 lisp_adjacency_copy (rmp->adjacencies, adjs);
1150 });
1151 /* *INDENT-ON* */
1152
1153 vec_free (adjs);
1154}
1155
1156static void
1157vl_api_lisp_eid_table_vni_dump_t_handler (vl_api_lisp_eid_table_vni_dump_t *
1158 mp)
1159{
1160 hash_pair_t *p;
1161 u32 *vnis = 0;
1162 unix_shared_memory_queue_t *q = 0;
1163 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1164
1165 q = vl_api_client_index_to_input_queue (mp->client_index);
1166 if (q == 0)
1167 {
1168 return;
1169 }
1170
1171 /* *INDENT-OFF* */
1172 hash_foreach_pair (p, lcm->table_id_by_vni,
1173 ({
1174 hash_set (vnis, p->key, 0);
1175 }));
1176
1177 hash_foreach_pair (p, lcm->bd_id_by_vni,
1178 ({
1179 hash_set (vnis, p->key, 0);
1180 }));
1181
1182 hash_foreach_pair (p, vnis,
1183 ({
1184 send_eid_table_vni (p->key, q, mp->context);
1185 }));
1186 /* *INDENT-ON* */
1187
1188 hash_free (vnis);
1189}
1190
1191static void
1192vl_api_show_lisp_status_t_handler (vl_api_show_lisp_status_t * mp)
1193{
1194 unix_shared_memory_queue_t *q = NULL;
1195 vl_api_show_lisp_status_reply_t *rmp = NULL;
1196 int rv = 0;
1197
1198 q = vl_api_client_index_to_input_queue (mp->client_index);
1199 if (q == 0)
1200 {
1201 return;
1202 }
1203
1204 /* *INDENT-OFF* */
1205 REPLY_MACRO2(VL_API_SHOW_LISP_STATUS_REPLY,
1206 ({
1207 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
1208 rmp->feature_status = vnet_lisp_enable_disable_status ();
1209 }));
1210 /* *INDENT-ON* */
1211}
1212
1213static void
1214 vl_api_lisp_get_map_request_itr_rlocs_t_handler
1215 (vl_api_lisp_get_map_request_itr_rlocs_t * mp)
1216{
1217 unix_shared_memory_queue_t *q = NULL;
1218 vl_api_lisp_get_map_request_itr_rlocs_reply_t *rmp = NULL;
1219 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1220 locator_set_t *loc_set = 0;
1221 u8 *tmp_str = 0;
1222 int rv = 0;
1223
1224 q = vl_api_client_index_to_input_queue (mp->client_index);
1225 if (q == 0)
1226 {
1227 return;
1228 }
1229
1230 if (~0 == lcm->mreq_itr_rlocs)
1231 {
1232 tmp_str = format (0, " ");
1233 }
1234 else
1235 {
1236 loc_set =
1237 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
1238 tmp_str = format (0, "%s", loc_set->name);
1239 }
1240
1241 /* *INDENT-OFF* */
1242 REPLY_MACRO2(VL_API_LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
1243 ({
1244 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1245 ARRAY_LEN(rmp->locator_set_name) - 1);
1246 }));
1247 /* *INDENT-ON* */
1248
1249 vec_free (tmp_str);
1250}
1251
1252static void
1253vl_api_show_lisp_pitr_t_handler (vl_api_show_lisp_pitr_t * mp)
1254{
1255 unix_shared_memory_queue_t *q = NULL;
1256 vl_api_show_lisp_pitr_reply_t *rmp = NULL;
1257 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1258 mapping_t *m;
1259 locator_set_t *ls = 0;
1260 u8 *tmp_str = 0;
1261 int rv = 0;
1262
1263 q = vl_api_client_index_to_input_queue (mp->client_index);
1264 if (q == 0)
1265 {
1266 return;
1267 }
1268
1269 if (!lcm->lisp_pitr)
1270 {
1271 tmp_str = format (0, "N/A");
1272 }
1273 else
1274 {
1275 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
1276 if (~0 != m->locator_set_index)
1277 {
1278 ls =
1279 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
1280 tmp_str = format (0, "%s", ls->name);
1281 }
1282 else
1283 {
1284 tmp_str = format (0, "N/A");
1285 }
1286 }
1287 vec_add1 (tmp_str, 0);
1288
1289 /* *INDENT-OFF* */
1290 REPLY_MACRO2(VL_API_SHOW_LISP_PITR_REPLY,
1291 ({
1292 rmp->status = lcm->lisp_pitr;
1293 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1294 ARRAY_LEN(rmp->locator_set_name) - 1);
1295 }));
1296 /* *INDENT-ON* */
1297}
1298
1299/*
1300 * lisp_api_hookup
1301 * Add vpe's API message handlers to the table.
1302 * vlib has alread mapped shared memory and
1303 * added the client registration handlers.
1304 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
1305 */
1306#define vl_msg_name_crc_list
1307#include <vnet/vnet_all_api_h.h>
1308#undef vl_msg_name_crc_list
1309
1310static void
1311setup_message_id_table (api_main_t * am)
1312{
1313#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
Filip Tehlar974cdc62017-02-22 18:09:49 +01001314 foreach_vl_msg_name_crc_lisp;
Pavel Kotucekcfb7be82016-12-21 14:15:37 +01001315#undef _
1316}
1317
1318static clib_error_t *
1319lisp_api_hookup (vlib_main_t * vm)
1320{
1321 api_main_t *am = &api_main;
1322
1323#define _(N,n) \
1324 vl_msg_api_set_handlers(VL_API_##N, #n, \
1325 vl_api_##n##_t_handler, \
1326 vl_noop_handler, \
1327 vl_api_##n##_t_endian, \
1328 vl_api_##n##_t_print, \
1329 sizeof(vl_api_##n##_t), 1);
1330 foreach_vpe_api_msg;
1331#undef _
1332
1333 /*
1334 * Set up the (msg_name, crc, message-id) table
1335 */
1336 setup_message_id_table (am);
1337
1338 return 0;
1339}
1340
1341VLIB_API_INIT_FUNCTION (lisp_api_hookup);
1342
1343/*
1344 * fd.io coding-style-patch-verification: ON
1345 *
1346 * Local Variables:
1347 * eval: (c-set-style "gnu")
1348 * End:
1349 */