aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorshubing guo <guo.shubing@zte.com.cn>2018-08-13 17:16:46 +0800
committerDamjan Marion <dmarion@me.com>2018-09-02 11:37:03 +0000
commit86f6d3e291197e136339a21f5d505fb25e996796 (patch)
tree151c6c5dfaee62dc4e1f10180280871f6648e788 /src
parent6b4b20318b4c96a79a79e5057c4ba77813050d7c (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> (cherry picked from commit 762a4938900abeedd42676ab2582fcceabdc07fa)
Diffstat (limited to 'src')
-rw-r--r--src/plugins/nat/dslite_in2out.c3
-rwxr-xr-xsrc/plugins/nat/nat.c31
-rw-r--r--src/plugins/nat/nat.h3
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 618711f5271..cc712b3b436 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 *
@@ -2083,12 +2074,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 97bbec21360..decfb0d8801 100644
--- a/src/plugins/nat/nat.h
+++ b/src/plugins/nat/nat.h
@@ -449,8 +449,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,