summaryrefslogtreecommitdiffstats
path: root/lib/command_common.h
blob: 0f7c41231fe93ac26208fc5048c58768daa700d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
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 */