[Pkg-voip-commits] [janus] 144/163: Added configurable port range for RTP/RTCP ports in the SIP plugin

Jonas Smedegaard dr at jones.dk
Sat Oct 28 01:22:24 UTC 2017


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag debian/0.2.5-1
in repository janus.

commit 450c62e70b51adae55bc9f180dbe2d88d607cabc
Author: Lorenzo Miniero <lminiero at gmail.com>
Date:   Fri Oct 20 15:14:01 2017 +0200

    Added configurable port range for RTP/RTCP ports in the SIP plugin
---
 conf/janus.plugin.sip.cfg.sample |  3 +++
 janus.c                          |  2 +-
 plugins/janus_sip.c              | 28 ++++++++++++++++++++++++++--
 3 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/conf/janus.plugin.sip.cfg.sample b/conf/janus.plugin.sip.cfg.sample
index f7c76a6..04e806d 100644
--- a/conf/janus.plugin.sip.cfg.sample
+++ b/conf/janus.plugin.sip.cfg.sample
@@ -18,5 +18,8 @@ behind_nat = no
 ; Expiration time for registrations
 register_ttl = 3600
 
+; Range of ports to use for RTP/RTCP (default=10000-60000)
+rtp_port_range = 20000-40000
+
 ; Whether events should be sent to event handlers (default is yes)
 ;events = no
diff --git a/janus.c b/janus.c
index f85ba4f..1484082 100644
--- a/janus.c
+++ b/janus.c
@@ -3719,7 +3719,7 @@ gint main(int argc, char *argv[])
 			*maxport = '-';
 		}
 		if(rtp_min_port > rtp_max_port) {
-			int temp_port = rtp_min_port;
+			uint16_t temp_port = rtp_min_port;
 			rtp_min_port = rtp_max_port;
 			rtp_max_port = temp_port;
 		}
diff --git a/plugins/janus_sip.c b/plugins/janus_sip.c
index a5e64f2..a43f893 100644
--- a/plugins/janus_sip.c
+++ b/plugins/janus_sip.c
@@ -202,6 +202,8 @@ static gboolean behind_nat = FALSE;
 static char *user_agent;
 #define JANUS_DEFAULT_REGISTER_TTL	3600
 static int register_ttl = JANUS_DEFAULT_REGISTER_TTL;
+static uint16_t rtp_range_min = 10000;
+static uint16_t rtp_range_max = 60000;
 
 static GThread *handler_thread;
 static GThread *watchdog;
@@ -830,6 +832,28 @@ int janus_sip_init(janus_callbacks *callback, const char *config_path) {
 			user_agent = g_strdup("Janus WebRTC Gateway SIP Plugin "JANUS_SIP_VERSION_STRING);
 		JANUS_LOG(LOG_VERB, "SIP User-Agent set to %s\n", user_agent);
 
+		item = janus_config_get_item_drilldown(config, "general", "rtp_port_range");
+		if(item && item->value) {
+			/* Split in min and max port */
+			char *maxport = strrchr(item->value, '-');
+			if(maxport != NULL) {
+				*maxport = '\0';
+				maxport++;
+				rtp_range_min = atoi(item->value);
+				rtp_range_max = atoi(maxport);
+				maxport--;
+				*maxport = '-';
+			}
+			if(rtp_range_min > rtp_range_max) {
+				uint16_t temp_port = rtp_range_min;
+				rtp_range_min = rtp_range_max;
+				rtp_range_max = temp_port;
+			}
+			if(rtp_range_max == 0)
+				rtp_range_max = 65535;
+			JANUS_LOG(LOG_VERB, "SIP RTP/RTCP port range: %u -- %u\n", rtp_range_min, rtp_range_max);
+		}
+
 		item = janus_config_get_item_drilldown(config, "general", "events");
 		if(item != NULL && item->value != NULL)
 			notify_events = janus_is_true(item->value);
@@ -3559,7 +3583,7 @@ static int janus_sip_allocate_local_ports(janus_sip_session *session) {
 				JANUS_LOG(LOG_ERR, "Error creating audio sockets...\n");
 				return -1;
 			}
-			int rtp_port = g_random_int_range(10000, 60000);	/* FIXME Should this be configurable? */
+			int rtp_port = g_random_int_range(rtp_range_min, rtp_range_max);
 			if(rtp_port % 2)
 				rtp_port++;	/* Pick an even port for RTP */
 			audio_rtp_address.sin_family = AF_INET;
@@ -3608,7 +3632,7 @@ static int janus_sip_allocate_local_ports(janus_sip_session *session) {
 				JANUS_LOG(LOG_ERR, "Error creating video sockets...\n");
 				return -1;
 			}
-			int rtp_port = g_random_int_range(10000, 60000);	/* FIXME Should this be configurable? */
+			int rtp_port = g_random_int_range(rtp_range_min, rtp_range_max);
 			if(rtp_port % 2)
 				rtp_port++;	/* Pick an even port for RTP */
 			video_rtp_address.sin_family = AF_INET;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-voip/janus.git



More information about the Pkg-voip-commits mailing list