summaryrefslogtreecommitdiffstats
path: root/lib/vty.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/vty.h')
-rw-r--r--lib/vty.h287
1 files changed, 172 insertions, 115 deletions
diff --git a/lib/vty.h b/lib/vty.h
index 7df04b5f..126218ab 100644
--- a/lib/vty.h
+++ b/lib/vty.h
@@ -1,130 +1,171 @@
-/* Virtual terminal [aka TeletYpe] interface routine
- Copyright (C) 1997 Kunihiro Ishiguro
-
-This file is part of GNU Zebra.
-
-GNU Zebra is free software; you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by the
-Free Software Foundation; either version 2, or (at your option) any
-later version.
-
-GNU Zebra 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
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Zebra; see the file COPYING. If not, write to the Free
-Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA. */
+/* VTY top level
+ * Copyright (C) 1997, 98 Kunihiro Ishiguro
+ *
+ * Revisions: Copyright (C) 2010 Chris Hall (GMCH), Highwayman
+ *
+ * This file is part of GNU Zebra.
+ *
+ * GNU Zebra is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * GNU Zebra 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Zebra; see the file COPYING. If not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
#ifndef _ZEBRA_VTY_H
#define _ZEBRA_VTY_H
+#include <stdbool.h>
+
#include "thread.h"
#include "log.h"
+#include "qpthreads.h"
+#include "qpselect.h"
+#include "qtimers.h"
+#include "qpnexus.h"
+#include "list_util.h"
+#include "vector.h"
+#include "qstring.h"
+#include "node_type.h"
+
+/* Macro in case there are particular compiler issues. */
+#ifndef Inline
+ #define Inline static inline
+#endif
-#define VTY_BUFSIZ 512
-#define VTY_MAXHIST 20
-
-/* VTY struct. */
-struct vty
-{
- /* File descripter of this vty. */
- int fd;
-
- /* Is this vty connect to file or not */
- enum {VTY_TERM, VTY_FILE, VTY_SHELL, VTY_SHELL_SERV} type;
-
- /* Node status of this vty */
- int node;
-
- /* What address is this vty comming from. */
- char *address;
-
- /* Failure count */
- int fail;
-
- /* Output buffer. */
- struct buffer *obuf;
-
- /* Command input buffer */
- char *buf;
-
- /* Command cursor point */
- int cp;
-
- /* Command length */
- int length;
+/*==============================================================================
+ * The VTYSH uses a unix socket to talk to the daemon.
+ *
+ * The ability to respond to a connection from VTYSH appears to be a *compile*
+ * time option. In the interests of keeping the code up to date, the VTYSH
+ * option is turned into a testable constant.
+ */
+#ifdef VTYSH
+# define VTYSH_DEFINED 1
+#else
+# define VTYSH_DEFINED 0
+#endif
- /* Command max length. */
- int max;
+enum { VTYSH_ENABLED = VTYSH_DEFINED } ;
- /* Histry of command */
- char *hist[VTY_MAXHIST];
+#undef VTYSH_DEFINED
- /* History lookup current point */
- int hp;
+/*==============================================================================
+ * VTY Types
+ */
+enum vty_type
+{
+ VTY_NONE = 0, /* no type at all */
- /* History insert end point */
- int hindex;
+ VTY_TERM, /* a telnet terminal -- input and output */
+ VTY_SHELL_SERV, /* a vty_shell slave -- input and output */
- /* For current referencing point of interface, route-map,
- access-list etc... */
- void *index;
+ VTY_CONFIG_READ, /* reading config file -- output is to buffer
+ -- no input */
- /* For multiple level index treatment such as key chain and key. */
- void *index_sub;
+ VTY_CONFIG_WRITE, /* writing config file -- output is to file
+ -- no input */
- /* For escape character. */
- unsigned char escape;
+ VTY_STDOUT, /* general output -- output is to stdout
+ -- no input */
- /* Current vty status. */
- enum {VTY_NORMAL, VTY_CLOSE, VTY_MORE, VTY_MORELINE} status;
+ VTY_STDERR, /* general output -- output is to stderr
+ -- no input */
- /* IAC handling: was the last character received the
- IAC (interpret-as-command) escape character (and therefore the next
- character will be the command code)? Refer to Telnet RFC 854. */
- unsigned char iac;
+ VTY_SHELL, /* vty in vtysh -- output is to stdout */
+} ;
- /* IAC SB (option subnegotiation) handling */
- unsigned char iac_sb_in_progress;
- /* At the moment, we care only about the NAWS (window size) negotiation,
- and that requires just a 5-character buffer (RFC 1073):
- <NAWS char> <16-bit width> <16-bit height> */
-#define TELNET_NAWS_SB_LEN 5
- unsigned char sb_buf[TELNET_NAWS_SB_LEN];
- /* How many subnegotiation characters have we received? We just drop
- those that do not fit in the buffer. */
- size_t sb_len;
+/*==============================================================================
+ * VTY struct.
+ */
- /* Window width/height. */
- int width;
- int height;
+typedef struct vty_io* vty_io ; /* private to vty.c */
- /* Configure lines. */
- int lines;
+struct cmd_parsed ; /* in case vty.h expanded before command.h */
- /* Terminal monitor. */
- int monitor;
+struct vty
+{
+ /*----------------------------------------------------------------------
+ * The following are the context in which commands are executed.
+ */
+
+ /* Node status of this vty
+ *
+ * NB: when using qpthreads should lock VTY to access this -- so use
+ * vty_get_node() and vty_set_node().
+ */
+ enum node_type node ;
+
+ /* For current referencing point of interface, route-map, access-list
+ * etc...
+ *
+ * NB: this value is private to the command execution, which is assumed
+ * to all be in the one thread... so no lock required.
+ */
+ void *index ;
+
+ /* For multiple level index treatment such as key chain and key.
+ *
+ * NB: this value is private to the command execution, which is assumed
+ * to all be in the one thread... so no lock required.
+ */
+ void *index_sub ;
+
+ /* String which is newline... read only -- no locking */
+ const char* newline ;
+
+ /*----------------------------------------------------------------------------
+ * The current command line.
+ *
+ * These are set when a command is parsed and dispatched.
+ *
+ * They are not touched until the command completes -- so may be read while
+ * the command is being parsed and executed.
+ */
+ const char* buf ;
+ struct cmd_parsed* parsed ;
+ unsigned lineno ;
+
+ /*----------------------------------------------------------------------
+ * The following are used inside vty.c only.
+ */
+
+ /* Pointer to related vty_io structure */
+ vty_io vio ;
+};
- /* In configure mode. */
- int config;
+/*------------------------------------------------------------------------------
+ * Can now include this
+ */
- /* Read and write thread. */
- struct thread *t_read;
- struct thread *t_write;
+#include "command.h"
- /* Timeout seconds and thread. */
- unsigned long v_timeout;
- struct thread *t_timeout;
-};
+/*------------------------------------------------------------------------------
+ *
+ */
+#define VTY_BUFSIZ 512
+#define VTY_MAXHIST 51
/* Integrated configuration file. */
#define INTEGRATE_DEFAULT_CONFIG "Quagga.conf"
/* Small macro to determine newline is newline only or linefeed needed. */
-#define VTY_NEWLINE ((vty->type == VTY_TERM) ? "\r\n" : "\n")
+#define VTY_NEWLINE (((vty) != NULL) ? (vty)->newline : "\n")
+
+/* For indenting, mostly. */
+extern const char vty_spaces_string[] ;
+enum { VTY_MAX_SPACES = 40 } ;
+#define VTY_SPACES(n) (vty_spaces_string + ((n) < VTY_MAX_SPACES \
+ ? VTY_MAX_SPACES - (n) : 0))
/* Default time out value */
#define VTY_TIMEOUT_DEFAULT 600
@@ -197,31 +238,47 @@ do {
} \
} while (0)
-/* Exported variables */
+/*------------------------------------------------------------------------------
+ * Exported variables
+ */
extern char integrate_default[];
-/* Prototypes. */
+/*------------------------------------------------------------------------------
+ * Prototypes.
+ */
extern void vty_init (struct thread_master *);
+extern void vty_init_r (qpn_nexus, qpn_nexus);
+extern void vty_start(const char *addr, unsigned short port, const char *path) ;
+#define vty_serv_sock(addr, port, path) vty_start(addr, port, path)
+extern void vty_restart(const char *addr, unsigned short port,
+ const char *path) ;
+extern struct vty* vty_open(enum vty_type type) ;
+extern void vty_close(struct vty *);
+
extern void vty_init_vtysh (void);
extern void vty_terminate (void);
extern void vty_reset (void);
-extern struct vty *vty_new (void);
+extern void vty_reset_because(const char* why) ;
+
extern int vty_out (struct vty *, const char *, ...) PRINTF_ATTRIBUTE(2, 3);
-extern void vty_read_config (char *, char *);
+extern void vty_out_indent(struct vty *vty, int indent) ;
+extern void vty_out_clear(struct vty *vty) ;
+
+extern void vty_read_config (char *config_file, char *config_default);
+extern void vty_read_config_first_cmd_special(
+ char *config_file, char *config_default,
+ struct cmd_element* first_cmd, bool ignore_warnings) ;
+
extern void vty_time_print (struct vty *, int);
-extern void vty_serv_sock (const char *, unsigned short, const char *);
-extern void vty_close (struct vty *);
+
extern char *vty_get_cwd (void);
-extern void vty_log (const char *level, const char *proto,
- const char *fmt, struct timestamp_control *, va_list);
-extern int vty_config_lock (struct vty *);
-extern int vty_config_unlock (struct vty *);
-extern int vty_shell (struct vty *);
-extern int vty_shell_serv (struct vty *);
-extern void vty_hello (struct vty *);
-/* Send a fixed-size message to all vty terminal monitors; this should be
- an async-signal-safe function. */
-extern void vty_log_fixed (const char *buf, size_t len);
+extern bool vty_shell (struct vty *);
+extern bool vty_term (struct vty *);
+extern bool vty_shell_serv (struct vty *);
+extern void vty_hello (struct vty *);
+extern enum node_type vty_get_node(struct vty *);
+extern void vty_set_node(struct vty *, enum node_type);
+extern void vty_set_lines(struct vty *, int);
#endif /* _ZEBRA_VTY_H */