aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/lisp-cp
diff options
context:
space:
mode:
authorNeale Ranns <nranns@cisco.com>2020-09-21 08:17:51 +0000
committerDamjan Marion <dmarion@me.com>2020-09-22 16:01:29 +0000
commit2b202bc4b2d870d76bfe6fb1906ae62e253cec72 (patch)
treeb05011f96b8d9d080647323e4609af0fac90b612 /src/vnet/lisp-cp
parentb468773aa4164bf52e0751fdf780f67248037cc0 (diff)
lisp: Move to plugin
Type: refactor Change-Id: I54df533a8f863c4e49742903cf2457f18b4fc506 Signed-off-by: Neale Ranns <nranns@cisco.com>
Diffstat (limited to 'src/vnet/lisp-cp')
-rw-r--r--src/vnet/lisp-cp/FEATURE.yaml14
-rw-r--r--src/vnet/lisp-cp/control.c5033
-rw-r--r--src/vnet/lisp-cp/control.h448
-rw-r--r--src/vnet/lisp-cp/gid_dictionary.c1077
-rw-r--r--src/vnet/lisp-cp/gid_dictionary.h161
-rw-r--r--src/vnet/lisp-cp/lisp.api674
-rw-r--r--src/vnet/lisp-cp/lisp_api.c1134
-rw-r--r--src/vnet/lisp-cp/lisp_cli.c1603
-rw-r--r--src/vnet/lisp-cp/lisp_cp_dpo.c122
-rw-r--r--src/vnet/lisp-cp/lisp_cp_dpo.h45
-rw-r--r--src/vnet/lisp-cp/lisp_cp_messages.h644
-rw-r--r--src/vnet/lisp-cp/lisp_msg_serdes.c381
-rw-r--r--src/vnet/lisp-cp/lisp_msg_serdes.h58
-rw-r--r--src/vnet/lisp-cp/lisp_types.api75
-rw-r--r--src/vnet/lisp-cp/lisp_types.c1488
-rw-r--r--src/vnet/lisp-cp/lisp_types.h350
-rw-r--r--src/vnet/lisp-cp/lisp_types_api.c88
-rw-r--r--src/vnet/lisp-cp/lisp_types_api.h26
-rw-r--r--src/vnet/lisp-cp/one.api1031
-rw-r--r--src/vnet/lisp-cp/one_api.c1741
-rw-r--r--src/vnet/lisp-cp/one_cli.c2340
-rw-r--r--src/vnet/lisp-cp/packets.c226
-rw-r--r--src/vnet/lisp-cp/packets.h38
23 files changed, 0 insertions, 18797 deletions
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 <fcoras@cisco.com>
-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 <vlibmemory/api.h>
-#include <vnet/lisp-cp/control.h>
-#include <vnet/lisp-cp/packets.h>
-#include <vnet/lisp-cp/lisp_msg_serdes.h>
-#include <vnet/lisp-gpe/lisp_gpe_fwd_entry.h>
-#include <vnet/lisp-gpe/lisp_gpe_tenant.h>
-#include <vnet/lisp-gpe/lisp_gpe_tunnel.h>
-#include <vnet/fib/fib_entry.h>
-#include <vnet/fib/fib_table.h>
-#include <vnet/ethernet/arp_packet.h>
-#include <vnet/ethernet/packet.h>
-
-#include <openssl/evp.h>
-#include <vnet/crypto/crypto.h>
-
-#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 <vnet/vnet.h>
-#include <vnet/lisp-cp/gid_dictionary.h>
-#include <vnet/lisp-cp/lisp_types.h>
-#include <vppinfra/timing_wheel.h>
-#include <vppinfra/tw_timer_1t_3w_1024sl_ov.h>
-
-#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 <vnet/lisp-cp/gid_dictionary.h>
-
-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 <vnet/vnet.h>
-#include <vnet/lisp-cp/lisp_types.h>
-#include <vppinfra/bihash_24_8.h>
-#include <vppinfra/bihash_template.h>
-
-#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 <vnet/vnet.h>
-#include <vlibmemory/api.h>
-
-#include <vnet/interface.h>
-#include <vnet/api_errno.h>
-#include <vnet/lisp-cp/control.h>
-#include <vnet/lisp-gpe/lisp_gpe.h>
-#include <vnet/ip/ip_types_api.h>
-#include <vnet/ethernet/ethernet_types_api.h>
-#include <vnet/lisp-cp/lisp_types_api.h>
-
-#include <vnet/vnet_msg_enum.h>
-
-
-#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 <vnet/vnet_all_api_h.h>
-#undef vl_typedefs
-
-#define vl_endianfun /* define message structures */
-#include <vnet/vnet_all_api_h.h>
-#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 <vnet/vnet_all_api_h.h>
-#undef vl_printfun
-
-#include <vlibapi/api_helper_macros.h>
-
-#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, "<remote-%d>", 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 <vnet/vnet_all_api_h.h>
-#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 <vnet/lisp-cp/control.h>
-#include <vnet/lisp-gpe/lisp_gpe.h>
-
-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 <ip>",
- .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 <vni>] eid <eid> "
- "locator-set <locator-set> [key <secret-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 <vni> vrf <vrf> | bd <bdi>",
- .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 <vni> "
- "eid <est-eid> [action <no-action|natively-forward|"
- "send-map-request|drop>] rloc <dst-locator> p <prio> "
- "w <weight> [rloc <dst-locator> ... ]",
- .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 <vni> reid <remote-eid> "
- "leid <local-eid>",
- .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 <locator-set-name>",
- .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 <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 <name> [iface <iface-name> "
- "p <priority> w <weight>]",
- .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 <name> iface <iface-name> "
- "p <priority> w <weight>",
- .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 <ip_address>",
- .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 <locator_set_name>",
- .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] <petr-ip>",
- .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 <vnet/dpo/dpo.h>
-#include <vnet/lisp-gpe/lisp_gpe.h>
-#include <vnet/lisp-cp/control.h>
-
-/**
- * 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 <vnet/vnet.h>
-#include <vnet/dpo/dpo.h>
-
-/**
- * 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 <vnet/vnet.h>
-
-#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 <vnet/lisp-cp/lisp_msg_serdes.h>
-#include <vnet/lisp-cp/packets.h>
-#include <vppinfra/time.h>
-
-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 <vnet/vnet.h>
-#include <vnet/lisp-cp/lisp_cp_messages.h>
-#include <vnet/lisp-cp/control.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);
-
-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 <vnet/ethernet/ethernet.h>
-#include <vnet/lisp-cp/lisp_types.h>
-
-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 <vnet/ip/ip.h>
-#include <vnet/lisp-cp/lisp_cp_messages.h>
-
-#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 <vnet/lisp-cp/lisp_types_api.h>
-#include <vnet/ip/ip_types_api.h>
-#include <vnet/ethernet/ethernet_types_api.h>
-
-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 <vnet/lisp-cp/lisp_types.h>
-#include <vnet/lisp-cp/lisp.api_types.h>
-
-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 <vnet/vnet.h>
-#include <vlibmemory/api.h>
-
-#include <vnet/interface.h>
-#include <vnet/api_errno.h>
-#include <vnet/lisp-cp/control.h>
-#include <vnet/lisp-gpe/lisp_gpe.h>
-
-#include <vnet/ip/ip_types_api.h>
-#include <vnet/ethernet/ethernet_types_api.h>
-
-#include <vnet/vnet_msg_enum.h>
-
-#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 <vnet/vnet_all_api_h.h>
-#undef vl_typedefs
-
-#define vl_endianfun /* define message structures */
-#include <vnet/vnet_all_api_h.h>
-#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 <vnet/vnet_all_api_h.h>
-#undef vl_printfun
-
-#include <vlibapi/api_helper_macros.h>
-
-#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, "<remote-%d>", 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 <vnet/vnet_all_api_h.h>
-#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 <vnet/lisp-cp/control.h>
-#include <vnet/lisp-gpe/lisp_gpe.h>
-
-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 <ip>",
- .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 <vni>] eid <eid> "
- "locator-set <locator-set> [key <secret-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 <vni> vrf <vrf> | bd <bdi>",
- .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 <bd> mac <mac> ip <ipv6>",
- .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 <bd> mac <mac> ip <ipv4>",
- .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 <vni> "
- "eid <est-eid> [action <no-action|natively-forward|"
- "send-map-request|drop>] rloc <dst-locator> p <prio> w <weight> "
- "[rloc <dst-locator> ... ]",
- .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 <vni> reid <remote-eid> "
- "leid <local-eid>",
- .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 <locator-set-name>",
- .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 <count>",
- .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 <locator-set-name>",
- .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 <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 <name> [iface <iface-name> "
- "p <priority> w <weight>]",
- .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 <name> iface <iface-name> "
- "p <priority> w <weight>",
- .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 <ip_address>",
- .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 <locator_set_name>",
- .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] <petr-ip>",
- .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 <vnet/lisp-cp/packets.h>
-#include <vnet/lisp-cp/lisp_cp_messages.h>
-#include <vnet/udp/udp_packet.h>
-
-/* 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 <vnet/vnet.h>
-#include <vnet/lisp-cp/lisp_types.h>
-
-#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:
- */