Change in osmo-mgw[master]: mgcp_network: fix implicit address loopback

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/.

dexter gerrit-no-reply at lists.osmocom.org
Mon May 10 12:50:35 UTC 2021


dexter has submitted this change. ( https://gerrit.osmocom.org/c/osmo-mgw/+/24174 )

Change subject: mgcp_network: fix implicit address loopback
......................................................................

mgcp_network: fix implicit address loopback

A call agent may send a CRCX to create a connection in LOOPBACK mode but
without specifiying the destination address. In those cases the MGW
should deduct the destination address from the first incoming RTP
packet.

Unfortunately this is currently blocked by an OSMO_ASSERT that checks the
current sa_familiy against the sa_family from the incoming packet. This
makes no sense since the current sa_family is still uninitalized, which
is expected and not an error since the code that follows will initalize
it.

It also makes sense not to access the osmo_sockaddr struct members
individually but rather copy the address as a wohle.

Since the event only happens once and since it is also somewhat special
it makes sense to log the event as well.

Change-Id: I2dbd6f62170a7f62e5287d04a4ee6716b8786c26
Related: OS#5123
---
M src/libosmo-mgcp/mgcp_network.c
1 file changed, 14 insertions(+), 6 deletions(-)

Approvals:
  laforge: Looks good to me, but someone else must approve
  pespin: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/libosmo-mgcp/mgcp_network.c b/src/libosmo-mgcp/mgcp_network.c
index 6a30165..abe01c9 100644
--- a/src/libosmo-mgcp/mgcp_network.c
+++ b/src/libosmo-mgcp/mgcp_network.c
@@ -1251,6 +1251,7 @@
 	struct mgcp_conn *conn = conn_src->conn;
 	struct mgcp_conn *conn_dst;
 	struct osmo_sockaddr *from_addr = mc->from_addr;
+	char ipbuf[INET6_ADDRSTRLEN];
 
 	/*! NOTE: This callback function implements the endpoint specific
 	 *  dispatch behaviour of an rtp bridge/proxy endpoint. It is assumed
@@ -1269,19 +1270,22 @@
 		 * address data from the UDP packet header to patch the
 		 * outgoing address in connection on the fly */
 		if (conn->u.rtp.end.rtp_port == 0) {
-			OSMO_ASSERT(conn->u.rtp.end.addr.u.sa.sa_family == from_addr->u.sa.sa_family);
+			memcpy(&conn->u.rtp.end.addr, from_addr,
+			       sizeof(conn->u.rtp.end.addr));
 			switch (from_addr->u.sa.sa_family) {
 			case AF_INET:
-				conn->u.rtp.end.addr.u.sin.sin_addr = from_addr->u.sin.sin_addr;
 				conn->u.rtp.end.rtp_port = from_addr->u.sin.sin_port;
 				break;
 			case AF_INET6:
-				conn->u.rtp.end.addr.u.sin6.sin6_addr = from_addr->u.sin6.sin6_addr;
 				conn->u.rtp.end.rtp_port = from_addr->u.sin6.sin6_port;
 				break;
 			default:
 				OSMO_ASSERT(false);
 			}
+			LOG_CONN_RTP(conn_src, LOGL_NOTICE,
+				     "loopback mode: implicitly using source address (%s:%u) as destination address\n",
+				     osmo_sockaddr_ntop(&from_addr->u.sa, ipbuf),
+				     conn->u.rtp.end.rtp_port);
 		}
 		return mgcp_send_rtp(conn_src, msg);
 	}
@@ -1331,6 +1335,7 @@
 	struct mgcp_conn_rtp *conn_src = mc->conn_src;
 	struct mgcp_conn *conn = conn_src->conn;
 	struct osmo_sockaddr *from_addr = mc->from_addr;
+	char ipbuf[INET6_ADDRSTRLEN];
 
 	/* Check if the connection is in loopback mode, if yes, just send the
 	 * incoming data back to the origin */
@@ -1340,19 +1345,22 @@
 		 * address data from the UDP packet header to patch the
 		 * outgoing address in connection on the fly */
 		if (conn->u.rtp.end.rtp_port == 0) {
-			OSMO_ASSERT(conn->u.rtp.end.addr.u.sa.sa_family == from_addr->u.sa.sa_family);
+			memcpy(&conn->u.rtp.end.addr, from_addr,
+			       sizeof(conn->u.rtp.end.addr));
 			switch (from_addr->u.sa.sa_family) {
 			case AF_INET:
-				conn->u.rtp.end.addr.u.sin.sin_addr = from_addr->u.sin.sin_addr;
 				conn->u.rtp.end.rtp_port = from_addr->u.sin.sin_port;
 				break;
 			case AF_INET6:
-				conn->u.rtp.end.addr.u.sin6.sin6_addr = from_addr->u.sin6.sin6_addr;
 				conn->u.rtp.end.rtp_port = from_addr->u.sin6.sin6_port;
 				break;
 			default:
 				OSMO_ASSERT(false);
 			}
+			LOG_CONN_RTP(conn_src, LOGL_NOTICE,
+				     "loopback mode: implicitly using source address (%s:%u) as destination address\n",
+				     osmo_sockaddr_ntop(&from_addr->u.sa, ipbuf),
+				     conn->u.rtp.end.rtp_port);
 		}
 		return mgcp_send_rtp(conn_src, msg);
 	}

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-mgw/+/24174
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-Change-Id: I2dbd6f62170a7f62e5287d04a4ee6716b8786c26
Gerrit-Change-Number: 24174
Gerrit-PatchSet: 2
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: dexter <pmaier at sysmocom.de>
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-Reviewer: neels <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210510/d0c80a22/attachment.htm>


More information about the gerrit-log mailing list