pespin has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/osmo-sgsn/+/30889 )


Change subject: Move global apn_list inside struct sgsn_instance
......................................................................

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
---
M include/osmocom/sgsn/apn.h
M include/osmocom/sgsn/sgsn.h
M src/sgsn/apn.c
M src/sgsn/gprs_sgsn.c
M src/sgsn/sgsn_vty.c
M tests/sgsn/sgsn_test.c
6 files changed, 12 insertions(+), 12 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-sgsn refs/changes/89/30889/1

diff --git a/include/osmocom/sgsn/apn.h b/include/osmocom/sgsn/apn.h
index adf62e2..3dc7a70 100644
--- a/include/osmocom/sgsn/apn.h
+++ b/include/osmocom/sgsn/apn.h
@@ -6,8 +6,6 @@

 #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 7e78eee..0bc88a9 100644
--- a/include/osmocom/sgsn/sgsn.h
+++ b/include/osmocom/sgsn/sgsn.h
@@ -151,6 +151,7 @@
 
        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 d6d5372..8ed523e 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 @@
        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 *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 c157625..42d1ece 100644
--- a/src/sgsn/gprs_sgsn.c
+++ b/src/sgsn/gprs_sgsn.c
@@ -658,7 +658,7 @@
                                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 @@

        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 @@
        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 b678f07..b6d03cf 100644
--- a/src/sgsn/sgsn_vty.c
+++ b/src/sgsn/sgsn_vty.c
@@ -311,9 +311,9 @@
        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 e7f820f..5d46162 100644
--- a/tests/sgsn/sgsn_test.c
+++ b/tests/sgsn/sgsn_test.c
@@ -1346,6 +1346,7 @@
        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", "");

--
To view, visit https://gerrit.osmocom.org/c/osmo-sgsn/+/30889
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-sgsn
Gerrit-Branch: master
Gerrit-Change-Id: I8cc8e540cfb64d0f130e9c0aaedf7b0835f8fe16
Gerrit-Change-Number: 30889
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <[email protected]>
Gerrit-MessageType: newchange

Reply via email to