blob: 447b68f377c0d69b7ecc79c6b52d8847edb3ae77 [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 Tehlar694396d2017-02-17 14:29:11 +010030#define vl_api_one_add_del_locator_set_t_endian vl_noop_handler
31#define vl_api_one_add_del_locator_set_t_print vl_noop_handler
32#define vl_api_one_add_del_remote_mapping_t_endian vl_noop_handler
33#define vl_api_one_add_del_remote_mapping_t_print vl_noop_handler
34
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
Filip Tehlard5a65db2017-05-17 17:21:10 +020040#define vl_api_one_add_del_l2_arp_entry vl_noop_handler
41#define vl_api_one_l2_arp_bd_get vl_noop_handler
42
Filip Tehlard6307132017-09-04 18:54:33 +020043#define vl_api_one_ndp_entries_get_reply_t_endian vl_noop_handler
44#define vl_api_one_ndp_entries_get_reply_t_print vl_noop_handler
45
Filip Tehlar694396d2017-02-17 14:29:11 +010046#define vl_typedefs /* define message structures */
47#include <vnet/vnet_all_api_h.h>
48#undef vl_typedefs
49
50#define vl_endianfun /* define message structures */
51#include <vnet/vnet_all_api_h.h>
52#undef vl_endianfun
53
54/* instantiate all the print functions we know about */
55#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
56#define vl_printfun
57#include <vnet/vnet_all_api_h.h>
58#undef vl_printfun
59
60#include <vlibapi/api_helper_macros.h>
61
Florin Coras6c4dae22018-01-09 06:39:23 -080062#define REPLY_DETAILS(t, body) \
63do { \
64 vl_api_registration_t * reg; \
65 rv = vl_msg_api_pd_handler (mp, rv); \
66 reg = vl_api_client_index_to_registration (mp->client_index); \
67 if (!reg) \
68 return; \
69 \
70 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
71 rmp->_vl_msg_id = ntohs((t)); \
72 rmp->context = mp->context; \
73 do {body;} while (0); \
74 vl_api_send_msg (reg, (u8 *)&rmp); \
Filip Tehlar4868ff62017-03-09 16:48:39 +010075} while(0);
76
Florin Coras6c4dae22018-01-09 06:39:23 -080077#define foreach_vpe_api_msg \
Filip Tehlar694396d2017-02-17 14:29:11 +010078_(ONE_ADD_DEL_LOCATOR_SET, one_add_del_locator_set) \
79_(ONE_ADD_DEL_LOCATOR, one_add_del_locator) \
80_(ONE_ADD_DEL_LOCAL_EID, one_add_del_local_eid) \
81_(ONE_ADD_DEL_MAP_RESOLVER, one_add_del_map_resolver) \
82_(ONE_ADD_DEL_MAP_SERVER, one_add_del_map_server) \
83_(ONE_ENABLE_DISABLE, one_enable_disable) \
84_(ONE_RLOC_PROBE_ENABLE_DISABLE, one_rloc_probe_enable_disable) \
85_(ONE_MAP_REGISTER_ENABLE_DISABLE, one_map_register_enable_disable) \
Filip Tehlar7048ff12017-07-27 08:09:14 +020086_(ONE_MAP_REGISTER_FALLBACK_THRESHOLD, \
87 one_map_register_fallback_threshold) \
Filip Tehlar694396d2017-02-17 14:29:11 +010088_(ONE_ADD_DEL_REMOTE_MAPPING, one_add_del_remote_mapping) \
89_(ONE_ADD_DEL_ADJACENCY, one_add_del_adjacency) \
90_(ONE_PITR_SET_LOCATOR_SET, one_pitr_set_locator_set) \
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020091_(ONE_NSH_SET_LOCATOR_SET, one_nsh_set_locator_set) \
Filip Tehlar694396d2017-02-17 14:29:11 +010092_(ONE_MAP_REQUEST_MODE, one_map_request_mode) \
93_(ONE_EID_TABLE_ADD_DEL_MAP, one_eid_table_add_del_map) \
94_(ONE_LOCATOR_SET_DUMP, one_locator_set_dump) \
95_(ONE_LOCATOR_DUMP, one_locator_dump) \
96_(ONE_EID_TABLE_DUMP, one_eid_table_dump) \
97_(ONE_MAP_RESOLVER_DUMP, one_map_resolver_dump) \
98_(ONE_MAP_SERVER_DUMP, one_map_server_dump) \
99_(ONE_EID_TABLE_MAP_DUMP, one_eid_table_map_dump) \
100_(ONE_EID_TABLE_VNI_DUMP, one_eid_table_vni_dump) \
101_(ONE_ADJACENCIES_GET, one_adjacencies_get) \
Filip Tehlar1e553a02017-08-02 12:45:07 +0200102_(ONE_MAP_REGISTER_SET_TTL, one_map_register_set_ttl) \
Filip Tehlaref2a5bf2017-05-30 07:14:46 +0200103_(SHOW_ONE_NSH_MAPPING, show_one_nsh_mapping) \
Filip Tehlar694396d2017-02-17 14:29:11 +0100104_(SHOW_ONE_RLOC_PROBE_STATE, show_one_rloc_probe_state) \
105_(SHOW_ONE_MAP_REGISTER_STATE, show_one_map_register_state) \
Filip Tehlar1e553a02017-08-02 12:45:07 +0200106_(SHOW_ONE_MAP_REGISTER_TTL, show_one_map_register_ttl) \
Filip Tehlar7048ff12017-07-27 08:09:14 +0200107_(SHOW_ONE_MAP_REGISTER_FALLBACK_THRESHOLD, \
108 show_one_map_register_fallback_threshold) \
Filip Tehlar694396d2017-02-17 14:29:11 +0100109_(SHOW_ONE_STATUS, show_one_status) \
110_(ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \
111 one_add_del_map_request_itr_rlocs) \
112_(ONE_GET_MAP_REQUEST_ITR_RLOCS, one_get_map_request_itr_rlocs) \
113_(SHOW_ONE_PITR, show_one_pitr) \
114_(SHOW_ONE_MAP_REQUEST_MODE, show_one_map_request_mode) \
115_(ONE_USE_PETR, one_use_petr) \
116_(SHOW_ONE_USE_PETR, show_one_use_petr) \
Filip Tehlar7eaf0e52017-03-08 08:46:51 +0100117_(SHOW_ONE_STATS_ENABLE_DISABLE, show_one_stats_enable_disable) \
118_(ONE_STATS_ENABLE_DISABLE, one_stats_enable_disable) \
119_(ONE_STATS_DUMP, one_stats_dump) \
Filip Tehlar21511912017-04-07 10:41:42 +0200120_(ONE_STATS_FLUSH, one_stats_flush) \
Filip Tehlard5a65db2017-05-17 17:21:10 +0200121_(ONE_L2_ARP_BD_GET, one_l2_arp_bd_get) \
122_(ONE_L2_ARP_ENTRIES_GET, one_l2_arp_entries_get) \
123_(ONE_ADD_DEL_L2_ARP_ENTRY, one_add_del_l2_arp_entry) \
Filip Tehlar05879992017-09-05 15:46:09 +0200124_(ONE_ADD_DEL_NDP_ENTRY, one_add_del_ndp_entry) \
125_(ONE_NDP_BD_GET, one_ndp_bd_get) \
126_(ONE_NDP_ENTRIES_GET, one_ndp_entries_get) \
Filip Tehlara4980b82017-09-27 14:32:02 +0200127_(ONE_SET_TRANSPORT_PROTOCOL, one_set_transport_protocol) \
Filip Tehlar0a8840d2017-10-16 05:48:23 -0700128_(ONE_GET_TRANSPORT_PROTOCOL, one_get_transport_protocol) \
129_(ONE_ENABLE_DISABLE_XTR_MODE, one_enable_disable_xtr_mode) \
130_(ONE_SHOW_XTR_MODE, one_show_xtr_mode) \
131_(ONE_ENABLE_DISABLE_PITR_MODE, one_enable_disable_pitr_mode) \
132_(ONE_SHOW_PITR_MODE, one_show_pitr_mode) \
133_(ONE_ENABLE_DISABLE_PETR_MODE, one_enable_disable_petr_mode) \
134_(ONE_SHOW_PETR_MODE, one_show_petr_mode) \
135
Filip Tehlar694396d2017-02-17 14:29:11 +0100136
137static locator_t *
Filip Tehlar974cdc62017-02-22 18:09:49 +0100138unformat_one_locs (vl_api_one_remote_locator_t * rmt_locs, u32 rloc_num)
Filip Tehlar694396d2017-02-17 14:29:11 +0100139{
140 u32 i;
141 locator_t *locs = 0, loc;
Filip Tehlar974cdc62017-02-22 18:09:49 +0100142 vl_api_one_remote_locator_t *r;
Filip Tehlar694396d2017-02-17 14:29:11 +0100143
144 for (i = 0; i < rloc_num; i++)
145 {
146 /* remote locators */
147 r = &rmt_locs[i];
Dave Barachb7b92992018-10-17 10:38:51 -0400148 clib_memset (&loc, 0, sizeof (loc));
Filip Tehlar694396d2017-02-17 14:29:11 +0100149 gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
150
151 loc.priority = r->priority;
152 loc.weight = r->weight;
153
154 vec_add1 (locs, loc);
155 }
156 return locs;
157}
158
159static void
Filip Tehlar1e553a02017-08-02 12:45:07 +0200160vl_api_one_map_register_set_ttl_t_handler (vl_api_one_map_register_set_ttl_t *
161 mp)
162{
163 vl_api_one_map_register_set_ttl_reply_t *rmp;
164 int rv = 0;
165
Filip Tehlar5391e192017-08-04 09:13:50 +0200166 mp->ttl = clib_net_to_host_u32 (mp->ttl);
Filip Tehlar1e553a02017-08-02 12:45:07 +0200167 rv = vnet_lisp_map_register_set_ttl (mp->ttl);
168
169 REPLY_MACRO (VL_API_ONE_MAP_REGISTER_SET_TTL_REPLY);
170}
171
172static void
173 vl_api_show_one_map_register_ttl_t_handler
174 (vl_api_show_one_map_register_ttl_t * mp)
175{
176 vl_api_show_one_map_register_ttl_reply_t *rmp;
177 int rv = 0;
178
179 u32 ttl = vnet_lisp_map_register_get_ttl ();
180 /* *INDENT-OFF* */
181 REPLY_MACRO2 (VL_API_SHOW_ONE_MAP_REGISTER_TTL_REPLY,
182 ({
183 rmp->ttl = clib_host_to_net_u32 (ttl);
184 }));
185 /* *INDENT-ON* */
186}
187
188static void
Filip Tehlar694396d2017-02-17 14:29:11 +0100189vl_api_one_add_del_locator_set_t_handler (vl_api_one_add_del_locator_set_t *
190 mp)
191{
192 vl_api_one_add_del_locator_set_reply_t *rmp;
193 int rv = 0;
194 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
195 locator_t locator;
Filip Tehlar974cdc62017-02-22 18:09:49 +0100196 vl_api_one_local_locator_t *ls_loc;
Filip Tehlar694396d2017-02-17 14:29:11 +0100197 u32 ls_index = ~0, locator_num;
198 u8 *locator_name = NULL;
199 int i;
200
Dave Barachb7b92992018-10-17 10:38:51 -0400201 clib_memset (a, 0, sizeof (a[0]));
Filip Tehlar694396d2017-02-17 14:29:11 +0100202
Filip Tehlar9d286a42017-10-26 23:57:09 -0700203 mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0;
Filip Tehlar694396d2017-02-17 14:29:11 +0100204 locator_name = format (0, "%s", mp->locator_set_name);
Gabriel Ganne3491d7f2017-10-19 15:10:46 +0200205 vec_terminate_c_string (locator_name);
Filip Tehlar694396d2017-02-17 14:29:11 +0100206
207 a->name = locator_name;
208 a->is_add = mp->is_add;
209 a->local = 1;
210 locator_num = clib_net_to_host_u32 (mp->locator_num);
211
Dave Barachb7b92992018-10-17 10:38:51 -0400212 clib_memset (&locator, 0, sizeof (locator));
Filip Tehlar694396d2017-02-17 14:29:11 +0100213 for (i = 0; i < locator_num; i++)
214 {
215 ls_loc = &mp->locators[i];
216 VALIDATE_SW_IF_INDEX (ls_loc);
217
218 locator.sw_if_index = htonl (ls_loc->sw_if_index);
219 locator.priority = ls_loc->priority;
220 locator.weight = ls_loc->weight;
221 locator.local = 1;
222 vec_add1 (a->locators, locator);
223 }
224
225 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
226
227 BAD_SW_IF_INDEX_LABEL;
228
229 vec_free (locator_name);
230 vec_free (a->locators);
231
232 /* *INDENT-OFF* */
233 REPLY_MACRO2 (VL_API_ONE_ADD_DEL_LOCATOR_SET_REPLY,
234 ({
235 rmp->ls_index = clib_host_to_net_u32 (ls_index);
236 }));
237 /* *INDENT-ON* */
238}
239
240static void
241vl_api_one_add_del_locator_t_handler (vl_api_one_add_del_locator_t * mp)
242{
243 vl_api_one_add_del_locator_reply_t *rmp;
244 int rv = 0;
245 locator_t locator, *locators = NULL;
246 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
247 u32 ls_index = ~0;
248 u8 *locator_name = NULL;
249
Dave Barachb7b92992018-10-17 10:38:51 -0400250 clib_memset (&locator, 0, sizeof (locator));
251 clib_memset (a, 0, sizeof (a[0]));
Filip Tehlar694396d2017-02-17 14:29:11 +0100252
253 locator.sw_if_index = ntohl (mp->sw_if_index);
254 locator.priority = mp->priority;
255 locator.weight = mp->weight;
256 locator.local = 1;
257 vec_add1 (locators, locator);
258
Filip Tehlar9d286a42017-10-26 23:57:09 -0700259 mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0;
Filip Tehlar694396d2017-02-17 14:29:11 +0100260 locator_name = format (0, "%s", mp->locator_set_name);
Gabriel Ganne3491d7f2017-10-19 15:10:46 +0200261 vec_terminate_c_string (locator_name);
Filip Tehlar694396d2017-02-17 14:29:11 +0100262
263 a->name = locator_name;
264 a->locators = locators;
265 a->is_add = mp->is_add;
266 a->local = 1;
267
268 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
269
270 vec_free (locators);
271 vec_free (locator_name);
272
273 REPLY_MACRO (VL_API_ONE_ADD_DEL_LOCATOR_REPLY);
274}
275
Filip Tehlaref2a5bf2017-05-30 07:14:46 +0200276typedef struct
277{
278 u32 spi;
279 u8 si;
280} __attribute__ ((__packed__)) lisp_nsh_api_t;
281
Filip Tehlar694396d2017-02-17 14:29:11 +0100282static int
283unformat_one_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
284 u8 len)
285{
Filip Tehlaref2a5bf2017-05-30 07:14:46 +0200286 lisp_nsh_api_t *nsh;
287
Filip Tehlar694396d2017-02-17 14:29:11 +0100288 switch (type)
289 {
290 case 0: /* ipv4 */
291 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
292 gid_address_ip_set (dst, src, IP4);
293 gid_address_ippref_len (dst) = len;
294 ip_prefix_normalize (&gid_address_ippref (dst));
295 break;
296 case 1: /* ipv6 */
297 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
298 gid_address_ip_set (dst, src, IP6);
299 gid_address_ippref_len (dst) = len;
300 ip_prefix_normalize (&gid_address_ippref (dst));
301 break;
302 case 2: /* l2 mac */
303 gid_address_type (dst) = GID_ADDR_MAC;
304 clib_memcpy (&gid_address_mac (dst), src, 6);
305 break;
Filip Tehlaref2a5bf2017-05-30 07:14:46 +0200306 case 3: /* NSH */
307 gid_address_type (dst) = GID_ADDR_NSH;
308 nsh = src;
309 gid_address_nsh_spi (dst) = clib_net_to_host_u32 (nsh->spi);
310 gid_address_nsh_si (dst) = nsh->si;
311 break;
Filip Tehlar694396d2017-02-17 14:29:11 +0100312 default:
313 /* unknown type */
314 return VNET_API_ERROR_INVALID_VALUE;
315 }
316
317 gid_address_vni (dst) = vni;
318
319 return 0;
320}
321
322static void
323vl_api_one_add_del_local_eid_t_handler (vl_api_one_add_del_local_eid_t * mp)
324{
325 vl_api_one_add_del_local_eid_reply_t *rmp;
326 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
327 int rv = 0;
328 gid_address_t _eid, *eid = &_eid;
329 uword *p = NULL;
330 u32 locator_set_index = ~0, map_index = ~0;
331 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
332 u8 *name = NULL, *key = NULL;
Dave Barachb7b92992018-10-17 10:38:51 -0400333 clib_memset (a, 0, sizeof (a[0]));
334 clib_memset (eid, 0, sizeof (eid[0]));
Filip Tehlar694396d2017-02-17 14:29:11 +0100335
336 rv = unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
337 mp->eid_type, mp->eid, mp->prefix_len);
338 if (rv)
339 goto out;
340
Filip Tehlaref2a5bf2017-05-30 07:14:46 +0200341 if (gid_address_type (eid) == GID_ADDR_NSH)
342 {
343 rv = VNET_API_ERROR_INVALID_VALUE;
344 goto out;
345 }
346
Filip Tehlar9d286a42017-10-26 23:57:09 -0700347 mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0;
Filip Tehlar694396d2017-02-17 14:29:11 +0100348 name = format (0, "%s", mp->locator_set_name);
Gabriel Ganne3491d7f2017-10-19 15:10:46 +0200349 vec_terminate_c_string (name);
Filip Tehlar694396d2017-02-17 14:29:11 +0100350 p = hash_get_mem (lcm->locator_set_index_by_name, name);
351 if (!p)
352 {
353 rv = VNET_API_ERROR_INVALID_VALUE;
354 goto out;
355 }
356 locator_set_index = p[0];
357
358 if (*mp->key)
359 key = format (0, "%s", mp->key);
360
361 /* XXX treat batch configuration */
362 a->is_add = mp->is_add;
363 gid_address_copy (&a->eid, eid);
364 a->locator_set_index = locator_set_index;
365 a->local = 1;
366 a->key = key;
367 a->key_id = clib_net_to_host_u16 (mp->key_id);
368
369 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
370
371out:
372 vec_free (name);
373 vec_free (key);
374 gid_address_free (&a->eid);
375
376 REPLY_MACRO (VL_API_ONE_ADD_DEL_LOCAL_EID_REPLY);
377}
378
379static void
380 vl_api_one_eid_table_add_del_map_t_handler
381 (vl_api_one_eid_table_add_del_map_t * mp)
382{
383 vl_api_one_eid_table_add_del_map_reply_t *rmp;
384 int rv = 0;
385 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
386 clib_net_to_host_u32 (mp->dp_table),
387 mp->is_l2, mp->is_add);
388REPLY_MACRO (VL_API_ONE_EID_TABLE_ADD_DEL_MAP_REPLY)}
389
390static void
391vl_api_one_add_del_map_server_t_handler (vl_api_one_add_del_map_server_t * mp)
392{
393 vl_api_one_add_del_map_server_reply_t *rmp;
394 int rv = 0;
395 ip_address_t addr;
396
Dave Barachb7b92992018-10-17 10:38:51 -0400397 clib_memset (&addr, 0, sizeof (addr));
Filip Tehlar694396d2017-02-17 14:29:11 +0100398
399 ip_address_set (&addr, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
400 rv = vnet_lisp_add_del_map_server (&addr, mp->is_add);
401
402 REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_SERVER_REPLY);
403}
404
405static void
406vl_api_one_add_del_map_resolver_t_handler (vl_api_one_add_del_map_resolver_t
407 * mp)
408{
409 vl_api_one_add_del_map_resolver_reply_t *rmp;
410 int rv = 0;
411 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
412
Dave Barachb7b92992018-10-17 10:38:51 -0400413 clib_memset (a, 0, sizeof (a[0]));
Filip Tehlar694396d2017-02-17 14:29:11 +0100414
415 a->is_add = mp->is_add;
416 ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
417
418 rv = vnet_lisp_add_del_map_resolver (a);
419
420 REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_RESOLVER_REPLY);
421}
422
423static void
424 vl_api_one_map_register_enable_disable_t_handler
425 (vl_api_one_map_register_enable_disable_t * mp)
426{
427 vl_api_one_map_register_enable_disable_reply_t *rmp;
428 int rv = 0;
429
430 vnet_lisp_map_register_enable_disable (mp->is_enabled);
431 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
432}
433
434static void
435 vl_api_one_rloc_probe_enable_disable_t_handler
436 (vl_api_one_rloc_probe_enable_disable_t * mp)
437{
438 vl_api_one_rloc_probe_enable_disable_reply_t *rmp;
439 int rv = 0;
440
441 vnet_lisp_rloc_probe_enable_disable (mp->is_enabled);
442 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
443}
444
445static void
446vl_api_one_enable_disable_t_handler (vl_api_one_enable_disable_t * mp)
447{
448 vl_api_one_enable_disable_reply_t *rmp;
449 int rv = 0;
450
451 vnet_lisp_enable_disable (mp->is_en);
452 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
453}
454
455static void
456 vl_api_show_one_map_request_mode_t_handler
457 (vl_api_show_one_map_request_mode_t * mp)
458{
459 int rv = 0;
460 vl_api_show_one_map_request_mode_reply_t *rmp;
461
462 /* *INDENT-OFF* */
463 REPLY_MACRO2(VL_API_SHOW_ONE_MAP_REQUEST_MODE_REPLY,
464 ({
465 rmp->mode = vnet_lisp_get_map_request_mode ();
466 }));
467 /* *INDENT-ON* */
468}
469
470static void
471vl_api_one_map_request_mode_t_handler (vl_api_one_map_request_mode_t * mp)
472{
473 vl_api_one_map_request_mode_reply_t *rmp;
474 int rv = 0;
475
476 rv = vnet_lisp_set_map_request_mode (mp->mode);
477
478 REPLY_MACRO (VL_API_ONE_MAP_REQUEST_MODE_REPLY);
479}
480
481static void
Filip Tehlaref2a5bf2017-05-30 07:14:46 +0200482vl_api_one_nsh_set_locator_set_t_handler (vl_api_one_nsh_set_locator_set_t
483 * mp)
484{
485 vl_api_one_nsh_set_locator_set_reply_t *rmp;
486 int rv = 0;
487 u8 *ls_name = 0;
488
Filip Tehlar9d286a42017-10-26 23:57:09 -0700489 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
Filip Tehlaref2a5bf2017-05-30 07:14:46 +0200490 ls_name = format (0, "%s", mp->ls_name);
Gabriel Ganne3491d7f2017-10-19 15:10:46 +0200491 vec_terminate_c_string (ls_name);
Filip Tehlaref2a5bf2017-05-30 07:14:46 +0200492 rv = vnet_lisp_nsh_set_locator_set (ls_name, mp->is_add);
493 vec_free (ls_name);
494
495 REPLY_MACRO (VL_API_ONE_PITR_SET_LOCATOR_SET_REPLY);
496}
497
498static void
Filip Tehlar694396d2017-02-17 14:29:11 +0100499vl_api_one_pitr_set_locator_set_t_handler (vl_api_one_pitr_set_locator_set_t
500 * mp)
501{
502 vl_api_one_pitr_set_locator_set_reply_t *rmp;
503 int rv = 0;
504 u8 *ls_name = 0;
505
Filip Tehlar9d286a42017-10-26 23:57:09 -0700506 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
Filip Tehlar694396d2017-02-17 14:29:11 +0100507 ls_name = format (0, "%s", mp->ls_name);
Gabriel Ganne3491d7f2017-10-19 15:10:46 +0200508 vec_terminate_c_string (ls_name);
Filip Tehlar694396d2017-02-17 14:29:11 +0100509 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
510 vec_free (ls_name);
511
512 REPLY_MACRO (VL_API_ONE_PITR_SET_LOCATOR_SET_REPLY);
513}
514
515static void
516vl_api_one_use_petr_t_handler (vl_api_one_use_petr_t * mp)
517{
518 vl_api_one_use_petr_reply_t *rmp;
519 int rv = 0;
520 ip_address_t addr;
521
522 ip_address_set (&addr, &mp->address, mp->is_ip4 ? IP4 : IP6);
523 rv = vnet_lisp_use_petr (&addr, mp->is_add);
524
525 REPLY_MACRO (VL_API_ONE_USE_PETR_REPLY);
526}
527
528static void
529vl_api_show_one_use_petr_t_handler (vl_api_show_one_use_petr_t * mp)
530{
Filip Tehlar694396d2017-02-17 14:29:11 +0100531 vl_api_show_one_use_petr_reply_t *rmp = NULL;
532 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
533 mapping_t *m;
534 locator_set_t *ls = 0;
535 int rv = 0;
536 locator_t *loc = 0;
537 u8 status = 0;
538 gid_address_t addr;
539
Dave Barachb7b92992018-10-17 10:38:51 -0400540 clib_memset (&addr, 0, sizeof (addr));
Filip Tehlar694396d2017-02-17 14:29:11 +0100541 status = lcm->flags & LISP_FLAG_USE_PETR;
542 if (status)
543 {
544 m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index);
545 if (~0 != m->locator_set_index)
546 {
547 ls =
548 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
549 loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]);
550 gid_address_copy (&addr, &loc->address);
551 }
552 }
553
554 /* *INDENT-OFF* */
555 REPLY_MACRO2 (VL_API_SHOW_ONE_USE_PETR_REPLY,
556 {
Filip Tehlar67a99f82017-03-10 13:18:02 +0100557 rmp->status = status;
558 ip_address_t *ip = &gid_address_ip (&addr);
559 switch (ip_addr_version (ip))
560 {
561 case IP4:
562 clib_memcpy (rmp->address, &ip_addr_v4 (ip),
563 sizeof (ip_addr_v4 (ip)));
564 break;
565
566 case IP6:
567 clib_memcpy (rmp->address, &ip_addr_v6 (ip),
568 sizeof (ip_addr_v6 (ip)));
569 break;
570
571 default:
572 ASSERT (0);
573 }
574 rmp->is_ip4 = (gid_address_ip_version (&addr) == IP4);
Filip Tehlar694396d2017-02-17 14:29:11 +0100575 });
576 /* *INDENT-ON* */
577}
578
579static void
580 vl_api_one_add_del_map_request_itr_rlocs_t_handler
581 (vl_api_one_add_del_map_request_itr_rlocs_t * mp)
582{
583 vl_api_one_add_del_map_request_itr_rlocs_reply_t *rmp;
584 int rv = 0;
585 u8 *locator_set_name = NULL;
586 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
587
Filip Tehlar9d286a42017-10-26 23:57:09 -0700588 mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0;
Filip Tehlar694396d2017-02-17 14:29:11 +0100589 locator_set_name = format (0, "%s", mp->locator_set_name);
Gabriel Ganne3491d7f2017-10-19 15:10:46 +0200590 vec_terminate_c_string (locator_set_name);
Filip Tehlar694396d2017-02-17 14:29:11 +0100591
592 a->is_add = mp->is_add;
593 a->locator_set_name = locator_set_name;
594
595 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
596
597 vec_free (locator_set_name);
598
599 REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
600}
601
602static void
603 vl_api_one_add_del_remote_mapping_t_handler
604 (vl_api_one_add_del_remote_mapping_t * mp)
605{
606 locator_t *rlocs = 0;
607 vl_api_one_add_del_remote_mapping_reply_t *rmp;
608 int rv = 0;
609 gid_address_t _eid, *eid = &_eid;
610 u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
611
Dave Barachb7b92992018-10-17 10:38:51 -0400612 clib_memset (eid, 0, sizeof (eid[0]));
Filip Tehlar694396d2017-02-17 14:29:11 +0100613
614 rv = unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
615 mp->eid_type, mp->eid, mp->eid_len);
616 if (rv)
617 goto send_reply;
618
619 rlocs = unformat_one_locs (mp->rlocs, rloc_num);
620
621 if (!mp->is_add)
622 {
623 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
Dave Barachb7b92992018-10-17 10:38:51 -0400624 clib_memset (a, 0, sizeof (a[0]));
Filip Tehlar694396d2017-02-17 14:29:11 +0100625 gid_address_copy (&a->reid, eid);
626 a->is_add = 0;
627 rv = vnet_lisp_add_del_adjacency (a);
628 if (rv)
629 {
630 goto out;
631 }
632 }
633
634 /* NOTE: for now this works as a static remote mapping, i.e.,
635 * not authoritative and ttl infinite. */
Filip Tehlar809bc742017-08-14 19:15:36 +0200636 if (mp->is_add)
637 {
638 vnet_lisp_add_del_mapping_args_t _m_args, *m_args = &_m_args;
Dave Barachb7b92992018-10-17 10:38:51 -0400639 clib_memset (m_args, 0, sizeof (m_args[0]));
Filip Tehlar809bc742017-08-14 19:15:36 +0200640 gid_address_copy (&m_args->eid, eid);
641 m_args->action = mp->action;
642 m_args->is_static = 1;
643 m_args->ttl = ~0;
644 m_args->authoritative = 0;
645 rv = vnet_lisp_add_mapping (m_args, rlocs, NULL, NULL);
646 }
647 else
648 rv = vnet_lisp_del_mapping (eid, NULL);
Filip Tehlar694396d2017-02-17 14:29:11 +0100649
650 if (mp->del_all)
651 vnet_lisp_clear_all_remote_adjacencies ();
652
653out:
654 vec_free (rlocs);
655send_reply:
656 REPLY_MACRO (VL_API_ONE_ADD_DEL_REMOTE_MAPPING_REPLY);
657}
658
659static void
660vl_api_one_add_del_adjacency_t_handler (vl_api_one_add_del_adjacency_t * mp)
661{
662 vl_api_one_add_del_adjacency_reply_t *rmp;
663 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
664
665 int rv = 0;
Dave Barachb7b92992018-10-17 10:38:51 -0400666 clib_memset (a, 0, sizeof (a[0]));
Filip Tehlar694396d2017-02-17 14:29:11 +0100667
668 rv = unformat_one_eid_api (&a->leid, clib_net_to_host_u32 (mp->vni),
669 mp->eid_type, mp->leid, mp->leid_len);
670 rv |= unformat_one_eid_api (&a->reid, clib_net_to_host_u32 (mp->vni),
671 mp->eid_type, mp->reid, mp->reid_len);
672
673 if (rv)
674 goto send_reply;
675
676 a->is_add = mp->is_add;
677 rv = vnet_lisp_add_del_adjacency (a);
678
679send_reply:
680 REPLY_MACRO (VL_API_ONE_ADD_DEL_ADJACENCY_REPLY);
681}
682
683static void
684send_one_locator_details (lisp_cp_main_t * lcm,
Florin Coras6c4dae22018-01-09 06:39:23 -0800685 locator_t * loc, vl_api_registration_t * reg,
686 u32 context)
Filip Tehlar694396d2017-02-17 14:29:11 +0100687{
688 vl_api_one_locator_details_t *rmp;
689
690 rmp = vl_msg_api_alloc (sizeof (*rmp));
Dave Barachb7b92992018-10-17 10:38:51 -0400691 clib_memset (rmp, 0, sizeof (*rmp));
Filip Tehlar694396d2017-02-17 14:29:11 +0100692 rmp->_vl_msg_id = ntohs (VL_API_ONE_LOCATOR_DETAILS);
693 rmp->context = context;
694
695 rmp->local = loc->local;
696 if (loc->local)
697 {
698 rmp->sw_if_index = ntohl (loc->sw_if_index);
699 }
700 else
701 {
702 rmp->is_ipv6 = gid_address_ip_version (&loc->address);
703 ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
704 }
705 rmp->priority = loc->priority;
706 rmp->weight = loc->weight;
707
Florin Coras6c4dae22018-01-09 06:39:23 -0800708 vl_api_send_msg (reg, (u8 *) rmp);
Filip Tehlar694396d2017-02-17 14:29:11 +0100709}
710
711static void
712vl_api_one_locator_dump_t_handler (vl_api_one_locator_dump_t * mp)
713{
714 u8 *ls_name = 0;
Florin Coras6c4dae22018-01-09 06:39:23 -0800715 vl_api_registration_t *reg;
Filip Tehlar694396d2017-02-17 14:29:11 +0100716 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
717 locator_set_t *lsit = 0;
718 locator_t *loc = 0;
719 u32 ls_index = ~0, *locit = 0;
720 uword *p = 0;
721
Florin Coras6c4dae22018-01-09 06:39:23 -0800722 reg = vl_api_client_index_to_registration (mp->client_index);
723 if (!reg)
724 return;
Filip Tehlar694396d2017-02-17 14:29:11 +0100725
726 if (mp->is_index_set)
727 ls_index = htonl (mp->ls_index);
728 else
729 {
730 /* make sure we get a proper C-string */
731 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
732 ls_name = format (0, "%s", mp->ls_name);
Gabriel Ganne3491d7f2017-10-19 15:10:46 +0200733 vec_terminate_c_string (ls_name);
Filip Tehlar694396d2017-02-17 14:29:11 +0100734 p = hash_get_mem (lcm->locator_set_index_by_name, ls_name);
735 if (!p)
736 goto out;
737 ls_index = p[0];
738 }
739
740 if (pool_is_free_index (lcm->locator_set_pool, ls_index))
741 return;
742
743 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
744
745 vec_foreach (locit, lsit->locator_indices)
746 {
747 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
Florin Coras6c4dae22018-01-09 06:39:23 -0800748 send_one_locator_details (lcm, loc, reg, mp->context);
Filip Tehlar694396d2017-02-17 14:29:11 +0100749 };
750out:
751 vec_free (ls_name);
752}
753
754static void
755send_one_locator_set_details (lisp_cp_main_t * lcm,
756 locator_set_t * lsit,
Florin Coras6c4dae22018-01-09 06:39:23 -0800757 vl_api_registration_t * reg, u32 context,
758 u32 ls_index)
Filip Tehlar694396d2017-02-17 14:29:11 +0100759{
760 vl_api_one_locator_set_details_t *rmp;
761 u8 *str = 0;
762
763 rmp = vl_msg_api_alloc (sizeof (*rmp));
Dave Barachb7b92992018-10-17 10:38:51 -0400764 clib_memset (rmp, 0, sizeof (*rmp));
Filip Tehlar694396d2017-02-17 14:29:11 +0100765 rmp->_vl_msg_id = ntohs (VL_API_ONE_LOCATOR_SET_DETAILS);
766 rmp->context = context;
767
768 rmp->ls_index = htonl (ls_index);
769 if (lsit->local)
770 {
771 ASSERT (lsit->name != NULL);
772 strncpy ((char *) rmp->ls_name, (char *) lsit->name,
773 vec_len (lsit->name));
774 }
775 else
776 {
777 str = format (0, "<remote-%d>", ls_index);
778 strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str));
779 vec_free (str);
780 }
781
Florin Coras6c4dae22018-01-09 06:39:23 -0800782 vl_api_send_msg (reg, (u8 *) rmp);
Filip Tehlar694396d2017-02-17 14:29:11 +0100783}
784
785static void
786vl_api_one_locator_set_dump_t_handler (vl_api_one_locator_set_dump_t * mp)
787{
Florin Coras6c4dae22018-01-09 06:39:23 -0800788 vl_api_registration_t *reg;
Filip Tehlar694396d2017-02-17 14:29:11 +0100789 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
790 locator_set_t *lsit = NULL;
791 u8 filter;
792
Florin Coras6c4dae22018-01-09 06:39:23 -0800793 reg = vl_api_client_index_to_registration (mp->client_index);
794 if (!reg)
795 return;
Filip Tehlar694396d2017-02-17 14:29:11 +0100796
797 filter = mp->filter;
798 /* *INDENT-OFF* */
799 pool_foreach (lsit, lcm->locator_set_pool,
800 ({
801 if (filter && !((1 == filter && lsit->local) ||
802 (2 == filter && !lsit->local)))
803 {
804 continue;
805 }
Florin Coras6c4dae22018-01-09 06:39:23 -0800806 send_one_locator_set_details (lcm, lsit, reg, mp->context,
Filip Tehlar694396d2017-02-17 14:29:11 +0100807 lsit - lcm->locator_set_pool);
808 }));
809 /* *INDENT-ON* */
810}
811
812static void
813one_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length)
814{
815 ASSERT (prefix_length);
816 ip_prefix_t *ippref = &fid_addr_ippref (src);
817
818 switch (fid_addr_type (src))
819 {
820 case FID_ADDR_IP_PREF:
821 if (ip_prefix_version (ippref) == IP4)
822 clib_memcpy (dst, &ip_prefix_v4 (ippref), 4);
823 else
824 clib_memcpy (dst, &ip_prefix_v6 (ippref), 16);
825 prefix_length[0] = ip_prefix_len (ippref);
826 break;
827
828 case FID_ADDR_MAC:
829 prefix_length[0] = 0;
830 clib_memcpy (dst, fid_addr_mac (src), 6);
831 break;
832
833 default:
834 clib_warning ("Unknown FID type %d!", fid_addr_type (src));
835 break;
836 }
837}
838
839static u8
840fid_type_to_api_type (fid_address_t * fid)
841{
842 ip_prefix_t *ippref;
843
844 switch (fid_addr_type (fid))
845 {
846 case FID_ADDR_IP_PREF:
847 ippref = &fid_addr_ippref (fid);
848 if (ip_prefix_version (ippref) == IP4)
849 return 0;
850 else if (ip_prefix_version (ippref) == IP6)
851 return 1;
852 else
853 return ~0;
854
855 case FID_ADDR_MAC:
856 return 2;
857 case FID_ADDR_NSH:
858 return 3;
859 }
860
861 return ~0;
862}
863
864static void
865send_one_eid_table_details (mapping_t * mapit,
Florin Coras6c4dae22018-01-09 06:39:23 -0800866 vl_api_registration_t * reg, u32 context,
867 u8 filter)
Filip Tehlar694396d2017-02-17 14:29:11 +0100868{
869 fid_address_t *fid;
870 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
871 locator_set_t *ls = 0;
872 vl_api_one_eid_table_details_t *rmp = NULL;
873 gid_address_t *gid = NULL;
874 u8 *mac = 0;
875 ip_prefix_t *ip_prefix = NULL;
876
Filip Tehlaref2a5bf2017-05-30 07:14:46 +0200877 if (mapit->pitr_set || mapit->nsh_set)
Filip Tehlar1e8d01f2017-03-30 15:17:01 +0200878 return;
879
Filip Tehlar694396d2017-02-17 14:29:11 +0100880 switch (filter)
881 {
882 case 0: /* all mappings */
883 break;
884
885 case 1: /* local only */
886 if (!mapit->local)
887 return;
888 break;
889 case 2: /* remote only */
890 if (mapit->local)
891 return;
892 break;
893 default:
894 clib_warning ("Filter error, unknown filter: %d", filter);
895 return;
896 }
897
898 gid = &mapit->eid;
899 ip_prefix = &gid_address_ippref (gid);
900 mac = gid_address_mac (gid);
901
902 rmp = vl_msg_api_alloc (sizeof (*rmp));
Dave Barachb7b92992018-10-17 10:38:51 -0400903 clib_memset (rmp, 0, sizeof (*rmp));
Filip Tehlar694396d2017-02-17 14:29:11 +0100904 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_DETAILS);
905
906 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
907 if (vec_len (ls->locator_indices) == 0)
908 rmp->locator_set_index = ~0;
909 else
910 rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
911
912 rmp->is_local = mapit->local;
913 rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
914 rmp->action = mapit->action;
915 rmp->authoritative = mapit->authoritative;
916
917 switch (gid_address_type (gid))
918 {
919 case GID_ADDR_SRC_DST:
920 rmp->is_src_dst = 1;
921 fid = &gid_address_sd_src (gid);
922 rmp->eid_type = fid_type_to_api_type (fid);
923 one_fid_put_api (rmp->seid, &gid_address_sd_src (gid),
924 &rmp->seid_prefix_len);
925 one_fid_put_api (rmp->eid, &gid_address_sd_dst (gid),
926 &rmp->eid_prefix_len);
927 break;
928 case GID_ADDR_IP_PREFIX:
929 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
930 if (ip_prefix_version (ip_prefix) == IP4)
931 {
932 rmp->eid_type = 0; /* ipv4 type */
933 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
934 sizeof (ip_prefix_v4 (ip_prefix)));
935 }
936 else
937 {
938 rmp->eid_type = 1; /* ipv6 type */
939 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
940 sizeof (ip_prefix_v6 (ip_prefix)));
941 }
942 break;
943 case GID_ADDR_MAC:
944 rmp->eid_type = 2; /* l2 mac type */
945 clib_memcpy (rmp->eid, mac, 6);
946 break;
Filip Tehlaref2a5bf2017-05-30 07:14:46 +0200947 case GID_ADDR_NSH:
948 rmp->eid_type = 3; /* NSH type */
949 lisp_nsh_api_t nsh;
950 nsh.spi = clib_host_to_net_u32 (gid_address_nsh_spi (gid));
951 nsh.si = gid_address_nsh_si (gid);
952 clib_memcpy (rmp->eid, &nsh, sizeof (nsh));
953 break;
Filip Tehlar694396d2017-02-17 14:29:11 +0100954 default:
955 ASSERT (0);
956 }
957 rmp->context = context;
958 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
959 rmp->key_id = clib_host_to_net_u16 (mapit->key_id);
960 memcpy (rmp->key, mapit->key, vec_len (mapit->key));
Florin Coras6c4dae22018-01-09 06:39:23 -0800961 vl_api_send_msg (reg, (u8 *) rmp);
Filip Tehlar694396d2017-02-17 14:29:11 +0100962}
963
964static void
965vl_api_one_eid_table_dump_t_handler (vl_api_one_eid_table_dump_t * mp)
966{
967 u32 mi;
Florin Coras6c4dae22018-01-09 06:39:23 -0800968 vl_api_registration_t *reg;
Filip Tehlar694396d2017-02-17 14:29:11 +0100969 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
970 mapping_t *mapit = NULL;
971 gid_address_t _eid, *eid = &_eid;
972
Florin Coras6c4dae22018-01-09 06:39:23 -0800973 reg = vl_api_client_index_to_registration (mp->client_index);
974 if (!reg)
975 return;
Filip Tehlar694396d2017-02-17 14:29:11 +0100976
977 if (mp->eid_set)
978 {
Dave Barachb7b92992018-10-17 10:38:51 -0400979 clib_memset (eid, 0, sizeof (*eid));
Filip Tehlar694396d2017-02-17 14:29:11 +0100980
981 unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
982 mp->eid_type, mp->eid, mp->prefix_length);
983
984 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
985 if ((u32) ~ 0 == mi)
986 return;
987
988 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
Florin Coras6c4dae22018-01-09 06:39:23 -0800989 send_one_eid_table_details (mapit, reg, mp->context,
Filip Tehlar694396d2017-02-17 14:29:11 +0100990 0 /* ignore filter */ );
991 }
992 else
993 {
994 /* *INDENT-OFF* */
995 pool_foreach (mapit, lcm->mapping_pool,
996 ({
Florin Coras6c4dae22018-01-09 06:39:23 -0800997 send_one_eid_table_details(mapit, reg, mp->context,
Filip Tehlar694396d2017-02-17 14:29:11 +0100998 mp->filter);
999 }));
1000 /* *INDENT-ON* */
1001 }
1002}
1003
1004static void
Florin Coras6c4dae22018-01-09 06:39:23 -08001005send_one_map_server_details (ip_address_t * ip, vl_api_registration_t * reg,
1006 u32 context)
Filip Tehlar694396d2017-02-17 14:29:11 +01001007{
1008 vl_api_one_map_server_details_t *rmp = NULL;
1009
1010 rmp = vl_msg_api_alloc (sizeof (*rmp));
Dave Barachb7b92992018-10-17 10:38:51 -04001011 clib_memset (rmp, 0, sizeof (*rmp));
Filip Tehlar694396d2017-02-17 14:29:11 +01001012 rmp->_vl_msg_id = ntohs (VL_API_ONE_MAP_SERVER_DETAILS);
1013
1014 switch (ip_addr_version (ip))
1015 {
1016 case IP4:
1017 rmp->is_ipv6 = 0;
1018 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
1019 sizeof (ip_addr_v4 (ip)));
1020 break;
1021
1022 case IP6:
1023 rmp->is_ipv6 = 1;
1024 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
1025 sizeof (ip_addr_v6 (ip)));
1026 break;
1027
1028 default:
1029 ASSERT (0);
1030 }
1031 rmp->context = context;
1032
Florin Coras6c4dae22018-01-09 06:39:23 -08001033 vl_api_send_msg (reg, (u8 *) rmp);
Filip Tehlar694396d2017-02-17 14:29:11 +01001034}
1035
1036static void
1037vl_api_one_map_server_dump_t_handler (vl_api_one_map_server_dump_t * mp)
1038{
Florin Coras6c4dae22018-01-09 06:39:23 -08001039 vl_api_registration_t *reg;
Filip Tehlar694396d2017-02-17 14:29:11 +01001040 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1041 lisp_msmr_t *mr;
1042
Florin Coras6c4dae22018-01-09 06:39:23 -08001043 reg = vl_api_client_index_to_registration (mp->client_index);
1044 if (!reg)
1045 return;
Filip Tehlar694396d2017-02-17 14:29:11 +01001046
1047 vec_foreach (mr, lcm->map_servers)
1048 {
Florin Coras6c4dae22018-01-09 06:39:23 -08001049 send_one_map_server_details (&mr->address, reg, mp->context);
Filip Tehlar694396d2017-02-17 14:29:11 +01001050 }
1051}
1052
1053static void
1054send_one_map_resolver_details (ip_address_t * ip,
Florin Coras6c4dae22018-01-09 06:39:23 -08001055 vl_api_registration_t * reg, u32 context)
Filip Tehlar694396d2017-02-17 14:29:11 +01001056{
1057 vl_api_one_map_resolver_details_t *rmp = NULL;
1058
1059 rmp = vl_msg_api_alloc (sizeof (*rmp));
Dave Barachb7b92992018-10-17 10:38:51 -04001060 clib_memset (rmp, 0, sizeof (*rmp));
Filip Tehlar694396d2017-02-17 14:29:11 +01001061 rmp->_vl_msg_id = ntohs (VL_API_ONE_MAP_RESOLVER_DETAILS);
1062
1063 switch (ip_addr_version (ip))
1064 {
1065 case IP4:
1066 rmp->is_ipv6 = 0;
1067 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
1068 sizeof (ip_addr_v4 (ip)));
1069 break;
1070
1071 case IP6:
1072 rmp->is_ipv6 = 1;
1073 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
1074 sizeof (ip_addr_v6 (ip)));
1075 break;
1076
1077 default:
1078 ASSERT (0);
1079 }
1080 rmp->context = context;
1081
Florin Coras6c4dae22018-01-09 06:39:23 -08001082 vl_api_send_msg (reg, (u8 *) rmp);
Filip Tehlar694396d2017-02-17 14:29:11 +01001083}
1084
1085static void
1086vl_api_one_map_resolver_dump_t_handler (vl_api_one_map_resolver_dump_t * mp)
1087{
Florin Coras6c4dae22018-01-09 06:39:23 -08001088 vl_api_registration_t *reg;
Filip Tehlar694396d2017-02-17 14:29:11 +01001089 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1090 lisp_msmr_t *mr;
1091
Florin Coras6c4dae22018-01-09 06:39:23 -08001092 reg = vl_api_client_index_to_registration (mp->client_index);
1093 if (!reg)
1094 return;
Filip Tehlar694396d2017-02-17 14:29:11 +01001095
1096 vec_foreach (mr, lcm->map_resolvers)
1097 {
Florin Coras6c4dae22018-01-09 06:39:23 -08001098 send_one_map_resolver_details (&mr->address, reg, mp->context);
Filip Tehlar694396d2017-02-17 14:29:11 +01001099 }
1100}
1101
1102static void
Florin Coras6c4dae22018-01-09 06:39:23 -08001103send_eid_table_map_pair (hash_pair_t * p, vl_api_registration_t * reg,
1104 u32 context)
Filip Tehlar694396d2017-02-17 14:29:11 +01001105{
1106 vl_api_one_eid_table_map_details_t *rmp = NULL;
1107
1108 rmp = vl_msg_api_alloc (sizeof (*rmp));
Dave Barachb7b92992018-10-17 10:38:51 -04001109 clib_memset (rmp, 0, sizeof (*rmp));
Filip Tehlar694396d2017-02-17 14:29:11 +01001110 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_MAP_DETAILS);
1111
1112 rmp->vni = clib_host_to_net_u32 (p->key);
1113 rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
1114 rmp->context = context;
Florin Coras6c4dae22018-01-09 06:39:23 -08001115 vl_api_send_msg (reg, (u8 *) rmp);
Filip Tehlar694396d2017-02-17 14:29:11 +01001116}
1117
1118static void
1119vl_api_one_eid_table_map_dump_t_handler (vl_api_one_eid_table_map_dump_t * mp)
1120{
Florin Coras6c4dae22018-01-09 06:39:23 -08001121 vl_api_registration_t *reg;
Filip Tehlar694396d2017-02-17 14:29:11 +01001122 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1123 hash_pair_t *p;
1124 uword *vni_table = 0;
1125
Florin Coras6c4dae22018-01-09 06:39:23 -08001126 reg = vl_api_client_index_to_registration (mp->client_index);
1127 if (!reg)
1128 return;
Filip Tehlar694396d2017-02-17 14:29:11 +01001129
1130 if (mp->is_l2)
1131 {
1132 vni_table = lcm->bd_id_by_vni;
1133 }
1134 else
1135 {
1136 vni_table = lcm->table_id_by_vni;
1137 }
1138
1139 /* *INDENT-OFF* */
1140 hash_foreach_pair (p, vni_table,
1141 ({
Florin Coras6c4dae22018-01-09 06:39:23 -08001142 send_eid_table_map_pair (p, reg, mp->context);
Filip Tehlar694396d2017-02-17 14:29:11 +01001143 }));
1144 /* *INDENT-ON* */
1145}
1146
1147static void
Florin Coras6c4dae22018-01-09 06:39:23 -08001148send_eid_table_vni (u32 vni, vl_api_registration_t * reg, u32 context)
Filip Tehlar694396d2017-02-17 14:29:11 +01001149{
1150 vl_api_one_eid_table_vni_details_t *rmp = 0;
1151
1152 rmp = vl_msg_api_alloc (sizeof (*rmp));
Dave Barachb7b92992018-10-17 10:38:51 -04001153 clib_memset (rmp, 0, sizeof (*rmp));
Filip Tehlar694396d2017-02-17 14:29:11 +01001154 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_VNI_DETAILS);
1155 rmp->context = context;
1156 rmp->vni = clib_host_to_net_u32 (vni);
Florin Coras6c4dae22018-01-09 06:39:23 -08001157 vl_api_send_msg (reg, (u8 *) rmp);
Filip Tehlar694396d2017-02-17 14:29:11 +01001158}
1159
1160static void
1161one_adjacency_copy (vl_api_one_adjacency_t * dst, lisp_adjacency_t * adjs)
1162{
1163 lisp_adjacency_t *adj;
1164 vl_api_one_adjacency_t a;
1165 u32 i, n = vec_len (adjs);
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02001166 lisp_nsh_api_t nsh;
Filip Tehlar694396d2017-02-17 14:29:11 +01001167
1168 for (i = 0; i < n; i++)
1169 {
1170 adj = vec_elt_at_index (adjs, i);
Dave Barachb7b92992018-10-17 10:38:51 -04001171 clib_memset (&a, 0, sizeof (a));
Filip Tehlar694396d2017-02-17 14:29:11 +01001172
1173 switch (gid_address_type (&adj->reid))
1174 {
1175 case GID_ADDR_IP_PREFIX:
1176 a.reid_prefix_len = gid_address_ippref_len (&adj->reid);
1177 a.leid_prefix_len = gid_address_ippref_len (&adj->leid);
1178 if (gid_address_ip_version (&adj->reid) == IP4)
1179 {
1180 a.eid_type = 0; /* ipv4 type */
1181 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 4);
1182 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 4);
1183 }
1184 else
1185 {
1186 a.eid_type = 1; /* ipv6 type */
1187 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 16);
1188 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 16);
1189 }
1190 break;
1191 case GID_ADDR_MAC:
1192 a.eid_type = 2; /* l2 mac type */
1193 mac_copy (a.reid, gid_address_mac (&adj->reid));
1194 mac_copy (a.leid, gid_address_mac (&adj->leid));
1195 break;
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02001196 case GID_ADDR_NSH:
1197 a.eid_type = 3; /* NSH type */
1198 nsh.spi = clib_host_to_net_u32 (gid_address_nsh_spi (&adj->reid));
1199 nsh.si = gid_address_nsh_si (&adj->reid);
1200 clib_memcpy (a.reid, &nsh, sizeof (nsh));
1201
1202 nsh.spi = clib_host_to_net_u32 (gid_address_nsh_spi (&adj->leid));
1203 nsh.si = gid_address_nsh_si (&adj->leid);
1204 clib_memcpy (a.leid, &nsh, sizeof (nsh));
Filip Tehlarb8633d22017-06-09 15:25:57 +02001205 break;
Filip Tehlar694396d2017-02-17 14:29:11 +01001206 default:
1207 ASSERT (0);
1208 }
1209 dst[i] = a;
1210 }
1211}
1212
1213static void
1214 vl_api_show_one_rloc_probe_state_t_handler
1215 (vl_api_show_one_rloc_probe_state_t * mp)
1216{
1217 vl_api_show_one_rloc_probe_state_reply_t *rmp = 0;
1218 int rv = 0;
1219
1220 /* *INDENT-OFF* */
1221 REPLY_MACRO2 (VL_API_SHOW_ONE_RLOC_PROBE_STATE_REPLY,
1222 {
1223 rmp->is_enabled = vnet_lisp_rloc_probe_state_get ();
1224 });
1225 /* *INDENT-ON* */
1226}
1227
1228static void
1229 vl_api_show_one_map_register_state_t_handler
1230 (vl_api_show_one_map_register_state_t * mp)
1231{
1232 vl_api_show_one_map_register_state_reply_t *rmp = 0;
1233 int rv = 0;
1234
1235 /* *INDENT-OFF* */
1236 REPLY_MACRO2 (VL_API_SHOW_ONE_MAP_REGISTER_STATE_REPLY,
1237 {
1238 rmp->is_enabled = vnet_lisp_map_register_state_get ();
1239 });
1240 /* *INDENT-ON* */
1241}
1242
1243static void
1244vl_api_one_adjacencies_get_t_handler (vl_api_one_adjacencies_get_t * mp)
1245{
1246 vl_api_one_adjacencies_get_reply_t *rmp = 0;
1247 lisp_adjacency_t *adjs = 0;
1248 int rv = 0;
1249 u32 size = ~0;
1250 u32 vni = clib_net_to_host_u32 (mp->vni);
1251
1252 adjs = vnet_lisp_adjacencies_get_by_vni (vni);
1253 size = vec_len (adjs) * sizeof (vl_api_one_adjacency_t);
1254
1255 /* *INDENT-OFF* */
1256 REPLY_MACRO4 (VL_API_ONE_ADJACENCIES_GET_REPLY, size,
1257 {
1258 rmp->count = clib_host_to_net_u32 (vec_len (adjs));
1259 one_adjacency_copy (rmp->adjacencies, adjs);
1260 });
1261 /* *INDENT-ON* */
1262
1263 vec_free (adjs);
1264}
1265
1266static void
1267vl_api_one_eid_table_vni_dump_t_handler (vl_api_one_eid_table_vni_dump_t * mp)
1268{
1269 hash_pair_t *p;
1270 u32 *vnis = 0;
Florin Coras6c4dae22018-01-09 06:39:23 -08001271 vl_api_registration_t *reg;
Filip Tehlar694396d2017-02-17 14:29:11 +01001272 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1273
Florin Coras6c4dae22018-01-09 06:39:23 -08001274 reg = vl_api_client_index_to_registration (mp->client_index);
1275 if (!reg)
1276 return;
Filip Tehlar694396d2017-02-17 14:29:11 +01001277
1278 /* *INDENT-OFF* */
1279 hash_foreach_pair (p, lcm->table_id_by_vni,
1280 ({
1281 hash_set (vnis, p->key, 0);
1282 }));
1283
1284 hash_foreach_pair (p, lcm->bd_id_by_vni,
1285 ({
1286 hash_set (vnis, p->key, 0);
1287 }));
1288
1289 hash_foreach_pair (p, vnis,
1290 ({
Florin Coras6c4dae22018-01-09 06:39:23 -08001291 send_eid_table_vni (p->key, reg, mp->context);
Filip Tehlar694396d2017-02-17 14:29:11 +01001292 }));
1293 /* *INDENT-ON* */
1294
1295 hash_free (vnis);
1296}
1297
1298static void
1299vl_api_show_one_status_t_handler (vl_api_show_one_status_t * mp)
1300{
Filip Tehlar694396d2017-02-17 14:29:11 +01001301 vl_api_show_one_status_reply_t *rmp = NULL;
1302 int rv = 0;
1303
Filip Tehlar694396d2017-02-17 14:29:11 +01001304 /* *INDENT-OFF* */
1305 REPLY_MACRO2(VL_API_SHOW_ONE_STATUS_REPLY,
1306 ({
1307 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
1308 rmp->feature_status = vnet_lisp_enable_disable_status ();
1309 }));
1310 /* *INDENT-ON* */
1311}
1312
1313static void
1314 vl_api_one_get_map_request_itr_rlocs_t_handler
1315 (vl_api_one_get_map_request_itr_rlocs_t * mp)
1316{
Filip Tehlar694396d2017-02-17 14:29:11 +01001317 vl_api_one_get_map_request_itr_rlocs_reply_t *rmp = NULL;
1318 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1319 locator_set_t *loc_set = 0;
1320 u8 *tmp_str = 0;
1321 int rv = 0;
1322
Filip Tehlar694396d2017-02-17 14:29:11 +01001323 if (~0 == lcm->mreq_itr_rlocs)
1324 {
1325 tmp_str = format (0, " ");
1326 }
1327 else
1328 {
1329 loc_set =
1330 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
1331 tmp_str = format (0, "%s", loc_set->name);
1332 }
1333
1334 /* *INDENT-OFF* */
1335 REPLY_MACRO2(VL_API_ONE_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
1336 ({
1337 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1338 ARRAY_LEN(rmp->locator_set_name) - 1);
1339 }));
1340 /* *INDENT-ON* */
1341
1342 vec_free (tmp_str);
1343}
1344
1345static void
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02001346vl_api_show_one_nsh_mapping_t_handler (vl_api_show_one_nsh_mapping_t * mp)
1347{
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02001348 vl_api_show_one_nsh_mapping_reply_t *rmp = NULL;
1349 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1350 mapping_t *m;
1351 locator_set_t *ls = 0;
1352 u8 *tmp_str = 0;
1353 u8 is_set = 0;
1354 int rv = 0;
1355
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02001356 if (lcm->nsh_map_index == (u32) ~ 0)
1357 {
1358 tmp_str = format (0, "N/A");
1359 }
1360 else
1361 {
1362 m = pool_elt_at_index (lcm->mapping_pool, lcm->nsh_map_index);
1363 if (~0 != m->locator_set_index)
1364 {
1365 ls =
1366 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
1367 tmp_str = format (0, "%s", ls->name);
1368 is_set = 1;
1369 }
1370 else
1371 {
1372 tmp_str = format (0, "N/A");
1373 }
1374 }
1375 vec_add1 (tmp_str, 0);
1376
1377 /* *INDENT-OFF* */
1378 REPLY_MACRO2(VL_API_SHOW_ONE_NSH_MAPPING_REPLY,
1379 ({
1380 rmp->is_set = is_set;
1381 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1382 ARRAY_LEN(rmp->locator_set_name) - 1);
1383 }));
1384 /* *INDENT-ON* */
1385}
1386
1387static void
Filip Tehlar694396d2017-02-17 14:29:11 +01001388vl_api_show_one_pitr_t_handler (vl_api_show_one_pitr_t * mp)
1389{
Filip Tehlar694396d2017-02-17 14:29:11 +01001390 vl_api_show_one_pitr_reply_t *rmp = NULL;
1391 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1392 mapping_t *m;
1393 locator_set_t *ls = 0;
1394 u8 *tmp_str = 0;
1395 int rv = 0;
1396
Filip Tehlar0a8840d2017-10-16 05:48:23 -07001397 u8 is_enabled = (lcm->flags & LISP_FLAG_PITR_MODE)
1398 && lcm->pitr_map_index != ~0;
1399
1400 if (!is_enabled)
Filip Tehlar694396d2017-02-17 14:29:11 +01001401 {
1402 tmp_str = format (0, "N/A");
1403 }
1404 else
1405 {
1406 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
1407 if (~0 != m->locator_set_index)
1408 {
1409 ls =
1410 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
1411 tmp_str = format (0, "%s", ls->name);
1412 }
1413 else
1414 {
1415 tmp_str = format (0, "N/A");
1416 }
1417 }
1418 vec_add1 (tmp_str, 0);
1419
1420 /* *INDENT-OFF* */
1421 REPLY_MACRO2(VL_API_SHOW_ONE_PITR_REPLY,
1422 ({
Filip Tehlar0a8840d2017-10-16 05:48:23 -07001423 rmp->status = lcm->flags & LISP_FLAG_PITR_MODE;
Filip Tehlar694396d2017-02-17 14:29:11 +01001424 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1425 ARRAY_LEN(rmp->locator_set_name) - 1);
1426 }));
1427 /* *INDENT-ON* */
1428}
1429
Filip Tehlar7eaf0e52017-03-08 08:46:51 +01001430static void
1431 vl_api_show_one_stats_enable_disable_t_handler
1432 (vl_api_show_one_stats_enable_disable_t * mp)
1433{
1434 vl_api_show_one_stats_enable_disable_reply_t *rmp = NULL;
1435 vnet_api_error_t rv = 0;
1436
1437 /* *INDENT-OFF* */
1438 REPLY_MACRO2 (VL_API_SHOW_ONE_STATS_ENABLE_DISABLE_REPLY,
1439 ({
1440 rmp->is_en = vnet_lisp_stats_enable_disable_state ();
1441 }));
1442 /* *INDENT-ON* */
1443}
1444
1445static void
1446 vl_api_one_stats_enable_disable_t_handler
1447 (vl_api_one_stats_enable_disable_t * mp)
1448{
1449 vl_api_one_enable_disable_reply_t *rmp = NULL;
1450
1451 vnet_api_error_t rv = vnet_lisp_stats_enable_disable (mp->is_en);
1452 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
1453}
1454
1455static void
Filip Tehlar4868ff62017-03-09 16:48:39 +01001456lisp_fid_addr_to_api (fid_address_t * fid, u8 * dst, u8 * api_eid_type,
1457 u8 * prefix_length)
1458{
1459 switch (fid_addr_type (fid))
1460 {
1461 case FID_ADDR_IP_PREF:
1462 *prefix_length = fid_addr_prefix_length (fid);
1463 if (fid_addr_ip_version (fid) == IP4)
1464 {
1465 *api_eid_type = 0; /* ipv4 type */
1466 clib_memcpy (dst, &fid_addr_ippref (fid), 4);
1467 }
1468 else
1469 {
1470 *api_eid_type = 1; /* ipv6 type */
1471 clib_memcpy (dst, &fid_addr_ippref (fid), 16);
1472 }
1473 break;
1474 case FID_ADDR_MAC:
1475 *api_eid_type = 2; /* l2 mac type */
1476 mac_copy (dst, fid_addr_mac (fid));
1477 break;
1478 default:
1479 ASSERT (0);
1480 }
1481}
1482
1483static void
Filip Tehlar21511912017-04-07 10:41:42 +02001484vl_api_one_stats_flush_t_handler (vl_api_one_stats_flush_t * mp)
1485{
1486 vl_api_one_stats_flush_reply_t *rmp;
1487 u8 rv;
1488
1489 rv = vnet_lisp_flush_stats ();
1490 REPLY_MACRO (VL_API_ONE_STATS_FLUSH_REPLY);
1491}
1492
1493static void
Filip Tehlar7eaf0e52017-03-08 08:46:51 +01001494vl_api_one_stats_dump_t_handler (vl_api_one_stats_dump_t * mp)
1495{
Filip Tehlar4868ff62017-03-09 16:48:39 +01001496 vl_api_one_stats_details_t *rmp;
1497 lisp_api_stats_t *stats, *stat;
1498 u8 rv = 0;
Filip Tehlar7eaf0e52017-03-08 08:46:51 +01001499
Filip Tehlar4868ff62017-03-09 16:48:39 +01001500 stats = vnet_lisp_get_stats ();
1501 vec_foreach (stat, stats)
1502 {
1503 /* *INDENT-OFF* */
1504 REPLY_DETAILS (VL_API_ONE_STATS_DETAILS,
1505 ({
1506 lisp_fid_addr_to_api (&stat->deid, rmp->deid, &rmp->eid_type,
1507 &rmp->deid_pref_len);
1508 lisp_fid_addr_to_api (&stat->seid, rmp->seid, &rmp->eid_type,
1509 &rmp->seid_pref_len);
1510 rmp->vni = clib_host_to_net_u32 (stat->vni);
1511
1512 rmp->is_ip4 = ip_addr_version (&stat->rmt_rloc) == IP4 ? 1 : 0;
1513 ip_address_copy_addr (rmp->rloc, &stat->rmt_rloc);
1514 ip_address_copy_addr (rmp->lloc, &stat->loc_rloc);
1515
Filip Tehlar21511912017-04-07 10:41:42 +02001516 rmp->pkt_count = clib_host_to_net_u32 (stat->counters.packets);
1517 rmp->bytes = clib_host_to_net_u32 (stat->counters.bytes);
Filip Tehlar4868ff62017-03-09 16:48:39 +01001518 }));
1519 /* *INDENT-ON* */
1520 }
Filip Tehlar7eaf0e52017-03-08 08:46:51 +01001521}
1522
Filip Tehlard5a65db2017-05-17 17:21:10 +02001523static void
1524 vl_api_one_add_del_l2_arp_entry_t_handler
1525 (vl_api_one_add_del_l2_arp_entry_t * mp)
1526{
1527 vl_api_one_add_del_l2_arp_entry_reply_t *rmp;
1528 int rv = 0;
1529 gid_address_t _arp, *arp = &_arp;
Dave Barachb7b92992018-10-17 10:38:51 -04001530 clib_memset (arp, 0, sizeof (*arp));
Filip Tehlard5a65db2017-05-17 17:21:10 +02001531
1532 gid_address_type (arp) = GID_ADDR_ARP;
1533 gid_address_arp_bd (arp) = clib_net_to_host_u32 (mp->bd);
1534
1535 /* vpp keeps ip4 addresses in network byte order */
Filip Tehlar05879992017-09-05 15:46:09 +02001536 ip_address_set (&gid_address_arp_ndp_ip (arp), &mp->ip4, IP4);
Filip Tehlard5a65db2017-05-17 17:21:10 +02001537
Filip Tehlar64929642017-09-20 08:41:23 +02001538 rv = vnet_lisp_add_del_l2_arp_ndp_entry (arp, mp->mac, mp->is_add);
Filip Tehlard5a65db2017-05-17 17:21:10 +02001539
1540 REPLY_MACRO (VL_API_ONE_ADD_DEL_L2_ARP_ENTRY_REPLY);
1541}
1542
1543static void
Filip Tehlar05879992017-09-05 15:46:09 +02001544vl_api_one_add_del_ndp_entry_t_handler (vl_api_one_add_del_ndp_entry_t * mp)
1545{
1546 vl_api_one_add_del_ndp_entry_reply_t *rmp;
1547 int rv = 0;
1548 gid_address_t _g, *g = &_g;
Dave Barachb7b92992018-10-17 10:38:51 -04001549 clib_memset (g, 0, sizeof (*g));
Filip Tehlar05879992017-09-05 15:46:09 +02001550
1551 gid_address_type (g) = GID_ADDR_NDP;
1552 gid_address_ndp_bd (g) = clib_net_to_host_u32 (mp->bd);
1553 ip_address_set (&gid_address_arp_ndp_ip (g), mp->ip6, IP6);
1554
Filip Tehlar64929642017-09-20 08:41:23 +02001555 rv = vnet_lisp_add_del_l2_arp_ndp_entry (g, mp->mac, mp->is_add);
Filip Tehlar05879992017-09-05 15:46:09 +02001556
1557 REPLY_MACRO (VL_API_ONE_ADD_DEL_NDP_ENTRY_REPLY);
1558}
1559
1560static void
1561vl_api_one_ndp_bd_get_t_handler (vl_api_one_ndp_bd_get_t * mp)
1562{
1563 vl_api_one_ndp_bd_get_reply_t *rmp;
1564 int rv = 0;
1565 u32 i = 0;
1566 hash_pair_t *p;
1567
1568 u32 *bds = vnet_lisp_ndp_bds_get ();
1569 u32 size = hash_elts (bds) * sizeof (u32);
1570
1571 /* *INDENT-OFF* */
1572 REPLY_MACRO4 (VL_API_ONE_NDP_BD_GET_REPLY, size,
1573 {
1574 rmp->count = clib_host_to_net_u32 (hash_elts (bds));
1575 hash_foreach_pair (p, bds,
1576 ({
1577 rmp->bridge_domains[i++] = clib_host_to_net_u32 (p->key);
1578 }));
1579 });
1580 /* *INDENT-ON* */
1581
1582 hash_free (bds);
1583}
1584
1585static void
Filip Tehlard5a65db2017-05-17 17:21:10 +02001586vl_api_one_l2_arp_bd_get_t_handler (vl_api_one_l2_arp_bd_get_t * mp)
1587{
1588 vl_api_one_l2_arp_bd_get_reply_t *rmp;
1589 int rv = 0;
1590 u32 i = 0;
1591 hash_pair_t *p;
1592
1593 u32 *bds = vnet_lisp_l2_arp_bds_get ();
1594 u32 size = hash_elts (bds) * sizeof (u32);
1595
1596 /* *INDENT-OFF* */
1597 REPLY_MACRO4 (VL_API_ONE_L2_ARP_BD_GET_REPLY, size,
1598 {
1599 rmp->count = clib_host_to_net_u32 (hash_elts (bds));
1600 hash_foreach_pair (p, bds,
1601 ({
1602 rmp->bridge_domains[i++] = clib_host_to_net_u32 (p->key);
1603 }));
1604 });
1605 /* *INDENT-ON* */
1606
1607 hash_free (bds);
1608}
1609
1610static void
1611vl_api_one_l2_arp_entries_get_t_handler (vl_api_one_l2_arp_entries_get_t * mp)
1612{
1613 vl_api_one_l2_arp_entries_get_reply_t *rmp;
1614 lisp_api_l2_arp_entry_t *entries = 0, *e;
1615 u32 i = 0;
1616 int rv = 0;
1617
1618 u32 bd = clib_net_to_host_u32 (mp->bd);
1619
1620 entries = vnet_lisp_l2_arp_entries_get_by_bd (bd);
Ole Troan1d7d2ab2017-07-06 14:25:38 +02001621 u32 size = vec_len (entries) * sizeof (vl_api_one_l2_arp_entry_t);
Filip Tehlard5a65db2017-05-17 17:21:10 +02001622
1623 /* *INDENT-OFF* */
1624 REPLY_MACRO4 (VL_API_ONE_L2_ARP_ENTRIES_GET_REPLY, size,
1625 {
1626 rmp->count = clib_host_to_net_u32 (vec_len (entries));
1627 vec_foreach (e, entries)
1628 {
1629 mac_copy (rmp->entries[i].mac, e->mac);
1630 rmp->entries[i].ip4 = e->ip4;
1631 i++;
1632 }
1633 });
1634 /* *INDENT-ON* */
1635
1636 vec_free (entries);
1637}
1638
Filip Tehlar7048ff12017-07-27 08:09:14 +02001639static void
1640 vl_api_one_map_register_fallback_threshold_t_handler
1641 (vl_api_one_map_register_fallback_threshold_t * mp)
1642{
1643 vl_api_one_map_register_fallback_threshold_reply_t *rmp;
1644 int rv = 0;
1645
1646 mp->value = clib_net_to_host_u32 (mp->value);
1647 rv = vnet_lisp_map_register_fallback_threshold_set (mp->value);
Filip Tehlar6f9f6f32017-08-08 13:11:22 +02001648 REPLY_MACRO (VL_API_ONE_MAP_REGISTER_FALLBACK_THRESHOLD_REPLY);
Filip Tehlar7048ff12017-07-27 08:09:14 +02001649}
1650
1651static void
1652 vl_api_show_one_map_register_fallback_threshold_t_handler
1653 (vl_api_show_one_map_register_fallback_threshold_t * mp)
1654{
1655 vl_api_show_one_map_register_fallback_threshold_reply_t *rmp;
1656 int rv = 0;
1657
1658 u32 value = vnet_lisp_map_register_fallback_threshold_get ();
1659
1660 /* *INDENT-OFF* */
1661 REPLY_MACRO2 (VL_API_SHOW_ONE_MAP_REGISTER_FALLBACK_THRESHOLD_REPLY,
1662 ({
1663 rmp->value = clib_host_to_net_u32 (value);
1664 }));
1665 /* *INDENT-ON* */
1666}
1667
Filip Tehlar05879992017-09-05 15:46:09 +02001668static void
Filip Tehlara4980b82017-09-27 14:32:02 +02001669 vl_api_one_set_transport_protocol_t_handler
1670 (vl_api_one_set_transport_protocol_t * mp)
1671{
1672 vl_api_one_set_transport_protocol_reply_t *rmp;
1673 int rv = 0;
1674
1675 rv = vnet_lisp_set_transport_protocol (mp->protocol);
1676
1677 REPLY_MACRO (VL_API_ONE_SET_TRANSPORT_PROTOCOL_REPLY);
1678}
1679
1680static void
1681 vl_api_one_get_transport_protocol_t_handler
1682 (vl_api_one_get_transport_protocol_t * mp)
1683{
1684 vl_api_one_get_transport_protocol_reply_t *rmp;
1685 int rv = 0;
1686 u8 proto = (u8) vnet_lisp_get_transport_protocol ();
1687
1688 /* *INDENT-OFF* */
1689 REPLY_MACRO2 (VL_API_ONE_GET_TRANSPORT_PROTOCOL_REPLY,
1690 ({
1691 rmp->protocol = proto;
1692 }));
1693 /* *INDENT-ON* */
1694}
1695
1696static void
Filip Tehlar05879992017-09-05 15:46:09 +02001697vl_api_one_ndp_entries_get_t_handler (vl_api_one_ndp_entries_get_t * mp)
1698{
1699 vl_api_one_ndp_entries_get_reply_t *rmp = 0;
1700 lisp_api_ndp_entry_t *entries = 0, *e;
1701 u32 i = 0;
1702 int rv = 0;
1703
1704 u32 bd = clib_net_to_host_u32 (mp->bd);
1705
1706 entries = vnet_lisp_ndp_entries_get_by_bd (bd);
1707 u32 size = vec_len (entries) * sizeof (vl_api_one_ndp_entry_t);
1708
1709 /* *INDENT-OFF* */
1710 REPLY_MACRO4 (VL_API_ONE_NDP_ENTRIES_GET_REPLY, size,
1711 {
1712 rmp->count = clib_host_to_net_u32 (vec_len (entries));
1713 vec_foreach (e, entries)
1714 {
1715 mac_copy (rmp->entries[i].mac, e->mac);
1716 clib_memcpy (rmp->entries[i].ip6, e->ip6, 16);
1717 i++;
1718 }
1719 });
1720 /* *INDENT-ON* */
1721
1722 vec_free (entries);
1723}
1724
Filip Tehlar0a8840d2017-10-16 05:48:23 -07001725static void
1726 vl_api_one_enable_disable_xtr_mode_t_handler
1727 (vl_api_one_enable_disable_xtr_mode_t * mp)
1728{
1729 vl_api_one_enable_disable_xtr_mode_reply_t *rmp = 0;
1730 int rv = vnet_lisp_enable_disable_xtr_mode (mp->is_en);
1731
1732 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_XTR_MODE_REPLY);
1733}
1734
1735static void
1736vl_api_one_show_xtr_mode_t_handler (vl_api_one_show_xtr_mode_t * mp)
1737{
1738 vl_api_one_show_xtr_mode_reply_t *rmp = 0;
1739 int rv = 0;
1740
1741 /* *INDENT-OFF* */
1742 REPLY_MACRO2 (VL_API_ONE_SHOW_XTR_MODE_REPLY,
1743 {
1744 rmp->is_en = vnet_lisp_get_xtr_mode ();
1745 });
1746 /* *INDENT-ON* */
1747}
1748
1749static void
1750 vl_api_one_enable_disable_pitr_mode_t_handler
1751 (vl_api_one_enable_disable_pitr_mode_t * mp)
1752{
1753 vl_api_one_enable_disable_pitr_mode_reply_t *rmp = 0;
1754 int rv = vnet_lisp_enable_disable_pitr_mode (mp->is_en);
1755
1756 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_PITR_MODE_REPLY);
1757}
1758
1759static void
1760vl_api_one_show_pitr_mode_t_handler (vl_api_one_show_pitr_mode_t * mp)
1761{
1762 vl_api_one_show_pitr_mode_reply_t *rmp = 0;
1763 int rv = 0;
1764
1765 /* *INDENT-OFF* */
1766 REPLY_MACRO2 (VL_API_ONE_SHOW_PITR_MODE_REPLY,
1767 {
1768 rmp->is_en = vnet_lisp_get_pitr_mode ();
1769 });
1770 /* *INDENT-ON* */
1771}
1772
1773static void
1774 vl_api_one_enable_disable_petr_mode_t_handler
1775 (vl_api_one_enable_disable_petr_mode_t * mp)
1776{
1777 vl_api_one_enable_disable_petr_mode_reply_t *rmp = 0;
1778 int rv = vnet_lisp_enable_disable_petr_mode (mp->is_en);
1779
1780 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_PETR_MODE_REPLY);
1781}
1782
1783static void
1784vl_api_one_show_petr_mode_t_handler (vl_api_one_show_petr_mode_t * mp)
1785{
1786 vl_api_one_show_petr_mode_reply_t *rmp = 0;
1787 int rv = 0;
1788
1789 /* *INDENT-OFF* */
1790 REPLY_MACRO2 (VL_API_ONE_SHOW_PETR_MODE_REPLY,
1791 {
1792 rmp->is_en = vnet_lisp_get_petr_mode ();
1793 });
1794 /* *INDENT-ON* */
1795}
1796
Filip Tehlar694396d2017-02-17 14:29:11 +01001797/*
1798 * one_api_hookup
1799 * Add vpe's API message handlers to the table.
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -07001800 * vlib has already mapped shared memory and
Filip Tehlar694396d2017-02-17 14:29:11 +01001801 * added the client registration handlers.
1802 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
1803 */
1804#define vl_msg_name_crc_list
1805#include <vnet/vnet_all_api_h.h>
1806#undef vl_msg_name_crc_list
1807
1808static void
1809setup_message_id_table (api_main_t * am)
1810{
1811#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
Filip Tehlar974cdc62017-02-22 18:09:49 +01001812 foreach_vl_msg_name_crc_one;
Filip Tehlar694396d2017-02-17 14:29:11 +01001813#undef _
1814}
1815
1816static clib_error_t *
1817one_api_hookup (vlib_main_t * vm)
1818{
1819 api_main_t *am = &api_main;
1820
1821#define _(N,n) \
1822 vl_msg_api_set_handlers(VL_API_##N, #n, \
1823 vl_api_##n##_t_handler, \
1824 vl_noop_handler, \
1825 vl_api_##n##_t_endian, \
1826 vl_api_##n##_t_print, \
1827 sizeof(vl_api_##n##_t), 1);
1828 foreach_vpe_api_msg;
1829#undef _
1830
1831 /*
1832 * Set up the (msg_name, crc, message-id) table
1833 */
1834 setup_message_id_table (am);
1835
1836 return 0;
1837}
1838
1839VLIB_API_INIT_FUNCTION (one_api_hookup);
1840
1841/*
1842 * fd.io coding-style-patch-verification: ON
1843 *
1844 * Local Variables:
1845 * eval: (c-set-style "gnu")
1846 * End:
1847 */