Fix regression in detection of legacy dummy packets

A commit refactored this code around one year ago, which broke osmux
detection of dummy messages. This commit partially reverts the earlier
commit and rearranges the existing code to make it more robust.

Fixes: b3d14eb552cba1c58970acf90dae1bee291d5293
Change-Id: Iedf085932c45af5d13e04e56a4cd1082de81d869
diff --git a/src/libosmo-mgcp/mgcp_osmux.c b/src/libosmo-mgcp/mgcp_osmux.c
index aae9579..23e4dad 100644
--- a/src/libosmo-mgcp/mgcp_osmux.c
+++ b/src/libosmo-mgcp/mgcp_osmux.c
@@ -363,30 +363,14 @@
 	}
 }
 
-static int osmux_legacy_dummy_parse_cid(const struct osmo_sockaddr *rem_addr, struct msgb *msg,
-					uint8_t *osmux_cid)
-{
-	if (msg->len < 1 + sizeof(*osmux_cid)) {
-		LOGP(DOSMUX, LOGL_ERROR,
-		     "Discarding truncated Osmux dummy load: %s\n", osmo_hexdump(msg->data, msg->len));
-		return -1;
-	}
-
-	/* extract the osmux CID from the dummy message */
-	memcpy(osmux_cid, &msg->data[1], sizeof(*osmux_cid));
-	return 0;
-}
-
-/* This is called from the bsc-nat */
-static int osmux_handle_dummy(struct mgcp_trunk *trunk, const struct osmo_sockaddr *rem_addr,
+/* Old versions of osmux used to send dummy packets [0x23 0x<CID>] to punch the
+ * hole in the NAT. Let's handle them speficially. */
+static int osmux_handle_legacy_dummy(struct mgcp_trunk *trunk, const struct osmo_sockaddr *rem_addr,
 			      struct msgb *msg)
 {
-	uint8_t osmux_cid;
+	uint8_t osmux_cid = msg->data[1];
 	struct mgcp_conn_rtp *conn;
 
-	if (osmux_legacy_dummy_parse_cid(rem_addr, msg, &osmux_cid) < 0)
-		goto out;
-
 	conn = osmux_conn_lookup(trunk, osmux_cid, rem_addr);
 	if (!conn) {
 		LOGP(DOSMUX, LOGL_DEBUG,
@@ -426,9 +410,9 @@
 		goto out;
 	}
 
-	/* not any further processing dummy messages */
-	if (mgcp_is_rtp_dummy_payload(msg))
-		return osmux_handle_dummy(trunk, &rem_addr, msg);
+	/* Catch legacy dummy message and process them separately: */
+	if (msg->len == 2 && msg->data[0] == MGCP_DUMMY_LOAD)
+		return osmux_handle_legacy_dummy(trunk, &rem_addr, msg);
 
 	rem = msg->len;
 	while((osmuxh = osmux_xfrm_output_pull(msg)) != NULL) {