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