pespin has submitted this change. ( 
https://gerrit.osmocom.org/c/libosmo-sigtran/+/39395?usp=email )

Change subject: ipa: Split msgb generation into its own helper function
......................................................................

ipa: Split msgb generation into its own helper function

This allows having a clearer picture when comparing against other
protocol stacks like M3UA and SUA, since both have a sua_to_msg() and
m3ua_to_msg() functions (which in turn call xua_to_msg()).

This way ipa_tx_xua_as() also becomes much more similar to
m3ua_tx_xua_as() and sua_tx_xua_as().

While at it, also add extra logging to m3ua/sua_tx_xua_as() to also
provide AS context logging information when encoding fail.

Change-Id: Ic0a405ab4d1811efea137167dcb08c9308a4d7e7
---
M src/ipa.c
M src/m3ua.c
M src/sua.c
3 files changed, 29 insertions(+), 15 deletions(-)

Approvals:
  pespin: Looks good to me, approved
  osmith: Looks good to me, but someone else must approve
  fixeria: Looks good to me, but someone else must approve
  Jenkins Builder: Verified




diff --git a/src/ipa.c b/src/ipa.c
index d62d710..6ca5b50 100644
--- a/src/ipa.c
+++ b/src/ipa.c
@@ -52,12 +52,7 @@
 #include "ss7_internal.h"
 #include "xua_asp_fsm.h"

-
-/*! \brief Send a given xUA message via a given IPA "Application Server"
- *  \param[in] as Application Server through which to send \a xua
- *  \param[in] xua xUA message to be sent
- *  \return 0 on success; negative on error */
-int ipa_tx_xua_as(struct osmo_ss7_as *as, struct xua_msg *xua)
+static struct msgb *ipa_to_msg(struct xua_msg *xua)
 {
        struct xua_msg_part *data_ie;
        struct m3ua_data_hdr *data_hdr;
@@ -66,18 +61,16 @@
        const uint8_t *src;
        uint8_t *dst;

-       OSMO_ASSERT(as->cfg.proto == OSMO_SS7_ASP_PROT_IPA);
-
        /* we're actually only interested in the data part */
        data_ie = xua_msg_find_tag(xua, M3UA_IEI_PROT_DATA);
        if (!data_ie || data_ie->len < sizeof(struct m3ua_data_hdr))
-               return -1;
+               return NULL;
        data_hdr = (struct m3ua_data_hdr *) data_ie->dat;

        if (data_hdr->si != MTP_SI_SCCP) {
-               LOGPAS(as, DLSS7, LOGL_ERROR, "Cannot transmit non-SCCP SI (%u) 
to IPA peer\n",
-                       data_hdr->si);
-               return -1;
+               LOGP(DLSS7, LOGL_ERROR, "Cannot transmit non-SCCP SI (%u) to 
IPA peer\n",
+                    data_hdr->si);
+               return NULL;
        }

        /* and even the data part still has the header prepended */
@@ -87,7 +80,7 @@
        /* sufficient headroom for osmo_ipa_msg_push_header() */
        msg = ipa_msg_alloc(16);
        if (!msg)
-               return -1;
+               return NULL;

        dst = msgb_put(msg, src_len);
        memcpy(dst, src, src_len);
@@ -95,6 +88,23 @@
        /* TODO: if we ever need something beyond SCCP, we can use the
         * M3UA SIO to determine the protocol */
        osmo_ipa_msg_push_header(msg, IPAC_PROTO_SCCP);
+       return msg;
+}
+
+/*! \brief Send a given xUA message via a given IPA "Application Server"
+ *  \param[in] as Application Server through which to send \a xua
+ *  \param[in] xua xUA message to be sent
+ *  \return 0 on success; negative on error */
+int ipa_tx_xua_as(struct osmo_ss7_as *as, struct xua_msg *xua)
+{
+       struct msgb *msg;
+       OSMO_ASSERT(as->cfg.proto == OSMO_SS7_ASP_PROT_IPA);
+
+       msg = ipa_to_msg(xua);
+       if (!msg) {
+               LOGPAS(as, DLSS7, LOGL_ERROR, "Error encoding IPA Msg\n");
+               return -1;
+       }

        return xua_as_transmit_msg(as, msg);
 }
diff --git a/src/m3ua.c b/src/m3ua.c
index be1f167..5f94674 100644
--- a/src/m3ua.c
+++ b/src/m3ua.c
@@ -522,8 +522,10 @@
                xua_msg_add_u32(xua, M3UA_IEI_ROUTE_CTX, 
as->cfg.routing_key.context);

        msg = m3ua_to_msg(xua);
-       if (!msg)
+       if (!msg) {
+               LOGPAS(as, DLM3UA, LOGL_ERROR, "Error encoding M3UA Msg\n");
                return -1;
+       }

        /* send the msg to the AS for transmission.  The AS FSM might
         * (depending on its state) enqueue it before transmission */
diff --git a/src/sua.c b/src/sua.c
index c7bde24..e81c471 100644
--- a/src/sua.c
+++ b/src/sua.c
@@ -317,8 +317,10 @@
                xua_msg_add_u32(xua, SUA_IEI_ROUTE_CTX, 
as->cfg.routing_key.context);

        msg = sua_to_msg(xua);
-       if (!msg)
+       if (!msg) {
+               LOGPAS(as, DLSUA, LOGL_ERROR, "Error encoding SUA Msg\n");
                return -1;
+       }

        /* send the msg to the AS for transmission.  The AS FSM might
         * (depending on its state) enqueue it before transmission */

--
To view, visit https://gerrit.osmocom.org/c/libosmo-sigtran/+/39395?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: libosmo-sigtran
Gerrit-Branch: master
Gerrit-Change-Id: Ic0a405ab4d1811efea137167dcb08c9308a4d7e7
Gerrit-Change-Number: 39395
Gerrit-PatchSet: 2
Gerrit-Owner: pespin <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <[email protected]>
Gerrit-Reviewer: osmith <[email protected]>
Gerrit-Reviewer: pespin <[email protected]>

Reply via email to