summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@diac24.net>2013-05-30 16:33:45 +0200
committerDavid Lamparter <equinox@opensourcerouting.org>2015-05-27 20:34:40 +0200
commitba5dc5ebb4dba56cb3a64acc21e71aa34df375d9 (patch)
treeaf180446cdaaa0bdab5171630249fd1db9fd5b86
parent4715a53b4d390e72a06c864a6a505971841e3dc9 (diff)
downloadquagga-ba5dc5ebb4dba56cb3a64acc21e71aa34df375d9.tar.bz2
quagga-ba5dc5ebb4dba56cb3a64acc21e71aa34df375d9.tar.xz
lib/vty: add vty_stdio()
this introduces a new public/API function to the vty code for opening a VTY on stdin/stdout. Intended for unrestricted use by the individual daemons, i.e. "offical API". Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
-rw-r--r--lib/vty.c77
-rw-r--r--lib/vty.h1
2 files changed, 57 insertions, 21 deletions
diff --git a/lib/vty.c b/lib/vty.c
index 4b445892..24df32c4 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -1610,6 +1610,34 @@ vty_flush (struct thread *thread)
return 0;
}
+/* allocate and initialise vty */
+static struct vty *
+vty_new_init (int vty_sock)
+{
+ struct vty *vty;
+
+ vty = vty_new ();
+ vty->fd = vty_sock;
+ vty->wfd = vty_sock;
+ vty->type = VTY_TERM;
+ vty->node = AUTH_NODE;
+ vty->fail = 0;
+ vty->cp = 0;
+ vty_clear_buf (vty);
+ vty->length = 0;
+ memset (vty->hist, 0, sizeof (vty->hist));
+ vty->hp = 0;
+ vty->hindex = 0;
+ vector_set_index (vtyvec, vty_sock, vty);
+ vty->status = VTY_NORMAL;
+ vty->lines = -1;
+ vty->iac = 0;
+ vty->iac_sb_in_progress = 0;
+ vty->sb_len = 0;
+
+ return vty;
+}
+
/* Create new vty structure. */
static struct vty *
vty_create (int vty_sock, union sockunion *su)
@@ -1620,10 +1648,10 @@ vty_create (int vty_sock, union sockunion *su)
sockunion2str(su, buf, SU_ADDRSTRLEN);
/* Allocate new vty structure and set up default values. */
- vty = vty_new ();
- vty->fd = vty_sock;
- vty->wfd = vty_sock;
- vty->type = VTY_TERM;
+ vty = vty_new_init (vty_sock);
+
+ /* configurable parameters not part of basic init */
+ vty->v_timeout = vty_timeout_val;
strcpy (vty->address, buf);
if (no_password_check)
{
@@ -1634,25 +1662,8 @@ vty_create (int vty_sock, union sockunion *su)
else
vty->node = VIEW_NODE;
}
- else
- vty->node = AUTH_NODE;
- vty->fail = 0;
- vty->cp = 0;
- vty_clear_buf (vty);
- vty->length = 0;
- memset (vty->hist, 0, sizeof (vty->hist));
- vty->hp = 0;
- vty->hindex = 0;
- vector_set_index (vtyvec, vty_sock, vty);
- vty->status = VTY_NORMAL;
- vty->v_timeout = vty_timeout_val;
if (host.lines >= 0)
vty->lines = host.lines;
- else
- vty->lines = -1;
- vty->iac = 0;
- vty->iac_sb_in_progress = 0;
- vty->sb_len = 0;
if (! no_password_check)
{
@@ -1688,6 +1699,30 @@ vty_create (int vty_sock, union sockunion *su)
return vty;
}
+/* create vty for stdio */
+struct vty *
+vty_stdio (void)
+{
+ struct vty *vty;
+
+ vty = vty_new_init (0);
+ vty->wfd = 1;
+
+ /* always have stdio vty in a known _unchangeable_ state, don't want config
+ * to have any effect here to make sure scripting this works as intended */
+ vty->node = ENABLE_NODE;
+ vty->v_timeout = 0;
+ strcpy (vty->address, "console");
+
+ vty_prompt (vty);
+
+ /* Add read/write thread. */
+ vty_event (VTY_WRITE, 1, vty);
+ vty_event (VTY_READ, 0, vty);
+
+ return vty;
+}
+
/* Accept connection from the network. */
static int
vty_accept (struct thread *thread)
diff --git a/lib/vty.h b/lib/vty.h
index b758df3e..abac3ddf 100644
--- a/lib/vty.h
+++ b/lib/vty.h
@@ -237,6 +237,7 @@ extern void vty_init_vtysh (void);
extern void vty_terminate (void);
extern void vty_reset (void);
extern struct vty *vty_new (void);
+extern struct vty *vty_stdio (void);
extern int vty_out (struct vty *, const char *, ...) PRINTF_ATTRIBUTE(2, 3);
extern void vty_read_config (char *, char *);
extern void vty_time_print (struct vty *, int);