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