paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* Virtual terminal interface shell. |
| 2 | * Copyright (C) 2000 Kunihiro Ishiguro |
| 3 | * |
| 4 | * This file is part of GNU Zebra. |
| 5 | * |
| 6 | * GNU Zebra is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License as published by the |
| 8 | * Free Software Foundation; either version 2, or (at your option) any |
| 9 | * later version. |
| 10 | * |
| 11 | * GNU Zebra is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with GNU Zebra; see the file COPYING. If not, write to the Free |
| 18 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 19 | * 02111-1307, USA. |
| 20 | */ |
| 21 | |
| 22 | #include <zebra.h> |
| 23 | |
| 24 | #include <sys/un.h> |
| 25 | #include <setjmp.h> |
| 26 | #include <sys/wait.h> |
| 27 | #include <sys/resource.h> |
| 28 | #include <sys/stat.h> |
| 29 | |
| 30 | #include <readline/readline.h> |
| 31 | #include <readline/history.h> |
| 32 | |
| 33 | #include "command.h" |
| 34 | #include "memory.h" |
| 35 | #include "vtysh/vtysh.h" |
ajs | 6099b3b | 2004-11-20 02:06:59 +0000 | [diff] [blame] | 36 | #include "log.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 37 | |
| 38 | /* Struct VTY. */ |
| 39 | struct vty *vty; |
| 40 | |
| 41 | /* VTY shell pager name. */ |
| 42 | char *vtysh_pager_name = NULL; |
| 43 | |
| 44 | /* VTY shell client structure. */ |
| 45 | struct vtysh_client |
| 46 | { |
| 47 | int fd; |
ajs | b1aa147 | 2005-01-28 21:11:46 +0000 | [diff] [blame] | 48 | const char *name; |
| 49 | int flag; |
| 50 | const char *path; |
| 51 | } vtysh_client[] = |
| 52 | { |
| 53 | { .fd = -1, .name = "zebra", .flag = VTYSH_ZEBRA, .path = ZEBRA_VTYSH_PATH}, |
| 54 | { .fd = -1, .name = "ripd", .flag = VTYSH_RIPD, .path = RIP_VTYSH_PATH}, |
| 55 | { .fd = -1, .name = "ripngd", .flag = VTYSH_RIPNGD, .path = RIPNG_VTYSH_PATH}, |
| 56 | { .fd = -1, .name = "ospfd", .flag = VTYSH_OSPFD, .path = OSPF_VTYSH_PATH}, |
| 57 | { .fd = -1, .name = "ospf6d", .flag = VTYSH_OSPF6D, .path = OSPF6_VTYSH_PATH}, |
| 58 | { .fd = -1, .name = "bgpd", .flag = VTYSH_BGPD, .path = BGP_VTYSH_PATH}, |
| 59 | { .fd = -1, .name = "isisd", .flag = VTYSH_ISISD, .path = ISIS_VTYSH_PATH}, |
| 60 | }; |
| 61 | |
| 62 | #define VTYSH_INDEX_MAX (sizeof(vtysh_client)/sizeof(vtysh_client[0])) |
| 63 | |
| 64 | /* We need direct access to ripd to implement vtysh_exit_ripd_only. */ |
| 65 | static struct vtysh_client *ripd_client = NULL; |
| 66 | |
hasso | b094d26 | 2004-08-25 12:22:00 +0000 | [diff] [blame] | 67 | |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 68 | /* Using integrated config from Quagga.conf. Default is no. */ |
| 69 | int vtysh_writeconfig_integrated = 0; |
| 70 | |
| 71 | extern char config_default[]; |
| 72 | |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 73 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 74 | vclient_close (struct vtysh_client *vclient) |
| 75 | { |
ajs | b1aa147 | 2005-01-28 21:11:46 +0000 | [diff] [blame] | 76 | if (vclient->fd >= 0) |
| 77 | { |
| 78 | fprintf(stderr, |
| 79 | "Warning: closing connection to %s because of an I/O error!\n", |
| 80 | vclient->name); |
| 81 | close (vclient->fd); |
| 82 | vclient->fd = -1; |
| 83 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 84 | } |
| 85 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 86 | /* Following filled with debug code to trace a problematic condition |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 87 | * under load - it SHOULD handle it. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 88 | #define ERR_WHERE_STRING "vtysh(): vtysh_client_config(): " |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 89 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 90 | vtysh_client_config (struct vtysh_client *vclient, char *line) |
| 91 | { |
| 92 | int ret; |
| 93 | char *buf; |
| 94 | size_t bufsz; |
| 95 | char *pbuf; |
| 96 | size_t left; |
| 97 | char *eoln; |
| 98 | int nbytes; |
| 99 | int i; |
| 100 | int readln; |
| 101 | |
| 102 | if (vclient->fd < 0) |
| 103 | return CMD_SUCCESS; |
| 104 | |
| 105 | ret = write (vclient->fd, line, strlen (line) + 1); |
| 106 | if (ret <= 0) |
| 107 | { |
| 108 | vclient_close (vclient); |
| 109 | return CMD_SUCCESS; |
| 110 | } |
| 111 | |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 112 | /* Allow enough room for buffer to read more than a few pages from socket. */ |
paul | e3d29b5 | 2003-01-23 18:05:42 +0000 | [diff] [blame] | 113 | bufsz = 5 * getpagesize() + 1; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 114 | buf = XMALLOC(MTYPE_TMP, bufsz); |
| 115 | memset(buf, 0, bufsz); |
| 116 | pbuf = buf; |
| 117 | |
| 118 | while (1) |
| 119 | { |
| 120 | if (pbuf >= ((buf + bufsz) -1)) |
| 121 | { |
| 122 | fprintf (stderr, ERR_WHERE_STRING \ |
| 123 | "warning - pbuf beyond buffer end.\n"); |
| 124 | return CMD_WARNING; |
| 125 | } |
| 126 | |
| 127 | readln = (buf + bufsz) - pbuf - 1; |
| 128 | nbytes = read (vclient->fd, pbuf, readln); |
| 129 | |
| 130 | if (nbytes <= 0) |
| 131 | { |
| 132 | |
| 133 | if (errno == EINTR) |
| 134 | continue; |
| 135 | |
| 136 | fprintf(stderr, ERR_WHERE_STRING "(%u)", errno); |
| 137 | perror(""); |
| 138 | |
| 139 | if (errno == EAGAIN || errno == EIO) |
| 140 | continue; |
| 141 | |
| 142 | vclient_close (vclient); |
| 143 | XFREE(MTYPE_TMP, buf); |
| 144 | return CMD_SUCCESS; |
| 145 | } |
| 146 | |
| 147 | pbuf[nbytes] = '\0'; |
| 148 | |
| 149 | if (nbytes >= 4) |
| 150 | { |
| 151 | i = nbytes - 4; |
| 152 | if (pbuf[i] == '\0' && pbuf[i + 1] == '\0' && pbuf[i + 2] == '\0') |
| 153 | { |
| 154 | ret = pbuf[i + 3]; |
| 155 | break; |
| 156 | } |
| 157 | } |
| 158 | pbuf += nbytes; |
| 159 | |
| 160 | /* See if a line exists in buffer, if so parse and consume it, and |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 161 | * reset read position. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 162 | if ((eoln = strrchr(buf, '\n')) == NULL) |
| 163 | continue; |
| 164 | |
| 165 | if (eoln >= ((buf + bufsz) - 1)) |
| 166 | { |
| 167 | fprintf (stderr, ERR_WHERE_STRING \ |
| 168 | "warning - eoln beyond buffer end.\n"); |
| 169 | } |
| 170 | vtysh_config_parse(buf); |
| 171 | |
| 172 | eoln++; |
| 173 | left = (size_t)(buf + bufsz - eoln); |
| 174 | memmove(buf, eoln, left); |
| 175 | buf[bufsz-1] = '\0'; |
| 176 | pbuf = buf + strlen(buf); |
| 177 | } |
| 178 | |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 179 | /* Parse anything left in the buffer. */ |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 180 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 181 | vtysh_config_parse (buf); |
| 182 | |
| 183 | XFREE(MTYPE_TMP, buf); |
| 184 | return ret; |
| 185 | } |
| 186 | |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 187 | static int |
hasso | dda0952 | 2004-10-07 21:40:25 +0000 | [diff] [blame] | 188 | vtysh_client_execute (struct vtysh_client *vclient, const char *line, FILE *fp) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 189 | { |
| 190 | int ret; |
| 191 | char buf[1001]; |
| 192 | int nbytes; |
paul | 2852de1 | 2004-09-17 06:52:16 +0000 | [diff] [blame] | 193 | int i; |
| 194 | int numnulls = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 195 | |
| 196 | if (vclient->fd < 0) |
| 197 | return CMD_SUCCESS; |
| 198 | |
| 199 | ret = write (vclient->fd, line, strlen (line) + 1); |
| 200 | if (ret <= 0) |
| 201 | { |
| 202 | vclient_close (vclient); |
| 203 | return CMD_SUCCESS; |
| 204 | } |
| 205 | |
| 206 | while (1) |
| 207 | { |
| 208 | nbytes = read (vclient->fd, buf, sizeof(buf)-1); |
| 209 | |
| 210 | if (nbytes <= 0 && errno != EINTR) |
| 211 | { |
| 212 | vclient_close (vclient); |
| 213 | return CMD_SUCCESS; |
| 214 | } |
| 215 | |
| 216 | if (nbytes > 0) |
| 217 | { |
ajs | 85fb1e6 | 2004-11-11 14:03:39 +0000 | [diff] [blame] | 218 | if ((numnulls == 3) && (nbytes == 1)) |
| 219 | return buf[0]; |
| 220 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 221 | buf[nbytes] = '\0'; |
ajs | 85fb1e6 | 2004-11-11 14:03:39 +0000 | [diff] [blame] | 222 | fputs (buf, fp); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 223 | fflush (fp); |
paul | 2852de1 | 2004-09-17 06:52:16 +0000 | [diff] [blame] | 224 | |
paul | 0921d48 | 2004-10-11 18:21:55 +0000 | [diff] [blame] | 225 | /* check for trailling \0\0\0<ret code>, |
| 226 | * even if split across reads |
| 227 | * (see lib/vty.c::vtysh_read) |
| 228 | */ |
paul | 2852de1 | 2004-09-17 06:52:16 +0000 | [diff] [blame] | 229 | if (nbytes >= 4) |
| 230 | { |
| 231 | i = nbytes-4; |
| 232 | numnulls = 0; |
| 233 | } |
| 234 | else |
| 235 | i = 0; |
| 236 | |
paul | 0921d48 | 2004-10-11 18:21:55 +0000 | [diff] [blame] | 237 | while (i < nbytes && numnulls < 3) |
paul | 2852de1 | 2004-09-17 06:52:16 +0000 | [diff] [blame] | 238 | { |
| 239 | if (buf[i++] == '\0') |
| 240 | numnulls++; |
| 241 | else |
ajs | 85fb1e6 | 2004-11-11 14:03:39 +0000 | [diff] [blame] | 242 | numnulls = 0; |
paul | 2852de1 | 2004-09-17 06:52:16 +0000 | [diff] [blame] | 243 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 244 | |
ajs | 85fb1e6 | 2004-11-11 14:03:39 +0000 | [diff] [blame] | 245 | /* got 3 or more trailing NULs? */ |
| 246 | if ((numnulls >= 3) && (i < nbytes)) |
paul | 0921d48 | 2004-10-11 18:21:55 +0000 | [diff] [blame] | 247 | return (buf[nbytes-1]); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 248 | } |
| 249 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | void |
ajs | b1aa147 | 2005-01-28 21:11:46 +0000 | [diff] [blame] | 253 | vtysh_exit_ripd_only (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 254 | { |
ajs | b1aa147 | 2005-01-28 21:11:46 +0000 | [diff] [blame] | 255 | if (ripd_client) |
| 256 | vtysh_client_execute (ripd_client, "exit", stdout); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | |
| 260 | void |
ajs | b1aa147 | 2005-01-28 21:11:46 +0000 | [diff] [blame] | 261 | vtysh_pager_init (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 262 | { |
hasso | 5a9c53d | 2004-08-27 14:23:28 +0000 | [diff] [blame] | 263 | char *pager_defined; |
| 264 | |
| 265 | pager_defined = getenv ("VTYSH_PAGER"); |
| 266 | |
| 267 | if (pager_defined) |
| 268 | vtysh_pager_name = strdup (pager_defined); |
| 269 | else |
hasso | 34553cc | 2004-08-27 13:56:39 +0000 | [diff] [blame] | 270 | vtysh_pager_name = strdup ("more"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | /* Command execution over the vty interface. */ |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 274 | static void |
hasso | dda0952 | 2004-10-07 21:40:25 +0000 | [diff] [blame] | 275 | vtysh_execute_func (const char *line, int pager) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 276 | { |
| 277 | int ret, cmd_stat; |
ajs | b1aa147 | 2005-01-28 21:11:46 +0000 | [diff] [blame] | 278 | u_int i; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 279 | vector vline; |
| 280 | struct cmd_element *cmd; |
| 281 | FILE *fp = NULL; |
hasso | 13bfca7 | 2005-01-23 21:42:25 +0000 | [diff] [blame] | 282 | int closepager = 0; |
| 283 | int tried = 0; |
| 284 | int saved_ret, saved_node; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 285 | |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 286 | /* Split readline string up into the vector. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 287 | vline = cmd_make_strvec (line); |
| 288 | |
| 289 | if (vline == NULL) |
| 290 | return; |
| 291 | |
hasso | 13bfca7 | 2005-01-23 21:42:25 +0000 | [diff] [blame] | 292 | saved_ret = ret = cmd_execute_command (vline, vty, &cmd, 1); |
| 293 | saved_node = vty->node; |
| 294 | |
| 295 | /* If command doesn't succeeded in current node, try to walk up in node tree. |
| 296 | * Changing vty->node is enough to try it just out without actual walkup in |
| 297 | * the vtysh. */ |
| 298 | while (ret != CMD_SUCCESS && ret != CMD_SUCCESS_DAEMON && ret != CMD_WARNING |
| 299 | && vty->node > CONFIG_NODE) |
| 300 | { |
| 301 | vty->node = node_parent(vty->node); |
| 302 | ret = cmd_execute_command (vline, vty, &cmd, 1); |
| 303 | tried++; |
| 304 | } |
| 305 | |
| 306 | vty->node = saved_node; |
| 307 | |
| 308 | /* If command succeeded in any other node than current (tried > 0) we have |
| 309 | * to move into node in the vtysh where it succeeded. */ |
| 310 | if (ret == CMD_SUCCESS || ret == CMD_SUCCESS_DAEMON || ret == CMD_WARNING) |
| 311 | { |
| 312 | if ((saved_node == BGP_VPNV4_NODE || saved_node == BGP_IPV4_NODE |
paul | 57b5b7e | 2005-08-22 22:44:29 +0000 | [diff] [blame] | 313 | || saved_node == BGP_IPV6_NODE || saved_node == BGP_IPV4M_NODE |
| 314 | || saved_node == BGP_IPV6M_NODE) |
hasso | 13bfca7 | 2005-01-23 21:42:25 +0000 | [diff] [blame] | 315 | && (tried == 1)) |
| 316 | { |
| 317 | vtysh_execute("exit-address-family"); |
| 318 | } |
| 319 | else if ((saved_node == KEYCHAIN_KEY_NODE) && (tried == 1)) |
| 320 | { |
| 321 | vtysh_execute("exit"); |
| 322 | } |
| 323 | else if (tried) |
| 324 | { |
| 325 | vtysh_execute ("end"); |
| 326 | vtysh_execute ("configure terminal"); |
| 327 | } |
| 328 | } |
| 329 | /* If command didn't succeed in any node, continue with return value from |
| 330 | * first try. */ |
| 331 | else if (tried) |
| 332 | { |
| 333 | ret = saved_ret; |
| 334 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 335 | |
| 336 | cmd_free_strvec (vline); |
| 337 | |
| 338 | switch (ret) |
| 339 | { |
| 340 | case CMD_WARNING: |
| 341 | if (vty->type == VTY_FILE) |
paul | 4fc01e6 | 2002-12-13 20:49:00 +0000 | [diff] [blame] | 342 | fprintf (stdout,"Warning...\n"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 343 | break; |
| 344 | case CMD_ERR_AMBIGUOUS: |
paul | 4fc01e6 | 2002-12-13 20:49:00 +0000 | [diff] [blame] | 345 | fprintf (stdout,"%% Ambiguous command.\n"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 346 | break; |
| 347 | case CMD_ERR_NO_MATCH: |
paul | 4fc01e6 | 2002-12-13 20:49:00 +0000 | [diff] [blame] | 348 | fprintf (stdout,"%% Unknown command.\n"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 349 | break; |
| 350 | case CMD_ERR_INCOMPLETE: |
paul | 4fc01e6 | 2002-12-13 20:49:00 +0000 | [diff] [blame] | 351 | fprintf (stdout,"%% Command incomplete.\n"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 352 | break; |
| 353 | case CMD_SUCCESS_DAEMON: |
| 354 | { |
hasso | 97b7db2 | 2004-10-20 19:07:48 +0000 | [diff] [blame] | 355 | /* FIXME: Don't open pager for exit commands. popen() causes problems |
| 356 | * if exited from vtysh at all. This hack shouldn't cause any problem |
| 357 | * but is really ugly. */ |
| 358 | if (pager && vtysh_pager_name && (strncmp(line, "exit", 4) != 0)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 359 | { |
paul | 4fc01e6 | 2002-12-13 20:49:00 +0000 | [diff] [blame] | 360 | fp = popen (vtysh_pager_name, "w"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 361 | if (fp == NULL) |
| 362 | { |
paul | a805cc2 | 2003-05-01 14:29:48 +0000 | [diff] [blame] | 363 | perror ("popen failed for pager"); |
| 364 | fp = stdout; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 365 | } |
paul | a805cc2 | 2003-05-01 14:29:48 +0000 | [diff] [blame] | 366 | else |
| 367 | closepager=1; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 368 | } |
| 369 | else |
| 370 | fp = stdout; |
| 371 | |
| 372 | if (! strcmp(cmd->string,"configure terminal")) |
| 373 | { |
ajs | b1aa147 | 2005-01-28 21:11:46 +0000 | [diff] [blame] | 374 | for (i = 0; i < VTYSH_INDEX_MAX; i++) |
| 375 | { |
| 376 | cmd_stat = vtysh_client_execute(&vtysh_client[i], line, fp); |
| 377 | if (cmd_stat == CMD_WARNING) |
| 378 | break; |
| 379 | } |
| 380 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 381 | if (cmd_stat) |
| 382 | { |
hasso | b094d26 | 2004-08-25 12:22:00 +0000 | [diff] [blame] | 383 | line = "end"; |
| 384 | vline = cmd_make_strvec (line); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 385 | |
hasso | b094d26 | 2004-08-25 12:22:00 +0000 | [diff] [blame] | 386 | if (vline == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 387 | { |
paul | a805cc2 | 2003-05-01 14:29:48 +0000 | [diff] [blame] | 388 | if (pager && vtysh_pager_name && fp && closepager) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 389 | { |
| 390 | if (pclose (fp) == -1) |
| 391 | { |
paul | a805cc2 | 2003-05-01 14:29:48 +0000 | [diff] [blame] | 392 | perror ("pclose failed for pager"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 393 | } |
| 394 | fp = NULL; |
| 395 | } |
| 396 | return; |
| 397 | } |
| 398 | |
hasso | 87d683b | 2005-01-16 23:31:54 +0000 | [diff] [blame] | 399 | ret = cmd_execute_command (vline, vty, &cmd, 1); |
hasso | b094d26 | 2004-08-25 12:22:00 +0000 | [diff] [blame] | 400 | cmd_free_strvec (vline); |
| 401 | if (ret != CMD_SUCCESS_DAEMON) |
| 402 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 403 | } |
| 404 | else |
| 405 | if (cmd->func) |
| 406 | { |
| 407 | (*cmd->func) (cmd, vty, 0, NULL); |
| 408 | break; |
hasso | b094d26 | 2004-08-25 12:22:00 +0000 | [diff] [blame] | 409 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 410 | } |
| 411 | |
ajs | b1aa147 | 2005-01-28 21:11:46 +0000 | [diff] [blame] | 412 | cmd_stat = CMD_SUCCESS; |
| 413 | for (i = 0; i < VTYSH_INDEX_MAX; i++) |
| 414 | { |
| 415 | if (cmd->daemon & vtysh_client[i].flag) |
| 416 | { |
| 417 | cmd_stat = vtysh_client_execute(&vtysh_client[i], line, fp); |
| 418 | if (cmd_stat != CMD_SUCCESS) |
| 419 | break; |
| 420 | } |
| 421 | } |
| 422 | if (cmd_stat != CMD_SUCCESS) |
| 423 | break; |
| 424 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 425 | if (cmd->func) |
| 426 | (*cmd->func) (cmd, vty, 0, NULL); |
| 427 | } |
| 428 | } |
paul | a805cc2 | 2003-05-01 14:29:48 +0000 | [diff] [blame] | 429 | if (pager && vtysh_pager_name && fp && closepager) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 430 | { |
| 431 | if (pclose (fp) == -1) |
| 432 | { |
paul | a805cc2 | 2003-05-01 14:29:48 +0000 | [diff] [blame] | 433 | perror ("pclose failed for pager"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 434 | } |
| 435 | fp = NULL; |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | void |
hasso | dda0952 | 2004-10-07 21:40:25 +0000 | [diff] [blame] | 440 | vtysh_execute_no_pager (const char *line) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 441 | { |
| 442 | vtysh_execute_func (line, 0); |
| 443 | } |
| 444 | |
| 445 | void |
hasso | dda0952 | 2004-10-07 21:40:25 +0000 | [diff] [blame] | 446 | vtysh_execute (const char *line) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 447 | { |
| 448 | vtysh_execute_func (line, 1); |
| 449 | } |
| 450 | |
| 451 | /* Configration make from file. */ |
| 452 | int |
| 453 | vtysh_config_from_file (struct vty *vty, FILE *fp) |
| 454 | { |
| 455 | int ret; |
| 456 | vector vline; |
| 457 | struct cmd_element *cmd; |
| 458 | |
| 459 | while (fgets (vty->buf, VTY_BUFSIZ, fp)) |
| 460 | { |
| 461 | if (vty->buf[0] == '!' || vty->buf[1] == '#') |
| 462 | continue; |
| 463 | |
| 464 | vline = cmd_make_strvec (vty->buf); |
| 465 | |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 466 | /* In case of comment line. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 467 | if (vline == NULL) |
| 468 | continue; |
| 469 | |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 470 | /* Execute configuration command : this is strict match. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 471 | ret = cmd_execute_command_strict (vline, vty, &cmd); |
| 472 | |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 473 | /* Try again with setting node to CONFIG_NODE. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 474 | if (ret != CMD_SUCCESS |
| 475 | && ret != CMD_SUCCESS_DAEMON |
| 476 | && ret != CMD_WARNING) |
| 477 | { |
| 478 | if (vty->node == KEYCHAIN_KEY_NODE) |
| 479 | { |
| 480 | vty->node = KEYCHAIN_NODE; |
| 481 | vtysh_exit_ripd_only (); |
| 482 | ret = cmd_execute_command_strict (vline, vty, &cmd); |
| 483 | |
| 484 | if (ret != CMD_SUCCESS |
| 485 | && ret != CMD_SUCCESS_DAEMON |
| 486 | && ret != CMD_WARNING) |
| 487 | { |
| 488 | vtysh_exit_ripd_only (); |
| 489 | vty->node = CONFIG_NODE; |
| 490 | ret = cmd_execute_command_strict (vline, vty, &cmd); |
| 491 | } |
| 492 | } |
| 493 | else |
| 494 | { |
| 495 | vtysh_execute ("end"); |
| 496 | vtysh_execute ("configure terminal"); |
| 497 | vty->node = CONFIG_NODE; |
| 498 | ret = cmd_execute_command_strict (vline, vty, &cmd); |
| 499 | } |
| 500 | } |
| 501 | |
| 502 | cmd_free_strvec (vline); |
| 503 | |
| 504 | switch (ret) |
| 505 | { |
| 506 | case CMD_WARNING: |
| 507 | if (vty->type == VTY_FILE) |
paul | 4fc01e6 | 2002-12-13 20:49:00 +0000 | [diff] [blame] | 508 | fprintf (stdout,"Warning...\n"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 509 | break; |
| 510 | case CMD_ERR_AMBIGUOUS: |
paul | 4fc01e6 | 2002-12-13 20:49:00 +0000 | [diff] [blame] | 511 | fprintf (stdout,"%% Ambiguous command.\n"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 512 | break; |
| 513 | case CMD_ERR_NO_MATCH: |
paul | 4fc01e6 | 2002-12-13 20:49:00 +0000 | [diff] [blame] | 514 | fprintf (stdout,"%% Unknown command: %s", vty->buf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 515 | break; |
| 516 | case CMD_ERR_INCOMPLETE: |
paul | 4fc01e6 | 2002-12-13 20:49:00 +0000 | [diff] [blame] | 517 | fprintf (stdout,"%% Command incomplete.\n"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 518 | break; |
| 519 | case CMD_SUCCESS_DAEMON: |
| 520 | { |
ajs | b1aa147 | 2005-01-28 21:11:46 +0000 | [diff] [blame] | 521 | u_int i; |
| 522 | int cmd_stat = CMD_SUCCESS; |
| 523 | |
| 524 | for (i = 0; i < VTYSH_INDEX_MAX; i++) |
| 525 | { |
| 526 | if (cmd->daemon && vtysh_client[i].flag) |
| 527 | { |
| 528 | cmd_stat = vtysh_client_execute (&vtysh_client[i], |
| 529 | vty->buf, stdout); |
| 530 | if (cmd_stat != CMD_SUCCESS) |
| 531 | break; |
| 532 | } |
| 533 | } |
| 534 | if (cmd_stat != CMD_SUCCESS) |
| 535 | break; |
| 536 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 537 | if (cmd->func) |
| 538 | (*cmd->func) (cmd, vty, 0, NULL); |
| 539 | } |
| 540 | } |
| 541 | } |
| 542 | return CMD_SUCCESS; |
| 543 | } |
| 544 | |
| 545 | /* We don't care about the point of the cursor when '?' is typed. */ |
| 546 | int |
ajs | b1aa147 | 2005-01-28 21:11:46 +0000 | [diff] [blame] | 547 | vtysh_rl_describe (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 548 | { |
| 549 | int ret; |
hasso | dda0952 | 2004-10-07 21:40:25 +0000 | [diff] [blame] | 550 | unsigned int i; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 551 | vector vline; |
| 552 | vector describe; |
| 553 | int width; |
| 554 | struct desc *desc; |
| 555 | |
| 556 | vline = cmd_make_strvec (rl_line_buffer); |
| 557 | |
| 558 | /* In case of '> ?'. */ |
| 559 | if (vline == NULL) |
| 560 | { |
| 561 | vline = vector_init (1); |
| 562 | vector_set (vline, '\0'); |
| 563 | } |
| 564 | else |
| 565 | if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1])) |
| 566 | vector_set (vline, '\0'); |
| 567 | |
| 568 | describe = cmd_describe_command (vline, vty, &ret); |
| 569 | |
paul | 4fc01e6 | 2002-12-13 20:49:00 +0000 | [diff] [blame] | 570 | fprintf (stdout,"\n"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 571 | |
| 572 | /* Ambiguous and no match error. */ |
| 573 | switch (ret) |
| 574 | { |
| 575 | case CMD_ERR_AMBIGUOUS: |
| 576 | cmd_free_strvec (vline); |
paul | 4fc01e6 | 2002-12-13 20:49:00 +0000 | [diff] [blame] | 577 | fprintf (stdout,"%% Ambiguous command.\n"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 578 | rl_on_new_line (); |
| 579 | return 0; |
| 580 | break; |
| 581 | case CMD_ERR_NO_MATCH: |
| 582 | cmd_free_strvec (vline); |
paul | 4fc01e6 | 2002-12-13 20:49:00 +0000 | [diff] [blame] | 583 | fprintf (stdout,"%% There is no matched command.\n"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 584 | rl_on_new_line (); |
| 585 | return 0; |
| 586 | break; |
| 587 | } |
| 588 | |
| 589 | /* Get width of command string. */ |
| 590 | width = 0; |
paul | 55468c8 | 2005-03-14 20:19:01 +0000 | [diff] [blame] | 591 | for (i = 0; i < vector_active (describe); i++) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 592 | if ((desc = vector_slot (describe, i)) != NULL) |
| 593 | { |
| 594 | int len; |
| 595 | |
| 596 | if (desc->cmd[0] == '\0') |
| 597 | continue; |
| 598 | |
| 599 | len = strlen (desc->cmd); |
| 600 | if (desc->cmd[0] == '.') |
| 601 | len--; |
| 602 | |
| 603 | if (width < len) |
| 604 | width = len; |
| 605 | } |
| 606 | |
paul | 55468c8 | 2005-03-14 20:19:01 +0000 | [diff] [blame] | 607 | for (i = 0; i < vector_active (describe); i++) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 608 | if ((desc = vector_slot (describe, i)) != NULL) |
| 609 | { |
| 610 | if (desc->cmd[0] == '\0') |
| 611 | continue; |
| 612 | |
| 613 | if (! desc->str) |
paul | 4fc01e6 | 2002-12-13 20:49:00 +0000 | [diff] [blame] | 614 | fprintf (stdout," %-s\n", |
hasso | b094d26 | 2004-08-25 12:22:00 +0000 | [diff] [blame] | 615 | desc->cmd[0] == '.' ? desc->cmd + 1 : desc->cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 616 | else |
paul | 4fc01e6 | 2002-12-13 20:49:00 +0000 | [diff] [blame] | 617 | fprintf (stdout," %-*s %s\n", |
hasso | b094d26 | 2004-08-25 12:22:00 +0000 | [diff] [blame] | 618 | width, |
| 619 | desc->cmd[0] == '.' ? desc->cmd + 1 : desc->cmd, |
| 620 | desc->str); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | cmd_free_strvec (vline); |
| 624 | vector_free (describe); |
| 625 | |
| 626 | rl_on_new_line(); |
| 627 | |
| 628 | return 0; |
| 629 | } |
| 630 | |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 631 | /* Result of cmd_complete_command() call will be stored here |
| 632 | * and used in new_completion() in order to put the space in |
| 633 | * correct places only. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 634 | int complete_status; |
| 635 | |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 636 | static char * |
paul | dfc0d9b | 2003-04-18 23:55:29 +0000 | [diff] [blame] | 637 | command_generator (const char *text, int state) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 638 | { |
| 639 | vector vline; |
| 640 | static char **matched = NULL; |
| 641 | static int index = 0; |
| 642 | |
| 643 | /* First call. */ |
| 644 | if (! state) |
| 645 | { |
| 646 | index = 0; |
| 647 | |
| 648 | if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE) |
| 649 | return NULL; |
| 650 | |
| 651 | vline = cmd_make_strvec (rl_line_buffer); |
| 652 | if (vline == NULL) |
| 653 | return NULL; |
| 654 | |
| 655 | if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1])) |
| 656 | vector_set (vline, '\0'); |
| 657 | |
| 658 | matched = cmd_complete_command (vline, vty, &complete_status); |
| 659 | } |
| 660 | |
| 661 | if (matched && matched[index]) |
| 662 | return matched[index++]; |
| 663 | |
| 664 | return NULL; |
| 665 | } |
| 666 | |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 667 | static char ** |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 668 | new_completion (char *text, int start, int end) |
| 669 | { |
| 670 | char **matches; |
| 671 | |
paul | dfc0d9b | 2003-04-18 23:55:29 +0000 | [diff] [blame] | 672 | matches = rl_completion_matches (text, command_generator); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 673 | |
| 674 | if (matches) |
| 675 | { |
| 676 | rl_point = rl_end; |
| 677 | if (complete_status == CMD_COMPLETE_FULL_MATCH) |
| 678 | rl_pending_input = ' '; |
| 679 | } |
| 680 | |
| 681 | return matches; |
| 682 | } |
| 683 | |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 684 | #if 0 |
| 685 | /* This function is not actually being used. */ |
| 686 | static char ** |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 687 | vtysh_completion (char *text, int start, int end) |
| 688 | { |
| 689 | int ret; |
| 690 | vector vline; |
| 691 | char **matched = NULL; |
| 692 | |
| 693 | if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE) |
| 694 | return NULL; |
| 695 | |
| 696 | vline = cmd_make_strvec (rl_line_buffer); |
| 697 | if (vline == NULL) |
| 698 | return NULL; |
| 699 | |
| 700 | /* In case of 'help \t'. */ |
| 701 | if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1])) |
| 702 | vector_set (vline, '\0'); |
| 703 | |
| 704 | matched = cmd_complete_command (vline, vty, &ret); |
| 705 | |
| 706 | cmd_free_strvec (vline); |
| 707 | |
| 708 | return (char **) matched; |
| 709 | } |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 710 | #endif |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 711 | |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 712 | /* Vty node structures. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 713 | struct cmd_node bgp_node = |
| 714 | { |
| 715 | BGP_NODE, |
| 716 | "%s(config-router)# ", |
| 717 | }; |
| 718 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 719 | struct cmd_node rip_node = |
| 720 | { |
| 721 | RIP_NODE, |
| 722 | "%s(config-router)# ", |
| 723 | }; |
| 724 | |
hasso | c25e458 | 2003-12-23 10:39:08 +0000 | [diff] [blame] | 725 | struct cmd_node isis_node = |
| 726 | { |
| 727 | ISIS_NODE, |
| 728 | "%s(config-router)# ", |
hasso | c25e458 | 2003-12-23 10:39:08 +0000 | [diff] [blame] | 729 | }; |
| 730 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 731 | struct cmd_node interface_node = |
| 732 | { |
| 733 | INTERFACE_NODE, |
| 734 | "%s(config-if)# ", |
| 735 | }; |
| 736 | |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 737 | struct cmd_node rmap_node = |
| 738 | { |
| 739 | RMAP_NODE, |
| 740 | "%s(config-route-map)# " |
| 741 | }; |
| 742 | |
| 743 | struct cmd_node zebra_node = |
| 744 | { |
| 745 | ZEBRA_NODE, |
| 746 | "%s(config-router)# " |
| 747 | }; |
| 748 | |
| 749 | struct cmd_node bgp_vpnv4_node = |
| 750 | { |
| 751 | BGP_VPNV4_NODE, |
| 752 | "%s(config-router-af)# " |
| 753 | }; |
| 754 | |
| 755 | struct cmd_node bgp_ipv4_node = |
| 756 | { |
| 757 | BGP_IPV4_NODE, |
| 758 | "%s(config-router-af)# " |
| 759 | }; |
| 760 | |
| 761 | struct cmd_node bgp_ipv4m_node = |
| 762 | { |
| 763 | BGP_IPV4M_NODE, |
| 764 | "%s(config-router-af)# " |
| 765 | }; |
| 766 | |
| 767 | struct cmd_node bgp_ipv6_node = |
| 768 | { |
| 769 | BGP_IPV6_NODE, |
| 770 | "%s(config-router-af)# " |
| 771 | }; |
| 772 | |
paul | 57b5b7e | 2005-08-22 22:44:29 +0000 | [diff] [blame] | 773 | struct cmd_node bgp_ipv6m_node = |
| 774 | { |
| 775 | BGP_IPV6M_NODE, |
| 776 | "%s(config-router-af)# " |
| 777 | }; |
| 778 | |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 779 | struct cmd_node ospf_node = |
| 780 | { |
| 781 | OSPF_NODE, |
| 782 | "%s(config-router)# " |
| 783 | }; |
| 784 | |
| 785 | struct cmd_node ripng_node = |
| 786 | { |
| 787 | RIPNG_NODE, |
| 788 | "%s(config-router)# " |
| 789 | }; |
| 790 | |
| 791 | struct cmd_node ospf6_node = |
| 792 | { |
| 793 | OSPF6_NODE, |
| 794 | "%s(config-ospf6)# " |
| 795 | }; |
| 796 | |
| 797 | struct cmd_node keychain_node = |
| 798 | { |
| 799 | KEYCHAIN_NODE, |
| 800 | "%s(config-keychain)# " |
| 801 | }; |
| 802 | |
| 803 | struct cmd_node keychain_key_node = |
| 804 | { |
| 805 | KEYCHAIN_KEY_NODE, |
| 806 | "%s(config-keychain-key)# " |
| 807 | }; |
| 808 | |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 809 | /* Defined in lib/vty.c */ |
| 810 | extern struct cmd_node vty_node; |
| 811 | |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 812 | /* When '^Z' is received from vty, move down to the enable mode. */ |
| 813 | int |
ajs | b1aa147 | 2005-01-28 21:11:46 +0000 | [diff] [blame] | 814 | vtysh_end (void) |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 815 | { |
| 816 | switch (vty->node) |
| 817 | { |
| 818 | case VIEW_NODE: |
| 819 | case ENABLE_NODE: |
| 820 | /* Nothing to do. */ |
| 821 | break; |
| 822 | default: |
| 823 | vty->node = ENABLE_NODE; |
| 824 | break; |
| 825 | } |
| 826 | return CMD_SUCCESS; |
| 827 | } |
| 828 | |
| 829 | DEFUNSH (VTYSH_ALL, |
| 830 | vtysh_end_all, |
| 831 | vtysh_end_all_cmd, |
| 832 | "end", |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 833 | "End current mode and change to enable mode\n") |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 834 | { |
hasso | 4289546 | 2004-09-26 16:25:07 +0000 | [diff] [blame] | 835 | return vtysh_end (); |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 836 | } |
| 837 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 838 | DEFUNSH (VTYSH_BGPD, |
| 839 | router_bgp, |
| 840 | router_bgp_cmd, |
| 841 | "router bgp <1-65535>", |
| 842 | ROUTER_STR |
| 843 | BGP_STR |
| 844 | AS_STR) |
| 845 | { |
| 846 | vty->node = BGP_NODE; |
| 847 | return CMD_SUCCESS; |
| 848 | } |
| 849 | |
| 850 | DEFUNSH (VTYSH_BGPD, |
| 851 | address_family_vpnv4, |
| 852 | address_family_vpnv4_cmd, |
| 853 | "address-family vpnv4", |
| 854 | "Enter Address Family command mode\n" |
| 855 | "Address family\n") |
| 856 | { |
| 857 | vty->node = BGP_VPNV4_NODE; |
| 858 | return CMD_SUCCESS; |
| 859 | } |
| 860 | |
| 861 | DEFUNSH (VTYSH_BGPD, |
| 862 | address_family_vpnv4_unicast, |
| 863 | address_family_vpnv4_unicast_cmd, |
| 864 | "address-family vpnv4 unicast", |
| 865 | "Enter Address Family command mode\n" |
| 866 | "Address family\n" |
| 867 | "Address Family Modifier\n") |
| 868 | { |
| 869 | vty->node = BGP_VPNV4_NODE; |
| 870 | return CMD_SUCCESS; |
| 871 | } |
| 872 | |
| 873 | DEFUNSH (VTYSH_BGPD, |
| 874 | address_family_ipv4_unicast, |
| 875 | address_family_ipv4_unicast_cmd, |
| 876 | "address-family ipv4 unicast", |
| 877 | "Enter Address Family command mode\n" |
| 878 | "Address family\n" |
| 879 | "Address Family Modifier\n") |
| 880 | { |
| 881 | vty->node = BGP_IPV4_NODE; |
| 882 | return CMD_SUCCESS; |
| 883 | } |
| 884 | |
| 885 | DEFUNSH (VTYSH_BGPD, |
| 886 | address_family_ipv4_multicast, |
| 887 | address_family_ipv4_multicast_cmd, |
| 888 | "address-family ipv4 multicast", |
| 889 | "Enter Address Family command mode\n" |
| 890 | "Address family\n" |
| 891 | "Address Family Modifier\n") |
| 892 | { |
| 893 | vty->node = BGP_IPV4M_NODE; |
| 894 | return CMD_SUCCESS; |
| 895 | } |
| 896 | |
| 897 | DEFUNSH (VTYSH_BGPD, |
| 898 | address_family_ipv6, |
| 899 | address_family_ipv6_cmd, |
| 900 | "address-family ipv6", |
| 901 | "Enter Address Family command mode\n" |
| 902 | "Address family\n") |
| 903 | { |
| 904 | vty->node = BGP_IPV6_NODE; |
| 905 | return CMD_SUCCESS; |
| 906 | } |
| 907 | |
| 908 | DEFUNSH (VTYSH_BGPD, |
| 909 | address_family_ipv6_unicast, |
| 910 | address_family_ipv6_unicast_cmd, |
| 911 | "address-family ipv6 unicast", |
| 912 | "Enter Address Family command mode\n" |
| 913 | "Address family\n" |
| 914 | "Address Family Modifier\n") |
| 915 | { |
| 916 | vty->node = BGP_IPV6_NODE; |
| 917 | return CMD_SUCCESS; |
| 918 | } |
| 919 | |
paul | 57b5b7e | 2005-08-22 22:44:29 +0000 | [diff] [blame] | 920 | DEFUNSH (VTYSH_BGPD, |
| 921 | address_family_ipv6_multicast, |
| 922 | address_family_ipv6_multicast_cmd, |
| 923 | "address-family ipv6 multicast", |
| 924 | "Enter Address Family command mode\n" |
| 925 | "Address family\n" |
| 926 | "Address Family Modifier\n") |
| 927 | { |
| 928 | vty->node = BGP_IPV6M_NODE; |
| 929 | return CMD_SUCCESS; |
| 930 | } |
| 931 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 932 | DEFUNSH (VTYSH_RIPD, |
| 933 | key_chain, |
| 934 | key_chain_cmd, |
| 935 | "key chain WORD", |
| 936 | "Authentication key management\n" |
| 937 | "Key-chain management\n" |
| 938 | "Key-chain name\n") |
| 939 | { |
| 940 | vty->node = KEYCHAIN_NODE; |
| 941 | return CMD_SUCCESS; |
| 942 | } |
| 943 | |
| 944 | DEFUNSH (VTYSH_RIPD, |
| 945 | key, |
| 946 | key_cmd, |
| 947 | "key <0-2147483647>", |
| 948 | "Configure a key\n" |
| 949 | "Key identifier number\n") |
| 950 | { |
| 951 | vty->node = KEYCHAIN_KEY_NODE; |
| 952 | return CMD_SUCCESS; |
| 953 | } |
| 954 | |
| 955 | DEFUNSH (VTYSH_RIPD, |
| 956 | router_rip, |
| 957 | router_rip_cmd, |
| 958 | "router rip", |
| 959 | ROUTER_STR |
| 960 | "RIP") |
| 961 | { |
| 962 | vty->node = RIP_NODE; |
| 963 | return CMD_SUCCESS; |
| 964 | } |
| 965 | |
| 966 | DEFUNSH (VTYSH_RIPNGD, |
| 967 | router_ripng, |
| 968 | router_ripng_cmd, |
| 969 | "router ripng", |
| 970 | ROUTER_STR |
| 971 | "RIPng") |
| 972 | { |
| 973 | vty->node = RIPNG_NODE; |
| 974 | return CMD_SUCCESS; |
| 975 | } |
| 976 | |
| 977 | DEFUNSH (VTYSH_OSPFD, |
| 978 | router_ospf, |
| 979 | router_ospf_cmd, |
| 980 | "router ospf", |
| 981 | "Enable a routing process\n" |
| 982 | "Start OSPF configuration\n") |
| 983 | { |
| 984 | vty->node = OSPF_NODE; |
| 985 | return CMD_SUCCESS; |
| 986 | } |
| 987 | |
| 988 | DEFUNSH (VTYSH_OSPF6D, |
| 989 | router_ospf6, |
| 990 | router_ospf6_cmd, |
| 991 | "router ospf6", |
| 992 | OSPF6_ROUTER_STR |
| 993 | OSPF6_STR) |
| 994 | { |
| 995 | vty->node = OSPF6_NODE; |
| 996 | return CMD_SUCCESS; |
| 997 | } |
| 998 | |
hasso | c25e458 | 2003-12-23 10:39:08 +0000 | [diff] [blame] | 999 | DEFUNSH (VTYSH_ISISD, |
hasso | b094d26 | 2004-08-25 12:22:00 +0000 | [diff] [blame] | 1000 | router_isis, |
| 1001 | router_isis_cmd, |
| 1002 | "router isis WORD", |
| 1003 | ROUTER_STR |
| 1004 | "ISO IS-IS\n" |
| 1005 | "ISO Routing area tag") |
hasso | c25e458 | 2003-12-23 10:39:08 +0000 | [diff] [blame] | 1006 | { |
| 1007 | vty->node = ISIS_NODE; |
| 1008 | return CMD_SUCCESS; |
| 1009 | } |
| 1010 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1011 | DEFUNSH (VTYSH_RMAP, |
| 1012 | route_map, |
| 1013 | route_map_cmd, |
| 1014 | "route-map WORD (deny|permit) <1-65535>", |
| 1015 | "Create route-map or enter route-map command mode\n" |
| 1016 | "Route map tag\n" |
| 1017 | "Route map denies set operations\n" |
| 1018 | "Route map permits set operations\n" |
| 1019 | "Sequence to insert to/delete from existing route-map entry\n") |
| 1020 | { |
| 1021 | vty->node = RMAP_NODE; |
| 1022 | return CMD_SUCCESS; |
| 1023 | } |
| 1024 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1025 | DEFUNSH (VTYSH_ALL, |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 1026 | vtysh_line_vty, |
| 1027 | vtysh_line_vty_cmd, |
| 1028 | "line vty", |
| 1029 | "Configure a terminal line\n" |
| 1030 | "Virtual terminal\n") |
| 1031 | { |
| 1032 | vty->node = VTY_NODE; |
| 1033 | return CMD_SUCCESS; |
| 1034 | } |
| 1035 | |
| 1036 | DEFUNSH (VTYSH_ALL, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1037 | vtysh_enable, |
| 1038 | vtysh_enable_cmd, |
| 1039 | "enable", |
| 1040 | "Turn on privileged mode command\n") |
| 1041 | { |
| 1042 | vty->node = ENABLE_NODE; |
| 1043 | return CMD_SUCCESS; |
| 1044 | } |
| 1045 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1046 | DEFUNSH (VTYSH_ALL, |
| 1047 | vtysh_disable, |
| 1048 | vtysh_disable_cmd, |
| 1049 | "disable", |
| 1050 | "Turn off privileged mode command\n") |
| 1051 | { |
| 1052 | if (vty->node == ENABLE_NODE) |
| 1053 | vty->node = VIEW_NODE; |
| 1054 | return CMD_SUCCESS; |
| 1055 | } |
| 1056 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1057 | DEFUNSH (VTYSH_ALL, |
| 1058 | vtysh_config_terminal, |
| 1059 | vtysh_config_terminal_cmd, |
| 1060 | "configure terminal", |
| 1061 | "Configuration from vty interface\n" |
| 1062 | "Configuration terminal\n") |
| 1063 | { |
| 1064 | vty->node = CONFIG_NODE; |
| 1065 | return CMD_SUCCESS; |
| 1066 | } |
| 1067 | |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 1068 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1069 | vtysh_exit (struct vty *vty) |
| 1070 | { |
| 1071 | switch (vty->node) |
| 1072 | { |
| 1073 | case VIEW_NODE: |
| 1074 | case ENABLE_NODE: |
| 1075 | exit (0); |
| 1076 | break; |
| 1077 | case CONFIG_NODE: |
| 1078 | vty->node = ENABLE_NODE; |
| 1079 | break; |
| 1080 | case INTERFACE_NODE: |
| 1081 | case ZEBRA_NODE: |
| 1082 | case BGP_NODE: |
| 1083 | case RIP_NODE: |
| 1084 | case RIPNG_NODE: |
| 1085 | case OSPF_NODE: |
| 1086 | case OSPF6_NODE: |
hasso | c25e458 | 2003-12-23 10:39:08 +0000 | [diff] [blame] | 1087 | case ISIS_NODE: |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1088 | case MASC_NODE: |
| 1089 | case RMAP_NODE: |
| 1090 | case VTY_NODE: |
| 1091 | case KEYCHAIN_NODE: |
hasso | 2a56df9 | 2004-05-09 23:16:40 +0000 | [diff] [blame] | 1092 | vtysh_execute("end"); |
| 1093 | vtysh_execute("configure terminal"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1094 | vty->node = CONFIG_NODE; |
| 1095 | break; |
| 1096 | case BGP_VPNV4_NODE: |
| 1097 | case BGP_IPV4_NODE: |
| 1098 | case BGP_IPV4M_NODE: |
| 1099 | case BGP_IPV6_NODE: |
paul | 57b5b7e | 2005-08-22 22:44:29 +0000 | [diff] [blame] | 1100 | case BGP_IPV6M_NODE: |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1101 | vty->node = BGP_NODE; |
| 1102 | break; |
| 1103 | case KEYCHAIN_KEY_NODE: |
| 1104 | vty->node = KEYCHAIN_NODE; |
| 1105 | break; |
| 1106 | default: |
| 1107 | break; |
| 1108 | } |
| 1109 | return CMD_SUCCESS; |
| 1110 | } |
| 1111 | |
| 1112 | DEFUNSH (VTYSH_ALL, |
| 1113 | vtysh_exit_all, |
| 1114 | vtysh_exit_all_cmd, |
| 1115 | "exit", |
| 1116 | "Exit current mode and down to previous mode\n") |
| 1117 | { |
| 1118 | return vtysh_exit (vty); |
| 1119 | } |
| 1120 | |
| 1121 | ALIAS (vtysh_exit_all, |
| 1122 | vtysh_quit_all_cmd, |
| 1123 | "quit", |
| 1124 | "Exit current mode and down to previous mode\n") |
| 1125 | |
| 1126 | DEFUNSH (VTYSH_BGPD, |
| 1127 | exit_address_family, |
| 1128 | exit_address_family_cmd, |
| 1129 | "exit-address-family", |
| 1130 | "Exit from Address Family configuration mode\n") |
| 1131 | { |
| 1132 | if (vty->node == BGP_IPV4_NODE |
| 1133 | || vty->node == BGP_IPV4M_NODE |
| 1134 | || vty->node == BGP_VPNV4_NODE |
paul | 57b5b7e | 2005-08-22 22:44:29 +0000 | [diff] [blame] | 1135 | || vty->node == BGP_IPV6_NODE |
| 1136 | || vty->node == BGP_IPV6M_NODE) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1137 | vty->node = BGP_NODE; |
| 1138 | return CMD_SUCCESS; |
| 1139 | } |
| 1140 | |
| 1141 | DEFUNSH (VTYSH_ZEBRA, |
| 1142 | vtysh_exit_zebra, |
| 1143 | vtysh_exit_zebra_cmd, |
| 1144 | "exit", |
| 1145 | "Exit current mode and down to previous mode\n") |
| 1146 | { |
| 1147 | return vtysh_exit (vty); |
| 1148 | } |
| 1149 | |
| 1150 | ALIAS (vtysh_exit_zebra, |
| 1151 | vtysh_quit_zebra_cmd, |
| 1152 | "quit", |
| 1153 | "Exit current mode and down to previous mode\n") |
| 1154 | |
| 1155 | DEFUNSH (VTYSH_RIPD, |
| 1156 | vtysh_exit_ripd, |
| 1157 | vtysh_exit_ripd_cmd, |
| 1158 | "exit", |
| 1159 | "Exit current mode and down to previous mode\n") |
| 1160 | { |
| 1161 | return vtysh_exit (vty); |
| 1162 | } |
| 1163 | |
| 1164 | ALIAS (vtysh_exit_ripd, |
| 1165 | vtysh_quit_ripd_cmd, |
| 1166 | "quit", |
| 1167 | "Exit current mode and down to previous mode\n") |
| 1168 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1169 | DEFUNSH (VTYSH_RIPNGD, |
hasso | b094d26 | 2004-08-25 12:22:00 +0000 | [diff] [blame] | 1170 | vtysh_exit_ripngd, |
| 1171 | vtysh_exit_ripngd_cmd, |
| 1172 | "exit", |
| 1173 | "Exit current mode and down to previous mode\n") |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1174 | { |
| 1175 | return vtysh_exit (vty); |
| 1176 | } |
| 1177 | |
| 1178 | ALIAS (vtysh_exit_ripngd, |
| 1179 | vtysh_quit_ripngd_cmd, |
| 1180 | "quit", |
| 1181 | "Exit current mode and down to previous mode\n") |
| 1182 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1183 | DEFUNSH (VTYSH_RMAP, |
| 1184 | vtysh_exit_rmap, |
| 1185 | vtysh_exit_rmap_cmd, |
| 1186 | "exit", |
| 1187 | "Exit current mode and down to previous mode\n") |
| 1188 | { |
| 1189 | return vtysh_exit (vty); |
| 1190 | } |
| 1191 | |
| 1192 | ALIAS (vtysh_exit_rmap, |
| 1193 | vtysh_quit_rmap_cmd, |
| 1194 | "quit", |
| 1195 | "Exit current mode and down to previous mode\n") |
| 1196 | |
| 1197 | DEFUNSH (VTYSH_BGPD, |
| 1198 | vtysh_exit_bgpd, |
| 1199 | vtysh_exit_bgpd_cmd, |
| 1200 | "exit", |
| 1201 | "Exit current mode and down to previous mode\n") |
| 1202 | { |
| 1203 | return vtysh_exit (vty); |
| 1204 | } |
| 1205 | |
| 1206 | ALIAS (vtysh_exit_bgpd, |
| 1207 | vtysh_quit_bgpd_cmd, |
| 1208 | "quit", |
| 1209 | "Exit current mode and down to previous mode\n") |
| 1210 | |
| 1211 | DEFUNSH (VTYSH_OSPFD, |
| 1212 | vtysh_exit_ospfd, |
| 1213 | vtysh_exit_ospfd_cmd, |
| 1214 | "exit", |
| 1215 | "Exit current mode and down to previous mode\n") |
| 1216 | { |
| 1217 | return vtysh_exit (vty); |
| 1218 | } |
| 1219 | |
| 1220 | ALIAS (vtysh_exit_ospfd, |
| 1221 | vtysh_quit_ospfd_cmd, |
| 1222 | "quit", |
| 1223 | "Exit current mode and down to previous mode\n") |
| 1224 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1225 | DEFUNSH (VTYSH_OSPF6D, |
hasso | b094d26 | 2004-08-25 12:22:00 +0000 | [diff] [blame] | 1226 | vtysh_exit_ospf6d, |
| 1227 | vtysh_exit_ospf6d_cmd, |
| 1228 | "exit", |
| 1229 | "Exit current mode and down to previous mode\n") |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1230 | { |
| 1231 | return vtysh_exit (vty); |
| 1232 | } |
| 1233 | |
| 1234 | ALIAS (vtysh_exit_ospf6d, |
| 1235 | vtysh_quit_ospf6d_cmd, |
| 1236 | "quit", |
| 1237 | "Exit current mode and down to previous mode\n") |
| 1238 | |
hasso | c25e458 | 2003-12-23 10:39:08 +0000 | [diff] [blame] | 1239 | DEFUNSH (VTYSH_ISISD, |
hasso | b094d26 | 2004-08-25 12:22:00 +0000 | [diff] [blame] | 1240 | vtysh_exit_isisd, |
| 1241 | vtysh_exit_isisd_cmd, |
| 1242 | "exit", |
| 1243 | "Exit current mode and down to previous mode\n") |
hasso | c25e458 | 2003-12-23 10:39:08 +0000 | [diff] [blame] | 1244 | { |
| 1245 | return vtysh_exit (vty); |
| 1246 | } |
| 1247 | |
| 1248 | ALIAS (vtysh_exit_isisd, |
| 1249 | vtysh_quit_isisd_cmd, |
| 1250 | "quit", |
| 1251 | "Exit current mode and down to previous mode\n") |
| 1252 | |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 1253 | DEFUNSH (VTYSH_ALL, |
| 1254 | vtysh_exit_line_vty, |
| 1255 | vtysh_exit_line_vty_cmd, |
| 1256 | "exit", |
| 1257 | "Exit current mode and down to previous mode\n") |
| 1258 | { |
| 1259 | return vtysh_exit (vty); |
| 1260 | } |
| 1261 | |
| 1262 | ALIAS (vtysh_exit_line_vty, |
| 1263 | vtysh_quit_line_vty_cmd, |
| 1264 | "quit", |
| 1265 | "Exit current mode and down to previous mode\n") |
| 1266 | |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1267 | DEFUNSH (VTYSH_INTERFACE, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1268 | vtysh_interface, |
| 1269 | vtysh_interface_cmd, |
| 1270 | "interface IFNAME", |
| 1271 | "Select an interface to configure\n" |
| 1272 | "Interface's name\n") |
| 1273 | { |
| 1274 | vty->node = INTERFACE_NODE; |
| 1275 | return CMD_SUCCESS; |
| 1276 | } |
| 1277 | |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1278 | /* TODO Implement "no interface command in isisd. */ |
paul | 32d2463 | 2003-05-23 09:25:20 +0000 | [diff] [blame] | 1279 | DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D, |
| 1280 | vtysh_no_interface_cmd, |
| 1281 | "no interface IFNAME", |
| 1282 | NO_STR |
| 1283 | "Delete a pseudo interface's configuration\n" |
| 1284 | "Interface's name\n") |
| 1285 | |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1286 | /* TODO Implement interface description commands in ripngd, ospf6d |
| 1287 | * and isisd. */ |
paul | 338a991 | 2003-03-01 15:44:10 +0000 | [diff] [blame] | 1288 | DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD, |
| 1289 | interface_desc_cmd, |
| 1290 | "description .LINE", |
| 1291 | "Interface specific description\n" |
| 1292 | "Characters describing this interface\n") |
paul | 464dc8d | 2003-03-28 02:25:45 +0000 | [diff] [blame] | 1293 | |
| 1294 | DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD, |
| 1295 | no_interface_desc_cmd, |
| 1296 | "no description", |
| 1297 | NO_STR |
| 1298 | "Interface specific description\n") |
paul | 338a991 | 2003-03-01 15:44:10 +0000 | [diff] [blame] | 1299 | |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1300 | DEFUNSH (VTYSH_INTERFACE, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1301 | vtysh_exit_interface, |
| 1302 | vtysh_exit_interface_cmd, |
| 1303 | "exit", |
| 1304 | "Exit current mode and down to previous mode\n") |
| 1305 | { |
| 1306 | return vtysh_exit (vty); |
| 1307 | } |
| 1308 | |
| 1309 | ALIAS (vtysh_exit_interface, |
| 1310 | vtysh_quit_interface_cmd, |
| 1311 | "quit", |
| 1312 | "Exit current mode and down to previous mode\n") |
| 1313 | |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1314 | /* Logging commands. */ |
| 1315 | DEFUNSH (VTYSH_ALL, |
| 1316 | vtysh_log_stdout, |
| 1317 | vtysh_log_stdout_cmd, |
| 1318 | "log stdout", |
| 1319 | "Logging control\n" |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 1320 | "Set stdout logging level\n") |
| 1321 | { |
| 1322 | return CMD_SUCCESS; |
| 1323 | } |
| 1324 | |
| 1325 | DEFUNSH (VTYSH_ALL, |
| 1326 | vtysh_log_stdout_level, |
| 1327 | vtysh_log_stdout_level_cmd, |
| 1328 | "log stdout "LOG_LEVELS, |
| 1329 | "Logging control\n" |
| 1330 | "Set stdout logging level\n" |
| 1331 | LOG_LEVEL_DESC) |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1332 | { |
| 1333 | return CMD_SUCCESS; |
| 1334 | } |
| 1335 | |
| 1336 | DEFUNSH (VTYSH_ALL, |
| 1337 | no_vtysh_log_stdout, |
| 1338 | no_vtysh_log_stdout_cmd, |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 1339 | "no log stdout [LEVEL]", |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1340 | NO_STR |
| 1341 | "Logging control\n" |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 1342 | "Cancel logging to stdout\n" |
| 1343 | "Logging level\n") |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1344 | { |
| 1345 | return CMD_SUCCESS; |
| 1346 | } |
| 1347 | |
| 1348 | DEFUNSH (VTYSH_ALL, |
| 1349 | vtysh_log_file, |
| 1350 | vtysh_log_file_cmd, |
| 1351 | "log file FILENAME", |
| 1352 | "Logging control\n" |
| 1353 | "Logging to file\n" |
| 1354 | "Logging filename\n") |
| 1355 | { |
| 1356 | return CMD_SUCCESS; |
| 1357 | } |
| 1358 | |
| 1359 | DEFUNSH (VTYSH_ALL, |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 1360 | vtysh_log_file_level, |
| 1361 | vtysh_log_file_level_cmd, |
| 1362 | "log file FILENAME "LOG_LEVELS, |
| 1363 | "Logging control\n" |
| 1364 | "Logging to file\n" |
| 1365 | "Logging filename\n" |
| 1366 | LOG_LEVEL_DESC) |
| 1367 | { |
| 1368 | return CMD_SUCCESS; |
| 1369 | } |
| 1370 | |
| 1371 | DEFUNSH (VTYSH_ALL, |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1372 | no_vtysh_log_file, |
| 1373 | no_vtysh_log_file_cmd, |
| 1374 | "no log file [FILENAME]", |
| 1375 | NO_STR |
| 1376 | "Logging control\n" |
| 1377 | "Cancel logging to file\n" |
| 1378 | "Logging file name\n") |
| 1379 | { |
| 1380 | return CMD_SUCCESS; |
| 1381 | } |
| 1382 | |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 1383 | ALIAS_SH (VTYSH_ALL, |
| 1384 | no_vtysh_log_file, |
| 1385 | no_vtysh_log_file_level_cmd, |
| 1386 | "no log file FILENAME LEVEL", |
| 1387 | NO_STR |
| 1388 | "Logging control\n" |
| 1389 | "Cancel logging to file\n" |
| 1390 | "Logging file name\n" |
| 1391 | "Logging level\n") |
| 1392 | |
| 1393 | DEFUNSH (VTYSH_ALL, |
| 1394 | vtysh_log_monitor, |
| 1395 | vtysh_log_monitor_cmd, |
| 1396 | "log monitor", |
| 1397 | "Logging control\n" |
| 1398 | "Set terminal line (monitor) logging level\n") |
| 1399 | { |
| 1400 | return CMD_SUCCESS; |
| 1401 | } |
| 1402 | |
| 1403 | DEFUNSH (VTYSH_ALL, |
| 1404 | vtysh_log_monitor_level, |
| 1405 | vtysh_log_monitor_level_cmd, |
| 1406 | "log monitor "LOG_LEVELS, |
| 1407 | "Logging control\n" |
| 1408 | "Set terminal line (monitor) logging level\n" |
| 1409 | LOG_LEVEL_DESC) |
| 1410 | { |
| 1411 | return CMD_SUCCESS; |
| 1412 | } |
| 1413 | |
| 1414 | DEFUNSH (VTYSH_ALL, |
| 1415 | no_vtysh_log_monitor, |
| 1416 | no_vtysh_log_monitor_cmd, |
| 1417 | "no log monitor [LEVEL]", |
| 1418 | NO_STR |
| 1419 | "Logging control\n" |
| 1420 | "Disable terminal line (monitor) logging\n" |
| 1421 | "Logging level\n") |
| 1422 | { |
| 1423 | return CMD_SUCCESS; |
| 1424 | } |
| 1425 | |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1426 | DEFUNSH (VTYSH_ALL, |
| 1427 | vtysh_log_syslog, |
| 1428 | vtysh_log_syslog_cmd, |
| 1429 | "log syslog", |
| 1430 | "Logging control\n" |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 1431 | "Set syslog logging level\n") |
| 1432 | { |
| 1433 | return CMD_SUCCESS; |
| 1434 | } |
| 1435 | |
| 1436 | DEFUNSH (VTYSH_ALL, |
| 1437 | vtysh_log_syslog_level, |
| 1438 | vtysh_log_syslog_level_cmd, |
| 1439 | "log syslog "LOG_LEVELS, |
| 1440 | "Logging control\n" |
| 1441 | "Set syslog logging level\n" |
| 1442 | LOG_LEVEL_DESC) |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1443 | { |
| 1444 | return CMD_SUCCESS; |
| 1445 | } |
| 1446 | |
| 1447 | DEFUNSH (VTYSH_ALL, |
| 1448 | no_vtysh_log_syslog, |
| 1449 | no_vtysh_log_syslog_cmd, |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 1450 | "no log syslog [LEVEL]", |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1451 | NO_STR |
| 1452 | "Logging control\n" |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 1453 | "Cancel logging to syslog\n" |
| 1454 | "Logging level\n") |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1455 | { |
| 1456 | return CMD_SUCCESS; |
| 1457 | } |
| 1458 | |
| 1459 | DEFUNSH (VTYSH_ALL, |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 1460 | vtysh_log_facility, |
| 1461 | vtysh_log_facility_cmd, |
| 1462 | "log facility "LOG_FACILITIES, |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1463 | "Logging control\n" |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 1464 | "Facility parameter for syslog messages\n" |
| 1465 | LOG_FACILITY_DESC) |
| 1466 | |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1467 | { |
| 1468 | return CMD_SUCCESS; |
| 1469 | } |
| 1470 | |
| 1471 | DEFUNSH (VTYSH_ALL, |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 1472 | no_vtysh_log_facility, |
| 1473 | no_vtysh_log_facility_cmd, |
| 1474 | "no log facility [FACILITY]", |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1475 | NO_STR |
| 1476 | "Logging control\n" |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 1477 | "Reset syslog facility to default (daemon)\n" |
| 1478 | "Syslog facility\n") |
| 1479 | |
| 1480 | { |
| 1481 | return CMD_SUCCESS; |
| 1482 | } |
| 1483 | |
| 1484 | DEFUNSH_DEPRECATED (VTYSH_ALL, |
| 1485 | vtysh_log_trap, |
| 1486 | vtysh_log_trap_cmd, |
| 1487 | "log trap "LOG_LEVELS, |
| 1488 | "Logging control\n" |
| 1489 | "(Deprecated) Set logging level and default for all destinations\n" |
| 1490 | LOG_LEVEL_DESC) |
| 1491 | |
| 1492 | { |
| 1493 | return CMD_SUCCESS; |
| 1494 | } |
| 1495 | |
| 1496 | DEFUNSH_DEPRECATED (VTYSH_ALL, |
| 1497 | no_vtysh_log_trap, |
| 1498 | no_vtysh_log_trap_cmd, |
| 1499 | "no log trap [LEVEL]", |
| 1500 | NO_STR |
| 1501 | "Logging control\n" |
| 1502 | "Permit all logging information\n" |
| 1503 | "Logging level\n") |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1504 | { |
| 1505 | return CMD_SUCCESS; |
| 1506 | } |
| 1507 | |
| 1508 | DEFUNSH (VTYSH_ALL, |
| 1509 | vtysh_log_record_priority, |
| 1510 | vtysh_log_record_priority_cmd, |
| 1511 | "log record-priority", |
| 1512 | "Logging control\n" |
| 1513 | "Log the priority of the message within the message\n") |
| 1514 | { |
| 1515 | return CMD_SUCCESS; |
| 1516 | } |
| 1517 | |
| 1518 | DEFUNSH (VTYSH_ALL, |
| 1519 | no_vtysh_log_record_priority, |
| 1520 | no_vtysh_log_record_priority_cmd, |
| 1521 | "no log record-priority", |
| 1522 | NO_STR |
| 1523 | "Logging control\n" |
| 1524 | "Do not log the priority of the message within the message\n") |
| 1525 | { |
| 1526 | return CMD_SUCCESS; |
| 1527 | } |
| 1528 | |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 1529 | DEFUNSH (VTYSH_ALL, |
| 1530 | vtysh_service_password_encrypt, |
| 1531 | vtysh_service_password_encrypt_cmd, |
| 1532 | "service password-encryption", |
| 1533 | "Set up miscellaneous service\n" |
| 1534 | "Enable encrypted passwords\n") |
| 1535 | { |
| 1536 | return CMD_SUCCESS; |
| 1537 | } |
| 1538 | |
| 1539 | DEFUNSH (VTYSH_ALL, |
| 1540 | no_vtysh_service_password_encrypt, |
| 1541 | no_vtysh_service_password_encrypt_cmd, |
| 1542 | "no service password-encryption", |
| 1543 | NO_STR |
| 1544 | "Set up miscellaneous service\n" |
| 1545 | "Enable encrypted passwords\n") |
| 1546 | { |
| 1547 | return CMD_SUCCESS; |
| 1548 | } |
| 1549 | |
| 1550 | DEFUNSH (VTYSH_ALL, |
| 1551 | vtysh_config_password, |
| 1552 | vtysh_password_cmd, |
| 1553 | "password (8|) WORD", |
| 1554 | "Assign the terminal connection password\n" |
| 1555 | "Specifies a HIDDEN password will follow\n" |
| 1556 | "dummy string \n" |
| 1557 | "The HIDDEN line password string\n") |
| 1558 | { |
| 1559 | return CMD_SUCCESS; |
| 1560 | } |
| 1561 | |
| 1562 | DEFUNSH (VTYSH_ALL, |
| 1563 | vtysh_password_text, |
| 1564 | vtysh_password_text_cmd, |
| 1565 | "password LINE", |
| 1566 | "Assign the terminal connection password\n" |
| 1567 | "The UNENCRYPTED (cleartext) line password\n") |
| 1568 | { |
| 1569 | return CMD_SUCCESS; |
| 1570 | } |
| 1571 | |
| 1572 | DEFUNSH (VTYSH_ALL, |
| 1573 | vtysh_config_enable_password, |
| 1574 | vtysh_enable_password_cmd, |
| 1575 | "enable password (8|) WORD", |
| 1576 | "Modify enable password parameters\n" |
| 1577 | "Assign the privileged level password\n" |
| 1578 | "Specifies a HIDDEN password will follow\n" |
| 1579 | "dummy string \n" |
| 1580 | "The HIDDEN 'enable' password string\n") |
| 1581 | { |
| 1582 | return CMD_SUCCESS; |
| 1583 | } |
| 1584 | |
| 1585 | DEFUNSH (VTYSH_ALL, |
| 1586 | vtysh_enable_password_text, |
| 1587 | vtysh_enable_password_text_cmd, |
| 1588 | "enable password LINE", |
| 1589 | "Modify enable password parameters\n" |
| 1590 | "Assign the privileged level password\n" |
| 1591 | "The UNENCRYPTED (cleartext) 'enable' password\n") |
| 1592 | { |
| 1593 | return CMD_SUCCESS; |
| 1594 | } |
| 1595 | |
| 1596 | DEFUNSH (VTYSH_ALL, |
| 1597 | no_vtysh_config_enable_password, |
| 1598 | no_vtysh_enable_password_cmd, |
| 1599 | "no enable password", |
| 1600 | NO_STR |
| 1601 | "Modify enable password parameters\n" |
| 1602 | "Assign the privileged level password\n") |
| 1603 | { |
| 1604 | return CMD_SUCCESS; |
| 1605 | } |
| 1606 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1607 | DEFUN (vtysh_write_terminal, |
| 1608 | vtysh_write_terminal_cmd, |
| 1609 | "write terminal", |
| 1610 | "Write running configuration to memory, network, or terminal\n" |
| 1611 | "Write to terminal\n") |
| 1612 | { |
ajs | b1aa147 | 2005-01-28 21:11:46 +0000 | [diff] [blame] | 1613 | u_int i; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1614 | int ret; |
| 1615 | char line[] = "write terminal\n"; |
| 1616 | FILE *fp = NULL; |
| 1617 | |
| 1618 | if (vtysh_pager_name) |
| 1619 | { |
paul | 4fc01e6 | 2002-12-13 20:49:00 +0000 | [diff] [blame] | 1620 | fp = popen (vtysh_pager_name, "w"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1621 | if (fp == NULL) |
| 1622 | { |
| 1623 | perror ("popen"); |
| 1624 | exit (1); |
| 1625 | } |
| 1626 | } |
| 1627 | else |
| 1628 | fp = stdout; |
| 1629 | |
| 1630 | vty_out (vty, "Building configuration...%s", VTY_NEWLINE); |
| 1631 | vty_out (vty, "%sCurrent configuration:%s", VTY_NEWLINE, |
| 1632 | VTY_NEWLINE); |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 1633 | vty_out (vty, "!%s", VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1634 | |
ajs | b1aa147 | 2005-01-28 21:11:46 +0000 | [diff] [blame] | 1635 | for (i = 0; i < VTYSH_INDEX_MAX; i++) |
| 1636 | ret = vtysh_client_config (&vtysh_client[i], line); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1637 | |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 1638 | /* Integrate vtysh specific configuration. */ |
| 1639 | vtysh_config_write (); |
| 1640 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1641 | vtysh_config_dump (fp); |
| 1642 | |
| 1643 | if (vtysh_pager_name && fp) |
| 1644 | { |
| 1645 | fflush (fp); |
| 1646 | if (pclose (fp) == -1) |
| 1647 | { |
| 1648 | perror ("pclose"); |
| 1649 | exit (1); |
| 1650 | } |
| 1651 | fp = NULL; |
| 1652 | } |
| 1653 | |
| 1654 | return CMD_SUCCESS; |
| 1655 | } |
| 1656 | |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 1657 | DEFUN (vtysh_integrated_config, |
| 1658 | vtysh_integrated_config_cmd, |
| 1659 | "service integrated-vtysh-config", |
| 1660 | "Set up miscellaneous service\n" |
| 1661 | "Write configuration into integrated file\n") |
paul | 4fc01e6 | 2002-12-13 20:49:00 +0000 | [diff] [blame] | 1662 | { |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 1663 | vtysh_writeconfig_integrated = 1; |
| 1664 | return CMD_SUCCESS; |
paul | 4fc01e6 | 2002-12-13 20:49:00 +0000 | [diff] [blame] | 1665 | } |
| 1666 | |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 1667 | DEFUN (no_vtysh_integrated_config, |
| 1668 | no_vtysh_integrated_config_cmd, |
| 1669 | "no service integrated-vtysh-config", |
| 1670 | NO_STR |
| 1671 | "Set up miscellaneous service\n" |
| 1672 | "Write configuration into integrated file\n") |
paul | 4fc01e6 | 2002-12-13 20:49:00 +0000 | [diff] [blame] | 1673 | { |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 1674 | vtysh_writeconfig_integrated = 0; |
| 1675 | return CMD_SUCCESS; |
paul | 4fc01e6 | 2002-12-13 20:49:00 +0000 | [diff] [blame] | 1676 | } |
| 1677 | |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 1678 | static int |
| 1679 | write_config_integrated(void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1680 | { |
ajs | b1aa147 | 2005-01-28 21:11:46 +0000 | [diff] [blame] | 1681 | u_int i; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1682 | int ret; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1683 | char line[] = "write terminal\n"; |
| 1684 | FILE *fp; |
| 1685 | char *integrate_sav = NULL; |
| 1686 | |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1687 | integrate_sav = malloc (strlen (integrate_default) + |
| 1688 | strlen (CONF_BACKUP_EXT) + 1); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1689 | strcpy (integrate_sav, integrate_default); |
| 1690 | strcat (integrate_sav, CONF_BACKUP_EXT); |
| 1691 | |
paul | 4fc01e6 | 2002-12-13 20:49:00 +0000 | [diff] [blame] | 1692 | fprintf (stdout,"Building Configuration...\n"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1693 | |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1694 | /* Move current configuration file to backup config file. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1695 | unlink (integrate_sav); |
| 1696 | rename (integrate_default, integrate_sav); |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1697 | free (integrate_sav); |
paul | 4fc01e6 | 2002-12-13 20:49:00 +0000 | [diff] [blame] | 1698 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1699 | fp = fopen (integrate_default, "w"); |
| 1700 | if (fp == NULL) |
| 1701 | { |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1702 | fprintf (stdout,"%% Can't open configuration file %s.\n", |
| 1703 | integrate_default); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1704 | return CMD_SUCCESS; |
| 1705 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1706 | |
ajs | b1aa147 | 2005-01-28 21:11:46 +0000 | [diff] [blame] | 1707 | for (i = 0; i < VTYSH_INDEX_MAX; i++) |
| 1708 | ret = vtysh_client_config (&vtysh_client[i], line); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1709 | |
| 1710 | vtysh_config_dump (fp); |
| 1711 | |
| 1712 | fclose (fp); |
| 1713 | |
gdt | aa593d5 | 2003-12-22 20:15:53 +0000 | [diff] [blame] | 1714 | if (chmod (integrate_default, CONFIGFILE_MASK) != 0) |
| 1715 | { |
| 1716 | fprintf (stdout,"%% Can't chmod configuration file %s: %s (%d)\n", |
ajs | 6099b3b | 2004-11-20 02:06:59 +0000 | [diff] [blame] | 1717 | integrate_default, safe_strerror(errno), errno); |
gdt | aa593d5 | 2003-12-22 20:15:53 +0000 | [diff] [blame] | 1718 | return CMD_WARNING; |
| 1719 | } |
| 1720 | |
paul | 4fc01e6 | 2002-12-13 20:49:00 +0000 | [diff] [blame] | 1721 | fprintf(stdout,"Integrated configuration saved to %s\n",integrate_default); |
| 1722 | |
| 1723 | fprintf (stdout,"[OK]\n"); |
| 1724 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1725 | return CMD_SUCCESS; |
| 1726 | } |
| 1727 | |
paul | 4fc01e6 | 2002-12-13 20:49:00 +0000 | [diff] [blame] | 1728 | DEFUN (vtysh_write_memory, |
| 1729 | vtysh_write_memory_cmd, |
| 1730 | "write memory", |
| 1731 | "Write running configuration to memory, network, or terminal\n" |
| 1732 | "Write configuration to the file (same as write file)\n") |
| 1733 | { |
paul | dfc0d9b | 2003-04-18 23:55:29 +0000 | [diff] [blame] | 1734 | int ret = CMD_SUCCESS; |
paul | 4fc01e6 | 2002-12-13 20:49:00 +0000 | [diff] [blame] | 1735 | char line[] = "write memory\n"; |
ajs | b1aa147 | 2005-01-28 21:11:46 +0000 | [diff] [blame] | 1736 | u_int i; |
paul | 4fc01e6 | 2002-12-13 20:49:00 +0000 | [diff] [blame] | 1737 | |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 1738 | /* If integrated Quagga.conf explicitely set. */ |
| 1739 | if (vtysh_writeconfig_integrated) |
| 1740 | return write_config_integrated(); |
paul | 4fc01e6 | 2002-12-13 20:49:00 +0000 | [diff] [blame] | 1741 | |
| 1742 | fprintf (stdout,"Building Configuration...\n"); |
| 1743 | |
ajs | b1aa147 | 2005-01-28 21:11:46 +0000 | [diff] [blame] | 1744 | for (i = 0; i < VTYSH_INDEX_MAX; i++) |
| 1745 | ret = vtysh_client_execute (&vtysh_client[i], line, stdout); |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 1746 | |
paul | 4fc01e6 | 2002-12-13 20:49:00 +0000 | [diff] [blame] | 1747 | fprintf (stdout,"[OK]\n"); |
| 1748 | |
paul | dfc0d9b | 2003-04-18 23:55:29 +0000 | [diff] [blame] | 1749 | return ret; |
paul | 4fc01e6 | 2002-12-13 20:49:00 +0000 | [diff] [blame] | 1750 | } |
| 1751 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1752 | ALIAS (vtysh_write_memory, |
| 1753 | vtysh_copy_runningconfig_startupconfig_cmd, |
| 1754 | "copy running-config startup-config", |
| 1755 | "Copy from one file to another\n" |
| 1756 | "Copy from current system configuration\n" |
| 1757 | "Copy to startup configuration\n") |
| 1758 | |
| 1759 | ALIAS (vtysh_write_memory, |
| 1760 | vtysh_write_file_cmd, |
| 1761 | "write file", |
| 1762 | "Write running configuration to memory, network, or terminal\n" |
| 1763 | "Write configuration to the file (same as write memory)\n") |
| 1764 | |
hasso | 4a6e225 | 2003-05-25 11:51:29 +0000 | [diff] [blame] | 1765 | ALIAS (vtysh_write_memory, |
| 1766 | vtysh_write_cmd, |
| 1767 | "write", |
| 1768 | "Write running configuration to memory, network, or terminal\n") |
| 1769 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1770 | ALIAS (vtysh_write_terminal, |
| 1771 | vtysh_show_running_config_cmd, |
| 1772 | "show running-config", |
| 1773 | SHOW_STR |
| 1774 | "Current operating configuration\n") |
hasso | b094d26 | 2004-08-25 12:22:00 +0000 | [diff] [blame] | 1775 | |
hasso | 34553cc | 2004-08-27 13:56:39 +0000 | [diff] [blame] | 1776 | DEFUN (vtysh_terminal_length, |
| 1777 | vtysh_terminal_length_cmd, |
| 1778 | "terminal length <0-512>", |
| 1779 | "Set terminal line parameters\n" |
| 1780 | "Set number of lines on a screen\n" |
| 1781 | "Number of lines on screen (0 for no pausing)\n") |
| 1782 | { |
| 1783 | int lines; |
| 1784 | char *endptr = NULL; |
| 1785 | char default_pager[10]; |
| 1786 | |
| 1787 | lines = strtol (argv[0], &endptr, 10); |
| 1788 | if (lines < 0 || lines > 512 || *endptr != '\0') |
| 1789 | { |
| 1790 | vty_out (vty, "length is malformed%s", VTY_NEWLINE); |
| 1791 | return CMD_WARNING; |
| 1792 | } |
| 1793 | |
| 1794 | if (vtysh_pager_name) |
| 1795 | { |
| 1796 | free (vtysh_pager_name); |
| 1797 | vtysh_pager_name = NULL; |
| 1798 | } |
| 1799 | |
| 1800 | if (lines != 0) |
| 1801 | { |
| 1802 | snprintf(default_pager, 10, "more -%i", lines); |
| 1803 | vtysh_pager_name = strdup (default_pager); |
| 1804 | } |
| 1805 | |
| 1806 | return CMD_SUCCESS; |
| 1807 | } |
| 1808 | |
| 1809 | DEFUN (vtysh_terminal_no_length, |
| 1810 | vtysh_terminal_no_length_cmd, |
| 1811 | "terminal no length", |
| 1812 | "Set terminal line parameters\n" |
| 1813 | NO_STR |
| 1814 | "Set number of lines on a screen\n") |
| 1815 | { |
| 1816 | if (vtysh_pager_name) |
| 1817 | { |
| 1818 | free (vtysh_pager_name); |
| 1819 | vtysh_pager_name = NULL; |
| 1820 | } |
| 1821 | |
| 1822 | vtysh_pager_init(); |
| 1823 | return CMD_SUCCESS; |
| 1824 | } |
| 1825 | |
hasso | f2799e6 | 2004-10-28 17:43:11 +0000 | [diff] [blame] | 1826 | DEFUN (vtysh_show_daemons, |
| 1827 | vtysh_show_daemons_cmd, |
| 1828 | "show daemons", |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 1829 | SHOW_STR |
| 1830 | "Show list of running daemons\n") |
| 1831 | { |
ajs | b1aa147 | 2005-01-28 21:11:46 +0000 | [diff] [blame] | 1832 | u_int i; |
| 1833 | |
| 1834 | for (i = 0; i < VTYSH_INDEX_MAX; i++) |
| 1835 | if ( vtysh_client[i].fd >= 0 ) |
| 1836 | vty_out(vty, " %s", vtysh_client[i].name); |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 1837 | vty_out(vty, "%s", VTY_NEWLINE); |
| 1838 | |
| 1839 | return CMD_SUCCESS; |
| 1840 | } |
| 1841 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1842 | /* Execute command in child process. */ |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 1843 | static int |
hasso | 5862ff5 | 2004-10-11 13:20:40 +0000 | [diff] [blame] | 1844 | execute_command (const char *command, int argc, const char *arg1, |
| 1845 | const char *arg2) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1846 | { |
| 1847 | int ret; |
| 1848 | pid_t pid; |
| 1849 | int status; |
| 1850 | |
| 1851 | /* Call fork(). */ |
| 1852 | pid = fork (); |
| 1853 | |
| 1854 | if (pid < 0) |
| 1855 | { |
| 1856 | /* Failure of fork(). */ |
ajs | 6099b3b | 2004-11-20 02:06:59 +0000 | [diff] [blame] | 1857 | fprintf (stderr, "Can't fork: %s\n", safe_strerror (errno)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1858 | exit (1); |
| 1859 | } |
| 1860 | else if (pid == 0) |
| 1861 | { |
| 1862 | /* This is child process. */ |
| 1863 | switch (argc) |
| 1864 | { |
| 1865 | case 0: |
hasso | fa2b17e | 2004-03-04 17:45:00 +0000 | [diff] [blame] | 1866 | ret = execlp (command, command, (const char *)NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1867 | break; |
| 1868 | case 1: |
hasso | fa2b17e | 2004-03-04 17:45:00 +0000 | [diff] [blame] | 1869 | ret = execlp (command, command, arg1, (const char *)NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1870 | break; |
| 1871 | case 2: |
hasso | fa2b17e | 2004-03-04 17:45:00 +0000 | [diff] [blame] | 1872 | ret = execlp (command, command, arg1, arg2, (const char *)NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1873 | break; |
| 1874 | } |
| 1875 | |
| 1876 | /* When execlp suceed, this part is not executed. */ |
ajs | 6099b3b | 2004-11-20 02:06:59 +0000 | [diff] [blame] | 1877 | fprintf (stderr, "Can't execute %s: %s\n", command, safe_strerror (errno)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1878 | exit (1); |
| 1879 | } |
| 1880 | else |
| 1881 | { |
| 1882 | /* This is parent. */ |
| 1883 | execute_flag = 1; |
| 1884 | ret = wait4 (pid, &status, 0, NULL); |
| 1885 | execute_flag = 0; |
| 1886 | } |
| 1887 | return 0; |
| 1888 | } |
| 1889 | |
| 1890 | DEFUN (vtysh_ping, |
| 1891 | vtysh_ping_cmd, |
| 1892 | "ping WORD", |
hasso | 4eeccf1 | 2003-06-25 10:49:55 +0000 | [diff] [blame] | 1893 | "Send echo messages\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1894 | "Ping destination address or hostname\n") |
| 1895 | { |
| 1896 | execute_command ("ping", 1, argv[0], NULL); |
| 1897 | return CMD_SUCCESS; |
| 1898 | } |
| 1899 | |
hasso | 4eeccf1 | 2003-06-25 10:49:55 +0000 | [diff] [blame] | 1900 | ALIAS (vtysh_ping, |
| 1901 | vtysh_ping_ip_cmd, |
| 1902 | "ping ip WORD", |
| 1903 | "Send echo messages\n" |
| 1904 | "IP echo\n" |
| 1905 | "Ping destination address or hostname\n") |
| 1906 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1907 | DEFUN (vtysh_traceroute, |
| 1908 | vtysh_traceroute_cmd, |
| 1909 | "traceroute WORD", |
| 1910 | "Trace route to destination\n" |
| 1911 | "Trace route to destination address or hostname\n") |
| 1912 | { |
| 1913 | execute_command ("traceroute", 1, argv[0], NULL); |
| 1914 | return CMD_SUCCESS; |
| 1915 | } |
| 1916 | |
hasso | 4eeccf1 | 2003-06-25 10:49:55 +0000 | [diff] [blame] | 1917 | ALIAS (vtysh_traceroute, |
| 1918 | vtysh_traceroute_ip_cmd, |
| 1919 | "traceroute ip WORD", |
| 1920 | "Trace route to destination\n" |
| 1921 | "IP trace\n" |
| 1922 | "Trace route to destination address or hostname\n") |
| 1923 | |
| 1924 | #ifdef HAVE_IPV6 |
| 1925 | DEFUN (vtysh_ping6, |
| 1926 | vtysh_ping6_cmd, |
| 1927 | "ping ipv6 WORD", |
| 1928 | "Send echo messages\n" |
| 1929 | "IPv6 echo\n" |
| 1930 | "Ping destination address or hostname\n") |
| 1931 | { |
| 1932 | execute_command ("ping6", 1, argv[0], NULL); |
| 1933 | return CMD_SUCCESS; |
| 1934 | } |
| 1935 | |
| 1936 | DEFUN (vtysh_traceroute6, |
| 1937 | vtysh_traceroute6_cmd, |
| 1938 | "traceroute ipv6 WORD", |
| 1939 | "Trace route to destination\n" |
| 1940 | "IPv6 trace\n" |
| 1941 | "Trace route to destination address or hostname\n") |
| 1942 | { |
| 1943 | execute_command ("traceroute6", 1, argv[0], NULL); |
| 1944 | return CMD_SUCCESS; |
| 1945 | } |
| 1946 | #endif |
| 1947 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1948 | DEFUN (vtysh_telnet, |
| 1949 | vtysh_telnet_cmd, |
| 1950 | "telnet WORD", |
| 1951 | "Open a telnet connection\n" |
| 1952 | "IP address or hostname of a remote system\n") |
| 1953 | { |
| 1954 | execute_command ("telnet", 1, argv[0], NULL); |
| 1955 | return CMD_SUCCESS; |
| 1956 | } |
| 1957 | |
| 1958 | DEFUN (vtysh_telnet_port, |
| 1959 | vtysh_telnet_port_cmd, |
| 1960 | "telnet WORD PORT", |
| 1961 | "Open a telnet connection\n" |
| 1962 | "IP address or hostname of a remote system\n" |
| 1963 | "TCP Port number\n") |
| 1964 | { |
| 1965 | execute_command ("telnet", 2, argv[0], argv[1]); |
| 1966 | return CMD_SUCCESS; |
| 1967 | } |
| 1968 | |
paul | 5087df5 | 2003-01-25 06:56:09 +0000 | [diff] [blame] | 1969 | DEFUN (vtysh_ssh, |
| 1970 | vtysh_ssh_cmd, |
| 1971 | "ssh WORD", |
| 1972 | "Open an ssh connection\n" |
| 1973 | "[user@]host\n") |
| 1974 | { |
| 1975 | execute_command ("ssh", 1, argv[0], NULL); |
| 1976 | return CMD_SUCCESS; |
| 1977 | } |
| 1978 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1979 | DEFUN (vtysh_start_shell, |
| 1980 | vtysh_start_shell_cmd, |
| 1981 | "start-shell", |
| 1982 | "Start UNIX shell\n") |
| 1983 | { |
| 1984 | execute_command ("sh", 0, NULL, NULL); |
| 1985 | return CMD_SUCCESS; |
| 1986 | } |
| 1987 | |
| 1988 | DEFUN (vtysh_start_bash, |
| 1989 | vtysh_start_bash_cmd, |
| 1990 | "start-shell bash", |
| 1991 | "Start UNIX shell\n" |
| 1992 | "Start bash\n") |
| 1993 | { |
| 1994 | execute_command ("bash", 0, NULL, NULL); |
| 1995 | return CMD_SUCCESS; |
| 1996 | } |
| 1997 | |
| 1998 | DEFUN (vtysh_start_zsh, |
| 1999 | vtysh_start_zsh_cmd, |
| 2000 | "start-shell zsh", |
| 2001 | "Start UNIX shell\n" |
| 2002 | "Start Z shell\n") |
| 2003 | { |
| 2004 | execute_command ("zsh", 0, NULL, NULL); |
| 2005 | return CMD_SUCCESS; |
| 2006 | } |
hasso | b094d26 | 2004-08-25 12:22:00 +0000 | [diff] [blame] | 2007 | |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 2008 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2009 | vtysh_install_default (enum node_type node) |
| 2010 | { |
| 2011 | install_element (node, &config_list_cmd); |
| 2012 | } |
| 2013 | |
| 2014 | /* Making connection to protocol daemon. */ |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 2015 | static int |
ajs | b1aa147 | 2005-01-28 21:11:46 +0000 | [diff] [blame] | 2016 | vtysh_connect (struct vtysh_client *vclient) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2017 | { |
| 2018 | int ret; |
| 2019 | int sock, len; |
| 2020 | struct sockaddr_un addr; |
| 2021 | struct stat s_stat; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2022 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2023 | /* Stat socket to see if we have permission to access it. */ |
ajs | b1aa147 | 2005-01-28 21:11:46 +0000 | [diff] [blame] | 2024 | ret = stat (vclient->path, &s_stat); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2025 | if (ret < 0 && errno != ENOENT) |
| 2026 | { |
| 2027 | fprintf (stderr, "vtysh_connect(%s): stat = %s\n", |
ajs | b1aa147 | 2005-01-28 21:11:46 +0000 | [diff] [blame] | 2028 | vclient->path, safe_strerror(errno)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2029 | exit(1); |
| 2030 | } |
| 2031 | |
| 2032 | if (ret >= 0) |
| 2033 | { |
| 2034 | if (! S_ISSOCK(s_stat.st_mode)) |
| 2035 | { |
| 2036 | fprintf (stderr, "vtysh_connect(%s): Not a socket\n", |
ajs | b1aa147 | 2005-01-28 21:11:46 +0000 | [diff] [blame] | 2037 | vclient->path); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2038 | exit (1); |
| 2039 | } |
| 2040 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2041 | } |
| 2042 | |
| 2043 | sock = socket (AF_UNIX, SOCK_STREAM, 0); |
| 2044 | if (sock < 0) |
| 2045 | { |
| 2046 | #ifdef DEBUG |
ajs | b1aa147 | 2005-01-28 21:11:46 +0000 | [diff] [blame] | 2047 | fprintf(stderr, "vtysh_connect(%s): socket = %s\n", vclient->path, |
ajs | 6099b3b | 2004-11-20 02:06:59 +0000 | [diff] [blame] | 2048 | safe_strerror(errno)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2049 | #endif /* DEBUG */ |
| 2050 | return -1; |
| 2051 | } |
| 2052 | |
| 2053 | memset (&addr, 0, sizeof (struct sockaddr_un)); |
| 2054 | addr.sun_family = AF_UNIX; |
ajs | b1aa147 | 2005-01-28 21:11:46 +0000 | [diff] [blame] | 2055 | strncpy (addr.sun_path, vclient->path, strlen (vclient->path)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2056 | #ifdef HAVE_SUN_LEN |
| 2057 | len = addr.sun_len = SUN_LEN(&addr); |
| 2058 | #else |
| 2059 | len = sizeof (addr.sun_family) + strlen (addr.sun_path); |
| 2060 | #endif /* HAVE_SUN_LEN */ |
| 2061 | |
| 2062 | ret = connect (sock, (struct sockaddr *) &addr, len); |
| 2063 | if (ret < 0) |
| 2064 | { |
| 2065 | #ifdef DEBUG |
ajs | b1aa147 | 2005-01-28 21:11:46 +0000 | [diff] [blame] | 2066 | fprintf(stderr, "vtysh_connect(%s): connect = %s\n", vclient->path, |
ajs | 6099b3b | 2004-11-20 02:06:59 +0000 | [diff] [blame] | 2067 | safe_strerror(errno)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2068 | #endif /* DEBUG */ |
| 2069 | close (sock); |
| 2070 | return -1; |
| 2071 | } |
| 2072 | vclient->fd = sock; |
| 2073 | |
| 2074 | return 0; |
| 2075 | } |
| 2076 | |
| 2077 | void |
ajs | b1aa147 | 2005-01-28 21:11:46 +0000 | [diff] [blame] | 2078 | vtysh_connect_all(void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2079 | { |
ajs | b1aa147 | 2005-01-28 21:11:46 +0000 | [diff] [blame] | 2080 | u_int i; |
| 2081 | |
| 2082 | for (i = 0; i < VTYSH_INDEX_MAX; i++) |
| 2083 | { |
| 2084 | vtysh_connect(&vtysh_client[i]); |
| 2085 | /* We need direct access to ripd in vtysh_exit_ripd_only. */ |
| 2086 | if (vtysh_client[i].flag == VTYSH_RIPD) |
| 2087 | ripd_client = &vtysh_client[i]; |
| 2088 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2089 | } |
| 2090 | |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 2091 | /* To disable readline's filename completion. */ |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 2092 | static char * |
paul | dfc0d9b | 2003-04-18 23:55:29 +0000 | [diff] [blame] | 2093 | vtysh_completion_entry_function (const char *ignore, int invoking_key) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2094 | { |
paul | dfc0d9b | 2003-04-18 23:55:29 +0000 | [diff] [blame] | 2095 | return NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2096 | } |
| 2097 | |
| 2098 | void |
ajs | b1aa147 | 2005-01-28 21:11:46 +0000 | [diff] [blame] | 2099 | vtysh_readline_init (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2100 | { |
| 2101 | /* readline related settings. */ |
hasso | 53a6f93 | 2005-09-15 06:50:53 +0000 | [diff] [blame] | 2102 | rl_bind_key ('?', (Function *) vtysh_rl_describe); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2103 | rl_completion_entry_function = vtysh_completion_entry_function; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2104 | rl_attempted_completion_function = (CPPFunction *)new_completion; |
| 2105 | /* do not append space after completion. It will be appended |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 2106 | * in new_completion() function explicitly. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2107 | rl_completion_append_character = '\0'; |
| 2108 | } |
| 2109 | |
| 2110 | char * |
ajs | b1aa147 | 2005-01-28 21:11:46 +0000 | [diff] [blame] | 2111 | vtysh_prompt (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2112 | { |
| 2113 | struct utsname names; |
| 2114 | static char buf[100]; |
| 2115 | const char*hostname; |
| 2116 | extern struct host host; |
| 2117 | |
| 2118 | hostname = host.name; |
| 2119 | |
| 2120 | if (!hostname) |
| 2121 | { |
| 2122 | uname (&names); |
| 2123 | hostname = names.nodename; |
| 2124 | } |
| 2125 | |
| 2126 | snprintf (buf, sizeof buf, cmd_prompt (vty->node), hostname); |
| 2127 | |
| 2128 | return buf; |
| 2129 | } |
| 2130 | |
| 2131 | void |
ajs | b1aa147 | 2005-01-28 21:11:46 +0000 | [diff] [blame] | 2132 | vtysh_init_vty (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2133 | { |
| 2134 | /* Make vty structure. */ |
| 2135 | vty = vty_new (); |
| 2136 | vty->type = VTY_SHELL; |
| 2137 | vty->node = VIEW_NODE; |
| 2138 | |
| 2139 | /* Initialize commands. */ |
| 2140 | cmd_init (0); |
| 2141 | |
| 2142 | /* Install nodes. */ |
| 2143 | install_node (&bgp_node, NULL); |
| 2144 | install_node (&rip_node, NULL); |
| 2145 | install_node (&interface_node, NULL); |
| 2146 | install_node (&rmap_node, NULL); |
| 2147 | install_node (&zebra_node, NULL); |
| 2148 | install_node (&bgp_vpnv4_node, NULL); |
| 2149 | install_node (&bgp_ipv4_node, NULL); |
| 2150 | install_node (&bgp_ipv4m_node, NULL); |
| 2151 | /* #ifdef HAVE_IPV6 */ |
| 2152 | install_node (&bgp_ipv6_node, NULL); |
paul | 57b5b7e | 2005-08-22 22:44:29 +0000 | [diff] [blame] | 2153 | install_node (&bgp_ipv6m_node, NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2154 | /* #endif */ |
| 2155 | install_node (&ospf_node, NULL); |
| 2156 | /* #ifdef HAVE_IPV6 */ |
| 2157 | install_node (&ripng_node, NULL); |
| 2158 | install_node (&ospf6_node, NULL); |
| 2159 | /* #endif */ |
| 2160 | install_node (&keychain_node, NULL); |
| 2161 | install_node (&keychain_key_node, NULL); |
hasso | c25e458 | 2003-12-23 10:39:08 +0000 | [diff] [blame] | 2162 | install_node (&isis_node, NULL); |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 2163 | install_node (&vty_node, NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2164 | |
| 2165 | vtysh_install_default (VIEW_NODE); |
| 2166 | vtysh_install_default (ENABLE_NODE); |
| 2167 | vtysh_install_default (CONFIG_NODE); |
| 2168 | vtysh_install_default (BGP_NODE); |
| 2169 | vtysh_install_default (RIP_NODE); |
| 2170 | vtysh_install_default (INTERFACE_NODE); |
| 2171 | vtysh_install_default (RMAP_NODE); |
| 2172 | vtysh_install_default (ZEBRA_NODE); |
| 2173 | vtysh_install_default (BGP_VPNV4_NODE); |
| 2174 | vtysh_install_default (BGP_IPV4_NODE); |
| 2175 | vtysh_install_default (BGP_IPV4M_NODE); |
| 2176 | vtysh_install_default (BGP_IPV6_NODE); |
paul | 57b5b7e | 2005-08-22 22:44:29 +0000 | [diff] [blame] | 2177 | vtysh_install_default (BGP_IPV6M_NODE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2178 | vtysh_install_default (OSPF_NODE); |
| 2179 | vtysh_install_default (RIPNG_NODE); |
| 2180 | vtysh_install_default (OSPF6_NODE); |
hasso | c25e458 | 2003-12-23 10:39:08 +0000 | [diff] [blame] | 2181 | vtysh_install_default (ISIS_NODE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2182 | vtysh_install_default (KEYCHAIN_NODE); |
| 2183 | vtysh_install_default (KEYCHAIN_KEY_NODE); |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 2184 | vtysh_install_default (VTY_NODE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2185 | |
| 2186 | install_element (VIEW_NODE, &vtysh_enable_cmd); |
| 2187 | install_element (ENABLE_NODE, &vtysh_config_terminal_cmd); |
| 2188 | install_element (ENABLE_NODE, &vtysh_disable_cmd); |
| 2189 | |
| 2190 | /* "exit" command. */ |
| 2191 | install_element (VIEW_NODE, &vtysh_exit_all_cmd); |
| 2192 | install_element (VIEW_NODE, &vtysh_quit_all_cmd); |
| 2193 | install_element (CONFIG_NODE, &vtysh_exit_all_cmd); |
| 2194 | /* install_element (CONFIG_NODE, &vtysh_quit_all_cmd); */ |
| 2195 | install_element (ENABLE_NODE, &vtysh_exit_all_cmd); |
| 2196 | install_element (ENABLE_NODE, &vtysh_quit_all_cmd); |
| 2197 | install_element (RIP_NODE, &vtysh_exit_ripd_cmd); |
| 2198 | install_element (RIP_NODE, &vtysh_quit_ripd_cmd); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2199 | install_element (RIPNG_NODE, &vtysh_exit_ripngd_cmd); |
| 2200 | install_element (RIPNG_NODE, &vtysh_quit_ripngd_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2201 | install_element (OSPF_NODE, &vtysh_exit_ospfd_cmd); |
| 2202 | install_element (OSPF_NODE, &vtysh_quit_ospfd_cmd); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2203 | install_element (OSPF6_NODE, &vtysh_exit_ospf6d_cmd); |
| 2204 | install_element (OSPF6_NODE, &vtysh_quit_ospf6d_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2205 | install_element (BGP_NODE, &vtysh_exit_bgpd_cmd); |
| 2206 | install_element (BGP_NODE, &vtysh_quit_bgpd_cmd); |
| 2207 | install_element (BGP_VPNV4_NODE, &vtysh_exit_bgpd_cmd); |
| 2208 | install_element (BGP_VPNV4_NODE, &vtysh_quit_bgpd_cmd); |
| 2209 | install_element (BGP_IPV4_NODE, &vtysh_exit_bgpd_cmd); |
| 2210 | install_element (BGP_IPV4_NODE, &vtysh_quit_bgpd_cmd); |
| 2211 | install_element (BGP_IPV4M_NODE, &vtysh_exit_bgpd_cmd); |
| 2212 | install_element (BGP_IPV4M_NODE, &vtysh_quit_bgpd_cmd); |
| 2213 | install_element (BGP_IPV6_NODE, &vtysh_exit_bgpd_cmd); |
| 2214 | install_element (BGP_IPV6_NODE, &vtysh_quit_bgpd_cmd); |
paul | 57b5b7e | 2005-08-22 22:44:29 +0000 | [diff] [blame] | 2215 | install_element (BGP_IPV6M_NODE, &vtysh_exit_bgpd_cmd); |
| 2216 | install_element (BGP_IPV6M_NODE, &vtysh_quit_bgpd_cmd); |
hasso | c25e458 | 2003-12-23 10:39:08 +0000 | [diff] [blame] | 2217 | install_element (ISIS_NODE, &vtysh_exit_isisd_cmd); |
| 2218 | install_element (ISIS_NODE, &vtysh_quit_isisd_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2219 | install_element (KEYCHAIN_NODE, &vtysh_exit_ripd_cmd); |
| 2220 | install_element (KEYCHAIN_NODE, &vtysh_quit_ripd_cmd); |
| 2221 | install_element (KEYCHAIN_KEY_NODE, &vtysh_exit_ripd_cmd); |
| 2222 | install_element (KEYCHAIN_KEY_NODE, &vtysh_quit_ripd_cmd); |
| 2223 | install_element (RMAP_NODE, &vtysh_exit_rmap_cmd); |
| 2224 | install_element (RMAP_NODE, &vtysh_quit_rmap_cmd); |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 2225 | install_element (VTY_NODE, &vtysh_exit_line_vty_cmd); |
| 2226 | install_element (VTY_NODE, &vtysh_quit_line_vty_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2227 | |
| 2228 | /* "end" command. */ |
| 2229 | install_element (CONFIG_NODE, &vtysh_end_all_cmd); |
| 2230 | install_element (ENABLE_NODE, &vtysh_end_all_cmd); |
| 2231 | install_element (RIP_NODE, &vtysh_end_all_cmd); |
| 2232 | install_element (RIPNG_NODE, &vtysh_end_all_cmd); |
| 2233 | install_element (OSPF_NODE, &vtysh_end_all_cmd); |
| 2234 | install_element (OSPF6_NODE, &vtysh_end_all_cmd); |
| 2235 | install_element (BGP_NODE, &vtysh_end_all_cmd); |
| 2236 | install_element (BGP_IPV4_NODE, &vtysh_end_all_cmd); |
| 2237 | install_element (BGP_IPV4M_NODE, &vtysh_end_all_cmd); |
| 2238 | install_element (BGP_VPNV4_NODE, &vtysh_end_all_cmd); |
| 2239 | install_element (BGP_IPV6_NODE, &vtysh_end_all_cmd); |
paul | 57b5b7e | 2005-08-22 22:44:29 +0000 | [diff] [blame] | 2240 | install_element (BGP_IPV6M_NODE, &vtysh_end_all_cmd); |
hasso | c25e458 | 2003-12-23 10:39:08 +0000 | [diff] [blame] | 2241 | install_element (ISIS_NODE, &vtysh_end_all_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2242 | install_element (KEYCHAIN_NODE, &vtysh_end_all_cmd); |
| 2243 | install_element (KEYCHAIN_KEY_NODE, &vtysh_end_all_cmd); |
| 2244 | install_element (RMAP_NODE, &vtysh_end_all_cmd); |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 2245 | install_element (VTY_NODE, &vtysh_end_all_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2246 | |
paul | 338a991 | 2003-03-01 15:44:10 +0000 | [diff] [blame] | 2247 | install_element (INTERFACE_NODE, &interface_desc_cmd); |
paul | 464dc8d | 2003-03-28 02:25:45 +0000 | [diff] [blame] | 2248 | install_element (INTERFACE_NODE, &no_interface_desc_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2249 | install_element (INTERFACE_NODE, &vtysh_end_all_cmd); |
| 2250 | install_element (INTERFACE_NODE, &vtysh_exit_interface_cmd); |
| 2251 | install_element (INTERFACE_NODE, &vtysh_quit_interface_cmd); |
| 2252 | install_element (CONFIG_NODE, &router_rip_cmd); |
| 2253 | #ifdef HAVE_IPV6 |
| 2254 | install_element (CONFIG_NODE, &router_ripng_cmd); |
| 2255 | #endif |
| 2256 | install_element (CONFIG_NODE, &router_ospf_cmd); |
| 2257 | #ifdef HAVE_IPV6 |
| 2258 | install_element (CONFIG_NODE, &router_ospf6_cmd); |
| 2259 | #endif |
hasso | c25e458 | 2003-12-23 10:39:08 +0000 | [diff] [blame] | 2260 | install_element (CONFIG_NODE, &router_isis_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2261 | install_element (CONFIG_NODE, &router_bgp_cmd); |
| 2262 | install_element (BGP_NODE, &address_family_vpnv4_cmd); |
| 2263 | install_element (BGP_NODE, &address_family_vpnv4_unicast_cmd); |
| 2264 | install_element (BGP_NODE, &address_family_ipv4_unicast_cmd); |
| 2265 | install_element (BGP_NODE, &address_family_ipv4_multicast_cmd); |
| 2266 | #ifdef HAVE_IPV6 |
| 2267 | install_element (BGP_NODE, &address_family_ipv6_cmd); |
| 2268 | install_element (BGP_NODE, &address_family_ipv6_unicast_cmd); |
| 2269 | #endif |
| 2270 | install_element (BGP_VPNV4_NODE, &exit_address_family_cmd); |
| 2271 | install_element (BGP_IPV4_NODE, &exit_address_family_cmd); |
| 2272 | install_element (BGP_IPV4M_NODE, &exit_address_family_cmd); |
| 2273 | install_element (BGP_IPV6_NODE, &exit_address_family_cmd); |
paul | 57b5b7e | 2005-08-22 22:44:29 +0000 | [diff] [blame] | 2274 | install_element (BGP_IPV6M_NODE, &exit_address_family_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2275 | install_element (CONFIG_NODE, &key_chain_cmd); |
| 2276 | install_element (CONFIG_NODE, &route_map_cmd); |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 2277 | install_element (CONFIG_NODE, &vtysh_line_vty_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2278 | install_element (KEYCHAIN_NODE, &key_cmd); |
| 2279 | install_element (KEYCHAIN_NODE, &key_chain_cmd); |
| 2280 | install_element (KEYCHAIN_KEY_NODE, &key_chain_cmd); |
| 2281 | install_element (CONFIG_NODE, &vtysh_interface_cmd); |
paul | 32d2463 | 2003-05-23 09:25:20 +0000 | [diff] [blame] | 2282 | install_element (CONFIG_NODE, &vtysh_no_interface_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2283 | install_element (ENABLE_NODE, &vtysh_show_running_config_cmd); |
| 2284 | install_element (ENABLE_NODE, &vtysh_copy_runningconfig_startupconfig_cmd); |
| 2285 | install_element (ENABLE_NODE, &vtysh_write_file_cmd); |
hasso | 4a6e225 | 2003-05-25 11:51:29 +0000 | [diff] [blame] | 2286 | install_element (ENABLE_NODE, &vtysh_write_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2287 | |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 2288 | /* "write terminal" command. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2289 | install_element (ENABLE_NODE, &vtysh_write_terminal_cmd); |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 2290 | |
| 2291 | install_element (CONFIG_NODE, &vtysh_integrated_config_cmd); |
| 2292 | install_element (CONFIG_NODE, &no_vtysh_integrated_config_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2293 | |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 2294 | /* "write memory" command. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2295 | install_element (ENABLE_NODE, &vtysh_write_memory_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2296 | |
hasso | 34553cc | 2004-08-27 13:56:39 +0000 | [diff] [blame] | 2297 | install_element (VIEW_NODE, &vtysh_terminal_length_cmd); |
| 2298 | install_element (ENABLE_NODE, &vtysh_terminal_length_cmd); |
| 2299 | install_element (VIEW_NODE, &vtysh_terminal_no_length_cmd); |
| 2300 | install_element (ENABLE_NODE, &vtysh_terminal_no_length_cmd); |
hasso | f2799e6 | 2004-10-28 17:43:11 +0000 | [diff] [blame] | 2301 | install_element (VIEW_NODE, &vtysh_show_daemons_cmd); |
| 2302 | install_element (ENABLE_NODE, &vtysh_show_daemons_cmd); |
hasso | 34553cc | 2004-08-27 13:56:39 +0000 | [diff] [blame] | 2303 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2304 | install_element (VIEW_NODE, &vtysh_ping_cmd); |
hasso | 4eeccf1 | 2003-06-25 10:49:55 +0000 | [diff] [blame] | 2305 | install_element (VIEW_NODE, &vtysh_ping_ip_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2306 | install_element (VIEW_NODE, &vtysh_traceroute_cmd); |
hasso | 4eeccf1 | 2003-06-25 10:49:55 +0000 | [diff] [blame] | 2307 | install_element (VIEW_NODE, &vtysh_traceroute_ip_cmd); |
| 2308 | #ifdef HAVE_IPV6 |
| 2309 | install_element (VIEW_NODE, &vtysh_ping6_cmd); |
| 2310 | install_element (VIEW_NODE, &vtysh_traceroute6_cmd); |
| 2311 | #endif |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2312 | install_element (VIEW_NODE, &vtysh_telnet_cmd); |
| 2313 | install_element (VIEW_NODE, &vtysh_telnet_port_cmd); |
paul | 5087df5 | 2003-01-25 06:56:09 +0000 | [diff] [blame] | 2314 | install_element (VIEW_NODE, &vtysh_ssh_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2315 | install_element (ENABLE_NODE, &vtysh_ping_cmd); |
hasso | 4eeccf1 | 2003-06-25 10:49:55 +0000 | [diff] [blame] | 2316 | install_element (ENABLE_NODE, &vtysh_ping_ip_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2317 | install_element (ENABLE_NODE, &vtysh_traceroute_cmd); |
hasso | 4eeccf1 | 2003-06-25 10:49:55 +0000 | [diff] [blame] | 2318 | install_element (ENABLE_NODE, &vtysh_traceroute_ip_cmd); |
| 2319 | #ifdef HAVE_IPV6 |
| 2320 | install_element (ENABLE_NODE, &vtysh_ping6_cmd); |
| 2321 | install_element (ENABLE_NODE, &vtysh_traceroute6_cmd); |
| 2322 | #endif |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2323 | install_element (ENABLE_NODE, &vtysh_telnet_cmd); |
| 2324 | install_element (ENABLE_NODE, &vtysh_telnet_port_cmd); |
hasso | 67e29ab | 2004-08-26 22:21:31 +0000 | [diff] [blame] | 2325 | install_element (ENABLE_NODE, &vtysh_ssh_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2326 | install_element (ENABLE_NODE, &vtysh_start_shell_cmd); |
| 2327 | install_element (ENABLE_NODE, &vtysh_start_bash_cmd); |
| 2328 | install_element (ENABLE_NODE, &vtysh_start_zsh_cmd); |
| 2329 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2330 | install_element (CONFIG_NODE, &vtysh_log_stdout_cmd); |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 2331 | install_element (CONFIG_NODE, &vtysh_log_stdout_level_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2332 | install_element (CONFIG_NODE, &no_vtysh_log_stdout_cmd); |
| 2333 | install_element (CONFIG_NODE, &vtysh_log_file_cmd); |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 2334 | install_element (CONFIG_NODE, &vtysh_log_file_level_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2335 | install_element (CONFIG_NODE, &no_vtysh_log_file_cmd); |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 2336 | install_element (CONFIG_NODE, &no_vtysh_log_file_level_cmd); |
| 2337 | install_element (CONFIG_NODE, &vtysh_log_monitor_cmd); |
| 2338 | install_element (CONFIG_NODE, &vtysh_log_monitor_level_cmd); |
| 2339 | install_element (CONFIG_NODE, &no_vtysh_log_monitor_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2340 | install_element (CONFIG_NODE, &vtysh_log_syslog_cmd); |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 2341 | install_element (CONFIG_NODE, &vtysh_log_syslog_level_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2342 | install_element (CONFIG_NODE, &no_vtysh_log_syslog_cmd); |
| 2343 | install_element (CONFIG_NODE, &vtysh_log_trap_cmd); |
| 2344 | install_element (CONFIG_NODE, &no_vtysh_log_trap_cmd); |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 2345 | install_element (CONFIG_NODE, &vtysh_log_facility_cmd); |
| 2346 | install_element (CONFIG_NODE, &no_vtysh_log_facility_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2347 | install_element (CONFIG_NODE, &vtysh_log_record_priority_cmd); |
| 2348 | install_element (CONFIG_NODE, &no_vtysh_log_record_priority_cmd); |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 2349 | |
| 2350 | install_element (CONFIG_NODE, &vtysh_service_password_encrypt_cmd); |
| 2351 | install_element (CONFIG_NODE, &no_vtysh_service_password_encrypt_cmd); |
| 2352 | |
| 2353 | install_element (CONFIG_NODE, &vtysh_password_cmd); |
| 2354 | install_element (CONFIG_NODE, &vtysh_password_text_cmd); |
| 2355 | install_element (CONFIG_NODE, &vtysh_enable_password_cmd); |
| 2356 | install_element (CONFIG_NODE, &vtysh_enable_password_text_cmd); |
| 2357 | install_element (CONFIG_NODE, &no_vtysh_enable_password_cmd); |
| 2358 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2359 | } |