aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2019-04-02 04:24:49 +0200
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2019-05-08 04:12:38 +0000
commit5857c595b3288906665cbc3e1e0576f50e90634d (patch)
treeebbc1a0f47f4975c47e63496f439ee70fb77c1b3
parentd9724f429818c6ecd2af822ee2c68a52c2cce358 (diff)
osmo-hlr: allow configuring db path from cfg file
So far, the cmdline argument was the only way to set a database config file. Add a similar config to VTY as 'hlr' / 'database'. The cmdline arg is stronger than the 'database' cfg item. DB is not reloaded from VTY command. Change-Id: I87b8673324e1e6225afb758fb4963ff3279ea3d8
-rw-r--r--src/hlr.c10
-rw-r--r--src/hlr.h3
-rw-r--r--src/hlr_vty.c13
-rw-r--r--tests/test_nodes.vty2
4 files changed, 25 insertions, 3 deletions
diff --git a/src/hlr.c b/src/hlr.c
index d9ebaf7..0bea590 100644
--- a/src/hlr.c
+++ b/src/hlr.c
@@ -626,7 +626,7 @@ static struct {
bool db_upgrade;
} cmdline_opts = {
.config_file = "osmo-hlr.cfg",
- .db_file = "hlr.db",
+ .db_file = NULL,
.daemonize = false,
.db_upgrade = false,
};
@@ -741,6 +741,7 @@ int main(int argc, char **argv)
INIT_LLIST_HEAD(&g_hlr->iuse_list);
INIT_LLIST_HEAD(&g_hlr->ss_sessions);
INIT_LLIST_HEAD(&g_hlr->ussd_routes);
+ g_hlr->db_file_path = talloc_strdup(g_hlr, HLR_DEFAULT_DB_FILE_PATH);
/* Init default (call independent) SS session guard timeout value */
g_hlr->ncss_guard_timeout = NCSS_GUARD_TIMEOUT_DEFAULT;
@@ -779,9 +780,12 @@ int main(int argc, char **argv)
exit(1);
}
- g_hlr->dbc = db_open(hlr_ctx, cmdline_opts.db_file, true, cmdline_opts.db_upgrade);
+ if (cmdline_opts.db_file)
+ osmo_talloc_replace_string(g_hlr, &g_hlr->db_file_path, cmdline_opts.db_file);
+
+ g_hlr->dbc = db_open(hlr_ctx, g_hlr->db_file_path, true, cmdline_opts.db_upgrade);
if (!g_hlr->dbc) {
- LOGP(DMAIN, LOGL_FATAL, "Error opening database\n");
+ LOGP(DMAIN, LOGL_FATAL, "Error opening database %s\n", osmo_quote_str(g_hlr->db_file_path, -1));
exit(1);
}
diff --git a/src/hlr.h b/src/hlr.h
index 00fa43c..e2e96a4 100644
--- a/src/hlr.h
+++ b/src/hlr.h
@@ -25,6 +25,8 @@
#include <stdbool.h>
#include <osmocom/core/linuxlist.h>
+#define HLR_DEFAULT_DB_FILE_PATH "hlr.db"
+
struct hlr_euse;
struct hlr {
@@ -32,6 +34,7 @@ struct hlr {
struct osmo_gsup_server *gs;
/* DB context */
+ char *db_file_path;
struct db_context *dbc;
/* Control Interface */
diff --git a/src/hlr_vty.c b/src/hlr_vty.c
index d0a623a..e4cc4be 100644
--- a/src/hlr_vty.c
+++ b/src/hlr_vty.c
@@ -74,6 +74,8 @@ static int config_write_hlr(struct vty *vty)
vty_out(vty, "hlr%s", VTY_NEWLINE);
if (g_hlr->store_imei)
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);
return CMD_SUCCESS;
}
@@ -224,6 +226,15 @@ DEFUN(cfg_ussd_no_defaultroute, cfg_ussd_no_defaultroute_cmd,
return CMD_SUCCESS;
}
+DEFUN(cfg_database, cfg_database_cmd,
+ "database PATH",
+ "Set the path to the HLR database file\n"
+ "Relative or absolute file system path to the database file (default is '" HLR_DEFAULT_DB_FILE_PATH "')\n")
+{
+ osmo_talloc_replace_string(g_hlr, &g_hlr->db_file_path, argv[0]);
+ return CMD_SUCCESS;
+}
+
struct cmd_node euse_node = {
EUSE_NODE,
"%s(config-hlr-euse)# ",
@@ -380,6 +391,8 @@ void hlr_vty_init(const struct log_info *cat)
install_element(GSUP_NODE, &cfg_hlr_gsup_bind_ip_cmd);
+ install_element(HLR_NODE, &cfg_database_cmd);
+
install_element(HLR_NODE, &cfg_euse_cmd);
install_element(HLR_NODE, &cfg_no_euse_cmd);
install_node(&euse_node, config_write_euse);
diff --git a/tests/test_nodes.vty b/tests/test_nodes.vty
index d90fa70..a4e53db 100644
--- a/tests/test_nodes.vty
+++ b/tests/test_nodes.vty
@@ -75,6 +75,7 @@ OsmoHLR(config-hlr)# list
exit
end
gsup
+ database PATH
euse NAME
no euse NAME
ussd route prefix PREFIX internal (own-msisdn|own-imsi)
@@ -124,6 +125,7 @@ log stderr
...
hlr
store-imei
+ database hlr_vty_test.db
gsup
bind ip 127.0.0.1
ussd route prefix *#100# internal own-msisdn