summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordongjuan <dong.juan1@zte.com.cn>2018-09-04 17:40:53 +0800
committerDamjan Marion <dmarion@me.com>2018-09-12 10:10:09 +0000
commitf0030614c361fdd9e967094e6dfb12dcbe90a810 (patch)
tree47205a0529ed2dcdaffafb13cc49d6bec671b752
parenta742315b787db0b7d30b6048bb2a583fa2265f15 (diff)
nat: fix busy ports of each thread
which can create dead loop in nat_alloc_addr_and_port_default function Change-Id: I468c25ce0f0a0b3f881de564623dea208b2ca700 Signed-off-by: dongjuan <dong.juan1@zte.com.cn> (cherry picked from commit 58f50f1bb64e962e5628e2c1867e07f238036c7b)
-rwxr-xr-xsrc/plugins/nat/nat.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/plugins/nat/nat.c b/src/plugins/nat/nat.c
index cc712b3b436..77360d7390b 100755
--- a/src/plugins/nat/nat.c
+++ b/src/plugins/nat/nat.c
@@ -760,6 +760,17 @@ snat_add_static_mapping_when_resolved (snat_main_t * sm,
rp->is_add = is_add;
rp->tag = vec_dup (tag);
}
+
+static u32 get_thread_idx_by_port(u16 e_port)
+{
+ snat_main_t * sm = &snat_main;
+ u32 thread_idx = sm->num_workers;
+ if (sm->num_workers > 1)
+ {
+ thread_idx = sm->first_worker_index + sm->workers[(e_port - 1024) / sm->port_per_thread];
+ }
+ return thread_idx;
+}
/**
* @brief Add static mapping.
@@ -947,7 +958,7 @@ int snat_add_static_mapping(ip4_address_t l_addr, ip4_address_t e_addr,
if (e_port > 1024) \
{ \
a->busy_##n##_ports++; \
- a->busy_##n##_ports_per_thread[(e_port - 1024) / sm->port_per_thread]++; \
+ a->busy_##n##_ports_per_thread[get_thread_idx_by_port(e_port)]++; \
} \
break;
foreach_snat_protocol
@@ -1092,7 +1103,7 @@ int snat_add_static_mapping(ip4_address_t l_addr, ip4_address_t e_addr,
if (e_port > 1024) \
{ \
a->busy_##n##_ports--; \
- a->busy_##n##_ports_per_thread[(e_port - 1024) / sm->port_per_thread]--; \
+ a->busy_##n##_ports_per_thread[get_thread_idx_by_port(e_port)]--; \
} \
break;
foreach_snat_protocol
@@ -1274,7 +1285,7 @@ int nat44_add_del_lb_static_mapping (ip4_address_t e_addr, u16 e_port,
if (e_port > 1024) \
{ \
a->busy_##n##_ports++; \
- a->busy_##n##_ports_per_thread[(e_port - 1024) / sm->port_per_thread]++; \
+ a->busy_##n##_ports_per_thread[get_thread_idx_by_port(e_port)]++; \
} \
break;
foreach_snat_protocol
@@ -1371,7 +1382,7 @@ int nat44_add_del_lb_static_mapping (ip4_address_t e_addr, u16 e_port,
if (e_port > 1024) \
{ \
a->busy_##n##_ports--; \
- a->busy_##n##_ports_per_thread[(e_port - 1024) / sm->port_per_thread]--; \
+ a->busy_##n##_ports_per_thread[get_thread_idx_by_port(e_port)]--; \
} \
break;
foreach_snat_protocol