summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2024-03-09 15:51:50 -0800
committerFlorin Coras <florin.coras@gmail.com>2024-03-10 00:13:01 +0000
commit236534136d5824bd29fd9842262b05e48111b2b2 (patch)
tree9d59d6e95ab00ea41cffcef201fea5cc32956a85 /src
parent91bfe5b658b14acdbecf7a0f357bfafaf1124c66 (diff)
session: use no for ports in transport port allocator
Type: improvement Change-Id: Ia1d8aaa3c51938cfa15dd09102471f52ebe67a3d Signed-off-by: Florin Coras <fcoras@cisco.com>
Diffstat (limited to 'src')
-rw-r--r--src/vnet/session/transport.c22
-rw-r--r--src/vnet/tcp/tcp.c2
-rw-r--r--src/vnet/udp/udp.c4
3 files changed, 17 insertions, 11 deletions
diff --git a/src/vnet/session/transport.c b/src/vnet/session/transport.c
index e6eb9d7ee3b..1c2a9261d3c 100644
--- a/src/vnet/session/transport.c
+++ b/src/vnet/session/transport.c
@@ -528,11 +528,13 @@ transport_release_local_endpoint (u8 proto, ip46_address_t *lcl_ip, u16 port)
u32 lepi;
lepi = transport_endpoint_lookup (&tm->local_endpoints_table, proto, lcl_ip,
- clib_net_to_host_u16 (port));
+ port);
if (lepi == ENDPOINT_INVALID_INDEX)
return -1;
- lep = pool_elt_at_index (tm->local_endpoints, lepi);
+ /* First worker may be cleaning up ports so avoid touching free bitmap */
+ lep = &tm->local_endpoints[lepi];
+ ASSERT (lep->refcnt >= 1);
/* Local endpoint no longer in use, program cleanup */
if (!clib_atomic_sub_fetch (&lep->refcnt, 1))
@@ -583,7 +585,7 @@ transport_share_local_endpoint (u8 proto, ip46_address_t * lcl_ip, u16 port)
* used to allocate and free ports. So, pool has only one writer and
* potentially many readers. Listeners are allocated with barrier */
lepi = transport_endpoint_lookup (&tm->local_endpoints_table, proto, lcl_ip,
- clib_net_to_host_u16 (port));
+ port);
if (lepi != ENDPOINT_INVALID_INDEX)
{
lep = pool_elt_at_index (tm->local_endpoints, lepi);
@@ -594,6 +596,8 @@ transport_share_local_endpoint (u8 proto, ip46_address_t * lcl_ip, u16 port)
/**
* Allocate local port and add if successful add entry to local endpoint
* table to mark the pair as used.
+ *
+ * @return port in net order or -1 if port cannot be allocated
*/
int
transport_alloc_local_port (u8 proto, ip46_address_t *lcl_addr,
@@ -619,7 +623,10 @@ transport_alloc_local_port (u8 proto, ip46_address_t *lcl_addr,
{
port = random_u32 (&tm->port_allocator_seed) & PORT_MASK;
if (PREDICT_TRUE (port >= min && port < max))
- break;
+ {
+ port = clib_host_to_net_u16 (port);
+ break;
+ }
}
if (!transport_endpoint_mark_used (proto, lcl_addr, port))
@@ -733,10 +740,9 @@ transport_alloc_local_endpoint (u8 proto, transport_endpoint_cfg_t * rmt_cfg,
}
else
{
- port = clib_net_to_host_u16 (rmt_cfg->peer.port);
- *lcl_port = port;
+ *lcl_port = rmt_cfg->peer.port;
- if (!transport_endpoint_mark_used (proto, lcl_addr, port))
+ if (!transport_endpoint_mark_used (proto, lcl_addr, rmt_cfg->peer.port))
return 0;
/* IP:port pair already in use, check if 6-tuple available */
@@ -746,7 +752,7 @@ transport_alloc_local_endpoint (u8 proto, transport_endpoint_cfg_t * rmt_cfg,
return SESSION_E_PORTINUSE;
/* 6-tuple is available so increment lcl endpoint refcount */
- transport_share_local_endpoint (proto, lcl_addr, port);
+ transport_share_local_endpoint (proto, lcl_addr, rmt_cfg->peer.port);
return 0;
}
diff --git a/src/vnet/tcp/tcp.c b/src/vnet/tcp/tcp.c
index a6eb35a28b9..c00685dba0c 100644
--- a/src/vnet/tcp/tcp.c
+++ b/src/vnet/tcp/tcp.c
@@ -831,7 +831,7 @@ tcp_session_open (transport_endpoint_cfg_t * rmt)
ip_copy (&tc->c_rmt_ip, &rmt->ip, rmt->is_ip4);
ip_copy (&tc->c_lcl_ip, &lcl_addr, rmt->is_ip4);
tc->c_rmt_port = rmt->port;
- tc->c_lcl_port = clib_host_to_net_u16 (lcl_port);
+ tc->c_lcl_port = lcl_port;
tc->c_is_ip4 = rmt->is_ip4;
tc->c_proto = TRANSPORT_PROTO_TCP;
tc->c_fib_index = rmt->fib_index;
diff --git a/src/vnet/udp/udp.c b/src/vnet/udp/udp.c
index 0a0247a5ef4..669dd03b34e 100644
--- a/src/vnet/udp/udp.c
+++ b/src/vnet/udp/udp.c
@@ -420,7 +420,7 @@ udp_open_connection (transport_endpoint_cfg_t * rmt)
lcl_port);
lcl_port =
transport_alloc_local_port (TRANSPORT_PROTO_UDP, &lcl_addr, rmt);
- if (lcl_port < 1)
+ if ((int) lcl_port < 1)
return SESSION_E_PORTINUSE;
}
}
@@ -432,7 +432,7 @@ udp_open_connection (transport_endpoint_cfg_t * rmt)
ip_copy (&uc->c_rmt_ip, &rmt->ip, rmt->is_ip4);
ip_copy (&uc->c_lcl_ip, &lcl_addr, rmt->is_ip4);
uc->c_rmt_port = rmt->port;
- uc->c_lcl_port = clib_host_to_net_u16 (lcl_port);
+ uc->c_lcl_port = lcl_port;
uc->c_is_ip4 = rmt->is_ip4;
uc->c_proto = TRANSPORT_PROTO_UDP;
uc->c_fib_index = rmt->fib_index;