aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2023-09-29 17:26:05 +0200
committerPau Espin Pedrol <pespin@sysmocom.de>2023-09-29 17:36:32 +0200
commite39a1047270f49d849754cc5c931cdce4c451b4d (patch)
tree0974b1deb769514f8917b5ca5b0d3b19b5afa174
parentadbf243e1b25c8c34a7e462f0afb078fc3105d15 (diff)
Factor our osmo_ss7_as allocation to its own function
This makes it easier to find out where the AS struct is allocated, plus also split between inst code looking up + checking + allocating and the code doing the allocation and initialization of the AS. Change-Id: Ie237ec8ac4b2e15b76fce3b3a56f47a59fdcc76e
-rw-r--r--src/osmo_ss7.c47
-rw-r--r--src/ss7_internal.h3
2 files changed, 35 insertions, 15 deletions
diff --git a/src/osmo_ss7.c b/src/osmo_ss7.c
index 9265898..1e8bcfb 100644
--- a/src/osmo_ss7.c
+++ b/src/osmo_ss7.c
@@ -954,6 +954,37 @@ struct osmo_ss7_as *osmo_ss7_as_find_by_proto(struct osmo_ss7_instance *inst,
return as_without_asp;
}
+/*! \brief Allocate an Application Server
+ * \param[in] inst SS7 Instance on which we operate
+ * \param[in] name Name of Application Server
+ * \param[in] proto Protocol of Application Server
+ * \returns pointer to Application Server on success; NULL otherwise */
+struct osmo_ss7_as *ss7_as_alloc(struct osmo_ss7_instance *inst, const char *name,
+ enum osmo_ss7_asp_protocol proto)
+{
+ struct osmo_ss7_as *as;
+
+ as = talloc_zero(inst, struct osmo_ss7_as);
+ if (!as)
+ return NULL;
+ as->ctrg = rate_ctr_group_alloc(as, &ss7_as_rcgd, g_ss7_as_rcg_idx++);
+ if (!as->ctrg) {
+ talloc_free(as);
+ return NULL;
+ }
+ rate_ctr_group_set_name(as->ctrg, name);
+ as->inst = inst;
+ as->cfg.name = talloc_strdup(as, name);
+ as->cfg.proto = proto;
+ as->cfg.mode = OSMO_SS7_AS_TMOD_OVERRIDE;
+ as->cfg.recovery_timeout_msec = 2000;
+ as->cfg.routing_key.l_rk_id = find_free_l_rk_id(inst);
+ as->fi = xua_as_fsm_start(as, LOGL_DEBUG);
+ llist_add_tail(&as->list, &inst->as_list);
+
+ return as;
+}
+
/*! \brief Find or Create Application Server
* \param[in] inst SS7 Instance on which we operate
* \param[in] name Name of Application Server
@@ -972,23 +1003,9 @@ osmo_ss7_as_find_or_create(struct osmo_ss7_instance *inst, const char *name,
return NULL;
if (!as) {
- as = talloc_zero(inst, struct osmo_ss7_as);
+ as = ss7_as_alloc(inst, name, proto);
if (!as)
return NULL;
- as->ctrg = rate_ctr_group_alloc(as, &ss7_as_rcgd, g_ss7_as_rcg_idx++);
- if (!as->ctrg) {
- talloc_free(as);
- return NULL;
- }
- rate_ctr_group_set_name(as->ctrg, name);
- as->inst = inst;
- as->cfg.name = talloc_strdup(as, name);
- as->cfg.proto = proto;
- as->cfg.mode = OSMO_SS7_AS_TMOD_OVERRIDE;
- as->cfg.recovery_timeout_msec = 2000;
- as->cfg.routing_key.l_rk_id = find_free_l_rk_id(inst);
- as->fi = xua_as_fsm_start(as, LOGL_DEBUG);
- llist_add_tail(&as->list, &inst->as_list);
LOGPAS(as, DLSS7, LOGL_INFO, "Created AS\n");
}
diff --git a/src/ss7_internal.h b/src/ss7_internal.h
index d05b16e..4539609 100644
--- a/src/ss7_internal.h
+++ b/src/ss7_internal.h
@@ -9,6 +9,9 @@ extern bool ss7_initialized;
bool ss7_ipv6_sctp_supported(const char *host, bool bind);
+struct osmo_ss7_as *ss7_as_alloc(struct osmo_ss7_instance *inst, const char *name,
+ enum osmo_ss7_asp_protocol proto);
+
struct osmo_ss7_asp *ss7_asp_alloc(struct osmo_ss7_instance *inst, const char *name,
uint16_t remote_port, uint16_t local_port,
enum osmo_ss7_asp_protocol proto);