pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmo-sigtran/+/43225?usp=email )
Change subject: xua_snm: constify xua_msg param in xua_snm_rx_* ......................................................................
xua_snm: constify xua_msg param in xua_snm_rx_*
There's no need to allocate talloc tons of times in format_affected_pcs(), which morever requrire the xua_msg pointer to be writable.
Change-Id: I3e5844a6f0d40c1df3ae31955bb8b24d891d86b1 --- M src/xua_internal.h M src/xua_snm.c 2 files changed, 24 insertions(+), 21 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmo-sigtran refs/changes/25/43225/1
diff --git a/src/xua_internal.h b/src/xua_internal.h index 5195b35..0317669 100644 --- a/src/xua_internal.h +++ b/src/xua_internal.h @@ -68,11 +68,11 @@ const uint32_t *aff_pc, unsigned int num_aff_pc, const char *info_str, bool available);
-void xua_snm_rx_daud(struct osmo_ss7_asp *asp, struct xua_msg *xua); -void xua_snm_rx_duna(struct osmo_ss7_asp *asp, struct osmo_ss7_as *as, struct xua_msg *xua); -void xua_snm_rx_dava(struct osmo_ss7_asp *asp, struct osmo_ss7_as *as, struct xua_msg *xua); -void xua_snm_rx_dupu(struct osmo_ss7_asp *asp, struct osmo_ss7_as *as, struct xua_msg *xua); -void xua_snm_rx_scon(struct osmo_ss7_asp *asp, struct osmo_ss7_as *as, struct xua_msg *xua); +void xua_snm_rx_daud(struct osmo_ss7_asp *asp, const struct xua_msg *xua); +void xua_snm_rx_duna(struct osmo_ss7_asp *asp, struct osmo_ss7_as *as, const struct xua_msg *xua); +void xua_snm_rx_dava(struct osmo_ss7_asp *asp, struct osmo_ss7_as *as, const struct xua_msg *xua); +void xua_snm_rx_dupu(struct osmo_ss7_asp *asp, struct osmo_ss7_as *as, const struct xua_msg *xua); +void xua_snm_rx_scon(struct osmo_ss7_asp *asp, struct osmo_ss7_as *as, const struct xua_msg *xua); int m3ua_rx_msg(struct osmo_ss7_asp *asp, struct msgb *msg);
struct msgb *m3ua_msgb_alloc(const char *name); diff --git a/src/xua_snm.c b/src/xua_snm.c index 2abc42e..03addcf 100644 --- a/src/xua_snm.c +++ b/src/xua_snm.c @@ -48,24 +48,27 @@ osmo_static_assert(M3UA_IEI_ROUTE_CTX == SUA_IEI_ROUTE_CTX, _sa_rctx); osmo_static_assert(M3UA_IEI_INFO_STRING == SUA_IEI_INFO_STRING, _sa_inf_str);
-static const char *format_affected_pcs_c(void *ctx, const struct osmo_ss7_instance *s7i, - const struct xua_msg_part *ie_aff_pc) +#define UINT32_MAX_DIGITS 10 +#define AFFECTED_PCS_MAX_LEN ((2 + MAX_PC_STR_LEN + 1 + UINT32_MAX_DIGITS) * OSMO_SS7_MAX_RCTX_COUNT + 1) +static const char *format_affected_pcs(const struct osmo_ss7_instance *s7i, const struct xua_msg_part *ie_aff_pc) { + static char buf[AFFECTED_PCS_MAX_LEN]; + struct osmo_strbuf sb = { .buf = buf, .len = sizeof(buf) }; const uint32_t *aff_pc = (const uint32_t *) ie_aff_pc->dat; unsigned int num_aff_pc = ie_aff_pc->len / sizeof(uint32_t); - char *out = talloc_strdup(ctx, ""); - int i; + unsigned int i;
+ buf[0] = '\0'; for (i = 0; i < num_aff_pc; i++) { uint32_t _aff_pc = ntohl(aff_pc[i]); uint32_t pc = _aff_pc & 0xffffff; uint8_t mask = _aff_pc >> 24;
/* append point code + mask */ - out = talloc_asprintf_append(out, "%s%s/%u", i == 0 ? "" : ", ", - osmo_ss7_pointcode_print(s7i, pc), mask); + OSMO_STRBUF_PRINTF(sb, "%s%s/%u", i == 0 ? "" : ", ", + osmo_ss7_pointcode_print(s7i, pc), mask); } - return out; + return buf; }
void xua_tx_snm_available(struct osmo_ss7_asp *asp, const uint32_t *rctx, unsigned int num_rctx, @@ -405,7 +408,7 @@ }
/* receive DAUD from ASP; pc is 'affected PC' IE with mask in network byte order! */ -void xua_snm_rx_daud(struct osmo_ss7_asp *asp, struct xua_msg *xua) +void xua_snm_rx_daud(struct osmo_ss7_asp *asp, const struct xua_msg *xua) { struct xua_msg_part *ie_aff_pc = xua_msg_find_tag(xua, M3UA_IEI_AFFECTED_PC); const char *info_str = xua_msg_get_str(xua, M3UA_IEI_INFO_STRING); @@ -424,7 +427,7 @@ num_rctx = ss7_asp_get_all_rctx_be(asp, rctx, ARRAY_SIZE(rctx), NULL);
LOGPASP(asp, log_ss, LOGL_INFO, "Rx DAUD(%s) for %s\n", info_str ? info_str : "", - format_affected_pcs_c(xua, asp->inst, ie_aff_pc)); + format_affected_pcs(asp->inst, ie_aff_pc));
/* iterate over list of point codes, generate DAVA/DUPU */ for (i = 0; i < num_aff_pc; i++) { @@ -484,7 +487,7 @@ }
/* an incoming xUA DUNA was received from a remote SG */ -void xua_snm_rx_duna(struct osmo_ss7_asp *asp, struct osmo_ss7_as *as, struct xua_msg *xua) +void xua_snm_rx_duna(struct osmo_ss7_asp *asp, struct osmo_ss7_as *as, const struct xua_msg *xua) { struct xua_msg_part *ie_aff_pc = xua_msg_find_tag(xua, M3UA_IEI_AFFECTED_PC); struct xua_msg_part *ie_ssn = xua_msg_find_tag(xua, SUA_IEI_SSN); @@ -497,7 +500,7 @@ OSMO_ASSERT(asp->cfg.role == OSMO_SS7_ASP_ROLE_ASP);
LOGPASP(asp, log_ss, LOGL_NOTICE, "Rx DUNA(%s) for %s\n", info_str ? info_str : "", - format_affected_pcs_c(xua, asp->inst, ie_aff_pc)); + format_affected_pcs(asp->inst, ie_aff_pc));
if (asp->cfg.proto == OSMO_SS7_ASP_PROT_SUA && ie_ssn) { /* when the SSN is included, DUNA corresponds to the SCCP N-STATE primitive */ @@ -517,7 +520,7 @@ }
/* an incoming xUA DAVA was received from a remote SG */ -void xua_snm_rx_dava(struct osmo_ss7_asp *asp, struct osmo_ss7_as *as, struct xua_msg *xua) +void xua_snm_rx_dava(struct osmo_ss7_asp *asp, struct osmo_ss7_as *as, const struct xua_msg *xua) { struct xua_msg_part *ie_aff_pc = xua_msg_find_tag(xua, M3UA_IEI_AFFECTED_PC); struct xua_msg_part *ie_ssn = xua_msg_find_tag(xua, SUA_IEI_SSN); @@ -530,7 +533,7 @@ OSMO_ASSERT(asp->cfg.role == OSMO_SS7_ASP_ROLE_ASP);
LOGPASP(asp, log_ss, LOGL_NOTICE, "Rx DAVA(%s) for %s\n", info_str ? info_str : "", - format_affected_pcs_c(xua, asp->inst, ie_aff_pc)); + format_affected_pcs(asp->inst, ie_aff_pc));
if (asp->cfg.proto == OSMO_SS7_ASP_PROT_SUA && ie_ssn) { /* when the SSN is included, DAVA corresponds to the SCCP N-STATE primitive */ @@ -550,7 +553,7 @@ }
/* an incoming SUA/M3UA DUPU was received from a remote SG */ -void xua_snm_rx_dupu(struct osmo_ss7_asp *asp, struct osmo_ss7_as *as, struct xua_msg *xua) +void xua_snm_rx_dupu(struct osmo_ss7_asp *asp, struct osmo_ss7_as *as, const struct xua_msg *xua) { uint32_t aff_pc = xua_msg_get_u32(xua, M3UA_IEI_AFFECTED_PC); const char *info_str = xua_msg_get_str(xua, M3UA_IEI_INFO_STRING); @@ -583,7 +586,7 @@ }
/* an incoming SUA/M3UA SCON was received from a remote ASP/SG/IPSP */ -void xua_snm_rx_scon(struct osmo_ss7_asp *asp, struct osmo_ss7_as *as, struct xua_msg *xua) +void xua_snm_rx_scon(struct osmo_ss7_asp *asp, struct osmo_ss7_as *as, const struct xua_msg *xua) { struct xua_msg_part *ie_aff_pc = xua_msg_find_tag(xua, M3UA_IEI_AFFECTED_PC); const char *info_str = xua_msg_get_str(xua, M3UA_IEI_INFO_STRING); @@ -595,7 +598,7 @@ OSMO_ASSERT(ie_aff_pc);
LOGPASP(asp, log_ss, LOGL_NOTICE, "RX SCON(%s) for %s level=%u\n", info_str ? info_str : "", - format_affected_pcs_c(xua, asp->inst, ie_aff_pc), cong_level ? *cong_level : 0); + format_affected_pcs(asp->inst, ie_aff_pc), cong_level ? *cong_level : 0);
xua_snm_scon(as, (const uint32_t *) ie_aff_pc->dat, ie_aff_pc->len / sizeof(uint32_t), concerned_dpc, (const uint8_t *) cong_level, info_str);