blob: f7a972be7a297cbc4ebb087d1a4a465d2a95f6cf [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
Jakub Grajciar58db6e12020-01-30 13:26:43 +010028#include <vnet/ip/ip_types_api.h>
29#include <vnet/ethernet/ethernet_types_api.h>
30
Filip Tehlar694396d2017-02-17 14:29:11 +010031#include <vnet/vnet_msg_enum.h>
32
Filip Tehlar694396d2017-02-17 14:29:11 +010033#define vl_api_one_add_del_locator_set_t_endian vl_noop_handler
34#define vl_api_one_add_del_locator_set_t_print vl_noop_handler
35#define vl_api_one_add_del_remote_mapping_t_endian vl_noop_handler
36#define vl_api_one_add_del_remote_mapping_t_print vl_noop_handler
37
38#define vl_api_one_add_del_locator_set_t_endian vl_noop_handler
39#define vl_api_one_add_del_locator_set_t_print vl_noop_handler
40#define vl_api_one_add_del_remote_mapping_t_endian vl_noop_handler
41#define vl_api_one_add_del_remote_mapping_t_print vl_noop_handler
42
Filip Tehlard5a65db2017-05-17 17:21:10 +020043#define vl_api_one_add_del_l2_arp_entry vl_noop_handler
44#define vl_api_one_l2_arp_bd_get vl_noop_handler
45
Filip Tehlard6307132017-09-04 18:54:33 +020046#define vl_api_one_ndp_entries_get_reply_t_endian vl_noop_handler
47#define vl_api_one_ndp_entries_get_reply_t_print vl_noop_handler
48
Filip Tehlar694396d2017-02-17 14:29:11 +010049#define vl_typedefs /* define message structures */
50#include <vnet/vnet_all_api_h.h>
51#undef vl_typedefs
52
53#define vl_endianfun /* define message structures */
54#include <vnet/vnet_all_api_h.h>
55#undef vl_endianfun
56
57/* instantiate all the print functions we know about */
58#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
59#define vl_printfun
60#include <vnet/vnet_all_api_h.h>
61#undef vl_printfun
62
63#include <vlibapi/api_helper_macros.h>
64
Florin Coras6c4dae22018-01-09 06:39:23 -080065#define REPLY_DETAILS(t, body) \
66do { \
67 vl_api_registration_t * reg; \
68 rv = vl_msg_api_pd_handler (mp, rv); \
69 reg = vl_api_client_index_to_registration (mp->client_index); \
70 if (!reg) \
71 return; \
72 \
73 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
74 rmp->_vl_msg_id = ntohs((t)); \
75 rmp->context = mp->context; \
76 do {body;} while (0); \
77 vl_api_send_msg (reg, (u8 *)&rmp); \
Filip Tehlar4868ff62017-03-09 16:48:39 +010078} while(0);
79
Florin Coras6c4dae22018-01-09 06:39:23 -080080#define foreach_vpe_api_msg \
Filip Tehlar694396d2017-02-17 14:29:11 +010081_(ONE_ADD_DEL_LOCATOR_SET, one_add_del_locator_set) \
82_(ONE_ADD_DEL_LOCATOR, one_add_del_locator) \
83_(ONE_ADD_DEL_LOCAL_EID, one_add_del_local_eid) \
84_(ONE_ADD_DEL_MAP_RESOLVER, one_add_del_map_resolver) \
85_(ONE_ADD_DEL_MAP_SERVER, one_add_del_map_server) \
86_(ONE_ENABLE_DISABLE, one_enable_disable) \
87_(ONE_RLOC_PROBE_ENABLE_DISABLE, one_rloc_probe_enable_disable) \
88_(ONE_MAP_REGISTER_ENABLE_DISABLE, one_map_register_enable_disable) \
Filip Tehlar7048ff12017-07-27 08:09:14 +020089_(ONE_MAP_REGISTER_FALLBACK_THRESHOLD, \
90 one_map_register_fallback_threshold) \
Filip Tehlar694396d2017-02-17 14:29:11 +010091_(ONE_ADD_DEL_REMOTE_MAPPING, one_add_del_remote_mapping) \
92_(ONE_ADD_DEL_ADJACENCY, one_add_del_adjacency) \
93_(ONE_PITR_SET_LOCATOR_SET, one_pitr_set_locator_set) \
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020094_(ONE_NSH_SET_LOCATOR_SET, one_nsh_set_locator_set) \
Filip Tehlar694396d2017-02-17 14:29:11 +010095_(ONE_MAP_REQUEST_MODE, one_map_request_mode) \
96_(ONE_EID_TABLE_ADD_DEL_MAP, one_eid_table_add_del_map) \
97_(ONE_LOCATOR_SET_DUMP, one_locator_set_dump) \
98_(ONE_LOCATOR_DUMP, one_locator_dump) \
99_(ONE_EID_TABLE_DUMP, one_eid_table_dump) \
100_(ONE_MAP_RESOLVER_DUMP, one_map_resolver_dump) \
101_(ONE_MAP_SERVER_DUMP, one_map_server_dump) \
102_(ONE_EID_TABLE_MAP_DUMP, one_eid_table_map_dump) \
103_(ONE_EID_TABLE_VNI_DUMP, one_eid_table_vni_dump) \
104_(ONE_ADJACENCIES_GET, one_adjacencies_get) \
Filip Tehlar1e553a02017-08-02 12:45:07 +0200105_(ONE_MAP_REGISTER_SET_TTL, one_map_register_set_ttl) \
Filip Tehlaref2a5bf2017-05-30 07:14:46 +0200106_(SHOW_ONE_NSH_MAPPING, show_one_nsh_mapping) \
Filip Tehlar694396d2017-02-17 14:29:11 +0100107_(SHOW_ONE_RLOC_PROBE_STATE, show_one_rloc_probe_state) \
108_(SHOW_ONE_MAP_REGISTER_STATE, show_one_map_register_state) \
Filip Tehlar1e553a02017-08-02 12:45:07 +0200109_(SHOW_ONE_MAP_REGISTER_TTL, show_one_map_register_ttl) \
Filip Tehlar7048ff12017-07-27 08:09:14 +0200110_(SHOW_ONE_MAP_REGISTER_FALLBACK_THRESHOLD, \
111 show_one_map_register_fallback_threshold) \
Filip Tehlar694396d2017-02-17 14:29:11 +0100112_(SHOW_ONE_STATUS, show_one_status) \
113_(ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \
114 one_add_del_map_request_itr_rlocs) \
115_(ONE_GET_MAP_REQUEST_ITR_RLOCS, one_get_map_request_itr_rlocs) \
116_(SHOW_ONE_PITR, show_one_pitr) \
117_(SHOW_ONE_MAP_REQUEST_MODE, show_one_map_request_mode) \
118_(ONE_USE_PETR, one_use_petr) \
119_(SHOW_ONE_USE_PETR, show_one_use_petr) \
Filip Tehlar7eaf0e52017-03-08 08:46:51 +0100120_(SHOW_ONE_STATS_ENABLE_DISABLE, show_one_stats_enable_disable) \
121_(ONE_STATS_ENABLE_DISABLE, one_stats_enable_disable) \
122_(ONE_STATS_DUMP, one_stats_dump) \
Filip Tehlar21511912017-04-07 10:41:42 +0200123_(ONE_STATS_FLUSH, one_stats_flush) \
Filip Tehlard5a65db2017-05-17 17:21:10 +0200124_(ONE_L2_ARP_BD_GET, one_l2_arp_bd_get) \
125_(ONE_L2_ARP_ENTRIES_GET, one_l2_arp_entries_get) \
126_(ONE_ADD_DEL_L2_ARP_ENTRY, one_add_del_l2_arp_entry) \
Filip Tehlar05879992017-09-05 15:46:09 +0200127_(ONE_ADD_DEL_NDP_ENTRY, one_add_del_ndp_entry) \
128_(ONE_NDP_BD_GET, one_ndp_bd_get) \
129_(ONE_NDP_ENTRIES_GET, one_ndp_entries_get) \
Filip Tehlara4980b82017-09-27 14:32:02 +0200130_(ONE_SET_TRANSPORT_PROTOCOL, one_set_transport_protocol) \
Filip Tehlar0a8840d2017-10-16 05:48:23 -0700131_(ONE_GET_TRANSPORT_PROTOCOL, one_get_transport_protocol) \
132_(ONE_ENABLE_DISABLE_XTR_MODE, one_enable_disable_xtr_mode) \
133_(ONE_SHOW_XTR_MODE, one_show_xtr_mode) \
134_(ONE_ENABLE_DISABLE_PITR_MODE, one_enable_disable_pitr_mode) \
135_(ONE_SHOW_PITR_MODE, one_show_pitr_mode) \
136_(ONE_ENABLE_DISABLE_PETR_MODE, one_enable_disable_petr_mode) \
137_(ONE_SHOW_PETR_MODE, one_show_petr_mode) \
138
Filip Tehlar694396d2017-02-17 14:29:11 +0100139
140static locator_t *
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100141unformat_one_locs (vl_api_remote_locator_t * rmt_locs, u32 rloc_num)
Filip Tehlar694396d2017-02-17 14:29:11 +0100142{
143 u32 i;
144 locator_t *locs = 0, loc;
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100145 vl_api_remote_locator_t *r;
Filip Tehlar694396d2017-02-17 14:29:11 +0100146
147 for (i = 0; i < rloc_num; i++)
148 {
149 /* remote locators */
150 r = &rmt_locs[i];
Dave Barachb7b92992018-10-17 10:38:51 -0400151 clib_memset (&loc, 0, sizeof (loc));
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100152 ip_address_decode2 (&r->ip_address, &loc.address.ippref.addr);
153 loc.address.ippref.len =
154 ip_address_max_len (loc.address.ippref.addr.version);
Filip Tehlar694396d2017-02-17 14:29:11 +0100155
156 loc.priority = r->priority;
157 loc.weight = r->weight;
158
159 vec_add1 (locs, loc);
160 }
161 return locs;
162}
163
164static void
Filip Tehlar1e553a02017-08-02 12:45:07 +0200165vl_api_one_map_register_set_ttl_t_handler (vl_api_one_map_register_set_ttl_t *
166 mp)
167{
168 vl_api_one_map_register_set_ttl_reply_t *rmp;
169 int rv = 0;
170
Filip Tehlar5391e192017-08-04 09:13:50 +0200171 mp->ttl = clib_net_to_host_u32 (mp->ttl);
Filip Tehlar1e553a02017-08-02 12:45:07 +0200172 rv = vnet_lisp_map_register_set_ttl (mp->ttl);
173
174 REPLY_MACRO (VL_API_ONE_MAP_REGISTER_SET_TTL_REPLY);
175}
176
177static void
178 vl_api_show_one_map_register_ttl_t_handler
179 (vl_api_show_one_map_register_ttl_t * mp)
180{
181 vl_api_show_one_map_register_ttl_reply_t *rmp;
182 int rv = 0;
183
184 u32 ttl = vnet_lisp_map_register_get_ttl ();
185 /* *INDENT-OFF* */
186 REPLY_MACRO2 (VL_API_SHOW_ONE_MAP_REGISTER_TTL_REPLY,
187 ({
188 rmp->ttl = clib_host_to_net_u32 (ttl);
189 }));
190 /* *INDENT-ON* */
191}
192
193static void
Filip Tehlar694396d2017-02-17 14:29:11 +0100194vl_api_one_add_del_locator_set_t_handler (vl_api_one_add_del_locator_set_t *
195 mp)
196{
197 vl_api_one_add_del_locator_set_reply_t *rmp;
198 int rv = 0;
199 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
200 locator_t locator;
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100201 vl_api_local_locator_t *ls_loc;
Filip Tehlar694396d2017-02-17 14:29:11 +0100202 u32 ls_index = ~0, locator_num;
203 u8 *locator_name = NULL;
204 int i;
205
Dave Barachb7b92992018-10-17 10:38:51 -0400206 clib_memset (a, 0, sizeof (a[0]));
Filip Tehlar694396d2017-02-17 14:29:11 +0100207
Filip Tehlar9d286a42017-10-26 23:57:09 -0700208 mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0;
Filip Tehlar694396d2017-02-17 14:29:11 +0100209 locator_name = format (0, "%s", mp->locator_set_name);
Gabriel Ganne3491d7f2017-10-19 15:10:46 +0200210 vec_terminate_c_string (locator_name);
Filip Tehlar694396d2017-02-17 14:29:11 +0100211
212 a->name = locator_name;
213 a->is_add = mp->is_add;
214 a->local = 1;
215 locator_num = clib_net_to_host_u32 (mp->locator_num);
216
Dave Barachb7b92992018-10-17 10:38:51 -0400217 clib_memset (&locator, 0, sizeof (locator));
Filip Tehlar694396d2017-02-17 14:29:11 +0100218 for (i = 0; i < locator_num; i++)
219 {
220 ls_loc = &mp->locators[i];
221 VALIDATE_SW_IF_INDEX (ls_loc);
222
223 locator.sw_if_index = htonl (ls_loc->sw_if_index);
224 locator.priority = ls_loc->priority;
225 locator.weight = ls_loc->weight;
226 locator.local = 1;
227 vec_add1 (a->locators, locator);
228 }
229
230 rv = vnet_lisp_add_del_locator_set (a, &ls_index);
231
232 BAD_SW_IF_INDEX_LABEL;
233
234 vec_free (locator_name);
235 vec_free (a->locators);
236
237 /* *INDENT-OFF* */
238 REPLY_MACRO2 (VL_API_ONE_ADD_DEL_LOCATOR_SET_REPLY,
239 ({
240 rmp->ls_index = clib_host_to_net_u32 (ls_index);
241 }));
242 /* *INDENT-ON* */
243}
244
245static void
246vl_api_one_add_del_locator_t_handler (vl_api_one_add_del_locator_t * mp)
247{
248 vl_api_one_add_del_locator_reply_t *rmp;
249 int rv = 0;
250 locator_t locator, *locators = NULL;
251 vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
252 u32 ls_index = ~0;
253 u8 *locator_name = NULL;
254
Dave Barachb7b92992018-10-17 10:38:51 -0400255 clib_memset (&locator, 0, sizeof (locator));
256 clib_memset (a, 0, sizeof (a[0]));
Filip Tehlar694396d2017-02-17 14:29:11 +0100257
258 locator.sw_if_index = ntohl (mp->sw_if_index);
259 locator.priority = mp->priority;
260 locator.weight = mp->weight;
261 locator.local = 1;
262 vec_add1 (locators, locator);
263
Filip Tehlar9d286a42017-10-26 23:57:09 -0700264 mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0;
Filip Tehlar694396d2017-02-17 14:29:11 +0100265 locator_name = format (0, "%s", mp->locator_set_name);
Gabriel Ganne3491d7f2017-10-19 15:10:46 +0200266 vec_terminate_c_string (locator_name);
Filip Tehlar694396d2017-02-17 14:29:11 +0100267
268 a->name = locator_name;
269 a->locators = locators;
270 a->is_add = mp->is_add;
271 a->local = 1;
272
273 rv = vnet_lisp_add_del_locator (a, NULL, &ls_index);
274
275 vec_free (locators);
276 vec_free (locator_name);
277
278 REPLY_MACRO (VL_API_ONE_ADD_DEL_LOCATOR_REPLY);
279}
280
Filip Tehlaref2a5bf2017-05-30 07:14:46 +0200281typedef struct
282{
283 u32 spi;
284 u8 si;
285} __attribute__ ((__packed__)) lisp_nsh_api_t;
286
Filip Tehlar694396d2017-02-17 14:29:11 +0100287static int
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100288unformat_one_eid_api (gid_address_t * dst, u32 vni, vl_api_eid_t * eid)
Filip Tehlar694396d2017-02-17 14:29:11 +0100289{
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100290 fib_prefix_t prefix;
Filip Tehlaref2a5bf2017-05-30 07:14:46 +0200291
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100292 switch (eid->type)
Filip Tehlar694396d2017-02-17 14:29:11 +0100293 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100294 case EID_TYPE_API_PREFIX:
295 ip_prefix_decode (&eid->address.prefix, &prefix);
Filip Tehlar694396d2017-02-17 14:29:11 +0100296 gid_address_type (dst) = GID_ADDR_IP_PREFIX;
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100297 if (prefix.fp_proto == FIB_PROTOCOL_IP4)
298 gid_address_ip_set (dst, &prefix.fp_addr.ip4, AF_IP4);
299 if (prefix.fp_proto == FIB_PROTOCOL_IP6)
300 gid_address_ip_set (dst, &prefix.fp_addr.ip6, AF_IP6);
301 gid_address_ippref_len (dst) = prefix.fp_len;
Filip Tehlar694396d2017-02-17 14:29:11 +0100302 ip_prefix_normalize (&gid_address_ippref (dst));
303 break;
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100304 case EID_TYPE_API_MAC:
Filip Tehlar694396d2017-02-17 14:29:11 +0100305 gid_address_type (dst) = GID_ADDR_MAC;
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100306 mac_address_decode (eid->address.mac,
307 (mac_address_t *) & gid_address_mac (dst));
Filip Tehlar694396d2017-02-17 14:29:11 +0100308 break;
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100309 case EID_TYPE_API_NSH:
Filip Tehlaref2a5bf2017-05-30 07:14:46 +0200310 gid_address_type (dst) = GID_ADDR_NSH;
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100311 gid_address_nsh_spi (dst) = clib_net_to_host_u32 (eid->address.nsh.spi);
312 gid_address_nsh_si (dst) = eid->address.nsh.si;
Filip Tehlaref2a5bf2017-05-30 07:14:46 +0200313 break;
Filip Tehlar694396d2017-02-17 14:29:11 +0100314 default:
315 /* unknown type */
316 return VNET_API_ERROR_INVALID_VALUE;
317 }
318
319 gid_address_vni (dst) = vni;
320
321 return 0;
322}
323
324static void
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100325fid_to_api_eid (fid_address_t * fid, vl_api_eid_t * eid)
326{
327 fib_prefix_t fib_prefix;
328 u32 eid_type;
329
330 switch (fid_addr_type (fid))
331 {
332 case FID_ADDR_IP_PREF:
333 eid_type = EID_TYPE_API_PREFIX;
334 ip_prefix_to_fib_prefix (&fid_addr_ippref (fid), &fib_prefix);
335 ip_prefix_encode (&fib_prefix, &eid->address.prefix);
336 break;
337 case FID_ADDR_MAC:
338 eid_type = EID_TYPE_API_MAC;
339 mac_address_encode ((mac_address_t *) fid_addr_mac (fid),
340 eid->address.mac);
341 break;
342 default:
343 /* unknown type */
344 return;
345 }
346
347 eid->type = eid_type;
348}
349
350static void
Filip Tehlar694396d2017-02-17 14:29:11 +0100351vl_api_one_add_del_local_eid_t_handler (vl_api_one_add_del_local_eid_t * mp)
352{
353 vl_api_one_add_del_local_eid_reply_t *rmp;
354 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
355 int rv = 0;
356 gid_address_t _eid, *eid = &_eid;
357 uword *p = NULL;
358 u32 locator_set_index = ~0, map_index = ~0;
359 vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
360 u8 *name = NULL, *key = NULL;
Dave Barachb7b92992018-10-17 10:38:51 -0400361 clib_memset (a, 0, sizeof (a[0]));
362 clib_memset (eid, 0, sizeof (eid[0]));
Filip Tehlar694396d2017-02-17 14:29:11 +0100363
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100364 rv = unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni), &mp->eid);
Filip Tehlar694396d2017-02-17 14:29:11 +0100365 if (rv)
366 goto out;
367
Filip Tehlaref2a5bf2017-05-30 07:14:46 +0200368 if (gid_address_type (eid) == GID_ADDR_NSH)
369 {
370 rv = VNET_API_ERROR_INVALID_VALUE;
371 goto out;
372 }
373
Filip Tehlar9d286a42017-10-26 23:57:09 -0700374 mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0;
Filip Tehlar694396d2017-02-17 14:29:11 +0100375 name = format (0, "%s", mp->locator_set_name);
Gabriel Ganne3491d7f2017-10-19 15:10:46 +0200376 vec_terminate_c_string (name);
Filip Tehlar694396d2017-02-17 14:29:11 +0100377 p = hash_get_mem (lcm->locator_set_index_by_name, name);
378 if (!p)
379 {
380 rv = VNET_API_ERROR_INVALID_VALUE;
381 goto out;
382 }
383 locator_set_index = p[0];
384
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100385 if (mp->key.id != KEY_ID_API_HMAC_NO_KEY)
386 key = format (0, "%s", mp->key.key);
Filip Tehlar694396d2017-02-17 14:29:11 +0100387
388 /* XXX treat batch configuration */
389 a->is_add = mp->is_add;
390 gid_address_copy (&a->eid, eid);
391 a->locator_set_index = locator_set_index;
392 a->local = 1;
393 a->key = key;
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100394 a->key_id = mp->key.id;
Filip Tehlar694396d2017-02-17 14:29:11 +0100395
396 rv = vnet_lisp_add_del_local_mapping (a, &map_index);
397
398out:
399 vec_free (name);
400 vec_free (key);
401 gid_address_free (&a->eid);
402
403 REPLY_MACRO (VL_API_ONE_ADD_DEL_LOCAL_EID_REPLY);
404}
405
406static void
407 vl_api_one_eid_table_add_del_map_t_handler
408 (vl_api_one_eid_table_add_del_map_t * mp)
409{
410 vl_api_one_eid_table_add_del_map_reply_t *rmp;
411 int rv = 0;
412 rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni),
413 clib_net_to_host_u32 (mp->dp_table),
414 mp->is_l2, mp->is_add);
415REPLY_MACRO (VL_API_ONE_EID_TABLE_ADD_DEL_MAP_REPLY)}
416
417static void
418vl_api_one_add_del_map_server_t_handler (vl_api_one_add_del_map_server_t * mp)
419{
420 vl_api_one_add_del_map_server_reply_t *rmp;
421 int rv = 0;
422 ip_address_t addr;
423
Dave Barachb7b92992018-10-17 10:38:51 -0400424 clib_memset (&addr, 0, sizeof (addr));
Filip Tehlar694396d2017-02-17 14:29:11 +0100425
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100426 ip_address_decode2 (&mp->ip_address, &addr);
427
Filip Tehlar694396d2017-02-17 14:29:11 +0100428 rv = vnet_lisp_add_del_map_server (&addr, mp->is_add);
429
430 REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_SERVER_REPLY);
431}
432
433static void
434vl_api_one_add_del_map_resolver_t_handler (vl_api_one_add_del_map_resolver_t
435 * mp)
436{
437 vl_api_one_add_del_map_resolver_reply_t *rmp;
438 int rv = 0;
439 vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
440
Dave Barachb7b92992018-10-17 10:38:51 -0400441 clib_memset (a, 0, sizeof (a[0]));
Filip Tehlar694396d2017-02-17 14:29:11 +0100442
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100443 ip_address_decode2 (&mp->ip_address, &a->address);
444
Filip Tehlar694396d2017-02-17 14:29:11 +0100445 a->is_add = mp->is_add;
Filip Tehlar694396d2017-02-17 14:29:11 +0100446
447 rv = vnet_lisp_add_del_map_resolver (a);
448
449 REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_RESOLVER_REPLY);
450}
451
452static void
453 vl_api_one_map_register_enable_disable_t_handler
454 (vl_api_one_map_register_enable_disable_t * mp)
455{
456 vl_api_one_map_register_enable_disable_reply_t *rmp;
457 int rv = 0;
458
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100459 vnet_lisp_map_register_enable_disable (mp->is_enable);
Filip Tehlar694396d2017-02-17 14:29:11 +0100460 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
461}
462
463static void
464 vl_api_one_rloc_probe_enable_disable_t_handler
465 (vl_api_one_rloc_probe_enable_disable_t * mp)
466{
467 vl_api_one_rloc_probe_enable_disable_reply_t *rmp;
468 int rv = 0;
469
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100470 vnet_lisp_rloc_probe_enable_disable (mp->is_enable);
Filip Tehlar694396d2017-02-17 14:29:11 +0100471 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
472}
473
474static void
475vl_api_one_enable_disable_t_handler (vl_api_one_enable_disable_t * mp)
476{
477 vl_api_one_enable_disable_reply_t *rmp;
478 int rv = 0;
479
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100480 vnet_lisp_enable_disable (mp->is_enable);
Filip Tehlar694396d2017-02-17 14:29:11 +0100481 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
482}
483
484static void
485 vl_api_show_one_map_request_mode_t_handler
486 (vl_api_show_one_map_request_mode_t * mp)
487{
488 int rv = 0;
489 vl_api_show_one_map_request_mode_reply_t *rmp;
490
491 /* *INDENT-OFF* */
492 REPLY_MACRO2(VL_API_SHOW_ONE_MAP_REQUEST_MODE_REPLY,
493 ({
494 rmp->mode = vnet_lisp_get_map_request_mode ();
495 }));
496 /* *INDENT-ON* */
497}
498
499static void
500vl_api_one_map_request_mode_t_handler (vl_api_one_map_request_mode_t * mp)
501{
502 vl_api_one_map_request_mode_reply_t *rmp;
503 int rv = 0;
504
505 rv = vnet_lisp_set_map_request_mode (mp->mode);
506
507 REPLY_MACRO (VL_API_ONE_MAP_REQUEST_MODE_REPLY);
508}
509
510static void
Filip Tehlaref2a5bf2017-05-30 07:14:46 +0200511vl_api_one_nsh_set_locator_set_t_handler (vl_api_one_nsh_set_locator_set_t
512 * mp)
513{
514 vl_api_one_nsh_set_locator_set_reply_t *rmp;
515 int rv = 0;
516 u8 *ls_name = 0;
517
Filip Tehlar9d286a42017-10-26 23:57:09 -0700518 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
Filip Tehlaref2a5bf2017-05-30 07:14:46 +0200519 ls_name = format (0, "%s", mp->ls_name);
Gabriel Ganne3491d7f2017-10-19 15:10:46 +0200520 vec_terminate_c_string (ls_name);
Filip Tehlaref2a5bf2017-05-30 07:14:46 +0200521 rv = vnet_lisp_nsh_set_locator_set (ls_name, mp->is_add);
522 vec_free (ls_name);
523
524 REPLY_MACRO (VL_API_ONE_PITR_SET_LOCATOR_SET_REPLY);
525}
526
527static void
Filip Tehlar694396d2017-02-17 14:29:11 +0100528vl_api_one_pitr_set_locator_set_t_handler (vl_api_one_pitr_set_locator_set_t
529 * mp)
530{
531 vl_api_one_pitr_set_locator_set_reply_t *rmp;
532 int rv = 0;
533 u8 *ls_name = 0;
534
Filip Tehlar9d286a42017-10-26 23:57:09 -0700535 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
Filip Tehlar694396d2017-02-17 14:29:11 +0100536 ls_name = format (0, "%s", mp->ls_name);
Gabriel Ganne3491d7f2017-10-19 15:10:46 +0200537 vec_terminate_c_string (ls_name);
Filip Tehlar694396d2017-02-17 14:29:11 +0100538 rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add);
539 vec_free (ls_name);
540
541 REPLY_MACRO (VL_API_ONE_PITR_SET_LOCATOR_SET_REPLY);
542}
543
544static void
545vl_api_one_use_petr_t_handler (vl_api_one_use_petr_t * mp)
546{
547 vl_api_one_use_petr_reply_t *rmp;
548 int rv = 0;
549 ip_address_t addr;
550
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100551 ip_address_decode2 (&mp->ip_address, &addr);
552
Filip Tehlar694396d2017-02-17 14:29:11 +0100553 rv = vnet_lisp_use_petr (&addr, mp->is_add);
554
555 REPLY_MACRO (VL_API_ONE_USE_PETR_REPLY);
556}
557
558static void
559vl_api_show_one_use_petr_t_handler (vl_api_show_one_use_petr_t * mp)
560{
Filip Tehlar694396d2017-02-17 14:29:11 +0100561 vl_api_show_one_use_petr_reply_t *rmp = NULL;
562 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
563 mapping_t *m;
564 locator_set_t *ls = 0;
565 int rv = 0;
566 locator_t *loc = 0;
567 u8 status = 0;
568 gid_address_t addr;
569
Dave Barachb7b92992018-10-17 10:38:51 -0400570 clib_memset (&addr, 0, sizeof (addr));
Filip Tehlar694396d2017-02-17 14:29:11 +0100571 status = lcm->flags & LISP_FLAG_USE_PETR;
572 if (status)
573 {
574 m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index);
575 if (~0 != m->locator_set_index)
576 {
577 ls =
578 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
579 loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]);
580 gid_address_copy (&addr, &loc->address);
581 }
582 }
583
584 /* *INDENT-OFF* */
585 REPLY_MACRO2 (VL_API_SHOW_ONE_USE_PETR_REPLY,
586 {
Filip Tehlar67a99f82017-03-10 13:18:02 +0100587 rmp->status = status;
588 ip_address_t *ip = &gid_address_ip (&addr);
Filip Tehlar67a99f82017-03-10 13:18:02 +0100589
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100590 ip_address_encode2 (ip, &rmp->ip_address);
Filip Tehlar694396d2017-02-17 14:29:11 +0100591 });
592 /* *INDENT-ON* */
593}
594
595static void
596 vl_api_one_add_del_map_request_itr_rlocs_t_handler
597 (vl_api_one_add_del_map_request_itr_rlocs_t * mp)
598{
599 vl_api_one_add_del_map_request_itr_rlocs_reply_t *rmp;
600 int rv = 0;
601 u8 *locator_set_name = NULL;
602 vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
603
Filip Tehlar9d286a42017-10-26 23:57:09 -0700604 mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0;
Filip Tehlar694396d2017-02-17 14:29:11 +0100605 locator_set_name = format (0, "%s", mp->locator_set_name);
Gabriel Ganne3491d7f2017-10-19 15:10:46 +0200606 vec_terminate_c_string (locator_set_name);
Filip Tehlar694396d2017-02-17 14:29:11 +0100607
608 a->is_add = mp->is_add;
609 a->locator_set_name = locator_set_name;
610
611 rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
612
613 vec_free (locator_set_name);
614
615 REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY);
616}
617
618static void
619 vl_api_one_add_del_remote_mapping_t_handler
620 (vl_api_one_add_del_remote_mapping_t * mp)
621{
622 locator_t *rlocs = 0;
623 vl_api_one_add_del_remote_mapping_reply_t *rmp;
624 int rv = 0;
625 gid_address_t _eid, *eid = &_eid;
626 u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num);
627
Dave Barachb7b92992018-10-17 10:38:51 -0400628 clib_memset (eid, 0, sizeof (eid[0]));
Filip Tehlar694396d2017-02-17 14:29:11 +0100629
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100630 rv = unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni), &mp->deid);
Filip Tehlar694396d2017-02-17 14:29:11 +0100631 if (rv)
632 goto send_reply;
633
634 rlocs = unformat_one_locs (mp->rlocs, rloc_num);
635
636 if (!mp->is_add)
637 {
638 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
Dave Barachb7b92992018-10-17 10:38:51 -0400639 clib_memset (a, 0, sizeof (a[0]));
Filip Tehlar694396d2017-02-17 14:29:11 +0100640 gid_address_copy (&a->reid, eid);
641 a->is_add = 0;
642 rv = vnet_lisp_add_del_adjacency (a);
643 if (rv)
644 {
645 goto out;
646 }
647 }
648
649 /* NOTE: for now this works as a static remote mapping, i.e.,
650 * not authoritative and ttl infinite. */
Filip Tehlar809bc742017-08-14 19:15:36 +0200651 if (mp->is_add)
652 {
653 vnet_lisp_add_del_mapping_args_t _m_args, *m_args = &_m_args;
Dave Barachb7b92992018-10-17 10:38:51 -0400654 clib_memset (m_args, 0, sizeof (m_args[0]));
Filip Tehlar809bc742017-08-14 19:15:36 +0200655 gid_address_copy (&m_args->eid, eid);
656 m_args->action = mp->action;
657 m_args->is_static = 1;
658 m_args->ttl = ~0;
659 m_args->authoritative = 0;
660 rv = vnet_lisp_add_mapping (m_args, rlocs, NULL, NULL);
661 }
662 else
663 rv = vnet_lisp_del_mapping (eid, NULL);
Filip Tehlar694396d2017-02-17 14:29:11 +0100664
665 if (mp->del_all)
666 vnet_lisp_clear_all_remote_adjacencies ();
667
668out:
669 vec_free (rlocs);
670send_reply:
671 REPLY_MACRO (VL_API_ONE_ADD_DEL_REMOTE_MAPPING_REPLY);
672}
673
674static void
675vl_api_one_add_del_adjacency_t_handler (vl_api_one_add_del_adjacency_t * mp)
676{
677 vl_api_one_add_del_adjacency_reply_t *rmp;
678 vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
679
680 int rv = 0;
Dave Barachb7b92992018-10-17 10:38:51 -0400681 clib_memset (a, 0, sizeof (a[0]));
Filip Tehlar694396d2017-02-17 14:29:11 +0100682
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100683 rv =
684 unformat_one_eid_api (&a->leid, clib_net_to_host_u32 (mp->vni),
685 &mp->leid);
686 rv |=
687 unformat_one_eid_api (&a->reid, clib_net_to_host_u32 (mp->vni),
688 &mp->reid);
Filip Tehlar694396d2017-02-17 14:29:11 +0100689
690 if (rv)
691 goto send_reply;
692
693 a->is_add = mp->is_add;
694 rv = vnet_lisp_add_del_adjacency (a);
695
696send_reply:
697 REPLY_MACRO (VL_API_ONE_ADD_DEL_ADJACENCY_REPLY);
698}
699
700static void
701send_one_locator_details (lisp_cp_main_t * lcm,
Florin Coras6c4dae22018-01-09 06:39:23 -0800702 locator_t * loc, vl_api_registration_t * reg,
703 u32 context)
Filip Tehlar694396d2017-02-17 14:29:11 +0100704{
705 vl_api_one_locator_details_t *rmp;
706
707 rmp = vl_msg_api_alloc (sizeof (*rmp));
Dave Barachb7b92992018-10-17 10:38:51 -0400708 clib_memset (rmp, 0, sizeof (*rmp));
Filip Tehlar694396d2017-02-17 14:29:11 +0100709 rmp->_vl_msg_id = ntohs (VL_API_ONE_LOCATOR_DETAILS);
710 rmp->context = context;
711
712 rmp->local = loc->local;
713 if (loc->local)
714 {
715 rmp->sw_if_index = ntohl (loc->sw_if_index);
716 }
717 else
718 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100719 ip_address_encode2 (&loc->address.ippref.addr, &rmp->ip_address);
Filip Tehlar694396d2017-02-17 14:29:11 +0100720 }
721 rmp->priority = loc->priority;
722 rmp->weight = loc->weight;
723
Florin Coras6c4dae22018-01-09 06:39:23 -0800724 vl_api_send_msg (reg, (u8 *) rmp);
Filip Tehlar694396d2017-02-17 14:29:11 +0100725}
726
727static void
728vl_api_one_locator_dump_t_handler (vl_api_one_locator_dump_t * mp)
729{
730 u8 *ls_name = 0;
Florin Coras6c4dae22018-01-09 06:39:23 -0800731 vl_api_registration_t *reg;
Filip Tehlar694396d2017-02-17 14:29:11 +0100732 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
733 locator_set_t *lsit = 0;
734 locator_t *loc = 0;
735 u32 ls_index = ~0, *locit = 0;
736 uword *p = 0;
737
Florin Coras6c4dae22018-01-09 06:39:23 -0800738 reg = vl_api_client_index_to_registration (mp->client_index);
739 if (!reg)
740 return;
Filip Tehlar694396d2017-02-17 14:29:11 +0100741
742 if (mp->is_index_set)
743 ls_index = htonl (mp->ls_index);
744 else
745 {
746 /* make sure we get a proper C-string */
747 mp->ls_name[sizeof (mp->ls_name) - 1] = 0;
748 ls_name = format (0, "%s", mp->ls_name);
Gabriel Ganne3491d7f2017-10-19 15:10:46 +0200749 vec_terminate_c_string (ls_name);
Filip Tehlar694396d2017-02-17 14:29:11 +0100750 p = hash_get_mem (lcm->locator_set_index_by_name, ls_name);
751 if (!p)
752 goto out;
753 ls_index = p[0];
754 }
755
756 if (pool_is_free_index (lcm->locator_set_pool, ls_index))
757 return;
758
759 lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index);
760
761 vec_foreach (locit, lsit->locator_indices)
762 {
763 loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
Florin Coras6c4dae22018-01-09 06:39:23 -0800764 send_one_locator_details (lcm, loc, reg, mp->context);
Filip Tehlar694396d2017-02-17 14:29:11 +0100765 };
766out:
767 vec_free (ls_name);
768}
769
770static void
771send_one_locator_set_details (lisp_cp_main_t * lcm,
772 locator_set_t * lsit,
Florin Coras6c4dae22018-01-09 06:39:23 -0800773 vl_api_registration_t * reg, u32 context,
774 u32 ls_index)
Filip Tehlar694396d2017-02-17 14:29:11 +0100775{
776 vl_api_one_locator_set_details_t *rmp;
777 u8 *str = 0;
778
779 rmp = vl_msg_api_alloc (sizeof (*rmp));
Dave Barachb7b92992018-10-17 10:38:51 -0400780 clib_memset (rmp, 0, sizeof (*rmp));
Filip Tehlar694396d2017-02-17 14:29:11 +0100781 rmp->_vl_msg_id = ntohs (VL_API_ONE_LOCATOR_SET_DETAILS);
782 rmp->context = context;
783
784 rmp->ls_index = htonl (ls_index);
785 if (lsit->local)
786 {
787 ASSERT (lsit->name != NULL);
788 strncpy ((char *) rmp->ls_name, (char *) lsit->name,
789 vec_len (lsit->name));
790 }
791 else
792 {
793 str = format (0, "<remote-%d>", ls_index);
794 strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str));
795 vec_free (str);
796 }
797
Florin Coras6c4dae22018-01-09 06:39:23 -0800798 vl_api_send_msg (reg, (u8 *) rmp);
Filip Tehlar694396d2017-02-17 14:29:11 +0100799}
800
801static void
802vl_api_one_locator_set_dump_t_handler (vl_api_one_locator_set_dump_t * mp)
803{
Florin Coras6c4dae22018-01-09 06:39:23 -0800804 vl_api_registration_t *reg;
Filip Tehlar694396d2017-02-17 14:29:11 +0100805 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
806 locator_set_t *lsit = NULL;
807 u8 filter;
808
Florin Coras6c4dae22018-01-09 06:39:23 -0800809 reg = vl_api_client_index_to_registration (mp->client_index);
810 if (!reg)
811 return;
Filip Tehlar694396d2017-02-17 14:29:11 +0100812
813 filter = mp->filter;
814 /* *INDENT-OFF* */
815 pool_foreach (lsit, lcm->locator_set_pool,
816 ({
817 if (filter && !((1 == filter && lsit->local) ||
818 (2 == filter && !lsit->local)))
819 {
820 continue;
821 }
Florin Coras6c4dae22018-01-09 06:39:23 -0800822 send_one_locator_set_details (lcm, lsit, reg, mp->context,
Filip Tehlar694396d2017-02-17 14:29:11 +0100823 lsit - lcm->locator_set_pool);
824 }));
825 /* *INDENT-ON* */
826}
827
828static void
Filip Tehlar694396d2017-02-17 14:29:11 +0100829send_one_eid_table_details (mapping_t * mapit,
Florin Coras6c4dae22018-01-09 06:39:23 -0800830 vl_api_registration_t * reg, u32 context,
831 u8 filter)
Filip Tehlar694396d2017-02-17 14:29:11 +0100832{
Filip Tehlar694396d2017-02-17 14:29:11 +0100833 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
834 locator_set_t *ls = 0;
835 vl_api_one_eid_table_details_t *rmp = NULL;
836 gid_address_t *gid = NULL;
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100837 u32 eid_type;
838 fib_prefix_t fib_prefix;
Filip Tehlar694396d2017-02-17 14:29:11 +0100839
Filip Tehlaref2a5bf2017-05-30 07:14:46 +0200840 if (mapit->pitr_set || mapit->nsh_set)
Filip Tehlar1e8d01f2017-03-30 15:17:01 +0200841 return;
842
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100843 switch (ntohl (filter))
Filip Tehlar694396d2017-02-17 14:29:11 +0100844 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100845 case ONE_FILTER_API_ALL: /* all mappings */
Filip Tehlar694396d2017-02-17 14:29:11 +0100846 break;
847
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100848 case ONE_FILTER_API_LOCAL: /* local only */
Filip Tehlar694396d2017-02-17 14:29:11 +0100849 if (!mapit->local)
850 return;
851 break;
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100852 case ONE_FILTER_API_REMOTE: /* remote only */
Filip Tehlar694396d2017-02-17 14:29:11 +0100853 if (mapit->local)
854 return;
855 break;
856 default:
857 clib_warning ("Filter error, unknown filter: %d", filter);
858 return;
859 }
860
861 gid = &mapit->eid;
Filip Tehlar694396d2017-02-17 14:29:11 +0100862
863 rmp = vl_msg_api_alloc (sizeof (*rmp));
Dave Barachb7b92992018-10-17 10:38:51 -0400864 clib_memset (rmp, 0, sizeof (*rmp));
Filip Tehlar694396d2017-02-17 14:29:11 +0100865 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_DETAILS);
866
867 ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index);
868 if (vec_len (ls->locator_indices) == 0)
869 rmp->locator_set_index = ~0;
870 else
871 rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index);
872
873 rmp->is_local = mapit->local;
874 rmp->ttl = clib_host_to_net_u32 (mapit->ttl);
875 rmp->action = mapit->action;
876 rmp->authoritative = mapit->authoritative;
877
878 switch (gid_address_type (gid))
879 {
880 case GID_ADDR_SRC_DST:
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100881 fid_to_api_eid (&gid_address_sd_src (gid), &rmp->seid);
882 fid_to_api_eid (&gid_address_sd_dst (gid), &rmp->deid);
Filip Tehlar694396d2017-02-17 14:29:11 +0100883 break;
884 case GID_ADDR_IP_PREFIX:
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100885 eid_type = EID_TYPE_API_PREFIX;
886 rmp->seid.type = eid_type;
887 ip_prefix_to_fib_prefix (&gid_address_ippref (gid), &fib_prefix);
888 ip_prefix_encode (&fib_prefix, &rmp->seid.address.prefix);
Filip Tehlar694396d2017-02-17 14:29:11 +0100889 break;
890 case GID_ADDR_MAC:
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100891 eid_type = EID_TYPE_API_MAC;
892 rmp->seid.type = eid_type;
893 mac_address_encode ((mac_address_t *) gid_address_mac (gid),
894 rmp->seid.address.mac);
Filip Tehlar694396d2017-02-17 14:29:11 +0100895 break;
Filip Tehlaref2a5bf2017-05-30 07:14:46 +0200896 case GID_ADDR_NSH:
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100897 eid_type = EID_TYPE_API_NSH;
898 rmp->seid.type = eid_type;
899 rmp->seid.address.nsh.spi =
900 clib_host_to_net_u32 (gid_address_nsh_spi (gid));
901 rmp->seid.address.nsh.si = gid_address_nsh_si (gid);
Filip Tehlaref2a5bf2017-05-30 07:14:46 +0200902 break;
Filip Tehlar694396d2017-02-17 14:29:11 +0100903 default:
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100904 /* unknown type */
905 return;
Filip Tehlar694396d2017-02-17 14:29:11 +0100906 }
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100907
Filip Tehlar694396d2017-02-17 14:29:11 +0100908 rmp->context = context;
909 rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid));
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100910 rmp->key.id = mapit->key_id;
911 memcpy (rmp->key.key, mapit->key, vec_len (mapit->key));
Florin Coras6c4dae22018-01-09 06:39:23 -0800912 vl_api_send_msg (reg, (u8 *) rmp);
Filip Tehlar694396d2017-02-17 14:29:11 +0100913}
914
915static void
916vl_api_one_eid_table_dump_t_handler (vl_api_one_eid_table_dump_t * mp)
917{
918 u32 mi;
Florin Coras6c4dae22018-01-09 06:39:23 -0800919 vl_api_registration_t *reg;
Filip Tehlar694396d2017-02-17 14:29:11 +0100920 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
921 mapping_t *mapit = NULL;
922 gid_address_t _eid, *eid = &_eid;
923
Florin Coras6c4dae22018-01-09 06:39:23 -0800924 reg = vl_api_client_index_to_registration (mp->client_index);
925 if (!reg)
926 return;
Filip Tehlar694396d2017-02-17 14:29:11 +0100927
928 if (mp->eid_set)
929 {
Dave Barachb7b92992018-10-17 10:38:51 -0400930 clib_memset (eid, 0, sizeof (*eid));
Filip Tehlar694396d2017-02-17 14:29:11 +0100931
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100932 unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni), &mp->eid);
Filip Tehlar694396d2017-02-17 14:29:11 +0100933
934 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid);
935 if ((u32) ~ 0 == mi)
936 return;
937
938 mapit = pool_elt_at_index (lcm->mapping_pool, mi);
Florin Coras6c4dae22018-01-09 06:39:23 -0800939 send_one_eid_table_details (mapit, reg, mp->context,
Filip Tehlar694396d2017-02-17 14:29:11 +0100940 0 /* ignore filter */ );
941 }
942 else
943 {
944 /* *INDENT-OFF* */
945 pool_foreach (mapit, lcm->mapping_pool,
946 ({
Florin Coras6c4dae22018-01-09 06:39:23 -0800947 send_one_eid_table_details(mapit, reg, mp->context,
Filip Tehlar694396d2017-02-17 14:29:11 +0100948 mp->filter);
949 }));
950 /* *INDENT-ON* */
951 }
952}
953
954static void
Florin Coras6c4dae22018-01-09 06:39:23 -0800955send_one_map_server_details (ip_address_t * ip, vl_api_registration_t * reg,
956 u32 context)
Filip Tehlar694396d2017-02-17 14:29:11 +0100957{
958 vl_api_one_map_server_details_t *rmp = NULL;
959
960 rmp = vl_msg_api_alloc (sizeof (*rmp));
Dave Barachb7b92992018-10-17 10:38:51 -0400961 clib_memset (rmp, 0, sizeof (*rmp));
Filip Tehlar694396d2017-02-17 14:29:11 +0100962 rmp->_vl_msg_id = ntohs (VL_API_ONE_MAP_SERVER_DETAILS);
963
Filip Tehlar694396d2017-02-17 14:29:11 +0100964
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100965 ip_address_encode2 (ip, &rmp->ip_address);
Filip Tehlar694396d2017-02-17 14:29:11 +0100966
Filip Tehlar694396d2017-02-17 14:29:11 +0100967 rmp->context = context;
968
Florin Coras6c4dae22018-01-09 06:39:23 -0800969 vl_api_send_msg (reg, (u8 *) rmp);
Filip Tehlar694396d2017-02-17 14:29:11 +0100970}
971
972static void
973vl_api_one_map_server_dump_t_handler (vl_api_one_map_server_dump_t * mp)
974{
Florin Coras6c4dae22018-01-09 06:39:23 -0800975 vl_api_registration_t *reg;
Filip Tehlar694396d2017-02-17 14:29:11 +0100976 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
977 lisp_msmr_t *mr;
978
Florin Coras6c4dae22018-01-09 06:39:23 -0800979 reg = vl_api_client_index_to_registration (mp->client_index);
980 if (!reg)
981 return;
Filip Tehlar694396d2017-02-17 14:29:11 +0100982
983 vec_foreach (mr, lcm->map_servers)
984 {
Florin Coras6c4dae22018-01-09 06:39:23 -0800985 send_one_map_server_details (&mr->address, reg, mp->context);
Filip Tehlar694396d2017-02-17 14:29:11 +0100986 }
987}
988
989static void
990send_one_map_resolver_details (ip_address_t * ip,
Florin Coras6c4dae22018-01-09 06:39:23 -0800991 vl_api_registration_t * reg, u32 context)
Filip Tehlar694396d2017-02-17 14:29:11 +0100992{
993 vl_api_one_map_resolver_details_t *rmp = NULL;
994
995 rmp = vl_msg_api_alloc (sizeof (*rmp));
Dave Barachb7b92992018-10-17 10:38:51 -0400996 clib_memset (rmp, 0, sizeof (*rmp));
Filip Tehlar694396d2017-02-17 14:29:11 +0100997 rmp->_vl_msg_id = ntohs (VL_API_ONE_MAP_RESOLVER_DETAILS);
998
Jakub Grajciar58db6e12020-01-30 13:26:43 +0100999 ip_address_encode2 (ip, &rmp->ip_address);
Filip Tehlar694396d2017-02-17 14:29:11 +01001000 rmp->context = context;
1001
Florin Coras6c4dae22018-01-09 06:39:23 -08001002 vl_api_send_msg (reg, (u8 *) rmp);
Filip Tehlar694396d2017-02-17 14:29:11 +01001003}
1004
1005static void
1006vl_api_one_map_resolver_dump_t_handler (vl_api_one_map_resolver_dump_t * mp)
1007{
Florin Coras6c4dae22018-01-09 06:39:23 -08001008 vl_api_registration_t *reg;
Filip Tehlar694396d2017-02-17 14:29:11 +01001009 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1010 lisp_msmr_t *mr;
1011
Florin Coras6c4dae22018-01-09 06:39:23 -08001012 reg = vl_api_client_index_to_registration (mp->client_index);
1013 if (!reg)
1014 return;
Filip Tehlar694396d2017-02-17 14:29:11 +01001015
1016 vec_foreach (mr, lcm->map_resolvers)
1017 {
Florin Coras6c4dae22018-01-09 06:39:23 -08001018 send_one_map_resolver_details (&mr->address, reg, mp->context);
Filip Tehlar694396d2017-02-17 14:29:11 +01001019 }
1020}
1021
1022static void
Florin Coras6c4dae22018-01-09 06:39:23 -08001023send_eid_table_map_pair (hash_pair_t * p, vl_api_registration_t * reg,
1024 u32 context)
Filip Tehlar694396d2017-02-17 14:29:11 +01001025{
1026 vl_api_one_eid_table_map_details_t *rmp = NULL;
1027
1028 rmp = vl_msg_api_alloc (sizeof (*rmp));
Dave Barachb7b92992018-10-17 10:38:51 -04001029 clib_memset (rmp, 0, sizeof (*rmp));
Filip Tehlar694396d2017-02-17 14:29:11 +01001030 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_MAP_DETAILS);
1031
1032 rmp->vni = clib_host_to_net_u32 (p->key);
1033 rmp->dp_table = clib_host_to_net_u32 (p->value[0]);
1034 rmp->context = context;
Florin Coras6c4dae22018-01-09 06:39:23 -08001035 vl_api_send_msg (reg, (u8 *) rmp);
Filip Tehlar694396d2017-02-17 14:29:11 +01001036}
1037
1038static void
1039vl_api_one_eid_table_map_dump_t_handler (vl_api_one_eid_table_map_dump_t * mp)
1040{
Florin Coras6c4dae22018-01-09 06:39:23 -08001041 vl_api_registration_t *reg;
Filip Tehlar694396d2017-02-17 14:29:11 +01001042 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1043 hash_pair_t *p;
1044 uword *vni_table = 0;
1045
Florin Coras6c4dae22018-01-09 06:39:23 -08001046 reg = vl_api_client_index_to_registration (mp->client_index);
1047 if (!reg)
1048 return;
Filip Tehlar694396d2017-02-17 14:29:11 +01001049
1050 if (mp->is_l2)
1051 {
1052 vni_table = lcm->bd_id_by_vni;
1053 }
1054 else
1055 {
1056 vni_table = lcm->table_id_by_vni;
1057 }
1058
1059 /* *INDENT-OFF* */
1060 hash_foreach_pair (p, vni_table,
1061 ({
Florin Coras6c4dae22018-01-09 06:39:23 -08001062 send_eid_table_map_pair (p, reg, mp->context);
Filip Tehlar694396d2017-02-17 14:29:11 +01001063 }));
1064 /* *INDENT-ON* */
1065}
1066
1067static void
Florin Coras6c4dae22018-01-09 06:39:23 -08001068send_eid_table_vni (u32 vni, vl_api_registration_t * reg, u32 context)
Filip Tehlar694396d2017-02-17 14:29:11 +01001069{
1070 vl_api_one_eid_table_vni_details_t *rmp = 0;
1071
1072 rmp = vl_msg_api_alloc (sizeof (*rmp));
Dave Barachb7b92992018-10-17 10:38:51 -04001073 clib_memset (rmp, 0, sizeof (*rmp));
Filip Tehlar694396d2017-02-17 14:29:11 +01001074 rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_VNI_DETAILS);
1075 rmp->context = context;
1076 rmp->vni = clib_host_to_net_u32 (vni);
Florin Coras6c4dae22018-01-09 06:39:23 -08001077 vl_api_send_msg (reg, (u8 *) rmp);
Filip Tehlar694396d2017-02-17 14:29:11 +01001078}
1079
1080static void
1081one_adjacency_copy (vl_api_one_adjacency_t * dst, lisp_adjacency_t * adjs)
1082{
1083 lisp_adjacency_t *adj;
1084 vl_api_one_adjacency_t a;
1085 u32 i, n = vec_len (adjs);
Jakub Grajciar58db6e12020-01-30 13:26:43 +01001086 fib_prefix_t rfib_prefix, lfib_prefix;
1087 u32 eid_type;
Filip Tehlar694396d2017-02-17 14:29:11 +01001088
1089 for (i = 0; i < n; i++)
1090 {
1091 adj = vec_elt_at_index (adjs, i);
Dave Barachb7b92992018-10-17 10:38:51 -04001092 clib_memset (&a, 0, sizeof (a));
Filip Tehlar694396d2017-02-17 14:29:11 +01001093
1094 switch (gid_address_type (&adj->reid))
1095 {
1096 case GID_ADDR_IP_PREFIX:
Jakub Grajciar58db6e12020-01-30 13:26:43 +01001097 eid_type = EID_TYPE_API_PREFIX;
1098 ip_prefix_to_fib_prefix (&gid_address_ippref (&adj->reid),
1099 &rfib_prefix);
1100 ip_prefix_to_fib_prefix (&gid_address_ippref (&adj->leid),
1101 &lfib_prefix);
1102 ip_prefix_encode (&rfib_prefix, &a.reid.address.prefix);
1103 ip_prefix_encode (&lfib_prefix, &a.leid.address.prefix);
Filip Tehlar694396d2017-02-17 14:29:11 +01001104 break;
1105 case GID_ADDR_MAC:
Jakub Grajciar58db6e12020-01-30 13:26:43 +01001106 eid_type = EID_TYPE_API_PREFIX;
1107 mac_address_encode ((mac_address_t *) gid_address_mac (&adj->reid),
1108 a.reid.address.mac);
1109 mac_address_encode ((mac_address_t *) gid_address_mac (&adj->leid),
1110 a.leid.address.mac);
Filip Tehlar694396d2017-02-17 14:29:11 +01001111 break;
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02001112 case GID_ADDR_NSH:
Jakub Grajciar58db6e12020-01-30 13:26:43 +01001113 eid_type = EID_TYPE_API_PREFIX;
1114 a.reid.address.nsh.spi =
1115 clib_host_to_net_u32 (gid_address_nsh_spi (&adj->reid));
1116 a.reid.address.nsh.si = gid_address_nsh_si (&adj->reid);
1117 a.leid.address.nsh.spi =
1118 clib_host_to_net_u32 (gid_address_nsh_spi (&adj->leid));
1119 a.leid.address.nsh.si = gid_address_nsh_si (&adj->leid);
Filip Tehlarb8633d22017-06-09 15:25:57 +02001120 break;
Filip Tehlar694396d2017-02-17 14:29:11 +01001121 default:
Dave Barachc72950e2020-05-04 14:47:45 -04001122 ALWAYS_ASSERT (0);
Filip Tehlar694396d2017-02-17 14:29:11 +01001123 }
Jakub Grajciar58db6e12020-01-30 13:26:43 +01001124 a.reid.type = eid_type;
1125 a.leid.type = eid_type;
Filip Tehlar694396d2017-02-17 14:29:11 +01001126 dst[i] = a;
1127 }
1128}
1129
1130static void
1131 vl_api_show_one_rloc_probe_state_t_handler
1132 (vl_api_show_one_rloc_probe_state_t * mp)
1133{
1134 vl_api_show_one_rloc_probe_state_reply_t *rmp = 0;
1135 int rv = 0;
1136
1137 /* *INDENT-OFF* */
1138 REPLY_MACRO2 (VL_API_SHOW_ONE_RLOC_PROBE_STATE_REPLY,
1139 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +01001140 rmp->is_enable = vnet_lisp_rloc_probe_state_get ();
Filip Tehlar694396d2017-02-17 14:29:11 +01001141 });
1142 /* *INDENT-ON* */
1143}
1144
1145static void
1146 vl_api_show_one_map_register_state_t_handler
1147 (vl_api_show_one_map_register_state_t * mp)
1148{
1149 vl_api_show_one_map_register_state_reply_t *rmp = 0;
1150 int rv = 0;
1151
1152 /* *INDENT-OFF* */
1153 REPLY_MACRO2 (VL_API_SHOW_ONE_MAP_REGISTER_STATE_REPLY,
1154 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +01001155 rmp->is_enable = vnet_lisp_map_register_state_get ();
Filip Tehlar694396d2017-02-17 14:29:11 +01001156 });
1157 /* *INDENT-ON* */
1158}
1159
1160static void
1161vl_api_one_adjacencies_get_t_handler (vl_api_one_adjacencies_get_t * mp)
1162{
1163 vl_api_one_adjacencies_get_reply_t *rmp = 0;
1164 lisp_adjacency_t *adjs = 0;
1165 int rv = 0;
1166 u32 size = ~0;
1167 u32 vni = clib_net_to_host_u32 (mp->vni);
1168
1169 adjs = vnet_lisp_adjacencies_get_by_vni (vni);
1170 size = vec_len (adjs) * sizeof (vl_api_one_adjacency_t);
1171
1172 /* *INDENT-OFF* */
1173 REPLY_MACRO4 (VL_API_ONE_ADJACENCIES_GET_REPLY, size,
1174 {
1175 rmp->count = clib_host_to_net_u32 (vec_len (adjs));
1176 one_adjacency_copy (rmp->adjacencies, adjs);
1177 });
1178 /* *INDENT-ON* */
1179
1180 vec_free (adjs);
1181}
1182
1183static void
1184vl_api_one_eid_table_vni_dump_t_handler (vl_api_one_eid_table_vni_dump_t * mp)
1185{
1186 hash_pair_t *p;
1187 u32 *vnis = 0;
Florin Coras6c4dae22018-01-09 06:39:23 -08001188 vl_api_registration_t *reg;
Filip Tehlar694396d2017-02-17 14:29:11 +01001189 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1190
Florin Coras6c4dae22018-01-09 06:39:23 -08001191 reg = vl_api_client_index_to_registration (mp->client_index);
1192 if (!reg)
1193 return;
Filip Tehlar694396d2017-02-17 14:29:11 +01001194
1195 /* *INDENT-OFF* */
1196 hash_foreach_pair (p, lcm->table_id_by_vni,
1197 ({
1198 hash_set (vnis, p->key, 0);
1199 }));
1200
1201 hash_foreach_pair (p, lcm->bd_id_by_vni,
1202 ({
1203 hash_set (vnis, p->key, 0);
1204 }));
1205
1206 hash_foreach_pair (p, vnis,
1207 ({
Florin Coras6c4dae22018-01-09 06:39:23 -08001208 send_eid_table_vni (p->key, reg, mp->context);
Filip Tehlar694396d2017-02-17 14:29:11 +01001209 }));
1210 /* *INDENT-ON* */
1211
1212 hash_free (vnis);
1213}
1214
1215static void
1216vl_api_show_one_status_t_handler (vl_api_show_one_status_t * mp)
1217{
Filip Tehlar694396d2017-02-17 14:29:11 +01001218 vl_api_show_one_status_reply_t *rmp = NULL;
1219 int rv = 0;
1220
Filip Tehlar694396d2017-02-17 14:29:11 +01001221 /* *INDENT-OFF* */
1222 REPLY_MACRO2(VL_API_SHOW_ONE_STATUS_REPLY,
1223 ({
1224 rmp->gpe_status = vnet_lisp_gpe_enable_disable_status ();
1225 rmp->feature_status = vnet_lisp_enable_disable_status ();
1226 }));
1227 /* *INDENT-ON* */
1228}
1229
1230static void
1231 vl_api_one_get_map_request_itr_rlocs_t_handler
1232 (vl_api_one_get_map_request_itr_rlocs_t * mp)
1233{
Filip Tehlar694396d2017-02-17 14:29:11 +01001234 vl_api_one_get_map_request_itr_rlocs_reply_t *rmp = NULL;
1235 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1236 locator_set_t *loc_set = 0;
1237 u8 *tmp_str = 0;
1238 int rv = 0;
1239
Filip Tehlar694396d2017-02-17 14:29:11 +01001240 if (~0 == lcm->mreq_itr_rlocs)
1241 {
1242 tmp_str = format (0, " ");
1243 }
1244 else
1245 {
1246 loc_set =
1247 pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
1248 tmp_str = format (0, "%s", loc_set->name);
1249 }
1250
1251 /* *INDENT-OFF* */
1252 REPLY_MACRO2(VL_API_ONE_GET_MAP_REQUEST_ITR_RLOCS_REPLY,
1253 ({
1254 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1255 ARRAY_LEN(rmp->locator_set_name) - 1);
1256 }));
1257 /* *INDENT-ON* */
1258
1259 vec_free (tmp_str);
1260}
1261
1262static void
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02001263vl_api_show_one_nsh_mapping_t_handler (vl_api_show_one_nsh_mapping_t * mp)
1264{
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02001265 vl_api_show_one_nsh_mapping_reply_t *rmp = NULL;
1266 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1267 mapping_t *m;
1268 locator_set_t *ls = 0;
1269 u8 *tmp_str = 0;
1270 u8 is_set = 0;
1271 int rv = 0;
1272
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02001273 if (lcm->nsh_map_index == (u32) ~ 0)
1274 {
1275 tmp_str = format (0, "N/A");
1276 }
1277 else
1278 {
1279 m = pool_elt_at_index (lcm->mapping_pool, lcm->nsh_map_index);
1280 if (~0 != m->locator_set_index)
1281 {
1282 ls =
1283 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
1284 tmp_str = format (0, "%s", ls->name);
1285 is_set = 1;
1286 }
1287 else
1288 {
1289 tmp_str = format (0, "N/A");
1290 }
1291 }
1292 vec_add1 (tmp_str, 0);
1293
1294 /* *INDENT-OFF* */
1295 REPLY_MACRO2(VL_API_SHOW_ONE_NSH_MAPPING_REPLY,
1296 ({
1297 rmp->is_set = is_set;
1298 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1299 ARRAY_LEN(rmp->locator_set_name) - 1);
1300 }));
1301 /* *INDENT-ON* */
1302}
1303
1304static void
Filip Tehlar694396d2017-02-17 14:29:11 +01001305vl_api_show_one_pitr_t_handler (vl_api_show_one_pitr_t * mp)
1306{
Filip Tehlar694396d2017-02-17 14:29:11 +01001307 vl_api_show_one_pitr_reply_t *rmp = NULL;
1308 lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
1309 mapping_t *m;
1310 locator_set_t *ls = 0;
1311 u8 *tmp_str = 0;
1312 int rv = 0;
1313
Jakub Grajciar58db6e12020-01-30 13:26:43 +01001314 u8 is_enable = (lcm->flags & LISP_FLAG_PITR_MODE)
Filip Tehlar0a8840d2017-10-16 05:48:23 -07001315 && lcm->pitr_map_index != ~0;
1316
Jakub Grajciar58db6e12020-01-30 13:26:43 +01001317 if (!is_enable)
Filip Tehlar694396d2017-02-17 14:29:11 +01001318 {
1319 tmp_str = format (0, "N/A");
1320 }
1321 else
1322 {
1323 m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
1324 if (~0 != m->locator_set_index)
1325 {
1326 ls =
1327 pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
1328 tmp_str = format (0, "%s", ls->name);
1329 }
1330 else
1331 {
1332 tmp_str = format (0, "N/A");
1333 }
1334 }
1335 vec_add1 (tmp_str, 0);
1336
1337 /* *INDENT-OFF* */
1338 REPLY_MACRO2(VL_API_SHOW_ONE_PITR_REPLY,
1339 ({
Filip Tehlar0a8840d2017-10-16 05:48:23 -07001340 rmp->status = lcm->flags & LISP_FLAG_PITR_MODE;
Filip Tehlar694396d2017-02-17 14:29:11 +01001341 strncpy((char *) rmp->locator_set_name, (char *) tmp_str,
1342 ARRAY_LEN(rmp->locator_set_name) - 1);
1343 }));
1344 /* *INDENT-ON* */
1345}
1346
Filip Tehlar7eaf0e52017-03-08 08:46:51 +01001347static void
1348 vl_api_show_one_stats_enable_disable_t_handler
1349 (vl_api_show_one_stats_enable_disable_t * mp)
1350{
1351 vl_api_show_one_stats_enable_disable_reply_t *rmp = NULL;
1352 vnet_api_error_t rv = 0;
1353
1354 /* *INDENT-OFF* */
1355 REPLY_MACRO2 (VL_API_SHOW_ONE_STATS_ENABLE_DISABLE_REPLY,
1356 ({
Jakub Grajciar58db6e12020-01-30 13:26:43 +01001357 rmp->is_enable = vnet_lisp_stats_enable_disable_state ();
Filip Tehlar7eaf0e52017-03-08 08:46:51 +01001358 }));
1359 /* *INDENT-ON* */
1360}
1361
1362static void
1363 vl_api_one_stats_enable_disable_t_handler
1364 (vl_api_one_stats_enable_disable_t * mp)
1365{
1366 vl_api_one_enable_disable_reply_t *rmp = NULL;
1367
Jakub Grajciar58db6e12020-01-30 13:26:43 +01001368 vnet_api_error_t rv = vnet_lisp_stats_enable_disable (mp->is_enable);
Filip Tehlar7eaf0e52017-03-08 08:46:51 +01001369 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
1370}
1371
1372static void
Filip Tehlar21511912017-04-07 10:41:42 +02001373vl_api_one_stats_flush_t_handler (vl_api_one_stats_flush_t * mp)
1374{
1375 vl_api_one_stats_flush_reply_t *rmp;
1376 u8 rv;
1377
1378 rv = vnet_lisp_flush_stats ();
1379 REPLY_MACRO (VL_API_ONE_STATS_FLUSH_REPLY);
1380}
1381
1382static void
Filip Tehlar7eaf0e52017-03-08 08:46:51 +01001383vl_api_one_stats_dump_t_handler (vl_api_one_stats_dump_t * mp)
1384{
Filip Tehlar4868ff62017-03-09 16:48:39 +01001385 vl_api_one_stats_details_t *rmp;
1386 lisp_api_stats_t *stats, *stat;
1387 u8 rv = 0;
Filip Tehlar7eaf0e52017-03-08 08:46:51 +01001388
Filip Tehlar4868ff62017-03-09 16:48:39 +01001389 stats = vnet_lisp_get_stats ();
1390 vec_foreach (stat, stats)
1391 {
1392 /* *INDENT-OFF* */
1393 REPLY_DETAILS (VL_API_ONE_STATS_DETAILS,
1394 ({
Jakub Grajciar58db6e12020-01-30 13:26:43 +01001395 fid_to_api_eid (&stat->deid, &rmp->deid);
1396 fid_to_api_eid (&stat->seid, &rmp->seid);
Filip Tehlar4868ff62017-03-09 16:48:39 +01001397 rmp->vni = clib_host_to_net_u32 (stat->vni);
1398
Jakub Grajciar58db6e12020-01-30 13:26:43 +01001399 ip_address_encode2 (&stat->rmt_rloc, &rmp->rloc);
1400 ip_address_encode2 (&stat->loc_rloc, &rmp->lloc);
Filip Tehlar4868ff62017-03-09 16:48:39 +01001401
Filip Tehlar21511912017-04-07 10:41:42 +02001402 rmp->pkt_count = clib_host_to_net_u32 (stat->counters.packets);
1403 rmp->bytes = clib_host_to_net_u32 (stat->counters.bytes);
Filip Tehlar4868ff62017-03-09 16:48:39 +01001404 }));
1405 /* *INDENT-ON* */
1406 }
Filip Tehlar7eaf0e52017-03-08 08:46:51 +01001407}
1408
Filip Tehlard5a65db2017-05-17 17:21:10 +02001409static void
1410 vl_api_one_add_del_l2_arp_entry_t_handler
1411 (vl_api_one_add_del_l2_arp_entry_t * mp)
1412{
1413 vl_api_one_add_del_l2_arp_entry_reply_t *rmp;
1414 int rv = 0;
1415 gid_address_t _arp, *arp = &_arp;
Jakub Grajciar58db6e12020-01-30 13:26:43 +01001416 ip4_address_t ip4;
1417 mac_address_t mac;
Dave Barachb7b92992018-10-17 10:38:51 -04001418 clib_memset (arp, 0, sizeof (*arp));
Filip Tehlard5a65db2017-05-17 17:21:10 +02001419
1420 gid_address_type (arp) = GID_ADDR_ARP;
1421 gid_address_arp_bd (arp) = clib_net_to_host_u32 (mp->bd);
1422
Jakub Grajciar58db6e12020-01-30 13:26:43 +01001423 ip4_address_decode (mp->entry.ip4, &ip4);
1424 ip_address_set (&gid_address_arp_ndp_ip (arp), &ip4, AF_IP4);
1425 mac_address_decode (mp->entry.mac, &mac);
Filip Tehlard5a65db2017-05-17 17:21:10 +02001426
Jakub Grajciar58db6e12020-01-30 13:26:43 +01001427 rv = vnet_lisp_add_del_l2_arp_ndp_entry (arp, mac.bytes, mp->is_add);
Filip Tehlard5a65db2017-05-17 17:21:10 +02001428
1429 REPLY_MACRO (VL_API_ONE_ADD_DEL_L2_ARP_ENTRY_REPLY);
1430}
1431
1432static void
Filip Tehlar05879992017-09-05 15:46:09 +02001433vl_api_one_add_del_ndp_entry_t_handler (vl_api_one_add_del_ndp_entry_t * mp)
1434{
1435 vl_api_one_add_del_ndp_entry_reply_t *rmp;
1436 int rv = 0;
1437 gid_address_t _g, *g = &_g;
Jakub Grajciar58db6e12020-01-30 13:26:43 +01001438 ip6_address_t ip6;
1439 mac_address_t mac;
Dave Barachb7b92992018-10-17 10:38:51 -04001440 clib_memset (g, 0, sizeof (*g));
Filip Tehlar05879992017-09-05 15:46:09 +02001441
1442 gid_address_type (g) = GID_ADDR_NDP;
1443 gid_address_ndp_bd (g) = clib_net_to_host_u32 (mp->bd);
Filip Tehlar05879992017-09-05 15:46:09 +02001444
Jakub Grajciar58db6e12020-01-30 13:26:43 +01001445 ip6_address_decode (mp->entry.ip6, &ip6);
1446 ip_address_set (&gid_address_arp_ndp_ip (g), &ip6, AF_IP6);
1447 mac_address_decode (mp->entry.mac, &mac);
1448
1449 rv = vnet_lisp_add_del_l2_arp_ndp_entry (g, mac.bytes, mp->is_add);
Filip Tehlar05879992017-09-05 15:46:09 +02001450
1451 REPLY_MACRO (VL_API_ONE_ADD_DEL_NDP_ENTRY_REPLY);
1452}
1453
1454static void
1455vl_api_one_ndp_bd_get_t_handler (vl_api_one_ndp_bd_get_t * mp)
1456{
1457 vl_api_one_ndp_bd_get_reply_t *rmp;
1458 int rv = 0;
1459 u32 i = 0;
1460 hash_pair_t *p;
1461
1462 u32 *bds = vnet_lisp_ndp_bds_get ();
1463 u32 size = hash_elts (bds) * sizeof (u32);
1464
1465 /* *INDENT-OFF* */
1466 REPLY_MACRO4 (VL_API_ONE_NDP_BD_GET_REPLY, size,
1467 {
1468 rmp->count = clib_host_to_net_u32 (hash_elts (bds));
1469 hash_foreach_pair (p, bds,
1470 ({
1471 rmp->bridge_domains[i++] = clib_host_to_net_u32 (p->key);
1472 }));
1473 });
1474 /* *INDENT-ON* */
1475
1476 hash_free (bds);
1477}
1478
1479static void
Filip Tehlard5a65db2017-05-17 17:21:10 +02001480vl_api_one_l2_arp_bd_get_t_handler (vl_api_one_l2_arp_bd_get_t * mp)
1481{
1482 vl_api_one_l2_arp_bd_get_reply_t *rmp;
1483 int rv = 0;
1484 u32 i = 0;
1485 hash_pair_t *p;
1486
1487 u32 *bds = vnet_lisp_l2_arp_bds_get ();
1488 u32 size = hash_elts (bds) * sizeof (u32);
1489
1490 /* *INDENT-OFF* */
1491 REPLY_MACRO4 (VL_API_ONE_L2_ARP_BD_GET_REPLY, size,
1492 {
1493 rmp->count = clib_host_to_net_u32 (hash_elts (bds));
1494 hash_foreach_pair (p, bds,
1495 ({
1496 rmp->bridge_domains[i++] = clib_host_to_net_u32 (p->key);
1497 }));
1498 });
1499 /* *INDENT-ON* */
1500
1501 hash_free (bds);
1502}
1503
1504static void
1505vl_api_one_l2_arp_entries_get_t_handler (vl_api_one_l2_arp_entries_get_t * mp)
1506{
1507 vl_api_one_l2_arp_entries_get_reply_t *rmp;
1508 lisp_api_l2_arp_entry_t *entries = 0, *e;
1509 u32 i = 0;
1510 int rv = 0;
1511
1512 u32 bd = clib_net_to_host_u32 (mp->bd);
1513
1514 entries = vnet_lisp_l2_arp_entries_get_by_bd (bd);
Ole Troan1d7d2ab2017-07-06 14:25:38 +02001515 u32 size = vec_len (entries) * sizeof (vl_api_one_l2_arp_entry_t);
Filip Tehlard5a65db2017-05-17 17:21:10 +02001516
1517 /* *INDENT-OFF* */
1518 REPLY_MACRO4 (VL_API_ONE_L2_ARP_ENTRIES_GET_REPLY, size,
1519 {
1520 rmp->count = clib_host_to_net_u32 (vec_len (entries));
1521 vec_foreach (e, entries)
1522 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +01001523 mac_address_encode ((mac_address_t *) e->mac, rmp->entries[i].mac);
1524 ip4_address_encode ((ip4_address_t *) &e->ip4, rmp->entries[i].ip4);
Filip Tehlard5a65db2017-05-17 17:21:10 +02001525 i++;
1526 }
1527 });
1528 /* *INDENT-ON* */
1529
1530 vec_free (entries);
1531}
1532
Filip Tehlar7048ff12017-07-27 08:09:14 +02001533static void
1534 vl_api_one_map_register_fallback_threshold_t_handler
1535 (vl_api_one_map_register_fallback_threshold_t * mp)
1536{
1537 vl_api_one_map_register_fallback_threshold_reply_t *rmp;
1538 int rv = 0;
1539
1540 mp->value = clib_net_to_host_u32 (mp->value);
1541 rv = vnet_lisp_map_register_fallback_threshold_set (mp->value);
Filip Tehlar6f9f6f32017-08-08 13:11:22 +02001542 REPLY_MACRO (VL_API_ONE_MAP_REGISTER_FALLBACK_THRESHOLD_REPLY);
Filip Tehlar7048ff12017-07-27 08:09:14 +02001543}
1544
1545static void
1546 vl_api_show_one_map_register_fallback_threshold_t_handler
1547 (vl_api_show_one_map_register_fallback_threshold_t * mp)
1548{
1549 vl_api_show_one_map_register_fallback_threshold_reply_t *rmp;
1550 int rv = 0;
1551
1552 u32 value = vnet_lisp_map_register_fallback_threshold_get ();
1553
1554 /* *INDENT-OFF* */
1555 REPLY_MACRO2 (VL_API_SHOW_ONE_MAP_REGISTER_FALLBACK_THRESHOLD_REPLY,
1556 ({
1557 rmp->value = clib_host_to_net_u32 (value);
1558 }));
1559 /* *INDENT-ON* */
1560}
1561
Filip Tehlar05879992017-09-05 15:46:09 +02001562static void
Filip Tehlara4980b82017-09-27 14:32:02 +02001563 vl_api_one_set_transport_protocol_t_handler
1564 (vl_api_one_set_transport_protocol_t * mp)
1565{
1566 vl_api_one_set_transport_protocol_reply_t *rmp;
1567 int rv = 0;
1568
1569 rv = vnet_lisp_set_transport_protocol (mp->protocol);
1570
1571 REPLY_MACRO (VL_API_ONE_SET_TRANSPORT_PROTOCOL_REPLY);
1572}
1573
1574static void
1575 vl_api_one_get_transport_protocol_t_handler
1576 (vl_api_one_get_transport_protocol_t * mp)
1577{
1578 vl_api_one_get_transport_protocol_reply_t *rmp;
1579 int rv = 0;
1580 u8 proto = (u8) vnet_lisp_get_transport_protocol ();
1581
1582 /* *INDENT-OFF* */
1583 REPLY_MACRO2 (VL_API_ONE_GET_TRANSPORT_PROTOCOL_REPLY,
1584 ({
1585 rmp->protocol = proto;
1586 }));
1587 /* *INDENT-ON* */
1588}
1589
1590static void
Filip Tehlar05879992017-09-05 15:46:09 +02001591vl_api_one_ndp_entries_get_t_handler (vl_api_one_ndp_entries_get_t * mp)
1592{
1593 vl_api_one_ndp_entries_get_reply_t *rmp = 0;
1594 lisp_api_ndp_entry_t *entries = 0, *e;
1595 u32 i = 0;
1596 int rv = 0;
1597
1598 u32 bd = clib_net_to_host_u32 (mp->bd);
1599
1600 entries = vnet_lisp_ndp_entries_get_by_bd (bd);
1601 u32 size = vec_len (entries) * sizeof (vl_api_one_ndp_entry_t);
1602
1603 /* *INDENT-OFF* */
1604 REPLY_MACRO4 (VL_API_ONE_NDP_ENTRIES_GET_REPLY, size,
1605 {
1606 rmp->count = clib_host_to_net_u32 (vec_len (entries));
1607 vec_foreach (e, entries)
1608 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +01001609 mac_address_encode ((mac_address_t *) e->mac, rmp->entries[i].mac);
1610 ip6_address_encode ((ip6_address_t *) &e->ip6, rmp->entries[i].ip6);
Filip Tehlar05879992017-09-05 15:46:09 +02001611 i++;
1612 }
1613 });
1614 /* *INDENT-ON* */
1615
1616 vec_free (entries);
1617}
1618
Filip Tehlar0a8840d2017-10-16 05:48:23 -07001619static void
1620 vl_api_one_enable_disable_xtr_mode_t_handler
1621 (vl_api_one_enable_disable_xtr_mode_t * mp)
1622{
1623 vl_api_one_enable_disable_xtr_mode_reply_t *rmp = 0;
Jakub Grajciar58db6e12020-01-30 13:26:43 +01001624 int rv = vnet_lisp_enable_disable_xtr_mode (mp->is_enable);
Filip Tehlar0a8840d2017-10-16 05:48:23 -07001625
1626 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_XTR_MODE_REPLY);
1627}
1628
1629static void
1630vl_api_one_show_xtr_mode_t_handler (vl_api_one_show_xtr_mode_t * mp)
1631{
1632 vl_api_one_show_xtr_mode_reply_t *rmp = 0;
1633 int rv = 0;
1634
1635 /* *INDENT-OFF* */
1636 REPLY_MACRO2 (VL_API_ONE_SHOW_XTR_MODE_REPLY,
1637 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +01001638 rmp->is_enable = vnet_lisp_get_xtr_mode ();
Filip Tehlar0a8840d2017-10-16 05:48:23 -07001639 });
1640 /* *INDENT-ON* */
1641}
1642
1643static void
1644 vl_api_one_enable_disable_pitr_mode_t_handler
1645 (vl_api_one_enable_disable_pitr_mode_t * mp)
1646{
1647 vl_api_one_enable_disable_pitr_mode_reply_t *rmp = 0;
Jakub Grajciar58db6e12020-01-30 13:26:43 +01001648 int rv = vnet_lisp_enable_disable_pitr_mode (mp->is_enable);
Filip Tehlar0a8840d2017-10-16 05:48:23 -07001649
1650 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_PITR_MODE_REPLY);
1651}
1652
1653static void
1654vl_api_one_show_pitr_mode_t_handler (vl_api_one_show_pitr_mode_t * mp)
1655{
1656 vl_api_one_show_pitr_mode_reply_t *rmp = 0;
1657 int rv = 0;
1658
1659 /* *INDENT-OFF* */
1660 REPLY_MACRO2 (VL_API_ONE_SHOW_PITR_MODE_REPLY,
1661 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +01001662 rmp->is_enable = vnet_lisp_get_pitr_mode ();
Filip Tehlar0a8840d2017-10-16 05:48:23 -07001663 });
1664 /* *INDENT-ON* */
1665}
1666
1667static void
1668 vl_api_one_enable_disable_petr_mode_t_handler
1669 (vl_api_one_enable_disable_petr_mode_t * mp)
1670{
1671 vl_api_one_enable_disable_petr_mode_reply_t *rmp = 0;
Jakub Grajciar58db6e12020-01-30 13:26:43 +01001672 int rv = vnet_lisp_enable_disable_petr_mode (mp->is_enable);
Filip Tehlar0a8840d2017-10-16 05:48:23 -07001673
1674 REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_PETR_MODE_REPLY);
1675}
1676
1677static void
1678vl_api_one_show_petr_mode_t_handler (vl_api_one_show_petr_mode_t * mp)
1679{
1680 vl_api_one_show_petr_mode_reply_t *rmp = 0;
1681 int rv = 0;
1682
1683 /* *INDENT-OFF* */
1684 REPLY_MACRO2 (VL_API_ONE_SHOW_PETR_MODE_REPLY,
1685 {
Jakub Grajciar58db6e12020-01-30 13:26:43 +01001686 rmp->is_enable = vnet_lisp_get_petr_mode ();
Filip Tehlar0a8840d2017-10-16 05:48:23 -07001687 });
1688 /* *INDENT-ON* */
1689}
1690
Filip Tehlar694396d2017-02-17 14:29:11 +01001691/*
1692 * one_api_hookup
1693 * Add vpe's API message handlers to the table.
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -07001694 * vlib has already mapped shared memory and
Filip Tehlar694396d2017-02-17 14:29:11 +01001695 * added the client registration handlers.
1696 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
1697 */
1698#define vl_msg_name_crc_list
1699#include <vnet/vnet_all_api_h.h>
1700#undef vl_msg_name_crc_list
1701
1702static void
1703setup_message_id_table (api_main_t * am)
1704{
1705#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
Filip Tehlar974cdc62017-02-22 18:09:49 +01001706 foreach_vl_msg_name_crc_one;
Filip Tehlar694396d2017-02-17 14:29:11 +01001707#undef _
1708}
1709
1710static clib_error_t *
1711one_api_hookup (vlib_main_t * vm)
1712{
Dave Barach39d69112019-11-27 11:42:13 -05001713 api_main_t *am = vlibapi_get_main ();
Filip Tehlar694396d2017-02-17 14:29:11 +01001714
1715#define _(N,n) \
1716 vl_msg_api_set_handlers(VL_API_##N, #n, \
1717 vl_api_##n##_t_handler, \
1718 vl_noop_handler, \
1719 vl_api_##n##_t_endian, \
1720 vl_api_##n##_t_print, \
1721 sizeof(vl_api_##n##_t), 1);
1722 foreach_vpe_api_msg;
1723#undef _
1724
1725 /*
1726 * Set up the (msg_name, crc, message-id) table
1727 */
1728 setup_message_id_table (am);
1729
1730 return 0;
1731}
1732
1733VLIB_API_INIT_FUNCTION (one_api_hookup);
1734
1735/*
1736 * fd.io coding-style-patch-verification: ON
1737 *
1738 * Local Variables:
1739 * eval: (c-set-style "gnu")
1740 * End:
1741 */