Move apn allocation code out of vty file

The details of creation of data structures don't belong on the vty file.
While at it, split allocation code into its own function to quickly find
out where the allocation of the object happens.

Change-Id: If15a4158dd6599341017efd24dbf67ca565a7c34
This commit is contained in:
Pau Espin Pedrol
2024-10-17 18:49:59 +02:00
parent 8c015bd89a
commit ce691d8e64
2 changed files with 36 additions and 30 deletions

View File

@@ -94,6 +94,42 @@ static void pool_close_all_pdp(struct ippool_t *pool)
}
}
static struct apn_ctx *apn_alloc(struct ggsn_ctx *ggsn, const char *name)
{
struct apn_ctx *apn;
apn = talloc_zero(ggsn, struct apn_ctx);
OSMO_ASSERT(apn);
apn->ggsn = ggsn;
apn->cfg.name = talloc_strdup(apn, name);
apn->cfg.shutdown = true;
apn->cfg.tx_gpdu_seq = true;
INIT_LLIST_HEAD(&apn->cfg.name_list);
llist_add_tail(&apn->list, &ggsn->apn_list);
return apn;
}
struct apn_ctx *ggsn_find_apn(struct ggsn_ctx *ggsn, const char *name)
{
struct apn_ctx *apn;
llist_for_each_entry(apn, &ggsn->apn_list, list) {
if (!strcmp(apn->cfg.name, name))
return apn;
}
return NULL;
}
struct apn_ctx *ggsn_find_or_create_apn(struct ggsn_ctx *ggsn, const char *name)
{
struct apn_ctx *apn = ggsn_find_apn(ggsn, name);
if (!apn)
apn = apn_alloc(ggsn, name);
return apn;
}
int apn_stop(struct apn_ctx *apn)
{
LOGPAPN(LOGL_NOTICE, apn, "Stopping\n");

View File

@@ -90,36 +90,6 @@ struct ggsn_ctx *ggsn_find_or_create(void *ctx, const char *name)
return ggsn;
}
struct apn_ctx *ggsn_find_apn(struct ggsn_ctx *ggsn, const char *name)
{
struct apn_ctx *apn;
llist_for_each_entry(apn, &ggsn->apn_list, list) {
if (!strcmp(apn->cfg.name, name))
return apn;
}
return NULL;
}
struct apn_ctx *ggsn_find_or_create_apn(struct ggsn_ctx *ggsn, const char *name)
{
struct apn_ctx *apn = ggsn_find_apn(ggsn, name);
if (apn)
return apn;
apn = talloc_zero(ggsn, struct apn_ctx);
if (!apn)
return NULL;
apn->ggsn = ggsn;
apn->cfg.name = talloc_strdup(apn, name);
apn->cfg.shutdown = true;
apn->cfg.tx_gpdu_seq = true;
INIT_LLIST_HEAD(&apn->cfg.name_list);
llist_add_tail(&apn->list, &ggsn->apn_list);
return apn;
}
/* GGSN Node */
static struct cmd_node ggsn_node = {