1/* 2 * Zebra configuration command interface routine 3 * Copyright (C) 1997, 98 Kunihiro Ishiguro 4 * 5 * This file is part of GNU Zebra. 6 * 7 * GNU Zebra is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published 9 * by the Free Software Foundation; either version 2, or (at your 10 * option) any later version. 11 * 12 * GNU Zebra is distributed in the hope that it will be useful, but 13 * WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with GNU Zebra; see the file COPYING. If not, write to the 19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 * Boston, MA 02111-1307, USA. 21 */ 22 23#ifndef _ZEBRA_COMMAND_H 24#define _ZEBRA_COMMAND_H 25 26#include "vector.h" 27#include "vty.h" 28 29/* Host configuration variable */ 30struct host 31{ 32 /* Host name of this router. */ 33 char *name; 34 35 /* Password for vty interface. */ 36 char *password; 37 char *password_encrypt; 38 39 /* Enable password */ 40 char *enable; 41 char *enable_encrypt; 42 43 /* System wide terminal lines. */ 44 int lines; 45 46 /* Log filename. */ 47 char *logfile; 48 49 /* Log stdout. */ 50 u_char log_stdout; 51 52 /* Log syslog. */ 53 u_char log_syslog; 54 55 /* config file name of this host */ 56 char *config; 57 58 /* Flags for services */ 59 int advanced; 60 int encrypt; 61 62 /* Banner configuration. */ 63 char *motd; 64}; 65 66/* There are some command levels which called from command node. */ 67enum node_type 68{ 69 AUTH_NODE, /* Authentication mode of vty interface. */ 70 VIEW_NODE, /* View node. Default mode of vty interface. */ 71 AUTH_ENABLE_NODE, /* Authentication mode for change enable. */ 72 ENABLE_NODE, /* Enable node. */ 73 CONFIG_NODE, /* Config node. Default mode of config file. */ 74 DEBUG_NODE, /* Debug node. */ 75 AAA_NODE, /* AAA node. */ 76 KEYCHAIN_NODE, /* Key-chain node. */ 77 KEYCHAIN_KEY_NODE, /* Key-chain key node. */ 78 INTERFACE_NODE, /* Interface mode node. */ 79 ZEBRA_NODE, /* zebra connection node. */ 80 TABLE_NODE, /* rtm_table selection node. */ 81 RIP_NODE, /* RIP protocol mode node. */ 82 RIPNG_NODE, /* RIPng protocol mode node. */ 83 BGP_NODE, /* BGP protocol mode which includes BGP4+ */ 84 BGP_VPNV4_NODE, /* BGP MPLS-VPN PE exchange. */ 85 BGP_IPV4_NODE, /* BGP IPv4 unicast address family. */ 86 BGP_IPV4M_NODE, /* BGP IPv4 multicast address family. */ 87 BGP_IPV6_NODE, /* BGP IPv6 address family */ 88 OSPF_NODE, /* OSPF protocol mode */ 89 OSPF6_NODE, /* OSPF protocol for IPv6 mode */ 90 MASC_NODE, /* MASC for multicast. */ 91 IRDP_NODE, /* ICMP Router Discovery Protocol mode. */ 92 IP_NODE, /* Static ip route node. */ 93 ACCESS_NODE, /* Access list node. */ 94 PREFIX_NODE, /* Prefix list node. */ 95 ACCESS_IPV6_NODE, /* Access list node. */ 96 PREFIX_IPV6_NODE, /* Prefix list node. */ 97 AS_LIST_NODE, /* AS list node. */ 98 COMMUNITY_LIST_NODE, /* Community list node. */ 99 RMAP_NODE, /* Route map node. */ 100 SMUX_NODE, /* SNMP configuration node. */ 101 DUMP_NODE, /* Packet dump node. */ 102 FORWARDING_NODE, /* IP forwarding node. */ 103 VTY_NODE /* Vty node. */ 104}; 105 106/* Node which has some commands and prompt string and configuration 107 function pointer . */ 108struct cmd_node 109{ 110 /* Node index. */ 111 enum node_type node; 112 113 /* Prompt character at vty interface. */ 114 char *prompt; 115 116 /* Is this node's configuration goes to vtysh ? */ 117 int vtysh; 118 119 /* Node's configuration write function */ 120 int (*func) (struct vty *); 121 122 /* Vector of this node's command list. */ 123 vector cmd_vector; 124}; 125 126/* Structure of command element. */ 127struct cmd_element 128{ 129 char *string; /* Command specification by string. */ 130 int (*func) (struct cmd_element *, struct vty *, int, char **); 131 char *doc; /* Documentation of this command. */ 132 int daemon; /* Daemon to which this command belong. */ 133 vector strvec; /* Pointing out each description vector. */ 134 int cmdsize; /* Command index count. */ 135 char *config; /* Configuration string */ 136 vector subconfig; /* Sub configuration string */ 137}; 138 139/* Command description structure. */ 140struct desc 141{ 142 char *cmd; /* Command string. */ 143 char *str; /* Command's description. */ 144}; 145 146/* Return value of the commands. */ 147#define CMD_SUCCESS 0 148#define CMD_WARNING 1 149#define CMD_ERR_NO_MATCH 2 150#define CMD_ERR_AMBIGUOUS 3 151#define CMD_ERR_INCOMPLETE 4 152#define CMD_ERR_EXEED_ARGC_MAX 5 153#define CMD_ERR_NOTHING_TODO 6 154#define CMD_COMPLETE_FULL_MATCH 7 155#define CMD_COMPLETE_MATCH 8 156#define CMD_COMPLETE_LIST_MATCH 9 157#define CMD_SUCCESS_DAEMON 10 158 159/* Argc max counts. */ 160#define CMD_ARGC_MAX 25 161 162/* Turn off these macros when uisng cpp with extract.pl */ 163#ifndef VTYSH_EXTRACT_PL 164 165/* DEFUN for vty command interafce. Little bit hacky ;-). */ 166#define DEFUN(funcname, cmdname, cmdstr, helpstr) \ 167 int funcname (struct cmd_element *, struct vty *, int, char **); \ 168 struct cmd_element cmdname = \ 169 { \ 170 cmdstr, \ 171 funcname, \ 172 helpstr \ 173 }; \ 174 int funcname \ 175 (struct cmd_element *self, struct vty *vty, int argc, char **argv) 176 177/* DEFUN_NOSH for commands that vtysh should ignore */ 178#define DEFUN_NOSH(funcname, cmdname, cmdstr, helpstr) \ 179 DEFUN(funcname, cmdname, cmdstr, helpstr) 180 181/* DEFSH for vtysh. */ 182#define DEFSH(daemon, cmdname, cmdstr, helpstr) \ 183 struct cmd_element cmdname = \ 184 { \ 185 cmdstr, \ 186 NULL, \ 187 helpstr, \ 188 daemon \ 189 }; \ 190 191/* DEFUN + DEFSH */ 192#define DEFUNSH(daemon, funcname, cmdname, cmdstr, helpstr) \ 193 int funcname (struct cmd_element *, struct vty *, int, char **); \ 194 struct cmd_element cmdname = \ 195 { \ 196 cmdstr, \ 197 funcname, \ 198 helpstr, \ 199 daemon \ 200 }; \ 201 int funcname \ 202 (struct cmd_element *self, struct vty *vty, int argc, char **argv) 203 204/* ALIAS macro which define existing command's alias. */ 205#define ALIAS(funcname, cmdname, cmdstr, helpstr) \ 206 struct cmd_element cmdname = \ 207 { \ 208 cmdstr, \ 209 funcname, \ 210 helpstr \ 211 }; 212 213#endif /* VTYSH_EXTRACT_PL */ 214 215/* Some macroes */ 216#define CMD_OPTION(S) ((S[0]) == '[') 217#define CMD_VARIABLE(S) (((S[0]) >= 'A' && (S[0]) <= 'Z') || ((S[0]) == '<')) 218#define CMD_VARARG(S) ((S[0]) == '.') 219#define CMD_RANGE(S) ((S[0] == '<')) 220 221#define CMD_IPV4(S) ((strcmp ((S), "A.B.C.D") == 0)) 222#define CMD_IPV4_PREFIX(S) ((strcmp ((S), "A.B.C.D/M") == 0)) 223#define CMD_IPV6(S) ((strcmp ((S), "X:X::X:X") == 0)) 224#define CMD_IPV6_PREFIX(S) ((strcmp ((S), "X:X::X:X/M") == 0)) 225 226/* Common descriptions. */ 227#define SHOW_STR "Show running system information\n" 228#define IP_STR "IP information\n" 229#define IPV6_STR "IPv6 information\n" 230#define NO_STR "Negate a command or set its defaults\n" 231#define CLEAR_STR "Reset functions\n" 232#define RIP_STR "RIP information\n" 233#define BGP_STR "BGP information\n" 234#define OSPF_STR "OSPF information\n" 235#define NEIGHBOR_STR "Specify neighbor router\n" 236#define DEBUG_STR "Debugging functions (see also 'undebug')\n" 237#define UNDEBUG_STR "Disable debugging functions (see also 'debug')\n" 238#define ROUTER_STR "Enable a routing process\n" 239#define AS_STR "AS number\n" 240#define MBGP_STR "MBGP information\n" 241#define MATCH_STR "Match values from routing table\n" 242#define SET_STR "Set values in destination routing protocol\n" 243#define OUT_STR "Filter outgoing routing updates\n" 244#define IN_STR "Filter incoming routing updates\n" 245#define V4NOTATION_STR "specify by IPv4 address notation(e.g. 0.0.0.0)\n" 246#define OSPF6_NUMBER_STR "Specify by number\n" 247#define INTERFACE_STR "Interface infomation\n" 248#define IFNAME_STR "Interface name(e.g. ep0)\n" 249#define IP6_STR "IPv6 Information\n" 250#define OSPF6_STR "Open Shortest Path First (OSPF) for IPv6\n" 251#define OSPF6_ROUTER_STR "Enable a routing process\n" 252#define OSPF6_INSTANCE_STR "<1-65535> Instance ID\n" 253#define SECONDS_STR "<1-65535> Seconds\n" 254#define ROUTE_STR "Routing Table\n" 255#define PREFIX_LIST_STR "Build a prefix list\n" 256#define OSPF6_DUMP_TYPE_LIST \ 257"(neighbor|interface|area|lsa|zebra|config|dbex|spf|route|lsdb|redistribute|hook|asbr|prefix|abr)" 258 259#define CONF_BACKUP_EXT ".sav" 260 261/* IPv4 only machine should not accept IPv6 address for peer's IP 262 address. So we replace VTY command string like below. */ 263#ifdef HAVE_IPV6 264#define NEIGHBOR_CMD "neighbor (A.B.C.D|X:X::X:X) " 265#define NO_NEIGHBOR_CMD "no neighbor (A.B.C.D|X:X::X:X) " 266#define NEIGHBOR_ADDR_STR "Neighbor address\nIPv6 address\n" 267#define NEIGHBOR_CMD2 "neighbor (A.B.C.D|X:X::X:X|WORD) " 268#define NO_NEIGHBOR_CMD2 "no neighbor (A.B.C.D|X:X::X:X|WORD) " 269#define NEIGHBOR_ADDR_STR2 "Neighbor address\nNeighbor IPv6 address\nNeighbor tag\n" 270#else 271#define NEIGHBOR_CMD "neighbor A.B.C.D " 272#define NO_NEIGHBOR_CMD "no neighbor A.B.C.D " 273#define NEIGHBOR_ADDR_STR "Neighbor address\n" 274#define NEIGHBOR_CMD2 "neighbor (A.B.C.D|WORD) " 275#define NO_NEIGHBOR_CMD2 "no neighbor (A.B.C.D|WORD) " 276#define NEIGHBOR_ADDR_STR2 "Neighbor address\nNeighbor tag\n" 277#endif /* HAVE_IPV6 */ 278 279/* Prototypes. */ 280void install_node (struct cmd_node *, int (*) (struct vty *)); 281void install_default (enum node_type); 282void install_element (enum node_type, struct cmd_element *); 283void sort_node (); 284 285char *argv_concat (char **, int, int); 286vector cmd_make_strvec (char *); 287void cmd_free_strvec (vector); 288vector cmd_describe_command (); 289char **cmd_complete_command (); 290char *cmd_prompt (enum node_type); 291int config_from_file (struct vty *, FILE *); 292int cmd_execute_command (vector, struct vty *, struct cmd_element **); 293int cmd_execute_command_strict (vector, struct vty *, struct cmd_element **); 294void config_replace_string (struct cmd_element *, char *, ...); 295void cmd_init (int); 296 297/* Export typical functions. */ 298extern struct cmd_element config_end_cmd; 299extern struct cmd_element config_exit_cmd; 300extern struct cmd_element config_quit_cmd; 301extern struct cmd_element config_help_cmd; 302extern struct cmd_element config_list_cmd; 303int config_exit (struct cmd_element *, struct vty *, int, char **); 304int config_help (struct cmd_element *, struct vty *, int, char **); 305char *host_config_file (); 306void host_config_set (char *); 307 308#endif /* _ZEBRA_COMMAND_H */ 309