summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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()