Change in libosmo-sccp[master]: m3ua: re-factor m3ua_rx_xfer(): Externalize AS for ASP lookup

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

laforge gerrit-no-reply at lists.osmocom.org
Mon Feb 8 10:41:03 UTC 2021


laforge has submitted this change. ( https://gerrit.osmocom.org/c/libosmo-sccp/+/22773 )

Change subject: m3ua: re-factor m3ua_rx_xfer(): Externalize AS for ASP lookup
......................................................................

m3ua: re-factor m3ua_rx_xfer(): Externalize AS for ASP lookup

Let's factor-out the lookup of the AS into the separate function
find_as_for_asp().  This enables us to reuse this code in upcoming
support for SNM messages.

Change-Id: If58ea24efe7d54994a7ca2f0a97944bd297a8cc6
---
M src/m3ua.c
1 file changed, 42 insertions(+), 29 deletions(-)

Approvals:
  pespin: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/m3ua.c b/src/m3ua.c
index 08a89b5..542777e 100644
--- a/src/m3ua.c
+++ b/src/m3ua.c
@@ -533,7 +533,7 @@
 }
 
 /* if given ASP only has one AS, return that AS */
-static struct osmo_ss7_as *find_single_as_for_asp(struct osmo_ss7_asp *asp)
+static struct osmo_ss7_as *find_single_as_for_asp(const struct osmo_ss7_asp *asp)
 {
 	struct osmo_ss7_as *as, *as_found = NULL;
 
@@ -549,11 +549,49 @@
 	return as_found;
 }
 
+static int find_as_for_asp(struct osmo_ss7_as **as, const struct osmo_ss7_asp *asp,
+			   const struct xua_msg_part *rctx_ie)
+{
+	*as = NULL;
+
+	if (rctx_ie) {
+		uint32_t rctx = xua_msg_part_get_u32(rctx_ie);
+		/* Use routing context IE to look up the AS for which the
+		 * message was received. */
+		*as = osmo_ss7_as_find_by_rctx(asp->inst, rctx);
+		if (!*as) {
+			LOGPASP(asp, DLM3UA, LOGL_ERROR, "%s(): invalid routing context: %u\n",
+				__func__, rctx);
+			return M3UA_ERR_INVAL_ROUT_CTX;
+		}
+
+		/* Verify that this ASP is part of the AS. */
+		if (!osmo_ss7_as_has_asp(*as, asp)) {
+			LOGPASP(asp, DLM3UA, LOGL_ERROR,
+				"%s(): This Application Server Process is not part of the AS %s "
+				"resolved by routing context %u\n", __func__, (*as)->cfg.name, rctx);
+			return M3UA_ERR_NO_CONFGD_AS_FOR_ASP;
+		}
+	} else {
+		/* no explicit routing context; this only works if there is only one AS in the ASP */
+		*as = find_single_as_for_asp(asp);
+		if (!*as) {
+			LOGPASP(asp, DLM3UA, LOGL_ERROR,
+				"%s(): ASP sent M3UA without Routing Context IE but unable to uniquely "
+				"identify the AS for this message\n", __func__);
+			return M3UA_ERR_INVAL_ROUT_CTX;
+		}
+	}
+
+	return 0;
+}
+
 static int m3ua_rx_xfer(struct osmo_ss7_asp *asp, struct xua_msg *xua)
 {
 	struct xua_msg_part *rctx_ie = xua_msg_find_tag(xua, M3UA_IEI_ROUTE_CTX);
 	struct m3ua_data_hdr *dh;
 	struct osmo_ss7_as *as;
+	int rc;
 
 	LOGPASP(asp, DLM3UA, LOGL_DEBUG, "m3ua_rx_xfer\n");
 
@@ -565,34 +603,9 @@
 		return M3UA_ERR_UNSUPP_MSG_TYPE;
 	}
 
-	if (rctx_ie) {
-		uint32_t rctx = xua_msg_part_get_u32(rctx_ie);
-		/* Use routing context IE to look up the AS for which the
-		 * message was received. */
-		as = osmo_ss7_as_find_by_rctx(asp->inst, rctx);
-		if (!as) {
-			LOGPASP(asp, DLM3UA, LOGL_ERROR, "%s(): invalid routing context: %u\n",
-				__func__, rctx);
-			return M3UA_ERR_INVAL_ROUT_CTX;
-		}
-
-		/* Verify that this ASP is part of the AS. */
-		if (!osmo_ss7_as_has_asp(as, asp)) {
-			LOGPASP(asp, DLM3UA, LOGL_ERROR,
-				"%s(): This Application Server Process is not part of the AS %s "
-				"resolved by routing context %u\n", __func__, (as)->cfg.name, rctx);
-			return M3UA_ERR_NO_CONFGD_AS_FOR_ASP;
-		}
-	} else {
-		/* no explicit routing context; this only works if there is only one AS in the ASP */
-		as = find_single_as_for_asp(asp);
-		if (!as) {
-			LOGPASP(asp, DLM3UA, LOGL_ERROR,
-				"%s(): ASP sent M3UA without Routing Context IE but unable to uniquely "
-				"identify the AS for this message\n", __func__);
-			return M3UA_ERR_INVAL_ROUT_CTX;
-		}
-	}
+	rc = find_as_for_asp(&as, asp, rctx_ie);
+	if (rc)
+		return rc;
 
 	/* FIXME: check for AS state == ACTIVE */
 

-- 
To view, visit https://gerrit.osmocom.org/c/libosmo-sccp/+/22773
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmo-sccp
Gerrit-Branch: master
Gerrit-Change-Id: If58ea24efe7d54994a7ca2f0a97944bd297a8cc6
Gerrit-Change-Number: 22773
Gerrit-PatchSet: 3
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210208/d3246be7/attachment.htm>


More information about the gerrit-log mailing list