Pavel Kotucek | cfb7be8 | 2016-12-21 14:15:37 +0100 | [diff] [blame] | 1 | /* |
| 2 | *------------------------------------------------------------------ |
| 3 | * lisp_api.c - lisp api |
| 4 | * |
| 5 | * Copyright (c) 2016 Cisco and/or its affiliates. |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at: |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | *------------------------------------------------------------------ |
| 18 | */ |
| 19 | |
| 20 | #include <vnet/vnet.h> |
| 21 | #include <vlibmemory/api.h> |
| 22 | |
| 23 | #include <vnet/interface.h> |
| 24 | #include <vnet/api_errno.h> |
| 25 | #include <vnet/lisp-cp/control.h> |
| 26 | #include <vnet/lisp-gpe/lisp_gpe.h> |
| 27 | |
| 28 | #include <vnet/vnet_msg_enum.h> |
| 29 | |
Filip Tehlar | 05a057b | 2017-02-01 08:50:31 +0100 | [diff] [blame] | 30 | #define vl_api_remote_locator_t_endian vl_noop_handler |
| 31 | #define vl_api_remote_locator_t_print vl_noop_handler |
| 32 | #define vl_api_local_locator_t_endian vl_noop_handler |
| 33 | #define vl_api_local_locator_t_print vl_noop_handler |
| 34 | |
| 35 | #define vl_api_lisp_add_del_locator_set_t_endian vl_noop_handler |
| 36 | #define vl_api_lisp_add_del_locator_set_t_print vl_noop_handler |
| 37 | #define vl_api_lisp_add_del_remote_mapping_t_endian vl_noop_handler |
| 38 | #define vl_api_lisp_add_del_remote_mapping_t_print vl_noop_handler |
| 39 | |
Filip Tehlar | 694396d | 2017-02-17 14:29:11 +0100 | [diff] [blame] | 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 | |
Pavel Kotucek | cfb7be8 | 2016-12-21 14:15:37 +0100 | [diff] [blame] | 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 | _(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set) \ |
| 63 | _(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator) \ |
| 64 | _(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid) \ |
| 65 | _(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver) \ |
| 66 | _(LISP_ADD_DEL_MAP_SERVER, lisp_add_del_map_server) \ |
| 67 | _(LISP_ENABLE_DISABLE, lisp_enable_disable) \ |
| 68 | _(LISP_RLOC_PROBE_ENABLE_DISABLE, lisp_rloc_probe_enable_disable) \ |
| 69 | _(LISP_MAP_REGISTER_ENABLE_DISABLE, lisp_map_register_enable_disable) \ |
| 70 | _(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping) \ |
| 71 | _(LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency) \ |
| 72 | _(LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set) \ |
| 73 | _(LISP_MAP_REQUEST_MODE, lisp_map_request_mode) \ |
| 74 | _(LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map) \ |
| 75 | _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \ |
| 76 | _(LISP_LOCATOR_DUMP, lisp_locator_dump) \ |
| 77 | _(LISP_EID_TABLE_DUMP, lisp_eid_table_dump) \ |
| 78 | _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump) \ |
| 79 | _(LISP_MAP_SERVER_DUMP, lisp_map_server_dump) \ |
| 80 | _(LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump) \ |
| 81 | _(LISP_EID_TABLE_VNI_DUMP, lisp_eid_table_vni_dump) \ |
| 82 | _(LISP_ADJACENCIES_GET, lisp_adjacencies_get) \ |
| 83 | _(SHOW_LISP_RLOC_PROBE_STATE, show_lisp_rloc_probe_state) \ |
| 84 | _(SHOW_LISP_MAP_REGISTER_STATE, show_lisp_map_register_state) \ |
| 85 | _(SHOW_LISP_STATUS, show_lisp_status) \ |
| 86 | _(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \ |
| 87 | lisp_add_del_map_request_itr_rlocs) \ |
| 88 | _(LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs) \ |
| 89 | _(SHOW_LISP_PITR, show_lisp_pitr) \ |
| 90 | _(SHOW_LISP_MAP_REQUEST_MODE, show_lisp_map_request_mode) \ |
Florin Coras | ba888e4 | 2017-01-24 11:38:18 -0800 | [diff] [blame] | 91 | _(LISP_USE_PETR, lisp_use_petr) \ |
| 92 | _(SHOW_LISP_USE_PETR, show_lisp_use_petr) \ |
Pavel Kotucek | cfb7be8 | 2016-12-21 14:15:37 +0100 | [diff] [blame] | 93 | |
Pavel Kotucek | cfb7be8 | 2016-12-21 14:15:37 +0100 | [diff] [blame] | 94 | static locator_t * |
Filip Tehlar | 05a057b | 2017-02-01 08:50:31 +0100 | [diff] [blame] | 95 | unformat_lisp_locs (vl_api_remote_locator_t * rmt_locs, u32 rloc_num) |
Pavel Kotucek | cfb7be8 | 2016-12-21 14:15:37 +0100 | [diff] [blame] | 96 | { |
| 97 | u32 i; |
| 98 | locator_t *locs = 0, loc; |
Filip Tehlar | 05a057b | 2017-02-01 08:50:31 +0100 | [diff] [blame] | 99 | vl_api_remote_locator_t *r; |
Pavel Kotucek | cfb7be8 | 2016-12-21 14:15:37 +0100 | [diff] [blame] | 100 | |
| 101 | for (i = 0; i < rloc_num; i++) |
| 102 | { |
| 103 | /* remote locators */ |
Filip Tehlar | 05a057b | 2017-02-01 08:50:31 +0100 | [diff] [blame] | 104 | r = &rmt_locs[i]; |
Pavel Kotucek | cfb7be8 | 2016-12-21 14:15:37 +0100 | [diff] [blame] | 105 | memset (&loc, 0, sizeof (loc)); |
| 106 | gid_address_ip_set (&loc.address, &r->addr, r->is_ip4 ? IP4 : IP6); |
| 107 | |
| 108 | loc.priority = r->priority; |
| 109 | loc.weight = r->weight; |
| 110 | |
| 111 | vec_add1 (locs, loc); |
| 112 | } |
| 113 | return locs; |
| 114 | } |
| 115 | |
| 116 | static void |
| 117 | vl_api_lisp_add_del_locator_set_t_handler (vl_api_lisp_add_del_locator_set_t * |
| 118 | mp) |
| 119 | { |
| 120 | vl_api_lisp_add_del_locator_set_reply_t *rmp; |
| 121 | int rv = 0; |
| 122 | vnet_lisp_add_del_locator_set_args_t _a, *a = &_a; |
| 123 | locator_t locator; |
Filip Tehlar | 05a057b | 2017-02-01 08:50:31 +0100 | [diff] [blame] | 124 | vl_api_local_locator_t *ls_loc; |
Pavel Kotucek | cfb7be8 | 2016-12-21 14:15:37 +0100 | [diff] [blame] | 125 | u32 ls_index = ~0, locator_num; |
| 126 | u8 *locator_name = NULL; |
| 127 | int i; |
| 128 | |
| 129 | memset (a, 0, sizeof (a[0])); |
| 130 | |
Filip Tehlar | 9d286a4 | 2017-10-26 23:57:09 -0700 | [diff] [blame] | 131 | mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0; |
Pavel Kotucek | cfb7be8 | 2016-12-21 14:15:37 +0100 | [diff] [blame] | 132 | locator_name = format (0, "%s", mp->locator_set_name); |
Gabriel Ganne | 3491d7f | 2017-10-19 15:10:46 +0200 | [diff] [blame] | 133 | vec_terminate_c_string (locator_name); |
Pavel Kotucek | cfb7be8 | 2016-12-21 14:15:37 +0100 | [diff] [blame] | 134 | |
| 135 | a->name = locator_name; |
| 136 | a->is_add = mp->is_add; |
| 137 | a->local = 1; |
| 138 | locator_num = clib_net_to_host_u32 (mp->locator_num); |
| 139 | |
| 140 | memset (&locator, 0, sizeof (locator)); |
| 141 | for (i = 0; i < locator_num; i++) |
| 142 | { |
Filip Tehlar | 05a057b | 2017-02-01 08:50:31 +0100 | [diff] [blame] | 143 | ls_loc = &mp->locators[i]; |
Pavel Kotucek | cfb7be8 | 2016-12-21 14:15:37 +0100 | [diff] [blame] | 144 | VALIDATE_SW_IF_INDEX (ls_loc); |
| 145 | |
| 146 | locator.sw_if_index = htonl (ls_loc->sw_if_index); |
| 147 | locator.priority = ls_loc->priority; |
| 148 | locator.weight = ls_loc->weight; |
| 149 | locator.local = 1; |
| 150 | vec_add1 (a->locators, locator); |
| 151 | } |
| 152 | |
| 153 | rv = vnet_lisp_add_del_locator_set (a, &ls_index); |
| 154 | |
| 155 | BAD_SW_IF_INDEX_LABEL; |
| 156 | |
| 157 | vec_free (locator_name); |
| 158 | vec_free (a->locators); |
| 159 | |
| 160 | /* *INDENT-OFF* */ |
| 161 | REPLY_MACRO2 (VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY, |
| 162 | ({ |
| 163 | rmp->ls_index = clib_host_to_net_u32 (ls_index); |
| 164 | })); |
| 165 | /* *INDENT-ON* */ |
| 166 | } |
| 167 | |
| 168 | static void |
| 169 | vl_api_lisp_add_del_locator_t_handler (vl_api_lisp_add_del_locator_t * mp) |
| 170 | { |
| 171 | vl_api_lisp_add_del_locator_reply_t *rmp; |
| 172 | int rv = 0; |
| 173 | locator_t locator, *locators = NULL; |
| 174 | vnet_lisp_add_del_locator_set_args_t _a, *a = &_a; |
| 175 | u32 ls_index = ~0; |
| 176 | u8 *locator_name = NULL; |
| 177 | |
| 178 | memset (&locator, 0, sizeof (locator)); |
| 179 | memset (a, 0, sizeof (a[0])); |
| 180 | |
| 181 | locator.sw_if_index = ntohl (mp->sw_if_index); |
| 182 | locator.priority = mp->priority; |
| 183 | locator.weight = mp->weight; |
| 184 | locator.local = 1; |
| 185 | vec_add1 (locators, locator); |
| 186 | |
Filip Tehlar | 9d286a4 | 2017-10-26 23:57:09 -0700 | [diff] [blame] | 187 | mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0; |
Pavel Kotucek | cfb7be8 | 2016-12-21 14:15:37 +0100 | [diff] [blame] | 188 | locator_name = format (0, "%s", mp->locator_set_name); |
Gabriel Ganne | 3491d7f | 2017-10-19 15:10:46 +0200 | [diff] [blame] | 189 | vec_terminate_c_string (locator_name); |
Pavel Kotucek | cfb7be8 | 2016-12-21 14:15:37 +0100 | [diff] [blame] | 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_LISP_ADD_DEL_LOCATOR_REPLY); |
| 202 | } |
| 203 | |
| 204 | static int |
| 205 | unformat_lisp_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_lisp_add_del_local_eid_t_handler (vl_api_lisp_add_del_local_eid_t * mp) |
| 238 | { |
| 239 | vl_api_lisp_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_lisp_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 | |
Filip Tehlar | 9d286a4 | 2017-10-26 23:57:09 -0700 | [diff] [blame] | 255 | mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0; |
Pavel Kotucek | cfb7be8 | 2016-12-21 14:15:37 +0100 | [diff] [blame] | 256 | name = format (0, "%s", mp->locator_set_name); |
Gabriel Ganne | 3491d7f | 2017-10-19 15:10:46 +0200 | [diff] [blame] | 257 | vec_terminate_c_string (name); |
Pavel Kotucek | cfb7be8 | 2016-12-21 14:15:37 +0100 | [diff] [blame] | 258 | p = hash_get_mem (lcm->locator_set_index_by_name, name); |
| 259 | if (!p) |
| 260 | { |
| 261 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 262 | goto out; |
| 263 | } |
| 264 | locator_set_index = p[0]; |
| 265 | |
| 266 | if (*mp->key) |
| 267 | key = format (0, "%s", mp->key); |
| 268 | |
| 269 | /* XXX treat batch configuration */ |
| 270 | a->is_add = mp->is_add; |
| 271 | gid_address_copy (&a->eid, eid); |
| 272 | a->locator_set_index = locator_set_index; |
| 273 | a->local = 1; |
| 274 | a->key = key; |
| 275 | a->key_id = clib_net_to_host_u16 (mp->key_id); |
| 276 | |
| 277 | rv = vnet_lisp_add_del_local_mapping (a, &map_index); |
| 278 | |
| 279 | out: |
| 280 | vec_free (name); |
| 281 | vec_free (key); |
| 282 | gid_address_free (&a->eid); |
| 283 | |
| 284 | REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY); |
| 285 | } |
| 286 | |
| 287 | static void |
| 288 | vl_api_lisp_eid_table_add_del_map_t_handler |
| 289 | (vl_api_lisp_eid_table_add_del_map_t * mp) |
| 290 | { |
| 291 | vl_api_lisp_eid_table_add_del_map_reply_t *rmp; |
| 292 | int rv = 0; |
| 293 | rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni), |
| 294 | clib_net_to_host_u32 (mp->dp_table), |
| 295 | mp->is_l2, mp->is_add); |
| 296 | REPLY_MACRO (VL_API_LISP_EID_TABLE_ADD_DEL_MAP_REPLY)} |
| 297 | |
| 298 | static void |
| 299 | vl_api_lisp_add_del_map_server_t_handler (vl_api_lisp_add_del_map_server_t |
| 300 | * mp) |
| 301 | { |
| 302 | vl_api_lisp_add_del_map_server_reply_t *rmp; |
| 303 | int rv = 0; |
| 304 | ip_address_t addr; |
| 305 | |
| 306 | memset (&addr, 0, sizeof (addr)); |
| 307 | |
| 308 | ip_address_set (&addr, mp->ip_address, mp->is_ipv6 ? IP6 : IP4); |
| 309 | rv = vnet_lisp_add_del_map_server (&addr, mp->is_add); |
| 310 | |
| 311 | REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_SERVER_REPLY); |
| 312 | } |
| 313 | |
| 314 | static void |
| 315 | vl_api_lisp_add_del_map_resolver_t_handler (vl_api_lisp_add_del_map_resolver_t |
| 316 | * mp) |
| 317 | { |
| 318 | vl_api_lisp_add_del_map_resolver_reply_t *rmp; |
| 319 | int rv = 0; |
| 320 | vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a; |
| 321 | |
| 322 | memset (a, 0, sizeof (a[0])); |
| 323 | |
| 324 | a->is_add = mp->is_add; |
| 325 | ip_address_set (&a->address, mp->ip_address, mp->is_ipv6 ? IP6 : IP4); |
| 326 | |
| 327 | rv = vnet_lisp_add_del_map_resolver (a); |
| 328 | |
| 329 | REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY); |
| 330 | } |
| 331 | |
| 332 | static void |
| 333 | vl_api_lisp_map_register_enable_disable_t_handler |
| 334 | (vl_api_lisp_map_register_enable_disable_t * mp) |
| 335 | { |
| 336 | vl_api_lisp_map_register_enable_disable_reply_t *rmp; |
| 337 | int rv = 0; |
| 338 | |
| 339 | vnet_lisp_map_register_enable_disable (mp->is_enabled); |
| 340 | REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY); |
| 341 | } |
| 342 | |
| 343 | static void |
| 344 | vl_api_lisp_rloc_probe_enable_disable_t_handler |
| 345 | (vl_api_lisp_rloc_probe_enable_disable_t * mp) |
| 346 | { |
| 347 | vl_api_lisp_rloc_probe_enable_disable_reply_t *rmp; |
| 348 | int rv = 0; |
| 349 | |
| 350 | vnet_lisp_rloc_probe_enable_disable (mp->is_enabled); |
| 351 | REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY); |
| 352 | } |
| 353 | |
| 354 | static void |
| 355 | vl_api_lisp_enable_disable_t_handler (vl_api_lisp_enable_disable_t * mp) |
| 356 | { |
| 357 | vl_api_lisp_enable_disable_reply_t *rmp; |
| 358 | int rv = 0; |
| 359 | |
| 360 | vnet_lisp_enable_disable (mp->is_en); |
| 361 | REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY); |
| 362 | } |
| 363 | |
| 364 | static void |
| 365 | vl_api_show_lisp_map_request_mode_t_handler |
| 366 | (vl_api_show_lisp_map_request_mode_t * mp) |
| 367 | { |
| 368 | int rv = 0; |
| 369 | vl_api_show_lisp_map_request_mode_reply_t *rmp; |
| 370 | |
| 371 | /* *INDENT-OFF* */ |
| 372 | REPLY_MACRO2(VL_API_SHOW_LISP_MAP_REQUEST_MODE_REPLY, |
| 373 | ({ |
| 374 | rmp->mode = vnet_lisp_get_map_request_mode (); |
| 375 | })); |
| 376 | /* *INDENT-ON* */ |
| 377 | } |
| 378 | |
| 379 | static void |
| 380 | vl_api_lisp_map_request_mode_t_handler (vl_api_lisp_map_request_mode_t * mp) |
| 381 | { |
| 382 | vl_api_lisp_map_request_mode_reply_t *rmp; |
| 383 | int rv = 0; |
| 384 | |
| 385 | rv = vnet_lisp_set_map_request_mode (mp->mode); |
| 386 | |
| 387 | REPLY_MACRO (VL_API_LISP_MAP_REQUEST_MODE_REPLY); |
| 388 | } |
| 389 | |
| 390 | static void |
| 391 | vl_api_lisp_pitr_set_locator_set_t_handler (vl_api_lisp_pitr_set_locator_set_t |
| 392 | * mp) |
| 393 | { |
| 394 | vl_api_lisp_pitr_set_locator_set_reply_t *rmp; |
| 395 | int rv = 0; |
| 396 | u8 *ls_name = 0; |
| 397 | |
Filip Tehlar | 9d286a4 | 2017-10-26 23:57:09 -0700 | [diff] [blame] | 398 | mp->ls_name[sizeof (mp->ls_name) - 1] = 0; |
Pavel Kotucek | cfb7be8 | 2016-12-21 14:15:37 +0100 | [diff] [blame] | 399 | ls_name = format (0, "%s", mp->ls_name); |
Gabriel Ganne | 3491d7f | 2017-10-19 15:10:46 +0200 | [diff] [blame] | 400 | vec_terminate_c_string (ls_name); |
Pavel Kotucek | cfb7be8 | 2016-12-21 14:15:37 +0100 | [diff] [blame] | 401 | rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add); |
| 402 | vec_free (ls_name); |
| 403 | |
| 404 | REPLY_MACRO (VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY); |
| 405 | } |
| 406 | |
| 407 | static void |
Florin Coras | ba888e4 | 2017-01-24 11:38:18 -0800 | [diff] [blame] | 408 | vl_api_lisp_use_petr_t_handler (vl_api_lisp_use_petr_t * mp) |
| 409 | { |
| 410 | vl_api_lisp_use_petr_reply_t *rmp; |
| 411 | int rv = 0; |
| 412 | ip_address_t addr; |
| 413 | |
| 414 | ip_address_set (&addr, &mp->address, mp->is_ip4 ? IP4 : IP6); |
| 415 | rv = vnet_lisp_use_petr (&addr, mp->is_add); |
| 416 | |
| 417 | REPLY_MACRO (VL_API_LISP_USE_PETR_REPLY); |
| 418 | } |
| 419 | |
| 420 | static void |
| 421 | vl_api_show_lisp_use_petr_t_handler (vl_api_show_lisp_use_petr_t * mp) |
| 422 | { |
| 423 | unix_shared_memory_queue_t *q = NULL; |
| 424 | vl_api_show_lisp_use_petr_reply_t *rmp = NULL; |
| 425 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 426 | mapping_t *m; |
| 427 | locator_set_t *ls = 0; |
| 428 | int rv = 0; |
Florin Coras | 2743cc4 | 2017-01-29 16:42:20 -0800 | [diff] [blame] | 429 | locator_t *loc = 0; |
| 430 | u8 status = 0; |
| 431 | gid_address_t addr; |
Florin Coras | ba888e4 | 2017-01-24 11:38:18 -0800 | [diff] [blame] | 432 | |
| 433 | q = vl_api_client_index_to_input_queue (mp->client_index); |
| 434 | if (q == 0) |
| 435 | { |
| 436 | return; |
| 437 | } |
| 438 | |
Florin Coras | 2743cc4 | 2017-01-29 16:42:20 -0800 | [diff] [blame] | 439 | memset (&addr, 0, sizeof (addr)); |
| 440 | status = lcm->flags & LISP_FLAG_USE_PETR; |
| 441 | if (status) |
Florin Coras | ba888e4 | 2017-01-24 11:38:18 -0800 | [diff] [blame] | 442 | { |
| 443 | m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index); |
| 444 | if (~0 != m->locator_set_index) |
| 445 | { |
| 446 | ls = |
| 447 | pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index); |
| 448 | loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]); |
Florin Coras | 2743cc4 | 2017-01-29 16:42:20 -0800 | [diff] [blame] | 449 | gid_address_copy (&addr, &loc->address); |
Florin Coras | ba888e4 | 2017-01-24 11:38:18 -0800 | [diff] [blame] | 450 | } |
| 451 | } |
| 452 | |
Florin Coras | 2743cc4 | 2017-01-29 16:42:20 -0800 | [diff] [blame] | 453 | /* *INDENT-OFF* */ |
| 454 | REPLY_MACRO2 (VL_API_SHOW_LISP_USE_PETR_REPLY, |
| 455 | { |
Filip Tehlar | 67a99f8 | 2017-03-10 13:18:02 +0100 | [diff] [blame] | 456 | rmp->status = status; |
| 457 | ip_address_t *ip = &gid_address_ip (&addr); |
| 458 | switch (ip_addr_version (ip)) |
| 459 | { |
| 460 | case IP4: |
| 461 | clib_memcpy (rmp->address, &ip_addr_v4 (ip), |
| 462 | sizeof (ip_addr_v4 (ip))); |
| 463 | break; |
| 464 | |
| 465 | case IP6: |
| 466 | clib_memcpy (rmp->address, &ip_addr_v6 (ip), |
| 467 | sizeof (ip_addr_v6 (ip))); |
| 468 | break; |
| 469 | |
| 470 | default: |
| 471 | ASSERT (0); |
| 472 | } |
| 473 | rmp->is_ip4 = (gid_address_ip_version (&addr) == IP4); |
Florin Coras | 2743cc4 | 2017-01-29 16:42:20 -0800 | [diff] [blame] | 474 | }); |
| 475 | /* *INDENT-ON* */ |
Florin Coras | ba888e4 | 2017-01-24 11:38:18 -0800 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | static void |
Pavel Kotucek | cfb7be8 | 2016-12-21 14:15:37 +0100 | [diff] [blame] | 479 | vl_api_lisp_add_del_map_request_itr_rlocs_t_handler |
| 480 | (vl_api_lisp_add_del_map_request_itr_rlocs_t * mp) |
| 481 | { |
| 482 | vl_api_lisp_add_del_map_request_itr_rlocs_reply_t *rmp; |
| 483 | int rv = 0; |
| 484 | u8 *locator_set_name = NULL; |
| 485 | vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a; |
| 486 | |
Filip Tehlar | 9d286a4 | 2017-10-26 23:57:09 -0700 | [diff] [blame] | 487 | mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0; |
Pavel Kotucek | cfb7be8 | 2016-12-21 14:15:37 +0100 | [diff] [blame] | 488 | locator_set_name = format (0, "%s", mp->locator_set_name); |
Gabriel Ganne | 3491d7f | 2017-10-19 15:10:46 +0200 | [diff] [blame] | 489 | vec_terminate_c_string (locator_set_name); |
Pavel Kotucek | cfb7be8 | 2016-12-21 14:15:37 +0100 | [diff] [blame] | 490 | |
| 491 | a->is_add = mp->is_add; |
| 492 | a->locator_set_name = locator_set_name; |
| 493 | |
| 494 | rv = vnet_lisp_add_del_mreq_itr_rlocs (a); |
| 495 | |
| 496 | vec_free (locator_set_name); |
| 497 | |
| 498 | REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY); |
| 499 | } |
| 500 | |
| 501 | static void |
| 502 | vl_api_lisp_add_del_remote_mapping_t_handler |
| 503 | (vl_api_lisp_add_del_remote_mapping_t * mp) |
| 504 | { |
| 505 | locator_t *rlocs = 0; |
| 506 | vl_api_lisp_add_del_remote_mapping_reply_t *rmp; |
| 507 | int rv = 0; |
| 508 | gid_address_t _eid, *eid = &_eid; |
| 509 | u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num); |
| 510 | |
| 511 | memset (eid, 0, sizeof (eid[0])); |
| 512 | |
| 513 | rv = unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni), |
| 514 | mp->eid_type, mp->eid, mp->eid_len); |
| 515 | if (rv) |
| 516 | goto send_reply; |
| 517 | |
| 518 | rlocs = unformat_lisp_locs (mp->rlocs, rloc_num); |
| 519 | |
| 520 | if (!mp->is_add) |
| 521 | { |
| 522 | vnet_lisp_add_del_adjacency_args_t _a, *a = &_a; |
Dave Barach | 59b2565 | 2017-09-10 15:04:27 -0400 | [diff] [blame] | 523 | memset (a, 0, sizeof (*a)); |
Pavel Kotucek | cfb7be8 | 2016-12-21 14:15:37 +0100 | [diff] [blame] | 524 | gid_address_copy (&a->reid, eid); |
| 525 | a->is_add = 0; |
| 526 | rv = vnet_lisp_add_del_adjacency (a); |
| 527 | if (rv) |
| 528 | { |
| 529 | goto out; |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | /* NOTE: for now this works as a static remote mapping, i.e., |
| 534 | * not authoritative and ttl infinite. */ |
Filip Tehlar | 809bc74 | 2017-08-14 19:15:36 +0200 | [diff] [blame] | 535 | if (mp->is_add) |
| 536 | { |
| 537 | vnet_lisp_add_del_mapping_args_t _m_args, *m_args = &_m_args; |
| 538 | memset (m_args, 0, sizeof (m_args[0])); |
| 539 | gid_address_copy (&m_args->eid, eid); |
| 540 | m_args->action = mp->action; |
| 541 | m_args->is_static = 1; |
| 542 | m_args->ttl = ~0; |
| 543 | m_args->authoritative = 0; |
| 544 | rv = vnet_lisp_add_mapping (m_args, rlocs, NULL, NULL); |
| 545 | } |
| 546 | else |
Dave Barach | 59b2565 | 2017-09-10 15:04:27 -0400 | [diff] [blame] | 547 | { |
| 548 | rv = vnet_lisp_del_mapping (eid, NULL); |
| 549 | } |
Pavel Kotucek | cfb7be8 | 2016-12-21 14:15:37 +0100 | [diff] [blame] | 550 | |
| 551 | if (mp->del_all) |
| 552 | vnet_lisp_clear_all_remote_adjacencies (); |
| 553 | |
| 554 | out: |
| 555 | vec_free (rlocs); |
| 556 | send_reply: |
| 557 | REPLY_MACRO (VL_API_LISP_ADD_DEL_REMOTE_MAPPING_REPLY); |
| 558 | } |
| 559 | |
| 560 | static void |
| 561 | vl_api_lisp_add_del_adjacency_t_handler (vl_api_lisp_add_del_adjacency_t * mp) |
| 562 | { |
| 563 | vl_api_lisp_add_del_adjacency_reply_t *rmp; |
| 564 | vnet_lisp_add_del_adjacency_args_t _a, *a = &_a; |
| 565 | |
| 566 | int rv = 0; |
| 567 | memset (a, 0, sizeof (a[0])); |
| 568 | |
| 569 | rv = unformat_lisp_eid_api (&a->leid, clib_net_to_host_u32 (mp->vni), |
| 570 | mp->eid_type, mp->leid, mp->leid_len); |
| 571 | rv |= unformat_lisp_eid_api (&a->reid, clib_net_to_host_u32 (mp->vni), |
| 572 | mp->eid_type, mp->reid, mp->reid_len); |
| 573 | |
| 574 | if (rv) |
| 575 | goto send_reply; |
| 576 | |
| 577 | a->is_add = mp->is_add; |
| 578 | rv = vnet_lisp_add_del_adjacency (a); |
| 579 | |
| 580 | send_reply: |
| 581 | REPLY_MACRO (VL_API_LISP_ADD_DEL_ADJACENCY_REPLY); |
| 582 | } |
| 583 | |
| 584 | static void |
| 585 | send_lisp_locator_details (lisp_cp_main_t * lcm, |
| 586 | locator_t * loc, |
| 587 | unix_shared_memory_queue_t * q, u32 context) |
| 588 | { |
| 589 | vl_api_lisp_locator_details_t *rmp; |
| 590 | |
| 591 | rmp = vl_msg_api_alloc (sizeof (*rmp)); |
| 592 | memset (rmp, 0, sizeof (*rmp)); |
| 593 | rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_DETAILS); |
| 594 | rmp->context = context; |
| 595 | |
| 596 | rmp->local = loc->local; |
| 597 | if (loc->local) |
| 598 | { |
| 599 | rmp->sw_if_index = ntohl (loc->sw_if_index); |
| 600 | } |
| 601 | else |
| 602 | { |
| 603 | rmp->is_ipv6 = gid_address_ip_version (&loc->address); |
| 604 | ip_address_copy_addr (rmp->ip_address, &gid_address_ip (&loc->address)); |
| 605 | } |
| 606 | rmp->priority = loc->priority; |
| 607 | rmp->weight = loc->weight; |
| 608 | |
| 609 | vl_msg_api_send_shmem (q, (u8 *) & rmp); |
| 610 | } |
| 611 | |
| 612 | static void |
| 613 | vl_api_lisp_locator_dump_t_handler (vl_api_lisp_locator_dump_t * mp) |
| 614 | { |
| 615 | u8 *ls_name = 0; |
| 616 | unix_shared_memory_queue_t *q = 0; |
| 617 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 618 | locator_set_t *lsit = 0; |
| 619 | locator_t *loc = 0; |
| 620 | u32 ls_index = ~0, *locit = 0; |
| 621 | uword *p = 0; |
| 622 | |
| 623 | q = vl_api_client_index_to_input_queue (mp->client_index); |
| 624 | if (q == 0) |
| 625 | { |
| 626 | return; |
| 627 | } |
| 628 | |
| 629 | if (mp->is_index_set) |
| 630 | ls_index = htonl (mp->ls_index); |
| 631 | else |
| 632 | { |
| 633 | /* make sure we get a proper C-string */ |
| 634 | mp->ls_name[sizeof (mp->ls_name) - 1] = 0; |
| 635 | ls_name = format (0, "%s", mp->ls_name); |
Gabriel Ganne | 3491d7f | 2017-10-19 15:10:46 +0200 | [diff] [blame] | 636 | vec_terminate_c_string (ls_name); |
Pavel Kotucek | cfb7be8 | 2016-12-21 14:15:37 +0100 | [diff] [blame] | 637 | p = hash_get_mem (lcm->locator_set_index_by_name, ls_name); |
| 638 | if (!p) |
| 639 | goto out; |
| 640 | ls_index = p[0]; |
| 641 | } |
| 642 | |
| 643 | if (pool_is_free_index (lcm->locator_set_pool, ls_index)) |
| 644 | return; |
| 645 | |
| 646 | lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index); |
| 647 | |
| 648 | vec_foreach (locit, lsit->locator_indices) |
| 649 | { |
| 650 | loc = pool_elt_at_index (lcm->locator_pool, locit[0]); |
| 651 | send_lisp_locator_details (lcm, loc, q, mp->context); |
| 652 | }; |
| 653 | out: |
| 654 | vec_free (ls_name); |
| 655 | } |
| 656 | |
| 657 | static void |
| 658 | send_lisp_locator_set_details (lisp_cp_main_t * lcm, |
| 659 | locator_set_t * lsit, |
| 660 | unix_shared_memory_queue_t * q, |
| 661 | u32 context, u32 ls_index) |
| 662 | { |
| 663 | vl_api_lisp_locator_set_details_t *rmp; |
| 664 | u8 *str = 0; |
| 665 | |
| 666 | rmp = vl_msg_api_alloc (sizeof (*rmp)); |
| 667 | memset (rmp, 0, sizeof (*rmp)); |
| 668 | rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_SET_DETAILS); |
| 669 | rmp->context = context; |
| 670 | |
| 671 | rmp->ls_index = htonl (ls_index); |
| 672 | if (lsit->local) |
| 673 | { |
| 674 | ASSERT (lsit->name != NULL); |
| 675 | strncpy ((char *) rmp->ls_name, (char *) lsit->name, |
| 676 | vec_len (lsit->name)); |
| 677 | } |
| 678 | else |
| 679 | { |
| 680 | str = format (0, "<remote-%d>", ls_index); |
| 681 | strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str)); |
| 682 | vec_free (str); |
| 683 | } |
| 684 | |
| 685 | vl_msg_api_send_shmem (q, (u8 *) & rmp); |
| 686 | } |
| 687 | |
| 688 | static void |
| 689 | vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t * mp) |
| 690 | { |
| 691 | unix_shared_memory_queue_t *q = NULL; |
| 692 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 693 | locator_set_t *lsit = NULL; |
| 694 | u8 filter; |
| 695 | |
| 696 | q = vl_api_client_index_to_input_queue (mp->client_index); |
| 697 | if (q == 0) |
| 698 | { |
| 699 | return; |
| 700 | } |
| 701 | |
| 702 | filter = mp->filter; |
| 703 | /* *INDENT-OFF* */ |
| 704 | pool_foreach (lsit, lcm->locator_set_pool, |
| 705 | ({ |
| 706 | if (filter && !((1 == filter && lsit->local) || |
| 707 | (2 == filter && !lsit->local))) |
| 708 | { |
| 709 | continue; |
| 710 | } |
| 711 | send_lisp_locator_set_details (lcm, lsit, q, mp->context, |
| 712 | lsit - lcm->locator_set_pool); |
| 713 | })); |
| 714 | /* *INDENT-ON* */ |
| 715 | } |
| 716 | |
| 717 | static void |
| 718 | lisp_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length) |
| 719 | { |
| 720 | ASSERT (prefix_length); |
| 721 | ip_prefix_t *ippref = &fid_addr_ippref (src); |
| 722 | |
| 723 | switch (fid_addr_type (src)) |
| 724 | { |
| 725 | case FID_ADDR_IP_PREF: |
| 726 | if (ip_prefix_version (ippref) == IP4) |
| 727 | clib_memcpy (dst, &ip_prefix_v4 (ippref), 4); |
| 728 | else |
| 729 | clib_memcpy (dst, &ip_prefix_v6 (ippref), 16); |
| 730 | prefix_length[0] = ip_prefix_len (ippref); |
| 731 | break; |
| 732 | |
| 733 | case FID_ADDR_MAC: |
| 734 | prefix_length[0] = 0; |
| 735 | clib_memcpy (dst, fid_addr_mac (src), 6); |
| 736 | break; |
| 737 | |
| 738 | default: |
| 739 | clib_warning ("Unknown FID type %d!", fid_addr_type (src)); |
| 740 | break; |
| 741 | } |
| 742 | } |
| 743 | |
| 744 | static u8 |
| 745 | fid_type_to_api_type (fid_address_t * fid) |
| 746 | { |
| 747 | ip_prefix_t *ippref; |
| 748 | |
| 749 | switch (fid_addr_type (fid)) |
| 750 | { |
| 751 | case FID_ADDR_IP_PREF: |
| 752 | ippref = &fid_addr_ippref (fid); |
| 753 | if (ip_prefix_version (ippref) == IP4) |
| 754 | return 0; |
| 755 | else if (ip_prefix_version (ippref) == IP6) |
| 756 | return 1; |
| 757 | else |
| 758 | return ~0; |
| 759 | |
| 760 | case FID_ADDR_MAC: |
| 761 | return 2; |
Florin Coras | ce1b4c7 | 2017-01-26 14:25:34 -0800 | [diff] [blame] | 762 | case FID_ADDR_NSH: |
| 763 | return 3; |
Pavel Kotucek | cfb7be8 | 2016-12-21 14:15:37 +0100 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | return ~0; |
| 767 | } |
| 768 | |
| 769 | static void |
| 770 | send_lisp_eid_table_details (mapping_t * mapit, |
| 771 | unix_shared_memory_queue_t * q, |
| 772 | u32 context, u8 filter) |
| 773 | { |
| 774 | fid_address_t *fid; |
| 775 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 776 | locator_set_t *ls = 0; |
| 777 | vl_api_lisp_eid_table_details_t *rmp = NULL; |
| 778 | gid_address_t *gid = NULL; |
| 779 | u8 *mac = 0; |
| 780 | ip_prefix_t *ip_prefix = NULL; |
| 781 | |
| 782 | switch (filter) |
| 783 | { |
| 784 | case 0: /* all mappings */ |
| 785 | break; |
| 786 | |
| 787 | case 1: /* local only */ |
| 788 | if (!mapit->local) |
| 789 | return; |
| 790 | break; |
| 791 | case 2: /* remote only */ |
| 792 | if (mapit->local) |
| 793 | return; |
| 794 | break; |
| 795 | default: |
| 796 | clib_warning ("Filter error, unknown filter: %d", filter); |
| 797 | return; |
| 798 | } |
| 799 | |
Filip Tehlar | 38206ee | 2017-02-20 17:31:57 +0100 | [diff] [blame] | 800 | /* don't send PITR generated mapping */ |
| 801 | if (mapit->pitr_set) |
| 802 | return; |
| 803 | |
Pavel Kotucek | cfb7be8 | 2016-12-21 14:15:37 +0100 | [diff] [blame] | 804 | gid = &mapit->eid; |
| 805 | ip_prefix = &gid_address_ippref (gid); |
| 806 | mac = gid_address_mac (gid); |
| 807 | |
| 808 | rmp = vl_msg_api_alloc (sizeof (*rmp)); |
| 809 | memset (rmp, 0, sizeof (*rmp)); |
| 810 | rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_DETAILS); |
| 811 | |
| 812 | ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index); |
| 813 | if (vec_len (ls->locator_indices) == 0) |
| 814 | rmp->locator_set_index = ~0; |
| 815 | else |
| 816 | rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index); |
| 817 | |
| 818 | rmp->is_local = mapit->local; |
| 819 | rmp->ttl = clib_host_to_net_u32 (mapit->ttl); |
| 820 | rmp->action = mapit->action; |
| 821 | rmp->authoritative = mapit->authoritative; |
| 822 | |
| 823 | switch (gid_address_type (gid)) |
| 824 | { |
| 825 | case GID_ADDR_SRC_DST: |
| 826 | rmp->is_src_dst = 1; |
| 827 | fid = &gid_address_sd_src (gid); |
| 828 | rmp->eid_type = fid_type_to_api_type (fid); |
| 829 | lisp_fid_put_api (rmp->seid, &gid_address_sd_src (gid), |
| 830 | &rmp->seid_prefix_len); |
| 831 | lisp_fid_put_api (rmp->eid, &gid_address_sd_dst (gid), |
| 832 | &rmp->eid_prefix_len); |
| 833 | break; |
| 834 | case GID_ADDR_IP_PREFIX: |
| 835 | rmp->eid_prefix_len = ip_prefix_len (ip_prefix); |
| 836 | if (ip_prefix_version (ip_prefix) == IP4) |
| 837 | { |
| 838 | rmp->eid_type = 0; /* ipv4 type */ |
| 839 | clib_memcpy (rmp->eid, &ip_prefix_v4 (ip_prefix), |
| 840 | sizeof (ip_prefix_v4 (ip_prefix))); |
| 841 | } |
| 842 | else |
| 843 | { |
| 844 | rmp->eid_type = 1; /* ipv6 type */ |
| 845 | clib_memcpy (rmp->eid, &ip_prefix_v6 (ip_prefix), |
| 846 | sizeof (ip_prefix_v6 (ip_prefix))); |
| 847 | } |
| 848 | break; |
| 849 | case GID_ADDR_MAC: |
| 850 | rmp->eid_type = 2; /* l2 mac type */ |
| 851 | clib_memcpy (rmp->eid, mac, 6); |
| 852 | break; |
| 853 | default: |
| 854 | ASSERT (0); |
| 855 | } |
| 856 | rmp->context = context; |
| 857 | rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid)); |
| 858 | rmp->key_id = clib_host_to_net_u16 (mapit->key_id); |
| 859 | memcpy (rmp->key, mapit->key, vec_len (mapit->key)); |
| 860 | vl_msg_api_send_shmem (q, (u8 *) & rmp); |
| 861 | } |
| 862 | |
| 863 | static void |
| 864 | vl_api_lisp_eid_table_dump_t_handler (vl_api_lisp_eid_table_dump_t * mp) |
| 865 | { |
| 866 | u32 mi; |
| 867 | unix_shared_memory_queue_t *q = NULL; |
| 868 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 869 | mapping_t *mapit = NULL; |
| 870 | gid_address_t _eid, *eid = &_eid; |
| 871 | |
| 872 | q = vl_api_client_index_to_input_queue (mp->client_index); |
| 873 | if (q == 0) |
| 874 | { |
| 875 | return; |
| 876 | } |
| 877 | |
| 878 | if (mp->eid_set) |
| 879 | { |
| 880 | memset (eid, 0, sizeof (*eid)); |
| 881 | |
| 882 | unformat_lisp_eid_api (eid, clib_net_to_host_u32 (mp->vni), |
| 883 | mp->eid_type, mp->eid, mp->prefix_length); |
| 884 | |
| 885 | mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid); |
| 886 | if ((u32) ~ 0 == mi) |
| 887 | return; |
| 888 | |
| 889 | mapit = pool_elt_at_index (lcm->mapping_pool, mi); |
| 890 | send_lisp_eid_table_details (mapit, q, mp->context, |
| 891 | 0 /* ignore filter */ ); |
| 892 | } |
| 893 | else |
| 894 | { |
| 895 | /* *INDENT-OFF* */ |
| 896 | pool_foreach (mapit, lcm->mapping_pool, |
| 897 | ({ |
| 898 | send_lisp_eid_table_details(mapit, q, mp->context, |
| 899 | mp->filter); |
| 900 | })); |
| 901 | /* *INDENT-ON* */ |
| 902 | } |
| 903 | } |
| 904 | |
| 905 | static void |
| 906 | send_lisp_map_server_details (ip_address_t * ip, |
| 907 | unix_shared_memory_queue_t * q, u32 context) |
| 908 | { |
| 909 | vl_api_lisp_map_server_details_t *rmp = NULL; |
| 910 | |
| 911 | rmp = vl_msg_api_alloc (sizeof (*rmp)); |
| 912 | memset (rmp, 0, sizeof (*rmp)); |
| 913 | rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_SERVER_DETAILS); |
| 914 | |
| 915 | switch (ip_addr_version (ip)) |
| 916 | { |
| 917 | case IP4: |
| 918 | rmp->is_ipv6 = 0; |
| 919 | clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip), |
| 920 | sizeof (ip_addr_v4 (ip))); |
| 921 | break; |
| 922 | |
| 923 | case IP6: |
| 924 | rmp->is_ipv6 = 1; |
| 925 | clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip), |
| 926 | sizeof (ip_addr_v6 (ip))); |
| 927 | break; |
| 928 | |
| 929 | default: |
| 930 | ASSERT (0); |
| 931 | } |
| 932 | rmp->context = context; |
| 933 | |
| 934 | vl_msg_api_send_shmem (q, (u8 *) & rmp); |
| 935 | } |
| 936 | |
| 937 | static void |
| 938 | vl_api_lisp_map_server_dump_t_handler (vl_api_lisp_map_server_dump_t * mp) |
| 939 | { |
| 940 | unix_shared_memory_queue_t *q = NULL; |
| 941 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 942 | lisp_msmr_t *mr; |
| 943 | |
| 944 | q = vl_api_client_index_to_input_queue (mp->client_index); |
| 945 | if (q == 0) |
| 946 | { |
| 947 | return; |
| 948 | } |
| 949 | |
| 950 | vec_foreach (mr, lcm->map_servers) |
| 951 | { |
| 952 | send_lisp_map_server_details (&mr->address, q, mp->context); |
| 953 | } |
| 954 | } |
| 955 | |
| 956 | static void |
| 957 | send_lisp_map_resolver_details (ip_address_t * ip, |
| 958 | unix_shared_memory_queue_t * q, u32 context) |
| 959 | { |
| 960 | vl_api_lisp_map_resolver_details_t *rmp = NULL; |
| 961 | |
| 962 | rmp = vl_msg_api_alloc (sizeof (*rmp)); |
| 963 | memset (rmp, 0, sizeof (*rmp)); |
| 964 | rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_RESOLVER_DETAILS); |
| 965 | |
| 966 | switch (ip_addr_version (ip)) |
| 967 | { |
| 968 | case IP4: |
| 969 | rmp->is_ipv6 = 0; |
| 970 | clib_memcpy (rmp->ip_address, &ip_addr_v4 (ip), |
| 971 | sizeof (ip_addr_v4 (ip))); |
| 972 | break; |
| 973 | |
| 974 | case IP6: |
| 975 | rmp->is_ipv6 = 1; |
| 976 | clib_memcpy (rmp->ip_address, &ip_addr_v6 (ip), |
| 977 | sizeof (ip_addr_v6 (ip))); |
| 978 | break; |
| 979 | |
| 980 | default: |
| 981 | ASSERT (0); |
| 982 | } |
| 983 | rmp->context = context; |
| 984 | |
| 985 | vl_msg_api_send_shmem (q, (u8 *) & rmp); |
| 986 | } |
| 987 | |
| 988 | static void |
| 989 | vl_api_lisp_map_resolver_dump_t_handler (vl_api_lisp_map_resolver_dump_t * mp) |
| 990 | { |
| 991 | unix_shared_memory_queue_t *q = NULL; |
| 992 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 993 | lisp_msmr_t *mr; |
| 994 | |
| 995 | q = vl_api_client_index_to_input_queue (mp->client_index); |
| 996 | if (q == 0) |
| 997 | { |
| 998 | return; |
| 999 | } |
| 1000 | |
| 1001 | vec_foreach (mr, lcm->map_resolvers) |
| 1002 | { |
| 1003 | send_lisp_map_resolver_details (&mr->address, q, mp->context); |
| 1004 | } |
| 1005 | } |
| 1006 | |
| 1007 | static void |
| 1008 | send_eid_table_map_pair (hash_pair_t * p, |
| 1009 | unix_shared_memory_queue_t * q, u32 context) |
| 1010 | { |
| 1011 | vl_api_lisp_eid_table_map_details_t *rmp = NULL; |
| 1012 | |
| 1013 | rmp = vl_msg_api_alloc (sizeof (*rmp)); |
| 1014 | memset (rmp, 0, sizeof (*rmp)); |
| 1015 | rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_MAP_DETAILS); |
| 1016 | |
| 1017 | rmp->vni = clib_host_to_net_u32 (p->key); |
| 1018 | rmp->dp_table = clib_host_to_net_u32 (p->value[0]); |
| 1019 | rmp->context = context; |
| 1020 | vl_msg_api_send_shmem (q, (u8 *) & rmp); |
| 1021 | } |
| 1022 | |
| 1023 | static void |
| 1024 | vl_api_lisp_eid_table_map_dump_t_handler (vl_api_lisp_eid_table_map_dump_t * |
| 1025 | mp) |
| 1026 | { |
| 1027 | unix_shared_memory_queue_t *q = NULL; |
| 1028 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 1029 | hash_pair_t *p; |
| 1030 | uword *vni_table = 0; |
| 1031 | |
| 1032 | q = vl_api_client_index_to_input_queue (mp->client_index); |
| 1033 | if (q == 0) |
| 1034 | { |
| 1035 | return; |
| 1036 | } |
| 1037 | |
| 1038 | if (mp->is_l2) |
| 1039 | { |
| 1040 | vni_table = lcm->bd_id_by_vni; |
| 1041 | } |
| 1042 | else |
| 1043 | { |
| 1044 | vni_table = lcm->table_id_by_vni; |
| 1045 | } |
| 1046 | |
| 1047 | /* *INDENT-OFF* */ |
| 1048 | hash_foreach_pair (p, vni_table, |
| 1049 | ({ |
| 1050 | send_eid_table_map_pair (p, q, mp->context); |
| 1051 | })); |
| 1052 | /* *INDENT-ON* */ |
| 1053 | } |
| 1054 | |
| 1055 | static void |
| 1056 | send_eid_table_vni (u32 vni, unix_shared_memory_queue_t * q, u32 context) |
| 1057 | { |
| 1058 | vl_api_lisp_eid_table_vni_details_t *rmp = 0; |
| 1059 | |
| 1060 | rmp = vl_msg_api_alloc (sizeof (*rmp)); |
| 1061 | memset (rmp, 0, sizeof (*rmp)); |
| 1062 | rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_VNI_DETAILS); |
| 1063 | rmp->context = context; |
| 1064 | rmp->vni = clib_host_to_net_u32 (vni); |
| 1065 | vl_msg_api_send_shmem (q, (u8 *) & rmp); |
| 1066 | } |
| 1067 | |
| 1068 | static void |
| 1069 | lisp_adjacency_copy (vl_api_lisp_adjacency_t * dst, lisp_adjacency_t * adjs) |
| 1070 | { |
| 1071 | lisp_adjacency_t *adj; |
| 1072 | vl_api_lisp_adjacency_t a; |
| 1073 | u32 i, n = vec_len (adjs); |
| 1074 | |
| 1075 | for (i = 0; i < n; i++) |
| 1076 | { |
| 1077 | adj = vec_elt_at_index (adjs, i); |
| 1078 | memset (&a, 0, sizeof (a)); |
| 1079 | |
| 1080 | switch (gid_address_type (&adj->reid)) |
| 1081 | { |
| 1082 | case GID_ADDR_IP_PREFIX: |
| 1083 | a.reid_prefix_len = gid_address_ippref_len (&adj->reid); |
| 1084 | a.leid_prefix_len = gid_address_ippref_len (&adj->leid); |
| 1085 | if (gid_address_ip_version (&adj->reid) == IP4) |
| 1086 | { |
| 1087 | a.eid_type = 0; /* ipv4 type */ |
| 1088 | clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 4); |
| 1089 | clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 4); |
| 1090 | } |
| 1091 | else |
| 1092 | { |
| 1093 | a.eid_type = 1; /* ipv6 type */ |
| 1094 | clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 16); |
| 1095 | clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 16); |
| 1096 | } |
| 1097 | break; |
| 1098 | case GID_ADDR_MAC: |
| 1099 | a.eid_type = 2; /* l2 mac type */ |
| 1100 | mac_copy (a.reid, gid_address_mac (&adj->reid)); |
| 1101 | mac_copy (a.leid, gid_address_mac (&adj->leid)); |
| 1102 | break; |
| 1103 | default: |
| 1104 | ASSERT (0); |
| 1105 | } |
| 1106 | dst[i] = a; |
| 1107 | } |
| 1108 | } |
| 1109 | |
| 1110 | static void |
| 1111 | vl_api_show_lisp_rloc_probe_state_t_handler |
| 1112 | (vl_api_show_lisp_rloc_probe_state_t * mp) |
| 1113 | { |
| 1114 | vl_api_show_lisp_rloc_probe_state_reply_t *rmp = 0; |
| 1115 | int rv = 0; |
| 1116 | |
| 1117 | /* *INDENT-OFF* */ |
| 1118 | REPLY_MACRO2 (VL_API_SHOW_LISP_RLOC_PROBE_STATE_REPLY, |
| 1119 | { |
| 1120 | rmp->is_enabled = vnet_lisp_rloc_probe_state_get (); |
| 1121 | }); |
| 1122 | /* *INDENT-ON* */ |
| 1123 | } |
| 1124 | |
| 1125 | static void |
| 1126 | vl_api_show_lisp_map_register_state_t_handler |
| 1127 | (vl_api_show_lisp_map_register_state_t * mp) |
| 1128 | { |
| 1129 | vl_api_show_lisp_map_register_state_reply_t *rmp = 0; |
| 1130 | int rv = 0; |
| 1131 | |
| 1132 | /* *INDENT-OFF* */ |
| 1133 | REPLY_MACRO2 (VL_API_SHOW_LISP_MAP_REGISTER_STATE_REPLY, |
| 1134 | { |
| 1135 | rmp->is_enabled = vnet_lisp_map_register_state_get (); |
| 1136 | }); |
| 1137 | /* *INDENT-ON* */ |
| 1138 | } |
| 1139 | |
| 1140 | static void |
| 1141 | vl_api_lisp_adjacencies_get_t_handler (vl_api_lisp_adjacencies_get_t * mp) |
| 1142 | { |
| 1143 | vl_api_lisp_adjacencies_get_reply_t *rmp = 0; |
| 1144 | lisp_adjacency_t *adjs = 0; |
| 1145 | int rv = 0; |
Pavel Kotucek | cfb7be8 | 2016-12-21 14:15:37 +0100 | [diff] [blame] | 1146 | u32 size = ~0; |
| 1147 | u32 vni = clib_net_to_host_u32 (mp->vni); |
| 1148 | |
| 1149 | adjs = vnet_lisp_adjacencies_get_by_vni (vni); |
Filip Tehlar | 5fae99c | 2017-01-18 12:57:37 +0100 | [diff] [blame] | 1150 | size = vec_len (adjs) * sizeof (vl_api_lisp_adjacency_t); |
Pavel Kotucek | cfb7be8 | 2016-12-21 14:15:37 +0100 | [diff] [blame] | 1151 | |
| 1152 | /* *INDENT-OFF* */ |
| 1153 | REPLY_MACRO4 (VL_API_LISP_ADJACENCIES_GET_REPLY, size, |
| 1154 | { |
| 1155 | rmp->count = clib_host_to_net_u32 (vec_len (adjs)); |
| 1156 | lisp_adjacency_copy (rmp->adjacencies, adjs); |
| 1157 | }); |
| 1158 | /* *INDENT-ON* */ |
| 1159 | |
| 1160 | vec_free (adjs); |
| 1161 | } |
| 1162 | |
| 1163 | static void |
| 1164 | vl_api_lisp_eid_table_vni_dump_t_handler (vl_api_lisp_eid_table_vni_dump_t * |
| 1165 | mp) |
| 1166 | { |
| 1167 | hash_pair_t *p; |
| 1168 | u32 *vnis = 0; |
| 1169 | unix_shared_memory_queue_t *q = 0; |
| 1170 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 1171 | |
| 1172 | q = vl_api_client_index_to_input_queue (mp->client_index); |
| 1173 | if (q == 0) |
| 1174 | { |
| 1175 | return; |
| 1176 | } |
| 1177 | |
| 1178 | /* *INDENT-OFF* */ |
| 1179 | hash_foreach_pair (p, lcm->table_id_by_vni, |
| 1180 | ({ |
| 1181 | hash_set (vnis, p->key, 0); |
| 1182 | })); |
| 1183 | |
| 1184 | hash_foreach_pair (p, lcm->bd_id_by_vni, |
| 1185 | ({ |
| 1186 | hash_set (vnis, p->key, 0); |
| 1187 | })); |
| 1188 | |
| 1189 | hash_foreach_pair (p, vnis, |
| 1190 | ({ |
| 1191 | send_eid_table_vni (p->key, q, mp->context); |
| 1192 | })); |
| 1193 | /* *INDENT-ON* */ |
| 1194 | |
| 1195 | hash_free (vnis); |
| 1196 | } |
| 1197 | |
| 1198 | static void |
| 1199 | vl_api_show_lisp_status_t_handler (vl_api_show_lisp_status_t * mp) |
| 1200 | { |
| 1201 | unix_shared_memory_queue_t *q = NULL; |
| 1202 | vl_api_show_lisp_status_reply_t *rmp = NULL; |
| 1203 | int rv = 0; |
| 1204 | |
| 1205 | q = vl_api_client_index_to_input_queue (mp->client_index); |
| 1206 | if (q == 0) |
| 1207 | { |
| 1208 | return; |
| 1209 | } |
| 1210 | |
| 1211 | /* *INDENT-OFF* */ |
| 1212 | REPLY_MACRO2(VL_API_SHOW_LISP_STATUS_REPLY, |
| 1213 | ({ |
| 1214 | rmp->gpe_status = vnet_lisp_gpe_enable_disable_status (); |
| 1215 | rmp->feature_status = vnet_lisp_enable_disable_status (); |
| 1216 | })); |
| 1217 | /* *INDENT-ON* */ |
| 1218 | } |
| 1219 | |
| 1220 | static void |
| 1221 | vl_api_lisp_get_map_request_itr_rlocs_t_handler |
| 1222 | (vl_api_lisp_get_map_request_itr_rlocs_t * mp) |
| 1223 | { |
| 1224 | unix_shared_memory_queue_t *q = NULL; |
| 1225 | vl_api_lisp_get_map_request_itr_rlocs_reply_t *rmp = NULL; |
| 1226 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 1227 | locator_set_t *loc_set = 0; |
| 1228 | u8 *tmp_str = 0; |
| 1229 | int rv = 0; |
| 1230 | |
| 1231 | q = vl_api_client_index_to_input_queue (mp->client_index); |
| 1232 | if (q == 0) |
| 1233 | { |
| 1234 | return; |
| 1235 | } |
| 1236 | |
| 1237 | if (~0 == lcm->mreq_itr_rlocs) |
| 1238 | { |
| 1239 | tmp_str = format (0, " "); |
| 1240 | } |
| 1241 | else |
| 1242 | { |
| 1243 | loc_set = |
| 1244 | pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs); |
| 1245 | tmp_str = format (0, "%s", loc_set->name); |
| 1246 | } |
| 1247 | |
| 1248 | /* *INDENT-OFF* */ |
| 1249 | REPLY_MACRO2(VL_API_LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY, |
| 1250 | ({ |
| 1251 | strncpy((char *) rmp->locator_set_name, (char *) tmp_str, |
| 1252 | ARRAY_LEN(rmp->locator_set_name) - 1); |
| 1253 | })); |
| 1254 | /* *INDENT-ON* */ |
| 1255 | |
| 1256 | vec_free (tmp_str); |
| 1257 | } |
| 1258 | |
| 1259 | static void |
| 1260 | vl_api_show_lisp_pitr_t_handler (vl_api_show_lisp_pitr_t * mp) |
| 1261 | { |
| 1262 | unix_shared_memory_queue_t *q = NULL; |
| 1263 | vl_api_show_lisp_pitr_reply_t *rmp = NULL; |
| 1264 | lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); |
| 1265 | mapping_t *m; |
| 1266 | locator_set_t *ls = 0; |
| 1267 | u8 *tmp_str = 0; |
| 1268 | int rv = 0; |
| 1269 | |
| 1270 | q = vl_api_client_index_to_input_queue (mp->client_index); |
| 1271 | if (q == 0) |
| 1272 | { |
| 1273 | return; |
| 1274 | } |
| 1275 | |
Filip Tehlar | 0a8840d | 2017-10-16 05:48:23 -0700 | [diff] [blame] | 1276 | u8 is_enabled = (lcm->flags & LISP_FLAG_PITR_MODE) |
| 1277 | && lcm->pitr_map_index != ~0; |
| 1278 | |
| 1279 | if (!is_enabled) |
Pavel Kotucek | cfb7be8 | 2016-12-21 14:15:37 +0100 | [diff] [blame] | 1280 | { |
| 1281 | tmp_str = format (0, "N/A"); |
| 1282 | } |
| 1283 | else |
| 1284 | { |
| 1285 | m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index); |
| 1286 | if (~0 != m->locator_set_index) |
| 1287 | { |
| 1288 | ls = |
| 1289 | pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index); |
| 1290 | tmp_str = format (0, "%s", ls->name); |
| 1291 | } |
| 1292 | else |
| 1293 | { |
| 1294 | tmp_str = format (0, "N/A"); |
| 1295 | } |
| 1296 | } |
| 1297 | vec_add1 (tmp_str, 0); |
| 1298 | |
| 1299 | /* *INDENT-OFF* */ |
| 1300 | REPLY_MACRO2(VL_API_SHOW_LISP_PITR_REPLY, |
| 1301 | ({ |
Filip Tehlar | 0a8840d | 2017-10-16 05:48:23 -0700 | [diff] [blame] | 1302 | rmp->status = lcm->flags & LISP_FLAG_PITR_MODE; |
Pavel Kotucek | cfb7be8 | 2016-12-21 14:15:37 +0100 | [diff] [blame] | 1303 | strncpy((char *) rmp->locator_set_name, (char *) tmp_str, |
| 1304 | ARRAY_LEN(rmp->locator_set_name) - 1); |
| 1305 | })); |
| 1306 | /* *INDENT-ON* */ |
| 1307 | } |
| 1308 | |
| 1309 | /* |
| 1310 | * lisp_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_lisp; |
Pavel Kotucek | cfb7be8 | 2016-12-21 14:15:37 +0100 | [diff] [blame] | 1325 | #undef _ |
| 1326 | } |
| 1327 | |
| 1328 | static clib_error_t * |
| 1329 | lisp_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 (lisp_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 | */ |