pespin has submitted this change. ( https://gerrit.osmocom.org/c/libosmo-sigtran/+/39397?usp=email )
(
11 is the latest approved patch-set. No files were changed between the latest approved patch-set and the submitted one. )Change subject: ASP loadsharing: Pass ownership of Rx xua_msg up the stack [2/2] ......................................................................
ASP loadsharing: Pass ownership of Rx xua_msg up the stack [2/2]
This is the second step patch where we also pass ownership on Rx path so that forwarded xua_msgs can be passed back to the Tx path without freeing them.
For SUA there's no change needed and we keep freeing the rx xua_msg right at the end of sua_rx_msg() since there's no actual path forwarding a xua_msg object back into Tx path, it always goes through upper layers using newly allocated primitives.
Related: SYS#7112 Change-Id: Icf3b4dda550637f722a9fe56d0313f49c8a2964e --- M src/ipa.c M src/m3ua.c M src/xua_rkm.c 3 files changed, 58 insertions(+), 34 deletions(-)
Approvals: laforge: Looks good to me, but someone else must approve osmith: Looks good to me, but someone else must approve pespin: Looks good to me, approved Jenkins Builder: Verified
diff --git a/src/ipa.c b/src/ipa.c index 47ddc0d..bbe94d1 100644 --- a/src/ipa.c +++ b/src/ipa.c @@ -302,9 +302,9 @@ /* Update xua->mtp with values from data_hdr */ m3ua_dh_to_xfer_param(&xua->mtp, &data_hdr);
- /* Pass on as if we had received it from an M3UA ASP */ + /* Pass on as if we had received it from an M3UA ASP. + * xua ownership is passed here: */ rc = m3ua_hmdc_rx_from_l2(asp->inst, xua); - xua_msg_free(xua); return rc; }
diff --git a/src/m3ua.c b/src/m3ua.c index cdbfc48..8232d7b 100644 --- a/src/m3ua.c +++ b/src/m3ua.c @@ -579,6 +579,7 @@ return data_hdr; }
+/* This function takes ownership of xua msg passed to it. */ static int m3ua_rx_xfer(struct osmo_ss7_asp *asp, struct xua_msg *xua) { struct xua_msg_part *na_ie = xua_msg_find_tag(xua, M3UA_IEI_NET_APPEAR); @@ -594,7 +595,8 @@ "%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 = M3UA_ERR_UNSUPP_MSG_TYPE; + goto ret_free; }
/* Reject unsupported Network Appearance IE. */ @@ -605,13 +607,15 @@ "Unsupported 'Network Appearance' IE '0x%08x' in message type '%s', sending 'Error'.\n", na, get_value_string(m3ua_xfer_msgt_names, xua->hdr.msg_type)); if (na_ie->len != 4) - return M3UA_ERR_PARAM_FIELD_ERR; - return M3UA_ERR_INVAL_NET_APPEAR; + rc = M3UA_ERR_PARAM_FIELD_ERR; + else + rc = M3UA_ERR_INVAL_NET_APPEAR; + goto ret_free; }
rc = xua_find_as_for_asp(&as, asp, rctx_ie); if (rc) - return rc; + goto ret_free;
rate_ctr_inc2(as->ctrg, SS7_AS_CTR_RX_MSU_TOTAL);
@@ -635,8 +639,12 @@ xua_msg_free_tag(xua, M3UA_IEI_ROUTE_CTX); }
+ /* xua ownership is passed here: */ return m3ua_hmdc_rx_from_l2(asp->inst, xua); - /* xua will be freed by caller m3ua_rx_msg() */ + +ret_free: + xua_msg_free(xua); + return rc; }
static int m3ua_rx_mgmt_err(struct osmo_ss7_asp *asp, struct xua_msg *xua) @@ -683,16 +691,24 @@ return 0; }
+/* This function takes ownership of xua msg passed to it. */ static int m3ua_rx_mgmt(struct osmo_ss7_asp *asp, struct xua_msg *xua) { + int rc; + switch (xua->hdr.msg_type) { case M3UA_MGMT_ERR: - return m3ua_rx_mgmt_err(asp, xua); + rc = m3ua_rx_mgmt_err(asp, xua); + break; case M3UA_MGMT_NTFY: - return m3ua_rx_mgmt_ntfy(asp, xua); + rc = m3ua_rx_mgmt_ntfy(asp, xua); + break; default: - return M3UA_ERR_UNSUPP_MSG_TYPE; + rc = M3UA_ERR_UNSUPP_MSG_TYPE; } + + xua_msg_free(xua); + return rc; }
/* map from M3UA ASPSM/ASPTM to xua_asp_fsm event */ @@ -709,23 +725,26 @@ { M3UA_MSGC_ASPTM, M3UA_ASPTM_INACTIVE_ACK, XUA_ASP_E_ASPTM_ASPIA_ACK }, };
- +/* This function takes ownership of xua msg passed to it. */ static int m3ua_rx_asp(struct osmo_ss7_asp *asp, struct xua_msg *xua) { int event; + int rc = 0;
/* map from the M3UA message class and message type to the XUA * ASP FSM event number */ event = xua_msg_event_map(xua, m3ua_aspxm_map, ARRAY_SIZE(m3ua_aspxm_map)); - if (event < 0) - return M3UA_ERR_UNSUPP_MSG_TYPE; + if (event < 0) { + rc = M3UA_ERR_UNSUPP_MSG_TYPE; + goto ret_free; + }
/* deliver that event to the ASP FSM */ - if (osmo_fsm_inst_dispatch(asp->fi, event, xua) < 0) - return M3UA_ERR_UNEXPECTED_MSG; - - return 0; + rc = osmo_fsm_inst_dispatch(asp->fi, event, xua); +ret_free: + xua_msg_free(xua); + return rc; }
static int m3ua_rx_snm(struct osmo_ss7_asp *asp, struct xua_msg *xua); @@ -753,9 +772,9 @@ "M3UA message\n");
if (hdr->version != M3UA_VERSION) - err = m3ua_gen_error_msg(M3UA_ERR_INVALID_VERSION, msg); + rc = M3UA_ERR_INVALID_VERSION; else - err = m3ua_gen_error_msg(M3UA_ERR_PARAM_FIELD_ERR, msg); + rc = M3UA_ERR_PARAM_FIELD_ERR; goto out; }
@@ -763,7 +782,8 @@ xua_hdr_dump(xua, &xua_dialect_m3ua));
if (!xua_dialect_check_all_mand_ies(&xua_dialect_m3ua, xua)) { - err = m3ua_gen_error_msg(M3UA_ERR_MISSING_PARAM, msg); + rc = M3UA_ERR_MISSING_PARAM; + xua_msg_free(xua); goto out; }
@@ -775,7 +795,8 @@ /* The DATA message MUST NOT be sent on stream 0. */ if (msgb_sctp_stream(msg) == 0) { rc = M3UA_ERR_INVAL_STREAM_ID; - break; + xua_msg_free(xua); + goto out; } rc = m3ua_rx_xfer(asp, xua); break; @@ -795,19 +816,16 @@ default: LOGPASP(asp, DLM3UA, LOGL_NOTICE, "Received unknown M3UA " "Message Class %u\n", xua->hdr.msg_class); - err = m3ua_gen_error_msg(M3UA_ERR_UNSUPP_MSG_CLASS, msg); - break; + rc = M3UA_ERR_UNSUPP_MSG_CLASS; + xua_msg_free(xua); + goto out; }
+out: if (rc > 0) err = m3ua_gen_error_msg(rc, msg); - -out: if (err) m3ua_tx_xua_asp(asp, err); - - xua_msg_free(xua); - return rc; }
@@ -957,7 +975,8 @@ m3ua_tx_xua_asp(asp, xua); }
-/* received SNM message on ASP side */ +/* received SNM message on ASP side + * This function takes ownership of xua msg passed to it. */ static int m3ua_rx_snm_asp(struct osmo_ss7_asp *asp, struct xua_msg *xua) { struct osmo_ss7_as *as = NULL; @@ -966,7 +985,7 @@
rc = xua_find_as_for_asp(&as, asp, rctx_ie); if (rc) - return rc; + goto ret_free;
/* report those up the stack so both other ASPs and local SCCP users can be notified */ switch (xua->hdr.msg_type) { @@ -996,14 +1015,16 @@ xua_snm_rx_daud(asp, xua); } else { LOGPASP(asp, DLM3UA, LOGL_ERROR, "DAUD not permitted in ASP role\n"); - return M3UA_ERR_UNSUPP_MSG_TYPE; + rc = M3UA_ERR_UNSUPP_MSG_TYPE; } break; default: - return M3UA_ERR_UNSUPP_MSG_TYPE; + rc = M3UA_ERR_UNSUPP_MSG_TYPE; }
- return 0; +ret_free: + xua_msg_free(xua); + return rc; }
/* received SNM message on SG side */ diff --git a/src/xua_rkm.c b/src/xua_rkm.c index 8fa8c3b..1ae5ea6 100644 --- a/src/xua_rkm.c +++ b/src/xua_rkm.c @@ -548,7 +548,8 @@ return 0; }
-/* process an incoming RKM message in xua format */ +/* process an incoming RKM message in xua format + * This function takes ownership of xua msg passed to it. */ int m3ua_rx_rkm(struct osmo_ss7_asp *asp, struct xua_msg *xua) { int rc; @@ -578,6 +579,8 @@ rc = -1; break; } + + xua_msg_free(xua); return rc; }