diff options
author | Harald Welte <laforge@osmocom.org> | 2021-02-07 12:34:42 +0100 |
---|---|---|
committer | laforge <laforge@osmocom.org> | 2021-02-08 10:41:03 +0000 |
commit | aabb38a77b9c0599849cfe7940679c88ebce25fb (patch) | |
tree | 758f01eb412a22a2da1be1973dd8466c51466951 | |
parent | bdf5ae5f02cf2d07a6a0e0b91667098e8e3ececf (diff) |
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
-rw-r--r-- | src/m3ua.c | 55 |
1 files changed, 34 insertions, 21 deletions
@@ -533,7 +533,7 @@ struct m3ua_data_hdr *data_hdr_from_m3ua(struct xua_msg *xua) } /* 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,44 +549,33 @@ static struct osmo_ss7_as *find_single_as_for_asp(struct osmo_ss7_asp *asp) return as_found; } -static int m3ua_rx_xfer(struct osmo_ss7_asp *asp, struct xua_msg *xua) +static int find_as_for_asp(struct osmo_ss7_as **as, const struct osmo_ss7_asp *asp, + const struct xua_msg_part *rctx_ie) { - 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; - - LOGPASP(asp, DLM3UA, LOGL_DEBUG, "m3ua_rx_xfer\n"); - - if (xua->hdr.msg_type != M3UA_XFER_DATA) { - LOGPASP(asp, DLM3UA, LOGL_ERROR, - "%s(): unsupported message type: %s\n", - __func__, - get_value_string(m3ua_xfer_msgt_names, xua->hdr.msg_type)); - return M3UA_ERR_UNSUPP_MSG_TYPE; - } + *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) { + *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)) { + 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); + "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) { + *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__); @@ -594,6 +583,30 @@ static int m3ua_rx_xfer(struct osmo_ss7_asp *asp, struct xua_msg *xua) } } + 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"); + + if (xua->hdr.msg_type != M3UA_XFER_DATA) { + LOGPASP(asp, DLM3UA, LOGL_ERROR, + "%s(): unsupported message type: %s\n", + __func__, + get_value_string(m3ua_xfer_msgt_names, xua->hdr.msg_type)); + return M3UA_ERR_UNSUPP_MSG_TYPE; + } + + rc = find_as_for_asp(&as, asp, rctx_ie); + if (rc) + return rc; + /* FIXME: check for AS state == ACTIVE */ /* store the MTP-level information in the xua_msg for use by |