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