aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2018-12-02 19:46:46 +0100
committerNeels Hofmeyr <neels@hofmeyr.de>2018-12-02 20:16:31 +0100
commita820ea1f67bab68136fbaae0108bb90c94b77b22 (patch)
treeb9f94dd6ef8e4a1b3ee3388f52bdb32d1eeb2925
parent8aa780bf80fa4ffde8a5df9d8b87a2e919193f1f (diff)
implement removal of MSISDN
Add the first "official" way to remove the MSISDN from a subscriber entry, to go back to 'MSISDN: none' like just after 'subscriber create'. Add VTY command 'subscriber <ID> update msisdn none' to drop the MSISDN from the subscriber. (Like 'subscriber <ID> update aud3g none') Add DB_STMT_DELETE_MSISDN_BY_IMSI. In db_subscr_update_msisdn_by_imsi(), allow passing a NULL msisdn, and if NULL, call above delete SQL statement. Change-Id: I15419105ea461137776adb92d384d8985210c90e
-rw-r--r--src/db.c1
-rw-r--r--src/db.h1
-rw-r--r--src/db_hlr.c13
-rw-r--r--src/hlr_vty_subscr.c42
-rw-r--r--tests/test_subscriber.vty21
5 files changed, 57 insertions, 21 deletions
diff --git a/src/db.c b/src/db.c
index 4b0577f..bcf83c6 100644
--- a/src/db.c
+++ b/src/db.c
@@ -62,6 +62,7 @@ static const char *stmt_sql[] = {
[DB_STMT_SUBSCR_CREATE] = "INSERT INTO subscriber (imsi) VALUES ($imsi)",
[DB_STMT_DEL_BY_ID] = "DELETE FROM subscriber WHERE id = $subscriber_id",
[DB_STMT_SET_MSISDN_BY_IMSI] = "UPDATE subscriber SET msisdn = $msisdn WHERE imsi = $imsi",
+ [DB_STMT_DELETE_MSISDN_BY_IMSI] = "UPDATE subscriber SET msisdn = NULL WHERE imsi = $imsi",
[DB_STMT_AUC_2G_INSERT] =
"INSERT INTO auc_2g (subscriber_id, algo_id_2g, ki)"
" VALUES($subscriber_id, $algo_id_2g, $ki)",
diff --git a/src/db.h b/src/db.h
index 956b5ed..34582c8 100644
--- a/src/db.h
+++ b/src/db.h
@@ -20,6 +20,7 @@ enum stmt_idx {
DB_STMT_SUBSCR_CREATE,
DB_STMT_DEL_BY_ID,
DB_STMT_SET_MSISDN_BY_IMSI,
+ DB_STMT_DELETE_MSISDN_BY_IMSI,
DB_STMT_AUC_2G_INSERT,
DB_STMT_AUC_2G_DELETE,
DB_STMT_AUC_3G_INSERT,
diff --git a/src/db_hlr.c b/src/db_hlr.c
index c4d4974..2bccc38 100644
--- a/src/db_hlr.c
+++ b/src/db_hlr.c
@@ -135,7 +135,7 @@ int db_subscr_delete_by_id(struct db_context *dbc, int64_t subscr_id)
/*! Set a subscriber's MSISDN in the HLR database.
* \param[in,out] dbc database context.
- * \param[in] imsi ASCII string of IMSI digits.
+ * \param[in] imsi ASCII string of IMSI digits, or NULL to remove the MSISDN.
* \param[in] msisdn ASCII string of MSISDN digits.
* \returns 0 on success, -EINVAL in case of invalid MSISDN string, -EIO on
* database failure, -ENOENT if no such subscriber exists.
@@ -146,19 +146,22 @@ int db_subscr_update_msisdn_by_imsi(struct db_context *dbc, const char *imsi,
int rc;
int ret = 0;
- if (!osmo_msisdn_str_valid(msisdn)) {
+ if (msisdn && !osmo_msisdn_str_valid(msisdn)) {
LOGHLR(imsi, LOGL_ERROR,
"Cannot update subscriber: invalid MSISDN: '%s'\n",
msisdn);
return -EINVAL;
}
- sqlite3_stmt *stmt = dbc->stmt[DB_STMT_SET_MSISDN_BY_IMSI];
+ sqlite3_stmt *stmt = dbc->stmt[
+ msisdn ? DB_STMT_SET_MSISDN_BY_IMSI : DB_STMT_DELETE_MSISDN_BY_IMSI];
if (!db_bind_text(stmt, "$imsi", imsi))
return -EIO;
- if (!db_bind_text(stmt, "$msisdn", msisdn))
- return -EIO;
+ if (msisdn) {
+ if (!db_bind_text(stmt, "$msisdn", msisdn))
+ return -EIO;
+ }
/* execute the statement */
rc = sqlite3_step(stmt);
diff --git a/src/hlr_vty_subscr.c b/src/hlr_vty_subscr.c
index ddbaf26..bc6f6a5 100644
--- a/src/hlr_vty_subscr.c
+++ b/src/hlr_vty_subscr.c
@@ -142,6 +142,7 @@ static int get_subscr_by_argv(struct vty *vty, const char *type, const char *id,
#define SUBSCR_UPDATE SUBSCR "update "
#define SUBSCR_UPDATE_HELP SUBSCR_HELP "Set or update subscriber data\n"
+#define SUBSCR_MSISDN_HELP "Set MSISDN (phone number) of the subscriber\n"
DEFUN(subscriber_show,
subscriber_show_cmd,
@@ -228,9 +229,9 @@ DEFUN(subscriber_delete,
DEFUN(subscriber_msisdn,
subscriber_msisdn_cmd,
- SUBSCR_UPDATE "msisdn MSISDN",
- SUBSCR_UPDATE_HELP
- "Set MSISDN (phone number) of the subscriber\n"
+ SUBSCR_UPDATE "msisdn (none|MSISDN)",
+ SUBSCR_UPDATE_HELP SUBSCR_MSISDN_HELP
+ "Remove MSISDN (phone number)\n"
"New MSISDN (phone number)\n")
{
struct hlr_subscriber subscr;
@@ -238,15 +239,19 @@ DEFUN(subscriber_msisdn,
const char *id = argv[1];
const char *msisdn = argv[2];
- if (strlen(msisdn) > sizeof(subscr.msisdn) - 1) {
- vty_out(vty, "%% MSISDN is too long, max. %zu characters are allowed%s",
- sizeof(subscr.msisdn)-1, VTY_NEWLINE);
- return CMD_WARNING;
- }
-
- if (!osmo_msisdn_str_valid(msisdn)) {
- vty_out(vty, "%% MSISDN invalid: '%s'%s", msisdn, VTY_NEWLINE);
- return CMD_WARNING;
+ if (strcmp(msisdn, "none") == 0)
+ msisdn = NULL;
+ else {
+ if (strlen(msisdn) > sizeof(subscr.msisdn) - 1) {
+ vty_out(vty, "%% MSISDN is too long, max. %zu characters are allowed%s",
+ sizeof(subscr.msisdn)-1, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ if (!osmo_msisdn_str_valid(msisdn)) {
+ vty_out(vty, "%% MSISDN invalid: '%s'%s", msisdn, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
}
if (get_subscr_by_argv(vty, id_type, id, &subscr))
@@ -258,11 +263,18 @@ DEFUN(subscriber_msisdn,
return CMD_WARNING;
}
- vty_out(vty, "%% Updated subscriber IMSI='%s' to MSISDN='%s'%s",
- subscr.imsi, msisdn, VTY_NEWLINE);
+ if (msisdn) {
+ vty_out(vty, "%% Updated subscriber IMSI='%s' to MSISDN='%s'%s",
+ subscr.imsi, msisdn, VTY_NEWLINE);
+
+ if (db_subscr_get_by_msisdn(g_hlr->dbc, msisdn, &subscr) == 0)
+ osmo_hlr_subscriber_update_notify(&subscr);
+ } else {
+ vty_out(vty, "%% Updated subscriber IMSI='%s': removed MSISDN%s",
+ subscr.imsi, VTY_NEWLINE);
- if (db_subscr_get_by_msisdn(g_hlr->dbc, msisdn, &subscr) == 0)
osmo_hlr_subscriber_update_notify(&subscr);
+ }
return CMD_SUCCESS;
}
diff --git a/tests/test_subscriber.vty b/tests/test_subscriber.vty
index c22f2df..8677c9b 100644
--- a/tests/test_subscriber.vty
+++ b/tests/test_subscriber.vty
@@ -6,7 +6,7 @@ OsmoHLR# list
show subscriber (imsi|msisdn|id) IDENT
subscriber imsi IDENT create
subscriber (imsi|msisdn|id) IDENT delete
- subscriber (imsi|msisdn|id) IDENT update msisdn MSISDN
+ subscriber (imsi|msisdn|id) IDENT update msisdn (none|MSISDN)
subscriber (imsi|msisdn|id) IDENT update aud2g none
subscriber (imsi|msisdn|id) IDENT update aud2g (comp128v1|comp128v2|comp128v3|xor) ki KI
subscriber (imsi|msisdn|id) IDENT update aud3g none
@@ -86,6 +86,21 @@ OsmoHLR# subscriber msisdn 12345 update msisdn 423
OsmoHLR# subscriber msisdn 12345 show
% No subscriber for msisdn = '12345'
+OsmoHLR# subscriber msisdn 423 update msisdn none
+% Updated subscriber IMSI='123456789023000': removed MSISDN
+OsmoHLR# subscriber msisdn 423 show
+% No subscriber for msisdn = '423'
+OsmoHLR# subscriber imsi 123456789023000 show
+ ID: 1
+ IMSI: 123456789023000
+ MSISDN: none
+OsmoHLR# subscriber imsi 123456789023000 update msisdn 423
+% Updated subscriber IMSI='123456789023000' to MSISDN='423'
+OsmoHLR# subscriber msisdn 423 show
+ ID: 1
+ IMSI: 123456789023000
+ MSISDN: 423
+
OsmoHLR# subscriber imsi 123456789023000 show
ID: 1
IMSI: 123456789023000
@@ -104,6 +119,10 @@ OsmoHLR# subscriber imsi 123456789023000 update ?
aud2g Set 2G authentication data
aud3g Set UMTS authentication data (3G, and 2G with UMTS AKA)
+OsmoHLR# subscriber imsi 123456789023000 update msisdn ?
+ none Remove MSISDN (phone number)
+ MSISDN New MSISDN (phone number)
+
OsmoHLR# subscriber imsi 123456789023000 update aud2g ?
none Delete 2G authentication data
comp128v1 Use COMP128v1 algorithm