summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Kluchnikov <kluchnikovi@gmail.com>2015-07-21 11:40:08 +0300
committerIvan Kluchnikov <kluchnikovi@gmail.com>2015-07-22 21:32:10 +0300
commit85439534961c34f620117979d658bdbb760bafb3 (patch)
tree1e3aaa5d50a689d03590c8533d3a1b8a5c5ddf1b
parent3cc7d2b50d8e6d8834135adbb984c90500cacaae (diff)
sub: Add the ability to set prefix for randomly generated extensions
Prefix is added before randomly generated extension. Prefix is useful in case of "accept-all" authentication mode is used and routing based on number prefix is used. Added optional configuration parameter "extension-prefix".
-rw-r--r--openbsc/include/openbsc/db.h4
-rw-r--r--openbsc/include/openbsc/gsm_data.h1
-rw-r--r--openbsc/src/libbsc/bsc_vty.c14
-rw-r--r--openbsc/src/libbsc/net_init.c1
-rw-r--r--openbsc/src/libmsc/db.c16
-rw-r--r--openbsc/src/libmsc/gsm_subscriber.c4
-rw-r--r--openbsc/tests/db/db_test.c6
7 files changed, 33 insertions, 13 deletions
diff --git a/openbsc/include/openbsc/db.h b/openbsc/include/openbsc/db.h
index 6699a86..acaf62a 100644
--- a/openbsc/include/openbsc/db.h
+++ b/openbsc/include/openbsc/db.h
@@ -35,13 +35,13 @@ int db_prepare(void);
int db_fini(void);
/* subscriber management */
-struct gsm_subscriber *db_create_subscriber(const char *imsi);
+struct gsm_subscriber *db_create_subscriber(const char *imsi, uint64_t prefix);
struct gsm_subscriber *db_get_subscriber(enum gsm_subscriber_field field,
const char *subscr);
int db_sync_subscriber(struct gsm_subscriber *subscriber);
int db_subscriber_expire(void *priv, void (*callback)(void *priv, long long unsigned int id));
int db_subscriber_alloc_tmsi(struct gsm_subscriber *subscriber);
-int db_subscriber_alloc_exten(struct gsm_subscriber *subscriber);
+int db_subscriber_alloc_exten(struct gsm_subscriber *subscriber, uint64_t prefix);
int db_subscriber_alloc_token(struct gsm_subscriber *subscriber, uint32_t* token);
int db_subscriber_assoc_imei(struct gsm_subscriber *subscriber, char *imei);
int db_subscriber_delete(struct gsm_subscriber *subscriber);
diff --git a/openbsc/include/openbsc/gsm_data.h b/openbsc/include/openbsc/gsm_data.h
index 6f7c8dd..b67b8c6 100644
--- a/openbsc/include/openbsc/gsm_data.h
+++ b/openbsc/include/openbsc/gsm_data.h
@@ -280,6 +280,7 @@ struct gsm_network {
int create_subscriber;
struct gsm_subscriber_group *subscr_group;
struct gsm_sms_queue *sms_queue;
+ uint64_t exten_prefix;
/* control interface */
struct ctrl_handle *ctrl;
diff --git a/openbsc/src/libbsc/bsc_vty.c b/openbsc/src/libbsc/bsc_vty.c
index a4c5309..6be6788 100644
--- a/openbsc/src/libbsc/bsc_vty.c
+++ b/openbsc/src/libbsc/bsc_vty.c
@@ -794,6 +794,8 @@ static int config_write_net(struct vty *vty)
vty_out(vty, " dtx-used %u%s", gsmnet->dtx_enabled, VTY_NEWLINE);
vty_out(vty, " subscriber-keep-in-ram %d%s",
gsmnet->subscr_group->keep_subscr, VTY_NEWLINE);
+ vty_out(vty, " extension-prefix %llu%s",
+ gsmnet->exten_prefix, VTY_NEWLINE);
return CMD_SUCCESS;
}
@@ -1601,6 +1603,17 @@ DEFUN(cfg_net_subscr_keep,
return CMD_SUCCESS;
}
+DEFUN(cfg_net_exten_prefix,
+ cfg_net_exten_prefix_cmd,
+ "extension-prefix <1-999999999>",
+ "Prefix for subscribers extension.\n"
+ "Extension prefix\n")
+{
+ struct gsm_network *gsmnet = gsmnet_from_vty(vty);
+ gsmnet->exten_prefix = strtoull(argv[0], NULL, 10);
+ return CMD_SUCCESS;
+}
+
/* per-BTS configuration */
DEFUN(cfg_bts,
cfg_bts_cmd,
@@ -3805,6 +3818,7 @@ int bsc_vty_init(const struct log_info *cat)
install_element(GSMNET_NODE, &cfg_net_dtx_cmd);
install_element(GSMNET_NODE, &cfg_net_subscr_keep_cmd);
install_element(GSMNET_NODE, &cfg_net_pag_any_tch_cmd);
+ install_element(GSMNET_NODE, &cfg_net_exten_prefix_cmd);
install_element(GSMNET_NODE, &cfg_bts_cmd);
install_node(&bts_node, config_write_bts);
diff --git a/openbsc/src/libbsc/net_init.c b/openbsc/src/libbsc/net_init.c
index 568a0b8..16e8146 100644
--- a/openbsc/src/libbsc/net_init.c
+++ b/openbsc/src/libbsc/net_init.c
@@ -49,6 +49,7 @@ struct gsm_network *gsm_network_init(uint16_t country_code, uint16_t network_cod
net->subscr_group->net = net;
net->create_subscriber = 1;
+ net->exten_prefix = 0;
net->country_code = country_code;
net->network_code = network_code;
diff --git a/openbsc/src/libmsc/db.c b/openbsc/src/libmsc/db.c
index 428f99b..38c72a4 100644
--- a/openbsc/src/libmsc/db.c
+++ b/openbsc/src/libmsc/db.c
@@ -498,7 +498,7 @@ int db_fini(void)
return 0;
}
-struct gsm_subscriber *db_create_subscriber(const char *imsi)
+struct gsm_subscriber *db_create_subscriber(const char *imsi, uint64_t prefix)
{
dbi_result result;
struct gsm_subscriber *subscr;
@@ -533,7 +533,7 @@ struct gsm_subscriber *db_create_subscriber(const char *imsi)
strncpy(subscr->imsi, imsi, GSM_IMSI_LENGTH-1);
dbi_result_free(result);
LOGP(DDB, LOGL_INFO, "New Subscriber: ID %llu, IMSI %s\n", subscr->id, subscr->imsi);
- db_subscriber_alloc_exten(subscr);
+ db_subscriber_alloc_exten(subscr, prefix);
return subscr;
}
@@ -1227,16 +1227,17 @@ int db_subscriber_alloc_tmsi(struct gsm_subscriber *subscriber)
return 0;
}
-int db_subscriber_alloc_exten(struct gsm_subscriber *subscriber)
+int db_subscriber_alloc_exten(struct gsm_subscriber *subscriber, uint64_t prefix)
{
dbi_result result = NULL;
- uint32_t try;
+ uint64_t try;
for (;;) {
try = (rand()%(GSM_MAX_EXTEN-GSM_MIN_EXTEN+1)+GSM_MIN_EXTEN);
+ try = prefix*100000 + try;
result = dbi_conn_queryf(conn,
"SELECT * FROM Subscriber "
- "WHERE extension = %i",
+ "WHERE extension = %llu",
try
);
if (!result) {
@@ -1254,8 +1255,9 @@ int db_subscriber_alloc_exten(struct gsm_subscriber *subscriber)
}
dbi_result_free(result);
}
- sprintf(subscriber->extension, "%i", try);
- DEBUGP(DDB, "Allocated extension %i for IMSI %s.\n", try, subscriber->imsi);
+ sprintf(subscriber->extension, "%llu", try);
+ DEBUGP(DDB, "Allocated extension %llu for IMSI %s.\n", try, subscriber->imsi);
+
return db_sync_subscriber(subscriber);
}
/*
diff --git a/openbsc/src/libmsc/gsm_subscriber.c b/openbsc/src/libmsc/gsm_subscriber.c
index 4559de5..2bf1c27 100644
--- a/openbsc/src/libmsc/gsm_subscriber.c
+++ b/openbsc/src/libmsc/gsm_subscriber.c
@@ -205,7 +205,9 @@ void subscr_remove_request(struct subscr_request *request)
struct gsm_subscriber *subscr_create_subscriber(struct gsm_subscriber_group *sgrp,
const char *imsi)
{
- struct gsm_subscriber *subscr = db_create_subscriber(imsi);
+ uint64_t prefix;
+ prefix = sgrp->net->exten_prefix;
+ struct gsm_subscriber *subscr = db_create_subscriber(imsi, prefix);
if (subscr)
subscr->group = sgrp;
return subscr;
diff --git a/openbsc/tests/db/db_test.c b/openbsc/tests/db/db_test.c
index a02d1f8..f990d8f 100644
--- a/openbsc/tests/db/db_test.c
+++ b/openbsc/tests/db/db_test.c
@@ -186,7 +186,7 @@ int main()
struct gsm_subscriber *alice_db;
char *alice_imsi = "3243245432345";
- alice = db_create_subscriber(alice_imsi);
+ alice = db_create_subscriber(alice_imsi, 0);
db_sync_subscriber(alice);
alice_db = db_get_subscriber(GSM_SUBSCRIBER_IMSI, alice->imsi);
COMPARE(alice, alice_db);
@@ -194,7 +194,7 @@ int main()
SUBSCR_PUT(alice);
alice_imsi = "3693245423445";
- alice = db_create_subscriber(alice_imsi);
+ alice = db_create_subscriber(alice_imsi, 0);
db_subscriber_assoc_imei(alice, "1234567890");
db_subscriber_alloc_tmsi(alice);
alice->lac=42;
@@ -220,7 +220,7 @@ int main()
SUBSCR_PUT(alice);
alice_imsi = "9993245423445";
- alice = db_create_subscriber(alice_imsi);
+ alice = db_create_subscriber(alice_imsi, 0);
db_subscriber_alloc_tmsi(alice);
alice->lac=42;
db_sync_subscriber(alice);