[Pkg-voip-commits] [janus] 140/282: Added configurable port range for RTP/RTCP ports in the SIPre plugin

Jonas Smedegaard dr at jones.dk
Wed Dec 20 21:53:35 UTC 2017


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

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

commit f954df1f942847e10e625e5286a1f796f8090569
Author: Lorenzo Miniero <lminiero at gmail.com>
Date:   Fri Oct 20 15:38:36 2017 +0200

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

diff --git a/conf/janus.plugin.sipre.cfg.sample b/conf/janus.plugin.sipre.cfg.sample
index 81fcd1c..f13e753 100644
--- a/conf/janus.plugin.sipre.cfg.sample
+++ b/conf/janus.plugin.sipre.cfg.sample
@@ -9,5 +9,8 @@
 ; 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/plugins/janus_sipre.c b/plugins/janus_sipre.c
index 7707672..d1c6acb 100644
--- a/plugins/janus_sipre.c
+++ b/plugins/janus_sipre.c
@@ -200,6 +200,8 @@ static gboolean behind_nat = FALSE;
 static char *user_agent;
 #define JANUS_DEFAULT_REGISTER_TTL	3600
 static uint32_t 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;
@@ -859,6 +861,28 @@ int janus_sipre_init(janus_callbacks *callback, const char *config_path) {
 		}
 		JANUS_LOG(LOG_VERB, "SIPre 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, "SIPre 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);
@@ -2754,7 +2778,7 @@ static int janus_sipre_allocate_local_ports(janus_sipre_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;
@@ -2803,7 +2827,7 @@ static int janus_sipre_allocate_local_ports(janus_sipre_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