blob: 7c8ba63f90e0c39b59b0ef142bba60a66b240535 [file] [log] [blame]
Filip Tehlar694396d2017-02-17 14:29:11 +01001/*
2 *------------------------------------------------------------------
3 * one_api.c - Overlay Network Engine API
4 *
5 * Copyright (c) 2016-2017 Cisco and/or its affiliates.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
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 Tehlar974cdc62017-02-22 18:09:49 +010030#define vl_api_one_remote_locator_t_endian vl_noop_handler
31#define vl_api_one_remote_locator_t_print vl_noop_handler
32#define vl_api_one_local_locator_t_endian vl_noop_handler
33#define vl_api_one_local_locator_t_print vl_noop_handler
Filip Tehlar694396d2017-02-17 14:29:11 +010034
35#define vl_api_one_add_del_locator_set_t_endian vl_noop_handler
36#define vl_api_one_add_del_locator_set_t_print vl_noop_handler
37#define vl_api_one_add_del_remote_mapping_t_endian vl_noop_handler
38#define vl_api_one_add_del_remote_mapping_t_print vl_noop_handler
39
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
44
Filip Tehlard5a65db2017-05-17 17:21:10 +020045#define vl_api_one_l2_arp_entry_t_endian vl_noop_handler
46#define vl_api_one_l2_arp_entry_t_print vl_noop_handler
47#define vl_api_one_add_del_l2_arp_entry vl_noop_handler
48#define vl_api_one_l2_arp_bd_get vl_noop_handler
49
Filip Tehlard6307132017-09-04 18:54:33 +020050#define vl_api_one_ndp_entry_t_endian vl_noop_handler
51#define vl_api_one_ndp_entry_t_print vl_noop_handler
52#define vl_api_one_ndp_entries_get_reply_t_endian vl_noop_handler
53#define vl_api_one_ndp_entries_get_reply_t_print vl_noop_handler
54
Filip Tehlar694396d2017-02-17 14:29:11 +010055#define vl_typedefs /* define message structures */
56#include <vnet/vnet_all_api_h.h>
57#undef vl_typedefs
58
59#define vl_endianfun /* define message structures */
60#include <vnet/vnet_all_api_h.h>
61#undef vl_endianfun
62
63/* instantiate all the print functions we know about */
64#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
65#define vl_printfun
66#include <vnet/vnet_all_api_h.h>
67#undef vl_printfun
68
69#include <vlibapi/api_helper_macros.h>
70
Filip Tehlar4868ff62017-03-09 16:48:39 +010071#define REPLY_DETAILS(t, body) \
72do { \
73 unix_shared_memory_queue_t * q; \
74 rv = vl_msg_api_pd_handler (mp, rv); \
75 q = vl_api_client_index_to_input_queue (mp->client_index); \
76 if (!q) \
77 return; \
78 \
79 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
80 rmp->_vl_msg_id = ntohs((t)); \
81 rmp->context = mp->context; \
82 do {body;} while (0); \
83 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
84} while(0);
85
Filip Tehlar694396d2017-02-17 14:29:11 +010086#define foreach_vpe_api_msg \
87_(ONE_ADD_DEL_LOCATOR_SET, one_add_del_locator_set) \
88_(ONE_ADD_DEL_LOCATOR, one_add_del_locator) \
89_(ONE_ADD_DEL_LOCAL_EID, one_add_del_local_eid) \
90_(ONE_ADD_DEL_MAP_RESOLVER, one_add_del_map_resolver) \
91_(ONE_ADD_DEL_MAP_SERVER, one_add_del_map_server) \
92_(ONE_ENABLE_DISABLE, one_enable_disable) \
93_(ONE_RLOC_PROBE_ENABLE_DISABLE, one_rloc_probe_enable_disable) \
94_(ONE_MAP_REGISTER_ENABLE_DISABLE, one_map_register_enable_disable) \
Filip Tehlar7048ff12017-07-27 08:09:14 +020095_(ONE_MAP_REGISTER_FALLBACK_THRESHOLD, \
96 one_map_register_fallback_threshold) \
Filip Tehlar694396d2017-02-17 14:29:11 +010097_(ONE_ADD_DEL_REMOTE_MAPPING, one_add_del_remote_mapping) \
98_(ONE_ADD_DEL_ADJACENCY, one_add_del_adjacency) \
99_(ONE_PITR_SET_LOCATOR_SET, one_pitr_set_locator_set) \
Filip Tehlaref2a5bf2017-05-30 07:14:46 +0200100_(ONE_NSH_SET_LOCATOR_SET, one_nsh_set_locator_set) \
Filip Tehlar694396d2017-02-17 14:29:11 +0100101_(ONE_MAP_REQUEST_MODE, one_map_request_mode) \
102_(ONE_EID_TABLE_ADD_DEL_MAP, one_eid_table_add_del_map) \
103_(ONE_LOCATOR_SET_DUMP, one_locator_set_dump) \
104_(ONE_LOCATOR_DUMP, one_locator_dump) \
105_(ONE_EID_TABLE_DUMP, one_eid_table_dump) \
106_(ONE_MAP_RESOLVER_DUMP, one_map_resolver_dump) \
107_(ONE_MAP_SERVER_DUMP, one_map_server_dump) \
108_(ONE_EID_TABLE_MAP_DUMP, one_eid_table_map_dump) \
109_(ONE_EID_TABLE_VNI_DUMP, one_eid_table_vni_dump) \
110_(ONE_ADJACENCIES_GET, one_adjacencies_get) \
Filip Tehlar1e553a02017-08-02 12:45:07 +0200111_(ONE_MAP_REGISTER_SET_TTL, one_map_register_set_ttl) \
Filip Tehlaref2a5bf2017-05-30 07:14:46 +0200112_(SHOW_ONE_NSH_MAPPING, show_one_nsh_mapping) \
Filip Tehlar694396d2017-02-17 14:29:11 +0100113_(SHOW_ONE_RLOC_PROBE_STATE, show_one_rloc_probe_state) \
114_(SHOW_ONE_MAP_REGISTER_STATE, show_one_map_register_state) \
Filip Tehlar1e553a02017-08-02 12:45:07 +0200115_(SHOW_ONE_MAP_REGISTER_TTL, show_one_map_register_ttl) \
Filip Tehlar7048ff12017-07-27 08:09:14 +0200116_(SHOW_ONE_MAP_REGISTER_FALLBACK_THRESHOLD, \
117 show_one_map_register_fallback_threshold) \
Filip Tehlar694396d2017-02-17 14:29:11 +0100118_(SHOW_ONE_STATUS, show_one_status) \
119_(ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \
120 one_add_del_map_request_itr_rlocs) \
121_(ONE_GET_MAP_REQUEST_ITR_RLOCS, one_get_map_request_itr_rlocs) \
122_(SHOW_ONE_PITR, show_one_pitr) \
123_(SHOW_ONE_MAP_REQUEST_MODE, show_one_map_request_mode) \
124_(ONE_USE_PETR, one_use_petr) \
125_(SHOW_ONE_USE_PETR, show_one_use_petr) \
Filip Tehlar7eaf0e52017-03-08 08:46:51 +0100126_(SHOW_ONE_STATS_ENABLE_DISABLE, show_one_stats_enable_disable) \
127_(ONE_STATS_ENABLE_DISABLE, one_stats_enable_disable) \
128_(ONE_STATS_DUMP, one_stats_dump) \
Filip Tehlar21511912017-04-07 10:41:42 +0200129_(ONE_STATS_FLUSH, one_stats_flush) \
Filip Tehlard5a65db2017-05-17 17:21:10 +0200130_(ONE_L2_ARP_BD_GET, one_l2_arp_bd_get) \
131_(ONE_L2_ARP_ENTRIES_GET, one_l2_arp_entries_get) \
132_(ONE_ADD_DEL_L2_ARP_ENTRY, one_add_del_l2_arp_entry) \
Filip Tehlar7eaf0e52017-03-08 08:46:51 +0100133
Filip Tehlar694396d2017-02-17 14:29:11 +0100134
135static locator_t *
Filip Tehlar974cdc62017-02-22 18:09:49 +0100136unformat_one_locs (vl_api_one_remote_locator_t * rmt_locs, u32 rloc_num)
Filip Tehlar694396d2017-02-17 14:29:11 +0100137{
138 u32 i;
139 locator_t *locs = 0, loc;
Filip Tehlar974cdc62017-02-22 18:09:49 +0100140 vl_api_one_remote_locator_t *r;
Filip Tehlar694396d2017-02-17 14:29:11 +0100141
142 for (i = 0; i < rloc_num; i++)
143 {
144 /* remote locators */
145 r = &rmt_locs[i];
146 memset (&loc, 0, sizeof (loc));
147 gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
148
149 loc.priority = r->priority;
150 loc.weight = r->weight;
151
152 vec_add1 (locs, loc);
153 }
154 return locs;
155}
156
157static void
Filip Tehlar1e553a02017-08-02 12:45:07 +0200158vl_api_one_map_register_set_ttl_t_handler (vl_api_one_map_register_set_ttl_t *
159 mp)
160{
161 vl_api_one_map_register_set_ttl_reply_t *rmp;
162 int rv = 0;
163
Filip Tehlar5391e192017-08-04 09:13:50 +0200164 mp->ttl = clib_net_to_host_u32 (mp->ttl);
Filip Tehlar1e553a02017-08-02 12:45:07 +0200165 rv = vnet_lisp_map_register_set_ttl (mp->ttl);
166
167 REPLY_MACRO (VL_API_ONE_MAP_REGISTER_SET_TTL_REPLY);
168}
169
170static void
171 vl_api_show_one_map_register_ttl_t_handler
172 (vl_api_show_one_map_register_ttl_t * mp)
173{
174 vl_api_show_one_map_register_ttl_reply_t *rmp;
175 int rv = 0;
176
177 u32 ttl = vnet_lisp_map_register_get_ttl ();
178 /* *INDENT-OFF* */
179 REPLY_MACRO2 (VL_API_SHOW_ONE_MAP_REGISTER_TTL_REPLY,
180 ({
181 rmp->ttl = clib_host_to_net_u32 (ttl);
182 }));
183 /* *INDENT-ON* */
184}
185
186static void
Filip Tehlar694396d2017-02-17 14:29:11 +0100187vl_api_one_add_del_locator_set_t_handler (vl_api_one_add_del_locator_set_t *
188 mp)
189{
190 vl_api_one_add_del_locator_set_reply_t *rmp;
191 int rv = 0;
192 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
193 locator_t locator;
Filip Tehlar974cdc62017-02-22 18:09:49 +0100194 vl_api_one_local_locator_t *ls_loc;
Filip Tehlar694396d2017-02-17 14:29:11 +0100195 u32 ls_index = ~0, locator_num;
196 u8 *locator_name = NULL;
197 int i;
198
199 memset (a, 0, sizeof (a[0]));
200
201 locator_name = format (0, "%s", mp->locator_set_name);
202
203 a->name = locator_name;
204 a->is_add = mp->is_add;
205 a->local = 1;
206 locator_num = clib_net_to_host_u32 (mp->locator_num);
207
208 memset (&locator, 0, sizeof (locator));
209 for (i = 0; i < locator_num; i++)
210 {
211 ls_loc = &mp->locators[i];
212 VALIDATE_SW_IF_INDEX (ls_loc);
213
214 locator.sw_if_index = htonl (ls_loc->sw_if_index);
215 locator.priority = ls_loc->priority;
216 locator.weight = ls_loc->weight;
217 locator.local = 1;
218 vec_add1 (a->locators, locator);
219 }
220
221 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
222
223 BAD_SW_IF_INDEX_LABEL;
224
225 vec_free (locator_name);
226 vec_free (a->locators);
227
228 /* *INDENT-OFF* */
229 REPLY_MACRO2 (VL_API_ONE_ADD_DEL_LOCATOR_SET_REPLY,
230 ({
231 rmp->ls_index = clib_host_to_net_u32 (ls_index);
232 }));
233 /* *INDENT-ON* */
234}
235
236static void
237vl_api_one_add_del_locator_t_handler (vl_api_one_add_del_locator_t * mp)
238{
239 vl_api_one_add_del_locator_reply_t *rmp;
240 int rv = 0;
241 locator_t locator, *locators = NULL;
242 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
243 u32 ls_index = ~0;
244 u8 *locator_name = NULL;
245
246 memset (&locator, 0, sizeof (locator));
247 memset (a, 0, sizeof (a[0]));
248
249 locator.sw_if_index = ntohl (mp->sw_if_index);
250 locator.priority = mp->priority;
251 locator.weight = mp->weight;
252 locator.local = 1;
253 vec_add1 (locators, locator);
254
255 locator_name = format (0, "%s", mp->locator_set_name);
256
257 a->name = locator_name;
258 a->locators = locators;
259 a->is_add = mp->is_add;
260 a->local = 1;
261
262 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
263
264 vec_free (locators);
265 vec_free (locator_name);
266
267 REPLY_MACRO (VL_API_ONE_ADD_DEL_LOCATOR_REPLY);
268}
269
Filip Tehlaref2a5bf2017-05-30 07:14:46 +0200270typedef struct
271{
272 u32 spi;
273 u8 si;
274} __attribute__ ((__packed__)) lisp_nsh_api_t;
275
Filip Tehlar694396d2017-02-17 14:29:11 +0100276static int
277unformat_one_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
278 u8 len)
279{
Filip Tehlaref2a5bf2017-05-30 07:14:46 +0200280 lisp_nsh_api_t *nsh;
281
Filip Tehlar694396d2017-02-17 14:29:11 +0100282 switch (type)
283 {
284 case 0: /* ipv4 */
285 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
286 gid_address_ip_set (dst, src, IP4);
287 gid_address_ippref_len (dst) = len;
288 ip_prefix_normalize (&gid_address_ippref (dst));
289 break;
290 case 1: /* ipv6 */
291 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
292 gid_address_ip_set (dst, src, IP6);
293 gid_address_ippref_len (dst) = len;
294 ip_prefix_normalize (&gid_address_ippref (dst));
295 break;
296 case 2: /* l2 mac */
297 gid_address_type (dst) = GID_ADDR_MAC;
298 clib_memcpy (&gid_address_mac (dst), src, 6);
299 break;
Filip Tehlaref2a5bf2017-05-30 07:14:46 +0200300 case 3: /* NSH */
301 gid_address_type (dst) = GID_ADDR_NSH;
302 nsh = src;
303 gid_address_nsh_spi (dst) = clib_net_to_host_u32 (nsh->spi);
304 gid_address_nsh_si (dst) = nsh->si;
305 break;
Filip Tehlar694396d2017-02-17 14:29:11 +0100306 default:
307 /* unknown type */
308 return VNET_API_ERROR_INVALID_VALUE;
309 }
310
311 gid_address_vni (dst) = vni;
312
313 return 0;
314}
315
316static void
317vl_api_one_add_del_local_eid_t_handler (vl_api_one_add_del_local_eid_t * mp)
318{
319 vl_api_one_add_del_local_eid_reply_t *rmp;
320 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
321 int rv = 0;
322 gid_address_t _eid, *eid = &_eid;
323 uword *p = NULL;
324 u32 locator_set_index = ~0, map_index = ~0;
325 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
326 u8 *name = NULL, *key = NULL;
327 memset (a, 0, sizeof (a[0]));
328 memset (eid, 0, sizeof (eid[0]));
329
330 rv = unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
331 mp->eid_type, mp->eid, mp->prefix_len);
332 if (rv)
333 goto out;
334
Filip Tehlaref2a5bf2017-05-30 07:14:46 +0200335 if (gid_address_type (eid) == GID_ADDR_NSH)
336 {
337 rv = VNET_API_ERROR_INVALID_VALUE;
338 goto out;
339 }
340
Filip Tehlar694396d2017-02-17 14:29:11 +0100341 name = format (0, "%s", mp->locator_set_name);
342 p = hash_get_mem (lcm->locator_set_index_by_name, name);
343 if (!p)
344 {
345 rv = VNET_API_ERROR_INVALID_VALUE;
346 goto out;
347 }
348 locator_set_index = p[0];
349
350 if (*mp->key)
351 key = format (0, "%s", mp->key);
352
353 /* XXX treat batch configuration */
354 a->is_add = mp->is_add;
355 gid_address_copy (&a->eid, eid);
356 a->locator_set_index = locator_set_index;
357 a->local = 1;
358 a->key = key;
359 a->key_id = clib_net_to_host_u16 (mp->key_id);
360
361 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
362
363out:
364 vec_free (name);
365 vec_free (key);
366 gid_address_free (&a->eid);
367
368 REPLY_MACRO (VL_API_ONE_ADD_DEL_LOCAL_EID_REPLY);
369}
370
371static void
372 vl_api_one_eid_table_add_del_map_t_handler
373 (vl_api_one_eid_table_add_del_map_t * mp)
374{
375 vl_api_one_eid_table_add_del_map_reply_t *rmp;
376 int rv = 0;
377 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
378 clib_net_to_host_u32 (mp->dp_table),
379 mp->is_l2, mp->is_add);
380REPLY_MACRO (VL_API_ONE_EID_TABLE_ADD_DEL_MAP_REPLY)}
381
382static void
383vl_api_one_add_del_map_server_t_handler (vl_api_one_add_del_map_server_t * mp)
384{
385 vl_api_one_add_del_map_server_reply_t *rmp;
386 int rv = 0;
387 ip_address_t addr;
388
389 memset (&addr, 0, sizeof (addr));
390
391 ip_address_set (&addr, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
392 rv = vnet_lisp_add_del_map_server (&addr, mp->is_add);
393
394 REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_SERVER_REPLY);
395}
396
397static void
398vl_api_one_add_del_map_resolver_t_handler (vl_api_one_add_del_map_resolver_t
399 * mp)
400{
401 vl_api_one_add_del_map_resolver_reply_t *rmp;
402 int rv = 0;
403 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
404
405 memset (a, 0, sizeof (a[0]));
406
407 a->is_add = mp->is_add;
408 ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
409
410 rv = vnet_lisp_add_del_map_resolver (a);
411
412 REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_RESOLVER_REPLY);
413}
414
415static void
416 vl_api_one_map_register_enable_disable_t_handler
417 (vl_api_one_map_register_enable_disable_t * mp)
418{
419 vl_api_one_map_register_enable_disable_reply_t *rmp;
420 int rv = 0;
421
422 vnet_lisp_map_register_enable_disable (mp->is_enabled);
423 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
424}
425
426static void
427 vl_api_one_rloc_probe_enable_disable_t_handler
428 (vl_api_one_rloc_probe_enable_disable_t * mp)
429{
430 vl_api_one_rloc_probe_enable_disable_reply_t *rmp;
431 int rv = 0;
432
433 vnet_lisp_rloc_probe_enable_disable (mp->is_enabled);
434 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
435}
436
437static void
438vl_api_one_enable_disable_t_handler (vl_api_one_enable_disable_t * mp)
439{
440 vl_api_one_enable_disable_reply_t *rmp;
441 int rv = 0;
442
443 vnet_lisp_enable_disable (mp->is_en);
444 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
445}
446
447static void
448 vl_api_show_one_map_request_mode_t_handler
449 (vl_api_show_one_map_request_mode_t * mp)
450{
451 int rv = 0;
452 vl_api_show_one_map_request_mode_reply_t *rmp;
453
454 /* *INDENT-OFF* */
455 REPLY_MACRO2(VL_API_SHOW_ONE_MAP_REQUEST_MODE_REPLY,
456 ({
457 rmp->mode = vnet_lisp_get_map_request_mode ();
458 }));
459 /* *INDENT-ON* */
460}
461
462static void
463vl_api_one_map_request_mode_t_handler (vl_api_one_map_request_mode_t * mp)
464{
465 vl_api_one_map_request_mode_reply_t *rmp;
466 int rv = 0;
467
468 rv = vnet_lisp_set_map_request_mode (mp->mode);
469
470 REPLY_MACRO (VL_API_ONE_MAP_REQUEST_MODE_REPLY);
471}
472
473static void
Filip Tehlaref2a5bf2017-05-30 07:14:46 +0200474vl_api_one_nsh_set_locator_set_t_handler (vl_api_one_nsh_set_locator_set_t
475 * mp)
476{
477 vl_api_one_nsh_set_locator_set_reply_t *rmp;
478 int rv = 0;
479 u8 *ls_name = 0;
480
481 ls_name = format (0, "%s", mp->ls_name);
482 rv = vnet_lisp_nsh_set_locator_set (ls_name, mp->is_add);
483 vec_free (ls_name);
484
485 REPLY_MACRO (VL_API_ONE_PITR_SET_LOCATOR_SET_REPLY);
486}
487
488static void
Filip Tehlar694396d2017-02-17 14:29:11 +0100489vl_api_one_pitr_set_locator_set_t_handler (vl_api_one_pitr_set_locator_set_t
490 * mp)
491{
492 vl_api_one_pitr_set_locator_set_reply_t *rmp;
493 int rv = 0;
494 u8 *ls_name = 0;
495
496 ls_name = format (0, "%s", mp->ls_name);
497 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
498 vec_free (ls_name);
499
500 REPLY_MACRO (VL_API_ONE_PITR_SET_LOCATOR_SET_REPLY);
501}
502
503static void
504vl_api_one_use_petr_t_handler (vl_api_one_use_petr_t * mp)
505{
506 vl_api_one_use_petr_reply_t *rmp;
507 int rv = 0;
508 ip_address_t addr;
509
510 ip_address_set (&addr, &mp->address, mp->is_ip4 ? IP4 : IP6);
511 rv = vnet_lisp_use_petr (&addr, mp->is_add);
512
513 REPLY_MACRO (VL_API_ONE_USE_PETR_REPLY);
514}
515
516static void
517vl_api_show_one_use_petr_t_handler (vl_api_show_one_use_petr_t * mp)
518{
519 unix_shared_memory_queue_t *q = NULL;
520 vl_api_show_one_use_petr_reply_t *rmp = NULL;
521 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
522 mapping_t *m;
523 locator_set_t *ls = 0;
524 int rv = 0;
525 locator_t *loc = 0;
526 u8 status = 0;
527 gid_address_t addr;
528
529 q = vl_api_client_index_to_input_queue (mp->client_index);
530 if (q == 0)
531 {
532 return;
533 }
534
535 memset (&addr, 0, sizeof (addr));
536 status = lcm->flags & LISP_FLAG_USE_PETR;
537 if (status)
538 {
539 m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index);
540 if (~0 != m->locator_set_index)
541 {
542 ls =
543 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
544 loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]);
545 gid_address_copy (&addr, &loc->address);
546 }
547 }
548
549 /* *INDENT-OFF* */
550 REPLY_MACRO2 (VL_API_SHOW_ONE_USE_PETR_REPLY,
551 {
Filip Tehlar67a99f82017-03-10 13:18:02 +0100552 rmp->status = status;
553 ip_address_t *ip = &gid_address_ip (&addr);
554 switch (ip_addr_version (ip))
555 {
556 case IP4:
557 clib_memcpy (rmp->address, &ip_addr_v4 (ip),
558 sizeof (ip_addr_v4 (ip)));
559 break;
560
561 case IP6:
562 clib_memcpy (rmp->address, &ip_addr_v6 (ip),
563 sizeof (ip_addr_v6 (ip)));
564 break;
565
566 default:
567 ASSERT (0);
568 }
569 rmp->is_ip4 = (gid_address_ip_version (&addr) == IP4);
Filip Tehlar694396d2017-02-17 14:29:11 +0100570 });
571 /* *INDENT-ON* */
572}
573
574static void
575 vl_api_one_add_del_map_request_itr_rlocs_t_handler
576 (vl_api_one_add_del_map_request_itr_rlocs_t * mp)
577{
578 vl_api_one_add_del_map_request_itr_rlocs_reply_t *rmp;
579 int rv = 0;
580 u8 *locator_set_name = NULL;
581 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
582
583 locator_set_name = format (0, "%s", mp->locator_set_name);
584
585 a->is_add = mp->is_add;
586 a->locator_set_name = locator_set_name;
587
588 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
589
590 vec_free (locator_set_name);
591
592 REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
593}
594
595static void
596 vl_api_one_add_del_remote_mapping_t_handler
597 (vl_api_one_add_del_remote_mapping_t * mp)
598{
599 locator_t *rlocs = 0;
600 vl_api_one_add_del_remote_mapping_reply_t *rmp;
601 int rv = 0;
602 gid_address_t _eid, *eid = &_eid;
603 u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
604
605 memset (eid, 0, sizeof (eid[0]));
606
607 rv = unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
608 mp->eid_type, mp->eid, mp->eid_len);
609 if (rv)
610 goto send_reply;
611
612 rlocs = unformat_one_locs (mp->rlocs, rloc_num);
613
614 if (!mp->is_add)
615 {
616 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
617 gid_address_copy (&a->reid, eid);
618 a->is_add = 0;
619 rv = vnet_lisp_add_del_adjacency (a);
620 if (rv)
621 {
622 goto out;
623 }
624 }
625
626 /* NOTE: for now this works as a static remote mapping, i.e.,
627 * not authoritative and ttl infinite. */
Filip Tehlar809bc742017-08-14 19:15:36 +0200628 if (mp->is_add)
629 {
630 vnet_lisp_add_del_mapping_args_t _m_args, *m_args = &_m_args;
631 memset (m_args, 0, sizeof (m_args[0]));
632 gid_address_copy (&m_args->eid, eid);
633 m_args->action = mp->action;
634 m_args->is_static = 1;
635 m_args->ttl = ~0;
636 m_args->authoritative = 0;
637 rv = vnet_lisp_add_mapping (m_args, rlocs, NULL, NULL);
638 }
639 else
640 rv = vnet_lisp_del_mapping (eid, NULL);
Filip Tehlar694396d2017-02-17 14:29:11 +0100641
642 if (mp->del_all)
643 vnet_lisp_clear_all_remote_adjacencies ();
644
645out:
646 vec_free (rlocs);
647send_reply:
648 REPLY_MACRO (VL_API_ONE_ADD_DEL_REMOTE_MAPPING_REPLY);
649}
650
651static void
652vl_api_one_add_del_adjacency_t_handler (vl_api_one_add_del_adjacency_t * mp)
653{
654 vl_api_one_add_del_adjacency_reply_t *rmp;
655 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
656
657 int rv = 0;
658 memset (a, 0, sizeof (a[0]));
659
660 rv = unformat_one_eid_api (&a->leid, clib_net_to_host_u32 (mp->vni),
661 mp->eid_type, mp->leid, mp->leid_len);
662 rv |= unformat_one_eid_api (&a->reid, clib_net_to_host_u32 (mp->vni),
663 mp->eid_type, mp->reid, mp->reid_len);
664
665 if (rv)
666 goto send_reply;
667
668 a->is_add = mp->is_add;
669 rv = vnet_lisp_add_del_adjacency (a);
670
671send_reply:
672 REPLY_MACRO (VL_API_ONE_ADD_DEL_ADJACENCY_REPLY);
673}
674
675static void
676send_one_locator_details (lisp_cp_main_t * lcm,
677 locator_t * loc,
678 unix_shared_memory_queue_t * q, u32 context)
679{
680 vl_api_one_locator_details_t *rmp;
681
682 rmp = vl_msg_api_alloc (sizeof (*rmp));
683 memset (rmp, 0, sizeof (*rmp));
684 rmp->_vl_msg_id = ntohs (VL_API_ONE_LOCATOR_DETAILS);
685 rmp->context = context;
686
687 rmp->local = loc->local;
688 if (loc->local)
689 {
690 rmp->sw_if_index = ntohl (loc->sw_if_index);
691 }
692 else
693 {
694 rmp->is_ipv6 = gid_address_ip_version (&loc->address);
695 ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
696 }
697 rmp->priority = loc->priority;
698 rmp->weight = loc->weight;
699
700 vl_msg_api_send_shmem (q, (u8 *) & rmp);
701}
702
703static void
704vl_api_one_locator_dump_t_handler (vl_api_one_locator_dump_t * mp)
705{
706 u8 *ls_name = 0;
707 unix_shared_memory_queue_t *q = 0;
708 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
709 locator_set_t *lsit = 0;
710 locator_t *loc = 0;
711 u32 ls_index = ~0, *locit = 0;
712 uword *p = 0;
713
714 q = vl_api_client_index_to_input_queue (mp->client_index);
715 if (q == 0)
716 {
717 return;
718 }
719
720 if (mp->is_index_set)
721 ls_index = htonl (mp->ls_index);
722 else
723 {
724 /* make sure we get a proper C-string */
725 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
726 ls_name = format (0, "%s", mp->ls_name);
727 p = hash_get_mem (lcm->locator_set_index_by_name, ls_name);
728 if (!p)
729 goto out;
730 ls_index = p[0];
731 }
732
733 if (pool_is_free_index (lcm->locator_set_pool, ls_index))
734 return;
735
736 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
737
738 vec_foreach (locit, lsit->locator_indices)
739 {
740 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
741 send_one_locator_details (lcm, loc, q, mp->context);
742 };
743out:
744 vec_free (ls_name);
745}
746
747static void
748send_one_locator_set_details (lisp_cp_main_t * lcm,
749 locator_set_t * lsit,
750 unix_shared_memory_queue_t * q,
751 u32 context, u32 ls_index)
752{
753 vl_api_one_locator_set_details_t *rmp;
754 u8 *str = 0;
755
756 rmp = vl_msg_api_alloc (sizeof (*rmp));
757 memset (rmp, 0, sizeof (*rmp));
758 rmp->_vl_msg_id = ntohs (VL_API_ONE_LOCATOR_SET_DETAILS);
759 rmp->context = context;
760
761 rmp->ls_index = htonl (ls_index);
762 if (lsit->local)
763 {
764 ASSERT (lsit->name != NULL);
765 strncpy ((char *) rmp->ls_name, (char *) lsit->name,
766 vec_len (lsit->name));
767 }
768 else
769 {
770 str = format (0, "<remote-%d>", ls_index);
771 strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str));
772 vec_free (str);
773 }
774
775 vl_msg_api_send_shmem (q, (u8 *) & rmp);
776}
777
778static void
779vl_api_one_locator_set_dump_t_handler (vl_api_one_locator_set_dump_t * mp)
780{
781 unix_shared_memory_queue_t *q = NULL;
782 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
783 locator_set_t *lsit = NULL;
784 u8 filter;
785
786 q = vl_api_client_index_to_input_queue (mp->client_index);
787 if (q == 0)
788 {
789 return;
790 }
791
792 filter = mp->filter;
793 /* *INDENT-OFF* */
794 pool_foreach (lsit, lcm->locator_set_pool,
795 ({
796 if (filter && !((1 == filter && lsit->local) ||
797 (2 == filter && !lsit->local)))
798 {
799 continue;
800 }
801 send_one_locator_set_details (lcm, lsit, q, mp->context,
802 lsit - lcm->locator_set_pool);
803 }));
804 /* *INDENT-ON* */
805}
806
807static void
808one_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length)
809{
810 ASSERT (prefix_length);
811 ip_prefix_t *ippref = &fid_addr_ippref (src);
812
813 switch (fid_addr_type (src))
814 {
815 case FID_ADDR_IP_PREF:
816 if (ip_prefix_version (ippref) == IP4)
817 clib_memcpy (dst, &ip_prefix_v4 (ippref), 4);
818 else
819 clib_memcpy (dst, &ip_prefix_v6 (ippref), 16);
820 prefix_length[0] = ip_prefix_len (ippref);
821 break;
822
823 case FID_ADDR_MAC:
824 prefix_length[0] = 0;
825 clib_memcpy (dst, fid_addr_mac (src), 6);
826 break;
827
828 default:
829 clib_warning ("Unknown FID type %d!", fid_addr_type (src));
830 break;
831 }
832}
833
834static u8
835fid_type_to_api_type (fid_address_t * fid)
836{
837 ip_prefix_t *ippref;
838
839 switch (fid_addr_type (fid))
840 {
841 case FID_ADDR_IP_PREF:
842 ippref = &fid_addr_ippref (fid);
843 if (ip_prefix_version (ippref) == IP4)
844 return 0;
845 else if (ip_prefix_version (ippref) == IP6)
846 return 1;
847 else
848 return ~0;
849
850 case FID_ADDR_MAC:
851 return 2;
852 case FID_ADDR_NSH:
853 return 3;
854 }
855
856 return ~0;
857}
858
859static void
860send_one_eid_table_details (mapping_t * mapit,
861 unix_shared_memory_queue_t * q,
862 u32 context, u8 filter)
863{
864 fid_address_t *fid;
865 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
866 locator_set_t *ls = 0;
867 vl_api_one_eid_table_details_t *rmp = NULL;
868 gid_address_t *gid = NULL;
869 u8 *mac = 0;
870 ip_prefix_t *ip_prefix = NULL;
871
Filip Tehlaref2a5bf2017-05-30 07:14:46 +0200872 if (mapit->pitr_set || mapit->nsh_set)
Filip Tehlar1e8d01f2017-03-30 15:17:01 +0200873 return;
874
Filip Tehlar694396d2017-02-17 14:29:11 +0100875 switch (filter)
876 {
877 case 0: /* all mappings */
878 break;
879
880 case 1: /* local only */
881 if (!mapit->local)
882 return;
883 break;
884 case 2: /* remote only */
885 if (mapit->local)
886 return;
887 break;
888 default:
889 clib_warning ("Filter error, unknown filter: %d", filter);
890 return;
891 }
892
893 gid = &mapit->eid;
894 ip_prefix = &gid_address_ippref (gid);
895 mac = gid_address_mac (gid);
896
897 rmp = vl_msg_api_alloc (sizeof (*rmp));
898 memset (rmp, 0, sizeof (*rmp));
899 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_DETAILS);
900
901 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
902 if (vec_len (ls->locator_indices) == 0)
903 rmp->locator_set_index = ~0;
904 else
905 rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
906
907 rmp->is_local = mapit->local;
908 rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
909 rmp->action = mapit->action;
910 rmp->authoritative = mapit->authoritative;
911
912 switch (gid_address_type (gid))
913 {
914 case GID_ADDR_SRC_DST:
915 rmp->is_src_dst = 1;
916 fid = &gid_address_sd_src (gid);
917 rmp->eid_type = fid_type_to_api_type (fid);
918 one_fid_put_api (rmp->seid, &gid_address_sd_src (gid),
919 &rmp->seid_prefix_len);
920 one_fid_put_api (rmp->eid, &gid_address_sd_dst (gid),
921 &rmp->eid_prefix_len);
922 break;
923 case GID_ADDR_IP_PREFIX:
924 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
925 if (ip_prefix_version (ip_prefix) == IP4)
926 {
927 rmp->eid_type = 0; /* ipv4 type */
928 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
929 sizeof (ip_prefix_v4 (ip_prefix)));
930 }
931 else
932 {
933 rmp->eid_type = 1; /* ipv6 type */
934 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
935 sizeof (ip_prefix_v6 (ip_prefix)));
936 }
937 break;
938 case GID_ADDR_MAC:
939 rmp->eid_type = 2; /* l2 mac type */
940 clib_memcpy (rmp->eid, mac, 6);
941 break;
Filip Tehlaref2a5bf2017-05-30 07:14:46 +0200942 case GID_ADDR_NSH:
943 rmp->eid_type = 3; /* NSH type */
944 lisp_nsh_api_t nsh;
945 nsh.spi = clib_host_to_net_u32 (gid_address_nsh_spi (gid));
946 nsh.si = gid_address_nsh_si (gid);
947 clib_memcpy (rmp->eid, &nsh, sizeof (nsh));
948 break;
Filip Tehlar694396d2017-02-17 14:29:11 +0100949 default:
950 ASSERT (0);
951 }
952 rmp->context = context;
953 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
954 rmp->key_id = clib_host_to_net_u16 (mapit->key_id);
955 memcpy (rmp->key, mapit->key, vec_len (mapit->key));
956 vl_msg_api_send_shmem (q, (u8 *) & rmp);
957}
958
959static void
960vl_api_one_eid_table_dump_t_handler (vl_api_one_eid_table_dump_t * mp)
961{
962 u32 mi;
963 unix_shared_memory_queue_t *q = NULL;
964 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
965 mapping_t *mapit = NULL;
966 gid_address_t _eid, *eid = &_eid;
967
968 q = vl_api_client_index_to_input_queue (mp->client_index);
969 if (q == 0)
970 {
971 return;
972 }
973
974 if (mp->eid_set)
975 {
976 memset (eid, 0, sizeof (*eid));
977
978 unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
979 mp->eid_type, mp->eid, mp->prefix_length);
980
981 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
982 if ((u32) ~ 0 == mi)
983 return;
984
985 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
986 send_one_eid_table_details (mapit, q, mp->context,
987 0 /* ignore filter */ );
988 }
989 else
990 {
991 /* *INDENT-OFF* */
992 pool_foreach (mapit, lcm->mapping_pool,
993 ({
994 send_one_eid_table_details(mapit, q, mp->context,
995 mp->filter);
996 }));
997 /* *INDENT-ON* */
998 }
999}
1000
1001static void
1002send_one_map_server_details (ip_address_t * ip,
1003 unix_shared_memory_queue_t * q, u32 context)
1004{
1005 vl_api_one_map_server_details_t *rmp = NULL;
1006
1007 rmp = vl_msg_api_alloc (sizeof (*rmp));
1008 memset (rmp, 0, sizeof (*rmp));
1009 rmp->_vl_msg_id = ntohs (VL_API_ONE_MAP_SERVER_DETAILS);
1010
1011 switch (ip_addr_version (ip))
1012 {
1013 case IP4:
1014 rmp->is_ipv6 = 0;
1015 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
1016 sizeof (ip_addr_v4 (ip)));
1017 break;
1018
1019 case IP6:
1020 rmp->is_ipv6 = 1;
1021 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
1022 sizeof (ip_addr_v6 (ip)));
1023 break;
1024
1025 default:
1026 ASSERT (0);
1027 }
1028 rmp->context = context;
1029
1030 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1031}
1032
1033static void
1034vl_api_one_map_server_dump_t_handler (vl_api_one_map_server_dump_t * mp)
1035{
1036 unix_shared_memory_queue_t *q = NULL;
1037 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1038 lisp_msmr_t *mr;
1039
1040 q = vl_api_client_index_to_input_queue (mp->client_index);
1041 if (q == 0)
1042 {
1043 return;
1044 }
1045
1046 vec_foreach (mr, lcm->map_servers)
1047 {
1048 send_one_map_server_details (&mr->address, q, mp->context);
1049 }
1050}
1051
1052static void
1053send_one_map_resolver_details (ip_address_t * ip,
1054 unix_shared_memory_queue_t * q, u32 context)
1055{
1056 vl_api_one_map_resolver_details_t *rmp = NULL;
1057
1058 rmp = vl_msg_api_alloc (sizeof (*rmp));
1059 memset (rmp, 0, sizeof (*rmp));
1060 rmp->_vl_msg_id = ntohs (VL_API_ONE_MAP_RESOLVER_DETAILS);
1061
1062 switch (ip_addr_version (ip))
1063 {
1064 case IP4:
1065 rmp->is_ipv6 = 0;
1066 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
1067 sizeof (ip_addr_v4 (ip)));
1068 break;
1069
1070 case IP6:
1071 rmp->is_ipv6 = 1;
1072 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
1073 sizeof (ip_addr_v6 (ip)));
1074 break;
1075
1076 default:
1077 ASSERT (0);
1078 }
1079 rmp->context = context;
1080
1081 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1082}
1083
1084static void
1085vl_api_one_map_resolver_dump_t_handler (vl_api_one_map_resolver_dump_t * mp)
1086{
1087 unix_shared_memory_queue_t *q = NULL;
1088 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1089 lisp_msmr_t *mr;
1090
1091 q = vl_api_client_index_to_input_queue (mp->client_index);
1092 if (q == 0)
1093 {
1094 return;
1095 }
1096
1097 vec_foreach (mr, lcm->map_resolvers)
1098 {
1099 send_one_map_resolver_details (&mr->address, q, mp->context);
1100 }
1101}
1102
1103static void
1104send_eid_table_map_pair (hash_pair_t * p,
1105 unix_shared_memory_queue_t * q, u32 context)
1106{
1107 vl_api_one_eid_table_map_details_t *rmp = NULL;
1108
1109 rmp = vl_msg_api_alloc (sizeof (*rmp));
1110 memset (rmp, 0, sizeof (*rmp));
1111 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_MAP_DETAILS);
1112
1113 rmp->vni = clib_host_to_net_u32 (p->key);
1114 rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
1115 rmp->context = context;
1116 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1117}
1118
1119static void
1120vl_api_one_eid_table_map_dump_t_handler (vl_api_one_eid_table_map_dump_t * mp)
1121{
1122 unix_shared_memory_queue_t *q = NULL;
1123 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1124 hash_pair_t *p;
1125 uword *vni_table = 0;
1126
1127 q = vl_api_client_index_to_input_queue (mp->client_index);
1128 if (q == 0)
1129 {
1130 return;
1131 }
1132
1133 if (mp->is_l2)
1134 {
1135 vni_table = lcm->bd_id_by_vni;
1136 }
1137 else
1138 {
1139 vni_table = lcm->table_id_by_vni;
1140 }
1141
1142 /* *INDENT-OFF* */
1143 hash_foreach_pair (p, vni_table,
1144 ({
1145 send_eid_table_map_pair (p, q, mp->context);
1146 }));
1147 /* *INDENT-ON* */
1148}
1149
1150static void
1151send_eid_table_vni (u32 vni, unix_shared_memory_queue_t * q, u32 context)
1152{
1153 vl_api_one_eid_table_vni_details_t *rmp = 0;
1154
1155 rmp = vl_msg_api_alloc (sizeof (*rmp));
1156 memset (rmp, 0, sizeof (*rmp));
1157 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_VNI_DETAILS);
1158 rmp->context = context;
1159 rmp->vni = clib_host_to_net_u32 (vni);
1160 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1161}
1162
1163static void
1164one_adjacency_copy (vl_api_one_adjacency_t * dst, lisp_adjacency_t * adjs)
1165{
1166 lisp_adjacency_t *adj;
1167 vl_api_one_adjacency_t a;
1168 u32 i, n = vec_len (adjs);
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02001169 lisp_nsh_api_t nsh;
Filip Tehlar694396d2017-02-17 14:29:11 +01001170
1171 for (i = 0; i < n; i++)
1172 {
1173 adj = vec_elt_at_index (adjs, i);
1174 memset (&a, 0, sizeof (a));
1175
1176 switch (gid_address_type (&adj->reid))
1177 {
1178 case GID_ADDR_IP_PREFIX:
1179 a.reid_prefix_len = gid_address_ippref_len (&adj->reid);
1180 a.leid_prefix_len = gid_address_ippref_len (&adj->leid);
1181 if (gid_address_ip_version (&adj->reid) == IP4)
1182 {
1183 a.eid_type = 0; /* ipv4 type */
1184 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 4);
1185 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 4);
1186 }
1187 else
1188 {
1189 a.eid_type = 1; /* ipv6 type */
1190 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 16);
1191 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 16);
1192 }
1193 break;
1194 case GID_ADDR_MAC:
1195 a.eid_type = 2; /* l2 mac type */
1196 mac_copy (a.reid, gid_address_mac (&adj->reid));
1197 mac_copy (a.leid, gid_address_mac (&adj->leid));
1198 break;
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02001199 case GID_ADDR_NSH:
1200 a.eid_type = 3; /* NSH type */
1201 nsh.spi = clib_host_to_net_u32 (gid_address_nsh_spi (&adj->reid));
1202 nsh.si = gid_address_nsh_si (&adj->reid);
1203 clib_memcpy (a.reid, &nsh, sizeof (nsh));
1204
1205 nsh.spi = clib_host_to_net_u32 (gid_address_nsh_spi (&adj->leid));
1206 nsh.si = gid_address_nsh_si (&adj->leid);
1207 clib_memcpy (a.leid, &nsh, sizeof (nsh));
Filip Tehlarb8633d22017-06-09 15:25:57 +02001208 break;
Filip Tehlar694396d2017-02-17 14:29:11 +01001209 default:
1210 ASSERT (0);
1211 }
1212 dst[i] = a;
1213 }
1214}
1215
1216static void
1217 vl_api_show_one_rloc_probe_state_t_handler
1218 (vl_api_show_one_rloc_probe_state_t * mp)
1219{
1220 vl_api_show_one_rloc_probe_state_reply_t *rmp = 0;
1221 int rv = 0;
1222
1223 /* *INDENT-OFF* */
1224 REPLY_MACRO2 (VL_API_SHOW_ONE_RLOC_PROBE_STATE_REPLY,
1225 {
1226 rmp->is_enabled = vnet_lisp_rloc_probe_state_get ();
1227 });
1228 /* *INDENT-ON* */
1229}
1230
1231static void
1232 vl_api_show_one_map_register_state_t_handler
1233 (vl_api_show_one_map_register_state_t * mp)
1234{
1235 vl_api_show_one_map_register_state_reply_t *rmp = 0;
1236 int rv = 0;
1237
1238 /* *INDENT-OFF* */
1239 REPLY_MACRO2 (VL_API_SHOW_ONE_MAP_REGISTER_STATE_REPLY,
1240 {
1241 rmp->is_enabled = vnet_lisp_map_register_state_get ();
1242 });
1243 /* *INDENT-ON* */
1244}
1245
1246static void
1247vl_api_one_adjacencies_get_t_handler (vl_api_one_adjacencies_get_t * mp)
1248{
1249 vl_api_one_adjacencies_get_reply_t *rmp = 0;
1250 lisp_adjacency_t *adjs = 0;
1251 int rv = 0;
1252 u32 size = ~0;
1253 u32 vni = clib_net_to_host_u32 (mp->vni);
1254
1255 adjs = vnet_lisp_adjacencies_get_by_vni (vni);
1256 size = vec_len (adjs) * sizeof (vl_api_one_adjacency_t);
1257
1258 /* *INDENT-OFF* */
1259 REPLY_MACRO4 (VL_API_ONE_ADJACENCIES_GET_REPLY, size,
1260 {
1261 rmp->count = clib_host_to_net_u32 (vec_len (adjs));
1262 one_adjacency_copy (rmp->adjacencies, adjs);
1263 });
1264 /* *INDENT-ON* */
1265
1266 vec_free (adjs);
1267}
1268
1269static void
1270vl_api_one_eid_table_vni_dump_t_handler (vl_api_one_eid_table_vni_dump_t * mp)
1271{
1272 hash_pair_t *p;
1273 u32 *vnis = 0;
1274 unix_shared_memory_queue_t *q = 0;
1275 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1276
1277 q = vl_api_client_index_to_input_queue (mp->client_index);
1278 if (q == 0)
1279 {
1280 return;
1281 }
1282
1283 /* *INDENT-OFF* */
1284 hash_foreach_pair (p, lcm->table_id_by_vni,
1285 ({
1286 hash_set (vnis, p->key, 0);
1287 }));
1288
1289 hash_foreach_pair (p, lcm->bd_id_by_vni,
1290 ({
1291 hash_set (vnis, p->key, 0);
1292 }));
1293
1294 hash_foreach_pair (p, vnis,
1295 ({
1296 send_eid_table_vni (p->key, q, mp->context);
1297 }));
1298 /* *INDENT-ON* */
1299
1300 hash_free (vnis);
1301}
1302
1303static void
1304vl_api_show_one_status_t_handler (vl_api_show_one_status_t * mp)
1305{
1306 unix_shared_memory_queue_t *q = NULL;
1307 vl_api_show_one_status_reply_t *rmp = NULL;
1308 int rv = 0;
1309
1310 q = vl_api_client_index_to_input_queue (mp->client_index);
1311 if (q == 0)
1312 {
1313 return;
1314 }
1315
1316 /* *INDENT-OFF* */
1317 REPLY_MACRO2(VL_API_SHOW_ONE_STATUS_REPLY,
1318 ({
1319 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
1320 rmp->feature_status = vnet_lisp_enable_disable_status ();
1321 }));
1322 /* *INDENT-ON* */
1323}
1324
1325static void
1326 vl_api_one_get_map_request_itr_rlocs_t_handler
1327 (vl_api_one_get_map_request_itr_rlocs_t * mp)
1328{
1329 unix_shared_memory_queue_t *q = NULL;
1330 vl_api_one_get_map_request_itr_rlocs_reply_t *rmp = NULL;
1331 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1332 locator_set_t *loc_set = 0;
1333 u8 *tmp_str = 0;
1334 int rv = 0;
1335
1336 q = vl_api_client_index_to_input_queue (mp->client_index);
1337 if (q == 0)
1338 {
1339 return;
1340 }
1341
1342 if (~0 == lcm->mreq_itr_rlocs)
1343 {
1344 tmp_str = format (0, " ");
1345 }
1346 else
1347 {
1348 loc_set =
1349 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
1350 tmp_str = format (0, "%s", loc_set->name);
1351 }
1352
1353 /* *INDENT-OFF* */
1354 REPLY_MACRO2(VL_API_ONE_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
1355 ({
1356 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1357 ARRAY_LEN(rmp->locator_set_name) - 1);
1358 }));
1359 /* *INDENT-ON* */
1360
1361 vec_free (tmp_str);
1362}
1363
1364static void
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02001365vl_api_show_one_nsh_mapping_t_handler (vl_api_show_one_nsh_mapping_t * mp)
1366{
1367 unix_shared_memory_queue_t *q = NULL;
1368 vl_api_show_one_nsh_mapping_reply_t *rmp = NULL;
1369 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1370 mapping_t *m;
1371 locator_set_t *ls = 0;
1372 u8 *tmp_str = 0;
1373 u8 is_set = 0;
1374 int rv = 0;
1375
1376 q = vl_api_client_index_to_input_queue (mp->client_index);
1377 if (q == 0)
1378 {
1379 return;
1380 }
1381
1382 if (lcm->nsh_map_index == (u32) ~ 0)
1383 {
1384 tmp_str = format (0, "N/A");
1385 }
1386 else
1387 {
1388 m = pool_elt_at_index (lcm->mapping_pool, lcm->nsh_map_index);
1389 if (~0 != m->locator_set_index)
1390 {
1391 ls =
1392 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
1393 tmp_str = format (0, "%s", ls->name);
1394 is_set = 1;
1395 }
1396 else
1397 {
1398 tmp_str = format (0, "N/A");
1399 }
1400 }
1401 vec_add1 (tmp_str, 0);
1402
1403 /* *INDENT-OFF* */
1404 REPLY_MACRO2(VL_API_SHOW_ONE_NSH_MAPPING_REPLY,
1405 ({
1406 rmp->is_set = is_set;
1407 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1408 ARRAY_LEN(rmp->locator_set_name) - 1);
1409 }));
1410 /* *INDENT-ON* */
1411}
1412
1413static void
Filip Tehlar694396d2017-02-17 14:29:11 +01001414vl_api_show_one_pitr_t_handler (vl_api_show_one_pitr_t * mp)
1415{
1416 unix_shared_memory_queue_t *q = NULL;
1417 vl_api_show_one_pitr_reply_t *rmp = NULL;
1418 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1419 mapping_t *m;
1420 locator_set_t *ls = 0;
1421 u8 *tmp_str = 0;
1422 int rv = 0;
1423
1424 q = vl_api_client_index_to_input_queue (mp->client_index);
1425 if (q == 0)
1426 {
1427 return;
1428 }
1429
1430 if (!lcm->lisp_pitr)
1431 {
1432 tmp_str = format (0, "N/A");
1433 }
1434 else
1435 {
1436 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
1437 if (~0 != m->locator_set_index)
1438 {
1439 ls =
1440 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
1441 tmp_str = format (0, "%s", ls->name);
1442 }
1443 else
1444 {
1445 tmp_str = format (0, "N/A");
1446 }
1447 }
1448 vec_add1 (tmp_str, 0);
1449
1450 /* *INDENT-OFF* */
1451 REPLY_MACRO2(VL_API_SHOW_ONE_PITR_REPLY,
1452 ({
1453 rmp->status = lcm->lisp_pitr;
1454 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1455 ARRAY_LEN(rmp->locator_set_name) - 1);
1456 }));
1457 /* *INDENT-ON* */
1458}
1459
Filip Tehlar7eaf0e52017-03-08 08:46:51 +01001460static void
1461 vl_api_show_one_stats_enable_disable_t_handler
1462 (vl_api_show_one_stats_enable_disable_t * mp)
1463{
1464 vl_api_show_one_stats_enable_disable_reply_t *rmp = NULL;
1465 vnet_api_error_t rv = 0;
1466
1467 /* *INDENT-OFF* */
1468 REPLY_MACRO2 (VL_API_SHOW_ONE_STATS_ENABLE_DISABLE_REPLY,
1469 ({
1470 rmp->is_en = vnet_lisp_stats_enable_disable_state ();
1471 }));
1472 /* *INDENT-ON* */
1473}
1474
1475static void
1476 vl_api_one_stats_enable_disable_t_handler
1477 (vl_api_one_stats_enable_disable_t * mp)
1478{
1479 vl_api_one_enable_disable_reply_t *rmp = NULL;
1480
1481 vnet_api_error_t rv = vnet_lisp_stats_enable_disable (mp->is_en);
1482 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
1483}
1484
1485static void
Filip Tehlar4868ff62017-03-09 16:48:39 +01001486lisp_fid_addr_to_api (fid_address_t * fid, u8 * dst, u8 * api_eid_type,
1487 u8 * prefix_length)
1488{
1489 switch (fid_addr_type (fid))
1490 {
1491 case FID_ADDR_IP_PREF:
1492 *prefix_length = fid_addr_prefix_length (fid);
1493 if (fid_addr_ip_version (fid) == IP4)
1494 {
1495 *api_eid_type = 0; /* ipv4 type */
1496 clib_memcpy (dst, &fid_addr_ippref (fid), 4);
1497 }
1498 else
1499 {
1500 *api_eid_type = 1; /* ipv6 type */
1501 clib_memcpy (dst, &fid_addr_ippref (fid), 16);
1502 }
1503 break;
1504 case FID_ADDR_MAC:
1505 *api_eid_type = 2; /* l2 mac type */
1506 mac_copy (dst, fid_addr_mac (fid));
1507 break;
1508 default:
1509 ASSERT (0);
1510 }
1511}
1512
1513static void
Filip Tehlar21511912017-04-07 10:41:42 +02001514vl_api_one_stats_flush_t_handler (vl_api_one_stats_flush_t * mp)
1515{
1516 vl_api_one_stats_flush_reply_t *rmp;
1517 u8 rv;
1518
1519 rv = vnet_lisp_flush_stats ();
1520 REPLY_MACRO (VL_API_ONE_STATS_FLUSH_REPLY);
1521}
1522
1523static void
Filip Tehlar7eaf0e52017-03-08 08:46:51 +01001524vl_api_one_stats_dump_t_handler (vl_api_one_stats_dump_t * mp)
1525{
Filip Tehlar4868ff62017-03-09 16:48:39 +01001526 vl_api_one_stats_details_t *rmp;
1527 lisp_api_stats_t *stats, *stat;
1528 u8 rv = 0;
Filip Tehlar7eaf0e52017-03-08 08:46:51 +01001529
Filip Tehlar4868ff62017-03-09 16:48:39 +01001530 stats = vnet_lisp_get_stats ();
1531 vec_foreach (stat, stats)
1532 {
1533 /* *INDENT-OFF* */
1534 REPLY_DETAILS (VL_API_ONE_STATS_DETAILS,
1535 ({
1536 lisp_fid_addr_to_api (&stat->deid, rmp->deid, &rmp->eid_type,
1537 &rmp->deid_pref_len);
1538 lisp_fid_addr_to_api (&stat->seid, rmp->seid, &rmp->eid_type,
1539 &rmp->seid_pref_len);
1540 rmp->vni = clib_host_to_net_u32 (stat->vni);
1541
1542 rmp->is_ip4 = ip_addr_version (&stat->rmt_rloc) == IP4 ? 1 : 0;
1543 ip_address_copy_addr (rmp->rloc, &stat->rmt_rloc);
1544 ip_address_copy_addr (rmp->lloc, &stat->loc_rloc);
1545
Filip Tehlar21511912017-04-07 10:41:42 +02001546 rmp->pkt_count = clib_host_to_net_u32 (stat->counters.packets);
1547 rmp->bytes = clib_host_to_net_u32 (stat->counters.bytes);
Filip Tehlar4868ff62017-03-09 16:48:39 +01001548 }));
1549 /* *INDENT-ON* */
1550 }
Filip Tehlar7eaf0e52017-03-08 08:46:51 +01001551}
1552
Filip Tehlard5a65db2017-05-17 17:21:10 +02001553static void
1554 vl_api_one_add_del_l2_arp_entry_t_handler
1555 (vl_api_one_add_del_l2_arp_entry_t * mp)
1556{
1557 vl_api_one_add_del_l2_arp_entry_reply_t *rmp;
1558 int rv = 0;
1559 gid_address_t _arp, *arp = &_arp;
1560 memset (arp, 0, sizeof (*arp));
1561
1562 gid_address_type (arp) = GID_ADDR_ARP;
1563 gid_address_arp_bd (arp) = clib_net_to_host_u32 (mp->bd);
1564
1565 /* vpp keeps ip4 addresses in network byte order */
1566 clib_memcpy (&gid_address_arp_ip4 (arp), &mp->ip4, 4);
1567
1568 rv = vnet_lisp_add_del_l2_arp_entry (arp, mp->mac, mp->is_add);
1569
1570 REPLY_MACRO (VL_API_ONE_ADD_DEL_L2_ARP_ENTRY_REPLY);
1571}
1572
1573static void
1574vl_api_one_l2_arp_bd_get_t_handler (vl_api_one_l2_arp_bd_get_t * mp)
1575{
1576 vl_api_one_l2_arp_bd_get_reply_t *rmp;
1577 int rv = 0;
1578 u32 i = 0;
1579 hash_pair_t *p;
1580
1581 u32 *bds = vnet_lisp_l2_arp_bds_get ();
1582 u32 size = hash_elts (bds) * sizeof (u32);
1583
1584 /* *INDENT-OFF* */
1585 REPLY_MACRO4 (VL_API_ONE_L2_ARP_BD_GET_REPLY, size,
1586 {
1587 rmp->count = clib_host_to_net_u32 (hash_elts (bds));
1588 hash_foreach_pair (p, bds,
1589 ({
1590 rmp->bridge_domains[i++] = clib_host_to_net_u32 (p->key);
1591 }));
1592 });
1593 /* *INDENT-ON* */
1594
1595 hash_free (bds);
1596}
1597
1598static void
1599vl_api_one_l2_arp_entries_get_t_handler (vl_api_one_l2_arp_entries_get_t * mp)
1600{
1601 vl_api_one_l2_arp_entries_get_reply_t *rmp;
1602 lisp_api_l2_arp_entry_t *entries = 0, *e;
1603 u32 i = 0;
1604 int rv = 0;
1605
1606 u32 bd = clib_net_to_host_u32 (mp->bd);
1607
1608 entries = vnet_lisp_l2_arp_entries_get_by_bd (bd);
Ole Troan1d7d2ab2017-07-06 14:25:38 +02001609 u32 size = vec_len (entries) * sizeof (vl_api_one_l2_arp_entry_t);
Filip Tehlard5a65db2017-05-17 17:21:10 +02001610
1611 /* *INDENT-OFF* */
1612 REPLY_MACRO4 (VL_API_ONE_L2_ARP_ENTRIES_GET_REPLY, size,
1613 {
1614 rmp->count = clib_host_to_net_u32 (vec_len (entries));
1615 vec_foreach (e, entries)
1616 {
1617 mac_copy (rmp->entries[i].mac, e->mac);
1618 rmp->entries[i].ip4 = e->ip4;
1619 i++;
1620 }
1621 });
1622 /* *INDENT-ON* */
1623
1624 vec_free (entries);
1625}
1626
Filip Tehlar7048ff12017-07-27 08:09:14 +02001627static void
1628 vl_api_one_map_register_fallback_threshold_t_handler
1629 (vl_api_one_map_register_fallback_threshold_t * mp)
1630{
1631 vl_api_one_map_register_fallback_threshold_reply_t *rmp;
1632 int rv = 0;
1633
1634 mp->value = clib_net_to_host_u32 (mp->value);
1635 rv = vnet_lisp_map_register_fallback_threshold_set (mp->value);
Filip Tehlar6f9f6f32017-08-08 13:11:22 +02001636 REPLY_MACRO (VL_API_ONE_MAP_REGISTER_FALLBACK_THRESHOLD_REPLY);
Filip Tehlar7048ff12017-07-27 08:09:14 +02001637}
1638
1639static void
1640 vl_api_show_one_map_register_fallback_threshold_t_handler
1641 (vl_api_show_one_map_register_fallback_threshold_t * mp)
1642{
1643 vl_api_show_one_map_register_fallback_threshold_reply_t *rmp;
1644 int rv = 0;
1645
1646 u32 value = vnet_lisp_map_register_fallback_threshold_get ();
1647
1648 /* *INDENT-OFF* */
1649 REPLY_MACRO2 (VL_API_SHOW_ONE_MAP_REGISTER_FALLBACK_THRESHOLD_REPLY,
1650 ({
1651 rmp->value = clib_host_to_net_u32 (value);
1652 }));
1653 /* *INDENT-ON* */
1654}
1655
Filip Tehlar694396d2017-02-17 14:29:11 +01001656/*
1657 * one_api_hookup
1658 * Add vpe's API message handlers to the table.
1659 * vlib has alread mapped shared memory and
1660 * added the client registration handlers.
1661 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
1662 */
1663#define vl_msg_name_crc_list
1664#include <vnet/vnet_all_api_h.h>
1665#undef vl_msg_name_crc_list
1666
1667static void
1668setup_message_id_table (api_main_t * am)
1669{
1670#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
Filip Tehlar974cdc62017-02-22 18:09:49 +01001671 foreach_vl_msg_name_crc_one;
Filip Tehlar694396d2017-02-17 14:29:11 +01001672#undef _
1673}
1674
1675static clib_error_t *
1676one_api_hookup (vlib_main_t * vm)
1677{
1678 api_main_t *am = &api_main;
1679
1680#define _(N,n) \
1681 vl_msg_api_set_handlers(VL_API_##N, #n, \
1682 vl_api_##n##_t_handler, \
1683 vl_noop_handler, \
1684 vl_api_##n##_t_endian, \
1685 vl_api_##n##_t_print, \
1686 sizeof(vl_api_##n##_t), 1);
1687 foreach_vpe_api_msg;
1688#undef _
1689
1690 /*
1691 * Set up the (msg_name, crc, message-id) table
1692 */
1693 setup_message_id_table (am);
1694
1695 return 0;
1696}
1697
1698VLIB_API_INIT_FUNCTION (one_api_hookup);
1699
1700/*
1701 * fd.io coding-style-patch-verification: ON
1702 *
1703 * Local Variables:
1704 * eval: (c-set-style "gnu")
1705 * End:
1706 */