pespin has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/osmo-hnbgw/+/28284 )


Change subject: mgw_fsm: Simplify cleanup paths
......................................................................

mgw_fsm: Simplify cleanup paths

Let's have a unified way of freeing the FSM instance once it was
allocated, otherwise it's far more difficult to understand and maintain.

Change-Id: I8883e737fa112cff57834abae7ef272388a54edb
---
M src/osmo-hnbgw/mgw_fsm.c
1 file changed, 37 insertions(+), 43 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-hnbgw refs/changes/84/28284/1

diff --git a/src/osmo-hnbgw/mgw_fsm.c b/src/osmo-hnbgw/mgw_fsm.c
index 1360849..51e6f32 100644
--- a/src/osmo-hnbgw/mgw_fsm.c
+++ b/src/osmo-hnbgw/mgw_fsm.c
@@ -141,11 +141,37 @@
 {
        struct mgw_fsm_priv *mgw_fsm_priv = fi->priv;
        struct hnbgw_context_map *map = mgw_fsm_priv->map;
+       struct osmo_sockaddr addr;
+       struct osmo_sockaddr_str addr_str;
+       RANAP_RAB_AssignmentRequestIEs_t *ies;
        const char *epname;
        struct mgcp_conn_peer mgw_info;
+       int rc;

        LOGPFSML(fi, LOGL_DEBUG, "RAB-AssignmentRequest received, creating HNB 
side call-leg on MGW...\n");

+       /* Parse the RAB Assignment Request now */
+       ies = 
&mgw_fsm_priv->ranap_rab_ass_req_message->msg.raB_AssignmentRequestIEs;
+       rc = ranap_rab_ass_req_ies_extract_inet_addr(&addr, 
&mgw_fsm_priv->rab_id, ies, 0);
+       if (rc < 0) {
+               LOGPFSML(fi,  LOGL_ERROR,
+                        "mgw_fsm_alloc_and_handle_rab_ass_req() rua_ctx_id=%d, 
invalid RAB-AssignmentRequest -- abort!\n",
+                        map->rua_ctx_id);
+               osmo_fsm_inst_state_chg(fi, MGW_ST_FAILURE, 0, 0);
+               return;
+       }
+
+       rc = osmo_sockaddr_str_from_sockaddr(&addr_str, &addr.u.sas);
+       if (rc < 0) {
+               LOGPFSML(fi, LOGL_ERROR,
+                        "mgw_fsm_alloc_and_handle_rab_ass_req() rua_ctx_id=%d, 
Invalid RTP IP-address or Port in RAB-AssignmentRequest -- abort\n",
+                        map->rua_ctx_id);
+               osmo_fsm_inst_state_chg(fi, MGW_ST_FAILURE, 0, 0);
+               return;
+       }
+       osmo_strlcpy(mgw_fsm_priv->msc_rtp_addr, addr_str.ip, 
sizeof(mgw_fsm_priv->msc_rtp_addr));
+       mgw_fsm_priv->msc_rtp_port = addr_str.port;
+
        mgw_info = (struct mgcp_conn_peer) {
                .call_id = (map->rua_ctx_id << 8) | mgw_fsm_priv->rab_id,
                .ptime = 20,
@@ -496,8 +522,9 @@
        return 0;
 }

-static void mgw_fsm_priv_cleanup(struct mgw_fsm_priv *mgw_fsm_priv)
+static void mgw_fsm_cleanup(struct osmo_fsm_inst *fi, enum osmo_fsm_term_cause 
cause)
 {
+       struct mgw_fsm_priv *mgw_fsm_priv = fi->priv;
        struct osmo_scu_prim *scu_prim;
        struct msgb *scu_msg;

@@ -523,12 +550,6 @@
        talloc_free(mgw_fsm_priv);
 }

-static void mgw_fsm_cleanup(struct osmo_fsm_inst *fi, enum osmo_fsm_term_cause 
cause)
-{
-       struct mgw_fsm_priv *mgw_fsm_priv = fi->priv;
-       mgw_fsm_priv_cleanup(mgw_fsm_priv);
-}
-
 static void mgw_fsm_pre_term(struct osmo_fsm_inst *fi, enum 
osmo_fsm_term_cause cause)
 {
        struct mgw_fsm_priv *mgw_fsm_priv = fi->priv;
@@ -659,11 +680,8 @@
 {
        static bool initialized = false;
        struct mgw_fsm_priv *mgw_fsm_priv;
-       struct osmo_sockaddr addr;
-       struct osmo_sockaddr_str addr_str;
-       RANAP_RAB_AssignmentRequestIEs_t *ies;
-       int rc;
        char fsm_name[255];
+       int rc;

        /* Initialize FSM if not done yet */
        if (!initialized) {
@@ -686,9 +704,6 @@
                OSMO_ASSERT(map->mgw_fi == NULL);
        }

-       mgw_fsm_priv = talloc_zero(map, struct mgw_fsm_priv);
-       mgw_fsm_priv->ranap_rab_ass_req_message = message;
-
        /* This FSM only supports RAB assignments with a single RAB assignment 
only. This limitation has been taken
         * into account under the assumption that voice calls typically require 
a single RAB only. Nevertheless, we
         * will block all incoming RAB assignments that try to assign more (or 
less) than one RAB. */
@@ -696,42 +711,21 @@
                LOGP(DMGW, LOGL_ERROR,
                     "mgw_fsm_alloc_and_handle_rab_ass_req() rua_ctx_id=%d, 
RAB-AssignmentRequest with more than one RAB assignment -- abort!\n",
                     map->rua_ctx_id);
-               goto error;
+               tx_release_req(map);
+               return -1;
        }

-       /* Parse the RAB Assignment Request now, if it is bad for some reason 
we will exit early and not bother with
-        * creating an FSM etc. */
-       ies = 
&mgw_fsm_priv->ranap_rab_ass_req_message->msg.raB_AssignmentRequestIEs;
-       rc = ranap_rab_ass_req_ies_extract_inet_addr(&addr, 
&mgw_fsm_priv->rab_id, ies, 0);
-       if (rc < 0) {
-               LOGP(DMGW, LOGL_ERROR,
-                    "mgw_fsm_alloc_and_handle_rab_ass_req() rua_ctx_id=%d, 
invalid RAB-AssignmentRequest -- abort!\n",
-                    map->rua_ctx_id);
-               goto error;
-       }
-
-       rc = osmo_sockaddr_str_from_sockaddr(&addr_str, &addr.u.sas);
-       if (rc < 0) {
-               LOGP(DMGW, LOGL_ERROR,
-                    "mgw_fsm_alloc_and_handle_rab_ass_req() rua_ctx_id=%d, 
Invalid RTP IP-address or Port in RAB-AssignmentRequest -- abort\n",
-                    map->rua_ctx_id);
-               goto error;
-       }
-       osmo_strlcpy(mgw_fsm_priv->msc_rtp_addr, addr_str.ip, 
sizeof(mgw_fsm_priv->msc_rtp_addr));
-       mgw_fsm_priv->msc_rtp_port = addr_str.port;
-
-       /* Allocate the FSM and start it. */
+       mgw_fsm_priv = talloc_zero(map, struct mgw_fsm_priv);
        mgw_fsm_priv->map = map;
+       mgw_fsm_priv->ranap_rab_ass_req_message = message;
+
+       /* Allocate FSM */
        snprintf(fsm_name, sizeof(fsm_name), "mgw-fsm-%u-%u", map->rua_ctx_id, 
mgw_fsm_priv->rab_id);
        map->mgw_fi = osmo_fsm_inst_alloc(&mgw_fsm, map, mgw_fsm_priv, 
LOGL_DEBUG, fsm_name);
-       mgw_fsm_state_chg(map->mgw_fi, MGW_ST_CRCX_HNB);

+       /* Start the FSM */
+       mgw_fsm_state_chg(map->mgw_fi, MGW_ST_CRCX_HNB);
        return 0;
-error:
-       /* Cleanup context and make sure that the call is cleared. */
-       mgw_fsm_priv_cleanup(mgw_fsm_priv);
-       tx_release_req(map);
-       return -EINVAL;
 }

 /*! Handlie RANAP RAB AssignmentResponse (deliver message, complete RTP stream 
switching).

--
To view, visit https://gerrit.osmocom.org/c/osmo-hnbgw/+/28284
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-hnbgw
Gerrit-Branch: master
Gerrit-Change-Id: I8883e737fa112cff57834abae7ef272388a54edb
Gerrit-Change-Number: 28284
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <[email protected]>
Gerrit-MessageType: newchange

Reply via email to