From 5663db37a3f2808489cf1be0b0bec4c97dc18ea5 Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Mon, 20 Jan 2020 15:59:37 +0100 Subject: examples/sccp_demo_user: Support reading log/vty config from file Passing a config file is still optional, and both client and server work out of the box with providing any. It's still goot allowing to pass a config file to be able to configure easily stuff like logging, VTY ip address binding, etc. Change-Id: Ie75d004a0e9f24309060f241f22209df1bbe358e --- examples/sccp_demo_user.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/examples/sccp_demo_user.c b/examples/sccp_demo_user.c index e3f5ee0..88aead3 100644 --- a/examples/sccp_demo_user.c +++ b/examples/sccp_demo_user.c @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include #include @@ -22,6 +24,8 @@ #include "internal.h" +static const char *config_file; + static struct osmo_sccp_instance *g_sccp; static struct osmo_sccp_instance *sua_server_helper(int local_port, const char *local_address, int local_pc, @@ -71,11 +75,10 @@ static const struct log_info log_info = { .num_cat = ARRAY_SIZE(log_info_cat), }; -static void init_logging(void) +static void init_logging(void *tall_ctx) { const int log_cats[] = { DLSS7, DLSUA, DLM3UA, DLSCCP, DLINP }; unsigned int i; - void *tall_ctx = talloc_named_const(NULL, 1, "example"); msgb_talloc_ctx_init(tall_ctx, 0); osmo_init_logging2(tall_ctx, &log_info); log_set_print_category(osmo_stderr_target, true); @@ -177,7 +180,7 @@ int main(int argc, char **argv) int remote_pc = DEFAULT_PC_CLIENT; bool lflag = false, rflag = false, Lflag = false, Rflag = false; - while ((ch = getopt(argc, argv, "cl:r:L:R:")) != -1) { + while ((ch = getopt(argc, argv, "cl:r:L:R:C:")) != -1) { switch (ch) { case 'c': client = true; @@ -222,6 +225,9 @@ int main(int argc, char **argv) remote_pc = atoi(optarg); Rflag = true; break; + case 'C': + config_file = optarg; + break; default: usage(); } @@ -237,14 +243,30 @@ int main(int argc, char **argv) signal(SIGUSR1, &signal_handler); signal(SIGUSR2, &signal_handler); - init_logging(); + void *tall_ctx = talloc_named_const(NULL, 1, "sccp_demo_user"); + init_logging(tall_ctx); OSMO_ASSERT(osmo_ss7_init() == 0); osmo_fsm_log_addr(false); + vty_info.tall_ctx = tall_ctx; vty_init(&vty_info); + logging_vty_add_cmds(); + osmo_talloc_vty_add_cmds(); + osmo_fsm_vty_add_cmds(); osmo_ss7_vty_init_asp(NULL); osmo_sccp_vty_init(); - rc = telnet_init_dynif(NULL, NULL, local_address, 2324+client); + /* Read the config if requested with -C */ + if (config_file) { + rc = vty_read_config_file(config_file, NULL); + if (rc < 0) { + LOGP(DMAIN, LOGL_FATAL, "Failed to parse the config file: '%s'\n", + config_file); + exit(1); + } + } + + rc = telnet_init_dynif(NULL, NULL, config_file ? vty_get_bind_addr() : local_address, + 2324+client); if (rc < 0) { perror("Error binding VTY port"); exit(1); -- cgit v1.2.3