summaryrefslogtreecommitdiffstats
path: root/src/vnet/teib
diff options
context:
space:
mode:
authorNeale Ranns <nranns@cisco.com>2020-09-17 12:56:47 +0000
committerFlorin Coras <florin.coras@gmail.com>2020-09-17 14:46:07 +0000
commite6b83059af3365ab12bbe93655a7dea6f691dbda (patch)
tree7b15b70d2d8a24a5c7dc53ad69a3fb7318fb1383 /src/vnet/teib
parent5ef25165b505f761a099e6c3bc06569cfef74f26 (diff)
teib: Use ip_address_t not ip46_address_t
Type: improvement Change-Id: Ica75c4e43d6198658a1954640c7ac56ea68bb39a Signed-off-by: Neale Ranns <nranns@cisco.com>
Diffstat (limited to 'src/vnet/teib')
-rw-r--r--src/vnet/teib/teib.c144
-rw-r--r--src/vnet/teib/teib.h18
-rw-r--r--src/vnet/teib/teib_api.c18
-rw-r--r--src/vnet/teib/teib_cli.c20
4 files changed, 90 insertions, 110 deletions
diff --git a/src/vnet/teib/teib.c b/src/vnet/teib/teib.c
index 0f33d087a50..69ed416b41a 100644
--- a/src/vnet/teib/teib.c
+++ b/src/vnet/teib/teib.c
@@ -1,7 +1,7 @@
/*
- * teib.h: next-hop resolution
+ * teib.h: Tunnel Endpoint Information Base
*
- * Copyright (c) 2016 Cisco and/or its affiliates.
+ * 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:
@@ -23,11 +23,13 @@
typedef struct teib_key_t_
{
- ip46_address_t tk_peer;
+ ip_address_t tk_peer;
+ u8 __pad[3];
u32 tk_sw_if_index;
- fib_protocol_t tk_proto;
} __clib_packed teib_key_t;
+STATIC_ASSERT_SIZEOF (teib_key_t, 24);
+
struct teib_entry_t_
{
teib_key_t *te_key;
@@ -35,7 +37,13 @@ struct teib_entry_t_
u32 te_fib_index;
};
-static uword *teib_db[FIB_PROTOCOL_IP_MAX];
+typedef struct teib_db_t_
+{
+ u32 td_n_entries[N_AF];
+ uword *td_db;
+} teib_db_t;
+
+static teib_db_t teib_db;
static teib_entry_t *teib_pool;
static teib_vft_t *teib_vfts;
static vlib_log_class_t teib_logger;
@@ -66,10 +74,10 @@ teib_entry_get_sw_if_index (const teib_entry_t * te)
return (te->te_key->tk_sw_if_index);
}
-fib_protocol_t
-teib_entry_get_proto (const teib_entry_t * te)
+static ip_address_family_t
+teib_entry_get_af (const teib_entry_t * te)
{
- return (te->te_key->tk_proto);
+ return (ip_addr_version (&te->te_key->tk_peer));
}
u32
@@ -78,7 +86,7 @@ teib_entry_get_fib_index (const teib_entry_t * te)
return (te->te_fib_index);
}
-const ip46_address_t *
+const ip_address_t *
teib_entry_get_peer (const teib_entry_t * te)
{
return (&te->te_key->tk_peer);
@@ -103,17 +111,15 @@ teib_entry_get (index_t tei)
}
teib_entry_t *
-teib_entry_find (u32 sw_if_index,
- fib_protocol_t fproto, const ip46_address_t * peer)
+teib_entry_find (u32 sw_if_index, const ip_address_t * peer)
{
teib_key_t nk = {
.tk_peer = *peer,
- .tk_proto = fproto,
.tk_sw_if_index = sw_if_index,
};
uword *p;
- p = hash_get_mem (teib_db[fproto], &nk);
+ p = hash_get_mem (teib_db.td_db, &nk);
if (NULL != p)
return teib_entry_get (p[0]);
@@ -121,26 +127,34 @@ teib_entry_find (u32 sw_if_index,
return (NULL);
}
+teib_entry_t *
+teib_entry_find_46 (u32 sw_if_index,
+ fib_protocol_t fproto, const ip46_address_t * peer)
+{
+ ip_address_t ip;
+
+ ip_address_from_46 (peer, fproto, &ip);
+
+ return (teib_entry_find (sw_if_index, &ip));
+}
+
static void
-teib_adj_fib_add (fib_protocol_t fproto,
- const ip46_address_t * ip, u32 sw_if_index, u32 fib_index)
+teib_adj_fib_add (const ip_address_t * ip, u32 sw_if_index, u32 fib_index)
{
- if (FIB_PROTOCOL_IP6 == fproto &&
- ip6_address_is_link_local_unicast (&ip->ip6))
+ if (AF_IP6 == ip_addr_version (ip) &&
+ ip6_address_is_link_local_unicast (&ip_addr_v6 (ip)))
{
ip6_ll_prefix_t pfx = {
- .ilp_addr = ip->ip6,
+ .ilp_addr = ip_addr_v6 (ip),
.ilp_sw_if_index = sw_if_index,
};
ip6_ll_table_entry_update (&pfx, FIB_ROUTE_PATH_FLAG_NONE);
}
else
{
- fib_prefix_t pfx = {
- .fp_len = (FIB_PROTOCOL_IP4 == fproto ? 32 : 128),
- .fp_proto = fproto,
- .fp_addr = *ip,
- };
+ fib_prefix_t pfx;
+
+ ip_address_to_fib_prefix (ip, &pfx);
fib_table_entry_path_add (fib_index, &pfx, FIB_SOURCE_ADJ,
FIB_ENTRY_FLAG_ATTACHED,
fib_proto_to_dpo (pfx.fp_proto),
@@ -149,55 +163,51 @@ teib_adj_fib_add (fib_protocol_t fproto,
~0, 1, NULL, FIB_ROUTE_PATH_FLAG_NONE);
- if (1 == hash_elts (teib_db[pfx.fp_proto]))
+ if (0 == teib_db.td_n_entries[ip_addr_version (ip)]++)
fib_table_lock (fib_index, pfx.fp_proto, FIB_SOURCE_ADJ);
}
}
static void
-teib_adj_fib_remove (fib_protocol_t fproto,
- ip46_address_t * ip, u32 sw_if_index, u32 fib_index)
+teib_adj_fib_remove (ip_address_t * ip, u32 sw_if_index, u32 fib_index)
{
- if (FIB_PROTOCOL_IP6 == fproto &&
- ip6_address_is_link_local_unicast (&ip->ip6))
+ if (AF_IP6 == ip_addr_version (ip) &&
+ ip6_address_is_link_local_unicast (&ip_addr_v6 (ip)))
{
ip6_ll_prefix_t pfx = {
- .ilp_addr = ip->ip6,
+ .ilp_addr = ip_addr_v6 (ip),
.ilp_sw_if_index = sw_if_index,
};
ip6_ll_table_entry_delete (&pfx);
}
else
{
- fib_prefix_t pfx = {
- .fp_len = (FIB_PROTOCOL_IP4 == fproto ? 32 : 128),
- .fp_proto = fproto,
- .fp_addr = *ip,
- };
+ fib_prefix_t pfx;
+ ip_address_to_fib_prefix (ip, &pfx);
fib_table_entry_path_remove (fib_index, &pfx, FIB_SOURCE_ADJ,
fib_proto_to_dpo (pfx.fp_proto),
&pfx.fp_addr,
sw_if_index,
~0, 1, FIB_ROUTE_PATH_FLAG_NONE);
- if (0 == hash_elts (teib_db[pfx.fp_proto]))
+ if (0 == --teib_db.td_n_entries[ip_addr_version (ip)])
fib_table_unlock (fib_index, pfx.fp_proto, FIB_SOURCE_ADJ);
}
}
int
teib_entry_add (u32 sw_if_index,
- fib_protocol_t fproto,
- const ip46_address_t * peer,
- u32 nh_table_id, const ip46_address_t * nh)
+ const ip_address_t * peer,
+ u32 nh_table_id, const ip_address_t * nh)
{
fib_protocol_t nh_proto;
teib_entry_t *te;
u32 fib_index;
index_t tei;
- nh_proto = (ip46_address_is_ip4 (nh) ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6);
+ nh_proto = (AF_IP4 == ip_addr_version (nh) ?
+ FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6);
fib_index = fib_table_find (nh_proto, nh_table_id);
@@ -206,19 +216,18 @@ teib_entry_add (u32 sw_if_index,
return (VNET_API_ERROR_NO_SUCH_FIB);
}
- te = teib_entry_find (sw_if_index, fproto, peer);
+ te = teib_entry_find (sw_if_index, peer);
if (NULL == te)
{
teib_key_t nk = {
.tk_peer = *peer,
- .tk_proto = fproto,
.tk_sw_if_index = sw_if_index,
};
teib_entry_t *te;
u32 fib_index;
- fib_index = fib_table_get_index_for_sw_if_index (fproto, sw_if_index);
+ fib_index = fib_table_get_index_for_sw_if_index (nh_proto, sw_if_index);
pool_get_zero (teib_pool, te);
@@ -226,16 +235,13 @@ teib_entry_add (u32 sw_if_index,
te->te_key = clib_mem_alloc (sizeof (*te->te_key));
clib_memcpy (te->te_key, &nk, sizeof (*te->te_key));
- ip46_address_copy (&te->te_nh.fp_addr, nh);
- te->te_nh.fp_proto = fproto;
- te->te_nh.fp_len = (te->te_nh.fp_proto == FIB_PROTOCOL_IP4 ? 32 : 128);
+ ip_address_to_fib_prefix (nh, &te->te_nh);
te->te_fib_index = fib_index;
- hash_set_mem (teib_db[fproto], te->te_key, tei);
+ hash_set_mem (teib_db.td_db, te->te_key, tei);
/* we how have a /32 in the overlay, add an adj-fib */
- teib_adj_fib_add (te->te_key->tk_proto,
- &te->te_key->tk_peer, sw_if_index, fib_index);
+ teib_adj_fib_add (&te->te_key->tk_peer, sw_if_index, fib_index);
TEIB_NOTIFY (te, nv_added);
TEIB_TE_INFO (te, "created");
@@ -249,12 +255,11 @@ teib_entry_add (u32 sw_if_index,
}
int
-teib_entry_del (u32 sw_if_index,
- fib_protocol_t fproto, const ip46_address_t * peer)
+teib_entry_del (u32 sw_if_index, const ip_address_t * peer)
{
teib_entry_t *te;
- te = teib_entry_find (sw_if_index, fproto, peer);
+ te = teib_entry_find (sw_if_index, peer);
if (te != NULL)
{
@@ -262,12 +267,13 @@ teib_entry_del (u32 sw_if_index,
u32 fib_index;
- fib_index = fib_table_get_index_for_sw_if_index (fproto, sw_if_index);
+ fib_index = fib_table_get_index_for_sw_if_index
+ (ip_address_family_to_fib_proto (ip_addr_version (peer)),
+ sw_if_index);
- teib_adj_fib_remove (te->te_key->tk_proto,
- &te->te_key->tk_peer, sw_if_index, fib_index);
+ teib_adj_fib_remove (&te->te_key->tk_peer, sw_if_index, fib_index);
- hash_unset_mem (teib_db[fproto], te->te_key);
+ hash_unset_mem (teib_db.td_db, te->te_key);
TEIB_NOTIFY (te, nv_deleted);
@@ -278,9 +284,7 @@ teib_entry_del (u32 sw_if_index,
{
TEIB_INFO ("no such entry: %U, %U, %U",
format_vnet_sw_if_index_name,
- vnet_get_main (), sw_if_index,
- format_fib_protocol, fproto,
- format_ip46_address, peer, IP46_TYPE_ANY);
+ vnet_get_main (), sw_if_index, format_ip_address, peer);
return (VNET_API_ERROR_NO_SUCH_ENTRY);
}
return 0;
@@ -298,8 +302,7 @@ format_teib_entry (u8 * s, va_list * args)
s = format (s, "[%d] ", tei);
s = format (s, "%U:", format_vnet_sw_if_index_name,
vnm, te->te_key->tk_sw_if_index);
- s = format (s, " %U:", format_fib_protocol, te->te_key->tk_proto);
- s = format (s, "%U", format_ip46_address,
+ s = format (s, "%U", format_ip_address,
&te->te_key->tk_peer, IP46_TYPE_ANY);
s = format (s, " via [%d]:%U",
fib_table_get_table_id (te->te_fib_index, te->te_nh.fp_proto),
@@ -337,7 +340,7 @@ teib_walk_itf (u32 sw_if_index, teib_walk_cb_t fn, void *ctx)
static void
teib_walk_itf_proto (u32 sw_if_index,
- fib_protocol_t fproto, teib_walk_cb_t fn, void *ctx)
+ ip_address_family_t af, teib_walk_cb_t fn, void *ctx)
{
index_t tei;
@@ -345,7 +348,7 @@ teib_walk_itf_proto (u32 sw_if_index,
pool_foreach_index(tei, teib_pool,
({
if (sw_if_index == teib_entry_get_sw_if_index(teib_entry_get(tei)) &&
- fproto == teib_entry_get_proto(teib_entry_get(tei)))
+ af == teib_entry_get_af(teib_entry_get(tei)))
fn(tei, ctx);
}));
/* *INDENT-ON* */
@@ -367,11 +370,9 @@ teib_walk_table_bind (index_t tei, void *arg)
TEIB_TE_INFO (te, "bind: %d -> %d", ctx->old_fib_index, ctx->new_fib_index);
- teib_adj_fib_remove (te->te_key->tk_proto,
- &te->te_key->tk_peer,
+ teib_adj_fib_remove (&te->te_key->tk_peer,
te->te_key->tk_sw_if_index, ctx->old_fib_index);
- teib_adj_fib_add (te->te_key->tk_proto,
- &te->te_key->tk_peer,
+ teib_adj_fib_add (&te->te_key->tk_peer,
te->te_key->tk_sw_if_index, ctx->new_fib_index);
return (WALK_CONTINUE);
@@ -387,8 +388,7 @@ teib_table_bind_v4 (ip4_main_t * im,
.new_fib_index = new_fib_index,
};
- teib_walk_itf_proto (sw_if_index,
- FIB_PROTOCOL_IP4, teib_walk_table_bind, &ctx);
+ teib_walk_itf_proto (sw_if_index, AF_IP4, teib_walk_table_bind, &ctx);
}
static void
@@ -401,8 +401,7 @@ teib_table_bind_v6 (ip6_main_t * im,
.new_fib_index = new_fib_index,
};
- teib_walk_itf_proto (sw_if_index,
- FIB_PROTOCOL_IP6, teib_walk_table_bind, &ctx);
+ teib_walk_itf_proto (sw_if_index, AF_IP6, teib_walk_table_bind, &ctx);
}
void
@@ -414,10 +413,7 @@ teib_register (const teib_vft_t * vft)
static clib_error_t *
teib_init (vlib_main_t * vm)
{
- fib_protocol_t fproto;
-
- FOR_EACH_FIB_IP_PROTOCOL (fproto)
- teib_db[fproto] = hash_create_mem (0, sizeof (teib_key_t), sizeof (u32));
+ teib_db.td_db = hash_create_mem (0, sizeof (teib_key_t), sizeof (u32));
ip4_table_bind_callback_t cb4 = {
.function = teib_table_bind_v4,
diff --git a/src/vnet/teib/teib.h b/src/vnet/teib/teib.h
index 2a5da76ef93..69fa740f432 100644
--- a/src/vnet/teib/teib.h
+++ b/src/vnet/teib/teib.h
@@ -36,8 +36,7 @@ typedef struct teib_entry_t_ teib_entry_t;
/** accessors for the opaque struct */
extern u32 teib_entry_get_sw_if_index (const teib_entry_t * ne);
extern u32 teib_entry_get_fib_index (const teib_entry_t * ne);
-extern const ip46_address_t *teib_entry_get_peer (const teib_entry_t * ne);
-extern fib_protocol_t teib_entry_get_proto (const teib_entry_t * ne);
+extern const ip_address_t *teib_entry_get_peer (const teib_entry_t * ne);
extern const fib_prefix_t *teib_entry_get_nh (const teib_entry_t * ne);
extern u8 *format_teib_entry (u8 * s, va_list * args);
@@ -45,17 +44,16 @@ extern u8 *format_teib_entry (u8 * s, va_list * args);
* Create a new TEIB entry
*/
extern int teib_entry_add (u32 sw_if_index,
- fib_protocol_t fproto,
- const ip46_address_t * peer,
- u32 nh_table_id, const ip46_address_t * nh);
+ const ip_address_t * peer,
+ u32 nh_table_id, const ip_address_t * nh);
-extern int teib_entry_del (u32 sw_if_index,
- fib_protocol_t fproto,
- const ip46_address_t * peer);
+extern int teib_entry_del (u32 sw_if_index, const ip_address_t * peer);
extern teib_entry_t *teib_entry_find (u32 sw_if_index,
- fib_protocol_t fproto,
- const ip46_address_t * peer);
+ const ip_address_t * peer);
+extern teib_entry_t *teib_entry_find_46 (u32 sw_if_index,
+ fib_protocol_t fproto,
+ const ip46_address_t * peer);
extern teib_entry_t *teib_entry_get (index_t nei);
extern void teib_entry_adj_stack (const teib_entry_t * ne, adj_index_t ai);
diff --git a/src/vnet/teib/teib_api.c b/src/vnet/teib/teib_api.c
index b885128baf4..2cd56327efb 100644
--- a/src/vnet/teib/teib_api.c
+++ b/src/vnet/teib/teib_api.c
@@ -39,26 +39,19 @@ static void
vl_api_teib_entry_add_del_t_handler (vl_api_teib_entry_add_del_t * mp)
{
vl_api_teib_entry_add_del_reply_t *rmp;
- ip46_address_t nh;
- ip_address_t peer;
+ ip_address_t peer, nh;
int rv;
VALIDATE_SW_IF_INDEX ((&mp->entry));
ip_address_decode2 (&mp->entry.peer, &peer);
- ip_address_decode (&mp->entry.nh, &nh);
+ ip_address_decode2 (&mp->entry.nh, &nh);
if (mp->is_add)
rv = teib_entry_add (ntohl (mp->entry.sw_if_index),
- ip_address_family_to_fib_proto (ip_addr_version
- (&peer)),
- &ip_addr_46 (&peer), ntohl (mp->entry.nh_table_id),
- &nh);
+ &peer, ntohl (mp->entry.nh_table_id), &nh);
else
- rv = teib_entry_del (ntohl (mp->entry.sw_if_index),
- ip_address_family_to_fib_proto (ip_addr_version
- (&peer)),
- &ip_addr_46 (&peer));
+ rv = teib_entry_del (ntohl (mp->entry.sw_if_index), &peer);
BAD_SW_IF_INDEX_LABEL;
@@ -86,8 +79,7 @@ vl_api_teib_send_one (index_t nei, void *arg)
ne = teib_entry_get (nei);
pfx = teib_entry_get_nh (ne);
- ip_address_encode (teib_entry_get_peer (ne), IP46_TYPE_ANY,
- &mp->entry.peer);
+ ip_address_encode2 (teib_entry_get_peer (ne), &mp->entry.peer);
ip_address_encode (&pfx->fp_addr, IP46_TYPE_ANY, &mp->entry.nh);
mp->entry.nh_table_id =
htonl (fib_table_get_table_id
diff --git a/src/vnet/teib/teib_cli.c b/src/vnet/teib/teib_cli.c
index 63e3645f14a..226b41298ab 100644
--- a/src/vnet/teib/teib_cli.c
+++ b/src/vnet/teib/teib_cli.c
@@ -20,8 +20,8 @@ teib_add (vlib_main_t * vm,
unformat_input_t * input, vlib_cli_command_t * cmd)
{
unformat_input_t _line_input, *line_input = &_line_input;
- ip46_address_t nh = ip46_address_initializer;
- ip_address_t peer = IP_ADDRESS_V6_ALL_0S;
+ ip_address_t peer = ip_address_initializer;
+ ip_address_t nh = ip_address_initializer;
u32 sw_if_index, nh_table_id;
clib_error_t *error = NULL;
int rv;
@@ -40,7 +40,7 @@ teib_add (vlib_main_t * vm,
;
else if (unformat (line_input, "peer %U", unformat_ip_address, &peer))
;
- else if (unformat (line_input, "nh %U", unformat_ip46_address, &nh))
+ else if (unformat (line_input, "nh %U", unformat_ip_address, &nh))
;
else if (unformat (line_input, "nh-table-id %d", &nh_table_id))
;
@@ -64,17 +64,14 @@ teib_add (vlib_main_t * vm,
format_unformat_error, line_input);
goto done;
}
- if (ip46_address_is_zero (&nh))
+ if (ip_address_is_zero (&nh))
{
error = clib_error_return (0, "next-hop required'",
format_unformat_error, line_input);
goto done;
}
- rv = teib_entry_add (sw_if_index,
- ip_address_family_to_fib_proto (ip_addr_version
- (&peer)),
- &ip_addr_46 (&peer), nh_table_id, &nh);
+ rv = teib_entry_add (sw_if_index, &peer, nh_table_id, &nh);
if (rv)
{
@@ -102,7 +99,7 @@ teib_del (vlib_main_t * vm,
unformat_input_t * input, vlib_cli_command_t * cmd)
{
unformat_input_t _line_input, *line_input = &_line_input;
- ip_address_t peer = IP_ADDRESS_V6_ALL_0S;
+ ip_address_t peer = ip_address_initializer;
clib_error_t *error = NULL;
u32 sw_if_index;
int rv;
@@ -140,10 +137,7 @@ teib_del (vlib_main_t * vm,
goto done;
}
- rv = teib_entry_del (sw_if_index,
- ip_address_family_to_fib_proto (ip_addr_version
- (&peer)),
- &ip_addr_46 (&peer));
+ rv = teib_entry_del (sw_if_index, &peer);
if (rv)
{