aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2010-12-22 14:31:34 +0100
committerHolger Hans Peter Freyther <zecke@selfish.org>2010-12-24 21:40:47 +0100
commitf694d5f47ae4d0fb2ea9ff7d5c3ed2d856fa75ef (patch)
tree2192edf50d424964ad65f7ff0e10f594f09aa663
parentdaee5ca7c1019ba973a00f5109256f64873b1b13 (diff)
subscr: Introduce subscr_purge_inactive to free unused subscribers
Introduce a method that will remove all subscribers that have a zero use count. This is useful if someone wants to purge subscribers from memory or wants to disable the everything in RAM feature.
-rw-r--r--openbsc/include/openbsc/gsm_subscriber.h2
-rw-r--r--openbsc/src/gsm_subscriber_base.c15
2 files changed, 17 insertions, 0 deletions
diff --git a/openbsc/include/openbsc/gsm_subscriber.h b/openbsc/include/openbsc/gsm_subscriber.h
index c688c0195..b5e8fb64f 100644
--- a/openbsc/include/openbsc/gsm_subscriber.h
+++ b/openbsc/include/openbsc/gsm_subscriber.h
@@ -90,6 +90,8 @@ struct gsm_subscriber *subscr_active_by_imsi(struct gsm_network *net,
char *subscr_name(struct gsm_subscriber *subscr);
+int subscr_purge_inactive(struct gsm_network *net);
+
/* internal */
struct gsm_subscriber *subscr_alloc(void);
extern struct llist_head active_subscribers;
diff --git a/openbsc/src/gsm_subscriber_base.c b/openbsc/src/gsm_subscriber_base.c
index e3a04f343..8872a9ade 100644
--- a/openbsc/src/gsm_subscriber_base.c
+++ b/openbsc/src/gsm_subscriber_base.c
@@ -133,3 +133,18 @@ struct gsm_subscriber *subscr_active_by_imsi(struct gsm_network *net, const char
return NULL;
}
+
+int subscr_purge_inactive(struct gsm_network *net)
+{
+ struct gsm_subscriber *subscr, *tmp;
+ int purged = 0;
+
+ llist_for_each_entry_safe(subscr, tmp, subscr_bsc_active_subscriber(), entry) {
+ if (subscr->net == net && subscr->use_count <= 0) {
+ subscr_free(subscr);
+ purged += 1;
+ }
+ }
+
+ return purged;
+}