pespin has uploaded this change for review.

View Change

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.

Change-Id: Icf3b4dda550637f722a9fe56d0313f49c8a2964e
---
M src/ipa.c
M src/m3ua.c
M src/xua_rkm.c
3 files changed, 46 insertions(+), 23 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/libosmo-sigtran refs/changes/97/39397/1
diff --git a/src/ipa.c b/src/ipa.c
index 944fbce..ac0cf3a 100644
--- a/src/ipa.c
+++ b/src/ipa.c
@@ -300,9 +300,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 ownsership 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 dbdd4e2..69910fb 100644
--- a/src/m3ua.c
+++ b/src/m3ua.c
@@ -566,6 +566,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);
@@ -581,7 +582,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. */
@@ -592,13 +594,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);

@@ -620,8 +624,12 @@
xua_msg_free_tag(xua, M3UA_IEI_ROUTE_CTX);
}

+ /* xua ownsership 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)
@@ -681,16 +689,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 */
@@ -707,23 +723,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);
@@ -804,8 +823,6 @@
if (err)
m3ua_tx_xua_asp(asp, err);

- xua_msg_free(xua);
-
return rc;
}

@@ -955,7 +972,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;
@@ -964,7 +982,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) {
@@ -1001,7 +1019,9 @@
return 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 9a3918e..73461ec 100644
--- a/src/xua_rkm.c
+++ b/src/xua_rkm.c
@@ -532,7 +532,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;
@@ -562,6 +563,8 @@
rc = -1;
break;
}
+
+ xua_msg_free(xua);
return rc;
}


To view, visit change 39397. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: libosmo-sigtran
Gerrit-Branch: master
Gerrit-Change-Id: Icf3b4dda550637f722a9fe56d0313f49c8a2964e
Gerrit-Change-Number: 39397
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin@sysmocom.de>