diff options
author | Matus Fabian <matfabia@cisco.com> | 2018-02-05 02:57:47 -0800 |
---|---|---|
committer | Dave Wallace <dwallacelf@gmail.com> | 2018-02-05 16:20:53 +0000 |
commit | e71eb5922a293eca36dbd323970741daaca3c5c7 (patch) | |
tree | 70686bc33aaa50f0c0673e06e5e795ececc1a375 | |
parent | 1403fcd7ec2da72334f5df20f0b7e6dbba24d856 (diff) |
NAT64: Run nat64-expire-worker-walk only when NAT64 is configured (VPP-1162)
Change-Id: Ic5e8d74bf5ac84cce5661de44778c89541c67636
Signed-off-by: Matus Fabian <matfabia@cisco.com>
-rw-r--r-- | src/plugins/nat/nat64.c | 42 | ||||
-rw-r--r-- | src/plugins/nat/nat64.h | 10 |
2 files changed, 48 insertions, 4 deletions
diff --git a/src/plugins/nat/nat64.c b/src/plugins/nat/nat64.c index 571e0717826..0b7536f21a7 100644 --- a/src/plugins/nat/nat64.c +++ b/src/plugins/nat/nat64.c @@ -232,6 +232,8 @@ nat64_init (vlib_main_t * vm) 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 @@ nat64_add_del_interface (u32 sw_if_index, u8 is_inside, u8 is_add) 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 @@ nat64_add_del_interface (u32 sw_if_index, u8 is_inside, u8 is_add) ~NAT_INTERFACE_FLAG_IS_OUTSIDE; else pool_put (nm->interfaces, interface); + + nm->total_enabled_count--; } if (!is_inside) @@ -1164,6 +1174,8 @@ VLIB_REGISTER_NODE (nat64_expire_worker_walk_node, static) = { }; /* *INDENT-ON* */ +static vlib_node_registration_t nat64_expire_walk_node; + /** * @brief Centralized process to drive per worker expire walk. */ @@ -1171,8 +1183,12 @@ static uword 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 @@ nat64_expire_walk_fn (vlib_main_t * vm, vlib_node_runtime_t * rt, 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 @@ nat64_expire_walk_fn (vlib_main_t * vm, vlib_node_runtime_t * rt, 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 d9d3d768e70..e2334a5ac6f 100644 --- a/src/plugins/nat/nat64.h +++ b/src/plugins/nat/nat64.h @@ -39,6 +39,11 @@ typedef enum #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 @@ typedef struct 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; |