s->in2out.fib_index);
snat_free_outside_address_and_port
- (sm, &s->out2in, s->outside_address_index);
+ (sm, thread_index, &s->out2in, s->outside_address_index);
}
s->outside_address_index = ~0;
s->out2in.port,
s->in2out.fib_index);
- snat_free_outside_address_and_port (sm, &s->out2in,
+ snat_free_outside_address_and_port (sm, thread_index, &s->out2in,
s->outside_address_index);
/* Remove in2out, out2in keys */
{
snat_address_t * ap;
snat_interface_t *i;
+ vlib_thread_main_t *tm = vlib_get_thread_main ();
if (vrf_id != ~0)
sm->vrf_mode = 1;
else
ap->fib_index = ~0;
#define _(N, i, n, s) \
- clib_bitmap_alloc (ap->busy_##n##_port_bitmap, 65535);
+ clib_bitmap_alloc (ap->busy_##n##_port_bitmap, 65535); \
+ ap->busy_##n##_ports = 0; \
+ vec_validate_init_empty (ap->busy_##n##_ports_per_thread, tm->n_vlib_mains - 1, 0);
foreach_snat_protocol
#undef _
return VNET_API_ERROR_INVALID_VALUE; \
clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, e_port, 1); \
if (e_port > 1024) \
- a->busy_##n##_ports++; \
+ { \
+ a->busy_##n##_ports++; \
+ a->busy_##n##_ports_per_thread[e_port / sm->port_per_thread]++; \
+ } \
break;
foreach_snat_protocol
#undef _
case SNAT_PROTOCOL_##N: \
clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, e_port, 0); \
if (e_port > 1024) \
- a->busy_##n##_ports--; \
+ { \
+ a->busy_##n##_ports--; \
+ a->busy_##n##_ports_per_thread[e_port / sm->port_per_thread]--; \
+ } \
break;
foreach_snat_protocol
#undef _
return VNET_API_ERROR_INVALID_VALUE; \
clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, e_port, 1); \
if (e_port > 1024) \
- a->busy_##n##_ports++; \
+ { \
+ a->busy_##n##_ports++; \
+ a->busy_##n##_ports_per_thread[e_port / sm->port_per_thread]++; \
+ } \
break;
foreach_snat_protocol
#undef _
case SNAT_PROTOCOL_##N: \
clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, e_port, 0); \
if (e_port > 1024) \
- a->busy_##n##_ports--; \
+ { \
+ a->busy_##n##_ports--; \
+ a->busy_##n##_ports_per_thread[e_port / sm->port_per_thread]--; \
+ } \
break;
foreach_snat_protocol
#undef _
VLIB_INIT_FUNCTION (snat_init);
void snat_free_outside_address_and_port (snat_main_t * sm,
+ u32 thread_index,
snat_session_key_t * k,
u32 address_index)
{
clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, \
port_host_byte_order, 0); \
a->busy_##n##_ports--; \
+ a->busy_##n##_ports_per_thread[thread_index]--; \
break;
foreach_snat_protocol
#undef _
{
#define _(N, j, n, s) \
case SNAT_PROTOCOL_##N: \
- if (a->busy_##n##_ports < (sm->port_per_thread * sm->num_snat_thread)) \
+ if (a->busy_##n##_ports_per_thread[thread_index] < sm->port_per_thread) \
{ \
while (1) \
{ \
if (clib_bitmap_get_no_check (a->busy_##n##_port_bitmap, portnum)) \
continue; \
clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, portnum, 1); \
+ a->busy_##n##_ports_per_thread[thread_index]++; \
a->busy_##n##_ports++; \
k->addr = a->addr; \
k->port = clib_host_to_net_u16(portnum); \