aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rwxr-xr-xsrc/plugins/wireguard/wireguard.h4
-rwxr-xr-xsrc/plugins/wireguard/wireguard_api.c14
-rwxr-xr-xsrc/plugins/wireguard/wireguard_cli.c16
-rwxr-xr-xsrc/plugins/wireguard/wireguard_timer.c35
-rwxr-xr-xsrc/plugins/wireguard/wireguard_timer.h1
5 files changed, 68 insertions, 2 deletions
diff --git a/src/plugins/wireguard/wireguard.h b/src/plugins/wireguard/wireguard.h
index 2c892a374b8..ef308c4c397 100755
--- a/src/plugins/wireguard/wireguard.h
+++ b/src/plugins/wireguard/wireguard.h
@@ -41,12 +41,16 @@ typedef struct
u32 out_fq_index;
wg_per_thread_data_t *per_thread_data;
+ u8 feature_init;
tw_timer_wheel_16t_2w_512sl_t timer_wheel;
} wg_main_t;
extern wg_main_t wg_main;
+#define WG_START_EVENT 1
+void wg_feature_init (wg_main_t * wmp);
+
#endif /* __included_wg_h__ */
/*
diff --git a/src/plugins/wireguard/wireguard_api.c b/src/plugins/wireguard/wireguard_api.c
index 283c09915fe..c9fe1e1a2d2 100755
--- a/src/plugins/wireguard/wireguard_api.c
+++ b/src/plugins/wireguard/wireguard_api.c
@@ -43,6 +43,8 @@ static void
u32 sw_if_index = ~0;
int rv = 0;
+ wg_feature_init (wmp);
+
ip_address_decode2 (&mp->interface.src_ip, &src);
if (AF_IP6 == ip_addr_version (&src))
@@ -75,6 +77,8 @@ static void
wg_main_t *wmp = &wg_main;
int rv = 0;
+ wg_feature_init (wmp);
+
VALIDATE_SW_IF_INDEX (mp);
rv = wg_if_delete (ntohl (mp->sw_if_index));
@@ -125,6 +129,9 @@ vl_api_wireguard_interface_dump_t_handler (vl_api_wireguard_interface_dump_t *
mp)
{
vl_api_registration_t *reg;
+ wg_main_t *wmp = &wg_main;
+
+ wg_feature_init (wmp);
reg = vl_api_client_index_to_registration (mp->client_index);
if (reg == 0)
@@ -157,6 +164,8 @@ vl_api_wireguard_peer_add_t_handler (vl_api_wireguard_peer_add_t * mp)
goto done;
}
+ wg_feature_init (wmp);
+
vec_validate (allowed_ips, mp->peer.n_allowed_ips - 1);
ip_address_decode2 (&mp->peer.endpoint, &endpoint);
@@ -195,6 +204,8 @@ vl_api_wireguard_peer_remove_t_handler (vl_api_wireguard_peer_remove_t * mp)
wg_main_t *wmp = &wg_main;
int rv = 0;
+ wg_feature_init (wmp);
+
rv = wg_peer_remove (ntohl (mp->peer_index));
/* *INDENT-OFF* */
@@ -247,6 +258,9 @@ static void
vl_api_wireguard_peers_dump_t_handler (vl_api_wireguard_peers_dump_t * mp)
{
vl_api_registration_t *reg;
+ wg_main_t *wmp = &wg_main;
+
+ wg_feature_init (wmp);
reg = vl_api_client_index_to_registration (mp->client_index);
if (reg == NULL)
diff --git a/src/plugins/wireguard/wireguard_cli.c b/src/plugins/wireguard/wireguard_cli.c
index 16794156d17..3b4bf56a3dc 100755
--- a/src/plugins/wireguard/wireguard_cli.c
+++ b/src/plugins/wireguard/wireguard_cli.c
@@ -23,6 +23,7 @@ static clib_error_t *
wg_if_create_cli (vlib_main_t * vm,
unformat_input_t * input, vlib_cli_command_t * cmd)
{
+ wg_main_t *wmp = &wg_main;
unformat_input_t _line_input, *line_input = &_line_input;
u8 private_key[NOISE_PUBLIC_KEY_LEN];
u32 instance, sw_if_index;
@@ -37,6 +38,8 @@ wg_if_create_cli (vlib_main_t * vm,
private_key_64 = 0;
port = 0;
+ wg_feature_init (wmp);
+
if (unformat_user (input, unformat_line_input, line_input))
{
while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
@@ -104,10 +107,13 @@ static clib_error_t *
wg_if_delete_cli (vlib_main_t * vm,
unformat_input_t * input, vlib_cli_command_t * cmd)
{
+ wg_main_t *wmp = &wg_main;
vnet_main_t *vnm;
u32 sw_if_index;
int rv;
+ wg_feature_init (wmp);
+
vnm = vnet_get_main ();
sw_if_index = ~0;
@@ -151,6 +157,7 @@ wg_peer_add_command_fn (vlib_main_t * vm,
unformat_input_t * input, vlib_cli_command_t * cmd)
{
vnet_main_t *vnm = vnet_get_main ();
+ wg_main_t *wmp = &wg_main;
clib_error_t *error = NULL;
unformat_input_t _line_input, *line_input = &_line_input;
@@ -168,6 +175,8 @@ wg_peer_add_command_fn (vlib_main_t * vm,
if (!unformat_user (input, unformat_line_input, line_input))
return 0;
+ wg_feature_init (wmp);
+
while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
if (unformat (line_input, "public-key %s", &public_key_64))
@@ -259,6 +268,7 @@ static clib_error_t *
wg_peer_remove_command_fn (vlib_main_t * vm,
unformat_input_t * input, vlib_cli_command_t * cmd)
{
+ wg_main_t *wmp = &wg_main;
clib_error_t *error = NULL;
u32 peer_index;
int rv;
@@ -267,6 +277,8 @@ wg_peer_remove_command_fn (vlib_main_t * vm,
if (!unformat_user (input, unformat_line_input, line_input))
return 0;
+ wg_feature_init (wmp);
+
if (unformat (line_input, "%d", &peer_index))
;
else
@@ -336,6 +348,10 @@ static clib_error_t *
wg_show_if_command_fn (vlib_main_t * vm,
unformat_input_t * input, vlib_cli_command_t * cmd)
{
+ wg_main_t *wmp = &wg_main;
+
+ wg_feature_init (wmp);
+
wg_if_walk (wg_if_show_one, vm);
return NULL;
diff --git a/src/plugins/wireguard/wireguard_timer.c b/src/plugins/wireguard/wireguard_timer.c
index b7fd6891d14..7c09617d00e 100755
--- a/src/plugins/wireguard/wireguard_timer.c
+++ b/src/plugins/wireguard/wireguard_timer.c
@@ -334,7 +334,6 @@ wg_timer_wheel_init ()
tw_timer_wheel_init_16t_2w_512sl (tw,
expired_timer_callback,
WG_TICK /* timer period in s */ , ~0);
- tw->last_run_time = vlib_time_now (wmp->vlib_main);
}
static uword
@@ -342,6 +341,28 @@ wg_timer_mngr_fn (vlib_main_t * vm, vlib_node_runtime_t * rt,
vlib_frame_t * f)
{
wg_main_t *wmp = &wg_main;
+ uword event_type = 0;
+
+ /* Park the process until the feature is configured */
+ while (1)
+ {
+ vlib_process_wait_for_event (vm);
+ event_type = vlib_process_get_events (vm, 0);
+ if (event_type == WG_START_EVENT)
+ {
+ break;
+ }
+ else
+ {
+ clib_warning ("Unknown event type %d", event_type);
+ }
+ }
+ /*
+ * Reset the timer wheel time so it won't try to
+ * expire Avogadro's number of time slots.
+ */
+ wmp->timer_wheel.last_run_time = vlib_time_now (vm);
+
while (1)
{
vlib_process_wait_for_event_or_clock (vm, WG_TICK);
@@ -377,6 +398,18 @@ VLIB_REGISTER_NODE (wg_timer_mngr_node, static) = {
};
/* *INDENT-ON* */
+void
+wg_feature_init (wg_main_t * wmp)
+{
+ if (wmp->feature_init)
+ return;
+ vlib_process_signal_event (wmp->vlib_main, wg_timer_mngr_node.index,
+ WG_START_EVENT, 0);
+ wmp->feature_init = 1;
+}
+
+
+
/*
* fd.io coding-style-patch-verification: ON
*
diff --git a/src/plugins/wireguard/wireguard_timer.h b/src/plugins/wireguard/wireguard_timer.h
index 2cc5dd01284..6b59a39f815 100755
--- a/src/plugins/wireguard/wireguard_timer.h
+++ b/src/plugins/wireguard/wireguard_timer.h
@@ -57,7 +57,6 @@ wg_birthdate_has_expired (f64 birthday_seconds, f64 expiration_seconds)
return (birthday_seconds + expiration_seconds) < now_seconds;
}
-
#endif /* __included_wg_timer_h__ */
/*