[PATCH] osmo-hlr[master]: main: add VTY and '-c config-file' option

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Mon Jan 30 22:31:49 UTC 2017


Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

    https://gerrit.osmocom.org/1707

to look at the new patch set (#2).

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
---
M src/Makefile.am
M src/hlr.c
A src/hlr_vty.c
A src/hlr_vty.h
4 files changed, 134 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-hlr refs/changes/07/1707/2

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 @@
 	gsup_server.h \
 	logging.h \
 	rand.h \
+	hlr_vty.h \
 	$(NULL)
 
 bin_PROGRAMS = \
@@ -38,6 +39,7 @@
 	hlr.c \
 	logging.c \
 	rand_urandom.c \
+	hlr_vty.c \
 	$(NULL)
 
 osmo_hlr_LDADD = \
diff --git a/src/hlr.c b/src/hlr.c
index ad11758..35ff10e 100644
--- a/src/hlr.c
+++ b/src/hlr.c
@@ -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_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 @@
 		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 @@
 			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 @@
 			break;
 		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. */
@@ -616,6 +634,13 @@
 	}
 }
 
+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 @@
 		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 at sysmocom.de>
+ * All Rights Reserved
+ *
+ * Author: Neels Hofmeyr <nhofmeyr at 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 at sysmocom.de>
+ * All Rights Reserved
+ *
+ * Author: Neels Hofmeyr <nhofmeyr at 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);

-- 
To view, visit https://gerrit.osmocom.org/1707
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: Iedb884345a597371a337b0c67eb6013b7d5d1ce1
Gerrit-PatchSet: 2
Gerrit-Project: osmo-hlr
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder


More information about the gerrit-log mailing list