From 2b202bc4b2d870d76bfe6fb1906ae62e253cec72 Mon Sep 17 00:00:00 2001 From: Neale Ranns Date: Mon, 21 Sep 2020 08:17:51 +0000 Subject: lisp: Move to plugin Type: refactor Change-Id: I54df533a8f863c4e49742903cf2457f18b4fc506 Signed-off-by: Neale Ranns --- src/plugins/lisp/CMakeLists.txt | 79 + src/plugins/lisp/lisp-cp/FEATURE.yaml | 14 + src/plugins/lisp/lisp-cp/control.c | 5031 ++++++ src/plugins/lisp/lisp-cp/control.h | 448 + src/plugins/lisp/lisp-cp/gid_dictionary.c | 1077 ++ src/plugins/lisp/lisp-cp/gid_dictionary.h | 161 + src/plugins/lisp/lisp-cp/lisp.api | 674 + src/plugins/lisp/lisp-cp/lisp_api.c | 1068 ++ src/plugins/lisp/lisp-cp/lisp_cli.c | 1603 ++ src/plugins/lisp/lisp-cp/lisp_cp_dpo.c | 122 + src/plugins/lisp/lisp-cp/lisp_cp_dpo.h | 45 + src/plugins/lisp/lisp-cp/lisp_cp_messages.h | 644 + src/plugins/lisp/lisp-cp/lisp_cp_test.c | 2052 +++ src/plugins/lisp/lisp-cp/lisp_msg_serdes.c | 381 + src/plugins/lisp/lisp-cp/lisp_msg_serdes.h | 58 + src/plugins/lisp/lisp-cp/lisp_test.c | 45 + src/plugins/lisp/lisp-cp/lisp_types.api | 75 + src/plugins/lisp/lisp-cp/lisp_types.c | 1488 ++ src/plugins/lisp/lisp-cp/lisp_types.h | 350 + src/plugins/lisp/lisp-cp/lisp_types_api.c | 88 + src/plugins/lisp/lisp-cp/lisp_types_api.h | 26 + src/plugins/lisp/lisp-cp/one.api | 1031 ++ src/plugins/lisp/lisp-cp/one_api.c | 1705 ++ src/plugins/lisp/lisp-cp/one_cli.c | 2340 +++ src/plugins/lisp/lisp-cp/one_test.c | 3101 ++++ src/plugins/lisp/lisp-cp/packets.c | 226 + src/plugins/lisp/lisp-cp/packets.h | 38 + src/plugins/lisp/lisp-gpe/FEATURE.yaml | 11 + src/plugins/lisp/lisp-gpe/decap.c | 605 + src/plugins/lisp/lisp-gpe/dir.dox | 26 + src/plugins/lisp/lisp-gpe/interface.c | 945 + src/plugins/lisp/lisp-gpe/lisp_gpe.api | 237 + src/plugins/lisp/lisp-gpe/lisp_gpe.c | 728 + src/plugins/lisp/lisp-gpe/lisp_gpe.h | 339 + src/plugins/lisp/lisp-gpe/lisp_gpe_adjacency.c | 604 + src/plugins/lisp/lisp-gpe/lisp_gpe_adjacency.h | 136 + src/plugins/lisp/lisp-gpe/lisp_gpe_api.c | 506 + src/plugins/lisp/lisp-gpe/lisp_gpe_error.def | 18 + src/plugins/lisp/lisp-gpe/lisp_gpe_fwd_entry.c | 1595 ++ src/plugins/lisp/lisp-gpe/lisp_gpe_fwd_entry.h | 240 + src/plugins/lisp/lisp-gpe/lisp_gpe_packet.h | 149 + src/plugins/lisp/lisp-gpe/lisp_gpe_sub_interface.c | 286 + src/plugins/lisp/lisp-gpe/lisp_gpe_sub_interface.h | 157 + src/plugins/lisp/lisp-gpe/lisp_gpe_tenant.c | 333 + src/plugins/lisp/lisp-gpe/lisp_gpe_tenant.h | 89 + src/plugins/lisp/lisp-gpe/lisp_gpe_test.c | 888 + src/plugins/lisp/lisp-gpe/lisp_gpe_tunnel.c | 293 + src/plugins/lisp/lisp-gpe/lisp_gpe_tunnel.h | 89 + src/plugins/lisp/lisp-gpe/lisp_types_api.c | 1 + src/plugins/lisp/lisp-gpe/lisp_types_api.h | 1 + src/plugins/lisp/lisp-gpe/rfc.txt | 826 + src/plugins/lisp/test/lisp_cp_test.c | 1442 ++ src/plugins/lisp/test/test_lisp.py | 208 + src/plugins/nsh/nsh-md2-ioam/md2_ioam_transit.c | 3 +- src/plugins/nsh/nsh-md2-ioam/nsh_md2_ioam_util.h | 3 +- src/plugins/unittest/CMakeLists.txt | 1 - src/plugins/unittest/lisp_cp_test.c | 1432 -- src/vat/api_format.c | 17714 +++++++------------ src/vnet/CMakeLists.txt | 58 - src/vnet/lisp-cp/FEATURE.yaml | 14 - src/vnet/lisp-cp/control.c | 5033 ------ src/vnet/lisp-cp/control.h | 448 - src/vnet/lisp-cp/gid_dictionary.c | 1077 -- src/vnet/lisp-cp/gid_dictionary.h | 161 - src/vnet/lisp-cp/lisp.api | 674 - src/vnet/lisp-cp/lisp_api.c | 1134 -- src/vnet/lisp-cp/lisp_cli.c | 1603 -- src/vnet/lisp-cp/lisp_cp_dpo.c | 122 - src/vnet/lisp-cp/lisp_cp_dpo.h | 45 - src/vnet/lisp-cp/lisp_cp_messages.h | 644 - src/vnet/lisp-cp/lisp_msg_serdes.c | 381 - src/vnet/lisp-cp/lisp_msg_serdes.h | 58 - src/vnet/lisp-cp/lisp_types.api | 75 - src/vnet/lisp-cp/lisp_types.c | 1488 -- src/vnet/lisp-cp/lisp_types.h | 350 - src/vnet/lisp-cp/lisp_types_api.c | 88 - src/vnet/lisp-cp/lisp_types_api.h | 26 - src/vnet/lisp-cp/one.api | 1031 -- src/vnet/lisp-cp/one_api.c | 1741 -- src/vnet/lisp-cp/one_cli.c | 2340 --- src/vnet/lisp-cp/packets.c | 226 - src/vnet/lisp-cp/packets.h | 38 - src/vnet/lisp-gpe/FEATURE.yaml | 11 - src/vnet/lisp-gpe/decap.c | 605 - src/vnet/lisp-gpe/dir.dox | 26 - src/vnet/lisp-gpe/interface.c | 945 - src/vnet/lisp-gpe/lisp_gpe.api | 237 - src/vnet/lisp-gpe/lisp_gpe.c | 728 - src/vnet/lisp-gpe/lisp_gpe.h | 339 - src/vnet/lisp-gpe/lisp_gpe_adjacency.c | 604 - src/vnet/lisp-gpe/lisp_gpe_adjacency.h | 136 - src/vnet/lisp-gpe/lisp_gpe_api.c | 549 - src/vnet/lisp-gpe/lisp_gpe_error.def | 18 - src/vnet/lisp-gpe/lisp_gpe_fwd_entry.c | 1595 -- src/vnet/lisp-gpe/lisp_gpe_fwd_entry.h | 240 - src/vnet/lisp-gpe/lisp_gpe_packet.h | 149 - src/vnet/lisp-gpe/lisp_gpe_sub_interface.c | 286 - src/vnet/lisp-gpe/lisp_gpe_sub_interface.h | 157 - src/vnet/lisp-gpe/lisp_gpe_tenant.c | 333 - src/vnet/lisp-gpe/lisp_gpe_tenant.h | 89 - src/vnet/lisp-gpe/lisp_gpe_tunnel.c | 293 - src/vnet/lisp-gpe/lisp_gpe_tunnel.h | 89 - src/vnet/lisp-gpe/lisp_types_api.c | 1 - src/vnet/lisp-gpe/lisp_types_api.h | 1 - src/vnet/lisp-gpe/rfc.txt | 826 - src/vnet/session/session_api.c | 2 +- src/vnet/vnet_all_api_h.h | 3 - src/vpp/api/custom_dump.c | 412 +- test/framework.py | 2 + test/test_lisp.py | 208 - 110 files changed, 41077 insertions(+), 40537 deletions(-) create mode 100644 src/plugins/lisp/CMakeLists.txt create mode 100644 src/plugins/lisp/lisp-cp/FEATURE.yaml create mode 100644 src/plugins/lisp/lisp-cp/control.c create mode 100644 src/plugins/lisp/lisp-cp/control.h create mode 100644 src/plugins/lisp/lisp-cp/gid_dictionary.c create mode 100644 src/plugins/lisp/lisp-cp/gid_dictionary.h create mode 100644 src/plugins/lisp/lisp-cp/lisp.api create mode 100644 src/plugins/lisp/lisp-cp/lisp_api.c create mode 100644 src/plugins/lisp/lisp-cp/lisp_cli.c create mode 100644 src/plugins/lisp/lisp-cp/lisp_cp_dpo.c create mode 100644 src/plugins/lisp/lisp-cp/lisp_cp_dpo.h create mode 100644 src/plugins/lisp/lisp-cp/lisp_cp_messages.h create mode 100644 src/plugins/lisp/lisp-cp/lisp_cp_test.c create mode 100644 src/plugins/lisp/lisp-cp/lisp_msg_serdes.c create mode 100644 src/plugins/lisp/lisp-cp/lisp_msg_serdes.h create mode 100644 src/plugins/lisp/lisp-cp/lisp_test.c create mode 100644 src/plugins/lisp/lisp-cp/lisp_types.api create mode 100644 src/plugins/lisp/lisp-cp/lisp_types.c create mode 100644 src/plugins/lisp/lisp-cp/lisp_types.h create mode 100644 src/plugins/lisp/lisp-cp/lisp_types_api.c create mode 100644 src/plugins/lisp/lisp-cp/lisp_types_api.h create mode 100644 src/plugins/lisp/lisp-cp/one.api create mode 100644 src/plugins/lisp/lisp-cp/one_api.c create mode 100644 src/plugins/lisp/lisp-cp/one_cli.c create mode 100644 src/plugins/lisp/lisp-cp/one_test.c create mode 100644 src/plugins/lisp/lisp-cp/packets.c create mode 100644 src/plugins/lisp/lisp-cp/packets.h create mode 100644 src/plugins/lisp/lisp-gpe/FEATURE.yaml create mode 100644 src/plugins/lisp/lisp-gpe/decap.c create mode 100644 src/plugins/lisp/lisp-gpe/dir.dox create mode 100644 src/plugins/lisp/lisp-gpe/interface.c create mode 100644 src/plugins/lisp/lisp-gpe/lisp_gpe.api create mode 100644 src/plugins/lisp/lisp-gpe/lisp_gpe.c create mode 100644 src/plugins/lisp/lisp-gpe/lisp_gpe.h create mode 100644 src/plugins/lisp/lisp-gpe/lisp_gpe_adjacency.c create mode 100644 src/plugins/lisp/lisp-gpe/lisp_gpe_adjacency.h create mode 100644 src/plugins/lisp/lisp-gpe/lisp_gpe_api.c create mode 100644 src/plugins/lisp/lisp-gpe/lisp_gpe_error.def create mode 100644 src/plugins/lisp/lisp-gpe/lisp_gpe_fwd_entry.c create mode 100644 src/plugins/lisp/lisp-gpe/lisp_gpe_fwd_entry.h create mode 100644 src/plugins/lisp/lisp-gpe/lisp_gpe_packet.h create mode 100644 src/plugins/lisp/lisp-gpe/lisp_gpe_sub_interface.c create mode 100644 src/plugins/lisp/lisp-gpe/lisp_gpe_sub_interface.h create mode 100644 src/plugins/lisp/lisp-gpe/lisp_gpe_tenant.c create mode 100644 src/plugins/lisp/lisp-gpe/lisp_gpe_tenant.h create mode 100644 src/plugins/lisp/lisp-gpe/lisp_gpe_test.c create mode 100644 src/plugins/lisp/lisp-gpe/lisp_gpe_tunnel.c create mode 100644 src/plugins/lisp/lisp-gpe/lisp_gpe_tunnel.h create mode 120000 src/plugins/lisp/lisp-gpe/lisp_types_api.c create mode 120000 src/plugins/lisp/lisp-gpe/lisp_types_api.h create mode 100644 src/plugins/lisp/lisp-gpe/rfc.txt create mode 100644 src/plugins/lisp/test/lisp_cp_test.c create mode 100644 src/plugins/lisp/test/test_lisp.py delete mode 100644 src/plugins/unittest/lisp_cp_test.c delete mode 100644 src/vnet/lisp-cp/FEATURE.yaml delete mode 100644 src/vnet/lisp-cp/control.c delete mode 100644 src/vnet/lisp-cp/control.h delete mode 100644 src/vnet/lisp-cp/gid_dictionary.c delete mode 100644 src/vnet/lisp-cp/gid_dictionary.h delete mode 100644 src/vnet/lisp-cp/lisp.api delete mode 100644 src/vnet/lisp-cp/lisp_api.c delete mode 100644 src/vnet/lisp-cp/lisp_cli.c delete mode 100644 src/vnet/lisp-cp/lisp_cp_dpo.c delete mode 100644 src/vnet/lisp-cp/lisp_cp_dpo.h delete mode 100644 src/vnet/lisp-cp/lisp_cp_messages.h delete mode 100644 src/vnet/lisp-cp/lisp_msg_serdes.c delete mode 100644 src/vnet/lisp-cp/lisp_msg_serdes.h delete mode 100644 src/vnet/lisp-cp/lisp_types.api delete mode 100644 src/vnet/lisp-cp/lisp_types.c delete mode 100644 src/vnet/lisp-cp/lisp_types.h delete mode 100644 src/vnet/lisp-cp/lisp_types_api.c delete mode 100644 src/vnet/lisp-cp/lisp_types_api.h delete mode 100644 src/vnet/lisp-cp/one.api delete mode 100644 src/vnet/lisp-cp/one_api.c delete mode 100644 src/vnet/lisp-cp/one_cli.c delete mode 100644 src/vnet/lisp-cp/packets.c delete mode 100644 src/vnet/lisp-cp/packets.h delete mode 100644 src/vnet/lisp-gpe/FEATURE.yaml delete mode 100644 src/vnet/lisp-gpe/decap.c delete mode 100644 src/vnet/lisp-gpe/dir.dox delete mode 100644 src/vnet/lisp-gpe/interface.c delete mode 100644 src/vnet/lisp-gpe/lisp_gpe.api delete mode 100644 src/vnet/lisp-gpe/lisp_gpe.c delete mode 100644 src/vnet/lisp-gpe/lisp_gpe.h delete mode 100644 src/vnet/lisp-gpe/lisp_gpe_adjacency.c delete mode 100644 src/vnet/lisp-gpe/lisp_gpe_adjacency.h delete mode 100644 src/vnet/lisp-gpe/lisp_gpe_api.c delete mode 100644 src/vnet/lisp-gpe/lisp_gpe_error.def delete mode 100644 src/vnet/lisp-gpe/lisp_gpe_fwd_entry.c delete mode 100644 src/vnet/lisp-gpe/lisp_gpe_fwd_entry.h delete mode 100644 src/vnet/lisp-gpe/lisp_gpe_packet.h delete mode 100644 src/vnet/lisp-gpe/lisp_gpe_sub_interface.c delete mode 100644 src/vnet/lisp-gpe/lisp_gpe_sub_interface.h delete mode 100644 src/vnet/lisp-gpe/lisp_gpe_tenant.c delete mode 100644 src/vnet/lisp-gpe/lisp_gpe_tenant.h delete mode 100644 src/vnet/lisp-gpe/lisp_gpe_tunnel.c delete mode 100644 src/vnet/lisp-gpe/lisp_gpe_tunnel.h delete mode 120000 src/vnet/lisp-gpe/lisp_types_api.c delete mode 120000 src/vnet/lisp-gpe/lisp_types_api.h delete mode 100644 src/vnet/lisp-gpe/rfc.txt delete mode 100644 test/test_lisp.py diff --git a/src/plugins/lisp/CMakeLists.txt b/src/plugins/lisp/CMakeLists.txt new file mode 100644 index 00000000000..bf0d60aab0f --- /dev/null +++ b/src/plugins/lisp/CMakeLists.txt @@ -0,0 +1,79 @@ +# Copyright (c) 2020 Cisco and/or its affiliates. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +############################################################################## +# LISP control plane: lisp-cp +############################################################################## + +############################################################################## +# Tunnel protocol: lisp-gpe +############################################################################## + +add_vpp_plugin(lisp + SOURCES + lisp-cp/lisp_types.c + lisp-cp/lisp_cp_dpo.c + lisp-cp/control.c + lisp-cp/control_main.c + lisp-cp/gid_dictionary.c + lisp-cp/lisp_msg_serdes.c + lisp-cp/packets.c + lisp-cp/one_cli.c + lisp-cp/lisp_cli.c + lisp-cp/one_api.c + lisp-cp/lisp_api.c + lisp-cp/lisp_types_api.c + lisp-gpe/lisp_gpe.c + lisp-gpe/lisp_gpe_sub_interface.c + lisp-gpe/lisp_gpe_adjacency.c + lisp-gpe/lisp_gpe_tunnel.c + lisp-gpe/lisp_gpe_fwd_entry.c + lisp-gpe/lisp_gpe_tenant.c + lisp-gpe/interface.c + lisp-gpe/decap.c + lisp-gpe/lisp_gpe_api.c + + API_FILES + lisp-cp/lisp_types.api + lisp-cp/lisp.api + lisp-cp/one.api + lisp-gpe/lisp_gpe.api + + INSTALL_HEADERS + lisp-cp/lisp_types.h + lisp-cp/packets.h + lisp-cp/gid_dictionary.h + lisp-cp/lisp_cp_messages.h + lisp-cp/lisp_msg_serdes.h + lisp-cp/control.h + lisp-cp/lisp_types_api.h + lisp-gpe/lisp_gpe.h + lisp-gpe/lisp_gpe_fwd_entry.h + lisp-gpe/lisp_gpe_tenant.h + lisp-gpe/lisp_gpe_packet.h + lisp-gpe/lisp_gpe_error.def + + API_TEST_SOURCES + lisp-cp/lisp_test.c + lisp-cp/lisp_cp_test.c + lisp-cp/one_test.c + lisp-gpe/lisp_gpe_test.c +) + +add_vpp_plugin(lisp_unittest + SOURCES + lisp-cp/lisp_msg_serdes.c + lisp-cp/control_main.c + lisp-cp/lisp_types.c + test/lisp_cp_test.c +) diff --git a/src/plugins/lisp/lisp-cp/FEATURE.yaml b/src/plugins/lisp/lisp-cp/FEATURE.yaml new file mode 100644 index 00000000000..fb48e1fd232 --- /dev/null +++ b/src/plugins/lisp/lisp-cp/FEATURE.yaml @@ -0,0 +1,14 @@ +--- +name: Locator ID Separation Protocol Control Plane +maintainer: Florin Coras +features: + - ITR, ETR and RTR mode of operation + - Multitenancy + - Multihoming + - Source/dest map-cache lookups + - RLOC-probing + - Support for Ethernet, IPv4, IPv6 and NSH EIDs (payloads) + - Map-resolver failover algorithm +description: "Locator ID Separation Protocol control plane (LISP) implementation" +state: production +properties: [API, CLI, STATS, MULTITHREAD] diff --git a/src/plugins/lisp/lisp-cp/control.c b/src/plugins/lisp/lisp-cp/control.c new file mode 100644 index 00000000000..6eee74ac7d0 --- /dev/null +++ b/src/plugins/lisp/lisp-cp/control.c @@ -0,0 +1,5031 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#define MAX_VALUE_U24 0xffffff + +/* mapping timer control constants (in seconds) */ +#define TIME_UNTIL_REFETCH_OR_DELETE 20 +#define MAPPING_TIMEOUT (((m->ttl) * 60) - TIME_UNTIL_REFETCH_OR_DELETE) + +u8 *format_lisp_cp_input_trace (u8 * s, va_list * args); +static void *send_map_request_thread_fn (void *arg); + +typedef enum +{ + LISP_CP_INPUT_NEXT_DROP, + LISP_CP_INPUT_N_NEXT, +} lisp_cp_input_next_t; + +typedef struct +{ + u8 is_resend; + gid_address_t seid; + gid_address_t deid; + u8 smr_invoked; +} map_request_args_t; + +u8 +vnet_lisp_get_map_request_mode (void) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + return lcm->map_request_mode; +} + +static u16 +auth_data_len_by_key_id (lisp_key_type_t key_id) +{ + switch (key_id) + { + case HMAC_SHA_1_96: + return SHA1_AUTH_DATA_LEN; + case HMAC_SHA_256_128: + return SHA256_AUTH_DATA_LEN; + default: + clib_warning ("unsupported key type: %d!", key_id); + return (u16) ~ 0; + } + return (u16) ~ 0; +} + +static int +queue_map_request (gid_address_t * seid, gid_address_t * deid, + u8 smr_invoked, u8 is_resend); + +ip_interface_address_t * +ip_interface_get_first_interface_address (ip_lookup_main_t * lm, + u32 sw_if_index, u8 loop) +{ + vnet_main_t *vnm = vnet_get_main (); + vnet_sw_interface_t *swif = vnet_get_sw_interface (vnm, sw_if_index); + if (loop && swif->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED) + sw_if_index = swif->unnumbered_sw_if_index; + u32 ia = + (vec_len ((lm)->if_address_pool_index_by_sw_if_index) > (sw_if_index)) ? + vec_elt ((lm)->if_address_pool_index_by_sw_if_index, (sw_if_index)) : + (u32) ~ 0; + return pool_elt_at_index ((lm)->if_address_pool, ia); +} + +void * +ip_interface_get_first_address (ip_lookup_main_t * lm, u32 sw_if_index, + u8 version) +{ + ip_interface_address_t *ia; + + ia = ip_interface_get_first_interface_address (lm, sw_if_index, 1); + if (!ia) + return 0; + return ip_interface_address_get_address (lm, ia); +} + +int +ip_interface_get_first_ip_address (lisp_cp_main_t * lcm, u32 sw_if_index, + u8 version, ip_address_t * result) +{ + ip_lookup_main_t *lm; + void *addr; + + lm = (version == AF_IP4) ? &lcm->im4->lookup_main : &lcm->im6->lookup_main; + addr = ip_interface_get_first_address (lm, sw_if_index, version); + if (!addr) + return 0; + + ip_address_set (result, addr, version); + return 1; +} + +/** + * Find the sw_if_index of the interface that would be used to egress towards + * dst. + */ +u32 +ip_fib_get_egress_iface_for_dst (lisp_cp_main_t * lcm, ip_address_t * dst) +{ + fib_node_index_t fei; + fib_prefix_t prefix; + + ip_address_to_fib_prefix (dst, &prefix); + + fei = fib_table_lookup (0, &prefix); + + return (fib_entry_get_resolving_interface (fei)); +} + +/** + * Find first IP of the interface that would be used to egress towards dst. + * Returns 1 if the address is found 0 otherwise. + */ +int +ip_fib_get_first_egress_ip_for_dst (lisp_cp_main_t * lcm, ip_address_t * dst, + ip_address_t * result) +{ + u32 si; + ip_lookup_main_t *lm; + void *addr = 0; + u8 ipver; + + ASSERT (result != 0); + + ipver = ip_addr_version (dst); + + lm = (ipver == AF_IP4) ? &lcm->im4->lookup_main : &lcm->im6->lookup_main; + si = ip_fib_get_egress_iface_for_dst (lcm, dst); + + if ((u32) ~ 0 == si) + return 0; + + /* find the first ip address */ + addr = ip_interface_get_first_address (lm, si, ipver); + if (0 == addr) + return 0; + + ip_address_set (result, addr, ipver); + return 1; +} + +static int +dp_add_del_iface (lisp_cp_main_t * lcm, u32 vni, u8 is_l2, u8 is_add, + u8 with_default_route) +{ + uword *dp_table; + + if (!is_l2) + { + dp_table = hash_get (lcm->table_id_by_vni, vni); + + if (!dp_table) + { + clib_warning ("vni %d not associated to a vrf!", vni); + return VNET_API_ERROR_INVALID_VALUE; + } + } + else + { + dp_table = hash_get (lcm->bd_id_by_vni, vni); + if (!dp_table) + { + clib_warning ("vni %d not associated to a bridge domain!", vni); + return VNET_API_ERROR_INVALID_VALUE; + } + } + + /* enable/disable data-plane interface */ + if (is_add) + { + if (is_l2) + lisp_gpe_tenant_l2_iface_add_or_lock (vni, dp_table[0]); + else + lisp_gpe_tenant_l3_iface_add_or_lock (vni, dp_table[0], + with_default_route); + } + else + { + if (is_l2) + lisp_gpe_tenant_l2_iface_unlock (vni); + else + lisp_gpe_tenant_l3_iface_unlock (vni); + } + + return 0; +} + +static void +dp_del_fwd_entry (lisp_cp_main_t * lcm, u32 dst_map_index) +{ + vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a; + fwd_entry_t *fe = 0; + uword *feip = 0; + clib_memset (a, 0, sizeof (*a)); + + feip = hash_get (lcm->fwd_entry_by_mapping_index, dst_map_index); + if (!feip) + return; + + fe = pool_elt_at_index (lcm->fwd_entry_pool, feip[0]); + + /* delete dp fwd entry */ + u32 sw_if_index; + a->is_add = 0; + a->locator_pairs = fe->locator_pairs; + a->vni = gid_address_vni (&fe->reid); + gid_address_copy (&a->rmt_eid, &fe->reid); + if (fe->is_src_dst) + gid_address_copy (&a->lcl_eid, &fe->leid); + + vnet_lisp_gpe_del_fwd_counters (a, feip[0]); + vnet_lisp_gpe_add_del_fwd_entry (a, &sw_if_index); + + /* delete entry in fwd table */ + hash_unset (lcm->fwd_entry_by_mapping_index, dst_map_index); + vec_free (fe->locator_pairs); + pool_put (lcm->fwd_entry_pool, fe); +} + +/** + * Finds first remote locator with best (lowest) priority that has a local + * peer locator with an underlying route to it. + * + */ +static u32 +get_locator_pairs (lisp_cp_main_t * lcm, mapping_t * lcl_map, + mapping_t * rmt_map, locator_pair_t ** locator_pairs) +{ + u32 i, limitp = 0, li, found = 0, esi; + locator_set_t *rmt_ls, *lcl_ls; + ip_address_t _lcl_addr, *lcl_addr = &_lcl_addr; + locator_t *lp, *rmt = 0; + uword *checked = 0; + locator_pair_t pair; + + rmt_ls = + pool_elt_at_index (lcm->locator_set_pool, rmt_map->locator_set_index); + lcl_ls = + pool_elt_at_index (lcm->locator_set_pool, lcl_map->locator_set_index); + + if (!rmt_ls || vec_len (rmt_ls->locator_indices) == 0) + return 0; + + while (1) + { + rmt = 0; + + /* find unvisited remote locator with best priority */ + for (i = 0; i < vec_len (rmt_ls->locator_indices); i++) + { + if (0 != hash_get (checked, i)) + continue; + + li = vec_elt (rmt_ls->locator_indices, i); + lp = pool_elt_at_index (lcm->locator_pool, li); + + /* we don't support non-IP locators for now */ + if (gid_address_type (&lp->address) != GID_ADDR_IP_PREFIX) + continue; + + if ((found && lp->priority == limitp) + || (!found && lp->priority >= limitp)) + { + rmt = lp; + + /* don't search for locators with lower priority and don't + * check this locator again*/ + limitp = lp->priority; + hash_set (checked, i, 1); + break; + } + } + /* check if a local locator with a route to remote locator exists */ + if (rmt != 0) + { + /* find egress sw_if_index for rmt locator */ + esi = + ip_fib_get_egress_iface_for_dst (lcm, + &gid_address_ip (&rmt->address)); + if ((u32) ~ 0 == esi) + continue; + + for (i = 0; i < vec_len (lcl_ls->locator_indices); i++) + { + li = vec_elt (lcl_ls->locator_indices, i); + locator_t *sl = pool_elt_at_index (lcm->locator_pool, li); + + /* found local locator with the needed sw_if_index */ + if (sl->sw_if_index == esi) + { + /* and it has an address */ + if (0 == ip_interface_get_first_ip_address (lcm, + sl->sw_if_index, + gid_address_ip_version + (&rmt->address), + lcl_addr)) + continue; + + clib_memset (&pair, 0, sizeof (pair)); + ip_address_copy (&pair.rmt_loc, + &gid_address_ip (&rmt->address)); + ip_address_copy (&pair.lcl_loc, lcl_addr); + pair.weight = rmt->weight; + pair.priority = rmt->priority; + vec_add1 (locator_pairs[0], pair); + found = 1; + } + } + } + else + break; + } + + hash_free (checked); + return found; +} + +static void +gid_address_sd_to_flat (gid_address_t * dst, gid_address_t * src, + fid_address_t * fid) +{ + ASSERT (GID_ADDR_SRC_DST == gid_address_type (src)); + + dst[0] = src[0]; + + switch (fid_addr_type (fid)) + { + case FID_ADDR_IP_PREF: + gid_address_type (dst) = GID_ADDR_IP_PREFIX; + gid_address_ippref (dst) = fid_addr_ippref (fid); + break; + case FID_ADDR_MAC: + gid_address_type (dst) = GID_ADDR_MAC; + mac_copy (gid_address_mac (dst), fid_addr_mac (fid)); + break; + default: + clib_warning ("Unsupported fid type %d!", fid_addr_type (fid)); + break; + } +} + +u8 +vnet_lisp_map_register_state_get (void) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + return lcm->map_registering; +} + +u8 +vnet_lisp_rloc_probe_state_get (void) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + return lcm->rloc_probing; +} + +static void +dp_add_fwd_entry (lisp_cp_main_t * lcm, u32 src_map_index, u32 dst_map_index) +{ + vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a; + gid_address_t *rmt_eid, *lcl_eid; + mapping_t *lcl_map, *rmt_map; + u32 sw_if_index, **rmts, rmts_idx; + uword *feip = 0, *dpid, *rmts_stored_idxp = 0; + fwd_entry_t *fe; + u8 type, is_src_dst = 0; + int rv; + + clib_memset (a, 0, sizeof (*a)); + + /* remove entry if it already exists */ + feip = hash_get (lcm->fwd_entry_by_mapping_index, dst_map_index); + if (feip) + dp_del_fwd_entry (lcm, dst_map_index); + + /* + * Determine local mapping and eid + */ + if (lcm->flags & LISP_FLAG_PITR_MODE) + { + if (lcm->pitr_map_index != ~0) + lcl_map = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index); + else + { + clib_warning ("no PITR mapping configured!"); + return; + } + } + else + lcl_map = pool_elt_at_index (lcm->mapping_pool, src_map_index); + lcl_eid = &lcl_map->eid; + + /* + * Determine remote mapping and eid + */ + rmt_map = pool_elt_at_index (lcm->mapping_pool, dst_map_index); + rmt_eid = &rmt_map->eid; + + /* + * Build and insert data plane forwarding entry + */ + a->is_add = 1; + + if (MR_MODE_SRC_DST == lcm->map_request_mode) + { + if (GID_ADDR_SRC_DST == gid_address_type (rmt_eid)) + { + gid_address_sd_to_flat (&a->rmt_eid, rmt_eid, + &gid_address_sd_dst (rmt_eid)); + gid_address_sd_to_flat (&a->lcl_eid, rmt_eid, + &gid_address_sd_src (rmt_eid)); + } + else + { + gid_address_copy (&a->rmt_eid, rmt_eid); + gid_address_copy (&a->lcl_eid, lcl_eid); + } + is_src_dst = 1; + } + else + gid_address_copy (&a->rmt_eid, rmt_eid); + + a->vni = gid_address_vni (&a->rmt_eid); + a->is_src_dst = is_src_dst; + + /* get vrf or bd_index associated to vni */ + type = gid_address_type (&a->rmt_eid); + if (GID_ADDR_IP_PREFIX == type) + { + dpid = hash_get (lcm->table_id_by_vni, a->vni); + if (!dpid) + { + clib_warning ("vni %d not associated to a vrf!", a->vni); + return; + } + a->table_id = dpid[0]; + } + else if (GID_ADDR_MAC == type) + { + dpid = hash_get (lcm->bd_id_by_vni, a->vni); + if (!dpid) + { + clib_warning ("vni %d not associated to a bridge domain !", a->vni); + return; + } + a->bd_id = dpid[0]; + } + + /* find best locator pair that 1) verifies LISP policy 2) are connected */ + rv = get_locator_pairs (lcm, lcl_map, rmt_map, &a->locator_pairs); + + /* Either rmt mapping is negative or we can't find underlay path. + * Try again with petr if configured */ + if (rv == 0 && (lcm->flags & LISP_FLAG_USE_PETR)) + { + rmt_map = lisp_get_petr_mapping (lcm); + rv = get_locator_pairs (lcm, lcl_map, rmt_map, &a->locator_pairs); + } + + /* negative entry */ + if (rv == 0) + { + a->is_negative = 1; + a->action = rmt_map->action; + } + + rv = vnet_lisp_gpe_add_del_fwd_entry (a, &sw_if_index); + if (rv) + { + if (a->locator_pairs) + vec_free (a->locator_pairs); + return; + } + + /* add tunnel to fwd entry table */ + pool_get (lcm->fwd_entry_pool, fe); + vnet_lisp_gpe_add_fwd_counters (a, fe - lcm->fwd_entry_pool); + + fe->locator_pairs = a->locator_pairs; + gid_address_copy (&fe->reid, &a->rmt_eid); + + if (is_src_dst) + gid_address_copy (&fe->leid, &a->lcl_eid); + else + gid_address_copy (&fe->leid, lcl_eid); + + fe->is_src_dst = is_src_dst; + hash_set (lcm->fwd_entry_by_mapping_index, dst_map_index, + fe - lcm->fwd_entry_pool); + + /* Add rmt mapping to the vector of adjacent mappings to lcl mapping */ + rmts_stored_idxp = + hash_get (lcm->lcl_to_rmt_adjs_by_lcl_idx, src_map_index); + if (!rmts_stored_idxp) + { + pool_get (lcm->lcl_to_rmt_adjacencies, rmts); + clib_memset (rmts, 0, sizeof (*rmts)); + rmts_idx = rmts - lcm->lcl_to_rmt_adjacencies; + hash_set (lcm->lcl_to_rmt_adjs_by_lcl_idx, src_map_index, rmts_idx); + } + else + { + rmts_idx = (u32) (*rmts_stored_idxp); + rmts = pool_elt_at_index (lcm->lcl_to_rmt_adjacencies, rmts_idx); + } + vec_add1 (rmts[0], dst_map_index); +} + +typedef struct +{ + u32 si; + u32 di; +} fwd_entry_mt_arg_t; + +static void * +dp_add_fwd_entry_thread_fn (void *arg) +{ + fwd_entry_mt_arg_t *a = arg; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + dp_add_fwd_entry (lcm, a->si, a->di); + return 0; +} + +static int +dp_add_fwd_entry_from_mt (u32 si, u32 di) +{ + fwd_entry_mt_arg_t a; + + clib_memset (&a, 0, sizeof (a)); + a.si = si; + a.di = di; + + vl_api_rpc_call_main_thread (dp_add_fwd_entry_thread_fn, + (u8 *) & a, sizeof (a)); + return 0; +} + +/** + * Returns vector of adjacencies. + * + * The caller must free the vector returned by this function. + * + * @param vni virtual network identifier + * @return vector of adjacencies + */ +lisp_adjacency_t * +vnet_lisp_adjacencies_get_by_vni (u32 vni) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + fwd_entry_t *fwd; + lisp_adjacency_t *adjs = 0, adj; + + /* *INDENT-OFF* */ + pool_foreach(fwd, lcm->fwd_entry_pool, + ({ + if (gid_address_vni (&fwd->reid) != vni) + continue; + + gid_address_copy (&adj.reid, &fwd->reid); + gid_address_copy (&adj.leid, &fwd->leid); + vec_add1 (adjs, adj); + })); + /* *INDENT-ON* */ + + return adjs; +} + +static lisp_msmr_t * +get_map_server (ip_address_t * a) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + lisp_msmr_t *m; + + vec_foreach (m, lcm->map_servers) + { + if (!ip_address_cmp (&m->address, a)) + { + return m; + } + } + return 0; +} + +static lisp_msmr_t * +get_map_resolver (ip_address_t * a) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + lisp_msmr_t *m; + + vec_foreach (m, lcm->map_resolvers) + { + if (!ip_address_cmp (&m->address, a)) + { + return m; + } + } + return 0; +} + +int +vnet_lisp_add_del_map_server (ip_address_t * addr, u8 is_add) +{ + u32 i; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + lisp_msmr_t _ms, *ms = &_ms; + + if (vnet_lisp_enable_disable_status () == 0) + { + clib_warning ("LISP is disabled!"); + return VNET_API_ERROR_LISP_DISABLED; + } + + if (is_add) + { + if (get_map_server (addr)) + { + clib_warning ("map-server %U already exists!", format_ip_address, + addr); + return -1; + } + + clib_memset (ms, 0, sizeof (*ms)); + ip_address_copy (&ms->address, addr); + vec_add1 (lcm->map_servers, ms[0]); + + if (vec_len (lcm->map_servers) == 1) + lcm->do_map_server_election = 1; + } + else + { + for (i = 0; i < vec_len (lcm->map_servers); i++) + { + ms = vec_elt_at_index (lcm->map_servers, i); + if (!ip_address_cmp (&ms->address, addr)) + { + if (!ip_address_cmp (&ms->address, &lcm->active_map_server)) + lcm->do_map_server_election = 1; + + vec_del1 (lcm->map_servers, i); + break; + } + } + } + + return 0; +} + +/** + * Add/remove mapping to/from map-cache. Overwriting not allowed. + */ +int +vnet_lisp_map_cache_add_del (vnet_lisp_add_del_mapping_args_t * a, + u32 * map_index_result) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + u32 mi, *map_indexp, map_index, i; + u32 **rmts = 0, *remote_idxp, rmts_itr, remote_idx; + uword *rmts_idxp; + mapping_t *m, *old_map; + u32 **eid_indexes; + + if (gid_address_type (&a->eid) == GID_ADDR_NSH) + { + if (gid_address_vni (&a->eid) != 0) + { + clib_warning ("Supported only default VNI for NSH!"); + return VNET_API_ERROR_INVALID_ARGUMENT; + } + if (gid_address_nsh_spi (&a->eid) > MAX_VALUE_U24) + { + clib_warning ("SPI is greater than 24bit!"); + return VNET_API_ERROR_INVALID_ARGUMENT; + } + } + + mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &a->eid); + old_map = mi != ~0 ? pool_elt_at_index (lcm->mapping_pool, mi) : 0; + if (a->is_add) + { + /* TODO check if overwriting and take appropriate actions */ + if (mi != GID_LOOKUP_MISS && !gid_address_cmp (&old_map->eid, &a->eid)) + { + clib_warning ("eid %U found in the eid-table", format_gid_address, + &a->eid); + return VNET_API_ERROR_VALUE_EXIST; + } + + pool_get (lcm->mapping_pool, m); + gid_address_copy (&m->eid, &a->eid); + m->locator_set_index = a->locator_set_index; + m->ttl = a->ttl; + m->action = a->action; + m->local = a->local; + m->is_static = a->is_static; + m->key = vec_dup (a->key); + m->key_id = a->key_id; + m->authoritative = a->authoritative; + + map_index = m - lcm->mapping_pool; + gid_dictionary_add_del (&lcm->mapping_index_by_gid, &a->eid, map_index, + 1); + + if (pool_is_free_index (lcm->locator_set_pool, a->locator_set_index)) + { + clib_warning ("Locator set with index %d doesn't exist", + a->locator_set_index); + return VNET_API_ERROR_INVALID_VALUE; + } + + /* add eid to list of eids supported by locator-set */ + vec_validate (lcm->locator_set_to_eids, a->locator_set_index); + eid_indexes = vec_elt_at_index (lcm->locator_set_to_eids, + a->locator_set_index); + vec_add1 (eid_indexes[0], map_index); + + if (a->local) + { + /* mark as local */ + vec_add1 (lcm->local_mappings_indexes, map_index); + } + map_index_result[0] = map_index; + } + else + { + if (mi == GID_LOOKUP_MISS) + { + clib_warning ("eid %U not found in the eid-table", + format_gid_address, &a->eid); + return VNET_API_ERROR_INVALID_VALUE; + } + + /* clear locator-set to eids binding */ + eid_indexes = vec_elt_at_index (lcm->locator_set_to_eids, + a->locator_set_index); + for (i = 0; i < vec_len (eid_indexes[0]); i++) + { + map_indexp = vec_elt_at_index (eid_indexes[0], i); + if (map_indexp[0] == mi) + break; + } + vec_del1 (eid_indexes[0], i); + + /* remove local mark if needed */ + m = pool_elt_at_index (lcm->mapping_pool, mi); + if (m->local) + { + /* Remove adjacencies associated with the local mapping */ + rmts_idxp = hash_get (lcm->lcl_to_rmt_adjs_by_lcl_idx, mi); + if (rmts_idxp) + { + rmts = + pool_elt_at_index (lcm->lcl_to_rmt_adjacencies, rmts_idxp[0]); + vec_foreach (remote_idxp, rmts[0]) + { + dp_del_fwd_entry (lcm, remote_idxp[0]); + } + vec_free (rmts[0]); + pool_put (lcm->lcl_to_rmt_adjacencies, rmts); + hash_unset (lcm->lcl_to_rmt_adjs_by_lcl_idx, mi); + } + + u32 k, *lm_indexp; + for (k = 0; k < vec_len (lcm->local_mappings_indexes); k++) + { + lm_indexp = vec_elt_at_index (lcm->local_mappings_indexes, k); + if (lm_indexp[0] == mi) + break; + } + vec_del1 (lcm->local_mappings_indexes, k); + } + else + { + /* Remove remote (if present) from the vectors of lcl-to-rmts + * TODO: Address this in a more efficient way. + */ + /* *INDENT-OFF* */ + pool_foreach (rmts, lcm->lcl_to_rmt_adjacencies, + ({ + vec_foreach_index (rmts_itr, rmts[0]) + { + remote_idx = vec_elt (rmts[0], rmts_itr); + if (mi == remote_idx) + { + vec_del1 (rmts[0], rmts_itr); + break; + } + } + })); + /* *INDENT-ON* */ + } + + /* remove mapping from dictionary */ + gid_dictionary_add_del (&lcm->mapping_index_by_gid, &a->eid, 0, 0); + gid_address_free (&m->eid); + pool_put_index (lcm->mapping_pool, mi); + } + + return 0; +} + +/** + * Add/update/delete mapping to/in/from map-cache. + */ +int +vnet_lisp_add_del_local_mapping (vnet_lisp_add_del_mapping_args_t * a, + u32 * map_index_result) +{ + uword *dp_table = 0; + u32 vni; + u8 type; + + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + + if (vnet_lisp_enable_disable_status () == 0) + { + clib_warning ("LISP is disabled!"); + return VNET_API_ERROR_LISP_DISABLED; + } + + vni = gid_address_vni (&a->eid); + type = gid_address_type (&a->eid); + if (GID_ADDR_IP_PREFIX == type) + dp_table = hash_get (lcm->table_id_by_vni, vni); + else if (GID_ADDR_MAC == type) + dp_table = hash_get (lcm->bd_id_by_vni, vni); + + if (!dp_table && GID_ADDR_NSH != type) + { + clib_warning ("vni %d not associated to a %s!", vni, + GID_ADDR_IP_PREFIX == type ? "vrf" : "bd"); + return VNET_API_ERROR_INVALID_VALUE; + } + + /* store/remove mapping from map-cache */ + return vnet_lisp_map_cache_add_del (a, map_index_result); +} + +static int +add_l2_arp_bd (BVT (clib_bihash_kv) * kvp, void *arg) +{ + u32 **ht = arg; + u32 version = (u32) kvp->key[0]; + if (AF_IP6 == version) + return (BIHASH_WALK_CONTINUE); + + u32 bd = (u32) (kvp->key[0] >> 32); + hash_set (ht[0], bd, 0); + return (BIHASH_WALK_CONTINUE); +} + +u32 * +vnet_lisp_l2_arp_bds_get (void) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + u32 *bds = 0; + + gid_dict_foreach_l2_arp_ndp_entry (&lcm->mapping_index_by_gid, + add_l2_arp_bd, &bds); + return bds; +} + +static int +add_ndp_bd (BVT (clib_bihash_kv) * kvp, void *arg) +{ + u32 **ht = arg; + u32 version = (u32) kvp->key[0]; + if (AF_IP4 == version) + return (BIHASH_WALK_CONTINUE); + + u32 bd = (u32) (kvp->key[0] >> 32); + hash_set (ht[0], bd, 0); + return (BIHASH_WALK_CONTINUE); +} + +u32 * +vnet_lisp_ndp_bds_get (void) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + u32 *bds = 0; + + gid_dict_foreach_l2_arp_ndp_entry (&lcm->mapping_index_by_gid, + add_ndp_bd, &bds); + return bds; +} + +typedef struct +{ + void *vector; + u32 bd; +} lisp_add_l2_arp_ndp_args_t; + +static int +add_l2_arp_entry (BVT (clib_bihash_kv) * kvp, void *arg) +{ + lisp_add_l2_arp_ndp_args_t *a = arg; + lisp_api_l2_arp_entry_t **vector = a->vector, e; + + u32 version = (u32) kvp->key[0]; + if (AF_IP6 == version) + return (BIHASH_WALK_CONTINUE); + + u32 bd = (u32) (kvp->key[0] >> 32); + + if (bd == a->bd) + { + mac_copy (e.mac, (void *) &kvp->value); + e.ip4 = (u32) kvp->key[1]; + vec_add1 (vector[0], e); + } + return (BIHASH_WALK_CONTINUE); +} + +lisp_api_l2_arp_entry_t * +vnet_lisp_l2_arp_entries_get_by_bd (u32 bd) +{ + lisp_api_l2_arp_entry_t *entries = 0; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + lisp_add_l2_arp_ndp_args_t a; + + a.vector = &entries; + a.bd = bd; + + gid_dict_foreach_l2_arp_ndp_entry (&lcm->mapping_index_by_gid, + add_l2_arp_entry, &a); + return entries; +} + +static int +add_ndp_entry (BVT (clib_bihash_kv) * kvp, void *arg) +{ + lisp_add_l2_arp_ndp_args_t *a = arg; + lisp_api_ndp_entry_t **vector = a->vector, e; + + u32 version = (u32) kvp->key[0]; + if (AF_IP4 == version) + return (BIHASH_WALK_CONTINUE); + + u32 bd = (u32) (kvp->key[0] >> 32); + + if (bd == a->bd) + { + mac_copy (e.mac, (void *) &kvp->value); + clib_memcpy (e.ip6, &kvp->key[1], 16); + vec_add1 (vector[0], e); + } + return (BIHASH_WALK_CONTINUE); +} + +lisp_api_ndp_entry_t * +vnet_lisp_ndp_entries_get_by_bd (u32 bd) +{ + lisp_api_ndp_entry_t *entries = 0; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + lisp_add_l2_arp_ndp_args_t a; + + a.vector = &entries; + a.bd = bd; + + gid_dict_foreach_l2_arp_ndp_entry (&lcm->mapping_index_by_gid, + add_ndp_entry, &a); + return entries; +} + +int +vnet_lisp_add_del_l2_arp_ndp_entry (gid_address_t * key, u8 * mac, u8 is_add) +{ + if (vnet_lisp_enable_disable_status () == 0) + { + clib_warning ("LISP is disabled!"); + return VNET_API_ERROR_LISP_DISABLED; + } + + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + int rc = 0; + + u64 res = gid_dictionary_lookup (&lcm->mapping_index_by_gid, key); + if (is_add) + { + if (res != GID_LOOKUP_MISS_L2) + { + clib_warning ("Entry %U exists in DB!", format_gid_address, key); + return VNET_API_ERROR_ENTRY_ALREADY_EXISTS; + } + u64 val = mac_to_u64 (mac); + gid_dictionary_add_del (&lcm->mapping_index_by_gid, key, val, + 1 /* is_add */ ); + } + else + { + if (res == GID_LOOKUP_MISS_L2) + { + clib_warning ("ONE entry %U not found - cannot delete!", + format_gid_address, key); + return -1; + } + gid_dictionary_add_del (&lcm->mapping_index_by_gid, key, 0, + 0 /* is_add */ ); + } + + return rc; +} + +int +vnet_lisp_eid_table_map (u32 vni, u32 dp_id, u8 is_l2, u8 is_add) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + uword *dp_idp, *vnip, **dp_table_by_vni, **vni_by_dp_table; + + if (vnet_lisp_enable_disable_status () == 0) + { + clib_warning ("LISP is disabled!"); + return VNET_API_ERROR_LISP_DISABLED; + } + + dp_table_by_vni = is_l2 ? &lcm->bd_id_by_vni : &lcm->table_id_by_vni; + vni_by_dp_table = is_l2 ? &lcm->vni_by_bd_id : &lcm->vni_by_table_id; + + if (!is_l2 && (vni == 0 || dp_id == 0)) + { + clib_warning ("can't add/del default vni-vrf mapping!"); + return -1; + } + + dp_idp = hash_get (dp_table_by_vni[0], vni); + vnip = hash_get (vni_by_dp_table[0], dp_id); + + if (is_add) + { + if (dp_idp || vnip) + { + clib_warning ("vni %d or vrf %d already used in vrf/vni " + "mapping!", vni, dp_id); + return -1; + } + hash_set (dp_table_by_vni[0], vni, dp_id); + hash_set (vni_by_dp_table[0], dp_id, vni); + + /* create dp iface */ + dp_add_del_iface (lcm, vni, is_l2, 1 /* is_add */ , + 1 /* with_default_route */ ); + } + else + { + if (!dp_idp || !vnip) + { + clib_warning ("vni %d or vrf %d not used in any vrf/vni! " + "mapping!", vni, dp_id); + return -1; + } + /* remove dp iface */ + dp_add_del_iface (lcm, vni, is_l2, 0 /* is_add */ , 0 /* unused */ ); + + hash_unset (dp_table_by_vni[0], vni); + hash_unset (vni_by_dp_table[0], dp_id); + } + return 0; + +} + +/* return 0 if the two locator sets are identical 1 otherwise */ +static u8 +compare_locators (lisp_cp_main_t * lcm, u32 * old_ls_indexes, + locator_t * new_locators) +{ + u32 i, old_li; + locator_t *old_loc, *new_loc; + + if (vec_len (old_ls_indexes) != vec_len (new_locators)) + return 1; + + for (i = 0; i < vec_len (new_locators); i++) + { + old_li = vec_elt (old_ls_indexes, i); + old_loc = pool_elt_at_index (lcm->locator_pool, old_li); + + new_loc = vec_elt_at_index (new_locators, i); + + if (locator_cmp (old_loc, new_loc)) + return 1; + } + return 0; +} + +typedef struct +{ + u8 is_negative; + void *lcm; + gid_address_t *eids_to_be_deleted; +} remove_mapping_args_t; + +/** + * Callback invoked when a sub-prefix is found + */ +static void +remove_mapping_if_needed (u32 mi, void *arg) +{ + u8 delete = 0; + remove_mapping_args_t *a = arg; + lisp_cp_main_t *lcm = a->lcm; + mapping_t *m; + locator_set_t *ls; + + m = pool_elt_at_index (lcm->mapping_pool, mi); + if (!m) + return; + + ls = pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index); + + if (a->is_negative) + { + if (0 != vec_len (ls->locator_indices)) + delete = 1; + } + else + { + if (0 == vec_len (ls->locator_indices)) + delete = 1; + } + + if (delete) + vec_add1 (a->eids_to_be_deleted, m->eid); +} + +/** + * This function searches map cache and looks for IP prefixes that are subset + * of the provided one. If such prefix is found depending on 'is_negative' + * it does follows: + * + * 1) if is_negative is true and found prefix points to positive mapping, + * then the mapping is removed + * 2) if is_negative is false and found prefix points to negative mapping, + * then the mapping is removed + */ +static void +remove_overlapping_sub_prefixes (lisp_cp_main_t * lcm, gid_address_t * eid, + u8 is_negative) +{ + gid_address_t *e; + remove_mapping_args_t a; + + clib_memset (&a, 0, sizeof (a)); + + /* do this only in src/dst mode ... */ + if (MR_MODE_SRC_DST != lcm->map_request_mode) + return; + + /* ... and only for IP prefix */ + if (GID_ADDR_SRC_DST != gid_address_type (eid) + || (FID_ADDR_IP_PREF != gid_address_sd_dst_type (eid))) + return; + + a.is_negative = is_negative; + a.lcm = lcm; + + gid_dict_foreach_subprefix (&lcm->mapping_index_by_gid, eid, + remove_mapping_if_needed, &a); + + vec_foreach (e, a.eids_to_be_deleted) + { + vnet_lisp_add_del_adjacency_args_t _adj_args, *adj_args = &_adj_args; + + clib_memset (adj_args, 0, sizeof (adj_args[0])); + gid_address_copy (&adj_args->reid, e); + adj_args->is_add = 0; + if (vnet_lisp_add_del_adjacency (adj_args)) + clib_warning ("failed to del adjacency!"); + + vnet_lisp_del_mapping (e, NULL); + } + + vec_free (a.eids_to_be_deleted); +} + +static int +is_local_ip (lisp_cp_main_t * lcm, ip_address_t * addr) +{ + fib_node_index_t fei; + fib_prefix_t prefix; + fib_entry_flag_t flags; + + ip_address_to_fib_prefix (addr, &prefix); + + fei = fib_table_lookup (0, &prefix); + flags = fib_entry_get_flags (fei); + return (FIB_ENTRY_FLAG_LOCAL & flags); +} + +/** + * Adds/updates mapping. Does not program forwarding. + * + * @param a parameters of the new mapping + * @param rlocs vector of remote locators + * @param res_map_index index of the newly created mapping + * @param locators_changed indicator if locators were updated in the mapping + * @return return code + */ +int +vnet_lisp_add_mapping (vnet_lisp_add_del_mapping_args_t * a, + locator_t * rlocs, + u32 * res_map_index, u8 * is_updated) +{ + vnet_lisp_add_del_locator_set_args_t _ls_args, *ls_args = &_ls_args; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + u32 mi, ls_index = 0, dst_map_index; + mapping_t *old_map; + locator_t *loc; + + if (vnet_lisp_enable_disable_status () == 0) + { + clib_warning ("LISP is disabled!"); + return VNET_API_ERROR_LISP_DISABLED; + } + + if (res_map_index) + res_map_index[0] = ~0; + if (is_updated) + is_updated[0] = 0; + + clib_memset (ls_args, 0, sizeof (ls_args[0])); + + ls_args->locators = rlocs; + mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &a->eid); + old_map = ((u32) ~ 0 != mi) ? pool_elt_at_index (lcm->mapping_pool, mi) : 0; + + /* check if none of the locators match locally configured address */ + vec_foreach (loc, rlocs) + { + ip_prefix_t *p = &gid_address_ippref (&loc->address); + if (is_local_ip (lcm, &ip_prefix_addr (p))) + { + clib_warning ("RLOC %U matches a local address!", + format_gid_address, &loc->address); + return VNET_API_ERROR_LISP_RLOC_LOCAL; + } + } + + /* overwrite: if mapping already exists, decide if locators should be + * updated and be done */ + if (old_map && gid_address_cmp (&old_map->eid, &a->eid) == 0) + { + if (!a->is_static && (old_map->is_static || old_map->local)) + { + /* do not overwrite local or static remote mappings */ + clib_warning ("mapping %U rejected due to collision with local " + "or static remote mapping!", format_gid_address, + &a->eid); + return 0; + } + + locator_set_t *old_ls; + + /* update mapping attributes */ + old_map->action = a->action; + if (old_map->action != a->action && NULL != is_updated) + is_updated[0] = 1; + + old_map->authoritative = a->authoritative; + old_map->ttl = a->ttl; + + old_ls = pool_elt_at_index (lcm->locator_set_pool, + old_map->locator_set_index); + if (compare_locators (lcm, old_ls->locator_indices, ls_args->locators)) + { + /* set locator-set index to overwrite */ + ls_args->is_add = 1; + ls_args->index = old_map->locator_set_index; + vnet_lisp_add_del_locator_set (ls_args, 0); + if (is_updated) + is_updated[0] = 1; + } + if (res_map_index) + res_map_index[0] = mi; + } + /* new mapping */ + else + { + if (is_updated) + is_updated[0] = 1; + remove_overlapping_sub_prefixes (lcm, &a->eid, 0 == ls_args->locators); + + ls_args->is_add = 1; + ls_args->index = ~0; + + vnet_lisp_add_del_locator_set (ls_args, &ls_index); + + /* add mapping */ + a->is_add = 1; + a->locator_set_index = ls_index; + vnet_lisp_map_cache_add_del (a, &dst_map_index); + + if (res_map_index) + res_map_index[0] = dst_map_index; + } + + /* success */ + return 0; +} + +/** + * Removes a mapping. Does not program forwarding. + * + * @param eid end-host identifier + * @param res_map_index index of the removed mapping + * @return return code + */ +int +vnet_lisp_del_mapping (gid_address_t * eid, u32 * res_map_index) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + vnet_lisp_add_del_mapping_args_t _m_args, *m_args = &_m_args; + vnet_lisp_add_del_locator_set_args_t _ls_args, *ls_args = &_ls_args; + mapping_t *old_map; + u32 mi; + + clib_memset (ls_args, 0, sizeof (ls_args[0])); + clib_memset (m_args, 0, sizeof (m_args[0])); + if (res_map_index) + res_map_index[0] = ~0; + + mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid); + old_map = ((u32) ~ 0 != mi) ? pool_elt_at_index (lcm->mapping_pool, mi) : 0; + + if (old_map == 0 || gid_address_cmp (&old_map->eid, eid) != 0) + { + clib_warning ("cannot delete mapping for eid %U", + format_gid_address, eid); + return -1; + } + + m_args->is_add = 0; + gid_address_copy (&m_args->eid, eid); + m_args->locator_set_index = old_map->locator_set_index; + + ls_args->is_add = 0; + ls_args->index = old_map->locator_set_index; + + /* delete timer associated to the mapping if any */ + if (old_map->timer_set) + TW (tw_timer_stop) (&lcm->wheel, old_map->timer_handle); + + /* delete locator set */ + vnet_lisp_add_del_locator_set (ls_args, 0); + + /* delete mapping associated from map-cache */ + vnet_lisp_map_cache_add_del (m_args, 0); + + /* return old mapping index */ + if (res_map_index) + res_map_index[0] = mi; + + /* success */ + return 0; +} + +int +vnet_lisp_clear_all_remote_adjacencies (void) +{ + int rv = 0; + u32 mi, *map_indices = 0, *map_indexp; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + vnet_lisp_add_del_mapping_args_t _dm_args, *dm_args = &_dm_args; + vnet_lisp_add_del_locator_set_args_t _ls, *ls = &_ls; + + /* *INDENT-OFF* */ + pool_foreach_index (mi, lcm->mapping_pool, + ({ + vec_add1 (map_indices, mi); + })); + /* *INDENT-ON* */ + + vec_foreach (map_indexp, map_indices) + { + mapping_t *map = pool_elt_at_index (lcm->mapping_pool, map_indexp[0]); + if (!map->local) + { + dp_del_fwd_entry (lcm, map_indexp[0]); + + dm_args->is_add = 0; + gid_address_copy (&dm_args->eid, &map->eid); + dm_args->locator_set_index = map->locator_set_index; + + /* delete mapping associated to fwd entry */ + vnet_lisp_map_cache_add_del (dm_args, 0); + + ls->is_add = 0; + ls->local = 0; + ls->index = map->locator_set_index; + /* delete locator set */ + rv = vnet_lisp_add_del_locator_set (ls, 0); + if (rv != 0) + goto cleanup; + } + } + +cleanup: + if (map_indices) + vec_free (map_indices); + return rv; +} + +/** + * Adds adjacency or removes forwarding entry associated to remote mapping. + * Note that adjacencies are not stored, they only result in forwarding entries + * being created. + */ +int +vnet_lisp_add_del_adjacency (vnet_lisp_add_del_adjacency_args_t * a) +{ + lisp_cp_main_t *lcm = &lisp_control_main; + u32 local_mi, remote_mi = ~0; + + if (vnet_lisp_enable_disable_status () == 0) + { + clib_warning ("LISP is disabled!"); + return VNET_API_ERROR_LISP_DISABLED; + } + + remote_mi = gid_dictionary_sd_lookup (&lcm->mapping_index_by_gid, + &a->reid, &a->leid); + if (GID_LOOKUP_MISS == remote_mi) + { + clib_warning ("Remote eid %U not found. Cannot add adjacency!", + format_gid_address, &a->reid); + + return -1; + } + + if (a->is_add) + { + /* check if source eid has an associated mapping. If pitr mode is on, + * just use the pitr's mapping */ + if (lcm->flags & LISP_FLAG_PITR_MODE) + { + if (lcm->pitr_map_index != ~0) + { + local_mi = lcm->pitr_map_index; + } + else + { + /* PITR mode is on, but no mapping is configured */ + return -1; + } + } + else + { + if (gid_address_type (&a->reid) == GID_ADDR_NSH) + { + if (lcm->nsh_map_index == ~0) + local_mi = GID_LOOKUP_MISS; + else + local_mi = lcm->nsh_map_index; + } + else + { + local_mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, + &a->leid); + } + } + + if (GID_LOOKUP_MISS == local_mi) + { + clib_warning ("Local eid %U not found. Cannot add adjacency!", + format_gid_address, &a->leid); + + return -1; + } + + /* update forwarding */ + dp_add_fwd_entry (lcm, local_mi, remote_mi); + } + else + dp_del_fwd_entry (lcm, remote_mi); + + return 0; +} + +int +vnet_lisp_set_map_request_mode (u8 mode) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + + if (vnet_lisp_enable_disable_status () == 0) + { + clib_warning ("LISP is disabled!"); + return VNET_API_ERROR_LISP_DISABLED; + } + + if (mode >= _MR_MODE_MAX) + { + clib_warning ("Invalid LISP map request mode %d!", mode); + return VNET_API_ERROR_INVALID_ARGUMENT; + } + + lcm->map_request_mode = mode; + return 0; +} + +int +vnet_lisp_nsh_set_locator_set (u8 * locator_set_name, u8 is_add) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main (); + u32 locator_set_index = ~0; + mapping_t *m; + uword *p; + + if (vnet_lisp_enable_disable_status () == 0) + { + clib_warning ("LISP is disabled!"); + return VNET_API_ERROR_LISP_DISABLED; + } + + if (is_add) + { + if (lcm->nsh_map_index == (u32) ~ 0) + { + p = hash_get_mem (lcm->locator_set_index_by_name, locator_set_name); + if (!p) + { + clib_warning ("locator-set %v doesn't exist", locator_set_name); + return -1; + } + locator_set_index = p[0]; + + pool_get (lcm->mapping_pool, m); + clib_memset (m, 0, sizeof *m); + m->locator_set_index = locator_set_index; + m->local = 1; + m->nsh_set = 1; + lcm->nsh_map_index = m - lcm->mapping_pool; + + if (~0 == vnet_lisp_gpe_add_nsh_iface (lgm)) + return -1; + } + } + else + { + if (lcm->nsh_map_index != (u32) ~ 0) + { + /* remove NSH mapping */ + pool_put_index (lcm->mapping_pool, lcm->nsh_map_index); + lcm->nsh_map_index = ~0; + vnet_lisp_gpe_del_nsh_iface (lgm); + } + } + return 0; +} + +int +vnet_lisp_pitr_set_locator_set (u8 * locator_set_name, u8 is_add) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + u32 locator_set_index = ~0; + mapping_t *m; + uword *p; + + if (vnet_lisp_enable_disable_status () == 0) + { + clib_warning ("LISP is disabled!"); + return VNET_API_ERROR_LISP_DISABLED; + } + + p = hash_get_mem (lcm->locator_set_index_by_name, locator_set_name); + if (!p) + { + clib_warning ("locator-set %v doesn't exist", locator_set_name); + return -1; + } + locator_set_index = p[0]; + + if (is_add) + { + pool_get (lcm->mapping_pool, m); + m->locator_set_index = locator_set_index; + m->local = 1; + m->pitr_set = 1; + lcm->pitr_map_index = m - lcm->mapping_pool; + } + else + { + /* remove pitr mapping */ + pool_put_index (lcm->mapping_pool, lcm->pitr_map_index); + lcm->pitr_map_index = ~0; + } + return 0; +} + +int +vnet_lisp_map_register_fallback_threshold_set (u32 value) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + if (0 == value) + { + return VNET_API_ERROR_INVALID_ARGUMENT; + } + + lcm->max_expired_map_registers = value; + return 0; +} + +u32 +vnet_lisp_map_register_fallback_threshold_get (void) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + return lcm->max_expired_map_registers; +} + +/** + * Configure Proxy-ETR + * + * @param ip PETR's IP address + * @param is_add Flag that indicates if this is an addition or removal + * + * return 0 on success + */ +int +vnet_lisp_use_petr (ip_address_t * ip, u8 is_add) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + u32 ls_index = ~0; + mapping_t *m; + vnet_lisp_add_del_locator_set_args_t _ls_args, *ls_args = &_ls_args; + locator_t loc; + + if (vnet_lisp_enable_disable_status () == 0) + { + clib_warning ("LISP is disabled!"); + return VNET_API_ERROR_LISP_DISABLED; + } + + clib_memset (ls_args, 0, sizeof (*ls_args)); + + if (is_add) + { + /* Create placeholder petr locator-set */ + clib_memset (&loc, 0, sizeof (loc)); + gid_address_from_ip (&loc.address, ip); + loc.priority = 1; + loc.state = loc.weight = 1; + loc.local = 0; + + ls_args->is_add = 1; + ls_args->index = ~0; + vec_add1 (ls_args->locators, loc); + vnet_lisp_add_del_locator_set (ls_args, &ls_index); + + /* Add petr mapping */ + pool_get (lcm->mapping_pool, m); + m->locator_set_index = ls_index; + lcm->petr_map_index = m - lcm->mapping_pool; + + /* Enable use-petr */ + lcm->flags |= LISP_FLAG_USE_PETR; + } + else + { + m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index); + + /* Remove petr locator */ + ls_args->is_add = 0; + ls_args->index = m->locator_set_index; + vnet_lisp_add_del_locator_set (ls_args, 0); + + /* Remove petr mapping */ + pool_put_index (lcm->mapping_pool, lcm->petr_map_index); + + /* Disable use-petr */ + lcm->flags &= ~LISP_FLAG_USE_PETR; + lcm->petr_map_index = ~0; + } + return 0; +} + +/* cleans locator to locator-set data and removes locators not part of + * any locator-set */ +static void +clean_locator_to_locator_set (lisp_cp_main_t * lcm, u32 lsi) +{ + u32 i, j, *loc_indexp, *ls_indexp, **ls_indexes, *to_be_deleted = 0; + locator_set_t *ls = pool_elt_at_index (lcm->locator_set_pool, lsi); + for (i = 0; i < vec_len (ls->locator_indices); i++) + { + loc_indexp = vec_elt_at_index (ls->locator_indices, i); + ls_indexes = vec_elt_at_index (lcm->locator_to_locator_sets, + loc_indexp[0]); + for (j = 0; j < vec_len (ls_indexes[0]); j++) + { + ls_indexp = vec_elt_at_index (ls_indexes[0], j); + if (ls_indexp[0] == lsi) + break; + } + + /* delete index for removed locator-set */ + vec_del1 (ls_indexes[0], j); + + /* delete locator if it's part of no locator-set */ + if (vec_len (ls_indexes[0]) == 0) + { + pool_put_index (lcm->locator_pool, loc_indexp[0]); + vec_add1 (to_be_deleted, i); + } + } + + if (to_be_deleted) + { + for (i = 0; i < vec_len (to_be_deleted); i++) + { + loc_indexp = vec_elt_at_index (to_be_deleted, i); + vec_del1 (ls->locator_indices, loc_indexp[0]); + } + vec_free (to_be_deleted); + } +} + +static inline uword * +get_locator_set_index (vnet_lisp_add_del_locator_set_args_t * a, uword * p) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + + ASSERT (a != NULL); + ASSERT (p != NULL); + + /* find locator-set */ + if (a->local) + { + ASSERT (a->name); + p = hash_get_mem (lcm->locator_set_index_by_name, a->name); + } + else + { + *p = a->index; + } + + return p; +} + +static inline int +is_locator_in_locator_set (lisp_cp_main_t * lcm, locator_set_t * ls, + locator_t * loc) +{ + locator_t *itloc; + u32 *locit; + + ASSERT (ls != NULL); + ASSERT (loc != NULL); + + vec_foreach (locit, ls->locator_indices) + { + itloc = pool_elt_at_index (lcm->locator_pool, locit[0]); + if ((ls->local && itloc->sw_if_index == loc->sw_if_index) || + (!ls->local && !gid_address_cmp (&itloc->address, &loc->address))) + { + clib_warning ("Duplicate locator"); + return VNET_API_ERROR_VALUE_EXIST; + } + } + + return 0; +} + +static void +update_adjacencies_by_map_index (lisp_cp_main_t * lcm, + u32 mapping_index, u8 remove_only) +{ + fwd_entry_t *fwd; + mapping_t *map; + uword *fei = 0, *rmts_idxp = 0; + u32 **rmts = 0, *remote_idxp = 0, *rmts_copy = 0; + vnet_lisp_add_del_adjacency_args_t _a, *a = &_a; + clib_memset (a, 0, sizeof (*a)); + + map = pool_elt_at_index (lcm->mapping_pool, mapping_index); + + if (map->local) + { + rmts_idxp = hash_get (lcm->lcl_to_rmt_adjs_by_lcl_idx, mapping_index); + if (rmts_idxp) + { + rmts = + pool_elt_at_index (lcm->lcl_to_rmt_adjacencies, rmts_idxp[0]); + rmts_copy = vec_dup (rmts[0]); + + vec_foreach (remote_idxp, rmts_copy) + { + fei = hash_get (lcm->fwd_entry_by_mapping_index, remote_idxp[0]); + if (!fei) + continue; + + fwd = pool_elt_at_index (lcm->fwd_entry_pool, fei[0]); + a->is_add = 0; + gid_address_copy (&a->leid, &fwd->leid); + gid_address_copy (&a->reid, &fwd->reid); + vnet_lisp_add_del_adjacency (a); + + if (!remove_only) + { + a->is_add = 1; + vnet_lisp_add_del_adjacency (a); + } + } + vec_free (rmts_copy); + } + } + else + { + fei = hash_get (lcm->fwd_entry_by_mapping_index, mapping_index); + if (!fei) + return; + + fwd = pool_elt_at_index (lcm->fwd_entry_pool, fei[0]); + a->is_add = 0; + gid_address_copy (&a->leid, &fwd->leid); + gid_address_copy (&a->reid, &fwd->reid); + vnet_lisp_add_del_adjacency (a); + + if (!remove_only) + { + a->is_add = 1; + vnet_lisp_add_del_adjacency (a); + } + } +} + +static void +update_fwd_entries_by_locator_set (lisp_cp_main_t * lcm, + u32 ls_index, u8 remove_only) +{ + u32 i, *map_indexp; + u32 **eid_indexes; + + if (vec_len (lcm->locator_set_to_eids) <= ls_index) + return; + + eid_indexes = vec_elt_at_index (lcm->locator_set_to_eids, ls_index); + + for (i = 0; i < vec_len (eid_indexes[0]); i++) + { + map_indexp = vec_elt_at_index (eid_indexes[0], i); + update_adjacencies_by_map_index (lcm, map_indexp[0], remove_only); + } +} + +static inline void +remove_locator_from_locator_set (locator_set_t * ls, u32 * locit, + u32 ls_index, u32 loc_id) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + u32 **ls_indexes = NULL; + + ASSERT (ls != NULL); + ASSERT (locit != NULL); + + ls_indexes = vec_elt_at_index (lcm->locator_to_locator_sets, locit[0]); + pool_put_index (lcm->locator_pool, locit[0]); + vec_del1 (ls->locator_indices, loc_id); + vec_del1 (ls_indexes[0], ls_index); +} + +int +vnet_lisp_add_del_locator (vnet_lisp_add_del_locator_set_args_t * a, + locator_set_t * ls, u32 * ls_result) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + locator_t *loc = NULL, *itloc = NULL; + uword _p = (u32) ~ 0, *p = &_p; + u32 loc_index = ~0, ls_index = ~0, *locit = NULL, **ls_indexes = NULL; + u32 loc_id = ~0; + int ret = 0; + + ASSERT (a != NULL); + + if (vnet_lisp_enable_disable_status () == 0) + { + clib_warning ("LISP is disabled!"); + return VNET_API_ERROR_LISP_DISABLED; + } + + p = get_locator_set_index (a, p); + if (!p) + { + clib_warning ("locator-set %v doesn't exist", a->name); + return VNET_API_ERROR_INVALID_ARGUMENT; + } + + if (ls == 0) + { + ls = pool_elt_at_index (lcm->locator_set_pool, p[0]); + if (!ls) + { + clib_warning ("locator-set %d to be overwritten doesn't exist!", + p[0]); + return VNET_API_ERROR_INVALID_ARGUMENT; + } + } + + if (a->is_add) + { + if (ls_result) + ls_result[0] = p[0]; + + /* allocate locators */ + vec_foreach (itloc, a->locators) + { + ret = is_locator_in_locator_set (lcm, ls, itloc); + if (0 != ret) + { + return ret; + } + + pool_get (lcm->locator_pool, loc); + loc[0] = itloc[0]; + loc_index = loc - lcm->locator_pool; + + vec_add1 (ls->locator_indices, loc_index); + + vec_validate (lcm->locator_to_locator_sets, loc_index); + ls_indexes = vec_elt_at_index (lcm->locator_to_locator_sets, + loc_index); + vec_add1 (ls_indexes[0], p[0]); + } + } + else + { + ls_index = p[0]; + u8 removed; + + vec_foreach (itloc, a->locators) + { + removed = 0; + loc_id = 0; + vec_foreach (locit, ls->locator_indices) + { + loc = pool_elt_at_index (lcm->locator_pool, locit[0]); + + if (loc->local && loc->sw_if_index == itloc->sw_if_index) + { + removed = 1; + remove_locator_from_locator_set (ls, locit, ls_index, loc_id); + } + else if (0 == loc->local && + !gid_address_cmp (&loc->address, &itloc->address)) + { + removed = 1; + remove_locator_from_locator_set (ls, locit, ls_index, loc_id); + } + + if (removed) + { + /* update fwd entries using this locator in DP */ + update_fwd_entries_by_locator_set (lcm, ls_index, + vec_len (ls->locator_indices) + == 0); + } + + loc_id++; + } + } + } + + return 0; +} + +int +vnet_lisp_add_del_locator_set (vnet_lisp_add_del_locator_set_args_t * a, + u32 * ls_result) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + locator_set_t *ls; + uword _p = (u32) ~ 0, *p = &_p; + u32 ls_index; + u32 **eid_indexes; + int ret = 0; + + if (vnet_lisp_enable_disable_status () == 0) + { + clib_warning ("LISP is disabled!"); + return VNET_API_ERROR_LISP_DISABLED; + } + + if (a->is_add) + { + p = get_locator_set_index (a, p); + + /* overwrite */ + if (p && p[0] != (u32) ~ 0) + { + ls = pool_elt_at_index (lcm->locator_set_pool, p[0]); + if (!ls) + { + clib_warning ("locator-set %d to be overwritten doesn't exist!", + p[0]); + return -1; + } + + /* clean locator to locator-set vectors and remove locators if + * they're not part of another locator-set */ + clean_locator_to_locator_set (lcm, p[0]); + + /* remove locator indices from locator set */ + vec_free (ls->locator_indices); + + ls_index = p[0]; + + if (ls_result) + ls_result[0] = p[0]; + } + /* new locator-set */ + else + { + pool_get (lcm->locator_set_pool, ls); + clib_memset (ls, 0, sizeof (*ls)); + ls_index = ls - lcm->locator_set_pool; + + if (a->local) + { + ls->name = vec_dup (a->name); + + if (!lcm->locator_set_index_by_name) + lcm->locator_set_index_by_name = + hash_create_vec ( /* size */ 0, sizeof (ls->name[0]), + sizeof (uword)); + hash_set_mem (lcm->locator_set_index_by_name, ls->name, + ls_index); + + /* mark as local locator-set */ + vec_add1 (lcm->local_locator_set_indexes, ls_index); + } + ls->local = a->local; + if (ls_result) + ls_result[0] = ls_index; + } + + ret = vnet_lisp_add_del_locator (a, ls, NULL); + if (0 != ret) + { + return ret; + } + } + else + { + p = get_locator_set_index (a, p); + if (!p) + { + clib_warning ("locator-set %v doesn't exists", a->name); + return -1; + } + + ls = pool_elt_at_index (lcm->locator_set_pool, p[0]); + if (!ls) + { + clib_warning ("locator-set with index %d doesn't exists", p[0]); + return -1; + } + + if (lcm->mreq_itr_rlocs == p[0]) + { + clib_warning ("Can't delete the locator-set used to constrain " + "the itr-rlocs in map-requests!"); + return -1; + } + + if (vec_len (lcm->locator_set_to_eids) != 0) + { + eid_indexes = vec_elt_at_index (lcm->locator_set_to_eids, p[0]); + if (vec_len (eid_indexes[0]) != 0) + { + clib_warning + ("Can't delete a locator that supports a mapping!"); + return -1; + } + } + + /* clean locator to locator-sets data */ + clean_locator_to_locator_set (lcm, p[0]); + + if (ls->local) + { + u32 it, lsi; + + vec_foreach_index (it, lcm->local_locator_set_indexes) + { + lsi = vec_elt (lcm->local_locator_set_indexes, it); + if (lsi == p[0]) + { + vec_del1 (lcm->local_locator_set_indexes, it); + break; + } + } + hash_unset_mem (lcm->locator_set_index_by_name, ls->name); + } + vec_free (ls->name); + vec_free (ls->locator_indices); + pool_put (lcm->locator_set_pool, ls); + } + return 0; +} + +int +vnet_lisp_rloc_probe_enable_disable (u8 is_enable) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + + lcm->rloc_probing = is_enable; + return 0; +} + +int +vnet_lisp_map_register_enable_disable (u8 is_enable) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + + lcm->map_registering = is_enable; + return 0; +} + +static void +lisp_cp_register_dst_port (vlib_main_t * vm) +{ + udp_register_dst_port (vm, UDP_DST_PORT_lisp_cp, + lisp_cp_input_node.index, 1 /* is_ip4 */ ); + udp_register_dst_port (vm, UDP_DST_PORT_lisp_cp6, + lisp_cp_input_node.index, 0 /* is_ip4 */ ); +} + +static void +lisp_cp_unregister_dst_port (vlib_main_t * vm) +{ + udp_unregister_dst_port (vm, UDP_DST_PORT_lisp_cp, 0 /* is_ip4 */ ); + udp_unregister_dst_port (vm, UDP_DST_PORT_lisp_cp6, 1 /* is_ip4 */ ); +} + +/** + * lisp_cp_enable_l2_l3_ifaces + * + * Enable all l2 and l3 ifaces + */ +static void +lisp_cp_enable_l2_l3_ifaces (lisp_cp_main_t * lcm, u8 with_default_route) +{ + u32 vni, dp_table; + + /* *INDENT-OFF* */ + hash_foreach(vni, dp_table, lcm->table_id_by_vni, ({ + dp_add_del_iface(lcm, vni, /* is_l2 */ 0, /* is_add */1, + with_default_route); + })); + hash_foreach(vni, dp_table, lcm->bd_id_by_vni, ({ + dp_add_del_iface(lcm, vni, /* is_l2 */ 1, 1, + with_default_route); + })); + /* *INDENT-ON* */ +} + +static void +lisp_cp_disable_l2_l3_ifaces (lisp_cp_main_t * lcm) +{ + u32 **rmts; + + /* clear interface table */ + hash_free (lcm->fwd_entry_by_mapping_index); + pool_free (lcm->fwd_entry_pool); + /* Clear state tracking rmt-lcl fwd entries */ + /* *INDENT-OFF* */ + pool_foreach(rmts, lcm->lcl_to_rmt_adjacencies, + { + vec_free(rmts[0]); + }); + /* *INDENT-ON* */ + hash_free (lcm->lcl_to_rmt_adjs_by_lcl_idx); + pool_free (lcm->lcl_to_rmt_adjacencies); +} + +clib_error_t * +vnet_lisp_enable_disable (u8 is_enable) +{ + clib_error_t *error = 0; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + vnet_lisp_gpe_enable_disable_args_t _a, *a = &_a; + + a->is_en = is_enable; + error = vnet_lisp_gpe_enable_disable (a); + if (error) + { + return clib_error_return (0, "failed to %s data-plane!", + a->is_en ? "enable" : "disable"); + } + + /* decide what to do based on mode */ + + if (lcm->flags & LISP_FLAG_XTR_MODE) + { + if (is_enable) + { + lisp_cp_register_dst_port (lcm->vlib_main); + lisp_cp_enable_l2_l3_ifaces (lcm, 1 /* with_default_route */ ); + } + else + { + lisp_cp_unregister_dst_port (lcm->vlib_main); + lisp_cp_disable_l2_l3_ifaces (lcm); + } + } + + if (lcm->flags & LISP_FLAG_PETR_MODE) + { + /* if in xTR mode, the LISP ports were already (un)registered above */ + if (!(lcm->flags & LISP_FLAG_XTR_MODE)) + { + if (is_enable) + lisp_cp_register_dst_port (lcm->vlib_main); + else + lisp_cp_unregister_dst_port (lcm->vlib_main); + } + } + + if (lcm->flags & LISP_FLAG_PITR_MODE) + { + if (is_enable) + { + /* install interfaces, but no default routes */ + lisp_cp_enable_l2_l3_ifaces (lcm, 0 /* with_default_route */ ); + } + else + { + lisp_cp_disable_l2_l3_ifaces (lcm); + } + } + + if (is_enable) + vnet_lisp_create_retry_process (lcm); + + /* update global flag */ + lcm->is_enabled = is_enable; + + return 0; +} + +u8 +vnet_lisp_enable_disable_status (void) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + return lcm->is_enabled; +} + +int +vnet_lisp_add_del_map_resolver (vnet_lisp_add_del_map_resolver_args_t * a) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + u32 i; + lisp_msmr_t _mr, *mr = &_mr; + + if (vnet_lisp_enable_disable_status () == 0) + { + clib_warning ("LISP is disabled!"); + return VNET_API_ERROR_LISP_DISABLED; + } + + if (a->is_add) + { + + if (get_map_resolver (&a->address)) + { + clib_warning ("map-resolver %U already exists!", format_ip_address, + &a->address); + return -1; + } + + clib_memset (mr, 0, sizeof (*mr)); + ip_address_copy (&mr->address, &a->address); + vec_add1 (lcm->map_resolvers, *mr); + + if (vec_len (lcm->map_resolvers) == 1) + lcm->do_map_resolver_election = 1; + } + else + { + for (i = 0; i < vec_len (lcm->map_resolvers); i++) + { + mr = vec_elt_at_index (lcm->map_resolvers, i); + if (!ip_address_cmp (&mr->address, &a->address)) + { + if (!ip_address_cmp (&mr->address, &lcm->active_map_resolver)) + lcm->do_map_resolver_election = 1; + + vec_del1 (lcm->map_resolvers, i); + break; + } + } + } + return 0; +} + +int +vnet_lisp_map_register_set_ttl (u32 ttl) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + lcm->map_register_ttl = ttl; + return 0; +} + +u32 +vnet_lisp_map_register_get_ttl (void) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + return lcm->map_register_ttl; +} + +int +vnet_lisp_add_del_mreq_itr_rlocs (vnet_lisp_add_del_mreq_itr_rloc_args_t * a) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + uword *p = 0; + + if (vnet_lisp_enable_disable_status () == 0) + { + clib_warning ("LISP is disabled!"); + return VNET_API_ERROR_LISP_DISABLED; + } + + if (a->is_add) + { + p = hash_get_mem (lcm->locator_set_index_by_name, a->locator_set_name); + if (!p) + { + clib_warning ("locator-set %v doesn't exist", a->locator_set_name); + return VNET_API_ERROR_INVALID_ARGUMENT; + } + + lcm->mreq_itr_rlocs = p[0]; + } + else + { + lcm->mreq_itr_rlocs = ~0; + } + + return 0; +} + +/* Statistics (not really errors) */ +#define foreach_lisp_cp_lookup_error \ +_(DROP, "drop") \ +_(MAP_REQUESTS_SENT, "map-request sent") \ +_(ARP_REPLY_TX, "ARP replies sent") \ +_(NDP_NEIGHBOR_ADVERTISEMENT_TX, \ + "neighbor advertisement sent") + +static char *lisp_cp_lookup_error_strings[] = { +#define _(sym,string) string, + foreach_lisp_cp_lookup_error +#undef _ +}; + +typedef enum +{ +#define _(sym,str) LISP_CP_LOOKUP_ERROR_##sym, + foreach_lisp_cp_lookup_error +#undef _ + LISP_CP_LOOKUP_N_ERROR, +} lisp_cp_lookup_error_t; + +typedef enum +{ + LISP_CP_LOOKUP_NEXT_DROP, + LISP_CP_LOOKUP_NEXT_ARP_NDP_REPLY_TX, + LISP_CP_LOOKUP_N_NEXT, +} lisp_cp_lookup_next_t; + +typedef struct +{ + gid_address_t dst_eid; + ip_address_t map_resolver_ip; +} lisp_cp_lookup_trace_t; + +u8 * +format_lisp_cp_lookup_trace (u8 * s, va_list * args) +{ + CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); + CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); + lisp_cp_lookup_trace_t *t = va_arg (*args, lisp_cp_lookup_trace_t *); + + s = format (s, "LISP-CP-LOOKUP: map-resolver: %U destination eid %U", + format_ip_address, &t->map_resolver_ip, format_gid_address, + &t->dst_eid); + return s; +} + +int +get_mr_and_local_iface_ip (lisp_cp_main_t * lcm, ip_address_t * mr_ip, + ip_address_t * sloc) +{ + lisp_msmr_t *mrit; + ip_address_t *a; + + if (vec_len (lcm->map_resolvers) == 0) + { + clib_warning ("No map-resolver configured"); + return 0; + } + + /* find the first mr ip we have a route to and the ip of the + * iface that has a route to it */ + vec_foreach (mrit, lcm->map_resolvers) + { + a = &mrit->address; + if (0 != ip_fib_get_first_egress_ip_for_dst (lcm, a, sloc)) + { + ip_address_copy (mr_ip, a); + + /* also update globals */ + return 1; + } + } + + clib_warning ("Can't find map-resolver and local interface ip!"); + return 0; +} + +static gid_address_t * +build_itr_rloc_list (lisp_cp_main_t * lcm, locator_set_t * loc_set) +{ + void *addr; + u32 i; + locator_t *loc; + u32 *loc_indexp; + ip_interface_address_t *ia = 0; + gid_address_t gid_data, *gid = &gid_data; + gid_address_t *rlocs = 0; + ip_prefix_t *ippref = &gid_address_ippref (gid); + ip_address_t *rloc = &ip_prefix_addr (ippref); + + clib_memset (gid, 0, sizeof (gid[0])); + gid_address_type (gid) = GID_ADDR_IP_PREFIX; + for (i = 0; i < vec_len (loc_set->locator_indices); i++) + { + loc_indexp = vec_elt_at_index (loc_set->locator_indices, i); + loc = pool_elt_at_index (lcm->locator_pool, loc_indexp[0]); + + /* Add ipv4 locators first TODO sort them */ + + /* *INDENT-OFF* */ + foreach_ip_interface_address (&lcm->im4->lookup_main, ia, + loc->sw_if_index, 1 /* unnumbered */, + ({ + addr = ip_interface_address_get_address (&lcm->im4->lookup_main, ia); + ip_address_set (rloc, addr, AF_IP4); + ip_prefix_len (ippref) = 32; + ip_prefix_normalize (ippref); + vec_add1 (rlocs, gid[0]); + })); + + /* Add ipv6 locators */ + foreach_ip_interface_address (&lcm->im6->lookup_main, ia, + loc->sw_if_index, 1 /* unnumbered */, + ({ + addr = ip_interface_address_get_address (&lcm->im6->lookup_main, ia); + ip_address_set (rloc, addr, AF_IP6); + ip_prefix_len (ippref) = 128; + ip_prefix_normalize (ippref); + vec_add1 (rlocs, gid[0]); + })); + /* *INDENT-ON* */ + + } + return rlocs; +} + +static vlib_buffer_t * +build_map_request (lisp_cp_main_t * lcm, gid_address_t * deid, + ip_address_t * sloc, ip_address_t * rloc, + gid_address_t * itr_rlocs, u64 * nonce_res, u32 * bi_res) +{ + vlib_buffer_t *b; + u32 bi; + vlib_main_t *vm = lcm->vlib_main; + + if (vlib_buffer_alloc (vm, &bi, 1) != 1) + { + clib_warning ("Can't allocate buffer for Map-Request!"); + return 0; + } + + b = vlib_get_buffer (vm, bi); + + /* leave some space for the encap headers */ + vlib_buffer_make_headroom (b, MAX_LISP_MSG_ENCAP_LEN); + + /* put lisp msg */ + lisp_msg_put_mreq (lcm, b, NULL, deid, itr_rlocs, 0 /* smr invoked */ , + 1 /* rloc probe */ , nonce_res); + + /* push outer ip header */ + pkt_push_udp_and_ip (vm, b, LISP_CONTROL_PORT, LISP_CONTROL_PORT, sloc, + rloc, 1); + + bi_res[0] = bi; + + return b; +} + +static vlib_buffer_t * +build_encapsulated_map_request (lisp_cp_main_t * lcm, + gid_address_t * seid, gid_address_t * deid, + locator_set_t * loc_set, ip_address_t * mr_ip, + ip_address_t * sloc, u8 is_smr_invoked, + u64 * nonce_res, u32 * bi_res) +{ + vlib_buffer_t *b; + u32 bi; + gid_address_t *rlocs = 0; + vlib_main_t *vm = lcm->vlib_main; + + if (vlib_buffer_alloc (vm, &bi, 1) != 1) + { + clib_warning ("Can't allocate buffer for Map-Request!"); + return 0; + } + + b = vlib_get_buffer (vm, bi); + b->flags = 0; + + /* leave some space for the encap headers */ + vlib_buffer_make_headroom (b, MAX_LISP_MSG_ENCAP_LEN); + + /* get rlocs */ + rlocs = build_itr_rloc_list (lcm, loc_set); + + if (MR_MODE_SRC_DST == lcm->map_request_mode + && GID_ADDR_SRC_DST != gid_address_type (deid)) + { + gid_address_t sd; + clib_memset (&sd, 0, sizeof (sd)); + build_src_dst (&sd, seid, deid); + lisp_msg_put_mreq (lcm, b, seid, &sd, rlocs, is_smr_invoked, + 0 /* rloc probe */ , nonce_res); + } + else + { + /* put lisp msg */ + lisp_msg_put_mreq (lcm, b, seid, deid, rlocs, is_smr_invoked, + 0 /* rloc probe */ , nonce_res); + } + + /* push ecm: udp-ip-lisp */ + lisp_msg_push_ecm (vm, b, LISP_CONTROL_PORT, LISP_CONTROL_PORT, seid, deid); + + /* push outer ip header */ + pkt_push_udp_and_ip (vm, b, LISP_CONTROL_PORT, LISP_CONTROL_PORT, sloc, + mr_ip, 1); + + bi_res[0] = bi; + + vec_free (rlocs); + return b; +} + +static void +reset_pending_mr_counters (pending_map_request_t * r) +{ + r->time_to_expire = PENDING_MREQ_EXPIRATION_TIME; + r->retries_num = 0; +} + +#define foreach_msmr \ + _(server) \ + _(resolver) + +#define _(name) \ +static int \ +elect_map_ ## name (lisp_cp_main_t * lcm) \ +{ \ + lisp_msmr_t *mr; \ + vec_foreach (mr, lcm->map_ ## name ## s) \ + { \ + if (!mr->is_down) \ + { \ + ip_address_copy (&lcm->active_map_ ##name, &mr->address); \ + lcm->do_map_ ## name ## _election = 0; \ + return 1; \ + } \ + } \ + return 0; \ +} +foreach_msmr +#undef _ + static void +free_map_register_records (mapping_t * maps) +{ + mapping_t *map; + vec_foreach (map, maps) vec_free (map->locators); + + vec_free (maps); +} + +static void +add_locators (lisp_cp_main_t * lcm, mapping_t * m, u32 locator_set_index, + ip_address_t * probed_loc) +{ + u32 *li; + locator_t *loc, new; + ip_interface_address_t *ia = 0; + void *addr; + ip_address_t *new_ip = &gid_address_ip (&new.address); + + m->locators = 0; + locator_set_t *ls = pool_elt_at_index (lcm->locator_set_pool, + locator_set_index); + vec_foreach (li, ls->locator_indices) + { + loc = pool_elt_at_index (lcm->locator_pool, li[0]); + new = loc[0]; + if (loc->local) + { + /* *INDENT-OFF* */ + foreach_ip_interface_address (&lcm->im4->lookup_main, ia, + loc->sw_if_index, 1 /* unnumbered */, + ({ + addr = ip_interface_address_get_address (&lcm->im4->lookup_main, + ia); + ip_address_set (new_ip, addr, AF_IP4); + })); + + /* Add ipv6 locators */ + foreach_ip_interface_address (&lcm->im6->lookup_main, ia, + loc->sw_if_index, 1 /* unnumbered */, + ({ + addr = ip_interface_address_get_address (&lcm->im6->lookup_main, + ia); + ip_address_set (new_ip, addr, AF_IP6); + })); + /* *INDENT-ON* */ + + if (probed_loc && ip_address_cmp (probed_loc, new_ip) == 0) + new.probed = 1; + } + vec_add1 (m->locators, new); + } +} + +static mapping_t * +build_map_register_record_list (lisp_cp_main_t * lcm) +{ + mapping_t *recs = 0, rec, *m; + + /* *INDENT-OFF* */ + pool_foreach(m, lcm->mapping_pool, + { + /* for now build only local mappings */ + if (!m->local) + continue; + + rec = m[0]; + add_locators (lcm, &rec, m->locator_set_index, NULL); + vec_add1 (recs, rec); + }); + /* *INDENT-ON* */ + + return recs; +} + +static vnet_crypto_alg_t +lisp_key_type_to_crypto_alg (lisp_key_type_t key_id) +{ + switch (key_id) + { + case HMAC_SHA_1_96: + return VNET_CRYPTO_ALG_HMAC_SHA1; + case HMAC_SHA_256_128: + return VNET_CRYPTO_ALG_HMAC_SHA256; + default: + clib_warning ("unsupported encryption key type: %d!", key_id); + break; + } + return VNET_CRYPTO_ALG_NONE; +} + +static vnet_crypto_op_id_t +lisp_key_type_to_crypto_op (lisp_key_type_t key_id) +{ + switch (key_id) + { + case HMAC_SHA_1_96: + return VNET_CRYPTO_OP_SHA1_HMAC; + case HMAC_SHA_256_128: + return VNET_CRYPTO_OP_SHA256_HMAC; + default: + clib_warning ("unsupported encryption key type: %d!", key_id); + break; + } + return VNET_CRYPTO_OP_NONE; +} + +static int +update_map_register_auth_data (map_register_hdr_t * map_reg_hdr, + lisp_key_type_t key_id, u8 * key, + u16 auth_data_len, u32 msg_len) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + MREG_KEY_ID (map_reg_hdr) = clib_host_to_net_u16 (key_id); + MREG_AUTH_DATA_LEN (map_reg_hdr) = clib_host_to_net_u16 (auth_data_len); + vnet_crypto_op_t _op, *op = &_op; + vnet_crypto_key_index_t ki; + + vnet_crypto_op_init (op, lisp_key_type_to_crypto_op (key_id)); + op->len = msg_len; + op->digest = MREG_DATA (map_reg_hdr); + op->src = (u8 *) map_reg_hdr; + op->digest_len = 0; + op->iv = 0; + + ki = vnet_crypto_key_add (lcm->vlib_main, + lisp_key_type_to_crypto_alg (key_id), key, + vec_len (key)); + + op->key_index = ki; + + vnet_crypto_process_ops (lcm->vlib_main, op, 1); + vnet_crypto_key_del (lcm->vlib_main, ki); + + return 0; +} + +static vlib_buffer_t * +build_map_register (lisp_cp_main_t * lcm, ip_address_t * sloc, + ip_address_t * ms_ip, u64 * nonce_res, u8 want_map_notif, + mapping_t * records, lisp_key_type_t key_id, u8 * key, + u32 * bi_res) +{ + void *map_reg_hdr; + vlib_buffer_t *b; + u32 bi, auth_data_len = 0, msg_len = 0; + vlib_main_t *vm = lcm->vlib_main; + + if (vlib_buffer_alloc (vm, &bi, 1) != 1) + { + clib_warning ("Can't allocate buffer for Map-Register!"); + return 0; + } + + b = vlib_get_buffer (vm, bi); + + /* leave some space for the encap headers */ + vlib_buffer_make_headroom (b, MAX_LISP_MSG_ENCAP_LEN); + + auth_data_len = auth_data_len_by_key_id (key_id); + map_reg_hdr = lisp_msg_put_map_register (b, records, want_map_notif, + auth_data_len, nonce_res, + &msg_len); + + update_map_register_auth_data (map_reg_hdr, key_id, key, auth_data_len, + msg_len); + + /* push outer ip header */ + pkt_push_udp_and_ip (vm, b, LISP_CONTROL_PORT, LISP_CONTROL_PORT, sloc, + ms_ip, 1); + + bi_res[0] = bi; + return b; +} + +#define _(name) \ +static int \ +get_egress_map_ ##name## _ip (lisp_cp_main_t * lcm, ip_address_t * ip) \ +{ \ + lisp_msmr_t *mr; \ + while (lcm->do_map_ ## name ## _election \ + | (0 == ip_fib_get_first_egress_ip_for_dst \ + (lcm, &lcm->active_map_ ##name, ip))) \ + { \ + if (0 == elect_map_ ## name (lcm)) \ + /* all map resolvers/servers are down */ \ + { \ + /* restart MR/MS checking by marking all of them up */ \ + vec_foreach (mr, lcm->map_ ## name ## s) mr->is_down = 0; \ + return -1; \ + } \ + } \ + return 0; \ +} + +foreach_msmr +#undef _ +/* CP output statistics */ +#define foreach_lisp_cp_output_error \ +_(MAP_REGISTERS_SENT, "map-registers sent") \ +_(MAP_REQUESTS_SENT, "map-requests sent") \ +_(RLOC_PROBES_SENT, "rloc-probes sent") +static char *lisp_cp_output_error_strings[] = { +#define _(sym,string) string, + foreach_lisp_cp_output_error +#undef _ +}; + +typedef enum +{ +#define _(sym,str) LISP_CP_OUTPUT_ERROR_##sym, + foreach_lisp_cp_output_error +#undef _ + LISP_CP_OUTPUT_N_ERROR, +} lisp_cp_output_error_t; + +static uword +lisp_cp_output (vlib_main_t * vm, vlib_node_runtime_t * node, + vlib_frame_t * from_frame) +{ + return 0; +} + +/* placeholder node used only for statistics */ +/* *INDENT-OFF* */ +VLIB_REGISTER_NODE (lisp_cp_output_node) = { + .function = lisp_cp_output, + .name = "lisp-cp-output", + .vector_size = sizeof (u32), + .format_trace = format_lisp_cp_input_trace, + .type = VLIB_NODE_TYPE_INTERNAL, + + .n_errors = LISP_CP_OUTPUT_N_ERROR, + .error_strings = lisp_cp_output_error_strings, + + .n_next_nodes = LISP_CP_INPUT_N_NEXT, + + .next_nodes = { + [LISP_CP_INPUT_NEXT_DROP] = "error-drop", + }, +}; +/* *INDENT-ON* */ + +static int +send_rloc_probe (lisp_cp_main_t * lcm, gid_address_t * deid, + u32 local_locator_set_index, ip_address_t * sloc, + ip_address_t * rloc) +{ + locator_set_t *ls; + u32 bi; + vlib_buffer_t *b; + vlib_frame_t *f; + u64 nonce = 0; + u32 next_index, *to_next; + gid_address_t *itr_rlocs; + + ls = pool_elt_at_index (lcm->locator_set_pool, local_locator_set_index); + itr_rlocs = build_itr_rloc_list (lcm, ls); + + b = build_map_request (lcm, deid, sloc, rloc, itr_rlocs, &nonce, &bi); + vec_free (itr_rlocs); + if (!b) + return -1; + + vnet_buffer (b)->sw_if_index[VLIB_TX] = 0; + + next_index = (ip_addr_version (rloc) == AF_IP4) ? + ip4_lookup_node.index : ip6_lookup_node.index; + + f = vlib_get_frame_to_node (lcm->vlib_main, next_index); + + /* Enqueue the packet */ + to_next = vlib_frame_vector_args (f); + to_next[0] = bi; + f->n_vectors = 1; + vlib_put_frame_to_node (lcm->vlib_main, next_index, f); + + return 0; +} + +static int +send_rloc_probes (lisp_cp_main_t * lcm) +{ + u8 lprio = 0; + mapping_t *lm; + fwd_entry_t *e; + locator_pair_t *lp; + u32 si, rloc_probes_sent = 0; + + /* *INDENT-OFF* */ + pool_foreach (e, lcm->fwd_entry_pool, + { + if (vec_len (e->locator_pairs) == 0) + continue; + + si = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &e->leid); + if (~0 == si) + { + clib_warning ("internal error: cannot find local eid %U in " + "map-cache!", format_gid_address, &e->leid); + continue; + } + lm = pool_elt_at_index (lcm->mapping_pool, si); + + /* get the best (lowest) priority */ + lprio = e->locator_pairs[0].priority; + + /* send rloc-probe for pair(s) with the best remote locator priority */ + vec_foreach (lp, e->locator_pairs) + { + if (lp->priority != lprio) + break; + + /* get first remote locator */ + send_rloc_probe (lcm, &e->reid, lm->locator_set_index, &lp->lcl_loc, + &lp->rmt_loc); + rloc_probes_sent++; + } + }); + /* *INDENT-ON* */ + + vlib_node_increment_counter (vlib_get_main (), lisp_cp_output_node.index, + LISP_CP_OUTPUT_ERROR_RLOC_PROBES_SENT, + rloc_probes_sent); + return 0; +} + +static int +send_map_register (lisp_cp_main_t * lcm, u8 want_map_notif) +{ + pending_map_register_t *pmr; + u32 bi, map_registers_sent = 0; + vlib_buffer_t *b; + ip_address_t sloc; + vlib_frame_t *f; + u64 nonce = 0; + u32 next_index, *to_next; + mapping_t *records, *r, *group, *k; + + if (get_egress_map_server_ip (lcm, &sloc) < 0) + return -1; + + records = build_map_register_record_list (lcm); + if (!records) + return -1; + + vec_foreach (r, records) + { + u8 *key = r->key; + u8 key_id = r->key_id; + + if (!key) + continue; /* no secret key -> map-register cannot be sent */ + + group = 0; + vec_add1 (group, r[0]); + + /* group mappings that share common key */ + for (k = r + 1; k < vec_end (records); k++) + { + if (k->key_id != r->key_id) + continue; + + if (vec_is_equal (k->key, r->key)) + { + vec_add1 (group, k[0]); + k->key = 0; /* don't process this mapping again */ + } + } + + b = build_map_register (lcm, &sloc, &lcm->active_map_server, &nonce, + want_map_notif, group, key_id, key, &bi); + vec_free (group); + if (!b) + continue; + + vnet_buffer (b)->sw_if_index[VLIB_TX] = 0; + + next_index = (ip_addr_version (&lcm->active_map_server) == AF_IP4) ? + ip4_lookup_node.index : ip6_lookup_node.index; + + f = vlib_get_frame_to_node (lcm->vlib_main, next_index); + + /* Enqueue the packet */ + to_next = vlib_frame_vector_args (f); + to_next[0] = bi; + f->n_vectors = 1; + vlib_put_frame_to_node (lcm->vlib_main, next_index, f); + map_registers_sent++; + + pool_get (lcm->pending_map_registers_pool, pmr); + clib_memset (pmr, 0, sizeof (*pmr)); + pmr->time_to_expire = PENDING_MREG_EXPIRATION_TIME; + hash_set (lcm->map_register_messages_by_nonce, nonce, + pmr - lcm->pending_map_registers_pool); + } + free_map_register_records (records); + + vlib_node_increment_counter (vlib_get_main (), lisp_cp_output_node.index, + LISP_CP_OUTPUT_ERROR_MAP_REGISTERS_SENT, + map_registers_sent); + + return 0; +} + +#define send_encapsulated_map_request(lcm, seid, deid, smr) \ + _send_encapsulated_map_request(lcm, seid, deid, smr, 0) + +#define resend_encapsulated_map_request(lcm, seid, deid, smr) \ + _send_encapsulated_map_request(lcm, seid, deid, smr, 1) + +static int +_send_encapsulated_map_request (lisp_cp_main_t * lcm, + gid_address_t * seid, gid_address_t * deid, + u8 is_smr_invoked, u8 is_resend) +{ + u32 next_index, bi = 0, *to_next, map_index; + vlib_buffer_t *b; + vlib_frame_t *f; + u64 nonce = 0; + locator_set_t *loc_set; + mapping_t *map; + pending_map_request_t *pmr, *duplicate_pmr = 0; + ip_address_t sloc; + u32 ls_index; + + /* if there is already a pending request remember it */ + + /* *INDENT-OFF* */ + pool_foreach(pmr, lcm->pending_map_requests_pool, + ({ + if (!gid_address_cmp (&pmr->src, seid) + && !gid_address_cmp (&pmr->dst, deid)) + { + duplicate_pmr = pmr; + break; + } + })); + /* *INDENT-ON* */ + + if (!is_resend && duplicate_pmr) + { + /* don't send the request if there is a pending map request already */ + return 0; + } + + u8 pitr_mode = lcm->flags & LISP_FLAG_PITR_MODE; + + /* get locator-set for seid */ + if (!pitr_mode && gid_address_type (deid) != GID_ADDR_NSH) + { + map_index = gid_dictionary_lookup (&lcm->mapping_index_by_gid, seid); + if (map_index == ~0) + { + clib_warning ("No local mapping found in eid-table for %U!", + format_gid_address, seid); + return -1; + } + + map = pool_elt_at_index (lcm->mapping_pool, map_index); + + if (!map->local) + { + clib_warning + ("Mapping found for src eid %U is not marked as local!", + format_gid_address, seid); + return -1; + } + ls_index = map->locator_set_index; + } + else + { + if (pitr_mode) + { + if (lcm->pitr_map_index != ~0) + { + map = + pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index); + ls_index = map->locator_set_index; + } + else + { + return -1; + } + } + else + { + if (lcm->nsh_map_index == (u32) ~ 0) + { + clib_warning ("No locator-set defined for NSH!"); + return -1; + } + else + { + map = pool_elt_at_index (lcm->mapping_pool, lcm->nsh_map_index); + ls_index = map->locator_set_index; + } + } + } + + /* overwrite locator set if map-request itr-rlocs configured */ + if (~0 != lcm->mreq_itr_rlocs) + { + ls_index = lcm->mreq_itr_rlocs; + } + + loc_set = pool_elt_at_index (lcm->locator_set_pool, ls_index); + + if (get_egress_map_resolver_ip (lcm, &sloc) < 0) + { + if (duplicate_pmr) + duplicate_pmr->to_be_removed = 1; + return -1; + } + + /* build the encapsulated map request */ + b = build_encapsulated_map_request (lcm, seid, deid, loc_set, + &lcm->active_map_resolver, + &sloc, is_smr_invoked, &nonce, &bi); + + if (!b) + return -1; + + /* set fib index to default and lookup node */ + vnet_buffer (b)->sw_if_index[VLIB_TX] = 0; + next_index = (ip_addr_version (&lcm->active_map_resolver) == AF_IP4) ? + ip4_lookup_node.index : ip6_lookup_node.index; + + f = vlib_get_frame_to_node (lcm->vlib_main, next_index); + + /* Enqueue the packet */ + to_next = vlib_frame_vector_args (f); + to_next[0] = bi; + f->n_vectors = 1; + vlib_put_frame_to_node (lcm->vlib_main, next_index, f); + + vlib_node_increment_counter (vlib_get_main (), lisp_cp_output_node.index, + LISP_CP_OUTPUT_ERROR_MAP_REQUESTS_SENT, 1); + + if (duplicate_pmr) + /* if there is a pending request already update it */ + { + if (clib_fifo_elts (duplicate_pmr->nonces) >= PENDING_MREQ_QUEUE_LEN) + { + /* remove the oldest nonce */ + u64 CLIB_UNUSED (tmp), *nonce_del; + nonce_del = clib_fifo_head (duplicate_pmr->nonces); + hash_unset (lcm->pending_map_requests_by_nonce, nonce_del[0]); + clib_fifo_sub1 (duplicate_pmr->nonces, tmp); + } + + clib_fifo_add1 (duplicate_pmr->nonces, nonce); + hash_set (lcm->pending_map_requests_by_nonce, nonce, + duplicate_pmr - lcm->pending_map_requests_pool); + } + else + { + /* add map-request to pending requests table */ + pool_get (lcm->pending_map_requests_pool, pmr); + clib_memset (pmr, 0, sizeof (*pmr)); + gid_address_copy (&pmr->src, seid); + gid_address_copy (&pmr->dst, deid); + clib_fifo_add1 (pmr->nonces, nonce); + pmr->is_smr_invoked = is_smr_invoked; + reset_pending_mr_counters (pmr); + hash_set (lcm->pending_map_requests_by_nonce, nonce, + pmr - lcm->pending_map_requests_pool); + } + + return 0; +} + +static void +get_src_and_dst_ip (void *hdr, ip_address_t * src, ip_address_t * dst) +{ + ip4_header_t *ip4 = hdr; + ip6_header_t *ip6; + + if ((ip4->ip_version_and_header_length & 0xF0) == 0x40) + { + ip_address_set (src, &ip4->src_address, AF_IP4); + ip_address_set (dst, &ip4->dst_address, AF_IP4); + } + else + { + ip6 = hdr; + ip_address_set (src, &ip6->src_address, AF_IP6); + ip_address_set (dst, &ip6->dst_address, AF_IP6); + } +} + +static u32 +lisp_get_vni_from_buffer_ip (lisp_cp_main_t * lcm, vlib_buffer_t * b, + u8 version) +{ + uword *vnip; + u32 vni = ~0, table_id = ~0; + + table_id = fib_table_get_table_id_for_sw_if_index ((version == + AF_IP4 ? + FIB_PROTOCOL_IP4 : + FIB_PROTOCOL_IP6), + vnet_buffer + (b)->sw_if_index + [VLIB_RX]); + + vnip = hash_get (lcm->vni_by_table_id, table_id); + if (vnip) + vni = vnip[0]; + else + clib_warning ("vrf %d is not mapped to any vni!", table_id); + + return vni; +} + +always_inline u32 +lisp_get_bd_from_buffer_eth (vlib_buffer_t * b) +{ + u32 sw_if_index0; + + l2input_main_t *l2im = &l2input_main; + l2_input_config_t *config; + l2_bridge_domain_t *bd_config; + + sw_if_index0 = vnet_buffer (b)->sw_if_index[VLIB_RX]; + config = vec_elt_at_index (l2im->configs, sw_if_index0); + bd_config = vec_elt_at_index (l2im->bd_configs, config->bd_index); + + return bd_config->bd_id; +} + +always_inline u32 +lisp_get_vni_from_buffer_eth (lisp_cp_main_t * lcm, vlib_buffer_t * b) +{ + uword *vnip; + u32 vni = ~0; + u32 bd = lisp_get_bd_from_buffer_eth (b); + + vnip = hash_get (lcm->vni_by_bd_id, bd); + if (vnip) + vni = vnip[0]; + else + clib_warning ("bridge domain %d is not mapped to any vni!", bd); + + return vni; +} + +void +get_src_and_dst_eids_from_buffer (lisp_cp_main_t * lcm, vlib_buffer_t * b, + gid_address_t * src, gid_address_t * dst, + u16 type) +{ + ethernet_header_t *eh; + u32 vni = 0; + icmp6_neighbor_discovery_ethernet_link_layer_address_option_t *opt; + + clib_memset (src, 0, sizeof (*src)); + clib_memset (dst, 0, sizeof (*dst)); + + gid_address_type (dst) = GID_ADDR_NO_ADDRESS; + gid_address_type (src) = GID_ADDR_NO_ADDRESS; + + if (LISP_AFI_IP == type || LISP_AFI_IP6 == type) + { + ip4_header_t *ip; + u8 version, preflen; + + gid_address_type (src) = GID_ADDR_IP_PREFIX; + gid_address_type (dst) = GID_ADDR_IP_PREFIX; + + ip = vlib_buffer_get_current (b); + get_src_and_dst_ip (ip, &gid_address_ip (src), &gid_address_ip (dst)); + + version = gid_address_ip_version (src); + preflen = ip_address_max_len (version); + gid_address_ippref_len (src) = preflen; + gid_address_ippref_len (dst) = preflen; + + vni = lisp_get_vni_from_buffer_ip (lcm, b, version); + gid_address_vni (dst) = vni; + gid_address_vni (src) = vni; + } + else if (LISP_AFI_MAC == type) + { + ethernet_arp_header_t *ah; + + eh = vlib_buffer_get_current (b); + + if (clib_net_to_host_u16 (eh->type) == ETHERNET_TYPE_ARP) + { + ah = (ethernet_arp_header_t *) (((u8 *) eh) + sizeof (*eh)); + gid_address_type (dst) = GID_ADDR_ARP; + + if (clib_net_to_host_u16 (ah->opcode) + != ETHERNET_ARP_OPCODE_request) + { + clib_memset (&gid_address_arp_ndp_ip (dst), 0, + sizeof (ip_address_t)); + ip_addr_version (&gid_address_arp_ndp_ip (dst)) = AF_IP4; + gid_address_arp_ndp_bd (dst) = ~0; + return; + } + + gid_address_arp_bd (dst) = lisp_get_bd_from_buffer_eth (b); + clib_memcpy (&gid_address_arp_ip4 (dst), + &ah->ip4_over_ethernet[1].ip4, 4); + } + else + { + if (clib_net_to_host_u16 (eh->type) == ETHERNET_TYPE_IP6) + { + ip6_header_t *ip; + ip = (ip6_header_t *) (eh + 1); + + if (IP_PROTOCOL_ICMP6 == ip->protocol) + { + icmp6_neighbor_solicitation_or_advertisement_header_t *ndh; + ndh = ip6_next_header (ip); + if (ndh->icmp.type == ICMP6_neighbor_solicitation) + { + gid_address_type (dst) = GID_ADDR_NDP; + + /* check that source link layer address option is present */ + opt = (void *) (ndh + 1); + if ((opt->header.type != + ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address) + || (opt->header.n_data_u64s != 1)) + { + clib_memset (&gid_address_arp_ndp_ip (dst), 0, + sizeof (ip_address_t)); + ip_addr_version (&gid_address_arp_ndp_ip (dst)) = + AF_IP6; + gid_address_arp_ndp_bd (dst) = ~0; + gid_address_type (src) = GID_ADDR_NO_ADDRESS; + return; + } + + gid_address_ndp_bd (dst) = + lisp_get_bd_from_buffer_eth (b); + ip_address_set (&gid_address_arp_ndp_ip (dst), + &ndh->target_address, AF_IP6); + return; + } + } + } + + gid_address_type (src) = GID_ADDR_MAC; + gid_address_type (dst) = GID_ADDR_MAC; + mac_copy (&gid_address_mac (src), eh->src_address); + mac_copy (&gid_address_mac (dst), eh->dst_address); + + /* get vni */ + vni = lisp_get_vni_from_buffer_eth (lcm, b); + + gid_address_vni (dst) = vni; + gid_address_vni (src) = vni; + } + } + else if (LISP_AFI_LCAF == type) + { + lisp_nsh_hdr_t *nh; + eh = vlib_buffer_get_current (b); + + if (clib_net_to_host_u16 (eh->type) == ETHERNET_TYPE_NSH) + { + nh = (lisp_nsh_hdr_t *) (((u8 *) eh) + sizeof (*eh)); + u32 spi = clib_net_to_host_u32 (nh->spi_si << 8); + u8 si = (u8) clib_net_to_host_u32 (nh->spi_si); + gid_address_nsh_spi (dst) = spi; + gid_address_nsh_si (dst) = si; + + gid_address_type (dst) = GID_ADDR_NSH; + gid_address_type (src) = GID_ADDR_NSH; + } + } +} + +static uword +lisp_cp_lookup_inline (vlib_main_t * vm, + vlib_node_runtime_t * node, + vlib_frame_t * from_frame, int overlay) +{ + icmp6_neighbor_discovery_ethernet_link_layer_address_option_t *opt; + u32 *from, *to_next, di, si; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + u32 next_index; + uword n_left_from, n_left_to_next; + vnet_main_t *vnm = vnet_get_main (); + + from = vlib_frame_vector_args (from_frame); + n_left_from = from_frame->n_vectors; + next_index = node->cached_next_index; + + while (n_left_from > 0) + { + vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); + + while (n_left_from > 0 && n_left_to_next > 0) + { + u32 pi0, sw_if_index0, next0; + u64 mac0; + vlib_buffer_t *b0; + gid_address_t src, dst; + ethernet_arp_header_t *arp0; + ethernet_header_t *eth0; + vnet_hw_interface_t *hw_if0; + ethernet_header_t *eh0; + icmp6_neighbor_solicitation_or_advertisement_header_t *ndh; + ip6_header_t *ip0; + + pi0 = from[0]; + from += 1; + n_left_from -= 1; + to_next[0] = pi0; + to_next += 1; + n_left_to_next -= 1; + + b0 = vlib_get_buffer (vm, pi0); + + /* src/dst eid pair */ + get_src_and_dst_eids_from_buffer (lcm, b0, &src, &dst, overlay); + + if (gid_address_type (&dst) == GID_ADDR_ARP) + { + mac0 = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &dst); + if (GID_LOOKUP_MISS_L2 == mac0) + goto drop; + + /* send ARP reply */ + sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX]; + vnet_buffer (b0)->sw_if_index[VLIB_TX] = sw_if_index0; + + hw_if0 = vnet_get_sup_hw_interface (vnm, sw_if_index0); + + eth0 = vlib_buffer_get_current (b0); + arp0 = (ethernet_arp_header_t *) (((u8 *) eth0) + + sizeof (*eth0)); + arp0->opcode = clib_host_to_net_u16 (ETHERNET_ARP_OPCODE_reply); + arp0->ip4_over_ethernet[1] = arp0->ip4_over_ethernet[0]; + mac_address_from_u64 (&arp0->ip4_over_ethernet[0].mac, mac0); + clib_memcpy (&arp0->ip4_over_ethernet[0].ip4, + &gid_address_arp_ip4 (&dst), 4); + + /* Hardware must be ethernet-like. */ + ASSERT (vec_len (hw_if0->hw_address) == 6); + + clib_memcpy (eth0->dst_address, eth0->src_address, 6); + clib_memcpy (eth0->src_address, hw_if0->hw_address, 6); + + b0->error = node->errors[LISP_CP_LOOKUP_ERROR_ARP_REPLY_TX]; + next0 = LISP_CP_LOOKUP_NEXT_ARP_NDP_REPLY_TX; + goto enqueue; + } + else if (gid_address_type (&dst) == GID_ADDR_NDP) + { + mac0 = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &dst); + if (GID_LOOKUP_MISS_L2 == mac0) + goto drop; + + sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX]; + vnet_buffer (b0)->sw_if_index[VLIB_TX] = sw_if_index0; + + eh0 = vlib_buffer_get_current (b0); + ip0 = (ip6_header_t *) (eh0 + 1); + ndh = ip6_next_header (ip0); + int bogus_length; + ip0->dst_address = ip0->src_address; + ip0->src_address = ndh->target_address; + ip0->hop_limit = 255; + opt = (void *) (ndh + 1); + opt->header.type = + ICMP6_NEIGHBOR_DISCOVERY_OPTION_target_link_layer_address; + clib_memcpy (opt->ethernet_address, (u8 *) & mac0, 6); + ndh->icmp.type = ICMP6_neighbor_advertisement; + ndh->advertisement_flags = clib_host_to_net_u32 + (ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_SOLICITED | + ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_OVERRIDE); + ndh->icmp.checksum = 0; + ndh->icmp.checksum = + ip6_tcp_udp_icmp_compute_checksum (vm, b0, ip0, + &bogus_length); + clib_memcpy (eh0->dst_address, eh0->src_address, 6); + clib_memcpy (eh0->src_address, (u8 *) & mac0, 6); + b0->error = + node->errors + [LISP_CP_LOOKUP_ERROR_NDP_NEIGHBOR_ADVERTISEMENT_TX]; + next0 = LISP_CP_LOOKUP_NEXT_ARP_NDP_REPLY_TX; + goto enqueue; + } + + /* if we have remote mapping for destination already in map-cache + add forwarding tunnel directly. If not send a map-request */ + di = gid_dictionary_sd_lookup (&lcm->mapping_index_by_gid, &dst, + &src); + if (~0 != di) + { + mapping_t *m = vec_elt_at_index (lcm->mapping_pool, di); + /* send a map-request also in case of negative mapping entry + with corresponding action */ + if (m->action == LISP_SEND_MAP_REQUEST) + { + /* send map-request */ + queue_map_request (&src, &dst, 0 /* smr_invoked */ , + 0 /* is_resend */ ); + } + else + { + if (GID_ADDR_NSH != gid_address_type (&dst)) + { + si = gid_dictionary_lookup (&lcm->mapping_index_by_gid, + &src); + } + else + si = lcm->nsh_map_index; + + if (~0 != si) + { + dp_add_fwd_entry_from_mt (si, di); + } + } + } + else + { + /* send map-request */ + queue_map_request (&src, &dst, 0 /* smr_invoked */ , + 0 /* is_resend */ ); + } + + drop: + b0->error = node->errors[LISP_CP_LOOKUP_ERROR_DROP]; + next0 = LISP_CP_LOOKUP_NEXT_DROP; + enqueue: + if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) + { + lisp_cp_lookup_trace_t *tr = vlib_add_trace (vm, node, b0, + sizeof (*tr)); + + clib_memset (tr, 0, sizeof (*tr)); + if ((gid_address_type (&dst) == GID_ADDR_NDP) || + (gid_address_type (&dst) == GID_ADDR_ARP)) + clib_memcpy (&tr->dst_eid, &dst, sizeof (gid_address_t)); + else + gid_address_copy (&tr->dst_eid, &dst); + ip_address_copy (&tr->map_resolver_ip, + &lcm->active_map_resolver); + } + gid_address_free (&dst); + gid_address_free (&src); + vlib_validate_buffer_enqueue_x1 (vm, node, next_index, + to_next, + n_left_to_next, pi0, next0); + } + + vlib_put_next_frame (vm, node, next_index, n_left_to_next); + } + return from_frame->n_vectors; +} + +static uword +lisp_cp_lookup_ip4 (vlib_main_t * vm, + vlib_node_runtime_t * node, vlib_frame_t * from_frame) +{ + return (lisp_cp_lookup_inline (vm, node, from_frame, LISP_AFI_IP)); +} + +static uword +lisp_cp_lookup_ip6 (vlib_main_t * vm, + vlib_node_runtime_t * node, vlib_frame_t * from_frame) +{ + return (lisp_cp_lookup_inline (vm, node, from_frame, LISP_AFI_IP6)); +} + +static uword +lisp_cp_lookup_l2 (vlib_main_t * vm, + vlib_node_runtime_t * node, vlib_frame_t * from_frame) +{ + return (lisp_cp_lookup_inline (vm, node, from_frame, LISP_AFI_MAC)); +} + +static uword +lisp_cp_lookup_nsh (vlib_main_t * vm, + vlib_node_runtime_t * node, vlib_frame_t * from_frame) +{ + /* TODO decide if NSH should be propagated as LCAF or not */ + return (lisp_cp_lookup_inline (vm, node, from_frame, LISP_AFI_LCAF)); +} + +/* *INDENT-OFF* */ +VLIB_REGISTER_NODE (lisp_cp_lookup_ip4_node) = { + .function = lisp_cp_lookup_ip4, + .name = "lisp-cp-lookup-ip4", + .vector_size = sizeof (u32), + .format_trace = format_lisp_cp_lookup_trace, + .type = VLIB_NODE_TYPE_INTERNAL, + + .n_errors = LISP_CP_LOOKUP_N_ERROR, + .error_strings = lisp_cp_lookup_error_strings, + + .n_next_nodes = LISP_CP_LOOKUP_N_NEXT, + + .next_nodes = { + [LISP_CP_LOOKUP_NEXT_DROP] = "error-drop", + [LISP_CP_LOOKUP_NEXT_ARP_NDP_REPLY_TX] = "interface-output", + }, +}; +/* *INDENT-ON* */ + +/* *INDENT-OFF* */ +VLIB_REGISTER_NODE (lisp_cp_lookup_ip6_node) = { + .function = lisp_cp_lookup_ip6, + .name = "lisp-cp-lookup-ip6", + .vector_size = sizeof (u32), + .format_trace = format_lisp_cp_lookup_trace, + .type = VLIB_NODE_TYPE_INTERNAL, + + .n_errors = LISP_CP_LOOKUP_N_ERROR, + .error_strings = lisp_cp_lookup_error_strings, + + .n_next_nodes = LISP_CP_LOOKUP_N_NEXT, + + .next_nodes = { + [LISP_CP_LOOKUP_NEXT_DROP] = "error-drop", + [LISP_CP_LOOKUP_NEXT_ARP_NDP_REPLY_TX] = "interface-output", + }, +}; +/* *INDENT-ON* */ + +/* *INDENT-OFF* */ +VLIB_REGISTER_NODE (lisp_cp_lookup_l2_node) = { + .function = lisp_cp_lookup_l2, + .name = "lisp-cp-lookup-l2", + .vector_size = sizeof (u32), + .format_trace = format_lisp_cp_lookup_trace, + .type = VLIB_NODE_TYPE_INTERNAL, + + .n_errors = LISP_CP_LOOKUP_N_ERROR, + .error_strings = lisp_cp_lookup_error_strings, + + .n_next_nodes = LISP_CP_LOOKUP_N_NEXT, + + .next_nodes = { + [LISP_CP_LOOKUP_NEXT_DROP] = "error-drop", + [LISP_CP_LOOKUP_NEXT_ARP_NDP_REPLY_TX] = "interface-output", + }, +}; +/* *INDENT-ON* */ + +/* *INDENT-OFF* */ +VLIB_REGISTER_NODE (lisp_cp_lookup_nsh_node) = { + .function = lisp_cp_lookup_nsh, + .name = "lisp-cp-lookup-nsh", + .vector_size = sizeof (u32), + .format_trace = format_lisp_cp_lookup_trace, + .type = VLIB_NODE_TYPE_INTERNAL, + + .n_errors = LISP_CP_LOOKUP_N_ERROR, + .error_strings = lisp_cp_lookup_error_strings, + + .n_next_nodes = LISP_CP_LOOKUP_N_NEXT, + + .next_nodes = { + [LISP_CP_LOOKUP_NEXT_DROP] = "error-drop", + [LISP_CP_LOOKUP_NEXT_ARP_NDP_REPLY_TX] = "interface-output", + }, +}; +/* *INDENT-ON* */ + +/* lisp_cp_input statistics */ +#define foreach_lisp_cp_input_error \ +_(DROP, "drop") \ +_(RLOC_PROBE_REQ_RECEIVED, "rloc-probe requests received") \ +_(RLOC_PROBE_REP_RECEIVED, "rloc-probe replies received") \ +_(MAP_NOTIFIES_RECEIVED, "map-notifies received") \ +_(MAP_REPLIES_RECEIVED, "map-replies received") + +static char *lisp_cp_input_error_strings[] = { +#define _(sym,string) string, + foreach_lisp_cp_input_error +#undef _ +}; + +typedef enum +{ +#define _(sym,str) LISP_CP_INPUT_ERROR_##sym, + foreach_lisp_cp_input_error +#undef _ + LISP_CP_INPUT_N_ERROR, +} lisp_cp_input_error_t; + +typedef struct +{ + gid_address_t dst_eid; + ip4_address_t map_resolver_ip; +} lisp_cp_input_trace_t; + +u8 * +format_lisp_cp_input_trace (u8 * s, va_list * args) +{ + CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); + CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); + CLIB_UNUSED (lisp_cp_input_trace_t * t) = + va_arg (*args, lisp_cp_input_trace_t *); + + s = format (s, "LISP-CP-INPUT: TODO"); + return s; +} + +static void +remove_expired_mapping (lisp_cp_main_t * lcm, u32 mi) +{ + mapping_t *m; + vnet_lisp_add_del_adjacency_args_t _adj_args, *adj_args = &_adj_args; + clib_memset (adj_args, 0, sizeof (adj_args[0])); + + m = pool_elt_at_index (lcm->mapping_pool, mi); + + gid_address_copy (&adj_args->reid, &m->eid); + adj_args->is_add = 0; + if (vnet_lisp_add_del_adjacency (adj_args)) + clib_warning ("failed to del adjacency!"); + + TW (tw_timer_stop) (&lcm->wheel, m->timer_handle); + vnet_lisp_del_mapping (&m->eid, NULL); +} + +static void +mapping_start_expiration_timer (lisp_cp_main_t * lcm, u32 mi, + f64 expiration_time) +{ + mapping_t *m; + u64 now = clib_cpu_time_now (); + u64 cpu_cps = lcm->vlib_main->clib_time.clocks_per_second; + u64 exp_clock_time = now + expiration_time * cpu_cps; + + m = pool_elt_at_index (lcm->mapping_pool, mi); + + m->timer_set = 1; + m->timer_handle = TW (tw_timer_start) (&lcm->wheel, mi, 0, exp_clock_time); +} + +static void +process_expired_mapping (lisp_cp_main_t * lcm, u32 mi) +{ + int rv; + vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a; + mapping_t *m = pool_elt_at_index (lcm->mapping_pool, mi); + uword *fei; + fwd_entry_t *fe; + vlib_counter_t c; + u8 have_stats = 0; + + if (m->delete_after_expiration) + { + remove_expired_mapping (lcm, mi); + return; + } + + fei = hash_get (lcm->fwd_entry_by_mapping_index, mi); + if (!fei) + return; + + fe = pool_elt_at_index (lcm->fwd_entry_pool, fei[0]); + + clib_memset (a, 0, sizeof (*a)); + a->rmt_eid = fe->reid; + if (fe->is_src_dst) + a->lcl_eid = fe->leid; + a->vni = gid_address_vni (&fe->reid); + + rv = vnet_lisp_gpe_get_fwd_stats (a, &c); + if (0 == rv) + have_stats = 1; + + if (m->almost_expired) + { + m->almost_expired = 0; /* reset flag */ + if (have_stats) + { + if (m->packets != c.packets) + { + /* mapping is in use, re-fetch */ + map_request_args_t mr_args; + clib_memset (&mr_args, 0, sizeof (mr_args)); + mr_args.seid = fe->leid; + mr_args.deid = fe->reid; + + send_map_request_thread_fn (&mr_args); + } + else + remove_expired_mapping (lcm, mi); + } + else + remove_expired_mapping (lcm, mi); + } + else + { + m->almost_expired = 1; + mapping_start_expiration_timer (lcm, mi, TIME_UNTIL_REFETCH_OR_DELETE); + + if (have_stats) + /* save counter */ + m->packets = c.packets; + else + m->delete_after_expiration = 1; + } +} + +static void +map_records_arg_free (map_records_arg_t * a) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + mapping_t *m; + vec_foreach (m, a->mappings) + { + vec_free (m->locators); + gid_address_free (&m->eid); + } + pool_put (lcm->map_records_args_pool[vlib_get_thread_index ()], a); +} + +void * +process_map_reply (map_records_arg_t * a) +{ + mapping_t *m; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + u32 dst_map_index = 0; + pending_map_request_t *pmr; + u64 *noncep; + uword *pmr_index; + u8 is_changed = 0; + + if (a->is_rloc_probe) + goto done; + + /* Check pending requests table and nonce */ + pmr_index = hash_get (lcm->pending_map_requests_by_nonce, a->nonce); + if (!pmr_index) + { + clib_warning ("No pending map-request entry with nonce %lu!", a->nonce); + goto done; + } + pmr = pool_elt_at_index (lcm->pending_map_requests_pool, pmr_index[0]); + + vec_foreach (m, a->mappings) + { + vnet_lisp_add_del_mapping_args_t _m_args, *m_args = &_m_args; + clib_memset (m_args, 0, sizeof (m_args[0])); + gid_address_copy (&m_args->eid, &m->eid); + m_args->action = m->action; + m_args->authoritative = m->authoritative; + m_args->ttl = m->ttl; + m_args->is_static = 0; + + /* insert/update mappings cache */ + vnet_lisp_add_mapping (m_args, m->locators, &dst_map_index, &is_changed); + + if (dst_map_index == (u32) ~ 0) + continue; + + if (is_changed) + { + /* try to program forwarding only if mapping saved or updated */ + vnet_lisp_add_del_adjacency_args_t _adj_args, *adj_args = &_adj_args; + clib_memset (adj_args, 0, sizeof (adj_args[0])); + + gid_address_copy (&adj_args->leid, &pmr->src); + gid_address_copy (&adj_args->reid, &m->eid); + adj_args->is_add = 1; + + if (vnet_lisp_add_del_adjacency (adj_args)) + clib_warning ("failed to add adjacency!"); + } + + if ((u32) ~ 0 != m->ttl) + mapping_start_expiration_timer (lcm, dst_map_index, + (m->ttl == 0) ? 0 : MAPPING_TIMEOUT); + } + + /* remove pending map request entry */ + + /* *INDENT-OFF* */ + clib_fifo_foreach (noncep, pmr->nonces, ({ + hash_unset(lcm->pending_map_requests_by_nonce, noncep[0]); + })); + /* *INDENT-ON* */ + + clib_fifo_free (pmr->nonces); + pool_put (lcm->pending_map_requests_pool, pmr); + +done: + a->is_free = 1; + return 0; +} + +static int +is_auth_data_valid (map_notify_hdr_t * h, u32 msg_len, + lisp_key_type_t key_id, u8 * key) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + u8 *auth_data = 0; + u16 auth_data_len; + int result; + vnet_crypto_op_t _op, *op = &_op; + vnet_crypto_key_index_t ki; + u8 out[EVP_MAX_MD_SIZE] = { 0, }; + + auth_data_len = auth_data_len_by_key_id (key_id); + if ((u16) ~ 0 == auth_data_len) + { + clib_warning ("invalid length for key_id %d!", key_id); + return 0; + } + + /* save auth data */ + vec_validate (auth_data, auth_data_len - 1); + clib_memcpy (auth_data, MNOTIFY_DATA (h), auth_data_len); + + /* clear auth data */ + clib_memset (MNOTIFY_DATA (h), 0, auth_data_len); + + vnet_crypto_op_init (op, lisp_key_type_to_crypto_op (key_id)); + op->len = msg_len; + op->digest = out; + op->src = (u8 *) h; + op->digest_len = 0; + op->iv = 0; + + ki = vnet_crypto_key_add (lcm->vlib_main, + lisp_key_type_to_crypto_alg (key_id), key, + vec_len (key)); + + op->key_index = ki; + + vnet_crypto_process_ops (lcm->vlib_main, op, 1); + vnet_crypto_key_del (lcm->vlib_main, ki); + + result = memcmp (out, auth_data, auth_data_len); + + vec_free (auth_data); + + return !result; +} + +static void +process_map_notify (map_records_arg_t * a) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + uword *pmr_index; + + pmr_index = hash_get (lcm->map_register_messages_by_nonce, a->nonce); + if (!pmr_index) + { + clib_warning ("No pending map-register entry with nonce %lu!", + a->nonce); + return; + } + + a->is_free = 1; + pool_put_index (lcm->pending_map_registers_pool, pmr_index[0]); + hash_unset (lcm->map_register_messages_by_nonce, a->nonce); + + /* reset map-notify counter */ + lcm->expired_map_registers = 0; +} + +static mapping_t * +get_mapping (lisp_cp_main_t * lcm, gid_address_t * e) +{ + u32 mi; + + mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, e); + if (~0 == mi) + { + clib_warning ("eid %U not found in map-cache!", unformat_gid_address, + e); + return 0; + } + return pool_elt_at_index (lcm->mapping_pool, mi); +} + +/** + * When map-notify is received it is necessary that all EIDs in the record + * list share common key. The key is then used to verify authentication + * data in map-notify message. + */ +static int +map_record_integrity_check (lisp_cp_main_t * lcm, mapping_t * maps, + u32 key_id, u8 ** key_out) +{ + u32 i, len = vec_len (maps); + mapping_t *m; + + /* get key of the first mapping */ + m = get_mapping (lcm, &maps[0].eid); + if (!m || !m->key) + return -1; + + key_out[0] = m->key; + + for (i = 1; i < len; i++) + { + m = get_mapping (lcm, &maps[i].eid); + if (!m || !m->key) + return -1; + + if (key_id != m->key_id || vec_cmp (m->key, key_out[0])) + { + clib_warning ("keys does not match! %v, %v", key_out[0], m->key); + return -1; + } + } + return 0; +} + +static int +parse_map_records (vlib_buffer_t * b, map_records_arg_t * a, u8 count) +{ + locator_t *locators = 0; + u32 i, len; + gid_address_t deid; + mapping_t m; + locator_t *loc; + + clib_memset (&m, 0, sizeof (m)); + + /* parse record eid */ + for (i = 0; i < count; i++) + { + locators = 0; + len = lisp_msg_parse_mapping_record (b, &deid, &locators, NULL); + if (len == ~0) + { + clib_warning ("Failed to parse mapping record!"); + vec_foreach (loc, locators) locator_free (loc); + vec_free (locators); + return -1; + } + + m.locators = locators; + gid_address_copy (&m.eid, &deid); + vec_add1 (a->mappings, m); + } + + return 0; +} + +static map_records_arg_t * +map_record_args_get () +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + map_records_arg_t *rec; + + /* Cleanup first */ + /* *INDENT-OFF* */ + pool_foreach (rec, lcm->map_records_args_pool[vlib_get_thread_index()], ({ + if (rec->is_free) + map_records_arg_free (rec); + })); + /* *INDENT-ON* */ + + pool_get (lcm->map_records_args_pool[vlib_get_thread_index ()], rec); + return rec; +} + +static map_records_arg_t * +parse_map_notify (vlib_buffer_t * b) +{ + int rc = 0; + map_notify_hdr_t *mnotif_hdr; + lisp_key_type_t key_id; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + u8 *key = 0; + gid_address_t deid; + u16 auth_data_len = 0; + u8 record_count; + map_records_arg_t *a; + + a = map_record_args_get (); + clib_memset (a, 0, sizeof (*a)); + mnotif_hdr = vlib_buffer_get_current (b); + vlib_buffer_pull (b, sizeof (*mnotif_hdr)); + clib_memset (&deid, 0, sizeof (deid)); + + a->nonce = MNOTIFY_NONCE (mnotif_hdr); + key_id = clib_net_to_host_u16 (MNOTIFY_KEY_ID (mnotif_hdr)); + auth_data_len = auth_data_len_by_key_id (key_id); + + /* advance buffer by authentication data */ + vlib_buffer_pull (b, auth_data_len); + + record_count = MNOTIFY_REC_COUNT (mnotif_hdr); + rc = parse_map_records (b, a, record_count); + if (rc != 0) + { + map_records_arg_free (a); + return 0; + } + + rc = map_record_integrity_check (lcm, a->mappings, key_id, &key); + if (rc != 0) + { + map_records_arg_free (a); + return 0; + } + + /* verify authentication data */ + if (!is_auth_data_valid (mnotif_hdr, vlib_buffer_get_tail (b) + - (u8 *) mnotif_hdr, key_id, key)) + { + clib_warning ("Map-notify auth data verification failed for nonce " + "0x%lx!", a->nonce); + map_records_arg_free (a); + return 0; + } + return a; +} + +static vlib_buffer_t * +build_map_reply (lisp_cp_main_t * lcm, ip_address_t * sloc, + ip_address_t * dst, u64 nonce, u8 probe_bit, + mapping_t * records, u16 dst_port, u32 * bi_res) +{ + vlib_buffer_t *b; + u32 bi; + vlib_main_t *vm = lcm->vlib_main; + + if (vlib_buffer_alloc (vm, &bi, 1) != 1) + { + clib_warning ("Can't allocate buffer for Map-Register!"); + return 0; + } + + b = vlib_get_buffer (vm, bi); + + /* leave some space for the encap headers */ + vlib_buffer_make_headroom (b, MAX_LISP_MSG_ENCAP_LEN); + + lisp_msg_put_map_reply (b, records, nonce, probe_bit); + + /* push outer ip header */ + pkt_push_udp_and_ip (vm, b, LISP_CONTROL_PORT, dst_port, sloc, dst, 1); + + bi_res[0] = bi; + return b; +} + +static int +send_map_reply (lisp_cp_main_t * lcm, u32 mi, ip_address_t * dst, + u8 probe_bit, u64 nonce, u16 dst_port, + ip_address_t * probed_loc) +{ + ip_address_t src; + u32 bi; + vlib_buffer_t *b; + vlib_frame_t *f; + u32 next_index, *to_next; + mapping_t *records = 0, *m; + + m = pool_elt_at_index (lcm->mapping_pool, mi); + if (!m) + return -1; + + vec_add1 (records, m[0]); + add_locators (lcm, &records[0], m->locator_set_index, probed_loc); + clib_memset (&src, 0, sizeof (src)); + + if (!ip_fib_get_first_egress_ip_for_dst (lcm, dst, &src)) + { + clib_warning ("can't find interface address for %U", format_ip_address, + dst); + return -1; + } + + b = build_map_reply (lcm, &src, dst, nonce, probe_bit, records, dst_port, + &bi); + if (!b) + return -1; + free_map_register_records (records); + + vnet_buffer (b)->sw_if_index[VLIB_TX] = 0; + next_index = (ip_addr_version (&lcm->active_map_resolver) == AF_IP4) ? + ip4_lookup_node.index : ip6_lookup_node.index; + + f = vlib_get_frame_to_node (lcm->vlib_main, next_index); + + /* Enqueue the packet */ + to_next = vlib_frame_vector_args (f); + to_next[0] = bi; + f->n_vectors = 1; + vlib_put_frame_to_node (lcm->vlib_main, next_index, f); + return 0; +} + +static void +find_ip_header (vlib_buffer_t * b, u8 ** ip_hdr) +{ + const i32 start = vnet_buffer (b)->l3_hdr_offset; + if (start < 0 && start < -sizeof (b->pre_data)) + { + *ip_hdr = 0; + return; + } + + *ip_hdr = b->data + start; + if ((u8 *) * ip_hdr > (u8 *) vlib_buffer_get_current (b)) + *ip_hdr = 0; +} + +void +process_map_request (vlib_main_t * vm, vlib_node_runtime_t * node, + lisp_cp_main_t * lcm, vlib_buffer_t * b) +{ + u8 *ip_hdr = 0; + ip_address_t *dst_loc = 0, probed_loc, src_loc; + mapping_t m; + map_request_hdr_t *mreq_hdr; + gid_address_t src, dst; + u64 nonce; + u32 i, len = 0, rloc_probe_recv = 0; + gid_address_t *itr_rlocs = 0; + + mreq_hdr = vlib_buffer_get_current (b); + if (!MREQ_SMR (mreq_hdr) && !MREQ_RLOC_PROBE (mreq_hdr)) + { + clib_warning + ("Only SMR Map-Requests and RLOC probe supported for now!"); + return; + } + + vlib_buffer_pull (b, sizeof (*mreq_hdr)); + nonce = MREQ_NONCE (mreq_hdr); + + /* parse src eid */ + len = lisp_msg_parse_addr (b, &src); + if (len == ~0) + return; + + len = lisp_msg_parse_itr_rlocs (b, &itr_rlocs, + MREQ_ITR_RLOC_COUNT (mreq_hdr) + 1); + if (len == ~0) + goto done; + + /* parse eid records and send SMR-invoked map-requests */ + for (i = 0; i < MREQ_REC_COUNT (mreq_hdr); i++) + { + clib_memset (&dst, 0, sizeof (dst)); + len = lisp_msg_parse_eid_rec (b, &dst); + if (len == ~0) + { + clib_warning ("Can't parse map-request EID-record"); + goto done; + } + + if (MREQ_SMR (mreq_hdr)) + { + /* send SMR-invoked map-requests */ + queue_map_request (&dst, &src, 1 /* invoked */ , 0 /* resend */ ); + } + else if (MREQ_RLOC_PROBE (mreq_hdr)) + { + find_ip_header (b, &ip_hdr); + if (!ip_hdr) + { + clib_warning ("Cannot find the IP header!"); + goto done; + } + rloc_probe_recv++; + clib_memset (&m, 0, sizeof (m)); + u32 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &dst); + + // TODO: select best locator; for now use the first one + dst_loc = &gid_address_ip (&itr_rlocs[0]); + + /* get src/dst IP addresses */ + get_src_and_dst_ip (ip_hdr, &src_loc, &probed_loc); + + // TODO get source port from buffer + u16 src_port = LISP_CONTROL_PORT; + + send_map_reply (lcm, mi, dst_loc, 1 /* probe-bit */ , nonce, + src_port, &probed_loc); + } + } + +done: + vlib_node_increment_counter (vm, node->node_index, + LISP_CP_INPUT_ERROR_RLOC_PROBE_REQ_RECEIVED, + rloc_probe_recv); + vec_free (itr_rlocs); +} + +map_records_arg_t * +parse_map_reply (vlib_buffer_t * b) +{ + locator_t probed; + gid_address_t deid; + void *h; + u32 i, len = 0; + mapping_t m; + map_reply_hdr_t *mrep_hdr; + map_records_arg_t *a; + + a = map_record_args_get (); + clib_memset (a, 0, sizeof (*a)); + + locator_t *locators; + + mrep_hdr = vlib_buffer_get_current (b); + a->nonce = MREP_NONCE (mrep_hdr); + a->is_rloc_probe = MREP_RLOC_PROBE (mrep_hdr); + if (!vlib_buffer_has_space (b, sizeof (*mrep_hdr))) + { + map_records_arg_free (a); + return 0; + } + vlib_buffer_pull (b, sizeof (*mrep_hdr)); + + for (i = 0; i < MREP_REC_COUNT (mrep_hdr); i++) + { + clib_memset (&m, 0, sizeof (m)); + locators = 0; + h = vlib_buffer_get_current (b); + + m.ttl = clib_net_to_host_u32 (MAP_REC_TTL (h)); + m.action = MAP_REC_ACTION (h); + m.authoritative = MAP_REC_AUTH (h); + + len = lisp_msg_parse_mapping_record (b, &deid, &locators, &probed); + if (len == ~0) + { + clib_warning ("Failed to parse mapping record!"); + map_records_arg_free (a); + return 0; + } + + m.locators = locators; + gid_address_copy (&m.eid, &deid); + vec_add1 (a->mappings, m); + } + return a; +} + +static void +queue_map_reply_for_processing (map_records_arg_t * a) +{ + vl_api_rpc_call_main_thread (process_map_reply, (u8 *) a, sizeof (*a)); +} + +static void +queue_map_notify_for_processing (map_records_arg_t * a) +{ + vl_api_rpc_call_main_thread (process_map_notify, (u8 *) a, sizeof (a[0])); +} + +static uword +lisp_cp_input (vlib_main_t * vm, vlib_node_runtime_t * node, + vlib_frame_t * from_frame) +{ + u32 n_left_from, *from, *to_next_drop, rloc_probe_rep_recv = 0, + map_notifies_recv = 0; + lisp_msg_type_e type; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + map_records_arg_t *a; + + from = vlib_frame_vector_args (from_frame); + n_left_from = from_frame->n_vectors; + + + while (n_left_from > 0) + { + u32 n_left_to_next_drop; + + vlib_get_next_frame (vm, node, LISP_CP_INPUT_NEXT_DROP, + to_next_drop, n_left_to_next_drop); + while (n_left_from > 0 && n_left_to_next_drop > 0) + { + u32 bi0; + vlib_buffer_t *b0; + + bi0 = from[0]; + from += 1; + n_left_from -= 1; + to_next_drop[0] = bi0; + to_next_drop += 1; + n_left_to_next_drop -= 1; + + b0 = vlib_get_buffer (vm, bi0); + + type = lisp_msg_type (vlib_buffer_get_current (b0)); + switch (type) + { + case LISP_MAP_REPLY: + a = parse_map_reply (b0); + if (a) + { + if (a->is_rloc_probe) + rloc_probe_rep_recv++; + queue_map_reply_for_processing (a); + } + break; + case LISP_MAP_REQUEST: + process_map_request (vm, node, lcm, b0); + break; + case LISP_MAP_NOTIFY: + a = parse_map_notify (b0); + if (a) + { + map_notifies_recv++; + queue_map_notify_for_processing (a); + } + break; + default: + clib_warning ("Unsupported LISP message type %d", type); + break; + } + + b0->error = node->errors[LISP_CP_INPUT_ERROR_DROP]; + + if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) + { + + } + } + + vlib_put_next_frame (vm, node, LISP_CP_INPUT_NEXT_DROP, + n_left_to_next_drop); + } + vlib_node_increment_counter (vm, node->node_index, + LISP_CP_INPUT_ERROR_RLOC_PROBE_REP_RECEIVED, + rloc_probe_rep_recv); + vlib_node_increment_counter (vm, node->node_index, + LISP_CP_INPUT_ERROR_MAP_NOTIFIES_RECEIVED, + map_notifies_recv); + return from_frame->n_vectors; +} + +/* *INDENT-OFF* */ +VLIB_REGISTER_NODE (lisp_cp_input_node) = { + .function = lisp_cp_input, + .name = "lisp-cp-input", + .vector_size = sizeof (u32), + .format_trace = format_lisp_cp_input_trace, + .type = VLIB_NODE_TYPE_INTERNAL, + + .n_errors = LISP_CP_INPUT_N_ERROR, + .error_strings = lisp_cp_input_error_strings, + + .n_next_nodes = LISP_CP_INPUT_N_NEXT, + + .next_nodes = { + [LISP_CP_INPUT_NEXT_DROP] = "error-drop", + }, +}; +/* *INDENT-ON* */ + +clib_error_t * +lisp_cp_init (vlib_main_t * vm) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + clib_error_t *error = 0; + vlib_thread_main_t *vtm = vlib_get_thread_main (); + u32 num_threads; + + if ((error = vlib_call_init_function (vm, lisp_gpe_init))) + return error; + + lcm->im4 = &ip4_main; + lcm->im6 = &ip6_main; + lcm->vlib_main = vm; + lcm->vnet_main = vnet_get_main (); + lcm->mreq_itr_rlocs = ~0; + lcm->flags = 0; + lcm->pitr_map_index = ~0; + lcm->petr_map_index = ~0; + clib_memset (&lcm->active_map_resolver, 0, + sizeof (lcm->active_map_resolver)); + clib_memset (&lcm->active_map_server, 0, sizeof (lcm->active_map_server)); + + gid_dictionary_init (&lcm->mapping_index_by_gid); + lcm->do_map_resolver_election = 1; + lcm->do_map_server_election = 1; + lcm->map_request_mode = MR_MODE_DST_ONLY; + + num_threads = 1 /* main thread */ + vtm->n_threads; + vec_validate (lcm->map_records_args_pool, num_threads - 1); + + /* default vrf mapped to vni 0 */ + hash_set (lcm->table_id_by_vni, 0, 0); + hash_set (lcm->vni_by_table_id, 0, 0); + + TW (tw_timer_wheel_init) (&lcm->wheel, 0 /* no callback */ , + 1e-3 /* timer period 1ms */ , + ~0 /* max expirations per call */ ); + lcm->nsh_map_index = ~0; + lcm->map_register_ttl = MAP_REGISTER_DEFAULT_TTL; + lcm->max_expired_map_registers = MAX_EXPIRED_MAP_REGISTERS_DEFAULT; + lcm->expired_map_registers = 0; + lcm->transport_protocol = LISP_TRANSPORT_PROTOCOL_UDP; + lcm->flags |= LISP_FLAG_XTR_MODE; + return 0; +} + +static int +lisp_stats_api_fill (lisp_cp_main_t * lcm, lisp_gpe_main_t * lgm, + lisp_api_stats_t * stat, lisp_stats_key_t * key, + u32 stats_index) +{ + vlib_counter_t v; + vlib_combined_counter_main_t *cm = &lgm->counters; + lisp_gpe_fwd_entry_key_t fwd_key; + const lisp_gpe_tunnel_t *lgt; + fwd_entry_t *fe; + + clib_memset (stat, 0, sizeof (*stat)); + clib_memset (&fwd_key, 0, sizeof (fwd_key)); + + fe = pool_elt_at_index (lcm->fwd_entry_pool, key->fwd_entry_index); + ASSERT (fe != 0); + + gid_to_dp_address (&fe->reid, &stat->deid); + gid_to_dp_address (&fe->leid, &stat->seid); + stat->vni = gid_address_vni (&fe->reid); + + lgt = lisp_gpe_tunnel_get (key->tunnel_index); + stat->loc_rloc = lgt->key->lcl; + stat->rmt_rloc = lgt->key->rmt; + + vlib_get_combined_counter (cm, stats_index, &v); + stat->counters = v; + return 1; +} + +lisp_api_stats_t * +vnet_lisp_get_stats (void) +{ + lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main (); + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + lisp_api_stats_t *stats = 0, stat; + lisp_stats_key_t *key; + u32 index; + + /* *INDENT-OFF* */ + hash_foreach_mem (key, index, lgm->lisp_stats_index_by_key, + { + if (lisp_stats_api_fill (lcm, lgm, &stat, key, index)) + vec_add1 (stats, stat); + }); + /* *INDENT-ON* */ + + return stats; +} + +static void * +send_map_request_thread_fn (void *arg) +{ + map_request_args_t *a = arg; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + + if (a->is_resend) + resend_encapsulated_map_request (lcm, &a->seid, &a->deid, a->smr_invoked); + else + send_encapsulated_map_request (lcm, &a->seid, &a->deid, a->smr_invoked); + + return 0; +} + +static int +queue_map_request (gid_address_t * seid, gid_address_t * deid, + u8 smr_invoked, u8 is_resend) +{ + map_request_args_t a; + + a.is_resend = is_resend; + gid_address_copy (&a.seid, seid); + gid_address_copy (&a.deid, deid); + a.smr_invoked = smr_invoked; + + vl_api_rpc_call_main_thread (send_map_request_thread_fn, + (u8 *) & a, sizeof (a)); + return 0; +} + +/** + * Take an action with a pending map request depending on expiration time + * and re-try counters. + */ +static void +update_pending_request (pending_map_request_t * r, f64 dt) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + lisp_msmr_t *mr; + + if (r->time_to_expire - dt < 0) + /* it's time to decide what to do with this pending request */ + { + if (r->retries_num >= NUMBER_OF_RETRIES) + /* too many retries -> assume current map resolver is not available */ + { + mr = get_map_resolver (&lcm->active_map_resolver); + if (!mr) + { + clib_warning ("Map resolver %U not found - probably deleted " + "by the user recently.", format_ip_address, + &lcm->active_map_resolver); + } + else + { + clib_warning ("map resolver %U is unreachable, ignoring", + format_ip_address, &lcm->active_map_resolver); + + /* mark current map resolver unavailable so it won't be + * selected next time */ + mr->is_down = 1; + mr->last_update = vlib_time_now (lcm->vlib_main); + } + + reset_pending_mr_counters (r); + elect_map_resolver (lcm); + + /* try to find a next eligible map resolver and re-send */ + queue_map_request (&r->src, &r->dst, r->is_smr_invoked, + 1 /* resend */ ); + } + else + { + /* try again */ + queue_map_request (&r->src, &r->dst, r->is_smr_invoked, + 1 /* resend */ ); + r->retries_num++; + r->time_to_expire = PENDING_MREQ_EXPIRATION_TIME; + } + } + else + r->time_to_expire -= dt; +} + +static void +remove_dead_pending_map_requests (lisp_cp_main_t * lcm) +{ + u64 *nonce; + pending_map_request_t *pmr; + u32 *to_be_removed = 0, *pmr_index; + + /* *INDENT-OFF* */ + pool_foreach (pmr, lcm->pending_map_requests_pool, + ({ + if (pmr->to_be_removed) + { + clib_fifo_foreach (nonce, pmr->nonces, ({ + hash_unset (lcm->pending_map_requests_by_nonce, nonce[0]); + })); + + vec_add1 (to_be_removed, pmr - lcm->pending_map_requests_pool); + } + })); + /* *INDENT-ON* */ + + vec_foreach (pmr_index, to_be_removed) + pool_put_index (lcm->pending_map_requests_pool, pmr_index[0]); + + vec_free (to_be_removed); +} + +static void +update_rloc_probing (lisp_cp_main_t * lcm, f64 dt) +{ + static f64 time_left = RLOC_PROBING_INTERVAL; + + if (!lcm->is_enabled || !lcm->rloc_probing) + return; + + time_left -= dt; + if (time_left <= 0) + { + time_left = RLOC_PROBING_INTERVAL; + send_rloc_probes (lcm); + } +} + +static int +update_pending_map_register (pending_map_register_t * r, f64 dt, u8 * del_all) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + lisp_msmr_t *ms; + del_all[0] = 0; + + r->time_to_expire -= dt; + + if (r->time_to_expire < 0) + { + lcm->expired_map_registers++; + + if (lcm->expired_map_registers >= lcm->max_expired_map_registers) + { + ms = get_map_server (&lcm->active_map_server); + if (!ms) + { + clib_warning ("Map server %U not found - probably deleted " + "by the user recently.", format_ip_address, + &lcm->active_map_server); + } + else + { + clib_warning ("map server %U is unreachable, ignoring", + format_ip_address, &lcm->active_map_server); + + /* mark current map server unavailable so it won't be + * elected next time */ + ms->is_down = 1; + ms->last_update = vlib_time_now (lcm->vlib_main); + } + + elect_map_server (lcm); + + /* indication for deleting all pending map registers */ + del_all[0] = 1; + lcm->expired_map_registers = 0; + return 0; + } + else + { + /* delete pending map register */ + return 0; + } + } + return 1; +} + +static void +update_map_register (lisp_cp_main_t * lcm, f64 dt) +{ + u32 *to_be_removed = 0, *pmr_index; + static f64 time_left = QUICK_MAP_REGISTER_INTERVAL; + static u64 mreg_sent_counter = 0; + + pending_map_register_t *pmr; + u8 del_all = 0; + + if (!lcm->is_enabled || !lcm->map_registering) + return; + + /* *INDENT-OFF* */ + pool_foreach (pmr, lcm->pending_map_registers_pool, + ({ + if (!update_pending_map_register (pmr, dt, &del_all)) + { + if (del_all) + break; + vec_add1 (to_be_removed, pmr - lcm->pending_map_registers_pool); + } + })); + /* *INDENT-ON* */ + + if (del_all) + { + /* delete all pending map register messages so they won't + * trigger another map server election.. */ + pool_free (lcm->pending_map_registers_pool); + hash_free (lcm->map_register_messages_by_nonce); + + /* ..and trigger registration against next map server (if any) */ + time_left = 0; + } + else + { + vec_foreach (pmr_index, to_be_removed) + pool_put_index (lcm->pending_map_registers_pool, pmr_index[0]); + } + + vec_free (to_be_removed); + + time_left -= dt; + if (time_left <= 0) + { + if (mreg_sent_counter >= QUICK_MAP_REGISTER_MSG_COUNT) + time_left = MAP_REGISTER_INTERVAL; + else + { + mreg_sent_counter++; + time_left = QUICK_MAP_REGISTER_INTERVAL; + } + send_map_register (lcm, 1 /* want map notify */ ); + } +} + +static uword +send_map_resolver_service (vlib_main_t * vm, + vlib_node_runtime_t * rt, vlib_frame_t * f) +{ + u32 *expired = 0; + f64 period = 2.0; + pending_map_request_t *pmr; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + + while (1) + { + vlib_process_wait_for_event_or_clock (vm, period); + + /* currently no signals are expected - just wait for clock */ + (void) vlib_process_get_events (vm, 0); + + /* *INDENT-OFF* */ + pool_foreach (pmr, lcm->pending_map_requests_pool, + ({ + if (!pmr->to_be_removed) + update_pending_request (pmr, period); + })); + /* *INDENT-ON* */ + + remove_dead_pending_map_requests (lcm); + + update_map_register (lcm, period); + update_rloc_probing (lcm, period); + + expired = TW (tw_timer_expire_timers_vec) (&lcm->wheel, + vlib_time_now (vm), expired); + if (vec_len (expired) > 0) + { + u32 *mi = 0; + vec_foreach (mi, expired) + { + process_expired_mapping (lcm, mi[0]); + } + _vec_len (expired) = 0; + } + } + + /* unreachable */ + return 0; +} + +vnet_api_error_t +vnet_lisp_stats_enable_disable (u8 enable) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + + if (vnet_lisp_enable_disable_status () == 0) + return VNET_API_ERROR_LISP_DISABLED; + + if (enable) + lcm->flags |= LISP_FLAG_STATS_ENABLED; + else + lcm->flags &= ~LISP_FLAG_STATS_ENABLED; + + return 0; +} + +u8 +vnet_lisp_stats_enable_disable_state (void) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + + if (vnet_lisp_enable_disable_status () == 0) + return VNET_API_ERROR_LISP_DISABLED; + + return lcm->flags & LISP_FLAG_STATS_ENABLED; +} + +void +vnet_lisp_create_retry_process (lisp_cp_main_t * lcm) +{ + if (lcm->retry_service_index) + return; + + lcm->retry_service_index = vlib_process_create (vlib_get_main (), + "lisp-retry-service", + send_map_resolver_service, + 16 /* stack_bytes */ ); +} + +u32 +vnet_lisp_set_transport_protocol (u8 protocol) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + + if (protocol < LISP_TRANSPORT_PROTOCOL_UDP || + protocol > LISP_TRANSPORT_PROTOCOL_API) + return VNET_API_ERROR_INVALID_ARGUMENT; + + lcm->transport_protocol = protocol; + return 0; +} + +lisp_transport_protocol_t +vnet_lisp_get_transport_protocol (void) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + return lcm->transport_protocol; +} + +int +vnet_lisp_enable_disable_xtr_mode (u8 is_enabled) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + u8 pitr_mode = lcm->flags & LISP_FLAG_PITR_MODE; + u8 xtr_mode = lcm->flags & LISP_FLAG_XTR_MODE; + u8 petr_mode = lcm->flags & LISP_FLAG_PETR_MODE; + + if (pitr_mode && is_enabled) + return VNET_API_ERROR_INVALID_ARGUMENT; + + if (is_enabled && xtr_mode) + return 0; + if (!is_enabled && !xtr_mode) + return 0; + + if (is_enabled) + { + if (!petr_mode) + { + lisp_cp_register_dst_port (lcm->vlib_main); + } + lisp_cp_enable_l2_l3_ifaces (lcm, 1 /* with_default_route */ ); + lcm->flags |= LISP_FLAG_XTR_MODE; + } + else + { + if (!petr_mode) + { + lisp_cp_unregister_dst_port (lcm->vlib_main); + } + lisp_cp_disable_l2_l3_ifaces (lcm); + lcm->flags &= ~LISP_FLAG_XTR_MODE; + } + return 0; +} + +int +vnet_lisp_enable_disable_pitr_mode (u8 is_enabled) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + u8 xtr_mode = lcm->flags & LISP_FLAG_XTR_MODE; + u8 pitr_mode = lcm->flags & LISP_FLAG_PITR_MODE; + + if (xtr_mode && is_enabled) + return VNET_API_ERROR_INVALID_VALUE; + + if (is_enabled && pitr_mode) + return 0; + if (!is_enabled && !pitr_mode) + return 0; + + if (is_enabled) + { + /* create iface, no default route */ + lisp_cp_enable_l2_l3_ifaces (lcm, 0 /* with_default_route */ ); + lcm->flags |= LISP_FLAG_PITR_MODE; + } + else + { + lisp_cp_disable_l2_l3_ifaces (lcm); + lcm->flags &= ~LISP_FLAG_PITR_MODE; + } + return 0; +} + +int +vnet_lisp_enable_disable_petr_mode (u8 is_enabled) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + u8 xtr_mode = lcm->flags & LISP_FLAG_XTR_MODE; + u8 petr_mode = lcm->flags & LISP_FLAG_PETR_MODE; + + if (is_enabled && petr_mode) + return 0; + if (!is_enabled && !petr_mode) + return 0; + + if (is_enabled) + { + if (!xtr_mode) + { + lisp_cp_register_dst_port (lcm->vlib_main); + } + lcm->flags |= LISP_FLAG_PETR_MODE; + } + else + { + if (!xtr_mode) + { + lisp_cp_unregister_dst_port (lcm->vlib_main); + } + lcm->flags &= ~LISP_FLAG_PETR_MODE; + } + return 0; +} + +u8 +vnet_lisp_get_xtr_mode (void) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + return (lcm->flags & LISP_FLAG_XTR_MODE); +} + +u8 +vnet_lisp_get_pitr_mode (void) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + return (lcm->flags & LISP_FLAG_PITR_MODE); +} + +u8 +vnet_lisp_get_petr_mode (void) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + return (lcm->flags & LISP_FLAG_PETR_MODE); +} + +VLIB_INIT_FUNCTION (lisp_cp_init); + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/lisp/lisp-cp/control.h b/src/plugins/lisp/lisp-cp/control.h new file mode 100644 index 00000000000..524f5028465 --- /dev/null +++ b/src/plugins/lisp/lisp-cp/control.h @@ -0,0 +1,448 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef VNET_CONTROL_H_ +#define VNET_CONTROL_H_ + +#include +#include +#include +#include +#include + +#define NUMBER_OF_RETRIES 1 +#define PENDING_MREQ_EXPIRATION_TIME 3.0 /* seconds */ +#define PENDING_MREQ_QUEUE_LEN 5 + +#define RLOC_PROBING_INTERVAL 60.0 + +/* when map-registration is enabled "quick registration" takes place first. + In this mode ETR sends map-register messages at an increased frequency + until specified message count is reached */ +#define QUICK_MAP_REGISTER_MSG_COUNT 5 +#define QUICK_MAP_REGISTER_INTERVAL 3.0 + +/* normal map-register period */ +#define MAP_REGISTER_INTERVAL 60.0 + +/* how many tries until next map-server election */ +#define MAX_EXPIRED_MAP_REGISTERS_DEFAULT 3 + +#define PENDING_MREG_EXPIRATION_TIME 3.0 /* seconds */ + +/* 24 hours */ +#define MAP_REGISTER_DEFAULT_TTL 86400 + +typedef struct +{ + gid_address_t src; + gid_address_t dst; + u32 retries_num; + f64 time_to_expire; + u8 is_smr_invoked; + u64 *nonces; + u8 to_be_removed; +} pending_map_request_t; + +typedef struct +{ + f64 time_to_expire; +} pending_map_register_t; + +typedef struct +{ + gid_address_t leid; + gid_address_t reid; + u8 is_src_dst; + locator_pair_t *locator_pairs; +} fwd_entry_t; + +typedef struct +{ + gid_address_t leid; + gid_address_t reid; +} lisp_adjacency_t; + +typedef enum +{ + IP4_MISS_PACKET, + IP6_MISS_PACKET +} miss_packet_type_t; + +/* map-server/map-resolver structure */ +typedef struct +{ + u8 is_down; + f64 last_update; + ip_address_t address; + char *key; +} lisp_msmr_t; + +typedef struct +{ + /* headers */ + u8 data[100]; + u32 length; + miss_packet_type_t type; +} miss_packet_t; + +typedef struct +{ + u8 mac[6]; + u32 ip4; +} lisp_api_l2_arp_entry_t; + +typedef struct +{ + u8 mac[6]; + u8 ip6[16]; +} lisp_api_ndp_entry_t; + +typedef enum +{ + MR_MODE_DST_ONLY = 0, + MR_MODE_SRC_DST, + _MR_MODE_MAX +} map_request_mode_t; + +#define foreach_lisp_flag_bit \ + _(USE_PETR, "Use Proxy-ETR") \ + _(XTR_MODE, "ITR/ETR mode") \ + _(PETR_MODE, "Proxy-ETR mode") \ + _(PITR_MODE, "Proxy-ITR mode") \ + _(STATS_ENABLED, "Statistics enabled") + +typedef enum lisp_flag_bits +{ +#define _(sym, str) LISP_FLAG_BIT_##sym, + foreach_lisp_flag_bit +#undef _ +} lisp_flag_bits_e; + +typedef enum lisp_flags +{ +#define _(sym, str) LISP_FLAG_##sym = 1 << LISP_FLAG_BIT_##sym, + foreach_lisp_flag_bit +#undef _ +} lisp_flags_e; + +typedef struct +{ + ip_address_t addr; + u32 bd; +} lisp_l2_arp_key_t; + +typedef enum +{ + LISP_TRANSPORT_PROTOCOL_UDP = 1, + LISP_TRANSPORT_PROTOCOL_API +} lisp_transport_protocol_t; + +typedef struct +{ + u64 nonce; + u8 is_rloc_probe; + mapping_t *mappings; + volatile u8 is_free; +} map_records_arg_t; + +typedef struct +{ + u32 flags; + + /* LISP feature status */ + u8 is_enabled; + + /* eid table */ + gid_dictionary_t mapping_index_by_gid; + + /* pool of mappings */ + mapping_t *mapping_pool; + + /* hash map of secret keys by mapping index */ + u8 *key_by_mapping_index; + + /* pool of locators */ + locator_t *locator_pool; + + /* pool of locator-sets */ + locator_set_t *locator_set_pool; + + /* vector of locator-set vectors composed of and indexed by locator index */ + u32 **locator_to_locator_sets; + + /* hash map of locators by name */ + uword *locator_set_index_by_name; + + /* vector of eid index vectors supported and indexed by locator-set index */ + u32 **locator_set_to_eids; + + /* vectors of indexes for local locator-sets and mappings */ + u32 *local_mappings_indexes; + u32 *local_locator_set_indexes; + + /* hash map of forwarding entries by mapping index */ + u32 *fwd_entry_by_mapping_index; + + /* pool of vectors of rmts per lcl mapping in adjacencies */ + u32 **lcl_to_rmt_adjacencies; + + /* hash of pool positions of vectors of rmts by lcl mapping index */ + u32 *lcl_to_rmt_adjs_by_lcl_idx; + + /* forwarding entries pool */ + fwd_entry_t *fwd_entry_pool; + + /* hash map keyed by nonce of pending map-requests */ + uword *pending_map_requests_by_nonce; + + /* pool of pending map requests */ + pending_map_request_t *pending_map_requests_pool; + + /* pool of pending map registers */ + pending_map_register_t *pending_map_registers_pool; + + /* hash map of sent map register messages */ + uword *map_register_messages_by_nonce; + + /* vector of map-resolvers */ + lisp_msmr_t *map_resolvers; + + /* vector of map-servers */ + lisp_msmr_t *map_servers; + + /* map resolver address currently being used for sending requests. + * This has to be an actual address and not an index to map_resolvers vector + * since the vector may be modified during request resend/retry procedure + * and break things :-) */ + ip_address_t active_map_resolver; + ip_address_t active_map_server; + + u8 do_map_resolver_election; + u8 do_map_server_election; + + /* map-request locator set index */ + u32 mreq_itr_rlocs; + + /* vni to vrf hash tables */ + uword *table_id_by_vni; + uword *vni_by_table_id; + + /* vni to bd-index hash tables */ + uword *bd_id_by_vni; + uword *vni_by_bd_id; + + /* track l2 and l3 interfaces that have been created for vni */ + uword *l2_dp_intf_by_vni; + + /* Proxy ITR map index */ + u32 pitr_map_index; + + /** Proxy ETR map index used for 'use-petr'. + * Not related to PETR tunnel mode */ + u32 petr_map_index; + + /* mapping index for NSH */ + u32 nsh_map_index; + + /* map request mode */ + u8 map_request_mode; + + /* enable/disable map registering */ + u8 map_registering; + + /* enable/disable rloc-probing */ + u8 rloc_probing; + + /* timing wheel for mapping timeouts */ + TWT (tw_timer_wheel) wheel; + + /** Per thread pool of records shared with thread0 */ + map_records_arg_t **map_records_args_pool; + + /* TTL used for all mappings when registering */ + u32 map_register_ttl; + + /* control variables for map server election */ + u32 max_expired_map_registers; + u32 expired_map_registers; + + /** either UDP based or binary API. Default is UDP */ + lisp_transport_protocol_t transport_protocol; + + /** Retry service node index */ + u32 retry_service_index; + + /* commodity */ + ip4_main_t *im4; + ip6_main_t *im6; + vlib_main_t *vlib_main; + vnet_main_t *vnet_main; +} lisp_cp_main_t; + +/* lisp-gpe control plane */ +extern lisp_cp_main_t lisp_control_main; + +extern vlib_node_registration_t lisp_cp_input_node; +extern vlib_node_registration_t lisp_cp_lookup_ip4_node; +extern vlib_node_registration_t lisp_cp_lookup_ip6_node; + +clib_error_t *lisp_cp_init (); + +always_inline lisp_cp_main_t * +vnet_lisp_cp_get_main () +{ + return &lisp_control_main; +} + +void +get_src_and_dst_eids_from_buffer (lisp_cp_main_t * lcm, vlib_buffer_t * b, + gid_address_t * src, gid_address_t * dst, + u16 type); + +typedef struct +{ + u8 is_add; + union + { + u8 *name; + u32 index; + }; + locator_t *locators; + u8 local; +} vnet_lisp_add_del_locator_set_args_t; + +int +vnet_lisp_add_del_locator_set (vnet_lisp_add_del_locator_set_args_t * a, + u32 * ls_index); +int +vnet_lisp_add_del_locator (vnet_lisp_add_del_locator_set_args_t * a, + locator_set_t * ls, u32 * ls_index); + +typedef struct +{ + u8 is_add; + gid_address_t eid; + u32 locator_set_index; + + u32 ttl; + u8 action; + u8 authoritative; + + u8 local; + u8 is_static; + u8 *key; + u8 key_id; +} vnet_lisp_add_del_mapping_args_t; + +int +vnet_lisp_map_cache_add_del (vnet_lisp_add_del_mapping_args_t * a, + u32 * map_index); +int +vnet_lisp_add_del_local_mapping (vnet_lisp_add_del_mapping_args_t * a, + u32 * map_index_result); + +int +vnet_lisp_add_mapping (vnet_lisp_add_del_mapping_args_t * a, + locator_t * rlocs, u32 * res_map_index, + u8 * is_changed); + +int vnet_lisp_del_mapping (gid_address_t * eid, u32 * res_map_index); + +typedef struct +{ + gid_address_t reid; + gid_address_t leid; + u8 is_add; +} vnet_lisp_add_del_adjacency_args_t; + +int vnet_lisp_add_del_adjacency (vnet_lisp_add_del_adjacency_args_t * a); + +typedef struct +{ + u8 is_add; + ip_address_t address; +} vnet_lisp_add_del_map_resolver_args_t; + +int +vnet_lisp_add_del_map_resolver (vnet_lisp_add_del_map_resolver_args_t * a); +int vnet_lisp_add_del_map_server (ip_address_t * addr, u8 is_add); + +clib_error_t *vnet_lisp_enable_disable (u8 is_enabled); +u8 vnet_lisp_enable_disable_status (void); +void vnet_lisp_create_retry_process (lisp_cp_main_t * lcm); + +int vnet_lisp_pitr_set_locator_set (u8 * locator_set_name, u8 is_add); +int vnet_lisp_use_petr (ip_address_t * ip, u8 is_add); + +typedef struct +{ + u8 is_add; + u8 *locator_set_name; +} vnet_lisp_add_del_mreq_itr_rloc_args_t; + +int +vnet_lisp_add_del_mreq_itr_rlocs (vnet_lisp_add_del_mreq_itr_rloc_args_t * a); + +int vnet_lisp_clear_all_remote_adjacencies (void); + +int vnet_lisp_eid_table_map (u32 vni, u32 vrf, u8 is_l2, u8 is_add); +int vnet_lisp_add_del_map_table_key (gid_address_t * eid, char *key, + u8 is_add); +int vnet_lisp_set_map_request_mode (u8 mode); +u8 vnet_lisp_get_map_request_mode (void); +lisp_adjacency_t *vnet_lisp_adjacencies_get_by_vni (u32 vni); +int vnet_lisp_rloc_probe_enable_disable (u8 is_enable); +int vnet_lisp_map_register_enable_disable (u8 is_enable); +u8 vnet_lisp_map_register_state_get (void); +u8 vnet_lisp_rloc_probe_state_get (void); +int vnet_lisp_add_del_l2_arp_ndp_entry (gid_address_t * key, u8 * mac, + u8 is_add); +u32 *vnet_lisp_l2_arp_bds_get (void); +lisp_api_l2_arp_entry_t *vnet_lisp_l2_arp_entries_get_by_bd (u32 bd); +int vnet_lisp_nsh_set_locator_set (u8 * locator_set_name, u8 is_add); +int vnet_lisp_map_register_set_ttl (u32 ttl); +u32 vnet_lisp_map_register_get_ttl (void); +int vnet_lisp_map_register_fallback_threshold_set (u32 value); +u32 vnet_lisp_map_register_fallback_threshold_get (void); +u32 *vnet_lisp_ndp_bds_get (void); +lisp_api_ndp_entry_t *vnet_lisp_ndp_entries_get_by_bd (u32 bd); +u32 vnet_lisp_set_transport_protocol (u8 protocol); +lisp_transport_protocol_t vnet_lisp_get_transport_protocol (void); + +extern int vnet_lisp_enable_disable_xtr_mode (u8 is_enabled); +extern int vnet_lisp_enable_disable_pitr_mode (u8 is_enabled); +extern int vnet_lisp_enable_disable_petr_mode (u8 is_enabled); +extern u8 vnet_lisp_get_xtr_mode (void); +extern u8 vnet_lisp_get_pitr_mode (void); +extern u8 vnet_lisp_get_petr_mode (void); + +map_records_arg_t *parse_map_reply (vlib_buffer_t * b); + +always_inline mapping_t * +lisp_get_petr_mapping (lisp_cp_main_t * lcm) +{ + return pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index); +} + +#endif /* VNET_CONTROL_H_ */ + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/lisp/lisp-cp/gid_dictionary.c b/src/plugins/lisp/lisp-cp/gid_dictionary.c new file mode 100644 index 00000000000..9b0af3f5c6d --- /dev/null +++ b/src/plugins/lisp/lisp-cp/gid_dictionary.c @@ -0,0 +1,1077 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +typedef struct +{ + void *arg; + ip_prefix_t src; + foreach_subprefix_match_cb_t cb; + union + { + gid_ip4_table_t *ip4_table; + gid_ip6_table_t *ip6_table; + }; +} sfib_entry_arg_t; + +static u32 ip4_lookup (gid_ip4_table_t * db, u32 vni, ip_prefix_t * key); + +static u32 ip6_lookup (gid_ip6_table_t * db, u32 vni, ip_prefix_t * key); + +static int +foreach_sfib4_subprefix (BVT (clib_bihash_kv) * kvp, void *arg) +{ + sfib_entry_arg_t *a = arg; + u32 ip = (u32) kvp->key[0]; + ip4_address_t *mask; + u8 plen = ip_prefix_len (&a->src); + + ASSERT (plen <= 32); + mask = &a->ip4_table->ip4_fib_masks[plen]; + + u32 src_ip = ip_prefix_v4 (&a->src).as_u32; + src_ip &= mask->as_u32; + ip &= mask->as_u32; + + if (src_ip == ip) + { + /* found sub-prefix of src prefix */ + (a->cb) (kvp->value, a->arg); + } + return (BIHASH_WALK_CONTINUE); +} + +static void +gid_dict_foreach_ip4_subprefix (gid_dictionary_t * db, u32 vni, + ip_prefix_t * src, ip_prefix_t * dst, + foreach_subprefix_match_cb_t cb, void *arg) +{ + u32 sfi; + gid_ip4_table_t *sfib4; + sfib_entry_arg_t a; + + sfi = ip4_lookup (&db->dst_ip4_table, vni, dst); + if (GID_LOOKUP_MISS == sfi) + return; + + sfib4 = pool_elt_at_index (db->src_ip4_table_pool, sfi); + + a.arg = arg; + a.cb = cb; + a.src = src[0]; + a.ip4_table = sfib4; + + BV (clib_bihash_foreach_key_value_pair) (&sfib4->ip4_lookup_table, + foreach_sfib4_subprefix, &a); +} + +static int +foreach_sfib6_subprefix (BVT (clib_bihash_kv) * kvp, void *arg) +{ + sfib_entry_arg_t *a = arg; + ip6_address_t ip; + ip6_address_t *mask; + u8 plen = ip_prefix_len (&a->src); + + mask = &a->ip6_table->ip6_fib_masks[plen]; + ip.as_u64[0] = kvp->key[0]; + ip.as_u64[1] = kvp->key[1]; + + if (ip6_address_is_equal_masked (&ip_prefix_v6 (&a->src), &ip, mask)) + { + /* found sub-prefix of src prefix */ + (a->cb) (kvp->value, a->arg); + } + return (BIHASH_WALK_CONTINUE); +} + +static void +gid_dict_foreach_ip6_subprefix (gid_dictionary_t * db, u32 vni, + ip_prefix_t * src, ip_prefix_t * dst, + foreach_subprefix_match_cb_t cb, void *arg) +{ + u32 sfi; + gid_ip6_table_t *sfib6; + sfib_entry_arg_t a; + + sfi = ip6_lookup (&db->dst_ip6_table, vni, dst); + if (GID_LOOKUP_MISS == sfi) + return; + + sfib6 = pool_elt_at_index (db->src_ip6_table_pool, sfi); + + a.arg = arg; + a.cb = cb; + a.src = src[0]; + a.ip6_table = sfib6; + + BV (clib_bihash_foreach_key_value_pair) (&sfib6->ip6_lookup_table, + foreach_sfib6_subprefix, &a); +} + +void +gid_dict_foreach_subprefix (gid_dictionary_t * db, gid_address_t * eid, + foreach_subprefix_match_cb_t cb, void *arg) +{ + ip_prefix_t *ippref = &gid_address_sd_dst_ippref (eid); + + if (AF_IP4 == ip_prefix_version (ippref)) + gid_dict_foreach_ip4_subprefix (db, gid_address_vni (eid), + &gid_address_sd_src_ippref (eid), + &gid_address_sd_dst_ippref (eid), cb, + arg); + else + gid_dict_foreach_ip6_subprefix (db, gid_address_vni (eid), + &gid_address_sd_src_ippref (eid), + &gid_address_sd_dst_ippref (eid), cb, + arg); +} + +void +gid_dict_foreach_l2_arp_ndp_entry (gid_dictionary_t * db, + BV (clib_bihash_foreach_key_value_pair_cb) + cb, void *ht) +{ + gid_l2_arp_ndp_table_t *tab = &db->arp_ndp_table; + BV (clib_bihash_foreach_key_value_pair) (&tab->arp_ndp_lookup_table, cb, + ht); +} + +static void +make_mac_sd_key (BVT (clib_bihash_kv) * kv, u32 vni, u8 src_mac[6], + u8 dst_mac[6]) +{ + kv->key[0] = (u64) vni; + kv->key[1] = mac_to_u64 (dst_mac); + kv->key[2] = src_mac ? mac_to_u64 (src_mac) : (u64) 0; +} + +static u32 +mac_sd_lookup (gid_mac_table_t * db, u32 vni, u8 * dst, u8 * src) +{ + int rv; + BVT (clib_bihash_kv) kv, value; + + make_mac_sd_key (&kv, vni, src, dst); + rv = BV (clib_bihash_search_inline_2) (&db->mac_lookup_table, &kv, &value); + + /* no match, try with src 0, catch all for dst */ + if (rv != 0) + { + kv.key[2] = 0; + rv = BV (clib_bihash_search_inline_2) (&db->mac_lookup_table, &kv, + &value); + if (rv == 0) + return value.value; + } + else + return value.value; + + return GID_LOOKUP_MISS; +} + +static u32 +ip4_lookup_exact_match (gid_ip4_table_t * db, u32 vni, ip_prefix_t * key) +{ + int rv; + BVT (clib_bihash_kv) kv, value; + + ip4_address_t *mask; + + mask = &db->ip4_fib_masks[ip_prefix_len (key)]; + + kv.key[0] = ((u64) vni << 32) | (ip_prefix_v4 (key).as_u32 & mask->as_u32); + kv.key[1] = 0; + kv.key[2] = 0; + + rv = BV (clib_bihash_search_inline_2) (&db->ip4_lookup_table, &kv, &value); + if (rv == 0) + return value.value; + + return GID_LOOKUP_MISS; +} + +static u32 +ip4_lookup (gid_ip4_table_t * db, u32 vni, ip_prefix_t * key) +{ + int i, len; + int rv; + BVT (clib_bihash_kv) kv, value; + + len = vec_len (db->ip4_prefix_lengths_in_search_order); + + for (i = 0; i < len; i++) + { + int dst_address_length = db->ip4_prefix_lengths_in_search_order[i]; + ip4_address_t *mask; + + ASSERT (dst_address_length >= 0 && dst_address_length <= 32); + + mask = &db->ip4_fib_masks[dst_address_length]; + + kv.key[0] = + ((u64) vni << 32) | (ip_prefix_v4 (key).as_u32 & mask->as_u32); + kv.key[1] = 0; + kv.key[2] = 0; + + rv = + BV (clib_bihash_search_inline_2) (&db->ip4_lookup_table, &kv, &value); + if (rv == 0) + return value.value; + } + + return GID_LOOKUP_MISS; +} + +static u32 +ip6_lookup_exact_match (gid_ip6_table_t * db, u32 vni, ip_prefix_t * key) +{ + int rv; + BVT (clib_bihash_kv) kv, value; + + ip6_address_t *mask; + mask = &db->ip6_fib_masks[ip_prefix_len (key)]; + + kv.key[0] = ip_prefix_v6 (key).as_u64[0] & mask->as_u64[0]; + kv.key[1] = ip_prefix_v6 (key).as_u64[1] & mask->as_u64[1]; + kv.key[2] = (u64) vni; + + rv = BV (clib_bihash_search_inline_2) (&db->ip6_lookup_table, &kv, &value); + if (rv == 0) + return value.value; + + return GID_LOOKUP_MISS; +} + +static u32 +ip6_lookup (gid_ip6_table_t * db, u32 vni, ip_prefix_t * key) +{ + int i, len; + int rv; + BVT (clib_bihash_kv) kv, value; + + len = vec_len (db->ip6_prefix_lengths_in_search_order); + + for (i = 0; i < len; i++) + { + int dst_address_length = db->ip6_prefix_lengths_in_search_order[i]; + ip6_address_t *mask; + + ASSERT (dst_address_length >= 0 && dst_address_length <= 128); + + mask = &db->ip6_fib_masks[dst_address_length]; + + kv.key[0] = ip_prefix_v6 (key).as_u64[0] & mask->as_u64[0]; + kv.key[1] = ip_prefix_v6 (key).as_u64[1] & mask->as_u64[1]; + kv.key[2] = (u64) vni; + + rv = + BV (clib_bihash_search_inline_2) (&db->ip6_lookup_table, &kv, &value); + if (rv == 0) + return value.value; + } + + return GID_LOOKUP_MISS; +} + +static u32 +ip_sd_lookup (gid_dictionary_t * db, u32 vni, ip_prefix_t * dst, + ip_prefix_t * src) +{ + u32 sfi; + gid_ip4_table_t *sfib4; + gid_ip6_table_t *sfib6; + + switch (ip_prefix_version (dst)) + { + case AF_IP4: + sfi = ip4_lookup (&db->dst_ip4_table, vni, dst); + if (GID_LOOKUP_MISS != sfi) + sfib4 = pool_elt_at_index (db->src_ip4_table_pool, sfi); + else + return GID_LOOKUP_MISS; + + if (!src) + { + ip_prefix_t sp; + clib_memset (&sp, 0, sizeof (sp)); + return ip4_lookup_exact_match (sfib4, 0, &sp); + } + else + return ip4_lookup (sfib4, 0, src); + + break; + case AF_IP6: + sfi = ip6_lookup (&db->dst_ip6_table, vni, dst); + if (GID_LOOKUP_MISS != sfi) + sfib6 = pool_elt_at_index (db->src_ip6_table_pool, sfi); + else + return GID_LOOKUP_MISS; + + if (!src) + { + ip_prefix_t sp; + clib_memset (&sp, 0, sizeof (sp)); + ip_prefix_version (&sp) = AF_IP6; + return ip6_lookup_exact_match (sfib6, 0, &sp); + } + else + return ip6_lookup (sfib6, 0, src); + + break; + default: + clib_warning ("address type %d not supported!", + ip_prefix_version (dst)); + break; + } + return GID_LOOKUP_MISS; +} + +static void +make_arp_ndp_key (BVT (clib_bihash_kv) * kv, u32 bd, ip_address_t * addr) +{ + kv->key[0] = ((u64) bd << 32) | (u32) ip_addr_version (addr); + if (ip_addr_version (addr) == AF_IP4) + { + kv->key[1] = (u64) ip_addr_v4 (addr).as_u32; + kv->key[2] = (u64) 0; + } + else + { + kv->key[1] = (u64) ip_addr_v6 (addr).as_u64[0]; + kv->key[2] = (u64) ip_addr_v6 (addr).as_u64[1]; + } +} + +static void +make_nsh_key (BVT (clib_bihash_kv) * kv, u32 vni, u32 spi, u8 si) +{ + kv->key[0] = (u64) vni; + kv->key[1] = (u64) spi; + kv->key[2] = (u64) si; +} + +static u64 +arp_ndp_lookup (gid_l2_arp_ndp_table_t * db, u32 bd, ip_address_t * key) +{ + int rv; + BVT (clib_bihash_kv) kv, value; + + make_arp_ndp_key (&kv, bd, key); + rv = BV (clib_bihash_search_inline_2) (&db->arp_ndp_lookup_table, &kv, + &value); + + if (rv == 0) + return value.value; + + return GID_LOOKUP_MISS_L2; +} + +static u32 +nsh_lookup (gid_nsh_table_t * db, u32 vni, u32 spi, u8 si) +{ + int rv; + BVT (clib_bihash_kv) kv, value; + + make_nsh_key (&kv, vni, spi, si); + rv = BV (clib_bihash_search_inline_2) (&db->nsh_lookup_table, &kv, &value); + + if (rv == 0) + return value.value; + + return GID_LOOKUP_MISS; +} + +u64 +gid_dictionary_lookup (gid_dictionary_t * db, gid_address_t * key) +{ + switch (gid_address_type (key)) + { + case GID_ADDR_IP_PREFIX: + return ip_sd_lookup (db, gid_address_vni (key), + &gid_address_ippref (key), 0); + case GID_ADDR_MAC: + return mac_sd_lookup (&db->sd_mac_table, gid_address_vni (key), + gid_address_mac (key), 0); + case GID_ADDR_SRC_DST: + switch (gid_address_sd_dst_type (key)) + { + case FID_ADDR_IP_PREF: + return ip_sd_lookup (db, gid_address_vni (key), + &gid_address_sd_dst_ippref (key), + &gid_address_sd_src_ippref (key)); + break; + case FID_ADDR_MAC: + return mac_sd_lookup (&db->sd_mac_table, gid_address_vni (key), + gid_address_sd_dst_mac (key), + gid_address_sd_src_mac (key)); + break; + default: + clib_warning ("Source/Dest address type %d not supported!", + gid_address_sd_dst_type (key)); + break; + } + break; + case GID_ADDR_ARP: + case GID_ADDR_NDP: + return arp_ndp_lookup (&db->arp_ndp_table, gid_address_arp_ndp_bd (key), + &gid_address_arp_ndp_ip (key)); + case GID_ADDR_NSH: + return nsh_lookup (&db->nsh_table, gid_address_vni (key), + gid_address_nsh_spi (key), gid_address_nsh_si (key)); + default: + clib_warning ("address type %d not supported!", gid_address_type (key)); + break; + } + return GID_LOOKUP_MISS; +} + +u32 +gid_dictionary_sd_lookup (gid_dictionary_t * db, gid_address_t * dst, + gid_address_t * src) +{ + switch (gid_address_type (dst)) + { + case GID_ADDR_IP_PREFIX: + return ip_sd_lookup (db, gid_address_vni (dst), + &gid_address_ippref (dst), + &gid_address_ippref (src)); + case GID_ADDR_MAC: + return mac_sd_lookup (&db->sd_mac_table, gid_address_vni (dst), + gid_address_mac (dst), gid_address_mac (src)); + case GID_ADDR_SRC_DST: + switch (gid_address_sd_dst_type (dst)) + { + case FID_ADDR_IP_PREF: + return ip_sd_lookup (db, gid_address_vni (dst), + &gid_address_sd_dst_ippref (dst), + &gid_address_sd_src_ippref (dst)); + break; + case FID_ADDR_MAC: + return mac_sd_lookup (&db->sd_mac_table, gid_address_vni (dst), + gid_address_sd_dst_mac (dst), + gid_address_sd_src_mac (dst)); + break; + default: + clib_warning ("Source/Dest address type %d not supported!", + gid_address_sd_dst_type (dst)); + break; + } + break; + case GID_ADDR_NSH: + return gid_dictionary_lookup (db, dst); + break; + default: + clib_warning ("address type %d not supported!", gid_address_type (dst)); + break; + } + return GID_LOOKUP_MISS; +} + +static void +ip4_compute_prefix_lengths_in_search_order (gid_ip4_table_t * db) +{ + int i; + vec_reset_length (db->ip4_prefix_lengths_in_search_order); + /* Note: bitmap reversed so this is in fact a longest prefix match */ + + /* *INDENT-OFF* */ + clib_bitmap_foreach (i, db->ip4_non_empty_dst_address_length_bitmap, + ({ + int dst_address_length = 32 - i; + vec_add1 (db->ip4_prefix_lengths_in_search_order, dst_address_length); + })); + /* *INDENT-ON* */ + +} + +static u32 +add_del_ip4_key (gid_ip4_table_t * db, u32 vni, ip_prefix_t * pref, u32 val, + u8 is_add) +{ + BVT (clib_bihash_kv) kv, value; + u32 old_val = ~0; + ip4_address_t key; + u8 plen = ip_prefix_len (pref); + + clib_memcpy (&key, &ip_prefix_v4 (pref), sizeof (key)); + key.as_u32 &= db->ip4_fib_masks[plen].as_u32; + if (is_add) + { + db->ip4_non_empty_dst_address_length_bitmap = + clib_bitmap_set (db->ip4_non_empty_dst_address_length_bitmap, + 32 - plen, 1); + ip4_compute_prefix_lengths_in_search_order (db); + + db->ip4_prefix_len_refcount[plen]++; + } + else + { + ASSERT (db->ip4_prefix_len_refcount[plen] != 0); + + db->ip4_prefix_len_refcount[plen]--; + + if (db->ip4_prefix_len_refcount[plen] == 0) + { + db->ip4_non_empty_dst_address_length_bitmap = + clib_bitmap_set (db->ip4_non_empty_dst_address_length_bitmap, + 32 - plen, 0); + ip4_compute_prefix_lengths_in_search_order (db); + } + } + + kv.key[0] = ((u64) vni << 32) | key.as_u32; + kv.key[1] = 0; + kv.key[2] = 0; + + if (BV (clib_bihash_search) (&db->ip4_lookup_table, &kv, &value) == 0) + old_val = value.value; + + if (!is_add) + { + BV (clib_bihash_add_del) (&db->ip4_lookup_table, &kv, 0 /* is_add */ ); + db->count--; + } + else + { + kv.value = val; + BV (clib_bihash_add_del) (&db->ip4_lookup_table, &kv, 1 /* is_add */ ); + db->count++; + } + return old_val; +} + +static void +ip4_lookup_init (gid_ip4_table_t * db) +{ + BVT (clib_bihash_init2_args) _a, *a = &_a; + uword i; + + clib_memset (db->ip4_prefix_len_refcount, 0, + sizeof (db->ip4_prefix_len_refcount)); + + for (i = 0; i < ARRAY_LEN (db->ip4_fib_masks); i++) + { + u32 m; + + if (i < 32) + m = pow2_mask (i) << (32 - i); + else + m = ~0; + db->ip4_fib_masks[i].as_u32 = clib_host_to_net_u32 (m); + } + if (db->ip4_lookup_table_nbuckets == 0) + db->ip4_lookup_table_nbuckets = IP4_LOOKUP_DEFAULT_HASH_NUM_BUCKETS; + + db->ip4_lookup_table_nbuckets = + 1 << max_log2 (db->ip4_lookup_table_nbuckets); + + if (db->ip4_lookup_table_size == 0) + db->ip4_lookup_table_size = IP4_LOOKUP_DEFAULT_HASH_MEMORY_SIZE; + + /* + * Danger Will Robinson, Danger! gid_ip4_table_t's are allocated from + * a pool. They MUST NOT be listed on the clib_all_bihashes list... + */ + memset (a, 0, sizeof (*a)); + a->h = &db->ip4_lookup_table; + a->name = "LISP ip4 lookup table"; + a->nbuckets = db->ip4_lookup_table_nbuckets; + a->memory_size = db->ip4_lookup_table_size; + a->dont_add_to_all_bihash_list = 1; /* See comment above */ + + BV (clib_bihash_init2) (a); +} + +static u32 +add_del_sd_ip4_key (gid_dictionary_t * db, u32 vni, ip_prefix_t * dst_pref, + ip_prefix_t * src_pref, u32 val, u8 is_add) +{ + u32 sfi, old_val = ~0; + gid_ip4_table_t *sfib; + + sfi = ip4_lookup_exact_match (&db->dst_ip4_table, vni, dst_pref); + + if (is_add) + { + if (GID_LOOKUP_MISS == sfi) + { + pool_get (db->src_ip4_table_pool, sfib); + ip4_lookup_init (sfib); + add_del_ip4_key (&db->dst_ip4_table, vni, dst_pref, + sfib - db->src_ip4_table_pool, is_add); + if (src_pref) + add_del_ip4_key (sfib, 0 /* vni */ , src_pref, val, is_add); + else + { + ip_prefix_t sp; + clib_memset (&sp, 0, sizeof (sp)); + add_del_ip4_key (sfib, 0 /* vni */ , &sp, val, is_add); + } + } + else + { + ASSERT (!pool_is_free_index (db->src_ip4_table_pool, sfi)); + sfib = pool_elt_at_index (db->src_ip4_table_pool, sfi); + if (src_pref) + { + old_val = ip4_lookup_exact_match (sfib, 0, src_pref); + add_del_ip4_key (sfib, 0 /* vni */ , src_pref, val, is_add); + } + else + { + ip_prefix_t sp; + clib_memset (&sp, 0, sizeof (sp)); + old_val = + add_del_ip4_key (sfib, 0 /* vni */ , &sp, val, is_add); + } + } + } + else + { + if (GID_LOOKUP_MISS != sfi) + { + sfib = pool_elt_at_index (db->src_ip4_table_pool, sfi); + if (src_pref) + old_val = add_del_ip4_key (sfib, 0, src_pref, 0, is_add); + else + { + ip_prefix_t sp; + clib_memset (&sp, 0, sizeof (sp)); + old_val = add_del_ip4_key (sfib, 0, &sp, 0, is_add); + } + + if (sfib->count == 0) + add_del_ip4_key (&db->dst_ip4_table, vni, dst_pref, 0, is_add); + } + else + clib_warning ("cannot delete dst mapping %U!", format_ip_prefix, + dst_pref); + } + return old_val; +} + +static void +ip6_compute_prefix_lengths_in_search_order (gid_ip6_table_t * db) +{ + int i; + vec_reset_length (db->ip6_prefix_lengths_in_search_order); + /* Note: bitmap reversed so this is in fact a longest prefix match */ + + /* *INDENT-OFF* */ + clib_bitmap_foreach (i, db->ip6_non_empty_dst_address_length_bitmap, + ({ + int dst_address_length = 128 - i; + vec_add1 (db->ip6_prefix_lengths_in_search_order, dst_address_length); + })); + /* *INDENT-ON* */ +} + +static u32 +add_del_ip6_key (gid_ip6_table_t * db, u32 vni, ip_prefix_t * pref, u32 val, + u8 is_add) +{ + BVT (clib_bihash_kv) kv, value; + u32 old_val = ~0; + ip6_address_t key; + u8 plen = ip_prefix_len (pref); + + clib_memcpy (&key, &ip_prefix_v6 (pref), sizeof (key)); + ip6_address_mask (&key, &db->ip6_fib_masks[plen]); + if (is_add) + { + db->ip6_non_empty_dst_address_length_bitmap = + clib_bitmap_set (db->ip6_non_empty_dst_address_length_bitmap, + 128 - plen, 1); + ip6_compute_prefix_lengths_in_search_order (db); + db->ip6_prefix_len_refcount[plen]++; + } + else + { + ASSERT (db->ip6_prefix_len_refcount[plen] != 0); + + db->ip6_prefix_len_refcount[plen]--; + + if (db->ip6_prefix_len_refcount[plen] == 0) + { + db->ip6_non_empty_dst_address_length_bitmap = + clib_bitmap_set (db->ip6_non_empty_dst_address_length_bitmap, + 128 - plen, 0); + ip6_compute_prefix_lengths_in_search_order (db); + } + } + + kv.key[0] = key.as_u64[0]; + kv.key[1] = key.as_u64[1]; + kv.key[2] = (u64) vni; +// kv.key[2] = ((u64)((fib - im->fibs))<<32) | ip_prefix_len(key); + + if (BV (clib_bihash_search) (&db->ip6_lookup_table, &kv, &value) == 0) + old_val = value.value; + + if (!is_add) + { + BV (clib_bihash_add_del) (&db->ip6_lookup_table, &kv, 0 /* is_add */ ); + db->count--; + } + else + { + kv.value = val; + BV (clib_bihash_add_del) (&db->ip6_lookup_table, &kv, 1 /* is_add */ ); + db->count++; + } + return old_val; +} + +static u32 +add_del_mac (gid_mac_table_t * db, u32 vni, u8 * dst_mac, u8 * src_mac, + u32 val, u8 is_add) +{ + BVT (clib_bihash_kv) kv, value; + u32 old_val = ~0; + + make_mac_sd_key (&kv, vni, src_mac, dst_mac); + + if (BV (clib_bihash_search) (&db->mac_lookup_table, &kv, &value) == 0) + old_val = value.value; + + if (!is_add) + { + BV (clib_bihash_add_del) (&db->mac_lookup_table, &kv, 0 /* is_add */ ); + db->count--; + } + else + { + kv.value = val; + BV (clib_bihash_add_del) (&db->mac_lookup_table, &kv, 1 /* is_add */ ); + db->count++; + } + return old_val; +} + +static void +ip6_lookup_init (gid_ip6_table_t * db) +{ + uword i; + BVT (clib_bihash_init2_args) _a, *a = &_a; + + clib_memset (db->ip6_prefix_len_refcount, 0, + sizeof (db->ip6_prefix_len_refcount)); + + for (i = 0; i < ARRAY_LEN (db->ip6_fib_masks); i++) + { + u32 j, i0, i1; + + i0 = i / 32; + i1 = i % 32; + + for (j = 0; j < i0; j++) + db->ip6_fib_masks[i].as_u32[j] = ~0; + + if (i1) + db->ip6_fib_masks[i].as_u32[i0] = + clib_host_to_net_u32 (pow2_mask (i1) << (32 - i1)); + } + + if (db->ip6_lookup_table_nbuckets == 0) + db->ip6_lookup_table_nbuckets = IP6_LOOKUP_DEFAULT_HASH_NUM_BUCKETS; + + db->ip6_lookup_table_nbuckets = + 1 << max_log2 (db->ip6_lookup_table_nbuckets); + + if (db->ip6_lookup_table_size == 0) + db->ip6_lookup_table_size = IP6_LOOKUP_DEFAULT_HASH_MEMORY_SIZE; + + /* + * Danger Will Robinson, Danger! gid_ip6_table_t's are allocated from + * a pool. They MUST NOT be listed on the clib_all_bihashes list... + */ + memset (a, 0, sizeof (*a)); + a->h = &db->ip6_lookup_table; + a->name = "LISP ip6 lookup table"; + a->nbuckets = db->ip6_lookup_table_nbuckets; + a->memory_size = db->ip6_lookup_table_size; + a->dont_add_to_all_bihash_list = 1; /* See comment above */ + + BV (clib_bihash_init2) (a); +} + +static u32 +add_del_sd_ip6_key (gid_dictionary_t * db, u32 vni, ip_prefix_t * dst_pref, + ip_prefix_t * src_pref, u32 val, u8 is_add) +{ + u32 sfi, old_val = ~0; + gid_ip6_table_t *sfib; + + sfi = ip6_lookup_exact_match (&db->dst_ip6_table, vni, dst_pref); + + if (is_add) + { + if (GID_LOOKUP_MISS == sfi) + { + pool_get (db->src_ip6_table_pool, sfib); + ip6_lookup_init (sfib); + add_del_ip6_key (&db->dst_ip6_table, vni, dst_pref, + sfib - db->src_ip6_table_pool, is_add); + if (src_pref) + add_del_ip6_key (sfib, 0 /* vni */ , src_pref, val, is_add); + else + { + ip_prefix_t sp; + clib_memset (&sp, 0, sizeof (sp)); + ip_prefix_version (&sp) = AF_IP6; + add_del_ip6_key (sfib, 0 /* vni */ , &sp, val, is_add); + } + } + else + { + ASSERT (!pool_is_free_index (db->src_ip6_table_pool, sfi)); + sfib = pool_elt_at_index (db->src_ip6_table_pool, sfi); + if (src_pref) + { + old_val = ip6_lookup_exact_match (sfib, 0, src_pref); + add_del_ip6_key (sfib, 0 /* vni */ , src_pref, val, is_add); + } + else + { + ip_prefix_t sp; + clib_memset (&sp, 0, sizeof (sp)); + ip_prefix_version (&sp) = AF_IP6; + old_val = + add_del_ip6_key (sfib, 0 /* vni */ , &sp, val, is_add); + } + } + } + else + { + if (GID_LOOKUP_MISS != sfi) + { + sfib = pool_elt_at_index (db->src_ip6_table_pool, sfi); + if (src_pref) + old_val = add_del_ip6_key (sfib, 0, src_pref, 0, is_add); + else + { + ip_prefix_t sp; + clib_memset (&sp, 0, sizeof (sp)); + ip_prefix_version (&sp) = AF_IP6; + old_val = add_del_ip6_key (sfib, 0, &sp, 0, is_add); + } + + if (sfib->count == 0) + add_del_ip6_key (&db->dst_ip6_table, vni, dst_pref, 0, is_add); + } + else + clib_warning ("cannot delete dst mapping %U!", format_ip_prefix, + dst_pref); + } + return old_val; +} + +static u32 +add_del_ip (gid_dictionary_t * db, u32 vni, ip_prefix_t * dst_key, + ip_prefix_t * src_key, u32 value, u8 is_add) +{ + switch (ip_prefix_version (dst_key)) + { + case AF_IP4: + return add_del_sd_ip4_key (db, vni, dst_key, src_key, value, is_add); + break; + case AF_IP6: + return add_del_sd_ip6_key (db, vni, dst_key, src_key, value, is_add); + break; + default: + clib_warning ("address type %d not supported!", + ip_prefix_version (dst_key)); + break; + } + return ~0; +} + +static u32 +add_del_sd (gid_dictionary_t * db, u32 vni, source_dest_t * key, u32 value, + u8 is_add) +{ + switch (sd_dst_type (key)) + { + case FID_ADDR_IP_PREF: + add_del_ip (db, vni, &sd_dst_ippref (key), &sd_src_ippref (key), + value, is_add); + + case FID_ADDR_MAC: + return add_del_mac (&db->sd_mac_table, vni, sd_dst_mac (key), + sd_src_mac (key), value, is_add); + + default: + clib_warning ("SD address type %d not supported!", sd_dst_type (key)); + break; + } + + return ~0; +} + +static u64 +add_del_arp_ndp (gid_l2_arp_ndp_table_t * db, u32 bd, ip_address_t * key, + u64 value, u8 is_add) +{ + BVT (clib_bihash_kv) kv, result; + u32 old_val = ~0; + + make_arp_ndp_key (&kv, bd, key); + if (BV (clib_bihash_search) (&db->arp_ndp_lookup_table, &kv, &result) == 0) + old_val = result.value; + + if (is_add) + { + kv.value = value; + BV (clib_bihash_add_del) (&db->arp_ndp_lookup_table, &kv, + 1 /* is_add */ ); + db->count++; + } + else + { + BV (clib_bihash_add_del) (&db->arp_ndp_lookup_table, &kv, + 0 /* is_add */ ); + db->count--; + } + return old_val; +} + +static u32 +add_del_nsh (gid_nsh_table_t * db, u32 vni, u32 spi, u8 si, u32 value, + u8 is_add) +{ + BVT (clib_bihash_kv) kv, result; + u32 old_val = ~0; + + make_nsh_key (&kv, vni, spi, si); + if (BV (clib_bihash_search) (&db->nsh_lookup_table, &kv, &result) == 0) + old_val = result.value; + + if (is_add) + { + kv.value = value; + BV (clib_bihash_add_del) (&db->nsh_lookup_table, &kv, 1 /* is_add */ ); + db->count++; + } + else + { + BV (clib_bihash_add_del) (&db->nsh_lookup_table, &kv, 0 /* is_add */ ); + db->count--; + } + return old_val; +} + +u32 +gid_dictionary_add_del (gid_dictionary_t * db, gid_address_t * key, u64 value, + u8 is_add) +{ + switch (gid_address_type (key)) + { + case GID_ADDR_IP_PREFIX: + return add_del_ip (db, gid_address_vni (key), &gid_address_ippref (key), + 0, (u32) value, is_add); + case GID_ADDR_MAC: + return add_del_mac (&db->sd_mac_table, gid_address_vni (key), + gid_address_mac (key), 0, (u32) value, is_add); + case GID_ADDR_SRC_DST: + return add_del_sd (db, gid_address_vni (key), &gid_address_sd (key), + (u32) value, is_add); + case GID_ADDR_ARP: + case GID_ADDR_NDP: + return add_del_arp_ndp (&db->arp_ndp_table, + gid_address_arp_ndp_bd (key), + &gid_address_arp_ndp_ip (key), value, is_add); + case GID_ADDR_NSH: + return add_del_nsh (&db->nsh_table, gid_address_vni (key), + gid_address_nsh_spi (key), gid_address_nsh_si (key), + value, is_add); + + default: + clib_warning ("address type %d not supported!", gid_address_type (key)); + break; + } + return ~0; +} + +static void +mac_lookup_init (gid_mac_table_t * db) +{ + if (db->mac_lookup_table_nbuckets == 0) + db->mac_lookup_table_nbuckets = MAC_LOOKUP_DEFAULT_HASH_NUM_BUCKETS; + + db->mac_lookup_table_nbuckets = + 1 << max_log2 (db->mac_lookup_table_nbuckets); + + if (db->mac_lookup_table_size == 0) + db->mac_lookup_table_size = MAC_LOOKUP_DEFAULT_HASH_MEMORY_SIZE; + + BV (clib_bihash_init) (&db->mac_lookup_table, "mac lookup table", + db->mac_lookup_table_nbuckets, + db->mac_lookup_table_size); +} + +static void +arp_ndp_lookup_init (gid_l2_arp_ndp_table_t * db) +{ + if (db->arp_ndp_lookup_table_nbuckets == 0) + db->arp_ndp_lookup_table_nbuckets = + ARP_NDP_LOOKUP_DEFAULT_HASH_NUM_BUCKETS; + + db->arp_ndp_lookup_table_nbuckets = + 1 << max_log2 (db->arp_ndp_lookup_table_nbuckets); + + if (db->arp_ndp_lookup_table_size == 0) + db->arp_ndp_lookup_table_size = ARP_NDP_LOOKUP_DEFAULT_HASH_MEMORY_SIZE; + + BV (clib_bihash_init) (&db->arp_ndp_lookup_table, "arp ndp lookup table", + db->arp_ndp_lookup_table_nbuckets, + db->arp_ndp_lookup_table_size); +} + +static void +nsh_lookup_init (gid_nsh_table_t * db) +{ + if (db->nsh_lookup_table_nbuckets == 0) + db->nsh_lookup_table_nbuckets = MAC_LOOKUP_DEFAULT_HASH_NUM_BUCKETS; + + db->nsh_lookup_table_nbuckets = + 1 << max_log2 (db->nsh_lookup_table_nbuckets); + + if (db->nsh_lookup_table_size == 0) + db->nsh_lookup_table_size = MAC_LOOKUP_DEFAULT_HASH_MEMORY_SIZE; + + BV (clib_bihash_init) (&db->nsh_lookup_table, "nsh lookup table", + db->nsh_lookup_table_nbuckets, + db->nsh_lookup_table_size); +} + +void +gid_dictionary_init (gid_dictionary_t * db) +{ + ip4_lookup_init (&db->dst_ip4_table); + ip6_lookup_init (&db->dst_ip6_table); + mac_lookup_init (&db->sd_mac_table); + arp_ndp_lookup_init (&db->arp_ndp_table); + nsh_lookup_init (&db->nsh_table); +} + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/lisp/lisp-cp/gid_dictionary.h b/src/plugins/lisp/lisp-cp/gid_dictionary.h new file mode 100644 index 00000000000..9a8e213c231 --- /dev/null +++ b/src/plugins/lisp/lisp-cp/gid_dictionary.h @@ -0,0 +1,161 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef VNET_LISP_GPE_GID_DICTIONARY_H_ +#define VNET_LISP_GPE_GID_DICTIONARY_H_ + +#include +#include +#include +#include + +#define GID_LOOKUP_MISS ((u32)~0) +#define GID_LOOKUP_MISS_L2 ((u64)~0) + +/* Default size of the ip4 hash table */ +#define IP4_LOOKUP_DEFAULT_HASH_NUM_BUCKETS (64 * 1024) +#define IP4_LOOKUP_DEFAULT_HASH_MEMORY_SIZE (32<<20) + +/* Default size of the ip6 hash table */ +#define IP6_LOOKUP_DEFAULT_HASH_NUM_BUCKETS (64 * 1024) +#define IP6_LOOKUP_DEFAULT_HASH_MEMORY_SIZE (32<<20) + +/* Default size of the MAC hash table */ +#define MAC_LOOKUP_DEFAULT_HASH_NUM_BUCKETS (64 * 1024) +#define MAC_LOOKUP_DEFAULT_HASH_MEMORY_SIZE (32<<20) + +/* Default size of the ARP/NDP hash table */ +#define ARP_NDP_LOOKUP_DEFAULT_HASH_NUM_BUCKETS (64 * 1024) +#define ARP_NDP_LOOKUP_DEFAULT_HASH_MEMORY_SIZE (32<<20) + +/* Default size of the NSH hash table */ +#define NSH_LOOKUP_DEFAULT_HASH_NUM_BUCKETS (64 * 1024) +#define NSH_LOOKUP_DEFAULT_HASH_MEMORY_SIZE (32<<20) + +typedef void (*foreach_subprefix_match_cb_t) (u32, void *); + +typedef struct +{ + BVT (clib_bihash) ip4_lookup_table; + + /* bitmap/vector of mask widths to search */ + uword *ip4_non_empty_dst_address_length_bitmap; + u8 *ip4_prefix_lengths_in_search_order; + ip4_address_t ip4_fib_masks[33]; + u32 ip4_prefix_len_refcount[33]; + + /* ip4 lookup table config parameters */ + u32 ip4_lookup_table_nbuckets; + uword ip4_lookup_table_size; + u32 count; +} gid_ip4_table_t; + +typedef struct +{ + BVT (clib_bihash) ip6_lookup_table; + + /* bitmap/vector of mask widths to search */ + uword *ip6_non_empty_dst_address_length_bitmap; + u8 *ip6_prefix_lengths_in_search_order; + ip6_address_t ip6_fib_masks[129]; + u64 ip6_prefix_len_refcount[129]; + + /* ip6 lookup table config parameters */ + u32 ip6_lookup_table_nbuckets; + uword ip6_lookup_table_size; + u64 count; +} gid_ip6_table_t; + +typedef struct gid_mac_table +{ + BVT (clib_bihash) mac_lookup_table; + + /* mac lookup table config parameters */ + u32 mac_lookup_table_nbuckets; + uword mac_lookup_table_size; + u64 count; +} gid_mac_table_t; + +typedef struct gid_nsh_table +{ + BVT (clib_bihash) nsh_lookup_table; + + /* nsh lookup table config parameters */ + u32 nsh_lookup_table_nbuckets; + uword nsh_lookup_table_size; + u64 count; +} gid_nsh_table_t; + +typedef struct +{ + BVT (clib_bihash) arp_ndp_lookup_table; + u32 arp_ndp_lookup_table_nbuckets; + uword arp_ndp_lookup_table_size; + u64 count; +} gid_l2_arp_ndp_table_t; + +typedef struct +{ + /** L2 ARP/NDP table */ + gid_l2_arp_ndp_table_t arp_ndp_table; + + /** NSH lookup table */ + gid_nsh_table_t nsh_table; + + /** destination IP LPM ip4 lookup table */ + gid_ip4_table_t dst_ip4_table; + + /** pool of source IP LPM ip4 lookup tables */ + gid_ip4_table_t *src_ip4_table_pool; + + /** destination IP LPM ip6 lookup table */ + gid_ip6_table_t dst_ip6_table; + + /** pool of source IP LPM ip6 lookup tables */ + gid_ip6_table_t *src_ip6_table_pool; + + /** flat source/dest mac lookup table */ + gid_mac_table_t sd_mac_table; + +} gid_dictionary_t; + +u32 +gid_dictionary_add_del (gid_dictionary_t * db, gid_address_t * key, u64 value, + u8 is_add); + +u64 gid_dictionary_lookup (gid_dictionary_t * db, gid_address_t * key); +u32 gid_dictionary_sd_lookup (gid_dictionary_t * db, gid_address_t * dst, + gid_address_t * src); + +void gid_dictionary_init (gid_dictionary_t * db); + +void +gid_dict_foreach_subprefix (gid_dictionary_t * db, gid_address_t * eid, + foreach_subprefix_match_cb_t cb, void *arg); + +void +gid_dict_foreach_l2_arp_ndp_entry (gid_dictionary_t * db, + BV (clib_bihash_foreach_key_value_pair_cb) + cb, void *ht); + +#endif /* VNET_LISP_GPE_GID_DICTIONARY_H_ */ + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/lisp/lisp-cp/lisp.api b/src/plugins/lisp/lisp-cp/lisp.api new file mode 100644 index 00000000000..ebd0a31c66e --- /dev/null +++ b/src/plugins/lisp/lisp-cp/lisp.api @@ -0,0 +1,674 @@ +/* + * Copyright (c) 2015-2016 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +option version = "2.0.0"; + +import "vnet/interface_types.api"; +import "plugins/lisp/lisp-cp/lisp_types.api"; + +/** \brief add or delete locator_set + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param is_add - add address if non-zero, else delete + @param locator_set_name - locator name + @param locator_num - number of locators + @param locators - LISP locator records +*/ +define lisp_add_del_locator_set +{ + u32 client_index; + u32 context; + bool is_add [default=true]; + string locator_set_name[64]; + u32 locator_num; + vl_api_local_locator_t locators[locator_num]; +}; + +/** \brief Reply for locator_set add/del + @param context - returned sender context, to match reply w/ request + @param retval - return code + @param ls_index - locator set index +*/ +define lisp_add_del_locator_set_reply +{ + u32 context; + i32 retval; + u32 ls_index; +}; + +/** \brief add or delete locator for locator_set + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param is_add - add address if non-zero, else delete + @param locator_set_name - name of locator_set to add/del locator + @param sw_if_index - index of the interface + @param priority - priority of the lisp locator + @param weight - weight of the lisp locator +*/ +autoreply define lisp_add_del_locator +{ + u32 client_index; + u32 context; + bool is_add [default=true]; + string locator_set_name[64]; + vl_api_interface_index_t sw_if_index; + u8 priority; + u8 weight; +}; + +/** \brief add or delete lisp eid-table + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param is_add - add address if non-zero, else delete + @param eid - endpoint identifier + @param locator_set_name - name of locator_set to add/del eid-table + @param vni - virtual network instance + @param key - secret key +*/ +autoreply define lisp_add_del_local_eid +{ + u32 client_index; + u32 context; + bool is_add [default=true]; + vl_api_eid_t eid; + string locator_set_name[64]; + u32 vni; + vl_api_hmac_key_t key; +}; + +/** \brief Add/delete map server + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param is_add - add address if non-zero; delete otherwise + @param ip_address - map server IP address +*/ +autoreply define lisp_add_del_map_server +{ + u32 client_index; + u32 context; + bool is_add [default=true]; + vl_api_address_t ip_address; +}; + +/** \brief add or delete map-resolver + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param is_add - add address if non-zero, else delete + @param ip_address - ip address +*/ +autoreply define lisp_add_del_map_resolver +{ + u32 client_index; + u32 context; + bool is_add [default=true]; + vl_api_address_t ip_address; +}; + +/** \brief enable or disable LISP feature + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param is_en - enable protocol if non-zero, else disable +*/ +autoreply define lisp_enable_disable +{ + u32 client_index; + u32 context; + bool is_enable [default=true]; +}; + +/** \brief configure or disable LISP PITR node + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param ls_name - locator set name + @param is_add - add locator set if non-zero, else disable pitr +*/ +autoreply define lisp_pitr_set_locator_set +{ + u32 client_index; + u32 context; + bool is_add [default=true]; + string ls_name[64]; +}; + +/** \brief configure or disable use of PETR + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param ip_address - PETR IP address + @param is_add - add locator set if non-zero, else disable pitr +*/ +autoreply define lisp_use_petr +{ + u32 client_index; + u32 context; + vl_api_address_t ip_address; + bool is_add [default=true]; +}; + +/** \brief Request for LISP PETR status + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request +*/ +define show_lisp_use_petr +{ + u32 client_index; + u32 context; +}; + +/** \brief LISP PETR status, enable or disable + @param context - sender context, to match reply w/ request + @param status - LISP PETR enable if non-zero, else disable + @param address - PETR IP address +*/ +define show_lisp_use_petr_reply +{ + u32 context; + i32 retval; + bool is_petr_enable [default=true]; + vl_api_address_t ip_address; +}; + +/** \brief Get state of LISP RLOC probing + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request +*/ +define show_lisp_rloc_probe_state +{ + u32 client_index; + u32 context; +}; + +/** \brief Reply for show_lisp_rloc_probe_state + @param context - returned sender context, to match reply w/ request + @param retval - return code + @param is_enabled - state of RLOC probing +*/ +define show_lisp_rloc_probe_state_reply +{ + u32 context; + i32 retval; + bool is_enabled [default=true]; +}; + +/** \brief enable/disable LISP RLOC probing + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param is_enable - enable if non-zero; disable otherwise +*/ +autoreply define lisp_rloc_probe_enable_disable +{ + u32 client_index; + u32 context; + bool is_enable [default=true]; +}; + +/** \brief enable/disable LISP map-register + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param is_enable - enable if non-zero; disable otherwise +*/ +autoreply define lisp_map_register_enable_disable +{ + u32 client_index; + u32 context; + bool is_enable [default=true]; +}; + +/** \brief Get state of LISP map-register + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request +*/ +define show_lisp_map_register_state +{ + u32 client_index; + u32 context; +}; + +/** \brief Reply for show_lisp_map_register_state + @param context - returned sender context, to match reply w/ request + @param retval - return code +*/ +define show_lisp_map_register_state_reply +{ + u32 context; + i32 retval; + bool is_enabled [default=true]; +}; + +/** \brief set LISP map-request mode. Based on configuration VPP will send + src/dest or just normal destination map requests. + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param is_src_dst - if non-zero source/destination else destination only +*/ +autoreply define lisp_map_request_mode +{ + u32 client_index; + u32 context; + bool is_src_dst; +}; + +/** \brief Request for LISP map-request mode + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request +*/ +define show_lisp_map_request_mode +{ + u32 client_index; + u32 context; +}; + +/** \brief Reply for show_lisp_map_request_mode + @param context - returned sender context, to match reply w/ request + @param retval - return code + @param is_src_dst - if non-zero source/destination else destination only +*/ +define show_lisp_map_request_mode_reply +{ + u32 context; + i32 retval; + bool is_src_dst; +}; + +/** \brief add or delete remote static mapping + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param is_add - add address if non-zero, else delete + @param is_src_dst - flag indicating src/dst based routing policy + @param del_all - if set, delete all remote mappings + @param vni - virtual network instance + @param action - negative map-reply action + @param deid - dst EID + @param seid - src EID, valid only if is_src_dst is enabled + @param rloc_num - number of remote locators + @param rlocs - remote locator records +*/ +autoreply define lisp_add_del_remote_mapping +{ + u32 client_index; + u32 context; + bool is_add [default=true]; + bool is_src_dst; + bool del_all; + u32 vni; + u8 action; + vl_api_eid_t deid; + vl_api_eid_t seid; + u32 rloc_num; + vl_api_remote_locator_t rlocs[rloc_num]; +}; + +/** \brief add or delete LISP adjacency adjacency + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param is_add - add address if non-zero, else delete + @param vni - virtual network instance + @param reid - remote EID + @param leid - local EID +*/ +autoreply define lisp_add_del_adjacency +{ + u32 client_index; + u32 context; + bool is_add [default=true]; + u32 vni; + vl_api_eid_t reid; + vl_api_eid_t leid; +}; + +/** \brief add or delete map request itr rlocs + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param is_add - add address if non-zero, else delete + @param locator_set_name - locator set name +*/ +autoreply define lisp_add_del_map_request_itr_rlocs +{ + u32 client_index; + u32 context; + bool is_add [default=true]; + string locator_set_name[64]; +}; + +/** \brief Reply for lisp_add_del_map_request_itr_rlocs + @param context - returned sender context, to match reply w/ request + @param retval - return code +*/ + +/** \brief map/unmap vni/bd_index to vrf + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param is_add - add or delete mapping + @param dp_table - virtual network id/bridge domain index + @param vrf - vrf +*/ +autoreply define lisp_eid_table_add_del_map +{ + u32 client_index; + u32 context; + bool is_add [default=true]; + u32 vni; + u32 dp_table; + bool is_l2; +}; + +/** \brief Request for map lisp locator status + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param locator_set_index - index of locator_set + @param ls_name - locator set name + @param is_index_set - flag indicating whether ls_name or ls_index is set + */ +define lisp_locator_dump +{ + u32 client_index; + u32 context; + u32 ls_index; + string ls_name[64]; + u8 is_index_set; +}; + +/** \brief LISP locator_set status + @param local - if is set, then locator is local + @param locator_set_name - name of the locator_set + @param sw_if_index - sw_if_index of the locator + @param ip_address - ip address + @param priority - locator priority + @param weight - locator weight + */ +define lisp_locator_details +{ + u32 context; + u8 local; + vl_api_interface_index_t sw_if_index; + vl_api_address_t ip_address; + u8 priority; + u8 weight; +}; + +/** \brief LISP locator_set status + @param context - sender context, to match reply w/ request + @param ls_index - locator set index + @param ls_name - name of the locator set + */ +define lisp_locator_set_details +{ + u32 context; + u32 ls_index; + string ls_name[64]; +}; + +enum lisp_locator_set_filter : u8 { + LISP_LOCATOR_SET_FILTER_API_ALL = 0, + LISP_LOCATOR_SET_FILTER_API_LOCAL = 1, + LISP_LOCATOR_SET_FILTER_API_REMOTE = 2, +}; + +/** \brief Request for locator_set summary status + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param filter - filter type + */ +define lisp_locator_set_dump +{ + u32 client_index; + u32 context; + vl_api_lisp_locator_set_filter_t filter; +}; + +/** \brief Dump lisp eid-table + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param locator_set_index - index of locator_set, if ~0 then the mapping + is negative + @param action - negative map request action + @param is_local - local if non-zero, else remote + @param is_src_dst - EID is type of source/destination + @param deid - dst EID + @param seid - src EID + @param vni - virtual network instance + @param ttl - time to live + @param authoritative - authoritative + @param key_id + HMAC_NO_KEY 0 + HMAC_SHA_1_96 1 + HMAC_SHA_256_128 2 + @param key - secret key +*/ + +define lisp_eid_table_details +{ + u32 context; + u32 locator_set_index; + u8 action; + bool is_local; + bool is_src_dst; + u32 vni; + vl_api_eid_t deid; + vl_api_eid_t seid; + u32 ttl; + u8 authoritative; + vl_api_hmac_key_t key; +}; + +/** \brief Request for eid table summary status + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param eid_set - if non-zero request info about specific mapping + @param vni - virtual network instance; valid only if eid_set != 0 + @param prefix_length - prefix length if EID is IP address; + valid only if eid_set != 0 + @param eid - endpoint identifier + @param filter - filter type; + Support values: + 0: all eid + 1: local eid + 2: remote eid + */ +define lisp_eid_table_dump +{ + u32 client_index; + u32 context; + u8 eid_set; + u8 prefix_length; + u32 vni; + vl_api_eid_t eid; + vl_api_lisp_locator_set_filter_t filter; +}; + +/** \brief LISP adjacency + @param reid - remote EID + @param leid - local EID + */ +typedef lisp_adjacency +{ + vl_api_eid_t reid; + vl_api_eid_t leid; +}; + +/** \brief LISP adjacency reply + @param count - number of adjacencies + @param adjacencies - array of adjacencies + */ +define lisp_adjacencies_get_reply +{ + u32 context; + i32 retval; + u32 count; + vl_api_lisp_adjacency_t adjacencies[count]; +}; + +/** \brief Request for LISP adjacencies + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param vni - filter adjacencies by VNI + */ +define lisp_adjacencies_get +{ + u32 client_index; + u32 context; + u32 vni; +}; + +/** \brief Shows relationship between vni and vrf/bd + @param dp_table - VRF index or bridge domain index + @param vni - virtual network instance + */ +define lisp_eid_table_map_details +{ + u32 context; + u32 vni; + u32 dp_table; +}; + +/** \brief Request for lisp_eid_table_map_details + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param is_l2 - if set dump vni/bd mappings else vni/vrf + */ +define lisp_eid_table_map_dump +{ + u32 client_index; + u32 context; + bool is_l2; +}; + +/** \brief Dumps all VNIs used in mappings + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + */ +define lisp_eid_table_vni_dump +{ + u32 client_index; + u32 context; +}; + +/** \brief reply to lisp_eid_table_vni_dump + @param context - sender context, to match reply w/ request + @param vni - virtual network instance + */ +define lisp_eid_table_vni_details +{ + u32 context; + u32 vni; +}; + +/** \brief LISP map resolver status + @param ip_address - array of address bytes + */ +define lisp_map_resolver_details +{ + u32 context; + vl_api_address_t ip_address; +}; + +/** \brief Request for map resolver summary status + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + */ +define lisp_map_resolver_dump +{ + u32 client_index; + u32 context; +}; + +/** \brief LISP map server details + @param ip_address - array of address bytes + */ +define lisp_map_server_details +{ + u32 context; + vl_api_address_t ip_address; +}; + +/** \brief Request for map server summary status + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + */ +define lisp_map_server_dump +{ + u32 client_index; + u32 context; +}; + +/** \brief Request for lisp-gpe protocol status + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request +*/ +define show_lisp_status +{ + u32 client_index; + u32 context; +}; + +/** \brief Status of lisp, enable or disable + @param context - sender context, to match reply w/ request + @param feature_status - lisp enable if non-zero, else disable + @param gpe_status - lisp enable if non-zero, else disable +*/ +define show_lisp_status_reply +{ + u32 context; + i32 retval; + bool is_lisp_enabled; + bool is_gpe_enabled; +}; + +/** \brief Get LISP map request itr rlocs status + @param context - sender context, to match reply w/ request + @param locator_set_name - name of the locator_set + */ +define lisp_get_map_request_itr_rlocs +{ + u32 client_index; + u32 context; +}; + +/** \brief Request for map request itr rlocs summary status + */ +define lisp_get_map_request_itr_rlocs_reply +{ + u32 context; + i32 retval; + string locator_set_name[64]; +}; + +/** \brief Request for lisp pitr status + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request +*/ +define show_lisp_pitr +{ + u32 client_index; + u32 context; +}; + +/** \brief Status of lisp pitr, enable or disable + @param context - sender context, to match reply w/ request + @param status - lisp pitr enable if non-zero, else disable + @param locator_set_name - name of the locator_set +*/ +define show_lisp_pitr_reply +{ + u32 context; + i32 retval; + bool is_enabled; + string locator_set_name[64]; +}; + +/* + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/lisp/lisp-cp/lisp_api.c b/src/plugins/lisp/lisp-cp/lisp_api.c new file mode 100644 index 00000000000..041069d5613 --- /dev/null +++ b/src/plugins/lisp/lisp-cp/lisp_api.c @@ -0,0 +1,1068 @@ +/* + *------------------------------------------------------------------ + * lisp_api.c - lisp api + * + * Copyright (c) 2016 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------ + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +/* define message IDs */ +#include +#include +#include + +/** + * Base message ID fot the plugin + */ +static u32 lisp_base_msg_id; +#define REPLY_MSG_ID_BASE lisp_base_msg_id + +#include + +static locator_t * +unformat_lisp_locs (vl_api_remote_locator_t * rmt_locs, u32 rloc_num) +{ + u32 i; + locator_t *locs = 0, loc; + vl_api_remote_locator_t *r; + + for (i = 0; i < rloc_num; i++) + { + /* remote locators */ + r = &rmt_locs[i]; + clib_memset (&loc, 0, sizeof (loc)); + ip_address_decode2 (&r->ip_address, &loc.address.ippref.addr); + loc.address.ippref.len = + ip_address_max_len (loc.address.ippref.addr.version); + + loc.priority = r->priority; + loc.weight = r->weight; + + vec_add1 (locs, loc); + } + return locs; +} + +static void +vl_api_lisp_add_del_locator_set_t_handler (vl_api_lisp_add_del_locator_set_t * + mp) +{ + vl_api_lisp_add_del_locator_set_reply_t *rmp; + int rv = 0; + vnet_lisp_add_del_locator_set_args_t _a, *a = &_a; + locator_t locator; + vl_api_local_locator_t *ls_loc; + u32 ls_index = ~0, locator_num; + u8 *locator_name = NULL; + int i; + + clib_memset (a, 0, sizeof (a[0])); + + mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0; + locator_name = format (0, "%s", mp->locator_set_name); + vec_terminate_c_string (locator_name); + + a->name = locator_name; + a->is_add = mp->is_add; + a->local = 1; + locator_num = clib_net_to_host_u32 (mp->locator_num); + + clib_memset (&locator, 0, sizeof (locator)); + for (i = 0; i < locator_num; i++) + { + ls_loc = &mp->locators[i]; + VALIDATE_SW_IF_INDEX (ls_loc); + + locator.sw_if_index = htonl (ls_loc->sw_if_index); + locator.priority = ls_loc->priority; + locator.weight = ls_loc->weight; + locator.local = 1; + vec_add1 (a->locators, locator); + } + + rv = vnet_lisp_add_del_locator_set (a, &ls_index); + + BAD_SW_IF_INDEX_LABEL; + + vec_free (locator_name); + vec_free (a->locators); + + /* *INDENT-OFF* */ + REPLY_MACRO2 (VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY, + ({ + rmp->ls_index = clib_host_to_net_u32 (ls_index); + })); + /* *INDENT-ON* */ +} + +static void +vl_api_lisp_add_del_locator_t_handler (vl_api_lisp_add_del_locator_t * mp) +{ + vl_api_lisp_add_del_locator_reply_t *rmp; + int rv = 0; + locator_t locator, *locators = NULL; + vnet_lisp_add_del_locator_set_args_t _a, *a = &_a; + u32 ls_index = ~0; + u8 *locator_name = NULL; + + clib_memset (&locator, 0, sizeof (locator)); + clib_memset (a, 0, sizeof (a[0])); + + locator.sw_if_index = ntohl (mp->sw_if_index); + locator.priority = mp->priority; + locator.weight = mp->weight; + locator.local = 1; + vec_add1 (locators, locator); + + mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0; + locator_name = format (0, "%s", mp->locator_set_name); + vec_terminate_c_string (locator_name); + + a->name = locator_name; + a->locators = locators; + a->is_add = mp->is_add; + a->local = 1; + + rv = vnet_lisp_add_del_locator (a, NULL, &ls_index); + + vec_free (locators); + vec_free (locator_name); + + REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCATOR_REPLY); +} + +static void +vl_api_lisp_add_del_local_eid_t_handler (vl_api_lisp_add_del_local_eid_t * mp) +{ + vl_api_lisp_add_del_local_eid_reply_t *rmp; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + int rv = 0; + gid_address_t _gid, *gid = &_gid; + uword *p = NULL; + u32 locator_set_index = ~0, map_index = ~0; + vnet_lisp_add_del_mapping_args_t _a, *a = &_a; + u8 *name = NULL, *key = NULL; + clib_memset (a, 0, sizeof (a[0])); + clib_memset (gid, 0, sizeof (gid[0])); + + rv = unformat_lisp_eid_api (gid, mp->vni, &mp->eid); + if (rv) + goto out; + + mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0; + name = format (0, "%s", mp->locator_set_name); + vec_terminate_c_string (name); + p = hash_get_mem (lcm->locator_set_index_by_name, name); + if (!p) + { + rv = VNET_API_ERROR_INVALID_VALUE; + goto out; + } + locator_set_index = p[0]; + + if (mp->key.id) + key = format (0, "%s", mp->key.key); + + /* XXX treat batch configuration */ + a->is_add = mp->is_add; + gid_address_copy (&a->eid, gid); + a->locator_set_index = locator_set_index; + a->local = 1; + a->key = key; + a->key_id = clib_net_to_host_u16 (mp->key.id); + + rv = vnet_lisp_add_del_local_mapping (a, &map_index); + +out: + vec_free (name); + vec_free (key); + gid_address_free (&a->eid); + + REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY); +} + +static void + vl_api_lisp_eid_table_add_del_map_t_handler + (vl_api_lisp_eid_table_add_del_map_t * mp) +{ + vl_api_lisp_eid_table_add_del_map_reply_t *rmp; + int rv = 0; + rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni), + clib_net_to_host_u32 (mp->dp_table), + mp->is_l2, mp->is_add); +REPLY_MACRO (VL_API_LISP_EID_TABLE_ADD_DEL_MAP_REPLY)} + +static void +vl_api_lisp_add_del_map_server_t_handler (vl_api_lisp_add_del_map_server_t + * mp) +{ + vl_api_lisp_add_del_map_server_reply_t *rmp; + int rv = 0; + ip_address_t addr; + + clib_memset (&addr, 0, sizeof (addr)); + + ip_address_decode2 (&mp->ip_address, &addr); + rv = vnet_lisp_add_del_map_server (&addr, mp->is_add); + + REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_SERVER_REPLY); +} + +static void +vl_api_lisp_add_del_map_resolver_t_handler (vl_api_lisp_add_del_map_resolver_t + * mp) +{ + vl_api_lisp_add_del_map_resolver_reply_t *rmp; + int rv = 0; + vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a; + + clib_memset (a, 0, sizeof (a[0])); + + a->is_add = mp->is_add; + ip_address_decode2 (&mp->ip_address, &a->address); + + rv = vnet_lisp_add_del_map_resolver (a); + + REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY); +} + +static void + vl_api_lisp_map_register_enable_disable_t_handler + (vl_api_lisp_map_register_enable_disable_t * mp) +{ + vl_api_lisp_map_register_enable_disable_reply_t *rmp; + int rv = 0; + + vnet_lisp_map_register_enable_disable (mp->is_enable); + REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY); +} + +static void + vl_api_lisp_rloc_probe_enable_disable_t_handler + (vl_api_lisp_rloc_probe_enable_disable_t * mp) +{ + vl_api_lisp_rloc_probe_enable_disable_reply_t *rmp; + int rv = 0; + + vnet_lisp_rloc_probe_enable_disable (mp->is_enable); + REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY); +} + +static void +vl_api_lisp_enable_disable_t_handler (vl_api_lisp_enable_disable_t * mp) +{ + vl_api_lisp_enable_disable_reply_t *rmp; + int rv = 0; + + vnet_lisp_enable_disable (mp->is_enable); + REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY); +} + +static void + vl_api_show_lisp_map_request_mode_t_handler + (vl_api_show_lisp_map_request_mode_t * mp) +{ + int rv = 0; + vl_api_show_lisp_map_request_mode_reply_t *rmp; + + /* *INDENT-OFF* */ + REPLY_MACRO2(VL_API_SHOW_LISP_MAP_REQUEST_MODE_REPLY, + ({ + rmp->is_src_dst = vnet_lisp_get_map_request_mode (); + })); + /* *INDENT-ON* */ +} + +static void +vl_api_lisp_map_request_mode_t_handler (vl_api_lisp_map_request_mode_t * mp) +{ + vl_api_lisp_map_request_mode_reply_t *rmp; + int rv = 0; + + rv = vnet_lisp_set_map_request_mode (mp->is_src_dst); + + REPLY_MACRO (VL_API_LISP_MAP_REQUEST_MODE_REPLY); +} + +static void +vl_api_lisp_pitr_set_locator_set_t_handler (vl_api_lisp_pitr_set_locator_set_t + * mp) +{ + vl_api_lisp_pitr_set_locator_set_reply_t *rmp; + int rv = 0; + u8 *ls_name = 0; + + mp->ls_name[sizeof (mp->ls_name) - 1] = 0; + ls_name = format (0, "%s", mp->ls_name); + vec_terminate_c_string (ls_name); + rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add); + vec_free (ls_name); + + REPLY_MACRO (VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY); +} + +static void +vl_api_lisp_use_petr_t_handler (vl_api_lisp_use_petr_t * mp) +{ + vl_api_lisp_use_petr_reply_t *rmp; + int rv = 0; + ip_address_t addr; + + ip_address_decode2 (&mp->ip_address, &addr); + rv = vnet_lisp_use_petr (&addr, mp->is_add); + + REPLY_MACRO (VL_API_LISP_USE_PETR_REPLY); +} + +static void +vl_api_show_lisp_use_petr_t_handler (vl_api_show_lisp_use_petr_t * mp) +{ + vl_api_show_lisp_use_petr_reply_t *rmp = NULL; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + mapping_t *m; + locator_set_t *ls = 0; + int rv = 0; + locator_t *loc = 0; + u8 status = 0; + gid_address_t addr; + + clib_memset (&addr, 0, sizeof (addr)); + status = lcm->flags & LISP_FLAG_USE_PETR; + if (status) + { + m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index); + if (~0 != m->locator_set_index) + { + ls = + pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index); + loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]); + gid_address_copy (&addr, &loc->address); + } + } + + /* *INDENT-OFF* */ + REPLY_MACRO2 (VL_API_SHOW_LISP_USE_PETR_REPLY, + { + rmp->is_petr_enable = status; + ip_address_encode2 (&gid_address_ip (&addr), &rmp->ip_address); + }); + /* *INDENT-ON* */ +} + +static void + vl_api_lisp_add_del_map_request_itr_rlocs_t_handler + (vl_api_lisp_add_del_map_request_itr_rlocs_t * mp) +{ + vl_api_lisp_add_del_map_request_itr_rlocs_reply_t *rmp; + int rv = 0; + u8 *locator_set_name = NULL; + vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a; + + mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0; + locator_set_name = format (0, "%s", mp->locator_set_name); + vec_terminate_c_string (locator_set_name); + + a->is_add = mp->is_add; + a->locator_set_name = locator_set_name; + + rv = vnet_lisp_add_del_mreq_itr_rlocs (a); + + vec_free (locator_set_name); + + REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY); +} + +static void + vl_api_lisp_add_del_remote_mapping_t_handler + (vl_api_lisp_add_del_remote_mapping_t * mp) +{ + locator_t *rlocs = 0; + vl_api_lisp_add_del_remote_mapping_reply_t *rmp; + int rv = 0; + gid_address_t _eid, *eid = &_eid; + u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num); + + clib_memset (eid, 0, sizeof (eid[0])); + + rv = unformat_lisp_eid_api (eid, mp->vni, &mp->deid); + if (rv) + goto send_reply; + + rlocs = unformat_lisp_locs (mp->rlocs, rloc_num); + + if (!mp->is_add) + { + vnet_lisp_add_del_adjacency_args_t _a, *a = &_a; + clib_memset (a, 0, sizeof (*a)); + gid_address_copy (&a->reid, eid); + a->is_add = 0; + rv = vnet_lisp_add_del_adjacency (a); + if (rv) + { + goto out; + } + } + + /* NOTE: for now this works as a static remote mapping, i.e., + * not authoritative and ttl infinite. */ + if (mp->is_add) + { + vnet_lisp_add_del_mapping_args_t _m_args, *m_args = &_m_args; + clib_memset (m_args, 0, sizeof (m_args[0])); + gid_address_copy (&m_args->eid, eid); + m_args->action = mp->action; + m_args->is_static = 1; + m_args->ttl = ~0; + m_args->authoritative = 0; + rv = vnet_lisp_add_mapping (m_args, rlocs, NULL, NULL); + } + else + { + rv = vnet_lisp_del_mapping (eid, NULL); + } + + if (mp->del_all) + vnet_lisp_clear_all_remote_adjacencies (); + +out: + vec_free (rlocs); +send_reply: + REPLY_MACRO (VL_API_LISP_ADD_DEL_REMOTE_MAPPING_REPLY); +} + +static void +vl_api_lisp_add_del_adjacency_t_handler (vl_api_lisp_add_del_adjacency_t * mp) +{ + vl_api_lisp_add_del_adjacency_reply_t *rmp; + vnet_lisp_add_del_adjacency_args_t _a, *a = &_a; + + int rv = 0; + clib_memset (a, 0, sizeof (a[0])); + + rv = unformat_lisp_eid_api (&a->leid, mp->vni, &mp->leid); + rv = unformat_lisp_eid_api (&a->reid, mp->vni, &mp->reid); + + if (rv) + goto send_reply; + + a->is_add = mp->is_add; + rv = vnet_lisp_add_del_adjacency (a); + +send_reply: + REPLY_MACRO (VL_API_LISP_ADD_DEL_ADJACENCY_REPLY); +} + +static void +send_lisp_locator_details (lisp_cp_main_t * lcm, + locator_t * loc, vl_api_registration_t * reg, + u32 context) +{ + vl_api_lisp_locator_details_t *rmp; + + rmp = vl_msg_api_alloc (sizeof (*rmp)); + clib_memset (rmp, 0, sizeof (*rmp)); + rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_DETAILS + REPLY_MSG_ID_BASE); + rmp->context = context; + + rmp->local = loc->local; + if (loc->local) + { + rmp->sw_if_index = ntohl (loc->sw_if_index); + } + else + { + ip_address_encode2 (&gid_address_ip (&loc->address), &rmp->ip_address); + } + rmp->priority = loc->priority; + rmp->weight = loc->weight; + + vl_api_send_msg (reg, (u8 *) rmp); +} + +static void +vl_api_lisp_locator_dump_t_handler (vl_api_lisp_locator_dump_t * mp) +{ + u8 *ls_name = 0; + vl_api_registration_t *reg = 0; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + locator_set_t *lsit = 0; + locator_t *loc = 0; + u32 ls_index = ~0, *locit = 0; + uword *p = 0; + + reg = vl_api_client_index_to_registration (mp->client_index); + if (!reg) + return; + + if (mp->is_index_set) + ls_index = htonl (mp->ls_index); + else + { + /* make sure we get a proper C-string */ + mp->ls_name[sizeof (mp->ls_name) - 1] = 0; + ls_name = format (0, "%s", mp->ls_name); + vec_terminate_c_string (ls_name); + p = hash_get_mem (lcm->locator_set_index_by_name, ls_name); + if (!p) + goto out; + ls_index = p[0]; + } + + if (pool_is_free_index (lcm->locator_set_pool, ls_index)) + return; + + lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index); + + vec_foreach (locit, lsit->locator_indices) + { + loc = pool_elt_at_index (lcm->locator_pool, locit[0]); + send_lisp_locator_details (lcm, loc, reg, mp->context); + }; +out: + vec_free (ls_name); +} + +static void +send_lisp_locator_set_details (lisp_cp_main_t * lcm, + locator_set_t * lsit, + vl_api_registration_t * reg, u32 context, + u32 ls_index) +{ + vl_api_lisp_locator_set_details_t *rmp; + u8 *str = 0; + + rmp = vl_msg_api_alloc (sizeof (*rmp)); + clib_memset (rmp, 0, sizeof (*rmp)); + rmp->_vl_msg_id = + ntohs (VL_API_LISP_LOCATOR_SET_DETAILS + REPLY_MSG_ID_BASE); + rmp->context = context; + + rmp->ls_index = htonl (ls_index); + if (lsit->local) + { + ASSERT (lsit->name != NULL); + strncpy ((char *) rmp->ls_name, (char *) lsit->name, + vec_len (lsit->name)); + } + else + { + str = format (0, "", ls_index); + strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str)); + vec_free (str); + } + + vl_api_send_msg (reg, (u8 *) rmp); +} + +static void +vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t * mp) +{ + vl_api_registration_t *reg; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + locator_set_t *lsit = NULL; + u8 filter; + + reg = vl_api_client_index_to_registration (mp->client_index); + if (!reg) + return; + + filter = mp->filter; + /* *INDENT-OFF* */ + pool_foreach (lsit, lcm->locator_set_pool, + ({ + if (filter && !((1 == filter && lsit->local) || + (2 == filter && !lsit->local))) + { + continue; + } + send_lisp_locator_set_details (lcm, lsit, reg, mp->context, + lsit - lcm->locator_set_pool); + })); + /* *INDENT-ON* */ +} + +static void +send_lisp_eid_table_details (mapping_t * mapit, + vl_api_registration_t * reg, u32 context, + u8 filter) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + locator_set_t *ls = 0; + vl_api_lisp_eid_table_details_t *rmp = NULL; + gid_address_t *gid = NULL; + + switch (filter) + { + case 0: /* all mappings */ + break; + + case 1: /* local only */ + if (!mapit->local) + return; + break; + case 2: /* remote only */ + if (mapit->local) + return; + break; + default: + clib_warning ("Filter error, unknown filter: %d", filter); + return; + } + + /* don't send PITR generated mapping */ + if (mapit->pitr_set) + return; + + gid = &mapit->eid; + + rmp = vl_msg_api_alloc (sizeof (*rmp)); + clib_memset (rmp, 0, sizeof (*rmp)); + rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_DETAILS + REPLY_MSG_ID_BASE); + + ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index); + if (vec_len (ls->locator_indices) == 0) + rmp->locator_set_index = ~0; + else + rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index); + + rmp->is_local = mapit->local; + rmp->ttl = clib_host_to_net_u32 (mapit->ttl); + rmp->action = mapit->action; + rmp->authoritative = mapit->authoritative; + switch (gid_address_type (gid)) + { + case GID_ADDR_SRC_DST: + lisp_fid_put_api (&rmp->seid, &gid_address_sd_src (gid)); + lisp_fid_put_api (&rmp->deid, &gid_address_sd_dst (gid)); + rmp->is_src_dst = 1; + break; + case GID_ADDR_IP_PREFIX: + lisp_gid_put_api (&rmp->seid, gid); + break; + case GID_ADDR_MAC: + lisp_gid_put_api (&rmp->seid, gid); + break; + default: + ASSERT (0); + } + rmp->context = context; + rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid)); + rmp->key.id = clib_host_to_net_u16 (mapit->key_id); + memcpy (rmp->key.key, mapit->key, vec_len (mapit->key)); + vl_api_send_msg (reg, (u8 *) rmp); +} + +static void +vl_api_lisp_eid_table_dump_t_handler (vl_api_lisp_eid_table_dump_t * mp) +{ + u32 mi; + vl_api_registration_t *reg; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + mapping_t *mapit = NULL; + gid_address_t _eid, *eid = &_eid; + + reg = vl_api_client_index_to_registration (mp->client_index); + if (!reg) + return; + + if (mp->eid_set) + { + clib_memset (eid, 0, sizeof (*eid)); + + unformat_lisp_eid_api (eid, mp->vni, &mp->eid); + + mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid); + if ((u32) ~ 0 == mi) + return; + + mapit = pool_elt_at_index (lcm->mapping_pool, mi); + send_lisp_eid_table_details (mapit, reg, mp->context, + 0 /* ignore filter */ ); + } + else + { + /* *INDENT-OFF* */ + pool_foreach (mapit, lcm->mapping_pool, + ({ + send_lisp_eid_table_details(mapit, reg, mp->context, + mp->filter); + })); + /* *INDENT-ON* */ + } +} + +static void +send_lisp_map_server_details (ip_address_t * ip, vl_api_registration_t * reg, + u32 context) +{ + vl_api_lisp_map_server_details_t *rmp = NULL; + + rmp = vl_msg_api_alloc (sizeof (*rmp)); + clib_memset (rmp, 0, sizeof (*rmp)); + rmp->_vl_msg_id = + ntohs (VL_API_LISP_MAP_SERVER_DETAILS + REPLY_MSG_ID_BASE); + + ip_address_encode2 (ip, &rmp->ip_address); + rmp->context = context; + + vl_api_send_msg (reg, (u8 *) rmp); +} + +static void +vl_api_lisp_map_server_dump_t_handler (vl_api_lisp_map_server_dump_t * mp) +{ + vl_api_registration_t *reg; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + lisp_msmr_t *mr; + + reg = vl_api_client_index_to_registration (mp->client_index); + if (!reg) + return; + + vec_foreach (mr, lcm->map_servers) + { + send_lisp_map_server_details (&mr->address, reg, mp->context); + } +} + +static void +send_lisp_map_resolver_details (ip_address_t * ip, + vl_api_registration_t * reg, u32 context) +{ + vl_api_lisp_map_resolver_details_t *rmp = NULL; + + rmp = vl_msg_api_alloc (sizeof (*rmp)); + clib_memset (rmp, 0, sizeof (*rmp)); + rmp->_vl_msg_id = + ntohs (VL_API_LISP_MAP_RESOLVER_DETAILS + REPLY_MSG_ID_BASE); + + ip_address_encode2 (ip, &rmp->ip_address); + rmp->context = context; + + vl_api_send_msg (reg, (u8 *) rmp); +} + +static void +vl_api_lisp_map_resolver_dump_t_handler (vl_api_lisp_map_resolver_dump_t * mp) +{ + vl_api_registration_t *reg; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + lisp_msmr_t *mr; + + reg = vl_api_client_index_to_registration (mp->client_index); + if (!reg) + return; + + vec_foreach (mr, lcm->map_resolvers) + { + send_lisp_map_resolver_details (&mr->address, reg, mp->context); + } +} + +static void +send_eid_table_map_pair (hash_pair_t * p, vl_api_registration_t * reg, + u32 context) +{ + vl_api_lisp_eid_table_map_details_t *rmp = NULL; + + rmp = vl_msg_api_alloc (sizeof (*rmp)); + clib_memset (rmp, 0, sizeof (*rmp)); + rmp->_vl_msg_id = + ntohs (VL_API_LISP_EID_TABLE_MAP_DETAILS + REPLY_MSG_ID_BASE); + + rmp->vni = clib_host_to_net_u32 (p->key); + rmp->dp_table = clib_host_to_net_u32 (p->value[0]); + rmp->context = context; + vl_api_send_msg (reg, (u8 *) rmp); +} + +static void +vl_api_lisp_eid_table_map_dump_t_handler (vl_api_lisp_eid_table_map_dump_t * + mp) +{ + vl_api_registration_t *reg; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + hash_pair_t *p; + uword *vni_table = 0; + + reg = vl_api_client_index_to_registration (mp->client_index); + if (!reg) + return; + + if (mp->is_l2) + { + vni_table = lcm->bd_id_by_vni; + } + else + { + vni_table = lcm->table_id_by_vni; + } + + /* *INDENT-OFF* */ + hash_foreach_pair (p, vni_table, + ({ + send_eid_table_map_pair (p, reg, mp->context); + })); + /* *INDENT-ON* */ +} + +static void +send_eid_table_vni (u32 vni, vl_api_registration_t * reg, u32 context) +{ + vl_api_lisp_eid_table_vni_details_t *rmp = 0; + + rmp = vl_msg_api_alloc (sizeof (*rmp)); + clib_memset (rmp, 0, sizeof (*rmp)); + rmp->_vl_msg_id = + ntohs (VL_API_LISP_EID_TABLE_VNI_DETAILS + REPLY_MSG_ID_BASE); + rmp->context = context; + rmp->vni = clib_host_to_net_u32 (vni); + vl_api_send_msg (reg, (u8 *) rmp); +} + +static void +lisp_adjacency_copy (vl_api_lisp_adjacency_t * dst, lisp_adjacency_t * adjs) +{ + lisp_adjacency_t *adj; + vl_api_lisp_adjacency_t a; + u32 i, n = vec_len (adjs); + + for (i = 0; i < n; i++) + { + adj = vec_elt_at_index (adjs, i); + clib_memset (&a, 0, sizeof (a)); + + lisp_gid_put_api (&a.reid, &adj->reid); + lisp_gid_put_api (&a.leid, &adj->leid); + + dst[i] = a; + } +} + +static void + vl_api_show_lisp_rloc_probe_state_t_handler + (vl_api_show_lisp_rloc_probe_state_t * mp) +{ + vl_api_show_lisp_rloc_probe_state_reply_t *rmp = 0; + int rv = 0; + + /* *INDENT-OFF* */ + REPLY_MACRO2 (VL_API_SHOW_LISP_RLOC_PROBE_STATE_REPLY, + { + rmp->is_enabled = vnet_lisp_rloc_probe_state_get (); + }); + /* *INDENT-ON* */ +} + +static void + vl_api_show_lisp_map_register_state_t_handler + (vl_api_show_lisp_map_register_state_t * mp) +{ + vl_api_show_lisp_map_register_state_reply_t *rmp = 0; + int rv = 0; + + /* *INDENT-OFF* */ + REPLY_MACRO2 (VL_API_SHOW_LISP_MAP_REGISTER_STATE_REPLY, + { + rmp->is_enabled = vnet_lisp_map_register_state_get (); + }); + /* *INDENT-ON* */ +} + +static void +vl_api_lisp_adjacencies_get_t_handler (vl_api_lisp_adjacencies_get_t * mp) +{ + vl_api_lisp_adjacencies_get_reply_t *rmp = 0; + lisp_adjacency_t *adjs = 0; + int rv = 0; + u32 size = ~0; + u32 vni = clib_net_to_host_u32 (mp->vni); + + adjs = vnet_lisp_adjacencies_get_by_vni (vni); + size = vec_len (adjs) * sizeof (vl_api_lisp_adjacency_t); + + /* *INDENT-OFF* */ + REPLY_MACRO4 (VL_API_LISP_ADJACENCIES_GET_REPLY, size, + { + rmp->count = clib_host_to_net_u32 (vec_len (adjs)); + lisp_adjacency_copy (rmp->adjacencies, adjs); + }); + /* *INDENT-ON* */ + + vec_free (adjs); +} + +static void +vl_api_lisp_eid_table_vni_dump_t_handler (vl_api_lisp_eid_table_vni_dump_t * + mp) +{ + hash_pair_t *p; + u32 *vnis = 0; + vl_api_registration_t *reg = 0; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + + reg = vl_api_client_index_to_registration (mp->client_index); + if (!reg) + return; + + /* *INDENT-OFF* */ + hash_foreach_pair (p, lcm->table_id_by_vni, + ({ + hash_set (vnis, p->key, 0); + })); + + hash_foreach_pair (p, lcm->bd_id_by_vni, + ({ + hash_set (vnis, p->key, 0); + })); + + hash_foreach_pair (p, vnis, + ({ + send_eid_table_vni (p->key, reg, mp->context); + })); + /* *INDENT-ON* */ + + hash_free (vnis); +} + +static void +vl_api_show_lisp_status_t_handler (vl_api_show_lisp_status_t * mp) +{ + vl_api_show_lisp_status_reply_t *rmp = NULL; + int rv = 0; + + /* *INDENT-OFF* */ + REPLY_MACRO2(VL_API_SHOW_LISP_STATUS_REPLY, + ({ + rmp->is_gpe_enabled = vnet_lisp_gpe_enable_disable_status (); + rmp->is_lisp_enabled = vnet_lisp_enable_disable_status (); + })); + /* *INDENT-ON* */ +} + +static void + vl_api_lisp_get_map_request_itr_rlocs_t_handler + (vl_api_lisp_get_map_request_itr_rlocs_t * mp) +{ + vl_api_lisp_get_map_request_itr_rlocs_reply_t *rmp = NULL; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + locator_set_t *loc_set = 0; + u8 *tmp_str = 0; + int rv = 0; + + if (~0 == lcm->mreq_itr_rlocs) + { + tmp_str = format (0, " "); + } + else + { + loc_set = + pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs); + tmp_str = format (0, "%s", loc_set->name); + } + + /* *INDENT-OFF* */ + REPLY_MACRO2(VL_API_LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY, + ({ + strncpy((char *) rmp->locator_set_name, (char *) tmp_str, + ARRAY_LEN(rmp->locator_set_name) - 1); + })); + /* *INDENT-ON* */ + + vec_free (tmp_str); +} + +static void +vl_api_show_lisp_pitr_t_handler (vl_api_show_lisp_pitr_t * mp) +{ + vl_api_show_lisp_pitr_reply_t *rmp = NULL; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + mapping_t *m; + locator_set_t *ls = 0; + u8 *tmp_str = 0; + int rv = 0; + + u8 is_enabled = (lcm->flags & LISP_FLAG_PITR_MODE) + && lcm->pitr_map_index != ~0; + + if (!is_enabled) + { + tmp_str = format (0, "N/A"); + } + else + { + m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index); + if (~0 != m->locator_set_index) + { + ls = + pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index); + tmp_str = format (0, "%s", ls->name); + } + else + { + tmp_str = format (0, "N/A"); + } + } + vec_add1 (tmp_str, 0); + + /* *INDENT-OFF* */ + REPLY_MACRO2(VL_API_SHOW_LISP_PITR_REPLY, + ({ + rmp->is_enabled = lcm->flags & LISP_FLAG_PITR_MODE; + strncpy((char *) rmp->locator_set_name, (char *) tmp_str, + ARRAY_LEN(rmp->locator_set_name) - 1); + })); + /* *INDENT-ON* */ +} + +/* + * lisp_api_hookup + * Add vpe's API message handlers to the table. + * vlib has already mapped shared memory and + * added the client registration handlers. + * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process() + */ +#include + +static clib_error_t * +lisp_api_hookup (vlib_main_t * vm) +{ + /* + * Set up the (msg_name, crc, message-id) table + */ + lisp_base_msg_id = setup_message_id_table (); + + return NULL; +} + +VLIB_API_INIT_FUNCTION (lisp_api_hookup); + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/lisp/lisp-cp/lisp_cli.c b/src/plugins/lisp/lisp-cp/lisp_cli.c new file mode 100644 index 00000000000..8685c1cc04a --- /dev/null +++ b/src/plugins/lisp/lisp-cp/lisp_cli.c @@ -0,0 +1,1603 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +static clib_error_t * +lisp_show_adjacencies_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + lisp_adjacency_t *adjs, *adj; + vlib_cli_output (vm, "%s %40s\n", "leid", "reid"); + unformat_input_t _line_input, *line_input = &_line_input; + u32 vni = ~0; + clib_error_t *error = NULL; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "vni %d", &vni)) + ; + else + { + vlib_cli_output (vm, "parse error: '%U'", + format_unformat_error, line_input); + goto done; + } + } + + if (~0 == vni) + { + vlib_cli_output (vm, "error: no vni specified!"); + goto done; + } + + adjs = vnet_lisp_adjacencies_get_by_vni (vni); + + vec_foreach (adj, adjs) + { + vlib_cli_output (vm, "%U %40U\n", format_gid_address, &adj->leid, + format_gid_address, &adj->reid); + } + vec_free (adjs); + +done: + unformat_free (line_input); + + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (lisp_show_adjacencies_command) = { + .path = "show lisp adjacencies", + .short_help = "show lisp adjacencies", + .function = lisp_show_adjacencies_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_add_del_map_server_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + int rv = 0; + u8 is_add = 1, ip_set = 0; + ip_address_t ip; + unformat_input_t _line_input, *line_input = &_line_input; + clib_error_t *error = NULL; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "add")) + is_add = 1; + else if (unformat (line_input, "del")) + is_add = 0; + else if (unformat (line_input, "%U", unformat_ip_address, &ip)) + ip_set = 1; + else + { + vlib_cli_output (vm, "parse error: '%U'", + format_unformat_error, line_input); + goto done; + } + } + + if (!ip_set) + { + vlib_cli_output (vm, "map-server ip address not set!"); + goto done; + } + + rv = vnet_lisp_add_del_map_server (&ip, is_add); + if (!rv) + vlib_cli_output (vm, "failed to %s map-server!", + is_add ? "add" : "delete"); + +done: + unformat_free (line_input); + + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (lisp_add_del_map_server_command) = { + .path = "lisp map-server", + .short_help = "lisp map-server add|del ", + .function = lisp_add_del_map_server_command_fn, +}; +/* *INDENT-ON* */ + + +static clib_error_t * +lisp_add_del_local_eid_command_fn (vlib_main_t * vm, unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + unformat_input_t _line_input, *line_input = &_line_input; + u8 is_add = 1; + gid_address_t eid; + gid_address_t *eids = 0; + clib_error_t *error = 0; + u8 *locator_set_name = 0; + u32 locator_set_index = 0, map_index = 0; + uword *p; + vnet_lisp_add_del_mapping_args_t _a, *a = &_a; + int rv = 0; + u32 vni = 0; + u8 *key = 0; + u32 key_id = 0; + + clib_memset (&eid, 0, sizeof (eid)); + clib_memset (a, 0, sizeof (*a)); + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "add")) + is_add = 1; + else if (unformat (line_input, "del")) + is_add = 0; + else if (unformat (line_input, "eid %U", unformat_gid_address, &eid)) + ; + else if (unformat (line_input, "vni %d", &vni)) + gid_address_vni (&eid) = vni; + else if (unformat (line_input, "secret-key %_%v%_", &key)) + ; + else if (unformat (line_input, "key-id %U", unformat_hmac_key_id, + &key_id)) + ; + else if (unformat (line_input, "locator-set %_%v%_", &locator_set_name)) + { + vec_terminate_c_string (locator_set_name); + p = hash_get_mem (lcm->locator_set_index_by_name, locator_set_name); + if (!p) + { + error = clib_error_return (0, "locator-set %s doesn't exist", + locator_set_name); + goto done; + } + locator_set_index = p[0]; + } + else + { + error = unformat_parse_error (line_input); + goto done; + } + } + /* XXX treat batch configuration */ + + if (GID_ADDR_SRC_DST == gid_address_type (&eid)) + { + error = + clib_error_return (0, "src/dst is not supported for local EIDs!"); + goto done; + } + + if (key && (0 == key_id)) + { + vlib_cli_output (vm, "invalid key_id!"); + goto done;; + } + + gid_address_copy (&a->eid, &eid); + a->is_add = is_add; + a->locator_set_index = locator_set_index; + a->local = 1; + a->key = key; + a->key_id = key_id; + + rv = vnet_lisp_add_del_local_mapping (a, &map_index); + if (0 != rv) + { + error = clib_error_return (0, "failed to %s local mapping!", + is_add ? "add" : "delete"); + } +done: + vec_free (eids); + if (locator_set_name) + vec_free (locator_set_name); + gid_address_free (&a->eid); + vec_free (a->key); + unformat_free (line_input); + + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (lisp_add_del_local_eid_command) = { + .path = "lisp eid-table", + .short_help = "lisp eid-table add/del [vni ] eid " + "locator-set [key key-id sha1|sha256 ]", + .function = lisp_add_del_local_eid_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_eid_table_map_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + u8 is_add = 1, is_l2 = 0; + u32 vni = 0, dp_id = 0; + unformat_input_t _line_input, *line_input = &_line_input; + clib_error_t *error = NULL; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "del")) + is_add = 0; + else if (unformat (line_input, "vni %d", &vni)) + ; + else if (unformat (line_input, "vrf %d", &dp_id)) + ; + else if (unformat (line_input, "bd %d", &dp_id)) + is_l2 = 1; + else + { + error = unformat_parse_error (line_input); + goto done; + } + } + vnet_lisp_eid_table_map (vni, dp_id, is_l2, is_add); + +done: + unformat_free (line_input); + + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (lisp_eid_table_map_command) = { + .path = "lisp eid-table map", + .short_help = "lisp eid-table map [del] vni vrf | bd ", + .function = lisp_eid_table_map_command_fn, +}; +/* *INDENT-ON* */ + +/** + * Handler for add/del remote mapping CLI. + * + * @param vm vlib context + * @param input input from user + * @param cmd cmd + * @return pointer to clib error structure + */ +static clib_error_t * +lisp_add_del_remote_mapping_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + clib_error_t *error = 0; + unformat_input_t _line_input, *line_input = &_line_input; + u8 is_add = 1, del_all = 0; + locator_t rloc, *rlocs = 0, *curr_rloc = 0; + gid_address_t eid; + u8 eid_set = 0; + u32 vni, action = ~0, p, w; + int rv; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + clib_memset (&eid, 0, sizeof (eid)); + clib_memset (&rloc, 0, sizeof (rloc)); + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "del-all")) + del_all = 1; + else if (unformat (line_input, "del")) + is_add = 0; + else if (unformat (line_input, "add")) + ; + else if (unformat (line_input, "eid %U", unformat_gid_address, &eid)) + eid_set = 1; + else if (unformat (line_input, "vni %u", &vni)) + { + gid_address_vni (&eid) = vni; + } + else if (unformat (line_input, "p %d w %d", &p, &w)) + { + if (!curr_rloc) + { + clib_warning + ("No RLOC configured for setting priority/weight!"); + goto done; + } + curr_rloc->priority = p; + curr_rloc->weight = w; + } + else if (unformat (line_input, "rloc %U", unformat_ip_address, + &gid_address_ip (&rloc.address))) + { + /* since rloc is stored in ip prefix we need to set prefix length */ + ip_prefix_t *pref = &gid_address_ippref (&rloc.address); + + u8 version = gid_address_ip_version (&rloc.address); + ip_prefix_len (pref) = ip_address_max_len (version); + + vec_add1 (rlocs, rloc); + curr_rloc = &rlocs[vec_len (rlocs) - 1]; + } + else if (unformat (line_input, "action %U", + unformat_negative_mapping_action, &action)) + ; + else + { + clib_warning ("parse error"); + goto done; + } + } + + if (!eid_set) + { + clib_warning ("missing eid!"); + goto done; + } + + if (!del_all) + { + if (is_add && (~0 == action) && 0 == vec_len (rlocs)) + { + clib_warning ("no action set for negative map-reply!"); + goto done; + } + } + else + { + vnet_lisp_clear_all_remote_adjacencies (); + goto done; + } + + /* TODO build src/dst with seid */ + + /* if it's a delete, clean forwarding */ + if (!is_add) + { + vnet_lisp_add_del_adjacency_args_t _a, *a = &_a; + clib_memset (a, 0, sizeof (a[0])); + gid_address_copy (&a->reid, &eid); + if (vnet_lisp_add_del_adjacency (a)) + { + clib_warning ("failed to delete adjacency!"); + goto done; + } + } + + /* add as static remote mapping, i.e., not authoritative and infinite + * ttl */ + if (is_add) + { + vnet_lisp_add_del_mapping_args_t _map_args, *map_args = &_map_args; + clib_memset (map_args, 0, sizeof (map_args[0])); + gid_address_copy (&map_args->eid, &eid); + map_args->action = action; + map_args->is_static = 1; + map_args->authoritative = 0; + map_args->ttl = ~0; + rv = vnet_lisp_add_mapping (map_args, rlocs, NULL, NULL); + } + else + rv = vnet_lisp_del_mapping (&eid, NULL); + + if (rv) + clib_warning ("failed to %s remote mapping!", is_add ? "add" : "delete"); + +done: + vec_free (rlocs); + unformat_free (line_input); + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (lisp_add_del_remote_mapping_command) = { + .path = "lisp remote-mapping", + .short_help = "lisp remote-mapping add|del [del-all] vni " + "eid [action ] rloc p " + "w [rloc ... ]", + .function = lisp_add_del_remote_mapping_command_fn, +}; +/* *INDENT-ON* */ + +/** + * Handler for add/del adjacency CLI. + */ +static clib_error_t * +lisp_add_del_adjacency_command_fn (vlib_main_t * vm, unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + clib_error_t *error = 0; + unformat_input_t _line_input, *line_input = &_line_input; + vnet_lisp_add_del_adjacency_args_t _a, *a = &_a; + u8 is_add = 1; + ip_prefix_t *reid_ippref, *leid_ippref; + gid_address_t leid, reid; + u8 *dmac = gid_address_mac (&reid); + u8 *smac = gid_address_mac (&leid); + u8 reid_set = 0, leid_set = 0; + u32 vni; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + clib_memset (&reid, 0, sizeof (reid)); + clib_memset (&leid, 0, sizeof (leid)); + + leid_ippref = &gid_address_ippref (&leid); + reid_ippref = &gid_address_ippref (&reid); + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "del")) + is_add = 0; + else if (unformat (line_input, "add")) + ; + else if (unformat (line_input, "reid %U", + unformat_ip_prefix, reid_ippref)) + { + gid_address_type (&reid) = GID_ADDR_IP_PREFIX; + reid_set = 1; + } + else if (unformat (line_input, "reid %U", unformat_mac_address, dmac)) + { + gid_address_type (&reid) = GID_ADDR_MAC; + reid_set = 1; + } + else if (unformat (line_input, "vni %u", &vni)) + { + gid_address_vni (&leid) = vni; + gid_address_vni (&reid) = vni; + } + else if (unformat (line_input, "leid %U", + unformat_ip_prefix, leid_ippref)) + { + gid_address_type (&leid) = GID_ADDR_IP_PREFIX; + leid_set = 1; + } + else if (unformat (line_input, "leid %U", unformat_mac_address, smac)) + { + gid_address_type (&leid) = GID_ADDR_MAC; + leid_set = 1; + } + else + { + clib_warning ("parse error"); + goto done; + } + } + + if (!reid_set || !leid_set) + { + clib_warning ("missing remote or local eid!"); + goto done; + } + + if ((gid_address_type (&leid) != gid_address_type (&reid)) + || (gid_address_type (&reid) == GID_ADDR_IP_PREFIX + && ip_prefix_version (reid_ippref) + != ip_prefix_version (leid_ippref))) + { + clib_warning ("remote and local EIDs are of different types!"); + goto done; + } + + clib_memset (a, 0, sizeof (a[0])); + gid_address_copy (&a->leid, &leid); + gid_address_copy (&a->reid, &reid); + a->is_add = is_add; + + if (vnet_lisp_add_del_adjacency (a)) + clib_warning ("failed to %s adjacency!", is_add ? "add" : "delete"); + +done: + unformat_free (line_input); + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (lisp_add_del_adjacency_command) = { + .path = "lisp adjacency", + .short_help = "lisp adjacency add|del vni reid " + "leid ", + .function = lisp_add_del_adjacency_command_fn, +}; +/* *INDENT-ON* */ + + +static clib_error_t * +lisp_map_request_mode_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + unformat_input_t _i, *i = &_i; + map_request_mode_t mr_mode = _MR_MODE_MAX; + clib_error_t *error = NULL; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, i)) + return 0; + + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + { + if (unformat (i, "dst-only")) + mr_mode = MR_MODE_DST_ONLY; + else if (unformat (i, "src-dst")) + mr_mode = MR_MODE_SRC_DST; + else + { + clib_warning ("parse error '%U'", format_unformat_error, i); + goto done; + } + } + + if (_MR_MODE_MAX == mr_mode) + { + clib_warning ("No LISP map request mode entered!"); + goto done; + } + + vnet_lisp_set_map_request_mode (mr_mode); + +done: + unformat_free (i); + + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (lisp_map_request_mode_command) = { + .path = "lisp map-request mode", + .short_help = "lisp map-request mode dst-only|src-dst", + .function = lisp_map_request_mode_command_fn, +}; +/* *INDENT-ON* */ + + +static u8 * +format_lisp_map_request_mode (u8 * s, va_list * args) +{ + u32 mode = va_arg (*args, u32); + + switch (mode) + { + case 0: + return format (0, "dst-only"); + case 1: + return format (0, "src-dst"); + } + return 0; +} + +static clib_error_t * +lisp_show_map_request_mode_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + vlib_cli_output (vm, "map-request mode: %U", format_lisp_map_request_mode, + vnet_lisp_get_map_request_mode ()); + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (lisp_show_map_request_mode_command) = { + .path = "show lisp map-request mode", + .short_help = "show lisp map-request mode", + .function = lisp_show_map_request_mode_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_show_map_resolvers_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + lisp_msmr_t *mr; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + + vec_foreach (mr, lcm->map_resolvers) + { + vlib_cli_output (vm, "%U", format_ip_address, &mr->address); + } + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (lisp_show_map_resolvers_command) = { + .path = "show lisp map-resolvers", + .short_help = "show lisp map-resolvers", + .function = lisp_show_map_resolvers_command_fn, +}; +/* *INDENT-ON* */ + + +static clib_error_t * +lisp_pitr_set_locator_set_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + u8 locator_name_set = 0; + u8 *locator_set_name = 0; + u8 is_add = 1; + unformat_input_t _line_input, *line_input = &_line_input; + clib_error_t *error = 0; + int rv = 0; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "ls %_%v%_", &locator_set_name)) + locator_name_set = 1; + else if (unformat (line_input, "disable")) + is_add = 0; + else + { + error = clib_error_return (0, "parse error"); + goto done; + } + } + + if (!locator_name_set) + { + clib_warning ("No locator set specified!"); + goto done; + } + vec_terminate_c_string (locator_set_name); + rv = vnet_lisp_pitr_set_locator_set (locator_set_name, is_add); + if (0 != rv) + { + error = clib_error_return (0, "failed to %s pitr!", + is_add ? "add" : "delete"); + } + +done: + if (locator_set_name) + vec_free (locator_set_name); + unformat_free (line_input); + + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (lisp_pitr_set_locator_set_command) = { + .path = "lisp pitr", + .short_help = "lisp pitr [disable] ls ", + .function = lisp_pitr_set_locator_set_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_show_pitr_command_fn (vlib_main_t * vm, + unformat_input_t * input, vlib_cli_command_t * cmd) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + mapping_t *m; + locator_set_t *ls; + u8 *tmp_str = 0; + u8 status = lcm->flags & LISP_FLAG_PITR_MODE; + + vlib_cli_output (vm, "%=20s%=16s", "pitr", status ? "locator-set" : ""); + + if (!status) + { + vlib_cli_output (vm, "%=20s", "disable"); + return 0; + } + + if (~0 == lcm->pitr_map_index) + { + tmp_str = format (0, "N/A"); + } + else + { + m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index); + if (~0 != m->locator_set_index) + { + ls = + pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index); + tmp_str = format (0, "%s", ls->name); + } + else + { + tmp_str = format (0, "N/A"); + } + } + vec_add1 (tmp_str, 0); + + vlib_cli_output (vm, "%=20s%=16s", "enable", tmp_str); + + vec_free (tmp_str); + + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (lisp_show_pitr_command) = { + .path = "show lisp pitr", + .short_help = "Show pitr", + .function = lisp_show_pitr_command_fn, +}; +/* *INDENT-ON* */ + +static u8 * +format_eid_entry (u8 * s, va_list * args) +{ + vnet_main_t *vnm = va_arg (*args, vnet_main_t *); + lisp_cp_main_t *lcm = va_arg (*args, lisp_cp_main_t *); + mapping_t *mapit = va_arg (*args, mapping_t *); + locator_set_t *ls = va_arg (*args, locator_set_t *); + gid_address_t *gid = &mapit->eid; + u32 ttl = mapit->ttl; + u8 aut = mapit->authoritative; + u32 *loc_index; + u8 first_line = 1; + u8 *loc; + + u8 *type = ls->local ? format (0, "local(%s)", ls->name) + : format (0, "remote"); + + if (vec_len (ls->locator_indices) == 0) + { + s = format (s, "%-35U%-30s%-20u%-u", format_gid_address, gid, + type, ttl, aut); + } + else + { + vec_foreach (loc_index, ls->locator_indices) + { + locator_t *l = pool_elt_at_index (lcm->locator_pool, loc_index[0]); + if (l->local) + loc = format (0, "%U", format_vnet_sw_if_index_name, vnm, + l->sw_if_index); + else + loc = format (0, "%U", format_ip_address, + &gid_address_ip (&l->address)); + + if (first_line) + { + s = format (s, "%-35U%-20s%-30v%-20u%-u\n", format_gid_address, + gid, type, loc, ttl, aut); + first_line = 0; + } + else + s = format (s, "%55s%v\n", "", loc); + } + } + return s; +} + +static clib_error_t * +lisp_show_eid_table_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + mapping_t *mapit; + unformat_input_t _line_input, *line_input = &_line_input; + u32 mi; + gid_address_t eid; + u8 print_all = 1; + u8 filter = 0; + clib_error_t *error = NULL; + + clib_memset (&eid, 0, sizeof (eid)); + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "eid %U", unformat_gid_address, &eid)) + print_all = 0; + else if (unformat (line_input, "local")) + filter = 1; + else if (unformat (line_input, "remote")) + filter = 2; + else + { + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + goto done; + } + } + + vlib_cli_output (vm, "%-35s%-20s%-30s%-20s%-s", + "EID", "type", "locators", "ttl", "authoritative"); + + if (print_all) + { + /* *INDENT-OFF* */ + pool_foreach (mapit, lcm->mapping_pool, + ({ + if (mapit->pitr_set) + continue; + + locator_set_t * ls = pool_elt_at_index (lcm->locator_set_pool, + mapit->locator_set_index); + if (filter && !((1 == filter && ls->local) || + (2 == filter && !ls->local))) + { + continue; + } + vlib_cli_output (vm, "%U", format_eid_entry, lcm->vnet_main, + lcm, mapit, ls); + })); + /* *INDENT-ON* */ + } + else + { + mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &eid); + if ((u32) ~ 0 == mi) + goto done; + + mapit = pool_elt_at_index (lcm->mapping_pool, mi); + locator_set_t *ls = pool_elt_at_index (lcm->locator_set_pool, + mapit->locator_set_index); + + if (filter && !((1 == filter && ls->local) || + (2 == filter && !ls->local))) + { + goto done; + } + + vlib_cli_output (vm, "%U,", format_eid_entry, lcm->vnet_main, + lcm, mapit, ls); + } + +done: + unformat_free (line_input); + + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (lisp_cp_show_eid_table_command) = { + .path = "show lisp eid-table", + .short_help = "show lisp eid-table [local|remote|eid ]", + .function = lisp_show_eid_table_command_fn, +}; +/* *INDENT-ON* */ + + +static clib_error_t * +lisp_enable_command_fn (vlib_main_t * vm, unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + return clib_error_return (0, "parse error: '%U'", format_unformat_error, + input); + + vnet_lisp_enable_disable (1); + + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (lisp_cp_enable_command) = { + .path = "lisp enable", + .short_help = "lisp enable", + .function = lisp_enable_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_disable_command_fn (vlib_main_t * vm, unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + return clib_error_return (0, "parse error: '%U'", format_unformat_error, + input); + + vnet_lisp_enable_disable (0); + + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (lisp_cp_disable_command) = { + .path = "lisp disable", + .short_help = "lisp disable", + .function = lisp_disable_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_map_register_enable_disable_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + unformat_input_t _line_input, *line_input = &_line_input; + u8 is_enabled = 0; + u8 is_set = 0; + clib_error_t *error = NULL; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return clib_error_return (0, "expected enable | disable"); + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "enable")) + { + is_set = 1; + is_enabled = 1; + } + else if (unformat (line_input, "disable")) + is_set = 1; + else + { + vlib_cli_output (vm, "parse error: '%U'", format_unformat_error, + line_input); + goto done; + } + } + + if (!is_set) + { + vlib_cli_output (vm, "state not set!"); + goto done; + } + + vnet_lisp_map_register_enable_disable (is_enabled); + +done: + unformat_free (line_input); + + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (lisp_map_register_enable_disable_command) = { + .path = "lisp map-register", + .short_help = "lisp map-register [enable|disable]", + .function = lisp_map_register_enable_disable_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_rloc_probe_enable_disable_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + unformat_input_t _line_input, *line_input = &_line_input; + u8 is_enabled = 0; + u8 is_set = 0; + clib_error_t *error = NULL; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return clib_error_return (0, "expected enable | disable"); + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "enable")) + { + is_set = 1; + is_enabled = 1; + } + else if (unformat (line_input, "disable")) + is_set = 1; + else + { + vlib_cli_output (vm, "parse error: '%U'", format_unformat_error, + line_input); + goto done; + } + } + + if (!is_set) + { + vlib_cli_output (vm, "state not set!"); + goto done; + } + + vnet_lisp_rloc_probe_enable_disable (is_enabled); + +done: + unformat_free (line_input); + + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (lisp_rloc_probe_enable_disable_command) = { + .path = "lisp rloc-probe", + .short_help = "lisp rloc-probe [enable|disable]", + .function = lisp_rloc_probe_enable_disable_command_fn, +}; +/* *INDENT-ON* */ + +static u8 * +format_lisp_status (u8 * s, va_list * args) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + return format (s, "%s", lcm->is_enabled ? "enabled" : "disabled"); +} + +static clib_error_t * +lisp_show_status_command_fn (vlib_main_t * vm, unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + u8 *msg = 0; + msg = format (msg, "feature: %U\ngpe: %U\n", + format_lisp_status, format_vnet_lisp_gpe_status); + vlib_cli_output (vm, "%v", msg); + vec_free (msg); + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (lisp_show_status_command) = { + .path = "show lisp status", + .short_help = "show lisp status", + .function = lisp_show_status_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_show_eid_table_map_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + hash_pair_t *p; + unformat_input_t _line_input, *line_input = &_line_input; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + uword *vni_table = 0; + u8 is_l2 = 0; + clib_error_t *error = NULL; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "l2")) + { + vni_table = lcm->bd_id_by_vni; + is_l2 = 1; + } + else if (unformat (line_input, "l3")) + { + vni_table = lcm->table_id_by_vni; + is_l2 = 0; + } + else + { + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + goto done; + } + } + + if (!vni_table) + { + vlib_cli_output (vm, "Error: expected l2|l3 param!\n"); + goto done; + } + + vlib_cli_output (vm, "%=10s%=10s", "VNI", is_l2 ? "BD" : "VRF"); + + /* *INDENT-OFF* */ + hash_foreach_pair (p, vni_table, + ({ + vlib_cli_output (vm, "%=10d%=10d", p->key, p->value[0]); + })); + /* *INDENT-ON* */ + +done: + unformat_free (line_input); + + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (lisp_show_eid_table_map_command) = { + .path = "show lisp eid-table map", + .short_help = "show lisp eid-table map l2|l3", + .function = lisp_show_eid_table_map_command_fn, +}; +/* *INDENT-ON* */ + + +static clib_error_t * +lisp_add_del_locator_set_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + lisp_gpe_main_t *lgm = &lisp_gpe_main; + vnet_main_t *vnm = lgm->vnet_main; + unformat_input_t _line_input, *line_input = &_line_input; + u8 is_add = 1; + clib_error_t *error = 0; + u8 *locator_set_name = 0; + locator_t locator, *locators = 0; + vnet_lisp_add_del_locator_set_args_t _a, *a = &_a; + u32 ls_index = 0; + int rv = 0; + + clib_memset (&locator, 0, sizeof (locator)); + clib_memset (a, 0, sizeof (a[0])); + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return clib_error_return (0, "missing parameters"); + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "add %_%v%_", &locator_set_name)) + is_add = 1; + else if (unformat (line_input, "del %_%v%_", &locator_set_name)) + is_add = 0; + else if (unformat (line_input, "iface %U p %d w %d", + unformat_vnet_sw_interface, vnm, + &locator.sw_if_index, &locator.priority, + &locator.weight)) + { + locator.local = 1; + locator.state = 1; + vec_add1 (locators, locator); + } + else + { + error = unformat_parse_error (line_input); + goto done; + } + } + + vec_terminate_c_string (locator_set_name); + a->name = locator_set_name; + a->locators = locators; + a->is_add = is_add; + a->local = 1; + + rv = vnet_lisp_add_del_locator_set (a, &ls_index); + if (0 != rv) + { + error = clib_error_return (0, "failed to %s locator-set!", + is_add ? "add" : "delete"); + } + +done: + vec_free (locators); + if (locator_set_name) + vec_free (locator_set_name); + unformat_free (line_input); + + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (lisp_cp_add_del_locator_set_command) = { + .path = "lisp locator-set", + .short_help = "lisp locator-set add/del [iface " + "p w ]", + .function = lisp_add_del_locator_set_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_add_del_locator_in_set_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + lisp_gpe_main_t *lgm = &lisp_gpe_main; + vnet_main_t *vnm = lgm->vnet_main; + unformat_input_t _line_input, *line_input = &_line_input; + u8 is_add = 1; + clib_error_t *error = 0; + u8 *locator_set_name = 0; + u8 locator_set_name_set = 0; + locator_t locator, *locators = 0; + vnet_lisp_add_del_locator_set_args_t _a, *a = &_a; + u32 ls_index = 0; + + clib_memset (&locator, 0, sizeof (locator)); + clib_memset (a, 0, sizeof (a[0])); + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "add")) + is_add = 1; + else if (unformat (line_input, "del")) + is_add = 0; + else if (unformat (line_input, "locator-set %_%v%_", &locator_set_name)) + locator_set_name_set = 1; + else if (unformat (line_input, "iface %U p %d w %d", + unformat_vnet_sw_interface, vnm, + &locator.sw_if_index, &locator.priority, + &locator.weight)) + { + locator.local = 1; + vec_add1 (locators, locator); + } + else + { + error = unformat_parse_error (line_input); + goto done; + } + } + + if (!locator_set_name_set) + { + error = clib_error_return (0, "locator_set name not set!"); + goto done; + } + + a->name = locator_set_name; + a->locators = locators; + a->is_add = is_add; + a->local = 1; + + vnet_lisp_add_del_locator (a, 0, &ls_index); + +done: + vec_free (locators); + vec_free (locator_set_name); + unformat_free (line_input); + + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (lisp_cp_add_del_locator_in_set_command) = { + .path = "lisp locator", + .short_help = "lisp locator add/del locator-set iface " + "p w ", + .function = lisp_add_del_locator_in_set_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_cp_show_locator_sets_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + locator_set_t *lsit; + locator_t *loc; + u32 *locit; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + + vlib_cli_output (vm, "%s%=16s%=16s%=16s", "Locator-set", "Locator", + "Priority", "Weight"); + + /* *INDENT-OFF* */ + pool_foreach (lsit, lcm->locator_set_pool, + ({ + u8 * msg = 0; + int next_line = 0; + if (lsit->local) + { + msg = format (msg, "%v", lsit->name); + } + else + { + msg = format (msg, "<%s-%d>", "remote", lsit - lcm->locator_set_pool); + } + vec_foreach (locit, lsit->locator_indices) + { + if (next_line) + { + msg = format (msg, "%16s", " "); + } + loc = pool_elt_at_index (lcm->locator_pool, locit[0]); + if (loc->local) + msg = format (msg, "%16d%16d%16d\n", loc->sw_if_index, loc->priority, + loc->weight); + else + msg = format (msg, "%16U%16d%16d\n", format_ip_address, + &gid_address_ip(&loc->address), loc->priority, + loc->weight); + next_line = 1; + } + vlib_cli_output (vm, "%v", msg); + vec_free (msg); + })); + /* *INDENT-ON* */ + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (lisp_cp_show_locator_sets_command) = { + .path = "show lisp locator-set", + .short_help = "Shows locator-sets", + .function = lisp_cp_show_locator_sets_command_fn, +}; +/* *INDENT-ON* */ + + +static clib_error_t * +lisp_add_del_map_resolver_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + unformat_input_t _line_input, *line_input = &_line_input; + u8 is_add = 1, addr_set = 0; + ip_address_t ip_addr; + clib_error_t *error = 0; + int rv = 0; + vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "add")) + is_add = 1; + else if (unformat (line_input, "del")) + is_add = 0; + else if (unformat (line_input, "%U", unformat_ip_address, &ip_addr)) + addr_set = 1; + else + { + error = unformat_parse_error (line_input); + goto done; + } + } + + if (!addr_set) + { + error = clib_error_return (0, "Map-resolver address must be set!"); + goto done; + } + + a->is_add = is_add; + a->address = ip_addr; + rv = vnet_lisp_add_del_map_resolver (a); + if (0 != rv) + { + error = clib_error_return (0, "failed to %s map-resolver!", + is_add ? "add" : "delete"); + } + +done: + unformat_free (line_input); + + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (lisp_add_del_map_resolver_command) = { + .path = "lisp map-resolver", + .short_help = "lisp map-resolver add/del ", + .function = lisp_add_del_map_resolver_command_fn, +}; +/* *INDENT-ON* */ + + +static clib_error_t * +lisp_add_del_mreq_itr_rlocs_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + unformat_input_t _line_input, *line_input = &_line_input; + u8 is_add = 1; + u8 *locator_set_name = 0; + clib_error_t *error = 0; + int rv = 0; + vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "del")) + is_add = 0; + else if (unformat (line_input, "add %_%v%_", &locator_set_name)) + is_add = 1; + else + { + error = unformat_parse_error (line_input); + goto done; + } + } + + vec_terminate_c_string (locator_set_name); + a->is_add = is_add; + a->locator_set_name = locator_set_name; + rv = vnet_lisp_add_del_mreq_itr_rlocs (a); + if (0 != rv) + { + error = clib_error_return (0, "failed to %s map-request itr-rlocs!", + is_add ? "add" : "delete"); + } + +done: + vec_free (locator_set_name); + unformat_free (line_input); + + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (lisp_add_del_map_request_command) = { + .path = "lisp map-request itr-rlocs", + .short_help = "lisp map-request itr-rlocs add/del ", + .function = lisp_add_del_mreq_itr_rlocs_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_show_mreq_itr_rlocs_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + locator_set_t *loc_set; + + vlib_cli_output (vm, "%=20s", "itr-rlocs"); + + if (~0 == lcm->mreq_itr_rlocs) + { + return 0; + } + + loc_set = pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs); + + vlib_cli_output (vm, "%=20s", loc_set->name); + + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (lisp_show_map_request_command) = { + .path = "show lisp map-request itr-rlocs", + .short_help = "Shows map-request itr-rlocs", + .function = lisp_show_mreq_itr_rlocs_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_use_petr_set_locator_set_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + u8 is_add = 1, ip_set = 0; + unformat_input_t _line_input, *line_input = &_line_input; + clib_error_t *error = 0; + ip_address_t ip; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "%U", unformat_ip_address, &ip)) + ip_set = 1; + else if (unformat (line_input, "disable")) + is_add = 0; + else + { + error = clib_error_return (0, "parse error"); + goto done; + } + } + + if (!ip_set) + { + clib_warning ("No petr IP specified!"); + goto done; + } + + if (vnet_lisp_use_petr (&ip, is_add)) + { + error = clib_error_return (0, "failed to %s petr!", + is_add ? "add" : "delete"); + } + +done: + unformat_free (line_input); + + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (lisp_use_petr_set_locator_set_command) = { + .path = "lisp use-petr", + .short_help = "lisp use-petr [disable] ", + .function = lisp_use_petr_set_locator_set_command_fn, +}; + +static clib_error_t * +lisp_show_petr_command_fn (vlib_main_t * vm, + unformat_input_t * input, vlib_cli_command_t * cmd) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + mapping_t *m; + locator_set_t *ls; + locator_t *loc; + u8 *tmp_str = 0; + u8 use_petr = lcm->flags & LISP_FLAG_USE_PETR; + vlib_cli_output (vm, "%=20s%=16s", "petr", use_petr ? "ip" : ""); + + if (!use_petr) + { + vlib_cli_output (vm, "%=20s", "disable"); + return 0; + } + + if (~0 == lcm->petr_map_index) + { + tmp_str = format (0, "N/A"); + } + else + { + m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index); + if (~0 != m->locator_set_index) + { + ls = pool_elt_at_index(lcm->locator_set_pool, m->locator_set_index); + loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]); + tmp_str = format (0, "%U", format_ip_address, &loc->address); + } + else + { + tmp_str = format (0, "N/A"); + } + } + vec_add1 (tmp_str, 0); + + vlib_cli_output (vm, "%=20s%=16s", "enable", tmp_str); + + vec_free (tmp_str); + + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (lisp_show_petr_command) = { + .path = "show lisp petr", + .short_help = "Show petr", + .function = lisp_show_petr_command_fn, +}; +/* *INDENT-ON* */ + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/lisp/lisp-cp/lisp_cp_dpo.c b/src/plugins/lisp/lisp-cp/lisp_cp_dpo.c new file mode 100644 index 00000000000..bbb0ee3b6dc --- /dev/null +++ b/src/plugins/lisp/lisp-cp/lisp_cp_dpo.c @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +/** + * The static array of LISP punt DPOs + */ +static dpo_id_t lisp_cp_dpos[DPO_PROTO_NUM]; + +const dpo_id_t * +lisp_cp_dpo_get (dpo_proto_t proto) +{ + /* + * there are only two instances of this DPO type. + * we can use the protocol as the index + */ + return (&lisp_cp_dpos[proto]); +} + +static u8 * +format_lisp_cp_dpo (u8 * s, va_list * args) +{ + index_t index = va_arg (*args, index_t); + CLIB_UNUSED (u32 indent) = va_arg (*args, u32); + + return (format (s, "lisp-cp-punt-%U", format_dpo_proto, index)); +} + +static void +lisp_cp_dpo_lock (dpo_id_t * dpo) +{ +} + +static void +lisp_cp_dpo_unlock (dpo_id_t * dpo) +{ +} + +const static dpo_vft_t lisp_cp_vft = { + .dv_lock = lisp_cp_dpo_lock, + .dv_unlock = lisp_cp_dpo_unlock, + .dv_format = format_lisp_cp_dpo, +}; + +/** + * @brief The per-protocol VLIB graph nodes that are assigned to a LISP-CP + * object. + * + * this means that these graph nodes are ones from which a LISP-CP is the + * parent object in the DPO-graph. + */ +const static char *const lisp_cp_ip4_nodes[] = { + "lisp-cp-lookup-ip4", + NULL, +}; + +const static char *const lisp_cp_ip6_nodes[] = { + "lisp-cp-lookup-ip6", + NULL, +}; + +const static char *const lisp_cp_ethernet_nodes[] = { + "lisp-cp-lookup-l2", + NULL, +}; + +const static char *const lisp_cp_nsh_nodes[] = { + "lisp-cp-lookup-nsh", + NULL, +}; + +const static char *const *const lisp_cp_nodes[DPO_PROTO_NUM] = { + [DPO_PROTO_IP4] = lisp_cp_ip4_nodes, + [DPO_PROTO_IP6] = lisp_cp_ip6_nodes, + [DPO_PROTO_ETHERNET] = lisp_cp_ethernet_nodes, + [DPO_PROTO_MPLS] = NULL, + [DPO_PROTO_NSH] = lisp_cp_nsh_nodes, +}; + +clib_error_t * +lisp_cp_dpo_module_init (vlib_main_t * vm) +{ + dpo_proto_t dproto; + + /* + * there are no exit arcs from the LIS-CP VLIB node, so we + * pass NULL as said node array. + */ + dpo_register (DPO_LISP_CP, &lisp_cp_vft, lisp_cp_nodes); + + FOR_EACH_DPO_PROTO (dproto) + { + dpo_set (&lisp_cp_dpos[dproto], DPO_LISP_CP, dproto, dproto); + } + + return (NULL); +} + +VLIB_INIT_FUNCTION (lisp_cp_dpo_module_init); + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/lisp/lisp-cp/lisp_cp_dpo.h b/src/plugins/lisp/lisp-cp/lisp_cp_dpo.h new file mode 100644 index 00000000000..f0f3fae81a4 --- /dev/null +++ b/src/plugins/lisp/lisp-cp/lisp_cp_dpo.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __LISP_CP_DPO_H__ +#define __LISP_CP_DPO_H__ + +#include +#include + +/** + * A representation of punt to the LISP control plane. + */ +typedef struct lisp_cp_dpo_t +{ + /** + * The transport payload type. + */ + dpo_proto_t lcd_proto; +} lisp_cp_dpo_t; + +extern const dpo_id_t *lisp_cp_dpo_get (dpo_proto_t proto); + +extern void lisp_cp_dpo_module_init (void); + +#endif + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/lisp/lisp-cp/lisp_cp_messages.h b/src/plugins/lisp/lisp-cp/lisp_cp_messages.h new file mode 100644 index 00000000000..69510a0e1ce --- /dev/null +++ b/src/plugins/lisp/lisp-cp/lisp_cp_messages.h @@ -0,0 +1,644 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef VNET_LISP_GPE_LISP_CP_MESSAGES_H_ +#define VNET_LISP_GPE_LISP_CP_MESSAGES_H_ + +#include + +#define MAX_IP_PKT_LEN 4096 +#define MAX_IP_HDR_LEN 40 /* without options or IPv6 hdr extensions */ +#define UDP_HDR_LEN 8 +#define LISP_DATA_HDR_LEN 8 +#define LISP_ECM_HDR_LEN 4 +#define MAX_LISP_MSG_ENCAP_LEN 2*(MAX_IP_HDR_LEN + UDP_HDR_LEN)+ LISP_ECM_HDR_LEN +#define MAX_LISP_PKT_ENCAP_LEN MAX_IP_HDR_LEN + UDP_HDR_LEN + LISP_DATA_HDR_LEN + +#define LISP_CONTROL_PORT 4342 + +/* + * EID RECORD FIELD + */ + +/* + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * / | Reserved | EID mask-len | EID-prefix-AFI | + * Rec +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * \ | EID-prefix ... | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ + + +typedef struct _eid_prefix_record_hdr +{ + u8 reserved; + u8 eid_prefix_length; +} __attribute__ ((__packed__)) eid_record_hdr_t; + +void eid_rec_hdr_init (eid_record_hdr_t * ptr); + +#define EID_REC_CAST(h_) ((eid_record_hdr_t *)(h_)) +#define EID_REC_MLEN(h_) EID_REC_CAST((h_))->eid_prefix_length +#define EID_REC_ADDR(h) (u8 *)(h) + sizeof(eid_record_hdr_t) + +/* LISP Types */ +typedef enum +{ + NOT_LISP_MSG, + LISP_MAP_REQUEST = 1, + LISP_MAP_REPLY, + LISP_MAP_REGISTER, + LISP_MAP_NOTIFY, + LISP_INFO_NAT = 7, + LISP_ENCAP_CONTROL_TYPE = 8, + LISP_MSG_TYPES +} lisp_msg_type_e; + +/* + * ENCAPSULATED CONTROL MESSAGE + */ + +/* + * 0 1 2 3 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * / | IPv4 or IPv6 Header | + * OH | (uses RLOC addresses) | + * \ | | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * / | Source Port = xxxx | Dest Port = 4342 | + * UDP +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * \ | UDP Length | UDP Checksum | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * LH |Type=8 |S| Reserved | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * / | IPv4 or IPv6 Header | + * IH | (uses RLOC or EID addresses) | + * \ | | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * / | Source Port = xxxx | Dest Port = yyyy | + * UDP +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * \ | UDP Length | UDP Checksum | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * LCM | LISP Control Message | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ + + +/* + * Encapsulated control message header. This is followed by the IP + * header of the encapsulated LISP control message. + * + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * |Type=8 |S| Reserved | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ + +typedef struct +{ +#if CLIB_ARCH_IS_LITTLE_ENDIAN + u8 reserved:3; + u8 s_bit:1; + u8 type:4; +#else + u8 type:4; + u8 s_bit:1; + u8 reserved:3; +#endif + u8 reserved2[3]; +} ecm_hdr_t; + +char *ecm_hdr_to_char (ecm_hdr_t * h); + +#define ECM_TYPE(h_) ((ecm_hdr_t *)(h_))->type + +/* + * MAP-REQUEST MESSAGE + */ + +/* + * Map-Request Message Format + * + * 0 1 2 3 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * |Type=1 |A|M|P|S|p|s| Reserved | IRC | Record Count | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Nonce . . . | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | . . . Nonce | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Source-EID-AFI | Source EID Address ... | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | ITR-RLOC-AFI 1 | ITR-RLOC Address 1 ... | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | ... | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | ITR-RLOC-AFI n | ITR-RLOC Address n ... | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * / | Reserved | EID mask-len | EID-prefix-AFI | + * Rec +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * \ | EID-prefix ... | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Map-Reply Record ... | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Mapping Protocol Data | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ + + +/* + * Fixed size portion of the map request. Variable size source EID + * address, originating ITR RLOC AFIs and addresses and then map + * request records follow. + */ +typedef struct +{ +#if CLIB_ARCH_IS_LITTLE_ENDIAN + u8 solicit_map_request:1; + u8 rloc_probe:1; + u8 map_data_present:1; + u8 authoritative:1; + u8 type:4; +#else + u8 type:4; + u8 authoritative:1; + u8 map_data_present:1; + u8 rloc_probe:1; + u8 solicit_map_request:1; +#endif +#if CLIB_ARCH_IS_LITTLE_ENDIAN + u8 reserved1:6; + u8 smr_invoked:1; + u8 pitr:1; +#else + u8 pitr:1; + u8 smr_invoked:1; + u8 reserved1:6; +#endif +#if CLIB_ARCH_IS_LITTLE_ENDIAN + u8 additional_itr_rloc_count:5; + u8 reserved2:3; +#else + u8 reserved2:3; + u8 additional_itr_rloc_count:5; +#endif + u8 record_count; + u64 nonce; +} __attribute__ ((__packed__)) map_request_hdr_t; + +void map_request_hdr_init (void *ptr); +char *map_request_hdr_to_char (map_request_hdr_t * h); + +#define MREQ_TYPE(h_) (h_)->type +#define MREQ_HDR_CAST(h_) ((map_request_hdr_t *)(h_)) +#define MREQ_REC_COUNT(h_) (MREQ_HDR_CAST(h_))->record_count +#define MREQ_RLOC_PROBE(h_) (MREQ_HDR_CAST(h_))->rloc_probe +#define MREQ_ITR_RLOC_COUNT(h_) (MREQ_HDR_CAST(h_))->additional_itr_rloc_count +#define MREQ_NONCE(h_) (MREQ_HDR_CAST(h_))->nonce +#define MREQ_SMR(h_) (MREQ_HDR_CAST(h_))->solicit_map_request +#define MREQ_SMR_INVOKED(h_) (MREQ_HDR_CAST(h_))->smr_invoked + +/* + * MAP-REPLY MESSAGE + */ + + /* + * Map-Reply Message Format + * + * 0 1 2 3 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * |Type=2 |P|E|S| Reserved | Record Count | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Nonce . . . | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | . . . Nonce | + * +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | | Record TTL | + * | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * R | Locator Count | EID mask-len | ACT |A| Reserved | + * e +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * c | Rsvd | Map-Version Number | EID-AFI | + * o +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * r | EID-prefix | + * d +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | /| Priority | Weight | M Priority | M Weight | + * | L +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | o | Unused Flags |L|p|R| Loc-AFI | + * | c +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | \| Locator | + * +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Mapping Protocol Data | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ + + /* + * Fixed size portion of the map reply. + */ +typedef struct +{ +#if CLIB_ARCH_IS_LITTLE_ENDIAN + u8 reserved1:1; + u8 security:1; + u8 echo_nonce:1; + u8 rloc_probe:1; + u8 type:4; +#else + u8 type:4; + u8 rloc_probe:1; + u8 echo_nonce:1; + u8 security:1; + u8 reserved1:1; +#endif + u8 reserved2; + u8 reserved3; + u8 record_count; + u64 nonce; +} __attribute__ ((__packed__)) map_reply_hdr_t; + +void map_reply_hdr_init (void *ptr); +char *map_reply_hdr_to_char (map_reply_hdr_t * h); + +#define MREP_TYPE(h_) MREP_HDR_CAST(h_)->type +#define MREP_HDR_CAST(h_) ((map_reply_hdr_t *)(h_)) +#define MREP_REC_COUNT(h_) MREP_HDR_CAST(h_)->record_count +#define MREP_RLOC_PROBE(h_) MREP_HDR_CAST(h_)->rloc_probe +#define MREP_NONCE(h_) MREP_HDR_CAST(h_)->nonce + + +always_inline lisp_msg_type_e +lisp_msg_type (void *b) +{ + ecm_hdr_t *hdr = b; + if (!hdr) + { + return (NOT_LISP_MSG); + } + return (hdr->type); +} + +always_inline void +increment_record_count (void *b) +{ + switch (lisp_msg_type (b)) + { + case LISP_MAP_REQUEST: + MREQ_REC_COUNT (b) += 1; + break; + case LISP_MAP_REPLY: + MREP_REC_COUNT (b) += 1; + break; + default: + return; + } +} + + +/* + * LOCATOR FIELD + * + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * /| Priority | Weight | M Priority | M Weight | + * L +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * o | Unused Flags |L|p|R| Loc-AFI | + * c +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * \| Locator | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * + * Fixed portion of the mapping record locator. Variable length + * locator address follows. + */ +typedef struct _locator_hdr +{ + u8 priority; + u8 weight; + u8 mpriority; + u8 mweight; + u8 unused1; +#ifdef CLIB_ARCH_IS_LITTLE_ENDIAN + u8 reachable:1; + u8 probed:1; + u8 local:1; + u8 unused2:5; +#else + u8 unused2:5; + u8 local:1; + u8 probed:1; + u8 reachable:1; +#endif +} __attribute__ ((__packed__)) locator_hdr_t; + +#define LOC_CAST(h_) ((locator_hdr_t *)(h_)) +#define LOC_PROBED(h_) LOC_CAST(h_)->probed +#define LOC_PRIORITY(h_) LOC_CAST(h_)->priority +#define LOC_WEIGHT(h_) LOC_CAST(h_)->weight +#define LOC_MPRIORITY(h_) LOC_CAST(h_)->mpriority +#define LOC_MWEIGHT(h_) LOC_CAST(h_)->mweight +#define LOC_REACHABLE(h_) LOC_CAST(h_)->reachable +#define LOC_LOCAL(h_) LOC_CAST(h_)->local +#define LOC_ADDR(h_) ((u8 *)(h_) + sizeof(locator_hdr_t)) + +/* + * MAPPING RECORD + * + * Mapping record used in all LISP control messages. + * + * +---> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | | Record TTL | + * | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * R | Locator Count | EID mask-len | ACT |A| Reserved | + * e +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * c | Rsvd | Map-Version Number | EID-AFI | + * o +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * r | EID-prefix | + * d +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | /| Priority | Weight | M Priority | M Weight | + * | / +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Loc | Unused Flags |L|p|R| Loc-AFI | + * | \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | \| Locator | + * +---> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ + +/* + * Fixed portion of the mapping record. EID prefix address and + * locators follow. + */ + +typedef struct _mapping_record_hdr_t +{ + u32 ttl; + u8 locator_count; + u8 eid_prefix_length; +#ifdef CLIB_ARCH_IS_LITTLE_ENDIAN + u8 reserved1:4; + u8 authoritative:1; + u8 action:3; +#else + u8 action:3; + u8 authoritative:1; + u8 reserved1:4; +#endif + u8 reserved2; +#ifdef CLIB_ARCH_IS_LITTLE_ENDIAN + u8 version_hi:4; + u8 reserved3:4; +#else + u8 reserved3:4; + u8 version_hi:4; +#endif + u8 version_low; +} __attribute__ ((__packed__)) mapping_record_hdr_t; + +void mapping_record_init_hdr (mapping_record_hdr_t * h); + +#define MAP_REC_EID_PLEN(h) ((mapping_record_hdr_t *)(h))->eid_prefix_length +#define MAP_REC_LOC_COUNT(h) ((mapping_record_hdr_t *)(h))->locator_count +#define MAP_REC_ACTION(h) ((mapping_record_hdr_t *)(h))->action +#define MAP_REC_AUTH(h) ((mapping_record_hdr_t *)(h))->authoritative +#define MAP_REC_TTL(h) ((mapping_record_hdr_t *)(h))->ttl +#define MAP_REC_EID(h) (u8 *)(h)+sizeof(mapping_record_hdr_t) +#define MAP_REC_VERSION(h) (h)->version_hi << 8 | (h)->version_low + +typedef enum +{ + LISP_NO_ACTION, + LISP_FORWARD_NATIVE, + LISP_SEND_MAP_REQUEST, + LISP_DROP +} lisp_action_e; + +typedef enum lisp_authoritative +{ + A_NO_AUTHORITATIVE = 0, + A_AUTHORITATIVE +} lisp_authoritative_e; + +/* + * LISP Canonical Address Format Encodings + * + * 0 1 2 3 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | AFI = 16387 | Rsvd1 | Flags | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Type | Rsvd2 | Length | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ + +typedef struct _lcaf_hdr_t +{ + u8 reserved1; + u8 flags; + u8 type; + u8 reserved2; + u16 len; +} __attribute__ ((__packed__)) lcaf_hdr_t; + +#define LCAF_TYPE(h) ((lcaf_hdr_t *)(h))->type +#define LCAF_LENGTH(h) ((lcaf_hdr_t *)(h))->len +#define LCAF_RES2(h) ((lcaf_hdr_t *)(h))->reserved2 +#define LCAF_FLAGS(h) ((lcaf_hdr_t *)(h))->flags +#define LCAF_PAYLOAD(h) (u8 *)(h)+sizeof(lcaf_hdr_t) + +/* + * Source/Dest Key Canonical Address Format: + * + * 0 1 2 3 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Reserved | Source-ML | Dest-ML | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ +typedef struct _lcaf_src_dst_hdr_t +{ + u16 reserved; + u8 src_mask_len; + u8 dst_mask_len; +} __attribute__ ((__packed__)) lcaf_src_dst_hdr_t; + +#define LCAF_SD_SRC_ML(_h) (_h)->src_mask_len +#define LCAF_SD_DST_ML(_h) (_h)->dst_mask_len + +/* + * SPI LCAF + * + * 0 1 2 3 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Service Path ID | Service index | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ +typedef struct _lcaf_spi_hdr_t +{ + u32 spi_si; +} __attribute__ ((__packed__)) lcaf_spi_hdr_t; + +#define LCAF_SPI_SI(_h) (_h)->spi_si + +/* + * The Map-Register message format is: + * + * 0 1 2 3 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * |Type=3 |P| Reserved |M| Record Count | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Nonce . . . | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | . . . Nonce | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Key ID | Authentication Data Length | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * ~ Authentication Data ~ + * +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | | Record TTL | + * | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * R | Locator Count | EID mask-len | ACT |A| Reserved | + * e +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * c | Rsvd | Map-Version Number | EID-Prefix-AFI | + * o +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * r | EID-Prefix | + * d +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | /| Priority | Weight | M Priority | M Weight | + * | L +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | o | Unused Flags |L|p|R| Loc-AFI | + * | c +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | \| Locator | + * +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ +typedef struct +{ +#if CLIB_ARCH_IS_LITTLE_ENDIAN + u8 res1:3; + u8 proxy_map_reply:1; + u8 type:4; +#else + u8 type:4; + u8 proxy_map_reply:1; + u8 res1:3; +#endif + + u8 res2; + +#if CLIB_ARCH_IS_LITTLE_ENDIAN + u8 want_map_notify:1; + u8 res3:7; +#else + u8 res3:7; + u8 want_map_notify:1; +#endif + + u8 record_count; + u64 nonce; + u16 key_id; + u16 auth_data_len; + u8 data[0]; +} __attribute__ ((__packed__)) map_register_hdr_t; + +#define MREG_TYPE(h_) (h_)->type +#define MREG_HDR_CAST(h_) ((map_register_hdr_t *)(h_)) +#define MREG_PROXY_MR(h_) (MREG_HDR_CAST(h_))->proxy_map_reply +#define MREG_WANT_MAP_NOTIFY(h_) (MREG_HDR_CAST(h_))->want_map_notify +#define MREG_REC_COUNT(h_) (MREG_HDR_CAST(h_))->record_count +#define MREG_NONCE(h_) (MREG_HDR_CAST(h_))->nonce +#define MREG_KEY_ID(h_) (MREG_HDR_CAST(h_))->key_id +#define MREG_AUTH_DATA_LEN(h_) (MREG_HDR_CAST(h_))->auth_data_len +#define MREG_DATA(h_) (MREG_HDR_CAST(h_))->data + +/* + * The Map-Notify message format is: + * + * 0 1 2 3 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * |Type=4 | Reserved | Record Count | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Nonce . . . | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | . . . Nonce | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Key ID | Authentication Data Length | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * ~ Authentication Data ~ + * +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | | Record TTL | + * | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * R | Locator Count | EID mask-len | ACT |A| Reserved | + * e +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * c | Rsvd | Map-Version Number | EID-Prefix-AFI | + * o +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * r | EID-Prefix | + * d +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | /| Priority | Weight | M Priority | M Weight | + * | L +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | o | Unused Flags |L|p|R| Loc-AFI | + * | c +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | \| Locator | + * +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +*/ + +typedef struct +{ +#if CLIB_ARCH_IS_LITTLE_ENDIAN + u8 res1:4; + u8 type:4; +#else + u8 type:4; + u8 res1:4; +#endif + + u16 res2; + + u8 record_count; + u64 nonce; + u16 key_id; + u16 auth_data_len; + u8 data[0]; +} __attribute__ ((__packed__)) map_notify_hdr_t; + +#define MNOTIFY_TYPE(h_) (h_)->type +#define MNOTIFY_HDR_CAST(h_) ((map_register_hdr_t *)(h_)) +#define MNOTIFY_REC_COUNT(h_) (MREG_HDR_CAST(h_))->record_count +#define MNOTIFY_NONCE(h_) (MREG_HDR_CAST(h_))->nonce +#define MNOTIFY_KEY_ID(h_) (MREG_HDR_CAST(h_))->key_id +#define MNOTIFY_AUTH_DATA_LEN(h_) (MREG_HDR_CAST(h_))->auth_data_len +#define MNOTIFY_DATA(h_) (MREG_HDR_CAST(h_))->data + +/* + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * |Ver|O|C|R|R|R|R|R|R| Length | MD type=0x1 | Next Protocol | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Service Path Identifer | Service Index | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ + +typedef struct +{ + u32 header; + u32 spi_si; +} __attribute__ ((__packed__)) lisp_nsh_hdr_t; + +#endif /* VNET_LISP_GPE_LISP_CP_MESSAGES_H_ */ + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/lisp/lisp-cp/lisp_cp_test.c b/src/plugins/lisp/lisp-cp/lisp_cp_test.c new file mode 100644 index 00000000000..faffb738c04 --- /dev/null +++ b/src/plugins/lisp/lisp-cp/lisp_cp_test.c @@ -0,0 +1,2052 @@ +/* + * Copyright (c) 2015 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include +#include +#include + +/* define message IDs */ +#include +#include +#include + +typedef struct +{ + /* API message ID base */ + u16 msg_id_base; + vat_main_t *vat_main; + u32 ping_id; +} lisp_test_main_t; + +lisp_test_main_t lisp_test_main; + +#define __plugin_msg_base lisp_test_main.msg_id_base +#include + +/* Macro to finish up custom dump fns */ +#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) +#define FINISH \ + vec_add1 (s, 0); \ + vl_print (handle, (char *)s); \ + vec_free (s); \ + return handle; + +typedef struct +{ + u32 spi; + u8 si; +} __attribute__ ((__packed__)) lisp_nsh_api_t; + +#define LISP_PING(_lm, mp_ping) \ + if (!(_lm)->ping_id) \ + (_lm)->ping_id = vl_msg_api_get_msg_index ((u8 *) (VL_API_CONTROL_PING_CRC)); \ + mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping)); \ + mp_ping->_vl_msg_id = htons ((_lm)->ping_id); \ + mp_ping->client_index = vam->my_client_index; \ + fformat (vam->ofp, "Sending ping id=%d\n", (_lm)->ping_id); \ + vam->result_ready = 0; \ + +uword +unformat_nsh_address (unformat_input_t * input, va_list * args) +{ + lisp_nsh_api_t *nsh = va_arg (*args, lisp_nsh_api_t *); + return unformat (input, "SPI:%d SI:%d", &nsh->spi, &nsh->si); +} + +static u8 * +format_nsh_address_vat (u8 * s, va_list * args) +{ + nsh_t *a = va_arg (*args, nsh_t *); + return format (s, "SPI:%d SI:%d", clib_net_to_host_u32 (a->spi), a->si); +} + +static u8 * +format_lisp_flat_eid (u8 * s, va_list * args) +{ + vl_api_eid_t *eid = va_arg (*args, vl_api_eid_t *); + + switch (eid->type) + { + case EID_TYPE_API_PREFIX: + if (eid->address.prefix.address.af) + return format (s, "%U/%d", format_ip6_address, + eid->address.prefix.address.un.ip6, + eid->address.prefix.len); + return format (s, "%U/%d", format_ip4_address, + eid->address.prefix.address.un.ip4, + eid->address.prefix.len); + case EID_TYPE_API_MAC: + return format (s, "%U", format_ethernet_address, eid->address.mac); + case EID_TYPE_API_NSH: + return format (s, "%U", format_nsh_address_vat, eid->address.nsh); + } + return 0; +} + +static u8 * +format_lisp_eid_vat (u8 * s, va_list * args) +{ + vl_api_eid_t *deid = va_arg (*args, vl_api_eid_t *); + vl_api_eid_t *seid = va_arg (*args, vl_api_eid_t *); + u8 is_src_dst = (u8) va_arg (*args, int); + + if (is_src_dst) + s = format (s, "%U|", format_lisp_flat_eid, seid); + + s = format (s, "%U", format_lisp_flat_eid, deid); + + return s; +} + + + +/* *INDENT-OFF* */ +/** Used for parsing LISP eids */ +typedef struct lisp_eid_vat_t_ +{ + union { + ip46_address_t ip; + mac_address_t mac; + lisp_nsh_api_t nsh; + } addr; + /**< prefix length if IP */ + u32 len; + /**< type of eid */ + u8 type; +} __clib_packed lisp_eid_vat_t; +/* *INDENT-ON* */ + +static uword +unformat_lisp_eid_vat (unformat_input_t * input, va_list * args) +{ + lisp_eid_vat_t *a = va_arg (*args, lisp_eid_vat_t *); + + clib_memset (a, 0, sizeof (a[0])); + + if (unformat (input, "%U/%d", unformat_ip46_address, a->addr.ip, &a->len)) + { + a->type = 0; /* ip prefix type */ + } + else if (unformat (input, "%U", unformat_ethernet_address, &a->addr.mac)) + { + a->type = 1; /* mac type */ + } + else if (unformat (input, "%U", unformat_nsh_address, a->addr.nsh)) + { + a->type = 2; /* NSH type */ + a->addr.nsh.spi = clib_host_to_net_u32 (a->addr.nsh.spi); + } + else + { + return 0; + } + + if (a->type == 0) + { + if (ip46_address_is_ip4 (&a->addr.ip)) + return a->len > 32 ? 1 : 0; + else + return a->len > 128 ? 1 : 0; + } + + return 1; +} + +static void +lisp_eid_put_vat (vl_api_eid_t * eid, const lisp_eid_vat_t * vat_eid) +{ + eid->type = vat_eid->type; + switch (eid->type) + { + case EID_TYPE_API_PREFIX: + if (ip46_address_is_ip4 (&vat_eid->addr.ip)) + { + clib_memcpy (&eid->address.prefix.address.un.ip4, + &vat_eid->addr.ip.ip4, 4); + eid->address.prefix.address.af = ADDRESS_IP4; + eid->address.prefix.len = vat_eid->len; + } + else + { + clib_memcpy (&eid->address.prefix.address.un.ip6, + &vat_eid->addr.ip.ip6, 16); + eid->address.prefix.address.af = ADDRESS_IP6; + eid->address.prefix.len = vat_eid->len; + } + return; + case EID_TYPE_API_MAC: + clib_memcpy (&eid->address.mac, &vat_eid->addr.mac, + sizeof (eid->address.mac)); + return; + case EID_TYPE_API_NSH: + clib_memcpy (&eid->address.nsh, &vat_eid->addr.nsh, + sizeof (eid->address.nsh)); + return; + default: + ASSERT (0); + return; + } +} + +static int +api_lisp_add_del_locator_set (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + vl_api_lisp_add_del_locator_set_t *mp; + u8 is_add = 1; + u8 *locator_set_name = NULL; + u8 locator_set_name_set = 0; + vl_api_local_locator_t locator, *locators = 0; + u32 sw_if_index, priority, weight; + u32 data_len = 0; + + int ret; + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "del")) + { + is_add = 0; + } + else if (unformat (input, "locator-set %s", &locator_set_name)) + { + locator_set_name_set = 1; + } + else if (unformat (input, "sw_if_index %u p %u w %u", + &sw_if_index, &priority, &weight)) + { + locator.sw_if_index = htonl (sw_if_index); + locator.priority = priority; + locator.weight = weight; + vec_add1 (locators, locator); + } + else + if (unformat + (input, "iface %U p %u w %u", unformat_sw_if_index, vam, + &sw_if_index, &priority, &weight)) + { + locator.sw_if_index = htonl (sw_if_index); + locator.priority = priority; + locator.weight = weight; + vec_add1 (locators, locator); + } + else + break; + } + + if (locator_set_name_set == 0) + { + errmsg ("missing locator-set name"); + vec_free (locators); + return -99; + } + + if (vec_len (locator_set_name) > 64) + { + errmsg ("locator-set name too long"); + vec_free (locator_set_name); + vec_free (locators); + return -99; + } + vec_add1 (locator_set_name, 0); + + data_len = sizeof (vl_api_local_locator_t) * vec_len (locators); + + /* Construct the API message */ + M2 (LISP_ADD_DEL_LOCATOR_SET, mp, data_len); + + mp->is_add = is_add; + clib_memcpy (mp->locator_set_name, locator_set_name, + vec_len (locator_set_name)); + vec_free (locator_set_name); + + mp->locator_num = clib_host_to_net_u32 (vec_len (locators)); + if (locators) + clib_memcpy (mp->locators, locators, data_len); + vec_free (locators); + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_lisp_add_del_locator (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + vl_api_lisp_add_del_locator_t *mp; + u32 tmp_if_index = ~0; + u32 sw_if_index = ~0; + u8 sw_if_index_set = 0; + u8 sw_if_index_if_name_set = 0; + u32 priority = ~0; + u8 priority_set = 0; + u32 weight = ~0; + u8 weight_set = 0; + u8 is_add = 1; + u8 *locator_set_name = NULL; + u8 locator_set_name_set = 0; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "del")) + { + is_add = 0; + } + else if (unformat (input, "locator-set %s", &locator_set_name)) + { + locator_set_name_set = 1; + } + else if (unformat (input, "iface %U", unformat_sw_if_index, vam, + &tmp_if_index)) + { + sw_if_index_if_name_set = 1; + sw_if_index = tmp_if_index; + } + else if (unformat (input, "sw_if_index %d", &tmp_if_index)) + { + sw_if_index_set = 1; + sw_if_index = tmp_if_index; + } + else if (unformat (input, "p %d", &priority)) + { + priority_set = 1; + } + else if (unformat (input, "w %d", &weight)) + { + weight_set = 1; + } + else + break; + } + + if (locator_set_name_set == 0) + { + errmsg ("missing locator-set name"); + return -99; + } + + if (sw_if_index_set == 0 && sw_if_index_if_name_set == 0) + { + errmsg ("missing sw_if_index"); + vec_free (locator_set_name); + return -99; + } + + if (sw_if_index_set != 0 && sw_if_index_if_name_set != 0) + { + errmsg ("cannot use both params interface name and sw_if_index"); + vec_free (locator_set_name); + return -99; + } + + if (priority_set == 0) + { + errmsg ("missing locator-set priority"); + vec_free (locator_set_name); + return -99; + } + + if (weight_set == 0) + { + errmsg ("missing locator-set weight"); + vec_free (locator_set_name); + return -99; + } + + if (vec_len (locator_set_name) > 64) + { + errmsg ("locator-set name too long"); + vec_free (locator_set_name); + return -99; + } + vec_add1 (locator_set_name, 0); + + /* Construct the API message */ + M (LISP_ADD_DEL_LOCATOR, mp); + + mp->is_add = is_add; + mp->sw_if_index = ntohl (sw_if_index); + mp->priority = priority; + mp->weight = weight; + clib_memcpy (mp->locator_set_name, locator_set_name, + vec_len (locator_set_name)); + vec_free (locator_set_name); + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_lisp_add_del_local_eid (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + vl_api_lisp_add_del_local_eid_t *mp; + u8 is_add = 1; + u8 eid_set = 0; + lisp_eid_vat_t _eid, *eid = &_eid; + u8 *locator_set_name = 0; + u8 locator_set_name_set = 0; + u32 vni = 0; + u16 key_id = 0; + u8 *key = 0; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "del")) + { + is_add = 0; + } + else if (unformat (input, "vni %d", &vni)) + { + ; + } + else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid)) + { + eid_set = 1; + } + else if (unformat (input, "locator-set %s", &locator_set_name)) + { + locator_set_name_set = 1; + } + else if (unformat (input, "key-id %U", unformat_hmac_key_id, &key_id)) + ; + else if (unformat (input, "secret-key %_%v%_", &key)) + ; + else + break; + } + + if (locator_set_name_set == 0) + { + errmsg ("missing locator-set name"); + return -99; + } + + if (0 == eid_set) + { + errmsg ("EID address not set!"); + vec_free (locator_set_name); + return -99; + } + + if (key && (0 == key_id)) + { + errmsg ("invalid key_id!"); + return -99; + } + + if (vec_len (key) > 64) + { + errmsg ("key too long"); + vec_free (key); + return -99; + } + + if (vec_len (locator_set_name) > 64) + { + errmsg ("locator-set name too long"); + vec_free (locator_set_name); + return -99; + } + vec_add1 (locator_set_name, 0); + + /* Construct the API message */ + M (LISP_ADD_DEL_LOCAL_EID, mp); + + mp->is_add = is_add; + lisp_eid_put_vat (&mp->eid, eid); + mp->vni = clib_host_to_net_u32 (vni); + mp->key.id = key_id; + clib_memcpy (mp->locator_set_name, locator_set_name, + vec_len (locator_set_name)); + clib_memcpy (mp->key.key, key, vec_len (key)); + + vec_free (locator_set_name); + vec_free (key); + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_lisp_add_del_map_server (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + vl_api_lisp_add_del_map_server_t *mp; + u8 is_add = 1; + u8 ipv4_set = 0; + u8 ipv6_set = 0; + ip4_address_t ipv4; + ip6_address_t ipv6; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "del")) + { + is_add = 0; + } + else if (unformat (input, "%U", unformat_ip4_address, &ipv4)) + { + ipv4_set = 1; + } + else if (unformat (input, "%U", unformat_ip6_address, &ipv6)) + { + ipv6_set = 1; + } + else + break; + } + + if (ipv4_set && ipv6_set) + { + errmsg ("both eid v4 and v6 addresses set"); + return -99; + } + + if (!ipv4_set && !ipv6_set) + { + errmsg ("eid addresses not set"); + return -99; + } + + /* Construct the API message */ + M (LISP_ADD_DEL_MAP_SERVER, mp); + + mp->is_add = is_add; + if (ipv6_set) + { + mp->ip_address.af = 1; + clib_memcpy (mp->ip_address.un.ip6, &ipv6, sizeof (ipv6)); + } + else + { + mp->ip_address.af = 0; + clib_memcpy (mp->ip_address.un.ip4, &ipv4, sizeof (ipv4)); + } + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_lisp_add_del_map_resolver (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + vl_api_lisp_add_del_map_resolver_t *mp; + u8 is_add = 1; + u8 ipv4_set = 0; + u8 ipv6_set = 0; + ip4_address_t ipv4; + ip6_address_t ipv6; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "del")) + { + is_add = 0; + } + else if (unformat (input, "%U", unformat_ip4_address, &ipv4)) + { + ipv4_set = 1; + } + else if (unformat (input, "%U", unformat_ip6_address, &ipv6)) + { + ipv6_set = 1; + } + else + break; + } + + if (ipv4_set && ipv6_set) + { + errmsg ("both eid v4 and v6 addresses set"); + return -99; + } + + if (!ipv4_set && !ipv6_set) + { + errmsg ("eid addresses not set"); + return -99; + } + + /* Construct the API message */ + M (LISP_ADD_DEL_MAP_RESOLVER, mp); + + mp->is_add = is_add; + if (ipv6_set) + { + mp->ip_address.af = 1; + clib_memcpy (mp->ip_address.un.ip6, &ipv6, sizeof (ipv6)); + } + else + { + mp->ip_address.af = 0; + clib_memcpy (mp->ip_address.un.ip6, &ipv4, sizeof (ipv4)); + } + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_lisp_enable_disable (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + vl_api_lisp_enable_disable_t *mp; + u8 is_set = 0; + u8 is_enable = 0; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "enable")) + { + is_set = 1; + is_enable = 1; + } + else if (unformat (input, "disable")) + { + is_set = 1; + } + else + break; + } + + if (!is_set) + { + errmsg ("Value not set"); + return -99; + } + + /* Construct the API message */ + M (LISP_ENABLE_DISABLE, mp); + + mp->is_enable = is_enable; + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +/** + * Enable/disable LISP proxy ITR. + * + * @param vam vpp API test context + * @return return code + */ +static int +api_lisp_pitr_set_locator_set (vat_main_t * vam) +{ + u8 ls_name_set = 0; + unformat_input_t *input = vam->input; + vl_api_lisp_pitr_set_locator_set_t *mp; + u8 is_add = 1; + u8 *ls_name = 0; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "del")) + is_add = 0; + else if (unformat (input, "locator-set %s", &ls_name)) + ls_name_set = 1; + else + { + errmsg ("parse error '%U'", format_unformat_error, input); + return -99; + } + } + + if (!ls_name_set) + { + errmsg ("locator-set name not set!"); + return -99; + } + + M (LISP_PITR_SET_LOCATOR_SET, mp); + + mp->is_add = is_add; + clib_memcpy (mp->ls_name, ls_name, vec_len (ls_name)); + vec_free (ls_name); + + /* send */ + S (mp); + + /* wait for reply */ + W (ret); + return ret; +} + +static int +api_lisp_use_petr (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + vl_api_lisp_use_petr_t *mp; + u8 is_add = 0; + ip_address_t ip; + int ret; + + clib_memset (&ip, 0, sizeof (ip)); + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "disable")) + is_add = 0; + else + if (unformat (input, "%U", unformat_ip4_address, &ip_addr_v4 (&ip))) + { + is_add = 1; + ip_addr_version (&ip) = AF_IP4; + } + else + if (unformat (input, "%U", unformat_ip6_address, &ip_addr_v6 (&ip))) + { + is_add = 1; + ip_addr_version (&ip) = AF_IP6; + } + else + { + errmsg ("parse error '%U'", format_unformat_error, input); + return -99; + } + } + + M (LISP_USE_PETR, mp); + + mp->is_add = is_add; + if (is_add) + { + mp->ip_address.af = ip_addr_version (&ip) == AF_IP4 ? 0 : 1; + if (mp->ip_address.af) + clib_memcpy (mp->ip_address.un.ip6, &ip, 16); + else + clib_memcpy (mp->ip_address.un.ip4, &ip, 4); + } + + /* send */ + S (mp); + + /* wait for reply */ + W (ret); + return ret; +} + +static void + vl_api_show_lisp_use_petr_reply_t_handler + (vl_api_show_lisp_use_petr_reply_t * mp) +{ + vat_main_t *vam = &vat_main; + i32 retval = ntohl (mp->retval); + + if (0 <= retval) + { + print (vam->ofp, "%s\n", mp->is_petr_enable ? "enabled" : "disabled"); + if (mp->is_petr_enable) + { + print (vam->ofp, "Proxy-ETR address; %U", + mp->ip_address.af ? format_ip6_address : format_ip4_address, + mp->ip_address.un); + } + } + + vam->retval = retval; + vam->result_ready = 1; +} + +static int +api_show_lisp_use_petr (vat_main_t * vam) +{ + vl_api_show_lisp_use_petr_t *mp; + int ret; + + if (!vam->json_output) + { + print (vam->ofp, "%=20s", "Proxy-ETR status:"); + } + + M (SHOW_LISP_USE_PETR, mp); + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static void + vl_api_show_lisp_rloc_probe_state_reply_t_handler + (vl_api_show_lisp_rloc_probe_state_reply_t * mp) +{ + vat_main_t *vam = &vat_main; + int retval = clib_net_to_host_u32 (mp->retval); + + if (retval) + goto end; + + print (vam->ofp, "%s", mp->is_enabled ? "enabled" : "disabled"); +end: + vam->retval = retval; + vam->result_ready = 1; +} + +static int +api_show_lisp_map_register_state (vat_main_t * vam) +{ + vl_api_show_lisp_map_register_state_t *mp; + int ret; + + M (SHOW_LISP_MAP_REGISTER_STATE, mp); + + /* send */ + S (mp); + + /* wait for reply */ + W (ret); + return ret; +} + +static int +api_show_lisp_rloc_probe_state (vat_main_t * vam) +{ + vl_api_show_lisp_rloc_probe_state_t *mp; + int ret; + + M (SHOW_LISP_RLOC_PROBE_STATE, mp); + + /* send */ + S (mp); + + /* wait for reply */ + W (ret); + return ret; +} + +static int +api_lisp_rloc_probe_enable_disable (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + vl_api_lisp_rloc_probe_enable_disable_t *mp; + u8 is_set = 0; + u8 is_enable = 0; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "enable")) + { + is_set = 1; + is_enable = 1; + } + else if (unformat (input, "disable")) + is_set = 1; + else + break; + } + + if (!is_set) + { + errmsg ("Value not set"); + return -99; + } + + /* Construct the API message */ + M (LISP_RLOC_PROBE_ENABLE_DISABLE, mp); + + mp->is_enable = is_enable; + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_lisp_map_register_enable_disable (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + vl_api_lisp_map_register_enable_disable_t *mp; + u8 is_set = 0; + u8 is_enable = 0; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "enable")) + { + is_set = 1; + is_enable = 1; + } + else if (unformat (input, "disable")) + is_set = 1; + else + break; + } + + if (!is_set) + { + errmsg ("Value not set"); + return -99; + } + + /* Construct the API message */ + M (LISP_MAP_REGISTER_ENABLE_DISABLE, mp); + + mp->is_enable = is_enable; + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static void + vl_api_show_lisp_map_request_mode_reply_t_handler + (vl_api_show_lisp_map_request_mode_reply_t * mp) +{ + vat_main_t *vam = &vat_main; + i32 retval = ntohl (mp->retval); + + if (0 <= retval) + { + print (vam->ofp, "map_request_mode: %s", + mp->is_src_dst ? "src-dst" : "dst-only"); + } + + vam->retval = retval; + vam->result_ready = 1; +} + +static void + vl_api_show_lisp_map_register_state_reply_t_handler + (vl_api_show_lisp_map_register_state_reply_t * mp) +{ + vat_main_t *vam = &vat_main; + int retval = clib_net_to_host_u32 (mp->retval); + + print (vam->ofp, "%s", mp->is_enabled ? "enabled" : "disabled"); + + vam->retval = retval; + vam->result_ready = 1; +} + +static void +vl_api_lisp_locator_details_t_handler (vl_api_lisp_locator_details_t * mp) +{ + vat_main_t *vam = &vat_main; + u8 *s = 0; + + if (mp->local) + { + s = format (s, "%=16d%=16d%=16d", + ntohl (mp->sw_if_index), mp->priority, mp->weight); + } + else + { + s = format (s, "%=16U%=16d%=16d", + format_ip46_address, + mp->ip_address, mp->priority, mp->weight); + } + + print (vam->ofp, "%v", s); + vec_free (s); +} + +static void +vl_api_lisp_locator_set_details_t_handler (vl_api_lisp_locator_set_details_t * + mp) +{ + vat_main_t *vam = &vat_main; + u8 *ls_name = 0; + + ls_name = format (0, "%s", mp->ls_name); + + print (vam->ofp, "%=10d%=15v", clib_net_to_host_u32 (mp->ls_index), + ls_name); + vec_free (ls_name); +} + +static void vl_api_lisp_add_del_locator_set_reply_t_handler + (vl_api_lisp_add_del_locator_set_reply_t * mp) +{ + vat_main_t *vam = &vat_main; + i32 retval = ntohl (mp->retval); + if (vam->async_mode) + { + vam->async_errors += (retval < 0); + } + else + { + vam->retval = retval; + vam->result_ready = 1; + } +} + + +static void +vl_api_lisp_eid_table_details_t_handler (vl_api_lisp_eid_table_details_t * mp) +{ + vat_main_t *vam = &vat_main; + u8 *s = 0, *eid = 0; + + if (~0 == mp->locator_set_index) + s = format (0, "action: %d", mp->action); + else + s = format (0, "%d", clib_net_to_host_u32 (mp->locator_set_index)); + + eid = format (0, "%U", format_lisp_eid_vat, + &mp->deid, &mp->seid, mp->is_src_dst); + vec_add1 (eid, 0); + + print (vam->ofp, "[%d] %-35s%-20s%-30s%-20d%-20d%-10d%-20s", + clib_net_to_host_u32 (mp->vni), + eid, + mp->is_local ? "local" : "remote", + s, clib_net_to_host_u32 (mp->ttl), mp->authoritative, + clib_net_to_host_u16 (mp->key.id), mp->key.key); + + vec_free (s); + vec_free (eid); +} + +static void + vl_api_lisp_eid_table_map_details_t_handler + (vl_api_lisp_eid_table_map_details_t * mp) +{ + vat_main_t *vam = &vat_main; + + u8 *line = format (0, "%=10d%=10d", + clib_net_to_host_u32 (mp->vni), + clib_net_to_host_u32 (mp->dp_table)); + print (vam->ofp, "%v", line); + vec_free (line); +} + +static void + vl_api_lisp_eid_table_vni_details_t_handler + (vl_api_lisp_eid_table_vni_details_t * mp) +{ + vat_main_t *vam = &vat_main; + + u8 *line = format (0, "%d", clib_net_to_host_u32 (mp->vni)); + print (vam->ofp, "%v", line); + vec_free (line); +} + +static void + vl_api_lisp_adjacencies_get_reply_t_handler + (vl_api_lisp_adjacencies_get_reply_t * mp) +{ + vat_main_t *vam = &vat_main; + u32 i, n; + int retval = clib_net_to_host_u32 (mp->retval); + vl_api_lisp_adjacency_t *a; + + if (retval) + goto end; + + n = clib_net_to_host_u32 (mp->count); + + for (i = 0; i < n; i++) + { + a = &mp->adjacencies[i]; + print (vam->ofp, "%U %40U", + format_lisp_flat_eid, a->leid, format_lisp_flat_eid, a->reid); + } + +end: + vam->retval = retval; + vam->result_ready = 1; +} + +static void +vl_api_lisp_map_server_details_t_handler (vl_api_lisp_map_server_details_t * + mp) +{ + vat_main_t *vam = &vat_main; + + print (vam->ofp, "%=20U", + mp->ip_address.af ? format_ip6_address : format_ip4_address, + mp->ip_address.un); +} + +static void +vl_api_lisp_map_resolver_details_t_handler (vl_api_lisp_map_resolver_details_t + * mp) +{ + vat_main_t *vam = &vat_main; + + print (vam->ofp, "%=20U", + mp->ip_address.af ? format_ip6_address : format_ip4_address, + mp->ip_address.un); +} + +static void +vl_api_show_lisp_status_reply_t_handler (vl_api_show_lisp_status_reply_t * mp) +{ + vat_main_t *vam = &vat_main; + i32 retval = ntohl (mp->retval); + + if (0 <= retval) + { + print (vam->ofp, "feature: %s\ngpe: %s", + mp->is_lisp_enabled ? "enabled" : "disabled", + mp->is_gpe_enabled ? "enabled" : "disabled"); + } + + vam->retval = retval; + vam->result_ready = 1; +} + +static void + vl_api_lisp_get_map_request_itr_rlocs_reply_t_handler + (vl_api_lisp_get_map_request_itr_rlocs_reply_t * mp) +{ + vat_main_t *vam = &vat_main; + i32 retval = ntohl (mp->retval); + + if (retval >= 0) + { + print (vam->ofp, "%=20s", mp->locator_set_name); + } + + vam->retval = retval; + vam->result_ready = 1; +} + +static void +vl_api_show_lisp_pitr_reply_t_handler (vl_api_show_lisp_pitr_reply_t * mp) +{ + vat_main_t *vam = &vat_main; + i32 retval = ntohl (mp->retval); + + if (0 <= retval) + { + print (vam->ofp, "%-20s%-16s", + mp->is_enabled ? "enabled" : "disabled", + mp->is_enabled ? (char *) mp->locator_set_name : ""); + } + + vam->retval = retval; + vam->result_ready = 1; +} + +uword +unformat_hmac_key_id (unformat_input_t * input, va_list * args) +{ + u32 *key_id = va_arg (*args, u32 *); + u8 *s = 0; + + if (unformat (input, "%s", &s)) + { + if (!strcmp ((char *) s, "sha1")) + key_id[0] = HMAC_SHA_1_96; + else if (!strcmp ((char *) s, "sha256")) + key_id[0] = HMAC_SHA_256_128; + else + { + clib_warning ("invalid key_id: '%s'", s); + key_id[0] = HMAC_NO_KEY; + } + } + else + return 0; + + vec_free (s); + return 1; +} + + + +static int +api_show_lisp_map_request_mode (vat_main_t * vam) +{ + vl_api_show_lisp_map_request_mode_t *mp; + int ret; + + M (SHOW_LISP_MAP_REQUEST_MODE, mp); + + /* send */ + S (mp); + + /* wait for reply */ + W (ret); + return ret; +} + +static int +api_lisp_map_request_mode (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + vl_api_lisp_map_request_mode_t *mp; + u8 mode = 0; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "dst-only")) + mode = 0; + else if (unformat (input, "src-dst")) + mode = 1; + else + { + errmsg ("parse error '%U'", format_unformat_error, input); + return -99; + } + } + + M (LISP_MAP_REQUEST_MODE, mp); + + mp->is_src_dst = mode == 1; + + /* send */ + S (mp); + + /* wait for reply */ + W (ret); + return ret; +} + +static int +api_show_lisp_pitr (vat_main_t * vam) +{ + vl_api_show_lisp_pitr_t *mp; + int ret; + + if (!vam->json_output) + { + print (vam->ofp, "%=20s", "lisp status:"); + } + + M (SHOW_LISP_PITR, mp); + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +/** + * Add/delete mapping between vni and vrf + */ +static int +api_lisp_eid_table_add_del_map (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + vl_api_lisp_eid_table_add_del_map_t *mp; + u8 is_add = 1, vni_set = 0, vrf_set = 0, bd_index_set = 0; + u32 vni, vrf, bd_index; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "del")) + is_add = 0; + else if (unformat (input, "vrf %d", &vrf)) + vrf_set = 1; + else if (unformat (input, "bd_index %d", &bd_index)) + bd_index_set = 1; + else if (unformat (input, "vni %d", &vni)) + vni_set = 1; + else + break; + } + + if (!vni_set || (!vrf_set && !bd_index_set)) + { + errmsg ("missing arguments!"); + return -99; + } + + if (vrf_set && bd_index_set) + { + errmsg ("error: both vrf and bd entered!"); + return -99; + } + + M (LISP_EID_TABLE_ADD_DEL_MAP, mp); + + mp->is_add = is_add; + mp->vni = htonl (vni); + mp->dp_table = vrf_set ? htonl (vrf) : htonl (bd_index); + mp->is_l2 = bd_index_set; + + /* send */ + S (mp); + + /* wait for reply */ + W (ret); + return ret; +} + +/** + * Add/del remote mapping to/from LISP control plane + * + * @param vam vpp API test context + * @return return code + */ +static int +api_lisp_add_del_remote_mapping (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + vl_api_lisp_add_del_remote_mapping_t *mp; + u32 vni = 0; + lisp_eid_vat_t _eid, *eid = &_eid; + lisp_eid_vat_t _seid, *seid = &_seid; + u8 is_add = 1, del_all = 0, eid_set = 0, seid_set = 0; + u32 action = ~0, p, w, data_len; + ip4_address_t rloc4; + ip6_address_t rloc6; + vl_api_remote_locator_t *rlocs = 0, rloc, *curr_rloc = 0; + int ret; + + clib_memset (&rloc, 0, sizeof (rloc)); + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "del-all")) + { + del_all = 1; + } + else if (unformat (input, "del")) + { + is_add = 0; + } + else if (unformat (input, "add")) + { + is_add = 1; + } + else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid)) + { + eid_set = 1; + } + else if (unformat (input, "seid %U", unformat_lisp_eid_vat, seid)) + { + seid_set = 1; + } + else if (unformat (input, "vni %d", &vni)) + { + ; + } + else if (unformat (input, "p %d w %d", &p, &w)) + { + if (!curr_rloc) + { + errmsg ("No RLOC configured for setting priority/weight!"); + return -99; + } + curr_rloc->priority = p; + curr_rloc->weight = w; + } + else if (unformat (input, "rloc %U", unformat_ip4_address, &rloc4)) + { + rloc.ip_address.af = 0; + clib_memcpy (&rloc.ip_address.un.ip6, &rloc6, sizeof (rloc6)); + vec_add1 (rlocs, rloc); + curr_rloc = &rlocs[vec_len (rlocs) - 1]; + } + else if (unformat (input, "rloc %U", unformat_ip6_address, &rloc6)) + { + rloc.ip_address.af = 1; + clib_memcpy (&rloc.ip_address.un.ip4, &rloc4, sizeof (rloc4)); + vec_add1 (rlocs, rloc); + curr_rloc = &rlocs[vec_len (rlocs) - 1]; + } + else if (unformat (input, "action %U", + unformat_negative_mapping_action, &action)) + { + ; + } + else + { + clib_warning ("parse error '%U'", format_unformat_error, input); + return -99; + } + } + + if (0 == eid_set) + { + errmsg ("missing params!"); + return -99; + } + + if (is_add && (~0 == action) && 0 == vec_len (rlocs)) + { + errmsg ("no action set for negative map-reply!"); + return -99; + } + + data_len = vec_len (rlocs) * sizeof (vl_api_remote_locator_t); + + M2 (LISP_ADD_DEL_REMOTE_MAPPING, mp, data_len); + mp->is_add = is_add; + mp->vni = htonl (vni); + mp->action = (u8) action; + mp->is_src_dst = seid_set; + mp->del_all = del_all; + lisp_eid_put_vat (&mp->deid, eid); + lisp_eid_put_vat (&mp->seid, seid); + + mp->rloc_num = clib_host_to_net_u32 (vec_len (rlocs)); + clib_memcpy (mp->rlocs, rlocs, data_len); + vec_free (rlocs); + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +/** + * Add/del LISP adjacency. Saves mapping in LISP control plane and updates + * forwarding entries in data-plane accordingly. + * + * @param vam vpp API test context + * @return return code + */ +static int +api_lisp_add_del_adjacency (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + vl_api_lisp_add_del_adjacency_t *mp; + u32 vni = 0; + u8 is_add = 1; + int ret; + lisp_eid_vat_t leid, reid; + + leid.type = reid.type = (u8) ~ 0; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "del")) + { + is_add = 0; + } + else if (unformat (input, "add")) + { + is_add = 1; + } + else if (unformat (input, "reid %U/%d", unformat_ip46_address, + &reid.addr.ip, &reid.len)) + { + reid.type = 0; /* ipv4 */ + } + else if (unformat (input, "reid %U", unformat_ethernet_address, + &reid.addr.mac)) + { + reid.type = 1; /* mac */ + } + else if (unformat (input, "leid %U/%d", unformat_ip46_address, + &leid.addr.ip, &leid.len)) + { + leid.type = 0; /* ipv4 */ + } + else if (unformat (input, "leid %U", unformat_ethernet_address, + &leid.addr.mac)) + { + leid.type = 1; /* mac */ + } + else if (unformat (input, "vni %d", &vni)) + { + ; + } + else + { + errmsg ("parse error '%U'", format_unformat_error, input); + return -99; + } + } + + if ((u8) ~ 0 == reid.type) + { + errmsg ("missing params!"); + return -99; + } + + if (leid.type != reid.type) + { + errmsg ("remote and local EIDs are of different types!"); + return -99; + } + + M (LISP_ADD_DEL_ADJACENCY, mp); + mp->is_add = is_add; + mp->vni = htonl (vni); + lisp_eid_put_vat (&mp->leid, &leid); + lisp_eid_put_vat (&mp->reid, &reid); + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +/** + * Add/del map request itr rlocs from LISP control plane and updates + * + * @param vam vpp API test context + * @return return code + */ +static int +api_lisp_add_del_map_request_itr_rlocs (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + vl_api_lisp_add_del_map_request_itr_rlocs_t *mp; + u8 *locator_set_name = 0; + u8 locator_set_name_set = 0; + u8 is_add = 1; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "del")) + { + is_add = 0; + } + else if (unformat (input, "%_%v%_", &locator_set_name)) + { + locator_set_name_set = 1; + } + else + { + clib_warning ("parse error '%U'", format_unformat_error, input); + return -99; + } + } + + if (is_add && !locator_set_name_set) + { + errmsg ("itr-rloc is not set!"); + return -99; + } + + if (is_add && vec_len (locator_set_name) > 64) + { + errmsg ("itr-rloc locator-set name too long"); + vec_free (locator_set_name); + return -99; + } + + M (LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, mp); + mp->is_add = is_add; + if (is_add) + { + clib_memcpy (mp->locator_set_name, locator_set_name, + vec_len (locator_set_name)); + } + else + { + clib_memset (mp->locator_set_name, 0, sizeof (mp->locator_set_name)); + } + vec_free (locator_set_name); + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_lisp_locator_dump (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + vl_api_lisp_locator_dump_t *mp; + vl_api_control_ping_t *mp_ping; + u8 is_index_set = 0, is_name_set = 0; + u8 *ls_name = 0; + u32 ls_index = ~0; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "ls_name %_%v%_", &ls_name)) + { + is_name_set = 1; + } + else if (unformat (input, "ls_index %d", &ls_index)) + { + is_index_set = 1; + } + else + { + errmsg ("parse error '%U'", format_unformat_error, input); + return -99; + } + } + + if (!is_index_set && !is_name_set) + { + errmsg ("error: expected lisp of index or name!"); + return -99; + } + + if (is_index_set && is_name_set) + { + errmsg ("error: only lisp param expected!"); + return -99; + } + + if (vec_len (ls_name) > 62) + { + errmsg ("error: locator set name too long!"); + return -99; + } + + if (!vam->json_output) + { + print (vam->ofp, "%=16s%=16s%=16s", "locator", "priority", "weight"); + } + + M (LISP_LOCATOR_DUMP, mp); + mp->is_index_set = is_index_set; + + if (is_index_set) + mp->ls_index = clib_host_to_net_u32 (ls_index); + else + { + vec_add1 (ls_name, 0); + strncpy ((char *) mp->ls_name, (char *) ls_name, + sizeof (mp->ls_name) - 1); + } + + /* send it... */ + S (mp); + + /* Use a control ping for synchronization */ + if (!lisp_test_main.ping_id) + lisp_test_main.ping_id = + vl_msg_api_get_msg_index ((u8 *) (VL_API_CONTROL_PING_CRC)); + mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping)); + mp_ping->_vl_msg_id = htons (lisp_test_main.ping_id); + mp_ping->client_index = vam->my_client_index; + + fformat (vam->ofp, "Sending ping id=%d\n", lisp_test_main.ping_id); + + vam->result_ready = 0; + S (mp_ping); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_lisp_locator_set_dump (vat_main_t * vam) +{ + vl_api_lisp_locator_set_dump_t *mp; + vl_api_control_ping_t *mp_ping; + unformat_input_t *input = vam->input; + u8 filter = 0; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "local")) + { + filter = 1; + } + else if (unformat (input, "remote")) + { + filter = 2; + } + else + { + errmsg ("parse error '%U'", format_unformat_error, input); + return -99; + } + } + + if (!vam->json_output) + { + print (vam->ofp, "%=10s%=15s", "ls_index", "ls_name"); + } + + M (LISP_LOCATOR_SET_DUMP, mp); + + mp->filter = filter; + + /* send it... */ + S (mp); + + /* Use a control ping for synchronization */ + LISP_PING (&lisp_test_main, mp_ping); + S (mp_ping); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_lisp_eid_table_map_dump (vat_main_t * vam) +{ + u8 is_l2 = 0; + u8 mode_set = 0; + unformat_input_t *input = vam->input; + vl_api_lisp_eid_table_map_dump_t *mp; + vl_api_control_ping_t *mp_ping; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "l2")) + { + is_l2 = 1; + mode_set = 1; + } + else if (unformat (input, "l3")) + { + is_l2 = 0; + mode_set = 1; + } + else + { + errmsg ("parse error '%U'", format_unformat_error, input); + return -99; + } + } + + if (!mode_set) + { + errmsg ("expected lisp of 'l2' or 'l3' parameter!"); + return -99; + } + + if (!vam->json_output) + { + print (vam->ofp, "%=10s%=10s", "VNI", is_l2 ? "BD" : "VRF"); + } + + M (LISP_EID_TABLE_MAP_DUMP, mp); + mp->is_l2 = is_l2; + + /* send it... */ + S (mp); + + /* Use a control ping for synchronization */ + LISP_PING (&lisp_test_main, mp_ping); + S (mp_ping); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_lisp_eid_table_vni_dump (vat_main_t * vam) +{ + vl_api_lisp_eid_table_vni_dump_t *mp; + vl_api_control_ping_t *mp_ping; + int ret; + + if (!vam->json_output) + { + print (vam->ofp, "VNI"); + } + + M (LISP_EID_TABLE_VNI_DUMP, mp); + + /* send it... */ + S (mp); + + /* Use a control ping for synchronization */ + LISP_PING (&lisp_test_main, mp_ping); + S (mp_ping); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_lisp_eid_table_dump (vat_main_t * vam) +{ + unformat_input_t *i = vam->input; + vl_api_lisp_eid_table_dump_t *mp; + vl_api_control_ping_t *mp_ping; + u8 filter = 0; + int ret; + u32 vni, t = 0; + lisp_eid_vat_t eid; + u8 eid_set = 0; + + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + { + if (unformat + (i, "eid %U/%d", unformat_ip46_address, &eid.addr.ip, &eid.len)) + { + eid_set = 1; + eid.type = 0; + } + else + if (unformat (i, "eid %U", unformat_ethernet_address, &eid.addr.mac)) + { + eid_set = 1; + eid.type = 1; + } + else if (unformat (i, "eid %U", unformat_nsh_address, &eid.addr.nsh)) + { + eid_set = 1; + eid.type = 2; + } + else if (unformat (i, "vni %d", &t)) + { + vni = t; + } + else if (unformat (i, "local")) + { + filter = 1; + } + else if (unformat (i, "remote")) + { + filter = 2; + } + else + { + errmsg ("parse error '%U'", format_unformat_error, i); + return -99; + } + } + + if (!vam->json_output) + { + print (vam->ofp, "%-35s%-20s%-30s%-20s%-20s%-10s%-20s", "EID", + "type", "ls_index", "ttl", "authoritative", "key_id", "key"); + } + + M (LISP_EID_TABLE_DUMP, mp); + + mp->filter = filter; + if (eid_set) + { + mp->eid_set = 1; + mp->vni = htonl (vni); + lisp_eid_put_vat (&mp->eid, &eid); + } + + /* send it... */ + S (mp); + + /* Use a control ping for synchronization */ + LISP_PING (&lisp_test_main, mp_ping); + S (mp_ping); + + /* Wait for a reply... */ + W (ret); + return ret; +} + + +static int +api_lisp_adjacencies_get (vat_main_t * vam) +{ + unformat_input_t *i = vam->input; + vl_api_lisp_adjacencies_get_t *mp; + u8 vni_set = 0; + u32 vni = ~0; + int ret; + + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + { + if (unformat (i, "vni %d", &vni)) + { + vni_set = 1; + } + else + { + errmsg ("parse error '%U'", format_unformat_error, i); + return -99; + } + } + + if (!vni_set) + { + errmsg ("vni not set!"); + return -99; + } + + if (!vam->json_output) + { + print (vam->ofp, "%s %40s", "leid", "reid"); + } + + M (LISP_ADJACENCIES_GET, mp); + mp->vni = clib_host_to_net_u32 (vni); + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_lisp_map_server_dump (vat_main_t * vam) +{ + vl_api_lisp_map_server_dump_t *mp; + vl_api_control_ping_t *mp_ping; + int ret; + + if (!vam->json_output) + { + print (vam->ofp, "%=20s", "Map server"); + } + + M (LISP_MAP_SERVER_DUMP, mp); + /* send it... */ + S (mp); + + /* Use a control ping for synchronization */ + LISP_PING (&lisp_test_main, mp_ping); + S (mp_ping); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_lisp_map_resolver_dump (vat_main_t * vam) +{ + vl_api_lisp_map_resolver_dump_t *mp; + vl_api_control_ping_t *mp_ping; + int ret; + + if (!vam->json_output) + { + print (vam->ofp, "%=20s", "Map resolver"); + } + + M (LISP_MAP_RESOLVER_DUMP, mp); + /* send it... */ + S (mp); + + /* Use a control ping for synchronization */ + LISP_PING (&lisp_test_main, mp_ping); + S (mp_ping); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_show_lisp_status (vat_main_t * vam) +{ + vl_api_show_lisp_status_t *mp; + int ret; + + if (!vam->json_output) + { + print (vam->ofp, "%-20s%-16s", "LISP status", "locator-set"); + } + + M (SHOW_LISP_STATUS, mp); + /* send it... */ + S (mp); + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_lisp_get_map_request_itr_rlocs (vat_main_t * vam) +{ + vl_api_lisp_get_map_request_itr_rlocs_t *mp; + int ret; + + if (!vam->json_output) + { + print (vam->ofp, "%=20s", "itr-rlocs:"); + } + + M (LISP_GET_MAP_REQUEST_ITR_RLOCS, mp); + /* send it... */ + S (mp); + /* Wait for a reply... */ + W (ret); + return ret; +} + +#define vat_plugin_register vat_plugin_register_cp +#include + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/lisp/lisp-cp/lisp_msg_serdes.c b/src/plugins/lisp/lisp-cp/lisp_msg_serdes.c new file mode 100644 index 00000000000..14d90982d4f --- /dev/null +++ b/src/plugins/lisp/lisp-cp/lisp_msg_serdes.c @@ -0,0 +1,381 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +void *lisp_msg_put_gid (vlib_buffer_t * b, gid_address_t * gid); + +static void +lisp_msg_put_locators (vlib_buffer_t * b, locator_t * locators) +{ + locator_t *loc; + + vec_foreach (loc, locators) + { + u8 *p = vlib_buffer_put_uninit (b, sizeof (locator_hdr_t)); + clib_memset (p, 0, sizeof (locator_hdr_t)); + LOC_PRIORITY (p) = loc->priority; + LOC_MPRIORITY (p) = loc->mpriority; + LOC_WEIGHT (p) = loc->weight; + LOC_MWEIGHT (p) = loc->mweight; + LOC_LOCAL (p) = loc->local; + LOC_PROBED (p) = loc->probed ? 1 : 0; + LOC_REACHABLE (p) = loc->state ? 1 : 0; + lisp_msg_put_gid (b, &loc->address); + } +} + +static void +lisp_msg_put_mapping_record (vlib_buffer_t * b, mapping_t * record) +{ + mapping_record_hdr_t *p = + vlib_buffer_put_uninit (b, sizeof (mapping_record_hdr_t)); + gid_address_t *eid = &record->eid; + + clib_memset (p, 0, sizeof (*p)); + MAP_REC_EID_PLEN (p) = gid_address_len (eid); + MAP_REC_TTL (p) = clib_host_to_net_u32 (MAP_REGISTER_DEFAULT_TTL); + MAP_REC_AUTH (p) = record->authoritative ? 1 : 0; + MAP_REC_LOC_COUNT (p) = vec_len (record->locators); + + lisp_msg_put_gid (b, eid); + lisp_msg_put_locators (b, record->locators); +} + +static void +lisp_msg_put_mreg_records (vlib_buffer_t * b, mapping_t * records) +{ + u32 i; + for (i = 0; i < vec_len (records); i++) + lisp_msg_put_mapping_record (b, &records[i]); +} + +void * +lisp_msg_put_gid (vlib_buffer_t * b, gid_address_t * gid) +{ + u8 *p = 0; + if (!gid) + { + /* insert only src-eid-afi field set to 0 */ + p = vlib_buffer_put_uninit (b, sizeof (u16)); + *(u16 *) p = 0; + } + else + { + p = vlib_buffer_put_uninit (b, gid_address_size_to_put (gid)); + gid_address_put (p, gid); + } + return p; +} + +static void * +lisp_msg_put_itr_rlocs (lisp_cp_main_t * lcm, vlib_buffer_t * b, + gid_address_t * rlocs, u8 * locs_put) +{ + u8 *bp, count = 0; + u32 i; + + bp = vlib_buffer_get_current (b); + for (i = 0; i < vec_len (rlocs); i++) + { + lisp_msg_put_gid (b, &rlocs[i]); + count++; + } + + *locs_put = count - 1; + return bp; +} + +void * +lisp_msg_put_eid_rec (vlib_buffer_t * b, gid_address_t * eid) +{ + eid_record_hdr_t *h = vlib_buffer_put_uninit (b, sizeof (*h)); + + clib_memset (h, 0, sizeof (*h)); + EID_REC_MLEN (h) = gid_address_len (eid); + lisp_msg_put_gid (b, eid); + return h; +} + +u64 +nonce_build (u32 seed) +{ + u64 nonce; + u32 nonce_lower; + u32 nonce_upper; + struct timespec ts; + + /* Put nanosecond clock in lower 32-bits and put an XOR of the nanosecond + * clock with the second clock in the upper 32-bits. */ + syscall (SYS_clock_gettime, CLOCK_REALTIME, &ts); + nonce_lower = ts.tv_nsec; + nonce_upper = ts.tv_sec ^ clib_host_to_net_u32 (nonce_lower); + + /* OR in a caller provided seed to the low-order 32-bits. */ + nonce_lower |= seed; + + /* Return 64-bit nonce. */ + nonce = nonce_upper; + nonce = (nonce << 32) | nonce_lower; + return nonce; +} + +void * +lisp_msg_put_map_reply (vlib_buffer_t * b, mapping_t * records, u64 nonce, + u8 probe_bit) +{ + map_reply_hdr_t *h = vlib_buffer_put_uninit (b, sizeof (h[0])); + + clib_memset (h, 0, sizeof (h[0])); + MREP_TYPE (h) = LISP_MAP_REPLY; + MREP_NONCE (h) = nonce; + MREP_REC_COUNT (h) = 1; + MREP_RLOC_PROBE (h) = probe_bit; + + lisp_msg_put_mreg_records (b, records); + return h; +} + +void * +lisp_msg_put_map_register (vlib_buffer_t * b, mapping_t * records, + u8 want_map_notify, u16 auth_data_len, u64 * nonce, + u32 * msg_len) +{ + u8 *auth_data = 0; + + /* Basic header init */ + map_register_hdr_t *h = vlib_buffer_put_uninit (b, sizeof (h[0])); + + clib_memset (h, 0, sizeof (h[0])); + MREG_TYPE (h) = LISP_MAP_REGISTER; + MREG_NONCE (h) = nonce_build (0); + MREG_WANT_MAP_NOTIFY (h) = want_map_notify ? 1 : 0; + MREG_REC_COUNT (h) = vec_len (records); + + auth_data = vlib_buffer_put_uninit (b, auth_data_len); + clib_memset (auth_data, 0, auth_data_len); + + /* Put map register records */ + lisp_msg_put_mreg_records (b, records); + + nonce[0] = MREG_NONCE (h); + msg_len[0] = vlib_buffer_get_tail (b) - (u8 *) h; + return h; +} + +void * +lisp_msg_put_mreq (lisp_cp_main_t * lcm, vlib_buffer_t * b, + gid_address_t * seid, gid_address_t * deid, + gid_address_t * rlocs, u8 is_smr_invoked, + u8 rloc_probe_set, u64 * nonce) +{ + u8 loc_count = 0; + + /* Basic header init */ + map_request_hdr_t *h = vlib_buffer_put_uninit (b, sizeof (h[0])); + + clib_memset (h, 0, sizeof (h[0])); + MREQ_TYPE (h) = LISP_MAP_REQUEST; + MREQ_NONCE (h) = nonce_build (0); + MREQ_SMR_INVOKED (h) = is_smr_invoked ? 1 : 0; + MREQ_RLOC_PROBE (h) = rloc_probe_set ? 1 : 0; + + /* We're adding one eid record */ + increment_record_count (h); + + /* Fill source eid */ + lisp_msg_put_gid (b, seid); + + /* Put itr rlocs */ + lisp_msg_put_itr_rlocs (lcm, b, rlocs, &loc_count); + MREQ_ITR_RLOC_COUNT (h) = loc_count; + + /* Put eid record */ + lisp_msg_put_eid_rec (b, deid); + + nonce[0] = MREQ_NONCE (h); + return h; +} + +void * +lisp_msg_push_ecm (vlib_main_t * vm, vlib_buffer_t * b, int lp, int rp, + gid_address_t * la, gid_address_t * ra) +{ + ecm_hdr_t *h; + ip_address_t _src_ip, *src_ip = &_src_ip, _dst_ip, *dst_ip = &_dst_ip; + if (gid_address_type (la) != GID_ADDR_IP_PREFIX) + { + /* empty ip4 */ + clib_memset (src_ip, 0, sizeof (src_ip[0])); + clib_memset (dst_ip, 0, sizeof (dst_ip[0])); + } + else + { + src_ip = &gid_address_ip (la); + dst_ip = &gid_address_ip (ra); + } + + /* Push inner ip and udp */ + pkt_push_udp_and_ip (vm, b, lp, rp, src_ip, dst_ip, 0); + + /* Push lisp ecm hdr */ + h = pkt_push_ecm_hdr (b); + + return h; +} + +static u32 +msg_type_to_hdr_len (lisp_msg_type_e type) +{ + switch (type) + { + case LISP_MAP_REQUEST: + return (sizeof (map_request_hdr_t)); + case LISP_MAP_REPLY: + return (sizeof (map_reply_hdr_t)); + default: + return (0); + } +} + +void * +lisp_msg_pull_hdr (vlib_buffer_t * b, lisp_msg_type_e type) +{ + return vlib_buffer_pull (b, msg_type_to_hdr_len (type)); +} + +u32 +lisp_msg_parse_addr (vlib_buffer_t * b, gid_address_t * eid) +{ + u32 len; + clib_memset (eid, 0, sizeof (*eid)); + len = gid_address_parse (vlib_buffer_get_current (b), eid); + if (len != ~0) + vlib_buffer_pull (b, len); + return len; +} + +u32 +lisp_msg_parse_eid_rec (vlib_buffer_t * b, gid_address_t * eid) +{ + eid_record_hdr_t *h = vlib_buffer_get_current (b); + u32 len; + clib_memset (eid, 0, sizeof (*eid)); + len = gid_address_parse (EID_REC_ADDR (h), eid); + if (len == ~0) + return len; + + gid_address_ippref_len (eid) = EID_REC_MLEN (h); + vlib_buffer_pull (b, len + sizeof (eid_record_hdr_t)); + + return len + sizeof (eid_record_hdr_t); +} + +u32 +lisp_msg_parse_itr_rlocs (vlib_buffer_t * b, gid_address_t ** rlocs, + u8 rloc_count) +{ + gid_address_t tloc; + u32 i, len = 0, tlen = 0; + + //MREQ_ITR_RLOC_COUNT(mreq_hdr) + 1 + for (i = 0; i < rloc_count; i++) + { + len = lisp_msg_parse_addr (b, &tloc); + if (len == ~0) + return len; + vec_add1 (*rlocs, tloc); + tlen += len; + } + return tlen; +} + +u32 +lisp_msg_parse_loc (vlib_buffer_t * b, locator_t * loc) +{ + int len; + + len = locator_parse (vlib_buffer_get_current (b), loc); + if (len == ~0) + return ~0; + + if (!vlib_buffer_has_space (b, sizeof (len))) + return ~0; + vlib_buffer_pull (b, len); + + return len; +} + +u32 +lisp_msg_parse_mapping_record (vlib_buffer_t * b, gid_address_t * eid, + locator_t ** locs, locator_t * probed_) +{ + void *h = 0, *loc_hdr = 0; + locator_t loc, *probed = 0; + int i = 0, len = 0, llen = 0; + + h = vlib_buffer_get_current (b); + if (!vlib_buffer_has_space (b, sizeof (mapping_record_hdr_t))) + return ~0; + + vlib_buffer_pull (b, sizeof (mapping_record_hdr_t)); + + clib_memset (eid, 0, sizeof (*eid)); + len = gid_address_parse (vlib_buffer_get_current (b), eid); + if (len == ~0) + return len; + + if (!vlib_buffer_has_space (b, sizeof (len))) + return ~0; + + vlib_buffer_pull (b, len); + if (GID_ADDR_IP_PREFIX == gid_address_type (eid)) + gid_address_ippref_len (eid) = MAP_REC_EID_PLEN (h); + + for (i = 0; i < MAP_REC_LOC_COUNT (h); i++) + { + loc_hdr = vlib_buffer_get_current (b); + + llen = lisp_msg_parse_loc (b, &loc); + if (llen == ~0) + return llen; + vec_add1 (*locs, loc); + len += llen; + + if (LOC_PROBED (loc_hdr)) + { + if (probed != 0) + clib_warning + ("Multiple locators probed! Probing only the first!"); + else + probed = &loc; + } + } + /* XXX */ + if (probed_ != 0 && probed) + *probed_ = *probed; + + return len + sizeof (map_reply_hdr_t); +} + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/lisp/lisp-cp/lisp_msg_serdes.h b/src/plugins/lisp/lisp-cp/lisp_msg_serdes.h new file mode 100644 index 00000000000..a6222a0263a --- /dev/null +++ b/src/plugins/lisp/lisp-cp/lisp_msg_serdes.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef VNET_LISP_GPE_LISP_MSG_BUILDER_H_ +#define VNET_LISP_GPE_LISP_MSG_BUILDER_H_ + +#include +#include +#include + +void *lisp_msg_put_mreq (lisp_cp_main_t * lcm, vlib_buffer_t * b, + gid_address_t * seid, gid_address_t * deid, + gid_address_t * rlocs, u8 is_smr_invoked, + u8 rloc_probe_set, u64 * nonce); + +void *lisp_msg_put_map_register (vlib_buffer_t * b, mapping_t * records, + u8 want_map_notify, u16 auth_data_len, + u64 * nonce, u32 * msg_len); + +void *lisp_msg_push_ecm (vlib_main_t * vm, vlib_buffer_t * b, int lp, int rp, + gid_address_t * la, gid_address_t * ra); + +void *lisp_msg_put_map_reply (vlib_buffer_t * b, mapping_t * record, + u64 nonce, u8 probe_bit); + +u32 +lisp_msg_parse_mapping_record (vlib_buffer_t * b, gid_address_t * eid, + locator_t ** locs, locator_t * probed_); + +u32 lisp_msg_parse_addr (vlib_buffer_t * b, gid_address_t * eid); + +u32 lisp_msg_parse_eid_rec (vlib_buffer_t * b, gid_address_t * eid); + +u32 +lisp_msg_parse_itr_rlocs (vlib_buffer_t * b, gid_address_t ** rlocs, + u8 rloc_count); + +#endif /* VNET_LISP_GPE_LISP_MSG_BUILDER_H_ */ + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/lisp/lisp-cp/lisp_test.c b/src/plugins/lisp/lisp-cp/lisp_test.c new file mode 100644 index 00000000000..17bfcf74ebd --- /dev/null +++ b/src/plugins/lisp/lisp-cp/lisp_test.c @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2020 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +clib_error_t *vat_plugin_register_one (vat_main_t * vam); +clib_error_t *vat_plugin_register_cp (vat_main_t * vam); +clib_error_t *vat_plugin_register_gpe (vat_main_t * vam); + +clib_error_t * +vat_plugin_register (vat_main_t * vam) +{ + clib_error_t *err; + + if ((err = vat_plugin_register_gpe (vam))) + return err; + if ((err = vat_plugin_register_cp (vam))) + return err; + if ((err = vat_plugin_register_one (vam))) + return err; + + return NULL; +} + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/lisp/lisp-cp/lisp_types.api b/src/plugins/lisp/lisp-cp/lisp_types.api new file mode 100644 index 00000000000..aab01308df8 --- /dev/null +++ b/src/plugins/lisp/lisp-cp/lisp_types.api @@ -0,0 +1,75 @@ +/* Hey Emacs use -*- mode: C -*- */ +/* + * Copyright (c) 2020 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +option version = "1.0.0"; + +import "vnet/interface_types.api"; +import "vnet/ethernet/ethernet_types.api"; +import "vnet/ip/ip_types.api"; + +typedef local_locator +{ + vl_api_interface_index_t sw_if_index; + u8 priority; + u8 weight; +}; + +typedef remote_locator +{ + u8 priority; + u8 weight; + vl_api_address_t ip_address; +}; + +enum eid_type : u8 +{ + EID_TYPE_API_PREFIX = 0, + EID_TYPE_API_MAC = 1, + EID_TYPE_API_NSH = 2, +}; + +typedef nsh +{ + u32 spi; + u8 si; +}; + +union eid_address +{ + vl_api_prefix_t prefix; + vl_api_mac_address_t mac; + vl_api_nsh_t nsh; +}; + +/* endpoint identifier */ +typedef eid +{ + vl_api_eid_type_t type; + vl_api_eid_address_t address; +}; + +enum hmac_key_id : u8 +{ + KEY_ID_API_HMAC_NO_KEY = 0, + KEY_ID_API_HMAC_SHA_1_96 = 1, + KEY_ID_API_HMAC_SHA_256_128 = 2, +}; + +typedef hmac_key +{ + vl_api_hmac_key_id_t id; + u8 key[64]; +}; diff --git a/src/plugins/lisp/lisp-cp/lisp_types.c b/src/plugins/lisp/lisp-cp/lisp_types.c new file mode 100644 index 00000000000..0356949b757 --- /dev/null +++ b/src/plugins/lisp/lisp-cp/lisp_types.c @@ -0,0 +1,1488 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +static u16 gid_address_put_no_vni (u8 * b, gid_address_t * gid); +static u16 gid_address_size_to_put_no_vni (gid_address_t * gid); +static u16 fid_addr_size_to_write (fid_address_t * a); + +u32 mac_parse (u8 * offset, u8 * a); + +typedef u16 (*size_to_write_fct) (void *); +typedef void *(*cast_fct) (gid_address_t *); +typedef u16 (*serdes_fct) (u8 *, void *); +typedef u8 (*addr_len_fct) (void *); +typedef void (*copy_fct) (void *, void *); +typedef void (*free_fct) (void *); +typedef int (*cmp_fct) (void *, void *); + +size_to_write_fct size_to_write_fcts[GID_ADDR_TYPES] = + { ip_prefix_size_to_write, lcaf_size_to_write, mac_size_to_write, + sd_size_to_write, nsh_size_to_write, 0 /* arp */ , no_addr_size_to_write +}; + +serdes_fct write_fcts[GID_ADDR_TYPES] = + { ip_prefix_write, lcaf_write, mac_write, sd_write, nsh_write, 0 /* arp */ , + no_addr_write +}; + +cast_fct cast_fcts[GID_ADDR_TYPES] = + { ip_prefix_cast, lcaf_cast, mac_cast, sd_cast, nsh_cast, no_addr_cast, + no_addr_cast +}; + +addr_len_fct addr_len_fcts[GID_ADDR_TYPES] = + { ip_prefix_length, lcaf_length, mac_length, sd_length, nsh_length, + 0 /* arp */ , no_addr_length +}; + +copy_fct copy_fcts[GID_ADDR_TYPES] = + { ip_prefix_copy, lcaf_copy, mac_copy, sd_copy, nsh_copy, no_addr_copy, + no_addr_copy +}; + +#define foreach_lcaf_type \ + _(1, no_addr) \ + _(0, NULL) \ + _(1, vni) \ + _(0, NULL) \ + _(0, NULL) \ + _(0, NULL) \ + _(0, NULL) \ + _(0, NULL) \ + _(0, NULL) \ + _(0, NULL) \ + _(0, NULL) \ + _(0, NULL) \ + _(1, sd) \ + _(0, NULL) \ + _(0, NULL) \ + _(0, NULL) \ + _(0, NULL) \ + _(1, nsh) + +#define _(cond, name) \ + u16 name ## _write (u8 * p, void * a); \ + u16 name ## _parse (u8 * p, void * a); \ + u16 name ## _size_to_write (void * a); \ + void name ## _free (void * a); \ + void name ## _copy (void * dst, void * src); \ + u8 name ## _length (void * a); \ + int name ## _cmp (void *, void *); +foreach_lcaf_type +#undef _ +#define CONCAT(a,b) a##_##b +#define IF(c, t, e) CONCAT(IF, c)(t, e) +#define IF_0(t, e) e +#define IF_1(t, e) t +#define EXPAND_FCN(cond, fcn) \ + IF(cond, fcn, NULL) + cmp_fct lcaf_cmp_fcts[LCAF_TYPES] = +{ +#define _(cond, name) \ + EXPAND_FCN(cond, name##_cmp), + foreach_lcaf_type +#undef _ +}; + +addr_len_fct lcaf_body_length_fcts[LCAF_TYPES] = { +#define _(cond, name) \ + EXPAND_FCN(cond, name##_length), + foreach_lcaf_type +#undef _ +}; + +copy_fct lcaf_copy_fcts[LCAF_TYPES] = { +#define _(cond, name) \ + EXPAND_FCN(cond, name##_copy), + foreach_lcaf_type +#undef _ +}; + +free_fct lcaf_free_fcts[LCAF_TYPES] = { +#define _(cond, name) \ + EXPAND_FCN(cond, name##_free), + foreach_lcaf_type +#undef _ +}; + +size_to_write_fct lcaf_size_to_write_fcts[LCAF_TYPES] = { +#define _(cond, name) \ + EXPAND_FCN(cond, name##_size_to_write), + foreach_lcaf_type +#undef _ +}; + +serdes_fct lcaf_write_fcts[LCAF_TYPES] = { +#define _(cond, name) \ + EXPAND_FCN(cond, name##_write), + foreach_lcaf_type +#undef _ +}; + +serdes_fct lcaf_parse_fcts[LCAF_TYPES] = { +#define _(cond, name) \ + EXPAND_FCN(cond, name##_parse), + foreach_lcaf_type +#undef _ +}; + +uword +unformat_nsh_address (unformat_input_t * input, va_list * args) +{ + nsh_t *a = va_arg (*args, nsh_t *); + return unformat (input, "SPI:%d SI:%d", &a->spi, &a->si); +} + +u8 * +format_nsh_address (u8 * s, va_list * args) +{ + nsh_t *a = va_arg (*args, nsh_t *); + return format (s, "SPI:%d SI:%d", a->spi, a->si); +} + +u8 * +format_fid_nsh_address (u8 * s, va_list * args) +{ + u32 *a = va_arg (*args, u32 *); + return format (s, "SPI:%d SI:%d", *a >> 8, *a & 0xff); +} + +u8 * +format_fid_address (u8 * s, va_list * args) +{ + fid_address_t *a = va_arg (*args, fid_address_t *); + + switch (fid_addr_type (a)) + { + case FID_ADDR_IP_PREF: + return format (s, "%U", format_ip_prefix, &fid_addr_ippref (a)); + case FID_ADDR_MAC: + return format (s, "%U", format_mac_address, &fid_addr_mac (a)); + case FID_ADDR_NSH: + return format (s, "%U", format_fid_nsh_address, &fid_addr_nsh (a)); + + default: + clib_warning ("Can't format fid address type %d!", fid_addr_type (a)); + return 0; + } + return 0; +} + +u8 * +format_gid_address (u8 * s, va_list * args) +{ + gid_address_t *a = va_arg (*args, gid_address_t *); + u8 type = gid_address_type (a); + switch (type) + { + case GID_ADDR_IP_PREFIX: + return format (s, "[%d] %U", gid_address_vni (a), format_ip_prefix, + &gid_address_ippref (a)); + case GID_ADDR_SRC_DST: + return format (s, "[%d] %U|%U", gid_address_vni (a), + format_fid_address, &gid_address_sd_src (a), + format_fid_address, &gid_address_sd_dst (a)); + case GID_ADDR_MAC: + return format (s, "[%d] %U", gid_address_vni (a), format_mac_address, + &gid_address_mac (a)); + case GID_ADDR_ARP: + case GID_ADDR_NDP: + return format (s, "[%d, %U]", gid_address_arp_ndp_bd (a), + format_ip_address, &gid_address_arp_ndp_ip (a)); + case GID_ADDR_NSH: + return format (s, "%U", format_nsh_address, &gid_address_nsh (a)); + + default: + clib_warning ("Can't format gid type %d", type); + return 0; + } + return 0; +} + +uword +unformat_fid_address (unformat_input_t * i, va_list * args) +{ + fid_address_t *a = va_arg (*args, fid_address_t *); + ip_prefix_t ippref; + u8 mac[6] = { 0 }; + nsh_t nsh; + + if (unformat (i, "%U", unformat_ip_prefix, &ippref)) + { + fid_addr_type (a) = FID_ADDR_IP_PREF; + ip_prefix_copy (&fid_addr_ippref (a), &ippref); + } + else if (unformat (i, "%U", unformat_mac_address, mac)) + { + fid_addr_type (a) = FID_ADDR_MAC; + mac_copy (fid_addr_mac (a), mac); + } + else if (unformat (i, "%U", unformat_nsh_address, &nsh)) + { + fid_addr_type (a) = FID_ADDR_NSH; + nsh_copy (&fid_addr_nsh (a), &nsh); + } + else + return 0; + + return 1; +} + +uword +unformat_hmac_key_id (unformat_input_t * input, va_list * args) +{ + u32 *key_id = va_arg (*args, u32 *); + u8 *s = 0; + + if (unformat (input, "%s", &s)) + { + if (!strcmp ((char *) s, "sha1")) + key_id[0] = HMAC_SHA_1_96; + else if (!strcmp ((char *) s, "sha256")) + key_id[0] = HMAC_SHA_256_128; + else + { + clib_warning ("invalid key_id: '%s'", s); + key_id[0] = HMAC_NO_KEY; + } + } + else + return 0; + + vec_free (s); + return 1; +} + +uword +unformat_gid_address (unformat_input_t * input, va_list * args) +{ + gid_address_t *a = va_arg (*args, gid_address_t *); + u8 mac[6] = { 0 }; + ip_prefix_t ippref; + fid_address_t sim1, sim2; + nsh_t nsh; + + clib_memset (&ippref, 0, sizeof (ippref)); + clib_memset (&sim1, 0, sizeof (sim1)); + clib_memset (&sim2, 0, sizeof (sim2)); + + if (unformat (input, "%U|%U", unformat_fid_address, &sim1, + unformat_fid_address, &sim2)) + { + gid_address_sd_src (a) = sim1; + gid_address_sd_dst (a) = sim2; + gid_address_type (a) = GID_ADDR_SRC_DST; + } + else if (unformat (input, "%U", unformat_ip_prefix, &ippref)) + { + ip_prefix_copy (&gid_address_ippref (a), &ippref); + gid_address_type (a) = GID_ADDR_IP_PREFIX; + } + else if (unformat (input, "%U", unformat_mac_address, mac)) + { + mac_copy (gid_address_mac (a), mac); + gid_address_type (a) = GID_ADDR_MAC; + } + else if (unformat (input, "%U", unformat_nsh_address, &nsh)) + { + nsh_copy (&gid_address_nsh (a), &nsh); + gid_address_type (a) = GID_ADDR_NSH; + } + else + return 0; + + return 1; +} + +uword +unformat_negative_mapping_action (unformat_input_t * input, va_list * args) +{ + u32 *action = va_arg (*args, u32 *); + u8 *s = 0; + + if (unformat (input, "%s", &s)) + { + if (!strcmp ((char *) s, "no-action")) + action[0] = LISP_NO_ACTION; + else if (!strcmp ((char *) s, "natively-forward")) + action[0] = LISP_FORWARD_NATIVE; + else if (!strcmp ((char *) s, "send-map-request")) + action[0] = LISP_SEND_MAP_REQUEST; + else if (!strcmp ((char *) s, "drop")) + action[0] = LISP_DROP; + else + { + clib_warning ("invalid action: '%s'", s); + action[0] = LISP_DROP; + } + } + else + return 0; + + vec_free (s); + return 1; +} + +u8 * +format_hmac_key_id (u8 * s, va_list * args) +{ + lisp_key_type_t key_id = va_arg (*args, lisp_key_type_t); + + switch (key_id) + { + case HMAC_SHA_1_96: + return format (0, "sha1"); + case HMAC_SHA_256_128: + return format (0, "sha256"); + default: + return 0; + } + + return 0; +} + +u8 * +format_negative_mapping_action (u8 * s, va_list * args) +{ + lisp_action_e action = va_arg (*args, lisp_action_e); + + switch (action) + { + case LISP_NO_ACTION: + s = format (s, "no-action"); + break; + case LISP_FORWARD_NATIVE: + s = format (s, "natively-forward"); + break; + case LISP_SEND_MAP_REQUEST: + s = format (s, "send-map-request"); + break; + case LISP_DROP: + default: + s = format (s, "drop"); + break; + } + return (s); +} + +u8 +ip_prefix_length (void *a) +{ + return ip_prefix_len ((ip_prefix_t *) a); +} + +always_inline lisp_afi_e +ip_version_to_iana_afi (u16 version) +{ + switch (version) + { + case AF_IP4: + return LISP_AFI_IP; + case AF_IP6: + return LISP_AFI_IP6; + default: + return 0; + } + return 0; +} + +always_inline u8 +ip_iana_afi_to_version (lisp_afi_e afi) +{ + switch (afi) + { + case LISP_AFI_IP: + return AF_IP4; + case LISP_AFI_IP6: + return AF_IP6; + default: + return 0; + } + return 0; +} + +u16 +ip_address_size_to_write (ip_address_t * a) +{ + return ip_address_size (a) + sizeof (u16); +} + +u16 +ip_address_iana_afi (ip_address_t * a) +{ + return ip_version_to_iana_afi (ip_addr_version (a)); +} + +u8 +ip_address_max_len (u8 version) +{ + return version == AF_IP4 ? 32 : 128; +} + +u16 +ip4_address_size_to_put () +{ + // return sizeof(u16) + sizeof (ip4_address_t); + return 6; +} + +u16 +ip6_address_size_to_put () +{ + //return sizeof(u16) + sizeof (ip6_address_t); + return 18; +} + +u32 +ip4_address_put (u8 * b, ip4_address_t * a) +{ + *(u16 *) b = clib_host_to_net_u16 (ip_version_to_iana_afi (AF_IP4)); + u8 *p = b + sizeof (u16); + clib_memcpy (p, a, sizeof (*a)); + return ip4_address_size_to_put (); +} + +u32 +ip6_address_put (u8 * b, ip6_address_t * a) +{ + *(u16 *) b = clib_host_to_net_u16 (ip_version_to_iana_afi (AF_IP6)); + u8 *p = b + sizeof (u16); + clib_memcpy (p, a, sizeof (*a)); + return ip6_address_size_to_put (); +} + +u32 +ip_address_put (u8 * b, ip_address_t * a) +{ + u32 len = ip_address_size (a); + *(u16 *) b = clib_host_to_net_u16 (ip_address_iana_afi (a)); + u8 *p = b + sizeof (u16); + clib_memcpy (p, ip_addr_bytes (a), len); + return (len + sizeof (u16)); +} + +u32 +ip_address_parse (void *offset, u16 iana_afi, ip_address_t * dst) +{ + ip_addr_version (dst) = ip_iana_afi_to_version (iana_afi); + u8 size = ip_version_to_size (ip_addr_version (dst)); + clib_memcpy (ip_addr_bytes (dst), offset + sizeof (u16), size); + return (sizeof (u16) + size); +} + +void +gid_to_dp_address (gid_address_t * g, dp_address_t * d) +{ + switch (gid_address_type (g)) + { + case GID_ADDR_SRC_DST: + switch (gid_address_sd_dst_type (g)) + { + case FID_ADDR_IP_PREF: + ip_prefix_copy (&d->ippref, &gid_address_sd_dst_ippref (g)); + d->type = FID_ADDR_IP_PREF; + break; + case FID_ADDR_MAC: + mac_copy (&d->mac, &gid_address_sd_dst_mac (g)); + d->type = FID_ADDR_MAC; + break; + default: + clib_warning ("Source/Dest address type %d not supported!", + gid_address_sd_dst_type (g)); + break; + } + break; + case GID_ADDR_IP_PREFIX: + ip_prefix_copy (&d->ippref, &gid_address_ippref (g)); + d->type = FID_ADDR_IP_PREF; + break; + case GID_ADDR_MAC: + mac_copy (&d->mac, &gid_address_mac (g)); + d->type = FID_ADDR_MAC; + break; + case GID_ADDR_NSH: + default: + d->nsh = gid_address_nsh (g).spi << 8 | gid_address_nsh (g).si; + d->type = FID_ADDR_NSH; + break; + } +} + +u32 +lcaf_hdr_parse (void *offset, lcaf_t * lcaf) +{ + lcaf_hdr_t *lh = offset; + lcaf->type = lh->type; + + /* this is a bit of hack: since the LCAF Instance ID is the + only message that uses reserved2 field, we can set it here. + If any LCAF format starts using reserved2 field as well this needs + to be moved elsewhere */ + lcaf_vni_len (lcaf) = lh->reserved2; + + return sizeof (lh[0]); +} + +static u8 +iana_afi_to_fid_addr_type (u16 type) +{ + switch (type) + { + case LISP_AFI_IP: + case LISP_AFI_IP6: + return FID_ADDR_IP_PREF; + + case LISP_AFI_MAC: + return FID_ADDR_MAC; + } + return ~0; +} + +static u16 +fid_addr_parse (u8 * p, fid_address_t * a) +{ + u16 afi = clib_net_to_host_u16 (*(u16 *) p); + fid_addr_type (a) = iana_afi_to_fid_addr_type (afi); + ip_address_t *ip_addr = &ip_prefix_addr (&fid_addr_ippref (a)); + + switch (fid_addr_type (a)) + { + case FID_ADDR_MAC: + return mac_parse (p, fid_addr_mac (a)); + + case FID_ADDR_IP_PREF: + return ip_address_parse (p, afi, ip_addr); + + case FID_ADDR_NSH: + break; + } + return ~0; +} + +#define INC(dst, exp) \ +do { \ + u16 _sum = (exp); \ + if ((u16)~0 == _sum) \ + return ~0; \ + dst += _sum; \ +} while (0); + +void +nsh_free (void *a) +{ + /* nothing to do */ +} + +u16 +nsh_parse (u8 * p, void *a) +{ + lcaf_spi_hdr_t *h = (lcaf_spi_hdr_t *) p; + gid_address_t *g = a; + + gid_address_type (g) = GID_ADDR_NSH; + gid_address_nsh_spi (g) = clib_net_to_host_u32 (LCAF_SPI_SI (h)) >> 8; + gid_address_nsh_si (g) = (u8) clib_net_to_host_u32 (LCAF_SPI_SI (h)); + + return sizeof (lcaf_spi_hdr_t); +} + +int +nsh_cmp (void *a1, void *a2) +{ + nsh_t *n1 = a1; + nsh_t *n2 = a2; + + if (n1->spi != n2->spi) + return 1; + if (n1->si != n2->si) + return 1; + return 0; +} + +u16 +sd_parse (u8 * p, void *a) +{ + lcaf_src_dst_hdr_t *sd_hdr; + gid_address_t *g = a; + u16 size = 0; + fid_address_t *src = &gid_address_sd_src (g); + fid_address_t *dst = &gid_address_sd_dst (g); + + gid_address_type (g) = GID_ADDR_SRC_DST; + + sd_hdr = (lcaf_src_dst_hdr_t *) (p + size); + size += sizeof (sd_hdr[0]); + + INC (size, fid_addr_parse (p + size, src)); + INC (size, fid_addr_parse (p + size, dst)); + + if (fid_addr_type (src) == FID_ADDR_IP_PREF) + { + ip_prefix_t *ippref = &fid_addr_ippref (src); + ip_prefix_len (ippref) = LCAF_SD_SRC_ML (sd_hdr); + } + if (fid_addr_type (dst) == FID_ADDR_IP_PREF) + { + ip_prefix_t *ippref = &fid_addr_ippref (dst); + ip_prefix_len (ippref) = LCAF_SD_DST_ML (sd_hdr); + } + return size; +} + +u16 +try_parse_src_dst_lcaf (u8 * p, gid_address_t * a) +{ + lcaf_t lcaf; + u16 size = sizeof (u16); /* skip AFI */ + + size += lcaf_hdr_parse (p + size, &lcaf); + + if (LCAF_SOURCE_DEST != lcaf_type (&lcaf)) + return ~0; + + INC (size, sd_parse (p + size, a)); + return size; +} + +u16 +vni_parse (u8 * p, void *a) +{ + lcaf_t *lcaf = a; + gid_address_t *g = a; + u16 size = 0; + + gid_address_vni (g) = clib_net_to_host_u32 (*(u32 *) p); + size += sizeof (u32); + gid_address_vni_mask (g) = lcaf_vni_len (lcaf); + + /* nested LCAFs are not supported except of src/dst with vni - to handle + * such case look at the next AFI and process src/dest LCAF separately */ + u16 afi = clib_net_to_host_u16 (*((u16 *) (p + size))); + if (LISP_AFI_LCAF == afi) + { + INC (size, try_parse_src_dst_lcaf (p + size, g)); + } + else + INC (size, gid_address_parse (p + size, g)); + + return size; +} + +u16 +no_addr_parse (u8 * p, void *a) +{ + /* do nothing */ + return 0; +} + +u32 +lcaf_parse (void *offset, gid_address_t * addr) +{ + /* skip AFI type */ + offset += sizeof (u16); + lcaf_t *lcaf = &gid_address_lcaf (addr); + + u32 size = lcaf_hdr_parse (offset, lcaf); + u8 type = lcaf_type (lcaf); + + if (!lcaf_parse_fcts[type]) + { + clib_warning ("Unsupported LCAF type: %u", type); + return ~0; + } + INC (size, (*lcaf_parse_fcts[type]) (offset + size, lcaf)); + return sizeof (u16) + size; +} + +void +vni_free (void *a) +{ + vni_t *v = a; + gid_address_free (vni_gid (v)); + clib_mem_free (vni_gid (v)); +} + +void +no_addr_free (void *a) +{ + /* nothing to do */ +} + +void +sd_free (void *a) +{ + /* nothing */ +} + +void +gid_address_free (gid_address_t * a) +{ + if (gid_address_type (a) != GID_ADDR_LCAF) + return; + + lcaf_t *lcaf = &gid_address_lcaf (a); + u8 lcaf_type = lcaf_type (lcaf); + (*lcaf_free_fcts[lcaf_type]) (lcaf); +} + +void +gid_address_from_ip (gid_address_t * g, ip_address_t * ip) +{ + clib_memset (g, 0, sizeof (g[0])); + ip_address_set (&gid_address_ip (g), ip, ip_addr_version (ip)); + gid_address_ippref_len (g) = 32; +} + +void * +ip_prefix_cast (gid_address_t * a) +{ + return &gid_address_ippref (a); +} + +u16 +ip_prefix_size_to_write (void *pref) +{ + ip_prefix_t *a = (ip_prefix_t *) pref; + return ip_address_size_to_write (&ip_prefix_addr (a)); +} + +u16 +ip_prefix_write (u8 * p, void *gid) +{ + gid_address_t *g = gid; + ip_prefix_t *a = &gid_address_ippref (g); + + switch (ip_prefix_version (a)) + { + case AF_IP4: + return ip4_address_put (p, &ip_prefix_v4 (a)); + break; + case AF_IP6: + return ip6_address_put (p, &ip_prefix_v6 (a)); + break; + } + return 0; +} + +void +mac_copy (void *dst, void *src) +{ + clib_memcpy (dst, src, 6); +} + +void +sd_copy (void *dst, void *src) +{ + clib_memcpy (dst, src, sizeof (source_dest_t)); +} + +void +nsh_copy (void *dst, void *src) +{ + clib_memcpy (dst, src, sizeof (nsh_t)); +} + +void +no_addr_copy (void *dst, void *src) +{ + /* nothing to do */ +} + +void +vni_copy (void *dst, void *src) +{ + vni_t *vd = dst; + vni_t *vs = src; + + clib_memcpy (vd, vs, sizeof (vd[0])); + vni_gid (vd) = clib_mem_alloc (sizeof (gid_address_t)); + gid_address_copy (vni_gid (vd), vni_gid (vs)); +} + +void +lcaf_copy (void *dst, void *src) +{ + lcaf_t *lcaf_dst = dst; + lcaf_t *lcaf_src = src; + + lcaf_type (lcaf_dst) = lcaf_type (lcaf_src); + (*lcaf_copy_fcts[lcaf_type (lcaf_src)]) (dst, src); +} + +u8 +lcaf_length (void *a) +{ + return 0; +} + +u8 +mac_length (void *a) +{ + return 0; +} + +u8 +sd_length (void *a) +{ + return 0; +} + +u8 +nsh_length (void *a) +{ + return 0; +} + +void * +lcaf_cast (gid_address_t * a) +{ + return &gid_address_lcaf (a); +} + +void * +mac_cast (gid_address_t * a) +{ + return &gid_address_mac (a); +} + +void * +no_addr_cast (gid_address_t * a) +{ + return (void *) a; +} + +void * +sd_cast (gid_address_t * a) +{ + return &gid_address_sd (a); +} + +void * +nsh_cast (gid_address_t * a) +{ + return &gid_address_nsh (a); +} + +u8 +no_addr_length (void *a) +{ + return 0; +} + +u8 +vni_length (void *a) +{ + vni_t *v = a; + return (sizeof (u32) /* VNI size */ + + gid_address_size_to_put (vni_gid (v)) /* vni body size */ ); +} + +u16 +lcaf_write (u8 * p, void *a) +{ + u16 size = 0, len; + lcaf_t *lcaf = a; + u8 type = lcaf_type (lcaf); + lcaf_hdr_t _h, *h = &_h; + + *(u16 *) p = clib_host_to_net_u16 (LISP_AFI_LCAF); + size += sizeof (u16); + clib_memset (h, 0, sizeof (h[0])); + LCAF_TYPE (h) = type; + u16 lcaf_len = (*lcaf_body_length_fcts[type]) (lcaf); + LCAF_LENGTH (h) = clib_host_to_net_u16 (lcaf_len); + + clib_memcpy (p + size, h, sizeof (h[0])); + size += sizeof (h[0]); + len = (*lcaf_write_fcts[type]) (p + size, lcaf); + + if ((u16) ~ 0 == len) + return ~0; + + return size + len; +} + +u16 +mac_write (u8 * p, void *a) +{ + *(u16 *) p = clib_host_to_net_u16 (LISP_AFI_MAC); + clib_memcpy (p + sizeof (u16), a, 6); + return mac_size_to_write (a); +} + +static u16 +fid_addr_write (u8 * p, fid_address_t * a) +{ + switch (fid_addr_type (a)) + { + case FID_ADDR_IP_PREF: + return ip_prefix_write (p, &fid_addr_ippref (a)); + + case FID_ADDR_MAC: + return mac_write (p, &fid_addr_mac (a)); + + default: + return ~0; + } + return ~0; +} + +static u8 +fid_address_length (fid_address_t * a) +{ + switch (fid_addr_type (a)) + { + case FID_ADDR_IP_PREF: + return ip_prefix_length (&fid_addr_ippref (a)); + case FID_ADDR_MAC: + return 0; + case FID_ADDR_NSH: + return 0; + } + return 0; +} + +u16 +sd_write (u8 * p, void *a) +{ + source_dest_t *sd = a; + u16 size = 0; + lcaf_hdr_t _h, *h = &_h; + lcaf_src_dst_hdr_t sd_hdr; + + *(u16 *) p = clib_host_to_net_u16 (LISP_AFI_LCAF); + size += sizeof (u16); + clib_memset (h, 0, sizeof (h[0])); + LCAF_TYPE (h) = LCAF_SOURCE_DEST; + u16 lcaf_len = sizeof (lcaf_src_dst_hdr_t) + + fid_addr_size_to_write (&sd_src (sd)) + + fid_addr_size_to_write (&sd_dst (sd)); + LCAF_LENGTH (h) = clib_host_to_net_u16 (lcaf_len); + + clib_memcpy (p + size, h, sizeof (h[0])); + size += sizeof (h[0]); + + clib_memset (&sd_hdr, 0, sizeof (sd_hdr)); + LCAF_SD_SRC_ML (&sd_hdr) = fid_address_length (&sd_src (sd)); + LCAF_SD_DST_ML (&sd_hdr) = fid_address_length (&sd_dst (sd)); + clib_memcpy (p + size, &sd_hdr, sizeof (sd_hdr)); + size += sizeof (sd_hdr); + + u16 len = fid_addr_write (p + size, &sd_src (sd)); + if ((u16) ~ 0 == len) + return ~0; + size += len; + + len = fid_addr_write (p + size, &sd_dst (sd)); + if ((u16) ~ 0 == len) + return ~0; + size += len; + + return size; +} + +u16 +nsh_write (u8 * p, void *a) +{ + lcaf_spi_hdr_t spi; + lcaf_hdr_t lcaf; + gid_address_t *g = a; + u16 size = 0; + + ASSERT (gid_address_type (g) == GID_ADDR_NSH); + + clib_memset (&lcaf, 0, sizeof (lcaf)); + clib_memset (&spi, 0, sizeof (spi)); + + LCAF_TYPE (&lcaf) = LCAF_NSH; + LCAF_LENGTH (&lcaf) = clib_host_to_net_u16 (sizeof (lcaf_spi_hdr_t)); + + u32 s = clib_host_to_net_u32 (gid_address_nsh_spi (g) << 8 | + gid_address_nsh_si (g)); + LCAF_SPI_SI (&spi) = s; + + *(u16 *) p = clib_host_to_net_u16 (LISP_AFI_LCAF); + size += sizeof (u16); + + clib_memcpy (p + size, &lcaf, sizeof (lcaf)); + size += sizeof (lcaf); + + clib_memcpy (p + size, &spi, sizeof (spi)); + size += sizeof (spi); + + return size; +} + +u16 +vni_write (u8 * p, void *a) +{ + lcaf_hdr_t _h, *h = &_h; + gid_address_t *g = a; + u16 size = 0, len; + + /* put lcaf header */ + *(u16 *) p = clib_host_to_net_u16 (LISP_AFI_LCAF); + size += sizeof (u16); + clib_memset (h, 0, sizeof (h[0])); + LCAF_TYPE (h) = LCAF_INSTANCE_ID; + u16 lcaf_len = sizeof (u32) /* Instance ID size */ + + gid_address_size_to_put_no_vni (g); + LCAF_LENGTH (h) = clib_host_to_net_u16 (lcaf_len); + LCAF_RES2 (h) = gid_address_vni_mask (g); + + /* put vni header */ + clib_memcpy (p + size, h, sizeof (h[0])); + size += sizeof (h[0]); + + u32 *afip = (u32 *) (p + size); + afip[0] = clib_host_to_net_u32 (gid_address_vni (g)); + size += sizeof (u32); + + if (GID_ADDR_SRC_DST == gid_address_type (g)) + /* write src/dst LCAF */ + { + len = sd_write (p + size, g); + if ((u16) ~ 0 == len) + return ~0; + } + else + /* write the actual address */ + len = gid_address_put_no_vni (p + size, g); + + if ((u16) ~ 0 == len) + return ~0; + + return size + len; +} + +u16 +no_addr_write (u8 * p, void *a) +{ + /* do nothing; return AFI field size */ + return sizeof (u16); +} + +u16 +no_addr_size_to_write (void *a) +{ + return sizeof (u16); /* AFI field length */ +} + +static u16 +fid_addr_size_to_write (fid_address_t * a) +{ + switch (fid_addr_type (a)) + { + case FID_ADDR_IP_PREF: + return ip_prefix_size_to_write (a); + + case FID_ADDR_MAC: + return mac_size_to_write (a); + + default: + break; + } + return 0; +} + +u16 +vni_size_to_write (void *a) +{ + gid_address_t *g = a; + + u16 lcaf_size = sizeof (u32) + sizeof (u16) /* LCAF AFI field size */ + + sizeof (lcaf_hdr_t); + + if (gid_address_type (g) == GID_ADDR_SRC_DST) + /* special case where nested LCAF is supported */ + return lcaf_size + sd_size_to_write (g); + else + return lcaf_size + gid_address_size_to_put_no_vni (g); +} + +u16 +lcaf_size_to_write (void *a) +{ + lcaf_t *lcaf = (lcaf_t *) a; + u32 size = 0, len; + u8 type = lcaf_type (lcaf); + + size += sizeof (u16); /* AFI size */ + + len = (*lcaf_size_to_write_fcts[type]) (lcaf); + if (~0 == len) + return ~0; + + return size + len; +} + +u16 +sd_size_to_write (void *a) +{ + source_dest_t *sd = a; + return sizeof (u16) + + sizeof (lcaf_hdr_t) + + sizeof (lcaf_src_dst_hdr_t) + + fid_addr_size_to_write (&sd_src (sd)) + + fid_addr_size_to_write (&sd_dst (sd)); +} + +u16 +mac_size_to_write (void *a) +{ + return sizeof (u16) + 6; +} + +u16 +nsh_size_to_write (void *a) +{ + return sizeof (u16) + sizeof (lcaf_hdr_t) + sizeof (lcaf_spi_hdr_t); +} + +u8 +gid_address_len (gid_address_t * a) +{ + gid_address_type_t type = gid_address_type (a); + return (*addr_len_fcts[type]) ((*cast_fcts[type]) (a)); +} + +static u16 +gid_address_put_no_vni (u8 * b, gid_address_t * gid) +{ + gid_address_type_t type = gid_address_type (gid); + return (*write_fcts[type]) (b, (*cast_fcts[type]) (gid)); +} + +u16 +gid_address_put (u8 * b, gid_address_t * gid) +{ + if (0 != gid_address_vni (gid)) + return vni_write (b, gid); + + return gid_address_put_no_vni (b, gid); +} + +static u16 +gid_address_size_to_put_no_vni (gid_address_t * gid) +{ + gid_address_type_t type = gid_address_type (gid); + return (*size_to_write_fcts[type]) ((*cast_fcts[type]) (gid)); +} + +u16 +gid_address_size_to_put (gid_address_t * gid) +{ + if (0 != gid_address_vni (gid)) + return vni_size_to_write (gid); + + return gid_address_size_to_put_no_vni (gid); +} + +void * +gid_address_cast (gid_address_t * gid, gid_address_type_t type) +{ + return (*cast_fcts[type]) (gid); +} + +void +gid_address_copy (gid_address_t * dst, gid_address_t * src) +{ + gid_address_type_t type = gid_address_type (src); + (*copy_fcts[type]) ((*cast_fcts[type]) (dst), (*cast_fcts[type]) (src)); + gid_address_type (dst) = type; + gid_address_vni (dst) = gid_address_vni (src); + gid_address_vni_mask (dst) = gid_address_vni_mask (src); +} + +u32 +mac_parse (u8 * offset, u8 * a) +{ + /* skip AFI field */ + offset += sizeof (u16); + + clib_memcpy (a, offset, 6); + return sizeof (u16) + 6; +} + +u32 +gid_address_parse (u8 * offset, gid_address_t * a) +{ + lisp_afi_e afi; + u16 len = 0; + + ASSERT (a); + + /* NOTE: since gid_address_parse may be called by vni_parse, we can't 0 + * the gid address here */ + afi = clib_net_to_host_u16 (*((u16 *) offset)); + + switch (afi) + { + case LISP_AFI_NO_ADDR: + len = sizeof (u16); + gid_address_type (a) = GID_ADDR_NO_ADDRESS; + break; + case LISP_AFI_IP: + len = ip_address_parse (offset, afi, &gid_address_ip (a)); + gid_address_type (a) = GID_ADDR_IP_PREFIX; + /* this should be modified outside if needed */ + gid_address_ippref_len (a) = 32; + break; + case LISP_AFI_IP6: + len = ip_address_parse (offset, afi, &gid_address_ip (a)); + gid_address_type (a) = GID_ADDR_IP_PREFIX; + /* this should be modified outside if needed */ + gid_address_ippref_len (a) = 128; + break; + case LISP_AFI_LCAF: + gid_address_type (a) = GID_ADDR_LCAF; + len = lcaf_parse (offset, a); + break; + case LISP_AFI_MAC: + len = mac_parse (offset, gid_address_mac (a)); + gid_address_type (a) = GID_ADDR_MAC; + break; + default: + clib_warning ("LISP AFI %d not supported!", afi); + return ~0; + } + return (len == (u16) ~ 0) ? ~0 : len; +} + +void +gid_address_ip_set (gid_address_t * dst, void *src, u8 version) +{ + gid_address_ippref_len (dst) = ip_address_max_len (version); + ip_address_set (&gid_address_ip (dst), src, version); +} + +int +no_addr_cmp (void *a1, void *a2) +{ + return 0; +} + +int +vni_cmp (void *a1, void *a2) +{ + vni_t *v1 = a1; + vni_t *v2 = a2; + + if (vni_mask_len (v1) != vni_mask_len (v2)) + return -1; + if (vni_vni (v1) != vni_vni (v2)) + return -1; + return gid_address_cmp (vni_gid (v1), vni_gid (v2)); +} + +static int +mac_cmp (void *a1, void *a2) +{ + return memcmp (a1, a2, 6); +} + +static int +fid_addr_cmp (fid_address_t * a1, fid_address_t * a2) +{ + if (fid_addr_type (a1) != fid_addr_type (a2)) + return -1; + + switch (fid_addr_type (a1)) + { + case FID_ADDR_IP_PREF: + return ip_prefix_cmp (&fid_addr_ippref (a1), &fid_addr_ippref (a2)); + + case FID_ADDR_MAC: + return mac_cmp (fid_addr_mac (a1), fid_addr_mac (a2)); + + default: + return -1; + } + return -1; +} + +int +sd_cmp (void *a1, void *a2) +{ + source_dest_t *sd1 = a1; + source_dest_t *sd2 = a2; + + if (fid_addr_cmp (&sd_dst (sd1), &sd_dst (sd2))) + return -1; + if (fid_addr_cmp (&sd_src (sd1), &sd_src (sd2))) + return -1; + return 0; +} + +/* Compare two gid_address_t. + * Returns: + * -1: If they are from different afi + * 0: Both address are the same + * 1: Addr1 is bigger than addr2 + * 2: Addr2 is bigger than addr1 + */ +int +gid_address_cmp (gid_address_t * a1, gid_address_t * a2) +{ + lcaf_t *lcaf1, *lcaf2; + int cmp = -1; + if (!a1 || !a2) + return -1; + if (gid_address_type (a1) != gid_address_type (a2)) + return -1; + if (gid_address_vni (a1) != gid_address_vni (a2)) + return -1; + + /* TODO vni mask is not supported, disable comparing for now + if (gid_address_vni_mask (a1) != gid_address_vni_mask (a2)) + return -1; + */ + + switch (gid_address_type (a1)) + { + case GID_ADDR_NO_ADDRESS: + if (a1 == a2) + cmp = 0; + else + cmp = 2; + break; + case GID_ADDR_IP_PREFIX: + cmp = + ip_prefix_cmp (&gid_address_ippref (a1), &gid_address_ippref (a2)); + break; + case GID_ADDR_LCAF: + lcaf1 = &gid_address_lcaf (a1); + lcaf2 = &gid_address_lcaf (a2); + if (lcaf_type (lcaf1) == lcaf_type (lcaf2)) + cmp = (*lcaf_cmp_fcts[lcaf_type (lcaf1)]) (lcaf1, lcaf2); + break; + case GID_ADDR_MAC: + cmp = mac_cmp (gid_address_mac (a1), gid_address_mac (a2)); + break; + + case GID_ADDR_SRC_DST: + cmp = sd_cmp (&gid_address_sd (a1), &gid_address_sd (a2)); + break; + case GID_ADDR_NSH: + cmp = nsh_cmp (&gid_address_nsh (a1), &gid_address_nsh (a2)); + break; + default: + break; + } + + return cmp; +} + +u32 +locator_parse (void *b, locator_t * loc) +{ + locator_hdr_t *h; + u8 status = 1; /* locator up */ + int len; + + h = b; + if (!LOC_REACHABLE (h) && LOC_LOCAL (h)) + status = 0; + + len = gid_address_parse (LOC_ADDR (h), &loc->address); + if (len == ~0) + return len; + + loc->state = status; + loc->local = 0; + loc->probed = 0; + loc->priority = LOC_PRIORITY (h); + loc->weight = LOC_WEIGHT (h); + loc->mpriority = LOC_MPRIORITY (h); + loc->mweight = LOC_MWEIGHT (h); + + return sizeof (locator_hdr_t) + len; +} + +void +locator_copy (locator_t * dst, locator_t * src) +{ + /* TODO if gid become more complex, this will need to be changed! */ + clib_memcpy (dst, src, sizeof (*dst)); + if (!src->local) + gid_address_copy (&dst->address, &src->address); +} + +u32 +locator_cmp (locator_t * l1, locator_t * l2) +{ + u32 ret = 0; + if ((ret = gid_address_cmp (&l1->address, &l2->address)) != 0) + return 1; + + if (l1->priority != l2->priority) + return 1; + if (l1->weight != l2->weight) + return 1; + if (l1->mpriority != l2->mpriority) + return 1; + if (l1->mweight != l2->mweight) + return 1; + return 0; +} + +void +locator_free (locator_t * l) +{ + if (!l->local) + gid_address_free (&l->address); +} + +void +build_src_dst (gid_address_t * sd, gid_address_t * src, gid_address_t * dst) +{ + clib_memset (sd, 0, sizeof (*sd)); + gid_address_type (sd) = GID_ADDR_SRC_DST; + gid_address_vni (sd) = gid_address_vni (dst); + gid_address_vni_mask (sd) = gid_address_vni_mask (dst); + + switch (gid_address_type (dst)) + { + case GID_ADDR_IP_PREFIX: + gid_address_sd_src_type (sd) = FID_ADDR_IP_PREF; + gid_address_sd_dst_type (sd) = FID_ADDR_IP_PREF; + ip_prefix_copy (&gid_address_sd_src_ippref (sd), + &gid_address_ippref (src)); + ip_prefix_copy (&gid_address_sd_dst_ippref (sd), + &gid_address_ippref (dst)); + break; + case GID_ADDR_MAC: + gid_address_sd_src_type (sd) = FID_ADDR_MAC; + gid_address_sd_dst_type (sd) = FID_ADDR_MAC; + mac_copy (gid_address_sd_src_mac (sd), gid_address_mac (src)); + mac_copy (gid_address_sd_dst_mac (sd), gid_address_mac (dst)); + break; + default: + clib_warning ("Unsupported gid type %d while conversion!", + gid_address_type (dst)); + break; + } +} + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/lisp/lisp-cp/lisp_types.h b/src/plugins/lisp/lisp-cp/lisp_types.h new file mode 100644 index 00000000000..3f7d0302640 --- /dev/null +++ b/src/plugins/lisp/lisp-cp/lisp_types.h @@ -0,0 +1,350 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef VNET_LISP_GPE_LISP_TYPES_H_ +#define VNET_LISP_GPE_LISP_TYPES_H_ + +#include +#include + +#define SHA1_AUTH_DATA_LEN 20 +#define SHA256_AUTH_DATA_LEN 32 + +typedef enum +{ + HMAC_NO_KEY = 0, + HMAC_SHA_1_96, + HMAC_SHA_256_128 +} lisp_key_type_t; + +uword unformat_hmac_key_id (unformat_input_t * input, va_list * args); +u8 *format_hmac_key_id (u8 * s, va_list * args); + +typedef enum +{ + /* NOTE: ip addresses are left out on purpose. Use max masked ip-prefixes + * instead */ + GID_ADDR_IP_PREFIX, + GID_ADDR_LCAF, + GID_ADDR_MAC, + GID_ADDR_SRC_DST, + GID_ADDR_NSH, + GID_ADDR_ARP, + GID_ADDR_NDP, + GID_ADDR_NO_ADDRESS, + GID_ADDR_TYPES +} gid_address_type_t; + +typedef enum +{ + /* make sure that values corresponds with RFC */ + LCAF_NULL_BODY = 0, + LCAF_AFI_LIST_TYPE, + LCAF_INSTANCE_ID, + LCAF_SOURCE_DEST = 12, + LCAF_NSH = 17, + LCAF_TYPES +} lcaf_type_t; + +typedef enum fid_addr_type_t_ +{ + FID_ADDR_IP_PREF, + FID_ADDR_MAC, + FID_ADDR_NSH +} __attribute__ ((packed)) fid_addr_type_t; + +/* flat address type */ +typedef struct +{ + union + { + ip_prefix_t ippref; + u8 mac[6]; + u32 nsh; + }; + fid_addr_type_t type; +} fid_address_t; + +typedef fid_address_t dp_address_t; + +#define fid_addr_ippref(_a) (_a)->ippref +#define fid_addr_prefix_length(_a) ip_prefix_len(&fid_addr_ippref(_a)) +#define fid_addr_ip_version(_a) ip_prefix_version(&fid_addr_ippref(_a)) +#define fid_addr_mac(_a) (_a)->mac +#define fid_addr_nsh(_a) (_a)->nsh +#define fid_addr_type(_a) (_a)->type +u8 *format_fid_address (u8 * s, va_list * args); + +typedef struct +{ + fid_address_t src; + fid_address_t dst; +} source_dest_t; + +#define sd_dst(_a) (_a)->dst +#define sd_src(_a) (_a)->src +#define sd_src_ippref(_a) fid_addr_ippref(&sd_src(_a)) +#define sd_dst_ippref(_a) fid_addr_ippref(&sd_dst(_a)) +#define sd_src_mac(_a) fid_addr_mac(&sd_src(_a)) +#define sd_dst_mac(_a) fid_addr_mac(&sd_dst(_a)) +#define sd_src_type(_a) fid_addr_type(&sd_src(_a)) +#define sd_dst_type(_a) fid_addr_type(&sd_dst(_a)) + +typedef struct +{ + u8 vni_mask_len; + u32 vni; + struct _gid_address_t *gid_addr; +} vni_t; + +#define vni_vni(_a) (_a)->vni +#define vni_mask_len(_a) (_a)->vni_mask_len +#define vni_gid(_a) (_a)->gid_addr + +typedef struct +{ + u32 spi; + u8 si; +} nsh_t; + +#define nsh_spi(_a) (_a)->spi +#define nsh_si(_a) (_a)->si + +typedef struct +{ + ip_address_t addr; + u32 bd; +} lcaf_arp_ndp_t; + +#define lcaf_arp_ndp_ip(_a) (_a)->addr +#define lcaf_arp_ndp_ip_ver(_a) ip_addr_version(&lcaf_arp_ndp_ip(_a)) +#define lcaf_arp_ndp_ip4(_a) ip_addr_v4(&lcaf_arp_ndp_ip(_a)) +#define lcaf_arp_ndp_ip6(_a) ip_addr_v6(&lcaf_arp_ndp_ip(_a)) +#define lcaf_arp_ndp_bd(_a) (_a)->bd + +typedef struct +{ + /* the union needs to be at the beginning! */ + union + { + source_dest_t sd; + lcaf_arp_ndp_t arp_ndp; + vni_t uni; + }; + u8 type; +} lcaf_t; + +#define lcaf_type(_a) (_a)->type +#define lcaf_vni(_a) vni_vni(& (_a)->uni) +#define lcaf_vni_len(_a) vni_mask_len(& (_a)->uni) + +/* might want to expand this in the future :) */ +typedef struct _gid_address_t +{ + union + { + ip_prefix_t ippref; + lcaf_t lcaf; + u8 mac[6]; + source_dest_t sd; + lcaf_arp_ndp_t arp_ndp; + nsh_t nsh; + }; + u8 type; + u32 vni; + u8 vni_mask; +} gid_address_t; + +u16 ip4_address_size_to_put (); +u16 ip6_address_size_to_put (); +u32 ip4_address_put (u8 * b, ip4_address_t * a); +u32 ip6_address_put (u8 * b, ip6_address_t * a); + +u16 ip_address_size_to_write (ip_address_t * a); +u16 ip_address_iana_afi (ip_address_t * a); +u8 ip_address_max_len (u8 ver); +u32 ip_address_put (u8 * b, ip_address_t * a); + +/* LISP AFI codes */ +typedef enum +{ + LISP_AFI_NO_ADDR, + LISP_AFI_IP, + LISP_AFI_IP6, + LISP_AFI_LCAF = 16387, + LISP_AFI_MAC = 16389 +} lisp_afi_e; + +u8 *format_gid_address (u8 * s, va_list * args); +uword unformat_gid_address (unformat_input_t * input, va_list * args); +int gid_address_cmp (gid_address_t * a1, gid_address_t * a2); +void gid_address_free (gid_address_t * a); + +u16 gid_address_size_to_put (gid_address_t * a); +u16 gid_address_put (u8 * b, gid_address_t * gid); +u8 gid_address_len (gid_address_t * a); +void *gid_address_cast (gid_address_t * gid, gid_address_type_t type); +void gid_address_copy (gid_address_t * dst, gid_address_t * src); +u32 gid_address_parse (u8 * offset, gid_address_t * a); +void gid_address_ip_set (gid_address_t * dst, void *src, u8 version); + +#define gid_address_type(_a) (_a)->type +#define gid_address_ippref(_a) (_a)->ippref +#define gid_address_ippref_len(_a) (_a)->ippref.len +#define gid_address_ip(_a) ip_prefix_addr(&gid_address_ippref(_a)) +#define gid_address_ip_version(_a) ip_addr_version(&gid_address_ip(_a)) +#define gid_address_lcaf(_a) (_a)->lcaf +#define gid_address_mac(_a) (_a)->mac +#define gid_address_nsh(_a) (_a)->nsh +#define gid_address_nsh_spi(_a) nsh_spi(&gid_address_nsh(_a)) +#define gid_address_nsh_si(_a) nsh_si(&gid_address_nsh(_a)) +#define gid_address_vni(_a) (_a)->vni +#define gid_address_vni_mask(_a) (_a)->vni_mask +#define gid_address_sd_dst_ippref(_a) sd_dst_ippref(&(_a)->sd) +#define gid_address_sd_src_ippref(_a) sd_src_ippref(&(_a)->sd) +#define gid_address_sd_dst_mac(_a) sd_dst_mac(&(_a)->sd) +#define gid_address_sd_src_mac(_a) sd_src_mac(&(_a)->sd) +#define gid_address_sd(_a) (_a)->sd +#define gid_address_sd_src(_a) sd_src(&gid_address_sd(_a)) +#define gid_address_sd_dst(_a) sd_dst(&gid_address_sd(_a)) +#define gid_address_sd_src_type(_a) sd_src_type(&gid_address_sd(_a)) +#define gid_address_sd_dst_type(_a) sd_dst_type(&gid_address_sd(_a)) +#define gid_address_arp_ndp(_a) (_a)->arp_ndp +#define gid_address_arp_ndp_bd(_a) lcaf_arp_ndp_bd(&gid_address_arp_ndp(_a)) +#define gid_address_arp_ndp_ip(_a) lcaf_arp_ndp_ip(&gid_address_arp_ndp(_a)) +#define gid_address_arp_ip4(_a) lcaf_arp_ndp_ip4(&gid_address_arp_ndp(_a)) +#define gid_address_ndp_ip6(_a) lcaf_arp_ndp_ip6(&gid_address_arp_ndp(_a)) +#define gid_address_ndp_bd gid_address_arp_ndp_bd +#define gid_address_arp_bd gid_address_arp_ndp_bd + +/* 'sub'address functions */ +#define foreach_gid_address_type_fcns \ + _(no_addr) \ + _(ip_prefix) \ + _(lcaf) \ + _(mac) \ + _(nsh) \ + _(sd) + +/* *INDENT-OFF* */ +#define _(_n) \ +u16 _n ## _size_to_write (void * pref); \ +u16 _n ## _write (u8 * p, void * pref); \ +u8 _n ## _length (void *a); \ +void * _n ## _cast (gid_address_t * a); \ +void _n ## _copy (void * dst , void * src); + +foreach_gid_address_type_fcns +#undef _ +/* *INDENT-ON* */ + +always_inline u64 +mac_to_u64 (u8 * m) +{ + return (*((u64 *) m) & 0xffffffffffff); +} + +typedef struct +{ + /* mark locator as local as opposed to remote */ + u8 local; + u8 state; + union + { + u32 sw_if_index; + gid_address_t address; + }; + u8 priority; + u8 weight; + u8 mpriority; + u8 mweight; + u8 probed; +} locator_t; + +u32 locator_parse (void *ptr, locator_t * loc); +void locator_copy (locator_t * dst, locator_t * src); +u32 locator_cmp (locator_t * l1, locator_t * l2); +void locator_free (locator_t * l); + +typedef struct +{ + /* locator-set name */ + u8 *name; + + /* vector of locator indices */ + u32 *locator_indices; + u8 local; +} locator_set_t; + +typedef struct +{ + gid_address_t eid; + + /* index of local locator set */ + union + { + u32 locator_set_index; + locator_t *locators; /* used for map register message */ + }; + + u32 ttl; + u8 action; + + u8 authoritative:1; + u8 local:1; + /* valid only for remote mappings */ + u8 is_static:1; + u8 pitr_set:1; + u8 nsh_set:1; + u8 almost_expired:1; + u8 delete_after_expiration:1; + u8 rsvd:1; + + u8 *key; + lisp_key_type_t key_id; + u8 timer_set; + u32 timer_handle; + counter_t packets; +} mapping_t; + +uword +unformat_negative_mapping_action (unformat_input_t * input, va_list * args); +u8 *format_negative_mapping_action (u8 *, va_list * args); + +typedef struct locator_pair +{ + /* local and remote locators (underlay attachment points) */ + ip_address_t lcl_loc; + ip_address_t rmt_loc; + + u8 priority; + u8 weight; +} locator_pair_t; + +void +build_src_dst (gid_address_t * sd, gid_address_t * src, gid_address_t * dst); + +void gid_address_from_ip (gid_address_t * g, ip_address_t * ip); +void gid_to_dp_address (gid_address_t * g, dp_address_t * d); + +#endif /* VNET_LISP_GPE_LISP_TYPES_H_ */ + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/lisp/lisp-cp/lisp_types_api.c b/src/plugins/lisp/lisp-cp/lisp_types_api.c new file mode 100644 index 00000000000..795bd15f3e2 --- /dev/null +++ b/src/plugins/lisp/lisp-cp/lisp_types_api.c @@ -0,0 +1,88 @@ +/* + *------------------------------------------------------------------ + * + * Copyright (c) 2020 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------ + */ + +#include +#include +#include + +int +unformat_lisp_eid_api (gid_address_t * dst, u32 vni, const vl_api_eid_t * eid) +{ + switch (eid->type) + { + case EID_TYPE_API_PREFIX: /* ip prefix */ + gid_address_type (dst) = GID_ADDR_IP_PREFIX; + ip_address_decode2 (&eid->address.prefix.address, &dst->ippref.addr); + gid_address_ippref_len (dst) = eid->address.prefix.len; + ip_prefix_normalize (&gid_address_ippref (dst)); + break; + case EID_TYPE_API_MAC: /* l2 mac */ + gid_address_type (dst) = GID_ADDR_MAC; + mac_address_decode (eid->address.mac, (mac_address_t *) gid_address_mac (dst)); + break; + default: + /* unknown type */ + return VNET_API_ERROR_INVALID_VALUE; + } + + gid_address_vni (dst) = clib_net_to_host_u32 (vni); + + return 0; +} + +void +lisp_fid_put_api (vl_api_eid_t * eid, const fid_address_t * fid) +{ + switch (fid_addr_type (fid)) + { + case FID_ADDR_IP_PREF: + ip_prefix_encode2 (&fid_addr_ippref (fid), &eid->address.prefix); + eid->type = EID_TYPE_API_PREFIX; + break; + + case FID_ADDR_MAC: + mac_address_encode ((mac_address_t *) fid_addr_mac (fid), eid->address.mac); + eid->type = EID_TYPE_API_MAC; + break; + + default: + clib_warning ("Unknown FID type %d!", fid_addr_type (fid)); + break; + } +} + +void +lisp_gid_put_api (vl_api_eid_t * eid, const gid_address_t * gid) +{ + switch (gid_address_type (gid)) + { + case GID_ADDR_IP_PREFIX: + ip_prefix_encode2 (&gid_address_ippref (gid), &eid->address.prefix); + eid->type = EID_TYPE_API_PREFIX; + break; + + case GID_ADDR_MAC: + mac_address_encode ((mac_address_t *) gid_address_mac (gid), eid->address.mac); + eid->type = EID_TYPE_API_MAC; + break; + + default: + clib_warning ("Unknown GID type %d!", gid_address_type (gid)); + break; + } +} diff --git a/src/plugins/lisp/lisp-cp/lisp_types_api.h b/src/plugins/lisp/lisp-cp/lisp_types_api.h new file mode 100644 index 00000000000..6f48281d81f --- /dev/null +++ b/src/plugins/lisp/lisp-cp/lisp_types_api.h @@ -0,0 +1,26 @@ +/* + *------------------------------------------------------------------ + * + * Copyright (c) 2020 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------ + */ + +#include +#include + +int unformat_lisp_eid_api (gid_address_t * dst, u32 vni, const vl_api_eid_t * eid); + +void lisp_fid_put_api (vl_api_eid_t * eid, const fid_address_t * fid); + +void lisp_gid_put_api (vl_api_eid_t * eid, const gid_address_t * gid); diff --git a/src/plugins/lisp/lisp-cp/one.api b/src/plugins/lisp/lisp-cp/one.api new file mode 100644 index 00000000000..4df5faf5a5f --- /dev/null +++ b/src/plugins/lisp/lisp-cp/one.api @@ -0,0 +1,1031 @@ +/* + * Copyright (c) 2015-2017 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +option version = "2.0.0"; + +import "vnet/interface_types.api"; +import "plugins/lisp/lisp-cp/lisp_types.api"; + +/** \brief add or delete locator_set + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param is_add - add address if non-zero, else delete + @param locator_set_name - locator name + @param locator_num - number of locators + @param locators - locator records +*/ +define one_add_del_locator_set +{ + u32 client_index; + u32 context; + bool is_add [default=true]; + string locator_set_name[64]; + u32 locator_num; + vl_api_local_locator_t locators[locator_num]; +}; + +/** \brief Reply for locator_set add/del + @param context - returned sender context, to match reply w/ request + @param retval - return code + @param ls_index - locator set index +*/ +define one_add_del_locator_set_reply +{ + u32 context; + i32 retval; + u32 ls_index; +}; + +/** \brief add or delete locator for locator set + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param is_add - add address if non-zero, else delete + @param locator_set_name - name of locator_set to add/del locator + @param sw_if_index - index of the interface + @param priority - priority of the locator + @param weight - weight of the locator +*/ +autoreply define one_add_del_locator +{ + u32 client_index; + u32 context; + bool is_add [default=true]; + string locator_set_name[64]; + vl_api_interface_index_t sw_if_index; + u8 priority; + u8 weight; +}; + + +/** \brief add or delete ONE eid-table + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param is_add - add address if non-zero, else delete + @param eid - endpoint identifier + @param locator_set_name - name of locator_set to add/del eid-table + @param vni - virtual network instance + @param key - secret key +*/ +autoreply define one_add_del_local_eid +{ + u32 client_index; + u32 context; + bool is_add [default=true]; + vl_api_eid_t eid; + string locator_set_name[64]; + u32 vni; + vl_api_hmac_key_t key; +}; + +/** \brief Set TTL for map register messages + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param ttl - time to live +*/ +autoreply define one_map_register_set_ttl +{ + u32 client_index; + u32 context; + u32 ttl; +}; + +/** \brief Get TTL for map register messages + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request +*/ +define show_one_map_register_ttl +{ + u32 client_index; + u32 context; +}; + +/** \brief Contains current TTL for map register messages + @param client_index - opaque cookie to identify the sender + @param retval - return code + @param ttl - time to live +*/ +define show_one_map_register_ttl_reply +{ + u32 context; + i32 retval; + u32 ttl; +}; + +/** \brief Add/delete map server + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param is_add - add address if non-zero; delete otherwise + @param is_ipv6 - if non-zero the address is ipv6, else ipv4 + @param ip_address - map server IP address +*/ +autoreply define one_add_del_map_server +{ + u32 client_index; + u32 context; + bool is_add [default=true]; + vl_api_address_t ip_address; +}; + +/** \brief add or delete map-resolver + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param is_add - add address if non-zero, else delete + @param is_ipv6 - if non-zero the address is ipv6, else ipv4 + @param ip_address - array of address bytes +*/ +autoreply define one_add_del_map_resolver +{ + u32 client_index; + u32 context; + bool is_add [default=true]; + vl_api_address_t ip_address; +}; + +/** \brief enable or disable ONE feature + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param is_enable - enable protocol if non-zero, else disable +*/ +autoreply define one_enable_disable +{ + u32 client_index; + u32 context; + bool is_enable [default=true]; +}; + +/** \brief configure or delete ONE NSH mapping + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param ls_name - locator set name + @param is_add - add locator set if non-zero; delete otherwise +*/ +autoreply define one_nsh_set_locator_set +{ + u32 client_index; + u32 context; + bool is_add [default=true]; + string ls_name[64]; +}; + +/** \brief configure or disable ONE PITR node + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param ls_name - locator set name + @param is_add - add locator set if non-zero, else disable pitr +*/ +autoreply define one_pitr_set_locator_set +{ + u32 client_index; + u32 context; + bool is_add [default=true]; + string ls_name[64]; +}; + +/** \brief configure or disable use of PETR + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param is_ip4 - Address is IPv4 if set and IPv6 otherwise + @param address - PETR IP address + @param is_add - add locator set if non-zero, else disable PETR +*/ +autoreply define one_use_petr +{ + u32 client_index; + u32 context; + vl_api_address_t ip_address; + bool is_add [default=true]; +}; + +/** \brief Request for ONE PETR status + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request +*/ +define show_one_use_petr +{ + u32 client_index; + u32 context; +}; + +/** \brief ONE PETR status, enable or disable + @param context - sender context, to match reply w/ request + @param enable - ONE PETR enable if non-zero, else disable + @param is_ip4 - Address is IPv4 if non-zero, else IPv6 + @param address - PETR IP address +*/ +define show_one_use_petr_reply +{ + u32 context; + i32 retval; + bool status; + vl_api_address_t ip_address; +}; + +/** \brief Get state of ONE RLOC probing + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request +*/ +define show_one_rloc_probe_state +{ + u32 client_index; + u32 context; +}; + +/** \brief Reply for show_one_rloc_probe_state + @param context - returned sender context, to match reply w/ request + @param retval - return code + @param is_enable - state of RLOC probing +*/ +define show_one_rloc_probe_state_reply +{ + u32 context; + i32 retval; + bool is_enable; +}; + +/** \brief enable/disable ONE RLOC probing + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param is_enable - enable if non-zero; disable otherwise +*/ +autoreply define one_rloc_probe_enable_disable +{ + u32 client_index; + u32 context; + bool is_enable [default=true]; +}; + +/** \brief enable/disable ONE map-register + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param is_enable - enable if non-zero; disable otherwise +*/ +autoreply define one_map_register_enable_disable +{ + u32 client_index; + u32 context; + bool is_enable [default=true]; +}; + +/** \brief Get state of ONE map-register + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request +*/ +define show_one_map_register_state +{ + u32 client_index; + u32 context; +}; + +/** \brief Reply for show_one_map_register_state + @param context - returned sender context, to match reply w/ request + @param retval - return code +*/ +define show_one_map_register_state_reply +{ + u32 context; + i32 retval; + bool is_enable; +}; + +enum one_map_mode +{ + ONE_MAP_MODE_API_DST_ONLY = 0, + ONE_MAP_MODE_API_SRC_DST = 1, +}; + +/** \brief set ONE map-request mode. Based on configuration VPP will send + src/dest or just normal destination map requests. + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param mode - new map-request mode. Supported values are: + 0 - destination only + 1 - source/destination +*/ +autoreply define one_map_request_mode +{ + u32 client_index; + u32 context; + vl_api_one_map_mode_t mode; +}; + +/** \brief Request for ONE map-request mode + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request +*/ +define show_one_map_request_mode +{ + u32 client_index; + u32 context; +}; + +/** \brief Reply for show_one_map_request_mode + @param context - returned sender context, to match reply w/ request + @param retval - return code + @param mode - map-request mode +*/ +define show_one_map_request_mode_reply +{ + u32 context; + i32 retval; + vl_api_one_map_mode_t mode; +}; + +/** \brief add or delete remote static mapping + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param is_add - add address if non-zero, else delete + @param is_src_dst - flag indicating src/dst based routing policy + @param del_all - if set, delete all remote mappings + @param vni - virtual network instance + @param action - negative map-reply action + @param deid - dst EID + @param seid - src EID, valid only if is_src_dst is enabled + @param rloc_num - number of remote locators + @param rlocs - remote locator records +*/ +autoreply define one_add_del_remote_mapping +{ + u32 client_index; + u32 context; + bool is_add [default=true]; + bool is_src_dst; + bool del_all; + u32 vni; + u8 action; + vl_api_eid_t deid; + vl_api_eid_t seid; + u32 rloc_num; + vl_api_remote_locator_t rlocs[rloc_num]; +}; + +typedef one_l2_arp_entry +{ + vl_api_mac_address_t mac; + vl_api_ip4_address_t ip4; +}; + +/** \brief Add/delete L2 ARP entries + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param is_add - add if non-zero; delete otherwise + @param bd - bridge domain + @param entry - ARP entry +*/ +autoreply define one_add_del_l2_arp_entry +{ + u32 client_index; + u32 context; + bool is_add [default=true]; + u32 bd; + vl_api_one_l2_arp_entry_t entry; +}; + +/** \brief Request for L2 ARP entries from specified bridge domain + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param bd - bridge domain +*/ +define one_l2_arp_entries_get +{ + u32 client_index; + u32 context; + u32 bd; +}; + +/** \brief Reply with L2 ARP entries from specified bridge domain + @param context - sender context, to match reply w/ request + @param retval - error code + @param count - number of elements in the list + @param vl_api_one_arp_entry_t - list of entries +*/ +define one_l2_arp_entries_get_reply +{ + u32 context; + i32 retval; + u32 count; + vl_api_one_l2_arp_entry_t entries[count]; +}; + +typedef one_ndp_entry +{ + vl_api_mac_address_t mac; + vl_api_ip6_address_t ip6; +}; + + +autoreply define one_add_del_ndp_entry +{ + u32 client_index; + u32 context; + bool is_add [default=true]; + u32 bd; + vl_api_one_ndp_entry_t entry; +}; + +define one_ndp_entries_get +{ + u32 client_index; + u32 context; + u32 bd; +}; + +define one_ndp_entries_get_reply +{ + u32 context; + i32 retval; + u32 count; + vl_api_one_ndp_entry_t entries[count]; +}; + +/** \brief Set ONE transport protocol + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param protocol - supported values: + 1: UDP based LISP (default) + 2: binary API +*/ +autoreply define one_set_transport_protocol +{ + u32 client_index; + u32 context; + u8 protocol; +}; + +define one_get_transport_protocol +{ + u32 client_index; + u32 context; +}; + +define one_get_transport_protocol_reply +{ + u32 context; + i32 retval; + u8 protocol; +}; + +/** \brief Request for list of bridge domains used by neighbor discovery + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request +*/ +define one_ndp_bd_get +{ + u32 client_index; + u32 context; +}; + +/** \brief Reply with list of bridge domains used by neighbor discovery + @param context - sender context, to match reply w/ request + @param count - number of elements in the list + @param bridge_domains - list of BDs +*/ +define one_ndp_bd_get_reply +{ + u32 context; + i32 retval; + u32 count; + u32 bridge_domains[count]; +}; + +/** \brief Request for list of bridge domains used by L2 ARP table + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request +*/ +define one_l2_arp_bd_get +{ + u32 client_index; + u32 context; +}; + +/** \brief Reply with list of bridge domains used by L2 ARP table + @param context - sender context, to match reply w/ request + @param count - number of elements in the list + @param bridge_domains - list of BDs +*/ +define one_l2_arp_bd_get_reply +{ + u32 context; + i32 retval; + u32 count; + u32 bridge_domains[count]; +}; + +/** \brief add or delete ONE adjacency adjacency + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param is_add - add address if non-zero, else delete + @param vni - virtual network instance + @param reid - remote EID + @param leid - local EID +*/ +autoreply define one_add_del_adjacency +{ + u32 client_index; + u32 context; + u8 is_add; + u32 vni; + vl_api_eid_t reid; + vl_api_eid_t leid; +}; + +/** \brief add or delete map request itr rlocs + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param is_add - add address if non-zero, else delete + @param locator_set_name - locator set name +*/ +autoreply define one_add_del_map_request_itr_rlocs +{ + u32 client_index; + u32 context; + bool is_add [default=true]; + string locator_set_name[64]; +}; + +/** \brief map/unmap vni/bd_index to vrf + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param is_add - add or delete mapping + @param dp_table - virtual network id/bridge domain index + @param vrf - vrf + @param is_l2 - is l2 +*/ +autoreply define one_eid_table_add_del_map +{ + u32 client_index; + u32 context; + bool is_add [default=true]; + u32 vni; + u32 dp_table; + bool is_l2; +}; + +/** \brief Request for map one locator status + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param locator_set_index - index of locator_set + @param ls_name - locator set name + @param is_index_set - flag indicating whether ls_name or ls_index is set + */ +define one_locator_dump +{ + u32 client_index; + u32 context; + u32 ls_index; + string ls_name[64]; + bool is_index_set; +}; + +/** \brief ONE locator_set status + @param local - if is set, then locator is local + @param locator_set_name - name of the locator_set + @param sw_if_index - sw_if_index of the locator + @param priority - locator priority + @param weight - locator weight + */ +define one_locator_details +{ + u32 context; + u8 local; + vl_api_interface_index_t sw_if_index; + vl_api_address_t ip_address; + u8 priority; + u8 weight; +}; + +/** \brief ONE locator_set status + @param context - sender context, to match reply w/ request + @param ls_index - locator set index + @param ls_name - name of the locator set + */ +define one_locator_set_details +{ + u32 context; + u32 ls_index; + string ls_name[64]; +}; + +enum one_filter +{ + ONE_FILTER_API_ALL = 0, + ONE_FILTER_API_LOCAL = 1, + ONE_FILTER_API_REMOTE = 2, +}; + +/** \brief Request for locator_set summary status + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param filter - filter type + Supported values: + 0: all locator sets + 1: local locator sets + 2: remote locator sets + */ +define one_locator_set_dump +{ + u32 client_index; + u32 context; + vl_api_one_filter_t filter; +}; + +/** \brief Dump ONE eid-table + @param context - sender context, to match reply w/ request + @param locator_set_index - index of locator_set, if ~0 then the mapping + is negative + @param action - negative map request action + @param is_local - local if non-zero, else remote + @param is_src_dst - EID is type of source/destination + @param deid - dst EID + @param seid - src EID + @param vni - virtual network instance + @param ttl - time to live + @param authoritative - authoritative + @param key - secret key +*/ + +// FIXME: action, authoritative + +define one_eid_table_details +{ + u32 context; + u32 locator_set_index; + u8 action; + bool is_local; + bool is_src_dst; + u32 vni; + vl_api_eid_t deid; + vl_api_eid_t seid; + u32 ttl; + u8 authoritative; + vl_api_hmac_key_t key; +}; + +/** \brief Request for eid table summary status + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param eid_set - if non-zero request info about specific mapping + @param vni - virtual network instance; valid only if eid_set != 0 + @param eid - endpoint identifier + @param filter - filter type; + Support values: + 0: all eid + 1: local eid + 2: remote eid + */ +define one_eid_table_dump +{ + u32 client_index; + u32 context; + bool eid_set; + u32 vni; + vl_api_eid_t eid; + vl_api_one_filter_t filter; +}; + +/** \brief ONE adjacency + @param reid - remote EID + @param leid - local EID + */ +typedef one_adjacency +{ + vl_api_eid_t reid; + vl_api_eid_t leid; +}; + +/** \brief ONE adjacency reply + @param count - number of adjacencies + @param adjacencies - array of adjacencies + */ +define one_adjacencies_get_reply +{ + u32 context; + i32 retval; + u32 count; + vl_api_one_adjacency_t adjacencies[count]; +}; + +/** \brief Request for ONE adjacencies + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param vni - filter adjacencies by VNI + */ +define one_adjacencies_get +{ + u32 client_index; + u32 context; + u32 vni; +}; + +/** \brief Shows relationship between vni and vrf/bd + @param dp_table - VRF index or bridge domain index + @param vni - virtual network instance + */ +define one_eid_table_map_details +{ + u32 context; + u32 vni; + u32 dp_table; +}; + +/** \brief Request for one_eid_table_map_details + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param is_l2 - if set dump vni/bd mappings else vni/vrf + */ +define one_eid_table_map_dump +{ + u32 client_index; + u32 context; + bool is_l2; +}; + +/** \brief Dumps all VNIs used in mappings + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + */ +define one_eid_table_vni_dump +{ + u32 client_index; + u32 context; +}; + +/** \brief reply to one_eid_table_vni_dump + @param context - sender context, to match reply w/ request + @param vni - virtual network instance + */ +define one_eid_table_vni_details +{ + u32 context; + u32 vni; +}; + +/** \brief ONE map resolver status + @param is_ipv6 - if non-zero the address is ipv6, else ipv4 + @param ip_address - array of address bytes + */ +define one_map_resolver_details +{ + u32 context; + vl_api_address_t ip_address; +}; + +/** \brief Request for map resolver summary status + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + */ +define one_map_resolver_dump +{ + u32 client_index; + u32 context; +}; + +/** \brief ONE map server details + @param is_ipv6 - if non-zero the address is ipv6, else ipv4 + @param ip_address - array of address bytes + */ +define one_map_server_details +{ + u32 context; + vl_api_address_t ip_address; +}; + +/** \brief Request for map server summary status + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + */ +define one_map_server_dump +{ + u32 client_index; + u32 context; +}; + +/** \brief Request for ONE status + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request +*/ +define show_one_status +{ + u32 client_index; + u32 context; +}; + +/** \brief ONE status + @param context - sender context, to match reply w/ request + @param feature_status - enabled if non-zero, else disabled + @param gpe_status - enabled if non-zero, else disabled +*/ +define show_one_status_reply +{ + u32 context; + i32 retval; + bool feature_status; + bool gpe_status; +}; + +/** \brief Get ONE map request itr rlocs status + @param context - sender context, to match reply w/ request + @param locator_set_name - name of the locator_set + */ +define one_get_map_request_itr_rlocs +{ + u32 client_index; + u32 context; +}; + +/** \brief Request for map request itr rlocs summary status + */ +define one_get_map_request_itr_rlocs_reply +{ + u32 context; + i32 retval; + string locator_set_name[64]; +}; + +/** \brief Request for ONE NSH mapping + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request +*/ +define show_one_nsh_mapping +{ + u32 client_index; + u32 context; +}; + +/** \brief Reply for ONE NSH mapping + @param context - sender context, to match reply w/ request + @param is_set - is ONE NSH mapping set + @param locator_set_name - name of the locator_set if NSH mapping is set +*/ +define show_one_nsh_mapping_reply +{ + u32 context; + i32 retval; + bool is_set; + string locator_set_name[64]; +}; + +/** \brief Request for ONE PITR status + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request +*/ +define show_one_pitr +{ + u32 client_index; + u32 context; +}; + +/** \brief Status of ONE PITR, enable or disable + @param context - sender context, to match reply w/ request + @param status - ONE PITR enable if non-zero, else disable + @param locator_set_name - name of the locator_set +*/ +define show_one_pitr_reply +{ + u32 context; + i32 retval; + bool status; + string locator_set_name[64]; +}; + +define one_stats_dump +{ + u32 client_index; + u32 context; +}; + +define one_stats_details +{ + u32 context; + u32 vni; + vl_api_eid_t deid; + vl_api_eid_t seid; + vl_api_address_t rloc; + vl_api_address_t lloc; + + u32 pkt_count; + u32 bytes; +}; + +autoreply define one_stats_flush +{ + u32 client_index; + u32 context; +}; + +autoreply define one_stats_enable_disable +{ + u32 client_index; + u32 context; + bool is_enable [default=true]; +}; + +define show_one_stats_enable_disable +{ + u32 client_index; + u32 context; +}; + +define show_one_stats_enable_disable_reply +{ + u32 context; + i32 retval; + bool is_enable; +}; + +autoreply define one_map_register_fallback_threshold +{ + u32 client_index; + u32 context; + u32 value; +}; + +define show_one_map_register_fallback_threshold +{ + u32 client_index; + u32 context; +}; + +define show_one_map_register_fallback_threshold_reply +{ + u32 context; + i32 retval; + u32 value; +}; + +autoreply define one_enable_disable_xtr_mode +{ + u32 client_index; + u32 context; + bool is_enable [default=true]; +}; + +define one_show_xtr_mode +{ + u32 client_index; + u32 context; +}; + +define one_show_xtr_mode_reply +{ + u32 context; + i32 retval; + bool is_enable; +}; + +autoreply define one_enable_disable_petr_mode +{ + u32 client_index; + u32 context; + bool is_enable [default=true]; +}; + +define one_show_petr_mode +{ + u32 client_index; + u32 context; +}; + +define one_show_petr_mode_reply +{ + u32 context; + i32 retval; + bool is_enable; +}; + +autoreply define one_enable_disable_pitr_mode +{ + u32 client_index; + u32 context; + bool is_enable [default=true]; +}; + +define one_show_pitr_mode +{ + u32 client_index; + u32 context; +}; + +define one_show_pitr_mode_reply +{ + u32 context; + i32 retval; + bool is_enable; +}; + +/* + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/lisp/lisp-cp/one_api.c b/src/plugins/lisp/lisp-cp/one_api.c new file mode 100644 index 00000000000..eb0b4c691b7 --- /dev/null +++ b/src/plugins/lisp/lisp-cp/one_api.c @@ -0,0 +1,1705 @@ +/* + *------------------------------------------------------------------ + * one_api.c - Overlay Network Engine API + * + * Copyright (c) 2016-2017 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------ + */ + +#include +#include + +#include +#include +#include +#include + +#include +#include + +/* define message IDs */ +#include +#include +#include + +/** + * Base message ID fot the plugin + */ +static u32 one_base_msg_id; +#define REPLY_MSG_ID_BASE one_base_msg_id + +#include + +#define REPLY_DETAILS(t, body) \ +do { \ + vl_api_registration_t * reg; \ + rv = vl_msg_api_pd_handler (mp, rv); \ + reg = vl_api_client_index_to_registration (mp->client_index); \ + if (!reg) \ + return; \ + \ + rmp = vl_msg_api_alloc (sizeof (*rmp)); \ + rmp->_vl_msg_id = ntohs((t)); \ + rmp->context = mp->context; \ + do {body;} while (0); \ + vl_api_send_msg (reg, (u8 *)&rmp); \ +} while(0); + +#define foreach_vpe_api_msg \ +_(ONE_ADD_DEL_LOCATOR_SET, one_add_del_locator_set) \ +_(ONE_ADD_DEL_LOCATOR, one_add_del_locator) \ +_(ONE_ADD_DEL_LOCAL_EID, one_add_del_local_eid) \ +_(ONE_ADD_DEL_MAP_RESOLVER, one_add_del_map_resolver) \ +_(ONE_ADD_DEL_MAP_SERVER, one_add_del_map_server) \ +_(ONE_ENABLE_DISABLE, one_enable_disable) \ +_(ONE_RLOC_PROBE_ENABLE_DISABLE, one_rloc_probe_enable_disable) \ +_(ONE_MAP_REGISTER_ENABLE_DISABLE, one_map_register_enable_disable) \ +_(ONE_MAP_REGISTER_FALLBACK_THRESHOLD, \ + one_map_register_fallback_threshold) \ +_(ONE_ADD_DEL_REMOTE_MAPPING, one_add_del_remote_mapping) \ +_(ONE_ADD_DEL_ADJACENCY, one_add_del_adjacency) \ +_(ONE_PITR_SET_LOCATOR_SET, one_pitr_set_locator_set) \ +_(ONE_NSH_SET_LOCATOR_SET, one_nsh_set_locator_set) \ +_(ONE_MAP_REQUEST_MODE, one_map_request_mode) \ +_(ONE_EID_TABLE_ADD_DEL_MAP, one_eid_table_add_del_map) \ +_(ONE_LOCATOR_SET_DUMP, one_locator_set_dump) \ +_(ONE_LOCATOR_DUMP, one_locator_dump) \ +_(ONE_EID_TABLE_DUMP, one_eid_table_dump) \ +_(ONE_MAP_RESOLVER_DUMP, one_map_resolver_dump) \ +_(ONE_MAP_SERVER_DUMP, one_map_server_dump) \ +_(ONE_EID_TABLE_MAP_DUMP, one_eid_table_map_dump) \ +_(ONE_EID_TABLE_VNI_DUMP, one_eid_table_vni_dump) \ +_(ONE_ADJACENCIES_GET, one_adjacencies_get) \ +_(ONE_MAP_REGISTER_SET_TTL, one_map_register_set_ttl) \ +_(SHOW_ONE_NSH_MAPPING, show_one_nsh_mapping) \ +_(SHOW_ONE_RLOC_PROBE_STATE, show_one_rloc_probe_state) \ +_(SHOW_ONE_MAP_REGISTER_STATE, show_one_map_register_state) \ +_(SHOW_ONE_MAP_REGISTER_TTL, show_one_map_register_ttl) \ +_(SHOW_ONE_MAP_REGISTER_FALLBACK_THRESHOLD, \ + show_one_map_register_fallback_threshold) \ +_(SHOW_ONE_STATUS, show_one_status) \ +_(ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \ + one_add_del_map_request_itr_rlocs) \ +_(ONE_GET_MAP_REQUEST_ITR_RLOCS, one_get_map_request_itr_rlocs) \ +_(SHOW_ONE_PITR, show_one_pitr) \ +_(SHOW_ONE_MAP_REQUEST_MODE, show_one_map_request_mode) \ +_(ONE_USE_PETR, one_use_petr) \ +_(SHOW_ONE_USE_PETR, show_one_use_petr) \ +_(SHOW_ONE_STATS_ENABLE_DISABLE, show_one_stats_enable_disable) \ +_(ONE_STATS_ENABLE_DISABLE, one_stats_enable_disable) \ +_(ONE_STATS_DUMP, one_stats_dump) \ +_(ONE_STATS_FLUSH, one_stats_flush) \ +_(ONE_L2_ARP_BD_GET, one_l2_arp_bd_get) \ +_(ONE_L2_ARP_ENTRIES_GET, one_l2_arp_entries_get) \ +_(ONE_ADD_DEL_L2_ARP_ENTRY, one_add_del_l2_arp_entry) \ +_(ONE_ADD_DEL_NDP_ENTRY, one_add_del_ndp_entry) \ +_(ONE_NDP_BD_GET, one_ndp_bd_get) \ +_(ONE_NDP_ENTRIES_GET, one_ndp_entries_get) \ +_(ONE_SET_TRANSPORT_PROTOCOL, one_set_transport_protocol) \ +_(ONE_GET_TRANSPORT_PROTOCOL, one_get_transport_protocol) \ +_(ONE_ENABLE_DISABLE_XTR_MODE, one_enable_disable_xtr_mode) \ +_(ONE_SHOW_XTR_MODE, one_show_xtr_mode) \ +_(ONE_ENABLE_DISABLE_PITR_MODE, one_enable_disable_pitr_mode) \ +_(ONE_SHOW_PITR_MODE, one_show_pitr_mode) \ +_(ONE_ENABLE_DISABLE_PETR_MODE, one_enable_disable_petr_mode) \ +_(ONE_SHOW_PETR_MODE, one_show_petr_mode) \ + + +static locator_t * +unformat_one_locs (vl_api_remote_locator_t * rmt_locs, u32 rloc_num) +{ + u32 i; + locator_t *locs = 0, loc; + vl_api_remote_locator_t *r; + + for (i = 0; i < rloc_num; i++) + { + /* remote locators */ + r = &rmt_locs[i]; + clib_memset (&loc, 0, sizeof (loc)); + ip_address_decode2 (&r->ip_address, &loc.address.ippref.addr); + loc.address.ippref.len = + ip_address_max_len (loc.address.ippref.addr.version); + + loc.priority = r->priority; + loc.weight = r->weight; + + vec_add1 (locs, loc); + } + return locs; +} + +static void +vl_api_one_map_register_set_ttl_t_handler (vl_api_one_map_register_set_ttl_t * + mp) +{ + vl_api_one_map_register_set_ttl_reply_t *rmp; + int rv = 0; + + mp->ttl = clib_net_to_host_u32 (mp->ttl); + rv = vnet_lisp_map_register_set_ttl (mp->ttl); + + REPLY_MACRO (VL_API_ONE_MAP_REGISTER_SET_TTL_REPLY); +} + +static void + vl_api_show_one_map_register_ttl_t_handler + (vl_api_show_one_map_register_ttl_t * mp) +{ + vl_api_show_one_map_register_ttl_reply_t *rmp; + int rv = 0; + + u32 ttl = vnet_lisp_map_register_get_ttl (); + /* *INDENT-OFF* */ + REPLY_MACRO2 (VL_API_SHOW_ONE_MAP_REGISTER_TTL_REPLY, + ({ + rmp->ttl = clib_host_to_net_u32 (ttl); + })); + /* *INDENT-ON* */ +} + +static void +vl_api_one_add_del_locator_set_t_handler (vl_api_one_add_del_locator_set_t * + mp) +{ + vl_api_one_add_del_locator_set_reply_t *rmp; + int rv = 0; + vnet_lisp_add_del_locator_set_args_t _a, *a = &_a; + locator_t locator; + vl_api_local_locator_t *ls_loc; + u32 ls_index = ~0, locator_num; + u8 *locator_name = NULL; + int i; + + clib_memset (a, 0, sizeof (a[0])); + + mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0; + locator_name = format (0, "%s", mp->locator_set_name); + vec_terminate_c_string (locator_name); + + a->name = locator_name; + a->is_add = mp->is_add; + a->local = 1; + locator_num = clib_net_to_host_u32 (mp->locator_num); + + clib_memset (&locator, 0, sizeof (locator)); + for (i = 0; i < locator_num; i++) + { + ls_loc = &mp->locators[i]; + VALIDATE_SW_IF_INDEX (ls_loc); + + locator.sw_if_index = htonl (ls_loc->sw_if_index); + locator.priority = ls_loc->priority; + locator.weight = ls_loc->weight; + locator.local = 1; + vec_add1 (a->locators, locator); + } + + rv = vnet_lisp_add_del_locator_set (a, &ls_index); + + BAD_SW_IF_INDEX_LABEL; + + vec_free (locator_name); + vec_free (a->locators); + + /* *INDENT-OFF* */ + REPLY_MACRO2 (VL_API_ONE_ADD_DEL_LOCATOR_SET_REPLY, + ({ + rmp->ls_index = clib_host_to_net_u32 (ls_index); + })); + /* *INDENT-ON* */ +} + +static void +vl_api_one_add_del_locator_t_handler (vl_api_one_add_del_locator_t * mp) +{ + vl_api_one_add_del_locator_reply_t *rmp; + int rv = 0; + locator_t locator, *locators = NULL; + vnet_lisp_add_del_locator_set_args_t _a, *a = &_a; + u32 ls_index = ~0; + u8 *locator_name = NULL; + + clib_memset (&locator, 0, sizeof (locator)); + clib_memset (a, 0, sizeof (a[0])); + + locator.sw_if_index = ntohl (mp->sw_if_index); + locator.priority = mp->priority; + locator.weight = mp->weight; + locator.local = 1; + vec_add1 (locators, locator); + + mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0; + locator_name = format (0, "%s", mp->locator_set_name); + vec_terminate_c_string (locator_name); + + a->name = locator_name; + a->locators = locators; + a->is_add = mp->is_add; + a->local = 1; + + rv = vnet_lisp_add_del_locator (a, NULL, &ls_index); + + vec_free (locators); + vec_free (locator_name); + + REPLY_MACRO (VL_API_ONE_ADD_DEL_LOCATOR_REPLY); +} + +typedef struct +{ + u32 spi; + u8 si; +} __attribute__ ((__packed__)) lisp_nsh_api_t; + +static int +unformat_one_eid_api (gid_address_t * dst, u32 vni, vl_api_eid_t * eid) +{ + fib_prefix_t prefix; + + switch (eid->type) + { + case EID_TYPE_API_PREFIX: + ip_prefix_decode (&eid->address.prefix, &prefix); + gid_address_type (dst) = GID_ADDR_IP_PREFIX; + if (prefix.fp_proto == FIB_PROTOCOL_IP4) + gid_address_ip_set (dst, &prefix.fp_addr.ip4, AF_IP4); + if (prefix.fp_proto == FIB_PROTOCOL_IP6) + gid_address_ip_set (dst, &prefix.fp_addr.ip6, AF_IP6); + gid_address_ippref_len (dst) = prefix.fp_len; + ip_prefix_normalize (&gid_address_ippref (dst)); + break; + case EID_TYPE_API_MAC: + gid_address_type (dst) = GID_ADDR_MAC; + mac_address_decode (eid->address.mac, + (mac_address_t *) & gid_address_mac (dst)); + break; + case EID_TYPE_API_NSH: + gid_address_type (dst) = GID_ADDR_NSH; + gid_address_nsh_spi (dst) = clib_net_to_host_u32 (eid->address.nsh.spi); + gid_address_nsh_si (dst) = eid->address.nsh.si; + break; + default: + /* unknown type */ + return VNET_API_ERROR_INVALID_VALUE; + } + + gid_address_vni (dst) = vni; + + return 0; +} + +static void +fid_to_api_eid (fid_address_t * fid, vl_api_eid_t * eid) +{ + fib_prefix_t fib_prefix; + u32 eid_type; + + switch (fid_addr_type (fid)) + { + case FID_ADDR_IP_PREF: + eid_type = EID_TYPE_API_PREFIX; + ip_prefix_to_fib_prefix (&fid_addr_ippref (fid), &fib_prefix); + ip_prefix_encode (&fib_prefix, &eid->address.prefix); + break; + case FID_ADDR_MAC: + eid_type = EID_TYPE_API_MAC; + mac_address_encode ((mac_address_t *) fid_addr_mac (fid), + eid->address.mac); + break; + default: + /* unknown type */ + return; + } + + eid->type = eid_type; +} + +static void +vl_api_one_add_del_local_eid_t_handler (vl_api_one_add_del_local_eid_t * mp) +{ + vl_api_one_add_del_local_eid_reply_t *rmp; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + int rv = 0; + gid_address_t _eid, *eid = &_eid; + uword *p = NULL; + u32 locator_set_index = ~0, map_index = ~0; + vnet_lisp_add_del_mapping_args_t _a, *a = &_a; + u8 *name = NULL, *key = NULL; + clib_memset (a, 0, sizeof (a[0])); + clib_memset (eid, 0, sizeof (eid[0])); + + rv = unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni), &mp->eid); + if (rv) + goto out; + + if (gid_address_type (eid) == GID_ADDR_NSH) + { + rv = VNET_API_ERROR_INVALID_VALUE; + goto out; + } + + mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0; + name = format (0, "%s", mp->locator_set_name); + vec_terminate_c_string (name); + p = hash_get_mem (lcm->locator_set_index_by_name, name); + if (!p) + { + rv = VNET_API_ERROR_INVALID_VALUE; + goto out; + } + locator_set_index = p[0]; + + if (mp->key.id != KEY_ID_API_HMAC_NO_KEY) + key = format (0, "%s", mp->key.key); + + /* XXX treat batch configuration */ + a->is_add = mp->is_add; + gid_address_copy (&a->eid, eid); + a->locator_set_index = locator_set_index; + a->local = 1; + a->key = key; + a->key_id = mp->key.id; + + rv = vnet_lisp_add_del_local_mapping (a, &map_index); + +out: + vec_free (name); + vec_free (key); + gid_address_free (&a->eid); + + REPLY_MACRO (VL_API_ONE_ADD_DEL_LOCAL_EID_REPLY); +} + +static void + vl_api_one_eid_table_add_del_map_t_handler + (vl_api_one_eid_table_add_del_map_t * mp) +{ + vl_api_one_eid_table_add_del_map_reply_t *rmp; + int rv = 0; + rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni), + clib_net_to_host_u32 (mp->dp_table), + mp->is_l2, mp->is_add); +REPLY_MACRO (VL_API_ONE_EID_TABLE_ADD_DEL_MAP_REPLY)} + +static void +vl_api_one_add_del_map_server_t_handler (vl_api_one_add_del_map_server_t * mp) +{ + vl_api_one_add_del_map_server_reply_t *rmp; + int rv = 0; + ip_address_t addr; + + clib_memset (&addr, 0, sizeof (addr)); + + ip_address_decode2 (&mp->ip_address, &addr); + + rv = vnet_lisp_add_del_map_server (&addr, mp->is_add); + + REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_SERVER_REPLY); +} + +static void +vl_api_one_add_del_map_resolver_t_handler (vl_api_one_add_del_map_resolver_t + * mp) +{ + vl_api_one_add_del_map_resolver_reply_t *rmp; + int rv = 0; + vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a; + + clib_memset (a, 0, sizeof (a[0])); + + ip_address_decode2 (&mp->ip_address, &a->address); + + a->is_add = mp->is_add; + + rv = vnet_lisp_add_del_map_resolver (a); + + REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_RESOLVER_REPLY); +} + +static void + vl_api_one_map_register_enable_disable_t_handler + (vl_api_one_map_register_enable_disable_t * mp) +{ + vl_api_one_map_register_enable_disable_reply_t *rmp; + int rv = 0; + + vnet_lisp_map_register_enable_disable (mp->is_enable); + REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY); +} + +static void + vl_api_one_rloc_probe_enable_disable_t_handler + (vl_api_one_rloc_probe_enable_disable_t * mp) +{ + vl_api_one_rloc_probe_enable_disable_reply_t *rmp; + int rv = 0; + + vnet_lisp_rloc_probe_enable_disable (mp->is_enable); + REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY); +} + +static void +vl_api_one_enable_disable_t_handler (vl_api_one_enable_disable_t * mp) +{ + vl_api_one_enable_disable_reply_t *rmp; + int rv = 0; + + vnet_lisp_enable_disable (mp->is_enable); + REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY); +} + +static void + vl_api_show_one_map_request_mode_t_handler + (vl_api_show_one_map_request_mode_t * mp) +{ + int rv = 0; + vl_api_show_one_map_request_mode_reply_t *rmp; + + /* *INDENT-OFF* */ + REPLY_MACRO2(VL_API_SHOW_ONE_MAP_REQUEST_MODE_REPLY, + ({ + rmp->mode = vnet_lisp_get_map_request_mode (); + })); + /* *INDENT-ON* */ +} + +static void +vl_api_one_map_request_mode_t_handler (vl_api_one_map_request_mode_t * mp) +{ + vl_api_one_map_request_mode_reply_t *rmp; + int rv = 0; + + rv = vnet_lisp_set_map_request_mode (mp->mode); + + REPLY_MACRO (VL_API_ONE_MAP_REQUEST_MODE_REPLY); +} + +static void +vl_api_one_nsh_set_locator_set_t_handler (vl_api_one_nsh_set_locator_set_t + * mp) +{ + vl_api_one_nsh_set_locator_set_reply_t *rmp; + int rv = 0; + u8 *ls_name = 0; + + mp->ls_name[sizeof (mp->ls_name) - 1] = 0; + ls_name = format (0, "%s", mp->ls_name); + vec_terminate_c_string (ls_name); + rv = vnet_lisp_nsh_set_locator_set (ls_name, mp->is_add); + vec_free (ls_name); + + REPLY_MACRO (VL_API_ONE_PITR_SET_LOCATOR_SET_REPLY); +} + +static void +vl_api_one_pitr_set_locator_set_t_handler (vl_api_one_pitr_set_locator_set_t + * mp) +{ + vl_api_one_pitr_set_locator_set_reply_t *rmp; + int rv = 0; + u8 *ls_name = 0; + + mp->ls_name[sizeof (mp->ls_name) - 1] = 0; + ls_name = format (0, "%s", mp->ls_name); + vec_terminate_c_string (ls_name); + rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add); + vec_free (ls_name); + + REPLY_MACRO (VL_API_ONE_PITR_SET_LOCATOR_SET_REPLY); +} + +static void +vl_api_one_use_petr_t_handler (vl_api_one_use_petr_t * mp) +{ + vl_api_one_use_petr_reply_t *rmp; + int rv = 0; + ip_address_t addr; + + ip_address_decode2 (&mp->ip_address, &addr); + + rv = vnet_lisp_use_petr (&addr, mp->is_add); + + REPLY_MACRO (VL_API_ONE_USE_PETR_REPLY); +} + +static void +vl_api_show_one_use_petr_t_handler (vl_api_show_one_use_petr_t * mp) +{ + vl_api_show_one_use_petr_reply_t *rmp = NULL; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + mapping_t *m; + locator_set_t *ls = 0; + int rv = 0; + locator_t *loc = 0; + u8 status = 0; + gid_address_t addr; + + clib_memset (&addr, 0, sizeof (addr)); + status = lcm->flags & LISP_FLAG_USE_PETR; + if (status) + { + m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index); + if (~0 != m->locator_set_index) + { + ls = + pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index); + loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]); + gid_address_copy (&addr, &loc->address); + } + } + + /* *INDENT-OFF* */ + REPLY_MACRO2 (VL_API_SHOW_ONE_USE_PETR_REPLY, + { + rmp->status = status; + ip_address_t *ip = &gid_address_ip (&addr); + + ip_address_encode2 (ip, &rmp->ip_address); + }); + /* *INDENT-ON* */ +} + +static void + vl_api_one_add_del_map_request_itr_rlocs_t_handler + (vl_api_one_add_del_map_request_itr_rlocs_t * mp) +{ + vl_api_one_add_del_map_request_itr_rlocs_reply_t *rmp; + int rv = 0; + u8 *locator_set_name = NULL; + vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a; + + mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0; + locator_set_name = format (0, "%s", mp->locator_set_name); + vec_terminate_c_string (locator_set_name); + + a->is_add = mp->is_add; + a->locator_set_name = locator_set_name; + + rv = vnet_lisp_add_del_mreq_itr_rlocs (a); + + vec_free (locator_set_name); + + REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY); +} + +static void + vl_api_one_add_del_remote_mapping_t_handler + (vl_api_one_add_del_remote_mapping_t * mp) +{ + locator_t *rlocs = 0; + vl_api_one_add_del_remote_mapping_reply_t *rmp; + int rv = 0; + gid_address_t _eid, *eid = &_eid; + u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num); + + clib_memset (eid, 0, sizeof (eid[0])); + + rv = unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni), &mp->deid); + if (rv) + goto send_reply; + + rlocs = unformat_one_locs (mp->rlocs, rloc_num); + + if (!mp->is_add) + { + vnet_lisp_add_del_adjacency_args_t _a, *a = &_a; + clib_memset (a, 0, sizeof (a[0])); + gid_address_copy (&a->reid, eid); + a->is_add = 0; + rv = vnet_lisp_add_del_adjacency (a); + if (rv) + { + goto out; + } + } + + /* NOTE: for now this works as a static remote mapping, i.e., + * not authoritative and ttl infinite. */ + if (mp->is_add) + { + vnet_lisp_add_del_mapping_args_t _m_args, *m_args = &_m_args; + clib_memset (m_args, 0, sizeof (m_args[0])); + gid_address_copy (&m_args->eid, eid); + m_args->action = mp->action; + m_args->is_static = 1; + m_args->ttl = ~0; + m_args->authoritative = 0; + rv = vnet_lisp_add_mapping (m_args, rlocs, NULL, NULL); + } + else + rv = vnet_lisp_del_mapping (eid, NULL); + + if (mp->del_all) + vnet_lisp_clear_all_remote_adjacencies (); + +out: + vec_free (rlocs); +send_reply: + REPLY_MACRO (VL_API_ONE_ADD_DEL_REMOTE_MAPPING_REPLY); +} + +static void +vl_api_one_add_del_adjacency_t_handler (vl_api_one_add_del_adjacency_t * mp) +{ + vl_api_one_add_del_adjacency_reply_t *rmp; + vnet_lisp_add_del_adjacency_args_t _a, *a = &_a; + + int rv = 0; + clib_memset (a, 0, sizeof (a[0])); + + rv = + unformat_one_eid_api (&a->leid, clib_net_to_host_u32 (mp->vni), + &mp->leid); + rv |= + unformat_one_eid_api (&a->reid, clib_net_to_host_u32 (mp->vni), + &mp->reid); + + if (rv) + goto send_reply; + + a->is_add = mp->is_add; + rv = vnet_lisp_add_del_adjacency (a); + +send_reply: + REPLY_MACRO (VL_API_ONE_ADD_DEL_ADJACENCY_REPLY); +} + +static void +send_one_locator_details (lisp_cp_main_t * lcm, + locator_t * loc, vl_api_registration_t * reg, + u32 context) +{ + vl_api_one_locator_details_t *rmp; + + rmp = vl_msg_api_alloc (sizeof (*rmp)); + clib_memset (rmp, 0, sizeof (*rmp)); + rmp->_vl_msg_id = ntohs (VL_API_ONE_LOCATOR_DETAILS); + rmp->context = context; + + rmp->local = loc->local; + if (loc->local) + { + rmp->sw_if_index = ntohl (loc->sw_if_index); + } + else + { + ip_address_encode2 (&loc->address.ippref.addr, &rmp->ip_address); + } + rmp->priority = loc->priority; + rmp->weight = loc->weight; + + vl_api_send_msg (reg, (u8 *) rmp); +} + +static void +vl_api_one_locator_dump_t_handler (vl_api_one_locator_dump_t * mp) +{ + u8 *ls_name = 0; + vl_api_registration_t *reg; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + locator_set_t *lsit = 0; + locator_t *loc = 0; + u32 ls_index = ~0, *locit = 0; + uword *p = 0; + + reg = vl_api_client_index_to_registration (mp->client_index); + if (!reg) + return; + + if (mp->is_index_set) + ls_index = htonl (mp->ls_index); + else + { + /* make sure we get a proper C-string */ + mp->ls_name[sizeof (mp->ls_name) - 1] = 0; + ls_name = format (0, "%s", mp->ls_name); + vec_terminate_c_string (ls_name); + p = hash_get_mem (lcm->locator_set_index_by_name, ls_name); + if (!p) + goto out; + ls_index = p[0]; + } + + if (pool_is_free_index (lcm->locator_set_pool, ls_index)) + return; + + lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index); + + vec_foreach (locit, lsit->locator_indices) + { + loc = pool_elt_at_index (lcm->locator_pool, locit[0]); + send_one_locator_details (lcm, loc, reg, mp->context); + }; +out: + vec_free (ls_name); +} + +static void +send_one_locator_set_details (lisp_cp_main_t * lcm, + locator_set_t * lsit, + vl_api_registration_t * reg, u32 context, + u32 ls_index) +{ + vl_api_one_locator_set_details_t *rmp; + u8 *str = 0; + + rmp = vl_msg_api_alloc (sizeof (*rmp)); + clib_memset (rmp, 0, sizeof (*rmp)); + rmp->_vl_msg_id = ntohs (VL_API_ONE_LOCATOR_SET_DETAILS); + rmp->context = context; + + rmp->ls_index = htonl (ls_index); + if (lsit->local) + { + ASSERT (lsit->name != NULL); + strncpy ((char *) rmp->ls_name, (char *) lsit->name, + vec_len (lsit->name)); + } + else + { + str = format (0, "", ls_index); + strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str)); + vec_free (str); + } + + vl_api_send_msg (reg, (u8 *) rmp); +} + +static void +vl_api_one_locator_set_dump_t_handler (vl_api_one_locator_set_dump_t * mp) +{ + vl_api_registration_t *reg; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + locator_set_t *lsit = NULL; + u8 filter; + + reg = vl_api_client_index_to_registration (mp->client_index); + if (!reg) + return; + + filter = mp->filter; + /* *INDENT-OFF* */ + pool_foreach (lsit, lcm->locator_set_pool, + ({ + if (filter && !((1 == filter && lsit->local) || + (2 == filter && !lsit->local))) + { + continue; + } + send_one_locator_set_details (lcm, lsit, reg, mp->context, + lsit - lcm->locator_set_pool); + })); + /* *INDENT-ON* */ +} + +static void +send_one_eid_table_details (mapping_t * mapit, + vl_api_registration_t * reg, u32 context, + u8 filter) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + locator_set_t *ls = 0; + vl_api_one_eid_table_details_t *rmp = NULL; + gid_address_t *gid = NULL; + u32 eid_type; + fib_prefix_t fib_prefix; + + if (mapit->pitr_set || mapit->nsh_set) + return; + + switch (filter) + { + case ONE_FILTER_API_ALL: /* all mappings */ + break; + + case ONE_FILTER_API_LOCAL: /* local only */ + if (!mapit->local) + return; + break; + case ONE_FILTER_API_REMOTE: /* remote only */ + if (mapit->local) + return; + break; + default: + clib_warning ("Filter error, unknown filter: %d", filter); + return; + } + + gid = &mapit->eid; + + rmp = vl_msg_api_alloc (sizeof (*rmp)); + clib_memset (rmp, 0, sizeof (*rmp)); + rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_DETAILS); + + ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index); + if (vec_len (ls->locator_indices) == 0) + rmp->locator_set_index = ~0; + else + rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index); + + rmp->is_local = mapit->local; + rmp->ttl = clib_host_to_net_u32 (mapit->ttl); + rmp->action = mapit->action; + rmp->authoritative = mapit->authoritative; + + switch (gid_address_type (gid)) + { + case GID_ADDR_SRC_DST: + fid_to_api_eid (&gid_address_sd_src (gid), &rmp->seid); + fid_to_api_eid (&gid_address_sd_dst (gid), &rmp->deid); + break; + case GID_ADDR_IP_PREFIX: + eid_type = EID_TYPE_API_PREFIX; + rmp->seid.type = eid_type; + ip_prefix_to_fib_prefix (&gid_address_ippref (gid), &fib_prefix); + ip_prefix_encode (&fib_prefix, &rmp->seid.address.prefix); + break; + case GID_ADDR_MAC: + eid_type = EID_TYPE_API_MAC; + rmp->seid.type = eid_type; + mac_address_encode ((mac_address_t *) gid_address_mac (gid), + rmp->seid.address.mac); + break; + case GID_ADDR_NSH: + eid_type = EID_TYPE_API_NSH; + rmp->seid.type = eid_type; + rmp->seid.address.nsh.spi = + clib_host_to_net_u32 (gid_address_nsh_spi (gid)); + rmp->seid.address.nsh.si = gid_address_nsh_si (gid); + break; + default: + /* unknown type */ + return; + } + + rmp->context = context; + rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid)); + rmp->key.id = mapit->key_id; + memcpy (rmp->key.key, mapit->key, vec_len (mapit->key)); + vl_api_send_msg (reg, (u8 *) rmp); +} + +static void +vl_api_one_eid_table_dump_t_handler (vl_api_one_eid_table_dump_t * mp) +{ + u32 mi; + vl_api_registration_t *reg; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + mapping_t *mapit = NULL; + gid_address_t _eid, *eid = &_eid; + + reg = vl_api_client_index_to_registration (mp->client_index); + if (!reg) + return; + + if (mp->eid_set) + { + clib_memset (eid, 0, sizeof (*eid)); + + unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni), &mp->eid); + + mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid); + if ((u32) ~ 0 == mi) + return; + + mapit = pool_elt_at_index (lcm->mapping_pool, mi); + send_one_eid_table_details (mapit, reg, mp->context, + 0 /* ignore filter */ ); + } + else + { + /* *INDENT-OFF* */ + pool_foreach (mapit, lcm->mapping_pool, + ({ + send_one_eid_table_details(mapit, reg, mp->context, + mp->filter); + })); + /* *INDENT-ON* */ + } +} + +static void +send_one_map_server_details (ip_address_t * ip, vl_api_registration_t * reg, + u32 context) +{ + vl_api_one_map_server_details_t *rmp = NULL; + + rmp = vl_msg_api_alloc (sizeof (*rmp)); + clib_memset (rmp, 0, sizeof (*rmp)); + rmp->_vl_msg_id = ntohs (VL_API_ONE_MAP_SERVER_DETAILS); + + + ip_address_encode2 (ip, &rmp->ip_address); + + rmp->context = context; + + vl_api_send_msg (reg, (u8 *) rmp); +} + +static void +vl_api_one_map_server_dump_t_handler (vl_api_one_map_server_dump_t * mp) +{ + vl_api_registration_t *reg; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + lisp_msmr_t *mr; + + reg = vl_api_client_index_to_registration (mp->client_index); + if (!reg) + return; + + vec_foreach (mr, lcm->map_servers) + { + send_one_map_server_details (&mr->address, reg, mp->context); + } +} + +static void +send_one_map_resolver_details (ip_address_t * ip, + vl_api_registration_t * reg, u32 context) +{ + vl_api_one_map_resolver_details_t *rmp = NULL; + + rmp = vl_msg_api_alloc (sizeof (*rmp)); + clib_memset (rmp, 0, sizeof (*rmp)); + rmp->_vl_msg_id = ntohs (VL_API_ONE_MAP_RESOLVER_DETAILS); + + ip_address_encode2 (ip, &rmp->ip_address); + rmp->context = context; + + vl_api_send_msg (reg, (u8 *) rmp); +} + +static void +vl_api_one_map_resolver_dump_t_handler (vl_api_one_map_resolver_dump_t * mp) +{ + vl_api_registration_t *reg; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + lisp_msmr_t *mr; + + reg = vl_api_client_index_to_registration (mp->client_index); + if (!reg) + return; + + vec_foreach (mr, lcm->map_resolvers) + { + send_one_map_resolver_details (&mr->address, reg, mp->context); + } +} + +static void +send_eid_table_map_pair (hash_pair_t * p, vl_api_registration_t * reg, + u32 context) +{ + vl_api_one_eid_table_map_details_t *rmp = NULL; + + rmp = vl_msg_api_alloc (sizeof (*rmp)); + clib_memset (rmp, 0, sizeof (*rmp)); + rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_MAP_DETAILS); + + rmp->vni = clib_host_to_net_u32 (p->key); + rmp->dp_table = clib_host_to_net_u32 (p->value[0]); + rmp->context = context; + vl_api_send_msg (reg, (u8 *) rmp); +} + +static void +vl_api_one_eid_table_map_dump_t_handler (vl_api_one_eid_table_map_dump_t * mp) +{ + vl_api_registration_t *reg; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + hash_pair_t *p; + uword *vni_table = 0; + + reg = vl_api_client_index_to_registration (mp->client_index); + if (!reg) + return; + + if (mp->is_l2) + { + vni_table = lcm->bd_id_by_vni; + } + else + { + vni_table = lcm->table_id_by_vni; + } + + /* *INDENT-OFF* */ + hash_foreach_pair (p, vni_table, + ({ + send_eid_table_map_pair (p, reg, mp->context); + })); + /* *INDENT-ON* */ +} + +static void +send_eid_table_vni (u32 vni, vl_api_registration_t * reg, u32 context) +{ + vl_api_one_eid_table_vni_details_t *rmp = 0; + + rmp = vl_msg_api_alloc (sizeof (*rmp)); + clib_memset (rmp, 0, sizeof (*rmp)); + rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_VNI_DETAILS); + rmp->context = context; + rmp->vni = clib_host_to_net_u32 (vni); + vl_api_send_msg (reg, (u8 *) rmp); +} + +static void +one_adjacency_copy (vl_api_one_adjacency_t * dst, lisp_adjacency_t * adjs) +{ + lisp_adjacency_t *adj; + vl_api_one_adjacency_t a; + u32 i, n = vec_len (adjs); + fib_prefix_t rfib_prefix, lfib_prefix; + u32 eid_type; + + for (i = 0; i < n; i++) + { + adj = vec_elt_at_index (adjs, i); + clib_memset (&a, 0, sizeof (a)); + + switch (gid_address_type (&adj->reid)) + { + case GID_ADDR_IP_PREFIX: + eid_type = EID_TYPE_API_PREFIX; + ip_prefix_to_fib_prefix (&gid_address_ippref (&adj->reid), + &rfib_prefix); + ip_prefix_to_fib_prefix (&gid_address_ippref (&adj->leid), + &lfib_prefix); + ip_prefix_encode (&rfib_prefix, &a.reid.address.prefix); + ip_prefix_encode (&lfib_prefix, &a.leid.address.prefix); + break; + case GID_ADDR_MAC: + eid_type = EID_TYPE_API_PREFIX; + mac_address_encode ((mac_address_t *) gid_address_mac (&adj->reid), + a.reid.address.mac); + mac_address_encode ((mac_address_t *) gid_address_mac (&adj->leid), + a.leid.address.mac); + break; + case GID_ADDR_NSH: + eid_type = EID_TYPE_API_PREFIX; + a.reid.address.nsh.spi = + clib_host_to_net_u32 (gid_address_nsh_spi (&adj->reid)); + a.reid.address.nsh.si = gid_address_nsh_si (&adj->reid); + a.leid.address.nsh.spi = + clib_host_to_net_u32 (gid_address_nsh_spi (&adj->leid)); + a.leid.address.nsh.si = gid_address_nsh_si (&adj->leid); + break; + default: + ALWAYS_ASSERT (0); + } + a.reid.type = eid_type; + a.leid.type = eid_type; + dst[i] = a; + } +} + +static void + vl_api_show_one_rloc_probe_state_t_handler + (vl_api_show_one_rloc_probe_state_t * mp) +{ + vl_api_show_one_rloc_probe_state_reply_t *rmp = 0; + int rv = 0; + + /* *INDENT-OFF* */ + REPLY_MACRO2 (VL_API_SHOW_ONE_RLOC_PROBE_STATE_REPLY, + { + rmp->is_enable = vnet_lisp_rloc_probe_state_get (); + }); + /* *INDENT-ON* */ +} + +static void + vl_api_show_one_map_register_state_t_handler + (vl_api_show_one_map_register_state_t * mp) +{ + vl_api_show_one_map_register_state_reply_t *rmp = 0; + int rv = 0; + + /* *INDENT-OFF* */ + REPLY_MACRO2 (VL_API_SHOW_ONE_MAP_REGISTER_STATE_REPLY, + { + rmp->is_enable = vnet_lisp_map_register_state_get (); + }); + /* *INDENT-ON* */ +} + +static void +vl_api_one_adjacencies_get_t_handler (vl_api_one_adjacencies_get_t * mp) +{ + vl_api_one_adjacencies_get_reply_t *rmp = 0; + lisp_adjacency_t *adjs = 0; + int rv = 0; + u32 size = ~0; + u32 vni = clib_net_to_host_u32 (mp->vni); + + adjs = vnet_lisp_adjacencies_get_by_vni (vni); + size = vec_len (adjs) * sizeof (vl_api_one_adjacency_t); + + /* *INDENT-OFF* */ + REPLY_MACRO4 (VL_API_ONE_ADJACENCIES_GET_REPLY, size, + { + rmp->count = clib_host_to_net_u32 (vec_len (adjs)); + one_adjacency_copy (rmp->adjacencies, adjs); + }); + /* *INDENT-ON* */ + + vec_free (adjs); +} + +static void +vl_api_one_eid_table_vni_dump_t_handler (vl_api_one_eid_table_vni_dump_t * mp) +{ + hash_pair_t *p; + u32 *vnis = 0; + vl_api_registration_t *reg; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + + reg = vl_api_client_index_to_registration (mp->client_index); + if (!reg) + return; + + /* *INDENT-OFF* */ + hash_foreach_pair (p, lcm->table_id_by_vni, + ({ + hash_set (vnis, p->key, 0); + })); + + hash_foreach_pair (p, lcm->bd_id_by_vni, + ({ + hash_set (vnis, p->key, 0); + })); + + hash_foreach_pair (p, vnis, + ({ + send_eid_table_vni (p->key, reg, mp->context); + })); + /* *INDENT-ON* */ + + hash_free (vnis); +} + +static void +vl_api_show_one_status_t_handler (vl_api_show_one_status_t * mp) +{ + vl_api_show_one_status_reply_t *rmp = NULL; + int rv = 0; + + /* *INDENT-OFF* */ + REPLY_MACRO2(VL_API_SHOW_ONE_STATUS_REPLY, + ({ + rmp->gpe_status = vnet_lisp_gpe_enable_disable_status (); + rmp->feature_status = vnet_lisp_enable_disable_status (); + })); + /* *INDENT-ON* */ +} + +static void + vl_api_one_get_map_request_itr_rlocs_t_handler + (vl_api_one_get_map_request_itr_rlocs_t * mp) +{ + vl_api_one_get_map_request_itr_rlocs_reply_t *rmp = NULL; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + locator_set_t *loc_set = 0; + u8 *tmp_str = 0; + int rv = 0; + + if (~0 == lcm->mreq_itr_rlocs) + { + tmp_str = format (0, " "); + } + else + { + loc_set = + pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs); + tmp_str = format (0, "%s", loc_set->name); + } + + /* *INDENT-OFF* */ + REPLY_MACRO2(VL_API_ONE_GET_MAP_REQUEST_ITR_RLOCS_REPLY, + ({ + strncpy((char *) rmp->locator_set_name, (char *) tmp_str, + ARRAY_LEN(rmp->locator_set_name) - 1); + })); + /* *INDENT-ON* */ + + vec_free (tmp_str); +} + +static void +vl_api_show_one_nsh_mapping_t_handler (vl_api_show_one_nsh_mapping_t * mp) +{ + vl_api_show_one_nsh_mapping_reply_t *rmp = NULL; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + mapping_t *m; + locator_set_t *ls = 0; + u8 *tmp_str = 0; + u8 is_set = 0; + int rv = 0; + + if (lcm->nsh_map_index == (u32) ~ 0) + { + tmp_str = format (0, "N/A"); + } + else + { + m = pool_elt_at_index (lcm->mapping_pool, lcm->nsh_map_index); + if (~0 != m->locator_set_index) + { + ls = + pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index); + tmp_str = format (0, "%s", ls->name); + is_set = 1; + } + else + { + tmp_str = format (0, "N/A"); + } + } + vec_add1 (tmp_str, 0); + + /* *INDENT-OFF* */ + REPLY_MACRO2(VL_API_SHOW_ONE_NSH_MAPPING_REPLY, + ({ + rmp->is_set = is_set; + strncpy((char *) rmp->locator_set_name, (char *) tmp_str, + ARRAY_LEN(rmp->locator_set_name) - 1); + })); + /* *INDENT-ON* */ +} + +static void +vl_api_show_one_pitr_t_handler (vl_api_show_one_pitr_t * mp) +{ + vl_api_show_one_pitr_reply_t *rmp = NULL; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + mapping_t *m; + locator_set_t *ls = 0; + u8 *tmp_str = 0; + int rv = 0; + + u8 is_enable = (lcm->flags & LISP_FLAG_PITR_MODE) + && lcm->pitr_map_index != ~0; + + if (!is_enable) + { + tmp_str = format (0, "N/A"); + } + else + { + m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index); + if (~0 != m->locator_set_index) + { + ls = + pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index); + tmp_str = format (0, "%s", ls->name); + } + else + { + tmp_str = format (0, "N/A"); + } + } + vec_add1 (tmp_str, 0); + + /* *INDENT-OFF* */ + REPLY_MACRO2(VL_API_SHOW_ONE_PITR_REPLY, + ({ + rmp->status = lcm->flags & LISP_FLAG_PITR_MODE; + strncpy((char *) rmp->locator_set_name, (char *) tmp_str, + ARRAY_LEN(rmp->locator_set_name) - 1); + })); + /* *INDENT-ON* */ +} + +static void + vl_api_show_one_stats_enable_disable_t_handler + (vl_api_show_one_stats_enable_disable_t * mp) +{ + vl_api_show_one_stats_enable_disable_reply_t *rmp = NULL; + vnet_api_error_t rv = 0; + + /* *INDENT-OFF* */ + REPLY_MACRO2 (VL_API_SHOW_ONE_STATS_ENABLE_DISABLE_REPLY, + ({ + rmp->is_enable = vnet_lisp_stats_enable_disable_state (); + })); + /* *INDENT-ON* */ +} + +static void + vl_api_one_stats_enable_disable_t_handler + (vl_api_one_stats_enable_disable_t * mp) +{ + vl_api_one_enable_disable_reply_t *rmp = NULL; + + vnet_api_error_t rv = vnet_lisp_stats_enable_disable (mp->is_enable); + REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY); +} + +static void +vl_api_one_stats_flush_t_handler (vl_api_one_stats_flush_t * mp) +{ + vl_api_one_stats_flush_reply_t *rmp; + u8 rv; + + rv = vnet_lisp_flush_stats (); + REPLY_MACRO (VL_API_ONE_STATS_FLUSH_REPLY); +} + +static void +vl_api_one_stats_dump_t_handler (vl_api_one_stats_dump_t * mp) +{ + vl_api_one_stats_details_t *rmp; + lisp_api_stats_t *stats, *stat; + u8 rv = 0; + + stats = vnet_lisp_get_stats (); + vec_foreach (stat, stats) + { + /* *INDENT-OFF* */ + REPLY_DETAILS (VL_API_ONE_STATS_DETAILS, + ({ + fid_to_api_eid (&stat->deid, &rmp->deid); + fid_to_api_eid (&stat->seid, &rmp->seid); + rmp->vni = clib_host_to_net_u32 (stat->vni); + + ip_address_encode2 (&stat->rmt_rloc, &rmp->rloc); + ip_address_encode2 (&stat->loc_rloc, &rmp->lloc); + + rmp->pkt_count = clib_host_to_net_u32 (stat->counters.packets); + rmp->bytes = clib_host_to_net_u32 (stat->counters.bytes); + })); + /* *INDENT-ON* */ + } +} + +static void + vl_api_one_add_del_l2_arp_entry_t_handler + (vl_api_one_add_del_l2_arp_entry_t * mp) +{ + vl_api_one_add_del_l2_arp_entry_reply_t *rmp; + int rv = 0; + gid_address_t _arp, *arp = &_arp; + ip4_address_t ip4; + mac_address_t mac; + clib_memset (arp, 0, sizeof (*arp)); + + gid_address_type (arp) = GID_ADDR_ARP; + gid_address_arp_bd (arp) = clib_net_to_host_u32 (mp->bd); + + ip4_address_decode (mp->entry.ip4, &ip4); + ip_address_set (&gid_address_arp_ndp_ip (arp), &ip4, AF_IP4); + mac_address_decode (mp->entry.mac, &mac); + + rv = vnet_lisp_add_del_l2_arp_ndp_entry (arp, mac.bytes, mp->is_add); + + REPLY_MACRO (VL_API_ONE_ADD_DEL_L2_ARP_ENTRY_REPLY); +} + +static void +vl_api_one_add_del_ndp_entry_t_handler (vl_api_one_add_del_ndp_entry_t * mp) +{ + vl_api_one_add_del_ndp_entry_reply_t *rmp; + int rv = 0; + gid_address_t _g, *g = &_g; + ip6_address_t ip6; + mac_address_t mac; + clib_memset (g, 0, sizeof (*g)); + + gid_address_type (g) = GID_ADDR_NDP; + gid_address_ndp_bd (g) = clib_net_to_host_u32 (mp->bd); + + ip6_address_decode (mp->entry.ip6, &ip6); + ip_address_set (&gid_address_arp_ndp_ip (g), &ip6, AF_IP6); + mac_address_decode (mp->entry.mac, &mac); + + rv = vnet_lisp_add_del_l2_arp_ndp_entry (g, mac.bytes, mp->is_add); + + REPLY_MACRO (VL_API_ONE_ADD_DEL_NDP_ENTRY_REPLY); +} + +static void +vl_api_one_ndp_bd_get_t_handler (vl_api_one_ndp_bd_get_t * mp) +{ + vl_api_one_ndp_bd_get_reply_t *rmp; + int rv = 0; + u32 i = 0; + hash_pair_t *p; + + u32 *bds = vnet_lisp_ndp_bds_get (); + u32 size = hash_elts (bds) * sizeof (u32); + + /* *INDENT-OFF* */ + REPLY_MACRO4 (VL_API_ONE_NDP_BD_GET_REPLY, size, + { + rmp->count = clib_host_to_net_u32 (hash_elts (bds)); + hash_foreach_pair (p, bds, + ({ + rmp->bridge_domains[i++] = clib_host_to_net_u32 (p->key); + })); + }); + /* *INDENT-ON* */ + + hash_free (bds); +} + +static void +vl_api_one_l2_arp_bd_get_t_handler (vl_api_one_l2_arp_bd_get_t * mp) +{ + vl_api_one_l2_arp_bd_get_reply_t *rmp; + int rv = 0; + u32 i = 0; + hash_pair_t *p; + + u32 *bds = vnet_lisp_l2_arp_bds_get (); + u32 size = hash_elts (bds) * sizeof (u32); + + /* *INDENT-OFF* */ + REPLY_MACRO4 (VL_API_ONE_L2_ARP_BD_GET_REPLY, size, + { + rmp->count = clib_host_to_net_u32 (hash_elts (bds)); + hash_foreach_pair (p, bds, + ({ + rmp->bridge_domains[i++] = clib_host_to_net_u32 (p->key); + })); + }); + /* *INDENT-ON* */ + + hash_free (bds); +} + +static void +vl_api_one_l2_arp_entries_get_t_handler (vl_api_one_l2_arp_entries_get_t * mp) +{ + vl_api_one_l2_arp_entries_get_reply_t *rmp; + lisp_api_l2_arp_entry_t *entries = 0, *e; + u32 i = 0; + int rv = 0; + + u32 bd = clib_net_to_host_u32 (mp->bd); + + entries = vnet_lisp_l2_arp_entries_get_by_bd (bd); + u32 size = vec_len (entries) * sizeof (vl_api_one_l2_arp_entry_t); + + /* *INDENT-OFF* */ + REPLY_MACRO4 (VL_API_ONE_L2_ARP_ENTRIES_GET_REPLY, size, + { + rmp->count = clib_host_to_net_u32 (vec_len (entries)); + vec_foreach (e, entries) + { + mac_address_encode ((mac_address_t *) e->mac, rmp->entries[i].mac); + ip4_address_encode ((ip4_address_t *) &e->ip4, rmp->entries[i].ip4); + i++; + } + }); + /* *INDENT-ON* */ + + vec_free (entries); +} + +static void + vl_api_one_map_register_fallback_threshold_t_handler + (vl_api_one_map_register_fallback_threshold_t * mp) +{ + vl_api_one_map_register_fallback_threshold_reply_t *rmp; + int rv = 0; + + mp->value = clib_net_to_host_u32 (mp->value); + rv = vnet_lisp_map_register_fallback_threshold_set (mp->value); + REPLY_MACRO (VL_API_ONE_MAP_REGISTER_FALLBACK_THRESHOLD_REPLY); +} + +static void + vl_api_show_one_map_register_fallback_threshold_t_handler + (vl_api_show_one_map_register_fallback_threshold_t * mp) +{ + vl_api_show_one_map_register_fallback_threshold_reply_t *rmp; + int rv = 0; + + u32 value = vnet_lisp_map_register_fallback_threshold_get (); + + /* *INDENT-OFF* */ + REPLY_MACRO2 (VL_API_SHOW_ONE_MAP_REGISTER_FALLBACK_THRESHOLD_REPLY, + ({ + rmp->value = clib_host_to_net_u32 (value); + })); + /* *INDENT-ON* */ +} + +static void + vl_api_one_set_transport_protocol_t_handler + (vl_api_one_set_transport_protocol_t * mp) +{ + vl_api_one_set_transport_protocol_reply_t *rmp; + int rv = 0; + + rv = vnet_lisp_set_transport_protocol (mp->protocol); + + REPLY_MACRO (VL_API_ONE_SET_TRANSPORT_PROTOCOL_REPLY); +} + +static void + vl_api_one_get_transport_protocol_t_handler + (vl_api_one_get_transport_protocol_t * mp) +{ + vl_api_one_get_transport_protocol_reply_t *rmp; + int rv = 0; + u8 proto = (u8) vnet_lisp_get_transport_protocol (); + + /* *INDENT-OFF* */ + REPLY_MACRO2 (VL_API_ONE_GET_TRANSPORT_PROTOCOL_REPLY, + ({ + rmp->protocol = proto; + })); + /* *INDENT-ON* */ +} + +static void +vl_api_one_ndp_entries_get_t_handler (vl_api_one_ndp_entries_get_t * mp) +{ + vl_api_one_ndp_entries_get_reply_t *rmp = 0; + lisp_api_ndp_entry_t *entries = 0, *e; + u32 i = 0; + int rv = 0; + + u32 bd = clib_net_to_host_u32 (mp->bd); + + entries = vnet_lisp_ndp_entries_get_by_bd (bd); + u32 size = vec_len (entries) * sizeof (vl_api_one_ndp_entry_t); + + /* *INDENT-OFF* */ + REPLY_MACRO4 (VL_API_ONE_NDP_ENTRIES_GET_REPLY, size, + { + rmp->count = clib_host_to_net_u32 (vec_len (entries)); + vec_foreach (e, entries) + { + mac_address_encode ((mac_address_t *) e->mac, rmp->entries[i].mac); + ip6_address_encode ((ip6_address_t *) &e->ip6, rmp->entries[i].ip6); + i++; + } + }); + /* *INDENT-ON* */ + + vec_free (entries); +} + +static void + vl_api_one_enable_disable_xtr_mode_t_handler + (vl_api_one_enable_disable_xtr_mode_t * mp) +{ + vl_api_one_enable_disable_xtr_mode_reply_t *rmp = 0; + int rv = vnet_lisp_enable_disable_xtr_mode (mp->is_enable); + + REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_XTR_MODE_REPLY); +} + +static void +vl_api_one_show_xtr_mode_t_handler (vl_api_one_show_xtr_mode_t * mp) +{ + vl_api_one_show_xtr_mode_reply_t *rmp = 0; + int rv = 0; + + /* *INDENT-OFF* */ + REPLY_MACRO2 (VL_API_ONE_SHOW_XTR_MODE_REPLY, + { + rmp->is_enable = vnet_lisp_get_xtr_mode (); + }); + /* *INDENT-ON* */ +} + +static void + vl_api_one_enable_disable_pitr_mode_t_handler + (vl_api_one_enable_disable_pitr_mode_t * mp) +{ + vl_api_one_enable_disable_pitr_mode_reply_t *rmp = 0; + int rv = vnet_lisp_enable_disable_pitr_mode (mp->is_enable); + + REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_PITR_MODE_REPLY); +} + +static void +vl_api_one_show_pitr_mode_t_handler (vl_api_one_show_pitr_mode_t * mp) +{ + vl_api_one_show_pitr_mode_reply_t *rmp = 0; + int rv = 0; + + /* *INDENT-OFF* */ + REPLY_MACRO2 (VL_API_ONE_SHOW_PITR_MODE_REPLY, + { + rmp->is_enable = vnet_lisp_get_pitr_mode (); + }); + /* *INDENT-ON* */ +} + +static void + vl_api_one_enable_disable_petr_mode_t_handler + (vl_api_one_enable_disable_petr_mode_t * mp) +{ + vl_api_one_enable_disable_petr_mode_reply_t *rmp = 0; + int rv = vnet_lisp_enable_disable_petr_mode (mp->is_enable); + + REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_PETR_MODE_REPLY); +} + +static void +vl_api_one_show_petr_mode_t_handler (vl_api_one_show_petr_mode_t * mp) +{ + vl_api_one_show_petr_mode_reply_t *rmp = 0; + int rv = 0; + + /* *INDENT-OFF* */ + REPLY_MACRO2 (VL_API_ONE_SHOW_PETR_MODE_REPLY, + { + rmp->is_enable = vnet_lisp_get_petr_mode (); + }); + /* *INDENT-ON* */ +} + +/* + * one_api_hookup + * Add vpe's API message handlers to the table. + * vlib has already mapped shared memory and + * added the client registration handlers. + * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process() + */ +#include + +static clib_error_t * +one_api_hookup (vlib_main_t * vm) +{ + one_base_msg_id = setup_message_id_table (); + + return 0; +} + +VLIB_API_INIT_FUNCTION (one_api_hookup); + +#include +#include + +/* *INDENT-OFF* */ +VLIB_PLUGIN_REGISTER () = { + .version = VPP_BUILD_VER, + .description = "Locator ID Separation Protocol (LISP)", +}; +/* *INDENT-ON* */ + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/lisp/lisp-cp/one_cli.c b/src/plugins/lisp/lisp-cp/one_cli.c new file mode 100644 index 00000000000..b43532684ef --- /dev/null +++ b/src/plugins/lisp/lisp-cp/one_cli.c @@ -0,0 +1,2340 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +static clib_error_t * +lisp_show_adjacencies_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + lisp_adjacency_t *adjs, *adj; + vlib_cli_output (vm, "%s %40s\n", "leid", "reid"); + unformat_input_t _line_input, *line_input = &_line_input; + u32 vni = ~0; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "vni %d", &vni)) + ; + else + { + vlib_cli_output (vm, "parse error: '%U'", + format_unformat_error, line_input); + unformat_free (line_input); + return 0; + } + } + unformat_free (line_input); + + if (~0 == vni) + { + vlib_cli_output (vm, "error: no vni specified!"); + return 0; + } + + adjs = vnet_lisp_adjacencies_get_by_vni (vni); + + vec_foreach (adj, adjs) + { + vlib_cli_output (vm, "%U %40U\n", format_gid_address, &adj->leid, + format_gid_address, &adj->reid); + } + vec_free (adjs); + + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_show_adjacencies_command) = { + .path = "show one adjacencies", + .short_help = "show one adjacencies", + .function = lisp_show_adjacencies_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_add_del_map_server_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + int rv = 0; + u8 is_add = 1, ip_set = 0; + ip_address_t ip; + unformat_input_t _line_input, *line_input = &_line_input; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "add")) + is_add = 1; + else if (unformat (line_input, "del")) + is_add = 0; + else if (unformat (line_input, "%U", unformat_ip_address, &ip)) + ip_set = 1; + else + { + vlib_cli_output (vm, "parse error: '%U'", + format_unformat_error, line_input); + unformat_free (line_input); + return 0; + } + } + unformat_free (line_input); + + if (!ip_set) + { + vlib_cli_output (vm, "map-server ip address not set!"); + return 0; + } + + rv = vnet_lisp_add_del_map_server (&ip, is_add); + if (!rv) + vlib_cli_output (vm, "failed to %s map-server!", + is_add ? "add" : "delete"); + + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_add_del_map_server_command) = { + .path = "one map-server", + .short_help = "one map-server add|del ", + .function = lisp_add_del_map_server_command_fn, +}; +/* *INDENT-ON* */ + + +static clib_error_t * +lisp_add_del_local_eid_command_fn (vlib_main_t * vm, unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + unformat_input_t _line_input, *line_input = &_line_input; + u8 is_add = 1; + gid_address_t eid; + gid_address_t *eids = 0; + clib_error_t *error = 0; + u8 *locator_set_name = 0; + u32 locator_set_index = 0, map_index = 0; + uword *p; + vnet_lisp_add_del_mapping_args_t _a, *a = &_a; + int rv = 0; + u32 vni = 0; + u8 *key = 0; + u32 key_id = 0; + + clib_memset (&eid, 0, sizeof (eid)); + clib_memset (a, 0, sizeof (*a)); + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "add")) + is_add = 1; + else if (unformat (line_input, "del")) + is_add = 0; + else if (unformat (line_input, "eid %U", unformat_gid_address, &eid)) + ; + else if (unformat (line_input, "vni %d", &vni)) + gid_address_vni (&eid) = vni; + else if (unformat (line_input, "secret-key %_%v%_", &key)) + ; + else if (unformat (line_input, "key-id %U", unformat_hmac_key_id, + &key_id)) + ; + else if (unformat (line_input, "locator-set %_%v%_", &locator_set_name)) + { + vec_terminate_c_string (locator_set_name); + p = hash_get_mem (lcm->locator_set_index_by_name, locator_set_name); + if (!p) + { + error = clib_error_return (0, "locator-set %s doesn't exist", + locator_set_name); + goto done; + } + locator_set_index = p[0]; + } + else if (unformat (line_input, "authoritative")) + a->authoritative = 1; + else + { + error = unformat_parse_error (line_input); + goto done; + } + } + /* XXX treat batch configuration */ + + if (GID_ADDR_SRC_DST == gid_address_type (&eid)) + { + error = + clib_error_return (0, "src/dst is not supported for local EIDs!"); + goto done; + } + + if (key && (0 == key_id)) + { + vlib_cli_output (vm, "invalid key_id!"); + goto done; + } + + gid_address_copy (&a->eid, &eid); + a->is_add = is_add; + a->locator_set_index = locator_set_index; + a->local = 1; + a->key = key; + a->key_id = key_id; + + rv = vnet_lisp_add_del_local_mapping (a, &map_index); + if (0 != rv) + { + error = clib_error_return (0, "failed to %s local mapping!", + is_add ? "add" : "delete"); + } +done: + vec_free (eids); + if (locator_set_name) + vec_free (locator_set_name); + gid_address_free (&a->eid); + vec_free (a->key); + unformat_free (line_input); + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_add_del_local_eid_command) = { + .path = "one eid-table", + .short_help = "one eid-table add/del [vni ] eid " + "locator-set [key key-id sha1|sha256 ]", + .function = lisp_add_del_local_eid_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_eid_table_map_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + u8 is_add = 1, is_l2 = 0; + u32 vni = 0, dp_id = 0; + unformat_input_t _line_input, *line_input = &_line_input; + clib_error_t *error = NULL; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "del")) + is_add = 0; + else if (unformat (line_input, "vni %d", &vni)) + ; + else if (unformat (line_input, "vrf %d", &dp_id)) + ; + else if (unformat (line_input, "bd %d", &dp_id)) + is_l2 = 1; + else + { + error = unformat_parse_error (line_input); + goto done; + } + } + vnet_lisp_eid_table_map (vni, dp_id, is_l2, is_add); + +done: + unformat_free (line_input); + + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_eid_table_map_command) = { + .path = "one eid-table map", + .short_help = "one eid-table map [del] vni vrf | bd ", + .function = lisp_eid_table_map_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_add_del_ndp_entry_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + unformat_input_t _line_input, *line_input = &_line_input; + clib_error_t *error = NULL; + int rc = 0; + u8 hw_addr[6], bd = 0; + ip6_address_t ip6; + u32 hw_addr_set = 0, ip_set = 0, is_add = 1; + gid_address_t _g, *g = &_g; + + clib_memset (&ip6, 0, sizeof (ip6)); + clib_memset (hw_addr, 0, sizeof (hw_addr)); + clib_memset (g, 0, sizeof (*g)); + + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "mac %U", unformat_mac_address, hw_addr)) + hw_addr_set = 1; + else if (unformat (line_input, "ip %U", unformat_ip6_address, &ip6)) + ip_set = 1; + else if (unformat (line_input, "del")) + is_add = 0; + else if (unformat (line_input, "bd %d", &bd)) + ; + else + { + error = clib_error_return (0, "parse error"); + goto done; + } + } + + if (!ip_set || (!hw_addr_set && is_add)) + { + vlib_cli_output (vm, "expected IP and MAC addresses!"); + return 0; + } + + /* build GID address */ + ip_address_set (&gid_address_arp_ndp_ip (g), &ip6, AF_IP6); + gid_address_ndp_bd (g) = bd; + gid_address_type (g) = GID_ADDR_NDP; + rc = vnet_lisp_add_del_l2_arp_ndp_entry (g, hw_addr, is_add); + if (rc) + clib_warning ("Failed to %s ndp entry!", is_add ? "add" : "delete"); + +done: + unformat_free (line_input); + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_add_del_ndp_entry_command) = { + .path = "one ndp", + .short_help = "one ndp [del] bd mac ip ", + .function = lisp_add_del_ndp_entry_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_add_del_l2_arp_entry_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + unformat_input_t _line_input, *line_input = &_line_input; + clib_error_t *error = NULL; + int rc = 0; + u8 hw_addr[6], bd = 0; + ip4_address_t ip4; + u32 hw_addr_set = 0, ip_set = 0, is_add = 1; + gid_address_t _arp, *arp = &_arp; + + clib_memset (&ip4, 0, sizeof (ip4)); + clib_memset (hw_addr, 0, sizeof (hw_addr)); + clib_memset (arp, 0, sizeof (*arp)); + + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "mac %U", unformat_mac_address, hw_addr)) + hw_addr_set = 1; + else if (unformat (line_input, "ip %U", unformat_ip4_address, &ip4)) + ip_set = 1; + else if (unformat (line_input, "del")) + is_add = 0; + else if (unformat (line_input, "bd %d", &bd)) + ; + else + { + error = clib_error_return (0, "parse error"); + goto done; + } + } + + if (!ip_set || (!hw_addr_set && is_add)) + { + vlib_cli_output (vm, "expected IP and MAC addresses!"); + return 0; + } + + /* build GID address */ + gid_address_arp_ip4 (arp) = ip4; + gid_address_arp_bd (arp) = bd; + gid_address_type (arp) = GID_ADDR_ARP; + rc = vnet_lisp_add_del_l2_arp_ndp_entry (arp, hw_addr, is_add); + if (rc) + clib_warning ("Failed to %s l2 arp entry!", is_add ? "add" : "delete"); + +done: + unformat_free (line_input); + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_add_del_l2_arp_entry_command) = { + .path = "one l2 arp", + .short_help = "one l2 arp [del] bd mac ip ", + .function = lisp_add_del_l2_arp_entry_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_show_l2_arp_entries_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + u32 *ht = vnet_lisp_l2_arp_bds_get (); + lisp_api_l2_arp_entry_t *entries, *e; + hash_pair_t *p; + + /* *INDENT-OFF* */ + hash_foreach_pair (p, ht, + ({ + entries = vnet_lisp_l2_arp_entries_get_by_bd (p->key); + vlib_cli_output (vm, "Table: %d", p->key); + + vec_foreach (e, entries) + { + vlib_cli_output (vm, "\t%U -> %U", format_ip4_address, &e->ip4, + format_mac_address, e->mac); + } + vec_free (entries); + })); + /* *INDENT-ON* */ + + hash_free (ht); + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_show_l2_arp_entries_command) = { + .path = "show one l2 arp entries", + .short_help = "Show ONE L2 ARP entries", + .function = lisp_show_l2_arp_entries_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_show_ndp_entries_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + u32 *ht = vnet_lisp_ndp_bds_get (); + lisp_api_ndp_entry_t *entries, *e; + hash_pair_t *p; + + /* *INDENT-OFF* */ + hash_foreach_pair (p, ht, + ({ + entries = vnet_lisp_ndp_entries_get_by_bd (p->key); + vlib_cli_output (vm, "Table: %d", p->key); + + vec_foreach (e, entries) + { + vlib_cli_output (vm, "\t%U -> %U", format_ip6_address, &e->ip6, + format_mac_address, e->mac); + } + vec_free (entries); + })); + /* *INDENT-ON* */ + + hash_free (ht); + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_show_ndp_entries_command) = { + .path = "show one ndp entries", + .short_help = "Show ONE NDP entries", + .function = lisp_show_ndp_entries_command_fn, +}; +/* *INDENT-ON* */ + +/** + * Handler for add/del remote mapping CLI. + * + * @param vm vlib context + * @param input input from user + * @param cmd cmd + * @return pointer to clib error structure + */ +static clib_error_t * +lisp_add_del_remote_mapping_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + clib_error_t *error = 0; + unformat_input_t _line_input, *line_input = &_line_input; + u8 is_add = 1, del_all = 0; + locator_t rloc, *rlocs = 0, *curr_rloc = 0; + gid_address_t eid; + u8 eid_set = 0; + u32 vni, action = ~0, p, w; + int rv; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + clib_memset (&eid, 0, sizeof (eid)); + clib_memset (&rloc, 0, sizeof (rloc)); + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "del-all")) + del_all = 1; + else if (unformat (line_input, "del")) + is_add = 0; + else if (unformat (line_input, "add")) + ; + else if (unformat (line_input, "eid %U", unformat_gid_address, &eid)) + eid_set = 1; + else if (unformat (line_input, "vni %u", &vni)) + { + gid_address_vni (&eid) = vni; + } + else if (unformat (line_input, "p %d w %d", &p, &w)) + { + if (!curr_rloc) + { + clib_warning + ("No RLOC configured for setting priority/weight!"); + goto done; + } + curr_rloc->priority = p; + curr_rloc->weight = w; + } + else if (unformat (line_input, "rloc %U", unformat_ip_address, + &gid_address_ip (&rloc.address))) + { + /* since rloc is stored in ip prefix we need to set prefix length */ + ip_prefix_t *pref = &gid_address_ippref (&rloc.address); + + u8 version = gid_address_ip_version (&rloc.address); + ip_prefix_len (pref) = ip_address_max_len (version); + + vec_add1 (rlocs, rloc); + curr_rloc = &rlocs[vec_len (rlocs) - 1]; + } + else if (unformat (line_input, "action %U", + unformat_negative_mapping_action, &action)) + ; + else + { + clib_warning ("parse error"); + goto done; + } + } + + if (!del_all && !eid_set) + { + clib_warning ("missing eid!"); + goto done; + } + + if (!del_all) + { + if (is_add && (~0 == action) && 0 == vec_len (rlocs)) + { + clib_warning ("no action set for negative map-reply!"); + goto done; + } + } + else + { + vnet_lisp_clear_all_remote_adjacencies (); + goto done; + } + + /* if it's a delete, clean forwarding */ + if (!is_add) + { + vnet_lisp_add_del_adjacency_args_t _a, *a = &_a; + clib_memset (a, 0, sizeof (a[0])); + gid_address_copy (&a->reid, &eid); + if (vnet_lisp_add_del_adjacency (a)) + { + clib_warning ("failed to delete adjacency!"); + goto done; + } + } + + /* add as static remote mapping, i.e., not authoritative and infinite + * ttl */ + if (is_add) + { + vnet_lisp_add_del_mapping_args_t _map_args, *map_args = &_map_args; + clib_memset (map_args, 0, sizeof (map_args[0])); + gid_address_copy (&map_args->eid, &eid); + map_args->action = action; + map_args->is_static = 1; + map_args->authoritative = 0; + map_args->ttl = ~0; + rv = vnet_lisp_add_mapping (map_args, rlocs, NULL, NULL); + } + else + rv = vnet_lisp_del_mapping (&eid, NULL); + + if (rv) + clib_warning ("failed to %s remote mapping!", is_add ? "add" : "delete"); + +done: + vec_free (rlocs); + unformat_free (line_input); + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_add_del_remote_mapping_command) = { + .path = "one remote-mapping", + .short_help = + "one remote-mapping add|del [del-all] vni " + "eid [action ] rloc p w " + "[rloc ... ]", + .function = lisp_add_del_remote_mapping_command_fn, +}; +/* *INDENT-ON* */ + +/** + * Handler for add/del adjacency CLI. + */ +static clib_error_t * +lisp_add_del_adjacency_command_fn (vlib_main_t * vm, unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + clib_error_t *error = 0; + unformat_input_t _line_input, *line_input = &_line_input; + vnet_lisp_add_del_adjacency_args_t _a, *a = &_a; + u8 is_add = 1; + ip_prefix_t *reid_ippref, *leid_ippref; + gid_address_t leid, reid; + u8 *dmac = gid_address_mac (&reid); + u8 *smac = gid_address_mac (&leid); + u8 reid_set = 0, leid_set = 0; + u32 vni; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + clib_memset (&reid, 0, sizeof (reid)); + clib_memset (&leid, 0, sizeof (leid)); + + leid_ippref = &gid_address_ippref (&leid); + reid_ippref = &gid_address_ippref (&reid); + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "del")) + is_add = 0; + else if (unformat (line_input, "add")) + ; + else if (unformat (line_input, "reid %U", + unformat_ip_prefix, reid_ippref)) + { + gid_address_type (&reid) = GID_ADDR_IP_PREFIX; + reid_set = 1; + } + else if (unformat (line_input, "reid %U", unformat_mac_address, dmac)) + { + gid_address_type (&reid) = GID_ADDR_MAC; + reid_set = 1; + } + else if (unformat (line_input, "vni %u", &vni)) + { + gid_address_vni (&leid) = vni; + gid_address_vni (&reid) = vni; + } + else if (unformat (line_input, "leid %U", + unformat_ip_prefix, leid_ippref)) + { + gid_address_type (&leid) = GID_ADDR_IP_PREFIX; + leid_set = 1; + } + else if (unformat (line_input, "leid %U", unformat_mac_address, smac)) + { + gid_address_type (&leid) = GID_ADDR_MAC; + leid_set = 1; + } + else + { + clib_warning ("parse error"); + goto done; + } + } + + if (!reid_set || !leid_set) + { + clib_warning ("missing remote or local eid!"); + goto done; + } + + if ((gid_address_type (&leid) != gid_address_type (&reid)) + || (gid_address_type (&reid) == GID_ADDR_IP_PREFIX + && ip_prefix_version (reid_ippref) + != ip_prefix_version (leid_ippref))) + { + clib_warning ("remote and local EIDs are of different types!"); + goto done; + } + + clib_memset (a, 0, sizeof (a[0])); + gid_address_copy (&a->leid, &leid); + gid_address_copy (&a->reid, &reid); + a->is_add = is_add; + + if (vnet_lisp_add_del_adjacency (a)) + clib_warning ("failed to %s adjacency!", is_add ? "add" : "delete"); + +done: + unformat_free (line_input); + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_add_del_adjacency_command) = { + .path = "one adjacency", + .short_help = "one adjacency add|del vni reid " + "leid ", + .function = lisp_add_del_adjacency_command_fn, +}; +/* *INDENT-ON* */ + + +static clib_error_t * +lisp_map_request_mode_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + unformat_input_t _i, *i = &_i; + map_request_mode_t mr_mode = _MR_MODE_MAX; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, i)) + return 0; + + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + { + if (unformat (i, "dst-only")) + mr_mode = MR_MODE_DST_ONLY; + else if (unformat (i, "src-dst")) + mr_mode = MR_MODE_SRC_DST; + else + { + clib_warning ("parse error '%U'", format_unformat_error, i); + goto done; + } + } + + if (_MR_MODE_MAX == mr_mode) + { + clib_warning ("No map request mode entered!"); + goto done; + } + + vnet_lisp_set_map_request_mode (mr_mode); + +done: + unformat_free (i); + + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_map_request_mode_command) = { + .path = "one map-request mode", + .short_help = "one map-request mode dst-only|src-dst", + .function = lisp_map_request_mode_command_fn, +}; +/* *INDENT-ON* */ + + +static u8 * +format_lisp_map_request_mode (u8 * s, va_list * args) +{ + u32 mode = va_arg (*args, u32); + + switch (mode) + { + case 0: + return format (0, "dst-only"); + case 1: + return format (0, "src-dst"); + } + return 0; +} + +static clib_error_t * +lisp_show_map_request_mode_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + vlib_cli_output (vm, "map-request mode: %U", format_lisp_map_request_mode, + vnet_lisp_get_map_request_mode ()); + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_show_map_request_mode_command) = { + .path = "show one map-request mode", + .short_help = "show one map-request mode", + .function = lisp_show_map_request_mode_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_show_map_resolvers_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + lisp_msmr_t *mr; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + + vec_foreach (mr, lcm->map_resolvers) + { + vlib_cli_output (vm, "%U", format_ip_address, &mr->address); + } + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_show_map_resolvers_command) = { + .path = "show one map-resolvers", + .short_help = "show one map-resolvers", + .function = lisp_show_map_resolvers_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_nsh_set_locator_set_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + u8 locator_name_set = 0; + u8 *locator_set_name = 0; + u8 is_add = 1; + unformat_input_t _line_input, *line_input = &_line_input; + clib_error_t *error = 0; + int rv = 0; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "ls %_%v%_", &locator_set_name)) + locator_name_set = 1; + else if (unformat (line_input, "disable")) + is_add = 0; + else + { + error = clib_error_return (0, "parse error"); + goto done; + } + } + + if (!locator_name_set) + { + clib_warning ("No locator set specified!"); + goto done; + } + + vec_terminate_c_string (locator_set_name); + rv = vnet_lisp_nsh_set_locator_set (locator_set_name, is_add); + if (0 != rv) + { + error = clib_error_return (0, "failed to %s NSH mapping!", + is_add ? "add" : "delete"); + } + +done: + vec_free (locator_set_name); + unformat_free (line_input); + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_nsh_set_locator_set_command) = { + .path = "one nsh-mapping", + .short_help = "one nsh-mapping [del] ls ", + .function = lisp_nsh_set_locator_set_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_map_register_fallback_threshold_show_command_fn (vlib_main_t * vm, + unformat_input_t * + input, + vlib_cli_command_t * + cmd) +{ + u32 val = vnet_lisp_map_register_fallback_threshold_get (); + vlib_cli_output (vm, "map register fallback threshold value: %d", val); + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_map_register_fallback_threshold_show_command) = { + .path = "show one map-register fallback-threshold", + .short_help = "show one map-register fallback-threshold", + .function = lisp_map_register_fallback_threshold_show_command_fn, +}; + +/* *INDENT-ON* */ + +static clib_error_t * +lisp_map_register_fallback_threshold_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + unformat_input_t _line_input, *line_input = &_line_input; + clib_error_t *error = 0; + u32 val = 0; + int rv = 0; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "%d", &val)) + ; + else + { + error = clib_error_return (0, "parse error"); + goto done; + } + } + + rv = vnet_lisp_map_register_fallback_threshold_set (val); + if (rv) + { + error = clib_error_return (0, "setting fallback threshold failed!"); + } + +done: + unformat_free (line_input); + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_map_register_fallback_threshold_command) = { + .path = "one map-register fallback-threshold", + .short_help = "one map-register fallback-threshold ", + .function = lisp_map_register_fallback_threshold_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_pitr_set_locator_set_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + u8 locator_name_set = 0; + u8 *locator_set_name = 0; + u8 is_add = 1; + unformat_input_t _line_input, *line_input = &_line_input; + clib_error_t *error = 0; + int rv = 0; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "ls %_%v%_", &locator_set_name)) + locator_name_set = 1; + else if (unformat (line_input, "disable")) + is_add = 0; + else + { + error = clib_error_return (0, "parse error"); + goto done; + } + } + + if (!locator_name_set) + { + clib_warning ("No locator set specified!"); + goto done; + } + vec_terminate_c_string (locator_set_name); + rv = vnet_lisp_pitr_set_locator_set (locator_set_name, is_add); + if (0 != rv) + { + error = clib_error_return (0, "failed to %s pitr!", + is_add ? "add" : "delete"); + } + +done: + if (locator_set_name) + vec_free (locator_set_name); + unformat_free (line_input); + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_pitr_set_locator_set_command) = { + .path = "one pitr", + .short_help = "one pitr [disable] ls ", + .function = lisp_pitr_set_locator_set_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_show_pitr_command_fn (vlib_main_t * vm, + unformat_input_t * input, vlib_cli_command_t * cmd) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + mapping_t *m; + locator_set_t *ls; + u8 *tmp_str = 0; + u8 status = lcm->flags & LISP_FLAG_PITR_MODE; + + vlib_cli_output (vm, "%=20s%=16s", "pitr", status ? "locator-set" : ""); + + if (!status) + { + vlib_cli_output (vm, "%=20s", "disable"); + return 0; + } + + if (~0 == lcm->pitr_map_index) + { + tmp_str = format (0, "N/A"); + } + else + { + m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index); + if (~0 != m->locator_set_index) + { + ls = + pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index); + tmp_str = format (0, "%s", ls->name); + } + else + { + tmp_str = format (0, "N/A"); + } + } + vec_add1 (tmp_str, 0); + + vlib_cli_output (vm, "%=20s%=16s", "enable", tmp_str); + + vec_free (tmp_str); + + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_show_pitr_command) = { + .path = "show one pitr", + .short_help = "Show pitr", + .function = lisp_show_pitr_command_fn, +}; +/* *INDENT-ON* */ + +static u8 * +format_eid_entry (u8 * s, va_list * args) +{ + vnet_main_t *vnm = va_arg (*args, vnet_main_t *); + lisp_cp_main_t *lcm = va_arg (*args, lisp_cp_main_t *); + mapping_t *mapit = va_arg (*args, mapping_t *); + locator_set_t *ls = va_arg (*args, locator_set_t *); + gid_address_t *gid = &mapit->eid; + u32 ttl = mapit->ttl; + u8 aut = mapit->authoritative; + u32 *loc_index; + u8 first_line = 1; + u8 *loc; + + u8 *type = ls->local ? format (0, "local(%s)", ls->name) + : format (0, "remote"); + + if (vec_len (ls->locator_indices) == 0) + { + s = format (s, "%-35U%-20saction:%-30U%-20u%-u", format_gid_address, + gid, type, format_negative_mapping_action, mapit->action, + ttl, aut); + } + else + { + vec_foreach (loc_index, ls->locator_indices) + { + locator_t *l = pool_elt_at_index (lcm->locator_pool, loc_index[0]); + if (l->local) + loc = format (0, "%U", format_vnet_sw_if_index_name, vnm, + l->sw_if_index); + else + loc = format (0, "%U", format_ip_address, + &gid_address_ip (&l->address)); + + if (first_line) + { + s = format (s, "%-35U%-20s%-30v%-20u%-u\n", format_gid_address, + gid, type, loc, ttl, aut); + first_line = 0; + } + else + s = format (s, "%55s%v\n", "", loc); + } + } + return s; +} + +static clib_error_t * +lisp_show_eid_table_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + mapping_t *mapit; + unformat_input_t _line_input, *line_input = &_line_input; + u32 mi; + gid_address_t eid; + u8 print_all = 1; + u8 filter = 0; + clib_error_t *error = NULL; + + clib_memset (&eid, 0, sizeof (eid)); + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "eid %U", unformat_gid_address, &eid)) + print_all = 0; + else if (unformat (line_input, "local")) + filter = 1; + else if (unformat (line_input, "remote")) + filter = 2; + else + { + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + goto done; + } + } + + vlib_cli_output (vm, "%-35s%-20s%-30s%-20s%-s", + "EID", "type", "locators", "ttl", "authoritative"); + + if (print_all) + { + /* *INDENT-OFF* */ + pool_foreach (mapit, lcm->mapping_pool, + ({ + if (mapit->pitr_set || mapit->nsh_set) + continue; + + locator_set_t * ls = pool_elt_at_index (lcm->locator_set_pool, + mapit->locator_set_index); + if (filter && !((1 == filter && ls->local) || + (2 == filter && !ls->local))) + { + continue; + } + vlib_cli_output (vm, "%U", format_eid_entry, lcm->vnet_main, + lcm, mapit, ls); + })); + /* *INDENT-ON* */ + } + else + { + mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &eid); + if ((u32) ~ 0 == mi) + goto done; + + mapit = pool_elt_at_index (lcm->mapping_pool, mi); + locator_set_t *ls = pool_elt_at_index (lcm->locator_set_pool, + mapit->locator_set_index); + + if (filter && !((1 == filter && ls->local) || + (2 == filter && !ls->local))) + { + goto done; + } + + vlib_cli_output (vm, "%U,", format_eid_entry, lcm->vnet_main, + lcm, mapit, ls); + } + +done: + unformat_free (line_input); + + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_cp_show_eid_table_command) = { + .path = "show one eid-table", + .short_help = "show one eid-table [local|remote|eid ]", + .function = lisp_show_eid_table_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_enable_disable_pitr_mode_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + unformat_input_t _line_input, *line_input = &_line_input; + u8 is_enabled = 0; + u8 is_set = 0; + clib_error_t *error = NULL; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return clib_error_return (0, "expected enable | disable"); + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "enable")) + { + is_set = 1; + is_enabled = 1; + } + else if (unformat (line_input, "disable")) + is_set = 1; + else + { + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + goto done; + } + } + + if (!is_set) + { + error = clib_error_return (0, "state not set"); + goto done; + } + + vnet_lisp_enable_disable_pitr_mode (is_enabled); + +done: + unformat_free (line_input); + + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_cp_enable_disable_pitr_mode_command) = { + .path = "one pitr mode", + .short_help = "one pitr mode [enable|disable]", + .function = lisp_enable_disable_pitr_mode_command_fn, +}; +/* *INDENT-ON* */ + + +static clib_error_t * +lisp_enable_disable_petr_mode_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + unformat_input_t _line_input, *line_input = &_line_input; + u8 is_enabled = 0; + u8 is_set = 0; + clib_error_t *error = NULL; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return clib_error_return (0, "expected enable | disable"); + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "enable")) + { + is_set = 1; + is_enabled = 1; + } + else if (unformat (line_input, "disable")) + is_set = 1; + else + { + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + goto done; + } + } + + if (!is_set) + { + error = clib_error_return (0, "state not set"); + goto done; + } + + vnet_lisp_enable_disable_petr_mode (is_enabled); + +done: + unformat_free (line_input); + + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_cp_enable_disable_petr_mode_command) = { + .path = "one petr mode", + .short_help = "one petr mode [enable|disable]", + .function = lisp_enable_disable_petr_mode_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_enable_disable_xtr_mode_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + unformat_input_t _line_input, *line_input = &_line_input; + u8 is_enabled = 0; + u8 is_set = 0; + clib_error_t *error = NULL; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return clib_error_return (0, "expected enable | disable"); + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "enable")) + { + is_set = 1; + is_enabled = 1; + } + else if (unformat (line_input, "disable")) + is_set = 1; + else + { + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + goto done; + } + } + + if (!is_set) + { + error = clib_error_return (0, "state not set"); + goto done; + } + + vnet_lisp_enable_disable_xtr_mode (is_enabled); + +done: + unformat_free (line_input); + + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_cp_enable_disable_xtr_mode_command) = { + .path = "one xtr mode", + .short_help = "one xtr mode [enable|disable]", + .function = lisp_enable_disable_xtr_mode_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +one_enable_command_fn (vlib_main_t * vm, unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + return clib_error_return (0, "parse error: '%U'", format_unformat_error, + input); + + vnet_lisp_enable_disable (1); + + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_cp_enable_command) = { + .path = "one enable", + .short_help = "one enable", + .function = one_enable_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +one_disable_command_fn (vlib_main_t * vm, unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + return clib_error_return (0, "parse error: '%U'", format_unformat_error, + input); + + vnet_lisp_enable_disable (0); + + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_cp_disable_command) = { + .path = "one disable", + .short_help = "one disable", + .function = one_disable_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_map_register_set_ttl_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + unformat_input_t _line_input, *line_input = &_line_input; + u32 ttl = 0; + u8 is_set = 0; + clib_error_t *error = NULL; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return clib_error_return (0, "expected enable | disable"); + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "%u", &ttl)) + is_set = 1; + else + { + vlib_cli_output (vm, "parse error: '%U'", format_unformat_error, + line_input); + goto done; + } + } + + if (!is_set) + { + vlib_cli_output (vm, "expected integer value for TTL!"); + goto done; + } + + vnet_lisp_map_register_set_ttl (ttl); + +done: + unformat_free (line_input); + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_map_register_set_ttl_command) = { + .path = "one map-register ttl", + .short_help = "one map-register ttl", + .function = lisp_map_register_set_ttl_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_map_register_show_ttl_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + u32 ttl = vnet_lisp_map_register_get_ttl (); + + vlib_cli_output (vm, "map-register TTL: %u", ttl); + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_map_register_show_ttl_command) = { + .path = "show one map-register ttl", + .short_help = "show one map-register ttl", + .function = lisp_map_register_show_ttl_command_fn, +}; + +/* *INDENT-ON* */ + +static clib_error_t * +lisp_map_register_enable_disable_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + unformat_input_t _line_input, *line_input = &_line_input; + u8 is_enabled = 0; + u8 is_set = 0; + clib_error_t *error = NULL; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return clib_error_return (0, "expected enable | disable"); + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "enable")) + { + is_set = 1; + is_enabled = 1; + } + else if (unformat (line_input, "disable")) + is_set = 1; + else + { + vlib_cli_output (vm, "parse error: '%U'", format_unformat_error, + line_input); + goto done; + } + } + + if (!is_set) + { + vlib_cli_output (vm, "state not set!"); + goto done; + } + + vnet_lisp_map_register_enable_disable (is_enabled); + +done: + unformat_free (line_input); + + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_map_register_enable_disable_command) = { + .path = "one map-register", + .short_help = "one map-register [enable|disable]", + .function = lisp_map_register_enable_disable_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_rloc_probe_enable_disable_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + unformat_input_t _line_input, *line_input = &_line_input; + u8 is_enabled = 0; + u8 is_set = 0; + clib_error_t *error = NULL; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return clib_error_return (0, "expected enable | disable"); + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "enable")) + { + is_set = 1; + is_enabled = 1; + } + else if (unformat (line_input, "disable")) + is_set = 1; + else + { + vlib_cli_output (vm, "parse error: '%U'", format_unformat_error, + line_input); + goto done; + } + } + + if (!is_set) + { + vlib_cli_output (vm, "state not set!"); + goto done; + } + + vnet_lisp_rloc_probe_enable_disable (is_enabled); + +done: + unformat_free (line_input); + + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_rloc_probe_enable_disable_command) = { + .path = "one rloc-probe", + .short_help = "one rloc-probe [enable|disable]", + .function = lisp_rloc_probe_enable_disable_command_fn, +}; +/* *INDENT-ON* */ + +static u8 * +format_lisp_status (u8 * s, va_list * args) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + return format (s, "%s", lcm->is_enabled ? "enabled" : "disabled"); +} + +static clib_error_t * +lisp_show_status_command_fn (vlib_main_t * vm, unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + u8 *msg = 0; + msg = format (msg, "feature: %U\ngpe: %U\n", + format_lisp_status, format_vnet_lisp_gpe_status); + vlib_cli_output (vm, "%v", msg); + vec_free (msg); + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_show_status_command) = { + .path = "show one status", + .short_help = "show one status", + .function = lisp_show_status_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_show_eid_table_map_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + hash_pair_t *p; + unformat_input_t _line_input, *line_input = &_line_input; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + uword *vni_table = 0; + u8 is_l2 = 0; + clib_error_t *error = NULL; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "l2")) + { + vni_table = lcm->bd_id_by_vni; + is_l2 = 1; + } + else if (unformat (line_input, "l3")) + { + vni_table = lcm->table_id_by_vni; + is_l2 = 0; + } + else + { + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + goto done; + } + } + + if (!vni_table) + { + vlib_cli_output (vm, "Error: expected l2|l3 param!\n"); + goto done; + } + + vlib_cli_output (vm, "%=10s%=10s", "VNI", is_l2 ? "BD" : "VRF"); + + /* *INDENT-OFF* */ + hash_foreach_pair (p, vni_table, + ({ + vlib_cli_output (vm, "%=10d%=10d", p->key, p->value[0]); + })); + /* *INDENT-ON* */ + +done: + unformat_free (line_input); + + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_show_eid_table_map_command) = { + .path = "show one eid-table map", + .short_help = "show one eid-table map l2|l3", + .function = lisp_show_eid_table_map_command_fn, +}; +/* *INDENT-ON* */ + + +static clib_error_t * +lisp_add_del_locator_set_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + lisp_gpe_main_t *lgm = &lisp_gpe_main; + vnet_main_t *vnm = lgm->vnet_main; + unformat_input_t _line_input, *line_input = &_line_input; + u8 is_add = 1; + clib_error_t *error = 0; + u8 *locator_set_name = 0; + locator_t locator, *locators = 0; + vnet_lisp_add_del_locator_set_args_t _a, *a = &_a; + u32 ls_index = 0; + int rv = 0; + + clib_memset (&locator, 0, sizeof (locator)); + clib_memset (a, 0, sizeof (a[0])); + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "add %_%v%_", &locator_set_name)) + is_add = 1; + else if (unformat (line_input, "del %_%v%_", &locator_set_name)) + is_add = 0; + else if (unformat (line_input, "iface %U p %d w %d", + unformat_vnet_sw_interface, vnm, + &locator.sw_if_index, &locator.priority, + &locator.weight)) + { + locator.local = 1; + locator.state = 1; + vec_add1 (locators, locator); + } + else + { + error = unformat_parse_error (line_input); + goto done; + } + } + + vec_terminate_c_string (locator_set_name); + a->name = locator_set_name; + a->locators = locators; + a->is_add = is_add; + a->local = 1; + + rv = vnet_lisp_add_del_locator_set (a, &ls_index); + if (0 != rv) + { + error = clib_error_return (0, "failed to %s locator-set!", + is_add ? "add" : "delete"); + } + +done: + vec_free (locators); + if (locator_set_name) + vec_free (locator_set_name); + unformat_free (line_input); + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_cp_add_del_locator_set_command) = { + .path = "one locator-set", + .short_help = "one locator-set add/del [iface " + "p w ]", + .function = lisp_add_del_locator_set_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_add_del_locator_in_set_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + lisp_gpe_main_t *lgm = &lisp_gpe_main; + vnet_main_t *vnm = lgm->vnet_main; + unformat_input_t _line_input, *line_input = &_line_input; + u8 is_add = 1; + clib_error_t *error = 0; + u8 *locator_set_name = 0; + u8 locator_set_name_set = 0; + locator_t locator, *locators = 0; + vnet_lisp_add_del_locator_set_args_t _a, *a = &_a; + u32 ls_index = 0; + + clib_memset (&locator, 0, sizeof (locator)); + clib_memset (a, 0, sizeof (a[0])); + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "add")) + is_add = 1; + else if (unformat (line_input, "del")) + is_add = 0; + else if (unformat (line_input, "locator-set %_%v%_", &locator_set_name)) + locator_set_name_set = 1; + else if (unformat (line_input, "iface %U p %d w %d", + unformat_vnet_sw_interface, vnm, + &locator.sw_if_index, &locator.priority, + &locator.weight)) + { + locator.local = 1; + vec_add1 (locators, locator); + } + else + { + error = unformat_parse_error (line_input); + goto done; + } + } + + if (!locator_set_name_set) + { + error = clib_error_return (0, "locator_set name not set!"); + goto done; + } + + vec_terminate_c_string (locator_set_name); + a->name = locator_set_name; + a->locators = locators; + a->is_add = is_add; + a->local = 1; + + vnet_lisp_add_del_locator (a, 0, &ls_index); + +done: + vec_free (locators); + vec_free (locator_set_name); + unformat_free (line_input); + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_cp_add_del_locator_in_set_command) = { + .path = "one locator", + .short_help = "one locator add/del locator-set iface " + "p w ", + .function = lisp_add_del_locator_in_set_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_cp_show_locator_sets_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + locator_set_t *lsit; + locator_t *loc; + u32 *locit; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + + vlib_cli_output (vm, "%s%=16s%=16s%=16s", "Locator-set", "Locator", + "Priority", "Weight"); + + /* *INDENT-OFF* */ + pool_foreach (lsit, lcm->locator_set_pool, + ({ + u8 * msg = 0; + int next_line = 0; + if (lsit->local) + { + msg = format (msg, "%s", lsit->name); + } + else + { + msg = format (msg, "<%s-%d>", "remote", lsit - lcm->locator_set_pool); + } + vec_foreach (locit, lsit->locator_indices) + { + if (next_line) + { + msg = format (msg, "%16s", " "); + } + loc = pool_elt_at_index (lcm->locator_pool, locit[0]); + if (loc->local) + msg = format (msg, "%16d%16d%16d\n", loc->sw_if_index, loc->priority, + loc->weight); + else + msg = format (msg, "%16U%16d%16d\n", format_ip_address, + &gid_address_ip(&loc->address), loc->priority, + loc->weight); + next_line = 1; + } + vlib_cli_output (vm, "%v", msg); + vec_free (msg); + })); + /* *INDENT-ON* */ + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_cp_show_locator_sets_command) = { + .path = "show one locator-set", + .short_help = "Shows locator-sets", + .function = lisp_cp_show_locator_sets_command_fn, +}; +/* *INDENT-ON* */ + + +static clib_error_t * +lisp_add_del_map_resolver_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + unformat_input_t _line_input, *line_input = &_line_input; + u8 is_add = 1, addr_set = 0; + ip_address_t ip_addr; + clib_error_t *error = 0; + int rv = 0; + vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "add")) + is_add = 1; + else if (unformat (line_input, "del")) + is_add = 0; + else if (unformat (line_input, "%U", unformat_ip_address, &ip_addr)) + addr_set = 1; + else + { + error = unformat_parse_error (line_input); + goto done; + } + } + + if (!addr_set) + { + error = clib_error_return (0, "Map-resolver address must be set!"); + goto done; + } + + a->is_add = is_add; + a->address = ip_addr; + rv = vnet_lisp_add_del_map_resolver (a); + if (0 != rv) + { + error = clib_error_return (0, "failed to %s map-resolver!", + is_add ? "add" : "delete"); + } + +done: + unformat_free (line_input); + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_add_del_map_resolver_command) = { + .path = "one map-resolver", + .short_help = "one map-resolver add/del ", + .function = lisp_add_del_map_resolver_command_fn, +}; +/* *INDENT-ON* */ + + +static clib_error_t * +lisp_add_del_mreq_itr_rlocs_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + unformat_input_t _line_input, *line_input = &_line_input; + u8 is_add = 1; + u8 *locator_set_name = 0; + clib_error_t *error = 0; + int rv = 0; + vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "del")) + is_add = 0; + else if (unformat (line_input, "add %_%v%_", &locator_set_name)) + is_add = 1; + else + { + error = unformat_parse_error (line_input); + goto done; + } + } + + vec_terminate_c_string (locator_set_name); + a->is_add = is_add; + a->locator_set_name = locator_set_name; + rv = vnet_lisp_add_del_mreq_itr_rlocs (a); + if (0 != rv) + { + error = clib_error_return (0, "failed to %s map-request itr-rlocs!", + is_add ? "add" : "delete"); + } + +done: + vec_free (locator_set_name); + unformat_free (line_input); + return error; + +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_add_del_map_request_command) = { + .path = "one map-request itr-rlocs", + .short_help = "one map-request itr-rlocs add/del ", + .function = lisp_add_del_mreq_itr_rlocs_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_show_mreq_itr_rlocs_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + locator_set_t *loc_set; + + vlib_cli_output (vm, "%=20s", "itr-rlocs"); + + if (~0 == lcm->mreq_itr_rlocs) + { + return 0; + } + + loc_set = pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs); + + vlib_cli_output (vm, "%=20s", loc_set->name); + + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_show_map_request_command) = { + .path = "show one map-request itr-rlocs", + .short_help = "Shows map-request itr-rlocs", + .function = lisp_show_mreq_itr_rlocs_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_use_petr_set_locator_set_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + u8 is_add = 1, ip_set = 0; + unformat_input_t _line_input, *line_input = &_line_input; + clib_error_t *error = 0; + ip_address_t ip; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "%U", unformat_ip_address, &ip)) + ip_set = 1; + else if (unformat (line_input, "disable")) + is_add = 0; + else + { + error = clib_error_return (0, "parse error"); + goto done; + } + } + + if (!ip_set) + { + clib_warning ("No petr IP specified!"); + goto done; + } + + if (vnet_lisp_use_petr (&ip, is_add)) + { + error = clib_error_return (0, "failed to %s petr!", + is_add ? "add" : "delete"); + } + +done: + unformat_free (line_input); + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_use_petr_set_locator_set_command) = { + .path = "one use-petr", + .short_help = "one use-petr [disable] ", + .function = lisp_use_petr_set_locator_set_command_fn, +}; + +static clib_error_t * +lisp_show_petr_command_fn (vlib_main_t * vm, + unformat_input_t * input, vlib_cli_command_t * cmd) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + mapping_t *m; + locator_set_t *ls; + locator_t *loc; + u8 *tmp_str = 0; + u8 use_petr = lcm->flags & LISP_FLAG_USE_PETR; + vlib_cli_output (vm, "%=20s%=16s", "petr", use_petr ? "ip" : ""); + + if (!use_petr) + { + vlib_cli_output (vm, "%=20s", "disable"); + return 0; + } + + if (~0 == lcm->petr_map_index) + { + tmp_str = format (0, "N/A"); + } + else + { + m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index); + if (~0 != m->locator_set_index) + { + ls = pool_elt_at_index(lcm->locator_set_pool, m->locator_set_index); + loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]); + tmp_str = format (0, "%U", format_ip_address, &loc->address); + } + else + { + tmp_str = format (0, "N/A"); + } + } + vec_add1 (tmp_str, 0); + + vlib_cli_output (vm, "%=20s%=16s", "enable", tmp_str); + + vec_free (tmp_str); + + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_show_petr_command) = { + .path = "show one petr", + .short_help = "Show petr", + .function = lisp_show_petr_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_show_map_servers_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + lisp_msmr_t *ms; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + + vec_foreach (ms, lcm->map_servers) + { + vlib_cli_output (vm, "%U", format_ip_address, &ms->address); + } + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_show_map_servers_command) = { + .path = "show one map-servers", + .short_help = "show one map servers", + .function = lisp_show_map_servers_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_show_map_register_state_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + u8 *msg = 0; + u8 is_enabled = vnet_lisp_map_register_state_get (); + + msg = format (msg, "%s\n", is_enabled ? "enabled" : "disabled"); + vlib_cli_output (vm, "%v", msg); + vec_free (msg); + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_show_map_register_state_command) = { + .path = "show one map-register state", + .short_help = "show one map-register state", + .function = lisp_show_map_register_state_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_show_rloc_probe_state_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + u8 *msg = 0; + u8 is_enabled = vnet_lisp_rloc_probe_state_get (); + + msg = format (msg, "%s\n", is_enabled ? "enabled" : "disabled"); + vlib_cli_output (vm, "%v", msg); + vec_free (msg); + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_show_rloc_probe_state_command) = { + .path = "show one rloc state", + .short_help = "show one RLOC state", + .function = lisp_show_rloc_probe_state_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_show_stats_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + u8 is_enabled = vnet_lisp_stats_enable_disable_state (); + vlib_cli_output (vm, "%s\n", is_enabled ? "enabled" : "disabled"); + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_show_stats_command) = { + .path = "show one statistics status", + .short_help = "show ONE statistics enable/disable status", + .function = lisp_show_stats_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_show_stats_details_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + lisp_api_stats_t *stat, *stats = vnet_lisp_get_stats (); + + if (vec_len (stats) > 0) + vlib_cli_output (vm, + "[src-EID, dst-EID] [loc-rloc, rmt-rloc] count bytes\n"); + else + vlib_cli_output (vm, "No statistics found.\n"); + + vec_foreach (stat, stats) + { + vlib_cli_output (vm, "[%U, %U] [%U, %U] %7u %7u\n", + format_fid_address, &stat->seid, + format_fid_address, &stat->deid, + format_ip_address, &stat->loc_rloc, + format_ip_address, &stat->rmt_rloc, + stat->counters.packets, stat->counters.bytes); + } + vec_free (stats); + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_show_stats_details_command) = { + .path = "show one statistics details", + .short_help = "show ONE statistics", + .function = lisp_show_stats_details_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_stats_enable_disable_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + unformat_input_t _line_input, *line_input = &_line_input; + u8 enable = 0; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return clib_error_return (0, "expected enable | disable"); + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "enable")) + enable = 1; + else if (unformat (line_input, "disable")) + enable = 0; + else + { + clib_warning ("Error: expected enable/disable!"); + goto done; + } + } + vnet_lisp_stats_enable_disable (enable); +done: + unformat_free (line_input); + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_stats_enable_disable_command) = { + .path = "one statistics", + .short_help = "enable/disable ONE statistics collecting", + .function = lisp_stats_enable_disable_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_stats_flush_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + vnet_lisp_flush_stats (); + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_stats_flush_command) = { + .path = "one statistics flush", + .short_help = "Flush ONE statistics", + .function = lisp_stats_flush_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_show_one_modes_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + u8 pitr_mode = vnet_lisp_get_pitr_mode (); + u8 petr_mode = vnet_lisp_get_petr_mode (); + u8 xtr_mode = vnet_lisp_get_xtr_mode (); + + vlib_cli_output (vm, "xTR: %s\n", xtr_mode ? "enabled" : "disabled"); + vlib_cli_output (vm, "P-ITR: %s\n", pitr_mode ? "enabled" : "disabled"); + vlib_cli_output (vm, "P-ETR: %s\n", petr_mode ? "enabled" : "disabled"); + + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (one_cp_show_one_modes_modes_command) = { + .path = "show one modes", + .short_help = "show one modes", + .function = lisp_show_one_modes_command_fn, +}; +/* *INDENT-ON* */ + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/lisp/lisp-cp/one_test.c b/src/plugins/lisp/lisp-cp/one_test.c new file mode 100644 index 00000000000..42554576fa0 --- /dev/null +++ b/src/plugins/lisp/lisp-cp/one_test.c @@ -0,0 +1,3101 @@ +/* + * Copyright (c) 2015 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include +#include +#include + +/* define message IDs */ +#include +#include +#include + +typedef struct +{ + /* API message ID base */ + u16 msg_id_base; + u32 ping_id; + vat_main_t *vat_main; +} one_test_main_t; + +one_test_main_t one_test_main; + +#define __plugin_msg_base one_test_main.msg_id_base +#include + +/* Macro to finish up custom dump fns */ +#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) +#define FINISH \ + vec_add1 (s, 0); \ + vl_print (handle, (char *)s); \ + vec_free (s); \ + return handle; + +#define LISP_PING(_lm, mp_ping) \ + if (!(_lm)->ping_id) \ + (_lm)->ping_id = vl_msg_api_get_msg_index ((u8 *) (VL_API_CONTROL_PING_CRC)); \ + mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping)); \ + mp_ping->_vl_msg_id = htons ((_lm)->ping_id); \ + mp_ping->client_index = vam->my_client_index; \ + fformat (vam->ofp, "Sending ping id=%d\n", (_lm)->ping_id); \ + vam->result_ready = 0; \ + +typedef struct +{ + u32 spi; + u8 si; +} __attribute__ ((__packed__)) lisp_nsh_api_t; + +static uword +unformat_nsh_address (unformat_input_t * input, va_list * args) +{ + lisp_nsh_api_t *nsh = va_arg (*args, lisp_nsh_api_t *); + return unformat (input, "SPI:%d SI:%d", &nsh->spi, &nsh->si); +} + +static u8 * +format_nsh_address_vat (u8 * s, va_list * args) +{ + nsh_t *a = va_arg (*args, nsh_t *); + return format (s, "SPI:%d SI:%d", clib_net_to_host_u32 (a->spi), a->si); +} + +static u8 * +format_lisp_transport_protocol (u8 * s, va_list * args) +{ + u32 proto = va_arg (*args, u32); + + switch (proto) + { + case 1: + return format (s, "udp"); + case 2: + return format (s, "api"); + default: + return 0; + } + return 0; +} + +static void +vl_api_one_locator_details_t_handler (vl_api_one_locator_details_t * mp) +{ + vat_main_t *vam = &vat_main; + u8 *s = 0; + + if (mp->local) + { + s = format (s, "%=16d%=16d%=16d", + ntohl (mp->sw_if_index), mp->priority, mp->weight); + } + else + { + s = format (s, "%=16U%=16d%=16d", + format_ip46_address, + mp->ip_address, mp->priority, mp->weight); + } + + print (vam->ofp, "%v", s); + vec_free (s); +} + +static void +vl_api_one_locator_set_details_t_handler (vl_api_one_locator_set_details_t * + mp) +{ + vat_main_t *vam = &vat_main; + u8 *ls_name = 0; + + ls_name = format (0, "%s", mp->ls_name); + + print (vam->ofp, "%=10d%=15v", clib_net_to_host_u32 (mp->ls_index), + ls_name); + vec_free (ls_name); +} + +static void vl_api_one_get_transport_protocol_reply_t_handler + (vl_api_one_get_transport_protocol_reply_t * mp) +{ + vat_main_t *vam = &vat_main; + i32 retval = ntohl (mp->retval); + if (vam->async_mode) + { + vam->async_errors += (retval < 0); + } + else + { + u32 proto = mp->protocol; + print (vam->ofp, "Transport protocol: %U", + format_lisp_transport_protocol, proto); + vam->retval = retval; + vam->result_ready = 1; + } +} + +static void vl_api_one_add_del_locator_set_reply_t_handler + (vl_api_one_add_del_locator_set_reply_t * mp) +{ + vat_main_t *vam = &vat_main; + i32 retval = ntohl (mp->retval); + if (vam->async_mode) + { + vam->async_errors += (retval < 0); + } + else + { + vam->retval = retval; + vam->result_ready = 1; + } +} + +static u8 * +format_lisp_flat_eid (u8 * s, va_list * args) +{ + vl_api_eid_t *eid = va_arg (*args, vl_api_eid_t *); + + switch (eid->type) + { + case EID_TYPE_API_PREFIX: + if (eid->address.prefix.address.af) + return format (s, "%U/%d", format_ip6_address, + eid->address.prefix.address.un.ip6, + eid->address.prefix.len); + return format (s, "%U/%d", format_ip4_address, + eid->address.prefix.address.un.ip4, + eid->address.prefix.len); + case EID_TYPE_API_MAC: + return format (s, "%U", format_ethernet_address, eid->address.mac); + case EID_TYPE_API_NSH: + return format (s, "%U", format_nsh_address_vat, eid->address.nsh); + } + return 0; +} + +static u8 * +format_lisp_eid_vat (u8 * s, va_list * args) +{ + vl_api_eid_t *deid = va_arg (*args, vl_api_eid_t *); + vl_api_eid_t *seid = va_arg (*args, vl_api_eid_t *); + u8 is_src_dst = (u8) va_arg (*args, int); + + if (is_src_dst) + s = format (s, "%U|", format_lisp_flat_eid, seid); + + s = format (s, "%U", format_lisp_flat_eid, deid); + + return s; +} + +static void +vl_api_one_eid_table_details_t_handler (vl_api_one_eid_table_details_t * mp) +{ + vat_main_t *vam = &vat_main; + u8 *s = 0, *eid = 0; + + if (~0 == mp->locator_set_index) + s = format (0, "action: %d", mp->action); + else + s = format (0, "%d", clib_net_to_host_u32 (mp->locator_set_index)); + + eid = format (0, "%U", format_lisp_eid_vat, + &mp->deid, &mp->seid, mp->is_src_dst); + vec_add1 (eid, 0); + + print (vam->ofp, "[%d] %-35s%-20s%-30s%-20d%-20d%-10d%-20s", + clib_net_to_host_u32 (mp->vni), + eid, + mp->is_local ? "local" : "remote", + s, clib_net_to_host_u32 (mp->ttl), mp->authoritative, + clib_net_to_host_u16 (mp->key.id), mp->key.key); + + vec_free (s); + vec_free (eid); +} + +static void +vl_api_one_stats_details_t_handler (vl_api_one_stats_details_t * mp) +{ + vat_main_t *vam = &vat_main; + u8 *seid = 0, *deid = 0; + ip46_address_t lloc, rloc; + + deid = format (0, "%U", format_lisp_eid_vat, &mp->deid, 0, 0); + + seid = format (0, "%U", format_lisp_eid_vat, &mp->seid, 0, 0); + + vec_add1 (deid, 0); + vec_add1 (seid, 0); + + if (mp->lloc.af) + { + clib_memcpy (&lloc.ip6, mp->lloc.un.ip6, 16); + clib_memcpy (&rloc.ip6, mp->rloc.un.ip6, 16); + } + else + { + clib_memcpy (&lloc.ip4, mp->lloc.un.ip4, 4); + clib_memcpy (&rloc.ip4, mp->rloc.un.ip4, 4); + } + + + print (vam->ofp, "([%d] %s %s) (%U %U) %u %u", + clib_net_to_host_u32 (mp->vni), + seid, deid, + format_ip46_address, lloc, + format_ip46_address, rloc, + clib_net_to_host_u32 (mp->pkt_count), + clib_net_to_host_u32 (mp->bytes)); + + vec_free (deid); + vec_free (seid); +} + +static void + vl_api_one_eid_table_map_details_t_handler + (vl_api_one_eid_table_map_details_t * mp) +{ + vat_main_t *vam = &vat_main; + + u8 *line = format (0, "%=10d%=10d", + clib_net_to_host_u32 (mp->vni), + clib_net_to_host_u32 (mp->dp_table)); + print (vam->ofp, "%v", line); + vec_free (line); +} + +static void + vl_api_one_eid_table_vni_details_t_handler + (vl_api_one_eid_table_vni_details_t * mp) +{ + vat_main_t *vam = &vat_main; + + u8 *line = format (0, "%d", clib_net_to_host_u32 (mp->vni)); + print (vam->ofp, "%v", line); + vec_free (line); +} + +static void + vl_api_show_one_map_register_fallback_threshold_reply_t_handler + (vl_api_show_one_map_register_fallback_threshold_reply_t * mp) +{ + vat_main_t *vam = &vat_main; + int retval = clib_net_to_host_u32 (mp->retval); + + print (vam->ofp, "fallback threshold value: %d", mp->value); + + vam->retval = retval; + vam->result_ready = 1; +} + +static void + vl_api_show_one_map_register_state_reply_t_handler + (vl_api_show_one_map_register_state_reply_t * mp) +{ + vat_main_t *vam = &vat_main; + int retval = clib_net_to_host_u32 (mp->retval); + + print (vam->ofp, "%s", mp->is_enable ? "enabled" : "disabled"); + + vam->retval = retval; + vam->result_ready = 1; +} + +static void + vl_api_show_one_rloc_probe_state_reply_t_handler + (vl_api_show_one_rloc_probe_state_reply_t * mp) +{ + vat_main_t *vam = &vat_main; + int retval = clib_net_to_host_u32 (mp->retval); + + if (retval) + goto end; + + print (vam->ofp, "%s", mp->is_enable ? "enabled" : "disabled"); +end: + vam->retval = retval; + vam->result_ready = 1; +} + +static void + vl_api_show_one_stats_enable_disable_reply_t_handler + (vl_api_show_one_stats_enable_disable_reply_t * mp) +{ + vat_main_t *vam = &vat_main; + int retval = clib_net_to_host_u32 (mp->retval); + + if (retval) + goto end; + + print (vam->ofp, "%s", mp->is_enable ? "enabled" : "disabled"); +end: + vam->retval = retval; + vam->result_ready = 1; +} + +static void + vl_api_one_ndp_entries_get_reply_t_handler + (vl_api_one_ndp_entries_get_reply_t * mp) +{ + vat_main_t *vam = &vat_main; + u32 i, n; + int retval = clib_net_to_host_u32 (mp->retval); + + if (retval) + goto end; + + n = clib_net_to_host_u32 (mp->count); + + for (i = 0; i < n; i++) + print (vam->ofp, "%U -> %U", format_ip6_address, &mp->entries[i].ip6, + format_ethernet_address, mp->entries[i].mac); + +end: + vam->retval = retval; + vam->result_ready = 1; +} + +static void + vl_api_one_l2_arp_entries_get_reply_t_handler + (vl_api_one_l2_arp_entries_get_reply_t * mp) +{ + vat_main_t *vam = &vat_main; + u32 i, n; + int retval = clib_net_to_host_u32 (mp->retval); + + if (retval) + goto end; + + n = clib_net_to_host_u32 (mp->count); + + for (i = 0; i < n; i++) + print (vam->ofp, "%U -> %U", format_ip4_address, &mp->entries[i].ip4, + format_ethernet_address, mp->entries[i].mac); + +end: + vam->retval = retval; + vam->result_ready = 1; +} + +static void +vl_api_one_ndp_bd_get_reply_t_handler (vl_api_one_ndp_bd_get_reply_t * mp) +{ + vat_main_t *vam = &vat_main; + u32 i, n; + int retval = clib_net_to_host_u32 (mp->retval); + + if (retval) + goto end; + + n = clib_net_to_host_u32 (mp->count); + + for (i = 0; i < n; i++) + { + print (vam->ofp, "%d", clib_net_to_host_u32 (mp->bridge_domains[i])); + } + +end: + vam->retval = retval; + vam->result_ready = 1; +} + +static void + vl_api_one_l2_arp_bd_get_reply_t_handler + (vl_api_one_l2_arp_bd_get_reply_t * mp) +{ + vat_main_t *vam = &vat_main; + u32 i, n; + int retval = clib_net_to_host_u32 (mp->retval); + + if (retval) + goto end; + + n = clib_net_to_host_u32 (mp->count); + + for (i = 0; i < n; i++) + { + print (vam->ofp, "%d", clib_net_to_host_u32 (mp->bridge_domains[i])); + } + +end: + vam->retval = retval; + vam->result_ready = 1; +} + +static void + vl_api_one_adjacencies_get_reply_t_handler + (vl_api_one_adjacencies_get_reply_t * mp) +{ + vat_main_t *vam = &vat_main; + u32 i, n; + int retval = clib_net_to_host_u32 (mp->retval); + vl_api_one_adjacency_t *a; + + if (retval) + goto end; + + n = clib_net_to_host_u32 (mp->count); + + for (i = 0; i < n; i++) + { + a = &mp->adjacencies[i]; + print (vam->ofp, "%U %40U", + format_lisp_flat_eid, a->leid, format_lisp_flat_eid, a->reid); + } + +end: + vam->retval = retval; + vam->result_ready = 1; +} + +static void +vl_api_one_map_server_details_t_handler (vl_api_one_map_server_details_t * mp) +{ + vat_main_t *vam = &vat_main; + + print (vam->ofp, "%=20U", + mp->ip_address.af ? format_ip6_address : format_ip4_address, + mp->ip_address.un); +} + +static void +vl_api_one_map_resolver_details_t_handler (vl_api_one_map_resolver_details_t + * mp) +{ + vat_main_t *vam = &vat_main; + + print (vam->ofp, "%=20U", + mp->ip_address.af ? format_ip6_address : format_ip4_address, + mp->ip_address.un); +} + +static void +vl_api_show_one_status_reply_t_handler (vl_api_show_one_status_reply_t * mp) +{ + vat_main_t *vam = &vat_main; + i32 retval = ntohl (mp->retval); + + if (0 <= retval) + { + print (vam->ofp, "feature: %s\ngpe: %s", + mp->feature_status ? "enabled" : "disabled", + mp->gpe_status ? "enabled" : "disabled"); + } + + vam->retval = retval; + vam->result_ready = 1; +} + +static void + vl_api_one_get_map_request_itr_rlocs_reply_t_handler + (vl_api_one_get_map_request_itr_rlocs_reply_t * mp) +{ + vat_main_t *vam = &vat_main; + i32 retval = ntohl (mp->retval); + + if (retval >= 0) + { + print (vam->ofp, "%=20s", mp->locator_set_name); + } + + vam->retval = retval; + vam->result_ready = 1; +} + +static u8 * +format_lisp_map_request_mode (u8 * s, va_list * args) +{ + u32 mode = va_arg (*args, u32); + + switch (mode) + { + case 0: + return format (0, "dst-only"); + case 1: + return format (0, "src-dst"); + } + return 0; +} + +static void + vl_api_show_one_map_request_mode_reply_t_handler + (vl_api_show_one_map_request_mode_reply_t * mp) +{ + vat_main_t *vam = &vat_main; + i32 retval = ntohl (mp->retval); + + if (0 <= retval) + { + u32 mode = mp->mode; + print (vam->ofp, "map_request_mode: %U", + format_lisp_map_request_mode, mode); + } + + vam->retval = retval; + vam->result_ready = 1; +} + +static void + vl_api_one_show_xtr_mode_reply_t_handler + (vl_api_one_show_xtr_mode_reply_t * mp) +{ + vat_main_t *vam = &vat_main; + i32 retval = ntohl (mp->retval); + + if (0 <= retval) + { + print (vam->ofp, "%s\n", mp->is_enable ? "enabled" : "disabled"); + } + + vam->retval = retval; + vam->result_ready = 1; +} + +static void + vl_api_one_show_pitr_mode_reply_t_handler + (vl_api_one_show_pitr_mode_reply_t * mp) +{ + vat_main_t *vam = &vat_main; + i32 retval = ntohl (mp->retval); + + if (0 <= retval) + { + print (vam->ofp, "%s\n", mp->is_enable ? "enabled" : "disabled"); + } + + vam->retval = retval; + vam->result_ready = 1; +} + +static void + vl_api_one_show_petr_mode_reply_t_handler + (vl_api_one_show_petr_mode_reply_t * mp) +{ + vat_main_t *vam = &vat_main; + i32 retval = ntohl (mp->retval); + + if (0 <= retval) + { + print (vam->ofp, "%s\n", mp->is_enable ? "enabled" : "disabled"); + } + + vam->retval = retval; + vam->result_ready = 1; +} + +static void + vl_api_show_one_use_petr_reply_t_handler + (vl_api_show_one_use_petr_reply_t * mp) +{ + vat_main_t *vam = &vat_main; + i32 retval = ntohl (mp->retval); + + if (0 <= retval) + { + print (vam->ofp, "%s\n", mp->status ? "enabled" : "disabled"); + if (mp->status) + { + print (vam->ofp, "Proxy-ETR address; %U", + mp->ip_address.af ? format_ip6_address : format_ip4_address, + mp->ip_address.un); + } + } + + vam->retval = retval; + vam->result_ready = 1; +} + +static void + vl_api_show_one_nsh_mapping_reply_t_handler + (vl_api_show_one_nsh_mapping_reply_t * mp) +{ + vat_main_t *vam = &vat_main; + i32 retval = ntohl (mp->retval); + + if (0 <= retval) + { + print (vam->ofp, "%-20s%-16s", + mp->is_set ? "set" : "not-set", + mp->is_set ? (char *) mp->locator_set_name : ""); + } + + vam->retval = retval; + vam->result_ready = 1; +} + +static void + vl_api_show_one_map_register_ttl_reply_t_handler + (vl_api_show_one_map_register_ttl_reply_t * mp) +{ + vat_main_t *vam = &vat_main; + i32 retval = ntohl (mp->retval); + + if (0 <= retval) + { + print (vam->ofp, "ttl: %u", mp->ttl); + } + + vam->retval = retval; + vam->result_ready = 1; +} + +static void +vl_api_show_one_pitr_reply_t_handler (vl_api_show_one_pitr_reply_t * mp) +{ + vat_main_t *vam = &vat_main; + i32 retval = ntohl (mp->retval); + + if (0 <= retval) + { + print (vam->ofp, "%-20s%-16s", + mp->status ? "enabled" : "disabled", + mp->status ? (char *) mp->locator_set_name : ""); + } + + vam->retval = retval; + vam->result_ready = 1; +} + +/* *INDENT-OFF* */ +/** Used for parsing LISP eids */ +typedef CLIB_PACKED(struct{ + union { + ip46_address_t ip; + mac_address_t mac; + lisp_nsh_api_t nsh; + } addr; + u32 len; /**< prefix length if IP */ + u8 type; /**< type of eid */ +}) lisp_eid_vat_t; +/* *INDENT-ON* */ + +static uword +unformat_lisp_eid_vat (unformat_input_t * input, va_list * args) +{ + lisp_eid_vat_t *a = va_arg (*args, lisp_eid_vat_t *); + + clib_memset (a, 0, sizeof (a[0])); + + if (unformat (input, "%U/%d", unformat_ip46_address, a->addr.ip, &a->len)) + { + a->type = 0; /* ip prefix type */ + } + else if (unformat (input, "%U", unformat_ethernet_address, &a->addr.mac)) + { + a->type = 1; /* mac type */ + } + else if (unformat (input, "%U", unformat_nsh_address, a->addr.nsh)) + { + a->type = 2; /* NSH type */ + a->addr.nsh.spi = clib_host_to_net_u32 (a->addr.nsh.spi); + } + else + { + return 0; + } + + if (a->type == 0) + { + if (ip46_address_is_ip4 (&a->addr.ip)) + return a->len > 32 ? 1 : 0; + else + return a->len > 128 ? 1 : 0; + } + + return 1; +} + +static void +lisp_eid_put_vat (vl_api_eid_t * eid, const lisp_eid_vat_t * vat_eid) +{ + eid->type = vat_eid->type; + switch (eid->type) + { + case EID_TYPE_API_PREFIX: + if (ip46_address_is_ip4 (&vat_eid->addr.ip)) + { + clib_memcpy (&eid->address.prefix.address.un.ip4, + &vat_eid->addr.ip.ip4, 4); + eid->address.prefix.address.af = ADDRESS_IP4; + eid->address.prefix.len = vat_eid->len; + } + else + { + clib_memcpy (&eid->address.prefix.address.un.ip6, + &vat_eid->addr.ip.ip6, 16); + eid->address.prefix.address.af = ADDRESS_IP6; + eid->address.prefix.len = vat_eid->len; + } + return; + case EID_TYPE_API_MAC: + clib_memcpy (&eid->address.mac, &vat_eid->addr.mac, + sizeof (eid->address.mac)); + return; + case EID_TYPE_API_NSH: + clib_memcpy (&eid->address.nsh, &vat_eid->addr.nsh, + sizeof (eid->address.nsh)); + return; + default: + ASSERT (0); + return; + } +} + +static int +api_one_add_del_locator_set (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + vl_api_one_add_del_locator_set_t *mp; + u8 is_add = 1; + u8 *locator_set_name = NULL; + u8 locator_set_name_set = 0; + vl_api_local_locator_t locator, *locators = 0; + u32 sw_if_index, priority, weight; + u32 data_len = 0; + + int ret; + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "del")) + { + is_add = 0; + } + else if (unformat (input, "locator-set %s", &locator_set_name)) + { + locator_set_name_set = 1; + } + else if (unformat (input, "sw_if_index %u p %u w %u", + &sw_if_index, &priority, &weight)) + { + locator.sw_if_index = htonl (sw_if_index); + locator.priority = priority; + locator.weight = weight; + vec_add1 (locators, locator); + } + else + if (unformat + (input, "iface %U p %u w %u", unformat_sw_if_index, vam, + &sw_if_index, &priority, &weight)) + { + locator.sw_if_index = htonl (sw_if_index); + locator.priority = priority; + locator.weight = weight; + vec_add1 (locators, locator); + } + else + break; + } + + if (locator_set_name_set == 0) + { + errmsg ("missing locator-set name"); + vec_free (locators); + return -99; + } + + if (vec_len (locator_set_name) > 64) + { + errmsg ("locator-set name too long"); + vec_free (locator_set_name); + vec_free (locators); + return -99; + } + vec_add1 (locator_set_name, 0); + + data_len = sizeof (vl_api_local_locator_t) * vec_len (locators); + + /* Construct the API message */ + M2 (ONE_ADD_DEL_LOCATOR_SET, mp, data_len); + + mp->is_add = is_add; + clib_memcpy (mp->locator_set_name, locator_set_name, + vec_len (locator_set_name)); + vec_free (locator_set_name); + + mp->locator_num = clib_host_to_net_u32 (vec_len (locators)); + if (locators) + clib_memcpy (mp->locators, locators, data_len); + vec_free (locators); + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +#define api_lisp_add_del_locator_set api_one_add_del_locator_set + +static int +api_one_add_del_locator (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + vl_api_one_add_del_locator_t *mp; + u32 tmp_if_index = ~0; + u32 sw_if_index = ~0; + u8 sw_if_index_set = 0; + u8 sw_if_index_if_name_set = 0; + u32 priority = ~0; + u8 priority_set = 0; + u32 weight = ~0; + u8 weight_set = 0; + u8 is_add = 1; + u8 *locator_set_name = NULL; + u8 locator_set_name_set = 0; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "del")) + { + is_add = 0; + } + else if (unformat (input, "locator-set %s", &locator_set_name)) + { + locator_set_name_set = 1; + } + else if (unformat (input, "iface %U", unformat_sw_if_index, vam, + &tmp_if_index)) + { + sw_if_index_if_name_set = 1; + sw_if_index = tmp_if_index; + } + else if (unformat (input, "sw_if_index %d", &tmp_if_index)) + { + sw_if_index_set = 1; + sw_if_index = tmp_if_index; + } + else if (unformat (input, "p %d", &priority)) + { + priority_set = 1; + } + else if (unformat (input, "w %d", &weight)) + { + weight_set = 1; + } + else + break; + } + + if (locator_set_name_set == 0) + { + errmsg ("missing locator-set name"); + return -99; + } + + if (sw_if_index_set == 0 && sw_if_index_if_name_set == 0) + { + errmsg ("missing sw_if_index"); + vec_free (locator_set_name); + return -99; + } + + if (sw_if_index_set != 0 && sw_if_index_if_name_set != 0) + { + errmsg ("cannot use both params interface name and sw_if_index"); + vec_free (locator_set_name); + return -99; + } + + if (priority_set == 0) + { + errmsg ("missing locator-set priority"); + vec_free (locator_set_name); + return -99; + } + + if (weight_set == 0) + { + errmsg ("missing locator-set weight"); + vec_free (locator_set_name); + return -99; + } + + if (vec_len (locator_set_name) > 64) + { + errmsg ("locator-set name too long"); + vec_free (locator_set_name); + return -99; + } + vec_add1 (locator_set_name, 0); + + /* Construct the API message */ + M (ONE_ADD_DEL_LOCATOR, mp); + + mp->is_add = is_add; + mp->sw_if_index = ntohl (sw_if_index); + mp->priority = priority; + mp->weight = weight; + clib_memcpy (mp->locator_set_name, locator_set_name, + vec_len (locator_set_name)); + vec_free (locator_set_name); + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +#define api_lisp_add_del_locator api_one_add_del_locator + +static int +api_one_add_del_local_eid (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + vl_api_one_add_del_local_eid_t *mp; + u8 is_add = 1; + u8 eid_set = 0; + lisp_eid_vat_t _eid, *eid = &_eid; + u8 *locator_set_name = 0; + u8 locator_set_name_set = 0; + u32 vni = 0; + u16 key_id = 0; + u8 *key = 0; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "del")) + { + is_add = 0; + } + else if (unformat (input, "vni %d", &vni)) + { + ; + } + else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid)) + { + eid_set = 1; + } + else if (unformat (input, "locator-set %s", &locator_set_name)) + { + locator_set_name_set = 1; + } + else if (unformat (input, "key-id %U", unformat_hmac_key_id, &key_id)) + ; + else if (unformat (input, "secret-key %_%v%_", &key)) + ; + else + break; + } + + if (locator_set_name_set == 0) + { + errmsg ("missing locator-set name"); + return -99; + } + + if (0 == eid_set) + { + errmsg ("EID address not set!"); + vec_free (locator_set_name); + return -99; + } + + if (key && (0 == key_id)) + { + errmsg ("invalid key_id!"); + return -99; + } + + if (vec_len (key) > 64) + { + errmsg ("key too long"); + vec_free (key); + return -99; + } + + if (vec_len (locator_set_name) > 64) + { + errmsg ("locator-set name too long"); + vec_free (locator_set_name); + return -99; + } + vec_add1 (locator_set_name, 0); + + /* Construct the API message */ + M (ONE_ADD_DEL_LOCAL_EID, mp); + + mp->is_add = is_add; + lisp_eid_put_vat (&mp->eid, eid); + mp->vni = clib_host_to_net_u32 (vni); + mp->key.id = key_id; + clib_memcpy (mp->locator_set_name, locator_set_name, + vec_len (locator_set_name)); + clib_memcpy (mp->key.key, key, vec_len (key)); + + vec_free (locator_set_name); + vec_free (key); + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_one_add_del_map_server (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + vl_api_one_add_del_map_server_t *mp; + u8 is_add = 1; + u8 ipv4_set = 0; + u8 ipv6_set = 0; + ip4_address_t ipv4; + ip6_address_t ipv6; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "del")) + { + is_add = 0; + } + else if (unformat (input, "%U", unformat_ip4_address, &ipv4)) + { + ipv4_set = 1; + } + else if (unformat (input, "%U", unformat_ip6_address, &ipv6)) + { + ipv6_set = 1; + } + else + break; + } + + if (ipv4_set && ipv6_set) + { + errmsg ("both eid v4 and v6 addresses set"); + return -99; + } + + if (!ipv4_set && !ipv6_set) + { + errmsg ("eid addresses not set"); + return -99; + } + + /* Construct the API message */ + M (ONE_ADD_DEL_MAP_SERVER, mp); + + mp->is_add = is_add; + if (ipv6_set) + { + mp->ip_address.af = 1; + clib_memcpy (mp->ip_address.un.ip6, &ipv6, sizeof (ipv6)); + } + else + { + mp->ip_address.af = 0; + clib_memcpy (mp->ip_address.un.ip4, &ipv4, sizeof (ipv4)); + } + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +#define api_lisp_add_del_map_server api_one_add_del_map_server + +static int +api_one_add_del_map_resolver (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + vl_api_one_add_del_map_resolver_t *mp; + u8 is_add = 1; + u8 ipv4_set = 0; + u8 ipv6_set = 0; + ip4_address_t ipv4; + ip6_address_t ipv6; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "del")) + { + is_add = 0; + } + else if (unformat (input, "%U", unformat_ip4_address, &ipv4)) + { + ipv4_set = 1; + } + else if (unformat (input, "%U", unformat_ip6_address, &ipv6)) + { + ipv6_set = 1; + } + else + break; + } + + if (ipv4_set && ipv6_set) + { + errmsg ("both eid v4 and v6 addresses set"); + return -99; + } + + if (!ipv4_set && !ipv6_set) + { + errmsg ("eid addresses not set"); + return -99; + } + + /* Construct the API message */ + M (ONE_ADD_DEL_MAP_RESOLVER, mp); + + mp->is_add = is_add; + if (ipv6_set) + { + mp->ip_address.af = 1; + clib_memcpy (mp->ip_address.un.ip6, &ipv6, sizeof (ipv6)); + } + else + { + mp->ip_address.af = 0; + clib_memcpy (mp->ip_address.un.ip6, &ipv4, sizeof (ipv4)); + } + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_one_rloc_probe_enable_disable (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + vl_api_one_rloc_probe_enable_disable_t *mp; + u8 is_set = 0; + u8 is_enable = 0; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "enable")) + { + is_set = 1; + is_enable = 1; + } + else if (unformat (input, "disable")) + is_set = 1; + else + break; + } + + if (!is_set) + { + errmsg ("Value not set"); + return -99; + } + + /* Construct the API message */ + M (ONE_RLOC_PROBE_ENABLE_DISABLE, mp); + + mp->is_enable = is_enable; + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +#define api_lisp_rloc_probe_enable_disable api_one_rloc_probe_enable_disable + +static int +api_one_map_register_enable_disable (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + vl_api_one_map_register_enable_disable_t *mp; + u8 is_set = 0; + u8 is_enable = 0; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "enable")) + { + is_set = 1; + is_enable = 1; + } + else if (unformat (input, "disable")) + is_set = 1; + else + break; + } + + if (!is_set) + { + errmsg ("Value not set"); + return -99; + } + + /* Construct the API message */ + M (ONE_MAP_REGISTER_ENABLE_DISABLE, mp); + + mp->is_enable = is_enable; + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +#define api_lisp_map_register_enable_disable api_one_map_register_enable_disable + +static int +api_one_enable_disable (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + vl_api_one_enable_disable_t *mp; + u8 is_set = 0; + u8 is_enable = 0; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "enable")) + { + is_set = 1; + is_enable = 1; + } + else if (unformat (input, "disable")) + { + is_set = 1; + } + else + break; + } + + if (!is_set) + { + errmsg ("Value not set"); + return -99; + } + + /* Construct the API message */ + M (ONE_ENABLE_DISABLE, mp); + + mp->is_enable = is_enable; + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +#define api_lisp_enable_disable api_one_enable_disable + +static int +api_one_enable_disable_xtr_mode (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + vl_api_one_enable_disable_xtr_mode_t *mp; + u8 is_set = 0; + u8 is_enable = 0; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "enable")) + { + is_set = 1; + is_enable = 1; + } + else if (unformat (input, "disable")) + { + is_set = 1; + } + else + break; + } + + if (!is_set) + { + errmsg ("Value not set"); + return -99; + } + + /* Construct the API message */ + M (ONE_ENABLE_DISABLE_XTR_MODE, mp); + + mp->is_enable = is_enable; + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_one_show_xtr_mode (vat_main_t * vam) +{ + vl_api_one_show_xtr_mode_t *mp; + int ret; + + /* Construct the API message */ + M (ONE_SHOW_XTR_MODE, mp); + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_one_enable_disable_pitr_mode (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + vl_api_one_enable_disable_pitr_mode_t *mp; + u8 is_set = 0; + u8 is_enable = 0; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "enable")) + { + is_set = 1; + is_enable = 1; + } + else if (unformat (input, "disable")) + { + is_set = 1; + } + else + break; + } + + if (!is_set) + { + errmsg ("Value not set"); + return -99; + } + + /* Construct the API message */ + M (ONE_ENABLE_DISABLE_PITR_MODE, mp); + + mp->is_enable = is_enable; + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_one_show_pitr_mode (vat_main_t * vam) +{ + vl_api_one_show_pitr_mode_t *mp; + int ret; + + /* Construct the API message */ + M (ONE_SHOW_PITR_MODE, mp); + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_one_enable_disable_petr_mode (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + vl_api_one_enable_disable_petr_mode_t *mp; + u8 is_set = 0; + u8 is_enable = 0; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "enable")) + { + is_set = 1; + is_enable = 1; + } + else if (unformat (input, "disable")) + { + is_set = 1; + } + else + break; + } + + if (!is_set) + { + errmsg ("Value not set"); + return -99; + } + + /* Construct the API message */ + M (ONE_ENABLE_DISABLE_PETR_MODE, mp); + + mp->is_enable = is_enable; + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_one_show_petr_mode (vat_main_t * vam) +{ + vl_api_one_show_petr_mode_t *mp; + int ret; + + /* Construct the API message */ + M (ONE_SHOW_PETR_MODE, mp); + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_show_one_map_register_state (vat_main_t * vam) +{ + vl_api_show_one_map_register_state_t *mp; + int ret; + + M (SHOW_ONE_MAP_REGISTER_STATE, mp); + + /* send */ + S (mp); + + /* wait for reply */ + W (ret); + return ret; +} + +#define api_show_lisp_map_register_state api_show_one_map_register_state + +static int +api_show_one_rloc_probe_state (vat_main_t * vam) +{ + vl_api_show_one_rloc_probe_state_t *mp; + int ret; + + M (SHOW_ONE_RLOC_PROBE_STATE, mp); + + /* send */ + S (mp); + + /* wait for reply */ + W (ret); + return ret; +} + +#define api_show_lisp_rloc_probe_state api_show_one_rloc_probe_state + +static int +api_one_add_del_ndp_entry (vat_main_t * vam) +{ + vl_api_one_add_del_ndp_entry_t *mp; + unformat_input_t *input = vam->input; + u8 is_add = 1; + u8 mac_set = 0; + u8 bd_set = 0; + u8 ip_set = 0; + u8 mac[6] = { 0, }; + u8 ip6[16] = { 0, }; + u32 bd = ~0; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "del")) + is_add = 0; + else if (unformat (input, "mac %U", unformat_ethernet_address, mac)) + mac_set = 1; + else if (unformat (input, "ip %U", unformat_ip6_address, ip6)) + ip_set = 1; + else if (unformat (input, "bd %d", &bd)) + bd_set = 1; + else + { + errmsg ("parse error '%U'", format_unformat_error, input); + return -99; + } + } + + if (!bd_set || !ip_set || (!mac_set && is_add)) + { + errmsg ("Missing BD, IP or MAC!"); + return -99; + } + + M (ONE_ADD_DEL_NDP_ENTRY, mp); + mp->is_add = is_add; + clib_memcpy (&mp->entry.mac, mac, 6); + mp->bd = clib_host_to_net_u32 (bd); + clib_memcpy (&mp->entry.ip6, ip6, sizeof (mp->entry.ip6)); + + /* send */ + S (mp); + + /* wait for reply */ + W (ret); + return ret; +} + +static int +api_one_add_del_l2_arp_entry (vat_main_t * vam) +{ + vl_api_one_add_del_l2_arp_entry_t *mp; + unformat_input_t *input = vam->input; + u8 is_add = 1; + u8 mac_set = 0; + u8 bd_set = 0; + u8 ip_set = 0; + u8 mac[6] = { 0, }; + u32 ip4 = 0, bd = ~0; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "del")) + is_add = 0; + else if (unformat (input, "mac %U", unformat_ethernet_address, mac)) + mac_set = 1; + else if (unformat (input, "ip %U", unformat_ip4_address, &ip4)) + ip_set = 1; + else if (unformat (input, "bd %d", &bd)) + bd_set = 1; + else + { + errmsg ("parse error '%U'", format_unformat_error, input); + return -99; + } + } + + if (!bd_set || !ip_set || (!mac_set && is_add)) + { + errmsg ("Missing BD, IP or MAC!"); + return -99; + } + + M (ONE_ADD_DEL_L2_ARP_ENTRY, mp); + mp->is_add = is_add; + clib_memcpy (&mp->entry.mac, mac, 6); + mp->bd = clib_host_to_net_u32 (bd); + clib_memcpy (mp->entry.ip4, &ip4, sizeof (mp->entry.ip4)); + + /* send */ + S (mp); + + /* wait for reply */ + W (ret); + return ret; +} + +static int +api_one_ndp_bd_get (vat_main_t * vam) +{ + vl_api_one_ndp_bd_get_t *mp; + int ret; + + M (ONE_NDP_BD_GET, mp); + + /* send */ + S (mp); + + /* wait for reply */ + W (ret); + return ret; +} + +static int +api_one_ndp_entries_get (vat_main_t * vam) +{ + vl_api_one_ndp_entries_get_t *mp; + unformat_input_t *input = vam->input; + u8 bd_set = 0; + u32 bd = ~0; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "bd %d", &bd)) + bd_set = 1; + else + { + errmsg ("parse error '%U'", format_unformat_error, input); + return -99; + } + } + + if (!bd_set) + { + errmsg ("Expected bridge domain!"); + return -99; + } + + M (ONE_NDP_ENTRIES_GET, mp); + mp->bd = clib_host_to_net_u32 (bd); + + /* send */ + S (mp); + + /* wait for reply */ + W (ret); + return ret; +} + +static int +api_one_l2_arp_bd_get (vat_main_t * vam) +{ + vl_api_one_l2_arp_bd_get_t *mp; + int ret; + + M (ONE_L2_ARP_BD_GET, mp); + + /* send */ + S (mp); + + /* wait for reply */ + W (ret); + return ret; +} + +static int +api_one_l2_arp_entries_get (vat_main_t * vam) +{ + vl_api_one_l2_arp_entries_get_t *mp; + unformat_input_t *input = vam->input; + u8 bd_set = 0; + u32 bd = ~0; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "bd %d", &bd)) + bd_set = 1; + else + { + errmsg ("parse error '%U'", format_unformat_error, input); + return -99; + } + } + + if (!bd_set) + { + errmsg ("Expected bridge domain!"); + return -99; + } + + M (ONE_L2_ARP_ENTRIES_GET, mp); + mp->bd = clib_host_to_net_u32 (bd); + + /* send */ + S (mp); + + /* wait for reply */ + W (ret); + return ret; +} + +static int +api_one_stats_enable_disable (vat_main_t * vam) +{ + vl_api_one_stats_enable_disable_t *mp; + unformat_input_t *input = vam->input; + u8 is_set = 0; + u8 is_enable = 0; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "enable")) + { + is_set = 1; + is_enable = 1; + } + else if (unformat (input, "disable")) + { + is_set = 1; + } + else + break; + } + + if (!is_set) + { + errmsg ("Value not set"); + return -99; + } + + M (ONE_STATS_ENABLE_DISABLE, mp); + mp->is_enable = is_enable; + + /* send */ + S (mp); + + /* wait for reply */ + W (ret); + return ret; +} + +static int +api_show_one_stats_enable_disable (vat_main_t * vam) +{ + vl_api_show_one_stats_enable_disable_t *mp; + int ret; + + M (SHOW_ONE_STATS_ENABLE_DISABLE, mp); + + /* send */ + S (mp); + + /* wait for reply */ + W (ret); + return ret; +} + +static int +api_show_one_map_request_mode (vat_main_t * vam) +{ + vl_api_show_one_map_request_mode_t *mp; + int ret; + + M (SHOW_ONE_MAP_REQUEST_MODE, mp); + + /* send */ + S (mp); + + /* wait for reply */ + W (ret); + return ret; +} + +#define api_show_lisp_map_request_mode api_show_one_map_request_mode + +static int +api_one_map_request_mode (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + vl_api_one_map_request_mode_t *mp; + u8 mode = 0; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "dst-only")) + mode = 0; + else if (unformat (input, "src-dst")) + mode = 1; + else + { + errmsg ("parse error '%U'", format_unformat_error, input); + return -99; + } + } + + M (ONE_MAP_REQUEST_MODE, mp); + + mp->mode = mode; + + /* send */ + S (mp); + + /* wait for reply */ + W (ret); + return ret; +} + +#define api_lisp_map_request_mode api_one_map_request_mode + +/** + * Enable/disable ONE proxy ITR. + * + * @param vam vpp API test context + * @return return code + */ +static int +api_one_pitr_set_locator_set (vat_main_t * vam) +{ + u8 ls_name_set = 0; + unformat_input_t *input = vam->input; + vl_api_one_pitr_set_locator_set_t *mp; + u8 is_add = 1; + u8 *ls_name = 0; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "del")) + is_add = 0; + else if (unformat (input, "locator-set %s", &ls_name)) + ls_name_set = 1; + else + { + errmsg ("parse error '%U'", format_unformat_error, input); + return -99; + } + } + + if (!ls_name_set) + { + errmsg ("locator-set name not set!"); + return -99; + } + + M (ONE_PITR_SET_LOCATOR_SET, mp); + + mp->is_add = is_add; + clib_memcpy (mp->ls_name, ls_name, vec_len (ls_name)); + vec_free (ls_name); + + /* send */ + S (mp); + + /* wait for reply */ + W (ret); + return ret; +} + +#define api_lisp_pitr_set_locator_set api_one_pitr_set_locator_set + +static int +api_one_nsh_set_locator_set (vat_main_t * vam) +{ + u8 ls_name_set = 0; + unformat_input_t *input = vam->input; + vl_api_one_nsh_set_locator_set_t *mp; + u8 is_add = 1; + u8 *ls_name = 0; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "del")) + is_add = 0; + else if (unformat (input, "ls %s", &ls_name)) + ls_name_set = 1; + else + { + errmsg ("parse error '%U'", format_unformat_error, input); + return -99; + } + } + + if (!ls_name_set && is_add) + { + errmsg ("locator-set name not set!"); + return -99; + } + + M (ONE_NSH_SET_LOCATOR_SET, mp); + + mp->is_add = is_add; + clib_memcpy (mp->ls_name, ls_name, vec_len (ls_name)); + vec_free (ls_name); + + /* send */ + S (mp); + + /* wait for reply */ + W (ret); + return ret; +} + +static int +api_show_one_pitr (vat_main_t * vam) +{ + vl_api_show_one_pitr_t *mp; + int ret; + + if (!vam->json_output) + { + print (vam->ofp, "%=20s", "lisp status:"); + } + + M (SHOW_ONE_PITR, mp); + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +#define api_show_lisp_pitr api_show_one_pitr + +static int +api_one_use_petr (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + vl_api_one_use_petr_t *mp; + u8 is_add = 0; + ip_address_t ip; + int ret; + + clib_memset (&ip, 0, sizeof (ip)); + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "disable")) + is_add = 0; + else + if (unformat (input, "%U", unformat_ip4_address, &ip_addr_v4 (&ip))) + { + is_add = 1; + ip_addr_version (&ip) = AF_IP4; + } + else + if (unformat (input, "%U", unformat_ip6_address, &ip_addr_v6 (&ip))) + { + is_add = 1; + ip_addr_version (&ip) = AF_IP6; + } + else + { + errmsg ("parse error '%U'", format_unformat_error, input); + return -99; + } + } + + M (ONE_USE_PETR, mp); + + mp->is_add = is_add; + if (is_add) + { + mp->ip_address.af = ip_addr_version (&ip) == AF_IP4 ? 0 : 1; + if (mp->ip_address.af) + clib_memcpy (mp->ip_address.un.ip6, &ip, 16); + else + clib_memcpy (mp->ip_address.un.ip4, &ip, 4); + } + + /* send */ + S (mp); + + /* wait for reply */ + W (ret); + return ret; +} + +#define api_lisp_use_petr api_one_use_petr + +static int +api_show_one_nsh_mapping (vat_main_t * vam) +{ + vl_api_show_one_use_petr_t *mp; + int ret; + + if (!vam->json_output) + { + print (vam->ofp, "%=20s", "local ONE NSH mapping:"); + } + + M (SHOW_ONE_NSH_MAPPING, mp); + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_show_one_use_petr (vat_main_t * vam) +{ + vl_api_show_one_use_petr_t *mp; + int ret; + + if (!vam->json_output) + { + print (vam->ofp, "%=20s", "Proxy-ETR status:"); + } + + M (SHOW_ONE_USE_PETR, mp); + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +#define api_show_lisp_use_petr api_show_one_use_petr + +/** + * Add/delete mapping between vni and vrf + */ +static int +api_one_eid_table_add_del_map (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + vl_api_one_eid_table_add_del_map_t *mp; + u8 is_add = 1, vni_set = 0, vrf_set = 0, bd_index_set = 0; + u32 vni, vrf, bd_index; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "del")) + is_add = 0; + else if (unformat (input, "vrf %d", &vrf)) + vrf_set = 1; + else if (unformat (input, "bd_index %d", &bd_index)) + bd_index_set = 1; + else if (unformat (input, "vni %d", &vni)) + vni_set = 1; + else + break; + } + + if (!vni_set || (!vrf_set && !bd_index_set)) + { + errmsg ("missing arguments!"); + return -99; + } + + if (vrf_set && bd_index_set) + { + errmsg ("error: both vrf and bd entered!"); + return -99; + } + + M (ONE_EID_TABLE_ADD_DEL_MAP, mp); + + mp->is_add = is_add; + mp->vni = htonl (vni); + mp->dp_table = vrf_set ? htonl (vrf) : htonl (bd_index); + mp->is_l2 = bd_index_set; + + /* send */ + S (mp); + + /* wait for reply */ + W (ret); + return ret; +} + +#define api_lisp_eid_table_add_del_map api_one_eid_table_add_del_map + +uword +unformat_negative_mapping_action (unformat_input_t * input, va_list * args) +{ + u32 *action = va_arg (*args, u32 *); + u8 *s = 0; + + if (unformat (input, "%s", &s)) + { + if (!strcmp ((char *) s, "no-action")) + action[0] = 0; + else if (!strcmp ((char *) s, "natively-forward")) + action[0] = 1; + else if (!strcmp ((char *) s, "send-map-request")) + action[0] = 2; + else if (!strcmp ((char *) s, "drop")) + action[0] = 3; + else + { + clib_warning ("invalid action: '%s'", s); + action[0] = 3; + } + } + else + return 0; + + vec_free (s); + return 1; +} + +/** + * Add/del remote mapping to/from ONE control plane + * + * @param vam vpp API test context + * @return return code + */ +static int +api_one_add_del_remote_mapping (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + vl_api_one_add_del_remote_mapping_t *mp; + u32 vni = 0; + lisp_eid_vat_t _eid, *eid = &_eid; + lisp_eid_vat_t _seid, *seid = &_seid; + u8 is_add = 1, del_all = 0, eid_set = 0, seid_set = 0; + u32 action = ~0, p, w, data_len; + ip4_address_t rloc4; + ip6_address_t rloc6; + vl_api_remote_locator_t *rlocs = 0, rloc, *curr_rloc = 0; + int ret; + + clib_memset (&rloc, 0, sizeof (rloc)); + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "del-all")) + { + del_all = 1; + } + else if (unformat (input, "del")) + { + is_add = 0; + } + else if (unformat (input, "add")) + { + is_add = 1; + } + else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid)) + { + eid_set = 1; + } + else if (unformat (input, "seid %U", unformat_lisp_eid_vat, seid)) + { + seid_set = 1; + } + else if (unformat (input, "vni %d", &vni)) + { + ; + } + else if (unformat (input, "p %d w %d", &p, &w)) + { + if (!curr_rloc) + { + errmsg ("No RLOC configured for setting priority/weight!"); + return -99; + } + curr_rloc->priority = p; + curr_rloc->weight = w; + } + else if (unformat (input, "rloc %U", unformat_ip4_address, &rloc4)) + { + rloc.ip_address.af = 0; + clib_memcpy (&rloc.ip_address.un.ip6, &rloc6, sizeof (rloc6)); + vec_add1 (rlocs, rloc); + curr_rloc = &rlocs[vec_len (rlocs) - 1]; + } + else if (unformat (input, "rloc %U", unformat_ip6_address, &rloc6)) + { + rloc.ip_address.af = 1; + clib_memcpy (&rloc.ip_address.un.ip4, &rloc4, sizeof (rloc4)); + vec_add1 (rlocs, rloc); + curr_rloc = &rlocs[vec_len (rlocs) - 1]; + } + else if (unformat (input, "action %U", + unformat_negative_mapping_action, &action)) + { + ; + } + else + { + clib_warning ("parse error '%U'", format_unformat_error, input); + return -99; + } + } + + if (0 == eid_set) + { + errmsg ("missing params!"); + return -99; + } + + if (is_add && (~0 == action) && 0 == vec_len (rlocs)) + { + errmsg ("no action set for negative map-reply!"); + return -99; + } + + data_len = vec_len (rlocs) * sizeof (vl_api_remote_locator_t); + + M2 (ONE_ADD_DEL_REMOTE_MAPPING, mp, data_len); + mp->is_add = is_add; + mp->vni = htonl (vni); + mp->action = (u8) action; + mp->is_src_dst = seid_set; + mp->del_all = del_all; + lisp_eid_put_vat (&mp->deid, eid); + lisp_eid_put_vat (&mp->seid, seid); + + mp->rloc_num = clib_host_to_net_u32 (vec_len (rlocs)); + clib_memcpy (mp->rlocs, rlocs, data_len); + vec_free (rlocs); + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +#define api_lisp_add_del_remote_mapping api_one_add_del_remote_mapping + +/** + * Add/del ONE adjacency. Saves mapping in ONE control plane and updates + * forwarding entries in data-plane accordingly. + * + * @param vam vpp API test context + * @return return code + */ +static int +api_one_add_del_adjacency (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + vl_api_one_add_del_adjacency_t *mp; + u32 vni = 0; + u8 is_add = 1; + int ret; + lisp_eid_vat_t leid, reid; + + leid.type = reid.type = (u8) ~ 0; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "del")) + { + is_add = 0; + } + else if (unformat (input, "add")) + { + is_add = 1; + } + else if (unformat (input, "reid %U/%d", unformat_ip46_address, + &reid.addr.ip, &reid.len)) + { + reid.type = 0; /* ipv4 */ + } + else if (unformat (input, "reid %U", unformat_ethernet_address, + &reid.addr.mac)) + { + reid.type = 1; /* mac */ + } + else if (unformat (input, "leid %U/%d", unformat_ip46_address, + &leid.addr.ip, &leid.len)) + { + leid.type = 0; /* ipv4 */ + } + else if (unformat (input, "leid %U", unformat_ethernet_address, + &leid.addr.mac)) + { + leid.type = 1; /* mac */ + } + else if (unformat (input, "vni %d", &vni)) + { + ; + } + else + { + errmsg ("parse error '%U'", format_unformat_error, input); + return -99; + } + } + + if ((u8) ~ 0 == reid.type) + { + errmsg ("missing params!"); + return -99; + } + + if (leid.type != reid.type) + { + errmsg ("remote and local EIDs are of different types!"); + return -99; + } + + M (ONE_ADD_DEL_ADJACENCY, mp); + mp->is_add = is_add; + mp->vni = htonl (vni); + lisp_eid_put_vat (&mp->leid, &leid); + lisp_eid_put_vat (&mp->reid, &reid); + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +#define api_lisp_add_del_adjacency api_one_add_del_adjacency + + +static int +api_one_map_register_fallback_threshold (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + vl_api_one_map_register_fallback_threshold_t *mp; + u32 value = 0; + u8 is_set = 0; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "%u", &value)) + is_set = 1; + else + { + clib_warning ("parse error '%U'", format_unformat_error, input); + return -99; + } + } + + if (!is_set) + { + errmsg ("fallback threshold value is missing!"); + return -99; + } + + M (ONE_MAP_REGISTER_FALLBACK_THRESHOLD, mp); + mp->value = clib_host_to_net_u32 (value); + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_show_one_map_register_fallback_threshold (vat_main_t * vam) +{ + vl_api_show_one_map_register_fallback_threshold_t *mp; + int ret; + + M (SHOW_ONE_MAP_REGISTER_FALLBACK_THRESHOLD, mp); + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +uword +unformat_lisp_transport_protocol (unformat_input_t * input, va_list * args) +{ + u32 *proto = va_arg (*args, u32 *); + + if (unformat (input, "udp")) + *proto = 1; + else if (unformat (input, "api")) + *proto = 2; + else + return 0; + + return 1; +} + +static int +api_one_set_transport_protocol (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + vl_api_one_set_transport_protocol_t *mp; + u8 is_set = 0; + u32 protocol = 0; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "%U", unformat_lisp_transport_protocol, &protocol)) + is_set = 1; + else + { + clib_warning ("parse error '%U'", format_unformat_error, input); + return -99; + } + } + + if (!is_set) + { + errmsg ("Transport protocol missing!"); + return -99; + } + + M (ONE_SET_TRANSPORT_PROTOCOL, mp); + mp->protocol = (u8) protocol; + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_one_get_transport_protocol (vat_main_t * vam) +{ + vl_api_one_get_transport_protocol_t *mp; + int ret; + + M (ONE_GET_TRANSPORT_PROTOCOL, mp); + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_one_map_register_set_ttl (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + vl_api_one_map_register_set_ttl_t *mp; + u32 ttl = 0; + u8 is_set = 0; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "%u", &ttl)) + is_set = 1; + else + { + clib_warning ("parse error '%U'", format_unformat_error, input); + return -99; + } + } + + if (!is_set) + { + errmsg ("TTL value missing!"); + return -99; + } + + M (ONE_MAP_REGISTER_SET_TTL, mp); + mp->ttl = clib_host_to_net_u32 (ttl); + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_show_one_map_register_ttl (vat_main_t * vam) +{ + vl_api_show_one_map_register_ttl_t *mp; + int ret; + + M (SHOW_ONE_MAP_REGISTER_TTL, mp); + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +/** + * Add/del map request itr rlocs from ONE control plane and updates + * + * @param vam vpp API test context + * @return return code + */ +static int +api_one_add_del_map_request_itr_rlocs (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + vl_api_one_add_del_map_request_itr_rlocs_t *mp; + u8 *locator_set_name = 0; + u8 locator_set_name_set = 0; + u8 is_add = 1; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "del")) + { + is_add = 0; + } + else if (unformat (input, "%_%v%_", &locator_set_name)) + { + locator_set_name_set = 1; + } + else + { + clib_warning ("parse error '%U'", format_unformat_error, input); + return -99; + } + } + + if (is_add && !locator_set_name_set) + { + errmsg ("itr-rloc is not set!"); + return -99; + } + + if (is_add && vec_len (locator_set_name) > 64) + { + errmsg ("itr-rloc locator-set name too long"); + vec_free (locator_set_name); + return -99; + } + + M (ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS, mp); + mp->is_add = is_add; + if (is_add) + { + clib_memcpy (mp->locator_set_name, locator_set_name, + vec_len (locator_set_name)); + } + else + { + clib_memset (mp->locator_set_name, 0, sizeof (mp->locator_set_name)); + } + vec_free (locator_set_name); + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +#define api_lisp_add_del_map_request_itr_rlocs api_one_add_del_map_request_itr_rlocs + +static int +api_one_locator_dump (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + vl_api_one_locator_dump_t *mp; + vl_api_control_ping_t *mp_ping; + u8 is_index_set = 0, is_name_set = 0; + u8 *ls_name = 0; + u32 ls_index = ~0; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "ls_name %_%v%_", &ls_name)) + { + is_name_set = 1; + } + else if (unformat (input, "ls_index %d", &ls_index)) + { + is_index_set = 1; + } + else + { + errmsg ("parse error '%U'", format_unformat_error, input); + return -99; + } + } + + if (!is_index_set && !is_name_set) + { + errmsg ("error: expected one of index or name!"); + return -99; + } + + if (is_index_set && is_name_set) + { + errmsg ("error: only one param expected!"); + return -99; + } + + if (vec_len (ls_name) > 62) + { + errmsg ("error: locator set name too long!"); + return -99; + } + + if (!vam->json_output) + { + print (vam->ofp, "%=16s%=16s%=16s", "locator", "priority", "weight"); + } + + M (ONE_LOCATOR_DUMP, mp); + mp->is_index_set = is_index_set; + + if (is_index_set) + mp->ls_index = clib_host_to_net_u32 (ls_index); + else + { + vec_add1 (ls_name, 0); + strncpy ((char *) mp->ls_name, (char *) ls_name, + sizeof (mp->ls_name) - 1); + } + + /* send it... */ + S (mp); + + /* Use a control ping for synchronization */ + LISP_PING (&one_test_main, mp_ping); + S (mp_ping); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +#define api_lisp_locator_dump api_one_locator_dump + +static int +api_one_locator_set_dump (vat_main_t * vam) +{ + vl_api_one_locator_set_dump_t *mp; + vl_api_control_ping_t *mp_ping; + unformat_input_t *input = vam->input; + u8 filter = 0; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "local")) + { + filter = 1; + } + else if (unformat (input, "remote")) + { + filter = 2; + } + else + { + errmsg ("parse error '%U'", format_unformat_error, input); + return -99; + } + } + + if (!vam->json_output) + { + print (vam->ofp, "%=10s%=15s", "ls_index", "ls_name"); + } + + M (ONE_LOCATOR_SET_DUMP, mp); + + mp->filter = filter; + + /* send it... */ + S (mp); + + /* Use a control ping for synchronization */ + LISP_PING (&one_test_main, mp_ping); + S (mp_ping); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +#define api_lisp_locator_set_dump api_one_locator_set_dump + +static int +api_one_eid_table_map_dump (vat_main_t * vam) +{ + u8 is_l2 = 0; + u8 mode_set = 0; + unformat_input_t *input = vam->input; + vl_api_one_eid_table_map_dump_t *mp; + vl_api_control_ping_t *mp_ping; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "l2")) + { + is_l2 = 1; + mode_set = 1; + } + else if (unformat (input, "l3")) + { + is_l2 = 0; + mode_set = 1; + } + else + { + errmsg ("parse error '%U'", format_unformat_error, input); + return -99; + } + } + + if (!mode_set) + { + errmsg ("expected one of 'l2' or 'l3' parameter!"); + return -99; + } + + if (!vam->json_output) + { + print (vam->ofp, "%=10s%=10s", "VNI", is_l2 ? "BD" : "VRF"); + } + + M (ONE_EID_TABLE_MAP_DUMP, mp); + mp->is_l2 = is_l2; + + /* send it... */ + S (mp); + + /* Use a control ping for synchronization */ + LISP_PING (&one_test_main, mp_ping); + S (mp_ping); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +#define api_lisp_eid_table_map_dump api_one_eid_table_map_dump + +static int +api_one_eid_table_vni_dump (vat_main_t * vam) +{ + vl_api_one_eid_table_vni_dump_t *mp; + vl_api_control_ping_t *mp_ping; + int ret; + + if (!vam->json_output) + { + print (vam->ofp, "VNI"); + } + + M (ONE_EID_TABLE_VNI_DUMP, mp); + + /* send it... */ + S (mp); + + /* Use a control ping for synchronization */ + LISP_PING (&one_test_main, mp_ping); + S (mp_ping); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +#define api_lisp_eid_table_vni_dump api_one_eid_table_vni_dump + +static int +api_one_eid_table_dump (vat_main_t * vam) +{ + unformat_input_t *i = vam->input; + vl_api_one_eid_table_dump_t *mp; + vl_api_control_ping_t *mp_ping; + u8 filter = 0; + int ret; + u32 vni, t = 0; + lisp_eid_vat_t eid; + u8 eid_set = 0; + + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + { + if (unformat + (i, "eid %U/%d", unformat_ip46_address, &eid.addr.ip, &eid.len)) + { + eid_set = 1; + eid.type = 0; + } + else + if (unformat (i, "eid %U", unformat_ethernet_address, &eid.addr.mac)) + { + eid_set = 1; + eid.type = 1; + } + else if (unformat (i, "eid %U", unformat_nsh_address, &eid.addr.nsh)) + { + eid_set = 1; + eid.type = 2; + } + else if (unformat (i, "vni %d", &t)) + { + vni = t; + } + else if (unformat (i, "local")) + { + filter = 1; + } + else if (unformat (i, "remote")) + { + filter = 2; + } + else + { + errmsg ("parse error '%U'", format_unformat_error, i); + return -99; + } + } + + if (!vam->json_output) + { + print (vam->ofp, "%-35s%-20s%-30s%-20s%-20s%-10s%-20s", "EID", + "type", "ls_index", "ttl", "authoritative", "key_id", "key"); + } + + M (ONE_EID_TABLE_DUMP, mp); + + mp->filter = filter; + if (eid_set) + { + mp->eid_set = 1; + mp->vni = htonl (vni); + lisp_eid_put_vat (&mp->eid, &eid); + } + + /* send it... */ + S (mp); + + /* Use a control ping for synchronization */ + LISP_PING (&one_test_main, mp_ping); + S (mp_ping); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_one_adjacencies_get (vat_main_t * vam) +{ + unformat_input_t *i = vam->input; + vl_api_one_adjacencies_get_t *mp; + u8 vni_set = 0; + u32 vni = ~0; + int ret; + + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + { + if (unformat (i, "vni %d", &vni)) + { + vni_set = 1; + } + else + { + errmsg ("parse error '%U'", format_unformat_error, i); + return -99; + } + } + + if (!vni_set) + { + errmsg ("vni not set!"); + return -99; + } + + if (!vam->json_output) + { + print (vam->ofp, "%s %40s", "leid", "reid"); + } + + M (ONE_ADJACENCIES_GET, mp); + mp->vni = clib_host_to_net_u32 (vni); + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_one_map_server_dump (vat_main_t * vam) +{ + vl_api_one_map_server_dump_t *mp; + vl_api_control_ping_t *mp_ping; + int ret; + + if (!vam->json_output) + { + print (vam->ofp, "%=20s", "Map server"); + } + + M (ONE_MAP_SERVER_DUMP, mp); + /* send it... */ + S (mp); + + /* Use a control ping for synchronization */ + LISP_PING (&one_test_main, mp_ping); + S (mp_ping); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +#define api_lisp_map_server_dump api_one_map_server_dump + +static int +api_one_map_resolver_dump (vat_main_t * vam) +{ + vl_api_one_map_resolver_dump_t *mp; + vl_api_control_ping_t *mp_ping; + int ret; + + if (!vam->json_output) + { + print (vam->ofp, "%=20s", "Map resolver"); + } + + M (ONE_MAP_RESOLVER_DUMP, mp); + /* send it... */ + S (mp); + + /* Use a control ping for synchronization */ + LISP_PING (&one_test_main, mp_ping); + S (mp_ping); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +#define api_lisp_map_resolver_dump api_one_map_resolver_dump + +static int +api_one_stats_flush (vat_main_t * vam) +{ + vl_api_one_stats_flush_t *mp; + int ret = 0; + + M (ONE_STATS_FLUSH, mp); + S (mp); + W (ret); + return ret; +} + +static int +api_one_stats_dump (vat_main_t * vam) +{ + vl_api_one_stats_dump_t *mp; + vl_api_control_ping_t *mp_ping; + int ret; + + M (ONE_STATS_DUMP, mp); + /* send it... */ + S (mp); + + /* Use a control ping for synchronization */ + LISP_PING (&one_test_main, mp_ping); + S (mp_ping); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_show_one_status (vat_main_t * vam) +{ + vl_api_show_one_status_t *mp; + int ret; + + if (!vam->json_output) + { + print (vam->ofp, "%-20s%-16s", "ONE status", "locator-set"); + } + + M (SHOW_ONE_STATUS, mp); + /* send it... */ + S (mp); + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_one_get_map_request_itr_rlocs (vat_main_t * vam) +{ + vl_api_one_get_map_request_itr_rlocs_t *mp; + int ret; + + if (!vam->json_output) + { + print (vam->ofp, "%=20s", "itr-rlocs:"); + } + + M (ONE_GET_MAP_REQUEST_ITR_RLOCS, mp); + /* send it... */ + S (mp); + /* Wait for a reply... */ + W (ret); + return ret; +} + +#define vat_plugin_register vat_plugin_register_one +#include + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/lisp/lisp-cp/packets.c b/src/plugins/lisp/lisp-cp/packets.c new file mode 100644 index 00000000000..95f95cdb68a --- /dev/null +++ b/src/plugins/lisp/lisp-cp/packets.c @@ -0,0 +1,226 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +/* Returns IP ID for the packet */ +/* static u16 ip_id = 0; +static inline u16 +get_IP_ID() +{ + ip_id++; + return (ip_id); +} */ + +u16 +udp_ip4_checksum (const void *b, u32 len, u8 * src, u8 * dst) +{ + const u16 *buf = b; + u16 *ip_src = (u16 *) src; + u16 *ip_dst = (u16 *) dst; + u32 length = len; + u32 sum = 0; + + while (len > 1) + { + sum += *buf++; + if (sum & 0x80000000) + sum = (sum & 0xFFFF) + (sum >> 16); + len -= 2; + } + + /* Add the padding if the packet length is odd */ + if (len & 1) + sum += *((u8 *) buf); + + /* Add the pseudo-header */ + sum += *(ip_src++); + sum += *ip_src; + + sum += *(ip_dst++); + sum += *ip_dst; + + sum += clib_host_to_net_u16 (IP_PROTOCOL_UDP); + sum += clib_host_to_net_u16 (length); + + /* Add the carries */ + while (sum >> 16) + sum = (sum & 0xFFFF) + (sum >> 16); + + /* Return the one's complement of sum */ + return ((u16) (~sum)); +} + +u16 +udp_ip6_checksum (ip6_header_t * ip6, udp_header_t * up, u32 len) +{ + size_t i; + register const u16 *sp; + u32 sum; + union + { + struct + { + ip6_address_t ph_src; + ip6_address_t ph_dst; + u32 ph_len; + u8 ph_zero[3]; + u8 ph_nxt; + } ph; + u16 pa[20]; + } phu; + + /* pseudo-header */ + clib_memset (&phu, 0, sizeof (phu)); + phu.ph.ph_src = ip6->src_address; + phu.ph.ph_dst = ip6->dst_address; + phu.ph.ph_len = clib_host_to_net_u32 (len); + phu.ph.ph_nxt = IP_PROTOCOL_UDP; + + sum = 0; + for (i = 0; i < sizeof (phu.pa) / sizeof (phu.pa[0]); i++) + sum += phu.pa[i]; + + sp = (const u16 *) up; + + for (i = 0; i < (len & ~1); i += 2) + sum += *sp++; + + if (len & 1) + sum += clib_host_to_net_u16 ((*(const u8 *) sp) << 8); + + while (sum > 0xffff) + sum = (sum & 0xffff) + (sum >> 16); + sum = ~sum & 0xffff; + + return (sum); +} + +u16 +udp_checksum (udp_header_t * uh, u32 udp_len, void *ih, u8 version) +{ + switch (version) + { + case AF_IP4: + return (udp_ip4_checksum (uh, udp_len, + ((ip4_header_t *) ih)->src_address.as_u8, + ((ip4_header_t *) ih)->dst_address.as_u8)); + case AF_IP6: + return (udp_ip6_checksum (ih, uh, udp_len)); + default: + return ~0; + } +} + +void * +pkt_push_udp (vlib_main_t * vm, vlib_buffer_t * b, u16 sp, u16 dp) +{ + udp_header_t *uh; + u16 udp_len = sizeof (udp_header_t) + vlib_buffer_length_in_chain (vm, b); + + uh = vlib_buffer_push_uninit (b, sizeof (*uh)); + + uh->src_port = clib_host_to_net_u16 (sp); + uh->dst_port = clib_host_to_net_u16 (dp); + uh->length = clib_host_to_net_u16 (udp_len); + uh->checksum = 0; + return uh; +} + +void * +pkt_push_ip (vlib_main_t * vm, vlib_buffer_t * b, ip_address_t * src, + ip_address_t * dst, u32 proto, u8 csum_offload) +{ + if (ip_addr_version (src) != ip_addr_version (dst)) + { + clib_warning ("src %U and dst %U IP have different AFI! Discarding!", + format_ip_address, src, format_ip_address, dst); + return 0; + } + + switch (ip_addr_version (src)) + { + case AF_IP4: + return vlib_buffer_push_ip4 (vm, b, &ip_addr_v4 (src), + &ip_addr_v4 (dst), proto, csum_offload); + break; + case AF_IP6: + return vlib_buffer_push_ip6 (vm, b, &ip_addr_v6 (src), + &ip_addr_v6 (dst), proto); + break; + } + + return 0; +} + +void * +pkt_push_udp_and_ip (vlib_main_t * vm, vlib_buffer_t * b, u16 sp, u16 dp, + ip_address_t * sip, ip_address_t * dip, u8 csum_offload) +{ + u16 udpsum; + udp_header_t *uh; + void *ih; + + uh = pkt_push_udp (vm, b, sp, dp); + + if (csum_offload) + { + ih = pkt_push_ip (vm, b, sip, dip, IP_PROTOCOL_UDP, 1); + b->flags |= VNET_BUFFER_F_OFFLOAD_UDP_CKSUM; + vnet_buffer (b)->l3_hdr_offset = (u8 *) ih - b->data; + vnet_buffer (b)->l4_hdr_offset = (u8 *) uh - b->data; + uh->checksum = 0; + } + else + { + ih = pkt_push_ip (vm, b, sip, dip, IP_PROTOCOL_UDP, 0); + udpsum = udp_checksum (uh, clib_net_to_host_u16 (uh->length), ih, + ip_addr_version (sip)); + if (udpsum == (u16) ~ 0) + { + clib_warning ("Failed UDP checksum! Discarding"); + return 0; + } + /* clear flags used for csum since we're not offloading */ + b->flags &= ~(VNET_BUFFER_F_IS_IP4 | VNET_BUFFER_F_IS_IP6); + uh->checksum = udpsum; + } + return ih; +} + +void * +pkt_push_ecm_hdr (vlib_buffer_t * b) +{ + ecm_hdr_t *h; + h = vlib_buffer_push_uninit (b, sizeof (h[0])); + + clib_memset (h, 0, sizeof (h[0])); + h->type = LISP_ENCAP_CONTROL_TYPE; + clib_memset (h->reserved2, 0, sizeof (h->reserved2)); + + return h; +} + +/* *INDENT-ON* */ + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/lisp/lisp-cp/packets.h b/src/plugins/lisp/lisp-cp/packets.h new file mode 100644 index 00000000000..68cd949e75d --- /dev/null +++ b/src/plugins/lisp/lisp-cp/packets.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#define IP_DF 0x4000 /* don't fragment */ + +void *pkt_push_ip (vlib_main_t * vm, vlib_buffer_t * b, ip_address_t * src, + ip_address_t * dst, u32 proto, u8 csum_offload); + +void *pkt_push_udp_and_ip (vlib_main_t * vm, vlib_buffer_t * b, u16 sp, + u16 dp, ip_address_t * sip, ip_address_t * dip, + u8 cksum_offload); + +void *pkt_push_ecm_hdr (vlib_buffer_t * b); + +/* *INDENT-ON* */ + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/lisp/lisp-gpe/FEATURE.yaml b/src/plugins/lisp/lisp-gpe/FEATURE.yaml new file mode 100644 index 00000000000..d2016e6120d --- /dev/null +++ b/src/plugins/lisp/lisp-gpe/FEATURE.yaml @@ -0,0 +1,11 @@ +--- +name: Locator ID Separation Protocol Generic Protocol Extension +maintainer: Florin Coras +features: + - ITR, ETR and RTR modes + - Support for Ethernet, IPv4, IPv6 and NSH EIDs (payloads) + - Source/dest forwarding + - IPv4 and IPv6 RLOCs +description: "Locator ID Separation Protocol Generic Protocol Extension (LISP-GPE) implementation" +state: production +properties: [API, CLI, STATS, MULTITHREAD] diff --git a/src/plugins/lisp/lisp-gpe/decap.c b/src/plugins/lisp/lisp-gpe/decap.c new file mode 100644 index 00000000000..03e265ab739 --- /dev/null +++ b/src/plugins/lisp/lisp-gpe/decap.c @@ -0,0 +1,605 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file + * @brief L2 LISP-GPE decap code. + * + */ +#include +#include +#include + +typedef struct +{ + u32 next_index; + u32 tunnel_index; + u32 error; + lisp_gpe_header_t h; +} lisp_gpe_rx_trace_t; + +static u8 * +format_lisp_gpe_rx_trace (u8 * s, va_list * args) +{ + CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); + CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); + lisp_gpe_rx_trace_t *t = va_arg (*args, lisp_gpe_rx_trace_t *); + + if (t->tunnel_index != ~0) + { + s = format (s, "LISP-GPE: tunnel %d next %d error %d", t->tunnel_index, + t->next_index, t->error); + } + else + { + s = format (s, "LISP-GPE: no tunnel next %d error %d\n", t->next_index, + t->error); + } + s = format (s, "\n %U", format_lisp_gpe_header_with_length, &t->h, + (u32) sizeof (t->h) /* max size */ ); + return s; +} + +static u32 next_proto_to_next_index[LISP_GPE_NEXT_PROTOS] = { + LISP_GPE_INPUT_NEXT_DROP, + LISP_GPE_INPUT_NEXT_IP4_INPUT, + LISP_GPE_INPUT_NEXT_IP6_INPUT, + LISP_GPE_INPUT_NEXT_L2_INPUT, + LISP_GPE_INPUT_NEXT_DROP +}; + +always_inline u32 +next_protocol_to_next_index (lisp_gpe_header_t * lgh, u8 * next_header) +{ + lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main (); + + /* lisp-gpe router */ + if (PREDICT_TRUE ((lgh->flags & LISP_GPE_FLAGS_P) + || GPE_ENCAP_VXLAN == lgm->encap_mode)) + { + if (PREDICT_FALSE (lgh->next_protocol >= LISP_GPE_NEXT_PROTOS)) + return LISP_GPE_INPUT_NEXT_DROP; + + return next_proto_to_next_index[lgh->next_protocol]; + } + /* legacy lisp router */ + else if ((lgh->flags & LISP_GPE_FLAGS_P) == 0) + { + ip4_header_t *iph = (ip4_header_t *) next_header; + if ((iph->ip_version_and_header_length & 0xF0) == 0x40) + return LISP_GPE_INPUT_NEXT_IP4_INPUT; + else if ((iph->ip_version_and_header_length & 0xF0) == 0x60) + return LISP_GPE_INPUT_NEXT_IP6_INPUT; + else + return LISP_GPE_INPUT_NEXT_DROP; + } + else + return LISP_GPE_INPUT_NEXT_DROP; +} + +always_inline tunnel_lookup_t * +next_index_to_iface (lisp_gpe_main_t * lgm, u32 next_index) +{ + if (LISP_GPE_INPUT_NEXT_IP4_INPUT == next_index + || LISP_GPE_INPUT_NEXT_IP6_INPUT == next_index) + return &lgm->l3_ifaces; + else if (LISP_GPE_INPUT_NEXT_L2_INPUT == next_index) + return &lgm->l2_ifaces; + else if (LISP_GPE_INPUT_NEXT_NSH_INPUT == next_index) + return &lgm->nsh_ifaces; + clib_warning ("next_index not associated to an interface!"); + return 0; +} + +static_always_inline void +incr_decap_stats (vnet_main_t * vnm, u32 thread_index, u32 length, + u32 sw_if_index, u32 * last_sw_if_index, u32 * n_packets, + u32 * n_bytes) +{ + vnet_interface_main_t *im; + + if (PREDICT_TRUE (sw_if_index == *last_sw_if_index)) + { + *n_packets += 1; + *n_bytes += length; + } + else + { + if (PREDICT_TRUE (*last_sw_if_index != ~0)) + { + im = &vnm->interface_main; + + vlib_increment_combined_counter (im->combined_sw_if_counters + + VNET_INTERFACE_COUNTER_RX, + thread_index, *last_sw_if_index, + *n_packets, *n_bytes); + } + *last_sw_if_index = sw_if_index; + *n_packets = 1; + *n_bytes = length; + } +} + +/** + * @brief LISP-GPE decap dispatcher. + * @node lisp_gpe_input_inline + * + * LISP-GPE decap dispatcher. + * + * Decaps IP-UDP-LISP-GPE header and based on the next protocol and in the + * GPE header and the vni decides the next node to forward the packet to. + * + * @param[in] vm vlib_main_t corresponding to current thread. + * @param[in] node vlib_node_runtime_t data for this node. + * @param[in] frame vlib_frame_t whose contents should be dispatched. + * + * @return number of vectors in frame. + */ +static uword +lisp_gpe_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node, + vlib_frame_t * from_frame, u8 is_v4) +{ + u32 n_left_from, next_index, *from, *to_next, thread_index; + u32 n_bytes = 0, n_packets = 0, last_sw_if_index = ~0, drops = 0; + lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main (); + + thread_index = vm->thread_index; + from = vlib_frame_vector_args (from_frame); + n_left_from = from_frame->n_vectors; + + next_index = node->cached_next_index; + + while (n_left_from > 0) + { + u32 n_left_to_next; + + vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); + + while (n_left_from >= 4 && n_left_to_next >= 2) + { + u32 bi0, bi1; + vlib_buffer_t *b0, *b1; + ip4_udp_lisp_gpe_header_t *iul4_0, *iul4_1; + ip6_udp_lisp_gpe_header_t *iul6_0, *iul6_1; + lisp_gpe_header_t *lh0, *lh1; + u32 next0, next1, error0, error1; + uword *si0, *si1; + tunnel_lookup_t *tl0, *tl1; + + /* Prefetch next iteration. */ + { + vlib_buffer_t *p2, *p3; + + p2 = vlib_get_buffer (vm, from[2]); + p3 = vlib_get_buffer (vm, from[3]); + + vlib_prefetch_buffer_header (p2, LOAD); + vlib_prefetch_buffer_header (p3, LOAD); + + CLIB_PREFETCH (p2->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD); + CLIB_PREFETCH (p3->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD); + } + + bi0 = from[0]; + bi1 = from[1]; + to_next[0] = bi0; + to_next[1] = bi1; + from += 2; + to_next += 2; + n_left_to_next -= 2; + n_left_from -= 2; + + b0 = vlib_get_buffer (vm, bi0); + b1 = vlib_get_buffer (vm, bi1); + + /* udp leaves current_data pointing at the lisp header */ + if (is_v4) + { + vlib_buffer_advance (b0, + -(word) (sizeof (udp_header_t) + + sizeof (ip4_header_t))); + vlib_buffer_advance (b1, + -(word) (sizeof (udp_header_t) + + sizeof (ip4_header_t))); + + iul4_0 = vlib_buffer_get_current (b0); + iul4_1 = vlib_buffer_get_current (b1); + + /* pop (ip, udp, lisp-gpe) */ + vlib_buffer_advance (b0, sizeof (*iul4_0)); + vlib_buffer_advance (b1, sizeof (*iul4_1)); + + lh0 = &iul4_0->lisp; + lh1 = &iul4_1->lisp; + } + else + { + vlib_buffer_advance (b0, + -(word) (sizeof (udp_header_t) + + sizeof (ip6_header_t))); + vlib_buffer_advance (b1, + -(word) (sizeof (udp_header_t) + + sizeof (ip6_header_t))); + + iul6_0 = vlib_buffer_get_current (b0); + iul6_1 = vlib_buffer_get_current (b1); + + /* pop (ip, udp, lisp-gpe) */ + vlib_buffer_advance (b0, sizeof (*iul6_0)); + vlib_buffer_advance (b1, sizeof (*iul6_1)); + + lh0 = &iul6_0->lisp; + lh1 = &iul6_1->lisp; + } + + /* determine next_index from lisp-gpe header */ + next0 = next_protocol_to_next_index (lh0, + vlib_buffer_get_current (b0)); + next1 = next_protocol_to_next_index (lh1, + vlib_buffer_get_current (b1)); + + /* determine if tunnel is l2 or l3 */ + tl0 = next_index_to_iface (lgm, next0); + tl1 = next_index_to_iface (lgm, next1); + + /* map iid/vni to lisp-gpe sw_if_index which is used by ipx_input to + * decide the rx vrf and the input features to be applied */ + si0 = hash_get (tl0->sw_if_index_by_vni, + clib_net_to_host_u32 (lh0->iid << 8)); + si1 = hash_get (tl1->sw_if_index_by_vni, + clib_net_to_host_u32 (lh1->iid << 8)); + + + /* Required to make the l2 tag push / pop code work on l2 subifs */ + vnet_update_l2_len (b0); + vnet_update_l2_len (b1); + + if (si0) + { + incr_decap_stats (lgm->vnet_main, thread_index, + vlib_buffer_length_in_chain (vm, b0), si0[0], + &last_sw_if_index, &n_packets, &n_bytes); + vnet_buffer (b0)->sw_if_index[VLIB_RX] = si0[0]; + error0 = 0; + } + else + { + next0 = LISP_GPE_INPUT_NEXT_DROP; + error0 = LISP_GPE_ERROR_NO_TUNNEL; + drops++; + } + + if (si1) + { + incr_decap_stats (lgm->vnet_main, thread_index, + vlib_buffer_length_in_chain (vm, b1), si1[0], + &last_sw_if_index, &n_packets, &n_bytes); + vnet_buffer (b1)->sw_if_index[VLIB_RX] = si1[0]; + error1 = 0; + } + else + { + next1 = LISP_GPE_INPUT_NEXT_DROP; + error1 = LISP_GPE_ERROR_NO_TUNNEL; + drops++; + } + + b0->error = error0 ? node->errors[error0] : 0; + b1->error = error1 ? node->errors[error1] : 0; + + if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) + { + lisp_gpe_rx_trace_t *tr = vlib_add_trace (vm, node, b0, + sizeof (*tr)); + tr->next_index = next0; + tr->error = error0; + tr->h = lh0[0]; + } + + if (PREDICT_FALSE (b1->flags & VLIB_BUFFER_IS_TRACED)) + { + lisp_gpe_rx_trace_t *tr = vlib_add_trace (vm, node, b1, + sizeof (*tr)); + tr->next_index = next1; + tr->error = error1; + tr->h = lh1[0]; + } + + vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next, + n_left_to_next, bi0, bi1, next0, + next1); + } + + while (n_left_from > 0 && n_left_to_next > 0) + { + u32 bi0; + vlib_buffer_t *b0; + u32 next0; + ip4_udp_lisp_gpe_header_t *iul4_0; + ip6_udp_lisp_gpe_header_t *iul6_0; + lisp_gpe_header_t *lh0; + u32 error0; + uword *si0; + tunnel_lookup_t *tl0; + + bi0 = from[0]; + to_next[0] = bi0; + from += 1; + to_next += 1; + n_left_from -= 1; + n_left_to_next -= 1; + + b0 = vlib_get_buffer (vm, bi0); + + /* udp leaves current_data pointing at the lisp header + * TODO: there's no difference in processing between v4 and v6 + * encapsulated packets so the code should be simplified if ip header + * info is not going to be used for dp smrs/dpsec */ + if (is_v4) + { + vlib_buffer_advance (b0, + -(word) (sizeof (udp_header_t) + + sizeof (ip4_header_t))); + + iul4_0 = vlib_buffer_get_current (b0); + + /* pop (ip, udp, lisp-gpe) */ + vlib_buffer_advance (b0, sizeof (*iul4_0)); + + lh0 = &iul4_0->lisp; + } + else + { + vlib_buffer_advance (b0, + -(word) (sizeof (udp_header_t) + + sizeof (ip6_header_t))); + + iul6_0 = vlib_buffer_get_current (b0); + + /* pop (ip, udp, lisp-gpe) */ + vlib_buffer_advance (b0, sizeof (*iul6_0)); + + lh0 = &iul6_0->lisp; + } + + /* TODO if security is to be implemented, something similar to RPF, + * probably we'd like to check that the peer is allowed to send us + * packets. For this, we should use the tunnel table OR check that + * we have a mapping for the source eid and that the outer source of + * the packet is one of its locators */ + + /* determine next_index from lisp-gpe header */ + next0 = next_protocol_to_next_index (lh0, + vlib_buffer_get_current (b0)); + + /* determine if tunnel is l2 or l3 */ + tl0 = next_index_to_iface (lgm, next0); + + /* map iid/vni to lisp-gpe sw_if_index which is used by ipx_input to + * decide the rx vrf and the input features to be applied. + * NOTE: vni uses only the first 24 bits */ + si0 = hash_get (tl0->sw_if_index_by_vni, + clib_net_to_host_u32 (lh0->iid << 8)); + + /* Required to make the l2 tag push / pop code work on l2 subifs */ + vnet_update_l2_len (b0); + + if (si0) + { + incr_decap_stats (lgm->vnet_main, thread_index, + vlib_buffer_length_in_chain (vm, b0), si0[0], + &last_sw_if_index, &n_packets, &n_bytes); + vnet_buffer (b0)->sw_if_index[VLIB_RX] = si0[0]; + error0 = 0; + } + else + { + next0 = LISP_GPE_INPUT_NEXT_DROP; + error0 = LISP_GPE_ERROR_NO_TUNNEL; + drops++; + } + + /* TODO error handling if security is implemented */ + b0->error = error0 ? node->errors[error0] : 0; + + if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) + { + lisp_gpe_rx_trace_t *tr = vlib_add_trace (vm, node, b0, + sizeof (*tr)); + tr->next_index = next0; + tr->error = error0; + tr->h = lh0[0]; + } + + vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, + n_left_to_next, bi0, next0); + } + + vlib_put_next_frame (vm, node, next_index, n_left_to_next); + } + + /* flush iface stats */ + incr_decap_stats (lgm->vnet_main, thread_index, 0, ~0, &last_sw_if_index, + &n_packets, &n_bytes); + vlib_node_increment_counter (vm, lisp_gpe_ip4_input_node.index, + LISP_GPE_ERROR_NO_TUNNEL, drops); + return from_frame->n_vectors; +} + +static uword +lisp_gpe_ip4_input (vlib_main_t * vm, vlib_node_runtime_t * node, + vlib_frame_t * from_frame) +{ + return lisp_gpe_input_inline (vm, node, from_frame, 1); +} + +static uword +lisp_gpe_ip6_input (vlib_main_t * vm, vlib_node_runtime_t * node, + vlib_frame_t * from_frame) +{ + return lisp_gpe_input_inline (vm, node, from_frame, 0); +} + +static char *lisp_gpe_ip4_input_error_strings[] = { +#define lisp_gpe_error(n,s) s, +#include +#undef lisp_gpe_error +}; + +/* *INDENT-OFF* */ +VLIB_REGISTER_NODE (lisp_gpe_ip4_input_node) = { + .function = lisp_gpe_ip4_input, + .name = "lisp-gpe-ip4-input", + /* Takes a vector of packets. */ + .vector_size = sizeof (u32), + .n_next_nodes = LISP_GPE_INPUT_N_NEXT, + .next_nodes = { +#define _(s,n) [LISP_GPE_INPUT_NEXT_##s] = n, + foreach_lisp_gpe_ip_input_next +#undef _ + }, + + .n_errors = ARRAY_LEN (lisp_gpe_ip4_input_error_strings), + .error_strings = lisp_gpe_ip4_input_error_strings, + + .format_buffer = format_lisp_gpe_header_with_length, + .format_trace = format_lisp_gpe_rx_trace, + // $$$$ .unformat_buffer = unformat_lisp_gpe_header, +}; +/* *INDENT-ON* */ + +/* *INDENT-OFF* */ +VLIB_REGISTER_NODE (lisp_gpe_ip6_input_node) = { + .function = lisp_gpe_ip6_input, + .name = "lisp-gpe-ip6-input", + /* Takes a vector of packets. */ + .vector_size = sizeof (u32), + .n_next_nodes = LISP_GPE_INPUT_N_NEXT, + .next_nodes = { +#define _(s,n) [LISP_GPE_INPUT_NEXT_##s] = n, + foreach_lisp_gpe_ip_input_next +#undef _ + }, + + .n_errors = ARRAY_LEN (lisp_gpe_ip4_input_error_strings), + .error_strings = lisp_gpe_ip4_input_error_strings, + + .format_buffer = format_lisp_gpe_header_with_length, + .format_trace = format_lisp_gpe_rx_trace, + // $$$$ .unformat_buffer = unformat_lisp_gpe_header, +}; +/* *INDENT-ON* */ + +/** + * Adds arc from lisp-gpe-input to nsh-input if nsh-input is available + */ +static void +gpe_add_arc_from_input_to_nsh () +{ + lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main (); + vlib_main_t *vm = lgm->vlib_main; + vlib_node_t *nsh_input; + + /* Arc already exists */ + if (next_proto_to_next_index[LISP_GPE_NEXT_PROTO_NSH] + != LISP_GPE_INPUT_NEXT_DROP) + return; + + /* Check if nsh-input is available */ + if ((nsh_input = vlib_get_node_by_name (vm, (u8 *) "nsh-input"))) + { + u32 slot4, slot6; + slot4 = vlib_node_add_next_with_slot (vm, lisp_gpe_ip4_input_node.index, + nsh_input->index, + LISP_GPE_NEXT_PROTO_NSH); + slot6 = vlib_node_add_next_with_slot (vm, lisp_gpe_ip6_input_node.index, + nsh_input->index, + LISP_GPE_NEXT_PROTO_NSH); + ASSERT (slot4 == slot6 && slot4 == LISP_GPE_INPUT_NEXT_NSH_INPUT); + + next_proto_to_next_index[LISP_GPE_NEXT_PROTO_NSH] = slot4; + } +} + +/** GPE decap init function. */ +clib_error_t * +gpe_decap_init (vlib_main_t * vm) +{ + clib_error_t *error = 0; + + if ((error = vlib_call_init_function (vm, lisp_gpe_init))) + return error; + + gpe_add_arc_from_input_to_nsh (); + return 0; +} + +static uword +lisp_gpe_nsh_placeholder_input (vlib_main_t * vm, vlib_node_runtime_t * node, + vlib_frame_t * from_frame) +{ + vlib_node_increment_counter (vm, node->node_index, 0, 1); + return from_frame->n_vectors; +} + +static char *lisp_gpe_nsh_placeholder_error_strings[] = { + "lisp gpe placeholder nsh decap", +}; + +/* *INDENT-OFF* */ +VLIB_REGISTER_NODE (lisp_gpe_nsh_placeholder_input_node) = { + .function = lisp_gpe_nsh_placeholder_input, + .name = "lisp-gpe-nsh-placeholder-input", + .vector_size = sizeof (u32), + .type = VLIB_NODE_TYPE_INTERNAL, + .n_next_nodes = 1, + + .n_errors = 1, + .error_strings = lisp_gpe_nsh_placeholder_error_strings, + + .next_nodes = { + [0] = "error-drop", + }, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_add_placeholder_nsh_node_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main (); + vlib_node_add_next (lgm->vlib_main, lisp_gpe_ip4_input_node.index, + lisp_gpe_nsh_placeholder_input_node.index); + next_proto_to_next_index[LISP_GPE_NEXT_PROTO_NSH] = + LISP_GPE_INPUT_NEXT_NSH_INPUT; + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (lisp_add_placeholder_nsh_node_command, static) = { + .path = "test one nsh add-placeholder-decap-node", + .function = lisp_add_placeholder_nsh_node_command_fn, +}; +/* *INDENT-ON* */ + +VLIB_INIT_FUNCTION (gpe_decap_init); + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/lisp/lisp-gpe/dir.dox b/src/plugins/lisp/lisp-gpe/dir.dox new file mode 100644 index 00000000000..afa6da9ab2c --- /dev/null +++ b/src/plugins/lisp/lisp-gpe/dir.dox @@ -0,0 +1,26 @@ +/* + * + * Copyright (c) 2013 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + @dir + @brief LISP-GPE code. + + An implementation of LISP-GPE as per: + rfc-6830 + draft-lewis-lisp-gpe-02 + + See file: rfc.txt + +*/ \ No newline at end of file diff --git a/src/plugins/lisp/lisp-gpe/interface.c b/src/plugins/lisp/lisp-gpe/interface.c new file mode 100644 index 00000000000..0d5f689fe7b --- /dev/null +++ b/src/plugins/lisp/lisp-gpe/interface.c @@ -0,0 +1,945 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * @brief Common utility functions for LISP-GPE interfaces. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/** + * @brief The VLIB node arc/edge from the interface's TX node, to the L2 + * load-balanceing node. Which is where all packets go + */ +static uword l2_arc_to_lb; + +#define foreach_lisp_gpe_tx_next \ + _(DROP, "error-drop") \ + _(IP4_LOOKUP, "ip4-lookup") \ + _(IP6_LOOKUP, "ip6-lookup") + +typedef enum +{ +#define _(sym,str) LISP_GPE_TX_NEXT_##sym, + foreach_lisp_gpe_tx_next +#undef _ + LISP_GPE_TX_N_NEXT, +} lisp_gpe_tx_next_t; + +typedef struct +{ + u32 tunnel_index; +} lisp_gpe_tx_trace_t; + +u8 * +format_lisp_gpe_tx_trace (u8 * s, va_list * args) +{ + CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); + CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); + lisp_gpe_tx_trace_t *t = va_arg (*args, lisp_gpe_tx_trace_t *); + + s = format (s, "LISP-GPE-TX: tunnel %d", t->tunnel_index); + return s; +} + +#define is_v4_packet(_h) ((*(u8*) _h) & 0xF0) == 0x40 + +/** + * @brief LISP-GPE interface TX (encap) function. + * @node lisp_gpe_interface_tx + * + * The LISP-GPE interface TX (encap) function. + * + * Looks up the associated tunnel based on the adjacency hit in the SD FIB + * and if the tunnel is multihomed it uses the flow hash to determine + * sub-tunnel, and rewrite string, to be used to encapsulate the packet. + * + * @param[in] vm vlib_main_t corresponding to the current thread. + * @param[in] node vlib_node_runtime_t data for this node. + * @param[in] frame vlib_frame_t whose contents should be dispatched. + * + * @return number of vectors in frame. + */ +static uword +lisp_gpe_interface_tx (vlib_main_t * vm, vlib_node_runtime_t * node, + vlib_frame_t * from_frame) +{ + u32 n_left_from, next_index, *from, *to_next; + lisp_gpe_main_t *lgm = &lisp_gpe_main; + + from = vlib_frame_vector_args (from_frame); + n_left_from = from_frame->n_vectors; + + next_index = node->cached_next_index; + + while (n_left_from > 0) + { + u32 n_left_to_next; + + vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); + + while (n_left_from > 0 && n_left_to_next > 0) + { + u32 bi0, adj_index0, next0; + const ip_adjacency_t *adj0; + const dpo_id_t *dpo0; + vlib_buffer_t *b0; + u8 is_v4_0; + + bi0 = from[0]; + to_next[0] = bi0; + from += 1; + to_next += 1; + n_left_from -= 1; + n_left_to_next -= 1; + + b0 = vlib_get_buffer (vm, bi0); + + /* Fixup the checksum and len fields in the LISP tunnel encap + * that was applied at the midchain node */ + is_v4_0 = is_v4_packet (vlib_buffer_get_current (b0)); + ip_udp_fixup_one (lgm->vlib_main, b0, is_v4_0); + + /* Follow the DPO on which the midchain is stacked */ + adj_index0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX]; + adj0 = adj_get (adj_index0); + dpo0 = &adj0->sub_type.midchain.next_dpo; + next0 = dpo0->dpoi_next_node; + vnet_buffer (b0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index; + + if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) + { + lisp_gpe_tx_trace_t *tr = vlib_add_trace (vm, node, b0, + sizeof (*tr)); + tr->tunnel_index = adj_index0; + } + vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, + n_left_to_next, bi0, next0); + } + + vlib_put_next_frame (vm, node, next_index, n_left_to_next); + } + + return from_frame->n_vectors; +} + +static u8 * +format_lisp_gpe_name (u8 * s, va_list * args) +{ + u32 dev_instance = va_arg (*args, u32); + return format (s, "lisp_gpe%d", dev_instance); +} + +/* *INDENT-OFF* */ +VNET_DEVICE_CLASS (lisp_gpe_device_class) = { + .name = "LISP_GPE", + .format_device_name = format_lisp_gpe_name, + .format_tx_trace = format_lisp_gpe_tx_trace, + .tx_function = lisp_gpe_interface_tx, +}; +/* *INDENT-ON* */ + +u8 * +format_lisp_gpe_header_with_length (u8 * s, va_list * args) +{ + lisp_gpe_header_t *h = va_arg (*args, lisp_gpe_header_t *); + u32 max_header_bytes = va_arg (*args, u32); + u32 header_bytes; + + header_bytes = sizeof (h[0]); + if (max_header_bytes != 0 && header_bytes > max_header_bytes) + return format (s, "lisp-gpe header truncated"); + + s = format (s, "flags: "); +#define _(n,v) if (h->flags & v) s = format (s, "%s ", #n); + foreach_lisp_gpe_flag_bit; +#undef _ + + s = format (s, "\n ver_res %d res %d next_protocol %d iid %d(%x)", + h->ver_res, h->res, h->next_protocol, + clib_net_to_host_u32 (h->iid << 8), + clib_net_to_host_u32 (h->iid << 8)); + return s; +} + +/* *INDENT-OFF* */ +VNET_HW_INTERFACE_CLASS (lisp_gpe_hw_class) = { + .name = "LISP_GPE", + .format_header = format_lisp_gpe_header_with_length, + .build_rewrite = lisp_gpe_build_rewrite, + .update_adjacency = lisp_gpe_update_adjacency, +}; +/* *INDENT-ON* */ + + +typedef struct +{ + u32 dpo_index; +} l2_lisp_gpe_tx_trace_t; + +static u8 * +format_l2_lisp_gpe_tx_trace (u8 * s, va_list * args) +{ + CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); + CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); + l2_lisp_gpe_tx_trace_t *t = va_arg (*args, l2_lisp_gpe_tx_trace_t *); + + s = format (s, "L2-LISP-GPE-TX: load-balance %d", t->dpo_index); + return s; +} + +/** + * @brief LISP-GPE interface TX (encap) function for L2 overlays. + * @node l2_lisp_gpe_interface_tx + * + * The L2 LISP-GPE interface TX (encap) function. + * + * Uses bridge domain index, source and destination ethernet addresses to + * lookup tunnel. If the tunnel is multihomed a flow has is used to determine + * the sub-tunnel and therefore the rewrite string to be used to encapsulate + * the packets. + * + * @param[in] vm vlib_main_t corresponding to the current thread. + * @param[in] node vlib_node_runtime_t data for this node. + * @param[in] frame vlib_frame_t whose contents should be dispatched. + * + * @return number of vectors in frame. + */ +static uword +l2_lisp_gpe_interface_tx (vlib_main_t * vm, vlib_node_runtime_t * node, + vlib_frame_t * from_frame) +{ + u32 n_left_from, next_index, *from, *to_next; + lisp_gpe_main_t *lgm = &lisp_gpe_main; + u32 thread_index = vm->thread_index; + vlib_combined_counter_main_t *cm = &load_balance_main.lbm_to_counters; + + from = vlib_frame_vector_args (from_frame); + n_left_from = from_frame->n_vectors; + + next_index = node->cached_next_index; + + while (n_left_from > 0) + { + u32 n_left_to_next; + + vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); + + while (n_left_from > 0 && n_left_to_next > 0) + { + vlib_buffer_t *b0; + u32 bi0, lbi0; + ethernet_header_t *e0; + + bi0 = from[0]; + to_next[0] = bi0; + from += 1; + to_next += 1; + n_left_from -= 1; + n_left_to_next -= 1; + + b0 = vlib_get_buffer (vm, bi0); + e0 = vlib_buffer_get_current (b0); + + vnet_buffer (b0)->lisp.overlay_afi = LISP_AFI_MAC; + + /* lookup dst + src mac */ + lbi0 = lisp_l2_fib_lookup (lgm, vnet_buffer (b0)->l2.bd_index, + e0->src_address, e0->dst_address); + vnet_buffer (b0)->ip.adj_index[VLIB_TX] = lbi0; + + vlib_increment_combined_counter (cm, thread_index, lbi0, 1, + vlib_buffer_length_in_chain (vm, + b0)); + if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) + { + l2_lisp_gpe_tx_trace_t *tr = vlib_add_trace (vm, node, b0, + sizeof (*tr)); + tr->dpo_index = lbi0; + } + vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, + n_left_to_next, bi0, l2_arc_to_lb); + } + + vlib_put_next_frame (vm, node, next_index, n_left_to_next); + } + + return from_frame->n_vectors; +} + +static u8 * +format_l2_lisp_gpe_name (u8 * s, va_list * args) +{ + u32 dev_instance = va_arg (*args, u32); + return format (s, "l2_lisp_gpe%d", dev_instance); +} + +/* *INDENT-OFF* */ +VNET_DEVICE_CLASS (l2_lisp_gpe_device_class,static) = { + .name = "L2_LISP_GPE", + .format_device_name = format_l2_lisp_gpe_name, + .format_tx_trace = format_l2_lisp_gpe_tx_trace, + .tx_function = l2_lisp_gpe_interface_tx, +}; +/* *INDENT-ON* */ + +typedef struct +{ + u32 dpo_index; +} nsh_lisp_gpe_tx_trace_t; + +u8 * +format_nsh_lisp_gpe_tx_trace (u8 * s, va_list * args) +{ + CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); + CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); + nsh_lisp_gpe_tx_trace_t *t = va_arg (*args, nsh_lisp_gpe_tx_trace_t *); + + s = format (s, "NSH-GPE-TX: tunnel %d", t->dpo_index); + return s; +} + +/** + * @brief LISP-GPE interface TX for NSH overlays. + * @node nsh_lisp_gpe_interface_tx + * + * The NSH LISP-GPE interface TX function. + * + * @param[in] vm vlib_main_t corresponding to the current thread. + * @param[in] node vlib_node_runtime_t data for this node. + * @param[in] frame vlib_frame_t whose contents should be dispatched. + * + * @return number of vectors in frame. + */ +static uword +nsh_lisp_gpe_interface_tx (vlib_main_t * vm, vlib_node_runtime_t * node, + vlib_frame_t * from_frame) +{ + u32 n_left_from, next_index, *from, *to_next; + lisp_gpe_main_t *lgm = &lisp_gpe_main; + + from = vlib_frame_vector_args (from_frame); + n_left_from = from_frame->n_vectors; + + next_index = node->cached_next_index; + + while (n_left_from > 0) + { + u32 n_left_to_next; + + vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); + + while (n_left_from > 0 && n_left_to_next > 0) + { + vlib_buffer_t *b0; + u32 bi0; + u32 *nsh0, next0; + const dpo_id_t *dpo0; + + bi0 = from[0]; + to_next[0] = bi0; + from += 1; + to_next += 1; + n_left_from -= 1; + n_left_to_next -= 1; + + b0 = vlib_get_buffer (vm, bi0); + nsh0 = vlib_buffer_get_current (b0); + + vnet_buffer (b0)->lisp.overlay_afi = LISP_AFI_LCAF; + + /* lookup SPI + SI (second word of the NSH header). + * NB: Load balancing was done by the control plane */ + dpo0 = lisp_nsh_fib_lookup (lgm, nsh0[1]); + + next0 = dpo0->dpoi_next_node; + vnet_buffer (b0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index; + + if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) + { + nsh_lisp_gpe_tx_trace_t *tr = vlib_add_trace (vm, node, b0, + sizeof (*tr)); + tr->dpo_index = dpo0->dpoi_index; + } + vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, + n_left_to_next, bi0, next0); + } + + vlib_put_next_frame (vm, node, next_index, n_left_to_next); + } + + return from_frame->n_vectors; +} + +static u8 * +format_nsh_lisp_gpe_name (u8 * s, va_list * args) +{ + u32 dev_instance = va_arg (*args, u32); + return format (s, "nsh_lisp_gpe%d", dev_instance); +} + +/* *INDENT-OFF* */ +VNET_DEVICE_CLASS (nsh_lisp_gpe_device_class,static) = { + .name = "NSH_LISP_GPE", + .format_device_name = format_nsh_lisp_gpe_name, + .format_tx_trace = format_nsh_lisp_gpe_tx_trace, + .tx_function = nsh_lisp_gpe_interface_tx, +}; +/* *INDENT-ON* */ + +static vnet_hw_interface_t * +lisp_gpe_create_iface (lisp_gpe_main_t * lgm, u32 vni, u32 dp_table, + vnet_device_class_t * dev_class, + tunnel_lookup_t * tuns) +{ + u32 flen; + u32 hw_if_index = ~0; + u8 *new_name; + vnet_hw_interface_t *hi; + vnet_main_t *vnm = lgm->vnet_main; + + /* create hw lisp_gpeX iface if needed, otherwise reuse existing */ + flen = vec_len (lgm->free_tunnel_hw_if_indices); + if (flen > 0) + { + hw_if_index = lgm->free_tunnel_hw_if_indices[flen - 1]; + _vec_len (lgm->free_tunnel_hw_if_indices) -= 1; + + hi = vnet_get_hw_interface (vnm, hw_if_index); + + /* rename interface */ + new_name = format (0, "%U", dev_class->format_device_name, vni); + + vec_add1 (new_name, 0); + vnet_rename_interface (vnm, hw_if_index, (char *) new_name); + vec_free (new_name); + + /* clear old stats of freed interface before reuse */ + vnet_interface_main_t *im = &vnm->interface_main; + vnet_interface_counter_lock (im); + vlib_zero_combined_counter (&im->combined_sw_if_counters + [VNET_INTERFACE_COUNTER_TX], + hi->sw_if_index); + vlib_zero_combined_counter (&im->combined_sw_if_counters + [VNET_INTERFACE_COUNTER_RX], + hi->sw_if_index); + vlib_zero_simple_counter (&im->sw_if_counters + [VNET_INTERFACE_COUNTER_DROP], + hi->sw_if_index); + vnet_interface_counter_unlock (im); + } + else + { + hw_if_index = vnet_register_interface (vnm, dev_class->index, vni, + lisp_gpe_hw_class.index, 0); + hi = vnet_get_hw_interface (vnm, hw_if_index); + } + + hash_set (tuns->hw_if_index_by_dp_table, dp_table, hw_if_index); + + /* set tunnel termination: post decap, packets are tagged as having been + * originated by lisp-gpe interface */ + hash_set (tuns->sw_if_index_by_vni, vni, hi->sw_if_index); + hash_set (tuns->vni_by_sw_if_index, hi->sw_if_index, vni); + + return hi; +} + +static void +lisp_gpe_remove_iface (lisp_gpe_main_t * lgm, u32 hi_index, u32 dp_table, + tunnel_lookup_t * tuns) +{ + vnet_main_t *vnm = lgm->vnet_main; + vnet_hw_interface_t *hi; + uword *vnip; + + hi = vnet_get_hw_interface (vnm, hi_index); + + /* disable interface */ + vnet_sw_interface_set_flags (vnm, hi->sw_if_index, 0 /* down */ ); + vnet_hw_interface_set_flags (vnm, hi->hw_if_index, 0 /* down */ ); + hash_unset (tuns->hw_if_index_by_dp_table, dp_table); + vec_add1 (lgm->free_tunnel_hw_if_indices, hi->hw_if_index); + + /* clean tunnel termination and vni to sw_if_index binding */ + vnip = hash_get (tuns->vni_by_sw_if_index, hi->sw_if_index); + if (0 == vnip) + { + clib_warning ("No vni associated to interface %d", hi->sw_if_index); + return; + } + hash_unset (tuns->sw_if_index_by_vni, vnip[0]); + hash_unset (tuns->vni_by_sw_if_index, hi->sw_if_index); +} + +static void +lisp_gpe_iface_set_table (u32 sw_if_index, u32 table_id) +{ + fib_node_index_t fib_index; + + fib_index = fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP4, table_id, + FIB_SOURCE_LISP); + vec_validate (ip4_main.fib_index_by_sw_if_index, sw_if_index); + ip4_main.fib_index_by_sw_if_index[sw_if_index] = fib_index; + ip4_sw_interface_enable_disable (sw_if_index, 1); + + fib_index = fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP6, table_id, + FIB_SOURCE_LISP); + vec_validate (ip6_main.fib_index_by_sw_if_index, sw_if_index); + ip6_main.fib_index_by_sw_if_index[sw_if_index] = fib_index; + ip6_sw_interface_enable_disable (sw_if_index, 1); +} + +static void +lisp_gpe_tenant_del_default_routes (u32 table_id) +{ + fib_protocol_t proto; + + FOR_EACH_FIB_IP_PROTOCOL (proto) + { + fib_prefix_t prefix = { + .fp_proto = proto, + }; + u32 fib_index; + + fib_index = fib_table_find (prefix.fp_proto, table_id); + fib_table_entry_special_remove (fib_index, &prefix, FIB_SOURCE_LISP); + fib_table_unlock (fib_index, prefix.fp_proto, FIB_SOURCE_LISP); + } +} + +static void +lisp_gpe_tenant_add_default_routes (u32 table_id) +{ + fib_protocol_t proto; + + FOR_EACH_FIB_IP_PROTOCOL (proto) + { + fib_prefix_t prefix = { + .fp_proto = proto, + }; + u32 fib_index; + + /* + * Add a deafult route that results in a control plane punt DPO + */ + fib_index = fib_table_find_or_create_and_lock (prefix.fp_proto, table_id, + FIB_SOURCE_LISP); + fib_table_entry_special_dpo_add (fib_index, &prefix, FIB_SOURCE_LISP, + FIB_ENTRY_FLAG_EXCLUSIVE, + lisp_cp_dpo_get (fib_proto_to_dpo + (proto))); + } +} + + +/** + * @brief Add/del LISP-GPE L3 interface. + * + * Creates LISP-GPE interface, sets ingress arcs from lisp_gpeX_lookup, + * installs default routes that attract all traffic with no more specific + * routes to lgpe-ipx-lookup, set egress arcs to ipx-lookup, sets + * the interface in the right vrf and enables it. + * + * @param[in] lgm Reference to @ref lisp_gpe_main_t. + * @param[in] a Parameters to create interface. + * + * @return number of vectors in frame. + */ +u32 +lisp_gpe_add_l3_iface (lisp_gpe_main_t * lgm, u32 vni, u32 table_id, + u8 with_default_routes) +{ + vnet_main_t *vnm = lgm->vnet_main; + tunnel_lookup_t *l3_ifaces = &lgm->l3_ifaces; + vnet_hw_interface_t *hi; + uword *hip, *si; + + hip = hash_get (l3_ifaces->hw_if_index_by_dp_table, table_id); + + if (hip) + { + clib_warning ("vrf %d already mapped to a vni", table_id); + return ~0; + } + + si = hash_get (l3_ifaces->sw_if_index_by_vni, vni); + + if (si) + { + clib_warning ("Interface for vni %d already exists", vni); + } + + /* create lisp iface and populate tunnel tables */ + hi = lisp_gpe_create_iface (lgm, vni, table_id, + &lisp_gpe_device_class, l3_ifaces); + + /* insert default routes that point to lisp-cp lookup */ + lisp_gpe_iface_set_table (hi->sw_if_index, table_id); + if (with_default_routes) + lisp_gpe_tenant_add_default_routes (table_id); + + /* enable interface */ + vnet_sw_interface_set_flags (vnm, hi->sw_if_index, + VNET_SW_INTERFACE_FLAG_ADMIN_UP); + vnet_hw_interface_set_flags (vnm, hi->hw_if_index, + VNET_HW_INTERFACE_FLAG_LINK_UP); + + return (hi->sw_if_index); +} + +void +lisp_gpe_del_l3_iface (lisp_gpe_main_t * lgm, u32 vni, u32 table_id) +{ + vnet_main_t *vnm = lgm->vnet_main; + tunnel_lookup_t *l3_ifaces = &lgm->l3_ifaces; + vnet_hw_interface_t *hi; + uword *hip; + + hip = hash_get (l3_ifaces->hw_if_index_by_dp_table, table_id); + + if (hip == 0) + { + clib_warning ("The interface for vrf %d doesn't exist", table_id); + return; + } + + hi = vnet_get_hw_interface (vnm, hip[0]); + + lisp_gpe_remove_iface (lgm, hip[0], table_id, &lgm->l3_ifaces); + + /* unset default routes */ + ip4_sw_interface_enable_disable (hi->sw_if_index, 0); + ip6_sw_interface_enable_disable (hi->sw_if_index, 0); + lisp_gpe_tenant_del_default_routes (table_id); +} + +/** + * @brief Add/del LISP-GPE L2 interface. + * + * Creates LISP-GPE interface, sets it in L2 mode in the appropriate + * bridge domain, sets egress arcs and enables it. + * + * @param[in] lgm Reference to @ref lisp_gpe_main_t. + * @param[in] a Parameters to create interface. + * + * @return number of vectors in frame. + */ +u32 +lisp_gpe_add_l2_iface (lisp_gpe_main_t * lgm, u32 vni, u32 bd_id) +{ + vnet_main_t *vnm = lgm->vnet_main; + tunnel_lookup_t *l2_ifaces = &lgm->l2_ifaces; + vnet_hw_interface_t *hi; + uword *hip, *si; + u16 bd_index; + + if (bd_id > L2_BD_ID_MAX) + { + clib_warning ("bridge domain ID %d exceed 16M limit", bd_id); + return ~0; + } + + bd_index = bd_find_or_add_bd_index (&bd_main, bd_id); + hip = hash_get (l2_ifaces->hw_if_index_by_dp_table, bd_index); + + if (hip) + { + clib_warning ("bridge domain %d already mapped to a vni", bd_id); + return ~0; + } + + si = hash_get (l2_ifaces->sw_if_index_by_vni, vni); + if (si) + { + clib_warning ("Interface for vni %d already exists", vni); + return ~0; + } + + /* create lisp iface and populate tunnel tables */ + hi = lisp_gpe_create_iface (lgm, vni, bd_index, + &l2_lisp_gpe_device_class, &lgm->l2_ifaces); + + /* enable interface */ + vnet_sw_interface_set_flags (vnm, hi->sw_if_index, + VNET_SW_INTERFACE_FLAG_ADMIN_UP); + vnet_hw_interface_set_flags (vnm, hi->hw_if_index, + VNET_HW_INTERFACE_FLAG_LINK_UP); + + l2_arc_to_lb = vlib_node_add_named_next (vlib_get_main (), + hi->tx_node_index, + "l2-load-balance"); + + /* we're ready. add iface to l2 bridge domain */ + set_int_l2_mode (lgm->vlib_main, vnm, MODE_L2_BRIDGE, hi->sw_if_index, + bd_index, L2_BD_PORT_TYPE_NORMAL, 0, 0); + + return (hi->sw_if_index); +} + +/** + * @brief Add/del LISP-GPE L2 interface. + * + * Creates LISP-GPE interface, sets it in L2 mode in the appropriate + * bridge domain, sets egress arcs and enables it. + * + * @param[in] lgm Reference to @ref lisp_gpe_main_t. + * @param[in] a Parameters to create interface. + * + * @return number of vectors in frame. + */ +void +lisp_gpe_del_l2_iface (lisp_gpe_main_t * lgm, u32 vni, u32 bd_id) +{ + tunnel_lookup_t *l2_ifaces = &lgm->l2_ifaces; + vnet_hw_interface_t *hi; + + u32 bd_index = bd_find_index (&bd_main, bd_id); + ASSERT (bd_index != ~0); + uword *hip = hash_get (l2_ifaces->hw_if_index_by_dp_table, bd_index); + + if (hip == 0) + { + clib_warning ("The interface for bridge domain %d doesn't exist", + bd_id); + return; + } + + /* Remove interface from bridge .. by enabling L3 mode */ + hi = vnet_get_hw_interface (lgm->vnet_main, hip[0]); + set_int_l2_mode (lgm->vlib_main, lgm->vnet_main, MODE_L3, hi->sw_if_index, + 0, L2_BD_PORT_TYPE_NORMAL, 0, 0); + lisp_gpe_remove_iface (lgm, hip[0], bd_index, &lgm->l2_ifaces); +} + +/** + * @brief Add LISP-GPE NSH interface. + * + * Creates LISP-GPE interface, sets it in L3 mode. + * + * @param[in] lgm Reference to @ref lisp_gpe_main_t. + * @param[in] a Parameters to create interface. + * + * @return sw_if_index. + */ +u32 +vnet_lisp_gpe_add_nsh_iface (lisp_gpe_main_t * lgm) +{ + vnet_main_t *vnm = lgm->vnet_main; + tunnel_lookup_t *nsh_ifaces = &lgm->nsh_ifaces; + vnet_hw_interface_t *hi; + uword *hip, *si; + + hip = hash_get (nsh_ifaces->hw_if_index_by_dp_table, 0); + + if (hip) + { + clib_warning ("NSH interface 0 already exists"); + return ~0; + } + + si = hash_get (nsh_ifaces->sw_if_index_by_vni, 0); + if (si) + { + clib_warning ("NSH interface already exists"); + return ~0; + } + + /* create lisp iface and populate tunnel tables */ + hi = lisp_gpe_create_iface (lgm, 0, 0, + &nsh_lisp_gpe_device_class, &lgm->nsh_ifaces); + + /* enable interface */ + vnet_sw_interface_set_flags (vnm, hi->sw_if_index, + VNET_SW_INTERFACE_FLAG_ADMIN_UP); + vnet_hw_interface_set_flags (vnm, hi->hw_if_index, + VNET_HW_INTERFACE_FLAG_LINK_UP); + + return (hi->sw_if_index); +} + +/** + * @brief Del LISP-GPE NSH interface. + * + */ +void +vnet_lisp_gpe_del_nsh_iface (lisp_gpe_main_t * lgm) +{ + tunnel_lookup_t *nsh_ifaces = &lgm->nsh_ifaces; + uword *hip; + + hip = hash_get (nsh_ifaces->hw_if_index_by_dp_table, 0); + + if (hip == 0) + { + clib_warning ("The NSH 0 interface doesn't exist"); + return; + } + lisp_gpe_remove_iface (lgm, hip[0], 0, &lgm->nsh_ifaces); +} + +static clib_error_t * +lisp_gpe_add_del_iface_command_fn (vlib_main_t * vm, unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + unformat_input_t _line_input, *line_input = &_line_input; + u8 is_add = 1; + u32 table_id, vni, bd_id; + u8 vni_is_set = 0, vrf_is_set = 0, bd_index_is_set = 0; + u8 nsh_iface = 0; + clib_error_t *error = NULL; + + if (vnet_lisp_gpe_enable_disable_status () == 0) + { + return clib_error_return (0, "LISP is disabled"); + } + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "add")) + is_add = 1; + else if (unformat (line_input, "del")) + is_add = 0; + else if (unformat (line_input, "vrf %d", &table_id)) + { + vrf_is_set = 1; + } + else if (unformat (line_input, "vni %d", &vni)) + { + vni_is_set = 1; + } + else if (unformat (line_input, "bd %d", &bd_id)) + { + bd_index_is_set = 1; + } + else if (unformat (line_input, "nsh")) + { + nsh_iface = 1; + } + else + { + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + goto done; + } + } + + if (nsh_iface) + { + if (is_add) + { + if (~0 == vnet_lisp_gpe_add_nsh_iface (&lisp_gpe_main)) + { + error = clib_error_return (0, "NSH interface not created"); + goto done; + } + } + else + { + vnet_lisp_gpe_del_nsh_iface (&lisp_gpe_main); + } + goto done; + } + + if (vrf_is_set && bd_index_is_set) + { + error = clib_error_return + (0, "Cannot set both vrf and brdige domain index!"); + goto done; + } + + if (!vni_is_set) + { + error = clib_error_return (0, "vni must be set!"); + goto done; + } + + if (!vrf_is_set && !bd_index_is_set) + { + error = + clib_error_return (0, "vrf or bridge domain index must be set!"); + goto done; + } + + if (bd_index_is_set) + { + if (is_add) + { + if (~0 == lisp_gpe_tenant_l2_iface_add_or_lock (vni, bd_id)) + { + error = clib_error_return (0, "L2 interface not created"); + goto done; + } + } + else + lisp_gpe_tenant_l2_iface_unlock (vni); + } + else + { + if (is_add) + { + if (~0 == lisp_gpe_tenant_l3_iface_add_or_lock (vni, table_id, 1 + /* with_default_route */ + )) + { + error = clib_error_return (0, "L3 interface not created"); + goto done; + } + } + else + lisp_gpe_tenant_l3_iface_unlock (vni); + } + +done: + unformat_free (line_input); + + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (add_del_lisp_gpe_iface_command, static) = { + .path = "gpe iface", + .short_help = "gpe iface add/del vni vrf ", + .function = lisp_gpe_add_del_iface_command_fn, +}; +/* *INDENT-ON* */ + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/lisp/lisp-gpe/lisp_gpe.api b/src/plugins/lisp/lisp-gpe/lisp_gpe.api new file mode 100644 index 00000000000..2e1846261ab --- /dev/null +++ b/src/plugins/lisp/lisp-gpe/lisp_gpe.api @@ -0,0 +1,237 @@ +/* + * Copyright (c) 2015-2016 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +option version = "2.0.0"; + +import "vnet/interface_types.api"; +import "plugins/lisp/lisp-cp/lisp_types.api"; + +/** \brief GPE locator structure + @param is_ip4 - whether addr is IPv4 or v6 + @param weight - locator weight + @param addr - IPv4/6 address +*/ +typedef gpe_locator +{ + u8 weight; + vl_api_address_t addr; +}; + +/** \brief add or delete GPE tunnel + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param is_add - add address if non-zero, else delete + @param rmt_eid - remote eid + @param lcl_eid - local eid + @param vni - virtual network identifier + @param dp_table - vrf/bridge domain id + @param action - negative action when 0 locators configured + @param loc_num - number of locators + @param locs - array of remote locators +*/ +define gpe_add_del_fwd_entry +{ + u32 client_index; + u32 context; + bool is_add [default=true]; + vl_api_eid_t rmt_eid; + vl_api_eid_t lcl_eid; + u32 vni; + u32 dp_table; + u8 action; + u32 loc_num; + vl_api_gpe_locator_t locs[loc_num]; +}; + +define gpe_add_del_fwd_entry_reply +{ + u32 context; + i32 retval; + u32 fwd_entry_index; +}; + +/** \brief enable or disable gpe protocol + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param is_enable [default=true] - enable protocol if non-zero, else disable +*/ +autoreply define gpe_enable_disable +{ + u32 client_index; + u32 context; + bool is_enable [default=true]; +}; + +/** \brief add or delete gpe_iface + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param is_add - add address if non-zero, else delete +*/ +autoreply define gpe_add_del_iface +{ + u32 client_index; + u32 context; + bool is_add [default=true]; + bool is_l2; + u32 dp_table; + u32 vni; +}; + +define gpe_fwd_entry_vnis_get +{ + u32 client_index; + u32 context; +}; + +define gpe_fwd_entry_vnis_get_reply +{ + u32 context; + i32 retval; + u32 count; + u32 vnis[count]; +}; + +define gpe_fwd_entries_get +{ + u32 client_index; + u32 context; + u32 vni; +}; + +typedef gpe_fwd_entry +{ + u32 fwd_entry_index; + u32 dp_table; + vl_api_eid_t leid; + vl_api_eid_t reid; + u32 vni; + u8 action; +}; + +define gpe_fwd_entries_get_reply +{ + u32 context; + i32 retval; + u32 count; + vl_api_gpe_fwd_entry_t entries[count]; +}; + +define gpe_fwd_entry_path_dump +{ + u32 client_index; + u32 context; + u32 fwd_entry_index; +}; + +define gpe_fwd_entry_path_details +{ + u32 context; + vl_api_gpe_locator_t lcl_loc; + vl_api_gpe_locator_t rmt_loc; +}; + +/** \brief Set GPE encapsulation mode + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param mode - LISP (value 0) or VXLAN (value 1) +*/ +autoreply define gpe_set_encap_mode +{ + u32 client_index; + u32 context; + bool is_vxlan; +}; + +/** \brief get GPE encapsulation mode + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param mode - LISP (value 0) or VXLAN (value 1) +*/ +define gpe_get_encap_mode +{ + u32 client_index; + u32 context; +}; + +/** \brief Reply for set_encap_mode + @param context - returned sender context, to match reply w/ request + @param retval - return code + @param encap_mode - GPE encapsulation mode +*/ +define gpe_get_encap_mode_reply +{ + u32 context; + i32 retval; + /* FIXME: gpe encap enum */ + u8 encap_mode; +}; + +/** \brief Add native fwd rpath + @param context - returned sender context, to match reply w/ request + @param retval - return code + @param is_add - flag to indicate add or del + @param table_id - table id for route path + @param nh_sw_if_index - next-hop sw_if_index (~0 if not set) + @param is_ip4 - flag to indicate if nh is ip4 + @param nh_addr - next hop ip address +*/ +autoreply define gpe_add_del_native_fwd_rpath +{ + u32 client_index; + u32 context; + bool is_add [default=true]; + u32 table_id; + vl_api_interface_index_t nh_sw_if_index; + vl_api_address_t nh_addr; +}; + +/** \brief get GPE native fwd rpath + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request +*/ +define gpe_native_fwd_rpaths_get +{ + u32 client_index; + u32 context; + bool is_ip4; +}; + +/** \brief Reply for get native fwd rpath + @param context - returned sender context, to match reply w/ request + @param retval - return code + @param table_id - table id for route path + @param nh_sw_if_index - next-hop sw_if_index (~0 if not set) + @param nh_addr - next hop address +*/ +typedef gpe_native_fwd_rpath +{ + u32 fib_index; + vl_api_interface_index_t nh_sw_if_index; + vl_api_address_t nh_addr; +}; + +define gpe_native_fwd_rpaths_get_reply +{ + u32 context; + i32 retval; + u32 count; + vl_api_gpe_native_fwd_rpath_t entries[count]; +}; + +/* + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/lisp/lisp-gpe/lisp_gpe.c b/src/plugins/lisp/lisp-gpe/lisp_gpe.c new file mode 100644 index 00000000000..1f087fd0625 --- /dev/null +++ b/src/plugins/lisp/lisp-gpe/lisp_gpe.c @@ -0,0 +1,728 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file + * @brief Common utility functions for IPv4, IPv6 and L2 LISP-GPE tunnels. + * + */ + +#include +#include +#include +#include +#include +#include +#include + +/** LISP-GPE global state */ +lisp_gpe_main_t lisp_gpe_main; + + +/** CLI command to add/del forwarding entry. */ +static clib_error_t * +lisp_gpe_add_del_fwd_entry_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + unformat_input_t _line_input, *line_input = &_line_input; + u8 is_add = 1; + ip_address_t lloc, rloc; + clib_error_t *error = 0; + gid_address_t _reid, *reid = &_reid, _leid, *leid = &_leid; + u8 reid_set = 0, leid_set = 0, is_negative = 0, dp_table_set = 0, + vni_set = 0; + u32 vni = 0, dp_table = 0, action = ~0, w; + locator_pair_t pair, *pairs = 0; + int rv; + + clib_memset (leid, 0, sizeof (*leid)); + clib_memset (reid, 0, sizeof (*reid)); + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "del")) + is_add = 0; + else if (unformat (line_input, "add")) + is_add = 1; + else if (unformat (line_input, "leid %U", unformat_gid_address, leid)) + { + leid_set = 1; + } + else if (unformat (line_input, "reid %U", unformat_gid_address, reid)) + { + reid_set = 1; + } + else if (unformat (line_input, "vni %u", &vni)) + { + gid_address_vni (leid) = vni; + gid_address_vni (reid) = vni; + vni_set = 1; + } + else if (unformat (line_input, "vrf %u", &dp_table)) + { + dp_table_set = 1; + } + else if (unformat (line_input, "bd %u", &dp_table)) + { + dp_table_set = 1; + } + else if (unformat (line_input, "negative action %U", + unformat_negative_mapping_action, &action)) + { + is_negative = 1; + } + else if (unformat (line_input, "loc-pair %U %U w %d", + unformat_ip_address, &lloc, + unformat_ip_address, &rloc, &w)) + { + ip_address_copy (&pair.lcl_loc, &lloc); + ip_address_copy (&pair.rmt_loc, &rloc); + pair.weight = w; + pair.priority = 0; + vec_add1 (pairs, pair); + } + else + { + error = unformat_parse_error (line_input); + vlib_cli_output (vm, "parse error: '%U'", + format_unformat_error, line_input); + goto done; + } + } + + if (!reid_set) + { + vlib_cli_output (vm, "remote eid must be set!"); + goto done; + } + + if (gid_address_type (reid) != GID_ADDR_NSH && (!vni_set || !dp_table_set)) + { + vlib_cli_output (vm, "vni and vrf/bd must be set!"); + goto done; + } + + if (is_negative) + { + if (~0 == action) + { + vlib_cli_output (vm, "no action set for negative tunnel!"); + goto done; + } + } + else + { + if (vec_len (pairs) == 0) + { + vlib_cli_output (vm, "expected ip4/ip6 locators"); + goto done; + } + } + + if (!leid_set) + { + /* if leid not set, make sure it's the same AFI like reid */ + gid_address_type (leid) = gid_address_type (reid); + if (GID_ADDR_IP_PREFIX == gid_address_type (reid)) + gid_address_ip_version (leid) = gid_address_ip_version (reid); + } + + /* add fwd entry */ + vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a; + clib_memset (a, 0, sizeof (a[0])); + + a->is_add = is_add; + a->is_negative = is_negative; + a->vni = vni; + a->table_id = dp_table; + gid_address_copy (&a->lcl_eid, leid); + gid_address_copy (&a->rmt_eid, reid); + a->locator_pairs = pairs; + a->action = action; + + rv = vnet_lisp_gpe_add_del_fwd_entry (a, 0); + if (0 != rv) + { + vlib_cli_output (vm, "failed to %s gpe tunnel!", + is_add ? "add" : "delete"); + } + +done: + unformat_free (line_input); + vec_free (pairs); + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (lisp_gpe_add_del_fwd_entry_command, static) = { + .path = "gpe entry", + .short_help = "gpe entry add/del vni vrf/bd [leid ]" + "reid [loc-pair w ] " + "[negative action ]", + .function = lisp_gpe_add_del_fwd_entry_command_fn, +}; +/* *INDENT-ON* */ + +/** Check if LISP-GPE is enabled. */ +u8 +vnet_lisp_gpe_enable_disable_status (void) +{ + lisp_gpe_main_t *lgm = &lisp_gpe_main; + + return lgm->is_en; +} + +/** Enable/disable LISP-GPE. */ +clib_error_t * +vnet_lisp_gpe_enable_disable (vnet_lisp_gpe_enable_disable_args_t * a) +{ + lisp_gpe_main_t *lgm = &lisp_gpe_main; + vlib_main_t *vm = vlib_get_main (); + + if (a->is_en) + { + lgm->is_en = 1; + udp_register_dst_port (vm, UDP_DST_PORT_lisp_gpe, + lisp_gpe_ip4_input_node.index, 1 /* is_ip4 */ ); + udp_register_dst_port (vm, UDP_DST_PORT_lisp_gpe6, + lisp_gpe_ip6_input_node.index, 0 /* is_ip4 */ ); + } + else + { + /* remove all entries */ + vnet_lisp_gpe_fwd_entry_flush (); + + /* disable all l3 ifaces */ + lisp_gpe_tenant_flush (); + + udp_unregister_dst_port (vm, UDP_DST_PORT_lisp_gpe, 0 /* is_ip4 */ ); + udp_unregister_dst_port (vm, UDP_DST_PORT_lisp_gpe6, 1 /* is_ip4 */ ); + lgm->is_en = 0; + } + + return 0; +} + +/** Set GPE encapsulation mode. */ +int +vnet_gpe_set_encap_mode (gpe_encap_mode_t mode) +{ + lisp_gpe_main_t *lgm = &lisp_gpe_main; + + if (mode >= GPE_ENCAP_COUNT) + return VNET_API_ERROR_INVALID_GPE_MODE; + + if (pool_elts (lgm->lisp_fwd_entry_pool) != 0) + return VNET_API_ERROR_LISP_GPE_ENTRIES_PRESENT; + + lgm->encap_mode = mode; + return 0; +} + +/** CLI command to set GPE encap */ +static clib_error_t * +gpe_set_encap_mode_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + unformat_input_t _line_input, *line_input = &_line_input; + gpe_encap_mode_t mode = GPE_ENCAP_COUNT; + vnet_api_error_t rv; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "lisp")) + mode = GPE_ENCAP_LISP; + else if (unformat (line_input, "vxlan")) + mode = GPE_ENCAP_VXLAN; + else + { + return clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + } + } + rv = vnet_gpe_set_encap_mode (mode); + if (rv) + { + return clib_error_return (0, + "Error: invalid mode or GPE entries are present!"); + } + + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (gpe_set_encap_mode_command, static) = { + .path = "gpe encap", + .short_help = "gpe encap [lisp|vxlan]", + .function = gpe_set_encap_mode_command_fn, +}; +/* *INDENT-ON* */ + +/** Format GPE encap mode. */ +u8 * +format_vnet_gpe_encap_mode (u8 * s, va_list * args) +{ + lisp_gpe_main_t *lgm = &lisp_gpe_main; + + switch (lgm->encap_mode) + { + case GPE_ENCAP_LISP: + return format (s, "lisp"); + case GPE_ENCAP_VXLAN: + return format (s, "vxlan"); + default: + return 0; + } + return 0; +} + +/** CLI command to show GPE encap */ +static clib_error_t * +gpe_show_encap_mode_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + vlib_cli_output (vm, "encap mode: %U", format_vnet_gpe_encap_mode); + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (gpe_show_encap_mode_command, static) = { + .path = "show gpe encap", + .short_help = "show GPE encapulation mode", + .function = gpe_show_encap_mode_command_fn, +}; +/* *INDENT-ON* */ + +/** CLI command to enable/disable LISP-GPE. */ +static clib_error_t * +lisp_gpe_enable_disable_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + unformat_input_t _line_input, *line_input = &_line_input; + u8 is_en = 1; + vnet_lisp_gpe_enable_disable_args_t _a, *a = &_a; + clib_error_t *error = NULL; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return clib_error_return (0, "expected enable | disable"); + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "enable")) + is_en = 1; + else if (unformat (line_input, "disable")) + is_en = 0; + else + { + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + goto done; + } + } + a->is_en = is_en; + error = vnet_lisp_gpe_enable_disable (a); + +done: + unformat_free (line_input); + + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (enable_disable_lisp_gpe_command, static) = { + .path = "gpe", + .short_help = "gpe [enable|disable]", + .function = lisp_gpe_enable_disable_command_fn, +}; +/* *INDENT-ON* */ + +/** CLI command to show LISP-GPE interfaces. */ +static clib_error_t * +lisp_show_iface_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + lisp_gpe_main_t *lgm = &lisp_gpe_main; + hash_pair_t *p; + + vlib_cli_output (vm, "%=10s%=12s", "vrf", "hw_if_index"); + + /* *INDENT-OFF* */ + hash_foreach_pair (p, lgm->l3_ifaces.hw_if_index_by_dp_table, ({ + vlib_cli_output (vm, "%=10d%=10d", p->key, p->value[0]); + })); + /* *INDENT-ON* */ + + if (0 != lgm->l2_ifaces.hw_if_index_by_dp_table) + { + vlib_cli_output (vm, "%=10s%=12s", "bd_id", "hw_if_index"); + /* *INDENT-OFF* */ + hash_foreach_pair (p, lgm->l2_ifaces.hw_if_index_by_dp_table, ({ + vlib_cli_output (vm, "%=10d%=10d", p->key, p->value[0]); + })); + /* *INDENT-ON* */ + } + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (lisp_show_iface_command) = { + .path = "show gpe interface", + .short_help = "show gpe interface", + .function = lisp_show_iface_command_fn, +}; +/* *INDENT-ON* */ + +/** CLI command to show GPE fwd native route path. */ +static clib_error_t * +gpe_show_native_fwd_rpath_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + lisp_gpe_main_t *lgm = &lisp_gpe_main; + fib_route_path_t *rpath; + + if (vec_len (lgm->native_fwd_rpath[AF_IP4])) + { + vec_foreach (rpath, lgm->native_fwd_rpath[AF_IP4]) + { + vlib_cli_output (vm, "nh: %U fib_index %u sw_if_index %u", + format_ip46_address, &rpath->frp_addr, + IP46_TYPE_IP4, rpath->frp_fib_index, + rpath->frp_sw_if_index); + } + } + if (vec_len (lgm->native_fwd_rpath[AF_IP6])) + { + vec_foreach (rpath, lgm->native_fwd_rpath[AF_IP6]) + { + vlib_cli_output (vm, "nh: %U fib_index %u sw_if_index %u", + format_ip46_address, &rpath->frp_addr, IP46_TYPE_IP6, + rpath->frp_fib_index, rpath->frp_sw_if_index); + } + } + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (gpe_show_native_fwd_rpath_command) = { + .path = "show gpe native-forward", + .short_help = "show gpe native-forward", + .function = gpe_show_native_fwd_rpath_command_fn, +}; +/* *INDENT-ON* */ + +void +gpe_update_native_fwd_path (u8 ip_version) +{ + lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main (); + lisp_gpe_fwd_entry_t *lfe; + fib_prefix_t fib_prefix; + u32 *lfei; + + vec_foreach (lfei, lgm->native_fwd_lfes[ip_version]) + { + lfe = pool_elt_at_index (lgm->lisp_fwd_entry_pool, lfei[0]); + ip_prefix_to_fib_prefix (&lfe->key->rmt.ippref, &fib_prefix); + fib_table_entry_update (lfe->eid_fib_index, &fib_prefix, FIB_SOURCE_LISP, + FIB_ENTRY_FLAG_NONE, + lgm->native_fwd_rpath[ip_version]); + } +} + +int +vnet_gpe_add_del_native_fwd_rpath (vnet_gpe_native_fwd_rpath_args_t * a) +{ + lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main (); + fib_route_path_t *rpath; + u8 ip_version; + + ip_version = a->rpath.frp_proto == DPO_PROTO_IP4 ? AF_IP4 : AF_IP6; + + if (a->is_add) + { + vec_add1 (lgm->native_fwd_rpath[ip_version], a->rpath); + } + else + { + vec_foreach (rpath, lgm->native_fwd_rpath[ip_version]) + { + if (!fib_route_path_cmp (rpath, &a->rpath)) + { + vec_del1 (lgm->native_fwd_rpath[ip_version], + rpath - lgm->native_fwd_rpath[ip_version]); + break; + } + } + } + gpe_update_native_fwd_path (ip_version); + return 0; +} + +/** + * CLI command to add action for native forward. + */ +static clib_error_t * +gpe_native_forward_command_fn (vlib_main_t * vm, unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + vnet_main_t *vnm = vnet_get_main (); + unformat_input_t _line_input, *line_input = &_line_input; + vnet_api_error_t rv; + fib_route_path_t rpath; + u32 table_id = ~0; + vnet_gpe_native_fwd_rpath_args_t _a, *a = &_a; + u8 is_add = 1; + clib_error_t *error = 0; + + /* Get a line of input. */ + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + clib_memset (&rpath, 0, sizeof (rpath)); + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "table %d", &table_id)) + ; + else if (unformat (line_input, "del")) + is_add = 0; + else if (unformat (line_input, "via %U %U", + unformat_ip4_address, + &rpath.frp_addr.ip4, + unformat_vnet_sw_interface, vnm, + &rpath.frp_sw_if_index)) + { + rpath.frp_weight = 1; + rpath.frp_proto = DPO_PROTO_IP4; + } + else if (unformat (line_input, "via %U %U", + unformat_ip6_address, + &rpath.frp_addr.ip6, + unformat_vnet_sw_interface, vnm, + &rpath.frp_sw_if_index)) + { + rpath.frp_weight = 1; + rpath.frp_proto = DPO_PROTO_IP6; + } + else if (unformat (line_input, "via %U", + unformat_ip4_address, &rpath.frp_addr.ip4)) + { + rpath.frp_weight = 1; + rpath.frp_sw_if_index = ~0; + rpath.frp_proto = DPO_PROTO_IP4; + } + else if (unformat (line_input, "via %U", + unformat_ip6_address, &rpath.frp_addr.ip6)) + { + rpath.frp_weight = 1; + rpath.frp_sw_if_index = ~0; + rpath.frp_proto = DPO_PROTO_IP6; + } + else + { + return clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + } + } + + if ((u32) ~ 0 == table_id) + { + rpath.frp_fib_index = 0; + } + else + { + rpath.frp_fib_index = + fib_table_find (dpo_proto_to_fib (rpath.frp_proto), table_id); + if ((u32) ~ 0 == rpath.frp_fib_index) + { + error = clib_error_return (0, "Nonexistent table id %d", table_id); + goto done; + } + } + + a->rpath = rpath; + a->is_add = is_add; + + rv = vnet_gpe_add_del_native_fwd_rpath (a); + if (rv) + { + return clib_error_return (0, "Error: couldn't add path!"); + } + +done: + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (gpe_native_forward_command) = { + .path = "gpe native-forward", + .short_help = "gpe native-forward [del] via [iface] " + "[table ]", + .function = gpe_native_forward_command_fn, +}; +/* *INDENT-ON* */ + +/** Format LISP-GPE status. */ +u8 * +format_vnet_lisp_gpe_status (u8 * s, va_list * args) +{ + lisp_gpe_main_t *lgm = &lisp_gpe_main; + return format (s, "%s", lgm->is_en ? "enabled" : "disabled"); +} + +/** LISP-GPE init function. */ +clib_error_t * +lisp_gpe_init (vlib_main_t * vm) +{ + lisp_gpe_main_t *lgm = &lisp_gpe_main; + clib_error_t *error = 0; + + if ((error = vlib_call_init_function (vm, ip_main_init))) + return error; + + if ((error = vlib_call_init_function (vm, ip4_lookup_init))) + return error; + + lgm->vnet_main = vnet_get_main (); + lgm->vlib_main = vm; + lgm->im4 = &ip4_main; + lgm->im6 = &ip6_main; + lgm->lm4 = &ip4_main.lookup_main; + lgm->lm6 = &ip6_main.lookup_main; + lgm->encap_mode = GPE_ENCAP_LISP; + + lgm->lisp_gpe_fwd_entries = + hash_create_mem (0, sizeof (lisp_gpe_fwd_entry_key_t), sizeof (uword)); + + lgm->lisp_stats_index_by_key = + hash_create_mem (0, sizeof (lisp_stats_key_t), sizeof (uword)); + clib_memset (&lgm->counters, 0, sizeof (lgm->counters)); + lgm->counters.name = "LISP counters"; + + return 0; +} + +gpe_encap_mode_t +vnet_gpe_get_encap_mode (void) +{ + lisp_gpe_main_t *lgm = &lisp_gpe_main; + return lgm->encap_mode; +} + +static clib_error_t * +lisp_gpe_test_send_nsh_packet (u8 * file_name) +{ + vlib_frame_t *f; + vlib_buffer_t *b; + lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main (); + pcap_main_t pm; + clib_error_t *error = 0; + + if (!file_name) + return clib_error_create ("no pcap file specified!"); + + clib_memset (&pm, 0, sizeof (pm)); + pm.file_name = (char *) file_name; + error = pcap_read (&pm); + if (error) + return error; + + u32 bi; + if (vlib_buffer_alloc (lgm->vlib_main, &bi, 1) != 1) + return clib_error_create ("cannot allocate memory!"); + + b = vlib_get_buffer (lgm->vlib_main, bi); + tunnel_lookup_t *nsh_ifaces = &lgm->nsh_ifaces; + uword *hip; + vnet_hw_interface_t *hi; + + hip = hash_get (nsh_ifaces->hw_if_index_by_dp_table, 0); + if (hip == 0) + return clib_error_create ("The NSH 0 interface doesn't exist"); + + hi = vnet_get_hw_interface (lgm->vnet_main, hip[0]); + + vnet_buffer (b)->sw_if_index[VLIB_TX] = hi->sw_if_index; + u8 *p = vlib_buffer_put_uninit (b, vec_len (pm.packets_read[0])); + clib_memcpy_fast (p, pm.packets_read[0], vec_len (pm.packets_read[0])); + vlib_buffer_pull (b, sizeof (ethernet_header_t)); + + vlib_node_t *n = vlib_get_node_by_name (lgm->vlib_main, + (u8 *) "interface-tx"); + f = vlib_get_frame_to_node (lgm->vlib_main, n->index); + u32 *to_next = vlib_frame_vector_args (f); + to_next[0] = bi; + f->n_vectors = 1; + vlib_put_frame_to_node (lgm->vlib_main, n->index, f); + + return error; +} + +static clib_error_t * +lisp_test_nsh_command_fn (vlib_main_t * vm, unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + clib_error_t *error = 0; + u8 *file_name = 0; + + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "pcap %v", &file_name)) + { + error = lisp_gpe_test_send_nsh_packet (file_name); + goto done; + } + else + { + error = clib_error_create ("unknown input `%U'", + format_unformat_error, input); + goto done; + } + } + +done: + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (lisp_test_nsh_command, static) = { + .path = "test one nsh", + .short_help = "test gpe nsh pcap ", + .function = lisp_test_nsh_command_fn, +}; +/* *INDENT-ON* */ + +VLIB_INIT_FUNCTION (lisp_gpe_init); + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/lisp/lisp-gpe/lisp_gpe.h b/src/plugins/lisp/lisp-gpe/lisp_gpe.h new file mode 100644 index 00000000000..aa2e7d1bfbf --- /dev/null +++ b/src/plugins/lisp/lisp-gpe/lisp_gpe.h @@ -0,0 +1,339 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file + * @brief LISP-GPE definitions. + */ + +#ifndef included_vnet_lisp_gpe_h +#define included_vnet_lisp_gpe_h + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/** IP4-UDP-LISP encap header */ +/* *INDENT-OFF* */ +typedef CLIB_PACKED (struct { + ip4_header_t ip4; /* 20 bytes */ + udp_header_t udp; /* 8 bytes */ + lisp_gpe_header_t lisp; /* 8 bytes */ +}) ip4_udp_lisp_gpe_header_t; +/* *INDENT-ON* */ + +/** IP6-UDP-LISP encap header */ +/* *INDENT-OFF* */ +typedef CLIB_PACKED (struct { + ip6_header_t ip6; /* 40 bytes */ + udp_header_t udp; /* 8 bytes */ + lisp_gpe_header_t lisp; /* 8 bytes */ +}) ip6_udp_lisp_gpe_header_t; +/* *INDENT-ON* */ + +#define foreach_lisp_gpe_ip_input_next \ +_(DROP, "error-drop") \ +_(IP4_INPUT, "ip4-input") \ +_(IP6_INPUT, "ip6-input") \ +_(L2_INPUT, "l2-input") + +/** Enum of possible next nodes post LISP-GPE decap */ +typedef enum +{ +#define _(s,n) LISP_GPE_INPUT_NEXT_##s, + foreach_lisp_gpe_ip_input_next +#undef _ + LISP_GPE_INPUT_N_NEXT, +} lisp_gpe_input_next_t; + +/* Arc to nsh-input added only if nsh-input exists */ +#define LISP_GPE_INPUT_NEXT_NSH_INPUT 4 + +typedef enum +{ +#define lisp_gpe_error(n,s) LISP_GPE_ERROR_##n, +#include +#undef lisp_gpe_error + LISP_GPE_N_ERROR, +} lisp_gpe_error_t; + +typedef struct tunnel_lookup +{ + /** Lookup lisp-gpe interfaces by dp table (eg. vrf/bridge index) */ + uword *hw_if_index_by_dp_table; + + /** lookup decap tunnel termination sw_if_index by vni and vice versa */ + uword *sw_if_index_by_vni; + + // FIXME - Need this? + uword *vni_by_sw_if_index; +} tunnel_lookup_t; + +typedef struct +{ + u32 fwd_entry_index; + u32 tunnel_index; +} lisp_stats_key_t; + +typedef struct +{ + u32 vni; + dp_address_t deid; + dp_address_t seid; + ip_address_t loc_rloc; + ip_address_t rmt_rloc; + + vlib_counter_t counters; +} lisp_api_stats_t; + +typedef enum gpe_encap_mode_e +{ + GPE_ENCAP_LISP, + GPE_ENCAP_VXLAN, + GPE_ENCAP_COUNT +} gpe_encap_mode_t; + +/** LISP-GPE global state*/ +typedef struct lisp_gpe_main +{ + /** + * @brief DB of all forwarding entries. The Key is:{l-EID,r-EID,vni} + * where the EID encodes L2 or L3 + */ + uword *lisp_gpe_fwd_entries; + + /** + * @brief A Pool of all LISP forwarding entries + */ + struct lisp_gpe_fwd_entry_t_ *lisp_fwd_entry_pool; + + /** Free vlib hw_if_indices */ + u32 *free_tunnel_hw_if_indices; + + u8 is_en; + + /* L3 data structures + * ================== */ + tunnel_lookup_t l3_ifaces; + + /* L2 data structures + * ================== */ + + /** L2 LISP FIB */ + BVT (clib_bihash) l2_fib; + + tunnel_lookup_t l2_ifaces; + + /** Load-balance for a miss in the table */ + dpo_id_t l2_lb_cp_lkup; + + /* NSH data structures + * ================== */ + + BVT (clib_bihash) nsh_fib; + + tunnel_lookup_t nsh_ifaces; + + const dpo_id_t *nsh_cp_lkup; + + gpe_encap_mode_t encap_mode; + + u8 *placeholder_stats_pool; + uword *lisp_stats_index_by_key; + vlib_combined_counter_main_t counters; + + /** Native fwd data structures */ + fib_route_path_t *native_fwd_rpath[2]; + u32 *native_fwd_lfes[2]; + + /** convenience */ + vlib_main_t *vlib_main; + vnet_main_t *vnet_main; + ip4_main_t *im4; + ip6_main_t *im6; + ip_lookup_main_t *lm4; + ip_lookup_main_t *lm6; +} lisp_gpe_main_t; + +/** LISP-GPE global state*/ +extern lisp_gpe_main_t lisp_gpe_main; + +always_inline lisp_gpe_main_t * +vnet_lisp_gpe_get_main () +{ + return &lisp_gpe_main; +} + + +extern vlib_node_registration_t lisp_gpe_ip4_input_node; +extern vlib_node_registration_t lisp_gpe_ip6_input_node; +extern vnet_hw_interface_class_t lisp_gpe_hw_class; + +u8 *format_lisp_gpe_header_with_length (u8 * s, va_list * args); + +/** Read LISP-GPE status */ +u8 vnet_lisp_gpe_enable_disable_status (void); + +u32 +lisp_gpe_l3_iface_find_or_create (lisp_gpe_main_t * lgm, + u32 overlay_table_id, u32 vni); + +/** Add/del LISP-GPE interface. */ +extern void lisp_gpe_del_l2_iface (lisp_gpe_main_t * lgm, u32 vni, u32 bd_id); +extern u32 lisp_gpe_add_l2_iface (lisp_gpe_main_t * lgm, u32 vni, u32 bd_id); +extern void lisp_gpe_del_l3_iface (lisp_gpe_main_t * lgm, u32 vni, u32 bd_id); +extern u32 lisp_gpe_add_l3_iface (lisp_gpe_main_t * lgm, u32 vni, u32 bd_id, + u8 with_default_route); + + +typedef struct +{ + u8 is_en; +} vnet_lisp_gpe_enable_disable_args_t; + +clib_error_t + * vnet_lisp_gpe_enable_disable (vnet_lisp_gpe_enable_disable_args_t * a); + +typedef enum +{ + NO_ACTION, + FORWARD_NATIVE, + SEND_MAP_REQUEST, + DROP +} negative_fwd_actions_e; + +/** */ +typedef struct +{ + /** forwarding entry index of */ + u32 fwd_entry_index; + + u8 is_src_dst; + + u8 is_add; + + /** type of mapping */ + u8 is_negative; + + /** action for negative mappings */ + negative_fwd_actions_e action; + + /** local eid */ + gid_address_t lcl_eid; + + /** remote eid */ + gid_address_t rmt_eid; + + /** vector of locator pairs */ + locator_pair_t *locator_pairs; + + /** FIB index to lookup remote locator at encap */ + u32 encap_fib_index; + + /** FIB index to lookup inner IP at decap */ + u32 decap_fib_index; + + /* TODO remove */ + u32 decap_next_index; + + /** VNI/tenant id in HOST byte order */ + u32 vni; + + /** vrf or bd where fwd entry should be inserted */ + union + { + /** table (vrf) id */ + u32 table_id; + + /** bridge domain id */ + u32 bd_id; + + /** generic access */ + u32 dp_table; + }; +} vnet_lisp_gpe_add_del_fwd_entry_args_t; + +typedef struct +{ + fib_route_path_t rpath; + u8 is_add; +} vnet_gpe_native_fwd_rpath_args_t; + +typedef struct +{ + u32 fwd_entry_index; + u32 dp_table; + u32 vni; + u8 action; + dp_address_t leid; + dp_address_t reid; +} lisp_api_gpe_fwd_entry_t; + +#define foreach_lgpe_ip4_lookup_next \ + _(DROP, "error-drop") \ + _(LISP_CP_LOOKUP, "lisp-cp-lookup") + +typedef enum lgpe_ip4_lookup_next +{ +#define _(sym,str) LGPE_IP4_LOOKUP_NEXT_##sym, + foreach_lgpe_ip4_lookup_next +#undef _ + LGPE_IP4_LOOKUP_N_NEXT, +} lgpe_ip4_lookup_next_t; + +#define foreach_lgpe_ip6_lookup_next \ + _(DROP, "error-drop") \ + _(LISP_CP_LOOKUP, "lisp-cp-lookup") + +typedef enum lgpe_ip6_lookup_next +{ +#define _(sym,str) LGPE_IP6_LOOKUP_NEXT_##sym, + foreach_lgpe_ip6_lookup_next +#undef _ + LGPE_IP6_LOOKUP_N_NEXT, +} lgpe_ip6_lookup_next_t; + +u8 *format_vnet_lisp_gpe_status (u8 * s, va_list * args); + +lisp_api_gpe_fwd_entry_t *vnet_lisp_gpe_fwd_entries_get_by_vni (u32 vni); +gpe_encap_mode_t vnet_gpe_get_encap_mode (void); +int vnet_gpe_set_encap_mode (gpe_encap_mode_t mode); + +u8 vnet_lisp_stats_enable_disable_state (void); +vnet_api_error_t vnet_lisp_stats_enable_disable (u8 enable); +lisp_api_stats_t *vnet_lisp_get_stats (void); +int vnet_lisp_flush_stats (void); +int vnet_gpe_add_del_native_fwd_rpath (vnet_gpe_native_fwd_rpath_args_t * a); +u32 vnet_lisp_gpe_add_nsh_iface (lisp_gpe_main_t * lgm); +void vnet_lisp_gpe_del_nsh_iface (lisp_gpe_main_t * lgm); + +#endif /* included_vnet_lisp_gpe_h */ + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/lisp/lisp-gpe/lisp_gpe_adjacency.c b/src/plugins/lisp/lisp-gpe/lisp_gpe_adjacency.c new file mode 100644 index 00000000000..eab10f4d2d5 --- /dev/null +++ b/src/plugins/lisp/lisp-gpe/lisp_gpe_adjacency.c @@ -0,0 +1,604 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file + * @brief Common utility functions for IPv4, IPv6 and L2 LISP-GPE adjacencys. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/** + * Memory pool of all adjacencies + */ +static lisp_gpe_adjacency_t *lisp_adj_pool; + +/** + * Hash table of all adjacencies. key:{nh, itf} + * We never have an all zeros address since the interfaces are multi-access, + * therefore there is no ambiguity between a v4 and v6 next-hop, so we don't + * need to add the protocol to the key. + */ +static +BVT (clib_bihash) + lisp_adj_db; + +#define LISP_ADJ_SET_KEY(_key, _itf, _nh) \ +{ \ + _key.key[0] = ip_addr_v6((_nh)).as_u64[0]; \ + _key.key[1] = ip_addr_v6((_nh)).as_u64[1]; \ + _key.key[2] = (_itf); \ +} + + static index_t lisp_adj_find (const ip_address_t * addr, u32 sw_if_index) +{ + BVT (clib_bihash_kv) kv; + + LISP_ADJ_SET_KEY (kv, sw_if_index, addr); + + if (BV (clib_bihash_search) (&lisp_adj_db, &kv, &kv) < 0) + { + return (INDEX_INVALID); + } + else + { + return (kv.value); + } +} + +static void +lisp_adj_insert (const ip_address_t * addr, u32 sw_if_index, index_t ai) +{ + BVT (clib_bihash_kv) kv; + + LISP_ADJ_SET_KEY (kv, sw_if_index, addr); + kv.value = ai; + + BV (clib_bihash_add_del) (&lisp_adj_db, &kv, 1); +} + +static void +lisp_adj_remove (const ip_address_t * addr, u32 sw_if_index) +{ + BVT (clib_bihash_kv) kv; + + LISP_ADJ_SET_KEY (kv, sw_if_index, addr); + + BV (clib_bihash_add_del) (&lisp_adj_db, &kv, 0); +} + +static lisp_gpe_adjacency_t * +lisp_gpe_adjacency_get_i (index_t lai) +{ + return (pool_elt_at_index (lisp_adj_pool, lai)); +} + +fib_forward_chain_type_t +lisp_gpe_adj_get_fib_chain_type (const lisp_gpe_adjacency_t * ladj) +{ + switch (ip_addr_version (&ladj->remote_rloc)) + { + case AF_IP4: + return (FIB_FORW_CHAIN_TYPE_UNICAST_IP4); + case AF_IP6: + return (FIB_FORW_CHAIN_TYPE_UNICAST_IP6); + default: + ASSERT (0); + break; + } + return (FIB_FORW_CHAIN_TYPE_UNICAST_IP4); +} + +static void +ip46_address_to_ip_address (const ip46_address_t * a, ip_address_t * b) +{ + if (ip46_address_is_ip4 (a)) + { + clib_memset (b, 0, sizeof (*b)); + ip_address_set (b, &a->ip4, AF_IP4); + } + else + { + ip_address_set (b, &a->ip6, AF_IP6); + } +} + +/** + * @brief Stack the tunnel's midchain on the IP forwarding chain of the via + */ +static void +lisp_gpe_adj_stack_one (lisp_gpe_adjacency_t * ladj, adj_index_t ai) +{ + const lisp_gpe_tunnel_t *lgt; + + lgt = lisp_gpe_tunnel_get (ladj->tunnel_index); + + adj_nbr_midchain_stack_on_fib_entry (ai, + lgt->fib_entry_index, + lisp_gpe_adj_get_fib_chain_type + (ladj)); +} + +/** + * @brief Call back when restacking all adjacencies on a GRE interface + */ +static adj_walk_rc_t +lisp_gpe_adj_walk_cb (adj_index_t ai, void *ctx) +{ + lisp_gpe_adjacency_t *ladj = ctx; + + lisp_gpe_adj_stack_one (ladj, ai); + + return (ADJ_WALK_RC_CONTINUE); +} + +static void +lisp_gpe_adj_stack (lisp_gpe_adjacency_t * ladj) +{ + fib_protocol_t nh_proto; + ip46_address_t nh; + + nh_proto = ip_address_to_46 (&ladj->remote_rloc, &nh); + + /* + * walk all the adjacencies on th lisp interface and restack them + */ + adj_nbr_walk_nh (ladj->sw_if_index, + nh_proto, &nh, lisp_gpe_adj_walk_cb, ladj); +} + +static lisp_gpe_next_protocol_e +lisp_gpe_adj_proto_from_vnet_link_type (vnet_link_t linkt) +{ + switch (linkt) + { + case VNET_LINK_IP4: + return (LISP_GPE_NEXT_PROTO_IP4); + case VNET_LINK_IP6: + return (LISP_GPE_NEXT_PROTO_IP6); + case VNET_LINK_ETHERNET: + return (LISP_GPE_NEXT_PROTO_ETHERNET); + case VNET_LINK_NSH: + return (LISP_GPE_NEXT_PROTO_NSH); + default: + ASSERT (0); + } + return (LISP_GPE_NEXT_PROTO_IP4); +} + +#define is_v4_packet(_h) ((*(u8*) _h) & 0xF0) == 0x40 + +static lisp_afi_e +lisp_afi_from_vnet_link_type (vnet_link_t link) +{ + switch (link) + { + case VNET_LINK_IP4: + return LISP_AFI_IP; + case VNET_LINK_IP6: + return LISP_AFI_IP6; + case VNET_LINK_ETHERNET: + return LISP_AFI_MAC; + default: + return LISP_AFI_NO_ADDR; + } +} + +static void +lisp_gpe_increment_stats_counters (lisp_cp_main_t * lcm, + const ip_adjacency_t * adj, + vlib_buffer_t * b) +{ + lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main (); + lisp_gpe_adjacency_t *ladj; + ip_address_t rloc; + index_t lai; + u32 si, di; + gid_address_t src, dst; + uword *feip; + + ip46_address_to_ip_address (&adj->sub_type.nbr.next_hop, &rloc); + si = vnet_buffer (b)->sw_if_index[VLIB_TX]; + lai = lisp_adj_find (&rloc, si); + ASSERT (INDEX_INVALID != lai); + + ladj = pool_elt_at_index (lisp_adj_pool, lai); + + u8 *lisp_data = (u8 *) vlib_buffer_get_current (b); + + /* skip IP header */ + if (is_v4_packet (lisp_data)) + lisp_data += sizeof (ip4_header_t); + else + lisp_data += sizeof (ip6_header_t); + + /* skip UDP header */ + lisp_data += sizeof (udp_header_t); + // TODO: skip TCP? + + /* skip LISP GPE header */ + lisp_data += sizeof (lisp_gpe_header_t); + + i16 saved_current_data = b->current_data; + b->current_data = lisp_data - b->data; + + lisp_afi_e afi = lisp_afi_from_vnet_link_type (adj->ia_link); + get_src_and_dst_eids_from_buffer (lcm, b, &src, &dst, afi); + b->current_data = saved_current_data; + di = gid_dictionary_sd_lookup (&lcm->mapping_index_by_gid, &dst, &src); + if (PREDICT_FALSE (~0 == di)) + { + clib_warning ("dst mapping not found (%U, %U)", format_gid_address, + &src, format_gid_address, &dst); + return; + } + + feip = hash_get (lcm->fwd_entry_by_mapping_index, di); + if (PREDICT_FALSE (!feip)) + return; + + lisp_stats_key_t key; + clib_memset (&key, 0, sizeof (key)); + key.fwd_entry_index = feip[0]; + key.tunnel_index = ladj->tunnel_index; + + uword *p = hash_get_mem (lgm->lisp_stats_index_by_key, &key); + ALWAYS_ASSERT (p); + + /* compute payload length starting after GPE */ + u32 bytes = b->current_length - (lisp_data - b->data - b->current_data); + vlib_increment_combined_counter (&lgm->counters, vlib_get_thread_index (), + p[0], 1, bytes); +} + +static void +lisp_gpe_fixup (vlib_main_t * vm, + const ip_adjacency_t * adj, + vlib_buffer_t * b, const void *data) +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + + if (lcm->flags & LISP_FLAG_STATS_ENABLED) + lisp_gpe_increment_stats_counters (lcm, adj, b); + + /* Fixup the checksum and len fields in the LISP tunnel encap + * that was applied at the midchain node */ + ip_udp_fixup_one (vm, b, is_v4_packet (vlib_buffer_get_current (b))); +} + +/** + * @brief The LISP-GPE interface registered function to update, i.e. + * provide an rewrite string for, an adjacency. + */ +void +lisp_gpe_update_adjacency (vnet_main_t * vnm, u32 sw_if_index, adj_index_t ai) +{ + const lisp_gpe_tunnel_t *lgt; + lisp_gpe_adjacency_t *ladj; + ip_adjacency_t *adj; + ip_address_t rloc; + vnet_link_t linkt; + adj_flags_t af; + index_t lai; + + adj = adj_get (ai); + ip46_address_to_ip_address (&adj->sub_type.nbr.next_hop, &rloc); + + /* + * find an existing or create a new adj + */ + lai = lisp_adj_find (&rloc, sw_if_index); + + ASSERT (INDEX_INVALID != lai); + + ladj = pool_elt_at_index (lisp_adj_pool, lai); + lgt = lisp_gpe_tunnel_get (ladj->tunnel_index); + linkt = adj_get_link_type (ai); + af = ADJ_FLAG_MIDCHAIN_IP_STACK; + if (VNET_LINK_ETHERNET == linkt) + af |= ADJ_FLAG_MIDCHAIN_NO_COUNT; + + adj_nbr_midchain_update_rewrite + (ai, lisp_gpe_fixup, NULL, af, + lisp_gpe_tunnel_build_rewrite (lgt, ladj, + lisp_gpe_adj_proto_from_vnet_link_type + (linkt))); + + lisp_gpe_adj_stack_one (ladj, ai); +} + +u8 * +lisp_gpe_build_rewrite (vnet_main_t * vnm, + u32 sw_if_index, + vnet_link_t link_type, const void *dst_address) +{ + ASSERT (0); + return (NULL); +} + +index_t +lisp_gpe_adjacency_find_or_create_and_lock (const locator_pair_t * pair, + u32 overlay_table_id, u32 vni) +{ + const lisp_gpe_sub_interface_t *l3s; + const lisp_gpe_tunnel_t *lgt; + lisp_gpe_adjacency_t *ladj; + index_t lai, l3si; + + /* + * first find the L3 sub-interface that corresponds to the loacl-rloc and vni + */ + l3si = lisp_gpe_sub_interface_find_or_create_and_lock (&pair->lcl_loc, + overlay_table_id, + vni); + l3s = lisp_gpe_sub_interface_get (l3si); + + /* + * find an existing or create a new adj + */ + lai = lisp_adj_find (&pair->rmt_loc, l3s->sw_if_index); + + if (INDEX_INVALID == lai) + { + + pool_get (lisp_adj_pool, ladj); + clib_memset (ladj, 0, sizeof (*ladj)); + lai = (ladj - lisp_adj_pool); + + ip_address_copy (&ladj->remote_rloc, &pair->rmt_loc); + ladj->vni = vni; + /* transfer the lock to the adj */ + ladj->lisp_l3_sub_index = l3si; + ladj->sw_if_index = l3s->sw_if_index; + + /* if vni is non-default */ + if (ladj->vni) + ladj->flags = LISP_GPE_FLAGS_I; + + /* work in lisp-gpe not legacy mode */ + ladj->flags |= LISP_GPE_FLAGS_P; + + /* + * find the tunnel that will provide the underlying transport + * and hence the rewrite. + * The RLOC FIB index is default table - always. + */ + ladj->tunnel_index = lisp_gpe_tunnel_find_or_create_and_lock (pair, 0); + + lgt = lisp_gpe_tunnel_get (ladj->tunnel_index); + + /* + * become of child of the RLOC FIB entry so we are updated when + * its reachability changes, allowing us to re-stack the midcahins + */ + ladj->fib_entry_child_index = fib_entry_child_add (lgt->fib_entry_index, + FIB_NODE_TYPE_LISP_ADJ, + lai); + + lisp_adj_insert (&ladj->remote_rloc, ladj->sw_if_index, lai); + } + else + { + /* unlock the interface from the find. */ + lisp_gpe_sub_interface_unlock (l3si); + ladj = lisp_gpe_adjacency_get_i (lai); + } + + ladj->locks++; + + return (lai); +} + +/** + * @brief Get a pointer to a tunnel from a pointer to a FIB node + */ +static lisp_gpe_adjacency_t * +lisp_gpe_adjacency_from_fib_node (const fib_node_t * node) +{ + return ((lisp_gpe_adjacency_t *) + ((char *) node - + STRUCT_OFFSET_OF (lisp_gpe_adjacency_t, fib_node))); +} + +static void +lisp_gpe_adjacency_last_lock_gone (lisp_gpe_adjacency_t * ladj) +{ + const lisp_gpe_tunnel_t *lgt; + + /* + * no children so we are not counting locks. no-op. + * at least not counting + */ + lisp_adj_remove (&ladj->remote_rloc, ladj->sw_if_index); + + /* + * unlock the resources this adj holds + */ + lgt = lisp_gpe_tunnel_get (ladj->tunnel_index); + + fib_entry_child_remove (lgt->fib_entry_index, ladj->fib_entry_child_index); + + lisp_gpe_tunnel_unlock (ladj->tunnel_index); + lisp_gpe_sub_interface_unlock (ladj->lisp_l3_sub_index); + + pool_put (lisp_adj_pool, ladj); +} + +void +lisp_gpe_adjacency_unlock (index_t lai) +{ + lisp_gpe_adjacency_t *ladj; + + ladj = lisp_gpe_adjacency_get_i (lai); + + ladj->locks--; + + if (0 == ladj->locks) + { + lisp_gpe_adjacency_last_lock_gone (ladj); + } +} + +const lisp_gpe_adjacency_t * +lisp_gpe_adjacency_get (index_t lai) +{ + return (lisp_gpe_adjacency_get_i (lai)); +} + + +/** + * @brief LISP GPE tunnel back walk + * + * The FIB entry through which this tunnel resolves has been updated. + * re-stack the midchain on the new forwarding. + */ +static fib_node_back_walk_rc_t +lisp_gpe_adjacency_back_walk (fib_node_t * node, + fib_node_back_walk_ctx_t * ctx) +{ + lisp_gpe_adj_stack (lisp_gpe_adjacency_from_fib_node (node)); + + return (FIB_NODE_BACK_WALK_CONTINUE); +} + +static fib_node_t * +lisp_gpe_adjacency_get_fib_node (fib_node_index_t index) +{ + lisp_gpe_adjacency_t *ladj; + + ladj = pool_elt_at_index (lisp_adj_pool, index); + return (&ladj->fib_node); +} + +static void +lisp_gpe_adjacency_last_fib_lock_gone (fib_node_t * node) +{ + lisp_gpe_adjacency_last_lock_gone (lisp_gpe_adjacency_from_fib_node (node)); +} + +const static fib_node_vft_t lisp_gpe_tuennel_vft = { + .fnv_get = lisp_gpe_adjacency_get_fib_node, + .fnv_back_walk = lisp_gpe_adjacency_back_walk, + .fnv_last_lock = lisp_gpe_adjacency_last_fib_lock_gone, +}; + +u8 * +format_lisp_gpe_adjacency (u8 * s, va_list * args) +{ + lisp_gpe_adjacency_t *ladj = va_arg (*args, lisp_gpe_adjacency_t *); + lisp_gpe_adjacency_format_flags_t flags = + va_arg (*args, lisp_gpe_adjacency_format_flags_t); + + if (flags & LISP_GPE_ADJ_FORMAT_FLAG_DETAIL) + { + s = + format (s, "index %d locks:%d\n", ladj - lisp_adj_pool, ladj->locks); + } + + s = format (s, " vni: %d,", ladj->vni); + s = format (s, " remote-RLOC: %U,", format_ip_address, &ladj->remote_rloc); + + if (flags & LISP_GPE_ADJ_FORMAT_FLAG_DETAIL) + { + s = format (s, " %U\n", + format_lisp_gpe_sub_interface, + lisp_gpe_sub_interface_get (ladj->lisp_l3_sub_index)); + s = format (s, " %U\n", + format_lisp_gpe_tunnel, + lisp_gpe_tunnel_get (ladj->tunnel_index)); + } + else + { + s = format (s, " LISP L3 sub-interface index: %d,", + ladj->lisp_l3_sub_index); + s = format (s, " LISP tunnel index: %d", ladj->tunnel_index); + } + + + return (s); +} + +static clib_error_t * +lisp_gpe_adjacency_show (vlib_main_t * vm, + unformat_input_t * input, vlib_cli_command_t * cmd) +{ + lisp_gpe_adjacency_t *ladj; + index_t index; + + if (pool_elts (lisp_adj_pool) == 0) + vlib_cli_output (vm, "No lisp-gpe Adjacencies"); + + if (unformat (input, "%d", &index)) + { + ladj = lisp_gpe_adjacency_get_i (index); + vlib_cli_output (vm, "%U", format_lisp_gpe_adjacency, ladj, + LISP_GPE_ADJ_FORMAT_FLAG_DETAIL); + } + else + { + /* *INDENT-OFF* */ + pool_foreach (ladj, lisp_adj_pool, + ({ + vlib_cli_output (vm, "[%d] %U\n", + ladj - lisp_adj_pool, + format_lisp_gpe_adjacency, ladj, + LISP_GPE_ADJ_FORMAT_FLAG_NONE); + })); + /* *INDENT-ON* */ + } + + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (show_lisp_gpe_tunnel_command, static) = +{ + .path = "show gpe adjacency", + .function = lisp_gpe_adjacency_show, +}; +/* *INDENT-ON* */ + +#define LISP_ADJ_NBR_DEFAULT_HASH_NUM_BUCKETS (256) +#define LISP_ADJ_NBR_DEFAULT_HASH_MEMORY_SIZE (1<<20) + +static clib_error_t * +lisp_gpe_adj_module_init (vlib_main_t * vm) +{ + BV (clib_bihash_init) (&lisp_adj_db, + "Adjacency Neighbour table", + LISP_ADJ_NBR_DEFAULT_HASH_NUM_BUCKETS, + LISP_ADJ_NBR_DEFAULT_HASH_MEMORY_SIZE); + + fib_node_register_type (FIB_NODE_TYPE_LISP_ADJ, &lisp_gpe_tuennel_vft); + return (NULL); +} + +VLIB_INIT_FUNCTION (lisp_gpe_adj_module_init); +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/lisp/lisp-gpe/lisp_gpe_adjacency.h b/src/plugins/lisp/lisp-gpe/lisp_gpe_adjacency.h new file mode 100644 index 00000000000..060c5d13ebc --- /dev/null +++ b/src/plugins/lisp/lisp-gpe/lisp_gpe_adjacency.h @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file + * @brief Common utility functions for IPv4, IPv6 and L2 LISP-GPE adjacencys. + * + */ + +#ifndef LISP_GPE_ADJACENCY_H__ +#define LISP_GPE_ADJACENCY_H__ + +#include +#include + +/** + * @brief A LISP GPE Adjacency. + * + * A adjacency represents peer on an L3 sub-interface to which to send traffic. + * adjacencies are thus present in the EID space. + * The peer is identified by the key:{remote-rloc, sub-interface}, which is + * equivalent to the usal adjacency key {next-hop, interface}. So curiously + * the rloc address from the underlay is used as a next hop address in the overlay + * This is OK because: + * 1 - the RLOC is unique in the underlay AND there is only one underlay VRF per + * overlay + * 2 - the RLOC may overlap with an address in the overlay, but we do not create + * an adj-fib (i.e. a route in the overlay FIB for the rloc) + * + * + */ +typedef struct lisp_gpe_adjacency_t_ +{ + /** + * The LISP adj is a part of the FIB control plane graph. + */ + fib_node_t fib_node; + + /** + * remote RLOC. The adjacency's next-hop + */ + ip_address_t remote_rloc; + + /** + * The VNI. Used in combination with the local-rloc to get the sub-interface + */ + u32 vni; + + /** + * The number of locks/reference counts on the adjacency. + */ + u32 locks; + + /** + * The index of the LISP L3 subinterface + */ + u32 lisp_l3_sub_index; + + /** + * The SW IF index of the sub-interface this adjacency uses. + * Cached for convenience from the LISP L3 sub-interface + */ + u32 sw_if_index; + + /** + * The index of the LISP GPE tunnel that provides the transport + * in the underlay. + */ + u32 tunnel_index; + + /** + * This adjacency is a child of the FIB entry to reach the RLOC. + * This is so when the reachability of that RLOC changes, we can restack + * the FIB adjacnecies. + */ + u32 fib_entry_child_index; + + /** + * LISP header fields in HOST byte order + */ + u8 flags; + u8 ver_res; + u8 res; + u8 next_protocol; + +} lisp_gpe_adjacency_t; + +extern index_t lisp_gpe_adjacency_find_or_create_and_lock (const + locator_pair_t * + pair, + u32 rloc_fib_index, + u32 vni); + +extern void lisp_gpe_adjacency_unlock (index_t l3si); + +extern const lisp_gpe_adjacency_t *lisp_gpe_adjacency_get (index_t l3si); + +extern void lisp_gpe_update_adjacency (vnet_main_t * vnm, + u32 sw_if_index, adj_index_t ai); +extern u8 *lisp_gpe_build_rewrite (vnet_main_t * vnm, + u32 sw_if_index, + vnet_link_t link_type, + const void *dst_address); + + +/** + * @brief Flags for displaying the adjacency + */ +typedef enum lisp_gpe_adjacency_format_flags_t_ +{ + LISP_GPE_ADJ_FORMAT_FLAG_NONE, + LISP_GPE_ADJ_FORMAT_FLAG_DETAIL, +} lisp_gpe_adjacency_format_flags_t; + +extern u8 *format_lisp_gpe_adjacency (u8 * s, va_list * args); + +#endif + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/lisp/lisp-gpe/lisp_gpe_api.c b/src/plugins/lisp/lisp-gpe/lisp_gpe_api.c new file mode 100644 index 00000000000..df90ef54403 --- /dev/null +++ b/src/plugins/lisp/lisp-gpe/lisp_gpe_api.c @@ -0,0 +1,506 @@ +/* + *------------------------------------------------------------------ + * lisp_gpe_api.c - lisp_gpe api + * + * Copyright (c) 2016 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------ + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* define message IDs */ +#include +#include +#include + +/** + * Base message ID fot the plugin + */ +static u32 gpe_base_msg_id; +#define REPLY_MSG_ID_BASE gpe_base_msg_id + +#include + +static locator_pair_t * +unformat_gpe_loc_pairs (void *locs, u32 rloc_num) +{ + u32 i; + locator_pair_t *pairs = 0, pair, *p; + vl_api_gpe_locator_t *r; + + for (i = 0; i < rloc_num; i++) + { + /* local locator */ + r = &((vl_api_gpe_locator_t *) locs)[i]; + clib_memset (&pair, 0, sizeof (pair)); + ip_address_decode2 (&r->addr, &pair.lcl_loc); + + pair.weight = r->weight; + vec_add1 (pairs, pair); + } + + for (i = rloc_num; i < rloc_num * 2; i++) + { + /* remote locators */ + r = &((vl_api_gpe_locator_t *) locs)[i]; + p = &pairs[i - rloc_num]; + ip_address_decode2 (&r->addr, &p->rmt_loc); + } + return pairs; +} + +static void + gpe_fwd_entry_path_dump_t_net_to_host + (vl_api_gpe_fwd_entry_path_dump_t * mp) +{ + mp->fwd_entry_index = clib_net_to_host_u32 (mp->fwd_entry_index); +} + +static void +lisp_api_set_locator (vl_api_gpe_locator_t * loc, + const ip_address_t * addr, u8 weight) +{ + loc->weight = weight; + ip_address_encode2 (addr, &loc->addr); +} + +static void + vl_api_gpe_fwd_entry_path_dump_t_handler + (vl_api_gpe_fwd_entry_path_dump_t * mp) +{ + lisp_fwd_path_t *path; + vl_api_gpe_fwd_entry_path_details_t *rmp = NULL; + lisp_gpe_main_t *lgm = &lisp_gpe_main; + vl_api_registration_t *reg; + lisp_gpe_fwd_entry_t *lfe; + + gpe_fwd_entry_path_dump_t_net_to_host (mp); + + reg = vl_api_client_index_to_registration (mp->client_index); + if (!reg) + return; + + if (pool_is_free_index (lgm->lisp_fwd_entry_pool, mp->fwd_entry_index)) + return; + + lfe = pool_elt_at_index (lgm->lisp_fwd_entry_pool, mp->fwd_entry_index); + + if (LISP_GPE_FWD_ENTRY_TYPE_NEGATIVE == lfe->type) + return; + + vec_foreach (path, lfe->paths) + { + rmp = vl_msg_api_alloc (sizeof (*rmp)); + clib_memset (rmp, 0, sizeof (*rmp)); + const lisp_gpe_tunnel_t *lgt; + + rmp->_vl_msg_id = + clib_host_to_net_u16 (VL_API_GPE_FWD_ENTRY_PATH_DETAILS); + + const lisp_gpe_adjacency_t *ladj = + lisp_gpe_adjacency_get (path->lisp_adj); + lisp_api_set_locator (&rmp->rmt_loc, &ladj->remote_rloc, path->weight); + lgt = lisp_gpe_tunnel_get (ladj->tunnel_index); + lisp_api_set_locator (&rmp->lcl_loc, &lgt->key->lcl, path->weight); + + rmp->context = mp->context; + vl_api_send_msg (reg, (u8 *) rmp); + } +} + +static void +gpe_fwd_entries_copy (vl_api_gpe_fwd_entry_t * dst, + lisp_api_gpe_fwd_entry_t * src) +{ + lisp_api_gpe_fwd_entry_t *e; + u32 i = 0; + + vec_foreach (e, src) + { + clib_memset (&dst[i], 0, sizeof (*dst)); + dst[i].dp_table = e->dp_table; + dst[i].fwd_entry_index = e->fwd_entry_index; + dst[i].vni = e->vni; + dst[i].action = e->action; + switch (fid_addr_type (&e->leid)) + { + case FID_ADDR_IP_PREF: + dst[i].leid.type = EID_TYPE_API_PREFIX; + dst[i].reid.type = EID_TYPE_API_PREFIX; + ip_prefix_encode2 (&fid_addr_ippref (&e->leid), + &dst[i].leid.address.prefix); + ip_prefix_encode2 (&fid_addr_ippref (&e->reid), + &dst[i].reid.address.prefix); + break; + case FID_ADDR_MAC: + mac_address_encode ((mac_address_t *) fid_addr_mac (&e->leid), + dst[i].leid.address.mac); + mac_address_encode ((mac_address_t *) fid_addr_mac (&e->reid), + dst[i].reid.address.mac); + dst[i].leid.type = EID_TYPE_API_MAC; + dst[i].reid.type = EID_TYPE_API_MAC; + break; + default: + clib_warning ("unknown fid type %d!", fid_addr_type (&e->leid)); + break; + } + i++; + } +} + +static void +gpe_fwd_entries_get_t_net_to_host (vl_api_gpe_fwd_entries_get_t * mp) +{ + mp->vni = clib_net_to_host_u32 (mp->vni); +} + +static void +gpe_entry_t_host_to_net (vl_api_gpe_fwd_entry_t * e) +{ + e->fwd_entry_index = clib_host_to_net_u32 (e->fwd_entry_index); + e->dp_table = clib_host_to_net_u32 (e->dp_table); + e->vni = clib_host_to_net_u32 (e->vni); +} + +static void + gpe_fwd_entries_get_reply_t_host_to_net + (vl_api_gpe_fwd_entries_get_reply_t * mp) +{ + u32 i; + vl_api_gpe_fwd_entry_t *e; + + for (i = 0; i < mp->count; i++) + { + e = &mp->entries[i]; + gpe_entry_t_host_to_net (e); + } + mp->count = clib_host_to_net_u32 (mp->count); +} + +static void +vl_api_gpe_fwd_entry_vnis_get_t_handler (vl_api_gpe_fwd_entry_vnis_get_t * mp) +{ + vl_api_gpe_fwd_entry_vnis_get_reply_t *rmp = 0; + hash_pair_t *p; + u32 i = 0; + int rv = 0; + + u32 *vnis = vnet_lisp_gpe_get_fwd_entry_vnis (); + u32 size = hash_elts (vnis) * sizeof (u32); + + /* *INDENT-OFF* */ + REPLY_MACRO4 (VL_API_GPE_FWD_ENTRY_VNIS_GET_REPLY, size, + { + rmp->count = clib_host_to_net_u32 (hash_elts (vnis)); + hash_foreach_pair (p, vnis, + ({ + rmp->vnis[i++] = clib_host_to_net_u32 (p->key); + })); + }); + /* *INDENT-ON* */ + + hash_free (vnis); +} + +static void +vl_api_gpe_fwd_entries_get_t_handler (vl_api_gpe_fwd_entries_get_t * mp) +{ + lisp_api_gpe_fwd_entry_t *e; + vl_api_gpe_fwd_entries_get_reply_t *rmp = 0; + u32 size = 0; + int rv = 0; + + gpe_fwd_entries_get_t_net_to_host (mp); + + e = vnet_lisp_gpe_fwd_entries_get_by_vni (mp->vni); + size = vec_len (e) * sizeof (vl_api_gpe_fwd_entry_t); + + /* *INDENT-OFF* */ + REPLY_MACRO4 (VL_API_GPE_FWD_ENTRIES_GET_REPLY, size, + { + rmp->count = vec_len (e); + gpe_fwd_entries_copy (rmp->entries, e); + gpe_fwd_entries_get_reply_t_host_to_net (rmp); + }); + /* *INDENT-ON* */ + + vec_free (e); +} + +static void +gpe_add_del_fwd_entry_t_net_to_host (vl_api_gpe_add_del_fwd_entry_t * mp) +{ + mp->vni = clib_net_to_host_u32 (mp->vni); + mp->dp_table = clib_net_to_host_u32 (mp->dp_table); + mp->loc_num = clib_net_to_host_u32 (mp->loc_num); +} + +static void +vl_api_gpe_add_del_fwd_entry_t_handler (vl_api_gpe_add_del_fwd_entry_t * mp) +{ + vl_api_gpe_add_del_fwd_entry_reply_t *rmp; + vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a; + locator_pair_t *pairs = 0; + int rv = 0; + + gpe_add_del_fwd_entry_t_net_to_host (mp); + clib_memset (a, 0, sizeof (a[0])); + + rv = unformat_lisp_eid_api (&a->rmt_eid, mp->vni, &mp->rmt_eid); + rv |= unformat_lisp_eid_api (&a->lcl_eid, mp->vni, &mp->lcl_eid); + + if (mp->loc_num % 2 != 0) + { + rv = -1; + goto send_reply; + } + pairs = unformat_gpe_loc_pairs (mp->locs, mp->loc_num / 2); + + if (rv) + goto send_reply; + + a->is_add = mp->is_add; + a->locator_pairs = pairs; + a->dp_table = mp->dp_table; + a->vni = mp->vni; + a->action = mp->action; + if (mp->loc_num == 0) + a->is_negative = 1; + + rv = vnet_lisp_gpe_add_del_fwd_entry (a, 0); + vec_free (pairs); +send_reply: + /* *INDENT-OFF* */ + REPLY_MACRO2 (VL_API_GPE_ADD_DEL_FWD_ENTRY_REPLY, + { + rmp->fwd_entry_index = clib_host_to_net_u32 (a->fwd_entry_index); + }); + /* *INDENT-ON* */ +} + +static void +vl_api_gpe_enable_disable_t_handler (vl_api_gpe_enable_disable_t * mp) +{ + vl_api_gpe_enable_disable_reply_t *rmp; + int rv = 0; + vnet_lisp_gpe_enable_disable_args_t _a, *a = &_a; + + a->is_en = mp->is_enable; + vnet_lisp_gpe_enable_disable (a); + + REPLY_MACRO (VL_API_GPE_ENABLE_DISABLE_REPLY); +} + +static void +vl_api_gpe_add_del_iface_t_handler (vl_api_gpe_add_del_iface_t * mp) +{ + vl_api_gpe_add_del_iface_reply_t *rmp; + int rv = 0; + u32 vni, dp_table; + + vni = clib_net_to_host_u32 (mp->vni); + dp_table = clib_net_to_host_u32 (mp->dp_table); + + if (mp->is_l2) + { + if (mp->is_add) + { + if (~0 == lisp_gpe_tenant_l2_iface_add_or_lock (vni, dp_table)) + rv = 1; + } + else + lisp_gpe_tenant_l2_iface_unlock (vni); + } + else + { + if (mp->is_add) + { + if (~0 == lisp_gpe_tenant_l3_iface_add_or_lock (vni, dp_table, 1)) + rv = 1; + } + else + lisp_gpe_tenant_l3_iface_unlock (vni); + } + + REPLY_MACRO (VL_API_GPE_ADD_DEL_IFACE_REPLY); +} + +static void +vl_api_gpe_set_encap_mode_t_handler (vl_api_gpe_set_encap_mode_t * mp) +{ + vl_api_gpe_set_encap_mode_reply_t *rmp; + int rv = 0; + + rv = vnet_gpe_set_encap_mode (mp->is_vxlan); + REPLY_MACRO (VL_API_GPE_SET_ENCAP_MODE_REPLY); +} + +static void +vl_api_gpe_get_encap_mode_t_handler (vl_api_gpe_get_encap_mode_t * mp) +{ + vl_api_gpe_get_encap_mode_reply_t *rmp; + int rv = 0; + + /* *INDENT-OFF* */ + REPLY_MACRO2 (VL_API_GPE_GET_ENCAP_MODE_REPLY, + ({ + rmp->encap_mode = vnet_gpe_get_encap_mode (); + })); + /* *INDENT-ON* */ +} + +static void + vl_api_gpe_add_del_native_fwd_rpath_t_handler + (vl_api_gpe_add_del_native_fwd_rpath_t * mp) +{ + vl_api_gpe_add_del_native_fwd_rpath_reply_t *rmp; + vnet_gpe_native_fwd_rpath_args_t _a, *a = &_a; + int rv = 0; + + clib_memset (a, 0, sizeof (a[0])); + + if (mp->nh_addr.af) + clib_memcpy (&a->rpath.frp_addr.ip6, mp->nh_addr.un.ip6, + sizeof (ip6_address_t)); + else + clib_memcpy (&a->rpath.frp_addr.ip4, mp->nh_addr.un.ip4, + sizeof (ip4_address_t)); + + a->is_add = mp->is_add; + a->rpath.frp_proto = mp->nh_addr.af ? DPO_PROTO_IP6 : DPO_PROTO_IP4; + a->rpath.frp_fib_index = + fib_table_find (dpo_proto_to_fib (a->rpath.frp_proto), + clib_net_to_host_u32 (mp->table_id)); + if (~0 == a->rpath.frp_fib_index) + { + rv = VNET_API_ERROR_INVALID_VALUE; + goto done; + } + + a->rpath.frp_sw_if_index = clib_net_to_host_u32 (mp->nh_sw_if_index); + a->rpath.frp_weight = 1; + + rv = vnet_gpe_add_del_native_fwd_rpath (a); +done: + REPLY_MACRO (VL_API_GPE_ADD_DEL_NATIVE_FWD_RPATH_REPLY); +} + +static void +gpe_native_fwd_rpaths_copy (vl_api_gpe_native_fwd_rpath_t * dst, + fib_route_path_t * src) +{ + fib_route_path_t *e; + fib_table_t *table; + u32 i = 0; + + vec_foreach (e, src) + { + clib_memset (&dst[i], 0, sizeof (*dst)); + table = fib_table_get (e->frp_fib_index, dpo_proto_to_fib (e->frp_proto)); + dst[i].fib_index = table->ft_table_id; + dst[i].nh_sw_if_index = e->frp_sw_if_index; + ip_address_encode (&e->frp_addr, IP46_TYPE_ANY, &dst[i].nh_addr); + i++; + } +} + +static void +gpe_native_fwd_rpath_t_host_to_net (vl_api_gpe_native_fwd_rpath_t * e) +{ + e->fib_index = clib_host_to_net_u32 (e->fib_index); + e->nh_sw_if_index = clib_host_to_net_u32 (e->nh_sw_if_index); +} + +static void + gpe_native_fwd_rpaths_get_reply_t_host_to_net + (vl_api_gpe_native_fwd_rpaths_get_reply_t * mp) +{ + u32 i; + vl_api_gpe_native_fwd_rpath_t *e; + + for (i = 0; i < mp->count; i++) + { + e = &mp->entries[i]; + gpe_native_fwd_rpath_t_host_to_net (e); + } + mp->count = clib_host_to_net_u32 (mp->count); +} + +static void +vl_api_gpe_native_fwd_rpaths_get_t_handler (vl_api_gpe_native_fwd_rpaths_get_t + * mp) +{ + lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main (); + vl_api_gpe_native_fwd_rpaths_get_reply_t *rmp; + u32 size = 0; + int rv = 0; + + u8 rpath_index = mp->is_ip4 ? 1 : 0; + + size = vec_len (lgm->native_fwd_rpath[rpath_index]) + * sizeof (vl_api_gpe_native_fwd_rpath_t); + + /* *INDENT-OFF* */ + REPLY_MACRO4 (VL_API_GPE_NATIVE_FWD_RPATHS_GET_REPLY, size, + { + rmp->count = vec_len (lgm->native_fwd_rpath[rpath_index]); + gpe_native_fwd_rpaths_copy (rmp->entries, + lgm->native_fwd_rpath[rpath_index]); + gpe_native_fwd_rpaths_get_reply_t_host_to_net (rmp); + }); + /* *INDENT-ON* */ +} + +/* + * lisp_api_hookup + * Add vpe's API message handlers to the table. + * vlib has already mapped shared memory and + * added the client registration handlers. + * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process() + */ +#include + +static clib_error_t * +gpe_api_hookup (vlib_main_t * vm) +{ + /* + * Set up the (msg_name, crc, message-id) table + */ + gpe_base_msg_id = setup_message_id_table (); + + return NULL; +} + +VLIB_API_INIT_FUNCTION (gpe_api_hookup); + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/lisp/lisp-gpe/lisp_gpe_error.def b/src/plugins/lisp/lisp-gpe/lisp_gpe_error.def new file mode 100644 index 00000000000..415fada73d2 --- /dev/null +++ b/src/plugins/lisp/lisp-gpe/lisp_gpe_error.def @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +lisp_gpe_error (ENCAPSULATED, "good packets encapsulated") +lisp_gpe_error (DECAPSULATED, "good packets decapsulated") +lisp_gpe_error (NO_TUNNEL, "tunnel does not exist") diff --git a/src/plugins/lisp/lisp-gpe/lisp_gpe_fwd_entry.c b/src/plugins/lisp/lisp-gpe/lisp_gpe_fwd_entry.c new file mode 100644 index 00000000000..334164c2583 --- /dev/null +++ b/src/plugins/lisp/lisp-gpe/lisp_gpe_fwd_entry.c @@ -0,0 +1,1595 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/** + * @brief Add route to IP4 or IP6 Destination FIB. + * + * Add a route to the destination FIB that results in the lookup + * in the SRC FIB. The SRC FIB is created is it does not yet exist. + * + * @param[in] dst_table_id Destination FIB Table-ID + * @param[in] dst_prefix Destination IP prefix. + * + * @return src_fib_index The index/ID of the SRC FIB created. + */ +static u32 +ip_dst_fib_add_route (u32 dst_fib_index, const ip_prefix_t * dst_prefix) +{ + fib_node_index_t src_fib_index; + fib_prefix_t dst_fib_prefix; + fib_node_index_t dst_fei; + + ASSERT (NULL != dst_prefix); + + ip_prefix_to_fib_prefix (dst_prefix, &dst_fib_prefix); + + /* + * lookup the destination prefix in the VRF table and retrieve the + * LISP associated data + */ + dst_fei = fib_table_lookup_exact_match (dst_fib_index, &dst_fib_prefix); + + /* + * If the FIB entry is not present, or not LISP sourced, add it + */ + if (dst_fei == FIB_NODE_INDEX_INVALID || + NULL == fib_entry_get_source_data (dst_fei, FIB_SOURCE_LISP)) + { + dpo_id_t src_lkup_dpo = DPO_INVALID; + + /* create a new src FIB. */ + src_fib_index = + fib_table_create_and_lock (dst_fib_prefix.fp_proto, + FIB_SOURCE_LISP, + "LISP-src for [%d,%U]", + dst_fib_index, + format_fib_prefix, &dst_fib_prefix); + /* + * add src fib default route + */ + fib_prefix_t prefix = { + .fp_proto = dst_fib_prefix.fp_proto, + }; + fib_table_entry_special_dpo_add (src_fib_index, &prefix, + FIB_SOURCE_LISP, + FIB_ENTRY_FLAG_EXCLUSIVE, + lisp_cp_dpo_get (fib_proto_to_dpo + (dst_fib_prefix.fp_proto))); + /* + * create a data-path object to perform the source address lookup + * in the SRC FIB + */ + lookup_dpo_add_or_lock_w_fib_index (src_fib_index, + (ip_prefix_version (dst_prefix) == + AF_IP6 ? DPO_PROTO_IP6 : + DPO_PROTO_IP4), + LOOKUP_UNICAST, + LOOKUP_INPUT_SRC_ADDR, + LOOKUP_TABLE_FROM_CONFIG, + &src_lkup_dpo); + + /* + * add the entry to the destination FIB that uses the lookup DPO + */ + dst_fei = fib_table_entry_special_dpo_add (dst_fib_index, + &dst_fib_prefix, + FIB_SOURCE_LISP, + FIB_ENTRY_FLAG_EXCLUSIVE, + &src_lkup_dpo); + + /* + * the DPO is locked by the FIB entry, and we have no further + * need for it. + */ + dpo_unlock (&src_lkup_dpo); + + /* + * save the SRC FIB index on the entry so we can retrieve it for + * subsequent routes. + */ + fib_entry_set_source_data (dst_fei, FIB_SOURCE_LISP, &src_fib_index); + } + else + { + /* + * destination FIB entry already present + */ + src_fib_index = *(u32 *) fib_entry_get_source_data (dst_fei, + FIB_SOURCE_LISP); + } + + return (src_fib_index); +} + +/** + * @brief Del route to IP4 or IP6 SD FIB. + * + * Remove routes from both destination and source FIBs. + * + * @param[in] src_fib_index The index/ID of the SRC FIB + * @param[in] src_prefix Source IP prefix. + * @param[in] dst_fib_index The index/ID of the DST FIB + * @param[in] dst_prefix Destination IP prefix. + */ +static void +ip_src_dst_fib_del_route (u32 src_fib_index, + const ip_prefix_t * src_prefix, + u32 dst_fib_index, const ip_prefix_t * dst_prefix) +{ + fib_prefix_t dst_fib_prefix, src_fib_prefix; + u8 have_default = 0; + u32 n_entries; + + ASSERT (NULL != dst_prefix); + ASSERT (NULL != src_prefix); + + ip_prefix_to_fib_prefix (dst_prefix, &dst_fib_prefix); + ip_prefix_to_fib_prefix (src_prefix, &src_fib_prefix); + + fib_table_entry_delete (src_fib_index, &src_fib_prefix, FIB_SOURCE_LISP); + + /* check if only default left or empty */ + fib_prefix_t default_pref = { + .fp_proto = dst_fib_prefix.fp_proto + }; + + if (fib_table_lookup_exact_match (src_fib_index, + &default_pref) != FIB_NODE_INDEX_INVALID) + have_default = 1; + + n_entries = fib_table_get_num_entries (src_fib_index, + src_fib_prefix.fp_proto, + FIB_SOURCE_LISP); + if (n_entries == 0 || (have_default && n_entries == 1)) + { + /* + * remove src FIB default route + */ + if (have_default) + fib_table_entry_special_remove (src_fib_index, &default_pref, + FIB_SOURCE_LISP); + + /* + * there's nothing left now, unlock the source FIB and the + * destination route + */ + fib_table_entry_special_remove (dst_fib_index, + &dst_fib_prefix, FIB_SOURCE_LISP); + fib_table_unlock (src_fib_index, src_fib_prefix.fp_proto, + FIB_SOURCE_LISP); + } +} + +/** + * @brief Add route to IP4 or IP6 SRC FIB. + * + * Adds a route to in the LISP SRC FIB with the result of the route + * being the DPO passed. + * + * @param[in] src_fib_index The index/ID of the SRC FIB + * @param[in] src_prefix Source IP prefix. + * @param[in] src_dpo The DPO the route will link to. + * + * @return fib index of the inserted prefix + */ +static fib_node_index_t +ip_src_fib_add_route_w_dpo (u32 src_fib_index, + const ip_prefix_t * src_prefix, + const dpo_id_t * src_dpo) +{ + fib_node_index_t fei = ~0; + fib_prefix_t src_fib_prefix; + + ip_prefix_to_fib_prefix (src_prefix, &src_fib_prefix); + + /* + * add the entry into the source fib. + */ + fib_node_index_t src_fei; + + src_fei = fib_table_lookup_exact_match (src_fib_index, &src_fib_prefix); + + if (FIB_NODE_INDEX_INVALID == src_fei || + !fib_entry_is_sourced (src_fei, FIB_SOURCE_LISP)) + { + fei = fib_table_entry_special_dpo_add (src_fib_index, + &src_fib_prefix, + FIB_SOURCE_LISP, + FIB_ENTRY_FLAG_EXCLUSIVE, + src_dpo); + } + return fei; +} + +static fib_route_path_t * +lisp_gpe_mk_fib_paths (const lisp_fwd_path_t * paths) +{ + const lisp_gpe_adjacency_t *ladj; + fib_route_path_t *rpaths = NULL; + fib_protocol_t fp; + u8 best_priority; + u32 ii; + + vec_validate (rpaths, vec_len (paths) - 1); + + best_priority = paths[0].priority; + + vec_foreach_index (ii, paths) + { + if (paths[0].priority != best_priority) + break; + + ladj = lisp_gpe_adjacency_get (paths[ii].lisp_adj); + + fp = ip_address_to_46 (&ladj->remote_rloc, &rpaths[ii].frp_addr); + + rpaths[ii].frp_proto = fib_proto_to_dpo (fp); + rpaths[ii].frp_sw_if_index = ladj->sw_if_index; + rpaths[ii].frp_weight = (paths[ii].weight ? paths[ii].weight : 1); + } + + ASSERT (0 != vec_len (rpaths)); + + return (rpaths); +} + +/** + * @brief Add route to IP4 or IP6 SRC FIB. + * + * Adds a route to in the LISP SRC FIB for the tunnel. + * + * @param[in] src_fib_index The index/ID of the SRC FIB + * @param[in] src_prefix Source IP prefix. + * @param[in] paths The paths from which to construct the + * load balance + */ +static fib_node_index_t +ip_src_fib_add_route (u32 src_fib_index, + const ip_prefix_t * src_prefix, + const lisp_fwd_path_t * paths) +{ + fib_prefix_t src_fib_prefix; + fib_route_path_t *rpaths; + + ip_prefix_to_fib_prefix (src_prefix, &src_fib_prefix); + + rpaths = lisp_gpe_mk_fib_paths (paths); + + fib_node_index_t fib_entry_index = + fib_table_entry_update (src_fib_index, &src_fib_prefix, FIB_SOURCE_LISP, + FIB_ENTRY_FLAG_NONE, rpaths); + vec_free (rpaths); + return fib_entry_index; +} + +static void +gpe_native_fwd_add_del_lfe (lisp_gpe_fwd_entry_t * lfe, u8 is_add) +{ + lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main (); + u8 found = 0, ip_version; + u32 *lfei, new_lfei; + ip_version = ip_prefix_version (&lfe->key->rmt.ippref); + + new_lfei = lfe - lgm->lisp_fwd_entry_pool; + vec_foreach (lfei, lgm->native_fwd_lfes[ip_version]) + { + lfe = pool_elt_at_index (lgm->lisp_fwd_entry_pool, lfei[0]); + if (lfei[0] == new_lfei) + { + found = 1; + break; + } + } + + if (is_add) + { + if (!found) + vec_add1 (lgm->native_fwd_lfes[ip_version], new_lfei); + } + else + { + if (found) + vec_del1 (lgm->native_fwd_lfes[ip_version], lfei[0]); + } +} + +static index_t +create_fib_entries (lisp_gpe_fwd_entry_t * lfe) +{ + fib_node_index_t fi; + fib_entry_t *fe; + lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main (); + dpo_proto_t dproto; + ip_prefix_t ippref; + fib_prefix_t fib_prefix; + u8 ip_version = ip_prefix_version (&lfe->key->rmt.ippref); + dproto = (ip_version == AF_IP4 ? DPO_PROTO_IP4 : DPO_PROTO_IP6); + + if (lfe->is_src_dst) + { + lfe->src_fib_index = ip_dst_fib_add_route (lfe->eid_fib_index, + &lfe->key->rmt.ippref); + memcpy (&ippref, &lfe->key->lcl.ippref, sizeof (ippref)); + } + else + { + lfe->src_fib_index = lfe->eid_fib_index; + memcpy (&ippref, &lfe->key->rmt.ippref, sizeof (ippref)); + } + + if (LISP_GPE_FWD_ENTRY_TYPE_NEGATIVE == lfe->type) + { + dpo_id_t dpo = DPO_INVALID; + + switch (lfe->action) + { + case LISP_FORWARD_NATIVE: + /* TODO handle route overlaps with fib and default route */ + if (vec_len (lgm->native_fwd_rpath[ip_version])) + { + ip_prefix_to_fib_prefix (&lfe->key->rmt.ippref, &fib_prefix); + fi = fib_table_entry_update (lfe->eid_fib_index, &fib_prefix, + FIB_SOURCE_LISP, + FIB_ENTRY_FLAG_NONE, + lgm->native_fwd_rpath[ip_version]); + gpe_native_fwd_add_del_lfe (lfe, 1); + goto done; + } + case LISP_NO_ACTION: + /* TODO update timers? */ + case LISP_SEND_MAP_REQUEST: + /* insert tunnel that always sends map-request */ + dpo_copy (&dpo, lisp_cp_dpo_get (dproto)); + break; + case LISP_DROP: + /* for drop fwd entries, just add route, no need to add encap tunnel */ + dpo_copy (&dpo, drop_dpo_get (dproto)); + break; + } + fi = ip_src_fib_add_route_w_dpo (lfe->src_fib_index, &ippref, &dpo); + dpo_reset (&dpo); + } + else + { + fi = ip_src_fib_add_route (lfe->src_fib_index, &ippref, lfe->paths); + } +done: + fe = fib_entry_get (fi); + return fe->fe_lb.dpoi_index; +} + +static void +delete_fib_entries (lisp_gpe_fwd_entry_t * lfe) +{ + fib_prefix_t dst_fib_prefix; + + if (lfe->is_src_dst) + ip_src_dst_fib_del_route (lfe->src_fib_index, + &lfe->key->lcl.ippref, + lfe->eid_fib_index, &lfe->key->rmt.ippref); + else + { + ip_prefix_to_fib_prefix (&lfe->key->rmt.ippref, &dst_fib_prefix); + fib_table_entry_delete (lfe->src_fib_index, &dst_fib_prefix, + FIB_SOURCE_LISP); + gpe_native_fwd_add_del_lfe (lfe, 0); + } +} + +static lisp_gpe_fwd_entry_t * +find_fwd_entry (lisp_gpe_main_t * lgm, + vnet_lisp_gpe_add_del_fwd_entry_args_t * a, + lisp_gpe_fwd_entry_key_t * key) +{ + uword *p; + + clib_memset (key, 0, sizeof (*key)); + + if (GID_ADDR_IP_PREFIX == gid_address_type (&a->rmt_eid)) + { + /* + * the ip version of the source is not set to ip6 when the + * source is all zeros. force it. + */ + ip_prefix_version (&gid_address_ippref (&a->lcl_eid)) = + ip_prefix_version (&gid_address_ippref (&a->rmt_eid)); + } + + gid_to_dp_address (&a->rmt_eid, &key->rmt); + gid_to_dp_address (&a->lcl_eid, &key->lcl); + key->vni = a->vni; + + p = hash_get_mem (lgm->lisp_gpe_fwd_entries, key); + + if (NULL != p) + { + return (pool_elt_at_index (lgm->lisp_fwd_entry_pool, p[0])); + } + return (NULL); +} + +static int +lisp_gpe_fwd_entry_path_sort (void *a1, void *a2) +{ + lisp_fwd_path_t *p1 = a1, *p2 = a2; + + return (p1->priority - p2->priority); +} + +static void +lisp_gpe_fwd_entry_mk_paths (lisp_gpe_fwd_entry_t * lfe, + vnet_lisp_gpe_add_del_fwd_entry_args_t * a) +{ + lisp_fwd_path_t *path; + u32 index; + + vec_validate (lfe->paths, vec_len (a->locator_pairs) - 1); + + vec_foreach_index (index, a->locator_pairs) + { + path = &lfe->paths[index]; + + path->priority = a->locator_pairs[index].priority; + path->weight = a->locator_pairs[index].weight; + + path->lisp_adj = + lisp_gpe_adjacency_find_or_create_and_lock (&a->locator_pairs + [index], + a->dp_table, lfe->key->vni); + } + vec_sort_with_function (lfe->paths, lisp_gpe_fwd_entry_path_sort); +} + +void +vnet_lisp_gpe_add_fwd_counters (vnet_lisp_gpe_add_del_fwd_entry_args_t * a, + u32 fwd_entry_index) +{ + const lisp_gpe_adjacency_t *ladj; + lisp_fwd_path_t *path; + lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main (); + u8 *placeholder_elt; + lisp_gpe_fwd_entry_t *lfe; + lisp_gpe_fwd_entry_key_t fe_key; + lisp_stats_key_t key; + + lfe = find_fwd_entry (lgm, a, &fe_key); + + if (!lfe) + return; + + if (LISP_GPE_FWD_ENTRY_TYPE_NORMAL != lfe->type) + return; + + clib_memset (&key, 0, sizeof (key)); + key.fwd_entry_index = fwd_entry_index; + + vec_foreach (path, lfe->paths) + { + ladj = lisp_gpe_adjacency_get (path->lisp_adj); + key.tunnel_index = ladj->tunnel_index; + lisp_stats_key_t *key_copy = clib_mem_alloc (sizeof (*key_copy)); + memcpy (key_copy, &key, sizeof (*key_copy)); + pool_get (lgm->placeholder_stats_pool, placeholder_elt); + hash_set_mem (lgm->lisp_stats_index_by_key, key_copy, + placeholder_elt - lgm->placeholder_stats_pool); + + vlib_validate_combined_counter (&lgm->counters, + placeholder_elt - + lgm->placeholder_stats_pool); + vlib_zero_combined_counter (&lgm->counters, + placeholder_elt - + lgm->placeholder_stats_pool); + } +} + +/** + * @brief Add/Delete LISP IP forwarding entry. + * + * creation of forwarding entries for IP LISP overlay: + * + * @param[in] lgm Reference to @ref lisp_gpe_main_t. + * @param[in] a Parameters for building the forwarding entry. + * + * @return 0 on success. + */ +static int +add_ip_fwd_entry (lisp_gpe_main_t * lgm, + vnet_lisp_gpe_add_del_fwd_entry_args_t * a) +{ + lisp_gpe_fwd_entry_key_t key; + lisp_gpe_fwd_entry_t *lfe; + fib_protocol_t fproto; + + lfe = find_fwd_entry (lgm, a, &key); + + if (NULL != lfe) + /* don't support updates */ + return VNET_API_ERROR_INVALID_VALUE; + + pool_get (lgm->lisp_fwd_entry_pool, lfe); + clib_memset (lfe, 0, sizeof (*lfe)); + lfe->key = clib_mem_alloc (sizeof (key)); + memcpy (lfe->key, &key, sizeof (key)); + + hash_set_mem (lgm->lisp_gpe_fwd_entries, lfe->key, + lfe - lgm->lisp_fwd_entry_pool); + a->fwd_entry_index = lfe - lgm->lisp_fwd_entry_pool; + + fproto = (AF_IP4 == ip_prefix_version (&fid_addr_ippref (&lfe->key->rmt)) ? + FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6); + + lfe->type = (a->is_negative ? + LISP_GPE_FWD_ENTRY_TYPE_NEGATIVE : + LISP_GPE_FWD_ENTRY_TYPE_NORMAL); + lfe->tenant = lisp_gpe_tenant_find_or_create (lfe->key->vni); + lfe->eid_table_id = a->table_id; + lfe->eid_fib_index = fib_table_find_or_create_and_lock (fproto, + lfe->eid_table_id, + FIB_SOURCE_LISP); + lfe->is_src_dst = a->is_src_dst; + + if (LISP_GPE_FWD_ENTRY_TYPE_NEGATIVE != lfe->type) + { + lisp_gpe_fwd_entry_mk_paths (lfe, a); + } + else + { + lfe->action = a->action; + } + + lfe->dpoi_index = create_fib_entries (lfe); + return (0); +} + +static void +del_ip_fwd_entry_i (lisp_gpe_main_t * lgm, lisp_gpe_fwd_entry_t * lfe) +{ + lisp_fwd_path_t *path; + fib_protocol_t fproto; + + if (LISP_GPE_FWD_ENTRY_TYPE_NEGATIVE != lfe->type) + { + vec_foreach (path, lfe->paths) + { + lisp_gpe_adjacency_unlock (path->lisp_adj); + } + } + + delete_fib_entries (lfe); + + fproto = (AF_IP4 == ip_prefix_version (&fid_addr_ippref (&lfe->key->rmt)) ? + FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6); + fib_table_unlock (lfe->eid_fib_index, fproto, FIB_SOURCE_LISP); + + hash_unset_mem (lgm->lisp_gpe_fwd_entries, lfe->key); + clib_mem_free (lfe->key); + pool_put (lgm->lisp_fwd_entry_pool, lfe); +} + +/** + * @brief Add/Delete LISP IP forwarding entry. + * + * removal of forwarding entries for IP LISP overlay: + * + * @param[in] lgm Reference to @ref lisp_gpe_main_t. + * @param[in] a Parameters for building the forwarding entry. + * + * @return 0 on success. + */ +static int +del_ip_fwd_entry (lisp_gpe_main_t * lgm, + vnet_lisp_gpe_add_del_fwd_entry_args_t * a) +{ + lisp_gpe_fwd_entry_key_t key; + lisp_gpe_fwd_entry_t *lfe; + + lfe = find_fwd_entry (lgm, a, &key); + + if (NULL == lfe) + /* no such entry */ + return VNET_API_ERROR_INVALID_VALUE; + + del_ip_fwd_entry_i (lgm, lfe); + + return (0); +} + +static void +make_mac_fib_key (BVT (clib_bihash_kv) * kv, u16 bd_index, u8 src_mac[6], + u8 dst_mac[6]) +{ + kv->key[0] = (((u64) bd_index) << 48) | mac_to_u64 (dst_mac); + kv->key[1] = mac_to_u64 (src_mac); + kv->key[2] = 0; +} + +/** + * @brief Lookup L2 SD FIB entry + * + * Does a vni + dest + source lookup in the L2 LISP FIB. If the lookup fails + * it tries a second time with source set to 0 (i.e., a simple dest lookup). + * + * @param[in] lgm Reference to @ref lisp_gpe_main_t. + * @param[in] bd_index Bridge domain index. + * @param[in] src_mac Source mac address. + * @param[in] dst_mac Destination mac address. + * + * @return index of mapping matching the lookup key. + */ +index_t +lisp_l2_fib_lookup (lisp_gpe_main_t * lgm, u16 bd_index, u8 src_mac[6], + u8 dst_mac[6]) +{ + int rv; + BVT (clib_bihash_kv) kv, value; + + make_mac_fib_key (&kv, bd_index, src_mac, dst_mac); + rv = BV (clib_bihash_search_inline_2) (&lgm->l2_fib, &kv, &value); + + /* no match, try with src 0, catch all for dst */ + if (rv != 0) + { + kv.key[1] = 0; + rv = BV (clib_bihash_search_inline_2) (&lgm->l2_fib, &kv, &value); + if (rv == 0) + return value.value; + } + else + return value.value; + + return lisp_gpe_main.l2_lb_cp_lkup.dpoi_index; +} + +/** + * @brief Add/del L2 SD FIB entry + * + * Inserts value in L2 FIB keyed by vni + dest + source. If entry is + * overwritten the associated value is returned. + * + * @param[in] lgm Reference to @ref lisp_gpe_main_t. + * @param[in] bd_index Bridge domain index. + * @param[in] src_mac Source mac address. + * @param[in] dst_mac Destination mac address. + * @param[in] val Value to add. + * @param[in] is_add Add/del flag. + * + * @return ~0 or value of overwritten entry. + */ +static u32 +lisp_l2_fib_add_del_entry (u16 bd_index, u8 src_mac[6], + u8 dst_mac[6], const dpo_id_t * dpo, u8 is_add) +{ + lisp_gpe_main_t *lgm = &lisp_gpe_main; + BVT (clib_bihash_kv) kv, value; + u32 old_val = ~0; + + make_mac_fib_key (&kv, bd_index, src_mac, dst_mac); + + if (BV (clib_bihash_search) (&lgm->l2_fib, &kv, &value) == 0) + old_val = value.value; + + if (!is_add) + BV (clib_bihash_add_del) (&lgm->l2_fib, &kv, 0 /* is_add */ ); + else + { + kv.value = dpo->dpoi_index; + BV (clib_bihash_add_del) (&lgm->l2_fib, &kv, 1 /* is_add */ ); + } + return old_val; +} + +#define L2_FIB_DEFAULT_HASH_NUM_BUCKETS (64 * 1024) +#define L2_FIB_DEFAULT_HASH_MEMORY_SIZE (32<<20) + +static void +l2_fib_init (lisp_gpe_main_t * lgm) +{ + index_t lbi; + + BV (clib_bihash_init) (&lgm->l2_fib, "l2 fib", + 1 << max_log2 (L2_FIB_DEFAULT_HASH_NUM_BUCKETS), + L2_FIB_DEFAULT_HASH_MEMORY_SIZE); + + /* + * the result from a 'miss' in a L2 Table + */ + lbi = load_balance_create (1, DPO_PROTO_ETHERNET, 0); + load_balance_set_bucket (lbi, 0, lisp_cp_dpo_get (DPO_PROTO_ETHERNET)); + + dpo_set (&lgm->l2_lb_cp_lkup, DPO_LOAD_BALANCE, DPO_PROTO_ETHERNET, lbi); +} + +static void +del_l2_fwd_entry_i (lisp_gpe_main_t * lgm, lisp_gpe_fwd_entry_t * lfe) +{ + lisp_fwd_path_t *path; + + if (LISP_GPE_FWD_ENTRY_TYPE_NEGATIVE != lfe->type) + { + vec_foreach (path, lfe->paths) + { + lisp_gpe_adjacency_unlock (path->lisp_adj); + } + fib_path_list_child_remove (lfe->l2.path_list_index, + lfe->l2.child_index); + } + + lisp_l2_fib_add_del_entry (lfe->l2.eid_bd_index, + fid_addr_mac (&lfe->key->lcl), + fid_addr_mac (&lfe->key->rmt), NULL, 0); + + hash_unset_mem (lgm->lisp_gpe_fwd_entries, lfe->key); + clib_mem_free (lfe->key); + pool_put (lgm->lisp_fwd_entry_pool, lfe); +} + +/** + * @brief Delete LISP L2 forwarding entry. + * + * Coordinates the removal of forwarding entries for L2 LISP overlay: + * + * @param[in] lgm Reference to @ref lisp_gpe_main_t. + * @param[in] a Parameters for building the forwarding entry. + * + * @return 0 on success. + */ +static int +del_l2_fwd_entry (lisp_gpe_main_t * lgm, + vnet_lisp_gpe_add_del_fwd_entry_args_t * a) +{ + lisp_gpe_fwd_entry_key_t key; + lisp_gpe_fwd_entry_t *lfe; + + lfe = find_fwd_entry (lgm, a, &key); + + if (NULL == lfe) + return VNET_API_ERROR_INVALID_VALUE; + + del_l2_fwd_entry_i (lgm, lfe); + + return (0); +} + +/** + * @brief Construct and insert the forwarding information used by an L2 entry + */ +static void +lisp_gpe_l2_update_fwding (lisp_gpe_fwd_entry_t * lfe) +{ + lisp_gpe_main_t *lgm = &lisp_gpe_main; + dpo_id_t dpo = DPO_INVALID; + + if (LISP_GPE_FWD_ENTRY_TYPE_NEGATIVE != lfe->type) + { + fib_path_list_contribute_forwarding (lfe->l2.path_list_index, + FIB_FORW_CHAIN_TYPE_ETHERNET, + FIB_PATH_LIST_FWD_FLAG_NONE, + &lfe->l2.dpo); + dpo_copy (&dpo, &lfe->l2.dpo); + } + else + { + switch (lfe->action) + { + case SEND_MAP_REQUEST: + dpo_copy (&dpo, &lgm->l2_lb_cp_lkup); + break; + case NO_ACTION: + case FORWARD_NATIVE: + case DROP: + dpo_copy (&dpo, drop_dpo_get (DPO_PROTO_ETHERNET)); + } + } + + /* add entry to l2 lisp fib */ + lisp_l2_fib_add_del_entry (lfe->l2.eid_bd_index, + fid_addr_mac (&lfe->key->lcl), + fid_addr_mac (&lfe->key->rmt), &dpo, 1); + lfe->dpoi_index = dpo.dpoi_index; + + dpo_reset (&dpo); +} + +/** + * @brief Add LISP L2 forwarding entry. + * + * Coordinates the creation of forwarding entries for L2 LISP overlay: + * creates lisp-gpe tunnel and injects new entry in Source/Dest L2 FIB. + * + * @param[in] lgm Reference to @ref lisp_gpe_main_t. + * @param[in] a Parameters for building the forwarding entry. + * + * @return 0 on success. + */ +static int +add_l2_fwd_entry (lisp_gpe_main_t * lgm, + vnet_lisp_gpe_add_del_fwd_entry_args_t * a) +{ + lisp_gpe_fwd_entry_key_t key; + bd_main_t *bdm = &bd_main; + lisp_gpe_fwd_entry_t *lfe; + uword *bd_indexp; + + bd_indexp = hash_get (bdm->bd_index_by_bd_id, a->bd_id); + if (!bd_indexp) + { + clib_warning ("bridge domain %d doesn't exist", a->bd_id); + return -1; + } + + lfe = find_fwd_entry (lgm, a, &key); + + if (NULL != lfe) + /* don't support updates */ + return VNET_API_ERROR_INVALID_VALUE; + + pool_get (lgm->lisp_fwd_entry_pool, lfe); + clib_memset (lfe, 0, sizeof (*lfe)); + lfe->key = clib_mem_alloc (sizeof (key)); + memcpy (lfe->key, &key, sizeof (key)); + + hash_set_mem (lgm->lisp_gpe_fwd_entries, lfe->key, + lfe - lgm->lisp_fwd_entry_pool); + a->fwd_entry_index = lfe - lgm->lisp_fwd_entry_pool; + + lfe->type = (a->is_negative ? + LISP_GPE_FWD_ENTRY_TYPE_NEGATIVE : + LISP_GPE_FWD_ENTRY_TYPE_NORMAL); + lfe->l2.eid_bd_id = a->bd_id; + lfe->l2.eid_bd_index = bd_indexp[0]; + lfe->tenant = lisp_gpe_tenant_find_or_create (lfe->key->vni); + + if (LISP_GPE_FWD_ENTRY_TYPE_NEGATIVE != lfe->type) + { + fib_route_path_t *rpaths; + + /* + * Make the sorted array of LISP paths with their resp. adjacency + */ + lisp_gpe_fwd_entry_mk_paths (lfe, a); + + /* + * From the LISP paths, construct a FIB path list that will + * contribute a load-balance. + */ + rpaths = lisp_gpe_mk_fib_paths (lfe->paths); + + lfe->l2.path_list_index = + fib_path_list_create (FIB_PATH_LIST_FLAG_NONE, rpaths); + + /* + * become a child of the path-list so we receive updates when + * its forwarding state changes. this includes an implicit lock. + */ + lfe->l2.child_index = + fib_path_list_child_add (lfe->l2.path_list_index, + FIB_NODE_TYPE_LISP_GPE_FWD_ENTRY, + lfe - lgm->lisp_fwd_entry_pool); + } + else + { + lfe->action = a->action; + } + + lisp_gpe_l2_update_fwding (lfe); + + return 0; +} + +/** + * @brief Lookup NSH SD FIB entry + * + * Does an SPI+SI lookup in the NSH LISP FIB. + * + * @param[in] lgm Reference to @ref lisp_gpe_main_t. + * @param[in] spi_si SPI + SI. + * + * @return next node index. + */ +const dpo_id_t * +lisp_nsh_fib_lookup (lisp_gpe_main_t * lgm, u32 spi_si_net_order) +{ + int rv; + BVT (clib_bihash_kv) kv, value; + + clib_memset (&kv, 0, sizeof (kv)); + kv.key[0] = spi_si_net_order; + rv = BV (clib_bihash_search_inline_2) (&lgm->nsh_fib, &kv, &value); + + if (rv != 0) + { + return lgm->nsh_cp_lkup; + } + else + { + lisp_gpe_fwd_entry_t *lfe; + lfe = pool_elt_at_index (lgm->lisp_fwd_entry_pool, value.value); + return &lfe->nsh.choice; + } +} + +/** + * @brief Add/del NSH FIB entry + * + * Inserts value in NSH FIB keyed by SPI+SI. If entry is + * overwritten the associated value is returned. + * + * @param[in] lgm Reference to @ref lisp_gpe_main_t. + * @param[in] spi_si SPI + SI. + * @param[in] dpo Load balanced mapped to SPI + SI + * + * @return ~0 or value of overwritten entry. + */ +static u32 +lisp_nsh_fib_add_del_entry (u32 spi_si_host_order, u32 lfei, u8 is_add) +{ + lisp_gpe_main_t *lgm = &lisp_gpe_main; + BVT (clib_bihash_kv) kv, value; + u32 old_val = ~0; + + clib_memset (&kv, 0, sizeof (kv)); + kv.key[0] = clib_host_to_net_u32 (spi_si_host_order); + kv.value = 0ULL; + + if (BV (clib_bihash_search) (&lgm->nsh_fib, &kv, &value) == 0) + old_val = value.value; + + if (!is_add) + BV (clib_bihash_add_del) (&lgm->nsh_fib, &kv, 0 /* is_add */ ); + else + { + kv.value = lfei; + BV (clib_bihash_add_del) (&lgm->nsh_fib, &kv, 1 /* is_add */ ); + } + return old_val; +} + +#define NSH_FIB_DEFAULT_HASH_NUM_BUCKETS (64 * 1024) +#define NSH_FIB_DEFAULT_HASH_MEMORY_SIZE (32<<20) + +static void +nsh_fib_init (lisp_gpe_main_t * lgm) +{ + BV (clib_bihash_init) (&lgm->nsh_fib, "nsh fib", + 1 << max_log2 (NSH_FIB_DEFAULT_HASH_NUM_BUCKETS), + NSH_FIB_DEFAULT_HASH_MEMORY_SIZE); + + /* + * the result from a 'miss' in a NSH Table + */ + lgm->nsh_cp_lkup = lisp_cp_dpo_get (DPO_PROTO_NSH); +} + +static void +del_nsh_fwd_entry_i (lisp_gpe_main_t * lgm, lisp_gpe_fwd_entry_t * lfe) +{ + lisp_fwd_path_t *path; + + if (LISP_GPE_FWD_ENTRY_TYPE_NEGATIVE != lfe->type) + { + vec_foreach (path, lfe->paths) + { + lisp_gpe_adjacency_unlock (path->lisp_adj); + } + fib_path_list_child_remove (lfe->nsh.path_list_index, + lfe->nsh.child_index); + dpo_reset (&lfe->nsh.choice); + } + + lisp_nsh_fib_add_del_entry (fid_addr_nsh (&lfe->key->rmt), (u32) ~ 0, 0); + + hash_unset_mem (lgm->lisp_gpe_fwd_entries, lfe->key); + clib_mem_free (lfe->key); + pool_put (lgm->lisp_fwd_entry_pool, lfe); +} + +/** + * @brief Delete LISP NSH forwarding entry. + * + * Coordinates the removal of forwarding entries for NSH LISP overlay: + * + * @param[in] lgm Reference to @ref lisp_gpe_main_t. + * @param[in] a Parameters for building the forwarding entry. + * + * @return 0 on success. + */ +static int +del_nsh_fwd_entry (lisp_gpe_main_t * lgm, + vnet_lisp_gpe_add_del_fwd_entry_args_t * a) +{ + lisp_gpe_fwd_entry_key_t key; + lisp_gpe_fwd_entry_t *lfe; + + lfe = find_fwd_entry (lgm, a, &key); + + if (NULL == lfe) + return VNET_API_ERROR_INVALID_VALUE; + + del_nsh_fwd_entry_i (lgm, lfe); + + return (0); +} + +/** + * @brief Construct and insert the forwarding information used by an NSH entry + */ +static void +lisp_gpe_nsh_update_fwding (lisp_gpe_fwd_entry_t * lfe) +{ + lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main (); + dpo_id_t dpo = DPO_INVALID; + vnet_hw_interface_t *hi; + uword *hip; + + if (LISP_GPE_FWD_ENTRY_TYPE_NEGATIVE != lfe->type) + { + fib_path_list_contribute_forwarding (lfe->nsh.path_list_index, + FIB_FORW_CHAIN_TYPE_NSH, + FIB_PATH_LIST_FWD_FLAG_NONE, + &lfe->nsh.dpo); + + /* + * LISP encap is always the same for this SPI+SI so we do that hash now + * and stack on the choice. + */ + if (DPO_LOAD_BALANCE == lfe->nsh.dpo.dpoi_type) + { + const dpo_id_t *tmp; + const load_balance_t *lb; + int hash; + + lb = load_balance_get (lfe->nsh.dpo.dpoi_index); + hash = fid_addr_nsh (&lfe->key->rmt) % lb->lb_n_buckets; + tmp = + load_balance_get_bucket_i (lb, hash & lb->lb_n_buckets_minus_1); + + dpo_copy (&dpo, tmp); + } + } + else + { + switch (lfe->action) + { + case SEND_MAP_REQUEST: + dpo_copy (&dpo, lgm->nsh_cp_lkup); + break; + case NO_ACTION: + case FORWARD_NATIVE: + case DROP: + dpo_copy (&dpo, drop_dpo_get (DPO_PROTO_NSH)); + } + } + + /* We have only one nsh-lisp interface (no NSH virtualization) */ + hip = hash_get (lgm->nsh_ifaces.hw_if_index_by_dp_table, 0); + if (hip) + { + hi = vnet_get_hw_interface (lgm->vnet_main, hip[0]); + dpo_stack_from_node (hi->tx_node_index, &lfe->nsh.choice, &dpo); + } + /* add entry to nsh lisp fib */ + lisp_nsh_fib_add_del_entry (fid_addr_nsh (&lfe->key->rmt), + lfe - lgm->lisp_fwd_entry_pool, 1); + dpo_reset (&dpo); + +} + +/** + * @brief Add LISP NSH forwarding entry. + * + * Coordinates the creation of forwarding entries for L2 LISP overlay: + * creates lisp-gpe tunnel and injects new entry in Source/Dest L2 FIB. + * + * @param[in] lgm Reference to @ref lisp_gpe_main_t. + * @param[in] a Parameters for building the forwarding entry. + * + * @return 0 on success. + */ +static int +add_nsh_fwd_entry (lisp_gpe_main_t * lgm, + vnet_lisp_gpe_add_del_fwd_entry_args_t * a) +{ + lisp_gpe_fwd_entry_key_t key; + lisp_gpe_fwd_entry_t *lfe; + + lfe = find_fwd_entry (lgm, a, &key); + + if (NULL != lfe) + /* don't support updates */ + return VNET_API_ERROR_INVALID_VALUE; + + pool_get (lgm->lisp_fwd_entry_pool, lfe); + clib_memset (lfe, 0, sizeof (*lfe)); + lfe->key = clib_mem_alloc (sizeof (key)); + memcpy (lfe->key, &key, sizeof (key)); + + hash_set_mem (lgm->lisp_gpe_fwd_entries, lfe->key, + lfe - lgm->lisp_fwd_entry_pool); + a->fwd_entry_index = lfe - lgm->lisp_fwd_entry_pool; + + lfe->type = (a->is_negative ? + LISP_GPE_FWD_ENTRY_TYPE_NEGATIVE : + LISP_GPE_FWD_ENTRY_TYPE_NORMAL); + lfe->tenant = 0; + + if (LISP_GPE_FWD_ENTRY_TYPE_NEGATIVE != lfe->type) + { + fib_route_path_t *rpaths; + + /* + * Make the sorted array of LISP paths with their resp. adjacency + */ + lisp_gpe_fwd_entry_mk_paths (lfe, a); + + /* + * From the LISP paths, construct a FIB path list that will + * contribute a load-balance. + */ + rpaths = lisp_gpe_mk_fib_paths (lfe->paths); + + lfe->nsh.path_list_index = + fib_path_list_create (FIB_PATH_LIST_FLAG_NONE, rpaths); + + /* + * become a child of the path-list so we receive updates when + * its forwarding state changes. this includes an implicit lock. + */ + lfe->nsh.child_index = + fib_path_list_child_add (lfe->nsh.path_list_index, + FIB_NODE_TYPE_LISP_GPE_FWD_ENTRY, + lfe - lgm->lisp_fwd_entry_pool); + } + else + { + lfe->action = a->action; + } + + lisp_gpe_nsh_update_fwding (lfe); + + return 0; +} + +/** + * @brief conver from the embedded fib_node_t struct to the LSIP entry + */ +static lisp_gpe_fwd_entry_t * +lisp_gpe_fwd_entry_from_fib_node (fib_node_t * node) +{ + return ((lisp_gpe_fwd_entry_t *) (((char *) node) - + STRUCT_OFFSET_OF (lisp_gpe_fwd_entry_t, + node))); +} + +/** + * @brief Function invoked during a backwalk of the FIB graph + */ +static fib_node_back_walk_rc_t +lisp_gpe_fib_node_back_walk (fib_node_t * node, + fib_node_back_walk_ctx_t * ctx) +{ + lisp_gpe_fwd_entry_t *lfe = lisp_gpe_fwd_entry_from_fib_node (node); + + if (fid_addr_type (&lfe->key->rmt) == FID_ADDR_MAC) + lisp_gpe_l2_update_fwding (lfe); + else if (fid_addr_type (&lfe->key->rmt) == FID_ADDR_NSH) + lisp_gpe_nsh_update_fwding (lfe); + + return (FIB_NODE_BACK_WALK_CONTINUE); +} + +/** + * @brief Get a fib_node_t struct from the index of a LISP fwd entry + */ +static fib_node_t * +lisp_gpe_fwd_entry_get_fib_node (fib_node_index_t index) +{ + lisp_gpe_main_t *lgm = &lisp_gpe_main; + lisp_gpe_fwd_entry_t *lfe; + + lfe = pool_elt_at_index (lgm->lisp_fwd_entry_pool, index); + + return (&(lfe->node)); +} + +/** + * @brief An indication from the graph that the last lock has gone + */ +static void +lisp_gpe_fwd_entry_fib_node_last_lock_gone (fib_node_t * node) +{ + /* We don't manage the locks of the LISP objects via the graph, since + * this object has no children. so this is a no-op. */ +} + +/** + * @brief Virtual function table to register with FIB for the LISP type + */ +const static fib_node_vft_t lisp_fwd_vft = { + .fnv_get = lisp_gpe_fwd_entry_get_fib_node, + .fnv_last_lock = lisp_gpe_fwd_entry_fib_node_last_lock_gone, + .fnv_back_walk = lisp_gpe_fib_node_back_walk, +}; + +/** + * @brief Forwarding entry create/remove dispatcher. + * + * Calls l2 or l3 forwarding entry add/del function based on input data. + * + * @param[in] a Forwarding entry parameters. + * @param[out] hw_if_indexp NOT USED + * + * @return 0 on success. + */ +int +vnet_lisp_gpe_add_del_fwd_entry (vnet_lisp_gpe_add_del_fwd_entry_args_t * a, + u32 * hw_if_indexp) +{ + lisp_gpe_main_t *lgm = &lisp_gpe_main; + u8 type; + + if (vnet_lisp_gpe_enable_disable_status () == 0) + { + clib_warning ("LISP is disabled!"); + return VNET_API_ERROR_LISP_DISABLED; + } + + type = gid_address_type (&a->rmt_eid); + switch (type) + { + case GID_ADDR_IP_PREFIX: + if (a->is_add) + return add_ip_fwd_entry (lgm, a); + else + return del_ip_fwd_entry (lgm, a); + break; + case GID_ADDR_MAC: + if (a->is_add) + return add_l2_fwd_entry (lgm, a); + else + return del_l2_fwd_entry (lgm, a); + case GID_ADDR_NSH: + if (a->is_add) + return add_nsh_fwd_entry (lgm, a); + else + return del_nsh_fwd_entry (lgm, a); + default: + clib_warning ("Forwarding entries for type %d not supported!", type); + return -1; + } +} + +int +vnet_lisp_flush_stats (void) +{ + lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main (); + vlib_combined_counter_main_t *cm = &lgm->counters; + u32 i; + + if (cm->counters == NULL) + return 0; + + for (i = 0; i < vlib_combined_counter_n_counters (cm); i++) + vlib_zero_combined_counter (cm, i); + + return 0; +} + +static void +lisp_del_adj_stats (lisp_gpe_main_t * lgm, u32 fwd_entry_index, u32 ti) +{ + hash_pair_t *hp; + lisp_stats_key_t key; + void *key_copy; + uword *p; + u8 *s; + + clib_memset (&key, 0, sizeof (key)); + key.fwd_entry_index = fwd_entry_index; + key.tunnel_index = ti; + + p = hash_get_mem (lgm->lisp_stats_index_by_key, &key); + if (p) + { + s = pool_elt_at_index (lgm->placeholder_stats_pool, p[0]); + hp = hash_get_pair (lgm->lisp_stats_index_by_key, &key); + key_copy = (void *) (hp->key); + hash_unset_mem (lgm->lisp_stats_index_by_key, &key); + clib_mem_free (key_copy); + pool_put (lgm->placeholder_stats_pool, s); + } +} + +void +vnet_lisp_gpe_del_fwd_counters (vnet_lisp_gpe_add_del_fwd_entry_args_t * a, + u32 fwd_entry_index) +{ + lisp_gpe_main_t *lgm = &lisp_gpe_main; + lisp_gpe_fwd_entry_key_t fe_key; + lisp_gpe_fwd_entry_t *lfe; + lisp_fwd_path_t *path; + const lisp_gpe_adjacency_t *ladj; + + lfe = find_fwd_entry (lgm, a, &fe_key); + if (!lfe) + return; + + if (LISP_GPE_FWD_ENTRY_TYPE_NORMAL != lfe->type) + return; + + vec_foreach (path, lfe->paths) + { + ladj = lisp_gpe_adjacency_get (path->lisp_adj); + lisp_del_adj_stats (lgm, fwd_entry_index, ladj->tunnel_index); + } +} + +/** + * @brief Flush all the forwrding entries + */ +void +vnet_lisp_gpe_fwd_entry_flush (void) +{ + lisp_gpe_main_t *lgm = &lisp_gpe_main; + lisp_gpe_fwd_entry_t *lfe; + + /* *INDENT-OFF* */ + pool_foreach (lfe, lgm->lisp_fwd_entry_pool, + ({ + switch (fid_addr_type(&lfe->key->rmt)) + { + case FID_ADDR_MAC: + del_l2_fwd_entry_i (lgm, lfe); + break; + case FID_ADDR_IP_PREF: + del_ip_fwd_entry_i (lgm, lfe); + break; + case FID_ADDR_NSH: + del_nsh_fwd_entry_i (lgm, lfe); + break; + } + })); + /* *INDENT-ON* */ +} + +static u8 * +format_lisp_fwd_path (u8 * s, va_list * ap) +{ + lisp_fwd_path_t *lfp = va_arg (*ap, lisp_fwd_path_t *); + + s = format (s, "weight:%d ", lfp->weight); + s = format (s, "adj:[%U]\n", + format_lisp_gpe_adjacency, + lisp_gpe_adjacency_get (lfp->lisp_adj), + LISP_GPE_ADJ_FORMAT_FLAG_NONE); + + return (s); +} + +typedef enum lisp_gpe_fwd_entry_format_flag_t_ +{ + LISP_GPE_FWD_ENTRY_FORMAT_NONE = (0 << 0), + LISP_GPE_FWD_ENTRY_FORMAT_DETAIL = (1 << 1), +} lisp_gpe_fwd_entry_format_flag_t; + + +static u8 * +format_lisp_gpe_fwd_entry (u8 * s, va_list * ap) +{ + lisp_gpe_main_t *lgm = &lisp_gpe_main; + lisp_gpe_fwd_entry_t *lfe = va_arg (*ap, lisp_gpe_fwd_entry_t *); + lisp_gpe_fwd_entry_format_flag_t flags = + va_arg (*ap, lisp_gpe_fwd_entry_format_flag_t); + + s = format (s, "VNI:%d VRF:%d EID: %U -> %U [index:%d]", + lfe->key->vni, lfe->eid_table_id, + format_fid_address, &lfe->key->lcl, + format_fid_address, &lfe->key->rmt, + lfe - lgm->lisp_fwd_entry_pool); + + if (LISP_GPE_FWD_ENTRY_TYPE_NEGATIVE == lfe->type) + { + s = format (s, "\n Negative - action:%U", + format_negative_mapping_action, lfe->action); + } + else + { + lisp_fwd_path_t *path; + + s = format (s, "\n via:"); + vec_foreach (path, lfe->paths) + { + s = format (s, "\n %U", format_lisp_fwd_path, path); + } + } + + if (flags & LISP_GPE_FWD_ENTRY_FORMAT_DETAIL) + { + switch (fid_addr_type (&lfe->key->rmt)) + { + case FID_ADDR_MAC: + s = format (s, " fib-path-list:%d\n", lfe->l2.path_list_index); + s = format (s, " dpo:%U\n", format_dpo_id, &lfe->l2.dpo, 0); + break; + case FID_ADDR_NSH: + s = format (s, " fib-path-list:%d\n", lfe->nsh.path_list_index); + s = format (s, " dpo:%U\n", format_dpo_id, &lfe->nsh.dpo, 0); + break; + case FID_ADDR_IP_PREF: + break; + } + } + + return (s); +} + +static clib_error_t * +lisp_gpe_fwd_entry_show (vlib_main_t * vm, + unformat_input_t * input, vlib_cli_command_t * cmd) +{ + lisp_gpe_main_t *lgm = &lisp_gpe_main; + lisp_gpe_fwd_entry_t *lfe; + index_t index; + u32 vni = ~0; + + if (unformat (input, "vni %d", &vni)) + ; + else if (unformat (input, "%d", &index)) + { + if (!pool_is_free_index (lgm->lisp_fwd_entry_pool, index)) + { + lfe = pool_elt_at_index (lgm->lisp_fwd_entry_pool, index); + + vlib_cli_output (vm, "[%d@] %U", + index, + format_lisp_gpe_fwd_entry, lfe, + LISP_GPE_FWD_ENTRY_FORMAT_DETAIL); + } + else + { + vlib_cli_output (vm, "entry %d invalid", index); + } + + return (NULL); + } + + /* *INDENT-OFF* */ + pool_foreach (lfe, lgm->lisp_fwd_entry_pool, + ({ + if ((vni == ~0) || + (lfe->key->vni == vni)) + vlib_cli_output (vm, "%U", format_lisp_gpe_fwd_entry, lfe, + LISP_GPE_FWD_ENTRY_FORMAT_NONE); + })); + /* *INDENT-ON* */ + + return (NULL); +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (lisp_gpe_fwd_entry_show_command, static) = { + .path = "show gpe entry", + .short_help = "show gpe entry vni vrf [leid ] reid ", + .function = lisp_gpe_fwd_entry_show, +}; +/* *INDENT-ON* */ + +clib_error_t * +lisp_gpe_fwd_entry_init (vlib_main_t * vm) +{ + lisp_gpe_main_t *lgm = &lisp_gpe_main; + clib_error_t *error = NULL; + + if ((error = vlib_call_init_function (vm, lisp_cp_dpo_module_init))) + return (error); + + l2_fib_init (lgm); + nsh_fib_init (lgm); + + fib_node_register_type (FIB_NODE_TYPE_LISP_GPE_FWD_ENTRY, &lisp_fwd_vft); + + return (error); +} + +u32 * +vnet_lisp_gpe_get_fwd_entry_vnis (void) +{ + lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main (); + lisp_gpe_fwd_entry_t *lfe; + u32 *vnis = 0; + + /* *INDENT-OFF* */ + pool_foreach (lfe, lgm->lisp_fwd_entry_pool, + ({ + hash_set (vnis, lfe->key->vni, 0); + })); + /* *INDENT-ON* */ + + return vnis; +} + +lisp_api_gpe_fwd_entry_t * +vnet_lisp_gpe_fwd_entries_get_by_vni (u32 vni) +{ + lisp_gpe_main_t *lgm = &lisp_gpe_main; + lisp_gpe_fwd_entry_t *lfe; + lisp_api_gpe_fwd_entry_t *entries = 0, e; + + /* *INDENT-OFF* */ + pool_foreach (lfe, lgm->lisp_fwd_entry_pool, + ({ + if (lfe->key->vni == vni) + { + clib_memset (&e, 0, sizeof (e)); + e.dp_table = lfe->eid_table_id; + e.vni = lfe->key->vni; + if (lfe->type == LISP_GPE_FWD_ENTRY_TYPE_NEGATIVE) + e.action = lfe->action; + e.fwd_entry_index = lfe - lgm->lisp_fwd_entry_pool; + memcpy (&e.reid, &lfe->key->rmt, sizeof (e.reid)); + memcpy (&e.leid, &lfe->key->lcl, sizeof (e.leid)); + vec_add1 (entries, e); + } + })); + /* *INDENT-ON* */ + + return entries; +} + +int +vnet_lisp_gpe_get_fwd_stats (vnet_lisp_gpe_add_del_fwd_entry_args_t * a, + vlib_counter_t * c) +{ + lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main (); + lisp_gpe_fwd_entry_t *lfe; + lisp_gpe_fwd_entry_key_t unused; + + lfe = find_fwd_entry (lgm, a, &unused); + if (NULL == lfe) + return -1; + + if (LISP_GPE_FWD_ENTRY_TYPE_NEGATIVE == lfe->type) + return -1; + + if (~0 == lfe->dpoi_index) + return -1; + + vlib_get_combined_counter (&load_balance_main.lbm_to_counters, + lfe->dpoi_index, c); + return 0; +} + +VLIB_INIT_FUNCTION (lisp_gpe_fwd_entry_init); + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/lisp/lisp-gpe/lisp_gpe_fwd_entry.h b/src/plugins/lisp/lisp-gpe/lisp_gpe_fwd_entry.h new file mode 100644 index 00000000000..a170787f5b2 --- /dev/null +++ b/src/plugins/lisp/lisp-gpe/lisp_gpe_fwd_entry.h @@ -0,0 +1,240 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file + * @brief LISP-GPE definitions. + */ + +#ifndef __LISP_GPE_FWD_ENTRY_H__ +#define __LISP_GPE_FWD_ENTRY_H__ + +#include + +/** + * @brief A path on which to forward lisp traffic + */ +typedef struct lisp_fwd_path_t_ +{ + /** + * The adjacency constructed for the locator pair + */ + index_t lisp_adj; + + /** + * Priority. Only the paths with the best priority will be installed in FIB + */ + u8 priority; + + /** + * [UE]CMP weigt for the path + */ + u8 weight; + +} lisp_fwd_path_t; + +/** + * @brief A Forwarding entry can be 'normal' or 'negative' + * Negative implies we deliberately want to add a FIB entry for an EID + * that results in 'special' behaviour determined by an 'action'. + * @normal means send it down some tunnels. + */ +typedef enum lisp_gpe_fwd_entry_type_t_ +{ + LISP_GPE_FWD_ENTRY_TYPE_NORMAL, + LISP_GPE_FWD_ENTRY_TYPE_NEGATIVE, +} lisp_gpe_fwd_entry_type_t; + + +/** + * LISP-GPE fwd entry key + */ +typedef struct lisp_gpe_fwd_entry_key_t_ +{ + dp_address_t rmt; + dp_address_t lcl; + u32 vni; +} lisp_gpe_fwd_entry_key_t; + +/** + * @brief A LISP Forwarding Entry + * + * A forwarding entry is from a locai EID to a remote EID over a set of rloc pairs + */ +typedef struct lisp_gpe_fwd_entry_t_ +{ + /** + * Follows src/dst or dst only forwarding policy + */ + u8 is_src_dst; + + /** + * This object joins the FIB control plane graph to receive updates to + * for changes to the graph. + */ + fib_node_t node; + + /** + * The Entry's key: {lEID,rEID,vni} + */ + lisp_gpe_fwd_entry_key_t *key; + + /** + * The forwarding entry type + */ + lisp_gpe_fwd_entry_type_t type; + + /** + * The tenant the entry belongs to + */ + u32 tenant; + + /** + * The VRF (in the case of L3) or Bridge-Domain (for L2) index + */ + union + { + /** + * Fields relevant to an L2 entry + */ + struct + { + /** + * The VRF ID + */ + u32 eid_table_id; + + /** + * The FIB index for the overlay, i.e. the FIB in which the EIDs + * are present + */ + u32 eid_fib_index; + /** + * The SRC-FIB index for created for anding source-route entries + */ + u32 src_fib_index; + }; + /** + * Fields relevant to an L2 entry + */ + struct + { + /** + * The Bridge-Domain (for L2) index + */ + u32 eid_bd_id; + + /** + * The Bridge-domain index for the overlay EIDs + */ + u32 eid_bd_index; + + /** + * The path-list created for the forwarding + */ + fib_node_index_t path_list_index; + + /** + * Child index of this entry on the path-list + */ + u32 child_index; + + /** + * The DPO used to forward + */ + dpo_id_t dpo; + } l2; + + /** + * Fields relevant to an NSH entry + */ + struct + { + /** + * The path-list created for the forwarding + */ + fib_node_index_t path_list_index; + + /** + * Child index of this entry on the path-list + */ + u32 child_index; + + /** + * The DPO contributed by NSH + */ + dpo_id_t dpo; + + /** + * The DPO used for forwarding. Obtained after stacking tx node + * onto lb choice + */ + dpo_id_t choice; + } nsh; + }; + + union + { + /** + * @brief When the type is 'normal' + * The RLOC pair that form the route's paths. i.e. where to send + * packets for this route. + */ + lisp_fwd_path_t *paths; + + /** + * @brief When the type is negative. The action to take. + */ + negative_fwd_actions_e action; + }; + + /** + * used for getting load balance statistics + */ + index_t dpoi_index; + +} lisp_gpe_fwd_entry_t; + +extern int +vnet_lisp_gpe_add_del_fwd_entry (vnet_lisp_gpe_add_del_fwd_entry_args_t * a, + u32 * hw_if_indexp); + +extern void vnet_lisp_gpe_fwd_entry_flush (void); + +extern u32 lisp_l2_fib_lookup (lisp_gpe_main_t * lgm, + u16 bd_index, u8 src_mac[8], u8 dst_mac[8]); + +extern const dpo_id_t *lisp_nsh_fib_lookup (lisp_gpe_main_t * lgm, + u32 spi_si); +extern void +vnet_lisp_gpe_del_fwd_counters (vnet_lisp_gpe_add_del_fwd_entry_args_t * a, + u32 fwd_entry_index); +extern void +vnet_lisp_gpe_add_fwd_counters (vnet_lisp_gpe_add_del_fwd_entry_args_t * a, + u32 fwd_entry_index); +extern u32 *vnet_lisp_gpe_get_fwd_entry_vnis (void); + +int +vnet_lisp_gpe_get_fwd_stats (vnet_lisp_gpe_add_del_fwd_entry_args_t * a, + vlib_counter_t * c); + +#endif + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/lisp/lisp-gpe/lisp_gpe_packet.h b/src/plugins/lisp/lisp-gpe/lisp_gpe_packet.h new file mode 100644 index 00000000000..62ac9bd7015 --- /dev/null +++ b/src/plugins/lisp/lisp-gpe/lisp_gpe_packet.h @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file + * @brief LISP-GPE packet header structure + * + */ + +#ifndef included_lisp_gpe_packet_h +#define included_lisp_gpe_packet_h + +/* + * From draft-lewis-lisp-gpe-02.txt + * + * 0 1 2 3 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * |N|L|E|V|I|P|R|O|Ver| Reserved | Next Protocol | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Instance ID/Locator-Status-Bits | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * + * N: The N-bit is the nonce-present bit. When this bit is set to 1, + * the low-order 24 bits of the first 32 bits of the LISP header + * contain a Nonce. See Section 6.3.1 for details. Both N- and + * V-bits MUST NOT be set in the same packet. If they are, a + * decapsulating ETR MUST treat the 'Nonce/Map-Version' field as + * having a Nonce value present. + * + * L: The L-bit is the 'Locator-Status-Bits' field enabled bit. When + * this bit is set to 1, the Locator-Status-Bits in the second + * 32 bits of the LISP header are in use. + * + * E: The E-bit is the echo-nonce-request bit. This bit MUST be ignored + * and has no meaning when the N-bit is set to 0. When the N-bit is + * set to 1 and this bit is set to 1, an ITR is requesting that the + * nonce value in the 'Nonce' field be echoed back in LISP- + * encapsulated packets when the ITR is also an ETR. See + * Section 6.3.1 for details. + * + * V: The V-bit is the Map-Version present bit. When this bit is set to + * 1, the N-bit MUST be 0. Refer to Section 6.6.3 for more details. + * + * I: The I-bit is the Instance ID bit. See Section 5.5 for more + * details. When this bit is set to 1, the 'Locator-Status-Bits' + * field is reduced to 8 bits and the high-order 24 bits are used as + * an Instance ID. If the L-bit is set to 0, then the low-order + * 8 bits are transmitted as zero and ignored on receipt. + * + * P Bit: Flag bit 5 is defined as the Next Protocol bit. The P bit + * MUST be set to 1 to indicate the presence of the 8 bit next + * protocol field. + * + * P = 0 indicates that the payload MUST conform to LISP as defined + * in [RFC6830]. + * + * Flag bit 5 was chosen as the P bit because this flag bit is + * currently unallocated in LISP [RFC6830]. + * + * O: Flag bit 7 is defined as the O bit. When the O bit is set to 1, the + * packet is an OAM packet and OAM processing MUST occur. The OAM + * protocol details are out of scope for this document. As with the + * P-bit, bit 7 is currently a reserved flag in [RFC6830]. + * + * Next Protocol Field: The lower 8 bits of the first word are used to + * carry a next protocol. This next protocol field contains the + * protocol of the encapsulated payload packet. + * + * LISP [RFC6830] uses the lower 16 bits of the first word for either + * a nonce, an echo-nonce ([RFC6830]) or to support map-versioning + * ([RFC6834]). These are all optional capabilities that are + * indicated by setting the N, E, and the V bit respectively. + * + * To maintain the desired data plane compatibility, when the P bit + * is set, the N, E, and V bits MUST be set to zero. + * + * A new protocol registry will be requested from IANA for the Next + * Protocol field. This draft defines the following Next Protocol + * values: + * + * 0x1 : IPv4 + * 0x2 : IPv6 + * 0x3 : Ethernet + * 0x4: Network Service Header + */ + +/** LISP-GPE header */ +typedef struct +{ + u8 flags; + u8 ver_res; + u8 res; + u8 next_protocol; + u32 iid; +} lisp_gpe_header_t; + +#define foreach_lisp_gpe_flag_bit \ +_(N, 0x80) \ +_(L, 0x40) \ +_(E, 0x20) \ +_(V, 0x10) \ +_(I, 0x08) \ +_(P, 0x04) \ +_(O, 0x01) + +typedef enum +{ +#define _(n,v) LISP_GPE_FLAGS_##n = v, + foreach_lisp_gpe_flag_bit +#undef _ +} vnet_lisp_gpe_flag_bit_t; + +#define LISP_GPE_VERSION 0x0 + +#define LISP_GPE_NEXT_PROTOCOL_IP4 0x1 +#define LISP_GPE_NEXT_PROTOCOL_IP6 0x2 +#define LISP_GPE_NEXT_PROTOCOL_ETHERNET 0x3 +#define LISP_GPE_NEXT_PROTOCOL_NSH 0x4 + +typedef enum +{ + LISP_GPE_NEXT_PROTO_IP4 = 1, + LISP_GPE_NEXT_PROTO_IP6, + LISP_GPE_NEXT_PROTO_ETHERNET, + LISP_GPE_NEXT_PROTO_NSH, + LISP_GPE_NEXT_PROTOS +} lisp_gpe_next_protocol_e; + +#endif /* included_lisp_gpe_packet_h */ + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/lisp/lisp-gpe/lisp_gpe_sub_interface.c b/src/plugins/lisp/lisp-gpe/lisp_gpe_sub_interface.c new file mode 100644 index 00000000000..b84c76f0103 --- /dev/null +++ b/src/plugins/lisp/lisp-gpe/lisp_gpe_sub_interface.c @@ -0,0 +1,286 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file + * @brief LISP sub-interfaces. + * + */ +#include +#include +#include +#include + +/** + * @brief Pool of all l3-sub-interfaces + */ +static lisp_gpe_sub_interface_t *lisp_gpe_sub_interface_pool; + +/** + * A DB of all LISP L3 sub-interfaces. The key is:{VNI,l-RLOC} + */ +static uword *lisp_gpe_sub_interfaces; + +/** + * A DB of all VNET L3 sub-interfaces. The key is:{VNI,l-RLOC} + * Used in the data-plane for interface lookup on decap. + */ +uword *lisp_gpe_sub_interfaces_sw_if_index; + +/** + * The next available sub-interface ID. FIXME + */ +static u32 lisp_gpe_sub_interface_id; + + +static index_t +lisp_gpe_sub_interface_db_find (const ip_address_t * lrloc, u32 vni) +{ + uword *p; + + lisp_gpe_sub_interface_key_t key; + + clib_memset (&key, 0, sizeof (key)); + ip_address_copy (&key.local_rloc, lrloc); + key.vni = vni; + p = hash_get_mem (lisp_gpe_sub_interfaces, &key); + + if (NULL == p) + return (INDEX_INVALID); + else + return (p[0]); +} + +static void +lisp_gpe_sub_interface_db_insert (const lisp_gpe_sub_interface_t * l3s) +{ + hash_set_mem (lisp_gpe_sub_interfaces, + l3s->key, l3s - lisp_gpe_sub_interface_pool); + hash_set_mem (lisp_gpe_sub_interfaces_sw_if_index, + l3s->key, l3s->sw_if_index); +} + +static void +lisp_gpe_sub_interface_db_remove (const lisp_gpe_sub_interface_t * l3s) +{ + hash_unset_mem (lisp_gpe_sub_interfaces, l3s->key); + hash_unset_mem (lisp_gpe_sub_interfaces_sw_if_index, l3s->key); +} + +lisp_gpe_sub_interface_t * +lisp_gpe_sub_interface_get_i (index_t l3si) +{ + return (pool_elt_at_index (lisp_gpe_sub_interface_pool, l3si)); +} + +static void +lisp_gpe_sub_interface_set_table (u32 sw_if_index, u32 table_id) +{ + fib_node_index_t fib_index; + + fib_index = fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP4, table_id, + FIB_SOURCE_LISP); + ASSERT (FIB_NODE_INDEX_INVALID != fib_index); + + vec_validate (ip4_main.fib_index_by_sw_if_index, sw_if_index); + ip4_main.fib_index_by_sw_if_index[sw_if_index] = fib_index; + + fib_index = fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP6, table_id, + FIB_SOURCE_LISP); + ASSERT (FIB_NODE_INDEX_INVALID != fib_index); + + vec_validate (ip6_main.fib_index_by_sw_if_index, sw_if_index); + ip6_main.fib_index_by_sw_if_index[sw_if_index] = fib_index; +} + +static void +lisp_gpe_sub_interface_unset_table (u32 sw_if_index, u32 table_id) +{ + fib_table_unlock (ip4_main.fib_index_by_sw_if_index[sw_if_index], + FIB_PROTOCOL_IP4, FIB_SOURCE_LISP); + ip4_main.fib_index_by_sw_if_index[sw_if_index] = 0; + ip4_sw_interface_enable_disable (sw_if_index, 0); + + fib_table_unlock (ip6_main.fib_index_by_sw_if_index[sw_if_index], + FIB_PROTOCOL_IP6, FIB_SOURCE_LISP); + ip6_main.fib_index_by_sw_if_index[sw_if_index] = 0; + ip6_sw_interface_enable_disable (sw_if_index, 0); +} + +index_t +lisp_gpe_sub_interface_find_or_create_and_lock (const ip_address_t * lrloc, + u32 overlay_table_id, u32 vni) +{ + lisp_gpe_sub_interface_t *l3s; + index_t l3si; + + l3si = lisp_gpe_sub_interface_db_find (lrloc, vni); + + if (INDEX_INVALID == l3si) + { + u32 main_sw_if_index, sub_sw_if_index; + + /* + * find the main interface from the VNI + */ + main_sw_if_index = + lisp_gpe_tenant_l3_iface_add_or_lock (vni, overlay_table_id, + 1 /* with_default_route */ ); + + vnet_sw_interface_t sub_itf_template = { + .type = VNET_SW_INTERFACE_TYPE_SUB, + .flood_class = VNET_FLOOD_CLASS_NORMAL, + .sup_sw_if_index = main_sw_if_index, + .sub.id = lisp_gpe_sub_interface_id++, + }; + + if (NULL != vnet_create_sw_interface (vnet_get_main (), + &sub_itf_template, + &sub_sw_if_index)) + return (INDEX_INVALID); + + pool_get (lisp_gpe_sub_interface_pool, l3s); + clib_memset (l3s, 0, sizeof (*l3s)); + l3s->key = clib_mem_alloc (sizeof (*l3s->key)); + clib_memset (l3s->key, 0, sizeof (*l3s->key)); + + ip_address_copy (&l3s->key->local_rloc, lrloc); + l3s->key->vni = vni; + l3s->main_sw_if_index = main_sw_if_index; + l3s->sw_if_index = sub_sw_if_index; + l3s->eid_table_id = overlay_table_id; + + l3si = (l3s - lisp_gpe_sub_interface_pool); + + // FIXME. enable When we get an adj + ip6_sw_interface_enable_disable (l3s->sw_if_index, 1); + ip4_sw_interface_enable_disable (l3s->sw_if_index, 1); + + vnet_sw_interface_set_flags (vnet_get_main (), + l3s->sw_if_index, + VNET_SW_INTERFACE_FLAG_ADMIN_UP); + + lisp_gpe_sub_interface_db_insert (l3s); + } + else + { + l3s = lisp_gpe_sub_interface_get_i (l3si); + l3s->eid_table_id = overlay_table_id; + } + + lisp_gpe_sub_interface_set_table (l3s->sw_if_index, l3s->eid_table_id); + l3s->locks++; + + return (l3si); +} + +void +lisp_gpe_sub_interface_unlock (index_t l3si) +{ + lisp_gpe_sub_interface_t *l3s; + + l3s = lisp_gpe_sub_interface_get_i (l3si); + + ASSERT (0 != l3s->locks); + l3s->locks--; + + if (0 == l3s->locks) + { + lisp_gpe_sub_interface_unset_table (l3s->sw_if_index, + l3s->eid_table_id); + + lisp_gpe_tenant_l3_iface_unlock (l3s->key->vni); + vnet_sw_interface_set_flags (vnet_get_main (), l3s->sw_if_index, 0); + vnet_delete_sub_interface (l3s->sw_if_index); + + lisp_gpe_sub_interface_db_remove (l3s); + + clib_mem_free (l3s->key); + pool_put (lisp_gpe_sub_interface_pool, l3s); + } +} + +const lisp_gpe_sub_interface_t * +lisp_gpe_sub_interface_get (index_t l3si) +{ + return (lisp_gpe_sub_interface_get_i (l3si)); +} + +u8 * +format_lisp_gpe_sub_interface (u8 * s, va_list * ap) +{ + lisp_gpe_sub_interface_t *l3s = va_arg (*ap, lisp_gpe_sub_interface_t *); + vnet_main_t *vnm = vnet_get_main (); + + s = format (s, "%-16U", + format_vnet_sw_interface_name, + vnm, vnet_get_sw_interface (vnm, l3s->sw_if_index)); + s = format (s, "%=8d", l3s->key->vni); + s = format (s, "%=15d", l3s->sw_if_index); + s = format (s, "%U", format_ip_address, &l3s->key->local_rloc); + + return (s); +} + +/** CLI command to show LISP-GPE interfaces. */ +static clib_error_t * +lisp_gpe_sub_interface_show (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + lisp_gpe_sub_interface_t *l3s; + + vlib_cli_output (vm, "%-16s%=8s%=15s%s", "Name", "VNI", "sw_if_index", + "local RLOC"); + + /* *INDENT-OFF* */ + pool_foreach (l3s, lisp_gpe_sub_interface_pool, + ({ + vlib_cli_output (vm, "%U", format_lisp_gpe_sub_interface, l3s); + })); + /* *INDENT-ON* */ + + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (lisp_gpe_sub_interface_command) = { + .path = "show gpe sub-interface", + .short_help = "show gpe sub-interface", + .function = lisp_gpe_sub_interface_show, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_gpe_sub_interface_module_init (vlib_main_t * vm) +{ + lisp_gpe_sub_interfaces = + hash_create_mem (0, + sizeof (lisp_gpe_sub_interface_key_t), sizeof (uword)); + lisp_gpe_sub_interfaces_sw_if_index = + hash_create_mem (0, + sizeof (lisp_gpe_sub_interface_key_t), sizeof (uword)); + + return (NULL); +} + +VLIB_INIT_FUNCTION (lisp_gpe_sub_interface_module_init); + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/lisp/lisp-gpe/lisp_gpe_sub_interface.h b/src/plugins/lisp/lisp-gpe/lisp_gpe_sub_interface.h new file mode 100644 index 00000000000..c8b447a65dc --- /dev/null +++ b/src/plugins/lisp/lisp-gpe/lisp_gpe_sub_interface.h @@ -0,0 +1,157 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file + * @brief LISP sub-interfaces. + * + */ + +#ifndef __LISP_GPE_SUB_INTERFACE_H__ +#define __LISP_GPE_SUB_INTERFACE_H__ + +#include + +/** + * A Key for lookup in the L£ sub-interface DB + */ +typedef struct lisp_gpe_sub_interface_key_t_ +{ + /** + * The local-RLOC. This is the interface's 'source' address. + */ + ip_address_t local_rloc; + + /** + * The VNI. In network byte order! + */ + u32 vni; +} lisp_gpe_sub_interface_key_t; + +/** + * @brief A LISP L3 sub-interface + * + * A LISP sub-interface is a multi-access interface, whose local address is a + * single local-RLOC. Adjacencies that form on this sub-interface, represent + * remote RLOCs. + * This is analogous to an ethernet interface. + * As with all interface types it can only be present in one VRF, hence a + * LISP sub-interface is per-local-rloc and per-VNI. + */ +typedef struct lisp_gpe_sub_interface_t_ +{ + /** + * The interface's key inthe DB; rloc & vni; + * The key is allocated from the heap so it can be used in the hash-table. + * if it's part of the object, then it is subjet to realloc, which no-worky. + */ + lisp_gpe_sub_interface_key_t *key; + + /** + * The Table-ID in the overlay that this interface is bound to. + */ + u32 eid_table_id; + + /** + * A reference counting lock on the number of users of this interface. + * When this count drops to 0 the interface is deleted. + */ + u32 locks; + + /** + * The SW if index assigned to this sub-interface + */ + u32 sw_if_index; + + /** + * The SW IF index assigned to the main interface of which this is a sub. + */ + u32 main_sw_if_index; +} lisp_gpe_sub_interface_t; + +extern index_t lisp_gpe_sub_interface_find_or_create_and_lock (const + ip_address_t * + lrloc, + u32 + eid_table_id, + u32 vni); + +extern u8 *format_lisp_gpe_sub_interface (u8 * s, va_list * ap); + +extern void lisp_gpe_sub_interface_unlock (index_t itf); + +extern const lisp_gpe_sub_interface_t *lisp_gpe_sub_interface_get (index_t + itf); + +/** + * A DB of all L3 sub-interfaces. The key is:{VNI,l-RLOC} + */ +extern uword *lisp_gpe_sub_interfaces_sw_if_index; + +/** + * @brief + * Get a VNET L3 interface matching the local-RLOC and VNI + * Called from the data-plane + */ +always_inline u32 +lisp_gpe_sub_interface_find_ip6 (const ip6_address_t * addr, u32 vni) +{ + lisp_gpe_sub_interface_key_t key; + const uword *p; + + ip_addr_v6 (&key.local_rloc).as_u64[0] = addr->as_u64[0]; + ip_addr_v6 (&key.local_rloc).as_u64[1] = addr->as_u64[1]; + ip_addr_version (&key.local_rloc) = AF_IP6; + key.vni = vni; + + p = hash_get_mem (&lisp_gpe_sub_interfaces_sw_if_index, &key); + + if (NULL != p) + return p[0]; + + return (INDEX_INVALID); +} + +/** + * @brief + * Get a VNET L3 interface matching the local-RLOC and VNI + * Called from the data-plane + */ +always_inline index_t +lisp_gpe_sub_interface_find_ip4 (const ip4_address_t * addr, u32 vni) +{ + lisp_gpe_sub_interface_key_t key; + const uword *p; + + ip_addr_v4 (&key.local_rloc).as_u32 = addr->as_u32; + key.local_rloc.version = AF_IP4; + key.vni = vni; + + p = hash_get_mem (&lisp_gpe_sub_interfaces_sw_if_index, &key); + + if (NULL != p) + return p[0]; + + return (INDEX_INVALID); +} + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ + +#endif diff --git a/src/plugins/lisp/lisp-gpe/lisp_gpe_tenant.c b/src/plugins/lisp/lisp-gpe/lisp_gpe_tenant.c new file mode 100644 index 00000000000..fb6aa1ac1d5 --- /dev/null +++ b/src/plugins/lisp/lisp-gpe/lisp_gpe_tenant.c @@ -0,0 +1,333 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +/** + * The pool of all tenants + */ +static lisp_gpe_tenant_t *lisp_gpe_tenant_pool; + +/** + * The hash table of all tenants: key:{VNI}. + */ +uword *lisp_gpe_tenant_db; + +static lisp_gpe_tenant_t * +lisp_gpe_tenant_find (u32 vni) +{ + uword *p; + + p = hash_get (lisp_gpe_tenant_db, vni); + + if (NULL == p) + return (NULL); + + return (pool_elt_at_index (lisp_gpe_tenant_pool, p[0])); +} + +static lisp_gpe_tenant_t * +lisp_gpe_tenant_find_or_create_i (u32 vni) +{ + lisp_gpe_tenant_t *lt; + + lt = lisp_gpe_tenant_find (vni); + + if (NULL == lt) + { + pool_get (lisp_gpe_tenant_pool, lt); + clib_memset (lt, 0, sizeof (*lt)); + + lt->lt_vni = vni; + lt->lt_table_id = ~0; + lt->lt_bd_id = ~0; + + hash_set (lisp_gpe_tenant_db, vni, lt - lisp_gpe_tenant_pool); + } + + return (lt); +} + +/** + * @brief Find or create a tenant for the given VNI + */ +u32 +lisp_gpe_tenant_find_or_create (u32 vni) +{ + lisp_gpe_tenant_t *lt; + + lt = lisp_gpe_tenant_find (vni); + + if (NULL == lt) + { + lt = lisp_gpe_tenant_find_or_create_i (vni); + } + + return (lt - lisp_gpe_tenant_pool); +} + +/** + * @brief If there are no more locks/users of te tenant, then delete it + */ +static void +lisp_gpe_tenant_delete_if_empty (lisp_gpe_tenant_t * lt) +{ + int i; + + for (i = 0; i < LISP_GPE_TENANT_LOCK_NUM; i++) + { + if (lt->lt_locks[i]) + return; + } + + hash_unset (lisp_gpe_tenant_db, lt->lt_vni); + pool_put (lisp_gpe_tenant_pool, lt); +} + +/** + * @brief Add/create and lock a new or find and lock the existing L3 + * interface for the tenant + * + * @paran vni The tenant's VNI + * @param table_id the Tenant's L3 table ID. + * @param with_default_route Install default route for the interface + * + * @return the SW IF index of the L3 interface + */ +u32 +lisp_gpe_tenant_l3_iface_add_or_lock (u32 vni, u32 table_id, + u8 with_default_route) +{ + lisp_gpe_tenant_t *lt; + + lt = lisp_gpe_tenant_find_or_create_i (vni); + + if (~0 == lt->lt_table_id) + lt->lt_table_id = table_id; + + ASSERT (lt->lt_table_id == table_id); + + if (0 == lt->lt_locks[LISP_GPE_TENANT_LOCK_L3_IFACE]) + { + /* create the l3 interface since there are currently no users of it */ + lt->lt_l3_sw_if_index = + lisp_gpe_add_l3_iface (&lisp_gpe_main, vni, table_id, + with_default_route); + } + + lt->lt_locks[LISP_GPE_TENANT_LOCK_L3_IFACE]++; + + return (lt->lt_l3_sw_if_index); +} + +/** + * @brief Release the lock held on the tenant's L3 interface + */ +void +lisp_gpe_tenant_l3_iface_unlock (u32 vni) +{ + lisp_gpe_tenant_t *lt; + + lt = lisp_gpe_tenant_find (vni); + + if (NULL == lt) + { + clib_warning ("No tenant for VNI %d", vni); + return; + } + + if (0 == lt->lt_locks[LISP_GPE_TENANT_LOCK_L3_IFACE]) + { + clib_warning ("No L3 interface for tenant VNI %d", vni); + return; + } + + lt->lt_locks[LISP_GPE_TENANT_LOCK_L3_IFACE]--; + + if (0 == lt->lt_locks[LISP_GPE_TENANT_LOCK_L3_IFACE]) + { + /* the last user has gone, so delete the l3 interface */ + lisp_gpe_del_l3_iface (&lisp_gpe_main, vni, lt->lt_table_id); + } + + /* + * If there are no more locks on any tenant managed resource, then + * this tenant is toast. + */ + lisp_gpe_tenant_delete_if_empty (lt); +} + +/** + * @brief Add/create and lock a new or find and lock the existing L2 + * interface for the tenant + * + * @paran vni The tenant's VNI + * @param table_id the Tenant's L2 Bridge Domain ID. + * + * @return the SW IF index of the L2 interface + */ +u32 +lisp_gpe_tenant_l2_iface_add_or_lock (u32 vni, u32 bd_id) +{ + lisp_gpe_tenant_t *lt; + + lt = lisp_gpe_tenant_find_or_create_i (vni); + + if (NULL == lt) + { + clib_warning ("No tenant for VNI %d", vni); + return ~0; + } + + if (~0 == lt->lt_bd_id) + lt->lt_bd_id = bd_id; + + ASSERT (lt->lt_bd_id == bd_id); + + if (0 == lt->lt_locks[LISP_GPE_TENANT_LOCK_L2_IFACE]) + { + /* create the l2 interface since there are currently no users of it */ + lt->lt_l2_sw_if_index = + lisp_gpe_add_l2_iface (&lisp_gpe_main, vni, bd_id); + } + + lt->lt_locks[LISP_GPE_TENANT_LOCK_L2_IFACE]++; + + return (lt->lt_l2_sw_if_index); +} + +/** + * @brief Release the lock held on the tenant's L3 interface + */ +void +lisp_gpe_tenant_l2_iface_unlock (u32 vni) +{ + lisp_gpe_tenant_t *lt; + + lt = lisp_gpe_tenant_find (vni); + + if (NULL == lt) + { + clib_warning ("No tenant for VNI %d", vni); + return; + } + + if (0 == lt->lt_locks[LISP_GPE_TENANT_LOCK_L2_IFACE]) + { + clib_warning ("No L2 interface for tenant VNI %d", vni); + return; + } + + lt->lt_locks[LISP_GPE_TENANT_LOCK_L2_IFACE]--; + + if (0 == lt->lt_locks[LISP_GPE_TENANT_LOCK_L2_IFACE]) + { + /* the last user has gone, so delete the l2 interface */ + lisp_gpe_del_l2_iface (&lisp_gpe_main, vni, lt->lt_bd_id); + } + + /* + * If there are no more locks on any tenant managed resource, then + * this tenant is toast. + */ + lisp_gpe_tenant_delete_if_empty (lt); +} + +/** + * @brief get a const pointer to the tenant object + */ +const lisp_gpe_tenant_t * +lisp_gpe_tenant_get (u32 index) +{ + return (pool_elt_at_index (lisp_gpe_tenant_pool, index)); +} + +/** + * @brief Flush/delete ALL the tenants + */ +void +lisp_gpe_tenant_flush (void) +{ + lisp_gpe_tenant_t *lt; + + /* *INDENT-OFF* */ + pool_foreach(lt, lisp_gpe_tenant_pool, + ({ + lisp_gpe_tenant_l2_iface_unlock(lt->lt_vni); + lisp_gpe_tenant_l3_iface_unlock(lt->lt_vni); + })); + /* *INDENT-ON* */ +} + +/** + * @brief Show/display one tenant + */ +static u8 * +format_lisp_gpe_tenant (u8 * s, va_list * ap) +{ + const lisp_gpe_tenant_t *lt = va_arg (*ap, lisp_gpe_tenant_t *); + + s = format (s, "VNI:%d ", lt->lt_vni); + + if (lt->lt_table_id != ~0) + { + s = format (s, "VRF:%d ", lt->lt_table_id); + s = format (s, "L3-SW-IF:%d ", lt->lt_l3_sw_if_index); + } + + if (lt->lt_bd_id != ~0) + { + s = format (s, "BD-ID:%d ", lt->lt_bd_id); + s = format (s, "L2-SW-IF:%d ", lt->lt_l2_sw_if_index); + } + + return (s); +} + +/** + * @brief CLI command to show LISP-GPE tenant. + */ +static clib_error_t * +lisp_gpe_tenant_show (vlib_main_t * vm, + unformat_input_t * input, vlib_cli_command_t * cmd) +{ + lisp_gpe_tenant_t *lt; + + /* *INDENT-OFF* */ + pool_foreach (lt, lisp_gpe_tenant_pool, + ({ + vlib_cli_output (vm, "%U", format_lisp_gpe_tenant, lt); + })); + /* *INDENT-ON* */ + + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (lisp_gpe_tenant_command) = { + .path = "show gpe tenant", + .short_help = "show gpe tenant", + .function = lisp_gpe_tenant_show, +}; +/* *INDENT-ON* */ + + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/lisp/lisp-gpe/lisp_gpe_tenant.h b/src/plugins/lisp/lisp-gpe/lisp_gpe_tenant.h new file mode 100644 index 00000000000..35b6569d0ed --- /dev/null +++ b/src/plugins/lisp/lisp-gpe/lisp_gpe_tenant.h @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __LISP_GPE_TENANT_H__ +#define __LISP_GPE_TENANT_H__ + +#include + +/** + * Refernece counting lock types on the tenant. + * When all of these counters drop to zero, we no longer need the tenant. + */ +typedef enum lisp_gpe_tenant_lock_t_ +{ + LISP_GPE_TENANT_LOCK_L2_IFACE, + LISP_GPE_TENANT_LOCK_L3_IFACE, + LISP_GPE_TENANT_LOCK_NUM, +} lisp_gpe_tenant_lock_t; + +/** + * @brief Representation of the data associated with a LISP overlay tenant + * + * This object exists to manage the shared resources of the L2 and L3 interface + * of a given tenant. + */ +typedef struct lisp_gpe_tenant_t_ +{ + /** + * The VNI is the identifier of the tenant + */ + u32 lt_vni; + + /** + * The tenant can have both L2 and L3 services enabled. + */ + u32 lt_table_id; + u32 lt_bd_id; + + /** + * The number of locks on the tenant's L3 interface. + */ + u32 lt_locks[LISP_GPE_TENANT_LOCK_NUM]; + + /** + * The L3 SW interface index + */ + u32 lt_l3_sw_if_index; + + /** + * The L2 SW interface index + */ + u32 lt_l2_sw_if_index; + +} lisp_gpe_tenant_t; + +extern u32 lisp_gpe_tenant_find_or_create (u32 vni); + +extern u32 lisp_gpe_tenant_l3_iface_add_or_lock (u32 vni, u32 vrf, + u8 with_default_route); +extern void lisp_gpe_tenant_l3_iface_unlock (u32 vni); + +extern u32 lisp_gpe_tenant_l2_iface_add_or_lock (u32 vni, u32 vrf); +extern void lisp_gpe_tenant_l2_iface_unlock (u32 vni); + +extern const lisp_gpe_tenant_t *lisp_gpe_tenant_get (u32 index); + +extern void lisp_gpe_tenant_flush (void); + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ + +#endif diff --git a/src/plugins/lisp/lisp-gpe/lisp_gpe_test.c b/src/plugins/lisp/lisp-gpe/lisp_gpe_test.c new file mode 100644 index 00000000000..39f99492268 --- /dev/null +++ b/src/plugins/lisp/lisp-gpe/lisp_gpe_test.c @@ -0,0 +1,888 @@ +/* + * Copyright (c) 2015 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include +#include +#include + +/* define message IDs */ +#include +#include +#include + +typedef struct +{ + /* API message ID base */ + u16 msg_id_base; + vat_main_t *vat_main; + u32 ping_id; +} lisp_gpe_test_main_t; + +lisp_gpe_test_main_t lisp_gpe_test_main; + +#define __plugin_msg_base lisp_gpe_test_main.msg_id_base +#include + +/* Macro to finish up custom dump fns */ +#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) +#define FINISH \ + vec_add1 (s, 0); \ + vl_print (handle, (char *)s); \ + vec_free (s); \ + return handle; + +#define LISP_PING(_lm, mp_ping) \ + if (!(_lm)->ping_id) \ + (_lm)->ping_id = vl_msg_api_get_msg_index ((u8 *) (VL_API_CONTROL_PING_CRC)); \ + mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping)); \ + mp_ping->_vl_msg_id = htons ((_lm)->ping_id); \ + mp_ping->client_index = vam->my_client_index; \ + fformat (vam->ofp, "Sending ping id=%d\n", (_lm)->ping_id); \ + vam->result_ready = 0; \ + +typedef struct +{ + u32 spi; + u8 si; +} __attribute__ ((__packed__)) lisp_nsh_api_t; + +static uword +unformat_nsh_address (unformat_input_t * input, va_list * args) +{ + lisp_nsh_api_t *nsh = va_arg (*args, lisp_nsh_api_t *); + return unformat (input, "SPI:%d SI:%d", &nsh->spi, &nsh->si); +} + +static u8 * +format_nsh_address_vat (u8 * s, va_list * args) +{ + nsh_t *a = va_arg (*args, nsh_t *); + return format (s, "SPI:%d SI:%d", clib_net_to_host_u32 (a->spi), a->si); +} + +static u8 * +format_lisp_flat_eid (u8 * s, va_list * args) +{ + vl_api_eid_t *eid = va_arg (*args, vl_api_eid_t *); + + switch (eid->type) + { + case EID_TYPE_API_PREFIX: + if (eid->address.prefix.address.af) + return format (s, "%U/%d", format_ip6_address, + eid->address.prefix.address.un.ip6, + eid->address.prefix.len); + return format (s, "%U/%d", format_ip4_address, + eid->address.prefix.address.un.ip4, + eid->address.prefix.len); + case EID_TYPE_API_MAC: + return format (s, "%U", format_ethernet_address, eid->address.mac); + case EID_TYPE_API_NSH: + return format (s, "%U", format_nsh_address_vat, eid->address.nsh); + } + return 0; +} + +static void vl_api_gpe_add_del_fwd_entry_reply_t_handler + (vl_api_gpe_add_del_fwd_entry_reply_t * mp) +{ + vat_main_t *vam = &vat_main; + i32 retval = ntohl (mp->retval); + if (vam->async_mode) + { + vam->async_errors += (retval < 0); + } + else + { + vam->retval = retval; + vam->result_ready = 1; + } +} + +static void +api_gpe_fwd_entry_net_to_host (vl_api_gpe_fwd_entry_t * e) +{ + e->dp_table = clib_net_to_host_u32 (e->dp_table); + e->fwd_entry_index = clib_net_to_host_u32 (e->fwd_entry_index); + e->vni = clib_net_to_host_u32 (e->vni); +} + +static void + gpe_fwd_entries_get_reply_t_net_to_host + (vl_api_gpe_fwd_entries_get_reply_t * mp) +{ + u32 i; + + mp->count = clib_net_to_host_u32 (mp->count); + for (i = 0; i < mp->count; i++) + { + api_gpe_fwd_entry_net_to_host (&mp->entries[i]); + } +} + +static u8 * +format_gpe_encap_mode (u8 * s, va_list * args) +{ + u32 mode = va_arg (*args, u32); + + switch (mode) + { + case 0: + return format (s, "lisp"); + case 1: + return format (s, "vxlan"); + } + return 0; +} + +static void + vl_api_gpe_get_encap_mode_reply_t_handler + (vl_api_gpe_get_encap_mode_reply_t * mp) +{ + vat_main_t *vam = &vat_main; + + print (vam->ofp, "gpe mode: %U", format_gpe_encap_mode, mp->encap_mode); + vam->retval = ntohl (mp->retval); + vam->result_ready = 1; +} + +static void + vl_api_gpe_fwd_entry_path_details_t_handler + (vl_api_gpe_fwd_entry_path_details_t * mp) +{ + vat_main_t *vam = &vat_main; + u8 *(*format_ip_address_fcn) (u8 *, va_list *) = 0; + + if (mp->lcl_loc.addr.af) + format_ip_address_fcn = format_ip6_address; + else + format_ip_address_fcn = format_ip4_address; + + print (vam->ofp, "w:%d %30U %30U", mp->rmt_loc.weight, + format_ip_address_fcn, &mp->lcl_loc.addr.un, + format_ip_address_fcn, &mp->rmt_loc.addr.un); +} + +static void + vl_api_gpe_fwd_entries_get_reply_t_handler + (vl_api_gpe_fwd_entries_get_reply_t * mp) +{ + vat_main_t *vam = &vat_main; + u32 i; + int retval = clib_net_to_host_u32 (mp->retval); + vl_api_gpe_fwd_entry_t *e; + + if (retval) + goto end; + + gpe_fwd_entries_get_reply_t_net_to_host (mp); + + for (i = 0; i < mp->count; i++) + { + e = &mp->entries[i]; + print (vam->ofp, "%10d %10d %U %40U", e->fwd_entry_index, e->dp_table, + format_lisp_flat_eid, e->leid, format_lisp_flat_eid, e->reid); + } + +end: + vam->retval = retval; + vam->result_ready = 1; +} + +static void + vl_api_gpe_native_fwd_rpaths_get_reply_t_handler + (vl_api_gpe_native_fwd_rpaths_get_reply_t * mp) +{ + vat_main_t *vam = &vat_main; + u32 i, n; + int retval = clib_net_to_host_u32 (mp->retval); + vl_api_gpe_native_fwd_rpath_t *r; + + if (retval) + goto end; + + n = clib_net_to_host_u32 (mp->count); + + for (i = 0; i < n; i++) + { + r = &mp->entries[i]; + print (vam->ofp, "fib_index: %d sw_if_index %d nh %U", + clib_net_to_host_u32 (r->fib_index), + clib_net_to_host_u32 (r->nh_sw_if_index), + r->nh_addr.af ? format_ip6_address : format_ip4_address, + r->nh_addr.un); + } + +end: + vam->retval = retval; + vam->result_ready = 1; +} + +static void + vl_api_gpe_fwd_entry_vnis_get_reply_t_handler + (vl_api_gpe_fwd_entry_vnis_get_reply_t * mp) +{ + vat_main_t *vam = &vat_main; + u32 i, n; + int retval = clib_net_to_host_u32 (mp->retval); + + if (retval) + goto end; + + n = clib_net_to_host_u32 (mp->count); + + for (i = 0; i < n; i++) + print (vam->ofp, "%d", clib_net_to_host_u32 (mp->vnis[i])); + +end: + vam->retval = retval; + vam->result_ready = 1; +} + + +/* *INDENT-OFF* */ +/** Used for parsing LISP eids */ +typedef CLIB_PACKED(struct{ + union { + ip46_address_t ip; + mac_address_t mac; + lisp_nsh_api_t nsh; + } addr; + u32 len; /**< prefix length if IP */ + u8 type; /**< type of eid */ +}) lisp_eid_vat_t; +/* *INDENT-ON* */ + +static uword +unformat_lisp_eid_vat (unformat_input_t * input, va_list * args) +{ + lisp_eid_vat_t *a = va_arg (*args, lisp_eid_vat_t *); + + clib_memset (a, 0, sizeof (a[0])); + + if (unformat (input, "%U/%d", unformat_ip46_address, a->addr.ip, &a->len)) + { + a->type = 0; /* ip prefix type */ + } + else if (unformat (input, "%U", unformat_ethernet_address, &a->addr.mac)) + { + a->type = 1; /* mac type */ + } + else if (unformat (input, "%U", unformat_nsh_address, a->addr.nsh)) + { + a->type = 2; /* NSH type */ + a->addr.nsh.spi = clib_host_to_net_u32 (a->addr.nsh.spi); + } + else + { + return 0; + } + + if (a->type == 0) + { + if (ip46_address_is_ip4 (&a->addr.ip)) + return a->len > 32 ? 1 : 0; + else + return a->len > 128 ? 1 : 0; + } + + return 1; +} + +static void +lisp_eid_put_vat (vl_api_eid_t * eid, const lisp_eid_vat_t * vat_eid) +{ + eid->type = vat_eid->type; + switch (eid->type) + { + case EID_TYPE_API_PREFIX: + if (ip46_address_is_ip4 (&vat_eid->addr.ip)) + { + clib_memcpy (&eid->address.prefix.address.un.ip4, + &vat_eid->addr.ip.ip4, 4); + eid->address.prefix.address.af = ADDRESS_IP4; + eid->address.prefix.len = vat_eid->len; + } + else + { + clib_memcpy (&eid->address.prefix.address.un.ip6, + &vat_eid->addr.ip.ip6, 16); + eid->address.prefix.address.af = ADDRESS_IP6; + eid->address.prefix.len = vat_eid->len; + } + return; + case EID_TYPE_API_MAC: + clib_memcpy (&eid->address.mac, &vat_eid->addr.mac, + sizeof (eid->address.mac)); + return; + case EID_TYPE_API_NSH: + clib_memcpy (&eid->address.nsh, &vat_eid->addr.nsh, + sizeof (eid->address.nsh)); + return; + default: + ASSERT (0); + return; + } +} + +static int +api_gpe_add_del_fwd_entry (vat_main_t * vam) +{ + u32 dp_table = 0, vni = 0;; + unformat_input_t *input = vam->input; + vl_api_gpe_add_del_fwd_entry_t *mp; + u8 is_add = 1; + lisp_eid_vat_t _rmt_eid, *rmt_eid = &_rmt_eid; + lisp_eid_vat_t _lcl_eid, *lcl_eid = &_lcl_eid; + u8 rmt_eid_set = 0, lcl_eid_set = 0; + u32 action = ~0, w; + ip4_address_t rmt_rloc4, lcl_rloc4; + ip6_address_t rmt_rloc6, lcl_rloc6; + vl_api_gpe_locator_t *rmt_locs = 0, *lcl_locs = 0, rloc, *curr_rloc = 0; + int ret; + + clib_memset (&rloc, 0, sizeof (rloc)); + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "del")) + is_add = 0; + else if (unformat (input, "add")) + is_add = 1; + else if (unformat (input, "reid %U", unformat_lisp_eid_vat, rmt_eid)) + { + rmt_eid_set = 1; + } + else if (unformat (input, "leid %U", unformat_lisp_eid_vat, lcl_eid)) + { + lcl_eid_set = 1; + } + else if (unformat (input, "vrf %d", &dp_table)) + ; + else if (unformat (input, "bd %d", &dp_table)) + ; + else if (unformat (input, "vni %d", &vni)) + ; + else if (unformat (input, "w %d", &w)) + { + if (!curr_rloc) + { + errmsg ("No RLOC configured for setting priority/weight!"); + return -99; + } + curr_rloc->weight = w; + } + else if (unformat (input, "loc-pair %U %U", unformat_ip4_address, + &lcl_rloc4, unformat_ip4_address, &rmt_rloc4)) + { + rloc.addr.af = 0; + clib_memcpy (&rloc.addr.un.ip4, &lcl_rloc4, sizeof (lcl_rloc4)); + rloc.weight = 0; + vec_add1 (lcl_locs, rloc); + + clib_memcpy (&rloc.addr.un.ip4, &rmt_rloc4, sizeof (rmt_rloc4)); + vec_add1 (rmt_locs, rloc); + /* weight saved in rmt loc */ + curr_rloc = &rmt_locs[vec_len (rmt_locs) - 1]; + } + else if (unformat (input, "loc-pair %U %U", unformat_ip6_address, + &lcl_rloc6, unformat_ip6_address, &rmt_rloc6)) + { + rloc.addr.af = 1; + clib_memcpy (&rloc.addr.un.ip6, &lcl_rloc6, sizeof (lcl_rloc6)); + rloc.weight = 0; + vec_add1 (lcl_locs, rloc); + + clib_memcpy (&rloc.addr.un.ip6, &rmt_rloc6, sizeof (rmt_rloc6)); + vec_add1 (rmt_locs, rloc); + /* weight saved in rmt loc */ + curr_rloc = &rmt_locs[vec_len (rmt_locs) - 1]; + } + else if (unformat (input, "action %d", &action)) + { + ; + } + else + { + clib_warning ("parse error '%U'", format_unformat_error, input); + return -99; + } + } + + if (!rmt_eid_set) + { + errmsg ("remote eid addresses not set"); + return -99; + } + + if (lcl_eid_set && rmt_eid->type != lcl_eid->type) + { + errmsg ("eid types don't match"); + return -99; + } + + if (0 == rmt_locs && (u32) ~ 0 == action) + { + errmsg ("action not set for negative mapping"); + return -99; + } + + /* Construct the API message */ + M2 (GPE_ADD_DEL_FWD_ENTRY, mp, + sizeof (vl_api_gpe_locator_t) * vec_len (rmt_locs) * 2); + + mp->is_add = is_add; + lisp_eid_put_vat (&mp->rmt_eid, rmt_eid); + lisp_eid_put_vat (&mp->lcl_eid, lcl_eid); + mp->dp_table = clib_host_to_net_u32 (dp_table); + mp->vni = clib_host_to_net_u32 (vni); + mp->action = action; + + if (0 != rmt_locs && 0 != lcl_locs) + { + mp->loc_num = clib_host_to_net_u32 (vec_len (rmt_locs) * 2); + clib_memcpy (mp->locs, lcl_locs, + (sizeof (vl_api_gpe_locator_t) * vec_len (lcl_locs))); + + u32 offset = sizeof (vl_api_gpe_locator_t) * vec_len (lcl_locs); + clib_memcpy (((u8 *) mp->locs) + offset, rmt_locs, + (sizeof (vl_api_gpe_locator_t) * vec_len (rmt_locs))); + } + vec_free (lcl_locs); + vec_free (rmt_locs); + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_gpe_enable_disable (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + vl_api_gpe_enable_disable_t *mp; + u8 is_set = 0; + u8 is_enable = 1; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "enable")) + { + is_set = 1; + is_enable = 1; + } + else if (unformat (input, "disable")) + { + is_set = 1; + is_enable = 0; + } + else + break; + } + + if (is_set == 0) + { + errmsg ("Value not set"); + return -99; + } + + /* Construct the API message */ + M (GPE_ENABLE_DISABLE, mp); + + mp->is_enable = is_enable; + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +uword +unformat_gpe_encap_mode (unformat_input_t * input, va_list * args) +{ + u32 *mode = va_arg (*args, u32 *); + + if (unformat (input, "lisp")) + *mode = 0; + else if (unformat (input, "vxlan")) + *mode = 1; + else + return 0; + + return 1; +} + +static int +api_gpe_get_encap_mode (vat_main_t * vam) +{ + vl_api_gpe_get_encap_mode_t *mp; + int ret; + + /* Construct the API message */ + M (GPE_GET_ENCAP_MODE, mp); + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_gpe_set_encap_mode (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + vl_api_gpe_set_encap_mode_t *mp; + int ret; + u32 mode = 0; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "%U", unformat_gpe_encap_mode, &mode)) + ; + else + break; + } + + /* Construct the API message */ + M (GPE_SET_ENCAP_MODE, mp); + + mp->is_vxlan = mode; + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_gpe_add_del_iface (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + vl_api_gpe_add_del_iface_t *mp; + u8 action_set = 0, is_add = 1, is_l2 = 0, dp_table_set = 0, vni_set = 0; + u32 dp_table = 0, vni = 0; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "up")) + { + action_set = 1; + is_add = 1; + } + else if (unformat (input, "down")) + { + action_set = 1; + is_add = 0; + } + else if (unformat (input, "table_id %d", &dp_table)) + { + dp_table_set = 1; + } + else if (unformat (input, "bd_id %d", &dp_table)) + { + dp_table_set = 1; + is_l2 = 1; + } + else if (unformat (input, "vni %d", &vni)) + { + vni_set = 1; + } + else + break; + } + + if (action_set == 0) + { + errmsg ("Action not set"); + return -99; + } + if (dp_table_set == 0 || vni_set == 0) + { + errmsg ("vni and dp_table must be set"); + return -99; + } + + /* Construct the API message */ + M (GPE_ADD_DEL_IFACE, mp); + + mp->is_add = is_add; + mp->dp_table = clib_host_to_net_u32 (dp_table); + mp->is_l2 = is_l2; + mp->vni = clib_host_to_net_u32 (vni); + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_gpe_fwd_entries_get (vat_main_t * vam) +{ + unformat_input_t *i = vam->input; + vl_api_gpe_fwd_entries_get_t *mp; + u8 vni_set = 0; + u32 vni = ~0; + int ret; + + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + { + if (unformat (i, "vni %d", &vni)) + { + vni_set = 1; + } + else + { + errmsg ("parse error '%U'", format_unformat_error, i); + return -99; + } + } + + if (!vni_set) + { + errmsg ("vni not set!"); + return -99; + } + + if (!vam->json_output) + { + print (vam->ofp, "%10s %10s %s %40s", "fwd_index", "dp_table", + "leid", "reid"); + } + + M (GPE_FWD_ENTRIES_GET, mp); + mp->vni = clib_host_to_net_u32 (vni); + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_gpe_native_fwd_rpaths_get (vat_main_t * vam) +{ + unformat_input_t *i = vam->input; + vl_api_gpe_native_fwd_rpaths_get_t *mp; + int ret; + u8 ip_family_set = 0, is_ip4 = 1; + + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + { + if (unformat (i, "ip4")) + { + ip_family_set = 1; + is_ip4 = 1; + } + else if (unformat (i, "ip6")) + { + ip_family_set = 1; + is_ip4 = 0; + } + else + { + errmsg ("parse error '%U'", format_unformat_error, i); + return -99; + } + } + + if (!ip_family_set) + { + errmsg ("ip family not set!"); + return -99; + } + + M (GPE_NATIVE_FWD_RPATHS_GET, mp); + mp->is_ip4 = is_ip4; + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_gpe_fwd_entry_vnis_get (vat_main_t * vam) +{ + vl_api_gpe_fwd_entry_vnis_get_t *mp; + int ret; + + if (!vam->json_output) + { + print (vam->ofp, "VNIs"); + } + + M (GPE_FWD_ENTRY_VNIS_GET, mp); + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_gpe_add_del_native_fwd_rpath (vat_main_t * vam) +{ + unformat_input_t *i = vam->input; + vl_api_gpe_add_del_native_fwd_rpath_t *mp; + int ret = 0; + u8 is_add = 1, ip_set = 0, is_ip4 = 1; + struct in_addr ip4; + struct in6_addr ip6; + u32 table_id = 0, nh_sw_if_index = ~0; + + clib_memset (&ip4, 0, sizeof (ip4)); + clib_memset (&ip6, 0, sizeof (ip6)); + + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + { + if (unformat (i, "del")) + is_add = 0; + else if (unformat (i, "via %U %U", unformat_ip4_address, &ip4, + unformat_sw_if_index, vam, &nh_sw_if_index)) + { + ip_set = 1; + is_ip4 = 1; + } + else if (unformat (i, "via %U %U", unformat_ip6_address, &ip6, + unformat_sw_if_index, vam, &nh_sw_if_index)) + { + ip_set = 1; + is_ip4 = 0; + } + else if (unformat (i, "via %U", unformat_ip4_address, &ip4)) + { + ip_set = 1; + is_ip4 = 1; + nh_sw_if_index = ~0; + } + else if (unformat (i, "via %U", unformat_ip6_address, &ip6)) + { + ip_set = 1; + is_ip4 = 0; + nh_sw_if_index = ~0; + } + else if (unformat (i, "table %d", &table_id)) + ; + else + { + errmsg ("parse error '%U'", format_unformat_error, i); + return -99; + } + } + + if (!ip_set) + { + errmsg ("nh addr not set!"); + return -99; + } + + M (GPE_ADD_DEL_NATIVE_FWD_RPATH, mp); + mp->is_add = is_add; + mp->table_id = clib_host_to_net_u32 (table_id); + mp->nh_sw_if_index = clib_host_to_net_u32 (nh_sw_if_index); + mp->nh_addr.af = is_ip4 ? 0 : 1; + if (is_ip4) + clib_memcpy (mp->nh_addr.un.ip4, &ip4, sizeof (ip4)); + else + clib_memcpy (mp->nh_addr.un.ip6, &ip6, sizeof (ip6)); + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_gpe_fwd_entry_path_dump (vat_main_t * vam) +{ + vl_api_gpe_fwd_entry_path_dump_t *mp; + vl_api_control_ping_t *mp_ping; + unformat_input_t *i = vam->input; + u32 fwd_entry_index = ~0; + int ret; + + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + { + if (unformat (i, "index %d", &fwd_entry_index)) + ; + else + break; + } + + if (~0 == fwd_entry_index) + { + errmsg ("no index specified!"); + return -99; + } + + if (!vam->json_output) + { + print (vam->ofp, "first line"); + } + + M (GPE_FWD_ENTRY_PATH_DUMP, mp); + + /* send it... */ + S (mp); + /* Use a control ping for synchronization */ + LISP_PING (&lisp_gpe_test_main, mp_ping); + S (mp_ping); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +#define vat_plugin_register vat_plugin_register_gpe +#include + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/lisp/lisp-gpe/lisp_gpe_tunnel.c b/src/plugins/lisp/lisp-gpe/lisp_gpe_tunnel.c new file mode 100644 index 00000000000..b2426429322 --- /dev/null +++ b/src/plugins/lisp/lisp-gpe/lisp_gpe_tunnel.c @@ -0,0 +1,293 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file + * @brief Common utility functions for IPv4, IPv6 and L2 LISP-GPE tunnels. + * + */ +#include +#include +#include + +#include + +/** + * @brief Pool of all LISP tunnels + */ +static lisp_gpe_tunnel_t *lisp_gpe_tunnel_pool; + +/** + * @brief a DB of all tunnels + */ +static uword *lisp_gpe_tunnel_db; + +/** + * @brief Compute IP-UDP-GPE sub-tunnel encap/rewrite header. + * + * @param[in] t Parent of the sub-tunnel. + * @param[in] st Sub-tunnel. + * @param[in] lp Local and remote locators used in the encap header. + * + * @return 0 on success. + */ +u8 * +lisp_gpe_tunnel_build_rewrite (const lisp_gpe_tunnel_t * lgt, + const lisp_gpe_adjacency_t * ladj, + lisp_gpe_next_protocol_e payload_proto) +{ + lisp_gpe_header_t *lisp0; + u8 *rw = 0; + int len; + gpe_encap_mode_t encap_mode = vnet_gpe_get_encap_mode (); + + if (AF_IP4 == ip_addr_version (&lgt->key->lcl)) + { + ip4_udp_lisp_gpe_header_t *h0; + ip4_header_t *ip0; + + len = sizeof (*h0); + + vec_validate_aligned (rw, len - 1, CLIB_CACHE_LINE_BYTES); + + h0 = (ip4_udp_lisp_gpe_header_t *) rw; + + /* Fixed portion of the (outer) ip4 header */ + ip0 = &h0->ip4; + ip0->ip_version_and_header_length = 0x45; + ip0->ttl = 254; + ip0->protocol = IP_PROTOCOL_UDP; + + /* we fix up the ip4 header length and checksum after-the-fact */ + ip_address_copy_addr (&ip0->src_address, &lgt->key->lcl); + ip_address_copy_addr (&ip0->dst_address, &lgt->key->rmt); + ip0->checksum = ip4_header_checksum (ip0); + + /* UDP header, randomize src port on something, maybe? */ + h0->udp.src_port = clib_host_to_net_u16 (4341); + h0->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_lisp_gpe); + + /* LISP-gpe header */ + lisp0 = &h0->lisp; + } + else + { + ip6_udp_lisp_gpe_header_t *h0; + ip6_header_t *ip0; + + len = sizeof (*h0); + + vec_validate_aligned (rw, len - 1, CLIB_CACHE_LINE_BYTES); + + h0 = (ip6_udp_lisp_gpe_header_t *) rw; + + /* Fixed portion of the (outer) ip6 header */ + ip0 = &h0->ip6; + ip0->ip_version_traffic_class_and_flow_label = + clib_host_to_net_u32 (0x6 << 28); + ip0->hop_limit = 254; + ip0->protocol = IP_PROTOCOL_UDP; + + /* we fix up the ip6 header length after-the-fact */ + ip_address_copy_addr (&ip0->src_address, &lgt->key->lcl); + ip_address_copy_addr (&ip0->dst_address, &lgt->key->rmt); + + /* UDP header, randomize src port on something, maybe? */ + h0->udp.src_port = clib_host_to_net_u16 (4341); + h0->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_lisp_gpe); + + /* LISP-gpe header */ + lisp0 = &h0->lisp; + } + + lisp0->flags = ladj->flags; + if (GPE_ENCAP_VXLAN == encap_mode) + /* unset P flag */ + lisp0->flags &= ~LISP_GPE_FLAGS_P; + + lisp0->ver_res = 0; + lisp0->res = 0; + lisp0->next_protocol = payload_proto; + lisp0->iid = clib_host_to_net_u32 (ladj->vni) >> 8; /* first 24 bits only */ + + return (rw); +} + +static lisp_gpe_tunnel_t * +lisp_gpe_tunnel_db_find (const lisp_gpe_tunnel_key_t * key) +{ + uword *p; + + p = hash_get_mem (lisp_gpe_tunnel_db, (void *) key); + + if (NULL != p) + { + return (pool_elt_at_index (lisp_gpe_tunnel_pool, p[0])); + } + return (NULL); +} + +lisp_gpe_tunnel_t * +lisp_gpe_tunnel_get_i (index_t lgti) +{ + return (pool_elt_at_index (lisp_gpe_tunnel_pool, lgti)); +} + +index_t +lisp_gpe_tunnel_find_or_create_and_lock (const locator_pair_t * pair, + u32 rloc_fib_index) +{ + lisp_gpe_tunnel_key_t key = { + .lcl = pair->lcl_loc, + .rmt = pair->rmt_loc, + .fib_index = rloc_fib_index, + }; + lisp_gpe_tunnel_t *lgt; + fib_prefix_t pfx; + + lgt = lisp_gpe_tunnel_db_find (&key); + + if (NULL == lgt) + { + pool_get (lisp_gpe_tunnel_pool, lgt); + clib_memset (lgt, 0, sizeof (*lgt)); + + lgt->key = clib_mem_alloc (sizeof (*lgt->key)); + clib_memset (lgt->key, 0, sizeof (*lgt->key)); + + lgt->key->rmt = pair->rmt_loc; + lgt->key->lcl = pair->lcl_loc; + lgt->key->fib_index = rloc_fib_index; + + /* + * source the FIB entry for the RLOC so we can track its forwarding + * chain + */ + ip_address_to_fib_prefix (&lgt->key->rmt, &pfx); + + lgt->fib_entry_index = fib_table_entry_special_add (rloc_fib_index, + &pfx, + FIB_SOURCE_RR, + FIB_ENTRY_FLAG_NONE); + + hash_set_mem (lisp_gpe_tunnel_db, lgt->key, + (lgt - lisp_gpe_tunnel_pool)); + } + + lgt->locks++; + + return (lgt - lisp_gpe_tunnel_pool); +} + +void +lisp_gpe_tunnel_unlock (index_t lgti) +{ + lisp_gpe_tunnel_t *lgt; + + lgt = lisp_gpe_tunnel_get_i (lgti); + lgt->locks--; + + if (0 == lgt->locks) + { + hash_unset_mem (lisp_gpe_tunnel_db, lgt->key); + clib_mem_free (lgt->key); + pool_put (lisp_gpe_tunnel_pool, lgt); + } +} + +const lisp_gpe_tunnel_t * +lisp_gpe_tunnel_get (index_t lgti) +{ + return (lisp_gpe_tunnel_get_i (lgti)); +} + +/** Format LISP-GPE tunnel. */ +u8 * +format_lisp_gpe_tunnel (u8 * s, va_list * args) +{ + lisp_gpe_tunnel_t *lgt = va_arg (*args, lisp_gpe_tunnel_t *); + + s = format (s, "tunnel %d\n", lgt - lisp_gpe_tunnel_pool); + s = format (s, " fib-index: %d, locks:%d \n", + lgt->key->fib_index, lgt->locks); + s = format (s, " lisp ver 0\n"); + + s = format (s, " locator-pair:\n"); + s = format (s, " local: %U remote: %U\n", + format_ip_address, &lgt->key->lcl, + format_ip_address, &lgt->key->rmt); + s = format (s, " RLOC FIB entry: %d\n", lgt->fib_entry_index); + + return s; +} + +/** + * CLI command to show LISP-GPE tunnels. + */ +static clib_error_t * +show_lisp_gpe_tunnel_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + lisp_gpe_tunnel_t *lgt; + index_t index; + + if (pool_elts (lisp_gpe_tunnel_pool) == 0) + vlib_cli_output (vm, "No lisp-gpe tunnels configured..."); + + if (unformat (input, "%d", &index)) + { + lgt = lisp_gpe_tunnel_get_i (index); + vlib_cli_output (vm, "%U", format_lisp_gpe_tunnel, lgt); + } + else + { + /* *INDENT-OFF* */ + pool_foreach (lgt, lisp_gpe_tunnel_pool, + ({ + vlib_cli_output (vm, "%U", format_lisp_gpe_tunnel, lgt); + })); + /* *INDENT-ON* */ + } + + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (show_lisp_gpe_tunnel_command, static) = +{ + .path = "show gpe tunnel", + .function = show_lisp_gpe_tunnel_command_fn, +}; +/* *INDENT-ON* */ + +static clib_error_t * +lisp_gpe_tunnel_module_init (vlib_main_t * vm) +{ + lisp_gpe_tunnel_db = hash_create_mem (0, + sizeof (lisp_gpe_tunnel_key_t), + sizeof (uword)); + + return (NULL); +} + +VLIB_INIT_FUNCTION (lisp_gpe_tunnel_module_init); + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/lisp/lisp-gpe/lisp_gpe_tunnel.h b/src/plugins/lisp/lisp-gpe/lisp_gpe_tunnel.h new file mode 100644 index 00000000000..7fe3062dc57 --- /dev/null +++ b/src/plugins/lisp/lisp-gpe/lisp_gpe_tunnel.h @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file + * @brief Common utility functions for IPv4, IPv6 and L2 LISP-GPE tunnels. + * + */ + +#ifndef LISP_GPE_TUNNEL_H__ +#define LISP_GPE_TUNNEL_H__ + +#include +#include + +/** + * Forward declaration + */ +struct lisp_gpe_adjacency_t_; + +/** + * A Key for a tunnel + */ +typedef struct lisp_gpe_tunnel_key_t_ +{ + ip_address_t rmt; + ip_address_t lcl; + u32 fib_index; +} lisp_gpe_tunnel_key_t; + +/** + * @brief A LISP GPE Tunnel. + * + * A tunnel represents an associatation between a local and remote RLOC. + * As such it represents a unique LISP rewrite. + */ +typedef struct lisp_gpe_tunnel_t_ +{ + /** + * RLOC pair and rloc fib_index. This is the tunnel's key. + */ + lisp_gpe_tunnel_key_t *key; + + /** + * number of reference counting locks + */ + u32 locks; + + /** + * the FIB entry through which the remote rloc is reachable + s */ + fib_node_index_t fib_entry_index; +} lisp_gpe_tunnel_t; + +extern index_t lisp_gpe_tunnel_find_or_create_and_lock (const locator_pair_t * + pair, + u32 rloc_fib_index); + +extern void lisp_gpe_tunnel_unlock (index_t lgti); + +extern const lisp_gpe_tunnel_t *lisp_gpe_tunnel_get (index_t lgti); + +extern u8 *lisp_gpe_tunnel_build_rewrite (const lisp_gpe_tunnel_t * lgt, + const struct lisp_gpe_adjacency_t_ + *ladj, + lisp_gpe_next_protocol_e + payload_proto); +extern u8 *format_lisp_gpe_tunnel (u8 * s, va_list * args); + +#endif + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/lisp/lisp-gpe/lisp_types_api.c b/src/plugins/lisp/lisp-gpe/lisp_types_api.c new file mode 120000 index 00000000000..84e06c41264 --- /dev/null +++ b/src/plugins/lisp/lisp-gpe/lisp_types_api.c @@ -0,0 +1 @@ +../lisp-cp/lisp_types_api.c \ No newline at end of file diff --git a/src/plugins/lisp/lisp-gpe/lisp_types_api.h b/src/plugins/lisp/lisp-gpe/lisp_types_api.h new file mode 120000 index 00000000000..f895123c6b0 --- /dev/null +++ b/src/plugins/lisp/lisp-gpe/lisp_types_api.h @@ -0,0 +1 @@ +../lisp-cp/lisp_types_api.h \ No newline at end of file diff --git a/src/plugins/lisp/lisp-gpe/rfc.txt b/src/plugins/lisp/lisp-gpe/rfc.txt new file mode 100644 index 00000000000..5e3da150c70 --- /dev/null +++ b/src/plugins/lisp/lisp-gpe/rfc.txt @@ -0,0 +1,826 @@ +Network Working Group D. Lewis +Internet-Draft Cisco Systems, Inc. +Intended status: Informational P. Agarwal +Expires: January 5, 2015 Broadcom + L. Kreeger + F. Maino + P. Quinn + M. Smith + N. Yadav + Cisco Systems, Inc. + July 4, 2014 + + + LISP Generic Protocol Extension + draft-lewis-lisp-gpe-02.txt + +Abstract + + This draft describes extending the Locator/ID Separation Protocol + (LISP) [RFC6830], via changes to the LISP header, with three new + capabilities: support for multi-protocol encapsulation, operations, + administration and management (OAM) signaling, and explicit + versioning. + +Status of this Memo + + This Internet-Draft is submitted in full conformance with the + provisions of BCP 78 and BCP 79. + + Internet-Drafts are working documents of the Internet Engineering + Task Force (IETF). Note that other groups may also distribute + working documents as Internet-Drafts. The list of current Internet- + Drafts is at http://datatracker.ietf.org/drafts/current/. + + Internet-Drafts are draft documents valid for a maximum of six months + and may be updated, replaced, or obsoleted by other documents at any + time. It is inappropriate to use Internet-Drafts as reference + material or to cite them other than as "work in progress." + + This Internet-Draft will expire on January 5, 2015. + +Copyright Notice + + Copyright (c) 2014 IETF Trust and the persons identified as the + document authors. All rights reserved. + + This document is subject to BCP 78 and the IETF Trust's Legal + Provisions Relating to IETF Documents + + + +Lewis, et al. Expires January 5, 2015 [Page 1] + +Internet-Draft LISP Generic Protocol Extension July 2014 + + + (http://trustee.ietf.org/license-info) in effect on the date of + publication of this document. Please review these documents + carefully, as they describe your rights and restrictions with respect + to this document. Code Components extracted from this document must + include Simplified BSD License text as described in Section 4.e of + the Trust Legal Provisions and are provided without warranty as + described in the Simplified BSD License. + + +Table of Contents + + 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 3 + 2. LISP Header Without Protocol Extensions . . . . . . . . . . . 4 + 3. Generic Protocol Extension for LISP (LISP-gpe) . . . . . . . . 5 + 3.1. Multi Protocol Support . . . . . . . . . . . . . . . . . . 5 + 3.2. OAM Support . . . . . . . . . . . . . . . . . . . . . . . 6 + 3.3. Version Bits . . . . . . . . . . . . . . . . . . . . . . . 6 + 4. Backward Compatibility . . . . . . . . . . . . . . . . . . . . 8 + 4.1. LISP-gpe Routers to (legacy) LISP Routers . . . . . . . . 8 + 4.2. (legacy) LISP Routers to LISP-gpe Routers . . . . . . . . 8 + 4.3. Type of Service . . . . . . . . . . . . . . . . . . . . . 8 + 4.4. VLAN Identifier (VID) . . . . . . . . . . . . . . . . . . 8 + 5. LISP-gpe Examples . . . . . . . . . . . . . . . . . . . . . . 9 + 6. Security Considerations . . . . . . . . . . . . . . . . . . . 11 + 7. Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . 12 + 8. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 13 + 9. References . . . . . . . . . . . . . . . . . . . . . . . . . . 14 + 9.1. Normative References . . . . . . . . . . . . . . . . . . . 14 + 9.2. Informative References . . . . . . . . . . . . . . . . . . 14 + Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . . 15 + + + + + + + + + + + + + + + + + + + + + +Lewis, et al. Expires January 5, 2015 [Page 2] + +Internet-Draft LISP Generic Protocol Extension July 2014 + + +1. Introduction + + LISP [RFC6830] defines an encapsulation format that carries IPv4 or + IPv6 (henceforth referred to as IP) packets in a LISP header and + outer UDP/IP transport. + + The LISP header does not specify the protocol being encapsulated and + therefore is currently limited to encapsulating only IP packet + payloads. Other protocols, most notably VXLAN [VXLAN] (which defines + a similar header format to LISP), are used to encapsulate L2 + protocols such as Ethernet. LISP [RFC6830] can be extended to + indicate the inner protocol, enabling the encapsulation of Ethernet, + IP or any other desired protocol all the while ensuring compatibility + with existing LISP [RFC6830] deployments. + + As LISP is deployed, there's also the need to provide increased + visibility and diagnostic capabilities within the overlay. + + This document describes extending LISP ([RFC6830]) via the following + changes: + + Next Protocol Bit (P bit): A reserved flag bit is allocated, and set + in the LISP-gpe header to indicate that a next protocol field is + present. + + OAM Flag Bit (O bit): A reserved flag bit is allocated, and set in + the LISP-gpe header, to indicate that the packet is an OAM packet. + + Version: Two reserved bits are allocated, and set in the LISP-gpe + header, to indicate LISP-gpe protocol version. + + Next protocol: An 8 bit next protocol field is present in the LISP- + gpe header. + + + + + + + + + + + + + + + + + + +Lewis, et al. Expires January 5, 2015 [Page 3] + +Internet-Draft LISP Generic Protocol Extension July 2014 + + +2. LISP Header Without Protocol Extensions + + As described in the introduction, the LISP header has no protocol + identifier that indicates the type of payload being carried by LISP. + Because of this, LISP is limited to an IP payload. Furthermore, the + LISP header has no mechanism to signal OAM packets. + + The LISP header contains flags (some defined, some reserved), a + Nonce/Map-version field and an instance ID/Locator-status-bit field. + The flags provide flexibility to define how the reserved bits can be + used to change the definition of the LISP header. + + + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + |N|L|E|V|I|flags| Nonce/Map-Version | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Instance ID/Locator-Status-Bits | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + + + Figure 1: LISP Header + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Lewis, et al. Expires January 5, 2015 [Page 4] + +Internet-Draft LISP Generic Protocol Extension July 2014 + + +3. Generic Protocol Extension for LISP (LISP-gpe) + +3.1. Multi Protocol Support + + This draft defines the following changes to the LISP header in order + to support multi-protocol encapsulation. + + P Bit: Flag bit 5 is defined as the Next Protocol bit. The P bit + MUST be set to 1 to indicate the presence of the 8 bit next + protocol field. + + P = 0 indicates that the payload MUST conform to LISP as defined + in [RFC6830]. + + Flag bit 5 was chosen as the P bit because this flag bit is + currently unallocated in LISP [RFC6830]. + + Next Protocol Field: The lower 8 bits of the first word are used to + carry a next protocol. This next protocol field contains the + protocol of the encapsulated payload packet. + + LISP [RFC6830] uses the lower 16 bits of the first word for either + a nonce, an echo-nonce ([RFC6830]) or to support map-versioning + ([RFC6834]). These are all optional capabilities that are + indicated by setting the N, E, and the V bit respectively. + + To maintain the desired data plane compatibility, when the P bit + is set, the N, E, and V bits MUST be set to zero. + + A new protocol registry will be requested from IANA for the Next + Protocol field. This draft defines the following Next Protocol + values: + + 0x1 : IPv4 + + 0x2 : IPv6 + + 0x3 : Ethernet + + 0x4: Network Service Header + + + + + + + + + + + +Lewis, et al. Expires January 5, 2015 [Page 5] + +Internet-Draft LISP Generic Protocol Extension July 2014 + + + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + |N|L|E|V|I|P|R|R| Reserved | Next Protocol | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Instance ID/Locator-Status-Bits | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + + + + Figure 2: LISP-gpe Next Protocol (P=1) + +3.2. OAM Support + + Flag bit 7 is defined as the O bit. When the O bit is set to 1, the + packet is an OAM packet and OAM processing MUST occur. The OAM + protocol details are out of scope for this document. As with the + P-bit, bit 7 is currently a reserved flag in [RFC6830]. + + + + + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + |N|L|E|V|I|P|R|O| Reserved | Next Protocol | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Instance ID/Locator-Status-Bits | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + + + + Figure 3: LISP-gpe OAM bit (P=1) + +3.3. Version Bits + + LISP-gpe bits8 and 9 are defined as version bits. The version field + is used to ensure backward compatibility going forward with future + LISP-gpe updates. + + The initial version for LISP-gpe is 0. + + + + + + + + + + +Lewis, et al. Expires January 5, 2015 [Page 6] + +Internet-Draft LISP Generic Protocol Extension July 2014 + + + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + |N|L|E|V|I|P|R|O|Ver| Reserved | Next Protocol | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Instance ID/Locator-Status-Bits | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + + + + Figure 4: LISP-gpe Version bits (P=1) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Lewis, et al. Expires January 5, 2015 [Page 7] + +Internet-Draft LISP Generic Protocol Extension July 2014 + + +4. Backward Compatibility + + Undefined (in RFC6830) flag bits 5 and 7, LISP-gpe P and O bits, were + selected to ensure compatibility with existing LISP [RFC6830] + deployments. + + Similarly, using P = 0 to indicate that the format of the header and + payload conforms to [RFC6830] ensures compatibility with existing + LISP hardware forwarding platforms. + +4.1. LISP-gpe Routers to (legacy) LISP Routers + + A LISP-gpe router MUST not encapsulate non-IP packet nor OAM packets + to a LISP router. A method for determining the capabilities of a + LISP router (gpe or "legacy") is out of the scope of this draft. + + When encapsulating IP packets to a LISP router the P bit SHOULD be + set to 1 and the UDP port MUST be set to 4341. OAM bit MUST be set + to 0. The Next Protocol field SHOULD be 0x1 (IPv4) or 0x2 (IPv6). + The (legacy) LISP router will ignore the P bit and the protocol type + field. The (legacy) LISP router will treat the packet as a LISP + packet and inspect the first nibble of the payload to determine the + IP version. + + When the P bit is set, the N, E, and V bits MUST be set to zero. The + receiving (legacy) LISP router will ignore N, E and V bits, when the + P bit is set. + +4.2. (legacy) LISP Routers to LISP-gpe Routers + + When a LISP-gpe router receives a packet from a (legacy) LISP router, + the P bit MUST not be set and the UDP port MUST be 4341. The payload + MUST be IP, and the LISP-gpe router will inspect the first nibble of + the payload to determine IP version. + +4.3. Type of Service + + When a LISP-gpe router performs Ethernet encapsulation, the inner + 802.1Q [IEEE8021Q] priority code point (PCP) field MAY be mapped from + the encapsulated frame to the Type of Service field in the outer IPv4 + header, or in the case of IPv6 the 'Traffic Class' field. + +4.4. VLAN Identifier (VID) + + When a LISP-gpe router performs Ethernet encapsulation, the inner + header 802.1Q [IEEE8021Q] VLAN Identifier (VID) MAY be mapped to, or + used to determine the LISP Instance ID field. + + + + +Lewis, et al. Expires January 5, 2015 [Page 8] + +Internet-Draft LISP Generic Protocol Extension July 2014 + + +5. LISP-gpe Examples + + This section provides two examples of IP protocols, and one example + of Ethernet encapsulated LISP-gpe using the generic extension + described in this document. + + + + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + |N|L|E|V|I|1|0|0|0| Reserved | NP = IPv4 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Instance ID/Locator-Status-Bits | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Original IPv4 Packet | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + + + + Figure 5: IPv4 and LISP-gpe + + + + + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + |N|L|E|V|I|1|0|0|0| Reserved | NP = IPv6 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Instance ID/Locator-Status-Bits | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Original IPv6 Packet | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + + + + Figure 6: IPv6 and LISP-gpe + + + + + + + + + + + + + +Lewis, et al. Expires January 5, 2015 [Page 9] + +Internet-Draft LISP Generic Protocol Extension July 2014 + + + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + |N|L|E|V|I|1|0|0|0| Reserved | NP = Ethernet | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Instance ID/Locator-Status-Bits | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Original Ethernet Frame | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + + + + Figure 7: Ethernet and LISP-gpe + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Lewis, et al. Expires January 5, 2015 [Page 10] + +Internet-Draft LISP Generic Protocol Extension July 2014 + + +6. Security Considerations + + LISP-gpe security considerations are similar to the LISP security + considerations documented at length in LISP [RFC6830]. With LISP- + gpe, issues such as dataplane spoofing, flooding, and traffic + redirection are dependent on the particular protocol payload + encapsulated. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Lewis, et al. Expires January 5, 2015 [Page 11] + +Internet-Draft LISP Generic Protocol Extension July 2014 + + +7. Acknowledgments + + A special thank you goes to Dino Farinacci for his guidance and + detailed review. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Lewis, et al. Expires January 5, 2015 [Page 12] + +Internet-Draft LISP Generic Protocol Extension July 2014 + + +8. IANA Considerations + + IANA is requested to set up a registry of "Next Protocol". These are + 8-bit values. Next Protocol values 0, 1, 2, 3 and 4 are defined in + this draft. New values are assigned via Standards Action [RFC5226]. + + +---------------+-------------+---------------+ + | Next Protocol | Description | Reference | + +---------------+-------------+---------------+ + | 0 | Reserved | This document | + | | | | + | 1 | IPv4 | This document | + | | | | + | 2 | IPv6 | This document | + | | | | + | 3 | Ethernet | This document | + | | | | + | 4 | NSH | This document | + | | | | + | 5..253 | Unassigned | | + +---------------+-------------+---------------+ + + Table 1 + + There are ten bits at the beginning of the LISP-gpe header. New + bits are assigned via Standards Action [RFC5226]. + + Bits 0-3 - Assigned by LISP [RFC6830] + Bit 4 - Instance ID (I bit) + Bit 5 - Next Protocol (P bit) + Bit 6 - Reserved + Bit 7 - OAM (O bit) + Bits 8-9 - Version + + + + + + + + + + + + + + + + + + +Lewis, et al. Expires January 5, 2015 [Page 13] + +Internet-Draft LISP Generic Protocol Extension July 2014 + + +9. References + +9.1. Normative References + + [RFC0768] Postel, J., "User Datagram Protocol", STD 6, RFC 768, + August 1980. + + [RFC0791] Postel, J., "Internet Protocol", STD 5, RFC 791, + September 1981. + + [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate + Requirement Levels", BCP 14, RFC 2119, March 1997. + + [RFC5226] Narten, T. and H. Alvestrand, "Guidelines for Writing an + IANA Considerations Section in RFCs", BCP 26, RFC 5226, + May 2008. + +9.2. Informative References + + [ETYPES] The IEEE Registration Authority, "IEEE 802 Numbers", 2012, + . + + [IEEE8021Q] + The IEEE Computer Society, "Media Access Control (MAC) + Bridges and Virtual Bridge Local Area Networks", August + 2012, . + + [RFC1700] Reynolds, J. and J. Postel, "Assigned Numbers", RFC 1700, + October 1994. + + [RFC6830] Farinacci, D., Fuller, V., Meyer, D., and D. Lewis, "The + Locator/ID Separation Protocol (LISP)", RFC 6830, + January 2013. + + [RFC6834] Iannone, L., Saucez, D., and O. Bonaventure, "Locator/ID + Separation Protocol (LISP) Map-Versioning", RFC 6834, + January 2013. + + [VXLAN] Dutt, D., Mahalingam, M., Duda, K., Agarwal, P., Kreeger, + L., Sridhar, T., Bursell, M., and C. Wright, "VXLAN: A + Framework for Overlaying Virtualized Layer 2 Networks over + Layer 3 Networks", 2013. + + + + + + + +Lewis, et al. Expires January 5, 2015 [Page 14] + +Internet-Draft LISP Generic Protocol Extension July 2014 + + +Authors' Addresses + + Darrel Lewis + Cisco Systems, Inc. + + Email: darlewis@cisco.com + + + Puneet Agarwal + Broadcom + + Email: pagarwal@broadcom.com + + + Larry Kreeger + Cisco Systems, Inc. + + Email: kreeger@cisco.com + + + Fabio Maino + Cisco Systems, Inc. + + Email: fmaino@cisco.com + + + Paul Quinn + Cisco Systems, Inc. + + Email: paulq@cisco.com + + + Michael Smith + Cisco Systems, Inc. + + Email: michsmit@cisco.com + + + Navindra Yadav + Cisco Systems, Inc. + + Email: nyadav@cisco.com diff --git a/src/plugins/lisp/test/lisp_cp_test.c b/src/plugins/lisp/test/lisp_cp_test.c new file mode 100644 index 00000000000..228ff32d010 --- /dev/null +++ b/src/plugins/lisp/test/lisp_cp_test.c @@ -0,0 +1,1442 @@ +/* + * Copyright (c) 2019 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +#define _assert(e) \ + error = CLIB_ERROR_ASSERT (e); \ + if (error) \ + { \ + fformat(stderr, "FAIL: line %d \n\n", __LINE__); \ + goto done; \ + } + +static void +print_chunk (u8 * b, int *offset, int c, char *des) +{ + int i, n = offset[0] + c;; + for (i = offset[0]; i < n; i++) + { + printf ("0x%02x, ", b[i]); + } + printf (" // %s\n", des); + *offset += c; +} + +void +print_map_request (map_request_hdr_t * h) +{ +#define pchunk(_count, _desc) \ + print_chunk((u8 *)h, &offset, _count, _desc) + + int offset = 0; + + pchunk (4, "data"); + pchunk (8, "Nonce"); + pchunk (2, "Source-EID-AFI"); + pchunk (4, "Source EID Address"); + pchunk (2, "ITR-RLOC-AFI 1"); + pchunk (4, "ITR-RLOC Address 1"); + pchunk (2, "ITR-RLOC-AFI 2"); + pchunk (16, "ITR-RLOC Address 2"); + pchunk (1, "REC: reserved"); + pchunk (1, "REC: EID mask-len"); + pchunk (2, "REC: EID-prefix-AFI"); + pchunk (4, "REC: EID-prefix"); + printf ("\n"); +} + +static clib_error_t * +test_lisp_msg_push_ecm () +{ + vlib_main_t *vm = vlib_get_main (); + clib_error_t *error = 0; + gid_address_t la, ra; + vlib_buffer_t *b = 0; + u32 buff_len = 900; + int lp = 0x15, rp = 0x14; + + b = clib_mem_alloc (buff_len); + clib_memset ((u8 *) b, 0, buff_len); + b->current_length = buff_len; + b->current_data = sizeof (udp_header_t) + sizeof (ip4_header_t) + + sizeof (ecm_hdr_t) + 1; + + la.type = GID_ADDR_IP_PREFIX; + la.ippref.addr.ip.ip4.as_u32 = 0xa1b2c3d4; + la.ippref.addr.version = AF_IP4; + + ra.type = GID_ADDR_IP_PREFIX; + ra.ippref.addr.ip.ip4.as_u32 = 0x90817263; + ra.ippref.addr.version = AF_IP4; + + ecm_hdr_t *lh = lisp_msg_push_ecm (vm, b, lp, rp, &la, &ra); + + u8 expected_ecm_hdr[] = { + 0x80, 0x00, 0x00, 0x00 + }; + _assert (0 == memcmp (expected_ecm_hdr, lh, sizeof (expected_ecm_hdr))); + + ip4_header_t *ih = (ip4_header_t *) (lh + 1); + /* clear ip checksum */ + clib_memset ((u8 *) ih + 10, 0, 2); + + /* *INDENT-OFF* */ + u8 expected_ip4_hdr[] = { + 0x45, /* version; IHL */ + 0x00, /* services */ + 0x03, 0xa0, /* total length */ + 0x00, 0x00, /* identification */ + 0x40, 0x00, /* flags; fragment offset*/ + 0xff, /* TTL */ + 0x11, /* protocol */ + 0x00, 0x00, /* header checksum */ + 0xd4, 0xc3, 0xb2, 0xa1, /* src IP */ + 0x63, 0x72, 0x81, 0x90, /* dst IP */ + }; + /* *INDENT-ON* */ + + _assert (0 == memcmp (ih, expected_ip4_hdr, sizeof (expected_ip4_hdr))); + + udp_header_t *uh = (udp_header_t *) (ih + 1); + /* clear udp checksum */ + clib_memset ((u8 *) uh + 6, 0, 2); + + /* *INDENT-OFF* */ + u8 expected_udp_hdr[] = { + 0x00, 0x15, /* src port */ + 0x00, 0x14, /* dst port */ + 0x03, 0x8c, /* length */ + 0x00, 0x00, /* checksum */ + }; + /* *INDENT-ON* */ + + _assert (0 == memcmp (uh, expected_udp_hdr, sizeof (expected_udp_hdr))); + +done: + clib_mem_free (b); + return error; +} + +static clib_error_t * +test_lisp_msg_parse_mapping_record () +{ + clib_error_t *error = 0; + locator_t probed; + locator_t *locs = 0; + vlib_buffer_t *b = 0; + gid_address_t eid; + u32 buff_len = 500; + + b = clib_mem_alloc (buff_len); + clib_memset ((u8 *) b, 0, buff_len); + + /* *INDENT-OFF* */ + u8 map_reply_records[] = { + /* 1. record */ + 0x01, 0x02, 0x03, 0x04, /* record TTL */ + 0x01, /* locator count */ + 0x00, 0x00, 0x00, /* eid-mask-len; ... */ + 0x00, 0x00, /* reserved; map-version num */ + 0x00, 0x01, /* EID-Prefix-AFI */ + 0x33, 0x44, 0x55, 0x66, /* eid-prefix */ + /* loc */ + 0x0a, /* prority */ + 0x0b, /* weight */ + 0x0c, /* m-prority */ + 0x0d, /* m-weight */ + 0x00, 0x00, /* unused flags */ + 0x00, 0x01, /* Loc-AFI */ + 0xaa, 0xbb, 0xcc, 0xdd, /* Loator */ + }; + /* *INDENT-ON* */ + + b->current_length = buff_len; + clib_memcpy (b->data, map_reply_records, sizeof (map_reply_records)); + + lisp_msg_parse_mapping_record (b, &eid, &locs, &probed); + _assert (vec_len (locs) == 1); + _assert (eid.ippref.addr.ip.ip4.as_u32 == 0x66554433); + _assert (locs[0].local == 0); + _assert (locs[0].address.ippref.addr.ip.ip4.as_u32 == 0xddccbbaa); + _assert (locs[0].address.type == GID_ADDR_IP_PREFIX); + _assert (locs[0].priority == 0xa); + _assert (locs[0].weight == 0xb); + _assert (locs[0].mpriority == 0xc); + _assert (locs[0].mweight == 0xd); + +done: + clib_mem_free (b); + if (locs) + vec_free (locs); + return error; +} + +static map_request_hdr_t * +build_map_request (lisp_cp_main_t * lcm, vlib_buffer_t * b, + gid_address_t * rlocs) +{ + gid_address_t _seid, *seid = &_seid; + gid_address_t _deid, *deid = &_deid; + u8 is_smr_invoked = 1; + u8 rloc_probe_set = 0; + u64 nonce = 0; + map_request_hdr_t *h = 0; + clib_memset (deid, 0, sizeof (deid[0])); + clib_memset (seid, 0, sizeof (seid[0])); + + gid_address_type (seid) = GID_ADDR_IP_PREFIX; + ip_address_t *ip_addr = &gid_address_ip (seid); + ip_addr_v4 (ip_addr).as_u32 = 0x12345678; + seid->ippref.addr.version = AF_IP4; + + gid_address_type (deid) = GID_ADDR_IP_PREFIX; + ip_address_t *ip_addr2 = &gid_address_ip (deid); + ip_addr_v4 (ip_addr2).as_u32 = 0x9abcdef0; + deid->ippref.addr.version = AF_IP4; + gid_address_ippref_len (deid) = 24; + + h = lisp_msg_put_mreq (lcm, b, seid, deid, rlocs, + is_smr_invoked, rloc_probe_set, &nonce); + vec_free (rlocs); + return h; +} + +static void +generate_rlocs (gid_address_t ** rlocs, u32 * count) +{ + gid_address_t gid_addr_data, *gid_addr = &gid_addr_data; + clib_memset (gid_addr, 0, sizeof (gid_addr[0])); + ip_address_t *addr = &gid_address_ip (gid_addr); + + gid_address_type (gid_addr) = GID_ADDR_IP_PREFIX; + + ip_addr_version (addr) = AF_IP4; + ip_addr_v4 (addr).data_u32 = 0x10203040; + vec_add1 (rlocs[0], gid_addr[0]); + + ip_addr_v6 (addr).as_u32[0] = 0xffeeddcc; + ip_addr_v6 (addr).as_u32[1] = 0xbbaa9988; + ip_addr_v6 (addr).as_u32[2] = 0x77665544; + ip_addr_v6 (addr).as_u32[3] = 0x33221100; + ip_addr_version (addr) = AF_IP6; + vec_add1 (rlocs[0], gid_addr[0]); +} + +static clib_error_t * +test_lisp_msg_parse () +{ + gid_address_t eid; + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + map_request_hdr_t *h; + gid_address_t gid; + clib_error_t *error = 0; + vlib_buffer_t *b; + gid_address_t *rlocs_decode = 0, *rlocs = 0; + u32 rloc_count_parse = 0; + + u8 *data = clib_mem_alloc (500); + clib_memset (data, 0, 500); + b = (vlib_buffer_t *) data; + + generate_rlocs (&rlocs_decode, &rloc_count_parse); + h = build_map_request (lcm, b, rlocs_decode); + + vlib_buffer_pull (b, sizeof (*h)); + u32 len = lisp_msg_parse_addr (b, &gid); + _assert (len == 2 + 4 + /* Source-EID-AFI field lenght + IPv4 address length */ ); + _assert (gid.ippref.addr.ip.ip4.as_u32 == 0x12345678); + _assert (gid.ippref.addr.version == AF_IP4); + + u8 rloc_count = MREQ_ITR_RLOC_COUNT (h) + 1; + lisp_msg_parse_itr_rlocs (b, &rlocs, rloc_count); + + _assert (vec_len (rlocs) == 2); + _assert (rlocs[0].ippref.addr.ip.ip4.as_u32 == 0x10203040); + _assert (rlocs[0].ippref.addr.version == AF_IP4); + + _assert (rlocs[1].ippref.addr.ip.ip6.as_u32[0] == 0xffeeddcc); + _assert (rlocs[1].ippref.addr.ip.ip6.as_u32[1] == 0xbbaa9988); + _assert (rlocs[1].ippref.addr.ip.ip6.as_u32[2] == 0x77665544); + _assert (rlocs[1].ippref.addr.ip.ip6.as_u32[3] == 0x33221100); + _assert (rlocs[1].ippref.addr.version == AF_IP6); + + lisp_msg_parse_eid_rec (b, &eid); + _assert (eid.ippref.addr.ip.ip4.as_u32 == 0x9abcdef0); + _assert (eid.ippref.addr.version == AF_IP4); + _assert (eid.ippref.len == 24); + +done: + clib_mem_free (data); + if (rlocs) + vec_free (rlocs); + return error; +} + +static clib_error_t * +test_lisp_msg_put_mreq_with_lcaf () +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + clib_error_t *error = 0; + map_request_hdr_t *h = 0; + gid_address_t *rlocs = 0; + + ip_prefix_t ippref; + ip_prefix_version (&ippref) = AF_IP4; + ip4_address_t *ip = &ip_prefix_v4 (&ippref); + ip->as_u32 = 0x11223344; + ippref.len = 32; + + gid_address_t g = { + .type = GID_ADDR_IP_PREFIX, + .ippref = ippref, + .vni = 0x90919293, + .vni_mask = 0x17 + }; + vec_add1 (rlocs, g); + + u8 *data = clib_mem_alloc (500); + clib_memset (data, 0, 500); + + h = build_map_request (lcm, (vlib_buffer_t *) data, rlocs); + + /* clear Nonce to simplify comparison */ + clib_memset ((u8 *) h + 4, 0, 8); + + /* *INDENT-OFF* */ + u8 expected_data[] = + { + 0x10, 0x40, 0x00, 0x01, /* type; flags; IRC; REC count */ + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, /* nonce */ + 0x00, 0x01, /* Source-EID-AFI */ + 0x78, 0x56, 0x34, 0x12, /* Source EID Address */ + + /* RLOCs */ + 0x40, 0x03, /* AFI = LCAF*/ + /* LCAF header*/ + 0x00, 0x00, /* reserved1, flags */ + 0x02, /* type = Instance ID */ + 0x17, /* IID mask-len */ + 0x00, 0x0a, /* lenght */ + 0x90, 0x91, 0x92, 0x93, /* IID / VNI */ + + 0x00, 0x01, /* AFI = ipv4 */ + 0x44, 0x33, 0x22, 0x11, /* ITR-RLOC Address 1 */ + + /* record */ + 0x00, /* reserved */ + 0x18, /* EID mask-len */ + 0x00, 0x01, /* EID-prefix-AFI */ + 0xf0, 0xde, 0xbc, 0x9a, /* EID-prefix */ + }; + /* *INDENT-ON* */ + + _assert (0 == memcmp (expected_data, (u8 *) h, sizeof (expected_data))); +done: + clib_mem_free (data); + return error; +} + +static clib_error_t * +test_lisp_msg_put_mreq () +{ + lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); + clib_error_t *error = 0; + map_request_hdr_t *h; + gid_address_t *rlocs = 0; + u32 rloc_count = 0; + + u8 *data = clib_mem_alloc (500); + clib_memset (data, 0, 500); + + generate_rlocs (&rlocs, &rloc_count); + h = build_map_request (lcm, (vlib_buffer_t *) data, rlocs); + + /* clear Nonce to simplify comparison */ + clib_memset ((u8 *) h + 4, 0, 8); + + print_map_request (h); + + /* *INDENT-OFF* */ + u8 expected_data[50] = { + 0x10, 0x40, 0x01, 0x01, /* type; flags; IRC; REC count */ + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, /* nonce */ + 0x00, 0x01, /* Source-EID-AFI */ + 0x78, 0x56, 0x34, 0x12, /* Source EID Address */ + + /* RLOCs */ + 0x00, 0x01, /* ITR-RLOC-AFI 1 */ + 0x40, 0x30, 0x20, 0x10, /* ITR-RLOC Address 1 */ + 0x00, 0x02, /* ITR-RLOC-AFI 2 */ + 0xcc, 0xdd, 0xee, 0xff, + 0x88, 0x99, 0xaa, 0xbb, + 0x44, 0x55, 0x66, 0x77, + 0x00, 0x11, 0x22, 0x33, /* ITR-RLOC Address 2 */ + + /* record */ + 0x00, /* reserved */ + 0x18, /* EID mask-len */ + 0x00, 0x01, /* EID-prefix-AFI */ + 0xf0, 0xde, 0xbc, 0x9a, /* EID-prefix */ + }; + /* *INDENT-ON* */ + + _assert (0 == memcmp (expected_data, (u8 *) h, sizeof (expected_data))); + +done: + clib_mem_free (data); + return error; +} + +/* generate a vector of eid records */ +static mapping_t * +build_test_map_records () +{ + mapping_t *records = 0; + + /* *INDENT-OFF* */ + mapping_t r = { + .ttl = MAP_REGISTER_DEFAULT_TTL, + .eid = { + .type = GID_ADDR_MAC, + .mac = {1, 2, 3, 4, 5, 6}, + .vni = 0x0 + } + }; + + locator_t loc = { + .weight = 1, + .priority = 2, + .local = 1, + .address = { + .type = GID_ADDR_IP_PREFIX, + .ippref = { + .addr = { + .ip.ip4.as_u32 = 0x99887766, + .version = AF_IP4 + } + } + } + }; + /* *INDENT-ON* */ + + vec_add1 (r.locators, loc); + vec_add1 (records, r); + + return records; +} + +static void +free_test_map_records (mapping_t * maps) +{ + mapping_t *map; + vec_foreach (map, maps) + { + vec_free (map->locators); + } + vec_free (maps); +} + +static clib_error_t * +test_lisp_map_register () +{ + vlib_buffer_t *b; + clib_error_t *error = 0; + u64 nonce; + u32 msg_len = 0; + mapping_t *records = build_test_map_records (); + + u8 *data = clib_mem_alloc (500); + clib_memset (data, 0, 500); + b = (vlib_buffer_t *) data; + + lisp_msg_put_map_register (b, records, 1 /* want map notify */ , + 20 /* length of HMAC_SHA_1_96 */ , + &nonce, &msg_len); + free_test_map_records (records); + + /* clear Nonce to simplify comparison */ + clib_memset ((u8 *) b->data + 4, 0, 8); + + /* clear authentication data */ + clib_memset ((u8 *) b->data + 16, 0, 20); + + /* *INDENT-OFF* */ + u8 expected_data[] = { + 0x30, 0x00, 0x01, 0x01, /* type; rsvd; want notify; REC count */ + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, /* nonce */ + 0x00, 0x00, 0x00, 0x00, /* key id, auth data length: + both are zeroes because those are set in another + function (see auth_data_len_by_key_id())*/ + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, /* auth data */ + + /* first record */ + /* 0x00, 0x00, 0x03, 0x84, */ /* default ttl (15 minues) */ + 0x00, 0x01, 0x51, 0x80, /* default ttl (24h = 86400s) */ + 0x01, 0x00, 0x00, 0x00, /* loc count, eid len, ACT, A */ + 0x00, 0x00, 0x40, 0x05, /* rsvd, map ver num, AFI = MAC */ + 0x01, 0x02, 0x03, 0x04, + 0x05, 0x06, /* MAC EID */ + + /* locator 1 */ + 0x02, 0x01, 0x00, 0x00, /* prio, weight, mprio, mweight */ + 0x00, 0x04, 0x00, 0x01, /* flags, AFI = ipv4 */ + 0x66, 0x77, 0x88, 0x99, /* ipv4 locator address */ + }; + /* *INDENT-ON* */ + + _assert (0 == memcmp (expected_data, b->data, sizeof (expected_data))); +done: + clib_mem_free (data); + return error; +} + +static vlib_buffer_t * +create_buffer (u8 * data, u32 data_len) +{ + vlib_buffer_t *b; + + u8 *buf_data = clib_mem_alloc (500); + clib_memset (buf_data, 0, 500); + b = (vlib_buffer_t *) buf_data; + + u8 *p = vlib_buffer_put_uninit (b, data_len); + clib_memcpy (p, data, data_len); + + return b; +} + +static clib_error_t * +test_lisp_parse_map_reply () +{ + clib_error_t *error = 0; + + /* *INDENT-OFF* */ + u8 map_reply_data[] = + { + 0x00, 0x00, 0x00, 0x01, /* type; rsvd; mapping count */ + 0x00, 0x00, 0x00, 0x00, + }; + /* *INDENT-ON* */ + + vlib_buffer_t *b = create_buffer (map_reply_data, sizeof (map_reply_data)); + map_records_arg_t *mrecs = parse_map_reply (b); + _assert (0 == mrecs); + clib_mem_free (b); + + /* *INDENT-OFF* */ + u8 map_reply_data2[] = + { + 0x00, 0x00, 0x00, 0x01, /* type; rsvd */ + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, /* nonce */ + + /* 1. record - incomplete */ + 0x01, 0x02, 0x03, 0x04, /* record TTL */ + 0x01, /* locator count */ + }; + /* *INDENT-ON* */ + + b = create_buffer (map_reply_data2, sizeof (map_reply_data2)); + mrecs = parse_map_reply (b); + _assert (0 == mrecs); +done: + clib_mem_free (b); + return error; +} + +static clib_error_t * +test_lisp_parse_lcaf () +{ + int i; + clib_error_t *error = 0; + gid_address_t eid; + locator_t *locs = 0; + locator_t probed; + vlib_buffer_t *b = 0; + u32 buff_len = 500; + + b = clib_mem_alloc (buff_len); + clib_memset ((u8 *) b, 0, buff_len); + + /* *INDENT-OFF* */ + u8 map_reply_records[] = + { + /* 1. record */ + 0x01, 0x02, 0x03, 0x04, /* record TTL */ + 0x03, /* locator count */ + 0x00, 0x00, 0x00, /* eid-mask-len; ... */ + 0x00, 0x00, /* reserved; map-version num */ + 0x00, 0x01, /* EID-Prefix-AFI */ + 0x33, 0x44, 0x55, 0x66, /* eid-prefix */ + + /* 1st locator */ + 0x0a, /* prority */ + 0x0b, /* weight */ + 0x0c, /* m-prority */ + 0x0d, /* m-weight */ + 0x00, 0x00, /* unused flags */ + 0x40, 0x03, /* Loc-AFI = LCAF*/ + + /* LCAF header*/ + 0x00, 0x00, /* reserved1, flags */ + 0x02, /* type = Instance ID */ + 0x18, /* IID mask-len */ + 0x00, 0x0a, /* lenght */ + /* LCAF Instance ID */ + 0x00, 0x00, 0x00, 0x09, /* iid */ + 0x00, 0x01, /* AFI = ipv4 */ + 0x10, 0xbb, 0xcc, 0xdd, /* ipv4 loator address */ + + /* 2nd locator */ + 0x07, /* prority */ + 0x06, /* weight */ + 0x05, /* m-prority */ + 0x04, /* m-weight */ + 0x00, 0x00, /* unused flags */ + 0x40, 0x03, /* Loc-AFI = LCAF*/ + + /* LCAF header*/ + 0x00, 0x00, /* reserved1, flags */ + 0x02, /* type = Instance ID */ + 0x18, /* IID mask-len */ + 0x00, 0x16, /* iid length + next AFI lenght */ + /* LCAF Instance ID */ + 0x22, 0x44, 0x66, 0x88, /* iid */ + 0x00, 0x02, /* AFI = ipv6 */ + 0xcc, 0xdd, 0xee, 0xff, + 0x88, 0x99, 0xaa, 0xbb, + 0x44, 0x55, 0x66, 0x77, + 0x00, 0x11, 0x22, 0x33, /* ipv6 locator address */ + + /* 3rd locator */ + 0x0a, /* prority */ + 0x0b, /* weight */ + 0x0c, /* m-prority */ + 0x0d, /* m-weight */ + 0x00, 0x00, /* unused flags */ + 0x00, 0x01, /* Loc-AFI */ + 0xaa, 0xbb, 0xcc, 0xdd, /* Loator */ + }; + /* *INDENT-ON* */ + + b->current_length = buff_len; + memcpy (b->data, map_reply_records, sizeof (map_reply_records)); + + lisp_msg_parse_mapping_record (b, &eid, &locs, &probed); + _assert (vec_len (locs) == 3); + _assert (eid.ippref.addr.ip.ip4.as_u32 == 0x66554433); + + /* check 1st locator - an LCAF with ipv4 */ + _assert (locs[0].local == 0); + _assert (locs[0].priority == 0xa); + _assert (locs[0].weight == 0xb); + _assert (locs[0].mpriority == 0xc); + _assert (locs[0].mweight == 0xd); + + _assert (gid_address_type (&locs[0].address) == GID_ADDR_IP_PREFIX); + _assert (gid_address_vni (&locs[0].address) == 0x09); + ip_prefix_t *ip_pref = &gid_address_ippref (&locs[0].address); + _assert (AF_IP4 == ip_prefix_version (ip_pref)); + + /* 2nd locator - LCAF entry with ipv6 address */ + _assert (locs[1].local == 0); + _assert (locs[1].priority == 0x7); + _assert (locs[1].weight == 0x6); + _assert (locs[1].mpriority == 0x5); + _assert (locs[1].mweight == 0x4); + + _assert (gid_address_type (&locs[1].address) == GID_ADDR_IP_PREFIX); + _assert (0x22446688 == gid_address_vni (&locs[1].address)); + ip_pref = &gid_address_ippref (&locs[1].address); + _assert (AF_IP6 == ip_prefix_version (ip_pref)); + + /* 3rd locator - simple ipv4 address */ + _assert (gid_address_type (&locs[2].address) == GID_ADDR_IP_PREFIX); +done: + clib_mem_free (b); + + for (i = 0; i < 3; i++) + locator_free (&locs[i]); + vec_free (locs); + return error; +} + +#define foreach_test_case \ + _(lisp_msg_put_mreq) \ + _(lisp_msg_put_mreq_with_lcaf) \ + _(lisp_msg_push_ecm) \ + _(lisp_msg_parse) \ + _(lisp_msg_parse_mapping_record) \ + _(lisp_parse_map_reply) \ + _(lisp_parse_lcaf) \ + _(lisp_map_register) + +static int +lisp_cp_serdes_tests (vlib_main_t * vm, unformat_input_t * input) +{ + clib_error_t *error; + +#define _(_test_name) \ + error = test_ ## _test_name (); \ + if (error) \ + { \ + fformat (stderr, "FAIL: test_" #_test_name "\n"); \ + return -1; \ + } \ + else \ + fformat (stderr, "PASS: test_" #_test_name "\n"); \ + + foreach_test_case +#undef _ + return 0; +} + +static clib_error_t * +test_locator_type (void) +{ + clib_error_t *error = 0; + gid_address_t _gid_addr, *gid = &_gid_addr; + ip_prefix_t *ippref; + gid_address_type (gid) = GID_ADDR_IP_PREFIX; + gid_address_ippref_len (gid) = 24; + ippref = &gid_address_ippref (gid); + ip_prefix_version (ippref) = AF_IP4; + ip_prefix_len (ippref) = 0; + ip4_address_t *ip4 = &ip_prefix_v4 (ippref); + ip4->as_u32 = 0x20304050; + + /* local locator */ + locator_t loc1, loc2 = { + .local = 1, + .state = 2, + .sw_if_index = 8, + .priority = 3, + .weight = 100, + .mpriority = 4, + .mweight = 101 + }; + locator_copy (&loc1, &loc2); + _assert (0 == locator_cmp (&loc1, &loc2)); + + /* remote locator */ + loc2.local = 0; + + ip_prefix_t nested_ippref; + ip_prefix_version (&nested_ippref) = AF_IP4; + ip_prefix_len (&nested_ippref) = 0; + ip4 = &ip_prefix_v4 (&nested_ippref); + ip4->as_u32 = 0x33882299; + gid_address_t nested_gid = { + .type = GID_ADDR_IP_PREFIX, + .ippref = nested_ippref + }; + + lcaf_t lcaf = { + .type = LCAF_INSTANCE_ID, + .uni = { + .vni_mask_len = 5, + .vni = 0xa1b2c3d4, + .gid_addr = &nested_gid} + }; + gid_address_type (gid) = GID_ADDR_LCAF; + gid_address_lcaf (gid) = lcaf; + + loc2.address = gid[0]; + locator_copy (&loc1, &loc2); + + _assert (0 == locator_cmp (&loc1, &loc2)); + +done: + locator_free (&loc1); + return error; +} + +static clib_error_t * +test_gid_parse_ip_pref () +{ + clib_error_t *error = 0; + gid_address_t _gid_addr, *gid_addr = &_gid_addr; + gid_address_t _gid_addr_copy, *copy = &_gid_addr_copy; + + /* *INDENT-OFF* */ + u8 data[] = + { + 0x00, 0x01, /* AFI = IPv4 */ + 0x10, 0xbb, 0xcc, 0xdd, /* ipv4 address */ + }; + /* *INDENT-ON* */ + + u32 len = gid_address_parse (data, gid_addr); + _assert (6 == len); + gid_address_copy (copy, gid_addr); + _assert (0 == gid_address_cmp (copy, gid_addr)); +done: + return error; +} + +static clib_error_t * +test_gid_parse_mac () +{ + clib_error_t *error = 0; + gid_address_t _gid, *gid = &_gid; + gid_address_t _gid_copy, *gid_copy = &_gid_copy; + + /* *INDENT-OFF* */ + u8 data[] = + { + 0x40, 0x05, /* AFI = MAC address */ + 0x10, 0xbb, 0xcc, 0xdd, /* MAC */ + 0x77, 0x99, + }; + /* *INDENT-ON* */ + + u32 len = gid_address_parse (data, gid); + _assert (8 == len); + _assert (GID_ADDR_MAC == gid_address_type (gid)); + gid_address_copy (gid_copy, gid); + _assert (0 == gid_address_cmp (gid_copy, gid)); +done: + return error; +} + +static clib_error_t * +test_gid_write_nsh (void) +{ + clib_error_t *error = 0; + + u8 *b = clib_mem_alloc (500); + clib_memset (b, 0, 500); + + gid_address_t g = { + .vni = 0, + .nsh.spi = 0x112233, + .nsh.si = 0x42, + .type = GID_ADDR_NSH, + }; + + u16 len = gid_address_put (b, &g); + + /* *INDENT-OFF* */ + u8 expected[] = + { + 0x40, 0x03, 0x00, 0x00, /* AFI = LCAF*/ + 0x11, 0x00, 0x00, 0x04, /* type = SPI LCAF, length = 4 */ + + /* Service Path ID, Service index */ + 0x11, 0x22, 0x33, 0x42, /* SPI, SI */ + }; + /* *INDENT-ON* */ + + _assert (sizeof (expected) == len); + _assert (0 == memcmp (expected, b, len)); +done: + clib_mem_free (b); + return error; +} + +static clib_error_t * +test_gid_parse_nsh () +{ + clib_error_t *error = 0; + gid_address_t _gid_addr, *gid_addr = &_gid_addr; + gid_address_t _gid_addr_copy, *copy = &_gid_addr_copy; + + clib_memset (gid_addr, 0, sizeof (gid_addr[0])); + clib_memset (copy, 0, sizeof (copy[0])); + + /* *INDENT-OFF* */ + u8 data[] = + { + 0x40, 0x03, 0x00, 0x00, /* AFI = LCAF*/ + 0x11, 0x00, 0x00, 0x04, /* type = SPI LCAF, length = 4 */ + + /* Service Path ID, Service index */ + 0x55, 0x99, 0x42, 0x09, /* SPI, SI */ + }; + /* *INDENT-ON* */ + + u32 len = gid_address_parse (data, gid_addr); + _assert (sizeof (data) == len); + gid_address_copy (copy, gid_addr); + _assert (0 == gid_address_cmp (gid_addr, copy)); + _assert (GID_ADDR_NSH == gid_address_type (copy)); + _assert (0 == gid_address_vni (copy)); + _assert (gid_address_nsh_spi (copy) == 0x559942); + _assert (gid_address_nsh_si (copy) == 0x09); + +done: + gid_address_free (copy); + gid_address_free (gid_addr); + return error; +} + +static clib_error_t * +test_gid_parse_lcaf () +{ + clib_error_t *error = 0; + gid_address_t _gid_addr, *gid_addr = &_gid_addr; + gid_address_t _gid_addr_copy, *gid_addr_copy = &_gid_addr_copy; + + clib_memset (gid_addr, 0, sizeof (gid_addr[0])); + clib_memset (gid_addr_copy, 0, sizeof (gid_addr_copy[0])); + + /* *INDENT-OFF* */ + u8 data[] = + { + 0x40, 0x03, /* AFI = LCAF*/ + + /* LCAF header*/ + 0x00, 0x00, /* reserved1, flags */ + 0x02, /* type = Instance ID */ + 0x18, /* IID mask-len */ + 0x00, 0x0a, /* iid length + next AFI lenght */ + /* LCAF Instance ID */ + 0x00, 0x00, 0x00, 0x09, /* iid */ + 0x00, 0x01, /* AFI = ipv4 */ + 0x10, 0xbb, 0xcc, 0xdd, /* ipv4 address */ + }; + /* *INDENT-ON* */ + + u32 len = gid_address_parse (data, gid_addr); + _assert (18 == len); + gid_address_copy (gid_addr_copy, gid_addr); + _assert (0 == gid_address_cmp (gid_addr_copy, gid_addr)); + _assert (GID_ADDR_IP_PREFIX == gid_address_type (gid_addr)); + _assert (9 == gid_address_vni (gid_addr)); + _assert (0x18 == gid_address_vni_mask (gid_addr)); + _assert (0xddccbb10 == gid_addr->ippref.addr.ip.ip4.as_u32); + +done: + gid_address_free (gid_addr); + gid_address_free (gid_addr_copy); + return error; +} + +/* recursive LCAFs are not supported */ +#if 0 +static clib_error_t * +test_gid_parse_lcaf_complex () +{ + clib_error_t *error = 0; + gid_address_t _gid_addr, *gid_addr = &_gid_addr; + gid_address_t _gid_addr_copy, *gid_addr_copy = &_gid_addr_copy; + + clib_memset (gid_addr, 0, sizeof (gid_addr[0])); + clib_memset (gid_addr_copy, 0, sizeof (gid_addr_copy[0])); + + /* *INDENT-OFF* */ + u8 data[] = { + 0x40, 0x03, /* AFI = LCAF */ + + /* LCAF header */ + 0x00, 0x00, /* reserved1, flags */ + 0x02, /* type = Instance ID */ + 0x18, /* IID mask-len */ + 0x00, 0x0a, /* iid length + next AFI lenght */ + /* LCAF Instance ID */ + 0x00, 0x00, 0x00, 0x0b, /* iid */ + + 0x40, 0x03, /* AFI = LCAF */ + /* LCAF header */ + 0x00, 0x00, /* reserved1, flags */ + 0x02, /* type = Instance ID */ + 0x17, /* IID mask-len */ + 0x00, 0x0a, /* iid length + next AFI lenght */ + /* LCAF Instance ID */ + 0x00, 0x00, 0x00, 0x0c, /* iid */ + + 0x40, 0x03, /* AFI = LCAF */ + /* LCAF header */ + 0x00, 0x00, /* reserved1, flags */ + 0x02, /* type = Instance ID */ + 0x16, /* IID mask-len */ + 0x00, 0x16, /* iid length + next AFI lenght */ + /* LCAF Instance ID */ + 0x00, 0x00, 0x00, 0x0d, /* iid */ + + 0x00, 0x02, /* AFI = IPv6 */ + + 0x10, 0xbb, 0xcc, 0xdd, + 0x10, 0xbb, 0xcc, 0xdd, + 0x10, 0xbb, 0xcc, 0xdd, + 0x10, 0xbb, 0xcc, 0xdd, /* ipv6 address */ + }; + /* *INDENT-ON* */ + + u32 len = gid_address_parse (data, gid_addr); + _assert (54 == len); + _assert (gid_addr->type == GID_ADDR_LCAF); + gid_address_copy (gid_addr_copy, gid_addr); + _assert (0 == gid_address_cmp (gid_addr_copy, gid_addr)); + _assert (gid_addr_copy->type == GID_ADDR_LCAF); + + lcaf_t *lcaf = &gid_address_lcaf (gid_addr_copy); + _assert (lcaf->type == LCAF_INSTANCE_ID); + vni_t *v = (vni_t *) lcaf; + _assert (v->vni == 0x0b); + _assert (v->vni_mask_len == 0x18); + + gid_address_t *tmp = vni_gid (v); + _assert (gid_address_type (tmp) == GID_ADDR_LCAF); + lcaf = &gid_address_lcaf (tmp); + _assert (lcaf->type == LCAF_INSTANCE_ID); + + v = (vni_t *) lcaf; + _assert (v->vni == 0x0c); + _assert (v->vni_mask_len == 0x17); + + tmp = vni_gid (v); + _assert (gid_address_type (tmp) == GID_ADDR_LCAF); + lcaf = &gid_address_lcaf (tmp); + + _assert (lcaf->type == LCAF_INSTANCE_ID); + v = (vni_t *) lcaf; + _assert (v->vni == 0x0d); + _assert (v->vni_mask_len == 0x16); + + tmp = vni_gid (v); + _assert (gid_address_type (tmp) == GID_ADDR_IP_PREFIX); + + ip_prefix_t *ip_pref = &gid_address_ippref (tmp); + ip6_address_t *ip6 = &ip_prefix_v6 (ip_pref); + _assert (ip6->as_u32[0] == 0xddccbb10); + _assert (ip6->as_u32[1] == 0xddccbb10); + _assert (ip6->as_u32[2] == 0xddccbb10); + _assert (ip6->as_u32[3] == 0xddccbb10); + _assert (ip_prefix_version (ip_pref) == AF_IP6); + +done: + gid_address_free (gid_addr); + gid_address_free (gid_addr_copy); + return error; +} +#endif + +static clib_error_t * +test_write_mac_in_lcaf (void) +{ + clib_error_t *error = 0; + + u8 *b = clib_mem_alloc (500); + clib_memset (b, 0, 500); + + gid_address_t g = { + .mac = {0x1, 0x2, 0x3, 0x4, 0x5, 0x6}, + .vni = 0x01020304, + .vni_mask = 0x10, + .type = GID_ADDR_MAC, + }; + + u16 len = gid_address_put (b, &g); + + /* *INDENT-OFF* */ + u8 expected[] = + { + 0x40, 0x03, /* AFI = LCAF */ + 0x00, /* reserved1 */ + 0x00, /* flags */ + 0x02, /* LCAF type = Instance ID */ + 0x10, /* IID/IID mask len */ + 0x00, 0x0c, /* length */ + 0x01, 0x02, 0x03, 0x04, /* Instance ID / VNI */ + + 0x40, 0x05, /* AFI = MAC */ + 0x01, 0x02, 0x03, 0x04, + 0x05, 0x06 /* MAC */ + }; + /* *INDENT-ON* */ + + _assert (sizeof (expected) == len); + _assert (0 == memcmp (expected, b, len)); +done: + clib_mem_free (b); + return error; +} + +static clib_error_t * +test_mac_address_write (void) +{ + clib_error_t *error = 0; + + u8 *b = clib_mem_alloc (500); + clib_memset (b, 0, 500); + + gid_address_t g = { + .mac = {0x1, 0x2, 0x3, 0x4, 0x5, 0x6}, + .type = GID_ADDR_MAC, + }; + + u16 len = gid_address_put (b, &g); + _assert (8 == len); + + /* *INDENT-OFF* */ + u8 expected[] = + { + 0x40, 0x05, /* AFI = MAC */ + 0x01, 0x02, 0x03, 0x04, + 0x05, 0x06 /* MAC */ + }; + /* *INDENT-ON* */ + + _assert (0 == memcmp (expected, b, len)); +done: + clib_mem_free (b); + return error; +} + +static clib_error_t * +test_src_dst_with_vni_serdes (void) +{ + clib_error_t *error = 0; + u8 *b = clib_mem_alloc (500); + clib_memset (b, 0, 500); + + /* *INDENT-OFF* */ + fid_address_t src = + { + .type = FID_ADDR_IP_PREF, + .ippref = + { + .len = 24, + .addr = + { + .version = AF_IP4, + .ip.ip4.data = { 0x1, 0x2, 0x3, 0x0 } + } + } + }; + + fid_address_t dst = + { + .type = FID_ADDR_IP_PREF, + .ippref = + { + .len = 16, + .addr = + { + .version = AF_IP4, + .ip.ip4.data = { 0x9, 0x8, 0x0, 0x0 } + } + } + }; + + source_dest_t sd = + { + .src = src, + .dst = dst + }; + + gid_address_t g = + { + .sd = sd, + .type = GID_ADDR_SRC_DST, + .vni = 0x12345678, + .vni_mask = 0x9 + }; + + /* *INDENT-ON* */ + + u16 size_to_put = gid_address_size_to_put (&g); + _assert (36 == size_to_put); + _assert (0 == gid_address_len (&g)); + + u16 write_len = gid_address_put (b, &g); + _assert (size_to_put == write_len); + + /* *INDENT-OFF* */ + u8 expected_data[] = + { + 0x40, 0x03, 0x00, 0x00, /* AFI = LCAF, reserved1, flags */ + 0x02, 0x09, 0x00, 0x1c, /* LCAF type = IID, IID mask-len, length */ + 0x12, 0x34, 0x56, 0x78, /* reserved; source-ML, Dest-ML */ + + 0x40, 0x03, 0x00, 0x00, /* AFI = LCAF, reserved1, flags */ + 0x0c, 0x00, 0x00, 0x10, /* LCAF type = source/dest key, rsvd, length */ + 0x00, 0x00, 0x18, 0x10, /* reserved; source-ML, Dest-ML */ + + 0x00, 0x01, /* AFI = ip4 */ + 0x01, 0x02, 0x03, 0x00, /* source */ + + 0x00, 0x01, /* AFI = ip4 */ + 0x09, 0x08, 0x00, 0x00, /* destination */ + }; + /* *INDENT-ON* */ + + _assert (0 == memcmp (expected_data, b, sizeof (expected_data))); + + gid_address_t p; + clib_memset (&p, 0, sizeof (p)); + _assert (write_len == gid_address_parse (b, &p)); + _assert (0 == gid_address_cmp (&g, &p)); +done: + clib_mem_free (b); + return error; +} + +static clib_error_t * +test_src_dst_deser_bad_afi (void) +{ + clib_error_t *error = 0; + + /* *INDENT-OFF* */ + u8 expected_data[] = + { + 0x40, 0x03, 0x00, 0x00, /* AFI = LCAF, reserved1, flags */ + 0x0c, 0x00, 0x00, 0x14, /* LCAF type = source/dest key, rsvd, length */ + 0x00, 0x00, 0x00, 0x00, /* reserved; source-ML, Dest-ML */ + + 0xde, 0xad, /* AFI = bad value */ + 0x11, 0x22, 0x33, 0x44, + 0x55, 0x66, /* source */ + + 0x40, 0x05, /* AFI = MAC */ + 0x10, 0x21, 0x32, 0x43, + 0x54, 0x65, /* destination */ + }; + /* *INDENT-ON* */ + + gid_address_t p; + _assert (~0 == gid_address_parse (expected_data, &p)); +done: + return error; +} + +static clib_error_t * +test_src_dst_serdes (void) +{ + clib_error_t *error = 0; + + u8 *b = clib_mem_alloc (500); + clib_memset (b, 0, 500); + + fid_address_t src = { + .type = FID_ADDR_MAC, + .mac = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66} + }; + + fid_address_t dst = { + .type = FID_ADDR_MAC, + .mac = {0x10, 0x21, 0x32, 0x43, 0x54, 0x65} + }; + + source_dest_t sd = { + .src = src, + .dst = dst + }; + + gid_address_t g = { + .sd = sd, + .type = GID_ADDR_SRC_DST, + .vni = 0x0, + .vni_mask = 0x0 + }; + + u16 size_to_put = gid_address_size_to_put (&g); + _assert (28 == size_to_put); + _assert (0 == gid_address_len (&g)); + + u16 write_len = gid_address_put (b, &g); + _assert (size_to_put == write_len); + + /* *INDENT-OFF* */ + u8 expected_data[] = + { + 0x40, 0x03, 0x00, 0x00, /* AFI = LCAF, reserved1, flags */ + 0x0c, 0x00, 0x00, 0x14, /* LCAF type = source/dest key, rsvd, length */ + 0x00, 0x00, 0x00, 0x00, /* reserved; source-ML, Dest-ML */ + + 0x40, 0x05, /* AFI = MAC */ + 0x11, 0x22, 0x33, 0x44, + 0x55, 0x66, /* source */ + + 0x40, 0x05, /* AFI = MAC */ + 0x10, 0x21, 0x32, 0x43, + 0x54, 0x65, /* destination */ + }; + /* *INDENT-ON* */ + + _assert (0 == memcmp (expected_data, b, sizeof (expected_data))); + + gid_address_t p; + clib_memset (&p, 0, sizeof (p)); + _assert (write_len == gid_address_parse (b, &p)); + _assert (0 == gid_address_cmp (&g, &p)); +done: + clib_mem_free (b); + return error; +} + +static clib_error_t * +test_gid_address_write (void) +{ + clib_error_t *error = 0; + ip_prefix_t ippref_data, *ippref = &ippref_data; + + u8 *b = clib_mem_alloc (500); + clib_memset (b, 0, 500); + + ip_prefix_version (ippref) = AF_IP4; + ip_prefix_len (ippref) = 9; + ip4_address_t *ip4 = &ip_prefix_v4 (ippref); + ip4->as_u32 = 0xaabbccdd; + + gid_address_t g = { + .ippref = ippref[0], + .type = GID_ADDR_IP_PREFIX, + .vni = 0x01020304, + .vni_mask = 0x18 + }; + + _assert (18 == gid_address_size_to_put (&g)); + _assert (gid_address_len (&g) == 9); + + u16 write_len = gid_address_put (b, &g); + _assert (18 == write_len); + + /* *INDENT-OFF* */ + u8 expected_gid_data[] = + { + 0x40, 0x03, /* AFI = LCAF */ + 0x00, /* reserved1 */ + 0x00, /* flags */ + 0x02, /* LCAF type = Instance ID */ + 0x18, /* IID/VNI mask len */ + 0x00, 0x0a, /* length */ + 0x01, 0x02, 0x03, 0x04, /* Instance ID / VNI */ + + 0x00, 0x01, /* AFI = IPv4 */ + 0xdd, 0xcc, 0xbb, 0xaa, /* ipv4 addr */ + }; + /* *INDENT-ON* */ + + _assert (0 == memcmp (expected_gid_data, b, sizeof (expected_gid_data))); +done: + clib_mem_free (b); + return error; +} + +#undef foreach_test_case + +#define foreach_test_case \ + _(locator_type) \ + _(gid_parse_ip_pref) \ + _(gid_parse_mac) \ + _(gid_parse_lcaf) \ + _(gid_parse_nsh) \ + _(gid_write_nsh) \ + _(mac_address_write) \ + _(gid_address_write) \ + _(src_dst_serdes) \ + _(write_mac_in_lcaf) \ + _(src_dst_deser_bad_afi) \ + _(src_dst_with_vni_serdes) + +static int +lisp_cp_types_tests (vlib_main_t * vm, unformat_input_t * input) +{ + clib_error_t *error; + +#define _(_test_name) \ + error = test_ ## _test_name (); \ + if (error) \ + { \ + fformat (stderr, "FAIL: test_" #_test_name "\n"); \ + return -1; \ + } \ + else \ + fformat (stderr, "PASS: test_" #_test_name "\n"); \ + + foreach_test_case +#undef _ + return 0; +} + +#undef _assert + +static clib_error_t * +lisp_cp_test (vlib_main_t * vm, unformat_input_t * input, + vlib_cli_command_t * cmd_arg) +{ + int res = 0; + + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "serdes")) + { + res = lisp_cp_serdes_tests (vm, input); + } + if (unformat (input, "types")) + { + res = lisp_cp_types_tests (vm, input); + } + else if (unformat (input, "all")) + { + if ((res = lisp_cp_serdes_tests (vm, input))) + goto done; + if ((res = lisp_cp_types_tests (vm, input))) + goto done; + } + else + break; + } + +done: + if (res) + return clib_error_return (0, "rbtree unit test failed"); + return 0; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (lisp_cp_command, static) = +{ + .path = "test lisp cp", + .short_help = "lisp cp internal unit tests", + .function = lisp_cp_test, +}; +/* *INDENT-ON* */ + +#include +#include + +/* *INDENT-OFF* */ +VLIB_PLUGIN_REGISTER () = { + .version = VPP_BUILD_VER, + .description = "Test Locator ID Separation Protocol (LISP)", + .default_disabled = 1, +}; +/* *INDENT-ON* */ + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/plugins/lisp/test/test_lisp.py b/src/plugins/lisp/test/test_lisp.py new file mode 100644 index 00000000000..70cb4f4bf34 --- /dev/null +++ b/src/plugins/lisp/test/test_lisp.py @@ -0,0 +1,208 @@ +#!/usr/bin/env python3 + +import abc +import six +import unittest + +from scapy.fields import BitField, ByteField, FlagsField, IntField +from scapy.packet import bind_layers, Packet, Raw +from scapy.layers.inet import IP, UDP, Ether +from scapy.layers.inet6 import IPv6 + +from framework import VppTestCase, VppTestRunner +from lisp import VppLocalMapping, VppLispAdjacency, VppLispLocator, \ + VppLispLocatorSet, VppRemoteMapping, LispRemoteLocator +from util import ppp, ForeignAddressFactory + +# From py_lispnetworking.lisp.py: # GNU General Public License v2.0 + + +class LISP_GPE_Header(Packet): + name = "LISP GPE Header" + fields_desc = [ + FlagsField("gpe_flags", None, 6, ["N", "L", "E", "V", "I", "P"]), + BitField("reserved", 0, 18), + ByteField("next_proto", 0), + IntField("iid", 0), + ] +bind_layers(UDP, LISP_GPE_Header, dport=4341) +bind_layers(UDP, LISP_GPE_Header, sport=4341) +bind_layers(LISP_GPE_Header, IP, next_proto=1) +bind_layers(LISP_GPE_Header, IPv6, next_proto=2) +bind_layers(LISP_GPE_Header, Ether, next_proto=3) + + +@six.add_metaclass(abc.ABCMeta) +class Driver(object): + + config_order = ['locator-sets', + 'locators', + 'local-mappings', + 'remote-mappings', + 'adjacencies'] + + """ Basic class for data driven testing """ + def __init__(self, test, test_cases): + self._test_cases = test_cases + self._test = test + + @property + def test_cases(self): + return self._test_cases + + @property + def test(self): + return self._test + + def create_packet(self, src_if, dst_if, deid, payload=''): + """ + Create IPv4 packet + + param: src_if + param: dst_if + """ + packet = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) / + IP(src=src_if.remote_ip4, dst=deid) / + Raw(payload)) + return packet + + @abc.abstractmethod + def run(self): + """ testing procedure """ + pass + + +class SimpleDriver(Driver): + """ Implements simple test procedure """ + def __init__(self, test, test_cases): + super(SimpleDriver, self).__init__(test, test_cases) + + def verify_capture(self, src_loc, dst_loc, capture): + """ + Verify captured packet + + :param src_loc: source locator address + :param dst_loc: destination locator address + :param capture: list of captured packets + """ + self.test.assertEqual(len(capture), 1, "Unexpected number of " + "packets! Expected 1 but {} received" + .format(len(capture))) + packet = capture[0] + try: + ip_hdr = packet[IP] + # assert the values match + self.test.assertEqual(ip_hdr.src, src_loc, "IP source address") + self.test.assertEqual(ip_hdr.dst, dst_loc, + "IP destination address") + gpe_hdr = packet[LISP_GPE_Header] + self.test.assertEqual(gpe_hdr.next_proto, 1, + "next_proto is not ipv4!") + ih = gpe_hdr[IP] + self.test.assertEqual(ih.src, self.test.pg0.remote_ip4, + "unexpected source EID!") + self.test.assertEqual(ih.dst, self.test.deid_ip4, + "unexpected dest EID!") + except: + self.test.logger.error(ppp("Unexpected or invalid packet:", + packet)) + raise + + def configure_tc(self, tc): + for config_item in self.config_order: + for vpp_object in tc[config_item]: + vpp_object.add_vpp_config() + + def run(self, dest): + """ Send traffic for each test case and verify that it + is encapsulated """ + for tc in enumerate(self.test_cases): + self.test.logger.info('Running {}'.format(tc[1]['name'])) + self.configure_tc(tc[1]) + + packet = self.create_packet(self.test.pg0, self.test.pg1, dest, + 'data') + self.test.pg0.add_stream(packet) + self.test.pg0.enable_capture() + self.test.pg1.enable_capture() + self.test.pg_start() + capture = self.test.pg1.get_capture(1) + self.verify_capture(self.test.pg1.local_ip4, + self.test.pg1.remote_ip4, capture) + self.test.pg0.assert_nothing_captured() + + +class TestLisp(VppTestCase): + """ Basic LISP test """ + + @classmethod + def setUpClass(cls): + super(TestLisp, cls).setUpClass() + cls.faf = ForeignAddressFactory() + cls.create_pg_interfaces(range(2)) # create pg0 and pg1 + for i in cls.pg_interfaces: + i.admin_up() # put the interface upsrc_if + i.config_ip4() # configure IPv4 address on the interface + i.resolve_arp() # resolve ARP, so that we know VPP MAC + + @classmethod + def tearDownClass(cls): + super(TestLisp, cls).tearDownClass() + + def setUp(self): + super(TestLisp, self).setUp() + self.vapi.lisp_enable_disable(is_enable=1) + + def test_lisp_basic_encap(self): + """Test case for basic encapsulation""" + + self.deid_ip4_net = self.faf.net + self.deid_ip4 = self.faf.get_ip4() + self.seid_ip4 = '{!s}/{!s}'.format(self.pg0.local_ip4, 32) + self.rloc_ip4 = self.pg1.remote_ip4 + + test_cases = [ + { + 'name': 'basic ip4 over ip4', + 'locator-sets': [VppLispLocatorSet(self, 'ls-4o4')], + 'locators': [ + VppLispLocator(self, self.pg1.sw_if_index, 'ls-4o4') + ], + 'local-mappings': [ + VppLocalMapping(self, self.seid_ip4, 'ls-4o4') + ], + 'remote-mappings': [ + VppRemoteMapping(self, self.deid_ip4_net, + [LispRemoteLocator(self.rloc_ip4)]) + ], + 'adjacencies': [ + VppLispAdjacency(self, self.seid_ip4, self.deid_ip4_net) + ] + } + ] + self.test_driver = SimpleDriver(self, test_cases) + self.test_driver.run(self.deid_ip4) + + +class TestLispUT(VppTestCase): + """ Lisp UT """ + + @classmethod + def setUpClass(cls): + super(TestLispUT, cls).setUpClass() + + @classmethod + def tearDownClass(cls): + super(TestLispUT, cls).tearDownClass() + + def test_fib(self): + """ LISP Unit Tests """ + error = self.vapi.cli("test lisp cp") + + if error: + self.logger.critical(error) + self.assertNotIn("Failed", error) + + +if __name__ == '__main__': + unittest.main(testRunner=VppTestRunner) diff --git a/src/plugins/nsh/nsh-md2-ioam/md2_ioam_transit.c b/src/plugins/nsh/nsh-md2-ioam/md2_ioam_transit.c index 6c5abcce052..b69cd745e9b 100644 --- a/src/plugins/nsh/nsh-md2-ioam/md2_ioam_transit.c +++ b/src/plugins/nsh/nsh-md2-ioam/md2_ioam_transit.c @@ -18,8 +18,7 @@ #include #include #include -#include -#include +#include #include #include #include diff --git a/src/plugins/nsh/nsh-md2-ioam/nsh_md2_ioam_util.h b/src/plugins/nsh/nsh-md2-ioam/nsh_md2_ioam_util.h index 77cc8792c93..cdb06dab996 100644 --- a/src/plugins/nsh/nsh-md2-ioam/nsh_md2_ioam_util.h +++ b/src/plugins/nsh/nsh-md2-ioam/nsh_md2_ioam_util.h @@ -15,8 +15,7 @@ #ifndef __included_nsh_md2_ioam_util_h__ #define __included_nsh_md2_ioam_util_h__ -#include -#include +#include #include #include #include diff --git a/src/plugins/unittest/CMakeLists.txt b/src/plugins/unittest/CMakeLists.txt index 18780b6a607..ba6a82280f6 100644 --- a/src/plugins/unittest/CMakeLists.txt +++ b/src/plugins/unittest/CMakeLists.txt @@ -33,7 +33,6 @@ add_vpp_plugin(unittest fib_test.c interface_test.c ipsec_test.c - lisp_cp_test.c llist_test.c mactime_test.c mfib_test.c diff --git a/src/plugins/unittest/lisp_cp_test.c b/src/plugins/unittest/lisp_cp_test.c deleted file mode 100644 index ac6f65c7e47..00000000000 --- a/src/plugins/unittest/lisp_cp_test.c +++ /dev/null @@ -1,1432 +0,0 @@ -/* - * Copyright (c) 2019 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include - -#define _assert(e) \ - error = CLIB_ERROR_ASSERT (e); \ - if (error) \ - { \ - fformat(stderr, "FAIL: line %d \n\n", __LINE__); \ - goto done; \ - } - -static void -print_chunk (u8 * b, int *offset, int c, char *des) -{ - int i, n = offset[0] + c;; - for (i = offset[0]; i < n; i++) - { - printf ("0x%02x, ", b[i]); - } - printf (" // %s\n", des); - *offset += c; -} - -void -print_map_request (map_request_hdr_t * h) -{ -#define pchunk(_count, _desc) \ - print_chunk((u8 *)h, &offset, _count, _desc) - - int offset = 0; - - pchunk (4, "data"); - pchunk (8, "Nonce"); - pchunk (2, "Source-EID-AFI"); - pchunk (4, "Source EID Address"); - pchunk (2, "ITR-RLOC-AFI 1"); - pchunk (4, "ITR-RLOC Address 1"); - pchunk (2, "ITR-RLOC-AFI 2"); - pchunk (16, "ITR-RLOC Address 2"); - pchunk (1, "REC: reserved"); - pchunk (1, "REC: EID mask-len"); - pchunk (2, "REC: EID-prefix-AFI"); - pchunk (4, "REC: EID-prefix"); - printf ("\n"); -} - -static clib_error_t * -test_lisp_msg_push_ecm () -{ - vlib_main_t *vm = vlib_get_main (); - clib_error_t *error = 0; - gid_address_t la, ra; - vlib_buffer_t *b = 0; - u32 buff_len = 900; - int lp = 0x15, rp = 0x14; - - b = clib_mem_alloc (buff_len); - clib_memset ((u8 *) b, 0, buff_len); - b->current_length = buff_len; - b->current_data = sizeof (udp_header_t) + sizeof (ip4_header_t) + - sizeof (ecm_hdr_t) + 1; - - la.type = GID_ADDR_IP_PREFIX; - la.ippref.addr.ip.ip4.as_u32 = 0xa1b2c3d4; - la.ippref.addr.version = AF_IP4; - - ra.type = GID_ADDR_IP_PREFIX; - ra.ippref.addr.ip.ip4.as_u32 = 0x90817263; - ra.ippref.addr.version = AF_IP4; - - ecm_hdr_t *lh = lisp_msg_push_ecm (vm, b, lp, rp, &la, &ra); - - u8 expected_ecm_hdr[] = { - 0x80, 0x00, 0x00, 0x00 - }; - _assert (0 == memcmp (expected_ecm_hdr, lh, sizeof (expected_ecm_hdr))); - - ip4_header_t *ih = (ip4_header_t *) (lh + 1); - /* clear ip checksum */ - clib_memset ((u8 *) ih + 10, 0, 2); - - /* *INDENT-OFF* */ - u8 expected_ip4_hdr[] = { - 0x45, /* version; IHL */ - 0x00, /* services */ - 0x03, 0xa0, /* total length */ - 0x00, 0x00, /* identification */ - 0x40, 0x00, /* flags; fragment offset*/ - 0xff, /* TTL */ - 0x11, /* protocol */ - 0x00, 0x00, /* header checksum */ - 0xd4, 0xc3, 0xb2, 0xa1, /* src IP */ - 0x63, 0x72, 0x81, 0x90, /* dst IP */ - }; - /* *INDENT-ON* */ - - _assert (0 == memcmp (ih, expected_ip4_hdr, sizeof (expected_ip4_hdr))); - - udp_header_t *uh = (udp_header_t *) (ih + 1); - /* clear udp checksum */ - clib_memset ((u8 *) uh + 6, 0, 2); - - /* *INDENT-OFF* */ - u8 expected_udp_hdr[] = { - 0x00, 0x15, /* src port */ - 0x00, 0x14, /* dst port */ - 0x03, 0x8c, /* length */ - 0x00, 0x00, /* checksum */ - }; - /* *INDENT-ON* */ - - _assert (0 == memcmp (uh, expected_udp_hdr, sizeof (expected_udp_hdr))); - -done: - clib_mem_free (b); - return error; -} - -static clib_error_t * -test_lisp_msg_parse_mapping_record () -{ - clib_error_t *error = 0; - locator_t probed; - locator_t *locs = 0; - vlib_buffer_t *b = 0; - gid_address_t eid; - u32 buff_len = 500; - - b = clib_mem_alloc (buff_len); - clib_memset ((u8 *) b, 0, buff_len); - - /* *INDENT-OFF* */ - u8 map_reply_records[] = { - /* 1. record */ - 0x01, 0x02, 0x03, 0x04, /* record TTL */ - 0x01, /* locator count */ - 0x00, 0x00, 0x00, /* eid-mask-len; ... */ - 0x00, 0x00, /* reserved; map-version num */ - 0x00, 0x01, /* EID-Prefix-AFI */ - 0x33, 0x44, 0x55, 0x66, /* eid-prefix */ - /* loc */ - 0x0a, /* prority */ - 0x0b, /* weight */ - 0x0c, /* m-prority */ - 0x0d, /* m-weight */ - 0x00, 0x00, /* unused flags */ - 0x00, 0x01, /* Loc-AFI */ - 0xaa, 0xbb, 0xcc, 0xdd, /* Loator */ - }; - /* *INDENT-ON* */ - - b->current_length = buff_len; - clib_memcpy (b->data, map_reply_records, sizeof (map_reply_records)); - - lisp_msg_parse_mapping_record (b, &eid, &locs, &probed); - _assert (vec_len (locs) == 1); - _assert (eid.ippref.addr.ip.ip4.as_u32 == 0x66554433); - _assert (locs[0].local == 0); - _assert (locs[0].address.ippref.addr.ip.ip4.as_u32 == 0xddccbbaa); - _assert (locs[0].address.type == GID_ADDR_IP_PREFIX); - _assert (locs[0].priority == 0xa); - _assert (locs[0].weight == 0xb); - _assert (locs[0].mpriority == 0xc); - _assert (locs[0].mweight == 0xd); - -done: - clib_mem_free (b); - if (locs) - vec_free (locs); - return error; -} - -static map_request_hdr_t * -build_map_request (lisp_cp_main_t * lcm, vlib_buffer_t * b, - gid_address_t * rlocs) -{ - gid_address_t _seid, *seid = &_seid; - gid_address_t _deid, *deid = &_deid; - u8 is_smr_invoked = 1; - u8 rloc_probe_set = 0; - u64 nonce = 0; - map_request_hdr_t *h = 0; - clib_memset (deid, 0, sizeof (deid[0])); - clib_memset (seid, 0, sizeof (seid[0])); - - gid_address_type (seid) = GID_ADDR_IP_PREFIX; - ip_address_t *ip_addr = &gid_address_ip (seid); - ip_addr_v4 (ip_addr).as_u32 = 0x12345678; - seid->ippref.addr.version = AF_IP4; - - gid_address_type (deid) = GID_ADDR_IP_PREFIX; - ip_address_t *ip_addr2 = &gid_address_ip (deid); - ip_addr_v4 (ip_addr2).as_u32 = 0x9abcdef0; - deid->ippref.addr.version = AF_IP4; - gid_address_ippref_len (deid) = 24; - - h = lisp_msg_put_mreq (lcm, b, seid, deid, rlocs, - is_smr_invoked, rloc_probe_set, &nonce); - vec_free (rlocs); - return h; -} - -static void -generate_rlocs (gid_address_t ** rlocs, u32 * count) -{ - gid_address_t gid_addr_data, *gid_addr = &gid_addr_data; - clib_memset (gid_addr, 0, sizeof (gid_addr[0])); - ip_address_t *addr = &gid_address_ip (gid_addr); - - gid_address_type (gid_addr) = GID_ADDR_IP_PREFIX; - - ip_addr_version (addr) = AF_IP4; - ip_addr_v4 (addr).data_u32 = 0x10203040; - vec_add1 (rlocs[0], gid_addr[0]); - - ip_addr_v6 (addr).as_u32[0] = 0xffeeddcc; - ip_addr_v6 (addr).as_u32[1] = 0xbbaa9988; - ip_addr_v6 (addr).as_u32[2] = 0x77665544; - ip_addr_v6 (addr).as_u32[3] = 0x33221100; - ip_addr_version (addr) = AF_IP6; - vec_add1 (rlocs[0], gid_addr[0]); -} - -static clib_error_t * -test_lisp_msg_parse () -{ - gid_address_t eid; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - map_request_hdr_t *h; - gid_address_t gid; - clib_error_t *error = 0; - vlib_buffer_t *b; - gid_address_t *rlocs_decode = 0, *rlocs = 0; - u32 rloc_count_parse = 0; - - u8 *data = clib_mem_alloc (500); - clib_memset (data, 0, 500); - b = (vlib_buffer_t *) data; - - generate_rlocs (&rlocs_decode, &rloc_count_parse); - h = build_map_request (lcm, b, rlocs_decode); - - vlib_buffer_pull (b, sizeof (*h)); - u32 len = lisp_msg_parse_addr (b, &gid); - _assert (len == 2 + 4 - /* Source-EID-AFI field lenght + IPv4 address length */ ); - _assert (gid.ippref.addr.ip.ip4.as_u32 == 0x12345678); - _assert (gid.ippref.addr.version == AF_IP4); - - u8 rloc_count = MREQ_ITR_RLOC_COUNT (h) + 1; - lisp_msg_parse_itr_rlocs (b, &rlocs, rloc_count); - - _assert (vec_len (rlocs) == 2); - _assert (rlocs[0].ippref.addr.ip.ip4.as_u32 == 0x10203040); - _assert (rlocs[0].ippref.addr.version == AF_IP4); - - _assert (rlocs[1].ippref.addr.ip.ip6.as_u32[0] == 0xffeeddcc); - _assert (rlocs[1].ippref.addr.ip.ip6.as_u32[1] == 0xbbaa9988); - _assert (rlocs[1].ippref.addr.ip.ip6.as_u32[2] == 0x77665544); - _assert (rlocs[1].ippref.addr.ip.ip6.as_u32[3] == 0x33221100); - _assert (rlocs[1].ippref.addr.version == AF_IP6); - - lisp_msg_parse_eid_rec (b, &eid); - _assert (eid.ippref.addr.ip.ip4.as_u32 == 0x9abcdef0); - _assert (eid.ippref.addr.version == AF_IP4); - _assert (eid.ippref.len == 24); - -done: - clib_mem_free (data); - if (rlocs) - vec_free (rlocs); - return error; -} - -static clib_error_t * -test_lisp_msg_put_mreq_with_lcaf () -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - clib_error_t *error = 0; - map_request_hdr_t *h = 0; - gid_address_t *rlocs = 0; - - ip_prefix_t ippref; - ip_prefix_version (&ippref) = AF_IP4; - ip4_address_t *ip = &ip_prefix_v4 (&ippref); - ip->as_u32 = 0x11223344; - ippref.len = 32; - - gid_address_t g = { - .type = GID_ADDR_IP_PREFIX, - .ippref = ippref, - .vni = 0x90919293, - .vni_mask = 0x17 - }; - vec_add1 (rlocs, g); - - u8 *data = clib_mem_alloc (500); - clib_memset (data, 0, 500); - - h = build_map_request (lcm, (vlib_buffer_t *) data, rlocs); - - /* clear Nonce to simplify comparison */ - clib_memset ((u8 *) h + 4, 0, 8); - - /* *INDENT-OFF* */ - u8 expected_data[] = - { - 0x10, 0x40, 0x00, 0x01, /* type; flags; IRC; REC count */ - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, /* nonce */ - 0x00, 0x01, /* Source-EID-AFI */ - 0x78, 0x56, 0x34, 0x12, /* Source EID Address */ - - /* RLOCs */ - 0x40, 0x03, /* AFI = LCAF*/ - /* LCAF header*/ - 0x00, 0x00, /* reserved1, flags */ - 0x02, /* type = Instance ID */ - 0x17, /* IID mask-len */ - 0x00, 0x0a, /* lenght */ - 0x90, 0x91, 0x92, 0x93, /* IID / VNI */ - - 0x00, 0x01, /* AFI = ipv4 */ - 0x44, 0x33, 0x22, 0x11, /* ITR-RLOC Address 1 */ - - /* record */ - 0x00, /* reserved */ - 0x18, /* EID mask-len */ - 0x00, 0x01, /* EID-prefix-AFI */ - 0xf0, 0xde, 0xbc, 0x9a, /* EID-prefix */ - }; - /* *INDENT-ON* */ - - _assert (0 == memcmp (expected_data, (u8 *) h, sizeof (expected_data))); -done: - clib_mem_free (data); - return error; -} - -static clib_error_t * -test_lisp_msg_put_mreq () -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - clib_error_t *error = 0; - map_request_hdr_t *h; - gid_address_t *rlocs = 0; - u32 rloc_count = 0; - - u8 *data = clib_mem_alloc (500); - clib_memset (data, 0, 500); - - generate_rlocs (&rlocs, &rloc_count); - h = build_map_request (lcm, (vlib_buffer_t *) data, rlocs); - - /* clear Nonce to simplify comparison */ - clib_memset ((u8 *) h + 4, 0, 8); - - print_map_request (h); - - /* *INDENT-OFF* */ - u8 expected_data[50] = { - 0x10, 0x40, 0x01, 0x01, /* type; flags; IRC; REC count */ - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, /* nonce */ - 0x00, 0x01, /* Source-EID-AFI */ - 0x78, 0x56, 0x34, 0x12, /* Source EID Address */ - - /* RLOCs */ - 0x00, 0x01, /* ITR-RLOC-AFI 1 */ - 0x40, 0x30, 0x20, 0x10, /* ITR-RLOC Address 1 */ - 0x00, 0x02, /* ITR-RLOC-AFI 2 */ - 0xcc, 0xdd, 0xee, 0xff, - 0x88, 0x99, 0xaa, 0xbb, - 0x44, 0x55, 0x66, 0x77, - 0x00, 0x11, 0x22, 0x33, /* ITR-RLOC Address 2 */ - - /* record */ - 0x00, /* reserved */ - 0x18, /* EID mask-len */ - 0x00, 0x01, /* EID-prefix-AFI */ - 0xf0, 0xde, 0xbc, 0x9a, /* EID-prefix */ - }; - /* *INDENT-ON* */ - - _assert (0 == memcmp (expected_data, (u8 *) h, sizeof (expected_data))); - -done: - clib_mem_free (data); - return error; -} - -/* generate a vector of eid records */ -static mapping_t * -build_test_map_records () -{ - mapping_t *records = 0; - - /* *INDENT-OFF* */ - mapping_t r = { - .ttl = MAP_REGISTER_DEFAULT_TTL, - .eid = { - .type = GID_ADDR_MAC, - .mac = {1, 2, 3, 4, 5, 6}, - .vni = 0x0 - } - }; - - locator_t loc = { - .weight = 1, - .priority = 2, - .local = 1, - .address = { - .type = GID_ADDR_IP_PREFIX, - .ippref = { - .addr = { - .ip.ip4.as_u32 = 0x99887766, - .version = AF_IP4 - } - } - } - }; - /* *INDENT-ON* */ - - vec_add1 (r.locators, loc); - vec_add1 (records, r); - - return records; -} - -static void -free_test_map_records (mapping_t * maps) -{ - mapping_t *map; - vec_foreach (map, maps) - { - vec_free (map->locators); - } - vec_free (maps); -} - -static clib_error_t * -test_lisp_map_register () -{ - vlib_buffer_t *b; - clib_error_t *error = 0; - u64 nonce; - u32 msg_len = 0; - mapping_t *records = build_test_map_records (); - - u8 *data = clib_mem_alloc (500); - clib_memset (data, 0, 500); - b = (vlib_buffer_t *) data; - - lisp_msg_put_map_register (b, records, 1 /* want map notify */ , - 20 /* length of HMAC_SHA_1_96 */ , - &nonce, &msg_len); - free_test_map_records (records); - - /* clear Nonce to simplify comparison */ - clib_memset ((u8 *) b->data + 4, 0, 8); - - /* clear authentication data */ - clib_memset ((u8 *) b->data + 16, 0, 20); - - /* *INDENT-OFF* */ - u8 expected_data[] = { - 0x30, 0x00, 0x01, 0x01, /* type; rsvd; want notify; REC count */ - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, /* nonce */ - 0x00, 0x00, 0x00, 0x00, /* key id, auth data length: - both are zeroes because those are set in another - function (see auth_data_len_by_key_id())*/ - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, /* auth data */ - - /* first record */ - /* 0x00, 0x00, 0x03, 0x84, */ /* default ttl (15 minues) */ - 0x00, 0x01, 0x51, 0x80, /* default ttl (24h = 86400s) */ - 0x01, 0x00, 0x00, 0x00, /* loc count, eid len, ACT, A */ - 0x00, 0x00, 0x40, 0x05, /* rsvd, map ver num, AFI = MAC */ - 0x01, 0x02, 0x03, 0x04, - 0x05, 0x06, /* MAC EID */ - - /* locator 1 */ - 0x02, 0x01, 0x00, 0x00, /* prio, weight, mprio, mweight */ - 0x00, 0x04, 0x00, 0x01, /* flags, AFI = ipv4 */ - 0x66, 0x77, 0x88, 0x99, /* ipv4 locator address */ - }; - /* *INDENT-ON* */ - - _assert (0 == memcmp (expected_data, b->data, sizeof (expected_data))); -done: - clib_mem_free (data); - return error; -} - -static vlib_buffer_t * -create_buffer (u8 * data, u32 data_len) -{ - vlib_buffer_t *b; - - u8 *buf_data = clib_mem_alloc (500); - clib_memset (buf_data, 0, 500); - b = (vlib_buffer_t *) buf_data; - - u8 *p = vlib_buffer_put_uninit (b, data_len); - clib_memcpy (p, data, data_len); - - return b; -} - -static clib_error_t * -test_lisp_parse_map_reply () -{ - clib_error_t *error = 0; - - /* *INDENT-OFF* */ - u8 map_reply_data[] = - { - 0x00, 0x00, 0x00, 0x01, /* type; rsvd; mapping count */ - 0x00, 0x00, 0x00, 0x00, - }; - /* *INDENT-ON* */ - - vlib_buffer_t *b = create_buffer (map_reply_data, sizeof (map_reply_data)); - map_records_arg_t *mrecs = parse_map_reply (b); - _assert (0 == mrecs); - clib_mem_free (b); - - /* *INDENT-OFF* */ - u8 map_reply_data2[] = - { - 0x00, 0x00, 0x00, 0x01, /* type; rsvd */ - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, /* nonce */ - - /* 1. record - incomplete */ - 0x01, 0x02, 0x03, 0x04, /* record TTL */ - 0x01, /* locator count */ - }; - /* *INDENT-ON* */ - - b = create_buffer (map_reply_data2, sizeof (map_reply_data2)); - mrecs = parse_map_reply (b); - _assert (0 == mrecs); -done: - clib_mem_free (b); - return error; -} - -static clib_error_t * -test_lisp_parse_lcaf () -{ - int i; - clib_error_t *error = 0; - gid_address_t eid; - locator_t *locs = 0; - locator_t probed; - vlib_buffer_t *b = 0; - u32 buff_len = 500; - - b = clib_mem_alloc (buff_len); - clib_memset ((u8 *) b, 0, buff_len); - - /* *INDENT-OFF* */ - u8 map_reply_records[] = - { - /* 1. record */ - 0x01, 0x02, 0x03, 0x04, /* record TTL */ - 0x03, /* locator count */ - 0x00, 0x00, 0x00, /* eid-mask-len; ... */ - 0x00, 0x00, /* reserved; map-version num */ - 0x00, 0x01, /* EID-Prefix-AFI */ - 0x33, 0x44, 0x55, 0x66, /* eid-prefix */ - - /* 1st locator */ - 0x0a, /* prority */ - 0x0b, /* weight */ - 0x0c, /* m-prority */ - 0x0d, /* m-weight */ - 0x00, 0x00, /* unused flags */ - 0x40, 0x03, /* Loc-AFI = LCAF*/ - - /* LCAF header*/ - 0x00, 0x00, /* reserved1, flags */ - 0x02, /* type = Instance ID */ - 0x18, /* IID mask-len */ - 0x00, 0x0a, /* lenght */ - /* LCAF Instance ID */ - 0x00, 0x00, 0x00, 0x09, /* iid */ - 0x00, 0x01, /* AFI = ipv4 */ - 0x10, 0xbb, 0xcc, 0xdd, /* ipv4 loator address */ - - /* 2nd locator */ - 0x07, /* prority */ - 0x06, /* weight */ - 0x05, /* m-prority */ - 0x04, /* m-weight */ - 0x00, 0x00, /* unused flags */ - 0x40, 0x03, /* Loc-AFI = LCAF*/ - - /* LCAF header*/ - 0x00, 0x00, /* reserved1, flags */ - 0x02, /* type = Instance ID */ - 0x18, /* IID mask-len */ - 0x00, 0x16, /* iid length + next AFI lenght */ - /* LCAF Instance ID */ - 0x22, 0x44, 0x66, 0x88, /* iid */ - 0x00, 0x02, /* AFI = ipv6 */ - 0xcc, 0xdd, 0xee, 0xff, - 0x88, 0x99, 0xaa, 0xbb, - 0x44, 0x55, 0x66, 0x77, - 0x00, 0x11, 0x22, 0x33, /* ipv6 locator address */ - - /* 3rd locator */ - 0x0a, /* prority */ - 0x0b, /* weight */ - 0x0c, /* m-prority */ - 0x0d, /* m-weight */ - 0x00, 0x00, /* unused flags */ - 0x00, 0x01, /* Loc-AFI */ - 0xaa, 0xbb, 0xcc, 0xdd, /* Loator */ - }; - /* *INDENT-ON* */ - - b->current_length = buff_len; - memcpy (b->data, map_reply_records, sizeof (map_reply_records)); - - lisp_msg_parse_mapping_record (b, &eid, &locs, &probed); - _assert (vec_len (locs) == 3); - _assert (eid.ippref.addr.ip.ip4.as_u32 == 0x66554433); - - /* check 1st locator - an LCAF with ipv4 */ - _assert (locs[0].local == 0); - _assert (locs[0].priority == 0xa); - _assert (locs[0].weight == 0xb); - _assert (locs[0].mpriority == 0xc); - _assert (locs[0].mweight == 0xd); - - _assert (gid_address_type (&locs[0].address) == GID_ADDR_IP_PREFIX); - _assert (gid_address_vni (&locs[0].address) == 0x09); - ip_prefix_t *ip_pref = &gid_address_ippref (&locs[0].address); - _assert (AF_IP4 == ip_prefix_version (ip_pref)); - - /* 2nd locator - LCAF entry with ipv6 address */ - _assert (locs[1].local == 0); - _assert (locs[1].priority == 0x7); - _assert (locs[1].weight == 0x6); - _assert (locs[1].mpriority == 0x5); - _assert (locs[1].mweight == 0x4); - - _assert (gid_address_type (&locs[1].address) == GID_ADDR_IP_PREFIX); - _assert (0x22446688 == gid_address_vni (&locs[1].address)); - ip_pref = &gid_address_ippref (&locs[1].address); - _assert (AF_IP6 == ip_prefix_version (ip_pref)); - - /* 3rd locator - simple ipv4 address */ - _assert (gid_address_type (&locs[2].address) == GID_ADDR_IP_PREFIX); -done: - clib_mem_free (b); - - for (i = 0; i < 3; i++) - locator_free (&locs[i]); - vec_free (locs); - return error; -} - -#define foreach_test_case \ - _(lisp_msg_put_mreq) \ - _(lisp_msg_put_mreq_with_lcaf) \ - _(lisp_msg_push_ecm) \ - _(lisp_msg_parse) \ - _(lisp_msg_parse_mapping_record) \ - _(lisp_parse_map_reply) \ - _(lisp_parse_lcaf) \ - _(lisp_map_register) - -static int -lisp_cp_serdes_tests (vlib_main_t * vm, unformat_input_t * input) -{ - clib_error_t *error; - -#define _(_test_name) \ - error = test_ ## _test_name (); \ - if (error) \ - { \ - fformat (stderr, "FAIL: test_" #_test_name "\n"); \ - return -1; \ - } \ - else \ - fformat (stderr, "PASS: test_" #_test_name "\n"); \ - - foreach_test_case -#undef _ - return 0; -} - -static clib_error_t * -test_locator_type (void) -{ - clib_error_t *error = 0; - gid_address_t _gid_addr, *gid = &_gid_addr; - ip_prefix_t *ippref; - gid_address_type (gid) = GID_ADDR_IP_PREFIX; - gid_address_ippref_len (gid) = 24; - ippref = &gid_address_ippref (gid); - ip_prefix_version (ippref) = AF_IP4; - ip_prefix_len (ippref) = 0; - ip4_address_t *ip4 = &ip_prefix_v4 (ippref); - ip4->as_u32 = 0x20304050; - - /* local locator */ - locator_t loc1, loc2 = { - .local = 1, - .state = 2, - .sw_if_index = 8, - .priority = 3, - .weight = 100, - .mpriority = 4, - .mweight = 101 - }; - locator_copy (&loc1, &loc2); - _assert (0 == locator_cmp (&loc1, &loc2)); - - /* remote locator */ - loc2.local = 0; - - ip_prefix_t nested_ippref; - ip_prefix_version (&nested_ippref) = AF_IP4; - ip_prefix_len (&nested_ippref) = 0; - ip4 = &ip_prefix_v4 (&nested_ippref); - ip4->as_u32 = 0x33882299; - gid_address_t nested_gid = { - .type = GID_ADDR_IP_PREFIX, - .ippref = nested_ippref - }; - - lcaf_t lcaf = { - .type = LCAF_INSTANCE_ID, - .uni = { - .vni_mask_len = 5, - .vni = 0xa1b2c3d4, - .gid_addr = &nested_gid} - }; - gid_address_type (gid) = GID_ADDR_LCAF; - gid_address_lcaf (gid) = lcaf; - - loc2.address = gid[0]; - locator_copy (&loc1, &loc2); - - _assert (0 == locator_cmp (&loc1, &loc2)); - -done: - locator_free (&loc1); - return error; -} - -static clib_error_t * -test_gid_parse_ip_pref () -{ - clib_error_t *error = 0; - gid_address_t _gid_addr, *gid_addr = &_gid_addr; - gid_address_t _gid_addr_copy, *copy = &_gid_addr_copy; - - /* *INDENT-OFF* */ - u8 data[] = - { - 0x00, 0x01, /* AFI = IPv4 */ - 0x10, 0xbb, 0xcc, 0xdd, /* ipv4 address */ - }; - /* *INDENT-ON* */ - - u32 len = gid_address_parse (data, gid_addr); - _assert (6 == len); - gid_address_copy (copy, gid_addr); - _assert (0 == gid_address_cmp (copy, gid_addr)); -done: - return error; -} - -static clib_error_t * -test_gid_parse_mac () -{ - clib_error_t *error = 0; - gid_address_t _gid, *gid = &_gid; - gid_address_t _gid_copy, *gid_copy = &_gid_copy; - - /* *INDENT-OFF* */ - u8 data[] = - { - 0x40, 0x05, /* AFI = MAC address */ - 0x10, 0xbb, 0xcc, 0xdd, /* MAC */ - 0x77, 0x99, - }; - /* *INDENT-ON* */ - - u32 len = gid_address_parse (data, gid); - _assert (8 == len); - _assert (GID_ADDR_MAC == gid_address_type (gid)); - gid_address_copy (gid_copy, gid); - _assert (0 == gid_address_cmp (gid_copy, gid)); -done: - return error; -} - -static clib_error_t * -test_gid_write_nsh (void) -{ - clib_error_t *error = 0; - - u8 *b = clib_mem_alloc (500); - clib_memset (b, 0, 500); - - gid_address_t g = { - .vni = 0, - .nsh.spi = 0x112233, - .nsh.si = 0x42, - .type = GID_ADDR_NSH, - }; - - u16 len = gid_address_put (b, &g); - - /* *INDENT-OFF* */ - u8 expected[] = - { - 0x40, 0x03, 0x00, 0x00, /* AFI = LCAF*/ - 0x11, 0x00, 0x00, 0x04, /* type = SPI LCAF, length = 4 */ - - /* Service Path ID, Service index */ - 0x11, 0x22, 0x33, 0x42, /* SPI, SI */ - }; - /* *INDENT-ON* */ - - _assert (sizeof (expected) == len); - _assert (0 == memcmp (expected, b, len)); -done: - clib_mem_free (b); - return error; -} - -static clib_error_t * -test_gid_parse_nsh () -{ - clib_error_t *error = 0; - gid_address_t _gid_addr, *gid_addr = &_gid_addr; - gid_address_t _gid_addr_copy, *copy = &_gid_addr_copy; - - clib_memset (gid_addr, 0, sizeof (gid_addr[0])); - clib_memset (copy, 0, sizeof (copy[0])); - - /* *INDENT-OFF* */ - u8 data[] = - { - 0x40, 0x03, 0x00, 0x00, /* AFI = LCAF*/ - 0x11, 0x00, 0x00, 0x04, /* type = SPI LCAF, length = 4 */ - - /* Service Path ID, Service index */ - 0x55, 0x99, 0x42, 0x09, /* SPI, SI */ - }; - /* *INDENT-ON* */ - - u32 len = gid_address_parse (data, gid_addr); - _assert (sizeof (data) == len); - gid_address_copy (copy, gid_addr); - _assert (0 == gid_address_cmp (gid_addr, copy)); - _assert (GID_ADDR_NSH == gid_address_type (copy)); - _assert (0 == gid_address_vni (copy)); - _assert (gid_address_nsh_spi (copy) == 0x559942); - _assert (gid_address_nsh_si (copy) == 0x09); - -done: - gid_address_free (copy); - gid_address_free (gid_addr); - return error; -} - -static clib_error_t * -test_gid_parse_lcaf () -{ - clib_error_t *error = 0; - gid_address_t _gid_addr, *gid_addr = &_gid_addr; - gid_address_t _gid_addr_copy, *gid_addr_copy = &_gid_addr_copy; - - clib_memset (gid_addr, 0, sizeof (gid_addr[0])); - clib_memset (gid_addr_copy, 0, sizeof (gid_addr_copy[0])); - - /* *INDENT-OFF* */ - u8 data[] = - { - 0x40, 0x03, /* AFI = LCAF*/ - - /* LCAF header*/ - 0x00, 0x00, /* reserved1, flags */ - 0x02, /* type = Instance ID */ - 0x18, /* IID mask-len */ - 0x00, 0x0a, /* iid length + next AFI lenght */ - /* LCAF Instance ID */ - 0x00, 0x00, 0x00, 0x09, /* iid */ - 0x00, 0x01, /* AFI = ipv4 */ - 0x10, 0xbb, 0xcc, 0xdd, /* ipv4 address */ - }; - /* *INDENT-ON* */ - - u32 len = gid_address_parse (data, gid_addr); - _assert (18 == len); - gid_address_copy (gid_addr_copy, gid_addr); - _assert (0 == gid_address_cmp (gid_addr_copy, gid_addr)); - _assert (GID_ADDR_IP_PREFIX == gid_address_type (gid_addr)); - _assert (9 == gid_address_vni (gid_addr)); - _assert (0x18 == gid_address_vni_mask (gid_addr)); - _assert (0xddccbb10 == gid_addr->ippref.addr.ip.ip4.as_u32); - -done: - gid_address_free (gid_addr); - gid_address_free (gid_addr_copy); - return error; -} - -/* recursive LCAFs are not supported */ -#if 0 -static clib_error_t * -test_gid_parse_lcaf_complex () -{ - clib_error_t *error = 0; - gid_address_t _gid_addr, *gid_addr = &_gid_addr; - gid_address_t _gid_addr_copy, *gid_addr_copy = &_gid_addr_copy; - - clib_memset (gid_addr, 0, sizeof (gid_addr[0])); - clib_memset (gid_addr_copy, 0, sizeof (gid_addr_copy[0])); - - /* *INDENT-OFF* */ - u8 data[] = { - 0x40, 0x03, /* AFI = LCAF */ - - /* LCAF header */ - 0x00, 0x00, /* reserved1, flags */ - 0x02, /* type = Instance ID */ - 0x18, /* IID mask-len */ - 0x00, 0x0a, /* iid length + next AFI lenght */ - /* LCAF Instance ID */ - 0x00, 0x00, 0x00, 0x0b, /* iid */ - - 0x40, 0x03, /* AFI = LCAF */ - /* LCAF header */ - 0x00, 0x00, /* reserved1, flags */ - 0x02, /* type = Instance ID */ - 0x17, /* IID mask-len */ - 0x00, 0x0a, /* iid length + next AFI lenght */ - /* LCAF Instance ID */ - 0x00, 0x00, 0x00, 0x0c, /* iid */ - - 0x40, 0x03, /* AFI = LCAF */ - /* LCAF header */ - 0x00, 0x00, /* reserved1, flags */ - 0x02, /* type = Instance ID */ - 0x16, /* IID mask-len */ - 0x00, 0x16, /* iid length + next AFI lenght */ - /* LCAF Instance ID */ - 0x00, 0x00, 0x00, 0x0d, /* iid */ - - 0x00, 0x02, /* AFI = IPv6 */ - - 0x10, 0xbb, 0xcc, 0xdd, - 0x10, 0xbb, 0xcc, 0xdd, - 0x10, 0xbb, 0xcc, 0xdd, - 0x10, 0xbb, 0xcc, 0xdd, /* ipv6 address */ - }; - /* *INDENT-ON* */ - - u32 len = gid_address_parse (data, gid_addr); - _assert (54 == len); - _assert (gid_addr->type == GID_ADDR_LCAF); - gid_address_copy (gid_addr_copy, gid_addr); - _assert (0 == gid_address_cmp (gid_addr_copy, gid_addr)); - _assert (gid_addr_copy->type == GID_ADDR_LCAF); - - lcaf_t *lcaf = &gid_address_lcaf (gid_addr_copy); - _assert (lcaf->type == LCAF_INSTANCE_ID); - vni_t *v = (vni_t *) lcaf; - _assert (v->vni == 0x0b); - _assert (v->vni_mask_len == 0x18); - - gid_address_t *tmp = vni_gid (v); - _assert (gid_address_type (tmp) == GID_ADDR_LCAF); - lcaf = &gid_address_lcaf (tmp); - _assert (lcaf->type == LCAF_INSTANCE_ID); - - v = (vni_t *) lcaf; - _assert (v->vni == 0x0c); - _assert (v->vni_mask_len == 0x17); - - tmp = vni_gid (v); - _assert (gid_address_type (tmp) == GID_ADDR_LCAF); - lcaf = &gid_address_lcaf (tmp); - - _assert (lcaf->type == LCAF_INSTANCE_ID); - v = (vni_t *) lcaf; - _assert (v->vni == 0x0d); - _assert (v->vni_mask_len == 0x16); - - tmp = vni_gid (v); - _assert (gid_address_type (tmp) == GID_ADDR_IP_PREFIX); - - ip_prefix_t *ip_pref = &gid_address_ippref (tmp); - ip6_address_t *ip6 = &ip_prefix_v6 (ip_pref); - _assert (ip6->as_u32[0] == 0xddccbb10); - _assert (ip6->as_u32[1] == 0xddccbb10); - _assert (ip6->as_u32[2] == 0xddccbb10); - _assert (ip6->as_u32[3] == 0xddccbb10); - _assert (ip_prefix_version (ip_pref) == AF_IP6); - -done: - gid_address_free (gid_addr); - gid_address_free (gid_addr_copy); - return error; -} -#endif - -static clib_error_t * -test_write_mac_in_lcaf (void) -{ - clib_error_t *error = 0; - - u8 *b = clib_mem_alloc (500); - clib_memset (b, 0, 500); - - gid_address_t g = { - .mac = {0x1, 0x2, 0x3, 0x4, 0x5, 0x6}, - .vni = 0x01020304, - .vni_mask = 0x10, - .type = GID_ADDR_MAC, - }; - - u16 len = gid_address_put (b, &g); - - /* *INDENT-OFF* */ - u8 expected[] = - { - 0x40, 0x03, /* AFI = LCAF */ - 0x00, /* reserved1 */ - 0x00, /* flags */ - 0x02, /* LCAF type = Instance ID */ - 0x10, /* IID/IID mask len */ - 0x00, 0x0c, /* length */ - 0x01, 0x02, 0x03, 0x04, /* Instance ID / VNI */ - - 0x40, 0x05, /* AFI = MAC */ - 0x01, 0x02, 0x03, 0x04, - 0x05, 0x06 /* MAC */ - }; - /* *INDENT-ON* */ - - _assert (sizeof (expected) == len); - _assert (0 == memcmp (expected, b, len)); -done: - clib_mem_free (b); - return error; -} - -static clib_error_t * -test_mac_address_write (void) -{ - clib_error_t *error = 0; - - u8 *b = clib_mem_alloc (500); - clib_memset (b, 0, 500); - - gid_address_t g = { - .mac = {0x1, 0x2, 0x3, 0x4, 0x5, 0x6}, - .type = GID_ADDR_MAC, - }; - - u16 len = gid_address_put (b, &g); - _assert (8 == len); - - /* *INDENT-OFF* */ - u8 expected[] = - { - 0x40, 0x05, /* AFI = MAC */ - 0x01, 0x02, 0x03, 0x04, - 0x05, 0x06 /* MAC */ - }; - /* *INDENT-ON* */ - - _assert (0 == memcmp (expected, b, len)); -done: - clib_mem_free (b); - return error; -} - -static clib_error_t * -test_src_dst_with_vni_serdes (void) -{ - clib_error_t *error = 0; - u8 *b = clib_mem_alloc (500); - clib_memset (b, 0, 500); - - /* *INDENT-OFF* */ - fid_address_t src = - { - .type = FID_ADDR_IP_PREF, - .ippref = - { - .len = 24, - .addr = - { - .version = AF_IP4, - .ip.ip4.data = { 0x1, 0x2, 0x3, 0x0 } - } - } - }; - - fid_address_t dst = - { - .type = FID_ADDR_IP_PREF, - .ippref = - { - .len = 16, - .addr = - { - .version = AF_IP4, - .ip.ip4.data = { 0x9, 0x8, 0x0, 0x0 } - } - } - }; - - source_dest_t sd = - { - .src = src, - .dst = dst - }; - - gid_address_t g = - { - .sd = sd, - .type = GID_ADDR_SRC_DST, - .vni = 0x12345678, - .vni_mask = 0x9 - }; - - /* *INDENT-ON* */ - - u16 size_to_put = gid_address_size_to_put (&g); - _assert (36 == size_to_put); - _assert (0 == gid_address_len (&g)); - - u16 write_len = gid_address_put (b, &g); - _assert (size_to_put == write_len); - - /* *INDENT-OFF* */ - u8 expected_data[] = - { - 0x40, 0x03, 0x00, 0x00, /* AFI = LCAF, reserved1, flags */ - 0x02, 0x09, 0x00, 0x1c, /* LCAF type = IID, IID mask-len, length */ - 0x12, 0x34, 0x56, 0x78, /* reserved; source-ML, Dest-ML */ - - 0x40, 0x03, 0x00, 0x00, /* AFI = LCAF, reserved1, flags */ - 0x0c, 0x00, 0x00, 0x10, /* LCAF type = source/dest key, rsvd, length */ - 0x00, 0x00, 0x18, 0x10, /* reserved; source-ML, Dest-ML */ - - 0x00, 0x01, /* AFI = ip4 */ - 0x01, 0x02, 0x03, 0x00, /* source */ - - 0x00, 0x01, /* AFI = ip4 */ - 0x09, 0x08, 0x00, 0x00, /* destination */ - }; - /* *INDENT-ON* */ - - _assert (0 == memcmp (expected_data, b, sizeof (expected_data))); - - gid_address_t p; - clib_memset (&p, 0, sizeof (p)); - _assert (write_len == gid_address_parse (b, &p)); - _assert (0 == gid_address_cmp (&g, &p)); -done: - clib_mem_free (b); - return error; -} - -static clib_error_t * -test_src_dst_deser_bad_afi (void) -{ - clib_error_t *error = 0; - - /* *INDENT-OFF* */ - u8 expected_data[] = - { - 0x40, 0x03, 0x00, 0x00, /* AFI = LCAF, reserved1, flags */ - 0x0c, 0x00, 0x00, 0x14, /* LCAF type = source/dest key, rsvd, length */ - 0x00, 0x00, 0x00, 0x00, /* reserved; source-ML, Dest-ML */ - - 0xde, 0xad, /* AFI = bad value */ - 0x11, 0x22, 0x33, 0x44, - 0x55, 0x66, /* source */ - - 0x40, 0x05, /* AFI = MAC */ - 0x10, 0x21, 0x32, 0x43, - 0x54, 0x65, /* destination */ - }; - /* *INDENT-ON* */ - - gid_address_t p; - _assert (~0 == gid_address_parse (expected_data, &p)); -done: - return error; -} - -static clib_error_t * -test_src_dst_serdes (void) -{ - clib_error_t *error = 0; - - u8 *b = clib_mem_alloc (500); - clib_memset (b, 0, 500); - - fid_address_t src = { - .type = FID_ADDR_MAC, - .mac = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66} - }; - - fid_address_t dst = { - .type = FID_ADDR_MAC, - .mac = {0x10, 0x21, 0x32, 0x43, 0x54, 0x65} - }; - - source_dest_t sd = { - .src = src, - .dst = dst - }; - - gid_address_t g = { - .sd = sd, - .type = GID_ADDR_SRC_DST, - .vni = 0x0, - .vni_mask = 0x0 - }; - - u16 size_to_put = gid_address_size_to_put (&g); - _assert (28 == size_to_put); - _assert (0 == gid_address_len (&g)); - - u16 write_len = gid_address_put (b, &g); - _assert (size_to_put == write_len); - - /* *INDENT-OFF* */ - u8 expected_data[] = - { - 0x40, 0x03, 0x00, 0x00, /* AFI = LCAF, reserved1, flags */ - 0x0c, 0x00, 0x00, 0x14, /* LCAF type = source/dest key, rsvd, length */ - 0x00, 0x00, 0x00, 0x00, /* reserved; source-ML, Dest-ML */ - - 0x40, 0x05, /* AFI = MAC */ - 0x11, 0x22, 0x33, 0x44, - 0x55, 0x66, /* source */ - - 0x40, 0x05, /* AFI = MAC */ - 0x10, 0x21, 0x32, 0x43, - 0x54, 0x65, /* destination */ - }; - /* *INDENT-ON* */ - - _assert (0 == memcmp (expected_data, b, sizeof (expected_data))); - - gid_address_t p; - clib_memset (&p, 0, sizeof (p)); - _assert (write_len == gid_address_parse (b, &p)); - _assert (0 == gid_address_cmp (&g, &p)); -done: - clib_mem_free (b); - return error; -} - -static clib_error_t * -test_gid_address_write (void) -{ - clib_error_t *error = 0; - ip_prefix_t ippref_data, *ippref = &ippref_data; - - u8 *b = clib_mem_alloc (500); - clib_memset (b, 0, 500); - - ip_prefix_version (ippref) = AF_IP4; - ip_prefix_len (ippref) = 9; - ip4_address_t *ip4 = &ip_prefix_v4 (ippref); - ip4->as_u32 = 0xaabbccdd; - - gid_address_t g = { - .ippref = ippref[0], - .type = GID_ADDR_IP_PREFIX, - .vni = 0x01020304, - .vni_mask = 0x18 - }; - - _assert (18 == gid_address_size_to_put (&g)); - _assert (gid_address_len (&g) == 9); - - u16 write_len = gid_address_put (b, &g); - _assert (18 == write_len); - - /* *INDENT-OFF* */ - u8 expected_gid_data[] = - { - 0x40, 0x03, /* AFI = LCAF */ - 0x00, /* reserved1 */ - 0x00, /* flags */ - 0x02, /* LCAF type = Instance ID */ - 0x18, /* IID/VNI mask len */ - 0x00, 0x0a, /* length */ - 0x01, 0x02, 0x03, 0x04, /* Instance ID / VNI */ - - 0x00, 0x01, /* AFI = IPv4 */ - 0xdd, 0xcc, 0xbb, 0xaa, /* ipv4 addr */ - }; - /* *INDENT-ON* */ - - _assert (0 == memcmp (expected_gid_data, b, sizeof (expected_gid_data))); -done: - clib_mem_free (b); - return error; -} - -#undef foreach_test_case - -#define foreach_test_case \ - _(locator_type) \ - _(gid_parse_ip_pref) \ - _(gid_parse_mac) \ - _(gid_parse_lcaf) \ - _(gid_parse_nsh) \ - _(gid_write_nsh) \ - _(mac_address_write) \ - _(gid_address_write) \ - _(src_dst_serdes) \ - _(write_mac_in_lcaf) \ - _(src_dst_deser_bad_afi) \ - _(src_dst_with_vni_serdes) - -static int -lisp_cp_types_tests (vlib_main_t * vm, unformat_input_t * input) -{ - clib_error_t *error; - -#define _(_test_name) \ - error = test_ ## _test_name (); \ - if (error) \ - { \ - fformat (stderr, "FAIL: test_" #_test_name "\n"); \ - return -1; \ - } \ - else \ - fformat (stderr, "PASS: test_" #_test_name "\n"); \ - - foreach_test_case -#undef _ - return 0; -} - -#undef _assert - -static clib_error_t * -lisp_cp_test (vlib_main_t * vm, unformat_input_t * input, - vlib_cli_command_t * cmd_arg) -{ - int res = 0; - - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (input, "serdes")) - { - res = lisp_cp_serdes_tests (vm, input); - } - if (unformat (input, "types")) - { - res = lisp_cp_types_tests (vm, input); - } - else if (unformat (input, "all")) - { - if ((res = lisp_cp_serdes_tests (vm, input))) - goto done; - if ((res = lisp_cp_types_tests (vm, input))) - goto done; - } - else - break; - } - -done: - if (res) - return clib_error_return (0, "rbtree unit test failed"); - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (lisp_cp_command, static) = -{ - .path = "test lisp cp", - .short_help = "lisp cp internal unit tests", - .function = lisp_cp_test, -}; -/* *INDENT-ON* */ - - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/src/vat/api_format.c b/src/vat/api_format.c index 926f65dcd86..d24a406ce01 100644 --- a/src/vat/api_format.c +++ b/src/vat/api_format.c @@ -30,7 +30,6 @@ #include #include #include -#include #include #include @@ -2295,131 +2294,6 @@ static void vl_api_mpls_tunnel_add_del_reply_t_handler_json vam->result_ready = 1; } -static void vl_api_gpe_add_del_fwd_entry_reply_t_handler - (vl_api_gpe_add_del_fwd_entry_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - i32 retval = ntohl (mp->retval); - if (vam->async_mode) - { - vam->async_errors += (retval < 0); - } - else - { - vam->retval = retval; - vam->result_ready = 1; - } -} - -static void vl_api_gpe_add_del_fwd_entry_reply_t_handler_json - (vl_api_gpe_add_del_fwd_entry_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - vat_json_node_t node; - - vat_json_init_object (&node); - vat_json_object_add_int (&node, "retval", ntohl (mp->retval)); - vat_json_object_add_uint (&node, "fwd_entry_index", - clib_net_to_host_u32 (mp->fwd_entry_index)); - - vat_json_print (vam->ofp, &node); - vat_json_free (&node); - - vam->retval = ntohl (mp->retval); - vam->result_ready = 1; -} - -u8 * -format_lisp_transport_protocol (u8 * s, va_list * args) -{ - u32 proto = va_arg (*args, u32); - - switch (proto) - { - case 1: - return format (s, "udp"); - case 2: - return format (s, "api"); - default: - return 0; - } - return 0; -} - -static void vl_api_one_get_transport_protocol_reply_t_handler - (vl_api_one_get_transport_protocol_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - i32 retval = ntohl (mp->retval); - if (vam->async_mode) - { - vam->async_errors += (retval < 0); - } - else - { - u32 proto = mp->protocol; - print (vam->ofp, "Transport protocol: %U", - format_lisp_transport_protocol, proto); - vam->retval = retval; - vam->result_ready = 1; - } -} - -static void vl_api_one_get_transport_protocol_reply_t_handler_json - (vl_api_one_get_transport_protocol_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - vat_json_node_t node; - u8 *s; - - s = format (0, "%U", format_lisp_transport_protocol, mp->protocol); - vec_add1 (s, 0); - - vat_json_init_object (&node); - vat_json_object_add_int (&node, "retval", ntohl (mp->retval)); - vat_json_object_add_string_copy (&node, "transport-protocol", s); - - vec_free (s); - vat_json_print (vam->ofp, &node); - vat_json_free (&node); - - vam->retval = ntohl (mp->retval); - vam->result_ready = 1; -} - -static void vl_api_one_add_del_locator_set_reply_t_handler - (vl_api_one_add_del_locator_set_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - i32 retval = ntohl (mp->retval); - if (vam->async_mode) - { - vam->async_errors += (retval < 0); - } - else - { - vam->retval = retval; - vam->result_ready = 1; - } -} - -static void vl_api_one_add_del_locator_set_reply_t_handler_json - (vl_api_one_add_del_locator_set_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - vat_json_node_t node; - - vat_json_init_object (&node); - vat_json_object_add_int (&node, "retval", ntohl (mp->retval)); - vat_json_object_add_uint (&node, "locator_set_index", ntohl (mp->ls_index)); - - vat_json_print (vam->ofp, &node); - vat_json_free (&node); - - vam->retval = ntohl (mp->retval); - vam->result_ready = 1; -} - static void vl_api_vxlan_add_del_tunnel_reply_t_handler (vl_api_vxlan_add_del_tunnel_reply_t * mp) { @@ -2802,287 +2676,164 @@ static void vl_api_get_node_graph_reply_t_handler_json vam->result_ready = 1; } -static void -vl_api_one_locator_details_t_handler (vl_api_one_locator_details_t * mp) +static u8 * +format_policer_type (u8 * s, va_list * va) { - vat_main_t *vam = &vat_main; - u8 *s = 0; + u32 i = va_arg (*va, u32); - if (mp->local) - { - s = format (s, "%=16d%=16d%=16d", - ntohl (mp->sw_if_index), mp->priority, mp->weight); - } + if (i == SSE2_QOS_POLICER_TYPE_1R2C) + s = format (s, "1r2c"); + else if (i == SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697) + s = format (s, "1r3c"); + else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698) + s = format (s, "2r3c-2698"); + else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115) + s = format (s, "2r3c-4115"); + else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1) + s = format (s, "2r3c-mef5cf1"); else - { - s = format (s, "%=16U%=16d%=16d", - format_ip46_address, - mp->ip_address, mp->priority, mp->weight); - } - - print (vam->ofp, "%v", s); - vec_free (s); + s = format (s, "ILLEGAL"); + return s; } -static void -vl_api_one_locator_details_t_handler_json (vl_api_one_locator_details_t * mp) +static u8 * +format_policer_rate_type (u8 * s, va_list * va) { - vat_main_t *vam = &vat_main; - vat_json_node_t *node = NULL; - struct in6_addr ip6; - struct in_addr ip4; - - if (VAT_JSON_ARRAY != vam->json_tree.type) - { - ASSERT (VAT_JSON_NONE == vam->json_tree.type); - vat_json_init_array (&vam->json_tree); - } - node = vat_json_array_add (&vam->json_tree); - vat_json_init_object (node); - - vat_json_object_add_uint (node, "local", mp->local ? 1 : 0); - vat_json_object_add_uint (node, "priority", mp->priority); - vat_json_object_add_uint (node, "weight", mp->weight); + u32 i = va_arg (*va, u32); - if (mp->local) - vat_json_object_add_uint (node, "sw_if_index", - clib_net_to_host_u32 (mp->sw_if_index)); + if (i == SSE2_QOS_RATE_KBPS) + s = format (s, "kbps"); + else if (i == SSE2_QOS_RATE_PPS) + s = format (s, "pps"); else - { - if (mp->ip_address.af) - { - clib_memcpy (&ip6, mp->ip_address.un.ip6, sizeof (ip6)); - vat_json_object_add_ip6 (node, "address", ip6); - } - else - { - clib_memcpy (&ip4, mp->ip_address.un.ip4, sizeof (ip4)); - vat_json_object_add_ip4 (node, "address", ip4); - } - } -} - -static void -vl_api_one_locator_set_details_t_handler (vl_api_one_locator_set_details_t * - mp) -{ - vat_main_t *vam = &vat_main; - u8 *ls_name = 0; - - ls_name = format (0, "%s", mp->ls_name); - - print (vam->ofp, "%=10d%=15v", clib_net_to_host_u32 (mp->ls_index), - ls_name); - vec_free (ls_name); -} - -static void - vl_api_one_locator_set_details_t_handler_json - (vl_api_one_locator_set_details_t * mp) -{ - vat_main_t *vam = &vat_main; - vat_json_node_t *node = 0; - u8 *ls_name = 0; - - ls_name = format (0, "%s", mp->ls_name); - vec_add1 (ls_name, 0); - - if (VAT_JSON_ARRAY != vam->json_tree.type) - { - ASSERT (VAT_JSON_NONE == vam->json_tree.type); - vat_json_init_array (&vam->json_tree); - } - node = vat_json_array_add (&vam->json_tree); - - vat_json_init_object (node); - vat_json_object_add_string_copy (node, "ls_name", ls_name); - vat_json_object_add_uint (node, "ls_index", - clib_net_to_host_u32 (mp->ls_index)); - vec_free (ls_name); + s = format (s, "ILLEGAL"); + return s; } -typedef struct +static u8 * +format_policer_round_type (u8 * s, va_list * va) { - u32 spi; - u8 si; -} __attribute__ ((__packed__)) lisp_nsh_api_t; + u32 i = va_arg (*va, u32); -uword -unformat_nsh_address (unformat_input_t * input, va_list * args) -{ - lisp_nsh_api_t *nsh = va_arg (*args, lisp_nsh_api_t *); - return unformat (input, "SPI:%d SI:%d", &nsh->spi, &nsh->si); + if (i == SSE2_QOS_ROUND_TO_CLOSEST) + s = format (s, "closest"); + else if (i == SSE2_QOS_ROUND_TO_UP) + s = format (s, "up"); + else if (i == SSE2_QOS_ROUND_TO_DOWN) + s = format (s, "down"); + else + s = format (s, "ILLEGAL"); + return s; } static u8 * -format_nsh_address_vat (u8 * s, va_list * args) +format_policer_action_type (u8 * s, va_list * va) { - nsh_t *a = va_arg (*args, nsh_t *); - return format (s, "SPI:%d SI:%d", clib_net_to_host_u32 (a->spi), a->si); + u32 i = va_arg (*va, u32); + + if (i == SSE2_QOS_ACTION_DROP) + s = format (s, "drop"); + else if (i == SSE2_QOS_ACTION_TRANSMIT) + s = format (s, "transmit"); + else if (i == SSE2_QOS_ACTION_MARK_AND_TRANSMIT) + s = format (s, "mark-and-transmit"); + else + s = format (s, "ILLEGAL"); + return s; } static u8 * -format_lisp_flat_eid (u8 * s, va_list * args) +format_dscp (u8 * s, va_list * va) { - vl_api_eid_t *eid = va_arg (*args, vl_api_eid_t *); + u32 i = va_arg (*va, u32); + char *t = 0; - switch (eid->type) + switch (i) { - case EID_TYPE_API_PREFIX: - if (eid->address.prefix.address.af) - return format (s, "%U/%d", format_ip6_address, - eid->address.prefix.address.un.ip6, - eid->address.prefix.len); - return format (s, "%U/%d", format_ip4_address, - eid->address.prefix.address.un.ip4, - eid->address.prefix.len); - case EID_TYPE_API_MAC: - return format (s, "%U", format_ethernet_address, eid->address.mac); - case EID_TYPE_API_NSH: - return format (s, "%U", format_nsh_address_vat, eid->address.nsh); +#define _(v,f,str) case VNET_DSCP_##f: t = str; break; + foreach_vnet_dscp +#undef _ + default: + return format (s, "ILLEGAL"); } - return 0; -} - -static u8 * -format_lisp_eid_vat (u8 * s, va_list * args) -{ - vl_api_eid_t *deid = va_arg (*args, vl_api_eid_t *); - vl_api_eid_t *seid = va_arg (*args, vl_api_eid_t *); - u8 is_src_dst = (u8) va_arg (*args, int); - - if (is_src_dst) - s = format (s, "%U|", format_lisp_flat_eid, seid); - - s = format (s, "%U", format_lisp_flat_eid, deid); - + s = format (s, "%s", t); return s; } static void -vl_api_one_eid_table_details_t_handler (vl_api_one_eid_table_details_t * mp) +vl_api_policer_details_t_handler (vl_api_policer_details_t * mp) { vat_main_t *vam = &vat_main; - u8 *s = 0, *eid = 0; + u8 *conform_dscp_str, *exceed_dscp_str, *violate_dscp_str; - if (~0 == mp->locator_set_index) - s = format (0, "action: %d", mp->action); + if (mp->conform_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT) + conform_dscp_str = format (0, "%U", format_dscp, mp->conform_action.dscp); else - s = format (0, "%d", clib_net_to_host_u32 (mp->locator_set_index)); - - eid = format (0, "%U", format_lisp_eid_vat, - &mp->deid, &mp->seid, mp->is_src_dst); - vec_add1 (eid, 0); - - print (vam->ofp, "[%d] %-35s%-20s%-30s%-20d%-20d%-10d%-20s", - clib_net_to_host_u32 (mp->vni), - eid, - mp->is_local ? "local" : "remote", - s, clib_net_to_host_u32 (mp->ttl), mp->authoritative, - clib_net_to_host_u16 (mp->key.id), mp->key.key); - - vec_free (s); - vec_free (eid); -} - -static void -vl_api_one_eid_table_details_t_handler_json (vl_api_one_eid_table_details_t - * mp) -{ - vat_main_t *vam = &vat_main; - vat_json_node_t *node = 0; - u8 *eid = 0; - - if (VAT_JSON_ARRAY != vam->json_tree.type) - { - ASSERT (VAT_JSON_NONE == vam->json_tree.type); - vat_json_init_array (&vam->json_tree); - } - node = vat_json_array_add (&vam->json_tree); + conform_dscp_str = format (0, ""); - vat_json_init_object (node); - if (~0 == mp->locator_set_index) - vat_json_object_add_uint (node, "action", mp->action); + if (mp->exceed_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT) + exceed_dscp_str = format (0, "%U", format_dscp, mp->exceed_action.dscp); else - vat_json_object_add_uint (node, "locator_set_index", - clib_net_to_host_u32 (mp->locator_set_index)); + exceed_dscp_str = format (0, ""); - vat_json_object_add_uint (node, "is_local", mp->is_local ? 1 : 0); - if (mp->deid.type == 3) - { - vat_json_node_t *nsh_json = vat_json_object_add (node, "eid"); - vat_json_init_object (nsh_json); - lisp_nsh_api_t *nsh = (lisp_nsh_api_t *) & mp->deid.address.nsh; - vat_json_object_add_uint (nsh_json, "spi", - clib_net_to_host_u32 (nsh->spi)); - vat_json_object_add_uint (nsh_json, "si", nsh->si); - } + if (mp->violate_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT) + violate_dscp_str = format (0, "%U", format_dscp, mp->violate_action.dscp); else - { - eid = format (0, "%U", format_lisp_eid_vat, - &mp->deid, &mp->seid, mp->is_src_dst); - vec_add1 (eid, 0); - vat_json_object_add_string_copy (node, "eid", eid); - vec_free (eid); - } - vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni)); - vat_json_object_add_uint (node, "ttl", clib_net_to_host_u32 (mp->ttl)); - vat_json_object_add_uint (node, "authoritative", (mp->authoritative)); + violate_dscp_str = format (0, ""); - if (mp->key.id) - { - vat_json_object_add_uint (node, "key_id", - clib_net_to_host_u16 (mp->key.id)); - vat_json_object_add_string_copy (node, "key", mp->key.key); - } -} - -static void -vl_api_one_stats_details_t_handler (vl_api_one_stats_details_t * mp) -{ - vat_main_t *vam = &vat_main; - u8 *seid = 0, *deid = 0; - ip46_address_t lloc, rloc; - - deid = format (0, "%U", format_lisp_eid_vat, &mp->deid, 0, 0); - - seid = format (0, "%U", format_lisp_eid_vat, &mp->seid, 0, 0); - - vec_add1 (deid, 0); - vec_add1 (seid, 0); - - if (mp->lloc.af) - { - clib_memcpy (&lloc.ip6, mp->lloc.un.ip6, 16); - clib_memcpy (&rloc.ip6, mp->rloc.un.ip6, 16); - } - else - { - clib_memcpy (&lloc.ip4, mp->lloc.un.ip4, 4); - clib_memcpy (&rloc.ip4, mp->rloc.un.ip4, 4); - } - - - print (vam->ofp, "([%d] %s %s) (%U %U) %u %u", - clib_net_to_host_u32 (mp->vni), - seid, deid, - format_ip46_address, lloc, - format_ip46_address, rloc, - clib_net_to_host_u32 (mp->pkt_count), - clib_net_to_host_u32 (mp->bytes)); + print (vam->ofp, "Name \"%s\", type %U, cir %u, eir %u, cb %u, eb %u, " + "rate type %U, round type %U, %s rate, %s color-aware, " + "cir %u tok/period, pir %u tok/period, scale %u, cur lim %u, " + "cur bkt %u, ext lim %u, ext bkt %u, last update %llu" + "conform action %U%s, exceed action %U%s, violate action %U%s", + mp->name, + format_policer_type, mp->type, + ntohl (mp->cir), + ntohl (mp->eir), + clib_net_to_host_u64 (mp->cb), + clib_net_to_host_u64 (mp->eb), + format_policer_rate_type, mp->rate_type, + format_policer_round_type, mp->round_type, + mp->single_rate ? "single" : "dual", + mp->color_aware ? "is" : "not", + ntohl (mp->cir_tokens_per_period), + ntohl (mp->pir_tokens_per_period), + ntohl (mp->scale), + ntohl (mp->current_limit), + ntohl (mp->current_bucket), + ntohl (mp->extended_limit), + ntohl (mp->extended_bucket), + clib_net_to_host_u64 (mp->last_update_time), + format_policer_action_type, mp->conform_action.type, + conform_dscp_str, + format_policer_action_type, mp->exceed_action.type, + exceed_dscp_str, + format_policer_action_type, mp->violate_action.type, + violate_dscp_str); - vec_free (deid); - vec_free (seid); + vec_free (conform_dscp_str); + vec_free (exceed_dscp_str); + vec_free (violate_dscp_str); } -static void -vl_api_one_stats_details_t_handler_json (vl_api_one_stats_details_t * mp) +static void vl_api_policer_details_t_handler_json + (vl_api_policer_details_t * mp) { - struct in6_addr ip6; - struct in_addr ip4; vat_main_t *vam = &vat_main; - vat_json_node_t *node = 0; - u8 *deid = 0, *seid = 0; + vat_json_node_t *node; + u8 *rate_type_str, *round_type_str, *type_str; + u8 *conform_action_str, *exceed_action_str, *violate_action_str; + + rate_type_str = format (0, "%U", format_policer_rate_type, mp->rate_type); + round_type_str = + format (0, "%U", format_policer_round_type, mp->round_type); + type_str = format (0, "%U", format_policer_type, mp->type); + conform_action_str = format (0, "%U", format_policer_action_type, + mp->conform_action.type); + exceed_action_str = format (0, "%U", format_policer_action_type, + mp->exceed_action.type); + violate_action_str = format (0, "%U", format_policer_action_type, + mp->violate_action.type); if (VAT_JSON_ARRAY != vam->json_tree.type) { @@ -3092,350 +2843,289 @@ vl_api_one_stats_details_t_handler_json (vl_api_one_stats_details_t * mp) node = vat_json_array_add (&vam->json_tree); vat_json_init_object (node); - deid = format (0, "%U", format_lisp_eid_vat, &mp->deid, 0, 0); - - seid = format (0, "%U", format_lisp_eid_vat, &mp->seid, 0, 0); - - vec_add1 (deid, 0); - vec_add1 (seid, 0); - - vat_json_object_add_string_copy (node, "seid", seid); - vat_json_object_add_string_copy (node, "deid", deid); - vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni)); - - if (mp->lloc.af) + vat_json_object_add_string_copy (node, "name", mp->name); + vat_json_object_add_uint (node, "cir", ntohl (mp->cir)); + vat_json_object_add_uint (node, "eir", ntohl (mp->eir)); + vat_json_object_add_uint (node, "cb", clib_net_to_host_u64 (mp->cb)); + vat_json_object_add_uint (node, "eb", clib_net_to_host_u64 (mp->eb)); + vat_json_object_add_string_copy (node, "rate_type", rate_type_str); + vat_json_object_add_string_copy (node, "round_type", round_type_str); + vat_json_object_add_string_copy (node, "type", type_str); + vat_json_object_add_uint (node, "single_rate", mp->single_rate); + vat_json_object_add_uint (node, "color_aware", mp->color_aware); + vat_json_object_add_uint (node, "scale", ntohl (mp->scale)); + vat_json_object_add_uint (node, "cir_tokens_per_period", + ntohl (mp->cir_tokens_per_period)); + vat_json_object_add_uint (node, "eir_tokens_per_period", + ntohl (mp->pir_tokens_per_period)); + vat_json_object_add_uint (node, "current_limit", ntohl (mp->current_limit)); + vat_json_object_add_uint (node, "current_bucket", + ntohl (mp->current_bucket)); + vat_json_object_add_uint (node, "extended_limit", + ntohl (mp->extended_limit)); + vat_json_object_add_uint (node, "extended_bucket", + ntohl (mp->extended_bucket)); + vat_json_object_add_uint (node, "last_update_time", + ntohl (mp->last_update_time)); + vat_json_object_add_string_copy (node, "conform_action", + conform_action_str); + if (mp->conform_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT) { - clib_memcpy (&ip6, mp->lloc.un.ip6, sizeof (ip6)); - vat_json_object_add_ip6 (node, "lloc", ip6); - clib_memcpy (&ip6, mp->rloc.un.ip6, sizeof (ip6)); - vat_json_object_add_ip6 (node, "rloc", ip6); - + u8 *dscp_str = format (0, "%U", format_dscp, mp->conform_action.dscp); + vat_json_object_add_string_copy (node, "conform_dscp", dscp_str); + vec_free (dscp_str); } - else + vat_json_object_add_string_copy (node, "exceed_action", exceed_action_str); + if (mp->exceed_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT) { - clib_memcpy (&ip4, mp->lloc.un.ip4, sizeof (ip4)); - vat_json_object_add_ip4 (node, "lloc", ip4); - clib_memcpy (&ip4, mp->rloc.un.ip4, sizeof (ip4)); - vat_json_object_add_ip4 (node, "rloc", ip4); + u8 *dscp_str = format (0, "%U", format_dscp, mp->exceed_action.dscp); + vat_json_object_add_string_copy (node, "exceed_dscp", dscp_str); + vec_free (dscp_str); } - vat_json_object_add_uint (node, "pkt_count", - clib_net_to_host_u32 (mp->pkt_count)); - vat_json_object_add_uint (node, "bytes", clib_net_to_host_u32 (mp->bytes)); - - vec_free (deid); - vec_free (seid); -} - -static void - vl_api_one_eid_table_map_details_t_handler - (vl_api_one_eid_table_map_details_t * mp) -{ - vat_main_t *vam = &vat_main; - - u8 *line = format (0, "%=10d%=10d", - clib_net_to_host_u32 (mp->vni), - clib_net_to_host_u32 (mp->dp_table)); - print (vam->ofp, "%v", line); - vec_free (line); -} - -static void - vl_api_one_eid_table_map_details_t_handler_json - (vl_api_one_eid_table_map_details_t * mp) -{ - vat_main_t *vam = &vat_main; - vat_json_node_t *node = NULL; - - if (VAT_JSON_ARRAY != vam->json_tree.type) + vat_json_object_add_string_copy (node, "violate_action", + violate_action_str); + if (mp->violate_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT) { - ASSERT (VAT_JSON_NONE == vam->json_tree.type); - vat_json_init_array (&vam->json_tree); + u8 *dscp_str = format (0, "%U", format_dscp, mp->violate_action.dscp); + vat_json_object_add_string_copy (node, "violate_dscp", dscp_str); + vec_free (dscp_str); } - node = vat_json_array_add (&vam->json_tree); - vat_json_init_object (node); - vat_json_object_add_uint (node, "dp_table", - clib_net_to_host_u32 (mp->dp_table)); - vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni)); -} - -static void - vl_api_one_eid_table_vni_details_t_handler - (vl_api_one_eid_table_vni_details_t * mp) -{ - vat_main_t *vam = &vat_main; - u8 *line = format (0, "%d", clib_net_to_host_u32 (mp->vni)); - print (vam->ofp, "%v", line); - vec_free (line); + vec_free (rate_type_str); + vec_free (round_type_str); + vec_free (type_str); + vec_free (conform_action_str); + vec_free (exceed_action_str); + vec_free (violate_action_str); } static void - vl_api_one_eid_table_vni_details_t_handler_json - (vl_api_one_eid_table_vni_details_t * mp) +vl_api_classify_table_ids_reply_t_handler (vl_api_classify_table_ids_reply_t * + mp) { vat_main_t *vam = &vat_main; - vat_json_node_t *node = NULL; + int i, count = ntohl (mp->count); - if (VAT_JSON_ARRAY != vam->json_tree.type) + if (count > 0) + print (vam->ofp, "classify table ids (%d) : ", count); + for (i = 0; i < count; i++) { - ASSERT (VAT_JSON_NONE == vam->json_tree.type); - vat_json_init_array (&vam->json_tree); + print (vam->ofp, "%d", ntohl (mp->ids[i])); + print (vam->ofp, (i < count - 1) ? "," : ""); } - node = vat_json_array_add (&vam->json_tree); - vat_json_init_object (node); - vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni)); -} - -static void - vl_api_show_one_map_register_fallback_threshold_reply_t_handler - (vl_api_show_one_map_register_fallback_threshold_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - int retval = clib_net_to_host_u32 (mp->retval); - - vl_api_show_one_map_register_fallback_threshold_reply_t_endian (mp); - print (vam->ofp, "fallback threshold value: %d", mp->value); - - vam->retval = retval; + vam->retval = ntohl (mp->retval); vam->result_ready = 1; } static void - vl_api_show_one_map_register_fallback_threshold_reply_t_handler_json - (vl_api_show_one_map_register_fallback_threshold_reply_t * mp) + vl_api_classify_table_ids_reply_t_handler_json + (vl_api_classify_table_ids_reply_t * mp) { vat_main_t *vam = &vat_main; - vat_json_node_t _node, *node = &_node; - int retval = clib_net_to_host_u32 (mp->retval); - - vl_api_show_one_map_register_fallback_threshold_reply_t_endian (mp); - vat_json_init_object (node); - vat_json_object_add_uint (node, "value", mp->value); + int i, count = ntohl (mp->count); - vat_json_print (vam->ofp, node); - vat_json_free (node); + if (count > 0) + { + vat_json_node_t node; - vam->retval = retval; + vat_json_init_object (&node); + for (i = 0; i < count; i++) + { + vat_json_object_add_uint (&node, "table_id", ntohl (mp->ids[i])); + } + vat_json_print (vam->ofp, &node); + vat_json_free (&node); + } + vam->retval = ntohl (mp->retval); vam->result_ready = 1; } static void - vl_api_show_one_map_register_state_reply_t_handler - (vl_api_show_one_map_register_state_reply_t * mp) + vl_api_classify_table_by_interface_reply_t_handler + (vl_api_classify_table_by_interface_reply_t * mp) { vat_main_t *vam = &vat_main; - int retval = clib_net_to_host_u32 (mp->retval); - - print (vam->ofp, "%s", mp->is_enable ? "enabled" : "disabled"); + u32 table_id; - vam->retval = retval; + table_id = ntohl (mp->l2_table_id); + if (table_id != ~0) + print (vam->ofp, "l2 table id : %d", table_id); + else + print (vam->ofp, "l2 table id : No input ACL tables configured"); + table_id = ntohl (mp->ip4_table_id); + if (table_id != ~0) + print (vam->ofp, "ip4 table id : %d", table_id); + else + print (vam->ofp, "ip4 table id : No input ACL tables configured"); + table_id = ntohl (mp->ip6_table_id); + if (table_id != ~0) + print (vam->ofp, "ip6 table id : %d", table_id); + else + print (vam->ofp, "ip6 table id : No input ACL tables configured"); + vam->retval = ntohl (mp->retval); vam->result_ready = 1; } static void - vl_api_show_one_map_register_state_reply_t_handler_json - (vl_api_show_one_map_register_state_reply_t * mp) + vl_api_classify_table_by_interface_reply_t_handler_json + (vl_api_classify_table_by_interface_reply_t * mp) { vat_main_t *vam = &vat_main; - vat_json_node_t _node, *node = &_node; - int retval = clib_net_to_host_u32 (mp->retval); + vat_json_node_t node; - u8 *s = format (0, "%s", mp->is_enable ? "enabled" : "disabled"); + vat_json_init_object (&node); - vat_json_init_object (node); - vat_json_object_add_string_copy (node, "state", s); + vat_json_object_add_int (&node, "l2_table_id", ntohl (mp->l2_table_id)); + vat_json_object_add_int (&node, "ip4_table_id", ntohl (mp->ip4_table_id)); + vat_json_object_add_int (&node, "ip6_table_id", ntohl (mp->ip6_table_id)); - vat_json_print (vam->ofp, node); - vat_json_free (node); + vat_json_print (vam->ofp, &node); + vat_json_free (&node); - vam->retval = retval; + vam->retval = ntohl (mp->retval); vam->result_ready = 1; - vec_free (s); } -static void - vl_api_show_one_rloc_probe_state_reply_t_handler - (vl_api_show_one_rloc_probe_state_reply_t * mp) +static void vl_api_policer_add_del_reply_t_handler + (vl_api_policer_add_del_reply_t * mp) { vat_main_t *vam = &vat_main; - int retval = clib_net_to_host_u32 (mp->retval); - - if (retval) - goto end; - - print (vam->ofp, "%s", mp->is_enable ? "enabled" : "disabled"); -end: - vam->retval = retval; - vam->result_ready = 1; + i32 retval = ntohl (mp->retval); + if (vam->async_mode) + { + vam->async_errors += (retval < 0); + } + else + { + vam->retval = retval; + vam->result_ready = 1; + if (retval == 0 && mp->policer_index != 0xFFFFFFFF) + /* + * Note: this is just barely thread-safe, depends on + * the main thread spinning waiting for an answer... + */ + errmsg ("policer index %d", ntohl (mp->policer_index)); + } } -static void - vl_api_show_one_rloc_probe_state_reply_t_handler_json - (vl_api_show_one_rloc_probe_state_reply_t * mp) +static void vl_api_policer_add_del_reply_t_handler_json + (vl_api_policer_add_del_reply_t * mp) { vat_main_t *vam = &vat_main; - vat_json_node_t _node, *node = &_node; - int retval = clib_net_to_host_u32 (mp->retval); + vat_json_node_t node; - u8 *s = format (0, "%s", mp->is_enable ? "enabled" : "disabled"); - vat_json_init_object (node); - vat_json_object_add_string_copy (node, "state", s); + vat_json_init_object (&node); + vat_json_object_add_int (&node, "retval", ntohl (mp->retval)); + vat_json_object_add_uint (&node, "policer_index", + ntohl (mp->policer_index)); - vat_json_print (vam->ofp, node); - vat_json_free (node); + vat_json_print (vam->ofp, &node); + vat_json_free (&node); - vam->retval = retval; + vam->retval = ntohl (mp->retval); vam->result_ready = 1; - vec_free (s); } -static void - vl_api_show_one_stats_enable_disable_reply_t_handler - (vl_api_show_one_stats_enable_disable_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - int retval = clib_net_to_host_u32 (mp->retval); - - if (retval) - goto end; - - print (vam->ofp, "%s", mp->is_enable ? "enabled" : "disabled"); -end: - vam->retval = retval; - vam->result_ready = 1; -} - -static void - vl_api_show_one_stats_enable_disable_reply_t_handler_json - (vl_api_show_one_stats_enable_disable_reply_t * mp) +/* Format hex dump. */ +u8 * +format_hex_bytes (u8 * s, va_list * va) { - vat_main_t *vam = &vat_main; - vat_json_node_t _node, *node = &_node; - int retval = clib_net_to_host_u32 (mp->retval); - - u8 *s = format (0, "%s", mp->is_enable ? "enabled" : "disabled"); - vat_json_init_object (node); - vat_json_object_add_string_copy (node, "state", s); - - vat_json_print (vam->ofp, node); - vat_json_free (node); - - vam->retval = retval; - vam->result_ready = 1; - vec_free (s); -} + u8 *bytes = va_arg (*va, u8 *); + int n_bytes = va_arg (*va, int); + uword i; -static void -api_gpe_fwd_entry_net_to_host (vl_api_gpe_fwd_entry_t * e) -{ - e->dp_table = clib_net_to_host_u32 (e->dp_table); - e->fwd_entry_index = clib_net_to_host_u32 (e->fwd_entry_index); - e->vni = clib_net_to_host_u32 (e->vni); -} + /* Print short or long form depending on byte count. */ + uword short_form = n_bytes <= 32; + u32 indent = format_get_indent (s); -static void - gpe_fwd_entries_get_reply_t_net_to_host - (vl_api_gpe_fwd_entries_get_reply_t * mp) -{ - u32 i; + if (n_bytes == 0) + return s; - mp->count = clib_net_to_host_u32 (mp->count); - for (i = 0; i < mp->count; i++) + for (i = 0; i < n_bytes; i++) { - api_gpe_fwd_entry_net_to_host (&mp->entries[i]); + if (!short_form && (i % 32) == 0) + s = format (s, "%08x: ", i); + s = format (s, "%02x", bytes[i]); + if (!short_form && ((i + 1) % 32) == 0 && (i + 1) < n_bytes) + s = format (s, "\n%U", format_white_space, indent); } -} - -static u8 * -format_gpe_encap_mode (u8 * s, va_list * args) -{ - u32 mode = va_arg (*args, u32); - switch (mode) - { - case 0: - return format (s, "lisp"); - case 1: - return format (s, "vxlan"); - } - return 0; + return s; } static void - vl_api_gpe_get_encap_mode_reply_t_handler - (vl_api_gpe_get_encap_mode_reply_t * mp) +vl_api_classify_table_info_reply_t_handler (vl_api_classify_table_info_reply_t + * mp) { vat_main_t *vam = &vat_main; - - print (vam->ofp, "gpe mode: %U", format_gpe_encap_mode, mp->encap_mode); - vam->retval = ntohl (mp->retval); + i32 retval = ntohl (mp->retval); + if (retval == 0) + { + print (vam->ofp, "classify table info :"); + print (vam->ofp, "sessions: %d nexttbl: %d nextnode: %d", + ntohl (mp->active_sessions), ntohl (mp->next_table_index), + ntohl (mp->miss_next_index)); + print (vam->ofp, "nbuckets: %d skip: %d match: %d", + ntohl (mp->nbuckets), ntohl (mp->skip_n_vectors), + ntohl (mp->match_n_vectors)); + print (vam->ofp, "mask: %U", format_hex_bytes, mp->mask, + ntohl (mp->mask_length)); + } + vam->retval = retval; vam->result_ready = 1; } static void - vl_api_gpe_get_encap_mode_reply_t_handler_json - (vl_api_gpe_get_encap_mode_reply_t * mp) + vl_api_classify_table_info_reply_t_handler_json + (vl_api_classify_table_info_reply_t * mp) { vat_main_t *vam = &vat_main; vat_json_node_t node; - u8 *encap_mode = format (0, "%U", format_gpe_encap_mode, mp->encap_mode); - vec_add1 (encap_mode, 0); - - vat_json_init_object (&node); - vat_json_object_add_string_copy (&node, "gpe_mode", encap_mode); + i32 retval = ntohl (mp->retval); + if (retval == 0) + { + vat_json_init_object (&node); - vec_free (encap_mode); - vat_json_print (vam->ofp, &node); - vat_json_free (&node); + vat_json_object_add_int (&node, "sessions", + ntohl (mp->active_sessions)); + vat_json_object_add_int (&node, "nexttbl", + ntohl (mp->next_table_index)); + vat_json_object_add_int (&node, "nextnode", + ntohl (mp->miss_next_index)); + vat_json_object_add_int (&node, "nbuckets", ntohl (mp->nbuckets)); + vat_json_object_add_int (&node, "skip", ntohl (mp->skip_n_vectors)); + vat_json_object_add_int (&node, "match", ntohl (mp->match_n_vectors)); + u8 *s = format (0, "%U%c", format_hex_bytes, mp->mask, + ntohl (mp->mask_length), 0); + vat_json_object_add_string_copy (&node, "mask", s); + vat_json_print (vam->ofp, &node); + vat_json_free (&node); + } vam->retval = ntohl (mp->retval); vam->result_ready = 1; } static void - vl_api_gpe_fwd_entry_path_details_t_handler - (vl_api_gpe_fwd_entry_path_details_t * mp) +vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t * + mp) { vat_main_t *vam = &vat_main; - u8 *(*format_ip_address_fcn) (u8 *, va_list *) = 0; - - if (mp->lcl_loc.addr.af) - format_ip_address_fcn = format_ip6_address; - else - format_ip_address_fcn = format_ip4_address; - - print (vam->ofp, "w:%d %30U %30U", mp->rmt_loc.weight, - format_ip_address_fcn, &mp->lcl_loc.addr.un, - format_ip_address_fcn, &mp->rmt_loc.addr.un); -} - -static void -lisp_fill_locator_node (vat_json_node_t * n, vl_api_gpe_locator_t * loc) -{ - struct in6_addr ip6; - struct in_addr ip4; - if (loc->addr.af) - { - clib_memcpy (&ip6, loc->addr.un.ip6, sizeof (ip6)); - vat_json_object_add_ip6 (n, "address", ip6); - } - else - { - clib_memcpy (&ip4, loc->addr.un.ip4, sizeof (ip4)); - vat_json_object_add_ip4 (n, "address", ip4); - } - vat_json_object_add_uint (n, "weight", loc->weight); + print (vam->ofp, "next_index: %d advance: %d opaque: %d ", + ntohl (mp->hit_next_index), ntohl (mp->advance), + ntohl (mp->opaque_index)); + print (vam->ofp, "mask: %U", format_hex_bytes, mp->match, + ntohl (mp->match_length)); } static void - vl_api_gpe_fwd_entry_path_details_t_handler_json - (vl_api_gpe_fwd_entry_path_details_t * mp) + vl_api_classify_session_details_t_handler_json + (vl_api_classify_session_details_t * mp) { vat_main_t *vam = &vat_main; vat_json_node_t *node = NULL; - vat_json_node_t *loc_node; if (VAT_JSON_ARRAY != vam->json_tree.type) { @@ -3443,5501 +3133,1106 @@ static void vat_json_init_array (&vam->json_tree); } node = vat_json_array_add (&vam->json_tree); - vat_json_init_object (node); - - loc_node = vat_json_object_add (node, "local_locator"); - vat_json_init_object (loc_node); - lisp_fill_locator_node (loc_node, &mp->lcl_loc); - loc_node = vat_json_object_add (node, "remote_locator"); - vat_json_init_object (loc_node); - lisp_fill_locator_node (loc_node, &mp->rmt_loc); + vat_json_init_object (node); + vat_json_object_add_int (node, "next_index", ntohl (mp->hit_next_index)); + vat_json_object_add_int (node, "advance", ntohl (mp->advance)); + vat_json_object_add_int (node, "opaque", ntohl (mp->opaque_index)); + u8 *s = + format (0, "%U%c", format_hex_bytes, mp->match, ntohl (mp->match_length), + 0); + vat_json_object_add_string_copy (node, "match", s); } -static void - vl_api_gpe_fwd_entries_get_reply_t_handler - (vl_api_gpe_fwd_entries_get_reply_t * mp) +static void vl_api_pg_create_interface_reply_t_handler + (vl_api_pg_create_interface_reply_t * mp) { vat_main_t *vam = &vat_main; - u32 i; - int retval = clib_net_to_host_u32 (mp->retval); - vl_api_gpe_fwd_entry_t *e; - - if (retval) - goto end; - gpe_fwd_entries_get_reply_t_net_to_host (mp); - - for (i = 0; i < mp->count; i++) - { - e = &mp->entries[i]; - print (vam->ofp, "%10d %10d %U %40U", e->fwd_entry_index, e->dp_table, - format_lisp_flat_eid, e->leid, format_lisp_flat_eid, e->reid); - } - -end: - vam->retval = retval; + vam->retval = ntohl (mp->retval); vam->result_ready = 1; } -static void - vl_api_gpe_fwd_entries_get_reply_t_handler_json - (vl_api_gpe_fwd_entries_get_reply_t * mp) +static void vl_api_pg_create_interface_reply_t_handler_json + (vl_api_pg_create_interface_reply_t * mp) { - u8 *s = 0; vat_main_t *vam = &vat_main; - vat_json_node_t *e = 0, root; - u32 i; - int retval = clib_net_to_host_u32 (mp->retval); - vl_api_gpe_fwd_entry_t *fwd; - - if (retval) - goto end; - - gpe_fwd_entries_get_reply_t_net_to_host (mp); - vat_json_init_array (&root); + vat_json_node_t node; - for (i = 0; i < mp->count; i++) + i32 retval = ntohl (mp->retval); + if (retval == 0) { - e = vat_json_array_add (&root); - fwd = &mp->entries[i]; - - vat_json_init_object (e); - vat_json_object_add_int (e, "fwd_entry_index", fwd->fwd_entry_index); - vat_json_object_add_int (e, "dp_table", fwd->dp_table); - vat_json_object_add_int (e, "vni", fwd->vni); - vat_json_object_add_int (e, "action", fwd->action); + vat_json_init_object (&node); - s = format (0, "%U", format_lisp_flat_eid, fwd->leid); - vec_add1 (s, 0); - vat_json_object_add_string_copy (e, "leid", s); - vec_free (s); + vat_json_object_add_int (&node, "sw_if_index", ntohl (mp->sw_if_index)); - s = format (0, "%U", format_lisp_flat_eid, fwd->reid); - vec_add1 (s, 0); - vat_json_object_add_string_copy (e, "reid", s); - vec_free (s); + vat_json_print (vam->ofp, &node); + vat_json_free (&node); } - - vat_json_print (vam->ofp, &root); - vat_json_free (&root); - -end: - vam->retval = retval; + vam->retval = ntohl (mp->retval); vam->result_ready = 1; } -static void - vl_api_gpe_native_fwd_rpaths_get_reply_t_handler - (vl_api_gpe_native_fwd_rpaths_get_reply_t * mp) +static void vl_api_policer_classify_details_t_handler + (vl_api_policer_classify_details_t * mp) { vat_main_t *vam = &vat_main; - u32 i, n; - int retval = clib_net_to_host_u32 (mp->retval); - vl_api_gpe_native_fwd_rpath_t *r; - - if (retval) - goto end; - - n = clib_net_to_host_u32 (mp->count); - - for (i = 0; i < n; i++) - { - r = &mp->entries[i]; - print (vam->ofp, "fib_index: %d sw_if_index %d nh %U", - clib_net_to_host_u32 (r->fib_index), - clib_net_to_host_u32 (r->nh_sw_if_index), - r->nh_addr.af ? format_ip6_address : format_ip4_address, - r->nh_addr.un); - } -end: - vam->retval = retval; - vam->result_ready = 1; + print (vam->ofp, "%10d%20d", ntohl (mp->sw_if_index), + ntohl (mp->table_index)); } -static void - vl_api_gpe_native_fwd_rpaths_get_reply_t_handler_json - (vl_api_gpe_native_fwd_rpaths_get_reply_t * mp) +static void vl_api_policer_classify_details_t_handler_json + (vl_api_policer_classify_details_t * mp) { vat_main_t *vam = &vat_main; - vat_json_node_t root, *e; - u32 i, n; - int retval = clib_net_to_host_u32 (mp->retval); - vl_api_gpe_native_fwd_rpath_t *r; - u8 *s; - - if (retval) - goto end; - - n = clib_net_to_host_u32 (mp->count); - vat_json_init_array (&root); + vat_json_node_t *node; - for (i = 0; i < n; i++) + if (VAT_JSON_ARRAY != vam->json_tree.type) { - e = vat_json_array_add (&root); - vat_json_init_object (e); - r = &mp->entries[i]; - s = - format (0, "%U", - r->nh_addr.af ? format_ip6_address : format_ip4_address, - r->nh_addr.un); - vec_add1 (s, 0); - vat_json_object_add_string_copy (e, "ip4", s); - vec_free (s); - - vat_json_object_add_uint (e, "fib_index", - clib_net_to_host_u32 (r->fib_index)); - vat_json_object_add_uint (e, "nh_sw_if_index", - clib_net_to_host_u32 (r->nh_sw_if_index)); + ASSERT (VAT_JSON_NONE == vam->json_tree.type); + vat_json_init_array (&vam->json_tree); } + node = vat_json_array_add (&vam->json_tree); - vat_json_print (vam->ofp, &root); - vat_json_free (&root); - -end: - vam->retval = retval; - vam->result_ready = 1; -} - -static void - vl_api_gpe_fwd_entry_vnis_get_reply_t_handler - (vl_api_gpe_fwd_entry_vnis_get_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - u32 i, n; - int retval = clib_net_to_host_u32 (mp->retval); - - if (retval) - goto end; - - n = clib_net_to_host_u32 (mp->count); - - for (i = 0; i < n; i++) - print (vam->ofp, "%d", clib_net_to_host_u32 (mp->vnis[i])); - -end: - vam->retval = retval; - vam->result_ready = 1; -} - -static void - vl_api_gpe_fwd_entry_vnis_get_reply_t_handler_json - (vl_api_gpe_fwd_entry_vnis_get_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - vat_json_node_t root; - u32 i, n; - int retval = clib_net_to_host_u32 (mp->retval); - - if (retval) - goto end; - - n = clib_net_to_host_u32 (mp->count); - vat_json_init_array (&root); - - for (i = 0; i < n; i++) - vat_json_array_add_uint (&root, clib_net_to_host_u32 (mp->vnis[i])); - - vat_json_print (vam->ofp, &root); - vat_json_free (&root); - -end: - vam->retval = retval; - vam->result_ready = 1; + vat_json_init_object (node); + vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index)); + vat_json_object_add_uint (node, "table_index", ntohl (mp->table_index)); } -static void - vl_api_one_ndp_entries_get_reply_t_handler - (vl_api_one_ndp_entries_get_reply_t * mp) +static void vl_api_flow_classify_details_t_handler + (vl_api_flow_classify_details_t * mp) { vat_main_t *vam = &vat_main; - u32 i, n; - int retval = clib_net_to_host_u32 (mp->retval); - if (retval) - goto end; - - n = clib_net_to_host_u32 (mp->count); - - for (i = 0; i < n; i++) - print (vam->ofp, "%U -> %U", format_ip6_address, &mp->entries[i].ip6, - format_ethernet_address, mp->entries[i].mac); - -end: - vam->retval = retval; - vam->result_ready = 1; + print (vam->ofp, "%10d%20d", ntohl (mp->sw_if_index), + ntohl (mp->table_index)); } -static void - vl_api_one_ndp_entries_get_reply_t_handler_json - (vl_api_one_ndp_entries_get_reply_t * mp) +static void vl_api_flow_classify_details_t_handler_json + (vl_api_flow_classify_details_t * mp) { - u8 *s = 0; vat_main_t *vam = &vat_main; - vat_json_node_t *e = 0, root; - u32 i, n; - int retval = clib_net_to_host_u32 (mp->retval); - vl_api_one_ndp_entry_t *arp_entry; - - if (retval) - goto end; - - n = clib_net_to_host_u32 (mp->count); - vat_json_init_array (&root); + vat_json_node_t *node; - for (i = 0; i < n; i++) + if (VAT_JSON_ARRAY != vam->json_tree.type) { - e = vat_json_array_add (&root); - arp_entry = &mp->entries[i]; - - vat_json_init_object (e); - s = format (0, "%U", format_ethernet_address, arp_entry->mac); - vec_add1 (s, 0); - - vat_json_object_add_string_copy (e, "mac", s); - vec_free (s); - - s = format (0, "%U", format_ip6_address, &arp_entry->ip6); - vec_add1 (s, 0); - vat_json_object_add_string_copy (e, "ip6", s); - vec_free (s); + ASSERT (VAT_JSON_NONE == vam->json_tree.type); + vat_json_init_array (&vam->json_tree); } + node = vat_json_array_add (&vam->json_tree); - vat_json_print (vam->ofp, &root); - vat_json_free (&root); - -end: - vam->retval = retval; - vam->result_ready = 1; + vat_json_init_object (node); + vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index)); + vat_json_object_add_uint (node, "table_index", ntohl (mp->table_index)); } -static void - vl_api_one_l2_arp_entries_get_reply_t_handler - (vl_api_one_l2_arp_entries_get_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - u32 i, n; - int retval = clib_net_to_host_u32 (mp->retval); - - if (retval) - goto end; - - n = clib_net_to_host_u32 (mp->count); - - for (i = 0; i < n; i++) - print (vam->ofp, "%U -> %U", format_ip4_address, &mp->entries[i].ip4, - format_ethernet_address, mp->entries[i].mac); - -end: - vam->retval = retval; - vam->result_ready = 1; -} +/* + * Generate boilerplate reply handlers, which + * dig the return value out of the xxx_reply_t API message, + * stick it into vam->retval, and set vam->result_ready + * + * Could also do this by pointing N message decode slots at + * a single function, but that could break in subtle ways. + */ -static void - vl_api_one_l2_arp_entries_get_reply_t_handler_json - (vl_api_one_l2_arp_entries_get_reply_t * mp) -{ - u8 *s = 0; - vat_main_t *vam = &vat_main; - vat_json_node_t *e = 0, root; - u32 i, n; - int retval = clib_net_to_host_u32 (mp->retval); - vl_api_one_l2_arp_entry_t *arp_entry; - - if (retval) - goto end; - - n = clib_net_to_host_u32 (mp->count); - vat_json_init_array (&root); - - for (i = 0; i < n; i++) - { - e = vat_json_array_add (&root); - arp_entry = &mp->entries[i]; - - vat_json_init_object (e); - s = format (0, "%U", format_ethernet_address, arp_entry->mac); - vec_add1 (s, 0); - - vat_json_object_add_string_copy (e, "mac", s); - vec_free (s); - - s = format (0, "%U", format_ip4_address, &arp_entry->ip4); - vec_add1 (s, 0); - vat_json_object_add_string_copy (e, "ip4", s); - vec_free (s); - } - - vat_json_print (vam->ofp, &root); - vat_json_free (&root); - -end: - vam->retval = retval; - vam->result_ready = 1; -} - -static void -vl_api_one_ndp_bd_get_reply_t_handler (vl_api_one_ndp_bd_get_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - u32 i, n; - int retval = clib_net_to_host_u32 (mp->retval); - - if (retval) - goto end; - - n = clib_net_to_host_u32 (mp->count); - - for (i = 0; i < n; i++) - { - print (vam->ofp, "%d", clib_net_to_host_u32 (mp->bridge_domains[i])); - } - -end: - vam->retval = retval; - vam->result_ready = 1; -} - -static void - vl_api_one_ndp_bd_get_reply_t_handler_json - (vl_api_one_ndp_bd_get_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - vat_json_node_t root; - u32 i, n; - int retval = clib_net_to_host_u32 (mp->retval); - - if (retval) - goto end; - - n = clib_net_to_host_u32 (mp->count); - vat_json_init_array (&root); - - for (i = 0; i < n; i++) - { - vat_json_array_add_uint (&root, - clib_net_to_host_u32 (mp->bridge_domains[i])); - } - - vat_json_print (vam->ofp, &root); - vat_json_free (&root); - -end: - vam->retval = retval; - vam->result_ready = 1; -} - -static void - vl_api_one_l2_arp_bd_get_reply_t_handler - (vl_api_one_l2_arp_bd_get_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - u32 i, n; - int retval = clib_net_to_host_u32 (mp->retval); - - if (retval) - goto end; - - n = clib_net_to_host_u32 (mp->count); - - for (i = 0; i < n; i++) - { - print (vam->ofp, "%d", clib_net_to_host_u32 (mp->bridge_domains[i])); - } - -end: - vam->retval = retval; - vam->result_ready = 1; -} - -static void - vl_api_one_l2_arp_bd_get_reply_t_handler_json - (vl_api_one_l2_arp_bd_get_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - vat_json_node_t root; - u32 i, n; - int retval = clib_net_to_host_u32 (mp->retval); - - if (retval) - goto end; - - n = clib_net_to_host_u32 (mp->count); - vat_json_init_array (&root); - - for (i = 0; i < n; i++) - { - vat_json_array_add_uint (&root, - clib_net_to_host_u32 (mp->bridge_domains[i])); - } - - vat_json_print (vam->ofp, &root); - vat_json_free (&root); - -end: - vam->retval = retval; - vam->result_ready = 1; -} - -static void - vl_api_one_adjacencies_get_reply_t_handler - (vl_api_one_adjacencies_get_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - u32 i, n; - int retval = clib_net_to_host_u32 (mp->retval); - vl_api_one_adjacency_t *a; - - if (retval) - goto end; - - n = clib_net_to_host_u32 (mp->count); - - for (i = 0; i < n; i++) - { - a = &mp->adjacencies[i]; - print (vam->ofp, "%U %40U", - format_lisp_flat_eid, a->leid, format_lisp_flat_eid, a->reid); - } - -end: - vam->retval = retval; - vam->result_ready = 1; -} - -static void - vl_api_one_adjacencies_get_reply_t_handler_json - (vl_api_one_adjacencies_get_reply_t * mp) -{ - u8 *s = 0; - vat_main_t *vam = &vat_main; - vat_json_node_t *e = 0, root; - u32 i, n; - int retval = clib_net_to_host_u32 (mp->retval); - vl_api_one_adjacency_t *a; - - if (retval) - goto end; - - n = clib_net_to_host_u32 (mp->count); - vat_json_init_array (&root); - - for (i = 0; i < n; i++) - { - e = vat_json_array_add (&root); - a = &mp->adjacencies[i]; - - vat_json_init_object (e); - s = format (0, "%U", format_lisp_flat_eid, a->leid); - vec_add1 (s, 0); - vat_json_object_add_string_copy (e, "leid", s); - vec_free (s); - - s = format (0, "%U", format_lisp_flat_eid, a->reid); - vec_add1 (s, 0); - vat_json_object_add_string_copy (e, "reid", s); - vec_free (s); - } - - vat_json_print (vam->ofp, &root); - vat_json_free (&root); - -end: - vam->retval = retval; - vam->result_ready = 1; -} - -static void -vl_api_one_map_server_details_t_handler (vl_api_one_map_server_details_t * mp) -{ - vat_main_t *vam = &vat_main; - - print (vam->ofp, "%=20U", - mp->ip_address.af ? format_ip6_address : format_ip4_address, - mp->ip_address.un); -} - -static void - vl_api_one_map_server_details_t_handler_json - (vl_api_one_map_server_details_t * mp) -{ - vat_main_t *vam = &vat_main; - vat_json_node_t *node = NULL; - struct in6_addr ip6; - struct in_addr ip4; +#define foreach_standard_reply_retval_handler \ +_(sw_interface_set_flags_reply) \ +_(sw_interface_add_del_address_reply) \ +_(sw_interface_set_rx_mode_reply) \ +_(sw_interface_set_rx_placement_reply) \ +_(sw_interface_set_table_reply) \ +_(sw_interface_set_mpls_enable_reply) \ +_(sw_interface_set_vpath_reply) \ +_(sw_interface_set_vxlan_bypass_reply) \ +_(sw_interface_set_vxlan_gpe_bypass_reply) \ +_(sw_interface_set_l2_bridge_reply) \ +_(sw_interface_set_bond_weight_reply) \ +_(bridge_domain_add_del_reply) \ +_(sw_interface_set_l2_xconnect_reply) \ +_(l2fib_add_del_reply) \ +_(l2fib_flush_int_reply) \ +_(l2fib_flush_bd_reply) \ +_(ip_route_add_del_reply) \ +_(ip_table_add_del_reply) \ +_(ip_table_replace_begin_reply) \ +_(ip_table_flush_reply) \ +_(ip_table_replace_end_reply) \ +_(ip_mroute_add_del_reply) \ +_(mpls_route_add_del_reply) \ +_(mpls_table_add_del_reply) \ +_(mpls_ip_bind_unbind_reply) \ +_(bier_route_add_del_reply) \ +_(bier_table_add_del_reply) \ +_(sw_interface_set_unnumbered_reply) \ +_(set_ip_flow_hash_reply) \ +_(sw_interface_ip6_enable_disable_reply) \ +_(l2_patch_add_del_reply) \ +_(sr_mpls_policy_add_reply) \ +_(sr_mpls_policy_mod_reply) \ +_(sr_mpls_policy_del_reply) \ +_(sr_policy_add_reply) \ +_(sr_policy_mod_reply) \ +_(sr_policy_del_reply) \ +_(sr_localsid_add_del_reply) \ +_(sr_steering_add_del_reply) \ +_(classify_add_del_session_reply) \ +_(classify_set_interface_ip_table_reply) \ +_(classify_set_interface_l2_tables_reply) \ +_(l2_fib_clear_table_reply) \ +_(l2_interface_efp_filter_reply) \ +_(l2_interface_vlan_tag_rewrite_reply) \ +_(modify_vhost_user_if_reply) \ +_(delete_vhost_user_if_reply) \ +_(want_l2_macs_events_reply) \ +_(input_acl_set_interface_reply) \ +_(ipsec_spd_add_del_reply) \ +_(ipsec_interface_add_del_spd_reply) \ +_(ipsec_spd_entry_add_del_reply) \ +_(ipsec_sad_entry_add_del_reply) \ +_(ipsec_tunnel_if_add_del_reply) \ +_(ipsec_tunnel_if_set_sa_reply) \ +_(delete_loopback_reply) \ +_(bd_ip_mac_add_del_reply) \ +_(bd_ip_mac_flush_reply) \ +_(want_interface_events_reply) \ +_(cop_interface_enable_disable_reply) \ +_(cop_whitelist_enable_disable_reply) \ +_(sw_interface_clear_stats_reply) \ +_(ioam_enable_reply) \ +_(ioam_disable_reply) \ +_(af_packet_delete_reply) \ +_(policer_classify_set_interface_reply) \ +_(set_ipfix_exporter_reply) \ +_(set_ipfix_classify_stream_reply) \ +_(ipfix_classify_table_add_del_reply) \ +_(flow_classify_set_interface_reply) \ +_(sw_interface_span_enable_disable_reply) \ +_(pg_capture_reply) \ +_(pg_enable_disable_reply) \ +_(pg_interface_enable_disable_coalesce_reply) \ +_(ip_source_and_port_range_check_add_del_reply) \ +_(ip_source_and_port_range_check_interface_add_del_reply)\ +_(delete_subif_reply) \ +_(l2_interface_pbb_tag_rewrite_reply) \ +_(set_punt_reply) \ +_(feature_enable_disable_reply) \ +_(feature_gso_enable_disable_reply) \ +_(sw_interface_tag_add_del_reply) \ +_(sw_interface_add_del_mac_address_reply) \ +_(hw_interface_set_mtu_reply) \ +_(p2p_ethernet_add_reply) \ +_(p2p_ethernet_del_reply) \ +_(tcp_configure_src_addresses_reply) \ +_(session_rule_add_del_reply) \ +_(ip_container_proxy_add_del_reply) \ +_(output_acl_set_interface_reply) \ +_(qos_record_enable_disable_reply) \ +_(flow_add_reply) - if (VAT_JSON_ARRAY != vam->json_tree.type) - { - ASSERT (VAT_JSON_NONE == vam->json_tree.type); - vat_json_init_array (&vam->json_tree); +#define _(n) \ + static void vl_api_##n##_t_handler \ + (vl_api_##n##_t * mp) \ + { \ + vat_main_t * vam = &vat_main; \ + i32 retval = ntohl(mp->retval); \ + if (vam->async_mode) { \ + vam->async_errors += (retval < 0); \ + } else { \ + vam->retval = retval; \ + vam->result_ready = 1; \ + } \ } - node = vat_json_array_add (&vam->json_tree); +foreach_standard_reply_retval_handler; +#undef _ - vat_json_init_object (node); - if (mp->ip_address.af) - { - clib_memcpy (&ip6, mp->ip_address.un.ip6, sizeof (ip6)); - vat_json_object_add_ip6 (node, "map-server", ip6); - } - else - { - clib_memcpy (&ip4, mp->ip_address.un.ip4, sizeof (ip4)); - vat_json_object_add_ip4 (node, "map-server", ip4); +#define _(n) \ + static void vl_api_##n##_t_handler_json \ + (vl_api_##n##_t * mp) \ + { \ + vat_main_t * vam = &vat_main; \ + vat_json_node_t node; \ + vat_json_init_object(&node); \ + vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \ + vat_json_print(vam->ofp, &node); \ + vam->retval = ntohl(mp->retval); \ + vam->result_ready = 1; \ } -} - -static void -vl_api_one_map_resolver_details_t_handler (vl_api_one_map_resolver_details_t - * mp) -{ - vat_main_t *vam = &vat_main; +foreach_standard_reply_retval_handler; +#undef _ - print (vam->ofp, "%=20U", - mp->ip_address.af ? format_ip6_address : format_ip4_address, - mp->ip_address.un); -} +/* + * Table of message reply handlers, must include boilerplate handlers + * we just generated + */ -static void - vl_api_one_map_resolver_details_t_handler_json - (vl_api_one_map_resolver_details_t * mp) -{ - vat_main_t *vam = &vat_main; - vat_json_node_t *node = NULL; - struct in6_addr ip6; - struct in_addr ip4; - - if (VAT_JSON_ARRAY != vam->json_tree.type) - { - ASSERT (VAT_JSON_NONE == vam->json_tree.type); - vat_json_init_array (&vam->json_tree); - } - node = vat_json_array_add (&vam->json_tree); - - vat_json_init_object (node); - if (mp->ip_address.af) - { - clib_memcpy (&ip6, mp->ip_address.un.ip6, sizeof (ip6)); - vat_json_object_add_ip6 (node, "map resolver", ip6); - } - else - { - clib_memcpy (&ip4, mp->ip_address.un.ip4, sizeof (ip4)); - vat_json_object_add_ip4 (node, "map resolver", ip4); - } -} - -static void -vl_api_show_one_status_reply_t_handler (vl_api_show_one_status_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - i32 retval = ntohl (mp->retval); - - if (0 <= retval) - { - print (vam->ofp, "feature: %s\ngpe: %s", - mp->feature_status ? "enabled" : "disabled", - mp->gpe_status ? "enabled" : "disabled"); - } - - vam->retval = retval; - vam->result_ready = 1; -} - -static void - vl_api_show_one_status_reply_t_handler_json - (vl_api_show_one_status_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - vat_json_node_t node; - u8 *gpe_status = NULL; - u8 *feature_status = NULL; - - gpe_status = format (0, "%s", mp->gpe_status ? "enabled" : "disabled"); - feature_status = format (0, "%s", - mp->feature_status ? "enabled" : "disabled"); - vec_add1 (gpe_status, 0); - vec_add1 (feature_status, 0); - - vat_json_init_object (&node); - vat_json_object_add_string_copy (&node, "gpe_status", gpe_status); - vat_json_object_add_string_copy (&node, "feature_status", feature_status); - - vec_free (gpe_status); - vec_free (feature_status); - - vat_json_print (vam->ofp, &node); - vat_json_free (&node); - - vam->retval = ntohl (mp->retval); - vam->result_ready = 1; -} - -static void - vl_api_one_get_map_request_itr_rlocs_reply_t_handler - (vl_api_one_get_map_request_itr_rlocs_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - i32 retval = ntohl (mp->retval); - - if (retval >= 0) - { - print (vam->ofp, "%=20s", mp->locator_set_name); - } - - vam->retval = retval; - vam->result_ready = 1; -} - -static void - vl_api_one_get_map_request_itr_rlocs_reply_t_handler_json - (vl_api_one_get_map_request_itr_rlocs_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - vat_json_node_t *node = NULL; - - if (VAT_JSON_ARRAY != vam->json_tree.type) - { - ASSERT (VAT_JSON_NONE == vam->json_tree.type); - vat_json_init_array (&vam->json_tree); - } - node = vat_json_array_add (&vam->json_tree); - - vat_json_init_object (node); - vat_json_object_add_string_copy (node, "itr-rlocs", mp->locator_set_name); - - vat_json_print (vam->ofp, node); - vat_json_free (node); - - vam->retval = ntohl (mp->retval); - vam->result_ready = 1; -} - -static u8 * -format_lisp_map_request_mode (u8 * s, va_list * args) -{ - u32 mode = va_arg (*args, u32); - - switch (mode) - { - case 0: - return format (0, "dst-only"); - case 1: - return format (0, "src-dst"); - } - return 0; -} - -static void - vl_api_show_one_map_request_mode_reply_t_handler - (vl_api_show_one_map_request_mode_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - i32 retval = ntohl (mp->retval); - - if (0 <= retval) - { - u32 mode = mp->mode; - print (vam->ofp, "map_request_mode: %U", - format_lisp_map_request_mode, mode); - } - - vam->retval = retval; - vam->result_ready = 1; -} - -static void - vl_api_show_one_map_request_mode_reply_t_handler_json - (vl_api_show_one_map_request_mode_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - vat_json_node_t node; - u8 *s = 0; - u32 mode; - - mode = mp->mode; - s = format (0, "%U", format_lisp_map_request_mode, mode); - vec_add1 (s, 0); - - vat_json_init_object (&node); - vat_json_object_add_string_copy (&node, "map_request_mode", s); - vat_json_print (vam->ofp, &node); - vat_json_free (&node); - - vec_free (s); - vam->retval = ntohl (mp->retval); - vam->result_ready = 1; -} - -static void - vl_api_one_show_xtr_mode_reply_t_handler - (vl_api_one_show_xtr_mode_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - i32 retval = ntohl (mp->retval); - - if (0 <= retval) - { - print (vam->ofp, "%s\n", mp->is_enable ? "enabled" : "disabled"); - } - - vam->retval = retval; - vam->result_ready = 1; -} - -static void - vl_api_one_show_xtr_mode_reply_t_handler_json - (vl_api_one_show_xtr_mode_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - vat_json_node_t node; - u8 *status = 0; - - status = format (0, "%s", mp->is_enable ? "enabled" : "disabled"); - vec_add1 (status, 0); - - vat_json_init_object (&node); - vat_json_object_add_string_copy (&node, "status", status); - - vec_free (status); - - vat_json_print (vam->ofp, &node); - vat_json_free (&node); - - vam->retval = ntohl (mp->retval); - vam->result_ready = 1; -} - -static void - vl_api_one_show_pitr_mode_reply_t_handler - (vl_api_one_show_pitr_mode_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - i32 retval = ntohl (mp->retval); - - if (0 <= retval) - { - print (vam->ofp, "%s\n", mp->is_enable ? "enabled" : "disabled"); - } - - vam->retval = retval; - vam->result_ready = 1; -} - -static void - vl_api_one_show_pitr_mode_reply_t_handler_json - (vl_api_one_show_pitr_mode_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - vat_json_node_t node; - u8 *status = 0; - - status = format (0, "%s", mp->is_enable ? "enabled" : "disabled"); - vec_add1 (status, 0); - - vat_json_init_object (&node); - vat_json_object_add_string_copy (&node, "status", status); - - vec_free (status); - - vat_json_print (vam->ofp, &node); - vat_json_free (&node); - - vam->retval = ntohl (mp->retval); - vam->result_ready = 1; -} - -static void - vl_api_one_show_petr_mode_reply_t_handler - (vl_api_one_show_petr_mode_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - i32 retval = ntohl (mp->retval); - - if (0 <= retval) - { - print (vam->ofp, "%s\n", mp->is_enable ? "enabled" : "disabled"); - } - - vam->retval = retval; - vam->result_ready = 1; -} - -static void - vl_api_one_show_petr_mode_reply_t_handler_json - (vl_api_one_show_petr_mode_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - vat_json_node_t node; - u8 *status = 0; - - status = format (0, "%s", mp->is_enable ? "enabled" : "disabled"); - vec_add1 (status, 0); - - vat_json_init_object (&node); - vat_json_object_add_string_copy (&node, "status", status); - - vec_free (status); - - vat_json_print (vam->ofp, &node); - vat_json_free (&node); - - vam->retval = ntohl (mp->retval); - vam->result_ready = 1; -} - -static void - vl_api_show_one_use_petr_reply_t_handler - (vl_api_show_one_use_petr_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - i32 retval = ntohl (mp->retval); - - if (0 <= retval) - { - print (vam->ofp, "%s\n", mp->status ? "enabled" : "disabled"); - if (mp->status) - { - print (vam->ofp, "Proxy-ETR address; %U", - mp->ip_address.af ? format_ip6_address : format_ip4_address, - mp->ip_address.un); - } - } - - vam->retval = retval; - vam->result_ready = 1; -} - -static void - vl_api_show_one_use_petr_reply_t_handler_json - (vl_api_show_one_use_petr_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - vat_json_node_t node; - u8 *status = 0; - struct in_addr ip4; - struct in6_addr ip6; - - status = format (0, "%s", mp->status ? "enabled" : "disabled"); - vec_add1 (status, 0); - - vat_json_init_object (&node); - vat_json_object_add_string_copy (&node, "status", status); - if (mp->status) - { - if (mp->ip_address.af) - { - clib_memcpy (&ip6, mp->ip_address.un.ip6, sizeof (ip6)); - vat_json_object_add_ip6 (&node, "address", ip6); - } - else - { - clib_memcpy (&ip4, mp->ip_address.un.ip4, sizeof (ip4)); - vat_json_object_add_ip4 (&node, "address", ip4); - } - } - - vec_free (status); - - vat_json_print (vam->ofp, &node); - vat_json_free (&node); - - vam->retval = ntohl (mp->retval); - vam->result_ready = 1; -} - -static void - vl_api_show_one_nsh_mapping_reply_t_handler - (vl_api_show_one_nsh_mapping_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - i32 retval = ntohl (mp->retval); - - if (0 <= retval) - { - print (vam->ofp, "%-20s%-16s", - mp->is_set ? "set" : "not-set", - mp->is_set ? (char *) mp->locator_set_name : ""); - } - - vam->retval = retval; - vam->result_ready = 1; -} - -static void - vl_api_show_one_nsh_mapping_reply_t_handler_json - (vl_api_show_one_nsh_mapping_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - vat_json_node_t node; - u8 *status = 0; - - status = format (0, "%s", mp->is_set ? "yes" : "no"); - vec_add1 (status, 0); - - vat_json_init_object (&node); - vat_json_object_add_string_copy (&node, "is_set", status); - if (mp->is_set) - { - vat_json_object_add_string_copy (&node, "locator_set", - mp->locator_set_name); - } - - vec_free (status); - - vat_json_print (vam->ofp, &node); - vat_json_free (&node); - - vam->retval = ntohl (mp->retval); - vam->result_ready = 1; -} - -static void - vl_api_show_one_map_register_ttl_reply_t_handler - (vl_api_show_one_map_register_ttl_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - i32 retval = ntohl (mp->retval); - - vl_api_show_one_map_register_ttl_reply_t_endian (mp); - - if (0 <= retval) - { - print (vam->ofp, "ttl: %u", mp->ttl); - } - - vam->retval = retval; - vam->result_ready = 1; -} - -static void - vl_api_show_one_map_register_ttl_reply_t_handler_json - (vl_api_show_one_map_register_ttl_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - vat_json_node_t node; - - vl_api_show_one_map_register_ttl_reply_t_endian (mp); - vat_json_init_object (&node); - vat_json_object_add_uint (&node, "ttl", mp->ttl); - - vat_json_print (vam->ofp, &node); - vat_json_free (&node); - - vam->retval = ntohl (mp->retval); - vam->result_ready = 1; -} - -static void -vl_api_show_one_pitr_reply_t_handler (vl_api_show_one_pitr_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - i32 retval = ntohl (mp->retval); - - if (0 <= retval) - { - print (vam->ofp, "%-20s%-16s", - mp->status ? "enabled" : "disabled", - mp->status ? (char *) mp->locator_set_name : ""); - } - - vam->retval = retval; - vam->result_ready = 1; -} - -static void -vl_api_show_one_pitr_reply_t_handler_json (vl_api_show_one_pitr_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - vat_json_node_t node; - u8 *status = 0; - - status = format (0, "%s", mp->status ? "enabled" : "disabled"); - vec_add1 (status, 0); - - vat_json_init_object (&node); - vat_json_object_add_string_copy (&node, "status", status); - if (mp->status) - { - vat_json_object_add_string_copy (&node, "locator_set", - mp->locator_set_name); - } - - vec_free (status); - - vat_json_print (vam->ofp, &node); - vat_json_free (&node); - - vam->retval = ntohl (mp->retval); - vam->result_ready = 1; -} - -static u8 * -format_policer_type (u8 * s, va_list * va) -{ - u32 i = va_arg (*va, u32); - - if (i == SSE2_QOS_POLICER_TYPE_1R2C) - s = format (s, "1r2c"); - else if (i == SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697) - s = format (s, "1r3c"); - else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698) - s = format (s, "2r3c-2698"); - else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115) - s = format (s, "2r3c-4115"); - else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1) - s = format (s, "2r3c-mef5cf1"); - else - s = format (s, "ILLEGAL"); - return s; -} - -static u8 * -format_policer_rate_type (u8 * s, va_list * va) -{ - u32 i = va_arg (*va, u32); - - if (i == SSE2_QOS_RATE_KBPS) - s = format (s, "kbps"); - else if (i == SSE2_QOS_RATE_PPS) - s = format (s, "pps"); - else - s = format (s, "ILLEGAL"); - return s; -} - -static u8 * -format_policer_round_type (u8 * s, va_list * va) -{ - u32 i = va_arg (*va, u32); - - if (i == SSE2_QOS_ROUND_TO_CLOSEST) - s = format (s, "closest"); - else if (i == SSE2_QOS_ROUND_TO_UP) - s = format (s, "up"); - else if (i == SSE2_QOS_ROUND_TO_DOWN) - s = format (s, "down"); - else - s = format (s, "ILLEGAL"); - return s; -} - -static u8 * -format_policer_action_type (u8 * s, va_list * va) -{ - u32 i = va_arg (*va, u32); - - if (i == SSE2_QOS_ACTION_DROP) - s = format (s, "drop"); - else if (i == SSE2_QOS_ACTION_TRANSMIT) - s = format (s, "transmit"); - else if (i == SSE2_QOS_ACTION_MARK_AND_TRANSMIT) - s = format (s, "mark-and-transmit"); - else - s = format (s, "ILLEGAL"); - return s; -} - -static u8 * -format_dscp (u8 * s, va_list * va) -{ - u32 i = va_arg (*va, u32); - char *t = 0; - - switch (i) - { -#define _(v,f,str) case VNET_DSCP_##f: t = str; break; - foreach_vnet_dscp -#undef _ - default: - return format (s, "ILLEGAL"); - } - s = format (s, "%s", t); - return s; -} - -static void -vl_api_policer_details_t_handler (vl_api_policer_details_t * mp) -{ - vat_main_t *vam = &vat_main; - u8 *conform_dscp_str, *exceed_dscp_str, *violate_dscp_str; - - if (mp->conform_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT) - conform_dscp_str = format (0, "%U", format_dscp, mp->conform_action.dscp); - else - conform_dscp_str = format (0, ""); - - if (mp->exceed_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT) - exceed_dscp_str = format (0, "%U", format_dscp, mp->exceed_action.dscp); - else - exceed_dscp_str = format (0, ""); - - if (mp->violate_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT) - violate_dscp_str = format (0, "%U", format_dscp, mp->violate_action.dscp); - else - violate_dscp_str = format (0, ""); - - print (vam->ofp, "Name \"%s\", type %U, cir %u, eir %u, cb %u, eb %u, " - "rate type %U, round type %U, %s rate, %s color-aware, " - "cir %u tok/period, pir %u tok/period, scale %u, cur lim %u, " - "cur bkt %u, ext lim %u, ext bkt %u, last update %llu" - "conform action %U%s, exceed action %U%s, violate action %U%s", - mp->name, - format_policer_type, mp->type, - ntohl (mp->cir), - ntohl (mp->eir), - clib_net_to_host_u64 (mp->cb), - clib_net_to_host_u64 (mp->eb), - format_policer_rate_type, mp->rate_type, - format_policer_round_type, mp->round_type, - mp->single_rate ? "single" : "dual", - mp->color_aware ? "is" : "not", - ntohl (mp->cir_tokens_per_period), - ntohl (mp->pir_tokens_per_period), - ntohl (mp->scale), - ntohl (mp->current_limit), - ntohl (mp->current_bucket), - ntohl (mp->extended_limit), - ntohl (mp->extended_bucket), - clib_net_to_host_u64 (mp->last_update_time), - format_policer_action_type, mp->conform_action.type, - conform_dscp_str, - format_policer_action_type, mp->exceed_action.type, - exceed_dscp_str, - format_policer_action_type, mp->violate_action.type, - violate_dscp_str); - - vec_free (conform_dscp_str); - vec_free (exceed_dscp_str); - vec_free (violate_dscp_str); -} - -static void vl_api_policer_details_t_handler_json - (vl_api_policer_details_t * mp) -{ - vat_main_t *vam = &vat_main; - vat_json_node_t *node; - u8 *rate_type_str, *round_type_str, *type_str; - u8 *conform_action_str, *exceed_action_str, *violate_action_str; - - rate_type_str = format (0, "%U", format_policer_rate_type, mp->rate_type); - round_type_str = - format (0, "%U", format_policer_round_type, mp->round_type); - type_str = format (0, "%U", format_policer_type, mp->type); - conform_action_str = format (0, "%U", format_policer_action_type, - mp->conform_action.type); - exceed_action_str = format (0, "%U", format_policer_action_type, - mp->exceed_action.type); - violate_action_str = format (0, "%U", format_policer_action_type, - mp->violate_action.type); - - if (VAT_JSON_ARRAY != vam->json_tree.type) - { - ASSERT (VAT_JSON_NONE == vam->json_tree.type); - vat_json_init_array (&vam->json_tree); - } - node = vat_json_array_add (&vam->json_tree); - - vat_json_init_object (node); - vat_json_object_add_string_copy (node, "name", mp->name); - vat_json_object_add_uint (node, "cir", ntohl (mp->cir)); - vat_json_object_add_uint (node, "eir", ntohl (mp->eir)); - vat_json_object_add_uint (node, "cb", clib_net_to_host_u64 (mp->cb)); - vat_json_object_add_uint (node, "eb", clib_net_to_host_u64 (mp->eb)); - vat_json_object_add_string_copy (node, "rate_type", rate_type_str); - vat_json_object_add_string_copy (node, "round_type", round_type_str); - vat_json_object_add_string_copy (node, "type", type_str); - vat_json_object_add_uint (node, "single_rate", mp->single_rate); - vat_json_object_add_uint (node, "color_aware", mp->color_aware); - vat_json_object_add_uint (node, "scale", ntohl (mp->scale)); - vat_json_object_add_uint (node, "cir_tokens_per_period", - ntohl (mp->cir_tokens_per_period)); - vat_json_object_add_uint (node, "eir_tokens_per_period", - ntohl (mp->pir_tokens_per_period)); - vat_json_object_add_uint (node, "current_limit", ntohl (mp->current_limit)); - vat_json_object_add_uint (node, "current_bucket", - ntohl (mp->current_bucket)); - vat_json_object_add_uint (node, "extended_limit", - ntohl (mp->extended_limit)); - vat_json_object_add_uint (node, "extended_bucket", - ntohl (mp->extended_bucket)); - vat_json_object_add_uint (node, "last_update_time", - ntohl (mp->last_update_time)); - vat_json_object_add_string_copy (node, "conform_action", - conform_action_str); - if (mp->conform_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT) - { - u8 *dscp_str = format (0, "%U", format_dscp, mp->conform_action.dscp); - vat_json_object_add_string_copy (node, "conform_dscp", dscp_str); - vec_free (dscp_str); - } - vat_json_object_add_string_copy (node, "exceed_action", exceed_action_str); - if (mp->exceed_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT) - { - u8 *dscp_str = format (0, "%U", format_dscp, mp->exceed_action.dscp); - vat_json_object_add_string_copy (node, "exceed_dscp", dscp_str); - vec_free (dscp_str); - } - vat_json_object_add_string_copy (node, "violate_action", - violate_action_str); - if (mp->violate_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT) - { - u8 *dscp_str = format (0, "%U", format_dscp, mp->violate_action.dscp); - vat_json_object_add_string_copy (node, "violate_dscp", dscp_str); - vec_free (dscp_str); - } - - vec_free (rate_type_str); - vec_free (round_type_str); - vec_free (type_str); - vec_free (conform_action_str); - vec_free (exceed_action_str); - vec_free (violate_action_str); -} - -static void -vl_api_classify_table_ids_reply_t_handler (vl_api_classify_table_ids_reply_t * - mp) -{ - vat_main_t *vam = &vat_main; - int i, count = ntohl (mp->count); - - if (count > 0) - print (vam->ofp, "classify table ids (%d) : ", count); - for (i = 0; i < count; i++) - { - print (vam->ofp, "%d", ntohl (mp->ids[i])); - print (vam->ofp, (i < count - 1) ? "," : ""); - } - vam->retval = ntohl (mp->retval); - vam->result_ready = 1; -} - -static void - vl_api_classify_table_ids_reply_t_handler_json - (vl_api_classify_table_ids_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - int i, count = ntohl (mp->count); - - if (count > 0) - { - vat_json_node_t node; - - vat_json_init_object (&node); - for (i = 0; i < count; i++) - { - vat_json_object_add_uint (&node, "table_id", ntohl (mp->ids[i])); - } - vat_json_print (vam->ofp, &node); - vat_json_free (&node); - } - vam->retval = ntohl (mp->retval); - vam->result_ready = 1; -} - -static void - vl_api_classify_table_by_interface_reply_t_handler - (vl_api_classify_table_by_interface_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - u32 table_id; - - table_id = ntohl (mp->l2_table_id); - if (table_id != ~0) - print (vam->ofp, "l2 table id : %d", table_id); - else - print (vam->ofp, "l2 table id : No input ACL tables configured"); - table_id = ntohl (mp->ip4_table_id); - if (table_id != ~0) - print (vam->ofp, "ip4 table id : %d", table_id); - else - print (vam->ofp, "ip4 table id : No input ACL tables configured"); - table_id = ntohl (mp->ip6_table_id); - if (table_id != ~0) - print (vam->ofp, "ip6 table id : %d", table_id); - else - print (vam->ofp, "ip6 table id : No input ACL tables configured"); - vam->retval = ntohl (mp->retval); - vam->result_ready = 1; -} - -static void - vl_api_classify_table_by_interface_reply_t_handler_json - (vl_api_classify_table_by_interface_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - vat_json_node_t node; - - vat_json_init_object (&node); - - vat_json_object_add_int (&node, "l2_table_id", ntohl (mp->l2_table_id)); - vat_json_object_add_int (&node, "ip4_table_id", ntohl (mp->ip4_table_id)); - vat_json_object_add_int (&node, "ip6_table_id", ntohl (mp->ip6_table_id)); - - vat_json_print (vam->ofp, &node); - vat_json_free (&node); - - vam->retval = ntohl (mp->retval); - vam->result_ready = 1; -} - -static void vl_api_policer_add_del_reply_t_handler - (vl_api_policer_add_del_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - i32 retval = ntohl (mp->retval); - if (vam->async_mode) - { - vam->async_errors += (retval < 0); - } - else - { - vam->retval = retval; - vam->result_ready = 1; - if (retval == 0 && mp->policer_index != 0xFFFFFFFF) - /* - * Note: this is just barely thread-safe, depends on - * the main thread spinning waiting for an answer... - */ - errmsg ("policer index %d", ntohl (mp->policer_index)); - } -} - -static void vl_api_policer_add_del_reply_t_handler_json - (vl_api_policer_add_del_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - vat_json_node_t node; - - vat_json_init_object (&node); - vat_json_object_add_int (&node, "retval", ntohl (mp->retval)); - vat_json_object_add_uint (&node, "policer_index", - ntohl (mp->policer_index)); - - vat_json_print (vam->ofp, &node); - vat_json_free (&node); - - vam->retval = ntohl (mp->retval); - vam->result_ready = 1; -} - -/* Format hex dump. */ -u8 * -format_hex_bytes (u8 * s, va_list * va) -{ - u8 *bytes = va_arg (*va, u8 *); - int n_bytes = va_arg (*va, int); - uword i; - - /* Print short or long form depending on byte count. */ - uword short_form = n_bytes <= 32; - u32 indent = format_get_indent (s); - - if (n_bytes == 0) - return s; - - for (i = 0; i < n_bytes; i++) - { - if (!short_form && (i % 32) == 0) - s = format (s, "%08x: ", i); - s = format (s, "%02x", bytes[i]); - if (!short_form && ((i + 1) % 32) == 0 && (i + 1) < n_bytes) - s = format (s, "\n%U", format_white_space, indent); - } - - return s; -} - -static void -vl_api_classify_table_info_reply_t_handler (vl_api_classify_table_info_reply_t - * mp) -{ - vat_main_t *vam = &vat_main; - i32 retval = ntohl (mp->retval); - if (retval == 0) - { - print (vam->ofp, "classify table info :"); - print (vam->ofp, "sessions: %d nexttbl: %d nextnode: %d", - ntohl (mp->active_sessions), ntohl (mp->next_table_index), - ntohl (mp->miss_next_index)); - print (vam->ofp, "nbuckets: %d skip: %d match: %d", - ntohl (mp->nbuckets), ntohl (mp->skip_n_vectors), - ntohl (mp->match_n_vectors)); - print (vam->ofp, "mask: %U", format_hex_bytes, mp->mask, - ntohl (mp->mask_length)); - } - vam->retval = retval; - vam->result_ready = 1; -} - -static void - vl_api_classify_table_info_reply_t_handler_json - (vl_api_classify_table_info_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - vat_json_node_t node; - - i32 retval = ntohl (mp->retval); - if (retval == 0) - { - vat_json_init_object (&node); - - vat_json_object_add_int (&node, "sessions", - ntohl (mp->active_sessions)); - vat_json_object_add_int (&node, "nexttbl", - ntohl (mp->next_table_index)); - vat_json_object_add_int (&node, "nextnode", - ntohl (mp->miss_next_index)); - vat_json_object_add_int (&node, "nbuckets", ntohl (mp->nbuckets)); - vat_json_object_add_int (&node, "skip", ntohl (mp->skip_n_vectors)); - vat_json_object_add_int (&node, "match", ntohl (mp->match_n_vectors)); - u8 *s = format (0, "%U%c", format_hex_bytes, mp->mask, - ntohl (mp->mask_length), 0); - vat_json_object_add_string_copy (&node, "mask", s); - - vat_json_print (vam->ofp, &node); - vat_json_free (&node); - } - vam->retval = ntohl (mp->retval); - vam->result_ready = 1; -} - -static void -vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t * - mp) -{ - vat_main_t *vam = &vat_main; - - print (vam->ofp, "next_index: %d advance: %d opaque: %d ", - ntohl (mp->hit_next_index), ntohl (mp->advance), - ntohl (mp->opaque_index)); - print (vam->ofp, "mask: %U", format_hex_bytes, mp->match, - ntohl (mp->match_length)); -} - -static void - vl_api_classify_session_details_t_handler_json - (vl_api_classify_session_details_t * mp) -{ - vat_main_t *vam = &vat_main; - vat_json_node_t *node = NULL; - - if (VAT_JSON_ARRAY != vam->json_tree.type) - { - ASSERT (VAT_JSON_NONE == vam->json_tree.type); - vat_json_init_array (&vam->json_tree); - } - node = vat_json_array_add (&vam->json_tree); - - vat_json_init_object (node); - vat_json_object_add_int (node, "next_index", ntohl (mp->hit_next_index)); - vat_json_object_add_int (node, "advance", ntohl (mp->advance)); - vat_json_object_add_int (node, "opaque", ntohl (mp->opaque_index)); - u8 *s = - format (0, "%U%c", format_hex_bytes, mp->match, ntohl (mp->match_length), - 0); - vat_json_object_add_string_copy (node, "match", s); -} - -static void vl_api_pg_create_interface_reply_t_handler - (vl_api_pg_create_interface_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - - vam->retval = ntohl (mp->retval); - vam->result_ready = 1; -} - -static void vl_api_pg_create_interface_reply_t_handler_json - (vl_api_pg_create_interface_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - vat_json_node_t node; - - i32 retval = ntohl (mp->retval); - if (retval == 0) - { - vat_json_init_object (&node); - - vat_json_object_add_int (&node, "sw_if_index", ntohl (mp->sw_if_index)); - - vat_json_print (vam->ofp, &node); - vat_json_free (&node); - } - vam->retval = ntohl (mp->retval); - vam->result_ready = 1; -} - -static void vl_api_policer_classify_details_t_handler - (vl_api_policer_classify_details_t * mp) -{ - vat_main_t *vam = &vat_main; - - print (vam->ofp, "%10d%20d", ntohl (mp->sw_if_index), - ntohl (mp->table_index)); -} - -static void vl_api_policer_classify_details_t_handler_json - (vl_api_policer_classify_details_t * mp) -{ - vat_main_t *vam = &vat_main; - vat_json_node_t *node; - - if (VAT_JSON_ARRAY != vam->json_tree.type) - { - ASSERT (VAT_JSON_NONE == vam->json_tree.type); - vat_json_init_array (&vam->json_tree); - } - node = vat_json_array_add (&vam->json_tree); - - vat_json_init_object (node); - vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index)); - vat_json_object_add_uint (node, "table_index", ntohl (mp->table_index)); -} - -static void vl_api_flow_classify_details_t_handler - (vl_api_flow_classify_details_t * mp) -{ - vat_main_t *vam = &vat_main; - - print (vam->ofp, "%10d%20d", ntohl (mp->sw_if_index), - ntohl (mp->table_index)); -} - -static void vl_api_flow_classify_details_t_handler_json - (vl_api_flow_classify_details_t * mp) -{ - vat_main_t *vam = &vat_main; - vat_json_node_t *node; - - if (VAT_JSON_ARRAY != vam->json_tree.type) - { - ASSERT (VAT_JSON_NONE == vam->json_tree.type); - vat_json_init_array (&vam->json_tree); - } - node = vat_json_array_add (&vam->json_tree); - - vat_json_init_object (node); - vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index)); - vat_json_object_add_uint (node, "table_index", ntohl (mp->table_index)); -} - -#define vl_api_one_adjacencies_get_reply_t_endian vl_noop_handler -#define vl_api_one_adjacencies_get_reply_t_print vl_noop_handler -#define vl_api_one_l2_arp_bd_get_reply_t_print vl_noop_handler -#define vl_api_one_l2_arp_entries_get_reply_t_endian vl_noop_handler -#define vl_api_one_l2_arp_entries_get_reply_t_print vl_noop_handler -#define vl_api_one_l2_arp_bd_get_reply_t_endian vl_noop_handler -#define vl_api_one_ndp_bd_get_reply_t_endian vl_noop_handler -#define vl_api_one_ndp_bd_get_reply_t_print vl_noop_handler -#define vl_api_one_ndp_entries_get_reply_t_print vl_noop_handler -#define vl_api_one_ndp_entries_get_reply_t_endian vl_noop_handler - -/* - * Generate boilerplate reply handlers, which - * dig the return value out of the xxx_reply_t API message, - * stick it into vam->retval, and set vam->result_ready - * - * Could also do this by pointing N message decode slots at - * a single function, but that could break in subtle ways. - */ - -#define foreach_standard_reply_retval_handler \ -_(sw_interface_set_flags_reply) \ -_(sw_interface_add_del_address_reply) \ -_(sw_interface_set_rx_mode_reply) \ -_(sw_interface_set_rx_placement_reply) \ -_(sw_interface_set_table_reply) \ -_(sw_interface_set_mpls_enable_reply) \ -_(sw_interface_set_vpath_reply) \ -_(sw_interface_set_vxlan_bypass_reply) \ -_(sw_interface_set_vxlan_gpe_bypass_reply) \ -_(sw_interface_set_l2_bridge_reply) \ -_(sw_interface_set_bond_weight_reply) \ -_(bridge_domain_add_del_reply) \ -_(sw_interface_set_l2_xconnect_reply) \ -_(l2fib_add_del_reply) \ -_(l2fib_flush_int_reply) \ -_(l2fib_flush_bd_reply) \ -_(ip_route_add_del_reply) \ -_(ip_table_add_del_reply) \ -_(ip_table_replace_begin_reply) \ -_(ip_table_flush_reply) \ -_(ip_table_replace_end_reply) \ -_(ip_mroute_add_del_reply) \ -_(mpls_route_add_del_reply) \ -_(mpls_table_add_del_reply) \ -_(mpls_ip_bind_unbind_reply) \ -_(bier_route_add_del_reply) \ -_(bier_table_add_del_reply) \ -_(sw_interface_set_unnumbered_reply) \ -_(set_ip_flow_hash_reply) \ -_(sw_interface_ip6_enable_disable_reply) \ -_(l2_patch_add_del_reply) \ -_(sr_mpls_policy_add_reply) \ -_(sr_mpls_policy_mod_reply) \ -_(sr_mpls_policy_del_reply) \ -_(sr_policy_add_reply) \ -_(sr_policy_mod_reply) \ -_(sr_policy_del_reply) \ -_(sr_localsid_add_del_reply) \ -_(sr_steering_add_del_reply) \ -_(classify_add_del_session_reply) \ -_(classify_set_interface_ip_table_reply) \ -_(classify_set_interface_l2_tables_reply) \ -_(l2_fib_clear_table_reply) \ -_(l2_interface_efp_filter_reply) \ -_(l2_interface_vlan_tag_rewrite_reply) \ -_(modify_vhost_user_if_reply) \ -_(delete_vhost_user_if_reply) \ -_(want_l2_macs_events_reply) \ -_(input_acl_set_interface_reply) \ -_(ipsec_spd_add_del_reply) \ -_(ipsec_interface_add_del_spd_reply) \ -_(ipsec_spd_entry_add_del_reply) \ -_(ipsec_sad_entry_add_del_reply) \ -_(ipsec_tunnel_if_add_del_reply) \ -_(ipsec_tunnel_if_set_sa_reply) \ -_(delete_loopback_reply) \ -_(bd_ip_mac_add_del_reply) \ -_(bd_ip_mac_flush_reply) \ -_(want_interface_events_reply) \ -_(cop_interface_enable_disable_reply) \ -_(cop_whitelist_enable_disable_reply) \ -_(sw_interface_clear_stats_reply) \ -_(ioam_enable_reply) \ -_(ioam_disable_reply) \ -_(one_add_del_locator_reply) \ -_(one_add_del_local_eid_reply) \ -_(one_add_del_remote_mapping_reply) \ -_(one_add_del_adjacency_reply) \ -_(one_add_del_map_resolver_reply) \ -_(one_add_del_map_server_reply) \ -_(one_enable_disable_reply) \ -_(one_rloc_probe_enable_disable_reply) \ -_(one_map_register_enable_disable_reply) \ -_(one_map_register_set_ttl_reply) \ -_(one_set_transport_protocol_reply) \ -_(one_map_register_fallback_threshold_reply) \ -_(one_pitr_set_locator_set_reply) \ -_(one_map_request_mode_reply) \ -_(one_add_del_map_request_itr_rlocs_reply) \ -_(one_eid_table_add_del_map_reply) \ -_(one_use_petr_reply) \ -_(one_stats_enable_disable_reply) \ -_(one_add_del_l2_arp_entry_reply) \ -_(one_add_del_ndp_entry_reply) \ -_(one_stats_flush_reply) \ -_(one_enable_disable_xtr_mode_reply) \ -_(one_enable_disable_pitr_mode_reply) \ -_(one_enable_disable_petr_mode_reply) \ -_(gpe_enable_disable_reply) \ -_(gpe_set_encap_mode_reply) \ -_(gpe_add_del_iface_reply) \ -_(gpe_add_del_native_fwd_rpath_reply) \ -_(af_packet_delete_reply) \ -_(policer_classify_set_interface_reply) \ -_(set_ipfix_exporter_reply) \ -_(set_ipfix_classify_stream_reply) \ -_(ipfix_classify_table_add_del_reply) \ -_(flow_classify_set_interface_reply) \ -_(sw_interface_span_enable_disable_reply) \ -_(pg_capture_reply) \ -_(pg_enable_disable_reply) \ -_(pg_interface_enable_disable_coalesce_reply) \ -_(ip_source_and_port_range_check_add_del_reply) \ -_(ip_source_and_port_range_check_interface_add_del_reply)\ -_(delete_subif_reply) \ -_(l2_interface_pbb_tag_rewrite_reply) \ -_(set_punt_reply) \ -_(feature_enable_disable_reply) \ -_(feature_gso_enable_disable_reply) \ -_(sw_interface_tag_add_del_reply) \ -_(sw_interface_add_del_mac_address_reply) \ -_(hw_interface_set_mtu_reply) \ -_(p2p_ethernet_add_reply) \ -_(p2p_ethernet_del_reply) \ -_(tcp_configure_src_addresses_reply) \ -_(session_rule_add_del_reply) \ -_(ip_container_proxy_add_del_reply) \ -_(output_acl_set_interface_reply) \ -_(qos_record_enable_disable_reply) \ -_(flow_add_reply) - -#define _(n) \ - static void vl_api_##n##_t_handler \ - (vl_api_##n##_t * mp) \ - { \ - vat_main_t * vam = &vat_main; \ - i32 retval = ntohl(mp->retval); \ - if (vam->async_mode) { \ - vam->async_errors += (retval < 0); \ - } else { \ - vam->retval = retval; \ - vam->result_ready = 1; \ - } \ - } -foreach_standard_reply_retval_handler; -#undef _ - -#define _(n) \ - static void vl_api_##n##_t_handler_json \ - (vl_api_##n##_t * mp) \ - { \ - vat_main_t * vam = &vat_main; \ - vat_json_node_t node; \ - vat_json_init_object(&node); \ - vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \ - vat_json_print(vam->ofp, &node); \ - vam->retval = ntohl(mp->retval); \ - vam->result_ready = 1; \ - } -foreach_standard_reply_retval_handler; -#undef _ - -/* - * Table of message reply handlers, must include boilerplate handlers - * we just generated - */ - -#define foreach_vpe_api_reply_msg \ -_(CREATE_LOOPBACK_REPLY, create_loopback_reply) \ -_(CREATE_LOOPBACK_INSTANCE_REPLY, create_loopback_instance_reply) \ -_(SW_INTERFACE_DETAILS, sw_interface_details) \ -_(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \ -_(CONTROL_PING_REPLY, control_ping_reply) \ -_(CLI_REPLY, cli_reply) \ -_(CLI_INBAND_REPLY, cli_inband_reply) \ -_(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \ - sw_interface_add_del_address_reply) \ -_(SW_INTERFACE_SET_RX_MODE_REPLY, sw_interface_set_rx_mode_reply) \ -_(SW_INTERFACE_SET_RX_PLACEMENT_REPLY, sw_interface_set_rx_placement_reply) \ -_(SW_INTERFACE_RX_PLACEMENT_DETAILS, sw_interface_rx_placement_details) \ -_(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \ -_(SW_INTERFACE_SET_MPLS_ENABLE_REPLY, sw_interface_set_mpls_enable_reply) \ -_(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \ -_(SW_INTERFACE_SET_VXLAN_BYPASS_REPLY, sw_interface_set_vxlan_bypass_reply) \ -_(SW_INTERFACE_SET_VXLAN_GPE_BYPASS_REPLY, sw_interface_set_vxlan_gpe_bypass_reply) \ -_(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \ - sw_interface_set_l2_xconnect_reply) \ -_(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \ - sw_interface_set_l2_bridge_reply) \ -_(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \ -_(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \ -_(BRIDGE_DOMAIN_SET_MAC_AGE_REPLY, bridge_domain_set_mac_age_reply) \ -_(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \ -_(L2FIB_FLUSH_INT_REPLY, l2fib_flush_int_reply) \ -_(L2FIB_FLUSH_BD_REPLY, l2fib_flush_bd_reply) \ -_(L2_FLAGS_REPLY, l2_flags_reply) \ -_(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \ -_(TAP_CREATE_V2_REPLY, tap_create_v2_reply) \ -_(TAP_DELETE_V2_REPLY, tap_delete_v2_reply) \ -_(SW_INTERFACE_TAP_V2_DETAILS, sw_interface_tap_v2_details) \ -_(VIRTIO_PCI_CREATE_REPLY, virtio_pci_create_reply) \ -_(VIRTIO_PCI_CREATE_V2_REPLY, virtio_pci_create_v2_reply) \ -_(VIRTIO_PCI_DELETE_REPLY, virtio_pci_delete_reply) \ -_(SW_INTERFACE_VIRTIO_PCI_DETAILS, sw_interface_virtio_pci_details) \ -_(BOND_CREATE_REPLY, bond_create_reply) \ -_(BOND_CREATE2_REPLY, bond_create2_reply) \ -_(BOND_DELETE_REPLY, bond_delete_reply) \ -_(BOND_ADD_MEMBER_REPLY, bond_add_member_reply) \ -_(BOND_DETACH_MEMBER_REPLY, bond_detach_member_reply) \ -_(SW_INTERFACE_SET_BOND_WEIGHT_REPLY, sw_interface_set_bond_weight_reply) \ -_(SW_BOND_INTERFACE_DETAILS, sw_bond_interface_details) \ -_(SW_MEMBER_INTERFACE_DETAILS, sw_member_interface_details) \ -_(IP_ROUTE_ADD_DEL_REPLY, ip_route_add_del_reply) \ -_(IP_TABLE_ADD_DEL_REPLY, ip_table_add_del_reply) \ -_(IP_TABLE_REPLACE_BEGIN_REPLY, ip_table_replace_begin_reply) \ -_(IP_TABLE_FLUSH_REPLY, ip_table_flush_reply) \ -_(IP_TABLE_REPLACE_END_REPLY, ip_table_replace_end_reply) \ -_(IP_MROUTE_ADD_DEL_REPLY, ip_mroute_add_del_reply) \ -_(MPLS_TABLE_ADD_DEL_REPLY, mpls_table_add_del_reply) \ -_(MPLS_ROUTE_ADD_DEL_REPLY, mpls_route_add_del_reply) \ -_(MPLS_IP_BIND_UNBIND_REPLY, mpls_ip_bind_unbind_reply) \ -_(BIER_ROUTE_ADD_DEL_REPLY, bier_route_add_del_reply) \ -_(BIER_TABLE_ADD_DEL_REPLY, bier_table_add_del_reply) \ -_(MPLS_TUNNEL_ADD_DEL_REPLY, mpls_tunnel_add_del_reply) \ -_(SW_INTERFACE_SET_UNNUMBERED_REPLY, \ - sw_interface_set_unnumbered_reply) \ -_(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \ -_(CREATE_SUBIF_REPLY, create_subif_reply) \ -_(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \ -_(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \ - sw_interface_ip6_enable_disable_reply) \ -_(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \ -_(SR_MPLS_POLICY_ADD_REPLY, sr_mpls_policy_add_reply) \ -_(SR_MPLS_POLICY_MOD_REPLY, sr_mpls_policy_mod_reply) \ -_(SR_MPLS_POLICY_DEL_REPLY, sr_mpls_policy_del_reply) \ -_(SR_POLICY_ADD_REPLY, sr_policy_add_reply) \ -_(SR_POLICY_MOD_REPLY, sr_policy_mod_reply) \ -_(SR_POLICY_DEL_REPLY, sr_policy_del_reply) \ -_(SR_LOCALSID_ADD_DEL_REPLY, sr_localsid_add_del_reply) \ -_(SR_STEERING_ADD_DEL_REPLY, sr_steering_add_del_reply) \ -_(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \ -_(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \ -_(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \ -classify_set_interface_ip_table_reply) \ -_(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \ - classify_set_interface_l2_tables_reply) \ -_(GET_NODE_INDEX_REPLY, get_node_index_reply) \ -_(ADD_NODE_NEXT_REPLY, add_node_next_reply) \ -_(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \ -_(VXLAN_OFFLOAD_RX_REPLY, vxlan_offload_rx_reply) \ -_(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \ -_(GRE_TUNNEL_ADD_DEL_REPLY, gre_tunnel_add_del_reply) \ -_(GRE_TUNNEL_DETAILS, gre_tunnel_details) \ -_(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \ -_(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \ -_(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \ -_(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \ -_(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \ -_(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \ -_(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \ -_(SHOW_VERSION_REPLY, show_version_reply) \ -_(SHOW_THREADS_REPLY, show_threads_reply) \ -_(L2_FIB_TABLE_DETAILS, l2_fib_table_details) \ -_(VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, vxlan_gpe_add_del_tunnel_reply) \ -_(VXLAN_GPE_TUNNEL_DETAILS, vxlan_gpe_tunnel_details) \ -_(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \ -_(WANT_L2_MACS_EVENTS_REPLY, want_l2_macs_events_reply) \ -_(L2_MACS_EVENT, l2_macs_event) \ -_(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \ -_(IP_ADDRESS_DETAILS, ip_address_details) \ -_(IP_DETAILS, ip_details) \ -_(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \ -_(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \ -_(IPSEC_SPD_ENTRY_ADD_DEL_REPLY, ipsec_spd_entry_add_del_reply) \ -_(IPSEC_SAD_ENTRY_ADD_DEL_REPLY, ipsec_sad_entry_add_del_reply) \ -_(IPSEC_SA_DETAILS, ipsec_sa_details) \ -_(IPSEC_TUNNEL_IF_ADD_DEL_REPLY, ipsec_tunnel_if_add_del_reply) \ -_(IPSEC_TUNNEL_IF_SET_SA_REPLY, ipsec_tunnel_if_set_sa_reply) \ -_(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \ -_(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \ -_(BD_IP_MAC_FLUSH_REPLY, bd_ip_mac_flush_reply) \ -_(BD_IP_MAC_DETAILS, bd_ip_mac_details) \ -_(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \ -_(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \ -_(COP_INTERFACE_ENABLE_DISABLE_REPLY, cop_interface_enable_disable_reply) \ -_(COP_WHITELIST_ENABLE_DISABLE_REPLY, cop_whitelist_enable_disable_reply) \ -_(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \ -_(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \ -_(IOAM_ENABLE_REPLY, ioam_enable_reply) \ -_(IOAM_DISABLE_REPLY, ioam_disable_reply) \ -_(ONE_ADD_DEL_LOCATOR_SET_REPLY, one_add_del_locator_set_reply) \ -_(ONE_ADD_DEL_LOCATOR_REPLY, one_add_del_locator_reply) \ -_(ONE_ADD_DEL_LOCAL_EID_REPLY, one_add_del_local_eid_reply) \ -_(ONE_ADD_DEL_REMOTE_MAPPING_REPLY, one_add_del_remote_mapping_reply) \ -_(ONE_ADD_DEL_ADJACENCY_REPLY, one_add_del_adjacency_reply) \ -_(ONE_ADD_DEL_MAP_RESOLVER_REPLY, one_add_del_map_resolver_reply) \ -_(ONE_ADD_DEL_MAP_SERVER_REPLY, one_add_del_map_server_reply) \ -_(ONE_ENABLE_DISABLE_REPLY, one_enable_disable_reply) \ -_(ONE_MAP_REGISTER_ENABLE_DISABLE_REPLY, \ - one_map_register_enable_disable_reply) \ -_(ONE_MAP_REGISTER_SET_TTL_REPLY, one_map_register_set_ttl_reply) \ -_(ONE_SET_TRANSPORT_PROTOCOL_REPLY, one_set_transport_protocol_reply) \ -_(ONE_GET_TRANSPORT_PROTOCOL_REPLY, one_get_transport_protocol_reply) \ -_(ONE_MAP_REGISTER_FALLBACK_THRESHOLD_REPLY, \ - one_map_register_fallback_threshold_reply) \ -_(ONE_RLOC_PROBE_ENABLE_DISABLE_REPLY, \ - one_rloc_probe_enable_disable_reply) \ -_(ONE_PITR_SET_LOCATOR_SET_REPLY, one_pitr_set_locator_set_reply) \ -_(ONE_USE_PETR_REPLY, one_use_petr_reply) \ -_(ONE_MAP_REQUEST_MODE_REPLY, one_map_request_mode_reply) \ -_(ONE_EID_TABLE_ADD_DEL_MAP_REPLY, one_eid_table_add_del_map_reply) \ -_(ONE_LOCATOR_SET_DETAILS, one_locator_set_details) \ -_(ONE_LOCATOR_DETAILS, one_locator_details) \ -_(ONE_EID_TABLE_DETAILS, one_eid_table_details) \ -_(ONE_EID_TABLE_MAP_DETAILS, one_eid_table_map_details) \ -_(ONE_EID_TABLE_VNI_DETAILS, one_eid_table_vni_details) \ -_(ONE_MAP_RESOLVER_DETAILS, one_map_resolver_details) \ -_(ONE_MAP_SERVER_DETAILS, one_map_server_details) \ -_(ONE_ADJACENCIES_GET_REPLY, one_adjacencies_get_reply) \ -_(ONE_STATS_DETAILS, one_stats_details) \ -_(ONE_STATS_FLUSH_REPLY, one_stats_flush_reply) \ -_(ONE_STATS_ENABLE_DISABLE_REPLY, one_stats_enable_disable_reply) \ -_(SHOW_ONE_STATS_ENABLE_DISABLE_REPLY, \ - show_one_stats_enable_disable_reply) \ -_(ONE_ADD_DEL_NDP_ENTRY_REPLY, one_add_del_ndp_entry_reply) \ -_(ONE_NDP_BD_GET_REPLY, one_ndp_bd_get_reply) \ -_(ONE_NDP_ENTRIES_GET_REPLY, one_ndp_entries_get_reply) \ -_(ONE_ADD_DEL_L2_ARP_ENTRY_REPLY, one_add_del_l2_arp_entry_reply) \ -_(ONE_L2_ARP_BD_GET_REPLY, one_l2_arp_bd_get_reply) \ -_(ONE_L2_ARP_ENTRIES_GET_REPLY, one_l2_arp_entries_get_reply) \ -_(ONE_ENABLE_DISABLE_XTR_MODE_REPLY, one_enable_disable_xtr_mode_reply) \ -_(ONE_ENABLE_DISABLE_PITR_MODE_REPLY, \ - one_enable_disable_pitr_mode_reply) \ -_(ONE_ENABLE_DISABLE_PETR_MODE_REPLY, \ - one_enable_disable_petr_mode_reply) \ -_(ONE_SHOW_XTR_MODE_REPLY, one_show_xtr_mode_reply) \ -_(ONE_SHOW_PITR_MODE_REPLY, one_show_pitr_mode_reply) \ -_(ONE_SHOW_PETR_MODE_REPLY, one_show_petr_mode_reply) \ -_(GPE_SET_ENCAP_MODE_REPLY, gpe_set_encap_mode_reply) \ -_(GPE_GET_ENCAP_MODE_REPLY, gpe_get_encap_mode_reply) \ -_(GPE_ADD_DEL_IFACE_REPLY, gpe_add_del_iface_reply) \ -_(GPE_ENABLE_DISABLE_REPLY, gpe_enable_disable_reply) \ -_(GPE_ADD_DEL_FWD_ENTRY_REPLY, gpe_add_del_fwd_entry_reply) \ -_(GPE_FWD_ENTRY_VNIS_GET_REPLY, gpe_fwd_entry_vnis_get_reply) \ -_(GPE_FWD_ENTRIES_GET_REPLY, gpe_fwd_entries_get_reply) \ -_(GPE_NATIVE_FWD_RPATHS_GET_REPLY, gpe_native_fwd_rpaths_get_reply) \ -_(GPE_ADD_DEL_NATIVE_FWD_RPATH_REPLY, \ - gpe_add_del_native_fwd_rpath_reply) \ -_(GPE_FWD_ENTRY_PATH_DETAILS, \ - gpe_fwd_entry_path_details) \ -_(SHOW_ONE_STATUS_REPLY, show_one_status_reply) \ -_(ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY, \ - one_add_del_map_request_itr_rlocs_reply) \ -_(ONE_GET_MAP_REQUEST_ITR_RLOCS_REPLY, \ - one_get_map_request_itr_rlocs_reply) \ -_(SHOW_ONE_NSH_MAPPING_REPLY, show_one_nsh_mapping_reply) \ -_(SHOW_ONE_PITR_REPLY, show_one_pitr_reply) \ -_(SHOW_ONE_USE_PETR_REPLY, show_one_use_petr_reply) \ -_(SHOW_ONE_MAP_REQUEST_MODE_REPLY, show_one_map_request_mode_reply) \ -_(SHOW_ONE_RLOC_PROBE_STATE_REPLY, show_one_rloc_probe_state_reply) \ -_(SHOW_ONE_MAP_REGISTER_STATE_REPLY, \ - show_one_map_register_state_reply) \ -_(SHOW_ONE_MAP_REGISTER_TTL_REPLY, show_one_map_register_ttl_reply) \ -_(SHOW_ONE_MAP_REGISTER_FALLBACK_THRESHOLD_REPLY, \ - show_one_map_register_fallback_threshold_reply) \ -_(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \ -_(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \ -_(AF_PACKET_DETAILS, af_packet_details) \ -_(POLICER_ADD_DEL_REPLY, policer_add_del_reply) \ -_(POLICER_DETAILS, policer_details) \ -_(POLICER_CLASSIFY_SET_INTERFACE_REPLY, policer_classify_set_interface_reply) \ -_(POLICER_CLASSIFY_DETAILS, policer_classify_details) \ -_(MPLS_TUNNEL_DETAILS, mpls_tunnel_details) \ -_(MPLS_TABLE_DETAILS, mpls_table_details) \ -_(MPLS_ROUTE_DETAILS, mpls_route_details) \ -_(CLASSIFY_TABLE_IDS_REPLY, classify_table_ids_reply) \ -_(CLASSIFY_TABLE_BY_INTERFACE_REPLY, classify_table_by_interface_reply) \ -_(CLASSIFY_TABLE_INFO_REPLY, classify_table_info_reply) \ -_(CLASSIFY_SESSION_DETAILS, classify_session_details) \ -_(SET_IPFIX_EXPORTER_REPLY, set_ipfix_exporter_reply) \ -_(IPFIX_EXPORTER_DETAILS, ipfix_exporter_details) \ -_(SET_IPFIX_CLASSIFY_STREAM_REPLY, set_ipfix_classify_stream_reply) \ -_(IPFIX_CLASSIFY_STREAM_DETAILS, ipfix_classify_stream_details) \ -_(IPFIX_CLASSIFY_TABLE_ADD_DEL_REPLY, ipfix_classify_table_add_del_reply) \ -_(IPFIX_CLASSIFY_TABLE_DETAILS, ipfix_classify_table_details) \ -_(FLOW_CLASSIFY_SET_INTERFACE_REPLY, flow_classify_set_interface_reply) \ -_(FLOW_CLASSIFY_DETAILS, flow_classify_details) \ -_(SW_INTERFACE_SPAN_ENABLE_DISABLE_REPLY, sw_interface_span_enable_disable_reply) \ -_(SW_INTERFACE_SPAN_DETAILS, sw_interface_span_details) \ -_(GET_NEXT_INDEX_REPLY, get_next_index_reply) \ -_(PG_CREATE_INTERFACE_REPLY, pg_create_interface_reply) \ -_(PG_CAPTURE_REPLY, pg_capture_reply) \ -_(PG_ENABLE_DISABLE_REPLY, pg_enable_disable_reply) \ -_(PG_INTERFACE_ENABLE_DISABLE_COALESCE_REPLY, pg_interface_enable_disable_coalesce_reply) \ -_(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY, \ - ip_source_and_port_range_check_add_del_reply) \ -_(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY, \ - ip_source_and_port_range_check_interface_add_del_reply) \ -_(DELETE_SUBIF_REPLY, delete_subif_reply) \ -_(L2_INTERFACE_PBB_TAG_REWRITE_REPLY, l2_interface_pbb_tag_rewrite_reply) \ -_(SET_PUNT_REPLY, set_punt_reply) \ -_(IP_TABLE_DETAILS, ip_table_details) \ -_(IP_ROUTE_DETAILS, ip_route_details) \ -_(FEATURE_ENABLE_DISABLE_REPLY, feature_enable_disable_reply) \ -_(FEATURE_GSO_ENABLE_DISABLE_REPLY, feature_gso_enable_disable_reply) \ -_(SW_INTERFACE_TAG_ADD_DEL_REPLY, sw_interface_tag_add_del_reply) \ -_(SW_INTERFACE_ADD_DEL_MAC_ADDRESS_REPLY, sw_interface_add_del_mac_address_reply) \ -_(L2_XCONNECT_DETAILS, l2_xconnect_details) \ -_(HW_INTERFACE_SET_MTU_REPLY, hw_interface_set_mtu_reply) \ -_(SW_INTERFACE_GET_TABLE_REPLY, sw_interface_get_table_reply) \ -_(P2P_ETHERNET_ADD_REPLY, p2p_ethernet_add_reply) \ -_(P2P_ETHERNET_DEL_REPLY, p2p_ethernet_del_reply) \ -_(TCP_CONFIGURE_SRC_ADDRESSES_REPLY, tcp_configure_src_addresses_reply) \ -_(APP_NAMESPACE_ADD_DEL_REPLY, app_namespace_add_del_reply) \ -_(SESSION_RULE_ADD_DEL_REPLY, session_rule_add_del_reply) \ -_(SESSION_RULES_DETAILS, session_rules_details) \ -_(IP_CONTAINER_PROXY_ADD_DEL_REPLY, ip_container_proxy_add_del_reply) \ -_(OUTPUT_ACL_SET_INTERFACE_REPLY, output_acl_set_interface_reply) \ -_(QOS_RECORD_ENABLE_DISABLE_REPLY, qos_record_enable_disable_reply) \ -_(FLOW_ADD_REPLY, flow_add_reply) \ - -#define foreach_standalone_reply_msg \ -_(SW_INTERFACE_EVENT, sw_interface_event) - -typedef struct -{ - u8 *name; - u32 value; -} name_sort_t; - -#define STR_VTR_OP_CASE(op) \ - case L2_VTR_ ## op: \ - return "" # op; - -static const char * -str_vtr_op (u32 vtr_op) -{ - switch (vtr_op) - { - STR_VTR_OP_CASE (DISABLED); - STR_VTR_OP_CASE (PUSH_1); - STR_VTR_OP_CASE (PUSH_2); - STR_VTR_OP_CASE (POP_1); - STR_VTR_OP_CASE (POP_2); - STR_VTR_OP_CASE (TRANSLATE_1_1); - STR_VTR_OP_CASE (TRANSLATE_1_2); - STR_VTR_OP_CASE (TRANSLATE_2_1); - STR_VTR_OP_CASE (TRANSLATE_2_2); - } - - return "UNKNOWN"; -} - -static int -dump_sub_interface_table (vat_main_t * vam) -{ - const sw_interface_subif_t *sub = NULL; - - if (vam->json_output) - { - clib_warning - ("JSON output supported only for VPE API calls and dump_stats_table"); - return -99; - } - - print (vam->ofp, - "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s", - "Interface", "sw_if_index", - "sub id", "dot1ad", "tags", "outer id", - "inner id", "exact", "default", "outer any", "inner any"); - - vec_foreach (sub, vam->sw_if_subif_table) - { - print (vam->ofp, - "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d", - sub->interface_name, - sub->sw_if_index, - sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q", - sub->sub_number_of_tags, sub->sub_outer_vlan_id, - sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default, - sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any); - if (sub->vtr_op != L2_VTR_DISABLED) - { - print (vam->ofp, - " vlan-tag-rewrite - op: %-14s [ dot1q: %d " - "tag1: %d tag2: %d ]", - str_vtr_op (sub->vtr_op), sub->vtr_push_dot1q, - sub->vtr_tag1, sub->vtr_tag2); - } - } - - return 0; -} - -static int -name_sort_cmp (void *a1, void *a2) -{ - name_sort_t *n1 = a1; - name_sort_t *n2 = a2; - - return strcmp ((char *) n1->name, (char *) n2->name); -} - -static int -dump_interface_table (vat_main_t * vam) -{ - hash_pair_t *p; - name_sort_t *nses = 0, *ns; - - if (vam->json_output) - { - clib_warning - ("JSON output supported only for VPE API calls and dump_stats_table"); - return -99; - } - - /* *INDENT-OFF* */ - hash_foreach_pair (p, vam->sw_if_index_by_interface_name, - ({ - vec_add2 (nses, ns, 1); - ns->name = (u8 *)(p->key); - ns->value = (u32) p->value[0]; - })); - /* *INDENT-ON* */ - - vec_sort_with_function (nses, name_sort_cmp); - - print (vam->ofp, "%-25s%-15s", "Interface", "sw_if_index"); - vec_foreach (ns, nses) - { - print (vam->ofp, "%-25s%-15d", ns->name, ns->value); - } - vec_free (nses); - return 0; -} - -static int -dump_ip_table (vat_main_t * vam, int is_ipv6) -{ - const ip_details_t *det = NULL; - const ip_address_details_t *address = NULL; - u32 i = ~0; - - print (vam->ofp, "%-12s", "sw_if_index"); - - vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6]) - { - i++; - if (!det->present) - { - continue; - } - print (vam->ofp, "%-12d", i); - print (vam->ofp, " %-30s%-13s", "Address", "Prefix length"); - if (!det->addr) - { - continue; - } - vec_foreach (address, det->addr) - { - print (vam->ofp, - " %-30U%-13d", - is_ipv6 ? format_ip6_address : format_ip4_address, - address->ip, address->prefix_length); - } - } - - return 0; -} - -static int -dump_ipv4_table (vat_main_t * vam) -{ - if (vam->json_output) - { - clib_warning - ("JSON output supported only for VPE API calls and dump_stats_table"); - return -99; - } - - return dump_ip_table (vam, 0); -} - -static int -dump_ipv6_table (vat_main_t * vam) -{ - if (vam->json_output) - { - clib_warning - ("JSON output supported only for VPE API calls and dump_stats_table"); - return -99; - } - - return dump_ip_table (vam, 1); -} - -/* - * Pass CLI buffers directly in the CLI_INBAND API message, - * instead of an additional shared memory area. - */ -static int -exec_inband (vat_main_t * vam) -{ - vl_api_cli_inband_t *mp; - unformat_input_t *i = vam->input; - int ret; - - if (vec_len (i->buffer) == 0) - return -1; - - if (vam->exec_mode == 0 && unformat (i, "mode")) - { - vam->exec_mode = 1; - return 0; - } - if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit"))) - { - vam->exec_mode = 0; - return 0; - } - - /* - * In order for the CLI command to work, it - * must be a vector ending in \n, not a C-string ending - * in \n\0. - */ - M2 (CLI_INBAND, mp, vec_len (vam->input->buffer)); - vl_api_vec_to_api_string (vam->input->buffer, &mp->cmd); - - S (mp); - W (ret); - /* json responses may or may not include a useful reply... */ - if (vec_len (vam->cmd_reply)) - print (vam->ofp, "%v", (char *) (vam->cmd_reply)); - return ret; -} - -int -exec (vat_main_t * vam) -{ - return exec_inband (vam); -} - -static int -api_create_loopback (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_create_loopback_t *mp; - vl_api_create_loopback_instance_t *mp_lbi; - u8 mac_address[6]; - u8 mac_set = 0; - u8 is_specified = 0; - u32 user_instance = 0; - int ret; - - clib_memset (mac_address, 0, sizeof (mac_address)); - - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) - mac_set = 1; - if (unformat (i, "instance %d", &user_instance)) - is_specified = 1; - else - break; - } - - if (is_specified) - { - M (CREATE_LOOPBACK_INSTANCE, mp_lbi); - mp_lbi->is_specified = is_specified; - if (is_specified) - mp_lbi->user_instance = htonl (user_instance); - if (mac_set) - clib_memcpy (mp_lbi->mac_address, mac_address, sizeof (mac_address)); - S (mp_lbi); - } - else - { - /* Construct the API message */ - M (CREATE_LOOPBACK, mp); - if (mac_set) - clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address)); - S (mp); - } - - W (ret); - return ret; -} - -static int -api_delete_loopback (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_delete_loopback_t *mp; - u32 sw_if_index = ~0; - int ret; - - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "sw_if_index %d", &sw_if_index)) - ; - else - break; - } - - if (sw_if_index == ~0) - { - errmsg ("missing sw_if_index"); - return -99; - } - - /* Construct the API message */ - M (DELETE_LOOPBACK, mp); - mp->sw_if_index = ntohl (sw_if_index); - - S (mp); - W (ret); - return ret; -} - -static int -api_want_interface_events (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_want_interface_events_t *mp; - int enable = -1; - int ret; - - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "enable")) - enable = 1; - else if (unformat (i, "disable")) - enable = 0; - else - break; - } - - if (enable == -1) - { - errmsg ("missing enable|disable"); - return -99; - } - - M (WANT_INTERFACE_EVENTS, mp); - mp->enable_disable = enable; - - vam->interface_event_display = enable; - - S (mp); - W (ret); - return ret; -} - - -/* Note: non-static, called once to set up the initial intfc table */ -int -api_sw_interface_dump (vat_main_t * vam) -{ - vl_api_sw_interface_dump_t *mp; - vl_api_control_ping_t *mp_ping; - hash_pair_t *p; - name_sort_t *nses = 0, *ns; - sw_interface_subif_t *sub = NULL; - int ret; - - /* Toss the old name table */ - /* *INDENT-OFF* */ - hash_foreach_pair (p, vam->sw_if_index_by_interface_name, - ({ - vec_add2 (nses, ns, 1); - ns->name = (u8 *)(p->key); - ns->value = (u32) p->value[0]; - })); - /* *INDENT-ON* */ - - hash_free (vam->sw_if_index_by_interface_name); - - vec_foreach (ns, nses) vec_free (ns->name); - - vec_free (nses); - - vec_foreach (sub, vam->sw_if_subif_table) - { - vec_free (sub->interface_name); - } - vec_free (vam->sw_if_subif_table); - - /* recreate the interface name hash table */ - vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword)); - - /* - * Ask for all interface names. Otherwise, the epic catalog of - * name filters becomes ridiculously long, and vat ends up needing - * to be taught about new interface types. - */ - M (SW_INTERFACE_DUMP, mp); - S (mp); - - /* Use a control ping for synchronization */ - MPING (CONTROL_PING, mp_ping); - S (mp_ping); - - W (ret); - return ret; -} - -static int -api_sw_interface_set_flags (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_sw_interface_set_flags_t *mp; - u32 sw_if_index; - u8 sw_if_index_set = 0; - u8 admin_up = 0; - int ret; - - /* Parse args required to build the message */ - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "admin-up")) - admin_up = 1; - else if (unformat (i, "admin-down")) - admin_up = 0; - else - if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) - sw_if_index_set = 1; - else if (unformat (i, "sw_if_index %d", &sw_if_index)) - sw_if_index_set = 1; - else - break; - } - - if (sw_if_index_set == 0) - { - errmsg ("missing interface name or sw_if_index"); - return -99; - } - - /* Construct the API message */ - M (SW_INTERFACE_SET_FLAGS, mp); - mp->sw_if_index = ntohl (sw_if_index); - mp->flags = ntohl ((admin_up) ? IF_STATUS_API_FLAG_ADMIN_UP : 0); - - /* send it... */ - S (mp); - - /* Wait for a reply, return the good/bad news... */ - W (ret); - return ret; -} - -static int -api_sw_interface_set_rx_mode (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_sw_interface_set_rx_mode_t *mp; - u32 sw_if_index; - u8 sw_if_index_set = 0; - int ret; - u8 queue_id_valid = 0; - u32 queue_id; - vnet_hw_interface_rx_mode mode = VNET_HW_INTERFACE_RX_MODE_UNKNOWN; - - /* Parse args required to build the message */ - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "queue %d", &queue_id)) - queue_id_valid = 1; - else if (unformat (i, "polling")) - mode = VNET_HW_INTERFACE_RX_MODE_POLLING; - else if (unformat (i, "interrupt")) - mode = VNET_HW_INTERFACE_RX_MODE_INTERRUPT; - else if (unformat (i, "adaptive")) - mode = VNET_HW_INTERFACE_RX_MODE_ADAPTIVE; - else - if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) - sw_if_index_set = 1; - else if (unformat (i, "sw_if_index %d", &sw_if_index)) - sw_if_index_set = 1; - else - break; - } - - if (sw_if_index_set == 0) - { - errmsg ("missing interface name or sw_if_index"); - return -99; - } - if (mode == VNET_HW_INTERFACE_RX_MODE_UNKNOWN) - { - errmsg ("missing rx-mode"); - return -99; - } - - /* Construct the API message */ - M (SW_INTERFACE_SET_RX_MODE, mp); - mp->sw_if_index = ntohl (sw_if_index); - mp->mode = (vl_api_rx_mode_t) mode; - mp->queue_id_valid = queue_id_valid; - mp->queue_id = queue_id_valid ? ntohl (queue_id) : ~0; - - /* send it... */ - S (mp); - - /* Wait for a reply, return the good/bad news... */ - W (ret); - return ret; -} - -static int -api_sw_interface_set_rx_placement (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_sw_interface_set_rx_placement_t *mp; - u32 sw_if_index; - u8 sw_if_index_set = 0; - int ret; - u8 is_main = 0; - u32 queue_id, thread_index; - - /* Parse args required to build the message */ - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "queue %d", &queue_id)) - ; - else if (unformat (i, "main")) - is_main = 1; - else if (unformat (i, "worker %d", &thread_index)) - ; - else - if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) - sw_if_index_set = 1; - else if (unformat (i, "sw_if_index %d", &sw_if_index)) - sw_if_index_set = 1; - else - break; - } - - if (sw_if_index_set == 0) - { - errmsg ("missing interface name or sw_if_index"); - return -99; - } - - if (is_main) - thread_index = 0; - /* Construct the API message */ - M (SW_INTERFACE_SET_RX_PLACEMENT, mp); - mp->sw_if_index = ntohl (sw_if_index); - mp->worker_id = ntohl (thread_index); - mp->queue_id = ntohl (queue_id); - mp->is_main = is_main; - - /* send it... */ - S (mp); - /* Wait for a reply, return the good/bad news... */ - W (ret); - return ret; -} - -static void vl_api_sw_interface_rx_placement_details_t_handler - (vl_api_sw_interface_rx_placement_details_t * mp) -{ - vat_main_t *vam = &vat_main; - u32 worker_id = ntohl (mp->worker_id); - - print (vam->ofp, - "\n%-11d %-11s %-6d %-5d %-9s", - ntohl (mp->sw_if_index), (worker_id == 0) ? "main" : "worker", - worker_id, ntohl (mp->queue_id), - (mp->mode == - 1) ? "polling" : ((mp->mode == 2) ? "interrupt" : "adaptive")); -} - -static void vl_api_sw_interface_rx_placement_details_t_handler_json - (vl_api_sw_interface_rx_placement_details_t * mp) -{ - vat_main_t *vam = &vat_main; - vat_json_node_t *node = NULL; - - if (VAT_JSON_ARRAY != vam->json_tree.type) - { - ASSERT (VAT_JSON_NONE == vam->json_tree.type); - vat_json_init_array (&vam->json_tree); - } - node = vat_json_array_add (&vam->json_tree); - - vat_json_init_object (node); - vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index)); - vat_json_object_add_uint (node, "worker_id", ntohl (mp->worker_id)); - vat_json_object_add_uint (node, "queue_id", ntohl (mp->queue_id)); - vat_json_object_add_uint (node, "mode", mp->mode); -} - -static int -api_sw_interface_rx_placement_dump (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_sw_interface_rx_placement_dump_t *mp; - vl_api_control_ping_t *mp_ping; - int ret; - u32 sw_if_index; - u8 sw_if_index_set = 0; - - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) - sw_if_index_set++; - else if (unformat (i, "sw_if_index %d", &sw_if_index)) - sw_if_index_set++; - else - break; - } - - print (vam->ofp, - "\n%-11s %-11s %-6s %-5s %-4s", - "sw_if_index", "main/worker", "thread", "queue", "mode"); - - /* Dump Interface rx placement */ - M (SW_INTERFACE_RX_PLACEMENT_DUMP, mp); - - if (sw_if_index_set) - mp->sw_if_index = htonl (sw_if_index); - else - mp->sw_if_index = ~0; - - S (mp); - - /* Use a control ping for synchronization */ - MPING (CONTROL_PING, mp_ping); - S (mp_ping); - - W (ret); - return ret; -} - -static int -api_sw_interface_clear_stats (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_sw_interface_clear_stats_t *mp; - u32 sw_if_index; - u8 sw_if_index_set = 0; - int ret; - - /* Parse args required to build the message */ - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) - sw_if_index_set = 1; - else if (unformat (i, "sw_if_index %d", &sw_if_index)) - sw_if_index_set = 1; - else - break; - } - - /* Construct the API message */ - M (SW_INTERFACE_CLEAR_STATS, mp); - - if (sw_if_index_set == 1) - mp->sw_if_index = ntohl (sw_if_index); - else - mp->sw_if_index = ~0; - - /* send it... */ - S (mp); - - /* Wait for a reply, return the good/bad news... */ - W (ret); - return ret; -} - -static int -api_sw_interface_add_del_address (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_sw_interface_add_del_address_t *mp; - u32 sw_if_index; - u8 sw_if_index_set = 0; - u8 is_add = 1, del_all = 0; - u32 address_length = 0; - u8 v4_address_set = 0; - u8 v6_address_set = 0; - ip4_address_t v4address; - ip6_address_t v6address; - int ret; - - /* Parse args required to build the message */ - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "del-all")) - del_all = 1; - else if (unformat (i, "del")) - is_add = 0; - else - if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) - sw_if_index_set = 1; - else if (unformat (i, "sw_if_index %d", &sw_if_index)) - sw_if_index_set = 1; - else if (unformat (i, "%U/%d", - unformat_ip4_address, &v4address, &address_length)) - v4_address_set = 1; - else if (unformat (i, "%U/%d", - unformat_ip6_address, &v6address, &address_length)) - v6_address_set = 1; - else - break; - } - - if (sw_if_index_set == 0) - { - errmsg ("missing interface name or sw_if_index"); - return -99; - } - if (v4_address_set && v6_address_set) - { - errmsg ("both v4 and v6 addresses set"); - return -99; - } - if (!v4_address_set && !v6_address_set && !del_all) - { - errmsg ("no addresses set"); - return -99; - } - - /* Construct the API message */ - M (SW_INTERFACE_ADD_DEL_ADDRESS, mp); - - mp->sw_if_index = ntohl (sw_if_index); - mp->is_add = is_add; - mp->del_all = del_all; - if (v6_address_set) - { - mp->prefix.address.af = ADDRESS_IP6; - clib_memcpy (mp->prefix.address.un.ip6, &v6address, sizeof (v6address)); - } - else - { - mp->prefix.address.af = ADDRESS_IP4; - clib_memcpy (mp->prefix.address.un.ip4, &v4address, sizeof (v4address)); - } - mp->prefix.len = address_length; - - /* send it... */ - S (mp); - - /* Wait for a reply, return good/bad news */ - W (ret); - return ret; -} - -static int -api_sw_interface_set_mpls_enable (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_sw_interface_set_mpls_enable_t *mp; - u32 sw_if_index; - u8 sw_if_index_set = 0; - u8 enable = 1; - int ret; - - /* Parse args required to build the message */ - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) - sw_if_index_set = 1; - else if (unformat (i, "sw_if_index %d", &sw_if_index)) - sw_if_index_set = 1; - else if (unformat (i, "disable")) - enable = 0; - else if (unformat (i, "dis")) - enable = 0; - else - break; - } - - if (sw_if_index_set == 0) - { - errmsg ("missing interface name or sw_if_index"); - return -99; - } - - /* Construct the API message */ - M (SW_INTERFACE_SET_MPLS_ENABLE, mp); - - mp->sw_if_index = ntohl (sw_if_index); - mp->enable = enable; - - /* send it... */ - S (mp); - - /* Wait for a reply... */ - W (ret); - return ret; -} - -static int -api_sw_interface_set_table (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_sw_interface_set_table_t *mp; - u32 sw_if_index, vrf_id = 0; - u8 sw_if_index_set = 0; - u8 is_ipv6 = 0; - int ret; - - /* Parse args required to build the message */ - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) - sw_if_index_set = 1; - else if (unformat (i, "sw_if_index %d", &sw_if_index)) - sw_if_index_set = 1; - else if (unformat (i, "vrf %d", &vrf_id)) - ; - else if (unformat (i, "ipv6")) - is_ipv6 = 1; - else - break; - } - - if (sw_if_index_set == 0) - { - errmsg ("missing interface name or sw_if_index"); - return -99; - } - - /* Construct the API message */ - M (SW_INTERFACE_SET_TABLE, mp); - - mp->sw_if_index = ntohl (sw_if_index); - mp->is_ipv6 = is_ipv6; - mp->vrf_id = ntohl (vrf_id); - - /* send it... */ - S (mp); - - /* Wait for a reply... */ - W (ret); - return ret; -} - -static void vl_api_sw_interface_get_table_reply_t_handler - (vl_api_sw_interface_get_table_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - - print (vam->ofp, "%d", ntohl (mp->vrf_id)); - - vam->retval = ntohl (mp->retval); - vam->result_ready = 1; - -} - -static void vl_api_sw_interface_get_table_reply_t_handler_json - (vl_api_sw_interface_get_table_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - vat_json_node_t node; - - vat_json_init_object (&node); - vat_json_object_add_int (&node, "retval", ntohl (mp->retval)); - vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id)); - - vat_json_print (vam->ofp, &node); - vat_json_free (&node); - - vam->retval = ntohl (mp->retval); - vam->result_ready = 1; -} - -static int -api_sw_interface_get_table (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_sw_interface_get_table_t *mp; - u32 sw_if_index; - u8 sw_if_index_set = 0; - u8 is_ipv6 = 0; - int ret; - - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) - sw_if_index_set = 1; - else if (unformat (i, "sw_if_index %d", &sw_if_index)) - sw_if_index_set = 1; - else if (unformat (i, "ipv6")) - is_ipv6 = 1; - else - break; - } - - if (sw_if_index_set == 0) - { - errmsg ("missing interface name or sw_if_index"); - return -99; - } - - M (SW_INTERFACE_GET_TABLE, mp); - mp->sw_if_index = htonl (sw_if_index); - mp->is_ipv6 = is_ipv6; - - S (mp); - W (ret); - return ret; -} - -static int -api_sw_interface_set_vpath (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_sw_interface_set_vpath_t *mp; - u32 sw_if_index = 0; - u8 sw_if_index_set = 0; - u8 is_enable = 0; - int ret; - - /* Parse args required to build the message */ - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) - sw_if_index_set = 1; - else if (unformat (i, "sw_if_index %d", &sw_if_index)) - sw_if_index_set = 1; - else if (unformat (i, "enable")) - is_enable = 1; - else if (unformat (i, "disable")) - is_enable = 0; - else - break; - } - - if (sw_if_index_set == 0) - { - errmsg ("missing interface name or sw_if_index"); - return -99; - } - - /* Construct the API message */ - M (SW_INTERFACE_SET_VPATH, mp); - - mp->sw_if_index = ntohl (sw_if_index); - mp->enable = is_enable; - - /* send it... */ - S (mp); - - /* Wait for a reply... */ - W (ret); - return ret; -} - -static int -api_sw_interface_set_vxlan_bypass (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_sw_interface_set_vxlan_bypass_t *mp; - u32 sw_if_index = 0; - u8 sw_if_index_set = 0; - u8 is_enable = 1; - u8 is_ipv6 = 0; - int ret; - - /* Parse args required to build the message */ - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) - sw_if_index_set = 1; - else if (unformat (i, "sw_if_index %d", &sw_if_index)) - sw_if_index_set = 1; - else if (unformat (i, "enable")) - is_enable = 1; - else if (unformat (i, "disable")) - is_enable = 0; - else if (unformat (i, "ip4")) - is_ipv6 = 0; - else if (unformat (i, "ip6")) - is_ipv6 = 1; - else - break; - } - - if (sw_if_index_set == 0) - { - errmsg ("missing interface name or sw_if_index"); - return -99; - } - - /* Construct the API message */ - M (SW_INTERFACE_SET_VXLAN_BYPASS, mp); - - mp->sw_if_index = ntohl (sw_if_index); - mp->enable = is_enable; - mp->is_ipv6 = is_ipv6; - - /* send it... */ - S (mp); - - /* Wait for a reply... */ - W (ret); - return ret; -} - -static int -api_sw_interface_set_l2_xconnect (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_sw_interface_set_l2_xconnect_t *mp; - u32 rx_sw_if_index; - u8 rx_sw_if_index_set = 0; - u32 tx_sw_if_index; - u8 tx_sw_if_index_set = 0; - u8 enable = 1; - int ret; - - /* Parse args required to build the message */ - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index)) - rx_sw_if_index_set = 1; - else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index)) - tx_sw_if_index_set = 1; - else if (unformat (i, "rx")) - { - if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "%U", api_unformat_sw_if_index, vam, - &rx_sw_if_index)) - rx_sw_if_index_set = 1; - } - else - break; - } - else if (unformat (i, "tx")) - { - if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "%U", api_unformat_sw_if_index, vam, - &tx_sw_if_index)) - tx_sw_if_index_set = 1; - } - else - break; - } - else if (unformat (i, "enable")) - enable = 1; - else if (unformat (i, "disable")) - enable = 0; - else - break; - } - - if (rx_sw_if_index_set == 0) - { - errmsg ("missing rx interface name or rx_sw_if_index"); - return -99; - } - - if (enable && (tx_sw_if_index_set == 0)) - { - errmsg ("missing tx interface name or tx_sw_if_index"); - return -99; - } - - M (SW_INTERFACE_SET_L2_XCONNECT, mp); - - mp->rx_sw_if_index = ntohl (rx_sw_if_index); - mp->tx_sw_if_index = ntohl (tx_sw_if_index); - mp->enable = enable; - - S (mp); - W (ret); - return ret; -} - -static int -api_sw_interface_set_l2_bridge (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_sw_interface_set_l2_bridge_t *mp; - vl_api_l2_port_type_t port_type; - u32 rx_sw_if_index; - u8 rx_sw_if_index_set = 0; - u32 bd_id; - u8 bd_id_set = 0; - u32 shg = 0; - u8 enable = 1; - int ret; - - port_type = L2_API_PORT_TYPE_NORMAL; - - /* Parse args required to build the message */ - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "sw_if_index %d", &rx_sw_if_index)) - rx_sw_if_index_set = 1; - else if (unformat (i, "bd_id %d", &bd_id)) - bd_id_set = 1; - else - if (unformat - (i, "%U", api_unformat_sw_if_index, vam, &rx_sw_if_index)) - rx_sw_if_index_set = 1; - else if (unformat (i, "shg %d", &shg)) - ; - else if (unformat (i, "bvi")) - port_type = L2_API_PORT_TYPE_BVI; - else if (unformat (i, "uu-fwd")) - port_type = L2_API_PORT_TYPE_UU_FWD; - else if (unformat (i, "enable")) - enable = 1; - else if (unformat (i, "disable")) - enable = 0; - else - break; - } - - if (rx_sw_if_index_set == 0) - { - errmsg ("missing rx interface name or sw_if_index"); - return -99; - } - - if (enable && (bd_id_set == 0)) - { - errmsg ("missing bridge domain"); - return -99; - } - - M (SW_INTERFACE_SET_L2_BRIDGE, mp); - - mp->rx_sw_if_index = ntohl (rx_sw_if_index); - mp->bd_id = ntohl (bd_id); - mp->shg = (u8) shg; - mp->port_type = ntohl (port_type); - mp->enable = enable; - - S (mp); - W (ret); - return ret; -} - -static int -api_bridge_domain_dump (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_bridge_domain_dump_t *mp; - vl_api_control_ping_t *mp_ping; - u32 bd_id = ~0; - int ret; - - /* Parse args required to build the message */ - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "bd_id %d", &bd_id)) - ; - else - break; - } - - M (BRIDGE_DOMAIN_DUMP, mp); - mp->bd_id = ntohl (bd_id); - S (mp); - - /* Use a control ping for synchronization */ - MPING (CONTROL_PING, mp_ping); - S (mp_ping); - - W (ret); - return ret; -} - -static int -api_bridge_domain_add_del (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_bridge_domain_add_del_t *mp; - u32 bd_id = ~0; - u8 is_add = 1; - u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0; - u8 *bd_tag = NULL; - u32 mac_age = 0; - int ret; - - /* Parse args required to build the message */ - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "bd_id %d", &bd_id)) - ; - else if (unformat (i, "flood %d", &flood)) - ; - else if (unformat (i, "uu-flood %d", &uu_flood)) - ; - else if (unformat (i, "forward %d", &forward)) - ; - else if (unformat (i, "learn %d", &learn)) - ; - else if (unformat (i, "arp-term %d", &arp_term)) - ; - else if (unformat (i, "mac-age %d", &mac_age)) - ; - else if (unformat (i, "bd-tag %s", &bd_tag)) - ; - else if (unformat (i, "del")) - { - is_add = 0; - flood = uu_flood = forward = learn = 0; - } - else - break; - } - - if (bd_id == ~0) - { - errmsg ("missing bridge domain"); - ret = -99; - goto done; - } - - if (mac_age > 255) - { - errmsg ("mac age must be less than 256 "); - ret = -99; - goto done; - } - - if ((bd_tag) && (vec_len (bd_tag) > 63)) - { - errmsg ("bd-tag cannot be longer than 63"); - ret = -99; - goto done; - } - - M (BRIDGE_DOMAIN_ADD_DEL, mp); - - mp->bd_id = ntohl (bd_id); - mp->flood = flood; - mp->uu_flood = uu_flood; - mp->forward = forward; - mp->learn = learn; - mp->arp_term = arp_term; - mp->is_add = is_add; - mp->mac_age = (u8) mac_age; - if (bd_tag) - { - clib_memcpy (mp->bd_tag, bd_tag, vec_len (bd_tag)); - mp->bd_tag[vec_len (bd_tag)] = 0; - } - S (mp); - W (ret); - -done: - vec_free (bd_tag); - return ret; -} - -static int -api_l2fib_flush_bd (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_l2fib_flush_bd_t *mp; - u32 bd_id = ~0; - int ret; - - /* Parse args required to build the message */ - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "bd_id %d", &bd_id)); - else - break; - } - - if (bd_id == ~0) - { - errmsg ("missing bridge domain"); - return -99; - } - - M (L2FIB_FLUSH_BD, mp); - - mp->bd_id = htonl (bd_id); - - S (mp); - W (ret); - return ret; -} - -static int -api_l2fib_flush_int (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_l2fib_flush_int_t *mp; - u32 sw_if_index = ~0; - int ret; - - /* Parse args required to build the message */ - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "sw_if_index %d", &sw_if_index)); - else - if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)); - else - break; - } - - if (sw_if_index == ~0) - { - errmsg ("missing interface name or sw_if_index"); - return -99; - } - - M (L2FIB_FLUSH_INT, mp); - - mp->sw_if_index = ntohl (sw_if_index); - - S (mp); - W (ret); - return ret; -} - -static int -api_l2fib_add_del (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_l2fib_add_del_t *mp; - f64 timeout; - u8 mac[6] = { 0 }; - u8 mac_set = 0; - u32 bd_id; - u8 bd_id_set = 0; - u32 sw_if_index = 0; - u8 sw_if_index_set = 0; - u8 is_add = 1; - u8 static_mac = 0; - u8 filter_mac = 0; - u8 bvi_mac = 0; - int count = 1; - f64 before = 0; - int j; - - /* Parse args required to build the message */ - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "mac %U", unformat_ethernet_address, mac)) - mac_set = 1; - else if (unformat (i, "bd_id %d", &bd_id)) - bd_id_set = 1; - else if (unformat (i, "sw_if_index %d", &sw_if_index)) - sw_if_index_set = 1; - else if (unformat (i, "sw_if")) - { - if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat - (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) - sw_if_index_set = 1; - } - else - break; - } - else if (unformat (i, "static")) - static_mac = 1; - else if (unformat (i, "filter")) - { - filter_mac = 1; - static_mac = 1; - } - else if (unformat (i, "bvi")) - { - bvi_mac = 1; - static_mac = 1; - } - else if (unformat (i, "del")) - is_add = 0; - else if (unformat (i, "count %d", &count)) - ; - else - break; - } - - if (mac_set == 0) - { - errmsg ("missing mac address"); - return -99; - } - - if (bd_id_set == 0) - { - errmsg ("missing bridge domain"); - return -99; - } - - if (is_add && sw_if_index_set == 0 && filter_mac == 0) - { - errmsg ("missing interface name or sw_if_index"); - return -99; - } - - if (count > 1) - { - /* Turn on async mode */ - vam->async_mode = 1; - vam->async_errors = 0; - before = vat_time_now (vam); - } - - for (j = 0; j < count; j++) - { - M (L2FIB_ADD_DEL, mp); - - clib_memcpy (mp->mac, mac, 6); - mp->bd_id = ntohl (bd_id); - mp->is_add = is_add; - mp->sw_if_index = ntohl (sw_if_index); - - if (is_add) - { - mp->static_mac = static_mac; - mp->filter_mac = filter_mac; - mp->bvi_mac = bvi_mac; - } - increment_mac_address (mac); - /* send it... */ - S (mp); - } - - if (count > 1) - { - vl_api_control_ping_t *mp_ping; - f64 after; - - /* Shut off async mode */ - vam->async_mode = 0; - - MPING (CONTROL_PING, mp_ping); - S (mp_ping); - - timeout = vat_time_now (vam) + 1.0; - while (vat_time_now (vam) < timeout) - if (vam->result_ready == 1) - goto out; - vam->retval = -99; - - out: - if (vam->retval == -99) - errmsg ("timeout"); - - if (vam->async_errors > 0) - { - errmsg ("%d asynchronous errors", vam->async_errors); - vam->retval = -98; - } - vam->async_errors = 0; - after = vat_time_now (vam); - - print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec", - count, after - before, count / (after - before)); - } - else - { - int ret; - - /* Wait for a reply... */ - W (ret); - return ret; - } - /* Return the good/bad news */ - return (vam->retval); -} - -static int -api_bridge_domain_set_mac_age (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_bridge_domain_set_mac_age_t *mp; - u32 bd_id = ~0; - u32 mac_age = 0; - int ret; - - /* Parse args required to build the message */ - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "bd_id %d", &bd_id)); - else if (unformat (i, "mac-age %d", &mac_age)); - else - break; - } - - if (bd_id == ~0) - { - errmsg ("missing bridge domain"); - return -99; - } - - if (mac_age > 255) - { - errmsg ("mac age must be less than 256 "); - return -99; - } - - M (BRIDGE_DOMAIN_SET_MAC_AGE, mp); - - mp->bd_id = htonl (bd_id); - mp->mac_age = (u8) mac_age; - - S (mp); - W (ret); - return ret; -} - -static int -api_l2_flags (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_l2_flags_t *mp; - u32 sw_if_index; - u32 flags = 0; - u8 sw_if_index_set = 0; - u8 is_set = 0; - int ret; - - /* Parse args required to build the message */ - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "sw_if_index %d", &sw_if_index)) - sw_if_index_set = 1; - else if (unformat (i, "sw_if")) - { - if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat - (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) - sw_if_index_set = 1; - } - else - break; - } - else if (unformat (i, "learn")) - flags |= L2_LEARN; - else if (unformat (i, "forward")) - flags |= L2_FWD; - else if (unformat (i, "flood")) - flags |= L2_FLOOD; - else if (unformat (i, "uu-flood")) - flags |= L2_UU_FLOOD; - else if (unformat (i, "arp-term")) - flags |= L2_ARP_TERM; - else if (unformat (i, "off")) - is_set = 0; - else if (unformat (i, "disable")) - is_set = 0; - else - break; - } - - if (sw_if_index_set == 0) - { - errmsg ("missing interface name or sw_if_index"); - return -99; - } - - M (L2_FLAGS, mp); - - mp->sw_if_index = ntohl (sw_if_index); - mp->feature_bitmap = ntohl (flags); - mp->is_set = is_set; - - S (mp); - W (ret); - return ret; -} - -static int -api_bridge_flags (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_bridge_flags_t *mp; - u32 bd_id; - u8 bd_id_set = 0; - u8 is_set = 1; - bd_flags_t flags = 0; - int ret; - - /* Parse args required to build the message */ - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "bd_id %d", &bd_id)) - bd_id_set = 1; - else if (unformat (i, "learn")) - flags |= BRIDGE_API_FLAG_LEARN; - else if (unformat (i, "forward")) - flags |= BRIDGE_API_FLAG_FWD; - else if (unformat (i, "flood")) - flags |= BRIDGE_API_FLAG_FLOOD; - else if (unformat (i, "uu-flood")) - flags |= BRIDGE_API_FLAG_UU_FLOOD; - else if (unformat (i, "arp-term")) - flags |= BRIDGE_API_FLAG_ARP_TERM; - else if (unformat (i, "off")) - is_set = 0; - else if (unformat (i, "disable")) - is_set = 0; - else - break; - } - - if (bd_id_set == 0) - { - errmsg ("missing bridge domain"); - return -99; - } - - M (BRIDGE_FLAGS, mp); - - mp->bd_id = ntohl (bd_id); - mp->flags = ntohl (flags); - mp->is_set = is_set; - - S (mp); - W (ret); - return ret; -} - -static int -api_bd_ip_mac_add_del (vat_main_t * vam) -{ - vl_api_address_t ip = VL_API_ZERO_ADDRESS; - vl_api_mac_address_t mac = { 0 }; - unformat_input_t *i = vam->input; - vl_api_bd_ip_mac_add_del_t *mp; - u32 bd_id; - u8 is_add = 1; - u8 bd_id_set = 0; - u8 ip_set = 0; - u8 mac_set = 0; - int ret; - - - /* Parse args required to build the message */ - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "bd_id %d", &bd_id)) - { - bd_id_set++; - } - else if (unformat (i, "%U", unformat_vl_api_address, &ip)) - { - ip_set++; - } - else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac)) - { - mac_set++; - } - else if (unformat (i, "del")) - is_add = 0; - else - break; - } - - if (bd_id_set == 0) - { - errmsg ("missing bridge domain"); - return -99; - } - else if (ip_set == 0) - { - errmsg ("missing IP address"); - return -99; - } - else if (mac_set == 0) - { - errmsg ("missing MAC address"); - return -99; - } - - M (BD_IP_MAC_ADD_DEL, mp); - - mp->entry.bd_id = ntohl (bd_id); - mp->is_add = is_add; - - clib_memcpy (&mp->entry.ip, &ip, sizeof (ip)); - clib_memcpy (&mp->entry.mac, &mac, sizeof (mac)); - - S (mp); - W (ret); - return ret; -} - -static int -api_bd_ip_mac_flush (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_bd_ip_mac_flush_t *mp; - u32 bd_id; - u8 bd_id_set = 0; - int ret; - - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "bd_id %d", &bd_id)) - { - bd_id_set++; - } - else - break; - } - - if (bd_id_set == 0) - { - errmsg ("missing bridge domain"); - return -99; - } - - M (BD_IP_MAC_FLUSH, mp); - - mp->bd_id = ntohl (bd_id); - - S (mp); - W (ret); - return ret; -} - -static void vl_api_bd_ip_mac_details_t_handler - (vl_api_bd_ip_mac_details_t * mp) -{ - vat_main_t *vam = &vat_main; - - print (vam->ofp, - "\n%-5d %U %U", - ntohl (mp->entry.bd_id), - format_vl_api_mac_address, mp->entry.mac, - format_vl_api_address, &mp->entry.ip); -} - -static void vl_api_bd_ip_mac_details_t_handler_json - (vl_api_bd_ip_mac_details_t * mp) -{ - vat_main_t *vam = &vat_main; - vat_json_node_t *node = NULL; - - if (VAT_JSON_ARRAY != vam->json_tree.type) - { - ASSERT (VAT_JSON_NONE == vam->json_tree.type); - vat_json_init_array (&vam->json_tree); - } - node = vat_json_array_add (&vam->json_tree); - - vat_json_init_object (node); - vat_json_object_add_uint (node, "bd_id", ntohl (mp->entry.bd_id)); - vat_json_object_add_string_copy (node, "mac_address", - format (0, "%U", format_vl_api_mac_address, - &mp->entry.mac)); - u8 *ip = 0; - - ip = format (0, "%U", format_vl_api_address, &mp->entry.ip); - vat_json_object_add_string_copy (node, "ip_address", ip); - vec_free (ip); -} - -static int -api_bd_ip_mac_dump (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_bd_ip_mac_dump_t *mp; - vl_api_control_ping_t *mp_ping; - int ret; - u32 bd_id; - u8 bd_id_set = 0; - - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "bd_id %d", &bd_id)) - { - bd_id_set++; - } - else - break; - } - - print (vam->ofp, - "\n%-5s %-7s %-20s %-30s", - "bd_id", "is_ipv6", "mac_address", "ip_address"); - - /* Dump Bridge Domain Ip to Mac entries */ - M (BD_IP_MAC_DUMP, mp); - - if (bd_id_set) - mp->bd_id = htonl (bd_id); - else - mp->bd_id = ~0; - - S (mp); - - /* Use a control ping for synchronization */ - MPING (CONTROL_PING, mp_ping); - S (mp_ping); - - W (ret); - return ret; -} - -static int -api_tap_create_v2 (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_tap_create_v2_t *mp; - u8 mac_address[6]; - u8 random_mac = 1; - u32 id = ~0; - u32 num_rx_queues = 0; - u8 *host_if_name = 0; - u8 host_if_name_set = 0; - u8 *host_ns = 0; - u8 host_ns_set = 0; - u8 host_mac_addr[6]; - u8 host_mac_addr_set = 0; - u8 *host_bridge = 0; - u8 host_bridge_set = 0; - u8 host_ip4_prefix_set = 0; - u8 host_ip6_prefix_set = 0; - ip4_address_t host_ip4_addr; - ip4_address_t host_ip4_gw; - u8 host_ip4_gw_set = 0; - u32 host_ip4_prefix_len = 0; - ip6_address_t host_ip6_addr; - ip6_address_t host_ip6_gw; - u8 host_ip6_gw_set = 0; - u32 host_ip6_prefix_len = 0; - u32 host_mtu_size = 0; - u8 host_mtu_set = 0; - u32 tap_flags = 0; - int ret; - u32 rx_ring_sz = 0, tx_ring_sz = 0; - - clib_memset (mac_address, 0, sizeof (mac_address)); - - /* Parse args required to build the message */ - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "id %u", &id)) - ; - else - if (unformat - (i, "hw-addr %U", unformat_ethernet_address, mac_address)) - random_mac = 0; - else if (unformat (i, "host-if-name %s", &host_if_name)) - host_if_name_set = 1; - else if (unformat (i, "num-rx-queues %u", &num_rx_queues)) - ; - else if (unformat (i, "host-ns %s", &host_ns)) - host_ns_set = 1; - else if (unformat (i, "host-mac-addr %U", unformat_ethernet_address, - host_mac_addr)) - host_mac_addr_set = 1; - else if (unformat (i, "host-bridge %s", &host_bridge)) - host_bridge_set = 1; - else if (unformat (i, "host-ip4-addr %U/%u", unformat_ip4_address, - &host_ip4_addr, &host_ip4_prefix_len)) - host_ip4_prefix_set = 1; - else if (unformat (i, "host-ip6-addr %U/%u", unformat_ip6_address, - &host_ip6_addr, &host_ip6_prefix_len)) - host_ip6_prefix_set = 1; - else if (unformat (i, "host-ip4-gw %U", unformat_ip4_address, - &host_ip4_gw)) - host_ip4_gw_set = 1; - else if (unformat (i, "host-ip6-gw %U", unformat_ip6_address, - &host_ip6_gw)) - host_ip6_gw_set = 1; - else if (unformat (i, "rx-ring-size %u", &rx_ring_sz)) - ; - else if (unformat (i, "tx-ring-size %u", &tx_ring_sz)) - ; - else if (unformat (i, "host-mtu-size %u", &host_mtu_size)) - host_mtu_set = 1; - else if (unformat (i, "no-gso")) - tap_flags &= ~TAP_API_FLAG_GSO; - else if (unformat (i, "gso")) - tap_flags |= TAP_API_FLAG_GSO; - else if (unformat (i, "csum-offload")) - tap_flags |= TAP_API_FLAG_CSUM_OFFLOAD; - else if (unformat (i, "persist")) - tap_flags |= TAP_API_FLAG_PERSIST; - else if (unformat (i, "attach")) - tap_flags |= TAP_API_FLAG_ATTACH; - else if (unformat (i, "tun")) - tap_flags |= TAP_API_FLAG_TUN; - else if (unformat (i, "gro-coalesce")) - tap_flags |= TAP_API_FLAG_GRO_COALESCE; - else if (unformat (i, "packed")) - tap_flags |= TAP_API_FLAG_PACKED; - else if (unformat (i, "in-order")) - tap_flags |= TAP_API_FLAG_IN_ORDER; - else - break; - } - - if (vec_len (host_if_name) > 63) - { - errmsg ("tap name too long. "); - return -99; - } - if (vec_len (host_ns) > 63) - { - errmsg ("host name space too long. "); - return -99; - } - if (vec_len (host_bridge) > 63) - { - errmsg ("host bridge name too long. "); - return -99; - } - if (host_ip4_prefix_len > 32) - { - errmsg ("host ip4 prefix length not valid. "); - return -99; - } - if (host_ip6_prefix_len > 128) - { - errmsg ("host ip6 prefix length not valid. "); - return -99; - } - if (!is_pow2 (rx_ring_sz)) - { - errmsg ("rx ring size must be power of 2. "); - return -99; - } - if (rx_ring_sz > 32768) - { - errmsg ("rx ring size must be 32768 or lower. "); - return -99; - } - if (!is_pow2 (tx_ring_sz)) - { - errmsg ("tx ring size must be power of 2. "); - return -99; - } - if (tx_ring_sz > 32768) - { - errmsg ("tx ring size must be 32768 or lower. "); - return -99; - } - if (host_mtu_set && (host_mtu_size < 64 || host_mtu_size > 65355)) - { - errmsg ("host MTU size must be in between 64 and 65355. "); - return -99; - } - - /* Construct the API message */ - M (TAP_CREATE_V2, mp); - - mp->id = ntohl (id); - mp->use_random_mac = random_mac; - mp->num_rx_queues = (u8) num_rx_queues; - mp->tx_ring_sz = ntohs (tx_ring_sz); - mp->rx_ring_sz = ntohs (rx_ring_sz); - mp->host_mtu_set = host_mtu_set; - mp->host_mtu_size = ntohl (host_mtu_size); - mp->host_mac_addr_set = host_mac_addr_set; - mp->host_ip4_prefix_set = host_ip4_prefix_set; - mp->host_ip6_prefix_set = host_ip6_prefix_set; - mp->host_ip4_gw_set = host_ip4_gw_set; - mp->host_ip6_gw_set = host_ip6_gw_set; - mp->tap_flags = ntohl (tap_flags); - mp->host_namespace_set = host_ns_set; - mp->host_if_name_set = host_if_name_set; - mp->host_bridge_set = host_bridge_set; - - if (random_mac == 0) - clib_memcpy (mp->mac_address, mac_address, 6); - if (host_mac_addr_set) - clib_memcpy (mp->host_mac_addr, host_mac_addr, 6); - if (host_if_name_set) - clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name)); - if (host_ns_set) - clib_memcpy (mp->host_namespace, host_ns, vec_len (host_ns)); - if (host_bridge_set) - clib_memcpy (mp->host_bridge, host_bridge, vec_len (host_bridge)); - if (host_ip4_prefix_set) - { - clib_memcpy (mp->host_ip4_prefix.address, &host_ip4_addr, 4); - mp->host_ip4_prefix.len = (u8) host_ip4_prefix_len; - } - if (host_ip6_prefix_set) - { - clib_memcpy (mp->host_ip6_prefix.address, &host_ip6_addr, 16); - mp->host_ip6_prefix.len = (u8) host_ip6_prefix_len; - } - if (host_ip4_gw_set) - clib_memcpy (mp->host_ip4_gw, &host_ip4_gw, 4); - if (host_ip6_gw_set) - clib_memcpy (mp->host_ip6_gw, &host_ip6_gw, 16); - - vec_free (host_ns); - vec_free (host_if_name); - vec_free (host_bridge); - - /* send it... */ - S (mp); - - /* Wait for a reply... */ - W (ret); - return ret; -} - -static int -api_tap_delete_v2 (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_tap_delete_v2_t *mp; - u32 sw_if_index = ~0; - u8 sw_if_index_set = 0; - int ret; - - /* Parse args required to build the message */ - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) - sw_if_index_set = 1; - else if (unformat (i, "sw_if_index %d", &sw_if_index)) - sw_if_index_set = 1; - else - break; - } - - if (sw_if_index_set == 0) - { - errmsg ("missing vpp interface name. "); - return -99; - } - - /* Construct the API message */ - M (TAP_DELETE_V2, mp); - - mp->sw_if_index = ntohl (sw_if_index); - - /* send it... */ - S (mp); - - /* Wait for a reply... */ - W (ret); - return ret; -} - -uword -unformat_vlib_pci_addr (unformat_input_t * input, va_list * args) -{ - vlib_pci_addr_t *addr = va_arg (*args, vlib_pci_addr_t *); - u32 x[4]; - - if (!unformat (input, "%x:%x:%x.%x", &x[0], &x[1], &x[2], &x[3])) - return 0; - - addr->domain = x[0]; - addr->bus = x[1]; - addr->slot = x[2]; - addr->function = x[3]; - - return 1; -} - -static int -api_virtio_pci_create_v2 (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_virtio_pci_create_v2_t *mp; - u8 mac_address[6]; - u8 random_mac = 1; - u32 pci_addr = 0; - u64 features = (u64) ~ (0ULL); - u32 virtio_flags = 0; - int ret; - - clib_memset (mac_address, 0, sizeof (mac_address)); - - /* Parse args required to build the message */ - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "hw-addr %U", unformat_ethernet_address, mac_address)) - { - random_mac = 0; - } - else if (unformat (i, "pci-addr %U", unformat_vlib_pci_addr, &pci_addr)) - ; - else if (unformat (i, "features 0x%llx", &features)) - ; - else if (unformat (i, "gso-enabled")) - virtio_flags |= VIRTIO_API_FLAG_GSO; - else if (unformat (i, "csum-offload-enabled")) - virtio_flags |= VIRTIO_API_FLAG_CSUM_OFFLOAD; - else if (unformat (i, "gro-coalesce")) - virtio_flags |= VIRTIO_API_FLAG_GRO_COALESCE; - else if (unformat (i, "packed")) - virtio_flags |= VIRTIO_API_FLAG_PACKED; - else if (unformat (i, "in-order")) - virtio_flags |= VIRTIO_API_FLAG_IN_ORDER; - else - break; - } - - if (pci_addr == 0) - { - errmsg ("pci address must be non zero. "); - return -99; - } - - /* Construct the API message */ - M (VIRTIO_PCI_CREATE_V2, mp); - - mp->use_random_mac = random_mac; - - mp->pci_addr.domain = htons (((vlib_pci_addr_t) pci_addr).domain); - mp->pci_addr.bus = ((vlib_pci_addr_t) pci_addr).bus; - mp->pci_addr.slot = ((vlib_pci_addr_t) pci_addr).slot; - mp->pci_addr.function = ((vlib_pci_addr_t) pci_addr).function; - - mp->features = clib_host_to_net_u64 (features); - mp->virtio_flags = clib_host_to_net_u32 (virtio_flags); - - if (random_mac == 0) - clib_memcpy (mp->mac_address, mac_address, 6); - - /* send it... */ - S (mp); - - /* Wait for a reply... */ - W (ret); - return ret; -} - -static int -api_virtio_pci_delete (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_virtio_pci_delete_t *mp; - u32 sw_if_index = ~0; - u8 sw_if_index_set = 0; - int ret; - - /* Parse args required to build the message */ - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) - sw_if_index_set = 1; - else if (unformat (i, "sw_if_index %d", &sw_if_index)) - sw_if_index_set = 1; - else - break; - } - - if (sw_if_index_set == 0) - { - errmsg ("missing vpp interface name. "); - return -99; - } - - /* Construct the API message */ - M (VIRTIO_PCI_DELETE, mp); - - mp->sw_if_index = htonl (sw_if_index); - - /* send it... */ - S (mp); - - /* Wait for a reply... */ - W (ret); - return ret; -} - -static int -api_bond_create (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_bond_create_t *mp; - u8 mac_address[6]; - u8 custom_mac = 0; - int ret; - u8 mode; - u8 lb; - u8 mode_is_set = 0; - u32 id = ~0; - u8 numa_only = 0; - - clib_memset (mac_address, 0, sizeof (mac_address)); - lb = BOND_LB_L2; - - /* Parse args required to build the message */ - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "mode %U", unformat_bond_mode, &mode)) - mode_is_set = 1; - else if (((mode == BOND_MODE_LACP) || (mode == BOND_MODE_XOR)) - && unformat (i, "lb %U", unformat_bond_load_balance, &lb)) - ; - else if (unformat (i, "hw-addr %U", unformat_ethernet_address, - mac_address)) - custom_mac = 1; - else if (unformat (i, "numa-only")) - numa_only = 1; - else if (unformat (i, "id %u", &id)) - ; - else - break; - } - - if (mode_is_set == 0) - { - errmsg ("Missing bond mode. "); - return -99; - } - - /* Construct the API message */ - M (BOND_CREATE, mp); - - mp->use_custom_mac = custom_mac; - - mp->mode = htonl (mode); - mp->lb = htonl (lb); - mp->id = htonl (id); - mp->numa_only = numa_only; - - if (custom_mac) - clib_memcpy (mp->mac_address, mac_address, 6); - - /* send it... */ - S (mp); - - /* Wait for a reply... */ - W (ret); - return ret; -} - -static int -api_bond_create2 (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_bond_create2_t *mp; - u8 mac_address[6]; - u8 custom_mac = 0; - int ret; - u8 mode; - u8 lb; - u8 mode_is_set = 0; - u32 id = ~0; - u8 numa_only = 0; - u8 gso = 0; - - clib_memset (mac_address, 0, sizeof (mac_address)); - lb = BOND_LB_L2; - - /* Parse args required to build the message */ - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "mode %U", unformat_bond_mode, &mode)) - mode_is_set = 1; - else if (((mode == BOND_MODE_LACP) || (mode == BOND_MODE_XOR)) - && unformat (i, "lb %U", unformat_bond_load_balance, &lb)) - ; - else if (unformat (i, "hw-addr %U", unformat_ethernet_address, - mac_address)) - custom_mac = 1; - else if (unformat (i, "numa-only")) - numa_only = 1; - else if (unformat (i, "gso")) - gso = 1; - else if (unformat (i, "id %u", &id)) - ; - else - break; - } - - if (mode_is_set == 0) - { - errmsg ("Missing bond mode. "); - return -99; - } - - /* Construct the API message */ - M (BOND_CREATE2, mp); - - mp->use_custom_mac = custom_mac; - - mp->mode = htonl (mode); - mp->lb = htonl (lb); - mp->id = htonl (id); - mp->numa_only = numa_only; - mp->enable_gso = gso; - - if (custom_mac) - clib_memcpy (mp->mac_address, mac_address, 6); - - /* send it... */ - S (mp); - - /* Wait for a reply... */ - W (ret); - return ret; -} - -static int -api_bond_delete (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_bond_delete_t *mp; - u32 sw_if_index = ~0; - u8 sw_if_index_set = 0; - int ret; - - /* Parse args required to build the message */ - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) - sw_if_index_set = 1; - else if (unformat (i, "sw_if_index %d", &sw_if_index)) - sw_if_index_set = 1; - else - break; - } - - if (sw_if_index_set == 0) - { - errmsg ("missing vpp interface name. "); - return -99; - } - - /* Construct the API message */ - M (BOND_DELETE, mp); - - mp->sw_if_index = ntohl (sw_if_index); - - /* send it... */ - S (mp); - - /* Wait for a reply... */ - W (ret); - return ret; -} - -static int -api_bond_add_member (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_bond_add_member_t *mp; - u32 bond_sw_if_index; - int ret; - u8 is_passive; - u8 is_long_timeout; - u32 bond_sw_if_index_is_set = 0; - u32 sw_if_index; - u8 sw_if_index_is_set = 0; - - /* Parse args required to build the message */ - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "sw_if_index %d", &sw_if_index)) - sw_if_index_is_set = 1; - else if (unformat (i, "bond %u", &bond_sw_if_index)) - bond_sw_if_index_is_set = 1; - else if (unformat (i, "passive %d", &is_passive)) - ; - else if (unformat (i, "long-timeout %d", &is_long_timeout)) - ; - else - break; - } - - if (bond_sw_if_index_is_set == 0) - { - errmsg ("Missing bond sw_if_index. "); - return -99; - } - if (sw_if_index_is_set == 0) - { - errmsg ("Missing member sw_if_index. "); - return -99; - } - - /* Construct the API message */ - M (BOND_ADD_MEMBER, mp); - - mp->bond_sw_if_index = ntohl (bond_sw_if_index); - mp->sw_if_index = ntohl (sw_if_index); - mp->is_long_timeout = is_long_timeout; - mp->is_passive = is_passive; - - /* send it... */ - S (mp); - - /* Wait for a reply... */ - W (ret); - return ret; -} - -static int -api_bond_detach_member (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_bond_detach_member_t *mp; - u32 sw_if_index = ~0; - u8 sw_if_index_set = 0; - int ret; - - /* Parse args required to build the message */ - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) - sw_if_index_set = 1; - else if (unformat (i, "sw_if_index %d", &sw_if_index)) - sw_if_index_set = 1; - else - break; - } - - if (sw_if_index_set == 0) - { - errmsg ("missing vpp interface name. "); - return -99; - } - - /* Construct the API message */ - M (BOND_DETACH_MEMBER, mp); - - mp->sw_if_index = ntohl (sw_if_index); - - /* send it... */ - S (mp); - - /* Wait for a reply... */ - W (ret); - return ret; -} - -static int -api_ip_table_add_del (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_ip_table_add_del_t *mp; - u32 table_id = ~0; - u8 is_ipv6 = 0; - u8 is_add = 1; - int ret = 0; - - /* Parse args required to build the message */ - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "ipv6")) - is_ipv6 = 1; - else if (unformat (i, "del")) - is_add = 0; - else if (unformat (i, "add")) - is_add = 1; - else if (unformat (i, "table %d", &table_id)) - ; - else - { - clib_warning ("parse error '%U'", format_unformat_error, i); - return -99; - } - } - - if (~0 == table_id) - { - errmsg ("missing table-ID"); - return -99; - } - - /* Construct the API message */ - M (IP_TABLE_ADD_DEL, mp); - - mp->table.table_id = ntohl (table_id); - mp->table.is_ip6 = is_ipv6; - mp->is_add = is_add; - - /* send it... */ - S (mp); - - /* Wait for a reply... */ - W (ret); - - return ret; -} - -uword -unformat_fib_path (unformat_input_t * input, va_list * args) -{ - vat_main_t *vam = va_arg (*args, vat_main_t *); - vl_api_fib_path_t *path = va_arg (*args, vl_api_fib_path_t *); - u32 weight, preference; - mpls_label_t out_label; - - clib_memset (path, 0, sizeof (*path)); - path->weight = 1; - path->sw_if_index = ~0; - path->rpf_id = ~0; - path->n_labels = 0; - - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (input, "%U %U", - unformat_vl_api_ip4_address, - &path->nh.address.ip4, - api_unformat_sw_if_index, vam, &path->sw_if_index)) - { - path->proto = FIB_API_PATH_NH_PROTO_IP4; - } - else if (unformat (input, "%U %U", - unformat_vl_api_ip6_address, - &path->nh.address.ip6, - api_unformat_sw_if_index, vam, &path->sw_if_index)) - { - path->proto = FIB_API_PATH_NH_PROTO_IP6; - } - else if (unformat (input, "weight %u", &weight)) - { - path->weight = weight; - } - else if (unformat (input, "preference %u", &preference)) - { - path->preference = preference; - } - else if (unformat (input, "%U next-hop-table %d", - unformat_vl_api_ip4_address, - &path->nh.address.ip4, &path->table_id)) - { - path->proto = FIB_API_PATH_NH_PROTO_IP4; - } - else if (unformat (input, "%U next-hop-table %d", - unformat_vl_api_ip6_address, - &path->nh.address.ip6, &path->table_id)) - { - path->proto = FIB_API_PATH_NH_PROTO_IP6; - } - else if (unformat (input, "%U", - unformat_vl_api_ip4_address, &path->nh.address.ip4)) - { - /* - * the recursive next-hops are by default in the default table - */ - path->table_id = 0; - path->sw_if_index = ~0; - path->proto = FIB_API_PATH_NH_PROTO_IP4; - } - else if (unformat (input, "%U", - unformat_vl_api_ip6_address, &path->nh.address.ip6)) - { - /* - * the recursive next-hops are by default in the default table - */ - path->table_id = 0; - path->sw_if_index = ~0; - path->proto = FIB_API_PATH_NH_PROTO_IP6; - } - else if (unformat (input, "resolve-via-host")) - { - path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_HOST; - } - else if (unformat (input, "resolve-via-attached")) - { - path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_ATTACHED; - } - else if (unformat (input, "ip4-lookup-in-table %d", &path->table_id)) - { - path->type = FIB_API_PATH_TYPE_LOCAL; - path->sw_if_index = ~0; - path->proto = FIB_API_PATH_NH_PROTO_IP4; - } - else if (unformat (input, "ip6-lookup-in-table %d", &path->table_id)) - { - path->type = FIB_API_PATH_TYPE_LOCAL; - path->sw_if_index = ~0; - path->proto = FIB_API_PATH_NH_PROTO_IP6; - } - else if (unformat (input, "sw_if_index %d", &path->sw_if_index)) - ; - else if (unformat (input, "via-label %d", &path->nh.via_label)) - { - path->proto = FIB_API_PATH_NH_PROTO_MPLS; - path->sw_if_index = ~0; - } - else if (unformat (input, "l2-input-on %d", &path->sw_if_index)) - { - path->proto = FIB_API_PATH_NH_PROTO_ETHERNET; - path->type = FIB_API_PATH_TYPE_INTERFACE_RX; - } - else if (unformat (input, "local")) - { - path->type = FIB_API_PATH_TYPE_LOCAL; - } - else if (unformat (input, "out-labels")) - { - while (unformat (input, "%d", &out_label)) - { - path->label_stack[path->n_labels].label = out_label; - path->label_stack[path->n_labels].is_uniform = 0; - path->label_stack[path->n_labels].ttl = 64; - path->n_labels++; - } - } - else if (unformat (input, "via")) - { - /* new path, back up and return */ - unformat_put_input (input); - unformat_put_input (input); - unformat_put_input (input); - unformat_put_input (input); - break; - } - else - { - return (0); - } - } - - path->proto = ntohl (path->proto); - path->type = ntohl (path->type); - path->flags = ntohl (path->flags); - path->table_id = ntohl (path->table_id); - path->sw_if_index = ntohl (path->sw_if_index); +#define foreach_vpe_api_reply_msg \ +_(CREATE_LOOPBACK_REPLY, create_loopback_reply) \ +_(CREATE_LOOPBACK_INSTANCE_REPLY, create_loopback_instance_reply) \ +_(SW_INTERFACE_DETAILS, sw_interface_details) \ +_(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \ +_(CONTROL_PING_REPLY, control_ping_reply) \ +_(CLI_REPLY, cli_reply) \ +_(CLI_INBAND_REPLY, cli_inband_reply) \ +_(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \ + sw_interface_add_del_address_reply) \ +_(SW_INTERFACE_SET_RX_MODE_REPLY, sw_interface_set_rx_mode_reply) \ +_(SW_INTERFACE_SET_RX_PLACEMENT_REPLY, sw_interface_set_rx_placement_reply) \ +_(SW_INTERFACE_RX_PLACEMENT_DETAILS, sw_interface_rx_placement_details) \ +_(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \ +_(SW_INTERFACE_SET_MPLS_ENABLE_REPLY, sw_interface_set_mpls_enable_reply) \ +_(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \ +_(SW_INTERFACE_SET_VXLAN_BYPASS_REPLY, sw_interface_set_vxlan_bypass_reply) \ +_(SW_INTERFACE_SET_VXLAN_GPE_BYPASS_REPLY, sw_interface_set_vxlan_gpe_bypass_reply) \ +_(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \ + sw_interface_set_l2_xconnect_reply) \ +_(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \ + sw_interface_set_l2_bridge_reply) \ +_(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \ +_(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \ +_(BRIDGE_DOMAIN_SET_MAC_AGE_REPLY, bridge_domain_set_mac_age_reply) \ +_(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \ +_(L2FIB_FLUSH_INT_REPLY, l2fib_flush_int_reply) \ +_(L2FIB_FLUSH_BD_REPLY, l2fib_flush_bd_reply) \ +_(L2_FLAGS_REPLY, l2_flags_reply) \ +_(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \ +_(TAP_CREATE_V2_REPLY, tap_create_v2_reply) \ +_(TAP_DELETE_V2_REPLY, tap_delete_v2_reply) \ +_(SW_INTERFACE_TAP_V2_DETAILS, sw_interface_tap_v2_details) \ +_(VIRTIO_PCI_CREATE_REPLY, virtio_pci_create_reply) \ +_(VIRTIO_PCI_CREATE_V2_REPLY, virtio_pci_create_v2_reply) \ +_(VIRTIO_PCI_DELETE_REPLY, virtio_pci_delete_reply) \ +_(SW_INTERFACE_VIRTIO_PCI_DETAILS, sw_interface_virtio_pci_details) \ +_(BOND_CREATE_REPLY, bond_create_reply) \ +_(BOND_CREATE2_REPLY, bond_create2_reply) \ +_(BOND_DELETE_REPLY, bond_delete_reply) \ +_(BOND_ADD_MEMBER_REPLY, bond_add_member_reply) \ +_(BOND_DETACH_MEMBER_REPLY, bond_detach_member_reply) \ +_(SW_INTERFACE_SET_BOND_WEIGHT_REPLY, sw_interface_set_bond_weight_reply) \ +_(SW_BOND_INTERFACE_DETAILS, sw_bond_interface_details) \ +_(SW_MEMBER_INTERFACE_DETAILS, sw_member_interface_details) \ +_(IP_ROUTE_ADD_DEL_REPLY, ip_route_add_del_reply) \ +_(IP_TABLE_ADD_DEL_REPLY, ip_table_add_del_reply) \ +_(IP_TABLE_REPLACE_BEGIN_REPLY, ip_table_replace_begin_reply) \ +_(IP_TABLE_FLUSH_REPLY, ip_table_flush_reply) \ +_(IP_TABLE_REPLACE_END_REPLY, ip_table_replace_end_reply) \ +_(IP_MROUTE_ADD_DEL_REPLY, ip_mroute_add_del_reply) \ +_(MPLS_TABLE_ADD_DEL_REPLY, mpls_table_add_del_reply) \ +_(MPLS_ROUTE_ADD_DEL_REPLY, mpls_route_add_del_reply) \ +_(MPLS_IP_BIND_UNBIND_REPLY, mpls_ip_bind_unbind_reply) \ +_(BIER_ROUTE_ADD_DEL_REPLY, bier_route_add_del_reply) \ +_(BIER_TABLE_ADD_DEL_REPLY, bier_table_add_del_reply) \ +_(MPLS_TUNNEL_ADD_DEL_REPLY, mpls_tunnel_add_del_reply) \ +_(SW_INTERFACE_SET_UNNUMBERED_REPLY, \ + sw_interface_set_unnumbered_reply) \ +_(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \ +_(CREATE_SUBIF_REPLY, create_subif_reply) \ +_(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \ +_(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \ + sw_interface_ip6_enable_disable_reply) \ +_(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \ +_(SR_MPLS_POLICY_ADD_REPLY, sr_mpls_policy_add_reply) \ +_(SR_MPLS_POLICY_MOD_REPLY, sr_mpls_policy_mod_reply) \ +_(SR_MPLS_POLICY_DEL_REPLY, sr_mpls_policy_del_reply) \ +_(SR_POLICY_ADD_REPLY, sr_policy_add_reply) \ +_(SR_POLICY_MOD_REPLY, sr_policy_mod_reply) \ +_(SR_POLICY_DEL_REPLY, sr_policy_del_reply) \ +_(SR_LOCALSID_ADD_DEL_REPLY, sr_localsid_add_del_reply) \ +_(SR_STEERING_ADD_DEL_REPLY, sr_steering_add_del_reply) \ +_(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \ +_(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \ +_(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \ +classify_set_interface_ip_table_reply) \ +_(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \ + classify_set_interface_l2_tables_reply) \ +_(GET_NODE_INDEX_REPLY, get_node_index_reply) \ +_(ADD_NODE_NEXT_REPLY, add_node_next_reply) \ +_(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \ +_(VXLAN_OFFLOAD_RX_REPLY, vxlan_offload_rx_reply) \ +_(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \ +_(GRE_TUNNEL_ADD_DEL_REPLY, gre_tunnel_add_del_reply) \ +_(GRE_TUNNEL_DETAILS, gre_tunnel_details) \ +_(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \ +_(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \ +_(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \ +_(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \ +_(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \ +_(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \ +_(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \ +_(SHOW_VERSION_REPLY, show_version_reply) \ +_(SHOW_THREADS_REPLY, show_threads_reply) \ +_(L2_FIB_TABLE_DETAILS, l2_fib_table_details) \ +_(VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, vxlan_gpe_add_del_tunnel_reply) \ +_(VXLAN_GPE_TUNNEL_DETAILS, vxlan_gpe_tunnel_details) \ +_(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \ +_(WANT_L2_MACS_EVENTS_REPLY, want_l2_macs_events_reply) \ +_(L2_MACS_EVENT, l2_macs_event) \ +_(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \ +_(IP_ADDRESS_DETAILS, ip_address_details) \ +_(IP_DETAILS, ip_details) \ +_(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \ +_(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \ +_(IPSEC_SPD_ENTRY_ADD_DEL_REPLY, ipsec_spd_entry_add_del_reply) \ +_(IPSEC_SAD_ENTRY_ADD_DEL_REPLY, ipsec_sad_entry_add_del_reply) \ +_(IPSEC_SA_DETAILS, ipsec_sa_details) \ +_(IPSEC_TUNNEL_IF_ADD_DEL_REPLY, ipsec_tunnel_if_add_del_reply) \ +_(IPSEC_TUNNEL_IF_SET_SA_REPLY, ipsec_tunnel_if_set_sa_reply) \ +_(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \ +_(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \ +_(BD_IP_MAC_FLUSH_REPLY, bd_ip_mac_flush_reply) \ +_(BD_IP_MAC_DETAILS, bd_ip_mac_details) \ +_(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \ +_(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \ +_(COP_INTERFACE_ENABLE_DISABLE_REPLY, cop_interface_enable_disable_reply) \ +_(COP_WHITELIST_ENABLE_DISABLE_REPLY, cop_whitelist_enable_disable_reply) \ +_(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \ +_(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \ +_(IOAM_ENABLE_REPLY, ioam_enable_reply) \ +_(IOAM_DISABLE_REPLY, ioam_disable_reply) \ +_(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \ +_(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \ +_(AF_PACKET_DETAILS, af_packet_details) \ +_(POLICER_ADD_DEL_REPLY, policer_add_del_reply) \ +_(POLICER_DETAILS, policer_details) \ +_(POLICER_CLASSIFY_SET_INTERFACE_REPLY, policer_classify_set_interface_reply) \ +_(POLICER_CLASSIFY_DETAILS, policer_classify_details) \ +_(MPLS_TUNNEL_DETAILS, mpls_tunnel_details) \ +_(MPLS_TABLE_DETAILS, mpls_table_details) \ +_(MPLS_ROUTE_DETAILS, mpls_route_details) \ +_(CLASSIFY_TABLE_IDS_REPLY, classify_table_ids_reply) \ +_(CLASSIFY_TABLE_BY_INTERFACE_REPLY, classify_table_by_interface_reply) \ +_(CLASSIFY_TABLE_INFO_REPLY, classify_table_info_reply) \ +_(CLASSIFY_SESSION_DETAILS, classify_session_details) \ +_(SET_IPFIX_EXPORTER_REPLY, set_ipfix_exporter_reply) \ +_(IPFIX_EXPORTER_DETAILS, ipfix_exporter_details) \ +_(SET_IPFIX_CLASSIFY_STREAM_REPLY, set_ipfix_classify_stream_reply) \ +_(IPFIX_CLASSIFY_STREAM_DETAILS, ipfix_classify_stream_details) \ +_(IPFIX_CLASSIFY_TABLE_ADD_DEL_REPLY, ipfix_classify_table_add_del_reply) \ +_(IPFIX_CLASSIFY_TABLE_DETAILS, ipfix_classify_table_details) \ +_(FLOW_CLASSIFY_SET_INTERFACE_REPLY, flow_classify_set_interface_reply) \ +_(FLOW_CLASSIFY_DETAILS, flow_classify_details) \ +_(SW_INTERFACE_SPAN_ENABLE_DISABLE_REPLY, sw_interface_span_enable_disable_reply) \ +_(SW_INTERFACE_SPAN_DETAILS, sw_interface_span_details) \ +_(GET_NEXT_INDEX_REPLY, get_next_index_reply) \ +_(PG_CREATE_INTERFACE_REPLY, pg_create_interface_reply) \ +_(PG_CAPTURE_REPLY, pg_capture_reply) \ +_(PG_ENABLE_DISABLE_REPLY, pg_enable_disable_reply) \ +_(PG_INTERFACE_ENABLE_DISABLE_COALESCE_REPLY, pg_interface_enable_disable_coalesce_reply) \ +_(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY, \ + ip_source_and_port_range_check_add_del_reply) \ +_(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY, \ + ip_source_and_port_range_check_interface_add_del_reply) \ +_(DELETE_SUBIF_REPLY, delete_subif_reply) \ +_(L2_INTERFACE_PBB_TAG_REWRITE_REPLY, l2_interface_pbb_tag_rewrite_reply) \ +_(SET_PUNT_REPLY, set_punt_reply) \ +_(IP_TABLE_DETAILS, ip_table_details) \ +_(IP_ROUTE_DETAILS, ip_route_details) \ +_(FEATURE_ENABLE_DISABLE_REPLY, feature_enable_disable_reply) \ +_(FEATURE_GSO_ENABLE_DISABLE_REPLY, feature_gso_enable_disable_reply) \ +_(SW_INTERFACE_TAG_ADD_DEL_REPLY, sw_interface_tag_add_del_reply) \ +_(SW_INTERFACE_ADD_DEL_MAC_ADDRESS_REPLY, sw_interface_add_del_mac_address_reply) \ +_(L2_XCONNECT_DETAILS, l2_xconnect_details) \ +_(HW_INTERFACE_SET_MTU_REPLY, hw_interface_set_mtu_reply) \ +_(SW_INTERFACE_GET_TABLE_REPLY, sw_interface_get_table_reply) \ +_(P2P_ETHERNET_ADD_REPLY, p2p_ethernet_add_reply) \ +_(P2P_ETHERNET_DEL_REPLY, p2p_ethernet_del_reply) \ +_(TCP_CONFIGURE_SRC_ADDRESSES_REPLY, tcp_configure_src_addresses_reply) \ +_(APP_NAMESPACE_ADD_DEL_REPLY, app_namespace_add_del_reply) \ +_(SESSION_RULE_ADD_DEL_REPLY, session_rule_add_del_reply) \ +_(SESSION_RULES_DETAILS, session_rules_details) \ +_(IP_CONTAINER_PROXY_ADD_DEL_REPLY, ip_container_proxy_add_del_reply) \ +_(OUTPUT_ACL_SET_INTERFACE_REPLY, output_acl_set_interface_reply) \ +_(QOS_RECORD_ENABLE_DISABLE_REPLY, qos_record_enable_disable_reply) \ +_(FLOW_ADD_REPLY, flow_add_reply) \ - return (1); -} +#define foreach_standalone_reply_msg \ +_(SW_INTERFACE_EVENT, sw_interface_event) -static int -api_ip_route_add_del (vat_main_t * vam) +typedef struct { - unformat_input_t *i = vam->input; - vl_api_ip_route_add_del_t *mp; - u32 vrf_id = 0; - u8 is_add = 1; - u8 is_multipath = 0; - u8 prefix_set = 0; - u8 path_count = 0; - vl_api_prefix_t pfx = { }; - vl_api_fib_path_t paths[8]; - int count = 1; - int j; - f64 before = 0; - u32 random_add_del = 0; - u32 *random_vector = 0; - u32 random_seed = 0xdeaddabe; - - /* Parse args required to build the message */ - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "%U", unformat_vl_api_prefix, &pfx)) - prefix_set = 1; - else if (unformat (i, "del")) - is_add = 0; - else if (unformat (i, "add")) - is_add = 1; - else if (unformat (i, "vrf %d", &vrf_id)) - ; - else if (unformat (i, "count %d", &count)) - ; - else if (unformat (i, "random")) - random_add_del = 1; - else if (unformat (i, "multipath")) - is_multipath = 1; - else if (unformat (i, "seed %d", &random_seed)) - ; - else - if (unformat - (i, "via %U", unformat_fib_path, vam, &paths[path_count])) - { - path_count++; - if (8 == path_count) - { - errmsg ("max 8 paths"); - return -99; - } - } - else - { - clib_warning ("parse error '%U'", format_unformat_error, i); - return -99; - } - } - - if (!path_count) - { - errmsg ("specify a path; via ..."); - return -99; - } - if (prefix_set == 0) - { - errmsg ("missing prefix"); - return -99; - } - - /* Generate a pile of unique, random routes */ - if (random_add_del) - { - ip4_address_t *i = (ip4_address_t *) & paths[0].nh.address.ip4; - u32 this_random_address; - uword *random_hash; - - random_hash = hash_create (count, sizeof (uword)); - - hash_set (random_hash, i->as_u32, 1); - for (j = 0; j <= count; j++) - { - do - { - this_random_address = random_u32 (&random_seed); - this_random_address = - clib_host_to_net_u32 (this_random_address); - } - while (hash_get (random_hash, this_random_address)); - vec_add1 (random_vector, this_random_address); - hash_set (random_hash, this_random_address, 1); - } - hash_free (random_hash); - set_ip4_address (&pfx.address, random_vector[0]); - } - - if (count > 1) - { - /* Turn on async mode */ - vam->async_mode = 1; - vam->async_errors = 0; - before = vat_time_now (vam); - } - - for (j = 0; j < count; j++) - { - /* Construct the API message */ - M2 (IP_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count); - - mp->is_add = is_add; - mp->is_multipath = is_multipath; - - clib_memcpy (&mp->route.prefix, &pfx, sizeof (pfx)); - mp->route.table_id = ntohl (vrf_id); - mp->route.n_paths = path_count; - - clib_memcpy (&mp->route.paths, &paths, sizeof (paths[0]) * path_count); - - if (random_add_del) - set_ip4_address (&pfx.address, random_vector[j + 1]); - else - increment_address (&pfx.address); - /* send it... */ - S (mp); - /* If we receive SIGTERM, stop now... */ - if (vam->do_exit) - break; - } - - /* When testing multiple add/del ops, use a control-ping to sync */ - if (count > 1) - { - vl_api_control_ping_t *mp_ping; - f64 after; - f64 timeout; - - /* Shut off async mode */ - vam->async_mode = 0; - - MPING (CONTROL_PING, mp_ping); - S (mp_ping); - - timeout = vat_time_now (vam) + 1.0; - while (vat_time_now (vam) < timeout) - if (vam->result_ready == 1) - goto out; - vam->retval = -99; - - out: - if (vam->retval == -99) - errmsg ("timeout"); - - if (vam->async_errors > 0) - { - errmsg ("%d asynchronous errors", vam->async_errors); - vam->retval = -98; - } - vam->async_errors = 0; - after = vat_time_now (vam); + u8 *name; + u32 value; +} name_sort_t; - /* slim chance, but we might have eaten SIGTERM on the first iteration */ - if (j > 0) - count = j; +#define STR_VTR_OP_CASE(op) \ + case L2_VTR_ ## op: \ + return "" # op; - print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec", - count, after - before, count / (after - before)); - } - else +static const char * +str_vtr_op (u32 vtr_op) +{ + switch (vtr_op) { - int ret; - - /* Wait for a reply... */ - W (ret); - return ret; + STR_VTR_OP_CASE (DISABLED); + STR_VTR_OP_CASE (PUSH_1); + STR_VTR_OP_CASE (PUSH_2); + STR_VTR_OP_CASE (POP_1); + STR_VTR_OP_CASE (POP_2); + STR_VTR_OP_CASE (TRANSLATE_1_1); + STR_VTR_OP_CASE (TRANSLATE_1_2); + STR_VTR_OP_CASE (TRANSLATE_2_1); + STR_VTR_OP_CASE (TRANSLATE_2_2); } - /* Return the good/bad news */ - return (vam->retval); + return "UNKNOWN"; } static int -api_ip_mroute_add_del (vat_main_t * vam) +dump_sub_interface_table (vat_main_t * vam) { - unformat_input_t *i = vam->input; - u8 path_set = 0, prefix_set = 0, is_add = 1; - vl_api_ip_mroute_add_del_t *mp; - mfib_entry_flags_t eflags = 0; - vl_api_mfib_path_t path; - vl_api_mprefix_t pfx = { }; - u32 vrf_id = 0; - int ret; - - /* Parse args required to build the message */ - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "%U", unformat_vl_api_mprefix, &pfx)) - { - prefix_set = 1; - pfx.grp_address_length = htons (pfx.grp_address_length); - } - else if (unformat (i, "del")) - is_add = 0; - else if (unformat (i, "add")) - is_add = 1; - else if (unformat (i, "vrf %d", &vrf_id)) - ; - else if (unformat (i, "%U", unformat_mfib_itf_flags, &path.itf_flags)) - path.itf_flags = htonl (path.itf_flags); - else if (unformat (i, "%U", unformat_mfib_entry_flags, &eflags)) - ; - else if (unformat (i, "via %U", unformat_fib_path, vam, &path.path)) - path_set = 1; - else - { - clib_warning ("parse error '%U'", format_unformat_error, i); - return -99; - } - } + const sw_interface_subif_t *sub = NULL; - if (prefix_set == 0) - { - errmsg ("missing addresses\n"); - return -99; - } - if (path_set == 0) + if (vam->json_output) { - errmsg ("missing path\n"); + clib_warning + ("JSON output supported only for VPE API calls and dump_stats_table"); return -99; } - /* Construct the API message */ - M (IP_MROUTE_ADD_DEL, mp); - - mp->is_add = is_add; - mp->is_multipath = 1; - - clib_memcpy (&mp->route.prefix, &pfx, sizeof (pfx)); - mp->route.table_id = htonl (vrf_id); - mp->route.n_paths = 1; - mp->route.entry_flags = htonl (eflags); + print (vam->ofp, + "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s", + "Interface", "sw_if_index", + "sub id", "dot1ad", "tags", "outer id", + "inner id", "exact", "default", "outer any", "inner any"); - clib_memcpy (&mp->route.paths, &path, sizeof (path)); + vec_foreach (sub, vam->sw_if_subif_table) + { + print (vam->ofp, + "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d", + sub->interface_name, + sub->sw_if_index, + sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q", + sub->sub_number_of_tags, sub->sub_outer_vlan_id, + sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default, + sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any); + if (sub->vtr_op != L2_VTR_DISABLED) + { + print (vam->ofp, + " vlan-tag-rewrite - op: %-14s [ dot1q: %d " + "tag1: %d tag2: %d ]", + str_vtr_op (sub->vtr_op), sub->vtr_push_dot1q, + sub->vtr_tag1, sub->vtr_tag2); + } + } - /* send it... */ - S (mp); - /* Wait for a reply... */ - W (ret); - return ret; + return 0; } static int -api_mpls_table_add_del (vat_main_t * vam) +name_sort_cmp (void *a1, void *a2) { - unformat_input_t *i = vam->input; - vl_api_mpls_table_add_del_t *mp; - u32 table_id = ~0; - u8 is_add = 1; - int ret = 0; + name_sort_t *n1 = a1; + name_sort_t *n2 = a2; - /* Parse args required to build the message */ - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "table %d", &table_id)) - ; - else if (unformat (i, "del")) - is_add = 0; - else if (unformat (i, "add")) - is_add = 1; - else - { - clib_warning ("parse error '%U'", format_unformat_error, i); - return -99; - } - } + return strcmp ((char *) n1->name, (char *) n2->name); +} - if (~0 == table_id) +static int +dump_interface_table (vat_main_t * vam) +{ + hash_pair_t *p; + name_sort_t *nses = 0, *ns; + + if (vam->json_output) { - errmsg ("missing table-ID"); + clib_warning + ("JSON output supported only for VPE API calls and dump_stats_table"); return -99; } - /* Construct the API message */ - M (MPLS_TABLE_ADD_DEL, mp); - - mp->mt_table.mt_table_id = ntohl (table_id); - mp->mt_is_add = is_add; - - /* send it... */ - S (mp); + /* *INDENT-OFF* */ + hash_foreach_pair (p, vam->sw_if_index_by_interface_name, + ({ + vec_add2 (nses, ns, 1); + ns->name = (u8 *)(p->key); + ns->value = (u32) p->value[0]; + })); + /* *INDENT-ON* */ - /* Wait for a reply... */ - W (ret); + vec_sort_with_function (nses, name_sort_cmp); - return ret; + print (vam->ofp, "%-25s%-15s", "Interface", "sw_if_index"); + vec_foreach (ns, nses) + { + print (vam->ofp, "%-25s%-15d", ns->name, ns->value); + } + vec_free (nses); + return 0; } static int -api_mpls_route_add_del (vat_main_t * vam) +dump_ip_table (vat_main_t * vam, int is_ipv6) { - u8 is_add = 1, path_count = 0, is_multipath = 0, is_eos = 0; - mpls_label_t local_label = MPLS_LABEL_INVALID; - unformat_input_t *i = vam->input; - vl_api_mpls_route_add_del_t *mp; - vl_api_fib_path_t paths[8]; - int count = 1, j; - f64 before = 0; + const ip_details_t *det = NULL; + const ip_address_details_t *address = NULL; + u32 i = ~0; - /* Parse args required to build the message */ - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "%d", &local_label)) - ; - else if (unformat (i, "eos")) - is_eos = 1; - else if (unformat (i, "non-eos")) - is_eos = 0; - else if (unformat (i, "del")) - is_add = 0; - else if (unformat (i, "add")) - is_add = 1; - else if (unformat (i, "multipath")) - is_multipath = 1; - else if (unformat (i, "count %d", &count)) - ; - else - if (unformat - (i, "via %U", unformat_fib_path, vam, &paths[path_count])) - { - path_count++; - if (8 == path_count) - { - errmsg ("max 8 paths"); - return -99; - } - } - else - { - clib_warning ("parse error '%U'", format_unformat_error, i); - return -99; - } - } + print (vam->ofp, "%-12s", "sw_if_index"); - if (!path_count) + vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6]) + { + i++; + if (!det->present) + { + continue; + } + print (vam->ofp, "%-12d", i); + print (vam->ofp, " %-30s%-13s", "Address", "Prefix length"); + if (!det->addr) + { + continue; + } + vec_foreach (address, det->addr) { - errmsg ("specify a path; via ..."); - return -99; + print (vam->ofp, + " %-30U%-13d", + is_ipv6 ? format_ip6_address : format_ip4_address, + address->ip, address->prefix_length); } + } - if (MPLS_LABEL_INVALID == local_label) + return 0; +} + +static int +dump_ipv4_table (vat_main_t * vam) +{ + if (vam->json_output) { - errmsg ("missing label"); + clib_warning + ("JSON output supported only for VPE API calls and dump_stats_table"); return -99; } - if (count > 1) - { - /* Turn on async mode */ - vam->async_mode = 1; - vam->async_errors = 0; - before = vat_time_now (vam); - } + return dump_ip_table (vam, 0); +} - for (j = 0; j < count; j++) +static int +dump_ipv6_table (vat_main_t * vam) +{ + if (vam->json_output) { - /* Construct the API message */ - M2 (MPLS_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count); - - mp->mr_is_add = is_add; - mp->mr_is_multipath = is_multipath; + clib_warning + ("JSON output supported only for VPE API calls and dump_stats_table"); + return -99; + } - mp->mr_route.mr_label = local_label; - mp->mr_route.mr_eos = is_eos; - mp->mr_route.mr_table_id = 0; - mp->mr_route.mr_n_paths = path_count; + return dump_ip_table (vam, 1); +} - clib_memcpy (&mp->mr_route.mr_paths, paths, - sizeof (paths[0]) * path_count); +/* + * Pass CLI buffers directly in the CLI_INBAND API message, + * instead of an additional shared memory area. + */ +static int +exec_inband (vat_main_t * vam) +{ + vl_api_cli_inband_t *mp; + unformat_input_t *i = vam->input; + int ret; - local_label++; + if (vec_len (i->buffer) == 0) + return -1; - /* send it... */ - S (mp); - /* If we receive SIGTERM, stop now... */ - if (vam->do_exit) - break; + if (vam->exec_mode == 0 && unformat (i, "mode")) + { + vam->exec_mode = 1; + return 0; } - - /* When testing multiple add/del ops, use a control-ping to sync */ - if (count > 1) + if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit"))) { - vl_api_control_ping_t *mp_ping; - f64 after; - f64 timeout; - - /* Shut off async mode */ - vam->async_mode = 0; + vam->exec_mode = 0; + return 0; + } - MPING (CONTROL_PING, mp_ping); - S (mp_ping); + /* + * In order for the CLI command to work, it + * must be a vector ending in \n, not a C-string ending + * in \n\0. + */ + M2 (CLI_INBAND, mp, vec_len (vam->input->buffer)); + vl_api_vec_to_api_string (vam->input->buffer, &mp->cmd); - timeout = vat_time_now (vam) + 1.0; - while (vat_time_now (vam) < timeout) - if (vam->result_ready == 1) - goto out; - vam->retval = -99; + S (mp); + W (ret); + /* json responses may or may not include a useful reply... */ + if (vec_len (vam->cmd_reply)) + print (vam->ofp, "%v", (char *) (vam->cmd_reply)); + return ret; +} - out: - if (vam->retval == -99) - errmsg ("timeout"); +int +exec (vat_main_t * vam) +{ + return exec_inband (vam); +} - if (vam->async_errors > 0) - { - errmsg ("%d asynchronous errors", vam->async_errors); - vam->retval = -98; - } - vam->async_errors = 0; - after = vat_time_now (vam); +static int +api_create_loopback (vat_main_t * vam) +{ + unformat_input_t *i = vam->input; + vl_api_create_loopback_t *mp; + vl_api_create_loopback_instance_t *mp_lbi; + u8 mac_address[6]; + u8 mac_set = 0; + u8 is_specified = 0; + u32 user_instance = 0; + int ret; - /* slim chance, but we might have eaten SIGTERM on the first iteration */ - if (j > 0) - count = j; + clib_memset (mac_address, 0, sizeof (mac_address)); - print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec", - count, after - before, count / (after - before)); + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + { + if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) + mac_set = 1; + if (unformat (i, "instance %d", &user_instance)) + is_specified = 1; + else + break; + } + + if (is_specified) + { + M (CREATE_LOOPBACK_INSTANCE, mp_lbi); + mp_lbi->is_specified = is_specified; + if (is_specified) + mp_lbi->user_instance = htonl (user_instance); + if (mac_set) + clib_memcpy (mp_lbi->mac_address, mac_address, sizeof (mac_address)); + S (mp_lbi); } else { - int ret; - - /* Wait for a reply... */ - W (ret); - return ret; + /* Construct the API message */ + M (CREATE_LOOPBACK, mp); + if (mac_set) + clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address)); + S (mp); } - /* Return the good/bad news */ - return (vam->retval); - return (0); + W (ret); + return ret; } static int -api_mpls_ip_bind_unbind (vat_main_t * vam) +api_delete_loopback (vat_main_t * vam) { unformat_input_t *i = vam->input; - vl_api_mpls_ip_bind_unbind_t *mp; - u32 ip_table_id = 0; - u8 is_bind = 1; - vl_api_prefix_t pfx; - u8 prefix_set = 0; - mpls_label_t local_label = MPLS_LABEL_INVALID; + vl_api_delete_loopback_t *mp; + u32 sw_if_index = ~0; int ret; - /* Parse args required to build the message */ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (i, "%U", unformat_vl_api_prefix, &pfx)) - prefix_set = 1; - else if (unformat (i, "%d", &local_label)) - ; - else if (unformat (i, "table-id %d", &ip_table_id)) + if (unformat (i, "sw_if_index %d", &sw_if_index)) ; - else if (unformat (i, "unbind")) - is_bind = 0; - else if (unformat (i, "bind")) - is_bind = 1; else - { - clib_warning ("parse error '%U'", format_unformat_error, i); - return -99; - } - } - - if (!prefix_set) - { - errmsg ("IP prefix not set"); - return -99; + break; } - if (MPLS_LABEL_INVALID == local_label) + if (sw_if_index == ~0) { - errmsg ("missing label"); + errmsg ("missing sw_if_index"); return -99; } /* Construct the API message */ - M (MPLS_IP_BIND_UNBIND, mp); - - mp->mb_is_bind = is_bind; - mp->mb_ip_table_id = ntohl (ip_table_id); - mp->mb_mpls_table_id = 0; - mp->mb_label = ntohl (local_label); - clib_memcpy (&mp->mb_prefix, &pfx, sizeof (pfx)); + M (DELETE_LOOPBACK, mp); + mp->sw_if_index = ntohl (sw_if_index); - /* send it... */ S (mp); - - /* Wait for a reply... */ W (ret); return ret; - return (0); } static int -api_sr_mpls_policy_add (vat_main_t * vam) +api_want_interface_events (vat_main_t * vam) { unformat_input_t *i = vam->input; - vl_api_sr_mpls_policy_add_t *mp; - u32 bsid = 0; - u32 weight = 1; - u8 type = 0; - u8 n_segments = 0; - u32 sid; - u32 *segments = NULL; + vl_api_want_interface_events_t *mp; + int enable = -1; int ret; - /* Parse args required to build the message */ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (i, "bsid %d", &bsid)) - ; - else if (unformat (i, "weight %d", &weight)) - ; - else if (unformat (i, "spray")) - type = 1; - else if (unformat (i, "next %d", &sid)) - { - n_segments += 1; - vec_add1 (segments, htonl (sid)); - } + if (unformat (i, "enable")) + enable = 1; + else if (unformat (i, "disable")) + enable = 0; else - { - clib_warning ("parse error '%U'", format_unformat_error, i); - return -99; - } + break; } - if (bsid == 0) + if (enable == -1) { - errmsg ("bsid not set"); + errmsg ("missing enable|disable"); return -99; } - if (n_segments == 0) - { - errmsg ("no sid in segment stack"); - return -99; - } + M (WANT_INTERFACE_EVENTS, mp); + mp->enable_disable = enable; - /* Construct the API message */ - M2 (SR_MPLS_POLICY_ADD, mp, sizeof (u32) * n_segments); + vam->interface_event_display = enable; - mp->bsid = htonl (bsid); - mp->weight = htonl (weight); - mp->is_spray = type; - mp->n_segments = n_segments; - memcpy (mp->segments, segments, sizeof (u32) * n_segments); - vec_free (segments); + S (mp); + W (ret); + return ret; +} - /* send it... */ + +/* Note: non-static, called once to set up the initial intfc table */ +int +api_sw_interface_dump (vat_main_t * vam) +{ + vl_api_sw_interface_dump_t *mp; + vl_api_control_ping_t *mp_ping; + hash_pair_t *p; + name_sort_t *nses = 0, *ns; + sw_interface_subif_t *sub = NULL; + int ret; + + /* Toss the old name table */ + /* *INDENT-OFF* */ + hash_foreach_pair (p, vam->sw_if_index_by_interface_name, + ({ + vec_add2 (nses, ns, 1); + ns->name = (u8 *)(p->key); + ns->value = (u32) p->value[0]; + })); + /* *INDENT-ON* */ + + hash_free (vam->sw_if_index_by_interface_name); + + vec_foreach (ns, nses) vec_free (ns->name); + + vec_free (nses); + + vec_foreach (sub, vam->sw_if_subif_table) + { + vec_free (sub->interface_name); + } + vec_free (vam->sw_if_subif_table); + + /* recreate the interface name hash table */ + vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword)); + + /* + * Ask for all interface names. Otherwise, the epic catalog of + * name filters becomes ridiculously long, and vat ends up needing + * to be taught about new interface types. + */ + M (SW_INTERFACE_DUMP, mp); S (mp); - /* Wait for a reply... */ + /* Use a control ping for synchronization */ + MPING (CONTROL_PING, mp_ping); + S (mp_ping); + W (ret); return ret; } static int -api_sr_mpls_policy_del (vat_main_t * vam) +api_sw_interface_set_flags (vat_main_t * vam) { unformat_input_t *i = vam->input; - vl_api_sr_mpls_policy_del_t *mp; - u32 bsid = 0; + vl_api_sw_interface_set_flags_t *mp; + u32 sw_if_index; + u8 sw_if_index_set = 0; + u8 admin_up = 0; int ret; /* Parse args required to build the message */ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (i, "bsid %d", &bsid)) - ; + if (unformat (i, "admin-up")) + admin_up = 1; + else if (unformat (i, "admin-down")) + admin_up = 0; else - { - clib_warning ("parse error '%U'", format_unformat_error, i); - return -99; - } + if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) + sw_if_index_set = 1; + else if (unformat (i, "sw_if_index %d", &sw_if_index)) + sw_if_index_set = 1; + else + break; } - if (bsid == 0) + if (sw_if_index_set == 0) { - errmsg ("bsid not set"); + errmsg ("missing interface name or sw_if_index"); return -99; } /* Construct the API message */ - M (SR_MPLS_POLICY_DEL, mp); - - mp->bsid = htonl (bsid); + M (SW_INTERFACE_SET_FLAGS, mp); + mp->sw_if_index = ntohl (sw_if_index); + mp->flags = ntohl ((admin_up) ? IF_STATUS_API_FLAG_ADMIN_UP : 0); /* send it... */ S (mp); - /* Wait for a reply... */ + /* Wait for a reply, return the good/bad news... */ W (ret); return ret; } static int -api_bier_table_add_del (vat_main_t * vam) +api_sw_interface_set_rx_mode (vat_main_t * vam) { unformat_input_t *i = vam->input; - vl_api_bier_table_add_del_t *mp; - u8 is_add = 1; - u32 set = 0, sub_domain = 0, hdr_len = 3; - mpls_label_t local_label = MPLS_LABEL_INVALID; + vl_api_sw_interface_set_rx_mode_t *mp; + u32 sw_if_index; + u8 sw_if_index_set = 0; int ret; + u8 queue_id_valid = 0; + u32 queue_id; + vnet_hw_interface_rx_mode mode = VNET_HW_INTERFACE_RX_MODE_UNKNOWN; /* Parse args required to build the message */ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (i, "sub-domain %d", &sub_domain)) - ; - else if (unformat (i, "set %d", &set)) - ; - else if (unformat (i, "label %d", &local_label)) - ; - else if (unformat (i, "hdr-len %d", &hdr_len)) - ; - else if (unformat (i, "add")) - is_add = 1; - else if (unformat (i, "del")) - is_add = 0; + if (unformat (i, "queue %d", &queue_id)) + queue_id_valid = 1; + else if (unformat (i, "polling")) + mode = VNET_HW_INTERFACE_RX_MODE_POLLING; + else if (unformat (i, "interrupt")) + mode = VNET_HW_INTERFACE_RX_MODE_INTERRUPT; + else if (unformat (i, "adaptive")) + mode = VNET_HW_INTERFACE_RX_MODE_ADAPTIVE; else - { - clib_warning ("parse error '%U'", format_unformat_error, i); - return -99; - } + if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) + sw_if_index_set = 1; + else if (unformat (i, "sw_if_index %d", &sw_if_index)) + sw_if_index_set = 1; + else + break; } - if (MPLS_LABEL_INVALID == local_label) + if (sw_if_index_set == 0) { - errmsg ("missing label\n"); + errmsg ("missing interface name or sw_if_index"); + return -99; + } + if (mode == VNET_HW_INTERFACE_RX_MODE_UNKNOWN) + { + errmsg ("missing rx-mode"); return -99; } /* Construct the API message */ - M (BIER_TABLE_ADD_DEL, mp); - - mp->bt_is_add = is_add; - mp->bt_label = ntohl (local_label); - mp->bt_tbl_id.bt_set = set; - mp->bt_tbl_id.bt_sub_domain = sub_domain; - mp->bt_tbl_id.bt_hdr_len_id = hdr_len; + M (SW_INTERFACE_SET_RX_MODE, mp); + mp->sw_if_index = ntohl (sw_if_index); + mp->mode = (vl_api_rx_mode_t) mode; + mp->queue_id_valid = queue_id_valid; + mp->queue_id = queue_id_valid ? ntohl (queue_id) : ~0; /* send it... */ S (mp); - /* Wait for a reply... */ + /* Wait for a reply, return the good/bad news... */ W (ret); - - return (ret); + return ret; } static int -api_bier_route_add_del (vat_main_t * vam) +api_sw_interface_set_rx_placement (vat_main_t * vam) { unformat_input_t *i = vam->input; - vl_api_bier_route_add_del_t *mp; - u8 is_add = 1; - u32 set = 0, sub_domain = 0, hdr_len = 3, bp = 0; - ip4_address_t v4_next_hop_address; - ip6_address_t v6_next_hop_address; - u8 next_hop_set = 0; - u8 next_hop_proto_is_ip4 = 1; - mpls_label_t next_hop_out_label = MPLS_LABEL_INVALID; + vl_api_sw_interface_set_rx_placement_t *mp; + u32 sw_if_index; + u8 sw_if_index_set = 0; int ret; + u8 is_main = 0; + u32 queue_id, thread_index; /* Parse args required to build the message */ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (i, "%U", unformat_ip4_address, &v4_next_hop_address)) - { - next_hop_proto_is_ip4 = 1; - next_hop_set = 1; - } - else if (unformat (i, "%U", unformat_ip6_address, &v6_next_hop_address)) - { - next_hop_proto_is_ip4 = 0; - next_hop_set = 1; - } - if (unformat (i, "sub-domain %d", &sub_domain)) - ; - else if (unformat (i, "set %d", &set)) - ; - else if (unformat (i, "hdr-len %d", &hdr_len)) - ; - else if (unformat (i, "bp %d", &bp)) + if (unformat (i, "queue %d", &queue_id)) ; - else if (unformat (i, "add")) - is_add = 1; - else if (unformat (i, "del")) - is_add = 0; - else if (unformat (i, "out-label %d", &next_hop_out_label)) + else if (unformat (i, "main")) + is_main = 1; + else if (unformat (i, "worker %d", &thread_index)) ; else - { - clib_warning ("parse error '%U'", format_unformat_error, i); - return -99; - } + if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) + sw_if_index_set = 1; + else if (unformat (i, "sw_if_index %d", &sw_if_index)) + sw_if_index_set = 1; + else + break; } - if (!next_hop_set || (MPLS_LABEL_INVALID == next_hop_out_label)) - { - errmsg ("next hop / label set\n"); - return -99; - } - if (0 == bp) + if (sw_if_index_set == 0) { - errmsg ("bit=position not set\n"); + errmsg ("missing interface name or sw_if_index"); return -99; } + if (is_main) + thread_index = 0; /* Construct the API message */ - M2 (BIER_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t)); - - mp->br_is_add = is_add; - mp->br_route.br_tbl_id.bt_set = set; - mp->br_route.br_tbl_id.bt_sub_domain = sub_domain; - mp->br_route.br_tbl_id.bt_hdr_len_id = hdr_len; - mp->br_route.br_bp = ntohs (bp); - mp->br_route.br_n_paths = 1; - mp->br_route.br_paths[0].n_labels = 1; - mp->br_route.br_paths[0].label_stack[0].label = ntohl (next_hop_out_label); - mp->br_route.br_paths[0].proto = (next_hop_proto_is_ip4 ? - FIB_API_PATH_NH_PROTO_IP4 : - FIB_API_PATH_NH_PROTO_IP6); - - if (next_hop_proto_is_ip4) - { - clib_memcpy (&mp->br_route.br_paths[0].nh.address.ip4, - &v4_next_hop_address, sizeof (v4_next_hop_address)); - } - else - { - clib_memcpy (&mp->br_route.br_paths[0].nh.address.ip6, - &v6_next_hop_address, sizeof (v6_next_hop_address)); - } + M (SW_INTERFACE_SET_RX_PLACEMENT, mp); + mp->sw_if_index = ntohl (sw_if_index); + mp->worker_id = ntohl (thread_index); + mp->queue_id = ntohl (queue_id); + mp->is_main = is_main; /* send it... */ S (mp); - - /* Wait for a reply... */ + /* Wait for a reply, return the good/bad news... */ W (ret); + return ret; +} - return (ret); +static void vl_api_sw_interface_rx_placement_details_t_handler + (vl_api_sw_interface_rx_placement_details_t * mp) +{ + vat_main_t *vam = &vat_main; + u32 worker_id = ntohl (mp->worker_id); + + print (vam->ofp, + "\n%-11d %-11s %-6d %-5d %-9s", + ntohl (mp->sw_if_index), (worker_id == 0) ? "main" : "worker", + worker_id, ntohl (mp->queue_id), + (mp->mode == + 1) ? "polling" : ((mp->mode == 2) ? "interrupt" : "adaptive")); +} + +static void vl_api_sw_interface_rx_placement_details_t_handler_json + (vl_api_sw_interface_rx_placement_details_t * mp) +{ + vat_main_t *vam = &vat_main; + vat_json_node_t *node = NULL; + + if (VAT_JSON_ARRAY != vam->json_tree.type) + { + ASSERT (VAT_JSON_NONE == vam->json_tree.type); + vat_json_init_array (&vam->json_tree); + } + node = vat_json_array_add (&vam->json_tree); + + vat_json_init_object (node); + vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index)); + vat_json_object_add_uint (node, "worker_id", ntohl (mp->worker_id)); + vat_json_object_add_uint (node, "queue_id", ntohl (mp->queue_id)); + vat_json_object_add_uint (node, "mode", mp->mode); } static int -api_mpls_tunnel_add_del (vat_main_t * vam) +api_sw_interface_rx_placement_dump (vat_main_t * vam) { unformat_input_t *i = vam->input; - vl_api_mpls_tunnel_add_del_t *mp; - - vl_api_fib_path_t paths[8]; - u32 sw_if_index = ~0; - u8 path_count = 0; - u8 l2_only = 0; - u8 is_add = 1; + vl_api_sw_interface_rx_placement_dump_t *mp; + vl_api_control_ping_t *mp_ping; int ret; + u32 sw_if_index; + u8 sw_if_index_set = 0; while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (i, "add")) - is_add = 1; - else - if (unformat - (i, "del %U", api_unformat_sw_if_index, vam, &sw_if_index)) - is_add = 0; - else if (unformat (i, "del sw_if_index %d", &sw_if_index)) - is_add = 0; - else if (unformat (i, "l2-only")) - l2_only = 1; - else - if (unformat - (i, "via %U", unformat_fib_path, vam, &paths[path_count])) - { - path_count++; - if (8 == path_count) - { - errmsg ("max 8 paths"); - return -99; - } - } + if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) + sw_if_index_set++; + else if (unformat (i, "sw_if_index %d", &sw_if_index)) + sw_if_index_set++; else - { - clib_warning ("parse error '%U'", format_unformat_error, i); - return -99; - } + break; } - M2 (MPLS_TUNNEL_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count); + print (vam->ofp, + "\n%-11s %-11s %-6s %-5s %-4s", + "sw_if_index", "main/worker", "thread", "queue", "mode"); - mp->mt_is_add = is_add; - mp->mt_tunnel.mt_sw_if_index = ntohl (sw_if_index); - mp->mt_tunnel.mt_l2_only = l2_only; - mp->mt_tunnel.mt_is_multicast = 0; - mp->mt_tunnel.mt_n_paths = path_count; + /* Dump Interface rx placement */ + M (SW_INTERFACE_RX_PLACEMENT_DUMP, mp); - clib_memcpy (&mp->mt_tunnel.mt_paths, &paths, - sizeof (paths[0]) * path_count); + if (sw_if_index_set) + mp->sw_if_index = htonl (sw_if_index); + else + mp->sw_if_index = ~0; S (mp); + + /* Use a control ping for synchronization */ + MPING (CONTROL_PING, mp_ping); + S (mp_ping); + W (ret); return ret; } static int -api_sw_interface_set_unnumbered (vat_main_t * vam) +api_sw_interface_clear_stats (vat_main_t * vam) { unformat_input_t *i = vam->input; - vl_api_sw_interface_set_unnumbered_t *mp; + vl_api_sw_interface_clear_stats_t *mp; u32 sw_if_index; - u32 unnum_sw_index = ~0; - u8 is_add = 1; u8 sw_if_index_set = 0; int ret; + /* Parse args required to build the message */ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) sw_if_index_set = 1; else if (unformat (i, "sw_if_index %d", &sw_if_index)) sw_if_index_set = 1; - else if (unformat (i, "unnum_if_index %d", &unnum_sw_index)) - ; - else if (unformat (i, "del")) - is_add = 0; else - { - clib_warning ("parse error '%U'", format_unformat_error, i); - return -99; - } - } - - if (sw_if_index_set == 0) - { - errmsg ("missing interface name or sw_if_index"); - return -99; + break; } - M (SW_INTERFACE_SET_UNNUMBERED, mp); + /* Construct the API message */ + M (SW_INTERFACE_CLEAR_STATS, mp); - mp->sw_if_index = ntohl (sw_if_index); - mp->unnumbered_sw_if_index = ntohl (unnum_sw_index); - mp->is_add = is_add; + if (sw_if_index_set == 1) + mp->sw_if_index = ntohl (sw_if_index); + else + mp->sw_if_index = ~0; + /* send it... */ S (mp); + + /* Wait for a reply, return the good/bad news... */ W (ret); return ret; } - static int -api_create_vlan_subif (vat_main_t * vam) +api_sw_interface_add_del_address (vat_main_t * vam) { unformat_input_t *i = vam->input; - vl_api_create_vlan_subif_t *mp; + vl_api_sw_interface_add_del_address_t *mp; u32 sw_if_index; u8 sw_if_index_set = 0; - u32 vlan_id; - u8 vlan_id_set = 0; + u8 is_add = 1, del_all = 0; + u32 address_length = 0; + u8 v4_address_set = 0; + u8 v6_address_set = 0; + ip4_address_t v4address; + ip6_address_t v6address; int ret; + /* Parse args required to build the message */ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (i, "sw_if_index %d", &sw_if_index)) - sw_if_index_set = 1; + if (unformat (i, "del-all")) + del_all = 1; + else if (unformat (i, "del")) + is_add = 0; else if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) sw_if_index_set = 1; - else if (unformat (i, "vlan %d", &vlan_id)) - vlan_id_set = 1; + else if (unformat (i, "sw_if_index %d", &sw_if_index)) + sw_if_index_set = 1; + else if (unformat (i, "%U/%d", + unformat_ip4_address, &v4address, &address_length)) + v4_address_set = 1; + else if (unformat (i, "%U/%d", + unformat_ip6_address, &v6address, &address_length)) + v6_address_set = 1; else - { - clib_warning ("parse error '%U'", format_unformat_error, i); - return -99; - } + break; } if (sw_if_index_set == 0) @@ -8945,86 +4240,66 @@ api_create_vlan_subif (vat_main_t * vam) errmsg ("missing interface name or sw_if_index"); return -99; } - - if (vlan_id_set == 0) + if (v4_address_set && v6_address_set) { - errmsg ("missing vlan_id"); + errmsg ("both v4 and v6 addresses set"); return -99; } - M (CREATE_VLAN_SUBIF, mp); + if (!v4_address_set && !v6_address_set && !del_all) + { + errmsg ("no addresses set"); + return -99; + } + + /* Construct the API message */ + M (SW_INTERFACE_ADD_DEL_ADDRESS, mp); mp->sw_if_index = ntohl (sw_if_index); - mp->vlan_id = ntohl (vlan_id); + mp->is_add = is_add; + mp->del_all = del_all; + if (v6_address_set) + { + mp->prefix.address.af = ADDRESS_IP6; + clib_memcpy (mp->prefix.address.un.ip6, &v6address, sizeof (v6address)); + } + else + { + mp->prefix.address.af = ADDRESS_IP4; + clib_memcpy (mp->prefix.address.un.ip4, &v4address, sizeof (v4address)); + } + mp->prefix.len = address_length; + /* send it... */ S (mp); + + /* Wait for a reply, return good/bad news */ W (ret); return ret; } -#define foreach_create_subif_bit \ -_(no_tags) \ -_(one_tag) \ -_(two_tags) \ -_(dot1ad) \ -_(exact_match) \ -_(default_sub) \ -_(outer_vlan_id_any) \ -_(inner_vlan_id_any) - -#define foreach_create_subif_flag \ -_(0, "no_tags") \ -_(1, "one_tag") \ -_(2, "two_tags") \ -_(3, "dot1ad") \ -_(4, "exact_match") \ -_(5, "default_sub") \ -_(6, "outer_vlan_id_any") \ -_(7, "inner_vlan_id_any") - static int -api_create_subif (vat_main_t * vam) +api_sw_interface_set_mpls_enable (vat_main_t * vam) { unformat_input_t *i = vam->input; - vl_api_create_subif_t *mp; + vl_api_sw_interface_set_mpls_enable_t *mp; u32 sw_if_index; u8 sw_if_index_set = 0; - u32 sub_id; - u8 sub_id_set = 0; - u32 __attribute__ ((unused)) no_tags = 0; - u32 __attribute__ ((unused)) one_tag = 0; - u32 __attribute__ ((unused)) two_tags = 0; - u32 __attribute__ ((unused)) dot1ad = 0; - u32 __attribute__ ((unused)) exact_match = 0; - u32 __attribute__ ((unused)) default_sub = 0; - u32 __attribute__ ((unused)) outer_vlan_id_any = 0; - u32 __attribute__ ((unused)) inner_vlan_id_any = 0; - u32 tmp; - u16 outer_vlan_id = 0; - u16 inner_vlan_id = 0; + u8 enable = 1; int ret; + /* Parse args required to build the message */ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (i, "sw_if_index %d", &sw_if_index)) + if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) sw_if_index_set = 1; - else - if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) + else if (unformat (i, "sw_if_index %d", &sw_if_index)) sw_if_index_set = 1; - else if (unformat (i, "sub_id %d", &sub_id)) - sub_id_set = 1; - else if (unformat (i, "outer_vlan_id %d", &tmp)) - outer_vlan_id = tmp; - else if (unformat (i, "inner_vlan_id %d", &tmp)) - inner_vlan_id = tmp; - -#define _(a) else if (unformat (i, #a)) a = 1 ; - foreach_create_subif_bit -#undef _ - else - { - clib_warning ("parse error '%U'", format_unformat_error, i); - return -99; - } + else if (unformat (i, "disable")) + enable = 0; + else if (unformat (i, "dis")) + enable = 0; + else + break; } if (sw_if_index_set == 0) @@ -9033,118 +4308,126 @@ api_create_subif (vat_main_t * vam) return -99; } - if (sub_id_set == 0) - { - errmsg ("missing sub_id"); - return -99; - } - M (CREATE_SUBIF, mp); + /* Construct the API message */ + M (SW_INTERFACE_SET_MPLS_ENABLE, mp); mp->sw_if_index = ntohl (sw_if_index); - mp->sub_id = ntohl (sub_id); - -#define _(a,b) mp->sub_if_flags |= (1 << a); - foreach_create_subif_flag; -#undef _ - - mp->outer_vlan_id = ntohs (outer_vlan_id); - mp->inner_vlan_id = ntohs (inner_vlan_id); + mp->enable = enable; + /* send it... */ S (mp); + + /* Wait for a reply... */ W (ret); return ret; } static int -api_ip_table_replace_begin (vat_main_t * vam) +api_sw_interface_set_table (vat_main_t * vam) { unformat_input_t *i = vam->input; - vl_api_ip_table_replace_begin_t *mp; - u32 table_id = 0; + vl_api_sw_interface_set_table_t *mp; + u32 sw_if_index, vrf_id = 0; + u8 sw_if_index_set = 0; u8 is_ipv6 = 0; - int ret; + + /* Parse args required to build the message */ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (i, "table %d", &table_id)) + if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) + sw_if_index_set = 1; + else if (unformat (i, "sw_if_index %d", &sw_if_index)) + sw_if_index_set = 1; + else if (unformat (i, "vrf %d", &vrf_id)) ; else if (unformat (i, "ipv6")) is_ipv6 = 1; else - { - clib_warning ("parse error '%U'", format_unformat_error, i); - return -99; - } + break; } - M (IP_TABLE_REPLACE_BEGIN, mp); - - mp->table.table_id = ntohl (table_id); - mp->table.is_ip6 = is_ipv6; - - S (mp); - W (ret); - return ret; -} - -static int -api_ip_table_flush (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_ip_table_flush_t *mp; - u32 table_id = 0; - u8 is_ipv6 = 0; - - int ret; - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + if (sw_if_index_set == 0) { - if (unformat (i, "table %d", &table_id)) - ; - else if (unformat (i, "ipv6")) - is_ipv6 = 1; - else - { - clib_warning ("parse error '%U'", format_unformat_error, i); - return -99; - } + errmsg ("missing interface name or sw_if_index"); + return -99; } - M (IP_TABLE_FLUSH, mp); + /* Construct the API message */ + M (SW_INTERFACE_SET_TABLE, mp); - mp->table.table_id = ntohl (table_id); - mp->table.is_ip6 = is_ipv6; + mp->sw_if_index = ntohl (sw_if_index); + mp->is_ipv6 = is_ipv6; + mp->vrf_id = ntohl (vrf_id); + /* send it... */ S (mp); + + /* Wait for a reply... */ W (ret); return ret; } +static void vl_api_sw_interface_get_table_reply_t_handler + (vl_api_sw_interface_get_table_reply_t * mp) +{ + vat_main_t *vam = &vat_main; + + print (vam->ofp, "%d", ntohl (mp->vrf_id)); + + vam->retval = ntohl (mp->retval); + vam->result_ready = 1; + +} + +static void vl_api_sw_interface_get_table_reply_t_handler_json + (vl_api_sw_interface_get_table_reply_t * mp) +{ + vat_main_t *vam = &vat_main; + vat_json_node_t node; + + vat_json_init_object (&node); + vat_json_object_add_int (&node, "retval", ntohl (mp->retval)); + vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id)); + + vat_json_print (vam->ofp, &node); + vat_json_free (&node); + + vam->retval = ntohl (mp->retval); + vam->result_ready = 1; +} + static int -api_ip_table_replace_end (vat_main_t * vam) +api_sw_interface_get_table (vat_main_t * vam) { unformat_input_t *i = vam->input; - vl_api_ip_table_replace_end_t *mp; - u32 table_id = 0; + vl_api_sw_interface_get_table_t *mp; + u32 sw_if_index; + u8 sw_if_index_set = 0; u8 is_ipv6 = 0; - int ret; + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (i, "table %d", &table_id)) - ; + if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) + sw_if_index_set = 1; + else if (unformat (i, "sw_if_index %d", &sw_if_index)) + sw_if_index_set = 1; else if (unformat (i, "ipv6")) is_ipv6 = 1; else - { - clib_warning ("parse error '%U'", format_unformat_error, i); - return -99; - } + break; } - M (IP_TABLE_REPLACE_END, mp); + if (sw_if_index_set == 0) + { + errmsg ("missing interface name or sw_if_index"); + return -99; + } - mp->table.table_id = ntohl (table_id); - mp->table.is_ip6 = is_ipv6; + M (SW_INTERFACE_GET_TABLE, mp); + mp->sw_if_index = htonl (sw_if_index); + mp->is_ipv6 = is_ipv6; S (mp); W (ret); @@ -9152,78 +4435,62 @@ api_ip_table_replace_end (vat_main_t * vam) } static int -api_set_ip_flow_hash (vat_main_t * vam) +api_sw_interface_set_vpath (vat_main_t * vam) { unformat_input_t *i = vam->input; - vl_api_set_ip_flow_hash_t *mp; - u32 vrf_id = 0; - u8 is_ipv6 = 0; - u8 vrf_id_set = 0; - u8 src = 0; - u8 dst = 0; - u8 sport = 0; - u8 dport = 0; - u8 proto = 0; - u8 reverse = 0; + vl_api_sw_interface_set_vpath_t *mp; + u32 sw_if_index = 0; + u8 sw_if_index_set = 0; + u8 is_enable = 0; int ret; + /* Parse args required to build the message */ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (i, "vrf %d", &vrf_id)) - vrf_id_set = 1; - else if (unformat (i, "ipv6")) - is_ipv6 = 1; - else if (unformat (i, "src")) - src = 1; - else if (unformat (i, "dst")) - dst = 1; - else if (unformat (i, "sport")) - sport = 1; - else if (unformat (i, "dport")) - dport = 1; - else if (unformat (i, "proto")) - proto = 1; - else if (unformat (i, "reverse")) - reverse = 1; - + if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) + sw_if_index_set = 1; + else if (unformat (i, "sw_if_index %d", &sw_if_index)) + sw_if_index_set = 1; + else if (unformat (i, "enable")) + is_enable = 1; + else if (unformat (i, "disable")) + is_enable = 0; else - { - clib_warning ("parse error '%U'", format_unformat_error, i); - return -99; - } + break; } - if (vrf_id_set == 0) + if (sw_if_index_set == 0) { - errmsg ("missing vrf id"); + errmsg ("missing interface name or sw_if_index"); return -99; } - M (SET_IP_FLOW_HASH, mp); - mp->src = src; - mp->dst = dst; - mp->sport = sport; - mp->dport = dport; - mp->proto = proto; - mp->reverse = reverse; - mp->vrf_id = ntohl (vrf_id); - mp->is_ipv6 = is_ipv6; + /* Construct the API message */ + M (SW_INTERFACE_SET_VPATH, mp); + + mp->sw_if_index = ntohl (sw_if_index); + mp->enable = is_enable; + /* send it... */ S (mp); + + /* Wait for a reply... */ W (ret); return ret; } static int -api_sw_interface_ip6_enable_disable (vat_main_t * vam) +api_sw_interface_set_vxlan_bypass (vat_main_t * vam) { unformat_input_t *i = vam->input; - vl_api_sw_interface_ip6_enable_disable_t *mp; - u32 sw_if_index; + vl_api_sw_interface_set_vxlan_bypass_t *mp; + u32 sw_if_index = 0; u8 sw_if_index_set = 0; - u8 enable = 0; + u8 is_enable = 1; + u8 is_ipv6 = 0; int ret; + /* Parse args required to build the message */ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) @@ -9231,14 +4498,15 @@ api_sw_interface_ip6_enable_disable (vat_main_t * vam) else if (unformat (i, "sw_if_index %d", &sw_if_index)) sw_if_index_set = 1; else if (unformat (i, "enable")) - enable = 1; + is_enable = 1; else if (unformat (i, "disable")) - enable = 0; + is_enable = 0; + else if (unformat (i, "ip4")) + is_ipv6 = 0; + else if (unformat (i, "ip6")) + is_ipv6 = 1; else - { - clib_warning ("parse error '%U'", format_unformat_error, i); - return -99; - } + break; } if (sw_if_index_set == 0) @@ -9247,27 +4515,31 @@ api_sw_interface_ip6_enable_disable (vat_main_t * vam) return -99; } - M (SW_INTERFACE_IP6_ENABLE_DISABLE, mp); + /* Construct the API message */ + M (SW_INTERFACE_SET_VXLAN_BYPASS, mp); mp->sw_if_index = ntohl (sw_if_index); - mp->enable = enable; + mp->enable = is_enable; + mp->is_ipv6 = is_ipv6; + /* send it... */ S (mp); + + /* Wait for a reply... */ W (ret); return ret; } - static int -api_l2_patch_add_del (vat_main_t * vam) +api_sw_interface_set_l2_xconnect (vat_main_t * vam) { unformat_input_t *i = vam->input; - vl_api_l2_patch_add_del_t *mp; + vl_api_sw_interface_set_l2_xconnect_t *mp; u32 rx_sw_if_index; u8 rx_sw_if_index_set = 0; u32 tx_sw_if_index; u8 tx_sw_if_index_set = 0; - u8 is_add = 1; + u8 enable = 1; int ret; /* Parse args required to build the message */ @@ -9299,8 +4571,10 @@ api_l2_patch_add_del (vat_main_t * vam) else break; } - else if (unformat (i, "del")) - is_add = 0; + else if (unformat (i, "enable")) + enable = 1; + else if (unformat (i, "disable")) + enable = 0; else break; } @@ -9311,79 +4585,83 @@ api_l2_patch_add_del (vat_main_t * vam) return -99; } - if (tx_sw_if_index_set == 0) + if (enable && (tx_sw_if_index_set == 0)) { errmsg ("missing tx interface name or tx_sw_if_index"); return -99; } - M (L2_PATCH_ADD_DEL, mp); + M (SW_INTERFACE_SET_L2_XCONNECT, mp); mp->rx_sw_if_index = ntohl (rx_sw_if_index); mp->tx_sw_if_index = ntohl (tx_sw_if_index); - mp->is_add = is_add; + mp->enable = enable; S (mp); W (ret); return ret; } -u8 is_del; -u8 localsid_addr[16]; -u8 end_psp; -u8 behavior; -u32 sw_if_index; -u32 vlan_index; -u32 fib_table; -u8 nh_addr[16]; - static int -api_sr_localsid_add_del (vat_main_t * vam) +api_sw_interface_set_l2_bridge (vat_main_t * vam) { unformat_input_t *i = vam->input; - vl_api_sr_localsid_add_del_t *mp; - - u8 is_del; - ip6_address_t localsid; - u8 end_psp = 0; - u8 behavior = ~0; - u32 sw_if_index; - u32 fib_table = ~(u32) 0; - ip46_address_t nh_addr; - clib_memset (&nh_addr, 0, sizeof (ip46_address_t)); - - bool nexthop_set = 0; - + vl_api_sw_interface_set_l2_bridge_t *mp; + vl_api_l2_port_type_t port_type; + u32 rx_sw_if_index; + u8 rx_sw_if_index_set = 0; + u32 bd_id; + u8 bd_id_set = 0; + u32 shg = 0; + u8 enable = 1; int ret; + port_type = L2_API_PORT_TYPE_NORMAL; + + /* Parse args required to build the message */ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (i, "del")) - is_del = 1; - else if (unformat (i, "address %U", unformat_ip6_address, &localsid)); - else if (unformat (i, "next-hop %U", unformat_ip46_address, &nh_addr)) - nexthop_set = 1; - else if (unformat (i, "behavior %u", &behavior)); - else if (unformat (i, "sw_if_index %u", &sw_if_index)); - else if (unformat (i, "fib-table %u", &fib_table)); - else if (unformat (i, "end.psp %u", &behavior)); + if (unformat (i, "sw_if_index %d", &rx_sw_if_index)) + rx_sw_if_index_set = 1; + else if (unformat (i, "bd_id %d", &bd_id)) + bd_id_set = 1; + else + if (unformat + (i, "%U", api_unformat_sw_if_index, vam, &rx_sw_if_index)) + rx_sw_if_index_set = 1; + else if (unformat (i, "shg %d", &shg)) + ; + else if (unformat (i, "bvi")) + port_type = L2_API_PORT_TYPE_BVI; + else if (unformat (i, "uu-fwd")) + port_type = L2_API_PORT_TYPE_UU_FWD; + else if (unformat (i, "enable")) + enable = 1; + else if (unformat (i, "disable")) + enable = 0; else break; } - M (SR_LOCALSID_ADD_DEL, mp); - - clib_memcpy (mp->localsid, &localsid, sizeof (mp->localsid)); + if (rx_sw_if_index_set == 0) + { + errmsg ("missing rx interface name or sw_if_index"); + return -99; + } - if (nexthop_set) + if (enable && (bd_id_set == 0)) { - clib_memcpy (&mp->nh_addr.un, &nh_addr, sizeof (mp->nh_addr.un)); + errmsg ("missing bridge domain"); + return -99; } - mp->behavior = behavior; - mp->sw_if_index = ntohl (sw_if_index); - mp->fib_table = ntohl (fib_table); - mp->end_psp = end_psp; - mp->is_del = is_del; + + M (SW_INTERFACE_SET_L2_BRIDGE, mp); + + mp->rx_sw_if_index = ntohl (rx_sw_if_index); + mp->bd_id = ntohl (bd_id); + mp->shg = (u8) shg; + mp->port_type = ntohl (port_type); + mp->enable = enable; S (mp); W (ret); @@ -9391,1394 +4669,1314 @@ api_sr_localsid_add_del (vat_main_t * vam) } static int -api_ioam_enable (vat_main_t * vam) +api_bridge_domain_dump (vat_main_t * vam) { - unformat_input_t *input = vam->input; - vl_api_ioam_enable_t *mp; - u32 id = 0; - int has_trace_option = 0; - int has_pot_option = 0; - int has_seqno_option = 0; - int has_analyse_option = 0; + unformat_input_t *i = vam->input; + vl_api_bridge_domain_dump_t *mp; + vl_api_control_ping_t *mp_ping; + u32 bd_id = ~0; int ret; - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + /* Parse args required to build the message */ + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (input, "trace")) - has_trace_option = 1; - else if (unformat (input, "pot")) - has_pot_option = 1; - else if (unformat (input, "seqno")) - has_seqno_option = 1; - else if (unformat (input, "analyse")) - has_analyse_option = 1; + if (unformat (i, "bd_id %d", &bd_id)) + ; else break; } - M (IOAM_ENABLE, mp); - mp->id = htons (id); - mp->seqno = has_seqno_option; - mp->analyse = has_analyse_option; - mp->pot_enable = has_pot_option; - mp->trace_enable = has_trace_option; + M (BRIDGE_DOMAIN_DUMP, mp); + mp->bd_id = ntohl (bd_id); S (mp); - W (ret); - return ret; -} - -static int -api_ioam_disable (vat_main_t * vam) -{ - vl_api_ioam_disable_t *mp; - int ret; + /* Use a control ping for synchronization */ + MPING (CONTROL_PING, mp_ping); + S (mp_ping); - M (IOAM_DISABLE, mp); - S (mp); W (ret); return ret; } -#define foreach_tcp_proto_field \ -_(src_port) \ -_(dst_port) - -#define foreach_udp_proto_field \ -_(src_port) \ -_(dst_port) - -#define foreach_ip4_proto_field \ -_(src_address) \ -_(dst_address) \ -_(tos) \ -_(length) \ -_(fragment_id) \ -_(ttl) \ -_(protocol) \ -_(checksum) - -typedef struct -{ - u16 src_port, dst_port; -} tcpudp_header_t; - -#if VPP_API_TEST_BUILTIN == 0 -uword -unformat_tcp_mask (unformat_input_t * input, va_list * args) +static int +api_bridge_domain_add_del (vat_main_t * vam) { - u8 **maskp = va_arg (*args, u8 **); - u8 *mask = 0; - u8 found_something = 0; - tcp_header_t *tcp; - -#define _(a) u8 a=0; - foreach_tcp_proto_field; -#undef _ + unformat_input_t *i = vam->input; + vl_api_bridge_domain_add_del_t *mp; + u32 bd_id = ~0; + u8 is_add = 1; + u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0; + u8 *bd_tag = NULL; + u32 mac_age = 0; + int ret; - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + /* Parse args required to build the message */ + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (0); -#define _(a) else if (unformat (input, #a)) a=1; - foreach_tcp_proto_field -#undef _ - else + if (unformat (i, "bd_id %d", &bd_id)) + ; + else if (unformat (i, "flood %d", &flood)) + ; + else if (unformat (i, "uu-flood %d", &uu_flood)) + ; + else if (unformat (i, "forward %d", &forward)) + ; + else if (unformat (i, "learn %d", &learn)) + ; + else if (unformat (i, "arp-term %d", &arp_term)) + ; + else if (unformat (i, "mac-age %d", &mac_age)) + ; + else if (unformat (i, "bd-tag %s", &bd_tag)) + ; + else if (unformat (i, "del")) + { + is_add = 0; + flood = uu_flood = forward = learn = 0; + } + else break; } -#define _(a) found_something += a; - foreach_tcp_proto_field; -#undef _ + if (bd_id == ~0) + { + errmsg ("missing bridge domain"); + ret = -99; + goto done; + } - if (found_something == 0) - return 0; + if (mac_age > 255) + { + errmsg ("mac age must be less than 256 "); + ret = -99; + goto done; + } - vec_validate (mask, sizeof (*tcp) - 1); + if ((bd_tag) && (vec_len (bd_tag) > 63)) + { + errmsg ("bd-tag cannot be longer than 63"); + ret = -99; + goto done; + } - tcp = (tcp_header_t *) mask; + M (BRIDGE_DOMAIN_ADD_DEL, mp); -#define _(a) if (a) clib_memset (&tcp->a, 0xff, sizeof (tcp->a)); - foreach_tcp_proto_field; -#undef _ + mp->bd_id = ntohl (bd_id); + mp->flood = flood; + mp->uu_flood = uu_flood; + mp->forward = forward; + mp->learn = learn; + mp->arp_term = arp_term; + mp->is_add = is_add; + mp->mac_age = (u8) mac_age; + if (bd_tag) + { + clib_memcpy (mp->bd_tag, bd_tag, vec_len (bd_tag)); + mp->bd_tag[vec_len (bd_tag)] = 0; + } + S (mp); + W (ret); - *maskp = mask; - return 1; +done: + vec_free (bd_tag); + return ret; } -uword -unformat_udp_mask (unformat_input_t * input, va_list * args) +static int +api_l2fib_flush_bd (vat_main_t * vam) { - u8 **maskp = va_arg (*args, u8 **); - u8 *mask = 0; - u8 found_something = 0; - udp_header_t *udp; - -#define _(a) u8 a=0; - foreach_udp_proto_field; -#undef _ + unformat_input_t *i = vam->input; + vl_api_l2fib_flush_bd_t *mp; + u32 bd_id = ~0; + int ret; - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + /* Parse args required to build the message */ + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (0); -#define _(a) else if (unformat (input, #a)) a=1; - foreach_udp_proto_field -#undef _ - else + if (unformat (i, "bd_id %d", &bd_id)); + else break; } -#define _(a) found_something += a; - foreach_udp_proto_field; -#undef _ - - if (found_something == 0) - return 0; - - vec_validate (mask, sizeof (*udp) - 1); + if (bd_id == ~0) + { + errmsg ("missing bridge domain"); + return -99; + } - udp = (udp_header_t *) mask; + M (L2FIB_FLUSH_BD, mp); -#define _(a) if (a) clib_memset (&udp->a, 0xff, sizeof (udp->a)); - foreach_udp_proto_field; -#undef _ + mp->bd_id = htonl (bd_id); - *maskp = mask; - return 1; + S (mp); + W (ret); + return ret; } -uword -unformat_l4_mask (unformat_input_t * input, va_list * args) +static int +api_l2fib_flush_int (vat_main_t * vam) { - u8 **maskp = va_arg (*args, u8 **); - u16 src_port = 0, dst_port = 0; - tcpudp_header_t *tcpudp; - - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (input, "tcp %U", unformat_tcp_mask, maskp)) - return 1; - else if (unformat (input, "udp %U", unformat_udp_mask, maskp)) - return 1; - else if (unformat (input, "src_port")) - src_port = 0xFFFF; - else if (unformat (input, "dst_port")) - dst_port = 0xFFFF; + unformat_input_t *i = vam->input; + vl_api_l2fib_flush_int_t *mp; + u32 sw_if_index = ~0; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + { + if (unformat (i, "sw_if_index %d", &sw_if_index)); else - return 0; + if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)); + else + break; } - if (!src_port && !dst_port) - return 0; - - u8 *mask = 0; - vec_validate (mask, sizeof (tcpudp_header_t) - 1); + if (sw_if_index == ~0) + { + errmsg ("missing interface name or sw_if_index"); + return -99; + } - tcpudp = (tcpudp_header_t *) mask; - tcpudp->src_port = src_port; - tcpudp->dst_port = dst_port; + M (L2FIB_FLUSH_INT, mp); - *maskp = mask; + mp->sw_if_index = ntohl (sw_if_index); - return 1; + S (mp); + W (ret); + return ret; } -uword -unformat_ip4_mask (unformat_input_t * input, va_list * args) +static int +api_l2fib_add_del (vat_main_t * vam) { - u8 **maskp = va_arg (*args, u8 **); - u8 *mask = 0; - u8 found_something = 0; - ip4_header_t *ip; + unformat_input_t *i = vam->input; + vl_api_l2fib_add_del_t *mp; + f64 timeout; + u8 mac[6] = { 0 }; + u8 mac_set = 0; + u32 bd_id; + u8 bd_id_set = 0; + u32 sw_if_index = 0; + u8 sw_if_index_set = 0; + u8 is_add = 1; + u8 static_mac = 0; + u8 filter_mac = 0; + u8 bvi_mac = 0; + int count = 1; + f64 before = 0; + int j; -#define _(a) u8 a=0; - foreach_ip4_proto_field; -#undef _ - u8 version = 0; - u8 hdr_length = 0; + /* Parse args required to build the message */ + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + { + if (unformat (i, "mac %U", unformat_ethernet_address, mac)) + mac_set = 1; + else if (unformat (i, "bd_id %d", &bd_id)) + bd_id_set = 1; + else if (unformat (i, "sw_if_index %d", &sw_if_index)) + sw_if_index_set = 1; + else if (unformat (i, "sw_if")) + { + if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + { + if (unformat + (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) + sw_if_index_set = 1; + } + else + break; + } + else if (unformat (i, "static")) + static_mac = 1; + else if (unformat (i, "filter")) + { + filter_mac = 1; + static_mac = 1; + } + else if (unformat (i, "bvi")) + { + bvi_mac = 1; + static_mac = 1; + } + else if (unformat (i, "del")) + is_add = 0; + else if (unformat (i, "count %d", &count)) + ; + else + break; + } + if (mac_set == 0) + { + errmsg ("missing mac address"); + return -99; + } - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + if (bd_id_set == 0) { - if (unformat (input, "version")) - version = 1; - else if (unformat (input, "hdr_length")) - hdr_length = 1; - else if (unformat (input, "src")) - src_address = 1; - else if (unformat (input, "dst")) - dst_address = 1; - else if (unformat (input, "proto")) - protocol = 1; + errmsg ("missing bridge domain"); + return -99; + } -#define _(a) else if (unformat (input, #a)) a=1; - foreach_ip4_proto_field -#undef _ - else - break; + if (is_add && sw_if_index_set == 0 && filter_mac == 0) + { + errmsg ("missing interface name or sw_if_index"); + return -99; } -#define _(a) found_something += a; - foreach_ip4_proto_field; -#undef _ + if (count > 1) + { + /* Turn on async mode */ + vam->async_mode = 1; + vam->async_errors = 0; + before = vat_time_now (vam); + } - if (found_something == 0) - return 0; + for (j = 0; j < count; j++) + { + M (L2FIB_ADD_DEL, mp); - vec_validate (mask, sizeof (*ip) - 1); + clib_memcpy (mp->mac, mac, 6); + mp->bd_id = ntohl (bd_id); + mp->is_add = is_add; + mp->sw_if_index = ntohl (sw_if_index); - ip = (ip4_header_t *) mask; + if (is_add) + { + mp->static_mac = static_mac; + mp->filter_mac = filter_mac; + mp->bvi_mac = bvi_mac; + } + increment_mac_address (mac); + /* send it... */ + S (mp); + } -#define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a)); - foreach_ip4_proto_field; -#undef _ + if (count > 1) + { + vl_api_control_ping_t *mp_ping; + f64 after; - ip->ip_version_and_header_length = 0; + /* Shut off async mode */ + vam->async_mode = 0; - if (version) - ip->ip_version_and_header_length |= 0xF0; + MPING (CONTROL_PING, mp_ping); + S (mp_ping); - if (hdr_length) - ip->ip_version_and_header_length |= 0x0F; + timeout = vat_time_now (vam) + 1.0; + while (vat_time_now (vam) < timeout) + if (vam->result_ready == 1) + goto out; + vam->retval = -99; - *maskp = mask; - return 1; -} + out: + if (vam->retval == -99) + errmsg ("timeout"); -#define foreach_ip6_proto_field \ -_(src_address) \ -_(dst_address) \ -_(payload_length) \ -_(hop_limit) \ -_(protocol) + if (vam->async_errors > 0) + { + errmsg ("%d asynchronous errors", vam->async_errors); + vam->retval = -98; + } + vam->async_errors = 0; + after = vat_time_now (vam); -uword -unformat_ip6_mask (unformat_input_t * input, va_list * args) -{ - u8 **maskp = va_arg (*args, u8 **); - u8 *mask = 0; - u8 found_something = 0; - ip6_header_t *ip; - u32 ip_version_traffic_class_and_flow_label; + print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec", + count, after - before, count / (after - before)); + } + else + { + int ret; -#define _(a) u8 a=0; - foreach_ip6_proto_field; -#undef _ - u8 version = 0; - u8 traffic_class = 0; - u8 flow_label = 0; + /* Wait for a reply... */ + W (ret); + return ret; + } + /* Return the good/bad news */ + return (vam->retval); +} - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (input, "version")) - version = 1; - else if (unformat (input, "traffic-class")) - traffic_class = 1; - else if (unformat (input, "flow-label")) - flow_label = 1; - else if (unformat (input, "src")) - src_address = 1; - else if (unformat (input, "dst")) - dst_address = 1; - else if (unformat (input, "proto")) - protocol = 1; +static int +api_bridge_domain_set_mac_age (vat_main_t * vam) +{ + unformat_input_t *i = vam->input; + vl_api_bridge_domain_set_mac_age_t *mp; + u32 bd_id = ~0; + u32 mac_age = 0; + int ret; -#define _(a) else if (unformat (input, #a)) a=1; - foreach_ip6_proto_field -#undef _ - else + /* Parse args required to build the message */ + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + { + if (unformat (i, "bd_id %d", &bd_id)); + else if (unformat (i, "mac-age %d", &mac_age)); + else break; } -#define _(a) found_something += a; - foreach_ip6_proto_field; -#undef _ - - if (found_something == 0) - return 0; - - vec_validate (mask, sizeof (*ip) - 1); - - ip = (ip6_header_t *) mask; - -#define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a)); - foreach_ip6_proto_field; -#undef _ - - ip_version_traffic_class_and_flow_label = 0; - - if (version) - ip_version_traffic_class_and_flow_label |= 0xF0000000; + if (bd_id == ~0) + { + errmsg ("missing bridge domain"); + return -99; + } - if (traffic_class) - ip_version_traffic_class_and_flow_label |= 0x0FF00000; + if (mac_age > 255) + { + errmsg ("mac age must be less than 256 "); + return -99; + } - if (flow_label) - ip_version_traffic_class_and_flow_label |= 0x000FFFFF; + M (BRIDGE_DOMAIN_SET_MAC_AGE, mp); - ip->ip_version_traffic_class_and_flow_label = - clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label); + mp->bd_id = htonl (bd_id); + mp->mac_age = (u8) mac_age; - *maskp = mask; - return 1; + S (mp); + W (ret); + return ret; } -uword -unformat_l3_mask (unformat_input_t * input, va_list * args) +static int +api_l2_flags (vat_main_t * vam) { - u8 **maskp = va_arg (*args, u8 **); + unformat_input_t *i = vam->input; + vl_api_l2_flags_t *mp; + u32 sw_if_index; + u32 flags = 0; + u8 sw_if_index_set = 0; + u8 is_set = 0; + int ret; - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + /* Parse args required to build the message */ + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp)) - return 1; - else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp)) - return 1; + if (unformat (i, "sw_if_index %d", &sw_if_index)) + sw_if_index_set = 1; + else if (unformat (i, "sw_if")) + { + if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + { + if (unformat + (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) + sw_if_index_set = 1; + } + else + break; + } + else if (unformat (i, "learn")) + flags |= L2_LEARN; + else if (unformat (i, "forward")) + flags |= L2_FWD; + else if (unformat (i, "flood")) + flags |= L2_FLOOD; + else if (unformat (i, "uu-flood")) + flags |= L2_UU_FLOOD; + else if (unformat (i, "arp-term")) + flags |= L2_ARP_TERM; + else if (unformat (i, "off")) + is_set = 0; + else if (unformat (i, "disable")) + is_set = 0; else break; } - return 0; -} - -uword -unformat_l2_mask (unformat_input_t * input, va_list * args) -{ - u8 **maskp = va_arg (*args, u8 **); - u8 *mask = 0; - u8 src = 0; - u8 dst = 0; - u8 proto = 0; - u8 tag1 = 0; - u8 tag2 = 0; - u8 ignore_tag1 = 0; - u8 ignore_tag2 = 0; - u8 cos1 = 0; - u8 cos2 = 0; - u8 dot1q = 0; - u8 dot1ad = 0; - int len = 14; - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + if (sw_if_index_set == 0) { - if (unformat (input, "src")) - src = 1; - else if (unformat (input, "dst")) - dst = 1; - else if (unformat (input, "proto")) - proto = 1; - else if (unformat (input, "tag1")) - tag1 = 1; - else if (unformat (input, "tag2")) - tag2 = 1; - else if (unformat (input, "ignore-tag1")) - ignore_tag1 = 1; - else if (unformat (input, "ignore-tag2")) - ignore_tag2 = 1; - else if (unformat (input, "cos1")) - cos1 = 1; - else if (unformat (input, "cos2")) - cos2 = 1; - else if (unformat (input, "dot1q")) - dot1q = 1; - else if (unformat (input, "dot1ad")) - dot1ad = 1; - else - break; + errmsg ("missing interface name or sw_if_index"); + return -99; } - if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad + - ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0) - return 0; - if (tag1 || ignore_tag1 || cos1 || dot1q) - len = 18; - if (tag2 || ignore_tag2 || cos2 || dot1ad) - len = 22; + M (L2_FLAGS, mp); - vec_validate (mask, len - 1); + mp->sw_if_index = ntohl (sw_if_index); + mp->feature_bitmap = ntohl (flags); + mp->is_set = is_set; - if (dst) - clib_memset (mask, 0xff, 6); + S (mp); + W (ret); + return ret; +} - if (src) - clib_memset (mask + 6, 0xff, 6); +static int +api_bridge_flags (vat_main_t * vam) +{ + unformat_input_t *i = vam->input; + vl_api_bridge_flags_t *mp; + u32 bd_id; + u8 bd_id_set = 0; + u8 is_set = 1; + bd_flags_t flags = 0; + int ret; - if (tag2 || dot1ad) + /* Parse args required to build the message */ + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - /* inner vlan tag */ - if (tag2) - { - mask[19] = 0xff; - mask[18] = 0x0f; - } - if (cos2) - mask[18] |= 0xe0; - if (proto) - mask[21] = mask[20] = 0xff; - if (tag1) - { - mask[15] = 0xff; - mask[14] = 0x0f; - } - if (cos1) - mask[14] |= 0xe0; - *maskp = mask; - return 1; + if (unformat (i, "bd_id %d", &bd_id)) + bd_id_set = 1; + else if (unformat (i, "learn")) + flags |= BRIDGE_API_FLAG_LEARN; + else if (unformat (i, "forward")) + flags |= BRIDGE_API_FLAG_FWD; + else if (unformat (i, "flood")) + flags |= BRIDGE_API_FLAG_FLOOD; + else if (unformat (i, "uu-flood")) + flags |= BRIDGE_API_FLAG_UU_FLOOD; + else if (unformat (i, "arp-term")) + flags |= BRIDGE_API_FLAG_ARP_TERM; + else if (unformat (i, "off")) + is_set = 0; + else if (unformat (i, "disable")) + is_set = 0; + else + break; } - if (tag1 | dot1q) - { - if (tag1) - { - mask[15] = 0xff; - mask[14] = 0x0f; - } - if (cos1) - mask[14] |= 0xe0; - if (proto) - mask[16] = mask[17] = 0xff; - *maskp = mask; - return 1; + if (bd_id_set == 0) + { + errmsg ("missing bridge domain"); + return -99; } - if (cos2) - mask[18] |= 0xe0; - if (cos1) - mask[14] |= 0xe0; - if (proto) - mask[12] = mask[13] = 0xff; - *maskp = mask; - return 1; + M (BRIDGE_FLAGS, mp); + + mp->bd_id = ntohl (bd_id); + mp->flags = ntohl (flags); + mp->is_set = is_set; + + S (mp); + W (ret); + return ret; } -uword -unformat_classify_mask (unformat_input_t * input, va_list * args) -{ - u8 **maskp = va_arg (*args, u8 **); - u32 *skipp = va_arg (*args, u32 *); - u32 *matchp = va_arg (*args, u32 *); - u32 match; - u8 *mask = 0; - u8 *l2 = 0; - u8 *l3 = 0; - u8 *l4 = 0; - int i; +static int +api_bd_ip_mac_add_del (vat_main_t * vam) +{ + vl_api_address_t ip = VL_API_ZERO_ADDRESS; + vl_api_mac_address_t mac = { 0 }; + unformat_input_t *i = vam->input; + vl_api_bd_ip_mac_add_del_t *mp; + u32 bd_id; + u8 is_add = 1; + u8 bd_id_set = 0; + u8 ip_set = 0; + u8 mac_set = 0; + int ret; + - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + /* Parse args required to build the message */ + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (input, "hex %U", unformat_hex_string, &mask)) - ; - else if (unformat (input, "l2 %U", unformat_l2_mask, &l2)) - ; - else if (unformat (input, "l3 %U", unformat_l3_mask, &l3)) - ; - else if (unformat (input, "l4 %U", unformat_l4_mask, &l4)) - ; + if (unformat (i, "bd_id %d", &bd_id)) + { + bd_id_set++; + } + else if (unformat (i, "%U", unformat_vl_api_address, &ip)) + { + ip_set++; + } + else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac)) + { + mac_set++; + } + else if (unformat (i, "del")) + is_add = 0; else break; } - if (l4 && !l3) + if (bd_id_set == 0) { - vec_free (mask); - vec_free (l2); - vec_free (l4); - return 0; + errmsg ("missing bridge domain"); + return -99; } - - if (mask || l2 || l3 || l4) + else if (ip_set == 0) { - if (l2 || l3 || l4) - { - /* "With a free Ethernet header in every package" */ - if (l2 == 0) - vec_validate (l2, 13); - mask = l2; - if (vec_len (l3)) - { - vec_append (mask, l3); - vec_free (l3); - } - if (vec_len (l4)) - { - vec_append (mask, l4); - vec_free (l4); - } - } + errmsg ("missing IP address"); + return -99; + } + else if (mac_set == 0) + { + errmsg ("missing MAC address"); + return -99; + } - /* Scan forward looking for the first significant mask octet */ - for (i = 0; i < vec_len (mask); i++) - if (mask[i]) - break; + M (BD_IP_MAC_ADD_DEL, mp); - /* compute (skip, match) params */ - *skipp = i / sizeof (u32x4); - vec_delete (mask, *skipp * sizeof (u32x4), 0); + mp->entry.bd_id = ntohl (bd_id); + mp->is_add = is_add; - /* Pad mask to an even multiple of the vector size */ - while (vec_len (mask) % sizeof (u32x4)) - vec_add1 (mask, 0); + clib_memcpy (&mp->entry.ip, &ip, sizeof (ip)); + clib_memcpy (&mp->entry.mac, &mac, sizeof (mac)); - match = vec_len (mask) / sizeof (u32x4); + S (mp); + W (ret); + return ret; +} - for (i = match * sizeof (u32x4); i > 0; i -= sizeof (u32x4)) +static int +api_bd_ip_mac_flush (vat_main_t * vam) +{ + unformat_input_t *i = vam->input; + vl_api_bd_ip_mac_flush_t *mp; + u32 bd_id; + u8 bd_id_set = 0; + int ret; + + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + { + if (unformat (i, "bd_id %d", &bd_id)) { - u64 *tmp = (u64 *) (mask + (i - sizeof (u32x4))); - if (*tmp || *(tmp + 1)) - break; - match--; + bd_id_set++; } - if (match == 0) - clib_warning ("BUG: match 0"); + else + break; + } - _vec_len (mask) = match * sizeof (u32x4); + if (bd_id_set == 0) + { + errmsg ("missing bridge domain"); + return -99; + } - *matchp = match; - *maskp = mask; + M (BD_IP_MAC_FLUSH, mp); - return 1; - } + mp->bd_id = ntohl (bd_id); - return 0; + S (mp); + W (ret); + return ret; } -#endif /* VPP_API_TEST_BUILTIN */ - -#define foreach_l2_next \ -_(drop, DROP) \ -_(ethernet, ETHERNET_INPUT) \ -_(ip4, IP4_INPUT) \ -_(ip6, IP6_INPUT) -uword -unformat_l2_next_index (unformat_input_t * input, va_list * args) +static void vl_api_bd_ip_mac_details_t_handler + (vl_api_bd_ip_mac_details_t * mp) { - u32 *miss_next_indexp = va_arg (*args, u32 *); - u32 next_index = 0; - u32 tmp; - -#define _(n,N) \ - if (unformat (input, #n)) { next_index = L2_INPUT_CLASSIFY_NEXT_##N; goto out;} - foreach_l2_next; -#undef _ - - if (unformat (input, "%d", &tmp)) - { - next_index = tmp; - goto out; - } - - return 0; + vat_main_t *vam = &vat_main; -out: - *miss_next_indexp = next_index; - return 1; + print (vam->ofp, + "\n%-5d %U %U", + ntohl (mp->entry.bd_id), + format_vl_api_mac_address, mp->entry.mac, + format_vl_api_address, &mp->entry.ip); } -#define foreach_ip_next \ -_(drop, DROP) \ -_(local, LOCAL) \ -_(rewrite, REWRITE) - -uword -api_unformat_ip_next_index (unformat_input_t * input, va_list * args) +static void vl_api_bd_ip_mac_details_t_handler_json + (vl_api_bd_ip_mac_details_t * mp) { - u32 *miss_next_indexp = va_arg (*args, u32 *); - u32 next_index = 0; - u32 tmp; - -#define _(n,N) \ - if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;} - foreach_ip_next; -#undef _ + vat_main_t *vam = &vat_main; + vat_json_node_t *node = NULL; - if (unformat (input, "%d", &tmp)) + if (VAT_JSON_ARRAY != vam->json_tree.type) { - next_index = tmp; - goto out; + ASSERT (VAT_JSON_NONE == vam->json_tree.type); + vat_json_init_array (&vam->json_tree); } + node = vat_json_array_add (&vam->json_tree); - return 0; + vat_json_init_object (node); + vat_json_object_add_uint (node, "bd_id", ntohl (mp->entry.bd_id)); + vat_json_object_add_string_copy (node, "mac_address", + format (0, "%U", format_vl_api_mac_address, + &mp->entry.mac)); + u8 *ip = 0; -out: - *miss_next_indexp = next_index; - return 1; + ip = format (0, "%U", format_vl_api_address, &mp->entry.ip); + vat_json_object_add_string_copy (node, "ip_address", ip); + vec_free (ip); } -#define foreach_acl_next \ -_(deny, DENY) - -uword -api_unformat_acl_next_index (unformat_input_t * input, va_list * args) +static int +api_bd_ip_mac_dump (vat_main_t * vam) { - u32 *miss_next_indexp = va_arg (*args, u32 *); - u32 next_index = 0; - u32 tmp; - -#define _(n,N) \ - if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;} - foreach_acl_next; -#undef _ + unformat_input_t *i = vam->input; + vl_api_bd_ip_mac_dump_t *mp; + vl_api_control_ping_t *mp_ping; + int ret; + u32 bd_id; + u8 bd_id_set = 0; - if (unformat (input, "permit")) - { - next_index = ~0; - goto out; - } - else if (unformat (input, "%d", &tmp)) + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - next_index = tmp; - goto out; + if (unformat (i, "bd_id %d", &bd_id)) + { + bd_id_set++; + } + else + break; } - return 0; - -out: - *miss_next_indexp = next_index; - return 1; -} - -uword -unformat_policer_precolor (unformat_input_t * input, va_list * args) -{ - u32 *r = va_arg (*args, u32 *); + print (vam->ofp, + "\n%-5s %-7s %-20s %-30s", + "bd_id", "is_ipv6", "mac_address", "ip_address"); - if (unformat (input, "conform-color")) - *r = POLICE_CONFORM; - else if (unformat (input, "exceed-color")) - *r = POLICE_EXCEED; + /* Dump Bridge Domain Ip to Mac entries */ + M (BD_IP_MAC_DUMP, mp); + + if (bd_id_set) + mp->bd_id = htonl (bd_id); else - return 0; + mp->bd_id = ~0; - return 1; + S (mp); + + /* Use a control ping for synchronization */ + MPING (CONTROL_PING, mp_ping); + S (mp_ping); + + W (ret); + return ret; } static int -api_classify_add_del_table (vat_main_t * vam) +api_tap_create_v2 (vat_main_t * vam) { unformat_input_t *i = vam->input; - vl_api_classify_add_del_table_t *mp; - - u32 nbuckets = 2; - u32 skip = ~0; - u32 match = ~0; - int is_add = 1; - int del_chain = 0; - u32 table_index = ~0; - u32 next_table_index = ~0; - u32 miss_next_index = ~0; - u32 memory_size = 32 << 20; - u8 *mask = 0; - u32 current_data_flag = 0; - int current_data_offset = 0; + vl_api_tap_create_v2_t *mp; + u8 mac_address[6]; + u8 random_mac = 1; + u32 id = ~0; + u32 num_rx_queues = 0; + u8 *host_if_name = 0; + u8 host_if_name_set = 0; + u8 *host_ns = 0; + u8 host_ns_set = 0; + u8 host_mac_addr[6]; + u8 host_mac_addr_set = 0; + u8 *host_bridge = 0; + u8 host_bridge_set = 0; + u8 host_ip4_prefix_set = 0; + u8 host_ip6_prefix_set = 0; + ip4_address_t host_ip4_addr; + ip4_address_t host_ip4_gw; + u8 host_ip4_gw_set = 0; + u32 host_ip4_prefix_len = 0; + ip6_address_t host_ip6_addr; + ip6_address_t host_ip6_gw; + u8 host_ip6_gw_set = 0; + u32 host_ip6_prefix_len = 0; + u32 host_mtu_size = 0; + u8 host_mtu_set = 0; + u32 tap_flags = 0; int ret; + u32 rx_ring_sz = 0, tx_ring_sz = 0; + clib_memset (mac_address, 0, sizeof (mac_address)); + + /* Parse args required to build the message */ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (i, "del")) - is_add = 0; - else if (unformat (i, "del-chain")) - { - is_add = 0; - del_chain = 1; - } - else if (unformat (i, "buckets %d", &nbuckets)) - ; - else if (unformat (i, "memory_size %d", &memory_size)) - ; - else if (unformat (i, "skip %d", &skip)) - ; - else if (unformat (i, "match %d", &match)) - ; - else if (unformat (i, "table %d", &table_index)) - ; - else if (unformat (i, "mask %U", unformat_classify_mask, - &mask, &skip, &match)) - ; - else if (unformat (i, "next-table %d", &next_table_index)) - ; - else if (unformat (i, "miss-next %U", api_unformat_ip_next_index, - &miss_next_index)) - ; - else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index, - &miss_next_index)) + if (unformat (i, "id %u", &id)) ; - else if (unformat (i, "acl-miss-next %U", api_unformat_acl_next_index, - &miss_next_index)) + else + if (unformat + (i, "hw-addr %U", unformat_ethernet_address, mac_address)) + random_mac = 0; + else if (unformat (i, "host-if-name %s", &host_if_name)) + host_if_name_set = 1; + else if (unformat (i, "num-rx-queues %u", &num_rx_queues)) ; - else if (unformat (i, "current-data-flag %d", ¤t_data_flag)) + else if (unformat (i, "host-ns %s", &host_ns)) + host_ns_set = 1; + else if (unformat (i, "host-mac-addr %U", unformat_ethernet_address, + host_mac_addr)) + host_mac_addr_set = 1; + else if (unformat (i, "host-bridge %s", &host_bridge)) + host_bridge_set = 1; + else if (unformat (i, "host-ip4-addr %U/%u", unformat_ip4_address, + &host_ip4_addr, &host_ip4_prefix_len)) + host_ip4_prefix_set = 1; + else if (unformat (i, "host-ip6-addr %U/%u", unformat_ip6_address, + &host_ip6_addr, &host_ip6_prefix_len)) + host_ip6_prefix_set = 1; + else if (unformat (i, "host-ip4-gw %U", unformat_ip4_address, + &host_ip4_gw)) + host_ip4_gw_set = 1; + else if (unformat (i, "host-ip6-gw %U", unformat_ip6_address, + &host_ip6_gw)) + host_ip6_gw_set = 1; + else if (unformat (i, "rx-ring-size %u", &rx_ring_sz)) ; - else if (unformat (i, "current-data-offset %d", ¤t_data_offset)) + else if (unformat (i, "tx-ring-size %u", &tx_ring_sz)) ; + else if (unformat (i, "host-mtu-size %u", &host_mtu_size)) + host_mtu_set = 1; + else if (unformat (i, "no-gso")) + tap_flags &= ~TAP_API_FLAG_GSO; + else if (unformat (i, "gso")) + tap_flags |= TAP_API_FLAG_GSO; + else if (unformat (i, "csum-offload")) + tap_flags |= TAP_API_FLAG_CSUM_OFFLOAD; + else if (unformat (i, "persist")) + tap_flags |= TAP_API_FLAG_PERSIST; + else if (unformat (i, "attach")) + tap_flags |= TAP_API_FLAG_ATTACH; + else if (unformat (i, "tun")) + tap_flags |= TAP_API_FLAG_TUN; + else if (unformat (i, "gro-coalesce")) + tap_flags |= TAP_API_FLAG_GRO_COALESCE; + else if (unformat (i, "packed")) + tap_flags |= TAP_API_FLAG_PACKED; + else if (unformat (i, "in-order")) + tap_flags |= TAP_API_FLAG_IN_ORDER; else break; } - if (is_add && mask == 0) + if (vec_len (host_if_name) > 63) { - errmsg ("Mask required"); + errmsg ("tap name too long. "); return -99; } - - if (is_add && skip == ~0) + if (vec_len (host_ns) > 63) { - errmsg ("skip count required"); + errmsg ("host name space too long. "); return -99; } - - if (is_add && match == ~0) + if (vec_len (host_bridge) > 63) { - errmsg ("match count required"); + errmsg ("host bridge name too long. "); return -99; } - - if (!is_add && table_index == ~0) + if (host_ip4_prefix_len > 32) { - errmsg ("table index required for delete"); + errmsg ("host ip4 prefix length not valid. "); + return -99; + } + if (host_ip6_prefix_len > 128) + { + errmsg ("host ip6 prefix length not valid. "); + return -99; + } + if (!is_pow2 (rx_ring_sz)) + { + errmsg ("rx ring size must be power of 2. "); + return -99; + } + if (rx_ring_sz > 32768) + { + errmsg ("rx ring size must be 32768 or lower. "); + return -99; + } + if (!is_pow2 (tx_ring_sz)) + { + errmsg ("tx ring size must be power of 2. "); + return -99; + } + if (tx_ring_sz > 32768) + { + errmsg ("tx ring size must be 32768 or lower. "); + return -99; + } + if (host_mtu_set && (host_mtu_size < 64 || host_mtu_size > 65355)) + { + errmsg ("host MTU size must be in between 64 and 65355. "); return -99; } - M2 (CLASSIFY_ADD_DEL_TABLE, mp, vec_len (mask)); - - mp->is_add = is_add; - mp->del_chain = del_chain; - mp->table_index = ntohl (table_index); - mp->nbuckets = ntohl (nbuckets); - mp->memory_size = ntohl (memory_size); - mp->skip_n_vectors = ntohl (skip); - mp->match_n_vectors = ntohl (match); - mp->next_table_index = ntohl (next_table_index); - mp->miss_next_index = ntohl (miss_next_index); - mp->current_data_flag = ntohl (current_data_flag); - mp->current_data_offset = ntohl (current_data_offset); - mp->mask_len = ntohl (vec_len (mask)); - clib_memcpy (mp->mask, mask, vec_len (mask)); - - vec_free (mask); - - S (mp); - W (ret); - return ret; -} - -#if VPP_API_TEST_BUILTIN == 0 -uword -unformat_l4_match (unformat_input_t * input, va_list * args) -{ - u8 **matchp = va_arg (*args, u8 **); - - u8 *proto_header = 0; - int src_port = 0; - int dst_port = 0; + /* Construct the API message */ + M (TAP_CREATE_V2, mp); - tcpudp_header_t h; + mp->id = ntohl (id); + mp->use_random_mac = random_mac; + mp->num_rx_queues = (u8) num_rx_queues; + mp->tx_ring_sz = ntohs (tx_ring_sz); + mp->rx_ring_sz = ntohs (rx_ring_sz); + mp->host_mtu_set = host_mtu_set; + mp->host_mtu_size = ntohl (host_mtu_size); + mp->host_mac_addr_set = host_mac_addr_set; + mp->host_ip4_prefix_set = host_ip4_prefix_set; + mp->host_ip6_prefix_set = host_ip6_prefix_set; + mp->host_ip4_gw_set = host_ip4_gw_set; + mp->host_ip6_gw_set = host_ip6_gw_set; + mp->tap_flags = ntohl (tap_flags); + mp->host_namespace_set = host_ns_set; + mp->host_if_name_set = host_if_name_set; + mp->host_bridge_set = host_bridge_set; - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + if (random_mac == 0) + clib_memcpy (mp->mac_address, mac_address, 6); + if (host_mac_addr_set) + clib_memcpy (mp->host_mac_addr, host_mac_addr, 6); + if (host_if_name_set) + clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name)); + if (host_ns_set) + clib_memcpy (mp->host_namespace, host_ns, vec_len (host_ns)); + if (host_bridge_set) + clib_memcpy (mp->host_bridge, host_bridge, vec_len (host_bridge)); + if (host_ip4_prefix_set) { - if (unformat (input, "src_port %d", &src_port)) - ; - else if (unformat (input, "dst_port %d", &dst_port)) - ; - else - return 0; + clib_memcpy (mp->host_ip4_prefix.address, &host_ip4_addr, 4); + mp->host_ip4_prefix.len = (u8) host_ip4_prefix_len; + } + if (host_ip6_prefix_set) + { + clib_memcpy (mp->host_ip6_prefix.address, &host_ip6_addr, 16); + mp->host_ip6_prefix.len = (u8) host_ip6_prefix_len; } + if (host_ip4_gw_set) + clib_memcpy (mp->host_ip4_gw, &host_ip4_gw, 4); + if (host_ip6_gw_set) + clib_memcpy (mp->host_ip6_gw, &host_ip6_gw, 16); - h.src_port = clib_host_to_net_u16 (src_port); - h.dst_port = clib_host_to_net_u16 (dst_port); - vec_validate (proto_header, sizeof (h) - 1); - memcpy (proto_header, &h, sizeof (h)); + vec_free (host_ns); + vec_free (host_if_name); + vec_free (host_bridge); - *matchp = proto_header; + /* send it... */ + S (mp); - return 1; + /* Wait for a reply... */ + W (ret); + return ret; } -uword -unformat_ip4_match (unformat_input_t * input, va_list * args) +static int +api_tap_delete_v2 (vat_main_t * vam) { - u8 **matchp = va_arg (*args, u8 **); - u8 *match = 0; - ip4_header_t *ip; - int version = 0; - u32 version_val; - int hdr_length = 0; - u32 hdr_length_val; - int src = 0, dst = 0; - ip4_address_t src_val, dst_val; - int proto = 0; - u32 proto_val; - int tos = 0; - u32 tos_val; - int length = 0; - u32 length_val; - int fragment_id = 0; - u32 fragment_id_val; - int ttl = 0; - int ttl_val; - int checksum = 0; - u32 checksum_val; + unformat_input_t *i = vam->input; + vl_api_tap_delete_v2_t *mp; + u32 sw_if_index = ~0; + u8 sw_if_index_set = 0; + int ret; - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + /* Parse args required to build the message */ + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (input, "version %d", &version_val)) - version = 1; - else if (unformat (input, "hdr_length %d", &hdr_length_val)) - hdr_length = 1; - else if (unformat (input, "src %U", unformat_ip4_address, &src_val)) - src = 1; - else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val)) - dst = 1; - else if (unformat (input, "proto %d", &proto_val)) - proto = 1; - else if (unformat (input, "tos %d", &tos_val)) - tos = 1; - else if (unformat (input, "length %d", &length_val)) - length = 1; - else if (unformat (input, "fragment_id %d", &fragment_id_val)) - fragment_id = 1; - else if (unformat (input, "ttl %d", &ttl_val)) - ttl = 1; - else if (unformat (input, "checksum %d", &checksum_val)) - checksum = 1; + if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) + sw_if_index_set = 1; + else if (unformat (i, "sw_if_index %d", &sw_if_index)) + sw_if_index_set = 1; else break; } - if (version + hdr_length + src + dst + proto + tos + length + fragment_id - + ttl + checksum == 0) - return 0; - - /* - * Aligned because we use the real comparison functions - */ - vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4)); - - ip = (ip4_header_t *) match; - - /* These are realistically matched in practice */ - if (src) - ip->src_address.as_u32 = src_val.as_u32; - - if (dst) - ip->dst_address.as_u32 = dst_val.as_u32; - - if (proto) - ip->protocol = proto_val; + if (sw_if_index_set == 0) + { + errmsg ("missing vpp interface name. "); + return -99; + } + /* Construct the API message */ + M (TAP_DELETE_V2, mp); - /* These are not, but they're included for completeness */ - if (version) - ip->ip_version_and_header_length |= (version_val & 0xF) << 4; + mp->sw_if_index = ntohl (sw_if_index); - if (hdr_length) - ip->ip_version_and_header_length |= (hdr_length_val & 0xF); + /* send it... */ + S (mp); - if (tos) - ip->tos = tos_val; + /* Wait for a reply... */ + W (ret); + return ret; +} - if (length) - ip->length = clib_host_to_net_u16 (length_val); +uword +unformat_vlib_pci_addr (unformat_input_t * input, va_list * args) +{ + vlib_pci_addr_t *addr = va_arg (*args, vlib_pci_addr_t *); + u32 x[4]; - if (ttl) - ip->ttl = ttl_val; + if (!unformat (input, "%x:%x:%x.%x", &x[0], &x[1], &x[2], &x[3])) + return 0; - if (checksum) - ip->checksum = clib_host_to_net_u16 (checksum_val); + addr->domain = x[0]; + addr->bus = x[1]; + addr->slot = x[2]; + addr->function = x[3]; - *matchp = match; return 1; } -uword -unformat_ip6_match (unformat_input_t * input, va_list * args) +static int +api_virtio_pci_create_v2 (vat_main_t * vam) { - u8 **matchp = va_arg (*args, u8 **); - u8 *match = 0; - ip6_header_t *ip; - int version = 0; - u32 version_val; - u8 traffic_class = 0; - u32 traffic_class_val = 0; - u8 flow_label = 0; - u8 flow_label_val; - int src = 0, dst = 0; - ip6_address_t src_val, dst_val; - int proto = 0; - u32 proto_val; - int payload_length = 0; - u32 payload_length_val; - int hop_limit = 0; - int hop_limit_val; - u32 ip_version_traffic_class_and_flow_label; + unformat_input_t *i = vam->input; + vl_api_virtio_pci_create_v2_t *mp; + u8 mac_address[6]; + u8 random_mac = 1; + u32 pci_addr = 0; + u64 features = (u64) ~ (0ULL); + u32 virtio_flags = 0; + int ret; - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + clib_memset (mac_address, 0, sizeof (mac_address)); + + /* Parse args required to build the message */ + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (input, "version %d", &version_val)) - version = 1; - else if (unformat (input, "traffic_class %d", &traffic_class_val)) - traffic_class = 1; - else if (unformat (input, "flow_label %d", &flow_label_val)) - flow_label = 1; - else if (unformat (input, "src %U", unformat_ip6_address, &src_val)) - src = 1; - else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val)) - dst = 1; - else if (unformat (input, "proto %d", &proto_val)) - proto = 1; - else if (unformat (input, "payload_length %d", &payload_length_val)) - payload_length = 1; - else if (unformat (input, "hop_limit %d", &hop_limit_val)) - hop_limit = 1; + if (unformat (i, "hw-addr %U", unformat_ethernet_address, mac_address)) + { + random_mac = 0; + } + else if (unformat (i, "pci-addr %U", unformat_vlib_pci_addr, &pci_addr)) + ; + else if (unformat (i, "features 0x%llx", &features)) + ; + else if (unformat (i, "gso-enabled")) + virtio_flags |= VIRTIO_API_FLAG_GSO; + else if (unformat (i, "csum-offload-enabled")) + virtio_flags |= VIRTIO_API_FLAG_CSUM_OFFLOAD; + else if (unformat (i, "gro-coalesce")) + virtio_flags |= VIRTIO_API_FLAG_GRO_COALESCE; + else if (unformat (i, "packed")) + virtio_flags |= VIRTIO_API_FLAG_PACKED; + else if (unformat (i, "in-order")) + virtio_flags |= VIRTIO_API_FLAG_IN_ORDER; else break; } - if (version + traffic_class + flow_label + src + dst + proto + - payload_length + hop_limit == 0) - return 0; - - /* - * Aligned because we use the real comparison functions - */ - vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4)); - - ip = (ip6_header_t *) match; - - if (src) - clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address)); - - if (dst) - clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address)); - - if (proto) - ip->protocol = proto_val; - - ip_version_traffic_class_and_flow_label = 0; - - if (version) - ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28; + if (pci_addr == 0) + { + errmsg ("pci address must be non zero. "); + return -99; + } - if (traffic_class) - ip_version_traffic_class_and_flow_label |= - (traffic_class_val & 0xFF) << 20; + /* Construct the API message */ + M (VIRTIO_PCI_CREATE_V2, mp); - if (flow_label) - ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF); + mp->use_random_mac = random_mac; - ip->ip_version_traffic_class_and_flow_label = - clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label); + mp->pci_addr.domain = htons (((vlib_pci_addr_t) pci_addr).domain); + mp->pci_addr.bus = ((vlib_pci_addr_t) pci_addr).bus; + mp->pci_addr.slot = ((vlib_pci_addr_t) pci_addr).slot; + mp->pci_addr.function = ((vlib_pci_addr_t) pci_addr).function; - if (payload_length) - ip->payload_length = clib_host_to_net_u16 (payload_length_val); + mp->features = clib_host_to_net_u64 (features); + mp->virtio_flags = clib_host_to_net_u32 (virtio_flags); - if (hop_limit) - ip->hop_limit = hop_limit_val; + if (random_mac == 0) + clib_memcpy (mp->mac_address, mac_address, 6); - *matchp = match; - return 1; + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; } -uword -unformat_l3_match (unformat_input_t * input, va_list * args) +static int +api_virtio_pci_delete (vat_main_t * vam) { - u8 **matchp = va_arg (*args, u8 **); + unformat_input_t *i = vam->input; + vl_api_virtio_pci_delete_t *mp; + u32 sw_if_index = ~0; + u8 sw_if_index_set = 0; + int ret; - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + /* Parse args required to build the message */ + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (input, "ip4 %U", unformat_ip4_match, matchp)) - return 1; - else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp)) - return 1; + if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) + sw_if_index_set = 1; + else if (unformat (i, "sw_if_index %d", &sw_if_index)) + sw_if_index_set = 1; else break; } - return 0; -} - -uword -unformat_vlan_tag (unformat_input_t * input, va_list * args) -{ - u8 *tagp = va_arg (*args, u8 *); - u32 tag; - if (unformat (input, "%d", &tag)) + if (sw_if_index_set == 0) { - tagp[0] = (tag >> 8) & 0x0F; - tagp[1] = tag & 0xFF; - return 1; + errmsg ("missing vpp interface name. "); + return -99; } - return 0; + /* Construct the API message */ + M (VIRTIO_PCI_DELETE, mp); + + mp->sw_if_index = htonl (sw_if_index); + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; } -uword -unformat_l2_match (unformat_input_t * input, va_list * args) +static int +api_bond_create (vat_main_t * vam) { - u8 **matchp = va_arg (*args, u8 **); - u8 *match = 0; - u8 src = 0; - u8 src_val[6]; - u8 dst = 0; - u8 dst_val[6]; - u8 proto = 0; - u16 proto_val; - u8 tag1 = 0; - u8 tag1_val[2]; - u8 tag2 = 0; - u8 tag2_val[2]; - int len = 14; - u8 ignore_tag1 = 0; - u8 ignore_tag2 = 0; - u8 cos1 = 0; - u8 cos2 = 0; - u32 cos1_val = 0; - u32 cos2_val = 0; + unformat_input_t *i = vam->input; + vl_api_bond_create_t *mp; + u8 mac_address[6]; + u8 custom_mac = 0; + int ret; + u8 mode; + u8 lb; + u8 mode_is_set = 0; + u32 id = ~0; + u8 numa_only = 0; - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + clib_memset (mac_address, 0, sizeof (mac_address)); + lb = BOND_LB_L2; + + /* Parse args required to build the message */ + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (input, "src %U", unformat_ethernet_address, &src_val)) - src = 1; - else - if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val)) - dst = 1; - else if (unformat (input, "proto %U", - unformat_ethernet_type_host_byte_order, &proto_val)) - proto = 1; - else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val)) - tag1 = 1; - else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val)) - tag2 = 1; - else if (unformat (input, "ignore-tag1")) - ignore_tag1 = 1; - else if (unformat (input, "ignore-tag2")) - ignore_tag2 = 1; - else if (unformat (input, "cos1 %d", &cos1_val)) - cos1 = 1; - else if (unformat (input, "cos2 %d", &cos2_val)) - cos2 = 1; + if (unformat (i, "mode %U", unformat_bond_mode, &mode)) + mode_is_set = 1; + else if (((mode == BOND_MODE_LACP) || (mode == BOND_MODE_XOR)) + && unformat (i, "lb %U", unformat_bond_load_balance, &lb)) + ; + else if (unformat (i, "hw-addr %U", unformat_ethernet_address, + mac_address)) + custom_mac = 1; + else if (unformat (i, "numa-only")) + numa_only = 1; + else if (unformat (i, "id %u", &id)) + ; else break; } - if ((src + dst + proto + tag1 + tag2 + - ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0) - return 0; - if (tag1 || ignore_tag1 || cos1) - len = 18; - if (tag2 || ignore_tag2 || cos2) - len = 22; + if (mode_is_set == 0) + { + errmsg ("Missing bond mode. "); + return -99; + } - vec_validate_aligned (match, len - 1, sizeof (u32x4)); + /* Construct the API message */ + M (BOND_CREATE, mp); - if (dst) - clib_memcpy (match, dst_val, 6); + mp->use_custom_mac = custom_mac; - if (src) - clib_memcpy (match + 6, src_val, 6); + mp->mode = htonl (mode); + mp->lb = htonl (lb); + mp->id = htonl (id); + mp->numa_only = numa_only; - if (tag2) + if (custom_mac) + clib_memcpy (mp->mac_address, mac_address, 6); + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_bond_create2 (vat_main_t * vam) +{ + unformat_input_t *i = vam->input; + vl_api_bond_create2_t *mp; + u8 mac_address[6]; + u8 custom_mac = 0; + int ret; + u8 mode; + u8 lb; + u8 mode_is_set = 0; + u32 id = ~0; + u8 numa_only = 0; + u8 gso = 0; + + clib_memset (mac_address, 0, sizeof (mac_address)); + lb = BOND_LB_L2; + + /* Parse args required to build the message */ + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - /* inner vlan tag */ - match[19] = tag2_val[1]; - match[18] = tag2_val[0]; - if (cos2) - match[18] |= (cos2_val & 0x7) << 5; - if (proto) - { - match[21] = proto_val & 0xff; - match[20] = proto_val >> 8; - } - if (tag1) - { - match[15] = tag1_val[1]; - match[14] = tag1_val[0]; - } - if (cos1) - match[14] |= (cos1_val & 0x7) << 5; - *matchp = match; - return 1; + if (unformat (i, "mode %U", unformat_bond_mode, &mode)) + mode_is_set = 1; + else if (((mode == BOND_MODE_LACP) || (mode == BOND_MODE_XOR)) + && unformat (i, "lb %U", unformat_bond_load_balance, &lb)) + ; + else if (unformat (i, "hw-addr %U", unformat_ethernet_address, + mac_address)) + custom_mac = 1; + else if (unformat (i, "numa-only")) + numa_only = 1; + else if (unformat (i, "gso")) + gso = 1; + else if (unformat (i, "id %u", &id)) + ; + else + break; } - if (tag1) - { - match[15] = tag1_val[1]; - match[14] = tag1_val[0]; - if (proto) - { - match[17] = proto_val & 0xff; - match[16] = proto_val >> 8; - } - if (cos1) - match[14] |= (cos1_val & 0x7) << 5; - *matchp = match; - return 1; - } - if (cos2) - match[18] |= (cos2_val & 0x7) << 5; - if (cos1) - match[14] |= (cos1_val & 0x7) << 5; - if (proto) + if (mode_is_set == 0) { - match[13] = proto_val & 0xff; - match[12] = proto_val >> 8; + errmsg ("Missing bond mode. "); + return -99; } - *matchp = match; - return 1; -} + /* Construct the API message */ + M (BOND_CREATE2, mp); -uword -unformat_qos_source (unformat_input_t * input, va_list * args) -{ - int *qs = va_arg (*args, int *); + mp->use_custom_mac = custom_mac; - if (unformat (input, "ip")) - *qs = QOS_SOURCE_IP; - else if (unformat (input, "mpls")) - *qs = QOS_SOURCE_MPLS; - else if (unformat (input, "ext")) - *qs = QOS_SOURCE_EXT; - else if (unformat (input, "vlan")) - *qs = QOS_SOURCE_VLAN; - else - return 0; + mp->mode = htonl (mode); + mp->lb = htonl (lb); + mp->id = htonl (id); + mp->numa_only = numa_only; + mp->enable_gso = gso; - return 1; + if (custom_mac) + clib_memcpy (mp->mac_address, mac_address, 6); + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; } -#endif -uword -api_unformat_classify_match (unformat_input_t * input, va_list * args) +static int +api_bond_delete (vat_main_t * vam) { - u8 **matchp = va_arg (*args, u8 **); - u32 skip_n_vectors = va_arg (*args, u32); - u32 match_n_vectors = va_arg (*args, u32); - - u8 *match = 0; - u8 *l2 = 0; - u8 *l3 = 0; - u8 *l4 = 0; + unformat_input_t *i = vam->input; + vl_api_bond_delete_t *mp; + u32 sw_if_index = ~0; + u8 sw_if_index_set = 0; + int ret; - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + /* Parse args required to build the message */ + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (input, "hex %U", unformat_hex_string, &match)) - ; - else if (unformat (input, "l2 %U", unformat_l2_match, &l2)) - ; - else if (unformat (input, "l3 %U", unformat_l3_match, &l3)) - ; - else if (unformat (input, "l4 %U", unformat_l4_match, &l4)) - ; + if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) + sw_if_index_set = 1; + else if (unformat (i, "sw_if_index %d", &sw_if_index)) + sw_if_index_set = 1; else break; } - if (l4 && !l3) + if (sw_if_index_set == 0) { - vec_free (match); - vec_free (l2); - vec_free (l4); - return 0; + errmsg ("missing vpp interface name. "); + return -99; } - if (match || l2 || l3 || l4) - { - if (l2 || l3 || l4) - { - /* "Win a free Ethernet header in every packet" */ - if (l2 == 0) - vec_validate_aligned (l2, 13, sizeof (u32x4)); - match = l2; - if (vec_len (l3)) - { - vec_append_aligned (match, l3, sizeof (u32x4)); - vec_free (l3); - } - if (vec_len (l4)) - { - vec_append_aligned (match, l4, sizeof (u32x4)); - vec_free (l4); - } - } - - /* Make sure the vector is big enough even if key is all 0's */ - vec_validate_aligned - (match, ((match_n_vectors + skip_n_vectors) * sizeof (u32x4)) - 1, - sizeof (u32x4)); - - /* Set size, include skipped vectors */ - _vec_len (match) = (match_n_vectors + skip_n_vectors) * sizeof (u32x4); + /* Construct the API message */ + M (BOND_DELETE, mp); - *matchp = match; + mp->sw_if_index = ntohl (sw_if_index); - return 1; - } + /* send it... */ + S (mp); - return 0; + /* Wait for a reply... */ + W (ret); + return ret; } static int -api_classify_add_del_session (vat_main_t * vam) +api_bond_add_member (vat_main_t * vam) { unformat_input_t *i = vam->input; - vl_api_classify_add_del_session_t *mp; - int is_add = 1; - u32 table_index = ~0; - u32 hit_next_index = ~0; - u32 opaque_index = ~0; - u8 *match = 0; - i32 advance = 0; - u32 skip_n_vectors = 0; - u32 match_n_vectors = 0; - u32 action = 0; - u32 metadata = 0; + vl_api_bond_add_member_t *mp; + u32 bond_sw_if_index; int ret; + u8 is_passive; + u8 is_long_timeout; + u32 bond_sw_if_index_is_set = 0; + u32 sw_if_index; + u8 sw_if_index_is_set = 0; - /* - * Warning: you have to supply skip_n and match_n - * because the API client cant simply look at the classify - * table object. - */ - + /* Parse args required to build the message */ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (i, "del")) - is_add = 0; - else if (unformat (i, "hit-next %U", api_unformat_ip_next_index, - &hit_next_index)) - ; - else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index, - &hit_next_index)) - ; - else if (unformat (i, "acl-hit-next %U", api_unformat_acl_next_index, - &hit_next_index)) - ; - else if (unformat (i, "policer-hit-next %d", &hit_next_index)) - ; - else if (unformat (i, "%U", unformat_policer_precolor, &opaque_index)) - ; - else if (unformat (i, "opaque-index %d", &opaque_index)) - ; - else if (unformat (i, "skip_n %d", &skip_n_vectors)) - ; - else if (unformat (i, "match_n %d", &match_n_vectors)) - ; - else if (unformat (i, "match %U", api_unformat_classify_match, - &match, skip_n_vectors, match_n_vectors)) - ; - else if (unformat (i, "advance %d", &advance)) - ; - else if (unformat (i, "table-index %d", &table_index)) - ; - else if (unformat (i, "action set-ip4-fib-id %d", &metadata)) - action = 1; - else if (unformat (i, "action set-ip6-fib-id %d", &metadata)) - action = 2; - else if (unformat (i, "action %d", &action)) + if (unformat (i, "sw_if_index %d", &sw_if_index)) + sw_if_index_is_set = 1; + else if (unformat (i, "bond %u", &bond_sw_if_index)) + bond_sw_if_index_is_set = 1; + else if (unformat (i, "passive %d", &is_passive)) ; - else if (unformat (i, "metadata %d", &metadata)) + else if (unformat (i, "long-timeout %d", &is_long_timeout)) ; else break; } - if (table_index == ~0) + if (bond_sw_if_index_is_set == 0) { - errmsg ("Table index required"); + errmsg ("Missing bond sw_if_index. "); return -99; } - - if (is_add && match == 0) + if (sw_if_index_is_set == 0) { - errmsg ("Match value required"); + errmsg ("Missing member sw_if_index. "); return -99; } - M2 (CLASSIFY_ADD_DEL_SESSION, mp, vec_len (match)); + /* Construct the API message */ + M (BOND_ADD_MEMBER, mp); - mp->is_add = is_add; - mp->table_index = ntohl (table_index); - mp->hit_next_index = ntohl (hit_next_index); - mp->opaque_index = ntohl (opaque_index); - mp->advance = ntohl (advance); - mp->action = action; - mp->metadata = ntohl (metadata); - mp->match_len = ntohl (vec_len (match)); - clib_memcpy (mp->match, match, vec_len (match)); - vec_free (match); + mp->bond_sw_if_index = ntohl (bond_sw_if_index); + mp->sw_if_index = ntohl (sw_if_index); + mp->is_long_timeout = is_long_timeout; + mp->is_passive = is_passive; + /* send it... */ S (mp); + + /* Wait for a reply... */ W (ret); return ret; } static int -api_classify_set_interface_ip_table (vat_main_t * vam) +api_bond_detach_member (vat_main_t * vam) { unformat_input_t *i = vam->input; - vl_api_classify_set_interface_ip_table_t *mp; - u32 sw_if_index; - int sw_if_index_set; - u32 table_index = ~0; - u8 is_ipv6 = 0; + vl_api_bond_detach_member_t *mp; + u32 sw_if_index = ~0; + u8 sw_if_index_set = 0; int ret; + /* Parse args required to build the message */ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) sw_if_index_set = 1; else if (unformat (i, "sw_if_index %d", &sw_if_index)) sw_if_index_set = 1; - else if (unformat (i, "table %d", &table_index)) - ; else - { - clib_warning ("parse error '%U'", format_unformat_error, i); - return -99; - } + break; } if (sw_if_index_set == 0) { - errmsg ("missing interface name or sw_if_index"); + errmsg ("missing vpp interface name. "); return -99; } - - M (CLASSIFY_SET_INTERFACE_IP_TABLE, mp); + /* Construct the API message */ + M (BOND_DETACH_MEMBER, mp); mp->sw_if_index = ntohl (sw_if_index); - mp->table_index = ntohl (table_index); - mp->is_ipv6 = is_ipv6; + /* send it... */ S (mp); + + /* Wait for a reply... */ W (ret); return ret; } static int -api_classify_set_interface_l2_tables (vat_main_t * vam) +api_ip_table_add_del (vat_main_t * vam) { unformat_input_t *i = vam->input; - vl_api_classify_set_interface_l2_tables_t *mp; - u32 sw_if_index; - int sw_if_index_set; - u32 ip4_table_index = ~0; - u32 ip6_table_index = ~0; - u32 other_table_index = ~0; - u32 is_input = 1; - int ret; + vl_api_ip_table_add_del_t *mp; + u32 table_id = ~0; + u8 is_ipv6 = 0; + u8 is_add = 1; + int ret = 0; + /* Parse args required to build the message */ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) - sw_if_index_set = 1; - else if (unformat (i, "sw_if_index %d", &sw_if_index)) - sw_if_index_set = 1; - else if (unformat (i, "ip4-table %d", &ip4_table_index)) - ; - else if (unformat (i, "ip6-table %d", &ip6_table_index)) - ; - else if (unformat (i, "other-table %d", &other_table_index)) - ; - else if (unformat (i, "is-input %d", &is_input)) + if (unformat (i, "ipv6")) + is_ipv6 = 1; + else if (unformat (i, "del")) + is_add = 0; + else if (unformat (i, "add")) + is_add = 1; + else if (unformat (i, "table %d", &table_id)) ; else { @@ -10787,1002 +5985,1256 @@ api_classify_set_interface_l2_tables (vat_main_t * vam) } } - if (sw_if_index_set == 0) + if (~0 == table_id) { - errmsg ("missing interface name or sw_if_index"); + errmsg ("missing table-ID"); return -99; } + /* Construct the API message */ + M (IP_TABLE_ADD_DEL, mp); - M (CLASSIFY_SET_INTERFACE_L2_TABLES, mp); - - mp->sw_if_index = ntohl (sw_if_index); - mp->ip4_table_index = ntohl (ip4_table_index); - mp->ip6_table_index = ntohl (ip6_table_index); - mp->other_table_index = ntohl (other_table_index); - mp->is_input = (u8) is_input; + mp->table.table_id = ntohl (table_id); + mp->table.is_ip6 = is_ipv6; + mp->is_add = is_add; + /* send it... */ S (mp); + + /* Wait for a reply... */ W (ret); + return ret; } +uword +unformat_fib_path (unformat_input_t * input, va_list * args) +{ + vat_main_t *vam = va_arg (*args, vat_main_t *); + vl_api_fib_path_t *path = va_arg (*args, vl_api_fib_path_t *); + u32 weight, preference; + mpls_label_t out_label; + + clib_memset (path, 0, sizeof (*path)); + path->weight = 1; + path->sw_if_index = ~0; + path->rpf_id = ~0; + path->n_labels = 0; + + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "%U %U", + unformat_vl_api_ip4_address, + &path->nh.address.ip4, + api_unformat_sw_if_index, vam, &path->sw_if_index)) + { + path->proto = FIB_API_PATH_NH_PROTO_IP4; + } + else if (unformat (input, "%U %U", + unformat_vl_api_ip6_address, + &path->nh.address.ip6, + api_unformat_sw_if_index, vam, &path->sw_if_index)) + { + path->proto = FIB_API_PATH_NH_PROTO_IP6; + } + else if (unformat (input, "weight %u", &weight)) + { + path->weight = weight; + } + else if (unformat (input, "preference %u", &preference)) + { + path->preference = preference; + } + else if (unformat (input, "%U next-hop-table %d", + unformat_vl_api_ip4_address, + &path->nh.address.ip4, &path->table_id)) + { + path->proto = FIB_API_PATH_NH_PROTO_IP4; + } + else if (unformat (input, "%U next-hop-table %d", + unformat_vl_api_ip6_address, + &path->nh.address.ip6, &path->table_id)) + { + path->proto = FIB_API_PATH_NH_PROTO_IP6; + } + else if (unformat (input, "%U", + unformat_vl_api_ip4_address, &path->nh.address.ip4)) + { + /* + * the recursive next-hops are by default in the default table + */ + path->table_id = 0; + path->sw_if_index = ~0; + path->proto = FIB_API_PATH_NH_PROTO_IP4; + } + else if (unformat (input, "%U", + unformat_vl_api_ip6_address, &path->nh.address.ip6)) + { + /* + * the recursive next-hops are by default in the default table + */ + path->table_id = 0; + path->sw_if_index = ~0; + path->proto = FIB_API_PATH_NH_PROTO_IP6; + } + else if (unformat (input, "resolve-via-host")) + { + path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_HOST; + } + else if (unformat (input, "resolve-via-attached")) + { + path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_ATTACHED; + } + else if (unformat (input, "ip4-lookup-in-table %d", &path->table_id)) + { + path->type = FIB_API_PATH_TYPE_LOCAL; + path->sw_if_index = ~0; + path->proto = FIB_API_PATH_NH_PROTO_IP4; + } + else if (unformat (input, "ip6-lookup-in-table %d", &path->table_id)) + { + path->type = FIB_API_PATH_TYPE_LOCAL; + path->sw_if_index = ~0; + path->proto = FIB_API_PATH_NH_PROTO_IP6; + } + else if (unformat (input, "sw_if_index %d", &path->sw_if_index)) + ; + else if (unformat (input, "via-label %d", &path->nh.via_label)) + { + path->proto = FIB_API_PATH_NH_PROTO_MPLS; + path->sw_if_index = ~0; + } + else if (unformat (input, "l2-input-on %d", &path->sw_if_index)) + { + path->proto = FIB_API_PATH_NH_PROTO_ETHERNET; + path->type = FIB_API_PATH_TYPE_INTERFACE_RX; + } + else if (unformat (input, "local")) + { + path->type = FIB_API_PATH_TYPE_LOCAL; + } + else if (unformat (input, "out-labels")) + { + while (unformat (input, "%d", &out_label)) + { + path->label_stack[path->n_labels].label = out_label; + path->label_stack[path->n_labels].is_uniform = 0; + path->label_stack[path->n_labels].ttl = 64; + path->n_labels++; + } + } + else if (unformat (input, "via")) + { + /* new path, back up and return */ + unformat_put_input (input); + unformat_put_input (input); + unformat_put_input (input); + unformat_put_input (input); + break; + } + else + { + return (0); + } + } + + path->proto = ntohl (path->proto); + path->type = ntohl (path->type); + path->flags = ntohl (path->flags); + path->table_id = ntohl (path->table_id); + path->sw_if_index = ntohl (path->sw_if_index); + + return (1); +} + static int -api_set_ipfix_exporter (vat_main_t * vam) +api_ip_route_add_del (vat_main_t * vam) { unformat_input_t *i = vam->input; - vl_api_set_ipfix_exporter_t *mp; - ip4_address_t collector_address; - u8 collector_address_set = 0; - u32 collector_port = ~0; - ip4_address_t src_address; - u8 src_address_set = 0; - u32 vrf_id = ~0; - u32 path_mtu = ~0; - u32 template_interval = ~0; - u8 udp_checksum = 0; - int ret; + vl_api_ip_route_add_del_t *mp; + u32 vrf_id = 0; + u8 is_add = 1; + u8 is_multipath = 0; + u8 prefix_set = 0; + u8 path_count = 0; + vl_api_prefix_t pfx = { }; + vl_api_fib_path_t paths[8]; + int count = 1; + int j; + f64 before = 0; + u32 random_add_del = 0; + u32 *random_vector = 0; + u32 random_seed = 0xdeaddabe; + /* Parse args required to build the message */ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (i, "collector_address %U", unformat_ip4_address, - &collector_address)) - collector_address_set = 1; - else if (unformat (i, "collector_port %d", &collector_port)) - ; - else if (unformat (i, "src_address %U", unformat_ip4_address, - &src_address)) - src_address_set = 1; - else if (unformat (i, "vrf_id %d", &vrf_id)) + if (unformat (i, "%U", unformat_vl_api_prefix, &pfx)) + prefix_set = 1; + else if (unformat (i, "del")) + is_add = 0; + else if (unformat (i, "add")) + is_add = 1; + else if (unformat (i, "vrf %d", &vrf_id)) ; - else if (unformat (i, "path_mtu %d", &path_mtu)) + else if (unformat (i, "count %d", &count)) ; - else if (unformat (i, "template_interval %d", &template_interval)) + else if (unformat (i, "random")) + random_add_del = 1; + else if (unformat (i, "multipath")) + is_multipath = 1; + else if (unformat (i, "seed %d", &random_seed)) ; - else if (unformat (i, "udp_checksum")) - udp_checksum = 1; else - break; + if (unformat + (i, "via %U", unformat_fib_path, vam, &paths[path_count])) + { + path_count++; + if (8 == path_count) + { + errmsg ("max 8 paths"); + return -99; + } + } + else + { + clib_warning ("parse error '%U'", format_unformat_error, i); + return -99; + } + } + + if (!path_count) + { + errmsg ("specify a path; via ..."); + return -99; + } + if (prefix_set == 0) + { + errmsg ("missing prefix"); + return -99; } - if (collector_address_set == 0) + /* Generate a pile of unique, random routes */ + if (random_add_del) { - errmsg ("collector_address required"); - return -99; + ip4_address_t *i = (ip4_address_t *) & paths[0].nh.address.ip4; + u32 this_random_address; + uword *random_hash; + + random_hash = hash_create (count, sizeof (uword)); + + hash_set (random_hash, i->as_u32, 1); + for (j = 0; j <= count; j++) + { + do + { + this_random_address = random_u32 (&random_seed); + this_random_address = + clib_host_to_net_u32 (this_random_address); + } + while (hash_get (random_hash, this_random_address)); + vec_add1 (random_vector, this_random_address); + hash_set (random_hash, this_random_address, 1); + } + hash_free (random_hash); + set_ip4_address (&pfx.address, random_vector[0]); } - if (src_address_set == 0) + if (count > 1) { - errmsg ("src_address required"); - return -99; + /* Turn on async mode */ + vam->async_mode = 1; + vam->async_errors = 0; + before = vat_time_now (vam); } - M (SET_IPFIX_EXPORTER, mp); + for (j = 0; j < count; j++) + { + /* Construct the API message */ + M2 (IP_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count); - memcpy (mp->collector_address.un.ip4, collector_address.data, - sizeof (collector_address.data)); - mp->collector_port = htons ((u16) collector_port); - memcpy (mp->src_address.un.ip4, src_address.data, - sizeof (src_address.data)); - mp->vrf_id = htonl (vrf_id); - mp->path_mtu = htonl (path_mtu); - mp->template_interval = htonl (template_interval); - mp->udp_checksum = udp_checksum; + mp->is_add = is_add; + mp->is_multipath = is_multipath; - S (mp); - W (ret); - return ret; -} + clib_memcpy (&mp->route.prefix, &pfx, sizeof (pfx)); + mp->route.table_id = ntohl (vrf_id); + mp->route.n_paths = path_count; -static int -api_set_ipfix_classify_stream (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_set_ipfix_classify_stream_t *mp; - u32 domain_id = 0; - u32 src_port = UDP_DST_PORT_ipfix; - int ret; + clib_memcpy (&mp->route.paths, &paths, sizeof (paths[0]) * path_count); - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "domain %d", &domain_id)) - ; - else if (unformat (i, "src_port %d", &src_port)) - ; + if (random_add_del) + set_ip4_address (&pfx.address, random_vector[j + 1]); else + increment_address (&pfx.address); + /* send it... */ + S (mp); + /* If we receive SIGTERM, stop now... */ + if (vam->do_exit) + break; + } + + /* When testing multiple add/del ops, use a control-ping to sync */ + if (count > 1) + { + vl_api_control_ping_t *mp_ping; + f64 after; + f64 timeout; + + /* Shut off async mode */ + vam->async_mode = 0; + + MPING (CONTROL_PING, mp_ping); + S (mp_ping); + + timeout = vat_time_now (vam) + 1.0; + while (vat_time_now (vam) < timeout) + if (vam->result_ready == 1) + goto out; + vam->retval = -99; + + out: + if (vam->retval == -99) + errmsg ("timeout"); + + if (vam->async_errors > 0) { - errmsg ("unknown input `%U'", format_unformat_error, i); - return -99; + errmsg ("%d asynchronous errors", vam->async_errors); + vam->retval = -98; } - } + vam->async_errors = 0; + after = vat_time_now (vam); - M (SET_IPFIX_CLASSIFY_STREAM, mp); + /* slim chance, but we might have eaten SIGTERM on the first iteration */ + if (j > 0) + count = j; - mp->domain_id = htonl (domain_id); - mp->src_port = htons ((u16) src_port); + print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec", + count, after - before, count / (after - before)); + } + else + { + int ret; - S (mp); - W (ret); - return ret; + /* Wait for a reply... */ + W (ret); + return ret; + } + + /* Return the good/bad news */ + return (vam->retval); } static int -api_ipfix_classify_table_add_del (vat_main_t * vam) +api_ip_mroute_add_del (vat_main_t * vam) { unformat_input_t *i = vam->input; - vl_api_ipfix_classify_table_add_del_t *mp; - int is_add = -1; - u32 classify_table_index = ~0; - u8 ip_version = 0; - u8 transport_protocol = 255; + u8 path_set = 0, prefix_set = 0, is_add = 1; + vl_api_ip_mroute_add_del_t *mp; + mfib_entry_flags_t eflags = 0; + vl_api_mfib_path_t path; + vl_api_mprefix_t pfx = { }; + u32 vrf_id = 0; int ret; + /* Parse args required to build the message */ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (i, "add")) - is_add = 1; + if (unformat (i, "%U", unformat_vl_api_mprefix, &pfx)) + { + prefix_set = 1; + pfx.grp_address_length = htons (pfx.grp_address_length); + } else if (unformat (i, "del")) is_add = 0; - else if (unformat (i, "table %d", &classify_table_index)) + else if (unformat (i, "add")) + is_add = 1; + else if (unformat (i, "vrf %d", &vrf_id)) ; - else if (unformat (i, "ip4")) - ip_version = 4; - else if (unformat (i, "ip6")) - ip_version = 6; - else if (unformat (i, "tcp")) - transport_protocol = 6; - else if (unformat (i, "udp")) - transport_protocol = 17; + else if (unformat (i, "%U", unformat_mfib_itf_flags, &path.itf_flags)) + path.itf_flags = htonl (path.itf_flags); + else if (unformat (i, "%U", unformat_mfib_entry_flags, &eflags)) + ; + else if (unformat (i, "via %U", unformat_fib_path, vam, &path.path)) + path_set = 1; else { - errmsg ("unknown input `%U'", format_unformat_error, i); + clib_warning ("parse error '%U'", format_unformat_error, i); return -99; } } - if (is_add == -1) - { - errmsg ("expecting: add|del"); - return -99; - } - if (classify_table_index == ~0) + if (prefix_set == 0) { - errmsg ("classifier table not specified"); + errmsg ("missing addresses\n"); return -99; } - if (ip_version == 0) + if (path_set == 0) { - errmsg ("IP version not specified"); + errmsg ("missing path\n"); return -99; } - M (IPFIX_CLASSIFY_TABLE_ADD_DEL, mp); + /* Construct the API message */ + M (IP_MROUTE_ADD_DEL, mp); mp->is_add = is_add; - mp->table_id = htonl (classify_table_index); - mp->ip_version = ip_version; - mp->transport_protocol = transport_protocol; - - S (mp); - W (ret); - return ret; -} - -static int -api_get_node_index (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_get_node_index_t *mp; - u8 *name = 0; - int ret; + mp->is_multipath = 1; - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "node %s", &name)) - ; - else - break; - } - if (name == 0) - { - errmsg ("node name required"); - return -99; - } - if (vec_len (name) >= ARRAY_LEN (mp->node_name)) - { - errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name)); - return -99; - } + clib_memcpy (&mp->route.prefix, &pfx, sizeof (pfx)); + mp->route.table_id = htonl (vrf_id); + mp->route.n_paths = 1; + mp->route.entry_flags = htonl (eflags); - M (GET_NODE_INDEX, mp); - clib_memcpy (mp->node_name, name, vec_len (name)); - vec_free (name); + clib_memcpy (&mp->route.paths, &path, sizeof (path)); + /* send it... */ S (mp); + /* Wait for a reply... */ W (ret); return ret; } static int -api_get_next_index (vat_main_t * vam) +api_mpls_table_add_del (vat_main_t * vam) { unformat_input_t *i = vam->input; - vl_api_get_next_index_t *mp; - u8 *node_name = 0, *next_node_name = 0; - int ret; - - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "node-name %s", &node_name)) - ; - else if (unformat (i, "next-node-name %s", &next_node_name)) - break; - } + vl_api_mpls_table_add_del_t *mp; + u32 table_id = ~0; + u8 is_add = 1; + int ret = 0; - if (node_name == 0) - { - errmsg ("node name required"); - return -99; - } - if (vec_len (node_name) >= ARRAY_LEN (mp->node_name)) + /* Parse args required to build the message */ + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name)); - return -99; + if (unformat (i, "table %d", &table_id)) + ; + else if (unformat (i, "del")) + is_add = 0; + else if (unformat (i, "add")) + is_add = 1; + else + { + clib_warning ("parse error '%U'", format_unformat_error, i); + return -99; + } } - if (next_node_name == 0) - { - errmsg ("next node name required"); - return -99; - } - if (vec_len (next_node_name) >= ARRAY_LEN (mp->next_name)) + if (~0 == table_id) { - errmsg ("next node name too long, max %d", ARRAY_LEN (mp->next_name)); + errmsg ("missing table-ID"); return -99; } - M (GET_NEXT_INDEX, mp); - clib_memcpy (mp->node_name, node_name, vec_len (node_name)); - clib_memcpy (mp->next_name, next_node_name, vec_len (next_node_name)); - vec_free (node_name); - vec_free (next_node_name); + /* Construct the API message */ + M (MPLS_TABLE_ADD_DEL, mp); + + mp->mt_table.mt_table_id = ntohl (table_id); + mp->mt_is_add = is_add; + /* send it... */ S (mp); + + /* Wait for a reply... */ W (ret); + return ret; } static int -api_add_node_next (vat_main_t * vam) +api_mpls_route_add_del (vat_main_t * vam) { + u8 is_add = 1, path_count = 0, is_multipath = 0, is_eos = 0; + mpls_label_t local_label = MPLS_LABEL_INVALID; unformat_input_t *i = vam->input; - vl_api_add_node_next_t *mp; - u8 *name = 0; - u8 *next = 0; - int ret; + vl_api_mpls_route_add_del_t *mp; + vl_api_fib_path_t paths[8]; + int count = 1, j; + f64 before = 0; + /* Parse args required to build the message */ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (i, "node %s", &name)) + if (unformat (i, "%d", &local_label)) ; - else if (unformat (i, "next %s", &next)) + else if (unformat (i, "eos")) + is_eos = 1; + else if (unformat (i, "non-eos")) + is_eos = 0; + else if (unformat (i, "del")) + is_add = 0; + else if (unformat (i, "add")) + is_add = 1; + else if (unformat (i, "multipath")) + is_multipath = 1; + else if (unformat (i, "count %d", &count)) ; else - break; + if (unformat + (i, "via %U", unformat_fib_path, vam, &paths[path_count])) + { + path_count++; + if (8 == path_count) + { + errmsg ("max 8 paths"); + return -99; + } + } + else + { + clib_warning ("parse error '%U'", format_unformat_error, i); + return -99; + } } - if (name == 0) + + if (!path_count) { - errmsg ("node name required"); + errmsg ("specify a path; via ..."); return -99; } - if (vec_len (name) >= ARRAY_LEN (mp->node_name)) + + if (MPLS_LABEL_INVALID == local_label) { - errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name)); + errmsg ("missing label"); return -99; } - if (next == 0) + + if (count > 1) { - errmsg ("next node required"); - return -99; + /* Turn on async mode */ + vam->async_mode = 1; + vam->async_errors = 0; + before = vat_time_now (vam); } - if (vec_len (next) >= ARRAY_LEN (mp->next_name)) + + for (j = 0; j < count; j++) { - errmsg ("next name too long, max %d", ARRAY_LEN (mp->next_name)); - return -99; + /* Construct the API message */ + M2 (MPLS_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count); + + mp->mr_is_add = is_add; + mp->mr_is_multipath = is_multipath; + + mp->mr_route.mr_label = local_label; + mp->mr_route.mr_eos = is_eos; + mp->mr_route.mr_table_id = 0; + mp->mr_route.mr_n_paths = path_count; + + clib_memcpy (&mp->mr_route.mr_paths, paths, + sizeof (paths[0]) * path_count); + + local_label++; + + /* send it... */ + S (mp); + /* If we receive SIGTERM, stop now... */ + if (vam->do_exit) + break; } - M (ADD_NODE_NEXT, mp); - clib_memcpy (mp->node_name, name, vec_len (name)); - clib_memcpy (mp->next_name, next, vec_len (next)); - vec_free (name); - vec_free (next); + /* When testing multiple add/del ops, use a control-ping to sync */ + if (count > 1) + { + vl_api_control_ping_t *mp_ping; + f64 after; + f64 timeout; - S (mp); - W (ret); - return ret; -} + /* Shut off async mode */ + vam->async_mode = 0; -static void vl_api_sw_interface_tap_v2_details_t_handler - (vl_api_sw_interface_tap_v2_details_t * mp) -{ - vat_main_t *vam = &vat_main; + MPING (CONTROL_PING, mp_ping); + S (mp_ping); - u8 *ip4 = - format (0, "%U/%d", format_ip4_address, mp->host_ip4_prefix.address, - mp->host_ip4_prefix.len); - u8 *ip6 = - format (0, "%U/%d", format_ip6_address, mp->host_ip6_prefix.address, - mp->host_ip6_prefix.len); + timeout = vat_time_now (vam) + 1.0; + while (vat_time_now (vam) < timeout) + if (vam->result_ready == 1) + goto out; + vam->retval = -99; - print (vam->ofp, - "\n%-16s %-12d %-5d %-12d %-12d %-14U %-30s %-20s %-20s %-30s 0x%-08x", - mp->dev_name, ntohl (mp->sw_if_index), ntohl (mp->id), - ntohs (mp->rx_ring_sz), ntohs (mp->tx_ring_sz), - format_ethernet_address, mp->host_mac_addr, mp->host_namespace, - mp->host_bridge, ip4, ip6, ntohl (mp->tap_flags)); + out: + if (vam->retval == -99) + errmsg ("timeout"); - vec_free (ip4); - vec_free (ip6); -} + if (vam->async_errors > 0) + { + errmsg ("%d asynchronous errors", vam->async_errors); + vam->retval = -98; + } + vam->async_errors = 0; + after = vat_time_now (vam); -static void vl_api_sw_interface_tap_v2_details_t_handler_json - (vl_api_sw_interface_tap_v2_details_t * mp) -{ - vat_main_t *vam = &vat_main; - vat_json_node_t *node = NULL; + /* slim chance, but we might have eaten SIGTERM on the first iteration */ + if (j > 0) + count = j; - if (VAT_JSON_ARRAY != vam->json_tree.type) + print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec", + count, after - before, count / (after - before)); + } + else { - ASSERT (VAT_JSON_NONE == vam->json_tree.type); - vat_json_init_array (&vam->json_tree); + int ret; + + /* Wait for a reply... */ + W (ret); + return ret; } - node = vat_json_array_add (&vam->json_tree); - vat_json_init_object (node); - vat_json_object_add_uint (node, "id", ntohl (mp->id)); - vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index)); - vat_json_object_add_uint (node, "tap_flags", ntohl (mp->tap_flags)); - vat_json_object_add_string_copy (node, "dev_name", mp->dev_name); - vat_json_object_add_uint (node, "rx_ring_sz", ntohs (mp->rx_ring_sz)); - vat_json_object_add_uint (node, "tx_ring_sz", ntohs (mp->tx_ring_sz)); - vat_json_object_add_string_copy (node, "host_mac_addr", - format (0, "%U", format_ethernet_address, - &mp->host_mac_addr)); - vat_json_object_add_string_copy (node, "host_namespace", - mp->host_namespace); - vat_json_object_add_string_copy (node, "host_bridge", mp->host_bridge); - vat_json_object_add_string_copy (node, "host_ip4_addr", - format (0, "%U/%d", format_ip4_address, - mp->host_ip4_prefix.address, - mp->host_ip4_prefix.len)); - vat_json_object_add_string_copy (node, "host_ip6_prefix", - format (0, "%U/%d", format_ip6_address, - mp->host_ip6_prefix.address, - mp->host_ip6_prefix.len)); + /* Return the good/bad news */ + return (vam->retval); + return (0); +} + +static int +api_mpls_ip_bind_unbind (vat_main_t * vam) +{ + unformat_input_t *i = vam->input; + vl_api_mpls_ip_bind_unbind_t *mp; + u32 ip_table_id = 0; + u8 is_bind = 1; + vl_api_prefix_t pfx; + u8 prefix_set = 0; + mpls_label_t local_label = MPLS_LABEL_INVALID; + int ret; + + /* Parse args required to build the message */ + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + { + if (unformat (i, "%U", unformat_vl_api_prefix, &pfx)) + prefix_set = 1; + else if (unformat (i, "%d", &local_label)) + ; + else if (unformat (i, "table-id %d", &ip_table_id)) + ; + else if (unformat (i, "unbind")) + is_bind = 0; + else if (unformat (i, "bind")) + is_bind = 1; + else + { + clib_warning ("parse error '%U'", format_unformat_error, i); + return -99; + } + } -} + if (!prefix_set) + { + errmsg ("IP prefix not set"); + return -99; + } -static int -api_sw_interface_tap_v2_dump (vat_main_t * vam) -{ - vl_api_sw_interface_tap_v2_dump_t *mp; - vl_api_control_ping_t *mp_ping; - int ret; + if (MPLS_LABEL_INVALID == local_label) + { + errmsg ("missing label"); + return -99; + } - print (vam->ofp, - "\n%-16s %-12s %-5s %-12s %-12s %-14s %-30s %-20s %-20s %-30s", - "dev_name", "sw_if_index", "id", "rx_ring_sz", "tx_ring_sz", - "host_mac_addr", "host_namespace", "host_bridge", "host_ip4_addr", - "host_ip6_addr"); + /* Construct the API message */ + M (MPLS_IP_BIND_UNBIND, mp); - /* Get list of tap interfaces */ - M (SW_INTERFACE_TAP_V2_DUMP, mp); - S (mp); + mp->mb_is_bind = is_bind; + mp->mb_ip_table_id = ntohl (ip_table_id); + mp->mb_mpls_table_id = 0; + mp->mb_label = ntohl (local_label); + clib_memcpy (&mp->mb_prefix, &pfx, sizeof (pfx)); - /* Use a control ping for synchronization */ - MPING (CONTROL_PING, mp_ping); - S (mp_ping); + /* send it... */ + S (mp); + /* Wait for a reply... */ W (ret); return ret; + return (0); } -static void vl_api_sw_interface_virtio_pci_details_t_handler - (vl_api_sw_interface_virtio_pci_details_t * mp) +static int +api_sr_mpls_policy_add (vat_main_t * vam) { - vat_main_t *vam = &vat_main; + unformat_input_t *i = vam->input; + vl_api_sr_mpls_policy_add_t *mp; + u32 bsid = 0; + u32 weight = 1; + u8 type = 0; + u8 n_segments = 0; + u32 sid; + u32 *segments = NULL; + int ret; - typedef union - { - struct + /* Parse args required to build the message */ + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - u16 domain; - u8 bus; - u8 slot:5; - u8 function:3; - }; - u32 as_u32; - } pci_addr_t; - pci_addr_t addr; - - addr.domain = ntohs (mp->pci_addr.domain); - addr.bus = mp->pci_addr.bus; - addr.slot = mp->pci_addr.slot; - addr.function = mp->pci_addr.function; - - u8 *pci_addr = format (0, "%04x:%02x:%02x.%x", addr.domain, addr.bus, - addr.slot, addr.function); - - print (vam->ofp, - "\n%-12s %-12d %-12d %-12d %-17U 0x%-08llx", - pci_addr, ntohl (mp->sw_if_index), - ntohs (mp->rx_ring_sz), ntohs (mp->tx_ring_sz), - format_ethernet_address, mp->mac_addr, - clib_net_to_host_u64 (mp->features)); - vec_free (pci_addr); -} + if (unformat (i, "bsid %d", &bsid)) + ; + else if (unformat (i, "weight %d", &weight)) + ; + else if (unformat (i, "spray")) + type = 1; + else if (unformat (i, "next %d", &sid)) + { + n_segments += 1; + vec_add1 (segments, htonl (sid)); + } + else + { + clib_warning ("parse error '%U'", format_unformat_error, i); + return -99; + } + } -static void vl_api_sw_interface_virtio_pci_details_t_handler_json - (vl_api_sw_interface_virtio_pci_details_t * mp) -{ - vat_main_t *vam = &vat_main; - vat_json_node_t *node = NULL; - vlib_pci_addr_t pci_addr; + if (bsid == 0) + { + errmsg ("bsid not set"); + return -99; + } - if (VAT_JSON_ARRAY != vam->json_tree.type) + if (n_segments == 0) { - ASSERT (VAT_JSON_NONE == vam->json_tree.type); - vat_json_init_array (&vam->json_tree); + errmsg ("no sid in segment stack"); + return -99; } - node = vat_json_array_add (&vam->json_tree); - pci_addr.domain = ntohs (mp->pci_addr.domain); - pci_addr.bus = mp->pci_addr.bus; - pci_addr.slot = mp->pci_addr.slot; - pci_addr.function = mp->pci_addr.function; + /* Construct the API message */ + M2 (SR_MPLS_POLICY_ADD, mp, sizeof (u32) * n_segments); - vat_json_init_object (node); - vat_json_object_add_uint (node, "pci-addr", pci_addr.as_u32); - vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index)); - vat_json_object_add_uint (node, "rx_ring_sz", ntohs (mp->rx_ring_sz)); - vat_json_object_add_uint (node, "tx_ring_sz", ntohs (mp->tx_ring_sz)); - vat_json_object_add_uint (node, "features", - clib_net_to_host_u64 (mp->features)); - vat_json_object_add_string_copy (node, "mac_addr", - format (0, "%U", format_ethernet_address, - &mp->mac_addr)); + mp->bsid = htonl (bsid); + mp->weight = htonl (weight); + mp->is_spray = type; + mp->n_segments = n_segments; + memcpy (mp->segments, segments, sizeof (u32) * n_segments); + vec_free (segments); + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; } static int -api_sw_interface_virtio_pci_dump (vat_main_t * vam) +api_sr_mpls_policy_del (vat_main_t * vam) { - vl_api_sw_interface_virtio_pci_dump_t *mp; - vl_api_control_ping_t *mp_ping; + unformat_input_t *i = vam->input; + vl_api_sr_mpls_policy_del_t *mp; + u32 bsid = 0; int ret; - print (vam->ofp, - "\n%-12s %-12s %-12s %-12s %-17s %-08s", - "pci_addr", "sw_if_index", "rx_ring_sz", "tx_ring_sz", - "mac_addr", "features"); + /* Parse args required to build the message */ + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + { + if (unformat (i, "bsid %d", &bsid)) + ; + else + { + clib_warning ("parse error '%U'", format_unformat_error, i); + return -99; + } + } - /* Get list of tap interfaces */ - M (SW_INTERFACE_VIRTIO_PCI_DUMP, mp); - S (mp); + if (bsid == 0) + { + errmsg ("bsid not set"); + return -99; + } - /* Use a control ping for synchronization */ - MPING (CONTROL_PING, mp_ping); - S (mp_ping); + /* Construct the API message */ + M (SR_MPLS_POLICY_DEL, mp); + + mp->bsid = htonl (bsid); + + /* send it... */ + S (mp); + /* Wait for a reply... */ W (ret); return ret; } static int -api_vxlan_offload_rx (vat_main_t * vam) +api_bier_table_add_del (vat_main_t * vam) { - unformat_input_t *line_input = vam->input; - vl_api_vxlan_offload_rx_t *mp; - u32 hw_if_index = ~0, rx_if_index = ~0; + unformat_input_t *i = vam->input; + vl_api_bier_table_add_del_t *mp; u8 is_add = 1; + u32 set = 0, sub_domain = 0, hdr_len = 3; + mpls_label_t local_label = MPLS_LABEL_INVALID; int ret; - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + /* Parse args required to build the message */ + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (line_input, "del")) - is_add = 0; - else if (unformat (line_input, "hw %U", api_unformat_hw_if_index, vam, - &hw_if_index)) + if (unformat (i, "sub-domain %d", &sub_domain)) ; - else if (unformat (line_input, "hw hw_if_index %u", &hw_if_index)) + else if (unformat (i, "set %d", &set)) ; - else if (unformat (line_input, "rx %U", api_unformat_sw_if_index, vam, - &rx_if_index)) + else if (unformat (i, "label %d", &local_label)) ; - else if (unformat (line_input, "rx sw_if_index %u", &rx_if_index)) + else if (unformat (i, "hdr-len %d", &hdr_len)) ; + else if (unformat (i, "add")) + is_add = 1; + else if (unformat (i, "del")) + is_add = 0; else { - errmsg ("parse error '%U'", format_unformat_error, line_input); + clib_warning ("parse error '%U'", format_unformat_error, i); return -99; } } - if (hw_if_index == ~0) - { - errmsg ("no hw interface"); - return -99; - } - - if (rx_if_index == ~0) + if (MPLS_LABEL_INVALID == local_label) { - errmsg ("no rx tunnel"); + errmsg ("missing label\n"); return -99; } - M (VXLAN_OFFLOAD_RX, mp); + /* Construct the API message */ + M (BIER_TABLE_ADD_DEL, mp); - mp->hw_if_index = ntohl (hw_if_index); - mp->sw_if_index = ntohl (rx_if_index); - mp->enable = is_add; + mp->bt_is_add = is_add; + mp->bt_label = ntohl (local_label); + mp->bt_tbl_id.bt_set = set; + mp->bt_tbl_id.bt_sub_domain = sub_domain; + mp->bt_tbl_id.bt_hdr_len_id = hdr_len; + /* send it... */ S (mp); - W (ret); - return ret; -} -static uword unformat_vxlan_decap_next - (unformat_input_t * input, va_list * args) -{ - u32 *result = va_arg (*args, u32 *); - u32 tmp; + /* Wait for a reply... */ + W (ret); - if (unformat (input, "l2")) - *result = VXLAN_INPUT_NEXT_L2_INPUT; - else if (unformat (input, "%d", &tmp)) - *result = tmp; - else - return 0; - return 1; + return (ret); } static int -api_vxlan_add_del_tunnel (vat_main_t * vam) +api_bier_route_add_del (vat_main_t * vam) { - unformat_input_t *line_input = vam->input; - vl_api_vxlan_add_del_tunnel_t *mp; - ip46_address_t src, dst; + unformat_input_t *i = vam->input; + vl_api_bier_route_add_del_t *mp; u8 is_add = 1; - u8 ipv4_set = 0, ipv6_set = 0; - u8 src_set = 0; - u8 dst_set = 0; - u8 grp_set = 0; - u32 instance = ~0; - u32 mcast_sw_if_index = ~0; - u32 encap_vrf_id = 0; - u32 decap_next_index = ~0; - u32 vni = 0; + u32 set = 0, sub_domain = 0, hdr_len = 3, bp = 0; + ip4_address_t v4_next_hop_address; + ip6_address_t v6_next_hop_address; + u8 next_hop_set = 0; + u8 next_hop_proto_is_ip4 = 1; + mpls_label_t next_hop_out_label = MPLS_LABEL_INVALID; int ret; - /* Can't "universally zero init" (={0}) due to GCC bug 53119 */ - clib_memset (&src, 0, sizeof src); - clib_memset (&dst, 0, sizeof dst); - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + /* Parse args required to build the message */ + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (line_input, "del")) - is_add = 0; - else if (unformat (line_input, "instance %d", &instance)) - ; - else - if (unformat (line_input, "src %U", unformat_ip4_address, &src.ip4)) - { - ipv4_set = 1; - src_set = 1; - } - else - if (unformat (line_input, "dst %U", unformat_ip4_address, &dst.ip4)) - { - ipv4_set = 1; - dst_set = 1; - } - else - if (unformat (line_input, "src %U", unformat_ip6_address, &src.ip6)) - { - ipv6_set = 1; - src_set = 1; - } - else - if (unformat (line_input, "dst %U", unformat_ip6_address, &dst.ip6)) - { - ipv6_set = 1; - dst_set = 1; - } - else if (unformat (line_input, "group %U %U", - unformat_ip4_address, &dst.ip4, - api_unformat_sw_if_index, vam, &mcast_sw_if_index)) - { - grp_set = dst_set = 1; - ipv4_set = 1; - } - else if (unformat (line_input, "group %U", - unformat_ip4_address, &dst.ip4)) - { - grp_set = dst_set = 1; - ipv4_set = 1; - } - else if (unformat (line_input, "group %U %U", - unformat_ip6_address, &dst.ip6, - api_unformat_sw_if_index, vam, &mcast_sw_if_index)) + if (unformat (i, "%U", unformat_ip4_address, &v4_next_hop_address)) { - grp_set = dst_set = 1; - ipv6_set = 1; + next_hop_proto_is_ip4 = 1; + next_hop_set = 1; } - else if (unformat (line_input, "group %U", - unformat_ip6_address, &dst.ip6)) + else if (unformat (i, "%U", unformat_ip6_address, &v6_next_hop_address)) { - grp_set = dst_set = 1; - ipv6_set = 1; + next_hop_proto_is_ip4 = 0; + next_hop_set = 1; } - else - if (unformat (line_input, "mcast_sw_if_index %u", &mcast_sw_if_index)) + if (unformat (i, "sub-domain %d", &sub_domain)) ; - else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id)) + else if (unformat (i, "set %d", &set)) ; - else if (unformat (line_input, "decap-next %U", - unformat_vxlan_decap_next, &decap_next_index)) + else if (unformat (i, "hdr-len %d", &hdr_len)) ; - else if (unformat (line_input, "vni %d", &vni)) + else if (unformat (i, "bp %d", &bp)) + ; + else if (unformat (i, "add")) + is_add = 1; + else if (unformat (i, "del")) + is_add = 0; + else if (unformat (i, "out-label %d", &next_hop_out_label)) ; else { - errmsg ("parse error '%U'", format_unformat_error, line_input); + clib_warning ("parse error '%U'", format_unformat_error, i); return -99; } } - if (src_set == 0) + if (!next_hop_set || (MPLS_LABEL_INVALID == next_hop_out_label)) { - errmsg ("tunnel src address not specified"); + errmsg ("next hop / label set\n"); return -99; } - if (dst_set == 0) + if (0 == bp) { - errmsg ("tunnel dst address not specified"); + errmsg ("bit=position not set\n"); return -99; } - if (grp_set && !ip46_address_is_multicast (&dst)) - { - errmsg ("tunnel group address not multicast"); - return -99; - } - if (grp_set && mcast_sw_if_index == ~0) + /* Construct the API message */ + M2 (BIER_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t)); + + mp->br_is_add = is_add; + mp->br_route.br_tbl_id.bt_set = set; + mp->br_route.br_tbl_id.bt_sub_domain = sub_domain; + mp->br_route.br_tbl_id.bt_hdr_len_id = hdr_len; + mp->br_route.br_bp = ntohs (bp); + mp->br_route.br_n_paths = 1; + mp->br_route.br_paths[0].n_labels = 1; + mp->br_route.br_paths[0].label_stack[0].label = ntohl (next_hop_out_label); + mp->br_route.br_paths[0].proto = (next_hop_proto_is_ip4 ? + FIB_API_PATH_NH_PROTO_IP4 : + FIB_API_PATH_NH_PROTO_IP6); + + if (next_hop_proto_is_ip4) { - errmsg ("tunnel nonexistent multicast device"); - return -99; + clib_memcpy (&mp->br_route.br_paths[0].nh.address.ip4, + &v4_next_hop_address, sizeof (v4_next_hop_address)); } - if (grp_set == 0 && ip46_address_is_multicast (&dst)) + else { - errmsg ("tunnel dst address must be unicast"); - return -99; + clib_memcpy (&mp->br_route.br_paths[0].nh.address.ip6, + &v6_next_hop_address, sizeof (v6_next_hop_address)); } + /* send it... */ + S (mp); - if (ipv4_set && ipv6_set) - { - errmsg ("both IPv4 and IPv6 addresses specified"); - return -99; - } + /* Wait for a reply... */ + W (ret); - if ((vni == 0) || (vni >> 24)) - { - errmsg ("vni not specified or out of range"); - return -99; - } + return (ret); +} - M (VXLAN_ADD_DEL_TUNNEL, mp); +static int +api_mpls_tunnel_add_del (vat_main_t * vam) +{ + unformat_input_t *i = vam->input; + vl_api_mpls_tunnel_add_del_t *mp; - if (ipv6_set) - { - clib_memcpy (mp->src_address.un.ip6, &src.ip6, sizeof (src.ip6)); - clib_memcpy (mp->dst_address.un.ip6, &dst.ip6, sizeof (dst.ip6)); - } - else + vl_api_fib_path_t paths[8]; + u32 sw_if_index = ~0; + u8 path_count = 0; + u8 l2_only = 0; + u8 is_add = 1; + int ret; + + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - clib_memcpy (mp->src_address.un.ip4, &src.ip4, sizeof (src.ip4)); - clib_memcpy (mp->dst_address.un.ip4, &dst.ip4, sizeof (dst.ip4)); + if (unformat (i, "add")) + is_add = 1; + else + if (unformat + (i, "del %U", api_unformat_sw_if_index, vam, &sw_if_index)) + is_add = 0; + else if (unformat (i, "del sw_if_index %d", &sw_if_index)) + is_add = 0; + else if (unformat (i, "l2-only")) + l2_only = 1; + else + if (unformat + (i, "via %U", unformat_fib_path, vam, &paths[path_count])) + { + path_count++; + if (8 == path_count) + { + errmsg ("max 8 paths"); + return -99; + } + } + else + { + clib_warning ("parse error '%U'", format_unformat_error, i); + return -99; + } } - mp->src_address.af = ipv6_set; - mp->dst_address.af = ipv6_set; - mp->instance = htonl (instance); - mp->encap_vrf_id = ntohl (encap_vrf_id); - mp->decap_next_index = ntohl (decap_next_index); - mp->mcast_sw_if_index = ntohl (mcast_sw_if_index); - mp->vni = ntohl (vni); - mp->is_add = is_add; + M2 (MPLS_TUNNEL_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count); + + mp->mt_is_add = is_add; + mp->mt_tunnel.mt_sw_if_index = ntohl (sw_if_index); + mp->mt_tunnel.mt_l2_only = l2_only; + mp->mt_tunnel.mt_is_multicast = 0; + mp->mt_tunnel.mt_n_paths = path_count; + + clib_memcpy (&mp->mt_tunnel.mt_paths, &paths, + sizeof (paths[0]) * path_count); S (mp); W (ret); return ret; } -static void vl_api_vxlan_tunnel_details_t_handler - (vl_api_vxlan_tunnel_details_t * mp) -{ - vat_main_t *vam = &vat_main; - ip46_address_t src = - to_ip46 (mp->dst_address.af, (u8 *) & mp->dst_address.un); - ip46_address_t dst = - to_ip46 (mp->dst_address.af, (u8 *) & mp->src_address.un); - - print (vam->ofp, "%11d%11d%24U%24U%14d%18d%13d%19d", - ntohl (mp->sw_if_index), - ntohl (mp->instance), - format_ip46_address, &src, IP46_TYPE_ANY, - format_ip46_address, &dst, IP46_TYPE_ANY, - ntohl (mp->encap_vrf_id), - ntohl (mp->decap_next_index), ntohl (mp->vni), - ntohl (mp->mcast_sw_if_index)); -} - -static void vl_api_vxlan_tunnel_details_t_handler_json - (vl_api_vxlan_tunnel_details_t * mp) +static int +api_sw_interface_set_unnumbered (vat_main_t * vam) { - vat_main_t *vam = &vat_main; - vat_json_node_t *node = NULL; + unformat_input_t *i = vam->input; + vl_api_sw_interface_set_unnumbered_t *mp; + u32 sw_if_index; + u32 unnum_sw_index = ~0; + u8 is_add = 1; + u8 sw_if_index_set = 0; + int ret; - if (VAT_JSON_ARRAY != vam->json_tree.type) + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - ASSERT (VAT_JSON_NONE == vam->json_tree.type); - vat_json_init_array (&vam->json_tree); + if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) + sw_if_index_set = 1; + else if (unformat (i, "sw_if_index %d", &sw_if_index)) + sw_if_index_set = 1; + else if (unformat (i, "unnum_if_index %d", &unnum_sw_index)) + ; + else if (unformat (i, "del")) + is_add = 0; + else + { + clib_warning ("parse error '%U'", format_unformat_error, i); + return -99; + } } - node = vat_json_array_add (&vam->json_tree); - - vat_json_init_object (node); - vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index)); - - vat_json_object_add_uint (node, "instance", ntohl (mp->instance)); - if (mp->src_address.af) + if (sw_if_index_set == 0) { - struct in6_addr ip6; - - clib_memcpy (&ip6, mp->src_address.un.ip6, sizeof (ip6)); - vat_json_object_add_ip6 (node, "src_address", ip6); - clib_memcpy (&ip6, mp->dst_address.un.ip6, sizeof (ip6)); - vat_json_object_add_ip6 (node, "dst_address", ip6); + errmsg ("missing interface name or sw_if_index"); + return -99; } - else - { - struct in_addr ip4; - clib_memcpy (&ip4, mp->src_address.un.ip4, sizeof (ip4)); - vat_json_object_add_ip4 (node, "src_address", ip4); - clib_memcpy (&ip4, mp->dst_address.un.ip4, sizeof (ip4)); - vat_json_object_add_ip4 (node, "dst_address", ip4); - } - vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id)); - vat_json_object_add_uint (node, "decap_next_index", - ntohl (mp->decap_next_index)); - vat_json_object_add_uint (node, "vni", ntohl (mp->vni)); - vat_json_object_add_uint (node, "mcast_sw_if_index", - ntohl (mp->mcast_sw_if_index)); + M (SW_INTERFACE_SET_UNNUMBERED, mp); + + mp->sw_if_index = ntohl (sw_if_index); + mp->unnumbered_sw_if_index = ntohl (unnum_sw_index); + mp->is_add = is_add; + + S (mp); + W (ret); + return ret; } + static int -api_vxlan_tunnel_dump (vat_main_t * vam) +api_create_vlan_subif (vat_main_t * vam) { unformat_input_t *i = vam->input; - vl_api_vxlan_tunnel_dump_t *mp; - vl_api_control_ping_t *mp_ping; + vl_api_create_vlan_subif_t *mp; u32 sw_if_index; u8 sw_if_index_set = 0; + u32 vlan_id; + u8 vlan_id_set = 0; int ret; - /* Parse args required to build the message */ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { if (unformat (i, "sw_if_index %d", &sw_if_index)) sw_if_index_set = 1; else - break; + if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) + sw_if_index_set = 1; + else if (unformat (i, "vlan %d", &vlan_id)) + vlan_id_set = 1; + else + { + clib_warning ("parse error '%U'", format_unformat_error, i); + return -99; + } } if (sw_if_index_set == 0) { - sw_if_index = ~0; + errmsg ("missing interface name or sw_if_index"); + return -99; } - if (!vam->json_output) + if (vlan_id_set == 0) { - print (vam->ofp, "%11s%11s%24s%24s%14s%18s%13s%19s", - "sw_if_index", "instance", "src_address", "dst_address", - "encap_vrf_id", "decap_next_index", "vni", "mcast_sw_if_index"); + errmsg ("missing vlan_id"); + return -99; } + M (CREATE_VLAN_SUBIF, mp); - /* Get list of vxlan-tunnel interfaces */ - M (VXLAN_TUNNEL_DUMP, mp); - - mp->sw_if_index = htonl (sw_if_index); + mp->sw_if_index = ntohl (sw_if_index); + mp->vlan_id = ntohl (vlan_id); S (mp); - - /* Use a control ping for synchronization */ - MPING (CONTROL_PING, mp_ping); - S (mp_ping); - W (ret); return ret; } +#define foreach_create_subif_bit \ +_(no_tags) \ +_(one_tag) \ +_(two_tags) \ +_(dot1ad) \ +_(exact_match) \ +_(default_sub) \ +_(outer_vlan_id_any) \ +_(inner_vlan_id_any) + +#define foreach_create_subif_flag \ +_(0, "no_tags") \ +_(1, "one_tag") \ +_(2, "two_tags") \ +_(3, "dot1ad") \ +_(4, "exact_match") \ +_(5, "default_sub") \ +_(6, "outer_vlan_id_any") \ +_(7, "inner_vlan_id_any") + static int -api_gre_tunnel_add_del (vat_main_t * vam) +api_create_subif (vat_main_t * vam) { - unformat_input_t *line_input = vam->input; - vl_api_address_t src = { }, dst = - { - }; - vl_api_gre_tunnel_add_del_t *mp; - vl_api_gre_tunnel_type_t t_type; - u8 is_add = 1; - u8 src_set = 0; - u8 dst_set = 0; - u32 outer_table_id = 0; - u32 session_id = 0; - u32 instance = ~0; + unformat_input_t *i = vam->input; + vl_api_create_subif_t *mp; + u32 sw_if_index; + u8 sw_if_index_set = 0; + u32 sub_id; + u8 sub_id_set = 0; + u32 __attribute__ ((unused)) no_tags = 0; + u32 __attribute__ ((unused)) one_tag = 0; + u32 __attribute__ ((unused)) two_tags = 0; + u32 __attribute__ ((unused)) dot1ad = 0; + u32 __attribute__ ((unused)) exact_match = 0; + u32 __attribute__ ((unused)) default_sub = 0; + u32 __attribute__ ((unused)) outer_vlan_id_any = 0; + u32 __attribute__ ((unused)) inner_vlan_id_any = 0; + u32 tmp; + u16 outer_vlan_id = 0; + u16 inner_vlan_id = 0; int ret; - t_type = GRE_API_TUNNEL_TYPE_L3; - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (line_input, "del")) - is_add = 0; - else if (unformat (line_input, "instance %d", &instance)) - ; - else if (unformat (line_input, "src %U", unformat_vl_api_address, &src)) - { - src_set = 1; - } - else if (unformat (line_input, "dst %U", unformat_vl_api_address, &dst)) - { - dst_set = 1; - } - else if (unformat (line_input, "outer-table-id %d", &outer_table_id)) - ; - else if (unformat (line_input, "teb")) - t_type = GRE_API_TUNNEL_TYPE_TEB; - else if (unformat (line_input, "erspan %d", &session_id)) - t_type = GRE_API_TUNNEL_TYPE_ERSPAN; + if (unformat (i, "sw_if_index %d", &sw_if_index)) + sw_if_index_set = 1; else + if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) + sw_if_index_set = 1; + else if (unformat (i, "sub_id %d", &sub_id)) + sub_id_set = 1; + else if (unformat (i, "outer_vlan_id %d", &tmp)) + outer_vlan_id = tmp; + else if (unformat (i, "inner_vlan_id %d", &tmp)) + inner_vlan_id = tmp; + +#define _(a) else if (unformat (i, #a)) a = 1 ; + foreach_create_subif_bit +#undef _ + else { - errmsg ("parse error '%U'", format_unformat_error, line_input); + clib_warning ("parse error '%U'", format_unformat_error, i); return -99; } } - if (src_set == 0) + if (sw_if_index_set == 0) { - errmsg ("tunnel src address not specified"); + errmsg ("missing interface name or sw_if_index"); return -99; } - if (dst_set == 0) + + if (sub_id_set == 0) { - errmsg ("tunnel dst address not specified"); + errmsg ("missing sub_id"); return -99; } + M (CREATE_SUBIF, mp); - M (GRE_TUNNEL_ADD_DEL, mp); + mp->sw_if_index = ntohl (sw_if_index); + mp->sub_id = ntohl (sub_id); - clib_memcpy (&mp->tunnel.src, &src, sizeof (mp->tunnel.src)); - clib_memcpy (&mp->tunnel.dst, &dst, sizeof (mp->tunnel.dst)); +#define _(a,b) mp->sub_if_flags |= (1 << a); + foreach_create_subif_flag; +#undef _ - mp->tunnel.instance = htonl (instance); - mp->tunnel.outer_table_id = htonl (outer_table_id); - mp->is_add = is_add; - mp->tunnel.session_id = htons ((u16) session_id); - mp->tunnel.type = htonl (t_type); + mp->outer_vlan_id = ntohs (outer_vlan_id); + mp->inner_vlan_id = ntohs (inner_vlan_id); S (mp); W (ret); return ret; } -static void vl_api_gre_tunnel_details_t_handler - (vl_api_gre_tunnel_details_t * mp) -{ - vat_main_t *vam = &vat_main; - - print (vam->ofp, "%11d%11d%24U%24U%13d%14d%12d", - ntohl (mp->tunnel.sw_if_index), - ntohl (mp->tunnel.instance), - format_vl_api_address, &mp->tunnel.src, - format_vl_api_address, &mp->tunnel.dst, - mp->tunnel.type, ntohl (mp->tunnel.outer_table_id), - ntohl (mp->tunnel.session_id)); -} - -static void vl_api_gre_tunnel_details_t_handler_json - (vl_api_gre_tunnel_details_t * mp) +static int +api_ip_table_replace_begin (vat_main_t * vam) { - vat_main_t *vam = &vat_main; - vat_json_node_t *node = NULL; + unformat_input_t *i = vam->input; + vl_api_ip_table_replace_begin_t *mp; + u32 table_id = 0; + u8 is_ipv6 = 0; - if (VAT_JSON_ARRAY != vam->json_tree.type) + int ret; + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - ASSERT (VAT_JSON_NONE == vam->json_tree.type); - vat_json_init_array (&vam->json_tree); + if (unformat (i, "table %d", &table_id)) + ; + else if (unformat (i, "ipv6")) + is_ipv6 = 1; + else + { + clib_warning ("parse error '%U'", format_unformat_error, i); + return -99; + } } - node = vat_json_array_add (&vam->json_tree); - vat_json_init_object (node); - vat_json_object_add_uint (node, "sw_if_index", - ntohl (mp->tunnel.sw_if_index)); - vat_json_object_add_uint (node, "instance", ntohl (mp->tunnel.instance)); + M (IP_TABLE_REPLACE_BEGIN, mp); - vat_json_object_add_address (node, "src", &mp->tunnel.src); - vat_json_object_add_address (node, "dst", &mp->tunnel.dst); - vat_json_object_add_uint (node, "tunnel_type", mp->tunnel.type); - vat_json_object_add_uint (node, "outer_table_id", - ntohl (mp->tunnel.outer_table_id)); - vat_json_object_add_uint (node, "session_id", mp->tunnel.session_id); + mp->table.table_id = ntohl (table_id); + mp->table.is_ip6 = is_ipv6; + + S (mp); + W (ret); + return ret; } static int -api_gre_tunnel_dump (vat_main_t * vam) +api_ip_table_flush (vat_main_t * vam) { unformat_input_t *i = vam->input; - vl_api_gre_tunnel_dump_t *mp; - vl_api_control_ping_t *mp_ping; - u32 sw_if_index; - u8 sw_if_index_set = 0; - int ret; + vl_api_ip_table_flush_t *mp; + u32 table_id = 0; + u8 is_ipv6 = 0; - /* Parse args required to build the message */ + int ret; while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (i, "sw_if_index %d", &sw_if_index)) - sw_if_index_set = 1; + if (unformat (i, "table %d", &table_id)) + ; + else if (unformat (i, "ipv6")) + is_ipv6 = 1; else - break; - } - - if (sw_if_index_set == 0) - { - sw_if_index = ~0; - } - - if (!vam->json_output) - { - print (vam->ofp, "%11s%11s%24s%24s%13s%14s%12s", - "sw_if_index", "instance", "src_address", "dst_address", - "tunnel_type", "outer_fib_id", "session_id"); + { + clib_warning ("parse error '%U'", format_unformat_error, i); + return -99; + } } - /* Get list of gre-tunnel interfaces */ - M (GRE_TUNNEL_DUMP, mp); + M (IP_TABLE_FLUSH, mp); - mp->sw_if_index = htonl (sw_if_index); + mp->table.table_id = ntohl (table_id); + mp->table.is_ip6 = is_ipv6; S (mp); - - /* Use a control ping for synchronization */ - MPING (CONTROL_PING, mp_ping); - S (mp_ping); - W (ret); return ret; } static int -api_l2_fib_clear_table (vat_main_t * vam) +api_ip_table_replace_end (vat_main_t * vam) { -// unformat_input_t * i = vam->input; - vl_api_l2_fib_clear_table_t *mp; + unformat_input_t *i = vam->input; + vl_api_ip_table_replace_end_t *mp; + u32 table_id = 0; + u8 is_ipv6 = 0; + int ret; + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + { + if (unformat (i, "table %d", &table_id)) + ; + else if (unformat (i, "ipv6")) + is_ipv6 = 1; + else + { + clib_warning ("parse error '%U'", format_unformat_error, i); + return -99; + } + } - M (L2_FIB_CLEAR_TABLE, mp); + M (IP_TABLE_REPLACE_END, mp); + + mp->table.table_id = ntohl (table_id); + mp->table.is_ip6 = is_ipv6; S (mp); W (ret); @@ -11790,25 +7242,40 @@ api_l2_fib_clear_table (vat_main_t * vam) } static int -api_l2_interface_efp_filter (vat_main_t * vam) +api_set_ip_flow_hash (vat_main_t * vam) { unformat_input_t *i = vam->input; - vl_api_l2_interface_efp_filter_t *mp; - u32 sw_if_index; - u8 enable = 1; - u8 sw_if_index_set = 0; + vl_api_set_ip_flow_hash_t *mp; + u32 vrf_id = 0; + u8 is_ipv6 = 0; + u8 vrf_id_set = 0; + u8 src = 0; + u8 dst = 0; + u8 sport = 0; + u8 dport = 0; + u8 proto = 0; + u8 reverse = 0; int ret; while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) - sw_if_index_set = 1; - else if (unformat (i, "sw_if_index %d", &sw_if_index)) - sw_if_index_set = 1; - else if (unformat (i, "enable")) - enable = 1; - else if (unformat (i, "disable")) - enable = 0; + if (unformat (i, "vrf %d", &vrf_id)) + vrf_id_set = 1; + else if (unformat (i, "ipv6")) + is_ipv6 = 1; + else if (unformat (i, "src")) + src = 1; + else if (unformat (i, "dst")) + dst = 1; + else if (unformat (i, "sport")) + sport = 1; + else if (unformat (i, "dport")) + dport = 1; + else if (unformat (i, "proto")) + proto = 1; + else if (unformat (i, "reverse")) + reverse = 1; + else { clib_warning ("parse error '%U'", format_unformat_error, i); @@ -11816,45 +7283,35 @@ api_l2_interface_efp_filter (vat_main_t * vam) } } - if (sw_if_index_set == 0) + if (vrf_id_set == 0) { - errmsg ("missing sw_if_index"); + errmsg ("missing vrf id"); return -99; } - M (L2_INTERFACE_EFP_FILTER, mp); - - mp->sw_if_index = ntohl (sw_if_index); - mp->enable_disable = enable; + M (SET_IP_FLOW_HASH, mp); + mp->src = src; + mp->dst = dst; + mp->sport = sport; + mp->dport = dport; + mp->proto = proto; + mp->reverse = reverse; + mp->vrf_id = ntohl (vrf_id); + mp->is_ipv6 = is_ipv6; S (mp); W (ret); return ret; } -#define foreach_vtr_op \ -_("disable", L2_VTR_DISABLED) \ -_("push-1", L2_VTR_PUSH_1) \ -_("push-2", L2_VTR_PUSH_2) \ -_("pop-1", L2_VTR_POP_1) \ -_("pop-2", L2_VTR_POP_2) \ -_("translate-1-1", L2_VTR_TRANSLATE_1_1) \ -_("translate-1-2", L2_VTR_TRANSLATE_1_2) \ -_("translate-2-1", L2_VTR_TRANSLATE_2_1) \ -_("translate-2-2", L2_VTR_TRANSLATE_2_2) - static int -api_l2_interface_vlan_tag_rewrite (vat_main_t * vam) +api_sw_interface_ip6_enable_disable (vat_main_t * vam) { unformat_input_t *i = vam->input; - vl_api_l2_interface_vlan_tag_rewrite_t *mp; + vl_api_sw_interface_ip6_enable_disable_t *mp; u32 sw_if_index; u8 sw_if_index_set = 0; - u8 vtr_op_set = 0; - u32 vtr_op = 0; - u32 push_dot1q = 1; - u32 tag1 = ~0; - u32 tag2 = ~0; + u8 enable = 0; int ret; while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) @@ -11863,17 +7320,10 @@ api_l2_interface_vlan_tag_rewrite (vat_main_t * vam) sw_if_index_set = 1; else if (unformat (i, "sw_if_index %d", &sw_if_index)) sw_if_index_set = 1; - else if (unformat (i, "vtr_op %d", &vtr_op)) - vtr_op_set = 1; -#define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;} - foreach_vtr_op -#undef _ - else if (unformat (i, "push_dot1q %d", &push_dot1q)) - ; - else if (unformat (i, "tag1 %d", &tag1)) - ; - else if (unformat (i, "tag2 %d", &tag2)) - ; + else if (unformat (i, "enable")) + enable = 1; + else if (unformat (i, "disable")) + enable = 0; else { clib_warning ("parse error '%U'", format_unformat_error, i); @@ -11881,179 +7331,149 @@ api_l2_interface_vlan_tag_rewrite (vat_main_t * vam) } } - if ((sw_if_index_set == 0) || (vtr_op_set == 0)) + if (sw_if_index_set == 0) { - errmsg ("missing vtr operation or sw_if_index"); + errmsg ("missing interface name or sw_if_index"); return -99; } - M (L2_INTERFACE_VLAN_TAG_REWRITE, mp); + M (SW_INTERFACE_IP6_ENABLE_DISABLE, mp); + mp->sw_if_index = ntohl (sw_if_index); - mp->vtr_op = ntohl (vtr_op); - mp->push_dot1q = ntohl (push_dot1q); - mp->tag1 = ntohl (tag1); - mp->tag2 = ntohl (tag2); + mp->enable = enable; S (mp); W (ret); return ret; } + static int -api_create_vhost_user_if (vat_main_t * vam) +api_l2_patch_add_del (vat_main_t * vam) { unformat_input_t *i = vam->input; - vl_api_create_vhost_user_if_t *mp; - u8 *file_name; - u8 is_server = 0; - u8 file_name_set = 0; - u32 custom_dev_instance = ~0; - u8 hwaddr[6]; - u8 use_custom_mac = 0; - u8 disable_mrg_rxbuf = 0; - u8 disable_indirect_desc = 0; - u8 *tag = 0; - u8 enable_gso = 0; - u8 enable_packed = 0; + vl_api_l2_patch_add_del_t *mp; + u32 rx_sw_if_index; + u8 rx_sw_if_index_set = 0; + u32 tx_sw_if_index; + u8 tx_sw_if_index_set = 0; + u8 is_add = 1; int ret; - /* Shut up coverity */ - clib_memset (hwaddr, 0, sizeof (hwaddr)); - + /* Parse args required to build the message */ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (i, "socket %s", &file_name)) + if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index)) + rx_sw_if_index_set = 1; + else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index)) + tx_sw_if_index_set = 1; + else if (unformat (i, "rx")) { - file_name_set = 1; + if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + { + if (unformat (i, "%U", api_unformat_sw_if_index, vam, + &rx_sw_if_index)) + rx_sw_if_index_set = 1; + } + else + break; } - else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance)) - ; - else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr)) - use_custom_mac = 1; - else if (unformat (i, "server")) - is_server = 1; - else if (unformat (i, "disable_mrg_rxbuf")) - disable_mrg_rxbuf = 1; - else if (unformat (i, "disable_indirect_desc")) - disable_indirect_desc = 1; - else if (unformat (i, "gso")) - enable_gso = 1; - else if (unformat (i, "packed")) - enable_packed = 1; - else if (unformat (i, "tag %s", &tag)) - ; + else if (unformat (i, "tx")) + { + if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + { + if (unformat (i, "%U", api_unformat_sw_if_index, vam, + &tx_sw_if_index)) + tx_sw_if_index_set = 1; + } + else + break; + } + else if (unformat (i, "del")) + is_add = 0; else break; } - if (file_name_set == 0) + if (rx_sw_if_index_set == 0) { - errmsg ("missing socket file name"); + errmsg ("missing rx interface name or rx_sw_if_index"); return -99; } - if (vec_len (file_name) > 255) + if (tx_sw_if_index_set == 0) { - errmsg ("socket file name too long"); + errmsg ("missing tx interface name or tx_sw_if_index"); return -99; } - vec_add1 (file_name, 0); - - M (CREATE_VHOST_USER_IF, mp); - mp->is_server = is_server; - mp->disable_mrg_rxbuf = disable_mrg_rxbuf; - mp->disable_indirect_desc = disable_indirect_desc; - mp->enable_gso = enable_gso; - mp->enable_packed = enable_packed; - clib_memcpy (mp->sock_filename, file_name, vec_len (file_name)); - vec_free (file_name); - if (custom_dev_instance != ~0) - { - mp->renumber = 1; - mp->custom_dev_instance = ntohl (custom_dev_instance); - } + M (L2_PATCH_ADD_DEL, mp); - mp->use_custom_mac = use_custom_mac; - clib_memcpy (mp->mac_address, hwaddr, 6); - if (tag) - strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1); - vec_free (tag); + mp->rx_sw_if_index = ntohl (rx_sw_if_index); + mp->tx_sw_if_index = ntohl (tx_sw_if_index); + mp->is_add = is_add; S (mp); W (ret); return ret; } +u8 is_del; +u8 localsid_addr[16]; +u8 end_psp; +u8 behavior; +u32 sw_if_index; +u32 vlan_index; +u32 fib_table; +u8 nh_addr[16]; + static int -api_modify_vhost_user_if (vat_main_t * vam) +api_sr_localsid_add_del (vat_main_t * vam) { unformat_input_t *i = vam->input; - vl_api_modify_vhost_user_if_t *mp; - u8 *file_name; - u8 is_server = 0; - u8 file_name_set = 0; - u32 custom_dev_instance = ~0; - u8 sw_if_index_set = 0; - u32 sw_if_index = (u32) ~ 0; - u8 enable_gso = 0; - u8 enable_packed = 0; + vl_api_sr_localsid_add_del_t *mp; + + u8 is_del; + ip6_address_t localsid; + u8 end_psp = 0; + u8 behavior = ~0; + u32 sw_if_index; + u32 fib_table = ~(u32) 0; + ip46_address_t nh_addr; + clib_memset (&nh_addr, 0, sizeof (ip46_address_t)); + + bool nexthop_set = 0; + int ret; while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) - sw_if_index_set = 1; - else if (unformat (i, "sw_if_index %d", &sw_if_index)) - sw_if_index_set = 1; - else if (unformat (i, "socket %s", &file_name)) - { - file_name_set = 1; - } - else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance)) - ; - else if (unformat (i, "server")) - is_server = 1; - else if (unformat (i, "gso")) - enable_gso = 1; - else if (unformat (i, "packed")) - enable_packed = 1; + if (unformat (i, "del")) + is_del = 1; + else if (unformat (i, "address %U", unformat_ip6_address, &localsid)); + else if (unformat (i, "next-hop %U", unformat_ip46_address, &nh_addr)) + nexthop_set = 1; + else if (unformat (i, "behavior %u", &behavior)); + else if (unformat (i, "sw_if_index %u", &sw_if_index)); + else if (unformat (i, "fib-table %u", &fib_table)); + else if (unformat (i, "end.psp %u", &behavior)); else break; } - if (sw_if_index_set == 0) - { - errmsg ("missing sw_if_index or interface name"); - return -99; - } + M (SR_LOCALSID_ADD_DEL, mp); - if (file_name_set == 0) - { - errmsg ("missing socket file name"); - return -99; - } + clib_memcpy (mp->localsid, &localsid, sizeof (mp->localsid)); - if (vec_len (file_name) > 255) + if (nexthop_set) { - errmsg ("socket file name too long"); - return -99; + clib_memcpy (&mp->nh_addr.un, &nh_addr, sizeof (mp->nh_addr.un)); } - vec_add1 (file_name, 0); - - M (MODIFY_VHOST_USER_IF, mp); - + mp->behavior = behavior; mp->sw_if_index = ntohl (sw_if_index); - mp->is_server = is_server; - mp->enable_gso = enable_gso; - mp->enable_packed = enable_packed; - clib_memcpy (mp->sock_filename, file_name, vec_len (file_name)); - vec_free (file_name); - if (custom_dev_instance != ~0) - { - mp->renumber = 1; - mp->custom_dev_instance = ntohl (custom_dev_instance); - } + mp->fib_table = ntohl (fib_table); + mp->end_psp = end_psp; + mp->is_del = is_del; S (mp); W (ret); @@ -12061,1317 +7481,1342 @@ api_modify_vhost_user_if (vat_main_t * vam) } static int -api_delete_vhost_user_if (vat_main_t * vam) +api_ioam_enable (vat_main_t * vam) { - unformat_input_t *i = vam->input; - vl_api_delete_vhost_user_if_t *mp; - u32 sw_if_index = ~0; - u8 sw_if_index_set = 0; + unformat_input_t *input = vam->input; + vl_api_ioam_enable_t *mp; + u32 id = 0; + int has_trace_option = 0; + int has_pot_option = 0; + int has_seqno_option = 0; + int has_analyse_option = 0; int ret; - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { - if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) - sw_if_index_set = 1; - else if (unformat (i, "sw_if_index %d", &sw_if_index)) - sw_if_index_set = 1; + if (unformat (input, "trace")) + has_trace_option = 1; + else if (unformat (input, "pot")) + has_pot_option = 1; + else if (unformat (input, "seqno")) + has_seqno_option = 1; + else if (unformat (input, "analyse")) + has_analyse_option = 1; else break; } + M (IOAM_ENABLE, mp); + mp->id = htons (id); + mp->seqno = has_seqno_option; + mp->analyse = has_analyse_option; + mp->pot_enable = has_pot_option; + mp->trace_enable = has_trace_option; - if (sw_if_index_set == 0) - { - errmsg ("missing sw_if_index or interface name"); - return -99; - } - + S (mp); + W (ret); + return ret; +} - M (DELETE_VHOST_USER_IF, mp); - mp->sw_if_index = ntohl (sw_if_index); +static int +api_ioam_disable (vat_main_t * vam) +{ + vl_api_ioam_disable_t *mp; + int ret; + M (IOAM_DISABLE, mp); S (mp); W (ret); return ret; } -static void vl_api_sw_interface_vhost_user_details_t_handler - (vl_api_sw_interface_vhost_user_details_t * mp) +#define foreach_tcp_proto_field \ +_(src_port) \ +_(dst_port) + +#define foreach_udp_proto_field \ +_(src_port) \ +_(dst_port) + +#define foreach_ip4_proto_field \ +_(src_address) \ +_(dst_address) \ +_(tos) \ +_(length) \ +_(fragment_id) \ +_(ttl) \ +_(protocol) \ +_(checksum) + +typedef struct { - vat_main_t *vam = &vat_main; - u64 features; + u16 src_port, dst_port; +} tcpudp_header_t; - features = - clib_net_to_host_u32 (mp->features_first_32) | ((u64) - clib_net_to_host_u32 - (mp->features_last_32) << - 32); +#if VPP_API_TEST_BUILTIN == 0 +uword +unformat_tcp_mask (unformat_input_t * input, va_list * args) +{ + u8 **maskp = va_arg (*args, u8 **); + u8 *mask = 0; + u8 found_something = 0; + tcp_header_t *tcp; + +#define _(a) u8 a=0; + foreach_tcp_proto_field; +#undef _ + + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (0); +#define _(a) else if (unformat (input, #a)) a=1; + foreach_tcp_proto_field +#undef _ + else + break; + } + +#define _(a) found_something += a; + foreach_tcp_proto_field; +#undef _ + + if (found_something == 0) + return 0; + + vec_validate (mask, sizeof (*tcp) - 1); + + tcp = (tcp_header_t *) mask; + +#define _(a) if (a) clib_memset (&tcp->a, 0xff, sizeof (tcp->a)); + foreach_tcp_proto_field; +#undef _ - print (vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %8x %6d %7d %s", - (char *) mp->interface_name, - ntohl (mp->sw_if_index), ntohl (mp->virtio_net_hdr_sz), - features, mp->is_server, - ntohl (mp->num_regions), (char *) mp->sock_filename); - print (vam->ofp, " Status: '%s'", strerror (ntohl (mp->sock_errno))); + *maskp = mask; + return 1; } -static void vl_api_sw_interface_vhost_user_details_t_handler_json - (vl_api_sw_interface_vhost_user_details_t * mp) +uword +unformat_udp_mask (unformat_input_t * input, va_list * args) { - vat_main_t *vam = &vat_main; - vat_json_node_t *node = NULL; + u8 **maskp = va_arg (*args, u8 **); + u8 *mask = 0; + u8 found_something = 0; + udp_header_t *udp; - if (VAT_JSON_ARRAY != vam->json_tree.type) +#define _(a) u8 a=0; + foreach_udp_proto_field; +#undef _ + + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { - ASSERT (VAT_JSON_NONE == vam->json_tree.type); - vat_json_init_array (&vam->json_tree); + if (0); +#define _(a) else if (unformat (input, #a)) a=1; + foreach_udp_proto_field +#undef _ + else + break; } - node = vat_json_array_add (&vam->json_tree); - vat_json_init_object (node); - vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index)); - vat_json_object_add_string_copy (node, "interface_name", - mp->interface_name); - vat_json_object_add_uint (node, "virtio_net_hdr_sz", - ntohl (mp->virtio_net_hdr_sz)); - vat_json_object_add_uint (node, "features_first_32", - clib_net_to_host_u32 (mp->features_first_32)); - vat_json_object_add_uint (node, "features_last_32", - clib_net_to_host_u32 (mp->features_last_32)); - vat_json_object_add_uint (node, "is_server", mp->is_server); - vat_json_object_add_string_copy (node, "sock_filename", mp->sock_filename); - vat_json_object_add_uint (node, "num_regions", ntohl (mp->num_regions)); - vat_json_object_add_uint (node, "sock_errno", ntohl (mp->sock_errno)); +#define _(a) found_something += a; + foreach_udp_proto_field; +#undef _ + + if (found_something == 0) + return 0; + + vec_validate (mask, sizeof (*udp) - 1); + + udp = (udp_header_t *) mask; + +#define _(a) if (a) clib_memset (&udp->a, 0xff, sizeof (udp->a)); + foreach_udp_proto_field; +#undef _ + + *maskp = mask; + return 1; } -static int -api_sw_interface_vhost_user_dump (vat_main_t * vam) +uword +unformat_l4_mask (unformat_input_t * input, va_list * args) { - unformat_input_t *i = vam->input; - vl_api_sw_interface_vhost_user_dump_t *mp; - vl_api_control_ping_t *mp_ping; - int ret; - u32 sw_if_index = ~0; + u8 **maskp = va_arg (*args, u8 **); + u16 src_port = 0, dst_port = 0; + tcpudp_header_t *tcpudp; - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { - if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) - ; - else if (unformat (i, "sw_if_index %d", &sw_if_index)) - ; + if (unformat (input, "tcp %U", unformat_tcp_mask, maskp)) + return 1; + else if (unformat (input, "udp %U", unformat_udp_mask, maskp)) + return 1; + else if (unformat (input, "src_port")) + src_port = 0xFFFF; + else if (unformat (input, "dst_port")) + dst_port = 0xFFFF; else - break; + return 0; } - print (vam->ofp, - "Interface name idx hdr_sz features server regions filename"); + if (!src_port && !dst_port) + return 0; - /* Get list of vhost-user interfaces */ - M (SW_INTERFACE_VHOST_USER_DUMP, mp); - mp->sw_if_index = ntohl (sw_if_index); - S (mp); + u8 *mask = 0; + vec_validate (mask, sizeof (tcpudp_header_t) - 1); - /* Use a control ping for synchronization */ - MPING (CONTROL_PING, mp_ping); - S (mp_ping); + tcpudp = (tcpudp_header_t *) mask; + tcpudp->src_port = src_port; + tcpudp->dst_port = dst_port; - W (ret); - return ret; + *maskp = mask; + + return 1; } -static int -api_show_version (vat_main_t * vam) +uword +unformat_ip4_mask (unformat_input_t * input, va_list * args) { - vl_api_show_version_t *mp; - int ret; - - M (SHOW_VERSION, mp); - - S (mp); - W (ret); - return ret; -} + u8 **maskp = va_arg (*args, u8 **); + u8 *mask = 0; + u8 found_something = 0; + ip4_header_t *ip; +#define _(a) u8 a=0; + foreach_ip4_proto_field; +#undef _ + u8 version = 0; + u8 hdr_length = 0; -static int -api_vxlan_gpe_add_del_tunnel (vat_main_t * vam) -{ - unformat_input_t *line_input = vam->input; - vl_api_vxlan_gpe_add_del_tunnel_t *mp; - ip46_address_t local, remote; - u8 is_add = 1; - u8 local_set = 0; - u8 remote_set = 0; - u8 grp_set = 0; - u32 mcast_sw_if_index = ~0; - u32 encap_vrf_id = 0; - u32 decap_vrf_id = 0; - u8 protocol = ~0; - u32 vni; - u8 vni_set = 0; - int ret; - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { - if (unformat (line_input, "del")) - is_add = 0; - else if (unformat (line_input, "local %U", - unformat_ip46_address, &local)) - { - local_set = 1; - } - else if (unformat (line_input, "remote %U", - unformat_ip46_address, &remote)) - { - remote_set = 1; - } - else if (unformat (line_input, "group %U %U", - unformat_ip46_address, &remote, - api_unformat_sw_if_index, vam, &mcast_sw_if_index)) - { - grp_set = remote_set = 1; - } - else if (unformat (line_input, "group %U", - unformat_ip46_address, &remote)) - { - grp_set = remote_set = 1; - } - else - if (unformat (line_input, "mcast_sw_if_index %u", &mcast_sw_if_index)) - ; - else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id)) - ; - else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id)) - ; - else if (unformat (line_input, "vni %d", &vni)) - vni_set = 1; - else if (unformat (line_input, "next-ip4")) + if (unformat (input, "version")) + version = 1; + else if (unformat (input, "hdr_length")) + hdr_length = 1; + else if (unformat (input, "src")) + src_address = 1; + else if (unformat (input, "dst")) + dst_address = 1; + else if (unformat (input, "proto")) protocol = 1; - else if (unformat (line_input, "next-ip6")) - protocol = 2; - else if (unformat (line_input, "next-ethernet")) - protocol = 3; - else if (unformat (line_input, "next-nsh")) - protocol = 4; - else - { - errmsg ("parse error '%U'", format_unformat_error, line_input); - return -99; - } - } - if (local_set == 0) - { - errmsg ("tunnel local address not specified"); - return -99; - } - if (remote_set == 0) - { - errmsg ("tunnel remote address not specified"); - return -99; - } - if (grp_set && mcast_sw_if_index == ~0) - { - errmsg ("tunnel nonexistent multicast device"); - return -99; - } - if (ip46_address_is_ip4 (&local) != ip46_address_is_ip4 (&remote)) - { - errmsg ("both IPv4 and IPv6 addresses specified"); - return -99; +#define _(a) else if (unformat (input, #a)) a=1; + foreach_ip4_proto_field +#undef _ + else + break; } - if (vni_set == 0) - { - errmsg ("vni not specified"); - return -99; - } +#define _(a) found_something += a; + foreach_ip4_proto_field; +#undef _ - M (VXLAN_GPE_ADD_DEL_TUNNEL, mp); + if (found_something == 0) + return 0; - ip_address_encode (&local, - ip46_address_is_ip4 (&local) ? IP46_TYPE_IP4 : - IP46_TYPE_IP6, &mp->local); - ip_address_encode (&remote, - ip46_address_is_ip4 (&remote) ? IP46_TYPE_IP4 : - IP46_TYPE_IP6, &mp->remote); + vec_validate (mask, sizeof (*ip) - 1); - mp->mcast_sw_if_index = ntohl (mcast_sw_if_index); - mp->encap_vrf_id = ntohl (encap_vrf_id); - mp->decap_vrf_id = ntohl (decap_vrf_id); - mp->protocol = protocol; - mp->vni = ntohl (vni); - mp->is_add = is_add; + ip = (ip4_header_t *) mask; - S (mp); - W (ret); - return ret; -} +#define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a)); + foreach_ip4_proto_field; +#undef _ -static void vl_api_vxlan_gpe_tunnel_details_t_handler - (vl_api_vxlan_gpe_tunnel_details_t * mp) -{ - vat_main_t *vam = &vat_main; - ip46_address_t local, remote; + ip->ip_version_and_header_length = 0; - ip_address_decode (&mp->local, &local); - ip_address_decode (&mp->remote, &remote); + if (version) + ip->ip_version_and_header_length |= 0xF0; - print (vam->ofp, "%11d%24U%24U%13d%12d%19d%14d%14d", - ntohl (mp->sw_if_index), - format_ip46_address, &local, IP46_TYPE_ANY, - format_ip46_address, &remote, IP46_TYPE_ANY, - ntohl (mp->vni), mp->protocol, - ntohl (mp->mcast_sw_if_index), - ntohl (mp->encap_vrf_id), ntohl (mp->decap_vrf_id)); + if (hdr_length) + ip->ip_version_and_header_length |= 0x0F; + + *maskp = mask; + return 1; } +#define foreach_ip6_proto_field \ +_(src_address) \ +_(dst_address) \ +_(payload_length) \ +_(hop_limit) \ +_(protocol) -static void vl_api_vxlan_gpe_tunnel_details_t_handler_json - (vl_api_vxlan_gpe_tunnel_details_t * mp) +uword +unformat_ip6_mask (unformat_input_t * input, va_list * args) { - vat_main_t *vam = &vat_main; - vat_json_node_t *node = NULL; - struct in_addr ip4; - struct in6_addr ip6; - ip46_address_t local, remote; + u8 **maskp = va_arg (*args, u8 **); + u8 *mask = 0; + u8 found_something = 0; + ip6_header_t *ip; + u32 ip_version_traffic_class_and_flow_label; - ip_address_decode (&mp->local, &local); - ip_address_decode (&mp->remote, &remote); +#define _(a) u8 a=0; + foreach_ip6_proto_field; +#undef _ + u8 version = 0; + u8 traffic_class = 0; + u8 flow_label = 0; - if (VAT_JSON_ARRAY != vam->json_tree.type) + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { - ASSERT (VAT_JSON_NONE == vam->json_tree.type); - vat_json_init_array (&vam->json_tree); - } - node = vat_json_array_add (&vam->json_tree); + if (unformat (input, "version")) + version = 1; + else if (unformat (input, "traffic-class")) + traffic_class = 1; + else if (unformat (input, "flow-label")) + flow_label = 1; + else if (unformat (input, "src")) + src_address = 1; + else if (unformat (input, "dst")) + dst_address = 1; + else if (unformat (input, "proto")) + protocol = 1; - vat_json_init_object (node); - vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index)); - if (ip46_address_is_ip4 (&local)) - { - clib_memcpy (&ip4, &local.ip4, sizeof (ip4)); - vat_json_object_add_ip4 (node, "local", ip4); - clib_memcpy (&ip4, &remote.ip4, sizeof (ip4)); - vat_json_object_add_ip4 (node, "remote", ip4); - } - else - { - clib_memcpy (&ip6, &local.ip6, sizeof (ip6)); - vat_json_object_add_ip6 (node, "local", ip6); - clib_memcpy (&ip6, &remote.ip6, sizeof (ip6)); - vat_json_object_add_ip6 (node, "remote", ip6); +#define _(a) else if (unformat (input, #a)) a=1; + foreach_ip6_proto_field +#undef _ + else + break; } - vat_json_object_add_uint (node, "vni", ntohl (mp->vni)); - vat_json_object_add_uint (node, "protocol", ntohl (mp->protocol)); - vat_json_object_add_uint (node, "mcast_sw_if_index", - ntohl (mp->mcast_sw_if_index)); - vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id)); - vat_json_object_add_uint (node, "decap_vrf_id", ntohl (mp->decap_vrf_id)); - vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6 ? 1 : 0); -} -static int -api_vxlan_gpe_tunnel_dump (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_vxlan_gpe_tunnel_dump_t *mp; - vl_api_control_ping_t *mp_ping; - u32 sw_if_index; - u8 sw_if_index_set = 0; - int ret; +#define _(a) found_something += a; + foreach_ip6_proto_field; +#undef _ - /* Parse args required to build the message */ - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "sw_if_index %d", &sw_if_index)) - sw_if_index_set = 1; - else - break; - } + if (found_something == 0) + return 0; - if (sw_if_index_set == 0) - { - sw_if_index = ~0; - } + vec_validate (mask, sizeof (*ip) - 1); - if (!vam->json_output) - { - print (vam->ofp, "%11s%24s%24s%13s%15s%19s%14s%14s", - "sw_if_index", "local", "remote", "vni", - "protocol", "mcast_sw_if_index", "encap_vrf_id", "decap_vrf_id"); - } + ip = (ip6_header_t *) mask; - /* Get list of vxlan-tunnel interfaces */ - M (VXLAN_GPE_TUNNEL_DUMP, mp); +#define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a)); + foreach_ip6_proto_field; +#undef _ - mp->sw_if_index = htonl (sw_if_index); + ip_version_traffic_class_and_flow_label = 0; - S (mp); + if (version) + ip_version_traffic_class_and_flow_label |= 0xF0000000; - /* Use a control ping for synchronization */ - MPING (CONTROL_PING, mp_ping); - S (mp_ping); + if (traffic_class) + ip_version_traffic_class_and_flow_label |= 0x0FF00000; - W (ret); - return ret; -} + if (flow_label) + ip_version_traffic_class_and_flow_label |= 0x000FFFFF; -static void vl_api_l2_fib_table_details_t_handler - (vl_api_l2_fib_table_details_t * mp) -{ - vat_main_t *vam = &vat_main; + ip->ip_version_traffic_class_and_flow_label = + clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label); - print (vam->ofp, "%3" PRIu32 " %U %3" PRIu32 - " %d %d %d", - ntohl (mp->bd_id), format_ethernet_address, mp->mac, - ntohl (mp->sw_if_index), mp->static_mac, mp->filter_mac, - mp->bvi_mac); + *maskp = mask; + return 1; } -static void vl_api_l2_fib_table_details_t_handler_json - (vl_api_l2_fib_table_details_t * mp) +uword +unformat_l3_mask (unformat_input_t * input, va_list * args) { - vat_main_t *vam = &vat_main; - vat_json_node_t *node = NULL; + u8 **maskp = va_arg (*args, u8 **); - if (VAT_JSON_ARRAY != vam->json_tree.type) + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { - ASSERT (VAT_JSON_NONE == vam->json_tree.type); - vat_json_init_array (&vam->json_tree); + if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp)) + return 1; + else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp)) + return 1; + else + break; } - node = vat_json_array_add (&vam->json_tree); - - vat_json_init_object (node); - vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id)); - vat_json_object_add_bytes (node, "mac", mp->mac, 6); - vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index)); - vat_json_object_add_uint (node, "static_mac", mp->static_mac); - vat_json_object_add_uint (node, "filter_mac", mp->filter_mac); - vat_json_object_add_uint (node, "bvi_mac", mp->bvi_mac); + return 0; } -static int -api_l2_fib_table_dump (vat_main_t * vam) +uword +unformat_l2_mask (unformat_input_t * input, va_list * args) { - unformat_input_t *i = vam->input; - vl_api_l2_fib_table_dump_t *mp; - vl_api_control_ping_t *mp_ping; - u32 bd_id; - u8 bd_id_set = 0; - int ret; + u8 **maskp = va_arg (*args, u8 **); + u8 *mask = 0; + u8 src = 0; + u8 dst = 0; + u8 proto = 0; + u8 tag1 = 0; + u8 tag2 = 0; + u8 ignore_tag1 = 0; + u8 ignore_tag2 = 0; + u8 cos1 = 0; + u8 cos2 = 0; + u8 dot1q = 0; + u8 dot1ad = 0; + int len = 14; - /* Parse args required to build the message */ - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { - if (unformat (i, "bd_id %d", &bd_id)) - bd_id_set = 1; + if (unformat (input, "src")) + src = 1; + else if (unformat (input, "dst")) + dst = 1; + else if (unformat (input, "proto")) + proto = 1; + else if (unformat (input, "tag1")) + tag1 = 1; + else if (unformat (input, "tag2")) + tag2 = 1; + else if (unformat (input, "ignore-tag1")) + ignore_tag1 = 1; + else if (unformat (input, "ignore-tag2")) + ignore_tag2 = 1; + else if (unformat (input, "cos1")) + cos1 = 1; + else if (unformat (input, "cos2")) + cos2 = 1; + else if (unformat (input, "dot1q")) + dot1q = 1; + else if (unformat (input, "dot1ad")) + dot1ad = 1; else - break; - } - - if (bd_id_set == 0) - { - errmsg ("missing bridge domain"); - return -99; + break; } + if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad + + ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0) + return 0; - print (vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI"); - - /* Get list of l2 fib entries */ - M (L2_FIB_TABLE_DUMP, mp); - - mp->bd_id = ntohl (bd_id); - S (mp); - - /* Use a control ping for synchronization */ - MPING (CONTROL_PING, mp_ping); - S (mp_ping); + if (tag1 || ignore_tag1 || cos1 || dot1q) + len = 18; + if (tag2 || ignore_tag2 || cos2 || dot1ad) + len = 22; - W (ret); - return ret; -} + vec_validate (mask, len - 1); + if (dst) + clib_memset (mask, 0xff, 6); -static int -api_interface_name_renumber (vat_main_t * vam) -{ - unformat_input_t *line_input = vam->input; - vl_api_interface_name_renumber_t *mp; - u32 sw_if_index = ~0; - u32 new_show_dev_instance = ~0; - int ret; + if (src) + clib_memset (mask + 6, 0xff, 6); - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + if (tag2 || dot1ad) { - if (unformat (line_input, "%U", api_unformat_sw_if_index, vam, - &sw_if_index)) - ; - else if (unformat (line_input, "sw_if_index %d", &sw_if_index)) - ; - else if (unformat (line_input, "new_show_dev_instance %d", - &new_show_dev_instance)) - ; - else - break; + /* inner vlan tag */ + if (tag2) + { + mask[19] = 0xff; + mask[18] = 0x0f; + } + if (cos2) + mask[18] |= 0xe0; + if (proto) + mask[21] = mask[20] = 0xff; + if (tag1) + { + mask[15] = 0xff; + mask[14] = 0x0f; + } + if (cos1) + mask[14] |= 0xe0; + *maskp = mask; + return 1; } - - if (sw_if_index == ~0) + if (tag1 | dot1q) { - errmsg ("missing interface name or sw_if_index"); - return -99; - } + if (tag1) + { + mask[15] = 0xff; + mask[14] = 0x0f; + } + if (cos1) + mask[14] |= 0xe0; + if (proto) + mask[16] = mask[17] = 0xff; - if (new_show_dev_instance == ~0) - { - errmsg ("missing new_show_dev_instance"); - return -99; + *maskp = mask; + return 1; } + if (cos2) + mask[18] |= 0xe0; + if (cos1) + mask[14] |= 0xe0; + if (proto) + mask[12] = mask[13] = 0xff; - M (INTERFACE_NAME_RENUMBER, mp); - - mp->sw_if_index = ntohl (sw_if_index); - mp->new_show_dev_instance = ntohl (new_show_dev_instance); - - S (mp); - W (ret); - return ret; + *maskp = mask; + return 1; } -static int -api_want_l2_macs_events (vat_main_t * vam) +uword +unformat_classify_mask (unformat_input_t * input, va_list * args) { - unformat_input_t *line_input = vam->input; - vl_api_want_l2_macs_events_t *mp; - u8 enable_disable = 1; - u32 scan_delay = 0; - u32 max_macs_in_event = 0; - u32 learn_limit = 0; - int ret; + u8 **maskp = va_arg (*args, u8 **); + u32 *skipp = va_arg (*args, u32 *); + u32 *matchp = va_arg (*args, u32 *); + u32 match; + u8 *mask = 0; + u8 *l2 = 0; + u8 *l3 = 0; + u8 *l4 = 0; + int i; - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { - if (unformat (line_input, "learn-limit %d", &learn_limit)) + if (unformat (input, "hex %U", unformat_hex_string, &mask)) ; - else if (unformat (line_input, "scan-delay %d", &scan_delay)) + else if (unformat (input, "l2 %U", unformat_l2_mask, &l2)) ; - else if (unformat (line_input, "max-entries %d", &max_macs_in_event)) + else if (unformat (input, "l3 %U", unformat_l3_mask, &l3)) + ; + else if (unformat (input, "l4 %U", unformat_l4_mask, &l4)) ; - else if (unformat (line_input, "disable")) - enable_disable = 0; else break; } - M (WANT_L2_MACS_EVENTS, mp); - mp->enable_disable = enable_disable; - mp->pid = htonl (getpid ()); - mp->learn_limit = htonl (learn_limit); - mp->scan_delay = (u8) scan_delay; - mp->max_macs_in_event = (u8) (max_macs_in_event / 10); - S (mp); - W (ret); - return ret; -} - -static int -api_input_acl_set_interface (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_input_acl_set_interface_t *mp; - u32 sw_if_index; - int sw_if_index_set; - u32 ip4_table_index = ~0; - u32 ip6_table_index = ~0; - u32 l2_table_index = ~0; - u8 is_add = 1; - int ret; - - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + if (l4 && !l3) { - if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) - sw_if_index_set = 1; - else if (unformat (i, "sw_if_index %d", &sw_if_index)) - sw_if_index_set = 1; - else if (unformat (i, "del")) - is_add = 0; - else if (unformat (i, "ip4-table %d", &ip4_table_index)) - ; - else if (unformat (i, "ip6-table %d", &ip6_table_index)) - ; - else if (unformat (i, "l2-table %d", &l2_table_index)) - ; - else - { - clib_warning ("parse error '%U'", format_unformat_error, i); - return -99; - } + vec_free (mask); + vec_free (l2); + vec_free (l4); + return 0; } - if (sw_if_index_set == 0) + if (mask || l2 || l3 || l4) { - errmsg ("missing interface name or sw_if_index"); - return -99; - } + if (l2 || l3 || l4) + { + /* "With a free Ethernet header in every package" */ + if (l2 == 0) + vec_validate (l2, 13); + mask = l2; + if (vec_len (l3)) + { + vec_append (mask, l3); + vec_free (l3); + } + if (vec_len (l4)) + { + vec_append (mask, l4); + vec_free (l4); + } + } - M (INPUT_ACL_SET_INTERFACE, mp); + /* Scan forward looking for the first significant mask octet */ + for (i = 0; i < vec_len (mask); i++) + if (mask[i]) + break; - mp->sw_if_index = ntohl (sw_if_index); - mp->ip4_table_index = ntohl (ip4_table_index); - mp->ip6_table_index = ntohl (ip6_table_index); - mp->l2_table_index = ntohl (l2_table_index); - mp->is_add = is_add; + /* compute (skip, match) params */ + *skipp = i / sizeof (u32x4); + vec_delete (mask, *skipp * sizeof (u32x4), 0); - S (mp); - W (ret); - return ret; -} + /* Pad mask to an even multiple of the vector size */ + while (vec_len (mask) % sizeof (u32x4)) + vec_add1 (mask, 0); -static int -api_output_acl_set_interface (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_output_acl_set_interface_t *mp; - u32 sw_if_index; - int sw_if_index_set; - u32 ip4_table_index = ~0; - u32 ip6_table_index = ~0; - u32 l2_table_index = ~0; - u8 is_add = 1; - int ret; + match = vec_len (mask) / sizeof (u32x4); - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) - sw_if_index_set = 1; - else if (unformat (i, "sw_if_index %d", &sw_if_index)) - sw_if_index_set = 1; - else if (unformat (i, "del")) - is_add = 0; - else if (unformat (i, "ip4-table %d", &ip4_table_index)) - ; - else if (unformat (i, "ip6-table %d", &ip6_table_index)) - ; - else if (unformat (i, "l2-table %d", &l2_table_index)) - ; - else - { - clib_warning ("parse error '%U'", format_unformat_error, i); - return -99; + for (i = match * sizeof (u32x4); i > 0; i -= sizeof (u32x4)) + { + u64 *tmp = (u64 *) (mask + (i - sizeof (u32x4))); + if (*tmp || *(tmp + 1)) + break; + match--; } - } + if (match == 0) + clib_warning ("BUG: match 0"); - if (sw_if_index_set == 0) - { - errmsg ("missing interface name or sw_if_index"); - return -99; - } + _vec_len (mask) = match * sizeof (u32x4); - M (OUTPUT_ACL_SET_INTERFACE, mp); + *matchp = match; + *maskp = mask; - mp->sw_if_index = ntohl (sw_if_index); - mp->ip4_table_index = ntohl (ip4_table_index); - mp->ip6_table_index = ntohl (ip6_table_index); - mp->l2_table_index = ntohl (l2_table_index); - mp->is_add = is_add; + return 1; + } - S (mp); - W (ret); - return ret; + return 0; } +#endif /* VPP_API_TEST_BUILTIN */ -static int -api_ip_address_dump (vat_main_t * vam) +#define foreach_l2_next \ +_(drop, DROP) \ +_(ethernet, ETHERNET_INPUT) \ +_(ip4, IP4_INPUT) \ +_(ip6, IP6_INPUT) + +uword +unformat_l2_next_index (unformat_input_t * input, va_list * args) { - unformat_input_t *i = vam->input; - vl_api_ip_address_dump_t *mp; - vl_api_control_ping_t *mp_ping; - u32 sw_if_index = ~0; - u8 sw_if_index_set = 0; - u8 ipv4_set = 0; - u8 ipv6_set = 0; - int ret; + u32 *miss_next_indexp = va_arg (*args, u32 *); + u32 next_index = 0; + u32 tmp; - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "sw_if_index %d", &sw_if_index)) - sw_if_index_set = 1; - else - if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) - sw_if_index_set = 1; - else if (unformat (i, "ipv4")) - ipv4_set = 1; - else if (unformat (i, "ipv6")) - ipv6_set = 1; - else - break; - } +#define _(n,N) \ + if (unformat (input, #n)) { next_index = L2_INPUT_CLASSIFY_NEXT_##N; goto out;} + foreach_l2_next; +#undef _ - if (ipv4_set && ipv6_set) + if (unformat (input, "%d", &tmp)) { - errmsg ("ipv4 and ipv6 flags cannot be both set"); - return -99; + next_index = tmp; + goto out; } - if ((!ipv4_set) && (!ipv6_set)) - { - errmsg ("no ipv4 nor ipv6 flag set"); - return -99; - } + return 0; - if (sw_if_index_set == 0) - { - errmsg ("missing interface name or sw_if_index"); - return -99; - } +out: + *miss_next_indexp = next_index; + return 1; +} - vam->current_sw_if_index = sw_if_index; - vam->is_ipv6 = ipv6_set; +#define foreach_ip_next \ +_(drop, DROP) \ +_(local, LOCAL) \ +_(rewrite, REWRITE) - M (IP_ADDRESS_DUMP, mp); - mp->sw_if_index = ntohl (sw_if_index); - mp->is_ipv6 = ipv6_set; - S (mp); +uword +api_unformat_ip_next_index (unformat_input_t * input, va_list * args) +{ + u32 *miss_next_indexp = va_arg (*args, u32 *); + u32 next_index = 0; + u32 tmp; - /* Use a control ping for synchronization */ - MPING (CONTROL_PING, mp_ping); - S (mp_ping); +#define _(n,N) \ + if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;} + foreach_ip_next; +#undef _ - W (ret); - return ret; + if (unformat (input, "%d", &tmp)) + { + next_index = tmp; + goto out; + } + + return 0; + +out: + *miss_next_indexp = next_index; + return 1; } -static int -api_ip_dump (vat_main_t * vam) +#define foreach_acl_next \ +_(deny, DENY) + +uword +api_unformat_acl_next_index (unformat_input_t * input, va_list * args) { - vl_api_ip_dump_t *mp; - vl_api_control_ping_t *mp_ping; - unformat_input_t *in = vam->input; - int ipv4_set = 0; - int ipv6_set = 0; - int is_ipv6; - int i; - int ret; + u32 *miss_next_indexp = va_arg (*args, u32 *); + u32 next_index = 0; + u32 tmp; - while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT) - { - if (unformat (in, "ipv4")) - ipv4_set = 1; - else if (unformat (in, "ipv6")) - ipv6_set = 1; - else - break; - } +#define _(n,N) \ + if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;} + foreach_acl_next; +#undef _ - if (ipv4_set && ipv6_set) + if (unformat (input, "permit")) { - errmsg ("ipv4 and ipv6 flags cannot be both set"); - return -99; + next_index = ~0; + goto out; } - - if ((!ipv4_set) && (!ipv6_set)) + else if (unformat (input, "%d", &tmp)) { - errmsg ("no ipv4 nor ipv6 flag set"); - return -99; + next_index = tmp; + goto out; } - is_ipv6 = ipv6_set; - vam->is_ipv6 = is_ipv6; + return 0; - /* free old data */ - for (i = 0; i < vec_len (vam->ip_details_by_sw_if_index[is_ipv6]); i++) - { - vec_free (vam->ip_details_by_sw_if_index[is_ipv6][i].addr); - } - vec_free (vam->ip_details_by_sw_if_index[is_ipv6]); +out: + *miss_next_indexp = next_index; + return 1; +} - M (IP_DUMP, mp); - mp->is_ipv6 = ipv6_set; - S (mp); +uword +unformat_policer_precolor (unformat_input_t * input, va_list * args) +{ + u32 *r = va_arg (*args, u32 *); - /* Use a control ping for synchronization */ - MPING (CONTROL_PING, mp_ping); - S (mp_ping); + if (unformat (input, "conform-color")) + *r = POLICE_CONFORM; + else if (unformat (input, "exceed-color")) + *r = POLICE_EXCEED; + else + return 0; - W (ret); - return ret; + return 1; } static int -api_ipsec_spd_add_del (vat_main_t * vam) +api_classify_add_del_table (vat_main_t * vam) { unformat_input_t *i = vam->input; - vl_api_ipsec_spd_add_del_t *mp; - u32 spd_id = ~0; - u8 is_add = 1; + vl_api_classify_add_del_table_t *mp; + + u32 nbuckets = 2; + u32 skip = ~0; + u32 match = ~0; + int is_add = 1; + int del_chain = 0; + u32 table_index = ~0; + u32 next_table_index = ~0; + u32 miss_next_index = ~0; + u32 memory_size = 32 << 20; + u8 *mask = 0; + u32 current_data_flag = 0; + int current_data_offset = 0; int ret; while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (i, "spd_id %d", &spd_id)) - ; - else if (unformat (i, "del")) + if (unformat (i, "del")) is_add = 0; - else + else if (unformat (i, "del-chain")) { - clib_warning ("parse error '%U'", format_unformat_error, i); - return -99; + is_add = 0; + del_chain = 1; } + else if (unformat (i, "buckets %d", &nbuckets)) + ; + else if (unformat (i, "memory_size %d", &memory_size)) + ; + else if (unformat (i, "skip %d", &skip)) + ; + else if (unformat (i, "match %d", &match)) + ; + else if (unformat (i, "table %d", &table_index)) + ; + else if (unformat (i, "mask %U", unformat_classify_mask, + &mask, &skip, &match)) + ; + else if (unformat (i, "next-table %d", &next_table_index)) + ; + else if (unformat (i, "miss-next %U", api_unformat_ip_next_index, + &miss_next_index)) + ; + else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index, + &miss_next_index)) + ; + else if (unformat (i, "acl-miss-next %U", api_unformat_acl_next_index, + &miss_next_index)) + ; + else if (unformat (i, "current-data-flag %d", ¤t_data_flag)) + ; + else if (unformat (i, "current-data-offset %d", ¤t_data_offset)) + ; + else + break; } - if (spd_id == ~0) + + if (is_add && mask == 0) { - errmsg ("spd_id must be set"); + errmsg ("Mask required"); return -99; } - M (IPSEC_SPD_ADD_DEL, mp); - - mp->spd_id = ntohl (spd_id); - mp->is_add = is_add; - - S (mp); - W (ret); - return ret; -} - -static int -api_ipsec_interface_add_del_spd (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_ipsec_interface_add_del_spd_t *mp; - u32 sw_if_index; - u8 sw_if_index_set = 0; - u32 spd_id = (u32) ~ 0; - u8 is_add = 1; - int ret; - - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + if (is_add && skip == ~0) { - if (unformat (i, "del")) - is_add = 0; - else if (unformat (i, "spd_id %d", &spd_id)) - ; - else - if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) - sw_if_index_set = 1; - else if (unformat (i, "sw_if_index %d", &sw_if_index)) - sw_if_index_set = 1; - else - { - clib_warning ("parse error '%U'", format_unformat_error, i); - return -99; - } - + errmsg ("skip count required"); + return -99; } - if (spd_id == (u32) ~ 0) + if (is_add && match == ~0) { - errmsg ("spd_id must be set"); + errmsg ("match count required"); return -99; } - if (sw_if_index_set == 0) + if (!is_add && table_index == ~0) { - errmsg ("missing interface name or sw_if_index"); + errmsg ("table index required for delete"); return -99; } - M (IPSEC_INTERFACE_ADD_DEL_SPD, mp); + M2 (CLASSIFY_ADD_DEL_TABLE, mp, vec_len (mask)); - mp->spd_id = ntohl (spd_id); - mp->sw_if_index = ntohl (sw_if_index); mp->is_add = is_add; + mp->del_chain = del_chain; + mp->table_index = ntohl (table_index); + mp->nbuckets = ntohl (nbuckets); + mp->memory_size = ntohl (memory_size); + mp->skip_n_vectors = ntohl (skip); + mp->match_n_vectors = ntohl (match); + mp->next_table_index = ntohl (next_table_index); + mp->miss_next_index = ntohl (miss_next_index); + mp->current_data_flag = ntohl (current_data_flag); + mp->current_data_offset = ntohl (current_data_offset); + mp->mask_len = ntohl (vec_len (mask)); + clib_memcpy (mp->mask, mask, vec_len (mask)); + + vec_free (mask); S (mp); W (ret); return ret; } -static int -api_ipsec_spd_entry_add_del (vat_main_t * vam) +#if VPP_API_TEST_BUILTIN == 0 +uword +unformat_l4_match (unformat_input_t * input, va_list * args) { - unformat_input_t *i = vam->input; - vl_api_ipsec_spd_entry_add_del_t *mp; - u8 is_add = 1, is_outbound = 0; - u32 spd_id = 0, sa_id = 0, protocol = 0, policy = 0; - i32 priority = 0; - u32 rport_start = 0, rport_stop = (u32) ~ 0; - u32 lport_start = 0, lport_stop = (u32) ~ 0; - vl_api_address_t laddr_start = { }, laddr_stop = - { - }, raddr_start = - { - }, raddr_stop = - { - }; - int ret; + u8 **matchp = va_arg (*args, u8 **); - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + u8 *proto_header = 0; + int src_port = 0; + int dst_port = 0; + + tcpudp_header_t h; + + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { - if (unformat (i, "del")) - is_add = 0; - if (unformat (i, "outbound")) - is_outbound = 1; - if (unformat (i, "inbound")) - is_outbound = 0; - else if (unformat (i, "spd_id %d", &spd_id)) - ; - else if (unformat (i, "sa_id %d", &sa_id)) - ; - else if (unformat (i, "priority %d", &priority)) - ; - else if (unformat (i, "protocol %d", &protocol)) - ; - else if (unformat (i, "lport_start %d", &lport_start)) - ; - else if (unformat (i, "lport_stop %d", &lport_stop)) - ; - else if (unformat (i, "rport_start %d", &rport_start)) - ; - else if (unformat (i, "rport_stop %d", &rport_stop)) - ; - else if (unformat (i, "laddr_start %U", - unformat_vl_api_address, &laddr_start)) - ; - else if (unformat (i, "laddr_stop %U", unformat_vl_api_address, - &laddr_stop)) - ; - else if (unformat (i, "raddr_start %U", unformat_vl_api_address, - &raddr_start)) + if (unformat (input, "src_port %d", &src_port)) ; - else if (unformat (i, "raddr_stop %U", unformat_vl_api_address, - &raddr_stop)) + else if (unformat (input, "dst_port %d", &dst_port)) ; else - if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy)) - { - if (policy == IPSEC_POLICY_ACTION_RESOLVE) - { - clib_warning ("unsupported action: 'resolve'"); - return -99; - } - } - else - { - clib_warning ("parse error '%U'", format_unformat_error, i); - return -99; - } + return 0; + } + + h.src_port = clib_host_to_net_u16 (src_port); + h.dst_port = clib_host_to_net_u16 (dst_port); + vec_validate (proto_header, sizeof (h) - 1); + memcpy (proto_header, &h, sizeof (h)); + + *matchp = proto_header; + return 1; +} + +uword +unformat_ip4_match (unformat_input_t * input, va_list * args) +{ + u8 **matchp = va_arg (*args, u8 **); + u8 *match = 0; + ip4_header_t *ip; + int version = 0; + u32 version_val; + int hdr_length = 0; + u32 hdr_length_val; + int src = 0, dst = 0; + ip4_address_t src_val, dst_val; + int proto = 0; + u32 proto_val; + int tos = 0; + u32 tos_val; + int length = 0; + u32 length_val; + int fragment_id = 0; + u32 fragment_id_val; + int ttl = 0; + int ttl_val; + int checksum = 0; + u32 checksum_val; + + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "version %d", &version_val)) + version = 1; + else if (unformat (input, "hdr_length %d", &hdr_length_val)) + hdr_length = 1; + else if (unformat (input, "src %U", unformat_ip4_address, &src_val)) + src = 1; + else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val)) + dst = 1; + else if (unformat (input, "proto %d", &proto_val)) + proto = 1; + else if (unformat (input, "tos %d", &tos_val)) + tos = 1; + else if (unformat (input, "length %d", &length_val)) + length = 1; + else if (unformat (input, "fragment_id %d", &fragment_id_val)) + fragment_id = 1; + else if (unformat (input, "ttl %d", &ttl_val)) + ttl = 1; + else if (unformat (input, "checksum %d", &checksum_val)) + checksum = 1; + else + break; } - M (IPSEC_SPD_ENTRY_ADD_DEL, mp); + if (version + hdr_length + src + dst + proto + tos + length + fragment_id + + ttl + checksum == 0) + return 0; - mp->is_add = is_add; + /* + * Aligned because we use the real comparison functions + */ + vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4)); - mp->entry.spd_id = ntohl (spd_id); - mp->entry.priority = ntohl (priority); - mp->entry.is_outbound = is_outbound; + ip = (ip4_header_t *) match; - clib_memcpy (&mp->entry.remote_address_start, &raddr_start, - sizeof (vl_api_address_t)); - clib_memcpy (&mp->entry.remote_address_stop, &raddr_stop, - sizeof (vl_api_address_t)); - clib_memcpy (&mp->entry.local_address_start, &laddr_start, - sizeof (vl_api_address_t)); - clib_memcpy (&mp->entry.local_address_stop, &laddr_stop, - sizeof (vl_api_address_t)); + /* These are realistically matched in practice */ + if (src) + ip->src_address.as_u32 = src_val.as_u32; + + if (dst) + ip->dst_address.as_u32 = dst_val.as_u32; + + if (proto) + ip->protocol = proto_val; + + + /* These are not, but they're included for completeness */ + if (version) + ip->ip_version_and_header_length |= (version_val & 0xF) << 4; + + if (hdr_length) + ip->ip_version_and_header_length |= (hdr_length_val & 0xF); + + if (tos) + ip->tos = tos_val; + + if (length) + ip->length = clib_host_to_net_u16 (length_val); - mp->entry.protocol = (u8) protocol; - mp->entry.local_port_start = ntohs ((u16) lport_start); - mp->entry.local_port_stop = ntohs ((u16) lport_stop); - mp->entry.remote_port_start = ntohs ((u16) rport_start); - mp->entry.remote_port_stop = ntohs ((u16) rport_stop); - mp->entry.policy = (u8) policy; - mp->entry.sa_id = ntohl (sa_id); + if (ttl) + ip->ttl = ttl_val; - S (mp); - W (ret); - return ret; + if (checksum) + ip->checksum = clib_host_to_net_u16 (checksum_val); + + *matchp = match; + return 1; } -static int -api_ipsec_sad_entry_add_del (vat_main_t * vam) +uword +unformat_ip6_match (unformat_input_t * input, va_list * args) { - unformat_input_t *i = vam->input; - vl_api_ipsec_sad_entry_add_del_t *mp; - u32 sad_id = 0, spi = 0; - u8 *ck = 0, *ik = 0; - u8 is_add = 1; - - vl_api_ipsec_crypto_alg_t crypto_alg = IPSEC_API_CRYPTO_ALG_NONE; - vl_api_ipsec_integ_alg_t integ_alg = IPSEC_API_INTEG_ALG_NONE; - vl_api_ipsec_sad_flags_t flags = IPSEC_API_SAD_FLAG_NONE; - vl_api_ipsec_proto_t protocol = IPSEC_API_PROTO_AH; - vl_api_address_t tun_src, tun_dst; - int ret; + u8 **matchp = va_arg (*args, u8 **); + u8 *match = 0; + ip6_header_t *ip; + int version = 0; + u32 version_val; + u8 traffic_class = 0; + u32 traffic_class_val = 0; + u8 flow_label = 0; + u8 flow_label_val; + int src = 0, dst = 0; + ip6_address_t src_val, dst_val; + int proto = 0; + u32 proto_val; + int payload_length = 0; + u32 payload_length_val; + int hop_limit = 0; + int hop_limit_val; + u32 ip_version_traffic_class_and_flow_label; - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { - if (unformat (i, "del")) - is_add = 0; - else if (unformat (i, "sad_id %d", &sad_id)) - ; - else if (unformat (i, "spi %d", &spi)) - ; - else if (unformat (i, "esp")) - protocol = IPSEC_API_PROTO_ESP; - else - if (unformat (i, "tunnel_src %U", unformat_vl_api_address, &tun_src)) - { - flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL; - if (ADDRESS_IP6 == tun_src.af) - flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL_V6; - } - else - if (unformat (i, "tunnel_dst %U", unformat_vl_api_address, &tun_dst)) - { - flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL; - if (ADDRESS_IP6 == tun_src.af) - flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL_V6; - } - else - if (unformat (i, "crypto_alg %U", - unformat_ipsec_api_crypto_alg, &crypto_alg)) - ; - else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck)) - ; - else if (unformat (i, "integ_alg %U", - unformat_ipsec_api_integ_alg, &integ_alg)) - ; - else if (unformat (i, "integ_key %U", unformat_hex_string, &ik)) - ; + if (unformat (input, "version %d", &version_val)) + version = 1; + else if (unformat (input, "traffic_class %d", &traffic_class_val)) + traffic_class = 1; + else if (unformat (input, "flow_label %d", &flow_label_val)) + flow_label = 1; + else if (unformat (input, "src %U", unformat_ip6_address, &src_val)) + src = 1; + else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val)) + dst = 1; + else if (unformat (input, "proto %d", &proto_val)) + proto = 1; + else if (unformat (input, "payload_length %d", &payload_length_val)) + payload_length = 1; + else if (unformat (input, "hop_limit %d", &hop_limit_val)) + hop_limit = 1; else - { - clib_warning ("parse error '%U'", format_unformat_error, i); - return -99; - } - + break; } - M (IPSEC_SAD_ENTRY_ADD_DEL, mp); + if (version + traffic_class + flow_label + src + dst + proto + + payload_length + hop_limit == 0) + return 0; - mp->is_add = is_add; - mp->entry.sad_id = ntohl (sad_id); - mp->entry.protocol = protocol; - mp->entry.spi = ntohl (spi); - mp->entry.flags = flags; + /* + * Aligned because we use the real comparison functions + */ + vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4)); - mp->entry.crypto_algorithm = crypto_alg; - mp->entry.integrity_algorithm = integ_alg; - mp->entry.crypto_key.length = vec_len (ck); - mp->entry.integrity_key.length = vec_len (ik); + ip = (ip6_header_t *) match; - if (mp->entry.crypto_key.length > sizeof (mp->entry.crypto_key.data)) - mp->entry.crypto_key.length = sizeof (mp->entry.crypto_key.data); + if (src) + clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address)); - if (mp->entry.integrity_key.length > sizeof (mp->entry.integrity_key.data)) - mp->entry.integrity_key.length = sizeof (mp->entry.integrity_key.data); + if (dst) + clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address)); - if (ck) - clib_memcpy (mp->entry.crypto_key.data, ck, mp->entry.crypto_key.length); - if (ik) - clib_memcpy (mp->entry.integrity_key.data, ik, - mp->entry.integrity_key.length); + if (proto) + ip->protocol = proto_val; - if (flags & IPSEC_API_SAD_FLAG_IS_TUNNEL) - { - clib_memcpy (&mp->entry.tunnel_src, &tun_src, - sizeof (mp->entry.tunnel_src)); - clib_memcpy (&mp->entry.tunnel_dst, &tun_dst, - sizeof (mp->entry.tunnel_dst)); - } + ip_version_traffic_class_and_flow_label = 0; - S (mp); - W (ret); - return ret; + if (version) + ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28; + + if (traffic_class) + ip_version_traffic_class_and_flow_label |= + (traffic_class_val & 0xFF) << 20; + + if (flow_label) + ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF); + + ip->ip_version_traffic_class_and_flow_label = + clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label); + + if (payload_length) + ip->payload_length = clib_host_to_net_u16 (payload_length_val); + + if (hop_limit) + ip->hop_limit = hop_limit_val; + + *matchp = match; + return 1; } -static int -api_ipsec_tunnel_if_add_del (vat_main_t * vam) +uword +unformat_l3_match (unformat_input_t * input, va_list * args) { - unformat_input_t *i = vam->input; - vl_api_ipsec_tunnel_if_add_del_t *mp; - u32 local_spi = 0, remote_spi = 0; - u32 crypto_alg = 0, integ_alg = 0; - u8 *lck = NULL, *rck = NULL; - u8 *lik = NULL, *rik = NULL; - vl_api_address_t local_ip = { 0 }; - vl_api_address_t remote_ip = { 0 }; - f64 before = 0; - u8 is_add = 1; - u8 esn = 0; - u8 anti_replay = 0; - u8 renumber = 0; - u32 instance = ~0; - u32 count = 1, jj; - int ret = -1; + u8 **matchp = va_arg (*args, u8 **); - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { - if (unformat (i, "del")) - is_add = 0; - else if (unformat (i, "esn")) - esn = 1; - else if (unformat (i, "anti-replay")) - anti_replay = 1; - else if (unformat (i, "count %d", &count)) - ; - else if (unformat (i, "local_spi %d", &local_spi)) - ; - else if (unformat (i, "remote_spi %d", &remote_spi)) - ; - else - if (unformat (i, "local_ip %U", unformat_vl_api_address, &local_ip)) - ; - else - if (unformat (i, "remote_ip %U", unformat_vl_api_address, &remote_ip)) - ; - else if (unformat (i, "local_crypto_key %U", unformat_hex_string, &lck)) - ; - else - if (unformat (i, "remote_crypto_key %U", unformat_hex_string, &rck)) - ; - else if (unformat (i, "local_integ_key %U", unformat_hex_string, &lik)) - ; - else if (unformat (i, "remote_integ_key %U", unformat_hex_string, &rik)) - ; - else - if (unformat - (i, "crypto_alg %U", unformat_ipsec_api_crypto_alg, &crypto_alg)) - { - if (crypto_alg >= IPSEC_CRYPTO_N_ALG) - { - errmsg ("unsupported crypto-alg: '%U'\n", - format_ipsec_crypto_alg, crypto_alg); - return -99; - } - } - else - if (unformat - (i, "integ_alg %U", unformat_ipsec_api_integ_alg, &integ_alg)) - { - if (integ_alg >= IPSEC_INTEG_N_ALG) - { - errmsg ("unsupported integ-alg: '%U'\n", - format_ipsec_integ_alg, integ_alg); - return -99; - } - } - else if (unformat (i, "instance %u", &instance)) - renumber = 1; - else - { - errmsg ("parse error '%U'\n", format_unformat_error, i); - return -99; - } + if (unformat (input, "ip4 %U", unformat_ip4_match, matchp)) + return 1; + else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp)) + return 1; + else + break; } + return 0; +} - if (count > 1) - { - /* Turn on async mode */ - vam->async_mode = 1; - vam->async_errors = 0; - before = vat_time_now (vam); - } +uword +unformat_vlan_tag (unformat_input_t * input, va_list * args) +{ + u8 *tagp = va_arg (*args, u8 *); + u32 tag; - for (jj = 0; jj < count; jj++) + if (unformat (input, "%d", &tag)) { - M (IPSEC_TUNNEL_IF_ADD_DEL, mp); + tagp[0] = (tag >> 8) & 0x0F; + tagp[1] = tag & 0xFF; + return 1; + } - mp->is_add = is_add; - mp->esn = esn; - mp->anti_replay = anti_replay; + return 0; +} - if (jj > 0) - increment_address (&remote_ip); +uword +unformat_l2_match (unformat_input_t * input, va_list * args) +{ + u8 **matchp = va_arg (*args, u8 **); + u8 *match = 0; + u8 src = 0; + u8 src_val[6]; + u8 dst = 0; + u8 dst_val[6]; + u8 proto = 0; + u16 proto_val; + u8 tag1 = 0; + u8 tag1_val[2]; + u8 tag2 = 0; + u8 tag2_val[2]; + int len = 14; + u8 ignore_tag1 = 0; + u8 ignore_tag2 = 0; + u8 cos1 = 0; + u8 cos2 = 0; + u32 cos1_val = 0; + u32 cos2_val = 0; - clib_memcpy (&mp->local_ip, &local_ip, sizeof (local_ip)); - clib_memcpy (&mp->remote_ip, &remote_ip, sizeof (remote_ip)); + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "src %U", unformat_ethernet_address, &src_val)) + src = 1; + else + if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val)) + dst = 1; + else if (unformat (input, "proto %U", + unformat_ethernet_type_host_byte_order, &proto_val)) + proto = 1; + else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val)) + tag1 = 1; + else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val)) + tag2 = 1; + else if (unformat (input, "ignore-tag1")) + ignore_tag1 = 1; + else if (unformat (input, "ignore-tag2")) + ignore_tag2 = 1; + else if (unformat (input, "cos1 %d", &cos1_val)) + cos1 = 1; + else if (unformat (input, "cos2 %d", &cos2_val)) + cos2 = 1; + else + break; + } + if ((src + dst + proto + tag1 + tag2 + + ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0) + return 0; - mp->local_spi = htonl (local_spi + jj); - mp->remote_spi = htonl (remote_spi + jj); - mp->crypto_alg = (u8) crypto_alg; + if (tag1 || ignore_tag1 || cos1) + len = 18; + if (tag2 || ignore_tag2 || cos2) + len = 22; - mp->local_crypto_key_len = 0; - if (lck) - { - mp->local_crypto_key_len = vec_len (lck); - if (mp->local_crypto_key_len > sizeof (mp->local_crypto_key)) - mp->local_crypto_key_len = sizeof (mp->local_crypto_key); - clib_memcpy (mp->local_crypto_key, lck, mp->local_crypto_key_len); - } + vec_validate_aligned (match, len - 1, sizeof (u32x4)); - mp->remote_crypto_key_len = 0; - if (rck) - { - mp->remote_crypto_key_len = vec_len (rck); - if (mp->remote_crypto_key_len > sizeof (mp->remote_crypto_key)) - mp->remote_crypto_key_len = sizeof (mp->remote_crypto_key); - clib_memcpy (mp->remote_crypto_key, rck, mp->remote_crypto_key_len); - } + if (dst) + clib_memcpy (match, dst_val, 6); - mp->integ_alg = (u8) integ_alg; + if (src) + clib_memcpy (match + 6, src_val, 6); - mp->local_integ_key_len = 0; - if (lik) + if (tag2) + { + /* inner vlan tag */ + match[19] = tag2_val[1]; + match[18] = tag2_val[0]; + if (cos2) + match[18] |= (cos2_val & 0x7) << 5; + if (proto) { - mp->local_integ_key_len = vec_len (lik); - if (mp->local_integ_key_len > sizeof (mp->local_integ_key)) - mp->local_integ_key_len = sizeof (mp->local_integ_key); - clib_memcpy (mp->local_integ_key, lik, mp->local_integ_key_len); + match[21] = proto_val & 0xff; + match[20] = proto_val >> 8; } - - mp->remote_integ_key_len = 0; - if (rik) + if (tag1) { - mp->remote_integ_key_len = vec_len (rik); - if (mp->remote_integ_key_len > sizeof (mp->remote_integ_key)) - mp->remote_integ_key_len = sizeof (mp->remote_integ_key); - clib_memcpy (mp->remote_integ_key, rik, mp->remote_integ_key_len); + match[15] = tag1_val[1]; + match[14] = tag1_val[0]; } - - if (renumber) + if (cos1) + match[14] |= (cos1_val & 0x7) << 5; + *matchp = match; + return 1; + } + if (tag1) + { + match[15] = tag1_val[1]; + match[14] = tag1_val[0]; + if (proto) { - mp->renumber = renumber; - mp->show_instance = ntohl (instance); + match[17] = proto_val & 0xff; + match[16] = proto_val >> 8; } - S (mp); - } + if (cos1) + match[14] |= (cos1_val & 0x7) << 5; - /* When testing multiple add/del ops, use a control-ping to sync */ - if (count > 1) + *matchp = match; + return 1; + } + if (cos2) + match[18] |= (cos2_val & 0x7) << 5; + if (cos1) + match[14] |= (cos1_val & 0x7) << 5; + if (proto) { - vl_api_control_ping_t *mp_ping; - f64 after; - f64 timeout; + match[13] = proto_val & 0xff; + match[12] = proto_val >> 8; + } - /* Shut off async mode */ - vam->async_mode = 0; + *matchp = match; + return 1; +} - MPING (CONTROL_PING, mp_ping); - S (mp_ping); +uword +unformat_qos_source (unformat_input_t * input, va_list * args) +{ + int *qs = va_arg (*args, int *); - timeout = vat_time_now (vam) + 1.0; - while (vat_time_now (vam) < timeout) - if (vam->result_ready == 1) - goto out; - vam->retval = -99; + if (unformat (input, "ip")) + *qs = QOS_SOURCE_IP; + else if (unformat (input, "mpls")) + *qs = QOS_SOURCE_MPLS; + else if (unformat (input, "ext")) + *qs = QOS_SOURCE_EXT; + else if (unformat (input, "vlan")) + *qs = QOS_SOURCE_VLAN; + else + return 0; - out: - if (vam->retval == -99) - errmsg ("timeout"); + return 1; +} +#endif - if (vam->async_errors > 0) +uword +api_unformat_classify_match (unformat_input_t * input, va_list * args) +{ + u8 **matchp = va_arg (*args, u8 **); + u32 skip_n_vectors = va_arg (*args, u32); + u32 match_n_vectors = va_arg (*args, u32); + + u8 *match = 0; + u8 *l2 = 0; + u8 *l3 = 0; + u8 *l4 = 0; + + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "hex %U", unformat_hex_string, &match)) + ; + else if (unformat (input, "l2 %U", unformat_l2_match, &l2)) + ; + else if (unformat (input, "l3 %U", unformat_l3_match, &l3)) + ; + else if (unformat (input, "l4 %U", unformat_l4_match, &l4)) + ; + else + break; + } + + if (l4 && !l3) + { + vec_free (match); + vec_free (l2); + vec_free (l4); + return 0; + } + + if (match || l2 || l3 || l4) + { + if (l2 || l3 || l4) { - errmsg ("%d asynchronous errors", vam->async_errors); - vam->retval = -98; + /* "Win a free Ethernet header in every packet" */ + if (l2 == 0) + vec_validate_aligned (l2, 13, sizeof (u32x4)); + match = l2; + if (vec_len (l3)) + { + vec_append_aligned (match, l3, sizeof (u32x4)); + vec_free (l3); + } + if (vec_len (l4)) + { + vec_append_aligned (match, l4, sizeof (u32x4)); + vec_free (l4); + } } - vam->async_errors = 0; - after = vat_time_now (vam); - /* slim chance, but we might have eaten SIGTERM on the first iteration */ - if (jj > 0) - count = jj; + /* Make sure the vector is big enough even if key is all 0's */ + vec_validate_aligned + (match, ((match_n_vectors + skip_n_vectors) * sizeof (u32x4)) - 1, + sizeof (u32x4)); - print (vam->ofp, "%d tunnels in %.6f secs, %.2f tunnels/sec", - count, after - before, count / (after - before)); - } - else - { - /* Wait for a reply... */ - W (ret); - return ret; + /* Set size, include skipped vectors */ + _vec_len (match) = (match_n_vectors + skip_n_vectors) * sizeof (u32x4); + + *matchp = match; + + return 1; } - return ret; + return 0; } -static void -vl_api_ipsec_sa_details_t_handler (vl_api_ipsec_sa_details_t * mp) +static int +api_classify_add_del_session (vat_main_t * vam) { - vat_main_t *vam = &vat_main; + unformat_input_t *i = vam->input; + vl_api_classify_add_del_session_t *mp; + int is_add = 1; + u32 table_index = ~0; + u32 hit_next_index = ~0; + u32 opaque_index = ~0; + u8 *match = 0; + i32 advance = 0; + u32 skip_n_vectors = 0; + u32 match_n_vectors = 0; + u32 action = 0; + u32 metadata = 0; + int ret; - print (vam->ofp, "sa_id %u sw_if_index %u spi %u proto %u crypto_alg %u " - "crypto_key %U integ_alg %u integ_key %U flags %x " - "tunnel_src_addr %U tunnel_dst_addr %U " - "salt %u seq_outbound %lu last_seq_inbound %lu " - "replay_window %lu stat_index %u\n", - ntohl (mp->entry.sad_id), - ntohl (mp->sw_if_index), - ntohl (mp->entry.spi), - ntohl (mp->entry.protocol), - ntohl (mp->entry.crypto_algorithm), - format_hex_bytes, mp->entry.crypto_key.data, - mp->entry.crypto_key.length, ntohl (mp->entry.integrity_algorithm), - format_hex_bytes, mp->entry.integrity_key.data, - mp->entry.integrity_key.length, ntohl (mp->entry.flags), - format_vl_api_address, &mp->entry.tunnel_src, format_vl_api_address, - &mp->entry.tunnel_dst, ntohl (mp->salt), - clib_net_to_host_u64 (mp->seq_outbound), - clib_net_to_host_u64 (mp->last_seq_inbound), - clib_net_to_host_u64 (mp->replay_window), ntohl (mp->stat_index)); -} + /* + * Warning: you have to supply skip_n and match_n + * because the API client cant simply look at the classify + * table object. + */ -#define vl_api_ipsec_sa_details_t_endian vl_noop_handler -#define vl_api_ipsec_sa_details_t_print vl_noop_handler + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + { + if (unformat (i, "del")) + is_add = 0; + else if (unformat (i, "hit-next %U", api_unformat_ip_next_index, + &hit_next_index)) + ; + else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index, + &hit_next_index)) + ; + else if (unformat (i, "acl-hit-next %U", api_unformat_acl_next_index, + &hit_next_index)) + ; + else if (unformat (i, "policer-hit-next %d", &hit_next_index)) + ; + else if (unformat (i, "%U", unformat_policer_precolor, &opaque_index)) + ; + else if (unformat (i, "opaque-index %d", &opaque_index)) + ; + else if (unformat (i, "skip_n %d", &skip_n_vectors)) + ; + else if (unformat (i, "match_n %d", &match_n_vectors)) + ; + else if (unformat (i, "match %U", api_unformat_classify_match, + &match, skip_n_vectors, match_n_vectors)) + ; + else if (unformat (i, "advance %d", &advance)) + ; + else if (unformat (i, "table-index %d", &table_index)) + ; + else if (unformat (i, "action set-ip4-fib-id %d", &metadata)) + action = 1; + else if (unformat (i, "action set-ip6-fib-id %d", &metadata)) + action = 2; + else if (unformat (i, "action %d", &action)) + ; + else if (unformat (i, "metadata %d", &metadata)) + ; + else + break; + } -static void vl_api_ipsec_sa_details_t_handler_json - (vl_api_ipsec_sa_details_t * mp) -{ - vat_main_t *vam = &vat_main; - vat_json_node_t *node = NULL; - vl_api_ipsec_sad_flags_t flags; + if (table_index == ~0) + { + errmsg ("Table index required"); + return -99; + } - if (VAT_JSON_ARRAY != vam->json_tree.type) + if (is_add && match == 0) { - ASSERT (VAT_JSON_NONE == vam->json_tree.type); - vat_json_init_array (&vam->json_tree); + errmsg ("Match value required"); + return -99; } - node = vat_json_array_add (&vam->json_tree); - vat_json_init_object (node); - vat_json_object_add_uint (node, "sa_id", ntohl (mp->entry.sad_id)); - vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index)); - vat_json_object_add_uint (node, "spi", ntohl (mp->entry.spi)); - vat_json_object_add_uint (node, "proto", ntohl (mp->entry.protocol)); - vat_json_object_add_uint (node, "crypto_alg", - ntohl (mp->entry.crypto_algorithm)); - vat_json_object_add_uint (node, "integ_alg", - ntohl (mp->entry.integrity_algorithm)); - flags = ntohl (mp->entry.flags); - vat_json_object_add_uint (node, "use_esn", - ! !(flags & IPSEC_API_SAD_FLAG_USE_ESN)); - vat_json_object_add_uint (node, "use_anti_replay", - ! !(flags & IPSEC_API_SAD_FLAG_USE_ANTI_REPLAY)); - vat_json_object_add_uint (node, "is_tunnel", - ! !(flags & IPSEC_API_SAD_FLAG_IS_TUNNEL)); - vat_json_object_add_uint (node, "is_tunnel_ip6", - ! !(flags & IPSEC_API_SAD_FLAG_IS_TUNNEL_V6)); - vat_json_object_add_uint (node, "udp_encap", - ! !(flags & IPSEC_API_SAD_FLAG_UDP_ENCAP)); - vat_json_object_add_bytes (node, "crypto_key", mp->entry.crypto_key.data, - mp->entry.crypto_key.length); - vat_json_object_add_bytes (node, "integ_key", mp->entry.integrity_key.data, - mp->entry.integrity_key.length); - vat_json_object_add_address (node, "src", &mp->entry.tunnel_src); - vat_json_object_add_address (node, "dst", &mp->entry.tunnel_dst); - vat_json_object_add_uint (node, "replay_window", - clib_net_to_host_u64 (mp->replay_window)); - vat_json_object_add_uint (node, "stat_index", ntohl (mp->stat_index)); + M2 (CLASSIFY_ADD_DEL_SESSION, mp, vec_len (match)); + + mp->is_add = is_add; + mp->table_index = ntohl (table_index); + mp->hit_next_index = ntohl (hit_next_index); + mp->opaque_index = ntohl (opaque_index); + mp->advance = ntohl (advance); + mp->action = action; + mp->metadata = ntohl (metadata); + mp->match_len = ntohl (vec_len (match)); + clib_memcpy (mp->match, match, vec_len (match)); + vec_free (match); + + S (mp); + W (ret); + return ret; } static int -api_ipsec_sa_dump (vat_main_t * vam) +api_classify_set_interface_ip_table (vat_main_t * vam) { unformat_input_t *i = vam->input; - vl_api_ipsec_sa_dump_t *mp; - vl_api_control_ping_t *mp_ping; - u32 sa_id = ~0; + vl_api_classify_set_interface_ip_table_t *mp; + u32 sw_if_index; + int sw_if_index_set; + u32 table_index = ~0; + u8 is_ipv6 = 0; int ret; while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (i, "sa_id %d", &sa_id)) + if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) + sw_if_index_set = 1; + else if (unformat (i, "sw_if_index %d", &sw_if_index)) + sw_if_index_set = 1; + else if (unformat (i, "table %d", &table_index)) ; else { @@ -13380,40 +8825,51 @@ api_ipsec_sa_dump (vat_main_t * vam) } } - M (IPSEC_SA_DUMP, mp); + if (sw_if_index_set == 0) + { + errmsg ("missing interface name or sw_if_index"); + return -99; + } - mp->sa_id = ntohl (sa_id); - S (mp); + M (CLASSIFY_SET_INTERFACE_IP_TABLE, mp); - /* Use a control ping for synchronization */ - M (CONTROL_PING, mp_ping); - S (mp_ping); + mp->sw_if_index = ntohl (sw_if_index); + mp->table_index = ntohl (table_index); + mp->is_ipv6 = is_ipv6; + S (mp); W (ret); return ret; } static int -api_ipsec_tunnel_if_set_sa (vat_main_t * vam) +api_classify_set_interface_l2_tables (vat_main_t * vam) { unformat_input_t *i = vam->input; - vl_api_ipsec_tunnel_if_set_sa_t *mp; - u32 sw_if_index = ~0; - u32 sa_id = ~0; - u8 is_outbound = (u8) ~ 0; + vl_api_classify_set_interface_l2_tables_t *mp; + u32 sw_if_index; + int sw_if_index_set; + u32 ip4_table_index = ~0; + u32 ip6_table_index = ~0; + u32 other_table_index = ~0; + u32 is_input = 1; int ret; while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) + sw_if_index_set = 1; + else if (unformat (i, "sw_if_index %d", &sw_if_index)) + sw_if_index_set = 1; + else if (unformat (i, "ip4-table %d", &ip4_table_index)) ; - else if (unformat (i, "sa_id %d", &sa_id)) + else if (unformat (i, "ip6-table %d", &ip6_table_index)) + ; + else if (unformat (i, "other-table %d", &other_table_index)) + ; + else if (unformat (i, "is-input %d", &is_input)) ; - else if (unformat (i, "outbound")) - is_outbound = 1; - else if (unformat (i, "inbound")) - is_outbound = 0; else { clib_warning ("parse error '%U'", format_unformat_error, i); @@ -13421,3170 +8877,2808 @@ api_ipsec_tunnel_if_set_sa (vat_main_t * vam) } } - if (sw_if_index == ~0) + if (sw_if_index_set == 0) { - errmsg ("interface must be specified"); + errmsg ("missing interface name or sw_if_index"); return -99; } - if (sa_id == ~0) - { - errmsg ("SA ID must be specified"); - return -99; - } - M (IPSEC_TUNNEL_IF_SET_SA, mp); + M (CLASSIFY_SET_INTERFACE_L2_TABLES, mp); - mp->sw_if_index = htonl (sw_if_index); - mp->sa_id = htonl (sa_id); - mp->is_outbound = is_outbound; + mp->sw_if_index = ntohl (sw_if_index); + mp->ip4_table_index = ntohl (ip4_table_index); + mp->ip6_table_index = ntohl (ip6_table_index); + mp->other_table_index = ntohl (other_table_index); + mp->is_input = (u8) is_input; S (mp); W (ret); - return ret; } static int -api_get_first_msg_id (vat_main_t * vam) +api_set_ipfix_exporter (vat_main_t * vam) { - vl_api_get_first_msg_id_t *mp; unformat_input_t *i = vam->input; - u8 *name; - u8 name_set = 0; + vl_api_set_ipfix_exporter_t *mp; + ip4_address_t collector_address; + u8 collector_address_set = 0; + u32 collector_port = ~0; + ip4_address_t src_address; + u8 src_address_set = 0; + u32 vrf_id = ~0; + u32 path_mtu = ~0; + u32 template_interval = ~0; + u8 udp_checksum = 0; int ret; while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (i, "client %s", &name)) - name_set = 1; + if (unformat (i, "collector_address %U", unformat_ip4_address, + &collector_address)) + collector_address_set = 1; + else if (unformat (i, "collector_port %d", &collector_port)) + ; + else if (unformat (i, "src_address %U", unformat_ip4_address, + &src_address)) + src_address_set = 1; + else if (unformat (i, "vrf_id %d", &vrf_id)) + ; + else if (unformat (i, "path_mtu %d", &path_mtu)) + ; + else if (unformat (i, "template_interval %d", &template_interval)) + ; + else if (unformat (i, "udp_checksum")) + udp_checksum = 1; else break; } - if (name_set == 0) + if (collector_address_set == 0) { - errmsg ("missing client name"); + errmsg ("collector_address required"); return -99; } - vec_add1 (name, 0); - if (vec_len (name) > 63) + if (src_address_set == 0) { - errmsg ("client name too long"); + errmsg ("src_address required"); return -99; } - M (GET_FIRST_MSG_ID, mp); - clib_memcpy (mp->name, name, vec_len (name)); + M (SET_IPFIX_EXPORTER, mp); + + memcpy (mp->collector_address.un.ip4, collector_address.data, + sizeof (collector_address.data)); + mp->collector_port = htons ((u16) collector_port); + memcpy (mp->src_address.un.ip4, src_address.data, + sizeof (src_address.data)); + mp->vrf_id = htonl (vrf_id); + mp->path_mtu = htonl (path_mtu); + mp->template_interval = htonl (template_interval); + mp->udp_checksum = udp_checksum; + S (mp); W (ret); return ret; } static int -api_cop_interface_enable_disable (vat_main_t * vam) +api_set_ipfix_classify_stream (vat_main_t * vam) { - unformat_input_t *line_input = vam->input; - vl_api_cop_interface_enable_disable_t *mp; - u32 sw_if_index = ~0; - u8 enable_disable = 1; + unformat_input_t *i = vam->input; + vl_api_set_ipfix_classify_stream_t *mp; + u32 domain_id = 0; + u32 src_port = UDP_DST_PORT_ipfix; int ret; - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (line_input, "disable")) - enable_disable = 0; - if (unformat (line_input, "enable")) - enable_disable = 1; - else if (unformat (line_input, "%U", api_unformat_sw_if_index, - vam, &sw_if_index)) + if (unformat (i, "domain %d", &domain_id)) ; - else if (unformat (line_input, "sw_if_index %d", &sw_if_index)) + else if (unformat (i, "src_port %d", &src_port)) ; else - break; + { + errmsg ("unknown input `%U'", format_unformat_error, i); + return -99; + } } - if (sw_if_index == ~0) - { - errmsg ("missing interface name or sw_if_index"); - return -99; - } + M (SET_IPFIX_CLASSIFY_STREAM, mp); - /* Construct the API message */ - M (COP_INTERFACE_ENABLE_DISABLE, mp); - mp->sw_if_index = ntohl (sw_if_index); - mp->enable_disable = enable_disable; + mp->domain_id = htonl (domain_id); + mp->src_port = htons ((u16) src_port); - /* send it... */ S (mp); - /* Wait for the reply */ W (ret); return ret; } static int -api_cop_whitelist_enable_disable (vat_main_t * vam) +api_ipfix_classify_table_add_del (vat_main_t * vam) { - unformat_input_t *line_input = vam->input; - vl_api_cop_whitelist_enable_disable_t *mp; - u32 sw_if_index = ~0; - u8 ip4 = 0, ip6 = 0, default_cop = 0; - u32 fib_id = 0; + unformat_input_t *i = vam->input; + vl_api_ipfix_classify_table_add_del_t *mp; + int is_add = -1; + u32 classify_table_index = ~0; + u8 ip_version = 0; + u8 transport_protocol = 255; int ret; - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (line_input, "ip4")) - ip4 = 1; - else if (unformat (line_input, "ip6")) - ip6 = 1; - else if (unformat (line_input, "default")) - default_cop = 1; - else if (unformat (line_input, "%U", api_unformat_sw_if_index, - vam, &sw_if_index)) - ; - else if (unformat (line_input, "sw_if_index %d", &sw_if_index)) - ; - else if (unformat (line_input, "fib-id %d", &fib_id)) + if (unformat (i, "add")) + is_add = 1; + else if (unformat (i, "del")) + is_add = 0; + else if (unformat (i, "table %d", &classify_table_index)) ; + else if (unformat (i, "ip4")) + ip_version = 4; + else if (unformat (i, "ip6")) + ip_version = 6; + else if (unformat (i, "tcp")) + transport_protocol = 6; + else if (unformat (i, "udp")) + transport_protocol = 17; else - break; + { + errmsg ("unknown input `%U'", format_unformat_error, i); + return -99; + } } - if (sw_if_index == ~0) + if (is_add == -1) { - errmsg ("missing interface name or sw_if_index"); + errmsg ("expecting: add|del"); + return -99; + } + if (classify_table_index == ~0) + { + errmsg ("classifier table not specified"); + return -99; + } + if (ip_version == 0) + { + errmsg ("IP version not specified"); return -99; } - /* Construct the API message */ - M (COP_WHITELIST_ENABLE_DISABLE, mp); - mp->sw_if_index = ntohl (sw_if_index); - mp->fib_id = ntohl (fib_id); - mp->ip4 = ip4; - mp->ip6 = ip6; - mp->default_cop = default_cop; + M (IPFIX_CLASSIFY_TABLE_ADD_DEL, mp); + + mp->is_add = is_add; + mp->table_id = htonl (classify_table_index); + mp->ip_version = ip_version; + mp->transport_protocol = transport_protocol; - /* send it... */ S (mp); - /* Wait for the reply */ W (ret); return ret; } static int -api_get_node_graph (vat_main_t * vam) +api_get_node_index (vat_main_t * vam) { - vl_api_get_node_graph_t *mp; + unformat_input_t *i = vam->input; + vl_api_get_node_index_t *mp; + u8 *name = 0; int ret; - M (GET_NODE_GRAPH, mp); - - /* send it... */ - S (mp); - /* Wait for the reply */ - W (ret); - return ret; -} - -/* *INDENT-OFF* */ -/** Used for parsing LISP eids */ -typedef CLIB_PACKED(struct{ - union { - ip46_address_t ip; - mac_address_t mac; - lisp_nsh_api_t nsh; - } addr; - u32 len; /**< prefix length if IP */ - u8 type; /**< type of eid */ -}) lisp_eid_vat_t; -/* *INDENT-ON* */ - -static uword -unformat_lisp_eid_vat (unformat_input_t * input, va_list * args) -{ - lisp_eid_vat_t *a = va_arg (*args, lisp_eid_vat_t *); - - clib_memset (a, 0, sizeof (a[0])); - - if (unformat (input, "%U/%d", unformat_ip46_address, a->addr.ip, &a->len)) - { - a->type = 0; /* ip prefix type */ - } - else if (unformat (input, "%U", unformat_ethernet_address, &a->addr.mac)) - { - a->type = 1; /* mac type */ - } - else if (unformat (input, "%U", unformat_nsh_address, a->addr.nsh)) + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - a->type = 2; /* NSH type */ - a->addr.nsh.spi = clib_host_to_net_u32 (a->addr.nsh.spi); + if (unformat (i, "node %s", &name)) + ; + else + break; } - else + if (name == 0) { - return 0; + errmsg ("node name required"); + return -99; } - - if (a->type == 0) + if (vec_len (name) >= ARRAY_LEN (mp->node_name)) { - if (ip46_address_is_ip4 (&a->addr.ip)) - return a->len > 32 ? 1 : 0; - else - return a->len > 128 ? 1 : 0; + errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name)); + return -99; } - return 1; -} + M (GET_NODE_INDEX, mp); + clib_memcpy (mp->node_name, name, vec_len (name)); + vec_free (name); -static void -lisp_eid_put_vat (vl_api_eid_t * eid, const lisp_eid_vat_t * vat_eid) -{ - eid->type = vat_eid->type; - switch (eid->type) - { - case EID_TYPE_API_PREFIX: - if (ip46_address_is_ip4 (&vat_eid->addr.ip)) - { - clib_memcpy (&eid->address.prefix.address.un.ip4, - &vat_eid->addr.ip.ip4, 4); - eid->address.prefix.address.af = ADDRESS_IP4; - eid->address.prefix.len = vat_eid->len; - } - else - { - clib_memcpy (&eid->address.prefix.address.un.ip6, - &vat_eid->addr.ip.ip6, 16); - eid->address.prefix.address.af = ADDRESS_IP6; - eid->address.prefix.len = vat_eid->len; - } - return; - case EID_TYPE_API_MAC: - clib_memcpy (&eid->address.mac, &vat_eid->addr.mac, - sizeof (eid->address.mac)); - return; - case EID_TYPE_API_NSH: - clib_memcpy (&eid->address.nsh, &vat_eid->addr.nsh, - sizeof (eid->address.nsh)); - return; - default: - ASSERT (0); - return; - } + S (mp); + W (ret); + return ret; } static int -api_one_add_del_locator_set (vat_main_t * vam) +api_get_next_index (vat_main_t * vam) { - unformat_input_t *input = vam->input; - vl_api_one_add_del_locator_set_t *mp; - u8 is_add = 1; - u8 *locator_set_name = NULL; - u8 locator_set_name_set = 0; - vl_api_local_locator_t locator, *locators = 0; - u32 sw_if_index, priority, weight; - u32 data_len = 0; - + unformat_input_t *i = vam->input; + vl_api_get_next_index_t *mp; + u8 *node_name = 0, *next_node_name = 0; int ret; - /* Parse args required to build the message */ - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (input, "del")) - { - is_add = 0; - } - else if (unformat (input, "locator-set %s", &locator_set_name)) - { - locator_set_name_set = 1; - } - else if (unformat (input, "sw_if_index %u p %u w %u", - &sw_if_index, &priority, &weight)) - { - locator.sw_if_index = htonl (sw_if_index); - locator.priority = priority; - locator.weight = weight; - vec_add1 (locators, locator); - } - else - if (unformat - (input, "iface %U p %u w %u", api_unformat_sw_if_index, vam, - &sw_if_index, &priority, &weight)) - { - locator.sw_if_index = htonl (sw_if_index); - locator.priority = priority; - locator.weight = weight; - vec_add1 (locators, locator); - } - else + if (unformat (i, "node-name %s", &node_name)) + ; + else if (unformat (i, "next-node-name %s", &next_node_name)) break; } - if (locator_set_name_set == 0) + if (node_name == 0) { - errmsg ("missing locator-set name"); - vec_free (locators); + errmsg ("node name required"); return -99; } - - if (vec_len (locator_set_name) > 64) + if (vec_len (node_name) >= ARRAY_LEN (mp->node_name)) { - errmsg ("locator-set name too long"); - vec_free (locator_set_name); - vec_free (locators); + errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name)); return -99; } - vec_add1 (locator_set_name, 0); - - data_len = sizeof (vl_api_local_locator_t) * vec_len (locators); - - /* Construct the API message */ - M2 (ONE_ADD_DEL_LOCATOR_SET, mp, data_len); - mp->is_add = is_add; - clib_memcpy (mp->locator_set_name, locator_set_name, - vec_len (locator_set_name)); - vec_free (locator_set_name); + if (next_node_name == 0) + { + errmsg ("next node name required"); + return -99; + } + if (vec_len (next_node_name) >= ARRAY_LEN (mp->next_name)) + { + errmsg ("next node name too long, max %d", ARRAY_LEN (mp->next_name)); + return -99; + } - mp->locator_num = clib_host_to_net_u32 (vec_len (locators)); - if (locators) - clib_memcpy (mp->locators, locators, data_len); - vec_free (locators); + M (GET_NEXT_INDEX, mp); + clib_memcpy (mp->node_name, node_name, vec_len (node_name)); + clib_memcpy (mp->next_name, next_node_name, vec_len (next_node_name)); + vec_free (node_name); + vec_free (next_node_name); - /* send it... */ S (mp); - - /* Wait for a reply... */ W (ret); return ret; } -#define api_lisp_add_del_locator_set api_one_add_del_locator_set - static int -api_one_add_del_locator (vat_main_t * vam) +api_add_node_next (vat_main_t * vam) { - unformat_input_t *input = vam->input; - vl_api_one_add_del_locator_t *mp; - u32 tmp_if_index = ~0; - u32 sw_if_index = ~0; - u8 sw_if_index_set = 0; - u8 sw_if_index_if_name_set = 0; - u32 priority = ~0; - u8 priority_set = 0; - u32 weight = ~0; - u8 weight_set = 0; - u8 is_add = 1; - u8 *locator_set_name = NULL; - u8 locator_set_name_set = 0; + unformat_input_t *i = vam->input; + vl_api_add_node_next_t *mp; + u8 *name = 0; + u8 *next = 0; int ret; - /* Parse args required to build the message */ - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (input, "del")) - { - is_add = 0; - } - else if (unformat (input, "locator-set %s", &locator_set_name)) - { - locator_set_name_set = 1; - } - else if (unformat (input, "iface %U", api_unformat_sw_if_index, vam, - &tmp_if_index)) - { - sw_if_index_if_name_set = 1; - sw_if_index = tmp_if_index; - } - else if (unformat (input, "sw_if_index %d", &tmp_if_index)) - { - sw_if_index_set = 1; - sw_if_index = tmp_if_index; - } - else if (unformat (input, "p %d", &priority)) - { - priority_set = 1; - } - else if (unformat (input, "w %d", &weight)) - { - weight_set = 1; - } + if (unformat (i, "node %s", &name)) + ; + else if (unformat (i, "next %s", &next)) + ; else break; } - - if (locator_set_name_set == 0) - { - errmsg ("missing locator-set name"); - return -99; - } - - if (sw_if_index_set == 0 && sw_if_index_if_name_set == 0) - { - errmsg ("missing sw_if_index"); - vec_free (locator_set_name); - return -99; - } - - if (sw_if_index_set != 0 && sw_if_index_if_name_set != 0) + if (name == 0) { - errmsg ("cannot use both params interface name and sw_if_index"); - vec_free (locator_set_name); + errmsg ("node name required"); return -99; } - - if (priority_set == 0) + if (vec_len (name) >= ARRAY_LEN (mp->node_name)) { - errmsg ("missing locator-set priority"); - vec_free (locator_set_name); + errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name)); return -99; } - - if (weight_set == 0) + if (next == 0) { - errmsg ("missing locator-set weight"); - vec_free (locator_set_name); + errmsg ("next node required"); return -99; } - - if (vec_len (locator_set_name) > 64) + if (vec_len (next) >= ARRAY_LEN (mp->next_name)) { - errmsg ("locator-set name too long"); - vec_free (locator_set_name); + errmsg ("next name too long, max %d", ARRAY_LEN (mp->next_name)); return -99; } - vec_add1 (locator_set_name, 0); - - /* Construct the API message */ - M (ONE_ADD_DEL_LOCATOR, mp); - mp->is_add = is_add; - mp->sw_if_index = ntohl (sw_if_index); - mp->priority = priority; - mp->weight = weight; - clib_memcpy (mp->locator_set_name, locator_set_name, - vec_len (locator_set_name)); - vec_free (locator_set_name); + M (ADD_NODE_NEXT, mp); + clib_memcpy (mp->node_name, name, vec_len (name)); + clib_memcpy (mp->next_name, next, vec_len (next)); + vec_free (name); + vec_free (next); - /* send it... */ S (mp); - - /* Wait for a reply... */ W (ret); return ret; } -#define api_lisp_add_del_locator api_one_add_del_locator +static void vl_api_sw_interface_tap_v2_details_t_handler + (vl_api_sw_interface_tap_v2_details_t * mp) +{ + vat_main_t *vam = &vat_main; -uword -unformat_hmac_key_id (unformat_input_t * input, va_list * args) + u8 *ip4 = + format (0, "%U/%d", format_ip4_address, mp->host_ip4_prefix.address, + mp->host_ip4_prefix.len); + u8 *ip6 = + format (0, "%U/%d", format_ip6_address, mp->host_ip6_prefix.address, + mp->host_ip6_prefix.len); + + print (vam->ofp, + "\n%-16s %-12d %-5d %-12d %-12d %-14U %-30s %-20s %-20s %-30s 0x%-08x", + mp->dev_name, ntohl (mp->sw_if_index), ntohl (mp->id), + ntohs (mp->rx_ring_sz), ntohs (mp->tx_ring_sz), + format_ethernet_address, mp->host_mac_addr, mp->host_namespace, + mp->host_bridge, ip4, ip6, ntohl (mp->tap_flags)); + + vec_free (ip4); + vec_free (ip6); +} + +static void vl_api_sw_interface_tap_v2_details_t_handler_json + (vl_api_sw_interface_tap_v2_details_t * mp) { - u32 *key_id = va_arg (*args, u32 *); - u8 *s = 0; + vat_main_t *vam = &vat_main; + vat_json_node_t *node = NULL; - if (unformat (input, "%s", &s)) + if (VAT_JSON_ARRAY != vam->json_tree.type) { - if (!strcmp ((char *) s, "sha1")) - key_id[0] = HMAC_SHA_1_96; - else if (!strcmp ((char *) s, "sha256")) - key_id[0] = HMAC_SHA_256_128; - else - { - clib_warning ("invalid key_id: '%s'", s); - key_id[0] = HMAC_NO_KEY; - } + ASSERT (VAT_JSON_NONE == vam->json_tree.type); + vat_json_init_array (&vam->json_tree); } - else - return 0; + node = vat_json_array_add (&vam->json_tree); + + vat_json_init_object (node); + vat_json_object_add_uint (node, "id", ntohl (mp->id)); + vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index)); + vat_json_object_add_uint (node, "tap_flags", ntohl (mp->tap_flags)); + vat_json_object_add_string_copy (node, "dev_name", mp->dev_name); + vat_json_object_add_uint (node, "rx_ring_sz", ntohs (mp->rx_ring_sz)); + vat_json_object_add_uint (node, "tx_ring_sz", ntohs (mp->tx_ring_sz)); + vat_json_object_add_string_copy (node, "host_mac_addr", + format (0, "%U", format_ethernet_address, + &mp->host_mac_addr)); + vat_json_object_add_string_copy (node, "host_namespace", + mp->host_namespace); + vat_json_object_add_string_copy (node, "host_bridge", mp->host_bridge); + vat_json_object_add_string_copy (node, "host_ip4_addr", + format (0, "%U/%d", format_ip4_address, + mp->host_ip4_prefix.address, + mp->host_ip4_prefix.len)); + vat_json_object_add_string_copy (node, "host_ip6_prefix", + format (0, "%U/%d", format_ip6_address, + mp->host_ip6_prefix.address, + mp->host_ip6_prefix.len)); - vec_free (s); - return 1; } static int -api_one_add_del_local_eid (vat_main_t * vam) +api_sw_interface_tap_v2_dump (vat_main_t * vam) { - unformat_input_t *input = vam->input; - vl_api_one_add_del_local_eid_t *mp; - u8 is_add = 1; - u8 eid_set = 0; - lisp_eid_vat_t _eid, *eid = &_eid; - u8 *locator_set_name = 0; - u8 locator_set_name_set = 0; - u32 vni = 0; - u16 key_id = 0; - u8 *key = 0; + vl_api_sw_interface_tap_v2_dump_t *mp; + vl_api_control_ping_t *mp_ping; int ret; - /* Parse args required to build the message */ - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (input, "del")) - { - is_add = 0; - } - else if (unformat (input, "vni %d", &vni)) - { - ; - } - else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid)) - { - eid_set = 1; - } - else if (unformat (input, "locator-set %s", &locator_set_name)) - { - locator_set_name_set = 1; - } - else if (unformat (input, "key-id %U", unformat_hmac_key_id, &key_id)) - ; - else if (unformat (input, "secret-key %_%v%_", &key)) - ; - else - break; - } + print (vam->ofp, + "\n%-16s %-12s %-5s %-12s %-12s %-14s %-30s %-20s %-20s %-30s", + "dev_name", "sw_if_index", "id", "rx_ring_sz", "tx_ring_sz", + "host_mac_addr", "host_namespace", "host_bridge", "host_ip4_addr", + "host_ip6_addr"); - if (locator_set_name_set == 0) - { - errmsg ("missing locator-set name"); - return -99; - } + /* Get list of tap interfaces */ + M (SW_INTERFACE_TAP_V2_DUMP, mp); + S (mp); - if (0 == eid_set) - { - errmsg ("EID address not set!"); - vec_free (locator_set_name); - return -99; - } + /* Use a control ping for synchronization */ + MPING (CONTROL_PING, mp_ping); + S (mp_ping); - if (key && (0 == key_id)) - { - errmsg ("invalid key_id!"); - return -99; - } + W (ret); + return ret; +} + +static void vl_api_sw_interface_virtio_pci_details_t_handler + (vl_api_sw_interface_virtio_pci_details_t * mp) +{ + vat_main_t *vam = &vat_main; - if (vec_len (key) > 64) + typedef union + { + struct { - errmsg ("key too long"); - vec_free (key); - return -99; - } + u16 domain; + u8 bus; + u8 slot:5; + u8 function:3; + }; + u32 as_u32; + } pci_addr_t; + pci_addr_t addr; + + addr.domain = ntohs (mp->pci_addr.domain); + addr.bus = mp->pci_addr.bus; + addr.slot = mp->pci_addr.slot; + addr.function = mp->pci_addr.function; + + u8 *pci_addr = format (0, "%04x:%02x:%02x.%x", addr.domain, addr.bus, + addr.slot, addr.function); - if (vec_len (locator_set_name) > 64) + print (vam->ofp, + "\n%-12s %-12d %-12d %-12d %-17U 0x%-08llx", + pci_addr, ntohl (mp->sw_if_index), + ntohs (mp->rx_ring_sz), ntohs (mp->tx_ring_sz), + format_ethernet_address, mp->mac_addr, + clib_net_to_host_u64 (mp->features)); + vec_free (pci_addr); +} + +static void vl_api_sw_interface_virtio_pci_details_t_handler_json + (vl_api_sw_interface_virtio_pci_details_t * mp) +{ + vat_main_t *vam = &vat_main; + vat_json_node_t *node = NULL; + vlib_pci_addr_t pci_addr; + + if (VAT_JSON_ARRAY != vam->json_tree.type) { - errmsg ("locator-set name too long"); - vec_free (locator_set_name); - return -99; + ASSERT (VAT_JSON_NONE == vam->json_tree.type); + vat_json_init_array (&vam->json_tree); } - vec_add1 (locator_set_name, 0); + node = vat_json_array_add (&vam->json_tree); - /* Construct the API message */ - M (ONE_ADD_DEL_LOCAL_EID, mp); + pci_addr.domain = ntohs (mp->pci_addr.domain); + pci_addr.bus = mp->pci_addr.bus; + pci_addr.slot = mp->pci_addr.slot; + pci_addr.function = mp->pci_addr.function; + + vat_json_init_object (node); + vat_json_object_add_uint (node, "pci-addr", pci_addr.as_u32); + vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index)); + vat_json_object_add_uint (node, "rx_ring_sz", ntohs (mp->rx_ring_sz)); + vat_json_object_add_uint (node, "tx_ring_sz", ntohs (mp->tx_ring_sz)); + vat_json_object_add_uint (node, "features", + clib_net_to_host_u64 (mp->features)); + vat_json_object_add_string_copy (node, "mac_addr", + format (0, "%U", format_ethernet_address, + &mp->mac_addr)); +} - mp->is_add = is_add; - lisp_eid_put_vat (&mp->eid, eid); - mp->vni = clib_host_to_net_u32 (vni); - mp->key.id = key_id; - clib_memcpy (mp->locator_set_name, locator_set_name, - vec_len (locator_set_name)); - clib_memcpy (mp->key.key, key, vec_len (key)); +static int +api_sw_interface_virtio_pci_dump (vat_main_t * vam) +{ + vl_api_sw_interface_virtio_pci_dump_t *mp; + vl_api_control_ping_t *mp_ping; + int ret; - vec_free (locator_set_name); - vec_free (key); + print (vam->ofp, + "\n%-12s %-12s %-12s %-12s %-17s %-08s", + "pci_addr", "sw_if_index", "rx_ring_sz", "tx_ring_sz", + "mac_addr", "features"); - /* send it... */ + /* Get list of tap interfaces */ + M (SW_INTERFACE_VIRTIO_PCI_DUMP, mp); S (mp); - /* Wait for a reply... */ + /* Use a control ping for synchronization */ + MPING (CONTROL_PING, mp_ping); + S (mp_ping); + W (ret); return ret; } -#define api_lisp_add_del_local_eid api_one_add_del_local_eid - static int -api_lisp_gpe_add_del_fwd_entry (vat_main_t * vam) +api_vxlan_offload_rx (vat_main_t * vam) { - u32 dp_table = 0, vni = 0;; - unformat_input_t *input = vam->input; - vl_api_gpe_add_del_fwd_entry_t *mp; + unformat_input_t *line_input = vam->input; + vl_api_vxlan_offload_rx_t *mp; + u32 hw_if_index = ~0, rx_if_index = ~0; u8 is_add = 1; - lisp_eid_vat_t _rmt_eid, *rmt_eid = &_rmt_eid; - lisp_eid_vat_t _lcl_eid, *lcl_eid = &_lcl_eid; - u8 rmt_eid_set = 0, lcl_eid_set = 0; - u32 action = ~0, w; - ip4_address_t rmt_rloc4, lcl_rloc4; - ip6_address_t rmt_rloc6, lcl_rloc6; - vl_api_gpe_locator_t *rmt_locs = 0, *lcl_locs = 0, rloc, *curr_rloc = 0; int ret; - clib_memset (&rloc, 0, sizeof (rloc)); - - /* Parse args required to build the message */ - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { - if (unformat (input, "del")) + if (unformat (line_input, "del")) is_add = 0; - else if (unformat (input, "add")) - is_add = 1; - else if (unformat (input, "reid %U", unformat_lisp_eid_vat, rmt_eid)) - { - rmt_eid_set = 1; - } - else if (unformat (input, "leid %U", unformat_lisp_eid_vat, lcl_eid)) - { - lcl_eid_set = 1; - } - else if (unformat (input, "vrf %d", &dp_table)) + else if (unformat (line_input, "hw %U", api_unformat_hw_if_index, vam, + &hw_if_index)) ; - else if (unformat (input, "bd %d", &dp_table)) + else if (unformat (line_input, "hw hw_if_index %u", &hw_if_index)) ; - else if (unformat (input, "vni %d", &vni)) + else if (unformat (line_input, "rx %U", api_unformat_sw_if_index, vam, + &rx_if_index)) + ; + else if (unformat (line_input, "rx sw_if_index %u", &rx_if_index)) ; - else if (unformat (input, "w %d", &w)) - { - if (!curr_rloc) - { - errmsg ("No RLOC configured for setting priority/weight!"); - return -99; - } - curr_rloc->weight = w; - } - else if (unformat (input, "loc-pair %U %U", unformat_ip4_address, - &lcl_rloc4, unformat_ip4_address, &rmt_rloc4)) - { - rloc.addr.af = 0; - clib_memcpy (&rloc.addr.un.ip4, &lcl_rloc4, sizeof (lcl_rloc4)); - rloc.weight = 0; - vec_add1 (lcl_locs, rloc); - - clib_memcpy (&rloc.addr.un.ip4, &rmt_rloc4, sizeof (rmt_rloc4)); - vec_add1 (rmt_locs, rloc); - /* weight saved in rmt loc */ - curr_rloc = &rmt_locs[vec_len (rmt_locs) - 1]; - } - else if (unformat (input, "loc-pair %U %U", unformat_ip6_address, - &lcl_rloc6, unformat_ip6_address, &rmt_rloc6)) - { - rloc.addr.af = 1; - clib_memcpy (&rloc.addr.un.ip6, &lcl_rloc6, sizeof (lcl_rloc6)); - rloc.weight = 0; - vec_add1 (lcl_locs, rloc); - - clib_memcpy (&rloc.addr.un.ip6, &rmt_rloc6, sizeof (rmt_rloc6)); - vec_add1 (rmt_locs, rloc); - /* weight saved in rmt loc */ - curr_rloc = &rmt_locs[vec_len (rmt_locs) - 1]; - } - else if (unformat (input, "action %d", &action)) - { - ; - } else { - clib_warning ("parse error '%U'", format_unformat_error, input); + errmsg ("parse error '%U'", format_unformat_error, line_input); return -99; } } - if (!rmt_eid_set) - { - errmsg ("remote eid addresses not set"); - return -99; - } - - if (lcl_eid_set && rmt_eid->type != lcl_eid->type) + if (hw_if_index == ~0) { - errmsg ("eid types don't match"); + errmsg ("no hw interface"); return -99; } - if (0 == rmt_locs && (u32) ~ 0 == action) + if (rx_if_index == ~0) { - errmsg ("action not set for negative mapping"); + errmsg ("no rx tunnel"); return -99; } - /* Construct the API message */ - M2 (GPE_ADD_DEL_FWD_ENTRY, mp, - sizeof (vl_api_gpe_locator_t) * vec_len (rmt_locs) * 2); - - mp->is_add = is_add; - lisp_eid_put_vat (&mp->rmt_eid, rmt_eid); - lisp_eid_put_vat (&mp->lcl_eid, lcl_eid); - mp->dp_table = clib_host_to_net_u32 (dp_table); - mp->vni = clib_host_to_net_u32 (vni); - mp->action = action; - - if (0 != rmt_locs && 0 != lcl_locs) - { - mp->loc_num = clib_host_to_net_u32 (vec_len (rmt_locs) * 2); - clib_memcpy (mp->locs, lcl_locs, - (sizeof (vl_api_gpe_locator_t) * vec_len (lcl_locs))); + M (VXLAN_OFFLOAD_RX, mp); - u32 offset = sizeof (vl_api_gpe_locator_t) * vec_len (lcl_locs); - clib_memcpy (((u8 *) mp->locs) + offset, rmt_locs, - (sizeof (vl_api_gpe_locator_t) * vec_len (rmt_locs))); - } - vec_free (lcl_locs); - vec_free (rmt_locs); + mp->hw_if_index = ntohl (hw_if_index); + mp->sw_if_index = ntohl (rx_if_index); + mp->enable = is_add; - /* send it... */ S (mp); - - /* Wait for a reply... */ W (ret); return ret; } +static uword unformat_vxlan_decap_next + (unformat_input_t * input, va_list * args) +{ + u32 *result = va_arg (*args, u32 *); + u32 tmp; + + if (unformat (input, "l2")) + *result = VXLAN_INPUT_NEXT_L2_INPUT; + else if (unformat (input, "%d", &tmp)) + *result = tmp; + else + return 0; + return 1; +} + static int -api_one_add_del_map_server (vat_main_t * vam) +api_vxlan_add_del_tunnel (vat_main_t * vam) { - unformat_input_t *input = vam->input; - vl_api_one_add_del_map_server_t *mp; + unformat_input_t *line_input = vam->input; + vl_api_vxlan_add_del_tunnel_t *mp; + ip46_address_t src, dst; u8 is_add = 1; - u8 ipv4_set = 0; - u8 ipv6_set = 0; - ip4_address_t ipv4; - ip6_address_t ipv6; + u8 ipv4_set = 0, ipv6_set = 0; + u8 src_set = 0; + u8 dst_set = 0; + u8 grp_set = 0; + u32 instance = ~0; + u32 mcast_sw_if_index = ~0; + u32 encap_vrf_id = 0; + u32 decap_next_index = ~0; + u32 vni = 0; int ret; - /* Parse args required to build the message */ - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + /* Can't "universally zero init" (={0}) due to GCC bug 53119 */ + clib_memset (&src, 0, sizeof src); + clib_memset (&dst, 0, sizeof dst); + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { - if (unformat (input, "del")) + if (unformat (line_input, "del")) + is_add = 0; + else if (unformat (line_input, "instance %d", &instance)) + ; + else + if (unformat (line_input, "src %U", unformat_ip4_address, &src.ip4)) { - is_add = 0; + ipv4_set = 1; + src_set = 1; } - else if (unformat (input, "%U", unformat_ip4_address, &ipv4)) + else + if (unformat (line_input, "dst %U", unformat_ip4_address, &dst.ip4)) { ipv4_set = 1; + dst_set = 1; } - else if (unformat (input, "%U", unformat_ip6_address, &ipv6)) + else + if (unformat (line_input, "src %U", unformat_ip6_address, &src.ip6)) { ipv6_set = 1; + src_set = 1; } else - break; - } - - if (ipv4_set && ipv6_set) - { - errmsg ("both eid v4 and v6 addresses set"); - return -99; - } - - if (!ipv4_set && !ipv6_set) - { - errmsg ("eid addresses not set"); - return -99; - } - - /* Construct the API message */ - M (ONE_ADD_DEL_MAP_SERVER, mp); - - mp->is_add = is_add; - if (ipv6_set) - { - mp->ip_address.af = 1; - clib_memcpy (mp->ip_address.un.ip6, &ipv6, sizeof (ipv6)); - } - else - { - mp->ip_address.af = 0; - clib_memcpy (mp->ip_address.un.ip4, &ipv4, sizeof (ipv4)); - } - - /* send it... */ - S (mp); - - /* Wait for a reply... */ - W (ret); - return ret; -} - -#define api_lisp_add_del_map_server api_one_add_del_map_server - -static int -api_one_add_del_map_resolver (vat_main_t * vam) -{ - unformat_input_t *input = vam->input; - vl_api_one_add_del_map_resolver_t *mp; - u8 is_add = 1; - u8 ipv4_set = 0; - u8 ipv6_set = 0; - ip4_address_t ipv4; - ip6_address_t ipv6; - int ret; - - /* Parse args required to build the message */ - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (input, "del")) + if (unformat (line_input, "dst %U", unformat_ip6_address, &dst.ip6)) { - is_add = 0; + ipv6_set = 1; + dst_set = 1; } - else if (unformat (input, "%U", unformat_ip4_address, &ipv4)) + else if (unformat (line_input, "group %U %U", + unformat_ip4_address, &dst.ip4, + api_unformat_sw_if_index, vam, &mcast_sw_if_index)) { + grp_set = dst_set = 1; ipv4_set = 1; } - else if (unformat (input, "%U", unformat_ip6_address, &ipv6)) + else if (unformat (line_input, "group %U", + unformat_ip4_address, &dst.ip4)) { - ipv6_set = 1; + grp_set = dst_set = 1; + ipv4_set = 1; } - else - break; - } - - if (ipv4_set && ipv6_set) - { - errmsg ("both eid v4 and v6 addresses set"); - return -99; - } - - if (!ipv4_set && !ipv6_set) - { - errmsg ("eid addresses not set"); - return -99; - } - - /* Construct the API message */ - M (ONE_ADD_DEL_MAP_RESOLVER, mp); - - mp->is_add = is_add; - if (ipv6_set) - { - mp->ip_address.af = 1; - clib_memcpy (mp->ip_address.un.ip6, &ipv6, sizeof (ipv6)); - } - else - { - mp->ip_address.af = 0; - clib_memcpy (mp->ip_address.un.ip6, &ipv4, sizeof (ipv4)); - } - - /* send it... */ - S (mp); - - /* Wait for a reply... */ - W (ret); - return ret; -} - -#define api_lisp_add_del_map_resolver api_one_add_del_map_resolver - -static int -api_lisp_gpe_enable_disable (vat_main_t * vam) -{ - unformat_input_t *input = vam->input; - vl_api_gpe_enable_disable_t *mp; - u8 is_set = 0; - u8 is_enable = 1; - int ret; - - /* Parse args required to build the message */ - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (input, "enable")) + else if (unformat (line_input, "group %U %U", + unformat_ip6_address, &dst.ip6, + api_unformat_sw_if_index, vam, &mcast_sw_if_index)) { - is_set = 1; - is_enable = 1; + grp_set = dst_set = 1; + ipv6_set = 1; } - else if (unformat (input, "disable")) + else if (unformat (line_input, "group %U", + unformat_ip6_address, &dst.ip6)) { - is_set = 1; - is_enable = 0; + grp_set = dst_set = 1; + ipv6_set = 1; } else - break; + if (unformat (line_input, "mcast_sw_if_index %u", &mcast_sw_if_index)) + ; + else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id)) + ; + else if (unformat (line_input, "decap-next %U", + unformat_vxlan_decap_next, &decap_next_index)) + ; + else if (unformat (line_input, "vni %d", &vni)) + ; + else + { + errmsg ("parse error '%U'", format_unformat_error, line_input); + return -99; + } } - if (is_set == 0) + if (src_set == 0) { - errmsg ("Value not set"); + errmsg ("tunnel src address not specified"); return -99; } - - /* Construct the API message */ - M (GPE_ENABLE_DISABLE, mp); - - mp->is_enable = is_enable; - - /* send it... */ - S (mp); - - /* Wait for a reply... */ - W (ret); - return ret; -} - -static int -api_one_rloc_probe_enable_disable (vat_main_t * vam) -{ - unformat_input_t *input = vam->input; - vl_api_one_rloc_probe_enable_disable_t *mp; - u8 is_set = 0; - u8 is_enable = 0; - int ret; - - /* Parse args required to build the message */ - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + if (dst_set == 0) { - if (unformat (input, "enable")) - { - is_set = 1; - is_enable = 1; - } - else if (unformat (input, "disable")) - is_set = 1; - else - break; + errmsg ("tunnel dst address not specified"); + return -99; } - if (!is_set) + if (grp_set && !ip46_address_is_multicast (&dst)) { - errmsg ("Value not set"); + errmsg ("tunnel group address not multicast"); + return -99; + } + if (grp_set && mcast_sw_if_index == ~0) + { + errmsg ("tunnel nonexistent multicast device"); + return -99; + } + if (grp_set == 0 && ip46_address_is_multicast (&dst)) + { + errmsg ("tunnel dst address must be unicast"); return -99; } - /* Construct the API message */ - M (ONE_RLOC_PROBE_ENABLE_DISABLE, mp); - - mp->is_enable = is_enable; - - /* send it... */ - S (mp); - - /* Wait for a reply... */ - W (ret); - return ret; -} - -#define api_lisp_rloc_probe_enable_disable api_one_rloc_probe_enable_disable - -static int -api_one_map_register_enable_disable (vat_main_t * vam) -{ - unformat_input_t *input = vam->input; - vl_api_one_map_register_enable_disable_t *mp; - u8 is_set = 0; - u8 is_enable = 0; - int ret; - /* Parse args required to build the message */ - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + if (ipv4_set && ipv6_set) { - if (unformat (input, "enable")) - { - is_set = 1; - is_enable = 1; - } - else if (unformat (input, "disable")) - is_set = 1; - else - break; + errmsg ("both IPv4 and IPv6 addresses specified"); + return -99; } - if (!is_set) + if ((vni == 0) || (vni >> 24)) { - errmsg ("Value not set"); + errmsg ("vni not specified or out of range"); return -99; } - /* Construct the API message */ - M (ONE_MAP_REGISTER_ENABLE_DISABLE, mp); + M (VXLAN_ADD_DEL_TUNNEL, mp); - mp->is_enable = is_enable; + if (ipv6_set) + { + clib_memcpy (mp->src_address.un.ip6, &src.ip6, sizeof (src.ip6)); + clib_memcpy (mp->dst_address.un.ip6, &dst.ip6, sizeof (dst.ip6)); + } + else + { + clib_memcpy (mp->src_address.un.ip4, &src.ip4, sizeof (src.ip4)); + clib_memcpy (mp->dst_address.un.ip4, &dst.ip4, sizeof (dst.ip4)); + } + mp->src_address.af = ipv6_set; + mp->dst_address.af = ipv6_set; - /* send it... */ - S (mp); + mp->instance = htonl (instance); + mp->encap_vrf_id = ntohl (encap_vrf_id); + mp->decap_next_index = ntohl (decap_next_index); + mp->mcast_sw_if_index = ntohl (mcast_sw_if_index); + mp->vni = ntohl (vni); + mp->is_add = is_add; - /* Wait for a reply... */ + S (mp); W (ret); return ret; } -#define api_lisp_map_register_enable_disable api_one_map_register_enable_disable +static void vl_api_vxlan_tunnel_details_t_handler + (vl_api_vxlan_tunnel_details_t * mp) +{ + vat_main_t *vam = &vat_main; + ip46_address_t src = + to_ip46 (mp->dst_address.af, (u8 *) & mp->dst_address.un); + ip46_address_t dst = + to_ip46 (mp->dst_address.af, (u8 *) & mp->src_address.un); -static int -api_one_enable_disable (vat_main_t * vam) + print (vam->ofp, "%11d%11d%24U%24U%14d%18d%13d%19d", + ntohl (mp->sw_if_index), + ntohl (mp->instance), + format_ip46_address, &src, IP46_TYPE_ANY, + format_ip46_address, &dst, IP46_TYPE_ANY, + ntohl (mp->encap_vrf_id), + ntohl (mp->decap_next_index), ntohl (mp->vni), + ntohl (mp->mcast_sw_if_index)); +} + +static void vl_api_vxlan_tunnel_details_t_handler_json + (vl_api_vxlan_tunnel_details_t * mp) { - unformat_input_t *input = vam->input; - vl_api_one_enable_disable_t *mp; - u8 is_set = 0; - u8 is_enable = 0; - int ret; + vat_main_t *vam = &vat_main; + vat_json_node_t *node = NULL; - /* Parse args required to build the message */ - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + if (VAT_JSON_ARRAY != vam->json_tree.type) { - if (unformat (input, "enable")) - { - is_set = 1; - is_enable = 1; - } - else if (unformat (input, "disable")) - { - is_set = 1; - } - else - break; + ASSERT (VAT_JSON_NONE == vam->json_tree.type); + vat_json_init_array (&vam->json_tree); } + node = vat_json_array_add (&vam->json_tree); - if (!is_set) - { - errmsg ("Value not set"); - return -99; - } + vat_json_init_object (node); + vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index)); - /* Construct the API message */ - M (ONE_ENABLE_DISABLE, mp); + vat_json_object_add_uint (node, "instance", ntohl (mp->instance)); - mp->is_enable = is_enable; + if (mp->src_address.af) + { + struct in6_addr ip6; - /* send it... */ - S (mp); + clib_memcpy (&ip6, mp->src_address.un.ip6, sizeof (ip6)); + vat_json_object_add_ip6 (node, "src_address", ip6); + clib_memcpy (&ip6, mp->dst_address.un.ip6, sizeof (ip6)); + vat_json_object_add_ip6 (node, "dst_address", ip6); + } + else + { + struct in_addr ip4; - /* Wait for a reply... */ - W (ret); - return ret; + clib_memcpy (&ip4, mp->src_address.un.ip4, sizeof (ip4)); + vat_json_object_add_ip4 (node, "src_address", ip4); + clib_memcpy (&ip4, mp->dst_address.un.ip4, sizeof (ip4)); + vat_json_object_add_ip4 (node, "dst_address", ip4); + } + vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id)); + vat_json_object_add_uint (node, "decap_next_index", + ntohl (mp->decap_next_index)); + vat_json_object_add_uint (node, "vni", ntohl (mp->vni)); + vat_json_object_add_uint (node, "mcast_sw_if_index", + ntohl (mp->mcast_sw_if_index)); } -#define api_lisp_enable_disable api_one_enable_disable - static int -api_one_enable_disable_xtr_mode (vat_main_t * vam) +api_vxlan_tunnel_dump (vat_main_t * vam) { - unformat_input_t *input = vam->input; - vl_api_one_enable_disable_xtr_mode_t *mp; - u8 is_set = 0; - u8 is_enable = 0; + unformat_input_t *i = vam->input; + vl_api_vxlan_tunnel_dump_t *mp; + vl_api_control_ping_t *mp_ping; + u32 sw_if_index; + u8 sw_if_index_set = 0; int ret; /* Parse args required to build the message */ - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (input, "enable")) - { - is_set = 1; - is_enable = 1; - } - else if (unformat (input, "disable")) - { - is_set = 1; - } + if (unformat (i, "sw_if_index %d", &sw_if_index)) + sw_if_index_set = 1; else break; } - if (!is_set) + if (sw_if_index_set == 0) + { + sw_if_index = ~0; + } + + if (!vam->json_output) { - errmsg ("Value not set"); - return -99; + print (vam->ofp, "%11s%11s%24s%24s%14s%18s%13s%19s", + "sw_if_index", "instance", "src_address", "dst_address", + "encap_vrf_id", "decap_next_index", "vni", "mcast_sw_if_index"); } - /* Construct the API message */ - M (ONE_ENABLE_DISABLE_XTR_MODE, mp); + /* Get list of vxlan-tunnel interfaces */ + M (VXLAN_TUNNEL_DUMP, mp); - mp->is_enable = is_enable; + mp->sw_if_index = htonl (sw_if_index); - /* send it... */ S (mp); - /* Wait for a reply... */ - W (ret); - return ret; -} - -static int -api_one_show_xtr_mode (vat_main_t * vam) -{ - vl_api_one_show_xtr_mode_t *mp; - int ret; - - /* Construct the API message */ - M (ONE_SHOW_XTR_MODE, mp); - - /* send it... */ - S (mp); + /* Use a control ping for synchronization */ + MPING (CONTROL_PING, mp_ping); + S (mp_ping); - /* Wait for a reply... */ W (ret); return ret; } static int -api_one_enable_disable_pitr_mode (vat_main_t * vam) +api_gre_tunnel_add_del (vat_main_t * vam) { - unformat_input_t *input = vam->input; - vl_api_one_enable_disable_pitr_mode_t *mp; - u8 is_set = 0; - u8 is_enable = 0; + unformat_input_t *line_input = vam->input; + vl_api_address_t src = { }, dst = + { + }; + vl_api_gre_tunnel_add_del_t *mp; + vl_api_gre_tunnel_type_t t_type; + u8 is_add = 1; + u8 src_set = 0; + u8 dst_set = 0; + u32 outer_table_id = 0; + u32 session_id = 0; + u32 instance = ~0; int ret; - /* Parse args required to build the message */ - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + t_type = GRE_API_TUNNEL_TYPE_L3; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { - if (unformat (input, "enable")) + if (unformat (line_input, "del")) + is_add = 0; + else if (unformat (line_input, "instance %d", &instance)) + ; + else if (unformat (line_input, "src %U", unformat_vl_api_address, &src)) { - is_set = 1; - is_enable = 1; + src_set = 1; } - else if (unformat (input, "disable")) + else if (unformat (line_input, "dst %U", unformat_vl_api_address, &dst)) + { + dst_set = 1; + } + else if (unformat (line_input, "outer-table-id %d", &outer_table_id)) + ; + else if (unformat (line_input, "teb")) + t_type = GRE_API_TUNNEL_TYPE_TEB; + else if (unformat (line_input, "erspan %d", &session_id)) + t_type = GRE_API_TUNNEL_TYPE_ERSPAN; + else { - is_set = 1; + errmsg ("parse error '%U'", format_unformat_error, line_input); + return -99; } - else - break; } - if (!is_set) + if (src_set == 0) + { + errmsg ("tunnel src address not specified"); + return -99; + } + if (dst_set == 0) { - errmsg ("Value not set"); + errmsg ("tunnel dst address not specified"); return -99; } - /* Construct the API message */ - M (ONE_ENABLE_DISABLE_PITR_MODE, mp); + M (GRE_TUNNEL_ADD_DEL, mp); - mp->is_enable = is_enable; + clib_memcpy (&mp->tunnel.src, &src, sizeof (mp->tunnel.src)); + clib_memcpy (&mp->tunnel.dst, &dst, sizeof (mp->tunnel.dst)); - /* send it... */ - S (mp); + mp->tunnel.instance = htonl (instance); + mp->tunnel.outer_table_id = htonl (outer_table_id); + mp->is_add = is_add; + mp->tunnel.session_id = htons ((u16) session_id); + mp->tunnel.type = htonl (t_type); - /* Wait for a reply... */ + S (mp); W (ret); return ret; } -static int -api_one_show_pitr_mode (vat_main_t * vam) +static void vl_api_gre_tunnel_details_t_handler + (vl_api_gre_tunnel_details_t * mp) { - vl_api_one_show_pitr_mode_t *mp; - int ret; + vat_main_t *vam = &vat_main; - /* Construct the API message */ - M (ONE_SHOW_PITR_MODE, mp); + print (vam->ofp, "%11d%11d%24U%24U%13d%14d%12d", + ntohl (mp->tunnel.sw_if_index), + ntohl (mp->tunnel.instance), + format_vl_api_address, &mp->tunnel.src, + format_vl_api_address, &mp->tunnel.dst, + mp->tunnel.type, ntohl (mp->tunnel.outer_table_id), + ntohl (mp->tunnel.session_id)); +} - /* send it... */ - S (mp); +static void vl_api_gre_tunnel_details_t_handler_json + (vl_api_gre_tunnel_details_t * mp) +{ + vat_main_t *vam = &vat_main; + vat_json_node_t *node = NULL; - /* Wait for a reply... */ - W (ret); - return ret; + if (VAT_JSON_ARRAY != vam->json_tree.type) + { + ASSERT (VAT_JSON_NONE == vam->json_tree.type); + vat_json_init_array (&vam->json_tree); + } + node = vat_json_array_add (&vam->json_tree); + + vat_json_init_object (node); + vat_json_object_add_uint (node, "sw_if_index", + ntohl (mp->tunnel.sw_if_index)); + vat_json_object_add_uint (node, "instance", ntohl (mp->tunnel.instance)); + + vat_json_object_add_address (node, "src", &mp->tunnel.src); + vat_json_object_add_address (node, "dst", &mp->tunnel.dst); + vat_json_object_add_uint (node, "tunnel_type", mp->tunnel.type); + vat_json_object_add_uint (node, "outer_table_id", + ntohl (mp->tunnel.outer_table_id)); + vat_json_object_add_uint (node, "session_id", mp->tunnel.session_id); } static int -api_one_enable_disable_petr_mode (vat_main_t * vam) +api_gre_tunnel_dump (vat_main_t * vam) { - unformat_input_t *input = vam->input; - vl_api_one_enable_disable_petr_mode_t *mp; - u8 is_set = 0; - u8 is_enable = 0; + unformat_input_t *i = vam->input; + vl_api_gre_tunnel_dump_t *mp; + vl_api_control_ping_t *mp_ping; + u32 sw_if_index; + u8 sw_if_index_set = 0; int ret; /* Parse args required to build the message */ - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (input, "enable")) - { - is_set = 1; - is_enable = 1; - } - else if (unformat (input, "disable")) - { - is_set = 1; - } + if (unformat (i, "sw_if_index %d", &sw_if_index)) + sw_if_index_set = 1; else break; } - if (!is_set) + if (sw_if_index_set == 0) { - errmsg ("Value not set"); - return -99; + sw_if_index = ~0; } - /* Construct the API message */ - M (ONE_ENABLE_DISABLE_PETR_MODE, mp); + if (!vam->json_output) + { + print (vam->ofp, "%11s%11s%24s%24s%13s%14s%12s", + "sw_if_index", "instance", "src_address", "dst_address", + "tunnel_type", "outer_fib_id", "session_id"); + } - mp->is_enable = is_enable; + /* Get list of gre-tunnel interfaces */ + M (GRE_TUNNEL_DUMP, mp); + + mp->sw_if_index = htonl (sw_if_index); - /* send it... */ S (mp); - /* Wait for a reply... */ + /* Use a control ping for synchronization */ + MPING (CONTROL_PING, mp_ping); + S (mp_ping); + W (ret); return ret; } static int -api_one_show_petr_mode (vat_main_t * vam) +api_l2_fib_clear_table (vat_main_t * vam) { - vl_api_one_show_petr_mode_t *mp; +// unformat_input_t * i = vam->input; + vl_api_l2_fib_clear_table_t *mp; int ret; - /* Construct the API message */ - M (ONE_SHOW_PETR_MODE, mp); + M (L2_FIB_CLEAR_TABLE, mp); - /* send it... */ S (mp); - - /* Wait for a reply... */ W (ret); return ret; } static int -api_show_one_map_register_state (vat_main_t * vam) +api_l2_interface_efp_filter (vat_main_t * vam) { - vl_api_show_one_map_register_state_t *mp; + unformat_input_t *i = vam->input; + vl_api_l2_interface_efp_filter_t *mp; + u32 sw_if_index; + u8 enable = 1; + u8 sw_if_index_set = 0; int ret; - M (SHOW_ONE_MAP_REGISTER_STATE, mp); - - /* send */ - S (mp); - - /* wait for reply */ - W (ret); - return ret; -} + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + { + if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) + sw_if_index_set = 1; + else if (unformat (i, "sw_if_index %d", &sw_if_index)) + sw_if_index_set = 1; + else if (unformat (i, "enable")) + enable = 1; + else if (unformat (i, "disable")) + enable = 0; + else + { + clib_warning ("parse error '%U'", format_unformat_error, i); + return -99; + } + } -#define api_show_lisp_map_register_state api_show_one_map_register_state + if (sw_if_index_set == 0) + { + errmsg ("missing sw_if_index"); + return -99; + } -static int -api_show_one_rloc_probe_state (vat_main_t * vam) -{ - vl_api_show_one_rloc_probe_state_t *mp; - int ret; + M (L2_INTERFACE_EFP_FILTER, mp); - M (SHOW_ONE_RLOC_PROBE_STATE, mp); + mp->sw_if_index = ntohl (sw_if_index); + mp->enable_disable = enable; - /* send */ S (mp); - - /* wait for reply */ W (ret); return ret; } -#define api_show_lisp_rloc_probe_state api_show_one_rloc_probe_state +#define foreach_vtr_op \ +_("disable", L2_VTR_DISABLED) \ +_("push-1", L2_VTR_PUSH_1) \ +_("push-2", L2_VTR_PUSH_2) \ +_("pop-1", L2_VTR_POP_1) \ +_("pop-2", L2_VTR_POP_2) \ +_("translate-1-1", L2_VTR_TRANSLATE_1_1) \ +_("translate-1-2", L2_VTR_TRANSLATE_1_2) \ +_("translate-2-1", L2_VTR_TRANSLATE_2_1) \ +_("translate-2-2", L2_VTR_TRANSLATE_2_2) static int -api_one_add_del_ndp_entry (vat_main_t * vam) +api_l2_interface_vlan_tag_rewrite (vat_main_t * vam) { - vl_api_one_add_del_ndp_entry_t *mp; - unformat_input_t *input = vam->input; - u8 is_add = 1; - u8 mac_set = 0; - u8 bd_set = 0; - u8 ip_set = 0; - u8 mac[6] = { 0, }; - u8 ip6[16] = { 0, }; - u32 bd = ~0; + unformat_input_t *i = vam->input; + vl_api_l2_interface_vlan_tag_rewrite_t *mp; + u32 sw_if_index; + u8 sw_if_index_set = 0; + u8 vtr_op_set = 0; + u32 vtr_op = 0; + u32 push_dot1q = 1; + u32 tag1 = ~0; + u32 tag2 = ~0; int ret; - /* Parse args required to build the message */ - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (input, "del")) - is_add = 0; - else if (unformat (input, "mac %U", unformat_ethernet_address, mac)) - mac_set = 1; - else if (unformat (input, "ip %U", unformat_ip6_address, ip6)) - ip_set = 1; - else if (unformat (input, "bd %d", &bd)) - bd_set = 1; + if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) + sw_if_index_set = 1; + else if (unformat (i, "sw_if_index %d", &sw_if_index)) + sw_if_index_set = 1; + else if (unformat (i, "vtr_op %d", &vtr_op)) + vtr_op_set = 1; +#define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;} + foreach_vtr_op +#undef _ + else if (unformat (i, "push_dot1q %d", &push_dot1q)) + ; + else if (unformat (i, "tag1 %d", &tag1)) + ; + else if (unformat (i, "tag2 %d", &tag2)) + ; else { - errmsg ("parse error '%U'", format_unformat_error, input); + clib_warning ("parse error '%U'", format_unformat_error, i); return -99; } } - if (!bd_set || !ip_set || (!mac_set && is_add)) + if ((sw_if_index_set == 0) || (vtr_op_set == 0)) { - errmsg ("Missing BD, IP or MAC!"); + errmsg ("missing vtr operation or sw_if_index"); return -99; } - M (ONE_ADD_DEL_NDP_ENTRY, mp); - mp->is_add = is_add; - clib_memcpy (&mp->entry.mac, mac, 6); - mp->bd = clib_host_to_net_u32 (bd); - clib_memcpy (&mp->entry.ip6, ip6, sizeof (mp->entry.ip6)); + M (L2_INTERFACE_VLAN_TAG_REWRITE, mp); + mp->sw_if_index = ntohl (sw_if_index); + mp->vtr_op = ntohl (vtr_op); + mp->push_dot1q = ntohl (push_dot1q); + mp->tag1 = ntohl (tag1); + mp->tag2 = ntohl (tag2); - /* send */ S (mp); - - /* wait for reply */ W (ret); return ret; } static int -api_one_add_del_l2_arp_entry (vat_main_t * vam) +api_create_vhost_user_if (vat_main_t * vam) { - vl_api_one_add_del_l2_arp_entry_t *mp; - unformat_input_t *input = vam->input; - u8 is_add = 1; - u8 mac_set = 0; - u8 bd_set = 0; - u8 ip_set = 0; - u8 mac[6] = { 0, }; - u32 ip4 = 0, bd = ~0; + unformat_input_t *i = vam->input; + vl_api_create_vhost_user_if_t *mp; + u8 *file_name; + u8 is_server = 0; + u8 file_name_set = 0; + u32 custom_dev_instance = ~0; + u8 hwaddr[6]; + u8 use_custom_mac = 0; + u8 disable_mrg_rxbuf = 0; + u8 disable_indirect_desc = 0; + u8 *tag = 0; + u8 enable_gso = 0; + u8 enable_packed = 0; int ret; - /* Parse args required to build the message */ - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + /* Shut up coverity */ + clib_memset (hwaddr, 0, sizeof (hwaddr)); + + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (input, "del")) - is_add = 0; - else if (unformat (input, "mac %U", unformat_ethernet_address, mac)) - mac_set = 1; - else if (unformat (input, "ip %U", unformat_ip4_address, &ip4)) - ip_set = 1; - else if (unformat (input, "bd %d", &bd)) - bd_set = 1; + if (unformat (i, "socket %s", &file_name)) + { + file_name_set = 1; + } + else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance)) + ; + else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr)) + use_custom_mac = 1; + else if (unformat (i, "server")) + is_server = 1; + else if (unformat (i, "disable_mrg_rxbuf")) + disable_mrg_rxbuf = 1; + else if (unformat (i, "disable_indirect_desc")) + disable_indirect_desc = 1; + else if (unformat (i, "gso")) + enable_gso = 1; + else if (unformat (i, "packed")) + enable_packed = 1; + else if (unformat (i, "tag %s", &tag)) + ; else - { - errmsg ("parse error '%U'", format_unformat_error, input); - return -99; - } + break; } - if (!bd_set || !ip_set || (!mac_set && is_add)) + if (file_name_set == 0) { - errmsg ("Missing BD, IP or MAC!"); + errmsg ("missing socket file name"); return -99; } - M (ONE_ADD_DEL_L2_ARP_ENTRY, mp); - mp->is_add = is_add; - clib_memcpy (&mp->entry.mac, mac, 6); - mp->bd = clib_host_to_net_u32 (bd); - clib_memcpy (mp->entry.ip4, &ip4, sizeof (mp->entry.ip4)); - - /* send */ - S (mp); + if (vec_len (file_name) > 255) + { + errmsg ("socket file name too long"); + return -99; + } + vec_add1 (file_name, 0); - /* wait for reply */ - W (ret); - return ret; -} + M (CREATE_VHOST_USER_IF, mp); -static int -api_one_ndp_bd_get (vat_main_t * vam) -{ - vl_api_one_ndp_bd_get_t *mp; - int ret; + mp->is_server = is_server; + mp->disable_mrg_rxbuf = disable_mrg_rxbuf; + mp->disable_indirect_desc = disable_indirect_desc; + mp->enable_gso = enable_gso; + mp->enable_packed = enable_packed; + clib_memcpy (mp->sock_filename, file_name, vec_len (file_name)); + vec_free (file_name); + if (custom_dev_instance != ~0) + { + mp->renumber = 1; + mp->custom_dev_instance = ntohl (custom_dev_instance); + } - M (ONE_NDP_BD_GET, mp); + mp->use_custom_mac = use_custom_mac; + clib_memcpy (mp->mac_address, hwaddr, 6); + if (tag) + strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1); + vec_free (tag); - /* send */ S (mp); - - /* wait for reply */ W (ret); return ret; } static int -api_one_ndp_entries_get (vat_main_t * vam) +api_modify_vhost_user_if (vat_main_t * vam) { - vl_api_one_ndp_entries_get_t *mp; - unformat_input_t *input = vam->input; - u8 bd_set = 0; - u32 bd = ~0; + unformat_input_t *i = vam->input; + vl_api_modify_vhost_user_if_t *mp; + u8 *file_name; + u8 is_server = 0; + u8 file_name_set = 0; + u32 custom_dev_instance = ~0; + u8 sw_if_index_set = 0; + u32 sw_if_index = (u32) ~ 0; + u8 enable_gso = 0; + u8 enable_packed = 0; int ret; - /* Parse args required to build the message */ - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (input, "bd %d", &bd)) - bd_set = 1; - else + if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) + sw_if_index_set = 1; + else if (unformat (i, "sw_if_index %d", &sw_if_index)) + sw_if_index_set = 1; + else if (unformat (i, "socket %s", &file_name)) { - errmsg ("parse error '%U'", format_unformat_error, input); - return -99; + file_name_set = 1; } + else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance)) + ; + else if (unformat (i, "server")) + is_server = 1; + else if (unformat (i, "gso")) + enable_gso = 1; + else if (unformat (i, "packed")) + enable_packed = 1; + else + break; } - if (!bd_set) + if (sw_if_index_set == 0) { - errmsg ("Expected bridge domain!"); + errmsg ("missing sw_if_index or interface name"); return -99; } - M (ONE_NDP_ENTRIES_GET, mp); - mp->bd = clib_host_to_net_u32 (bd); - - /* send */ - S (mp); - - /* wait for reply */ - W (ret); - return ret; -} - -static int -api_one_l2_arp_bd_get (vat_main_t * vam) -{ - vl_api_one_l2_arp_bd_get_t *mp; - int ret; - - M (ONE_L2_ARP_BD_GET, mp); - - /* send */ - S (mp); - - /* wait for reply */ - W (ret); - return ret; -} - -static int -api_one_l2_arp_entries_get (vat_main_t * vam) -{ - vl_api_one_l2_arp_entries_get_t *mp; - unformat_input_t *input = vam->input; - u8 bd_set = 0; - u32 bd = ~0; - int ret; - - /* Parse args required to build the message */ - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + if (file_name_set == 0) { - if (unformat (input, "bd %d", &bd)) - bd_set = 1; - else - { - errmsg ("parse error '%U'", format_unformat_error, input); - return -99; - } + errmsg ("missing socket file name"); + return -99; } - if (!bd_set) + if (vec_len (file_name) > 255) { - errmsg ("Expected bridge domain!"); + errmsg ("socket file name too long"); return -99; } + vec_add1 (file_name, 0); - M (ONE_L2_ARP_ENTRIES_GET, mp); - mp->bd = clib_host_to_net_u32 (bd); + M (MODIFY_VHOST_USER_IF, mp); - /* send */ - S (mp); + mp->sw_if_index = ntohl (sw_if_index); + mp->is_server = is_server; + mp->enable_gso = enable_gso; + mp->enable_packed = enable_packed; + clib_memcpy (mp->sock_filename, file_name, vec_len (file_name)); + vec_free (file_name); + if (custom_dev_instance != ~0) + { + mp->renumber = 1; + mp->custom_dev_instance = ntohl (custom_dev_instance); + } - /* wait for reply */ + S (mp); W (ret); return ret; } static int -api_one_stats_enable_disable (vat_main_t * vam) +api_delete_vhost_user_if (vat_main_t * vam) { - vl_api_one_stats_enable_disable_t *mp; - unformat_input_t *input = vam->input; - u8 is_set = 0; - u8 is_enable = 0; + unformat_input_t *i = vam->input; + vl_api_delete_vhost_user_if_t *mp; + u32 sw_if_index = ~0; + u8 sw_if_index_set = 0; int ret; - /* Parse args required to build the message */ - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (input, "enable")) - { - is_set = 1; - is_enable = 1; - } - else if (unformat (input, "disable")) - { - is_set = 1; - } + if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) + sw_if_index_set = 1; + else if (unformat (i, "sw_if_index %d", &sw_if_index)) + sw_if_index_set = 1; else break; } - if (!is_set) + if (sw_if_index_set == 0) { - errmsg ("Value not set"); + errmsg ("missing sw_if_index or interface name"); return -99; } - M (ONE_STATS_ENABLE_DISABLE, mp); - mp->is_enable = is_enable; - /* send */ - S (mp); + M (DELETE_VHOST_USER_IF, mp); + + mp->sw_if_index = ntohl (sw_if_index); - /* wait for reply */ + S (mp); W (ret); return ret; } -static int -api_show_one_stats_enable_disable (vat_main_t * vam) +static void vl_api_sw_interface_vhost_user_details_t_handler + (vl_api_sw_interface_vhost_user_details_t * mp) { - vl_api_show_one_stats_enable_disable_t *mp; - int ret; - - M (SHOW_ONE_STATS_ENABLE_DISABLE, mp); + vat_main_t *vam = &vat_main; + u64 features; - /* send */ - S (mp); + features = + clib_net_to_host_u32 (mp->features_first_32) | ((u64) + clib_net_to_host_u32 + (mp->features_last_32) << + 32); - /* wait for reply */ - W (ret); - return ret; + print (vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %8x %6d %7d %s", + (char *) mp->interface_name, + ntohl (mp->sw_if_index), ntohl (mp->virtio_net_hdr_sz), + features, mp->is_server, + ntohl (mp->num_regions), (char *) mp->sock_filename); + print (vam->ofp, " Status: '%s'", strerror (ntohl (mp->sock_errno))); } -static int -api_show_one_map_request_mode (vat_main_t * vam) +static void vl_api_sw_interface_vhost_user_details_t_handler_json + (vl_api_sw_interface_vhost_user_details_t * mp) { - vl_api_show_one_map_request_mode_t *mp; - int ret; - - M (SHOW_ONE_MAP_REQUEST_MODE, mp); + vat_main_t *vam = &vat_main; + vat_json_node_t *node = NULL; - /* send */ - S (mp); + if (VAT_JSON_ARRAY != vam->json_tree.type) + { + ASSERT (VAT_JSON_NONE == vam->json_tree.type); + vat_json_init_array (&vam->json_tree); + } + node = vat_json_array_add (&vam->json_tree); - /* wait for reply */ - W (ret); - return ret; + vat_json_init_object (node); + vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index)); + vat_json_object_add_string_copy (node, "interface_name", + mp->interface_name); + vat_json_object_add_uint (node, "virtio_net_hdr_sz", + ntohl (mp->virtio_net_hdr_sz)); + vat_json_object_add_uint (node, "features_first_32", + clib_net_to_host_u32 (mp->features_first_32)); + vat_json_object_add_uint (node, "features_last_32", + clib_net_to_host_u32 (mp->features_last_32)); + vat_json_object_add_uint (node, "is_server", mp->is_server); + vat_json_object_add_string_copy (node, "sock_filename", mp->sock_filename); + vat_json_object_add_uint (node, "num_regions", ntohl (mp->num_regions)); + vat_json_object_add_uint (node, "sock_errno", ntohl (mp->sock_errno)); } -#define api_show_lisp_map_request_mode api_show_one_map_request_mode - static int -api_one_map_request_mode (vat_main_t * vam) +api_sw_interface_vhost_user_dump (vat_main_t * vam) { - unformat_input_t *input = vam->input; - vl_api_one_map_request_mode_t *mp; - u8 mode = 0; + unformat_input_t *i = vam->input; + vl_api_sw_interface_vhost_user_dump_t *mp; + vl_api_control_ping_t *mp_ping; int ret; + u32 sw_if_index = ~0; - /* Parse args required to build the message */ - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (input, "dst-only")) - mode = 0; - else if (unformat (input, "src-dst")) - mode = 1; + if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) + ; + else if (unformat (i, "sw_if_index %d", &sw_if_index)) + ; else - { - errmsg ("parse error '%U'", format_unformat_error, input); - return -99; - } + break; } - M (ONE_MAP_REQUEST_MODE, mp); - - mp->mode = mode; + print (vam->ofp, + "Interface name idx hdr_sz features server regions filename"); - /* send */ + /* Get list of vhost-user interfaces */ + M (SW_INTERFACE_VHOST_USER_DUMP, mp); + mp->sw_if_index = ntohl (sw_if_index); S (mp); - /* wait for reply */ + /* Use a control ping for synchronization */ + MPING (CONTROL_PING, mp_ping); + S (mp_ping); + W (ret); return ret; } -#define api_lisp_map_request_mode api_one_map_request_mode - -/** - * Enable/disable ONE proxy ITR. - * - * @param vam vpp API test context - * @return return code - */ static int -api_one_pitr_set_locator_set (vat_main_t * vam) +api_show_version (vat_main_t * vam) { - u8 ls_name_set = 0; - unformat_input_t *input = vam->input; - vl_api_one_pitr_set_locator_set_t *mp; - u8 is_add = 1; - u8 *ls_name = 0; + vl_api_show_version_t *mp; int ret; - /* Parse args required to build the message */ - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (input, "del")) - is_add = 0; - else if (unformat (input, "locator-set %s", &ls_name)) - ls_name_set = 1; - else - { - errmsg ("parse error '%U'", format_unformat_error, input); - return -99; - } - } - - if (!ls_name_set) - { - errmsg ("locator-set name not set!"); - return -99; - } - - M (ONE_PITR_SET_LOCATOR_SET, mp); - - mp->is_add = is_add; - clib_memcpy (mp->ls_name, ls_name, vec_len (ls_name)); - vec_free (ls_name); + M (SHOW_VERSION, mp); - /* send */ S (mp); - - /* wait for reply */ W (ret); return ret; } -#define api_lisp_pitr_set_locator_set api_one_pitr_set_locator_set static int -api_one_nsh_set_locator_set (vat_main_t * vam) +api_vxlan_gpe_add_del_tunnel (vat_main_t * vam) { - u8 ls_name_set = 0; - unformat_input_t *input = vam->input; - vl_api_one_nsh_set_locator_set_t *mp; + unformat_input_t *line_input = vam->input; + vl_api_vxlan_gpe_add_del_tunnel_t *mp; + ip46_address_t local, remote; u8 is_add = 1; - u8 *ls_name = 0; + u8 local_set = 0; + u8 remote_set = 0; + u8 grp_set = 0; + u32 mcast_sw_if_index = ~0; + u32 encap_vrf_id = 0; + u32 decap_vrf_id = 0; + u8 protocol = ~0; + u32 vni; + u8 vni_set = 0; int ret; - /* Parse args required to build the message */ - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { - if (unformat (input, "del")) + if (unformat (line_input, "del")) is_add = 0; - else if (unformat (input, "ls %s", &ls_name)) - ls_name_set = 1; + else if (unformat (line_input, "local %U", + unformat_ip46_address, &local)) + { + local_set = 1; + } + else if (unformat (line_input, "remote %U", + unformat_ip46_address, &remote)) + { + remote_set = 1; + } + else if (unformat (line_input, "group %U %U", + unformat_ip46_address, &remote, + api_unformat_sw_if_index, vam, &mcast_sw_if_index)) + { + grp_set = remote_set = 1; + } + else if (unformat (line_input, "group %U", + unformat_ip46_address, &remote)) + { + grp_set = remote_set = 1; + } + else + if (unformat (line_input, "mcast_sw_if_index %u", &mcast_sw_if_index)) + ; + else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id)) + ; + else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id)) + ; + else if (unformat (line_input, "vni %d", &vni)) + vni_set = 1; + else if (unformat (line_input, "next-ip4")) + protocol = 1; + else if (unformat (line_input, "next-ip6")) + protocol = 2; + else if (unformat (line_input, "next-ethernet")) + protocol = 3; + else if (unformat (line_input, "next-nsh")) + protocol = 4; else { - errmsg ("parse error '%U'", format_unformat_error, input); + errmsg ("parse error '%U'", format_unformat_error, line_input); return -99; } } - if (!ls_name_set && is_add) + if (local_set == 0) + { + errmsg ("tunnel local address not specified"); + return -99; + } + if (remote_set == 0) + { + errmsg ("tunnel remote address not specified"); + return -99; + } + if (grp_set && mcast_sw_if_index == ~0) + { + errmsg ("tunnel nonexistent multicast device"); + return -99; + } + if (ip46_address_is_ip4 (&local) != ip46_address_is_ip4 (&remote)) + { + errmsg ("both IPv4 and IPv6 addresses specified"); + return -99; + } + + if (vni_set == 0) { - errmsg ("locator-set name not set!"); + errmsg ("vni not specified"); return -99; } - M (ONE_NSH_SET_LOCATOR_SET, mp); + M (VXLAN_GPE_ADD_DEL_TUNNEL, mp); + + ip_address_encode (&local, + ip46_address_is_ip4 (&local) ? IP46_TYPE_IP4 : + IP46_TYPE_IP6, &mp->local); + ip_address_encode (&remote, + ip46_address_is_ip4 (&remote) ? IP46_TYPE_IP4 : + IP46_TYPE_IP6, &mp->remote); + mp->mcast_sw_if_index = ntohl (mcast_sw_if_index); + mp->encap_vrf_id = ntohl (encap_vrf_id); + mp->decap_vrf_id = ntohl (decap_vrf_id); + mp->protocol = protocol; + mp->vni = ntohl (vni); mp->is_add = is_add; - clib_memcpy (mp->ls_name, ls_name, vec_len (ls_name)); - vec_free (ls_name); - /* send */ S (mp); - - /* wait for reply */ W (ret); return ret; } -static int -api_show_one_pitr (vat_main_t * vam) +static void vl_api_vxlan_gpe_tunnel_details_t_handler + (vl_api_vxlan_gpe_tunnel_details_t * mp) { - vl_api_show_one_pitr_t *mp; - int ret; + vat_main_t *vam = &vat_main; + ip46_address_t local, remote; - if (!vam->json_output) + ip_address_decode (&mp->local, &local); + ip_address_decode (&mp->remote, &remote); + + print (vam->ofp, "%11d%24U%24U%13d%12d%19d%14d%14d", + ntohl (mp->sw_if_index), + format_ip46_address, &local, IP46_TYPE_ANY, + format_ip46_address, &remote, IP46_TYPE_ANY, + ntohl (mp->vni), mp->protocol, + ntohl (mp->mcast_sw_if_index), + ntohl (mp->encap_vrf_id), ntohl (mp->decap_vrf_id)); +} + + +static void vl_api_vxlan_gpe_tunnel_details_t_handler_json + (vl_api_vxlan_gpe_tunnel_details_t * mp) +{ + vat_main_t *vam = &vat_main; + vat_json_node_t *node = NULL; + struct in_addr ip4; + struct in6_addr ip6; + ip46_address_t local, remote; + + ip_address_decode (&mp->local, &local); + ip_address_decode (&mp->remote, &remote); + + if (VAT_JSON_ARRAY != vam->json_tree.type) { - print (vam->ofp, "%=20s", "lisp status:"); + ASSERT (VAT_JSON_NONE == vam->json_tree.type); + vat_json_init_array (&vam->json_tree); } + node = vat_json_array_add (&vam->json_tree); - M (SHOW_ONE_PITR, mp); - /* send it... */ - S (mp); - - /* Wait for a reply... */ - W (ret); - return ret; + vat_json_init_object (node); + vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index)); + if (ip46_address_is_ip4 (&local)) + { + clib_memcpy (&ip4, &local.ip4, sizeof (ip4)); + vat_json_object_add_ip4 (node, "local", ip4); + clib_memcpy (&ip4, &remote.ip4, sizeof (ip4)); + vat_json_object_add_ip4 (node, "remote", ip4); + } + else + { + clib_memcpy (&ip6, &local.ip6, sizeof (ip6)); + vat_json_object_add_ip6 (node, "local", ip6); + clib_memcpy (&ip6, &remote.ip6, sizeof (ip6)); + vat_json_object_add_ip6 (node, "remote", ip6); + } + vat_json_object_add_uint (node, "vni", ntohl (mp->vni)); + vat_json_object_add_uint (node, "protocol", ntohl (mp->protocol)); + vat_json_object_add_uint (node, "mcast_sw_if_index", + ntohl (mp->mcast_sw_if_index)); + vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id)); + vat_json_object_add_uint (node, "decap_vrf_id", ntohl (mp->decap_vrf_id)); + vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6 ? 1 : 0); } -#define api_show_lisp_pitr api_show_one_pitr - static int -api_one_use_petr (vat_main_t * vam) +api_vxlan_gpe_tunnel_dump (vat_main_t * vam) { - unformat_input_t *input = vam->input; - vl_api_one_use_petr_t *mp; - u8 is_add = 0; - ip_address_t ip; + unformat_input_t *i = vam->input; + vl_api_vxlan_gpe_tunnel_dump_t *mp; + vl_api_control_ping_t *mp_ping; + u32 sw_if_index; + u8 sw_if_index_set = 0; int ret; - clib_memset (&ip, 0, sizeof (ip)); - /* Parse args required to build the message */ - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (input, "disable")) - is_add = 0; - else - if (unformat (input, "%U", unformat_ip4_address, &ip_addr_v4 (&ip))) - { - is_add = 1; - ip_addr_version (&ip) = AF_IP4; - } - else - if (unformat (input, "%U", unformat_ip6_address, &ip_addr_v6 (&ip))) - { - is_add = 1; - ip_addr_version (&ip) = AF_IP6; - } + if (unformat (i, "sw_if_index %d", &sw_if_index)) + sw_if_index_set = 1; else - { - errmsg ("parse error '%U'", format_unformat_error, input); - return -99; - } + break; } - M (ONE_USE_PETR, mp); + if (sw_if_index_set == 0) + { + sw_if_index = ~0; + } - mp->is_add = is_add; - if (is_add) + if (!vam->json_output) { - mp->ip_address.af = ip_addr_version (&ip) == AF_IP4 ? 0 : 1; - if (mp->ip_address.af) - clib_memcpy (mp->ip_address.un.ip6, &ip, 16); - else - clib_memcpy (mp->ip_address.un.ip4, &ip, 4); + print (vam->ofp, "%11s%24s%24s%13s%15s%19s%14s%14s", + "sw_if_index", "local", "remote", "vni", + "protocol", "mcast_sw_if_index", "encap_vrf_id", "decap_vrf_id"); } - /* send */ + /* Get list of vxlan-tunnel interfaces */ + M (VXLAN_GPE_TUNNEL_DUMP, mp); + + mp->sw_if_index = htonl (sw_if_index); + S (mp); - /* wait for reply */ + /* Use a control ping for synchronization */ + MPING (CONTROL_PING, mp_ping); + S (mp_ping); + W (ret); return ret; } -#define api_lisp_use_petr api_one_use_petr +static void vl_api_l2_fib_table_details_t_handler + (vl_api_l2_fib_table_details_t * mp) +{ + vat_main_t *vam = &vat_main; + + print (vam->ofp, "%3" PRIu32 " %U %3" PRIu32 + " %d %d %d", + ntohl (mp->bd_id), format_ethernet_address, mp->mac, + ntohl (mp->sw_if_index), mp->static_mac, mp->filter_mac, + mp->bvi_mac); +} -static int -api_show_one_nsh_mapping (vat_main_t * vam) +static void vl_api_l2_fib_table_details_t_handler_json + (vl_api_l2_fib_table_details_t * mp) { - vl_api_show_one_use_petr_t *mp; - int ret; + vat_main_t *vam = &vat_main; + vat_json_node_t *node = NULL; - if (!vam->json_output) + if (VAT_JSON_ARRAY != vam->json_tree.type) { - print (vam->ofp, "%=20s", "local ONE NSH mapping:"); + ASSERT (VAT_JSON_NONE == vam->json_tree.type); + vat_json_init_array (&vam->json_tree); } + node = vat_json_array_add (&vam->json_tree); - M (SHOW_ONE_NSH_MAPPING, mp); - /* send it... */ - S (mp); - - /* Wait for a reply... */ - W (ret); - return ret; + vat_json_init_object (node); + vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id)); + vat_json_object_add_bytes (node, "mac", mp->mac, 6); + vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index)); + vat_json_object_add_uint (node, "static_mac", mp->static_mac); + vat_json_object_add_uint (node, "filter_mac", mp->filter_mac); + vat_json_object_add_uint (node, "bvi_mac", mp->bvi_mac); } static int -api_show_one_use_petr (vat_main_t * vam) +api_l2_fib_table_dump (vat_main_t * vam) { - vl_api_show_one_use_petr_t *mp; + unformat_input_t *i = vam->input; + vl_api_l2_fib_table_dump_t *mp; + vl_api_control_ping_t *mp_ping; + u32 bd_id; + u8 bd_id_set = 0; int ret; - if (!vam->json_output) + /* Parse args required to build the message */ + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + { + if (unformat (i, "bd_id %d", &bd_id)) + bd_id_set = 1; + else + break; + } + + if (bd_id_set == 0) { - print (vam->ofp, "%=20s", "Proxy-ETR status:"); + errmsg ("missing bridge domain"); + return -99; } - M (SHOW_ONE_USE_PETR, mp); - /* send it... */ + print (vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI"); + + /* Get list of l2 fib entries */ + M (L2_FIB_TABLE_DUMP, mp); + + mp->bd_id = ntohl (bd_id); S (mp); - /* Wait for a reply... */ + /* Use a control ping for synchronization */ + MPING (CONTROL_PING, mp_ping); + S (mp_ping); + W (ret); return ret; } -#define api_show_lisp_use_petr api_show_one_use_petr -/** - * Add/delete mapping between vni and vrf - */ static int -api_one_eid_table_add_del_map (vat_main_t * vam) +api_interface_name_renumber (vat_main_t * vam) { - unformat_input_t *input = vam->input; - vl_api_one_eid_table_add_del_map_t *mp; - u8 is_add = 1, vni_set = 0, vrf_set = 0, bd_index_set = 0; - u32 vni, vrf, bd_index; + unformat_input_t *line_input = vam->input; + vl_api_interface_name_renumber_t *mp; + u32 sw_if_index = ~0; + u32 new_show_dev_instance = ~0; int ret; - /* Parse args required to build the message */ - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { - if (unformat (input, "del")) - is_add = 0; - else if (unformat (input, "vrf %d", &vrf)) - vrf_set = 1; - else if (unformat (input, "bd_index %d", &bd_index)) - bd_index_set = 1; - else if (unformat (input, "vni %d", &vni)) - vni_set = 1; + if (unformat (line_input, "%U", api_unformat_sw_if_index, vam, + &sw_if_index)) + ; + else if (unformat (line_input, "sw_if_index %d", &sw_if_index)) + ; + else if (unformat (line_input, "new_show_dev_instance %d", + &new_show_dev_instance)) + ; else break; } - if (!vni_set || (!vrf_set && !bd_index_set)) + if (sw_if_index == ~0) { - errmsg ("missing arguments!"); + errmsg ("missing interface name or sw_if_index"); return -99; } - if (vrf_set && bd_index_set) + if (new_show_dev_instance == ~0) { - errmsg ("error: both vrf and bd entered!"); + errmsg ("missing new_show_dev_instance"); return -99; } - M (ONE_EID_TABLE_ADD_DEL_MAP, mp); + M (INTERFACE_NAME_RENUMBER, mp); - mp->is_add = is_add; - mp->vni = htonl (vni); - mp->dp_table = vrf_set ? htonl (vrf) : htonl (bd_index); - mp->is_l2 = bd_index_set; + mp->sw_if_index = ntohl (sw_if_index); + mp->new_show_dev_instance = ntohl (new_show_dev_instance); - /* send */ S (mp); - - /* wait for reply */ W (ret); return ret; } -#define api_lisp_eid_table_add_del_map api_one_eid_table_add_del_map - -uword -unformat_negative_mapping_action (unformat_input_t * input, va_list * args) +static int +api_want_l2_macs_events (vat_main_t * vam) { - u32 *action = va_arg (*args, u32 *); - u8 *s = 0; + unformat_input_t *line_input = vam->input; + vl_api_want_l2_macs_events_t *mp; + u8 enable_disable = 1; + u32 scan_delay = 0; + u32 max_macs_in_event = 0; + u32 learn_limit = 0; + int ret; - if (unformat (input, "%s", &s)) + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { - if (!strcmp ((char *) s, "no-action")) - action[0] = 0; - else if (!strcmp ((char *) s, "natively-forward")) - action[0] = 1; - else if (!strcmp ((char *) s, "send-map-request")) - action[0] = 2; - else if (!strcmp ((char *) s, "drop")) - action[0] = 3; + if (unformat (line_input, "learn-limit %d", &learn_limit)) + ; + else if (unformat (line_input, "scan-delay %d", &scan_delay)) + ; + else if (unformat (line_input, "max-entries %d", &max_macs_in_event)) + ; + else if (unformat (line_input, "disable")) + enable_disable = 0; else - { - clib_warning ("invalid action: '%s'", s); - action[0] = 3; - } + break; } - else - return 0; - vec_free (s); - return 1; + M (WANT_L2_MACS_EVENTS, mp); + mp->enable_disable = enable_disable; + mp->pid = htonl (getpid ()); + mp->learn_limit = htonl (learn_limit); + mp->scan_delay = (u8) scan_delay; + mp->max_macs_in_event = (u8) (max_macs_in_event / 10); + S (mp); + W (ret); + return ret; } -/** - * Add/del remote mapping to/from ONE control plane - * - * @param vam vpp API test context - * @return return code - */ static int -api_one_add_del_remote_mapping (vat_main_t * vam) +api_input_acl_set_interface (vat_main_t * vam) { - unformat_input_t *input = vam->input; - vl_api_one_add_del_remote_mapping_t *mp; - u32 vni = 0; - lisp_eid_vat_t _eid, *eid = &_eid; - lisp_eid_vat_t _seid, *seid = &_seid; - u8 is_add = 1, del_all = 0, eid_set = 0, seid_set = 0; - u32 action = ~0, p, w, data_len; - ip4_address_t rloc4; - ip6_address_t rloc6; - vl_api_remote_locator_t *rlocs = 0, rloc, *curr_rloc = 0; + unformat_input_t *i = vam->input; + vl_api_input_acl_set_interface_t *mp; + u32 sw_if_index; + int sw_if_index_set; + u32 ip4_table_index = ~0; + u32 ip6_table_index = ~0; + u32 l2_table_index = ~0; + u8 is_add = 1; int ret; - clib_memset (&rloc, 0, sizeof (rloc)); - - /* Parse args required to build the message */ - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (input, "del-all")) - { - del_all = 1; - } - else if (unformat (input, "del")) - { - is_add = 0; - } - else if (unformat (input, "add")) - { - is_add = 1; - } - else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid)) - { - eid_set = 1; - } - else if (unformat (input, "seid %U", unformat_lisp_eid_vat, seid)) - { - seid_set = 1; - } - else if (unformat (input, "vni %d", &vni)) - { - ; - } - else if (unformat (input, "p %d w %d", &p, &w)) - { - if (!curr_rloc) - { - errmsg ("No RLOC configured for setting priority/weight!"); - return -99; - } - curr_rloc->priority = p; - curr_rloc->weight = w; - } - else if (unformat (input, "rloc %U", unformat_ip4_address, &rloc4)) - { - rloc.ip_address.af = 0; - clib_memcpy (&rloc.ip_address.un.ip6, &rloc6, sizeof (rloc6)); - vec_add1 (rlocs, rloc); - curr_rloc = &rlocs[vec_len (rlocs) - 1]; - } - else if (unformat (input, "rloc %U", unformat_ip6_address, &rloc6)) - { - rloc.ip_address.af = 1; - clib_memcpy (&rloc.ip_address.un.ip4, &rloc4, sizeof (rloc4)); - vec_add1 (rlocs, rloc); - curr_rloc = &rlocs[vec_len (rlocs) - 1]; - } - else if (unformat (input, "action %U", - unformat_negative_mapping_action, &action)) - { - ; - } + if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) + sw_if_index_set = 1; + else if (unformat (i, "sw_if_index %d", &sw_if_index)) + sw_if_index_set = 1; + else if (unformat (i, "del")) + is_add = 0; + else if (unformat (i, "ip4-table %d", &ip4_table_index)) + ; + else if (unformat (i, "ip6-table %d", &ip6_table_index)) + ; + else if (unformat (i, "l2-table %d", &l2_table_index)) + ; else { - clib_warning ("parse error '%U'", format_unformat_error, input); + clib_warning ("parse error '%U'", format_unformat_error, i); return -99; } } - if (0 == eid_set) - { - errmsg ("missing params!"); - return -99; - } - - if (is_add && (~0 == action) && 0 == vec_len (rlocs)) + if (sw_if_index_set == 0) { - errmsg ("no action set for negative map-reply!"); + errmsg ("missing interface name or sw_if_index"); return -99; } - data_len = vec_len (rlocs) * sizeof (vl_api_remote_locator_t); + M (INPUT_ACL_SET_INTERFACE, mp); - M2 (ONE_ADD_DEL_REMOTE_MAPPING, mp, data_len); + mp->sw_if_index = ntohl (sw_if_index); + mp->ip4_table_index = ntohl (ip4_table_index); + mp->ip6_table_index = ntohl (ip6_table_index); + mp->l2_table_index = ntohl (l2_table_index); mp->is_add = is_add; - mp->vni = htonl (vni); - mp->action = (u8) action; - mp->is_src_dst = seid_set; - mp->del_all = del_all; - lisp_eid_put_vat (&mp->deid, eid); - lisp_eid_put_vat (&mp->seid, seid); - mp->rloc_num = clib_host_to_net_u32 (vec_len (rlocs)); - clib_memcpy (mp->rlocs, rlocs, data_len); - vec_free (rlocs); - - /* send it... */ S (mp); - - /* Wait for a reply... */ W (ret); return ret; } -#define api_lisp_add_del_remote_mapping api_one_add_del_remote_mapping - -/** - * Add/del ONE adjacency. Saves mapping in ONE control plane and updates - * forwarding entries in data-plane accordingly. - * - * @param vam vpp API test context - * @return return code - */ static int -api_one_add_del_adjacency (vat_main_t * vam) +api_output_acl_set_interface (vat_main_t * vam) { - unformat_input_t *input = vam->input; - vl_api_one_add_del_adjacency_t *mp; - u32 vni = 0; + unformat_input_t *i = vam->input; + vl_api_output_acl_set_interface_t *mp; + u32 sw_if_index; + int sw_if_index_set; + u32 ip4_table_index = ~0; + u32 ip6_table_index = ~0; + u32 l2_table_index = ~0; u8 is_add = 1; int ret; - lisp_eid_vat_t leid, reid; - - leid.type = reid.type = (u8) ~ 0; - /* Parse args required to build the message */ - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (input, "del")) - { - is_add = 0; - } - else if (unformat (input, "add")) - { - is_add = 1; - } - else if (unformat (input, "reid %U/%d", unformat_ip46_address, - &reid.addr.ip, &reid.len)) - { - reid.type = 0; /* ipv4 */ - } - else if (unformat (input, "reid %U", unformat_ethernet_address, - &reid.addr.mac)) - { - reid.type = 1; /* mac */ - } - else if (unformat (input, "leid %U/%d", unformat_ip46_address, - &leid.addr.ip, &leid.len)) - { - leid.type = 0; /* ipv4 */ - } - else if (unformat (input, "leid %U", unformat_ethernet_address, - &leid.addr.mac)) - { - leid.type = 1; /* mac */ - } - else if (unformat (input, "vni %d", &vni)) - { - ; - } + if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) + sw_if_index_set = 1; + else if (unformat (i, "sw_if_index %d", &sw_if_index)) + sw_if_index_set = 1; + else if (unformat (i, "del")) + is_add = 0; + else if (unformat (i, "ip4-table %d", &ip4_table_index)) + ; + else if (unformat (i, "ip6-table %d", &ip6_table_index)) + ; + else if (unformat (i, "l2-table %d", &l2_table_index)) + ; else { - errmsg ("parse error '%U'", format_unformat_error, input); + clib_warning ("parse error '%U'", format_unformat_error, i); return -99; } } - if ((u8) ~ 0 == reid.type) - { - errmsg ("missing params!"); - return -99; - } - - if (leid.type != reid.type) + if (sw_if_index_set == 0) { - errmsg ("remote and local EIDs are of different types!"); + errmsg ("missing interface name or sw_if_index"); return -99; } - M (ONE_ADD_DEL_ADJACENCY, mp); - mp->is_add = is_add; - mp->vni = htonl (vni); - lisp_eid_put_vat (&mp->leid, &leid); - lisp_eid_put_vat (&mp->reid, &reid); - - /* send it... */ - S (mp); - - /* Wait for a reply... */ - W (ret); - return ret; -} - -#define api_lisp_add_del_adjacency api_one_add_del_adjacency - -uword -unformat_gpe_encap_mode (unformat_input_t * input, va_list * args) -{ - u32 *mode = va_arg (*args, u32 *); - - if (unformat (input, "lisp")) - *mode = 0; - else if (unformat (input, "vxlan")) - *mode = 1; - else - return 0; - - return 1; -} - -static int -api_gpe_get_encap_mode (vat_main_t * vam) -{ - vl_api_gpe_get_encap_mode_t *mp; - int ret; - - /* Construct the API message */ - M (GPE_GET_ENCAP_MODE, mp); - - /* send it... */ - S (mp); - - /* Wait for a reply... */ - W (ret); - return ret; -} - -static int -api_gpe_set_encap_mode (vat_main_t * vam) -{ - unformat_input_t *input = vam->input; - vl_api_gpe_set_encap_mode_t *mp; - int ret; - u32 mode = 0; - - /* Parse args required to build the message */ - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (input, "%U", unformat_gpe_encap_mode, &mode)) - ; - else - break; - } - - /* Construct the API message */ - M (GPE_SET_ENCAP_MODE, mp); + M (OUTPUT_ACL_SET_INTERFACE, mp); - mp->is_vxlan = mode; + mp->sw_if_index = ntohl (sw_if_index); + mp->ip4_table_index = ntohl (ip4_table_index); + mp->ip6_table_index = ntohl (ip6_table_index); + mp->l2_table_index = ntohl (l2_table_index); + mp->is_add = is_add; - /* send it... */ S (mp); - - /* Wait for a reply... */ W (ret); return ret; } static int -api_lisp_gpe_add_del_iface (vat_main_t * vam) +api_ip_address_dump (vat_main_t * vam) { - unformat_input_t *input = vam->input; - vl_api_gpe_add_del_iface_t *mp; - u8 action_set = 0, is_add = 1, is_l2 = 0, dp_table_set = 0, vni_set = 0; - u32 dp_table = 0, vni = 0; + unformat_input_t *i = vam->input; + vl_api_ip_address_dump_t *mp; + vl_api_control_ping_t *mp_ping; + u32 sw_if_index = ~0; + u8 sw_if_index_set = 0; + u8 ipv4_set = 0; + u8 ipv6_set = 0; int ret; - /* Parse args required to build the message */ - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (input, "up")) - { - action_set = 1; - is_add = 1; - } - else if (unformat (input, "down")) - { - action_set = 1; - is_add = 0; - } - else if (unformat (input, "table_id %d", &dp_table)) - { - dp_table_set = 1; - } - else if (unformat (input, "bd_id %d", &dp_table)) - { - dp_table_set = 1; - is_l2 = 1; - } - else if (unformat (input, "vni %d", &vni)) - { - vni_set = 1; - } + if (unformat (i, "sw_if_index %d", &sw_if_index)) + sw_if_index_set = 1; + else + if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) + sw_if_index_set = 1; + else if (unformat (i, "ipv4")) + ipv4_set = 1; + else if (unformat (i, "ipv6")) + ipv6_set = 1; else break; } - if (action_set == 0) + if (ipv4_set && ipv6_set) { - errmsg ("Action not set"); + errmsg ("ipv4 and ipv6 flags cannot be both set"); return -99; } - if (dp_table_set == 0 || vni_set == 0) + + if ((!ipv4_set) && (!ipv6_set)) { - errmsg ("vni and dp_table must be set"); + errmsg ("no ipv4 nor ipv6 flag set"); return -99; } - /* Construct the API message */ - M (GPE_ADD_DEL_IFACE, mp); + if (sw_if_index_set == 0) + { + errmsg ("missing interface name or sw_if_index"); + return -99; + } - mp->is_add = is_add; - mp->dp_table = clib_host_to_net_u32 (dp_table); - mp->is_l2 = is_l2; - mp->vni = clib_host_to_net_u32 (vni); + vam->current_sw_if_index = sw_if_index; + vam->is_ipv6 = ipv6_set; - /* send it... */ + M (IP_ADDRESS_DUMP, mp); + mp->sw_if_index = ntohl (sw_if_index); + mp->is_ipv6 = ipv6_set; S (mp); - /* Wait for a reply... */ + /* Use a control ping for synchronization */ + MPING (CONTROL_PING, mp_ping); + S (mp_ping); + W (ret); return ret; } static int -api_one_map_register_fallback_threshold (vat_main_t * vam) +api_ip_dump (vat_main_t * vam) { - unformat_input_t *input = vam->input; - vl_api_one_map_register_fallback_threshold_t *mp; - u32 value = 0; - u8 is_set = 0; + vl_api_ip_dump_t *mp; + vl_api_control_ping_t *mp_ping; + unformat_input_t *in = vam->input; + int ipv4_set = 0; + int ipv6_set = 0; + int is_ipv6; + int i; int ret; - /* Parse args required to build the message */ - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT) { - if (unformat (input, "%u", &value)) - is_set = 1; + if (unformat (in, "ipv4")) + ipv4_set = 1; + else if (unformat (in, "ipv6")) + ipv6_set = 1; else - { - clib_warning ("parse error '%U'", format_unformat_error, input); - return -99; - } + break; } - if (!is_set) + if (ipv4_set && ipv6_set) { - errmsg ("fallback threshold value is missing!"); + errmsg ("ipv4 and ipv6 flags cannot be both set"); return -99; } - M (ONE_MAP_REGISTER_FALLBACK_THRESHOLD, mp); - mp->value = clib_host_to_net_u32 (value); - - /* send it... */ - S (mp); - - /* Wait for a reply... */ - W (ret); - return ret; -} + if ((!ipv4_set) && (!ipv6_set)) + { + errmsg ("no ipv4 nor ipv6 flag set"); + return -99; + } -static int -api_show_one_map_register_fallback_threshold (vat_main_t * vam) -{ - vl_api_show_one_map_register_fallback_threshold_t *mp; - int ret; + is_ipv6 = ipv6_set; + vam->is_ipv6 = is_ipv6; - M (SHOW_ONE_MAP_REGISTER_FALLBACK_THRESHOLD, mp); + /* free old data */ + for (i = 0; i < vec_len (vam->ip_details_by_sw_if_index[is_ipv6]); i++) + { + vec_free (vam->ip_details_by_sw_if_index[is_ipv6][i].addr); + } + vec_free (vam->ip_details_by_sw_if_index[is_ipv6]); - /* send it... */ + M (IP_DUMP, mp); + mp->is_ipv6 = ipv6_set; S (mp); - /* Wait for a reply... */ + /* Use a control ping for synchronization */ + MPING (CONTROL_PING, mp_ping); + S (mp_ping); + W (ret); return ret; } -uword -unformat_lisp_transport_protocol (unformat_input_t * input, va_list * args) -{ - u32 *proto = va_arg (*args, u32 *); - - if (unformat (input, "udp")) - *proto = 1; - else if (unformat (input, "api")) - *proto = 2; - else - return 0; - - return 1; -} - static int -api_one_set_transport_protocol (vat_main_t * vam) +api_ipsec_spd_add_del (vat_main_t * vam) { - unformat_input_t *input = vam->input; - vl_api_one_set_transport_protocol_t *mp; - u8 is_set = 0; - u32 protocol = 0; + unformat_input_t *i = vam->input; + vl_api_ipsec_spd_add_del_t *mp; + u32 spd_id = ~0; + u8 is_add = 1; int ret; - /* Parse args required to build the message */ - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (input, "%U", unformat_lisp_transport_protocol, &protocol)) - is_set = 1; + if (unformat (i, "spd_id %d", &spd_id)) + ; + else if (unformat (i, "del")) + is_add = 0; else { - clib_warning ("parse error '%U'", format_unformat_error, input); + clib_warning ("parse error '%U'", format_unformat_error, i); return -99; } } - - if (!is_set) + if (spd_id == ~0) { - errmsg ("Transport protocol missing!"); + errmsg ("spd_id must be set"); return -99; } - M (ONE_SET_TRANSPORT_PROTOCOL, mp); - mp->protocol = (u8) protocol; - - /* send it... */ - S (mp); - - /* Wait for a reply... */ - W (ret); - return ret; -} - -static int -api_one_get_transport_protocol (vat_main_t * vam) -{ - vl_api_one_get_transport_protocol_t *mp; - int ret; + M (IPSEC_SPD_ADD_DEL, mp); - M (ONE_GET_TRANSPORT_PROTOCOL, mp); + mp->spd_id = ntohl (spd_id); + mp->is_add = is_add; - /* send it... */ S (mp); - - /* Wait for a reply... */ W (ret); return ret; } static int -api_one_map_register_set_ttl (vat_main_t * vam) +api_ipsec_interface_add_del_spd (vat_main_t * vam) { - unformat_input_t *input = vam->input; - vl_api_one_map_register_set_ttl_t *mp; - u32 ttl = 0; - u8 is_set = 0; + unformat_input_t *i = vam->input; + vl_api_ipsec_interface_add_del_spd_t *mp; + u32 sw_if_index; + u8 sw_if_index_set = 0; + u32 spd_id = (u32) ~ 0; + u8 is_add = 1; int ret; - /* Parse args required to build the message */ - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (input, "%u", &ttl)) - is_set = 1; + if (unformat (i, "del")) + is_add = 0; + else if (unformat (i, "spd_id %d", &spd_id)) + ; + else + if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) + sw_if_index_set = 1; + else if (unformat (i, "sw_if_index %d", &sw_if_index)) + sw_if_index_set = 1; else { - clib_warning ("parse error '%U'", format_unformat_error, input); + clib_warning ("parse error '%U'", format_unformat_error, i); return -99; } + } - if (!is_set) + if (spd_id == (u32) ~ 0) { - errmsg ("TTL value missing!"); + errmsg ("spd_id must be set"); return -99; } - M (ONE_MAP_REGISTER_SET_TTL, mp); - mp->ttl = clib_host_to_net_u32 (ttl); - - /* send it... */ - S (mp); - - /* Wait for a reply... */ - W (ret); - return ret; -} + if (sw_if_index_set == 0) + { + errmsg ("missing interface name or sw_if_index"); + return -99; + } -static int -api_show_one_map_register_ttl (vat_main_t * vam) -{ - vl_api_show_one_map_register_ttl_t *mp; - int ret; + M (IPSEC_INTERFACE_ADD_DEL_SPD, mp); - M (SHOW_ONE_MAP_REGISTER_TTL, mp); + mp->spd_id = ntohl (spd_id); + mp->sw_if_index = ntohl (sw_if_index); + mp->is_add = is_add; - /* send it... */ S (mp); - - /* Wait for a reply... */ W (ret); return ret; } -/** - * Add/del map request itr rlocs from ONE control plane and updates - * - * @param vam vpp API test context - * @return return code - */ static int -api_one_add_del_map_request_itr_rlocs (vat_main_t * vam) +api_ipsec_spd_entry_add_del (vat_main_t * vam) { - unformat_input_t *input = vam->input; - vl_api_one_add_del_map_request_itr_rlocs_t *mp; - u8 *locator_set_name = 0; - u8 locator_set_name_set = 0; - u8 is_add = 1; + unformat_input_t *i = vam->input; + vl_api_ipsec_spd_entry_add_del_t *mp; + u8 is_add = 1, is_outbound = 0; + u32 spd_id = 0, sa_id = 0, protocol = 0, policy = 0; + i32 priority = 0; + u32 rport_start = 0, rport_stop = (u32) ~ 0; + u32 lport_start = 0, lport_stop = (u32) ~ 0; + vl_api_address_t laddr_start = { }, laddr_stop = + { + }, raddr_start = + { + }, raddr_stop = + { + }; int ret; - /* Parse args required to build the message */ - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (input, "del")) - { - is_add = 0; - } - else if (unformat (input, "%_%v%_", &locator_set_name)) + if (unformat (i, "del")) + is_add = 0; + if (unformat (i, "outbound")) + is_outbound = 1; + if (unformat (i, "inbound")) + is_outbound = 0; + else if (unformat (i, "spd_id %d", &spd_id)) + ; + else if (unformat (i, "sa_id %d", &sa_id)) + ; + else if (unformat (i, "priority %d", &priority)) + ; + else if (unformat (i, "protocol %d", &protocol)) + ; + else if (unformat (i, "lport_start %d", &lport_start)) + ; + else if (unformat (i, "lport_stop %d", &lport_stop)) + ; + else if (unformat (i, "rport_start %d", &rport_start)) + ; + else if (unformat (i, "rport_stop %d", &rport_stop)) + ; + else if (unformat (i, "laddr_start %U", + unformat_vl_api_address, &laddr_start)) + ; + else if (unformat (i, "laddr_stop %U", unformat_vl_api_address, + &laddr_stop)) + ; + else if (unformat (i, "raddr_start %U", unformat_vl_api_address, + &raddr_start)) + ; + else if (unformat (i, "raddr_stop %U", unformat_vl_api_address, + &raddr_stop)) + ; + else + if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy)) { - locator_set_name_set = 1; + if (policy == IPSEC_POLICY_ACTION_RESOLVE) + { + clib_warning ("unsupported action: 'resolve'"); + return -99; + } } else { - clib_warning ("parse error '%U'", format_unformat_error, input); + clib_warning ("parse error '%U'", format_unformat_error, i); return -99; } - } - if (is_add && !locator_set_name_set) - { - errmsg ("itr-rloc is not set!"); - return -99; } - if (is_add && vec_len (locator_set_name) > 64) - { - errmsg ("itr-rloc locator-set name too long"); - vec_free (locator_set_name); - return -99; - } + M (IPSEC_SPD_ENTRY_ADD_DEL, mp); - M (ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS, mp); mp->is_add = is_add; - if (is_add) - { - clib_memcpy (mp->locator_set_name, locator_set_name, - vec_len (locator_set_name)); - } - else - { - clib_memset (mp->locator_set_name, 0, sizeof (mp->locator_set_name)); - } - vec_free (locator_set_name); - /* send it... */ - S (mp); + mp->entry.spd_id = ntohl (spd_id); + mp->entry.priority = ntohl (priority); + mp->entry.is_outbound = is_outbound; - /* Wait for a reply... */ + clib_memcpy (&mp->entry.remote_address_start, &raddr_start, + sizeof (vl_api_address_t)); + clib_memcpy (&mp->entry.remote_address_stop, &raddr_stop, + sizeof (vl_api_address_t)); + clib_memcpy (&mp->entry.local_address_start, &laddr_start, + sizeof (vl_api_address_t)); + clib_memcpy (&mp->entry.local_address_stop, &laddr_stop, + sizeof (vl_api_address_t)); + + mp->entry.protocol = (u8) protocol; + mp->entry.local_port_start = ntohs ((u16) lport_start); + mp->entry.local_port_stop = ntohs ((u16) lport_stop); + mp->entry.remote_port_start = ntohs ((u16) rport_start); + mp->entry.remote_port_stop = ntohs ((u16) rport_stop); + mp->entry.policy = (u8) policy; + mp->entry.sa_id = ntohl (sa_id); + + S (mp); W (ret); return ret; } -#define api_lisp_add_del_map_request_itr_rlocs api_one_add_del_map_request_itr_rlocs - static int -api_one_locator_dump (vat_main_t * vam) +api_ipsec_sad_entry_add_del (vat_main_t * vam) { - unformat_input_t *input = vam->input; - vl_api_one_locator_dump_t *mp; - vl_api_control_ping_t *mp_ping; - u8 is_index_set = 0, is_name_set = 0; - u8 *ls_name = 0; - u32 ls_index = ~0; + unformat_input_t *i = vam->input; + vl_api_ipsec_sad_entry_add_del_t *mp; + u32 sad_id = 0, spi = 0; + u8 *ck = 0, *ik = 0; + u8 is_add = 1; + + vl_api_ipsec_crypto_alg_t crypto_alg = IPSEC_API_CRYPTO_ALG_NONE; + vl_api_ipsec_integ_alg_t integ_alg = IPSEC_API_INTEG_ALG_NONE; + vl_api_ipsec_sad_flags_t flags = IPSEC_API_SAD_FLAG_NONE; + vl_api_ipsec_proto_t protocol = IPSEC_API_PROTO_AH; + vl_api_address_t tun_src, tun_dst; int ret; - /* Parse args required to build the message */ - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (input, "ls_name %_%v%_", &ls_name)) + if (unformat (i, "del")) + is_add = 0; + else if (unformat (i, "sad_id %d", &sad_id)) + ; + else if (unformat (i, "spi %d", &spi)) + ; + else if (unformat (i, "esp")) + protocol = IPSEC_API_PROTO_ESP; + else + if (unformat (i, "tunnel_src %U", unformat_vl_api_address, &tun_src)) { - is_name_set = 1; + flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL; + if (ADDRESS_IP6 == tun_src.af) + flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL_V6; } - else if (unformat (input, "ls_index %d", &ls_index)) + else + if (unformat (i, "tunnel_dst %U", unformat_vl_api_address, &tun_dst)) { - is_index_set = 1; + flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL; + if (ADDRESS_IP6 == tun_src.af) + flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL_V6; } + else + if (unformat (i, "crypto_alg %U", + unformat_ipsec_api_crypto_alg, &crypto_alg)) + ; + else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck)) + ; + else if (unformat (i, "integ_alg %U", + unformat_ipsec_api_integ_alg, &integ_alg)) + ; + else if (unformat (i, "integ_key %U", unformat_hex_string, &ik)) + ; else { - errmsg ("parse error '%U'", format_unformat_error, input); + clib_warning ("parse error '%U'", format_unformat_error, i); return -99; } - } - - if (!is_index_set && !is_name_set) - { - errmsg ("error: expected one of index or name!"); - return -99; - } - - if (is_index_set && is_name_set) - { - errmsg ("error: only one param expected!"); - return -99; - } - if (vec_len (ls_name) > 62) - { - errmsg ("error: locator set name too long!"); - return -99; - } - - if (!vam->json_output) - { - print (vam->ofp, "%=16s%=16s%=16s", "locator", "priority", "weight"); - } - - M (ONE_LOCATOR_DUMP, mp); - mp->is_index_set = is_index_set; - - if (is_index_set) - mp->ls_index = clib_host_to_net_u32 (ls_index); - else - { - vec_add1 (ls_name, 0); - strncpy ((char *) mp->ls_name, (char *) ls_name, - sizeof (mp->ls_name) - 1); } - /* send it... */ - S (mp); + M (IPSEC_SAD_ENTRY_ADD_DEL, mp); - /* Use a control ping for synchronization */ - MPING (CONTROL_PING, mp_ping); - S (mp_ping); + mp->is_add = is_add; + mp->entry.sad_id = ntohl (sad_id); + mp->entry.protocol = protocol; + mp->entry.spi = ntohl (spi); + mp->entry.flags = flags; - /* Wait for a reply... */ - W (ret); - return ret; -} + mp->entry.crypto_algorithm = crypto_alg; + mp->entry.integrity_algorithm = integ_alg; + mp->entry.crypto_key.length = vec_len (ck); + mp->entry.integrity_key.length = vec_len (ik); -#define api_lisp_locator_dump api_one_locator_dump + if (mp->entry.crypto_key.length > sizeof (mp->entry.crypto_key.data)) + mp->entry.crypto_key.length = sizeof (mp->entry.crypto_key.data); -static int -api_one_locator_set_dump (vat_main_t * vam) -{ - vl_api_one_locator_set_dump_t *mp; - vl_api_control_ping_t *mp_ping; - unformat_input_t *input = vam->input; - u8 filter = 0; - int ret; + if (mp->entry.integrity_key.length > sizeof (mp->entry.integrity_key.data)) + mp->entry.integrity_key.length = sizeof (mp->entry.integrity_key.data); - /* Parse args required to build the message */ - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (input, "local")) - { - filter = 1; - } - else if (unformat (input, "remote")) - { - filter = 2; - } - else - { - errmsg ("parse error '%U'", format_unformat_error, input); - return -99; - } - } + if (ck) + clib_memcpy (mp->entry.crypto_key.data, ck, mp->entry.crypto_key.length); + if (ik) + clib_memcpy (mp->entry.integrity_key.data, ik, + mp->entry.integrity_key.length); - if (!vam->json_output) + if (flags & IPSEC_API_SAD_FLAG_IS_TUNNEL) { - print (vam->ofp, "%=10s%=15s", "ls_index", "ls_name"); + clib_memcpy (&mp->entry.tunnel_src, &tun_src, + sizeof (mp->entry.tunnel_src)); + clib_memcpy (&mp->entry.tunnel_dst, &tun_dst, + sizeof (mp->entry.tunnel_dst)); } - M (ONE_LOCATOR_SET_DUMP, mp); - - mp->filter = filter; - - /* send it... */ S (mp); - - /* Use a control ping for synchronization */ - MPING (CONTROL_PING, mp_ping); - S (mp_ping); - - /* Wait for a reply... */ W (ret); return ret; } -#define api_lisp_locator_set_dump api_one_locator_set_dump - static int -api_one_eid_table_map_dump (vat_main_t * vam) +api_ipsec_tunnel_if_add_del (vat_main_t * vam) { - u8 is_l2 = 0; - u8 mode_set = 0; - unformat_input_t *input = vam->input; - vl_api_one_eid_table_map_dump_t *mp; - vl_api_control_ping_t *mp_ping; - int ret; + unformat_input_t *i = vam->input; + vl_api_ipsec_tunnel_if_add_del_t *mp; + u32 local_spi = 0, remote_spi = 0; + u32 crypto_alg = 0, integ_alg = 0; + u8 *lck = NULL, *rck = NULL; + u8 *lik = NULL, *rik = NULL; + vl_api_address_t local_ip = { 0 }; + vl_api_address_t remote_ip = { 0 }; + f64 before = 0; + u8 is_add = 1; + u8 esn = 0; + u8 anti_replay = 0; + u8 renumber = 0; + u32 instance = ~0; + u32 count = 1, jj; + int ret = -1; - /* Parse args required to build the message */ - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (input, "l2")) + if (unformat (i, "del")) + is_add = 0; + else if (unformat (i, "esn")) + esn = 1; + else if (unformat (i, "anti-replay")) + anti_replay = 1; + else if (unformat (i, "count %d", &count)) + ; + else if (unformat (i, "local_spi %d", &local_spi)) + ; + else if (unformat (i, "remote_spi %d", &remote_spi)) + ; + else + if (unformat (i, "local_ip %U", unformat_vl_api_address, &local_ip)) + ; + else + if (unformat (i, "remote_ip %U", unformat_vl_api_address, &remote_ip)) + ; + else if (unformat (i, "local_crypto_key %U", unformat_hex_string, &lck)) + ; + else + if (unformat (i, "remote_crypto_key %U", unformat_hex_string, &rck)) + ; + else if (unformat (i, "local_integ_key %U", unformat_hex_string, &lik)) + ; + else if (unformat (i, "remote_integ_key %U", unformat_hex_string, &rik)) + ; + else + if (unformat + (i, "crypto_alg %U", unformat_ipsec_api_crypto_alg, &crypto_alg)) { - is_l2 = 1; - mode_set = 1; + if (crypto_alg >= IPSEC_CRYPTO_N_ALG) + { + errmsg ("unsupported crypto-alg: '%U'\n", + format_ipsec_crypto_alg, crypto_alg); + return -99; + } } - else if (unformat (input, "l3")) + else + if (unformat + (i, "integ_alg %U", unformat_ipsec_api_integ_alg, &integ_alg)) { - is_l2 = 0; - mode_set = 1; + if (integ_alg >= IPSEC_INTEG_N_ALG) + { + errmsg ("unsupported integ-alg: '%U'\n", + format_ipsec_integ_alg, integ_alg); + return -99; + } } + else if (unformat (i, "instance %u", &instance)) + renumber = 1; else { - errmsg ("parse error '%U'", format_unformat_error, input); + errmsg ("parse error '%U'\n", format_unformat_error, i); return -99; } } - if (!mode_set) - { - errmsg ("expected one of 'l2' or 'l3' parameter!"); - return -99; - } - - if (!vam->json_output) + if (count > 1) { - print (vam->ofp, "%=10s%=10s", "VNI", is_l2 ? "BD" : "VRF"); + /* Turn on async mode */ + vam->async_mode = 1; + vam->async_errors = 0; + before = vat_time_now (vam); } - M (ONE_EID_TABLE_MAP_DUMP, mp); - mp->is_l2 = is_l2; - - /* send it... */ - S (mp); - - /* Use a control ping for synchronization */ - MPING (CONTROL_PING, mp_ping); - S (mp_ping); - - /* Wait for a reply... */ - W (ret); - return ret; -} - -#define api_lisp_eid_table_map_dump api_one_eid_table_map_dump - -static int -api_one_eid_table_vni_dump (vat_main_t * vam) -{ - vl_api_one_eid_table_vni_dump_t *mp; - vl_api_control_ping_t *mp_ping; - int ret; - - if (!vam->json_output) + for (jj = 0; jj < count; jj++) { - print (vam->ofp, "VNI"); - } - - M (ONE_EID_TABLE_VNI_DUMP, mp); - - /* send it... */ - S (mp); + M (IPSEC_TUNNEL_IF_ADD_DEL, mp); - /* Use a control ping for synchronization */ - MPING (CONTROL_PING, mp_ping); - S (mp_ping); + mp->is_add = is_add; + mp->esn = esn; + mp->anti_replay = anti_replay; - /* Wait for a reply... */ - W (ret); - return ret; -} + if (jj > 0) + increment_address (&remote_ip); -#define api_lisp_eid_table_vni_dump api_one_eid_table_vni_dump + clib_memcpy (&mp->local_ip, &local_ip, sizeof (local_ip)); + clib_memcpy (&mp->remote_ip, &remote_ip, sizeof (remote_ip)); -static int -api_one_eid_table_dump (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_one_eid_table_dump_t *mp; - vl_api_control_ping_t *mp_ping; - u8 filter = 0; - int ret; - u32 vni, t = 0; - lisp_eid_vat_t eid; - u8 eid_set = 0; + mp->local_spi = htonl (local_spi + jj); + mp->remote_spi = htonl (remote_spi + jj); + mp->crypto_alg = (u8) crypto_alg; - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat - (i, "eid %U/%d", unformat_ip46_address, &eid.addr.ip, &eid.len)) - { - eid_set = 1; - eid.type = 0; - } - else - if (unformat (i, "eid %U", unformat_ethernet_address, &eid.addr.mac)) - { - eid_set = 1; - eid.type = 1; - } - else if (unformat (i, "eid %U", unformat_nsh_address, &eid.addr.nsh)) + mp->local_crypto_key_len = 0; + if (lck) { - eid_set = 1; - eid.type = 2; + mp->local_crypto_key_len = vec_len (lck); + if (mp->local_crypto_key_len > sizeof (mp->local_crypto_key)) + mp->local_crypto_key_len = sizeof (mp->local_crypto_key); + clib_memcpy (mp->local_crypto_key, lck, mp->local_crypto_key_len); } - else if (unformat (i, "vni %d", &t)) + + mp->remote_crypto_key_len = 0; + if (rck) { - vni = t; + mp->remote_crypto_key_len = vec_len (rck); + if (mp->remote_crypto_key_len > sizeof (mp->remote_crypto_key)) + mp->remote_crypto_key_len = sizeof (mp->remote_crypto_key); + clib_memcpy (mp->remote_crypto_key, rck, mp->remote_crypto_key_len); } - else if (unformat (i, "local")) + + mp->integ_alg = (u8) integ_alg; + + mp->local_integ_key_len = 0; + if (lik) { - filter = 1; + mp->local_integ_key_len = vec_len (lik); + if (mp->local_integ_key_len > sizeof (mp->local_integ_key)) + mp->local_integ_key_len = sizeof (mp->local_integ_key); + clib_memcpy (mp->local_integ_key, lik, mp->local_integ_key_len); } - else if (unformat (i, "remote")) + + mp->remote_integ_key_len = 0; + if (rik) { - filter = 2; + mp->remote_integ_key_len = vec_len (rik); + if (mp->remote_integ_key_len > sizeof (mp->remote_integ_key)) + mp->remote_integ_key_len = sizeof (mp->remote_integ_key); + clib_memcpy (mp->remote_integ_key, rik, mp->remote_integ_key_len); } - else + + if (renumber) { - errmsg ("parse error '%U'", format_unformat_error, i); - return -99; + mp->renumber = renumber; + mp->show_instance = ntohl (instance); } + S (mp); } - if (!vam->json_output) - { - print (vam->ofp, "%-35s%-20s%-30s%-20s%-20s%-10s%-20s", "EID", - "type", "ls_index", "ttl", "authoritative", "key_id", "key"); - } - - M (ONE_EID_TABLE_DUMP, mp); - - mp->filter = filter; - if (eid_set) + /* When testing multiple add/del ops, use a control-ping to sync */ + if (count > 1) { - mp->eid_set = 1; - mp->vni = htonl (vni); - lisp_eid_put_vat (&mp->eid, &eid); - } - - /* send it... */ - S (mp); + vl_api_control_ping_t *mp_ping; + f64 after; + f64 timeout; - /* Use a control ping for synchronization */ - MPING (CONTROL_PING, mp_ping); - S (mp_ping); + /* Shut off async mode */ + vam->async_mode = 0; - /* Wait for a reply... */ - W (ret); - return ret; -} + MPING (CONTROL_PING, mp_ping); + S (mp_ping); -#define api_lisp_eid_table_dump api_one_eid_table_dump + timeout = vat_time_now (vam) + 1.0; + while (vat_time_now (vam) < timeout) + if (vam->result_ready == 1) + goto out; + vam->retval = -99; -static int -api_lisp_gpe_fwd_entries_get (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_gpe_fwd_entries_get_t *mp; - u8 vni_set = 0; - u32 vni = ~0; - int ret; + out: + if (vam->retval == -99) + errmsg ("timeout"); - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "vni %d", &vni)) - { - vni_set = 1; - } - else + if (vam->async_errors > 0) { - errmsg ("parse error '%U'", format_unformat_error, i); - return -99; + errmsg ("%d asynchronous errors", vam->async_errors); + vam->retval = -98; } - } + vam->async_errors = 0; + after = vat_time_now (vam); - if (!vni_set) - { - errmsg ("vni not set!"); - return -99; - } + /* slim chance, but we might have eaten SIGTERM on the first iteration */ + if (jj > 0) + count = jj; - if (!vam->json_output) + print (vam->ofp, "%d tunnels in %.6f secs, %.2f tunnels/sec", + count, after - before, count / (after - before)); + } + else { - print (vam->ofp, "%10s %10s %s %40s", "fwd_index", "dp_table", - "leid", "reid"); + /* Wait for a reply... */ + W (ret); + return ret; } - M (GPE_FWD_ENTRIES_GET, mp); - mp->vni = clib_host_to_net_u32 (vni); - - /* send it... */ - S (mp); - - /* Wait for a reply... */ - W (ret); return ret; } -#define vl_api_gpe_native_fwd_rpaths_get_reply_t_endian vl_noop_handler -#define vl_api_gpe_native_fwd_rpaths_get_reply_t_print vl_noop_handler -#define vl_api_gpe_fwd_entry_vnis_get_reply_t_endian vl_noop_handler -#define vl_api_gpe_fwd_entry_vnis_get_reply_t_print vl_noop_handler -#define vl_api_gpe_fwd_entries_get_reply_t_endian vl_noop_handler -#define vl_api_gpe_fwd_entries_get_reply_t_print vl_noop_handler -#define vl_api_gpe_fwd_entry_path_details_t_endian vl_noop_handler -#define vl_api_gpe_fwd_entry_path_details_t_print vl_noop_handler - -static int -api_one_adjacencies_get (vat_main_t * vam) +static void +vl_api_ipsec_sa_details_t_handler (vl_api_ipsec_sa_details_t * mp) { - unformat_input_t *i = vam->input; - vl_api_one_adjacencies_get_t *mp; - u8 vni_set = 0; - u32 vni = ~0; - int ret; + vat_main_t *vam = &vat_main; - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "vni %d", &vni)) - { - vni_set = 1; - } - else - { - errmsg ("parse error '%U'", format_unformat_error, i); - return -99; - } - } + print (vam->ofp, "sa_id %u sw_if_index %u spi %u proto %u crypto_alg %u " + "crypto_key %U integ_alg %u integ_key %U flags %x " + "tunnel_src_addr %U tunnel_dst_addr %U " + "salt %u seq_outbound %lu last_seq_inbound %lu " + "replay_window %lu stat_index %u\n", + ntohl (mp->entry.sad_id), + ntohl (mp->sw_if_index), + ntohl (mp->entry.spi), + ntohl (mp->entry.protocol), + ntohl (mp->entry.crypto_algorithm), + format_hex_bytes, mp->entry.crypto_key.data, + mp->entry.crypto_key.length, ntohl (mp->entry.integrity_algorithm), + format_hex_bytes, mp->entry.integrity_key.data, + mp->entry.integrity_key.length, ntohl (mp->entry.flags), + format_vl_api_address, &mp->entry.tunnel_src, format_vl_api_address, + &mp->entry.tunnel_dst, ntohl (mp->salt), + clib_net_to_host_u64 (mp->seq_outbound), + clib_net_to_host_u64 (mp->last_seq_inbound), + clib_net_to_host_u64 (mp->replay_window), ntohl (mp->stat_index)); +} - if (!vni_set) - { - errmsg ("vni not set!"); - return -99; - } +#define vl_api_ipsec_sa_details_t_endian vl_noop_handler +#define vl_api_ipsec_sa_details_t_print vl_noop_handler - if (!vam->json_output) +static void vl_api_ipsec_sa_details_t_handler_json + (vl_api_ipsec_sa_details_t * mp) +{ + vat_main_t *vam = &vat_main; + vat_json_node_t *node = NULL; + vl_api_ipsec_sad_flags_t flags; + + if (VAT_JSON_ARRAY != vam->json_tree.type) { - print (vam->ofp, "%s %40s", "leid", "reid"); + ASSERT (VAT_JSON_NONE == vam->json_tree.type); + vat_json_init_array (&vam->json_tree); } + node = vat_json_array_add (&vam->json_tree); - M (ONE_ADJACENCIES_GET, mp); - mp->vni = clib_host_to_net_u32 (vni); - - /* send it... */ - S (mp); - - /* Wait for a reply... */ - W (ret); - return ret; + vat_json_init_object (node); + vat_json_object_add_uint (node, "sa_id", ntohl (mp->entry.sad_id)); + vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index)); + vat_json_object_add_uint (node, "spi", ntohl (mp->entry.spi)); + vat_json_object_add_uint (node, "proto", ntohl (mp->entry.protocol)); + vat_json_object_add_uint (node, "crypto_alg", + ntohl (mp->entry.crypto_algorithm)); + vat_json_object_add_uint (node, "integ_alg", + ntohl (mp->entry.integrity_algorithm)); + flags = ntohl (mp->entry.flags); + vat_json_object_add_uint (node, "use_esn", + ! !(flags & IPSEC_API_SAD_FLAG_USE_ESN)); + vat_json_object_add_uint (node, "use_anti_replay", + ! !(flags & IPSEC_API_SAD_FLAG_USE_ANTI_REPLAY)); + vat_json_object_add_uint (node, "is_tunnel", + ! !(flags & IPSEC_API_SAD_FLAG_IS_TUNNEL)); + vat_json_object_add_uint (node, "is_tunnel_ip6", + ! !(flags & IPSEC_API_SAD_FLAG_IS_TUNNEL_V6)); + vat_json_object_add_uint (node, "udp_encap", + ! !(flags & IPSEC_API_SAD_FLAG_UDP_ENCAP)); + vat_json_object_add_bytes (node, "crypto_key", mp->entry.crypto_key.data, + mp->entry.crypto_key.length); + vat_json_object_add_bytes (node, "integ_key", mp->entry.integrity_key.data, + mp->entry.integrity_key.length); + vat_json_object_add_address (node, "src", &mp->entry.tunnel_src); + vat_json_object_add_address (node, "dst", &mp->entry.tunnel_dst); + vat_json_object_add_uint (node, "replay_window", + clib_net_to_host_u64 (mp->replay_window)); + vat_json_object_add_uint (node, "stat_index", ntohl (mp->stat_index)); } -#define api_lisp_adjacencies_get api_one_adjacencies_get - static int -api_gpe_native_fwd_rpaths_get (vat_main_t * vam) +api_ipsec_sa_dump (vat_main_t * vam) { unformat_input_t *i = vam->input; - vl_api_gpe_native_fwd_rpaths_get_t *mp; + vl_api_ipsec_sa_dump_t *mp; + vl_api_control_ping_t *mp_ping; + u32 sa_id = ~0; int ret; - u8 ip_family_set = 0, is_ip4 = 1; while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (i, "ip4")) - { - ip_family_set = 1; - is_ip4 = 1; - } - else if (unformat (i, "ip6")) - { - ip_family_set = 1; - is_ip4 = 0; - } + if (unformat (i, "sa_id %d", &sa_id)) + ; else { - errmsg ("parse error '%U'", format_unformat_error, i); + clib_warning ("parse error '%U'", format_unformat_error, i); return -99; } } - if (!ip_family_set) - { - errmsg ("ip family not set!"); - return -99; - } + M (IPSEC_SA_DUMP, mp); - M (GPE_NATIVE_FWD_RPATHS_GET, mp); - mp->is_ip4 = is_ip4; + mp->sa_id = ntohl (sa_id); - /* send it... */ S (mp); - /* Wait for a reply... */ - W (ret); - return ret; -} - -static int -api_gpe_fwd_entry_vnis_get (vat_main_t * vam) -{ - vl_api_gpe_fwd_entry_vnis_get_t *mp; - int ret; - - if (!vam->json_output) - { - print (vam->ofp, "VNIs"); - } - - M (GPE_FWD_ENTRY_VNIS_GET, mp); - - /* send it... */ - S (mp); + /* Use a control ping for synchronization */ + M (CONTROL_PING, mp_ping); + S (mp_ping); - /* Wait for a reply... */ W (ret); return ret; } static int -api_gpe_add_del_native_fwd_rpath (vat_main_t * vam) +api_ipsec_tunnel_if_set_sa (vat_main_t * vam) { unformat_input_t *i = vam->input; - vl_api_gpe_add_del_native_fwd_rpath_t *mp; - int ret = 0; - u8 is_add = 1, ip_set = 0, is_ip4 = 1; - struct in_addr ip4; - struct in6_addr ip6; - u32 table_id = 0, nh_sw_if_index = ~0; - - clib_memset (&ip4, 0, sizeof (ip4)); - clib_memset (&ip6, 0, sizeof (ip6)); + vl_api_ipsec_tunnel_if_set_sa_t *mp; + u32 sw_if_index = ~0; + u32 sa_id = ~0; + u8 is_outbound = (u8) ~ 0; + int ret; while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - if (unformat (i, "del")) - is_add = 0; - else if (unformat (i, "via %U %U", unformat_ip4_address, &ip4, - api_unformat_sw_if_index, vam, &nh_sw_if_index)) - { - ip_set = 1; - is_ip4 = 1; - } - else if (unformat (i, "via %U %U", unformat_ip6_address, &ip6, - api_unformat_sw_if_index, vam, &nh_sw_if_index)) - { - ip_set = 1; - is_ip4 = 0; - } - else if (unformat (i, "via %U", unformat_ip4_address, &ip4)) - { - ip_set = 1; - is_ip4 = 1; - nh_sw_if_index = ~0; - } - else if (unformat (i, "via %U", unformat_ip6_address, &ip6)) - { - ip_set = 1; - is_ip4 = 0; - nh_sw_if_index = ~0; - } - else if (unformat (i, "table %d", &table_id)) + if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index)) ; + else if (unformat (i, "sa_id %d", &sa_id)) + ; + else if (unformat (i, "outbound")) + is_outbound = 1; + else if (unformat (i, "inbound")) + is_outbound = 0; else { - errmsg ("parse error '%U'", format_unformat_error, i); + clib_warning ("parse error '%U'", format_unformat_error, i); return -99; } } - if (!ip_set) + if (sw_if_index == ~0) { - errmsg ("nh addr not set!"); + errmsg ("interface must be specified"); return -99; } - M (GPE_ADD_DEL_NATIVE_FWD_RPATH, mp); - mp->is_add = is_add; - mp->table_id = clib_host_to_net_u32 (table_id); - mp->nh_sw_if_index = clib_host_to_net_u32 (nh_sw_if_index); - mp->nh_addr.af = is_ip4 ? 0 : 1; - if (is_ip4) - clib_memcpy (mp->nh_addr.un.ip4, &ip4, sizeof (ip4)); - else - clib_memcpy (mp->nh_addr.un.ip6, &ip6, sizeof (ip6)); - - /* send it... */ - S (mp); - - /* Wait for a reply... */ - W (ret); - return ret; -} - -static int -api_one_map_server_dump (vat_main_t * vam) -{ - vl_api_one_map_server_dump_t *mp; - vl_api_control_ping_t *mp_ping; - int ret; - - if (!vam->json_output) + if (sa_id == ~0) { - print (vam->ofp, "%=20s", "Map server"); + errmsg ("SA ID must be specified"); + return -99; } - M (ONE_MAP_SERVER_DUMP, mp); - /* send it... */ - S (mp); + M (IPSEC_TUNNEL_IF_SET_SA, mp); - /* Use a control ping for synchronization */ - MPING (CONTROL_PING, mp_ping); - S (mp_ping); + mp->sw_if_index = htonl (sw_if_index); + mp->sa_id = htonl (sa_id); + mp->is_outbound = is_outbound; - /* Wait for a reply... */ + S (mp); W (ret); + return ret; } -#define api_lisp_map_server_dump api_one_map_server_dump - static int -api_one_map_resolver_dump (vat_main_t * vam) +api_get_first_msg_id (vat_main_t * vam) { - vl_api_one_map_resolver_dump_t *mp; - vl_api_control_ping_t *mp_ping; + vl_api_get_first_msg_id_t *mp; + unformat_input_t *i = vam->input; + u8 *name; + u8 name_set = 0; int ret; - if (!vam->json_output) + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) { - print (vam->ofp, "%=20s", "Map resolver"); + if (unformat (i, "client %s", &name)) + name_set = 1; + else + break; } - M (ONE_MAP_RESOLVER_DUMP, mp); - /* send it... */ - S (mp); - - /* Use a control ping for synchronization */ - MPING (CONTROL_PING, mp_ping); - S (mp_ping); - - /* Wait for a reply... */ - W (ret); - return ret; -} - -#define api_lisp_map_resolver_dump api_one_map_resolver_dump + if (name_set == 0) + { + errmsg ("missing client name"); + return -99; + } + vec_add1 (name, 0); -static int -api_one_stats_flush (vat_main_t * vam) -{ - vl_api_one_stats_flush_t *mp; - int ret = 0; + if (vec_len (name) > 63) + { + errmsg ("client name too long"); + return -99; + } - M (ONE_STATS_FLUSH, mp); + M (GET_FIRST_MSG_ID, mp); + clib_memcpy (mp->name, name, vec_len (name)); S (mp); W (ret); return ret; } static int -api_one_stats_dump (vat_main_t * vam) +api_cop_interface_enable_disable (vat_main_t * vam) { - vl_api_one_stats_dump_t *mp; - vl_api_control_ping_t *mp_ping; + unformat_input_t *line_input = vam->input; + vl_api_cop_interface_enable_disable_t *mp; + u32 sw_if_index = ~0; + u8 enable_disable = 1; int ret; - M (ONE_STATS_DUMP, mp); - /* send it... */ - S (mp); - - /* Use a control ping for synchronization */ - MPING (CONTROL_PING, mp_ping); - S (mp_ping); - - /* Wait for a reply... */ - W (ret); - return ret; -} - -static int -api_show_one_status (vat_main_t * vam) -{ - vl_api_show_one_status_t *mp; - int ret; + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (line_input, "disable")) + enable_disable = 0; + if (unformat (line_input, "enable")) + enable_disable = 1; + else if (unformat (line_input, "%U", api_unformat_sw_if_index, + vam, &sw_if_index)) + ; + else if (unformat (line_input, "sw_if_index %d", &sw_if_index)) + ; + else + break; + } - if (!vam->json_output) + if (sw_if_index == ~0) { - print (vam->ofp, "%-20s%-16s", "ONE status", "locator-set"); + errmsg ("missing interface name or sw_if_index"); + return -99; } - M (SHOW_ONE_STATUS, mp); + /* Construct the API message */ + M (COP_INTERFACE_ENABLE_DISABLE, mp); + mp->sw_if_index = ntohl (sw_if_index); + mp->enable_disable = enable_disable; + /* send it... */ S (mp); - /* Wait for a reply... */ + /* Wait for the reply */ W (ret); return ret; } -#define api_show_lisp_status api_show_one_status - static int -api_lisp_gpe_fwd_entry_path_dump (vat_main_t * vam) +api_cop_whitelist_enable_disable (vat_main_t * vam) { - vl_api_gpe_fwd_entry_path_dump_t *mp; - vl_api_control_ping_t *mp_ping; - unformat_input_t *i = vam->input; - u32 fwd_entry_index = ~0; + unformat_input_t *line_input = vam->input; + vl_api_cop_whitelist_enable_disable_t *mp; + u32 sw_if_index = ~0; + u8 ip4 = 0, ip6 = 0, default_cop = 0; + u32 fib_id = 0; int ret; - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { - if (unformat (i, "index %d", &fwd_entry_index)) + if (unformat (line_input, "ip4")) + ip4 = 1; + else if (unformat (line_input, "ip6")) + ip6 = 1; + else if (unformat (line_input, "default")) + default_cop = 1; + else if (unformat (line_input, "%U", api_unformat_sw_if_index, + vam, &sw_if_index)) + ; + else if (unformat (line_input, "sw_if_index %d", &sw_if_index)) + ; + else if (unformat (line_input, "fib-id %d", &fib_id)) ; else break; } - if (~0 == fwd_entry_index) + if (sw_if_index == ~0) { - errmsg ("no index specified!"); + errmsg ("missing interface name or sw_if_index"); return -99; } - if (!vam->json_output) - { - print (vam->ofp, "first line"); - } - - M (GPE_FWD_ENTRY_PATH_DUMP, mp); + /* Construct the API message */ + M (COP_WHITELIST_ENABLE_DISABLE, mp); + mp->sw_if_index = ntohl (sw_if_index); + mp->fib_id = ntohl (fib_id); + mp->ip4 = ip4; + mp->ip6 = ip6; + mp->default_cop = default_cop; /* send it... */ S (mp); - /* Use a control ping for synchronization */ - MPING (CONTROL_PING, mp_ping); - S (mp_ping); - - /* Wait for a reply... */ + /* Wait for the reply */ W (ret); return ret; } static int -api_one_get_map_request_itr_rlocs (vat_main_t * vam) +api_get_node_graph (vat_main_t * vam) { - vl_api_one_get_map_request_itr_rlocs_t *mp; + vl_api_get_node_graph_t *mp; int ret; - if (!vam->json_output) - { - print (vam->ofp, "%=20s", "itr-rlocs:"); - } + M (GET_NODE_GRAPH, mp); - M (ONE_GET_MAP_REQUEST_ITR_RLOCS, mp); /* send it... */ S (mp); - /* Wait for a reply... */ + /* Wait for the reply */ W (ret); return ret; } -#define api_lisp_get_map_request_itr_rlocs api_one_get_map_request_itr_rlocs - static int api_af_packet_create (vat_main_t * vam) { @@ -20187,128 +15281,6 @@ _(get_node_graph, " ") \ _(sw_interface_clear_stats," | sw_if_index ") \ _(ioam_enable, "[trace] [pow] [ppc ]") \ _(ioam_disable, "") \ -_(one_add_del_locator_set, "locator-set [iface |" \ - " sw_if_index p " \ - "w ] [del]") \ -_(one_add_del_locator, "locator-set " \ - "iface | sw_if_index " \ - "p w [del]") \ -_(one_add_del_local_eid,"vni eid " \ - "/ | " \ - "locator-set [del]" \ - "[key-id sha1|sha256 secret-key ]")\ -_(one_add_del_map_resolver, " [del]") \ -_(one_add_del_map_server, " [del]") \ -_(one_enable_disable, "enable|disable") \ -_(one_map_register_enable_disable, "enable|disable") \ -_(one_map_register_fallback_threshold, "") \ -_(one_rloc_probe_enable_disable, "enable|disable") \ -_(one_add_del_remote_mapping, "add|del vni eid " \ - "[seid ] " \ - "rloc p " \ - "w [rloc ... ] " \ - "action [del-all]") \ -_(one_add_del_adjacency, "add|del vni reid leid " \ - "") \ -_(one_pitr_set_locator_set, "locator-set | del") \ -_(one_use_petr, "ip-address> | disable") \ -_(one_map_request_mode, "src-dst|dst-only") \ -_(one_add_del_map_request_itr_rlocs, " [del]") \ -_(one_eid_table_add_del_map, "[del] vni vrf ") \ -_(one_locator_set_dump, "[local | remote]") \ -_(one_locator_dump, "ls_index | ls_name ") \ -_(one_eid_table_dump, "[eid / | ] [vni] " \ - "[local] | [remote]") \ -_(one_add_del_ndp_entry, "[del] mac bd ip6 ") \ -_(one_ndp_bd_get, "") \ -_(one_ndp_entries_get, "bd ") \ -_(one_add_del_l2_arp_entry, "[del] mac bd ip ") \ -_(one_l2_arp_bd_get, "") \ -_(one_l2_arp_entries_get, "bd ") \ -_(one_stats_enable_disable, "enable|disable") \ -_(show_one_stats_enable_disable, "") \ -_(one_eid_table_vni_dump, "") \ -_(one_eid_table_map_dump, "l2|l3") \ -_(one_map_resolver_dump, "") \ -_(one_map_server_dump, "") \ -_(one_adjacencies_get, "vni ") \ -_(one_nsh_set_locator_set, "[del] ls ") \ -_(show_one_rloc_probe_state, "") \ -_(show_one_map_register_state, "") \ -_(show_one_status, "") \ -_(one_stats_dump, "") \ -_(one_stats_flush, "") \ -_(one_get_map_request_itr_rlocs, "") \ -_(one_map_register_set_ttl, "") \ -_(one_set_transport_protocol, "udp|api") \ -_(one_get_transport_protocol, "") \ -_(one_enable_disable_xtr_mode, "enable|disable") \ -_(one_show_xtr_mode, "") \ -_(one_enable_disable_pitr_mode, "enable|disable") \ -_(one_show_pitr_mode, "") \ -_(one_enable_disable_petr_mode, "enable|disable") \ -_(one_show_petr_mode, "") \ -_(show_one_nsh_mapping, "") \ -_(show_one_pitr, "") \ -_(show_one_use_petr, "") \ -_(show_one_map_request_mode, "") \ -_(show_one_map_register_ttl, "") \ -_(show_one_map_register_fallback_threshold, "") \ -_(lisp_add_del_locator_set, "locator-set [iface |"\ - " sw_if_index p " \ - "w ] [del]") \ -_(lisp_add_del_locator, "locator-set " \ - "iface | sw_if_index " \ - "p w [del]") \ -_(lisp_add_del_local_eid,"vni eid " \ - "/ | " \ - "locator-set [del]" \ - "[key-id sha1|sha256 secret-key ]") \ -_(lisp_add_del_map_resolver, " [del]") \ -_(lisp_add_del_map_server, " [del]") \ -_(lisp_enable_disable, "enable|disable") \ -_(lisp_map_register_enable_disable, "enable|disable") \ -_(lisp_rloc_probe_enable_disable, "enable|disable") \ -_(lisp_add_del_remote_mapping, "add|del vni eid " \ - "[seid ] " \ - "rloc p " \ - "w [rloc ... ] " \ - "action [del-all]") \ -_(lisp_add_del_adjacency, "add|del vni reid leid " \ - "") \ -_(lisp_pitr_set_locator_set, "locator-set | del") \ -_(lisp_use_petr, " | disable") \ -_(lisp_map_request_mode, "src-dst|dst-only") \ -_(lisp_add_del_map_request_itr_rlocs, " [del]") \ -_(lisp_eid_table_add_del_map, "[del] vni vrf ") \ -_(lisp_locator_set_dump, "[local | remote]") \ -_(lisp_locator_dump, "ls_index | ls_name ") \ -_(lisp_eid_table_dump, "[eid / | ] [vni] " \ - "[local] | [remote]") \ -_(lisp_eid_table_vni_dump, "") \ -_(lisp_eid_table_map_dump, "l2|l3") \ -_(lisp_map_resolver_dump, "") \ -_(lisp_map_server_dump, "") \ -_(lisp_adjacencies_get, "vni ") \ -_(gpe_fwd_entry_vnis_get, "") \ -_(gpe_native_fwd_rpaths_get, "ip4 | ip6") \ -_(gpe_add_del_native_fwd_rpath, "[del] via [iface] " \ - "[table ]") \ -_(lisp_gpe_fwd_entries_get, "vni ") \ -_(lisp_gpe_fwd_entry_path_dump, "index ") \ -_(gpe_set_encap_mode, "lisp|vxlan") \ -_(gpe_get_encap_mode, "") \ -_(lisp_gpe_add_del_iface, "up|down") \ -_(lisp_gpe_enable_disable, "enable|disable") \ -_(lisp_gpe_add_del_fwd_entry, "reid [leid ] vni " \ - "vrf/bd loc-pair w ... [del]") \ -_(show_lisp_rloc_probe_state, "") \ -_(show_lisp_map_register_state, "") \ -_(show_lisp_status, "") \ -_(lisp_get_map_request_itr_rlocs, "") \ -_(show_lisp_pitr, "") \ -_(show_lisp_use_petr, "") \ -_(show_lisp_map_request_mode, "") \ _(af_packet_create, "name [hw_addr ]") \ _(af_packet_delete, "name ") \ _(af_packet_dump, "") \ diff --git a/src/vnet/CMakeLists.txt b/src/vnet/CMakeLists.txt index 124af13f202..4c65d71f3b2 100644 --- a/src/vnet/CMakeLists.txt +++ b/src/vnet/CMakeLists.txt @@ -817,64 +817,6 @@ list(APPEND VNET_HEADERS list(APPEND VNET_API_FILES vxlan-gpe/vxlan_gpe.api) -############################################################################## -# LISP control plane: lisp-cp -############################################################################## - -list(APPEND VNET_SOURCES - lisp-cp/lisp_types.c - lisp-cp/lisp_cp_dpo.c - lisp-cp/control.c - lisp-cp/gid_dictionary.c - lisp-cp/lisp_msg_serdes.c - lisp-cp/packets.c - lisp-cp/one_cli.c - lisp-cp/lisp_cli.c - lisp-cp/one_api.c - lisp-cp/lisp_api.c - lisp-cp/lisp_types_api.c -) - -list(APPEND VNET_HEADERS - lisp-cp/lisp_types.h - lisp-cp/packets.h - lisp-cp/gid_dictionary.h - lisp-cp/lisp_cp_messages.h - lisp-cp/lisp_msg_serdes.h - lisp-cp/control.h - lisp-cp/lisp_types_api.h -) - -list(APPEND VNET_API_FILES lisp-cp/lisp_types.api) -list(APPEND VNET_API_FILES lisp-cp/lisp.api) -list(APPEND VNET_API_FILES lisp-cp/one.api) - -############################################################################## -# Tunnel protocol: lisp-gpe -############################################################################## - -list(APPEND VNET_SOURCES - lisp-gpe/lisp_gpe.c - lisp-gpe/lisp_gpe_sub_interface.c - lisp-gpe/lisp_gpe_adjacency.c - lisp-gpe/lisp_gpe_tunnel.c - lisp-gpe/lisp_gpe_fwd_entry.c - lisp-gpe/lisp_gpe_tenant.c - lisp-gpe/interface.c - lisp-gpe/decap.c - lisp-gpe/lisp_gpe_api.c -) - -list(APPEND VNET_HEADERS - lisp-gpe/lisp_gpe.h - lisp-gpe/lisp_gpe_fwd_entry.h - lisp-gpe/lisp_gpe_tenant.h - lisp-gpe/lisp_gpe_packet.h - lisp-gpe/lisp_gpe_error.def -) - -list(APPEND VNET_API_FILES lisp-gpe/lisp_gpe.api) - ############################################################################## # ipv6 segment routing ############################################################################## diff --git a/src/vnet/lisp-cp/FEATURE.yaml b/src/vnet/lisp-cp/FEATURE.yaml deleted file mode 100644 index fb48e1fd232..00000000000 --- a/src/vnet/lisp-cp/FEATURE.yaml +++ /dev/null @@ -1,14 +0,0 @@ ---- -name: Locator ID Separation Protocol Control Plane -maintainer: Florin Coras -features: - - ITR, ETR and RTR mode of operation - - Multitenancy - - Multihoming - - Source/dest map-cache lookups - - RLOC-probing - - Support for Ethernet, IPv4, IPv6 and NSH EIDs (payloads) - - Map-resolver failover algorithm -description: "Locator ID Separation Protocol control plane (LISP) implementation" -state: production -properties: [API, CLI, STATS, MULTITHREAD] diff --git a/src/vnet/lisp-cp/control.c b/src/vnet/lisp-cp/control.c deleted file mode 100644 index 60d85619dc5..00000000000 --- a/src/vnet/lisp-cp/control.c +++ /dev/null @@ -1,5033 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#define MAX_VALUE_U24 0xffffff - -/* mapping timer control constants (in seconds) */ -#define TIME_UNTIL_REFETCH_OR_DELETE 20 -#define MAPPING_TIMEOUT (((m->ttl) * 60) - TIME_UNTIL_REFETCH_OR_DELETE) - -lisp_cp_main_t lisp_control_main; - -u8 *format_lisp_cp_input_trace (u8 * s, va_list * args); -static void *send_map_request_thread_fn (void *arg); - -typedef enum -{ - LISP_CP_INPUT_NEXT_DROP, - LISP_CP_INPUT_N_NEXT, -} lisp_cp_input_next_t; - -typedef struct -{ - u8 is_resend; - gid_address_t seid; - gid_address_t deid; - u8 smr_invoked; -} map_request_args_t; - -u8 -vnet_lisp_get_map_request_mode (void) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - return lcm->map_request_mode; -} - -static u16 -auth_data_len_by_key_id (lisp_key_type_t key_id) -{ - switch (key_id) - { - case HMAC_SHA_1_96: - return SHA1_AUTH_DATA_LEN; - case HMAC_SHA_256_128: - return SHA256_AUTH_DATA_LEN; - default: - clib_warning ("unsupported key type: %d!", key_id); - return (u16) ~ 0; - } - return (u16) ~ 0; -} - -static int -queue_map_request (gid_address_t * seid, gid_address_t * deid, - u8 smr_invoked, u8 is_resend); - -ip_interface_address_t * -ip_interface_get_first_interface_address (ip_lookup_main_t * lm, - u32 sw_if_index, u8 loop) -{ - vnet_main_t *vnm = vnet_get_main (); - vnet_sw_interface_t *swif = vnet_get_sw_interface (vnm, sw_if_index); - if (loop && swif->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED) - sw_if_index = swif->unnumbered_sw_if_index; - u32 ia = - (vec_len ((lm)->if_address_pool_index_by_sw_if_index) > (sw_if_index)) ? - vec_elt ((lm)->if_address_pool_index_by_sw_if_index, (sw_if_index)) : - (u32) ~ 0; - return pool_elt_at_index ((lm)->if_address_pool, ia); -} - -void * -ip_interface_get_first_address (ip_lookup_main_t * lm, u32 sw_if_index, - u8 version) -{ - ip_interface_address_t *ia; - - ia = ip_interface_get_first_interface_address (lm, sw_if_index, 1); - if (!ia) - return 0; - return ip_interface_address_get_address (lm, ia); -} - -int -ip_interface_get_first_ip_address (lisp_cp_main_t * lcm, u32 sw_if_index, - u8 version, ip_address_t * result) -{ - ip_lookup_main_t *lm; - void *addr; - - lm = (version == AF_IP4) ? &lcm->im4->lookup_main : &lcm->im6->lookup_main; - addr = ip_interface_get_first_address (lm, sw_if_index, version); - if (!addr) - return 0; - - ip_address_set (result, addr, version); - return 1; -} - -/** - * Find the sw_if_index of the interface that would be used to egress towards - * dst. - */ -u32 -ip_fib_get_egress_iface_for_dst (lisp_cp_main_t * lcm, ip_address_t * dst) -{ - fib_node_index_t fei; - fib_prefix_t prefix; - - ip_address_to_fib_prefix (dst, &prefix); - - fei = fib_table_lookup (0, &prefix); - - return (fib_entry_get_resolving_interface (fei)); -} - -/** - * Find first IP of the interface that would be used to egress towards dst. - * Returns 1 if the address is found 0 otherwise. - */ -int -ip_fib_get_first_egress_ip_for_dst (lisp_cp_main_t * lcm, ip_address_t * dst, - ip_address_t * result) -{ - u32 si; - ip_lookup_main_t *lm; - void *addr = 0; - u8 ipver; - - ASSERT (result != 0); - - ipver = ip_addr_version (dst); - - lm = (ipver == AF_IP4) ? &lcm->im4->lookup_main : &lcm->im6->lookup_main; - si = ip_fib_get_egress_iface_for_dst (lcm, dst); - - if ((u32) ~ 0 == si) - return 0; - - /* find the first ip address */ - addr = ip_interface_get_first_address (lm, si, ipver); - if (0 == addr) - return 0; - - ip_address_set (result, addr, ipver); - return 1; -} - -static int -dp_add_del_iface (lisp_cp_main_t * lcm, u32 vni, u8 is_l2, u8 is_add, - u8 with_default_route) -{ - uword *dp_table; - - if (!is_l2) - { - dp_table = hash_get (lcm->table_id_by_vni, vni); - - if (!dp_table) - { - clib_warning ("vni %d not associated to a vrf!", vni); - return VNET_API_ERROR_INVALID_VALUE; - } - } - else - { - dp_table = hash_get (lcm->bd_id_by_vni, vni); - if (!dp_table) - { - clib_warning ("vni %d not associated to a bridge domain!", vni); - return VNET_API_ERROR_INVALID_VALUE; - } - } - - /* enable/disable data-plane interface */ - if (is_add) - { - if (is_l2) - lisp_gpe_tenant_l2_iface_add_or_lock (vni, dp_table[0]); - else - lisp_gpe_tenant_l3_iface_add_or_lock (vni, dp_table[0], - with_default_route); - } - else - { - if (is_l2) - lisp_gpe_tenant_l2_iface_unlock (vni); - else - lisp_gpe_tenant_l3_iface_unlock (vni); - } - - return 0; -} - -static void -dp_del_fwd_entry (lisp_cp_main_t * lcm, u32 dst_map_index) -{ - vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a; - fwd_entry_t *fe = 0; - uword *feip = 0; - clib_memset (a, 0, sizeof (*a)); - - feip = hash_get (lcm->fwd_entry_by_mapping_index, dst_map_index); - if (!feip) - return; - - fe = pool_elt_at_index (lcm->fwd_entry_pool, feip[0]); - - /* delete dp fwd entry */ - u32 sw_if_index; - a->is_add = 0; - a->locator_pairs = fe->locator_pairs; - a->vni = gid_address_vni (&fe->reid); - gid_address_copy (&a->rmt_eid, &fe->reid); - if (fe->is_src_dst) - gid_address_copy (&a->lcl_eid, &fe->leid); - - vnet_lisp_gpe_del_fwd_counters (a, feip[0]); - vnet_lisp_gpe_add_del_fwd_entry (a, &sw_if_index); - - /* delete entry in fwd table */ - hash_unset (lcm->fwd_entry_by_mapping_index, dst_map_index); - vec_free (fe->locator_pairs); - pool_put (lcm->fwd_entry_pool, fe); -} - -/** - * Finds first remote locator with best (lowest) priority that has a local - * peer locator with an underlying route to it. - * - */ -static u32 -get_locator_pairs (lisp_cp_main_t * lcm, mapping_t * lcl_map, - mapping_t * rmt_map, locator_pair_t ** locator_pairs) -{ - u32 i, limitp = 0, li, found = 0, esi; - locator_set_t *rmt_ls, *lcl_ls; - ip_address_t _lcl_addr, *lcl_addr = &_lcl_addr; - locator_t *lp, *rmt = 0; - uword *checked = 0; - locator_pair_t pair; - - rmt_ls = - pool_elt_at_index (lcm->locator_set_pool, rmt_map->locator_set_index); - lcl_ls = - pool_elt_at_index (lcm->locator_set_pool, lcl_map->locator_set_index); - - if (!rmt_ls || vec_len (rmt_ls->locator_indices) == 0) - return 0; - - while (1) - { - rmt = 0; - - /* find unvisited remote locator with best priority */ - for (i = 0; i < vec_len (rmt_ls->locator_indices); i++) - { - if (0 != hash_get (checked, i)) - continue; - - li = vec_elt (rmt_ls->locator_indices, i); - lp = pool_elt_at_index (lcm->locator_pool, li); - - /* we don't support non-IP locators for now */ - if (gid_address_type (&lp->address) != GID_ADDR_IP_PREFIX) - continue; - - if ((found && lp->priority == limitp) - || (!found && lp->priority >= limitp)) - { - rmt = lp; - - /* don't search for locators with lower priority and don't - * check this locator again*/ - limitp = lp->priority; - hash_set (checked, i, 1); - break; - } - } - /* check if a local locator with a route to remote locator exists */ - if (rmt != 0) - { - /* find egress sw_if_index for rmt locator */ - esi = - ip_fib_get_egress_iface_for_dst (lcm, - &gid_address_ip (&rmt->address)); - if ((u32) ~ 0 == esi) - continue; - - for (i = 0; i < vec_len (lcl_ls->locator_indices); i++) - { - li = vec_elt (lcl_ls->locator_indices, i); - locator_t *sl = pool_elt_at_index (lcm->locator_pool, li); - - /* found local locator with the needed sw_if_index */ - if (sl->sw_if_index == esi) - { - /* and it has an address */ - if (0 == ip_interface_get_first_ip_address (lcm, - sl->sw_if_index, - gid_address_ip_version - (&rmt->address), - lcl_addr)) - continue; - - clib_memset (&pair, 0, sizeof (pair)); - ip_address_copy (&pair.rmt_loc, - &gid_address_ip (&rmt->address)); - ip_address_copy (&pair.lcl_loc, lcl_addr); - pair.weight = rmt->weight; - pair.priority = rmt->priority; - vec_add1 (locator_pairs[0], pair); - found = 1; - } - } - } - else - break; - } - - hash_free (checked); - return found; -} - -static void -gid_address_sd_to_flat (gid_address_t * dst, gid_address_t * src, - fid_address_t * fid) -{ - ASSERT (GID_ADDR_SRC_DST == gid_address_type (src)); - - dst[0] = src[0]; - - switch (fid_addr_type (fid)) - { - case FID_ADDR_IP_PREF: - gid_address_type (dst) = GID_ADDR_IP_PREFIX; - gid_address_ippref (dst) = fid_addr_ippref (fid); - break; - case FID_ADDR_MAC: - gid_address_type (dst) = GID_ADDR_MAC; - mac_copy (gid_address_mac (dst), fid_addr_mac (fid)); - break; - default: - clib_warning ("Unsupported fid type %d!", fid_addr_type (fid)); - break; - } -} - -u8 -vnet_lisp_map_register_state_get (void) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - return lcm->map_registering; -} - -u8 -vnet_lisp_rloc_probe_state_get (void) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - return lcm->rloc_probing; -} - -static void -dp_add_fwd_entry (lisp_cp_main_t * lcm, u32 src_map_index, u32 dst_map_index) -{ - vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a; - gid_address_t *rmt_eid, *lcl_eid; - mapping_t *lcl_map, *rmt_map; - u32 sw_if_index, **rmts, rmts_idx; - uword *feip = 0, *dpid, *rmts_stored_idxp = 0; - fwd_entry_t *fe; - u8 type, is_src_dst = 0; - int rv; - - clib_memset (a, 0, sizeof (*a)); - - /* remove entry if it already exists */ - feip = hash_get (lcm->fwd_entry_by_mapping_index, dst_map_index); - if (feip) - dp_del_fwd_entry (lcm, dst_map_index); - - /* - * Determine local mapping and eid - */ - if (lcm->flags & LISP_FLAG_PITR_MODE) - { - if (lcm->pitr_map_index != ~0) - lcl_map = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index); - else - { - clib_warning ("no PITR mapping configured!"); - return; - } - } - else - lcl_map = pool_elt_at_index (lcm->mapping_pool, src_map_index); - lcl_eid = &lcl_map->eid; - - /* - * Determine remote mapping and eid - */ - rmt_map = pool_elt_at_index (lcm->mapping_pool, dst_map_index); - rmt_eid = &rmt_map->eid; - - /* - * Build and insert data plane forwarding entry - */ - a->is_add = 1; - - if (MR_MODE_SRC_DST == lcm->map_request_mode) - { - if (GID_ADDR_SRC_DST == gid_address_type (rmt_eid)) - { - gid_address_sd_to_flat (&a->rmt_eid, rmt_eid, - &gid_address_sd_dst (rmt_eid)); - gid_address_sd_to_flat (&a->lcl_eid, rmt_eid, - &gid_address_sd_src (rmt_eid)); - } - else - { - gid_address_copy (&a->rmt_eid, rmt_eid); - gid_address_copy (&a->lcl_eid, lcl_eid); - } - is_src_dst = 1; - } - else - gid_address_copy (&a->rmt_eid, rmt_eid); - - a->vni = gid_address_vni (&a->rmt_eid); - a->is_src_dst = is_src_dst; - - /* get vrf or bd_index associated to vni */ - type = gid_address_type (&a->rmt_eid); - if (GID_ADDR_IP_PREFIX == type) - { - dpid = hash_get (lcm->table_id_by_vni, a->vni); - if (!dpid) - { - clib_warning ("vni %d not associated to a vrf!", a->vni); - return; - } - a->table_id = dpid[0]; - } - else if (GID_ADDR_MAC == type) - { - dpid = hash_get (lcm->bd_id_by_vni, a->vni); - if (!dpid) - { - clib_warning ("vni %d not associated to a bridge domain !", a->vni); - return; - } - a->bd_id = dpid[0]; - } - - /* find best locator pair that 1) verifies LISP policy 2) are connected */ - rv = get_locator_pairs (lcm, lcl_map, rmt_map, &a->locator_pairs); - - /* Either rmt mapping is negative or we can't find underlay path. - * Try again with petr if configured */ - if (rv == 0 && (lcm->flags & LISP_FLAG_USE_PETR)) - { - rmt_map = lisp_get_petr_mapping (lcm); - rv = get_locator_pairs (lcm, lcl_map, rmt_map, &a->locator_pairs); - } - - /* negative entry */ - if (rv == 0) - { - a->is_negative = 1; - a->action = rmt_map->action; - } - - rv = vnet_lisp_gpe_add_del_fwd_entry (a, &sw_if_index); - if (rv) - { - if (a->locator_pairs) - vec_free (a->locator_pairs); - return; - } - - /* add tunnel to fwd entry table */ - pool_get (lcm->fwd_entry_pool, fe); - vnet_lisp_gpe_add_fwd_counters (a, fe - lcm->fwd_entry_pool); - - fe->locator_pairs = a->locator_pairs; - gid_address_copy (&fe->reid, &a->rmt_eid); - - if (is_src_dst) - gid_address_copy (&fe->leid, &a->lcl_eid); - else - gid_address_copy (&fe->leid, lcl_eid); - - fe->is_src_dst = is_src_dst; - hash_set (lcm->fwd_entry_by_mapping_index, dst_map_index, - fe - lcm->fwd_entry_pool); - - /* Add rmt mapping to the vector of adjacent mappings to lcl mapping */ - rmts_stored_idxp = - hash_get (lcm->lcl_to_rmt_adjs_by_lcl_idx, src_map_index); - if (!rmts_stored_idxp) - { - pool_get (lcm->lcl_to_rmt_adjacencies, rmts); - clib_memset (rmts, 0, sizeof (*rmts)); - rmts_idx = rmts - lcm->lcl_to_rmt_adjacencies; - hash_set (lcm->lcl_to_rmt_adjs_by_lcl_idx, src_map_index, rmts_idx); - } - else - { - rmts_idx = (u32) (*rmts_stored_idxp); - rmts = pool_elt_at_index (lcm->lcl_to_rmt_adjacencies, rmts_idx); - } - vec_add1 (rmts[0], dst_map_index); -} - -typedef struct -{ - u32 si; - u32 di; -} fwd_entry_mt_arg_t; - -static void * -dp_add_fwd_entry_thread_fn (void *arg) -{ - fwd_entry_mt_arg_t *a = arg; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - dp_add_fwd_entry (lcm, a->si, a->di); - return 0; -} - -static int -dp_add_fwd_entry_from_mt (u32 si, u32 di) -{ - fwd_entry_mt_arg_t a; - - clib_memset (&a, 0, sizeof (a)); - a.si = si; - a.di = di; - - vl_api_rpc_call_main_thread (dp_add_fwd_entry_thread_fn, - (u8 *) & a, sizeof (a)); - return 0; -} - -/** - * Returns vector of adjacencies. - * - * The caller must free the vector returned by this function. - * - * @param vni virtual network identifier - * @return vector of adjacencies - */ -lisp_adjacency_t * -vnet_lisp_adjacencies_get_by_vni (u32 vni) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - fwd_entry_t *fwd; - lisp_adjacency_t *adjs = 0, adj; - - /* *INDENT-OFF* */ - pool_foreach(fwd, lcm->fwd_entry_pool, - ({ - if (gid_address_vni (&fwd->reid) != vni) - continue; - - gid_address_copy (&adj.reid, &fwd->reid); - gid_address_copy (&adj.leid, &fwd->leid); - vec_add1 (adjs, adj); - })); - /* *INDENT-ON* */ - - return adjs; -} - -static lisp_msmr_t * -get_map_server (ip_address_t * a) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - lisp_msmr_t *m; - - vec_foreach (m, lcm->map_servers) - { - if (!ip_address_cmp (&m->address, a)) - { - return m; - } - } - return 0; -} - -static lisp_msmr_t * -get_map_resolver (ip_address_t * a) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - lisp_msmr_t *m; - - vec_foreach (m, lcm->map_resolvers) - { - if (!ip_address_cmp (&m->address, a)) - { - return m; - } - } - return 0; -} - -int -vnet_lisp_add_del_map_server (ip_address_t * addr, u8 is_add) -{ - u32 i; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - lisp_msmr_t _ms, *ms = &_ms; - - if (vnet_lisp_enable_disable_status () == 0) - { - clib_warning ("LISP is disabled!"); - return VNET_API_ERROR_LISP_DISABLED; - } - - if (is_add) - { - if (get_map_server (addr)) - { - clib_warning ("map-server %U already exists!", format_ip_address, - addr); - return -1; - } - - clib_memset (ms, 0, sizeof (*ms)); - ip_address_copy (&ms->address, addr); - vec_add1 (lcm->map_servers, ms[0]); - - if (vec_len (lcm->map_servers) == 1) - lcm->do_map_server_election = 1; - } - else - { - for (i = 0; i < vec_len (lcm->map_servers); i++) - { - ms = vec_elt_at_index (lcm->map_servers, i); - if (!ip_address_cmp (&ms->address, addr)) - { - if (!ip_address_cmp (&ms->address, &lcm->active_map_server)) - lcm->do_map_server_election = 1; - - vec_del1 (lcm->map_servers, i); - break; - } - } - } - - return 0; -} - -/** - * Add/remove mapping to/from map-cache. Overwriting not allowed. - */ -int -vnet_lisp_map_cache_add_del (vnet_lisp_add_del_mapping_args_t * a, - u32 * map_index_result) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - u32 mi, *map_indexp, map_index, i; - u32 **rmts = 0, *remote_idxp, rmts_itr, remote_idx; - uword *rmts_idxp; - mapping_t *m, *old_map; - u32 **eid_indexes; - - if (gid_address_type (&a->eid) == GID_ADDR_NSH) - { - if (gid_address_vni (&a->eid) != 0) - { - clib_warning ("Supported only default VNI for NSH!"); - return VNET_API_ERROR_INVALID_ARGUMENT; - } - if (gid_address_nsh_spi (&a->eid) > MAX_VALUE_U24) - { - clib_warning ("SPI is greater than 24bit!"); - return VNET_API_ERROR_INVALID_ARGUMENT; - } - } - - mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &a->eid); - old_map = mi != ~0 ? pool_elt_at_index (lcm->mapping_pool, mi) : 0; - if (a->is_add) - { - /* TODO check if overwriting and take appropriate actions */ - if (mi != GID_LOOKUP_MISS && !gid_address_cmp (&old_map->eid, &a->eid)) - { - clib_warning ("eid %U found in the eid-table", format_gid_address, - &a->eid); - return VNET_API_ERROR_VALUE_EXIST; - } - - pool_get (lcm->mapping_pool, m); - gid_address_copy (&m->eid, &a->eid); - m->locator_set_index = a->locator_set_index; - m->ttl = a->ttl; - m->action = a->action; - m->local = a->local; - m->is_static = a->is_static; - m->key = vec_dup (a->key); - m->key_id = a->key_id; - m->authoritative = a->authoritative; - - map_index = m - lcm->mapping_pool; - gid_dictionary_add_del (&lcm->mapping_index_by_gid, &a->eid, map_index, - 1); - - if (pool_is_free_index (lcm->locator_set_pool, a->locator_set_index)) - { - clib_warning ("Locator set with index %d doesn't exist", - a->locator_set_index); - return VNET_API_ERROR_INVALID_VALUE; - } - - /* add eid to list of eids supported by locator-set */ - vec_validate (lcm->locator_set_to_eids, a->locator_set_index); - eid_indexes = vec_elt_at_index (lcm->locator_set_to_eids, - a->locator_set_index); - vec_add1 (eid_indexes[0], map_index); - - if (a->local) - { - /* mark as local */ - vec_add1 (lcm->local_mappings_indexes, map_index); - } - map_index_result[0] = map_index; - } - else - { - if (mi == GID_LOOKUP_MISS) - { - clib_warning ("eid %U not found in the eid-table", - format_gid_address, &a->eid); - return VNET_API_ERROR_INVALID_VALUE; - } - - /* clear locator-set to eids binding */ - eid_indexes = vec_elt_at_index (lcm->locator_set_to_eids, - a->locator_set_index); - for (i = 0; i < vec_len (eid_indexes[0]); i++) - { - map_indexp = vec_elt_at_index (eid_indexes[0], i); - if (map_indexp[0] == mi) - break; - } - vec_del1 (eid_indexes[0], i); - - /* remove local mark if needed */ - m = pool_elt_at_index (lcm->mapping_pool, mi); - if (m->local) - { - /* Remove adjacencies associated with the local mapping */ - rmts_idxp = hash_get (lcm->lcl_to_rmt_adjs_by_lcl_idx, mi); - if (rmts_idxp) - { - rmts = - pool_elt_at_index (lcm->lcl_to_rmt_adjacencies, rmts_idxp[0]); - vec_foreach (remote_idxp, rmts[0]) - { - dp_del_fwd_entry (lcm, remote_idxp[0]); - } - vec_free (rmts[0]); - pool_put (lcm->lcl_to_rmt_adjacencies, rmts); - hash_unset (lcm->lcl_to_rmt_adjs_by_lcl_idx, mi); - } - - u32 k, *lm_indexp; - for (k = 0; k < vec_len (lcm->local_mappings_indexes); k++) - { - lm_indexp = vec_elt_at_index (lcm->local_mappings_indexes, k); - if (lm_indexp[0] == mi) - break; - } - vec_del1 (lcm->local_mappings_indexes, k); - } - else - { - /* Remove remote (if present) from the vectors of lcl-to-rmts - * TODO: Address this in a more efficient way. - */ - /* *INDENT-OFF* */ - pool_foreach (rmts, lcm->lcl_to_rmt_adjacencies, - ({ - vec_foreach_index (rmts_itr, rmts[0]) - { - remote_idx = vec_elt (rmts[0], rmts_itr); - if (mi == remote_idx) - { - vec_del1 (rmts[0], rmts_itr); - break; - } - } - })); - /* *INDENT-ON* */ - } - - /* remove mapping from dictionary */ - gid_dictionary_add_del (&lcm->mapping_index_by_gid, &a->eid, 0, 0); - gid_address_free (&m->eid); - pool_put_index (lcm->mapping_pool, mi); - } - - return 0; -} - -/** - * Add/update/delete mapping to/in/from map-cache. - */ -int -vnet_lisp_add_del_local_mapping (vnet_lisp_add_del_mapping_args_t * a, - u32 * map_index_result) -{ - uword *dp_table = 0; - u32 vni; - u8 type; - - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - - if (vnet_lisp_enable_disable_status () == 0) - { - clib_warning ("LISP is disabled!"); - return VNET_API_ERROR_LISP_DISABLED; - } - - vni = gid_address_vni (&a->eid); - type = gid_address_type (&a->eid); - if (GID_ADDR_IP_PREFIX == type) - dp_table = hash_get (lcm->table_id_by_vni, vni); - else if (GID_ADDR_MAC == type) - dp_table = hash_get (lcm->bd_id_by_vni, vni); - - if (!dp_table && GID_ADDR_NSH != type) - { - clib_warning ("vni %d not associated to a %s!", vni, - GID_ADDR_IP_PREFIX == type ? "vrf" : "bd"); - return VNET_API_ERROR_INVALID_VALUE; - } - - /* store/remove mapping from map-cache */ - return vnet_lisp_map_cache_add_del (a, map_index_result); -} - -static int -add_l2_arp_bd (BVT (clib_bihash_kv) * kvp, void *arg) -{ - u32 **ht = arg; - u32 version = (u32) kvp->key[0]; - if (AF_IP6 == version) - return (BIHASH_WALK_CONTINUE); - - u32 bd = (u32) (kvp->key[0] >> 32); - hash_set (ht[0], bd, 0); - return (BIHASH_WALK_CONTINUE); -} - -u32 * -vnet_lisp_l2_arp_bds_get (void) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - u32 *bds = 0; - - gid_dict_foreach_l2_arp_ndp_entry (&lcm->mapping_index_by_gid, - add_l2_arp_bd, &bds); - return bds; -} - -static int -add_ndp_bd (BVT (clib_bihash_kv) * kvp, void *arg) -{ - u32 **ht = arg; - u32 version = (u32) kvp->key[0]; - if (AF_IP4 == version) - return (BIHASH_WALK_CONTINUE); - - u32 bd = (u32) (kvp->key[0] >> 32); - hash_set (ht[0], bd, 0); - return (BIHASH_WALK_CONTINUE); -} - -u32 * -vnet_lisp_ndp_bds_get (void) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - u32 *bds = 0; - - gid_dict_foreach_l2_arp_ndp_entry (&lcm->mapping_index_by_gid, - add_ndp_bd, &bds); - return bds; -} - -typedef struct -{ - void *vector; - u32 bd; -} lisp_add_l2_arp_ndp_args_t; - -static int -add_l2_arp_entry (BVT (clib_bihash_kv) * kvp, void *arg) -{ - lisp_add_l2_arp_ndp_args_t *a = arg; - lisp_api_l2_arp_entry_t **vector = a->vector, e; - - u32 version = (u32) kvp->key[0]; - if (AF_IP6 == version) - return (BIHASH_WALK_CONTINUE); - - u32 bd = (u32) (kvp->key[0] >> 32); - - if (bd == a->bd) - { - mac_copy (e.mac, (void *) &kvp->value); - e.ip4 = (u32) kvp->key[1]; - vec_add1 (vector[0], e); - } - return (BIHASH_WALK_CONTINUE); -} - -lisp_api_l2_arp_entry_t * -vnet_lisp_l2_arp_entries_get_by_bd (u32 bd) -{ - lisp_api_l2_arp_entry_t *entries = 0; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - lisp_add_l2_arp_ndp_args_t a; - - a.vector = &entries; - a.bd = bd; - - gid_dict_foreach_l2_arp_ndp_entry (&lcm->mapping_index_by_gid, - add_l2_arp_entry, &a); - return entries; -} - -static int -add_ndp_entry (BVT (clib_bihash_kv) * kvp, void *arg) -{ - lisp_add_l2_arp_ndp_args_t *a = arg; - lisp_api_ndp_entry_t **vector = a->vector, e; - - u32 version = (u32) kvp->key[0]; - if (AF_IP4 == version) - return (BIHASH_WALK_CONTINUE); - - u32 bd = (u32) (kvp->key[0] >> 32); - - if (bd == a->bd) - { - mac_copy (e.mac, (void *) &kvp->value); - clib_memcpy (e.ip6, &kvp->key[1], 16); - vec_add1 (vector[0], e); - } - return (BIHASH_WALK_CONTINUE); -} - -lisp_api_ndp_entry_t * -vnet_lisp_ndp_entries_get_by_bd (u32 bd) -{ - lisp_api_ndp_entry_t *entries = 0; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - lisp_add_l2_arp_ndp_args_t a; - - a.vector = &entries; - a.bd = bd; - - gid_dict_foreach_l2_arp_ndp_entry (&lcm->mapping_index_by_gid, - add_ndp_entry, &a); - return entries; -} - -int -vnet_lisp_add_del_l2_arp_ndp_entry (gid_address_t * key, u8 * mac, u8 is_add) -{ - if (vnet_lisp_enable_disable_status () == 0) - { - clib_warning ("LISP is disabled!"); - return VNET_API_ERROR_LISP_DISABLED; - } - - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - int rc = 0; - - u64 res = gid_dictionary_lookup (&lcm->mapping_index_by_gid, key); - if (is_add) - { - if (res != GID_LOOKUP_MISS_L2) - { - clib_warning ("Entry %U exists in DB!", format_gid_address, key); - return VNET_API_ERROR_ENTRY_ALREADY_EXISTS; - } - u64 val = mac_to_u64 (mac); - gid_dictionary_add_del (&lcm->mapping_index_by_gid, key, val, - 1 /* is_add */ ); - } - else - { - if (res == GID_LOOKUP_MISS_L2) - { - clib_warning ("ONE entry %U not found - cannot delete!", - format_gid_address, key); - return -1; - } - gid_dictionary_add_del (&lcm->mapping_index_by_gid, key, 0, - 0 /* is_add */ ); - } - - return rc; -} - -int -vnet_lisp_eid_table_map (u32 vni, u32 dp_id, u8 is_l2, u8 is_add) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - uword *dp_idp, *vnip, **dp_table_by_vni, **vni_by_dp_table; - - if (vnet_lisp_enable_disable_status () == 0) - { - clib_warning ("LISP is disabled!"); - return VNET_API_ERROR_LISP_DISABLED; - } - - dp_table_by_vni = is_l2 ? &lcm->bd_id_by_vni : &lcm->table_id_by_vni; - vni_by_dp_table = is_l2 ? &lcm->vni_by_bd_id : &lcm->vni_by_table_id; - - if (!is_l2 && (vni == 0 || dp_id == 0)) - { - clib_warning ("can't add/del default vni-vrf mapping!"); - return -1; - } - - dp_idp = hash_get (dp_table_by_vni[0], vni); - vnip = hash_get (vni_by_dp_table[0], dp_id); - - if (is_add) - { - if (dp_idp || vnip) - { - clib_warning ("vni %d or vrf %d already used in vrf/vni " - "mapping!", vni, dp_id); - return -1; - } - hash_set (dp_table_by_vni[0], vni, dp_id); - hash_set (vni_by_dp_table[0], dp_id, vni); - - /* create dp iface */ - dp_add_del_iface (lcm, vni, is_l2, 1 /* is_add */ , - 1 /* with_default_route */ ); - } - else - { - if (!dp_idp || !vnip) - { - clib_warning ("vni %d or vrf %d not used in any vrf/vni! " - "mapping!", vni, dp_id); - return -1; - } - /* remove dp iface */ - dp_add_del_iface (lcm, vni, is_l2, 0 /* is_add */ , 0 /* unused */ ); - - hash_unset (dp_table_by_vni[0], vni); - hash_unset (vni_by_dp_table[0], dp_id); - } - return 0; - -} - -/* return 0 if the two locator sets are identical 1 otherwise */ -static u8 -compare_locators (lisp_cp_main_t * lcm, u32 * old_ls_indexes, - locator_t * new_locators) -{ - u32 i, old_li; - locator_t *old_loc, *new_loc; - - if (vec_len (old_ls_indexes) != vec_len (new_locators)) - return 1; - - for (i = 0; i < vec_len (new_locators); i++) - { - old_li = vec_elt (old_ls_indexes, i); - old_loc = pool_elt_at_index (lcm->locator_pool, old_li); - - new_loc = vec_elt_at_index (new_locators, i); - - if (locator_cmp (old_loc, new_loc)) - return 1; - } - return 0; -} - -typedef struct -{ - u8 is_negative; - void *lcm; - gid_address_t *eids_to_be_deleted; -} remove_mapping_args_t; - -/** - * Callback invoked when a sub-prefix is found - */ -static void -remove_mapping_if_needed (u32 mi, void *arg) -{ - u8 delete = 0; - remove_mapping_args_t *a = arg; - lisp_cp_main_t *lcm = a->lcm; - mapping_t *m; - locator_set_t *ls; - - m = pool_elt_at_index (lcm->mapping_pool, mi); - if (!m) - return; - - ls = pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index); - - if (a->is_negative) - { - if (0 != vec_len (ls->locator_indices)) - delete = 1; - } - else - { - if (0 == vec_len (ls->locator_indices)) - delete = 1; - } - - if (delete) - vec_add1 (a->eids_to_be_deleted, m->eid); -} - -/** - * This function searches map cache and looks for IP prefixes that are subset - * of the provided one. If such prefix is found depending on 'is_negative' - * it does follows: - * - * 1) if is_negative is true and found prefix points to positive mapping, - * then the mapping is removed - * 2) if is_negative is false and found prefix points to negative mapping, - * then the mapping is removed - */ -static void -remove_overlapping_sub_prefixes (lisp_cp_main_t * lcm, gid_address_t * eid, - u8 is_negative) -{ - gid_address_t *e; - remove_mapping_args_t a; - - clib_memset (&a, 0, sizeof (a)); - - /* do this only in src/dst mode ... */ - if (MR_MODE_SRC_DST != lcm->map_request_mode) - return; - - /* ... and only for IP prefix */ - if (GID_ADDR_SRC_DST != gid_address_type (eid) - || (FID_ADDR_IP_PREF != gid_address_sd_dst_type (eid))) - return; - - a.is_negative = is_negative; - a.lcm = lcm; - - gid_dict_foreach_subprefix (&lcm->mapping_index_by_gid, eid, - remove_mapping_if_needed, &a); - - vec_foreach (e, a.eids_to_be_deleted) - { - vnet_lisp_add_del_adjacency_args_t _adj_args, *adj_args = &_adj_args; - - clib_memset (adj_args, 0, sizeof (adj_args[0])); - gid_address_copy (&adj_args->reid, e); - adj_args->is_add = 0; - if (vnet_lisp_add_del_adjacency (adj_args)) - clib_warning ("failed to del adjacency!"); - - vnet_lisp_del_mapping (e, NULL); - } - - vec_free (a.eids_to_be_deleted); -} - -static int -is_local_ip (lisp_cp_main_t * lcm, ip_address_t * addr) -{ - fib_node_index_t fei; - fib_prefix_t prefix; - fib_entry_flag_t flags; - - ip_address_to_fib_prefix (addr, &prefix); - - fei = fib_table_lookup (0, &prefix); - flags = fib_entry_get_flags (fei); - return (FIB_ENTRY_FLAG_LOCAL & flags); -} - -/** - * Adds/updates mapping. Does not program forwarding. - * - * @param a parameters of the new mapping - * @param rlocs vector of remote locators - * @param res_map_index index of the newly created mapping - * @param locators_changed indicator if locators were updated in the mapping - * @return return code - */ -int -vnet_lisp_add_mapping (vnet_lisp_add_del_mapping_args_t * a, - locator_t * rlocs, - u32 * res_map_index, u8 * is_updated) -{ - vnet_lisp_add_del_locator_set_args_t _ls_args, *ls_args = &_ls_args; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - u32 mi, ls_index = 0, dst_map_index; - mapping_t *old_map; - locator_t *loc; - - if (vnet_lisp_enable_disable_status () == 0) - { - clib_warning ("LISP is disabled!"); - return VNET_API_ERROR_LISP_DISABLED; - } - - if (res_map_index) - res_map_index[0] = ~0; - if (is_updated) - is_updated[0] = 0; - - clib_memset (ls_args, 0, sizeof (ls_args[0])); - - ls_args->locators = rlocs; - mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &a->eid); - old_map = ((u32) ~ 0 != mi) ? pool_elt_at_index (lcm->mapping_pool, mi) : 0; - - /* check if none of the locators match locally configured address */ - vec_foreach (loc, rlocs) - { - ip_prefix_t *p = &gid_address_ippref (&loc->address); - if (is_local_ip (lcm, &ip_prefix_addr (p))) - { - clib_warning ("RLOC %U matches a local address!", - format_gid_address, &loc->address); - return VNET_API_ERROR_LISP_RLOC_LOCAL; - } - } - - /* overwrite: if mapping already exists, decide if locators should be - * updated and be done */ - if (old_map && gid_address_cmp (&old_map->eid, &a->eid) == 0) - { - if (!a->is_static && (old_map->is_static || old_map->local)) - { - /* do not overwrite local or static remote mappings */ - clib_warning ("mapping %U rejected due to collision with local " - "or static remote mapping!", format_gid_address, - &a->eid); - return 0; - } - - locator_set_t *old_ls; - - /* update mapping attributes */ - old_map->action = a->action; - if (old_map->action != a->action && NULL != is_updated) - is_updated[0] = 1; - - old_map->authoritative = a->authoritative; - old_map->ttl = a->ttl; - - old_ls = pool_elt_at_index (lcm->locator_set_pool, - old_map->locator_set_index); - if (compare_locators (lcm, old_ls->locator_indices, ls_args->locators)) - { - /* set locator-set index to overwrite */ - ls_args->is_add = 1; - ls_args->index = old_map->locator_set_index; - vnet_lisp_add_del_locator_set (ls_args, 0); - if (is_updated) - is_updated[0] = 1; - } - if (res_map_index) - res_map_index[0] = mi; - } - /* new mapping */ - else - { - if (is_updated) - is_updated[0] = 1; - remove_overlapping_sub_prefixes (lcm, &a->eid, 0 == ls_args->locators); - - ls_args->is_add = 1; - ls_args->index = ~0; - - vnet_lisp_add_del_locator_set (ls_args, &ls_index); - - /* add mapping */ - a->is_add = 1; - a->locator_set_index = ls_index; - vnet_lisp_map_cache_add_del (a, &dst_map_index); - - if (res_map_index) - res_map_index[0] = dst_map_index; - } - - /* success */ - return 0; -} - -/** - * Removes a mapping. Does not program forwarding. - * - * @param eid end-host identifier - * @param res_map_index index of the removed mapping - * @return return code - */ -int -vnet_lisp_del_mapping (gid_address_t * eid, u32 * res_map_index) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - vnet_lisp_add_del_mapping_args_t _m_args, *m_args = &_m_args; - vnet_lisp_add_del_locator_set_args_t _ls_args, *ls_args = &_ls_args; - mapping_t *old_map; - u32 mi; - - clib_memset (ls_args, 0, sizeof (ls_args[0])); - clib_memset (m_args, 0, sizeof (m_args[0])); - if (res_map_index) - res_map_index[0] = ~0; - - mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid); - old_map = ((u32) ~ 0 != mi) ? pool_elt_at_index (lcm->mapping_pool, mi) : 0; - - if (old_map == 0 || gid_address_cmp (&old_map->eid, eid) != 0) - { - clib_warning ("cannot delete mapping for eid %U", - format_gid_address, eid); - return -1; - } - - m_args->is_add = 0; - gid_address_copy (&m_args->eid, eid); - m_args->locator_set_index = old_map->locator_set_index; - - ls_args->is_add = 0; - ls_args->index = old_map->locator_set_index; - - /* delete timer associated to the mapping if any */ - if (old_map->timer_set) - TW (tw_timer_stop) (&lcm->wheel, old_map->timer_handle); - - /* delete locator set */ - vnet_lisp_add_del_locator_set (ls_args, 0); - - /* delete mapping associated from map-cache */ - vnet_lisp_map_cache_add_del (m_args, 0); - - /* return old mapping index */ - if (res_map_index) - res_map_index[0] = mi; - - /* success */ - return 0; -} - -int -vnet_lisp_clear_all_remote_adjacencies (void) -{ - int rv = 0; - u32 mi, *map_indices = 0, *map_indexp; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - vnet_lisp_add_del_mapping_args_t _dm_args, *dm_args = &_dm_args; - vnet_lisp_add_del_locator_set_args_t _ls, *ls = &_ls; - - /* *INDENT-OFF* */ - pool_foreach_index (mi, lcm->mapping_pool, - ({ - vec_add1 (map_indices, mi); - })); - /* *INDENT-ON* */ - - vec_foreach (map_indexp, map_indices) - { - mapping_t *map = pool_elt_at_index (lcm->mapping_pool, map_indexp[0]); - if (!map->local) - { - dp_del_fwd_entry (lcm, map_indexp[0]); - - dm_args->is_add = 0; - gid_address_copy (&dm_args->eid, &map->eid); - dm_args->locator_set_index = map->locator_set_index; - - /* delete mapping associated to fwd entry */ - vnet_lisp_map_cache_add_del (dm_args, 0); - - ls->is_add = 0; - ls->local = 0; - ls->index = map->locator_set_index; - /* delete locator set */ - rv = vnet_lisp_add_del_locator_set (ls, 0); - if (rv != 0) - goto cleanup; - } - } - -cleanup: - if (map_indices) - vec_free (map_indices); - return rv; -} - -/** - * Adds adjacency or removes forwarding entry associated to remote mapping. - * Note that adjacencies are not stored, they only result in forwarding entries - * being created. - */ -int -vnet_lisp_add_del_adjacency (vnet_lisp_add_del_adjacency_args_t * a) -{ - lisp_cp_main_t *lcm = &lisp_control_main; - u32 local_mi, remote_mi = ~0; - - if (vnet_lisp_enable_disable_status () == 0) - { - clib_warning ("LISP is disabled!"); - return VNET_API_ERROR_LISP_DISABLED; - } - - remote_mi = gid_dictionary_sd_lookup (&lcm->mapping_index_by_gid, - &a->reid, &a->leid); - if (GID_LOOKUP_MISS == remote_mi) - { - clib_warning ("Remote eid %U not found. Cannot add adjacency!", - format_gid_address, &a->reid); - - return -1; - } - - if (a->is_add) - { - /* check if source eid has an associated mapping. If pitr mode is on, - * just use the pitr's mapping */ - if (lcm->flags & LISP_FLAG_PITR_MODE) - { - if (lcm->pitr_map_index != ~0) - { - local_mi = lcm->pitr_map_index; - } - else - { - /* PITR mode is on, but no mapping is configured */ - return -1; - } - } - else - { - if (gid_address_type (&a->reid) == GID_ADDR_NSH) - { - if (lcm->nsh_map_index == ~0) - local_mi = GID_LOOKUP_MISS; - else - local_mi = lcm->nsh_map_index; - } - else - { - local_mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, - &a->leid); - } - } - - if (GID_LOOKUP_MISS == local_mi) - { - clib_warning ("Local eid %U not found. Cannot add adjacency!", - format_gid_address, &a->leid); - - return -1; - } - - /* update forwarding */ - dp_add_fwd_entry (lcm, local_mi, remote_mi); - } - else - dp_del_fwd_entry (lcm, remote_mi); - - return 0; -} - -int -vnet_lisp_set_map_request_mode (u8 mode) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - - if (vnet_lisp_enable_disable_status () == 0) - { - clib_warning ("LISP is disabled!"); - return VNET_API_ERROR_LISP_DISABLED; - } - - if (mode >= _MR_MODE_MAX) - { - clib_warning ("Invalid LISP map request mode %d!", mode); - return VNET_API_ERROR_INVALID_ARGUMENT; - } - - lcm->map_request_mode = mode; - return 0; -} - -int -vnet_lisp_nsh_set_locator_set (u8 * locator_set_name, u8 is_add) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main (); - u32 locator_set_index = ~0; - mapping_t *m; - uword *p; - - if (vnet_lisp_enable_disable_status () == 0) - { - clib_warning ("LISP is disabled!"); - return VNET_API_ERROR_LISP_DISABLED; - } - - if (is_add) - { - if (lcm->nsh_map_index == (u32) ~ 0) - { - p = hash_get_mem (lcm->locator_set_index_by_name, locator_set_name); - if (!p) - { - clib_warning ("locator-set %v doesn't exist", locator_set_name); - return -1; - } - locator_set_index = p[0]; - - pool_get (lcm->mapping_pool, m); - clib_memset (m, 0, sizeof *m); - m->locator_set_index = locator_set_index; - m->local = 1; - m->nsh_set = 1; - lcm->nsh_map_index = m - lcm->mapping_pool; - - if (~0 == vnet_lisp_gpe_add_nsh_iface (lgm)) - return -1; - } - } - else - { - if (lcm->nsh_map_index != (u32) ~ 0) - { - /* remove NSH mapping */ - pool_put_index (lcm->mapping_pool, lcm->nsh_map_index); - lcm->nsh_map_index = ~0; - vnet_lisp_gpe_del_nsh_iface (lgm); - } - } - return 0; -} - -int -vnet_lisp_pitr_set_locator_set (u8 * locator_set_name, u8 is_add) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - u32 locator_set_index = ~0; - mapping_t *m; - uword *p; - - if (vnet_lisp_enable_disable_status () == 0) - { - clib_warning ("LISP is disabled!"); - return VNET_API_ERROR_LISP_DISABLED; - } - - p = hash_get_mem (lcm->locator_set_index_by_name, locator_set_name); - if (!p) - { - clib_warning ("locator-set %v doesn't exist", locator_set_name); - return -1; - } - locator_set_index = p[0]; - - if (is_add) - { - pool_get (lcm->mapping_pool, m); - m->locator_set_index = locator_set_index; - m->local = 1; - m->pitr_set = 1; - lcm->pitr_map_index = m - lcm->mapping_pool; - } - else - { - /* remove pitr mapping */ - pool_put_index (lcm->mapping_pool, lcm->pitr_map_index); - lcm->pitr_map_index = ~0; - } - return 0; -} - -int -vnet_lisp_map_register_fallback_threshold_set (u32 value) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - if (0 == value) - { - return VNET_API_ERROR_INVALID_ARGUMENT; - } - - lcm->max_expired_map_registers = value; - return 0; -} - -u32 -vnet_lisp_map_register_fallback_threshold_get (void) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - return lcm->max_expired_map_registers; -} - -/** - * Configure Proxy-ETR - * - * @param ip PETR's IP address - * @param is_add Flag that indicates if this is an addition or removal - * - * return 0 on success - */ -int -vnet_lisp_use_petr (ip_address_t * ip, u8 is_add) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - u32 ls_index = ~0; - mapping_t *m; - vnet_lisp_add_del_locator_set_args_t _ls_args, *ls_args = &_ls_args; - locator_t loc; - - if (vnet_lisp_enable_disable_status () == 0) - { - clib_warning ("LISP is disabled!"); - return VNET_API_ERROR_LISP_DISABLED; - } - - clib_memset (ls_args, 0, sizeof (*ls_args)); - - if (is_add) - { - /* Create placeholder petr locator-set */ - clib_memset (&loc, 0, sizeof (loc)); - gid_address_from_ip (&loc.address, ip); - loc.priority = 1; - loc.state = loc.weight = 1; - loc.local = 0; - - ls_args->is_add = 1; - ls_args->index = ~0; - vec_add1 (ls_args->locators, loc); - vnet_lisp_add_del_locator_set (ls_args, &ls_index); - - /* Add petr mapping */ - pool_get (lcm->mapping_pool, m); - m->locator_set_index = ls_index; - lcm->petr_map_index = m - lcm->mapping_pool; - - /* Enable use-petr */ - lcm->flags |= LISP_FLAG_USE_PETR; - } - else - { - m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index); - - /* Remove petr locator */ - ls_args->is_add = 0; - ls_args->index = m->locator_set_index; - vnet_lisp_add_del_locator_set (ls_args, 0); - - /* Remove petr mapping */ - pool_put_index (lcm->mapping_pool, lcm->petr_map_index); - - /* Disable use-petr */ - lcm->flags &= ~LISP_FLAG_USE_PETR; - lcm->petr_map_index = ~0; - } - return 0; -} - -/* cleans locator to locator-set data and removes locators not part of - * any locator-set */ -static void -clean_locator_to_locator_set (lisp_cp_main_t * lcm, u32 lsi) -{ - u32 i, j, *loc_indexp, *ls_indexp, **ls_indexes, *to_be_deleted = 0; - locator_set_t *ls = pool_elt_at_index (lcm->locator_set_pool, lsi); - for (i = 0; i < vec_len (ls->locator_indices); i++) - { - loc_indexp = vec_elt_at_index (ls->locator_indices, i); - ls_indexes = vec_elt_at_index (lcm->locator_to_locator_sets, - loc_indexp[0]); - for (j = 0; j < vec_len (ls_indexes[0]); j++) - { - ls_indexp = vec_elt_at_index (ls_indexes[0], j); - if (ls_indexp[0] == lsi) - break; - } - - /* delete index for removed locator-set */ - vec_del1 (ls_indexes[0], j); - - /* delete locator if it's part of no locator-set */ - if (vec_len (ls_indexes[0]) == 0) - { - pool_put_index (lcm->locator_pool, loc_indexp[0]); - vec_add1 (to_be_deleted, i); - } - } - - if (to_be_deleted) - { - for (i = 0; i < vec_len (to_be_deleted); i++) - { - loc_indexp = vec_elt_at_index (to_be_deleted, i); - vec_del1 (ls->locator_indices, loc_indexp[0]); - } - vec_free (to_be_deleted); - } -} - -static inline uword * -get_locator_set_index (vnet_lisp_add_del_locator_set_args_t * a, uword * p) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - - ASSERT (a != NULL); - ASSERT (p != NULL); - - /* find locator-set */ - if (a->local) - { - ASSERT (a->name); - p = hash_get_mem (lcm->locator_set_index_by_name, a->name); - } - else - { - *p = a->index; - } - - return p; -} - -static inline int -is_locator_in_locator_set (lisp_cp_main_t * lcm, locator_set_t * ls, - locator_t * loc) -{ - locator_t *itloc; - u32 *locit; - - ASSERT (ls != NULL); - ASSERT (loc != NULL); - - vec_foreach (locit, ls->locator_indices) - { - itloc = pool_elt_at_index (lcm->locator_pool, locit[0]); - if ((ls->local && itloc->sw_if_index == loc->sw_if_index) || - (!ls->local && !gid_address_cmp (&itloc->address, &loc->address))) - { - clib_warning ("Duplicate locator"); - return VNET_API_ERROR_VALUE_EXIST; - } - } - - return 0; -} - -static void -update_adjacencies_by_map_index (lisp_cp_main_t * lcm, - u32 mapping_index, u8 remove_only) -{ - fwd_entry_t *fwd; - mapping_t *map; - uword *fei = 0, *rmts_idxp = 0; - u32 **rmts = 0, *remote_idxp = 0, *rmts_copy = 0; - vnet_lisp_add_del_adjacency_args_t _a, *a = &_a; - clib_memset (a, 0, sizeof (*a)); - - map = pool_elt_at_index (lcm->mapping_pool, mapping_index); - - if (map->local) - { - rmts_idxp = hash_get (lcm->lcl_to_rmt_adjs_by_lcl_idx, mapping_index); - if (rmts_idxp) - { - rmts = - pool_elt_at_index (lcm->lcl_to_rmt_adjacencies, rmts_idxp[0]); - rmts_copy = vec_dup (rmts[0]); - - vec_foreach (remote_idxp, rmts_copy) - { - fei = hash_get (lcm->fwd_entry_by_mapping_index, remote_idxp[0]); - if (!fei) - continue; - - fwd = pool_elt_at_index (lcm->fwd_entry_pool, fei[0]); - a->is_add = 0; - gid_address_copy (&a->leid, &fwd->leid); - gid_address_copy (&a->reid, &fwd->reid); - vnet_lisp_add_del_adjacency (a); - - if (!remove_only) - { - a->is_add = 1; - vnet_lisp_add_del_adjacency (a); - } - } - vec_free (rmts_copy); - } - } - else - { - fei = hash_get (lcm->fwd_entry_by_mapping_index, mapping_index); - if (!fei) - return; - - fwd = pool_elt_at_index (lcm->fwd_entry_pool, fei[0]); - a->is_add = 0; - gid_address_copy (&a->leid, &fwd->leid); - gid_address_copy (&a->reid, &fwd->reid); - vnet_lisp_add_del_adjacency (a); - - if (!remove_only) - { - a->is_add = 1; - vnet_lisp_add_del_adjacency (a); - } - } -} - -static void -update_fwd_entries_by_locator_set (lisp_cp_main_t * lcm, - u32 ls_index, u8 remove_only) -{ - u32 i, *map_indexp; - u32 **eid_indexes; - - if (vec_len (lcm->locator_set_to_eids) <= ls_index) - return; - - eid_indexes = vec_elt_at_index (lcm->locator_set_to_eids, ls_index); - - for (i = 0; i < vec_len (eid_indexes[0]); i++) - { - map_indexp = vec_elt_at_index (eid_indexes[0], i); - update_adjacencies_by_map_index (lcm, map_indexp[0], remove_only); - } -} - -static inline void -remove_locator_from_locator_set (locator_set_t * ls, u32 * locit, - u32 ls_index, u32 loc_id) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - u32 **ls_indexes = NULL; - - ASSERT (ls != NULL); - ASSERT (locit != NULL); - - ls_indexes = vec_elt_at_index (lcm->locator_to_locator_sets, locit[0]); - pool_put_index (lcm->locator_pool, locit[0]); - vec_del1 (ls->locator_indices, loc_id); - vec_del1 (ls_indexes[0], ls_index); -} - -int -vnet_lisp_add_del_locator (vnet_lisp_add_del_locator_set_args_t * a, - locator_set_t * ls, u32 * ls_result) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - locator_t *loc = NULL, *itloc = NULL; - uword _p = (u32) ~ 0, *p = &_p; - u32 loc_index = ~0, ls_index = ~0, *locit = NULL, **ls_indexes = NULL; - u32 loc_id = ~0; - int ret = 0; - - ASSERT (a != NULL); - - if (vnet_lisp_enable_disable_status () == 0) - { - clib_warning ("LISP is disabled!"); - return VNET_API_ERROR_LISP_DISABLED; - } - - p = get_locator_set_index (a, p); - if (!p) - { - clib_warning ("locator-set %v doesn't exist", a->name); - return VNET_API_ERROR_INVALID_ARGUMENT; - } - - if (ls == 0) - { - ls = pool_elt_at_index (lcm->locator_set_pool, p[0]); - if (!ls) - { - clib_warning ("locator-set %d to be overwritten doesn't exist!", - p[0]); - return VNET_API_ERROR_INVALID_ARGUMENT; - } - } - - if (a->is_add) - { - if (ls_result) - ls_result[0] = p[0]; - - /* allocate locators */ - vec_foreach (itloc, a->locators) - { - ret = is_locator_in_locator_set (lcm, ls, itloc); - if (0 != ret) - { - return ret; - } - - pool_get (lcm->locator_pool, loc); - loc[0] = itloc[0]; - loc_index = loc - lcm->locator_pool; - - vec_add1 (ls->locator_indices, loc_index); - - vec_validate (lcm->locator_to_locator_sets, loc_index); - ls_indexes = vec_elt_at_index (lcm->locator_to_locator_sets, - loc_index); - vec_add1 (ls_indexes[0], p[0]); - } - } - else - { - ls_index = p[0]; - u8 removed; - - vec_foreach (itloc, a->locators) - { - removed = 0; - loc_id = 0; - vec_foreach (locit, ls->locator_indices) - { - loc = pool_elt_at_index (lcm->locator_pool, locit[0]); - - if (loc->local && loc->sw_if_index == itloc->sw_if_index) - { - removed = 1; - remove_locator_from_locator_set (ls, locit, ls_index, loc_id); - } - else if (0 == loc->local && - !gid_address_cmp (&loc->address, &itloc->address)) - { - removed = 1; - remove_locator_from_locator_set (ls, locit, ls_index, loc_id); - } - - if (removed) - { - /* update fwd entries using this locator in DP */ - update_fwd_entries_by_locator_set (lcm, ls_index, - vec_len (ls->locator_indices) - == 0); - } - - loc_id++; - } - } - } - - return 0; -} - -int -vnet_lisp_add_del_locator_set (vnet_lisp_add_del_locator_set_args_t * a, - u32 * ls_result) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - locator_set_t *ls; - uword _p = (u32) ~ 0, *p = &_p; - u32 ls_index; - u32 **eid_indexes; - int ret = 0; - - if (vnet_lisp_enable_disable_status () == 0) - { - clib_warning ("LISP is disabled!"); - return VNET_API_ERROR_LISP_DISABLED; - } - - if (a->is_add) - { - p = get_locator_set_index (a, p); - - /* overwrite */ - if (p && p[0] != (u32) ~ 0) - { - ls = pool_elt_at_index (lcm->locator_set_pool, p[0]); - if (!ls) - { - clib_warning ("locator-set %d to be overwritten doesn't exist!", - p[0]); - return -1; - } - - /* clean locator to locator-set vectors and remove locators if - * they're not part of another locator-set */ - clean_locator_to_locator_set (lcm, p[0]); - - /* remove locator indices from locator set */ - vec_free (ls->locator_indices); - - ls_index = p[0]; - - if (ls_result) - ls_result[0] = p[0]; - } - /* new locator-set */ - else - { - pool_get (lcm->locator_set_pool, ls); - clib_memset (ls, 0, sizeof (*ls)); - ls_index = ls - lcm->locator_set_pool; - - if (a->local) - { - ls->name = vec_dup (a->name); - - if (!lcm->locator_set_index_by_name) - lcm->locator_set_index_by_name = - hash_create_vec ( /* size */ 0, sizeof (ls->name[0]), - sizeof (uword)); - hash_set_mem (lcm->locator_set_index_by_name, ls->name, - ls_index); - - /* mark as local locator-set */ - vec_add1 (lcm->local_locator_set_indexes, ls_index); - } - ls->local = a->local; - if (ls_result) - ls_result[0] = ls_index; - } - - ret = vnet_lisp_add_del_locator (a, ls, NULL); - if (0 != ret) - { - return ret; - } - } - else - { - p = get_locator_set_index (a, p); - if (!p) - { - clib_warning ("locator-set %v doesn't exists", a->name); - return -1; - } - - ls = pool_elt_at_index (lcm->locator_set_pool, p[0]); - if (!ls) - { - clib_warning ("locator-set with index %d doesn't exists", p[0]); - return -1; - } - - if (lcm->mreq_itr_rlocs == p[0]) - { - clib_warning ("Can't delete the locator-set used to constrain " - "the itr-rlocs in map-requests!"); - return -1; - } - - if (vec_len (lcm->locator_set_to_eids) != 0) - { - eid_indexes = vec_elt_at_index (lcm->locator_set_to_eids, p[0]); - if (vec_len (eid_indexes[0]) != 0) - { - clib_warning - ("Can't delete a locator that supports a mapping!"); - return -1; - } - } - - /* clean locator to locator-sets data */ - clean_locator_to_locator_set (lcm, p[0]); - - if (ls->local) - { - u32 it, lsi; - - vec_foreach_index (it, lcm->local_locator_set_indexes) - { - lsi = vec_elt (lcm->local_locator_set_indexes, it); - if (lsi == p[0]) - { - vec_del1 (lcm->local_locator_set_indexes, it); - break; - } - } - hash_unset_mem (lcm->locator_set_index_by_name, ls->name); - } - vec_free (ls->name); - vec_free (ls->locator_indices); - pool_put (lcm->locator_set_pool, ls); - } - return 0; -} - -int -vnet_lisp_rloc_probe_enable_disable (u8 is_enable) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - - lcm->rloc_probing = is_enable; - return 0; -} - -int -vnet_lisp_map_register_enable_disable (u8 is_enable) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - - lcm->map_registering = is_enable; - return 0; -} - -static void -lisp_cp_register_dst_port (vlib_main_t * vm) -{ - udp_register_dst_port (vm, UDP_DST_PORT_lisp_cp, - lisp_cp_input_node.index, 1 /* is_ip4 */ ); - udp_register_dst_port (vm, UDP_DST_PORT_lisp_cp6, - lisp_cp_input_node.index, 0 /* is_ip4 */ ); -} - -static void -lisp_cp_unregister_dst_port (vlib_main_t * vm) -{ - udp_unregister_dst_port (vm, UDP_DST_PORT_lisp_cp, 0 /* is_ip4 */ ); - udp_unregister_dst_port (vm, UDP_DST_PORT_lisp_cp6, 1 /* is_ip4 */ ); -} - -/** - * lisp_cp_enable_l2_l3_ifaces - * - * Enable all l2 and l3 ifaces - */ -static void -lisp_cp_enable_l2_l3_ifaces (lisp_cp_main_t * lcm, u8 with_default_route) -{ - u32 vni, dp_table; - - /* *INDENT-OFF* */ - hash_foreach(vni, dp_table, lcm->table_id_by_vni, ({ - dp_add_del_iface(lcm, vni, /* is_l2 */ 0, /* is_add */1, - with_default_route); - })); - hash_foreach(vni, dp_table, lcm->bd_id_by_vni, ({ - dp_add_del_iface(lcm, vni, /* is_l2 */ 1, 1, - with_default_route); - })); - /* *INDENT-ON* */ -} - -static void -lisp_cp_disable_l2_l3_ifaces (lisp_cp_main_t * lcm) -{ - u32 **rmts; - - /* clear interface table */ - hash_free (lcm->fwd_entry_by_mapping_index); - pool_free (lcm->fwd_entry_pool); - /* Clear state tracking rmt-lcl fwd entries */ - /* *INDENT-OFF* */ - pool_foreach(rmts, lcm->lcl_to_rmt_adjacencies, - { - vec_free(rmts[0]); - }); - /* *INDENT-ON* */ - hash_free (lcm->lcl_to_rmt_adjs_by_lcl_idx); - pool_free (lcm->lcl_to_rmt_adjacencies); -} - -clib_error_t * -vnet_lisp_enable_disable (u8 is_enable) -{ - clib_error_t *error = 0; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - vnet_lisp_gpe_enable_disable_args_t _a, *a = &_a; - - a->is_en = is_enable; - error = vnet_lisp_gpe_enable_disable (a); - if (error) - { - return clib_error_return (0, "failed to %s data-plane!", - a->is_en ? "enable" : "disable"); - } - - /* decide what to do based on mode */ - - if (lcm->flags & LISP_FLAG_XTR_MODE) - { - if (is_enable) - { - lisp_cp_register_dst_port (lcm->vlib_main); - lisp_cp_enable_l2_l3_ifaces (lcm, 1 /* with_default_route */ ); - } - else - { - lisp_cp_unregister_dst_port (lcm->vlib_main); - lisp_cp_disable_l2_l3_ifaces (lcm); - } - } - - if (lcm->flags & LISP_FLAG_PETR_MODE) - { - /* if in xTR mode, the LISP ports were already (un)registered above */ - if (!(lcm->flags & LISP_FLAG_XTR_MODE)) - { - if (is_enable) - lisp_cp_register_dst_port (lcm->vlib_main); - else - lisp_cp_unregister_dst_port (lcm->vlib_main); - } - } - - if (lcm->flags & LISP_FLAG_PITR_MODE) - { - if (is_enable) - { - /* install interfaces, but no default routes */ - lisp_cp_enable_l2_l3_ifaces (lcm, 0 /* with_default_route */ ); - } - else - { - lisp_cp_disable_l2_l3_ifaces (lcm); - } - } - - if (is_enable) - vnet_lisp_create_retry_process (lcm); - - /* update global flag */ - lcm->is_enabled = is_enable; - - return 0; -} - -u8 -vnet_lisp_enable_disable_status (void) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - return lcm->is_enabled; -} - -int -vnet_lisp_add_del_map_resolver (vnet_lisp_add_del_map_resolver_args_t * a) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - u32 i; - lisp_msmr_t _mr, *mr = &_mr; - - if (vnet_lisp_enable_disable_status () == 0) - { - clib_warning ("LISP is disabled!"); - return VNET_API_ERROR_LISP_DISABLED; - } - - if (a->is_add) - { - - if (get_map_resolver (&a->address)) - { - clib_warning ("map-resolver %U already exists!", format_ip_address, - &a->address); - return -1; - } - - clib_memset (mr, 0, sizeof (*mr)); - ip_address_copy (&mr->address, &a->address); - vec_add1 (lcm->map_resolvers, *mr); - - if (vec_len (lcm->map_resolvers) == 1) - lcm->do_map_resolver_election = 1; - } - else - { - for (i = 0; i < vec_len (lcm->map_resolvers); i++) - { - mr = vec_elt_at_index (lcm->map_resolvers, i); - if (!ip_address_cmp (&mr->address, &a->address)) - { - if (!ip_address_cmp (&mr->address, &lcm->active_map_resolver)) - lcm->do_map_resolver_election = 1; - - vec_del1 (lcm->map_resolvers, i); - break; - } - } - } - return 0; -} - -int -vnet_lisp_map_register_set_ttl (u32 ttl) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - lcm->map_register_ttl = ttl; - return 0; -} - -u32 -vnet_lisp_map_register_get_ttl (void) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - return lcm->map_register_ttl; -} - -int -vnet_lisp_add_del_mreq_itr_rlocs (vnet_lisp_add_del_mreq_itr_rloc_args_t * a) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - uword *p = 0; - - if (vnet_lisp_enable_disable_status () == 0) - { - clib_warning ("LISP is disabled!"); - return VNET_API_ERROR_LISP_DISABLED; - } - - if (a->is_add) - { - p = hash_get_mem (lcm->locator_set_index_by_name, a->locator_set_name); - if (!p) - { - clib_warning ("locator-set %v doesn't exist", a->locator_set_name); - return VNET_API_ERROR_INVALID_ARGUMENT; - } - - lcm->mreq_itr_rlocs = p[0]; - } - else - { - lcm->mreq_itr_rlocs = ~0; - } - - return 0; -} - -/* Statistics (not really errors) */ -#define foreach_lisp_cp_lookup_error \ -_(DROP, "drop") \ -_(MAP_REQUESTS_SENT, "map-request sent") \ -_(ARP_REPLY_TX, "ARP replies sent") \ -_(NDP_NEIGHBOR_ADVERTISEMENT_TX, \ - "neighbor advertisement sent") - -static char *lisp_cp_lookup_error_strings[] = { -#define _(sym,string) string, - foreach_lisp_cp_lookup_error -#undef _ -}; - -typedef enum -{ -#define _(sym,str) LISP_CP_LOOKUP_ERROR_##sym, - foreach_lisp_cp_lookup_error -#undef _ - LISP_CP_LOOKUP_N_ERROR, -} lisp_cp_lookup_error_t; - -typedef enum -{ - LISP_CP_LOOKUP_NEXT_DROP, - LISP_CP_LOOKUP_NEXT_ARP_NDP_REPLY_TX, - LISP_CP_LOOKUP_N_NEXT, -} lisp_cp_lookup_next_t; - -typedef struct -{ - gid_address_t dst_eid; - ip_address_t map_resolver_ip; -} lisp_cp_lookup_trace_t; - -u8 * -format_lisp_cp_lookup_trace (u8 * s, va_list * args) -{ - CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); - CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); - lisp_cp_lookup_trace_t *t = va_arg (*args, lisp_cp_lookup_trace_t *); - - s = format (s, "LISP-CP-LOOKUP: map-resolver: %U destination eid %U", - format_ip_address, &t->map_resolver_ip, format_gid_address, - &t->dst_eid); - return s; -} - -int -get_mr_and_local_iface_ip (lisp_cp_main_t * lcm, ip_address_t * mr_ip, - ip_address_t * sloc) -{ - lisp_msmr_t *mrit; - ip_address_t *a; - - if (vec_len (lcm->map_resolvers) == 0) - { - clib_warning ("No map-resolver configured"); - return 0; - } - - /* find the first mr ip we have a route to and the ip of the - * iface that has a route to it */ - vec_foreach (mrit, lcm->map_resolvers) - { - a = &mrit->address; - if (0 != ip_fib_get_first_egress_ip_for_dst (lcm, a, sloc)) - { - ip_address_copy (mr_ip, a); - - /* also update globals */ - return 1; - } - } - - clib_warning ("Can't find map-resolver and local interface ip!"); - return 0; -} - -static gid_address_t * -build_itr_rloc_list (lisp_cp_main_t * lcm, locator_set_t * loc_set) -{ - void *addr; - u32 i; - locator_t *loc; - u32 *loc_indexp; - ip_interface_address_t *ia = 0; - gid_address_t gid_data, *gid = &gid_data; - gid_address_t *rlocs = 0; - ip_prefix_t *ippref = &gid_address_ippref (gid); - ip_address_t *rloc = &ip_prefix_addr (ippref); - - clib_memset (gid, 0, sizeof (gid[0])); - gid_address_type (gid) = GID_ADDR_IP_PREFIX; - for (i = 0; i < vec_len (loc_set->locator_indices); i++) - { - loc_indexp = vec_elt_at_index (loc_set->locator_indices, i); - loc = pool_elt_at_index (lcm->locator_pool, loc_indexp[0]); - - /* Add ipv4 locators first TODO sort them */ - - /* *INDENT-OFF* */ - foreach_ip_interface_address (&lcm->im4->lookup_main, ia, - loc->sw_if_index, 1 /* unnumbered */, - ({ - addr = ip_interface_address_get_address (&lcm->im4->lookup_main, ia); - ip_address_set (rloc, addr, AF_IP4); - ip_prefix_len (ippref) = 32; - ip_prefix_normalize (ippref); - vec_add1 (rlocs, gid[0]); - })); - - /* Add ipv6 locators */ - foreach_ip_interface_address (&lcm->im6->lookup_main, ia, - loc->sw_if_index, 1 /* unnumbered */, - ({ - addr = ip_interface_address_get_address (&lcm->im6->lookup_main, ia); - ip_address_set (rloc, addr, AF_IP6); - ip_prefix_len (ippref) = 128; - ip_prefix_normalize (ippref); - vec_add1 (rlocs, gid[0]); - })); - /* *INDENT-ON* */ - - } - return rlocs; -} - -static vlib_buffer_t * -build_map_request (lisp_cp_main_t * lcm, gid_address_t * deid, - ip_address_t * sloc, ip_address_t * rloc, - gid_address_t * itr_rlocs, u64 * nonce_res, u32 * bi_res) -{ - vlib_buffer_t *b; - u32 bi; - vlib_main_t *vm = lcm->vlib_main; - - if (vlib_buffer_alloc (vm, &bi, 1) != 1) - { - clib_warning ("Can't allocate buffer for Map-Request!"); - return 0; - } - - b = vlib_get_buffer (vm, bi); - - /* leave some space for the encap headers */ - vlib_buffer_make_headroom (b, MAX_LISP_MSG_ENCAP_LEN); - - /* put lisp msg */ - lisp_msg_put_mreq (lcm, b, NULL, deid, itr_rlocs, 0 /* smr invoked */ , - 1 /* rloc probe */ , nonce_res); - - /* push outer ip header */ - pkt_push_udp_and_ip (vm, b, LISP_CONTROL_PORT, LISP_CONTROL_PORT, sloc, - rloc, 1); - - bi_res[0] = bi; - - return b; -} - -static vlib_buffer_t * -build_encapsulated_map_request (lisp_cp_main_t * lcm, - gid_address_t * seid, gid_address_t * deid, - locator_set_t * loc_set, ip_address_t * mr_ip, - ip_address_t * sloc, u8 is_smr_invoked, - u64 * nonce_res, u32 * bi_res) -{ - vlib_buffer_t *b; - u32 bi; - gid_address_t *rlocs = 0; - vlib_main_t *vm = lcm->vlib_main; - - if (vlib_buffer_alloc (vm, &bi, 1) != 1) - { - clib_warning ("Can't allocate buffer for Map-Request!"); - return 0; - } - - b = vlib_get_buffer (vm, bi); - b->flags = 0; - - /* leave some space for the encap headers */ - vlib_buffer_make_headroom (b, MAX_LISP_MSG_ENCAP_LEN); - - /* get rlocs */ - rlocs = build_itr_rloc_list (lcm, loc_set); - - if (MR_MODE_SRC_DST == lcm->map_request_mode - && GID_ADDR_SRC_DST != gid_address_type (deid)) - { - gid_address_t sd; - clib_memset (&sd, 0, sizeof (sd)); - build_src_dst (&sd, seid, deid); - lisp_msg_put_mreq (lcm, b, seid, &sd, rlocs, is_smr_invoked, - 0 /* rloc probe */ , nonce_res); - } - else - { - /* put lisp msg */ - lisp_msg_put_mreq (lcm, b, seid, deid, rlocs, is_smr_invoked, - 0 /* rloc probe */ , nonce_res); - } - - /* push ecm: udp-ip-lisp */ - lisp_msg_push_ecm (vm, b, LISP_CONTROL_PORT, LISP_CONTROL_PORT, seid, deid); - - /* push outer ip header */ - pkt_push_udp_and_ip (vm, b, LISP_CONTROL_PORT, LISP_CONTROL_PORT, sloc, - mr_ip, 1); - - bi_res[0] = bi; - - vec_free (rlocs); - return b; -} - -static void -reset_pending_mr_counters (pending_map_request_t * r) -{ - r->time_to_expire = PENDING_MREQ_EXPIRATION_TIME; - r->retries_num = 0; -} - -#define foreach_msmr \ - _(server) \ - _(resolver) - -#define _(name) \ -static int \ -elect_map_ ## name (lisp_cp_main_t * lcm) \ -{ \ - lisp_msmr_t *mr; \ - vec_foreach (mr, lcm->map_ ## name ## s) \ - { \ - if (!mr->is_down) \ - { \ - ip_address_copy (&lcm->active_map_ ##name, &mr->address); \ - lcm->do_map_ ## name ## _election = 0; \ - return 1; \ - } \ - } \ - return 0; \ -} -foreach_msmr -#undef _ - static void -free_map_register_records (mapping_t * maps) -{ - mapping_t *map; - vec_foreach (map, maps) vec_free (map->locators); - - vec_free (maps); -} - -static void -add_locators (lisp_cp_main_t * lcm, mapping_t * m, u32 locator_set_index, - ip_address_t * probed_loc) -{ - u32 *li; - locator_t *loc, new; - ip_interface_address_t *ia = 0; - void *addr; - ip_address_t *new_ip = &gid_address_ip (&new.address); - - m->locators = 0; - locator_set_t *ls = pool_elt_at_index (lcm->locator_set_pool, - locator_set_index); - vec_foreach (li, ls->locator_indices) - { - loc = pool_elt_at_index (lcm->locator_pool, li[0]); - new = loc[0]; - if (loc->local) - { - /* *INDENT-OFF* */ - foreach_ip_interface_address (&lcm->im4->lookup_main, ia, - loc->sw_if_index, 1 /* unnumbered */, - ({ - addr = ip_interface_address_get_address (&lcm->im4->lookup_main, - ia); - ip_address_set (new_ip, addr, AF_IP4); - })); - - /* Add ipv6 locators */ - foreach_ip_interface_address (&lcm->im6->lookup_main, ia, - loc->sw_if_index, 1 /* unnumbered */, - ({ - addr = ip_interface_address_get_address (&lcm->im6->lookup_main, - ia); - ip_address_set (new_ip, addr, AF_IP6); - })); - /* *INDENT-ON* */ - - if (probed_loc && ip_address_cmp (probed_loc, new_ip) == 0) - new.probed = 1; - } - vec_add1 (m->locators, new); - } -} - -static mapping_t * -build_map_register_record_list (lisp_cp_main_t * lcm) -{ - mapping_t *recs = 0, rec, *m; - - /* *INDENT-OFF* */ - pool_foreach(m, lcm->mapping_pool, - { - /* for now build only local mappings */ - if (!m->local) - continue; - - rec = m[0]; - add_locators (lcm, &rec, m->locator_set_index, NULL); - vec_add1 (recs, rec); - }); - /* *INDENT-ON* */ - - return recs; -} - -static vnet_crypto_alg_t -lisp_key_type_to_crypto_alg (lisp_key_type_t key_id) -{ - switch (key_id) - { - case HMAC_SHA_1_96: - return VNET_CRYPTO_ALG_HMAC_SHA1; - case HMAC_SHA_256_128: - return VNET_CRYPTO_ALG_HMAC_SHA256; - default: - clib_warning ("unsupported encryption key type: %d!", key_id); - break; - } - return VNET_CRYPTO_ALG_NONE; -} - -static vnet_crypto_op_id_t -lisp_key_type_to_crypto_op (lisp_key_type_t key_id) -{ - switch (key_id) - { - case HMAC_SHA_1_96: - return VNET_CRYPTO_OP_SHA1_HMAC; - case HMAC_SHA_256_128: - return VNET_CRYPTO_OP_SHA256_HMAC; - default: - clib_warning ("unsupported encryption key type: %d!", key_id); - break; - } - return VNET_CRYPTO_OP_NONE; -} - -static int -update_map_register_auth_data (map_register_hdr_t * map_reg_hdr, - lisp_key_type_t key_id, u8 * key, - u16 auth_data_len, u32 msg_len) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - MREG_KEY_ID (map_reg_hdr) = clib_host_to_net_u16 (key_id); - MREG_AUTH_DATA_LEN (map_reg_hdr) = clib_host_to_net_u16 (auth_data_len); - vnet_crypto_op_t _op, *op = &_op; - vnet_crypto_key_index_t ki; - - vnet_crypto_op_init (op, lisp_key_type_to_crypto_op (key_id)); - op->len = msg_len; - op->digest = MREG_DATA (map_reg_hdr); - op->src = (u8 *) map_reg_hdr; - op->digest_len = 0; - op->iv = 0; - - ki = vnet_crypto_key_add (lcm->vlib_main, - lisp_key_type_to_crypto_alg (key_id), key, - vec_len (key)); - - op->key_index = ki; - - vnet_crypto_process_ops (lcm->vlib_main, op, 1); - vnet_crypto_key_del (lcm->vlib_main, ki); - - return 0; -} - -static vlib_buffer_t * -build_map_register (lisp_cp_main_t * lcm, ip_address_t * sloc, - ip_address_t * ms_ip, u64 * nonce_res, u8 want_map_notif, - mapping_t * records, lisp_key_type_t key_id, u8 * key, - u32 * bi_res) -{ - void *map_reg_hdr; - vlib_buffer_t *b; - u32 bi, auth_data_len = 0, msg_len = 0; - vlib_main_t *vm = lcm->vlib_main; - - if (vlib_buffer_alloc (vm, &bi, 1) != 1) - { - clib_warning ("Can't allocate buffer for Map-Register!"); - return 0; - } - - b = vlib_get_buffer (vm, bi); - - /* leave some space for the encap headers */ - vlib_buffer_make_headroom (b, MAX_LISP_MSG_ENCAP_LEN); - - auth_data_len = auth_data_len_by_key_id (key_id); - map_reg_hdr = lisp_msg_put_map_register (b, records, want_map_notif, - auth_data_len, nonce_res, - &msg_len); - - update_map_register_auth_data (map_reg_hdr, key_id, key, auth_data_len, - msg_len); - - /* push outer ip header */ - pkt_push_udp_and_ip (vm, b, LISP_CONTROL_PORT, LISP_CONTROL_PORT, sloc, - ms_ip, 1); - - bi_res[0] = bi; - return b; -} - -#define _(name) \ -static int \ -get_egress_map_ ##name## _ip (lisp_cp_main_t * lcm, ip_address_t * ip) \ -{ \ - lisp_msmr_t *mr; \ - while (lcm->do_map_ ## name ## _election \ - | (0 == ip_fib_get_first_egress_ip_for_dst \ - (lcm, &lcm->active_map_ ##name, ip))) \ - { \ - if (0 == elect_map_ ## name (lcm)) \ - /* all map resolvers/servers are down */ \ - { \ - /* restart MR/MS checking by marking all of them up */ \ - vec_foreach (mr, lcm->map_ ## name ## s) mr->is_down = 0; \ - return -1; \ - } \ - } \ - return 0; \ -} - -foreach_msmr -#undef _ -/* CP output statistics */ -#define foreach_lisp_cp_output_error \ -_(MAP_REGISTERS_SENT, "map-registers sent") \ -_(MAP_REQUESTS_SENT, "map-requests sent") \ -_(RLOC_PROBES_SENT, "rloc-probes sent") -static char *lisp_cp_output_error_strings[] = { -#define _(sym,string) string, - foreach_lisp_cp_output_error -#undef _ -}; - -typedef enum -{ -#define _(sym,str) LISP_CP_OUTPUT_ERROR_##sym, - foreach_lisp_cp_output_error -#undef _ - LISP_CP_OUTPUT_N_ERROR, -} lisp_cp_output_error_t; - -static uword -lisp_cp_output (vlib_main_t * vm, vlib_node_runtime_t * node, - vlib_frame_t * from_frame) -{ - return 0; -} - -/* placeholder node used only for statistics */ -/* *INDENT-OFF* */ -VLIB_REGISTER_NODE (lisp_cp_output_node) = { - .function = lisp_cp_output, - .name = "lisp-cp-output", - .vector_size = sizeof (u32), - .format_trace = format_lisp_cp_input_trace, - .type = VLIB_NODE_TYPE_INTERNAL, - - .n_errors = LISP_CP_OUTPUT_N_ERROR, - .error_strings = lisp_cp_output_error_strings, - - .n_next_nodes = LISP_CP_INPUT_N_NEXT, - - .next_nodes = { - [LISP_CP_INPUT_NEXT_DROP] = "error-drop", - }, -}; -/* *INDENT-ON* */ - -static int -send_rloc_probe (lisp_cp_main_t * lcm, gid_address_t * deid, - u32 local_locator_set_index, ip_address_t * sloc, - ip_address_t * rloc) -{ - locator_set_t *ls; - u32 bi; - vlib_buffer_t *b; - vlib_frame_t *f; - u64 nonce = 0; - u32 next_index, *to_next; - gid_address_t *itr_rlocs; - - ls = pool_elt_at_index (lcm->locator_set_pool, local_locator_set_index); - itr_rlocs = build_itr_rloc_list (lcm, ls); - - b = build_map_request (lcm, deid, sloc, rloc, itr_rlocs, &nonce, &bi); - vec_free (itr_rlocs); - if (!b) - return -1; - - vnet_buffer (b)->sw_if_index[VLIB_TX] = 0; - - next_index = (ip_addr_version (rloc) == AF_IP4) ? - ip4_lookup_node.index : ip6_lookup_node.index; - - f = vlib_get_frame_to_node (lcm->vlib_main, next_index); - - /* Enqueue the packet */ - to_next = vlib_frame_vector_args (f); - to_next[0] = bi; - f->n_vectors = 1; - vlib_put_frame_to_node (lcm->vlib_main, next_index, f); - - return 0; -} - -static int -send_rloc_probes (lisp_cp_main_t * lcm) -{ - u8 lprio = 0; - mapping_t *lm; - fwd_entry_t *e; - locator_pair_t *lp; - u32 si, rloc_probes_sent = 0; - - /* *INDENT-OFF* */ - pool_foreach (e, lcm->fwd_entry_pool, - { - if (vec_len (e->locator_pairs) == 0) - continue; - - si = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &e->leid); - if (~0 == si) - { - clib_warning ("internal error: cannot find local eid %U in " - "map-cache!", format_gid_address, &e->leid); - continue; - } - lm = pool_elt_at_index (lcm->mapping_pool, si); - - /* get the best (lowest) priority */ - lprio = e->locator_pairs[0].priority; - - /* send rloc-probe for pair(s) with the best remote locator priority */ - vec_foreach (lp, e->locator_pairs) - { - if (lp->priority != lprio) - break; - - /* get first remote locator */ - send_rloc_probe (lcm, &e->reid, lm->locator_set_index, &lp->lcl_loc, - &lp->rmt_loc); - rloc_probes_sent++; - } - }); - /* *INDENT-ON* */ - - vlib_node_increment_counter (vlib_get_main (), lisp_cp_output_node.index, - LISP_CP_OUTPUT_ERROR_RLOC_PROBES_SENT, - rloc_probes_sent); - return 0; -} - -static int -send_map_register (lisp_cp_main_t * lcm, u8 want_map_notif) -{ - pending_map_register_t *pmr; - u32 bi, map_registers_sent = 0; - vlib_buffer_t *b; - ip_address_t sloc; - vlib_frame_t *f; - u64 nonce = 0; - u32 next_index, *to_next; - mapping_t *records, *r, *group, *k; - - if (get_egress_map_server_ip (lcm, &sloc) < 0) - return -1; - - records = build_map_register_record_list (lcm); - if (!records) - return -1; - - vec_foreach (r, records) - { - u8 *key = r->key; - u8 key_id = r->key_id; - - if (!key) - continue; /* no secret key -> map-register cannot be sent */ - - group = 0; - vec_add1 (group, r[0]); - - /* group mappings that share common key */ - for (k = r + 1; k < vec_end (records); k++) - { - if (k->key_id != r->key_id) - continue; - - if (vec_is_equal (k->key, r->key)) - { - vec_add1 (group, k[0]); - k->key = 0; /* don't process this mapping again */ - } - } - - b = build_map_register (lcm, &sloc, &lcm->active_map_server, &nonce, - want_map_notif, group, key_id, key, &bi); - vec_free (group); - if (!b) - continue; - - vnet_buffer (b)->sw_if_index[VLIB_TX] = 0; - - next_index = (ip_addr_version (&lcm->active_map_server) == AF_IP4) ? - ip4_lookup_node.index : ip6_lookup_node.index; - - f = vlib_get_frame_to_node (lcm->vlib_main, next_index); - - /* Enqueue the packet */ - to_next = vlib_frame_vector_args (f); - to_next[0] = bi; - f->n_vectors = 1; - vlib_put_frame_to_node (lcm->vlib_main, next_index, f); - map_registers_sent++; - - pool_get (lcm->pending_map_registers_pool, pmr); - clib_memset (pmr, 0, sizeof (*pmr)); - pmr->time_to_expire = PENDING_MREG_EXPIRATION_TIME; - hash_set (lcm->map_register_messages_by_nonce, nonce, - pmr - lcm->pending_map_registers_pool); - } - free_map_register_records (records); - - vlib_node_increment_counter (vlib_get_main (), lisp_cp_output_node.index, - LISP_CP_OUTPUT_ERROR_MAP_REGISTERS_SENT, - map_registers_sent); - - return 0; -} - -#define send_encapsulated_map_request(lcm, seid, deid, smr) \ - _send_encapsulated_map_request(lcm, seid, deid, smr, 0) - -#define resend_encapsulated_map_request(lcm, seid, deid, smr) \ - _send_encapsulated_map_request(lcm, seid, deid, smr, 1) - -static int -_send_encapsulated_map_request (lisp_cp_main_t * lcm, - gid_address_t * seid, gid_address_t * deid, - u8 is_smr_invoked, u8 is_resend) -{ - u32 next_index, bi = 0, *to_next, map_index; - vlib_buffer_t *b; - vlib_frame_t *f; - u64 nonce = 0; - locator_set_t *loc_set; - mapping_t *map; - pending_map_request_t *pmr, *duplicate_pmr = 0; - ip_address_t sloc; - u32 ls_index; - - /* if there is already a pending request remember it */ - - /* *INDENT-OFF* */ - pool_foreach(pmr, lcm->pending_map_requests_pool, - ({ - if (!gid_address_cmp (&pmr->src, seid) - && !gid_address_cmp (&pmr->dst, deid)) - { - duplicate_pmr = pmr; - break; - } - })); - /* *INDENT-ON* */ - - if (!is_resend && duplicate_pmr) - { - /* don't send the request if there is a pending map request already */ - return 0; - } - - u8 pitr_mode = lcm->flags & LISP_FLAG_PITR_MODE; - - /* get locator-set for seid */ - if (!pitr_mode && gid_address_type (deid) != GID_ADDR_NSH) - { - map_index = gid_dictionary_lookup (&lcm->mapping_index_by_gid, seid); - if (map_index == ~0) - { - clib_warning ("No local mapping found in eid-table for %U!", - format_gid_address, seid); - return -1; - } - - map = pool_elt_at_index (lcm->mapping_pool, map_index); - - if (!map->local) - { - clib_warning - ("Mapping found for src eid %U is not marked as local!", - format_gid_address, seid); - return -1; - } - ls_index = map->locator_set_index; - } - else - { - if (pitr_mode) - { - if (lcm->pitr_map_index != ~0) - { - map = - pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index); - ls_index = map->locator_set_index; - } - else - { - return -1; - } - } - else - { - if (lcm->nsh_map_index == (u32) ~ 0) - { - clib_warning ("No locator-set defined for NSH!"); - return -1; - } - else - { - map = pool_elt_at_index (lcm->mapping_pool, lcm->nsh_map_index); - ls_index = map->locator_set_index; - } - } - } - - /* overwrite locator set if map-request itr-rlocs configured */ - if (~0 != lcm->mreq_itr_rlocs) - { - ls_index = lcm->mreq_itr_rlocs; - } - - loc_set = pool_elt_at_index (lcm->locator_set_pool, ls_index); - - if (get_egress_map_resolver_ip (lcm, &sloc) < 0) - { - if (duplicate_pmr) - duplicate_pmr->to_be_removed = 1; - return -1; - } - - /* build the encapsulated map request */ - b = build_encapsulated_map_request (lcm, seid, deid, loc_set, - &lcm->active_map_resolver, - &sloc, is_smr_invoked, &nonce, &bi); - - if (!b) - return -1; - - /* set fib index to default and lookup node */ - vnet_buffer (b)->sw_if_index[VLIB_TX] = 0; - next_index = (ip_addr_version (&lcm->active_map_resolver) == AF_IP4) ? - ip4_lookup_node.index : ip6_lookup_node.index; - - f = vlib_get_frame_to_node (lcm->vlib_main, next_index); - - /* Enqueue the packet */ - to_next = vlib_frame_vector_args (f); - to_next[0] = bi; - f->n_vectors = 1; - vlib_put_frame_to_node (lcm->vlib_main, next_index, f); - - vlib_node_increment_counter (vlib_get_main (), lisp_cp_output_node.index, - LISP_CP_OUTPUT_ERROR_MAP_REQUESTS_SENT, 1); - - if (duplicate_pmr) - /* if there is a pending request already update it */ - { - if (clib_fifo_elts (duplicate_pmr->nonces) >= PENDING_MREQ_QUEUE_LEN) - { - /* remove the oldest nonce */ - u64 CLIB_UNUSED (tmp), *nonce_del; - nonce_del = clib_fifo_head (duplicate_pmr->nonces); - hash_unset (lcm->pending_map_requests_by_nonce, nonce_del[0]); - clib_fifo_sub1 (duplicate_pmr->nonces, tmp); - } - - clib_fifo_add1 (duplicate_pmr->nonces, nonce); - hash_set (lcm->pending_map_requests_by_nonce, nonce, - duplicate_pmr - lcm->pending_map_requests_pool); - } - else - { - /* add map-request to pending requests table */ - pool_get (lcm->pending_map_requests_pool, pmr); - clib_memset (pmr, 0, sizeof (*pmr)); - gid_address_copy (&pmr->src, seid); - gid_address_copy (&pmr->dst, deid); - clib_fifo_add1 (pmr->nonces, nonce); - pmr->is_smr_invoked = is_smr_invoked; - reset_pending_mr_counters (pmr); - hash_set (lcm->pending_map_requests_by_nonce, nonce, - pmr - lcm->pending_map_requests_pool); - } - - return 0; -} - -static void -get_src_and_dst_ip (void *hdr, ip_address_t * src, ip_address_t * dst) -{ - ip4_header_t *ip4 = hdr; - ip6_header_t *ip6; - - if ((ip4->ip_version_and_header_length & 0xF0) == 0x40) - { - ip_address_set (src, &ip4->src_address, AF_IP4); - ip_address_set (dst, &ip4->dst_address, AF_IP4); - } - else - { - ip6 = hdr; - ip_address_set (src, &ip6->src_address, AF_IP6); - ip_address_set (dst, &ip6->dst_address, AF_IP6); - } -} - -static u32 -lisp_get_vni_from_buffer_ip (lisp_cp_main_t * lcm, vlib_buffer_t * b, - u8 version) -{ - uword *vnip; - u32 vni = ~0, table_id = ~0; - - table_id = fib_table_get_table_id_for_sw_if_index ((version == - AF_IP4 ? - FIB_PROTOCOL_IP4 : - FIB_PROTOCOL_IP6), - vnet_buffer - (b)->sw_if_index - [VLIB_RX]); - - vnip = hash_get (lcm->vni_by_table_id, table_id); - if (vnip) - vni = vnip[0]; - else - clib_warning ("vrf %d is not mapped to any vni!", table_id); - - return vni; -} - -always_inline u32 -lisp_get_bd_from_buffer_eth (vlib_buffer_t * b) -{ - u32 sw_if_index0; - - l2input_main_t *l2im = &l2input_main; - l2_input_config_t *config; - l2_bridge_domain_t *bd_config; - - sw_if_index0 = vnet_buffer (b)->sw_if_index[VLIB_RX]; - config = vec_elt_at_index (l2im->configs, sw_if_index0); - bd_config = vec_elt_at_index (l2im->bd_configs, config->bd_index); - - return bd_config->bd_id; -} - -always_inline u32 -lisp_get_vni_from_buffer_eth (lisp_cp_main_t * lcm, vlib_buffer_t * b) -{ - uword *vnip; - u32 vni = ~0; - u32 bd = lisp_get_bd_from_buffer_eth (b); - - vnip = hash_get (lcm->vni_by_bd_id, bd); - if (vnip) - vni = vnip[0]; - else - clib_warning ("bridge domain %d is not mapped to any vni!", bd); - - return vni; -} - -void -get_src_and_dst_eids_from_buffer (lisp_cp_main_t * lcm, vlib_buffer_t * b, - gid_address_t * src, gid_address_t * dst, - u16 type) -{ - ethernet_header_t *eh; - u32 vni = 0; - icmp6_neighbor_discovery_ethernet_link_layer_address_option_t *opt; - - clib_memset (src, 0, sizeof (*src)); - clib_memset (dst, 0, sizeof (*dst)); - - gid_address_type (dst) = GID_ADDR_NO_ADDRESS; - gid_address_type (src) = GID_ADDR_NO_ADDRESS; - - if (LISP_AFI_IP == type || LISP_AFI_IP6 == type) - { - ip4_header_t *ip; - u8 version, preflen; - - gid_address_type (src) = GID_ADDR_IP_PREFIX; - gid_address_type (dst) = GID_ADDR_IP_PREFIX; - - ip = vlib_buffer_get_current (b); - get_src_and_dst_ip (ip, &gid_address_ip (src), &gid_address_ip (dst)); - - version = gid_address_ip_version (src); - preflen = ip_address_max_len (version); - gid_address_ippref_len (src) = preflen; - gid_address_ippref_len (dst) = preflen; - - vni = lisp_get_vni_from_buffer_ip (lcm, b, version); - gid_address_vni (dst) = vni; - gid_address_vni (src) = vni; - } - else if (LISP_AFI_MAC == type) - { - ethernet_arp_header_t *ah; - - eh = vlib_buffer_get_current (b); - - if (clib_net_to_host_u16 (eh->type) == ETHERNET_TYPE_ARP) - { - ah = (ethernet_arp_header_t *) (((u8 *) eh) + sizeof (*eh)); - gid_address_type (dst) = GID_ADDR_ARP; - - if (clib_net_to_host_u16 (ah->opcode) - != ETHERNET_ARP_OPCODE_request) - { - clib_memset (&gid_address_arp_ndp_ip (dst), 0, - sizeof (ip_address_t)); - ip_addr_version (&gid_address_arp_ndp_ip (dst)) = AF_IP4; - gid_address_arp_ndp_bd (dst) = ~0; - return; - } - - gid_address_arp_bd (dst) = lisp_get_bd_from_buffer_eth (b); - clib_memcpy (&gid_address_arp_ip4 (dst), - &ah->ip4_over_ethernet[1].ip4, 4); - } - else - { - if (clib_net_to_host_u16 (eh->type) == ETHERNET_TYPE_IP6) - { - ip6_header_t *ip; - ip = (ip6_header_t *) (eh + 1); - - if (IP_PROTOCOL_ICMP6 == ip->protocol) - { - icmp6_neighbor_solicitation_or_advertisement_header_t *ndh; - ndh = ip6_next_header (ip); - if (ndh->icmp.type == ICMP6_neighbor_solicitation) - { - gid_address_type (dst) = GID_ADDR_NDP; - - /* check that source link layer address option is present */ - opt = (void *) (ndh + 1); - if ((opt->header.type != - ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address) - || (opt->header.n_data_u64s != 1)) - { - clib_memset (&gid_address_arp_ndp_ip (dst), 0, - sizeof (ip_address_t)); - ip_addr_version (&gid_address_arp_ndp_ip (dst)) = - AF_IP6; - gid_address_arp_ndp_bd (dst) = ~0; - gid_address_type (src) = GID_ADDR_NO_ADDRESS; - return; - } - - gid_address_ndp_bd (dst) = - lisp_get_bd_from_buffer_eth (b); - ip_address_set (&gid_address_arp_ndp_ip (dst), - &ndh->target_address, AF_IP6); - return; - } - } - } - - gid_address_type (src) = GID_ADDR_MAC; - gid_address_type (dst) = GID_ADDR_MAC; - mac_copy (&gid_address_mac (src), eh->src_address); - mac_copy (&gid_address_mac (dst), eh->dst_address); - - /* get vni */ - vni = lisp_get_vni_from_buffer_eth (lcm, b); - - gid_address_vni (dst) = vni; - gid_address_vni (src) = vni; - } - } - else if (LISP_AFI_LCAF == type) - { - lisp_nsh_hdr_t *nh; - eh = vlib_buffer_get_current (b); - - if (clib_net_to_host_u16 (eh->type) == ETHERNET_TYPE_NSH) - { - nh = (lisp_nsh_hdr_t *) (((u8 *) eh) + sizeof (*eh)); - u32 spi = clib_net_to_host_u32 (nh->spi_si << 8); - u8 si = (u8) clib_net_to_host_u32 (nh->spi_si); - gid_address_nsh_spi (dst) = spi; - gid_address_nsh_si (dst) = si; - - gid_address_type (dst) = GID_ADDR_NSH; - gid_address_type (src) = GID_ADDR_NSH; - } - } -} - -static uword -lisp_cp_lookup_inline (vlib_main_t * vm, - vlib_node_runtime_t * node, - vlib_frame_t * from_frame, int overlay) -{ - icmp6_neighbor_discovery_ethernet_link_layer_address_option_t *opt; - u32 *from, *to_next, di, si; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - u32 next_index; - uword n_left_from, n_left_to_next; - vnet_main_t *vnm = vnet_get_main (); - - from = vlib_frame_vector_args (from_frame); - n_left_from = from_frame->n_vectors; - next_index = node->cached_next_index; - - while (n_left_from > 0) - { - vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); - - while (n_left_from > 0 && n_left_to_next > 0) - { - u32 pi0, sw_if_index0, next0; - u64 mac0; - vlib_buffer_t *b0; - gid_address_t src, dst; - ethernet_arp_header_t *arp0; - ethernet_header_t *eth0; - vnet_hw_interface_t *hw_if0; - ethernet_header_t *eh0; - icmp6_neighbor_solicitation_or_advertisement_header_t *ndh; - ip6_header_t *ip0; - - pi0 = from[0]; - from += 1; - n_left_from -= 1; - to_next[0] = pi0; - to_next += 1; - n_left_to_next -= 1; - - b0 = vlib_get_buffer (vm, pi0); - - /* src/dst eid pair */ - get_src_and_dst_eids_from_buffer (lcm, b0, &src, &dst, overlay); - - if (gid_address_type (&dst) == GID_ADDR_ARP) - { - mac0 = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &dst); - if (GID_LOOKUP_MISS_L2 == mac0) - goto drop; - - /* send ARP reply */ - sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX]; - vnet_buffer (b0)->sw_if_index[VLIB_TX] = sw_if_index0; - - hw_if0 = vnet_get_sup_hw_interface (vnm, sw_if_index0); - - eth0 = vlib_buffer_get_current (b0); - arp0 = (ethernet_arp_header_t *) (((u8 *) eth0) - + sizeof (*eth0)); - arp0->opcode = clib_host_to_net_u16 (ETHERNET_ARP_OPCODE_reply); - arp0->ip4_over_ethernet[1] = arp0->ip4_over_ethernet[0]; - mac_address_from_u64 (&arp0->ip4_over_ethernet[0].mac, mac0); - clib_memcpy (&arp0->ip4_over_ethernet[0].ip4, - &gid_address_arp_ip4 (&dst), 4); - - /* Hardware must be ethernet-like. */ - ASSERT (vec_len (hw_if0->hw_address) == 6); - - clib_memcpy (eth0->dst_address, eth0->src_address, 6); - clib_memcpy (eth0->src_address, hw_if0->hw_address, 6); - - b0->error = node->errors[LISP_CP_LOOKUP_ERROR_ARP_REPLY_TX]; - next0 = LISP_CP_LOOKUP_NEXT_ARP_NDP_REPLY_TX; - goto enqueue; - } - else if (gid_address_type (&dst) == GID_ADDR_NDP) - { - mac0 = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &dst); - if (GID_LOOKUP_MISS_L2 == mac0) - goto drop; - - sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX]; - vnet_buffer (b0)->sw_if_index[VLIB_TX] = sw_if_index0; - - eh0 = vlib_buffer_get_current (b0); - ip0 = (ip6_header_t *) (eh0 + 1); - ndh = ip6_next_header (ip0); - int bogus_length; - ip0->dst_address = ip0->src_address; - ip0->src_address = ndh->target_address; - ip0->hop_limit = 255; - opt = (void *) (ndh + 1); - opt->header.type = - ICMP6_NEIGHBOR_DISCOVERY_OPTION_target_link_layer_address; - clib_memcpy (opt->ethernet_address, (u8 *) & mac0, 6); - ndh->icmp.type = ICMP6_neighbor_advertisement; - ndh->advertisement_flags = clib_host_to_net_u32 - (ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_SOLICITED | - ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_OVERRIDE); - ndh->icmp.checksum = 0; - ndh->icmp.checksum = - ip6_tcp_udp_icmp_compute_checksum (vm, b0, ip0, - &bogus_length); - clib_memcpy (eh0->dst_address, eh0->src_address, 6); - clib_memcpy (eh0->src_address, (u8 *) & mac0, 6); - b0->error = - node->errors - [LISP_CP_LOOKUP_ERROR_NDP_NEIGHBOR_ADVERTISEMENT_TX]; - next0 = LISP_CP_LOOKUP_NEXT_ARP_NDP_REPLY_TX; - goto enqueue; - } - - /* if we have remote mapping for destination already in map-cache - add forwarding tunnel directly. If not send a map-request */ - di = gid_dictionary_sd_lookup (&lcm->mapping_index_by_gid, &dst, - &src); - if (~0 != di) - { - mapping_t *m = vec_elt_at_index (lcm->mapping_pool, di); - /* send a map-request also in case of negative mapping entry - with corresponding action */ - if (m->action == LISP_SEND_MAP_REQUEST) - { - /* send map-request */ - queue_map_request (&src, &dst, 0 /* smr_invoked */ , - 0 /* is_resend */ ); - } - else - { - if (GID_ADDR_NSH != gid_address_type (&dst)) - { - si = gid_dictionary_lookup (&lcm->mapping_index_by_gid, - &src); - } - else - si = lcm->nsh_map_index; - - if (~0 != si) - { - dp_add_fwd_entry_from_mt (si, di); - } - } - } - else - { - /* send map-request */ - queue_map_request (&src, &dst, 0 /* smr_invoked */ , - 0 /* is_resend */ ); - } - - drop: - b0->error = node->errors[LISP_CP_LOOKUP_ERROR_DROP]; - next0 = LISP_CP_LOOKUP_NEXT_DROP; - enqueue: - if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) - { - lisp_cp_lookup_trace_t *tr = vlib_add_trace (vm, node, b0, - sizeof (*tr)); - - clib_memset (tr, 0, sizeof (*tr)); - if ((gid_address_type (&dst) == GID_ADDR_NDP) || - (gid_address_type (&dst) == GID_ADDR_ARP)) - clib_memcpy (&tr->dst_eid, &dst, sizeof (gid_address_t)); - else - gid_address_copy (&tr->dst_eid, &dst); - ip_address_copy (&tr->map_resolver_ip, - &lcm->active_map_resolver); - } - gid_address_free (&dst); - gid_address_free (&src); - vlib_validate_buffer_enqueue_x1 (vm, node, next_index, - to_next, - n_left_to_next, pi0, next0); - } - - vlib_put_next_frame (vm, node, next_index, n_left_to_next); - } - return from_frame->n_vectors; -} - -static uword -lisp_cp_lookup_ip4 (vlib_main_t * vm, - vlib_node_runtime_t * node, vlib_frame_t * from_frame) -{ - return (lisp_cp_lookup_inline (vm, node, from_frame, LISP_AFI_IP)); -} - -static uword -lisp_cp_lookup_ip6 (vlib_main_t * vm, - vlib_node_runtime_t * node, vlib_frame_t * from_frame) -{ - return (lisp_cp_lookup_inline (vm, node, from_frame, LISP_AFI_IP6)); -} - -static uword -lisp_cp_lookup_l2 (vlib_main_t * vm, - vlib_node_runtime_t * node, vlib_frame_t * from_frame) -{ - return (lisp_cp_lookup_inline (vm, node, from_frame, LISP_AFI_MAC)); -} - -static uword -lisp_cp_lookup_nsh (vlib_main_t * vm, - vlib_node_runtime_t * node, vlib_frame_t * from_frame) -{ - /* TODO decide if NSH should be propagated as LCAF or not */ - return (lisp_cp_lookup_inline (vm, node, from_frame, LISP_AFI_LCAF)); -} - -/* *INDENT-OFF* */ -VLIB_REGISTER_NODE (lisp_cp_lookup_ip4_node) = { - .function = lisp_cp_lookup_ip4, - .name = "lisp-cp-lookup-ip4", - .vector_size = sizeof (u32), - .format_trace = format_lisp_cp_lookup_trace, - .type = VLIB_NODE_TYPE_INTERNAL, - - .n_errors = LISP_CP_LOOKUP_N_ERROR, - .error_strings = lisp_cp_lookup_error_strings, - - .n_next_nodes = LISP_CP_LOOKUP_N_NEXT, - - .next_nodes = { - [LISP_CP_LOOKUP_NEXT_DROP] = "error-drop", - [LISP_CP_LOOKUP_NEXT_ARP_NDP_REPLY_TX] = "interface-output", - }, -}; -/* *INDENT-ON* */ - -/* *INDENT-OFF* */ -VLIB_REGISTER_NODE (lisp_cp_lookup_ip6_node) = { - .function = lisp_cp_lookup_ip6, - .name = "lisp-cp-lookup-ip6", - .vector_size = sizeof (u32), - .format_trace = format_lisp_cp_lookup_trace, - .type = VLIB_NODE_TYPE_INTERNAL, - - .n_errors = LISP_CP_LOOKUP_N_ERROR, - .error_strings = lisp_cp_lookup_error_strings, - - .n_next_nodes = LISP_CP_LOOKUP_N_NEXT, - - .next_nodes = { - [LISP_CP_LOOKUP_NEXT_DROP] = "error-drop", - [LISP_CP_LOOKUP_NEXT_ARP_NDP_REPLY_TX] = "interface-output", - }, -}; -/* *INDENT-ON* */ - -/* *INDENT-OFF* */ -VLIB_REGISTER_NODE (lisp_cp_lookup_l2_node) = { - .function = lisp_cp_lookup_l2, - .name = "lisp-cp-lookup-l2", - .vector_size = sizeof (u32), - .format_trace = format_lisp_cp_lookup_trace, - .type = VLIB_NODE_TYPE_INTERNAL, - - .n_errors = LISP_CP_LOOKUP_N_ERROR, - .error_strings = lisp_cp_lookup_error_strings, - - .n_next_nodes = LISP_CP_LOOKUP_N_NEXT, - - .next_nodes = { - [LISP_CP_LOOKUP_NEXT_DROP] = "error-drop", - [LISP_CP_LOOKUP_NEXT_ARP_NDP_REPLY_TX] = "interface-output", - }, -}; -/* *INDENT-ON* */ - -/* *INDENT-OFF* */ -VLIB_REGISTER_NODE (lisp_cp_lookup_nsh_node) = { - .function = lisp_cp_lookup_nsh, - .name = "lisp-cp-lookup-nsh", - .vector_size = sizeof (u32), - .format_trace = format_lisp_cp_lookup_trace, - .type = VLIB_NODE_TYPE_INTERNAL, - - .n_errors = LISP_CP_LOOKUP_N_ERROR, - .error_strings = lisp_cp_lookup_error_strings, - - .n_next_nodes = LISP_CP_LOOKUP_N_NEXT, - - .next_nodes = { - [LISP_CP_LOOKUP_NEXT_DROP] = "error-drop", - [LISP_CP_LOOKUP_NEXT_ARP_NDP_REPLY_TX] = "interface-output", - }, -}; -/* *INDENT-ON* */ - -/* lisp_cp_input statistics */ -#define foreach_lisp_cp_input_error \ -_(DROP, "drop") \ -_(RLOC_PROBE_REQ_RECEIVED, "rloc-probe requests received") \ -_(RLOC_PROBE_REP_RECEIVED, "rloc-probe replies received") \ -_(MAP_NOTIFIES_RECEIVED, "map-notifies received") \ -_(MAP_REPLIES_RECEIVED, "map-replies received") - -static char *lisp_cp_input_error_strings[] = { -#define _(sym,string) string, - foreach_lisp_cp_input_error -#undef _ -}; - -typedef enum -{ -#define _(sym,str) LISP_CP_INPUT_ERROR_##sym, - foreach_lisp_cp_input_error -#undef _ - LISP_CP_INPUT_N_ERROR, -} lisp_cp_input_error_t; - -typedef struct -{ - gid_address_t dst_eid; - ip4_address_t map_resolver_ip; -} lisp_cp_input_trace_t; - -u8 * -format_lisp_cp_input_trace (u8 * s, va_list * args) -{ - CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); - CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); - CLIB_UNUSED (lisp_cp_input_trace_t * t) = - va_arg (*args, lisp_cp_input_trace_t *); - - s = format (s, "LISP-CP-INPUT: TODO"); - return s; -} - -static void -remove_expired_mapping (lisp_cp_main_t * lcm, u32 mi) -{ - mapping_t *m; - vnet_lisp_add_del_adjacency_args_t _adj_args, *adj_args = &_adj_args; - clib_memset (adj_args, 0, sizeof (adj_args[0])); - - m = pool_elt_at_index (lcm->mapping_pool, mi); - - gid_address_copy (&adj_args->reid, &m->eid); - adj_args->is_add = 0; - if (vnet_lisp_add_del_adjacency (adj_args)) - clib_warning ("failed to del adjacency!"); - - TW (tw_timer_stop) (&lcm->wheel, m->timer_handle); - vnet_lisp_del_mapping (&m->eid, NULL); -} - -static void -mapping_start_expiration_timer (lisp_cp_main_t * lcm, u32 mi, - f64 expiration_time) -{ - mapping_t *m; - u64 now = clib_cpu_time_now (); - u64 cpu_cps = lcm->vlib_main->clib_time.clocks_per_second; - u64 exp_clock_time = now + expiration_time * cpu_cps; - - m = pool_elt_at_index (lcm->mapping_pool, mi); - - m->timer_set = 1; - m->timer_handle = TW (tw_timer_start) (&lcm->wheel, mi, 0, exp_clock_time); -} - -static void -process_expired_mapping (lisp_cp_main_t * lcm, u32 mi) -{ - int rv; - vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a; - mapping_t *m = pool_elt_at_index (lcm->mapping_pool, mi); - uword *fei; - fwd_entry_t *fe; - vlib_counter_t c; - u8 have_stats = 0; - - if (m->delete_after_expiration) - { - remove_expired_mapping (lcm, mi); - return; - } - - fei = hash_get (lcm->fwd_entry_by_mapping_index, mi); - if (!fei) - return; - - fe = pool_elt_at_index (lcm->fwd_entry_pool, fei[0]); - - clib_memset (a, 0, sizeof (*a)); - a->rmt_eid = fe->reid; - if (fe->is_src_dst) - a->lcl_eid = fe->leid; - a->vni = gid_address_vni (&fe->reid); - - rv = vnet_lisp_gpe_get_fwd_stats (a, &c); - if (0 == rv) - have_stats = 1; - - if (m->almost_expired) - { - m->almost_expired = 0; /* reset flag */ - if (have_stats) - { - if (m->packets != c.packets) - { - /* mapping is in use, re-fetch */ - map_request_args_t mr_args; - clib_memset (&mr_args, 0, sizeof (mr_args)); - mr_args.seid = fe->leid; - mr_args.deid = fe->reid; - - send_map_request_thread_fn (&mr_args); - } - else - remove_expired_mapping (lcm, mi); - } - else - remove_expired_mapping (lcm, mi); - } - else - { - m->almost_expired = 1; - mapping_start_expiration_timer (lcm, mi, TIME_UNTIL_REFETCH_OR_DELETE); - - if (have_stats) - /* save counter */ - m->packets = c.packets; - else - m->delete_after_expiration = 1; - } -} - -static void -map_records_arg_free (map_records_arg_t * a) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - mapping_t *m; - vec_foreach (m, a->mappings) - { - vec_free (m->locators); - gid_address_free (&m->eid); - } - pool_put (lcm->map_records_args_pool[vlib_get_thread_index ()], a); -} - -void * -process_map_reply (map_records_arg_t * a) -{ - mapping_t *m; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - u32 dst_map_index = 0; - pending_map_request_t *pmr; - u64 *noncep; - uword *pmr_index; - u8 is_changed = 0; - - if (a->is_rloc_probe) - goto done; - - /* Check pending requests table and nonce */ - pmr_index = hash_get (lcm->pending_map_requests_by_nonce, a->nonce); - if (!pmr_index) - { - clib_warning ("No pending map-request entry with nonce %lu!", a->nonce); - goto done; - } - pmr = pool_elt_at_index (lcm->pending_map_requests_pool, pmr_index[0]); - - vec_foreach (m, a->mappings) - { - vnet_lisp_add_del_mapping_args_t _m_args, *m_args = &_m_args; - clib_memset (m_args, 0, sizeof (m_args[0])); - gid_address_copy (&m_args->eid, &m->eid); - m_args->action = m->action; - m_args->authoritative = m->authoritative; - m_args->ttl = m->ttl; - m_args->is_static = 0; - - /* insert/update mappings cache */ - vnet_lisp_add_mapping (m_args, m->locators, &dst_map_index, &is_changed); - - if (dst_map_index == (u32) ~ 0) - continue; - - if (is_changed) - { - /* try to program forwarding only if mapping saved or updated */ - vnet_lisp_add_del_adjacency_args_t _adj_args, *adj_args = &_adj_args; - clib_memset (adj_args, 0, sizeof (adj_args[0])); - - gid_address_copy (&adj_args->leid, &pmr->src); - gid_address_copy (&adj_args->reid, &m->eid); - adj_args->is_add = 1; - - if (vnet_lisp_add_del_adjacency (adj_args)) - clib_warning ("failed to add adjacency!"); - } - - if ((u32) ~ 0 != m->ttl) - mapping_start_expiration_timer (lcm, dst_map_index, - (m->ttl == 0) ? 0 : MAPPING_TIMEOUT); - } - - /* remove pending map request entry */ - - /* *INDENT-OFF* */ - clib_fifo_foreach (noncep, pmr->nonces, ({ - hash_unset(lcm->pending_map_requests_by_nonce, noncep[0]); - })); - /* *INDENT-ON* */ - - clib_fifo_free (pmr->nonces); - pool_put (lcm->pending_map_requests_pool, pmr); - -done: - a->is_free = 1; - return 0; -} - -static int -is_auth_data_valid (map_notify_hdr_t * h, u32 msg_len, - lisp_key_type_t key_id, u8 * key) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - u8 *auth_data = 0; - u16 auth_data_len; - int result; - vnet_crypto_op_t _op, *op = &_op; - vnet_crypto_key_index_t ki; - u8 out[EVP_MAX_MD_SIZE] = { 0, }; - - auth_data_len = auth_data_len_by_key_id (key_id); - if ((u16) ~ 0 == auth_data_len) - { - clib_warning ("invalid length for key_id %d!", key_id); - return 0; - } - - /* save auth data */ - vec_validate (auth_data, auth_data_len - 1); - clib_memcpy (auth_data, MNOTIFY_DATA (h), auth_data_len); - - /* clear auth data */ - clib_memset (MNOTIFY_DATA (h), 0, auth_data_len); - - vnet_crypto_op_init (op, lisp_key_type_to_crypto_op (key_id)); - op->len = msg_len; - op->digest = out; - op->src = (u8 *) h; - op->digest_len = 0; - op->iv = 0; - - ki = vnet_crypto_key_add (lcm->vlib_main, - lisp_key_type_to_crypto_alg (key_id), key, - vec_len (key)); - - op->key_index = ki; - - vnet_crypto_process_ops (lcm->vlib_main, op, 1); - vnet_crypto_key_del (lcm->vlib_main, ki); - - result = memcmp (out, auth_data, auth_data_len); - - vec_free (auth_data); - - return !result; -} - -static void -process_map_notify (map_records_arg_t * a) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - uword *pmr_index; - - pmr_index = hash_get (lcm->map_register_messages_by_nonce, a->nonce); - if (!pmr_index) - { - clib_warning ("No pending map-register entry with nonce %lu!", - a->nonce); - return; - } - - a->is_free = 1; - pool_put_index (lcm->pending_map_registers_pool, pmr_index[0]); - hash_unset (lcm->map_register_messages_by_nonce, a->nonce); - - /* reset map-notify counter */ - lcm->expired_map_registers = 0; -} - -static mapping_t * -get_mapping (lisp_cp_main_t * lcm, gid_address_t * e) -{ - u32 mi; - - mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, e); - if (~0 == mi) - { - clib_warning ("eid %U not found in map-cache!", unformat_gid_address, - e); - return 0; - } - return pool_elt_at_index (lcm->mapping_pool, mi); -} - -/** - * When map-notify is received it is necessary that all EIDs in the record - * list share common key. The key is then used to verify authentication - * data in map-notify message. - */ -static int -map_record_integrity_check (lisp_cp_main_t * lcm, mapping_t * maps, - u32 key_id, u8 ** key_out) -{ - u32 i, len = vec_len (maps); - mapping_t *m; - - /* get key of the first mapping */ - m = get_mapping (lcm, &maps[0].eid); - if (!m || !m->key) - return -1; - - key_out[0] = m->key; - - for (i = 1; i < len; i++) - { - m = get_mapping (lcm, &maps[i].eid); - if (!m || !m->key) - return -1; - - if (key_id != m->key_id || vec_cmp (m->key, key_out[0])) - { - clib_warning ("keys does not match! %v, %v", key_out[0], m->key); - return -1; - } - } - return 0; -} - -static int -parse_map_records (vlib_buffer_t * b, map_records_arg_t * a, u8 count) -{ - locator_t *locators = 0; - u32 i, len; - gid_address_t deid; - mapping_t m; - locator_t *loc; - - clib_memset (&m, 0, sizeof (m)); - - /* parse record eid */ - for (i = 0; i < count; i++) - { - locators = 0; - len = lisp_msg_parse_mapping_record (b, &deid, &locators, NULL); - if (len == ~0) - { - clib_warning ("Failed to parse mapping record!"); - vec_foreach (loc, locators) locator_free (loc); - vec_free (locators); - return -1; - } - - m.locators = locators; - gid_address_copy (&m.eid, &deid); - vec_add1 (a->mappings, m); - } - - return 0; -} - -static map_records_arg_t * -map_record_args_get () -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - map_records_arg_t *rec; - - /* Cleanup first */ - /* *INDENT-OFF* */ - pool_foreach (rec, lcm->map_records_args_pool[vlib_get_thread_index()], ({ - if (rec->is_free) - map_records_arg_free (rec); - })); - /* *INDENT-ON* */ - - pool_get (lcm->map_records_args_pool[vlib_get_thread_index ()], rec); - return rec; -} - -static map_records_arg_t * -parse_map_notify (vlib_buffer_t * b) -{ - int rc = 0; - map_notify_hdr_t *mnotif_hdr; - lisp_key_type_t key_id; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - u8 *key = 0; - gid_address_t deid; - u16 auth_data_len = 0; - u8 record_count; - map_records_arg_t *a; - - a = map_record_args_get (); - clib_memset (a, 0, sizeof (*a)); - mnotif_hdr = vlib_buffer_get_current (b); - vlib_buffer_pull (b, sizeof (*mnotif_hdr)); - clib_memset (&deid, 0, sizeof (deid)); - - a->nonce = MNOTIFY_NONCE (mnotif_hdr); - key_id = clib_net_to_host_u16 (MNOTIFY_KEY_ID (mnotif_hdr)); - auth_data_len = auth_data_len_by_key_id (key_id); - - /* advance buffer by authentication data */ - vlib_buffer_pull (b, auth_data_len); - - record_count = MNOTIFY_REC_COUNT (mnotif_hdr); - rc = parse_map_records (b, a, record_count); - if (rc != 0) - { - map_records_arg_free (a); - return 0; - } - - rc = map_record_integrity_check (lcm, a->mappings, key_id, &key); - if (rc != 0) - { - map_records_arg_free (a); - return 0; - } - - /* verify authentication data */ - if (!is_auth_data_valid (mnotif_hdr, vlib_buffer_get_tail (b) - - (u8 *) mnotif_hdr, key_id, key)) - { - clib_warning ("Map-notify auth data verification failed for nonce " - "0x%lx!", a->nonce); - map_records_arg_free (a); - return 0; - } - return a; -} - -static vlib_buffer_t * -build_map_reply (lisp_cp_main_t * lcm, ip_address_t * sloc, - ip_address_t * dst, u64 nonce, u8 probe_bit, - mapping_t * records, u16 dst_port, u32 * bi_res) -{ - vlib_buffer_t *b; - u32 bi; - vlib_main_t *vm = lcm->vlib_main; - - if (vlib_buffer_alloc (vm, &bi, 1) != 1) - { - clib_warning ("Can't allocate buffer for Map-Register!"); - return 0; - } - - b = vlib_get_buffer (vm, bi); - - /* leave some space for the encap headers */ - vlib_buffer_make_headroom (b, MAX_LISP_MSG_ENCAP_LEN); - - lisp_msg_put_map_reply (b, records, nonce, probe_bit); - - /* push outer ip header */ - pkt_push_udp_and_ip (vm, b, LISP_CONTROL_PORT, dst_port, sloc, dst, 1); - - bi_res[0] = bi; - return b; -} - -static int -send_map_reply (lisp_cp_main_t * lcm, u32 mi, ip_address_t * dst, - u8 probe_bit, u64 nonce, u16 dst_port, - ip_address_t * probed_loc) -{ - ip_address_t src; - u32 bi; - vlib_buffer_t *b; - vlib_frame_t *f; - u32 next_index, *to_next; - mapping_t *records = 0, *m; - - m = pool_elt_at_index (lcm->mapping_pool, mi); - if (!m) - return -1; - - vec_add1 (records, m[0]); - add_locators (lcm, &records[0], m->locator_set_index, probed_loc); - clib_memset (&src, 0, sizeof (src)); - - if (!ip_fib_get_first_egress_ip_for_dst (lcm, dst, &src)) - { - clib_warning ("can't find interface address for %U", format_ip_address, - dst); - return -1; - } - - b = build_map_reply (lcm, &src, dst, nonce, probe_bit, records, dst_port, - &bi); - if (!b) - return -1; - free_map_register_records (records); - - vnet_buffer (b)->sw_if_index[VLIB_TX] = 0; - next_index = (ip_addr_version (&lcm->active_map_resolver) == AF_IP4) ? - ip4_lookup_node.index : ip6_lookup_node.index; - - f = vlib_get_frame_to_node (lcm->vlib_main, next_index); - - /* Enqueue the packet */ - to_next = vlib_frame_vector_args (f); - to_next[0] = bi; - f->n_vectors = 1; - vlib_put_frame_to_node (lcm->vlib_main, next_index, f); - return 0; -} - -static void -find_ip_header (vlib_buffer_t * b, u8 ** ip_hdr) -{ - const i32 start = vnet_buffer (b)->l3_hdr_offset; - if (start < 0 && start < -sizeof (b->pre_data)) - { - *ip_hdr = 0; - return; - } - - *ip_hdr = b->data + start; - if ((u8 *) * ip_hdr > (u8 *) vlib_buffer_get_current (b)) - *ip_hdr = 0; -} - -void -process_map_request (vlib_main_t * vm, vlib_node_runtime_t * node, - lisp_cp_main_t * lcm, vlib_buffer_t * b) -{ - u8 *ip_hdr = 0; - ip_address_t *dst_loc = 0, probed_loc, src_loc; - mapping_t m; - map_request_hdr_t *mreq_hdr; - gid_address_t src, dst; - u64 nonce; - u32 i, len = 0, rloc_probe_recv = 0; - gid_address_t *itr_rlocs = 0; - - mreq_hdr = vlib_buffer_get_current (b); - if (!MREQ_SMR (mreq_hdr) && !MREQ_RLOC_PROBE (mreq_hdr)) - { - clib_warning - ("Only SMR Map-Requests and RLOC probe supported for now!"); - return; - } - - vlib_buffer_pull (b, sizeof (*mreq_hdr)); - nonce = MREQ_NONCE (mreq_hdr); - - /* parse src eid */ - len = lisp_msg_parse_addr (b, &src); - if (len == ~0) - return; - - len = lisp_msg_parse_itr_rlocs (b, &itr_rlocs, - MREQ_ITR_RLOC_COUNT (mreq_hdr) + 1); - if (len == ~0) - goto done; - - /* parse eid records and send SMR-invoked map-requests */ - for (i = 0; i < MREQ_REC_COUNT (mreq_hdr); i++) - { - clib_memset (&dst, 0, sizeof (dst)); - len = lisp_msg_parse_eid_rec (b, &dst); - if (len == ~0) - { - clib_warning ("Can't parse map-request EID-record"); - goto done; - } - - if (MREQ_SMR (mreq_hdr)) - { - /* send SMR-invoked map-requests */ - queue_map_request (&dst, &src, 1 /* invoked */ , 0 /* resend */ ); - } - else if (MREQ_RLOC_PROBE (mreq_hdr)) - { - find_ip_header (b, &ip_hdr); - if (!ip_hdr) - { - clib_warning ("Cannot find the IP header!"); - goto done; - } - rloc_probe_recv++; - clib_memset (&m, 0, sizeof (m)); - u32 mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &dst); - - // TODO: select best locator; for now use the first one - dst_loc = &gid_address_ip (&itr_rlocs[0]); - - /* get src/dst IP addresses */ - get_src_and_dst_ip (ip_hdr, &src_loc, &probed_loc); - - // TODO get source port from buffer - u16 src_port = LISP_CONTROL_PORT; - - send_map_reply (lcm, mi, dst_loc, 1 /* probe-bit */ , nonce, - src_port, &probed_loc); - } - } - -done: - vlib_node_increment_counter (vm, node->node_index, - LISP_CP_INPUT_ERROR_RLOC_PROBE_REQ_RECEIVED, - rloc_probe_recv); - vec_free (itr_rlocs); -} - -map_records_arg_t * -parse_map_reply (vlib_buffer_t * b) -{ - locator_t probed; - gid_address_t deid; - void *h; - u32 i, len = 0; - mapping_t m; - map_reply_hdr_t *mrep_hdr; - map_records_arg_t *a; - - a = map_record_args_get (); - clib_memset (a, 0, sizeof (*a)); - - locator_t *locators; - - mrep_hdr = vlib_buffer_get_current (b); - a->nonce = MREP_NONCE (mrep_hdr); - a->is_rloc_probe = MREP_RLOC_PROBE (mrep_hdr); - if (!vlib_buffer_has_space (b, sizeof (*mrep_hdr))) - { - map_records_arg_free (a); - return 0; - } - vlib_buffer_pull (b, sizeof (*mrep_hdr)); - - for (i = 0; i < MREP_REC_COUNT (mrep_hdr); i++) - { - clib_memset (&m, 0, sizeof (m)); - locators = 0; - h = vlib_buffer_get_current (b); - - m.ttl = clib_net_to_host_u32 (MAP_REC_TTL (h)); - m.action = MAP_REC_ACTION (h); - m.authoritative = MAP_REC_AUTH (h); - - len = lisp_msg_parse_mapping_record (b, &deid, &locators, &probed); - if (len == ~0) - { - clib_warning ("Failed to parse mapping record!"); - map_records_arg_free (a); - return 0; - } - - m.locators = locators; - gid_address_copy (&m.eid, &deid); - vec_add1 (a->mappings, m); - } - return a; -} - -static void -queue_map_reply_for_processing (map_records_arg_t * a) -{ - vl_api_rpc_call_main_thread (process_map_reply, (u8 *) a, sizeof (*a)); -} - -static void -queue_map_notify_for_processing (map_records_arg_t * a) -{ - vl_api_rpc_call_main_thread (process_map_notify, (u8 *) a, sizeof (a[0])); -} - -static uword -lisp_cp_input (vlib_main_t * vm, vlib_node_runtime_t * node, - vlib_frame_t * from_frame) -{ - u32 n_left_from, *from, *to_next_drop, rloc_probe_rep_recv = 0, - map_notifies_recv = 0; - lisp_msg_type_e type; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - map_records_arg_t *a; - - from = vlib_frame_vector_args (from_frame); - n_left_from = from_frame->n_vectors; - - - while (n_left_from > 0) - { - u32 n_left_to_next_drop; - - vlib_get_next_frame (vm, node, LISP_CP_INPUT_NEXT_DROP, - to_next_drop, n_left_to_next_drop); - while (n_left_from > 0 && n_left_to_next_drop > 0) - { - u32 bi0; - vlib_buffer_t *b0; - - bi0 = from[0]; - from += 1; - n_left_from -= 1; - to_next_drop[0] = bi0; - to_next_drop += 1; - n_left_to_next_drop -= 1; - - b0 = vlib_get_buffer (vm, bi0); - - type = lisp_msg_type (vlib_buffer_get_current (b0)); - switch (type) - { - case LISP_MAP_REPLY: - a = parse_map_reply (b0); - if (a) - { - if (a->is_rloc_probe) - rloc_probe_rep_recv++; - queue_map_reply_for_processing (a); - } - break; - case LISP_MAP_REQUEST: - process_map_request (vm, node, lcm, b0); - break; - case LISP_MAP_NOTIFY: - a = parse_map_notify (b0); - if (a) - { - map_notifies_recv++; - queue_map_notify_for_processing (a); - } - break; - default: - clib_warning ("Unsupported LISP message type %d", type); - break; - } - - b0->error = node->errors[LISP_CP_INPUT_ERROR_DROP]; - - if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) - { - - } - } - - vlib_put_next_frame (vm, node, LISP_CP_INPUT_NEXT_DROP, - n_left_to_next_drop); - } - vlib_node_increment_counter (vm, node->node_index, - LISP_CP_INPUT_ERROR_RLOC_PROBE_REP_RECEIVED, - rloc_probe_rep_recv); - vlib_node_increment_counter (vm, node->node_index, - LISP_CP_INPUT_ERROR_MAP_NOTIFIES_RECEIVED, - map_notifies_recv); - return from_frame->n_vectors; -} - -/* *INDENT-OFF* */ -VLIB_REGISTER_NODE (lisp_cp_input_node) = { - .function = lisp_cp_input, - .name = "lisp-cp-input", - .vector_size = sizeof (u32), - .format_trace = format_lisp_cp_input_trace, - .type = VLIB_NODE_TYPE_INTERNAL, - - .n_errors = LISP_CP_INPUT_N_ERROR, - .error_strings = lisp_cp_input_error_strings, - - .n_next_nodes = LISP_CP_INPUT_N_NEXT, - - .next_nodes = { - [LISP_CP_INPUT_NEXT_DROP] = "error-drop", - }, -}; -/* *INDENT-ON* */ - -clib_error_t * -lisp_cp_init (vlib_main_t * vm) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - clib_error_t *error = 0; - vlib_thread_main_t *vtm = vlib_get_thread_main (); - u32 num_threads; - - if ((error = vlib_call_init_function (vm, lisp_gpe_init))) - return error; - - lcm->im4 = &ip4_main; - lcm->im6 = &ip6_main; - lcm->vlib_main = vm; - lcm->vnet_main = vnet_get_main (); - lcm->mreq_itr_rlocs = ~0; - lcm->flags = 0; - lcm->pitr_map_index = ~0; - lcm->petr_map_index = ~0; - clib_memset (&lcm->active_map_resolver, 0, - sizeof (lcm->active_map_resolver)); - clib_memset (&lcm->active_map_server, 0, sizeof (lcm->active_map_server)); - - gid_dictionary_init (&lcm->mapping_index_by_gid); - lcm->do_map_resolver_election = 1; - lcm->do_map_server_election = 1; - lcm->map_request_mode = MR_MODE_DST_ONLY; - - num_threads = 1 /* main thread */ + vtm->n_threads; - vec_validate (lcm->map_records_args_pool, num_threads - 1); - - /* default vrf mapped to vni 0 */ - hash_set (lcm->table_id_by_vni, 0, 0); - hash_set (lcm->vni_by_table_id, 0, 0); - - TW (tw_timer_wheel_init) (&lcm->wheel, 0 /* no callback */ , - 1e-3 /* timer period 1ms */ , - ~0 /* max expirations per call */ ); - lcm->nsh_map_index = ~0; - lcm->map_register_ttl = MAP_REGISTER_DEFAULT_TTL; - lcm->max_expired_map_registers = MAX_EXPIRED_MAP_REGISTERS_DEFAULT; - lcm->expired_map_registers = 0; - lcm->transport_protocol = LISP_TRANSPORT_PROTOCOL_UDP; - lcm->flags |= LISP_FLAG_XTR_MODE; - return 0; -} - -static int -lisp_stats_api_fill (lisp_cp_main_t * lcm, lisp_gpe_main_t * lgm, - lisp_api_stats_t * stat, lisp_stats_key_t * key, - u32 stats_index) -{ - vlib_counter_t v; - vlib_combined_counter_main_t *cm = &lgm->counters; - lisp_gpe_fwd_entry_key_t fwd_key; - const lisp_gpe_tunnel_t *lgt; - fwd_entry_t *fe; - - clib_memset (stat, 0, sizeof (*stat)); - clib_memset (&fwd_key, 0, sizeof (fwd_key)); - - fe = pool_elt_at_index (lcm->fwd_entry_pool, key->fwd_entry_index); - ASSERT (fe != 0); - - gid_to_dp_address (&fe->reid, &stat->deid); - gid_to_dp_address (&fe->leid, &stat->seid); - stat->vni = gid_address_vni (&fe->reid); - - lgt = lisp_gpe_tunnel_get (key->tunnel_index); - stat->loc_rloc = lgt->key->lcl; - stat->rmt_rloc = lgt->key->rmt; - - vlib_get_combined_counter (cm, stats_index, &v); - stat->counters = v; - return 1; -} - -lisp_api_stats_t * -vnet_lisp_get_stats (void) -{ - lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main (); - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - lisp_api_stats_t *stats = 0, stat; - lisp_stats_key_t *key; - u32 index; - - /* *INDENT-OFF* */ - hash_foreach_mem (key, index, lgm->lisp_stats_index_by_key, - { - if (lisp_stats_api_fill (lcm, lgm, &stat, key, index)) - vec_add1 (stats, stat); - }); - /* *INDENT-ON* */ - - return stats; -} - -static void * -send_map_request_thread_fn (void *arg) -{ - map_request_args_t *a = arg; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - - if (a->is_resend) - resend_encapsulated_map_request (lcm, &a->seid, &a->deid, a->smr_invoked); - else - send_encapsulated_map_request (lcm, &a->seid, &a->deid, a->smr_invoked); - - return 0; -} - -static int -queue_map_request (gid_address_t * seid, gid_address_t * deid, - u8 smr_invoked, u8 is_resend) -{ - map_request_args_t a; - - a.is_resend = is_resend; - gid_address_copy (&a.seid, seid); - gid_address_copy (&a.deid, deid); - a.smr_invoked = smr_invoked; - - vl_api_rpc_call_main_thread (send_map_request_thread_fn, - (u8 *) & a, sizeof (a)); - return 0; -} - -/** - * Take an action with a pending map request depending on expiration time - * and re-try counters. - */ -static void -update_pending_request (pending_map_request_t * r, f64 dt) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - lisp_msmr_t *mr; - - if (r->time_to_expire - dt < 0) - /* it's time to decide what to do with this pending request */ - { - if (r->retries_num >= NUMBER_OF_RETRIES) - /* too many retries -> assume current map resolver is not available */ - { - mr = get_map_resolver (&lcm->active_map_resolver); - if (!mr) - { - clib_warning ("Map resolver %U not found - probably deleted " - "by the user recently.", format_ip_address, - &lcm->active_map_resolver); - } - else - { - clib_warning ("map resolver %U is unreachable, ignoring", - format_ip_address, &lcm->active_map_resolver); - - /* mark current map resolver unavailable so it won't be - * selected next time */ - mr->is_down = 1; - mr->last_update = vlib_time_now (lcm->vlib_main); - } - - reset_pending_mr_counters (r); - elect_map_resolver (lcm); - - /* try to find a next eligible map resolver and re-send */ - queue_map_request (&r->src, &r->dst, r->is_smr_invoked, - 1 /* resend */ ); - } - else - { - /* try again */ - queue_map_request (&r->src, &r->dst, r->is_smr_invoked, - 1 /* resend */ ); - r->retries_num++; - r->time_to_expire = PENDING_MREQ_EXPIRATION_TIME; - } - } - else - r->time_to_expire -= dt; -} - -static void -remove_dead_pending_map_requests (lisp_cp_main_t * lcm) -{ - u64 *nonce; - pending_map_request_t *pmr; - u32 *to_be_removed = 0, *pmr_index; - - /* *INDENT-OFF* */ - pool_foreach (pmr, lcm->pending_map_requests_pool, - ({ - if (pmr->to_be_removed) - { - clib_fifo_foreach (nonce, pmr->nonces, ({ - hash_unset (lcm->pending_map_requests_by_nonce, nonce[0]); - })); - - vec_add1 (to_be_removed, pmr - lcm->pending_map_requests_pool); - } - })); - /* *INDENT-ON* */ - - vec_foreach (pmr_index, to_be_removed) - pool_put_index (lcm->pending_map_requests_pool, pmr_index[0]); - - vec_free (to_be_removed); -} - -static void -update_rloc_probing (lisp_cp_main_t * lcm, f64 dt) -{ - static f64 time_left = RLOC_PROBING_INTERVAL; - - if (!lcm->is_enabled || !lcm->rloc_probing) - return; - - time_left -= dt; - if (time_left <= 0) - { - time_left = RLOC_PROBING_INTERVAL; - send_rloc_probes (lcm); - } -} - -static int -update_pending_map_register (pending_map_register_t * r, f64 dt, u8 * del_all) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - lisp_msmr_t *ms; - del_all[0] = 0; - - r->time_to_expire -= dt; - - if (r->time_to_expire < 0) - { - lcm->expired_map_registers++; - - if (lcm->expired_map_registers >= lcm->max_expired_map_registers) - { - ms = get_map_server (&lcm->active_map_server); - if (!ms) - { - clib_warning ("Map server %U not found - probably deleted " - "by the user recently.", format_ip_address, - &lcm->active_map_server); - } - else - { - clib_warning ("map server %U is unreachable, ignoring", - format_ip_address, &lcm->active_map_server); - - /* mark current map server unavailable so it won't be - * elected next time */ - ms->is_down = 1; - ms->last_update = vlib_time_now (lcm->vlib_main); - } - - elect_map_server (lcm); - - /* indication for deleting all pending map registers */ - del_all[0] = 1; - lcm->expired_map_registers = 0; - return 0; - } - else - { - /* delete pending map register */ - return 0; - } - } - return 1; -} - -static void -update_map_register (lisp_cp_main_t * lcm, f64 dt) -{ - u32 *to_be_removed = 0, *pmr_index; - static f64 time_left = QUICK_MAP_REGISTER_INTERVAL; - static u64 mreg_sent_counter = 0; - - pending_map_register_t *pmr; - u8 del_all = 0; - - if (!lcm->is_enabled || !lcm->map_registering) - return; - - /* *INDENT-OFF* */ - pool_foreach (pmr, lcm->pending_map_registers_pool, - ({ - if (!update_pending_map_register (pmr, dt, &del_all)) - { - if (del_all) - break; - vec_add1 (to_be_removed, pmr - lcm->pending_map_registers_pool); - } - })); - /* *INDENT-ON* */ - - if (del_all) - { - /* delete all pending map register messages so they won't - * trigger another map server election.. */ - pool_free (lcm->pending_map_registers_pool); - hash_free (lcm->map_register_messages_by_nonce); - - /* ..and trigger registration against next map server (if any) */ - time_left = 0; - } - else - { - vec_foreach (pmr_index, to_be_removed) - pool_put_index (lcm->pending_map_registers_pool, pmr_index[0]); - } - - vec_free (to_be_removed); - - time_left -= dt; - if (time_left <= 0) - { - if (mreg_sent_counter >= QUICK_MAP_REGISTER_MSG_COUNT) - time_left = MAP_REGISTER_INTERVAL; - else - { - mreg_sent_counter++; - time_left = QUICK_MAP_REGISTER_INTERVAL; - } - send_map_register (lcm, 1 /* want map notify */ ); - } -} - -static uword -send_map_resolver_service (vlib_main_t * vm, - vlib_node_runtime_t * rt, vlib_frame_t * f) -{ - u32 *expired = 0; - f64 period = 2.0; - pending_map_request_t *pmr; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - - while (1) - { - vlib_process_wait_for_event_or_clock (vm, period); - - /* currently no signals are expected - just wait for clock */ - (void) vlib_process_get_events (vm, 0); - - /* *INDENT-OFF* */ - pool_foreach (pmr, lcm->pending_map_requests_pool, - ({ - if (!pmr->to_be_removed) - update_pending_request (pmr, period); - })); - /* *INDENT-ON* */ - - remove_dead_pending_map_requests (lcm); - - update_map_register (lcm, period); - update_rloc_probing (lcm, period); - - expired = TW (tw_timer_expire_timers_vec) (&lcm->wheel, - vlib_time_now (vm), expired); - if (vec_len (expired) > 0) - { - u32 *mi = 0; - vec_foreach (mi, expired) - { - process_expired_mapping (lcm, mi[0]); - } - _vec_len (expired) = 0; - } - } - - /* unreachable */ - return 0; -} - -vnet_api_error_t -vnet_lisp_stats_enable_disable (u8 enable) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - - if (vnet_lisp_enable_disable_status () == 0) - return VNET_API_ERROR_LISP_DISABLED; - - if (enable) - lcm->flags |= LISP_FLAG_STATS_ENABLED; - else - lcm->flags &= ~LISP_FLAG_STATS_ENABLED; - - return 0; -} - -u8 -vnet_lisp_stats_enable_disable_state (void) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - - if (vnet_lisp_enable_disable_status () == 0) - return VNET_API_ERROR_LISP_DISABLED; - - return lcm->flags & LISP_FLAG_STATS_ENABLED; -} - -void -vnet_lisp_create_retry_process (lisp_cp_main_t * lcm) -{ - if (lcm->retry_service_index) - return; - - lcm->retry_service_index = vlib_process_create (vlib_get_main (), - "lisp-retry-service", - send_map_resolver_service, - 16 /* stack_bytes */ ); -} - -u32 -vnet_lisp_set_transport_protocol (u8 protocol) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - - if (protocol < LISP_TRANSPORT_PROTOCOL_UDP || - protocol > LISP_TRANSPORT_PROTOCOL_API) - return VNET_API_ERROR_INVALID_ARGUMENT; - - lcm->transport_protocol = protocol; - return 0; -} - -lisp_transport_protocol_t -vnet_lisp_get_transport_protocol (void) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - return lcm->transport_protocol; -} - -int -vnet_lisp_enable_disable_xtr_mode (u8 is_enabled) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - u8 pitr_mode = lcm->flags & LISP_FLAG_PITR_MODE; - u8 xtr_mode = lcm->flags & LISP_FLAG_XTR_MODE; - u8 petr_mode = lcm->flags & LISP_FLAG_PETR_MODE; - - if (pitr_mode && is_enabled) - return VNET_API_ERROR_INVALID_ARGUMENT; - - if (is_enabled && xtr_mode) - return 0; - if (!is_enabled && !xtr_mode) - return 0; - - if (is_enabled) - { - if (!petr_mode) - { - lisp_cp_register_dst_port (lcm->vlib_main); - } - lisp_cp_enable_l2_l3_ifaces (lcm, 1 /* with_default_route */ ); - lcm->flags |= LISP_FLAG_XTR_MODE; - } - else - { - if (!petr_mode) - { - lisp_cp_unregister_dst_port (lcm->vlib_main); - } - lisp_cp_disable_l2_l3_ifaces (lcm); - lcm->flags &= ~LISP_FLAG_XTR_MODE; - } - return 0; -} - -int -vnet_lisp_enable_disable_pitr_mode (u8 is_enabled) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - u8 xtr_mode = lcm->flags & LISP_FLAG_XTR_MODE; - u8 pitr_mode = lcm->flags & LISP_FLAG_PITR_MODE; - - if (xtr_mode && is_enabled) - return VNET_API_ERROR_INVALID_VALUE; - - if (is_enabled && pitr_mode) - return 0; - if (!is_enabled && !pitr_mode) - return 0; - - if (is_enabled) - { - /* create iface, no default route */ - lisp_cp_enable_l2_l3_ifaces (lcm, 0 /* with_default_route */ ); - lcm->flags |= LISP_FLAG_PITR_MODE; - } - else - { - lisp_cp_disable_l2_l3_ifaces (lcm); - lcm->flags &= ~LISP_FLAG_PITR_MODE; - } - return 0; -} - -int -vnet_lisp_enable_disable_petr_mode (u8 is_enabled) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - u8 xtr_mode = lcm->flags & LISP_FLAG_XTR_MODE; - u8 petr_mode = lcm->flags & LISP_FLAG_PETR_MODE; - - if (is_enabled && petr_mode) - return 0; - if (!is_enabled && !petr_mode) - return 0; - - if (is_enabled) - { - if (!xtr_mode) - { - lisp_cp_register_dst_port (lcm->vlib_main); - } - lcm->flags |= LISP_FLAG_PETR_MODE; - } - else - { - if (!xtr_mode) - { - lisp_cp_unregister_dst_port (lcm->vlib_main); - } - lcm->flags &= ~LISP_FLAG_PETR_MODE; - } - return 0; -} - -u8 -vnet_lisp_get_xtr_mode (void) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - return (lcm->flags & LISP_FLAG_XTR_MODE); -} - -u8 -vnet_lisp_get_pitr_mode (void) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - return (lcm->flags & LISP_FLAG_PITR_MODE); -} - -u8 -vnet_lisp_get_petr_mode (void) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - return (lcm->flags & LISP_FLAG_PETR_MODE); -} - -VLIB_INIT_FUNCTION (lisp_cp_init); - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/src/vnet/lisp-cp/control.h b/src/vnet/lisp-cp/control.h deleted file mode 100644 index 78d1ffe5e70..00000000000 --- a/src/vnet/lisp-cp/control.h +++ /dev/null @@ -1,448 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef VNET_CONTROL_H_ -#define VNET_CONTROL_H_ - -#include -#include -#include -#include -#include - -#define NUMBER_OF_RETRIES 1 -#define PENDING_MREQ_EXPIRATION_TIME 3.0 /* seconds */ -#define PENDING_MREQ_QUEUE_LEN 5 - -#define RLOC_PROBING_INTERVAL 60.0 - -/* when map-registration is enabled "quick registration" takes place first. - In this mode ETR sends map-register messages at an increased frequency - until specified message count is reached */ -#define QUICK_MAP_REGISTER_MSG_COUNT 5 -#define QUICK_MAP_REGISTER_INTERVAL 3.0 - -/* normal map-register period */ -#define MAP_REGISTER_INTERVAL 60.0 - -/* how many tries until next map-server election */ -#define MAX_EXPIRED_MAP_REGISTERS_DEFAULT 3 - -#define PENDING_MREG_EXPIRATION_TIME 3.0 /* seconds */ - -/* 24 hours */ -#define MAP_REGISTER_DEFAULT_TTL 86400 - -typedef struct -{ - gid_address_t src; - gid_address_t dst; - u32 retries_num; - f64 time_to_expire; - u8 is_smr_invoked; - u64 *nonces; - u8 to_be_removed; -} pending_map_request_t; - -typedef struct -{ - f64 time_to_expire; -} pending_map_register_t; - -typedef struct -{ - gid_address_t leid; - gid_address_t reid; - u8 is_src_dst; - locator_pair_t *locator_pairs; -} fwd_entry_t; - -typedef struct -{ - gid_address_t leid; - gid_address_t reid; -} lisp_adjacency_t; - -typedef enum -{ - IP4_MISS_PACKET, - IP6_MISS_PACKET -} miss_packet_type_t; - -/* map-server/map-resolver structure */ -typedef struct -{ - u8 is_down; - f64 last_update; - ip_address_t address; - char *key; -} lisp_msmr_t; - -typedef struct -{ - /* headers */ - u8 data[100]; - u32 length; - miss_packet_type_t type; -} miss_packet_t; - -typedef struct -{ - u8 mac[6]; - u32 ip4; -} lisp_api_l2_arp_entry_t; - -typedef struct -{ - u8 mac[6]; - u8 ip6[16]; -} lisp_api_ndp_entry_t; - -typedef enum -{ - MR_MODE_DST_ONLY = 0, - MR_MODE_SRC_DST, - _MR_MODE_MAX -} map_request_mode_t; - -#define foreach_lisp_flag_bit \ - _(USE_PETR, "Use Proxy-ETR") \ - _(XTR_MODE, "ITR/ETR mode") \ - _(PETR_MODE, "Proxy-ETR mode") \ - _(PITR_MODE, "Proxy-ITR mode") \ - _(STATS_ENABLED, "Statistics enabled") - -typedef enum lisp_flag_bits -{ -#define _(sym, str) LISP_FLAG_BIT_##sym, - foreach_lisp_flag_bit -#undef _ -} lisp_flag_bits_e; - -typedef enum lisp_flags -{ -#define _(sym, str) LISP_FLAG_##sym = 1 << LISP_FLAG_BIT_##sym, - foreach_lisp_flag_bit -#undef _ -} lisp_flags_e; - -typedef struct -{ - ip_address_t addr; - u32 bd; -} lisp_l2_arp_key_t; - -typedef enum -{ - LISP_TRANSPORT_PROTOCOL_UDP = 1, - LISP_TRANSPORT_PROTOCOL_API -} lisp_transport_protocol_t; - -typedef struct -{ - u64 nonce; - u8 is_rloc_probe; - mapping_t *mappings; - volatile u8 is_free; -} map_records_arg_t; - -typedef struct -{ - u32 flags; - - /* LISP feature status */ - u8 is_enabled; - - /* eid table */ - gid_dictionary_t mapping_index_by_gid; - - /* pool of mappings */ - mapping_t *mapping_pool; - - /* hash map of secret keys by mapping index */ - u8 *key_by_mapping_index; - - /* pool of locators */ - locator_t *locator_pool; - - /* pool of locator-sets */ - locator_set_t *locator_set_pool; - - /* vector of locator-set vectors composed of and indexed by locator index */ - u32 **locator_to_locator_sets; - - /* hash map of locators by name */ - uword *locator_set_index_by_name; - - /* vector of eid index vectors supported and indexed by locator-set index */ - u32 **locator_set_to_eids; - - /* vectors of indexes for local locator-sets and mappings */ - u32 *local_mappings_indexes; - u32 *local_locator_set_indexes; - - /* hash map of forwarding entries by mapping index */ - u32 *fwd_entry_by_mapping_index; - - /* pool of vectors of rmts per lcl mapping in adjacencies */ - u32 **lcl_to_rmt_adjacencies; - - /* hash of pool positions of vectors of rmts by lcl mapping index */ - u32 *lcl_to_rmt_adjs_by_lcl_idx; - - /* forwarding entries pool */ - fwd_entry_t *fwd_entry_pool; - - /* hash map keyed by nonce of pending map-requests */ - uword *pending_map_requests_by_nonce; - - /* pool of pending map requests */ - pending_map_request_t *pending_map_requests_pool; - - /* pool of pending map registers */ - pending_map_register_t *pending_map_registers_pool; - - /* hash map of sent map register messages */ - uword *map_register_messages_by_nonce; - - /* vector of map-resolvers */ - lisp_msmr_t *map_resolvers; - - /* vector of map-servers */ - lisp_msmr_t *map_servers; - - /* map resolver address currently being used for sending requests. - * This has to be an actual address and not an index to map_resolvers vector - * since the vector may be modified during request resend/retry procedure - * and break things :-) */ - ip_address_t active_map_resolver; - ip_address_t active_map_server; - - u8 do_map_resolver_election; - u8 do_map_server_election; - - /* map-request locator set index */ - u32 mreq_itr_rlocs; - - /* vni to vrf hash tables */ - uword *table_id_by_vni; - uword *vni_by_table_id; - - /* vni to bd-index hash tables */ - uword *bd_id_by_vni; - uword *vni_by_bd_id; - - /* track l2 and l3 interfaces that have been created for vni */ - uword *l2_dp_intf_by_vni; - - /* Proxy ITR map index */ - u32 pitr_map_index; - - /** Proxy ETR map index used for 'use-petr'. - * Not related to PETR tunnel mode */ - u32 petr_map_index; - - /* mapping index for NSH */ - u32 nsh_map_index; - - /* map request mode */ - u8 map_request_mode; - - /* enable/disable map registering */ - u8 map_registering; - - /* enable/disable rloc-probing */ - u8 rloc_probing; - - /* timing wheel for mapping timeouts */ - TWT (tw_timer_wheel) wheel; - - /** Per thread pool of records shared with thread0 */ - map_records_arg_t **map_records_args_pool; - - /* TTL used for all mappings when registering */ - u32 map_register_ttl; - - /* control variables for map server election */ - u32 max_expired_map_registers; - u32 expired_map_registers; - - /** either UDP based or binary API. Default is UDP */ - lisp_transport_protocol_t transport_protocol; - - /** Retry service node index */ - u32 retry_service_index; - - /* commodity */ - ip4_main_t *im4; - ip6_main_t *im6; - vlib_main_t *vlib_main; - vnet_main_t *vnet_main; -} lisp_cp_main_t; - -/* lisp-gpe control plane */ -extern lisp_cp_main_t lisp_control_main; - -extern vlib_node_registration_t lisp_cp_input_node; -extern vlib_node_registration_t lisp_cp_lookup_ip4_node; -extern vlib_node_registration_t lisp_cp_lookup_ip6_node; - -clib_error_t *lisp_cp_init (); - -always_inline lisp_cp_main_t * -vnet_lisp_cp_get_main () -{ - return &lisp_control_main; -} - -void -get_src_and_dst_eids_from_buffer (lisp_cp_main_t * lcm, vlib_buffer_t * b, - gid_address_t * src, gid_address_t * dst, - u16 type); - -typedef struct -{ - u8 is_add; - union - { - u8 *name; - u32 index; - }; - locator_t *locators; - u8 local; -} vnet_lisp_add_del_locator_set_args_t; - -int -vnet_lisp_add_del_locator_set (vnet_lisp_add_del_locator_set_args_t * a, - u32 * ls_index); -int -vnet_lisp_add_del_locator (vnet_lisp_add_del_locator_set_args_t * a, - locator_set_t * ls, u32 * ls_index); - -typedef struct -{ - u8 is_add; - gid_address_t eid; - u32 locator_set_index; - - u32 ttl; - u8 action; - u8 authoritative; - - u8 local; - u8 is_static; - u8 *key; - u8 key_id; -} vnet_lisp_add_del_mapping_args_t; - -int -vnet_lisp_map_cache_add_del (vnet_lisp_add_del_mapping_args_t * a, - u32 * map_index); -int -vnet_lisp_add_del_local_mapping (vnet_lisp_add_del_mapping_args_t * a, - u32 * map_index_result); - -int -vnet_lisp_add_mapping (vnet_lisp_add_del_mapping_args_t * a, - locator_t * rlocs, u32 * res_map_index, - u8 * is_changed); - -int vnet_lisp_del_mapping (gid_address_t * eid, u32 * res_map_index); - -typedef struct -{ - gid_address_t reid; - gid_address_t leid; - u8 is_add; -} vnet_lisp_add_del_adjacency_args_t; - -int vnet_lisp_add_del_adjacency (vnet_lisp_add_del_adjacency_args_t * a); - -typedef struct -{ - u8 is_add; - ip_address_t address; -} vnet_lisp_add_del_map_resolver_args_t; - -int -vnet_lisp_add_del_map_resolver (vnet_lisp_add_del_map_resolver_args_t * a); -int vnet_lisp_add_del_map_server (ip_address_t * addr, u8 is_add); - -clib_error_t *vnet_lisp_enable_disable (u8 is_enabled); -u8 vnet_lisp_enable_disable_status (void); -void vnet_lisp_create_retry_process (lisp_cp_main_t * lcm); - -int vnet_lisp_pitr_set_locator_set (u8 * locator_set_name, u8 is_add); -int vnet_lisp_use_petr (ip_address_t * ip, u8 is_add); - -typedef struct -{ - u8 is_add; - u8 *locator_set_name; -} vnet_lisp_add_del_mreq_itr_rloc_args_t; - -int -vnet_lisp_add_del_mreq_itr_rlocs (vnet_lisp_add_del_mreq_itr_rloc_args_t * a); - -int vnet_lisp_clear_all_remote_adjacencies (void); - -int vnet_lisp_eid_table_map (u32 vni, u32 vrf, u8 is_l2, u8 is_add); -int vnet_lisp_add_del_map_table_key (gid_address_t * eid, char *key, - u8 is_add); -int vnet_lisp_set_map_request_mode (u8 mode); -u8 vnet_lisp_get_map_request_mode (void); -lisp_adjacency_t *vnet_lisp_adjacencies_get_by_vni (u32 vni); -int vnet_lisp_rloc_probe_enable_disable (u8 is_enable); -int vnet_lisp_map_register_enable_disable (u8 is_enable); -u8 vnet_lisp_map_register_state_get (void); -u8 vnet_lisp_rloc_probe_state_get (void); -int vnet_lisp_add_del_l2_arp_ndp_entry (gid_address_t * key, u8 * mac, - u8 is_add); -u32 *vnet_lisp_l2_arp_bds_get (void); -lisp_api_l2_arp_entry_t *vnet_lisp_l2_arp_entries_get_by_bd (u32 bd); -int vnet_lisp_nsh_set_locator_set (u8 * locator_set_name, u8 is_add); -int vnet_lisp_map_register_set_ttl (u32 ttl); -u32 vnet_lisp_map_register_get_ttl (void); -int vnet_lisp_map_register_fallback_threshold_set (u32 value); -u32 vnet_lisp_map_register_fallback_threshold_get (void); -u32 *vnet_lisp_ndp_bds_get (void); -lisp_api_ndp_entry_t *vnet_lisp_ndp_entries_get_by_bd (u32 bd); -u32 vnet_lisp_set_transport_protocol (u8 protocol); -lisp_transport_protocol_t vnet_lisp_get_transport_protocol (void); - -extern int vnet_lisp_enable_disable_xtr_mode (u8 is_enabled); -extern int vnet_lisp_enable_disable_pitr_mode (u8 is_enabled); -extern int vnet_lisp_enable_disable_petr_mode (u8 is_enabled); -extern u8 vnet_lisp_get_xtr_mode (void); -extern u8 vnet_lisp_get_pitr_mode (void); -extern u8 vnet_lisp_get_petr_mode (void); - -map_records_arg_t *parse_map_reply (vlib_buffer_t * b); - -always_inline mapping_t * -lisp_get_petr_mapping (lisp_cp_main_t * lcm) -{ - return pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index); -} - -#endif /* VNET_CONTROL_H_ */ - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/src/vnet/lisp-cp/gid_dictionary.c b/src/vnet/lisp-cp/gid_dictionary.c deleted file mode 100644 index 564ee8ea84d..00000000000 --- a/src/vnet/lisp-cp/gid_dictionary.c +++ /dev/null @@ -1,1077 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -typedef struct -{ - void *arg; - ip_prefix_t src; - foreach_subprefix_match_cb_t cb; - union - { - gid_ip4_table_t *ip4_table; - gid_ip6_table_t *ip6_table; - }; -} sfib_entry_arg_t; - -static u32 ip4_lookup (gid_ip4_table_t * db, u32 vni, ip_prefix_t * key); - -static u32 ip6_lookup (gid_ip6_table_t * db, u32 vni, ip_prefix_t * key); - -static int -foreach_sfib4_subprefix (BVT (clib_bihash_kv) * kvp, void *arg) -{ - sfib_entry_arg_t *a = arg; - u32 ip = (u32) kvp->key[0]; - ip4_address_t *mask; - u8 plen = ip_prefix_len (&a->src); - - ASSERT (plen <= 32); - mask = &a->ip4_table->ip4_fib_masks[plen]; - - u32 src_ip = ip_prefix_v4 (&a->src).as_u32; - src_ip &= mask->as_u32; - ip &= mask->as_u32; - - if (src_ip == ip) - { - /* found sub-prefix of src prefix */ - (a->cb) (kvp->value, a->arg); - } - return (BIHASH_WALK_CONTINUE); -} - -static void -gid_dict_foreach_ip4_subprefix (gid_dictionary_t * db, u32 vni, - ip_prefix_t * src, ip_prefix_t * dst, - foreach_subprefix_match_cb_t cb, void *arg) -{ - u32 sfi; - gid_ip4_table_t *sfib4; - sfib_entry_arg_t a; - - sfi = ip4_lookup (&db->dst_ip4_table, vni, dst); - if (GID_LOOKUP_MISS == sfi) - return; - - sfib4 = pool_elt_at_index (db->src_ip4_table_pool, sfi); - - a.arg = arg; - a.cb = cb; - a.src = src[0]; - a.ip4_table = sfib4; - - BV (clib_bihash_foreach_key_value_pair) (&sfib4->ip4_lookup_table, - foreach_sfib4_subprefix, &a); -} - -static int -foreach_sfib6_subprefix (BVT (clib_bihash_kv) * kvp, void *arg) -{ - sfib_entry_arg_t *a = arg; - ip6_address_t ip; - ip6_address_t *mask; - u8 plen = ip_prefix_len (&a->src); - - mask = &a->ip6_table->ip6_fib_masks[plen]; - ip.as_u64[0] = kvp->key[0]; - ip.as_u64[1] = kvp->key[1]; - - if (ip6_address_is_equal_masked (&ip_prefix_v6 (&a->src), &ip, mask)) - { - /* found sub-prefix of src prefix */ - (a->cb) (kvp->value, a->arg); - } - return (BIHASH_WALK_CONTINUE); -} - -static void -gid_dict_foreach_ip6_subprefix (gid_dictionary_t * db, u32 vni, - ip_prefix_t * src, ip_prefix_t * dst, - foreach_subprefix_match_cb_t cb, void *arg) -{ - u32 sfi; - gid_ip6_table_t *sfib6; - sfib_entry_arg_t a; - - sfi = ip6_lookup (&db->dst_ip6_table, vni, dst); - if (GID_LOOKUP_MISS == sfi) - return; - - sfib6 = pool_elt_at_index (db->src_ip6_table_pool, sfi); - - a.arg = arg; - a.cb = cb; - a.src = src[0]; - a.ip6_table = sfib6; - - BV (clib_bihash_foreach_key_value_pair) (&sfib6->ip6_lookup_table, - foreach_sfib6_subprefix, &a); -} - -void -gid_dict_foreach_subprefix (gid_dictionary_t * db, gid_address_t * eid, - foreach_subprefix_match_cb_t cb, void *arg) -{ - ip_prefix_t *ippref = &gid_address_sd_dst_ippref (eid); - - if (AF_IP4 == ip_prefix_version (ippref)) - gid_dict_foreach_ip4_subprefix (db, gid_address_vni (eid), - &gid_address_sd_src_ippref (eid), - &gid_address_sd_dst_ippref (eid), cb, - arg); - else - gid_dict_foreach_ip6_subprefix (db, gid_address_vni (eid), - &gid_address_sd_src_ippref (eid), - &gid_address_sd_dst_ippref (eid), cb, - arg); -} - -void -gid_dict_foreach_l2_arp_ndp_entry (gid_dictionary_t * db, - BV (clib_bihash_foreach_key_value_pair_cb) - cb, void *ht) -{ - gid_l2_arp_ndp_table_t *tab = &db->arp_ndp_table; - BV (clib_bihash_foreach_key_value_pair) (&tab->arp_ndp_lookup_table, cb, - ht); -} - -static void -make_mac_sd_key (BVT (clib_bihash_kv) * kv, u32 vni, u8 src_mac[6], - u8 dst_mac[6]) -{ - kv->key[0] = (u64) vni; - kv->key[1] = mac_to_u64 (dst_mac); - kv->key[2] = src_mac ? mac_to_u64 (src_mac) : (u64) 0; -} - -static u32 -mac_sd_lookup (gid_mac_table_t * db, u32 vni, u8 * dst, u8 * src) -{ - int rv; - BVT (clib_bihash_kv) kv, value; - - make_mac_sd_key (&kv, vni, src, dst); - rv = BV (clib_bihash_search_inline_2) (&db->mac_lookup_table, &kv, &value); - - /* no match, try with src 0, catch all for dst */ - if (rv != 0) - { - kv.key[2] = 0; - rv = BV (clib_bihash_search_inline_2) (&db->mac_lookup_table, &kv, - &value); - if (rv == 0) - return value.value; - } - else - return value.value; - - return GID_LOOKUP_MISS; -} - -static u32 -ip4_lookup_exact_match (gid_ip4_table_t * db, u32 vni, ip_prefix_t * key) -{ - int rv; - BVT (clib_bihash_kv) kv, value; - - ip4_address_t *mask; - - mask = &db->ip4_fib_masks[ip_prefix_len (key)]; - - kv.key[0] = ((u64) vni << 32) | (ip_prefix_v4 (key).as_u32 & mask->as_u32); - kv.key[1] = 0; - kv.key[2] = 0; - - rv = BV (clib_bihash_search_inline_2) (&db->ip4_lookup_table, &kv, &value); - if (rv == 0) - return value.value; - - return GID_LOOKUP_MISS; -} - -static u32 -ip4_lookup (gid_ip4_table_t * db, u32 vni, ip_prefix_t * key) -{ - int i, len; - int rv; - BVT (clib_bihash_kv) kv, value; - - len = vec_len (db->ip4_prefix_lengths_in_search_order); - - for (i = 0; i < len; i++) - { - int dst_address_length = db->ip4_prefix_lengths_in_search_order[i]; - ip4_address_t *mask; - - ASSERT (dst_address_length >= 0 && dst_address_length <= 32); - - mask = &db->ip4_fib_masks[dst_address_length]; - - kv.key[0] = - ((u64) vni << 32) | (ip_prefix_v4 (key).as_u32 & mask->as_u32); - kv.key[1] = 0; - kv.key[2] = 0; - - rv = - BV (clib_bihash_search_inline_2) (&db->ip4_lookup_table, &kv, &value); - if (rv == 0) - return value.value; - } - - return GID_LOOKUP_MISS; -} - -static u32 -ip6_lookup_exact_match (gid_ip6_table_t * db, u32 vni, ip_prefix_t * key) -{ - int rv; - BVT (clib_bihash_kv) kv, value; - - ip6_address_t *mask; - mask = &db->ip6_fib_masks[ip_prefix_len (key)]; - - kv.key[0] = ip_prefix_v6 (key).as_u64[0] & mask->as_u64[0]; - kv.key[1] = ip_prefix_v6 (key).as_u64[1] & mask->as_u64[1]; - kv.key[2] = (u64) vni; - - rv = BV (clib_bihash_search_inline_2) (&db->ip6_lookup_table, &kv, &value); - if (rv == 0) - return value.value; - - return GID_LOOKUP_MISS; -} - -static u32 -ip6_lookup (gid_ip6_table_t * db, u32 vni, ip_prefix_t * key) -{ - int i, len; - int rv; - BVT (clib_bihash_kv) kv, value; - - len = vec_len (db->ip6_prefix_lengths_in_search_order); - - for (i = 0; i < len; i++) - { - int dst_address_length = db->ip6_prefix_lengths_in_search_order[i]; - ip6_address_t *mask; - - ASSERT (dst_address_length >= 0 && dst_address_length <= 128); - - mask = &db->ip6_fib_masks[dst_address_length]; - - kv.key[0] = ip_prefix_v6 (key).as_u64[0] & mask->as_u64[0]; - kv.key[1] = ip_prefix_v6 (key).as_u64[1] & mask->as_u64[1]; - kv.key[2] = (u64) vni; - - rv = - BV (clib_bihash_search_inline_2) (&db->ip6_lookup_table, &kv, &value); - if (rv == 0) - return value.value; - } - - return GID_LOOKUP_MISS; -} - -static u32 -ip_sd_lookup (gid_dictionary_t * db, u32 vni, ip_prefix_t * dst, - ip_prefix_t * src) -{ - u32 sfi; - gid_ip4_table_t *sfib4; - gid_ip6_table_t *sfib6; - - switch (ip_prefix_version (dst)) - { - case AF_IP4: - sfi = ip4_lookup (&db->dst_ip4_table, vni, dst); - if (GID_LOOKUP_MISS != sfi) - sfib4 = pool_elt_at_index (db->src_ip4_table_pool, sfi); - else - return GID_LOOKUP_MISS; - - if (!src) - { - ip_prefix_t sp; - clib_memset (&sp, 0, sizeof (sp)); - return ip4_lookup_exact_match (sfib4, 0, &sp); - } - else - return ip4_lookup (sfib4, 0, src); - - break; - case AF_IP6: - sfi = ip6_lookup (&db->dst_ip6_table, vni, dst); - if (GID_LOOKUP_MISS != sfi) - sfib6 = pool_elt_at_index (db->src_ip6_table_pool, sfi); - else - return GID_LOOKUP_MISS; - - if (!src) - { - ip_prefix_t sp; - clib_memset (&sp, 0, sizeof (sp)); - ip_prefix_version (&sp) = AF_IP6; - return ip6_lookup_exact_match (sfib6, 0, &sp); - } - else - return ip6_lookup (sfib6, 0, src); - - break; - default: - clib_warning ("address type %d not supported!", - ip_prefix_version (dst)); - break; - } - return GID_LOOKUP_MISS; -} - -static void -make_arp_ndp_key (BVT (clib_bihash_kv) * kv, u32 bd, ip_address_t * addr) -{ - kv->key[0] = ((u64) bd << 32) | (u32) ip_addr_version (addr); - if (ip_addr_version (addr) == AF_IP4) - { - kv->key[1] = (u64) ip_addr_v4 (addr).as_u32; - kv->key[2] = (u64) 0; - } - else - { - kv->key[1] = (u64) ip_addr_v6 (addr).as_u64[0]; - kv->key[2] = (u64) ip_addr_v6 (addr).as_u64[1]; - } -} - -static void -make_nsh_key (BVT (clib_bihash_kv) * kv, u32 vni, u32 spi, u8 si) -{ - kv->key[0] = (u64) vni; - kv->key[1] = (u64) spi; - kv->key[2] = (u64) si; -} - -static u64 -arp_ndp_lookup (gid_l2_arp_ndp_table_t * db, u32 bd, ip_address_t * key) -{ - int rv; - BVT (clib_bihash_kv) kv, value; - - make_arp_ndp_key (&kv, bd, key); - rv = BV (clib_bihash_search_inline_2) (&db->arp_ndp_lookup_table, &kv, - &value); - - if (rv == 0) - return value.value; - - return GID_LOOKUP_MISS_L2; -} - -static u32 -nsh_lookup (gid_nsh_table_t * db, u32 vni, u32 spi, u8 si) -{ - int rv; - BVT (clib_bihash_kv) kv, value; - - make_nsh_key (&kv, vni, spi, si); - rv = BV (clib_bihash_search_inline_2) (&db->nsh_lookup_table, &kv, &value); - - if (rv == 0) - return value.value; - - return GID_LOOKUP_MISS; -} - -u64 -gid_dictionary_lookup (gid_dictionary_t * db, gid_address_t * key) -{ - switch (gid_address_type (key)) - { - case GID_ADDR_IP_PREFIX: - return ip_sd_lookup (db, gid_address_vni (key), - &gid_address_ippref (key), 0); - case GID_ADDR_MAC: - return mac_sd_lookup (&db->sd_mac_table, gid_address_vni (key), - gid_address_mac (key), 0); - case GID_ADDR_SRC_DST: - switch (gid_address_sd_dst_type (key)) - { - case FID_ADDR_IP_PREF: - return ip_sd_lookup (db, gid_address_vni (key), - &gid_address_sd_dst_ippref (key), - &gid_address_sd_src_ippref (key)); - break; - case FID_ADDR_MAC: - return mac_sd_lookup (&db->sd_mac_table, gid_address_vni (key), - gid_address_sd_dst_mac (key), - gid_address_sd_src_mac (key)); - break; - default: - clib_warning ("Source/Dest address type %d not supported!", - gid_address_sd_dst_type (key)); - break; - } - break; - case GID_ADDR_ARP: - case GID_ADDR_NDP: - return arp_ndp_lookup (&db->arp_ndp_table, gid_address_arp_ndp_bd (key), - &gid_address_arp_ndp_ip (key)); - case GID_ADDR_NSH: - return nsh_lookup (&db->nsh_table, gid_address_vni (key), - gid_address_nsh_spi (key), gid_address_nsh_si (key)); - default: - clib_warning ("address type %d not supported!", gid_address_type (key)); - break; - } - return GID_LOOKUP_MISS; -} - -u32 -gid_dictionary_sd_lookup (gid_dictionary_t * db, gid_address_t * dst, - gid_address_t * src) -{ - switch (gid_address_type (dst)) - { - case GID_ADDR_IP_PREFIX: - return ip_sd_lookup (db, gid_address_vni (dst), - &gid_address_ippref (dst), - &gid_address_ippref (src)); - case GID_ADDR_MAC: - return mac_sd_lookup (&db->sd_mac_table, gid_address_vni (dst), - gid_address_mac (dst), gid_address_mac (src)); - case GID_ADDR_SRC_DST: - switch (gid_address_sd_dst_type (dst)) - { - case FID_ADDR_IP_PREF: - return ip_sd_lookup (db, gid_address_vni (dst), - &gid_address_sd_dst_ippref (dst), - &gid_address_sd_src_ippref (dst)); - break; - case FID_ADDR_MAC: - return mac_sd_lookup (&db->sd_mac_table, gid_address_vni (dst), - gid_address_sd_dst_mac (dst), - gid_address_sd_src_mac (dst)); - break; - default: - clib_warning ("Source/Dest address type %d not supported!", - gid_address_sd_dst_type (dst)); - break; - } - break; - case GID_ADDR_NSH: - return gid_dictionary_lookup (db, dst); - break; - default: - clib_warning ("address type %d not supported!", gid_address_type (dst)); - break; - } - return GID_LOOKUP_MISS; -} - -static void -ip4_compute_prefix_lengths_in_search_order (gid_ip4_table_t * db) -{ - int i; - vec_reset_length (db->ip4_prefix_lengths_in_search_order); - /* Note: bitmap reversed so this is in fact a longest prefix match */ - - /* *INDENT-OFF* */ - clib_bitmap_foreach (i, db->ip4_non_empty_dst_address_length_bitmap, - ({ - int dst_address_length = 32 - i; - vec_add1 (db->ip4_prefix_lengths_in_search_order, dst_address_length); - })); - /* *INDENT-ON* */ - -} - -static u32 -add_del_ip4_key (gid_ip4_table_t * db, u32 vni, ip_prefix_t * pref, u32 val, - u8 is_add) -{ - BVT (clib_bihash_kv) kv, value; - u32 old_val = ~0; - ip4_address_t key; - u8 plen = ip_prefix_len (pref); - - clib_memcpy (&key, &ip_prefix_v4 (pref), sizeof (key)); - key.as_u32 &= db->ip4_fib_masks[plen].as_u32; - if (is_add) - { - db->ip4_non_empty_dst_address_length_bitmap = - clib_bitmap_set (db->ip4_non_empty_dst_address_length_bitmap, - 32 - plen, 1); - ip4_compute_prefix_lengths_in_search_order (db); - - db->ip4_prefix_len_refcount[plen]++; - } - else - { - ASSERT (db->ip4_prefix_len_refcount[plen] != 0); - - db->ip4_prefix_len_refcount[plen]--; - - if (db->ip4_prefix_len_refcount[plen] == 0) - { - db->ip4_non_empty_dst_address_length_bitmap = - clib_bitmap_set (db->ip4_non_empty_dst_address_length_bitmap, - 32 - plen, 0); - ip4_compute_prefix_lengths_in_search_order (db); - } - } - - kv.key[0] = ((u64) vni << 32) | key.as_u32; - kv.key[1] = 0; - kv.key[2] = 0; - - if (BV (clib_bihash_search) (&db->ip4_lookup_table, &kv, &value) == 0) - old_val = value.value; - - if (!is_add) - { - BV (clib_bihash_add_del) (&db->ip4_lookup_table, &kv, 0 /* is_add */ ); - db->count--; - } - else - { - kv.value = val; - BV (clib_bihash_add_del) (&db->ip4_lookup_table, &kv, 1 /* is_add */ ); - db->count++; - } - return old_val; -} - -static void -ip4_lookup_init (gid_ip4_table_t * db) -{ - BVT (clib_bihash_init2_args) _a, *a = &_a; - uword i; - - clib_memset (db->ip4_prefix_len_refcount, 0, - sizeof (db->ip4_prefix_len_refcount)); - - for (i = 0; i < ARRAY_LEN (db->ip4_fib_masks); i++) - { - u32 m; - - if (i < 32) - m = pow2_mask (i) << (32 - i); - else - m = ~0; - db->ip4_fib_masks[i].as_u32 = clib_host_to_net_u32 (m); - } - if (db->ip4_lookup_table_nbuckets == 0) - db->ip4_lookup_table_nbuckets = IP4_LOOKUP_DEFAULT_HASH_NUM_BUCKETS; - - db->ip4_lookup_table_nbuckets = - 1 << max_log2 (db->ip4_lookup_table_nbuckets); - - if (db->ip4_lookup_table_size == 0) - db->ip4_lookup_table_size = IP4_LOOKUP_DEFAULT_HASH_MEMORY_SIZE; - - /* - * Danger Will Robinson, Danger! gid_ip4_table_t's are allocated from - * a pool. They MUST NOT be listed on the clib_all_bihashes list... - */ - memset (a, 0, sizeof (*a)); - a->h = &db->ip4_lookup_table; - a->name = "LISP ip4 lookup table"; - a->nbuckets = db->ip4_lookup_table_nbuckets; - a->memory_size = db->ip4_lookup_table_size; - a->dont_add_to_all_bihash_list = 1; /* See comment above */ - - BV (clib_bihash_init2) (a); -} - -static u32 -add_del_sd_ip4_key (gid_dictionary_t * db, u32 vni, ip_prefix_t * dst_pref, - ip_prefix_t * src_pref, u32 val, u8 is_add) -{ - u32 sfi, old_val = ~0; - gid_ip4_table_t *sfib; - - sfi = ip4_lookup_exact_match (&db->dst_ip4_table, vni, dst_pref); - - if (is_add) - { - if (GID_LOOKUP_MISS == sfi) - { - pool_get (db->src_ip4_table_pool, sfib); - ip4_lookup_init (sfib); - add_del_ip4_key (&db->dst_ip4_table, vni, dst_pref, - sfib - db->src_ip4_table_pool, is_add); - if (src_pref) - add_del_ip4_key (sfib, 0 /* vni */ , src_pref, val, is_add); - else - { - ip_prefix_t sp; - clib_memset (&sp, 0, sizeof (sp)); - add_del_ip4_key (sfib, 0 /* vni */ , &sp, val, is_add); - } - } - else - { - ASSERT (!pool_is_free_index (db->src_ip4_table_pool, sfi)); - sfib = pool_elt_at_index (db->src_ip4_table_pool, sfi); - if (src_pref) - { - old_val = ip4_lookup_exact_match (sfib, 0, src_pref); - add_del_ip4_key (sfib, 0 /* vni */ , src_pref, val, is_add); - } - else - { - ip_prefix_t sp; - clib_memset (&sp, 0, sizeof (sp)); - old_val = - add_del_ip4_key (sfib, 0 /* vni */ , &sp, val, is_add); - } - } - } - else - { - if (GID_LOOKUP_MISS != sfi) - { - sfib = pool_elt_at_index (db->src_ip4_table_pool, sfi); - if (src_pref) - old_val = add_del_ip4_key (sfib, 0, src_pref, 0, is_add); - else - { - ip_prefix_t sp; - clib_memset (&sp, 0, sizeof (sp)); - old_val = add_del_ip4_key (sfib, 0, &sp, 0, is_add); - } - - if (sfib->count == 0) - add_del_ip4_key (&db->dst_ip4_table, vni, dst_pref, 0, is_add); - } - else - clib_warning ("cannot delete dst mapping %U!", format_ip_prefix, - dst_pref); - } - return old_val; -} - -static void -ip6_compute_prefix_lengths_in_search_order (gid_ip6_table_t * db) -{ - int i; - vec_reset_length (db->ip6_prefix_lengths_in_search_order); - /* Note: bitmap reversed so this is in fact a longest prefix match */ - - /* *INDENT-OFF* */ - clib_bitmap_foreach (i, db->ip6_non_empty_dst_address_length_bitmap, - ({ - int dst_address_length = 128 - i; - vec_add1 (db->ip6_prefix_lengths_in_search_order, dst_address_length); - })); - /* *INDENT-ON* */ -} - -static u32 -add_del_ip6_key (gid_ip6_table_t * db, u32 vni, ip_prefix_t * pref, u32 val, - u8 is_add) -{ - BVT (clib_bihash_kv) kv, value; - u32 old_val = ~0; - ip6_address_t key; - u8 plen = ip_prefix_len (pref); - - clib_memcpy (&key, &ip_prefix_v6 (pref), sizeof (key)); - ip6_address_mask (&key, &db->ip6_fib_masks[plen]); - if (is_add) - { - db->ip6_non_empty_dst_address_length_bitmap = - clib_bitmap_set (db->ip6_non_empty_dst_address_length_bitmap, - 128 - plen, 1); - ip6_compute_prefix_lengths_in_search_order (db); - db->ip6_prefix_len_refcount[plen]++; - } - else - { - ASSERT (db->ip6_prefix_len_refcount[plen] != 0); - - db->ip6_prefix_len_refcount[plen]--; - - if (db->ip6_prefix_len_refcount[plen] == 0) - { - db->ip6_non_empty_dst_address_length_bitmap = - clib_bitmap_set (db->ip6_non_empty_dst_address_length_bitmap, - 128 - plen, 0); - ip6_compute_prefix_lengths_in_search_order (db); - } - } - - kv.key[0] = key.as_u64[0]; - kv.key[1] = key.as_u64[1]; - kv.key[2] = (u64) vni; -// kv.key[2] = ((u64)((fib - im->fibs))<<32) | ip_prefix_len(key); - - if (BV (clib_bihash_search) (&db->ip6_lookup_table, &kv, &value) == 0) - old_val = value.value; - - if (!is_add) - { - BV (clib_bihash_add_del) (&db->ip6_lookup_table, &kv, 0 /* is_add */ ); - db->count--; - } - else - { - kv.value = val; - BV (clib_bihash_add_del) (&db->ip6_lookup_table, &kv, 1 /* is_add */ ); - db->count++; - } - return old_val; -} - -static u32 -add_del_mac (gid_mac_table_t * db, u32 vni, u8 * dst_mac, u8 * src_mac, - u32 val, u8 is_add) -{ - BVT (clib_bihash_kv) kv, value; - u32 old_val = ~0; - - make_mac_sd_key (&kv, vni, src_mac, dst_mac); - - if (BV (clib_bihash_search) (&db->mac_lookup_table, &kv, &value) == 0) - old_val = value.value; - - if (!is_add) - { - BV (clib_bihash_add_del) (&db->mac_lookup_table, &kv, 0 /* is_add */ ); - db->count--; - } - else - { - kv.value = val; - BV (clib_bihash_add_del) (&db->mac_lookup_table, &kv, 1 /* is_add */ ); - db->count++; - } - return old_val; -} - -static void -ip6_lookup_init (gid_ip6_table_t * db) -{ - uword i; - BVT (clib_bihash_init2_args) _a, *a = &_a; - - clib_memset (db->ip6_prefix_len_refcount, 0, - sizeof (db->ip6_prefix_len_refcount)); - - for (i = 0; i < ARRAY_LEN (db->ip6_fib_masks); i++) - { - u32 j, i0, i1; - - i0 = i / 32; - i1 = i % 32; - - for (j = 0; j < i0; j++) - db->ip6_fib_masks[i].as_u32[j] = ~0; - - if (i1) - db->ip6_fib_masks[i].as_u32[i0] = - clib_host_to_net_u32 (pow2_mask (i1) << (32 - i1)); - } - - if (db->ip6_lookup_table_nbuckets == 0) - db->ip6_lookup_table_nbuckets = IP6_LOOKUP_DEFAULT_HASH_NUM_BUCKETS; - - db->ip6_lookup_table_nbuckets = - 1 << max_log2 (db->ip6_lookup_table_nbuckets); - - if (db->ip6_lookup_table_size == 0) - db->ip6_lookup_table_size = IP6_LOOKUP_DEFAULT_HASH_MEMORY_SIZE; - - /* - * Danger Will Robinson, Danger! gid_ip6_table_t's are allocated from - * a pool. They MUST NOT be listed on the clib_all_bihashes list... - */ - memset (a, 0, sizeof (*a)); - a->h = &db->ip6_lookup_table; - a->name = "LISP ip6 lookup table"; - a->nbuckets = db->ip6_lookup_table_nbuckets; - a->memory_size = db->ip6_lookup_table_size; - a->dont_add_to_all_bihash_list = 1; /* See comment above */ - - BV (clib_bihash_init2) (a); -} - -static u32 -add_del_sd_ip6_key (gid_dictionary_t * db, u32 vni, ip_prefix_t * dst_pref, - ip_prefix_t * src_pref, u32 val, u8 is_add) -{ - u32 sfi, old_val = ~0; - gid_ip6_table_t *sfib; - - sfi = ip6_lookup_exact_match (&db->dst_ip6_table, vni, dst_pref); - - if (is_add) - { - if (GID_LOOKUP_MISS == sfi) - { - pool_get (db->src_ip6_table_pool, sfib); - ip6_lookup_init (sfib); - add_del_ip6_key (&db->dst_ip6_table, vni, dst_pref, - sfib - db->src_ip6_table_pool, is_add); - if (src_pref) - add_del_ip6_key (sfib, 0 /* vni */ , src_pref, val, is_add); - else - { - ip_prefix_t sp; - clib_memset (&sp, 0, sizeof (sp)); - ip_prefix_version (&sp) = AF_IP6; - add_del_ip6_key (sfib, 0 /* vni */ , &sp, val, is_add); - } - } - else - { - ASSERT (!pool_is_free_index (db->src_ip6_table_pool, sfi)); - sfib = pool_elt_at_index (db->src_ip6_table_pool, sfi); - if (src_pref) - { - old_val = ip6_lookup_exact_match (sfib, 0, src_pref); - add_del_ip6_key (sfib, 0 /* vni */ , src_pref, val, is_add); - } - else - { - ip_prefix_t sp; - clib_memset (&sp, 0, sizeof (sp)); - ip_prefix_version (&sp) = AF_IP6; - old_val = - add_del_ip6_key (sfib, 0 /* vni */ , &sp, val, is_add); - } - } - } - else - { - if (GID_LOOKUP_MISS != sfi) - { - sfib = pool_elt_at_index (db->src_ip6_table_pool, sfi); - if (src_pref) - old_val = add_del_ip6_key (sfib, 0, src_pref, 0, is_add); - else - { - ip_prefix_t sp; - clib_memset (&sp, 0, sizeof (sp)); - ip_prefix_version (&sp) = AF_IP6; - old_val = add_del_ip6_key (sfib, 0, &sp, 0, is_add); - } - - if (sfib->count == 0) - add_del_ip6_key (&db->dst_ip6_table, vni, dst_pref, 0, is_add); - } - else - clib_warning ("cannot delete dst mapping %U!", format_ip_prefix, - dst_pref); - } - return old_val; -} - -static u32 -add_del_ip (gid_dictionary_t * db, u32 vni, ip_prefix_t * dst_key, - ip_prefix_t * src_key, u32 value, u8 is_add) -{ - switch (ip_prefix_version (dst_key)) - { - case AF_IP4: - return add_del_sd_ip4_key (db, vni, dst_key, src_key, value, is_add); - break; - case AF_IP6: - return add_del_sd_ip6_key (db, vni, dst_key, src_key, value, is_add); - break; - default: - clib_warning ("address type %d not supported!", - ip_prefix_version (dst_key)); - break; - } - return ~0; -} - -static u32 -add_del_sd (gid_dictionary_t * db, u32 vni, source_dest_t * key, u32 value, - u8 is_add) -{ - switch (sd_dst_type (key)) - { - case FID_ADDR_IP_PREF: - add_del_ip (db, vni, &sd_dst_ippref (key), &sd_src_ippref (key), - value, is_add); - - case FID_ADDR_MAC: - return add_del_mac (&db->sd_mac_table, vni, sd_dst_mac (key), - sd_src_mac (key), value, is_add); - - default: - clib_warning ("SD address type %d not supported!", sd_dst_type (key)); - break; - } - - return ~0; -} - -static u64 -add_del_arp_ndp (gid_l2_arp_ndp_table_t * db, u32 bd, ip_address_t * key, - u64 value, u8 is_add) -{ - BVT (clib_bihash_kv) kv, result; - u32 old_val = ~0; - - make_arp_ndp_key (&kv, bd, key); - if (BV (clib_bihash_search) (&db->arp_ndp_lookup_table, &kv, &result) == 0) - old_val = result.value; - - if (is_add) - { - kv.value = value; - BV (clib_bihash_add_del) (&db->arp_ndp_lookup_table, &kv, - 1 /* is_add */ ); - db->count++; - } - else - { - BV (clib_bihash_add_del) (&db->arp_ndp_lookup_table, &kv, - 0 /* is_add */ ); - db->count--; - } - return old_val; -} - -static u32 -add_del_nsh (gid_nsh_table_t * db, u32 vni, u32 spi, u8 si, u32 value, - u8 is_add) -{ - BVT (clib_bihash_kv) kv, result; - u32 old_val = ~0; - - make_nsh_key (&kv, vni, spi, si); - if (BV (clib_bihash_search) (&db->nsh_lookup_table, &kv, &result) == 0) - old_val = result.value; - - if (is_add) - { - kv.value = value; - BV (clib_bihash_add_del) (&db->nsh_lookup_table, &kv, 1 /* is_add */ ); - db->count++; - } - else - { - BV (clib_bihash_add_del) (&db->nsh_lookup_table, &kv, 0 /* is_add */ ); - db->count--; - } - return old_val; -} - -u32 -gid_dictionary_add_del (gid_dictionary_t * db, gid_address_t * key, u64 value, - u8 is_add) -{ - switch (gid_address_type (key)) - { - case GID_ADDR_IP_PREFIX: - return add_del_ip (db, gid_address_vni (key), &gid_address_ippref (key), - 0, (u32) value, is_add); - case GID_ADDR_MAC: - return add_del_mac (&db->sd_mac_table, gid_address_vni (key), - gid_address_mac (key), 0, (u32) value, is_add); - case GID_ADDR_SRC_DST: - return add_del_sd (db, gid_address_vni (key), &gid_address_sd (key), - (u32) value, is_add); - case GID_ADDR_ARP: - case GID_ADDR_NDP: - return add_del_arp_ndp (&db->arp_ndp_table, - gid_address_arp_ndp_bd (key), - &gid_address_arp_ndp_ip (key), value, is_add); - case GID_ADDR_NSH: - return add_del_nsh (&db->nsh_table, gid_address_vni (key), - gid_address_nsh_spi (key), gid_address_nsh_si (key), - value, is_add); - - default: - clib_warning ("address type %d not supported!", gid_address_type (key)); - break; - } - return ~0; -} - -static void -mac_lookup_init (gid_mac_table_t * db) -{ - if (db->mac_lookup_table_nbuckets == 0) - db->mac_lookup_table_nbuckets = MAC_LOOKUP_DEFAULT_HASH_NUM_BUCKETS; - - db->mac_lookup_table_nbuckets = - 1 << max_log2 (db->mac_lookup_table_nbuckets); - - if (db->mac_lookup_table_size == 0) - db->mac_lookup_table_size = MAC_LOOKUP_DEFAULT_HASH_MEMORY_SIZE; - - BV (clib_bihash_init) (&db->mac_lookup_table, "mac lookup table", - db->mac_lookup_table_nbuckets, - db->mac_lookup_table_size); -} - -static void -arp_ndp_lookup_init (gid_l2_arp_ndp_table_t * db) -{ - if (db->arp_ndp_lookup_table_nbuckets == 0) - db->arp_ndp_lookup_table_nbuckets = - ARP_NDP_LOOKUP_DEFAULT_HASH_NUM_BUCKETS; - - db->arp_ndp_lookup_table_nbuckets = - 1 << max_log2 (db->arp_ndp_lookup_table_nbuckets); - - if (db->arp_ndp_lookup_table_size == 0) - db->arp_ndp_lookup_table_size = ARP_NDP_LOOKUP_DEFAULT_HASH_MEMORY_SIZE; - - BV (clib_bihash_init) (&db->arp_ndp_lookup_table, "arp ndp lookup table", - db->arp_ndp_lookup_table_nbuckets, - db->arp_ndp_lookup_table_size); -} - -static void -nsh_lookup_init (gid_nsh_table_t * db) -{ - if (db->nsh_lookup_table_nbuckets == 0) - db->nsh_lookup_table_nbuckets = MAC_LOOKUP_DEFAULT_HASH_NUM_BUCKETS; - - db->nsh_lookup_table_nbuckets = - 1 << max_log2 (db->nsh_lookup_table_nbuckets); - - if (db->nsh_lookup_table_size == 0) - db->nsh_lookup_table_size = MAC_LOOKUP_DEFAULT_HASH_MEMORY_SIZE; - - BV (clib_bihash_init) (&db->nsh_lookup_table, "nsh lookup table", - db->nsh_lookup_table_nbuckets, - db->nsh_lookup_table_size); -} - -void -gid_dictionary_init (gid_dictionary_t * db) -{ - ip4_lookup_init (&db->dst_ip4_table); - ip6_lookup_init (&db->dst_ip6_table); - mac_lookup_init (&db->sd_mac_table); - arp_ndp_lookup_init (&db->arp_ndp_table); - nsh_lookup_init (&db->nsh_table); -} - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/src/vnet/lisp-cp/gid_dictionary.h b/src/vnet/lisp-cp/gid_dictionary.h deleted file mode 100644 index 5154b3a5874..00000000000 --- a/src/vnet/lisp-cp/gid_dictionary.h +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef VNET_LISP_GPE_GID_DICTIONARY_H_ -#define VNET_LISP_GPE_GID_DICTIONARY_H_ - -#include -#include -#include -#include - -#define GID_LOOKUP_MISS ((u32)~0) -#define GID_LOOKUP_MISS_L2 ((u64)~0) - -/* Default size of the ip4 hash table */ -#define IP4_LOOKUP_DEFAULT_HASH_NUM_BUCKETS (64 * 1024) -#define IP4_LOOKUP_DEFAULT_HASH_MEMORY_SIZE (32<<20) - -/* Default size of the ip6 hash table */ -#define IP6_LOOKUP_DEFAULT_HASH_NUM_BUCKETS (64 * 1024) -#define IP6_LOOKUP_DEFAULT_HASH_MEMORY_SIZE (32<<20) - -/* Default size of the MAC hash table */ -#define MAC_LOOKUP_DEFAULT_HASH_NUM_BUCKETS (64 * 1024) -#define MAC_LOOKUP_DEFAULT_HASH_MEMORY_SIZE (32<<20) - -/* Default size of the ARP/NDP hash table */ -#define ARP_NDP_LOOKUP_DEFAULT_HASH_NUM_BUCKETS (64 * 1024) -#define ARP_NDP_LOOKUP_DEFAULT_HASH_MEMORY_SIZE (32<<20) - -/* Default size of the NSH hash table */ -#define NSH_LOOKUP_DEFAULT_HASH_NUM_BUCKETS (64 * 1024) -#define NSH_LOOKUP_DEFAULT_HASH_MEMORY_SIZE (32<<20) - -typedef void (*foreach_subprefix_match_cb_t) (u32, void *); - -typedef struct -{ - BVT (clib_bihash) ip4_lookup_table; - - /* bitmap/vector of mask widths to search */ - uword *ip4_non_empty_dst_address_length_bitmap; - u8 *ip4_prefix_lengths_in_search_order; - ip4_address_t ip4_fib_masks[33]; - u32 ip4_prefix_len_refcount[33]; - - /* ip4 lookup table config parameters */ - u32 ip4_lookup_table_nbuckets; - uword ip4_lookup_table_size; - u32 count; -} gid_ip4_table_t; - -typedef struct -{ - BVT (clib_bihash) ip6_lookup_table; - - /* bitmap/vector of mask widths to search */ - uword *ip6_non_empty_dst_address_length_bitmap; - u8 *ip6_prefix_lengths_in_search_order; - ip6_address_t ip6_fib_masks[129]; - u64 ip6_prefix_len_refcount[129]; - - /* ip6 lookup table config parameters */ - u32 ip6_lookup_table_nbuckets; - uword ip6_lookup_table_size; - u64 count; -} gid_ip6_table_t; - -typedef struct gid_mac_table -{ - BVT (clib_bihash) mac_lookup_table; - - /* mac lookup table config parameters */ - u32 mac_lookup_table_nbuckets; - uword mac_lookup_table_size; - u64 count; -} gid_mac_table_t; - -typedef struct gid_nsh_table -{ - BVT (clib_bihash) nsh_lookup_table; - - /* nsh lookup table config parameters */ - u32 nsh_lookup_table_nbuckets; - uword nsh_lookup_table_size; - u64 count; -} gid_nsh_table_t; - -typedef struct -{ - BVT (clib_bihash) arp_ndp_lookup_table; - u32 arp_ndp_lookup_table_nbuckets; - uword arp_ndp_lookup_table_size; - u64 count; -} gid_l2_arp_ndp_table_t; - -typedef struct -{ - /** L2 ARP/NDP table */ - gid_l2_arp_ndp_table_t arp_ndp_table; - - /** NSH lookup table */ - gid_nsh_table_t nsh_table; - - /** destination IP LPM ip4 lookup table */ - gid_ip4_table_t dst_ip4_table; - - /** pool of source IP LPM ip4 lookup tables */ - gid_ip4_table_t *src_ip4_table_pool; - - /** destination IP LPM ip6 lookup table */ - gid_ip6_table_t dst_ip6_table; - - /** pool of source IP LPM ip6 lookup tables */ - gid_ip6_table_t *src_ip6_table_pool; - - /** flat source/dest mac lookup table */ - gid_mac_table_t sd_mac_table; - -} gid_dictionary_t; - -u32 -gid_dictionary_add_del (gid_dictionary_t * db, gid_address_t * key, u64 value, - u8 is_add); - -u64 gid_dictionary_lookup (gid_dictionary_t * db, gid_address_t * key); -u32 gid_dictionary_sd_lookup (gid_dictionary_t * db, gid_address_t * dst, - gid_address_t * src); - -void gid_dictionary_init (gid_dictionary_t * db); - -void -gid_dict_foreach_subprefix (gid_dictionary_t * db, gid_address_t * eid, - foreach_subprefix_match_cb_t cb, void *arg); - -void -gid_dict_foreach_l2_arp_ndp_entry (gid_dictionary_t * db, - BV (clib_bihash_foreach_key_value_pair_cb) - cb, void *ht); - -#endif /* VNET_LISP_GPE_GID_DICTIONARY_H_ */ - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/src/vnet/lisp-cp/lisp.api b/src/vnet/lisp-cp/lisp.api deleted file mode 100644 index 50d72527193..00000000000 --- a/src/vnet/lisp-cp/lisp.api +++ /dev/null @@ -1,674 +0,0 @@ -/* - * Copyright (c) 2015-2016 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -option version = "2.0.0"; - -import "vnet/interface_types.api"; -import "vnet/lisp-cp/lisp_types.api"; - -/** \brief add or delete locator_set - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param is_add - add address if non-zero, else delete - @param locator_set_name - locator name - @param locator_num - number of locators - @param locators - LISP locator records -*/ -manual_endian manual_print define lisp_add_del_locator_set -{ - u32 client_index; - u32 context; - bool is_add [default=true]; - string locator_set_name[64]; - u32 locator_num; - vl_api_local_locator_t locators[locator_num]; -}; - -/** \brief Reply for locator_set add/del - @param context - returned sender context, to match reply w/ request - @param retval - return code - @param ls_index - locator set index -*/ -define lisp_add_del_locator_set_reply -{ - u32 context; - i32 retval; - u32 ls_index; -}; - -/** \brief add or delete locator for locator_set - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param is_add - add address if non-zero, else delete - @param locator_set_name - name of locator_set to add/del locator - @param sw_if_index - index of the interface - @param priority - priority of the lisp locator - @param weight - weight of the lisp locator -*/ -autoreply define lisp_add_del_locator -{ - u32 client_index; - u32 context; - bool is_add [default=true]; - string locator_set_name[64]; - vl_api_interface_index_t sw_if_index; - u8 priority; - u8 weight; -}; - -/** \brief add or delete lisp eid-table - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param is_add - add address if non-zero, else delete - @param eid - endpoint identifier - @param locator_set_name - name of locator_set to add/del eid-table - @param vni - virtual network instance - @param key - secret key -*/ -autoreply define lisp_add_del_local_eid -{ - u32 client_index; - u32 context; - bool is_add [default=true]; - vl_api_eid_t eid; - string locator_set_name[64]; - u32 vni; - vl_api_hmac_key_t key; -}; - -/** \brief Add/delete map server - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param is_add - add address if non-zero; delete otherwise - @param ip_address - map server IP address -*/ -autoreply define lisp_add_del_map_server -{ - u32 client_index; - u32 context; - bool is_add [default=true]; - vl_api_address_t ip_address; -}; - -/** \brief add or delete map-resolver - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param is_add - add address if non-zero, else delete - @param ip_address - ip address -*/ -autoreply define lisp_add_del_map_resolver -{ - u32 client_index; - u32 context; - bool is_add [default=true]; - vl_api_address_t ip_address; -}; - -/** \brief enable or disable LISP feature - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param is_en - enable protocol if non-zero, else disable -*/ -autoreply define lisp_enable_disable -{ - u32 client_index; - u32 context; - bool is_enable [default=true]; -}; - -/** \brief configure or disable LISP PITR node - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param ls_name - locator set name - @param is_add - add locator set if non-zero, else disable pitr -*/ -autoreply define lisp_pitr_set_locator_set -{ - u32 client_index; - u32 context; - bool is_add [default=true]; - string ls_name[64]; -}; - -/** \brief configure or disable use of PETR - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param ip_address - PETR IP address - @param is_add - add locator set if non-zero, else disable pitr -*/ -autoreply define lisp_use_petr -{ - u32 client_index; - u32 context; - vl_api_address_t ip_address; - bool is_add [default=true]; -}; - -/** \brief Request for LISP PETR status - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request -*/ -define show_lisp_use_petr -{ - u32 client_index; - u32 context; -}; - -/** \brief LISP PETR status, enable or disable - @param context - sender context, to match reply w/ request - @param status - LISP PETR enable if non-zero, else disable - @param address - PETR IP address -*/ -define show_lisp_use_petr_reply -{ - u32 context; - i32 retval; - bool is_petr_enable [default=true]; - vl_api_address_t ip_address; -}; - -/** \brief Get state of LISP RLOC probing - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request -*/ -define show_lisp_rloc_probe_state -{ - u32 client_index; - u32 context; -}; - -/** \brief Reply for show_lisp_rloc_probe_state - @param context - returned sender context, to match reply w/ request - @param retval - return code - @param is_enabled - state of RLOC probing -*/ -define show_lisp_rloc_probe_state_reply -{ - u32 context; - i32 retval; - bool is_enabled [default=true]; -}; - -/** \brief enable/disable LISP RLOC probing - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param is_enable - enable if non-zero; disable otherwise -*/ -autoreply define lisp_rloc_probe_enable_disable -{ - u32 client_index; - u32 context; - bool is_enable [default=true]; -}; - -/** \brief enable/disable LISP map-register - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param is_enable - enable if non-zero; disable otherwise -*/ -autoreply define lisp_map_register_enable_disable -{ - u32 client_index; - u32 context; - bool is_enable [default=true]; -}; - -/** \brief Get state of LISP map-register - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request -*/ -define show_lisp_map_register_state -{ - u32 client_index; - u32 context; -}; - -/** \brief Reply for show_lisp_map_register_state - @param context - returned sender context, to match reply w/ request - @param retval - return code -*/ -define show_lisp_map_register_state_reply -{ - u32 context; - i32 retval; - bool is_enabled [default=true]; -}; - -/** \brief set LISP map-request mode. Based on configuration VPP will send - src/dest or just normal destination map requests. - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param is_src_dst - if non-zero source/destination else destination only -*/ -autoreply define lisp_map_request_mode -{ - u32 client_index; - u32 context; - bool is_src_dst; -}; - -/** \brief Request for LISP map-request mode - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request -*/ -define show_lisp_map_request_mode -{ - u32 client_index; - u32 context; -}; - -/** \brief Reply for show_lisp_map_request_mode - @param context - returned sender context, to match reply w/ request - @param retval - return code - @param is_src_dst - if non-zero source/destination else destination only -*/ -define show_lisp_map_request_mode_reply -{ - u32 context; - i32 retval; - bool is_src_dst; -}; - -/** \brief add or delete remote static mapping - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param is_add - add address if non-zero, else delete - @param is_src_dst - flag indicating src/dst based routing policy - @param del_all - if set, delete all remote mappings - @param vni - virtual network instance - @param action - negative map-reply action - @param deid - dst EID - @param seid - src EID, valid only if is_src_dst is enabled - @param rloc_num - number of remote locators - @param rlocs - remote locator records -*/ -autoreply manual_print manual_endian define lisp_add_del_remote_mapping -{ - u32 client_index; - u32 context; - bool is_add [default=true]; - bool is_src_dst; - bool del_all; - u32 vni; - u8 action; - vl_api_eid_t deid; - vl_api_eid_t seid; - u32 rloc_num; - vl_api_remote_locator_t rlocs[rloc_num]; -}; - -/** \brief add or delete LISP adjacency adjacency - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param is_add - add address if non-zero, else delete - @param vni - virtual network instance - @param reid - remote EID - @param leid - local EID -*/ -autoreply define lisp_add_del_adjacency -{ - u32 client_index; - u32 context; - bool is_add [default=true]; - u32 vni; - vl_api_eid_t reid; - vl_api_eid_t leid; -}; - -/** \brief add or delete map request itr rlocs - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param is_add - add address if non-zero, else delete - @param locator_set_name - locator set name -*/ -autoreply define lisp_add_del_map_request_itr_rlocs -{ - u32 client_index; - u32 context; - bool is_add [default=true]; - string locator_set_name[64]; -}; - -/** \brief Reply for lisp_add_del_map_request_itr_rlocs - @param context - returned sender context, to match reply w/ request - @param retval - return code -*/ - -/** \brief map/unmap vni/bd_index to vrf - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param is_add - add or delete mapping - @param dp_table - virtual network id/bridge domain index - @param vrf - vrf -*/ -autoreply define lisp_eid_table_add_del_map -{ - u32 client_index; - u32 context; - bool is_add [default=true]; - u32 vni; - u32 dp_table; - bool is_l2; -}; - -/** \brief Request for map lisp locator status - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param locator_set_index - index of locator_set - @param ls_name - locator set name - @param is_index_set - flag indicating whether ls_name or ls_index is set - */ -define lisp_locator_dump -{ - u32 client_index; - u32 context; - u32 ls_index; - string ls_name[64]; - u8 is_index_set; -}; - -/** \brief LISP locator_set status - @param local - if is set, then locator is local - @param locator_set_name - name of the locator_set - @param sw_if_index - sw_if_index of the locator - @param ip_address - ip address - @param priority - locator priority - @param weight - locator weight - */ -define lisp_locator_details -{ - u32 context; - u8 local; - vl_api_interface_index_t sw_if_index; - vl_api_address_t ip_address; - u8 priority; - u8 weight; -}; - -/** \brief LISP locator_set status - @param context - sender context, to match reply w/ request - @param ls_index - locator set index - @param ls_name - name of the locator set - */ -define lisp_locator_set_details -{ - u32 context; - u32 ls_index; - string ls_name[64]; -}; - -enum lisp_locator_set_filter : u8 { - LISP_LOCATOR_SET_FILTER_API_ALL = 0, - LISP_LOCATOR_SET_FILTER_API_LOCAL = 1, - LISP_LOCATOR_SET_FILTER_API_REMOTE = 2, -}; - -/** \brief Request for locator_set summary status - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param filter - filter type - */ -define lisp_locator_set_dump -{ - u32 client_index; - u32 context; - vl_api_lisp_locator_set_filter_t filter; -}; - -/** \brief Dump lisp eid-table - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param locator_set_index - index of locator_set, if ~0 then the mapping - is negative - @param action - negative map request action - @param is_local - local if non-zero, else remote - @param is_src_dst - EID is type of source/destination - @param deid - dst EID - @param seid - src EID - @param vni - virtual network instance - @param ttl - time to live - @param authoritative - authoritative - @param key_id - HMAC_NO_KEY 0 - HMAC_SHA_1_96 1 - HMAC_SHA_256_128 2 - @param key - secret key -*/ - -define lisp_eid_table_details -{ - u32 context; - u32 locator_set_index; - u8 action; - bool is_local; - bool is_src_dst; - u32 vni; - vl_api_eid_t deid; - vl_api_eid_t seid; - u32 ttl; - u8 authoritative; - vl_api_hmac_key_t key; -}; - -/** \brief Request for eid table summary status - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param eid_set - if non-zero request info about specific mapping - @param vni - virtual network instance; valid only if eid_set != 0 - @param prefix_length - prefix length if EID is IP address; - valid only if eid_set != 0 - @param eid - endpoint identifier - @param filter - filter type; - Support values: - 0: all eid - 1: local eid - 2: remote eid - */ -define lisp_eid_table_dump -{ - u32 client_index; - u32 context; - u8 eid_set; - u8 prefix_length; - u32 vni; - vl_api_eid_t eid; - vl_api_lisp_locator_set_filter_t filter; -}; - -/** \brief LISP adjacency - @param reid - remote EID - @param leid - local EID - */ -typedef lisp_adjacency -{ - vl_api_eid_t reid; - vl_api_eid_t leid; -}; - -/** \brief LISP adjacency reply - @param count - number of adjacencies - @param adjacencies - array of adjacencies - */ -manual_endian manual_print define lisp_adjacencies_get_reply -{ - u32 context; - i32 retval; - u32 count; - vl_api_lisp_adjacency_t adjacencies[count]; -}; - -/** \brief Request for LISP adjacencies - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param vni - filter adjacencies by VNI - */ -define lisp_adjacencies_get -{ - u32 client_index; - u32 context; - u32 vni; -}; - -/** \brief Shows relationship between vni and vrf/bd - @param dp_table - VRF index or bridge domain index - @param vni - virtual network instance - */ -define lisp_eid_table_map_details -{ - u32 context; - u32 vni; - u32 dp_table; -}; - -/** \brief Request for lisp_eid_table_map_details - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param is_l2 - if set dump vni/bd mappings else vni/vrf - */ -define lisp_eid_table_map_dump -{ - u32 client_index; - u32 context; - bool is_l2; -}; - -/** \brief Dumps all VNIs used in mappings - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - */ -define lisp_eid_table_vni_dump -{ - u32 client_index; - u32 context; -}; - -/** \brief reply to lisp_eid_table_vni_dump - @param context - sender context, to match reply w/ request - @param vni - virtual network instance - */ -define lisp_eid_table_vni_details -{ - u32 context; - u32 vni; -}; - -/** \brief LISP map resolver status - @param ip_address - array of address bytes - */ -define lisp_map_resolver_details -{ - u32 context; - vl_api_address_t ip_address; -}; - -/** \brief Request for map resolver summary status - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - */ -define lisp_map_resolver_dump -{ - u32 client_index; - u32 context; -}; - -/** \brief LISP map server details - @param ip_address - array of address bytes - */ -define lisp_map_server_details -{ - u32 context; - vl_api_address_t ip_address; -}; - -/** \brief Request for map server summary status - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - */ -define lisp_map_server_dump -{ - u32 client_index; - u32 context; -}; - -/** \brief Request for lisp-gpe protocol status - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request -*/ -define show_lisp_status -{ - u32 client_index; - u32 context; -}; - -/** \brief Status of lisp, enable or disable - @param context - sender context, to match reply w/ request - @param feature_status - lisp enable if non-zero, else disable - @param gpe_status - lisp enable if non-zero, else disable -*/ -define show_lisp_status_reply -{ - u32 context; - i32 retval; - bool is_lisp_enabled; - bool is_gpe_enabled; -}; - -/** \brief Get LISP map request itr rlocs status - @param context - sender context, to match reply w/ request - @param locator_set_name - name of the locator_set - */ -define lisp_get_map_request_itr_rlocs -{ - u32 client_index; - u32 context; -}; - -/** \brief Request for map request itr rlocs summary status - */ -define lisp_get_map_request_itr_rlocs_reply -{ - u32 context; - i32 retval; - string locator_set_name[64]; -}; - -/** \brief Request for lisp pitr status - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request -*/ -define show_lisp_pitr -{ - u32 client_index; - u32 context; -}; - -/** \brief Status of lisp pitr, enable or disable - @param context - sender context, to match reply w/ request - @param status - lisp pitr enable if non-zero, else disable - @param locator_set_name - name of the locator_set -*/ -define show_lisp_pitr_reply -{ - u32 context; - i32 retval; - bool is_enabled; - string locator_set_name[64]; -}; - -/* - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/src/vnet/lisp-cp/lisp_api.c b/src/vnet/lisp-cp/lisp_api.c deleted file mode 100644 index 3cb892f035c..00000000000 --- a/src/vnet/lisp-cp/lisp_api.c +++ /dev/null @@ -1,1134 +0,0 @@ -/* - *------------------------------------------------------------------ - * lisp_api.c - lisp api - * - * Copyright (c) 2016 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------ - */ - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include - - -#define vl_api_lisp_add_del_locator_set_t_endian vl_noop_handler -#define vl_api_lisp_add_del_locator_set_t_print vl_noop_handler -#define vl_api_lisp_add_del_remote_mapping_t_endian vl_noop_handler -#define vl_api_lisp_add_del_remote_mapping_t_print vl_noop_handler - -#define vl_api_one_add_del_locator_set_t_endian vl_noop_handler -#define vl_api_one_add_del_locator_set_t_print vl_noop_handler -#define vl_api_one_add_del_remote_mapping_t_endian vl_noop_handler -#define vl_api_one_add_del_remote_mapping_t_print vl_noop_handler - -#define vl_typedefs /* define message structures */ -#include -#undef vl_typedefs - -#define vl_endianfun /* define message structures */ -#include -#undef vl_endianfun - -/* instantiate all the print functions we know about */ -#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) -#define vl_printfun -#include -#undef vl_printfun - -#include - -#define foreach_vpe_api_msg \ -_(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set) \ -_(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator) \ -_(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid) \ -_(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver) \ -_(LISP_ADD_DEL_MAP_SERVER, lisp_add_del_map_server) \ -_(LISP_ENABLE_DISABLE, lisp_enable_disable) \ -_(LISP_RLOC_PROBE_ENABLE_DISABLE, lisp_rloc_probe_enable_disable) \ -_(LISP_MAP_REGISTER_ENABLE_DISABLE, lisp_map_register_enable_disable) \ -_(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping) \ -_(LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency) \ -_(LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set) \ -_(LISP_MAP_REQUEST_MODE, lisp_map_request_mode) \ -_(LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map) \ -_(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \ -_(LISP_LOCATOR_DUMP, lisp_locator_dump) \ -_(LISP_EID_TABLE_DUMP, lisp_eid_table_dump) \ -_(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump) \ -_(LISP_MAP_SERVER_DUMP, lisp_map_server_dump) \ -_(LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump) \ -_(LISP_EID_TABLE_VNI_DUMP, lisp_eid_table_vni_dump) \ -_(LISP_ADJACENCIES_GET, lisp_adjacencies_get) \ -_(SHOW_LISP_RLOC_PROBE_STATE, show_lisp_rloc_probe_state) \ -_(SHOW_LISP_MAP_REGISTER_STATE, show_lisp_map_register_state) \ -_(SHOW_LISP_STATUS, show_lisp_status) \ -_(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \ - lisp_add_del_map_request_itr_rlocs) \ -_(LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs) \ -_(SHOW_LISP_PITR, show_lisp_pitr) \ -_(SHOW_LISP_MAP_REQUEST_MODE, show_lisp_map_request_mode) \ -_(LISP_USE_PETR, lisp_use_petr) \ -_(SHOW_LISP_USE_PETR, show_lisp_use_petr) \ - -static locator_t * -unformat_lisp_locs (vl_api_remote_locator_t * rmt_locs, u32 rloc_num) -{ - u32 i; - locator_t *locs = 0, loc; - vl_api_remote_locator_t *r; - - for (i = 0; i < rloc_num; i++) - { - /* remote locators */ - r = &rmt_locs[i]; - clib_memset (&loc, 0, sizeof (loc)); - ip_address_decode2 (&r->ip_address, &loc.address.ippref.addr); - loc.address.ippref.len = - ip_address_max_len (loc.address.ippref.addr.version); - - loc.priority = r->priority; - loc.weight = r->weight; - - vec_add1 (locs, loc); - } - return locs; -} - -static void -vl_api_lisp_add_del_locator_set_t_handler (vl_api_lisp_add_del_locator_set_t * - mp) -{ - vl_api_lisp_add_del_locator_set_reply_t *rmp; - int rv = 0; - vnet_lisp_add_del_locator_set_args_t _a, *a = &_a; - locator_t locator; - vl_api_local_locator_t *ls_loc; - u32 ls_index = ~0, locator_num; - u8 *locator_name = NULL; - int i; - - clib_memset (a, 0, sizeof (a[0])); - - mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0; - locator_name = format (0, "%s", mp->locator_set_name); - vec_terminate_c_string (locator_name); - - a->name = locator_name; - a->is_add = mp->is_add; - a->local = 1; - locator_num = clib_net_to_host_u32 (mp->locator_num); - - clib_memset (&locator, 0, sizeof (locator)); - for (i = 0; i < locator_num; i++) - { - ls_loc = &mp->locators[i]; - VALIDATE_SW_IF_INDEX (ls_loc); - - locator.sw_if_index = htonl (ls_loc->sw_if_index); - locator.priority = ls_loc->priority; - locator.weight = ls_loc->weight; - locator.local = 1; - vec_add1 (a->locators, locator); - } - - rv = vnet_lisp_add_del_locator_set (a, &ls_index); - - BAD_SW_IF_INDEX_LABEL; - - vec_free (locator_name); - vec_free (a->locators); - - /* *INDENT-OFF* */ - REPLY_MACRO2 (VL_API_LISP_ADD_DEL_LOCATOR_SET_REPLY, - ({ - rmp->ls_index = clib_host_to_net_u32 (ls_index); - })); - /* *INDENT-ON* */ -} - -static void -vl_api_lisp_add_del_locator_t_handler (vl_api_lisp_add_del_locator_t * mp) -{ - vl_api_lisp_add_del_locator_reply_t *rmp; - int rv = 0; - locator_t locator, *locators = NULL; - vnet_lisp_add_del_locator_set_args_t _a, *a = &_a; - u32 ls_index = ~0; - u8 *locator_name = NULL; - - clib_memset (&locator, 0, sizeof (locator)); - clib_memset (a, 0, sizeof (a[0])); - - locator.sw_if_index = ntohl (mp->sw_if_index); - locator.priority = mp->priority; - locator.weight = mp->weight; - locator.local = 1; - vec_add1 (locators, locator); - - mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0; - locator_name = format (0, "%s", mp->locator_set_name); - vec_terminate_c_string (locator_name); - - a->name = locator_name; - a->locators = locators; - a->is_add = mp->is_add; - a->local = 1; - - rv = vnet_lisp_add_del_locator (a, NULL, &ls_index); - - vec_free (locators); - vec_free (locator_name); - - REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCATOR_REPLY); -} - -static void -vl_api_lisp_add_del_local_eid_t_handler (vl_api_lisp_add_del_local_eid_t * mp) -{ - vl_api_lisp_add_del_local_eid_reply_t *rmp; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - int rv = 0; - gid_address_t _gid, *gid = &_gid; - uword *p = NULL; - u32 locator_set_index = ~0, map_index = ~0; - vnet_lisp_add_del_mapping_args_t _a, *a = &_a; - u8 *name = NULL, *key = NULL; - clib_memset (a, 0, sizeof (a[0])); - clib_memset (gid, 0, sizeof (gid[0])); - - rv = unformat_lisp_eid_api (gid, mp->vni, &mp->eid); - if (rv) - goto out; - - mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0; - name = format (0, "%s", mp->locator_set_name); - vec_terminate_c_string (name); - p = hash_get_mem (lcm->locator_set_index_by_name, name); - if (!p) - { - rv = VNET_API_ERROR_INVALID_VALUE; - goto out; - } - locator_set_index = p[0]; - - if (mp->key.id) - key = format (0, "%s", mp->key.key); - - /* XXX treat batch configuration */ - a->is_add = mp->is_add; - gid_address_copy (&a->eid, gid); - a->locator_set_index = locator_set_index; - a->local = 1; - a->key = key; - a->key_id = clib_net_to_host_u16 (mp->key.id); - - rv = vnet_lisp_add_del_local_mapping (a, &map_index); - -out: - vec_free (name); - vec_free (key); - gid_address_free (&a->eid); - - REPLY_MACRO (VL_API_LISP_ADD_DEL_LOCAL_EID_REPLY); -} - -static void - vl_api_lisp_eid_table_add_del_map_t_handler - (vl_api_lisp_eid_table_add_del_map_t * mp) -{ - vl_api_lisp_eid_table_add_del_map_reply_t *rmp; - int rv = 0; - rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni), - clib_net_to_host_u32 (mp->dp_table), - mp->is_l2, mp->is_add); -REPLY_MACRO (VL_API_LISP_EID_TABLE_ADD_DEL_MAP_REPLY)} - -static void -vl_api_lisp_add_del_map_server_t_handler (vl_api_lisp_add_del_map_server_t - * mp) -{ - vl_api_lisp_add_del_map_server_reply_t *rmp; - int rv = 0; - ip_address_t addr; - - clib_memset (&addr, 0, sizeof (addr)); - - ip_address_decode2 (&mp->ip_address, &addr); - rv = vnet_lisp_add_del_map_server (&addr, mp->is_add); - - REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_SERVER_REPLY); -} - -static void -vl_api_lisp_add_del_map_resolver_t_handler (vl_api_lisp_add_del_map_resolver_t - * mp) -{ - vl_api_lisp_add_del_map_resolver_reply_t *rmp; - int rv = 0; - vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a; - - clib_memset (a, 0, sizeof (a[0])); - - a->is_add = mp->is_add; - ip_address_decode2 (&mp->ip_address, &a->address); - - rv = vnet_lisp_add_del_map_resolver (a); - - REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_RESOLVER_REPLY); -} - -static void - vl_api_lisp_map_register_enable_disable_t_handler - (vl_api_lisp_map_register_enable_disable_t * mp) -{ - vl_api_lisp_map_register_enable_disable_reply_t *rmp; - int rv = 0; - - vnet_lisp_map_register_enable_disable (mp->is_enable); - REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY); -} - -static void - vl_api_lisp_rloc_probe_enable_disable_t_handler - (vl_api_lisp_rloc_probe_enable_disable_t * mp) -{ - vl_api_lisp_rloc_probe_enable_disable_reply_t *rmp; - int rv = 0; - - vnet_lisp_rloc_probe_enable_disable (mp->is_enable); - REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY); -} - -static void -vl_api_lisp_enable_disable_t_handler (vl_api_lisp_enable_disable_t * mp) -{ - vl_api_lisp_enable_disable_reply_t *rmp; - int rv = 0; - - vnet_lisp_enable_disable (mp->is_enable); - REPLY_MACRO (VL_API_LISP_ENABLE_DISABLE_REPLY); -} - -static void - vl_api_show_lisp_map_request_mode_t_handler - (vl_api_show_lisp_map_request_mode_t * mp) -{ - int rv = 0; - vl_api_show_lisp_map_request_mode_reply_t *rmp; - - /* *INDENT-OFF* */ - REPLY_MACRO2(VL_API_SHOW_LISP_MAP_REQUEST_MODE_REPLY, - ({ - rmp->is_src_dst = vnet_lisp_get_map_request_mode (); - })); - /* *INDENT-ON* */ -} - -static void -vl_api_lisp_map_request_mode_t_handler (vl_api_lisp_map_request_mode_t * mp) -{ - vl_api_lisp_map_request_mode_reply_t *rmp; - int rv = 0; - - rv = vnet_lisp_set_map_request_mode (mp->is_src_dst); - - REPLY_MACRO (VL_API_LISP_MAP_REQUEST_MODE_REPLY); -} - -static void -vl_api_lisp_pitr_set_locator_set_t_handler (vl_api_lisp_pitr_set_locator_set_t - * mp) -{ - vl_api_lisp_pitr_set_locator_set_reply_t *rmp; - int rv = 0; - u8 *ls_name = 0; - - mp->ls_name[sizeof (mp->ls_name) - 1] = 0; - ls_name = format (0, "%s", mp->ls_name); - vec_terminate_c_string (ls_name); - rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add); - vec_free (ls_name); - - REPLY_MACRO (VL_API_LISP_PITR_SET_LOCATOR_SET_REPLY); -} - -static void -vl_api_lisp_use_petr_t_handler (vl_api_lisp_use_petr_t * mp) -{ - vl_api_lisp_use_petr_reply_t *rmp; - int rv = 0; - ip_address_t addr; - - ip_address_decode2 (&mp->ip_address, &addr); - rv = vnet_lisp_use_petr (&addr, mp->is_add); - - REPLY_MACRO (VL_API_LISP_USE_PETR_REPLY); -} - -static void -vl_api_show_lisp_use_petr_t_handler (vl_api_show_lisp_use_petr_t * mp) -{ - vl_api_show_lisp_use_petr_reply_t *rmp = NULL; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - mapping_t *m; - locator_set_t *ls = 0; - int rv = 0; - locator_t *loc = 0; - u8 status = 0; - gid_address_t addr; - - clib_memset (&addr, 0, sizeof (addr)); - status = lcm->flags & LISP_FLAG_USE_PETR; - if (status) - { - m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index); - if (~0 != m->locator_set_index) - { - ls = - pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index); - loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]); - gid_address_copy (&addr, &loc->address); - } - } - - /* *INDENT-OFF* */ - REPLY_MACRO2 (VL_API_SHOW_LISP_USE_PETR_REPLY, - { - rmp->is_petr_enable = status; - ip_address_encode2 (&gid_address_ip (&addr), &rmp->ip_address); - }); - /* *INDENT-ON* */ -} - -static void - vl_api_lisp_add_del_map_request_itr_rlocs_t_handler - (vl_api_lisp_add_del_map_request_itr_rlocs_t * mp) -{ - vl_api_lisp_add_del_map_request_itr_rlocs_reply_t *rmp; - int rv = 0; - u8 *locator_set_name = NULL; - vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a; - - mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0; - locator_set_name = format (0, "%s", mp->locator_set_name); - vec_terminate_c_string (locator_set_name); - - a->is_add = mp->is_add; - a->locator_set_name = locator_set_name; - - rv = vnet_lisp_add_del_mreq_itr_rlocs (a); - - vec_free (locator_set_name); - - REPLY_MACRO (VL_API_LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY); -} - -static void - vl_api_lisp_add_del_remote_mapping_t_handler - (vl_api_lisp_add_del_remote_mapping_t * mp) -{ - locator_t *rlocs = 0; - vl_api_lisp_add_del_remote_mapping_reply_t *rmp; - int rv = 0; - gid_address_t _eid, *eid = &_eid; - u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num); - - clib_memset (eid, 0, sizeof (eid[0])); - - rv = unformat_lisp_eid_api (eid, mp->vni, &mp->deid); - if (rv) - goto send_reply; - - rlocs = unformat_lisp_locs (mp->rlocs, rloc_num); - - if (!mp->is_add) - { - vnet_lisp_add_del_adjacency_args_t _a, *a = &_a; - clib_memset (a, 0, sizeof (*a)); - gid_address_copy (&a->reid, eid); - a->is_add = 0; - rv = vnet_lisp_add_del_adjacency (a); - if (rv) - { - goto out; - } - } - - /* NOTE: for now this works as a static remote mapping, i.e., - * not authoritative and ttl infinite. */ - if (mp->is_add) - { - vnet_lisp_add_del_mapping_args_t _m_args, *m_args = &_m_args; - clib_memset (m_args, 0, sizeof (m_args[0])); - gid_address_copy (&m_args->eid, eid); - m_args->action = mp->action; - m_args->is_static = 1; - m_args->ttl = ~0; - m_args->authoritative = 0; - rv = vnet_lisp_add_mapping (m_args, rlocs, NULL, NULL); - } - else - { - rv = vnet_lisp_del_mapping (eid, NULL); - } - - if (mp->del_all) - vnet_lisp_clear_all_remote_adjacencies (); - -out: - vec_free (rlocs); -send_reply: - REPLY_MACRO (VL_API_LISP_ADD_DEL_REMOTE_MAPPING_REPLY); -} - -static void -vl_api_lisp_add_del_adjacency_t_handler (vl_api_lisp_add_del_adjacency_t * mp) -{ - vl_api_lisp_add_del_adjacency_reply_t *rmp; - vnet_lisp_add_del_adjacency_args_t _a, *a = &_a; - - int rv = 0; - clib_memset (a, 0, sizeof (a[0])); - - rv = unformat_lisp_eid_api (&a->leid, mp->vni, &mp->leid); - rv = unformat_lisp_eid_api (&a->reid, mp->vni, &mp->reid); - - if (rv) - goto send_reply; - - a->is_add = mp->is_add; - rv = vnet_lisp_add_del_adjacency (a); - -send_reply: - REPLY_MACRO (VL_API_LISP_ADD_DEL_ADJACENCY_REPLY); -} - -static void -send_lisp_locator_details (lisp_cp_main_t * lcm, - locator_t * loc, vl_api_registration_t * reg, - u32 context) -{ - vl_api_lisp_locator_details_t *rmp; - - rmp = vl_msg_api_alloc (sizeof (*rmp)); - clib_memset (rmp, 0, sizeof (*rmp)); - rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_DETAILS); - rmp->context = context; - - rmp->local = loc->local; - if (loc->local) - { - rmp->sw_if_index = ntohl (loc->sw_if_index); - } - else - { - ip_address_encode2 (&gid_address_ip (&loc->address), &rmp->ip_address); - } - rmp->priority = loc->priority; - rmp->weight = loc->weight; - - vl_api_send_msg (reg, (u8 *) rmp); -} - -static void -vl_api_lisp_locator_dump_t_handler (vl_api_lisp_locator_dump_t * mp) -{ - u8 *ls_name = 0; - vl_api_registration_t *reg = 0; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - locator_set_t *lsit = 0; - locator_t *loc = 0; - u32 ls_index = ~0, *locit = 0; - uword *p = 0; - - reg = vl_api_client_index_to_registration (mp->client_index); - if (!reg) - return; - - if (mp->is_index_set) - ls_index = htonl (mp->ls_index); - else - { - /* make sure we get a proper C-string */ - mp->ls_name[sizeof (mp->ls_name) - 1] = 0; - ls_name = format (0, "%s", mp->ls_name); - vec_terminate_c_string (ls_name); - p = hash_get_mem (lcm->locator_set_index_by_name, ls_name); - if (!p) - goto out; - ls_index = p[0]; - } - - if (pool_is_free_index (lcm->locator_set_pool, ls_index)) - return; - - lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index); - - vec_foreach (locit, lsit->locator_indices) - { - loc = pool_elt_at_index (lcm->locator_pool, locit[0]); - send_lisp_locator_details (lcm, loc, reg, mp->context); - }; -out: - vec_free (ls_name); -} - -static void -send_lisp_locator_set_details (lisp_cp_main_t * lcm, - locator_set_t * lsit, - vl_api_registration_t * reg, u32 context, - u32 ls_index) -{ - vl_api_lisp_locator_set_details_t *rmp; - u8 *str = 0; - - rmp = vl_msg_api_alloc (sizeof (*rmp)); - clib_memset (rmp, 0, sizeof (*rmp)); - rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_SET_DETAILS); - rmp->context = context; - - rmp->ls_index = htonl (ls_index); - if (lsit->local) - { - ASSERT (lsit->name != NULL); - strncpy ((char *) rmp->ls_name, (char *) lsit->name, - vec_len (lsit->name)); - } - else - { - str = format (0, "", ls_index); - strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str)); - vec_free (str); - } - - vl_api_send_msg (reg, (u8 *) rmp); -} - -static void -vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t * mp) -{ - vl_api_registration_t *reg; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - locator_set_t *lsit = NULL; - u8 filter; - - reg = vl_api_client_index_to_registration (mp->client_index); - if (!reg) - return; - - filter = mp->filter; - /* *INDENT-OFF* */ - pool_foreach (lsit, lcm->locator_set_pool, - ({ - if (filter && !((1 == filter && lsit->local) || - (2 == filter && !lsit->local))) - { - continue; - } - send_lisp_locator_set_details (lcm, lsit, reg, mp->context, - lsit - lcm->locator_set_pool); - })); - /* *INDENT-ON* */ -} - -static void -send_lisp_eid_table_details (mapping_t * mapit, - vl_api_registration_t * reg, u32 context, - u8 filter) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - locator_set_t *ls = 0; - vl_api_lisp_eid_table_details_t *rmp = NULL; - gid_address_t *gid = NULL; - - switch (filter) - { - case 0: /* all mappings */ - break; - - case 1: /* local only */ - if (!mapit->local) - return; - break; - case 2: /* remote only */ - if (mapit->local) - return; - break; - default: - clib_warning ("Filter error, unknown filter: %d", filter); - return; - } - - /* don't send PITR generated mapping */ - if (mapit->pitr_set) - return; - - gid = &mapit->eid; - - rmp = vl_msg_api_alloc (sizeof (*rmp)); - clib_memset (rmp, 0, sizeof (*rmp)); - rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_DETAILS); - - ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index); - if (vec_len (ls->locator_indices) == 0) - rmp->locator_set_index = ~0; - else - rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index); - - rmp->is_local = mapit->local; - rmp->ttl = clib_host_to_net_u32 (mapit->ttl); - rmp->action = mapit->action; - rmp->authoritative = mapit->authoritative; - switch (gid_address_type (gid)) - { - case GID_ADDR_SRC_DST: - lisp_fid_put_api (&rmp->seid, &gid_address_sd_src (gid)); - lisp_fid_put_api (&rmp->deid, &gid_address_sd_dst (gid)); - rmp->is_src_dst = 1; - break; - case GID_ADDR_IP_PREFIX: - lisp_gid_put_api (&rmp->seid, gid); - break; - case GID_ADDR_MAC: - lisp_gid_put_api (&rmp->seid, gid); - break; - default: - ASSERT (0); - } - rmp->context = context; - rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid)); - rmp->key.id = clib_host_to_net_u16 (mapit->key_id); - memcpy (rmp->key.key, mapit->key, vec_len (mapit->key)); - vl_api_send_msg (reg, (u8 *) rmp); -} - -static void -vl_api_lisp_eid_table_dump_t_handler (vl_api_lisp_eid_table_dump_t * mp) -{ - u32 mi; - vl_api_registration_t *reg; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - mapping_t *mapit = NULL; - gid_address_t _eid, *eid = &_eid; - - reg = vl_api_client_index_to_registration (mp->client_index); - if (!reg) - return; - - if (mp->eid_set) - { - clib_memset (eid, 0, sizeof (*eid)); - - unformat_lisp_eid_api (eid, mp->vni, &mp->eid); - - mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid); - if ((u32) ~ 0 == mi) - return; - - mapit = pool_elt_at_index (lcm->mapping_pool, mi); - send_lisp_eid_table_details (mapit, reg, mp->context, - 0 /* ignore filter */ ); - } - else - { - /* *INDENT-OFF* */ - pool_foreach (mapit, lcm->mapping_pool, - ({ - send_lisp_eid_table_details(mapit, reg, mp->context, - mp->filter); - })); - /* *INDENT-ON* */ - } -} - -static void -send_lisp_map_server_details (ip_address_t * ip, vl_api_registration_t * reg, - u32 context) -{ - vl_api_lisp_map_server_details_t *rmp = NULL; - - rmp = vl_msg_api_alloc (sizeof (*rmp)); - clib_memset (rmp, 0, sizeof (*rmp)); - rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_SERVER_DETAILS); - - ip_address_encode2 (ip, &rmp->ip_address); - rmp->context = context; - - vl_api_send_msg (reg, (u8 *) rmp); -} - -static void -vl_api_lisp_map_server_dump_t_handler (vl_api_lisp_map_server_dump_t * mp) -{ - vl_api_registration_t *reg; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - lisp_msmr_t *mr; - - reg = vl_api_client_index_to_registration (mp->client_index); - if (!reg) - return; - - vec_foreach (mr, lcm->map_servers) - { - send_lisp_map_server_details (&mr->address, reg, mp->context); - } -} - -static void -send_lisp_map_resolver_details (ip_address_t * ip, - vl_api_registration_t * reg, u32 context) -{ - vl_api_lisp_map_resolver_details_t *rmp = NULL; - - rmp = vl_msg_api_alloc (sizeof (*rmp)); - clib_memset (rmp, 0, sizeof (*rmp)); - rmp->_vl_msg_id = ntohs (VL_API_LISP_MAP_RESOLVER_DETAILS); - - ip_address_encode2 (ip, &rmp->ip_address); - rmp->context = context; - - vl_api_send_msg (reg, (u8 *) rmp); -} - -static void -vl_api_lisp_map_resolver_dump_t_handler (vl_api_lisp_map_resolver_dump_t * mp) -{ - vl_api_registration_t *reg; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - lisp_msmr_t *mr; - - reg = vl_api_client_index_to_registration (mp->client_index); - if (!reg) - return; - - vec_foreach (mr, lcm->map_resolvers) - { - send_lisp_map_resolver_details (&mr->address, reg, mp->context); - } -} - -static void -send_eid_table_map_pair (hash_pair_t * p, vl_api_registration_t * reg, - u32 context) -{ - vl_api_lisp_eid_table_map_details_t *rmp = NULL; - - rmp = vl_msg_api_alloc (sizeof (*rmp)); - clib_memset (rmp, 0, sizeof (*rmp)); - rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_MAP_DETAILS); - - rmp->vni = clib_host_to_net_u32 (p->key); - rmp->dp_table = clib_host_to_net_u32 (p->value[0]); - rmp->context = context; - vl_api_send_msg (reg, (u8 *) rmp); -} - -static void -vl_api_lisp_eid_table_map_dump_t_handler (vl_api_lisp_eid_table_map_dump_t * - mp) -{ - vl_api_registration_t *reg; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - hash_pair_t *p; - uword *vni_table = 0; - - reg = vl_api_client_index_to_registration (mp->client_index); - if (!reg) - return; - - if (mp->is_l2) - { - vni_table = lcm->bd_id_by_vni; - } - else - { - vni_table = lcm->table_id_by_vni; - } - - /* *INDENT-OFF* */ - hash_foreach_pair (p, vni_table, - ({ - send_eid_table_map_pair (p, reg, mp->context); - })); - /* *INDENT-ON* */ -} - -static void -send_eid_table_vni (u32 vni, vl_api_registration_t * reg, u32 context) -{ - vl_api_lisp_eid_table_vni_details_t *rmp = 0; - - rmp = vl_msg_api_alloc (sizeof (*rmp)); - clib_memset (rmp, 0, sizeof (*rmp)); - rmp->_vl_msg_id = ntohs (VL_API_LISP_EID_TABLE_VNI_DETAILS); - rmp->context = context; - rmp->vni = clib_host_to_net_u32 (vni); - vl_api_send_msg (reg, (u8 *) rmp); -} - -static void -lisp_adjacency_copy (vl_api_lisp_adjacency_t * dst, lisp_adjacency_t * adjs) -{ - lisp_adjacency_t *adj; - vl_api_lisp_adjacency_t a; - u32 i, n = vec_len (adjs); - - for (i = 0; i < n; i++) - { - adj = vec_elt_at_index (adjs, i); - clib_memset (&a, 0, sizeof (a)); - - lisp_gid_put_api (&a.reid, &adj->reid); - lisp_gid_put_api (&a.leid, &adj->leid); - - dst[i] = a; - } -} - -static void - vl_api_show_lisp_rloc_probe_state_t_handler - (vl_api_show_lisp_rloc_probe_state_t * mp) -{ - vl_api_show_lisp_rloc_probe_state_reply_t *rmp = 0; - int rv = 0; - - /* *INDENT-OFF* */ - REPLY_MACRO2 (VL_API_SHOW_LISP_RLOC_PROBE_STATE_REPLY, - { - rmp->is_enabled = vnet_lisp_rloc_probe_state_get (); - }); - /* *INDENT-ON* */ -} - -static void - vl_api_show_lisp_map_register_state_t_handler - (vl_api_show_lisp_map_register_state_t * mp) -{ - vl_api_show_lisp_map_register_state_reply_t *rmp = 0; - int rv = 0; - - /* *INDENT-OFF* */ - REPLY_MACRO2 (VL_API_SHOW_LISP_MAP_REGISTER_STATE_REPLY, - { - rmp->is_enabled = vnet_lisp_map_register_state_get (); - }); - /* *INDENT-ON* */ -} - -static void -vl_api_lisp_adjacencies_get_t_handler (vl_api_lisp_adjacencies_get_t * mp) -{ - vl_api_lisp_adjacencies_get_reply_t *rmp = 0; - lisp_adjacency_t *adjs = 0; - int rv = 0; - u32 size = ~0; - u32 vni = clib_net_to_host_u32 (mp->vni); - - adjs = vnet_lisp_adjacencies_get_by_vni (vni); - size = vec_len (adjs) * sizeof (vl_api_lisp_adjacency_t); - - /* *INDENT-OFF* */ - REPLY_MACRO4 (VL_API_LISP_ADJACENCIES_GET_REPLY, size, - { - rmp->count = clib_host_to_net_u32 (vec_len (adjs)); - lisp_adjacency_copy (rmp->adjacencies, adjs); - }); - /* *INDENT-ON* */ - - vec_free (adjs); -} - -static void -vl_api_lisp_eid_table_vni_dump_t_handler (vl_api_lisp_eid_table_vni_dump_t * - mp) -{ - hash_pair_t *p; - u32 *vnis = 0; - vl_api_registration_t *reg = 0; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - - reg = vl_api_client_index_to_registration (mp->client_index); - if (!reg) - return; - - /* *INDENT-OFF* */ - hash_foreach_pair (p, lcm->table_id_by_vni, - ({ - hash_set (vnis, p->key, 0); - })); - - hash_foreach_pair (p, lcm->bd_id_by_vni, - ({ - hash_set (vnis, p->key, 0); - })); - - hash_foreach_pair (p, vnis, - ({ - send_eid_table_vni (p->key, reg, mp->context); - })); - /* *INDENT-ON* */ - - hash_free (vnis); -} - -static void -vl_api_show_lisp_status_t_handler (vl_api_show_lisp_status_t * mp) -{ - vl_api_show_lisp_status_reply_t *rmp = NULL; - int rv = 0; - - /* *INDENT-OFF* */ - REPLY_MACRO2(VL_API_SHOW_LISP_STATUS_REPLY, - ({ - rmp->is_gpe_enabled = vnet_lisp_gpe_enable_disable_status (); - rmp->is_lisp_enabled = vnet_lisp_enable_disable_status (); - })); - /* *INDENT-ON* */ -} - -static void - vl_api_lisp_get_map_request_itr_rlocs_t_handler - (vl_api_lisp_get_map_request_itr_rlocs_t * mp) -{ - vl_api_lisp_get_map_request_itr_rlocs_reply_t *rmp = NULL; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - locator_set_t *loc_set = 0; - u8 *tmp_str = 0; - int rv = 0; - - if (~0 == lcm->mreq_itr_rlocs) - { - tmp_str = format (0, " "); - } - else - { - loc_set = - pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs); - tmp_str = format (0, "%s", loc_set->name); - } - - /* *INDENT-OFF* */ - REPLY_MACRO2(VL_API_LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY, - ({ - strncpy((char *) rmp->locator_set_name, (char *) tmp_str, - ARRAY_LEN(rmp->locator_set_name) - 1); - })); - /* *INDENT-ON* */ - - vec_free (tmp_str); -} - -static void -vl_api_show_lisp_pitr_t_handler (vl_api_show_lisp_pitr_t * mp) -{ - vl_api_show_lisp_pitr_reply_t *rmp = NULL; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - mapping_t *m; - locator_set_t *ls = 0; - u8 *tmp_str = 0; - int rv = 0; - - u8 is_enabled = (lcm->flags & LISP_FLAG_PITR_MODE) - && lcm->pitr_map_index != ~0; - - if (!is_enabled) - { - tmp_str = format (0, "N/A"); - } - else - { - m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index); - if (~0 != m->locator_set_index) - { - ls = - pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index); - tmp_str = format (0, "%s", ls->name); - } - else - { - tmp_str = format (0, "N/A"); - } - } - vec_add1 (tmp_str, 0); - - /* *INDENT-OFF* */ - REPLY_MACRO2(VL_API_SHOW_LISP_PITR_REPLY, - ({ - rmp->is_enabled = lcm->flags & LISP_FLAG_PITR_MODE; - strncpy((char *) rmp->locator_set_name, (char *) tmp_str, - ARRAY_LEN(rmp->locator_set_name) - 1); - })); - /* *INDENT-ON* */ -} - -/* - * lisp_api_hookup - * Add vpe's API message handlers to the table. - * vlib has already mapped shared memory and - * added the client registration handlers. - * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process() - */ -#define vl_msg_name_crc_list -#include -#undef vl_msg_name_crc_list - -static void -setup_message_id_table (api_main_t * am) -{ -#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id); - foreach_vl_msg_name_crc_lisp; -#undef _ -} - -static clib_error_t * -lisp_api_hookup (vlib_main_t * vm) -{ - api_main_t *am = vlibapi_get_main (); - -#define _(N,n) \ - vl_msg_api_set_handlers(VL_API_##N, #n, \ - vl_api_##n##_t_handler, \ - vl_noop_handler, \ - vl_api_##n##_t_endian, \ - vl_api_##n##_t_print, \ - sizeof(vl_api_##n##_t), 1); - foreach_vpe_api_msg; -#undef _ - - /* - * Set up the (msg_name, crc, message-id) table - */ - setup_message_id_table (am); - - return 0; -} - -VLIB_API_INIT_FUNCTION (lisp_api_hookup); - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/src/vnet/lisp-cp/lisp_cli.c b/src/vnet/lisp-cp/lisp_cli.c deleted file mode 100644 index 93422fe2de7..00000000000 --- a/src/vnet/lisp-cp/lisp_cli.c +++ /dev/null @@ -1,1603 +0,0 @@ -/* - * Copyright (c) 2017 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -static clib_error_t * -lisp_show_adjacencies_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - lisp_adjacency_t *adjs, *adj; - vlib_cli_output (vm, "%s %40s\n", "leid", "reid"); - unformat_input_t _line_input, *line_input = &_line_input; - u32 vni = ~0; - clib_error_t *error = NULL; - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return 0; - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "vni %d", &vni)) - ; - else - { - vlib_cli_output (vm, "parse error: '%U'", - format_unformat_error, line_input); - goto done; - } - } - - if (~0 == vni) - { - vlib_cli_output (vm, "error: no vni specified!"); - goto done; - } - - adjs = vnet_lisp_adjacencies_get_by_vni (vni); - - vec_foreach (adj, adjs) - { - vlib_cli_output (vm, "%U %40U\n", format_gid_address, &adj->leid, - format_gid_address, &adj->reid); - } - vec_free (adjs); - -done: - unformat_free (line_input); - - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (lisp_show_adjacencies_command) = { - .path = "show lisp adjacencies", - .short_help = "show lisp adjacencies", - .function = lisp_show_adjacencies_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_add_del_map_server_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - int rv = 0; - u8 is_add = 1, ip_set = 0; - ip_address_t ip; - unformat_input_t _line_input, *line_input = &_line_input; - clib_error_t *error = NULL; - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return 0; - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "add")) - is_add = 1; - else if (unformat (line_input, "del")) - is_add = 0; - else if (unformat (line_input, "%U", unformat_ip_address, &ip)) - ip_set = 1; - else - { - vlib_cli_output (vm, "parse error: '%U'", - format_unformat_error, line_input); - goto done; - } - } - - if (!ip_set) - { - vlib_cli_output (vm, "map-server ip address not set!"); - goto done; - } - - rv = vnet_lisp_add_del_map_server (&ip, is_add); - if (!rv) - vlib_cli_output (vm, "failed to %s map-server!", - is_add ? "add" : "delete"); - -done: - unformat_free (line_input); - - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (lisp_add_del_map_server_command) = { - .path = "lisp map-server", - .short_help = "lisp map-server add|del ", - .function = lisp_add_del_map_server_command_fn, -}; -/* *INDENT-ON* */ - - -static clib_error_t * -lisp_add_del_local_eid_command_fn (vlib_main_t * vm, unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - unformat_input_t _line_input, *line_input = &_line_input; - u8 is_add = 1; - gid_address_t eid; - gid_address_t *eids = 0; - clib_error_t *error = 0; - u8 *locator_set_name = 0; - u32 locator_set_index = 0, map_index = 0; - uword *p; - vnet_lisp_add_del_mapping_args_t _a, *a = &_a; - int rv = 0; - u32 vni = 0; - u8 *key = 0; - u32 key_id = 0; - - clib_memset (&eid, 0, sizeof (eid)); - clib_memset (a, 0, sizeof (*a)); - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return 0; - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "add")) - is_add = 1; - else if (unformat (line_input, "del")) - is_add = 0; - else if (unformat (line_input, "eid %U", unformat_gid_address, &eid)) - ; - else if (unformat (line_input, "vni %d", &vni)) - gid_address_vni (&eid) = vni; - else if (unformat (line_input, "secret-key %_%v%_", &key)) - ; - else if (unformat (line_input, "key-id %U", unformat_hmac_key_id, - &key_id)) - ; - else if (unformat (line_input, "locator-set %_%v%_", &locator_set_name)) - { - vec_terminate_c_string (locator_set_name); - p = hash_get_mem (lcm->locator_set_index_by_name, locator_set_name); - if (!p) - { - error = clib_error_return (0, "locator-set %s doesn't exist", - locator_set_name); - goto done; - } - locator_set_index = p[0]; - } - else - { - error = unformat_parse_error (line_input); - goto done; - } - } - /* XXX treat batch configuration */ - - if (GID_ADDR_SRC_DST == gid_address_type (&eid)) - { - error = - clib_error_return (0, "src/dst is not supported for local EIDs!"); - goto done; - } - - if (key && (0 == key_id)) - { - vlib_cli_output (vm, "invalid key_id!"); - goto done;; - } - - gid_address_copy (&a->eid, &eid); - a->is_add = is_add; - a->locator_set_index = locator_set_index; - a->local = 1; - a->key = key; - a->key_id = key_id; - - rv = vnet_lisp_add_del_local_mapping (a, &map_index); - if (0 != rv) - { - error = clib_error_return (0, "failed to %s local mapping!", - is_add ? "add" : "delete"); - } -done: - vec_free (eids); - if (locator_set_name) - vec_free (locator_set_name); - gid_address_free (&a->eid); - vec_free (a->key); - unformat_free (line_input); - - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (lisp_add_del_local_eid_command) = { - .path = "lisp eid-table", - .short_help = "lisp eid-table add/del [vni ] eid " - "locator-set [key key-id sha1|sha256 ]", - .function = lisp_add_del_local_eid_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_eid_table_map_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - u8 is_add = 1, is_l2 = 0; - u32 vni = 0, dp_id = 0; - unformat_input_t _line_input, *line_input = &_line_input; - clib_error_t *error = NULL; - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return 0; - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "del")) - is_add = 0; - else if (unformat (line_input, "vni %d", &vni)) - ; - else if (unformat (line_input, "vrf %d", &dp_id)) - ; - else if (unformat (line_input, "bd %d", &dp_id)) - is_l2 = 1; - else - { - error = unformat_parse_error (line_input); - goto done; - } - } - vnet_lisp_eid_table_map (vni, dp_id, is_l2, is_add); - -done: - unformat_free (line_input); - - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (lisp_eid_table_map_command) = { - .path = "lisp eid-table map", - .short_help = "lisp eid-table map [del] vni vrf | bd ", - .function = lisp_eid_table_map_command_fn, -}; -/* *INDENT-ON* */ - -/** - * Handler for add/del remote mapping CLI. - * - * @param vm vlib context - * @param input input from user - * @param cmd cmd - * @return pointer to clib error structure - */ -static clib_error_t * -lisp_add_del_remote_mapping_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - clib_error_t *error = 0; - unformat_input_t _line_input, *line_input = &_line_input; - u8 is_add = 1, del_all = 0; - locator_t rloc, *rlocs = 0, *curr_rloc = 0; - gid_address_t eid; - u8 eid_set = 0; - u32 vni, action = ~0, p, w; - int rv; - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return 0; - - clib_memset (&eid, 0, sizeof (eid)); - clib_memset (&rloc, 0, sizeof (rloc)); - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "del-all")) - del_all = 1; - else if (unformat (line_input, "del")) - is_add = 0; - else if (unformat (line_input, "add")) - ; - else if (unformat (line_input, "eid %U", unformat_gid_address, &eid)) - eid_set = 1; - else if (unformat (line_input, "vni %u", &vni)) - { - gid_address_vni (&eid) = vni; - } - else if (unformat (line_input, "p %d w %d", &p, &w)) - { - if (!curr_rloc) - { - clib_warning - ("No RLOC configured for setting priority/weight!"); - goto done; - } - curr_rloc->priority = p; - curr_rloc->weight = w; - } - else if (unformat (line_input, "rloc %U", unformat_ip_address, - &gid_address_ip (&rloc.address))) - { - /* since rloc is stored in ip prefix we need to set prefix length */ - ip_prefix_t *pref = &gid_address_ippref (&rloc.address); - - u8 version = gid_address_ip_version (&rloc.address); - ip_prefix_len (pref) = ip_address_max_len (version); - - vec_add1 (rlocs, rloc); - curr_rloc = &rlocs[vec_len (rlocs) - 1]; - } - else if (unformat (line_input, "action %U", - unformat_negative_mapping_action, &action)) - ; - else - { - clib_warning ("parse error"); - goto done; - } - } - - if (!eid_set) - { - clib_warning ("missing eid!"); - goto done; - } - - if (!del_all) - { - if (is_add && (~0 == action) && 0 == vec_len (rlocs)) - { - clib_warning ("no action set for negative map-reply!"); - goto done; - } - } - else - { - vnet_lisp_clear_all_remote_adjacencies (); - goto done; - } - - /* TODO build src/dst with seid */ - - /* if it's a delete, clean forwarding */ - if (!is_add) - { - vnet_lisp_add_del_adjacency_args_t _a, *a = &_a; - clib_memset (a, 0, sizeof (a[0])); - gid_address_copy (&a->reid, &eid); - if (vnet_lisp_add_del_adjacency (a)) - { - clib_warning ("failed to delete adjacency!"); - goto done; - } - } - - /* add as static remote mapping, i.e., not authoritative and infinite - * ttl */ - if (is_add) - { - vnet_lisp_add_del_mapping_args_t _map_args, *map_args = &_map_args; - clib_memset (map_args, 0, sizeof (map_args[0])); - gid_address_copy (&map_args->eid, &eid); - map_args->action = action; - map_args->is_static = 1; - map_args->authoritative = 0; - map_args->ttl = ~0; - rv = vnet_lisp_add_mapping (map_args, rlocs, NULL, NULL); - } - else - rv = vnet_lisp_del_mapping (&eid, NULL); - - if (rv) - clib_warning ("failed to %s remote mapping!", is_add ? "add" : "delete"); - -done: - vec_free (rlocs); - unformat_free (line_input); - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (lisp_add_del_remote_mapping_command) = { - .path = "lisp remote-mapping", - .short_help = "lisp remote-mapping add|del [del-all] vni " - "eid [action ] rloc p " - "w [rloc ... ]", - .function = lisp_add_del_remote_mapping_command_fn, -}; -/* *INDENT-ON* */ - -/** - * Handler for add/del adjacency CLI. - */ -static clib_error_t * -lisp_add_del_adjacency_command_fn (vlib_main_t * vm, unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - clib_error_t *error = 0; - unformat_input_t _line_input, *line_input = &_line_input; - vnet_lisp_add_del_adjacency_args_t _a, *a = &_a; - u8 is_add = 1; - ip_prefix_t *reid_ippref, *leid_ippref; - gid_address_t leid, reid; - u8 *dmac = gid_address_mac (&reid); - u8 *smac = gid_address_mac (&leid); - u8 reid_set = 0, leid_set = 0; - u32 vni; - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return 0; - - clib_memset (&reid, 0, sizeof (reid)); - clib_memset (&leid, 0, sizeof (leid)); - - leid_ippref = &gid_address_ippref (&leid); - reid_ippref = &gid_address_ippref (&reid); - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "del")) - is_add = 0; - else if (unformat (line_input, "add")) - ; - else if (unformat (line_input, "reid %U", - unformat_ip_prefix, reid_ippref)) - { - gid_address_type (&reid) = GID_ADDR_IP_PREFIX; - reid_set = 1; - } - else if (unformat (line_input, "reid %U", unformat_mac_address, dmac)) - { - gid_address_type (&reid) = GID_ADDR_MAC; - reid_set = 1; - } - else if (unformat (line_input, "vni %u", &vni)) - { - gid_address_vni (&leid) = vni; - gid_address_vni (&reid) = vni; - } - else if (unformat (line_input, "leid %U", - unformat_ip_prefix, leid_ippref)) - { - gid_address_type (&leid) = GID_ADDR_IP_PREFIX; - leid_set = 1; - } - else if (unformat (line_input, "leid %U", unformat_mac_address, smac)) - { - gid_address_type (&leid) = GID_ADDR_MAC; - leid_set = 1; - } - else - { - clib_warning ("parse error"); - goto done; - } - } - - if (!reid_set || !leid_set) - { - clib_warning ("missing remote or local eid!"); - goto done; - } - - if ((gid_address_type (&leid) != gid_address_type (&reid)) - || (gid_address_type (&reid) == GID_ADDR_IP_PREFIX - && ip_prefix_version (reid_ippref) - != ip_prefix_version (leid_ippref))) - { - clib_warning ("remote and local EIDs are of different types!"); - goto done; - } - - clib_memset (a, 0, sizeof (a[0])); - gid_address_copy (&a->leid, &leid); - gid_address_copy (&a->reid, &reid); - a->is_add = is_add; - - if (vnet_lisp_add_del_adjacency (a)) - clib_warning ("failed to %s adjacency!", is_add ? "add" : "delete"); - -done: - unformat_free (line_input); - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (lisp_add_del_adjacency_command) = { - .path = "lisp adjacency", - .short_help = "lisp adjacency add|del vni reid " - "leid ", - .function = lisp_add_del_adjacency_command_fn, -}; -/* *INDENT-ON* */ - - -static clib_error_t * -lisp_map_request_mode_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - unformat_input_t _i, *i = &_i; - map_request_mode_t mr_mode = _MR_MODE_MAX; - clib_error_t *error = NULL; - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, i)) - return 0; - - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "dst-only")) - mr_mode = MR_MODE_DST_ONLY; - else if (unformat (i, "src-dst")) - mr_mode = MR_MODE_SRC_DST; - else - { - clib_warning ("parse error '%U'", format_unformat_error, i); - goto done; - } - } - - if (_MR_MODE_MAX == mr_mode) - { - clib_warning ("No LISP map request mode entered!"); - goto done; - } - - vnet_lisp_set_map_request_mode (mr_mode); - -done: - unformat_free (i); - - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (lisp_map_request_mode_command) = { - .path = "lisp map-request mode", - .short_help = "lisp map-request mode dst-only|src-dst", - .function = lisp_map_request_mode_command_fn, -}; -/* *INDENT-ON* */ - - -static u8 * -format_lisp_map_request_mode (u8 * s, va_list * args) -{ - u32 mode = va_arg (*args, u32); - - switch (mode) - { - case 0: - return format (0, "dst-only"); - case 1: - return format (0, "src-dst"); - } - return 0; -} - -static clib_error_t * -lisp_show_map_request_mode_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - vlib_cli_output (vm, "map-request mode: %U", format_lisp_map_request_mode, - vnet_lisp_get_map_request_mode ()); - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (lisp_show_map_request_mode_command) = { - .path = "show lisp map-request mode", - .short_help = "show lisp map-request mode", - .function = lisp_show_map_request_mode_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_show_map_resolvers_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - lisp_msmr_t *mr; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - - vec_foreach (mr, lcm->map_resolvers) - { - vlib_cli_output (vm, "%U", format_ip_address, &mr->address); - } - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (lisp_show_map_resolvers_command) = { - .path = "show lisp map-resolvers", - .short_help = "show lisp map-resolvers", - .function = lisp_show_map_resolvers_command_fn, -}; -/* *INDENT-ON* */ - - -static clib_error_t * -lisp_pitr_set_locator_set_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - u8 locator_name_set = 0; - u8 *locator_set_name = 0; - u8 is_add = 1; - unformat_input_t _line_input, *line_input = &_line_input; - clib_error_t *error = 0; - int rv = 0; - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return 0; - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "ls %_%v%_", &locator_set_name)) - locator_name_set = 1; - else if (unformat (line_input, "disable")) - is_add = 0; - else - { - error = clib_error_return (0, "parse error"); - goto done; - } - } - - if (!locator_name_set) - { - clib_warning ("No locator set specified!"); - goto done; - } - vec_terminate_c_string (locator_set_name); - rv = vnet_lisp_pitr_set_locator_set (locator_set_name, is_add); - if (0 != rv) - { - error = clib_error_return (0, "failed to %s pitr!", - is_add ? "add" : "delete"); - } - -done: - if (locator_set_name) - vec_free (locator_set_name); - unformat_free (line_input); - - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (lisp_pitr_set_locator_set_command) = { - .path = "lisp pitr", - .short_help = "lisp pitr [disable] ls ", - .function = lisp_pitr_set_locator_set_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_show_pitr_command_fn (vlib_main_t * vm, - unformat_input_t * input, vlib_cli_command_t * cmd) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - mapping_t *m; - locator_set_t *ls; - u8 *tmp_str = 0; - u8 status = lcm->flags & LISP_FLAG_PITR_MODE; - - vlib_cli_output (vm, "%=20s%=16s", "pitr", status ? "locator-set" : ""); - - if (!status) - { - vlib_cli_output (vm, "%=20s", "disable"); - return 0; - } - - if (~0 == lcm->pitr_map_index) - { - tmp_str = format (0, "N/A"); - } - else - { - m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index); - if (~0 != m->locator_set_index) - { - ls = - pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index); - tmp_str = format (0, "%s", ls->name); - } - else - { - tmp_str = format (0, "N/A"); - } - } - vec_add1 (tmp_str, 0); - - vlib_cli_output (vm, "%=20s%=16s", "enable", tmp_str); - - vec_free (tmp_str); - - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (lisp_show_pitr_command) = { - .path = "show lisp pitr", - .short_help = "Show pitr", - .function = lisp_show_pitr_command_fn, -}; -/* *INDENT-ON* */ - -static u8 * -format_eid_entry (u8 * s, va_list * args) -{ - vnet_main_t *vnm = va_arg (*args, vnet_main_t *); - lisp_cp_main_t *lcm = va_arg (*args, lisp_cp_main_t *); - mapping_t *mapit = va_arg (*args, mapping_t *); - locator_set_t *ls = va_arg (*args, locator_set_t *); - gid_address_t *gid = &mapit->eid; - u32 ttl = mapit->ttl; - u8 aut = mapit->authoritative; - u32 *loc_index; - u8 first_line = 1; - u8 *loc; - - u8 *type = ls->local ? format (0, "local(%s)", ls->name) - : format (0, "remote"); - - if (vec_len (ls->locator_indices) == 0) - { - s = format (s, "%-35U%-30s%-20u%-u", format_gid_address, gid, - type, ttl, aut); - } - else - { - vec_foreach (loc_index, ls->locator_indices) - { - locator_t *l = pool_elt_at_index (lcm->locator_pool, loc_index[0]); - if (l->local) - loc = format (0, "%U", format_vnet_sw_if_index_name, vnm, - l->sw_if_index); - else - loc = format (0, "%U", format_ip_address, - &gid_address_ip (&l->address)); - - if (first_line) - { - s = format (s, "%-35U%-20s%-30v%-20u%-u\n", format_gid_address, - gid, type, loc, ttl, aut); - first_line = 0; - } - else - s = format (s, "%55s%v\n", "", loc); - } - } - return s; -} - -static clib_error_t * -lisp_show_eid_table_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - mapping_t *mapit; - unformat_input_t _line_input, *line_input = &_line_input; - u32 mi; - gid_address_t eid; - u8 print_all = 1; - u8 filter = 0; - clib_error_t *error = NULL; - - clib_memset (&eid, 0, sizeof (eid)); - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return 0; - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "eid %U", unformat_gid_address, &eid)) - print_all = 0; - else if (unformat (line_input, "local")) - filter = 1; - else if (unformat (line_input, "remote")) - filter = 2; - else - { - error = clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); - goto done; - } - } - - vlib_cli_output (vm, "%-35s%-20s%-30s%-20s%-s", - "EID", "type", "locators", "ttl", "authoritative"); - - if (print_all) - { - /* *INDENT-OFF* */ - pool_foreach (mapit, lcm->mapping_pool, - ({ - if (mapit->pitr_set) - continue; - - locator_set_t * ls = pool_elt_at_index (lcm->locator_set_pool, - mapit->locator_set_index); - if (filter && !((1 == filter && ls->local) || - (2 == filter && !ls->local))) - { - continue; - } - vlib_cli_output (vm, "%U", format_eid_entry, lcm->vnet_main, - lcm, mapit, ls); - })); - /* *INDENT-ON* */ - } - else - { - mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &eid); - if ((u32) ~ 0 == mi) - goto done; - - mapit = pool_elt_at_index (lcm->mapping_pool, mi); - locator_set_t *ls = pool_elt_at_index (lcm->locator_set_pool, - mapit->locator_set_index); - - if (filter && !((1 == filter && ls->local) || - (2 == filter && !ls->local))) - { - goto done; - } - - vlib_cli_output (vm, "%U,", format_eid_entry, lcm->vnet_main, - lcm, mapit, ls); - } - -done: - unformat_free (line_input); - - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (lisp_cp_show_eid_table_command) = { - .path = "show lisp eid-table", - .short_help = "show lisp eid-table [local|remote|eid ]", - .function = lisp_show_eid_table_command_fn, -}; -/* *INDENT-ON* */ - - -static clib_error_t * -lisp_enable_command_fn (vlib_main_t * vm, unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) - return clib_error_return (0, "parse error: '%U'", format_unformat_error, - input); - - vnet_lisp_enable_disable (1); - - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (lisp_cp_enable_command) = { - .path = "lisp enable", - .short_help = "lisp enable", - .function = lisp_enable_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_disable_command_fn (vlib_main_t * vm, unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) - return clib_error_return (0, "parse error: '%U'", format_unformat_error, - input); - - vnet_lisp_enable_disable (0); - - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (lisp_cp_disable_command) = { - .path = "lisp disable", - .short_help = "lisp disable", - .function = lisp_disable_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_map_register_enable_disable_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - unformat_input_t _line_input, *line_input = &_line_input; - u8 is_enabled = 0; - u8 is_set = 0; - clib_error_t *error = NULL; - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return clib_error_return (0, "expected enable | disable"); - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "enable")) - { - is_set = 1; - is_enabled = 1; - } - else if (unformat (line_input, "disable")) - is_set = 1; - else - { - vlib_cli_output (vm, "parse error: '%U'", format_unformat_error, - line_input); - goto done; - } - } - - if (!is_set) - { - vlib_cli_output (vm, "state not set!"); - goto done; - } - - vnet_lisp_map_register_enable_disable (is_enabled); - -done: - unformat_free (line_input); - - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (lisp_map_register_enable_disable_command) = { - .path = "lisp map-register", - .short_help = "lisp map-register [enable|disable]", - .function = lisp_map_register_enable_disable_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_rloc_probe_enable_disable_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - unformat_input_t _line_input, *line_input = &_line_input; - u8 is_enabled = 0; - u8 is_set = 0; - clib_error_t *error = NULL; - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return clib_error_return (0, "expected enable | disable"); - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "enable")) - { - is_set = 1; - is_enabled = 1; - } - else if (unformat (line_input, "disable")) - is_set = 1; - else - { - vlib_cli_output (vm, "parse error: '%U'", format_unformat_error, - line_input); - goto done; - } - } - - if (!is_set) - { - vlib_cli_output (vm, "state not set!"); - goto done; - } - - vnet_lisp_rloc_probe_enable_disable (is_enabled); - -done: - unformat_free (line_input); - - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (lisp_rloc_probe_enable_disable_command) = { - .path = "lisp rloc-probe", - .short_help = "lisp rloc-probe [enable|disable]", - .function = lisp_rloc_probe_enable_disable_command_fn, -}; -/* *INDENT-ON* */ - -static u8 * -format_lisp_status (u8 * s, va_list * args) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - return format (s, "%s", lcm->is_enabled ? "enabled" : "disabled"); -} - -static clib_error_t * -lisp_show_status_command_fn (vlib_main_t * vm, unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - u8 *msg = 0; - msg = format (msg, "feature: %U\ngpe: %U\n", - format_lisp_status, format_vnet_lisp_gpe_status); - vlib_cli_output (vm, "%v", msg); - vec_free (msg); - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (lisp_show_status_command) = { - .path = "show lisp status", - .short_help = "show lisp status", - .function = lisp_show_status_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_show_eid_table_map_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - hash_pair_t *p; - unformat_input_t _line_input, *line_input = &_line_input; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - uword *vni_table = 0; - u8 is_l2 = 0; - clib_error_t *error = NULL; - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return 0; - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "l2")) - { - vni_table = lcm->bd_id_by_vni; - is_l2 = 1; - } - else if (unformat (line_input, "l3")) - { - vni_table = lcm->table_id_by_vni; - is_l2 = 0; - } - else - { - error = clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); - goto done; - } - } - - if (!vni_table) - { - vlib_cli_output (vm, "Error: expected l2|l3 param!\n"); - goto done; - } - - vlib_cli_output (vm, "%=10s%=10s", "VNI", is_l2 ? "BD" : "VRF"); - - /* *INDENT-OFF* */ - hash_foreach_pair (p, vni_table, - ({ - vlib_cli_output (vm, "%=10d%=10d", p->key, p->value[0]); - })); - /* *INDENT-ON* */ - -done: - unformat_free (line_input); - - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (lisp_show_eid_table_map_command) = { - .path = "show lisp eid-table map", - .short_help = "show lisp eid-table map l2|l3", - .function = lisp_show_eid_table_map_command_fn, -}; -/* *INDENT-ON* */ - - -static clib_error_t * -lisp_add_del_locator_set_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - lisp_gpe_main_t *lgm = &lisp_gpe_main; - vnet_main_t *vnm = lgm->vnet_main; - unformat_input_t _line_input, *line_input = &_line_input; - u8 is_add = 1; - clib_error_t *error = 0; - u8 *locator_set_name = 0; - locator_t locator, *locators = 0; - vnet_lisp_add_del_locator_set_args_t _a, *a = &_a; - u32 ls_index = 0; - int rv = 0; - - clib_memset (&locator, 0, sizeof (locator)); - clib_memset (a, 0, sizeof (a[0])); - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return clib_error_return (0, "missing parameters"); - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "add %_%v%_", &locator_set_name)) - is_add = 1; - else if (unformat (line_input, "del %_%v%_", &locator_set_name)) - is_add = 0; - else if (unformat (line_input, "iface %U p %d w %d", - unformat_vnet_sw_interface, vnm, - &locator.sw_if_index, &locator.priority, - &locator.weight)) - { - locator.local = 1; - locator.state = 1; - vec_add1 (locators, locator); - } - else - { - error = unformat_parse_error (line_input); - goto done; - } - } - - vec_terminate_c_string (locator_set_name); - a->name = locator_set_name; - a->locators = locators; - a->is_add = is_add; - a->local = 1; - - rv = vnet_lisp_add_del_locator_set (a, &ls_index); - if (0 != rv) - { - error = clib_error_return (0, "failed to %s locator-set!", - is_add ? "add" : "delete"); - } - -done: - vec_free (locators); - if (locator_set_name) - vec_free (locator_set_name); - unformat_free (line_input); - - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (lisp_cp_add_del_locator_set_command) = { - .path = "lisp locator-set", - .short_help = "lisp locator-set add/del [iface " - "p w ]", - .function = lisp_add_del_locator_set_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_add_del_locator_in_set_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - lisp_gpe_main_t *lgm = &lisp_gpe_main; - vnet_main_t *vnm = lgm->vnet_main; - unformat_input_t _line_input, *line_input = &_line_input; - u8 is_add = 1; - clib_error_t *error = 0; - u8 *locator_set_name = 0; - u8 locator_set_name_set = 0; - locator_t locator, *locators = 0; - vnet_lisp_add_del_locator_set_args_t _a, *a = &_a; - u32 ls_index = 0; - - clib_memset (&locator, 0, sizeof (locator)); - clib_memset (a, 0, sizeof (a[0])); - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return 0; - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "add")) - is_add = 1; - else if (unformat (line_input, "del")) - is_add = 0; - else if (unformat (line_input, "locator-set %_%v%_", &locator_set_name)) - locator_set_name_set = 1; - else if (unformat (line_input, "iface %U p %d w %d", - unformat_vnet_sw_interface, vnm, - &locator.sw_if_index, &locator.priority, - &locator.weight)) - { - locator.local = 1; - vec_add1 (locators, locator); - } - else - { - error = unformat_parse_error (line_input); - goto done; - } - } - - if (!locator_set_name_set) - { - error = clib_error_return (0, "locator_set name not set!"); - goto done; - } - - a->name = locator_set_name; - a->locators = locators; - a->is_add = is_add; - a->local = 1; - - vnet_lisp_add_del_locator (a, 0, &ls_index); - -done: - vec_free (locators); - vec_free (locator_set_name); - unformat_free (line_input); - - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (lisp_cp_add_del_locator_in_set_command) = { - .path = "lisp locator", - .short_help = "lisp locator add/del locator-set iface " - "p w ", - .function = lisp_add_del_locator_in_set_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_cp_show_locator_sets_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - locator_set_t *lsit; - locator_t *loc; - u32 *locit; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - - vlib_cli_output (vm, "%s%=16s%=16s%=16s", "Locator-set", "Locator", - "Priority", "Weight"); - - /* *INDENT-OFF* */ - pool_foreach (lsit, lcm->locator_set_pool, - ({ - u8 * msg = 0; - int next_line = 0; - if (lsit->local) - { - msg = format (msg, "%v", lsit->name); - } - else - { - msg = format (msg, "<%s-%d>", "remote", lsit - lcm->locator_set_pool); - } - vec_foreach (locit, lsit->locator_indices) - { - if (next_line) - { - msg = format (msg, "%16s", " "); - } - loc = pool_elt_at_index (lcm->locator_pool, locit[0]); - if (loc->local) - msg = format (msg, "%16d%16d%16d\n", loc->sw_if_index, loc->priority, - loc->weight); - else - msg = format (msg, "%16U%16d%16d\n", format_ip_address, - &gid_address_ip(&loc->address), loc->priority, - loc->weight); - next_line = 1; - } - vlib_cli_output (vm, "%v", msg); - vec_free (msg); - })); - /* *INDENT-ON* */ - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (lisp_cp_show_locator_sets_command) = { - .path = "show lisp locator-set", - .short_help = "Shows locator-sets", - .function = lisp_cp_show_locator_sets_command_fn, -}; -/* *INDENT-ON* */ - - -static clib_error_t * -lisp_add_del_map_resolver_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - unformat_input_t _line_input, *line_input = &_line_input; - u8 is_add = 1, addr_set = 0; - ip_address_t ip_addr; - clib_error_t *error = 0; - int rv = 0; - vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a; - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return 0; - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "add")) - is_add = 1; - else if (unformat (line_input, "del")) - is_add = 0; - else if (unformat (line_input, "%U", unformat_ip_address, &ip_addr)) - addr_set = 1; - else - { - error = unformat_parse_error (line_input); - goto done; - } - } - - if (!addr_set) - { - error = clib_error_return (0, "Map-resolver address must be set!"); - goto done; - } - - a->is_add = is_add; - a->address = ip_addr; - rv = vnet_lisp_add_del_map_resolver (a); - if (0 != rv) - { - error = clib_error_return (0, "failed to %s map-resolver!", - is_add ? "add" : "delete"); - } - -done: - unformat_free (line_input); - - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (lisp_add_del_map_resolver_command) = { - .path = "lisp map-resolver", - .short_help = "lisp map-resolver add/del ", - .function = lisp_add_del_map_resolver_command_fn, -}; -/* *INDENT-ON* */ - - -static clib_error_t * -lisp_add_del_mreq_itr_rlocs_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - unformat_input_t _line_input, *line_input = &_line_input; - u8 is_add = 1; - u8 *locator_set_name = 0; - clib_error_t *error = 0; - int rv = 0; - vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a; - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return 0; - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "del")) - is_add = 0; - else if (unformat (line_input, "add %_%v%_", &locator_set_name)) - is_add = 1; - else - { - error = unformat_parse_error (line_input); - goto done; - } - } - - vec_terminate_c_string (locator_set_name); - a->is_add = is_add; - a->locator_set_name = locator_set_name; - rv = vnet_lisp_add_del_mreq_itr_rlocs (a); - if (0 != rv) - { - error = clib_error_return (0, "failed to %s map-request itr-rlocs!", - is_add ? "add" : "delete"); - } - -done: - vec_free (locator_set_name); - unformat_free (line_input); - - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (lisp_add_del_map_request_command) = { - .path = "lisp map-request itr-rlocs", - .short_help = "lisp map-request itr-rlocs add/del ", - .function = lisp_add_del_mreq_itr_rlocs_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_show_mreq_itr_rlocs_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - locator_set_t *loc_set; - - vlib_cli_output (vm, "%=20s", "itr-rlocs"); - - if (~0 == lcm->mreq_itr_rlocs) - { - return 0; - } - - loc_set = pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs); - - vlib_cli_output (vm, "%=20s", loc_set->name); - - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (lisp_show_map_request_command) = { - .path = "show lisp map-request itr-rlocs", - .short_help = "Shows map-request itr-rlocs", - .function = lisp_show_mreq_itr_rlocs_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_use_petr_set_locator_set_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - u8 is_add = 1, ip_set = 0; - unformat_input_t _line_input, *line_input = &_line_input; - clib_error_t *error = 0; - ip_address_t ip; - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return 0; - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "%U", unformat_ip_address, &ip)) - ip_set = 1; - else if (unformat (line_input, "disable")) - is_add = 0; - else - { - error = clib_error_return (0, "parse error"); - goto done; - } - } - - if (!ip_set) - { - clib_warning ("No petr IP specified!"); - goto done; - } - - if (vnet_lisp_use_petr (&ip, is_add)) - { - error = clib_error_return (0, "failed to %s petr!", - is_add ? "add" : "delete"); - } - -done: - unformat_free (line_input); - - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (lisp_use_petr_set_locator_set_command) = { - .path = "lisp use-petr", - .short_help = "lisp use-petr [disable] ", - .function = lisp_use_petr_set_locator_set_command_fn, -}; - -static clib_error_t * -lisp_show_petr_command_fn (vlib_main_t * vm, - unformat_input_t * input, vlib_cli_command_t * cmd) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - mapping_t *m; - locator_set_t *ls; - locator_t *loc; - u8 *tmp_str = 0; - u8 use_petr = lcm->flags & LISP_FLAG_USE_PETR; - vlib_cli_output (vm, "%=20s%=16s", "petr", use_petr ? "ip" : ""); - - if (!use_petr) - { - vlib_cli_output (vm, "%=20s", "disable"); - return 0; - } - - if (~0 == lcm->petr_map_index) - { - tmp_str = format (0, "N/A"); - } - else - { - m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index); - if (~0 != m->locator_set_index) - { - ls = pool_elt_at_index(lcm->locator_set_pool, m->locator_set_index); - loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]); - tmp_str = format (0, "%U", format_ip_address, &loc->address); - } - else - { - tmp_str = format (0, "N/A"); - } - } - vec_add1 (tmp_str, 0); - - vlib_cli_output (vm, "%=20s%=16s", "enable", tmp_str); - - vec_free (tmp_str); - - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (lisp_show_petr_command) = { - .path = "show lisp petr", - .short_help = "Show petr", - .function = lisp_show_petr_command_fn, -}; -/* *INDENT-ON* */ - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/src/vnet/lisp-cp/lisp_cp_dpo.c b/src/vnet/lisp-cp/lisp_cp_dpo.c deleted file mode 100644 index 848f621e35f..00000000000 --- a/src/vnet/lisp-cp/lisp_cp_dpo.c +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -/** - * The static array of LISP punt DPOs - */ -static dpo_id_t lisp_cp_dpos[DPO_PROTO_NUM]; - -const dpo_id_t * -lisp_cp_dpo_get (dpo_proto_t proto) -{ - /* - * there are only two instances of this DPO type. - * we can use the protocol as the index - */ - return (&lisp_cp_dpos[proto]); -} - -static u8 * -format_lisp_cp_dpo (u8 * s, va_list * args) -{ - index_t index = va_arg (*args, index_t); - CLIB_UNUSED (u32 indent) = va_arg (*args, u32); - - return (format (s, "lisp-cp-punt-%U", format_dpo_proto, index)); -} - -static void -lisp_cp_dpo_lock (dpo_id_t * dpo) -{ -} - -static void -lisp_cp_dpo_unlock (dpo_id_t * dpo) -{ -} - -const static dpo_vft_t lisp_cp_vft = { - .dv_lock = lisp_cp_dpo_lock, - .dv_unlock = lisp_cp_dpo_unlock, - .dv_format = format_lisp_cp_dpo, -}; - -/** - * @brief The per-protocol VLIB graph nodes that are assigned to a LISP-CP - * object. - * - * this means that these graph nodes are ones from which a LISP-CP is the - * parent object in the DPO-graph. - */ -const static char *const lisp_cp_ip4_nodes[] = { - "lisp-cp-lookup-ip4", - NULL, -}; - -const static char *const lisp_cp_ip6_nodes[] = { - "lisp-cp-lookup-ip6", - NULL, -}; - -const static char *const lisp_cp_ethernet_nodes[] = { - "lisp-cp-lookup-l2", - NULL, -}; - -const static char *const lisp_cp_nsh_nodes[] = { - "lisp-cp-lookup-nsh", - NULL, -}; - -const static char *const *const lisp_cp_nodes[DPO_PROTO_NUM] = { - [DPO_PROTO_IP4] = lisp_cp_ip4_nodes, - [DPO_PROTO_IP6] = lisp_cp_ip6_nodes, - [DPO_PROTO_ETHERNET] = lisp_cp_ethernet_nodes, - [DPO_PROTO_MPLS] = NULL, - [DPO_PROTO_NSH] = lisp_cp_nsh_nodes, -}; - -clib_error_t * -lisp_cp_dpo_module_init (vlib_main_t * vm) -{ - dpo_proto_t dproto; - - /* - * there are no exit arcs from the LIS-CP VLIB node, so we - * pass NULL as said node array. - */ - dpo_register (DPO_LISP_CP, &lisp_cp_vft, lisp_cp_nodes); - - FOR_EACH_DPO_PROTO (dproto) - { - dpo_set (&lisp_cp_dpos[dproto], DPO_LISP_CP, dproto, dproto); - } - - return (NULL); -} - -VLIB_INIT_FUNCTION (lisp_cp_dpo_module_init); - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/src/vnet/lisp-cp/lisp_cp_dpo.h b/src/vnet/lisp-cp/lisp_cp_dpo.h deleted file mode 100644 index f0f3fae81a4..00000000000 --- a/src/vnet/lisp-cp/lisp_cp_dpo.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __LISP_CP_DPO_H__ -#define __LISP_CP_DPO_H__ - -#include -#include - -/** - * A representation of punt to the LISP control plane. - */ -typedef struct lisp_cp_dpo_t -{ - /** - * The transport payload type. - */ - dpo_proto_t lcd_proto; -} lisp_cp_dpo_t; - -extern const dpo_id_t *lisp_cp_dpo_get (dpo_proto_t proto); - -extern void lisp_cp_dpo_module_init (void); - -#endif - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/src/vnet/lisp-cp/lisp_cp_messages.h b/src/vnet/lisp-cp/lisp_cp_messages.h deleted file mode 100644 index 69510a0e1ce..00000000000 --- a/src/vnet/lisp-cp/lisp_cp_messages.h +++ /dev/null @@ -1,644 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef VNET_LISP_GPE_LISP_CP_MESSAGES_H_ -#define VNET_LISP_GPE_LISP_CP_MESSAGES_H_ - -#include - -#define MAX_IP_PKT_LEN 4096 -#define MAX_IP_HDR_LEN 40 /* without options or IPv6 hdr extensions */ -#define UDP_HDR_LEN 8 -#define LISP_DATA_HDR_LEN 8 -#define LISP_ECM_HDR_LEN 4 -#define MAX_LISP_MSG_ENCAP_LEN 2*(MAX_IP_HDR_LEN + UDP_HDR_LEN)+ LISP_ECM_HDR_LEN -#define MAX_LISP_PKT_ENCAP_LEN MAX_IP_HDR_LEN + UDP_HDR_LEN + LISP_DATA_HDR_LEN - -#define LISP_CONTROL_PORT 4342 - -/* - * EID RECORD FIELD - */ - -/* - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * / | Reserved | EID mask-len | EID-prefix-AFI | - * Rec +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * \ | EID-prefix ... | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - - -typedef struct _eid_prefix_record_hdr -{ - u8 reserved; - u8 eid_prefix_length; -} __attribute__ ((__packed__)) eid_record_hdr_t; - -void eid_rec_hdr_init (eid_record_hdr_t * ptr); - -#define EID_REC_CAST(h_) ((eid_record_hdr_t *)(h_)) -#define EID_REC_MLEN(h_) EID_REC_CAST((h_))->eid_prefix_length -#define EID_REC_ADDR(h) (u8 *)(h) + sizeof(eid_record_hdr_t) - -/* LISP Types */ -typedef enum -{ - NOT_LISP_MSG, - LISP_MAP_REQUEST = 1, - LISP_MAP_REPLY, - LISP_MAP_REGISTER, - LISP_MAP_NOTIFY, - LISP_INFO_NAT = 7, - LISP_ENCAP_CONTROL_TYPE = 8, - LISP_MSG_TYPES -} lisp_msg_type_e; - -/* - * ENCAPSULATED CONTROL MESSAGE - */ - -/* - * 0 1 2 3 - * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * / | IPv4 or IPv6 Header | - * OH | (uses RLOC addresses) | - * \ | | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * / | Source Port = xxxx | Dest Port = 4342 | - * UDP +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * \ | UDP Length | UDP Checksum | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * LH |Type=8 |S| Reserved | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * / | IPv4 or IPv6 Header | - * IH | (uses RLOC or EID addresses) | - * \ | | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * / | Source Port = xxxx | Dest Port = yyyy | - * UDP +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * \ | UDP Length | UDP Checksum | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * LCM | LISP Control Message | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - - -/* - * Encapsulated control message header. This is followed by the IP - * header of the encapsulated LISP control message. - * - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * |Type=8 |S| Reserved | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - -typedef struct -{ -#if CLIB_ARCH_IS_LITTLE_ENDIAN - u8 reserved:3; - u8 s_bit:1; - u8 type:4; -#else - u8 type:4; - u8 s_bit:1; - u8 reserved:3; -#endif - u8 reserved2[3]; -} ecm_hdr_t; - -char *ecm_hdr_to_char (ecm_hdr_t * h); - -#define ECM_TYPE(h_) ((ecm_hdr_t *)(h_))->type - -/* - * MAP-REQUEST MESSAGE - */ - -/* - * Map-Request Message Format - * - * 0 1 2 3 - * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * |Type=1 |A|M|P|S|p|s| Reserved | IRC | Record Count | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Nonce . . . | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | . . . Nonce | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Source-EID-AFI | Source EID Address ... | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | ITR-RLOC-AFI 1 | ITR-RLOC Address 1 ... | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | ... | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | ITR-RLOC-AFI n | ITR-RLOC Address n ... | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * / | Reserved | EID mask-len | EID-prefix-AFI | - * Rec +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * \ | EID-prefix ... | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Map-Reply Record ... | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Mapping Protocol Data | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - - -/* - * Fixed size portion of the map request. Variable size source EID - * address, originating ITR RLOC AFIs and addresses and then map - * request records follow. - */ -typedef struct -{ -#if CLIB_ARCH_IS_LITTLE_ENDIAN - u8 solicit_map_request:1; - u8 rloc_probe:1; - u8 map_data_present:1; - u8 authoritative:1; - u8 type:4; -#else - u8 type:4; - u8 authoritative:1; - u8 map_data_present:1; - u8 rloc_probe:1; - u8 solicit_map_request:1; -#endif -#if CLIB_ARCH_IS_LITTLE_ENDIAN - u8 reserved1:6; - u8 smr_invoked:1; - u8 pitr:1; -#else - u8 pitr:1; - u8 smr_invoked:1; - u8 reserved1:6; -#endif -#if CLIB_ARCH_IS_LITTLE_ENDIAN - u8 additional_itr_rloc_count:5; - u8 reserved2:3; -#else - u8 reserved2:3; - u8 additional_itr_rloc_count:5; -#endif - u8 record_count; - u64 nonce; -} __attribute__ ((__packed__)) map_request_hdr_t; - -void map_request_hdr_init (void *ptr); -char *map_request_hdr_to_char (map_request_hdr_t * h); - -#define MREQ_TYPE(h_) (h_)->type -#define MREQ_HDR_CAST(h_) ((map_request_hdr_t *)(h_)) -#define MREQ_REC_COUNT(h_) (MREQ_HDR_CAST(h_))->record_count -#define MREQ_RLOC_PROBE(h_) (MREQ_HDR_CAST(h_))->rloc_probe -#define MREQ_ITR_RLOC_COUNT(h_) (MREQ_HDR_CAST(h_))->additional_itr_rloc_count -#define MREQ_NONCE(h_) (MREQ_HDR_CAST(h_))->nonce -#define MREQ_SMR(h_) (MREQ_HDR_CAST(h_))->solicit_map_request -#define MREQ_SMR_INVOKED(h_) (MREQ_HDR_CAST(h_))->smr_invoked - -/* - * MAP-REPLY MESSAGE - */ - - /* - * Map-Reply Message Format - * - * 0 1 2 3 - * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * |Type=2 |P|E|S| Reserved | Record Count | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Nonce . . . | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | . . . Nonce | - * +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | | Record TTL | - * | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * R | Locator Count | EID mask-len | ACT |A| Reserved | - * e +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * c | Rsvd | Map-Version Number | EID-AFI | - * o +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * r | EID-prefix | - * d +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | /| Priority | Weight | M Priority | M Weight | - * | L +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | o | Unused Flags |L|p|R| Loc-AFI | - * | c +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | \| Locator | - * +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Mapping Protocol Data | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - - /* - * Fixed size portion of the map reply. - */ -typedef struct -{ -#if CLIB_ARCH_IS_LITTLE_ENDIAN - u8 reserved1:1; - u8 security:1; - u8 echo_nonce:1; - u8 rloc_probe:1; - u8 type:4; -#else - u8 type:4; - u8 rloc_probe:1; - u8 echo_nonce:1; - u8 security:1; - u8 reserved1:1; -#endif - u8 reserved2; - u8 reserved3; - u8 record_count; - u64 nonce; -} __attribute__ ((__packed__)) map_reply_hdr_t; - -void map_reply_hdr_init (void *ptr); -char *map_reply_hdr_to_char (map_reply_hdr_t * h); - -#define MREP_TYPE(h_) MREP_HDR_CAST(h_)->type -#define MREP_HDR_CAST(h_) ((map_reply_hdr_t *)(h_)) -#define MREP_REC_COUNT(h_) MREP_HDR_CAST(h_)->record_count -#define MREP_RLOC_PROBE(h_) MREP_HDR_CAST(h_)->rloc_probe -#define MREP_NONCE(h_) MREP_HDR_CAST(h_)->nonce - - -always_inline lisp_msg_type_e -lisp_msg_type (void *b) -{ - ecm_hdr_t *hdr = b; - if (!hdr) - { - return (NOT_LISP_MSG); - } - return (hdr->type); -} - -always_inline void -increment_record_count (void *b) -{ - switch (lisp_msg_type (b)) - { - case LISP_MAP_REQUEST: - MREQ_REC_COUNT (b) += 1; - break; - case LISP_MAP_REPLY: - MREP_REC_COUNT (b) += 1; - break; - default: - return; - } -} - - -/* - * LOCATOR FIELD - * - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * /| Priority | Weight | M Priority | M Weight | - * L +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * o | Unused Flags |L|p|R| Loc-AFI | - * c +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * \| Locator | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * - * Fixed portion of the mapping record locator. Variable length - * locator address follows. - */ -typedef struct _locator_hdr -{ - u8 priority; - u8 weight; - u8 mpriority; - u8 mweight; - u8 unused1; -#ifdef CLIB_ARCH_IS_LITTLE_ENDIAN - u8 reachable:1; - u8 probed:1; - u8 local:1; - u8 unused2:5; -#else - u8 unused2:5; - u8 local:1; - u8 probed:1; - u8 reachable:1; -#endif -} __attribute__ ((__packed__)) locator_hdr_t; - -#define LOC_CAST(h_) ((locator_hdr_t *)(h_)) -#define LOC_PROBED(h_) LOC_CAST(h_)->probed -#define LOC_PRIORITY(h_) LOC_CAST(h_)->priority -#define LOC_WEIGHT(h_) LOC_CAST(h_)->weight -#define LOC_MPRIORITY(h_) LOC_CAST(h_)->mpriority -#define LOC_MWEIGHT(h_) LOC_CAST(h_)->mweight -#define LOC_REACHABLE(h_) LOC_CAST(h_)->reachable -#define LOC_LOCAL(h_) LOC_CAST(h_)->local -#define LOC_ADDR(h_) ((u8 *)(h_) + sizeof(locator_hdr_t)) - -/* - * MAPPING RECORD - * - * Mapping record used in all LISP control messages. - * - * +---> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | | Record TTL | - * | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * R | Locator Count | EID mask-len | ACT |A| Reserved | - * e +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * c | Rsvd | Map-Version Number | EID-AFI | - * o +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * r | EID-prefix | - * d +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | /| Priority | Weight | M Priority | M Weight | - * | / +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Loc | Unused Flags |L|p|R| Loc-AFI | - * | \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | \| Locator | - * +---> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - -/* - * Fixed portion of the mapping record. EID prefix address and - * locators follow. - */ - -typedef struct _mapping_record_hdr_t -{ - u32 ttl; - u8 locator_count; - u8 eid_prefix_length; -#ifdef CLIB_ARCH_IS_LITTLE_ENDIAN - u8 reserved1:4; - u8 authoritative:1; - u8 action:3; -#else - u8 action:3; - u8 authoritative:1; - u8 reserved1:4; -#endif - u8 reserved2; -#ifdef CLIB_ARCH_IS_LITTLE_ENDIAN - u8 version_hi:4; - u8 reserved3:4; -#else - u8 reserved3:4; - u8 version_hi:4; -#endif - u8 version_low; -} __attribute__ ((__packed__)) mapping_record_hdr_t; - -void mapping_record_init_hdr (mapping_record_hdr_t * h); - -#define MAP_REC_EID_PLEN(h) ((mapping_record_hdr_t *)(h))->eid_prefix_length -#define MAP_REC_LOC_COUNT(h) ((mapping_record_hdr_t *)(h))->locator_count -#define MAP_REC_ACTION(h) ((mapping_record_hdr_t *)(h))->action -#define MAP_REC_AUTH(h) ((mapping_record_hdr_t *)(h))->authoritative -#define MAP_REC_TTL(h) ((mapping_record_hdr_t *)(h))->ttl -#define MAP_REC_EID(h) (u8 *)(h)+sizeof(mapping_record_hdr_t) -#define MAP_REC_VERSION(h) (h)->version_hi << 8 | (h)->version_low - -typedef enum -{ - LISP_NO_ACTION, - LISP_FORWARD_NATIVE, - LISP_SEND_MAP_REQUEST, - LISP_DROP -} lisp_action_e; - -typedef enum lisp_authoritative -{ - A_NO_AUTHORITATIVE = 0, - A_AUTHORITATIVE -} lisp_authoritative_e; - -/* - * LISP Canonical Address Format Encodings - * - * 0 1 2 3 - * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | AFI = 16387 | Rsvd1 | Flags | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Type | Rsvd2 | Length | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - -typedef struct _lcaf_hdr_t -{ - u8 reserved1; - u8 flags; - u8 type; - u8 reserved2; - u16 len; -} __attribute__ ((__packed__)) lcaf_hdr_t; - -#define LCAF_TYPE(h) ((lcaf_hdr_t *)(h))->type -#define LCAF_LENGTH(h) ((lcaf_hdr_t *)(h))->len -#define LCAF_RES2(h) ((lcaf_hdr_t *)(h))->reserved2 -#define LCAF_FLAGS(h) ((lcaf_hdr_t *)(h))->flags -#define LCAF_PAYLOAD(h) (u8 *)(h)+sizeof(lcaf_hdr_t) - -/* - * Source/Dest Key Canonical Address Format: - * - * 0 1 2 3 - * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Reserved | Source-ML | Dest-ML | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ -typedef struct _lcaf_src_dst_hdr_t -{ - u16 reserved; - u8 src_mask_len; - u8 dst_mask_len; -} __attribute__ ((__packed__)) lcaf_src_dst_hdr_t; - -#define LCAF_SD_SRC_ML(_h) (_h)->src_mask_len -#define LCAF_SD_DST_ML(_h) (_h)->dst_mask_len - -/* - * SPI LCAF - * - * 0 1 2 3 - * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Service Path ID | Service index | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ -typedef struct _lcaf_spi_hdr_t -{ - u32 spi_si; -} __attribute__ ((__packed__)) lcaf_spi_hdr_t; - -#define LCAF_SPI_SI(_h) (_h)->spi_si - -/* - * The Map-Register message format is: - * - * 0 1 2 3 - * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * |Type=3 |P| Reserved |M| Record Count | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Nonce . . . | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | . . . Nonce | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Key ID | Authentication Data Length | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * ~ Authentication Data ~ - * +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | | Record TTL | - * | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * R | Locator Count | EID mask-len | ACT |A| Reserved | - * e +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * c | Rsvd | Map-Version Number | EID-Prefix-AFI | - * o +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * r | EID-Prefix | - * d +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | /| Priority | Weight | M Priority | M Weight | - * | L +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | o | Unused Flags |L|p|R| Loc-AFI | - * | c +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | \| Locator | - * +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ -typedef struct -{ -#if CLIB_ARCH_IS_LITTLE_ENDIAN - u8 res1:3; - u8 proxy_map_reply:1; - u8 type:4; -#else - u8 type:4; - u8 proxy_map_reply:1; - u8 res1:3; -#endif - - u8 res2; - -#if CLIB_ARCH_IS_LITTLE_ENDIAN - u8 want_map_notify:1; - u8 res3:7; -#else - u8 res3:7; - u8 want_map_notify:1; -#endif - - u8 record_count; - u64 nonce; - u16 key_id; - u16 auth_data_len; - u8 data[0]; -} __attribute__ ((__packed__)) map_register_hdr_t; - -#define MREG_TYPE(h_) (h_)->type -#define MREG_HDR_CAST(h_) ((map_register_hdr_t *)(h_)) -#define MREG_PROXY_MR(h_) (MREG_HDR_CAST(h_))->proxy_map_reply -#define MREG_WANT_MAP_NOTIFY(h_) (MREG_HDR_CAST(h_))->want_map_notify -#define MREG_REC_COUNT(h_) (MREG_HDR_CAST(h_))->record_count -#define MREG_NONCE(h_) (MREG_HDR_CAST(h_))->nonce -#define MREG_KEY_ID(h_) (MREG_HDR_CAST(h_))->key_id -#define MREG_AUTH_DATA_LEN(h_) (MREG_HDR_CAST(h_))->auth_data_len -#define MREG_DATA(h_) (MREG_HDR_CAST(h_))->data - -/* - * The Map-Notify message format is: - * - * 0 1 2 3 - * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * |Type=4 | Reserved | Record Count | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Nonce . . . | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | . . . Nonce | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Key ID | Authentication Data Length | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * ~ Authentication Data ~ - * +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | | Record TTL | - * | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * R | Locator Count | EID mask-len | ACT |A| Reserved | - * e +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * c | Rsvd | Map-Version Number | EID-Prefix-AFI | - * o +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * r | EID-Prefix | - * d +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | /| Priority | Weight | M Priority | M Weight | - * | L +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | o | Unused Flags |L|p|R| Loc-AFI | - * | c +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | \| Locator | - * +-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -*/ - -typedef struct -{ -#if CLIB_ARCH_IS_LITTLE_ENDIAN - u8 res1:4; - u8 type:4; -#else - u8 type:4; - u8 res1:4; -#endif - - u16 res2; - - u8 record_count; - u64 nonce; - u16 key_id; - u16 auth_data_len; - u8 data[0]; -} __attribute__ ((__packed__)) map_notify_hdr_t; - -#define MNOTIFY_TYPE(h_) (h_)->type -#define MNOTIFY_HDR_CAST(h_) ((map_register_hdr_t *)(h_)) -#define MNOTIFY_REC_COUNT(h_) (MREG_HDR_CAST(h_))->record_count -#define MNOTIFY_NONCE(h_) (MREG_HDR_CAST(h_))->nonce -#define MNOTIFY_KEY_ID(h_) (MREG_HDR_CAST(h_))->key_id -#define MNOTIFY_AUTH_DATA_LEN(h_) (MREG_HDR_CAST(h_))->auth_data_len -#define MNOTIFY_DATA(h_) (MREG_HDR_CAST(h_))->data - -/* - * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * |Ver|O|C|R|R|R|R|R|R| Length | MD type=0x1 | Next Protocol | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Service Path Identifer | Service Index | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - -typedef struct -{ - u32 header; - u32 spi_si; -} __attribute__ ((__packed__)) lisp_nsh_hdr_t; - -#endif /* VNET_LISP_GPE_LISP_CP_MESSAGES_H_ */ - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/src/vnet/lisp-cp/lisp_msg_serdes.c b/src/vnet/lisp-cp/lisp_msg_serdes.c deleted file mode 100644 index 90afb10b68b..00000000000 --- a/src/vnet/lisp-cp/lisp_msg_serdes.c +++ /dev/null @@ -1,381 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -void *lisp_msg_put_gid (vlib_buffer_t * b, gid_address_t * gid); - -static void -lisp_msg_put_locators (vlib_buffer_t * b, locator_t * locators) -{ - locator_t *loc; - - vec_foreach (loc, locators) - { - u8 *p = vlib_buffer_put_uninit (b, sizeof (locator_hdr_t)); - clib_memset (p, 0, sizeof (locator_hdr_t)); - LOC_PRIORITY (p) = loc->priority; - LOC_MPRIORITY (p) = loc->mpriority; - LOC_WEIGHT (p) = loc->weight; - LOC_MWEIGHT (p) = loc->mweight; - LOC_LOCAL (p) = loc->local; - LOC_PROBED (p) = loc->probed ? 1 : 0; - LOC_REACHABLE (p) = loc->state ? 1 : 0; - lisp_msg_put_gid (b, &loc->address); - } -} - -static void -lisp_msg_put_mapping_record (vlib_buffer_t * b, mapping_t * record) -{ - mapping_record_hdr_t *p = - vlib_buffer_put_uninit (b, sizeof (mapping_record_hdr_t)); - gid_address_t *eid = &record->eid; - - clib_memset (p, 0, sizeof (*p)); - MAP_REC_EID_PLEN (p) = gid_address_len (eid); - MAP_REC_TTL (p) = clib_host_to_net_u32 (MAP_REGISTER_DEFAULT_TTL); - MAP_REC_AUTH (p) = record->authoritative ? 1 : 0; - MAP_REC_LOC_COUNT (p) = vec_len (record->locators); - - lisp_msg_put_gid (b, eid); - lisp_msg_put_locators (b, record->locators); -} - -static void -lisp_msg_put_mreg_records (vlib_buffer_t * b, mapping_t * records) -{ - u32 i; - for (i = 0; i < vec_len (records); i++) - lisp_msg_put_mapping_record (b, &records[i]); -} - -void * -lisp_msg_put_gid (vlib_buffer_t * b, gid_address_t * gid) -{ - u8 *p = 0; - if (!gid) - { - /* insert only src-eid-afi field set to 0 */ - p = vlib_buffer_put_uninit (b, sizeof (u16)); - *(u16 *) p = 0; - } - else - { - p = vlib_buffer_put_uninit (b, gid_address_size_to_put (gid)); - gid_address_put (p, gid); - } - return p; -} - -static void * -lisp_msg_put_itr_rlocs (lisp_cp_main_t * lcm, vlib_buffer_t * b, - gid_address_t * rlocs, u8 * locs_put) -{ - u8 *bp, count = 0; - u32 i; - - bp = vlib_buffer_get_current (b); - for (i = 0; i < vec_len (rlocs); i++) - { - lisp_msg_put_gid (b, &rlocs[i]); - count++; - } - - *locs_put = count - 1; - return bp; -} - -void * -lisp_msg_put_eid_rec (vlib_buffer_t * b, gid_address_t * eid) -{ - eid_record_hdr_t *h = vlib_buffer_put_uninit (b, sizeof (*h)); - - clib_memset (h, 0, sizeof (*h)); - EID_REC_MLEN (h) = gid_address_len (eid); - lisp_msg_put_gid (b, eid); - return h; -} - -u64 -nonce_build (u32 seed) -{ - u64 nonce; - u32 nonce_lower; - u32 nonce_upper; - struct timespec ts; - - /* Put nanosecond clock in lower 32-bits and put an XOR of the nanosecond - * clock with the second clock in the upper 32-bits. */ - syscall (SYS_clock_gettime, CLOCK_REALTIME, &ts); - nonce_lower = ts.tv_nsec; - nonce_upper = ts.tv_sec ^ clib_host_to_net_u32 (nonce_lower); - - /* OR in a caller provided seed to the low-order 32-bits. */ - nonce_lower |= seed; - - /* Return 64-bit nonce. */ - nonce = nonce_upper; - nonce = (nonce << 32) | nonce_lower; - return nonce; -} - -void * -lisp_msg_put_map_reply (vlib_buffer_t * b, mapping_t * records, u64 nonce, - u8 probe_bit) -{ - map_reply_hdr_t *h = vlib_buffer_put_uninit (b, sizeof (h[0])); - - clib_memset (h, 0, sizeof (h[0])); - MREP_TYPE (h) = LISP_MAP_REPLY; - MREP_NONCE (h) = nonce; - MREP_REC_COUNT (h) = 1; - MREP_RLOC_PROBE (h) = probe_bit; - - lisp_msg_put_mreg_records (b, records); - return h; -} - -void * -lisp_msg_put_map_register (vlib_buffer_t * b, mapping_t * records, - u8 want_map_notify, u16 auth_data_len, u64 * nonce, - u32 * msg_len) -{ - u8 *auth_data = 0; - - /* Basic header init */ - map_register_hdr_t *h = vlib_buffer_put_uninit (b, sizeof (h[0])); - - clib_memset (h, 0, sizeof (h[0])); - MREG_TYPE (h) = LISP_MAP_REGISTER; - MREG_NONCE (h) = nonce_build (0); - MREG_WANT_MAP_NOTIFY (h) = want_map_notify ? 1 : 0; - MREG_REC_COUNT (h) = vec_len (records); - - auth_data = vlib_buffer_put_uninit (b, auth_data_len); - clib_memset (auth_data, 0, auth_data_len); - - /* Put map register records */ - lisp_msg_put_mreg_records (b, records); - - nonce[0] = MREG_NONCE (h); - msg_len[0] = vlib_buffer_get_tail (b) - (u8 *) h; - return h; -} - -void * -lisp_msg_put_mreq (lisp_cp_main_t * lcm, vlib_buffer_t * b, - gid_address_t * seid, gid_address_t * deid, - gid_address_t * rlocs, u8 is_smr_invoked, - u8 rloc_probe_set, u64 * nonce) -{ - u8 loc_count = 0; - - /* Basic header init */ - map_request_hdr_t *h = vlib_buffer_put_uninit (b, sizeof (h[0])); - - clib_memset (h, 0, sizeof (h[0])); - MREQ_TYPE (h) = LISP_MAP_REQUEST; - MREQ_NONCE (h) = nonce_build (0); - MREQ_SMR_INVOKED (h) = is_smr_invoked ? 1 : 0; - MREQ_RLOC_PROBE (h) = rloc_probe_set ? 1 : 0; - - /* We're adding one eid record */ - increment_record_count (h); - - /* Fill source eid */ - lisp_msg_put_gid (b, seid); - - /* Put itr rlocs */ - lisp_msg_put_itr_rlocs (lcm, b, rlocs, &loc_count); - MREQ_ITR_RLOC_COUNT (h) = loc_count; - - /* Put eid record */ - lisp_msg_put_eid_rec (b, deid); - - nonce[0] = MREQ_NONCE (h); - return h; -} - -void * -lisp_msg_push_ecm (vlib_main_t * vm, vlib_buffer_t * b, int lp, int rp, - gid_address_t * la, gid_address_t * ra) -{ - ecm_hdr_t *h; - ip_address_t _src_ip, *src_ip = &_src_ip, _dst_ip, *dst_ip = &_dst_ip; - if (gid_address_type (la) != GID_ADDR_IP_PREFIX) - { - /* empty ip4 */ - clib_memset (src_ip, 0, sizeof (src_ip[0])); - clib_memset (dst_ip, 0, sizeof (dst_ip[0])); - } - else - { - src_ip = &gid_address_ip (la); - dst_ip = &gid_address_ip (ra); - } - - /* Push inner ip and udp */ - pkt_push_udp_and_ip (vm, b, lp, rp, src_ip, dst_ip, 0); - - /* Push lisp ecm hdr */ - h = pkt_push_ecm_hdr (b); - - return h; -} - -static u32 -msg_type_to_hdr_len (lisp_msg_type_e type) -{ - switch (type) - { - case LISP_MAP_REQUEST: - return (sizeof (map_request_hdr_t)); - case LISP_MAP_REPLY: - return (sizeof (map_reply_hdr_t)); - default: - return (0); - } -} - -void * -lisp_msg_pull_hdr (vlib_buffer_t * b, lisp_msg_type_e type) -{ - return vlib_buffer_pull (b, msg_type_to_hdr_len (type)); -} - -u32 -lisp_msg_parse_addr (vlib_buffer_t * b, gid_address_t * eid) -{ - u32 len; - clib_memset (eid, 0, sizeof (*eid)); - len = gid_address_parse (vlib_buffer_get_current (b), eid); - if (len != ~0) - vlib_buffer_pull (b, len); - return len; -} - -u32 -lisp_msg_parse_eid_rec (vlib_buffer_t * b, gid_address_t * eid) -{ - eid_record_hdr_t *h = vlib_buffer_get_current (b); - u32 len; - clib_memset (eid, 0, sizeof (*eid)); - len = gid_address_parse (EID_REC_ADDR (h), eid); - if (len == ~0) - return len; - - gid_address_ippref_len (eid) = EID_REC_MLEN (h); - vlib_buffer_pull (b, len + sizeof (eid_record_hdr_t)); - - return len + sizeof (eid_record_hdr_t); -} - -u32 -lisp_msg_parse_itr_rlocs (vlib_buffer_t * b, gid_address_t ** rlocs, - u8 rloc_count) -{ - gid_address_t tloc; - u32 i, len = 0, tlen = 0; - - //MREQ_ITR_RLOC_COUNT(mreq_hdr) + 1 - for (i = 0; i < rloc_count; i++) - { - len = lisp_msg_parse_addr (b, &tloc); - if (len == ~0) - return len; - vec_add1 (*rlocs, tloc); - tlen += len; - } - return tlen; -} - -u32 -lisp_msg_parse_loc (vlib_buffer_t * b, locator_t * loc) -{ - int len; - - len = locator_parse (vlib_buffer_get_current (b), loc); - if (len == ~0) - return ~0; - - if (!vlib_buffer_has_space (b, sizeof (len))) - return ~0; - vlib_buffer_pull (b, len); - - return len; -} - -u32 -lisp_msg_parse_mapping_record (vlib_buffer_t * b, gid_address_t * eid, - locator_t ** locs, locator_t * probed_) -{ - void *h = 0, *loc_hdr = 0; - locator_t loc, *probed = 0; - int i = 0, len = 0, llen = 0; - - h = vlib_buffer_get_current (b); - if (!vlib_buffer_has_space (b, sizeof (mapping_record_hdr_t))) - return ~0; - - vlib_buffer_pull (b, sizeof (mapping_record_hdr_t)); - - clib_memset (eid, 0, sizeof (*eid)); - len = gid_address_parse (vlib_buffer_get_current (b), eid); - if (len == ~0) - return len; - - if (!vlib_buffer_has_space (b, sizeof (len))) - return ~0; - - vlib_buffer_pull (b, len); - if (GID_ADDR_IP_PREFIX == gid_address_type (eid)) - gid_address_ippref_len (eid) = MAP_REC_EID_PLEN (h); - - for (i = 0; i < MAP_REC_LOC_COUNT (h); i++) - { - loc_hdr = vlib_buffer_get_current (b); - - llen = lisp_msg_parse_loc (b, &loc); - if (llen == ~0) - return llen; - vec_add1 (*locs, loc); - len += llen; - - if (LOC_PROBED (loc_hdr)) - { - if (probed != 0) - clib_warning - ("Multiple locators probed! Probing only the first!"); - else - probed = &loc; - } - } - /* XXX */ - if (probed_ != 0 && probed) - *probed_ = *probed; - - return len + sizeof (map_reply_hdr_t); -} - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/src/vnet/lisp-cp/lisp_msg_serdes.h b/src/vnet/lisp-cp/lisp_msg_serdes.h deleted file mode 100644 index d794eff6340..00000000000 --- a/src/vnet/lisp-cp/lisp_msg_serdes.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef VNET_LISP_GPE_LISP_MSG_BUILDER_H_ -#define VNET_LISP_GPE_LISP_MSG_BUILDER_H_ - -#include -#include -#include - -void *lisp_msg_put_mreq (lisp_cp_main_t * lcm, vlib_buffer_t * b, - gid_address_t * seid, gid_address_t * deid, - gid_address_t * rlocs, u8 is_smr_invoked, - u8 rloc_probe_set, u64 * nonce); - -void *lisp_msg_put_map_register (vlib_buffer_t * b, mapping_t * records, - u8 want_map_notify, u16 auth_data_len, - u64 * nonce, u32 * msg_len); - -void *lisp_msg_push_ecm (vlib_main_t * vm, vlib_buffer_t * b, int lp, int rp, - gid_address_t * la, gid_address_t * ra); - -void *lisp_msg_put_map_reply (vlib_buffer_t * b, mapping_t * record, - u64 nonce, u8 probe_bit); - -u32 -lisp_msg_parse_mapping_record (vlib_buffer_t * b, gid_address_t * eid, - locator_t ** locs, locator_t * probed_); - -u32 lisp_msg_parse_addr (vlib_buffer_t * b, gid_address_t * eid); - -u32 lisp_msg_parse_eid_rec (vlib_buffer_t * b, gid_address_t * eid); - -u32 -lisp_msg_parse_itr_rlocs (vlib_buffer_t * b, gid_address_t ** rlocs, - u8 rloc_count); - -#endif /* VNET_LISP_GPE_LISP_MSG_BUILDER_H_ */ - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/src/vnet/lisp-cp/lisp_types.api b/src/vnet/lisp-cp/lisp_types.api deleted file mode 100644 index aab01308df8..00000000000 --- a/src/vnet/lisp-cp/lisp_types.api +++ /dev/null @@ -1,75 +0,0 @@ -/* Hey Emacs use -*- mode: C -*- */ -/* - * Copyright (c) 2020 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -option version = "1.0.0"; - -import "vnet/interface_types.api"; -import "vnet/ethernet/ethernet_types.api"; -import "vnet/ip/ip_types.api"; - -typedef local_locator -{ - vl_api_interface_index_t sw_if_index; - u8 priority; - u8 weight; -}; - -typedef remote_locator -{ - u8 priority; - u8 weight; - vl_api_address_t ip_address; -}; - -enum eid_type : u8 -{ - EID_TYPE_API_PREFIX = 0, - EID_TYPE_API_MAC = 1, - EID_TYPE_API_NSH = 2, -}; - -typedef nsh -{ - u32 spi; - u8 si; -}; - -union eid_address -{ - vl_api_prefix_t prefix; - vl_api_mac_address_t mac; - vl_api_nsh_t nsh; -}; - -/* endpoint identifier */ -typedef eid -{ - vl_api_eid_type_t type; - vl_api_eid_address_t address; -}; - -enum hmac_key_id : u8 -{ - KEY_ID_API_HMAC_NO_KEY = 0, - KEY_ID_API_HMAC_SHA_1_96 = 1, - KEY_ID_API_HMAC_SHA_256_128 = 2, -}; - -typedef hmac_key -{ - vl_api_hmac_key_id_t id; - u8 key[64]; -}; diff --git a/src/vnet/lisp-cp/lisp_types.c b/src/vnet/lisp-cp/lisp_types.c deleted file mode 100644 index 6ff3b4ebf4b..00000000000 --- a/src/vnet/lisp-cp/lisp_types.c +++ /dev/null @@ -1,1488 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -static u16 gid_address_put_no_vni (u8 * b, gid_address_t * gid); -static u16 gid_address_size_to_put_no_vni (gid_address_t * gid); -static u16 fid_addr_size_to_write (fid_address_t * a); - -u32 mac_parse (u8 * offset, u8 * a); - -typedef u16 (*size_to_write_fct) (void *); -typedef void *(*cast_fct) (gid_address_t *); -typedef u16 (*serdes_fct) (u8 *, void *); -typedef u8 (*addr_len_fct) (void *); -typedef void (*copy_fct) (void *, void *); -typedef void (*free_fct) (void *); -typedef int (*cmp_fct) (void *, void *); - -size_to_write_fct size_to_write_fcts[GID_ADDR_TYPES] = - { ip_prefix_size_to_write, lcaf_size_to_write, mac_size_to_write, - sd_size_to_write, nsh_size_to_write, 0 /* arp */ , no_addr_size_to_write -}; - -serdes_fct write_fcts[GID_ADDR_TYPES] = - { ip_prefix_write, lcaf_write, mac_write, sd_write, nsh_write, 0 /* arp */ , - no_addr_write -}; - -cast_fct cast_fcts[GID_ADDR_TYPES] = - { ip_prefix_cast, lcaf_cast, mac_cast, sd_cast, nsh_cast, no_addr_cast, - no_addr_cast -}; - -addr_len_fct addr_len_fcts[GID_ADDR_TYPES] = - { ip_prefix_length, lcaf_length, mac_length, sd_length, nsh_length, - 0 /* arp */ , no_addr_length -}; - -copy_fct copy_fcts[GID_ADDR_TYPES] = - { ip_prefix_copy, lcaf_copy, mac_copy, sd_copy, nsh_copy, no_addr_copy, - no_addr_copy -}; - -#define foreach_lcaf_type \ - _(1, no_addr) \ - _(0, NULL) \ - _(1, vni) \ - _(0, NULL) \ - _(0, NULL) \ - _(0, NULL) \ - _(0, NULL) \ - _(0, NULL) \ - _(0, NULL) \ - _(0, NULL) \ - _(0, NULL) \ - _(0, NULL) \ - _(1, sd) \ - _(0, NULL) \ - _(0, NULL) \ - _(0, NULL) \ - _(0, NULL) \ - _(1, nsh) - -#define _(cond, name) \ - u16 name ## _write (u8 * p, void * a); \ - u16 name ## _parse (u8 * p, void * a); \ - u16 name ## _size_to_write (void * a); \ - void name ## _free (void * a); \ - void name ## _copy (void * dst, void * src); \ - u8 name ## _length (void * a); \ - int name ## _cmp (void *, void *); -foreach_lcaf_type -#undef _ -#define CONCAT(a,b) a##_##b -#define IF(c, t, e) CONCAT(IF, c)(t, e) -#define IF_0(t, e) e -#define IF_1(t, e) t -#define EXPAND_FCN(cond, fcn) \ - IF(cond, fcn, NULL) - cmp_fct lcaf_cmp_fcts[LCAF_TYPES] = -{ -#define _(cond, name) \ - EXPAND_FCN(cond, name##_cmp), - foreach_lcaf_type -#undef _ -}; - -addr_len_fct lcaf_body_length_fcts[LCAF_TYPES] = { -#define _(cond, name) \ - EXPAND_FCN(cond, name##_length), - foreach_lcaf_type -#undef _ -}; - -copy_fct lcaf_copy_fcts[LCAF_TYPES] = { -#define _(cond, name) \ - EXPAND_FCN(cond, name##_copy), - foreach_lcaf_type -#undef _ -}; - -free_fct lcaf_free_fcts[LCAF_TYPES] = { -#define _(cond, name) \ - EXPAND_FCN(cond, name##_free), - foreach_lcaf_type -#undef _ -}; - -size_to_write_fct lcaf_size_to_write_fcts[LCAF_TYPES] = { -#define _(cond, name) \ - EXPAND_FCN(cond, name##_size_to_write), - foreach_lcaf_type -#undef _ -}; - -serdes_fct lcaf_write_fcts[LCAF_TYPES] = { -#define _(cond, name) \ - EXPAND_FCN(cond, name##_write), - foreach_lcaf_type -#undef _ -}; - -serdes_fct lcaf_parse_fcts[LCAF_TYPES] = { -#define _(cond, name) \ - EXPAND_FCN(cond, name##_parse), - foreach_lcaf_type -#undef _ -}; - -uword -unformat_nsh_address (unformat_input_t * input, va_list * args) -{ - nsh_t *a = va_arg (*args, nsh_t *); - return unformat (input, "SPI:%d SI:%d", &a->spi, &a->si); -} - -u8 * -format_nsh_address (u8 * s, va_list * args) -{ - nsh_t *a = va_arg (*args, nsh_t *); - return format (s, "SPI:%d SI:%d", a->spi, a->si); -} - -u8 * -format_fid_nsh_address (u8 * s, va_list * args) -{ - u32 *a = va_arg (*args, u32 *); - return format (s, "SPI:%d SI:%d", *a >> 8, *a & 0xff); -} - -u8 * -format_fid_address (u8 * s, va_list * args) -{ - fid_address_t *a = va_arg (*args, fid_address_t *); - - switch (fid_addr_type (a)) - { - case FID_ADDR_IP_PREF: - return format (s, "%U", format_ip_prefix, &fid_addr_ippref (a)); - case FID_ADDR_MAC: - return format (s, "%U", format_mac_address, &fid_addr_mac (a)); - case FID_ADDR_NSH: - return format (s, "%U", format_fid_nsh_address, &fid_addr_nsh (a)); - - default: - clib_warning ("Can't format fid address type %d!", fid_addr_type (a)); - return 0; - } - return 0; -} - -u8 * -format_gid_address (u8 * s, va_list * args) -{ - gid_address_t *a = va_arg (*args, gid_address_t *); - u8 type = gid_address_type (a); - switch (type) - { - case GID_ADDR_IP_PREFIX: - return format (s, "[%d] %U", gid_address_vni (a), format_ip_prefix, - &gid_address_ippref (a)); - case GID_ADDR_SRC_DST: - return format (s, "[%d] %U|%U", gid_address_vni (a), - format_fid_address, &gid_address_sd_src (a), - format_fid_address, &gid_address_sd_dst (a)); - case GID_ADDR_MAC: - return format (s, "[%d] %U", gid_address_vni (a), format_mac_address, - &gid_address_mac (a)); - case GID_ADDR_ARP: - case GID_ADDR_NDP: - return format (s, "[%d, %U]", gid_address_arp_ndp_bd (a), - format_ip_address, &gid_address_arp_ndp_ip (a)); - case GID_ADDR_NSH: - return format (s, "%U", format_nsh_address, &gid_address_nsh (a)); - - default: - clib_warning ("Can't format gid type %d", type); - return 0; - } - return 0; -} - -uword -unformat_fid_address (unformat_input_t * i, va_list * args) -{ - fid_address_t *a = va_arg (*args, fid_address_t *); - ip_prefix_t ippref; - u8 mac[6] = { 0 }; - nsh_t nsh; - - if (unformat (i, "%U", unformat_ip_prefix, &ippref)) - { - fid_addr_type (a) = FID_ADDR_IP_PREF; - ip_prefix_copy (&fid_addr_ippref (a), &ippref); - } - else if (unformat (i, "%U", unformat_mac_address, mac)) - { - fid_addr_type (a) = FID_ADDR_MAC; - mac_copy (fid_addr_mac (a), mac); - } - else if (unformat (i, "%U", unformat_nsh_address, &nsh)) - { - fid_addr_type (a) = FID_ADDR_NSH; - nsh_copy (&fid_addr_nsh (a), &nsh); - } - else - return 0; - - return 1; -} - -uword -unformat_hmac_key_id (unformat_input_t * input, va_list * args) -{ - u32 *key_id = va_arg (*args, u32 *); - u8 *s = 0; - - if (unformat (input, "%s", &s)) - { - if (!strcmp ((char *) s, "sha1")) - key_id[0] = HMAC_SHA_1_96; - else if (!strcmp ((char *) s, "sha256")) - key_id[0] = HMAC_SHA_256_128; - else - { - clib_warning ("invalid key_id: '%s'", s); - key_id[0] = HMAC_NO_KEY; - } - } - else - return 0; - - vec_free (s); - return 1; -} - -uword -unformat_gid_address (unformat_input_t * input, va_list * args) -{ - gid_address_t *a = va_arg (*args, gid_address_t *); - u8 mac[6] = { 0 }; - ip_prefix_t ippref; - fid_address_t sim1, sim2; - nsh_t nsh; - - clib_memset (&ippref, 0, sizeof (ippref)); - clib_memset (&sim1, 0, sizeof (sim1)); - clib_memset (&sim2, 0, sizeof (sim2)); - - if (unformat (input, "%U|%U", unformat_fid_address, &sim1, - unformat_fid_address, &sim2)) - { - gid_address_sd_src (a) = sim1; - gid_address_sd_dst (a) = sim2; - gid_address_type (a) = GID_ADDR_SRC_DST; - } - else if (unformat (input, "%U", unformat_ip_prefix, &ippref)) - { - ip_prefix_copy (&gid_address_ippref (a), &ippref); - gid_address_type (a) = GID_ADDR_IP_PREFIX; - } - else if (unformat (input, "%U", unformat_mac_address, mac)) - { - mac_copy (gid_address_mac (a), mac); - gid_address_type (a) = GID_ADDR_MAC; - } - else if (unformat (input, "%U", unformat_nsh_address, &nsh)) - { - nsh_copy (&gid_address_nsh (a), &nsh); - gid_address_type (a) = GID_ADDR_NSH; - } - else - return 0; - - return 1; -} - -uword -unformat_negative_mapping_action (unformat_input_t * input, va_list * args) -{ - u32 *action = va_arg (*args, u32 *); - u8 *s = 0; - - if (unformat (input, "%s", &s)) - { - if (!strcmp ((char *) s, "no-action")) - action[0] = LISP_NO_ACTION; - else if (!strcmp ((char *) s, "natively-forward")) - action[0] = LISP_FORWARD_NATIVE; - else if (!strcmp ((char *) s, "send-map-request")) - action[0] = LISP_SEND_MAP_REQUEST; - else if (!strcmp ((char *) s, "drop")) - action[0] = LISP_DROP; - else - { - clib_warning ("invalid action: '%s'", s); - action[0] = LISP_DROP; - } - } - else - return 0; - - vec_free (s); - return 1; -} - -u8 * -format_hmac_key_id (u8 * s, va_list * args) -{ - lisp_key_type_t key_id = va_arg (*args, lisp_key_type_t); - - switch (key_id) - { - case HMAC_SHA_1_96: - return format (0, "sha1"); - case HMAC_SHA_256_128: - return format (0, "sha256"); - default: - return 0; - } - - return 0; -} - -u8 * -format_negative_mapping_action (u8 * s, va_list * args) -{ - lisp_action_e action = va_arg (*args, lisp_action_e); - - switch (action) - { - case LISP_NO_ACTION: - s = format (s, "no-action"); - break; - case LISP_FORWARD_NATIVE: - s = format (s, "natively-forward"); - break; - case LISP_SEND_MAP_REQUEST: - s = format (s, "send-map-request"); - break; - case LISP_DROP: - default: - s = format (s, "drop"); - break; - } - return (s); -} - -u8 -ip_prefix_length (void *a) -{ - return ip_prefix_len ((ip_prefix_t *) a); -} - -always_inline lisp_afi_e -ip_version_to_iana_afi (u16 version) -{ - switch (version) - { - case AF_IP4: - return LISP_AFI_IP; - case AF_IP6: - return LISP_AFI_IP6; - default: - return 0; - } - return 0; -} - -always_inline u8 -ip_iana_afi_to_version (lisp_afi_e afi) -{ - switch (afi) - { - case LISP_AFI_IP: - return AF_IP4; - case LISP_AFI_IP6: - return AF_IP6; - default: - return 0; - } - return 0; -} - -u16 -ip_address_size_to_write (ip_address_t * a) -{ - return ip_address_size (a) + sizeof (u16); -} - -u16 -ip_address_iana_afi (ip_address_t * a) -{ - return ip_version_to_iana_afi (ip_addr_version (a)); -} - -u8 -ip_address_max_len (u8 version) -{ - return version == AF_IP4 ? 32 : 128; -} - -u16 -ip4_address_size_to_put () -{ - // return sizeof(u16) + sizeof (ip4_address_t); - return 6; -} - -u16 -ip6_address_size_to_put () -{ - //return sizeof(u16) + sizeof (ip6_address_t); - return 18; -} - -u32 -ip4_address_put (u8 * b, ip4_address_t * a) -{ - *(u16 *) b = clib_host_to_net_u16 (ip_version_to_iana_afi (AF_IP4)); - u8 *p = b + sizeof (u16); - clib_memcpy (p, a, sizeof (*a)); - return ip4_address_size_to_put (); -} - -u32 -ip6_address_put (u8 * b, ip6_address_t * a) -{ - *(u16 *) b = clib_host_to_net_u16 (ip_version_to_iana_afi (AF_IP6)); - u8 *p = b + sizeof (u16); - clib_memcpy (p, a, sizeof (*a)); - return ip6_address_size_to_put (); -} - -u32 -ip_address_put (u8 * b, ip_address_t * a) -{ - u32 len = ip_address_size (a); - *(u16 *) b = clib_host_to_net_u16 (ip_address_iana_afi (a)); - u8 *p = b + sizeof (u16); - clib_memcpy (p, ip_addr_bytes (a), len); - return (len + sizeof (u16)); -} - -u32 -ip_address_parse (void *offset, u16 iana_afi, ip_address_t * dst) -{ - ip_addr_version (dst) = ip_iana_afi_to_version (iana_afi); - u8 size = ip_version_to_size (ip_addr_version (dst)); - clib_memcpy (ip_addr_bytes (dst), offset + sizeof (u16), size); - return (sizeof (u16) + size); -} - -void -gid_to_dp_address (gid_address_t * g, dp_address_t * d) -{ - switch (gid_address_type (g)) - { - case GID_ADDR_SRC_DST: - switch (gid_address_sd_dst_type (g)) - { - case FID_ADDR_IP_PREF: - ip_prefix_copy (&d->ippref, &gid_address_sd_dst_ippref (g)); - d->type = FID_ADDR_IP_PREF; - break; - case FID_ADDR_MAC: - mac_copy (&d->mac, &gid_address_sd_dst_mac (g)); - d->type = FID_ADDR_MAC; - break; - default: - clib_warning ("Source/Dest address type %d not supported!", - gid_address_sd_dst_type (g)); - break; - } - break; - case GID_ADDR_IP_PREFIX: - ip_prefix_copy (&d->ippref, &gid_address_ippref (g)); - d->type = FID_ADDR_IP_PREF; - break; - case GID_ADDR_MAC: - mac_copy (&d->mac, &gid_address_mac (g)); - d->type = FID_ADDR_MAC; - break; - case GID_ADDR_NSH: - default: - d->nsh = gid_address_nsh (g).spi << 8 | gid_address_nsh (g).si; - d->type = FID_ADDR_NSH; - break; - } -} - -u32 -lcaf_hdr_parse (void *offset, lcaf_t * lcaf) -{ - lcaf_hdr_t *lh = offset; - lcaf->type = lh->type; - - /* this is a bit of hack: since the LCAF Instance ID is the - only message that uses reserved2 field, we can set it here. - If any LCAF format starts using reserved2 field as well this needs - to be moved elsewhere */ - lcaf_vni_len (lcaf) = lh->reserved2; - - return sizeof (lh[0]); -} - -static u8 -iana_afi_to_fid_addr_type (u16 type) -{ - switch (type) - { - case LISP_AFI_IP: - case LISP_AFI_IP6: - return FID_ADDR_IP_PREF; - - case LISP_AFI_MAC: - return FID_ADDR_MAC; - } - return ~0; -} - -static u16 -fid_addr_parse (u8 * p, fid_address_t * a) -{ - u16 afi = clib_net_to_host_u16 (*(u16 *) p); - fid_addr_type (a) = iana_afi_to_fid_addr_type (afi); - ip_address_t *ip_addr = &ip_prefix_addr (&fid_addr_ippref (a)); - - switch (fid_addr_type (a)) - { - case FID_ADDR_MAC: - return mac_parse (p, fid_addr_mac (a)); - - case FID_ADDR_IP_PREF: - return ip_address_parse (p, afi, ip_addr); - - case FID_ADDR_NSH: - break; - } - return ~0; -} - -#define INC(dst, exp) \ -do { \ - u16 _sum = (exp); \ - if ((u16)~0 == _sum) \ - return ~0; \ - dst += _sum; \ -} while (0); - -void -nsh_free (void *a) -{ - /* nothing to do */ -} - -u16 -nsh_parse (u8 * p, void *a) -{ - lcaf_spi_hdr_t *h = (lcaf_spi_hdr_t *) p; - gid_address_t *g = a; - - gid_address_type (g) = GID_ADDR_NSH; - gid_address_nsh_spi (g) = clib_net_to_host_u32 (LCAF_SPI_SI (h)) >> 8; - gid_address_nsh_si (g) = (u8) clib_net_to_host_u32 (LCAF_SPI_SI (h)); - - return sizeof (lcaf_spi_hdr_t); -} - -int -nsh_cmp (void *a1, void *a2) -{ - nsh_t *n1 = a1; - nsh_t *n2 = a2; - - if (n1->spi != n2->spi) - return 1; - if (n1->si != n2->si) - return 1; - return 0; -} - -u16 -sd_parse (u8 * p, void *a) -{ - lcaf_src_dst_hdr_t *sd_hdr; - gid_address_t *g = a; - u16 size = 0; - fid_address_t *src = &gid_address_sd_src (g); - fid_address_t *dst = &gid_address_sd_dst (g); - - gid_address_type (g) = GID_ADDR_SRC_DST; - - sd_hdr = (lcaf_src_dst_hdr_t *) (p + size); - size += sizeof (sd_hdr[0]); - - INC (size, fid_addr_parse (p + size, src)); - INC (size, fid_addr_parse (p + size, dst)); - - if (fid_addr_type (src) == FID_ADDR_IP_PREF) - { - ip_prefix_t *ippref = &fid_addr_ippref (src); - ip_prefix_len (ippref) = LCAF_SD_SRC_ML (sd_hdr); - } - if (fid_addr_type (dst) == FID_ADDR_IP_PREF) - { - ip_prefix_t *ippref = &fid_addr_ippref (dst); - ip_prefix_len (ippref) = LCAF_SD_DST_ML (sd_hdr); - } - return size; -} - -u16 -try_parse_src_dst_lcaf (u8 * p, gid_address_t * a) -{ - lcaf_t lcaf; - u16 size = sizeof (u16); /* skip AFI */ - - size += lcaf_hdr_parse (p + size, &lcaf); - - if (LCAF_SOURCE_DEST != lcaf_type (&lcaf)) - return ~0; - - INC (size, sd_parse (p + size, a)); - return size; -} - -u16 -vni_parse (u8 * p, void *a) -{ - lcaf_t *lcaf = a; - gid_address_t *g = a; - u16 size = 0; - - gid_address_vni (g) = clib_net_to_host_u32 (*(u32 *) p); - size += sizeof (u32); - gid_address_vni_mask (g) = lcaf_vni_len (lcaf); - - /* nested LCAFs are not supported except of src/dst with vni - to handle - * such case look at the next AFI and process src/dest LCAF separately */ - u16 afi = clib_net_to_host_u16 (*((u16 *) (p + size))); - if (LISP_AFI_LCAF == afi) - { - INC (size, try_parse_src_dst_lcaf (p + size, g)); - } - else - INC (size, gid_address_parse (p + size, g)); - - return size; -} - -u16 -no_addr_parse (u8 * p, void *a) -{ - /* do nothing */ - return 0; -} - -u32 -lcaf_parse (void *offset, gid_address_t * addr) -{ - /* skip AFI type */ - offset += sizeof (u16); - lcaf_t *lcaf = &gid_address_lcaf (addr); - - u32 size = lcaf_hdr_parse (offset, lcaf); - u8 type = lcaf_type (lcaf); - - if (!lcaf_parse_fcts[type]) - { - clib_warning ("Unsupported LCAF type: %u", type); - return ~0; - } - INC (size, (*lcaf_parse_fcts[type]) (offset + size, lcaf)); - return sizeof (u16) + size; -} - -void -vni_free (void *a) -{ - vni_t *v = a; - gid_address_free (vni_gid (v)); - clib_mem_free (vni_gid (v)); -} - -void -no_addr_free (void *a) -{ - /* nothing to do */ -} - -void -sd_free (void *a) -{ - /* nothing */ -} - -void -gid_address_free (gid_address_t * a) -{ - if (gid_address_type (a) != GID_ADDR_LCAF) - return; - - lcaf_t *lcaf = &gid_address_lcaf (a); - u8 lcaf_type = lcaf_type (lcaf); - (*lcaf_free_fcts[lcaf_type]) (lcaf); -} - -void -gid_address_from_ip (gid_address_t * g, ip_address_t * ip) -{ - clib_memset (g, 0, sizeof (g[0])); - ip_address_set (&gid_address_ip (g), ip, ip_addr_version (ip)); - gid_address_ippref_len (g) = 32; -} - -void * -ip_prefix_cast (gid_address_t * a) -{ - return &gid_address_ippref (a); -} - -u16 -ip_prefix_size_to_write (void *pref) -{ - ip_prefix_t *a = (ip_prefix_t *) pref; - return ip_address_size_to_write (&ip_prefix_addr (a)); -} - -u16 -ip_prefix_write (u8 * p, void *gid) -{ - gid_address_t *g = gid; - ip_prefix_t *a = &gid_address_ippref (g); - - switch (ip_prefix_version (a)) - { - case AF_IP4: - return ip4_address_put (p, &ip_prefix_v4 (a)); - break; - case AF_IP6: - return ip6_address_put (p, &ip_prefix_v6 (a)); - break; - } - return 0; -} - -void -mac_copy (void *dst, void *src) -{ - clib_memcpy (dst, src, 6); -} - -void -sd_copy (void *dst, void *src) -{ - clib_memcpy (dst, src, sizeof (source_dest_t)); -} - -void -nsh_copy (void *dst, void *src) -{ - clib_memcpy (dst, src, sizeof (nsh_t)); -} - -void -no_addr_copy (void *dst, void *src) -{ - /* nothing to do */ -} - -void -vni_copy (void *dst, void *src) -{ - vni_t *vd = dst; - vni_t *vs = src; - - clib_memcpy (vd, vs, sizeof (vd[0])); - vni_gid (vd) = clib_mem_alloc (sizeof (gid_address_t)); - gid_address_copy (vni_gid (vd), vni_gid (vs)); -} - -void -lcaf_copy (void *dst, void *src) -{ - lcaf_t *lcaf_dst = dst; - lcaf_t *lcaf_src = src; - - lcaf_type (lcaf_dst) = lcaf_type (lcaf_src); - (*lcaf_copy_fcts[lcaf_type (lcaf_src)]) (dst, src); -} - -u8 -lcaf_length (void *a) -{ - return 0; -} - -u8 -mac_length (void *a) -{ - return 0; -} - -u8 -sd_length (void *a) -{ - return 0; -} - -u8 -nsh_length (void *a) -{ - return 0; -} - -void * -lcaf_cast (gid_address_t * a) -{ - return &gid_address_lcaf (a); -} - -void * -mac_cast (gid_address_t * a) -{ - return &gid_address_mac (a); -} - -void * -no_addr_cast (gid_address_t * a) -{ - return (void *) a; -} - -void * -sd_cast (gid_address_t * a) -{ - return &gid_address_sd (a); -} - -void * -nsh_cast (gid_address_t * a) -{ - return &gid_address_nsh (a); -} - -u8 -no_addr_length (void *a) -{ - return 0; -} - -u8 -vni_length (void *a) -{ - vni_t *v = a; - return (sizeof (u32) /* VNI size */ - + gid_address_size_to_put (vni_gid (v)) /* vni body size */ ); -} - -u16 -lcaf_write (u8 * p, void *a) -{ - u16 size = 0, len; - lcaf_t *lcaf = a; - u8 type = lcaf_type (lcaf); - lcaf_hdr_t _h, *h = &_h; - - *(u16 *) p = clib_host_to_net_u16 (LISP_AFI_LCAF); - size += sizeof (u16); - clib_memset (h, 0, sizeof (h[0])); - LCAF_TYPE (h) = type; - u16 lcaf_len = (*lcaf_body_length_fcts[type]) (lcaf); - LCAF_LENGTH (h) = clib_host_to_net_u16 (lcaf_len); - - clib_memcpy (p + size, h, sizeof (h[0])); - size += sizeof (h[0]); - len = (*lcaf_write_fcts[type]) (p + size, lcaf); - - if ((u16) ~ 0 == len) - return ~0; - - return size + len; -} - -u16 -mac_write (u8 * p, void *a) -{ - *(u16 *) p = clib_host_to_net_u16 (LISP_AFI_MAC); - clib_memcpy (p + sizeof (u16), a, 6); - return mac_size_to_write (a); -} - -static u16 -fid_addr_write (u8 * p, fid_address_t * a) -{ - switch (fid_addr_type (a)) - { - case FID_ADDR_IP_PREF: - return ip_prefix_write (p, &fid_addr_ippref (a)); - - case FID_ADDR_MAC: - return mac_write (p, &fid_addr_mac (a)); - - default: - return ~0; - } - return ~0; -} - -static u8 -fid_address_length (fid_address_t * a) -{ - switch (fid_addr_type (a)) - { - case FID_ADDR_IP_PREF: - return ip_prefix_length (&fid_addr_ippref (a)); - case FID_ADDR_MAC: - return 0; - case FID_ADDR_NSH: - return 0; - } - return 0; -} - -u16 -sd_write (u8 * p, void *a) -{ - source_dest_t *sd = a; - u16 size = 0; - lcaf_hdr_t _h, *h = &_h; - lcaf_src_dst_hdr_t sd_hdr; - - *(u16 *) p = clib_host_to_net_u16 (LISP_AFI_LCAF); - size += sizeof (u16); - clib_memset (h, 0, sizeof (h[0])); - LCAF_TYPE (h) = LCAF_SOURCE_DEST; - u16 lcaf_len = sizeof (lcaf_src_dst_hdr_t) - + fid_addr_size_to_write (&sd_src (sd)) - + fid_addr_size_to_write (&sd_dst (sd)); - LCAF_LENGTH (h) = clib_host_to_net_u16 (lcaf_len); - - clib_memcpy (p + size, h, sizeof (h[0])); - size += sizeof (h[0]); - - clib_memset (&sd_hdr, 0, sizeof (sd_hdr)); - LCAF_SD_SRC_ML (&sd_hdr) = fid_address_length (&sd_src (sd)); - LCAF_SD_DST_ML (&sd_hdr) = fid_address_length (&sd_dst (sd)); - clib_memcpy (p + size, &sd_hdr, sizeof (sd_hdr)); - size += sizeof (sd_hdr); - - u16 len = fid_addr_write (p + size, &sd_src (sd)); - if ((u16) ~ 0 == len) - return ~0; - size += len; - - len = fid_addr_write (p + size, &sd_dst (sd)); - if ((u16) ~ 0 == len) - return ~0; - size += len; - - return size; -} - -u16 -nsh_write (u8 * p, void *a) -{ - lcaf_spi_hdr_t spi; - lcaf_hdr_t lcaf; - gid_address_t *g = a; - u16 size = 0; - - ASSERT (gid_address_type (g) == GID_ADDR_NSH); - - clib_memset (&lcaf, 0, sizeof (lcaf)); - clib_memset (&spi, 0, sizeof (spi)); - - LCAF_TYPE (&lcaf) = LCAF_NSH; - LCAF_LENGTH (&lcaf) = clib_host_to_net_u16 (sizeof (lcaf_spi_hdr_t)); - - u32 s = clib_host_to_net_u32 (gid_address_nsh_spi (g) << 8 | - gid_address_nsh_si (g)); - LCAF_SPI_SI (&spi) = s; - - *(u16 *) p = clib_host_to_net_u16 (LISP_AFI_LCAF); - size += sizeof (u16); - - clib_memcpy (p + size, &lcaf, sizeof (lcaf)); - size += sizeof (lcaf); - - clib_memcpy (p + size, &spi, sizeof (spi)); - size += sizeof (spi); - - return size; -} - -u16 -vni_write (u8 * p, void *a) -{ - lcaf_hdr_t _h, *h = &_h; - gid_address_t *g = a; - u16 size = 0, len; - - /* put lcaf header */ - *(u16 *) p = clib_host_to_net_u16 (LISP_AFI_LCAF); - size += sizeof (u16); - clib_memset (h, 0, sizeof (h[0])); - LCAF_TYPE (h) = LCAF_INSTANCE_ID; - u16 lcaf_len = sizeof (u32) /* Instance ID size */ - + gid_address_size_to_put_no_vni (g); - LCAF_LENGTH (h) = clib_host_to_net_u16 (lcaf_len); - LCAF_RES2 (h) = gid_address_vni_mask (g); - - /* put vni header */ - clib_memcpy (p + size, h, sizeof (h[0])); - size += sizeof (h[0]); - - u32 *afip = (u32 *) (p + size); - afip[0] = clib_host_to_net_u32 (gid_address_vni (g)); - size += sizeof (u32); - - if (GID_ADDR_SRC_DST == gid_address_type (g)) - /* write src/dst LCAF */ - { - len = sd_write (p + size, g); - if ((u16) ~ 0 == len) - return ~0; - } - else - /* write the actual address */ - len = gid_address_put_no_vni (p + size, g); - - if ((u16) ~ 0 == len) - return ~0; - - return size + len; -} - -u16 -no_addr_write (u8 * p, void *a) -{ - /* do nothing; return AFI field size */ - return sizeof (u16); -} - -u16 -no_addr_size_to_write (void *a) -{ - return sizeof (u16); /* AFI field length */ -} - -static u16 -fid_addr_size_to_write (fid_address_t * a) -{ - switch (fid_addr_type (a)) - { - case FID_ADDR_IP_PREF: - return ip_prefix_size_to_write (a); - - case FID_ADDR_MAC: - return mac_size_to_write (a); - - default: - break; - } - return 0; -} - -u16 -vni_size_to_write (void *a) -{ - gid_address_t *g = a; - - u16 lcaf_size = sizeof (u32) + sizeof (u16) /* LCAF AFI field size */ - + sizeof (lcaf_hdr_t); - - if (gid_address_type (g) == GID_ADDR_SRC_DST) - /* special case where nested LCAF is supported */ - return lcaf_size + sd_size_to_write (g); - else - return lcaf_size + gid_address_size_to_put_no_vni (g); -} - -u16 -lcaf_size_to_write (void *a) -{ - lcaf_t *lcaf = (lcaf_t *) a; - u32 size = 0, len; - u8 type = lcaf_type (lcaf); - - size += sizeof (u16); /* AFI size */ - - len = (*lcaf_size_to_write_fcts[type]) (lcaf); - if (~0 == len) - return ~0; - - return size + len; -} - -u16 -sd_size_to_write (void *a) -{ - source_dest_t *sd = a; - return sizeof (u16) - + sizeof (lcaf_hdr_t) - + sizeof (lcaf_src_dst_hdr_t) - + fid_addr_size_to_write (&sd_src (sd)) - + fid_addr_size_to_write (&sd_dst (sd)); -} - -u16 -mac_size_to_write (void *a) -{ - return sizeof (u16) + 6; -} - -u16 -nsh_size_to_write (void *a) -{ - return sizeof (u16) + sizeof (lcaf_hdr_t) + sizeof (lcaf_spi_hdr_t); -} - -u8 -gid_address_len (gid_address_t * a) -{ - gid_address_type_t type = gid_address_type (a); - return (*addr_len_fcts[type]) ((*cast_fcts[type]) (a)); -} - -static u16 -gid_address_put_no_vni (u8 * b, gid_address_t * gid) -{ - gid_address_type_t type = gid_address_type (gid); - return (*write_fcts[type]) (b, (*cast_fcts[type]) (gid)); -} - -u16 -gid_address_put (u8 * b, gid_address_t * gid) -{ - if (0 != gid_address_vni (gid)) - return vni_write (b, gid); - - return gid_address_put_no_vni (b, gid); -} - -static u16 -gid_address_size_to_put_no_vni (gid_address_t * gid) -{ - gid_address_type_t type = gid_address_type (gid); - return (*size_to_write_fcts[type]) ((*cast_fcts[type]) (gid)); -} - -u16 -gid_address_size_to_put (gid_address_t * gid) -{ - if (0 != gid_address_vni (gid)) - return vni_size_to_write (gid); - - return gid_address_size_to_put_no_vni (gid); -} - -void * -gid_address_cast (gid_address_t * gid, gid_address_type_t type) -{ - return (*cast_fcts[type]) (gid); -} - -void -gid_address_copy (gid_address_t * dst, gid_address_t * src) -{ - gid_address_type_t type = gid_address_type (src); - (*copy_fcts[type]) ((*cast_fcts[type]) (dst), (*cast_fcts[type]) (src)); - gid_address_type (dst) = type; - gid_address_vni (dst) = gid_address_vni (src); - gid_address_vni_mask (dst) = gid_address_vni_mask (src); -} - -u32 -mac_parse (u8 * offset, u8 * a) -{ - /* skip AFI field */ - offset += sizeof (u16); - - clib_memcpy (a, offset, 6); - return sizeof (u16) + 6; -} - -u32 -gid_address_parse (u8 * offset, gid_address_t * a) -{ - lisp_afi_e afi; - u16 len = 0; - - ASSERT (a); - - /* NOTE: since gid_address_parse may be called by vni_parse, we can't 0 - * the gid address here */ - afi = clib_net_to_host_u16 (*((u16 *) offset)); - - switch (afi) - { - case LISP_AFI_NO_ADDR: - len = sizeof (u16); - gid_address_type (a) = GID_ADDR_NO_ADDRESS; - break; - case LISP_AFI_IP: - len = ip_address_parse (offset, afi, &gid_address_ip (a)); - gid_address_type (a) = GID_ADDR_IP_PREFIX; - /* this should be modified outside if needed */ - gid_address_ippref_len (a) = 32; - break; - case LISP_AFI_IP6: - len = ip_address_parse (offset, afi, &gid_address_ip (a)); - gid_address_type (a) = GID_ADDR_IP_PREFIX; - /* this should be modified outside if needed */ - gid_address_ippref_len (a) = 128; - break; - case LISP_AFI_LCAF: - gid_address_type (a) = GID_ADDR_LCAF; - len = lcaf_parse (offset, a); - break; - case LISP_AFI_MAC: - len = mac_parse (offset, gid_address_mac (a)); - gid_address_type (a) = GID_ADDR_MAC; - break; - default: - clib_warning ("LISP AFI %d not supported!", afi); - return ~0; - } - return (len == (u16) ~ 0) ? ~0 : len; -} - -void -gid_address_ip_set (gid_address_t * dst, void *src, u8 version) -{ - gid_address_ippref_len (dst) = ip_address_max_len (version); - ip_address_set (&gid_address_ip (dst), src, version); -} - -int -no_addr_cmp (void *a1, void *a2) -{ - return 0; -} - -int -vni_cmp (void *a1, void *a2) -{ - vni_t *v1 = a1; - vni_t *v2 = a2; - - if (vni_mask_len (v1) != vni_mask_len (v2)) - return -1; - if (vni_vni (v1) != vni_vni (v2)) - return -1; - return gid_address_cmp (vni_gid (v1), vni_gid (v2)); -} - -static int -mac_cmp (void *a1, void *a2) -{ - return memcmp (a1, a2, 6); -} - -static int -fid_addr_cmp (fid_address_t * a1, fid_address_t * a2) -{ - if (fid_addr_type (a1) != fid_addr_type (a2)) - return -1; - - switch (fid_addr_type (a1)) - { - case FID_ADDR_IP_PREF: - return ip_prefix_cmp (&fid_addr_ippref (a1), &fid_addr_ippref (a2)); - - case FID_ADDR_MAC: - return mac_cmp (fid_addr_mac (a1), fid_addr_mac (a2)); - - default: - return -1; - } - return -1; -} - -int -sd_cmp (void *a1, void *a2) -{ - source_dest_t *sd1 = a1; - source_dest_t *sd2 = a2; - - if (fid_addr_cmp (&sd_dst (sd1), &sd_dst (sd2))) - return -1; - if (fid_addr_cmp (&sd_src (sd1), &sd_src (sd2))) - return -1; - return 0; -} - -/* Compare two gid_address_t. - * Returns: - * -1: If they are from different afi - * 0: Both address are the same - * 1: Addr1 is bigger than addr2 - * 2: Addr2 is bigger than addr1 - */ -int -gid_address_cmp (gid_address_t * a1, gid_address_t * a2) -{ - lcaf_t *lcaf1, *lcaf2; - int cmp = -1; - if (!a1 || !a2) - return -1; - if (gid_address_type (a1) != gid_address_type (a2)) - return -1; - if (gid_address_vni (a1) != gid_address_vni (a2)) - return -1; - - /* TODO vni mask is not supported, disable comparing for now - if (gid_address_vni_mask (a1) != gid_address_vni_mask (a2)) - return -1; - */ - - switch (gid_address_type (a1)) - { - case GID_ADDR_NO_ADDRESS: - if (a1 == a2) - cmp = 0; - else - cmp = 2; - break; - case GID_ADDR_IP_PREFIX: - cmp = - ip_prefix_cmp (&gid_address_ippref (a1), &gid_address_ippref (a2)); - break; - case GID_ADDR_LCAF: - lcaf1 = &gid_address_lcaf (a1); - lcaf2 = &gid_address_lcaf (a2); - if (lcaf_type (lcaf1) == lcaf_type (lcaf2)) - cmp = (*lcaf_cmp_fcts[lcaf_type (lcaf1)]) (lcaf1, lcaf2); - break; - case GID_ADDR_MAC: - cmp = mac_cmp (gid_address_mac (a1), gid_address_mac (a2)); - break; - - case GID_ADDR_SRC_DST: - cmp = sd_cmp (&gid_address_sd (a1), &gid_address_sd (a2)); - break; - case GID_ADDR_NSH: - cmp = nsh_cmp (&gid_address_nsh (a1), &gid_address_nsh (a2)); - break; - default: - break; - } - - return cmp; -} - -u32 -locator_parse (void *b, locator_t * loc) -{ - locator_hdr_t *h; - u8 status = 1; /* locator up */ - int len; - - h = b; - if (!LOC_REACHABLE (h) && LOC_LOCAL (h)) - status = 0; - - len = gid_address_parse (LOC_ADDR (h), &loc->address); - if (len == ~0) - return len; - - loc->state = status; - loc->local = 0; - loc->probed = 0; - loc->priority = LOC_PRIORITY (h); - loc->weight = LOC_WEIGHT (h); - loc->mpriority = LOC_MPRIORITY (h); - loc->mweight = LOC_MWEIGHT (h); - - return sizeof (locator_hdr_t) + len; -} - -void -locator_copy (locator_t * dst, locator_t * src) -{ - /* TODO if gid become more complex, this will need to be changed! */ - clib_memcpy (dst, src, sizeof (*dst)); - if (!src->local) - gid_address_copy (&dst->address, &src->address); -} - -u32 -locator_cmp (locator_t * l1, locator_t * l2) -{ - u32 ret = 0; - if ((ret = gid_address_cmp (&l1->address, &l2->address)) != 0) - return 1; - - if (l1->priority != l2->priority) - return 1; - if (l1->weight != l2->weight) - return 1; - if (l1->mpriority != l2->mpriority) - return 1; - if (l1->mweight != l2->mweight) - return 1; - return 0; -} - -void -locator_free (locator_t * l) -{ - if (!l->local) - gid_address_free (&l->address); -} - -void -build_src_dst (gid_address_t * sd, gid_address_t * src, gid_address_t * dst) -{ - clib_memset (sd, 0, sizeof (*sd)); - gid_address_type (sd) = GID_ADDR_SRC_DST; - gid_address_vni (sd) = gid_address_vni (dst); - gid_address_vni_mask (sd) = gid_address_vni_mask (dst); - - switch (gid_address_type (dst)) - { - case GID_ADDR_IP_PREFIX: - gid_address_sd_src_type (sd) = FID_ADDR_IP_PREF; - gid_address_sd_dst_type (sd) = FID_ADDR_IP_PREF; - ip_prefix_copy (&gid_address_sd_src_ippref (sd), - &gid_address_ippref (src)); - ip_prefix_copy (&gid_address_sd_dst_ippref (sd), - &gid_address_ippref (dst)); - break; - case GID_ADDR_MAC: - gid_address_sd_src_type (sd) = FID_ADDR_MAC; - gid_address_sd_dst_type (sd) = FID_ADDR_MAC; - mac_copy (gid_address_sd_src_mac (sd), gid_address_mac (src)); - mac_copy (gid_address_sd_dst_mac (sd), gid_address_mac (dst)); - break; - default: - clib_warning ("Unsupported gid type %d while conversion!", - gid_address_type (dst)); - break; - } -} - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/src/vnet/lisp-cp/lisp_types.h b/src/vnet/lisp-cp/lisp_types.h deleted file mode 100644 index e08ba15dfd3..00000000000 --- a/src/vnet/lisp-cp/lisp_types.h +++ /dev/null @@ -1,350 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef VNET_LISP_GPE_LISP_TYPES_H_ -#define VNET_LISP_GPE_LISP_TYPES_H_ - -#include -#include - -#define SHA1_AUTH_DATA_LEN 20 -#define SHA256_AUTH_DATA_LEN 32 - -typedef enum -{ - HMAC_NO_KEY = 0, - HMAC_SHA_1_96, - HMAC_SHA_256_128 -} lisp_key_type_t; - -uword unformat_hmac_key_id (unformat_input_t * input, va_list * args); -u8 *format_hmac_key_id (u8 * s, va_list * args); - -typedef enum -{ - /* NOTE: ip addresses are left out on purpose. Use max masked ip-prefixes - * instead */ - GID_ADDR_IP_PREFIX, - GID_ADDR_LCAF, - GID_ADDR_MAC, - GID_ADDR_SRC_DST, - GID_ADDR_NSH, - GID_ADDR_ARP, - GID_ADDR_NDP, - GID_ADDR_NO_ADDRESS, - GID_ADDR_TYPES -} gid_address_type_t; - -typedef enum -{ - /* make sure that values corresponds with RFC */ - LCAF_NULL_BODY = 0, - LCAF_AFI_LIST_TYPE, - LCAF_INSTANCE_ID, - LCAF_SOURCE_DEST = 12, - LCAF_NSH = 17, - LCAF_TYPES -} lcaf_type_t; - -typedef enum fid_addr_type_t_ -{ - FID_ADDR_IP_PREF, - FID_ADDR_MAC, - FID_ADDR_NSH -} __attribute__ ((packed)) fid_addr_type_t; - -/* flat address type */ -typedef struct -{ - union - { - ip_prefix_t ippref; - u8 mac[6]; - u32 nsh; - }; - fid_addr_type_t type; -} fid_address_t; - -typedef fid_address_t dp_address_t; - -#define fid_addr_ippref(_a) (_a)->ippref -#define fid_addr_prefix_length(_a) ip_prefix_len(&fid_addr_ippref(_a)) -#define fid_addr_ip_version(_a) ip_prefix_version(&fid_addr_ippref(_a)) -#define fid_addr_mac(_a) (_a)->mac -#define fid_addr_nsh(_a) (_a)->nsh -#define fid_addr_type(_a) (_a)->type -u8 *format_fid_address (u8 * s, va_list * args); - -typedef struct -{ - fid_address_t src; - fid_address_t dst; -} source_dest_t; - -#define sd_dst(_a) (_a)->dst -#define sd_src(_a) (_a)->src -#define sd_src_ippref(_a) fid_addr_ippref(&sd_src(_a)) -#define sd_dst_ippref(_a) fid_addr_ippref(&sd_dst(_a)) -#define sd_src_mac(_a) fid_addr_mac(&sd_src(_a)) -#define sd_dst_mac(_a) fid_addr_mac(&sd_dst(_a)) -#define sd_src_type(_a) fid_addr_type(&sd_src(_a)) -#define sd_dst_type(_a) fid_addr_type(&sd_dst(_a)) - -typedef struct -{ - u8 vni_mask_len; - u32 vni; - struct _gid_address_t *gid_addr; -} vni_t; - -#define vni_vni(_a) (_a)->vni -#define vni_mask_len(_a) (_a)->vni_mask_len -#define vni_gid(_a) (_a)->gid_addr - -typedef struct -{ - u32 spi; - u8 si; -} nsh_t; - -#define nsh_spi(_a) (_a)->spi -#define nsh_si(_a) (_a)->si - -typedef struct -{ - ip_address_t addr; - u32 bd; -} lcaf_arp_ndp_t; - -#define lcaf_arp_ndp_ip(_a) (_a)->addr -#define lcaf_arp_ndp_ip_ver(_a) ip_addr_version(&lcaf_arp_ndp_ip(_a)) -#define lcaf_arp_ndp_ip4(_a) ip_addr_v4(&lcaf_arp_ndp_ip(_a)) -#define lcaf_arp_ndp_ip6(_a) ip_addr_v6(&lcaf_arp_ndp_ip(_a)) -#define lcaf_arp_ndp_bd(_a) (_a)->bd - -typedef struct -{ - /* the union needs to be at the beginning! */ - union - { - source_dest_t sd; - lcaf_arp_ndp_t arp_ndp; - vni_t uni; - }; - u8 type; -} lcaf_t; - -#define lcaf_type(_a) (_a)->type -#define lcaf_vni(_a) vni_vni(& (_a)->uni) -#define lcaf_vni_len(_a) vni_mask_len(& (_a)->uni) - -/* might want to expand this in the future :) */ -typedef struct _gid_address_t -{ - union - { - ip_prefix_t ippref; - lcaf_t lcaf; - u8 mac[6]; - source_dest_t sd; - lcaf_arp_ndp_t arp_ndp; - nsh_t nsh; - }; - u8 type; - u32 vni; - u8 vni_mask; -} gid_address_t; - -u16 ip4_address_size_to_put (); -u16 ip6_address_size_to_put (); -u32 ip4_address_put (u8 * b, ip4_address_t * a); -u32 ip6_address_put (u8 * b, ip6_address_t * a); - -u16 ip_address_size_to_write (ip_address_t * a); -u16 ip_address_iana_afi (ip_address_t * a); -u8 ip_address_max_len (u8 ver); -u32 ip_address_put (u8 * b, ip_address_t * a); - -/* LISP AFI codes */ -typedef enum -{ - LISP_AFI_NO_ADDR, - LISP_AFI_IP, - LISP_AFI_IP6, - LISP_AFI_LCAF = 16387, - LISP_AFI_MAC = 16389 -} lisp_afi_e; - -u8 *format_gid_address (u8 * s, va_list * args); -uword unformat_gid_address (unformat_input_t * input, va_list * args); -int gid_address_cmp (gid_address_t * a1, gid_address_t * a2); -void gid_address_free (gid_address_t * a); - -u16 gid_address_size_to_put (gid_address_t * a); -u16 gid_address_put (u8 * b, gid_address_t * gid); -u8 gid_address_len (gid_address_t * a); -void *gid_address_cast (gid_address_t * gid, gid_address_type_t type); -void gid_address_copy (gid_address_t * dst, gid_address_t * src); -u32 gid_address_parse (u8 * offset, gid_address_t * a); -void gid_address_ip_set (gid_address_t * dst, void *src, u8 version); - -#define gid_address_type(_a) (_a)->type -#define gid_address_ippref(_a) (_a)->ippref -#define gid_address_ippref_len(_a) (_a)->ippref.len -#define gid_address_ip(_a) ip_prefix_addr(&gid_address_ippref(_a)) -#define gid_address_ip_version(_a) ip_addr_version(&gid_address_ip(_a)) -#define gid_address_lcaf(_a) (_a)->lcaf -#define gid_address_mac(_a) (_a)->mac -#define gid_address_nsh(_a) (_a)->nsh -#define gid_address_nsh_spi(_a) nsh_spi(&gid_address_nsh(_a)) -#define gid_address_nsh_si(_a) nsh_si(&gid_address_nsh(_a)) -#define gid_address_vni(_a) (_a)->vni -#define gid_address_vni_mask(_a) (_a)->vni_mask -#define gid_address_sd_dst_ippref(_a) sd_dst_ippref(&(_a)->sd) -#define gid_address_sd_src_ippref(_a) sd_src_ippref(&(_a)->sd) -#define gid_address_sd_dst_mac(_a) sd_dst_mac(&(_a)->sd) -#define gid_address_sd_src_mac(_a) sd_src_mac(&(_a)->sd) -#define gid_address_sd(_a) (_a)->sd -#define gid_address_sd_src(_a) sd_src(&gid_address_sd(_a)) -#define gid_address_sd_dst(_a) sd_dst(&gid_address_sd(_a)) -#define gid_address_sd_src_type(_a) sd_src_type(&gid_address_sd(_a)) -#define gid_address_sd_dst_type(_a) sd_dst_type(&gid_address_sd(_a)) -#define gid_address_arp_ndp(_a) (_a)->arp_ndp -#define gid_address_arp_ndp_bd(_a) lcaf_arp_ndp_bd(&gid_address_arp_ndp(_a)) -#define gid_address_arp_ndp_ip(_a) lcaf_arp_ndp_ip(&gid_address_arp_ndp(_a)) -#define gid_address_arp_ip4(_a) lcaf_arp_ndp_ip4(&gid_address_arp_ndp(_a)) -#define gid_address_ndp_ip6(_a) lcaf_arp_ndp_ip6(&gid_address_arp_ndp(_a)) -#define gid_address_ndp_bd gid_address_arp_ndp_bd -#define gid_address_arp_bd gid_address_arp_ndp_bd - -/* 'sub'address functions */ -#define foreach_gid_address_type_fcns \ - _(no_addr) \ - _(ip_prefix) \ - _(lcaf) \ - _(mac) \ - _(nsh) \ - _(sd) - -/* *INDENT-OFF* */ -#define _(_n) \ -u16 _n ## _size_to_write (void * pref); \ -u16 _n ## _write (u8 * p, void * pref); \ -u8 _n ## _length (void *a); \ -void * _n ## _cast (gid_address_t * a); \ -void _n ## _copy (void * dst , void * src); - -foreach_gid_address_type_fcns -#undef _ -/* *INDENT-ON* */ - -always_inline u64 -mac_to_u64 (u8 * m) -{ - return (*((u64 *) m) & 0xffffffffffff); -} - -typedef struct -{ - /* mark locator as local as opposed to remote */ - u8 local; - u8 state; - union - { - u32 sw_if_index; - gid_address_t address; - }; - u8 priority; - u8 weight; - u8 mpriority; - u8 mweight; - u8 probed; -} locator_t; - -u32 locator_parse (void *ptr, locator_t * loc); -void locator_copy (locator_t * dst, locator_t * src); -u32 locator_cmp (locator_t * l1, locator_t * l2); -void locator_free (locator_t * l); - -typedef struct -{ - /* locator-set name */ - u8 *name; - - /* vector of locator indices */ - u32 *locator_indices; - u8 local; -} locator_set_t; - -typedef struct -{ - gid_address_t eid; - - /* index of local locator set */ - union - { - u32 locator_set_index; - locator_t *locators; /* used for map register message */ - }; - - u32 ttl; - u8 action; - - u8 authoritative:1; - u8 local:1; - /* valid only for remote mappings */ - u8 is_static:1; - u8 pitr_set:1; - u8 nsh_set:1; - u8 almost_expired:1; - u8 delete_after_expiration:1; - u8 rsvd:1; - - u8 *key; - lisp_key_type_t key_id; - u8 timer_set; - u32 timer_handle; - counter_t packets; -} mapping_t; - -uword -unformat_negative_mapping_action (unformat_input_t * input, va_list * args); -u8 *format_negative_mapping_action (u8 *, va_list * args); - -typedef struct locator_pair -{ - /* local and remote locators (underlay attachment points) */ - ip_address_t lcl_loc; - ip_address_t rmt_loc; - - u8 priority; - u8 weight; -} locator_pair_t; - -void -build_src_dst (gid_address_t * sd, gid_address_t * src, gid_address_t * dst); - -void gid_address_from_ip (gid_address_t * g, ip_address_t * ip); -void gid_to_dp_address (gid_address_t * g, dp_address_t * d); - -#endif /* VNET_LISP_GPE_LISP_TYPES_H_ */ - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/src/vnet/lisp-cp/lisp_types_api.c b/src/vnet/lisp-cp/lisp_types_api.c deleted file mode 100644 index e966f625677..00000000000 --- a/src/vnet/lisp-cp/lisp_types_api.c +++ /dev/null @@ -1,88 +0,0 @@ -/* - *------------------------------------------------------------------ - * - * Copyright (c) 2020 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------ - */ - -#include -#include -#include - -int -unformat_lisp_eid_api (gid_address_t * dst, u32 vni, const vl_api_eid_t * eid) -{ - switch (eid->type) - { - case EID_TYPE_API_PREFIX: /* ip prefix */ - gid_address_type (dst) = GID_ADDR_IP_PREFIX; - ip_address_decode2 (&eid->address.prefix.address, &dst->ippref.addr); - gid_address_ippref_len (dst) = eid->address.prefix.len; - ip_prefix_normalize (&gid_address_ippref (dst)); - break; - case EID_TYPE_API_MAC: /* l2 mac */ - gid_address_type (dst) = GID_ADDR_MAC; - mac_address_decode (eid->address.mac, (mac_address_t *) gid_address_mac (dst)); - break; - default: - /* unknown type */ - return VNET_API_ERROR_INVALID_VALUE; - } - - gid_address_vni (dst) = clib_net_to_host_u32 (vni); - - return 0; -} - -void -lisp_fid_put_api (vl_api_eid_t * eid, const fid_address_t * fid) -{ - switch (fid_addr_type (fid)) - { - case FID_ADDR_IP_PREF: - ip_prefix_encode2 (&fid_addr_ippref (fid), &eid->address.prefix); - eid->type = EID_TYPE_API_PREFIX; - break; - - case FID_ADDR_MAC: - mac_address_encode ((mac_address_t *) fid_addr_mac (fid), eid->address.mac); - eid->type = EID_TYPE_API_MAC; - break; - - default: - clib_warning ("Unknown FID type %d!", fid_addr_type (fid)); - break; - } -} - -void -lisp_gid_put_api (vl_api_eid_t * eid, const gid_address_t * gid) -{ - switch (gid_address_type (gid)) - { - case GID_ADDR_IP_PREFIX: - ip_prefix_encode2 (&gid_address_ippref (gid), &eid->address.prefix); - eid->type = EID_TYPE_API_PREFIX; - break; - - case GID_ADDR_MAC: - mac_address_encode ((mac_address_t *) gid_address_mac (gid), eid->address.mac); - eid->type = EID_TYPE_API_MAC; - break; - - default: - clib_warning ("Unknown GID type %d!", gid_address_type (gid)); - break; - } -} diff --git a/src/vnet/lisp-cp/lisp_types_api.h b/src/vnet/lisp-cp/lisp_types_api.h deleted file mode 100644 index c1aa9dc81ff..00000000000 --- a/src/vnet/lisp-cp/lisp_types_api.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - *------------------------------------------------------------------ - * - * Copyright (c) 2020 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------ - */ - -#include -#include - -int unformat_lisp_eid_api (gid_address_t * dst, u32 vni, const vl_api_eid_t * eid); - -void lisp_fid_put_api (vl_api_eid_t * eid, const fid_address_t * fid); - -void lisp_gid_put_api (vl_api_eid_t * eid, const gid_address_t * gid); diff --git a/src/vnet/lisp-cp/one.api b/src/vnet/lisp-cp/one.api deleted file mode 100644 index be3a444e263..00000000000 --- a/src/vnet/lisp-cp/one.api +++ /dev/null @@ -1,1031 +0,0 @@ -/* - * Copyright (c) 2015-2017 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -option version = "2.0.0"; - -import "vnet/interface_types.api"; -import "vnet/lisp-cp/lisp_types.api"; - -/** \brief add or delete locator_set - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param is_add - add address if non-zero, else delete - @param locator_set_name - locator name - @param locator_num - number of locators - @param locators - locator records -*/ -manual_endian manual_print define one_add_del_locator_set -{ - u32 client_index; - u32 context; - bool is_add [default=true]; - string locator_set_name[64]; - u32 locator_num; - vl_api_local_locator_t locators[locator_num]; -}; - -/** \brief Reply for locator_set add/del - @param context - returned sender context, to match reply w/ request - @param retval - return code - @param ls_index - locator set index -*/ -define one_add_del_locator_set_reply -{ - u32 context; - i32 retval; - u32 ls_index; -}; - -/** \brief add or delete locator for locator set - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param is_add - add address if non-zero, else delete - @param locator_set_name - name of locator_set to add/del locator - @param sw_if_index - index of the interface - @param priority - priority of the locator - @param weight - weight of the locator -*/ -autoreply define one_add_del_locator -{ - u32 client_index; - u32 context; - bool is_add [default=true]; - string locator_set_name[64]; - vl_api_interface_index_t sw_if_index; - u8 priority; - u8 weight; -}; - - -/** \brief add or delete ONE eid-table - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param is_add - add address if non-zero, else delete - @param eid - endpoint identifier - @param locator_set_name - name of locator_set to add/del eid-table - @param vni - virtual network instance - @param key - secret key -*/ -autoreply define one_add_del_local_eid -{ - u32 client_index; - u32 context; - bool is_add [default=true]; - vl_api_eid_t eid; - string locator_set_name[64]; - u32 vni; - vl_api_hmac_key_t key; -}; - -/** \brief Set TTL for map register messages - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param ttl - time to live -*/ -autoreply define one_map_register_set_ttl -{ - u32 client_index; - u32 context; - u32 ttl; -}; - -/** \brief Get TTL for map register messages - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request -*/ -define show_one_map_register_ttl -{ - u32 client_index; - u32 context; -}; - -/** \brief Contains current TTL for map register messages - @param client_index - opaque cookie to identify the sender - @param retval - return code - @param ttl - time to live -*/ -define show_one_map_register_ttl_reply -{ - u32 context; - i32 retval; - u32 ttl; -}; - -/** \brief Add/delete map server - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param is_add - add address if non-zero; delete otherwise - @param is_ipv6 - if non-zero the address is ipv6, else ipv4 - @param ip_address - map server IP address -*/ -autoreply define one_add_del_map_server -{ - u32 client_index; - u32 context; - bool is_add [default=true]; - vl_api_address_t ip_address; -}; - -/** \brief add or delete map-resolver - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param is_add - add address if non-zero, else delete - @param is_ipv6 - if non-zero the address is ipv6, else ipv4 - @param ip_address - array of address bytes -*/ -autoreply define one_add_del_map_resolver -{ - u32 client_index; - u32 context; - bool is_add [default=true]; - vl_api_address_t ip_address; -}; - -/** \brief enable or disable ONE feature - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param is_enable - enable protocol if non-zero, else disable -*/ -autoreply define one_enable_disable -{ - u32 client_index; - u32 context; - bool is_enable [default=true]; -}; - -/** \brief configure or delete ONE NSH mapping - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param ls_name - locator set name - @param is_add - add locator set if non-zero; delete otherwise -*/ -autoreply define one_nsh_set_locator_set -{ - u32 client_index; - u32 context; - bool is_add [default=true]; - string ls_name[64]; -}; - -/** \brief configure or disable ONE PITR node - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param ls_name - locator set name - @param is_add - add locator set if non-zero, else disable pitr -*/ -autoreply define one_pitr_set_locator_set -{ - u32 client_index; - u32 context; - bool is_add [default=true]; - string ls_name[64]; -}; - -/** \brief configure or disable use of PETR - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param is_ip4 - Address is IPv4 if set and IPv6 otherwise - @param address - PETR IP address - @param is_add - add locator set if non-zero, else disable PETR -*/ -autoreply define one_use_petr -{ - u32 client_index; - u32 context; - vl_api_address_t ip_address; - bool is_add [default=true]; -}; - -/** \brief Request for ONE PETR status - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request -*/ -define show_one_use_petr -{ - u32 client_index; - u32 context; -}; - -/** \brief ONE PETR status, enable or disable - @param context - sender context, to match reply w/ request - @param enable - ONE PETR enable if non-zero, else disable - @param is_ip4 - Address is IPv4 if non-zero, else IPv6 - @param address - PETR IP address -*/ -define show_one_use_petr_reply -{ - u32 context; - i32 retval; - bool status; - vl_api_address_t ip_address; -}; - -/** \brief Get state of ONE RLOC probing - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request -*/ -define show_one_rloc_probe_state -{ - u32 client_index; - u32 context; -}; - -/** \brief Reply for show_one_rloc_probe_state - @param context - returned sender context, to match reply w/ request - @param retval - return code - @param is_enable - state of RLOC probing -*/ -define show_one_rloc_probe_state_reply -{ - u32 context; - i32 retval; - bool is_enable; -}; - -/** \brief enable/disable ONE RLOC probing - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param is_enable - enable if non-zero; disable otherwise -*/ -autoreply define one_rloc_probe_enable_disable -{ - u32 client_index; - u32 context; - bool is_enable [default=true]; -}; - -/** \brief enable/disable ONE map-register - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param is_enable - enable if non-zero; disable otherwise -*/ -autoreply define one_map_register_enable_disable -{ - u32 client_index; - u32 context; - bool is_enable [default=true]; -}; - -/** \brief Get state of ONE map-register - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request -*/ -define show_one_map_register_state -{ - u32 client_index; - u32 context; -}; - -/** \brief Reply for show_one_map_register_state - @param context - returned sender context, to match reply w/ request - @param retval - return code -*/ -define show_one_map_register_state_reply -{ - u32 context; - i32 retval; - bool is_enable; -}; - -enum one_map_mode -{ - ONE_MAP_MODE_API_DST_ONLY = 0, - ONE_MAP_MODE_API_SRC_DST = 1, -}; - -/** \brief set ONE map-request mode. Based on configuration VPP will send - src/dest or just normal destination map requests. - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param mode - new map-request mode. Supported values are: - 0 - destination only - 1 - source/destination -*/ -autoreply define one_map_request_mode -{ - u32 client_index; - u32 context; - vl_api_one_map_mode_t mode; -}; - -/** \brief Request for ONE map-request mode - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request -*/ -define show_one_map_request_mode -{ - u32 client_index; - u32 context; -}; - -/** \brief Reply for show_one_map_request_mode - @param context - returned sender context, to match reply w/ request - @param retval - return code - @param mode - map-request mode -*/ -define show_one_map_request_mode_reply -{ - u32 context; - i32 retval; - vl_api_one_map_mode_t mode; -}; - -/** \brief add or delete remote static mapping - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param is_add - add address if non-zero, else delete - @param is_src_dst - flag indicating src/dst based routing policy - @param del_all - if set, delete all remote mappings - @param vni - virtual network instance - @param action - negative map-reply action - @param deid - dst EID - @param seid - src EID, valid only if is_src_dst is enabled - @param rloc_num - number of remote locators - @param rlocs - remote locator records -*/ -autoreply manual_print manual_endian define one_add_del_remote_mapping -{ - u32 client_index; - u32 context; - bool is_add [default=true]; - bool is_src_dst; - bool del_all; - u32 vni; - u8 action; - vl_api_eid_t deid; - vl_api_eid_t seid; - u32 rloc_num; - vl_api_remote_locator_t rlocs[rloc_num]; -}; - -typedef one_l2_arp_entry -{ - vl_api_mac_address_t mac; - vl_api_ip4_address_t ip4; -}; - -/** \brief Add/delete L2 ARP entries - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param is_add - add if non-zero; delete otherwise - @param bd - bridge domain - @param entry - ARP entry -*/ -autoreply define one_add_del_l2_arp_entry -{ - u32 client_index; - u32 context; - bool is_add [default=true]; - u32 bd; - vl_api_one_l2_arp_entry_t entry; -}; - -/** \brief Request for L2 ARP entries from specified bridge domain - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param bd - bridge domain -*/ -define one_l2_arp_entries_get -{ - u32 client_index; - u32 context; - u32 bd; -}; - -/** \brief Reply with L2 ARP entries from specified bridge domain - @param context - sender context, to match reply w/ request - @param retval - error code - @param count - number of elements in the list - @param vl_api_one_arp_entry_t - list of entries -*/ -manual_print manual_endian define one_l2_arp_entries_get_reply -{ - u32 context; - i32 retval; - u32 count; - vl_api_one_l2_arp_entry_t entries[count]; -}; - -typedef one_ndp_entry -{ - vl_api_mac_address_t mac; - vl_api_ip6_address_t ip6; -}; - - -autoreply define one_add_del_ndp_entry -{ - u32 client_index; - u32 context; - bool is_add [default=true]; - u32 bd; - vl_api_one_ndp_entry_t entry; -}; - -define one_ndp_entries_get -{ - u32 client_index; - u32 context; - u32 bd; -}; - -manual_print manual_endian define one_ndp_entries_get_reply -{ - u32 context; - i32 retval; - u32 count; - vl_api_one_ndp_entry_t entries[count]; -}; - -/** \brief Set ONE transport protocol - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param protocol - supported values: - 1: UDP based LISP (default) - 2: binary API -*/ -autoreply define one_set_transport_protocol -{ - u32 client_index; - u32 context; - u8 protocol; -}; - -define one_get_transport_protocol -{ - u32 client_index; - u32 context; -}; - -define one_get_transport_protocol_reply -{ - u32 context; - i32 retval; - u8 protocol; -}; - -/** \brief Request for list of bridge domains used by neighbor discovery - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request -*/ -define one_ndp_bd_get -{ - u32 client_index; - u32 context; -}; - -/** \brief Reply with list of bridge domains used by neighbor discovery - @param context - sender context, to match reply w/ request - @param count - number of elements in the list - @param bridge_domains - list of BDs -*/ -manual_print manual_endian define one_ndp_bd_get_reply -{ - u32 context; - i32 retval; - u32 count; - u32 bridge_domains[count]; -}; - -/** \brief Request for list of bridge domains used by L2 ARP table - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request -*/ -define one_l2_arp_bd_get -{ - u32 client_index; - u32 context; -}; - -/** \brief Reply with list of bridge domains used by L2 ARP table - @param context - sender context, to match reply w/ request - @param count - number of elements in the list - @param bridge_domains - list of BDs -*/ -manual_print manual_endian define one_l2_arp_bd_get_reply -{ - u32 context; - i32 retval; - u32 count; - u32 bridge_domains[count]; -}; - -/** \brief add or delete ONE adjacency adjacency - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param is_add - add address if non-zero, else delete - @param vni - virtual network instance - @param reid - remote EID - @param leid - local EID -*/ -autoreply define one_add_del_adjacency -{ - u32 client_index; - u32 context; - u8 is_add; - u32 vni; - vl_api_eid_t reid; - vl_api_eid_t leid; -}; - -/** \brief add or delete map request itr rlocs - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param is_add - add address if non-zero, else delete - @param locator_set_name - locator set name -*/ -autoreply define one_add_del_map_request_itr_rlocs -{ - u32 client_index; - u32 context; - bool is_add [default=true]; - string locator_set_name[64]; -}; - -/** \brief map/unmap vni/bd_index to vrf - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param is_add - add or delete mapping - @param dp_table - virtual network id/bridge domain index - @param vrf - vrf - @param is_l2 - is l2 -*/ -autoreply define one_eid_table_add_del_map -{ - u32 client_index; - u32 context; - bool is_add [default=true]; - u32 vni; - u32 dp_table; - bool is_l2; -}; - -/** \brief Request for map one locator status - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param locator_set_index - index of locator_set - @param ls_name - locator set name - @param is_index_set - flag indicating whether ls_name or ls_index is set - */ -define one_locator_dump -{ - u32 client_index; - u32 context; - u32 ls_index; - string ls_name[64]; - bool is_index_set; -}; - -/** \brief ONE locator_set status - @param local - if is set, then locator is local - @param locator_set_name - name of the locator_set - @param sw_if_index - sw_if_index of the locator - @param priority - locator priority - @param weight - locator weight - */ -define one_locator_details -{ - u32 context; - u8 local; - vl_api_interface_index_t sw_if_index; - vl_api_address_t ip_address; - u8 priority; - u8 weight; -}; - -/** \brief ONE locator_set status - @param context - sender context, to match reply w/ request - @param ls_index - locator set index - @param ls_name - name of the locator set - */ -define one_locator_set_details -{ - u32 context; - u32 ls_index; - string ls_name[64]; -}; - -enum one_filter -{ - ONE_FILTER_API_ALL = 0, - ONE_FILTER_API_LOCAL = 1, - ONE_FILTER_API_REMOTE = 2, -}; - -/** \brief Request for locator_set summary status - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param filter - filter type - Supported values: - 0: all locator sets - 1: local locator sets - 2: remote locator sets - */ -define one_locator_set_dump -{ - u32 client_index; - u32 context; - vl_api_one_filter_t filter; -}; - -/** \brief Dump ONE eid-table - @param context - sender context, to match reply w/ request - @param locator_set_index - index of locator_set, if ~0 then the mapping - is negative - @param action - negative map request action - @param is_local - local if non-zero, else remote - @param is_src_dst - EID is type of source/destination - @param deid - dst EID - @param seid - src EID - @param vni - virtual network instance - @param ttl - time to live - @param authoritative - authoritative - @param key - secret key -*/ - -// FIXME: action, authoritative - -define one_eid_table_details -{ - u32 context; - u32 locator_set_index; - u8 action; - bool is_local; - bool is_src_dst; - u32 vni; - vl_api_eid_t deid; - vl_api_eid_t seid; - u32 ttl; - u8 authoritative; - vl_api_hmac_key_t key; -}; - -/** \brief Request for eid table summary status - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param eid_set - if non-zero request info about specific mapping - @param vni - virtual network instance; valid only if eid_set != 0 - @param eid - endpoint identifier - @param filter - filter type; - Support values: - 0: all eid - 1: local eid - 2: remote eid - */ -define one_eid_table_dump -{ - u32 client_index; - u32 context; - bool eid_set; - u32 vni; - vl_api_eid_t eid; - vl_api_one_filter_t filter; -}; - -/** \brief ONE adjacency - @param reid - remote EID - @param leid - local EID - */ -typedef one_adjacency -{ - vl_api_eid_t reid; - vl_api_eid_t leid; -}; - -/** \brief ONE adjacency reply - @param count - number of adjacencies - @param adjacencies - array of adjacencies - */ -manual_endian manual_print define one_adjacencies_get_reply -{ - u32 context; - i32 retval; - u32 count; - vl_api_one_adjacency_t adjacencies[count]; -}; - -/** \brief Request for ONE adjacencies - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param vni - filter adjacencies by VNI - */ -define one_adjacencies_get -{ - u32 client_index; - u32 context; - u32 vni; -}; - -/** \brief Shows relationship between vni and vrf/bd - @param dp_table - VRF index or bridge domain index - @param vni - virtual network instance - */ -define one_eid_table_map_details -{ - u32 context; - u32 vni; - u32 dp_table; -}; - -/** \brief Request for one_eid_table_map_details - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param is_l2 - if set dump vni/bd mappings else vni/vrf - */ -define one_eid_table_map_dump -{ - u32 client_index; - u32 context; - bool is_l2; -}; - -/** \brief Dumps all VNIs used in mappings - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - */ -define one_eid_table_vni_dump -{ - u32 client_index; - u32 context; -}; - -/** \brief reply to one_eid_table_vni_dump - @param context - sender context, to match reply w/ request - @param vni - virtual network instance - */ -define one_eid_table_vni_details -{ - u32 context; - u32 vni; -}; - -/** \brief ONE map resolver status - @param is_ipv6 - if non-zero the address is ipv6, else ipv4 - @param ip_address - array of address bytes - */ -define one_map_resolver_details -{ - u32 context; - vl_api_address_t ip_address; -}; - -/** \brief Request for map resolver summary status - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - */ -define one_map_resolver_dump -{ - u32 client_index; - u32 context; -}; - -/** \brief ONE map server details - @param is_ipv6 - if non-zero the address is ipv6, else ipv4 - @param ip_address - array of address bytes - */ -define one_map_server_details -{ - u32 context; - vl_api_address_t ip_address; -}; - -/** \brief Request for map server summary status - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - */ -define one_map_server_dump -{ - u32 client_index; - u32 context; -}; - -/** \brief Request for ONE status - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request -*/ -define show_one_status -{ - u32 client_index; - u32 context; -}; - -/** \brief ONE status - @param context - sender context, to match reply w/ request - @param feature_status - enabled if non-zero, else disabled - @param gpe_status - enabled if non-zero, else disabled -*/ -define show_one_status_reply -{ - u32 context; - i32 retval; - bool feature_status; - bool gpe_status; -}; - -/** \brief Get ONE map request itr rlocs status - @param context - sender context, to match reply w/ request - @param locator_set_name - name of the locator_set - */ -define one_get_map_request_itr_rlocs -{ - u32 client_index; - u32 context; -}; - -/** \brief Request for map request itr rlocs summary status - */ -define one_get_map_request_itr_rlocs_reply -{ - u32 context; - i32 retval; - string locator_set_name[64]; -}; - -/** \brief Request for ONE NSH mapping - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request -*/ -define show_one_nsh_mapping -{ - u32 client_index; - u32 context; -}; - -/** \brief Reply for ONE NSH mapping - @param context - sender context, to match reply w/ request - @param is_set - is ONE NSH mapping set - @param locator_set_name - name of the locator_set if NSH mapping is set -*/ -define show_one_nsh_mapping_reply -{ - u32 context; - i32 retval; - bool is_set; - string locator_set_name[64]; -}; - -/** \brief Request for ONE PITR status - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request -*/ -define show_one_pitr -{ - u32 client_index; - u32 context; -}; - -/** \brief Status of ONE PITR, enable or disable - @param context - sender context, to match reply w/ request - @param status - ONE PITR enable if non-zero, else disable - @param locator_set_name - name of the locator_set -*/ -define show_one_pitr_reply -{ - u32 context; - i32 retval; - bool status; - string locator_set_name[64]; -}; - -define one_stats_dump -{ - u32 client_index; - u32 context; -}; - -define one_stats_details -{ - u32 context; - u32 vni; - vl_api_eid_t deid; - vl_api_eid_t seid; - vl_api_address_t rloc; - vl_api_address_t lloc; - - u32 pkt_count; - u32 bytes; -}; - -autoreply define one_stats_flush -{ - u32 client_index; - u32 context; -}; - -autoreply define one_stats_enable_disable -{ - u32 client_index; - u32 context; - bool is_enable [default=true]; -}; - -define show_one_stats_enable_disable -{ - u32 client_index; - u32 context; -}; - -define show_one_stats_enable_disable_reply -{ - u32 context; - i32 retval; - bool is_enable; -}; - -autoreply define one_map_register_fallback_threshold -{ - u32 client_index; - u32 context; - u32 value; -}; - -define show_one_map_register_fallback_threshold -{ - u32 client_index; - u32 context; -}; - -define show_one_map_register_fallback_threshold_reply -{ - u32 context; - i32 retval; - u32 value; -}; - -autoreply define one_enable_disable_xtr_mode -{ - u32 client_index; - u32 context; - bool is_enable [default=true]; -}; - -define one_show_xtr_mode -{ - u32 client_index; - u32 context; -}; - -define one_show_xtr_mode_reply -{ - u32 context; - i32 retval; - bool is_enable; -}; - -autoreply define one_enable_disable_petr_mode -{ - u32 client_index; - u32 context; - bool is_enable [default=true]; -}; - -define one_show_petr_mode -{ - u32 client_index; - u32 context; -}; - -define one_show_petr_mode_reply -{ - u32 context; - i32 retval; - bool is_enable; -}; - -autoreply define one_enable_disable_pitr_mode -{ - u32 client_index; - u32 context; - bool is_enable [default=true]; -}; - -define one_show_pitr_mode -{ - u32 client_index; - u32 context; -}; - -define one_show_pitr_mode_reply -{ - u32 context; - i32 retval; - bool is_enable; -}; - -/* - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/src/vnet/lisp-cp/one_api.c b/src/vnet/lisp-cp/one_api.c deleted file mode 100644 index 452a756ee80..00000000000 --- a/src/vnet/lisp-cp/one_api.c +++ /dev/null @@ -1,1741 +0,0 @@ -/* - *------------------------------------------------------------------ - * one_api.c - Overlay Network Engine API - * - * Copyright (c) 2016-2017 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------ - */ - -#include -#include - -#include -#include -#include -#include - -#include -#include - -#include - -#define vl_api_one_add_del_locator_set_t_endian vl_noop_handler -#define vl_api_one_add_del_locator_set_t_print vl_noop_handler -#define vl_api_one_add_del_remote_mapping_t_endian vl_noop_handler -#define vl_api_one_add_del_remote_mapping_t_print vl_noop_handler - -#define vl_api_one_add_del_locator_set_t_endian vl_noop_handler -#define vl_api_one_add_del_locator_set_t_print vl_noop_handler -#define vl_api_one_add_del_remote_mapping_t_endian vl_noop_handler -#define vl_api_one_add_del_remote_mapping_t_print vl_noop_handler - -#define vl_api_one_add_del_l2_arp_entry vl_noop_handler -#define vl_api_one_l2_arp_bd_get vl_noop_handler - -#define vl_api_one_ndp_entries_get_reply_t_endian vl_noop_handler -#define vl_api_one_ndp_entries_get_reply_t_print vl_noop_handler - -#define vl_typedefs /* define message structures */ -#include -#undef vl_typedefs - -#define vl_endianfun /* define message structures */ -#include -#undef vl_endianfun - -/* instantiate all the print functions we know about */ -#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) -#define vl_printfun -#include -#undef vl_printfun - -#include - -#define REPLY_DETAILS(t, body) \ -do { \ - vl_api_registration_t * reg; \ - rv = vl_msg_api_pd_handler (mp, rv); \ - reg = vl_api_client_index_to_registration (mp->client_index); \ - if (!reg) \ - return; \ - \ - rmp = vl_msg_api_alloc (sizeof (*rmp)); \ - rmp->_vl_msg_id = ntohs((t)); \ - rmp->context = mp->context; \ - do {body;} while (0); \ - vl_api_send_msg (reg, (u8 *)&rmp); \ -} while(0); - -#define foreach_vpe_api_msg \ -_(ONE_ADD_DEL_LOCATOR_SET, one_add_del_locator_set) \ -_(ONE_ADD_DEL_LOCATOR, one_add_del_locator) \ -_(ONE_ADD_DEL_LOCAL_EID, one_add_del_local_eid) \ -_(ONE_ADD_DEL_MAP_RESOLVER, one_add_del_map_resolver) \ -_(ONE_ADD_DEL_MAP_SERVER, one_add_del_map_server) \ -_(ONE_ENABLE_DISABLE, one_enable_disable) \ -_(ONE_RLOC_PROBE_ENABLE_DISABLE, one_rloc_probe_enable_disable) \ -_(ONE_MAP_REGISTER_ENABLE_DISABLE, one_map_register_enable_disable) \ -_(ONE_MAP_REGISTER_FALLBACK_THRESHOLD, \ - one_map_register_fallback_threshold) \ -_(ONE_ADD_DEL_REMOTE_MAPPING, one_add_del_remote_mapping) \ -_(ONE_ADD_DEL_ADJACENCY, one_add_del_adjacency) \ -_(ONE_PITR_SET_LOCATOR_SET, one_pitr_set_locator_set) \ -_(ONE_NSH_SET_LOCATOR_SET, one_nsh_set_locator_set) \ -_(ONE_MAP_REQUEST_MODE, one_map_request_mode) \ -_(ONE_EID_TABLE_ADD_DEL_MAP, one_eid_table_add_del_map) \ -_(ONE_LOCATOR_SET_DUMP, one_locator_set_dump) \ -_(ONE_LOCATOR_DUMP, one_locator_dump) \ -_(ONE_EID_TABLE_DUMP, one_eid_table_dump) \ -_(ONE_MAP_RESOLVER_DUMP, one_map_resolver_dump) \ -_(ONE_MAP_SERVER_DUMP, one_map_server_dump) \ -_(ONE_EID_TABLE_MAP_DUMP, one_eid_table_map_dump) \ -_(ONE_EID_TABLE_VNI_DUMP, one_eid_table_vni_dump) \ -_(ONE_ADJACENCIES_GET, one_adjacencies_get) \ -_(ONE_MAP_REGISTER_SET_TTL, one_map_register_set_ttl) \ -_(SHOW_ONE_NSH_MAPPING, show_one_nsh_mapping) \ -_(SHOW_ONE_RLOC_PROBE_STATE, show_one_rloc_probe_state) \ -_(SHOW_ONE_MAP_REGISTER_STATE, show_one_map_register_state) \ -_(SHOW_ONE_MAP_REGISTER_TTL, show_one_map_register_ttl) \ -_(SHOW_ONE_MAP_REGISTER_FALLBACK_THRESHOLD, \ - show_one_map_register_fallback_threshold) \ -_(SHOW_ONE_STATUS, show_one_status) \ -_(ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \ - one_add_del_map_request_itr_rlocs) \ -_(ONE_GET_MAP_REQUEST_ITR_RLOCS, one_get_map_request_itr_rlocs) \ -_(SHOW_ONE_PITR, show_one_pitr) \ -_(SHOW_ONE_MAP_REQUEST_MODE, show_one_map_request_mode) \ -_(ONE_USE_PETR, one_use_petr) \ -_(SHOW_ONE_USE_PETR, show_one_use_petr) \ -_(SHOW_ONE_STATS_ENABLE_DISABLE, show_one_stats_enable_disable) \ -_(ONE_STATS_ENABLE_DISABLE, one_stats_enable_disable) \ -_(ONE_STATS_DUMP, one_stats_dump) \ -_(ONE_STATS_FLUSH, one_stats_flush) \ -_(ONE_L2_ARP_BD_GET, one_l2_arp_bd_get) \ -_(ONE_L2_ARP_ENTRIES_GET, one_l2_arp_entries_get) \ -_(ONE_ADD_DEL_L2_ARP_ENTRY, one_add_del_l2_arp_entry) \ -_(ONE_ADD_DEL_NDP_ENTRY, one_add_del_ndp_entry) \ -_(ONE_NDP_BD_GET, one_ndp_bd_get) \ -_(ONE_NDP_ENTRIES_GET, one_ndp_entries_get) \ -_(ONE_SET_TRANSPORT_PROTOCOL, one_set_transport_protocol) \ -_(ONE_GET_TRANSPORT_PROTOCOL, one_get_transport_protocol) \ -_(ONE_ENABLE_DISABLE_XTR_MODE, one_enable_disable_xtr_mode) \ -_(ONE_SHOW_XTR_MODE, one_show_xtr_mode) \ -_(ONE_ENABLE_DISABLE_PITR_MODE, one_enable_disable_pitr_mode) \ -_(ONE_SHOW_PITR_MODE, one_show_pitr_mode) \ -_(ONE_ENABLE_DISABLE_PETR_MODE, one_enable_disable_petr_mode) \ -_(ONE_SHOW_PETR_MODE, one_show_petr_mode) \ - - -static locator_t * -unformat_one_locs (vl_api_remote_locator_t * rmt_locs, u32 rloc_num) -{ - u32 i; - locator_t *locs = 0, loc; - vl_api_remote_locator_t *r; - - for (i = 0; i < rloc_num; i++) - { - /* remote locators */ - r = &rmt_locs[i]; - clib_memset (&loc, 0, sizeof (loc)); - ip_address_decode2 (&r->ip_address, &loc.address.ippref.addr); - loc.address.ippref.len = - ip_address_max_len (loc.address.ippref.addr.version); - - loc.priority = r->priority; - loc.weight = r->weight; - - vec_add1 (locs, loc); - } - return locs; -} - -static void -vl_api_one_map_register_set_ttl_t_handler (vl_api_one_map_register_set_ttl_t * - mp) -{ - vl_api_one_map_register_set_ttl_reply_t *rmp; - int rv = 0; - - mp->ttl = clib_net_to_host_u32 (mp->ttl); - rv = vnet_lisp_map_register_set_ttl (mp->ttl); - - REPLY_MACRO (VL_API_ONE_MAP_REGISTER_SET_TTL_REPLY); -} - -static void - vl_api_show_one_map_register_ttl_t_handler - (vl_api_show_one_map_register_ttl_t * mp) -{ - vl_api_show_one_map_register_ttl_reply_t *rmp; - int rv = 0; - - u32 ttl = vnet_lisp_map_register_get_ttl (); - /* *INDENT-OFF* */ - REPLY_MACRO2 (VL_API_SHOW_ONE_MAP_REGISTER_TTL_REPLY, - ({ - rmp->ttl = clib_host_to_net_u32 (ttl); - })); - /* *INDENT-ON* */ -} - -static void -vl_api_one_add_del_locator_set_t_handler (vl_api_one_add_del_locator_set_t * - mp) -{ - vl_api_one_add_del_locator_set_reply_t *rmp; - int rv = 0; - vnet_lisp_add_del_locator_set_args_t _a, *a = &_a; - locator_t locator; - vl_api_local_locator_t *ls_loc; - u32 ls_index = ~0, locator_num; - u8 *locator_name = NULL; - int i; - - clib_memset (a, 0, sizeof (a[0])); - - mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0; - locator_name = format (0, "%s", mp->locator_set_name); - vec_terminate_c_string (locator_name); - - a->name = locator_name; - a->is_add = mp->is_add; - a->local = 1; - locator_num = clib_net_to_host_u32 (mp->locator_num); - - clib_memset (&locator, 0, sizeof (locator)); - for (i = 0; i < locator_num; i++) - { - ls_loc = &mp->locators[i]; - VALIDATE_SW_IF_INDEX (ls_loc); - - locator.sw_if_index = htonl (ls_loc->sw_if_index); - locator.priority = ls_loc->priority; - locator.weight = ls_loc->weight; - locator.local = 1; - vec_add1 (a->locators, locator); - } - - rv = vnet_lisp_add_del_locator_set (a, &ls_index); - - BAD_SW_IF_INDEX_LABEL; - - vec_free (locator_name); - vec_free (a->locators); - - /* *INDENT-OFF* */ - REPLY_MACRO2 (VL_API_ONE_ADD_DEL_LOCATOR_SET_REPLY, - ({ - rmp->ls_index = clib_host_to_net_u32 (ls_index); - })); - /* *INDENT-ON* */ -} - -static void -vl_api_one_add_del_locator_t_handler (vl_api_one_add_del_locator_t * mp) -{ - vl_api_one_add_del_locator_reply_t *rmp; - int rv = 0; - locator_t locator, *locators = NULL; - vnet_lisp_add_del_locator_set_args_t _a, *a = &_a; - u32 ls_index = ~0; - u8 *locator_name = NULL; - - clib_memset (&locator, 0, sizeof (locator)); - clib_memset (a, 0, sizeof (a[0])); - - locator.sw_if_index = ntohl (mp->sw_if_index); - locator.priority = mp->priority; - locator.weight = mp->weight; - locator.local = 1; - vec_add1 (locators, locator); - - mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0; - locator_name = format (0, "%s", mp->locator_set_name); - vec_terminate_c_string (locator_name); - - a->name = locator_name; - a->locators = locators; - a->is_add = mp->is_add; - a->local = 1; - - rv = vnet_lisp_add_del_locator (a, NULL, &ls_index); - - vec_free (locators); - vec_free (locator_name); - - REPLY_MACRO (VL_API_ONE_ADD_DEL_LOCATOR_REPLY); -} - -typedef struct -{ - u32 spi; - u8 si; -} __attribute__ ((__packed__)) lisp_nsh_api_t; - -static int -unformat_one_eid_api (gid_address_t * dst, u32 vni, vl_api_eid_t * eid) -{ - fib_prefix_t prefix; - - switch (eid->type) - { - case EID_TYPE_API_PREFIX: - ip_prefix_decode (&eid->address.prefix, &prefix); - gid_address_type (dst) = GID_ADDR_IP_PREFIX; - if (prefix.fp_proto == FIB_PROTOCOL_IP4) - gid_address_ip_set (dst, &prefix.fp_addr.ip4, AF_IP4); - if (prefix.fp_proto == FIB_PROTOCOL_IP6) - gid_address_ip_set (dst, &prefix.fp_addr.ip6, AF_IP6); - gid_address_ippref_len (dst) = prefix.fp_len; - ip_prefix_normalize (&gid_address_ippref (dst)); - break; - case EID_TYPE_API_MAC: - gid_address_type (dst) = GID_ADDR_MAC; - mac_address_decode (eid->address.mac, - (mac_address_t *) & gid_address_mac (dst)); - break; - case EID_TYPE_API_NSH: - gid_address_type (dst) = GID_ADDR_NSH; - gid_address_nsh_spi (dst) = clib_net_to_host_u32 (eid->address.nsh.spi); - gid_address_nsh_si (dst) = eid->address.nsh.si; - break; - default: - /* unknown type */ - return VNET_API_ERROR_INVALID_VALUE; - } - - gid_address_vni (dst) = vni; - - return 0; -} - -static void -fid_to_api_eid (fid_address_t * fid, vl_api_eid_t * eid) -{ - fib_prefix_t fib_prefix; - u32 eid_type; - - switch (fid_addr_type (fid)) - { - case FID_ADDR_IP_PREF: - eid_type = EID_TYPE_API_PREFIX; - ip_prefix_to_fib_prefix (&fid_addr_ippref (fid), &fib_prefix); - ip_prefix_encode (&fib_prefix, &eid->address.prefix); - break; - case FID_ADDR_MAC: - eid_type = EID_TYPE_API_MAC; - mac_address_encode ((mac_address_t *) fid_addr_mac (fid), - eid->address.mac); - break; - default: - /* unknown type */ - return; - } - - eid->type = eid_type; -} - -static void -vl_api_one_add_del_local_eid_t_handler (vl_api_one_add_del_local_eid_t * mp) -{ - vl_api_one_add_del_local_eid_reply_t *rmp; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - int rv = 0; - gid_address_t _eid, *eid = &_eid; - uword *p = NULL; - u32 locator_set_index = ~0, map_index = ~0; - vnet_lisp_add_del_mapping_args_t _a, *a = &_a; - u8 *name = NULL, *key = NULL; - clib_memset (a, 0, sizeof (a[0])); - clib_memset (eid, 0, sizeof (eid[0])); - - rv = unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni), &mp->eid); - if (rv) - goto out; - - if (gid_address_type (eid) == GID_ADDR_NSH) - { - rv = VNET_API_ERROR_INVALID_VALUE; - goto out; - } - - mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0; - name = format (0, "%s", mp->locator_set_name); - vec_terminate_c_string (name); - p = hash_get_mem (lcm->locator_set_index_by_name, name); - if (!p) - { - rv = VNET_API_ERROR_INVALID_VALUE; - goto out; - } - locator_set_index = p[0]; - - if (mp->key.id != KEY_ID_API_HMAC_NO_KEY) - key = format (0, "%s", mp->key.key); - - /* XXX treat batch configuration */ - a->is_add = mp->is_add; - gid_address_copy (&a->eid, eid); - a->locator_set_index = locator_set_index; - a->local = 1; - a->key = key; - a->key_id = mp->key.id; - - rv = vnet_lisp_add_del_local_mapping (a, &map_index); - -out: - vec_free (name); - vec_free (key); - gid_address_free (&a->eid); - - REPLY_MACRO (VL_API_ONE_ADD_DEL_LOCAL_EID_REPLY); -} - -static void - vl_api_one_eid_table_add_del_map_t_handler - (vl_api_one_eid_table_add_del_map_t * mp) -{ - vl_api_one_eid_table_add_del_map_reply_t *rmp; - int rv = 0; - rv = vnet_lisp_eid_table_map (clib_net_to_host_u32 (mp->vni), - clib_net_to_host_u32 (mp->dp_table), - mp->is_l2, mp->is_add); -REPLY_MACRO (VL_API_ONE_EID_TABLE_ADD_DEL_MAP_REPLY)} - -static void -vl_api_one_add_del_map_server_t_handler (vl_api_one_add_del_map_server_t * mp) -{ - vl_api_one_add_del_map_server_reply_t *rmp; - int rv = 0; - ip_address_t addr; - - clib_memset (&addr, 0, sizeof (addr)); - - ip_address_decode2 (&mp->ip_address, &addr); - - rv = vnet_lisp_add_del_map_server (&addr, mp->is_add); - - REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_SERVER_REPLY); -} - -static void -vl_api_one_add_del_map_resolver_t_handler (vl_api_one_add_del_map_resolver_t - * mp) -{ - vl_api_one_add_del_map_resolver_reply_t *rmp; - int rv = 0; - vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a; - - clib_memset (a, 0, sizeof (a[0])); - - ip_address_decode2 (&mp->ip_address, &a->address); - - a->is_add = mp->is_add; - - rv = vnet_lisp_add_del_map_resolver (a); - - REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_RESOLVER_REPLY); -} - -static void - vl_api_one_map_register_enable_disable_t_handler - (vl_api_one_map_register_enable_disable_t * mp) -{ - vl_api_one_map_register_enable_disable_reply_t *rmp; - int rv = 0; - - vnet_lisp_map_register_enable_disable (mp->is_enable); - REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY); -} - -static void - vl_api_one_rloc_probe_enable_disable_t_handler - (vl_api_one_rloc_probe_enable_disable_t * mp) -{ - vl_api_one_rloc_probe_enable_disable_reply_t *rmp; - int rv = 0; - - vnet_lisp_rloc_probe_enable_disable (mp->is_enable); - REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY); -} - -static void -vl_api_one_enable_disable_t_handler (vl_api_one_enable_disable_t * mp) -{ - vl_api_one_enable_disable_reply_t *rmp; - int rv = 0; - - vnet_lisp_enable_disable (mp->is_enable); - REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY); -} - -static void - vl_api_show_one_map_request_mode_t_handler - (vl_api_show_one_map_request_mode_t * mp) -{ - int rv = 0; - vl_api_show_one_map_request_mode_reply_t *rmp; - - /* *INDENT-OFF* */ - REPLY_MACRO2(VL_API_SHOW_ONE_MAP_REQUEST_MODE_REPLY, - ({ - rmp->mode = vnet_lisp_get_map_request_mode (); - })); - /* *INDENT-ON* */ -} - -static void -vl_api_one_map_request_mode_t_handler (vl_api_one_map_request_mode_t * mp) -{ - vl_api_one_map_request_mode_reply_t *rmp; - int rv = 0; - - rv = vnet_lisp_set_map_request_mode (mp->mode); - - REPLY_MACRO (VL_API_ONE_MAP_REQUEST_MODE_REPLY); -} - -static void -vl_api_one_nsh_set_locator_set_t_handler (vl_api_one_nsh_set_locator_set_t - * mp) -{ - vl_api_one_nsh_set_locator_set_reply_t *rmp; - int rv = 0; - u8 *ls_name = 0; - - mp->ls_name[sizeof (mp->ls_name) - 1] = 0; - ls_name = format (0, "%s", mp->ls_name); - vec_terminate_c_string (ls_name); - rv = vnet_lisp_nsh_set_locator_set (ls_name, mp->is_add); - vec_free (ls_name); - - REPLY_MACRO (VL_API_ONE_PITR_SET_LOCATOR_SET_REPLY); -} - -static void -vl_api_one_pitr_set_locator_set_t_handler (vl_api_one_pitr_set_locator_set_t - * mp) -{ - vl_api_one_pitr_set_locator_set_reply_t *rmp; - int rv = 0; - u8 *ls_name = 0; - - mp->ls_name[sizeof (mp->ls_name) - 1] = 0; - ls_name = format (0, "%s", mp->ls_name); - vec_terminate_c_string (ls_name); - rv = vnet_lisp_pitr_set_locator_set (ls_name, mp->is_add); - vec_free (ls_name); - - REPLY_MACRO (VL_API_ONE_PITR_SET_LOCATOR_SET_REPLY); -} - -static void -vl_api_one_use_petr_t_handler (vl_api_one_use_petr_t * mp) -{ - vl_api_one_use_petr_reply_t *rmp; - int rv = 0; - ip_address_t addr; - - ip_address_decode2 (&mp->ip_address, &addr); - - rv = vnet_lisp_use_petr (&addr, mp->is_add); - - REPLY_MACRO (VL_API_ONE_USE_PETR_REPLY); -} - -static void -vl_api_show_one_use_petr_t_handler (vl_api_show_one_use_petr_t * mp) -{ - vl_api_show_one_use_petr_reply_t *rmp = NULL; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - mapping_t *m; - locator_set_t *ls = 0; - int rv = 0; - locator_t *loc = 0; - u8 status = 0; - gid_address_t addr; - - clib_memset (&addr, 0, sizeof (addr)); - status = lcm->flags & LISP_FLAG_USE_PETR; - if (status) - { - m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index); - if (~0 != m->locator_set_index) - { - ls = - pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index); - loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]); - gid_address_copy (&addr, &loc->address); - } - } - - /* *INDENT-OFF* */ - REPLY_MACRO2 (VL_API_SHOW_ONE_USE_PETR_REPLY, - { - rmp->status = status; - ip_address_t *ip = &gid_address_ip (&addr); - - ip_address_encode2 (ip, &rmp->ip_address); - }); - /* *INDENT-ON* */ -} - -static void - vl_api_one_add_del_map_request_itr_rlocs_t_handler - (vl_api_one_add_del_map_request_itr_rlocs_t * mp) -{ - vl_api_one_add_del_map_request_itr_rlocs_reply_t *rmp; - int rv = 0; - u8 *locator_set_name = NULL; - vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a; - - mp->locator_set_name[sizeof (mp->locator_set_name) - 1] = 0; - locator_set_name = format (0, "%s", mp->locator_set_name); - vec_terminate_c_string (locator_set_name); - - a->is_add = mp->is_add; - a->locator_set_name = locator_set_name; - - rv = vnet_lisp_add_del_mreq_itr_rlocs (a); - - vec_free (locator_set_name); - - REPLY_MACRO (VL_API_ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY); -} - -static void - vl_api_one_add_del_remote_mapping_t_handler - (vl_api_one_add_del_remote_mapping_t * mp) -{ - locator_t *rlocs = 0; - vl_api_one_add_del_remote_mapping_reply_t *rmp; - int rv = 0; - gid_address_t _eid, *eid = &_eid; - u32 rloc_num = clib_net_to_host_u32 (mp->rloc_num); - - clib_memset (eid, 0, sizeof (eid[0])); - - rv = unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni), &mp->deid); - if (rv) - goto send_reply; - - rlocs = unformat_one_locs (mp->rlocs, rloc_num); - - if (!mp->is_add) - { - vnet_lisp_add_del_adjacency_args_t _a, *a = &_a; - clib_memset (a, 0, sizeof (a[0])); - gid_address_copy (&a->reid, eid); - a->is_add = 0; - rv = vnet_lisp_add_del_adjacency (a); - if (rv) - { - goto out; - } - } - - /* NOTE: for now this works as a static remote mapping, i.e., - * not authoritative and ttl infinite. */ - if (mp->is_add) - { - vnet_lisp_add_del_mapping_args_t _m_args, *m_args = &_m_args; - clib_memset (m_args, 0, sizeof (m_args[0])); - gid_address_copy (&m_args->eid, eid); - m_args->action = mp->action; - m_args->is_static = 1; - m_args->ttl = ~0; - m_args->authoritative = 0; - rv = vnet_lisp_add_mapping (m_args, rlocs, NULL, NULL); - } - else - rv = vnet_lisp_del_mapping (eid, NULL); - - if (mp->del_all) - vnet_lisp_clear_all_remote_adjacencies (); - -out: - vec_free (rlocs); -send_reply: - REPLY_MACRO (VL_API_ONE_ADD_DEL_REMOTE_MAPPING_REPLY); -} - -static void -vl_api_one_add_del_adjacency_t_handler (vl_api_one_add_del_adjacency_t * mp) -{ - vl_api_one_add_del_adjacency_reply_t *rmp; - vnet_lisp_add_del_adjacency_args_t _a, *a = &_a; - - int rv = 0; - clib_memset (a, 0, sizeof (a[0])); - - rv = - unformat_one_eid_api (&a->leid, clib_net_to_host_u32 (mp->vni), - &mp->leid); - rv |= - unformat_one_eid_api (&a->reid, clib_net_to_host_u32 (mp->vni), - &mp->reid); - - if (rv) - goto send_reply; - - a->is_add = mp->is_add; - rv = vnet_lisp_add_del_adjacency (a); - -send_reply: - REPLY_MACRO (VL_API_ONE_ADD_DEL_ADJACENCY_REPLY); -} - -static void -send_one_locator_details (lisp_cp_main_t * lcm, - locator_t * loc, vl_api_registration_t * reg, - u32 context) -{ - vl_api_one_locator_details_t *rmp; - - rmp = vl_msg_api_alloc (sizeof (*rmp)); - clib_memset (rmp, 0, sizeof (*rmp)); - rmp->_vl_msg_id = ntohs (VL_API_ONE_LOCATOR_DETAILS); - rmp->context = context; - - rmp->local = loc->local; - if (loc->local) - { - rmp->sw_if_index = ntohl (loc->sw_if_index); - } - else - { - ip_address_encode2 (&loc->address.ippref.addr, &rmp->ip_address); - } - rmp->priority = loc->priority; - rmp->weight = loc->weight; - - vl_api_send_msg (reg, (u8 *) rmp); -} - -static void -vl_api_one_locator_dump_t_handler (vl_api_one_locator_dump_t * mp) -{ - u8 *ls_name = 0; - vl_api_registration_t *reg; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - locator_set_t *lsit = 0; - locator_t *loc = 0; - u32 ls_index = ~0, *locit = 0; - uword *p = 0; - - reg = vl_api_client_index_to_registration (mp->client_index); - if (!reg) - return; - - if (mp->is_index_set) - ls_index = htonl (mp->ls_index); - else - { - /* make sure we get a proper C-string */ - mp->ls_name[sizeof (mp->ls_name) - 1] = 0; - ls_name = format (0, "%s", mp->ls_name); - vec_terminate_c_string (ls_name); - p = hash_get_mem (lcm->locator_set_index_by_name, ls_name); - if (!p) - goto out; - ls_index = p[0]; - } - - if (pool_is_free_index (lcm->locator_set_pool, ls_index)) - return; - - lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index); - - vec_foreach (locit, lsit->locator_indices) - { - loc = pool_elt_at_index (lcm->locator_pool, locit[0]); - send_one_locator_details (lcm, loc, reg, mp->context); - }; -out: - vec_free (ls_name); -} - -static void -send_one_locator_set_details (lisp_cp_main_t * lcm, - locator_set_t * lsit, - vl_api_registration_t * reg, u32 context, - u32 ls_index) -{ - vl_api_one_locator_set_details_t *rmp; - u8 *str = 0; - - rmp = vl_msg_api_alloc (sizeof (*rmp)); - clib_memset (rmp, 0, sizeof (*rmp)); - rmp->_vl_msg_id = ntohs (VL_API_ONE_LOCATOR_SET_DETAILS); - rmp->context = context; - - rmp->ls_index = htonl (ls_index); - if (lsit->local) - { - ASSERT (lsit->name != NULL); - strncpy ((char *) rmp->ls_name, (char *) lsit->name, - vec_len (lsit->name)); - } - else - { - str = format (0, "", ls_index); - strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str)); - vec_free (str); - } - - vl_api_send_msg (reg, (u8 *) rmp); -} - -static void -vl_api_one_locator_set_dump_t_handler (vl_api_one_locator_set_dump_t * mp) -{ - vl_api_registration_t *reg; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - locator_set_t *lsit = NULL; - u8 filter; - - reg = vl_api_client_index_to_registration (mp->client_index); - if (!reg) - return; - - filter = mp->filter; - /* *INDENT-OFF* */ - pool_foreach (lsit, lcm->locator_set_pool, - ({ - if (filter && !((1 == filter && lsit->local) || - (2 == filter && !lsit->local))) - { - continue; - } - send_one_locator_set_details (lcm, lsit, reg, mp->context, - lsit - lcm->locator_set_pool); - })); - /* *INDENT-ON* */ -} - -static void -send_one_eid_table_details (mapping_t * mapit, - vl_api_registration_t * reg, u32 context, - u8 filter) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - locator_set_t *ls = 0; - vl_api_one_eid_table_details_t *rmp = NULL; - gid_address_t *gid = NULL; - u32 eid_type; - fib_prefix_t fib_prefix; - - if (mapit->pitr_set || mapit->nsh_set) - return; - - switch (filter) - { - case ONE_FILTER_API_ALL: /* all mappings */ - break; - - case ONE_FILTER_API_LOCAL: /* local only */ - if (!mapit->local) - return; - break; - case ONE_FILTER_API_REMOTE: /* remote only */ - if (mapit->local) - return; - break; - default: - clib_warning ("Filter error, unknown filter: %d", filter); - return; - } - - gid = &mapit->eid; - - rmp = vl_msg_api_alloc (sizeof (*rmp)); - clib_memset (rmp, 0, sizeof (*rmp)); - rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_DETAILS); - - ls = pool_elt_at_index (lcm->locator_set_pool, mapit->locator_set_index); - if (vec_len (ls->locator_indices) == 0) - rmp->locator_set_index = ~0; - else - rmp->locator_set_index = clib_host_to_net_u32 (mapit->locator_set_index); - - rmp->is_local = mapit->local; - rmp->ttl = clib_host_to_net_u32 (mapit->ttl); - rmp->action = mapit->action; - rmp->authoritative = mapit->authoritative; - - switch (gid_address_type (gid)) - { - case GID_ADDR_SRC_DST: - fid_to_api_eid (&gid_address_sd_src (gid), &rmp->seid); - fid_to_api_eid (&gid_address_sd_dst (gid), &rmp->deid); - break; - case GID_ADDR_IP_PREFIX: - eid_type = EID_TYPE_API_PREFIX; - rmp->seid.type = eid_type; - ip_prefix_to_fib_prefix (&gid_address_ippref (gid), &fib_prefix); - ip_prefix_encode (&fib_prefix, &rmp->seid.address.prefix); - break; - case GID_ADDR_MAC: - eid_type = EID_TYPE_API_MAC; - rmp->seid.type = eid_type; - mac_address_encode ((mac_address_t *) gid_address_mac (gid), - rmp->seid.address.mac); - break; - case GID_ADDR_NSH: - eid_type = EID_TYPE_API_NSH; - rmp->seid.type = eid_type; - rmp->seid.address.nsh.spi = - clib_host_to_net_u32 (gid_address_nsh_spi (gid)); - rmp->seid.address.nsh.si = gid_address_nsh_si (gid); - break; - default: - /* unknown type */ - return; - } - - rmp->context = context; - rmp->vni = clib_host_to_net_u32 (gid_address_vni (gid)); - rmp->key.id = mapit->key_id; - memcpy (rmp->key.key, mapit->key, vec_len (mapit->key)); - vl_api_send_msg (reg, (u8 *) rmp); -} - -static void -vl_api_one_eid_table_dump_t_handler (vl_api_one_eid_table_dump_t * mp) -{ - u32 mi; - vl_api_registration_t *reg; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - mapping_t *mapit = NULL; - gid_address_t _eid, *eid = &_eid; - - reg = vl_api_client_index_to_registration (mp->client_index); - if (!reg) - return; - - if (mp->eid_set) - { - clib_memset (eid, 0, sizeof (*eid)); - - unformat_one_eid_api (eid, clib_net_to_host_u32 (mp->vni), &mp->eid); - - mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, eid); - if ((u32) ~ 0 == mi) - return; - - mapit = pool_elt_at_index (lcm->mapping_pool, mi); - send_one_eid_table_details (mapit, reg, mp->context, - 0 /* ignore filter */ ); - } - else - { - /* *INDENT-OFF* */ - pool_foreach (mapit, lcm->mapping_pool, - ({ - send_one_eid_table_details(mapit, reg, mp->context, - mp->filter); - })); - /* *INDENT-ON* */ - } -} - -static void -send_one_map_server_details (ip_address_t * ip, vl_api_registration_t * reg, - u32 context) -{ - vl_api_one_map_server_details_t *rmp = NULL; - - rmp = vl_msg_api_alloc (sizeof (*rmp)); - clib_memset (rmp, 0, sizeof (*rmp)); - rmp->_vl_msg_id = ntohs (VL_API_ONE_MAP_SERVER_DETAILS); - - - ip_address_encode2 (ip, &rmp->ip_address); - - rmp->context = context; - - vl_api_send_msg (reg, (u8 *) rmp); -} - -static void -vl_api_one_map_server_dump_t_handler (vl_api_one_map_server_dump_t * mp) -{ - vl_api_registration_t *reg; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - lisp_msmr_t *mr; - - reg = vl_api_client_index_to_registration (mp->client_index); - if (!reg) - return; - - vec_foreach (mr, lcm->map_servers) - { - send_one_map_server_details (&mr->address, reg, mp->context); - } -} - -static void -send_one_map_resolver_details (ip_address_t * ip, - vl_api_registration_t * reg, u32 context) -{ - vl_api_one_map_resolver_details_t *rmp = NULL; - - rmp = vl_msg_api_alloc (sizeof (*rmp)); - clib_memset (rmp, 0, sizeof (*rmp)); - rmp->_vl_msg_id = ntohs (VL_API_ONE_MAP_RESOLVER_DETAILS); - - ip_address_encode2 (ip, &rmp->ip_address); - rmp->context = context; - - vl_api_send_msg (reg, (u8 *) rmp); -} - -static void -vl_api_one_map_resolver_dump_t_handler (vl_api_one_map_resolver_dump_t * mp) -{ - vl_api_registration_t *reg; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - lisp_msmr_t *mr; - - reg = vl_api_client_index_to_registration (mp->client_index); - if (!reg) - return; - - vec_foreach (mr, lcm->map_resolvers) - { - send_one_map_resolver_details (&mr->address, reg, mp->context); - } -} - -static void -send_eid_table_map_pair (hash_pair_t * p, vl_api_registration_t * reg, - u32 context) -{ - vl_api_one_eid_table_map_details_t *rmp = NULL; - - rmp = vl_msg_api_alloc (sizeof (*rmp)); - clib_memset (rmp, 0, sizeof (*rmp)); - rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_MAP_DETAILS); - - rmp->vni = clib_host_to_net_u32 (p->key); - rmp->dp_table = clib_host_to_net_u32 (p->value[0]); - rmp->context = context; - vl_api_send_msg (reg, (u8 *) rmp); -} - -static void -vl_api_one_eid_table_map_dump_t_handler (vl_api_one_eid_table_map_dump_t * mp) -{ - vl_api_registration_t *reg; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - hash_pair_t *p; - uword *vni_table = 0; - - reg = vl_api_client_index_to_registration (mp->client_index); - if (!reg) - return; - - if (mp->is_l2) - { - vni_table = lcm->bd_id_by_vni; - } - else - { - vni_table = lcm->table_id_by_vni; - } - - /* *INDENT-OFF* */ - hash_foreach_pair (p, vni_table, - ({ - send_eid_table_map_pair (p, reg, mp->context); - })); - /* *INDENT-ON* */ -} - -static void -send_eid_table_vni (u32 vni, vl_api_registration_t * reg, u32 context) -{ - vl_api_one_eid_table_vni_details_t *rmp = 0; - - rmp = vl_msg_api_alloc (sizeof (*rmp)); - clib_memset (rmp, 0, sizeof (*rmp)); - rmp->_vl_msg_id = ntohs (VL_API_ONE_EID_TABLE_VNI_DETAILS); - rmp->context = context; - rmp->vni = clib_host_to_net_u32 (vni); - vl_api_send_msg (reg, (u8 *) rmp); -} - -static void -one_adjacency_copy (vl_api_one_adjacency_t * dst, lisp_adjacency_t * adjs) -{ - lisp_adjacency_t *adj; - vl_api_one_adjacency_t a; - u32 i, n = vec_len (adjs); - fib_prefix_t rfib_prefix, lfib_prefix; - u32 eid_type; - - for (i = 0; i < n; i++) - { - adj = vec_elt_at_index (adjs, i); - clib_memset (&a, 0, sizeof (a)); - - switch (gid_address_type (&adj->reid)) - { - case GID_ADDR_IP_PREFIX: - eid_type = EID_TYPE_API_PREFIX; - ip_prefix_to_fib_prefix (&gid_address_ippref (&adj->reid), - &rfib_prefix); - ip_prefix_to_fib_prefix (&gid_address_ippref (&adj->leid), - &lfib_prefix); - ip_prefix_encode (&rfib_prefix, &a.reid.address.prefix); - ip_prefix_encode (&lfib_prefix, &a.leid.address.prefix); - break; - case GID_ADDR_MAC: - eid_type = EID_TYPE_API_PREFIX; - mac_address_encode ((mac_address_t *) gid_address_mac (&adj->reid), - a.reid.address.mac); - mac_address_encode ((mac_address_t *) gid_address_mac (&adj->leid), - a.leid.address.mac); - break; - case GID_ADDR_NSH: - eid_type = EID_TYPE_API_PREFIX; - a.reid.address.nsh.spi = - clib_host_to_net_u32 (gid_address_nsh_spi (&adj->reid)); - a.reid.address.nsh.si = gid_address_nsh_si (&adj->reid); - a.leid.address.nsh.spi = - clib_host_to_net_u32 (gid_address_nsh_spi (&adj->leid)); - a.leid.address.nsh.si = gid_address_nsh_si (&adj->leid); - break; - default: - ALWAYS_ASSERT (0); - } - a.reid.type = eid_type; - a.leid.type = eid_type; - dst[i] = a; - } -} - -static void - vl_api_show_one_rloc_probe_state_t_handler - (vl_api_show_one_rloc_probe_state_t * mp) -{ - vl_api_show_one_rloc_probe_state_reply_t *rmp = 0; - int rv = 0; - - /* *INDENT-OFF* */ - REPLY_MACRO2 (VL_API_SHOW_ONE_RLOC_PROBE_STATE_REPLY, - { - rmp->is_enable = vnet_lisp_rloc_probe_state_get (); - }); - /* *INDENT-ON* */ -} - -static void - vl_api_show_one_map_register_state_t_handler - (vl_api_show_one_map_register_state_t * mp) -{ - vl_api_show_one_map_register_state_reply_t *rmp = 0; - int rv = 0; - - /* *INDENT-OFF* */ - REPLY_MACRO2 (VL_API_SHOW_ONE_MAP_REGISTER_STATE_REPLY, - { - rmp->is_enable = vnet_lisp_map_register_state_get (); - }); - /* *INDENT-ON* */ -} - -static void -vl_api_one_adjacencies_get_t_handler (vl_api_one_adjacencies_get_t * mp) -{ - vl_api_one_adjacencies_get_reply_t *rmp = 0; - lisp_adjacency_t *adjs = 0; - int rv = 0; - u32 size = ~0; - u32 vni = clib_net_to_host_u32 (mp->vni); - - adjs = vnet_lisp_adjacencies_get_by_vni (vni); - size = vec_len (adjs) * sizeof (vl_api_one_adjacency_t); - - /* *INDENT-OFF* */ - REPLY_MACRO4 (VL_API_ONE_ADJACENCIES_GET_REPLY, size, - { - rmp->count = clib_host_to_net_u32 (vec_len (adjs)); - one_adjacency_copy (rmp->adjacencies, adjs); - }); - /* *INDENT-ON* */ - - vec_free (adjs); -} - -static void -vl_api_one_eid_table_vni_dump_t_handler (vl_api_one_eid_table_vni_dump_t * mp) -{ - hash_pair_t *p; - u32 *vnis = 0; - vl_api_registration_t *reg; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - - reg = vl_api_client_index_to_registration (mp->client_index); - if (!reg) - return; - - /* *INDENT-OFF* */ - hash_foreach_pair (p, lcm->table_id_by_vni, - ({ - hash_set (vnis, p->key, 0); - })); - - hash_foreach_pair (p, lcm->bd_id_by_vni, - ({ - hash_set (vnis, p->key, 0); - })); - - hash_foreach_pair (p, vnis, - ({ - send_eid_table_vni (p->key, reg, mp->context); - })); - /* *INDENT-ON* */ - - hash_free (vnis); -} - -static void -vl_api_show_one_status_t_handler (vl_api_show_one_status_t * mp) -{ - vl_api_show_one_status_reply_t *rmp = NULL; - int rv = 0; - - /* *INDENT-OFF* */ - REPLY_MACRO2(VL_API_SHOW_ONE_STATUS_REPLY, - ({ - rmp->gpe_status = vnet_lisp_gpe_enable_disable_status (); - rmp->feature_status = vnet_lisp_enable_disable_status (); - })); - /* *INDENT-ON* */ -} - -static void - vl_api_one_get_map_request_itr_rlocs_t_handler - (vl_api_one_get_map_request_itr_rlocs_t * mp) -{ - vl_api_one_get_map_request_itr_rlocs_reply_t *rmp = NULL; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - locator_set_t *loc_set = 0; - u8 *tmp_str = 0; - int rv = 0; - - if (~0 == lcm->mreq_itr_rlocs) - { - tmp_str = format (0, " "); - } - else - { - loc_set = - pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs); - tmp_str = format (0, "%s", loc_set->name); - } - - /* *INDENT-OFF* */ - REPLY_MACRO2(VL_API_ONE_GET_MAP_REQUEST_ITR_RLOCS_REPLY, - ({ - strncpy((char *) rmp->locator_set_name, (char *) tmp_str, - ARRAY_LEN(rmp->locator_set_name) - 1); - })); - /* *INDENT-ON* */ - - vec_free (tmp_str); -} - -static void -vl_api_show_one_nsh_mapping_t_handler (vl_api_show_one_nsh_mapping_t * mp) -{ - vl_api_show_one_nsh_mapping_reply_t *rmp = NULL; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - mapping_t *m; - locator_set_t *ls = 0; - u8 *tmp_str = 0; - u8 is_set = 0; - int rv = 0; - - if (lcm->nsh_map_index == (u32) ~ 0) - { - tmp_str = format (0, "N/A"); - } - else - { - m = pool_elt_at_index (lcm->mapping_pool, lcm->nsh_map_index); - if (~0 != m->locator_set_index) - { - ls = - pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index); - tmp_str = format (0, "%s", ls->name); - is_set = 1; - } - else - { - tmp_str = format (0, "N/A"); - } - } - vec_add1 (tmp_str, 0); - - /* *INDENT-OFF* */ - REPLY_MACRO2(VL_API_SHOW_ONE_NSH_MAPPING_REPLY, - ({ - rmp->is_set = is_set; - strncpy((char *) rmp->locator_set_name, (char *) tmp_str, - ARRAY_LEN(rmp->locator_set_name) - 1); - })); - /* *INDENT-ON* */ -} - -static void -vl_api_show_one_pitr_t_handler (vl_api_show_one_pitr_t * mp) -{ - vl_api_show_one_pitr_reply_t *rmp = NULL; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - mapping_t *m; - locator_set_t *ls = 0; - u8 *tmp_str = 0; - int rv = 0; - - u8 is_enable = (lcm->flags & LISP_FLAG_PITR_MODE) - && lcm->pitr_map_index != ~0; - - if (!is_enable) - { - tmp_str = format (0, "N/A"); - } - else - { - m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index); - if (~0 != m->locator_set_index) - { - ls = - pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index); - tmp_str = format (0, "%s", ls->name); - } - else - { - tmp_str = format (0, "N/A"); - } - } - vec_add1 (tmp_str, 0); - - /* *INDENT-OFF* */ - REPLY_MACRO2(VL_API_SHOW_ONE_PITR_REPLY, - ({ - rmp->status = lcm->flags & LISP_FLAG_PITR_MODE; - strncpy((char *) rmp->locator_set_name, (char *) tmp_str, - ARRAY_LEN(rmp->locator_set_name) - 1); - })); - /* *INDENT-ON* */ -} - -static void - vl_api_show_one_stats_enable_disable_t_handler - (vl_api_show_one_stats_enable_disable_t * mp) -{ - vl_api_show_one_stats_enable_disable_reply_t *rmp = NULL; - vnet_api_error_t rv = 0; - - /* *INDENT-OFF* */ - REPLY_MACRO2 (VL_API_SHOW_ONE_STATS_ENABLE_DISABLE_REPLY, - ({ - rmp->is_enable = vnet_lisp_stats_enable_disable_state (); - })); - /* *INDENT-ON* */ -} - -static void - vl_api_one_stats_enable_disable_t_handler - (vl_api_one_stats_enable_disable_t * mp) -{ - vl_api_one_enable_disable_reply_t *rmp = NULL; - - vnet_api_error_t rv = vnet_lisp_stats_enable_disable (mp->is_enable); - REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY); -} - -static void -vl_api_one_stats_flush_t_handler (vl_api_one_stats_flush_t * mp) -{ - vl_api_one_stats_flush_reply_t *rmp; - u8 rv; - - rv = vnet_lisp_flush_stats (); - REPLY_MACRO (VL_API_ONE_STATS_FLUSH_REPLY); -} - -static void -vl_api_one_stats_dump_t_handler (vl_api_one_stats_dump_t * mp) -{ - vl_api_one_stats_details_t *rmp; - lisp_api_stats_t *stats, *stat; - u8 rv = 0; - - stats = vnet_lisp_get_stats (); - vec_foreach (stat, stats) - { - /* *INDENT-OFF* */ - REPLY_DETAILS (VL_API_ONE_STATS_DETAILS, - ({ - fid_to_api_eid (&stat->deid, &rmp->deid); - fid_to_api_eid (&stat->seid, &rmp->seid); - rmp->vni = clib_host_to_net_u32 (stat->vni); - - ip_address_encode2 (&stat->rmt_rloc, &rmp->rloc); - ip_address_encode2 (&stat->loc_rloc, &rmp->lloc); - - rmp->pkt_count = clib_host_to_net_u32 (stat->counters.packets); - rmp->bytes = clib_host_to_net_u32 (stat->counters.bytes); - })); - /* *INDENT-ON* */ - } -} - -static void - vl_api_one_add_del_l2_arp_entry_t_handler - (vl_api_one_add_del_l2_arp_entry_t * mp) -{ - vl_api_one_add_del_l2_arp_entry_reply_t *rmp; - int rv = 0; - gid_address_t _arp, *arp = &_arp; - ip4_address_t ip4; - mac_address_t mac; - clib_memset (arp, 0, sizeof (*arp)); - - gid_address_type (arp) = GID_ADDR_ARP; - gid_address_arp_bd (arp) = clib_net_to_host_u32 (mp->bd); - - ip4_address_decode (mp->entry.ip4, &ip4); - ip_address_set (&gid_address_arp_ndp_ip (arp), &ip4, AF_IP4); - mac_address_decode (mp->entry.mac, &mac); - - rv = vnet_lisp_add_del_l2_arp_ndp_entry (arp, mac.bytes, mp->is_add); - - REPLY_MACRO (VL_API_ONE_ADD_DEL_L2_ARP_ENTRY_REPLY); -} - -static void -vl_api_one_add_del_ndp_entry_t_handler (vl_api_one_add_del_ndp_entry_t * mp) -{ - vl_api_one_add_del_ndp_entry_reply_t *rmp; - int rv = 0; - gid_address_t _g, *g = &_g; - ip6_address_t ip6; - mac_address_t mac; - clib_memset (g, 0, sizeof (*g)); - - gid_address_type (g) = GID_ADDR_NDP; - gid_address_ndp_bd (g) = clib_net_to_host_u32 (mp->bd); - - ip6_address_decode (mp->entry.ip6, &ip6); - ip_address_set (&gid_address_arp_ndp_ip (g), &ip6, AF_IP6); - mac_address_decode (mp->entry.mac, &mac); - - rv = vnet_lisp_add_del_l2_arp_ndp_entry (g, mac.bytes, mp->is_add); - - REPLY_MACRO (VL_API_ONE_ADD_DEL_NDP_ENTRY_REPLY); -} - -static void -vl_api_one_ndp_bd_get_t_handler (vl_api_one_ndp_bd_get_t * mp) -{ - vl_api_one_ndp_bd_get_reply_t *rmp; - int rv = 0; - u32 i = 0; - hash_pair_t *p; - - u32 *bds = vnet_lisp_ndp_bds_get (); - u32 size = hash_elts (bds) * sizeof (u32); - - /* *INDENT-OFF* */ - REPLY_MACRO4 (VL_API_ONE_NDP_BD_GET_REPLY, size, - { - rmp->count = clib_host_to_net_u32 (hash_elts (bds)); - hash_foreach_pair (p, bds, - ({ - rmp->bridge_domains[i++] = clib_host_to_net_u32 (p->key); - })); - }); - /* *INDENT-ON* */ - - hash_free (bds); -} - -static void -vl_api_one_l2_arp_bd_get_t_handler (vl_api_one_l2_arp_bd_get_t * mp) -{ - vl_api_one_l2_arp_bd_get_reply_t *rmp; - int rv = 0; - u32 i = 0; - hash_pair_t *p; - - u32 *bds = vnet_lisp_l2_arp_bds_get (); - u32 size = hash_elts (bds) * sizeof (u32); - - /* *INDENT-OFF* */ - REPLY_MACRO4 (VL_API_ONE_L2_ARP_BD_GET_REPLY, size, - { - rmp->count = clib_host_to_net_u32 (hash_elts (bds)); - hash_foreach_pair (p, bds, - ({ - rmp->bridge_domains[i++] = clib_host_to_net_u32 (p->key); - })); - }); - /* *INDENT-ON* */ - - hash_free (bds); -} - -static void -vl_api_one_l2_arp_entries_get_t_handler (vl_api_one_l2_arp_entries_get_t * mp) -{ - vl_api_one_l2_arp_entries_get_reply_t *rmp; - lisp_api_l2_arp_entry_t *entries = 0, *e; - u32 i = 0; - int rv = 0; - - u32 bd = clib_net_to_host_u32 (mp->bd); - - entries = vnet_lisp_l2_arp_entries_get_by_bd (bd); - u32 size = vec_len (entries) * sizeof (vl_api_one_l2_arp_entry_t); - - /* *INDENT-OFF* */ - REPLY_MACRO4 (VL_API_ONE_L2_ARP_ENTRIES_GET_REPLY, size, - { - rmp->count = clib_host_to_net_u32 (vec_len (entries)); - vec_foreach (e, entries) - { - mac_address_encode ((mac_address_t *) e->mac, rmp->entries[i].mac); - ip4_address_encode ((ip4_address_t *) &e->ip4, rmp->entries[i].ip4); - i++; - } - }); - /* *INDENT-ON* */ - - vec_free (entries); -} - -static void - vl_api_one_map_register_fallback_threshold_t_handler - (vl_api_one_map_register_fallback_threshold_t * mp) -{ - vl_api_one_map_register_fallback_threshold_reply_t *rmp; - int rv = 0; - - mp->value = clib_net_to_host_u32 (mp->value); - rv = vnet_lisp_map_register_fallback_threshold_set (mp->value); - REPLY_MACRO (VL_API_ONE_MAP_REGISTER_FALLBACK_THRESHOLD_REPLY); -} - -static void - vl_api_show_one_map_register_fallback_threshold_t_handler - (vl_api_show_one_map_register_fallback_threshold_t * mp) -{ - vl_api_show_one_map_register_fallback_threshold_reply_t *rmp; - int rv = 0; - - u32 value = vnet_lisp_map_register_fallback_threshold_get (); - - /* *INDENT-OFF* */ - REPLY_MACRO2 (VL_API_SHOW_ONE_MAP_REGISTER_FALLBACK_THRESHOLD_REPLY, - ({ - rmp->value = clib_host_to_net_u32 (value); - })); - /* *INDENT-ON* */ -} - -static void - vl_api_one_set_transport_protocol_t_handler - (vl_api_one_set_transport_protocol_t * mp) -{ - vl_api_one_set_transport_protocol_reply_t *rmp; - int rv = 0; - - rv = vnet_lisp_set_transport_protocol (mp->protocol); - - REPLY_MACRO (VL_API_ONE_SET_TRANSPORT_PROTOCOL_REPLY); -} - -static void - vl_api_one_get_transport_protocol_t_handler - (vl_api_one_get_transport_protocol_t * mp) -{ - vl_api_one_get_transport_protocol_reply_t *rmp; - int rv = 0; - u8 proto = (u8) vnet_lisp_get_transport_protocol (); - - /* *INDENT-OFF* */ - REPLY_MACRO2 (VL_API_ONE_GET_TRANSPORT_PROTOCOL_REPLY, - ({ - rmp->protocol = proto; - })); - /* *INDENT-ON* */ -} - -static void -vl_api_one_ndp_entries_get_t_handler (vl_api_one_ndp_entries_get_t * mp) -{ - vl_api_one_ndp_entries_get_reply_t *rmp = 0; - lisp_api_ndp_entry_t *entries = 0, *e; - u32 i = 0; - int rv = 0; - - u32 bd = clib_net_to_host_u32 (mp->bd); - - entries = vnet_lisp_ndp_entries_get_by_bd (bd); - u32 size = vec_len (entries) * sizeof (vl_api_one_ndp_entry_t); - - /* *INDENT-OFF* */ - REPLY_MACRO4 (VL_API_ONE_NDP_ENTRIES_GET_REPLY, size, - { - rmp->count = clib_host_to_net_u32 (vec_len (entries)); - vec_foreach (e, entries) - { - mac_address_encode ((mac_address_t *) e->mac, rmp->entries[i].mac); - ip6_address_encode ((ip6_address_t *) &e->ip6, rmp->entries[i].ip6); - i++; - } - }); - /* *INDENT-ON* */ - - vec_free (entries); -} - -static void - vl_api_one_enable_disable_xtr_mode_t_handler - (vl_api_one_enable_disable_xtr_mode_t * mp) -{ - vl_api_one_enable_disable_xtr_mode_reply_t *rmp = 0; - int rv = vnet_lisp_enable_disable_xtr_mode (mp->is_enable); - - REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_XTR_MODE_REPLY); -} - -static void -vl_api_one_show_xtr_mode_t_handler (vl_api_one_show_xtr_mode_t * mp) -{ - vl_api_one_show_xtr_mode_reply_t *rmp = 0; - int rv = 0; - - /* *INDENT-OFF* */ - REPLY_MACRO2 (VL_API_ONE_SHOW_XTR_MODE_REPLY, - { - rmp->is_enable = vnet_lisp_get_xtr_mode (); - }); - /* *INDENT-ON* */ -} - -static void - vl_api_one_enable_disable_pitr_mode_t_handler - (vl_api_one_enable_disable_pitr_mode_t * mp) -{ - vl_api_one_enable_disable_pitr_mode_reply_t *rmp = 0; - int rv = vnet_lisp_enable_disable_pitr_mode (mp->is_enable); - - REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_PITR_MODE_REPLY); -} - -static void -vl_api_one_show_pitr_mode_t_handler (vl_api_one_show_pitr_mode_t * mp) -{ - vl_api_one_show_pitr_mode_reply_t *rmp = 0; - int rv = 0; - - /* *INDENT-OFF* */ - REPLY_MACRO2 (VL_API_ONE_SHOW_PITR_MODE_REPLY, - { - rmp->is_enable = vnet_lisp_get_pitr_mode (); - }); - /* *INDENT-ON* */ -} - -static void - vl_api_one_enable_disable_petr_mode_t_handler - (vl_api_one_enable_disable_petr_mode_t * mp) -{ - vl_api_one_enable_disable_petr_mode_reply_t *rmp = 0; - int rv = vnet_lisp_enable_disable_petr_mode (mp->is_enable); - - REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_PETR_MODE_REPLY); -} - -static void -vl_api_one_show_petr_mode_t_handler (vl_api_one_show_petr_mode_t * mp) -{ - vl_api_one_show_petr_mode_reply_t *rmp = 0; - int rv = 0; - - /* *INDENT-OFF* */ - REPLY_MACRO2 (VL_API_ONE_SHOW_PETR_MODE_REPLY, - { - rmp->is_enable = vnet_lisp_get_petr_mode (); - }); - /* *INDENT-ON* */ -} - -/* - * one_api_hookup - * Add vpe's API message handlers to the table. - * vlib has already mapped shared memory and - * added the client registration handlers. - * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process() - */ -#define vl_msg_name_crc_list -#include -#undef vl_msg_name_crc_list - -static void -setup_message_id_table (api_main_t * am) -{ -#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id); - foreach_vl_msg_name_crc_one; -#undef _ -} - -static clib_error_t * -one_api_hookup (vlib_main_t * vm) -{ - api_main_t *am = vlibapi_get_main (); - -#define _(N,n) \ - vl_msg_api_set_handlers(VL_API_##N, #n, \ - vl_api_##n##_t_handler, \ - vl_noop_handler, \ - vl_api_##n##_t_endian, \ - vl_api_##n##_t_print, \ - sizeof(vl_api_##n##_t), 1); - foreach_vpe_api_msg; -#undef _ - - /* - * Set up the (msg_name, crc, message-id) table - */ - setup_message_id_table (am); - - return 0; -} - -VLIB_API_INIT_FUNCTION (one_api_hookup); - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/src/vnet/lisp-cp/one_cli.c b/src/vnet/lisp-cp/one_cli.c deleted file mode 100644 index 70de0c1a554..00000000000 --- a/src/vnet/lisp-cp/one_cli.c +++ /dev/null @@ -1,2340 +0,0 @@ -/* - * Copyright (c) 2017 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -static clib_error_t * -lisp_show_adjacencies_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - lisp_adjacency_t *adjs, *adj; - vlib_cli_output (vm, "%s %40s\n", "leid", "reid"); - unformat_input_t _line_input, *line_input = &_line_input; - u32 vni = ~0; - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return 0; - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "vni %d", &vni)) - ; - else - { - vlib_cli_output (vm, "parse error: '%U'", - format_unformat_error, line_input); - unformat_free (line_input); - return 0; - } - } - unformat_free (line_input); - - if (~0 == vni) - { - vlib_cli_output (vm, "error: no vni specified!"); - return 0; - } - - adjs = vnet_lisp_adjacencies_get_by_vni (vni); - - vec_foreach (adj, adjs) - { - vlib_cli_output (vm, "%U %40U\n", format_gid_address, &adj->leid, - format_gid_address, &adj->reid); - } - vec_free (adjs); - - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_show_adjacencies_command) = { - .path = "show one adjacencies", - .short_help = "show one adjacencies", - .function = lisp_show_adjacencies_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_add_del_map_server_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - int rv = 0; - u8 is_add = 1, ip_set = 0; - ip_address_t ip; - unformat_input_t _line_input, *line_input = &_line_input; - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return 0; - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "add")) - is_add = 1; - else if (unformat (line_input, "del")) - is_add = 0; - else if (unformat (line_input, "%U", unformat_ip_address, &ip)) - ip_set = 1; - else - { - vlib_cli_output (vm, "parse error: '%U'", - format_unformat_error, line_input); - unformat_free (line_input); - return 0; - } - } - unformat_free (line_input); - - if (!ip_set) - { - vlib_cli_output (vm, "map-server ip address not set!"); - return 0; - } - - rv = vnet_lisp_add_del_map_server (&ip, is_add); - if (!rv) - vlib_cli_output (vm, "failed to %s map-server!", - is_add ? "add" : "delete"); - - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_add_del_map_server_command) = { - .path = "one map-server", - .short_help = "one map-server add|del ", - .function = lisp_add_del_map_server_command_fn, -}; -/* *INDENT-ON* */ - - -static clib_error_t * -lisp_add_del_local_eid_command_fn (vlib_main_t * vm, unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - unformat_input_t _line_input, *line_input = &_line_input; - u8 is_add = 1; - gid_address_t eid; - gid_address_t *eids = 0; - clib_error_t *error = 0; - u8 *locator_set_name = 0; - u32 locator_set_index = 0, map_index = 0; - uword *p; - vnet_lisp_add_del_mapping_args_t _a, *a = &_a; - int rv = 0; - u32 vni = 0; - u8 *key = 0; - u32 key_id = 0; - - clib_memset (&eid, 0, sizeof (eid)); - clib_memset (a, 0, sizeof (*a)); - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return 0; - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "add")) - is_add = 1; - else if (unformat (line_input, "del")) - is_add = 0; - else if (unformat (line_input, "eid %U", unformat_gid_address, &eid)) - ; - else if (unformat (line_input, "vni %d", &vni)) - gid_address_vni (&eid) = vni; - else if (unformat (line_input, "secret-key %_%v%_", &key)) - ; - else if (unformat (line_input, "key-id %U", unformat_hmac_key_id, - &key_id)) - ; - else if (unformat (line_input, "locator-set %_%v%_", &locator_set_name)) - { - vec_terminate_c_string (locator_set_name); - p = hash_get_mem (lcm->locator_set_index_by_name, locator_set_name); - if (!p) - { - error = clib_error_return (0, "locator-set %s doesn't exist", - locator_set_name); - goto done; - } - locator_set_index = p[0]; - } - else if (unformat (line_input, "authoritative")) - a->authoritative = 1; - else - { - error = unformat_parse_error (line_input); - goto done; - } - } - /* XXX treat batch configuration */ - - if (GID_ADDR_SRC_DST == gid_address_type (&eid)) - { - error = - clib_error_return (0, "src/dst is not supported for local EIDs!"); - goto done; - } - - if (key && (0 == key_id)) - { - vlib_cli_output (vm, "invalid key_id!"); - goto done; - } - - gid_address_copy (&a->eid, &eid); - a->is_add = is_add; - a->locator_set_index = locator_set_index; - a->local = 1; - a->key = key; - a->key_id = key_id; - - rv = vnet_lisp_add_del_local_mapping (a, &map_index); - if (0 != rv) - { - error = clib_error_return (0, "failed to %s local mapping!", - is_add ? "add" : "delete"); - } -done: - vec_free (eids); - if (locator_set_name) - vec_free (locator_set_name); - gid_address_free (&a->eid); - vec_free (a->key); - unformat_free (line_input); - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_add_del_local_eid_command) = { - .path = "one eid-table", - .short_help = "one eid-table add/del [vni ] eid " - "locator-set [key key-id sha1|sha256 ]", - .function = lisp_add_del_local_eid_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_eid_table_map_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - u8 is_add = 1, is_l2 = 0; - u32 vni = 0, dp_id = 0; - unformat_input_t _line_input, *line_input = &_line_input; - clib_error_t *error = NULL; - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return 0; - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "del")) - is_add = 0; - else if (unformat (line_input, "vni %d", &vni)) - ; - else if (unformat (line_input, "vrf %d", &dp_id)) - ; - else if (unformat (line_input, "bd %d", &dp_id)) - is_l2 = 1; - else - { - error = unformat_parse_error (line_input); - goto done; - } - } - vnet_lisp_eid_table_map (vni, dp_id, is_l2, is_add); - -done: - unformat_free (line_input); - - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_eid_table_map_command) = { - .path = "one eid-table map", - .short_help = "one eid-table map [del] vni vrf | bd ", - .function = lisp_eid_table_map_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_add_del_ndp_entry_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - unformat_input_t _line_input, *line_input = &_line_input; - clib_error_t *error = NULL; - int rc = 0; - u8 hw_addr[6], bd = 0; - ip6_address_t ip6; - u32 hw_addr_set = 0, ip_set = 0, is_add = 1; - gid_address_t _g, *g = &_g; - - clib_memset (&ip6, 0, sizeof (ip6)); - clib_memset (hw_addr, 0, sizeof (hw_addr)); - clib_memset (g, 0, sizeof (*g)); - - if (!unformat_user (input, unformat_line_input, line_input)) - return 0; - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "mac %U", unformat_mac_address, hw_addr)) - hw_addr_set = 1; - else if (unformat (line_input, "ip %U", unformat_ip6_address, &ip6)) - ip_set = 1; - else if (unformat (line_input, "del")) - is_add = 0; - else if (unformat (line_input, "bd %d", &bd)) - ; - else - { - error = clib_error_return (0, "parse error"); - goto done; - } - } - - if (!ip_set || (!hw_addr_set && is_add)) - { - vlib_cli_output (vm, "expected IP and MAC addresses!"); - return 0; - } - - /* build GID address */ - ip_address_set (&gid_address_arp_ndp_ip (g), &ip6, AF_IP6); - gid_address_ndp_bd (g) = bd; - gid_address_type (g) = GID_ADDR_NDP; - rc = vnet_lisp_add_del_l2_arp_ndp_entry (g, hw_addr, is_add); - if (rc) - clib_warning ("Failed to %s ndp entry!", is_add ? "add" : "delete"); - -done: - unformat_free (line_input); - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_add_del_ndp_entry_command) = { - .path = "one ndp", - .short_help = "one ndp [del] bd mac ip ", - .function = lisp_add_del_ndp_entry_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_add_del_l2_arp_entry_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - unformat_input_t _line_input, *line_input = &_line_input; - clib_error_t *error = NULL; - int rc = 0; - u8 hw_addr[6], bd = 0; - ip4_address_t ip4; - u32 hw_addr_set = 0, ip_set = 0, is_add = 1; - gid_address_t _arp, *arp = &_arp; - - clib_memset (&ip4, 0, sizeof (ip4)); - clib_memset (hw_addr, 0, sizeof (hw_addr)); - clib_memset (arp, 0, sizeof (*arp)); - - if (!unformat_user (input, unformat_line_input, line_input)) - return 0; - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "mac %U", unformat_mac_address, hw_addr)) - hw_addr_set = 1; - else if (unformat (line_input, "ip %U", unformat_ip4_address, &ip4)) - ip_set = 1; - else if (unformat (line_input, "del")) - is_add = 0; - else if (unformat (line_input, "bd %d", &bd)) - ; - else - { - error = clib_error_return (0, "parse error"); - goto done; - } - } - - if (!ip_set || (!hw_addr_set && is_add)) - { - vlib_cli_output (vm, "expected IP and MAC addresses!"); - return 0; - } - - /* build GID address */ - gid_address_arp_ip4 (arp) = ip4; - gid_address_arp_bd (arp) = bd; - gid_address_type (arp) = GID_ADDR_ARP; - rc = vnet_lisp_add_del_l2_arp_ndp_entry (arp, hw_addr, is_add); - if (rc) - clib_warning ("Failed to %s l2 arp entry!", is_add ? "add" : "delete"); - -done: - unformat_free (line_input); - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_add_del_l2_arp_entry_command) = { - .path = "one l2 arp", - .short_help = "one l2 arp [del] bd mac ip ", - .function = lisp_add_del_l2_arp_entry_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_show_l2_arp_entries_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - u32 *ht = vnet_lisp_l2_arp_bds_get (); - lisp_api_l2_arp_entry_t *entries, *e; - hash_pair_t *p; - - /* *INDENT-OFF* */ - hash_foreach_pair (p, ht, - ({ - entries = vnet_lisp_l2_arp_entries_get_by_bd (p->key); - vlib_cli_output (vm, "Table: %d", p->key); - - vec_foreach (e, entries) - { - vlib_cli_output (vm, "\t%U -> %U", format_ip4_address, &e->ip4, - format_mac_address, e->mac); - } - vec_free (entries); - })); - /* *INDENT-ON* */ - - hash_free (ht); - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_show_l2_arp_entries_command) = { - .path = "show one l2 arp entries", - .short_help = "Show ONE L2 ARP entries", - .function = lisp_show_l2_arp_entries_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_show_ndp_entries_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - u32 *ht = vnet_lisp_ndp_bds_get (); - lisp_api_ndp_entry_t *entries, *e; - hash_pair_t *p; - - /* *INDENT-OFF* */ - hash_foreach_pair (p, ht, - ({ - entries = vnet_lisp_ndp_entries_get_by_bd (p->key); - vlib_cli_output (vm, "Table: %d", p->key); - - vec_foreach (e, entries) - { - vlib_cli_output (vm, "\t%U -> %U", format_ip6_address, &e->ip6, - format_mac_address, e->mac); - } - vec_free (entries); - })); - /* *INDENT-ON* */ - - hash_free (ht); - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_show_ndp_entries_command) = { - .path = "show one ndp entries", - .short_help = "Show ONE NDP entries", - .function = lisp_show_ndp_entries_command_fn, -}; -/* *INDENT-ON* */ - -/** - * Handler for add/del remote mapping CLI. - * - * @param vm vlib context - * @param input input from user - * @param cmd cmd - * @return pointer to clib error structure - */ -static clib_error_t * -lisp_add_del_remote_mapping_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - clib_error_t *error = 0; - unformat_input_t _line_input, *line_input = &_line_input; - u8 is_add = 1, del_all = 0; - locator_t rloc, *rlocs = 0, *curr_rloc = 0; - gid_address_t eid; - u8 eid_set = 0; - u32 vni, action = ~0, p, w; - int rv; - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return 0; - - clib_memset (&eid, 0, sizeof (eid)); - clib_memset (&rloc, 0, sizeof (rloc)); - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "del-all")) - del_all = 1; - else if (unformat (line_input, "del")) - is_add = 0; - else if (unformat (line_input, "add")) - ; - else if (unformat (line_input, "eid %U", unformat_gid_address, &eid)) - eid_set = 1; - else if (unformat (line_input, "vni %u", &vni)) - { - gid_address_vni (&eid) = vni; - } - else if (unformat (line_input, "p %d w %d", &p, &w)) - { - if (!curr_rloc) - { - clib_warning - ("No RLOC configured for setting priority/weight!"); - goto done; - } - curr_rloc->priority = p; - curr_rloc->weight = w; - } - else if (unformat (line_input, "rloc %U", unformat_ip_address, - &gid_address_ip (&rloc.address))) - { - /* since rloc is stored in ip prefix we need to set prefix length */ - ip_prefix_t *pref = &gid_address_ippref (&rloc.address); - - u8 version = gid_address_ip_version (&rloc.address); - ip_prefix_len (pref) = ip_address_max_len (version); - - vec_add1 (rlocs, rloc); - curr_rloc = &rlocs[vec_len (rlocs) - 1]; - } - else if (unformat (line_input, "action %U", - unformat_negative_mapping_action, &action)) - ; - else - { - clib_warning ("parse error"); - goto done; - } - } - - if (!del_all && !eid_set) - { - clib_warning ("missing eid!"); - goto done; - } - - if (!del_all) - { - if (is_add && (~0 == action) && 0 == vec_len (rlocs)) - { - clib_warning ("no action set for negative map-reply!"); - goto done; - } - } - else - { - vnet_lisp_clear_all_remote_adjacencies (); - goto done; - } - - /* if it's a delete, clean forwarding */ - if (!is_add) - { - vnet_lisp_add_del_adjacency_args_t _a, *a = &_a; - clib_memset (a, 0, sizeof (a[0])); - gid_address_copy (&a->reid, &eid); - if (vnet_lisp_add_del_adjacency (a)) - { - clib_warning ("failed to delete adjacency!"); - goto done; - } - } - - /* add as static remote mapping, i.e., not authoritative and infinite - * ttl */ - if (is_add) - { - vnet_lisp_add_del_mapping_args_t _map_args, *map_args = &_map_args; - clib_memset (map_args, 0, sizeof (map_args[0])); - gid_address_copy (&map_args->eid, &eid); - map_args->action = action; - map_args->is_static = 1; - map_args->authoritative = 0; - map_args->ttl = ~0; - rv = vnet_lisp_add_mapping (map_args, rlocs, NULL, NULL); - } - else - rv = vnet_lisp_del_mapping (&eid, NULL); - - if (rv) - clib_warning ("failed to %s remote mapping!", is_add ? "add" : "delete"); - -done: - vec_free (rlocs); - unformat_free (line_input); - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_add_del_remote_mapping_command) = { - .path = "one remote-mapping", - .short_help = - "one remote-mapping add|del [del-all] vni " - "eid [action ] rloc p w " - "[rloc ... ]", - .function = lisp_add_del_remote_mapping_command_fn, -}; -/* *INDENT-ON* */ - -/** - * Handler for add/del adjacency CLI. - */ -static clib_error_t * -lisp_add_del_adjacency_command_fn (vlib_main_t * vm, unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - clib_error_t *error = 0; - unformat_input_t _line_input, *line_input = &_line_input; - vnet_lisp_add_del_adjacency_args_t _a, *a = &_a; - u8 is_add = 1; - ip_prefix_t *reid_ippref, *leid_ippref; - gid_address_t leid, reid; - u8 *dmac = gid_address_mac (&reid); - u8 *smac = gid_address_mac (&leid); - u8 reid_set = 0, leid_set = 0; - u32 vni; - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return 0; - - clib_memset (&reid, 0, sizeof (reid)); - clib_memset (&leid, 0, sizeof (leid)); - - leid_ippref = &gid_address_ippref (&leid); - reid_ippref = &gid_address_ippref (&reid); - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "del")) - is_add = 0; - else if (unformat (line_input, "add")) - ; - else if (unformat (line_input, "reid %U", - unformat_ip_prefix, reid_ippref)) - { - gid_address_type (&reid) = GID_ADDR_IP_PREFIX; - reid_set = 1; - } - else if (unformat (line_input, "reid %U", unformat_mac_address, dmac)) - { - gid_address_type (&reid) = GID_ADDR_MAC; - reid_set = 1; - } - else if (unformat (line_input, "vni %u", &vni)) - { - gid_address_vni (&leid) = vni; - gid_address_vni (&reid) = vni; - } - else if (unformat (line_input, "leid %U", - unformat_ip_prefix, leid_ippref)) - { - gid_address_type (&leid) = GID_ADDR_IP_PREFIX; - leid_set = 1; - } - else if (unformat (line_input, "leid %U", unformat_mac_address, smac)) - { - gid_address_type (&leid) = GID_ADDR_MAC; - leid_set = 1; - } - else - { - clib_warning ("parse error"); - goto done; - } - } - - if (!reid_set || !leid_set) - { - clib_warning ("missing remote or local eid!"); - goto done; - } - - if ((gid_address_type (&leid) != gid_address_type (&reid)) - || (gid_address_type (&reid) == GID_ADDR_IP_PREFIX - && ip_prefix_version (reid_ippref) - != ip_prefix_version (leid_ippref))) - { - clib_warning ("remote and local EIDs are of different types!"); - goto done; - } - - clib_memset (a, 0, sizeof (a[0])); - gid_address_copy (&a->leid, &leid); - gid_address_copy (&a->reid, &reid); - a->is_add = is_add; - - if (vnet_lisp_add_del_adjacency (a)) - clib_warning ("failed to %s adjacency!", is_add ? "add" : "delete"); - -done: - unformat_free (line_input); - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_add_del_adjacency_command) = { - .path = "one adjacency", - .short_help = "one adjacency add|del vni reid " - "leid ", - .function = lisp_add_del_adjacency_command_fn, -}; -/* *INDENT-ON* */ - - -static clib_error_t * -lisp_map_request_mode_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - unformat_input_t _i, *i = &_i; - map_request_mode_t mr_mode = _MR_MODE_MAX; - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, i)) - return 0; - - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "dst-only")) - mr_mode = MR_MODE_DST_ONLY; - else if (unformat (i, "src-dst")) - mr_mode = MR_MODE_SRC_DST; - else - { - clib_warning ("parse error '%U'", format_unformat_error, i); - goto done; - } - } - - if (_MR_MODE_MAX == mr_mode) - { - clib_warning ("No map request mode entered!"); - goto done; - } - - vnet_lisp_set_map_request_mode (mr_mode); - -done: - unformat_free (i); - - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_map_request_mode_command) = { - .path = "one map-request mode", - .short_help = "one map-request mode dst-only|src-dst", - .function = lisp_map_request_mode_command_fn, -}; -/* *INDENT-ON* */ - - -static u8 * -format_lisp_map_request_mode (u8 * s, va_list * args) -{ - u32 mode = va_arg (*args, u32); - - switch (mode) - { - case 0: - return format (0, "dst-only"); - case 1: - return format (0, "src-dst"); - } - return 0; -} - -static clib_error_t * -lisp_show_map_request_mode_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - vlib_cli_output (vm, "map-request mode: %U", format_lisp_map_request_mode, - vnet_lisp_get_map_request_mode ()); - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_show_map_request_mode_command) = { - .path = "show one map-request mode", - .short_help = "show one map-request mode", - .function = lisp_show_map_request_mode_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_show_map_resolvers_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - lisp_msmr_t *mr; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - - vec_foreach (mr, lcm->map_resolvers) - { - vlib_cli_output (vm, "%U", format_ip_address, &mr->address); - } - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_show_map_resolvers_command) = { - .path = "show one map-resolvers", - .short_help = "show one map-resolvers", - .function = lisp_show_map_resolvers_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_nsh_set_locator_set_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - u8 locator_name_set = 0; - u8 *locator_set_name = 0; - u8 is_add = 1; - unformat_input_t _line_input, *line_input = &_line_input; - clib_error_t *error = 0; - int rv = 0; - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return 0; - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "ls %_%v%_", &locator_set_name)) - locator_name_set = 1; - else if (unformat (line_input, "disable")) - is_add = 0; - else - { - error = clib_error_return (0, "parse error"); - goto done; - } - } - - if (!locator_name_set) - { - clib_warning ("No locator set specified!"); - goto done; - } - - vec_terminate_c_string (locator_set_name); - rv = vnet_lisp_nsh_set_locator_set (locator_set_name, is_add); - if (0 != rv) - { - error = clib_error_return (0, "failed to %s NSH mapping!", - is_add ? "add" : "delete"); - } - -done: - vec_free (locator_set_name); - unformat_free (line_input); - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_nsh_set_locator_set_command) = { - .path = "one nsh-mapping", - .short_help = "one nsh-mapping [del] ls ", - .function = lisp_nsh_set_locator_set_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_map_register_fallback_threshold_show_command_fn (vlib_main_t * vm, - unformat_input_t * - input, - vlib_cli_command_t * - cmd) -{ - u32 val = vnet_lisp_map_register_fallback_threshold_get (); - vlib_cli_output (vm, "map register fallback threshold value: %d", val); - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_map_register_fallback_threshold_show_command) = { - .path = "show one map-register fallback-threshold", - .short_help = "show one map-register fallback-threshold", - .function = lisp_map_register_fallback_threshold_show_command_fn, -}; - -/* *INDENT-ON* */ - -static clib_error_t * -lisp_map_register_fallback_threshold_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - unformat_input_t _line_input, *line_input = &_line_input; - clib_error_t *error = 0; - u32 val = 0; - int rv = 0; - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return 0; - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "%d", &val)) - ; - else - { - error = clib_error_return (0, "parse error"); - goto done; - } - } - - rv = vnet_lisp_map_register_fallback_threshold_set (val); - if (rv) - { - error = clib_error_return (0, "setting fallback threshold failed!"); - } - -done: - unformat_free (line_input); - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_map_register_fallback_threshold_command) = { - .path = "one map-register fallback-threshold", - .short_help = "one map-register fallback-threshold ", - .function = lisp_map_register_fallback_threshold_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_pitr_set_locator_set_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - u8 locator_name_set = 0; - u8 *locator_set_name = 0; - u8 is_add = 1; - unformat_input_t _line_input, *line_input = &_line_input; - clib_error_t *error = 0; - int rv = 0; - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return 0; - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "ls %_%v%_", &locator_set_name)) - locator_name_set = 1; - else if (unformat (line_input, "disable")) - is_add = 0; - else - { - error = clib_error_return (0, "parse error"); - goto done; - } - } - - if (!locator_name_set) - { - clib_warning ("No locator set specified!"); - goto done; - } - vec_terminate_c_string (locator_set_name); - rv = vnet_lisp_pitr_set_locator_set (locator_set_name, is_add); - if (0 != rv) - { - error = clib_error_return (0, "failed to %s pitr!", - is_add ? "add" : "delete"); - } - -done: - if (locator_set_name) - vec_free (locator_set_name); - unformat_free (line_input); - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_pitr_set_locator_set_command) = { - .path = "one pitr", - .short_help = "one pitr [disable] ls ", - .function = lisp_pitr_set_locator_set_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_show_pitr_command_fn (vlib_main_t * vm, - unformat_input_t * input, vlib_cli_command_t * cmd) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - mapping_t *m; - locator_set_t *ls; - u8 *tmp_str = 0; - u8 status = lcm->flags & LISP_FLAG_PITR_MODE; - - vlib_cli_output (vm, "%=20s%=16s", "pitr", status ? "locator-set" : ""); - - if (!status) - { - vlib_cli_output (vm, "%=20s", "disable"); - return 0; - } - - if (~0 == lcm->pitr_map_index) - { - tmp_str = format (0, "N/A"); - } - else - { - m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index); - if (~0 != m->locator_set_index) - { - ls = - pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index); - tmp_str = format (0, "%s", ls->name); - } - else - { - tmp_str = format (0, "N/A"); - } - } - vec_add1 (tmp_str, 0); - - vlib_cli_output (vm, "%=20s%=16s", "enable", tmp_str); - - vec_free (tmp_str); - - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_show_pitr_command) = { - .path = "show one pitr", - .short_help = "Show pitr", - .function = lisp_show_pitr_command_fn, -}; -/* *INDENT-ON* */ - -static u8 * -format_eid_entry (u8 * s, va_list * args) -{ - vnet_main_t *vnm = va_arg (*args, vnet_main_t *); - lisp_cp_main_t *lcm = va_arg (*args, lisp_cp_main_t *); - mapping_t *mapit = va_arg (*args, mapping_t *); - locator_set_t *ls = va_arg (*args, locator_set_t *); - gid_address_t *gid = &mapit->eid; - u32 ttl = mapit->ttl; - u8 aut = mapit->authoritative; - u32 *loc_index; - u8 first_line = 1; - u8 *loc; - - u8 *type = ls->local ? format (0, "local(%s)", ls->name) - : format (0, "remote"); - - if (vec_len (ls->locator_indices) == 0) - { - s = format (s, "%-35U%-20saction:%-30U%-20u%-u", format_gid_address, - gid, type, format_negative_mapping_action, mapit->action, - ttl, aut); - } - else - { - vec_foreach (loc_index, ls->locator_indices) - { - locator_t *l = pool_elt_at_index (lcm->locator_pool, loc_index[0]); - if (l->local) - loc = format (0, "%U", format_vnet_sw_if_index_name, vnm, - l->sw_if_index); - else - loc = format (0, "%U", format_ip_address, - &gid_address_ip (&l->address)); - - if (first_line) - { - s = format (s, "%-35U%-20s%-30v%-20u%-u\n", format_gid_address, - gid, type, loc, ttl, aut); - first_line = 0; - } - else - s = format (s, "%55s%v\n", "", loc); - } - } - return s; -} - -static clib_error_t * -lisp_show_eid_table_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - mapping_t *mapit; - unformat_input_t _line_input, *line_input = &_line_input; - u32 mi; - gid_address_t eid; - u8 print_all = 1; - u8 filter = 0; - clib_error_t *error = NULL; - - clib_memset (&eid, 0, sizeof (eid)); - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return 0; - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "eid %U", unformat_gid_address, &eid)) - print_all = 0; - else if (unformat (line_input, "local")) - filter = 1; - else if (unformat (line_input, "remote")) - filter = 2; - else - { - error = clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); - goto done; - } - } - - vlib_cli_output (vm, "%-35s%-20s%-30s%-20s%-s", - "EID", "type", "locators", "ttl", "authoritative"); - - if (print_all) - { - /* *INDENT-OFF* */ - pool_foreach (mapit, lcm->mapping_pool, - ({ - if (mapit->pitr_set || mapit->nsh_set) - continue; - - locator_set_t * ls = pool_elt_at_index (lcm->locator_set_pool, - mapit->locator_set_index); - if (filter && !((1 == filter && ls->local) || - (2 == filter && !ls->local))) - { - continue; - } - vlib_cli_output (vm, "%U", format_eid_entry, lcm->vnet_main, - lcm, mapit, ls); - })); - /* *INDENT-ON* */ - } - else - { - mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &eid); - if ((u32) ~ 0 == mi) - goto done; - - mapit = pool_elt_at_index (lcm->mapping_pool, mi); - locator_set_t *ls = pool_elt_at_index (lcm->locator_set_pool, - mapit->locator_set_index); - - if (filter && !((1 == filter && ls->local) || - (2 == filter && !ls->local))) - { - goto done; - } - - vlib_cli_output (vm, "%U,", format_eid_entry, lcm->vnet_main, - lcm, mapit, ls); - } - -done: - unformat_free (line_input); - - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_cp_show_eid_table_command) = { - .path = "show one eid-table", - .short_help = "show one eid-table [local|remote|eid ]", - .function = lisp_show_eid_table_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_enable_disable_pitr_mode_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - unformat_input_t _line_input, *line_input = &_line_input; - u8 is_enabled = 0; - u8 is_set = 0; - clib_error_t *error = NULL; - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return clib_error_return (0, "expected enable | disable"); - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "enable")) - { - is_set = 1; - is_enabled = 1; - } - else if (unformat (line_input, "disable")) - is_set = 1; - else - { - error = clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); - goto done; - } - } - - if (!is_set) - { - error = clib_error_return (0, "state not set"); - goto done; - } - - vnet_lisp_enable_disable_pitr_mode (is_enabled); - -done: - unformat_free (line_input); - - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_cp_enable_disable_pitr_mode_command) = { - .path = "one pitr mode", - .short_help = "one pitr mode [enable|disable]", - .function = lisp_enable_disable_pitr_mode_command_fn, -}; -/* *INDENT-ON* */ - - -static clib_error_t * -lisp_enable_disable_petr_mode_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - unformat_input_t _line_input, *line_input = &_line_input; - u8 is_enabled = 0; - u8 is_set = 0; - clib_error_t *error = NULL; - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return clib_error_return (0, "expected enable | disable"); - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "enable")) - { - is_set = 1; - is_enabled = 1; - } - else if (unformat (line_input, "disable")) - is_set = 1; - else - { - error = clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); - goto done; - } - } - - if (!is_set) - { - error = clib_error_return (0, "state not set"); - goto done; - } - - vnet_lisp_enable_disable_petr_mode (is_enabled); - -done: - unformat_free (line_input); - - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_cp_enable_disable_petr_mode_command) = { - .path = "one petr mode", - .short_help = "one petr mode [enable|disable]", - .function = lisp_enable_disable_petr_mode_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_enable_disable_xtr_mode_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - unformat_input_t _line_input, *line_input = &_line_input; - u8 is_enabled = 0; - u8 is_set = 0; - clib_error_t *error = NULL; - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return clib_error_return (0, "expected enable | disable"); - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "enable")) - { - is_set = 1; - is_enabled = 1; - } - else if (unformat (line_input, "disable")) - is_set = 1; - else - { - error = clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); - goto done; - } - } - - if (!is_set) - { - error = clib_error_return (0, "state not set"); - goto done; - } - - vnet_lisp_enable_disable_xtr_mode (is_enabled); - -done: - unformat_free (line_input); - - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_cp_enable_disable_xtr_mode_command) = { - .path = "one xtr mode", - .short_help = "one xtr mode [enable|disable]", - .function = lisp_enable_disable_xtr_mode_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -one_enable_command_fn (vlib_main_t * vm, unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) - return clib_error_return (0, "parse error: '%U'", format_unformat_error, - input); - - vnet_lisp_enable_disable (1); - - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_cp_enable_command) = { - .path = "one enable", - .short_help = "one enable", - .function = one_enable_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -one_disable_command_fn (vlib_main_t * vm, unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) - return clib_error_return (0, "parse error: '%U'", format_unformat_error, - input); - - vnet_lisp_enable_disable (0); - - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_cp_disable_command) = { - .path = "one disable", - .short_help = "one disable", - .function = one_disable_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_map_register_set_ttl_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - unformat_input_t _line_input, *line_input = &_line_input; - u32 ttl = 0; - u8 is_set = 0; - clib_error_t *error = NULL; - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return clib_error_return (0, "expected enable | disable"); - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "%u", &ttl)) - is_set = 1; - else - { - vlib_cli_output (vm, "parse error: '%U'", format_unformat_error, - line_input); - goto done; - } - } - - if (!is_set) - { - vlib_cli_output (vm, "expected integer value for TTL!"); - goto done; - } - - vnet_lisp_map_register_set_ttl (ttl); - -done: - unformat_free (line_input); - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_map_register_set_ttl_command) = { - .path = "one map-register ttl", - .short_help = "one map-register ttl", - .function = lisp_map_register_set_ttl_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_map_register_show_ttl_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - u32 ttl = vnet_lisp_map_register_get_ttl (); - - vlib_cli_output (vm, "map-register TTL: %u", ttl); - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_map_register_show_ttl_command) = { - .path = "show one map-register ttl", - .short_help = "show one map-register ttl", - .function = lisp_map_register_show_ttl_command_fn, -}; - -/* *INDENT-ON* */ - -static clib_error_t * -lisp_map_register_enable_disable_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - unformat_input_t _line_input, *line_input = &_line_input; - u8 is_enabled = 0; - u8 is_set = 0; - clib_error_t *error = NULL; - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return clib_error_return (0, "expected enable | disable"); - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "enable")) - { - is_set = 1; - is_enabled = 1; - } - else if (unformat (line_input, "disable")) - is_set = 1; - else - { - vlib_cli_output (vm, "parse error: '%U'", format_unformat_error, - line_input); - goto done; - } - } - - if (!is_set) - { - vlib_cli_output (vm, "state not set!"); - goto done; - } - - vnet_lisp_map_register_enable_disable (is_enabled); - -done: - unformat_free (line_input); - - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_map_register_enable_disable_command) = { - .path = "one map-register", - .short_help = "one map-register [enable|disable]", - .function = lisp_map_register_enable_disable_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_rloc_probe_enable_disable_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - unformat_input_t _line_input, *line_input = &_line_input; - u8 is_enabled = 0; - u8 is_set = 0; - clib_error_t *error = NULL; - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return clib_error_return (0, "expected enable | disable"); - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "enable")) - { - is_set = 1; - is_enabled = 1; - } - else if (unformat (line_input, "disable")) - is_set = 1; - else - { - vlib_cli_output (vm, "parse error: '%U'", format_unformat_error, - line_input); - goto done; - } - } - - if (!is_set) - { - vlib_cli_output (vm, "state not set!"); - goto done; - } - - vnet_lisp_rloc_probe_enable_disable (is_enabled); - -done: - unformat_free (line_input); - - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_rloc_probe_enable_disable_command) = { - .path = "one rloc-probe", - .short_help = "one rloc-probe [enable|disable]", - .function = lisp_rloc_probe_enable_disable_command_fn, -}; -/* *INDENT-ON* */ - -static u8 * -format_lisp_status (u8 * s, va_list * args) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - return format (s, "%s", lcm->is_enabled ? "enabled" : "disabled"); -} - -static clib_error_t * -lisp_show_status_command_fn (vlib_main_t * vm, unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - u8 *msg = 0; - msg = format (msg, "feature: %U\ngpe: %U\n", - format_lisp_status, format_vnet_lisp_gpe_status); - vlib_cli_output (vm, "%v", msg); - vec_free (msg); - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_show_status_command) = { - .path = "show one status", - .short_help = "show one status", - .function = lisp_show_status_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_show_eid_table_map_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - hash_pair_t *p; - unformat_input_t _line_input, *line_input = &_line_input; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - uword *vni_table = 0; - u8 is_l2 = 0; - clib_error_t *error = NULL; - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return 0; - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "l2")) - { - vni_table = lcm->bd_id_by_vni; - is_l2 = 1; - } - else if (unformat (line_input, "l3")) - { - vni_table = lcm->table_id_by_vni; - is_l2 = 0; - } - else - { - error = clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); - goto done; - } - } - - if (!vni_table) - { - vlib_cli_output (vm, "Error: expected l2|l3 param!\n"); - goto done; - } - - vlib_cli_output (vm, "%=10s%=10s", "VNI", is_l2 ? "BD" : "VRF"); - - /* *INDENT-OFF* */ - hash_foreach_pair (p, vni_table, - ({ - vlib_cli_output (vm, "%=10d%=10d", p->key, p->value[0]); - })); - /* *INDENT-ON* */ - -done: - unformat_free (line_input); - - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_show_eid_table_map_command) = { - .path = "show one eid-table map", - .short_help = "show one eid-table map l2|l3", - .function = lisp_show_eid_table_map_command_fn, -}; -/* *INDENT-ON* */ - - -static clib_error_t * -lisp_add_del_locator_set_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - lisp_gpe_main_t *lgm = &lisp_gpe_main; - vnet_main_t *vnm = lgm->vnet_main; - unformat_input_t _line_input, *line_input = &_line_input; - u8 is_add = 1; - clib_error_t *error = 0; - u8 *locator_set_name = 0; - locator_t locator, *locators = 0; - vnet_lisp_add_del_locator_set_args_t _a, *a = &_a; - u32 ls_index = 0; - int rv = 0; - - clib_memset (&locator, 0, sizeof (locator)); - clib_memset (a, 0, sizeof (a[0])); - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return 0; - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "add %_%v%_", &locator_set_name)) - is_add = 1; - else if (unformat (line_input, "del %_%v%_", &locator_set_name)) - is_add = 0; - else if (unformat (line_input, "iface %U p %d w %d", - unformat_vnet_sw_interface, vnm, - &locator.sw_if_index, &locator.priority, - &locator.weight)) - { - locator.local = 1; - locator.state = 1; - vec_add1 (locators, locator); - } - else - { - error = unformat_parse_error (line_input); - goto done; - } - } - - vec_terminate_c_string (locator_set_name); - a->name = locator_set_name; - a->locators = locators; - a->is_add = is_add; - a->local = 1; - - rv = vnet_lisp_add_del_locator_set (a, &ls_index); - if (0 != rv) - { - error = clib_error_return (0, "failed to %s locator-set!", - is_add ? "add" : "delete"); - } - -done: - vec_free (locators); - if (locator_set_name) - vec_free (locator_set_name); - unformat_free (line_input); - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_cp_add_del_locator_set_command) = { - .path = "one locator-set", - .short_help = "one locator-set add/del [iface " - "p w ]", - .function = lisp_add_del_locator_set_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_add_del_locator_in_set_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - lisp_gpe_main_t *lgm = &lisp_gpe_main; - vnet_main_t *vnm = lgm->vnet_main; - unformat_input_t _line_input, *line_input = &_line_input; - u8 is_add = 1; - clib_error_t *error = 0; - u8 *locator_set_name = 0; - u8 locator_set_name_set = 0; - locator_t locator, *locators = 0; - vnet_lisp_add_del_locator_set_args_t _a, *a = &_a; - u32 ls_index = 0; - - clib_memset (&locator, 0, sizeof (locator)); - clib_memset (a, 0, sizeof (a[0])); - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return 0; - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "add")) - is_add = 1; - else if (unformat (line_input, "del")) - is_add = 0; - else if (unformat (line_input, "locator-set %_%v%_", &locator_set_name)) - locator_set_name_set = 1; - else if (unformat (line_input, "iface %U p %d w %d", - unformat_vnet_sw_interface, vnm, - &locator.sw_if_index, &locator.priority, - &locator.weight)) - { - locator.local = 1; - vec_add1 (locators, locator); - } - else - { - error = unformat_parse_error (line_input); - goto done; - } - } - - if (!locator_set_name_set) - { - error = clib_error_return (0, "locator_set name not set!"); - goto done; - } - - vec_terminate_c_string (locator_set_name); - a->name = locator_set_name; - a->locators = locators; - a->is_add = is_add; - a->local = 1; - - vnet_lisp_add_del_locator (a, 0, &ls_index); - -done: - vec_free (locators); - vec_free (locator_set_name); - unformat_free (line_input); - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_cp_add_del_locator_in_set_command) = { - .path = "one locator", - .short_help = "one locator add/del locator-set iface " - "p w ", - .function = lisp_add_del_locator_in_set_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_cp_show_locator_sets_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - locator_set_t *lsit; - locator_t *loc; - u32 *locit; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - - vlib_cli_output (vm, "%s%=16s%=16s%=16s", "Locator-set", "Locator", - "Priority", "Weight"); - - /* *INDENT-OFF* */ - pool_foreach (lsit, lcm->locator_set_pool, - ({ - u8 * msg = 0; - int next_line = 0; - if (lsit->local) - { - msg = format (msg, "%s", lsit->name); - } - else - { - msg = format (msg, "<%s-%d>", "remote", lsit - lcm->locator_set_pool); - } - vec_foreach (locit, lsit->locator_indices) - { - if (next_line) - { - msg = format (msg, "%16s", " "); - } - loc = pool_elt_at_index (lcm->locator_pool, locit[0]); - if (loc->local) - msg = format (msg, "%16d%16d%16d\n", loc->sw_if_index, loc->priority, - loc->weight); - else - msg = format (msg, "%16U%16d%16d\n", format_ip_address, - &gid_address_ip(&loc->address), loc->priority, - loc->weight); - next_line = 1; - } - vlib_cli_output (vm, "%v", msg); - vec_free (msg); - })); - /* *INDENT-ON* */ - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_cp_show_locator_sets_command) = { - .path = "show one locator-set", - .short_help = "Shows locator-sets", - .function = lisp_cp_show_locator_sets_command_fn, -}; -/* *INDENT-ON* */ - - -static clib_error_t * -lisp_add_del_map_resolver_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - unformat_input_t _line_input, *line_input = &_line_input; - u8 is_add = 1, addr_set = 0; - ip_address_t ip_addr; - clib_error_t *error = 0; - int rv = 0; - vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a; - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return 0; - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "add")) - is_add = 1; - else if (unformat (line_input, "del")) - is_add = 0; - else if (unformat (line_input, "%U", unformat_ip_address, &ip_addr)) - addr_set = 1; - else - { - error = unformat_parse_error (line_input); - goto done; - } - } - - if (!addr_set) - { - error = clib_error_return (0, "Map-resolver address must be set!"); - goto done; - } - - a->is_add = is_add; - a->address = ip_addr; - rv = vnet_lisp_add_del_map_resolver (a); - if (0 != rv) - { - error = clib_error_return (0, "failed to %s map-resolver!", - is_add ? "add" : "delete"); - } - -done: - unformat_free (line_input); - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_add_del_map_resolver_command) = { - .path = "one map-resolver", - .short_help = "one map-resolver add/del ", - .function = lisp_add_del_map_resolver_command_fn, -}; -/* *INDENT-ON* */ - - -static clib_error_t * -lisp_add_del_mreq_itr_rlocs_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - unformat_input_t _line_input, *line_input = &_line_input; - u8 is_add = 1; - u8 *locator_set_name = 0; - clib_error_t *error = 0; - int rv = 0; - vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a; - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return 0; - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "del")) - is_add = 0; - else if (unformat (line_input, "add %_%v%_", &locator_set_name)) - is_add = 1; - else - { - error = unformat_parse_error (line_input); - goto done; - } - } - - vec_terminate_c_string (locator_set_name); - a->is_add = is_add; - a->locator_set_name = locator_set_name; - rv = vnet_lisp_add_del_mreq_itr_rlocs (a); - if (0 != rv) - { - error = clib_error_return (0, "failed to %s map-request itr-rlocs!", - is_add ? "add" : "delete"); - } - -done: - vec_free (locator_set_name); - unformat_free (line_input); - return error; - -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_add_del_map_request_command) = { - .path = "one map-request itr-rlocs", - .short_help = "one map-request itr-rlocs add/del ", - .function = lisp_add_del_mreq_itr_rlocs_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_show_mreq_itr_rlocs_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - locator_set_t *loc_set; - - vlib_cli_output (vm, "%=20s", "itr-rlocs"); - - if (~0 == lcm->mreq_itr_rlocs) - { - return 0; - } - - loc_set = pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs); - - vlib_cli_output (vm, "%=20s", loc_set->name); - - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_show_map_request_command) = { - .path = "show one map-request itr-rlocs", - .short_help = "Shows map-request itr-rlocs", - .function = lisp_show_mreq_itr_rlocs_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_use_petr_set_locator_set_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - u8 is_add = 1, ip_set = 0; - unformat_input_t _line_input, *line_input = &_line_input; - clib_error_t *error = 0; - ip_address_t ip; - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return 0; - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "%U", unformat_ip_address, &ip)) - ip_set = 1; - else if (unformat (line_input, "disable")) - is_add = 0; - else - { - error = clib_error_return (0, "parse error"); - goto done; - } - } - - if (!ip_set) - { - clib_warning ("No petr IP specified!"); - goto done; - } - - if (vnet_lisp_use_petr (&ip, is_add)) - { - error = clib_error_return (0, "failed to %s petr!", - is_add ? "add" : "delete"); - } - -done: - unformat_free (line_input); - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_use_petr_set_locator_set_command) = { - .path = "one use-petr", - .short_help = "one use-petr [disable] ", - .function = lisp_use_petr_set_locator_set_command_fn, -}; - -static clib_error_t * -lisp_show_petr_command_fn (vlib_main_t * vm, - unformat_input_t * input, vlib_cli_command_t * cmd) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - mapping_t *m; - locator_set_t *ls; - locator_t *loc; - u8 *tmp_str = 0; - u8 use_petr = lcm->flags & LISP_FLAG_USE_PETR; - vlib_cli_output (vm, "%=20s%=16s", "petr", use_petr ? "ip" : ""); - - if (!use_petr) - { - vlib_cli_output (vm, "%=20s", "disable"); - return 0; - } - - if (~0 == lcm->petr_map_index) - { - tmp_str = format (0, "N/A"); - } - else - { - m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index); - if (~0 != m->locator_set_index) - { - ls = pool_elt_at_index(lcm->locator_set_pool, m->locator_set_index); - loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]); - tmp_str = format (0, "%U", format_ip_address, &loc->address); - } - else - { - tmp_str = format (0, "N/A"); - } - } - vec_add1 (tmp_str, 0); - - vlib_cli_output (vm, "%=20s%=16s", "enable", tmp_str); - - vec_free (tmp_str); - - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_show_petr_command) = { - .path = "show one petr", - .short_help = "Show petr", - .function = lisp_show_petr_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_show_map_servers_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - lisp_msmr_t *ms; - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - - vec_foreach (ms, lcm->map_servers) - { - vlib_cli_output (vm, "%U", format_ip_address, &ms->address); - } - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_show_map_servers_command) = { - .path = "show one map-servers", - .short_help = "show one map servers", - .function = lisp_show_map_servers_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_show_map_register_state_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - u8 *msg = 0; - u8 is_enabled = vnet_lisp_map_register_state_get (); - - msg = format (msg, "%s\n", is_enabled ? "enabled" : "disabled"); - vlib_cli_output (vm, "%v", msg); - vec_free (msg); - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_show_map_register_state_command) = { - .path = "show one map-register state", - .short_help = "show one map-register state", - .function = lisp_show_map_register_state_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_show_rloc_probe_state_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - u8 *msg = 0; - u8 is_enabled = vnet_lisp_rloc_probe_state_get (); - - msg = format (msg, "%s\n", is_enabled ? "enabled" : "disabled"); - vlib_cli_output (vm, "%v", msg); - vec_free (msg); - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_show_rloc_probe_state_command) = { - .path = "show one rloc state", - .short_help = "show one RLOC state", - .function = lisp_show_rloc_probe_state_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_show_stats_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - u8 is_enabled = vnet_lisp_stats_enable_disable_state (); - vlib_cli_output (vm, "%s\n", is_enabled ? "enabled" : "disabled"); - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_show_stats_command) = { - .path = "show one statistics status", - .short_help = "show ONE statistics enable/disable status", - .function = lisp_show_stats_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_show_stats_details_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - lisp_api_stats_t *stat, *stats = vnet_lisp_get_stats (); - - if (vec_len (stats) > 0) - vlib_cli_output (vm, - "[src-EID, dst-EID] [loc-rloc, rmt-rloc] count bytes\n"); - else - vlib_cli_output (vm, "No statistics found.\n"); - - vec_foreach (stat, stats) - { - vlib_cli_output (vm, "[%U, %U] [%U, %U] %7u %7u\n", - format_fid_address, &stat->seid, - format_fid_address, &stat->deid, - format_ip_address, &stat->loc_rloc, - format_ip_address, &stat->rmt_rloc, - stat->counters.packets, stat->counters.bytes); - } - vec_free (stats); - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_show_stats_details_command) = { - .path = "show one statistics details", - .short_help = "show ONE statistics", - .function = lisp_show_stats_details_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_stats_enable_disable_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - unformat_input_t _line_input, *line_input = &_line_input; - u8 enable = 0; - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return clib_error_return (0, "expected enable | disable"); - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "enable")) - enable = 1; - else if (unformat (line_input, "disable")) - enable = 0; - else - { - clib_warning ("Error: expected enable/disable!"); - goto done; - } - } - vnet_lisp_stats_enable_disable (enable); -done: - unformat_free (line_input); - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_stats_enable_disable_command) = { - .path = "one statistics", - .short_help = "enable/disable ONE statistics collecting", - .function = lisp_stats_enable_disable_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_stats_flush_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - vnet_lisp_flush_stats (); - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_stats_flush_command) = { - .path = "one statistics flush", - .short_help = "Flush ONE statistics", - .function = lisp_stats_flush_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_show_one_modes_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - u8 pitr_mode = vnet_lisp_get_pitr_mode (); - u8 petr_mode = vnet_lisp_get_petr_mode (); - u8 xtr_mode = vnet_lisp_get_xtr_mode (); - - vlib_cli_output (vm, "xTR: %s\n", xtr_mode ? "enabled" : "disabled"); - vlib_cli_output (vm, "P-ITR: %s\n", pitr_mode ? "enabled" : "disabled"); - vlib_cli_output (vm, "P-ETR: %s\n", petr_mode ? "enabled" : "disabled"); - - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (one_cp_show_one_modes_modes_command) = { - .path = "show one modes", - .short_help = "show one modes", - .function = lisp_show_one_modes_command_fn, -}; -/* *INDENT-ON* */ - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/src/vnet/lisp-cp/packets.c b/src/vnet/lisp-cp/packets.c deleted file mode 100644 index bbc3ad64572..00000000000 --- a/src/vnet/lisp-cp/packets.c +++ /dev/null @@ -1,226 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -/* Returns IP ID for the packet */ -/* static u16 ip_id = 0; -static inline u16 -get_IP_ID() -{ - ip_id++; - return (ip_id); -} */ - -u16 -udp_ip4_checksum (const void *b, u32 len, u8 * src, u8 * dst) -{ - const u16 *buf = b; - u16 *ip_src = (u16 *) src; - u16 *ip_dst = (u16 *) dst; - u32 length = len; - u32 sum = 0; - - while (len > 1) - { - sum += *buf++; - if (sum & 0x80000000) - sum = (sum & 0xFFFF) + (sum >> 16); - len -= 2; - } - - /* Add the padding if the packet length is odd */ - if (len & 1) - sum += *((u8 *) buf); - - /* Add the pseudo-header */ - sum += *(ip_src++); - sum += *ip_src; - - sum += *(ip_dst++); - sum += *ip_dst; - - sum += clib_host_to_net_u16 (IP_PROTOCOL_UDP); - sum += clib_host_to_net_u16 (length); - - /* Add the carries */ - while (sum >> 16) - sum = (sum & 0xFFFF) + (sum >> 16); - - /* Return the one's complement of sum */ - return ((u16) (~sum)); -} - -u16 -udp_ip6_checksum (ip6_header_t * ip6, udp_header_t * up, u32 len) -{ - size_t i; - register const u16 *sp; - u32 sum; - union - { - struct - { - ip6_address_t ph_src; - ip6_address_t ph_dst; - u32 ph_len; - u8 ph_zero[3]; - u8 ph_nxt; - } ph; - u16 pa[20]; - } phu; - - /* pseudo-header */ - clib_memset (&phu, 0, sizeof (phu)); - phu.ph.ph_src = ip6->src_address; - phu.ph.ph_dst = ip6->dst_address; - phu.ph.ph_len = clib_host_to_net_u32 (len); - phu.ph.ph_nxt = IP_PROTOCOL_UDP; - - sum = 0; - for (i = 0; i < sizeof (phu.pa) / sizeof (phu.pa[0]); i++) - sum += phu.pa[i]; - - sp = (const u16 *) up; - - for (i = 0; i < (len & ~1); i += 2) - sum += *sp++; - - if (len & 1) - sum += clib_host_to_net_u16 ((*(const u8 *) sp) << 8); - - while (sum > 0xffff) - sum = (sum & 0xffff) + (sum >> 16); - sum = ~sum & 0xffff; - - return (sum); -} - -u16 -udp_checksum (udp_header_t * uh, u32 udp_len, void *ih, u8 version) -{ - switch (version) - { - case AF_IP4: - return (udp_ip4_checksum (uh, udp_len, - ((ip4_header_t *) ih)->src_address.as_u8, - ((ip4_header_t *) ih)->dst_address.as_u8)); - case AF_IP6: - return (udp_ip6_checksum (ih, uh, udp_len)); - default: - return ~0; - } -} - -void * -pkt_push_udp (vlib_main_t * vm, vlib_buffer_t * b, u16 sp, u16 dp) -{ - udp_header_t *uh; - u16 udp_len = sizeof (udp_header_t) + vlib_buffer_length_in_chain (vm, b); - - uh = vlib_buffer_push_uninit (b, sizeof (*uh)); - - uh->src_port = clib_host_to_net_u16 (sp); - uh->dst_port = clib_host_to_net_u16 (dp); - uh->length = clib_host_to_net_u16 (udp_len); - uh->checksum = 0; - return uh; -} - -void * -pkt_push_ip (vlib_main_t * vm, vlib_buffer_t * b, ip_address_t * src, - ip_address_t * dst, u32 proto, u8 csum_offload) -{ - if (ip_addr_version (src) != ip_addr_version (dst)) - { - clib_warning ("src %U and dst %U IP have different AFI! Discarding!", - format_ip_address, src, format_ip_address, dst); - return 0; - } - - switch (ip_addr_version (src)) - { - case AF_IP4: - return vlib_buffer_push_ip4 (vm, b, &ip_addr_v4 (src), - &ip_addr_v4 (dst), proto, csum_offload); - break; - case AF_IP6: - return vlib_buffer_push_ip6 (vm, b, &ip_addr_v6 (src), - &ip_addr_v6 (dst), proto); - break; - } - - return 0; -} - -void * -pkt_push_udp_and_ip (vlib_main_t * vm, vlib_buffer_t * b, u16 sp, u16 dp, - ip_address_t * sip, ip_address_t * dip, u8 csum_offload) -{ - u16 udpsum; - udp_header_t *uh; - void *ih; - - uh = pkt_push_udp (vm, b, sp, dp); - - if (csum_offload) - { - ih = pkt_push_ip (vm, b, sip, dip, IP_PROTOCOL_UDP, 1); - b->flags |= VNET_BUFFER_F_OFFLOAD_UDP_CKSUM; - vnet_buffer (b)->l3_hdr_offset = (u8 *) ih - b->data; - vnet_buffer (b)->l4_hdr_offset = (u8 *) uh - b->data; - uh->checksum = 0; - } - else - { - ih = pkt_push_ip (vm, b, sip, dip, IP_PROTOCOL_UDP, 0); - udpsum = udp_checksum (uh, clib_net_to_host_u16 (uh->length), ih, - ip_addr_version (sip)); - if (udpsum == (u16) ~ 0) - { - clib_warning ("Failed UDP checksum! Discarding"); - return 0; - } - /* clear flags used for csum since we're not offloading */ - b->flags &= ~(VNET_BUFFER_F_IS_IP4 | VNET_BUFFER_F_IS_IP6); - uh->checksum = udpsum; - } - return ih; -} - -void * -pkt_push_ecm_hdr (vlib_buffer_t * b) -{ - ecm_hdr_t *h; - h = vlib_buffer_push_uninit (b, sizeof (h[0])); - - clib_memset (h, 0, sizeof (h[0])); - h->type = LISP_ENCAP_CONTROL_TYPE; - clib_memset (h->reserved2, 0, sizeof (h->reserved2)); - - return h; -} - -/* *INDENT-ON* */ - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/src/vnet/lisp-cp/packets.h b/src/vnet/lisp-cp/packets.h deleted file mode 100644 index eb9871bf9c0..00000000000 --- a/src/vnet/lisp-cp/packets.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#define IP_DF 0x4000 /* don't fragment */ - -void *pkt_push_ip (vlib_main_t * vm, vlib_buffer_t * b, ip_address_t * src, - ip_address_t * dst, u32 proto, u8 csum_offload); - -void *pkt_push_udp_and_ip (vlib_main_t * vm, vlib_buffer_t * b, u16 sp, - u16 dp, ip_address_t * sip, ip_address_t * dip, - u8 cksum_offload); - -void *pkt_push_ecm_hdr (vlib_buffer_t * b); - -/* *INDENT-ON* */ - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/src/vnet/lisp-gpe/FEATURE.yaml b/src/vnet/lisp-gpe/FEATURE.yaml deleted file mode 100644 index d2016e6120d..00000000000 --- a/src/vnet/lisp-gpe/FEATURE.yaml +++ /dev/null @@ -1,11 +0,0 @@ ---- -name: Locator ID Separation Protocol Generic Protocol Extension -maintainer: Florin Coras -features: - - ITR, ETR and RTR modes - - Support for Ethernet, IPv4, IPv6 and NSH EIDs (payloads) - - Source/dest forwarding - - IPv4 and IPv6 RLOCs -description: "Locator ID Separation Protocol Generic Protocol Extension (LISP-GPE) implementation" -state: production -properties: [API, CLI, STATS, MULTITHREAD] diff --git a/src/vnet/lisp-gpe/decap.c b/src/vnet/lisp-gpe/decap.c deleted file mode 100644 index ab35c7ea73d..00000000000 --- a/src/vnet/lisp-gpe/decap.c +++ /dev/null @@ -1,605 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @file - * @brief L2 LISP-GPE decap code. - * - */ -#include -#include -#include - -typedef struct -{ - u32 next_index; - u32 tunnel_index; - u32 error; - lisp_gpe_header_t h; -} lisp_gpe_rx_trace_t; - -static u8 * -format_lisp_gpe_rx_trace (u8 * s, va_list * args) -{ - CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); - CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); - lisp_gpe_rx_trace_t *t = va_arg (*args, lisp_gpe_rx_trace_t *); - - if (t->tunnel_index != ~0) - { - s = format (s, "LISP-GPE: tunnel %d next %d error %d", t->tunnel_index, - t->next_index, t->error); - } - else - { - s = format (s, "LISP-GPE: no tunnel next %d error %d\n", t->next_index, - t->error); - } - s = format (s, "\n %U", format_lisp_gpe_header_with_length, &t->h, - (u32) sizeof (t->h) /* max size */ ); - return s; -} - -static u32 next_proto_to_next_index[LISP_GPE_NEXT_PROTOS] = { - LISP_GPE_INPUT_NEXT_DROP, - LISP_GPE_INPUT_NEXT_IP4_INPUT, - LISP_GPE_INPUT_NEXT_IP6_INPUT, - LISP_GPE_INPUT_NEXT_L2_INPUT, - LISP_GPE_INPUT_NEXT_DROP -}; - -always_inline u32 -next_protocol_to_next_index (lisp_gpe_header_t * lgh, u8 * next_header) -{ - lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main (); - - /* lisp-gpe router */ - if (PREDICT_TRUE ((lgh->flags & LISP_GPE_FLAGS_P) - || GPE_ENCAP_VXLAN == lgm->encap_mode)) - { - if (PREDICT_FALSE (lgh->next_protocol >= LISP_GPE_NEXT_PROTOS)) - return LISP_GPE_INPUT_NEXT_DROP; - - return next_proto_to_next_index[lgh->next_protocol]; - } - /* legacy lisp router */ - else if ((lgh->flags & LISP_GPE_FLAGS_P) == 0) - { - ip4_header_t *iph = (ip4_header_t *) next_header; - if ((iph->ip_version_and_header_length & 0xF0) == 0x40) - return LISP_GPE_INPUT_NEXT_IP4_INPUT; - else if ((iph->ip_version_and_header_length & 0xF0) == 0x60) - return LISP_GPE_INPUT_NEXT_IP6_INPUT; - else - return LISP_GPE_INPUT_NEXT_DROP; - } - else - return LISP_GPE_INPUT_NEXT_DROP; -} - -always_inline tunnel_lookup_t * -next_index_to_iface (lisp_gpe_main_t * lgm, u32 next_index) -{ - if (LISP_GPE_INPUT_NEXT_IP4_INPUT == next_index - || LISP_GPE_INPUT_NEXT_IP6_INPUT == next_index) - return &lgm->l3_ifaces; - else if (LISP_GPE_INPUT_NEXT_L2_INPUT == next_index) - return &lgm->l2_ifaces; - else if (LISP_GPE_INPUT_NEXT_NSH_INPUT == next_index) - return &lgm->nsh_ifaces; - clib_warning ("next_index not associated to an interface!"); - return 0; -} - -static_always_inline void -incr_decap_stats (vnet_main_t * vnm, u32 thread_index, u32 length, - u32 sw_if_index, u32 * last_sw_if_index, u32 * n_packets, - u32 * n_bytes) -{ - vnet_interface_main_t *im; - - if (PREDICT_TRUE (sw_if_index == *last_sw_if_index)) - { - *n_packets += 1; - *n_bytes += length; - } - else - { - if (PREDICT_TRUE (*last_sw_if_index != ~0)) - { - im = &vnm->interface_main; - - vlib_increment_combined_counter (im->combined_sw_if_counters + - VNET_INTERFACE_COUNTER_RX, - thread_index, *last_sw_if_index, - *n_packets, *n_bytes); - } - *last_sw_if_index = sw_if_index; - *n_packets = 1; - *n_bytes = length; - } -} - -/** - * @brief LISP-GPE decap dispatcher. - * @node lisp_gpe_input_inline - * - * LISP-GPE decap dispatcher. - * - * Decaps IP-UDP-LISP-GPE header and based on the next protocol and in the - * GPE header and the vni decides the next node to forward the packet to. - * - * @param[in] vm vlib_main_t corresponding to current thread. - * @param[in] node vlib_node_runtime_t data for this node. - * @param[in] frame vlib_frame_t whose contents should be dispatched. - * - * @return number of vectors in frame. - */ -static uword -lisp_gpe_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node, - vlib_frame_t * from_frame, u8 is_v4) -{ - u32 n_left_from, next_index, *from, *to_next, thread_index; - u32 n_bytes = 0, n_packets = 0, last_sw_if_index = ~0, drops = 0; - lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main (); - - thread_index = vm->thread_index; - from = vlib_frame_vector_args (from_frame); - n_left_from = from_frame->n_vectors; - - next_index = node->cached_next_index; - - while (n_left_from > 0) - { - u32 n_left_to_next; - - vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); - - while (n_left_from >= 4 && n_left_to_next >= 2) - { - u32 bi0, bi1; - vlib_buffer_t *b0, *b1; - ip4_udp_lisp_gpe_header_t *iul4_0, *iul4_1; - ip6_udp_lisp_gpe_header_t *iul6_0, *iul6_1; - lisp_gpe_header_t *lh0, *lh1; - u32 next0, next1, error0, error1; - uword *si0, *si1; - tunnel_lookup_t *tl0, *tl1; - - /* Prefetch next iteration. */ - { - vlib_buffer_t *p2, *p3; - - p2 = vlib_get_buffer (vm, from[2]); - p3 = vlib_get_buffer (vm, from[3]); - - vlib_prefetch_buffer_header (p2, LOAD); - vlib_prefetch_buffer_header (p3, LOAD); - - CLIB_PREFETCH (p2->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD); - CLIB_PREFETCH (p3->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD); - } - - bi0 = from[0]; - bi1 = from[1]; - to_next[0] = bi0; - to_next[1] = bi1; - from += 2; - to_next += 2; - n_left_to_next -= 2; - n_left_from -= 2; - - b0 = vlib_get_buffer (vm, bi0); - b1 = vlib_get_buffer (vm, bi1); - - /* udp leaves current_data pointing at the lisp header */ - if (is_v4) - { - vlib_buffer_advance (b0, - -(word) (sizeof (udp_header_t) + - sizeof (ip4_header_t))); - vlib_buffer_advance (b1, - -(word) (sizeof (udp_header_t) + - sizeof (ip4_header_t))); - - iul4_0 = vlib_buffer_get_current (b0); - iul4_1 = vlib_buffer_get_current (b1); - - /* pop (ip, udp, lisp-gpe) */ - vlib_buffer_advance (b0, sizeof (*iul4_0)); - vlib_buffer_advance (b1, sizeof (*iul4_1)); - - lh0 = &iul4_0->lisp; - lh1 = &iul4_1->lisp; - } - else - { - vlib_buffer_advance (b0, - -(word) (sizeof (udp_header_t) + - sizeof (ip6_header_t))); - vlib_buffer_advance (b1, - -(word) (sizeof (udp_header_t) + - sizeof (ip6_header_t))); - - iul6_0 = vlib_buffer_get_current (b0); - iul6_1 = vlib_buffer_get_current (b1); - - /* pop (ip, udp, lisp-gpe) */ - vlib_buffer_advance (b0, sizeof (*iul6_0)); - vlib_buffer_advance (b1, sizeof (*iul6_1)); - - lh0 = &iul6_0->lisp; - lh1 = &iul6_1->lisp; - } - - /* determine next_index from lisp-gpe header */ - next0 = next_protocol_to_next_index (lh0, - vlib_buffer_get_current (b0)); - next1 = next_protocol_to_next_index (lh1, - vlib_buffer_get_current (b1)); - - /* determine if tunnel is l2 or l3 */ - tl0 = next_index_to_iface (lgm, next0); - tl1 = next_index_to_iface (lgm, next1); - - /* map iid/vni to lisp-gpe sw_if_index which is used by ipx_input to - * decide the rx vrf and the input features to be applied */ - si0 = hash_get (tl0->sw_if_index_by_vni, - clib_net_to_host_u32 (lh0->iid << 8)); - si1 = hash_get (tl1->sw_if_index_by_vni, - clib_net_to_host_u32 (lh1->iid << 8)); - - - /* Required to make the l2 tag push / pop code work on l2 subifs */ - vnet_update_l2_len (b0); - vnet_update_l2_len (b1); - - if (si0) - { - incr_decap_stats (lgm->vnet_main, thread_index, - vlib_buffer_length_in_chain (vm, b0), si0[0], - &last_sw_if_index, &n_packets, &n_bytes); - vnet_buffer (b0)->sw_if_index[VLIB_RX] = si0[0]; - error0 = 0; - } - else - { - next0 = LISP_GPE_INPUT_NEXT_DROP; - error0 = LISP_GPE_ERROR_NO_TUNNEL; - drops++; - } - - if (si1) - { - incr_decap_stats (lgm->vnet_main, thread_index, - vlib_buffer_length_in_chain (vm, b1), si1[0], - &last_sw_if_index, &n_packets, &n_bytes); - vnet_buffer (b1)->sw_if_index[VLIB_RX] = si1[0]; - error1 = 0; - } - else - { - next1 = LISP_GPE_INPUT_NEXT_DROP; - error1 = LISP_GPE_ERROR_NO_TUNNEL; - drops++; - } - - b0->error = error0 ? node->errors[error0] : 0; - b1->error = error1 ? node->errors[error1] : 0; - - if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) - { - lisp_gpe_rx_trace_t *tr = vlib_add_trace (vm, node, b0, - sizeof (*tr)); - tr->next_index = next0; - tr->error = error0; - tr->h = lh0[0]; - } - - if (PREDICT_FALSE (b1->flags & VLIB_BUFFER_IS_TRACED)) - { - lisp_gpe_rx_trace_t *tr = vlib_add_trace (vm, node, b1, - sizeof (*tr)); - tr->next_index = next1; - tr->error = error1; - tr->h = lh1[0]; - } - - vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next, - n_left_to_next, bi0, bi1, next0, - next1); - } - - while (n_left_from > 0 && n_left_to_next > 0) - { - u32 bi0; - vlib_buffer_t *b0; - u32 next0; - ip4_udp_lisp_gpe_header_t *iul4_0; - ip6_udp_lisp_gpe_header_t *iul6_0; - lisp_gpe_header_t *lh0; - u32 error0; - uword *si0; - tunnel_lookup_t *tl0; - - bi0 = from[0]; - to_next[0] = bi0; - from += 1; - to_next += 1; - n_left_from -= 1; - n_left_to_next -= 1; - - b0 = vlib_get_buffer (vm, bi0); - - /* udp leaves current_data pointing at the lisp header - * TODO: there's no difference in processing between v4 and v6 - * encapsulated packets so the code should be simplified if ip header - * info is not going to be used for dp smrs/dpsec */ - if (is_v4) - { - vlib_buffer_advance (b0, - -(word) (sizeof (udp_header_t) + - sizeof (ip4_header_t))); - - iul4_0 = vlib_buffer_get_current (b0); - - /* pop (ip, udp, lisp-gpe) */ - vlib_buffer_advance (b0, sizeof (*iul4_0)); - - lh0 = &iul4_0->lisp; - } - else - { - vlib_buffer_advance (b0, - -(word) (sizeof (udp_header_t) + - sizeof (ip6_header_t))); - - iul6_0 = vlib_buffer_get_current (b0); - - /* pop (ip, udp, lisp-gpe) */ - vlib_buffer_advance (b0, sizeof (*iul6_0)); - - lh0 = &iul6_0->lisp; - } - - /* TODO if security is to be implemented, something similar to RPF, - * probably we'd like to check that the peer is allowed to send us - * packets. For this, we should use the tunnel table OR check that - * we have a mapping for the source eid and that the outer source of - * the packet is one of its locators */ - - /* determine next_index from lisp-gpe header */ - next0 = next_protocol_to_next_index (lh0, - vlib_buffer_get_current (b0)); - - /* determine if tunnel is l2 or l3 */ - tl0 = next_index_to_iface (lgm, next0); - - /* map iid/vni to lisp-gpe sw_if_index which is used by ipx_input to - * decide the rx vrf and the input features to be applied. - * NOTE: vni uses only the first 24 bits */ - si0 = hash_get (tl0->sw_if_index_by_vni, - clib_net_to_host_u32 (lh0->iid << 8)); - - /* Required to make the l2 tag push / pop code work on l2 subifs */ - vnet_update_l2_len (b0); - - if (si0) - { - incr_decap_stats (lgm->vnet_main, thread_index, - vlib_buffer_length_in_chain (vm, b0), si0[0], - &last_sw_if_index, &n_packets, &n_bytes); - vnet_buffer (b0)->sw_if_index[VLIB_RX] = si0[0]; - error0 = 0; - } - else - { - next0 = LISP_GPE_INPUT_NEXT_DROP; - error0 = LISP_GPE_ERROR_NO_TUNNEL; - drops++; - } - - /* TODO error handling if security is implemented */ - b0->error = error0 ? node->errors[error0] : 0; - - if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) - { - lisp_gpe_rx_trace_t *tr = vlib_add_trace (vm, node, b0, - sizeof (*tr)); - tr->next_index = next0; - tr->error = error0; - tr->h = lh0[0]; - } - - vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, - n_left_to_next, bi0, next0); - } - - vlib_put_next_frame (vm, node, next_index, n_left_to_next); - } - - /* flush iface stats */ - incr_decap_stats (lgm->vnet_main, thread_index, 0, ~0, &last_sw_if_index, - &n_packets, &n_bytes); - vlib_node_increment_counter (vm, lisp_gpe_ip4_input_node.index, - LISP_GPE_ERROR_NO_TUNNEL, drops); - return from_frame->n_vectors; -} - -static uword -lisp_gpe_ip4_input (vlib_main_t * vm, vlib_node_runtime_t * node, - vlib_frame_t * from_frame) -{ - return lisp_gpe_input_inline (vm, node, from_frame, 1); -} - -static uword -lisp_gpe_ip6_input (vlib_main_t * vm, vlib_node_runtime_t * node, - vlib_frame_t * from_frame) -{ - return lisp_gpe_input_inline (vm, node, from_frame, 0); -} - -static char *lisp_gpe_ip4_input_error_strings[] = { -#define lisp_gpe_error(n,s) s, -#include -#undef lisp_gpe_error -}; - -/* *INDENT-OFF* */ -VLIB_REGISTER_NODE (lisp_gpe_ip4_input_node) = { - .function = lisp_gpe_ip4_input, - .name = "lisp-gpe-ip4-input", - /* Takes a vector of packets. */ - .vector_size = sizeof (u32), - .n_next_nodes = LISP_GPE_INPUT_N_NEXT, - .next_nodes = { -#define _(s,n) [LISP_GPE_INPUT_NEXT_##s] = n, - foreach_lisp_gpe_ip_input_next -#undef _ - }, - - .n_errors = ARRAY_LEN (lisp_gpe_ip4_input_error_strings), - .error_strings = lisp_gpe_ip4_input_error_strings, - - .format_buffer = format_lisp_gpe_header_with_length, - .format_trace = format_lisp_gpe_rx_trace, - // $$$$ .unformat_buffer = unformat_lisp_gpe_header, -}; -/* *INDENT-ON* */ - -/* *INDENT-OFF* */ -VLIB_REGISTER_NODE (lisp_gpe_ip6_input_node) = { - .function = lisp_gpe_ip6_input, - .name = "lisp-gpe-ip6-input", - /* Takes a vector of packets. */ - .vector_size = sizeof (u32), - .n_next_nodes = LISP_GPE_INPUT_N_NEXT, - .next_nodes = { -#define _(s,n) [LISP_GPE_INPUT_NEXT_##s] = n, - foreach_lisp_gpe_ip_input_next -#undef _ - }, - - .n_errors = ARRAY_LEN (lisp_gpe_ip4_input_error_strings), - .error_strings = lisp_gpe_ip4_input_error_strings, - - .format_buffer = format_lisp_gpe_header_with_length, - .format_trace = format_lisp_gpe_rx_trace, - // $$$$ .unformat_buffer = unformat_lisp_gpe_header, -}; -/* *INDENT-ON* */ - -/** - * Adds arc from lisp-gpe-input to nsh-input if nsh-input is available - */ -static void -gpe_add_arc_from_input_to_nsh () -{ - lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main (); - vlib_main_t *vm = lgm->vlib_main; - vlib_node_t *nsh_input; - - /* Arc already exists */ - if (next_proto_to_next_index[LISP_GPE_NEXT_PROTO_NSH] - != LISP_GPE_INPUT_NEXT_DROP) - return; - - /* Check if nsh-input is available */ - if ((nsh_input = vlib_get_node_by_name (vm, (u8 *) "nsh-input"))) - { - u32 slot4, slot6; - slot4 = vlib_node_add_next_with_slot (vm, lisp_gpe_ip4_input_node.index, - nsh_input->index, - LISP_GPE_NEXT_PROTO_NSH); - slot6 = vlib_node_add_next_with_slot (vm, lisp_gpe_ip6_input_node.index, - nsh_input->index, - LISP_GPE_NEXT_PROTO_NSH); - ASSERT (slot4 == slot6 && slot4 == LISP_GPE_INPUT_NEXT_NSH_INPUT); - - next_proto_to_next_index[LISP_GPE_NEXT_PROTO_NSH] = slot4; - } -} - -/** GPE decap init function. */ -clib_error_t * -gpe_decap_init (vlib_main_t * vm) -{ - clib_error_t *error = 0; - - if ((error = vlib_call_init_function (vm, lisp_gpe_init))) - return error; - - gpe_add_arc_from_input_to_nsh (); - return 0; -} - -static uword -lisp_gpe_nsh_placeholder_input (vlib_main_t * vm, vlib_node_runtime_t * node, - vlib_frame_t * from_frame) -{ - vlib_node_increment_counter (vm, node->node_index, 0, 1); - return from_frame->n_vectors; -} - -static char *lisp_gpe_nsh_placeholder_error_strings[] = { - "lisp gpe placeholder nsh decap", -}; - -/* *INDENT-OFF* */ -VLIB_REGISTER_NODE (lisp_gpe_nsh_placeholder_input_node) = { - .function = lisp_gpe_nsh_placeholder_input, - .name = "lisp-gpe-nsh-placeholder-input", - .vector_size = sizeof (u32), - .type = VLIB_NODE_TYPE_INTERNAL, - .n_next_nodes = 1, - - .n_errors = 1, - .error_strings = lisp_gpe_nsh_placeholder_error_strings, - - .next_nodes = { - [0] = "error-drop", - }, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_add_placeholder_nsh_node_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main (); - vlib_node_add_next (lgm->vlib_main, lisp_gpe_ip4_input_node.index, - lisp_gpe_nsh_placeholder_input_node.index); - next_proto_to_next_index[LISP_GPE_NEXT_PROTO_NSH] = - LISP_GPE_INPUT_NEXT_NSH_INPUT; - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (lisp_add_placeholder_nsh_node_command, static) = { - .path = "test one nsh add-placeholder-decap-node", - .function = lisp_add_placeholder_nsh_node_command_fn, -}; -/* *INDENT-ON* */ - -VLIB_INIT_FUNCTION (gpe_decap_init); - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/src/vnet/lisp-gpe/dir.dox b/src/vnet/lisp-gpe/dir.dox deleted file mode 100644 index afa6da9ab2c..00000000000 --- a/src/vnet/lisp-gpe/dir.dox +++ /dev/null @@ -1,26 +0,0 @@ -/* - * - * Copyright (c) 2013 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - @dir - @brief LISP-GPE code. - - An implementation of LISP-GPE as per: - rfc-6830 - draft-lewis-lisp-gpe-02 - - See file: rfc.txt - -*/ \ No newline at end of file diff --git a/src/vnet/lisp-gpe/interface.c b/src/vnet/lisp-gpe/interface.c deleted file mode 100644 index 1ccb53dda72..00000000000 --- a/src/vnet/lisp-gpe/interface.c +++ /dev/null @@ -1,945 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @file - * @brief Common utility functions for LISP-GPE interfaces. - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/** - * @brief The VLIB node arc/edge from the interface's TX node, to the L2 - * load-balanceing node. Which is where all packets go - */ -static uword l2_arc_to_lb; - -#define foreach_lisp_gpe_tx_next \ - _(DROP, "error-drop") \ - _(IP4_LOOKUP, "ip4-lookup") \ - _(IP6_LOOKUP, "ip6-lookup") - -typedef enum -{ -#define _(sym,str) LISP_GPE_TX_NEXT_##sym, - foreach_lisp_gpe_tx_next -#undef _ - LISP_GPE_TX_N_NEXT, -} lisp_gpe_tx_next_t; - -typedef struct -{ - u32 tunnel_index; -} lisp_gpe_tx_trace_t; - -u8 * -format_lisp_gpe_tx_trace (u8 * s, va_list * args) -{ - CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); - CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); - lisp_gpe_tx_trace_t *t = va_arg (*args, lisp_gpe_tx_trace_t *); - - s = format (s, "LISP-GPE-TX: tunnel %d", t->tunnel_index); - return s; -} - -#define is_v4_packet(_h) ((*(u8*) _h) & 0xF0) == 0x40 - -/** - * @brief LISP-GPE interface TX (encap) function. - * @node lisp_gpe_interface_tx - * - * The LISP-GPE interface TX (encap) function. - * - * Looks up the associated tunnel based on the adjacency hit in the SD FIB - * and if the tunnel is multihomed it uses the flow hash to determine - * sub-tunnel, and rewrite string, to be used to encapsulate the packet. - * - * @param[in] vm vlib_main_t corresponding to the current thread. - * @param[in] node vlib_node_runtime_t data for this node. - * @param[in] frame vlib_frame_t whose contents should be dispatched. - * - * @return number of vectors in frame. - */ -static uword -lisp_gpe_interface_tx (vlib_main_t * vm, vlib_node_runtime_t * node, - vlib_frame_t * from_frame) -{ - u32 n_left_from, next_index, *from, *to_next; - lisp_gpe_main_t *lgm = &lisp_gpe_main; - - from = vlib_frame_vector_args (from_frame); - n_left_from = from_frame->n_vectors; - - next_index = node->cached_next_index; - - while (n_left_from > 0) - { - u32 n_left_to_next; - - vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); - - while (n_left_from > 0 && n_left_to_next > 0) - { - u32 bi0, adj_index0, next0; - const ip_adjacency_t *adj0; - const dpo_id_t *dpo0; - vlib_buffer_t *b0; - u8 is_v4_0; - - bi0 = from[0]; - to_next[0] = bi0; - from += 1; - to_next += 1; - n_left_from -= 1; - n_left_to_next -= 1; - - b0 = vlib_get_buffer (vm, bi0); - - /* Fixup the checksum and len fields in the LISP tunnel encap - * that was applied at the midchain node */ - is_v4_0 = is_v4_packet (vlib_buffer_get_current (b0)); - ip_udp_fixup_one (lgm->vlib_main, b0, is_v4_0); - - /* Follow the DPO on which the midchain is stacked */ - adj_index0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX]; - adj0 = adj_get (adj_index0); - dpo0 = &adj0->sub_type.midchain.next_dpo; - next0 = dpo0->dpoi_next_node; - vnet_buffer (b0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index; - - if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) - { - lisp_gpe_tx_trace_t *tr = vlib_add_trace (vm, node, b0, - sizeof (*tr)); - tr->tunnel_index = adj_index0; - } - vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, - n_left_to_next, bi0, next0); - } - - vlib_put_next_frame (vm, node, next_index, n_left_to_next); - } - - return from_frame->n_vectors; -} - -static u8 * -format_lisp_gpe_name (u8 * s, va_list * args) -{ - u32 dev_instance = va_arg (*args, u32); - return format (s, "lisp_gpe%d", dev_instance); -} - -/* *INDENT-OFF* */ -VNET_DEVICE_CLASS (lisp_gpe_device_class) = { - .name = "LISP_GPE", - .format_device_name = format_lisp_gpe_name, - .format_tx_trace = format_lisp_gpe_tx_trace, - .tx_function = lisp_gpe_interface_tx, -}; -/* *INDENT-ON* */ - -u8 * -format_lisp_gpe_header_with_length (u8 * s, va_list * args) -{ - lisp_gpe_header_t *h = va_arg (*args, lisp_gpe_header_t *); - u32 max_header_bytes = va_arg (*args, u32); - u32 header_bytes; - - header_bytes = sizeof (h[0]); - if (max_header_bytes != 0 && header_bytes > max_header_bytes) - return format (s, "lisp-gpe header truncated"); - - s = format (s, "flags: "); -#define _(n,v) if (h->flags & v) s = format (s, "%s ", #n); - foreach_lisp_gpe_flag_bit; -#undef _ - - s = format (s, "\n ver_res %d res %d next_protocol %d iid %d(%x)", - h->ver_res, h->res, h->next_protocol, - clib_net_to_host_u32 (h->iid << 8), - clib_net_to_host_u32 (h->iid << 8)); - return s; -} - -/* *INDENT-OFF* */ -VNET_HW_INTERFACE_CLASS (lisp_gpe_hw_class) = { - .name = "LISP_GPE", - .format_header = format_lisp_gpe_header_with_length, - .build_rewrite = lisp_gpe_build_rewrite, - .update_adjacency = lisp_gpe_update_adjacency, -}; -/* *INDENT-ON* */ - - -typedef struct -{ - u32 dpo_index; -} l2_lisp_gpe_tx_trace_t; - -static u8 * -format_l2_lisp_gpe_tx_trace (u8 * s, va_list * args) -{ - CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); - CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); - l2_lisp_gpe_tx_trace_t *t = va_arg (*args, l2_lisp_gpe_tx_trace_t *); - - s = format (s, "L2-LISP-GPE-TX: load-balance %d", t->dpo_index); - return s; -} - -/** - * @brief LISP-GPE interface TX (encap) function for L2 overlays. - * @node l2_lisp_gpe_interface_tx - * - * The L2 LISP-GPE interface TX (encap) function. - * - * Uses bridge domain index, source and destination ethernet addresses to - * lookup tunnel. If the tunnel is multihomed a flow has is used to determine - * the sub-tunnel and therefore the rewrite string to be used to encapsulate - * the packets. - * - * @param[in] vm vlib_main_t corresponding to the current thread. - * @param[in] node vlib_node_runtime_t data for this node. - * @param[in] frame vlib_frame_t whose contents should be dispatched. - * - * @return number of vectors in frame. - */ -static uword -l2_lisp_gpe_interface_tx (vlib_main_t * vm, vlib_node_runtime_t * node, - vlib_frame_t * from_frame) -{ - u32 n_left_from, next_index, *from, *to_next; - lisp_gpe_main_t *lgm = &lisp_gpe_main; - u32 thread_index = vm->thread_index; - vlib_combined_counter_main_t *cm = &load_balance_main.lbm_to_counters; - - from = vlib_frame_vector_args (from_frame); - n_left_from = from_frame->n_vectors; - - next_index = node->cached_next_index; - - while (n_left_from > 0) - { - u32 n_left_to_next; - - vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); - - while (n_left_from > 0 && n_left_to_next > 0) - { - vlib_buffer_t *b0; - u32 bi0, lbi0; - ethernet_header_t *e0; - - bi0 = from[0]; - to_next[0] = bi0; - from += 1; - to_next += 1; - n_left_from -= 1; - n_left_to_next -= 1; - - b0 = vlib_get_buffer (vm, bi0); - e0 = vlib_buffer_get_current (b0); - - vnet_buffer (b0)->lisp.overlay_afi = LISP_AFI_MAC; - - /* lookup dst + src mac */ - lbi0 = lisp_l2_fib_lookup (lgm, vnet_buffer (b0)->l2.bd_index, - e0->src_address, e0->dst_address); - vnet_buffer (b0)->ip.adj_index[VLIB_TX] = lbi0; - - vlib_increment_combined_counter (cm, thread_index, lbi0, 1, - vlib_buffer_length_in_chain (vm, - b0)); - if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) - { - l2_lisp_gpe_tx_trace_t *tr = vlib_add_trace (vm, node, b0, - sizeof (*tr)); - tr->dpo_index = lbi0; - } - vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, - n_left_to_next, bi0, l2_arc_to_lb); - } - - vlib_put_next_frame (vm, node, next_index, n_left_to_next); - } - - return from_frame->n_vectors; -} - -static u8 * -format_l2_lisp_gpe_name (u8 * s, va_list * args) -{ - u32 dev_instance = va_arg (*args, u32); - return format (s, "l2_lisp_gpe%d", dev_instance); -} - -/* *INDENT-OFF* */ -VNET_DEVICE_CLASS (l2_lisp_gpe_device_class,static) = { - .name = "L2_LISP_GPE", - .format_device_name = format_l2_lisp_gpe_name, - .format_tx_trace = format_l2_lisp_gpe_tx_trace, - .tx_function = l2_lisp_gpe_interface_tx, -}; -/* *INDENT-ON* */ - -typedef struct -{ - u32 dpo_index; -} nsh_lisp_gpe_tx_trace_t; - -u8 * -format_nsh_lisp_gpe_tx_trace (u8 * s, va_list * args) -{ - CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); - CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); - nsh_lisp_gpe_tx_trace_t *t = va_arg (*args, nsh_lisp_gpe_tx_trace_t *); - - s = format (s, "NSH-GPE-TX: tunnel %d", t->dpo_index); - return s; -} - -/** - * @brief LISP-GPE interface TX for NSH overlays. - * @node nsh_lisp_gpe_interface_tx - * - * The NSH LISP-GPE interface TX function. - * - * @param[in] vm vlib_main_t corresponding to the current thread. - * @param[in] node vlib_node_runtime_t data for this node. - * @param[in] frame vlib_frame_t whose contents should be dispatched. - * - * @return number of vectors in frame. - */ -static uword -nsh_lisp_gpe_interface_tx (vlib_main_t * vm, vlib_node_runtime_t * node, - vlib_frame_t * from_frame) -{ - u32 n_left_from, next_index, *from, *to_next; - lisp_gpe_main_t *lgm = &lisp_gpe_main; - - from = vlib_frame_vector_args (from_frame); - n_left_from = from_frame->n_vectors; - - next_index = node->cached_next_index; - - while (n_left_from > 0) - { - u32 n_left_to_next; - - vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); - - while (n_left_from > 0 && n_left_to_next > 0) - { - vlib_buffer_t *b0; - u32 bi0; - u32 *nsh0, next0; - const dpo_id_t *dpo0; - - bi0 = from[0]; - to_next[0] = bi0; - from += 1; - to_next += 1; - n_left_from -= 1; - n_left_to_next -= 1; - - b0 = vlib_get_buffer (vm, bi0); - nsh0 = vlib_buffer_get_current (b0); - - vnet_buffer (b0)->lisp.overlay_afi = LISP_AFI_LCAF; - - /* lookup SPI + SI (second word of the NSH header). - * NB: Load balancing was done by the control plane */ - dpo0 = lisp_nsh_fib_lookup (lgm, nsh0[1]); - - next0 = dpo0->dpoi_next_node; - vnet_buffer (b0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index; - - if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) - { - nsh_lisp_gpe_tx_trace_t *tr = vlib_add_trace (vm, node, b0, - sizeof (*tr)); - tr->dpo_index = dpo0->dpoi_index; - } - vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, - n_left_to_next, bi0, next0); - } - - vlib_put_next_frame (vm, node, next_index, n_left_to_next); - } - - return from_frame->n_vectors; -} - -static u8 * -format_nsh_lisp_gpe_name (u8 * s, va_list * args) -{ - u32 dev_instance = va_arg (*args, u32); - return format (s, "nsh_lisp_gpe%d", dev_instance); -} - -/* *INDENT-OFF* */ -VNET_DEVICE_CLASS (nsh_lisp_gpe_device_class,static) = { - .name = "NSH_LISP_GPE", - .format_device_name = format_nsh_lisp_gpe_name, - .format_tx_trace = format_nsh_lisp_gpe_tx_trace, - .tx_function = nsh_lisp_gpe_interface_tx, -}; -/* *INDENT-ON* */ - -static vnet_hw_interface_t * -lisp_gpe_create_iface (lisp_gpe_main_t * lgm, u32 vni, u32 dp_table, - vnet_device_class_t * dev_class, - tunnel_lookup_t * tuns) -{ - u32 flen; - u32 hw_if_index = ~0; - u8 *new_name; - vnet_hw_interface_t *hi; - vnet_main_t *vnm = lgm->vnet_main; - - /* create hw lisp_gpeX iface if needed, otherwise reuse existing */ - flen = vec_len (lgm->free_tunnel_hw_if_indices); - if (flen > 0) - { - hw_if_index = lgm->free_tunnel_hw_if_indices[flen - 1]; - _vec_len (lgm->free_tunnel_hw_if_indices) -= 1; - - hi = vnet_get_hw_interface (vnm, hw_if_index); - - /* rename interface */ - new_name = format (0, "%U", dev_class->format_device_name, vni); - - vec_add1 (new_name, 0); - vnet_rename_interface (vnm, hw_if_index, (char *) new_name); - vec_free (new_name); - - /* clear old stats of freed interface before reuse */ - vnet_interface_main_t *im = &vnm->interface_main; - vnet_interface_counter_lock (im); - vlib_zero_combined_counter (&im->combined_sw_if_counters - [VNET_INTERFACE_COUNTER_TX], - hi->sw_if_index); - vlib_zero_combined_counter (&im->combined_sw_if_counters - [VNET_INTERFACE_COUNTER_RX], - hi->sw_if_index); - vlib_zero_simple_counter (&im->sw_if_counters - [VNET_INTERFACE_COUNTER_DROP], - hi->sw_if_index); - vnet_interface_counter_unlock (im); - } - else - { - hw_if_index = vnet_register_interface (vnm, dev_class->index, vni, - lisp_gpe_hw_class.index, 0); - hi = vnet_get_hw_interface (vnm, hw_if_index); - } - - hash_set (tuns->hw_if_index_by_dp_table, dp_table, hw_if_index); - - /* set tunnel termination: post decap, packets are tagged as having been - * originated by lisp-gpe interface */ - hash_set (tuns->sw_if_index_by_vni, vni, hi->sw_if_index); - hash_set (tuns->vni_by_sw_if_index, hi->sw_if_index, vni); - - return hi; -} - -static void -lisp_gpe_remove_iface (lisp_gpe_main_t * lgm, u32 hi_index, u32 dp_table, - tunnel_lookup_t * tuns) -{ - vnet_main_t *vnm = lgm->vnet_main; - vnet_hw_interface_t *hi; - uword *vnip; - - hi = vnet_get_hw_interface (vnm, hi_index); - - /* disable interface */ - vnet_sw_interface_set_flags (vnm, hi->sw_if_index, 0 /* down */ ); - vnet_hw_interface_set_flags (vnm, hi->hw_if_index, 0 /* down */ ); - hash_unset (tuns->hw_if_index_by_dp_table, dp_table); - vec_add1 (lgm->free_tunnel_hw_if_indices, hi->hw_if_index); - - /* clean tunnel termination and vni to sw_if_index binding */ - vnip = hash_get (tuns->vni_by_sw_if_index, hi->sw_if_index); - if (0 == vnip) - { - clib_warning ("No vni associated to interface %d", hi->sw_if_index); - return; - } - hash_unset (tuns->sw_if_index_by_vni, vnip[0]); - hash_unset (tuns->vni_by_sw_if_index, hi->sw_if_index); -} - -static void -lisp_gpe_iface_set_table (u32 sw_if_index, u32 table_id) -{ - fib_node_index_t fib_index; - - fib_index = fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP4, table_id, - FIB_SOURCE_LISP); - vec_validate (ip4_main.fib_index_by_sw_if_index, sw_if_index); - ip4_main.fib_index_by_sw_if_index[sw_if_index] = fib_index; - ip4_sw_interface_enable_disable (sw_if_index, 1); - - fib_index = fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP6, table_id, - FIB_SOURCE_LISP); - vec_validate (ip6_main.fib_index_by_sw_if_index, sw_if_index); - ip6_main.fib_index_by_sw_if_index[sw_if_index] = fib_index; - ip6_sw_interface_enable_disable (sw_if_index, 1); -} - -static void -lisp_gpe_tenant_del_default_routes (u32 table_id) -{ - fib_protocol_t proto; - - FOR_EACH_FIB_IP_PROTOCOL (proto) - { - fib_prefix_t prefix = { - .fp_proto = proto, - }; - u32 fib_index; - - fib_index = fib_table_find (prefix.fp_proto, table_id); - fib_table_entry_special_remove (fib_index, &prefix, FIB_SOURCE_LISP); - fib_table_unlock (fib_index, prefix.fp_proto, FIB_SOURCE_LISP); - } -} - -static void -lisp_gpe_tenant_add_default_routes (u32 table_id) -{ - fib_protocol_t proto; - - FOR_EACH_FIB_IP_PROTOCOL (proto) - { - fib_prefix_t prefix = { - .fp_proto = proto, - }; - u32 fib_index; - - /* - * Add a deafult route that results in a control plane punt DPO - */ - fib_index = fib_table_find_or_create_and_lock (prefix.fp_proto, table_id, - FIB_SOURCE_LISP); - fib_table_entry_special_dpo_add (fib_index, &prefix, FIB_SOURCE_LISP, - FIB_ENTRY_FLAG_EXCLUSIVE, - lisp_cp_dpo_get (fib_proto_to_dpo - (proto))); - } -} - - -/** - * @brief Add/del LISP-GPE L3 interface. - * - * Creates LISP-GPE interface, sets ingress arcs from lisp_gpeX_lookup, - * installs default routes that attract all traffic with no more specific - * routes to lgpe-ipx-lookup, set egress arcs to ipx-lookup, sets - * the interface in the right vrf and enables it. - * - * @param[in] lgm Reference to @ref lisp_gpe_main_t. - * @param[in] a Parameters to create interface. - * - * @return number of vectors in frame. - */ -u32 -lisp_gpe_add_l3_iface (lisp_gpe_main_t * lgm, u32 vni, u32 table_id, - u8 with_default_routes) -{ - vnet_main_t *vnm = lgm->vnet_main; - tunnel_lookup_t *l3_ifaces = &lgm->l3_ifaces; - vnet_hw_interface_t *hi; - uword *hip, *si; - - hip = hash_get (l3_ifaces->hw_if_index_by_dp_table, table_id); - - if (hip) - { - clib_warning ("vrf %d already mapped to a vni", table_id); - return ~0; - } - - si = hash_get (l3_ifaces->sw_if_index_by_vni, vni); - - if (si) - { - clib_warning ("Interface for vni %d already exists", vni); - } - - /* create lisp iface and populate tunnel tables */ - hi = lisp_gpe_create_iface (lgm, vni, table_id, - &lisp_gpe_device_class, l3_ifaces); - - /* insert default routes that point to lisp-cp lookup */ - lisp_gpe_iface_set_table (hi->sw_if_index, table_id); - if (with_default_routes) - lisp_gpe_tenant_add_default_routes (table_id); - - /* enable interface */ - vnet_sw_interface_set_flags (vnm, hi->sw_if_index, - VNET_SW_INTERFACE_FLAG_ADMIN_UP); - vnet_hw_interface_set_flags (vnm, hi->hw_if_index, - VNET_HW_INTERFACE_FLAG_LINK_UP); - - return (hi->sw_if_index); -} - -void -lisp_gpe_del_l3_iface (lisp_gpe_main_t * lgm, u32 vni, u32 table_id) -{ - vnet_main_t *vnm = lgm->vnet_main; - tunnel_lookup_t *l3_ifaces = &lgm->l3_ifaces; - vnet_hw_interface_t *hi; - uword *hip; - - hip = hash_get (l3_ifaces->hw_if_index_by_dp_table, table_id); - - if (hip == 0) - { - clib_warning ("The interface for vrf %d doesn't exist", table_id); - return; - } - - hi = vnet_get_hw_interface (vnm, hip[0]); - - lisp_gpe_remove_iface (lgm, hip[0], table_id, &lgm->l3_ifaces); - - /* unset default routes */ - ip4_sw_interface_enable_disable (hi->sw_if_index, 0); - ip6_sw_interface_enable_disable (hi->sw_if_index, 0); - lisp_gpe_tenant_del_default_routes (table_id); -} - -/** - * @brief Add/del LISP-GPE L2 interface. - * - * Creates LISP-GPE interface, sets it in L2 mode in the appropriate - * bridge domain, sets egress arcs and enables it. - * - * @param[in] lgm Reference to @ref lisp_gpe_main_t. - * @param[in] a Parameters to create interface. - * - * @return number of vectors in frame. - */ -u32 -lisp_gpe_add_l2_iface (lisp_gpe_main_t * lgm, u32 vni, u32 bd_id) -{ - vnet_main_t *vnm = lgm->vnet_main; - tunnel_lookup_t *l2_ifaces = &lgm->l2_ifaces; - vnet_hw_interface_t *hi; - uword *hip, *si; - u16 bd_index; - - if (bd_id > L2_BD_ID_MAX) - { - clib_warning ("bridge domain ID %d exceed 16M limit", bd_id); - return ~0; - } - - bd_index = bd_find_or_add_bd_index (&bd_main, bd_id); - hip = hash_get (l2_ifaces->hw_if_index_by_dp_table, bd_index); - - if (hip) - { - clib_warning ("bridge domain %d already mapped to a vni", bd_id); - return ~0; - } - - si = hash_get (l2_ifaces->sw_if_index_by_vni, vni); - if (si) - { - clib_warning ("Interface for vni %d already exists", vni); - return ~0; - } - - /* create lisp iface and populate tunnel tables */ - hi = lisp_gpe_create_iface (lgm, vni, bd_index, - &l2_lisp_gpe_device_class, &lgm->l2_ifaces); - - /* enable interface */ - vnet_sw_interface_set_flags (vnm, hi->sw_if_index, - VNET_SW_INTERFACE_FLAG_ADMIN_UP); - vnet_hw_interface_set_flags (vnm, hi->hw_if_index, - VNET_HW_INTERFACE_FLAG_LINK_UP); - - l2_arc_to_lb = vlib_node_add_named_next (vlib_get_main (), - hi->tx_node_index, - "l2-load-balance"); - - /* we're ready. add iface to l2 bridge domain */ - set_int_l2_mode (lgm->vlib_main, vnm, MODE_L2_BRIDGE, hi->sw_if_index, - bd_index, L2_BD_PORT_TYPE_NORMAL, 0, 0); - - return (hi->sw_if_index); -} - -/** - * @brief Add/del LISP-GPE L2 interface. - * - * Creates LISP-GPE interface, sets it in L2 mode in the appropriate - * bridge domain, sets egress arcs and enables it. - * - * @param[in] lgm Reference to @ref lisp_gpe_main_t. - * @param[in] a Parameters to create interface. - * - * @return number of vectors in frame. - */ -void -lisp_gpe_del_l2_iface (lisp_gpe_main_t * lgm, u32 vni, u32 bd_id) -{ - tunnel_lookup_t *l2_ifaces = &lgm->l2_ifaces; - vnet_hw_interface_t *hi; - - u32 bd_index = bd_find_index (&bd_main, bd_id); - ASSERT (bd_index != ~0); - uword *hip = hash_get (l2_ifaces->hw_if_index_by_dp_table, bd_index); - - if (hip == 0) - { - clib_warning ("The interface for bridge domain %d doesn't exist", - bd_id); - return; - } - - /* Remove interface from bridge .. by enabling L3 mode */ - hi = vnet_get_hw_interface (lgm->vnet_main, hip[0]); - set_int_l2_mode (lgm->vlib_main, lgm->vnet_main, MODE_L3, hi->sw_if_index, - 0, L2_BD_PORT_TYPE_NORMAL, 0, 0); - lisp_gpe_remove_iface (lgm, hip[0], bd_index, &lgm->l2_ifaces); -} - -/** - * @brief Add LISP-GPE NSH interface. - * - * Creates LISP-GPE interface, sets it in L3 mode. - * - * @param[in] lgm Reference to @ref lisp_gpe_main_t. - * @param[in] a Parameters to create interface. - * - * @return sw_if_index. - */ -u32 -vnet_lisp_gpe_add_nsh_iface (lisp_gpe_main_t * lgm) -{ - vnet_main_t *vnm = lgm->vnet_main; - tunnel_lookup_t *nsh_ifaces = &lgm->nsh_ifaces; - vnet_hw_interface_t *hi; - uword *hip, *si; - - hip = hash_get (nsh_ifaces->hw_if_index_by_dp_table, 0); - - if (hip) - { - clib_warning ("NSH interface 0 already exists"); - return ~0; - } - - si = hash_get (nsh_ifaces->sw_if_index_by_vni, 0); - if (si) - { - clib_warning ("NSH interface already exists"); - return ~0; - } - - /* create lisp iface and populate tunnel tables */ - hi = lisp_gpe_create_iface (lgm, 0, 0, - &nsh_lisp_gpe_device_class, &lgm->nsh_ifaces); - - /* enable interface */ - vnet_sw_interface_set_flags (vnm, hi->sw_if_index, - VNET_SW_INTERFACE_FLAG_ADMIN_UP); - vnet_hw_interface_set_flags (vnm, hi->hw_if_index, - VNET_HW_INTERFACE_FLAG_LINK_UP); - - return (hi->sw_if_index); -} - -/** - * @brief Del LISP-GPE NSH interface. - * - */ -void -vnet_lisp_gpe_del_nsh_iface (lisp_gpe_main_t * lgm) -{ - tunnel_lookup_t *nsh_ifaces = &lgm->nsh_ifaces; - uword *hip; - - hip = hash_get (nsh_ifaces->hw_if_index_by_dp_table, 0); - - if (hip == 0) - { - clib_warning ("The NSH 0 interface doesn't exist"); - return; - } - lisp_gpe_remove_iface (lgm, hip[0], 0, &lgm->nsh_ifaces); -} - -static clib_error_t * -lisp_gpe_add_del_iface_command_fn (vlib_main_t * vm, unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - unformat_input_t _line_input, *line_input = &_line_input; - u8 is_add = 1; - u32 table_id, vni, bd_id; - u8 vni_is_set = 0, vrf_is_set = 0, bd_index_is_set = 0; - u8 nsh_iface = 0; - clib_error_t *error = NULL; - - if (vnet_lisp_gpe_enable_disable_status () == 0) - { - return clib_error_return (0, "LISP is disabled"); - } - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return 0; - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "add")) - is_add = 1; - else if (unformat (line_input, "del")) - is_add = 0; - else if (unformat (line_input, "vrf %d", &table_id)) - { - vrf_is_set = 1; - } - else if (unformat (line_input, "vni %d", &vni)) - { - vni_is_set = 1; - } - else if (unformat (line_input, "bd %d", &bd_id)) - { - bd_index_is_set = 1; - } - else if (unformat (line_input, "nsh")) - { - nsh_iface = 1; - } - else - { - error = clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); - goto done; - } - } - - if (nsh_iface) - { - if (is_add) - { - if (~0 == vnet_lisp_gpe_add_nsh_iface (&lisp_gpe_main)) - { - error = clib_error_return (0, "NSH interface not created"); - goto done; - } - } - else - { - vnet_lisp_gpe_del_nsh_iface (&lisp_gpe_main); - } - goto done; - } - - if (vrf_is_set && bd_index_is_set) - { - error = clib_error_return - (0, "Cannot set both vrf and brdige domain index!"); - goto done; - } - - if (!vni_is_set) - { - error = clib_error_return (0, "vni must be set!"); - goto done; - } - - if (!vrf_is_set && !bd_index_is_set) - { - error = - clib_error_return (0, "vrf or bridge domain index must be set!"); - goto done; - } - - if (bd_index_is_set) - { - if (is_add) - { - if (~0 == lisp_gpe_tenant_l2_iface_add_or_lock (vni, bd_id)) - { - error = clib_error_return (0, "L2 interface not created"); - goto done; - } - } - else - lisp_gpe_tenant_l2_iface_unlock (vni); - } - else - { - if (is_add) - { - if (~0 == lisp_gpe_tenant_l3_iface_add_or_lock (vni, table_id, 1 - /* with_default_route */ - )) - { - error = clib_error_return (0, "L3 interface not created"); - goto done; - } - } - else - lisp_gpe_tenant_l3_iface_unlock (vni); - } - -done: - unformat_free (line_input); - - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (add_del_lisp_gpe_iface_command, static) = { - .path = "gpe iface", - .short_help = "gpe iface add/del vni vrf ", - .function = lisp_gpe_add_del_iface_command_fn, -}; -/* *INDENT-ON* */ - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/src/vnet/lisp-gpe/lisp_gpe.api b/src/vnet/lisp-gpe/lisp_gpe.api deleted file mode 100644 index 6c751eabffb..00000000000 --- a/src/vnet/lisp-gpe/lisp_gpe.api +++ /dev/null @@ -1,237 +0,0 @@ -/* - * Copyright (c) 2015-2016 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -option version = "2.0.0"; - -import "vnet/interface_types.api"; -import "vnet/lisp-cp/lisp_types.api"; - -/** \brief GPE locator structure - @param is_ip4 - whether addr is IPv4 or v6 - @param weight - locator weight - @param addr - IPv4/6 address -*/ -typedef gpe_locator -{ - u8 weight; - vl_api_address_t addr; -}; - -/** \brief add or delete GPE tunnel - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param is_add - add address if non-zero, else delete - @param rmt_eid - remote eid - @param lcl_eid - local eid - @param vni - virtual network identifier - @param dp_table - vrf/bridge domain id - @param action - negative action when 0 locators configured - @param loc_num - number of locators - @param locs - array of remote locators -*/ -manual_print manual_endian define gpe_add_del_fwd_entry -{ - u32 client_index; - u32 context; - bool is_add [default=true]; - vl_api_eid_t rmt_eid; - vl_api_eid_t lcl_eid; - u32 vni; - u32 dp_table; - u8 action; - u32 loc_num; - vl_api_gpe_locator_t locs[loc_num]; -}; - -define gpe_add_del_fwd_entry_reply -{ - u32 context; - i32 retval; - u32 fwd_entry_index; -}; - -/** \brief enable or disable gpe protocol - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param is_enable [default=true] - enable protocol if non-zero, else disable -*/ -autoreply define gpe_enable_disable -{ - u32 client_index; - u32 context; - bool is_enable [default=true]; -}; - -/** \brief add or delete gpe_iface - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param is_add - add address if non-zero, else delete -*/ -autoreply define gpe_add_del_iface -{ - u32 client_index; - u32 context; - bool is_add [default=true]; - bool is_l2; - u32 dp_table; - u32 vni; -}; - -define gpe_fwd_entry_vnis_get -{ - u32 client_index; - u32 context; -}; - -manual_print manual_endian define gpe_fwd_entry_vnis_get_reply -{ - u32 context; - i32 retval; - u32 count; - u32 vnis[count]; -}; - -define gpe_fwd_entries_get -{ - u32 client_index; - u32 context; - u32 vni; -}; - -typedef gpe_fwd_entry -{ - u32 fwd_entry_index; - u32 dp_table; - vl_api_eid_t leid; - vl_api_eid_t reid; - u32 vni; - u8 action; -}; - -manual_print manual_endian define gpe_fwd_entries_get_reply -{ - u32 context; - i32 retval; - u32 count; - vl_api_gpe_fwd_entry_t entries[count]; -}; - -define gpe_fwd_entry_path_dump -{ - u32 client_index; - u32 context; - u32 fwd_entry_index; -}; - -manual_endian manual_print define gpe_fwd_entry_path_details -{ - u32 context; - vl_api_gpe_locator_t lcl_loc; - vl_api_gpe_locator_t rmt_loc; -}; - -/** \brief Set GPE encapsulation mode - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param mode - LISP (value 0) or VXLAN (value 1) -*/ -autoreply define gpe_set_encap_mode -{ - u32 client_index; - u32 context; - bool is_vxlan; -}; - -/** \brief get GPE encapsulation mode - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param mode - LISP (value 0) or VXLAN (value 1) -*/ -define gpe_get_encap_mode -{ - u32 client_index; - u32 context; -}; - -/** \brief Reply for set_encap_mode - @param context - returned sender context, to match reply w/ request - @param retval - return code - @param encap_mode - GPE encapsulation mode -*/ -define gpe_get_encap_mode_reply -{ - u32 context; - i32 retval; - /* FIXME: gpe encap enum */ - u8 encap_mode; -}; - -/** \brief Add native fwd rpath - @param context - returned sender context, to match reply w/ request - @param retval - return code - @param is_add - flag to indicate add or del - @param table_id - table id for route path - @param nh_sw_if_index - next-hop sw_if_index (~0 if not set) - @param is_ip4 - flag to indicate if nh is ip4 - @param nh_addr - next hop ip address -*/ -autoreply define gpe_add_del_native_fwd_rpath -{ - u32 client_index; - u32 context; - bool is_add [default=true]; - u32 table_id; - vl_api_interface_index_t nh_sw_if_index; - vl_api_address_t nh_addr; -}; - -/** \brief get GPE native fwd rpath - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request -*/ -define gpe_native_fwd_rpaths_get -{ - u32 client_index; - u32 context; - bool is_ip4; -}; - -/** \brief Reply for get native fwd rpath - @param context - returned sender context, to match reply w/ request - @param retval - return code - @param table_id - table id for route path - @param nh_sw_if_index - next-hop sw_if_index (~0 if not set) - @param nh_addr - next hop address -*/ -typedef gpe_native_fwd_rpath -{ - u32 fib_index; - vl_api_interface_index_t nh_sw_if_index; - vl_api_address_t nh_addr; -}; - -manual_print manual_endian define gpe_native_fwd_rpaths_get_reply -{ - u32 context; - i32 retval; - u32 count; - vl_api_gpe_native_fwd_rpath_t entries[count]; -}; - -/* - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/src/vnet/lisp-gpe/lisp_gpe.c b/src/vnet/lisp-gpe/lisp_gpe.c deleted file mode 100644 index c75ad6b87cd..00000000000 --- a/src/vnet/lisp-gpe/lisp_gpe.c +++ /dev/null @@ -1,728 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @file - * @brief Common utility functions for IPv4, IPv6 and L2 LISP-GPE tunnels. - * - */ - -#include -#include -#include -#include -#include -#include -#include - -/** LISP-GPE global state */ -lisp_gpe_main_t lisp_gpe_main; - - -/** CLI command to add/del forwarding entry. */ -static clib_error_t * -lisp_gpe_add_del_fwd_entry_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - unformat_input_t _line_input, *line_input = &_line_input; - u8 is_add = 1; - ip_address_t lloc, rloc; - clib_error_t *error = 0; - gid_address_t _reid, *reid = &_reid, _leid, *leid = &_leid; - u8 reid_set = 0, leid_set = 0, is_negative = 0, dp_table_set = 0, - vni_set = 0; - u32 vni = 0, dp_table = 0, action = ~0, w; - locator_pair_t pair, *pairs = 0; - int rv; - - clib_memset (leid, 0, sizeof (*leid)); - clib_memset (reid, 0, sizeof (*reid)); - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return 0; - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "del")) - is_add = 0; - else if (unformat (line_input, "add")) - is_add = 1; - else if (unformat (line_input, "leid %U", unformat_gid_address, leid)) - { - leid_set = 1; - } - else if (unformat (line_input, "reid %U", unformat_gid_address, reid)) - { - reid_set = 1; - } - else if (unformat (line_input, "vni %u", &vni)) - { - gid_address_vni (leid) = vni; - gid_address_vni (reid) = vni; - vni_set = 1; - } - else if (unformat (line_input, "vrf %u", &dp_table)) - { - dp_table_set = 1; - } - else if (unformat (line_input, "bd %u", &dp_table)) - { - dp_table_set = 1; - } - else if (unformat (line_input, "negative action %U", - unformat_negative_mapping_action, &action)) - { - is_negative = 1; - } - else if (unformat (line_input, "loc-pair %U %U w %d", - unformat_ip_address, &lloc, - unformat_ip_address, &rloc, &w)) - { - ip_address_copy (&pair.lcl_loc, &lloc); - ip_address_copy (&pair.rmt_loc, &rloc); - pair.weight = w; - pair.priority = 0; - vec_add1 (pairs, pair); - } - else - { - error = unformat_parse_error (line_input); - vlib_cli_output (vm, "parse error: '%U'", - format_unformat_error, line_input); - goto done; - } - } - - if (!reid_set) - { - vlib_cli_output (vm, "remote eid must be set!"); - goto done; - } - - if (gid_address_type (reid) != GID_ADDR_NSH && (!vni_set || !dp_table_set)) - { - vlib_cli_output (vm, "vni and vrf/bd must be set!"); - goto done; - } - - if (is_negative) - { - if (~0 == action) - { - vlib_cli_output (vm, "no action set for negative tunnel!"); - goto done; - } - } - else - { - if (vec_len (pairs) == 0) - { - vlib_cli_output (vm, "expected ip4/ip6 locators"); - goto done; - } - } - - if (!leid_set) - { - /* if leid not set, make sure it's the same AFI like reid */ - gid_address_type (leid) = gid_address_type (reid); - if (GID_ADDR_IP_PREFIX == gid_address_type (reid)) - gid_address_ip_version (leid) = gid_address_ip_version (reid); - } - - /* add fwd entry */ - vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a; - clib_memset (a, 0, sizeof (a[0])); - - a->is_add = is_add; - a->is_negative = is_negative; - a->vni = vni; - a->table_id = dp_table; - gid_address_copy (&a->lcl_eid, leid); - gid_address_copy (&a->rmt_eid, reid); - a->locator_pairs = pairs; - a->action = action; - - rv = vnet_lisp_gpe_add_del_fwd_entry (a, 0); - if (0 != rv) - { - vlib_cli_output (vm, "failed to %s gpe tunnel!", - is_add ? "add" : "delete"); - } - -done: - unformat_free (line_input); - vec_free (pairs); - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (lisp_gpe_add_del_fwd_entry_command, static) = { - .path = "gpe entry", - .short_help = "gpe entry add/del vni vrf/bd [leid ]" - "reid [loc-pair w ] " - "[negative action ]", - .function = lisp_gpe_add_del_fwd_entry_command_fn, -}; -/* *INDENT-ON* */ - -/** Check if LISP-GPE is enabled. */ -u8 -vnet_lisp_gpe_enable_disable_status (void) -{ - lisp_gpe_main_t *lgm = &lisp_gpe_main; - - return lgm->is_en; -} - -/** Enable/disable LISP-GPE. */ -clib_error_t * -vnet_lisp_gpe_enable_disable (vnet_lisp_gpe_enable_disable_args_t * a) -{ - lisp_gpe_main_t *lgm = &lisp_gpe_main; - vlib_main_t *vm = vlib_get_main (); - - if (a->is_en) - { - lgm->is_en = 1; - udp_register_dst_port (vm, UDP_DST_PORT_lisp_gpe, - lisp_gpe_ip4_input_node.index, 1 /* is_ip4 */ ); - udp_register_dst_port (vm, UDP_DST_PORT_lisp_gpe6, - lisp_gpe_ip6_input_node.index, 0 /* is_ip4 */ ); - } - else - { - /* remove all entries */ - vnet_lisp_gpe_fwd_entry_flush (); - - /* disable all l3 ifaces */ - lisp_gpe_tenant_flush (); - - udp_unregister_dst_port (vm, UDP_DST_PORT_lisp_gpe, 0 /* is_ip4 */ ); - udp_unregister_dst_port (vm, UDP_DST_PORT_lisp_gpe6, 1 /* is_ip4 */ ); - lgm->is_en = 0; - } - - return 0; -} - -/** Set GPE encapsulation mode. */ -int -vnet_gpe_set_encap_mode (gpe_encap_mode_t mode) -{ - lisp_gpe_main_t *lgm = &lisp_gpe_main; - - if (mode >= GPE_ENCAP_COUNT) - return VNET_API_ERROR_INVALID_GPE_MODE; - - if (pool_elts (lgm->lisp_fwd_entry_pool) != 0) - return VNET_API_ERROR_LISP_GPE_ENTRIES_PRESENT; - - lgm->encap_mode = mode; - return 0; -} - -/** CLI command to set GPE encap */ -static clib_error_t * -gpe_set_encap_mode_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - unformat_input_t _line_input, *line_input = &_line_input; - gpe_encap_mode_t mode = GPE_ENCAP_COUNT; - vnet_api_error_t rv; - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return 0; - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "lisp")) - mode = GPE_ENCAP_LISP; - else if (unformat (line_input, "vxlan")) - mode = GPE_ENCAP_VXLAN; - else - { - return clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); - } - } - rv = vnet_gpe_set_encap_mode (mode); - if (rv) - { - return clib_error_return (0, - "Error: invalid mode or GPE entries are present!"); - } - - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (gpe_set_encap_mode_command, static) = { - .path = "gpe encap", - .short_help = "gpe encap [lisp|vxlan]", - .function = gpe_set_encap_mode_command_fn, -}; -/* *INDENT-ON* */ - -/** Format GPE encap mode. */ -u8 * -format_vnet_gpe_encap_mode (u8 * s, va_list * args) -{ - lisp_gpe_main_t *lgm = &lisp_gpe_main; - - switch (lgm->encap_mode) - { - case GPE_ENCAP_LISP: - return format (s, "lisp"); - case GPE_ENCAP_VXLAN: - return format (s, "vxlan"); - default: - return 0; - } - return 0; -} - -/** CLI command to show GPE encap */ -static clib_error_t * -gpe_show_encap_mode_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - vlib_cli_output (vm, "encap mode: %U", format_vnet_gpe_encap_mode); - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (gpe_show_encap_mode_command, static) = { - .path = "show gpe encap", - .short_help = "show GPE encapulation mode", - .function = gpe_show_encap_mode_command_fn, -}; -/* *INDENT-ON* */ - -/** CLI command to enable/disable LISP-GPE. */ -static clib_error_t * -lisp_gpe_enable_disable_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - unformat_input_t _line_input, *line_input = &_line_input; - u8 is_en = 1; - vnet_lisp_gpe_enable_disable_args_t _a, *a = &_a; - clib_error_t *error = NULL; - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return clib_error_return (0, "expected enable | disable"); - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "enable")) - is_en = 1; - else if (unformat (line_input, "disable")) - is_en = 0; - else - { - error = clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); - goto done; - } - } - a->is_en = is_en; - error = vnet_lisp_gpe_enable_disable (a); - -done: - unformat_free (line_input); - - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (enable_disable_lisp_gpe_command, static) = { - .path = "gpe", - .short_help = "gpe [enable|disable]", - .function = lisp_gpe_enable_disable_command_fn, -}; -/* *INDENT-ON* */ - -/** CLI command to show LISP-GPE interfaces. */ -static clib_error_t * -lisp_show_iface_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - lisp_gpe_main_t *lgm = &lisp_gpe_main; - hash_pair_t *p; - - vlib_cli_output (vm, "%=10s%=12s", "vrf", "hw_if_index"); - - /* *INDENT-OFF* */ - hash_foreach_pair (p, lgm->l3_ifaces.hw_if_index_by_dp_table, ({ - vlib_cli_output (vm, "%=10d%=10d", p->key, p->value[0]); - })); - /* *INDENT-ON* */ - - if (0 != lgm->l2_ifaces.hw_if_index_by_dp_table) - { - vlib_cli_output (vm, "%=10s%=12s", "bd_id", "hw_if_index"); - /* *INDENT-OFF* */ - hash_foreach_pair (p, lgm->l2_ifaces.hw_if_index_by_dp_table, ({ - vlib_cli_output (vm, "%=10d%=10d", p->key, p->value[0]); - })); - /* *INDENT-ON* */ - } - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (lisp_show_iface_command) = { - .path = "show gpe interface", - .short_help = "show gpe interface", - .function = lisp_show_iface_command_fn, -}; -/* *INDENT-ON* */ - -/** CLI command to show GPE fwd native route path. */ -static clib_error_t * -gpe_show_native_fwd_rpath_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - lisp_gpe_main_t *lgm = &lisp_gpe_main; - fib_route_path_t *rpath; - - if (vec_len (lgm->native_fwd_rpath[AF_IP4])) - { - vec_foreach (rpath, lgm->native_fwd_rpath[AF_IP4]) - { - vlib_cli_output (vm, "nh: %U fib_index %u sw_if_index %u", - format_ip46_address, &rpath->frp_addr, - IP46_TYPE_IP4, rpath->frp_fib_index, - rpath->frp_sw_if_index); - } - } - if (vec_len (lgm->native_fwd_rpath[AF_IP6])) - { - vec_foreach (rpath, lgm->native_fwd_rpath[AF_IP6]) - { - vlib_cli_output (vm, "nh: %U fib_index %u sw_if_index %u", - format_ip46_address, &rpath->frp_addr, IP46_TYPE_IP6, - rpath->frp_fib_index, rpath->frp_sw_if_index); - } - } - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (gpe_show_native_fwd_rpath_command) = { - .path = "show gpe native-forward", - .short_help = "show gpe native-forward", - .function = gpe_show_native_fwd_rpath_command_fn, -}; -/* *INDENT-ON* */ - -void -gpe_update_native_fwd_path (u8 ip_version) -{ - lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main (); - lisp_gpe_fwd_entry_t *lfe; - fib_prefix_t fib_prefix; - u32 *lfei; - - vec_foreach (lfei, lgm->native_fwd_lfes[ip_version]) - { - lfe = pool_elt_at_index (lgm->lisp_fwd_entry_pool, lfei[0]); - ip_prefix_to_fib_prefix (&lfe->key->rmt.ippref, &fib_prefix); - fib_table_entry_update (lfe->eid_fib_index, &fib_prefix, FIB_SOURCE_LISP, - FIB_ENTRY_FLAG_NONE, - lgm->native_fwd_rpath[ip_version]); - } -} - -int -vnet_gpe_add_del_native_fwd_rpath (vnet_gpe_native_fwd_rpath_args_t * a) -{ - lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main (); - fib_route_path_t *rpath; - u8 ip_version; - - ip_version = a->rpath.frp_proto == DPO_PROTO_IP4 ? AF_IP4 : AF_IP6; - - if (a->is_add) - { - vec_add1 (lgm->native_fwd_rpath[ip_version], a->rpath); - } - else - { - vec_foreach (rpath, lgm->native_fwd_rpath[ip_version]) - { - if (!fib_route_path_cmp (rpath, &a->rpath)) - { - vec_del1 (lgm->native_fwd_rpath[ip_version], - rpath - lgm->native_fwd_rpath[ip_version]); - break; - } - } - } - gpe_update_native_fwd_path (ip_version); - return 0; -} - -/** - * CLI command to add action for native forward. - */ -static clib_error_t * -gpe_native_forward_command_fn (vlib_main_t * vm, unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - vnet_main_t *vnm = vnet_get_main (); - unformat_input_t _line_input, *line_input = &_line_input; - vnet_api_error_t rv; - fib_route_path_t rpath; - u32 table_id = ~0; - vnet_gpe_native_fwd_rpath_args_t _a, *a = &_a; - u8 is_add = 1; - clib_error_t *error = 0; - - /* Get a line of input. */ - if (!unformat_user (input, unformat_line_input, line_input)) - return 0; - - clib_memset (&rpath, 0, sizeof (rpath)); - - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (line_input, "table %d", &table_id)) - ; - else if (unformat (line_input, "del")) - is_add = 0; - else if (unformat (line_input, "via %U %U", - unformat_ip4_address, - &rpath.frp_addr.ip4, - unformat_vnet_sw_interface, vnm, - &rpath.frp_sw_if_index)) - { - rpath.frp_weight = 1; - rpath.frp_proto = DPO_PROTO_IP4; - } - else if (unformat (line_input, "via %U %U", - unformat_ip6_address, - &rpath.frp_addr.ip6, - unformat_vnet_sw_interface, vnm, - &rpath.frp_sw_if_index)) - { - rpath.frp_weight = 1; - rpath.frp_proto = DPO_PROTO_IP6; - } - else if (unformat (line_input, "via %U", - unformat_ip4_address, &rpath.frp_addr.ip4)) - { - rpath.frp_weight = 1; - rpath.frp_sw_if_index = ~0; - rpath.frp_proto = DPO_PROTO_IP4; - } - else if (unformat (line_input, "via %U", - unformat_ip6_address, &rpath.frp_addr.ip6)) - { - rpath.frp_weight = 1; - rpath.frp_sw_if_index = ~0; - rpath.frp_proto = DPO_PROTO_IP6; - } - else - { - return clib_error_return (0, "parse error: '%U'", - format_unformat_error, line_input); - } - } - - if ((u32) ~ 0 == table_id) - { - rpath.frp_fib_index = 0; - } - else - { - rpath.frp_fib_index = - fib_table_find (dpo_proto_to_fib (rpath.frp_proto), table_id); - if ((u32) ~ 0 == rpath.frp_fib_index) - { - error = clib_error_return (0, "Nonexistent table id %d", table_id); - goto done; - } - } - - a->rpath = rpath; - a->is_add = is_add; - - rv = vnet_gpe_add_del_native_fwd_rpath (a); - if (rv) - { - return clib_error_return (0, "Error: couldn't add path!"); - } - -done: - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (gpe_native_forward_command) = { - .path = "gpe native-forward", - .short_help = "gpe native-forward [del] via [iface] " - "[table
]", - .function = gpe_native_forward_command_fn, -}; -/* *INDENT-ON* */ - -/** Format LISP-GPE status. */ -u8 * -format_vnet_lisp_gpe_status (u8 * s, va_list * args) -{ - lisp_gpe_main_t *lgm = &lisp_gpe_main; - return format (s, "%s", lgm->is_en ? "enabled" : "disabled"); -} - -/** LISP-GPE init function. */ -clib_error_t * -lisp_gpe_init (vlib_main_t * vm) -{ - lisp_gpe_main_t *lgm = &lisp_gpe_main; - clib_error_t *error = 0; - - if ((error = vlib_call_init_function (vm, ip_main_init))) - return error; - - if ((error = vlib_call_init_function (vm, ip4_lookup_init))) - return error; - - lgm->vnet_main = vnet_get_main (); - lgm->vlib_main = vm; - lgm->im4 = &ip4_main; - lgm->im6 = &ip6_main; - lgm->lm4 = &ip4_main.lookup_main; - lgm->lm6 = &ip6_main.lookup_main; - lgm->encap_mode = GPE_ENCAP_LISP; - - lgm->lisp_gpe_fwd_entries = - hash_create_mem (0, sizeof (lisp_gpe_fwd_entry_key_t), sizeof (uword)); - - lgm->lisp_stats_index_by_key = - hash_create_mem (0, sizeof (lisp_stats_key_t), sizeof (uword)); - clib_memset (&lgm->counters, 0, sizeof (lgm->counters)); - lgm->counters.name = "LISP counters"; - - return 0; -} - -gpe_encap_mode_t -vnet_gpe_get_encap_mode (void) -{ - lisp_gpe_main_t *lgm = &lisp_gpe_main; - return lgm->encap_mode; -} - -static clib_error_t * -lisp_gpe_test_send_nsh_packet (u8 * file_name) -{ - vlib_frame_t *f; - vlib_buffer_t *b; - lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main (); - pcap_main_t pm; - clib_error_t *error = 0; - - if (!file_name) - return clib_error_create ("no pcap file specified!"); - - clib_memset (&pm, 0, sizeof (pm)); - pm.file_name = (char *) file_name; - error = pcap_read (&pm); - if (error) - return error; - - u32 bi; - if (vlib_buffer_alloc (lgm->vlib_main, &bi, 1) != 1) - return clib_error_create ("cannot allocate memory!"); - - b = vlib_get_buffer (lgm->vlib_main, bi); - tunnel_lookup_t *nsh_ifaces = &lgm->nsh_ifaces; - uword *hip; - vnet_hw_interface_t *hi; - - hip = hash_get (nsh_ifaces->hw_if_index_by_dp_table, 0); - if (hip == 0) - return clib_error_create ("The NSH 0 interface doesn't exist"); - - hi = vnet_get_hw_interface (lgm->vnet_main, hip[0]); - - vnet_buffer (b)->sw_if_index[VLIB_TX] = hi->sw_if_index; - u8 *p = vlib_buffer_put_uninit (b, vec_len (pm.packets_read[0])); - clib_memcpy_fast (p, pm.packets_read[0], vec_len (pm.packets_read[0])); - vlib_buffer_pull (b, sizeof (ethernet_header_t)); - - vlib_node_t *n = vlib_get_node_by_name (lgm->vlib_main, - (u8 *) "interface-tx"); - f = vlib_get_frame_to_node (lgm->vlib_main, n->index); - u32 *to_next = vlib_frame_vector_args (f); - to_next[0] = bi; - f->n_vectors = 1; - vlib_put_frame_to_node (lgm->vlib_main, n->index, f); - - return error; -} - -static clib_error_t * -lisp_test_nsh_command_fn (vlib_main_t * vm, unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - clib_error_t *error = 0; - u8 *file_name = 0; - - while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) - { - if (unformat (input, "pcap %v", &file_name)) - { - error = lisp_gpe_test_send_nsh_packet (file_name); - goto done; - } - else - { - error = clib_error_create ("unknown input `%U'", - format_unformat_error, input); - goto done; - } - } - -done: - return error; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (lisp_test_nsh_command, static) = { - .path = "test one nsh", - .short_help = "test gpe nsh pcap ", - .function = lisp_test_nsh_command_fn, -}; -/* *INDENT-ON* */ - -VLIB_INIT_FUNCTION (lisp_gpe_init); - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/src/vnet/lisp-gpe/lisp_gpe.h b/src/vnet/lisp-gpe/lisp_gpe.h deleted file mode 100644 index 3a3d0e9f4da..00000000000 --- a/src/vnet/lisp-gpe/lisp_gpe.h +++ /dev/null @@ -1,339 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @file - * @brief LISP-GPE definitions. - */ - -#ifndef included_vnet_lisp_gpe_h -#define included_vnet_lisp_gpe_h - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/** IP4-UDP-LISP encap header */ -/* *INDENT-OFF* */ -typedef CLIB_PACKED (struct { - ip4_header_t ip4; /* 20 bytes */ - udp_header_t udp; /* 8 bytes */ - lisp_gpe_header_t lisp; /* 8 bytes */ -}) ip4_udp_lisp_gpe_header_t; -/* *INDENT-ON* */ - -/** IP6-UDP-LISP encap header */ -/* *INDENT-OFF* */ -typedef CLIB_PACKED (struct { - ip6_header_t ip6; /* 40 bytes */ - udp_header_t udp; /* 8 bytes */ - lisp_gpe_header_t lisp; /* 8 bytes */ -}) ip6_udp_lisp_gpe_header_t; -/* *INDENT-ON* */ - -#define foreach_lisp_gpe_ip_input_next \ -_(DROP, "error-drop") \ -_(IP4_INPUT, "ip4-input") \ -_(IP6_INPUT, "ip6-input") \ -_(L2_INPUT, "l2-input") - -/** Enum of possible next nodes post LISP-GPE decap */ -typedef enum -{ -#define _(s,n) LISP_GPE_INPUT_NEXT_##s, - foreach_lisp_gpe_ip_input_next -#undef _ - LISP_GPE_INPUT_N_NEXT, -} lisp_gpe_input_next_t; - -/* Arc to nsh-input added only if nsh-input exists */ -#define LISP_GPE_INPUT_NEXT_NSH_INPUT 4 - -typedef enum -{ -#define lisp_gpe_error(n,s) LISP_GPE_ERROR_##n, -#include -#undef lisp_gpe_error - LISP_GPE_N_ERROR, -} lisp_gpe_error_t; - -typedef struct tunnel_lookup -{ - /** Lookup lisp-gpe interfaces by dp table (eg. vrf/bridge index) */ - uword *hw_if_index_by_dp_table; - - /** lookup decap tunnel termination sw_if_index by vni and vice versa */ - uword *sw_if_index_by_vni; - - // FIXME - Need this? - uword *vni_by_sw_if_index; -} tunnel_lookup_t; - -typedef struct -{ - u32 fwd_entry_index; - u32 tunnel_index; -} lisp_stats_key_t; - -typedef struct -{ - u32 vni; - dp_address_t deid; - dp_address_t seid; - ip_address_t loc_rloc; - ip_address_t rmt_rloc; - - vlib_counter_t counters; -} lisp_api_stats_t; - -typedef enum gpe_encap_mode_e -{ - GPE_ENCAP_LISP, - GPE_ENCAP_VXLAN, - GPE_ENCAP_COUNT -} gpe_encap_mode_t; - -/** LISP-GPE global state*/ -typedef struct lisp_gpe_main -{ - /** - * @brief DB of all forwarding entries. The Key is:{l-EID,r-EID,vni} - * where the EID encodes L2 or L3 - */ - uword *lisp_gpe_fwd_entries; - - /** - * @brief A Pool of all LISP forwarding entries - */ - struct lisp_gpe_fwd_entry_t_ *lisp_fwd_entry_pool; - - /** Free vlib hw_if_indices */ - u32 *free_tunnel_hw_if_indices; - - u8 is_en; - - /* L3 data structures - * ================== */ - tunnel_lookup_t l3_ifaces; - - /* L2 data structures - * ================== */ - - /** L2 LISP FIB */ - BVT (clib_bihash) l2_fib; - - tunnel_lookup_t l2_ifaces; - - /** Load-balance for a miss in the table */ - dpo_id_t l2_lb_cp_lkup; - - /* NSH data structures - * ================== */ - - BVT (clib_bihash) nsh_fib; - - tunnel_lookup_t nsh_ifaces; - - const dpo_id_t *nsh_cp_lkup; - - gpe_encap_mode_t encap_mode; - - u8 *placeholder_stats_pool; - uword *lisp_stats_index_by_key; - vlib_combined_counter_main_t counters; - - /** Native fwd data structures */ - fib_route_path_t *native_fwd_rpath[2]; - u32 *native_fwd_lfes[2]; - - /** convenience */ - vlib_main_t *vlib_main; - vnet_main_t *vnet_main; - ip4_main_t *im4; - ip6_main_t *im6; - ip_lookup_main_t *lm4; - ip_lookup_main_t *lm6; -} lisp_gpe_main_t; - -/** LISP-GPE global state*/ -extern lisp_gpe_main_t lisp_gpe_main; - -always_inline lisp_gpe_main_t * -vnet_lisp_gpe_get_main () -{ - return &lisp_gpe_main; -} - - -extern vlib_node_registration_t lisp_gpe_ip4_input_node; -extern vlib_node_registration_t lisp_gpe_ip6_input_node; -extern vnet_hw_interface_class_t lisp_gpe_hw_class; - -u8 *format_lisp_gpe_header_with_length (u8 * s, va_list * args); - -/** Read LISP-GPE status */ -u8 vnet_lisp_gpe_enable_disable_status (void); - -u32 -lisp_gpe_l3_iface_find_or_create (lisp_gpe_main_t * lgm, - u32 overlay_table_id, u32 vni); - -/** Add/del LISP-GPE interface. */ -extern void lisp_gpe_del_l2_iface (lisp_gpe_main_t * lgm, u32 vni, u32 bd_id); -extern u32 lisp_gpe_add_l2_iface (lisp_gpe_main_t * lgm, u32 vni, u32 bd_id); -extern void lisp_gpe_del_l3_iface (lisp_gpe_main_t * lgm, u32 vni, u32 bd_id); -extern u32 lisp_gpe_add_l3_iface (lisp_gpe_main_t * lgm, u32 vni, u32 bd_id, - u8 with_default_route); - - -typedef struct -{ - u8 is_en; -} vnet_lisp_gpe_enable_disable_args_t; - -clib_error_t - * vnet_lisp_gpe_enable_disable (vnet_lisp_gpe_enable_disable_args_t * a); - -typedef enum -{ - NO_ACTION, - FORWARD_NATIVE, - SEND_MAP_REQUEST, - DROP -} negative_fwd_actions_e; - -/** */ -typedef struct -{ - /** forwarding entry index of */ - u32 fwd_entry_index; - - u8 is_src_dst; - - u8 is_add; - - /** type of mapping */ - u8 is_negative; - - /** action for negative mappings */ - negative_fwd_actions_e action; - - /** local eid */ - gid_address_t lcl_eid; - - /** remote eid */ - gid_address_t rmt_eid; - - /** vector of locator pairs */ - locator_pair_t *locator_pairs; - - /** FIB index to lookup remote locator at encap */ - u32 encap_fib_index; - - /** FIB index to lookup inner IP at decap */ - u32 decap_fib_index; - - /* TODO remove */ - u32 decap_next_index; - - /** VNI/tenant id in HOST byte order */ - u32 vni; - - /** vrf or bd where fwd entry should be inserted */ - union - { - /** table (vrf) id */ - u32 table_id; - - /** bridge domain id */ - u32 bd_id; - - /** generic access */ - u32 dp_table; - }; -} vnet_lisp_gpe_add_del_fwd_entry_args_t; - -typedef struct -{ - fib_route_path_t rpath; - u8 is_add; -} vnet_gpe_native_fwd_rpath_args_t; - -typedef struct -{ - u32 fwd_entry_index; - u32 dp_table; - u32 vni; - u8 action; - dp_address_t leid; - dp_address_t reid; -} lisp_api_gpe_fwd_entry_t; - -#define foreach_lgpe_ip4_lookup_next \ - _(DROP, "error-drop") \ - _(LISP_CP_LOOKUP, "lisp-cp-lookup") - -typedef enum lgpe_ip4_lookup_next -{ -#define _(sym,str) LGPE_IP4_LOOKUP_NEXT_##sym, - foreach_lgpe_ip4_lookup_next -#undef _ - LGPE_IP4_LOOKUP_N_NEXT, -} lgpe_ip4_lookup_next_t; - -#define foreach_lgpe_ip6_lookup_next \ - _(DROP, "error-drop") \ - _(LISP_CP_LOOKUP, "lisp-cp-lookup") - -typedef enum lgpe_ip6_lookup_next -{ -#define _(sym,str) LGPE_IP6_LOOKUP_NEXT_##sym, - foreach_lgpe_ip6_lookup_next -#undef _ - LGPE_IP6_LOOKUP_N_NEXT, -} lgpe_ip6_lookup_next_t; - -u8 *format_vnet_lisp_gpe_status (u8 * s, va_list * args); - -lisp_api_gpe_fwd_entry_t *vnet_lisp_gpe_fwd_entries_get_by_vni (u32 vni); -gpe_encap_mode_t vnet_gpe_get_encap_mode (void); -int vnet_gpe_set_encap_mode (gpe_encap_mode_t mode); - -u8 vnet_lisp_stats_enable_disable_state (void); -vnet_api_error_t vnet_lisp_stats_enable_disable (u8 enable); -lisp_api_stats_t *vnet_lisp_get_stats (void); -int vnet_lisp_flush_stats (void); -int vnet_gpe_add_del_native_fwd_rpath (vnet_gpe_native_fwd_rpath_args_t * a); -u32 vnet_lisp_gpe_add_nsh_iface (lisp_gpe_main_t * lgm); -void vnet_lisp_gpe_del_nsh_iface (lisp_gpe_main_t * lgm); - -#endif /* included_vnet_lisp_gpe_h */ - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/src/vnet/lisp-gpe/lisp_gpe_adjacency.c b/src/vnet/lisp-gpe/lisp_gpe_adjacency.c deleted file mode 100644 index cd0b33857f5..00000000000 --- a/src/vnet/lisp-gpe/lisp_gpe_adjacency.c +++ /dev/null @@ -1,604 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @file - * @brief Common utility functions for IPv4, IPv6 and L2 LISP-GPE adjacencys. - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/** - * Memory pool of all adjacencies - */ -static lisp_gpe_adjacency_t *lisp_adj_pool; - -/** - * Hash table of all adjacencies. key:{nh, itf} - * We never have an all zeros address since the interfaces are multi-access, - * therefore there is no ambiguity between a v4 and v6 next-hop, so we don't - * need to add the protocol to the key. - */ -static -BVT (clib_bihash) - lisp_adj_db; - -#define LISP_ADJ_SET_KEY(_key, _itf, _nh) \ -{ \ - _key.key[0] = ip_addr_v6((_nh)).as_u64[0]; \ - _key.key[1] = ip_addr_v6((_nh)).as_u64[1]; \ - _key.key[2] = (_itf); \ -} - - static index_t lisp_adj_find (const ip_address_t * addr, u32 sw_if_index) -{ - BVT (clib_bihash_kv) kv; - - LISP_ADJ_SET_KEY (kv, sw_if_index, addr); - - if (BV (clib_bihash_search) (&lisp_adj_db, &kv, &kv) < 0) - { - return (INDEX_INVALID); - } - else - { - return (kv.value); - } -} - -static void -lisp_adj_insert (const ip_address_t * addr, u32 sw_if_index, index_t ai) -{ - BVT (clib_bihash_kv) kv; - - LISP_ADJ_SET_KEY (kv, sw_if_index, addr); - kv.value = ai; - - BV (clib_bihash_add_del) (&lisp_adj_db, &kv, 1); -} - -static void -lisp_adj_remove (const ip_address_t * addr, u32 sw_if_index) -{ - BVT (clib_bihash_kv) kv; - - LISP_ADJ_SET_KEY (kv, sw_if_index, addr); - - BV (clib_bihash_add_del) (&lisp_adj_db, &kv, 0); -} - -static lisp_gpe_adjacency_t * -lisp_gpe_adjacency_get_i (index_t lai) -{ - return (pool_elt_at_index (lisp_adj_pool, lai)); -} - -fib_forward_chain_type_t -lisp_gpe_adj_get_fib_chain_type (const lisp_gpe_adjacency_t * ladj) -{ - switch (ip_addr_version (&ladj->remote_rloc)) - { - case AF_IP4: - return (FIB_FORW_CHAIN_TYPE_UNICAST_IP4); - case AF_IP6: - return (FIB_FORW_CHAIN_TYPE_UNICAST_IP6); - default: - ASSERT (0); - break; - } - return (FIB_FORW_CHAIN_TYPE_UNICAST_IP4); -} - -static void -ip46_address_to_ip_address (const ip46_address_t * a, ip_address_t * b) -{ - if (ip46_address_is_ip4 (a)) - { - clib_memset (b, 0, sizeof (*b)); - ip_address_set (b, &a->ip4, AF_IP4); - } - else - { - ip_address_set (b, &a->ip6, AF_IP6); - } -} - -/** - * @brief Stack the tunnel's midchain on the IP forwarding chain of the via - */ -static void -lisp_gpe_adj_stack_one (lisp_gpe_adjacency_t * ladj, adj_index_t ai) -{ - const lisp_gpe_tunnel_t *lgt; - - lgt = lisp_gpe_tunnel_get (ladj->tunnel_index); - - adj_nbr_midchain_stack_on_fib_entry (ai, - lgt->fib_entry_index, - lisp_gpe_adj_get_fib_chain_type - (ladj)); -} - -/** - * @brief Call back when restacking all adjacencies on a GRE interface - */ -static adj_walk_rc_t -lisp_gpe_adj_walk_cb (adj_index_t ai, void *ctx) -{ - lisp_gpe_adjacency_t *ladj = ctx; - - lisp_gpe_adj_stack_one (ladj, ai); - - return (ADJ_WALK_RC_CONTINUE); -} - -static void -lisp_gpe_adj_stack (lisp_gpe_adjacency_t * ladj) -{ - fib_protocol_t nh_proto; - ip46_address_t nh; - - nh_proto = ip_address_to_46 (&ladj->remote_rloc, &nh); - - /* - * walk all the adjacencies on th lisp interface and restack them - */ - adj_nbr_walk_nh (ladj->sw_if_index, - nh_proto, &nh, lisp_gpe_adj_walk_cb, ladj); -} - -static lisp_gpe_next_protocol_e -lisp_gpe_adj_proto_from_vnet_link_type (vnet_link_t linkt) -{ - switch (linkt) - { - case VNET_LINK_IP4: - return (LISP_GPE_NEXT_PROTO_IP4); - case VNET_LINK_IP6: - return (LISP_GPE_NEXT_PROTO_IP6); - case VNET_LINK_ETHERNET: - return (LISP_GPE_NEXT_PROTO_ETHERNET); - case VNET_LINK_NSH: - return (LISP_GPE_NEXT_PROTO_NSH); - default: - ASSERT (0); - } - return (LISP_GPE_NEXT_PROTO_IP4); -} - -#define is_v4_packet(_h) ((*(u8*) _h) & 0xF0) == 0x40 - -static lisp_afi_e -lisp_afi_from_vnet_link_type (vnet_link_t link) -{ - switch (link) - { - case VNET_LINK_IP4: - return LISP_AFI_IP; - case VNET_LINK_IP6: - return LISP_AFI_IP6; - case VNET_LINK_ETHERNET: - return LISP_AFI_MAC; - default: - return LISP_AFI_NO_ADDR; - } -} - -static void -lisp_gpe_increment_stats_counters (lisp_cp_main_t * lcm, - const ip_adjacency_t * adj, - vlib_buffer_t * b) -{ - lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main (); - lisp_gpe_adjacency_t *ladj; - ip_address_t rloc; - index_t lai; - u32 si, di; - gid_address_t src, dst; - uword *feip; - - ip46_address_to_ip_address (&adj->sub_type.nbr.next_hop, &rloc); - si = vnet_buffer (b)->sw_if_index[VLIB_TX]; - lai = lisp_adj_find (&rloc, si); - ASSERT (INDEX_INVALID != lai); - - ladj = pool_elt_at_index (lisp_adj_pool, lai); - - u8 *lisp_data = (u8 *) vlib_buffer_get_current (b); - - /* skip IP header */ - if (is_v4_packet (lisp_data)) - lisp_data += sizeof (ip4_header_t); - else - lisp_data += sizeof (ip6_header_t); - - /* skip UDP header */ - lisp_data += sizeof (udp_header_t); - // TODO: skip TCP? - - /* skip LISP GPE header */ - lisp_data += sizeof (lisp_gpe_header_t); - - i16 saved_current_data = b->current_data; - b->current_data = lisp_data - b->data; - - lisp_afi_e afi = lisp_afi_from_vnet_link_type (adj->ia_link); - get_src_and_dst_eids_from_buffer (lcm, b, &src, &dst, afi); - b->current_data = saved_current_data; - di = gid_dictionary_sd_lookup (&lcm->mapping_index_by_gid, &dst, &src); - if (PREDICT_FALSE (~0 == di)) - { - clib_warning ("dst mapping not found (%U, %U)", format_gid_address, - &src, format_gid_address, &dst); - return; - } - - feip = hash_get (lcm->fwd_entry_by_mapping_index, di); - if (PREDICT_FALSE (!feip)) - return; - - lisp_stats_key_t key; - clib_memset (&key, 0, sizeof (key)); - key.fwd_entry_index = feip[0]; - key.tunnel_index = ladj->tunnel_index; - - uword *p = hash_get_mem (lgm->lisp_stats_index_by_key, &key); - ALWAYS_ASSERT (p); - - /* compute payload length starting after GPE */ - u32 bytes = b->current_length - (lisp_data - b->data - b->current_data); - vlib_increment_combined_counter (&lgm->counters, vlib_get_thread_index (), - p[0], 1, bytes); -} - -static void -lisp_gpe_fixup (vlib_main_t * vm, - const ip_adjacency_t * adj, - vlib_buffer_t * b, const void *data) -{ - lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); - - if (lcm->flags & LISP_FLAG_STATS_ENABLED) - lisp_gpe_increment_stats_counters (lcm, adj, b); - - /* Fixup the checksum and len fields in the LISP tunnel encap - * that was applied at the midchain node */ - ip_udp_fixup_one (vm, b, is_v4_packet (vlib_buffer_get_current (b))); -} - -/** - * @brief The LISP-GPE interface registered function to update, i.e. - * provide an rewrite string for, an adjacency. - */ -void -lisp_gpe_update_adjacency (vnet_main_t * vnm, u32 sw_if_index, adj_index_t ai) -{ - const lisp_gpe_tunnel_t *lgt; - lisp_gpe_adjacency_t *ladj; - ip_adjacency_t *adj; - ip_address_t rloc; - vnet_link_t linkt; - adj_flags_t af; - index_t lai; - - adj = adj_get (ai); - ip46_address_to_ip_address (&adj->sub_type.nbr.next_hop, &rloc); - - /* - * find an existing or create a new adj - */ - lai = lisp_adj_find (&rloc, sw_if_index); - - ASSERT (INDEX_INVALID != lai); - - ladj = pool_elt_at_index (lisp_adj_pool, lai); - lgt = lisp_gpe_tunnel_get (ladj->tunnel_index); - linkt = adj_get_link_type (ai); - af = ADJ_FLAG_MIDCHAIN_IP_STACK; - if (VNET_LINK_ETHERNET == linkt) - af |= ADJ_FLAG_MIDCHAIN_NO_COUNT; - - adj_nbr_midchain_update_rewrite - (ai, lisp_gpe_fixup, NULL, af, - lisp_gpe_tunnel_build_rewrite (lgt, ladj, - lisp_gpe_adj_proto_from_vnet_link_type - (linkt))); - - lisp_gpe_adj_stack_one (ladj, ai); -} - -u8 * -lisp_gpe_build_rewrite (vnet_main_t * vnm, - u32 sw_if_index, - vnet_link_t link_type, const void *dst_address) -{ - ASSERT (0); - return (NULL); -} - -index_t -lisp_gpe_adjacency_find_or_create_and_lock (const locator_pair_t * pair, - u32 overlay_table_id, u32 vni) -{ - const lisp_gpe_sub_interface_t *l3s; - const lisp_gpe_tunnel_t *lgt; - lisp_gpe_adjacency_t *ladj; - index_t lai, l3si; - - /* - * first find the L3 sub-interface that corresponds to the loacl-rloc and vni - */ - l3si = lisp_gpe_sub_interface_find_or_create_and_lock (&pair->lcl_loc, - overlay_table_id, - vni); - l3s = lisp_gpe_sub_interface_get (l3si); - - /* - * find an existing or create a new adj - */ - lai = lisp_adj_find (&pair->rmt_loc, l3s->sw_if_index); - - if (INDEX_INVALID == lai) - { - - pool_get (lisp_adj_pool, ladj); - clib_memset (ladj, 0, sizeof (*ladj)); - lai = (ladj - lisp_adj_pool); - - ip_address_copy (&ladj->remote_rloc, &pair->rmt_loc); - ladj->vni = vni; - /* transfer the lock to the adj */ - ladj->lisp_l3_sub_index = l3si; - ladj->sw_if_index = l3s->sw_if_index; - - /* if vni is non-default */ - if (ladj->vni) - ladj->flags = LISP_GPE_FLAGS_I; - - /* work in lisp-gpe not legacy mode */ - ladj->flags |= LISP_GPE_FLAGS_P; - - /* - * find the tunnel that will provide the underlying transport - * and hence the rewrite. - * The RLOC FIB index is default table - always. - */ - ladj->tunnel_index = lisp_gpe_tunnel_find_or_create_and_lock (pair, 0); - - lgt = lisp_gpe_tunnel_get (ladj->tunnel_index); - - /* - * become of child of the RLOC FIB entry so we are updated when - * its reachability changes, allowing us to re-stack the midcahins - */ - ladj->fib_entry_child_index = fib_entry_child_add (lgt->fib_entry_index, - FIB_NODE_TYPE_LISP_ADJ, - lai); - - lisp_adj_insert (&ladj->remote_rloc, ladj->sw_if_index, lai); - } - else - { - /* unlock the interface from the find. */ - lisp_gpe_sub_interface_unlock (l3si); - ladj = lisp_gpe_adjacency_get_i (lai); - } - - ladj->locks++; - - return (lai); -} - -/** - * @brief Get a pointer to a tunnel from a pointer to a FIB node - */ -static lisp_gpe_adjacency_t * -lisp_gpe_adjacency_from_fib_node (const fib_node_t * node) -{ - return ((lisp_gpe_adjacency_t *) - ((char *) node - - STRUCT_OFFSET_OF (lisp_gpe_adjacency_t, fib_node))); -} - -static void -lisp_gpe_adjacency_last_lock_gone (lisp_gpe_adjacency_t * ladj) -{ - const lisp_gpe_tunnel_t *lgt; - - /* - * no children so we are not counting locks. no-op. - * at least not counting - */ - lisp_adj_remove (&ladj->remote_rloc, ladj->sw_if_index); - - /* - * unlock the resources this adj holds - */ - lgt = lisp_gpe_tunnel_get (ladj->tunnel_index); - - fib_entry_child_remove (lgt->fib_entry_index, ladj->fib_entry_child_index); - - lisp_gpe_tunnel_unlock (ladj->tunnel_index); - lisp_gpe_sub_interface_unlock (ladj->lisp_l3_sub_index); - - pool_put (lisp_adj_pool, ladj); -} - -void -lisp_gpe_adjacency_unlock (index_t lai) -{ - lisp_gpe_adjacency_t *ladj; - - ladj = lisp_gpe_adjacency_get_i (lai); - - ladj->locks--; - - if (0 == ladj->locks) - { - lisp_gpe_adjacency_last_lock_gone (ladj); - } -} - -const lisp_gpe_adjacency_t * -lisp_gpe_adjacency_get (index_t lai) -{ - return (lisp_gpe_adjacency_get_i (lai)); -} - - -/** - * @brief LISP GPE tunnel back walk - * - * The FIB entry through which this tunnel resolves has been updated. - * re-stack the midchain on the new forwarding. - */ -static fib_node_back_walk_rc_t -lisp_gpe_adjacency_back_walk (fib_node_t * node, - fib_node_back_walk_ctx_t * ctx) -{ - lisp_gpe_adj_stack (lisp_gpe_adjacency_from_fib_node (node)); - - return (FIB_NODE_BACK_WALK_CONTINUE); -} - -static fib_node_t * -lisp_gpe_adjacency_get_fib_node (fib_node_index_t index) -{ - lisp_gpe_adjacency_t *ladj; - - ladj = pool_elt_at_index (lisp_adj_pool, index); - return (&ladj->fib_node); -} - -static void -lisp_gpe_adjacency_last_fib_lock_gone (fib_node_t * node) -{ - lisp_gpe_adjacency_last_lock_gone (lisp_gpe_adjacency_from_fib_node (node)); -} - -const static fib_node_vft_t lisp_gpe_tuennel_vft = { - .fnv_get = lisp_gpe_adjacency_get_fib_node, - .fnv_back_walk = lisp_gpe_adjacency_back_walk, - .fnv_last_lock = lisp_gpe_adjacency_last_fib_lock_gone, -}; - -u8 * -format_lisp_gpe_adjacency (u8 * s, va_list * args) -{ - lisp_gpe_adjacency_t *ladj = va_arg (*args, lisp_gpe_adjacency_t *); - lisp_gpe_adjacency_format_flags_t flags = - va_arg (*args, lisp_gpe_adjacency_format_flags_t); - - if (flags & LISP_GPE_ADJ_FORMAT_FLAG_DETAIL) - { - s = - format (s, "index %d locks:%d\n", ladj - lisp_adj_pool, ladj->locks); - } - - s = format (s, " vni: %d,", ladj->vni); - s = format (s, " remote-RLOC: %U,", format_ip_address, &ladj->remote_rloc); - - if (flags & LISP_GPE_ADJ_FORMAT_FLAG_DETAIL) - { - s = format (s, " %U\n", - format_lisp_gpe_sub_interface, - lisp_gpe_sub_interface_get (ladj->lisp_l3_sub_index)); - s = format (s, " %U\n", - format_lisp_gpe_tunnel, - lisp_gpe_tunnel_get (ladj->tunnel_index)); - } - else - { - s = format (s, " LISP L3 sub-interface index: %d,", - ladj->lisp_l3_sub_index); - s = format (s, " LISP tunnel index: %d", ladj->tunnel_index); - } - - - return (s); -} - -static clib_error_t * -lisp_gpe_adjacency_show (vlib_main_t * vm, - unformat_input_t * input, vlib_cli_command_t * cmd) -{ - lisp_gpe_adjacency_t *ladj; - index_t index; - - if (pool_elts (lisp_adj_pool) == 0) - vlib_cli_output (vm, "No lisp-gpe Adjacencies"); - - if (unformat (input, "%d", &index)) - { - ladj = lisp_gpe_adjacency_get_i (index); - vlib_cli_output (vm, "%U", format_lisp_gpe_adjacency, ladj, - LISP_GPE_ADJ_FORMAT_FLAG_DETAIL); - } - else - { - /* *INDENT-OFF* */ - pool_foreach (ladj, lisp_adj_pool, - ({ - vlib_cli_output (vm, "[%d] %U\n", - ladj - lisp_adj_pool, - format_lisp_gpe_adjacency, ladj, - LISP_GPE_ADJ_FORMAT_FLAG_NONE); - })); - /* *INDENT-ON* */ - } - - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (show_lisp_gpe_tunnel_command, static) = -{ - .path = "show gpe adjacency", - .function = lisp_gpe_adjacency_show, -}; -/* *INDENT-ON* */ - -#define LISP_ADJ_NBR_DEFAULT_HASH_NUM_BUCKETS (256) -#define LISP_ADJ_NBR_DEFAULT_HASH_MEMORY_SIZE (1<<20) - -static clib_error_t * -lisp_gpe_adj_module_init (vlib_main_t * vm) -{ - BV (clib_bihash_init) (&lisp_adj_db, - "Adjacency Neighbour table", - LISP_ADJ_NBR_DEFAULT_HASH_NUM_BUCKETS, - LISP_ADJ_NBR_DEFAULT_HASH_MEMORY_SIZE); - - fib_node_register_type (FIB_NODE_TYPE_LISP_ADJ, &lisp_gpe_tuennel_vft); - return (NULL); -} - -VLIB_INIT_FUNCTION (lisp_gpe_adj_module_init); -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/src/vnet/lisp-gpe/lisp_gpe_adjacency.h b/src/vnet/lisp-gpe/lisp_gpe_adjacency.h deleted file mode 100644 index adc3acaee3c..00000000000 --- a/src/vnet/lisp-gpe/lisp_gpe_adjacency.h +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @file - * @brief Common utility functions for IPv4, IPv6 and L2 LISP-GPE adjacencys. - * - */ - -#ifndef LISP_GPE_ADJACENCY_H__ -#define LISP_GPE_ADJACENCY_H__ - -#include -#include - -/** - * @brief A LISP GPE Adjacency. - * - * A adjacency represents peer on an L3 sub-interface to which to send traffic. - * adjacencies are thus present in the EID space. - * The peer is identified by the key:{remote-rloc, sub-interface}, which is - * equivalent to the usal adjacency key {next-hop, interface}. So curiously - * the rloc address from the underlay is used as a next hop address in the overlay - * This is OK because: - * 1 - the RLOC is unique in the underlay AND there is only one underlay VRF per - * overlay - * 2 - the RLOC may overlap with an address in the overlay, but we do not create - * an adj-fib (i.e. a route in the overlay FIB for the rloc) - * - * - */ -typedef struct lisp_gpe_adjacency_t_ -{ - /** - * The LISP adj is a part of the FIB control plane graph. - */ - fib_node_t fib_node; - - /** - * remote RLOC. The adjacency's next-hop - */ - ip_address_t remote_rloc; - - /** - * The VNI. Used in combination with the local-rloc to get the sub-interface - */ - u32 vni; - - /** - * The number of locks/reference counts on the adjacency. - */ - u32 locks; - - /** - * The index of the LISP L3 subinterface - */ - u32 lisp_l3_sub_index; - - /** - * The SW IF index of the sub-interface this adjacency uses. - * Cached for convenience from the LISP L3 sub-interface - */ - u32 sw_if_index; - - /** - * The index of the LISP GPE tunnel that provides the transport - * in the underlay. - */ - u32 tunnel_index; - - /** - * This adjacency is a child of the FIB entry to reach the RLOC. - * This is so when the reachability of that RLOC changes, we can restack - * the FIB adjacnecies. - */ - u32 fib_entry_child_index; - - /** - * LISP header fields in HOST byte order - */ - u8 flags; - u8 ver_res; - u8 res; - u8 next_protocol; - -} lisp_gpe_adjacency_t; - -extern index_t lisp_gpe_adjacency_find_or_create_and_lock (const - locator_pair_t * - pair, - u32 rloc_fib_index, - u32 vni); - -extern void lisp_gpe_adjacency_unlock (index_t l3si); - -extern const lisp_gpe_adjacency_t *lisp_gpe_adjacency_get (index_t l3si); - -extern void lisp_gpe_update_adjacency (vnet_main_t * vnm, - u32 sw_if_index, adj_index_t ai); -extern u8 *lisp_gpe_build_rewrite (vnet_main_t * vnm, - u32 sw_if_index, - vnet_link_t link_type, - const void *dst_address); - - -/** - * @brief Flags for displaying the adjacency - */ -typedef enum lisp_gpe_adjacency_format_flags_t_ -{ - LISP_GPE_ADJ_FORMAT_FLAG_NONE, - LISP_GPE_ADJ_FORMAT_FLAG_DETAIL, -} lisp_gpe_adjacency_format_flags_t; - -extern u8 *format_lisp_gpe_adjacency (u8 * s, va_list * args); - -#endif - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/src/vnet/lisp-gpe/lisp_gpe_api.c b/src/vnet/lisp-gpe/lisp_gpe_api.c deleted file mode 100644 index e20347a46f6..00000000000 --- a/src/vnet/lisp-gpe/lisp_gpe_api.c +++ /dev/null @@ -1,549 +0,0 @@ -/* - *------------------------------------------------------------------ - * lisp_gpe_api.c - lisp_gpe api - * - * Copyright (c) 2016 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------ - */ - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define vl_api_gpe_locator_pair_t_endian vl_noop_handler -#define vl_api_gpe_locator_pair_t_print vl_noop_handler -#define vl_api_gpe_add_del_fwd_entry_t_endian vl_noop_handler -#define vl_api_gpe_add_del_fwd_entry_t_print vl_noop_handler - -#define vl_typedefs /* define message structures */ -#include -#undef vl_typedefs - -#define vl_endianfun /* define message structures */ -#include -#undef vl_endianfun - -/* instantiate all the print functions we know about */ -#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) -#define vl_printfun -#include -#undef vl_printfun - -#include - -#define foreach_vpe_api_msg \ -_(GPE_ADD_DEL_FWD_ENTRY, gpe_add_del_fwd_entry) \ -_(GPE_FWD_ENTRIES_GET, gpe_fwd_entries_get) \ -_(GPE_FWD_ENTRY_PATH_DUMP, gpe_fwd_entry_path_dump) \ -_(GPE_ENABLE_DISABLE, gpe_enable_disable) \ -_(GPE_ADD_DEL_IFACE, gpe_add_del_iface) \ -_(GPE_FWD_ENTRY_VNIS_GET, gpe_fwd_entry_vnis_get) \ -_(GPE_SET_ENCAP_MODE, gpe_set_encap_mode) \ -_(GPE_GET_ENCAP_MODE, gpe_get_encap_mode) \ -_(GPE_ADD_DEL_NATIVE_FWD_RPATH, gpe_add_del_native_fwd_rpath) \ -_(GPE_NATIVE_FWD_RPATHS_GET, gpe_native_fwd_rpaths_get) - -static locator_pair_t * -unformat_gpe_loc_pairs (void *locs, u32 rloc_num) -{ - u32 i; - locator_pair_t *pairs = 0, pair, *p; - vl_api_gpe_locator_t *r; - - for (i = 0; i < rloc_num; i++) - { - /* local locator */ - r = &((vl_api_gpe_locator_t *) locs)[i]; - clib_memset (&pair, 0, sizeof (pair)); - ip_address_decode2 (&r->addr, &pair.lcl_loc); - - pair.weight = r->weight; - vec_add1 (pairs, pair); - } - - for (i = rloc_num; i < rloc_num * 2; i++) - { - /* remote locators */ - r = &((vl_api_gpe_locator_t *) locs)[i]; - p = &pairs[i - rloc_num]; - ip_address_decode2 (&r->addr, &p->rmt_loc); - } - return pairs; -} - -static void - gpe_fwd_entry_path_dump_t_net_to_host - (vl_api_gpe_fwd_entry_path_dump_t * mp) -{ - mp->fwd_entry_index = clib_net_to_host_u32 (mp->fwd_entry_index); -} - -static void -lisp_api_set_locator (vl_api_gpe_locator_t * loc, - const ip_address_t * addr, u8 weight) -{ - loc->weight = weight; - ip_address_encode2 (addr, &loc->addr); -} - -static void - vl_api_gpe_fwd_entry_path_dump_t_handler - (vl_api_gpe_fwd_entry_path_dump_t * mp) -{ - lisp_fwd_path_t *path; - vl_api_gpe_fwd_entry_path_details_t *rmp = NULL; - lisp_gpe_main_t *lgm = &lisp_gpe_main; - vl_api_registration_t *reg; - lisp_gpe_fwd_entry_t *lfe; - - gpe_fwd_entry_path_dump_t_net_to_host (mp); - - reg = vl_api_client_index_to_registration (mp->client_index); - if (!reg) - return; - - if (pool_is_free_index (lgm->lisp_fwd_entry_pool, mp->fwd_entry_index)) - return; - - lfe = pool_elt_at_index (lgm->lisp_fwd_entry_pool, mp->fwd_entry_index); - - if (LISP_GPE_FWD_ENTRY_TYPE_NEGATIVE == lfe->type) - return; - - vec_foreach (path, lfe->paths) - { - rmp = vl_msg_api_alloc (sizeof (*rmp)); - clib_memset (rmp, 0, sizeof (*rmp)); - const lisp_gpe_tunnel_t *lgt; - - rmp->_vl_msg_id = - clib_host_to_net_u16 (VL_API_GPE_FWD_ENTRY_PATH_DETAILS); - - const lisp_gpe_adjacency_t *ladj = - lisp_gpe_adjacency_get (path->lisp_adj); - lisp_api_set_locator (&rmp->rmt_loc, &ladj->remote_rloc, path->weight); - lgt = lisp_gpe_tunnel_get (ladj->tunnel_index); - lisp_api_set_locator (&rmp->lcl_loc, &lgt->key->lcl, path->weight); - - rmp->context = mp->context; - vl_api_send_msg (reg, (u8 *) rmp); - } -} - -static void -gpe_fwd_entries_copy (vl_api_gpe_fwd_entry_t * dst, - lisp_api_gpe_fwd_entry_t * src) -{ - lisp_api_gpe_fwd_entry_t *e; - u32 i = 0; - - vec_foreach (e, src) - { - clib_memset (&dst[i], 0, sizeof (*dst)); - dst[i].dp_table = e->dp_table; - dst[i].fwd_entry_index = e->fwd_entry_index; - dst[i].vni = e->vni; - dst[i].action = e->action; - switch (fid_addr_type (&e->leid)) - { - case FID_ADDR_IP_PREF: - dst[i].leid.type = EID_TYPE_API_PREFIX; - dst[i].reid.type = EID_TYPE_API_PREFIX; - ip_prefix_encode2 (&fid_addr_ippref (&e->leid), - &dst[i].leid.address.prefix); - ip_prefix_encode2 (&fid_addr_ippref (&e->reid), - &dst[i].reid.address.prefix); - break; - case FID_ADDR_MAC: - mac_address_encode ((mac_address_t *) fid_addr_mac (&e->leid), - dst[i].leid.address.mac); - mac_address_encode ((mac_address_t *) fid_addr_mac (&e->reid), - dst[i].reid.address.mac); - dst[i].leid.type = EID_TYPE_API_MAC; - dst[i].reid.type = EID_TYPE_API_MAC; - break; - default: - clib_warning ("unknown fid type %d!", fid_addr_type (&e->leid)); - break; - } - i++; - } -} - -static void -gpe_fwd_entries_get_t_net_to_host (vl_api_gpe_fwd_entries_get_t * mp) -{ - mp->vni = clib_net_to_host_u32 (mp->vni); -} - -static void -gpe_entry_t_host_to_net (vl_api_gpe_fwd_entry_t * e) -{ - e->fwd_entry_index = clib_host_to_net_u32 (e->fwd_entry_index); - e->dp_table = clib_host_to_net_u32 (e->dp_table); - e->vni = clib_host_to_net_u32 (e->vni); -} - -static void - gpe_fwd_entries_get_reply_t_host_to_net - (vl_api_gpe_fwd_entries_get_reply_t * mp) -{ - u32 i; - vl_api_gpe_fwd_entry_t *e; - - for (i = 0; i < mp->count; i++) - { - e = &mp->entries[i]; - gpe_entry_t_host_to_net (e); - } - mp->count = clib_host_to_net_u32 (mp->count); -} - -static void -vl_api_gpe_fwd_entry_vnis_get_t_handler (vl_api_gpe_fwd_entry_vnis_get_t * mp) -{ - vl_api_gpe_fwd_entry_vnis_get_reply_t *rmp = 0; - hash_pair_t *p; - u32 i = 0; - int rv = 0; - - u32 *vnis = vnet_lisp_gpe_get_fwd_entry_vnis (); - u32 size = hash_elts (vnis) * sizeof (u32); - - /* *INDENT-OFF* */ - REPLY_MACRO4 (VL_API_GPE_FWD_ENTRY_VNIS_GET_REPLY, size, - { - rmp->count = clib_host_to_net_u32 (hash_elts (vnis)); - hash_foreach_pair (p, vnis, - ({ - rmp->vnis[i++] = clib_host_to_net_u32 (p->key); - })); - }); - /* *INDENT-ON* */ - - hash_free (vnis); -} - -static void -vl_api_gpe_fwd_entries_get_t_handler (vl_api_gpe_fwd_entries_get_t * mp) -{ - lisp_api_gpe_fwd_entry_t *e; - vl_api_gpe_fwd_entries_get_reply_t *rmp = 0; - u32 size = 0; - int rv = 0; - - gpe_fwd_entries_get_t_net_to_host (mp); - - e = vnet_lisp_gpe_fwd_entries_get_by_vni (mp->vni); - size = vec_len (e) * sizeof (vl_api_gpe_fwd_entry_t); - - /* *INDENT-OFF* */ - REPLY_MACRO4 (VL_API_GPE_FWD_ENTRIES_GET_REPLY, size, - { - rmp->count = vec_len (e); - gpe_fwd_entries_copy (rmp->entries, e); - gpe_fwd_entries_get_reply_t_host_to_net (rmp); - }); - /* *INDENT-ON* */ - - vec_free (e); -} - -static void -gpe_add_del_fwd_entry_t_net_to_host (vl_api_gpe_add_del_fwd_entry_t * mp) -{ - mp->vni = clib_net_to_host_u32 (mp->vni); - mp->dp_table = clib_net_to_host_u32 (mp->dp_table); - mp->loc_num = clib_net_to_host_u32 (mp->loc_num); -} - -static void -vl_api_gpe_add_del_fwd_entry_t_handler (vl_api_gpe_add_del_fwd_entry_t * mp) -{ - vl_api_gpe_add_del_fwd_entry_reply_t *rmp; - vnet_lisp_gpe_add_del_fwd_entry_args_t _a, *a = &_a; - locator_pair_t *pairs = 0; - int rv = 0; - - gpe_add_del_fwd_entry_t_net_to_host (mp); - clib_memset (a, 0, sizeof (a[0])); - - rv = unformat_lisp_eid_api (&a->rmt_eid, mp->vni, &mp->rmt_eid); - rv |= unformat_lisp_eid_api (&a->lcl_eid, mp->vni, &mp->lcl_eid); - - if (mp->loc_num % 2 != 0) - { - rv = -1; - goto send_reply; - } - pairs = unformat_gpe_loc_pairs (mp->locs, mp->loc_num / 2); - - if (rv) - goto send_reply; - - a->is_add = mp->is_add; - a->locator_pairs = pairs; - a->dp_table = mp->dp_table; - a->vni = mp->vni; - a->action = mp->action; - if (mp->loc_num == 0) - a->is_negative = 1; - - rv = vnet_lisp_gpe_add_del_fwd_entry (a, 0); - vec_free (pairs); -send_reply: - /* *INDENT-OFF* */ - REPLY_MACRO2 (VL_API_GPE_ADD_DEL_FWD_ENTRY_REPLY, - { - rmp->fwd_entry_index = clib_host_to_net_u32 (a->fwd_entry_index); - }); - /* *INDENT-ON* */ -} - -static void -vl_api_gpe_enable_disable_t_handler (vl_api_gpe_enable_disable_t * mp) -{ - vl_api_gpe_enable_disable_reply_t *rmp; - int rv = 0; - vnet_lisp_gpe_enable_disable_args_t _a, *a = &_a; - - a->is_en = mp->is_enable; - vnet_lisp_gpe_enable_disable (a); - - REPLY_MACRO (VL_API_GPE_ENABLE_DISABLE_REPLY); -} - -static void -vl_api_gpe_add_del_iface_t_handler (vl_api_gpe_add_del_iface_t * mp) -{ - vl_api_gpe_add_del_iface_reply_t *rmp; - int rv = 0; - u32 vni, dp_table; - - vni = clib_net_to_host_u32 (mp->vni); - dp_table = clib_net_to_host_u32 (mp->dp_table); - - if (mp->is_l2) - { - if (mp->is_add) - { - if (~0 == lisp_gpe_tenant_l2_iface_add_or_lock (vni, dp_table)) - rv = 1; - } - else - lisp_gpe_tenant_l2_iface_unlock (vni); - } - else - { - if (mp->is_add) - { - if (~0 == lisp_gpe_tenant_l3_iface_add_or_lock (vni, dp_table, 1)) - rv = 1; - } - else - lisp_gpe_tenant_l3_iface_unlock (vni); - } - - REPLY_MACRO (VL_API_GPE_ADD_DEL_IFACE_REPLY); -} - -static void -vl_api_gpe_set_encap_mode_t_handler (vl_api_gpe_set_encap_mode_t * mp) -{ - vl_api_gpe_set_encap_mode_reply_t *rmp; - int rv = 0; - - rv = vnet_gpe_set_encap_mode (mp->is_vxlan); - REPLY_MACRO (VL_API_GPE_SET_ENCAP_MODE_REPLY); -} - -static void -vl_api_gpe_get_encap_mode_t_handler (vl_api_gpe_get_encap_mode_t * mp) -{ - vl_api_gpe_get_encap_mode_reply_t *rmp; - int rv = 0; - - /* *INDENT-OFF* */ - REPLY_MACRO2 (VL_API_GPE_GET_ENCAP_MODE_REPLY, - ({ - rmp->encap_mode = vnet_gpe_get_encap_mode (); - })); - /* *INDENT-ON* */ -} - -static void - vl_api_gpe_add_del_native_fwd_rpath_t_handler - (vl_api_gpe_add_del_native_fwd_rpath_t * mp) -{ - vl_api_gpe_add_del_native_fwd_rpath_reply_t *rmp; - vnet_gpe_native_fwd_rpath_args_t _a, *a = &_a; - int rv = 0; - - clib_memset (a, 0, sizeof (a[0])); - - if (mp->nh_addr.af) - clib_memcpy (&a->rpath.frp_addr.ip6, mp->nh_addr.un.ip6, - sizeof (ip6_address_t)); - else - clib_memcpy (&a->rpath.frp_addr.ip4, mp->nh_addr.un.ip4, - sizeof (ip4_address_t)); - - a->is_add = mp->is_add; - a->rpath.frp_proto = mp->nh_addr.af ? DPO_PROTO_IP6 : DPO_PROTO_IP4; - a->rpath.frp_fib_index = - fib_table_find (dpo_proto_to_fib (a->rpath.frp_proto), - clib_net_to_host_u32 (mp->table_id)); - if (~0 == a->rpath.frp_fib_index) - { - rv = VNET_API_ERROR_INVALID_VALUE; - goto done; - } - - a->rpath.frp_sw_if_index = clib_net_to_host_u32 (mp->nh_sw_if_index); - a->rpath.frp_weight = 1; - - rv = vnet_gpe_add_del_native_fwd_rpath (a); -done: - REPLY_MACRO (VL_API_GPE_ADD_DEL_NATIVE_FWD_RPATH_REPLY); -} - -static void -gpe_native_fwd_rpaths_copy (vl_api_gpe_native_fwd_rpath_t * dst, - fib_route_path_t * src) -{ - fib_route_path_t *e; - fib_table_t *table; - u32 i = 0; - - vec_foreach (e, src) - { - clib_memset (&dst[i], 0, sizeof (*dst)); - table = fib_table_get (e->frp_fib_index, dpo_proto_to_fib (e->frp_proto)); - dst[i].fib_index = table->ft_table_id; - dst[i].nh_sw_if_index = e->frp_sw_if_index; - ip_address_encode (&e->frp_addr, IP46_TYPE_ANY, &dst[i].nh_addr); - i++; - } -} - -static void -gpe_native_fwd_rpath_t_host_to_net (vl_api_gpe_native_fwd_rpath_t * e) -{ - e->fib_index = clib_host_to_net_u32 (e->fib_index); - e->nh_sw_if_index = clib_host_to_net_u32 (e->nh_sw_if_index); -} - -static void - gpe_native_fwd_rpaths_get_reply_t_host_to_net - (vl_api_gpe_native_fwd_rpaths_get_reply_t * mp) -{ - u32 i; - vl_api_gpe_native_fwd_rpath_t *e; - - for (i = 0; i < mp->count; i++) - { - e = &mp->entries[i]; - gpe_native_fwd_rpath_t_host_to_net (e); - } - mp->count = clib_host_to_net_u32 (mp->count); -} - -static void -vl_api_gpe_native_fwd_rpaths_get_t_handler (vl_api_gpe_native_fwd_rpaths_get_t - * mp) -{ - lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main (); - vl_api_gpe_native_fwd_rpaths_get_reply_t *rmp; - u32 size = 0; - int rv = 0; - - u8 rpath_index = mp->is_ip4 ? 1 : 0; - - size = vec_len (lgm->native_fwd_rpath[rpath_index]) - * sizeof (vl_api_gpe_native_fwd_rpath_t); - - /* *INDENT-OFF* */ - REPLY_MACRO4 (VL_API_GPE_NATIVE_FWD_RPATHS_GET_REPLY, size, - { - rmp->count = vec_len (lgm->native_fwd_rpath[rpath_index]); - gpe_native_fwd_rpaths_copy (rmp->entries, - lgm->native_fwd_rpath[rpath_index]); - gpe_native_fwd_rpaths_get_reply_t_host_to_net (rmp); - }); - /* *INDENT-ON* */ -} - -/* - * gpe_api_hookup - * Add vpe's API message handlers to the table. - * vlib has already mapped shared memory and - * added the client registration handlers. - * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process() - */ -#define vl_msg_name_crc_list -#include -#undef vl_msg_name_crc_list - -static void -setup_message_id_table (api_main_t * am) -{ -#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id); - foreach_vl_msg_name_crc_lisp_gpe; -#undef _ -} - -static clib_error_t * -gpe_api_hookup (vlib_main_t * vm) -{ - api_main_t *am = vlibapi_get_main (); - -#define _(N,n) \ - vl_msg_api_set_handlers(VL_API_##N, #n, \ - vl_api_##n##_t_handler, \ - vl_noop_handler, \ - vl_api_##n##_t_endian, \ - vl_api_##n##_t_print, \ - sizeof(vl_api_##n##_t), 1); - foreach_vpe_api_msg; -#undef _ - - /* - * Set up the (msg_name, crc, message-id) table - */ - setup_message_id_table (am); - - return 0; -} - -VLIB_API_INIT_FUNCTION (gpe_api_hookup); - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/src/vnet/lisp-gpe/lisp_gpe_error.def b/src/vnet/lisp-gpe/lisp_gpe_error.def deleted file mode 100644 index 415fada73d2..00000000000 --- a/src/vnet/lisp-gpe/lisp_gpe_error.def +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -lisp_gpe_error (ENCAPSULATED, "good packets encapsulated") -lisp_gpe_error (DECAPSULATED, "good packets decapsulated") -lisp_gpe_error (NO_TUNNEL, "tunnel does not exist") diff --git a/src/vnet/lisp-gpe/lisp_gpe_fwd_entry.c b/src/vnet/lisp-gpe/lisp_gpe_fwd_entry.c deleted file mode 100644 index 487ba246b4d..00000000000 --- a/src/vnet/lisp-gpe/lisp_gpe_fwd_entry.c +++ /dev/null @@ -1,1595 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/** - * @brief Add route to IP4 or IP6 Destination FIB. - * - * Add a route to the destination FIB that results in the lookup - * in the SRC FIB. The SRC FIB is created is it does not yet exist. - * - * @param[in] dst_table_id Destination FIB Table-ID - * @param[in] dst_prefix Destination IP prefix. - * - * @return src_fib_index The index/ID of the SRC FIB created. - */ -static u32 -ip_dst_fib_add_route (u32 dst_fib_index, const ip_prefix_t * dst_prefix) -{ - fib_node_index_t src_fib_index; - fib_prefix_t dst_fib_prefix; - fib_node_index_t dst_fei; - - ASSERT (NULL != dst_prefix); - - ip_prefix_to_fib_prefix (dst_prefix, &dst_fib_prefix); - - /* - * lookup the destination prefix in the VRF table and retrieve the - * LISP associated data - */ - dst_fei = fib_table_lookup_exact_match (dst_fib_index, &dst_fib_prefix); - - /* - * If the FIB entry is not present, or not LISP sourced, add it - */ - if (dst_fei == FIB_NODE_INDEX_INVALID || - NULL == fib_entry_get_source_data (dst_fei, FIB_SOURCE_LISP)) - { - dpo_id_t src_lkup_dpo = DPO_INVALID; - - /* create a new src FIB. */ - src_fib_index = - fib_table_create_and_lock (dst_fib_prefix.fp_proto, - FIB_SOURCE_LISP, - "LISP-src for [%d,%U]", - dst_fib_index, - format_fib_prefix, &dst_fib_prefix); - /* - * add src fib default route - */ - fib_prefix_t prefix = { - .fp_proto = dst_fib_prefix.fp_proto, - }; - fib_table_entry_special_dpo_add (src_fib_index, &prefix, - FIB_SOURCE_LISP, - FIB_ENTRY_FLAG_EXCLUSIVE, - lisp_cp_dpo_get (fib_proto_to_dpo - (dst_fib_prefix.fp_proto))); - /* - * create a data-path object to perform the source address lookup - * in the SRC FIB - */ - lookup_dpo_add_or_lock_w_fib_index (src_fib_index, - (ip_prefix_version (dst_prefix) == - AF_IP6 ? DPO_PROTO_IP6 : - DPO_PROTO_IP4), - LOOKUP_UNICAST, - LOOKUP_INPUT_SRC_ADDR, - LOOKUP_TABLE_FROM_CONFIG, - &src_lkup_dpo); - - /* - * add the entry to the destination FIB that uses the lookup DPO - */ - dst_fei = fib_table_entry_special_dpo_add (dst_fib_index, - &dst_fib_prefix, - FIB_SOURCE_LISP, - FIB_ENTRY_FLAG_EXCLUSIVE, - &src_lkup_dpo); - - /* - * the DPO is locked by the FIB entry, and we have no further - * need for it. - */ - dpo_unlock (&src_lkup_dpo); - - /* - * save the SRC FIB index on the entry so we can retrieve it for - * subsequent routes. - */ - fib_entry_set_source_data (dst_fei, FIB_SOURCE_LISP, &src_fib_index); - } - else - { - /* - * destination FIB entry already present - */ - src_fib_index = *(u32 *) fib_entry_get_source_data (dst_fei, - FIB_SOURCE_LISP); - } - - return (src_fib_index); -} - -/** - * @brief Del route to IP4 or IP6 SD FIB. - * - * Remove routes from both destination and source FIBs. - * - * @param[in] src_fib_index The index/ID of the SRC FIB - * @param[in] src_prefix Source IP prefix. - * @param[in] dst_fib_index The index/ID of the DST FIB - * @param[in] dst_prefix Destination IP prefix. - */ -static void -ip_src_dst_fib_del_route (u32 src_fib_index, - const ip_prefix_t * src_prefix, - u32 dst_fib_index, const ip_prefix_t * dst_prefix) -{ - fib_prefix_t dst_fib_prefix, src_fib_prefix; - u8 have_default = 0; - u32 n_entries; - - ASSERT (NULL != dst_prefix); - ASSERT (NULL != src_prefix); - - ip_prefix_to_fib_prefix (dst_prefix, &dst_fib_prefix); - ip_prefix_to_fib_prefix (src_prefix, &src_fib_prefix); - - fib_table_entry_delete (src_fib_index, &src_fib_prefix, FIB_SOURCE_LISP); - - /* check if only default left or empty */ - fib_prefix_t default_pref = { - .fp_proto = dst_fib_prefix.fp_proto - }; - - if (fib_table_lookup_exact_match (src_fib_index, - &default_pref) != FIB_NODE_INDEX_INVALID) - have_default = 1; - - n_entries = fib_table_get_num_entries (src_fib_index, - src_fib_prefix.fp_proto, - FIB_SOURCE_LISP); - if (n_entries == 0 || (have_default && n_entries == 1)) - { - /* - * remove src FIB default route - */ - if (have_default) - fib_table_entry_special_remove (src_fib_index, &default_pref, - FIB_SOURCE_LISP); - - /* - * there's nothing left now, unlock the source FIB and the - * destination route - */ - fib_table_entry_special_remove (dst_fib_index, - &dst_fib_prefix, FIB_SOURCE_LISP); - fib_table_unlock (src_fib_index, src_fib_prefix.fp_proto, - FIB_SOURCE_LISP); - } -} - -/** - * @brief Add route to IP4 or IP6 SRC FIB. - * - * Adds a route to in the LISP SRC FIB with the result of the route - * being the DPO passed. - * - * @param[in] src_fib_index The index/ID of the SRC FIB - * @param[in] src_prefix Source IP prefix. - * @param[in] src_dpo The DPO the route will link to. - * - * @return fib index of the inserted prefix - */ -static fib_node_index_t -ip_src_fib_add_route_w_dpo (u32 src_fib_index, - const ip_prefix_t * src_prefix, - const dpo_id_t * src_dpo) -{ - fib_node_index_t fei = ~0; - fib_prefix_t src_fib_prefix; - - ip_prefix_to_fib_prefix (src_prefix, &src_fib_prefix); - - /* - * add the entry into the source fib. - */ - fib_node_index_t src_fei; - - src_fei = fib_table_lookup_exact_match (src_fib_index, &src_fib_prefix); - - if (FIB_NODE_INDEX_INVALID == src_fei || - !fib_entry_is_sourced (src_fei, FIB_SOURCE_LISP)) - { - fei = fib_table_entry_special_dpo_add (src_fib_index, - &src_fib_prefix, - FIB_SOURCE_LISP, - FIB_ENTRY_FLAG_EXCLUSIVE, - src_dpo); - } - return fei; -} - -static fib_route_path_t * -lisp_gpe_mk_fib_paths (const lisp_fwd_path_t * paths) -{ - const lisp_gpe_adjacency_t *ladj; - fib_route_path_t *rpaths = NULL; - fib_protocol_t fp; - u8 best_priority; - u32 ii; - - vec_validate (rpaths, vec_len (paths) - 1); - - best_priority = paths[0].priority; - - vec_foreach_index (ii, paths) - { - if (paths[0].priority != best_priority) - break; - - ladj = lisp_gpe_adjacency_get (paths[ii].lisp_adj); - - fp = ip_address_to_46 (&ladj->remote_rloc, &rpaths[ii].frp_addr); - - rpaths[ii].frp_proto = fib_proto_to_dpo (fp); - rpaths[ii].frp_sw_if_index = ladj->sw_if_index; - rpaths[ii].frp_weight = (paths[ii].weight ? paths[ii].weight : 1); - } - - ASSERT (0 != vec_len (rpaths)); - - return (rpaths); -} - -/** - * @brief Add route to IP4 or IP6 SRC FIB. - * - * Adds a route to in the LISP SRC FIB for the tunnel. - * - * @param[in] src_fib_index The index/ID of the SRC FIB - * @param[in] src_prefix Source IP prefix. - * @param[in] paths The paths from which to construct the - * load balance - */ -static fib_node_index_t -ip_src_fib_add_route (u32 src_fib_index, - const ip_prefix_t * src_prefix, - const lisp_fwd_path_t * paths) -{ - fib_prefix_t src_fib_prefix; - fib_route_path_t *rpaths; - - ip_prefix_to_fib_prefix (src_prefix, &src_fib_prefix); - - rpaths = lisp_gpe_mk_fib_paths (paths); - - fib_node_index_t fib_entry_index = - fib_table_entry_update (src_fib_index, &src_fib_prefix, FIB_SOURCE_LISP, - FIB_ENTRY_FLAG_NONE, rpaths); - vec_free (rpaths); - return fib_entry_index; -} - -static void -gpe_native_fwd_add_del_lfe (lisp_gpe_fwd_entry_t * lfe, u8 is_add) -{ - lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main (); - u8 found = 0, ip_version; - u32 *lfei, new_lfei; - ip_version = ip_prefix_version (&lfe->key->rmt.ippref); - - new_lfei = lfe - lgm->lisp_fwd_entry_pool; - vec_foreach (lfei, lgm->native_fwd_lfes[ip_version]) - { - lfe = pool_elt_at_index (lgm->lisp_fwd_entry_pool, lfei[0]); - if (lfei[0] == new_lfei) - { - found = 1; - break; - } - } - - if (is_add) - { - if (!found) - vec_add1 (lgm->native_fwd_lfes[ip_version], new_lfei); - } - else - { - if (found) - vec_del1 (lgm->native_fwd_lfes[ip_version], lfei[0]); - } -} - -static index_t -create_fib_entries (lisp_gpe_fwd_entry_t * lfe) -{ - fib_node_index_t fi; - fib_entry_t *fe; - lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main (); - dpo_proto_t dproto; - ip_prefix_t ippref; - fib_prefix_t fib_prefix; - u8 ip_version = ip_prefix_version (&lfe->key->rmt.ippref); - dproto = (ip_version == AF_IP4 ? DPO_PROTO_IP4 : DPO_PROTO_IP6); - - if (lfe->is_src_dst) - { - lfe->src_fib_index = ip_dst_fib_add_route (lfe->eid_fib_index, - &lfe->key->rmt.ippref); - memcpy (&ippref, &lfe->key->lcl.ippref, sizeof (ippref)); - } - else - { - lfe->src_fib_index = lfe->eid_fib_index; - memcpy (&ippref, &lfe->key->rmt.ippref, sizeof (ippref)); - } - - if (LISP_GPE_FWD_ENTRY_TYPE_NEGATIVE == lfe->type) - { - dpo_id_t dpo = DPO_INVALID; - - switch (lfe->action) - { - case LISP_FORWARD_NATIVE: - /* TODO handle route overlaps with fib and default route */ - if (vec_len (lgm->native_fwd_rpath[ip_version])) - { - ip_prefix_to_fib_prefix (&lfe->key->rmt.ippref, &fib_prefix); - fi = fib_table_entry_update (lfe->eid_fib_index, &fib_prefix, - FIB_SOURCE_LISP, - FIB_ENTRY_FLAG_NONE, - lgm->native_fwd_rpath[ip_version]); - gpe_native_fwd_add_del_lfe (lfe, 1); - goto done; - } - case LISP_NO_ACTION: - /* TODO update timers? */ - case LISP_SEND_MAP_REQUEST: - /* insert tunnel that always sends map-request */ - dpo_copy (&dpo, lisp_cp_dpo_get (dproto)); - break; - case LISP_DROP: - /* for drop fwd entries, just add route, no need to add encap tunnel */ - dpo_copy (&dpo, drop_dpo_get (dproto)); - break; - } - fi = ip_src_fib_add_route_w_dpo (lfe->src_fib_index, &ippref, &dpo); - dpo_reset (&dpo); - } - else - { - fi = ip_src_fib_add_route (lfe->src_fib_index, &ippref, lfe->paths); - } -done: - fe = fib_entry_get (fi); - return fe->fe_lb.dpoi_index; -} - -static void -delete_fib_entries (lisp_gpe_fwd_entry_t * lfe) -{ - fib_prefix_t dst_fib_prefix; - - if (lfe->is_src_dst) - ip_src_dst_fib_del_route (lfe->src_fib_index, - &lfe->key->lcl.ippref, - lfe->eid_fib_index, &lfe->key->rmt.ippref); - else - { - ip_prefix_to_fib_prefix (&lfe->key->rmt.ippref, &dst_fib_prefix); - fib_table_entry_delete (lfe->src_fib_index, &dst_fib_prefix, - FIB_SOURCE_LISP); - gpe_native_fwd_add_del_lfe (lfe, 0); - } -} - -static lisp_gpe_fwd_entry_t * -find_fwd_entry (lisp_gpe_main_t * lgm, - vnet_lisp_gpe_add_del_fwd_entry_args_t * a, - lisp_gpe_fwd_entry_key_t * key) -{ - uword *p; - - clib_memset (key, 0, sizeof (*key)); - - if (GID_ADDR_IP_PREFIX == gid_address_type (&a->rmt_eid)) - { - /* - * the ip version of the source is not set to ip6 when the - * source is all zeros. force it. - */ - ip_prefix_version (&gid_address_ippref (&a->lcl_eid)) = - ip_prefix_version (&gid_address_ippref (&a->rmt_eid)); - } - - gid_to_dp_address (&a->rmt_eid, &key->rmt); - gid_to_dp_address (&a->lcl_eid, &key->lcl); - key->vni = a->vni; - - p = hash_get_mem (lgm->lisp_gpe_fwd_entries, key); - - if (NULL != p) - { - return (pool_elt_at_index (lgm->lisp_fwd_entry_pool, p[0])); - } - return (NULL); -} - -static int -lisp_gpe_fwd_entry_path_sort (void *a1, void *a2) -{ - lisp_fwd_path_t *p1 = a1, *p2 = a2; - - return (p1->priority - p2->priority); -} - -static void -lisp_gpe_fwd_entry_mk_paths (lisp_gpe_fwd_entry_t * lfe, - vnet_lisp_gpe_add_del_fwd_entry_args_t * a) -{ - lisp_fwd_path_t *path; - u32 index; - - vec_validate (lfe->paths, vec_len (a->locator_pairs) - 1); - - vec_foreach_index (index, a->locator_pairs) - { - path = &lfe->paths[index]; - - path->priority = a->locator_pairs[index].priority; - path->weight = a->locator_pairs[index].weight; - - path->lisp_adj = - lisp_gpe_adjacency_find_or_create_and_lock (&a->locator_pairs - [index], - a->dp_table, lfe->key->vni); - } - vec_sort_with_function (lfe->paths, lisp_gpe_fwd_entry_path_sort); -} - -void -vnet_lisp_gpe_add_fwd_counters (vnet_lisp_gpe_add_del_fwd_entry_args_t * a, - u32 fwd_entry_index) -{ - const lisp_gpe_adjacency_t *ladj; - lisp_fwd_path_t *path; - lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main (); - u8 *placeholder_elt; - lisp_gpe_fwd_entry_t *lfe; - lisp_gpe_fwd_entry_key_t fe_key; - lisp_stats_key_t key; - - lfe = find_fwd_entry (lgm, a, &fe_key); - - if (!lfe) - return; - - if (LISP_GPE_FWD_ENTRY_TYPE_NORMAL != lfe->type) - return; - - clib_memset (&key, 0, sizeof (key)); - key.fwd_entry_index = fwd_entry_index; - - vec_foreach (path, lfe->paths) - { - ladj = lisp_gpe_adjacency_get (path->lisp_adj); - key.tunnel_index = ladj->tunnel_index; - lisp_stats_key_t *key_copy = clib_mem_alloc (sizeof (*key_copy)); - memcpy (key_copy, &key, sizeof (*key_copy)); - pool_get (lgm->placeholder_stats_pool, placeholder_elt); - hash_set_mem (lgm->lisp_stats_index_by_key, key_copy, - placeholder_elt - lgm->placeholder_stats_pool); - - vlib_validate_combined_counter (&lgm->counters, - placeholder_elt - - lgm->placeholder_stats_pool); - vlib_zero_combined_counter (&lgm->counters, - placeholder_elt - - lgm->placeholder_stats_pool); - } -} - -/** - * @brief Add/Delete LISP IP forwarding entry. - * - * creation of forwarding entries for IP LISP overlay: - * - * @param[in] lgm Reference to @ref lisp_gpe_main_t. - * @param[in] a Parameters for building the forwarding entry. - * - * @return 0 on success. - */ -static int -add_ip_fwd_entry (lisp_gpe_main_t * lgm, - vnet_lisp_gpe_add_del_fwd_entry_args_t * a) -{ - lisp_gpe_fwd_entry_key_t key; - lisp_gpe_fwd_entry_t *lfe; - fib_protocol_t fproto; - - lfe = find_fwd_entry (lgm, a, &key); - - if (NULL != lfe) - /* don't support updates */ - return VNET_API_ERROR_INVALID_VALUE; - - pool_get (lgm->lisp_fwd_entry_pool, lfe); - clib_memset (lfe, 0, sizeof (*lfe)); - lfe->key = clib_mem_alloc (sizeof (key)); - memcpy (lfe->key, &key, sizeof (key)); - - hash_set_mem (lgm->lisp_gpe_fwd_entries, lfe->key, - lfe - lgm->lisp_fwd_entry_pool); - a->fwd_entry_index = lfe - lgm->lisp_fwd_entry_pool; - - fproto = (AF_IP4 == ip_prefix_version (&fid_addr_ippref (&lfe->key->rmt)) ? - FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6); - - lfe->type = (a->is_negative ? - LISP_GPE_FWD_ENTRY_TYPE_NEGATIVE : - LISP_GPE_FWD_ENTRY_TYPE_NORMAL); - lfe->tenant = lisp_gpe_tenant_find_or_create (lfe->key->vni); - lfe->eid_table_id = a->table_id; - lfe->eid_fib_index = fib_table_find_or_create_and_lock (fproto, - lfe->eid_table_id, - FIB_SOURCE_LISP); - lfe->is_src_dst = a->is_src_dst; - - if (LISP_GPE_FWD_ENTRY_TYPE_NEGATIVE != lfe->type) - { - lisp_gpe_fwd_entry_mk_paths (lfe, a); - } - else - { - lfe->action = a->action; - } - - lfe->dpoi_index = create_fib_entries (lfe); - return (0); -} - -static void -del_ip_fwd_entry_i (lisp_gpe_main_t * lgm, lisp_gpe_fwd_entry_t * lfe) -{ - lisp_fwd_path_t *path; - fib_protocol_t fproto; - - if (LISP_GPE_FWD_ENTRY_TYPE_NEGATIVE != lfe->type) - { - vec_foreach (path, lfe->paths) - { - lisp_gpe_adjacency_unlock (path->lisp_adj); - } - } - - delete_fib_entries (lfe); - - fproto = (AF_IP4 == ip_prefix_version (&fid_addr_ippref (&lfe->key->rmt)) ? - FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6); - fib_table_unlock (lfe->eid_fib_index, fproto, FIB_SOURCE_LISP); - - hash_unset_mem (lgm->lisp_gpe_fwd_entries, lfe->key); - clib_mem_free (lfe->key); - pool_put (lgm->lisp_fwd_entry_pool, lfe); -} - -/** - * @brief Add/Delete LISP IP forwarding entry. - * - * removal of forwarding entries for IP LISP overlay: - * - * @param[in] lgm Reference to @ref lisp_gpe_main_t. - * @param[in] a Parameters for building the forwarding entry. - * - * @return 0 on success. - */ -static int -del_ip_fwd_entry (lisp_gpe_main_t * lgm, - vnet_lisp_gpe_add_del_fwd_entry_args_t * a) -{ - lisp_gpe_fwd_entry_key_t key; - lisp_gpe_fwd_entry_t *lfe; - - lfe = find_fwd_entry (lgm, a, &key); - - if (NULL == lfe) - /* no such entry */ - return VNET_API_ERROR_INVALID_VALUE; - - del_ip_fwd_entry_i (lgm, lfe); - - return (0); -} - -static void -make_mac_fib_key (BVT (clib_bihash_kv) * kv, u16 bd_index, u8 src_mac[6], - u8 dst_mac[6]) -{ - kv->key[0] = (((u64) bd_index) << 48) | mac_to_u64 (dst_mac); - kv->key[1] = mac_to_u64 (src_mac); - kv->key[2] = 0; -} - -/** - * @brief Lookup L2 SD FIB entry - * - * Does a vni + dest + source lookup in the L2 LISP FIB. If the lookup fails - * it tries a second time with source set to 0 (i.e., a simple dest lookup). - * - * @param[in] lgm Reference to @ref lisp_gpe_main_t. - * @param[in] bd_index Bridge domain index. - * @param[in] src_mac Source mac address. - * @param[in] dst_mac Destination mac address. - * - * @return index of mapping matching the lookup key. - */ -index_t -lisp_l2_fib_lookup (lisp_gpe_main_t * lgm, u16 bd_index, u8 src_mac[6], - u8 dst_mac[6]) -{ - int rv; - BVT (clib_bihash_kv) kv, value; - - make_mac_fib_key (&kv, bd_index, src_mac, dst_mac); - rv = BV (clib_bihash_search_inline_2) (&lgm->l2_fib, &kv, &value); - - /* no match, try with src 0, catch all for dst */ - if (rv != 0) - { - kv.key[1] = 0; - rv = BV (clib_bihash_search_inline_2) (&lgm->l2_fib, &kv, &value); - if (rv == 0) - return value.value; - } - else - return value.value; - - return lisp_gpe_main.l2_lb_cp_lkup.dpoi_index; -} - -/** - * @brief Add/del L2 SD FIB entry - * - * Inserts value in L2 FIB keyed by vni + dest + source. If entry is - * overwritten the associated value is returned. - * - * @param[in] lgm Reference to @ref lisp_gpe_main_t. - * @param[in] bd_index Bridge domain index. - * @param[in] src_mac Source mac address. - * @param[in] dst_mac Destination mac address. - * @param[in] val Value to add. - * @param[in] is_add Add/del flag. - * - * @return ~0 or value of overwritten entry. - */ -static u32 -lisp_l2_fib_add_del_entry (u16 bd_index, u8 src_mac[6], - u8 dst_mac[6], const dpo_id_t * dpo, u8 is_add) -{ - lisp_gpe_main_t *lgm = &lisp_gpe_main; - BVT (clib_bihash_kv) kv, value; - u32 old_val = ~0; - - make_mac_fib_key (&kv, bd_index, src_mac, dst_mac); - - if (BV (clib_bihash_search) (&lgm->l2_fib, &kv, &value) == 0) - old_val = value.value; - - if (!is_add) - BV (clib_bihash_add_del) (&lgm->l2_fib, &kv, 0 /* is_add */ ); - else - { - kv.value = dpo->dpoi_index; - BV (clib_bihash_add_del) (&lgm->l2_fib, &kv, 1 /* is_add */ ); - } - return old_val; -} - -#define L2_FIB_DEFAULT_HASH_NUM_BUCKETS (64 * 1024) -#define L2_FIB_DEFAULT_HASH_MEMORY_SIZE (32<<20) - -static void -l2_fib_init (lisp_gpe_main_t * lgm) -{ - index_t lbi; - - BV (clib_bihash_init) (&lgm->l2_fib, "l2 fib", - 1 << max_log2 (L2_FIB_DEFAULT_HASH_NUM_BUCKETS), - L2_FIB_DEFAULT_HASH_MEMORY_SIZE); - - /* - * the result from a 'miss' in a L2 Table - */ - lbi = load_balance_create (1, DPO_PROTO_ETHERNET, 0); - load_balance_set_bucket (lbi, 0, lisp_cp_dpo_get (DPO_PROTO_ETHERNET)); - - dpo_set (&lgm->l2_lb_cp_lkup, DPO_LOAD_BALANCE, DPO_PROTO_ETHERNET, lbi); -} - -static void -del_l2_fwd_entry_i (lisp_gpe_main_t * lgm, lisp_gpe_fwd_entry_t * lfe) -{ - lisp_fwd_path_t *path; - - if (LISP_GPE_FWD_ENTRY_TYPE_NEGATIVE != lfe->type) - { - vec_foreach (path, lfe->paths) - { - lisp_gpe_adjacency_unlock (path->lisp_adj); - } - fib_path_list_child_remove (lfe->l2.path_list_index, - lfe->l2.child_index); - } - - lisp_l2_fib_add_del_entry (lfe->l2.eid_bd_index, - fid_addr_mac (&lfe->key->lcl), - fid_addr_mac (&lfe->key->rmt), NULL, 0); - - hash_unset_mem (lgm->lisp_gpe_fwd_entries, lfe->key); - clib_mem_free (lfe->key); - pool_put (lgm->lisp_fwd_entry_pool, lfe); -} - -/** - * @brief Delete LISP L2 forwarding entry. - * - * Coordinates the removal of forwarding entries for L2 LISP overlay: - * - * @param[in] lgm Reference to @ref lisp_gpe_main_t. - * @param[in] a Parameters for building the forwarding entry. - * - * @return 0 on success. - */ -static int -del_l2_fwd_entry (lisp_gpe_main_t * lgm, - vnet_lisp_gpe_add_del_fwd_entry_args_t * a) -{ - lisp_gpe_fwd_entry_key_t key; - lisp_gpe_fwd_entry_t *lfe; - - lfe = find_fwd_entry (lgm, a, &key); - - if (NULL == lfe) - return VNET_API_ERROR_INVALID_VALUE; - - del_l2_fwd_entry_i (lgm, lfe); - - return (0); -} - -/** - * @brief Construct and insert the forwarding information used by an L2 entry - */ -static void -lisp_gpe_l2_update_fwding (lisp_gpe_fwd_entry_t * lfe) -{ - lisp_gpe_main_t *lgm = &lisp_gpe_main; - dpo_id_t dpo = DPO_INVALID; - - if (LISP_GPE_FWD_ENTRY_TYPE_NEGATIVE != lfe->type) - { - fib_path_list_contribute_forwarding (lfe->l2.path_list_index, - FIB_FORW_CHAIN_TYPE_ETHERNET, - FIB_PATH_LIST_FWD_FLAG_NONE, - &lfe->l2.dpo); - dpo_copy (&dpo, &lfe->l2.dpo); - } - else - { - switch (lfe->action) - { - case SEND_MAP_REQUEST: - dpo_copy (&dpo, &lgm->l2_lb_cp_lkup); - break; - case NO_ACTION: - case FORWARD_NATIVE: - case DROP: - dpo_copy (&dpo, drop_dpo_get (DPO_PROTO_ETHERNET)); - } - } - - /* add entry to l2 lisp fib */ - lisp_l2_fib_add_del_entry (lfe->l2.eid_bd_index, - fid_addr_mac (&lfe->key->lcl), - fid_addr_mac (&lfe->key->rmt), &dpo, 1); - lfe->dpoi_index = dpo.dpoi_index; - - dpo_reset (&dpo); -} - -/** - * @brief Add LISP L2 forwarding entry. - * - * Coordinates the creation of forwarding entries for L2 LISP overlay: - * creates lisp-gpe tunnel and injects new entry in Source/Dest L2 FIB. - * - * @param[in] lgm Reference to @ref lisp_gpe_main_t. - * @param[in] a Parameters for building the forwarding entry. - * - * @return 0 on success. - */ -static int -add_l2_fwd_entry (lisp_gpe_main_t * lgm, - vnet_lisp_gpe_add_del_fwd_entry_args_t * a) -{ - lisp_gpe_fwd_entry_key_t key; - bd_main_t *bdm = &bd_main; - lisp_gpe_fwd_entry_t *lfe; - uword *bd_indexp; - - bd_indexp = hash_get (bdm->bd_index_by_bd_id, a->bd_id); - if (!bd_indexp) - { - clib_warning ("bridge domain %d doesn't exist", a->bd_id); - return -1; - } - - lfe = find_fwd_entry (lgm, a, &key); - - if (NULL != lfe) - /* don't support updates */ - return VNET_API_ERROR_INVALID_VALUE; - - pool_get (lgm->lisp_fwd_entry_pool, lfe); - clib_memset (lfe, 0, sizeof (*lfe)); - lfe->key = clib_mem_alloc (sizeof (key)); - memcpy (lfe->key, &key, sizeof (key)); - - hash_set_mem (lgm->lisp_gpe_fwd_entries, lfe->key, - lfe - lgm->lisp_fwd_entry_pool); - a->fwd_entry_index = lfe - lgm->lisp_fwd_entry_pool; - - lfe->type = (a->is_negative ? - LISP_GPE_FWD_ENTRY_TYPE_NEGATIVE : - LISP_GPE_FWD_ENTRY_TYPE_NORMAL); - lfe->l2.eid_bd_id = a->bd_id; - lfe->l2.eid_bd_index = bd_indexp[0]; - lfe->tenant = lisp_gpe_tenant_find_or_create (lfe->key->vni); - - if (LISP_GPE_FWD_ENTRY_TYPE_NEGATIVE != lfe->type) - { - fib_route_path_t *rpaths; - - /* - * Make the sorted array of LISP paths with their resp. adjacency - */ - lisp_gpe_fwd_entry_mk_paths (lfe, a); - - /* - * From the LISP paths, construct a FIB path list that will - * contribute a load-balance. - */ - rpaths = lisp_gpe_mk_fib_paths (lfe->paths); - - lfe->l2.path_list_index = - fib_path_list_create (FIB_PATH_LIST_FLAG_NONE, rpaths); - - /* - * become a child of the path-list so we receive updates when - * its forwarding state changes. this includes an implicit lock. - */ - lfe->l2.child_index = - fib_path_list_child_add (lfe->l2.path_list_index, - FIB_NODE_TYPE_LISP_GPE_FWD_ENTRY, - lfe - lgm->lisp_fwd_entry_pool); - } - else - { - lfe->action = a->action; - } - - lisp_gpe_l2_update_fwding (lfe); - - return 0; -} - -/** - * @brief Lookup NSH SD FIB entry - * - * Does an SPI+SI lookup in the NSH LISP FIB. - * - * @param[in] lgm Reference to @ref lisp_gpe_main_t. - * @param[in] spi_si SPI + SI. - * - * @return next node index. - */ -const dpo_id_t * -lisp_nsh_fib_lookup (lisp_gpe_main_t * lgm, u32 spi_si_net_order) -{ - int rv; - BVT (clib_bihash_kv) kv, value; - - clib_memset (&kv, 0, sizeof (kv)); - kv.key[0] = spi_si_net_order; - rv = BV (clib_bihash_search_inline_2) (&lgm->nsh_fib, &kv, &value); - - if (rv != 0) - { - return lgm->nsh_cp_lkup; - } - else - { - lisp_gpe_fwd_entry_t *lfe; - lfe = pool_elt_at_index (lgm->lisp_fwd_entry_pool, value.value); - return &lfe->nsh.choice; - } -} - -/** - * @brief Add/del NSH FIB entry - * - * Inserts value in NSH FIB keyed by SPI+SI. If entry is - * overwritten the associated value is returned. - * - * @param[in] lgm Reference to @ref lisp_gpe_main_t. - * @param[in] spi_si SPI + SI. - * @param[in] dpo Load balanced mapped to SPI + SI - * - * @return ~0 or value of overwritten entry. - */ -static u32 -lisp_nsh_fib_add_del_entry (u32 spi_si_host_order, u32 lfei, u8 is_add) -{ - lisp_gpe_main_t *lgm = &lisp_gpe_main; - BVT (clib_bihash_kv) kv, value; - u32 old_val = ~0; - - clib_memset (&kv, 0, sizeof (kv)); - kv.key[0] = clib_host_to_net_u32 (spi_si_host_order); - kv.value = 0ULL; - - if (BV (clib_bihash_search) (&lgm->nsh_fib, &kv, &value) == 0) - old_val = value.value; - - if (!is_add) - BV (clib_bihash_add_del) (&lgm->nsh_fib, &kv, 0 /* is_add */ ); - else - { - kv.value = lfei; - BV (clib_bihash_add_del) (&lgm->nsh_fib, &kv, 1 /* is_add */ ); - } - return old_val; -} - -#define NSH_FIB_DEFAULT_HASH_NUM_BUCKETS (64 * 1024) -#define NSH_FIB_DEFAULT_HASH_MEMORY_SIZE (32<<20) - -static void -nsh_fib_init (lisp_gpe_main_t * lgm) -{ - BV (clib_bihash_init) (&lgm->nsh_fib, "nsh fib", - 1 << max_log2 (NSH_FIB_DEFAULT_HASH_NUM_BUCKETS), - NSH_FIB_DEFAULT_HASH_MEMORY_SIZE); - - /* - * the result from a 'miss' in a NSH Table - */ - lgm->nsh_cp_lkup = lisp_cp_dpo_get (DPO_PROTO_NSH); -} - -static void -del_nsh_fwd_entry_i (lisp_gpe_main_t * lgm, lisp_gpe_fwd_entry_t * lfe) -{ - lisp_fwd_path_t *path; - - if (LISP_GPE_FWD_ENTRY_TYPE_NEGATIVE != lfe->type) - { - vec_foreach (path, lfe->paths) - { - lisp_gpe_adjacency_unlock (path->lisp_adj); - } - fib_path_list_child_remove (lfe->nsh.path_list_index, - lfe->nsh.child_index); - dpo_reset (&lfe->nsh.choice); - } - - lisp_nsh_fib_add_del_entry (fid_addr_nsh (&lfe->key->rmt), (u32) ~ 0, 0); - - hash_unset_mem (lgm->lisp_gpe_fwd_entries, lfe->key); - clib_mem_free (lfe->key); - pool_put (lgm->lisp_fwd_entry_pool, lfe); -} - -/** - * @brief Delete LISP NSH forwarding entry. - * - * Coordinates the removal of forwarding entries for NSH LISP overlay: - * - * @param[in] lgm Reference to @ref lisp_gpe_main_t. - * @param[in] a Parameters for building the forwarding entry. - * - * @return 0 on success. - */ -static int -del_nsh_fwd_entry (lisp_gpe_main_t * lgm, - vnet_lisp_gpe_add_del_fwd_entry_args_t * a) -{ - lisp_gpe_fwd_entry_key_t key; - lisp_gpe_fwd_entry_t *lfe; - - lfe = find_fwd_entry (lgm, a, &key); - - if (NULL == lfe) - return VNET_API_ERROR_INVALID_VALUE; - - del_nsh_fwd_entry_i (lgm, lfe); - - return (0); -} - -/** - * @brief Construct and insert the forwarding information used by an NSH entry - */ -static void -lisp_gpe_nsh_update_fwding (lisp_gpe_fwd_entry_t * lfe) -{ - lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main (); - dpo_id_t dpo = DPO_INVALID; - vnet_hw_interface_t *hi; - uword *hip; - - if (LISP_GPE_FWD_ENTRY_TYPE_NEGATIVE != lfe->type) - { - fib_path_list_contribute_forwarding (lfe->nsh.path_list_index, - FIB_FORW_CHAIN_TYPE_NSH, - FIB_PATH_LIST_FWD_FLAG_NONE, - &lfe->nsh.dpo); - - /* - * LISP encap is always the same for this SPI+SI so we do that hash now - * and stack on the choice. - */ - if (DPO_LOAD_BALANCE == lfe->nsh.dpo.dpoi_type) - { - const dpo_id_t *tmp; - const load_balance_t *lb; - int hash; - - lb = load_balance_get (lfe->nsh.dpo.dpoi_index); - hash = fid_addr_nsh (&lfe->key->rmt) % lb->lb_n_buckets; - tmp = - load_balance_get_bucket_i (lb, hash & lb->lb_n_buckets_minus_1); - - dpo_copy (&dpo, tmp); - } - } - else - { - switch (lfe->action) - { - case SEND_MAP_REQUEST: - dpo_copy (&dpo, lgm->nsh_cp_lkup); - break; - case NO_ACTION: - case FORWARD_NATIVE: - case DROP: - dpo_copy (&dpo, drop_dpo_get (DPO_PROTO_NSH)); - } - } - - /* We have only one nsh-lisp interface (no NSH virtualization) */ - hip = hash_get (lgm->nsh_ifaces.hw_if_index_by_dp_table, 0); - if (hip) - { - hi = vnet_get_hw_interface (lgm->vnet_main, hip[0]); - dpo_stack_from_node (hi->tx_node_index, &lfe->nsh.choice, &dpo); - } - /* add entry to nsh lisp fib */ - lisp_nsh_fib_add_del_entry (fid_addr_nsh (&lfe->key->rmt), - lfe - lgm->lisp_fwd_entry_pool, 1); - dpo_reset (&dpo); - -} - -/** - * @brief Add LISP NSH forwarding entry. - * - * Coordinates the creation of forwarding entries for L2 LISP overlay: - * creates lisp-gpe tunnel and injects new entry in Source/Dest L2 FIB. - * - * @param[in] lgm Reference to @ref lisp_gpe_main_t. - * @param[in] a Parameters for building the forwarding entry. - * - * @return 0 on success. - */ -static int -add_nsh_fwd_entry (lisp_gpe_main_t * lgm, - vnet_lisp_gpe_add_del_fwd_entry_args_t * a) -{ - lisp_gpe_fwd_entry_key_t key; - lisp_gpe_fwd_entry_t *lfe; - - lfe = find_fwd_entry (lgm, a, &key); - - if (NULL != lfe) - /* don't support updates */ - return VNET_API_ERROR_INVALID_VALUE; - - pool_get (lgm->lisp_fwd_entry_pool, lfe); - clib_memset (lfe, 0, sizeof (*lfe)); - lfe->key = clib_mem_alloc (sizeof (key)); - memcpy (lfe->key, &key, sizeof (key)); - - hash_set_mem (lgm->lisp_gpe_fwd_entries, lfe->key, - lfe - lgm->lisp_fwd_entry_pool); - a->fwd_entry_index = lfe - lgm->lisp_fwd_entry_pool; - - lfe->type = (a->is_negative ? - LISP_GPE_FWD_ENTRY_TYPE_NEGATIVE : - LISP_GPE_FWD_ENTRY_TYPE_NORMAL); - lfe->tenant = 0; - - if (LISP_GPE_FWD_ENTRY_TYPE_NEGATIVE != lfe->type) - { - fib_route_path_t *rpaths; - - /* - * Make the sorted array of LISP paths with their resp. adjacency - */ - lisp_gpe_fwd_entry_mk_paths (lfe, a); - - /* - * From the LISP paths, construct a FIB path list that will - * contribute a load-balance. - */ - rpaths = lisp_gpe_mk_fib_paths (lfe->paths); - - lfe->nsh.path_list_index = - fib_path_list_create (FIB_PATH_LIST_FLAG_NONE, rpaths); - - /* - * become a child of the path-list so we receive updates when - * its forwarding state changes. this includes an implicit lock. - */ - lfe->nsh.child_index = - fib_path_list_child_add (lfe->nsh.path_list_index, - FIB_NODE_TYPE_LISP_GPE_FWD_ENTRY, - lfe - lgm->lisp_fwd_entry_pool); - } - else - { - lfe->action = a->action; - } - - lisp_gpe_nsh_update_fwding (lfe); - - return 0; -} - -/** - * @brief conver from the embedded fib_node_t struct to the LSIP entry - */ -static lisp_gpe_fwd_entry_t * -lisp_gpe_fwd_entry_from_fib_node (fib_node_t * node) -{ - return ((lisp_gpe_fwd_entry_t *) (((char *) node) - - STRUCT_OFFSET_OF (lisp_gpe_fwd_entry_t, - node))); -} - -/** - * @brief Function invoked during a backwalk of the FIB graph - */ -static fib_node_back_walk_rc_t -lisp_gpe_fib_node_back_walk (fib_node_t * node, - fib_node_back_walk_ctx_t * ctx) -{ - lisp_gpe_fwd_entry_t *lfe = lisp_gpe_fwd_entry_from_fib_node (node); - - if (fid_addr_type (&lfe->key->rmt) == FID_ADDR_MAC) - lisp_gpe_l2_update_fwding (lfe); - else if (fid_addr_type (&lfe->key->rmt) == FID_ADDR_NSH) - lisp_gpe_nsh_update_fwding (lfe); - - return (FIB_NODE_BACK_WALK_CONTINUE); -} - -/** - * @brief Get a fib_node_t struct from the index of a LISP fwd entry - */ -static fib_node_t * -lisp_gpe_fwd_entry_get_fib_node (fib_node_index_t index) -{ - lisp_gpe_main_t *lgm = &lisp_gpe_main; - lisp_gpe_fwd_entry_t *lfe; - - lfe = pool_elt_at_index (lgm->lisp_fwd_entry_pool, index); - - return (&(lfe->node)); -} - -/** - * @brief An indication from the graph that the last lock has gone - */ -static void -lisp_gpe_fwd_entry_fib_node_last_lock_gone (fib_node_t * node) -{ - /* We don't manage the locks of the LISP objects via the graph, since - * this object has no children. so this is a no-op. */ -} - -/** - * @brief Virtual function table to register with FIB for the LISP type - */ -const static fib_node_vft_t lisp_fwd_vft = { - .fnv_get = lisp_gpe_fwd_entry_get_fib_node, - .fnv_last_lock = lisp_gpe_fwd_entry_fib_node_last_lock_gone, - .fnv_back_walk = lisp_gpe_fib_node_back_walk, -}; - -/** - * @brief Forwarding entry create/remove dispatcher. - * - * Calls l2 or l3 forwarding entry add/del function based on input data. - * - * @param[in] a Forwarding entry parameters. - * @param[out] hw_if_indexp NOT USED - * - * @return 0 on success. - */ -int -vnet_lisp_gpe_add_del_fwd_entry (vnet_lisp_gpe_add_del_fwd_entry_args_t * a, - u32 * hw_if_indexp) -{ - lisp_gpe_main_t *lgm = &lisp_gpe_main; - u8 type; - - if (vnet_lisp_gpe_enable_disable_status () == 0) - { - clib_warning ("LISP is disabled!"); - return VNET_API_ERROR_LISP_DISABLED; - } - - type = gid_address_type (&a->rmt_eid); - switch (type) - { - case GID_ADDR_IP_PREFIX: - if (a->is_add) - return add_ip_fwd_entry (lgm, a); - else - return del_ip_fwd_entry (lgm, a); - break; - case GID_ADDR_MAC: - if (a->is_add) - return add_l2_fwd_entry (lgm, a); - else - return del_l2_fwd_entry (lgm, a); - case GID_ADDR_NSH: - if (a->is_add) - return add_nsh_fwd_entry (lgm, a); - else - return del_nsh_fwd_entry (lgm, a); - default: - clib_warning ("Forwarding entries for type %d not supported!", type); - return -1; - } -} - -int -vnet_lisp_flush_stats (void) -{ - lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main (); - vlib_combined_counter_main_t *cm = &lgm->counters; - u32 i; - - if (cm->counters == NULL) - return 0; - - for (i = 0; i < vlib_combined_counter_n_counters (cm); i++) - vlib_zero_combined_counter (cm, i); - - return 0; -} - -static void -lisp_del_adj_stats (lisp_gpe_main_t * lgm, u32 fwd_entry_index, u32 ti) -{ - hash_pair_t *hp; - lisp_stats_key_t key; - void *key_copy; - uword *p; - u8 *s; - - clib_memset (&key, 0, sizeof (key)); - key.fwd_entry_index = fwd_entry_index; - key.tunnel_index = ti; - - p = hash_get_mem (lgm->lisp_stats_index_by_key, &key); - if (p) - { - s = pool_elt_at_index (lgm->placeholder_stats_pool, p[0]); - hp = hash_get_pair (lgm->lisp_stats_index_by_key, &key); - key_copy = (void *) (hp->key); - hash_unset_mem (lgm->lisp_stats_index_by_key, &key); - clib_mem_free (key_copy); - pool_put (lgm->placeholder_stats_pool, s); - } -} - -void -vnet_lisp_gpe_del_fwd_counters (vnet_lisp_gpe_add_del_fwd_entry_args_t * a, - u32 fwd_entry_index) -{ - lisp_gpe_main_t *lgm = &lisp_gpe_main; - lisp_gpe_fwd_entry_key_t fe_key; - lisp_gpe_fwd_entry_t *lfe; - lisp_fwd_path_t *path; - const lisp_gpe_adjacency_t *ladj; - - lfe = find_fwd_entry (lgm, a, &fe_key); - if (!lfe) - return; - - if (LISP_GPE_FWD_ENTRY_TYPE_NORMAL != lfe->type) - return; - - vec_foreach (path, lfe->paths) - { - ladj = lisp_gpe_adjacency_get (path->lisp_adj); - lisp_del_adj_stats (lgm, fwd_entry_index, ladj->tunnel_index); - } -} - -/** - * @brief Flush all the forwrding entries - */ -void -vnet_lisp_gpe_fwd_entry_flush (void) -{ - lisp_gpe_main_t *lgm = &lisp_gpe_main; - lisp_gpe_fwd_entry_t *lfe; - - /* *INDENT-OFF* */ - pool_foreach (lfe, lgm->lisp_fwd_entry_pool, - ({ - switch (fid_addr_type(&lfe->key->rmt)) - { - case FID_ADDR_MAC: - del_l2_fwd_entry_i (lgm, lfe); - break; - case FID_ADDR_IP_PREF: - del_ip_fwd_entry_i (lgm, lfe); - break; - case FID_ADDR_NSH: - del_nsh_fwd_entry_i (lgm, lfe); - break; - } - })); - /* *INDENT-ON* */ -} - -static u8 * -format_lisp_fwd_path (u8 * s, va_list * ap) -{ - lisp_fwd_path_t *lfp = va_arg (*ap, lisp_fwd_path_t *); - - s = format (s, "weight:%d ", lfp->weight); - s = format (s, "adj:[%U]\n", - format_lisp_gpe_adjacency, - lisp_gpe_adjacency_get (lfp->lisp_adj), - LISP_GPE_ADJ_FORMAT_FLAG_NONE); - - return (s); -} - -typedef enum lisp_gpe_fwd_entry_format_flag_t_ -{ - LISP_GPE_FWD_ENTRY_FORMAT_NONE = (0 << 0), - LISP_GPE_FWD_ENTRY_FORMAT_DETAIL = (1 << 1), -} lisp_gpe_fwd_entry_format_flag_t; - - -static u8 * -format_lisp_gpe_fwd_entry (u8 * s, va_list * ap) -{ - lisp_gpe_main_t *lgm = &lisp_gpe_main; - lisp_gpe_fwd_entry_t *lfe = va_arg (*ap, lisp_gpe_fwd_entry_t *); - lisp_gpe_fwd_entry_format_flag_t flags = - va_arg (*ap, lisp_gpe_fwd_entry_format_flag_t); - - s = format (s, "VNI:%d VRF:%d EID: %U -> %U [index:%d]", - lfe->key->vni, lfe->eid_table_id, - format_fid_address, &lfe->key->lcl, - format_fid_address, &lfe->key->rmt, - lfe - lgm->lisp_fwd_entry_pool); - - if (LISP_GPE_FWD_ENTRY_TYPE_NEGATIVE == lfe->type) - { - s = format (s, "\n Negative - action:%U", - format_negative_mapping_action, lfe->action); - } - else - { - lisp_fwd_path_t *path; - - s = format (s, "\n via:"); - vec_foreach (path, lfe->paths) - { - s = format (s, "\n %U", format_lisp_fwd_path, path); - } - } - - if (flags & LISP_GPE_FWD_ENTRY_FORMAT_DETAIL) - { - switch (fid_addr_type (&lfe->key->rmt)) - { - case FID_ADDR_MAC: - s = format (s, " fib-path-list:%d\n", lfe->l2.path_list_index); - s = format (s, " dpo:%U\n", format_dpo_id, &lfe->l2.dpo, 0); - break; - case FID_ADDR_NSH: - s = format (s, " fib-path-list:%d\n", lfe->nsh.path_list_index); - s = format (s, " dpo:%U\n", format_dpo_id, &lfe->nsh.dpo, 0); - break; - case FID_ADDR_IP_PREF: - break; - } - } - - return (s); -} - -static clib_error_t * -lisp_gpe_fwd_entry_show (vlib_main_t * vm, - unformat_input_t * input, vlib_cli_command_t * cmd) -{ - lisp_gpe_main_t *lgm = &lisp_gpe_main; - lisp_gpe_fwd_entry_t *lfe; - index_t index; - u32 vni = ~0; - - if (unformat (input, "vni %d", &vni)) - ; - else if (unformat (input, "%d", &index)) - { - if (!pool_is_free_index (lgm->lisp_fwd_entry_pool, index)) - { - lfe = pool_elt_at_index (lgm->lisp_fwd_entry_pool, index); - - vlib_cli_output (vm, "[%d@] %U", - index, - format_lisp_gpe_fwd_entry, lfe, - LISP_GPE_FWD_ENTRY_FORMAT_DETAIL); - } - else - { - vlib_cli_output (vm, "entry %d invalid", index); - } - - return (NULL); - } - - /* *INDENT-OFF* */ - pool_foreach (lfe, lgm->lisp_fwd_entry_pool, - ({ - if ((vni == ~0) || - (lfe->key->vni == vni)) - vlib_cli_output (vm, "%U", format_lisp_gpe_fwd_entry, lfe, - LISP_GPE_FWD_ENTRY_FORMAT_NONE); - })); - /* *INDENT-ON* */ - - return (NULL); -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (lisp_gpe_fwd_entry_show_command, static) = { - .path = "show gpe entry", - .short_help = "show gpe entry vni vrf [leid ] reid ", - .function = lisp_gpe_fwd_entry_show, -}; -/* *INDENT-ON* */ - -clib_error_t * -lisp_gpe_fwd_entry_init (vlib_main_t * vm) -{ - lisp_gpe_main_t *lgm = &lisp_gpe_main; - clib_error_t *error = NULL; - - if ((error = vlib_call_init_function (vm, lisp_cp_dpo_module_init))) - return (error); - - l2_fib_init (lgm); - nsh_fib_init (lgm); - - fib_node_register_type (FIB_NODE_TYPE_LISP_GPE_FWD_ENTRY, &lisp_fwd_vft); - - return (error); -} - -u32 * -vnet_lisp_gpe_get_fwd_entry_vnis (void) -{ - lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main (); - lisp_gpe_fwd_entry_t *lfe; - u32 *vnis = 0; - - /* *INDENT-OFF* */ - pool_foreach (lfe, lgm->lisp_fwd_entry_pool, - ({ - hash_set (vnis, lfe->key->vni, 0); - })); - /* *INDENT-ON* */ - - return vnis; -} - -lisp_api_gpe_fwd_entry_t * -vnet_lisp_gpe_fwd_entries_get_by_vni (u32 vni) -{ - lisp_gpe_main_t *lgm = &lisp_gpe_main; - lisp_gpe_fwd_entry_t *lfe; - lisp_api_gpe_fwd_entry_t *entries = 0, e; - - /* *INDENT-OFF* */ - pool_foreach (lfe, lgm->lisp_fwd_entry_pool, - ({ - if (lfe->key->vni == vni) - { - clib_memset (&e, 0, sizeof (e)); - e.dp_table = lfe->eid_table_id; - e.vni = lfe->key->vni; - if (lfe->type == LISP_GPE_FWD_ENTRY_TYPE_NEGATIVE) - e.action = lfe->action; - e.fwd_entry_index = lfe - lgm->lisp_fwd_entry_pool; - memcpy (&e.reid, &lfe->key->rmt, sizeof (e.reid)); - memcpy (&e.leid, &lfe->key->lcl, sizeof (e.leid)); - vec_add1 (entries, e); - } - })); - /* *INDENT-ON* */ - - return entries; -} - -int -vnet_lisp_gpe_get_fwd_stats (vnet_lisp_gpe_add_del_fwd_entry_args_t * a, - vlib_counter_t * c) -{ - lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main (); - lisp_gpe_fwd_entry_t *lfe; - lisp_gpe_fwd_entry_key_t unused; - - lfe = find_fwd_entry (lgm, a, &unused); - if (NULL == lfe) - return -1; - - if (LISP_GPE_FWD_ENTRY_TYPE_NEGATIVE == lfe->type) - return -1; - - if (~0 == lfe->dpoi_index) - return -1; - - vlib_get_combined_counter (&load_balance_main.lbm_to_counters, - lfe->dpoi_index, c); - return 0; -} - -VLIB_INIT_FUNCTION (lisp_gpe_fwd_entry_init); - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/src/vnet/lisp-gpe/lisp_gpe_fwd_entry.h b/src/vnet/lisp-gpe/lisp_gpe_fwd_entry.h deleted file mode 100644 index dfdb8b911ae..00000000000 --- a/src/vnet/lisp-gpe/lisp_gpe_fwd_entry.h +++ /dev/null @@ -1,240 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @file - * @brief LISP-GPE definitions. - */ - -#ifndef __LISP_GPE_FWD_ENTRY_H__ -#define __LISP_GPE_FWD_ENTRY_H__ - -#include - -/** - * @brief A path on which to forward lisp traffic - */ -typedef struct lisp_fwd_path_t_ -{ - /** - * The adjacency constructed for the locator pair - */ - index_t lisp_adj; - - /** - * Priority. Only the paths with the best priority will be installed in FIB - */ - u8 priority; - - /** - * [UE]CMP weigt for the path - */ - u8 weight; - -} lisp_fwd_path_t; - -/** - * @brief A Forwarding entry can be 'normal' or 'negative' - * Negative implies we deliberately want to add a FIB entry for an EID - * that results in 'special' behaviour determined by an 'action'. - * @normal means send it down some tunnels. - */ -typedef enum lisp_gpe_fwd_entry_type_t_ -{ - LISP_GPE_FWD_ENTRY_TYPE_NORMAL, - LISP_GPE_FWD_ENTRY_TYPE_NEGATIVE, -} lisp_gpe_fwd_entry_type_t; - - -/** - * LISP-GPE fwd entry key - */ -typedef struct lisp_gpe_fwd_entry_key_t_ -{ - dp_address_t rmt; - dp_address_t lcl; - u32 vni; -} lisp_gpe_fwd_entry_key_t; - -/** - * @brief A LISP Forwarding Entry - * - * A forwarding entry is from a locai EID to a remote EID over a set of rloc pairs - */ -typedef struct lisp_gpe_fwd_entry_t_ -{ - /** - * Follows src/dst or dst only forwarding policy - */ - u8 is_src_dst; - - /** - * This object joins the FIB control plane graph to receive updates to - * for changes to the graph. - */ - fib_node_t node; - - /** - * The Entry's key: {lEID,rEID,vni} - */ - lisp_gpe_fwd_entry_key_t *key; - - /** - * The forwarding entry type - */ - lisp_gpe_fwd_entry_type_t type; - - /** - * The tenant the entry belongs to - */ - u32 tenant; - - /** - * The VRF (in the case of L3) or Bridge-Domain (for L2) index - */ - union - { - /** - * Fields relevant to an L2 entry - */ - struct - { - /** - * The VRF ID - */ - u32 eid_table_id; - - /** - * The FIB index for the overlay, i.e. the FIB in which the EIDs - * are present - */ - u32 eid_fib_index; - /** - * The SRC-FIB index for created for anding source-route entries - */ - u32 src_fib_index; - }; - /** - * Fields relevant to an L2 entry - */ - struct - { - /** - * The Bridge-Domain (for L2) index - */ - u32 eid_bd_id; - - /** - * The Bridge-domain index for the overlay EIDs - */ - u32 eid_bd_index; - - /** - * The path-list created for the forwarding - */ - fib_node_index_t path_list_index; - - /** - * Child index of this entry on the path-list - */ - u32 child_index; - - /** - * The DPO used to forward - */ - dpo_id_t dpo; - } l2; - - /** - * Fields relevant to an NSH entry - */ - struct - { - /** - * The path-list created for the forwarding - */ - fib_node_index_t path_list_index; - - /** - * Child index of this entry on the path-list - */ - u32 child_index; - - /** - * The DPO contributed by NSH - */ - dpo_id_t dpo; - - /** - * The DPO used for forwarding. Obtained after stacking tx node - * onto lb choice - */ - dpo_id_t choice; - } nsh; - }; - - union - { - /** - * @brief When the type is 'normal' - * The RLOC pair that form the route's paths. i.e. where to send - * packets for this route. - */ - lisp_fwd_path_t *paths; - - /** - * @brief When the type is negative. The action to take. - */ - negative_fwd_actions_e action; - }; - - /** - * used for getting load balance statistics - */ - index_t dpoi_index; - -} lisp_gpe_fwd_entry_t; - -extern int -vnet_lisp_gpe_add_del_fwd_entry (vnet_lisp_gpe_add_del_fwd_entry_args_t * a, - u32 * hw_if_indexp); - -extern void vnet_lisp_gpe_fwd_entry_flush (void); - -extern u32 lisp_l2_fib_lookup (lisp_gpe_main_t * lgm, - u16 bd_index, u8 src_mac[8], u8 dst_mac[8]); - -extern const dpo_id_t *lisp_nsh_fib_lookup (lisp_gpe_main_t * lgm, - u32 spi_si); -extern void -vnet_lisp_gpe_del_fwd_counters (vnet_lisp_gpe_add_del_fwd_entry_args_t * a, - u32 fwd_entry_index); -extern void -vnet_lisp_gpe_add_fwd_counters (vnet_lisp_gpe_add_del_fwd_entry_args_t * a, - u32 fwd_entry_index); -extern u32 *vnet_lisp_gpe_get_fwd_entry_vnis (void); - -int -vnet_lisp_gpe_get_fwd_stats (vnet_lisp_gpe_add_del_fwd_entry_args_t * a, - vlib_counter_t * c); - -#endif - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/src/vnet/lisp-gpe/lisp_gpe_packet.h b/src/vnet/lisp-gpe/lisp_gpe_packet.h deleted file mode 100644 index 62ac9bd7015..00000000000 --- a/src/vnet/lisp-gpe/lisp_gpe_packet.h +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @file - * @brief LISP-GPE packet header structure - * - */ - -#ifndef included_lisp_gpe_packet_h -#define included_lisp_gpe_packet_h - -/* - * From draft-lewis-lisp-gpe-02.txt - * - * 0 1 2 3 - * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * |N|L|E|V|I|P|R|O|Ver| Reserved | Next Protocol | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Instance ID/Locator-Status-Bits | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * - * N: The N-bit is the nonce-present bit. When this bit is set to 1, - * the low-order 24 bits of the first 32 bits of the LISP header - * contain a Nonce. See Section 6.3.1 for details. Both N- and - * V-bits MUST NOT be set in the same packet. If they are, a - * decapsulating ETR MUST treat the 'Nonce/Map-Version' field as - * having a Nonce value present. - * - * L: The L-bit is the 'Locator-Status-Bits' field enabled bit. When - * this bit is set to 1, the Locator-Status-Bits in the second - * 32 bits of the LISP header are in use. - * - * E: The E-bit is the echo-nonce-request bit. This bit MUST be ignored - * and has no meaning when the N-bit is set to 0. When the N-bit is - * set to 1 and this bit is set to 1, an ITR is requesting that the - * nonce value in the 'Nonce' field be echoed back in LISP- - * encapsulated packets when the ITR is also an ETR. See - * Section 6.3.1 for details. - * - * V: The V-bit is the Map-Version present bit. When this bit is set to - * 1, the N-bit MUST be 0. Refer to Section 6.6.3 for more details. - * - * I: The I-bit is the Instance ID bit. See Section 5.5 for more - * details. When this bit is set to 1, the 'Locator-Status-Bits' - * field is reduced to 8 bits and the high-order 24 bits are used as - * an Instance ID. If the L-bit is set to 0, then the low-order - * 8 bits are transmitted as zero and ignored on receipt. - * - * P Bit: Flag bit 5 is defined as the Next Protocol bit. The P bit - * MUST be set to 1 to indicate the presence of the 8 bit next - * protocol field. - * - * P = 0 indicates that the payload MUST conform to LISP as defined - * in [RFC6830]. - * - * Flag bit 5 was chosen as the P bit because this flag bit is - * currently unallocated in LISP [RFC6830]. - * - * O: Flag bit 7 is defined as the O bit. When the O bit is set to 1, the - * packet is an OAM packet and OAM processing MUST occur. The OAM - * protocol details are out of scope for this document. As with the - * P-bit, bit 7 is currently a reserved flag in [RFC6830]. - * - * Next Protocol Field: The lower 8 bits of the first word are used to - * carry a next protocol. This next protocol field contains the - * protocol of the encapsulated payload packet. - * - * LISP [RFC6830] uses the lower 16 bits of the first word for either - * a nonce, an echo-nonce ([RFC6830]) or to support map-versioning - * ([RFC6834]). These are all optional capabilities that are - * indicated by setting the N, E, and the V bit respectively. - * - * To maintain the desired data plane compatibility, when the P bit - * is set, the N, E, and V bits MUST be set to zero. - * - * A new protocol registry will be requested from IANA for the Next - * Protocol field. This draft defines the following Next Protocol - * values: - * - * 0x1 : IPv4 - * 0x2 : IPv6 - * 0x3 : Ethernet - * 0x4: Network Service Header - */ - -/** LISP-GPE header */ -typedef struct -{ - u8 flags; - u8 ver_res; - u8 res; - u8 next_protocol; - u32 iid; -} lisp_gpe_header_t; - -#define foreach_lisp_gpe_flag_bit \ -_(N, 0x80) \ -_(L, 0x40) \ -_(E, 0x20) \ -_(V, 0x10) \ -_(I, 0x08) \ -_(P, 0x04) \ -_(O, 0x01) - -typedef enum -{ -#define _(n,v) LISP_GPE_FLAGS_##n = v, - foreach_lisp_gpe_flag_bit -#undef _ -} vnet_lisp_gpe_flag_bit_t; - -#define LISP_GPE_VERSION 0x0 - -#define LISP_GPE_NEXT_PROTOCOL_IP4 0x1 -#define LISP_GPE_NEXT_PROTOCOL_IP6 0x2 -#define LISP_GPE_NEXT_PROTOCOL_ETHERNET 0x3 -#define LISP_GPE_NEXT_PROTOCOL_NSH 0x4 - -typedef enum -{ - LISP_GPE_NEXT_PROTO_IP4 = 1, - LISP_GPE_NEXT_PROTO_IP6, - LISP_GPE_NEXT_PROTO_ETHERNET, - LISP_GPE_NEXT_PROTO_NSH, - LISP_GPE_NEXT_PROTOS -} lisp_gpe_next_protocol_e; - -#endif /* included_lisp_gpe_packet_h */ - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/src/vnet/lisp-gpe/lisp_gpe_sub_interface.c b/src/vnet/lisp-gpe/lisp_gpe_sub_interface.c deleted file mode 100644 index 1ccd5817d7f..00000000000 --- a/src/vnet/lisp-gpe/lisp_gpe_sub_interface.c +++ /dev/null @@ -1,286 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @file - * @brief LISP sub-interfaces. - * - */ -#include -#include -#include -#include - -/** - * @brief Pool of all l3-sub-interfaces - */ -static lisp_gpe_sub_interface_t *lisp_gpe_sub_interface_pool; - -/** - * A DB of all LISP L3 sub-interfaces. The key is:{VNI,l-RLOC} - */ -static uword *lisp_gpe_sub_interfaces; - -/** - * A DB of all VNET L3 sub-interfaces. The key is:{VNI,l-RLOC} - * Used in the data-plane for interface lookup on decap. - */ -uword *lisp_gpe_sub_interfaces_sw_if_index; - -/** - * The next available sub-interface ID. FIXME - */ -static u32 lisp_gpe_sub_interface_id; - - -static index_t -lisp_gpe_sub_interface_db_find (const ip_address_t * lrloc, u32 vni) -{ - uword *p; - - lisp_gpe_sub_interface_key_t key; - - clib_memset (&key, 0, sizeof (key)); - ip_address_copy (&key.local_rloc, lrloc); - key.vni = vni; - p = hash_get_mem (lisp_gpe_sub_interfaces, &key); - - if (NULL == p) - return (INDEX_INVALID); - else - return (p[0]); -} - -static void -lisp_gpe_sub_interface_db_insert (const lisp_gpe_sub_interface_t * l3s) -{ - hash_set_mem (lisp_gpe_sub_interfaces, - l3s->key, l3s - lisp_gpe_sub_interface_pool); - hash_set_mem (lisp_gpe_sub_interfaces_sw_if_index, - l3s->key, l3s->sw_if_index); -} - -static void -lisp_gpe_sub_interface_db_remove (const lisp_gpe_sub_interface_t * l3s) -{ - hash_unset_mem (lisp_gpe_sub_interfaces, l3s->key); - hash_unset_mem (lisp_gpe_sub_interfaces_sw_if_index, l3s->key); -} - -lisp_gpe_sub_interface_t * -lisp_gpe_sub_interface_get_i (index_t l3si) -{ - return (pool_elt_at_index (lisp_gpe_sub_interface_pool, l3si)); -} - -static void -lisp_gpe_sub_interface_set_table (u32 sw_if_index, u32 table_id) -{ - fib_node_index_t fib_index; - - fib_index = fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP4, table_id, - FIB_SOURCE_LISP); - ASSERT (FIB_NODE_INDEX_INVALID != fib_index); - - vec_validate (ip4_main.fib_index_by_sw_if_index, sw_if_index); - ip4_main.fib_index_by_sw_if_index[sw_if_index] = fib_index; - - fib_index = fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP6, table_id, - FIB_SOURCE_LISP); - ASSERT (FIB_NODE_INDEX_INVALID != fib_index); - - vec_validate (ip6_main.fib_index_by_sw_if_index, sw_if_index); - ip6_main.fib_index_by_sw_if_index[sw_if_index] = fib_index; -} - -static void -lisp_gpe_sub_interface_unset_table (u32 sw_if_index, u32 table_id) -{ - fib_table_unlock (ip4_main.fib_index_by_sw_if_index[sw_if_index], - FIB_PROTOCOL_IP4, FIB_SOURCE_LISP); - ip4_main.fib_index_by_sw_if_index[sw_if_index] = 0; - ip4_sw_interface_enable_disable (sw_if_index, 0); - - fib_table_unlock (ip6_main.fib_index_by_sw_if_index[sw_if_index], - FIB_PROTOCOL_IP6, FIB_SOURCE_LISP); - ip6_main.fib_index_by_sw_if_index[sw_if_index] = 0; - ip6_sw_interface_enable_disable (sw_if_index, 0); -} - -index_t -lisp_gpe_sub_interface_find_or_create_and_lock (const ip_address_t * lrloc, - u32 overlay_table_id, u32 vni) -{ - lisp_gpe_sub_interface_t *l3s; - index_t l3si; - - l3si = lisp_gpe_sub_interface_db_find (lrloc, vni); - - if (INDEX_INVALID == l3si) - { - u32 main_sw_if_index, sub_sw_if_index; - - /* - * find the main interface from the VNI - */ - main_sw_if_index = - lisp_gpe_tenant_l3_iface_add_or_lock (vni, overlay_table_id, - 1 /* with_default_route */ ); - - vnet_sw_interface_t sub_itf_template = { - .type = VNET_SW_INTERFACE_TYPE_SUB, - .flood_class = VNET_FLOOD_CLASS_NORMAL, - .sup_sw_if_index = main_sw_if_index, - .sub.id = lisp_gpe_sub_interface_id++, - }; - - if (NULL != vnet_create_sw_interface (vnet_get_main (), - &sub_itf_template, - &sub_sw_if_index)) - return (INDEX_INVALID); - - pool_get (lisp_gpe_sub_interface_pool, l3s); - clib_memset (l3s, 0, sizeof (*l3s)); - l3s->key = clib_mem_alloc (sizeof (*l3s->key)); - clib_memset (l3s->key, 0, sizeof (*l3s->key)); - - ip_address_copy (&l3s->key->local_rloc, lrloc); - l3s->key->vni = vni; - l3s->main_sw_if_index = main_sw_if_index; - l3s->sw_if_index = sub_sw_if_index; - l3s->eid_table_id = overlay_table_id; - - l3si = (l3s - lisp_gpe_sub_interface_pool); - - // FIXME. enable When we get an adj - ip6_sw_interface_enable_disable (l3s->sw_if_index, 1); - ip4_sw_interface_enable_disable (l3s->sw_if_index, 1); - - vnet_sw_interface_set_flags (vnet_get_main (), - l3s->sw_if_index, - VNET_SW_INTERFACE_FLAG_ADMIN_UP); - - lisp_gpe_sub_interface_db_insert (l3s); - } - else - { - l3s = lisp_gpe_sub_interface_get_i (l3si); - l3s->eid_table_id = overlay_table_id; - } - - lisp_gpe_sub_interface_set_table (l3s->sw_if_index, l3s->eid_table_id); - l3s->locks++; - - return (l3si); -} - -void -lisp_gpe_sub_interface_unlock (index_t l3si) -{ - lisp_gpe_sub_interface_t *l3s; - - l3s = lisp_gpe_sub_interface_get_i (l3si); - - ASSERT (0 != l3s->locks); - l3s->locks--; - - if (0 == l3s->locks) - { - lisp_gpe_sub_interface_unset_table (l3s->sw_if_index, - l3s->eid_table_id); - - lisp_gpe_tenant_l3_iface_unlock (l3s->key->vni); - vnet_sw_interface_set_flags (vnet_get_main (), l3s->sw_if_index, 0); - vnet_delete_sub_interface (l3s->sw_if_index); - - lisp_gpe_sub_interface_db_remove (l3s); - - clib_mem_free (l3s->key); - pool_put (lisp_gpe_sub_interface_pool, l3s); - } -} - -const lisp_gpe_sub_interface_t * -lisp_gpe_sub_interface_get (index_t l3si) -{ - return (lisp_gpe_sub_interface_get_i (l3si)); -} - -u8 * -format_lisp_gpe_sub_interface (u8 * s, va_list * ap) -{ - lisp_gpe_sub_interface_t *l3s = va_arg (*ap, lisp_gpe_sub_interface_t *); - vnet_main_t *vnm = vnet_get_main (); - - s = format (s, "%-16U", - format_vnet_sw_interface_name, - vnm, vnet_get_sw_interface (vnm, l3s->sw_if_index)); - s = format (s, "%=8d", l3s->key->vni); - s = format (s, "%=15d", l3s->sw_if_index); - s = format (s, "%U", format_ip_address, &l3s->key->local_rloc); - - return (s); -} - -/** CLI command to show LISP-GPE interfaces. */ -static clib_error_t * -lisp_gpe_sub_interface_show (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - lisp_gpe_sub_interface_t *l3s; - - vlib_cli_output (vm, "%-16s%=8s%=15s%s", "Name", "VNI", "sw_if_index", - "local RLOC"); - - /* *INDENT-OFF* */ - pool_foreach (l3s, lisp_gpe_sub_interface_pool, - ({ - vlib_cli_output (vm, "%U", format_lisp_gpe_sub_interface, l3s); - })); - /* *INDENT-ON* */ - - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (lisp_gpe_sub_interface_command) = { - .path = "show gpe sub-interface", - .short_help = "show gpe sub-interface", - .function = lisp_gpe_sub_interface_show, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_gpe_sub_interface_module_init (vlib_main_t * vm) -{ - lisp_gpe_sub_interfaces = - hash_create_mem (0, - sizeof (lisp_gpe_sub_interface_key_t), sizeof (uword)); - lisp_gpe_sub_interfaces_sw_if_index = - hash_create_mem (0, - sizeof (lisp_gpe_sub_interface_key_t), sizeof (uword)); - - return (NULL); -} - -VLIB_INIT_FUNCTION (lisp_gpe_sub_interface_module_init); - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/src/vnet/lisp-gpe/lisp_gpe_sub_interface.h b/src/vnet/lisp-gpe/lisp_gpe_sub_interface.h deleted file mode 100644 index 7375bf00ccc..00000000000 --- a/src/vnet/lisp-gpe/lisp_gpe_sub_interface.h +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @file - * @brief LISP sub-interfaces. - * - */ - -#ifndef __LISP_GPE_SUB_INTERFACE_H__ -#define __LISP_GPE_SUB_INTERFACE_H__ - -#include - -/** - * A Key for lookup in the L£ sub-interface DB - */ -typedef struct lisp_gpe_sub_interface_key_t_ -{ - /** - * The local-RLOC. This is the interface's 'source' address. - */ - ip_address_t local_rloc; - - /** - * The VNI. In network byte order! - */ - u32 vni; -} lisp_gpe_sub_interface_key_t; - -/** - * @brief A LISP L3 sub-interface - * - * A LISP sub-interface is a multi-access interface, whose local address is a - * single local-RLOC. Adjacencies that form on this sub-interface, represent - * remote RLOCs. - * This is analogous to an ethernet interface. - * As with all interface types it can only be present in one VRF, hence a - * LISP sub-interface is per-local-rloc and per-VNI. - */ -typedef struct lisp_gpe_sub_interface_t_ -{ - /** - * The interface's key inthe DB; rloc & vni; - * The key is allocated from the heap so it can be used in the hash-table. - * if it's part of the object, then it is subjet to realloc, which no-worky. - */ - lisp_gpe_sub_interface_key_t *key; - - /** - * The Table-ID in the overlay that this interface is bound to. - */ - u32 eid_table_id; - - /** - * A reference counting lock on the number of users of this interface. - * When this count drops to 0 the interface is deleted. - */ - u32 locks; - - /** - * The SW if index assigned to this sub-interface - */ - u32 sw_if_index; - - /** - * The SW IF index assigned to the main interface of which this is a sub. - */ - u32 main_sw_if_index; -} lisp_gpe_sub_interface_t; - -extern index_t lisp_gpe_sub_interface_find_or_create_and_lock (const - ip_address_t * - lrloc, - u32 - eid_table_id, - u32 vni); - -extern u8 *format_lisp_gpe_sub_interface (u8 * s, va_list * ap); - -extern void lisp_gpe_sub_interface_unlock (index_t itf); - -extern const lisp_gpe_sub_interface_t *lisp_gpe_sub_interface_get (index_t - itf); - -/** - * A DB of all L3 sub-interfaces. The key is:{VNI,l-RLOC} - */ -extern uword *lisp_gpe_sub_interfaces_sw_if_index; - -/** - * @brief - * Get a VNET L3 interface matching the local-RLOC and VNI - * Called from the data-plane - */ -always_inline u32 -lisp_gpe_sub_interface_find_ip6 (const ip6_address_t * addr, u32 vni) -{ - lisp_gpe_sub_interface_key_t key; - const uword *p; - - ip_addr_v6 (&key.local_rloc).as_u64[0] = addr->as_u64[0]; - ip_addr_v6 (&key.local_rloc).as_u64[1] = addr->as_u64[1]; - ip_addr_version (&key.local_rloc) = AF_IP6; - key.vni = vni; - - p = hash_get_mem (&lisp_gpe_sub_interfaces_sw_if_index, &key); - - if (NULL != p) - return p[0]; - - return (INDEX_INVALID); -} - -/** - * @brief - * Get a VNET L3 interface matching the local-RLOC and VNI - * Called from the data-plane - */ -always_inline index_t -lisp_gpe_sub_interface_find_ip4 (const ip4_address_t * addr, u32 vni) -{ - lisp_gpe_sub_interface_key_t key; - const uword *p; - - ip_addr_v4 (&key.local_rloc).as_u32 = addr->as_u32; - key.local_rloc.version = AF_IP4; - key.vni = vni; - - p = hash_get_mem (&lisp_gpe_sub_interfaces_sw_if_index, &key); - - if (NULL != p) - return p[0]; - - return (INDEX_INVALID); -} - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ - -#endif diff --git a/src/vnet/lisp-gpe/lisp_gpe_tenant.c b/src/vnet/lisp-gpe/lisp_gpe_tenant.c deleted file mode 100644 index e2a310c043c..00000000000 --- a/src/vnet/lisp-gpe/lisp_gpe_tenant.c +++ /dev/null @@ -1,333 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -/** - * The pool of all tenants - */ -static lisp_gpe_tenant_t *lisp_gpe_tenant_pool; - -/** - * The hash table of all tenants: key:{VNI}. - */ -uword *lisp_gpe_tenant_db; - -static lisp_gpe_tenant_t * -lisp_gpe_tenant_find (u32 vni) -{ - uword *p; - - p = hash_get (lisp_gpe_tenant_db, vni); - - if (NULL == p) - return (NULL); - - return (pool_elt_at_index (lisp_gpe_tenant_pool, p[0])); -} - -static lisp_gpe_tenant_t * -lisp_gpe_tenant_find_or_create_i (u32 vni) -{ - lisp_gpe_tenant_t *lt; - - lt = lisp_gpe_tenant_find (vni); - - if (NULL == lt) - { - pool_get (lisp_gpe_tenant_pool, lt); - clib_memset (lt, 0, sizeof (*lt)); - - lt->lt_vni = vni; - lt->lt_table_id = ~0; - lt->lt_bd_id = ~0; - - hash_set (lisp_gpe_tenant_db, vni, lt - lisp_gpe_tenant_pool); - } - - return (lt); -} - -/** - * @brief Find or create a tenant for the given VNI - */ -u32 -lisp_gpe_tenant_find_or_create (u32 vni) -{ - lisp_gpe_tenant_t *lt; - - lt = lisp_gpe_tenant_find (vni); - - if (NULL == lt) - { - lt = lisp_gpe_tenant_find_or_create_i (vni); - } - - return (lt - lisp_gpe_tenant_pool); -} - -/** - * @brief If there are no more locks/users of te tenant, then delete it - */ -static void -lisp_gpe_tenant_delete_if_empty (lisp_gpe_tenant_t * lt) -{ - int i; - - for (i = 0; i < LISP_GPE_TENANT_LOCK_NUM; i++) - { - if (lt->lt_locks[i]) - return; - } - - hash_unset (lisp_gpe_tenant_db, lt->lt_vni); - pool_put (lisp_gpe_tenant_pool, lt); -} - -/** - * @brief Add/create and lock a new or find and lock the existing L3 - * interface for the tenant - * - * @paran vni The tenant's VNI - * @param table_id the Tenant's L3 table ID. - * @param with_default_route Install default route for the interface - * - * @return the SW IF index of the L3 interface - */ -u32 -lisp_gpe_tenant_l3_iface_add_or_lock (u32 vni, u32 table_id, - u8 with_default_route) -{ - lisp_gpe_tenant_t *lt; - - lt = lisp_gpe_tenant_find_or_create_i (vni); - - if (~0 == lt->lt_table_id) - lt->lt_table_id = table_id; - - ASSERT (lt->lt_table_id == table_id); - - if (0 == lt->lt_locks[LISP_GPE_TENANT_LOCK_L3_IFACE]) - { - /* create the l3 interface since there are currently no users of it */ - lt->lt_l3_sw_if_index = - lisp_gpe_add_l3_iface (&lisp_gpe_main, vni, table_id, - with_default_route); - } - - lt->lt_locks[LISP_GPE_TENANT_LOCK_L3_IFACE]++; - - return (lt->lt_l3_sw_if_index); -} - -/** - * @brief Release the lock held on the tenant's L3 interface - */ -void -lisp_gpe_tenant_l3_iface_unlock (u32 vni) -{ - lisp_gpe_tenant_t *lt; - - lt = lisp_gpe_tenant_find (vni); - - if (NULL == lt) - { - clib_warning ("No tenant for VNI %d", vni); - return; - } - - if (0 == lt->lt_locks[LISP_GPE_TENANT_LOCK_L3_IFACE]) - { - clib_warning ("No L3 interface for tenant VNI %d", vni); - return; - } - - lt->lt_locks[LISP_GPE_TENANT_LOCK_L3_IFACE]--; - - if (0 == lt->lt_locks[LISP_GPE_TENANT_LOCK_L3_IFACE]) - { - /* the last user has gone, so delete the l3 interface */ - lisp_gpe_del_l3_iface (&lisp_gpe_main, vni, lt->lt_table_id); - } - - /* - * If there are no more locks on any tenant managed resource, then - * this tenant is toast. - */ - lisp_gpe_tenant_delete_if_empty (lt); -} - -/** - * @brief Add/create and lock a new or find and lock the existing L2 - * interface for the tenant - * - * @paran vni The tenant's VNI - * @param table_id the Tenant's L2 Bridge Domain ID. - * - * @return the SW IF index of the L2 interface - */ -u32 -lisp_gpe_tenant_l2_iface_add_or_lock (u32 vni, u32 bd_id) -{ - lisp_gpe_tenant_t *lt; - - lt = lisp_gpe_tenant_find_or_create_i (vni); - - if (NULL == lt) - { - clib_warning ("No tenant for VNI %d", vni); - return ~0; - } - - if (~0 == lt->lt_bd_id) - lt->lt_bd_id = bd_id; - - ASSERT (lt->lt_bd_id == bd_id); - - if (0 == lt->lt_locks[LISP_GPE_TENANT_LOCK_L2_IFACE]) - { - /* create the l2 interface since there are currently no users of it */ - lt->lt_l2_sw_if_index = - lisp_gpe_add_l2_iface (&lisp_gpe_main, vni, bd_id); - } - - lt->lt_locks[LISP_GPE_TENANT_LOCK_L2_IFACE]++; - - return (lt->lt_l2_sw_if_index); -} - -/** - * @brief Release the lock held on the tenant's L3 interface - */ -void -lisp_gpe_tenant_l2_iface_unlock (u32 vni) -{ - lisp_gpe_tenant_t *lt; - - lt = lisp_gpe_tenant_find (vni); - - if (NULL == lt) - { - clib_warning ("No tenant for VNI %d", vni); - return; - } - - if (0 == lt->lt_locks[LISP_GPE_TENANT_LOCK_L2_IFACE]) - { - clib_warning ("No L2 interface for tenant VNI %d", vni); - return; - } - - lt->lt_locks[LISP_GPE_TENANT_LOCK_L2_IFACE]--; - - if (0 == lt->lt_locks[LISP_GPE_TENANT_LOCK_L2_IFACE]) - { - /* the last user has gone, so delete the l2 interface */ - lisp_gpe_del_l2_iface (&lisp_gpe_main, vni, lt->lt_bd_id); - } - - /* - * If there are no more locks on any tenant managed resource, then - * this tenant is toast. - */ - lisp_gpe_tenant_delete_if_empty (lt); -} - -/** - * @brief get a const pointer to the tenant object - */ -const lisp_gpe_tenant_t * -lisp_gpe_tenant_get (u32 index) -{ - return (pool_elt_at_index (lisp_gpe_tenant_pool, index)); -} - -/** - * @brief Flush/delete ALL the tenants - */ -void -lisp_gpe_tenant_flush (void) -{ - lisp_gpe_tenant_t *lt; - - /* *INDENT-OFF* */ - pool_foreach(lt, lisp_gpe_tenant_pool, - ({ - lisp_gpe_tenant_l2_iface_unlock(lt->lt_vni); - lisp_gpe_tenant_l3_iface_unlock(lt->lt_vni); - })); - /* *INDENT-ON* */ -} - -/** - * @brief Show/display one tenant - */ -static u8 * -format_lisp_gpe_tenant (u8 * s, va_list * ap) -{ - const lisp_gpe_tenant_t *lt = va_arg (*ap, lisp_gpe_tenant_t *); - - s = format (s, "VNI:%d ", lt->lt_vni); - - if (lt->lt_table_id != ~0) - { - s = format (s, "VRF:%d ", lt->lt_table_id); - s = format (s, "L3-SW-IF:%d ", lt->lt_l3_sw_if_index); - } - - if (lt->lt_bd_id != ~0) - { - s = format (s, "BD-ID:%d ", lt->lt_bd_id); - s = format (s, "L2-SW-IF:%d ", lt->lt_l2_sw_if_index); - } - - return (s); -} - -/** - * @brief CLI command to show LISP-GPE tenant. - */ -static clib_error_t * -lisp_gpe_tenant_show (vlib_main_t * vm, - unformat_input_t * input, vlib_cli_command_t * cmd) -{ - lisp_gpe_tenant_t *lt; - - /* *INDENT-OFF* */ - pool_foreach (lt, lisp_gpe_tenant_pool, - ({ - vlib_cli_output (vm, "%U", format_lisp_gpe_tenant, lt); - })); - /* *INDENT-ON* */ - - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (lisp_gpe_tenant_command) = { - .path = "show gpe tenant", - .short_help = "show gpe tenant", - .function = lisp_gpe_tenant_show, -}; -/* *INDENT-ON* */ - - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/src/vnet/lisp-gpe/lisp_gpe_tenant.h b/src/vnet/lisp-gpe/lisp_gpe_tenant.h deleted file mode 100644 index a9271da91f5..00000000000 --- a/src/vnet/lisp-gpe/lisp_gpe_tenant.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __LISP_GPE_TENANT_H__ -#define __LISP_GPE_TENANT_H__ - -#include - -/** - * Refernece counting lock types on the tenant. - * When all of these counters drop to zero, we no longer need the tenant. - */ -typedef enum lisp_gpe_tenant_lock_t_ -{ - LISP_GPE_TENANT_LOCK_L2_IFACE, - LISP_GPE_TENANT_LOCK_L3_IFACE, - LISP_GPE_TENANT_LOCK_NUM, -} lisp_gpe_tenant_lock_t; - -/** - * @brief Representation of the data associated with a LISP overlay tenant - * - * This object exists to manage the shared resources of the L2 and L3 interface - * of a given tenant. - */ -typedef struct lisp_gpe_tenant_t_ -{ - /** - * The VNI is the identifier of the tenant - */ - u32 lt_vni; - - /** - * The tenant can have both L2 and L3 services enabled. - */ - u32 lt_table_id; - u32 lt_bd_id; - - /** - * The number of locks on the tenant's L3 interface. - */ - u32 lt_locks[LISP_GPE_TENANT_LOCK_NUM]; - - /** - * The L3 SW interface index - */ - u32 lt_l3_sw_if_index; - - /** - * The L2 SW interface index - */ - u32 lt_l2_sw_if_index; - -} lisp_gpe_tenant_t; - -extern u32 lisp_gpe_tenant_find_or_create (u32 vni); - -extern u32 lisp_gpe_tenant_l3_iface_add_or_lock (u32 vni, u32 vrf, - u8 with_default_route); -extern void lisp_gpe_tenant_l3_iface_unlock (u32 vni); - -extern u32 lisp_gpe_tenant_l2_iface_add_or_lock (u32 vni, u32 vrf); -extern void lisp_gpe_tenant_l2_iface_unlock (u32 vni); - -extern const lisp_gpe_tenant_t *lisp_gpe_tenant_get (u32 index); - -extern void lisp_gpe_tenant_flush (void); - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ - -#endif diff --git a/src/vnet/lisp-gpe/lisp_gpe_tunnel.c b/src/vnet/lisp-gpe/lisp_gpe_tunnel.c deleted file mode 100644 index 0373542ba34..00000000000 --- a/src/vnet/lisp-gpe/lisp_gpe_tunnel.c +++ /dev/null @@ -1,293 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @file - * @brief Common utility functions for IPv4, IPv6 and L2 LISP-GPE tunnels. - * - */ -#include -#include -#include - -#include - -/** - * @brief Pool of all LISP tunnels - */ -static lisp_gpe_tunnel_t *lisp_gpe_tunnel_pool; - -/** - * @brief a DB of all tunnels - */ -static uword *lisp_gpe_tunnel_db; - -/** - * @brief Compute IP-UDP-GPE sub-tunnel encap/rewrite header. - * - * @param[in] t Parent of the sub-tunnel. - * @param[in] st Sub-tunnel. - * @param[in] lp Local and remote locators used in the encap header. - * - * @return 0 on success. - */ -u8 * -lisp_gpe_tunnel_build_rewrite (const lisp_gpe_tunnel_t * lgt, - const lisp_gpe_adjacency_t * ladj, - lisp_gpe_next_protocol_e payload_proto) -{ - lisp_gpe_header_t *lisp0; - u8 *rw = 0; - int len; - gpe_encap_mode_t encap_mode = vnet_gpe_get_encap_mode (); - - if (AF_IP4 == ip_addr_version (&lgt->key->lcl)) - { - ip4_udp_lisp_gpe_header_t *h0; - ip4_header_t *ip0; - - len = sizeof (*h0); - - vec_validate_aligned (rw, len - 1, CLIB_CACHE_LINE_BYTES); - - h0 = (ip4_udp_lisp_gpe_header_t *) rw; - - /* Fixed portion of the (outer) ip4 header */ - ip0 = &h0->ip4; - ip0->ip_version_and_header_length = 0x45; - ip0->ttl = 254; - ip0->protocol = IP_PROTOCOL_UDP; - - /* we fix up the ip4 header length and checksum after-the-fact */ - ip_address_copy_addr (&ip0->src_address, &lgt->key->lcl); - ip_address_copy_addr (&ip0->dst_address, &lgt->key->rmt); - ip0->checksum = ip4_header_checksum (ip0); - - /* UDP header, randomize src port on something, maybe? */ - h0->udp.src_port = clib_host_to_net_u16 (4341); - h0->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_lisp_gpe); - - /* LISP-gpe header */ - lisp0 = &h0->lisp; - } - else - { - ip6_udp_lisp_gpe_header_t *h0; - ip6_header_t *ip0; - - len = sizeof (*h0); - - vec_validate_aligned (rw, len - 1, CLIB_CACHE_LINE_BYTES); - - h0 = (ip6_udp_lisp_gpe_header_t *) rw; - - /* Fixed portion of the (outer) ip6 header */ - ip0 = &h0->ip6; - ip0->ip_version_traffic_class_and_flow_label = - clib_host_to_net_u32 (0x6 << 28); - ip0->hop_limit = 254; - ip0->protocol = IP_PROTOCOL_UDP; - - /* we fix up the ip6 header length after-the-fact */ - ip_address_copy_addr (&ip0->src_address, &lgt->key->lcl); - ip_address_copy_addr (&ip0->dst_address, &lgt->key->rmt); - - /* UDP header, randomize src port on something, maybe? */ - h0->udp.src_port = clib_host_to_net_u16 (4341); - h0->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_lisp_gpe); - - /* LISP-gpe header */ - lisp0 = &h0->lisp; - } - - lisp0->flags = ladj->flags; - if (GPE_ENCAP_VXLAN == encap_mode) - /* unset P flag */ - lisp0->flags &= ~LISP_GPE_FLAGS_P; - - lisp0->ver_res = 0; - lisp0->res = 0; - lisp0->next_protocol = payload_proto; - lisp0->iid = clib_host_to_net_u32 (ladj->vni) >> 8; /* first 24 bits only */ - - return (rw); -} - -static lisp_gpe_tunnel_t * -lisp_gpe_tunnel_db_find (const lisp_gpe_tunnel_key_t * key) -{ - uword *p; - - p = hash_get_mem (lisp_gpe_tunnel_db, (void *) key); - - if (NULL != p) - { - return (pool_elt_at_index (lisp_gpe_tunnel_pool, p[0])); - } - return (NULL); -} - -lisp_gpe_tunnel_t * -lisp_gpe_tunnel_get_i (index_t lgti) -{ - return (pool_elt_at_index (lisp_gpe_tunnel_pool, lgti)); -} - -index_t -lisp_gpe_tunnel_find_or_create_and_lock (const locator_pair_t * pair, - u32 rloc_fib_index) -{ - lisp_gpe_tunnel_key_t key = { - .lcl = pair->lcl_loc, - .rmt = pair->rmt_loc, - .fib_index = rloc_fib_index, - }; - lisp_gpe_tunnel_t *lgt; - fib_prefix_t pfx; - - lgt = lisp_gpe_tunnel_db_find (&key); - - if (NULL == lgt) - { - pool_get (lisp_gpe_tunnel_pool, lgt); - clib_memset (lgt, 0, sizeof (*lgt)); - - lgt->key = clib_mem_alloc (sizeof (*lgt->key)); - clib_memset (lgt->key, 0, sizeof (*lgt->key)); - - lgt->key->rmt = pair->rmt_loc; - lgt->key->lcl = pair->lcl_loc; - lgt->key->fib_index = rloc_fib_index; - - /* - * source the FIB entry for the RLOC so we can track its forwarding - * chain - */ - ip_address_to_fib_prefix (&lgt->key->rmt, &pfx); - - lgt->fib_entry_index = fib_table_entry_special_add (rloc_fib_index, - &pfx, - FIB_SOURCE_RR, - FIB_ENTRY_FLAG_NONE); - - hash_set_mem (lisp_gpe_tunnel_db, lgt->key, - (lgt - lisp_gpe_tunnel_pool)); - } - - lgt->locks++; - - return (lgt - lisp_gpe_tunnel_pool); -} - -void -lisp_gpe_tunnel_unlock (index_t lgti) -{ - lisp_gpe_tunnel_t *lgt; - - lgt = lisp_gpe_tunnel_get_i (lgti); - lgt->locks--; - - if (0 == lgt->locks) - { - hash_unset_mem (lisp_gpe_tunnel_db, lgt->key); - clib_mem_free (lgt->key); - pool_put (lisp_gpe_tunnel_pool, lgt); - } -} - -const lisp_gpe_tunnel_t * -lisp_gpe_tunnel_get (index_t lgti) -{ - return (lisp_gpe_tunnel_get_i (lgti)); -} - -/** Format LISP-GPE tunnel. */ -u8 * -format_lisp_gpe_tunnel (u8 * s, va_list * args) -{ - lisp_gpe_tunnel_t *lgt = va_arg (*args, lisp_gpe_tunnel_t *); - - s = format (s, "tunnel %d\n", lgt - lisp_gpe_tunnel_pool); - s = format (s, " fib-index: %d, locks:%d \n", - lgt->key->fib_index, lgt->locks); - s = format (s, " lisp ver 0\n"); - - s = format (s, " locator-pair:\n"); - s = format (s, " local: %U remote: %U\n", - format_ip_address, &lgt->key->lcl, - format_ip_address, &lgt->key->rmt); - s = format (s, " RLOC FIB entry: %d\n", lgt->fib_entry_index); - - return s; -} - -/** - * CLI command to show LISP-GPE tunnels. - */ -static clib_error_t * -show_lisp_gpe_tunnel_command_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) -{ - lisp_gpe_tunnel_t *lgt; - index_t index; - - if (pool_elts (lisp_gpe_tunnel_pool) == 0) - vlib_cli_output (vm, "No lisp-gpe tunnels configured..."); - - if (unformat (input, "%d", &index)) - { - lgt = lisp_gpe_tunnel_get_i (index); - vlib_cli_output (vm, "%U", format_lisp_gpe_tunnel, lgt); - } - else - { - /* *INDENT-OFF* */ - pool_foreach (lgt, lisp_gpe_tunnel_pool, - ({ - vlib_cli_output (vm, "%U", format_lisp_gpe_tunnel, lgt); - })); - /* *INDENT-ON* */ - } - - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (show_lisp_gpe_tunnel_command, static) = -{ - .path = "show gpe tunnel", - .function = show_lisp_gpe_tunnel_command_fn, -}; -/* *INDENT-ON* */ - -static clib_error_t * -lisp_gpe_tunnel_module_init (vlib_main_t * vm) -{ - lisp_gpe_tunnel_db = hash_create_mem (0, - sizeof (lisp_gpe_tunnel_key_t), - sizeof (uword)); - - return (NULL); -} - -VLIB_INIT_FUNCTION (lisp_gpe_tunnel_module_init); - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/src/vnet/lisp-gpe/lisp_gpe_tunnel.h b/src/vnet/lisp-gpe/lisp_gpe_tunnel.h deleted file mode 100644 index 333d2882883..00000000000 --- a/src/vnet/lisp-gpe/lisp_gpe_tunnel.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @file - * @brief Common utility functions for IPv4, IPv6 and L2 LISP-GPE tunnels. - * - */ - -#ifndef LISP_GPE_TUNNEL_H__ -#define LISP_GPE_TUNNEL_H__ - -#include -#include - -/** - * Forward declaration - */ -struct lisp_gpe_adjacency_t_; - -/** - * A Key for a tunnel - */ -typedef struct lisp_gpe_tunnel_key_t_ -{ - ip_address_t rmt; - ip_address_t lcl; - u32 fib_index; -} lisp_gpe_tunnel_key_t; - -/** - * @brief A LISP GPE Tunnel. - * - * A tunnel represents an associatation between a local and remote RLOC. - * As such it represents a unique LISP rewrite. - */ -typedef struct lisp_gpe_tunnel_t_ -{ - /** - * RLOC pair and rloc fib_index. This is the tunnel's key. - */ - lisp_gpe_tunnel_key_t *key; - - /** - * number of reference counting locks - */ - u32 locks; - - /** - * the FIB entry through which the remote rloc is reachable - s */ - fib_node_index_t fib_entry_index; -} lisp_gpe_tunnel_t; - -extern index_t lisp_gpe_tunnel_find_or_create_and_lock (const locator_pair_t * - pair, - u32 rloc_fib_index); - -extern void lisp_gpe_tunnel_unlock (index_t lgti); - -extern const lisp_gpe_tunnel_t *lisp_gpe_tunnel_get (index_t lgti); - -extern u8 *lisp_gpe_tunnel_build_rewrite (const lisp_gpe_tunnel_t * lgt, - const struct lisp_gpe_adjacency_t_ - *ladj, - lisp_gpe_next_protocol_e - payload_proto); -extern u8 *format_lisp_gpe_tunnel (u8 * s, va_list * args); - -#endif - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/src/vnet/lisp-gpe/lisp_types_api.c b/src/vnet/lisp-gpe/lisp_types_api.c deleted file mode 120000 index 84e06c41264..00000000000 --- a/src/vnet/lisp-gpe/lisp_types_api.c +++ /dev/null @@ -1 +0,0 @@ -../lisp-cp/lisp_types_api.c \ No newline at end of file diff --git a/src/vnet/lisp-gpe/lisp_types_api.h b/src/vnet/lisp-gpe/lisp_types_api.h deleted file mode 120000 index f895123c6b0..00000000000 --- a/src/vnet/lisp-gpe/lisp_types_api.h +++ /dev/null @@ -1 +0,0 @@ -../lisp-cp/lisp_types_api.h \ No newline at end of file diff --git a/src/vnet/lisp-gpe/rfc.txt b/src/vnet/lisp-gpe/rfc.txt deleted file mode 100644 index 5e3da150c70..00000000000 --- a/src/vnet/lisp-gpe/rfc.txt +++ /dev/null @@ -1,826 +0,0 @@ -Network Working Group D. Lewis -Internet-Draft Cisco Systems, Inc. -Intended status: Informational P. Agarwal -Expires: January 5, 2015 Broadcom - L. Kreeger - F. Maino - P. Quinn - M. Smith - N. Yadav - Cisco Systems, Inc. - July 4, 2014 - - - LISP Generic Protocol Extension - draft-lewis-lisp-gpe-02.txt - -Abstract - - This draft describes extending the Locator/ID Separation Protocol - (LISP) [RFC6830], via changes to the LISP header, with three new - capabilities: support for multi-protocol encapsulation, operations, - administration and management (OAM) signaling, and explicit - versioning. - -Status of this Memo - - This Internet-Draft is submitted in full conformance with the - provisions of BCP 78 and BCP 79. - - Internet-Drafts are working documents of the Internet Engineering - Task Force (IETF). Note that other groups may also distribute - working documents as Internet-Drafts. The list of current Internet- - Drafts is at http://datatracker.ietf.org/drafts/current/. - - Internet-Drafts are draft documents valid for a maximum of six months - and may be updated, replaced, or obsoleted by other documents at any - time. It is inappropriate to use Internet-Drafts as reference - material or to cite them other than as "work in progress." - - This Internet-Draft will expire on January 5, 2015. - -Copyright Notice - - Copyright (c) 2014 IETF Trust and the persons identified as the - document authors. All rights reserved. - - This document is subject to BCP 78 and the IETF Trust's Legal - Provisions Relating to IETF Documents - - - -Lewis, et al. Expires January 5, 2015 [Page 1] - -Internet-Draft LISP Generic Protocol Extension July 2014 - - - (http://trustee.ietf.org/license-info) in effect on the date of - publication of this document. Please review these documents - carefully, as they describe your rights and restrictions with respect - to this document. Code Components extracted from this document must - include Simplified BSD License text as described in Section 4.e of - the Trust Legal Provisions and are provided without warranty as - described in the Simplified BSD License. - - -Table of Contents - - 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 3 - 2. LISP Header Without Protocol Extensions . . . . . . . . . . . 4 - 3. Generic Protocol Extension for LISP (LISP-gpe) . . . . . . . . 5 - 3.1. Multi Protocol Support . . . . . . . . . . . . . . . . . . 5 - 3.2. OAM Support . . . . . . . . . . . . . . . . . . . . . . . 6 - 3.3. Version Bits . . . . . . . . . . . . . . . . . . . . . . . 6 - 4. Backward Compatibility . . . . . . . . . . . . . . . . . . . . 8 - 4.1. LISP-gpe Routers to (legacy) LISP Routers . . . . . . . . 8 - 4.2. (legacy) LISP Routers to LISP-gpe Routers . . . . . . . . 8 - 4.3. Type of Service . . . . . . . . . . . . . . . . . . . . . 8 - 4.4. VLAN Identifier (VID) . . . . . . . . . . . . . . . . . . 8 - 5. LISP-gpe Examples . . . . . . . . . . . . . . . . . . . . . . 9 - 6. Security Considerations . . . . . . . . . . . . . . . . . . . 11 - 7. Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . 12 - 8. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 13 - 9. References . . . . . . . . . . . . . . . . . . . . . . . . . . 14 - 9.1. Normative References . . . . . . . . . . . . . . . . . . . 14 - 9.2. Informative References . . . . . . . . . . . . . . . . . . 14 - Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . . 15 - - - - - - - - - - - - - - - - - - - - - -Lewis, et al. Expires January 5, 2015 [Page 2] - -Internet-Draft LISP Generic Protocol Extension July 2014 - - -1. Introduction - - LISP [RFC6830] defines an encapsulation format that carries IPv4 or - IPv6 (henceforth referred to as IP) packets in a LISP header and - outer UDP/IP transport. - - The LISP header does not specify the protocol being encapsulated and - therefore is currently limited to encapsulating only IP packet - payloads. Other protocols, most notably VXLAN [VXLAN] (which defines - a similar header format to LISP), are used to encapsulate L2 - protocols such as Ethernet. LISP [RFC6830] can be extended to - indicate the inner protocol, enabling the encapsulation of Ethernet, - IP or any other desired protocol all the while ensuring compatibility - with existing LISP [RFC6830] deployments. - - As LISP is deployed, there's also the need to provide increased - visibility and diagnostic capabilities within the overlay. - - This document describes extending LISP ([RFC6830]) via the following - changes: - - Next Protocol Bit (P bit): A reserved flag bit is allocated, and set - in the LISP-gpe header to indicate that a next protocol field is - present. - - OAM Flag Bit (O bit): A reserved flag bit is allocated, and set in - the LISP-gpe header, to indicate that the packet is an OAM packet. - - Version: Two reserved bits are allocated, and set in the LISP-gpe - header, to indicate LISP-gpe protocol version. - - Next protocol: An 8 bit next protocol field is present in the LISP- - gpe header. - - - - - - - - - - - - - - - - - - -Lewis, et al. Expires January 5, 2015 [Page 3] - -Internet-Draft LISP Generic Protocol Extension July 2014 - - -2. LISP Header Without Protocol Extensions - - As described in the introduction, the LISP header has no protocol - identifier that indicates the type of payload being carried by LISP. - Because of this, LISP is limited to an IP payload. Furthermore, the - LISP header has no mechanism to signal OAM packets. - - The LISP header contains flags (some defined, some reserved), a - Nonce/Map-version field and an instance ID/Locator-status-bit field. - The flags provide flexibility to define how the reserved bits can be - used to change the definition of the LISP header. - - - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - |N|L|E|V|I|flags| Nonce/Map-Version | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Instance ID/Locator-Status-Bits | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - - Figure 1: LISP Header - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Lewis, et al. Expires January 5, 2015 [Page 4] - -Internet-Draft LISP Generic Protocol Extension July 2014 - - -3. Generic Protocol Extension for LISP (LISP-gpe) - -3.1. Multi Protocol Support - - This draft defines the following changes to the LISP header in order - to support multi-protocol encapsulation. - - P Bit: Flag bit 5 is defined as the Next Protocol bit. The P bit - MUST be set to 1 to indicate the presence of the 8 bit next - protocol field. - - P = 0 indicates that the payload MUST conform to LISP as defined - in [RFC6830]. - - Flag bit 5 was chosen as the P bit because this flag bit is - currently unallocated in LISP [RFC6830]. - - Next Protocol Field: The lower 8 bits of the first word are used to - carry a next protocol. This next protocol field contains the - protocol of the encapsulated payload packet. - - LISP [RFC6830] uses the lower 16 bits of the first word for either - a nonce, an echo-nonce ([RFC6830]) or to support map-versioning - ([RFC6834]). These are all optional capabilities that are - indicated by setting the N, E, and the V bit respectively. - - To maintain the desired data plane compatibility, when the P bit - is set, the N, E, and V bits MUST be set to zero. - - A new protocol registry will be requested from IANA for the Next - Protocol field. This draft defines the following Next Protocol - values: - - 0x1 : IPv4 - - 0x2 : IPv6 - - 0x3 : Ethernet - - 0x4: Network Service Header - - - - - - - - - - - -Lewis, et al. Expires January 5, 2015 [Page 5] - -Internet-Draft LISP Generic Protocol Extension July 2014 - - - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - |N|L|E|V|I|P|R|R| Reserved | Next Protocol | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Instance ID/Locator-Status-Bits | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - - - Figure 2: LISP-gpe Next Protocol (P=1) - -3.2. OAM Support - - Flag bit 7 is defined as the O bit. When the O bit is set to 1, the - packet is an OAM packet and OAM processing MUST occur. The OAM - protocol details are out of scope for this document. As with the - P-bit, bit 7 is currently a reserved flag in [RFC6830]. - - - - - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - |N|L|E|V|I|P|R|O| Reserved | Next Protocol | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Instance ID/Locator-Status-Bits | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - - - Figure 3: LISP-gpe OAM bit (P=1) - -3.3. Version Bits - - LISP-gpe bits8 and 9 are defined as version bits. The version field - is used to ensure backward compatibility going forward with future - LISP-gpe updates. - - The initial version for LISP-gpe is 0. - - - - - - - - - - -Lewis, et al. Expires January 5, 2015 [Page 6] - -Internet-Draft LISP Generic Protocol Extension July 2014 - - - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - |N|L|E|V|I|P|R|O|Ver| Reserved | Next Protocol | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Instance ID/Locator-Status-Bits | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - - - Figure 4: LISP-gpe Version bits (P=1) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Lewis, et al. Expires January 5, 2015 [Page 7] - -Internet-Draft LISP Generic Protocol Extension July 2014 - - -4. Backward Compatibility - - Undefined (in RFC6830) flag bits 5 and 7, LISP-gpe P and O bits, were - selected to ensure compatibility with existing LISP [RFC6830] - deployments. - - Similarly, using P = 0 to indicate that the format of the header and - payload conforms to [RFC6830] ensures compatibility with existing - LISP hardware forwarding platforms. - -4.1. LISP-gpe Routers to (legacy) LISP Routers - - A LISP-gpe router MUST not encapsulate non-IP packet nor OAM packets - to a LISP router. A method for determining the capabilities of a - LISP router (gpe or "legacy") is out of the scope of this draft. - - When encapsulating IP packets to a LISP router the P bit SHOULD be - set to 1 and the UDP port MUST be set to 4341. OAM bit MUST be set - to 0. The Next Protocol field SHOULD be 0x1 (IPv4) or 0x2 (IPv6). - The (legacy) LISP router will ignore the P bit and the protocol type - field. The (legacy) LISP router will treat the packet as a LISP - packet and inspect the first nibble of the payload to determine the - IP version. - - When the P bit is set, the N, E, and V bits MUST be set to zero. The - receiving (legacy) LISP router will ignore N, E and V bits, when the - P bit is set. - -4.2. (legacy) LISP Routers to LISP-gpe Routers - - When a LISP-gpe router receives a packet from a (legacy) LISP router, - the P bit MUST not be set and the UDP port MUST be 4341. The payload - MUST be IP, and the LISP-gpe router will inspect the first nibble of - the payload to determine IP version. - -4.3. Type of Service - - When a LISP-gpe router performs Ethernet encapsulation, the inner - 802.1Q [IEEE8021Q] priority code point (PCP) field MAY be mapped from - the encapsulated frame to the Type of Service field in the outer IPv4 - header, or in the case of IPv6 the 'Traffic Class' field. - -4.4. VLAN Identifier (VID) - - When a LISP-gpe router performs Ethernet encapsulation, the inner - header 802.1Q [IEEE8021Q] VLAN Identifier (VID) MAY be mapped to, or - used to determine the LISP Instance ID field. - - - - -Lewis, et al. Expires January 5, 2015 [Page 8] - -Internet-Draft LISP Generic Protocol Extension July 2014 - - -5. LISP-gpe Examples - - This section provides two examples of IP protocols, and one example - of Ethernet encapsulated LISP-gpe using the generic extension - described in this document. - - - - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - |N|L|E|V|I|1|0|0|0| Reserved | NP = IPv4 | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Instance ID/Locator-Status-Bits | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Original IPv4 Packet | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - - - Figure 5: IPv4 and LISP-gpe - - - - - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - |N|L|E|V|I|1|0|0|0| Reserved | NP = IPv6 | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Instance ID/Locator-Status-Bits | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Original IPv6 Packet | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - - - Figure 6: IPv6 and LISP-gpe - - - - - - - - - - - - - -Lewis, et al. Expires January 5, 2015 [Page 9] - -Internet-Draft LISP Generic Protocol Extension July 2014 - - - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - |N|L|E|V|I|1|0|0|0| Reserved | NP = Ethernet | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Instance ID/Locator-Status-Bits | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Original Ethernet Frame | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - - - Figure 7: Ethernet and LISP-gpe - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Lewis, et al. Expires January 5, 2015 [Page 10] - -Internet-Draft LISP Generic Protocol Extension July 2014 - - -6. Security Considerations - - LISP-gpe security considerations are similar to the LISP security - considerations documented at length in LISP [RFC6830]. With LISP- - gpe, issues such as dataplane spoofing, flooding, and traffic - redirection are dependent on the particular protocol payload - encapsulated. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Lewis, et al. Expires January 5, 2015 [Page 11] - -Internet-Draft LISP Generic Protocol Extension July 2014 - - -7. Acknowledgments - - A special thank you goes to Dino Farinacci for his guidance and - detailed review. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Lewis, et al. Expires January 5, 2015 [Page 12] - -Internet-Draft LISP Generic Protocol Extension July 2014 - - -8. IANA Considerations - - IANA is requested to set up a registry of "Next Protocol". These are - 8-bit values. Next Protocol values 0, 1, 2, 3 and 4 are defined in - this draft. New values are assigned via Standards Action [RFC5226]. - - +---------------+-------------+---------------+ - | Next Protocol | Description | Reference | - +---------------+-------------+---------------+ - | 0 | Reserved | This document | - | | | | - | 1 | IPv4 | This document | - | | | | - | 2 | IPv6 | This document | - | | | | - | 3 | Ethernet | This document | - | | | | - | 4 | NSH | This document | - | | | | - | 5..253 | Unassigned | | - +---------------+-------------+---------------+ - - Table 1 - - There are ten bits at the beginning of the LISP-gpe header. New - bits are assigned via Standards Action [RFC5226]. - - Bits 0-3 - Assigned by LISP [RFC6830] - Bit 4 - Instance ID (I bit) - Bit 5 - Next Protocol (P bit) - Bit 6 - Reserved - Bit 7 - OAM (O bit) - Bits 8-9 - Version - - - - - - - - - - - - - - - - - - -Lewis, et al. Expires January 5, 2015 [Page 13] - -Internet-Draft LISP Generic Protocol Extension July 2014 - - -9. References - -9.1. Normative References - - [RFC0768] Postel, J., "User Datagram Protocol", STD 6, RFC 768, - August 1980. - - [RFC0791] Postel, J., "Internet Protocol", STD 5, RFC 791, - September 1981. - - [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate - Requirement Levels", BCP 14, RFC 2119, March 1997. - - [RFC5226] Narten, T. and H. Alvestrand, "Guidelines for Writing an - IANA Considerations Section in RFCs", BCP 26, RFC 5226, - May 2008. - -9.2. Informative References - - [ETYPES] The IEEE Registration Authority, "IEEE 802 Numbers", 2012, - . - - [IEEE8021Q] - The IEEE Computer Society, "Media Access Control (MAC) - Bridges and Virtual Bridge Local Area Networks", August - 2012, . - - [RFC1700] Reynolds, J. and J. Postel, "Assigned Numbers", RFC 1700, - October 1994. - - [RFC6830] Farinacci, D., Fuller, V., Meyer, D., and D. Lewis, "The - Locator/ID Separation Protocol (LISP)", RFC 6830, - January 2013. - - [RFC6834] Iannone, L., Saucez, D., and O. Bonaventure, "Locator/ID - Separation Protocol (LISP) Map-Versioning", RFC 6834, - January 2013. - - [VXLAN] Dutt, D., Mahalingam, M., Duda, K., Agarwal, P., Kreeger, - L., Sridhar, T., Bursell, M., and C. Wright, "VXLAN: A - Framework for Overlaying Virtualized Layer 2 Networks over - Layer 3 Networks", 2013. - - - - - - - -Lewis, et al. Expires January 5, 2015 [Page 14] - -Internet-Draft LISP Generic Protocol Extension July 2014 - - -Authors' Addresses - - Darrel Lewis - Cisco Systems, Inc. - - Email: darlewis@cisco.com - - - Puneet Agarwal - Broadcom - - Email: pagarwal@broadcom.com - - - Larry Kreeger - Cisco Systems, Inc. - - Email: kreeger@cisco.com - - - Fabio Maino - Cisco Systems, Inc. - - Email: fmaino@cisco.com - - - Paul Quinn - Cisco Systems, Inc. - - Email: paulq@cisco.com - - - Michael Smith - Cisco Systems, Inc. - - Email: michsmit@cisco.com - - - Navindra Yadav - Cisco Systems, Inc. - - Email: nyadav@cisco.com diff --git a/src/vnet/session/session_api.c b/src/vnet/session/session_api.c index bda98b7417c..1403e67482c 100644 --- a/src/vnet/session/session_api.c +++ b/src/vnet/session/session_api.c @@ -988,7 +988,7 @@ send_session_rules_table_details (session_rules_table_t * srt, u8 fib_proto, } static void -vl_api_session_rules_dump_t_handler (vl_api_one_map_server_dump_t * mp) +vl_api_session_rules_dump_t_handler (vl_api_session_rules_dump_t * mp) { vl_api_registration_t *reg; session_table_t *st; diff --git a/src/vnet/vnet_all_api_h.h b/src/vnet/vnet_all_api_h.h index 86edc88ac49..e48d4395436 100644 --- a/src/vnet/vnet_all_api_h.h +++ b/src/vnet/vnet_all_api_h.h @@ -46,9 +46,6 @@ #include #include #include -#include -#include -#include #include #include #include diff --git a/src/vpp/api/custom_dump.c b/src/vpp/api/custom_dump.c index b17e7ded2b2..4a2c2cb7838 100644 --- a/src/vpp/api/custom_dump.c +++ b/src/vpp/api/custom_dump.c @@ -38,7 +38,6 @@ #include #include #include -#include #include #include @@ -2523,364 +2522,6 @@ static void *vl_api_ip_source_and_port_range_check_interface_add_del_t_print FINISH; } -static void *vl_api_lisp_enable_disable_t_print - (vl_api_lisp_enable_disable_t * mp, void *handle) -{ - u8 *s; - - s = format (0, "SCRIPT: lisp_enable_disable %s", - mp->is_enable ? "enable" : "disable"); - - FINISH; -} - -static void *vl_api_gpe_add_del_iface_t_print - (vl_api_gpe_add_del_iface_t * mp, void *handle) -{ - u8 *s; - - s = format (0, "SCRIPT: gpe_add_del_iface "); - - s = format (s, "%s ", mp->is_add ? "up" : "down"); - s = format (s, "vni %d ", mp->vni); - s = format (s, "%s %d ", mp->is_l2 ? "bd_id" : "table_id", mp->dp_table); - - FINISH; -} - -static void *vl_api_lisp_pitr_set_locator_set_t_print - (vl_api_lisp_pitr_set_locator_set_t * mp, void *handle) -{ - u8 *s; - - s = format (0, "SCRIPT: lisp_pitr_set_locator_set "); - - if (mp->is_add) - s = format (s, "locator-set %s ", mp->ls_name); - else - s = format (s, "del"); - - FINISH; -} - -static u8 * -format_nsh_address_vat (u8 * s, va_list * args) -{ - nsh_t *a = va_arg (*args, nsh_t *); - return format (s, "SPI:%d SI:%d", clib_net_to_host_u32 (a->spi), a->si); -} - -static u8 * -format_lisp_flat_eid (u8 * s, va_list * args) -{ - vl_api_eid_t *eid = va_arg (*args, vl_api_eid_t *); - - switch (eid->type) - { - case EID_TYPE_API_PREFIX: - if (eid->address.prefix.address.af) - return format (s, "%U/%d", format_ip6_address, - eid->address.prefix.address.un.ip6, - eid->address.prefix.len); - return format (s, "%U/%d", format_ip4_address, - eid->address.prefix.address.un.ip4, - eid->address.prefix.len); - case EID_TYPE_API_MAC: - return format (s, "%U", format_ethernet_address, eid->address.mac); - case EID_TYPE_API_NSH: - return format (s, "%U", format_nsh_address_vat, eid->address.nsh); - } - return 0; -} - -static void *vl_api_lisp_add_del_remote_mapping_t_print - (vl_api_lisp_add_del_remote_mapping_t * mp, void *handle) -{ - u8 *s; - u32 rloc_num = 0; - - s = format (0, "SCRIPT: lisp_add_del_remote_mapping "); - - if (mp->del_all) - s = format (s, "del-all "); - - s = format (s, "%s ", mp->is_add ? "add" : "del"); - s = format (s, "vni %d ", (mp->vni)); - - s = format (s, "eid %U ", format_lisp_flat_eid, &mp->deid); - - if (mp->is_src_dst) - { - s = format (s, "seid %U ", format_lisp_flat_eid, &mp->seid); - } - rloc_num = (mp->rloc_num); - - if (0 == rloc_num) - s = format (s, "action %d", mp->action); - - FINISH; -} - -static void *vl_api_lisp_add_del_adjacency_t_print - (vl_api_lisp_add_del_adjacency_t * mp, void *handle) -{ - u8 *s; - - s = format (0, "SCRIPT: lisp_add_del_adjacency "); - - s = format (s, "%s ", mp->is_add ? "add" : "del"); - s = format (s, "vni %d ", (mp->vni)); - s = format (s, "reid %U leid %U ", - format_lisp_flat_eid, &mp->reid, format_lisp_flat_eid, - &mp->leid); - - FINISH; -} - -static void *vl_api_lisp_add_del_map_request_itr_rlocs_t_print - (vl_api_lisp_add_del_map_request_itr_rlocs_t * mp, void *handle) -{ - u8 *s; - - s = format (0, "SCRIPT: lisp_add_del_map_request_itr_rlocs "); - - if (mp->is_add) - s = format (s, "%s", mp->locator_set_name); - else - s = format (s, "del"); - - FINISH; -} - -static void *vl_api_lisp_eid_table_add_del_map_t_print - (vl_api_lisp_eid_table_add_del_map_t * mp, void *handle) -{ - u8 *s; - - s = format (0, "SCRIPT: lisp_eid_table_add_del_map "); - - if (!mp->is_add) - s = format (s, "del "); - - s = format (s, "vni %d ", (mp->vni)); - s = format (s, "%s %d ", mp->is_l2 ? "bd_index" : "vrf", (mp->dp_table)); - FINISH; -} - -static void *vl_api_lisp_add_del_local_eid_t_print - (vl_api_lisp_add_del_local_eid_t * mp, void *handle) -{ - u8 *s; - - s = format (0, "SCRIPT: lisp_add_del_local_eid "); - - if (!mp->is_add) - s = format (s, "del "); - - s = format (s, "vni %d ", (mp->vni)); - s = format (s, "eid %U ", format_lisp_flat_eid, &mp->eid); - s = format (s, "locator-set %s ", mp->locator_set_name); - if (mp->key.id) - { - u32 key_id = mp->key.id; - s = format (s, "key-id %U", format_hmac_key_id, key_id); - s = format (s, "secret-key %s", mp->key.key); - } - FINISH; -} - -static void *vl_api_gpe_add_del_fwd_entry_t_print - (vl_api_gpe_add_del_fwd_entry_t * mp, void *handle) -{ - u8 *s; - - s = format (0, "SCRIPT: gpe_add_del_fwd_entry TODO"); - - FINISH; -} - -static void *vl_api_lisp_add_del_map_resolver_t_print - (vl_api_lisp_add_del_map_resolver_t * mp, void *handle) -{ - u8 *s; - - s = format (0, "SCRIPT: lisp_add_del_map_resolver "); - - if (!mp->is_add) - s = format (s, "del "); - - if (mp->ip_address.af) - s = format (s, "%U ", format_ip6_address, mp->ip_address.un.ip6); - else - s = format (s, "%U ", format_ip4_address, mp->ip_address.un.ip4); - - FINISH; -} - -static void *vl_api_gpe_enable_disable_t_print - (vl_api_gpe_enable_disable_t * mp, void *handle) -{ - u8 *s; - - s = format (0, "SCRIPT: gpe_enable_disable "); - - s = format (s, "%s ", mp->is_enable ? "enable" : "disable"); - - FINISH; -} - -static void *vl_api_lisp_add_del_locator_set_t_print - (vl_api_lisp_add_del_locator_set_t * mp, void *handle) -{ - u8 *s; - - s = format (0, "SCRIPT: lisp_add_del_locator_set "); - - if (!mp->is_add) - s = format (s, "del "); - - s = format (s, "locator-set %s ", mp->locator_set_name); - - FINISH; -} - -static void *vl_api_lisp_add_del_locator_t_print - (vl_api_lisp_add_del_locator_t * mp, void *handle) -{ - u8 *s; - - s = format (0, "SCRIPT: lisp_add_del_locator "); - - if (!mp->is_add) - s = format (s, "del "); - - s = format (s, "locator-set %s ", mp->locator_set_name); - s = format (s, "sw_if_index %d ", mp->sw_if_index); - s = format (s, "p %d w %d ", mp->priority, mp->weight); - - FINISH; -} - -static void *vl_api_lisp_locator_set_dump_t_print - (vl_api_lisp_locator_set_dump_t * mp, void *handle) -{ - u8 *s; - - s = format (0, "SCRIPT: lisp_locator_set_dump "); - if (mp->filter == 1) - s = format (s, "local"); - else if (mp->filter == 2) - s = format (s, "remote"); - - FINISH; -} - -static void *vl_api_lisp_locator_dump_t_print - (vl_api_lisp_locator_dump_t * mp, void *handle) -{ - u8 *s; - - s = format (0, "SCRIPT: lisp_locator_dump "); - if (mp->is_index_set) - s = format (s, "ls_index %d", (mp->ls_index)); - else - s = format (s, "ls_name %s", mp->ls_name); - - FINISH; -} - -static void *vl_api_lisp_map_request_mode_t_print - (vl_api_lisp_map_request_mode_t * mp, void *handle) -{ - u8 *s; - - s = format (0, "SCRIPT: lisp_map_request_mode "); - - s = mp->is_src_dst ? format (s, "src-dst") : format (s, "dst-only"); - - FINISH; -} - -static void *vl_api_lisp_eid_table_dump_t_print - (vl_api_lisp_eid_table_dump_t * mp, void *handle) -{ - u8 *s; - - s = format (0, "SCRIPT: lisp_eid_table_dump "); - - if (mp->eid_set) - { - s = format (s, "vni %d ", (mp->vni)); - s = format (s, "eid %U ", format_lisp_flat_eid, &mp->eid); - switch (mp->filter) - { - case 1: - s = format (s, "local "); - break; - case 2: - s = format (s, "remote "); - break; - default: - break; - } - } - FINISH; -} - -static void *vl_api_lisp_rloc_probe_enable_disable_t_print - (vl_api_lisp_rloc_probe_enable_disable_t * mp, void *handle) -{ - u8 *s; - - s = format (0, "SCRIPT: lisp_rloc_probe_enable_disable "); - if (mp->is_enable) - s = format (s, "enable"); - else - s = format (s, "disable"); - - FINISH; -} - -static void *vl_api_lisp_map_register_enable_disable_t_print - (vl_api_lisp_map_register_enable_disable_t * mp, void *handle) -{ - u8 *s; - - s = format (0, "SCRIPT: lisp_map_register_enable_disable "); - if (mp->is_enable) - s = format (s, "enable"); - else - s = format (s, "disable"); - - FINISH; -} - -static void *vl_api_lisp_adjacencies_get_t_print - (vl_api_lisp_adjacencies_get_t * mp, void *handle) -{ - u8 *s; - - s = format (0, "SCRIPT: lisp_adjacencies_get "); - s = format (s, "vni %d", (mp->vni)); - - FINISH; -} - -static void *vl_api_lisp_eid_table_map_dump_t_print - (vl_api_lisp_eid_table_map_dump_t * mp, void *handle) -{ - u8 *s; - - s = format (0, "SCRIPT: lisp_eid_table_map_dump "); - - if (mp->is_l2) - s = format (s, "l2"); - else - s = format (s, "l3"); - - FINISH; -} - static void *vl_api_ipsec_tunnel_if_add_del_t_print (vl_api_ipsec_tunnel_if_add_del_t * mp, void *handle) { @@ -2923,6 +2564,13 @@ static void *vl_api_ipsec_tunnel_if_add_del_t_print FINISH; } +/* static u8 * */ +/* format_nsh_address_vat (u8 * s, va_list * args) */ +/* { */ +/* nsh_t *a = va_arg (*args, nsh_t *); */ +/* return format (s, "SPI:%d SI:%d", clib_net_to_host_u32 (a->spi), a->si); */ +/* } */ + static const char *policy_strs[] = { "BYPASS", "DISCARD", @@ -3381,24 +3029,6 @@ static void * vl_api_ ## f ## _t_print \ foreach_no_print_function; #undef _ -#define foreach_custom_print_no_arg_function \ -_(lisp_eid_table_vni_dump) \ -_(lisp_map_resolver_dump) \ -_(lisp_map_server_dump) \ -_(show_lisp_rloc_probe_state) \ -_(show_lisp_map_register_state) \ -_(show_lisp_map_request_mode) - -#define _(f) \ -static void * vl_api_ ## f ## _t_print \ - (vl_api_ ## f ## _t * mp, void * handle) \ -{ \ - u8 * s; \ - s = format (0, "SCRIPT: " #f ); \ - FINISH; \ -} -foreach_custom_print_no_arg_function; -#undef _ #define foreach_custom_print_function \ _(CREATE_LOOPBACK, create_loopback) \ _(CREATE_LOOPBACK_INSTANCE, create_loopback_instance) \ @@ -3525,34 +3155,6 @@ _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, \ ip_source_and_port_range_check_add_del) \ _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \ ip_source_and_port_range_check_interface_add_del) \ -_(LISP_ENABLE_DISABLE, lisp_enable_disable) \ -_(GPE_ENABLE_DISABLE, gpe_enable_disable) \ -_(GPE_ADD_DEL_IFACE, gpe_add_del_iface) \ -_(LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set) \ -_(LISP_MAP_REQUEST_MODE, lisp_map_request_mode) \ -_(SHOW_LISP_MAP_REQUEST_MODE, show_lisp_map_request_mode) \ -_(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping) \ -_(LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency) \ -_(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \ - lisp_add_del_map_request_itr_rlocs) \ -_(LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map) \ -_(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid) \ -_(GPE_ADD_DEL_FWD_ENTRY, gpe_add_del_fwd_entry) \ -_(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set) \ -_(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver) \ -_(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator) \ -_(LISP_EID_TABLE_DUMP, lisp_eid_table_dump) \ -_(LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump) \ -_(LISP_EID_TABLE_VNI_DUMP, lisp_eid_table_vni_dump) \ -_(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump) \ -_(LISP_MAP_SERVER_DUMP, lisp_map_server_dump) \ -_(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \ -_(LISP_LOCATOR_DUMP, lisp_locator_dump) \ -_(LISP_ADJACENCIES_GET, lisp_adjacencies_get) \ -_(SHOW_LISP_RLOC_PROBE_STATE, show_lisp_rloc_probe_state) \ -_(SHOW_LISP_MAP_REGISTER_STATE, show_lisp_map_register_state) \ -_(LISP_RLOC_PROBE_ENABLE_DISABLE, lisp_rloc_probe_enable_disable) \ -_(LISP_MAP_REGISTER_ENABLE_DISABLE, lisp_map_register_enable_disable) \ _(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd) \ _(IPSEC_SAD_ENTRY_ADD_DEL, ipsec_sad_entry_add_del) \ _(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del) \ diff --git a/test/framework.py b/test/framework.py index ba5f4014798..82d1c35fd7c 100644 --- a/test/framework.py +++ b/test/framework.py @@ -419,6 +419,8 @@ class VppTestCase(unittest.TestCase): "plugins", "{", "plugin", "dpdk_plugin.so", "{", "disable", "}", "plugin", "rdma_plugin.so", "{", "disable", + "}", "plugin", "lisp_unittest_plugin.so", "{", + "enable", "}", "plugin", "unittest_plugin.so", "{", "enable", "}"] + cls.extra_vpp_plugin_config + ["}", ] diff --git a/test/test_lisp.py b/test/test_lisp.py deleted file mode 100644 index 70cb4f4bf34..00000000000 --- a/test/test_lisp.py +++ /dev/null @@ -1,208 +0,0 @@ -#!/usr/bin/env python3 - -import abc -import six -import unittest - -from scapy.fields import BitField, ByteField, FlagsField, IntField -from scapy.packet import bind_layers, Packet, Raw -from scapy.layers.inet import IP, UDP, Ether -from scapy.layers.inet6 import IPv6 - -from framework import VppTestCase, VppTestRunner -from lisp import VppLocalMapping, VppLispAdjacency, VppLispLocator, \ - VppLispLocatorSet, VppRemoteMapping, LispRemoteLocator -from util import ppp, ForeignAddressFactory - -# From py_lispnetworking.lisp.py: # GNU General Public License v2.0 - - -class LISP_GPE_Header(Packet): - name = "LISP GPE Header" - fields_desc = [ - FlagsField("gpe_flags", None, 6, ["N", "L", "E", "V", "I", "P"]), - BitField("reserved", 0, 18), - ByteField("next_proto", 0), - IntField("iid", 0), - ] -bind_layers(UDP, LISP_GPE_Header, dport=4341) -bind_layers(UDP, LISP_GPE_Header, sport=4341) -bind_layers(LISP_GPE_Header, IP, next_proto=1) -bind_layers(LISP_GPE_Header, IPv6, next_proto=2) -bind_layers(LISP_GPE_Header, Ether, next_proto=3) - - -@six.add_metaclass(abc.ABCMeta) -class Driver(object): - - config_order = ['locator-sets', - 'locators', - 'local-mappings', - 'remote-mappings', - 'adjacencies'] - - """ Basic class for data driven testing """ - def __init__(self, test, test_cases): - self._test_cases = test_cases - self._test = test - - @property - def test_cases(self): - return self._test_cases - - @property - def test(self): - return self._test - - def create_packet(self, src_if, dst_if, deid, payload=''): - """ - Create IPv4 packet - - param: src_if - param: dst_if - """ - packet = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) / - IP(src=src_if.remote_ip4, dst=deid) / - Raw(payload)) - return packet - - @abc.abstractmethod - def run(self): - """ testing procedure """ - pass - - -class SimpleDriver(Driver): - """ Implements simple test procedure """ - def __init__(self, test, test_cases): - super(SimpleDriver, self).__init__(test, test_cases) - - def verify_capture(self, src_loc, dst_loc, capture): - """ - Verify captured packet - - :param src_loc: source locator address - :param dst_loc: destination locator address - :param capture: list of captured packets - """ - self.test.assertEqual(len(capture), 1, "Unexpected number of " - "packets! Expected 1 but {} received" - .format(len(capture))) - packet = capture[0] - try: - ip_hdr = packet[IP] - # assert the values match - self.test.assertEqual(ip_hdr.src, src_loc, "IP source address") - self.test.assertEqual(ip_hdr.dst, dst_loc, - "IP destination address") - gpe_hdr = packet[LISP_GPE_Header] - self.test.assertEqual(gpe_hdr.next_proto, 1, - "next_proto is not ipv4!") - ih = gpe_hdr[IP] - self.test.assertEqual(ih.src, self.test.pg0.remote_ip4, - "unexpected source EID!") - self.test.assertEqual(ih.dst, self.test.deid_ip4, - "unexpected dest EID!") - except: - self.test.logger.error(ppp("Unexpected or invalid packet:", - packet)) - raise - - def configure_tc(self, tc): - for config_item in self.config_order: - for vpp_object in tc[config_item]: - vpp_object.add_vpp_config() - - def run(self, dest): - """ Send traffic for each test case and verify that it - is encapsulated """ - for tc in enumerate(self.test_cases): - self.test.logger.info('Running {}'.format(tc[1]['name'])) - self.configure_tc(tc[1]) - - packet = self.create_packet(self.test.pg0, self.test.pg1, dest, - 'data') - self.test.pg0.add_stream(packet) - self.test.pg0.enable_capture() - self.test.pg1.enable_capture() - self.test.pg_start() - capture = self.test.pg1.get_capture(1) - self.verify_capture(self.test.pg1.local_ip4, - self.test.pg1.remote_ip4, capture) - self.test.pg0.assert_nothing_captured() - - -class TestLisp(VppTestCase): - """ Basic LISP test """ - - @classmethod - def setUpClass(cls): - super(TestLisp, cls).setUpClass() - cls.faf = ForeignAddressFactory() - cls.create_pg_interfaces(range(2)) # create pg0 and pg1 - for i in cls.pg_interfaces: - i.admin_up() # put the interface upsrc_if - i.config_ip4() # configure IPv4 address on the interface - i.resolve_arp() # resolve ARP, so that we know VPP MAC - - @classmethod - def tearDownClass(cls): - super(TestLisp, cls).tearDownClass() - - def setUp(self): - super(TestLisp, self).setUp() - self.vapi.lisp_enable_disable(is_enable=1) - - def test_lisp_basic_encap(self): - """Test case for basic encapsulation""" - - self.deid_ip4_net = self.faf.net - self.deid_ip4 = self.faf.get_ip4() - self.seid_ip4 = '{!s}/{!s}'.format(self.pg0.local_ip4, 32) - self.rloc_ip4 = self.pg1.remote_ip4 - - test_cases = [ - { - 'name': 'basic ip4 over ip4', - 'locator-sets': [VppLispLocatorSet(self, 'ls-4o4')], - 'locators': [ - VppLispLocator(self, self.pg1.sw_if_index, 'ls-4o4') - ], - 'local-mappings': [ - VppLocalMapping(self, self.seid_ip4, 'ls-4o4') - ], - 'remote-mappings': [ - VppRemoteMapping(self, self.deid_ip4_net, - [LispRemoteLocator(self.rloc_ip4)]) - ], - 'adjacencies': [ - VppLispAdjacency(self, self.seid_ip4, self.deid_ip4_net) - ] - } - ] - self.test_driver = SimpleDriver(self, test_cases) - self.test_driver.run(self.deid_ip4) - - -class TestLispUT(VppTestCase): - """ Lisp UT """ - - @classmethod - def setUpClass(cls): - super(TestLispUT, cls).setUpClass() - - @classmethod - def tearDownClass(cls): - super(TestLispUT, cls).tearDownClass() - - def test_fib(self): - """ LISP Unit Tests """ - error = self.vapi.cli("test lisp cp") - - if error: - self.logger.critical(error) - self.assertNotIn("Failed", error) - - -if __name__ == '__main__': - unittest.main(testRunner=VppTestRunner) -- cgit 1.2.3-korg