summaryrefslogtreecommitdiffstats
path: root/src/plugins/nat/nat.c
diff options
context:
space:
mode:
authorshubing guo <guo.shubing@zte.com.cn>2018-08-13 17:16:46 +0800
committerOle Trøan <otroan@employees.org>2018-08-15 07:10:30 +0000
commit762a4938900abeedd42676ab2582fcceabdc07fa (patch)
tree58fd9b0bfed3fb02c13584def97f26c45f823f7b /src/plugins/nat/nat.c
parent38bc30802f10e550f03f8741e7427217208252a7 (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>
Diffstat (limited to 'src/plugins/nat/nat.c')
-rwxr-xr-xsrc/plugins/nat/nat.c31
1 files changed, 14 insertions, 17 deletions
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;