laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmo-hlr/+/37779?usp=email )
Change subject: subscriber-create-on-demand: rework configuration ......................................................................
subscriber-create-on-demand: rework configuration
This commit prepares for adding a new subscriber-create-on-demand mode (MSISDN=IMSI), which is implemented in a follow-up patch.
* add an enumerated type for subscriber-create-on-demand mode; * store the related parameters in an anonymous structure.
Change-Id: Ib553172655f83dad1ac0e0254615c8c207d79ca9 --- M include/osmocom/hlr/hlr.h M src/hlr.c M src/hlr_vty.c M tests/test_nodes.vty 4 files changed, 68 insertions(+), 32 deletions(-)
Approvals: osmith: Looks good to me, but someone else must approve neels: Looks good to me, but someone else must approve Jenkins Builder: Verified pespin: Looks good to me, but someone else must approve fixeria: Looks good to me, approved
diff --git a/include/osmocom/hlr/hlr.h b/include/osmocom/hlr/hlr.h index 278a85a..4bdb5b0 100644 --- a/include/osmocom/hlr/hlr.h +++ b/include/osmocom/hlr/hlr.h @@ -39,6 +39,12 @@
extern struct osmo_tdef g_hlr_tdefs[];
+enum subscr_create_on_demand_mode { + SUBSCR_COD_MODE_DISABLED = 0, + SUBSCR_COD_MODE_NO_MSISDN, + SUBSCR_COD_MODE_RAND_MSISDN, +}; + struct hlr { /* GSUP server pointer */ struct osmo_gsup_server *gs; @@ -80,10 +86,12 @@
bool store_imei;
- bool subscr_create_on_demand; - /* Bitmask of DB_SUBSCR_FLAG_* */ - uint8_t subscr_create_on_demand_flags; - unsigned int subscr_create_on_demand_rand_msisdn_len; + struct { + enum subscr_create_on_demand_mode mode; + unsigned int rand_msisdn_len; + /* Bitmask of DB_SUBSCR_FLAG_* */ + uint8_t flags; + } subscr_create_on_demand;
struct { bool allow_startup; diff --git a/src/hlr.c b/src/hlr.c index 8ad3dfc..44c96b5 100644 --- a/src/hlr.c +++ b/src/hlr.c @@ -204,23 +204,31 @@ { char msisdn[GSM23003_MSISDN_MAX_DIGITS + 1]; int rc; - unsigned int rand_msisdn_len = g_hlr->subscr_create_on_demand_rand_msisdn_len;
- if (!g_hlr->subscr_create_on_demand) - return -1; if (db_subscr_exists_by_imsi(g_hlr->dbc, imsi) == 0) return -1; - if (rand_msisdn_len && generate_new_msisdn(msisdn, imsi, rand_msisdn_len) != 0) + + switch (g_hlr->subscr_create_on_demand.mode) { + case SUBSCR_COD_MODE_RAND_MSISDN: + if (generate_new_msisdn(msisdn, imsi, g_hlr->subscr_create_on_demand.rand_msisdn_len) != 0) + return -1; + break; + case SUBSCR_COD_MODE_NO_MSISDN: + msisdn[0] = '\0'; + break; + case SUBSCR_COD_MODE_DISABLED: + default: return -1; + }
LOGP(DMAIN, LOGL_INFO, "IMSI='%s': Creating subscriber on demand\n", imsi); - rc = db_subscr_create(g_hlr->dbc, imsi, g_hlr->subscr_create_on_demand_flags); + rc = db_subscr_create(g_hlr->dbc, imsi, g_hlr->subscr_create_on_demand.flags); if (rc) { LOGP(DMAIN, LOGL_ERROR, "Failed to create subscriber on demand (rc=%d): IMSI='%s'\n", rc, imsi); return rc; }
- if (!rand_msisdn_len) + if (msisdn[0] == '\0') return 0;
/* Update MSISDN of the new (just allocated) subscriber */ diff --git a/src/hlr_vty.c b/src/hlr_vty.c index c4e99e2..ae1e13e 100644 --- a/src/hlr_vty.c +++ b/src/hlr_vty.c @@ -282,6 +282,36 @@ return CMD_SUCCESS; }
+static void config_write_subscr_create_on_demand(struct vty *vty) +{ + const uint8_t flags = g_hlr->subscr_create_on_demand.flags; + const char *flags_str; + + switch (g_hlr->subscr_create_on_demand.mode) { + case SUBSCR_COD_MODE_RAND_MSISDN: + vty_out(vty, " subscriber-create-on-demand %u", + g_hlr->subscr_create_on_demand.rand_msisdn_len); + break; + case SUBSCR_COD_MODE_NO_MSISDN: + vty_out(vty, " subscriber-create-on-demand no-msisdn"); + break; + case SUBSCR_COD_MODE_DISABLED: + default: + vty_out(vty, " no subscriber-create-on-demand%s", VTY_NEWLINE); + return; + } + + if ((flags & DB_SUBSCR_FLAG_NAM_CS) && (flags & DB_SUBSCR_FLAG_NAM_PS)) + flags_str = "cs+ps"; + else if (flags & DB_SUBSCR_FLAG_NAM_CS) + flags_str = "cs"; + else if (flags & DB_SUBSCR_FLAG_NAM_PS) + flags_str = "ps"; + else + flags_str = "none"; + vty_out(vty, " %s%s", flags_str, VTY_NEWLINE); +} +
static int config_write_hlr(struct vty *vty) { @@ -299,23 +329,7 @@ vty_out(vty, " store-imei%s", VTY_NEWLINE); if (g_hlr->db_file_path && strcmp(g_hlr->db_file_path, HLR_DEFAULT_DB_FILE_PATH)) vty_out(vty, " database %s%s", g_hlr->db_file_path, VTY_NEWLINE); - if (g_hlr->subscr_create_on_demand) { - const char *flags_str = "none"; - uint8_t flags = g_hlr->subscr_create_on_demand_flags; - unsigned int rand_msisdn_len = g_hlr->subscr_create_on_demand_rand_msisdn_len; - - if ((flags & DB_SUBSCR_FLAG_NAM_CS) && (flags & DB_SUBSCR_FLAG_NAM_PS)) - flags_str = "cs+ps"; - else if (flags & DB_SUBSCR_FLAG_NAM_CS) - flags_str = "cs"; - else if (flags & DB_SUBSCR_FLAG_NAM_PS) - flags_str = "ps"; - - if (rand_msisdn_len) - vty_out(vty, " subscriber-create-on-demand %i %s%s", rand_msisdn_len, flags_str, VTY_NEWLINE); - else - vty_out(vty, " subscriber-create-on-demand no-msisdn %s%s", flags_str, VTY_NEWLINE); - } + config_write_subscr_create_on_demand(vty); return CMD_SUCCESS; }
@@ -805,20 +819,25 @@ "Allow access to packet switched NAM by default.\n" "Allow access to circuit and packet switched NAM by default.\n") { + enum subscr_create_on_demand_mode mode; unsigned int rand_msisdn_len = 0; uint8_t flags = 0x00;
- if (strcmp(argv[0], "no-msisdn") != 0) + if (strcmp(argv[0], "no-msisdn") == 0) { + mode = SUBSCR_COD_MODE_NO_MSISDN; + } else { /* random MSISDN */ + mode = SUBSCR_COD_MODE_RAND_MSISDN; rand_msisdn_len = atoi(argv[0]); + }
if (strstr(argv[1], "cs")) flags |= DB_SUBSCR_FLAG_NAM_CS; if (strstr(argv[1], "ps")) flags |= DB_SUBSCR_FLAG_NAM_PS;
- g_hlr->subscr_create_on_demand = true; - g_hlr->subscr_create_on_demand_rand_msisdn_len = rand_msisdn_len; - g_hlr->subscr_create_on_demand_flags = flags; + g_hlr->subscr_create_on_demand.mode = mode; + g_hlr->subscr_create_on_demand.rand_msisdn_len = rand_msisdn_len; + g_hlr->subscr_create_on_demand.flags = flags;
return CMD_SUCCESS; } @@ -827,7 +846,7 @@ "no subscriber-create-on-demand", "Do not make a new record when a subscriber is first seen.\n") { - g_hlr->subscr_create_on_demand = false; + g_hlr->subscr_create_on_demand.mode = SUBSCR_COD_MODE_DISABLED; return CMD_SUCCESS; }
diff --git a/tests/test_nodes.vty b/tests/test_nodes.vty index 4aea638..02a5552 100644 --- a/tests/test_nodes.vty +++ b/tests/test_nodes.vty @@ -115,6 +115,7 @@ hlr store-imei database hlr_vty_test.db + no subscriber-create-on-demand gsup bind ip 127.0.0.1 ipa-name unnamed-HLR