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