aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/mpls
diff options
context:
space:
mode:
authorNeale Ranns <nranns@cisco.com>2017-09-10 04:39:11 -0700
committerDamjan Marion <dmarion.lists@gmail.com>2017-09-11 10:14:36 +0000
commit1500254bee11355bbd69cc1dd9705be4f002f2bd (patch)
treec403642105f399baccb3a727020232b5732fe8f7 /src/vnet/mpls
parenta7191840beeb2c3a0f2598707ed1051a9f23c45f (diff)
FIB table add/delete API
part 2; - this adds the code to create an IP and MPLS table via the API. - but the enforcement that the table must be created before it is used is still missing, this is so that CSIT can pass. Change-Id: Id124d884ade6cb7da947225200e3bb193454c555 Signed-off-by: Neale Ranns <nranns@cisco.com>
Diffstat (limited to 'src/vnet/mpls')
-rw-r--r--src/vnet/mpls/interface.c26
-rw-r--r--src/vnet/mpls/mpls.c76
-rw-r--r--src/vnet/mpls/mpls.h16
-rw-r--r--src/vnet/mpls/mpls_api.c66
4 files changed, 154 insertions, 30 deletions
diff --git a/src/vnet/mpls/interface.c b/src/vnet/mpls/interface.c
index a085aaa2f19..d7c8e7d340e 100644
--- a/src/vnet/mpls/interface.c
+++ b/src/vnet/mpls/interface.c
@@ -35,25 +35,33 @@ mpls_sw_interface_is_enabled (u32 sw_if_index)
return (mm->mpls_enabled_by_sw_if_index[sw_if_index]);
}
-void
+int
mpls_sw_interface_enable_disable (mpls_main_t * mm,
u32 sw_if_index,
- u8 is_enable)
+ u8 is_enable,
+ u8 is_api)
{
fib_node_index_t lfib_index;
vec_validate_init_empty (mm->mpls_enabled_by_sw_if_index, sw_if_index, 0);
+ lfib_index = fib_table_find(FIB_PROTOCOL_MPLS,
+ MPLS_FIB_DEFAULT_TABLE_ID);
+
+ if (~0 == lfib_index)
+ return VNET_API_ERROR_NO_SUCH_FIB;
+
/*
* enable/disable only on the 1<->0 transition
*/
if (is_enable)
{
if (1 != ++mm->mpls_enabled_by_sw_if_index[sw_if_index])
- return;
+ return (0);
+
+ fib_table_lock(lfib_index, FIB_PROTOCOL_MPLS,
+ (is_api? FIB_SOURCE_API: FIB_SOURCE_CLI));
- lfib_index = fib_table_find_or_create_and_lock(FIB_PROTOCOL_MPLS,
- MPLS_FIB_DEFAULT_TABLE_ID);
vec_validate(mm->fib_index_by_sw_if_index, 0);
mm->fib_index_by_sw_if_index[sw_if_index] = lfib_index;
}
@@ -61,15 +69,17 @@ mpls_sw_interface_enable_disable (mpls_main_t * mm,
{
ASSERT(mm->mpls_enabled_by_sw_if_index[sw_if_index] > 0);
if (0 != --mm->mpls_enabled_by_sw_if_index[sw_if_index])
- return;
+ return (0);
fib_table_unlock(mm->fib_index_by_sw_if_index[sw_if_index],
- FIB_PROTOCOL_MPLS);
+ FIB_PROTOCOL_MPLS,
+ (is_api? FIB_SOURCE_API: FIB_SOURCE_CLI));
}
vnet_feature_enable_disable ("mpls-input", "mpls-not-enabled",
sw_if_index, !is_enable, 0, 0);
+ return (0);
}
static clib_error_t *
@@ -101,7 +111,7 @@ mpls_interface_enable_disable (vlib_main_t * vm,
goto done;
}
- mpls_sw_interface_enable_disable(&mpls_main, sw_if_index, enable);
+ mpls_sw_interface_enable_disable(&mpls_main, sw_if_index, enable, 0);
done:
return error;
diff --git a/src/vnet/mpls/mpls.c b/src/vnet/mpls/mpls.c
index 5021ac23bc0..7bdfd8c7c8d 100644
--- a/src/vnet/mpls/mpls.c
+++ b/src/vnet/mpls/mpls.c
@@ -536,6 +536,78 @@ VLIB_CLI_COMMAND (mpls_local_label_command, static) = {
.short_help = "Create/Delete MPL local labels",
};
+clib_error_t *
+vnet_mpls_table_cmd (vlib_main_t * vm,
+ unformat_input_t * main_input,
+ vlib_cli_command_t * cmdo)
+{
+ unformat_input_t _line_input, *line_input = &_line_input;
+ clib_error_t *error = NULL;
+ u32 table_id, is_add;
+
+ is_add = 1;
+ table_id = ~0;
+
+ /* Get a line of input. */
+ if (!unformat_user (main_input, unformat_line_input, line_input))
+ return 0;
+
+ while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (line_input, "%d", &table_id))
+ ;
+ else if (unformat (line_input, "del"))
+ is_add = 0;
+ else if (unformat (line_input, "add"))
+ is_add = 1;
+ else
+ {
+ error = unformat_parse_error (line_input);
+ goto done;
+ }
+ }
+
+ if (~0 == table_id)
+ {
+ error = clib_error_return (0, "No table id");
+ goto done;
+ }
+ else if (0 == table_id)
+ {
+ error = clib_error_return (0, "Can't change the default table");
+ goto done;
+ }
+ else
+ {
+ if (is_add)
+ {
+ mpls_table_create (table_id, 0);
+ }
+ else
+ {
+ mpls_table_delete (table_id, 0);
+ }
+ }
+
+ done:
+ unformat_free (line_input);
+ return error;
+}
+
+/* *INDENT-ON* */
+/*?
+ * This command is used to add or delete MPLS Tables. All
+ * Tables must be explicitly added before that can be used,
+ * Including the default table.
+ ?*/
+/* *INDENT-OFF* */
+VLIB_CLI_COMMAND (ip6_table_command, static) = {
+ .path = "mpla table",
+ .short_help = "mpls table [add|del] <table-id>",
+ .function = vnet_mpls_table_cmd,
+ .is_mp_safe = 1,
+};
+
int
mpls_fib_reset_labels (u32 fib_id)
{
@@ -546,12 +618,8 @@ mpls_fib_reset_labels (u32 fib_id)
static clib_error_t *
mpls_init (vlib_main_t * vm)
{
- mpls_main_t * mm = &mpls_main;
clib_error_t * error;
- mm->vlib_main = vm;
- mm->vnet_main = vnet_get_main();
-
if ((error = vlib_call_init_function (vm, ip_main_init)))
return error;
diff --git a/src/vnet/mpls/mpls.h b/src/vnet/mpls/mpls.h
index b0125e60c63..31cb1746f71 100644
--- a/src/vnet/mpls/mpls.h
+++ b/src/vnet/mpls/mpls.h
@@ -56,10 +56,6 @@ typedef struct {
/* IP4 enabled count by software interface */
u8 * mpls_enabled_by_sw_if_index;
-
- /* convenience */
- vlib_main_t * vlib_main;
- vnet_main_t * vnet_main;
} mpls_main_t;
extern mpls_main_t mpls_main;
@@ -77,8 +73,6 @@ extern vlib_node_registration_t mpls_midchain_node;
/* Parse mpls protocol as 0xXXXX or protocol name.
In either host or network byte order. */
-unformat_function_t unformat_mpls_protocol_host_byte_order;
-unformat_function_t unformat_mpls_protocol_net_byte_order;
unformat_function_t unformat_mpls_label_net_byte_order;
unformat_function_t unformat_mpls_unicast_label;
@@ -86,9 +80,10 @@ unformat_function_t unformat_mpls_unicast_label;
unformat_function_t unformat_mpls_header;
unformat_function_t unformat_pg_mpls_header;
-void mpls_sw_interface_enable_disable (mpls_main_t * mm,
- u32 sw_if_index,
- u8 is_enable);
+int mpls_sw_interface_enable_disable (mpls_main_t * mm,
+ u32 sw_if_index,
+ u8 is_enable,
+ u8 is_api);
u8 mpls_sw_interface_is_enabled (u32 sw_if_index);
@@ -103,4 +98,7 @@ mpls_fib_index_cmp(void * a1, void * a2);
int
mpls_label_cmp(void * a1, void * a2);
+void mpls_table_create(uint32_t table_id, u8 is_api);
+void mpls_table_delete(uint32_t table_id, u8 is_api);
+
#endif /* included_vnet_mpls_h */
diff --git a/src/vnet/mpls/mpls_api.c b/src/vnet/mpls/mpls_api.c
index a44b1a25653..38f5b014344 100644
--- a/src/vnet/mpls/mpls_api.c
+++ b/src/vnet/mpls/mpls_api.c
@@ -59,6 +59,29 @@ extern void stats_dslock_with_hint (int hint, int tag);
extern void stats_dsunlock (void);
void
+mpls_table_delete (u32 table_id, u8 is_api)
+{
+ u32 fib_index;
+
+ /*
+ * The MPLS defult table must also be explicitly created via the API.
+ * So in contrast to IP, it gets no special treatment here.
+ *
+ * The API holds only one lock on the table.
+ * i.e. it can be added many times via the API but needs to be
+ * deleted only once.
+ */
+ fib_index = fib_table_find (FIB_PROTOCOL_MPLS, table_id);
+
+ if (~0 != fib_index)
+ {
+ fib_table_unlock (fib_index,
+ FIB_PROTOCOL_MPLS,
+ (is_api ? FIB_SOURCE_API : FIB_SOURCE_CLI));
+ }
+}
+
+void
vl_api_mpls_table_add_del_t_handler (vl_api_mpls_table_add_del_t * mp)
{
vl_api_mpls_table_add_del_reply_t *rmp;
@@ -68,6 +91,13 @@ vl_api_mpls_table_add_del_t_handler (vl_api_mpls_table_add_del_t * mp)
vnm = vnet_get_main ();
vnm->api_errno = 0;
+ if (mp->mt_is_add)
+ mpls_table_create (ntohl (mp->mt_table_id), 1);
+ else
+ mpls_table_delete (ntohl (mp->mt_table_id), 1);
+
+ rv = (rv == 0) ? vnm->api_errno : rv;
+
REPLY_MACRO (VL_API_MPLS_TABLE_ADD_DEL_REPLY);
}
@@ -82,14 +112,7 @@ mpls_ip_bind_unbind_handler (vnet_main_t * vnm,
if (~0 == mpls_fib_index)
{
- if (mp->mb_create_table_if_needed)
- {
- mpls_fib_index =
- fib_table_find_or_create_and_lock (FIB_PROTOCOL_MPLS,
- ntohl (mp->mb_mpls_table_id));
- }
- else
- return VNET_API_ERROR_NO_SUCH_FIB;
+ return VNET_API_ERROR_NO_SUCH_FIB;
}
ip_fib_index = fib_table_find ((mp->mb_is_ip4 ?
@@ -170,7 +193,6 @@ mpls_route_add_del_t_handler (vnet_main_t * vnm,
mp->mr_next_hop_sw_if_index,
pfx.fp_payload_proto,
mp->mr_next_hop_table_id,
- mp->mr_create_table_if_needed,
mp->mr_is_rpf_id,
&fib_index, &next_hop_fib_index);
@@ -235,6 +257,32 @@ vl_api_mpls_route_add_del_t_handler (vl_api_mpls_route_add_del_t * mp)
REPLY_MACRO (VL_API_MPLS_ROUTE_ADD_DEL_REPLY);
}
+void
+mpls_table_create (u32 table_id, u8 is_api)
+{
+ u32 fib_index;
+
+ /*
+ * The MPLS defult table must also be explicitly created via the API.
+ * So in contrast to IP, it gets no special treatment here.
+ */
+
+ /*
+ * The API holds only one lock on the table.
+ * i.e. it can be added many times via the API but needs to be
+ * deleted only once.
+ */
+ fib_index = fib_table_find (FIB_PROTOCOL_MPLS, table_id);
+
+ if (~0 == fib_index)
+ {
+ fib_table_find_or_create_and_lock (FIB_PROTOCOL_MPLS,
+ table_id,
+ (is_api ?
+ FIB_SOURCE_API : FIB_SOURCE_CLI));
+ }
+}
+
static void
vl_api_mpls_tunnel_add_del_t_handler (vl_api_mpls_tunnel_add_del_t * mp)
{