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