Change in osmo-mgw[master]: rework message handling

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

Hoernchen gerrit-no-reply at lists.osmocom.org
Tue Nov 9 17:51:28 UTC 2021


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


Change subject: rework message handling
......................................................................

rework message handling

This was previously broken and a free endpoint was requirted to dlcx *,
additionaly globally handling this is difficult due to different
response
codes, so just do it in the functions, they know best.

Change-Id: I8cbbe5936067ea1caa7935e8d14908ac5c4010bd
---
M src/libosmo-mgcp/mgcp_protocol.c
1 file changed, 57 insertions(+), 58 deletions(-)



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

diff --git a/src/libosmo-mgcp/mgcp_protocol.c b/src/libosmo-mgcp/mgcp_protocol.c
index f0c184b..7775415 100644
--- a/src/libosmo-mgcp/mgcp_protocol.c
+++ b/src/libosmo-mgcp/mgcp_protocol.c
@@ -97,10 +97,6 @@
 	/* function pointer to the request handler */
 	struct msgb *(*handle_request)(struct mgcp_request_data *data);
 
-	/* true if the request requires an endpoint, false if only a trunk
-	 * is sufficient. (corner cases, e.g. wildcarded DLCX) */
-	bool require_endp;
-
 	/* a human readable name that describes the request */
 	char *debug_name;
 };
@@ -112,32 +108,34 @@
 static struct msgb *handle_rsip(struct mgcp_request_data *data);
 static struct msgb *handle_noti_req(struct mgcp_request_data *data);
 static const struct mgcp_request mgcp_requests[] = {
-	{ .name = "AUEP",
-	  .handle_request = handle_audit_endpoint,
-	  .debug_name = "AuditEndpoint",
-	  .require_endp = true },
-	{ .name = "CRCX",
-	  .handle_request = handle_create_con,
-	  .debug_name = "CreateConnection",
-	  .require_endp = true },
-	{ .name = "DLCX",
-	  .handle_request = handle_delete_con,
-	  .debug_name = "DeleteConnection",
-	  .require_endp = false },
-	{ .name = "MDCX",
-	  .handle_request = handle_modify_con,
-	  .debug_name = "ModifiyConnection",
-	  .require_endp = true },
-	{ .name = "RQNT",
-	  .handle_request = handle_noti_req,
-	  .debug_name = "NotificationRequest",
-	  .require_endp = true },
+	{ .name = "AUEP", .handle_request = handle_audit_endpoint, .debug_name = "AuditEndpoint" },
+	{
+		.name = "CRCX",
+		.handle_request = handle_create_con,
+		.debug_name = "CreateConnection",
+	},
+	{
+		.name = "DLCX",
+		.handle_request = handle_delete_con,
+		.debug_name = "DeleteConnection",
+	},
+	{
+		.name = "MDCX",
+		.handle_request = handle_modify_con,
+		.debug_name = "ModifiyConnection",
+	},
+	{
+		.name = "RQNT",
+		.handle_request = handle_noti_req,
+		.debug_name = "NotificationRequest",
+	},
 
 	/* SPEC extension */
-	{ .name = "RSIP",
-	  .handle_request = handle_rsip,
-	  .debug_name = "ReSetInProgress",
-	  .require_endp = true },
+	{
+		.name = "RSIP",
+		.handle_request = handle_rsip,
+		.debug_name = "ReSetInProgress",
+	},
 };
 
 /* Initalize transcoder */
@@ -424,17 +422,8 @@
 	}
 
 	/* Find an appropriate handler for the current request and execute it */
-	for (i = 0; i < ARRAY_SIZE(mgcp_requests); i++) {
+	for (int i = 0; i < ARRAY_SIZE(mgcp_requests); i++) {
 		if (strcmp(mgcp_requests[i].name, rq.name) == 0) {
-			/* Check if the request requires and endpoint, if yes, check if we have it, otherwise don't
-			 * execute the request handler. */
-			if (mgcp_requests[i].require_endp && !rq.endp) {
-				LOGP(DLMGCP, LOGL_ERROR,
-				     "%s: the request handler \"%s\" requires an endpoint resource for \"%s\", which is not available -- abort\n",
-				     rq.name, mgcp_requests[i].debug_name, pdata.epname);
-				return create_err_response(rq.trunk, NULL, -rq.mgcp_cause, rq.name, pdata.trans);
-			}
-
 			/* Execute request handler */
 			if (rq.endp)
 				LOGP(DLMGCP, LOGL_INFO,
@@ -465,6 +454,11 @@
 static struct msgb *handle_audit_endpoint(struct mgcp_request_data *rq)
 {
 	LOGPENDP(rq->endp, DLMGCP, LOGL_NOTICE, "AUEP: auditing endpoint ...\n");
+	if (!rq->endp || !mgcp_endp_avail(rq->endp)) {
+		LOGPENDP(rq->endp, DLMGCP, LOGL_ERROR, "AUEP: selected endpoint not available!\n");
+		return create_err_response(rq->trunk, NULL, 501, "AUEP", rq->pdata->trans);
+	}
+
 	return create_ok_response(rq->trunk, rq->endp, 200, "AUEP", rq->pdata->trans);
 }
 
@@ -859,6 +853,13 @@
 
 	LOGPENDP(endp, DLMGCP, LOGL_NOTICE, "CRCX: creating new connection ...\n");
 
+	/* we must have a free ep */
+	if (!endp) {
+		rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_CRCX_FAIL_AVAIL));
+		LOGPENDP(endp, DLMGCP, LOGL_ERROR, "CRCX: no free endpoints available!\n");
+		return create_err_response(rq->trunk, NULL, 403, "CRCX", pdata->trans);
+	}
+
 	if (!mgcp_endp_avail(endp)) {
 		rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_CRCX_FAIL_AVAIL));
 		LOGPENDP(endp, DLMGCP, LOGL_ERROR,
@@ -1116,13 +1117,6 @@
 
 	LOGPENDP(endp, DLMGCP, LOGL_NOTICE, "MDCX: modifying existing connection ...\n");
 
-	if (!mgcp_endp_avail(endp)) {
-		rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_MDCX_FAIL_AVAIL));
-		LOGPENDP(endp, DLMGCP, LOGL_ERROR,
-			 "MDCX: selected endpoint not available!\n");
-		return create_err_response(endp, NULL, 501, "MDCX", pdata->trans);
-	}
-
 	/* Prohibit wildcarded requests */
 	if (rq->wildcarded) {
 		LOGPENDP(endp, DLMGCP, LOGL_ERROR,
@@ -1131,6 +1125,11 @@
 		return create_err_response(rq->trunk, endp, 507, "MDCX", pdata->trans);
 	}
 
+	if (!endp || !mgcp_endp_avail(endp)) {
+		rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_MDCX_FAIL_AVAIL));
+		LOGPENDP(endp, DLMGCP, LOGL_ERROR, "MDCX: selected endpoint not available!\n");
+		return create_err_response(rq->trunk, NULL, 501, "MDCX", pdata->trans);
+	}
 	if (llist_count(&endp->conns) <= 0) {
 		LOGPENDP(endp, DLMGCP, LOGL_ERROR,
 			 "MDCX: endpoint is not holding a connection.\n");
@@ -1349,6 +1348,19 @@
 		return create_err_response(endp, endp, 515, "DLCX", pdata->trans);
 	}
 
+	/* Handle wildcarded DLCX that refers to the whole trunk. This means
+	 * that we walk over all endpoints on the trunk in order to drop all
+	 * connections on the trunk. (see also RFC3435 Annex F.7) */
+	if (rq->wildcarded) {
+		int num_conns = 0;
+		for (i = 0; i < trunk->number_endpoints; i++) {
+			num_conns += llist_count(&trunk->endpoints[i]->conns);
+			mgcp_endp_release(trunk->endpoints[i]);
+		}
+		rate_ctr_add(rate_ctr_group_get_ctr(rate_ctrs, MGCP_DLCX_SUCCESS), num_conns);
+		return create_ok_response(trunk, NULL, 200, "DLCX", pdata->trans);
+	}
+
 	for_each_line(line, pdata->save) {
 		if (!mgcp_check_param(endp, trunk, line))
 			continue;
@@ -1398,19 +1410,6 @@
 		}
 	}
 
-	/* Handle wildcarded DLCX that refers to the whole trunk. This means
-	 * that we walk over all endpoints on the trunk in order to drop all
-	 * connections on the trunk. (see also RFC3435 Annex F.7) */
-	if (rq->wildcarded) {
-		int num_conns = 0;
-		for (i = 0; i < trunk->number_endpoints; i++) {
-			num_conns += llist_count(&trunk->endpoints[i]->conns);
-			mgcp_endp_release(trunk->endpoints[i]);
-		}
-		rate_ctr_add(rate_ctr_group_get_ctr(rate_ctrs, MGCP_DLCX_SUCCESS), num_conns);
-		return create_ok_response(trunk, NULL, 200, "DLCX", pdata->trans);
-	}
-
 	/* The logic does not permit to go past this point without having the
 	 * the endp pointer populated. */
 	OSMO_ASSERT(endp);

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

Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-Change-Id: I8cbbe5936067ea1caa7935e8d14908ac5c4010bd
Gerrit-Change-Number: 26189
Gerrit-PatchSet: 1
Gerrit-Owner: Hoernchen <ewild at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20211109/cadc859d/attachment.htm>


More information about the gerrit-log mailing list