[MERGED] osmo-mgw[master]: msg: fix response code on exhausted endp resources

Harald Welte gerrit-no-reply at lists.osmocom.org
Sat Feb 3 14:22:53 UTC 2018


Harald Welte has submitted this change and it was merged.

Change subject: msg: fix response code on exhausted endp resources
......................................................................


msg: fix response code on exhausted endp resources

When all endpoints are seized and a call agent tries to allocate
another one, then 500 is returned as response code, which means
that the endpoint was not found. This does not match.

- Return 403 which is defined as "Insufficient resources available
  at this time"

Change-Id: Idf241b47e711e35e9f9b5a43f3cea5c0298ea30b
---
M src/libosmo-mgcp/mgcp_msg.c
1 file changed, 19 insertions(+), 7 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/libosmo-mgcp/mgcp_msg.c b/src/libosmo-mgcp/mgcp_msg.c
index 3aa93b7..4055a0c 100644
--- a/src/libosmo-mgcp/mgcp_msg.c
+++ b/src/libosmo-mgcp/mgcp_msg.c
@@ -224,11 +224,15 @@
 /* Search the endpoint pool for the endpoint that had been selected via the
  * MGCP message (helper function for mgcp_analyze_header()) */
 static struct mgcp_endpoint *find_endpoint(struct mgcp_config *cfg,
-					   const char *mgcp)
+					   const char *mgcp,
+					   int *cause)
 {
 	char *endptr = NULL;
 	unsigned int gw = INT_MAX;
 	const char *endpoint_number_str;
+	struct mgcp_endpoint *endp;
+
+	*cause = 0;
 
 	/* Check if the domainname in the request is correct */
 	if (check_domain_name(cfg, mgcp)) {
@@ -237,8 +241,12 @@
 	}
 
 	/* Check if the E1 trunk is requested */
-	if (strncmp(mgcp, "ds/e1", 5) == 0)
-		return find_e1_endpoint(cfg, mgcp);
+	if (strncmp(mgcp, "ds/e1", 5) == 0) {
+		endp = find_e1_endpoint(cfg, mgcp);
+		if (!endp)
+			*cause = -500;
+		return endp;
+	}
 
 	/* Check if the virtual trunk is addressed (new, correct way with prefix) */
 	if (strncmp
@@ -247,10 +255,12 @@
 		endpoint_number_str =
 		    mgcp + strlen(MGCP_ENDPOINT_PREFIX_VIRTUAL_TRUNK);
 		if (endpoint_number_str[0] == '*') {
-			return find_free_endpoint(cfg->trunk.endpoints,
+			endp = find_free_endpoint(cfg->trunk.endpoints,
 						  cfg->trunk.number_endpoints);
+			if (!endp)
+				*cause = -403;
+			return endp;
 		}
-
 		gw = strtoul(endpoint_number_str, &endptr, 16);
 		if (gw < cfg->trunk.number_endpoints && endptr[0] == '@')
 			return &cfg->trunk.endpoints[gw];
@@ -265,6 +275,7 @@
 		return &cfg->trunk.endpoints[gw];
 
 	LOGP(DLMGCP, LOGL_ERROR, "Not able to find the endpoint: '%s'\n", mgcp);
+	*cause = -500;
 	return NULL;
 }
 
@@ -277,6 +288,7 @@
 {
 	int i = 0;
 	char *elem, *save = NULL;
+	int cause;
 
 	/*! This function will parse the header part of the received
 	 *  MGCP message. The parsing results are stored in pdata.
@@ -294,11 +306,11 @@
 			pdata->trans = elem;
 			break;
 		case 1:
-			pdata->endp = find_endpoint(pdata->cfg, elem);
+			pdata->endp = find_endpoint(pdata->cfg, elem, &cause);
 			if (!pdata->endp) {
 				LOGP(DLMGCP, LOGL_ERROR,
 				     "Unable to find Endpoint `%s'\n", elem);
-				return -500;
+				return cause;
 			}
 			break;
 		case 2:

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Idf241b47e711e35e9f9b5a43f3cea5c0298ea30b
Gerrit-PatchSet: 1
Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder


More information about the gerrit-log mailing list