blob: 8a0ffffd9cf018a1b1f3ab6bd266ab4f41b7e84e [file] [log] [blame]
Pavel Kotucekcfb7be82016-12-21 14:15:37 +01001/*
2 *------------------------------------------------------------------
3 * lisp_api.c - lisp api
4 *
5 * Copyright (c) 2016 Cisco and/or its affiliates.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *------------------------------------------------------------------
18 */
19
20#include <vnet/vnet.h>
21#include <vlibmemory/api.h>
22
23#include <vnet/interface.h>
24#include <vnet/api_errno.h>
25#include <vnet/lisp-cp/control.h>
26#include <vnet/lisp-gpe/lisp_gpe.h>
27
28#include <vnet/vnet_msg_enum.h>
29
Filip Tehlar05a057b2017-02-01 08:50:31 +010030
31#define vl_api_lisp_add_del_locator_set_t_endian vl_noop_handler
32#define vl_api_lisp_add_del_locator_set_t_print vl_noop_handler
33#define vl_api_lisp_add_del_remote_mapping_t_endian vl_noop_handler
34#define vl_api_lisp_add_del_remote_mapping_t_print vl_noop_handler
35
Filip Tehlar694396d2017-02-17 14:29:11 +010036#define vl_api_one_add_del_locator_set_t_endian vl_noop_handler
37#define vl_api_one_add_del_locator_set_t_print vl_noop_handler
38#define vl_api_one_add_del_remote_mapping_t_endian vl_noop_handler
39#define vl_api_one_add_del_remote_mapping_t_print vl_noop_handler
40
Pavel Kotucekcfb7be82016-12-21 14:15:37 +010041#define vl_typedefs /* define message structures */
42#include <vnet/vnet_all_api_h.h>
43#undef vl_typedefs
44
45#define vl_endianfun /* define message structures */
46#include <vnet/vnet_all_api_h.h>
47#undef vl_endianfun
48
49/* instantiate all the print functions we know about */
50#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
51#define vl_printfun
52#include <vnet/vnet_all_api_h.h>
53#undef vl_printfun
54
55#include <vlibapi/api_helper_macros.h>
56
57#define foreach_vpe_api_msg \
58_(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set) \
59_(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator) \
60_(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid) \
61_(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver) \
62_(LISP_ADD_DEL_MAP_SERVER, lisp_add_del_map_server) \
63_(LISP_ENABLE_DISABLE, lisp_enable_disable) \
64_(LISP_RLOC_PROBE_ENABLE_DISABLE, lisp_rloc_probe_enable_disable) \
65_(LISP_MAP_REGISTER_ENABLE_DISABLE, lisp_map_register_enable_disable) \
66_(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping) \
67_(LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency) \
68_(LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set) \
69_(LISP_MAP_REQUEST_MODE, lisp_map_request_mode) \
70_(LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map) \
71_(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \
72_(LISP_LOCATOR_DUMP, lisp_locator_dump) \
73_(LISP_EID_TABLE_DUMP, lisp_eid_table_dump) \
74_(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump) \
75_(LISP_MAP_SERVER_DUMP, lisp_map_server_dump) \
76_(LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump) \
77_(LISP_EID_TABLE_VNI_DUMP, lisp_eid_table_vni_dump) \
78_(LISP_ADJACENCIES_GET, lisp_adjacencies_get) \
79_(SHOW_LISP_RLOC_PROBE_STATE, show_lisp_rloc_probe_state) \
80_(SHOW_LISP_MAP_REGISTER_STATE, show_lisp_map_register_state) \
81_(SHOW_LISP_STATUS, show_lisp_status) \
82_(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \
83 lisp_add_del_map_request_itr_rlocs) \
84_(LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs) \
85_(SHOW_LISP_PITR, show_lisp_pitr) \
86_(SHOW_LISP_MAP_REQUEST_MODE, show_lisp_map_request_mode) \
Florin Corasba888e42017-01-24 11:38:18 -080087_(LISP_USE_PETR, lisp_use_petr) \
88_(SHOW_LISP_USE_PETR, show_lisp_use_petr) \
Pavel Kotucekcfb7be82016-12-21 14:15:37 +010089
Pavel Kotucekcfb7be82016-12-21 14:15:37 +010090static locator_t *
Filip Tehlar05a057b2017-02-01 08:50:31 +010091unformat_lisp_locs (vl_api_remote_locator_t * rmt_locs, u32 rloc_num)
Pavel Kotucekcfb7be82016-12-21 14:15:37 +010092{
93 u32 i;
94 locator_t *locs = 0, loc;
Filip Tehlar05a057b2017-02-01 08:50:31 +010095 vl_api_remote_locator_t *r;
Pavel Kotucekcfb7be82016-12-21 14:15:37 +010096
97 for (i = 0; i < rloc_num; i++)
98 {
99 /* remote locators */
Filip Tehlar05a057b2017-02-01 08:50:31 +0100100 r = &rmt_locs[i];
Dave Barachb7b92992018-10-17 10:38:51 -0400101 clib_memset (&loc, 0, sizeof (loc));
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100102 gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
103
104 loc.priority = r->priority;
105 loc.weight = r->weight;
106
107 vec_add1 (locs, loc);
108 }
109 return locs;
110}
111
112static void
113vl_api_lisp_add_del_locator_set_t_handler (vl_api_lisp_add_del_locator_set_t *
114 mp)
115{
116 vl_api_lisp_add_del_locator_set_reply_t *rmp;
117 int rv = 0;
118 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
119 locator_t locator;
Filip Tehlar05a057b2017-02-01 08:50:31 +0100120 vl_api_local_locator_t *ls_loc;
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100121 u32 ls_index = ~0, locator_num;
122 u8 *locator_name = NULL;
123 int i;
124
Dave Barachb7b92992018-10-17 10:38:51 -0400125 clib_memset (a, 0, sizeof (a[0]));
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100126
Filip Tehlar9d286a42017-10-26 23:57:09 -0700127 mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0;
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100128 locator_name = format (0, "%s", mp->locator_set_name);
Gabriel Ganne3491d7f2017-10-19 15:10:46 +0200129 vec_terminate_c_string (locator_name);
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100130
131 a->name = locator_name;
132 a->is_add = mp->is_add;
133 a->local = 1;
134 locator_num = clib_net_to_host_u32 (mp->locator_num);
135
Dave Barachb7b92992018-10-17 10:38:51 -0400136 clib_memset (&locator, 0, sizeof (locator));
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100137 for (i = 0; i < locator_num; i++)
138 {
Filip Tehlar05a057b2017-02-01 08:50:31 +0100139 ls_loc = &mp->locators[i];
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100140 VALIDATE_SW_IF_INDEX (ls_loc);
141
142 locator.sw_if_index = htonl (ls_loc->sw_if_index);
143 locator.priority = ls_loc->priority;
144 locator.weight = ls_loc->weight;
145 locator.local = 1;
146 vec_add1 (a->locators, locator);
147 }
148
149 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
150
151 BAD_SW_IF_INDEX_LABEL;
152
153 vec_free (locator_name);
154 vec_free (a->locators);
155
156 /* *INDENT-OFF* */
157 REPLY_MACRO2 (VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY,
158 ({
159 rmp->ls_index = clib_host_to_net_u32 (ls_index);
160 }));
161 /* *INDENT-ON* */
162}
163
164static void
165vl_api_lisp_add_del_locator_t_handler (vl_api_lisp_add_del_locator_t * mp)
166{
167 vl_api_lisp_add_del_locator_reply_t *rmp;
168 int rv = 0;
169 locator_t locator, *locators = NULL;
170 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
171 u32 ls_index = ~0;
172 u8 *locator_name = NULL;
173
Dave Barachb7b92992018-10-17 10:38:51 -0400174 clib_memset (&locator, 0, sizeof (locator));
175 clib_memset (a, 0, sizeof (a[0]));
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100176
177 locator.sw_if_index = ntohl (mp->sw_if_index);
178 locator.priority = mp->priority;
179 locator.weight = mp->weight;
180 locator.local = 1;
181 vec_add1 (locators, locator);
182
Filip Tehlar9d286a42017-10-26 23:57:09 -0700183 mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0;
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100184 locator_name = format (0, "%s", mp->locator_set_name);
Gabriel Ganne3491d7f2017-10-19 15:10:46 +0200185 vec_terminate_c_string (locator_name);
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100186
187 a->name = locator_name;
188 a->locators = locators;
189 a->is_add = mp->is_add;
190 a->local = 1;
191
192 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
193
194 vec_free (locators);
195 vec_free (locator_name);
196
197 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCATOR_REPLY);
198}
199
200static int
201unformat_lisp_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
202 u8 len)
203{
204 switch (type)
205 {
206 case 0: /* ipv4 */
207 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
208 gid_address_ip_set (dst, src, IP4);
209 gid_address_ippref_len (dst) = len;
210 ip_prefix_normalize (&gid_address_ippref (dst));
211 break;
212 case 1: /* ipv6 */
213 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
214 gid_address_ip_set (dst, src, IP6);
215 gid_address_ippref_len (dst) = len;
216 ip_prefix_normalize (&gid_address_ippref (dst));
217 break;
218 case 2: /* l2 mac */
219 gid_address_type (dst) = GID_ADDR_MAC;
220 clib_memcpy (&gid_address_mac (dst), src, 6);
221 break;
222 default:
223 /* unknown type */
224 return VNET_API_ERROR_INVALID_VALUE;
225 }
226
227 gid_address_vni (dst) = vni;
228
229 return 0;
230}
231
232static void
233vl_api_lisp_add_del_local_eid_t_handler (vl_api_lisp_add_del_local_eid_t * mp)
234{
235 vl_api_lisp_add_del_local_eid_reply_t *rmp;
236 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
237 int rv = 0;
238 gid_address_t _eid, *eid = &_eid;
239 uword *p = NULL;
240 u32 locator_set_index = ~0, map_index = ~0;
241 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
242 u8 *name = NULL, *key = NULL;
Dave Barachb7b92992018-10-17 10:38:51 -0400243 clib_memset (a, 0, sizeof (a[0]));
244 clib_memset (eid, 0, sizeof (eid[0]));
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100245
246 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
247 mp->eid_type, mp->eid, mp->prefix_len);
248 if (rv)
249 goto out;
250
Filip Tehlar9d286a42017-10-26 23:57:09 -0700251 mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0;
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100252 name = format (0, "%s", mp->locator_set_name);
Gabriel Ganne3491d7f2017-10-19 15:10:46 +0200253 vec_terminate_c_string (name);
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100254 p = hash_get_mem (lcm->locator_set_index_by_name, name);
255 if (!p)
256 {
257 rv = VNET_API_ERROR_INVALID_VALUE;
258 goto out;
259 }
260 locator_set_index = p[0];
261
262 if (*mp->key)
263 key = format (0, "%s", mp->key);
264
265 /* XXX treat batch configuration */
266 a->is_add = mp->is_add;
267 gid_address_copy (&a->eid, eid);
268 a->locator_set_index = locator_set_index;
269 a->local = 1;
270 a->key = key;
271 a->key_id = clib_net_to_host_u16 (mp->key_id);
272
273 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
274
275out:
276 vec_free (name);
277 vec_free (key);
278 gid_address_free (&a->eid);
279
280 REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY);
281}
282
283static void
284 vl_api_lisp_eid_table_add_del_map_t_handler
285 (vl_api_lisp_eid_table_add_del_map_t * mp)
286{
287 vl_api_lisp_eid_table_add_del_map_reply_t *rmp;
288 int rv = 0;
289 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
290 clib_net_to_host_u32 (mp->dp_table),
291 mp->is_l2, mp->is_add);
292REPLY_MACRO (VL_API_LISP_EID_TABLE_ADD_DEL_MAP_REPLY)}
293
294static void
295vl_api_lisp_add_del_map_server_t_handler (vl_api_lisp_add_del_map_server_t
296 * mp)
297{
298 vl_api_lisp_add_del_map_server_reply_t *rmp;
299 int rv = 0;
300 ip_address_t addr;
301
Dave Barachb7b92992018-10-17 10:38:51 -0400302 clib_memset (&addr, 0, sizeof (addr));
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100303
304 ip_address_set (&addr, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
305 rv = vnet_lisp_add_del_map_server (&addr, mp->is_add);
306
307 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_SERVER_REPLY);
308}
309
310static void
311vl_api_lisp_add_del_map_resolver_t_handler (vl_api_lisp_add_del_map_resolver_t
312 * mp)
313{
314 vl_api_lisp_add_del_map_resolver_reply_t *rmp;
315 int rv = 0;
316 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
317
Dave Barachb7b92992018-10-17 10:38:51 -0400318 clib_memset (a, 0, sizeof (a[0]));
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100319
320 a->is_add = mp->is_add;
321 ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
322
323 rv = vnet_lisp_add_del_map_resolver (a);
324
325 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY);
326}
327
328static void
329 vl_api_lisp_map_register_enable_disable_t_handler
330 (vl_api_lisp_map_register_enable_disable_t * mp)
331{
332 vl_api_lisp_map_register_enable_disable_reply_t *rmp;
333 int rv = 0;
334
335 vnet_lisp_map_register_enable_disable (mp->is_enabled);
336 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
337}
338
339static void
340 vl_api_lisp_rloc_probe_enable_disable_t_handler
341 (vl_api_lisp_rloc_probe_enable_disable_t * mp)
342{
343 vl_api_lisp_rloc_probe_enable_disable_reply_t *rmp;
344 int rv = 0;
345
346 vnet_lisp_rloc_probe_enable_disable (mp->is_enabled);
347 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
348}
349
350static void
351vl_api_lisp_enable_disable_t_handler (vl_api_lisp_enable_disable_t * mp)
352{
353 vl_api_lisp_enable_disable_reply_t *rmp;
354 int rv = 0;
355
356 vnet_lisp_enable_disable (mp->is_en);
357 REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY);
358}
359
360static void
361 vl_api_show_lisp_map_request_mode_t_handler
362 (vl_api_show_lisp_map_request_mode_t * mp)
363{
364 int rv = 0;
365 vl_api_show_lisp_map_request_mode_reply_t *rmp;
366
367 /* *INDENT-OFF* */
368 REPLY_MACRO2(VL_API_SHOW_LISP_MAP_REQUEST_MODE_REPLY,
369 ({
370 rmp->mode = vnet_lisp_get_map_request_mode ();
371 }));
372 /* *INDENT-ON* */
373}
374
375static void
376vl_api_lisp_map_request_mode_t_handler (vl_api_lisp_map_request_mode_t * mp)
377{
378 vl_api_lisp_map_request_mode_reply_t *rmp;
379 int rv = 0;
380
381 rv = vnet_lisp_set_map_request_mode (mp->mode);
382
383 REPLY_MACRO (VL_API_LISP_MAP_REQUEST_MODE_REPLY);
384}
385
386static void
387vl_api_lisp_pitr_set_locator_set_t_handler (vl_api_lisp_pitr_set_locator_set_t
388 * mp)
389{
390 vl_api_lisp_pitr_set_locator_set_reply_t *rmp;
391 int rv = 0;
392 u8 *ls_name = 0;
393
Filip Tehlar9d286a42017-10-26 23:57:09 -0700394 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100395 ls_name = format (0, "%s", mp->ls_name);
Gabriel Ganne3491d7f2017-10-19 15:10:46 +0200396 vec_terminate_c_string (ls_name);
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100397 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
398 vec_free (ls_name);
399
400 REPLY_MACRO (VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY);
401}
402
403static void
Florin Corasba888e42017-01-24 11:38:18 -0800404vl_api_lisp_use_petr_t_handler (vl_api_lisp_use_petr_t * mp)
405{
406 vl_api_lisp_use_petr_reply_t *rmp;
407 int rv = 0;
408 ip_address_t addr;
409
410 ip_address_set (&addr, &mp->address, mp->is_ip4 ? IP4 : IP6);
411 rv = vnet_lisp_use_petr (&addr, mp->is_add);
412
413 REPLY_MACRO (VL_API_LISP_USE_PETR_REPLY);
414}
415
416static void
417vl_api_show_lisp_use_petr_t_handler (vl_api_show_lisp_use_petr_t * mp)
418{
Florin Corasba888e42017-01-24 11:38:18 -0800419 vl_api_show_lisp_use_petr_reply_t *rmp = NULL;
420 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
421 mapping_t *m;
422 locator_set_t *ls = 0;
423 int rv = 0;
Florin Coras2743cc42017-01-29 16:42:20 -0800424 locator_t *loc = 0;
425 u8 status = 0;
426 gid_address_t addr;
Florin Corasba888e42017-01-24 11:38:18 -0800427
Dave Barachb7b92992018-10-17 10:38:51 -0400428 clib_memset (&addr, 0, sizeof (addr));
Florin Coras2743cc42017-01-29 16:42:20 -0800429 status = lcm->flags & LISP_FLAG_USE_PETR;
430 if (status)
Florin Corasba888e42017-01-24 11:38:18 -0800431 {
432 m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index);
433 if (~0 != m->locator_set_index)
434 {
435 ls =
436 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
437 loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]);
Florin Coras2743cc42017-01-29 16:42:20 -0800438 gid_address_copy (&addr, &loc->address);
Florin Corasba888e42017-01-24 11:38:18 -0800439 }
440 }
441
Florin Coras2743cc42017-01-29 16:42:20 -0800442 /* *INDENT-OFF* */
443 REPLY_MACRO2 (VL_API_SHOW_LISP_USE_PETR_REPLY,
444 {
Filip Tehlar67a99f82017-03-10 13:18:02 +0100445 rmp->status = status;
446 ip_address_t *ip = &gid_address_ip (&addr);
447 switch (ip_addr_version (ip))
448 {
449 case IP4:
450 clib_memcpy (rmp->address, &ip_addr_v4 (ip),
451 sizeof (ip_addr_v4 (ip)));
452 break;
453
454 case IP6:
455 clib_memcpy (rmp->address, &ip_addr_v6 (ip),
456 sizeof (ip_addr_v6 (ip)));
457 break;
458
459 default:
460 ASSERT (0);
461 }
462 rmp->is_ip4 = (gid_address_ip_version (&addr) == IP4);
Florin Coras2743cc42017-01-29 16:42:20 -0800463 });
464 /* *INDENT-ON* */
Florin Corasba888e42017-01-24 11:38:18 -0800465}
466
467static void
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100468 vl_api_lisp_add_del_map_request_itr_rlocs_t_handler
469 (vl_api_lisp_add_del_map_request_itr_rlocs_t * mp)
470{
471 vl_api_lisp_add_del_map_request_itr_rlocs_reply_t *rmp;
472 int rv = 0;
473 u8 *locator_set_name = NULL;
474 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
475
Filip Tehlar9d286a42017-10-26 23:57:09 -0700476 mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0;
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100477 locator_set_name = format (0, "%s", mp->locator_set_name);
Gabriel Ganne3491d7f2017-10-19 15:10:46 +0200478 vec_terminate_c_string (locator_set_name);
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100479
480 a->is_add = mp->is_add;
481 a->locator_set_name = locator_set_name;
482
483 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
484
485 vec_free (locator_set_name);
486
487 REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
488}
489
490static void
491 vl_api_lisp_add_del_remote_mapping_t_handler
492 (vl_api_lisp_add_del_remote_mapping_t * mp)
493{
494 locator_t *rlocs = 0;
495 vl_api_lisp_add_del_remote_mapping_reply_t *rmp;
496 int rv = 0;
497 gid_address_t _eid, *eid = &_eid;
498 u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
499
Dave Barachb7b92992018-10-17 10:38:51 -0400500 clib_memset (eid, 0, sizeof (eid[0]));
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100501
502 rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
503 mp->eid_type, mp->eid, mp->eid_len);
504 if (rv)
505 goto send_reply;
506
507 rlocs = unformat_lisp_locs (mp->rlocs, rloc_num);
508
509 if (!mp->is_add)
510 {
511 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
Dave Barachb7b92992018-10-17 10:38:51 -0400512 clib_memset (a, 0, sizeof (*a));
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100513 gid_address_copy (&a->reid, eid);
514 a->is_add = 0;
515 rv = vnet_lisp_add_del_adjacency (a);
516 if (rv)
517 {
518 goto out;
519 }
520 }
521
522 /* NOTE: for now this works as a static remote mapping, i.e.,
523 * not authoritative and ttl infinite. */
Filip Tehlar809bc742017-08-14 19:15:36 +0200524 if (mp->is_add)
525 {
526 vnet_lisp_add_del_mapping_args_t _m_args, *m_args = &_m_args;
Dave Barachb7b92992018-10-17 10:38:51 -0400527 clib_memset (m_args, 0, sizeof (m_args[0]));
Filip Tehlar809bc742017-08-14 19:15:36 +0200528 gid_address_copy (&m_args->eid, eid);
529 m_args->action = mp->action;
530 m_args->is_static = 1;
531 m_args->ttl = ~0;
532 m_args->authoritative = 0;
533 rv = vnet_lisp_add_mapping (m_args, rlocs, NULL, NULL);
534 }
535 else
Dave Barach59b25652017-09-10 15:04:27 -0400536 {
537 rv = vnet_lisp_del_mapping (eid, NULL);
538 }
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100539
540 if (mp->del_all)
541 vnet_lisp_clear_all_remote_adjacencies ();
542
543out:
544 vec_free (rlocs);
545send_reply:
546 REPLY_MACRO (VL_API_LISP_ADD_DEL_REMOTE_MAPPING_REPLY);
547}
548
549static void
550vl_api_lisp_add_del_adjacency_t_handler (vl_api_lisp_add_del_adjacency_t * mp)
551{
552 vl_api_lisp_add_del_adjacency_reply_t *rmp;
553 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
554
555 int rv = 0;
Dave Barachb7b92992018-10-17 10:38:51 -0400556 clib_memset (a, 0, sizeof (a[0]));
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100557
558 rv = unformat_lisp_eid_api (&a->leid, clib_net_to_host_u32 (mp->vni),
559 mp->eid_type, mp->leid, mp->leid_len);
560 rv |= unformat_lisp_eid_api (&a->reid, clib_net_to_host_u32 (mp->vni),
561 mp->eid_type, mp->reid, mp->reid_len);
562
563 if (rv)
564 goto send_reply;
565
566 a->is_add = mp->is_add;
567 rv = vnet_lisp_add_del_adjacency (a);
568
569send_reply:
570 REPLY_MACRO (VL_API_LISP_ADD_DEL_ADJACENCY_REPLY);
571}
572
573static void
574send_lisp_locator_details (lisp_cp_main_t * lcm,
Florin Coras6c4dae22018-01-09 06:39:23 -0800575 locator_t * loc, vl_api_registration_t * reg,
576 u32 context)
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100577{
578 vl_api_lisp_locator_details_t *rmp;
579
580 rmp = vl_msg_api_alloc (sizeof (*rmp));
Dave Barachb7b92992018-10-17 10:38:51 -0400581 clib_memset (rmp, 0, sizeof (*rmp));
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100582 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_DETAILS);
583 rmp->context = context;
584
585 rmp->local = loc->local;
586 if (loc->local)
587 {
588 rmp->sw_if_index = ntohl (loc->sw_if_index);
589 }
590 else
591 {
592 rmp->is_ipv6 = gid_address_ip_version (&loc->address);
593 ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
594 }
595 rmp->priority = loc->priority;
596 rmp->weight = loc->weight;
597
Florin Coras6c4dae22018-01-09 06:39:23 -0800598 vl_api_send_msg (reg, (u8 *) rmp);
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100599}
600
601static void
602vl_api_lisp_locator_dump_t_handler (vl_api_lisp_locator_dump_t * mp)
603{
604 u8 *ls_name = 0;
Florin Coras6c4dae22018-01-09 06:39:23 -0800605 vl_api_registration_t *reg = 0;
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100606 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
607 locator_set_t *lsit = 0;
608 locator_t *loc = 0;
609 u32 ls_index = ~0, *locit = 0;
610 uword *p = 0;
611
Florin Coras6c4dae22018-01-09 06:39:23 -0800612 reg = vl_api_client_index_to_registration (mp->client_index);
613 if (!reg)
614 return;
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100615
616 if (mp->is_index_set)
617 ls_index = htonl (mp->ls_index);
618 else
619 {
620 /* make sure we get a proper C-string */
621 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
622 ls_name = format (0, "%s", mp->ls_name);
Gabriel Ganne3491d7f2017-10-19 15:10:46 +0200623 vec_terminate_c_string (ls_name);
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100624 p = hash_get_mem (lcm->locator_set_index_by_name, ls_name);
625 if (!p)
626 goto out;
627 ls_index = p[0];
628 }
629
630 if (pool_is_free_index (lcm->locator_set_pool, ls_index))
631 return;
632
633 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
634
635 vec_foreach (locit, lsit->locator_indices)
636 {
637 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
Florin Coras6c4dae22018-01-09 06:39:23 -0800638 send_lisp_locator_details (lcm, loc, reg, mp->context);
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100639 };
640out:
641 vec_free (ls_name);
642}
643
644static void
645send_lisp_locator_set_details (lisp_cp_main_t * lcm,
646 locator_set_t * lsit,
Florin Coras6c4dae22018-01-09 06:39:23 -0800647 vl_api_registration_t * reg, u32 context,
648 u32 ls_index)
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100649{
650 vl_api_lisp_locator_set_details_t *rmp;
651 u8 *str = 0;
652
653 rmp = vl_msg_api_alloc (sizeof (*rmp));
Dave Barachb7b92992018-10-17 10:38:51 -0400654 clib_memset (rmp, 0, sizeof (*rmp));
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100655 rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_SET_DETAILS);
656 rmp->context = context;
657
658 rmp->ls_index = htonl (ls_index);
659 if (lsit->local)
660 {
661 ASSERT (lsit->name != NULL);
662 strncpy ((char *) rmp->ls_name, (char *) lsit->name,
663 vec_len (lsit->name));
664 }
665 else
666 {
667 str = format (0, "<remote-%d>", ls_index);
668 strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str));
669 vec_free (str);
670 }
671
Florin Coras6c4dae22018-01-09 06:39:23 -0800672 vl_api_send_msg (reg, (u8 *) rmp);
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100673}
674
675static void
676vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t * mp)
677{
Florin Coras6c4dae22018-01-09 06:39:23 -0800678 vl_api_registration_t *reg;
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100679 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
680 locator_set_t *lsit = NULL;
681 u8 filter;
682
Florin Coras6c4dae22018-01-09 06:39:23 -0800683 reg = vl_api_client_index_to_registration (mp->client_index);
684 if (!reg)
685 return;
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100686
687 filter = mp->filter;
688 /* *INDENT-OFF* */
689 pool_foreach (lsit, lcm->locator_set_pool,
690 ({
691 if (filter && !((1 == filter && lsit->local) ||
692 (2 == filter && !lsit->local)))
693 {
694 continue;
695 }
Florin Coras6c4dae22018-01-09 06:39:23 -0800696 send_lisp_locator_set_details (lcm, lsit, reg, mp->context,
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100697 lsit - lcm->locator_set_pool);
698 }));
699 /* *INDENT-ON* */
700}
701
702static void
703lisp_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length)
704{
705 ASSERT (prefix_length);
706 ip_prefix_t *ippref = &fid_addr_ippref (src);
707
708 switch (fid_addr_type (src))
709 {
710 case FID_ADDR_IP_PREF:
711 if (ip_prefix_version (ippref) == IP4)
712 clib_memcpy (dst, &ip_prefix_v4 (ippref), 4);
713 else
714 clib_memcpy (dst, &ip_prefix_v6 (ippref), 16);
715 prefix_length[0] = ip_prefix_len (ippref);
716 break;
717
718 case FID_ADDR_MAC:
719 prefix_length[0] = 0;
720 clib_memcpy (dst, fid_addr_mac (src), 6);
721 break;
722
723 default:
724 clib_warning ("Unknown FID type %d!", fid_addr_type (src));
725 break;
726 }
727}
728
729static u8
730fid_type_to_api_type (fid_address_t * fid)
731{
732 ip_prefix_t *ippref;
733
734 switch (fid_addr_type (fid))
735 {
736 case FID_ADDR_IP_PREF:
737 ippref = &fid_addr_ippref (fid);
738 if (ip_prefix_version (ippref) == IP4)
739 return 0;
740 else if (ip_prefix_version (ippref) == IP6)
741 return 1;
742 else
743 return ~0;
744
745 case FID_ADDR_MAC:
746 return 2;
Florin Corasce1b4c72017-01-26 14:25:34 -0800747 case FID_ADDR_NSH:
748 return 3;
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100749 }
750
751 return ~0;
752}
753
754static void
755send_lisp_eid_table_details (mapping_t * mapit,
Florin Coras6c4dae22018-01-09 06:39:23 -0800756 vl_api_registration_t * reg, u32 context,
757 u8 filter)
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100758{
759 fid_address_t *fid;
760 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
761 locator_set_t *ls = 0;
762 vl_api_lisp_eid_table_details_t *rmp = NULL;
763 gid_address_t *gid = NULL;
764 u8 *mac = 0;
765 ip_prefix_t *ip_prefix = NULL;
766
767 switch (filter)
768 {
769 case 0: /* all mappings */
770 break;
771
772 case 1: /* local only */
773 if (!mapit->local)
774 return;
775 break;
776 case 2: /* remote only */
777 if (mapit->local)
778 return;
779 break;
780 default:
781 clib_warning ("Filter error, unknown filter: %d", filter);
782 return;
783 }
784
Filip Tehlar38206ee2017-02-20 17:31:57 +0100785 /* don't send PITR generated mapping */
786 if (mapit->pitr_set)
787 return;
788
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100789 gid = &mapit->eid;
790 ip_prefix = &gid_address_ippref (gid);
791 mac = gid_address_mac (gid);
792
793 rmp = vl_msg_api_alloc (sizeof (*rmp));
Dave Barachb7b92992018-10-17 10:38:51 -0400794 clib_memset (rmp, 0, sizeof (*rmp));
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100795 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_DETAILS);
796
797 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
798 if (vec_len (ls->locator_indices) == 0)
799 rmp->locator_set_index = ~0;
800 else
801 rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
802
803 rmp->is_local = mapit->local;
804 rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
805 rmp->action = mapit->action;
806 rmp->authoritative = mapit->authoritative;
807
808 switch (gid_address_type (gid))
809 {
810 case GID_ADDR_SRC_DST:
811 rmp->is_src_dst = 1;
812 fid = &gid_address_sd_src (gid);
813 rmp->eid_type = fid_type_to_api_type (fid);
814 lisp_fid_put_api (rmp->seid, &gid_address_sd_src (gid),
815 &rmp->seid_prefix_len);
816 lisp_fid_put_api (rmp->eid, &gid_address_sd_dst (gid),
817 &rmp->eid_prefix_len);
818 break;
819 case GID_ADDR_IP_PREFIX:
820 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
821 if (ip_prefix_version (ip_prefix) == IP4)
822 {
823 rmp->eid_type = 0; /* ipv4 type */
824 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
825 sizeof (ip_prefix_v4 (ip_prefix)));
826 }
827 else
828 {
829 rmp->eid_type = 1; /* ipv6 type */
830 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
831 sizeof (ip_prefix_v6 (ip_prefix)));
832 }
833 break;
834 case GID_ADDR_MAC:
835 rmp->eid_type = 2; /* l2 mac type */
836 clib_memcpy (rmp->eid, mac, 6);
837 break;
838 default:
839 ASSERT (0);
840 }
841 rmp->context = context;
842 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
843 rmp->key_id = clib_host_to_net_u16 (mapit->key_id);
844 memcpy (rmp->key, mapit->key, vec_len (mapit->key));
Florin Coras6c4dae22018-01-09 06:39:23 -0800845 vl_api_send_msg (reg, (u8 *) rmp);
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100846}
847
848static void
849vl_api_lisp_eid_table_dump_t_handler (vl_api_lisp_eid_table_dump_t * mp)
850{
851 u32 mi;
Florin Coras6c4dae22018-01-09 06:39:23 -0800852 vl_api_registration_t *reg;
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100853 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
854 mapping_t *mapit = NULL;
855 gid_address_t _eid, *eid = &_eid;
856
Florin Coras6c4dae22018-01-09 06:39:23 -0800857 reg = vl_api_client_index_to_registration (mp->client_index);
858 if (!reg)
859 return;
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100860
861 if (mp->eid_set)
862 {
Dave Barachb7b92992018-10-17 10:38:51 -0400863 clib_memset (eid, 0, sizeof (*eid));
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100864
865 unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni),
866 mp->eid_type, mp->eid, mp->prefix_length);
867
868 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
869 if ((u32) ~ 0 == mi)
870 return;
871
872 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
Florin Coras6c4dae22018-01-09 06:39:23 -0800873 send_lisp_eid_table_details (mapit, reg, mp->context,
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100874 0 /* ignore filter */ );
875 }
876 else
877 {
878 /* *INDENT-OFF* */
879 pool_foreach (mapit, lcm->mapping_pool,
880 ({
Florin Coras6c4dae22018-01-09 06:39:23 -0800881 send_lisp_eid_table_details(mapit, reg, mp->context,
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100882 mp->filter);
883 }));
884 /* *INDENT-ON* */
885 }
886}
887
888static void
Florin Coras6c4dae22018-01-09 06:39:23 -0800889send_lisp_map_server_details (ip_address_t * ip, vl_api_registration_t * reg,
890 u32 context)
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100891{
892 vl_api_lisp_map_server_details_t *rmp = NULL;
893
894 rmp = vl_msg_api_alloc (sizeof (*rmp));
Dave Barachb7b92992018-10-17 10:38:51 -0400895 clib_memset (rmp, 0, sizeof (*rmp));
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100896 rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_SERVER_DETAILS);
897
898 switch (ip_addr_version (ip))
899 {
900 case IP4:
901 rmp->is_ipv6 = 0;
902 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
903 sizeof (ip_addr_v4 (ip)));
904 break;
905
906 case IP6:
907 rmp->is_ipv6 = 1;
908 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
909 sizeof (ip_addr_v6 (ip)));
910 break;
911
912 default:
913 ASSERT (0);
914 }
915 rmp->context = context;
916
Florin Coras6c4dae22018-01-09 06:39:23 -0800917 vl_api_send_msg (reg, (u8 *) rmp);
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100918}
919
920static void
921vl_api_lisp_map_server_dump_t_handler (vl_api_lisp_map_server_dump_t * mp)
922{
Florin Coras6c4dae22018-01-09 06:39:23 -0800923 vl_api_registration_t *reg;
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100924 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
925 lisp_msmr_t *mr;
926
Florin Coras6c4dae22018-01-09 06:39:23 -0800927 reg = vl_api_client_index_to_registration (mp->client_index);
928 if (!reg)
929 return;
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100930
931 vec_foreach (mr, lcm->map_servers)
932 {
Florin Coras6c4dae22018-01-09 06:39:23 -0800933 send_lisp_map_server_details (&mr->address, reg, mp->context);
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100934 }
935}
936
937static void
938send_lisp_map_resolver_details (ip_address_t * ip,
Florin Coras6c4dae22018-01-09 06:39:23 -0800939 vl_api_registration_t * reg, u32 context)
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100940{
941 vl_api_lisp_map_resolver_details_t *rmp = NULL;
942
943 rmp = vl_msg_api_alloc (sizeof (*rmp));
Dave Barachb7b92992018-10-17 10:38:51 -0400944 clib_memset (rmp, 0, sizeof (*rmp));
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100945 rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_RESOLVER_DETAILS);
946
947 switch (ip_addr_version (ip))
948 {
949 case IP4:
950 rmp->is_ipv6 = 0;
951 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
952 sizeof (ip_addr_v4 (ip)));
953 break;
954
955 case IP6:
956 rmp->is_ipv6 = 1;
957 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
958 sizeof (ip_addr_v6 (ip)));
959 break;
960
961 default:
962 ASSERT (0);
963 }
964 rmp->context = context;
965
Florin Coras6c4dae22018-01-09 06:39:23 -0800966 vl_api_send_msg (reg, (u8 *) rmp);
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100967}
968
969static void
970vl_api_lisp_map_resolver_dump_t_handler (vl_api_lisp_map_resolver_dump_t * mp)
971{
Florin Coras6c4dae22018-01-09 06:39:23 -0800972 vl_api_registration_t *reg;
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100973 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
974 lisp_msmr_t *mr;
975
Florin Coras6c4dae22018-01-09 06:39:23 -0800976 reg = vl_api_client_index_to_registration (mp->client_index);
977 if (!reg)
978 return;
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100979
980 vec_foreach (mr, lcm->map_resolvers)
981 {
Florin Coras6c4dae22018-01-09 06:39:23 -0800982 send_lisp_map_resolver_details (&mr->address, reg, mp->context);
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100983 }
984}
985
986static void
Florin Coras6c4dae22018-01-09 06:39:23 -0800987send_eid_table_map_pair (hash_pair_t * p, vl_api_registration_t * reg,
988 u32 context)
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100989{
990 vl_api_lisp_eid_table_map_details_t *rmp = NULL;
991
992 rmp = vl_msg_api_alloc (sizeof (*rmp));
Dave Barachb7b92992018-10-17 10:38:51 -0400993 clib_memset (rmp, 0, sizeof (*rmp));
Pavel Kotucekcfb7be82016-12-21 14:15:37 +0100994 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_MAP_DETAILS);
995
996 rmp->vni = clib_host_to_net_u32 (p->key);
997 rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
998 rmp->context = context;
Florin Coras6c4dae22018-01-09 06:39:23 -0800999 vl_api_send_msg (reg, (u8 *) rmp);
Pavel Kotucekcfb7be82016-12-21 14:15:37 +01001000}
1001
1002static void
1003vl_api_lisp_eid_table_map_dump_t_handler (vl_api_lisp_eid_table_map_dump_t *
1004 mp)
1005{
Florin Coras6c4dae22018-01-09 06:39:23 -08001006 vl_api_registration_t *reg;
Pavel Kotucekcfb7be82016-12-21 14:15:37 +01001007 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1008 hash_pair_t *p;
1009 uword *vni_table = 0;
1010
Florin Coras6c4dae22018-01-09 06:39:23 -08001011 reg = vl_api_client_index_to_registration (mp->client_index);
1012 if (!reg)
1013 return;
Pavel Kotucekcfb7be82016-12-21 14:15:37 +01001014
1015 if (mp->is_l2)
1016 {
1017 vni_table = lcm->bd_id_by_vni;
1018 }
1019 else
1020 {
1021 vni_table = lcm->table_id_by_vni;
1022 }
1023
1024 /* *INDENT-OFF* */
1025 hash_foreach_pair (p, vni_table,
1026 ({
Florin Coras6c4dae22018-01-09 06:39:23 -08001027 send_eid_table_map_pair (p, reg, mp->context);
Pavel Kotucekcfb7be82016-12-21 14:15:37 +01001028 }));
1029 /* *INDENT-ON* */
1030}
1031
1032static void
Florin Coras6c4dae22018-01-09 06:39:23 -08001033send_eid_table_vni (u32 vni, vl_api_registration_t * reg, u32 context)
Pavel Kotucekcfb7be82016-12-21 14:15:37 +01001034{
1035 vl_api_lisp_eid_table_vni_details_t *rmp = 0;
1036
1037 rmp = vl_msg_api_alloc (sizeof (*rmp));
Dave Barachb7b92992018-10-17 10:38:51 -04001038 clib_memset (rmp, 0, sizeof (*rmp));
Pavel Kotucekcfb7be82016-12-21 14:15:37 +01001039 rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_VNI_DETAILS);
1040 rmp->context = context;
1041 rmp->vni = clib_host_to_net_u32 (vni);
Florin Coras6c4dae22018-01-09 06:39:23 -08001042 vl_api_send_msg (reg, (u8 *) rmp);
Pavel Kotucekcfb7be82016-12-21 14:15:37 +01001043}
1044
1045static void
1046lisp_adjacency_copy (vl_api_lisp_adjacency_t * dst, lisp_adjacency_t * adjs)
1047{
1048 lisp_adjacency_t *adj;
1049 vl_api_lisp_adjacency_t a;
1050 u32 i, n = vec_len (adjs);
1051
1052 for (i = 0; i < n; i++)
1053 {
1054 adj = vec_elt_at_index (adjs, i);
Dave Barachb7b92992018-10-17 10:38:51 -04001055 clib_memset (&a, 0, sizeof (a));
Pavel Kotucekcfb7be82016-12-21 14:15:37 +01001056
1057 switch (gid_address_type (&adj->reid))
1058 {
1059 case GID_ADDR_IP_PREFIX:
1060 a.reid_prefix_len = gid_address_ippref_len (&adj->reid);
1061 a.leid_prefix_len = gid_address_ippref_len (&adj->leid);
1062 if (gid_address_ip_version (&adj->reid) == IP4)
1063 {
1064 a.eid_type = 0; /* ipv4 type */
1065 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 4);
1066 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 4);
1067 }
1068 else
1069 {
1070 a.eid_type = 1; /* ipv6 type */
1071 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 16);
1072 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 16);
1073 }
1074 break;
1075 case GID_ADDR_MAC:
1076 a.eid_type = 2; /* l2 mac type */
1077 mac_copy (a.reid, gid_address_mac (&adj->reid));
1078 mac_copy (a.leid, gid_address_mac (&adj->leid));
1079 break;
1080 default:
1081 ASSERT (0);
1082 }
1083 dst[i] = a;
1084 }
1085}
1086
1087static void
1088 vl_api_show_lisp_rloc_probe_state_t_handler
1089 (vl_api_show_lisp_rloc_probe_state_t * mp)
1090{
1091 vl_api_show_lisp_rloc_probe_state_reply_t *rmp = 0;
1092 int rv = 0;
1093
1094 /* *INDENT-OFF* */
1095 REPLY_MACRO2 (VL_API_SHOW_LISP_RLOC_PROBE_STATE_REPLY,
1096 {
1097 rmp->is_enabled = vnet_lisp_rloc_probe_state_get ();
1098 });
1099 /* *INDENT-ON* */
1100}
1101
1102static void
1103 vl_api_show_lisp_map_register_state_t_handler
1104 (vl_api_show_lisp_map_register_state_t * mp)
1105{
1106 vl_api_show_lisp_map_register_state_reply_t *rmp = 0;
1107 int rv = 0;
1108
1109 /* *INDENT-OFF* */
1110 REPLY_MACRO2 (VL_API_SHOW_LISP_MAP_REGISTER_STATE_REPLY,
1111 {
1112 rmp->is_enabled = vnet_lisp_map_register_state_get ();
1113 });
1114 /* *INDENT-ON* */
1115}
1116
1117static void
1118vl_api_lisp_adjacencies_get_t_handler (vl_api_lisp_adjacencies_get_t * mp)
1119{
1120 vl_api_lisp_adjacencies_get_reply_t *rmp = 0;
1121 lisp_adjacency_t *adjs = 0;
1122 int rv = 0;
Pavel Kotucekcfb7be82016-12-21 14:15:37 +01001123 u32 size = ~0;
1124 u32 vni = clib_net_to_host_u32 (mp->vni);
1125
1126 adjs = vnet_lisp_adjacencies_get_by_vni (vni);
Filip Tehlar5fae99c2017-01-18 12:57:37 +01001127 size = vec_len (adjs) * sizeof (vl_api_lisp_adjacency_t);
Pavel Kotucekcfb7be82016-12-21 14:15:37 +01001128
1129 /* *INDENT-OFF* */
1130 REPLY_MACRO4 (VL_API_LISP_ADJACENCIES_GET_REPLY, size,
1131 {
1132 rmp->count = clib_host_to_net_u32 (vec_len (adjs));
1133 lisp_adjacency_copy (rmp->adjacencies, adjs);
1134 });
1135 /* *INDENT-ON* */
1136
1137 vec_free (adjs);
1138}
1139
1140static void
1141vl_api_lisp_eid_table_vni_dump_t_handler (vl_api_lisp_eid_table_vni_dump_t *
1142 mp)
1143{
1144 hash_pair_t *p;
1145 u32 *vnis = 0;
Florin Coras6c4dae22018-01-09 06:39:23 -08001146 vl_api_registration_t *reg = 0;
Pavel Kotucekcfb7be82016-12-21 14:15:37 +01001147 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1148
Florin Coras6c4dae22018-01-09 06:39:23 -08001149 reg = vl_api_client_index_to_registration (mp->client_index);
1150 if (!reg)
1151 return;
Pavel Kotucekcfb7be82016-12-21 14:15:37 +01001152
1153 /* *INDENT-OFF* */
1154 hash_foreach_pair (p, lcm->table_id_by_vni,
1155 ({
1156 hash_set (vnis, p->key, 0);
1157 }));
1158
1159 hash_foreach_pair (p, lcm->bd_id_by_vni,
1160 ({
1161 hash_set (vnis, p->key, 0);
1162 }));
1163
1164 hash_foreach_pair (p, vnis,
1165 ({
Florin Coras6c4dae22018-01-09 06:39:23 -08001166 send_eid_table_vni (p->key, reg, mp->context);
Pavel Kotucekcfb7be82016-12-21 14:15:37 +01001167 }));
1168 /* *INDENT-ON* */
1169
1170 hash_free (vnis);
1171}
1172
1173static void
1174vl_api_show_lisp_status_t_handler (vl_api_show_lisp_status_t * mp)
1175{
Pavel Kotucekcfb7be82016-12-21 14:15:37 +01001176 vl_api_show_lisp_status_reply_t *rmp = NULL;
1177 int rv = 0;
1178
Pavel Kotucekcfb7be82016-12-21 14:15:37 +01001179 /* *INDENT-OFF* */
1180 REPLY_MACRO2(VL_API_SHOW_LISP_STATUS_REPLY,
1181 ({
1182 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
1183 rmp->feature_status = vnet_lisp_enable_disable_status ();
1184 }));
1185 /* *INDENT-ON* */
1186}
1187
1188static void
1189 vl_api_lisp_get_map_request_itr_rlocs_t_handler
1190 (vl_api_lisp_get_map_request_itr_rlocs_t * mp)
1191{
Pavel Kotucekcfb7be82016-12-21 14:15:37 +01001192 vl_api_lisp_get_map_request_itr_rlocs_reply_t *rmp = NULL;
1193 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1194 locator_set_t *loc_set = 0;
1195 u8 *tmp_str = 0;
1196 int rv = 0;
1197
Pavel Kotucekcfb7be82016-12-21 14:15:37 +01001198 if (~0 == lcm->mreq_itr_rlocs)
1199 {
1200 tmp_str = format (0, " ");
1201 }
1202 else
1203 {
1204 loc_set =
1205 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
1206 tmp_str = format (0, "%s", loc_set->name);
1207 }
1208
1209 /* *INDENT-OFF* */
1210 REPLY_MACRO2(VL_API_LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
1211 ({
1212 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1213 ARRAY_LEN(rmp->locator_set_name) - 1);
1214 }));
1215 /* *INDENT-ON* */
1216
1217 vec_free (tmp_str);
1218}
1219
1220static void
1221vl_api_show_lisp_pitr_t_handler (vl_api_show_lisp_pitr_t * mp)
1222{
Pavel Kotucekcfb7be82016-12-21 14:15:37 +01001223 vl_api_show_lisp_pitr_reply_t *rmp = NULL;
1224 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1225 mapping_t *m;
1226 locator_set_t *ls = 0;
1227 u8 *tmp_str = 0;
1228 int rv = 0;
1229
Filip Tehlar0a8840d2017-10-16 05:48:23 -07001230 u8 is_enabled = (lcm->flags & LISP_FLAG_PITR_MODE)
1231 && lcm->pitr_map_index != ~0;
1232
1233 if (!is_enabled)
Pavel Kotucekcfb7be82016-12-21 14:15:37 +01001234 {
1235 tmp_str = format (0, "N/A");
1236 }
1237 else
1238 {
1239 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
1240 if (~0 != m->locator_set_index)
1241 {
1242 ls =
1243 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
1244 tmp_str = format (0, "%s", ls->name);
1245 }
1246 else
1247 {
1248 tmp_str = format (0, "N/A");
1249 }
1250 }
1251 vec_add1 (tmp_str, 0);
1252
1253 /* *INDENT-OFF* */
1254 REPLY_MACRO2(VL_API_SHOW_LISP_PITR_REPLY,
1255 ({
Filip Tehlar0a8840d2017-10-16 05:48:23 -07001256 rmp->status = lcm->flags & LISP_FLAG_PITR_MODE;
Pavel Kotucekcfb7be82016-12-21 14:15:37 +01001257 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1258 ARRAY_LEN(rmp->locator_set_name) - 1);
1259 }));
1260 /* *INDENT-ON* */
1261}
1262
1263/*
1264 * lisp_api_hookup
1265 * Add vpe's API message handlers to the table.
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -07001266 * vlib has already mapped shared memory and
Pavel Kotucekcfb7be82016-12-21 14:15:37 +01001267 * added the client registration handlers.
1268 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
1269 */
1270#define vl_msg_name_crc_list
1271#include <vnet/vnet_all_api_h.h>
1272#undef vl_msg_name_crc_list
1273
1274static void
1275setup_message_id_table (api_main_t * am)
1276{
1277#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
Filip Tehlar974cdc62017-02-22 18:09:49 +01001278 foreach_vl_msg_name_crc_lisp;
Pavel Kotucekcfb7be82016-12-21 14:15:37 +01001279#undef _
1280}
1281
1282static clib_error_t *
1283lisp_api_hookup (vlib_main_t * vm)
1284{
1285 api_main_t *am = &api_main;
1286
1287#define _(N,n) \
1288 vl_msg_api_set_handlers(VL_API_##N, #n, \
1289 vl_api_##n##_t_handler, \
1290 vl_noop_handler, \
1291 vl_api_##n##_t_endian, \
1292 vl_api_##n##_t_print, \
1293 sizeof(vl_api_##n##_t), 1);
1294 foreach_vpe_api_msg;
1295#undef _
1296
1297 /*
1298 * Set up the (msg_name, crc, message-id) table
1299 */
1300 setup_message_id_table (am);
1301
1302 return 0;
1303}
1304
1305VLIB_API_INIT_FUNCTION (lisp_api_hookup);
1306
1307/*
1308 * fd.io coding-style-patch-verification: ON
1309 *
1310 * Local Variables:
1311 * eval: (c-set-style "gnu")
1312 * End:
1313 */