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