aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2019-10-30 02:08:28 +0100
committerOliver Smith <osmith@sysmocom.de>2019-11-25 13:13:19 +0100
commita7d0f87eb7587a8ea28e87dca1c4d5f829f52b32 (patch)
tree48026adc78769b39e26946d737f73724d5951f53
parent981e126686e1e3e05192b8d34b95be4935dfb8f0 (diff)
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
-rw-r--r--include/osmocom/hlr/gsup_server.h1
-rw-r--r--src/gsup_server.c7
-rw-r--r--src/hlr.c14
-rw-r--r--src/hlr_ussd.c6
-rw-r--r--src/luop.c3
5 files changed, 17 insertions, 14 deletions
diff --git a/include/osmocom/hlr/gsup_server.h b/include/osmocom/hlr/gsup_server.h
index 9c4d483..14f5013 100644
--- a/include/osmocom/hlr/gsup_server.h
+++ b/include/osmocom/hlr/gsup_server.h
@@ -47,6 +47,7 @@ struct osmo_gsup_conn {
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/gsup_server.c b/src/gsup_server.c
index bee6aef..ed1b285 100644
--- a/src/gsup_server.c
+++ b/src/gsup_server.c
@@ -30,6 +30,13 @@
#include <osmocom/hlr/gsup_server.h>
#include <osmocom/hlr/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/hlr.c b/src/hlr.c
index 0970bb1..1638e67 100644
--- a/src/hlr.c
+++ b/src/hlr.c
@@ -128,7 +128,7 @@ osmo_hlr_subscriber_update_notify(struct hlr_subscriber *subscr)
}
/* 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 @@ static int rx_send_auth_info(struct osmo_gsup_conn *conn,
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 @@ static int rx_purge_ms_req(struct osmo_gsup_conn *conn,
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,8 +466,7 @@ static int gsup_send_err_reply(struct osmo_gsup_conn *conn, const char *imsi,
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");
- OSMO_ASSERT(msg_out);
+ msg_out = osmo_gsup_msgb_alloc("GSUP ERR response");
osmo_gsup_encode(msg_out, &gsup_reply);
LOGP(DMAIN, LOGL_NOTICE, "Tx %s\n", osmo_gsup_message_type_name(type_err));
return osmo_gsup_conn_send(conn, msg_out);
@@ -525,7 +524,7 @@ static int rx_check_imei_req(struct osmo_gsup_conn *conn, const struct osmo_gsup
/* 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,8 +590,7 @@ static int read_cb_forward(struct osmo_gsup_conn *conn, struct msgb *msg, const
end:
/* Send error back to source */
if (ret) {
- struct msgb *msg_err = msgb_alloc_headroom(1024+16, 16, "GSUP forward ERR response");
- OSMO_ASSERT(msg_err);
+ struct msgb *msg_err = osmo_gsup_msgb_alloc("GSUP forward ERR response");
gsup_err->message_type = OSMO_GSUP_MSGT_E_ROUTING_ERROR;
osmo_gsup_encode(msg_err, gsup_err);
LOGP_GSUP_FWD(gsup_err, LOGL_NOTICE, "Tx %s\n", osmo_gsup_message_type_name(gsup_err->message_type));
diff --git a/src/hlr_ussd.c b/src/hlr_ussd.c
index 00023ba..8cdc15c 100644
--- a/src/hlr_ussd.c
+++ b/src/hlr_ussd.c
@@ -464,8 +464,7 @@ static int handle_ussd(struct osmo_gsup_conn *conn, struct ss_session *ss,
}
if (is_euse_originated) {
- msg_out = msgb_alloc_headroom(1024+16, 16, "GSUP USSD FW");
- OSMO_ASSERT(msg_out);
+ msg_out = osmo_gsup_msgb_alloc("GSUP USSD FW");
/* Received from EUSE, Forward to VLR */
osmo_gsup_encode(msg_out, gsup);
ss_gsup_send(ss, conn->server, msg_out);
@@ -481,8 +480,7 @@ static int handle_ussd(struct osmo_gsup_conn *conn, struct ss_session *ss,
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");
- OSMO_ASSERT(msg_out);
+ msg_out = osmo_gsup_msgb_alloc("GSUP USSD FW");
osmo_gsup_encode(msg_out, gsup);
osmo_gsup_conn_send(conn, msg_out);
}
diff --git a/src/luop.c b/src/luop.c
index 652ce0d..1a2f854 100644
--- a/src/luop.c
+++ b/src/luop.c
@@ -50,8 +50,7 @@ static void _luop_tx_gsup(struct lu_operation *luop,
{
struct msgb *msg_out;
- msg_out = msgb_alloc_headroom(1024+16, 16, "GSUP LUOP");
- OSMO_ASSERT(msg_out);
+ msg_out = osmo_gsup_msgb_alloc("GSUP LUOP");
osmo_gsup_encode(msg_out, gsup);
osmo_gsup_addr_send(luop->gsup_server, luop->peer,