aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2023-01-05 19:37:05 +0100
committerPau Espin Pedrol <pespin@sysmocom.de>2023-01-05 19:37:07 +0100
commitfd4d435442429630969c34d20900c89c7ec1dbb7 (patch)
treefa2a7ec9f7aa068a98886f19b5830f76e61e89ce
parent8ec269a0e0bffc53b2447f50bb54f8d6f6bb8fd4 (diff)
Move global apn_list inside struct sgsn_instance
This way apns are managed by the lifcycle of the main global struct sgsn_instance automatically. Change-Id: I8cc8e540cfb64d0f130e9c0aaedf7b0835f8fe16
-rw-r--r--include/osmocom/sgsn/apn.h2
-rw-r--r--include/osmocom/sgsn/sgsn.h1
-rw-r--r--src/sgsn/apn.c11
-rw-r--r--src/sgsn/gprs_sgsn.c5
-rw-r--r--src/sgsn/sgsn_vty.c4
-rw-r--r--tests/sgsn/sgsn_test.c1
6 files changed, 12 insertions, 12 deletions
diff --git a/include/osmocom/sgsn/apn.h b/include/osmocom/sgsn/apn.h
index adf62e21f..3dc7a70ca 100644
--- a/include/osmocom/sgsn/apn.h
+++ b/include/osmocom/sgsn/apn.h
@@ -6,8 +6,6 @@ struct sgsn_ggsn_ctx;
#define GSM_APN_LENGTH 102
-extern struct llist_head sgsn_apn_ctxts;
-
struct apn_ctx {
struct llist_head list;
struct sgsn_ggsn_ctx *ggsn;
diff --git a/include/osmocom/sgsn/sgsn.h b/include/osmocom/sgsn/sgsn.h
index 7e78eeea0..0bc88a935 100644
--- a/include/osmocom/sgsn/sgsn.h
+++ b/include/osmocom/sgsn/sgsn.h
@@ -151,6 +151,7 @@ struct sgsn_instance {
struct rate_ctr_group *rate_ctrs;
+ struct llist_head apn_list; /* list of struct sgsn_apn_ctx */
struct llist_head ggsn_list; /* list of struct sgsn_ggsn_ctx */
struct llist_head mme_list; /* list of struct sgsn_mme_ctx */
diff --git a/src/sgsn/apn.c b/src/sgsn/apn.c
index d6d537204..8ed523e73 100644
--- a/src/sgsn/apn.c
+++ b/src/sgsn/apn.c
@@ -25,22 +25,21 @@
#include <talloc.h>
#include <osmocom/sgsn/apn.h>
+#include <osmocom/sgsn/sgsn.h>
extern void *tall_sgsn_ctx;
-LLIST_HEAD(sgsn_apn_ctxts);
-
static struct apn_ctx *sgsn_apn_ctx_alloc(const char *ap_name, const char *imsi_prefix)
{
struct apn_ctx *actx;
- actx = talloc_zero(tall_sgsn_ctx, struct apn_ctx);
+ actx = talloc_zero(sgsn, struct apn_ctx);
if (!actx)
return NULL;
actx->name = talloc_strdup(actx, ap_name);
actx->imsi_prefix = talloc_strdup(actx, imsi_prefix);
- llist_add_tail(&actx->list, &sgsn_apn_ctxts);
+ llist_add_tail(&actx->list, &sgsn->apn_list);
return actx;
}
@@ -59,7 +58,7 @@ struct apn_ctx *sgsn_apn_ctx_match(const char *name, const char *imsi)
size_t name_prio = 0;
size_t name_req_len = strlen(name);
- llist_for_each_entry(actx, &sgsn_apn_ctxts, list) {
+ llist_for_each_entry(actx, &sgsn->apn_list, list) {
size_t name_ref_len, imsi_ref_len;
const char *name_ref_start, *name_match_start;
@@ -106,7 +105,7 @@ struct apn_ctx *sgsn_apn_ctx_by_name(const char *name, const char *imsi_prefix)
{
struct apn_ctx *actx;
- llist_for_each_entry(actx, &sgsn_apn_ctxts, list) {
+ llist_for_each_entry(actx, &sgsn->apn_list, list) {
if (strcasecmp(name, actx->name) == 0 &&
strcasecmp(imsi_prefix, actx->imsi_prefix) == 0)
return actx;
diff --git a/src/sgsn/gprs_sgsn.c b/src/sgsn/gprs_sgsn.c
index c1576253a..42d1ecee3 100644
--- a/src/sgsn/gprs_sgsn.c
+++ b/src/sgsn/gprs_sgsn.c
@@ -658,7 +658,7 @@ struct sgsn_ggsn_ctx *sgsn_mm_ctx_find_ggsn_ctx(struct sgsn_mm_ctx *mmctx,
insert_extra(tp, mmctx->subscr->sgsn_data, pdp);
continue;
}
- if (!llist_empty(&sgsn_apn_ctxts)) {
+ if (!llist_empty(&sgsn->apn_list)) {
apn_ctx = sgsn_apn_ctx_match(req_apn_str, mmctx->imsi);
/* Not configured */
if (apn_ctx == NULL)
@@ -711,7 +711,7 @@ struct sgsn_ggsn_ctx *sgsn_mm_ctx_find_ggsn_ctx(struct sgsn_mm_ctx *mmctx,
if (apn_ctx != NULL) {
ggsn = apn_ctx->ggsn;
- } else if (llist_empty(&sgsn_apn_ctxts)) {
+ } else if (llist_empty(&sgsn->apn_list)) {
/* No configuration -> use GGSN 0 */
ggsn = sgsn_ggsn_ctx_by_id(0);
} else if (allow_any_apn &&
@@ -821,6 +821,7 @@ struct sgsn_instance *sgsn_instance_alloc(void *talloc_ctx)
inst->rate_ctrs = rate_ctr_group_alloc(inst, &sgsn_ctrg_desc, 0);
OSMO_ASSERT(inst->rate_ctrs);
+ INIT_LLIST_HEAD(&inst->apn_list);
INIT_LLIST_HEAD(&inst->ggsn_list);
INIT_LLIST_HEAD(&inst->mme_list);
diff --git a/src/sgsn/sgsn_vty.c b/src/sgsn/sgsn_vty.c
index b678f07ed..b6d03cf00 100644
--- a/src/sgsn/sgsn_vty.c
+++ b/src/sgsn/sgsn_vty.c
@@ -311,9 +311,9 @@ static int config_write_sgsn(struct vty *vty)
llist_for_each_entry(acl, &g_cfg->imsi_acl, list)
vty_out(vty, " imsi-acl add %s%s", acl->imsi, VTY_NEWLINE);
- if (llist_empty(&sgsn_apn_ctxts))
+ if (llist_empty(&sgsn->apn_list))
vty_out(vty, " ! apn * ggsn 0%s", VTY_NEWLINE);
- llist_for_each_entry(actx, &sgsn_apn_ctxts, list) {
+ llist_for_each_entry(actx, &sgsn->apn_list, list) {
if (strlen(actx->imsi_prefix) > 0)
vty_out(vty, " apn %s imsi-prefix %s ggsn %u%s",
actx->name, actx->imsi_prefix, actx->ggsn->id,
diff --git a/tests/sgsn/sgsn_test.c b/tests/sgsn/sgsn_test.c
index e7f820f98..5d4616250 100644
--- a/tests/sgsn/sgsn_test.c
+++ b/tests/sgsn/sgsn_test.c
@@ -1346,6 +1346,7 @@ static void test_apn_matching(void)
struct apn_ctx *actx, *actxs[9];
printf("Testing APN matching\n");
+ sgsn = sgsn_instance_alloc(tall_sgsn_ctx);
actxs[0] = sgsn_apn_ctx_find_alloc("*.test", "");
actxs[1] = sgsn_apn_ctx_find_alloc("*.def.test", "");