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