[PATCH] osmo-mgw[master]: Return proper MGCP Error codes, as per spec

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

Harald Welte gerrit-no-reply at lists.osmocom.org
Thu Dec 28 12:50:19 UTC 2017


Review at  https://gerrit.osmocom.org/5609

Return proper MGCP Error codes, as per spec

Change-Id: I55db8351422ff951516fefa6a29e87086b7ab74b
Closes: OS#2657, OS#2656
---
M include/osmocom/mgcp/mgcp_internal.h
M src/libosmo-mgcp/mgcp_protocol.c
2 files changed, 21 insertions(+), 14 deletions(-)


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

diff --git a/include/osmocom/mgcp/mgcp_internal.h b/include/osmocom/mgcp/mgcp_internal.h
index 5c96928..33a754c 100644
--- a/include/osmocom/mgcp/mgcp_internal.h
+++ b/include/osmocom/mgcp/mgcp_internal.h
@@ -273,7 +273,6 @@
 	struct mgcp_endpoint *endp;
 	char *trans;
 	char *save;
-	int found;
 };
 
 int mgcp_send(struct mgcp_endpoint *endp, int is_rtp, struct sockaddr_in *addr,
diff --git a/src/libosmo-mgcp/mgcp_protocol.c b/src/libosmo-mgcp/mgcp_protocol.c
index 71c0fde..9d79343 100644
--- a/src/libosmo-mgcp/mgcp_protocol.c
+++ b/src/libosmo-mgcp/mgcp_protocol.c
@@ -252,7 +252,7 @@
 struct msgb *mgcp_handle_message(struct mgcp_config *cfg, struct msgb *msg)
 {
 	struct mgcp_parse_data pdata;
-	int i, code, handled = 0;
+	int rc, i, code, handled = 0;
 	struct msgb *resp = NULL;
 	char *data;
 
@@ -280,7 +280,7 @@
 	memset(&pdata, 0, sizeof(pdata));
 	pdata.cfg = cfg;
 	data = mgcp_strline((char *)msg->l3h, &pdata.save);
-	pdata.found = mgcp_parse_header(&pdata, data);
+	rc = mgcp_parse_header(&pdata, data);
 	if (pdata.endp && pdata.trans
 	    && pdata.endp->last_trans
 	    && strcmp(pdata.endp->last_trans, pdata.trans) == 0) {
@@ -288,9 +288,9 @@
 	}
 
 	/* check for general parser failure */
-	if (pdata.found < 0) {
+	if (rc < 0) {
 		LOGP(DLMGCP, LOGL_NOTICE, "%s: failed to find the endpoint\n", msg->l2h);
-		return create_err_response(NULL, -pdata.found, (const char *) msg->l2h, pdata.trans);
+		return create_err_response(NULL, -rc, (const char *) msg->l2h, pdata.trans);
 	}
 
 	for (i = 0; i < ARRAY_SIZE(mgcp_requests); ++i) {
@@ -500,14 +500,14 @@
 		LOGP(DLMGCP, LOGL_ERROR,
 		     "CRCX: endpoint:%x insufficient parameters, missing callid\n",
 		     ENDPOINT_NUMBER(endp));
-		return create_err_response(endp, 400, "CRCX", p->trans);
+		return create_err_response(endp, 516, "CRCX", p->trans);
 	}
 
 	if (!mode) {
 		LOGP(DLMGCP, LOGL_ERROR,
 		     "CRCX: endpoint:%x insufficient parameters, missing mode\n",
 		     ENDPOINT_NUMBER(endp));
-		return create_err_response(endp, 400, "CRCX", p->trans);
+		return create_err_response(endp, 517, "CRCX", p->trans);
 	}
 
 	/* Check if we are able to accept the creation of another connection */
@@ -523,7 +523,7 @@
 		} else {
 			/* There is no more room for a connection, leave
 			 * everything as it is and return with an error */
-			return create_err_response(endp, 400, "CRCX", p->trans);
+			return create_err_response(endp, 540, "CRCX", p->trans);
 		}
 	}
 
@@ -685,13 +685,17 @@
 
 		switch (line[0]) {
 		case 'C':
-			if (mgcp_verify_call_id(endp, line + 3) != 0)
+			if (mgcp_verify_call_id(endp, line + 3) != 0) {
+				error_code = 516;
 				goto error3;
+			}
 			break;
 		case 'I':
 			conn_id = (const char *)line + 3;
-			if (mgcp_verify_ci(endp, conn_id) != 0)
+			if (mgcp_verify_ci(endp, conn_id) != 0) {
+				error_code = 515;
 				goto error3;
+			}
 			break;
 		case 'L':
 			local_options = (const char *)line + 3;
@@ -719,7 +723,7 @@
 		LOGP(DLMGCP, LOGL_ERROR,
 		     "MDCX: endpoint:0x%x insufficient parameters, missing ci (connectionIdentifier)\n",
 		     ENDPOINT_NUMBER(endp));
-		return create_err_response(endp, 400, "MDCX", p->trans);
+		return create_err_response(endp, 515, "MDCX", p->trans);
 	}
 
 	conn = mgcp_conn_get_rtp(endp, conn_id);
@@ -826,7 +830,7 @@
 		LOGP(DLMGCP, LOGL_ERROR,
 		     "DLCX: endpoint:0x%x endpoint is not holding a connection.\n",
 		     ENDPOINT_NUMBER(endp));
-		return create_err_response(endp, 400, "DLCX", p->trans);
+		return create_err_response(endp, 515, "DLCX", p->trans);
 	}
 
 	for_each_line(line, p->save) {
@@ -835,13 +839,17 @@
 
 		switch (line[0]) {
 		case 'C':
-			if (mgcp_verify_call_id(endp, line + 3) != 0)
+			if (mgcp_verify_call_id(endp, line + 3) != 0) {
+				error_code = 516;
 				goto error3;
+			}
 			break;
 		case 'I':
 			conn_id = (const char *)line + 3;
-			if (mgcp_verify_ci(endp, conn_id) != 0)
+			if (mgcp_verify_ci(endp, conn_id) != 0) {
+				error_code = 515;
 				goto error3;
+			}
 			break;
 		case 'Z':
 			silent = strcmp("noanswer", line + 3) == 0;

-- 
To view, visit https://gerrit.osmocom.org/5609
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I55db8351422ff951516fefa6a29e87086b7ab74b
Gerrit-PatchSet: 1
Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>



More information about the gerrit-log mailing list