ss7: Refactor osmo_ss7_asp_find_or_create()
Move allocation code to its own function. Simplify osmo_ss7_asp_find_or_create() code paths. Change-Id: Ibbf20c63fc1d2b22a7c5d750002f94795ee31f26
This commit is contained in:
parent
c086a8ed42
commit
5cf725b191
|
@ -1521,6 +1521,31 @@ osmo_ss7_asp_find(struct osmo_ss7_instance *inst, const char *name,
|
||||||
return asp;
|
return asp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct osmo_ss7_asp *
|
||||||
|
osmo_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)
|
||||||
|
{
|
||||||
|
struct osmo_ss7_asp *asp = talloc_zero(inst, struct osmo_ss7_asp);
|
||||||
|
asp->ctrg = rate_ctr_group_alloc(asp, &ss7_asp_rcgd, g_ss7_asp_rcg_idx++);
|
||||||
|
if (!asp->ctrg) {
|
||||||
|
talloc_free(asp);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
rate_ctr_group_set_name(asp->ctrg, name);
|
||||||
|
asp->inst = inst;
|
||||||
|
asp->cfg.remote.port = remote_port;
|
||||||
|
asp->cfg.local.port = local_port;
|
||||||
|
asp->cfg.proto = proto;
|
||||||
|
asp->cfg.name = talloc_strdup(asp, name);
|
||||||
|
llist_add_tail(&asp->list, &inst->asp_list);
|
||||||
|
|
||||||
|
/* The SUA code internally needs SCCP to work */
|
||||||
|
if (proto == OSMO_SS7_ASP_PROT_SUA)
|
||||||
|
osmo_ss7_ensure_sccp(inst);
|
||||||
|
return asp;
|
||||||
|
}
|
||||||
|
|
||||||
struct osmo_ss7_asp *
|
struct osmo_ss7_asp *
|
||||||
osmo_ss7_asp_find_or_create(struct osmo_ss7_instance *inst, const char *name,
|
osmo_ss7_asp_find_or_create(struct osmo_ss7_instance *inst, const char *name,
|
||||||
uint16_t remote_port, uint16_t local_port,
|
uint16_t remote_port, uint16_t local_port,
|
||||||
|
@ -1530,34 +1555,15 @@ osmo_ss7_asp_find_or_create(struct osmo_ss7_instance *inst, const char *name,
|
||||||
|
|
||||||
OSMO_ASSERT(ss7_initialized);
|
OSMO_ASSERT(ss7_initialized);
|
||||||
asp = osmo_ss7_asp_find_by_name(inst, name);
|
asp = osmo_ss7_asp_find_by_name(inst, name);
|
||||||
|
if (asp) {
|
||||||
if (asp && (asp->cfg.remote.port != remote_port ||
|
if (asp->cfg.remote.port != remote_port ||
|
||||||
asp->cfg.local.port != local_port ||
|
asp->cfg.local.port != local_port ||
|
||||||
asp->cfg.proto != proto))
|
asp->cfg.proto != proto)
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (!asp) {
|
|
||||||
/* FIXME: check if local port has SCTP? */
|
|
||||||
asp = talloc_zero(inst, struct osmo_ss7_asp);
|
|
||||||
asp->ctrg = rate_ctr_group_alloc(asp, &ss7_asp_rcgd, g_ss7_asp_rcg_idx++);
|
|
||||||
if (!asp->ctrg) {
|
|
||||||
talloc_free(asp);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
return asp;
|
||||||
rate_ctr_group_set_name(asp->ctrg, name);
|
|
||||||
asp->inst = inst;
|
|
||||||
asp->cfg.remote.port = remote_port;
|
|
||||||
asp->cfg.local.port = local_port;
|
|
||||||
asp->cfg.proto = proto;
|
|
||||||
asp->cfg.name = talloc_strdup(asp, name);
|
|
||||||
llist_add_tail(&asp->list, &inst->asp_list);
|
|
||||||
|
|
||||||
/* The SUA code internally needs SCCP to work */
|
|
||||||
if (proto == OSMO_SS7_ASP_PROT_SUA)
|
|
||||||
osmo_ss7_ensure_sccp(inst);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return asp;
|
|
||||||
|
return osmo_ss7_asp_alloc(inst, name, remote_port, local_port, proto);
|
||||||
}
|
}
|
||||||
|
|
||||||
void osmo_ss7_asp_destroy(struct osmo_ss7_asp *asp)
|
void osmo_ss7_asp_destroy(struct osmo_ss7_asp *asp)
|
||||||
|
|
Loading…
Reference in New Issue