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