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/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 - 49 files changed, 1 insertion(+), 27116 deletions(-) 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 (limited to 'src/vnet') 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 -- cgit 1.2.3-korg