diff options
author | Neels Hofmeyr <nhofmeyr@sysmocom.de> | 2017-01-30 23:30:26 +0100 |
---|---|---|
committer | Neels Hofmeyr <nhofmeyr@sysmocom.de> | 2017-01-30 23:30:35 +0100 |
commit | c0cbf9f2e4fed359e81fbdb37576d1fd778f3b1a (patch) | |
tree | 1c8667e5420efddcc3f9b080138248261dea6b64 | |
parent | ff0b27324ed391d3a4ea186e6cc8d05a68f5d74b (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 | 43 | ||||
-rw-r--r-- | src/hlr_vty.c | 60 | ||||
-rw-r--r-- | src/hlr_vty.h | 30 |
4 files changed, 134 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 = \ @@ -29,12 +29,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; @@ -527,18 +532,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"); } struct { + const char *config_file; const char *db_file; bool daemonize; } cmdline_opts = { + .config_file = "osmo-hlr.cfg", .db_file = "hlr.db", .daemonize = false, }; @@ -549,16 +558,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; @@ -568,6 +579,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; @@ -586,6 +600,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"); @@ -616,6 +634,13 @@ static void signal_hdlr(int signal) } } +static struct vty_app_info vty_info = { + .name = "OsmoHLR", + .version = PACKAGE_VERSION, + .go_parent_cb = hlr_vty_go_parent, + .is_config_node = hlr_vty_is_config_node, +}; + int main(int argc, char **argv) { int rc; @@ -629,7 +654,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..4ac2d94 --- /dev/null +++ b/src/hlr_vty.c @@ -0,0 +1,60 @@ +/* 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_go_parent(struct vty *vty) +{ + switch (vty->node) { + /* space for future nodes... */ + default: + if (hlr_vty_is_config_node(vty, vty->node)) + vty->node = CONFIG_NODE; + else + vty->node = ENABLE_NODE; + + vty->index = NULL; + } + + return vty->node; +} + +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..16c633a --- /dev/null +++ b/src/hlr_vty.h @@ -0,0 +1,30 @@ +/* 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_go_parent(struct vty *vty); +int hlr_vty_is_config_node(struct vty *vty, int node); +void hlr_vty_init(const struct log_info *cat); |