pespin has submitted this change. ( https://gerrit.osmocom.org/c/osmo-hlr/+/28318 )
Change subject: ctrl: Introduce cmd SET subscriber.create <imsi> ......................................................................
ctrl: Introduce cmd SET subscriber.create <imsi>
Create a new subscriber from CTRL, similar to VTY command "imsi IDENT create".
On success SET_REPLY contains the ID of the newly created subscriber.
Related: SYS#5993 Change-Id: Id1b760cd07712245a0eeabaac7891bce93c1fe8e --- M include/osmocom/hlr/logging.h M src/ctrl.c M src/logging.c M tests/test_subscriber.ctrl M tests/test_subscriber_errors.ctrl 5 files changed, 66 insertions(+), 0 deletions(-)
Approvals: fixeria: Looks good to me, but someone else must approve osmith: Looks good to me, approved pespin: Verified
diff --git a/include/osmocom/hlr/logging.h b/include/osmocom/hlr/logging.h index a8081af..0a44a08 100644 --- a/include/osmocom/hlr/logging.h +++ b/include/osmocom/hlr/logging.h @@ -11,6 +11,7 @@ DMSLOOKUP, DLU, DDGSM, + DCTRL, };
extern const struct log_info hlr_log_info; diff --git a/src/ctrl.c b/src/ctrl.c index 37177c5..5b091f8 100644 --- a/src/ctrl.c +++ b/src/ctrl.c @@ -197,6 +197,43 @@ aud->u.umts.sqn); }
+CTRL_CMD_DEFINE_WO_NOVRF(subscr_create, "create"); +static int set_subscr_create(struct ctrl_cmd *cmd, void *data) +{ + struct hlr_subscriber subscr; + struct hlr *hlr = data; + const char *imsi = cmd->value; + int rc; + + if (!osmo_imsi_str_valid(imsi)) { + cmd->reply = "Invalid IMSI value."; + return CTRL_CMD_ERROR; + } + + /* Create the subscriber in the DB */ + rc = db_subscr_create(g_hlr->dbc, imsi, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS); + if (rc) { + if (rc == -EEXIST) + cmd->reply = "Subscriber already exists."; + else + cmd->reply = "Cannot create subscriber."; + return CTRL_CMD_ERROR; + } + + LOGP(DCTRL, LOGL_INFO, "Created subscriber IMSI='%s'\n", + imsi); + + /* Retrieve data of newly created subscriber: */ + rc = db_subscr_get_by_imsi(hlr->dbc, imsi, &subscr); + if (rc < 0) { + cmd->reply = "Failed retrieving ID of newly created subscriber."; + return CTRL_CMD_ERROR; + } + + cmd->reply = talloc_asprintf(cmd, "%" PRIu64, subscr.id); + return CTRL_CMD_REPLY; +} + CTRL_CMD_DEFINE_RO(subscr_info, "info"); static int get_subscr_info(struct ctrl_cmd *cmd, void *data) { @@ -380,6 +417,8 @@ { int rc = 0;
+ rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR, &cmd_subscr_create); + rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR_BY, &cmd_subscr_info); rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR_BY, &cmd_subscr_info_aud); rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR_BY, &cmd_subscr_info_all); diff --git a/src/logging.c b/src/logging.c index eab0510..6f0f3d2 100644 --- a/src/logging.c +++ b/src/logging.c @@ -43,6 +43,12 @@ .color = "\033[1;35m", .enabled = 1, .loglevel = LOGL_NOTICE, }, + [DCTRL] = { + .name = "DCTRL", + .description = "Osmocom CTRL interface", + .color = "\033[1;30m", + .enabled = 1, .loglevel = LOGL_NOTICE, + }, };
const struct log_info hlr_log_info = { diff --git a/tests/test_subscriber.ctrl b/tests/test_subscriber.ctrl index 756e888..8d3c9dc 100644 --- a/tests/test_subscriber.ctrl +++ b/tests/test_subscriber.ctrl @@ -610,3 +610,17 @@ periodic_rau_tau_timer 0 lmsi 00000000
+SET 101 subscriber.create 901991234567891 +SET_REPLY 101 subscriber.create 124 + +GET 102 subscriber.by-id-124.info +GET_REPLY 102 subscriber.by-id-124.info +id 124 +imsi 901991234567891 +nam_cs 1 +nam_ps 1 +ms_purged_cs 0 +ms_purged_ps 0 +periodic_lu_timer 0 +periodic_rau_tau_timer 0 +lmsi 00000000 diff --git a/tests/test_subscriber_errors.ctrl b/tests/test_subscriber_errors.ctrl index 0c5b587..425b0df 100644 --- a/tests/test_subscriber_errors.ctrl +++ b/tests/test_subscriber_errors.ctrl @@ -108,3 +108,9 @@
GET 48 subscriber.by-id-0x0123.info ERROR 48 Invalid value part of 'by-xxx-value' selector. + +SET 49 subscriber.create zzz +ERROR 49 Invalid IMSI value. + +SET 50 subscriber.create 901990000000001 +ERROR 50 Subscriber already exists.