blob: 85c5d7e19452712492e6f934135b52fbd9a60ff0 [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
Florin Coras6c4dae22018-01-09 06:39:23 -080071#define REPLY_DETAILS(t, body) \
72do { \
73 vl_api_registration_t * reg; \
74 rv = vl_msg_api_pd_handler (mp, rv); \
75 reg = vl_api_client_index_to_registration (mp->client_index); \
76 if (!reg) \
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_api_send_msg (reg, (u8 *)&rmp); \
Filip Tehlar4868ff62017-03-09 16:48:39 +010084} while(0);
85
Florin Coras6c4dae22018-01-09 06:39:23 -080086#define foreach_vpe_api_msg \
Filip Tehlar694396d2017-02-17 14:29:11 +010087_(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 Tehlar05879992017-09-05 15:46:09 +0200133_(ONE_ADD_DEL_NDP_ENTRY, one_add_del_ndp_entry) \
134_(ONE_NDP_BD_GET, one_ndp_bd_get) \
135_(ONE_NDP_ENTRIES_GET, one_ndp_entries_get) \
Filip Tehlara4980b82017-09-27 14:32:02 +0200136_(ONE_SET_TRANSPORT_PROTOCOL, one_set_transport_protocol) \
Filip Tehlar0a8840d2017-10-16 05:48:23 -0700137_(ONE_GET_TRANSPORT_PROTOCOL, one_get_transport_protocol) \
138_(ONE_ENABLE_DISABLE_XTR_MODE, one_enable_disable_xtr_mode) \
139_(ONE_SHOW_XTR_MODE, one_show_xtr_mode) \
140_(ONE_ENABLE_DISABLE_PITR_MODE, one_enable_disable_pitr_mode) \
141_(ONE_SHOW_PITR_MODE, one_show_pitr_mode) \
142_(ONE_ENABLE_DISABLE_PETR_MODE, one_enable_disable_petr_mode) \
143_(ONE_SHOW_PETR_MODE, one_show_petr_mode) \
144
Filip Tehlar694396d2017-02-17 14:29:11 +0100145
146static locator_t *
Filip Tehlar974cdc62017-02-22 18:09:49 +0100147unformat_one_locs (vl_api_one_remote_locator_t * rmt_locs, u32 rloc_num)
Filip Tehlar694396d2017-02-17 14:29:11 +0100148{
149 u32 i;
150 locator_t *locs = 0, loc;
Filip Tehlar974cdc62017-02-22 18:09:49 +0100151 vl_api_one_remote_locator_t *r;
Filip Tehlar694396d2017-02-17 14:29:11 +0100152
153 for (i = 0; i < rloc_num; i++)
154 {
155 /* remote locators */
156 r = &rmt_locs[i];
157 memset (&loc, 0, sizeof (loc));
158 gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
159
160 loc.priority = r->priority;
161 loc.weight = r->weight;
162
163 vec_add1 (locs, loc);
164 }
165 return locs;
166}
167
168static void
Filip Tehlar1e553a02017-08-02 12:45:07 +0200169vl_api_one_map_register_set_ttl_t_handler (vl_api_one_map_register_set_ttl_t *
170 mp)
171{
172 vl_api_one_map_register_set_ttl_reply_t *rmp;
173 int rv = 0;
174
Filip Tehlar5391e192017-08-04 09:13:50 +0200175 mp->ttl = clib_net_to_host_u32 (mp->ttl);
Filip Tehlar1e553a02017-08-02 12:45:07 +0200176 rv = vnet_lisp_map_register_set_ttl (mp->ttl);
177
178 REPLY_MACRO (VL_API_ONE_MAP_REGISTER_SET_TTL_REPLY);
179}
180
181static void
182 vl_api_show_one_map_register_ttl_t_handler
183 (vl_api_show_one_map_register_ttl_t * mp)
184{
185 vl_api_show_one_map_register_ttl_reply_t *rmp;
186 int rv = 0;
187
188 u32 ttl = vnet_lisp_map_register_get_ttl ();
189 /* *INDENT-OFF* */
190 REPLY_MACRO2 (VL_API_SHOW_ONE_MAP_REGISTER_TTL_REPLY,
191 ({
192 rmp->ttl = clib_host_to_net_u32 (ttl);
193 }));
194 /* *INDENT-ON* */
195}
196
197static void
Filip Tehlar694396d2017-02-17 14:29:11 +0100198vl_api_one_add_del_locator_set_t_handler (vl_api_one_add_del_locator_set_t *
199 mp)
200{
201 vl_api_one_add_del_locator_set_reply_t *rmp;
202 int rv = 0;
203 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
204 locator_t locator;
Filip Tehlar974cdc62017-02-22 18:09:49 +0100205 vl_api_one_local_locator_t *ls_loc;
Filip Tehlar694396d2017-02-17 14:29:11 +0100206 u32 ls_index = ~0, locator_num;
207 u8 *locator_name = NULL;
208 int i;
209
210 memset (a, 0, sizeof (a[0]));
211
Filip Tehlar9d286a42017-10-26 23:57:09 -0700212 mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0;
Filip Tehlar694396d2017-02-17 14:29:11 +0100213 locator_name = format (0, "%s", mp->locator_set_name);
Gabriel Ganne3491d7f2017-10-19 15:10:46 +0200214 vec_terminate_c_string (locator_name);
Filip Tehlar694396d2017-02-17 14:29:11 +0100215
216 a->name = locator_name;
217 a->is_add = mp->is_add;
218 a->local = 1;
219 locator_num = clib_net_to_host_u32 (mp->locator_num);
220
221 memset (&locator, 0, sizeof (locator));
222 for (i = 0; i < locator_num; i++)
223 {
224 ls_loc = &mp->locators[i];
225 VALIDATE_SW_IF_INDEX (ls_loc);
226
227 locator.sw_if_index = htonl (ls_loc->sw_if_index);
228 locator.priority = ls_loc->priority;
229 locator.weight = ls_loc->weight;
230 locator.local = 1;
231 vec_add1 (a->locators, locator);
232 }
233
234 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
235
236 BAD_SW_IF_INDEX_LABEL;
237
238 vec_free (locator_name);
239 vec_free (a->locators);
240
241 /* *INDENT-OFF* */
242 REPLY_MACRO2 (VL_API_ONE_ADD_DEL_LOCATOR_SET_REPLY,
243 ({
244 rmp->ls_index = clib_host_to_net_u32 (ls_index);
245 }));
246 /* *INDENT-ON* */
247}
248
249static void
250vl_api_one_add_del_locator_t_handler (vl_api_one_add_del_locator_t * mp)
251{
252 vl_api_one_add_del_locator_reply_t *rmp;
253 int rv = 0;
254 locator_t locator, *locators = NULL;
255 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
256 u32 ls_index = ~0;
257 u8 *locator_name = NULL;
258
259 memset (&locator, 0, sizeof (locator));
260 memset (a, 0, sizeof (a[0]));
261
262 locator.sw_if_index = ntohl (mp->sw_if_index);
263 locator.priority = mp->priority;
264 locator.weight = mp->weight;
265 locator.local = 1;
266 vec_add1 (locators, locator);
267
Filip Tehlar9d286a42017-10-26 23:57:09 -0700268 mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0;
Filip Tehlar694396d2017-02-17 14:29:11 +0100269 locator_name = format (0, "%s", mp->locator_set_name);
Gabriel Ganne3491d7f2017-10-19 15:10:46 +0200270 vec_terminate_c_string (locator_name);
Filip Tehlar694396d2017-02-17 14:29:11 +0100271
272 a->name = locator_name;
273 a->locators = locators;
274 a->is_add = mp->is_add;
275 a->local = 1;
276
277 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
278
279 vec_free (locators);
280 vec_free (locator_name);
281
282 REPLY_MACRO (VL_API_ONE_ADD_DEL_LOCATOR_REPLY);
283}
284
Filip Tehlaref2a5bf2017-05-30 07:14:46 +0200285typedef struct
286{
287 u32 spi;
288 u8 si;
289} __attribute__ ((__packed__)) lisp_nsh_api_t;
290
Filip Tehlar694396d2017-02-17 14:29:11 +0100291static int
292unformat_one_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
293 u8 len)
294{
Filip Tehlaref2a5bf2017-05-30 07:14:46 +0200295 lisp_nsh_api_t *nsh;
296
Filip Tehlar694396d2017-02-17 14:29:11 +0100297 switch (type)
298 {
299 case 0: /* ipv4 */
300 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
301 gid_address_ip_set (dst, src, IP4);
302 gid_address_ippref_len (dst) = len;
303 ip_prefix_normalize (&gid_address_ippref (dst));
304 break;
305 case 1: /* ipv6 */
306 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
307 gid_address_ip_set (dst, src, IP6);
308 gid_address_ippref_len (dst) = len;
309 ip_prefix_normalize (&gid_address_ippref (dst));
310 break;
311 case 2: /* l2 mac */
312 gid_address_type (dst) = GID_ADDR_MAC;
313 clib_memcpy (&gid_address_mac (dst), src, 6);
314 break;
Filip Tehlaref2a5bf2017-05-30 07:14:46 +0200315 case 3: /* NSH */
316 gid_address_type (dst) = GID_ADDR_NSH;
317 nsh = src;
318 gid_address_nsh_spi (dst) = clib_net_to_host_u32 (nsh->spi);
319 gid_address_nsh_si (dst) = nsh->si;
320 break;
Filip Tehlar694396d2017-02-17 14:29:11 +0100321 default:
322 /* unknown type */
323 return VNET_API_ERROR_INVALID_VALUE;
324 }
325
326 gid_address_vni (dst) = vni;
327
328 return 0;
329}
330
331static void
332vl_api_one_add_del_local_eid_t_handler (vl_api_one_add_del_local_eid_t * mp)
333{
334 vl_api_one_add_del_local_eid_reply_t *rmp;
335 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
336 int rv = 0;
337 gid_address_t _eid, *eid = &_eid;
338 uword *p = NULL;
339 u32 locator_set_index = ~0, map_index = ~0;
340 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
341 u8 *name = NULL, *key = NULL;
342 memset (a, 0, sizeof (a[0]));
343 memset (eid, 0, sizeof (eid[0]));
344
345 rv = unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
346 mp->eid_type, mp->eid, mp->prefix_len);
347 if (rv)
348 goto out;
349
Filip Tehlaref2a5bf2017-05-30 07:14:46 +0200350 if (gid_address_type (eid) == GID_ADDR_NSH)
351 {
352 rv = VNET_API_ERROR_INVALID_VALUE;
353 goto out;
354 }
355
Filip Tehlar9d286a42017-10-26 23:57:09 -0700356 mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0;
Filip Tehlar694396d2017-02-17 14:29:11 +0100357 name = format (0, "%s", mp->locator_set_name);
Gabriel Ganne3491d7f2017-10-19 15:10:46 +0200358 vec_terminate_c_string (name);
Filip Tehlar694396d2017-02-17 14:29:11 +0100359 p = hash_get_mem (lcm->locator_set_index_by_name, name);
360 if (!p)
361 {
362 rv = VNET_API_ERROR_INVALID_VALUE;
363 goto out;
364 }
365 locator_set_index = p[0];
366
367 if (*mp->key)
368 key = format (0, "%s", mp->key);
369
370 /* XXX treat batch configuration */
371 a->is_add = mp->is_add;
372 gid_address_copy (&a->eid, eid);
373 a->locator_set_index = locator_set_index;
374 a->local = 1;
375 a->key = key;
376 a->key_id = clib_net_to_host_u16 (mp->key_id);
377
378 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
379
380out:
381 vec_free (name);
382 vec_free (key);
383 gid_address_free (&a->eid);
384
385 REPLY_MACRO (VL_API_ONE_ADD_DEL_LOCAL_EID_REPLY);
386}
387
388static void
389 vl_api_one_eid_table_add_del_map_t_handler
390 (vl_api_one_eid_table_add_del_map_t * mp)
391{
392 vl_api_one_eid_table_add_del_map_reply_t *rmp;
393 int rv = 0;
394 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
395 clib_net_to_host_u32 (mp->dp_table),
396 mp->is_l2, mp->is_add);
397REPLY_MACRO (VL_API_ONE_EID_TABLE_ADD_DEL_MAP_REPLY)}
398
399static void
400vl_api_one_add_del_map_server_t_handler (vl_api_one_add_del_map_server_t * mp)
401{
402 vl_api_one_add_del_map_server_reply_t *rmp;
403 int rv = 0;
404 ip_address_t addr;
405
406 memset (&addr, 0, sizeof (addr));
407
408 ip_address_set (&addr, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
409 rv = vnet_lisp_add_del_map_server (&addr, mp->is_add);
410
411 REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_SERVER_REPLY);
412}
413
414static void
415vl_api_one_add_del_map_resolver_t_handler (vl_api_one_add_del_map_resolver_t
416 * mp)
417{
418 vl_api_one_add_del_map_resolver_reply_t *rmp;
419 int rv = 0;
420 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
421
422 memset (a, 0, sizeof (a[0]));
423
424 a->is_add = mp->is_add;
425 ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
426
427 rv = vnet_lisp_add_del_map_resolver (a);
428
429 REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_RESOLVER_REPLY);
430}
431
432static void
433 vl_api_one_map_register_enable_disable_t_handler
434 (vl_api_one_map_register_enable_disable_t * mp)
435{
436 vl_api_one_map_register_enable_disable_reply_t *rmp;
437 int rv = 0;
438
439 vnet_lisp_map_register_enable_disable (mp->is_enabled);
440 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
441}
442
443static void
444 vl_api_one_rloc_probe_enable_disable_t_handler
445 (vl_api_one_rloc_probe_enable_disable_t * mp)
446{
447 vl_api_one_rloc_probe_enable_disable_reply_t *rmp;
448 int rv = 0;
449
450 vnet_lisp_rloc_probe_enable_disable (mp->is_enabled);
451 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
452}
453
454static void
455vl_api_one_enable_disable_t_handler (vl_api_one_enable_disable_t * mp)
456{
457 vl_api_one_enable_disable_reply_t *rmp;
458 int rv = 0;
459
460 vnet_lisp_enable_disable (mp->is_en);
461 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
462}
463
464static void
465 vl_api_show_one_map_request_mode_t_handler
466 (vl_api_show_one_map_request_mode_t * mp)
467{
468 int rv = 0;
469 vl_api_show_one_map_request_mode_reply_t *rmp;
470
471 /* *INDENT-OFF* */
472 REPLY_MACRO2(VL_API_SHOW_ONE_MAP_REQUEST_MODE_REPLY,
473 ({
474 rmp->mode = vnet_lisp_get_map_request_mode ();
475 }));
476 /* *INDENT-ON* */
477}
478
479static void
480vl_api_one_map_request_mode_t_handler (vl_api_one_map_request_mode_t * mp)
481{
482 vl_api_one_map_request_mode_reply_t *rmp;
483 int rv = 0;
484
485 rv = vnet_lisp_set_map_request_mode (mp->mode);
486
487 REPLY_MACRO (VL_API_ONE_MAP_REQUEST_MODE_REPLY);
488}
489
490static void
Filip Tehlaref2a5bf2017-05-30 07:14:46 +0200491vl_api_one_nsh_set_locator_set_t_handler (vl_api_one_nsh_set_locator_set_t
492 * mp)
493{
494 vl_api_one_nsh_set_locator_set_reply_t *rmp;
495 int rv = 0;
496 u8 *ls_name = 0;
497
Filip Tehlar9d286a42017-10-26 23:57:09 -0700498 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
Filip Tehlaref2a5bf2017-05-30 07:14:46 +0200499 ls_name = format (0, "%s", mp->ls_name);
Gabriel Ganne3491d7f2017-10-19 15:10:46 +0200500 vec_terminate_c_string (ls_name);
Filip Tehlaref2a5bf2017-05-30 07:14:46 +0200501 rv = vnet_lisp_nsh_set_locator_set (ls_name, mp->is_add);
502 vec_free (ls_name);
503
504 REPLY_MACRO (VL_API_ONE_PITR_SET_LOCATOR_SET_REPLY);
505}
506
507static void
Filip Tehlar694396d2017-02-17 14:29:11 +0100508vl_api_one_pitr_set_locator_set_t_handler (vl_api_one_pitr_set_locator_set_t
509 * mp)
510{
511 vl_api_one_pitr_set_locator_set_reply_t *rmp;
512 int rv = 0;
513 u8 *ls_name = 0;
514
Filip Tehlar9d286a42017-10-26 23:57:09 -0700515 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
Filip Tehlar694396d2017-02-17 14:29:11 +0100516 ls_name = format (0, "%s", mp->ls_name);
Gabriel Ganne3491d7f2017-10-19 15:10:46 +0200517 vec_terminate_c_string (ls_name);
Filip Tehlar694396d2017-02-17 14:29:11 +0100518 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
519 vec_free (ls_name);
520
521 REPLY_MACRO (VL_API_ONE_PITR_SET_LOCATOR_SET_REPLY);
522}
523
524static void
525vl_api_one_use_petr_t_handler (vl_api_one_use_petr_t * mp)
526{
527 vl_api_one_use_petr_reply_t *rmp;
528 int rv = 0;
529 ip_address_t addr;
530
531 ip_address_set (&addr, &mp->address, mp->is_ip4 ? IP4 : IP6);
532 rv = vnet_lisp_use_petr (&addr, mp->is_add);
533
534 REPLY_MACRO (VL_API_ONE_USE_PETR_REPLY);
535}
536
537static void
538vl_api_show_one_use_petr_t_handler (vl_api_show_one_use_petr_t * mp)
539{
Filip Tehlar694396d2017-02-17 14:29:11 +0100540 vl_api_show_one_use_petr_reply_t *rmp = NULL;
541 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
542 mapping_t *m;
543 locator_set_t *ls = 0;
544 int rv = 0;
545 locator_t *loc = 0;
546 u8 status = 0;
547 gid_address_t addr;
548
Filip Tehlar694396d2017-02-17 14:29:11 +0100549 memset (&addr, 0, sizeof (addr));
550 status = lcm->flags & LISP_FLAG_USE_PETR;
551 if (status)
552 {
553 m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index);
554 if (~0 != m->locator_set_index)
555 {
556 ls =
557 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
558 loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]);
559 gid_address_copy (&addr, &loc->address);
560 }
561 }
562
563 /* *INDENT-OFF* */
564 REPLY_MACRO2 (VL_API_SHOW_ONE_USE_PETR_REPLY,
565 {
Filip Tehlar67a99f82017-03-10 13:18:02 +0100566 rmp->status = status;
567 ip_address_t *ip = &gid_address_ip (&addr);
568 switch (ip_addr_version (ip))
569 {
570 case IP4:
571 clib_memcpy (rmp->address, &ip_addr_v4 (ip),
572 sizeof (ip_addr_v4 (ip)));
573 break;
574
575 case IP6:
576 clib_memcpy (rmp->address, &ip_addr_v6 (ip),
577 sizeof (ip_addr_v6 (ip)));
578 break;
579
580 default:
581 ASSERT (0);
582 }
583 rmp->is_ip4 = (gid_address_ip_version (&addr) == IP4);
Filip Tehlar694396d2017-02-17 14:29:11 +0100584 });
585 /* *INDENT-ON* */
586}
587
588static void
589 vl_api_one_add_del_map_request_itr_rlocs_t_handler
590 (vl_api_one_add_del_map_request_itr_rlocs_t * mp)
591{
592 vl_api_one_add_del_map_request_itr_rlocs_reply_t *rmp;
593 int rv = 0;
594 u8 *locator_set_name = NULL;
595 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
596
Filip Tehlar9d286a42017-10-26 23:57:09 -0700597 mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0;
Filip Tehlar694396d2017-02-17 14:29:11 +0100598 locator_set_name = format (0, "%s", mp->locator_set_name);
Gabriel Ganne3491d7f2017-10-19 15:10:46 +0200599 vec_terminate_c_string (locator_set_name);
Filip Tehlar694396d2017-02-17 14:29:11 +0100600
601 a->is_add = mp->is_add;
602 a->locator_set_name = locator_set_name;
603
604 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
605
606 vec_free (locator_set_name);
607
608 REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
609}
610
611static void
612 vl_api_one_add_del_remote_mapping_t_handler
613 (vl_api_one_add_del_remote_mapping_t * mp)
614{
615 locator_t *rlocs = 0;
616 vl_api_one_add_del_remote_mapping_reply_t *rmp;
617 int rv = 0;
618 gid_address_t _eid, *eid = &_eid;
619 u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
620
621 memset (eid, 0, sizeof (eid[0]));
622
623 rv = unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
624 mp->eid_type, mp->eid, mp->eid_len);
625 if (rv)
626 goto send_reply;
627
628 rlocs = unformat_one_locs (mp->rlocs, rloc_num);
629
630 if (!mp->is_add)
631 {
632 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
Filip Tehlar0a8840d2017-10-16 05:48:23 -0700633 memset (a, 0, sizeof (a[0]));
Filip Tehlar694396d2017-02-17 14:29:11 +0100634 gid_address_copy (&a->reid, eid);
635 a->is_add = 0;
636 rv = vnet_lisp_add_del_adjacency (a);
637 if (rv)
638 {
639 goto out;
640 }
641 }
642
643 /* NOTE: for now this works as a static remote mapping, i.e.,
644 * not authoritative and ttl infinite. */
Filip Tehlar809bc742017-08-14 19:15:36 +0200645 if (mp->is_add)
646 {
647 vnet_lisp_add_del_mapping_args_t _m_args, *m_args = &_m_args;
648 memset (m_args, 0, sizeof (m_args[0]));
649 gid_address_copy (&m_args->eid, eid);
650 m_args->action = mp->action;
651 m_args->is_static = 1;
652 m_args->ttl = ~0;
653 m_args->authoritative = 0;
654 rv = vnet_lisp_add_mapping (m_args, rlocs, NULL, NULL);
655 }
656 else
657 rv = vnet_lisp_del_mapping (eid, NULL);
Filip Tehlar694396d2017-02-17 14:29:11 +0100658
659 if (mp->del_all)
660 vnet_lisp_clear_all_remote_adjacencies ();
661
662out:
663 vec_free (rlocs);
664send_reply:
665 REPLY_MACRO (VL_API_ONE_ADD_DEL_REMOTE_MAPPING_REPLY);
666}
667
668static void
669vl_api_one_add_del_adjacency_t_handler (vl_api_one_add_del_adjacency_t * mp)
670{
671 vl_api_one_add_del_adjacency_reply_t *rmp;
672 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
673
674 int rv = 0;
675 memset (a, 0, sizeof (a[0]));
676
677 rv = unformat_one_eid_api (&a->leid, clib_net_to_host_u32 (mp->vni),
678 mp->eid_type, mp->leid, mp->leid_len);
679 rv |= unformat_one_eid_api (&a->reid, clib_net_to_host_u32 (mp->vni),
680 mp->eid_type, mp->reid, mp->reid_len);
681
682 if (rv)
683 goto send_reply;
684
685 a->is_add = mp->is_add;
686 rv = vnet_lisp_add_del_adjacency (a);
687
688send_reply:
689 REPLY_MACRO (VL_API_ONE_ADD_DEL_ADJACENCY_REPLY);
690}
691
692static void
693send_one_locator_details (lisp_cp_main_t * lcm,
Florin Coras6c4dae22018-01-09 06:39:23 -0800694 locator_t * loc, vl_api_registration_t * reg,
695 u32 context)
Filip Tehlar694396d2017-02-17 14:29:11 +0100696{
697 vl_api_one_locator_details_t *rmp;
698
699 rmp = vl_msg_api_alloc (sizeof (*rmp));
700 memset (rmp, 0, sizeof (*rmp));
701 rmp->_vl_msg_id = ntohs (VL_API_ONE_LOCATOR_DETAILS);
702 rmp->context = context;
703
704 rmp->local = loc->local;
705 if (loc->local)
706 {
707 rmp->sw_if_index = ntohl (loc->sw_if_index);
708 }
709 else
710 {
711 rmp->is_ipv6 = gid_address_ip_version (&loc->address);
712 ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
713 }
714 rmp->priority = loc->priority;
715 rmp->weight = loc->weight;
716
Florin Coras6c4dae22018-01-09 06:39:23 -0800717 vl_api_send_msg (reg, (u8 *) rmp);
Filip Tehlar694396d2017-02-17 14:29:11 +0100718}
719
720static void
721vl_api_one_locator_dump_t_handler (vl_api_one_locator_dump_t * mp)
722{
723 u8 *ls_name = 0;
Florin Coras6c4dae22018-01-09 06:39:23 -0800724 vl_api_registration_t *reg;
Filip Tehlar694396d2017-02-17 14:29:11 +0100725 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
726 locator_set_t *lsit = 0;
727 locator_t *loc = 0;
728 u32 ls_index = ~0, *locit = 0;
729 uword *p = 0;
730
Florin Coras6c4dae22018-01-09 06:39:23 -0800731 reg = vl_api_client_index_to_registration (mp->client_index);
732 if (!reg)
733 return;
Filip Tehlar694396d2017-02-17 14:29:11 +0100734
735 if (mp->is_index_set)
736 ls_index = htonl (mp->ls_index);
737 else
738 {
739 /* make sure we get a proper C-string */
740 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
741 ls_name = format (0, "%s", mp->ls_name);
Gabriel Ganne3491d7f2017-10-19 15:10:46 +0200742 vec_terminate_c_string (ls_name);
Filip Tehlar694396d2017-02-17 14:29:11 +0100743 p = hash_get_mem (lcm->locator_set_index_by_name, ls_name);
744 if (!p)
745 goto out;
746 ls_index = p[0];
747 }
748
749 if (pool_is_free_index (lcm->locator_set_pool, ls_index))
750 return;
751
752 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
753
754 vec_foreach (locit, lsit->locator_indices)
755 {
756 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
Florin Coras6c4dae22018-01-09 06:39:23 -0800757 send_one_locator_details (lcm, loc, reg, mp->context);
Filip Tehlar694396d2017-02-17 14:29:11 +0100758 };
759out:
760 vec_free (ls_name);
761}
762
763static void
764send_one_locator_set_details (lisp_cp_main_t * lcm,
765 locator_set_t * lsit,
Florin Coras6c4dae22018-01-09 06:39:23 -0800766 vl_api_registration_t * reg, u32 context,
767 u32 ls_index)
Filip Tehlar694396d2017-02-17 14:29:11 +0100768{
769 vl_api_one_locator_set_details_t *rmp;
770 u8 *str = 0;
771
772 rmp = vl_msg_api_alloc (sizeof (*rmp));
773 memset (rmp, 0, sizeof (*rmp));
774 rmp->_vl_msg_id = ntohs (VL_API_ONE_LOCATOR_SET_DETAILS);
775 rmp->context = context;
776
777 rmp->ls_index = htonl (ls_index);
778 if (lsit->local)
779 {
780 ASSERT (lsit->name != NULL);
781 strncpy ((char *) rmp->ls_name, (char *) lsit->name,
782 vec_len (lsit->name));
783 }
784 else
785 {
786 str = format (0, "<remote-%d>", ls_index);
787 strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str));
788 vec_free (str);
789 }
790
Florin Coras6c4dae22018-01-09 06:39:23 -0800791 vl_api_send_msg (reg, (u8 *) rmp);
Filip Tehlar694396d2017-02-17 14:29:11 +0100792}
793
794static void
795vl_api_one_locator_set_dump_t_handler (vl_api_one_locator_set_dump_t * mp)
796{
Florin Coras6c4dae22018-01-09 06:39:23 -0800797 vl_api_registration_t *reg;
Filip Tehlar694396d2017-02-17 14:29:11 +0100798 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
799 locator_set_t *lsit = NULL;
800 u8 filter;
801
Florin Coras6c4dae22018-01-09 06:39:23 -0800802 reg = vl_api_client_index_to_registration (mp->client_index);
803 if (!reg)
804 return;
Filip Tehlar694396d2017-02-17 14:29:11 +0100805
806 filter = mp->filter;
807 /* *INDENT-OFF* */
808 pool_foreach (lsit, lcm->locator_set_pool,
809 ({
810 if (filter && !((1 == filter && lsit->local) ||
811 (2 == filter && !lsit->local)))
812 {
813 continue;
814 }
Florin Coras6c4dae22018-01-09 06:39:23 -0800815 send_one_locator_set_details (lcm, lsit, reg, mp->context,
Filip Tehlar694396d2017-02-17 14:29:11 +0100816 lsit - lcm->locator_set_pool);
817 }));
818 /* *INDENT-ON* */
819}
820
821static void
822one_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length)
823{
824 ASSERT (prefix_length);
825 ip_prefix_t *ippref = &fid_addr_ippref (src);
826
827 switch (fid_addr_type (src))
828 {
829 case FID_ADDR_IP_PREF:
830 if (ip_prefix_version (ippref) == IP4)
831 clib_memcpy (dst, &ip_prefix_v4 (ippref), 4);
832 else
833 clib_memcpy (dst, &ip_prefix_v6 (ippref), 16);
834 prefix_length[0] = ip_prefix_len (ippref);
835 break;
836
837 case FID_ADDR_MAC:
838 prefix_length[0] = 0;
839 clib_memcpy (dst, fid_addr_mac (src), 6);
840 break;
841
842 default:
843 clib_warning ("Unknown FID type %d!", fid_addr_type (src));
844 break;
845 }
846}
847
848static u8
849fid_type_to_api_type (fid_address_t * fid)
850{
851 ip_prefix_t *ippref;
852
853 switch (fid_addr_type (fid))
854 {
855 case FID_ADDR_IP_PREF:
856 ippref = &fid_addr_ippref (fid);
857 if (ip_prefix_version (ippref) == IP4)
858 return 0;
859 else if (ip_prefix_version (ippref) == IP6)
860 return 1;
861 else
862 return ~0;
863
864 case FID_ADDR_MAC:
865 return 2;
866 case FID_ADDR_NSH:
867 return 3;
868 }
869
870 return ~0;
871}
872
873static void
874send_one_eid_table_details (mapping_t * mapit,
Florin Coras6c4dae22018-01-09 06:39:23 -0800875 vl_api_registration_t * reg, u32 context,
876 u8 filter)
Filip Tehlar694396d2017-02-17 14:29:11 +0100877{
878 fid_address_t *fid;
879 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
880 locator_set_t *ls = 0;
881 vl_api_one_eid_table_details_t *rmp = NULL;
882 gid_address_t *gid = NULL;
883 u8 *mac = 0;
884 ip_prefix_t *ip_prefix = NULL;
885
Filip Tehlaref2a5bf2017-05-30 07:14:46 +0200886 if (mapit->pitr_set || mapit->nsh_set)
Filip Tehlar1e8d01f2017-03-30 15:17:01 +0200887 return;
888
Filip Tehlar694396d2017-02-17 14:29:11 +0100889 switch (filter)
890 {
891 case 0: /* all mappings */
892 break;
893
894 case 1: /* local only */
895 if (!mapit->local)
896 return;
897 break;
898 case 2: /* remote only */
899 if (mapit->local)
900 return;
901 break;
902 default:
903 clib_warning ("Filter error, unknown filter: %d", filter);
904 return;
905 }
906
907 gid = &mapit->eid;
908 ip_prefix = &gid_address_ippref (gid);
909 mac = gid_address_mac (gid);
910
911 rmp = vl_msg_api_alloc (sizeof (*rmp));
912 memset (rmp, 0, sizeof (*rmp));
913 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_DETAILS);
914
915 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
916 if (vec_len (ls->locator_indices) == 0)
917 rmp->locator_set_index = ~0;
918 else
919 rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
920
921 rmp->is_local = mapit->local;
922 rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
923 rmp->action = mapit->action;
924 rmp->authoritative = mapit->authoritative;
925
926 switch (gid_address_type (gid))
927 {
928 case GID_ADDR_SRC_DST:
929 rmp->is_src_dst = 1;
930 fid = &gid_address_sd_src (gid);
931 rmp->eid_type = fid_type_to_api_type (fid);
932 one_fid_put_api (rmp->seid, &gid_address_sd_src (gid),
933 &rmp->seid_prefix_len);
934 one_fid_put_api (rmp->eid, &gid_address_sd_dst (gid),
935 &rmp->eid_prefix_len);
936 break;
937 case GID_ADDR_IP_PREFIX:
938 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
939 if (ip_prefix_version (ip_prefix) == IP4)
940 {
941 rmp->eid_type = 0; /* ipv4 type */
942 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
943 sizeof (ip_prefix_v4 (ip_prefix)));
944 }
945 else
946 {
947 rmp->eid_type = 1; /* ipv6 type */
948 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
949 sizeof (ip_prefix_v6 (ip_prefix)));
950 }
951 break;
952 case GID_ADDR_MAC:
953 rmp->eid_type = 2; /* l2 mac type */
954 clib_memcpy (rmp->eid, mac, 6);
955 break;
Filip Tehlaref2a5bf2017-05-30 07:14:46 +0200956 case GID_ADDR_NSH:
957 rmp->eid_type = 3; /* NSH type */
958 lisp_nsh_api_t nsh;
959 nsh.spi = clib_host_to_net_u32 (gid_address_nsh_spi (gid));
960 nsh.si = gid_address_nsh_si (gid);
961 clib_memcpy (rmp->eid, &nsh, sizeof (nsh));
962 break;
Filip Tehlar694396d2017-02-17 14:29:11 +0100963 default:
964 ASSERT (0);
965 }
966 rmp->context = context;
967 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
968 rmp->key_id = clib_host_to_net_u16 (mapit->key_id);
969 memcpy (rmp->key, mapit->key, vec_len (mapit->key));
Florin Coras6c4dae22018-01-09 06:39:23 -0800970 vl_api_send_msg (reg, (u8 *) rmp);
Filip Tehlar694396d2017-02-17 14:29:11 +0100971}
972
973static void
974vl_api_one_eid_table_dump_t_handler (vl_api_one_eid_table_dump_t * mp)
975{
976 u32 mi;
Florin Coras6c4dae22018-01-09 06:39:23 -0800977 vl_api_registration_t *reg;
Filip Tehlar694396d2017-02-17 14:29:11 +0100978 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
979 mapping_t *mapit = NULL;
980 gid_address_t _eid, *eid = &_eid;
981
Florin Coras6c4dae22018-01-09 06:39:23 -0800982 reg = vl_api_client_index_to_registration (mp->client_index);
983 if (!reg)
984 return;
Filip Tehlar694396d2017-02-17 14:29:11 +0100985
986 if (mp->eid_set)
987 {
988 memset (eid, 0, sizeof (*eid));
989
990 unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
991 mp->eid_type, mp->eid, mp->prefix_length);
992
993 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
994 if ((u32) ~ 0 == mi)
995 return;
996
997 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
Florin Coras6c4dae22018-01-09 06:39:23 -0800998 send_one_eid_table_details (mapit, reg, mp->context,
Filip Tehlar694396d2017-02-17 14:29:11 +0100999 0 /* ignore filter */ );
1000 }
1001 else
1002 {
1003 /* *INDENT-OFF* */
1004 pool_foreach (mapit, lcm->mapping_pool,
1005 ({
Florin Coras6c4dae22018-01-09 06:39:23 -08001006 send_one_eid_table_details(mapit, reg, mp->context,
Filip Tehlar694396d2017-02-17 14:29:11 +01001007 mp->filter);
1008 }));
1009 /* *INDENT-ON* */
1010 }
1011}
1012
1013static void
Florin Coras6c4dae22018-01-09 06:39:23 -08001014send_one_map_server_details (ip_address_t * ip, vl_api_registration_t * reg,
1015 u32 context)
Filip Tehlar694396d2017-02-17 14:29:11 +01001016{
1017 vl_api_one_map_server_details_t *rmp = NULL;
1018
1019 rmp = vl_msg_api_alloc (sizeof (*rmp));
1020 memset (rmp, 0, sizeof (*rmp));
1021 rmp->_vl_msg_id = ntohs (VL_API_ONE_MAP_SERVER_DETAILS);
1022
1023 switch (ip_addr_version (ip))
1024 {
1025 case IP4:
1026 rmp->is_ipv6 = 0;
1027 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
1028 sizeof (ip_addr_v4 (ip)));
1029 break;
1030
1031 case IP6:
1032 rmp->is_ipv6 = 1;
1033 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
1034 sizeof (ip_addr_v6 (ip)));
1035 break;
1036
1037 default:
1038 ASSERT (0);
1039 }
1040 rmp->context = context;
1041
Florin Coras6c4dae22018-01-09 06:39:23 -08001042 vl_api_send_msg (reg, (u8 *) rmp);
Filip Tehlar694396d2017-02-17 14:29:11 +01001043}
1044
1045static void
1046vl_api_one_map_server_dump_t_handler (vl_api_one_map_server_dump_t * mp)
1047{
Florin Coras6c4dae22018-01-09 06:39:23 -08001048 vl_api_registration_t *reg;
Filip Tehlar694396d2017-02-17 14:29:11 +01001049 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1050 lisp_msmr_t *mr;
1051
Florin Coras6c4dae22018-01-09 06:39:23 -08001052 reg = vl_api_client_index_to_registration (mp->client_index);
1053 if (!reg)
1054 return;
Filip Tehlar694396d2017-02-17 14:29:11 +01001055
1056 vec_foreach (mr, lcm->map_servers)
1057 {
Florin Coras6c4dae22018-01-09 06:39:23 -08001058 send_one_map_server_details (&mr->address, reg, mp->context);
Filip Tehlar694396d2017-02-17 14:29:11 +01001059 }
1060}
1061
1062static void
1063send_one_map_resolver_details (ip_address_t * ip,
Florin Coras6c4dae22018-01-09 06:39:23 -08001064 vl_api_registration_t * reg, u32 context)
Filip Tehlar694396d2017-02-17 14:29:11 +01001065{
1066 vl_api_one_map_resolver_details_t *rmp = NULL;
1067
1068 rmp = vl_msg_api_alloc (sizeof (*rmp));
1069 memset (rmp, 0, sizeof (*rmp));
1070 rmp->_vl_msg_id = ntohs (VL_API_ONE_MAP_RESOLVER_DETAILS);
1071
1072 switch (ip_addr_version (ip))
1073 {
1074 case IP4:
1075 rmp->is_ipv6 = 0;
1076 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
1077 sizeof (ip_addr_v4 (ip)));
1078 break;
1079
1080 case IP6:
1081 rmp->is_ipv6 = 1;
1082 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
1083 sizeof (ip_addr_v6 (ip)));
1084 break;
1085
1086 default:
1087 ASSERT (0);
1088 }
1089 rmp->context = context;
1090
Florin Coras6c4dae22018-01-09 06:39:23 -08001091 vl_api_send_msg (reg, (u8 *) rmp);
Filip Tehlar694396d2017-02-17 14:29:11 +01001092}
1093
1094static void
1095vl_api_one_map_resolver_dump_t_handler (vl_api_one_map_resolver_dump_t * mp)
1096{
Florin Coras6c4dae22018-01-09 06:39:23 -08001097 vl_api_registration_t *reg;
Filip Tehlar694396d2017-02-17 14:29:11 +01001098 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1099 lisp_msmr_t *mr;
1100
Florin Coras6c4dae22018-01-09 06:39:23 -08001101 reg = vl_api_client_index_to_registration (mp->client_index);
1102 if (!reg)
1103 return;
Filip Tehlar694396d2017-02-17 14:29:11 +01001104
1105 vec_foreach (mr, lcm->map_resolvers)
1106 {
Florin Coras6c4dae22018-01-09 06:39:23 -08001107 send_one_map_resolver_details (&mr->address, reg, mp->context);
Filip Tehlar694396d2017-02-17 14:29:11 +01001108 }
1109}
1110
1111static void
Florin Coras6c4dae22018-01-09 06:39:23 -08001112send_eid_table_map_pair (hash_pair_t * p, vl_api_registration_t * reg,
1113 u32 context)
Filip Tehlar694396d2017-02-17 14:29:11 +01001114{
1115 vl_api_one_eid_table_map_details_t *rmp = NULL;
1116
1117 rmp = vl_msg_api_alloc (sizeof (*rmp));
1118 memset (rmp, 0, sizeof (*rmp));
1119 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_MAP_DETAILS);
1120
1121 rmp->vni = clib_host_to_net_u32 (p->key);
1122 rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
1123 rmp->context = context;
Florin Coras6c4dae22018-01-09 06:39:23 -08001124 vl_api_send_msg (reg, (u8 *) rmp);
Filip Tehlar694396d2017-02-17 14:29:11 +01001125}
1126
1127static void
1128vl_api_one_eid_table_map_dump_t_handler (vl_api_one_eid_table_map_dump_t * mp)
1129{
Florin Coras6c4dae22018-01-09 06:39:23 -08001130 vl_api_registration_t *reg;
Filip Tehlar694396d2017-02-17 14:29:11 +01001131 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1132 hash_pair_t *p;
1133 uword *vni_table = 0;
1134
Florin Coras6c4dae22018-01-09 06:39:23 -08001135 reg = vl_api_client_index_to_registration (mp->client_index);
1136 if (!reg)
1137 return;
Filip Tehlar694396d2017-02-17 14:29:11 +01001138
1139 if (mp->is_l2)
1140 {
1141 vni_table = lcm->bd_id_by_vni;
1142 }
1143 else
1144 {
1145 vni_table = lcm->table_id_by_vni;
1146 }
1147
1148 /* *INDENT-OFF* */
1149 hash_foreach_pair (p, vni_table,
1150 ({
Florin Coras6c4dae22018-01-09 06:39:23 -08001151 send_eid_table_map_pair (p, reg, mp->context);
Filip Tehlar694396d2017-02-17 14:29:11 +01001152 }));
1153 /* *INDENT-ON* */
1154}
1155
1156static void
Florin Coras6c4dae22018-01-09 06:39:23 -08001157send_eid_table_vni (u32 vni, vl_api_registration_t * reg, u32 context)
Filip Tehlar694396d2017-02-17 14:29:11 +01001158{
1159 vl_api_one_eid_table_vni_details_t *rmp = 0;
1160
1161 rmp = vl_msg_api_alloc (sizeof (*rmp));
1162 memset (rmp, 0, sizeof (*rmp));
1163 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_VNI_DETAILS);
1164 rmp->context = context;
1165 rmp->vni = clib_host_to_net_u32 (vni);
Florin Coras6c4dae22018-01-09 06:39:23 -08001166 vl_api_send_msg (reg, (u8 *) rmp);
Filip Tehlar694396d2017-02-17 14:29:11 +01001167}
1168
1169static void
1170one_adjacency_copy (vl_api_one_adjacency_t * dst, lisp_adjacency_t * adjs)
1171{
1172 lisp_adjacency_t *adj;
1173 vl_api_one_adjacency_t a;
1174 u32 i, n = vec_len (adjs);
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02001175 lisp_nsh_api_t nsh;
Filip Tehlar694396d2017-02-17 14:29:11 +01001176
1177 for (i = 0; i < n; i++)
1178 {
1179 adj = vec_elt_at_index (adjs, i);
1180 memset (&a, 0, sizeof (a));
1181
1182 switch (gid_address_type (&adj->reid))
1183 {
1184 case GID_ADDR_IP_PREFIX:
1185 a.reid_prefix_len = gid_address_ippref_len (&adj->reid);
1186 a.leid_prefix_len = gid_address_ippref_len (&adj->leid);
1187 if (gid_address_ip_version (&adj->reid) == IP4)
1188 {
1189 a.eid_type = 0; /* ipv4 type */
1190 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 4);
1191 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 4);
1192 }
1193 else
1194 {
1195 a.eid_type = 1; /* ipv6 type */
1196 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 16);
1197 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 16);
1198 }
1199 break;
1200 case GID_ADDR_MAC:
1201 a.eid_type = 2; /* l2 mac type */
1202 mac_copy (a.reid, gid_address_mac (&adj->reid));
1203 mac_copy (a.leid, gid_address_mac (&adj->leid));
1204 break;
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02001205 case GID_ADDR_NSH:
1206 a.eid_type = 3; /* NSH type */
1207 nsh.spi = clib_host_to_net_u32 (gid_address_nsh_spi (&adj->reid));
1208 nsh.si = gid_address_nsh_si (&adj->reid);
1209 clib_memcpy (a.reid, &nsh, sizeof (nsh));
1210
1211 nsh.spi = clib_host_to_net_u32 (gid_address_nsh_spi (&adj->leid));
1212 nsh.si = gid_address_nsh_si (&adj->leid);
1213 clib_memcpy (a.leid, &nsh, sizeof (nsh));
Filip Tehlarb8633d22017-06-09 15:25:57 +02001214 break;
Filip Tehlar694396d2017-02-17 14:29:11 +01001215 default:
1216 ASSERT (0);
1217 }
1218 dst[i] = a;
1219 }
1220}
1221
1222static void
1223 vl_api_show_one_rloc_probe_state_t_handler
1224 (vl_api_show_one_rloc_probe_state_t * mp)
1225{
1226 vl_api_show_one_rloc_probe_state_reply_t *rmp = 0;
1227 int rv = 0;
1228
1229 /* *INDENT-OFF* */
1230 REPLY_MACRO2 (VL_API_SHOW_ONE_RLOC_PROBE_STATE_REPLY,
1231 {
1232 rmp->is_enabled = vnet_lisp_rloc_probe_state_get ();
1233 });
1234 /* *INDENT-ON* */
1235}
1236
1237static void
1238 vl_api_show_one_map_register_state_t_handler
1239 (vl_api_show_one_map_register_state_t * mp)
1240{
1241 vl_api_show_one_map_register_state_reply_t *rmp = 0;
1242 int rv = 0;
1243
1244 /* *INDENT-OFF* */
1245 REPLY_MACRO2 (VL_API_SHOW_ONE_MAP_REGISTER_STATE_REPLY,
1246 {
1247 rmp->is_enabled = vnet_lisp_map_register_state_get ();
1248 });
1249 /* *INDENT-ON* */
1250}
1251
1252static void
1253vl_api_one_adjacencies_get_t_handler (vl_api_one_adjacencies_get_t * mp)
1254{
1255 vl_api_one_adjacencies_get_reply_t *rmp = 0;
1256 lisp_adjacency_t *adjs = 0;
1257 int rv = 0;
1258 u32 size = ~0;
1259 u32 vni = clib_net_to_host_u32 (mp->vni);
1260
1261 adjs = vnet_lisp_adjacencies_get_by_vni (vni);
1262 size = vec_len (adjs) * sizeof (vl_api_one_adjacency_t);
1263
1264 /* *INDENT-OFF* */
1265 REPLY_MACRO4 (VL_API_ONE_ADJACENCIES_GET_REPLY, size,
1266 {
1267 rmp->count = clib_host_to_net_u32 (vec_len (adjs));
1268 one_adjacency_copy (rmp->adjacencies, adjs);
1269 });
1270 /* *INDENT-ON* */
1271
1272 vec_free (adjs);
1273}
1274
1275static void
1276vl_api_one_eid_table_vni_dump_t_handler (vl_api_one_eid_table_vni_dump_t * mp)
1277{
1278 hash_pair_t *p;
1279 u32 *vnis = 0;
Florin Coras6c4dae22018-01-09 06:39:23 -08001280 vl_api_registration_t *reg;
Filip Tehlar694396d2017-02-17 14:29:11 +01001281 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1282
Florin Coras6c4dae22018-01-09 06:39:23 -08001283 reg = vl_api_client_index_to_registration (mp->client_index);
1284 if (!reg)
1285 return;
Filip Tehlar694396d2017-02-17 14:29:11 +01001286
1287 /* *INDENT-OFF* */
1288 hash_foreach_pair (p, lcm->table_id_by_vni,
1289 ({
1290 hash_set (vnis, p->key, 0);
1291 }));
1292
1293 hash_foreach_pair (p, lcm->bd_id_by_vni,
1294 ({
1295 hash_set (vnis, p->key, 0);
1296 }));
1297
1298 hash_foreach_pair (p, vnis,
1299 ({
Florin Coras6c4dae22018-01-09 06:39:23 -08001300 send_eid_table_vni (p->key, reg, mp->context);
Filip Tehlar694396d2017-02-17 14:29:11 +01001301 }));
1302 /* *INDENT-ON* */
1303
1304 hash_free (vnis);
1305}
1306
1307static void
1308vl_api_show_one_status_t_handler (vl_api_show_one_status_t * mp)
1309{
Filip Tehlar694396d2017-02-17 14:29:11 +01001310 vl_api_show_one_status_reply_t *rmp = NULL;
1311 int rv = 0;
1312
Filip Tehlar694396d2017-02-17 14:29:11 +01001313 /* *INDENT-OFF* */
1314 REPLY_MACRO2(VL_API_SHOW_ONE_STATUS_REPLY,
1315 ({
1316 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
1317 rmp->feature_status = vnet_lisp_enable_disable_status ();
1318 }));
1319 /* *INDENT-ON* */
1320}
1321
1322static void
1323 vl_api_one_get_map_request_itr_rlocs_t_handler
1324 (vl_api_one_get_map_request_itr_rlocs_t * mp)
1325{
Filip Tehlar694396d2017-02-17 14:29:11 +01001326 vl_api_one_get_map_request_itr_rlocs_reply_t *rmp = NULL;
1327 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1328 locator_set_t *loc_set = 0;
1329 u8 *tmp_str = 0;
1330 int rv = 0;
1331
Filip Tehlar694396d2017-02-17 14:29:11 +01001332 if (~0 == lcm->mreq_itr_rlocs)
1333 {
1334 tmp_str = format (0, " ");
1335 }
1336 else
1337 {
1338 loc_set =
1339 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
1340 tmp_str = format (0, "%s", loc_set->name);
1341 }
1342
1343 /* *INDENT-OFF* */
1344 REPLY_MACRO2(VL_API_ONE_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
1345 ({
1346 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1347 ARRAY_LEN(rmp->locator_set_name) - 1);
1348 }));
1349 /* *INDENT-ON* */
1350
1351 vec_free (tmp_str);
1352}
1353
1354static void
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02001355vl_api_show_one_nsh_mapping_t_handler (vl_api_show_one_nsh_mapping_t * mp)
1356{
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02001357 vl_api_show_one_nsh_mapping_reply_t *rmp = NULL;
1358 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1359 mapping_t *m;
1360 locator_set_t *ls = 0;
1361 u8 *tmp_str = 0;
1362 u8 is_set = 0;
1363 int rv = 0;
1364
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02001365 if (lcm->nsh_map_index == (u32) ~ 0)
1366 {
1367 tmp_str = format (0, "N/A");
1368 }
1369 else
1370 {
1371 m = pool_elt_at_index (lcm->mapping_pool, lcm->nsh_map_index);
1372 if (~0 != m->locator_set_index)
1373 {
1374 ls =
1375 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
1376 tmp_str = format (0, "%s", ls->name);
1377 is_set = 1;
1378 }
1379 else
1380 {
1381 tmp_str = format (0, "N/A");
1382 }
1383 }
1384 vec_add1 (tmp_str, 0);
1385
1386 /* *INDENT-OFF* */
1387 REPLY_MACRO2(VL_API_SHOW_ONE_NSH_MAPPING_REPLY,
1388 ({
1389 rmp->is_set = is_set;
1390 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1391 ARRAY_LEN(rmp->locator_set_name) - 1);
1392 }));
1393 /* *INDENT-ON* */
1394}
1395
1396static void
Filip Tehlar694396d2017-02-17 14:29:11 +01001397vl_api_show_one_pitr_t_handler (vl_api_show_one_pitr_t * mp)
1398{
Filip Tehlar694396d2017-02-17 14:29:11 +01001399 vl_api_show_one_pitr_reply_t *rmp = NULL;
1400 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1401 mapping_t *m;
1402 locator_set_t *ls = 0;
1403 u8 *tmp_str = 0;
1404 int rv = 0;
1405
Filip Tehlar0a8840d2017-10-16 05:48:23 -07001406 u8 is_enabled = (lcm->flags & LISP_FLAG_PITR_MODE)
1407 && lcm->pitr_map_index != ~0;
1408
1409 if (!is_enabled)
Filip Tehlar694396d2017-02-17 14:29:11 +01001410 {
1411 tmp_str = format (0, "N/A");
1412 }
1413 else
1414 {
1415 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
1416 if (~0 != m->locator_set_index)
1417 {
1418 ls =
1419 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
1420 tmp_str = format (0, "%s", ls->name);
1421 }
1422 else
1423 {
1424 tmp_str = format (0, "N/A");
1425 }
1426 }
1427 vec_add1 (tmp_str, 0);
1428
1429 /* *INDENT-OFF* */
1430 REPLY_MACRO2(VL_API_SHOW_ONE_PITR_REPLY,
1431 ({
Filip Tehlar0a8840d2017-10-16 05:48:23 -07001432 rmp->status = lcm->flags & LISP_FLAG_PITR_MODE;
Filip Tehlar694396d2017-02-17 14:29:11 +01001433 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1434 ARRAY_LEN(rmp->locator_set_name) - 1);
1435 }));
1436 /* *INDENT-ON* */
1437}
1438
Filip Tehlar7eaf0e52017-03-08 08:46:51 +01001439static void
1440 vl_api_show_one_stats_enable_disable_t_handler
1441 (vl_api_show_one_stats_enable_disable_t * mp)
1442{
1443 vl_api_show_one_stats_enable_disable_reply_t *rmp = NULL;
1444 vnet_api_error_t rv = 0;
1445
1446 /* *INDENT-OFF* */
1447 REPLY_MACRO2 (VL_API_SHOW_ONE_STATS_ENABLE_DISABLE_REPLY,
1448 ({
1449 rmp->is_en = vnet_lisp_stats_enable_disable_state ();
1450 }));
1451 /* *INDENT-ON* */
1452}
1453
1454static void
1455 vl_api_one_stats_enable_disable_t_handler
1456 (vl_api_one_stats_enable_disable_t * mp)
1457{
1458 vl_api_one_enable_disable_reply_t *rmp = NULL;
1459
1460 vnet_api_error_t rv = vnet_lisp_stats_enable_disable (mp->is_en);
1461 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
1462}
1463
1464static void
Filip Tehlar4868ff62017-03-09 16:48:39 +01001465lisp_fid_addr_to_api (fid_address_t * fid, u8 * dst, u8 * api_eid_type,
1466 u8 * prefix_length)
1467{
1468 switch (fid_addr_type (fid))
1469 {
1470 case FID_ADDR_IP_PREF:
1471 *prefix_length = fid_addr_prefix_length (fid);
1472 if (fid_addr_ip_version (fid) == IP4)
1473 {
1474 *api_eid_type = 0; /* ipv4 type */
1475 clib_memcpy (dst, &fid_addr_ippref (fid), 4);
1476 }
1477 else
1478 {
1479 *api_eid_type = 1; /* ipv6 type */
1480 clib_memcpy (dst, &fid_addr_ippref (fid), 16);
1481 }
1482 break;
1483 case FID_ADDR_MAC:
1484 *api_eid_type = 2; /* l2 mac type */
1485 mac_copy (dst, fid_addr_mac (fid));
1486 break;
1487 default:
1488 ASSERT (0);
1489 }
1490}
1491
1492static void
Filip Tehlar21511912017-04-07 10:41:42 +02001493vl_api_one_stats_flush_t_handler (vl_api_one_stats_flush_t * mp)
1494{
1495 vl_api_one_stats_flush_reply_t *rmp;
1496 u8 rv;
1497
1498 rv = vnet_lisp_flush_stats ();
1499 REPLY_MACRO (VL_API_ONE_STATS_FLUSH_REPLY);
1500}
1501
1502static void
Filip Tehlar7eaf0e52017-03-08 08:46:51 +01001503vl_api_one_stats_dump_t_handler (vl_api_one_stats_dump_t * mp)
1504{
Filip Tehlar4868ff62017-03-09 16:48:39 +01001505 vl_api_one_stats_details_t *rmp;
1506 lisp_api_stats_t *stats, *stat;
1507 u8 rv = 0;
Filip Tehlar7eaf0e52017-03-08 08:46:51 +01001508
Filip Tehlar4868ff62017-03-09 16:48:39 +01001509 stats = vnet_lisp_get_stats ();
1510 vec_foreach (stat, stats)
1511 {
1512 /* *INDENT-OFF* */
1513 REPLY_DETAILS (VL_API_ONE_STATS_DETAILS,
1514 ({
1515 lisp_fid_addr_to_api (&stat->deid, rmp->deid, &rmp->eid_type,
1516 &rmp->deid_pref_len);
1517 lisp_fid_addr_to_api (&stat->seid, rmp->seid, &rmp->eid_type,
1518 &rmp->seid_pref_len);
1519 rmp->vni = clib_host_to_net_u32 (stat->vni);
1520
1521 rmp->is_ip4 = ip_addr_version (&stat->rmt_rloc) == IP4 ? 1 : 0;
1522 ip_address_copy_addr (rmp->rloc, &stat->rmt_rloc);
1523 ip_address_copy_addr (rmp->lloc, &stat->loc_rloc);
1524
Filip Tehlar21511912017-04-07 10:41:42 +02001525 rmp->pkt_count = clib_host_to_net_u32 (stat->counters.packets);
1526 rmp->bytes = clib_host_to_net_u32 (stat->counters.bytes);
Filip Tehlar4868ff62017-03-09 16:48:39 +01001527 }));
1528 /* *INDENT-ON* */
1529 }
Filip Tehlar7eaf0e52017-03-08 08:46:51 +01001530}
1531
Filip Tehlard5a65db2017-05-17 17:21:10 +02001532static void
1533 vl_api_one_add_del_l2_arp_entry_t_handler
1534 (vl_api_one_add_del_l2_arp_entry_t * mp)
1535{
1536 vl_api_one_add_del_l2_arp_entry_reply_t *rmp;
1537 int rv = 0;
1538 gid_address_t _arp, *arp = &_arp;
1539 memset (arp, 0, sizeof (*arp));
1540
1541 gid_address_type (arp) = GID_ADDR_ARP;
1542 gid_address_arp_bd (arp) = clib_net_to_host_u32 (mp->bd);
1543
1544 /* vpp keeps ip4 addresses in network byte order */
Filip Tehlar05879992017-09-05 15:46:09 +02001545 ip_address_set (&gid_address_arp_ndp_ip (arp), &mp->ip4, IP4);
Filip Tehlard5a65db2017-05-17 17:21:10 +02001546
Filip Tehlar64929642017-09-20 08:41:23 +02001547 rv = vnet_lisp_add_del_l2_arp_ndp_entry (arp, mp->mac, mp->is_add);
Filip Tehlard5a65db2017-05-17 17:21:10 +02001548
1549 REPLY_MACRO (VL_API_ONE_ADD_DEL_L2_ARP_ENTRY_REPLY);
1550}
1551
1552static void
Filip Tehlar05879992017-09-05 15:46:09 +02001553vl_api_one_add_del_ndp_entry_t_handler (vl_api_one_add_del_ndp_entry_t * mp)
1554{
1555 vl_api_one_add_del_ndp_entry_reply_t *rmp;
1556 int rv = 0;
1557 gid_address_t _g, *g = &_g;
1558 memset (g, 0, sizeof (*g));
1559
1560 gid_address_type (g) = GID_ADDR_NDP;
1561 gid_address_ndp_bd (g) = clib_net_to_host_u32 (mp->bd);
1562 ip_address_set (&gid_address_arp_ndp_ip (g), mp->ip6, IP6);
1563
Filip Tehlar64929642017-09-20 08:41:23 +02001564 rv = vnet_lisp_add_del_l2_arp_ndp_entry (g, mp->mac, mp->is_add);
Filip Tehlar05879992017-09-05 15:46:09 +02001565
1566 REPLY_MACRO (VL_API_ONE_ADD_DEL_NDP_ENTRY_REPLY);
1567}
1568
1569static void
1570vl_api_one_ndp_bd_get_t_handler (vl_api_one_ndp_bd_get_t * mp)
1571{
1572 vl_api_one_ndp_bd_get_reply_t *rmp;
1573 int rv = 0;
1574 u32 i = 0;
1575 hash_pair_t *p;
1576
1577 u32 *bds = vnet_lisp_ndp_bds_get ();
1578 u32 size = hash_elts (bds) * sizeof (u32);
1579
1580 /* *INDENT-OFF* */
1581 REPLY_MACRO4 (VL_API_ONE_NDP_BD_GET_REPLY, size,
1582 {
1583 rmp->count = clib_host_to_net_u32 (hash_elts (bds));
1584 hash_foreach_pair (p, bds,
1585 ({
1586 rmp->bridge_domains[i++] = clib_host_to_net_u32 (p->key);
1587 }));
1588 });
1589 /* *INDENT-ON* */
1590
1591 hash_free (bds);
1592}
1593
1594static void
Filip Tehlard5a65db2017-05-17 17:21:10 +02001595vl_api_one_l2_arp_bd_get_t_handler (vl_api_one_l2_arp_bd_get_t * mp)
1596{
1597 vl_api_one_l2_arp_bd_get_reply_t *rmp;
1598 int rv = 0;
1599 u32 i = 0;
1600 hash_pair_t *p;
1601
1602 u32 *bds = vnet_lisp_l2_arp_bds_get ();
1603 u32 size = hash_elts (bds) * sizeof (u32);
1604
1605 /* *INDENT-OFF* */
1606 REPLY_MACRO4 (VL_API_ONE_L2_ARP_BD_GET_REPLY, size,
1607 {
1608 rmp->count = clib_host_to_net_u32 (hash_elts (bds));
1609 hash_foreach_pair (p, bds,
1610 ({
1611 rmp->bridge_domains[i++] = clib_host_to_net_u32 (p->key);
1612 }));
1613 });
1614 /* *INDENT-ON* */
1615
1616 hash_free (bds);
1617}
1618
1619static void
1620vl_api_one_l2_arp_entries_get_t_handler (vl_api_one_l2_arp_entries_get_t * mp)
1621{
1622 vl_api_one_l2_arp_entries_get_reply_t *rmp;
1623 lisp_api_l2_arp_entry_t *entries = 0, *e;
1624 u32 i = 0;
1625 int rv = 0;
1626
1627 u32 bd = clib_net_to_host_u32 (mp->bd);
1628
1629 entries = vnet_lisp_l2_arp_entries_get_by_bd (bd);
Ole Troan1d7d2ab2017-07-06 14:25:38 +02001630 u32 size = vec_len (entries) * sizeof (vl_api_one_l2_arp_entry_t);
Filip Tehlard5a65db2017-05-17 17:21:10 +02001631
1632 /* *INDENT-OFF* */
1633 REPLY_MACRO4 (VL_API_ONE_L2_ARP_ENTRIES_GET_REPLY, size,
1634 {
1635 rmp->count = clib_host_to_net_u32 (vec_len (entries));
1636 vec_foreach (e, entries)
1637 {
1638 mac_copy (rmp->entries[i].mac, e->mac);
1639 rmp->entries[i].ip4 = e->ip4;
1640 i++;
1641 }
1642 });
1643 /* *INDENT-ON* */
1644
1645 vec_free (entries);
1646}
1647
Filip Tehlar7048ff12017-07-27 08:09:14 +02001648static void
1649 vl_api_one_map_register_fallback_threshold_t_handler
1650 (vl_api_one_map_register_fallback_threshold_t * mp)
1651{
1652 vl_api_one_map_register_fallback_threshold_reply_t *rmp;
1653 int rv = 0;
1654
1655 mp->value = clib_net_to_host_u32 (mp->value);
1656 rv = vnet_lisp_map_register_fallback_threshold_set (mp->value);
Filip Tehlar6f9f6f32017-08-08 13:11:22 +02001657 REPLY_MACRO (VL_API_ONE_MAP_REGISTER_FALLBACK_THRESHOLD_REPLY);
Filip Tehlar7048ff12017-07-27 08:09:14 +02001658}
1659
1660static void
1661 vl_api_show_one_map_register_fallback_threshold_t_handler
1662 (vl_api_show_one_map_register_fallback_threshold_t * mp)
1663{
1664 vl_api_show_one_map_register_fallback_threshold_reply_t *rmp;
1665 int rv = 0;
1666
1667 u32 value = vnet_lisp_map_register_fallback_threshold_get ();
1668
1669 /* *INDENT-OFF* */
1670 REPLY_MACRO2 (VL_API_SHOW_ONE_MAP_REGISTER_FALLBACK_THRESHOLD_REPLY,
1671 ({
1672 rmp->value = clib_host_to_net_u32 (value);
1673 }));
1674 /* *INDENT-ON* */
1675}
1676
Filip Tehlar05879992017-09-05 15:46:09 +02001677static void
Filip Tehlara4980b82017-09-27 14:32:02 +02001678 vl_api_one_set_transport_protocol_t_handler
1679 (vl_api_one_set_transport_protocol_t * mp)
1680{
1681 vl_api_one_set_transport_protocol_reply_t *rmp;
1682 int rv = 0;
1683
1684 rv = vnet_lisp_set_transport_protocol (mp->protocol);
1685
1686 REPLY_MACRO (VL_API_ONE_SET_TRANSPORT_PROTOCOL_REPLY);
1687}
1688
1689static void
1690 vl_api_one_get_transport_protocol_t_handler
1691 (vl_api_one_get_transport_protocol_t * mp)
1692{
1693 vl_api_one_get_transport_protocol_reply_t *rmp;
1694 int rv = 0;
1695 u8 proto = (u8) vnet_lisp_get_transport_protocol ();
1696
1697 /* *INDENT-OFF* */
1698 REPLY_MACRO2 (VL_API_ONE_GET_TRANSPORT_PROTOCOL_REPLY,
1699 ({
1700 rmp->protocol = proto;
1701 }));
1702 /* *INDENT-ON* */
1703}
1704
1705static void
Filip Tehlar05879992017-09-05 15:46:09 +02001706vl_api_one_ndp_entries_get_t_handler (vl_api_one_ndp_entries_get_t * mp)
1707{
1708 vl_api_one_ndp_entries_get_reply_t *rmp = 0;
1709 lisp_api_ndp_entry_t *entries = 0, *e;
1710 u32 i = 0;
1711 int rv = 0;
1712
1713 u32 bd = clib_net_to_host_u32 (mp->bd);
1714
1715 entries = vnet_lisp_ndp_entries_get_by_bd (bd);
1716 u32 size = vec_len (entries) * sizeof (vl_api_one_ndp_entry_t);
1717
1718 /* *INDENT-OFF* */
1719 REPLY_MACRO4 (VL_API_ONE_NDP_ENTRIES_GET_REPLY, size,
1720 {
1721 rmp->count = clib_host_to_net_u32 (vec_len (entries));
1722 vec_foreach (e, entries)
1723 {
1724 mac_copy (rmp->entries[i].mac, e->mac);
1725 clib_memcpy (rmp->entries[i].ip6, e->ip6, 16);
1726 i++;
1727 }
1728 });
1729 /* *INDENT-ON* */
1730
1731 vec_free (entries);
1732}
1733
Filip Tehlar0a8840d2017-10-16 05:48:23 -07001734static void
1735 vl_api_one_enable_disable_xtr_mode_t_handler
1736 (vl_api_one_enable_disable_xtr_mode_t * mp)
1737{
1738 vl_api_one_enable_disable_xtr_mode_reply_t *rmp = 0;
1739 int rv = vnet_lisp_enable_disable_xtr_mode (mp->is_en);
1740
1741 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_XTR_MODE_REPLY);
1742}
1743
1744static void
1745vl_api_one_show_xtr_mode_t_handler (vl_api_one_show_xtr_mode_t * mp)
1746{
1747 vl_api_one_show_xtr_mode_reply_t *rmp = 0;
1748 int rv = 0;
1749
1750 /* *INDENT-OFF* */
1751 REPLY_MACRO2 (VL_API_ONE_SHOW_XTR_MODE_REPLY,
1752 {
1753 rmp->is_en = vnet_lisp_get_xtr_mode ();
1754 });
1755 /* *INDENT-ON* */
1756}
1757
1758static void
1759 vl_api_one_enable_disable_pitr_mode_t_handler
1760 (vl_api_one_enable_disable_pitr_mode_t * mp)
1761{
1762 vl_api_one_enable_disable_pitr_mode_reply_t *rmp = 0;
1763 int rv = vnet_lisp_enable_disable_pitr_mode (mp->is_en);
1764
1765 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_PITR_MODE_REPLY);
1766}
1767
1768static void
1769vl_api_one_show_pitr_mode_t_handler (vl_api_one_show_pitr_mode_t * mp)
1770{
1771 vl_api_one_show_pitr_mode_reply_t *rmp = 0;
1772 int rv = 0;
1773
1774 /* *INDENT-OFF* */
1775 REPLY_MACRO2 (VL_API_ONE_SHOW_PITR_MODE_REPLY,
1776 {
1777 rmp->is_en = vnet_lisp_get_pitr_mode ();
1778 });
1779 /* *INDENT-ON* */
1780}
1781
1782static void
1783 vl_api_one_enable_disable_petr_mode_t_handler
1784 (vl_api_one_enable_disable_petr_mode_t * mp)
1785{
1786 vl_api_one_enable_disable_petr_mode_reply_t *rmp = 0;
1787 int rv = vnet_lisp_enable_disable_petr_mode (mp->is_en);
1788
1789 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_PETR_MODE_REPLY);
1790}
1791
1792static void
1793vl_api_one_show_petr_mode_t_handler (vl_api_one_show_petr_mode_t * mp)
1794{
1795 vl_api_one_show_petr_mode_reply_t *rmp = 0;
1796 int rv = 0;
1797
1798 /* *INDENT-OFF* */
1799 REPLY_MACRO2 (VL_API_ONE_SHOW_PETR_MODE_REPLY,
1800 {
1801 rmp->is_en = vnet_lisp_get_petr_mode ();
1802 });
1803 /* *INDENT-ON* */
1804}
1805
Filip Tehlar694396d2017-02-17 14:29:11 +01001806/*
1807 * one_api_hookup
1808 * Add vpe's API message handlers to the table.
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -07001809 * vlib has already mapped shared memory and
Filip Tehlar694396d2017-02-17 14:29:11 +01001810 * added the client registration handlers.
1811 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
1812 */
1813#define vl_msg_name_crc_list
1814#include <vnet/vnet_all_api_h.h>
1815#undef vl_msg_name_crc_list
1816
1817static void
1818setup_message_id_table (api_main_t * am)
1819{
1820#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
Filip Tehlar974cdc62017-02-22 18:09:49 +01001821 foreach_vl_msg_name_crc_one;
Filip Tehlar694396d2017-02-17 14:29:11 +01001822#undef _
1823}
1824
1825static clib_error_t *
1826one_api_hookup (vlib_main_t * vm)
1827{
1828 api_main_t *am = &api_main;
1829
1830#define _(N,n) \
1831 vl_msg_api_set_handlers(VL_API_##N, #n, \
1832 vl_api_##n##_t_handler, \
1833 vl_noop_handler, \
1834 vl_api_##n##_t_endian, \
1835 vl_api_##n##_t_print, \
1836 sizeof(vl_api_##n##_t), 1);
1837 foreach_vpe_api_msg;
1838#undef _
1839
1840 /*
1841 * Set up the (msg_name, crc, message-id) table
1842 */
1843 setup_message_id_table (am);
1844
1845 return 0;
1846}
1847
1848VLIB_API_INIT_FUNCTION (one_api_hookup);
1849
1850/*
1851 * fd.io coding-style-patch-verification: ON
1852 *
1853 * Local Variables:
1854 * eval: (c-set-style "gnu")
1855 * End:
1856 */