diff mbox

[1/3] Do not send RTP to port 0

Message ID 1461926375-18893-1-git-send-email-msuraev@sysmocom.de
State New
Headers show

Commit Message

Max April 29, 2016, 10:39 a.m. UTC
From: Max <msuraev@sysmocom.de>

Previously it was possible to send RTP data to port 0. This produce
multiple errors during the beginning of RTP transmission.

To address this OSMO_RTP_F_DISABLED flag was introduced. It's set by
default for all new RTP sessions. It can be manually unset after the
call to osmo_rtp_socket_create(). When the flag is set it prevents
transmission and reception of RTP frames for the session. The flag is
unset automatically in osmo_rtp_socket_connect() when session is bound
to non-zero remote port.

Fixes: OS#1662
---
 include/osmocom/trau/osmo_ortp.h |  1 +
 src/trau/osmo_ortp.c             | 14 ++++++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)

Comments

Holger Freyther April 29, 2016, 11:58 a.m. UTC | #1
> On 29 Apr 2016, at 12:39, msuraev@sysmocom.de wrote:
> 
> From: Max <msuraev@sysmocom.de>
> 

did you test:

* sysmoBTS with old oRTP after your change? What was the result?

holger
Max April 29, 2016, 12:37 p.m. UTC | #2
Yes, sure. The voice was working as expected.

On 04/29/2016 01:58 PM, Holger Freyther wrote:
>> On 29 Apr 2016, at 12:39, msuraev@sysmocom.de wrote:
>>
>> From: Max <msuraev@sysmocom.de>
>>
> did you test:
>
> * sysmoBTS with old oRTP after your change? What was the result?
>
> holger
>
diff mbox

Patch

diff --git a/include/osmocom/trau/osmo_ortp.h b/include/osmocom/trau/osmo_ortp.h
index c02cca8..2ca9cfc 100644
--- a/include/osmocom/trau/osmo_ortp.h
+++ b/include/osmocom/trau/osmo_ortp.h
@@ -29,6 +29,7 @@  enum osmo_rtp_param {
 
 /*! \brief Flag to indicate the socket is in polling-only mode */
 #define OSMO_RTP_F_POLL		0x0001
+#define OSMO_RTP_F_DISABLED	2
 
 /*! \brief A structure representing one RTP socket */
 struct osmo_rtp_socket {
diff --git a/src/trau/osmo_ortp.c b/src/trau/osmo_ortp.c
index 65ec269..22c5856 100644
--- a/src/trau/osmo_ortp.c
+++ b/src/trau/osmo_ortp.c
@@ -149,6 +149,8 @@  static void ortp_sig_cb_ts(RtpSession *rs, void *data)
 int osmo_rtp_socket_poll(struct osmo_rtp_socket *rs)
 {
 	mblk_t *mblk;
+	if (rs->flags & OSMO_RTP_F_DISABLED)
+		return 0;
 
 	mblk = rtp_session_recvm_with_ts(rs->sess, rs->rx_user_ts);
 	if (mblk) {
@@ -313,7 +315,7 @@  struct osmo_rtp_socket *osmo_rtp_socket_create(void *talloc_ctx, unsigned int fl
 	if (!rs)
 		return NULL;
 
-	rs->flags = flags;
+	rs->flags = OSMO_RTP_F_DISABLED | flags;
 	rs->sess = rtp_session_new(RTP_SESSION_SENDRECV);
 	if (!rs->sess) {
 		talloc_free(rs);
@@ -382,11 +384,16 @@  int osmo_rtp_socket_bind(struct osmo_rtp_socket *rs, const char *ip, int port)
 int osmo_rtp_socket_connect(struct osmo_rtp_socket *rs, const char *ip, uint16_t port)
 {
 	int rc;
-
+	if (!port) {
+		LOGP(DLMIB, LOGL_INFO, "osmo_rtp_socket_connect() refused to "
+		     "set remote %s:%u\n", ip, port);
+		return 0;
+	}
 	/* enable the use of connect() so later getsockname() will
 	 * actually return the IP address that was chosen for the local
 	 * sid of the connection */
 	rtp_session_set_connected_mode(rs->sess, 1);
+	rs->flags &= ~OSMO_RTP_F_DISABLED;
 
 	rc = rtp_session_set_remote_addr(rs->sess, ip, port);
 	if (rc < 0)
@@ -411,6 +418,9 @@  int osmo_rtp_send_frame(struct osmo_rtp_socket *rs, const uint8_t *payload,
 	mblk_t *mblk;
 	int rc;
 
+	if (rs->flags & OSMO_RTP_F_DISABLED)
+		return 0;
+
 	mblk = rtp_session_create_packet(rs->sess, RTP_FIXED_HEADER_SIZE,
 					 payload, payload_len);
 	if (!mblk)