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