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