blob: ff00bf5bfcec7b37dd3169a0fe6fa9d26d60c99a [file] [log] [blame]
Filip Tehlar694396d2017-02-17 14:29:11 +01001/*
2 *------------------------------------------------------------------
3 * one_api.c - Overlay Network Engine API
4 *
5 * Copyright (c) 2016-2017 Cisco and/or its affiliates.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *------------------------------------------------------------------
18 */
19
20#include <vnet/vnet.h>
21#include <vlibmemory/api.h>
22
23#include <vnet/interface.h>
24#include <vnet/api_errno.h>
25#include <vnet/lisp-cp/control.h>
26#include <vnet/lisp-gpe/lisp_gpe.h>
27
28#include <vnet/vnet_msg_enum.h>
29
Filip Tehlar974cdc62017-02-22 18:09:49 +010030#define vl_api_one_remote_locator_t_endian vl_noop_handler
31#define vl_api_one_remote_locator_t_print vl_noop_handler
32#define vl_api_one_local_locator_t_endian vl_noop_handler
33#define vl_api_one_local_locator_t_print vl_noop_handler
Filip Tehlar694396d2017-02-17 14:29:11 +010034
35#define vl_api_one_add_del_locator_set_t_endian vl_noop_handler
36#define vl_api_one_add_del_locator_set_t_print vl_noop_handler
37#define vl_api_one_add_del_remote_mapping_t_endian vl_noop_handler
38#define vl_api_one_add_del_remote_mapping_t_print vl_noop_handler
39
40#define vl_api_one_add_del_locator_set_t_endian vl_noop_handler
41#define vl_api_one_add_del_locator_set_t_print vl_noop_handler
42#define vl_api_one_add_del_remote_mapping_t_endian vl_noop_handler
43#define vl_api_one_add_del_remote_mapping_t_print vl_noop_handler
44
45#define vl_typedefs /* define message structures */
46#include <vnet/vnet_all_api_h.h>
47#undef vl_typedefs
48
49#define vl_endianfun /* define message structures */
50#include <vnet/vnet_all_api_h.h>
51#undef vl_endianfun
52
53/* instantiate all the print functions we know about */
54#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
55#define vl_printfun
56#include <vnet/vnet_all_api_h.h>
57#undef vl_printfun
58
59#include <vlibapi/api_helper_macros.h>
60
61#define foreach_vpe_api_msg \
62_(ONE_ADD_DEL_LOCATOR_SET, one_add_del_locator_set) \
63_(ONE_ADD_DEL_LOCATOR, one_add_del_locator) \
64_(ONE_ADD_DEL_LOCAL_EID, one_add_del_local_eid) \
65_(ONE_ADD_DEL_MAP_RESOLVER, one_add_del_map_resolver) \
66_(ONE_ADD_DEL_MAP_SERVER, one_add_del_map_server) \
67_(ONE_ENABLE_DISABLE, one_enable_disable) \
68_(ONE_RLOC_PROBE_ENABLE_DISABLE, one_rloc_probe_enable_disable) \
69_(ONE_MAP_REGISTER_ENABLE_DISABLE, one_map_register_enable_disable) \
70_(ONE_ADD_DEL_REMOTE_MAPPING, one_add_del_remote_mapping) \
71_(ONE_ADD_DEL_ADJACENCY, one_add_del_adjacency) \
72_(ONE_PITR_SET_LOCATOR_SET, one_pitr_set_locator_set) \
73_(ONE_MAP_REQUEST_MODE, one_map_request_mode) \
74_(ONE_EID_TABLE_ADD_DEL_MAP, one_eid_table_add_del_map) \
75_(ONE_LOCATOR_SET_DUMP, one_locator_set_dump) \
76_(ONE_LOCATOR_DUMP, one_locator_dump) \
77_(ONE_EID_TABLE_DUMP, one_eid_table_dump) \
78_(ONE_MAP_RESOLVER_DUMP, one_map_resolver_dump) \
79_(ONE_MAP_SERVER_DUMP, one_map_server_dump) \
80_(ONE_EID_TABLE_MAP_DUMP, one_eid_table_map_dump) \
81_(ONE_EID_TABLE_VNI_DUMP, one_eid_table_vni_dump) \
82_(ONE_ADJACENCIES_GET, one_adjacencies_get) \
83_(SHOW_ONE_RLOC_PROBE_STATE, show_one_rloc_probe_state) \
84_(SHOW_ONE_MAP_REGISTER_STATE, show_one_map_register_state) \
85_(SHOW_ONE_STATUS, show_one_status) \
86_(ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \
87 one_add_del_map_request_itr_rlocs) \
88_(ONE_GET_MAP_REQUEST_ITR_RLOCS, one_get_map_request_itr_rlocs) \
89_(SHOW_ONE_PITR, show_one_pitr) \
90_(SHOW_ONE_MAP_REQUEST_MODE, show_one_map_request_mode) \
91_(ONE_USE_PETR, one_use_petr) \
92_(SHOW_ONE_USE_PETR, show_one_use_petr) \
Filip Tehlar7eaf0e52017-03-08 08:46:51 +010093_(SHOW_ONE_STATS_ENABLE_DISABLE, show_one_stats_enable_disable) \
94_(ONE_STATS_ENABLE_DISABLE, one_stats_enable_disable) \
95_(ONE_STATS_DUMP, one_stats_dump) \
96
Filip Tehlar694396d2017-02-17 14:29:11 +010097
98static locator_t *
Filip Tehlar974cdc62017-02-22 18:09:49 +010099unformat_one_locs (vl_api_one_remote_locator_t * rmt_locs, u32 rloc_num)
Filip Tehlar694396d2017-02-17 14:29:11 +0100100{
101 u32 i;
102 locator_t *locs = 0, loc;
Filip Tehlar974cdc62017-02-22 18:09:49 +0100103 vl_api_one_remote_locator_t *r;
Filip Tehlar694396d2017-02-17 14:29:11 +0100104
105 for (i = 0; i < rloc_num; i++)
106 {
107 /* remote locators */
108 r = &rmt_locs[i];
109 memset (&loc, 0, sizeof (loc));
110 gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6);
111
112 loc.priority = r->priority;
113 loc.weight = r->weight;
114
115 vec_add1 (locs, loc);
116 }
117 return locs;
118}
119
120static void
121vl_api_one_add_del_locator_set_t_handler (vl_api_one_add_del_locator_set_t *
122 mp)
123{
124 vl_api_one_add_del_locator_set_reply_t *rmp;
125 int rv = 0;
126 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
127 locator_t locator;
Filip Tehlar974cdc62017-02-22 18:09:49 +0100128 vl_api_one_local_locator_t *ls_loc;
Filip Tehlar694396d2017-02-17 14:29:11 +0100129 u32 ls_index = ~0, locator_num;
130 u8 *locator_name = NULL;
131 int i;
132
133 memset (a, 0, sizeof (a[0]));
134
135 locator_name = format (0, "%s", mp->locator_set_name);
136
137 a->name = locator_name;
138 a->is_add = mp->is_add;
139 a->local = 1;
140 locator_num = clib_net_to_host_u32 (mp->locator_num);
141
142 memset (&locator, 0, sizeof (locator));
143 for (i = 0; i < locator_num; i++)
144 {
145 ls_loc = &mp->locators[i];
146 VALIDATE_SW_IF_INDEX (ls_loc);
147
148 locator.sw_if_index = htonl (ls_loc->sw_if_index);
149 locator.priority = ls_loc->priority;
150 locator.weight = ls_loc->weight;
151 locator.local = 1;
152 vec_add1 (a->locators, locator);
153 }
154
155 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
156
157 BAD_SW_IF_INDEX_LABEL;
158
159 vec_free (locator_name);
160 vec_free (a->locators);
161
162 /* *INDENT-OFF* */
163 REPLY_MACRO2 (VL_API_ONE_ADD_DEL_LOCATOR_SET_REPLY,
164 ({
165 rmp->ls_index = clib_host_to_net_u32 (ls_index);
166 }));
167 /* *INDENT-ON* */
168}
169
170static void
171vl_api_one_add_del_locator_t_handler (vl_api_one_add_del_locator_t * mp)
172{
173 vl_api_one_add_del_locator_reply_t *rmp;
174 int rv = 0;
175 locator_t locator, *locators = NULL;
176 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
177 u32 ls_index = ~0;
178 u8 *locator_name = NULL;
179
180 memset (&locator, 0, sizeof (locator));
181 memset (a, 0, sizeof (a[0]));
182
183 locator.sw_if_index = ntohl (mp->sw_if_index);
184 locator.priority = mp->priority;
185 locator.weight = mp->weight;
186 locator.local = 1;
187 vec_add1 (locators, locator);
188
189 locator_name = format (0, "%s", mp->locator_set_name);
190
191 a->name = locator_name;
192 a->locators = locators;
193 a->is_add = mp->is_add;
194 a->local = 1;
195
196 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
197
198 vec_free (locators);
199 vec_free (locator_name);
200
201 REPLY_MACRO (VL_API_ONE_ADD_DEL_LOCATOR_REPLY);
202}
203
204static int
205unformat_one_eid_api (gid_address_t * dst, u32 vni, u8 type, void *src,
206 u8 len)
207{
208 switch (type)
209 {
210 case 0: /* ipv4 */
211 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
212 gid_address_ip_set (dst, src, IP4);
213 gid_address_ippref_len (dst) = len;
214 ip_prefix_normalize (&gid_address_ippref (dst));
215 break;
216 case 1: /* ipv6 */
217 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
218 gid_address_ip_set (dst, src, IP6);
219 gid_address_ippref_len (dst) = len;
220 ip_prefix_normalize (&gid_address_ippref (dst));
221 break;
222 case 2: /* l2 mac */
223 gid_address_type (dst) = GID_ADDR_MAC;
224 clib_memcpy (&gid_address_mac (dst), src, 6);
225 break;
226 default:
227 /* unknown type */
228 return VNET_API_ERROR_INVALID_VALUE;
229 }
230
231 gid_address_vni (dst) = vni;
232
233 return 0;
234}
235
236static void
237vl_api_one_add_del_local_eid_t_handler (vl_api_one_add_del_local_eid_t * mp)
238{
239 vl_api_one_add_del_local_eid_reply_t *rmp;
240 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
241 int rv = 0;
242 gid_address_t _eid, *eid = &_eid;
243 uword *p = NULL;
244 u32 locator_set_index = ~0, map_index = ~0;
245 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
246 u8 *name = NULL, *key = NULL;
247 memset (a, 0, sizeof (a[0]));
248 memset (eid, 0, sizeof (eid[0]));
249
250 rv = unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
251 mp->eid_type, mp->eid, mp->prefix_len);
252 if (rv)
253 goto out;
254
255 name = format (0, "%s", mp->locator_set_name);
256 p = hash_get_mem (lcm->locator_set_index_by_name, name);
257 if (!p)
258 {
259 rv = VNET_API_ERROR_INVALID_VALUE;
260 goto out;
261 }
262 locator_set_index = p[0];
263
264 if (*mp->key)
265 key = format (0, "%s", mp->key);
266
267 /* XXX treat batch configuration */
268 a->is_add = mp->is_add;
269 gid_address_copy (&a->eid, eid);
270 a->locator_set_index = locator_set_index;
271 a->local = 1;
272 a->key = key;
273 a->key_id = clib_net_to_host_u16 (mp->key_id);
274
275 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
276
277out:
278 vec_free (name);
279 vec_free (key);
280 gid_address_free (&a->eid);
281
282 REPLY_MACRO (VL_API_ONE_ADD_DEL_LOCAL_EID_REPLY);
283}
284
285static void
286 vl_api_one_eid_table_add_del_map_t_handler
287 (vl_api_one_eid_table_add_del_map_t * mp)
288{
289 vl_api_one_eid_table_add_del_map_reply_t *rmp;
290 int rv = 0;
291 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
292 clib_net_to_host_u32 (mp->dp_table),
293 mp->is_l2, mp->is_add);
294REPLY_MACRO (VL_API_ONE_EID_TABLE_ADD_DEL_MAP_REPLY)}
295
296static void
297vl_api_one_add_del_map_server_t_handler (vl_api_one_add_del_map_server_t * mp)
298{
299 vl_api_one_add_del_map_server_reply_t *rmp;
300 int rv = 0;
301 ip_address_t addr;
302
303 memset (&addr, 0, sizeof (addr));
304
305 ip_address_set (&addr, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
306 rv = vnet_lisp_add_del_map_server (&addr, mp->is_add);
307
308 REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_SERVER_REPLY);
309}
310
311static void
312vl_api_one_add_del_map_resolver_t_handler (vl_api_one_add_del_map_resolver_t
313 * mp)
314{
315 vl_api_one_add_del_map_resolver_reply_t *rmp;
316 int rv = 0;
317 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
318
319 memset (a, 0, sizeof (a[0]));
320
321 a->is_add = mp->is_add;
322 ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4);
323
324 rv = vnet_lisp_add_del_map_resolver (a);
325
326 REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_RESOLVER_REPLY);
327}
328
329static void
330 vl_api_one_map_register_enable_disable_t_handler
331 (vl_api_one_map_register_enable_disable_t * mp)
332{
333 vl_api_one_map_register_enable_disable_reply_t *rmp;
334 int rv = 0;
335
336 vnet_lisp_map_register_enable_disable (mp->is_enabled);
337 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
338}
339
340static void
341 vl_api_one_rloc_probe_enable_disable_t_handler
342 (vl_api_one_rloc_probe_enable_disable_t * mp)
343{
344 vl_api_one_rloc_probe_enable_disable_reply_t *rmp;
345 int rv = 0;
346
347 vnet_lisp_rloc_probe_enable_disable (mp->is_enabled);
348 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
349}
350
351static void
352vl_api_one_enable_disable_t_handler (vl_api_one_enable_disable_t * mp)
353{
354 vl_api_one_enable_disable_reply_t *rmp;
355 int rv = 0;
356
357 vnet_lisp_enable_disable (mp->is_en);
358 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
359}
360
361static void
362 vl_api_show_one_map_request_mode_t_handler
363 (vl_api_show_one_map_request_mode_t * mp)
364{
365 int rv = 0;
366 vl_api_show_one_map_request_mode_reply_t *rmp;
367
368 /* *INDENT-OFF* */
369 REPLY_MACRO2(VL_API_SHOW_ONE_MAP_REQUEST_MODE_REPLY,
370 ({
371 rmp->mode = vnet_lisp_get_map_request_mode ();
372 }));
373 /* *INDENT-ON* */
374}
375
376static void
377vl_api_one_map_request_mode_t_handler (vl_api_one_map_request_mode_t * mp)
378{
379 vl_api_one_map_request_mode_reply_t *rmp;
380 int rv = 0;
381
382 rv = vnet_lisp_set_map_request_mode (mp->mode);
383
384 REPLY_MACRO (VL_API_ONE_MAP_REQUEST_MODE_REPLY);
385}
386
387static void
388vl_api_one_pitr_set_locator_set_t_handler (vl_api_one_pitr_set_locator_set_t
389 * mp)
390{
391 vl_api_one_pitr_set_locator_set_reply_t *rmp;
392 int rv = 0;
393 u8 *ls_name = 0;
394
395 ls_name = format (0, "%s", mp->ls_name);
396 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
397 vec_free (ls_name);
398
399 REPLY_MACRO (VL_API_ONE_PITR_SET_LOCATOR_SET_REPLY);
400}
401
402static void
403vl_api_one_use_petr_t_handler (vl_api_one_use_petr_t * mp)
404{
405 vl_api_one_use_petr_reply_t *rmp;
406 int rv = 0;
407 ip_address_t addr;
408
409 ip_address_set (&addr, &mp->address, mp->is_ip4 ? IP4 : IP6);
410 rv = vnet_lisp_use_petr (&addr, mp->is_add);
411
412 REPLY_MACRO (VL_API_ONE_USE_PETR_REPLY);
413}
414
415static void
416vl_api_show_one_use_petr_t_handler (vl_api_show_one_use_petr_t * mp)
417{
418 unix_shared_memory_queue_t *q = NULL;
419 vl_api_show_one_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;
424 locator_t *loc = 0;
425 u8 status = 0;
426 gid_address_t addr;
427
428 q = vl_api_client_index_to_input_queue (mp->client_index);
429 if (q == 0)
430 {
431 return;
432 }
433
434 memset (&addr, 0, sizeof (addr));
435 status = lcm->flags & LISP_FLAG_USE_PETR;
436 if (status)
437 {
438 m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index);
439 if (~0 != m->locator_set_index)
440 {
441 ls =
442 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
443 loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]);
444 gid_address_copy (&addr, &loc->address);
445 }
446 }
447
448 /* *INDENT-OFF* */
449 REPLY_MACRO2 (VL_API_SHOW_ONE_USE_PETR_REPLY,
450 {
451 rmp->status = status;
452 gid_address_put (rmp->address, &addr);
453 rmp->is_ip4 = (gid_address_ip_version (&addr) == IP4);
454 });
455 /* *INDENT-ON* */
456}
457
458static void
459 vl_api_one_add_del_map_request_itr_rlocs_t_handler
460 (vl_api_one_add_del_map_request_itr_rlocs_t * mp)
461{
462 vl_api_one_add_del_map_request_itr_rlocs_reply_t *rmp;
463 int rv = 0;
464 u8 *locator_set_name = NULL;
465 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
466
467 locator_set_name = format (0, "%s", mp->locator_set_name);
468
469 a->is_add = mp->is_add;
470 a->locator_set_name = locator_set_name;
471
472 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
473
474 vec_free (locator_set_name);
475
476 REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
477}
478
479static void
480 vl_api_one_add_del_remote_mapping_t_handler
481 (vl_api_one_add_del_remote_mapping_t * mp)
482{
483 locator_t *rlocs = 0;
484 vl_api_one_add_del_remote_mapping_reply_t *rmp;
485 int rv = 0;
486 gid_address_t _eid, *eid = &_eid;
487 u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
488
489 memset (eid, 0, sizeof (eid[0]));
490
491 rv = unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
492 mp->eid_type, mp->eid, mp->eid_len);
493 if (rv)
494 goto send_reply;
495
496 rlocs = unformat_one_locs (mp->rlocs, rloc_num);
497
498 if (!mp->is_add)
499 {
500 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
501 gid_address_copy (&a->reid, eid);
502 a->is_add = 0;
503 rv = vnet_lisp_add_del_adjacency (a);
504 if (rv)
505 {
506 goto out;
507 }
508 }
509
510 /* NOTE: for now this works as a static remote mapping, i.e.,
511 * not authoritative and ttl infinite. */
512 rv = vnet_lisp_add_del_mapping (eid, rlocs, mp->action, 0, ~0,
513 mp->is_add, 1 /* is_static */ , 0);
514
515 if (mp->del_all)
516 vnet_lisp_clear_all_remote_adjacencies ();
517
518out:
519 vec_free (rlocs);
520send_reply:
521 REPLY_MACRO (VL_API_ONE_ADD_DEL_REMOTE_MAPPING_REPLY);
522}
523
524static void
525vl_api_one_add_del_adjacency_t_handler (vl_api_one_add_del_adjacency_t * mp)
526{
527 vl_api_one_add_del_adjacency_reply_t *rmp;
528 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
529
530 int rv = 0;
531 memset (a, 0, sizeof (a[0]));
532
533 rv = unformat_one_eid_api (&a->leid, clib_net_to_host_u32 (mp->vni),
534 mp->eid_type, mp->leid, mp->leid_len);
535 rv |= unformat_one_eid_api (&a->reid, clib_net_to_host_u32 (mp->vni),
536 mp->eid_type, mp->reid, mp->reid_len);
537
538 if (rv)
539 goto send_reply;
540
541 a->is_add = mp->is_add;
542 rv = vnet_lisp_add_del_adjacency (a);
543
544send_reply:
545 REPLY_MACRO (VL_API_ONE_ADD_DEL_ADJACENCY_REPLY);
546}
547
548static void
549send_one_locator_details (lisp_cp_main_t * lcm,
550 locator_t * loc,
551 unix_shared_memory_queue_t * q, u32 context)
552{
553 vl_api_one_locator_details_t *rmp;
554
555 rmp = vl_msg_api_alloc (sizeof (*rmp));
556 memset (rmp, 0, sizeof (*rmp));
557 rmp->_vl_msg_id = ntohs (VL_API_ONE_LOCATOR_DETAILS);
558 rmp->context = context;
559
560 rmp->local = loc->local;
561 if (loc->local)
562 {
563 rmp->sw_if_index = ntohl (loc->sw_if_index);
564 }
565 else
566 {
567 rmp->is_ipv6 = gid_address_ip_version (&loc->address);
568 ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address));
569 }
570 rmp->priority = loc->priority;
571 rmp->weight = loc->weight;
572
573 vl_msg_api_send_shmem (q, (u8 *) & rmp);
574}
575
576static void
577vl_api_one_locator_dump_t_handler (vl_api_one_locator_dump_t * mp)
578{
579 u8 *ls_name = 0;
580 unix_shared_memory_queue_t *q = 0;
581 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
582 locator_set_t *lsit = 0;
583 locator_t *loc = 0;
584 u32 ls_index = ~0, *locit = 0;
585 uword *p = 0;
586
587 q = vl_api_client_index_to_input_queue (mp->client_index);
588 if (q == 0)
589 {
590 return;
591 }
592
593 if (mp->is_index_set)
594 ls_index = htonl (mp->ls_index);
595 else
596 {
597 /* make sure we get a proper C-string */
598 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
599 ls_name = format (0, "%s", mp->ls_name);
600 p = hash_get_mem (lcm->locator_set_index_by_name, ls_name);
601 if (!p)
602 goto out;
603 ls_index = p[0];
604 }
605
606 if (pool_is_free_index (lcm->locator_set_pool, ls_index))
607 return;
608
609 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
610
611 vec_foreach (locit, lsit->locator_indices)
612 {
613 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
614 send_one_locator_details (lcm, loc, q, mp->context);
615 };
616out:
617 vec_free (ls_name);
618}
619
620static void
621send_one_locator_set_details (lisp_cp_main_t * lcm,
622 locator_set_t * lsit,
623 unix_shared_memory_queue_t * q,
624 u32 context, u32 ls_index)
625{
626 vl_api_one_locator_set_details_t *rmp;
627 u8 *str = 0;
628
629 rmp = vl_msg_api_alloc (sizeof (*rmp));
630 memset (rmp, 0, sizeof (*rmp));
631 rmp->_vl_msg_id = ntohs (VL_API_ONE_LOCATOR_SET_DETAILS);
632 rmp->context = context;
633
634 rmp->ls_index = htonl (ls_index);
635 if (lsit->local)
636 {
637 ASSERT (lsit->name != NULL);
638 strncpy ((char *) rmp->ls_name, (char *) lsit->name,
639 vec_len (lsit->name));
640 }
641 else
642 {
643 str = format (0, "<remote-%d>", ls_index);
644 strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str));
645 vec_free (str);
646 }
647
648 vl_msg_api_send_shmem (q, (u8 *) & rmp);
649}
650
651static void
652vl_api_one_locator_set_dump_t_handler (vl_api_one_locator_set_dump_t * mp)
653{
654 unix_shared_memory_queue_t *q = NULL;
655 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
656 locator_set_t *lsit = NULL;
657 u8 filter;
658
659 q = vl_api_client_index_to_input_queue (mp->client_index);
660 if (q == 0)
661 {
662 return;
663 }
664
665 filter = mp->filter;
666 /* *INDENT-OFF* */
667 pool_foreach (lsit, lcm->locator_set_pool,
668 ({
669 if (filter && !((1 == filter && lsit->local) ||
670 (2 == filter && !lsit->local)))
671 {
672 continue;
673 }
674 send_one_locator_set_details (lcm, lsit, q, mp->context,
675 lsit - lcm->locator_set_pool);
676 }));
677 /* *INDENT-ON* */
678}
679
680static void
681one_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length)
682{
683 ASSERT (prefix_length);
684 ip_prefix_t *ippref = &fid_addr_ippref (src);
685
686 switch (fid_addr_type (src))
687 {
688 case FID_ADDR_IP_PREF:
689 if (ip_prefix_version (ippref) == IP4)
690 clib_memcpy (dst, &ip_prefix_v4 (ippref), 4);
691 else
692 clib_memcpy (dst, &ip_prefix_v6 (ippref), 16);
693 prefix_length[0] = ip_prefix_len (ippref);
694 break;
695
696 case FID_ADDR_MAC:
697 prefix_length[0] = 0;
698 clib_memcpy (dst, fid_addr_mac (src), 6);
699 break;
700
701 default:
702 clib_warning ("Unknown FID type %d!", fid_addr_type (src));
703 break;
704 }
705}
706
707static u8
708fid_type_to_api_type (fid_address_t * fid)
709{
710 ip_prefix_t *ippref;
711
712 switch (fid_addr_type (fid))
713 {
714 case FID_ADDR_IP_PREF:
715 ippref = &fid_addr_ippref (fid);
716 if (ip_prefix_version (ippref) == IP4)
717 return 0;
718 else if (ip_prefix_version (ippref) == IP6)
719 return 1;
720 else
721 return ~0;
722
723 case FID_ADDR_MAC:
724 return 2;
725 case FID_ADDR_NSH:
726 return 3;
727 }
728
729 return ~0;
730}
731
732static void
733send_one_eid_table_details (mapping_t * mapit,
734 unix_shared_memory_queue_t * q,
735 u32 context, u8 filter)
736{
737 fid_address_t *fid;
738 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
739 locator_set_t *ls = 0;
740 vl_api_one_eid_table_details_t *rmp = NULL;
741 gid_address_t *gid = NULL;
742 u8 *mac = 0;
743 ip_prefix_t *ip_prefix = NULL;
744
745 switch (filter)
746 {
747 case 0: /* all mappings */
748 break;
749
750 case 1: /* local only */
751 if (!mapit->local)
752 return;
753 break;
754 case 2: /* remote only */
755 if (mapit->local)
756 return;
757 break;
758 default:
759 clib_warning ("Filter error, unknown filter: %d", filter);
760 return;
761 }
762
763 gid = &mapit->eid;
764 ip_prefix = &gid_address_ippref (gid);
765 mac = gid_address_mac (gid);
766
767 rmp = vl_msg_api_alloc (sizeof (*rmp));
768 memset (rmp, 0, sizeof (*rmp));
769 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_DETAILS);
770
771 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
772 if (vec_len (ls->locator_indices) == 0)
773 rmp->locator_set_index = ~0;
774 else
775 rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
776
777 rmp->is_local = mapit->local;
778 rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
779 rmp->action = mapit->action;
780 rmp->authoritative = mapit->authoritative;
781
782 switch (gid_address_type (gid))
783 {
784 case GID_ADDR_SRC_DST:
785 rmp->is_src_dst = 1;
786 fid = &gid_address_sd_src (gid);
787 rmp->eid_type = fid_type_to_api_type (fid);
788 one_fid_put_api (rmp->seid, &gid_address_sd_src (gid),
789 &rmp->seid_prefix_len);
790 one_fid_put_api (rmp->eid, &gid_address_sd_dst (gid),
791 &rmp->eid_prefix_len);
792 break;
793 case GID_ADDR_IP_PREFIX:
794 rmp->eid_prefix_len = ip_prefix_len (ip_prefix);
795 if (ip_prefix_version (ip_prefix) == IP4)
796 {
797 rmp->eid_type = 0; /* ipv4 type */
798 clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix),
799 sizeof (ip_prefix_v4 (ip_prefix)));
800 }
801 else
802 {
803 rmp->eid_type = 1; /* ipv6 type */
804 clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix),
805 sizeof (ip_prefix_v6 (ip_prefix)));
806 }
807 break;
808 case GID_ADDR_MAC:
809 rmp->eid_type = 2; /* l2 mac type */
810 clib_memcpy (rmp->eid, mac, 6);
811 break;
812 default:
813 ASSERT (0);
814 }
815 rmp->context = context;
816 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
817 rmp->key_id = clib_host_to_net_u16 (mapit->key_id);
818 memcpy (rmp->key, mapit->key, vec_len (mapit->key));
819 vl_msg_api_send_shmem (q, (u8 *) & rmp);
820}
821
822static void
823vl_api_one_eid_table_dump_t_handler (vl_api_one_eid_table_dump_t * mp)
824{
825 u32 mi;
826 unix_shared_memory_queue_t *q = NULL;
827 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
828 mapping_t *mapit = NULL;
829 gid_address_t _eid, *eid = &_eid;
830
831 q = vl_api_client_index_to_input_queue (mp->client_index);
832 if (q == 0)
833 {
834 return;
835 }
836
837 if (mp->eid_set)
838 {
839 memset (eid, 0, sizeof (*eid));
840
841 unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni),
842 mp->eid_type, mp->eid, mp->prefix_length);
843
844 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
845 if ((u32) ~ 0 == mi)
846 return;
847
848 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
849 send_one_eid_table_details (mapit, q, mp->context,
850 0 /* ignore filter */ );
851 }
852 else
853 {
854 /* *INDENT-OFF* */
855 pool_foreach (mapit, lcm->mapping_pool,
856 ({
857 send_one_eid_table_details(mapit, q, mp->context,
858 mp->filter);
859 }));
860 /* *INDENT-ON* */
861 }
862}
863
864static void
865send_one_map_server_details (ip_address_t * ip,
866 unix_shared_memory_queue_t * q, u32 context)
867{
868 vl_api_one_map_server_details_t *rmp = NULL;
869
870 rmp = vl_msg_api_alloc (sizeof (*rmp));
871 memset (rmp, 0, sizeof (*rmp));
872 rmp->_vl_msg_id = ntohs (VL_API_ONE_MAP_SERVER_DETAILS);
873
874 switch (ip_addr_version (ip))
875 {
876 case IP4:
877 rmp->is_ipv6 = 0;
878 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
879 sizeof (ip_addr_v4 (ip)));
880 break;
881
882 case IP6:
883 rmp->is_ipv6 = 1;
884 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
885 sizeof (ip_addr_v6 (ip)));
886 break;
887
888 default:
889 ASSERT (0);
890 }
891 rmp->context = context;
892
893 vl_msg_api_send_shmem (q, (u8 *) & rmp);
894}
895
896static void
897vl_api_one_map_server_dump_t_handler (vl_api_one_map_server_dump_t * mp)
898{
899 unix_shared_memory_queue_t *q = NULL;
900 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
901 lisp_msmr_t *mr;
902
903 q = vl_api_client_index_to_input_queue (mp->client_index);
904 if (q == 0)
905 {
906 return;
907 }
908
909 vec_foreach (mr, lcm->map_servers)
910 {
911 send_one_map_server_details (&mr->address, q, mp->context);
912 }
913}
914
915static void
916send_one_map_resolver_details (ip_address_t * ip,
917 unix_shared_memory_queue_t * q, u32 context)
918{
919 vl_api_one_map_resolver_details_t *rmp = NULL;
920
921 rmp = vl_msg_api_alloc (sizeof (*rmp));
922 memset (rmp, 0, sizeof (*rmp));
923 rmp->_vl_msg_id = ntohs (VL_API_ONE_MAP_RESOLVER_DETAILS);
924
925 switch (ip_addr_version (ip))
926 {
927 case IP4:
928 rmp->is_ipv6 = 0;
929 clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip),
930 sizeof (ip_addr_v4 (ip)));
931 break;
932
933 case IP6:
934 rmp->is_ipv6 = 1;
935 clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip),
936 sizeof (ip_addr_v6 (ip)));
937 break;
938
939 default:
940 ASSERT (0);
941 }
942 rmp->context = context;
943
944 vl_msg_api_send_shmem (q, (u8 *) & rmp);
945}
946
947static void
948vl_api_one_map_resolver_dump_t_handler (vl_api_one_map_resolver_dump_t * mp)
949{
950 unix_shared_memory_queue_t *q = NULL;
951 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
952 lisp_msmr_t *mr;
953
954 q = vl_api_client_index_to_input_queue (mp->client_index);
955 if (q == 0)
956 {
957 return;
958 }
959
960 vec_foreach (mr, lcm->map_resolvers)
961 {
962 send_one_map_resolver_details (&mr->address, q, mp->context);
963 }
964}
965
966static void
967send_eid_table_map_pair (hash_pair_t * p,
968 unix_shared_memory_queue_t * q, u32 context)
969{
970 vl_api_one_eid_table_map_details_t *rmp = NULL;
971
972 rmp = vl_msg_api_alloc (sizeof (*rmp));
973 memset (rmp, 0, sizeof (*rmp));
974 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_MAP_DETAILS);
975
976 rmp->vni = clib_host_to_net_u32 (p->key);
977 rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
978 rmp->context = context;
979 vl_msg_api_send_shmem (q, (u8 *) & rmp);
980}
981
982static void
983vl_api_one_eid_table_map_dump_t_handler (vl_api_one_eid_table_map_dump_t * mp)
984{
985 unix_shared_memory_queue_t *q = NULL;
986 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
987 hash_pair_t *p;
988 uword *vni_table = 0;
989
990 q = vl_api_client_index_to_input_queue (mp->client_index);
991 if (q == 0)
992 {
993 return;
994 }
995
996 if (mp->is_l2)
997 {
998 vni_table = lcm->bd_id_by_vni;
999 }
1000 else
1001 {
1002 vni_table = lcm->table_id_by_vni;
1003 }
1004
1005 /* *INDENT-OFF* */
1006 hash_foreach_pair (p, vni_table,
1007 ({
1008 send_eid_table_map_pair (p, q, mp->context);
1009 }));
1010 /* *INDENT-ON* */
1011}
1012
1013static void
1014send_eid_table_vni (u32 vni, unix_shared_memory_queue_t * q, u32 context)
1015{
1016 vl_api_one_eid_table_vni_details_t *rmp = 0;
1017
1018 rmp = vl_msg_api_alloc (sizeof (*rmp));
1019 memset (rmp, 0, sizeof (*rmp));
1020 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_VNI_DETAILS);
1021 rmp->context = context;
1022 rmp->vni = clib_host_to_net_u32 (vni);
1023 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1024}
1025
1026static void
1027one_adjacency_copy (vl_api_one_adjacency_t * dst, lisp_adjacency_t * adjs)
1028{
1029 lisp_adjacency_t *adj;
1030 vl_api_one_adjacency_t a;
1031 u32 i, n = vec_len (adjs);
1032
1033 for (i = 0; i < n; i++)
1034 {
1035 adj = vec_elt_at_index (adjs, i);
1036 memset (&a, 0, sizeof (a));
1037
1038 switch (gid_address_type (&adj->reid))
1039 {
1040 case GID_ADDR_IP_PREFIX:
1041 a.reid_prefix_len = gid_address_ippref_len (&adj->reid);
1042 a.leid_prefix_len = gid_address_ippref_len (&adj->leid);
1043 if (gid_address_ip_version (&adj->reid) == IP4)
1044 {
1045 a.eid_type = 0; /* ipv4 type */
1046 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 4);
1047 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 4);
1048 }
1049 else
1050 {
1051 a.eid_type = 1; /* ipv6 type */
1052 clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 16);
1053 clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 16);
1054 }
1055 break;
1056 case GID_ADDR_MAC:
1057 a.eid_type = 2; /* l2 mac type */
1058 mac_copy (a.reid, gid_address_mac (&adj->reid));
1059 mac_copy (a.leid, gid_address_mac (&adj->leid));
1060 break;
1061 default:
1062 ASSERT (0);
1063 }
1064 dst[i] = a;
1065 }
1066}
1067
1068static void
1069 vl_api_show_one_rloc_probe_state_t_handler
1070 (vl_api_show_one_rloc_probe_state_t * mp)
1071{
1072 vl_api_show_one_rloc_probe_state_reply_t *rmp = 0;
1073 int rv = 0;
1074
1075 /* *INDENT-OFF* */
1076 REPLY_MACRO2 (VL_API_SHOW_ONE_RLOC_PROBE_STATE_REPLY,
1077 {
1078 rmp->is_enabled = vnet_lisp_rloc_probe_state_get ();
1079 });
1080 /* *INDENT-ON* */
1081}
1082
1083static void
1084 vl_api_show_one_map_register_state_t_handler
1085 (vl_api_show_one_map_register_state_t * mp)
1086{
1087 vl_api_show_one_map_register_state_reply_t *rmp = 0;
1088 int rv = 0;
1089
1090 /* *INDENT-OFF* */
1091 REPLY_MACRO2 (VL_API_SHOW_ONE_MAP_REGISTER_STATE_REPLY,
1092 {
1093 rmp->is_enabled = vnet_lisp_map_register_state_get ();
1094 });
1095 /* *INDENT-ON* */
1096}
1097
1098static void
1099vl_api_one_adjacencies_get_t_handler (vl_api_one_adjacencies_get_t * mp)
1100{
1101 vl_api_one_adjacencies_get_reply_t *rmp = 0;
1102 lisp_adjacency_t *adjs = 0;
1103 int rv = 0;
1104 u32 size = ~0;
1105 u32 vni = clib_net_to_host_u32 (mp->vni);
1106
1107 adjs = vnet_lisp_adjacencies_get_by_vni (vni);
1108 size = vec_len (adjs) * sizeof (vl_api_one_adjacency_t);
1109
1110 /* *INDENT-OFF* */
1111 REPLY_MACRO4 (VL_API_ONE_ADJACENCIES_GET_REPLY, size,
1112 {
1113 rmp->count = clib_host_to_net_u32 (vec_len (adjs));
1114 one_adjacency_copy (rmp->adjacencies, adjs);
1115 });
1116 /* *INDENT-ON* */
1117
1118 vec_free (adjs);
1119}
1120
1121static void
1122vl_api_one_eid_table_vni_dump_t_handler (vl_api_one_eid_table_vni_dump_t * mp)
1123{
1124 hash_pair_t *p;
1125 u32 *vnis = 0;
1126 unix_shared_memory_queue_t *q = 0;
1127 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1128
1129 q = vl_api_client_index_to_input_queue (mp->client_index);
1130 if (q == 0)
1131 {
1132 return;
1133 }
1134
1135 /* *INDENT-OFF* */
1136 hash_foreach_pair (p, lcm->table_id_by_vni,
1137 ({
1138 hash_set (vnis, p->key, 0);
1139 }));
1140
1141 hash_foreach_pair (p, lcm->bd_id_by_vni,
1142 ({
1143 hash_set (vnis, p->key, 0);
1144 }));
1145
1146 hash_foreach_pair (p, vnis,
1147 ({
1148 send_eid_table_vni (p->key, q, mp->context);
1149 }));
1150 /* *INDENT-ON* */
1151
1152 hash_free (vnis);
1153}
1154
1155static void
1156vl_api_show_one_status_t_handler (vl_api_show_one_status_t * mp)
1157{
1158 unix_shared_memory_queue_t *q = NULL;
1159 vl_api_show_one_status_reply_t *rmp = NULL;
1160 int rv = 0;
1161
1162 q = vl_api_client_index_to_input_queue (mp->client_index);
1163 if (q == 0)
1164 {
1165 return;
1166 }
1167
1168 /* *INDENT-OFF* */
1169 REPLY_MACRO2(VL_API_SHOW_ONE_STATUS_REPLY,
1170 ({
1171 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
1172 rmp->feature_status = vnet_lisp_enable_disable_status ();
1173 }));
1174 /* *INDENT-ON* */
1175}
1176
1177static void
1178 vl_api_one_get_map_request_itr_rlocs_t_handler
1179 (vl_api_one_get_map_request_itr_rlocs_t * mp)
1180{
1181 unix_shared_memory_queue_t *q = NULL;
1182 vl_api_one_get_map_request_itr_rlocs_reply_t *rmp = NULL;
1183 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1184 locator_set_t *loc_set = 0;
1185 u8 *tmp_str = 0;
1186 int rv = 0;
1187
1188 q = vl_api_client_index_to_input_queue (mp->client_index);
1189 if (q == 0)
1190 {
1191 return;
1192 }
1193
1194 if (~0 == lcm->mreq_itr_rlocs)
1195 {
1196 tmp_str = format (0, " ");
1197 }
1198 else
1199 {
1200 loc_set =
1201 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
1202 tmp_str = format (0, "%s", loc_set->name);
1203 }
1204
1205 /* *INDENT-OFF* */
1206 REPLY_MACRO2(VL_API_ONE_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
1207 ({
1208 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1209 ARRAY_LEN(rmp->locator_set_name) - 1);
1210 }));
1211 /* *INDENT-ON* */
1212
1213 vec_free (tmp_str);
1214}
1215
1216static void
1217vl_api_show_one_pitr_t_handler (vl_api_show_one_pitr_t * mp)
1218{
1219 unix_shared_memory_queue_t *q = NULL;
1220 vl_api_show_one_pitr_reply_t *rmp = NULL;
1221 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1222 mapping_t *m;
1223 locator_set_t *ls = 0;
1224 u8 *tmp_str = 0;
1225 int rv = 0;
1226
1227 q = vl_api_client_index_to_input_queue (mp->client_index);
1228 if (q == 0)
1229 {
1230 return;
1231 }
1232
1233 if (!lcm->lisp_pitr)
1234 {
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_ONE_PITR_REPLY,
1255 ({
1256 rmp->status = lcm->lisp_pitr;
1257 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1258 ARRAY_LEN(rmp->locator_set_name) - 1);
1259 }));
1260 /* *INDENT-ON* */
1261}
1262
Filip Tehlar7eaf0e52017-03-08 08:46:51 +01001263static void
1264 vl_api_show_one_stats_enable_disable_t_handler
1265 (vl_api_show_one_stats_enable_disable_t * mp)
1266{
1267 vl_api_show_one_stats_enable_disable_reply_t *rmp = NULL;
1268 vnet_api_error_t rv = 0;
1269
1270 /* *INDENT-OFF* */
1271 REPLY_MACRO2 (VL_API_SHOW_ONE_STATS_ENABLE_DISABLE_REPLY,
1272 ({
1273 rmp->is_en = vnet_lisp_stats_enable_disable_state ();
1274 }));
1275 /* *INDENT-ON* */
1276}
1277
1278static void
1279 vl_api_one_stats_enable_disable_t_handler
1280 (vl_api_one_stats_enable_disable_t * mp)
1281{
1282 vl_api_one_enable_disable_reply_t *rmp = NULL;
1283
1284 vnet_api_error_t rv = vnet_lisp_stats_enable_disable (mp->is_en);
1285 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
1286}
1287
1288static void
1289vl_api_one_stats_dump_t_handler (vl_api_one_stats_dump_t * mp)
1290{
1291
1292}
1293
Filip Tehlar694396d2017-02-17 14:29:11 +01001294/*
1295 * one_api_hookup
1296 * Add vpe's API message handlers to the table.
1297 * vlib has alread mapped shared memory and
1298 * added the client registration handlers.
1299 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
1300 */
1301#define vl_msg_name_crc_list
1302#include <vnet/vnet_all_api_h.h>
1303#undef vl_msg_name_crc_list
1304
1305static void
1306setup_message_id_table (api_main_t * am)
1307{
1308#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
Filip Tehlar974cdc62017-02-22 18:09:49 +01001309 foreach_vl_msg_name_crc_one;
Filip Tehlar694396d2017-02-17 14:29:11 +01001310#undef _
1311}
1312
1313static clib_error_t *
1314one_api_hookup (vlib_main_t * vm)
1315{
1316 api_main_t *am = &api_main;
1317
1318#define _(N,n) \
1319 vl_msg_api_set_handlers(VL_API_##N, #n, \
1320 vl_api_##n##_t_handler, \
1321 vl_noop_handler, \
1322 vl_api_##n##_t_endian, \
1323 vl_api_##n##_t_print, \
1324 sizeof(vl_api_##n##_t), 1);
1325 foreach_vpe_api_msg;
1326#undef _
1327
1328 /*
1329 * Set up the (msg_name, crc, message-id) table
1330 */
1331 setup_message_id_table (am);
1332
1333 return 0;
1334}
1335
1336VLIB_API_INIT_FUNCTION (one_api_hookup);
1337
1338/*
1339 * fd.io coding-style-patch-verification: ON
1340 *
1341 * Local Variables:
1342 * eval: (c-set-style "gnu")
1343 * End:
1344 */