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