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