neels has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/osmo-hlr/+/15915 )


Change subject: add osmo_gsup_msgb_alloc()
......................................................................

add osmo_gsup_msgb_alloc()

Throughout osmo-hlr's code, the GSUP msgb allocation is duplicated as:

  msgb_alloc_headroom(1024+16, 16, "foo");

Instead, use one common function to keep the magic numbers in one place.

Change-Id: I40e99b5bc4fd8f750da7643c03b2119ac3bfd95e
---
M src/gsup_server.c
M src/gsup_server.h
M src/hlr.c
M src/hlr_ussd.c
M src/luop.c
5 files changed, 17 insertions(+), 9 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-hlr refs/changes/15/15915/1

diff --git a/src/gsup_server.c b/src/gsup_server.c
index e75bbd7..2870e9d 100644
--- a/src/gsup_server.c
+++ b/src/gsup_server.c
@@ -30,6 +30,13 @@
 #include "gsup_server.h"
 #include "gsup_router.h"

+struct msgb *osmo_gsup_msgb_alloc(const char *label)
+{
+       struct msgb *msg = msgb_alloc_headroom(1024+16, 16, label);
+       OSMO_ASSERT(msg);
+       return msg;
+}
+
 static void osmo_gsup_server_send(struct osmo_gsup_conn *conn,
                             int proto_ext, struct msgb *msg_tx)
 {
diff --git a/src/gsup_server.h b/src/gsup_server.h
index 9c4d483..14f5013 100644
--- a/src/gsup_server.h
+++ b/src/gsup_server.h
@@ -47,6 +47,7 @@
        bool supports_ps; /* client supports OSMO_GSUP_CN_DOMAIN_PS */
 };

+struct msgb *osmo_gsup_msgb_alloc(const char *label);

 int osmo_gsup_conn_send(struct osmo_gsup_conn *conn, struct msgb *msg);
 int osmo_gsup_conn_ccm_get(const struct osmo_gsup_conn *clnt, uint8_t **addr,
diff --git a/src/hlr.c b/src/hlr.c
index 6bfc141..aef890e 100644
--- a/src/hlr.c
+++ b/src/hlr.c
@@ -128,7 +128,7 @@
                }

                /* Send ISD to MSC/SGSN */
-               msg_out = msgb_alloc_headroom(1024+16, 16, "GSUP ISD UPDATE");
+               msg_out = osmo_gsup_msgb_alloc("GSUP ISD UPDATE");
                if (msg_out == NULL) {
                        LOGP(DLGSUP, LOGL_ERROR,
                               "IMSI='%s': Cannot notify GSUP client; could not 
allocate msg buffer "
@@ -271,7 +271,7 @@
                gsup_out.num_auth_vectors = rc;
        }

-       msg_out = msgb_alloc_headroom(1024+16, 16, "GSUP AUC response");
+       msg_out = osmo_gsup_msgb_alloc("GSUP AUC response");
        osmo_gsup_encode(msg_out, &gsup_out);
        return osmo_gsup_conn_send(conn, msg_out);
 }
@@ -451,7 +451,7 @@
                gsup_reply.cause = GMM_CAUSE_NET_FAIL;
        }

-       msg_out = msgb_alloc_headroom(1024+16, 16, "GSUP AUC response");
+       msg_out = osmo_gsup_msgb_alloc("GSUP AUC response");
        osmo_gsup_encode(msg_out, &gsup_reply);
        return osmo_gsup_conn_send(conn, msg_out);
 }
@@ -466,7 +466,7 @@
        OSMO_STRLCPY_ARRAY(gsup_reply.imsi, imsi);
        gsup_reply.message_type = type_err;
        gsup_reply.cause = err_cause;
-       msg_out = msgb_alloc_headroom(1024+16, 16, "GSUP ERR response");
+       msg_out = osmo_gsup_msgb_alloc("GSUP ERR response");
        OSMO_ASSERT(msg_out);
        osmo_gsup_encode(msg_out, &gsup_reply);
        LOGP(DMAIN, LOGL_NOTICE, "Tx %s\n", 
osmo_gsup_message_type_name(type_err));
@@ -525,7 +525,7 @@
        /* Accept all IMEIs */
        gsup_reply.imei_result = OSMO_GSUP_IMEI_RESULT_ACK;
        gsup_reply.message_type = OSMO_GSUP_MSGT_CHECK_IMEI_RESULT;
-       msg_out = msgb_alloc_headroom(1024+16, 16, "GSUP Check_IMEI response");
+       msg_out = osmo_gsup_msgb_alloc("GSUP Check_IMEI response");
        memcpy(gsup_reply.imsi, gsup->imsi, sizeof(gsup_reply.imsi));
        osmo_gsup_encode(msg_out, &gsup_reply);
        return osmo_gsup_conn_send(conn, msg_out);
@@ -591,7 +591,7 @@
 end:
        /* Send error back to source */
        if (ret) {
-               struct msgb *msg_err = msgb_alloc_headroom(1024+16, 16, "GSUP 
forward ERR response");
+               struct msgb *msg_err = osmo_gsup_msgb_alloc("GSUP forward ERR 
response");
                OSMO_ASSERT(msg_err);
                gsup_err->message_type = OSMO_GSUP_MSGT_E_ROUTING_ERROR;
                osmo_gsup_encode(msg_err, gsup_err);
diff --git a/src/hlr_ussd.c b/src/hlr_ussd.c
index 1568815..be0fee0 100644
--- a/src/hlr_ussd.c
+++ b/src/hlr_ussd.c
@@ -464,7 +464,7 @@
        }

        if (is_euse_originated) {
-               msg_out = msgb_alloc_headroom(1024+16, 16, "GSUP USSD FW");
+               msg_out = osmo_gsup_msgb_alloc("GSUP USSD FW");
                OSMO_ASSERT(msg_out);
                /* Received from EUSE, Forward to VLR */
                osmo_gsup_encode(msg_out, gsup);
@@ -481,7 +481,7 @@
                                LOGPSS(ss, LOGL_ERROR, "Cannot find conn for 
EUSE %s\n", addr);
                                ss_tx_error(ss, req->invoke_id, 
GSM0480_ERR_CODE_SYSTEM_FAILURE);
                        } else {
-                               msg_out = msgb_alloc_headroom(1024+16, 16, 
"GSUP USSD FW");
+                               msg_out = osmo_gsup_msgb_alloc("GSUP USSD FW");
                                OSMO_ASSERT(msg_out);
                                osmo_gsup_encode(msg_out, gsup);
                                osmo_gsup_conn_send(conn, msg_out);
diff --git a/src/luop.c b/src/luop.c
index aff4d81..75f021f 100644
--- a/src/luop.c
+++ b/src/luop.c
@@ -50,7 +50,7 @@
 {
        struct msgb *msg_out;

-       msg_out = msgb_alloc_headroom(1024+16, 16, "GSUP LUOP");
+       msg_out = osmo_gsup_msgb_alloc("GSUP LUOP");
        OSMO_ASSERT(msg_out);
        osmo_gsup_encode(msg_out, gsup);
 

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

Gerrit-Project: osmo-hlr
Gerrit-Branch: master
Gerrit-Change-Id: I40e99b5bc4fd8f750da7643c03b2119ac3bfd95e
Gerrit-Change-Number: 15915
Gerrit-PatchSet: 1
Gerrit-Owner: neels <nhofm...@sysmocom.de>
Gerrit-MessageType: newchange

Reply via email to