Do not send RTP to port 0
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
diff --git a/include/osmocom/trau/osmo_ortp.h b/include/osmocom/trau/osmo_ortp.h
index c02cca8..9512759 100644
--- a/include/osmocom/trau/osmo_ortp.h
+++ b/include/osmocom/trau/osmo_ortp.h
@@ -29,6 +29,7 @@
/*! \brief Flag to indicate the socket is in polling-only mode */
#define OSMO_RTP_F_POLL 0x0001
+#define OSMO_RTP_F_DISABLED 0x0002
/*! \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 @@
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 @@
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_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 @@
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)