From 6d867d1d08490a270be86911b74fcf0a8cede44d Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Thu, 27 Sep 2018 01:21:45 +0200 Subject: cosmetic: allocate ss7->sccp in one common function Instead of allocating ss7->sccp in various places, unify that in one common function. We shouldn't spread the decision what to pass as priv pointer around everywhere. There is no functional difference. This is preparation for a patch where the sccp_instance gets allocated from the telnet VTY: I would prefer to hide all allocation details from that code; which also makes sense for the other callers of osmo_sccp_instance_create(). Change-Id: Ie912898c66d31ce4ac8eeeea5a6ddc3f821c06f7 --- include/osmocom/sigtran/osmo_ss7.h | 2 ++ src/osmo_ss7.c | 20 ++++++++++++++++---- src/sccp_user.c | 6 ++---- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/include/osmocom/sigtran/osmo_ss7.h b/include/osmocom/sigtran/osmo_ss7.h index a93c663..34d5408 100644 --- a/include/osmocom/sigtran/osmo_ss7.h +++ b/include/osmocom/sigtran/osmo_ss7.h @@ -111,6 +111,8 @@ int osmo_ss7_instance_set_pc_fmt(struct osmo_ss7_instance *inst, int osmo_ss7_instance_bind(struct osmo_ss7_instance *inst); int osmo_ss7_bind_all_instances(); +struct osmo_sccp_instance *osmo_ss7_ensure_sccp(struct osmo_ss7_instance *inst); + /*********************************************************************** * MTP Users (Users of MTP, such as SCCP or ISUP) ***********************************************************************/ diff --git a/src/osmo_ss7.c b/src/osmo_ss7.c index 025c21c..9805b3b 100644 --- a/src/osmo_ss7.c +++ b/src/osmo_ss7.c @@ -460,6 +460,18 @@ int osmo_ss7_bind_all_instances() return rc; } +/*! Allocate an SCCP instance, if not present yet. + * \returns inst->sccp. */ +struct osmo_sccp_instance *osmo_ss7_ensure_sccp(struct osmo_ss7_instance *inst) +{ + if (inst->sccp) + return inst->sccp; + + LOGSS7(inst, LOGL_NOTICE, "Creating SCCP instance\n"); + inst->sccp = osmo_sccp_instance_create(inst, NULL); + return inst->sccp; +} + /*********************************************************************** * MTP Users (Users of MTP, such as SCCP or ISUP) ***********************************************************************/ @@ -1169,8 +1181,8 @@ osmo_ss7_asp_find_or_create(struct osmo_ss7_instance *inst, const char *name, llist_add_tail(&asp->list, &inst->asp_list); /* The SUA code internally needs SCCP to work */ - if (proto == OSMO_SS7_ASP_PROT_SUA && !inst->sccp) - inst->sccp = osmo_sccp_instance_create(inst, NULL); + if (proto == OSMO_SS7_ASP_PROT_SUA) + osmo_ss7_ensure_sccp(inst); } return asp; @@ -1817,8 +1829,8 @@ osmo_ss7_xua_server_create(struct osmo_ss7_instance *inst, enum osmo_ss7_asp_pro llist_add_tail(&oxs->list, &inst->xua_servers); /* The SUA code internally needs SCCP to work */ - if (proto == OSMO_SS7_ASP_PROT_SUA && !inst->sccp) - inst->sccp = osmo_sccp_instance_create(inst, NULL); + if (proto == OSMO_SS7_ASP_PROT_SUA) + osmo_ss7_ensure_sccp(inst); return oxs; } diff --git a/src/sccp_user.c b/src/sccp_user.c index 99ed96e..020166d 100644 --- a/src/sccp_user.c +++ b/src/sccp_user.c @@ -480,9 +480,7 @@ osmo_sccp_simple_client_on_ss7_id(void *ctx, uint32_t ss7_id, const char *name, LOGP(DLSCCP, LOGL_NOTICE, "%s: Using ASP instance %s\n", name, asp->cfg.name); - /* Allocate SCCP instance */ - LOGP(DLSCCP, LOGL_NOTICE, "%s: Creating SCCP instance\n", name); - ss7->sccp = osmo_sccp_instance_create(ss7, NULL); + osmo_ss7_ensure_sccp(ss7); if (!ss7->sccp) goto out_asp; @@ -562,7 +560,7 @@ osmo_sccp_simple_server_on_ss7_id(void *ctx, uint32_t ss7_id, uint32_t pc, goto out_xs; /* Allocate SCCP stack */ - ss7->sccp = osmo_sccp_instance_create(ss7, NULL); + osmo_ss7_ensure_sccp(ss7); if (!ss7->sccp) goto out_xs; -- cgit v1.2.3