diff --git a/include/osmocom/sgsn/gtp_ggsn.h b/include/osmocom/sgsn/gtp_ggsn.h index 224fa3559..6afb8664a 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 sgsn_ggsn_ctx { 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 42d1ecee3..8c2734b79 100644 --- a/src/sgsn/gprs_sgsn.c +++ b/src/sgsn/gprs_sgsn.c @@ -713,11 +713,11 @@ struct sgsn_ggsn_ctx *sgsn_mm_ctx_find_ggsn_ctx(struct sgsn_mm_ctx *mmctx, 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 157e27972..184350dd6 100644 --- a/src/sgsn/gprs_sm.c +++ b/src/sgsn/gprs_sm.c @@ -378,7 +378,7 @@ static void ggsn_lookup_cb(void *arg, int status, int timeouts, struct hostent * 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 be07d13e9..b43fb25cd 100644 --- a/src/sgsn/gtp_ggsn.c +++ b/src/sgsn/gtp_ggsn.c @@ -35,8 +35,6 @@ #include #include -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 @@ static void echo_timer_cb(void *data) 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 @@ void sgsn_ggsn_ctx_free(struct sgsn_ggsn_ctx *ggc) 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 @@ struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_by_id(uint32_t id) 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_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_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 4fe804d94..948e8e8ac 100644 --- a/src/sgsn/gtp_mme.c +++ b/src/sgsn/gtp_mme.c @@ -39,7 +39,7 @@ static bool _eutran_tai_equal(const struct osmo_eutran_tai *t1, const struct osm 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 f848e57fa..dc3f916ef 100644 --- a/src/sgsn/sgsn_libgtp.c +++ b/src/sgsn/sgsn_libgtp.c @@ -600,7 +600,7 @@ static int cb_recovery3(struct gsn_t *gsn, struct sockaddr_in *peer, struct pdp_ 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 b6d03cf00..3d3e8cdf4 100644 --- a/src/sgsn/sgsn_vty.c +++ b/src/sgsn/sgsn_vty.c @@ -422,7 +422,7 @@ DEFUN(cfg_ggsn_remote_ip, cfg_ggsn_remote_ip_cmd, "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 @@ DEFUN(cfg_ggsn_gtp_version, cfg_ggsn_gtp_version_cmd, "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 @@ DEFUN(cfg_ggsn_echo_interval, cfg_ggsn_echo_interval_cmd, "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 @@ DEFUN(cfg_ggsn_no_echo_interval, cfg_ggsn_no_echo_interval_cmd, 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 @@ static int add_apn_ggsn_mapping(struct vty *vty, const char *apn_str, 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 5d4616250..bf4d82b83 100644 --- a/tests/sgsn/sgsn_test.c +++ b/tests/sgsn/sgsn_test.c @@ -1473,9 +1473,9 @@ static void test_ggsn_selection(void) /* 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];