From 3d6156fed8be0c1e3ffe081be16f82be5be603fd Mon Sep 17 00:00:00 2001 From: Florin Coras Date: Mon, 30 Jan 2023 11:18:36 -0800 Subject: session: consolidate port alloc logic Move port allocation logic from transports into generic transport layer. Type: improvement Signed-off-by: Florin Coras Change-Id: I55a21f185d00f5e118c36bcc4a6ffba2cbda885e --- src/vnet/udp/udp.c | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) (limited to 'src/vnet/udp/udp.c') 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 (); -- cgit 1.2.3-korg