summaryrefslogtreecommitdiffstats
path: root/lib/vty_io.h
diff options
context:
space:
mode:
authorChris Hall <GMCH@hestia.halldom.com>2010-03-16 01:35:19 +0000
committerChris Hall <GMCH@hestia.halldom.com>2010-03-16 01:35:19 +0000
commitd87a9d74eab06082ea49313083ffa0aa41f666f9 (patch)
tree7c6f7ae0be39683b7c90ea298454ec28d49406cb /lib/vty_io.h
parent05fb7fd0421b395c089bb08dd0e0d78d3746b8cf (diff)
downloadquagga-d87a9d74eab06082ea49313083ffa0aa41f666f9.tar.bz2
quagga-d87a9d74eab06082ea49313083ffa0aa41f666f9.tar.xz
Major update
bgpd/bgp_advertise.c bgpd/bgp_advertise.h The adj_in and adj_out objects are now put on a list based on the peer to whom the route belongs. The adj_in and adj_out objects also now point to the bgp_node which they are routes for. This substantially reduces the work needed to shut down a peer. bgpd/bgp_damp.c Changes to adj_in and adj_out forced small change to macros used in bgp_damp.c to manage its lists. bgpd/bgp_debug.c Replaced direct access to vty->node by the required vty_get_node(). bgpd/bgp_dump.c Changes to the names of fields in bgp_info structures. bgpd/bgp_engine.h Modified the debug and trace functions. bgpd/bgp_fsm.c Make use of sockunion2str() consistent with common usage. Improved some documentation. bgpd/bgp_main.c Use the newly extended qpn_add_hook_function() facility. bgpd/bgp_mplsvpn.c Changes to the names of fields in bgp_info structures. bgpd/bgp_msg_read.c Bug fix: correct handling of capability code length. Improvement: better casting in calculation of message length. bgpd/bgp_msg_write.c Bug fix: correct byte ordering of bgp_id in open message. bgpd/bgp_network.c Bug fix: correct handling of incoming connections. Takes advantage of improvements in sockunion.c. bgpd/bgp_nexthop.c Changes to the names of fields in bgp_info structures. bgpd/bgp_open_state.c Remove mistaken #include of memtypes.h bgpd/bgp_packet.c Improvements to handling of withdrawing routes for peers. bgpd/bgp_peer.c Tidying up the state of peers as they are enabled and disabled. Improvements to handling of withdrawing routes for peers. bgpd/bgp_peer.h Adding list bases for lists of routes originated by the peer. bgpd/bgp_peer_index.c Bug fix: correct freeing of peer indexes. bgpd/bgp_route.c Implement lists of bgp_info based in the owning peer. Adjust for name changes to bgp_info fields. Reimplemented all the clearing functions to use the lists of items that belong to the peer -- rather than searching route tables for stuff to withdraw. Changed work queue handling for added/changed routes, so that queues run through existing items, rather than having queues of auxiliary items -- lower memory overhead. bgpd/bgp_route.h Added fields to bgp_info to allow all bgp_info originated by each peer to live on lists based in the peer. And changed the name of existing fields to avoid confusion. bgpd/bgp_routemap.c Removing redundant code and fixing a memory leak. bgpd/bgp_table.h Based work queue for added/changed routes directly in the table, rather than having auxiliary structures. bgpd/bgp_vty.c Use vty_get_node() and vty_set_node() rather than direct access to the vty field. bgpd/bgpd.c Implement changes to route clearing. bgpd/bgpd.h Changes to work queue handling. lib/buffer.c Changes to allow embedded buffer structures. lib/buffer.h Moved struct buffer here so that could have embedded buffer structurs. lib/command.c Substantial tidy up and document exercise. Restructured the top level command processing and finding of descriptions and command completion. Removal of unpleasant messing around with the insides of vector structures. Movement of some command actions to vty.c. Uses uty.h to pick up the "private" functions from vty.c et al. lib/command.h Moved the "node" values to node_type.h, so that can use an enum node_type in places where cannot include command.h. lib/command_queue.c Updated to cope with the called command changing the node value. Improved handling of revoked commands, so the the command line handler does not get stuck waiting for a command to complete which has been revoked ! lib/command_queue.h Improved message format. lib/if.c Use vty_set_node(). lib/keychain.c Use vty_set_node(). new lib/keystroke.c new lib/keystroke.h New code to implement a keystroke FIFO. This moves some complexity out of the command handler. The handling of mixtures of escapes and Telnet IACs is tightened up. It would be possible to extend this to, say, UTF-8. Regularises the "stealing" of keystrokes for the "--more--" output handling... which was a bit hit and miss. new lib/list_util.c new lib/list_util.h New code to implement various forms of linked list, where the list pointers are embedded in structures. lib/log.c Changed the handling of log messages, so that all types of log output (except syslog) use the same message buffer scheme, and the message is constructed once and once only. Changes to the handling of VTY_LOCK() etc. Uses uty.h to pick up the "private" functions from vty.c et al. lib/log.h Changes to the buffering of log messages. new lib/mem_tracker.c New code to track memory allocation/deallocation, for debug purposes. lib/memory.c lib/memory.h Updated to allow the use of the mem_tracker. lib/memtypes.awk Made the memtypes into a named enum MTYPE. lib/memtypes.c Various new memory types. lib/mqueue.c lib/mqueue.h Add mqueue_finish function for close-down. lib/network.c lib/network.h Added non-blocking read_nb() and write_nb(). new lib/node_type.h As above. lib/plist.c Remove vty_puts() which wasn't a good idea. lib/qlib_init.c Added qps_init() to first stage and mqueue_finish to finish. lib/qpnexus.c lib/qpnexus.h More flexible hooks for in_thread_init and in_thread_final. lib/qpselect.c lib/qpselect.h Added qps_start_up() to build the required maps once and for all. Added qdebug to control the debug checks and validation. Improved validation and test functions. new lib/qstring.c new lib/qstring.h New code for limited flexible string handling. lib/qtimers.c Added qdebug to control the debug checks and validation. lib/routemap.c Use vty_set_node(). lib/sockunion.c lib/sockunion.h Tidied up and regularised the handling of sin_len and sin6_len. Created common function for setting port into socket. Created common function for initialisation/allocation of new sockunion. Reduced various functions by using common sub-functions. Rationalised some code. Added sockunion_listen() and sockunion_new_sockaddr(). Renamed sockunion_new() to sockunion_new_prefix(). Improved some logging messages. Added documentation. new lib/uty.h Functions etc. used only by vty/command/log/vty_io and vty_cli. lib/vector.c lib/vector.h Added vector_t type. Removed VECTOR_INDEX, vector_only_wrapper_free() and vector_only_index_free() -- following improvement of code in command.c. Added vector_set_min_length(), vector_set_new_min_length() and vector_length() functions. new lib/vio_fifo.c new lib/vio_fifo.h New code to manage simple FIFO of indefinite length. lib/vty.c lib/vty.h Reworked. Broken into vty.c, vty_io.c and vty_cli.c. new lib/vty_cli.c new lib/vty_cli.h CLI handling parts of the vty family. new lib/vty_io.c new lib/vty_io.h I/O parts of the vty family. lib/workqueue.h Introduced tyedefs for the various call-back entries. new tests/test-list_util.c Tests for the list-util stuff. vtysh/vtysh.c Small change to interface for cmd_execute_command()
Diffstat (limited to 'lib/vty_io.h')
-rw-r--r--lib/vty_io.h297
1 files changed, 297 insertions, 0 deletions
diff --git a/lib/vty_io.h b/lib/vty_io.h
new file mode 100644
index 00000000..06cefe06
--- /dev/null
+++ b/lib/vty_io.h
@@ -0,0 +1,297 @@
+/* VTY IO Structure and Functions -- header
+ * Virtual terminal [aka TeletYpe] interface routine.
+ * 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_IO_H
+#define _ZEBRA_VTY_IO_H
+
+#include <stdbool.h>
+#include <errno.h>
+
+#include "uty.h"
+#include "vty.h"
+#include "vio_fifo.h"
+#include "keystroke.h"
+#include "thread.h"
+#include "command.h"
+#include "qstring.h"
+
+/*==============================================================================
+ * Here are structures and other definitions which are shared by:
+ *
+ * vty.c -- the main vty handler
+ * vty_cli.c -- which handles the command line stuff
+ * vty_io.c -- ....
+ *
+ * The "struct vty" is used extensively across the Quagga daemons, where it
+ * has two functions relating to command handling as:
+ *
+ * 1) a "file handle" for output produced by commands
+ *
+ * 2) the holder of some context -- notably the current command "node" -- for
+ * command execution to use
+ *
+ * The bulk of "struct vty" is, therefore, private to vty.c and is factored
+ * out into the "struct vty_io".
+ *
+ * To reduce the size of vty.c, some groups of functions are separated into:
+ *
+ * vty_cli.c -- which looks after the keystroke by keystroke handling
+ * of the command line.
+ *
+ */
+
+/*------------------------------------------------------------------------------
+ * VTY file structure
+ *
+ * Used
+ */
+
+typedef int thread_action(struct thread *) ;
+
+union file_action
+{
+ qps_action* qnexus ;
+ thread_action* thread ;
+ void* anon ;
+} ;
+
+union timer_action
+{
+ qtimer_action* qnexus ;
+ thread_action* thread ;
+ void* anon ;
+} ;
+
+struct vio_file_actions
+{
+ union file_action read ;
+ union file_action write ;
+ union timer_action timer ;
+};
+
+typedef struct vio_file* vio_file ;
+struct vio_file
+{
+ int fd ;
+
+ void* info ; /* for action routines */
+
+ struct vio_file_actions action ;
+
+ bool read_open ; /* read returns 0 if not open */
+ bool write_open ; /* write completes instantly if not open */
+ int error_seen ; /* non-zero => failed */
+
+ qps_file qf ; /* when running qnexus */
+
+ struct thread *t_read; /* when running threads */
+ struct thread *t_write;
+
+ unsigned long v_timeout; /* time-out in seconds -- 0 => none */
+ bool timer_running ; /* true when timer is running */
+
+ qtimer qtr; /* when running qnexus */
+ struct thread *t_timer; /* when running threads */
+
+} ;
+
+struct vty_line_control
+{
+ int tba ;
+} ;
+
+enum
+{
+ off = false,
+ on = true
+};
+
+/*------------------------------------------------------------------------------
+ *
+ */
+
+struct vty_io {
+ /* List of all vty_io objects */
+ struct dl_list_pair(vty_io) vio_list ;
+
+ bool half_closed ; /* => on death watch list */
+ bool timed_out ; /* closed by timer */
+
+ /* List of all vty_io that are in monitor state */
+ struct dl_list_pair(vty_io) mon_list ;
+
+ /* The attached to this vty */
+ struct vty* vty ;
+
+ /* Type of VTY */
+ enum vty_type type;
+
+ /* File level stuff */
+ struct vio_file file ;
+
+ /* "name" of the VTY (for VTY_TERM is IP address) */
+ char *name ;
+
+ /* Keystroke stream and raw input buffer */
+ keystroke_stream key_stream ;
+ qstring_t ibuf ;
+
+ /*--------------------------------------------------------------------*/
+ /* Command line and related state */
+
+ /* cli_drawn <=> the current prompt and user input occupy the current
+ * line on the screen.
+ *
+ * If cli_drawn is true, the following are valid:
+ *
+ * cli_prompt_len -- the length of the prompt part.
+ *
+ * cli_extra_len -- the length of any ^X at the cursor position
+ * (for when blocked waiting for queued command)
+ *
+ * cli_echo_suppress -- the user part of the command line is suppressed
+ *
+ * NB: cli_echo_suppress is only used for password entry.
+ */
+ int cli_drawn ;
+
+ int cli_prompt_len ; /* for drawn line (if any) */
+ int cli_extra_len ; /* for for drawn line (if any) */
+
+ bool cli_echo_suppress ; /* non-zero => suppress cli echo */
+
+ /* "cache" for prompt -- when node or host name changes, prompt does */
+ enum node_type cli_prompt_node ;
+ bool cli_prompt_set ;
+ qstring_t cli_prompt_for_node ;
+
+ /* State of the CLI
+ *
+ * cli_blocked -- blocked from processing keystrokes
+ * cmd_in_progress -- command dispatched (may be queued)
+ *
+ * cli_wait_more -- is in "--more--" wait state
+ *
+ */
+ bool cli_blocked ;
+ bool cmd_in_progress ;
+
+ /* Command Line(s)
+ *
+ * cli_do -- when current command being prepared is completed (by
+ * CR/LF or otherwise) this says what there now is to be done.
+ *
+ * cl -- current command line being prepared.
+ *
+ * clx -- current command line being executed.
+ *
+ * NB: during command execution vty->buf is set to point at the '\0'
+ * terminated current command line being executed.
+ */
+ enum cli_do cli_do ;
+
+ qstring_t cl ;
+ qstring_t clx ;
+
+ /* CLI output buffering */
+ qstring_t cli_vbuf ; /* for uty_cli_out */
+ vio_fifo_t cli_obuf ;
+
+ /* Command output buffering */
+ qstring_t cmd_vbuf ; /* for uty_vout() */
+ vio_fifo_t cmd_obuf ;
+
+ bool cmd_wait_more ;
+
+ struct vty_line_control line_control ;
+ /* Failure count for login attempts */
+ int fail;
+
+ /* History of commands */
+ vector_t hist ;
+ int hp ; /* History lookup current point */
+ int hindex; /* History insert end point */
+
+ /* Window width/height. */
+ int width;
+ int height;
+
+ /* Configure lines. */
+ int lines;
+
+ /* Terminal monitor. */
+ bool monitor ;
+
+ /* In configure mode. */
+ bool config;
+} ;
+
+/*==============================================================================
+ * Functions
+ */
+
+extern struct vty*
+uty_new (int fd, enum vty_type type) ;
+
+extern void
+uty_open_listeners(const char *addr, unsigned short port, const char *path) ;
+extern void
+uty_close_listeners(void) ;
+
+extern void
+uty_half_close (vty_io vio) ;
+extern void
+uty_close (vty_io vio) ;
+extern void
+uty_full_close (vty_io vio) ;
+extern void
+uty_watch_dog_stop(void) ;
+
+extern int
+uty_out (struct vty *vty, const char *format, ...) PRINTF_ATTRIBUTE(2, 3) ;
+extern int
+uty_vout(struct vty *vty, const char *format, va_list args) ;
+extern void
+uty_out_discard(vty_io vio) ;
+
+extern void
+uty_file_set_read(vio_file file, bool on) ;
+extern void
+uty_file_set_write(vio_file file, bool on) ;
+extern void
+uty_file_set_timer(vio_file file, unsigned long timeout) ;
+
+extern int
+uty_read (vty_io vio, keystroke steal) ;
+extern int
+utysh_read (vty_io vio, qstring cl, qstring buf) ;
+
+
+extern const char*
+uty_get_name(vty_io vio) ;
+
+extern void
+uty_set_monitor(vty_io vio, bool on) ;
+
+#endif /* _ZEBRA_VTY_IO_H */