neels submitted this change.
add hnbgw_decode_ranap_co()
An upcoming patch will re-use this pattern of decoding RANAP and
attaching a talloc destructor to the result for the third time. The
caller will be in hnbgw_rua.c, so make this a "public" function.
Change-Id: I3695babfb083ed1f5fff700dcb7646fa95496a52
---
M include/osmocom/hnbgw/hnbgw_rua.h
M src/osmo-hnbgw/context_map_rua.c
2 files changed, 40 insertions(+), 11 deletions(-)
diff --git a/include/osmocom/hnbgw/hnbgw_rua.h b/include/osmocom/hnbgw/hnbgw_rua.h
index 1526f11..0bf2de8 100644
--- a/include/osmocom/hnbgw/hnbgw_rua.h
+++ b/include/osmocom/hnbgw/hnbgw_rua.h
@@ -2,6 +2,7 @@
#include <osmocom/hnbgw/hnbgw.h>
#include <osmocom/rua/RUA_Cause.h>
+#include <osmocom/ranap/ranap_ies_defs.h>
int hnbgw_rua_rx(struct hnb_context *hnb, struct msgb *msg);
@@ -10,3 +11,5 @@
const uint8_t *data, unsigned int len);
int rua_tx_disc(struct hnb_context *hnb, int is_ps, uint32_t context_id,
const RUA_Cause_t *cause, const uint8_t *data, unsigned int len);
+
+ranap_message *hnbgw_decode_ranap_co(struct msgb *ranap_msg);
diff --git a/src/osmo-hnbgw/context_map_rua.c b/src/osmo-hnbgw/context_map_rua.c
index 9cb45b0..09c275d 100644
--- a/src/osmo-hnbgw/context_map_rua.c
+++ b/src/osmo-hnbgw/context_map_rua.c
@@ -133,22 +133,38 @@
return 0;
}
+/* Decode RANAP message with convenient memory freeing: just talloc_free() the returned pointer..
+ * Allocate a ranap_message from OTC_SELECT, decode RANAP msgb into it, attach a talloc destructor that calls
+ * ranap_cn_rx_co_free() upon talloc_free(), and return the decoded ranap_message. */
+ranap_message *hnbgw_decode_ranap_co(struct msgb *ranap_msg)
+{
+ int rc;
+ ranap_message *message;
+
+ if (!msg_has_l2_data(ranap_msg))
+ return NULL;
+ message = talloc_zero(OTC_SELECT, ranap_message);
+ rc = ranap_cn_rx_co_decode2(message, msgb_l2(ranap_msg), msgb_l2len(ranap_msg));
+ if (rc != 0) {
+ talloc_free(message);
+ return NULL;
+ }
+ talloc_set_destructor(message, destruct_ranap_cn_rx_co_ies);
+ return message;
+}
+
/* Dispatch RANAP message to SCCP, if any. */
static int handle_rx_rua(struct osmo_fsm_inst *fi, struct msgb *ranap_msg)
{
struct hnbgw_context_map *map = fi->priv;
- int rc;
if (!msg_has_l2_data(ranap_msg))
return 0;
/* See if it is a RAB Assignment Response message from RUA to SCCP, where we need to change the user plane
* information, for RTP mapping via MGW, or GTP mapping via UPF. */
if (!map->is_ps) {
- ranap_message *message = talloc_zero(OTC_SELECT, ranap_message);
- rc = ranap_cn_rx_co_decode2(message, msgb_l2(ranap_msg), msgb_l2len(ranap_msg));
- if (rc == 0) {
- talloc_set_destructor(message, destruct_ranap_cn_rx_co_ies);
-
+ ranap_message *message = hnbgw_decode_ranap_co(ranap_msg);
+ if (message) {
LOGPFSML(fi, LOGL_DEBUG, "rx from RUA: RANAP %s\n",
get_value_string(ranap_procedure_code_vals, message->procedureCode));
@@ -161,11 +177,8 @@
#if ENABLE_PFCP
} else if (hnb_gw_is_gtp_mapping_enabled()) {
/* map->is_ps == true and PFCP is enabled in osmo-hnbgw.cfg */
- ranap_message *message = talloc_zero(OTC_SELECT, ranap_message);
- rc = ranap_cn_rx_co_decode2(message, msgb_l2(ranap_msg), msgb_l2len(ranap_msg));
- if (rc == 0) {
- talloc_set_destructor(message, destruct_ranap_cn_rx_co_ies);
-
+ ranap_message *message = hnbgw_decode_ranap_co(ranap_msg);
+ if (message) {
LOGPFSML(fi, LOGL_DEBUG, "rx from RUA: RANAP %s\n",
get_value_string(ranap_procedure_code_vals, message->procedureCode));
To view, visit change 33132. To unsubscribe, or for help writing mail filters, visit settings.