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 | |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 55 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 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(): " |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 66 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 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 | |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 164 | static 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. */ |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 250 | static 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 | |
hasso | 87d683b | 2005-01-16 23:31:54 +0000 | [diff] [blame] | 265 | ret = cmd_execute_command (vline, vty, &cmd, 1); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 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 | 87d683b | 2005-01-16 23:31:54 +0000 | [diff] [blame] | 343 | ret = cmd_execute_command (vline, vty, &cmd, 1); |
hasso | b094d26 | 2004-08-25 12:22:00 +0000 | [diff] [blame] | 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 | |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 607 | static 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 | |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 638 | static char ** |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 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 | |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 655 | #if 0 |
| 656 | /* This function is not actually being used. */ |
| 657 | static char ** |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 658 | vtysh_completion (char *text, int start, int end) |
| 659 | { |
| 660 | int ret; |
| 661 | vector vline; |
| 662 | char **matched = NULL; |
| 663 | |
| 664 | if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE) |
| 665 | return NULL; |
| 666 | |
| 667 | vline = cmd_make_strvec (rl_line_buffer); |
| 668 | if (vline == NULL) |
| 669 | return NULL; |
| 670 | |
| 671 | /* In case of 'help \t'. */ |
| 672 | if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1])) |
| 673 | vector_set (vline, '\0'); |
| 674 | |
| 675 | matched = cmd_complete_command (vline, vty, &ret); |
| 676 | |
| 677 | cmd_free_strvec (vline); |
| 678 | |
| 679 | return (char **) matched; |
| 680 | } |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 681 | #endif |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 682 | |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 683 | /* Vty node structures. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 684 | struct cmd_node bgp_node = |
| 685 | { |
| 686 | BGP_NODE, |
| 687 | "%s(config-router)# ", |
| 688 | }; |
| 689 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 690 | struct cmd_node rip_node = |
| 691 | { |
| 692 | RIP_NODE, |
| 693 | "%s(config-router)# ", |
| 694 | }; |
| 695 | |
hasso | c25e458 | 2003-12-23 10:39:08 +0000 | [diff] [blame] | 696 | struct cmd_node isis_node = |
| 697 | { |
| 698 | ISIS_NODE, |
| 699 | "%s(config-router)# ", |
hasso | c25e458 | 2003-12-23 10:39:08 +0000 | [diff] [blame] | 700 | }; |
| 701 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 702 | struct cmd_node interface_node = |
| 703 | { |
| 704 | INTERFACE_NODE, |
| 705 | "%s(config-if)# ", |
| 706 | }; |
| 707 | |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 708 | struct cmd_node rmap_node = |
| 709 | { |
| 710 | RMAP_NODE, |
| 711 | "%s(config-route-map)# " |
| 712 | }; |
| 713 | |
| 714 | struct cmd_node zebra_node = |
| 715 | { |
| 716 | ZEBRA_NODE, |
| 717 | "%s(config-router)# " |
| 718 | }; |
| 719 | |
| 720 | struct cmd_node bgp_vpnv4_node = |
| 721 | { |
| 722 | BGP_VPNV4_NODE, |
| 723 | "%s(config-router-af)# " |
| 724 | }; |
| 725 | |
| 726 | struct cmd_node bgp_ipv4_node = |
| 727 | { |
| 728 | BGP_IPV4_NODE, |
| 729 | "%s(config-router-af)# " |
| 730 | }; |
| 731 | |
| 732 | struct cmd_node bgp_ipv4m_node = |
| 733 | { |
| 734 | BGP_IPV4M_NODE, |
| 735 | "%s(config-router-af)# " |
| 736 | }; |
| 737 | |
| 738 | struct cmd_node bgp_ipv6_node = |
| 739 | { |
| 740 | BGP_IPV6_NODE, |
| 741 | "%s(config-router-af)# " |
| 742 | }; |
| 743 | |
| 744 | struct cmd_node ospf_node = |
| 745 | { |
| 746 | OSPF_NODE, |
| 747 | "%s(config-router)# " |
| 748 | }; |
| 749 | |
| 750 | struct cmd_node ripng_node = |
| 751 | { |
| 752 | RIPNG_NODE, |
| 753 | "%s(config-router)# " |
| 754 | }; |
| 755 | |
| 756 | struct cmd_node ospf6_node = |
| 757 | { |
| 758 | OSPF6_NODE, |
| 759 | "%s(config-ospf6)# " |
| 760 | }; |
| 761 | |
| 762 | struct cmd_node keychain_node = |
| 763 | { |
| 764 | KEYCHAIN_NODE, |
| 765 | "%s(config-keychain)# " |
| 766 | }; |
| 767 | |
| 768 | struct cmd_node keychain_key_node = |
| 769 | { |
| 770 | KEYCHAIN_KEY_NODE, |
| 771 | "%s(config-keychain-key)# " |
| 772 | }; |
| 773 | |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 774 | /* Defined in lib/vty.c */ |
| 775 | extern struct cmd_node vty_node; |
| 776 | |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 777 | /* When '^Z' is received from vty, move down to the enable mode. */ |
| 778 | int |
| 779 | vtysh_end () |
| 780 | { |
| 781 | switch (vty->node) |
| 782 | { |
| 783 | case VIEW_NODE: |
| 784 | case ENABLE_NODE: |
| 785 | /* Nothing to do. */ |
| 786 | break; |
| 787 | default: |
| 788 | vty->node = ENABLE_NODE; |
| 789 | break; |
| 790 | } |
| 791 | return CMD_SUCCESS; |
| 792 | } |
| 793 | |
| 794 | DEFUNSH (VTYSH_ALL, |
| 795 | vtysh_end_all, |
| 796 | vtysh_end_all_cmd, |
| 797 | "end", |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 798 | "End current mode and change to enable mode\n") |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 799 | { |
hasso | 4289546 | 2004-09-26 16:25:07 +0000 | [diff] [blame] | 800 | return vtysh_end (); |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 801 | } |
| 802 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 803 | DEFUNSH (VTYSH_BGPD, |
| 804 | router_bgp, |
| 805 | router_bgp_cmd, |
| 806 | "router bgp <1-65535>", |
| 807 | ROUTER_STR |
| 808 | BGP_STR |
| 809 | AS_STR) |
| 810 | { |
| 811 | vty->node = BGP_NODE; |
| 812 | return CMD_SUCCESS; |
| 813 | } |
| 814 | |
| 815 | DEFUNSH (VTYSH_BGPD, |
| 816 | address_family_vpnv4, |
| 817 | address_family_vpnv4_cmd, |
| 818 | "address-family vpnv4", |
| 819 | "Enter Address Family command mode\n" |
| 820 | "Address family\n") |
| 821 | { |
| 822 | vty->node = BGP_VPNV4_NODE; |
| 823 | return CMD_SUCCESS; |
| 824 | } |
| 825 | |
| 826 | DEFUNSH (VTYSH_BGPD, |
| 827 | address_family_vpnv4_unicast, |
| 828 | address_family_vpnv4_unicast_cmd, |
| 829 | "address-family vpnv4 unicast", |
| 830 | "Enter Address Family command mode\n" |
| 831 | "Address family\n" |
| 832 | "Address Family Modifier\n") |
| 833 | { |
| 834 | vty->node = BGP_VPNV4_NODE; |
| 835 | return CMD_SUCCESS; |
| 836 | } |
| 837 | |
| 838 | DEFUNSH (VTYSH_BGPD, |
| 839 | address_family_ipv4_unicast, |
| 840 | address_family_ipv4_unicast_cmd, |
| 841 | "address-family ipv4 unicast", |
| 842 | "Enter Address Family command mode\n" |
| 843 | "Address family\n" |
| 844 | "Address Family Modifier\n") |
| 845 | { |
| 846 | vty->node = BGP_IPV4_NODE; |
| 847 | return CMD_SUCCESS; |
| 848 | } |
| 849 | |
| 850 | DEFUNSH (VTYSH_BGPD, |
| 851 | address_family_ipv4_multicast, |
| 852 | address_family_ipv4_multicast_cmd, |
| 853 | "address-family ipv4 multicast", |
| 854 | "Enter Address Family command mode\n" |
| 855 | "Address family\n" |
| 856 | "Address Family Modifier\n") |
| 857 | { |
| 858 | vty->node = BGP_IPV4M_NODE; |
| 859 | return CMD_SUCCESS; |
| 860 | } |
| 861 | |
| 862 | DEFUNSH (VTYSH_BGPD, |
| 863 | address_family_ipv6, |
| 864 | address_family_ipv6_cmd, |
| 865 | "address-family ipv6", |
| 866 | "Enter Address Family command mode\n" |
| 867 | "Address family\n") |
| 868 | { |
| 869 | vty->node = BGP_IPV6_NODE; |
| 870 | return CMD_SUCCESS; |
| 871 | } |
| 872 | |
| 873 | DEFUNSH (VTYSH_BGPD, |
| 874 | address_family_ipv6_unicast, |
| 875 | address_family_ipv6_unicast_cmd, |
| 876 | "address-family ipv6 unicast", |
| 877 | "Enter Address Family command mode\n" |
| 878 | "Address family\n" |
| 879 | "Address Family Modifier\n") |
| 880 | { |
| 881 | vty->node = BGP_IPV6_NODE; |
| 882 | return CMD_SUCCESS; |
| 883 | } |
| 884 | |
| 885 | DEFUNSH (VTYSH_RIPD, |
| 886 | key_chain, |
| 887 | key_chain_cmd, |
| 888 | "key chain WORD", |
| 889 | "Authentication key management\n" |
| 890 | "Key-chain management\n" |
| 891 | "Key-chain name\n") |
| 892 | { |
| 893 | vty->node = KEYCHAIN_NODE; |
| 894 | return CMD_SUCCESS; |
| 895 | } |
| 896 | |
| 897 | DEFUNSH (VTYSH_RIPD, |
| 898 | key, |
| 899 | key_cmd, |
| 900 | "key <0-2147483647>", |
| 901 | "Configure a key\n" |
| 902 | "Key identifier number\n") |
| 903 | { |
| 904 | vty->node = KEYCHAIN_KEY_NODE; |
| 905 | return CMD_SUCCESS; |
| 906 | } |
| 907 | |
| 908 | DEFUNSH (VTYSH_RIPD, |
| 909 | router_rip, |
| 910 | router_rip_cmd, |
| 911 | "router rip", |
| 912 | ROUTER_STR |
| 913 | "RIP") |
| 914 | { |
| 915 | vty->node = RIP_NODE; |
| 916 | return CMD_SUCCESS; |
| 917 | } |
| 918 | |
| 919 | DEFUNSH (VTYSH_RIPNGD, |
| 920 | router_ripng, |
| 921 | router_ripng_cmd, |
| 922 | "router ripng", |
| 923 | ROUTER_STR |
| 924 | "RIPng") |
| 925 | { |
| 926 | vty->node = RIPNG_NODE; |
| 927 | return CMD_SUCCESS; |
| 928 | } |
| 929 | |
| 930 | DEFUNSH (VTYSH_OSPFD, |
| 931 | router_ospf, |
| 932 | router_ospf_cmd, |
| 933 | "router ospf", |
| 934 | "Enable a routing process\n" |
| 935 | "Start OSPF configuration\n") |
| 936 | { |
| 937 | vty->node = OSPF_NODE; |
| 938 | return CMD_SUCCESS; |
| 939 | } |
| 940 | |
| 941 | DEFUNSH (VTYSH_OSPF6D, |
| 942 | router_ospf6, |
| 943 | router_ospf6_cmd, |
| 944 | "router ospf6", |
| 945 | OSPF6_ROUTER_STR |
| 946 | OSPF6_STR) |
| 947 | { |
| 948 | vty->node = OSPF6_NODE; |
| 949 | return CMD_SUCCESS; |
| 950 | } |
| 951 | |
hasso | c25e458 | 2003-12-23 10:39:08 +0000 | [diff] [blame] | 952 | DEFUNSH (VTYSH_ISISD, |
hasso | b094d26 | 2004-08-25 12:22:00 +0000 | [diff] [blame] | 953 | router_isis, |
| 954 | router_isis_cmd, |
| 955 | "router isis WORD", |
| 956 | ROUTER_STR |
| 957 | "ISO IS-IS\n" |
| 958 | "ISO Routing area tag") |
hasso | c25e458 | 2003-12-23 10:39:08 +0000 | [diff] [blame] | 959 | { |
| 960 | vty->node = ISIS_NODE; |
| 961 | return CMD_SUCCESS; |
| 962 | } |
| 963 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 964 | DEFUNSH (VTYSH_RMAP, |
| 965 | route_map, |
| 966 | route_map_cmd, |
| 967 | "route-map WORD (deny|permit) <1-65535>", |
| 968 | "Create route-map or enter route-map command mode\n" |
| 969 | "Route map tag\n" |
| 970 | "Route map denies set operations\n" |
| 971 | "Route map permits set operations\n" |
| 972 | "Sequence to insert to/delete from existing route-map entry\n") |
| 973 | { |
| 974 | vty->node = RMAP_NODE; |
| 975 | return CMD_SUCCESS; |
| 976 | } |
| 977 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 978 | DEFUNSH (VTYSH_ALL, |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 979 | vtysh_line_vty, |
| 980 | vtysh_line_vty_cmd, |
| 981 | "line vty", |
| 982 | "Configure a terminal line\n" |
| 983 | "Virtual terminal\n") |
| 984 | { |
| 985 | vty->node = VTY_NODE; |
| 986 | return CMD_SUCCESS; |
| 987 | } |
| 988 | |
| 989 | DEFUNSH (VTYSH_ALL, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 990 | vtysh_enable, |
| 991 | vtysh_enable_cmd, |
| 992 | "enable", |
| 993 | "Turn on privileged mode command\n") |
| 994 | { |
| 995 | vty->node = ENABLE_NODE; |
| 996 | return CMD_SUCCESS; |
| 997 | } |
| 998 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 999 | DEFUNSH (VTYSH_ALL, |
| 1000 | vtysh_disable, |
| 1001 | vtysh_disable_cmd, |
| 1002 | "disable", |
| 1003 | "Turn off privileged mode command\n") |
| 1004 | { |
| 1005 | if (vty->node == ENABLE_NODE) |
| 1006 | vty->node = VIEW_NODE; |
| 1007 | return CMD_SUCCESS; |
| 1008 | } |
| 1009 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1010 | DEFUNSH (VTYSH_ALL, |
| 1011 | vtysh_config_terminal, |
| 1012 | vtysh_config_terminal_cmd, |
| 1013 | "configure terminal", |
| 1014 | "Configuration from vty interface\n" |
| 1015 | "Configuration terminal\n") |
| 1016 | { |
| 1017 | vty->node = CONFIG_NODE; |
| 1018 | return CMD_SUCCESS; |
| 1019 | } |
| 1020 | |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 1021 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1022 | vtysh_exit (struct vty *vty) |
| 1023 | { |
| 1024 | switch (vty->node) |
| 1025 | { |
| 1026 | case VIEW_NODE: |
| 1027 | case ENABLE_NODE: |
| 1028 | exit (0); |
| 1029 | break; |
| 1030 | case CONFIG_NODE: |
| 1031 | vty->node = ENABLE_NODE; |
| 1032 | break; |
| 1033 | case INTERFACE_NODE: |
| 1034 | case ZEBRA_NODE: |
| 1035 | case BGP_NODE: |
| 1036 | case RIP_NODE: |
| 1037 | case RIPNG_NODE: |
| 1038 | case OSPF_NODE: |
| 1039 | case OSPF6_NODE: |
hasso | c25e458 | 2003-12-23 10:39:08 +0000 | [diff] [blame] | 1040 | case ISIS_NODE: |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1041 | case MASC_NODE: |
| 1042 | case RMAP_NODE: |
| 1043 | case VTY_NODE: |
| 1044 | case KEYCHAIN_NODE: |
hasso | 2a56df9 | 2004-05-09 23:16:40 +0000 | [diff] [blame] | 1045 | vtysh_execute("end"); |
| 1046 | vtysh_execute("configure terminal"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1047 | vty->node = CONFIG_NODE; |
| 1048 | break; |
| 1049 | case BGP_VPNV4_NODE: |
| 1050 | case BGP_IPV4_NODE: |
| 1051 | case BGP_IPV4M_NODE: |
| 1052 | case BGP_IPV6_NODE: |
| 1053 | vty->node = BGP_NODE; |
| 1054 | break; |
| 1055 | case KEYCHAIN_KEY_NODE: |
| 1056 | vty->node = KEYCHAIN_NODE; |
| 1057 | break; |
| 1058 | default: |
| 1059 | break; |
| 1060 | } |
| 1061 | return CMD_SUCCESS; |
| 1062 | } |
| 1063 | |
| 1064 | DEFUNSH (VTYSH_ALL, |
| 1065 | vtysh_exit_all, |
| 1066 | vtysh_exit_all_cmd, |
| 1067 | "exit", |
| 1068 | "Exit current mode and down to previous mode\n") |
| 1069 | { |
| 1070 | return vtysh_exit (vty); |
| 1071 | } |
| 1072 | |
| 1073 | ALIAS (vtysh_exit_all, |
| 1074 | vtysh_quit_all_cmd, |
| 1075 | "quit", |
| 1076 | "Exit current mode and down to previous mode\n") |
| 1077 | |
| 1078 | DEFUNSH (VTYSH_BGPD, |
| 1079 | exit_address_family, |
| 1080 | exit_address_family_cmd, |
| 1081 | "exit-address-family", |
| 1082 | "Exit from Address Family configuration mode\n") |
| 1083 | { |
| 1084 | if (vty->node == BGP_IPV4_NODE |
| 1085 | || vty->node == BGP_IPV4M_NODE |
| 1086 | || vty->node == BGP_VPNV4_NODE |
| 1087 | || vty->node == BGP_IPV6_NODE) |
| 1088 | vty->node = BGP_NODE; |
| 1089 | return CMD_SUCCESS; |
| 1090 | } |
| 1091 | |
| 1092 | DEFUNSH (VTYSH_ZEBRA, |
| 1093 | vtysh_exit_zebra, |
| 1094 | vtysh_exit_zebra_cmd, |
| 1095 | "exit", |
| 1096 | "Exit current mode and down to previous mode\n") |
| 1097 | { |
| 1098 | return vtysh_exit (vty); |
| 1099 | } |
| 1100 | |
| 1101 | ALIAS (vtysh_exit_zebra, |
| 1102 | vtysh_quit_zebra_cmd, |
| 1103 | "quit", |
| 1104 | "Exit current mode and down to previous mode\n") |
| 1105 | |
| 1106 | DEFUNSH (VTYSH_RIPD, |
| 1107 | vtysh_exit_ripd, |
| 1108 | vtysh_exit_ripd_cmd, |
| 1109 | "exit", |
| 1110 | "Exit current mode and down to previous mode\n") |
| 1111 | { |
| 1112 | return vtysh_exit (vty); |
| 1113 | } |
| 1114 | |
| 1115 | ALIAS (vtysh_exit_ripd, |
| 1116 | vtysh_quit_ripd_cmd, |
| 1117 | "quit", |
| 1118 | "Exit current mode and down to previous mode\n") |
| 1119 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1120 | DEFUNSH (VTYSH_RIPNGD, |
hasso | b094d26 | 2004-08-25 12:22:00 +0000 | [diff] [blame] | 1121 | vtysh_exit_ripngd, |
| 1122 | vtysh_exit_ripngd_cmd, |
| 1123 | "exit", |
| 1124 | "Exit current mode and down to previous mode\n") |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1125 | { |
| 1126 | return vtysh_exit (vty); |
| 1127 | } |
| 1128 | |
| 1129 | ALIAS (vtysh_exit_ripngd, |
| 1130 | vtysh_quit_ripngd_cmd, |
| 1131 | "quit", |
| 1132 | "Exit current mode and down to previous mode\n") |
| 1133 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1134 | DEFUNSH (VTYSH_RMAP, |
| 1135 | vtysh_exit_rmap, |
| 1136 | vtysh_exit_rmap_cmd, |
| 1137 | "exit", |
| 1138 | "Exit current mode and down to previous mode\n") |
| 1139 | { |
| 1140 | return vtysh_exit (vty); |
| 1141 | } |
| 1142 | |
| 1143 | ALIAS (vtysh_exit_rmap, |
| 1144 | vtysh_quit_rmap_cmd, |
| 1145 | "quit", |
| 1146 | "Exit current mode and down to previous mode\n") |
| 1147 | |
| 1148 | DEFUNSH (VTYSH_BGPD, |
| 1149 | vtysh_exit_bgpd, |
| 1150 | vtysh_exit_bgpd_cmd, |
| 1151 | "exit", |
| 1152 | "Exit current mode and down to previous mode\n") |
| 1153 | { |
| 1154 | return vtysh_exit (vty); |
| 1155 | } |
| 1156 | |
| 1157 | ALIAS (vtysh_exit_bgpd, |
| 1158 | vtysh_quit_bgpd_cmd, |
| 1159 | "quit", |
| 1160 | "Exit current mode and down to previous mode\n") |
| 1161 | |
| 1162 | DEFUNSH (VTYSH_OSPFD, |
| 1163 | vtysh_exit_ospfd, |
| 1164 | vtysh_exit_ospfd_cmd, |
| 1165 | "exit", |
| 1166 | "Exit current mode and down to previous mode\n") |
| 1167 | { |
| 1168 | return vtysh_exit (vty); |
| 1169 | } |
| 1170 | |
| 1171 | ALIAS (vtysh_exit_ospfd, |
| 1172 | vtysh_quit_ospfd_cmd, |
| 1173 | "quit", |
| 1174 | "Exit current mode and down to previous mode\n") |
| 1175 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1176 | DEFUNSH (VTYSH_OSPF6D, |
hasso | b094d26 | 2004-08-25 12:22:00 +0000 | [diff] [blame] | 1177 | vtysh_exit_ospf6d, |
| 1178 | vtysh_exit_ospf6d_cmd, |
| 1179 | "exit", |
| 1180 | "Exit current mode and down to previous mode\n") |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1181 | { |
| 1182 | return vtysh_exit (vty); |
| 1183 | } |
| 1184 | |
| 1185 | ALIAS (vtysh_exit_ospf6d, |
| 1186 | vtysh_quit_ospf6d_cmd, |
| 1187 | "quit", |
| 1188 | "Exit current mode and down to previous mode\n") |
| 1189 | |
hasso | c25e458 | 2003-12-23 10:39:08 +0000 | [diff] [blame] | 1190 | DEFUNSH (VTYSH_ISISD, |
hasso | b094d26 | 2004-08-25 12:22:00 +0000 | [diff] [blame] | 1191 | vtysh_exit_isisd, |
| 1192 | vtysh_exit_isisd_cmd, |
| 1193 | "exit", |
| 1194 | "Exit current mode and down to previous mode\n") |
hasso | c25e458 | 2003-12-23 10:39:08 +0000 | [diff] [blame] | 1195 | { |
| 1196 | return vtysh_exit (vty); |
| 1197 | } |
| 1198 | |
| 1199 | ALIAS (vtysh_exit_isisd, |
| 1200 | vtysh_quit_isisd_cmd, |
| 1201 | "quit", |
| 1202 | "Exit current mode and down to previous mode\n") |
| 1203 | |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 1204 | DEFUNSH (VTYSH_ALL, |
| 1205 | vtysh_exit_line_vty, |
| 1206 | vtysh_exit_line_vty_cmd, |
| 1207 | "exit", |
| 1208 | "Exit current mode and down to previous mode\n") |
| 1209 | { |
| 1210 | return vtysh_exit (vty); |
| 1211 | } |
| 1212 | |
| 1213 | ALIAS (vtysh_exit_line_vty, |
| 1214 | vtysh_quit_line_vty_cmd, |
| 1215 | "quit", |
| 1216 | "Exit current mode and down to previous mode\n") |
| 1217 | |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1218 | DEFUNSH (VTYSH_INTERFACE, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1219 | vtysh_interface, |
| 1220 | vtysh_interface_cmd, |
| 1221 | "interface IFNAME", |
| 1222 | "Select an interface to configure\n" |
| 1223 | "Interface's name\n") |
| 1224 | { |
| 1225 | vty->node = INTERFACE_NODE; |
| 1226 | return CMD_SUCCESS; |
| 1227 | } |
| 1228 | |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1229 | /* TODO Implement "no interface command in isisd. */ |
paul | 32d2463 | 2003-05-23 09:25:20 +0000 | [diff] [blame] | 1230 | DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D, |
| 1231 | vtysh_no_interface_cmd, |
| 1232 | "no interface IFNAME", |
| 1233 | NO_STR |
| 1234 | "Delete a pseudo interface's configuration\n" |
| 1235 | "Interface's name\n") |
| 1236 | |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1237 | /* TODO Implement interface description commands in ripngd, ospf6d |
| 1238 | * and isisd. */ |
paul | 338a991 | 2003-03-01 15:44:10 +0000 | [diff] [blame] | 1239 | DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD, |
| 1240 | interface_desc_cmd, |
| 1241 | "description .LINE", |
| 1242 | "Interface specific description\n" |
| 1243 | "Characters describing this interface\n") |
paul | 464dc8d | 2003-03-28 02:25:45 +0000 | [diff] [blame] | 1244 | |
| 1245 | DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD, |
| 1246 | no_interface_desc_cmd, |
| 1247 | "no description", |
| 1248 | NO_STR |
| 1249 | "Interface specific description\n") |
paul | 338a991 | 2003-03-01 15:44:10 +0000 | [diff] [blame] | 1250 | |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1251 | DEFUNSH (VTYSH_INTERFACE, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1252 | vtysh_exit_interface, |
| 1253 | vtysh_exit_interface_cmd, |
| 1254 | "exit", |
| 1255 | "Exit current mode and down to previous mode\n") |
| 1256 | { |
| 1257 | return vtysh_exit (vty); |
| 1258 | } |
| 1259 | |
| 1260 | ALIAS (vtysh_exit_interface, |
| 1261 | vtysh_quit_interface_cmd, |
| 1262 | "quit", |
| 1263 | "Exit current mode and down to previous mode\n") |
| 1264 | |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1265 | /* Logging commands. */ |
| 1266 | DEFUNSH (VTYSH_ALL, |
| 1267 | vtysh_log_stdout, |
| 1268 | vtysh_log_stdout_cmd, |
| 1269 | "log stdout", |
| 1270 | "Logging control\n" |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 1271 | "Set stdout logging level\n") |
| 1272 | { |
| 1273 | return CMD_SUCCESS; |
| 1274 | } |
| 1275 | |
| 1276 | DEFUNSH (VTYSH_ALL, |
| 1277 | vtysh_log_stdout_level, |
| 1278 | vtysh_log_stdout_level_cmd, |
| 1279 | "log stdout "LOG_LEVELS, |
| 1280 | "Logging control\n" |
| 1281 | "Set stdout logging level\n" |
| 1282 | LOG_LEVEL_DESC) |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1283 | { |
| 1284 | return CMD_SUCCESS; |
| 1285 | } |
| 1286 | |
| 1287 | DEFUNSH (VTYSH_ALL, |
| 1288 | no_vtysh_log_stdout, |
| 1289 | no_vtysh_log_stdout_cmd, |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 1290 | "no log stdout [LEVEL]", |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1291 | NO_STR |
| 1292 | "Logging control\n" |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 1293 | "Cancel logging to stdout\n" |
| 1294 | "Logging level\n") |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1295 | { |
| 1296 | return CMD_SUCCESS; |
| 1297 | } |
| 1298 | |
| 1299 | DEFUNSH (VTYSH_ALL, |
| 1300 | vtysh_log_file, |
| 1301 | vtysh_log_file_cmd, |
| 1302 | "log file FILENAME", |
| 1303 | "Logging control\n" |
| 1304 | "Logging to file\n" |
| 1305 | "Logging filename\n") |
| 1306 | { |
| 1307 | return CMD_SUCCESS; |
| 1308 | } |
| 1309 | |
| 1310 | DEFUNSH (VTYSH_ALL, |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 1311 | vtysh_log_file_level, |
| 1312 | vtysh_log_file_level_cmd, |
| 1313 | "log file FILENAME "LOG_LEVELS, |
| 1314 | "Logging control\n" |
| 1315 | "Logging to file\n" |
| 1316 | "Logging filename\n" |
| 1317 | LOG_LEVEL_DESC) |
| 1318 | { |
| 1319 | return CMD_SUCCESS; |
| 1320 | } |
| 1321 | |
| 1322 | DEFUNSH (VTYSH_ALL, |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1323 | no_vtysh_log_file, |
| 1324 | no_vtysh_log_file_cmd, |
| 1325 | "no log file [FILENAME]", |
| 1326 | NO_STR |
| 1327 | "Logging control\n" |
| 1328 | "Cancel logging to file\n" |
| 1329 | "Logging file name\n") |
| 1330 | { |
| 1331 | return CMD_SUCCESS; |
| 1332 | } |
| 1333 | |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 1334 | ALIAS_SH (VTYSH_ALL, |
| 1335 | no_vtysh_log_file, |
| 1336 | no_vtysh_log_file_level_cmd, |
| 1337 | "no log file FILENAME LEVEL", |
| 1338 | NO_STR |
| 1339 | "Logging control\n" |
| 1340 | "Cancel logging to file\n" |
| 1341 | "Logging file name\n" |
| 1342 | "Logging level\n") |
| 1343 | |
| 1344 | DEFUNSH (VTYSH_ALL, |
| 1345 | vtysh_log_monitor, |
| 1346 | vtysh_log_monitor_cmd, |
| 1347 | "log monitor", |
| 1348 | "Logging control\n" |
| 1349 | "Set terminal line (monitor) logging level\n") |
| 1350 | { |
| 1351 | return CMD_SUCCESS; |
| 1352 | } |
| 1353 | |
| 1354 | DEFUNSH (VTYSH_ALL, |
| 1355 | vtysh_log_monitor_level, |
| 1356 | vtysh_log_monitor_level_cmd, |
| 1357 | "log monitor "LOG_LEVELS, |
| 1358 | "Logging control\n" |
| 1359 | "Set terminal line (monitor) logging level\n" |
| 1360 | LOG_LEVEL_DESC) |
| 1361 | { |
| 1362 | return CMD_SUCCESS; |
| 1363 | } |
| 1364 | |
| 1365 | DEFUNSH (VTYSH_ALL, |
| 1366 | no_vtysh_log_monitor, |
| 1367 | no_vtysh_log_monitor_cmd, |
| 1368 | "no log monitor [LEVEL]", |
| 1369 | NO_STR |
| 1370 | "Logging control\n" |
| 1371 | "Disable terminal line (monitor) logging\n" |
| 1372 | "Logging level\n") |
| 1373 | { |
| 1374 | return CMD_SUCCESS; |
| 1375 | } |
| 1376 | |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1377 | DEFUNSH (VTYSH_ALL, |
| 1378 | vtysh_log_syslog, |
| 1379 | vtysh_log_syslog_cmd, |
| 1380 | "log syslog", |
| 1381 | "Logging control\n" |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 1382 | "Set syslog logging level\n") |
| 1383 | { |
| 1384 | return CMD_SUCCESS; |
| 1385 | } |
| 1386 | |
| 1387 | DEFUNSH (VTYSH_ALL, |
| 1388 | vtysh_log_syslog_level, |
| 1389 | vtysh_log_syslog_level_cmd, |
| 1390 | "log syslog "LOG_LEVELS, |
| 1391 | "Logging control\n" |
| 1392 | "Set syslog logging level\n" |
| 1393 | LOG_LEVEL_DESC) |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1394 | { |
| 1395 | return CMD_SUCCESS; |
| 1396 | } |
| 1397 | |
| 1398 | DEFUNSH (VTYSH_ALL, |
| 1399 | no_vtysh_log_syslog, |
| 1400 | no_vtysh_log_syslog_cmd, |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 1401 | "no log syslog [LEVEL]", |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1402 | NO_STR |
| 1403 | "Logging control\n" |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 1404 | "Cancel logging to syslog\n" |
| 1405 | "Logging level\n") |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1406 | { |
| 1407 | return CMD_SUCCESS; |
| 1408 | } |
| 1409 | |
| 1410 | DEFUNSH (VTYSH_ALL, |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 1411 | vtysh_log_facility, |
| 1412 | vtysh_log_facility_cmd, |
| 1413 | "log facility "LOG_FACILITIES, |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1414 | "Logging control\n" |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 1415 | "Facility parameter for syslog messages\n" |
| 1416 | LOG_FACILITY_DESC) |
| 1417 | |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1418 | { |
| 1419 | return CMD_SUCCESS; |
| 1420 | } |
| 1421 | |
| 1422 | DEFUNSH (VTYSH_ALL, |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 1423 | no_vtysh_log_facility, |
| 1424 | no_vtysh_log_facility_cmd, |
| 1425 | "no log facility [FACILITY]", |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1426 | NO_STR |
| 1427 | "Logging control\n" |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 1428 | "Reset syslog facility to default (daemon)\n" |
| 1429 | "Syslog facility\n") |
| 1430 | |
| 1431 | { |
| 1432 | return CMD_SUCCESS; |
| 1433 | } |
| 1434 | |
| 1435 | DEFUNSH_DEPRECATED (VTYSH_ALL, |
| 1436 | vtysh_log_trap, |
| 1437 | vtysh_log_trap_cmd, |
| 1438 | "log trap "LOG_LEVELS, |
| 1439 | "Logging control\n" |
| 1440 | "(Deprecated) Set logging level and default for all destinations\n" |
| 1441 | LOG_LEVEL_DESC) |
| 1442 | |
| 1443 | { |
| 1444 | return CMD_SUCCESS; |
| 1445 | } |
| 1446 | |
| 1447 | DEFUNSH_DEPRECATED (VTYSH_ALL, |
| 1448 | no_vtysh_log_trap, |
| 1449 | no_vtysh_log_trap_cmd, |
| 1450 | "no log trap [LEVEL]", |
| 1451 | NO_STR |
| 1452 | "Logging control\n" |
| 1453 | "Permit all logging information\n" |
| 1454 | "Logging level\n") |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1455 | { |
| 1456 | return CMD_SUCCESS; |
| 1457 | } |
| 1458 | |
| 1459 | DEFUNSH (VTYSH_ALL, |
| 1460 | vtysh_log_record_priority, |
| 1461 | vtysh_log_record_priority_cmd, |
| 1462 | "log record-priority", |
| 1463 | "Logging control\n" |
| 1464 | "Log the priority of the message within the message\n") |
| 1465 | { |
| 1466 | return CMD_SUCCESS; |
| 1467 | } |
| 1468 | |
| 1469 | DEFUNSH (VTYSH_ALL, |
| 1470 | no_vtysh_log_record_priority, |
| 1471 | no_vtysh_log_record_priority_cmd, |
| 1472 | "no log record-priority", |
| 1473 | NO_STR |
| 1474 | "Logging control\n" |
| 1475 | "Do not log the priority of the message within the message\n") |
| 1476 | { |
| 1477 | return CMD_SUCCESS; |
| 1478 | } |
| 1479 | |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 1480 | DEFUNSH (VTYSH_ALL, |
| 1481 | vtysh_service_password_encrypt, |
| 1482 | vtysh_service_password_encrypt_cmd, |
| 1483 | "service password-encryption", |
| 1484 | "Set up miscellaneous service\n" |
| 1485 | "Enable encrypted passwords\n") |
| 1486 | { |
| 1487 | return CMD_SUCCESS; |
| 1488 | } |
| 1489 | |
| 1490 | DEFUNSH (VTYSH_ALL, |
| 1491 | no_vtysh_service_password_encrypt, |
| 1492 | no_vtysh_service_password_encrypt_cmd, |
| 1493 | "no service password-encryption", |
| 1494 | NO_STR |
| 1495 | "Set up miscellaneous service\n" |
| 1496 | "Enable encrypted passwords\n") |
| 1497 | { |
| 1498 | return CMD_SUCCESS; |
| 1499 | } |
| 1500 | |
| 1501 | DEFUNSH (VTYSH_ALL, |
| 1502 | vtysh_config_password, |
| 1503 | vtysh_password_cmd, |
| 1504 | "password (8|) WORD", |
| 1505 | "Assign the terminal connection password\n" |
| 1506 | "Specifies a HIDDEN password will follow\n" |
| 1507 | "dummy string \n" |
| 1508 | "The HIDDEN line password string\n") |
| 1509 | { |
| 1510 | return CMD_SUCCESS; |
| 1511 | } |
| 1512 | |
| 1513 | DEFUNSH (VTYSH_ALL, |
| 1514 | vtysh_password_text, |
| 1515 | vtysh_password_text_cmd, |
| 1516 | "password LINE", |
| 1517 | "Assign the terminal connection password\n" |
| 1518 | "The UNENCRYPTED (cleartext) line password\n") |
| 1519 | { |
| 1520 | return CMD_SUCCESS; |
| 1521 | } |
| 1522 | |
| 1523 | DEFUNSH (VTYSH_ALL, |
| 1524 | vtysh_config_enable_password, |
| 1525 | vtysh_enable_password_cmd, |
| 1526 | "enable password (8|) WORD", |
| 1527 | "Modify enable password parameters\n" |
| 1528 | "Assign the privileged level password\n" |
| 1529 | "Specifies a HIDDEN password will follow\n" |
| 1530 | "dummy string \n" |
| 1531 | "The HIDDEN 'enable' password string\n") |
| 1532 | { |
| 1533 | return CMD_SUCCESS; |
| 1534 | } |
| 1535 | |
| 1536 | DEFUNSH (VTYSH_ALL, |
| 1537 | vtysh_enable_password_text, |
| 1538 | vtysh_enable_password_text_cmd, |
| 1539 | "enable password LINE", |
| 1540 | "Modify enable password parameters\n" |
| 1541 | "Assign the privileged level password\n" |
| 1542 | "The UNENCRYPTED (cleartext) 'enable' password\n") |
| 1543 | { |
| 1544 | return CMD_SUCCESS; |
| 1545 | } |
| 1546 | |
| 1547 | DEFUNSH (VTYSH_ALL, |
| 1548 | no_vtysh_config_enable_password, |
| 1549 | no_vtysh_enable_password_cmd, |
| 1550 | "no enable password", |
| 1551 | NO_STR |
| 1552 | "Modify enable password parameters\n" |
| 1553 | "Assign the privileged level password\n") |
| 1554 | { |
| 1555 | return CMD_SUCCESS; |
| 1556 | } |
| 1557 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1558 | DEFUN (vtysh_write_terminal, |
| 1559 | vtysh_write_terminal_cmd, |
| 1560 | "write terminal", |
| 1561 | "Write running configuration to memory, network, or terminal\n" |
| 1562 | "Write to terminal\n") |
| 1563 | { |
| 1564 | int ret; |
| 1565 | char line[] = "write terminal\n"; |
| 1566 | FILE *fp = NULL; |
| 1567 | |
| 1568 | if (vtysh_pager_name) |
| 1569 | { |
paul | 4fc01e6 | 2002-12-13 20:49:00 +0000 | [diff] [blame] | 1570 | fp = popen (vtysh_pager_name, "w"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1571 | if (fp == NULL) |
| 1572 | { |
| 1573 | perror ("popen"); |
| 1574 | exit (1); |
| 1575 | } |
| 1576 | } |
| 1577 | else |
| 1578 | fp = stdout; |
| 1579 | |
| 1580 | vty_out (vty, "Building configuration...%s", VTY_NEWLINE); |
| 1581 | vty_out (vty, "%sCurrent configuration:%s", VTY_NEWLINE, |
| 1582 | VTY_NEWLINE); |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 1583 | vty_out (vty, "!%s", VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1584 | |
| 1585 | ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_ZEBRA], line); |
| 1586 | ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_RIP], line); |
| 1587 | ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_RIPNG], line); |
| 1588 | ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_OSPF], line); |
| 1589 | ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_OSPF6], line); |
| 1590 | ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_BGP], line); |
hasso | c25e458 | 2003-12-23 10:39:08 +0000 | [diff] [blame] | 1591 | ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_ISIS], line); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1592 | |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 1593 | /* Integrate vtysh specific configuration. */ |
| 1594 | vtysh_config_write (); |
| 1595 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1596 | vtysh_config_dump (fp); |
| 1597 | |
| 1598 | if (vtysh_pager_name && fp) |
| 1599 | { |
| 1600 | fflush (fp); |
| 1601 | if (pclose (fp) == -1) |
| 1602 | { |
| 1603 | perror ("pclose"); |
| 1604 | exit (1); |
| 1605 | } |
| 1606 | fp = NULL; |
| 1607 | } |
| 1608 | |
| 1609 | return CMD_SUCCESS; |
| 1610 | } |
| 1611 | |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 1612 | DEFUN (vtysh_integrated_config, |
| 1613 | vtysh_integrated_config_cmd, |
| 1614 | "service integrated-vtysh-config", |
| 1615 | "Set up miscellaneous service\n" |
| 1616 | "Write configuration into integrated file\n") |
paul | 4fc01e6 | 2002-12-13 20:49:00 +0000 | [diff] [blame] | 1617 | { |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 1618 | vtysh_writeconfig_integrated = 1; |
| 1619 | return CMD_SUCCESS; |
paul | 4fc01e6 | 2002-12-13 20:49:00 +0000 | [diff] [blame] | 1620 | } |
| 1621 | |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 1622 | DEFUN (no_vtysh_integrated_config, |
| 1623 | no_vtysh_integrated_config_cmd, |
| 1624 | "no service integrated-vtysh-config", |
| 1625 | NO_STR |
| 1626 | "Set up miscellaneous service\n" |
| 1627 | "Write configuration into integrated file\n") |
paul | 4fc01e6 | 2002-12-13 20:49:00 +0000 | [diff] [blame] | 1628 | { |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 1629 | vtysh_writeconfig_integrated = 0; |
| 1630 | return CMD_SUCCESS; |
paul | 4fc01e6 | 2002-12-13 20:49:00 +0000 | [diff] [blame] | 1631 | } |
| 1632 | |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 1633 | static int |
| 1634 | write_config_integrated(void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1635 | { |
| 1636 | int ret; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1637 | char line[] = "write terminal\n"; |
| 1638 | FILE *fp; |
| 1639 | char *integrate_sav = NULL; |
| 1640 | |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1641 | integrate_sav = malloc (strlen (integrate_default) + |
| 1642 | strlen (CONF_BACKUP_EXT) + 1); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1643 | strcpy (integrate_sav, integrate_default); |
| 1644 | strcat (integrate_sav, CONF_BACKUP_EXT); |
| 1645 | |
paul | 4fc01e6 | 2002-12-13 20:49:00 +0000 | [diff] [blame] | 1646 | fprintf (stdout,"Building Configuration...\n"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1647 | |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1648 | /* Move current configuration file to backup config file. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1649 | unlink (integrate_sav); |
| 1650 | rename (integrate_default, integrate_sav); |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1651 | free (integrate_sav); |
paul | 4fc01e6 | 2002-12-13 20:49:00 +0000 | [diff] [blame] | 1652 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1653 | fp = fopen (integrate_default, "w"); |
| 1654 | if (fp == NULL) |
| 1655 | { |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 1656 | fprintf (stdout,"%% Can't open configuration file %s.\n", |
| 1657 | integrate_default); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1658 | return CMD_SUCCESS; |
| 1659 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1660 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1661 | ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_ZEBRA], line); |
| 1662 | ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_RIP], line); |
| 1663 | ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_RIPNG], line); |
| 1664 | ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_OSPF], line); |
| 1665 | ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_OSPF6], line); |
| 1666 | ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_BGP], line); |
hasso | c25e458 | 2003-12-23 10:39:08 +0000 | [diff] [blame] | 1667 | ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_ISIS], line); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1668 | |
| 1669 | vtysh_config_dump (fp); |
| 1670 | |
| 1671 | fclose (fp); |
| 1672 | |
gdt | aa593d5 | 2003-12-22 20:15:53 +0000 | [diff] [blame] | 1673 | if (chmod (integrate_default, CONFIGFILE_MASK) != 0) |
| 1674 | { |
| 1675 | fprintf (stdout,"%% Can't chmod configuration file %s: %s (%d)\n", |
ajs | 6099b3b | 2004-11-20 02:06:59 +0000 | [diff] [blame] | 1676 | integrate_default, safe_strerror(errno), errno); |
gdt | aa593d5 | 2003-12-22 20:15:53 +0000 | [diff] [blame] | 1677 | return CMD_WARNING; |
| 1678 | } |
| 1679 | |
paul | 4fc01e6 | 2002-12-13 20:49:00 +0000 | [diff] [blame] | 1680 | fprintf(stdout,"Integrated configuration saved to %s\n",integrate_default); |
| 1681 | |
| 1682 | fprintf (stdout,"[OK]\n"); |
| 1683 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1684 | return CMD_SUCCESS; |
| 1685 | } |
| 1686 | |
paul | 4fc01e6 | 2002-12-13 20:49:00 +0000 | [diff] [blame] | 1687 | DEFUN (vtysh_write_memory, |
| 1688 | vtysh_write_memory_cmd, |
| 1689 | "write memory", |
| 1690 | "Write running configuration to memory, network, or terminal\n" |
| 1691 | "Write configuration to the file (same as write file)\n") |
| 1692 | { |
paul | dfc0d9b | 2003-04-18 23:55:29 +0000 | [diff] [blame] | 1693 | int ret = CMD_SUCCESS; |
paul | 4fc01e6 | 2002-12-13 20:49:00 +0000 | [diff] [blame] | 1694 | char line[] = "write memory\n"; |
| 1695 | |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 1696 | /* If integrated Quagga.conf explicitely set. */ |
| 1697 | if (vtysh_writeconfig_integrated) |
| 1698 | return write_config_integrated(); |
paul | 4fc01e6 | 2002-12-13 20:49:00 +0000 | [diff] [blame] | 1699 | |
| 1700 | fprintf (stdout,"Building Configuration...\n"); |
| 1701 | |
| 1702 | ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ZEBRA], line, stdout); |
| 1703 | ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIP], line, stdout); |
| 1704 | ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIPNG], line, stdout); |
| 1705 | ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF], line, stdout); |
| 1706 | ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF6], line, stdout); |
| 1707 | ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_BGP], line, stdout); |
hasso | c25e458 | 2003-12-23 10:39:08 +0000 | [diff] [blame] | 1708 | ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ISIS], line, stdout); |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 1709 | |
paul | 4fc01e6 | 2002-12-13 20:49:00 +0000 | [diff] [blame] | 1710 | fprintf (stdout,"[OK]\n"); |
| 1711 | |
paul | dfc0d9b | 2003-04-18 23:55:29 +0000 | [diff] [blame] | 1712 | return ret; |
paul | 4fc01e6 | 2002-12-13 20:49:00 +0000 | [diff] [blame] | 1713 | } |
| 1714 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1715 | ALIAS (vtysh_write_memory, |
| 1716 | vtysh_copy_runningconfig_startupconfig_cmd, |
| 1717 | "copy running-config startup-config", |
| 1718 | "Copy from one file to another\n" |
| 1719 | "Copy from current system configuration\n" |
| 1720 | "Copy to startup configuration\n") |
| 1721 | |
| 1722 | ALIAS (vtysh_write_memory, |
| 1723 | vtysh_write_file_cmd, |
| 1724 | "write file", |
| 1725 | "Write running configuration to memory, network, or terminal\n" |
| 1726 | "Write configuration to the file (same as write memory)\n") |
| 1727 | |
hasso | 4a6e225 | 2003-05-25 11:51:29 +0000 | [diff] [blame] | 1728 | ALIAS (vtysh_write_memory, |
| 1729 | vtysh_write_cmd, |
| 1730 | "write", |
| 1731 | "Write running configuration to memory, network, or terminal\n") |
| 1732 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1733 | ALIAS (vtysh_write_terminal, |
| 1734 | vtysh_show_running_config_cmd, |
| 1735 | "show running-config", |
| 1736 | SHOW_STR |
| 1737 | "Current operating configuration\n") |
hasso | b094d26 | 2004-08-25 12:22:00 +0000 | [diff] [blame] | 1738 | |
hasso | 34553cc | 2004-08-27 13:56:39 +0000 | [diff] [blame] | 1739 | DEFUN (vtysh_terminal_length, |
| 1740 | vtysh_terminal_length_cmd, |
| 1741 | "terminal length <0-512>", |
| 1742 | "Set terminal line parameters\n" |
| 1743 | "Set number of lines on a screen\n" |
| 1744 | "Number of lines on screen (0 for no pausing)\n") |
| 1745 | { |
| 1746 | int lines; |
| 1747 | char *endptr = NULL; |
| 1748 | char default_pager[10]; |
| 1749 | |
| 1750 | lines = strtol (argv[0], &endptr, 10); |
| 1751 | if (lines < 0 || lines > 512 || *endptr != '\0') |
| 1752 | { |
| 1753 | vty_out (vty, "length is malformed%s", VTY_NEWLINE); |
| 1754 | return CMD_WARNING; |
| 1755 | } |
| 1756 | |
| 1757 | if (vtysh_pager_name) |
| 1758 | { |
| 1759 | free (vtysh_pager_name); |
| 1760 | vtysh_pager_name = NULL; |
| 1761 | } |
| 1762 | |
| 1763 | if (lines != 0) |
| 1764 | { |
| 1765 | snprintf(default_pager, 10, "more -%i", lines); |
| 1766 | vtysh_pager_name = strdup (default_pager); |
| 1767 | } |
| 1768 | |
| 1769 | return CMD_SUCCESS; |
| 1770 | } |
| 1771 | |
| 1772 | DEFUN (vtysh_terminal_no_length, |
| 1773 | vtysh_terminal_no_length_cmd, |
| 1774 | "terminal no length", |
| 1775 | "Set terminal line parameters\n" |
| 1776 | NO_STR |
| 1777 | "Set number of lines on a screen\n") |
| 1778 | { |
| 1779 | if (vtysh_pager_name) |
| 1780 | { |
| 1781 | free (vtysh_pager_name); |
| 1782 | vtysh_pager_name = NULL; |
| 1783 | } |
| 1784 | |
| 1785 | vtysh_pager_init(); |
| 1786 | return CMD_SUCCESS; |
| 1787 | } |
| 1788 | |
hasso | f2799e6 | 2004-10-28 17:43:11 +0000 | [diff] [blame] | 1789 | DEFUN (vtysh_show_daemons, |
| 1790 | vtysh_show_daemons_cmd, |
| 1791 | "show daemons", |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 1792 | SHOW_STR |
| 1793 | "Show list of running daemons\n") |
| 1794 | { |
| 1795 | if ( vtysh_client[VTYSH_INDEX_ZEBRA].fd > 0 ) |
| 1796 | vty_out(vty, " zebra"); |
| 1797 | if ( vtysh_client[VTYSH_INDEX_RIP].fd > 0 ) |
| 1798 | vty_out(vty, " ripd"); |
| 1799 | if ( vtysh_client[VTYSH_INDEX_RIPNG].fd > 0 ) |
| 1800 | vty_out(vty, " ripngd"); |
| 1801 | if ( vtysh_client[VTYSH_INDEX_OSPF].fd > 0 ) |
| 1802 | vty_out(vty, " ospfd"); |
| 1803 | if ( vtysh_client[VTYSH_INDEX_OSPF6].fd > 0 ) |
| 1804 | vty_out(vty, " ospf6d"); |
| 1805 | if ( vtysh_client[VTYSH_INDEX_BGP].fd > 0 ) |
| 1806 | vty_out(vty, " bgpd"); |
| 1807 | if ( vtysh_client[VTYSH_INDEX_ISIS].fd > 0 ) |
| 1808 | vty_out(vty, " isisd"); |
| 1809 | vty_out(vty, "%s", VTY_NEWLINE); |
| 1810 | |
| 1811 | return CMD_SUCCESS; |
| 1812 | } |
| 1813 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1814 | /* Execute command in child process. */ |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 1815 | static int |
hasso | 5862ff5 | 2004-10-11 13:20:40 +0000 | [diff] [blame] | 1816 | execute_command (const char *command, int argc, const char *arg1, |
| 1817 | const char *arg2) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1818 | { |
| 1819 | int ret; |
| 1820 | pid_t pid; |
| 1821 | int status; |
| 1822 | |
| 1823 | /* Call fork(). */ |
| 1824 | pid = fork (); |
| 1825 | |
| 1826 | if (pid < 0) |
| 1827 | { |
| 1828 | /* Failure of fork(). */ |
ajs | 6099b3b | 2004-11-20 02:06:59 +0000 | [diff] [blame] | 1829 | fprintf (stderr, "Can't fork: %s\n", safe_strerror (errno)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1830 | exit (1); |
| 1831 | } |
| 1832 | else if (pid == 0) |
| 1833 | { |
| 1834 | /* This is child process. */ |
| 1835 | switch (argc) |
| 1836 | { |
| 1837 | case 0: |
hasso | fa2b17e | 2004-03-04 17:45:00 +0000 | [diff] [blame] | 1838 | ret = execlp (command, command, (const char *)NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1839 | break; |
| 1840 | case 1: |
hasso | fa2b17e | 2004-03-04 17:45:00 +0000 | [diff] [blame] | 1841 | ret = execlp (command, command, arg1, (const char *)NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1842 | break; |
| 1843 | case 2: |
hasso | fa2b17e | 2004-03-04 17:45:00 +0000 | [diff] [blame] | 1844 | ret = execlp (command, command, arg1, arg2, (const char *)NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1845 | break; |
| 1846 | } |
| 1847 | |
| 1848 | /* When execlp suceed, this part is not executed. */ |
ajs | 6099b3b | 2004-11-20 02:06:59 +0000 | [diff] [blame] | 1849 | fprintf (stderr, "Can't execute %s: %s\n", command, safe_strerror (errno)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1850 | exit (1); |
| 1851 | } |
| 1852 | else |
| 1853 | { |
| 1854 | /* This is parent. */ |
| 1855 | execute_flag = 1; |
| 1856 | ret = wait4 (pid, &status, 0, NULL); |
| 1857 | execute_flag = 0; |
| 1858 | } |
| 1859 | return 0; |
| 1860 | } |
| 1861 | |
| 1862 | DEFUN (vtysh_ping, |
| 1863 | vtysh_ping_cmd, |
| 1864 | "ping WORD", |
hasso | 4eeccf1 | 2003-06-25 10:49:55 +0000 | [diff] [blame] | 1865 | "Send echo messages\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1866 | "Ping destination address or hostname\n") |
| 1867 | { |
| 1868 | execute_command ("ping", 1, argv[0], NULL); |
| 1869 | return CMD_SUCCESS; |
| 1870 | } |
| 1871 | |
hasso | 4eeccf1 | 2003-06-25 10:49:55 +0000 | [diff] [blame] | 1872 | ALIAS (vtysh_ping, |
| 1873 | vtysh_ping_ip_cmd, |
| 1874 | "ping ip WORD", |
| 1875 | "Send echo messages\n" |
| 1876 | "IP echo\n" |
| 1877 | "Ping destination address or hostname\n") |
| 1878 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1879 | DEFUN (vtysh_traceroute, |
| 1880 | vtysh_traceroute_cmd, |
| 1881 | "traceroute WORD", |
| 1882 | "Trace route to destination\n" |
| 1883 | "Trace route to destination address or hostname\n") |
| 1884 | { |
| 1885 | execute_command ("traceroute", 1, argv[0], NULL); |
| 1886 | return CMD_SUCCESS; |
| 1887 | } |
| 1888 | |
hasso | 4eeccf1 | 2003-06-25 10:49:55 +0000 | [diff] [blame] | 1889 | ALIAS (vtysh_traceroute, |
| 1890 | vtysh_traceroute_ip_cmd, |
| 1891 | "traceroute ip WORD", |
| 1892 | "Trace route to destination\n" |
| 1893 | "IP trace\n" |
| 1894 | "Trace route to destination address or hostname\n") |
| 1895 | |
| 1896 | #ifdef HAVE_IPV6 |
| 1897 | DEFUN (vtysh_ping6, |
| 1898 | vtysh_ping6_cmd, |
| 1899 | "ping ipv6 WORD", |
| 1900 | "Send echo messages\n" |
| 1901 | "IPv6 echo\n" |
| 1902 | "Ping destination address or hostname\n") |
| 1903 | { |
| 1904 | execute_command ("ping6", 1, argv[0], NULL); |
| 1905 | return CMD_SUCCESS; |
| 1906 | } |
| 1907 | |
| 1908 | DEFUN (vtysh_traceroute6, |
| 1909 | vtysh_traceroute6_cmd, |
| 1910 | "traceroute ipv6 WORD", |
| 1911 | "Trace route to destination\n" |
| 1912 | "IPv6 trace\n" |
| 1913 | "Trace route to destination address or hostname\n") |
| 1914 | { |
| 1915 | execute_command ("traceroute6", 1, argv[0], NULL); |
| 1916 | return CMD_SUCCESS; |
| 1917 | } |
| 1918 | #endif |
| 1919 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1920 | DEFUN (vtysh_telnet, |
| 1921 | vtysh_telnet_cmd, |
| 1922 | "telnet WORD", |
| 1923 | "Open a telnet connection\n" |
| 1924 | "IP address or hostname of a remote system\n") |
| 1925 | { |
| 1926 | execute_command ("telnet", 1, argv[0], NULL); |
| 1927 | return CMD_SUCCESS; |
| 1928 | } |
| 1929 | |
| 1930 | DEFUN (vtysh_telnet_port, |
| 1931 | vtysh_telnet_port_cmd, |
| 1932 | "telnet WORD PORT", |
| 1933 | "Open a telnet connection\n" |
| 1934 | "IP address or hostname of a remote system\n" |
| 1935 | "TCP Port number\n") |
| 1936 | { |
| 1937 | execute_command ("telnet", 2, argv[0], argv[1]); |
| 1938 | return CMD_SUCCESS; |
| 1939 | } |
| 1940 | |
paul | 5087df5 | 2003-01-25 06:56:09 +0000 | [diff] [blame] | 1941 | DEFUN (vtysh_ssh, |
| 1942 | vtysh_ssh_cmd, |
| 1943 | "ssh WORD", |
| 1944 | "Open an ssh connection\n" |
| 1945 | "[user@]host\n") |
| 1946 | { |
| 1947 | execute_command ("ssh", 1, argv[0], NULL); |
| 1948 | return CMD_SUCCESS; |
| 1949 | } |
| 1950 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1951 | DEFUN (vtysh_start_shell, |
| 1952 | vtysh_start_shell_cmd, |
| 1953 | "start-shell", |
| 1954 | "Start UNIX shell\n") |
| 1955 | { |
| 1956 | execute_command ("sh", 0, NULL, NULL); |
| 1957 | return CMD_SUCCESS; |
| 1958 | } |
| 1959 | |
| 1960 | DEFUN (vtysh_start_bash, |
| 1961 | vtysh_start_bash_cmd, |
| 1962 | "start-shell bash", |
| 1963 | "Start UNIX shell\n" |
| 1964 | "Start bash\n") |
| 1965 | { |
| 1966 | execute_command ("bash", 0, NULL, NULL); |
| 1967 | return CMD_SUCCESS; |
| 1968 | } |
| 1969 | |
| 1970 | DEFUN (vtysh_start_zsh, |
| 1971 | vtysh_start_zsh_cmd, |
| 1972 | "start-shell zsh", |
| 1973 | "Start UNIX shell\n" |
| 1974 | "Start Z shell\n") |
| 1975 | { |
| 1976 | execute_command ("zsh", 0, NULL, NULL); |
| 1977 | return CMD_SUCCESS; |
| 1978 | } |
hasso | b094d26 | 2004-08-25 12:22:00 +0000 | [diff] [blame] | 1979 | |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 1980 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1981 | vtysh_install_default (enum node_type node) |
| 1982 | { |
| 1983 | install_element (node, &config_list_cmd); |
| 1984 | } |
| 1985 | |
| 1986 | /* Making connection to protocol daemon. */ |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 1987 | static int |
hasso | dda0952 | 2004-10-07 21:40:25 +0000 | [diff] [blame] | 1988 | vtysh_connect (struct vtysh_client *vclient, const char *path) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1989 | { |
| 1990 | int ret; |
| 1991 | int sock, len; |
| 1992 | struct sockaddr_un addr; |
| 1993 | struct stat s_stat; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1994 | |
| 1995 | memset (vclient, 0, sizeof (struct vtysh_client)); |
| 1996 | vclient->fd = -1; |
| 1997 | |
| 1998 | /* Stat socket to see if we have permission to access it. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1999 | ret = stat (path, &s_stat); |
| 2000 | if (ret < 0 && errno != ENOENT) |
| 2001 | { |
| 2002 | fprintf (stderr, "vtysh_connect(%s): stat = %s\n", |
ajs | 6099b3b | 2004-11-20 02:06:59 +0000 | [diff] [blame] | 2003 | path, safe_strerror(errno)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2004 | exit(1); |
| 2005 | } |
| 2006 | |
| 2007 | if (ret >= 0) |
| 2008 | { |
| 2009 | if (! S_ISSOCK(s_stat.st_mode)) |
| 2010 | { |
| 2011 | fprintf (stderr, "vtysh_connect(%s): Not a socket\n", |
| 2012 | path); |
| 2013 | exit (1); |
| 2014 | } |
| 2015 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2016 | } |
| 2017 | |
| 2018 | sock = socket (AF_UNIX, SOCK_STREAM, 0); |
| 2019 | if (sock < 0) |
| 2020 | { |
| 2021 | #ifdef DEBUG |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 2022 | fprintf(stderr, "vtysh_connect(%s): socket = %s\n", path, |
ajs | 6099b3b | 2004-11-20 02:06:59 +0000 | [diff] [blame] | 2023 | safe_strerror(errno)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2024 | #endif /* DEBUG */ |
| 2025 | return -1; |
| 2026 | } |
| 2027 | |
| 2028 | memset (&addr, 0, sizeof (struct sockaddr_un)); |
| 2029 | addr.sun_family = AF_UNIX; |
| 2030 | strncpy (addr.sun_path, path, strlen (path)); |
| 2031 | #ifdef HAVE_SUN_LEN |
| 2032 | len = addr.sun_len = SUN_LEN(&addr); |
| 2033 | #else |
| 2034 | len = sizeof (addr.sun_family) + strlen (addr.sun_path); |
| 2035 | #endif /* HAVE_SUN_LEN */ |
| 2036 | |
| 2037 | ret = connect (sock, (struct sockaddr *) &addr, len); |
| 2038 | if (ret < 0) |
| 2039 | { |
| 2040 | #ifdef DEBUG |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 2041 | fprintf(stderr, "vtysh_connect(%s): connect = %s\n", path, |
ajs | 6099b3b | 2004-11-20 02:06:59 +0000 | [diff] [blame] | 2042 | safe_strerror(errno)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2043 | #endif /* DEBUG */ |
| 2044 | close (sock); |
| 2045 | return -1; |
| 2046 | } |
| 2047 | vclient->fd = sock; |
| 2048 | |
| 2049 | return 0; |
| 2050 | } |
| 2051 | |
| 2052 | void |
| 2053 | vtysh_connect_all() |
| 2054 | { |
| 2055 | /* Clear each daemons client structure. */ |
paul | fe06778 | 2003-04-07 16:10:05 +0000 | [diff] [blame] | 2056 | vtysh_connect (&vtysh_client[VTYSH_INDEX_ZEBRA], ZEBRA_VTYSH_PATH); |
| 2057 | vtysh_connect (&vtysh_client[VTYSH_INDEX_RIP], RIP_VTYSH_PATH); |
| 2058 | vtysh_connect (&vtysh_client[VTYSH_INDEX_RIPNG], RIPNG_VTYSH_PATH); |
| 2059 | vtysh_connect (&vtysh_client[VTYSH_INDEX_OSPF], OSPF_VTYSH_PATH); |
| 2060 | vtysh_connect (&vtysh_client[VTYSH_INDEX_OSPF6], OSPF6_VTYSH_PATH); |
| 2061 | vtysh_connect (&vtysh_client[VTYSH_INDEX_BGP], BGP_VTYSH_PATH); |
hasso | c25e458 | 2003-12-23 10:39:08 +0000 | [diff] [blame] | 2062 | vtysh_connect (&vtysh_client[VTYSH_INDEX_ISIS], ISIS_VTYSH_PATH); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2063 | } |
| 2064 | |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 2065 | /* To disable readline's filename completion. */ |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 2066 | static char * |
paul | dfc0d9b | 2003-04-18 23:55:29 +0000 | [diff] [blame] | 2067 | vtysh_completion_entry_function (const char *ignore, int invoking_key) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2068 | { |
paul | dfc0d9b | 2003-04-18 23:55:29 +0000 | [diff] [blame] | 2069 | return NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2070 | } |
| 2071 | |
| 2072 | void |
| 2073 | vtysh_readline_init () |
| 2074 | { |
| 2075 | /* readline related settings. */ |
| 2076 | rl_bind_key ('?', vtysh_rl_describe); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2077 | rl_completion_entry_function = vtysh_completion_entry_function; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2078 | rl_attempted_completion_function = (CPPFunction *)new_completion; |
| 2079 | /* do not append space after completion. It will be appended |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 2080 | * in new_completion() function explicitly. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2081 | rl_completion_append_character = '\0'; |
| 2082 | } |
| 2083 | |
| 2084 | char * |
| 2085 | vtysh_prompt () |
| 2086 | { |
| 2087 | struct utsname names; |
| 2088 | static char buf[100]; |
| 2089 | const char*hostname; |
| 2090 | extern struct host host; |
| 2091 | |
| 2092 | hostname = host.name; |
| 2093 | |
| 2094 | if (!hostname) |
| 2095 | { |
| 2096 | uname (&names); |
| 2097 | hostname = names.nodename; |
| 2098 | } |
| 2099 | |
| 2100 | snprintf (buf, sizeof buf, cmd_prompt (vty->node), hostname); |
| 2101 | |
| 2102 | return buf; |
| 2103 | } |
| 2104 | |
| 2105 | void |
| 2106 | vtysh_init_vty () |
| 2107 | { |
| 2108 | /* Make vty structure. */ |
| 2109 | vty = vty_new (); |
| 2110 | vty->type = VTY_SHELL; |
| 2111 | vty->node = VIEW_NODE; |
| 2112 | |
| 2113 | /* Initialize commands. */ |
| 2114 | cmd_init (0); |
| 2115 | |
| 2116 | /* Install nodes. */ |
| 2117 | install_node (&bgp_node, NULL); |
| 2118 | install_node (&rip_node, NULL); |
| 2119 | install_node (&interface_node, NULL); |
| 2120 | install_node (&rmap_node, NULL); |
| 2121 | install_node (&zebra_node, NULL); |
| 2122 | install_node (&bgp_vpnv4_node, NULL); |
| 2123 | install_node (&bgp_ipv4_node, NULL); |
| 2124 | install_node (&bgp_ipv4m_node, NULL); |
| 2125 | /* #ifdef HAVE_IPV6 */ |
| 2126 | install_node (&bgp_ipv6_node, NULL); |
| 2127 | /* #endif */ |
| 2128 | install_node (&ospf_node, NULL); |
| 2129 | /* #ifdef HAVE_IPV6 */ |
| 2130 | install_node (&ripng_node, NULL); |
| 2131 | install_node (&ospf6_node, NULL); |
| 2132 | /* #endif */ |
| 2133 | install_node (&keychain_node, NULL); |
| 2134 | install_node (&keychain_key_node, NULL); |
hasso | c25e458 | 2003-12-23 10:39:08 +0000 | [diff] [blame] | 2135 | install_node (&isis_node, NULL); |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 2136 | install_node (&vty_node, NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2137 | |
| 2138 | vtysh_install_default (VIEW_NODE); |
| 2139 | vtysh_install_default (ENABLE_NODE); |
| 2140 | vtysh_install_default (CONFIG_NODE); |
| 2141 | vtysh_install_default (BGP_NODE); |
| 2142 | vtysh_install_default (RIP_NODE); |
| 2143 | vtysh_install_default (INTERFACE_NODE); |
| 2144 | vtysh_install_default (RMAP_NODE); |
| 2145 | vtysh_install_default (ZEBRA_NODE); |
| 2146 | vtysh_install_default (BGP_VPNV4_NODE); |
| 2147 | vtysh_install_default (BGP_IPV4_NODE); |
| 2148 | vtysh_install_default (BGP_IPV4M_NODE); |
| 2149 | vtysh_install_default (BGP_IPV6_NODE); |
| 2150 | vtysh_install_default (OSPF_NODE); |
| 2151 | vtysh_install_default (RIPNG_NODE); |
| 2152 | vtysh_install_default (OSPF6_NODE); |
hasso | c25e458 | 2003-12-23 10:39:08 +0000 | [diff] [blame] | 2153 | vtysh_install_default (ISIS_NODE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2154 | vtysh_install_default (KEYCHAIN_NODE); |
| 2155 | vtysh_install_default (KEYCHAIN_KEY_NODE); |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 2156 | vtysh_install_default (VTY_NODE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2157 | |
| 2158 | install_element (VIEW_NODE, &vtysh_enable_cmd); |
| 2159 | install_element (ENABLE_NODE, &vtysh_config_terminal_cmd); |
| 2160 | install_element (ENABLE_NODE, &vtysh_disable_cmd); |
| 2161 | |
| 2162 | /* "exit" command. */ |
| 2163 | install_element (VIEW_NODE, &vtysh_exit_all_cmd); |
| 2164 | install_element (VIEW_NODE, &vtysh_quit_all_cmd); |
| 2165 | install_element (CONFIG_NODE, &vtysh_exit_all_cmd); |
| 2166 | /* install_element (CONFIG_NODE, &vtysh_quit_all_cmd); */ |
| 2167 | install_element (ENABLE_NODE, &vtysh_exit_all_cmd); |
| 2168 | install_element (ENABLE_NODE, &vtysh_quit_all_cmd); |
| 2169 | install_element (RIP_NODE, &vtysh_exit_ripd_cmd); |
| 2170 | install_element (RIP_NODE, &vtysh_quit_ripd_cmd); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2171 | install_element (RIPNG_NODE, &vtysh_exit_ripngd_cmd); |
| 2172 | install_element (RIPNG_NODE, &vtysh_quit_ripngd_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2173 | install_element (OSPF_NODE, &vtysh_exit_ospfd_cmd); |
| 2174 | install_element (OSPF_NODE, &vtysh_quit_ospfd_cmd); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 2175 | install_element (OSPF6_NODE, &vtysh_exit_ospf6d_cmd); |
| 2176 | install_element (OSPF6_NODE, &vtysh_quit_ospf6d_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2177 | install_element (BGP_NODE, &vtysh_exit_bgpd_cmd); |
| 2178 | install_element (BGP_NODE, &vtysh_quit_bgpd_cmd); |
| 2179 | install_element (BGP_VPNV4_NODE, &vtysh_exit_bgpd_cmd); |
| 2180 | install_element (BGP_VPNV4_NODE, &vtysh_quit_bgpd_cmd); |
| 2181 | install_element (BGP_IPV4_NODE, &vtysh_exit_bgpd_cmd); |
| 2182 | install_element (BGP_IPV4_NODE, &vtysh_quit_bgpd_cmd); |
| 2183 | install_element (BGP_IPV4M_NODE, &vtysh_exit_bgpd_cmd); |
| 2184 | install_element (BGP_IPV4M_NODE, &vtysh_quit_bgpd_cmd); |
| 2185 | install_element (BGP_IPV6_NODE, &vtysh_exit_bgpd_cmd); |
| 2186 | install_element (BGP_IPV6_NODE, &vtysh_quit_bgpd_cmd); |
hasso | c25e458 | 2003-12-23 10:39:08 +0000 | [diff] [blame] | 2187 | install_element (ISIS_NODE, &vtysh_exit_isisd_cmd); |
| 2188 | install_element (ISIS_NODE, &vtysh_quit_isisd_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2189 | install_element (KEYCHAIN_NODE, &vtysh_exit_ripd_cmd); |
| 2190 | install_element (KEYCHAIN_NODE, &vtysh_quit_ripd_cmd); |
| 2191 | install_element (KEYCHAIN_KEY_NODE, &vtysh_exit_ripd_cmd); |
| 2192 | install_element (KEYCHAIN_KEY_NODE, &vtysh_quit_ripd_cmd); |
| 2193 | install_element (RMAP_NODE, &vtysh_exit_rmap_cmd); |
| 2194 | install_element (RMAP_NODE, &vtysh_quit_rmap_cmd); |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 2195 | install_element (VTY_NODE, &vtysh_exit_line_vty_cmd); |
| 2196 | install_element (VTY_NODE, &vtysh_quit_line_vty_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2197 | |
| 2198 | /* "end" command. */ |
| 2199 | install_element (CONFIG_NODE, &vtysh_end_all_cmd); |
| 2200 | install_element (ENABLE_NODE, &vtysh_end_all_cmd); |
| 2201 | install_element (RIP_NODE, &vtysh_end_all_cmd); |
| 2202 | install_element (RIPNG_NODE, &vtysh_end_all_cmd); |
| 2203 | install_element (OSPF_NODE, &vtysh_end_all_cmd); |
| 2204 | install_element (OSPF6_NODE, &vtysh_end_all_cmd); |
| 2205 | install_element (BGP_NODE, &vtysh_end_all_cmd); |
| 2206 | install_element (BGP_IPV4_NODE, &vtysh_end_all_cmd); |
| 2207 | install_element (BGP_IPV4M_NODE, &vtysh_end_all_cmd); |
| 2208 | install_element (BGP_VPNV4_NODE, &vtysh_end_all_cmd); |
| 2209 | install_element (BGP_IPV6_NODE, &vtysh_end_all_cmd); |
hasso | c25e458 | 2003-12-23 10:39:08 +0000 | [diff] [blame] | 2210 | install_element (ISIS_NODE, &vtysh_end_all_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2211 | install_element (KEYCHAIN_NODE, &vtysh_end_all_cmd); |
| 2212 | install_element (KEYCHAIN_KEY_NODE, &vtysh_end_all_cmd); |
| 2213 | install_element (RMAP_NODE, &vtysh_end_all_cmd); |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 2214 | install_element (VTY_NODE, &vtysh_end_all_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2215 | |
paul | 338a991 | 2003-03-01 15:44:10 +0000 | [diff] [blame] | 2216 | install_element (INTERFACE_NODE, &interface_desc_cmd); |
paul | 464dc8d | 2003-03-28 02:25:45 +0000 | [diff] [blame] | 2217 | install_element (INTERFACE_NODE, &no_interface_desc_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2218 | install_element (INTERFACE_NODE, &vtysh_end_all_cmd); |
| 2219 | install_element (INTERFACE_NODE, &vtysh_exit_interface_cmd); |
| 2220 | install_element (INTERFACE_NODE, &vtysh_quit_interface_cmd); |
| 2221 | install_element (CONFIG_NODE, &router_rip_cmd); |
| 2222 | #ifdef HAVE_IPV6 |
| 2223 | install_element (CONFIG_NODE, &router_ripng_cmd); |
| 2224 | #endif |
| 2225 | install_element (CONFIG_NODE, &router_ospf_cmd); |
| 2226 | #ifdef HAVE_IPV6 |
| 2227 | install_element (CONFIG_NODE, &router_ospf6_cmd); |
| 2228 | #endif |
hasso | c25e458 | 2003-12-23 10:39:08 +0000 | [diff] [blame] | 2229 | install_element (CONFIG_NODE, &router_isis_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2230 | install_element (CONFIG_NODE, &router_bgp_cmd); |
| 2231 | install_element (BGP_NODE, &address_family_vpnv4_cmd); |
| 2232 | install_element (BGP_NODE, &address_family_vpnv4_unicast_cmd); |
| 2233 | install_element (BGP_NODE, &address_family_ipv4_unicast_cmd); |
| 2234 | install_element (BGP_NODE, &address_family_ipv4_multicast_cmd); |
| 2235 | #ifdef HAVE_IPV6 |
| 2236 | install_element (BGP_NODE, &address_family_ipv6_cmd); |
| 2237 | install_element (BGP_NODE, &address_family_ipv6_unicast_cmd); |
| 2238 | #endif |
| 2239 | install_element (BGP_VPNV4_NODE, &exit_address_family_cmd); |
| 2240 | install_element (BGP_IPV4_NODE, &exit_address_family_cmd); |
| 2241 | install_element (BGP_IPV4M_NODE, &exit_address_family_cmd); |
| 2242 | install_element (BGP_IPV6_NODE, &exit_address_family_cmd); |
| 2243 | install_element (CONFIG_NODE, &key_chain_cmd); |
| 2244 | install_element (CONFIG_NODE, &route_map_cmd); |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 2245 | install_element (CONFIG_NODE, &vtysh_line_vty_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2246 | install_element (KEYCHAIN_NODE, &key_cmd); |
| 2247 | install_element (KEYCHAIN_NODE, &key_chain_cmd); |
| 2248 | install_element (KEYCHAIN_KEY_NODE, &key_chain_cmd); |
| 2249 | install_element (CONFIG_NODE, &vtysh_interface_cmd); |
paul | 32d2463 | 2003-05-23 09:25:20 +0000 | [diff] [blame] | 2250 | install_element (CONFIG_NODE, &vtysh_no_interface_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2251 | install_element (ENABLE_NODE, &vtysh_show_running_config_cmd); |
| 2252 | install_element (ENABLE_NODE, &vtysh_copy_runningconfig_startupconfig_cmd); |
| 2253 | install_element (ENABLE_NODE, &vtysh_write_file_cmd); |
hasso | 4a6e225 | 2003-05-25 11:51:29 +0000 | [diff] [blame] | 2254 | install_element (ENABLE_NODE, &vtysh_write_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2255 | |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 2256 | /* "write terminal" command. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2257 | install_element (ENABLE_NODE, &vtysh_write_terminal_cmd); |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 2258 | |
| 2259 | install_element (CONFIG_NODE, &vtysh_integrated_config_cmd); |
| 2260 | install_element (CONFIG_NODE, &no_vtysh_integrated_config_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2261 | |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 2262 | /* "write memory" command. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2263 | install_element (ENABLE_NODE, &vtysh_write_memory_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2264 | |
hasso | 34553cc | 2004-08-27 13:56:39 +0000 | [diff] [blame] | 2265 | install_element (VIEW_NODE, &vtysh_terminal_length_cmd); |
| 2266 | install_element (ENABLE_NODE, &vtysh_terminal_length_cmd); |
| 2267 | install_element (VIEW_NODE, &vtysh_terminal_no_length_cmd); |
| 2268 | install_element (ENABLE_NODE, &vtysh_terminal_no_length_cmd); |
hasso | f2799e6 | 2004-10-28 17:43:11 +0000 | [diff] [blame] | 2269 | install_element (VIEW_NODE, &vtysh_show_daemons_cmd); |
| 2270 | install_element (ENABLE_NODE, &vtysh_show_daemons_cmd); |
hasso | 34553cc | 2004-08-27 13:56:39 +0000 | [diff] [blame] | 2271 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2272 | install_element (VIEW_NODE, &vtysh_ping_cmd); |
hasso | 4eeccf1 | 2003-06-25 10:49:55 +0000 | [diff] [blame] | 2273 | install_element (VIEW_NODE, &vtysh_ping_ip_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2274 | install_element (VIEW_NODE, &vtysh_traceroute_cmd); |
hasso | 4eeccf1 | 2003-06-25 10:49:55 +0000 | [diff] [blame] | 2275 | install_element (VIEW_NODE, &vtysh_traceroute_ip_cmd); |
| 2276 | #ifdef HAVE_IPV6 |
| 2277 | install_element (VIEW_NODE, &vtysh_ping6_cmd); |
| 2278 | install_element (VIEW_NODE, &vtysh_traceroute6_cmd); |
| 2279 | #endif |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2280 | install_element (VIEW_NODE, &vtysh_telnet_cmd); |
| 2281 | install_element (VIEW_NODE, &vtysh_telnet_port_cmd); |
paul | 5087df5 | 2003-01-25 06:56:09 +0000 | [diff] [blame] | 2282 | install_element (VIEW_NODE, &vtysh_ssh_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2283 | install_element (ENABLE_NODE, &vtysh_ping_cmd); |
hasso | 4eeccf1 | 2003-06-25 10:49:55 +0000 | [diff] [blame] | 2284 | install_element (ENABLE_NODE, &vtysh_ping_ip_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2285 | install_element (ENABLE_NODE, &vtysh_traceroute_cmd); |
hasso | 4eeccf1 | 2003-06-25 10:49:55 +0000 | [diff] [blame] | 2286 | install_element (ENABLE_NODE, &vtysh_traceroute_ip_cmd); |
| 2287 | #ifdef HAVE_IPV6 |
| 2288 | install_element (ENABLE_NODE, &vtysh_ping6_cmd); |
| 2289 | install_element (ENABLE_NODE, &vtysh_traceroute6_cmd); |
| 2290 | #endif |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2291 | install_element (ENABLE_NODE, &vtysh_telnet_cmd); |
| 2292 | install_element (ENABLE_NODE, &vtysh_telnet_port_cmd); |
hasso | 67e29ab | 2004-08-26 22:21:31 +0000 | [diff] [blame] | 2293 | install_element (ENABLE_NODE, &vtysh_ssh_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2294 | install_element (ENABLE_NODE, &vtysh_start_shell_cmd); |
| 2295 | install_element (ENABLE_NODE, &vtysh_start_bash_cmd); |
| 2296 | install_element (ENABLE_NODE, &vtysh_start_zsh_cmd); |
| 2297 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2298 | install_element (CONFIG_NODE, &vtysh_log_stdout_cmd); |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 2299 | install_element (CONFIG_NODE, &vtysh_log_stdout_level_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2300 | install_element (CONFIG_NODE, &no_vtysh_log_stdout_cmd); |
| 2301 | install_element (CONFIG_NODE, &vtysh_log_file_cmd); |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 2302 | install_element (CONFIG_NODE, &vtysh_log_file_level_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2303 | install_element (CONFIG_NODE, &no_vtysh_log_file_cmd); |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 2304 | install_element (CONFIG_NODE, &no_vtysh_log_file_level_cmd); |
| 2305 | install_element (CONFIG_NODE, &vtysh_log_monitor_cmd); |
| 2306 | install_element (CONFIG_NODE, &vtysh_log_monitor_level_cmd); |
| 2307 | install_element (CONFIG_NODE, &no_vtysh_log_monitor_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2308 | install_element (CONFIG_NODE, &vtysh_log_syslog_cmd); |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 2309 | install_element (CONFIG_NODE, &vtysh_log_syslog_level_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2310 | install_element (CONFIG_NODE, &no_vtysh_log_syslog_cmd); |
| 2311 | install_element (CONFIG_NODE, &vtysh_log_trap_cmd); |
| 2312 | install_element (CONFIG_NODE, &no_vtysh_log_trap_cmd); |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 2313 | install_element (CONFIG_NODE, &vtysh_log_facility_cmd); |
| 2314 | install_element (CONFIG_NODE, &no_vtysh_log_facility_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2315 | install_element (CONFIG_NODE, &vtysh_log_record_priority_cmd); |
| 2316 | install_element (CONFIG_NODE, &no_vtysh_log_record_priority_cmd); |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 2317 | |
| 2318 | install_element (CONFIG_NODE, &vtysh_service_password_encrypt_cmd); |
| 2319 | install_element (CONFIG_NODE, &no_vtysh_service_password_encrypt_cmd); |
| 2320 | |
| 2321 | install_element (CONFIG_NODE, &vtysh_password_cmd); |
| 2322 | install_element (CONFIG_NODE, &vtysh_password_text_cmd); |
| 2323 | install_element (CONFIG_NODE, &vtysh_enable_password_cmd); |
| 2324 | install_element (CONFIG_NODE, &vtysh_enable_password_text_cmd); |
| 2325 | install_element (CONFIG_NODE, &no_vtysh_enable_password_cmd); |
| 2326 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2327 | } |