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