pespin has submitted this change. ( https://gerrit.osmocom.org/c/osmo-sgsn/+/30890 )
Change subject: gtp_{ggsn,mme}: Allocate contexts under struct sgsn_instance ......................................................................
gtp_{ggsn,mme}: Allocate contexts under struct sgsn_instance
This way apns are managed by the lifcycle of the main global struct sgsn_instance automatically.
Change-Id: Ie65d59632a368c6957c33dca64e856ace792b2c6 --- M include/osmocom/sgsn/gtp_ggsn.h M src/sgsn/gprs_sgsn.c M src/sgsn/gprs_sm.c M src/sgsn/gtp_ggsn.c M src/sgsn/gtp_mme.c M src/sgsn/sgsn_libgtp.c M src/sgsn/sgsn_vty.c M tests/sgsn/sgsn_test.c 8 files changed, 25 insertions(+), 26 deletions(-)
Approvals: Jenkins Builder: Verified fixeria: Looks good to me, approved daniel: Looks good to me, but someone else must approve
diff --git a/include/osmocom/sgsn/gtp_ggsn.h b/include/osmocom/sgsn/gtp_ggsn.h index 224fa35..6afb866 100644 --- a/include/osmocom/sgsn/gtp_ggsn.h +++ b/include/osmocom/sgsn/gtp_ggsn.h @@ -10,6 +10,7 @@
struct gsn_t; struct sgsn_pdp_ctx; +struct sgsn_instance;
struct sgsn_ggsn_ctx { struct llist_head list; @@ -22,11 +23,11 @@ struct osmo_timer_list echo_timer; unsigned int echo_interval; }; -struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_alloc(uint32_t id); +struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_alloc(struct sgsn_instance *sgsn, uint32_t id); void sgsn_ggsn_ctx_free(struct sgsn_ggsn_ctx *ggc); -struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_by_id(uint32_t id); -struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_by_addr(struct in_addr *addr); -struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_find_alloc(uint32_t id); +struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_by_id(struct sgsn_instance *sgsn, uint32_t id); +struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_by_addr(struct sgsn_instance *sgsn, struct in_addr *addr); +struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_find_alloc(struct sgsn_instance *sgsn, uint32_t id); void sgsn_ggsn_ctx_drop_pdp(struct sgsn_pdp_ctx *pctx); int sgsn_ggsn_ctx_drop_all_pdp_except(struct sgsn_ggsn_ctx *ggsn, struct sgsn_pdp_ctx *except); int sgsn_ggsn_ctx_drop_all_pdp(struct sgsn_ggsn_ctx *ggsn); diff --git a/src/sgsn/gprs_sgsn.c b/src/sgsn/gprs_sgsn.c index 42d1ece..8c2734b 100644 --- a/src/sgsn/gprs_sgsn.c +++ b/src/sgsn/gprs_sgsn.c @@ -713,11 +713,11 @@ ggsn = apn_ctx->ggsn; } else if (llist_empty(&sgsn->apn_list)) { /* No configuration -> use GGSN 0 */ - ggsn = sgsn_ggsn_ctx_by_id(0); + ggsn = sgsn_ggsn_ctx_by_id(sgsn, 0); } else if (allow_any_apn && (selected_apn_str == NULL || strlen(selected_apn_str) == 0)) { /* No APN given and no default configuration -> Use GGSN 0 */ - ggsn = sgsn_ggsn_ctx_by_id(0); + ggsn = sgsn_ggsn_ctx_by_id(sgsn, 0); } else { /* No matching configuration found */ LOGMMCTXP(LOGL_NOTICE, mmctx, diff --git a/src/sgsn/gprs_sm.c b/src/sgsn/gprs_sm.c index 157e279..184350d 100644 --- a/src/sgsn/gprs_sm.c +++ b/src/sgsn/gprs_sm.c @@ -378,7 +378,7 @@ goto reject_due_failure; }
- ggsn = sgsn_ggsn_ctx_alloc(UINT32_MAX); + ggsn = sgsn_ggsn_ctx_alloc(sgsn, UINT32_MAX); if (!ggsn) { LOGMMCTXP(LOGL_ERROR, lookup->mmctx, "Failed to create ggsn.\n"); goto reject_due_failure; diff --git a/src/sgsn/gtp_ggsn.c b/src/sgsn/gtp_ggsn.c index be07d13..b43fb25 100644 --- a/src/sgsn/gtp_ggsn.c +++ b/src/sgsn/gtp_ggsn.c @@ -35,8 +35,6 @@ #include <osmocom/sgsn/gprs_gmm_fsm.h> #include <osmocom/sgsn/gprs_sm.h>
-extern void *tall_sgsn_ctx; - void sgsn_ggsn_ctx_check_echo_timer(struct sgsn_ggsn_ctx *ggc) { bool pending = osmo_timer_pending(&ggc->echo_timer); @@ -59,11 +57,11 @@ osmo_timer_schedule(&ggc->echo_timer, ggc->echo_interval, 0); }
-struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_alloc(uint32_t id) +struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_alloc(struct sgsn_instance *sgsn, uint32_t id) { struct sgsn_ggsn_ctx *ggc;
- ggc = talloc_zero(tall_sgsn_ctx, struct sgsn_ggsn_ctx); + ggc = talloc_zero(sgsn, struct sgsn_ggsn_ctx); if (!ggc) return NULL;
@@ -86,7 +84,7 @@ talloc_free(ggc); }
-struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_by_id(uint32_t id) +struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_by_id(struct sgsn_instance *sgsn, uint32_t id) { struct sgsn_ggsn_ctx *ggc;
@@ -97,7 +95,7 @@ return NULL; }
-struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_by_addr(struct in_addr *addr) +struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_by_addr(struct sgsn_instance *sgsn, struct in_addr *addr) { struct sgsn_ggsn_ctx *ggc;
@@ -109,13 +107,13 @@ }
-struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_find_alloc(uint32_t id) +struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_find_alloc(struct sgsn_instance *sgsn, uint32_t id) { struct sgsn_ggsn_ctx *ggc;
- ggc = sgsn_ggsn_ctx_by_id(id); + ggc = sgsn_ggsn_ctx_by_id(sgsn, id); if (!ggc) - ggc = sgsn_ggsn_ctx_alloc(id); + ggc = sgsn_ggsn_ctx_alloc(sgsn, id); return ggc; }
diff --git a/src/sgsn/gtp_mme.c b/src/sgsn/gtp_mme.c index 4fe804d..948e8e8 100644 --- a/src/sgsn/gtp_mme.c +++ b/src/sgsn/gtp_mme.c @@ -39,7 +39,7 @@ struct sgsn_mme_ctx *sgsn_mme_ctx_alloc(struct sgsn_instance *sgsn, const char *name) { struct sgsn_mme_ctx *mme; - mme = talloc_zero(tall_sgsn_ctx, struct sgsn_mme_ctx); + mme = talloc_zero(sgsn, struct sgsn_mme_ctx); if (!mme) return NULL;
diff --git a/src/sgsn/sgsn_libgtp.c b/src/sgsn/sgsn_libgtp.c index f848e57..dc3f916 100644 --- a/src/sgsn/sgsn_libgtp.c +++ b/src/sgsn/sgsn_libgtp.c @@ -600,7 +600,7 @@ struct sgsn_ggsn_ctx *ggsn; struct sgsn_pdp_ctx *pctx = NULL;
- ggsn = sgsn_ggsn_ctx_by_addr(&peer->sin_addr); + ggsn = sgsn_ggsn_ctx_by_addr(sgsn, &peer->sin_addr); if (!ggsn) { LOGP(DGPRS, LOGL_NOTICE, "Received Recovery IE for unknown GGSN\n"); return -EINVAL; diff --git a/src/sgsn/sgsn_vty.c b/src/sgsn/sgsn_vty.c index b6d03cf..3d3e8cd 100644 --- a/src/sgsn/sgsn_vty.c +++ b/src/sgsn/sgsn_vty.c @@ -422,7 +422,7 @@ "IPv4 Address\n") { uint32_t id = atoi(argv[0]); - struct sgsn_ggsn_ctx *ggc = sgsn_ggsn_ctx_find_alloc(id); + struct sgsn_ggsn_ctx *ggc = sgsn_ggsn_ctx_find_alloc(sgsn, id);
inet_aton(argv[1], &ggc->remote_addr);
@@ -447,7 +447,7 @@ "Version 0\n" "Version 1\n") { uint32_t id = atoi(argv[0]); - struct sgsn_ggsn_ctx *ggc = sgsn_ggsn_ctx_find_alloc(id); + struct sgsn_ggsn_ctx *ggc = sgsn_ggsn_ctx_find_alloc(sgsn, id);
if (atoi(argv[1])) ggc->gtp_version = 1; @@ -465,7 +465,7 @@ "Interval between echo requests in seconds.\n") { uint32_t id = atoi(argv[0]); - struct sgsn_ggsn_ctx *ggc = sgsn_ggsn_ctx_find_alloc(id); + struct sgsn_ggsn_ctx *ggc = sgsn_ggsn_ctx_find_alloc(sgsn, id);
ggc->echo_interval = atoi(argv[1]);
@@ -484,7 +484,7 @@ NO_STR "Send an echo request to this static GGSN every interval.\n") { uint32_t id = atoi(argv[0]); - struct sgsn_ggsn_ctx *ggc = sgsn_ggsn_ctx_find_alloc(id); + struct sgsn_ggsn_ctx *ggc = sgsn_ggsn_ctx_find_alloc(sgsn, id);
ggc->echo_interval = 0; sgsn_ggsn_ctx_check_echo_timer(ggc); @@ -525,7 +525,7 @@ struct apn_ctx *actx; struct sgsn_ggsn_ctx *ggsn;
- ggsn = sgsn_ggsn_ctx_by_id(ggsn_id); + ggsn = sgsn_ggsn_ctx_by_id(sgsn, ggsn_id); if (ggsn == NULL) { vty_out(vty, "%% a GGSN with id %d has not been defined%s", ggsn_id, VTY_NEWLINE); diff --git a/tests/sgsn/sgsn_test.c b/tests/sgsn/sgsn_test.c index 5d46162..bf4d82b 100644 --- a/tests/sgsn/sgsn_test.c +++ b/tests/sgsn/sgsn_test.c @@ -1473,9 +1473,9 @@
/* TODO: Add PDP info entries to s1 */
- ggcs[0] = sgsn_ggsn_ctx_find_alloc(0); - ggcs[1] = sgsn_ggsn_ctx_find_alloc(1); - ggcs[2] = sgsn_ggsn_ctx_find_alloc(2); + ggcs[0] = sgsn_ggsn_ctx_find_alloc(sgsn, 0); + ggcs[1] = sgsn_ggsn_ctx_find_alloc(sgsn, 1); + ggcs[2] = sgsn_ggsn_ctx_find_alloc(sgsn, 2);
actxs[0] = sgsn_apn_ctx_find_alloc("test.apn", "123456"); actxs[0]->ggsn = ggcs[0];