From 4acb6d6e34e78553a80edd49512b7925e8b86cb3 Mon Sep 17 00:00:00 2001 From: Thomas Ries Date: Sun, 20 Mar 2005 10:35:59 +0000 Subject: [PATCH] - when allocating local ports for RTP relaying, do this in a round-robin way over the available port range. --- ChangeLog | 2 ++ src/rtpproxy_relay.c | 21 +++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8c1aab3..370323e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 0.5.11 ====== + 20-Mar-2005: - when allocating local ports for RTP relaying, do this + in a round-robin way over the available port range. 1-Mar-2005: - working on running siproxd in front of a routing device and NOT on the firewall itself. 19-Feb-2005: - more work on new libosip API diff --git a/src/rtpproxy_relay.c b/src/rtpproxy_relay.c index 8316ac0..cd6cc78 100644 --- a/src/rtpproxy_relay.c +++ b/src/rtpproxy_relay.c @@ -389,7 +389,9 @@ int rtp_relay_start_fwd (osip_call_id_t *callid, char *client_id, int media_stream_no, struct in_addr local_ipaddr, int *local_port, struct in_addr remote_ipaddr, int remote_port) { - int i, j; + static int prev_used_port = 0; + int num_ports; + int i2, i, j; int sock, port; int freeidx; int sts=STS_SUCCESS; @@ -526,7 +528,20 @@ int rtp_relay_start_fwd (osip_call_id_t *callid, char *client_id, /* find a local port number to use and bind to it */ sock=0; port=0; - for (i=configuration.rtp_port_low; i<=configuration.rtp_port_high; i+=2) { +// for (i=configuration.rtp_port_low; i<=configuration.rtp_port_high; i+=2) { + +DEBUGC(DBCLASS_RTP,"*****a prev_used_port=%i",prev_used_port); + if ((prev_used_port < configuration.rtp_port_low) || + (prev_used_port > configuration.rtp_port_high)) { + prev_used_port = configuration.rtp_port_high; + } + + num_ports = configuration.rtp_port_high - configuration.rtp_port_low + 1; + for (i2 = (prev_used_port - configuration.rtp_port_low + 1); + i2 < (num_ports + prev_used_port - configuration.rtp_port_low + 1); + i2 += 2) { + i = (i2%num_ports) + configuration.rtp_port_low; +DEBUGC(DBCLASS_RTP,"***** i=%i, i2=%i",i,i2); for (j=0; j