summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJacob Erlbeck <jerlbeck@sysmocom.de>2014-12-03 11:08:23 +0100
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2014-12-09 09:08:28 +0100
commit70d8e31a748026a92e5739147411dcf512df7205 (patch)
tree3cafaaf35fc462b7c72f0e591624f941fef567a5
parent901c40f55041d72220403c653646a2e8f82f1924 (diff)
msc: Add per subscriber keep_in_ram flag
Currently the keep_subscr flag in gsm_subscriber_group refers to a whole group of subscribers which makes it difficult to really delete single entries if the flag is set. This patch adds a keep_in_ram field to gsm_subscriber which allows for keeping subscriber objects in RAM while deleting others. Note that really deleting an entry requires that both flags (subscr_group->keep_subscr and subscr->keep_in_ram) are set to 0. So only the latter should be used if a specification requires the deletion of a subscriber entry. Sponsored-by: On-Waves ehf
-rw-r--r--openbsc/include/openbsc/gsm_subscriber.h3
-rw-r--r--openbsc/src/libcommon/gsm_subscriber_base.c4
-rw-r--r--openbsc/tests/subscr/subscr_test.c16
3 files changed, 22 insertions, 1 deletions
diff --git a/openbsc/include/openbsc/gsm_subscriber.h b/openbsc/include/openbsc/gsm_subscriber.h
index eaf4028da..46fc87f51 100644
--- a/openbsc/include/openbsc/gsm_subscriber.h
+++ b/openbsc/include/openbsc/gsm_subscriber.h
@@ -49,6 +49,9 @@ struct gsm_subscriber {
int authorized;
time_t expire_lu;
+ /* Don't delete subscribers even if group->keep_subscr is not set */
+ int keep_in_ram;
+
/* Temporary field which is not stored in the DB/HLR */
uint32_t flags;
diff --git a/openbsc/src/libcommon/gsm_subscriber_base.c b/openbsc/src/libcommon/gsm_subscriber_base.c
index 3d01ca20d..3c56101f6 100644
--- a/openbsc/src/libcommon/gsm_subscriber_base.c
+++ b/openbsc/src/libcommon/gsm_subscriber_base.c
@@ -91,7 +91,9 @@ struct gsm_subscriber *subscr_put(struct gsm_subscriber *subscr)
subscr->use_count--;
DEBUGP(DREF, "subscr %s usage decreased usage to: %d\n",
subscr->extension, subscr->use_count);
- if (subscr->use_count <= 0 && !subscr->group->keep_subscr)
+ if (subscr->use_count <= 0 &&
+ !((subscr->group && subscr->group->keep_subscr) ||
+ subscr->keep_in_ram))
subscr_free(subscr);
return NULL;
}
diff --git a/openbsc/tests/subscr/subscr_test.c b/openbsc/tests/subscr/subscr_test.c
index 277fc8866..2a5d0e1c2 100644
--- a/openbsc/tests/subscr/subscr_test.c
+++ b/openbsc/tests/subscr/subscr_test.c
@@ -83,6 +83,22 @@ static void test_subscr(void)
subscr_purge_inactive(&dummy_sgrp);
OSMO_ASSERT(llist_empty(&active_subscribers));
+
+ /* Test force_no_keep */
+
+ dummy_sgrp.keep_subscr = 0;
+
+ subscr = subscr_get_or_create(&dummy_sgrp, imsi);
+ OSMO_ASSERT(subscr);
+ subscr->keep_in_ram = 1;
+
+ OSMO_ASSERT(!llist_empty(&active_subscribers));
+ OSMO_ASSERT(subscr->use_count == 1);
+
+ subscr->keep_in_ram = 0;
+
+ subscr_put(subscr);
+ OSMO_ASSERT(llist_empty(&active_subscribers));
}
int main()