pespin has submitted this change. ( https://gerrit.osmocom.org/c/osmo-ggsn/+/38455?usp=email )
Change subject: Move ggsn allocation code out of vty file ......................................................................
Move ggsn 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: Iaa4cd86c44957321c238d268ea62daafa1b79c69 --- M ggsn/ggsn.c M ggsn/ggsn_vty.c 2 files changed, 36 insertions(+), 33 deletions(-)
Approvals: Jenkins Builder: Verified laforge: Looks good to me, but someone else must approve osmith: Looks good to me, approved
diff --git a/ggsn/ggsn.c b/ggsn/ggsn.c index 9e33b50..8fa0f74 100644 --- a/ggsn/ggsn.c +++ b/ggsn/ggsn.c @@ -879,6 +879,42 @@ return sgsn_peer_handle_recovery(sgsn, pdp, recovery); }
+static struct ggsn_ctx *ggsn_alloc(void *ctx, const char *name) +{ + struct ggsn_ctx *ggsn; + + ggsn = talloc_zero(ctx, struct ggsn_ctx); + OSMO_ASSERT(ggsn); + + ggsn->cfg.name = talloc_strdup(ggsn, name); + ggsn->cfg.state_dir = talloc_strdup(ggsn, "/tmp"); + ggsn->cfg.shutdown = true; + INIT_LLIST_HEAD(&ggsn->apn_list); + INIT_LLIST_HEAD(&ggsn->sgsn_list); + + llist_add_tail(&ggsn->list, &g_ggsn_list); + return ggsn; +} + +struct ggsn_ctx *ggsn_find(const char *name) +{ + struct ggsn_ctx *ggsn; + + llist_for_each_entry(ggsn, &g_ggsn_list, list) { + if (!strcmp(ggsn->cfg.name, name)) + return ggsn; + } + return NULL; +} + +struct ggsn_ctx *ggsn_find_or_create(void *ctx, const char *name) +{ + struct ggsn_ctx *ggsn = ggsn_find(name); + if (!ggsn) + ggsn = ggsn_alloc(ctx, name); + return ggsn; +} + /* Start a given GGSN */ int ggsn_start(struct ggsn_ctx *ggsn) { diff --git a/ggsn/ggsn_vty.c b/ggsn/ggsn_vty.c index 82eff3e..68d2cdc 100644 --- a/ggsn/ggsn_vty.c +++ b/ggsn/ggsn_vty.c @@ -57,39 +57,6 @@ APN_NODE, };
-struct ggsn_ctx *ggsn_find(const char *name) -{ - struct ggsn_ctx *ggsn; - - llist_for_each_entry(ggsn, &g_ggsn_list, list) { - if (!strcmp(ggsn->cfg.name, name)) - return ggsn; - } - return NULL; -} - -struct ggsn_ctx *ggsn_find_or_create(void *ctx, const char *name) -{ - struct ggsn_ctx *ggsn; - - ggsn = ggsn_find(name); - if (ggsn) - return ggsn; - - ggsn = talloc_zero(ctx, struct ggsn_ctx); - if (!ggsn) - return NULL; - - ggsn->cfg.name = talloc_strdup(ggsn, name); - ggsn->cfg.state_dir = talloc_strdup(ggsn, "/tmp"); - ggsn->cfg.shutdown = true; - INIT_LLIST_HEAD(&ggsn->apn_list); - INIT_LLIST_HEAD(&ggsn->sgsn_list); - - llist_add_tail(&ggsn->list, &g_ggsn_list); - return ggsn; -} - /* GGSN Node */
static struct cmd_node ggsn_node = {