summaryrefslogtreecommitdiffstats
path: root/src/vnet/cop/cop.c
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2019-05-14 18:01:44 -0400
committerFlorin Coras <florin.coras@gmail.com>2019-05-16 16:11:23 +0000
commitf8d50682cd1245f6f5ce4c846ca6f1bdc11255a6 (patch)
tree8ecc60e4715db88bdbc8ea6bd0170fbae6f645eb /src/vnet/cop/cop.c
parentc1f93067ed4b9954bbba82e2c9c104b22e2f7f33 (diff)
init / exit function ordering
The vlib init function subsystem now supports a mix of procedural and formally-specified ordering constraints. We should eliminate procedural knowledge wherever possible. The following schemes are *roughly* equivalent: static clib_error_t *init_runs_first (vlib_main_t *vm) { clib_error_t *error; ... do some stuff... if ((error = vlib_call_init_function (init_runs_next))) return error; ... } VLIB_INIT_FUNCTION (init_runs_first); and static clib_error_t *init_runs_first (vlib_main_t *vm) { ... do some stuff... } VLIB_INIT_FUNCTION (init_runs_first) = { .runs_before = VLIB_INITS("init_runs_next"), }; The first form will [most likely] call "init_runs_next" on the spot. The second form means that "init_runs_first" runs before "init_runs_next," possibly much earlier in the sequence. Please DO NOT construct sets of init functions where A before B actually means A *right before* B. It's not necessary - simply combine A and B - and it leads to hugely annoying debugging exercises when trying to switch from ad-hoc procedural ordering constraints to formal ordering constraints. Change-Id: I5e4353503bf43b4acb11a45fb33c79a5ade8426c Signed-off-by: Dave Barach <dave@barachs.net>
Diffstat (limited to 'src/vnet/cop/cop.c')
-rw-r--r--src/vnet/cop/cop.c63
1 files changed, 30 insertions, 33 deletions
diff --git a/src/vnet/cop/cop.c b/src/vnet/cop/cop.c
index 700bd7348ed..edd09856092 100644
--- a/src/vnet/cop/cop.c
+++ b/src/vnet/cop/cop.c
@@ -29,7 +29,7 @@ cop_sw_interface_add_del (vnet_main_t * vnm, u32 sw_if_index, u32 is_add)
clib_memset (data, 0, sizeof(*data));
- /*
+ /*
* Ignore local interface, pg interfaces. $$$ need a #define for the
* first "real" interface. The answer is 5 at the moment.
*/
@@ -41,7 +41,7 @@ cop_sw_interface_add_del (vnet_main_t * vnm, u32 sw_if_index, u32 is_add)
{
ccm = &cm->cop_config_mains[address_family];
- /*
+ /*
* Once-only code to initialize the per-address-family
* cop feature subgraphs.
* Since the (single) start-node, cop-input, must be able
@@ -60,8 +60,8 @@ cop_sw_interface_add_del (vnet_main_t * vnm, u32 sw_if_index, u32 is_add)
[IP4_RX_COP_WHITELIST] = "ip4-cop-whitelist",
[IP4_RX_COP_INPUT] = "ip4-input",
};
-
- vnet_config_init (vm, &ccm->config_main,
+
+ vnet_config_init (vm, &ccm->config_main,
start_nodes, ARRAY_LEN(start_nodes),
feature_nodes, ARRAY_LEN(feature_nodes));
}
@@ -73,7 +73,7 @@ cop_sw_interface_add_del (vnet_main_t * vnm, u32 sw_if_index, u32 is_add)
[IP6_RX_COP_WHITELIST] = "ip6-cop-whitelist",
[IP6_RX_COP_INPUT] = "ip6-input",
};
- vnet_config_init (vm, &ccm->config_main,
+ vnet_config_init (vm, &ccm->config_main,
start_nodes, ARRAY_LEN(start_nodes),
feature_nodes, ARRAY_LEN(feature_nodes));
}
@@ -86,7 +86,7 @@ cop_sw_interface_add_del (vnet_main_t * vnm, u32 sw_if_index, u32 is_add)
[DEFAULT_RX_COP_WHITELIST] = "default-cop-whitelist",
[DEFAULT_RX_COP_INPUT] = "ethernet-input",
};
- vnet_config_init (vm, &ccm->config_main,
+ vnet_config_init (vm, &ccm->config_main,
start_nodes, ARRAY_LEN(start_nodes),
feature_nodes, ARRAY_LEN(feature_nodes));
}
@@ -109,15 +109,15 @@ cop_sw_interface_add_del (vnet_main_t * vnm, u32 sw_if_index, u32 is_add)
default_next = IP6_RX_COP_INPUT;
else
default_next = DEFAULT_RX_COP_INPUT;
-
+
if (is_add)
ci = vnet_config_add_feature (vm, &ccm->config_main,
- ci,
+ ci,
default_next,
data, sizeof(*data));
else
ci = vnet_config_del_feature (vm, &ccm->config_main,
- ci,
+ ci,
default_next,
data, sizeof(*data));
@@ -132,13 +132,6 @@ static clib_error_t *
cop_init (vlib_main_t *vm)
{
cop_main_t * cm = &cop_main;
- clib_error_t * error;
-
- if ((error = vlib_call_init_function (vm, ip4_whitelist_init)))
- return error;
-
- if ((error = vlib_call_init_function (vm, ip6_whitelist_init)))
- return error;
cm->vlib_main = vm;
cm->vnet_main = vnet_get_main();
@@ -146,7 +139,12 @@ cop_init (vlib_main_t *vm)
return 0;
}
-VLIB_INIT_FUNCTION (cop_init);
+/* *INDENT-OFF* */
+VLIB_INIT_FUNCTION (cop_init) =
+{
+ .runs_after = VLIB_INITS ("ip4_whitelist_init", "ip6_whitelist_init"),
+};
+/* *INDENT-ON* */
int cop_interface_enable_disable (u32 sw_if_index, int enable_disable)
{
@@ -159,11 +157,11 @@ int cop_interface_enable_disable (u32 sw_if_index, int enable_disable)
sw = vnet_get_sw_interface (cm->vnet_main, sw_if_index);
if (sw->type != VNET_SW_INTERFACE_TYPE_HARDWARE)
return VNET_API_ERROR_INVALID_SW_IF_INDEX;
-
- /*
+
+ /*
* Redirect pkts from the driver to the cop node.
* Returns VNET_API_ERROR_UNIMPLEMENTED if the h/w driver
- * doesn't implement the API.
+ * doesn't implement the API.
*
* Node_index = ~0 => shut off redirection
*/
@@ -180,7 +178,7 @@ cop_enable_disable_command_fn (vlib_main_t * vm,
cop_main_t * cm = &cop_main;
u32 sw_if_index = ~0;
int enable_disable = 1;
-
+
int rv;
while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
@@ -195,7 +193,7 @@ cop_enable_disable_command_fn (vlib_main_t * vm,
if (sw_if_index == ~0)
return clib_error_return (0, "Please specify an interface...");
-
+
rv = cop_interface_enable_disable (sw_if_index, enable_disable);
switch(rv) {
@@ -203,7 +201,7 @@ cop_enable_disable_command_fn (vlib_main_t * vm,
break;
case VNET_API_ERROR_INVALID_SW_IF_INDEX:
- return clib_error_return
+ return clib_error_return
(0, "Invalid interface, only works on physical ports");
break;
@@ -220,7 +218,7 @@ cop_enable_disable_command_fn (vlib_main_t * vm,
VLIB_CLI_COMMAND (cop_interface_command, static) = {
.path = "cop interface",
- .short_help =
+ .short_help =
"cop interface <interface-name> [disable]",
.function = cop_enable_disable_command_fn,
};
@@ -246,10 +244,10 @@ int cop_whitelist_enable_disable (cop_whitelist_enable_disable_args_t *a)
*/
for (address_family = VNET_COP_IP4; address_family < VNET_N_COPS;
- address_family++)
+ address_family++)
{
ccm = &cm->cop_config_mains[address_family];
-
+
switch(address_family)
{
case VNET_COP_IP4:
@@ -267,7 +265,7 @@ int cop_whitelist_enable_disable (cop_whitelist_enable_disable_args_t *a)
continue;
}
break;
-
+
case VNET_COP_IP6:
is_add = (a->ip6 != 0);
next_to_add_del = IP6_RX_COP_WHITELIST;
@@ -287,7 +285,7 @@ int cop_whitelist_enable_disable (cop_whitelist_enable_disable_args_t *a)
is_add = (a->default_cop != 0);
next_to_add_del = DEFAULT_RX_COP_WHITELIST;
break;
-
+
default:
clib_warning ("BUG");
}
@@ -343,7 +341,7 @@ cop_whitelist_enable_disable_command_fn (vlib_main_t * vm,
if (sw_if_index == ~0)
return clib_error_return (0, "Please specify an interface...");
-
+
a->sw_if_index = sw_if_index;
a->ip4 = ip4;
a->ip6 = ip6;
@@ -357,12 +355,12 @@ cop_whitelist_enable_disable_command_fn (vlib_main_t * vm,
break;
case VNET_API_ERROR_INVALID_SW_IF_INDEX:
- return clib_error_return
+ return clib_error_return
(0, "Invalid interface, only works on physical ports");
break;
case VNET_API_ERROR_NO_SUCH_FIB:
- return clib_error_return
+ return clib_error_return
(0, "Invalid fib");
break;
@@ -380,8 +378,7 @@ cop_whitelist_enable_disable_command_fn (vlib_main_t * vm,
VLIB_CLI_COMMAND (cop_whitelist_command, static) = {
.path = "cop whitelist",
- .short_help =
+ .short_help =
"cop whitelist <interface-name> [ip4][ip6][default][fib-id <NN>][disable]",
.function = cop_whitelist_enable_disable_command_fn,
};
-