From ca280a1a84c5638c7c4a23520766e7b42f4a0434 Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Tue, 6 Jul 2021 18:15:35 +0200 Subject: [PATCH] mgw: rx CRCX: Avoid sending dummy rtp if remote address not provided The following sequence of events was seen frequently in a osmo-mgw instance running on the field with heavy traffic: """ endpoint:rtpbridge/1@mgw CRCX: creating new connection ... mgcp_network.c:236 endpoint:rtpbridge/1@mgw CI:1C8CCFA9 Failed to send dummy RTP packet. """ Allegedly, that happens because at CRCX time the remote address may still not be known, hence we end up trying to send a dummy rtp packet to, for instance, host 0.0.0.0 port 0, which will of course fail. Let's avoid sending it if the address is not yet known. Similary, same issue could be seen during MDCX, since at MDCX we don't necessarily need to have a valid addr+port (there could be several MDCX and only last one set it). Finally, the keepalive timer also needs the check, since it iterates over all connections, and it could be that some is still not fully configured. Related: SYS#5498 Change-Id: I8ceafda691146823b12232b4a804b4ce74acbdc8 --- include/osmocom/mgcp/mgcp_network.h | 2 ++ src/libosmo-mgcp/mgcp_network.c | 5 +++++ src/libosmo-mgcp/mgcp_protocol.c | 14 +++++++++----- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/include/osmocom/mgcp/mgcp_network.h b/include/osmocom/mgcp/mgcp_network.h index 1ed00e495..75b342d54 100644 --- a/include/osmocom/mgcp/mgcp_network.h +++ b/include/osmocom/mgcp/mgcp_network.h @@ -132,6 +132,8 @@ struct mgcp_rtp_end { char local_addr[INET6_ADDRSTRLEN]; }; +bool mgcp_rtp_end_remote_addr_available(const struct mgcp_rtp_end *rtp_end); + struct mgcp_rtp_tap { /* is this tap active (1) or not (0) */ int enabled; diff --git a/src/libosmo-mgcp/mgcp_network.c b/src/libosmo-mgcp/mgcp_network.c index 5b3ea51c3..d18c7cb10 100644 --- a/src/libosmo-mgcp/mgcp_network.c +++ b/src/libosmo-mgcp/mgcp_network.c @@ -88,6 +88,11 @@ static bool addr_is_any(const struct osmo_sockaddr *osa) } } +bool mgcp_rtp_end_remote_addr_available(const struct mgcp_rtp_end *rtp_end) +{ + return rtp_end->rtp_port && !addr_is_any(&rtp_end->addr); +} + /*! Determine the local rtp bind IP-address. * \param[out] addr caller provided memory to store the resulting IP-Address. * \param[in] endp mgcp endpoint, that holds a copy of the VTY parameters. diff --git a/src/libosmo-mgcp/mgcp_protocol.c b/src/libosmo-mgcp/mgcp_protocol.c index 8d6f6f502..4fb93b0b0 100644 --- a/src/libosmo-mgcp/mgcp_protocol.c +++ b/src/libosmo-mgcp/mgcp_protocol.c @@ -990,8 +990,9 @@ mgcp_header_done: /* Send dummy packet, see also comments in mgcp_keepalive_timer_cb() */ OSMO_ASSERT(trunk->keepalive_interval >= MGCP_KEEPALIVE_ONCE); - if (conn->conn->mode & MGCP_CONN_RECV_ONLY - && trunk->keepalive_interval != MGCP_KEEPALIVE_NEVER) + if (conn->conn->mode & MGCP_CONN_RECV_ONLY && + mgcp_rtp_end_remote_addr_available(&conn->end) && + trunk->keepalive_interval != MGCP_KEEPALIVE_NEVER) send_dummy(endp, conn); LOGPCONN(_conn, DLMGCP, LOGL_NOTICE, @@ -1232,8 +1233,9 @@ mgcp_header_done: /* Send dummy packet, see also comments in mgcp_keepalive_timer_cb() */ OSMO_ASSERT(endp->trunk->keepalive_interval >= MGCP_KEEPALIVE_ONCE); - if (conn->conn->mode & MGCP_CONN_RECV_ONLY - && endp->trunk->keepalive_interval != MGCP_KEEPALIVE_NEVER) + if (conn->conn->mode & MGCP_CONN_RECV_ONLY && + mgcp_rtp_end_remote_addr_available(&conn->end) && + endp->trunk->keepalive_interval != MGCP_KEEPALIVE_NEVER) send_dummy(endp, conn); rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_MDCX_SUCCESS)); @@ -1495,7 +1497,9 @@ static void mgcp_keepalive_timer_cb(void *_trunk) for (i = 1; i < trunk->number_endpoints; ++i) { struct mgcp_endpoint *endp = trunk->endpoints[i]; llist_for_each_entry(conn, &endp->conns, entry) { - if (conn->mode == MGCP_CONN_RECV_ONLY) + if (conn->type == MGCP_CONN_TYPE_RTP && + conn->mode == MGCP_CONN_RECV_ONLY && + mgcp_rtp_end_remote_addr_available(&conn->u.rtp.end)) send_dummy(endp, &conn->u.rtp); } }