msc: Add and use gsm_subscriber_group
Currently every subcriber object directly refers to the gsm_network
which contains a flag shared by every related subscriber
(keep_subscr). This adds a dependency on gsm_network even if only the
function defined in gsm_subscriber_base.c are used.
This patch adds a new struct gsm_subscriber_group which contains the
keep_subscr flag and a back reference to the network object. The
latter is not dereferenced in gsm_subscriber_base.c, so it can safely
be set to NULL when only that part of the gsm_subscriber API is being
used. It also changes that API to use gsm_subscriber_group instead of
gsm_network parameters.
Since there are some places where a pointer to the gsm_network is
needed but where only a gsm_subscriber is available, a 'net' back
pointer is added to the group struct, too. Nevertheless subscr group
and network could be separated completely, but this is not the topic
of this commit.
Sponsored-by: On-Waves ehf
diff --git a/openbsc/src/libcommon/gsm_subscriber_base.c b/openbsc/src/libcommon/gsm_subscriber_base.c
index 5e00443..3d01ca2 100644
--- a/openbsc/src/libcommon/gsm_subscriber_base.c
+++ b/openbsc/src/libcommon/gsm_subscriber_base.c
@@ -91,18 +91,18 @@
subscr->use_count--;
DEBUGP(DREF, "subscr %s usage decreased usage to: %d\n",
subscr->extension, subscr->use_count);
- if (subscr->use_count <= 0 && !subscr->net->keep_subscr)
+ if (subscr->use_count <= 0 && !subscr->group->keep_subscr)
subscr_free(subscr);
return NULL;
}
-struct gsm_subscriber *subscr_get_or_create(struct gsm_network *net,
+struct gsm_subscriber *subscr_get_or_create(struct gsm_subscriber_group *sgrp,
const char *imsi)
{
struct gsm_subscriber *subscr;
llist_for_each_entry(subscr, subscr_bsc_active_subscribers(), entry) {
- if (strcmp(subscr->imsi, imsi) == 0 && subscr->net == net)
+ if (strcmp(subscr->imsi, imsi) == 0 && subscr->group == sgrp)
return subscr_get(subscr);
}
@@ -112,41 +112,43 @@
strncpy(subscr->imsi, imsi, GSM_IMSI_LENGTH);
subscr->imsi[GSM_IMSI_LENGTH - 1] = '\0';
- subscr->net = net;
+ subscr->group = sgrp;
return subscr;
}
-struct gsm_subscriber *subscr_active_by_tmsi(struct gsm_network *net, uint32_t tmsi)
+struct gsm_subscriber *subscr_active_by_tmsi(struct gsm_subscriber_group *sgrp,
+ uint32_t tmsi)
{
struct gsm_subscriber *subscr;
llist_for_each_entry(subscr, subscr_bsc_active_subscribers(), entry) {
- if (subscr->tmsi == tmsi && subscr->net == net)
+ if (subscr->tmsi == tmsi && subscr->group == sgrp)
return subscr_get(subscr);
}
return NULL;
}
-struct gsm_subscriber *subscr_active_by_imsi(struct gsm_network *net, const char *imsi)
+struct gsm_subscriber *subscr_active_by_imsi(struct gsm_subscriber_group *sgrp,
+ const char *imsi)
{
struct gsm_subscriber *subscr;
llist_for_each_entry(subscr, subscr_bsc_active_subscribers(), entry) {
- if (strcmp(subscr->imsi, imsi) == 0 && subscr->net == net)
+ if (strcmp(subscr->imsi, imsi) == 0 && subscr->group == sgrp)
return subscr_get(subscr);
}
return NULL;
}
-int subscr_purge_inactive(struct gsm_network *net)
+int subscr_purge_inactive(struct gsm_subscriber_group *sgrp)
{
struct gsm_subscriber *subscr, *tmp;
int purged = 0;
llist_for_each_entry_safe(subscr, tmp, subscr_bsc_active_subscribers(), entry) {
- if (subscr->net == net && subscr->use_count <= 0) {
+ if (subscr->group == sgrp && subscr->use_count <= 0) {
subscr_free(subscr);
purged += 1;
}