Change in osmo-bts[master]: rtp: make port range configurable, assign correct port numbers

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Fri May 25 17:33:12 UTC 2018


Harald Welte has submitted this change and it was merged. ( https://gerrit.osmocom.org/9261 )

Change subject: rtp: make port range configurable, assign correct port numbers
......................................................................

rtp: make port range configurable, assign correct port numbers

The current implementation does not allow the user to specify a port
range in which the BTS is allowed to allocate a local RTP port. Also
the ports the BTS picks do not match the policy described in RFC3550.
An RTP Port must be at an even port number and the matching RTCP
port must be at the following (odd) port number. The BTS currently
picks random port numbers for both.

- Add a VTY command to specify a port range in which the BTS may
  assign local ports.

- Pick ports as described in RFC3550.

Change-Id: Id75f1dfaf898ed8750d28b1c4840e188f4cfdc87
Related: OS#2825 OS#2635
---
M include/osmo-bts/gsm_data_shared.h
M src/common/bts.c
M src/common/rsl.c
M src/common/vty.c
4 files changed, 72 insertions(+), 2 deletions(-)

Approvals:
  Jenkins Builder: Verified
  Harald Welte: Looks good to me, approved



diff --git a/include/osmo-bts/gsm_data_shared.h b/include/osmo-bts/gsm_data_shared.h
index 81cac3e..f4fb766 100644
--- a/include/osmo-bts/gsm_data_shared.h
+++ b/include/osmo-bts/gsm_data_shared.h
@@ -688,6 +688,11 @@
 	struct llist_head oml_queue;
 	unsigned int rtp_jitter_buf_ms;
 	bool rtp_jitter_adaptive;
+
+	uint16_t rtp_port_range_start;
+	uint16_t rtp_port_range_end;
+	uint16_t rtp_port_range_next;
+
 	struct {
 		uint8_t ciphers;	/* flags A5/1==0x1, A5/2==0x2, A5/3==0x4 */
 	} support;
diff --git a/src/common/bts.c b/src/common/bts.c
index 74630cc..54e5480 100644
--- a/src/common/bts.c
+++ b/src/common/bts.c
@@ -135,6 +135,9 @@
 	bts->paging_state = paging_init(bts, 200, 0);
 	bts->ul_power_target = -75;	/* dBm default */
 	bts->rtp_jitter_adaptive = false;
+	bts->rtp_port_range_start = 16384;
+	bts->rtp_port_range_end = 17407;
+	bts->rtp_port_range_next = bts->rtp_port_range_start;
 
 	/* configurable via OML */
 	bts->load.ccch.load_ind_period = 112;
diff --git a/src/common/rsl.c b/src/common/rsl.c
index 5dd2c59..b5d0c2b 100644
--- a/src/common/rsl.c
+++ b/src/common/rsl.c
@@ -1787,6 +1787,29 @@
 	return hostbuf;
 }
 
+static int bind_rtp(struct gsm_bts *bts, struct osmo_rtp_socket *rs, const char *ip)
+{
+	int rc;
+	unsigned int i;
+	unsigned int tries;
+
+	tries = (bts->rtp_port_range_end - bts->rtp_port_range_start) / 2;
+	for (i = 0; i < tries; i++) {
+
+		if (bts->rtp_port_range_next >= bts->rtp_port_range_end)
+			bts->rtp_port_range_next = bts->rtp_port_range_start;
+
+		rc = osmo_rtp_socket_bind(rs, ip, bts->rtp_port_range_next);
+
+		bts->rtp_port_range_next += 2;
+
+		if (rc == 0)
+			return 0;
+	}
+
+	return -1;
+}
+
 static int rsl_rx_ipac_XXcx(struct msgb *msg)
 {
 	struct abis_rsl_dchan_hdr *dch = msgb_l2(msg);
@@ -1907,8 +1930,7 @@
 			 * back to the BSC in the CRCX_ACK */
 			ipstr = get_rsl_local_ip(lchan->ts->trx);
 		}
-		rc = osmo_rtp_socket_bind(lchan->abis_ip.rtp_socket,
-					  ipstr, -1);
+		rc = bind_rtp(bts, lchan->abis_ip.rtp_socket, ipstr);
 		if (rc < 0) {
 			LOGP(DRTP, LOGL_ERROR,
 			     "%s IPAC Failed to bind RTP/RTCP sockets\n",
diff --git a/src/common/vty.c b/src/common/vty.c
index 2716a7a..6061335 100644
--- a/src/common/vty.c
+++ b/src/common/vty.c
@@ -262,6 +262,8 @@
 	if (bts->rtp_jitter_adaptive)
 		vty_out(vty, " adaptive");
 	vty_out(vty, "%s", VTY_NEWLINE);
+	vty_out(vty, " rtp port-range %u %u%s", bts->rtp_port_range_start,
+		bts->rtp_port_range_end, VTY_NEWLINE);
 	vty_out(vty, " paging queue-size %u%s", paging_get_queue_max(bts->paging_state),
 		VTY_NEWLINE);
 	vty_out(vty, " paging lifetime %u%s", paging_get_lifetime(bts->paging_state),
@@ -486,6 +488,43 @@
 	return CMD_SUCCESS;
 }
 
+DEFUN(cfg_bts_rtp_port_range,
+	cfg_bts_rtp_port_range_cmd,
+	"rtp port-range <1-65534> <1-65534>",
+      RTP_STR "Range of local ports to use for RTP/RTCP traffic\n")
+{
+	struct gsm_bts *bts = vty->index;
+	unsigned int start;
+	unsigned int end;
+
+	start = atoi(argv[0]);
+	end = atoi(argv[1]);
+
+	if (end < start) {
+		vty_out(vty, "range end port (%u) must be greater than the range start port (%u)!%s",
+			end, start, VTY_NEWLINE);
+		return CMD_WARNING;
+	}
+
+	if (start & 1) {
+		vty_out(vty, "range must begin at an even port number! (%u not even)%s",
+			start, VTY_NEWLINE);
+		return CMD_WARNING;
+	}
+
+	if ((end & 1) == 0) {
+		vty_out(vty, "range must end at an odd port number! (%u not odd)%s",
+			end, VTY_NEWLINE);
+		return CMD_WARNING;
+	}
+
+	bts->rtp_port_range_start = start;
+	bts->rtp_port_range_end = end;
+	bts->rtp_port_range_next = bts->rtp_port_range_start;
+
+	return CMD_SUCCESS;
+}
+
 #define PAG_STR "Paging related parameters\n"
 
 DEFUN(cfg_bts_paging_queue_size,
@@ -1554,6 +1593,7 @@
 	install_element(BTS_NODE, &cfg_bts_oml_ip_cmd);
 	install_element(BTS_NODE, &cfg_bts_rtp_bind_ip_cmd);
 	install_element(BTS_NODE, &cfg_bts_rtp_jitbuf_cmd);
+	install_element(BTS_NODE, &cfg_bts_rtp_port_range_cmd);
 	install_element(BTS_NODE, &cfg_bts_band_cmd);
 	install_element(BTS_NODE, &cfg_description_cmd);
 	install_element(BTS_NODE, &cfg_no_description_cmd);

-- 
To view, visit https://gerrit.osmocom.org/9261
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Id75f1dfaf898ed8750d28b1c4840e188f4cfdc87
Gerrit-Change-Number: 9261
Gerrit-PatchSet: 3
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20180525/9ca573ac/attachment.htm>


More information about the gerrit-log mailing list