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