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