summaryrefslogtreecommitdiffstats
path: root/lib/command_common.h
diff options
context:
space:
mode:
authorChris Hall <chris.hall@highwayman.com>2011-02-13 22:53:14 +0000
committerChris Hall <chris.hall@highwayman.com>2011-02-13 22:53:14 +0000
commit64be6d766a65dc0749d17f5023d714678e9c96a6 (patch)
treef97e04068600d0851687b58d25ff198d1eb6cc73 /lib/command_common.h
parent8443ca08672e0cf5b779f59db9d556dadf763de7 (diff)
downloadquagga-ex10p.tar.bz2
quagga-ex10p.tar.xz
Initial commit to seed the "pipework" branchex10p
This is a major revision of the command processing, in order to support new lexical level for command lines, plus all the necessary I/O redirection for the pipes. This is version 0.99.15ex10p. This supports: < filename <+ filename .... > filename .... >> filename .... >* Also contains all lexical level handling of '...', "...." and \x in order to allow use of '>' et al if required. Updated command line completion and help is a work in progress.
Diffstat (limited to 'lib/command_common.h')
-rw-r--r--lib/command_common.h221
1 files changed, 221 insertions, 0 deletions
diff --git a/lib/command_common.h b/lib/command_common.h
new file mode 100644
index 00000000..0f7c4123
--- /dev/null
+++ b/lib/command_common.h
@@ -0,0 +1,221 @@
+/* Command handler node_type stuff -- header
+ * Copyright (C) 1997, 98 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.
+ */
+
+#ifndef _ZEBRA_COMMAND_COMMON_H
+#define _ZEBRA_COMMAND_COMMON_H
+
+#include "misc.h"
+#include "vector.h"
+
+/*------------------------------------------------------------------------------
+ * These are the command levels/contexts.
+ *
+ * NB: this is the order in which configuration is written to the
+ * configuration file.
+ */
+enum node_type
+{
+ NULL_NODE = 0, /* For when need "not a node" */
+
+ AUTH_NODE, /* VTY login -> VIEW_NODE */
+ RESTRICTED_NODE, /* if no login required, may use this node */
+ VIEW_NODE, /* aka user EXEC */
+ AUTH_ENABLE_NODE, /* enable login -> ENABLE_NODE */
+ ENABLE_NODE, /* aka privileged EXEC */
+
+ MIN_DO_SHORTCUT_NODE = ENABLE_NODE,
+ /* May not "do xxx" at any node lower */
+ MAX_NON_CONFIG_NODE = ENABLE_NODE,
+ /* May not be higher than this without owning
+ * the configuration symbol of power */
+
+ CONFIG_NODE, /* aka global configuration mode */
+
+ MIN_CONFIG_NODE = CONFIG_NODE,
+ /* May not change context to any node lower */
+
+ SERVICE_NODE, /* unused ! */
+ DEBUG_NODE, /* debug config write only */
+ AAA_NODE, /* unused ! */
+ KEYCHAIN_NODE, /* see: keychain.c */
+ KEYCHAIN_KEY_NODE, /* see: keychain.c -- child of KEYCHAIN_NODE */
+ INTERFACE_NODE, /* interface commands */
+ ZEBRA_NODE, /* router zebra commands */
+ TABLE_NODE, /* rtm_table config write -- see zserv.c */
+ RIP_NODE, /* router rip commands */
+ RIPNG_NODE, /* router ripng commands */
+ BGP_NODE, /* router bgp commands */
+ BGP_VPNV4_NODE, /* address-family vpnv4 -- child of BGP_NODE */
+ BGP_IPV4_NODE, /* address-family ipv4 (unicast) -- child of BGP_NODE */
+ BGP_IPV4M_NODE, /* address-family ipv4 multicast -- child of BGP_NODE */
+ BGP_IPV6_NODE, /* address-family ipv6 (unicast) -- child of BGP_NODE */
+ BGP_IPV6M_NODE, /* address-family ipv6 multicast -- child of BGP_NODE */
+ OSPF_NODE, /* router ospf commands */
+ OSPF6_NODE, /* router ospf6 commands */
+ ISIS_NODE, /* router isis commands */
+ MASC_NODE, /* unused ! RFC 2909 Multicast Address-Set Claim */
+ IRDP_NODE, /* unused ! ICMP Router Discovery Protocol */
+ IP_NODE, /* zebra_ip_config write only -- see zebra_vty.c */
+ ACCESS_NODE, /* access list config write only -- see filter.c */
+ PREFIX_NODE, /* prefix list config write only -- see plist.c */
+ ACCESS_IPV6_NODE, /* access list config write only -- see filter.c */
+ PREFIX_IPV6_NODE, /* prefix list config write only -- see plist.c */
+ AS_LIST_NODE, /* AS list config write only -- see bgp_filter.c */
+ COMMUNITY_LIST_NODE, /* Community list config write only -- see bgp_vty.c */
+ RMAP_NODE, /* route-map commands */
+ SMUX_NODE, /* SNMP config write only -- see smux.c */
+ DUMP_NODE, /* BGP dump config write only -- see bgp_dump.c */
+ FORWARDING_NODE, /* forwarding config write -- see zserv.c */
+ PROTOCOL_NODE, /* protocol config write -- see zebra_vty.c */
+ VTY_NODE, /* line vty commands */
+} ;
+typedef enum node_type node_type_t ;
+
+/*------------------------------------------------------------------------------
+ * Return values for command handling.
+ *
+ * NB: when a command is executed it may return CMD_SUCCESS, CMD_WARNING
+ * or CMD_ERROR.
+ *
+ * In all cases any output required (including any warning or error
+ * messages) must already have been output.
+ *
+ * CMD_WARNING will stop configuration reader, unless ignore warning
+ * option is set.
+ *
+ * CMD_ERROR will always stop the configuration reader.
+ *
+ * If there is no output and either CMD_WARNING or CMD_ERROR, then will
+ * output a general warning message.
+ *
+ * All other return codes are for use within the command handler.
+ */
+enum cmd_return_code
+{
+ CMD_SUCCESS = 0,
+ CMD_WARNING = 1,
+ CMD_ERROR,
+
+ CMD_IO_ERROR, /* I/O -- failed :-( */
+
+ CMD_SUCCESS_DAEMON, /* parser: success & command is for vtysh ? */
+
+ CMD_CLOSE, /* command: used by "exit" */
+
+ CMD_EMPTY, /* parser: nothing to execute */
+ CMD_WAITING, /* I/O: waiting for more input */
+ CMD_EOF, /* I/O: nothing more to come */
+
+ CMD_ERR_PARSING, /* parser: general parser error */
+ CMD_ERR_NO_MATCH, /* parser: command/argument not recognised */
+ CMD_ERR_AMBIGUOUS, /* parser: more than on command matches */
+ CMD_ERR_INCOMPLETE,
+
+
+ CMD_COMPLETE_FULL_MATCH, /* cmd_completion returns */
+ CMD_COMPLETE_MATCH,
+ CMD_COMPLETE_LIST_MATCH,
+ CMD_COMPLETE_ALREADY
+} ;
+
+typedef enum cmd_return_code cmd_return_code_t ;
+
+/*------------------------------------------------------------------------------
+ * Structure for each node -- root of all commands for the node.
+ *
+ * See install_node().
+ */
+struct vty ; /* Forward reference */
+
+struct cmd_node
+{
+ node_type_t node ; /* who we are */
+
+ const char* prompt ; /* prompt string for vty */
+
+ bool config_to_vtysh ; /* configuration goes to vtysh ? */
+
+ node_type_t parent ; /* parent when parsing commands */
+ node_type_t exit_to ; /* where to go on "exit" */
+ node_type_t end_to ; /* where to go on "end", "^C" or "^Z" */
+
+ int (*config_write) (struct vty*) ; /* configuration write function */
+
+ vector_t cmd_vector; /* Vector of this node's commands. */
+} ;
+
+typedef struct cmd_node cmd_node_t ;
+typedef struct cmd_node* cmd_node ;
+
+/*------------------------------------------------------------------------------
+ * Command elements -- contents of the node's cmd_vector
+ */
+enum cmd_attr
+{
+ CMD_ATTR_SIMPLE = 0, /* bit significant */
+ CMD_ATTR_DEPRECATED = BIT(0),
+ CMD_ATTR_HIDDEN = BIT(1),
+ CMD_ATTR_DIRECT = BIT(2),
+};
+typedef enum cmd_attr cmd_attr_t ;
+
+/* Structure of command element. */
+
+struct cmd_command ;
+typedef struct cmd_command* cmd_command ;
+
+typedef const char* const argv_t[] ;
+
+#define DEFUN_CMD_ARG_UNUSED __attribute__ ((unused))
+#define DEFUN_CMD_FUNCTION(name) \
+ enum cmd_return_code name (cmd_command self DEFUN_CMD_ARG_UNUSED, \
+ struct vty* vty DEFUN_CMD_ARG_UNUSED, \
+ int argc DEFUN_CMD_ARG_UNUSED, \
+ argv_t argv DEFUN_CMD_ARG_UNUSED)
+
+typedef DEFUN_CMD_FUNCTION((cmd_function)) ;
+
+struct cmd_item ; /* Defined in command_parse.h */
+
+struct cmd_command
+{
+ const char* string ; /* Command specification by string. */
+ cmd_function* func ;
+ const char* doc ; /* Documentation of this command. */
+ int daemon ; /* Daemon to which this command belong. */
+ cmd_attr_t attr ; /* Command attributes */
+
+ vector items ; /* Vector of pointers to cmd_item(s) */
+
+ uint nt_min ; /* excluding [option](s) */
+ uint nt ; /* count of all items */
+ uint nt_max ; /* "infinite" if .vararg */
+
+ struct cmd_item* vararg ; /* if there is a vararg item */
+
+ char* r_string ;
+ char* r_doc ;
+
+//char* config ; /* Configuration string */
+//vector subconfig ; /* Sub configuration string */
+};
+
+#endif /* _ZEBRA_COMMAND_COMMON_H */