summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorMatus Fabian <matfabia@cisco.com>2016-12-15 05:30:37 -0800
committerDamjan Marion <dmarion.lists@gmail.com>2016-12-19 21:40:26 +0000
commit07ea7615ff319802356e4667dbbb74b0dfe1a02f (patch)
treef67f7352dfa388a90a3baffd37cf05a053b1417b /plugins
parentf5984bde0462f21402ba5c2c3ad04e44440402eb (diff)
snat: fix port allocation
Change-Id: Id6aeb4d19476934dfaa354562aa1703650bd037f Signed-off-by: Matus Fabian <matfabia@cisco.com>
Diffstat (limited to 'plugins')
-rw-r--r--plugins/snat-plugin/snat/snat.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/plugins/snat-plugin/snat/snat.c b/plugins/snat-plugin/snat/snat.c
index d0bcabb73d1..ad350d6a128 100644
--- a/plugins/snat-plugin/snat/snat.c
+++ b/plugins/snat-plugin/snat/snat.c
@@ -221,7 +221,7 @@ void snat_add_address (snat_main_t *sm, ip4_address_t *addr)
vec_add2 (sm->addresses, ap, 1);
ap->addr = *addr;
-
+ clib_bitmap_alloc (ap->busy_port_bitmap, 65535);
}
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;
/* 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;
- a->busy_port_bitmap = clib_bitmap_set (a->busy_port_bitmap,
- e_port, 1);
+ clib_bitmap_set_no_check (a->busy_port_bitmap, e_port, 1);
if (e_port > 1024)
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)
{
a = sm->addresses + i;
- a->busy_port_bitmap = clib_bitmap_set (a->busy_port_bitmap,
- e_port, 0);
+ clib_bitmap_set_no_check (a->busy_port_bitmap, e_port, 0);
a->busy_ports--;
break;
@@ -1223,10 +1221,10 @@ void snat_free_outside_address_and_port (snat_main_t * sm,
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,
- port_host_byte_order, 0);
+ clib_bitmap_set_no_check (a->busy_port_bitmap, port_host_byte_order, 0);
a->busy_ports--;
}
@@ -1311,10 +1309,9 @@ int snat_alloc_outside_address_and_port (snat_main_t * sm,
portnum &= 0xFFFF;
if (portnum < 1024)
continue;
- if (clib_bitmap_get (a->busy_port_bitmap, portnum))
+ if (clib_bitmap_get_no_check (a->busy_port_bitmap, portnum))
continue;
- a->busy_port_bitmap = clib_bitmap_set (a->busy_port_bitmap,
- portnum, 1);
+ clib_bitmap_set_no_check (a->busy_port_bitmap, portnum, 1);
a->busy_ports++;
/* Caller sets protocol and fib index */
k->addr = a->addr;
@@ -1822,6 +1819,7 @@ show_snat_command_fn (vlib_main_t * vm,
snat_user_t * u;
snat_static_mapping_t *m;
snat_interface_t *i;
+ snat_address_t * ap;
vnet_main_t *vnm = vnet_get_main();
snat_main_per_thread_data_t *tsm;
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),
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)