summaryrefslogtreecommitdiffstats
path: root/src/vnet/udp
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2023-01-30 11:18:36 -0800
committerDave Barach <vpp@barachs.net>2023-02-28 22:50:36 +0000
commit3d6156fed8be0c1e3ffe081be16f82be5be603fd (patch)
tree78a29e173f1611f2e5a630c93f3d53d67466d440 /src/vnet/udp
parent045a6ae99db25d3ce8a83d1f291715ff033a7f11 (diff)
session: consolidate port alloc logic
Move port allocation logic from transports into generic transport layer. Type: improvement Signed-off-by: Florin Coras <fcoras@cisco.com> Change-Id: I55a21f185d00f5e118c36bcc4a6ffba2cbda885e
Diffstat (limited to 'src/vnet/udp')
-rw-r--r--src/vnet/udp/udp.c34
1 files changed, 10 insertions, 24 deletions
diff --git a/src/vnet/udp/udp.c b/src/vnet/udp/udp.c
index 4553701dced..7147fa32657 100644
--- a/src/vnet/udp/udp.c
+++ b/src/vnet/udp/udp.c
@@ -362,44 +362,30 @@ udp_open_connection (transport_endpoint_cfg_t * rmt)
rv = transport_alloc_local_endpoint (TRANSPORT_PROTO_UDP, rmt, &lcl_addr,
&lcl_port);
if (rv)
- {
- if (rv != SESSION_E_PORTINUSE)
- return rv;
-
- if (udp_connection_port_used_extern (lcl_port, rmt->is_ip4))
- return SESSION_E_PORTINUSE;
-
- /* If port in use, check if 5-tuple is also in use */
- if (session_lookup_connection (rmt->fib_index, &lcl_addr, &rmt->ip,
- lcl_port, rmt->port, TRANSPORT_PROTO_UDP,
- rmt->is_ip4))
- return SESSION_E_PORTINUSE;
-
- /* 5-tuple is available so increase lcl endpoint refcount and proceed
- * with connection allocation */
- transport_share_local_endpoint (TRANSPORT_PROTO_UDP, &lcl_addr,
- lcl_port);
- goto conn_alloc;
- }
+ return rv;
if (udp_is_valid_dst_port (lcl_port, rmt->is_ip4))
{
/* If specific source port was requested abort */
if (rmt->peer.port)
- return SESSION_E_PORTINUSE;
+ {
+ transport_release_local_endpoint (TRANSPORT_PROTO_UDP, &lcl_addr,
+ lcl_port);
+ return SESSION_E_PORTINUSE;
+ }
/* Try to find a port that's not used */
while (udp_is_valid_dst_port (lcl_port, rmt->is_ip4))
{
- lcl_port = transport_alloc_local_port (TRANSPORT_PROTO_UDP,
- &lcl_addr);
+ transport_release_local_endpoint (TRANSPORT_PROTO_UDP, &lcl_addr,
+ lcl_port);
+ lcl_port =
+ transport_alloc_local_port (TRANSPORT_PROTO_UDP, &lcl_addr, rmt);
if (lcl_port < 1)
return SESSION_E_PORTINUSE;
}
}
-conn_alloc:
-
/* We don't poll main thread if we have workers */
thread_index = transport_cl_thread ();