From 052f16da56bc290069428e7eda38d6be94b3c7b3 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 24 Jul 2025 11:33:51 -0400 Subject: [PATCH] MT#55283 allow allocation of out-of-pool ports Different instances of rtpengine may be configured with different port ranges. If HA requests usage of a port not part of our pool, allow it. Change-Id: Ib4ace6c4facac35ea44948720fa46bcbdaf441d3 --- daemon/media_socket.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/daemon/media_socket.c b/daemon/media_socket.c index 1ea8c5f9b..2aab970e3 100644 --- a/daemon/media_socket.c +++ b/daemon/media_socket.c @@ -1167,9 +1167,6 @@ void append_thread_lpr_to_glob_lpr(void) { } static struct socket_port_link get_one_port_link(unsigned int port, struct intf_spec *spec) { - if (!port_is_in_range(&spec->port_pool, port)) - return (struct socket_port_link) {}; - __auto_type links = get_port_links(&spec->port_pool, port); return (struct socket_port_link) { .links = links, .pp = &spec->port_pool, .socket = { .fd = -1 }}; } @@ -1217,7 +1214,14 @@ static bool open_port_link_sockets(socket_port_q *out, struct intf_spec *spec, c struct socket_port_link get_specific_port(unsigned int port, struct intf_spec *spec, const str *label) { - ilog(LOG_DEBUG, "A specific port value is requested: '%d'", port); + if (!port_is_in_range(&spec->port_pool, port)) { + ilog(LOG_DEBUG, "A specific out-of-pool port is requested: '%d'", port); + struct socket_port_link spl = {0}; + add_socket(&spl.socket, port, spec, label); + return spl; + } + + ilog(LOG_DEBUG, "A specific in-pool port is requested: '%d'", port); __auto_type spl = get_one_port_link(port, spec); if (spl.links.length) { if (add_socket(&spl.socket, port, spec, label)) @@ -1307,7 +1311,8 @@ new_cycle: port = GPOINTER_TO_UINT(spl.links.head->data); /* RTP */ /* ports for RTP must be even, if there is an additional port for RTCP */ - if (num_ports > 1 && (port & 1)) { + // also bail if end port is out of range of the pool + if ((num_ports > 1 && (port & 1)) || port + num_ports - 1 > spec->port_pool.max) { /* return port for RTP back and try again */ release_reserved_port(pp, &spl.links, port); continue;