diff options
author | shubing guo <guo.shubing@zte.com.cn> | 2018-08-13 17:16:46 +0800 |
---|---|---|
committer | Ole Trøan <otroan@employees.org> | 2018-08-15 07:10:30 +0000 |
commit | 762a4938900abeedd42676ab2582fcceabdc07fa (patch) | |
tree | 58fd9b0bfed3fb02c13584def97f26c45f823f7b | |
parent | 38bc30802f10e550f03f8741e7427217208252a7 (diff) |
VPP-1387:foreach outside address vector to find correct index when free outside address and port
Change-Id: Ie5452350a8ebe2c1b62085fcab50dbc0138d3ae2
Signed-off-by: shubing guo <guo.shubing@zte.com.cn>
-rw-r--r-- | src/plugins/nat/dslite_in2out.c | 3 | ||||
-rwxr-xr-x | src/plugins/nat/nat.c | 31 | ||||
-rw-r--r-- | src/plugins/nat/nat.h | 3 |
3 files changed, 16 insertions, 21 deletions
diff --git a/src/plugins/nat/dslite_in2out.c b/src/plugins/nat/dslite_in2out.c index 991d6eda775..bf51ca23051 100644 --- a/src/plugins/nat/dslite_in2out.c +++ b/src/plugins/nat/dslite_in2out.c @@ -103,8 +103,7 @@ slow_path (dslite_main_t * dm, dslite_session_key_t * in2out_key, clib_bihash_add_del_8_8 (&dm->per_thread_data[thread_index].out2in, &out2in_kv, 0); snat_free_outside_address_and_port (dm->addr_pool, thread_index, - &s->out2in, - s->outside_address_index); + &s->out2in); s->outside_address_index = ~0; if (snat_alloc_outside_address_and_port diff --git a/src/plugins/nat/nat.c b/src/plugins/nat/nat.c index b37ea22e1ed..ff3b2ed8a5f 100755 --- a/src/plugins/nat/nat.c +++ b/src/plugins/nat/nat.c @@ -190,8 +190,6 @@ nat_free_session_data (snat_main_t * sm, snat_session_t * s, u32 thread_index) clib_bihash_kv_8_8_t kv; nat_ed_ses_key_t ed_key; clib_bihash_kv_16_8_t ed_kv; - int i; - snat_address_t *a; snat_main_per_thread_data_t *tsm = vec_elt_at_index (sm->per_thread_data, thread_index); @@ -271,18 +269,11 @@ nat_free_session_data (snat_main_t * sm, snat_session_t * s, u32 thread_index) /* Twice NAT address and port for external host */ if (is_twice_nat_session (s)) { - for (i = 0; i < vec_len (sm->twice_nat_addresses); i++) - { - key.protocol = s->in2out.protocol; - key.port = s->ext_host_nat_port; - a = sm->twice_nat_addresses + i; - if (a->addr.as_u32 == s->ext_host_nat_addr.as_u32) - { - snat_free_outside_address_and_port (sm->twice_nat_addresses, - thread_index, &key, i); - break; - } - } + key.protocol = s->in2out.protocol; + key.port = s->ext_host_nat_port; + key.addr.as_u32 = s->ext_host_nat_addr.as_u32; + snat_free_outside_address_and_port (sm->twice_nat_addresses, + thread_index, &key); } if (snat_is_session_static (s)) @@ -290,7 +281,7 @@ nat_free_session_data (snat_main_t * sm, snat_session_t * s, u32 thread_index) if (s->outside_address_index != ~0) snat_free_outside_address_and_port (sm->addresses, thread_index, - &s->out2in, s->outside_address_index); + &s->out2in); } snat_user_t * @@ -2094,12 +2085,18 @@ VLIB_INIT_FUNCTION (snat_init); void snat_free_outside_address_and_port (snat_address_t * addresses, u32 thread_index, - snat_session_key_t * k, - u32 address_index) + snat_session_key_t * k) { snat_address_t *a; + u32 address_index; u16 port_host_byte_order = clib_net_to_host_u16 (k->port); + for (address_index = 0; address_index < vec_len (addresses); address_index++) + { + if (addresses[address_index].addr.as_u32 == k->addr.as_u32) + break; + } + ASSERT (address_index < vec_len (addresses)); a = addresses + address_index; diff --git a/src/plugins/nat/nat.h b/src/plugins/nat/nat.h index 0d51109175f..6ff6cd891ec 100644 --- a/src/plugins/nat/nat.h +++ b/src/plugins/nat/nat.h @@ -451,8 +451,7 @@ extern vlib_node_registration_t nat44_ed_out2in_worker_handoff_node; void snat_free_outside_address_and_port (snat_address_t * addresses, u32 thread_index, - snat_session_key_t * k, - u32 address_index); + snat_session_key_t * k); int snat_alloc_outside_address_and_port (snat_address_t * addresses, u32 fib_index, |