snat: fix port allocation
Change-Id: Id6aeb4d19476934dfaa354562aa1703650bd037f Signed-off-by: Matus Fabian <matfabia@cisco.com>
This commit is contained in:

committed by
Damjan Marion

parent
f5984bde04
commit
07ea7615ff
@ -221,7 +221,7 @@ void snat_add_address (snat_main_t *sm, ip4_address_t *addr)
|
|||||||
|
|
||||||
vec_add2 (sm->addresses, ap, 1);
|
vec_add2 (sm->addresses, ap, 1);
|
||||||
ap->addr = *addr;
|
ap->addr = *addr;
|
||||||
|
clib_bitmap_alloc (ap->busy_port_bitmap, 65535);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int is_snat_address_used_in_static_mapping (snat_main_t *sm,
|
static int is_snat_address_used_in_static_mapping (snat_main_t *sm,
|
||||||
@ -399,10 +399,9 @@ int snat_add_static_mapping(ip4_address_t l_addr, ip4_address_t e_addr,
|
|||||||
{
|
{
|
||||||
a = sm->addresses + i;
|
a = sm->addresses + i;
|
||||||
/* External port must be unused */
|
/* External port must be unused */
|
||||||
if (clib_bitmap_get (a->busy_port_bitmap, e_port))
|
if (clib_bitmap_get_no_check (a->busy_port_bitmap, e_port))
|
||||||
return VNET_API_ERROR_INVALID_VALUE;
|
return VNET_API_ERROR_INVALID_VALUE;
|
||||||
a->busy_port_bitmap = clib_bitmap_set (a->busy_port_bitmap,
|
clib_bitmap_set_no_check (a->busy_port_bitmap, e_port, 1);
|
||||||
e_port, 1);
|
|
||||||
if (e_port > 1024)
|
if (e_port > 1024)
|
||||||
a->busy_ports++;
|
a->busy_ports++;
|
||||||
|
|
||||||
@ -483,8 +482,7 @@ int snat_add_static_mapping(ip4_address_t l_addr, ip4_address_t e_addr,
|
|||||||
if (sm->addresses[i].addr.as_u32 == e_addr.as_u32)
|
if (sm->addresses[i].addr.as_u32 == e_addr.as_u32)
|
||||||
{
|
{
|
||||||
a = sm->addresses + i;
|
a = sm->addresses + i;
|
||||||
a->busy_port_bitmap = clib_bitmap_set (a->busy_port_bitmap,
|
clib_bitmap_set_no_check (a->busy_port_bitmap, e_port, 0);
|
||||||
e_port, 0);
|
|
||||||
a->busy_ports--;
|
a->busy_ports--;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -1223,10 +1221,10 @@ void snat_free_outside_address_and_port (snat_main_t * sm,
|
|||||||
|
|
||||||
a = sm->addresses + address_index;
|
a = sm->addresses + address_index;
|
||||||
|
|
||||||
ASSERT (clib_bitmap_get (a->busy_port_bitmap, port_host_byte_order) == 1);
|
ASSERT (clib_bitmap_get_no_check (a->busy_port_bitmap,
|
||||||
|
port_host_byte_order) == 1);
|
||||||
|
|
||||||
a->busy_port_bitmap = clib_bitmap_set (a->busy_port_bitmap,
|
clib_bitmap_set_no_check (a->busy_port_bitmap, port_host_byte_order, 0);
|
||||||
port_host_byte_order, 0);
|
|
||||||
a->busy_ports--;
|
a->busy_ports--;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1311,10 +1309,9 @@ int snat_alloc_outside_address_and_port (snat_main_t * sm,
|
|||||||
portnum &= 0xFFFF;
|
portnum &= 0xFFFF;
|
||||||
if (portnum < 1024)
|
if (portnum < 1024)
|
||||||
continue;
|
continue;
|
||||||
if (clib_bitmap_get (a->busy_port_bitmap, portnum))
|
if (clib_bitmap_get_no_check (a->busy_port_bitmap, portnum))
|
||||||
continue;
|
continue;
|
||||||
a->busy_port_bitmap = clib_bitmap_set (a->busy_port_bitmap,
|
clib_bitmap_set_no_check (a->busy_port_bitmap, portnum, 1);
|
||||||
portnum, 1);
|
|
||||||
a->busy_ports++;
|
a->busy_ports++;
|
||||||
/* Caller sets protocol and fib index */
|
/* Caller sets protocol and fib index */
|
||||||
k->addr = a->addr;
|
k->addr = a->addr;
|
||||||
@ -1822,6 +1819,7 @@ show_snat_command_fn (vlib_main_t * vm,
|
|||||||
snat_user_t * u;
|
snat_user_t * u;
|
||||||
snat_static_mapping_t *m;
|
snat_static_mapping_t *m;
|
||||||
snat_interface_t *i;
|
snat_interface_t *i;
|
||||||
|
snat_address_t * ap;
|
||||||
vnet_main_t *vnm = vnet_get_main();
|
vnet_main_t *vnm = vnet_get_main();
|
||||||
snat_main_per_thread_data_t *tsm;
|
snat_main_per_thread_data_t *tsm;
|
||||||
u32 users_num = 0, sessions_num = 0, *worker;
|
u32 users_num = 0, sessions_num = 0, *worker;
|
||||||
@ -1853,6 +1851,17 @@ show_snat_command_fn (vlib_main_t * vm,
|
|||||||
vnet_get_sw_interface (vnm, i->sw_if_index),
|
vnet_get_sw_interface (vnm, i->sw_if_index),
|
||||||
i->is_inside ? "in" : "out");
|
i->is_inside ? "in" : "out");
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
vec_foreach (ap, sm->addresses)
|
||||||
|
{
|
||||||
|
u8 * s = format (0, "");
|
||||||
|
vlib_cli_output (vm, "%U", format_ip4_address, &ap->addr);
|
||||||
|
clib_bitmap_foreach (j, ap->busy_port_bitmap,
|
||||||
|
({
|
||||||
|
s = format (s, " %d", j);
|
||||||
|
}));
|
||||||
|
vlib_cli_output (vm, " %d busy ports:%s", ap->busy_ports, s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sm->num_workers > 1)
|
if (sm->num_workers > 1)
|
||||||
|
Reference in New Issue
Block a user