Change in osmo-mgw[master]: mgcp_network: refactor MGCP_DUMMY_LOAD

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
Thu May 20 12:25:27 UTC 2021


dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-mgw/+/24315 )


Change subject: mgcp_network: refactor MGCP_DUMMY_LOAD
......................................................................

mgcp_network: refactor MGCP_DUMMY_LOAD

The constant MGCP_DUMMY_LOAD is used ambigously. Sometimes it is used as
initalizer for an array, sometimes it is used as a single byte. Also the
name is not very expressive. Lets refactor this.

Change-Id: I21d96cefeeb647958bfa1e22a0ea030884746fad
---
M include/osmocom/mgcp/mgcp_network.h
M src/libosmo-mgcp/mgcp_network.c
M src/libosmo-mgcp/mgcp_osmux.c
M tests/mgcp/mgcp_test.c
4 files changed, 17 insertions(+), 13 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/15/24315/1

diff --git a/include/osmocom/mgcp/mgcp_network.h b/include/osmocom/mgcp/mgcp_network.h
index 6e1e52c..cd56fcc 100644
--- a/include/osmocom/mgcp/mgcp_network.h
+++ b/include/osmocom/mgcp/mgcp_network.h
@@ -7,7 +7,16 @@
 
 #include <osmocom/mgcp/mgcp.h>
 
-#define MGCP_DUMMY_LOAD 0x23
+/* The following constant defines a an RTP dummy payload that is used for
+ * "UDP Hole Punching" (NAT) */
+static const char rtp_dummy_payload[] = { 0x23 };
+
+/* Check if the data in a given message buffer matches the rtp dummy payload
+ * defined above */
+#define mgcp_is_rtp_dummy_payload(msg) \
+	(msgb_length(msg) == sizeof(rtp_dummy_payload) && \
+	memcmp(msgb_data(msg), rtp_dummy_payload, sizeof(rtp_dummy_payload)) == 0)
+
 #define RTP_BUF_SIZE	4096
 
 struct mgcp_rtp_stream_state {
diff --git a/src/libosmo-mgcp/mgcp_network.c b/src/libosmo-mgcp/mgcp_network.c
index e03c100..162fbc0 100644
--- a/src/libosmo-mgcp/mgcp_network.c
+++ b/src/libosmo-mgcp/mgcp_network.c
@@ -205,7 +205,6 @@
  *  \returns bytes sent, -1 on error. */
 int mgcp_send_dummy(struct mgcp_endpoint *endp, struct mgcp_conn_rtp *conn)
 {
-	static char buf[] = { MGCP_DUMMY_LOAD };
 	int rc;
 	int was_rtcp = 0;
 
@@ -216,7 +215,7 @@
 		 mgcp_conn_dump(conn->conn));
 
 	rc = mgcp_udp_send(conn->end.rtp.fd, &conn->end.addr,
-			   conn->end.rtp_port, buf, 1);
+			   conn->end.rtp_port, rtp_dummy_payload, sizeof(rtp_dummy_payload));
 
 	if (rc == -1)
 		goto failed;
@@ -226,7 +225,7 @@
 
 	was_rtcp = 1;
 	rc = mgcp_udp_send(conn->end.rtcp.fd, &conn->end.addr,
-			   conn->end.rtcp_port, buf, 1);
+			   conn->end.rtcp_port, rtp_dummy_payload, sizeof(rtp_dummy_payload));
 
 	if (rc >= 0)
 		return rc;
@@ -1398,11 +1397,6 @@
 	mgcp_cleanup_rtp_bridge_cb(endp, conn);
 }
 
-static bool is_dummy_msg(enum rtp_proto proto, struct msgb *msg)
-{
-	return msgb_length(msg) == 1 && msgb_data(msg)[0] == MGCP_DUMMY_LOAD;
-}
-
 /* Handle incoming RTP data from NET */
 static int rtp_data_net(struct osmo_fd *fd, unsigned int what)
 {
@@ -1453,7 +1447,7 @@
 		goto out;
 	}
 
-	if (is_dummy_msg(proto, msg)) {
+	if (mgcp_is_rtp_dummy_payload(msg)) {
 		LOG_CONN_RTP(conn_src, LOGL_DEBUG, "rx dummy packet (dropped)\n");
 		rc = 0;
 		goto out;
diff --git a/src/libosmo-mgcp/mgcp_osmux.c b/src/libosmo-mgcp/mgcp_osmux.c
index bb85735..8f0a906 100644
--- a/src/libosmo-mgcp/mgcp_osmux.c
+++ b/src/libosmo-mgcp/mgcp_osmux.c
@@ -375,7 +375,7 @@
 	}
 
 	/* not any further processing dummy messages */
-	if (msg->data[0] == MGCP_DUMMY_LOAD)
+	if (mgcp_is_rtp_dummy_payload(msg))
 		return osmux_handle_dummy(cfg, &addr, msg);
 
 	rem = msg->len;
diff --git a/tests/mgcp/mgcp_test.c b/tests/mgcp/mgcp_test.c
index 620b0d1..ae43eb5 100644
--- a/tests/mgcp/mgcp_test.c
+++ b/tests/mgcp/mgcp_test.c
@@ -30,6 +30,7 @@
 #include <osmocom/mgcp/mgcp_trunk.h>
 #include <osmocom/mgcp/mgcp_sdp.h>
 #include <osmocom/mgcp/mgcp_codec.h>
+#include <osmocom/mgcp/mgcp_network.h>
 
 #include <osmocom/core/application.h>
 #include <osmocom/core/talloc.h>
@@ -616,7 +617,6 @@
 	return MGCP_POLICY_CONT;
 }
 
-#define MGCP_DUMMY_LOAD 0x23
 static int dummy_packets = 0;
 /* override and forward */
 ssize_t sendto(int sockfd, const void *buf, size_t len, int flags,
@@ -626,7 +626,8 @@
 	    htonl(((struct sockaddr_in *)dest_addr)->sin_addr.s_addr);
 	int dest_port = htons(((struct sockaddr_in *)dest_addr)->sin_port);
 
-	if (len == 1 && ((const char *)buf)[0] == MGCP_DUMMY_LOAD) {
+	if (len == sizeof(rtp_dummy_payload)
+	    && memcmp(buf, rtp_dummy_payload, sizeof(rtp_dummy_payload)) == 0) {
 		fprintf(stderr,
 			"Dummy packet to 0x%08x:%d, msg length %zu\n%s\n\n",
 			dest_host, dest_port, len, osmo_hexdump(buf, len));

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

Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-Change-Id: I21d96cefeeb647958bfa1e22a0ea030884746fad
Gerrit-Change-Number: 24315
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210520/d319a067/attachment.htm>


More information about the gerrit-log mailing list