pespin has submitted this change. ( https://gerrit.osmocom.org/c/osmo-ggsn/+/38454?usp=email )
Change subject: Move apn allocation code out of vty file ......................................................................
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 --- M ggsn/ggsn.c M ggsn/ggsn_vty.c 2 files changed, 36 insertions(+), 30 deletions(-)
Approvals: Jenkins Builder: Verified osmith: Looks good to me, approved laforge: Looks good to me, but someone else must approve
diff --git a/ggsn/ggsn.c b/ggsn/ggsn.c index a6cfc58..9e33b50 100644 --- a/ggsn/ggsn.c +++ b/ggsn/ggsn.c @@ -94,6 +94,42 @@ } }
+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"); diff --git a/ggsn/ggsn_vty.c b/ggsn/ggsn_vty.c index da67591..82eff3e 100644 --- a/ggsn/ggsn_vty.c +++ b/ggsn/ggsn_vty.c @@ -90,36 +90,6 @@ 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 = {