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