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
changes/89/30889/1
Pau Espin 2023-01-05 19:37:05 +01:00
parent 8ec269a0e0
commit fd4d435442
6 changed files with 12 additions and 12 deletions

View File

@ -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;

View File

@ -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 */

View File

@ -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;

View File

@ -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);

View File

@ -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,

View File

@ -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", "");