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