summaryrefslogtreecommitdiffstats
path: root/lib/command.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/command.h')
-rw-r--r--lib/command.h258
1 files changed, 145 insertions, 113 deletions
diff --git a/lib/command.h b/lib/command.h
index 1275efee..ba7c4bb2 100644
--- a/lib/command.h
+++ b/lib/command.h
@@ -8,7 +8,7 @@
* 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
@@ -23,9 +23,17 @@
#ifndef _ZEBRA_COMMAND_H
#define _ZEBRA_COMMAND_H
+#include <stdbool.h>
+
+#include "node_type.h"
#include "vector.h"
-#include "vty.h"
-#include "lib/route_types.h"
+#include "qstring.h"
+
+#ifndef Inline
+#define Inline static inline
+#endif
+
+struct vty ; /* in case command.h expanded first */
/* Host configuration variable */
struct host
@@ -59,83 +67,90 @@ struct host
char *motdfile;
};
-/* There are some command levels which called from command node. */
-enum node_type
-{
- AUTH_NODE, /* Authentication mode of vty interface. */
- RESTRICTED_NODE, /* Restricted view mode */
- VIEW_NODE, /* View node. Default mode of vty interface. */
- AUTH_ENABLE_NODE, /* Authentication mode for change enable. */
- ENABLE_NODE, /* Enable node. */
- CONFIG_NODE, /* Config node. Default mode of config file. */
- SERVICE_NODE, /* Service node. */
- DEBUG_NODE, /* Debug node. */
- AAA_NODE, /* AAA node. */
- KEYCHAIN_NODE, /* Key-chain node. */
- KEYCHAIN_KEY_NODE, /* Key-chain key node. */
- INTERFACE_NODE, /* Interface mode node. */
- ZEBRA_NODE, /* zebra connection node. */
- TABLE_NODE, /* rtm_table selection node. */
- RIP_NODE, /* RIP protocol mode node. */
- RIPNG_NODE, /* RIPng protocol mode node. */
- BGP_NODE, /* BGP protocol mode which includes BGP4+ */
- BGP_VPNV4_NODE, /* BGP MPLS-VPN PE exchange. */
- BGP_IPV4_NODE, /* BGP IPv4 unicast address family. */
- BGP_IPV4M_NODE, /* BGP IPv4 multicast address family. */
- BGP_IPV6_NODE, /* BGP IPv6 address family */
- BGP_IPV6M_NODE, /* BGP IPv6 multicast address family. */
- OSPF_NODE, /* OSPF protocol mode */
- OSPF6_NODE, /* OSPF protocol for IPv6 mode */
- ISIS_NODE, /* ISIS protocol mode */
- MASC_NODE, /* MASC for multicast. */
- IRDP_NODE, /* ICMP Router Discovery Protocol mode. */
- IP_NODE, /* Static ip route node. */
- ACCESS_NODE, /* Access list node. */
- PREFIX_NODE, /* Prefix list node. */
- ACCESS_IPV6_NODE, /* Access list node. */
- PREFIX_IPV6_NODE, /* Prefix list node. */
- AS_LIST_NODE, /* AS list node. */
- COMMUNITY_LIST_NODE, /* Community list node. */
- RMAP_NODE, /* Route map node. */
- SMUX_NODE, /* SNMP configuration node. */
- DUMP_NODE, /* Packet dump node. */
- FORWARDING_NODE, /* IP forwarding node. */
- PROTOCOL_NODE, /* protocol filtering node */
- VTY_NODE, /* Vty node. */
-};
-
/* Node which has some commands and prompt string and configuration
function pointer . */
-struct cmd_node
+struct cmd_node
{
/* Node index. */
- enum node_type node;
+ enum node_type node;
/* Prompt character at vty interface. */
- const char *prompt;
+ const char *prompt;
/* Is this node's configuration goes to vtysh ? */
int vtysh;
-
+
/* Node's configuration write function */
int (*func) (struct vty *);
/* Vector of this node's command list. */
- vector cmd_vector;
+ vector cmd_vector;
};
enum
{
- CMD_ATTR_DEPRECATED = 1,
- CMD_ATTR_HIDDEN,
+ /* bit significant */
+ CMD_ATTR_DEPRECATED = 0x01,
+ CMD_ATTR_HIDDEN = 0x02,
+ CMD_ATTR_CALL = 0x04,
};
-/* Structure of command element. */
-struct cmd_element
+/* Return values for command handling.
+ *
+ * NB: when a command is executed it may return CMD_SUCCESS or CMD_WARNING.
+ *
+ * In both cases any output required (including any warning or error
+ * messages) must already have been output.
+ *
+ * All other return codes are for use within the command handler.
+ */
+enum cmd_return_code
{
- const char *string; /* Command specification by string. */
- int (*func) (struct cmd_element *, struct vty *, int, const char *[]);
- const char *doc; /* Documentation of this command. */
+ CMD_SUCCESS = 0,
+ CMD_WARNING = 1,
+ CMD_ERROR,
+
+ CMD_EMPTY,
+ CMD_SUCCESS_DAEMON,
+
+ CMD_CLOSE,
+ CMD_QUEUED,
+
+ CMD_ERR_NO_MATCH,
+ CMD_ERR_AMBIGUOUS,
+ CMD_ERR_INCOMPLETE,
+
+ CMD_COMPLETE_FULL_MATCH,
+ CMD_COMPLETE_MATCH,
+ CMD_COMPLETE_LIST_MATCH,
+ CMD_COMPLETE_ALREADY
+} ;
+
+#define MSG_CMD_ERR_AMBIGUOUS "Ambiguous command"
+#define MSG_CMD_ERR_NO_MATCH "Unrecognised command"
+#define MSG_CMD_ERR_NO_MATCH_old "There is no matched command"
+
+/* Structure of command element. */
+
+struct cmd_element ;
+typedef struct cmd_element* cmd_element ;
+
+typedef const char* const argv_t[] ;
+
+#define DEFUN_CMD_ARG_UNUSED __attribute__ ((unused))
+#define DEFUN_CMD_FUNCTION(name) \
+ enum cmd_return_code name (cmd_element 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_element
+{
+ 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. */
vector strvec; /* Pointing out each description vector. */
unsigned int cmdsize; /* Command index count. */
@@ -144,31 +159,57 @@ struct cmd_element
u_char attr; /* Command attributes */
};
-/* Command description structure. */
+/* Command description structure. */
struct desc
{
char *cmd; /* Command string. */
char *str; /* Command's description. */
};
-/* Return value of the commands. */
-#define CMD_SUCCESS 0
-#define CMD_WARNING 1
-#define CMD_ERR_NO_MATCH 2
-#define CMD_ERR_AMBIGUOUS 3
-#define CMD_ERR_INCOMPLETE 4
-#define CMD_ERR_EXEED_ARGC_MAX 5
-#define CMD_ERR_NOTHING_TODO 6
-#define CMD_COMPLETE_FULL_MATCH 7
-#define CMD_COMPLETE_MATCH 8
-#define CMD_COMPLETE_LIST_MATCH 9
-#define CMD_SUCCESS_DAEMON 10
-
-/* Argc max counts. */
-#define CMD_ARGC_MAX 25
+/* Command parsing options */
+enum cmd_parse_type /* bit significant */
+{
+ cmd_parse_completion = 0x00,
+ cmd_parse_strict = 0x01,
+
+ cmd_parse_do = 0x02,
+ cmd_parse_tree = 0x04,
+} ;
+/* Parsed command */
+typedef struct cmd_parsed* cmd_parsed ;
+struct cmd_parsed
+{
+ struct cmd_element *cmd ; /* NULL if empty command
+ or fails to parse */
+
+ enum node_type cnode ; /* node command is in */
+ enum node_type onode ; /* node the parser started in */
+
+ bool do_shortcut ; /* true => is "do" command */
+
+ qstring_t words ; /* the words, '\0' separated */
+
+ vector_t vline ; /* pointers to the words */
+} ;
+
+
+/* Command dispatch options */
+enum {
+ cmd_no_queue = true,
+ cmd_may_queue = false,
+} ;
+
+/*------------------------------------------------------------------------------
+ * Can now include these
+ */
+
+#include "vty.h"
+#include "uty.h"
+
+/*----------------------------------------------------------------------------*/
/* Turn off these macros when uisng cpp with extract.pl */
-#ifndef VTYSH_EXTRACT_PL
+#ifndef VTYSH_EXTRACT_PL
/* helper defines for end-user DEFUN* macros */
#define DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, attrs, dnum) \
@@ -182,14 +223,10 @@ struct desc
};
#define DEFUN_CMD_FUNC_DECL(funcname) \
- static int funcname (struct cmd_element *, struct vty *, int, const char *[]);
+ static cmd_function funcname;
#define DEFUN_CMD_FUNC_TEXT(funcname) \
- static int funcname \
- (struct cmd_element *self __attribute__ ((unused)), \
- struct vty *vty __attribute__ ((unused)), \
- int argc __attribute__ ((unused)), \
- const char *argv[] __attribute__ ((unused)) )
+ static DEFUN_CMD_FUNCTION(funcname)
/* DEFUN for vty command interafce. Little bit hacky ;-). */
#define DEFUN(funcname, cmdname, cmdstr, helpstr) \
@@ -205,8 +242,17 @@ struct desc
#define DEFUN_HIDDEN(funcname, cmdname, cmdstr, helpstr) \
DEFUN_ATTR (funcname, cmdname, cmdstr, helpstr, CMD_ATTR_HIDDEN)
+#define DEFUN_HID_CALL(funcname, cmdname, cmdstr, helpstr) \
+ DEFUN_ATTR (funcname, cmdname, cmdstr, helpstr, (CMD_ATTR_CALL | CMD_ATTR_HIDDEN))
+
#define DEFUN_DEPRECATED(funcname, cmdname, cmdstr, helpstr) \
- DEFUN_ATTR (funcname, cmdname, cmdstr, helpstr, CMD_ATTR_DEPRECATED) \
+ DEFUN_ATTR (funcname, cmdname, cmdstr, helpstr, CMD_ATTR_DEPRECATED)
+
+#define DEFUN_DEP_CALL(funcname, cmdname, cmdstr, helpstr) \
+ DEFUN_ATTR (funcname, cmdname, cmdstr, helpstr, (CMD_ATTR_CALL | CMD_ATTR_DEPRECATED))
+
+#define DEFUN_CALL(funcname, cmdname, cmdstr, helpstr) \
+ DEFUN_ATTR (funcname, cmdname, cmdstr, helpstr, CMD_ATTR_CALL)
/* DEFUN_NOSH for commands that vtysh should ignore */
#define DEFUN_NOSH(funcname, cmdname, cmdstr, helpstr) \
@@ -214,7 +260,7 @@ struct desc
/* DEFSH for vtysh. */
#define DEFSH(daemon, cmdname, cmdstr, helpstr) \
- DEFUN_CMD_ELEMENT(NULL, cmdname, cmdstr, helpstr, 0, daemon) \
+ DEFUN_CMD_ELEMENT(NULL, cmdname, cmdstr, helpstr, 0, daemon)
/* DEFUN + DEFSH */
#define DEFUNSH(daemon, funcname, cmdname, cmdstr, helpstr) \
@@ -247,6 +293,9 @@ struct desc
#define ALIAS_DEPRECATED(funcname, cmdname, cmdstr, helpstr) \
DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, CMD_ATTR_DEPRECATED, 0)
+#define ALIAS_CALL(funcname, cmdname, cmdstr, helpstr) \
+ DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, CMD_ATTR_CALL, 0)
+
#define ALIAS_SH(daemon, funcname, cmdname, cmdstr, helpstr) \
DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, 0, daemon)
@@ -326,6 +375,11 @@ struct desc
#endif /* HAVE_IPV6 */
/* Prototypes. */
+extern void cmd_init (int);
+extern void cmd_terminate (void);
+
+extern void print_version (const char *);
+
extern void install_node (struct cmd_node *, int (*) (struct vty *));
extern void install_default (enum node_type);
extern void install_element (enum node_type, struct cmd_element *);
@@ -334,35 +388,13 @@ extern void sort_node (void);
/* Concatenates argv[shift] through argv[argc-1] into a single NUL-terminated
string with a space between each element (allocated using
XMALLOC(MTYPE_TMP)). Returns NULL if shift >= argc. */
-extern char *argv_concat (const char **argv, int argc, int shift);
-
-extern vector cmd_make_strvec (const char *);
-extern void cmd_free_strvec (vector);
-extern vector cmd_describe_command (vector, struct vty *, int *status);
-extern char **cmd_complete_command (vector, struct vty *, int *status);
-extern const char *cmd_prompt (enum node_type);
-extern int config_from_file (struct vty *, FILE *);
-extern enum node_type node_parent (enum node_type);
-extern int cmd_execute_command (vector, struct vty *, struct cmd_element **, int);
-extern int cmd_execute_command_strict (vector, struct vty *, struct cmd_element **);
-extern void config_replace_string (struct cmd_element *, char *, ...);
-extern void cmd_init (int);
-extern void cmd_terminate (void);
-
-/* Export typical functions. */
-extern struct cmd_element config_end_cmd;
-extern struct cmd_element config_exit_cmd;
-extern struct cmd_element config_quit_cmd;
-extern struct cmd_element config_help_cmd;
-extern struct cmd_element config_list_cmd;
-extern char *host_config_file (void);
-extern void host_config_set (char *);
-
-extern void print_version (const char *);
+extern char *argv_concat (const char* const* argv, int argc, int shift);
/* struct host global, ick */
-extern struct host host;
+extern struct host host;
+
+#ifdef QDEBUG
+extern const char *debug_banner ;
+#endif
-/* "<cr>" global */
-extern char *command_cr;
#endif /* _ZEBRA_COMMAND_H */