NAT64: Run nat64-expire-worker-walk only when NAT64 is configured (VPP-1162)
Change-Id: Ic5e8d74bf5ac84cce5661de44778c89541c67636
Signed-off-by: Matus Fabian <matfabia@cisco.com>
diff --git a/src/plugins/nat/nat64.c b/src/plugins/nat/nat64.c
index 571e071..0b7536f 100644
--- a/src/plugins/nat/nat64.c
+++ b/src/plugins/nat/nat64.c
@@ -232,6 +232,8 @@
nm->tcp_est_timeout = SNAT_TCP_ESTABLISHED_TIMEOUT;
nm->tcp_incoming_syn_timeout = SNAT_TCP_INCOMING_SYN;
+ nm->total_enabled_count = 0;
+
/* Set up the interface address add/del callback */
cb4.function = nat64_ip4_add_del_interface_address_cb;
cb4.function_opaque = 0;
@@ -430,6 +432,12 @@
interface->flags |= NAT_INTERFACE_FLAG_IS_INSIDE;
else
interface->flags |= NAT_INTERFACE_FLAG_IS_OUTSIDE;
+
+ nm->total_enabled_count++;
+ vlib_process_signal_event (nm->sm->vlib_main,
+ nm->nat64_expire_walk_node_index,
+ NAT64_CLEANER_RESCHEDULE, 0);
+
}
else
{
@@ -443,6 +451,8 @@
~NAT_INTERFACE_FLAG_IS_OUTSIDE;
else
pool_put (nm->interfaces, interface);
+
+ nm->total_enabled_count--;
}
if (!is_inside)
@@ -1164,6 +1174,8 @@
};
/* *INDENT-ON* */
+static vlib_node_registration_t nat64_expire_walk_node;
+
/**
* @brief Centralized process to drive per worker expire walk.
*/
@@ -1171,8 +1183,12 @@
nat64_expire_walk_fn (vlib_main_t * vm, vlib_node_runtime_t * rt,
vlib_frame_t * f)
{
+ nat64_main_t *nm = &nat64_main;
vlib_main_t **worker_vms = 0, *worker_vm;
int i;
+ uword event_type, *event_data = 0;
+
+ nm->nat64_expire_walk_node_index = nat64_expire_walk_node.index;
if (vec_len (vlib_mains) == 0)
vec_add1 (worker_vms, vm);
@@ -1188,8 +1204,28 @@
while (1)
{
- vlib_process_wait_for_event_or_clock (vm, 10.0);
- vlib_process_get_events (vm, NULL);
+ if (nm->total_enabled_count)
+ {
+ vlib_process_wait_for_event_or_clock (vm, 10.0);
+ event_type = vlib_process_get_events (vm, &event_data);
+ }
+ else
+ {
+ vlib_process_wait_for_event (vm);
+ event_type = vlib_process_get_events (vm, &event_data);
+ }
+
+ switch (event_type)
+ {
+ case ~0:
+ break;
+ case NAT64_CLEANER_RESCHEDULE:
+ break;
+ default:
+ clib_warning ("unknown event %u", event_type);
+ break;
+ }
+
for (i = 0; i < vec_len (worker_vms); i++)
{
worker_vm = worker_vms[i];
@@ -1201,8 +1237,6 @@
return 0;
}
-static vlib_node_registration_t nat64_expire_walk_node;
-
/* *INDENT-OFF* */
VLIB_REGISTER_NODE (nat64_expire_walk_node, static) = {
.function = nat64_expire_walk_fn,
diff --git a/src/plugins/nat/nat64.h b/src/plugins/nat/nat64.h
index d9d3d76..e2334a5 100644
--- a/src/plugins/nat/nat64.h
+++ b/src/plugins/nat/nat64.h
@@ -39,6 +39,11 @@
#undef _
} nat64_tcp_ses_state_t;
+enum
+{
+ NAT64_CLEANER_RESCHEDULE = 1,
+} nat64_cleaner_process_event_e;
+
typedef struct
{
ip6_address_t prefix;
@@ -99,6 +104,11 @@
u32 tcp_est_timeout;
u32 tcp_incoming_syn_timeout;
+ /* Total count of interfaces enabled */
+ u32 total_enabled_count;
+ /* The process node which orcherstrates the cleanup */
+ u32 nat64_expire_walk_node_index;
+
ip4_main_t *ip4_main;
snat_main_t *sm;
} nat64_main_t;