From: Max <[email protected]>

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(-)

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)
-- 
2.8.1

Reply via email to