summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNeels Hofmeyr <nhofmeyr@sysmocom.de>2016-02-23 14:01:41 +0100
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2016-02-25 11:02:34 +0100
commit96172f01002a64359bbe643c4a0d3cfa9a929b56 (patch)
treea23a2ca497877e198153a08415383e6038b4c060 /src
parentcc00bf8779f48fd1e592fc7d0a60fc00b04826cd (diff)
vty: add bind command for telnet vty line
Add VTY command line vty bind A.B.C.D The command merely stores the configured IP-address, which can then be used by the calling main program to set the telnet port of the VTY line. (Commits in openbsc and osmo-iuh will follow up on this.) Add function vty_get_bind_addr() to publish the address in the vty.h API. Add static vty_bind_addr to store. For allocation/freeing reasons, a NULL address defaults to 127.0.0.1. BTW, I decided against allowing keywords 'any' and 'localhost' in place of an actual IP address to make sure a written config is always identical to the parsed config.
Diffstat (limited to 'src')
-rw-r--r--src/vty/vty.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/vty/vty.c b/src/vty/vty.c
index 5bcbe4a9..8c0c73ab 100644
--- a/src/vty/vty.c
+++ b/src/vty/vty.c
@@ -75,6 +75,12 @@ vector Vvty_serv_thread;
char *vty_cwd = NULL;
+/* IP address passed to the 'line vty'/'bind' command.
+ * Setting the default as vty_bind_addr = "127.0.0.1" doesn't allow freeing, so
+ * use NULL and VTY_BIND_ADDR_DEFAULT instead. */
+static const char *vty_bind_addr = NULL;
+#define VTY_BIND_ADDR_DEFAULT "127.0.0.1"
+
/* Configure lock. */
static int vty_config;
@@ -1585,6 +1591,23 @@ DEFUN(no_vty_login,
return CMD_SUCCESS;
}
+/* vty bind */
+DEFUN(vty_bind, vty_bind_cmd, "bind A.B.C.D",
+ "Accept VTY telnet connections on local interface\n"
+ "Local interface IP address (default: " VTY_BIND_ADDR_DEFAULT ")\n")
+{
+ talloc_free((void*)vty_bind_addr);
+ vty_bind_addr = talloc_strdup(tall_vty_ctx, argv[0]);
+ return CMD_SUCCESS;
+}
+
+const char *vty_get_bind_addr(void)
+{
+ if (!vty_bind_addr)
+ return VTY_BIND_ADDR_DEFAULT;
+ return vty_bind_addr;
+}
+
DEFUN(service_advanced_vty,
service_advanced_vty_cmd,
"service advanced-vty",
@@ -1654,6 +1677,10 @@ static int vty_config_write(struct vty *vty)
if (!password_check)
vty_out(vty, " no login%s", VTY_NEWLINE);
+ /* bind */
+ if (vty_bind_addr && (strcmp(vty_bind_addr, "127.0.0.1") != 0))
+ vty_out(vty, " bind %s%s", vty_bind_addr, VTY_NEWLINE);
+
vty_out(vty, "!%s", VTY_NEWLINE);
return CMD_SUCCESS;
@@ -1757,6 +1784,7 @@ void vty_init(struct vty_app_info *app_info)
vty_install_default(VTY_NODE);
install_element(VTY_NODE, &vty_login_cmd);
install_element(VTY_NODE, &no_vty_login_cmd);
+ install_element(VTY_NODE, &vty_bind_cmd);
}
/*! \brief Read the configuration file using the VTY code