diff options
author | Neels Hofmeyr <nhofmeyr@sysmocom.de> | 2017-01-30 23:30:26 +0100 |
---|---|---|
committer | Neels Hofmeyr <nhofmeyr@sysmocom.de> | 2017-02-01 13:58:50 +0100 |
commit | 7685a7875743f6ccc72f814d7c620214703ddeba (patch) | |
tree | d820e05190bd433ba962069d8263617b25bfe60c | |
parent | 7f9491fe5fa8b4e6dba1bf4087c5aede2fd1daf9 (diff) |
main: add VTY and '-c config-file' option
Add config file, mainly for logging control.
Open VTY on the OMSO_VTY_PORT_HLR added to libosmocore in
commit 92fa18e6b800a27aa064a5fb8321cddd7383ae20
aka change-id I08cb52d9399a27e6876e45da36f434708c4fddef.
Add hlr_vty.h/c for standard VTY setup.
Add -c option to pass config file.
Add --version option.
Change-Id: Iedb884345a597371a337b0c67eb6013b7d5d1ce1
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/hlr.c | 42 | ||||
-rw-r--r-- | src/hlr_vty.c | 44 | ||||
-rw-r--r-- | src/hlr_vty.h | 29 |
4 files changed, 116 insertions, 1 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 6c6c9e6..9bbc13e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -18,6 +18,7 @@ noinst_HEADERS = \ gsup_server.h \ logging.h \ rand.h \ + hlr_vty.h \ $(NULL) bin_PROGRAMS = \ @@ -38,6 +39,7 @@ osmo_hlr_SOURCES = \ hlr.c \ logging.c \ rand_urandom.c \ + hlr_vty.c \ $(NULL) osmo_hlr_LDADD = \ @@ -28,12 +28,17 @@ #include <osmocom/gsm/gsup.h> #include <osmocom/gsm/apn.h> #include <osmocom/gsm/gsm48_ie.h> +#include <osmocom/vty/vty.h> +#include <osmocom/vty/command.h> +#include <osmocom/vty/telnet_interface.h> +#include <osmocom/vty/ports.h> #include "db.h" #include "logging.h" #include "gsup_server.h" #include "gsup_router.h" #include "rand.h" +#include "hlr_vty.h" static struct db_context *g_dbc; @@ -526,18 +531,22 @@ static void print_usage() static void print_help() { printf(" -h --help This text.\n"); + printf(" -c --config-file filename The config file to use.\n"); printf(" -l --database db-name The database to use.\n"); printf(" -d option --debug=DRLL:DCC:DMM:DRR:DRSL:DNM Enable debugging.\n"); printf(" -D --daemonize Fork the process into a background daemon.\n"); printf(" -s --disable-color Do not print ANSI colors in the log\n"); printf(" -T --timestamp Prefix every log line with a timestamp.\n"); printf(" -e --log-level number Set a global loglevel.\n"); + printf(" -V --version Print the version of OsmoHLR.\n"); } static struct { + const char *config_file; const char *db_file; bool daemonize; } cmdline_opts = { + .config_file = "osmo-hlr.cfg", .db_file = "hlr.db", .daemonize = false, }; @@ -548,16 +557,18 @@ static void handle_options(int argc, char **argv) int option_index = 0, c; static struct option long_options[] = { {"help", 0, 0, 'h'}, + {"config-file", 1, 0, 'c'}, {"database", 1, 0, 'l'}, {"debug", 1, 0, 'd'}, {"daemonize", 0, 0, 'D'}, {"disable-color", 0, 0, 's'}, {"log-level", 1, 0, 'e'}, {"timestamp", 0, 0, 'T'}, + {"version", 0, 0, 'V' }, {0, 0, 0, 0} }; - c = getopt_long(argc, argv, "hl:d:Dse:T", + c = getopt_long(argc, argv, "hc:l:d:Dse:TV", long_options, &option_index); if (c == -1) break; @@ -567,6 +578,9 @@ static void handle_options(int argc, char **argv) print_usage(); print_help(); exit(0); + case 'c': + cmdline_opts.config_file = optarg; + break; case 'l': cmdline_opts.db_file = optarg; break; @@ -585,6 +599,10 @@ static void handle_options(int argc, char **argv) case 'T': log_set_print_timestamp(osmo_stderr_target, 1); break; + case 'V': + print_version(1); + exit(0); + break; default: /* catch unknown options *as well as* missing arguments. */ fprintf(stderr, "Error in command line options. Exiting.\n"); @@ -615,6 +633,12 @@ static void signal_hdlr(int signal) } } +static struct vty_app_info vty_info = { + .name = "OsmoHLR", + .version = PACKAGE_VERSION, + .is_config_node = hlr_vty_is_config_node, +}; + int main(int argc, char **argv) { int rc; @@ -628,7 +652,23 @@ int main(int argc, char **argv) exit(1); } + vty_init(&vty_info); handle_options(argc, argv); + hlr_vty_init(&hlr_log_info); + + rc = vty_read_config_file(cmdline_opts.config_file, NULL); + if (rc < 0) { + LOGP(DMAIN, LOGL_FATAL, + "Failed to parse the config file: '%s'\n", + cmdline_opts.config_file); + return rc; + } + + /* start telnet after reading config for vty_get_bind_addr() */ + rc = telnet_init_dynif(hlr_ctx, NULL, vty_get_bind_addr(), + OSMO_VTY_PORT_HLR); + if (rc < 0) + return rc; LOGP(DMAIN, LOGL_NOTICE, "hlr starting\n"); diff --git a/src/hlr_vty.c b/src/hlr_vty.c new file mode 100644 index 0000000..e4eef8f --- /dev/null +++ b/src/hlr_vty.c @@ -0,0 +1,44 @@ +/* OsmoHLR VTY implementation */ + +/* (C) 2016 sysmocom s.f.m.c. GmbH <info@sysmocom.de> + * All Rights Reserved + * + * Author: Neels Hofmeyr <nhofmeyr@sysmocom.de> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#include <osmocom/vty/vty.h> +#include <osmocom/vty/command.h> +#include <osmocom/vty/logging.h> + +#include "hlr_vty.h" + +int hlr_vty_is_config_node(struct vty *vty, int node) +{ + switch (node) { + /* add items that are not config */ + case CONFIG_NODE: + return 0; + + default: + return 1; + } +} + +void hlr_vty_init(const struct log_info *cat) +{ + logging_vty_add_cmds(cat); +} diff --git a/src/hlr_vty.h b/src/hlr_vty.h new file mode 100644 index 0000000..abc9804 --- /dev/null +++ b/src/hlr_vty.h @@ -0,0 +1,29 @@ +/* OsmoHLR VTY implementation */ + +/* (C) 2016 sysmocom s.f.m.c. GmbH <info@sysmocom.de> + * All Rights Reserved + * + * Author: Neels Hofmeyr <nhofmeyr@sysmocom.de> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#pragma once + +#include <osmocom/core/logging.h> +#include <osmocom/vty/vty.h> + +int hlr_vty_is_config_node(struct vty *vty, int node); +void hlr_vty_init(const struct log_info *cat); |