blob: 5d59062dfcfa29c9775ba02ce259dff5d8d3b36f [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* 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"
ajs6099b3b2004-11-20 02:06:59 +000036#include "log.h"
Paul Jakma320da872008-07-02 13:40:33 +000037#include "bgpd/bgp_vty.h"
Feng Lu471ea392015-05-22 11:40:00 +020038#include "vrf.h"
paul718e3742002-12-13 20:15:29 +000039
40/* Struct VTY. */
41struct vty *vty;
42
43/* VTY shell pager name. */
44char *vtysh_pager_name = NULL;
45
46/* VTY shell client structure. */
47struct vtysh_client
48{
49 int fd;
ajsb1aa1472005-01-28 21:11:46 +000050 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 Herve596470f2009-08-11 15:45:26 -030062 { .fd = -1, .name = "pimd", .flag = VTYSH_PIMD, .path = PIM_VTYSH_PATH},
Timo Teräsdafa05e2017-01-19 17:27:01 +020063 { .fd = -1, .name = "nhrpd", .flag = VTYSH_NHRPD, .path = NHRP_VTYSH_PATH},
ajsb1aa1472005-01-28 21:11:46 +000064};
65
ajsb1aa1472005-01-28 21:11:46 +000066
67/* We need direct access to ripd to implement vtysh_exit_ripd_only. */
68static struct vtysh_client *ripd_client = NULL;
69
hassob094d262004-08-25 12:22:00 +000070
hassoe7168df2004-10-03 20:11:32 +000071/* Using integrated config from Quagga.conf. Default is no. */
72int vtysh_writeconfig_integrated = 0;
73
74extern char config_default[];
75
ajs274a4a42004-12-07 15:39:31 +000076static void
paul718e3742002-12-13 20:15:29 +000077vclient_close (struct vtysh_client *vclient)
78{
ajsb1aa1472005-01-28 21:11:46 +000079 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 }
paul718e3742002-12-13 20:15:29 +000087}
88
Donald Sharp07440402016-02-25 07:39:45 -050089/* Return true if str begins with prefix, else return false */
90static int
91begins_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
paul718e3742002-12-13 20:15:29 +0000102/* Following filled with debug code to trace a problematic condition
hasso95e735b2004-08-26 13:08:30 +0000103 * under load - it SHOULD handle it. */
Gautam Kumarcc216b72015-10-26 13:22:12 -0700104#define ERR_WHERE_STRING "vtysh(): vtysh_client_execute(): "
ajs274a4a42004-12-07 15:39:31 +0000105static int
Gautam Kumarcc216b72015-10-26 13:22:12 -0700106vtysh_client_execute (struct vtysh_client *vclient, const char *line, FILE *fp)
paul718e3742002-12-13 20:15:29 +0000107{
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 Kumarcc216b72015-10-26 13:22:12 -0700117 int numnulls = 0;
paul718e3742002-12-13 20:15:29 +0000118
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
hasso95e735b2004-08-26 13:08:30 +0000129 /* Allow enough room for buffer to read more than a few pages from socket. */
paule3d29b52003-01-23 18:05:42 +0000130 bufsz = 5 * getpagesize() + 1;
paul718e3742002-12-13 20:15:29 +0000131 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 Franke99f56722016-06-14 20:07:10 +0200141 XFREE(MTYPE_TMP, buf);
paul718e3742002-12-13 20:15:29 +0000142 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 Kumarcc216b72015-10-26 13:22:12 -0700164 /* 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 }
paul718e3742002-12-13 20:15:29 +0000170
171 pbuf[nbytes] = '\0';
172
Gautam Kumarcc216b72015-10-26 13:22:12 -0700173 /* If the config needs to be written in file or stdout */
174 if (fp)
175 {
176 fputs(pbuf, fp);
177 fflush (fp);
178 }
paul718e3742002-12-13 20:15:29 +0000179
Gautam Kumarcc216b72015-10-26 13:22:12 -0700180 /* At max look last four bytes */
181 if (nbytes >= 4)
182 {
183 i = nbytes - 4;
184 numnulls = 0;
185 }
186 else
187 i = 0;
paul718e3742002-12-13 20:15:29 +0000188
Gautam Kumarcc216b72015-10-26 13:22:12 -0700189 /* 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;
paul718e3742002-12-13 20:15:29 +0000200
Gautam Kumarcc216b72015-10-26 13:22:12 -0700201 /* 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 }
paul718e3742002-12-13 20:15:29 +0000236 }
237
Gautam Kumarcc216b72015-10-26 13:22:12 -0700238 if(!fp)
239 vtysh_config_parse (buf);
paul718e3742002-12-13 20:15:29 +0000240
241 XFREE(MTYPE_TMP, buf);
242 return ret;
243}
Gautam Kumarcc216b72015-10-26 13:22:12 -0700244
paul718e3742002-12-13 20:15:29 +0000245
paul718e3742002-12-13 20:15:29 +0000246void
ajsb1aa1472005-01-28 21:11:46 +0000247vtysh_pager_init (void)
paul718e3742002-12-13 20:15:29 +0000248{
hasso5a9c53d2004-08-27 14:23:28 +0000249 char *pager_defined;
250
251 pager_defined = getenv ("VTYSH_PAGER");
252
253 if (pager_defined)
254 vtysh_pager_name = strdup (pager_defined);
255 else
hasso34553cc2004-08-27 13:56:39 +0000256 vtysh_pager_name = strdup ("more");
paul718e3742002-12-13 20:15:29 +0000257}
258
259/* Command execution over the vty interface. */
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700260static int
hassodda09522004-10-07 21:40:25 +0000261vtysh_execute_func (const char *line, int pager)
paul718e3742002-12-13 20:15:29 +0000262{
Stephen Hemminger2c4d48b2008-07-28 15:04:56 -0700263 int ret, cmd_stat;
ajsb1aa1472005-01-28 21:11:46 +0000264 u_int i;
paul718e3742002-12-13 20:15:29 +0000265 vector vline;
266 struct cmd_element *cmd;
267 FILE *fp = NULL;
hasso13bfca72005-01-23 21:42:25 +0000268 int closepager = 0;
269 int tried = 0;
270 int saved_ret, saved_node;
paul718e3742002-12-13 20:15:29 +0000271
hasso95e735b2004-08-26 13:08:30 +0000272 /* Split readline string up into the vector. */
paul718e3742002-12-13 20:15:29 +0000273 vline = cmd_make_strvec (line);
274
275 if (vline == NULL)
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700276 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000277
hasso13bfca72005-01-23 21:42:25 +0000278 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 Berger82dd7072016-01-12 13:41:57 -0500298 if ((saved_node == BGP_VPNV4_NODE || saved_node == BGP_VPNV6_NODE
Lou Bergera3fda882016-01-12 13:42:04 -0500299 || saved_node == BGP_ENCAP_NODE || saved_node == BGP_ENCAPV6_NODE
Lou Berger13c378d2016-01-12 13:41:56 -0500300 || saved_node == BGP_IPV4_NODE
paul57b5b7e2005-08-22 22:44:29 +0000301 || saved_node == BGP_IPV6_NODE || saved_node == BGP_IPV4M_NODE
302 || saved_node == BGP_IPV6M_NODE)
hasso13bfca72005-01-23 21:42:25 +0000303 && (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 }
paul718e3742002-12-13 20:15:29 +0000323
324 cmd_free_strvec (vline);
325
Stephen Hemminger2c4d48b2008-07-28 15:04:56 -0700326 cmd_stat = ret;
paul718e3742002-12-13 20:15:29 +0000327 switch (ret)
328 {
329 case CMD_WARNING:
330 if (vty->type == VTY_FILE)
paul4fc01e62002-12-13 20:49:00 +0000331 fprintf (stdout,"Warning...\n");
paul718e3742002-12-13 20:15:29 +0000332 break;
333 case CMD_ERR_AMBIGUOUS:
paul4fc01e62002-12-13 20:49:00 +0000334 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000335 break;
336 case CMD_ERR_NO_MATCH:
paul4fc01e62002-12-13 20:49:00 +0000337 fprintf (stdout,"%% Unknown command.\n");
paul718e3742002-12-13 20:15:29 +0000338 break;
339 case CMD_ERR_INCOMPLETE:
paul4fc01e62002-12-13 20:49:00 +0000340 fprintf (stdout,"%% Command incomplete.\n");
paul718e3742002-12-13 20:15:29 +0000341 break;
342 case CMD_SUCCESS_DAEMON:
343 {
hasso97b7db22004-10-20 19:07:48 +0000344 /* 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))
paul718e3742002-12-13 20:15:29 +0000348 {
paul4fc01e62002-12-13 20:49:00 +0000349 fp = popen (vtysh_pager_name, "w");
paul718e3742002-12-13 20:15:29 +0000350 if (fp == NULL)
351 {
paula805cc22003-05-01 14:29:48 +0000352 perror ("popen failed for pager");
353 fp = stdout;
paul718e3742002-12-13 20:15:29 +0000354 }
paula805cc22003-05-01 14:29:48 +0000355 else
356 closepager=1;
paul718e3742002-12-13 20:15:29 +0000357 }
358 else
359 fp = stdout;
360
361 if (! strcmp(cmd->string,"configure terminal"))
362 {
Balaji.G837d16c2012-09-26 14:09:10 +0530363 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +0000364 {
365 cmd_stat = vtysh_client_execute(&vtysh_client[i], line, fp);
366 if (cmd_stat == CMD_WARNING)
367 break;
368 }
369
paul718e3742002-12-13 20:15:29 +0000370 if (cmd_stat)
371 {
hassob094d262004-08-25 12:22:00 +0000372 line = "end";
373 vline = cmd_make_strvec (line);
paul718e3742002-12-13 20:15:29 +0000374
hassob094d262004-08-25 12:22:00 +0000375 if (vline == NULL)
paul718e3742002-12-13 20:15:29 +0000376 {
paula805cc22003-05-01 14:29:48 +0000377 if (pager && vtysh_pager_name && fp && closepager)
paul718e3742002-12-13 20:15:29 +0000378 {
379 if (pclose (fp) == -1)
380 {
paula805cc22003-05-01 14:29:48 +0000381 perror ("pclose failed for pager");
paul718e3742002-12-13 20:15:29 +0000382 }
383 fp = NULL;
384 }
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700385 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000386 }
387
hasso87d683b2005-01-16 23:31:54 +0000388 ret = cmd_execute_command (vline, vty, &cmd, 1);
hassob094d262004-08-25 12:22:00 +0000389 cmd_free_strvec (vline);
390 if (ret != CMD_SUCCESS_DAEMON)
391 break;
paul718e3742002-12-13 20:15:29 +0000392 }
393 else
394 if (cmd->func)
395 {
396 (*cmd->func) (cmd, vty, 0, NULL);
397 break;
hassob094d262004-08-25 12:22:00 +0000398 }
paul718e3742002-12-13 20:15:29 +0000399 }
400
ajsb1aa1472005-01-28 21:11:46 +0000401 cmd_stat = CMD_SUCCESS;
Balaji.G837d16c2012-09-26 14:09:10 +0530402 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +0000403 {
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
paul718e3742002-12-13 20:15:29 +0000414 if (cmd->func)
415 (*cmd->func) (cmd, vty, 0, NULL);
416 }
417 }
paula805cc22003-05-01 14:29:48 +0000418 if (pager && vtysh_pager_name && fp && closepager)
paul718e3742002-12-13 20:15:29 +0000419 {
420 if (pclose (fp) == -1)
421 {
paula805cc22003-05-01 14:29:48 +0000422 perror ("pclose failed for pager");
paul718e3742002-12-13 20:15:29 +0000423 }
424 fp = NULL;
425 }
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700426 return cmd_stat;
paul718e3742002-12-13 20:15:29 +0000427}
428
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700429int
hassodda09522004-10-07 21:40:25 +0000430vtysh_execute_no_pager (const char *line)
paul718e3742002-12-13 20:15:29 +0000431{
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700432 return vtysh_execute_func (line, 0);
paul718e3742002-12-13 20:15:29 +0000433}
434
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700435int
hassodda09522004-10-07 21:40:25 +0000436vtysh_execute (const char *line)
paul718e3742002-12-13 20:15:29 +0000437{
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700438 return vtysh_execute_func (line, 1);
paul718e3742002-12-13 20:15:29 +0000439}
440
441/* Configration make from file. */
442int
443vtysh_config_from_file (struct vty *vty, FILE *fp)
444{
445 int ret;
paul718e3742002-12-13 20:15:29 +0000446 struct cmd_element *cmd;
447
Quentin Youngb7ceefe2017-01-10 23:33:50 +0000448 while (fgets (vty->buf, vty->max, fp))
paul718e3742002-12-13 20:15:29 +0000449 {
Donald Sharpd8aa4be2015-09-28 20:10:40 -0400450 ret = command_config_read_one_line (vty, &cmd, 1);
paul718e3742002-12-13 20:15:29 +0000451
452 switch (ret)
453 {
454 case CMD_WARNING:
455 if (vty->type == VTY_FILE)
paul4fc01e62002-12-13 20:49:00 +0000456 fprintf (stdout,"Warning...\n");
paul718e3742002-12-13 20:15:29 +0000457 break;
458 case CMD_ERR_AMBIGUOUS:
paul4fc01e62002-12-13 20:49:00 +0000459 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000460 break;
461 case CMD_ERR_NO_MATCH:
paul4fc01e62002-12-13 20:49:00 +0000462 fprintf (stdout,"%% Unknown command: %s", vty->buf);
paul718e3742002-12-13 20:15:29 +0000463 break;
464 case CMD_ERR_INCOMPLETE:
paul4fc01e62002-12-13 20:49:00 +0000465 fprintf (stdout,"%% Command incomplete.\n");
paul718e3742002-12-13 20:15:29 +0000466 break;
467 case CMD_SUCCESS_DAEMON:
468 {
ajsb1aa1472005-01-28 21:11:46 +0000469 u_int i;
470 int cmd_stat = CMD_SUCCESS;
471
Balaji.G837d16c2012-09-26 14:09:10 +0530472 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +0000473 {
paul44316fe2006-01-11 01:38:25 +0000474 if (cmd->daemon & vtysh_client[i].flag)
ajsb1aa1472005-01-28 21:11:46 +0000475 {
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
paul718e3742002-12-13 20:15:29 +0000485 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 Lampartera9eb9062015-03-04 07:07:01 +0100494static int
ajsb1aa1472005-01-28 21:11:46 +0000495vtysh_rl_describe (void)
paul718e3742002-12-13 20:15:29 +0000496{
497 int ret;
hassodda09522004-10-07 21:40:25 +0000498 unsigned int i;
paul718e3742002-12-13 20:15:29 +0000499 vector vline;
500 vector describe;
501 int width;
Christian Frankecd40b322013-09-30 12:27:51 +0000502 struct cmd_token *token;
paul718e3742002-12-13 20:15:29 +0000503
504 vline = cmd_make_strvec (rl_line_buffer);
505
506 /* In case of '> ?'. */
507 if (vline == NULL)
508 {
509 vline = vector_init (1);
David Lampartera91a3ba2015-03-03 09:06:51 +0100510 vector_set (vline, NULL);
paul718e3742002-12-13 20:15:29 +0000511 }
512 else
513 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
David Lampartera91a3ba2015-03-03 09:06:51 +0100514 vector_set (vline, NULL);
paul718e3742002-12-13 20:15:29 +0000515
516 describe = cmd_describe_command (vline, vty, &ret);
517
paul4fc01e62002-12-13 20:49:00 +0000518 fprintf (stdout,"\n");
paul718e3742002-12-13 20:15:29 +0000519
520 /* Ambiguous and no match error. */
521 switch (ret)
522 {
523 case CMD_ERR_AMBIGUOUS:
524 cmd_free_strvec (vline);
paul4fc01e62002-12-13 20:49:00 +0000525 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000526 rl_on_new_line ();
527 return 0;
528 break;
529 case CMD_ERR_NO_MATCH:
530 cmd_free_strvec (vline);
paul4fc01e62002-12-13 20:49:00 +0000531 fprintf (stdout,"%% There is no matched command.\n");
paul718e3742002-12-13 20:15:29 +0000532 rl_on_new_line ();
533 return 0;
534 break;
535 }
536
537 /* Get width of command string. */
538 width = 0;
paul55468c82005-03-14 20:19:01 +0000539 for (i = 0; i < vector_active (describe); i++)
Christian Frankecd40b322013-09-30 12:27:51 +0000540 if ((token = vector_slot (describe, i)) != NULL)
paul718e3742002-12-13 20:15:29 +0000541 {
542 int len;
543
Christian Frankecd40b322013-09-30 12:27:51 +0000544 if (token->cmd[0] == '\0')
paul718e3742002-12-13 20:15:29 +0000545 continue;
546
Christian Frankecd40b322013-09-30 12:27:51 +0000547 len = strlen (token->cmd);
548 if (token->cmd[0] == '.')
paul718e3742002-12-13 20:15:29 +0000549 len--;
550
551 if (width < len)
552 width = len;
553 }
554
paul55468c82005-03-14 20:19:01 +0000555 for (i = 0; i < vector_active (describe); i++)
Christian Frankecd40b322013-09-30 12:27:51 +0000556 if ((token = vector_slot (describe, i)) != NULL)
paul718e3742002-12-13 20:15:29 +0000557 {
Christian Frankecd40b322013-09-30 12:27:51 +0000558 if (token->cmd[0] == '\0')
paul718e3742002-12-13 20:15:29 +0000559 continue;
560
Christian Frankecd40b322013-09-30 12:27:51 +0000561 if (! token->desc)
paul4fc01e62002-12-13 20:49:00 +0000562 fprintf (stdout," %-s\n",
Christian Frankecd40b322013-09-30 12:27:51 +0000563 token->cmd[0] == '.' ? token->cmd + 1 : token->cmd);
paul718e3742002-12-13 20:15:29 +0000564 else
paul4fc01e62002-12-13 20:49:00 +0000565 fprintf (stdout," %-*s %s\n",
hassob094d262004-08-25 12:22:00 +0000566 width,
Christian Frankecd40b322013-09-30 12:27:51 +0000567 token->cmd[0] == '.' ? token->cmd + 1 : token->cmd,
568 token->desc);
paul718e3742002-12-13 20:15:29 +0000569 }
570
571 cmd_free_strvec (vline);
572 vector_free (describe);
573
574 rl_on_new_line();
575
576 return 0;
577}
578
hasso95e735b2004-08-26 13:08:30 +0000579/* 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. */
paul718e3742002-12-13 20:15:29 +0000582int complete_status;
583
ajs274a4a42004-12-07 15:39:31 +0000584static char *
pauldfc0d9b2003-04-18 23:55:29 +0000585command_generator (const char *text, int state)
paul718e3742002-12-13 20:15:29 +0000586{
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 Lampartera91a3ba2015-03-03 09:06:51 +0100604 vector_set (vline, NULL);
paul718e3742002-12-13 20:15:29 +0000605
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
ajs274a4a42004-12-07 15:39:31 +0000615static char **
paul718e3742002-12-13 20:15:29 +0000616new_completion (char *text, int start, int end)
617{
618 char **matches;
619
pauldfc0d9b2003-04-18 23:55:29 +0000620 matches = rl_completion_matches (text, command_generator);
paul718e3742002-12-13 20:15:29 +0000621
622 if (matches)
623 {
624 rl_point = rl_end;
Christian Franke67e7a212013-03-04 09:23:30 +0000625 if (complete_status != CMD_COMPLETE_FULL_MATCH)
626 /* only append a space on full match */
627 rl_completion_append_character = '\0';
paul718e3742002-12-13 20:15:29 +0000628 }
629
630 return matches;
631}
632
ajs274a4a42004-12-07 15:39:31 +0000633#if 0
634/* This function is not actually being used. */
635static char **
paul718e3742002-12-13 20:15:29 +0000636vtysh_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}
ajs274a4a42004-12-07 15:39:31 +0000659#endif
paul718e3742002-12-13 20:15:29 +0000660
hasso95e735b2004-08-26 13:08:30 +0000661/* Vty node structures. */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800662static struct cmd_node bgp_node =
paul718e3742002-12-13 20:15:29 +0000663{
664 BGP_NODE,
665 "%s(config-router)# ",
666};
667
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800668static struct cmd_node rip_node =
paul718e3742002-12-13 20:15:29 +0000669{
670 RIP_NODE,
671 "%s(config-router)# ",
672};
673
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800674static struct cmd_node isis_node =
hassoc25e4582003-12-23 10:39:08 +0000675{
676 ISIS_NODE,
677 "%s(config-router)# ",
hassoc25e4582003-12-23 10:39:08 +0000678};
679
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800680static struct cmd_node interface_node =
paul718e3742002-12-13 20:15:29 +0000681{
682 INTERFACE_NODE,
683 "%s(config-if)# ",
684};
685
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800686static struct cmd_node rmap_node =
hasso95e735b2004-08-26 13:08:30 +0000687{
688 RMAP_NODE,
689 "%s(config-route-map)# "
690};
691
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800692static struct cmd_node zebra_node =
hasso95e735b2004-08-26 13:08:30 +0000693{
694 ZEBRA_NODE,
695 "%s(config-router)# "
696};
697
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800698static struct cmd_node bgp_vpnv4_node =
hasso95e735b2004-08-26 13:08:30 +0000699{
700 BGP_VPNV4_NODE,
701 "%s(config-router-af)# "
702};
703
Lou Berger13c378d2016-01-12 13:41:56 -0500704static struct cmd_node bgp_vpnv6_node =
705{
706 BGP_VPNV6_NODE,
707 "%s(config-router-af)# "
708};
709
Lou Bergera3fda882016-01-12 13:42:04 -0500710static struct cmd_node bgp_encap_node =
711{
712 BGP_ENCAP_NODE,
713 "%s(config-router-af)# "
714};
715
716static struct cmd_node bgp_encapv6_node =
717{
718 BGP_ENCAPV6_NODE,
719 "%s(config-router-af)# "
720};
721
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800722static struct cmd_node bgp_ipv4_node =
hasso95e735b2004-08-26 13:08:30 +0000723{
724 BGP_IPV4_NODE,
725 "%s(config-router-af)# "
726};
727
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800728static struct cmd_node bgp_ipv4m_node =
hasso95e735b2004-08-26 13:08:30 +0000729{
730 BGP_IPV4M_NODE,
731 "%s(config-router-af)# "
732};
733
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800734static struct cmd_node bgp_ipv6_node =
hasso95e735b2004-08-26 13:08:30 +0000735{
736 BGP_IPV6_NODE,
737 "%s(config-router-af)# "
738};
739
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800740static struct cmd_node bgp_ipv6m_node =
paul57b5b7e2005-08-22 22:44:29 +0000741{
742 BGP_IPV6M_NODE,
743 "%s(config-router-af)# "
744};
745
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800746static struct cmd_node ospf_node =
hasso95e735b2004-08-26 13:08:30 +0000747{
748 OSPF_NODE,
749 "%s(config-router)# "
750};
751
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800752static struct cmd_node ripng_node =
hasso95e735b2004-08-26 13:08:30 +0000753{
754 RIPNG_NODE,
755 "%s(config-router)# "
756};
757
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800758static struct cmd_node ospf6_node =
hasso95e735b2004-08-26 13:08:30 +0000759{
760 OSPF6_NODE,
761 "%s(config-ospf6)# "
762};
763
David Lamparteree53c8b2015-05-23 05:45:59 +0200764static struct cmd_node babel_node =
765{
766 BABEL_NODE,
767 "%s(config-babel)# "
768};
769
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800770static struct cmd_node keychain_node =
hasso95e735b2004-08-26 13:08:30 +0000771{
772 KEYCHAIN_NODE,
773 "%s(config-keychain)# "
774};
775
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800776static struct cmd_node keychain_key_node =
hasso95e735b2004-08-26 13:08:30 +0000777{
778 KEYCHAIN_KEY_NODE,
779 "%s(config-keychain-key)# "
780};
781
Olivier Dugeonac10d302016-04-19 18:33:42 +0200782struct cmd_node link_params_node =
783{
784 LINK_PARAMS_NODE,
785 "%s(config-link-params)# ",
786};
787
hassoe7168df2004-10-03 20:11:32 +0000788/* Defined in lib/vty.c */
789extern struct cmd_node vty_node;
790
hasso95e735b2004-08-26 13:08:30 +0000791/* When '^Z' is received from vty, move down to the enable mode. */
David Lampartera9eb9062015-03-04 07:07:01 +0100792static int
ajsb1aa1472005-01-28 21:11:46 +0000793vtysh_end (void)
hasso95e735b2004-08-26 13:08:30 +0000794{
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
808DEFUNSH (VTYSH_ALL,
809 vtysh_end_all,
810 vtysh_end_all_cmd,
811 "end",
hassoe7168df2004-10-03 20:11:32 +0000812 "End current mode and change to enable mode\n")
hasso95e735b2004-08-26 13:08:30 +0000813{
hasso42895462004-09-26 16:25:07 +0000814 return vtysh_end ();
hasso95e735b2004-08-26 13:08:30 +0000815}
816
paul718e3742002-12-13 20:15:29 +0000817DEFUNSH (VTYSH_BGPD,
818 router_bgp,
819 router_bgp_cmd,
Paul Jakma320da872008-07-02 13:40:33 +0000820 "router bgp " CMD_AS_RANGE,
paul718e3742002-12-13 20:15:29 +0000821 ROUTER_STR
822 BGP_STR
823 AS_STR)
824{
825 vty->node = BGP_NODE;
826 return CMD_SUCCESS;
827}
828
Paul Jakma10895fd2008-07-03 19:34:48 +0000829ALIAS_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
paul718e3742002-12-13 20:15:29 +0000839DEFUNSH (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
850DEFUNSH (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
862DEFUNSH (VTYSH_BGPD,
Lou Berger13c378d2016-01-12 13:41:56 -0500863 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
873DEFUNSH (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
885DEFUNSH (VTYSH_BGPD,
Lou Bergera3fda882016-01-12 13:42:04 -0500886 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
896DEFUNSH (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
907DEFUNSH (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
918DEFUNSH (VTYSH_BGPD,
paul718e3742002-12-13 20:15:29 +0000919 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
930DEFUNSH (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
942DEFUNSH (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
953DEFUNSH (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
paul57b5b7e2005-08-22 22:44:29 +0000965DEFUNSH (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
paul718e3742002-12-13 20:15:29 +0000977DEFUNSH (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
989DEFUNSH (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
1000DEFUNSH (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
1011DEFUNSH (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
1022DEFUNSH (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
1033DEFUNSH (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
hassoc25e4582003-12-23 10:39:08 +00001044DEFUNSH (VTYSH_ISISD,
hassob094d262004-08-25 12:22:00 +00001045 router_isis,
1046 router_isis_cmd,
1047 "router isis WORD",
1048 ROUTER_STR
1049 "ISO IS-IS\n"
1050 "ISO Routing area tag")
hassoc25e4582003-12-23 10:39:08 +00001051{
1052 vty->node = ISIS_NODE;
1053 return CMD_SUCCESS;
1054}
1055
paul718e3742002-12-13 20:15:29 +00001056DEFUNSH (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
paul718e3742002-12-13 20:15:29 +00001070DEFUNSH (VTYSH_ALL,
hassoe7168df2004-10-03 20:11:32 +00001071 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
1081DEFUNSH (VTYSH_ALL,
paul718e3742002-12-13 20:15:29 +00001082 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
paul718e3742002-12-13 20:15:29 +00001091DEFUNSH (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
paul718e3742002-12-13 20:15:29 +00001102DEFUNSH (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
ajs274a4a42004-12-07 15:39:31 +00001113static int
paul718e3742002-12-13 20:15:29 +00001114vtysh_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 Chroboczekfeb6c532012-02-07 04:58:49 +01001132 case BABEL_NODE:
hassoc25e4582003-12-23 10:39:08 +00001133 case ISIS_NODE:
paul718e3742002-12-13 20:15:29 +00001134 case MASC_NODE:
1135 case RMAP_NODE:
1136 case VTY_NODE:
1137 case KEYCHAIN_NODE:
hasso2a56df92004-05-09 23:16:40 +00001138 vtysh_execute("end");
1139 vtysh_execute("configure terminal");
paul718e3742002-12-13 20:15:29 +00001140 vty->node = CONFIG_NODE;
1141 break;
1142 case BGP_VPNV4_NODE:
Lou Berger13c378d2016-01-12 13:41:56 -05001143 case BGP_VPNV6_NODE:
Lou Bergera3fda882016-01-12 13:42:04 -05001144 case BGP_ENCAP_NODE:
1145 case BGP_ENCAPV6_NODE:
paul718e3742002-12-13 20:15:29 +00001146 case BGP_IPV4_NODE:
1147 case BGP_IPV4M_NODE:
1148 case BGP_IPV6_NODE:
paul57b5b7e2005-08-22 22:44:29 +00001149 case BGP_IPV6M_NODE:
paul718e3742002-12-13 20:15:29 +00001150 vty->node = BGP_NODE;
1151 break;
1152 case KEYCHAIN_KEY_NODE:
1153 vty->node = KEYCHAIN_NODE;
1154 break;
Olivier Dugeonac10d302016-04-19 18:33:42 +02001155 case LINK_PARAMS_NODE:
1156 vty->node = INTERFACE_NODE;
1157 break;
paul718e3742002-12-13 20:15:29 +00001158 default:
1159 break;
1160 }
1161 return CMD_SUCCESS;
1162}
1163
1164DEFUNSH (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
1173ALIAS (vtysh_exit_all,
1174 vtysh_quit_all_cmd,
1175 "quit",
1176 "Exit current mode and down to previous mode\n")
1177
1178DEFUNSH (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 Berger13c378d2016-01-12 13:41:56 -05001187 || vty->node == BGP_VPNV6_NODE
Lou Bergera3fda882016-01-12 13:42:04 -05001188 || vty->node == BGP_ENCAP_NODE
1189 || vty->node == BGP_ENCAPV6_NODE
paul57b5b7e2005-08-22 22:44:29 +00001190 || vty->node == BGP_IPV6_NODE
1191 || vty->node == BGP_IPV6M_NODE)
paul718e3742002-12-13 20:15:29 +00001192 vty->node = BGP_NODE;
1193 return CMD_SUCCESS;
1194}
1195
1196DEFUNSH (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
1205ALIAS (vtysh_exit_zebra,
1206 vtysh_quit_zebra_cmd,
1207 "quit",
1208 "Exit current mode and down to previous mode\n")
1209
1210DEFUNSH (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
1219ALIAS (vtysh_exit_ripd,
1220 vtysh_quit_ripd_cmd,
1221 "quit",
1222 "Exit current mode and down to previous mode\n")
1223
paul68980082003-03-25 05:07:42 +00001224DEFUNSH (VTYSH_RIPNGD,
hassob094d262004-08-25 12:22:00 +00001225 vtysh_exit_ripngd,
1226 vtysh_exit_ripngd_cmd,
1227 "exit",
1228 "Exit current mode and down to previous mode\n")
paul68980082003-03-25 05:07:42 +00001229{
1230 return vtysh_exit (vty);
1231}
1232
1233ALIAS (vtysh_exit_ripngd,
1234 vtysh_quit_ripngd_cmd,
1235 "quit",
1236 "Exit current mode and down to previous mode\n")
1237
paul718e3742002-12-13 20:15:29 +00001238DEFUNSH (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
1247ALIAS (vtysh_exit_rmap,
1248 vtysh_quit_rmap_cmd,
1249 "quit",
1250 "Exit current mode and down to previous mode\n")
1251
1252DEFUNSH (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
1261ALIAS (vtysh_exit_bgpd,
1262 vtysh_quit_bgpd_cmd,
1263 "quit",
1264 "Exit current mode and down to previous mode\n")
1265
1266DEFUNSH (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
1275ALIAS (vtysh_exit_ospfd,
1276 vtysh_quit_ospfd_cmd,
1277 "quit",
1278 "Exit current mode and down to previous mode\n")
1279
paul68980082003-03-25 05:07:42 +00001280DEFUNSH (VTYSH_OSPF6D,
hassob094d262004-08-25 12:22:00 +00001281 vtysh_exit_ospf6d,
1282 vtysh_exit_ospf6d_cmd,
1283 "exit",
1284 "Exit current mode and down to previous mode\n")
paul68980082003-03-25 05:07:42 +00001285{
1286 return vtysh_exit (vty);
1287}
1288
1289ALIAS (vtysh_exit_ospf6d,
1290 vtysh_quit_ospf6d_cmd,
1291 "quit",
1292 "Exit current mode and down to previous mode\n")
1293
hassoc25e4582003-12-23 10:39:08 +00001294DEFUNSH (VTYSH_ISISD,
hassob094d262004-08-25 12:22:00 +00001295 vtysh_exit_isisd,
1296 vtysh_exit_isisd_cmd,
1297 "exit",
1298 "Exit current mode and down to previous mode\n")
hassoc25e4582003-12-23 10:39:08 +00001299{
1300 return vtysh_exit (vty);
1301}
1302
1303ALIAS (vtysh_exit_isisd,
1304 vtysh_quit_isisd_cmd,
1305 "quit",
1306 "Exit current mode and down to previous mode\n")
1307
hassoe7168df2004-10-03 20:11:32 +00001308DEFUNSH (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
1317ALIAS (vtysh_exit_line_vty,
1318 vtysh_quit_line_vty_cmd,
1319 "quit",
1320 "Exit current mode and down to previous mode\n")
1321
hasso95e735b2004-08-26 13:08:30 +00001322DEFUNSH (VTYSH_INTERFACE,
paul718e3742002-12-13 20:15:29 +00001323 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 Lu471ea392015-05-22 11:40:00 +02001333ALIAS_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 Ryzhov6ff2acd2016-06-09 16:44:21 +03001341DEFSH (VTYSH_INTERFACE,
paul32d24632003-05-23 09:25:20 +00001342 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 Lu471ea392015-05-22 11:40:00 +02001348DEFSH (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
hasso95e735b2004-08-26 13:08:30 +00001356/* TODO Implement interface description commands in ripngd, ospf6d
1357 * and isisd. */
paul338a9912003-03-01 15:44:10 +00001358DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1359 interface_desc_cmd,
1360 "description .LINE",
1361 "Interface specific description\n"
1362 "Characters describing this interface\n")
paul464dc8d2003-03-28 02:25:45 +00001363
1364DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1365 no_interface_desc_cmd,
1366 "no description",
1367 NO_STR
1368 "Interface specific description\n")
paul338a9912003-03-01 15:44:10 +00001369
hasso95e735b2004-08-26 13:08:30 +00001370DEFUNSH (VTYSH_INTERFACE,
paul718e3742002-12-13 20:15:29 +00001371 vtysh_exit_interface,
1372 vtysh_exit_interface_cmd,
1373 "exit",
1374 "Exit current mode and down to previous mode\n")
1375{
1376 return vtysh_exit (vty);
1377}
1378
1379ALIAS (vtysh_exit_interface,
1380 vtysh_quit_interface_cmd,
1381 "quit",
1382 "Exit current mode and down to previous mode\n")
1383
Donald Sharp567a6382015-08-19 21:22:17 -04001384DEFUN (vtysh_show_thread,
1385 vtysh_show_thread_cmd,
1386 "show thread cpu [FILTER]",
1387 SHOW_STR
1388 "Thread information\n"
1389 "Thread CPU usage\n"
1390 "Display filter (rwtexb)\n")
1391{
1392 unsigned int i;
1393 int ret = CMD_SUCCESS;
1394 char line[100];
1395
1396 sprintf(line, "show thread cpu %s\n", (argc == 1) ? argv[0] : "");
1397 for (i = 0; i < array_size(vtysh_client); i++)
1398 if ( vtysh_client[i].fd >= 0 )
1399 {
1400 fprintf (stdout, "Thread statistics for %s:\n",
1401 vtysh_client[i].name);
1402 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1403 fprintf (stdout,"\n");
1404 }
1405 return ret;
1406}
1407
1408DEFUN (vtysh_show_work_queues,
1409 vtysh_show_work_queues_cmd,
1410 "show work-queues",
1411 SHOW_STR
1412 "Work Queue information\n")
1413{
1414 unsigned int i;
1415 int ret = CMD_SUCCESS;
1416 char line[] = "show work-queues\n";
1417
1418 for (i = 0; i < array_size(vtysh_client); i++)
1419 if ( vtysh_client[i].fd >= 0 )
1420 {
1421 fprintf (stdout, "Work queue statistics for %s:\n",
1422 vtysh_client[i].name);
1423 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1424 fprintf (stdout,"\n");
1425 }
1426
1427 return ret;
1428}
1429
Donald Sharp07440402016-02-25 07:39:45 -05001430DEFUN (vtysh_show_work_queues_daemon,
1431 vtysh_show_work_queues_daemon_cmd,
1432 "show work-queues (zebra|ripd|ripngd|ospfd|ospf6d|bgpd|isisd)",
1433 SHOW_STR
1434 "Work Queue information\n"
1435 "For the zebra daemon\n"
1436 "For the rip daemon\n"
1437 "For the ripng daemon\n"
1438 "For the ospf daemon\n"
1439 "For the ospfv6 daemon\n"
1440 "For the bgp daemon\n"
1441 "For the isis daemon\n")
1442{
1443 unsigned int i;
1444 int ret = CMD_SUCCESS;
1445
1446 for (i = 0; i < array_size(vtysh_client); i++)
1447 {
1448 if (begins_with(vtysh_client[i].name, argv[0]))
1449 break;
1450 }
1451
1452 ret = vtysh_client_execute(&vtysh_client[i], "show work-queues\n", stdout);
1453
1454 return ret;
1455}
1456
Olivier Dugeonac10d302016-04-19 18:33:42 +02001457DEFUNSH (VTYSH_ZEBRA,
1458 vtysh_link_params,
1459 vtysh_link_params_cmd,
1460 "link-params",
1461 LINK_PARAMS_STR
1462 )
1463{
1464 vty->node = LINK_PARAMS_NODE;
1465 return CMD_SUCCESS;
1466}
1467
Donald Sharp2c0adbf2016-11-18 15:42:41 -05001468DEFUNSH (VTYSH_ZEBRA,
1469 exit_link_params,
1470 exit_link_params_cmd,
1471 "exit-link-params",
1472 "Exit from Link Params configuration node\n")
1473{
1474 if (vty->node == LINK_PARAMS_NODE)
1475 vty->node = INTERFACE_NODE;
1476 return CMD_SUCCESS;
1477}
1478
Paul Jakma362b4032006-05-28 07:54:45 +00001479/* Memory */
1480DEFUN (vtysh_show_memory,
1481 vtysh_show_memory_cmd,
1482 "show memory",
1483 SHOW_STR
1484 "Memory statistics\n")
1485{
1486 unsigned int i;
1487 int ret = CMD_SUCCESS;
1488 char line[] = "show memory\n";
1489
Balaji.G837d16c2012-09-26 14:09:10 +05301490 for (i = 0; i < array_size(vtysh_client); i++)
Paul Jakma362b4032006-05-28 07:54:45 +00001491 if ( vtysh_client[i].fd >= 0 )
1492 {
1493 fprintf (stdout, "Memory statistics for %s:\n",
1494 vtysh_client[i].name);
1495 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1496 fprintf (stdout,"\n");
1497 }
1498
1499 return ret;
1500}
1501
hasso95e735b2004-08-26 13:08:30 +00001502/* Logging commands. */
Paul Jakmadbf7d132006-05-23 22:10:01 +00001503DEFUN (vtysh_show_logging,
1504 vtysh_show_logging_cmd,
1505 "show logging",
1506 SHOW_STR
1507 "Show current logging configuration\n")
1508{
1509 unsigned int i;
1510 int ret = CMD_SUCCESS;
1511 char line[] = "show logging\n";
1512
Balaji.G837d16c2012-09-26 14:09:10 +05301513 for (i = 0; i < array_size(vtysh_client); i++)
Paul Jakma4150f332006-05-23 22:10:55 +00001514 if ( vtysh_client[i].fd >= 0 )
1515 {
1516 fprintf (stdout,"Logging configuration for %s:\n",
1517 vtysh_client[i].name);
1518 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1519 fprintf (stdout,"\n");
1520 }
1521
Paul Jakmadbf7d132006-05-23 22:10:01 +00001522 return ret;
1523}
1524
hasso95e735b2004-08-26 13:08:30 +00001525DEFUNSH (VTYSH_ALL,
1526 vtysh_log_stdout,
1527 vtysh_log_stdout_cmd,
1528 "log stdout",
1529 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001530 "Set stdout logging level\n")
1531{
1532 return CMD_SUCCESS;
1533}
1534
1535DEFUNSH (VTYSH_ALL,
1536 vtysh_log_stdout_level,
1537 vtysh_log_stdout_level_cmd,
1538 "log stdout "LOG_LEVELS,
1539 "Logging control\n"
1540 "Set stdout logging level\n"
1541 LOG_LEVEL_DESC)
hasso95e735b2004-08-26 13:08:30 +00001542{
1543 return CMD_SUCCESS;
1544}
1545
1546DEFUNSH (VTYSH_ALL,
1547 no_vtysh_log_stdout,
1548 no_vtysh_log_stdout_cmd,
ajs274a4a42004-12-07 15:39:31 +00001549 "no log stdout [LEVEL]",
hasso95e735b2004-08-26 13:08:30 +00001550 NO_STR
1551 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001552 "Cancel logging to stdout\n"
1553 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001554{
1555 return CMD_SUCCESS;
1556}
1557
1558DEFUNSH (VTYSH_ALL,
1559 vtysh_log_file,
1560 vtysh_log_file_cmd,
1561 "log file FILENAME",
1562 "Logging control\n"
1563 "Logging to file\n"
1564 "Logging filename\n")
1565{
1566 return CMD_SUCCESS;
1567}
1568
1569DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001570 vtysh_log_file_level,
1571 vtysh_log_file_level_cmd,
1572 "log file FILENAME "LOG_LEVELS,
1573 "Logging control\n"
1574 "Logging to file\n"
1575 "Logging filename\n"
1576 LOG_LEVEL_DESC)
1577{
1578 return CMD_SUCCESS;
1579}
1580
1581DEFUNSH (VTYSH_ALL,
hasso95e735b2004-08-26 13:08:30 +00001582 no_vtysh_log_file,
1583 no_vtysh_log_file_cmd,
1584 "no log file [FILENAME]",
1585 NO_STR
1586 "Logging control\n"
1587 "Cancel logging to file\n"
1588 "Logging file name\n")
1589{
1590 return CMD_SUCCESS;
1591}
1592
ajs274a4a42004-12-07 15:39:31 +00001593ALIAS_SH (VTYSH_ALL,
1594 no_vtysh_log_file,
1595 no_vtysh_log_file_level_cmd,
1596 "no log file FILENAME LEVEL",
1597 NO_STR
1598 "Logging control\n"
1599 "Cancel logging to file\n"
1600 "Logging file name\n"
1601 "Logging level\n")
1602
1603DEFUNSH (VTYSH_ALL,
1604 vtysh_log_monitor,
1605 vtysh_log_monitor_cmd,
1606 "log monitor",
1607 "Logging control\n"
1608 "Set terminal line (monitor) logging level\n")
1609{
1610 return CMD_SUCCESS;
1611}
1612
1613DEFUNSH (VTYSH_ALL,
1614 vtysh_log_monitor_level,
1615 vtysh_log_monitor_level_cmd,
1616 "log monitor "LOG_LEVELS,
1617 "Logging control\n"
1618 "Set terminal line (monitor) logging level\n"
1619 LOG_LEVEL_DESC)
1620{
1621 return CMD_SUCCESS;
1622}
1623
1624DEFUNSH (VTYSH_ALL,
1625 no_vtysh_log_monitor,
1626 no_vtysh_log_monitor_cmd,
1627 "no log monitor [LEVEL]",
1628 NO_STR
1629 "Logging control\n"
1630 "Disable terminal line (monitor) logging\n"
1631 "Logging level\n")
1632{
1633 return CMD_SUCCESS;
1634}
1635
hasso95e735b2004-08-26 13:08:30 +00001636DEFUNSH (VTYSH_ALL,
1637 vtysh_log_syslog,
1638 vtysh_log_syslog_cmd,
1639 "log syslog",
1640 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001641 "Set syslog logging level\n")
1642{
1643 return CMD_SUCCESS;
1644}
1645
1646DEFUNSH (VTYSH_ALL,
1647 vtysh_log_syslog_level,
1648 vtysh_log_syslog_level_cmd,
1649 "log syslog "LOG_LEVELS,
1650 "Logging control\n"
1651 "Set syslog logging level\n"
1652 LOG_LEVEL_DESC)
hasso95e735b2004-08-26 13:08:30 +00001653{
1654 return CMD_SUCCESS;
1655}
1656
1657DEFUNSH (VTYSH_ALL,
1658 no_vtysh_log_syslog,
1659 no_vtysh_log_syslog_cmd,
ajs274a4a42004-12-07 15:39:31 +00001660 "no log syslog [LEVEL]",
hasso95e735b2004-08-26 13:08:30 +00001661 NO_STR
1662 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001663 "Cancel logging to syslog\n"
1664 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001665{
1666 return CMD_SUCCESS;
1667}
1668
1669DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001670 vtysh_log_facility,
1671 vtysh_log_facility_cmd,
1672 "log facility "LOG_FACILITIES,
hasso95e735b2004-08-26 13:08:30 +00001673 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001674 "Facility parameter for syslog messages\n"
1675 LOG_FACILITY_DESC)
1676
hasso95e735b2004-08-26 13:08:30 +00001677{
1678 return CMD_SUCCESS;
1679}
1680
1681DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001682 no_vtysh_log_facility,
1683 no_vtysh_log_facility_cmd,
1684 "no log facility [FACILITY]",
hasso95e735b2004-08-26 13:08:30 +00001685 NO_STR
1686 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001687 "Reset syslog facility to default (daemon)\n"
1688 "Syslog facility\n")
1689
1690{
1691 return CMD_SUCCESS;
1692}
1693
1694DEFUNSH_DEPRECATED (VTYSH_ALL,
1695 vtysh_log_trap,
1696 vtysh_log_trap_cmd,
1697 "log trap "LOG_LEVELS,
1698 "Logging control\n"
1699 "(Deprecated) Set logging level and default for all destinations\n"
1700 LOG_LEVEL_DESC)
1701
1702{
1703 return CMD_SUCCESS;
1704}
1705
1706DEFUNSH_DEPRECATED (VTYSH_ALL,
1707 no_vtysh_log_trap,
1708 no_vtysh_log_trap_cmd,
1709 "no log trap [LEVEL]",
1710 NO_STR
1711 "Logging control\n"
1712 "Permit all logging information\n"
1713 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001714{
1715 return CMD_SUCCESS;
1716}
1717
1718DEFUNSH (VTYSH_ALL,
1719 vtysh_log_record_priority,
1720 vtysh_log_record_priority_cmd,
1721 "log record-priority",
1722 "Logging control\n"
1723 "Log the priority of the message within the message\n")
1724{
1725 return CMD_SUCCESS;
1726}
1727
1728DEFUNSH (VTYSH_ALL,
1729 no_vtysh_log_record_priority,
1730 no_vtysh_log_record_priority_cmd,
1731 "no log record-priority",
1732 NO_STR
1733 "Logging control\n"
1734 "Do not log the priority of the message within the message\n")
1735{
1736 return CMD_SUCCESS;
1737}
1738
hassoe7168df2004-10-03 20:11:32 +00001739DEFUNSH (VTYSH_ALL,
Andrew J. Schorrc749b722007-04-29 03:53:31 +00001740 vtysh_log_timestamp_precision,
1741 vtysh_log_timestamp_precision_cmd,
1742 "log timestamp precision <0-6>",
1743 "Logging control\n"
1744 "Timestamp configuration\n"
1745 "Set the timestamp precision\n"
1746 "Number of subsecond digits\n")
1747{
1748 return CMD_SUCCESS;
1749}
1750
1751DEFUNSH (VTYSH_ALL,
1752 no_vtysh_log_timestamp_precision,
1753 no_vtysh_log_timestamp_precision_cmd,
1754 "no log timestamp precision",
1755 NO_STR
1756 "Logging control\n"
1757 "Timestamp configuration\n"
1758 "Reset the timestamp precision to the default value of 0\n")
1759{
1760 return CMD_SUCCESS;
1761}
1762
1763DEFUNSH (VTYSH_ALL,
hassoe7168df2004-10-03 20:11:32 +00001764 vtysh_service_password_encrypt,
1765 vtysh_service_password_encrypt_cmd,
1766 "service password-encryption",
1767 "Set up miscellaneous service\n"
1768 "Enable encrypted passwords\n")
1769{
1770 return CMD_SUCCESS;
1771}
1772
1773DEFUNSH (VTYSH_ALL,
1774 no_vtysh_service_password_encrypt,
1775 no_vtysh_service_password_encrypt_cmd,
1776 "no service password-encryption",
1777 NO_STR
1778 "Set up miscellaneous service\n"
1779 "Enable encrypted passwords\n")
1780{
1781 return CMD_SUCCESS;
1782}
1783
1784DEFUNSH (VTYSH_ALL,
1785 vtysh_config_password,
1786 vtysh_password_cmd,
1787 "password (8|) WORD",
1788 "Assign the terminal connection password\n"
1789 "Specifies a HIDDEN password will follow\n"
1790 "dummy string \n"
1791 "The HIDDEN line password string\n")
1792{
1793 return CMD_SUCCESS;
1794}
1795
1796DEFUNSH (VTYSH_ALL,
1797 vtysh_password_text,
1798 vtysh_password_text_cmd,
1799 "password LINE",
1800 "Assign the terminal connection password\n"
1801 "The UNENCRYPTED (cleartext) line password\n")
1802{
1803 return CMD_SUCCESS;
1804}
1805
1806DEFUNSH (VTYSH_ALL,
1807 vtysh_config_enable_password,
1808 vtysh_enable_password_cmd,
1809 "enable password (8|) WORD",
1810 "Modify enable password parameters\n"
1811 "Assign the privileged level password\n"
1812 "Specifies a HIDDEN password will follow\n"
1813 "dummy string \n"
1814 "The HIDDEN 'enable' password string\n")
1815{
1816 return CMD_SUCCESS;
1817}
1818
1819DEFUNSH (VTYSH_ALL,
1820 vtysh_enable_password_text,
1821 vtysh_enable_password_text_cmd,
1822 "enable password LINE",
1823 "Modify enable password parameters\n"
1824 "Assign the privileged level password\n"
1825 "The UNENCRYPTED (cleartext) 'enable' password\n")
1826{
1827 return CMD_SUCCESS;
1828}
1829
1830DEFUNSH (VTYSH_ALL,
1831 no_vtysh_config_enable_password,
1832 no_vtysh_enable_password_cmd,
1833 "no enable password",
1834 NO_STR
1835 "Modify enable password parameters\n"
1836 "Assign the privileged level password\n")
1837{
1838 return CMD_SUCCESS;
1839}
1840
paul718e3742002-12-13 20:15:29 +00001841DEFUN (vtysh_write_terminal,
1842 vtysh_write_terminal_cmd,
1843 "write terminal",
1844 "Write running configuration to memory, network, or terminal\n"
1845 "Write to terminal\n")
1846{
ajsb1aa1472005-01-28 21:11:46 +00001847 u_int i;
paul718e3742002-12-13 20:15:29 +00001848 char line[] = "write terminal\n";
1849 FILE *fp = NULL;
1850
1851 if (vtysh_pager_name)
1852 {
paul4fc01e62002-12-13 20:49:00 +00001853 fp = popen (vtysh_pager_name, "w");
paul718e3742002-12-13 20:15:29 +00001854 if (fp == NULL)
1855 {
1856 perror ("popen");
1857 exit (1);
1858 }
1859 }
1860 else
1861 fp = stdout;
1862
1863 vty_out (vty, "Building configuration...%s", VTY_NEWLINE);
1864 vty_out (vty, "%sCurrent configuration:%s", VTY_NEWLINE,
1865 VTY_NEWLINE);
hassoe7168df2004-10-03 20:11:32 +00001866 vty_out (vty, "!%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001867
Balaji.G837d16c2012-09-26 14:09:10 +05301868 for (i = 0; i < array_size(vtysh_client); i++)
Gautam Kumarcc216b72015-10-26 13:22:12 -07001869 vtysh_client_execute (&vtysh_client[i], line, NULL);
paul718e3742002-12-13 20:15:29 +00001870
hassoe7168df2004-10-03 20:11:32 +00001871 /* Integrate vtysh specific configuration. */
1872 vtysh_config_write ();
1873
paul718e3742002-12-13 20:15:29 +00001874 vtysh_config_dump (fp);
1875
1876 if (vtysh_pager_name && fp)
1877 {
1878 fflush (fp);
1879 if (pclose (fp) == -1)
1880 {
1881 perror ("pclose");
1882 exit (1);
1883 }
1884 fp = NULL;
1885 }
1886
Chris Caputo6e79f8b2009-06-23 05:55:57 +00001887 vty_out (vty, "end%s", VTY_NEWLINE);
1888
paul718e3742002-12-13 20:15:29 +00001889 return CMD_SUCCESS;
1890}
1891
Donald Sharp9fb73e82015-09-22 11:13:12 -04001892DEFUN (vtysh_write_terminal_daemon,
1893 vtysh_write_terminal_daemon_cmd,
1894 "write terminal (zebra|ripd|ripngd|ospfd|ospf6d|bgpd|isisd|babeld)",
1895 "Write running configuration to memory, network, or terminal\n"
1896 "Write to terminal\n"
1897 "For the zebra daemon\n"
1898 "For the rip daemon\n"
1899 "For the ripng daemon\n"
1900 "For the ospf daemon\n"
1901 "For the ospfv6 daemon\n"
1902 "For the bgp daemon\n"
1903 "For the isis daemon\n"
1904 "For the babel daemon\n")
1905{
1906 unsigned int i;
1907 int ret = CMD_SUCCESS;
1908
1909 for (i = 0; i < array_size(vtysh_client); i++)
1910 {
1911 if (strcmp(vtysh_client[i].name, argv[0]) == 0)
1912 break;
1913 }
1914
Christian Franke5d9fae22016-06-14 20:07:09 +02001915 if (i == array_size(vtysh_client))
1916 return CMD_ERR_NO_MATCH;
1917
Donald Sharp9fb73e82015-09-22 11:13:12 -04001918 ret = vtysh_client_execute(&vtysh_client[i], "show running-config\n", stdout);
1919
1920 return ret;
1921}
1922
hassoe7168df2004-10-03 20:11:32 +00001923DEFUN (vtysh_integrated_config,
1924 vtysh_integrated_config_cmd,
1925 "service integrated-vtysh-config",
1926 "Set up miscellaneous service\n"
1927 "Write configuration into integrated file\n")
paul4fc01e62002-12-13 20:49:00 +00001928{
hassoe7168df2004-10-03 20:11:32 +00001929 vtysh_writeconfig_integrated = 1;
1930 return CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001931}
1932
hassoe7168df2004-10-03 20:11:32 +00001933DEFUN (no_vtysh_integrated_config,
1934 no_vtysh_integrated_config_cmd,
1935 "no service integrated-vtysh-config",
1936 NO_STR
1937 "Set up miscellaneous service\n"
1938 "Write configuration into integrated file\n")
paul4fc01e62002-12-13 20:49:00 +00001939{
hassoe7168df2004-10-03 20:11:32 +00001940 vtysh_writeconfig_integrated = 0;
1941 return CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001942}
1943
ajs274a4a42004-12-07 15:39:31 +00001944static int
1945write_config_integrated(void)
paul718e3742002-12-13 20:15:29 +00001946{
ajsb1aa1472005-01-28 21:11:46 +00001947 u_int i;
paul718e3742002-12-13 20:15:29 +00001948 char line[] = "write terminal\n";
1949 FILE *fp;
1950 char *integrate_sav = NULL;
1951
hasso95e735b2004-08-26 13:08:30 +00001952 integrate_sav = malloc (strlen (integrate_default) +
1953 strlen (CONF_BACKUP_EXT) + 1);
paul718e3742002-12-13 20:15:29 +00001954 strcpy (integrate_sav, integrate_default);
1955 strcat (integrate_sav, CONF_BACKUP_EXT);
1956
paul4fc01e62002-12-13 20:49:00 +00001957 fprintf (stdout,"Building Configuration...\n");
paul718e3742002-12-13 20:15:29 +00001958
hasso95e735b2004-08-26 13:08:30 +00001959 /* Move current configuration file to backup config file. */
paul718e3742002-12-13 20:15:29 +00001960 unlink (integrate_sav);
1961 rename (integrate_default, integrate_sav);
hasso95e735b2004-08-26 13:08:30 +00001962 free (integrate_sav);
paul4fc01e62002-12-13 20:49:00 +00001963
paul718e3742002-12-13 20:15:29 +00001964 fp = fopen (integrate_default, "w");
1965 if (fp == NULL)
1966 {
hasso95e735b2004-08-26 13:08:30 +00001967 fprintf (stdout,"%% Can't open configuration file %s.\n",
1968 integrate_default);
paul718e3742002-12-13 20:15:29 +00001969 return CMD_SUCCESS;
1970 }
paul718e3742002-12-13 20:15:29 +00001971
Balaji.G837d16c2012-09-26 14:09:10 +05301972 for (i = 0; i < array_size(vtysh_client); i++)
Gautam Kumarcc216b72015-10-26 13:22:12 -07001973 vtysh_client_execute (&vtysh_client[i], line, NULL);
paul718e3742002-12-13 20:15:29 +00001974
Donald Sharp147a8122015-05-21 16:06:21 -07001975 vtysh_config_write ();
paul718e3742002-12-13 20:15:29 +00001976 vtysh_config_dump (fp);
1977
1978 fclose (fp);
1979
gdtaa593d52003-12-22 20:15:53 +00001980 if (chmod (integrate_default, CONFIGFILE_MASK) != 0)
1981 {
1982 fprintf (stdout,"%% Can't chmod configuration file %s: %s (%d)\n",
ajs6099b3b2004-11-20 02:06:59 +00001983 integrate_default, safe_strerror(errno), errno);
gdtaa593d52003-12-22 20:15:53 +00001984 return CMD_WARNING;
1985 }
1986
paul4fc01e62002-12-13 20:49:00 +00001987 fprintf(stdout,"Integrated configuration saved to %s\n",integrate_default);
1988
1989 fprintf (stdout,"[OK]\n");
1990
paul718e3742002-12-13 20:15:29 +00001991 return CMD_SUCCESS;
1992}
1993
paul4fc01e62002-12-13 20:49:00 +00001994DEFUN (vtysh_write_memory,
1995 vtysh_write_memory_cmd,
1996 "write memory",
1997 "Write running configuration to memory, network, or terminal\n"
1998 "Write configuration to the file (same as write file)\n")
1999{
pauldfc0d9b2003-04-18 23:55:29 +00002000 int ret = CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00002001 char line[] = "write memory\n";
ajsb1aa1472005-01-28 21:11:46 +00002002 u_int i;
paul4fc01e62002-12-13 20:49:00 +00002003
hassoe7168df2004-10-03 20:11:32 +00002004 /* If integrated Quagga.conf explicitely set. */
2005 if (vtysh_writeconfig_integrated)
2006 return write_config_integrated();
paul4fc01e62002-12-13 20:49:00 +00002007
2008 fprintf (stdout,"Building Configuration...\n");
2009
Balaji.G837d16c2012-09-26 14:09:10 +05302010 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00002011 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
hassoe7168df2004-10-03 20:11:32 +00002012
paul4fc01e62002-12-13 20:49:00 +00002013 fprintf (stdout,"[OK]\n");
2014
pauldfc0d9b2003-04-18 23:55:29 +00002015 return ret;
paul4fc01e62002-12-13 20:49:00 +00002016}
2017
paul718e3742002-12-13 20:15:29 +00002018ALIAS (vtysh_write_memory,
2019 vtysh_copy_runningconfig_startupconfig_cmd,
2020 "copy running-config startup-config",
2021 "Copy from one file to another\n"
2022 "Copy from current system configuration\n"
2023 "Copy to startup configuration\n")
2024
2025ALIAS (vtysh_write_memory,
2026 vtysh_write_file_cmd,
2027 "write file",
2028 "Write running configuration to memory, network, or terminal\n"
2029 "Write configuration to the file (same as write memory)\n")
2030
hasso4a6e2252003-05-25 11:51:29 +00002031ALIAS (vtysh_write_memory,
2032 vtysh_write_cmd,
2033 "write",
2034 "Write running configuration to memory, network, or terminal\n")
2035
paul718e3742002-12-13 20:15:29 +00002036ALIAS (vtysh_write_terminal,
2037 vtysh_show_running_config_cmd,
2038 "show running-config",
2039 SHOW_STR
2040 "Current operating configuration\n")
hassob094d262004-08-25 12:22:00 +00002041
Donald Sharp9fb73e82015-09-22 11:13:12 -04002042ALIAS (vtysh_write_terminal_daemon,
2043 vtysh_show_running_config_daemon_cmd,
2044 "show running-config (zebra|ripd|ripngd|ospfd|ospf6d|bgpd|isisd|babeld)",
2045 SHOW_STR
2046 "Current operating configuration\n"
2047 "For the zebra daemon\n"
2048 "For the rip daemon\n"
2049 "For the ripng daemon\n"
2050 "For the ospf daemon\n"
2051 "For the ospfv6 daemon\n"
2052 "For the bgp daemon\n"
2053 "For the isis daemon\n"
2054 "For the babel daemon\n")
2055
hasso34553cc2004-08-27 13:56:39 +00002056DEFUN (vtysh_terminal_length,
2057 vtysh_terminal_length_cmd,
2058 "terminal length <0-512>",
2059 "Set terminal line parameters\n"
2060 "Set number of lines on a screen\n"
2061 "Number of lines on screen (0 for no pausing)\n")
2062{
2063 int lines;
2064 char *endptr = NULL;
2065 char default_pager[10];
2066
2067 lines = strtol (argv[0], &endptr, 10);
2068 if (lines < 0 || lines > 512 || *endptr != '\0')
2069 {
2070 vty_out (vty, "length is malformed%s", VTY_NEWLINE);
2071 return CMD_WARNING;
2072 }
2073
2074 if (vtysh_pager_name)
2075 {
2076 free (vtysh_pager_name);
2077 vtysh_pager_name = NULL;
2078 }
2079
2080 if (lines != 0)
2081 {
2082 snprintf(default_pager, 10, "more -%i", lines);
2083 vtysh_pager_name = strdup (default_pager);
2084 }
2085
2086 return CMD_SUCCESS;
2087}
2088
2089DEFUN (vtysh_terminal_no_length,
2090 vtysh_terminal_no_length_cmd,
2091 "terminal no length",
2092 "Set terminal line parameters\n"
2093 NO_STR
2094 "Set number of lines on a screen\n")
2095{
2096 if (vtysh_pager_name)
2097 {
2098 free (vtysh_pager_name);
2099 vtysh_pager_name = NULL;
2100 }
2101
2102 vtysh_pager_init();
2103 return CMD_SUCCESS;
2104}
2105
hassof2799e62004-10-28 17:43:11 +00002106DEFUN (vtysh_show_daemons,
2107 vtysh_show_daemons_cmd,
2108 "show daemons",
hassoe7168df2004-10-03 20:11:32 +00002109 SHOW_STR
2110 "Show list of running daemons\n")
2111{
ajsb1aa1472005-01-28 21:11:46 +00002112 u_int i;
2113
Balaji.G837d16c2012-09-26 14:09:10 +05302114 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00002115 if ( vtysh_client[i].fd >= 0 )
2116 vty_out(vty, " %s", vtysh_client[i].name);
hassoe7168df2004-10-03 20:11:32 +00002117 vty_out(vty, "%s", VTY_NEWLINE);
2118
2119 return CMD_SUCCESS;
2120}
2121
paul718e3742002-12-13 20:15:29 +00002122/* Execute command in child process. */
ajs274a4a42004-12-07 15:39:31 +00002123static int
hasso5862ff52004-10-11 13:20:40 +00002124execute_command (const char *command, int argc, const char *arg1,
2125 const char *arg2)
paul718e3742002-12-13 20:15:29 +00002126{
paul718e3742002-12-13 20:15:29 +00002127 pid_t pid;
2128 int status;
2129
2130 /* Call fork(). */
2131 pid = fork ();
2132
2133 if (pid < 0)
2134 {
2135 /* Failure of fork(). */
ajs6099b3b2004-11-20 02:06:59 +00002136 fprintf (stderr, "Can't fork: %s\n", safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +00002137 exit (1);
2138 }
2139 else if (pid == 0)
2140 {
2141 /* This is child process. */
2142 switch (argc)
2143 {
2144 case 0:
David Lamparter6769f432015-03-04 07:18:24 +01002145 execlp (command, command, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00002146 break;
2147 case 1:
David Lamparter6769f432015-03-04 07:18:24 +01002148 execlp (command, command, arg1, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00002149 break;
2150 case 2:
David Lamparter6769f432015-03-04 07:18:24 +01002151 execlp (command, command, arg1, arg2, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00002152 break;
2153 }
2154
2155 /* When execlp suceed, this part is not executed. */
ajs6099b3b2004-11-20 02:06:59 +00002156 fprintf (stderr, "Can't execute %s: %s\n", command, safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +00002157 exit (1);
2158 }
2159 else
2160 {
2161 /* This is parent. */
2162 execute_flag = 1;
David Lamparter6769f432015-03-04 07:18:24 +01002163 wait4 (pid, &status, 0, NULL);
paul718e3742002-12-13 20:15:29 +00002164 execute_flag = 0;
2165 }
2166 return 0;
2167}
2168
2169DEFUN (vtysh_ping,
2170 vtysh_ping_cmd,
2171 "ping WORD",
hasso4eeccf12003-06-25 10:49:55 +00002172 "Send echo messages\n"
paul718e3742002-12-13 20:15:29 +00002173 "Ping destination address or hostname\n")
2174{
2175 execute_command ("ping", 1, argv[0], NULL);
2176 return CMD_SUCCESS;
2177}
2178
hasso4eeccf12003-06-25 10:49:55 +00002179ALIAS (vtysh_ping,
2180 vtysh_ping_ip_cmd,
2181 "ping ip WORD",
2182 "Send echo messages\n"
2183 "IP echo\n"
2184 "Ping destination address or hostname\n")
2185
paul718e3742002-12-13 20:15:29 +00002186DEFUN (vtysh_traceroute,
2187 vtysh_traceroute_cmd,
2188 "traceroute WORD",
2189 "Trace route to destination\n"
2190 "Trace route to destination address or hostname\n")
2191{
2192 execute_command ("traceroute", 1, argv[0], NULL);
2193 return CMD_SUCCESS;
2194}
2195
hasso4eeccf12003-06-25 10:49:55 +00002196ALIAS (vtysh_traceroute,
2197 vtysh_traceroute_ip_cmd,
2198 "traceroute ip WORD",
2199 "Trace route to destination\n"
2200 "IP trace\n"
2201 "Trace route to destination address or hostname\n")
2202
2203#ifdef HAVE_IPV6
2204DEFUN (vtysh_ping6,
2205 vtysh_ping6_cmd,
2206 "ping ipv6 WORD",
2207 "Send echo messages\n"
2208 "IPv6 echo\n"
2209 "Ping destination address or hostname\n")
2210{
2211 execute_command ("ping6", 1, argv[0], NULL);
2212 return CMD_SUCCESS;
2213}
2214
2215DEFUN (vtysh_traceroute6,
2216 vtysh_traceroute6_cmd,
2217 "traceroute ipv6 WORD",
2218 "Trace route to destination\n"
2219 "IPv6 trace\n"
2220 "Trace route to destination address or hostname\n")
2221{
2222 execute_command ("traceroute6", 1, argv[0], NULL);
2223 return CMD_SUCCESS;
2224}
2225#endif
2226
paul718e3742002-12-13 20:15:29 +00002227DEFUN (vtysh_telnet,
2228 vtysh_telnet_cmd,
2229 "telnet WORD",
2230 "Open a telnet connection\n"
2231 "IP address or hostname of a remote system\n")
2232{
2233 execute_command ("telnet", 1, argv[0], NULL);
2234 return CMD_SUCCESS;
2235}
2236
2237DEFUN (vtysh_telnet_port,
2238 vtysh_telnet_port_cmd,
2239 "telnet WORD PORT",
2240 "Open a telnet connection\n"
2241 "IP address or hostname of a remote system\n"
2242 "TCP Port number\n")
2243{
2244 execute_command ("telnet", 2, argv[0], argv[1]);
2245 return CMD_SUCCESS;
2246}
2247
paul5087df52003-01-25 06:56:09 +00002248DEFUN (vtysh_ssh,
2249 vtysh_ssh_cmd,
2250 "ssh WORD",
2251 "Open an ssh connection\n"
2252 "[user@]host\n")
2253{
2254 execute_command ("ssh", 1, argv[0], NULL);
2255 return CMD_SUCCESS;
2256}
2257
paul718e3742002-12-13 20:15:29 +00002258DEFUN (vtysh_start_shell,
2259 vtysh_start_shell_cmd,
2260 "start-shell",
2261 "Start UNIX shell\n")
2262{
2263 execute_command ("sh", 0, NULL, NULL);
2264 return CMD_SUCCESS;
2265}
2266
2267DEFUN (vtysh_start_bash,
2268 vtysh_start_bash_cmd,
2269 "start-shell bash",
2270 "Start UNIX shell\n"
2271 "Start bash\n")
2272{
2273 execute_command ("bash", 0, NULL, NULL);
2274 return CMD_SUCCESS;
2275}
2276
2277DEFUN (vtysh_start_zsh,
2278 vtysh_start_zsh_cmd,
2279 "start-shell zsh",
2280 "Start UNIX shell\n"
2281 "Start Z shell\n")
2282{
2283 execute_command ("zsh", 0, NULL, NULL);
2284 return CMD_SUCCESS;
2285}
hassob094d262004-08-25 12:22:00 +00002286
ajs274a4a42004-12-07 15:39:31 +00002287static void
paul718e3742002-12-13 20:15:29 +00002288vtysh_install_default (enum node_type node)
2289{
2290 install_element (node, &config_list_cmd);
2291}
2292
2293/* Making connection to protocol daemon. */
ajs274a4a42004-12-07 15:39:31 +00002294static int
ajsb1aa1472005-01-28 21:11:46 +00002295vtysh_connect (struct vtysh_client *vclient)
paul718e3742002-12-13 20:15:29 +00002296{
2297 int ret;
2298 int sock, len;
2299 struct sockaddr_un addr;
2300 struct stat s_stat;
paul718e3742002-12-13 20:15:29 +00002301
paul718e3742002-12-13 20:15:29 +00002302 /* Stat socket to see if we have permission to access it. */
ajsb1aa1472005-01-28 21:11:46 +00002303 ret = stat (vclient->path, &s_stat);
paul718e3742002-12-13 20:15:29 +00002304 if (ret < 0 && errno != ENOENT)
2305 {
2306 fprintf (stderr, "vtysh_connect(%s): stat = %s\n",
ajsb1aa1472005-01-28 21:11:46 +00002307 vclient->path, safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002308 exit(1);
2309 }
2310
2311 if (ret >= 0)
2312 {
2313 if (! S_ISSOCK(s_stat.st_mode))
2314 {
2315 fprintf (stderr, "vtysh_connect(%s): Not a socket\n",
ajsb1aa1472005-01-28 21:11:46 +00002316 vclient->path);
paul718e3742002-12-13 20:15:29 +00002317 exit (1);
2318 }
2319
paul718e3742002-12-13 20:15:29 +00002320 }
2321
2322 sock = socket (AF_UNIX, SOCK_STREAM, 0);
2323 if (sock < 0)
2324 {
2325#ifdef DEBUG
ajsb1aa1472005-01-28 21:11:46 +00002326 fprintf(stderr, "vtysh_connect(%s): socket = %s\n", vclient->path,
ajs6099b3b2004-11-20 02:06:59 +00002327 safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002328#endif /* DEBUG */
2329 return -1;
2330 }
2331
2332 memset (&addr, 0, sizeof (struct sockaddr_un));
2333 addr.sun_family = AF_UNIX;
ajsb1aa1472005-01-28 21:11:46 +00002334 strncpy (addr.sun_path, vclient->path, strlen (vclient->path));
Paul Jakma6f0e3f62007-05-10 02:38:51 +00002335#ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
paul718e3742002-12-13 20:15:29 +00002336 len = addr.sun_len = SUN_LEN(&addr);
2337#else
2338 len = sizeof (addr.sun_family) + strlen (addr.sun_path);
Paul Jakma6f0e3f62007-05-10 02:38:51 +00002339#endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
paul718e3742002-12-13 20:15:29 +00002340
2341 ret = connect (sock, (struct sockaddr *) &addr, len);
2342 if (ret < 0)
2343 {
2344#ifdef DEBUG
ajsb1aa1472005-01-28 21:11:46 +00002345 fprintf(stderr, "vtysh_connect(%s): connect = %s\n", vclient->path,
ajs6099b3b2004-11-20 02:06:59 +00002346 safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002347#endif /* DEBUG */
2348 close (sock);
2349 return -1;
2350 }
2351 vclient->fd = sock;
2352
2353 return 0;
2354}
2355
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002356int
2357vtysh_connect_all(const char *daemon_name)
paul718e3742002-12-13 20:15:29 +00002358{
ajsb1aa1472005-01-28 21:11:46 +00002359 u_int i;
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002360 int rc = 0;
2361 int matches = 0;
ajsb1aa1472005-01-28 21:11:46 +00002362
Balaji.G837d16c2012-09-26 14:09:10 +05302363 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00002364 {
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002365 if (!daemon_name || !strcmp(daemon_name, vtysh_client[i].name))
2366 {
2367 matches++;
2368 if (vtysh_connect(&vtysh_client[i]) == 0)
2369 rc++;
2370 /* We need direct access to ripd in vtysh_exit_ripd_only. */
2371 if (vtysh_client[i].flag == VTYSH_RIPD)
2372 ripd_client = &vtysh_client[i];
2373 }
ajsb1aa1472005-01-28 21:11:46 +00002374 }
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002375 if (!matches)
2376 fprintf(stderr, "Error: no daemons match name %s!\n", daemon_name);
2377 return rc;
paul718e3742002-12-13 20:15:29 +00002378}
2379
hasso95e735b2004-08-26 13:08:30 +00002380/* To disable readline's filename completion. */
ajs274a4a42004-12-07 15:39:31 +00002381static char *
pauldfc0d9b2003-04-18 23:55:29 +00002382vtysh_completion_entry_function (const char *ignore, int invoking_key)
paul718e3742002-12-13 20:15:29 +00002383{
pauldfc0d9b2003-04-18 23:55:29 +00002384 return NULL;
paul718e3742002-12-13 20:15:29 +00002385}
2386
2387void
ajsb1aa1472005-01-28 21:11:46 +00002388vtysh_readline_init (void)
paul718e3742002-12-13 20:15:29 +00002389{
2390 /* readline related settings. */
SĂ©bastien Luttringer66d2ead2014-05-27 19:55:11 +02002391 rl_bind_key ('?', (rl_command_func_t *) vtysh_rl_describe);
paul68980082003-03-25 05:07:42 +00002392 rl_completion_entry_function = vtysh_completion_entry_function;
SĂ©bastien Luttringer66d2ead2014-05-27 19:55:11 +02002393 rl_attempted_completion_function = (rl_completion_func_t *)new_completion;
paul718e3742002-12-13 20:15:29 +00002394}
2395
2396char *
ajsb1aa1472005-01-28 21:11:46 +00002397vtysh_prompt (void)
paul718e3742002-12-13 20:15:29 +00002398{
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002399 static struct utsname names;
paul718e3742002-12-13 20:15:29 +00002400 static char buf[100];
2401 const char*hostname;
2402 extern struct host host;
2403
2404 hostname = host.name;
2405
2406 if (!hostname)
2407 {
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002408 if (!names.nodename[0])
2409 uname (&names);
paul718e3742002-12-13 20:15:29 +00002410 hostname = names.nodename;
2411 }
2412
2413 snprintf (buf, sizeof buf, cmd_prompt (vty->node), hostname);
2414
2415 return buf;
2416}
2417
2418void
ajsb1aa1472005-01-28 21:11:46 +00002419vtysh_init_vty (void)
paul718e3742002-12-13 20:15:29 +00002420{
2421 /* Make vty structure. */
2422 vty = vty_new ();
2423 vty->type = VTY_SHELL;
2424 vty->node = VIEW_NODE;
2425
2426 /* Initialize commands. */
2427 cmd_init (0);
2428
2429 /* Install nodes. */
2430 install_node (&bgp_node, NULL);
2431 install_node (&rip_node, NULL);
2432 install_node (&interface_node, NULL);
Olivier Dugeonac10d302016-04-19 18:33:42 +02002433 install_node (&link_params_node, NULL);
paul718e3742002-12-13 20:15:29 +00002434 install_node (&rmap_node, NULL);
2435 install_node (&zebra_node, NULL);
2436 install_node (&bgp_vpnv4_node, NULL);
Lou Berger13c378d2016-01-12 13:41:56 -05002437 install_node (&bgp_vpnv6_node, NULL);
Lou Bergera3fda882016-01-12 13:42:04 -05002438 install_node (&bgp_encap_node, NULL);
2439 install_node (&bgp_encapv6_node, NULL);
paul718e3742002-12-13 20:15:29 +00002440 install_node (&bgp_ipv4_node, NULL);
2441 install_node (&bgp_ipv4m_node, NULL);
2442/* #ifdef HAVE_IPV6 */
2443 install_node (&bgp_ipv6_node, NULL);
paul57b5b7e2005-08-22 22:44:29 +00002444 install_node (&bgp_ipv6m_node, NULL);
paul718e3742002-12-13 20:15:29 +00002445/* #endif */
2446 install_node (&ospf_node, NULL);
2447/* #ifdef HAVE_IPV6 */
2448 install_node (&ripng_node, NULL);
2449 install_node (&ospf6_node, NULL);
2450/* #endif */
David Lamparteree53c8b2015-05-23 05:45:59 +02002451 install_node (&babel_node, NULL);
paul718e3742002-12-13 20:15:29 +00002452 install_node (&keychain_node, NULL);
2453 install_node (&keychain_key_node, NULL);
hassoc25e4582003-12-23 10:39:08 +00002454 install_node (&isis_node, NULL);
hassoe7168df2004-10-03 20:11:32 +00002455 install_node (&vty_node, NULL);
paul718e3742002-12-13 20:15:29 +00002456
2457 vtysh_install_default (VIEW_NODE);
2458 vtysh_install_default (ENABLE_NODE);
2459 vtysh_install_default (CONFIG_NODE);
2460 vtysh_install_default (BGP_NODE);
2461 vtysh_install_default (RIP_NODE);
2462 vtysh_install_default (INTERFACE_NODE);
Olivier Dugeonac10d302016-04-19 18:33:42 +02002463 vtysh_install_default (LINK_PARAMS_NODE);
paul718e3742002-12-13 20:15:29 +00002464 vtysh_install_default (RMAP_NODE);
2465 vtysh_install_default (ZEBRA_NODE);
2466 vtysh_install_default (BGP_VPNV4_NODE);
Lou Berger13c378d2016-01-12 13:41:56 -05002467 vtysh_install_default (BGP_VPNV6_NODE);
Lou Bergera3fda882016-01-12 13:42:04 -05002468 vtysh_install_default (BGP_ENCAP_NODE);
2469 vtysh_install_default (BGP_ENCAPV6_NODE);
paul718e3742002-12-13 20:15:29 +00002470 vtysh_install_default (BGP_IPV4_NODE);
2471 vtysh_install_default (BGP_IPV4M_NODE);
2472 vtysh_install_default (BGP_IPV6_NODE);
paul57b5b7e2005-08-22 22:44:29 +00002473 vtysh_install_default (BGP_IPV6M_NODE);
paul718e3742002-12-13 20:15:29 +00002474 vtysh_install_default (OSPF_NODE);
2475 vtysh_install_default (RIPNG_NODE);
2476 vtysh_install_default (OSPF6_NODE);
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +01002477 vtysh_install_default (BABEL_NODE);
hassoc25e4582003-12-23 10:39:08 +00002478 vtysh_install_default (ISIS_NODE);
paul718e3742002-12-13 20:15:29 +00002479 vtysh_install_default (KEYCHAIN_NODE);
2480 vtysh_install_default (KEYCHAIN_KEY_NODE);
hassoe7168df2004-10-03 20:11:32 +00002481 vtysh_install_default (VTY_NODE);
paul718e3742002-12-13 20:15:29 +00002482
2483 install_element (VIEW_NODE, &vtysh_enable_cmd);
2484 install_element (ENABLE_NODE, &vtysh_config_terminal_cmd);
2485 install_element (ENABLE_NODE, &vtysh_disable_cmd);
2486
2487 /* "exit" command. */
2488 install_element (VIEW_NODE, &vtysh_exit_all_cmd);
2489 install_element (VIEW_NODE, &vtysh_quit_all_cmd);
2490 install_element (CONFIG_NODE, &vtysh_exit_all_cmd);
2491 /* install_element (CONFIG_NODE, &vtysh_quit_all_cmd); */
2492 install_element (ENABLE_NODE, &vtysh_exit_all_cmd);
2493 install_element (ENABLE_NODE, &vtysh_quit_all_cmd);
2494 install_element (RIP_NODE, &vtysh_exit_ripd_cmd);
2495 install_element (RIP_NODE, &vtysh_quit_ripd_cmd);
paul68980082003-03-25 05:07:42 +00002496 install_element (RIPNG_NODE, &vtysh_exit_ripngd_cmd);
2497 install_element (RIPNG_NODE, &vtysh_quit_ripngd_cmd);
paul718e3742002-12-13 20:15:29 +00002498 install_element (OSPF_NODE, &vtysh_exit_ospfd_cmd);
2499 install_element (OSPF_NODE, &vtysh_quit_ospfd_cmd);
paul68980082003-03-25 05:07:42 +00002500 install_element (OSPF6_NODE, &vtysh_exit_ospf6d_cmd);
2501 install_element (OSPF6_NODE, &vtysh_quit_ospf6d_cmd);
paul718e3742002-12-13 20:15:29 +00002502 install_element (BGP_NODE, &vtysh_exit_bgpd_cmd);
2503 install_element (BGP_NODE, &vtysh_quit_bgpd_cmd);
2504 install_element (BGP_VPNV4_NODE, &vtysh_exit_bgpd_cmd);
2505 install_element (BGP_VPNV4_NODE, &vtysh_quit_bgpd_cmd);
Lou Berger13c378d2016-01-12 13:41:56 -05002506 install_element (BGP_VPNV6_NODE, &vtysh_exit_bgpd_cmd);
2507 install_element (BGP_VPNV6_NODE, &vtysh_quit_bgpd_cmd);
Lou Bergera3fda882016-01-12 13:42:04 -05002508 install_element (BGP_ENCAP_NODE, &vtysh_exit_bgpd_cmd);
2509 install_element (BGP_ENCAP_NODE, &vtysh_quit_bgpd_cmd);
2510 install_element (BGP_ENCAPV6_NODE, &vtysh_exit_bgpd_cmd);
2511 install_element (BGP_ENCAPV6_NODE, &vtysh_quit_bgpd_cmd);
paul718e3742002-12-13 20:15:29 +00002512 install_element (BGP_IPV4_NODE, &vtysh_exit_bgpd_cmd);
2513 install_element (BGP_IPV4_NODE, &vtysh_quit_bgpd_cmd);
2514 install_element (BGP_IPV4M_NODE, &vtysh_exit_bgpd_cmd);
2515 install_element (BGP_IPV4M_NODE, &vtysh_quit_bgpd_cmd);
2516 install_element (BGP_IPV6_NODE, &vtysh_exit_bgpd_cmd);
2517 install_element (BGP_IPV6_NODE, &vtysh_quit_bgpd_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002518 install_element (BGP_IPV6M_NODE, &vtysh_exit_bgpd_cmd);
2519 install_element (BGP_IPV6M_NODE, &vtysh_quit_bgpd_cmd);
hassoc25e4582003-12-23 10:39:08 +00002520 install_element (ISIS_NODE, &vtysh_exit_isisd_cmd);
2521 install_element (ISIS_NODE, &vtysh_quit_isisd_cmd);
paul718e3742002-12-13 20:15:29 +00002522 install_element (KEYCHAIN_NODE, &vtysh_exit_ripd_cmd);
2523 install_element (KEYCHAIN_NODE, &vtysh_quit_ripd_cmd);
2524 install_element (KEYCHAIN_KEY_NODE, &vtysh_exit_ripd_cmd);
2525 install_element (KEYCHAIN_KEY_NODE, &vtysh_quit_ripd_cmd);
2526 install_element (RMAP_NODE, &vtysh_exit_rmap_cmd);
2527 install_element (RMAP_NODE, &vtysh_quit_rmap_cmd);
hassoe7168df2004-10-03 20:11:32 +00002528 install_element (VTY_NODE, &vtysh_exit_line_vty_cmd);
2529 install_element (VTY_NODE, &vtysh_quit_line_vty_cmd);
paul718e3742002-12-13 20:15:29 +00002530
2531 /* "end" command. */
2532 install_element (CONFIG_NODE, &vtysh_end_all_cmd);
2533 install_element (ENABLE_NODE, &vtysh_end_all_cmd);
2534 install_element (RIP_NODE, &vtysh_end_all_cmd);
2535 install_element (RIPNG_NODE, &vtysh_end_all_cmd);
2536 install_element (OSPF_NODE, &vtysh_end_all_cmd);
2537 install_element (OSPF6_NODE, &vtysh_end_all_cmd);
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +01002538 install_element (BABEL_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002539 install_element (BGP_NODE, &vtysh_end_all_cmd);
2540 install_element (BGP_IPV4_NODE, &vtysh_end_all_cmd);
2541 install_element (BGP_IPV4M_NODE, &vtysh_end_all_cmd);
2542 install_element (BGP_VPNV4_NODE, &vtysh_end_all_cmd);
Lou Berger13c378d2016-01-12 13:41:56 -05002543 install_element (BGP_VPNV6_NODE, &vtysh_end_all_cmd);
Lou Bergera3fda882016-01-12 13:42:04 -05002544 install_element (BGP_ENCAP_NODE, &vtysh_end_all_cmd);
2545 install_element (BGP_ENCAPV6_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002546 install_element (BGP_IPV6_NODE, &vtysh_end_all_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002547 install_element (BGP_IPV6M_NODE, &vtysh_end_all_cmd);
hassoc25e4582003-12-23 10:39:08 +00002548 install_element (ISIS_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002549 install_element (KEYCHAIN_NODE, &vtysh_end_all_cmd);
2550 install_element (KEYCHAIN_KEY_NODE, &vtysh_end_all_cmd);
2551 install_element (RMAP_NODE, &vtysh_end_all_cmd);
hassoe7168df2004-10-03 20:11:32 +00002552 install_element (VTY_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002553
paul338a9912003-03-01 15:44:10 +00002554 install_element (INTERFACE_NODE, &interface_desc_cmd);
paul464dc8d2003-03-28 02:25:45 +00002555 install_element (INTERFACE_NODE, &no_interface_desc_cmd);
paul718e3742002-12-13 20:15:29 +00002556 install_element (INTERFACE_NODE, &vtysh_end_all_cmd);
2557 install_element (INTERFACE_NODE, &vtysh_exit_interface_cmd);
Donald Sharp2c0adbf2016-11-18 15:42:41 -05002558 install_element (LINK_PARAMS_NODE, &exit_link_params_cmd);
Olivier Dugeonac10d302016-04-19 18:33:42 +02002559 install_element (LINK_PARAMS_NODE, &vtysh_end_all_cmd);
2560 install_element (LINK_PARAMS_NODE, &vtysh_exit_interface_cmd);
paul718e3742002-12-13 20:15:29 +00002561 install_element (INTERFACE_NODE, &vtysh_quit_interface_cmd);
2562 install_element (CONFIG_NODE, &router_rip_cmd);
2563#ifdef HAVE_IPV6
2564 install_element (CONFIG_NODE, &router_ripng_cmd);
2565#endif
2566 install_element (CONFIG_NODE, &router_ospf_cmd);
2567#ifdef HAVE_IPV6
2568 install_element (CONFIG_NODE, &router_ospf6_cmd);
2569#endif
hassoc25e4582003-12-23 10:39:08 +00002570 install_element (CONFIG_NODE, &router_isis_cmd);
paul718e3742002-12-13 20:15:29 +00002571 install_element (CONFIG_NODE, &router_bgp_cmd);
Paul Jakma10895fd2008-07-03 19:34:48 +00002572 install_element (CONFIG_NODE, &router_bgp_view_cmd);
paul718e3742002-12-13 20:15:29 +00002573 install_element (BGP_NODE, &address_family_vpnv4_cmd);
2574 install_element (BGP_NODE, &address_family_vpnv4_unicast_cmd);
Lou Berger13c378d2016-01-12 13:41:56 -05002575 install_element (BGP_NODE, &address_family_vpnv6_cmd);
2576 install_element (BGP_NODE, &address_family_vpnv6_unicast_cmd);
Lou Bergera3fda882016-01-12 13:42:04 -05002577 install_element (BGP_NODE, &address_family_encap_cmd);
2578 install_element (BGP_NODE, &address_family_encapv6_cmd);
paul718e3742002-12-13 20:15:29 +00002579 install_element (BGP_NODE, &address_family_ipv4_unicast_cmd);
2580 install_element (BGP_NODE, &address_family_ipv4_multicast_cmd);
2581#ifdef HAVE_IPV6
2582 install_element (BGP_NODE, &address_family_ipv6_cmd);
2583 install_element (BGP_NODE, &address_family_ipv6_unicast_cmd);
viveka4f40292015-11-09 20:21:46 -05002584 install_element (BGP_NODE, &address_family_ipv6_multicast_cmd);
paul718e3742002-12-13 20:15:29 +00002585#endif
2586 install_element (BGP_VPNV4_NODE, &exit_address_family_cmd);
Lou Berger13c378d2016-01-12 13:41:56 -05002587 install_element (BGP_VPNV6_NODE, &exit_address_family_cmd);
Lou Bergera3fda882016-01-12 13:42:04 -05002588 install_element (BGP_ENCAP_NODE, &exit_address_family_cmd);
2589 install_element (BGP_ENCAPV6_NODE, &exit_address_family_cmd);
paul718e3742002-12-13 20:15:29 +00002590 install_element (BGP_IPV4_NODE, &exit_address_family_cmd);
2591 install_element (BGP_IPV4M_NODE, &exit_address_family_cmd);
2592 install_element (BGP_IPV6_NODE, &exit_address_family_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002593 install_element (BGP_IPV6M_NODE, &exit_address_family_cmd);
paul718e3742002-12-13 20:15:29 +00002594 install_element (CONFIG_NODE, &key_chain_cmd);
2595 install_element (CONFIG_NODE, &route_map_cmd);
hassoe7168df2004-10-03 20:11:32 +00002596 install_element (CONFIG_NODE, &vtysh_line_vty_cmd);
paul718e3742002-12-13 20:15:29 +00002597 install_element (KEYCHAIN_NODE, &key_cmd);
2598 install_element (KEYCHAIN_NODE, &key_chain_cmd);
2599 install_element (KEYCHAIN_KEY_NODE, &key_chain_cmd);
2600 install_element (CONFIG_NODE, &vtysh_interface_cmd);
paul32d24632003-05-23 09:25:20 +00002601 install_element (CONFIG_NODE, &vtysh_no_interface_cmd);
Feng Lu471ea392015-05-22 11:40:00 +02002602 install_element (CONFIG_NODE, &vtysh_interface_vrf_cmd);
2603 install_element (CONFIG_NODE, &vtysh_no_interface_vrf_cmd);
Olivier Dugeonac10d302016-04-19 18:33:42 +02002604 install_element (INTERFACE_NODE, &vtysh_link_params_cmd);
paul718e3742002-12-13 20:15:29 +00002605 install_element (ENABLE_NODE, &vtysh_show_running_config_cmd);
Donald Sharp9fb73e82015-09-22 11:13:12 -04002606 install_element (ENABLE_NODE, &vtysh_show_running_config_daemon_cmd);
paul718e3742002-12-13 20:15:29 +00002607 install_element (ENABLE_NODE, &vtysh_copy_runningconfig_startupconfig_cmd);
2608 install_element (ENABLE_NODE, &vtysh_write_file_cmd);
hasso4a6e2252003-05-25 11:51:29 +00002609 install_element (ENABLE_NODE, &vtysh_write_cmd);
paul718e3742002-12-13 20:15:29 +00002610
hasso95e735b2004-08-26 13:08:30 +00002611 /* "write terminal" command. */
paul718e3742002-12-13 20:15:29 +00002612 install_element (ENABLE_NODE, &vtysh_write_terminal_cmd);
Donald Sharp9fb73e82015-09-22 11:13:12 -04002613 install_element (ENABLE_NODE, &vtysh_write_terminal_daemon_cmd);
Donald Sharp07440402016-02-25 07:39:45 -05002614
hassoe7168df2004-10-03 20:11:32 +00002615 install_element (CONFIG_NODE, &vtysh_integrated_config_cmd);
2616 install_element (CONFIG_NODE, &no_vtysh_integrated_config_cmd);
paul718e3742002-12-13 20:15:29 +00002617
hasso95e735b2004-08-26 13:08:30 +00002618 /* "write memory" command. */
paul718e3742002-12-13 20:15:29 +00002619 install_element (ENABLE_NODE, &vtysh_write_memory_cmd);
paul718e3742002-12-13 20:15:29 +00002620
hasso34553cc2004-08-27 13:56:39 +00002621 install_element (VIEW_NODE, &vtysh_terminal_length_cmd);
2622 install_element (ENABLE_NODE, &vtysh_terminal_length_cmd);
2623 install_element (VIEW_NODE, &vtysh_terminal_no_length_cmd);
2624 install_element (ENABLE_NODE, &vtysh_terminal_no_length_cmd);
hassof2799e62004-10-28 17:43:11 +00002625 install_element (VIEW_NODE, &vtysh_show_daemons_cmd);
2626 install_element (ENABLE_NODE, &vtysh_show_daemons_cmd);
hasso34553cc2004-08-27 13:56:39 +00002627
paul718e3742002-12-13 20:15:29 +00002628 install_element (VIEW_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002629 install_element (VIEW_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00002630 install_element (VIEW_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002631 install_element (VIEW_NODE, &vtysh_traceroute_ip_cmd);
2632#ifdef HAVE_IPV6
2633 install_element (VIEW_NODE, &vtysh_ping6_cmd);
2634 install_element (VIEW_NODE, &vtysh_traceroute6_cmd);
2635#endif
paul718e3742002-12-13 20:15:29 +00002636 install_element (VIEW_NODE, &vtysh_telnet_cmd);
2637 install_element (VIEW_NODE, &vtysh_telnet_port_cmd);
paul5087df52003-01-25 06:56:09 +00002638 install_element (VIEW_NODE, &vtysh_ssh_cmd);
paul718e3742002-12-13 20:15:29 +00002639 install_element (ENABLE_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002640 install_element (ENABLE_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00002641 install_element (ENABLE_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002642 install_element (ENABLE_NODE, &vtysh_traceroute_ip_cmd);
2643#ifdef HAVE_IPV6
2644 install_element (ENABLE_NODE, &vtysh_ping6_cmd);
2645 install_element (ENABLE_NODE, &vtysh_traceroute6_cmd);
2646#endif
paul718e3742002-12-13 20:15:29 +00002647 install_element (ENABLE_NODE, &vtysh_telnet_cmd);
2648 install_element (ENABLE_NODE, &vtysh_telnet_port_cmd);
hasso67e29ab2004-08-26 22:21:31 +00002649 install_element (ENABLE_NODE, &vtysh_ssh_cmd);
paul718e3742002-12-13 20:15:29 +00002650 install_element (ENABLE_NODE, &vtysh_start_shell_cmd);
2651 install_element (ENABLE_NODE, &vtysh_start_bash_cmd);
2652 install_element (ENABLE_NODE, &vtysh_start_zsh_cmd);
Paul Jakmadbf7d132006-05-23 22:10:01 +00002653
Paul Jakma362b4032006-05-28 07:54:45 +00002654 install_element (VIEW_NODE, &vtysh_show_memory_cmd);
2655 install_element (ENABLE_NODE, &vtysh_show_memory_cmd);
2656
Donald Sharp567a6382015-08-19 21:22:17 -04002657 install_element (VIEW_NODE, &vtysh_show_work_queues_cmd);
2658 install_element (ENABLE_NODE, &vtysh_show_work_queues_cmd);
Donald Sharp07440402016-02-25 07:39:45 -05002659 install_element (ENABLE_NODE, &vtysh_show_work_queues_daemon_cmd);
2660 install_element (VIEW_NODE, &vtysh_show_work_queues_daemon_cmd);
Donald Sharp567a6382015-08-19 21:22:17 -04002661
2662 install_element (VIEW_NODE, &vtysh_show_thread_cmd);
2663 install_element (ENABLE_NODE, &vtysh_show_thread_cmd);
2664
Paul Jakmadbf7d132006-05-23 22:10:01 +00002665 /* Logging */
2666 install_element (ENABLE_NODE, &vtysh_show_logging_cmd);
2667 install_element (VIEW_NODE, &vtysh_show_logging_cmd);
paul718e3742002-12-13 20:15:29 +00002668 install_element (CONFIG_NODE, &vtysh_log_stdout_cmd);
ajs274a4a42004-12-07 15:39:31 +00002669 install_element (CONFIG_NODE, &vtysh_log_stdout_level_cmd);
paul718e3742002-12-13 20:15:29 +00002670 install_element (CONFIG_NODE, &no_vtysh_log_stdout_cmd);
2671 install_element (CONFIG_NODE, &vtysh_log_file_cmd);
ajs274a4a42004-12-07 15:39:31 +00002672 install_element (CONFIG_NODE, &vtysh_log_file_level_cmd);
paul718e3742002-12-13 20:15:29 +00002673 install_element (CONFIG_NODE, &no_vtysh_log_file_cmd);
ajs274a4a42004-12-07 15:39:31 +00002674 install_element (CONFIG_NODE, &no_vtysh_log_file_level_cmd);
2675 install_element (CONFIG_NODE, &vtysh_log_monitor_cmd);
2676 install_element (CONFIG_NODE, &vtysh_log_monitor_level_cmd);
2677 install_element (CONFIG_NODE, &no_vtysh_log_monitor_cmd);
paul718e3742002-12-13 20:15:29 +00002678 install_element (CONFIG_NODE, &vtysh_log_syslog_cmd);
ajs274a4a42004-12-07 15:39:31 +00002679 install_element (CONFIG_NODE, &vtysh_log_syslog_level_cmd);
paul718e3742002-12-13 20:15:29 +00002680 install_element (CONFIG_NODE, &no_vtysh_log_syslog_cmd);
2681 install_element (CONFIG_NODE, &vtysh_log_trap_cmd);
2682 install_element (CONFIG_NODE, &no_vtysh_log_trap_cmd);
ajs274a4a42004-12-07 15:39:31 +00002683 install_element (CONFIG_NODE, &vtysh_log_facility_cmd);
2684 install_element (CONFIG_NODE, &no_vtysh_log_facility_cmd);
paul718e3742002-12-13 20:15:29 +00002685 install_element (CONFIG_NODE, &vtysh_log_record_priority_cmd);
2686 install_element (CONFIG_NODE, &no_vtysh_log_record_priority_cmd);
Andrew J. Schorrc749b722007-04-29 03:53:31 +00002687 install_element (CONFIG_NODE, &vtysh_log_timestamp_precision_cmd);
2688 install_element (CONFIG_NODE, &no_vtysh_log_timestamp_precision_cmd);
hassoe7168df2004-10-03 20:11:32 +00002689
2690 install_element (CONFIG_NODE, &vtysh_service_password_encrypt_cmd);
2691 install_element (CONFIG_NODE, &no_vtysh_service_password_encrypt_cmd);
2692
2693 install_element (CONFIG_NODE, &vtysh_password_cmd);
2694 install_element (CONFIG_NODE, &vtysh_password_text_cmd);
2695 install_element (CONFIG_NODE, &vtysh_enable_password_cmd);
2696 install_element (CONFIG_NODE, &vtysh_enable_password_text_cmd);
2697 install_element (CONFIG_NODE, &no_vtysh_enable_password_cmd);
2698
paul718e3742002-12-13 20:15:29 +00002699}