summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/plugins/unittest/session_test.c3
-rw-r--r--src/vnet/interface_api.c5
-rw-r--r--src/vnet/ip/ip.api17
-rw-r--r--src/vnet/ip/ip.h2
-rw-r--r--src/vnet/ip/ip_api.c65
-rw-r--r--src/vnet/ip/ip_test.c54
-rw-r--r--src/vnet/ip/lookup.c7
7 files changed, 133 insertions, 20 deletions
diff --git a/src/plugins/unittest/session_test.c b/src/plugins/unittest/session_test.c
index 12d000bd46f..6d28b2d25ec 100644
--- a/src/plugins/unittest/session_test.c
+++ b/src/plugins/unittest/session_test.c
@@ -133,7 +133,8 @@ session_create_lookpback (u32 table_id, u32 * sw_if_index,
if (table_id != 0)
{
- ip_table_create (FIB_PROTOCOL_IP4, table_id, 0, 0);
+ ip_table_create (FIB_PROTOCOL_IP4, table_id, 0 /* is_api */,
+ 1 /* create_mfib */, 0);
ip_table_bind (FIB_PROTOCOL_IP4, *sw_if_index, table_id);
}
diff --git a/src/vnet/interface_api.c b/src/vnet/interface_api.c
index c727e519138..69bf4b72ba4 100644
--- a/src/vnet/interface_api.c
+++ b/src/vnet/interface_api.c
@@ -579,7 +579,7 @@ ip_table_bind (fib_protocol_t fproto, u32 sw_if_index, u32 table_id)
fib_index = fib_table_find (fproto, table_id);
mfib_index = mfib_table_find (fproto, table_id);
- if (~0 == fib_index || ~0 == mfib_index)
+ if (~0 == fib_index)
{
return (VNET_API_ERROR_NO_SUCH_FIB);
}
@@ -601,7 +601,8 @@ ip_table_bind (fib_protocol_t fproto, u32 sw_if_index, u32 table_id)
/* clang-format on */
fib_table_bind (fproto, sw_if_index, fib_index);
- mfib_table_bind (fproto, sw_if_index, mfib_index);
+ if (mfib_index != ~0)
+ mfib_table_bind (fproto, sw_if_index, mfib_index);
return (0);
}
diff --git a/src/vnet/ip/ip.api b/src/vnet/ip/ip.api
index 967f56cf917..fc7d7582dec 100644
--- a/src/vnet/ip/ip.api
+++ b/src/vnet/ip/ip.api
@@ -57,6 +57,23 @@ autoreply define ip_table_add_del
vl_api_ip_table_t table;
};
+/** \brief Add / del table request - version 2
+ A table can be added multiple times, but need be deleted only once.
+ @param client_index - opaque cookie to identify the sender
+ @param context - sender context, to match reply w/ request
+ @param table - the FIB table to add or del
+ @param create_mfib - whether to create mfib or not
+ @param is_add - add or del
+*/
+autoreply define ip_table_add_del_v2
+{
+ u32 client_index;
+ u32 context;
+ vl_api_ip_table_t table;
+ bool create_mfib [default=true];
+ bool is_add [default=true];
+};
+
/** \brief Allocate an unused table
A table can be added multiple times.
If a large number of tables are in use (millions), this API might
diff --git a/src/vnet/ip/ip.h b/src/vnet/ip/ip.h
index 9ebefa0cf5d..084243dccfa 100644
--- a/src/vnet/ip/ip.h
+++ b/src/vnet/ip/ip.h
@@ -262,7 +262,7 @@ extern vlib_node_registration_t ip4_inacl_node;
extern vlib_node_registration_t ip6_inacl_node;
void ip_table_create (fib_protocol_t fproto, u32 table_id, u8 is_api,
- const u8 * name);
+ u8 create_mfib, const u8 *name);
void ip_table_delete (fib_protocol_t fproto, u32 table_id, u8 is_api);
diff --git a/src/vnet/ip/ip_api.c b/src/vnet/ip/ip_api.c
index 6dd95140f4b..5ced88fec2e 100644
--- a/src/vnet/ip/ip_api.c
+++ b/src/vnet/ip/ip_api.c
@@ -636,7 +636,8 @@ vl_api_ip_table_add_del_t_handler (vl_api_ip_table_add_del_t * mp)
if (mp->is_add)
{
- ip_table_create (fproto, table_id, 1, mp->table.name);
+ ip_table_create (fproto, table_id, 1 /* is_api */, 1 /* create_mfib */,
+ mp->table.name);
}
else
{
@@ -647,6 +648,28 @@ vl_api_ip_table_add_del_t_handler (vl_api_ip_table_add_del_t * mp)
}
void
+vl_api_ip_table_add_del_v2_t_handler (vl_api_ip_table_add_del_v2_t *mp)
+{
+ vl_api_ip_table_add_del_v2_reply_t *rmp;
+ fib_protocol_t fproto =
+ (mp->table.is_ip6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4);
+ u32 table_id = ntohl (mp->table.table_id);
+ int rv = 0;
+
+ if (mp->is_add)
+ {
+ ip_table_create (fproto, table_id, 1 /* is_api */, mp->create_mfib,
+ mp->table.name);
+ }
+ else
+ {
+ ip_table_delete (fproto, table_id, 1);
+ }
+
+ REPLY_MACRO (VL_API_IP_TABLE_ADD_DEL_V2_REPLY);
+}
+
+void
vl_api_ip_table_allocate_t_handler (vl_api_ip_table_allocate_t *mp)
{
vl_api_ip_table_allocate_reply_t *rmp;
@@ -661,7 +684,8 @@ vl_api_ip_table_allocate_t_handler (vl_api_ip_table_allocate_t *mp)
if (~0 == table_id)
rv = VNET_API_ERROR_EAGAIN;
else
- ip_table_create (fproto, table_id, 1, mp->table.name);
+ ip_table_create (fproto, table_id, 1 /* is_api */, 1 /* create_mfib */,
+ mp->table.name);
REPLY_MACRO2 (VL_API_IP_TABLE_ALLOCATE_REPLY, {
clib_memcpy_fast (&rmp->table, &mp->table, sizeof (mp->table));
@@ -915,8 +939,8 @@ vl_api_ip_route_lookup_v2_t_handler (vl_api_ip_route_lookup_v2_t *mp)
}
void
-ip_table_create (fib_protocol_t fproto,
- u32 table_id, u8 is_api, const u8 * name)
+ip_table_create (fib_protocol_t fproto, u32 table_id, u8 is_api,
+ u8 create_mfib, const u8 *name)
{
u32 fib_index, mfib_index;
vnet_main_t *vnm = vnet_get_main ();
@@ -936,16 +960,23 @@ ip_table_create (fib_protocol_t fproto,
* their own unicast tables.
*/
fib_index = fib_table_find (fproto, table_id);
- mfib_index = mfib_table_find (fproto, table_id);
-
/*
* Always try to re-lock in case the fib was deleted by an API call
* but was not yet freed because some other locks were held
*/
fib_table_find_or_create_and_lock_w_name (
fproto, table_id, (is_api ? FIB_SOURCE_API : FIB_SOURCE_CLI), name);
- mfib_table_find_or_create_and_lock_w_name (
- fproto, table_id, (is_api ? MFIB_SOURCE_API : MFIB_SOURCE_CLI), name);
+
+ if (create_mfib)
+ {
+ /* same for mfib, if needs be */
+ mfib_index = mfib_table_find (fproto, table_id);
+ mfib_table_find_or_create_and_lock_w_name (
+ fproto, table_id, (is_api ? MFIB_SOURCE_API : MFIB_SOURCE_CLI),
+ name);
+ }
+ else
+ mfib_index = 0;
if ((~0 == fib_index) || (~0 == mfib_index))
call_elf_section_ip_table_callbacks (vnm, table_id, 1 /* is_add */ ,
@@ -1655,9 +1686,10 @@ vl_api_ip_table_replace_begin_t_handler (vl_api_ip_table_replace_begin_t * mp)
rv = VNET_API_ERROR_NO_SUCH_FIB;
else
{
+ u32 mfib_index = mfib_table_find (fproto, ntohl (mp->table.table_id));
fib_table_mark (fib_index, fproto, FIB_SOURCE_API);
- mfib_table_mark (mfib_table_find (fproto, ntohl (mp->table.table_id)),
- fproto, MFIB_SOURCE_API);
+ if (mfib_index != INDEX_INVALID)
+ mfib_table_mark (mfib_index, fproto, MFIB_SOURCE_API);
}
REPLY_MACRO (VL_API_IP_TABLE_REPLACE_BEGIN_REPLY);
}
@@ -1677,10 +1709,10 @@ vl_api_ip_table_replace_end_t_handler (vl_api_ip_table_replace_end_t * mp)
rv = VNET_API_ERROR_NO_SUCH_FIB;
else
{
+ u32 mfib_index = mfib_table_find (fproto, ntohl (mp->table.table_id));
fib_table_sweep (fib_index, fproto, FIB_SOURCE_API);
- mfib_table_sweep (mfib_table_find
- (fproto, ntohl (mp->table.table_id)), fproto,
- MFIB_SOURCE_API);
+ if (mfib_index != INDEX_INVALID)
+ mfib_table_sweep (mfib_index, fproto, MFIB_SOURCE_API);
}
REPLY_MACRO (VL_API_IP_TABLE_REPLACE_END_REPLY);
}
@@ -1703,6 +1735,7 @@ vl_api_ip_table_flush_t_handler (vl_api_ip_table_flush_t * mp)
vnet_main_t *vnm = vnet_get_main ();
vnet_interface_main_t *im = &vnm->interface_main;
vnet_sw_interface_t *si;
+ u32 mfib_index;
/* Shut down interfaces in this FIB / clean out intfc routes */
pool_foreach (si, im->sw_interfaces)
@@ -1717,8 +1750,10 @@ vl_api_ip_table_flush_t_handler (vl_api_ip_table_flush_t * mp)
}
fib_table_flush (fib_index, fproto, FIB_SOURCE_API);
- mfib_table_flush (mfib_table_find (fproto, ntohl (mp->table.table_id)),
- fproto, MFIB_SOURCE_API);
+
+ mfib_index = mfib_table_find (fproto, ntohl (mp->table.table_id));
+ if (mfib_index != INDEX_INVALID)
+ mfib_table_flush (mfib_index, fproto, MFIB_SOURCE_API);
}
REPLY_MACRO (VL_API_IP_TABLE_FLUSH_REPLY);
diff --git a/src/vnet/ip/ip_test.c b/src/vnet/ip/ip_test.c
index 727afba67f4..0d1c71063ae 100644
--- a/src/vnet/ip/ip_test.c
+++ b/src/vnet/ip/ip_test.c
@@ -464,6 +464,60 @@ api_ip_table_add_del (vat_main_t *vam)
}
static int
+api_ip_table_add_del_v2 (vat_main_t *vam)
+{
+ unformat_input_t *i = vam->input;
+ vl_api_ip_table_add_del_v2_t *mp;
+ u8 create_mfib = 1;
+ u32 table_id = ~0;
+ u8 is_ipv6 = 0;
+ u8 is_add = 1;
+ int ret = 0;
+
+ /* Parse args required to build the message */
+ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (i, "ipv6"))
+ is_ipv6 = 1;
+ else if (unformat (i, "del"))
+ is_add = 0;
+ else if (unformat (i, "add"))
+ is_add = 1;
+ else if (unformat (i, "table %d", &table_id))
+ ;
+ else if (unformat (i, "no-mfib"))
+ create_mfib = 0;
+ else
+ {
+ clib_warning ("parse error '%U'", format_unformat_error, i);
+ return -99;
+ }
+ }
+
+ if (~0 == table_id)
+ {
+ errmsg ("missing table-ID");
+ return -99;
+ }
+
+ /* Construct the API message */
+ M (IP_TABLE_ADD_DEL_V2, mp);
+
+ mp->table.table_id = ntohl (table_id);
+ mp->table.is_ip6 = is_ipv6;
+ mp->is_add = is_add;
+ mp->create_mfib = create_mfib;
+
+ /* send it... */
+ S (mp);
+
+ /* Wait for a reply... */
+ W (ret);
+
+ return ret;
+}
+
+static int
api_ip_table_replace_begin (vat_main_t *vam)
{
unformat_input_t *i = vam->input;
diff --git a/src/vnet/ip/lookup.c b/src/vnet/ip/lookup.c
index c0fa430e0aa..b978bd79742 100644
--- a/src/vnet/ip/lookup.c
+++ b/src/vnet/ip/lookup.c
@@ -419,10 +419,12 @@ vnet_ip_table_cmd (vlib_main_t * vm,
unformat_input_t _line_input, *line_input = &_line_input;
clib_error_t *error = NULL;
u32 table_id, is_add;
+ u8 create_mfib;
u8 *name = NULL;
is_add = 1;
table_id = ~0;
+ create_mfib = 1;
/* Get a line of input. */
if (!unformat_user (main_input, unformat_line_input, line_input))
@@ -438,6 +440,8 @@ vnet_ip_table_cmd (vlib_main_t * vm,
is_add = 1;
else if (unformat (line_input, "name %s", &name))
;
+ else if (unformat (line_input, "no-mfib"))
+ create_mfib = 0;
else
{
error = unformat_parse_error (line_input);
@@ -459,7 +463,8 @@ vnet_ip_table_cmd (vlib_main_t * vm,
table_id = ip_table_get_unused_id (fproto);
vlib_cli_output (vm, "%u\n", table_id);
}
- ip_table_create (fproto, table_id, 0, name);
+ ip_table_create (fproto, table_id, 0 /* is_api */, create_mfib,
+ name);
}
else
{