blob: d0cc2ebb5205d5b2e0e0d820ec91b4dfcc0e26b0 [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},
ajsb1aa1472005-01-28 21:11:46 +000063};
64
ajsb1aa1472005-01-28 21:11:46 +000065
66/* We need direct access to ripd to implement vtysh_exit_ripd_only. */
67static struct vtysh_client *ripd_client = NULL;
68
hassob094d262004-08-25 12:22:00 +000069
hassoe7168df2004-10-03 20:11:32 +000070/* Using integrated config from Quagga.conf. Default is no. */
71int vtysh_writeconfig_integrated = 0;
72
73extern char config_default[];
74
ajs274a4a42004-12-07 15:39:31 +000075static void
paul718e3742002-12-13 20:15:29 +000076vclient_close (struct vtysh_client *vclient)
77{
ajsb1aa1472005-01-28 21:11:46 +000078 if (vclient->fd >= 0)
79 {
80 fprintf(stderr,
81 "Warning: closing connection to %s because of an I/O error!\n",
82 vclient->name);
83 close (vclient->fd);
84 vclient->fd = -1;
85 }
paul718e3742002-12-13 20:15:29 +000086}
87
Donald Sharp07440402016-02-25 07:39:45 -050088/* Return true if str begins with prefix, else return false */
89static int
90begins_with(const char *str, const char *prefix)
91{
92 if (!str || !prefix)
93 return 0;
94 size_t lenstr = strlen(str);
95 size_t lenprefix = strlen(prefix);
96 if (lenprefix > lenstr)
97 return 0;
98 return strncmp(str, prefix, lenprefix) == 0;
99}
100
paul718e3742002-12-13 20:15:29 +0000101/* Following filled with debug code to trace a problematic condition
hasso95e735b2004-08-26 13:08:30 +0000102 * under load - it SHOULD handle it. */
Gautam Kumarcc216b72015-10-26 13:22:12 -0700103#define ERR_WHERE_STRING "vtysh(): vtysh_client_execute(): "
ajs274a4a42004-12-07 15:39:31 +0000104static int
Gautam Kumarcc216b72015-10-26 13:22:12 -0700105vtysh_client_execute (struct vtysh_client *vclient, const char *line, FILE *fp)
paul718e3742002-12-13 20:15:29 +0000106{
107 int ret;
108 char *buf;
109 size_t bufsz;
110 char *pbuf;
111 size_t left;
112 char *eoln;
113 int nbytes;
114 int i;
115 int readln;
Gautam Kumarcc216b72015-10-26 13:22:12 -0700116 int numnulls = 0;
paul718e3742002-12-13 20:15:29 +0000117
118 if (vclient->fd < 0)
119 return CMD_SUCCESS;
120
121 ret = write (vclient->fd, line, strlen (line) + 1);
122 if (ret <= 0)
123 {
124 vclient_close (vclient);
125 return CMD_SUCCESS;
126 }
127
hasso95e735b2004-08-26 13:08:30 +0000128 /* Allow enough room for buffer to read more than a few pages from socket. */
paule3d29b52003-01-23 18:05:42 +0000129 bufsz = 5 * getpagesize() + 1;
paul718e3742002-12-13 20:15:29 +0000130 buf = XMALLOC(MTYPE_TMP, bufsz);
131 memset(buf, 0, bufsz);
132 pbuf = buf;
133
134 while (1)
135 {
136 if (pbuf >= ((buf + bufsz) -1))
137 {
138 fprintf (stderr, ERR_WHERE_STRING \
139 "warning - pbuf beyond buffer end.\n");
Christian Franke99f56722016-06-14 20:07:10 +0200140 XFREE(MTYPE_TMP, buf);
paul718e3742002-12-13 20:15:29 +0000141 return CMD_WARNING;
142 }
143
144 readln = (buf + bufsz) - pbuf - 1;
145 nbytes = read (vclient->fd, pbuf, readln);
146
147 if (nbytes <= 0)
148 {
149
150 if (errno == EINTR)
151 continue;
152
153 fprintf(stderr, ERR_WHERE_STRING "(%u)", errno);
154 perror("");
155
156 if (errno == EAGAIN || errno == EIO)
157 continue;
158
159 vclient_close (vclient);
160 XFREE(MTYPE_TMP, buf);
161 return CMD_SUCCESS;
162 }
Gautam Kumarcc216b72015-10-26 13:22:12 -0700163 /* If we have already seen 3 nulls, then current byte is ret code */
164 if ((numnulls == 3) && (nbytes == 1))
165 {
166 ret = pbuf[0];
167 break;
168 }
paul718e3742002-12-13 20:15:29 +0000169
170 pbuf[nbytes] = '\0';
171
Gautam Kumarcc216b72015-10-26 13:22:12 -0700172 /* If the config needs to be written in file or stdout */
173 if (fp)
174 {
175 fputs(pbuf, fp);
176 fflush (fp);
177 }
paul718e3742002-12-13 20:15:29 +0000178
Gautam Kumarcc216b72015-10-26 13:22:12 -0700179 /* At max look last four bytes */
180 if (nbytes >= 4)
181 {
182 i = nbytes - 4;
183 numnulls = 0;
184 }
185 else
186 i = 0;
paul718e3742002-12-13 20:15:29 +0000187
Gautam Kumarcc216b72015-10-26 13:22:12 -0700188 /* Count the numnulls */
189 while (i < nbytes && numnulls <3)
190 {
191 if (pbuf[i++] == '\0')
192 numnulls++;
193 else
194 numnulls = 0;
195 }
196 /* We might have seen 3 consecutive nulls so store the ret code before updating pbuf*/
197 ret = pbuf[nbytes-1];
198 pbuf += nbytes;
paul718e3742002-12-13 20:15:29 +0000199
Gautam Kumarcc216b72015-10-26 13:22:12 -0700200 /* See if a line exists in buffer, if so parse and consume it, and
201 * reset read position. If 3 nulls has been encountered consume the buffer before
202 * next read.
203 */
204 if (((eoln = strrchr(buf, '\n')) == NULL) && (numnulls<3))
205 continue;
206
207 if (eoln >= ((buf + bufsz) - 1))
208 {
209 fprintf (stderr, ERR_WHERE_STRING \
210 "warning - eoln beyond buffer end.\n");
211 }
212
213 /* If the config needs parsing, consume it */
214 if(!fp)
215 vtysh_config_parse(buf);
216
217 eoln++;
218 left = (size_t)(buf + bufsz - eoln);
219 /*
220 * This check is required since when a config line split between two consecutive reads,
221 * then buf will have first half of config line and current read will bring rest of the
222 * line. So in this case eoln will be 1 here, hence calculation of left will be wrong.
223 * In this case we don't need to do memmove, because we have already seen 3 nulls.
224 */
225 if(left < bufsz)
226 memmove(buf, eoln, left);
227
228 buf[bufsz-1] = '\0';
229 pbuf = buf + strlen(buf);
230 /* got 3 or more trailing NULs? */
231 if ((numnulls >=3) && (i < nbytes))
232 {
233 break;
234 }
paul718e3742002-12-13 20:15:29 +0000235 }
236
Gautam Kumarcc216b72015-10-26 13:22:12 -0700237 if(!fp)
238 vtysh_config_parse (buf);
paul718e3742002-12-13 20:15:29 +0000239
240 XFREE(MTYPE_TMP, buf);
241 return ret;
242}
Gautam Kumarcc216b72015-10-26 13:22:12 -0700243
paul718e3742002-12-13 20:15:29 +0000244
paul718e3742002-12-13 20:15:29 +0000245void
ajsb1aa1472005-01-28 21:11:46 +0000246vtysh_pager_init (void)
paul718e3742002-12-13 20:15:29 +0000247{
hasso5a9c53d2004-08-27 14:23:28 +0000248 char *pager_defined;
249
250 pager_defined = getenv ("VTYSH_PAGER");
251
252 if (pager_defined)
253 vtysh_pager_name = strdup (pager_defined);
254 else
hasso34553cc2004-08-27 13:56:39 +0000255 vtysh_pager_name = strdup ("more");
paul718e3742002-12-13 20:15:29 +0000256}
257
258/* Command execution over the vty interface. */
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700259static int
hassodda09522004-10-07 21:40:25 +0000260vtysh_execute_func (const char *line, int pager)
paul718e3742002-12-13 20:15:29 +0000261{
Stephen Hemminger2c4d48b2008-07-28 15:04:56 -0700262 int ret, cmd_stat;
ajsb1aa1472005-01-28 21:11:46 +0000263 u_int i;
paul718e3742002-12-13 20:15:29 +0000264 vector vline;
265 struct cmd_element *cmd;
266 FILE *fp = NULL;
hasso13bfca72005-01-23 21:42:25 +0000267 int closepager = 0;
268 int tried = 0;
269 int saved_ret, saved_node;
paul718e3742002-12-13 20:15:29 +0000270
hasso95e735b2004-08-26 13:08:30 +0000271 /* Split readline string up into the vector. */
paul718e3742002-12-13 20:15:29 +0000272 vline = cmd_make_strvec (line);
273
274 if (vline == NULL)
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700275 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000276
hasso13bfca72005-01-23 21:42:25 +0000277 saved_ret = ret = cmd_execute_command (vline, vty, &cmd, 1);
278 saved_node = vty->node;
279
280 /* If command doesn't succeeded in current node, try to walk up in node tree.
281 * Changing vty->node is enough to try it just out without actual walkup in
282 * the vtysh. */
283 while (ret != CMD_SUCCESS && ret != CMD_SUCCESS_DAEMON && ret != CMD_WARNING
284 && vty->node > CONFIG_NODE)
285 {
286 vty->node = node_parent(vty->node);
287 ret = cmd_execute_command (vline, vty, &cmd, 1);
288 tried++;
289 }
290
291 vty->node = saved_node;
292
293 /* If command succeeded in any other node than current (tried > 0) we have
294 * to move into node in the vtysh where it succeeded. */
295 if (ret == CMD_SUCCESS || ret == CMD_SUCCESS_DAEMON || ret == CMD_WARNING)
296 {
Lou Berger82dd7072016-01-12 13:41:57 -0500297 if ((saved_node == BGP_VPNV4_NODE || saved_node == BGP_VPNV6_NODE
Lou Bergera3fda882016-01-12 13:42:04 -0500298 || saved_node == BGP_ENCAP_NODE || saved_node == BGP_ENCAPV6_NODE
Lou Berger13c378d2016-01-12 13:41:56 -0500299 || saved_node == BGP_IPV4_NODE
paul57b5b7e2005-08-22 22:44:29 +0000300 || saved_node == BGP_IPV6_NODE || saved_node == BGP_IPV4M_NODE
301 || saved_node == BGP_IPV6M_NODE)
hasso13bfca72005-01-23 21:42:25 +0000302 && (tried == 1))
303 {
304 vtysh_execute("exit-address-family");
305 }
306 else if ((saved_node == KEYCHAIN_KEY_NODE) && (tried == 1))
307 {
308 vtysh_execute("exit");
309 }
310 else if (tried)
311 {
312 vtysh_execute ("end");
313 vtysh_execute ("configure terminal");
314 }
315 }
316 /* If command didn't succeed in any node, continue with return value from
317 * first try. */
318 else if (tried)
319 {
320 ret = saved_ret;
321 }
paul718e3742002-12-13 20:15:29 +0000322
323 cmd_free_strvec (vline);
324
Stephen Hemminger2c4d48b2008-07-28 15:04:56 -0700325 cmd_stat = ret;
paul718e3742002-12-13 20:15:29 +0000326 switch (ret)
327 {
328 case CMD_WARNING:
329 if (vty->type == VTY_FILE)
paul4fc01e62002-12-13 20:49:00 +0000330 fprintf (stdout,"Warning...\n");
paul718e3742002-12-13 20:15:29 +0000331 break;
332 case CMD_ERR_AMBIGUOUS:
paul4fc01e62002-12-13 20:49:00 +0000333 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000334 break;
335 case CMD_ERR_NO_MATCH:
paul4fc01e62002-12-13 20:49:00 +0000336 fprintf (stdout,"%% Unknown command.\n");
paul718e3742002-12-13 20:15:29 +0000337 break;
338 case CMD_ERR_INCOMPLETE:
paul4fc01e62002-12-13 20:49:00 +0000339 fprintf (stdout,"%% Command incomplete.\n");
paul718e3742002-12-13 20:15:29 +0000340 break;
341 case CMD_SUCCESS_DAEMON:
342 {
hasso97b7db22004-10-20 19:07:48 +0000343 /* FIXME: Don't open pager for exit commands. popen() causes problems
344 * if exited from vtysh at all. This hack shouldn't cause any problem
345 * but is really ugly. */
346 if (pager && vtysh_pager_name && (strncmp(line, "exit", 4) != 0))
paul718e3742002-12-13 20:15:29 +0000347 {
paul4fc01e62002-12-13 20:49:00 +0000348 fp = popen (vtysh_pager_name, "w");
paul718e3742002-12-13 20:15:29 +0000349 if (fp == NULL)
350 {
paula805cc22003-05-01 14:29:48 +0000351 perror ("popen failed for pager");
352 fp = stdout;
paul718e3742002-12-13 20:15:29 +0000353 }
paula805cc22003-05-01 14:29:48 +0000354 else
355 closepager=1;
paul718e3742002-12-13 20:15:29 +0000356 }
357 else
358 fp = stdout;
359
360 if (! strcmp(cmd->string,"configure terminal"))
361 {
Balaji.G837d16c2012-09-26 14:09:10 +0530362 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +0000363 {
364 cmd_stat = vtysh_client_execute(&vtysh_client[i], line, fp);
365 if (cmd_stat == CMD_WARNING)
366 break;
367 }
368
paul718e3742002-12-13 20:15:29 +0000369 if (cmd_stat)
370 {
hassob094d262004-08-25 12:22:00 +0000371 line = "end";
372 vline = cmd_make_strvec (line);
paul718e3742002-12-13 20:15:29 +0000373
hassob094d262004-08-25 12:22:00 +0000374 if (vline == NULL)
paul718e3742002-12-13 20:15:29 +0000375 {
paula805cc22003-05-01 14:29:48 +0000376 if (pager && vtysh_pager_name && fp && closepager)
paul718e3742002-12-13 20:15:29 +0000377 {
378 if (pclose (fp) == -1)
379 {
paula805cc22003-05-01 14:29:48 +0000380 perror ("pclose failed for pager");
paul718e3742002-12-13 20:15:29 +0000381 }
382 fp = NULL;
383 }
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700384 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000385 }
386
hasso87d683b2005-01-16 23:31:54 +0000387 ret = cmd_execute_command (vline, vty, &cmd, 1);
hassob094d262004-08-25 12:22:00 +0000388 cmd_free_strvec (vline);
389 if (ret != CMD_SUCCESS_DAEMON)
390 break;
paul718e3742002-12-13 20:15:29 +0000391 }
392 else
393 if (cmd->func)
394 {
395 (*cmd->func) (cmd, vty, 0, NULL);
396 break;
hassob094d262004-08-25 12:22:00 +0000397 }
paul718e3742002-12-13 20:15:29 +0000398 }
399
ajsb1aa1472005-01-28 21:11:46 +0000400 cmd_stat = CMD_SUCCESS;
Balaji.G837d16c2012-09-26 14:09:10 +0530401 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +0000402 {
403 if (cmd->daemon & vtysh_client[i].flag)
404 {
405 cmd_stat = vtysh_client_execute(&vtysh_client[i], line, fp);
406 if (cmd_stat != CMD_SUCCESS)
407 break;
408 }
409 }
410 if (cmd_stat != CMD_SUCCESS)
411 break;
412
paul718e3742002-12-13 20:15:29 +0000413 if (cmd->func)
414 (*cmd->func) (cmd, vty, 0, NULL);
415 }
416 }
paula805cc22003-05-01 14:29:48 +0000417 if (pager && vtysh_pager_name && fp && closepager)
paul718e3742002-12-13 20:15:29 +0000418 {
419 if (pclose (fp) == -1)
420 {
paula805cc22003-05-01 14:29:48 +0000421 perror ("pclose failed for pager");
paul718e3742002-12-13 20:15:29 +0000422 }
423 fp = NULL;
424 }
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700425 return cmd_stat;
paul718e3742002-12-13 20:15:29 +0000426}
427
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700428int
hassodda09522004-10-07 21:40:25 +0000429vtysh_execute_no_pager (const char *line)
paul718e3742002-12-13 20:15:29 +0000430{
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700431 return vtysh_execute_func (line, 0);
paul718e3742002-12-13 20:15:29 +0000432}
433
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700434int
hassodda09522004-10-07 21:40:25 +0000435vtysh_execute (const char *line)
paul718e3742002-12-13 20:15:29 +0000436{
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700437 return vtysh_execute_func (line, 1);
paul718e3742002-12-13 20:15:29 +0000438}
439
440/* Configration make from file. */
441int
442vtysh_config_from_file (struct vty *vty, FILE *fp)
443{
444 int ret;
paul718e3742002-12-13 20:15:29 +0000445 struct cmd_element *cmd;
446
Quentin Youngb7ceefe2017-01-10 23:33:50 +0000447 while (fgets (vty->buf, vty->max, fp))
paul718e3742002-12-13 20:15:29 +0000448 {
Donald Sharpd8aa4be2015-09-28 20:10:40 -0400449 ret = command_config_read_one_line (vty, &cmd, 1);
paul718e3742002-12-13 20:15:29 +0000450
451 switch (ret)
452 {
453 case CMD_WARNING:
454 if (vty->type == VTY_FILE)
paul4fc01e62002-12-13 20:49:00 +0000455 fprintf (stdout,"Warning...\n");
paul718e3742002-12-13 20:15:29 +0000456 break;
457 case CMD_ERR_AMBIGUOUS:
paul4fc01e62002-12-13 20:49:00 +0000458 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000459 break;
460 case CMD_ERR_NO_MATCH:
paul4fc01e62002-12-13 20:49:00 +0000461 fprintf (stdout,"%% Unknown command: %s", vty->buf);
paul718e3742002-12-13 20:15:29 +0000462 break;
463 case CMD_ERR_INCOMPLETE:
paul4fc01e62002-12-13 20:49:00 +0000464 fprintf (stdout,"%% Command incomplete.\n");
paul718e3742002-12-13 20:15:29 +0000465 break;
466 case CMD_SUCCESS_DAEMON:
467 {
ajsb1aa1472005-01-28 21:11:46 +0000468 u_int i;
469 int cmd_stat = CMD_SUCCESS;
470
Balaji.G837d16c2012-09-26 14:09:10 +0530471 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +0000472 {
paul44316fe2006-01-11 01:38:25 +0000473 if (cmd->daemon & vtysh_client[i].flag)
ajsb1aa1472005-01-28 21:11:46 +0000474 {
475 cmd_stat = vtysh_client_execute (&vtysh_client[i],
476 vty->buf, stdout);
477 if (cmd_stat != CMD_SUCCESS)
478 break;
479 }
480 }
481 if (cmd_stat != CMD_SUCCESS)
482 break;
483
paul718e3742002-12-13 20:15:29 +0000484 if (cmd->func)
485 (*cmd->func) (cmd, vty, 0, NULL);
486 }
487 }
488 }
489 return CMD_SUCCESS;
490}
491
492/* We don't care about the point of the cursor when '?' is typed. */
David Lampartera9eb9062015-03-04 07:07:01 +0100493static int
ajsb1aa1472005-01-28 21:11:46 +0000494vtysh_rl_describe (void)
paul718e3742002-12-13 20:15:29 +0000495{
496 int ret;
hassodda09522004-10-07 21:40:25 +0000497 unsigned int i;
paul718e3742002-12-13 20:15:29 +0000498 vector vline;
499 vector describe;
500 int width;
Christian Frankecd40b322013-09-30 12:27:51 +0000501 struct cmd_token *token;
paul718e3742002-12-13 20:15:29 +0000502
503 vline = cmd_make_strvec (rl_line_buffer);
504
505 /* In case of '> ?'. */
506 if (vline == NULL)
507 {
508 vline = vector_init (1);
David Lampartera91a3ba2015-03-03 09:06:51 +0100509 vector_set (vline, NULL);
paul718e3742002-12-13 20:15:29 +0000510 }
511 else
512 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
David Lampartera91a3ba2015-03-03 09:06:51 +0100513 vector_set (vline, NULL);
paul718e3742002-12-13 20:15:29 +0000514
515 describe = cmd_describe_command (vline, vty, &ret);
516
paul4fc01e62002-12-13 20:49:00 +0000517 fprintf (stdout,"\n");
paul718e3742002-12-13 20:15:29 +0000518
519 /* Ambiguous and no match error. */
520 switch (ret)
521 {
522 case CMD_ERR_AMBIGUOUS:
523 cmd_free_strvec (vline);
paul4fc01e62002-12-13 20:49:00 +0000524 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000525 rl_on_new_line ();
526 return 0;
527 break;
528 case CMD_ERR_NO_MATCH:
529 cmd_free_strvec (vline);
paul4fc01e62002-12-13 20:49:00 +0000530 fprintf (stdout,"%% There is no matched command.\n");
paul718e3742002-12-13 20:15:29 +0000531 rl_on_new_line ();
532 return 0;
533 break;
534 }
535
536 /* Get width of command string. */
537 width = 0;
paul55468c82005-03-14 20:19:01 +0000538 for (i = 0; i < vector_active (describe); i++)
Christian Frankecd40b322013-09-30 12:27:51 +0000539 if ((token = vector_slot (describe, i)) != NULL)
paul718e3742002-12-13 20:15:29 +0000540 {
541 int len;
542
Christian Frankecd40b322013-09-30 12:27:51 +0000543 if (token->cmd[0] == '\0')
paul718e3742002-12-13 20:15:29 +0000544 continue;
545
Christian Frankecd40b322013-09-30 12:27:51 +0000546 len = strlen (token->cmd);
547 if (token->cmd[0] == '.')
paul718e3742002-12-13 20:15:29 +0000548 len--;
549
550 if (width < len)
551 width = len;
552 }
553
paul55468c82005-03-14 20:19:01 +0000554 for (i = 0; i < vector_active (describe); i++)
Christian Frankecd40b322013-09-30 12:27:51 +0000555 if ((token = vector_slot (describe, i)) != NULL)
paul718e3742002-12-13 20:15:29 +0000556 {
Christian Frankecd40b322013-09-30 12:27:51 +0000557 if (token->cmd[0] == '\0')
paul718e3742002-12-13 20:15:29 +0000558 continue;
559
Christian Frankecd40b322013-09-30 12:27:51 +0000560 if (! token->desc)
paul4fc01e62002-12-13 20:49:00 +0000561 fprintf (stdout," %-s\n",
Christian Frankecd40b322013-09-30 12:27:51 +0000562 token->cmd[0] == '.' ? token->cmd + 1 : token->cmd);
paul718e3742002-12-13 20:15:29 +0000563 else
paul4fc01e62002-12-13 20:49:00 +0000564 fprintf (stdout," %-*s %s\n",
hassob094d262004-08-25 12:22:00 +0000565 width,
Christian Frankecd40b322013-09-30 12:27:51 +0000566 token->cmd[0] == '.' ? token->cmd + 1 : token->cmd,
567 token->desc);
paul718e3742002-12-13 20:15:29 +0000568 }
569
570 cmd_free_strvec (vline);
571 vector_free (describe);
572
573 rl_on_new_line();
574
575 return 0;
576}
577
hasso95e735b2004-08-26 13:08:30 +0000578/* Result of cmd_complete_command() call will be stored here
579 * and used in new_completion() in order to put the space in
580 * correct places only. */
paul718e3742002-12-13 20:15:29 +0000581int complete_status;
582
ajs274a4a42004-12-07 15:39:31 +0000583static char *
pauldfc0d9b2003-04-18 23:55:29 +0000584command_generator (const char *text, int state)
paul718e3742002-12-13 20:15:29 +0000585{
586 vector vline;
587 static char **matched = NULL;
588 static int index = 0;
589
590 /* First call. */
591 if (! state)
592 {
593 index = 0;
594
595 if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
596 return NULL;
597
598 vline = cmd_make_strvec (rl_line_buffer);
599 if (vline == NULL)
600 return NULL;
601
602 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
David Lampartera91a3ba2015-03-03 09:06:51 +0100603 vector_set (vline, NULL);
paul718e3742002-12-13 20:15:29 +0000604
605 matched = cmd_complete_command (vline, vty, &complete_status);
606 }
607
608 if (matched && matched[index])
609 return matched[index++];
610
611 return NULL;
612}
613
ajs274a4a42004-12-07 15:39:31 +0000614static char **
paul718e3742002-12-13 20:15:29 +0000615new_completion (char *text, int start, int end)
616{
617 char **matches;
618
pauldfc0d9b2003-04-18 23:55:29 +0000619 matches = rl_completion_matches (text, command_generator);
paul718e3742002-12-13 20:15:29 +0000620
621 if (matches)
622 {
623 rl_point = rl_end;
Christian Franke67e7a212013-03-04 09:23:30 +0000624 if (complete_status != CMD_COMPLETE_FULL_MATCH)
625 /* only append a space on full match */
626 rl_completion_append_character = '\0';
paul718e3742002-12-13 20:15:29 +0000627 }
628
629 return matches;
630}
631
ajs274a4a42004-12-07 15:39:31 +0000632#if 0
633/* This function is not actually being used. */
634static char **
paul718e3742002-12-13 20:15:29 +0000635vtysh_completion (char *text, int start, int end)
636{
637 int ret;
638 vector vline;
639 char **matched = NULL;
640
641 if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
642 return NULL;
643
644 vline = cmd_make_strvec (rl_line_buffer);
645 if (vline == NULL)
646 return NULL;
647
648 /* In case of 'help \t'. */
649 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
650 vector_set (vline, '\0');
651
652 matched = cmd_complete_command (vline, vty, &ret);
653
654 cmd_free_strvec (vline);
655
656 return (char **) matched;
657}
ajs274a4a42004-12-07 15:39:31 +0000658#endif
paul718e3742002-12-13 20:15:29 +0000659
hasso95e735b2004-08-26 13:08:30 +0000660/* Vty node structures. */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800661static struct cmd_node bgp_node =
paul718e3742002-12-13 20:15:29 +0000662{
663 BGP_NODE,
664 "%s(config-router)# ",
665};
666
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800667static struct cmd_node rip_node =
paul718e3742002-12-13 20:15:29 +0000668{
669 RIP_NODE,
670 "%s(config-router)# ",
671};
672
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800673static struct cmd_node isis_node =
hassoc25e4582003-12-23 10:39:08 +0000674{
675 ISIS_NODE,
676 "%s(config-router)# ",
hassoc25e4582003-12-23 10:39:08 +0000677};
678
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800679static struct cmd_node interface_node =
paul718e3742002-12-13 20:15:29 +0000680{
681 INTERFACE_NODE,
682 "%s(config-if)# ",
683};
684
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800685static struct cmd_node rmap_node =
hasso95e735b2004-08-26 13:08:30 +0000686{
687 RMAP_NODE,
688 "%s(config-route-map)# "
689};
690
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800691static struct cmd_node zebra_node =
hasso95e735b2004-08-26 13:08:30 +0000692{
693 ZEBRA_NODE,
694 "%s(config-router)# "
695};
696
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800697static struct cmd_node bgp_vpnv4_node =
hasso95e735b2004-08-26 13:08:30 +0000698{
699 BGP_VPNV4_NODE,
700 "%s(config-router-af)# "
701};
702
Lou Berger13c378d2016-01-12 13:41:56 -0500703static struct cmd_node bgp_vpnv6_node =
704{
705 BGP_VPNV6_NODE,
706 "%s(config-router-af)# "
707};
708
Lou Bergera3fda882016-01-12 13:42:04 -0500709static struct cmd_node bgp_encap_node =
710{
711 BGP_ENCAP_NODE,
712 "%s(config-router-af)# "
713};
714
715static struct cmd_node bgp_encapv6_node =
716{
717 BGP_ENCAPV6_NODE,
718 "%s(config-router-af)# "
719};
720
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800721static struct cmd_node bgp_ipv4_node =
hasso95e735b2004-08-26 13:08:30 +0000722{
723 BGP_IPV4_NODE,
724 "%s(config-router-af)# "
725};
726
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800727static struct cmd_node bgp_ipv4m_node =
hasso95e735b2004-08-26 13:08:30 +0000728{
729 BGP_IPV4M_NODE,
730 "%s(config-router-af)# "
731};
732
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800733static struct cmd_node bgp_ipv6_node =
hasso95e735b2004-08-26 13:08:30 +0000734{
735 BGP_IPV6_NODE,
736 "%s(config-router-af)# "
737};
738
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800739static struct cmd_node bgp_ipv6m_node =
paul57b5b7e2005-08-22 22:44:29 +0000740{
741 BGP_IPV6M_NODE,
742 "%s(config-router-af)# "
743};
744
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800745static struct cmd_node ospf_node =
hasso95e735b2004-08-26 13:08:30 +0000746{
747 OSPF_NODE,
748 "%s(config-router)# "
749};
750
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800751static struct cmd_node ripng_node =
hasso95e735b2004-08-26 13:08:30 +0000752{
753 RIPNG_NODE,
754 "%s(config-router)# "
755};
756
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800757static struct cmd_node ospf6_node =
hasso95e735b2004-08-26 13:08:30 +0000758{
759 OSPF6_NODE,
760 "%s(config-ospf6)# "
761};
762
David Lamparteree53c8b2015-05-23 05:45:59 +0200763static struct cmd_node babel_node =
764{
765 BABEL_NODE,
766 "%s(config-babel)# "
767};
768
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800769static struct cmd_node keychain_node =
hasso95e735b2004-08-26 13:08:30 +0000770{
771 KEYCHAIN_NODE,
772 "%s(config-keychain)# "
773};
774
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800775static struct cmd_node keychain_key_node =
hasso95e735b2004-08-26 13:08:30 +0000776{
777 KEYCHAIN_KEY_NODE,
778 "%s(config-keychain-key)# "
779};
780
Olivier Dugeonac10d302016-04-19 18:33:42 +0200781struct cmd_node link_params_node =
782{
783 LINK_PARAMS_NODE,
784 "%s(config-link-params)# ",
785};
786
hassoe7168df2004-10-03 20:11:32 +0000787/* Defined in lib/vty.c */
788extern struct cmd_node vty_node;
789
hasso95e735b2004-08-26 13:08:30 +0000790/* When '^Z' is received from vty, move down to the enable mode. */
David Lampartera9eb9062015-03-04 07:07:01 +0100791static int
ajsb1aa1472005-01-28 21:11:46 +0000792vtysh_end (void)
hasso95e735b2004-08-26 13:08:30 +0000793{
794 switch (vty->node)
795 {
796 case VIEW_NODE:
797 case ENABLE_NODE:
798 /* Nothing to do. */
799 break;
800 default:
801 vty->node = ENABLE_NODE;
802 break;
803 }
804 return CMD_SUCCESS;
805}
806
807DEFUNSH (VTYSH_ALL,
808 vtysh_end_all,
809 vtysh_end_all_cmd,
810 "end",
hassoe7168df2004-10-03 20:11:32 +0000811 "End current mode and change to enable mode\n")
hasso95e735b2004-08-26 13:08:30 +0000812{
hasso42895462004-09-26 16:25:07 +0000813 return vtysh_end ();
hasso95e735b2004-08-26 13:08:30 +0000814}
815
paul718e3742002-12-13 20:15:29 +0000816DEFUNSH (VTYSH_BGPD,
817 router_bgp,
818 router_bgp_cmd,
Paul Jakma320da872008-07-02 13:40:33 +0000819 "router bgp " CMD_AS_RANGE,
paul718e3742002-12-13 20:15:29 +0000820 ROUTER_STR
821 BGP_STR
822 AS_STR)
823{
824 vty->node = BGP_NODE;
825 return CMD_SUCCESS;
826}
827
Paul Jakma10895fd2008-07-03 19:34:48 +0000828ALIAS_SH (VTYSH_BGPD,
829 router_bgp,
830 router_bgp_view_cmd,
831 "router bgp " CMD_AS_RANGE " view WORD",
832 ROUTER_STR
833 BGP_STR
834 AS_STR
835 "BGP view\n"
836 "view name\n")
837
paul718e3742002-12-13 20:15:29 +0000838DEFUNSH (VTYSH_BGPD,
839 address_family_vpnv4,
840 address_family_vpnv4_cmd,
841 "address-family vpnv4",
842 "Enter Address Family command mode\n"
843 "Address family\n")
844{
845 vty->node = BGP_VPNV4_NODE;
846 return CMD_SUCCESS;
847}
848
849DEFUNSH (VTYSH_BGPD,
850 address_family_vpnv4_unicast,
851 address_family_vpnv4_unicast_cmd,
852 "address-family vpnv4 unicast",
853 "Enter Address Family command mode\n"
854 "Address family\n"
855 "Address Family Modifier\n")
856{
857 vty->node = BGP_VPNV4_NODE;
858 return CMD_SUCCESS;
859}
860
861DEFUNSH (VTYSH_BGPD,
Lou Berger13c378d2016-01-12 13:41:56 -0500862 address_family_vpnv6,
863 address_family_vpnv6_cmd,
864 "address-family vpnv6",
865 "Enter Address Family command mode\n"
866 "Address family\n")
867{
868 vty->node = BGP_VPNV6_NODE;
869 return CMD_SUCCESS;
870}
871
872DEFUNSH (VTYSH_BGPD,
873 address_family_vpnv6_unicast,
874 address_family_vpnv6_unicast_cmd,
875 "address-family vpnv6 unicast",
876 "Enter Address Family command mode\n"
877 "Address family\n"
878 "Address Family Modifier\n")
879{
880 vty->node = BGP_VPNV6_NODE;
881 return CMD_SUCCESS;
882}
883
884DEFUNSH (VTYSH_BGPD,
Lou Bergera3fda882016-01-12 13:42:04 -0500885 address_family_encap,
886 address_family_encap_cmd,
887 "address-family encap",
888 "Enter Address Family command mode\n"
889 "Address family\n")
890{
891 vty->node = BGP_ENCAP_NODE;
892 return CMD_SUCCESS;
893}
894
895DEFUNSH (VTYSH_BGPD,
896 address_family_encapv4,
897 address_family_encapv4_cmd,
898 "address-family encapv4",
899 "Enter Address Family command mode\n"
900 "Address family\n")
901{
902 vty->node = BGP_ENCAP_NODE;
903 return CMD_SUCCESS;
904}
905
906DEFUNSH (VTYSH_BGPD,
907 address_family_encapv6,
908 address_family_encapv6_cmd,
909 "address-family encapv6",
910 "Enter Address Family command mode\n"
911 "Address family\n")
912{
913 vty->node = BGP_ENCAPV6_NODE;
914 return CMD_SUCCESS;
915}
916
917DEFUNSH (VTYSH_BGPD,
paul718e3742002-12-13 20:15:29 +0000918 address_family_ipv4_unicast,
919 address_family_ipv4_unicast_cmd,
920 "address-family ipv4 unicast",
921 "Enter Address Family command mode\n"
922 "Address family\n"
923 "Address Family Modifier\n")
924{
925 vty->node = BGP_IPV4_NODE;
926 return CMD_SUCCESS;
927}
928
929DEFUNSH (VTYSH_BGPD,
930 address_family_ipv4_multicast,
931 address_family_ipv4_multicast_cmd,
932 "address-family ipv4 multicast",
933 "Enter Address Family command mode\n"
934 "Address family\n"
935 "Address Family Modifier\n")
936{
937 vty->node = BGP_IPV4M_NODE;
938 return CMD_SUCCESS;
939}
940
941DEFUNSH (VTYSH_BGPD,
942 address_family_ipv6,
943 address_family_ipv6_cmd,
944 "address-family ipv6",
945 "Enter Address Family command mode\n"
946 "Address family\n")
947{
948 vty->node = BGP_IPV6_NODE;
949 return CMD_SUCCESS;
950}
951
952DEFUNSH (VTYSH_BGPD,
953 address_family_ipv6_unicast,
954 address_family_ipv6_unicast_cmd,
955 "address-family ipv6 unicast",
956 "Enter Address Family command mode\n"
957 "Address family\n"
958 "Address Family Modifier\n")
959{
960 vty->node = BGP_IPV6_NODE;
961 return CMD_SUCCESS;
962}
963
paul57b5b7e2005-08-22 22:44:29 +0000964DEFUNSH (VTYSH_BGPD,
965 address_family_ipv6_multicast,
966 address_family_ipv6_multicast_cmd,
967 "address-family ipv6 multicast",
968 "Enter Address Family command mode\n"
969 "Address family\n"
970 "Address Family Modifier\n")
971{
972 vty->node = BGP_IPV6M_NODE;
973 return CMD_SUCCESS;
974}
975
paul718e3742002-12-13 20:15:29 +0000976DEFUNSH (VTYSH_RIPD,
977 key_chain,
978 key_chain_cmd,
979 "key chain WORD",
980 "Authentication key management\n"
981 "Key-chain management\n"
982 "Key-chain name\n")
983{
984 vty->node = KEYCHAIN_NODE;
985 return CMD_SUCCESS;
986}
987
988DEFUNSH (VTYSH_RIPD,
989 key,
990 key_cmd,
991 "key <0-2147483647>",
992 "Configure a key\n"
993 "Key identifier number\n")
994{
995 vty->node = KEYCHAIN_KEY_NODE;
996 return CMD_SUCCESS;
997}
998
999DEFUNSH (VTYSH_RIPD,
1000 router_rip,
1001 router_rip_cmd,
1002 "router rip",
1003 ROUTER_STR
1004 "RIP")
1005{
1006 vty->node = RIP_NODE;
1007 return CMD_SUCCESS;
1008}
1009
1010DEFUNSH (VTYSH_RIPNGD,
1011 router_ripng,
1012 router_ripng_cmd,
1013 "router ripng",
1014 ROUTER_STR
1015 "RIPng")
1016{
1017 vty->node = RIPNG_NODE;
1018 return CMD_SUCCESS;
1019}
1020
1021DEFUNSH (VTYSH_OSPFD,
1022 router_ospf,
1023 router_ospf_cmd,
1024 "router ospf",
1025 "Enable a routing process\n"
1026 "Start OSPF configuration\n")
1027{
1028 vty->node = OSPF_NODE;
1029 return CMD_SUCCESS;
1030}
1031
1032DEFUNSH (VTYSH_OSPF6D,
1033 router_ospf6,
1034 router_ospf6_cmd,
1035 "router ospf6",
1036 OSPF6_ROUTER_STR
1037 OSPF6_STR)
1038{
1039 vty->node = OSPF6_NODE;
1040 return CMD_SUCCESS;
1041}
1042
hassoc25e4582003-12-23 10:39:08 +00001043DEFUNSH (VTYSH_ISISD,
hassob094d262004-08-25 12:22:00 +00001044 router_isis,
1045 router_isis_cmd,
1046 "router isis WORD",
1047 ROUTER_STR
1048 "ISO IS-IS\n"
1049 "ISO Routing area tag")
hassoc25e4582003-12-23 10:39:08 +00001050{
1051 vty->node = ISIS_NODE;
1052 return CMD_SUCCESS;
1053}
1054
paul718e3742002-12-13 20:15:29 +00001055DEFUNSH (VTYSH_RMAP,
1056 route_map,
1057 route_map_cmd,
1058 "route-map WORD (deny|permit) <1-65535>",
1059 "Create route-map or enter route-map command mode\n"
1060 "Route map tag\n"
1061 "Route map denies set operations\n"
1062 "Route map permits set operations\n"
1063 "Sequence to insert to/delete from existing route-map entry\n")
1064{
1065 vty->node = RMAP_NODE;
1066 return CMD_SUCCESS;
1067}
1068
paul718e3742002-12-13 20:15:29 +00001069DEFUNSH (VTYSH_ALL,
hassoe7168df2004-10-03 20:11:32 +00001070 vtysh_line_vty,
1071 vtysh_line_vty_cmd,
1072 "line vty",
1073 "Configure a terminal line\n"
1074 "Virtual terminal\n")
1075{
1076 vty->node = VTY_NODE;
1077 return CMD_SUCCESS;
1078}
1079
1080DEFUNSH (VTYSH_ALL,
paul718e3742002-12-13 20:15:29 +00001081 vtysh_enable,
1082 vtysh_enable_cmd,
1083 "enable",
1084 "Turn on privileged mode command\n")
1085{
1086 vty->node = ENABLE_NODE;
1087 return CMD_SUCCESS;
1088}
1089
paul718e3742002-12-13 20:15:29 +00001090DEFUNSH (VTYSH_ALL,
1091 vtysh_disable,
1092 vtysh_disable_cmd,
1093 "disable",
1094 "Turn off privileged mode command\n")
1095{
1096 if (vty->node == ENABLE_NODE)
1097 vty->node = VIEW_NODE;
1098 return CMD_SUCCESS;
1099}
1100
paul718e3742002-12-13 20:15:29 +00001101DEFUNSH (VTYSH_ALL,
1102 vtysh_config_terminal,
1103 vtysh_config_terminal_cmd,
1104 "configure terminal",
1105 "Configuration from vty interface\n"
1106 "Configuration terminal\n")
1107{
1108 vty->node = CONFIG_NODE;
1109 return CMD_SUCCESS;
1110}
1111
ajs274a4a42004-12-07 15:39:31 +00001112static int
paul718e3742002-12-13 20:15:29 +00001113vtysh_exit (struct vty *vty)
1114{
1115 switch (vty->node)
1116 {
1117 case VIEW_NODE:
1118 case ENABLE_NODE:
1119 exit (0);
1120 break;
1121 case CONFIG_NODE:
1122 vty->node = ENABLE_NODE;
1123 break;
1124 case INTERFACE_NODE:
1125 case ZEBRA_NODE:
1126 case BGP_NODE:
1127 case RIP_NODE:
1128 case RIPNG_NODE:
1129 case OSPF_NODE:
1130 case OSPF6_NODE:
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +01001131 case BABEL_NODE:
hassoc25e4582003-12-23 10:39:08 +00001132 case ISIS_NODE:
paul718e3742002-12-13 20:15:29 +00001133 case MASC_NODE:
1134 case RMAP_NODE:
1135 case VTY_NODE:
1136 case KEYCHAIN_NODE:
hasso2a56df92004-05-09 23:16:40 +00001137 vtysh_execute("end");
1138 vtysh_execute("configure terminal");
paul718e3742002-12-13 20:15:29 +00001139 vty->node = CONFIG_NODE;
1140 break;
1141 case BGP_VPNV4_NODE:
Lou Berger13c378d2016-01-12 13:41:56 -05001142 case BGP_VPNV6_NODE:
Lou Bergera3fda882016-01-12 13:42:04 -05001143 case BGP_ENCAP_NODE:
1144 case BGP_ENCAPV6_NODE:
paul718e3742002-12-13 20:15:29 +00001145 case BGP_IPV4_NODE:
1146 case BGP_IPV4M_NODE:
1147 case BGP_IPV6_NODE:
paul57b5b7e2005-08-22 22:44:29 +00001148 case BGP_IPV6M_NODE:
paul718e3742002-12-13 20:15:29 +00001149 vty->node = BGP_NODE;
1150 break;
1151 case KEYCHAIN_KEY_NODE:
1152 vty->node = KEYCHAIN_NODE;
1153 break;
Olivier Dugeonac10d302016-04-19 18:33:42 +02001154 case LINK_PARAMS_NODE:
1155 vty->node = INTERFACE_NODE;
1156 break;
paul718e3742002-12-13 20:15:29 +00001157 default:
1158 break;
1159 }
1160 return CMD_SUCCESS;
1161}
1162
1163DEFUNSH (VTYSH_ALL,
1164 vtysh_exit_all,
1165 vtysh_exit_all_cmd,
1166 "exit",
1167 "Exit current mode and down to previous mode\n")
1168{
1169 return vtysh_exit (vty);
1170}
1171
1172ALIAS (vtysh_exit_all,
1173 vtysh_quit_all_cmd,
1174 "quit",
1175 "Exit current mode and down to previous mode\n")
1176
1177DEFUNSH (VTYSH_BGPD,
1178 exit_address_family,
1179 exit_address_family_cmd,
1180 "exit-address-family",
1181 "Exit from Address Family configuration mode\n")
1182{
1183 if (vty->node == BGP_IPV4_NODE
1184 || vty->node == BGP_IPV4M_NODE
1185 || vty->node == BGP_VPNV4_NODE
Lou Berger13c378d2016-01-12 13:41:56 -05001186 || vty->node == BGP_VPNV6_NODE
Lou Bergera3fda882016-01-12 13:42:04 -05001187 || vty->node == BGP_ENCAP_NODE
1188 || vty->node == BGP_ENCAPV6_NODE
paul57b5b7e2005-08-22 22:44:29 +00001189 || vty->node == BGP_IPV6_NODE
1190 || vty->node == BGP_IPV6M_NODE)
paul718e3742002-12-13 20:15:29 +00001191 vty->node = BGP_NODE;
1192 return CMD_SUCCESS;
1193}
1194
1195DEFUNSH (VTYSH_ZEBRA,
1196 vtysh_exit_zebra,
1197 vtysh_exit_zebra_cmd,
1198 "exit",
1199 "Exit current mode and down to previous mode\n")
1200{
1201 return vtysh_exit (vty);
1202}
1203
1204ALIAS (vtysh_exit_zebra,
1205 vtysh_quit_zebra_cmd,
1206 "quit",
1207 "Exit current mode and down to previous mode\n")
1208
1209DEFUNSH (VTYSH_RIPD,
1210 vtysh_exit_ripd,
1211 vtysh_exit_ripd_cmd,
1212 "exit",
1213 "Exit current mode and down to previous mode\n")
1214{
1215 return vtysh_exit (vty);
1216}
1217
1218ALIAS (vtysh_exit_ripd,
1219 vtysh_quit_ripd_cmd,
1220 "quit",
1221 "Exit current mode and down to previous mode\n")
1222
paul68980082003-03-25 05:07:42 +00001223DEFUNSH (VTYSH_RIPNGD,
hassob094d262004-08-25 12:22:00 +00001224 vtysh_exit_ripngd,
1225 vtysh_exit_ripngd_cmd,
1226 "exit",
1227 "Exit current mode and down to previous mode\n")
paul68980082003-03-25 05:07:42 +00001228{
1229 return vtysh_exit (vty);
1230}
1231
1232ALIAS (vtysh_exit_ripngd,
1233 vtysh_quit_ripngd_cmd,
1234 "quit",
1235 "Exit current mode and down to previous mode\n")
1236
paul718e3742002-12-13 20:15:29 +00001237DEFUNSH (VTYSH_RMAP,
1238 vtysh_exit_rmap,
1239 vtysh_exit_rmap_cmd,
1240 "exit",
1241 "Exit current mode and down to previous mode\n")
1242{
1243 return vtysh_exit (vty);
1244}
1245
1246ALIAS (vtysh_exit_rmap,
1247 vtysh_quit_rmap_cmd,
1248 "quit",
1249 "Exit current mode and down to previous mode\n")
1250
1251DEFUNSH (VTYSH_BGPD,
1252 vtysh_exit_bgpd,
1253 vtysh_exit_bgpd_cmd,
1254 "exit",
1255 "Exit current mode and down to previous mode\n")
1256{
1257 return vtysh_exit (vty);
1258}
1259
1260ALIAS (vtysh_exit_bgpd,
1261 vtysh_quit_bgpd_cmd,
1262 "quit",
1263 "Exit current mode and down to previous mode\n")
1264
1265DEFUNSH (VTYSH_OSPFD,
1266 vtysh_exit_ospfd,
1267 vtysh_exit_ospfd_cmd,
1268 "exit",
1269 "Exit current mode and down to previous mode\n")
1270{
1271 return vtysh_exit (vty);
1272}
1273
1274ALIAS (vtysh_exit_ospfd,
1275 vtysh_quit_ospfd_cmd,
1276 "quit",
1277 "Exit current mode and down to previous mode\n")
1278
paul68980082003-03-25 05:07:42 +00001279DEFUNSH (VTYSH_OSPF6D,
hassob094d262004-08-25 12:22:00 +00001280 vtysh_exit_ospf6d,
1281 vtysh_exit_ospf6d_cmd,
1282 "exit",
1283 "Exit current mode and down to previous mode\n")
paul68980082003-03-25 05:07:42 +00001284{
1285 return vtysh_exit (vty);
1286}
1287
1288ALIAS (vtysh_exit_ospf6d,
1289 vtysh_quit_ospf6d_cmd,
1290 "quit",
1291 "Exit current mode and down to previous mode\n")
1292
hassoc25e4582003-12-23 10:39:08 +00001293DEFUNSH (VTYSH_ISISD,
hassob094d262004-08-25 12:22:00 +00001294 vtysh_exit_isisd,
1295 vtysh_exit_isisd_cmd,
1296 "exit",
1297 "Exit current mode and down to previous mode\n")
hassoc25e4582003-12-23 10:39:08 +00001298{
1299 return vtysh_exit (vty);
1300}
1301
1302ALIAS (vtysh_exit_isisd,
1303 vtysh_quit_isisd_cmd,
1304 "quit",
1305 "Exit current mode and down to previous mode\n")
1306
hassoe7168df2004-10-03 20:11:32 +00001307DEFUNSH (VTYSH_ALL,
1308 vtysh_exit_line_vty,
1309 vtysh_exit_line_vty_cmd,
1310 "exit",
1311 "Exit current mode and down to previous mode\n")
1312{
1313 return vtysh_exit (vty);
1314}
1315
1316ALIAS (vtysh_exit_line_vty,
1317 vtysh_quit_line_vty_cmd,
1318 "quit",
1319 "Exit current mode and down to previous mode\n")
1320
hasso95e735b2004-08-26 13:08:30 +00001321DEFUNSH (VTYSH_INTERFACE,
paul718e3742002-12-13 20:15:29 +00001322 vtysh_interface,
1323 vtysh_interface_cmd,
1324 "interface IFNAME",
1325 "Select an interface to configure\n"
1326 "Interface's name\n")
1327{
1328 vty->node = INTERFACE_NODE;
1329 return CMD_SUCCESS;
1330}
1331
Feng Lu471ea392015-05-22 11:40:00 +02001332ALIAS_SH (VTYSH_ZEBRA,
1333 vtysh_interface,
1334 vtysh_interface_vrf_cmd,
1335 "interface IFNAME " VRF_CMD_STR,
1336 "Select an interface to configure\n"
1337 "Interface's name\n"
1338 VRF_CMD_HELP_STR)
1339
Igor Ryzhov6ff2acd2016-06-09 16:44:21 +03001340DEFSH (VTYSH_INTERFACE,
paul32d24632003-05-23 09:25:20 +00001341 vtysh_no_interface_cmd,
1342 "no interface IFNAME",
1343 NO_STR
1344 "Delete a pseudo interface's configuration\n"
1345 "Interface's name\n")
1346
Feng Lu471ea392015-05-22 11:40:00 +02001347DEFSH (VTYSH_ZEBRA,
1348 vtysh_no_interface_vrf_cmd,
1349 "no interface IFNAME " VRF_CMD_STR,
1350 NO_STR
1351 "Delete a pseudo interface's configuration\n"
1352 "Interface's name\n"
1353 VRF_CMD_HELP_STR)
1354
hasso95e735b2004-08-26 13:08:30 +00001355/* TODO Implement interface description commands in ripngd, ospf6d
1356 * and isisd. */
paul338a9912003-03-01 15:44:10 +00001357DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1358 interface_desc_cmd,
1359 "description .LINE",
1360 "Interface specific description\n"
1361 "Characters describing this interface\n")
paul464dc8d2003-03-28 02:25:45 +00001362
1363DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1364 no_interface_desc_cmd,
1365 "no description",
1366 NO_STR
1367 "Interface specific description\n")
paul338a9912003-03-01 15:44:10 +00001368
hasso95e735b2004-08-26 13:08:30 +00001369DEFUNSH (VTYSH_INTERFACE,
paul718e3742002-12-13 20:15:29 +00001370 vtysh_exit_interface,
1371 vtysh_exit_interface_cmd,
1372 "exit",
1373 "Exit current mode and down to previous mode\n")
1374{
1375 return vtysh_exit (vty);
1376}
1377
1378ALIAS (vtysh_exit_interface,
1379 vtysh_quit_interface_cmd,
1380 "quit",
1381 "Exit current mode and down to previous mode\n")
1382
Donald Sharp567a6382015-08-19 21:22:17 -04001383DEFUN (vtysh_show_thread,
1384 vtysh_show_thread_cmd,
1385 "show thread cpu [FILTER]",
1386 SHOW_STR
1387 "Thread information\n"
1388 "Thread CPU usage\n"
1389 "Display filter (rwtexb)\n")
1390{
1391 unsigned int i;
1392 int ret = CMD_SUCCESS;
1393 char line[100];
1394
1395 sprintf(line, "show thread cpu %s\n", (argc == 1) ? argv[0] : "");
1396 for (i = 0; i < array_size(vtysh_client); i++)
1397 if ( vtysh_client[i].fd >= 0 )
1398 {
1399 fprintf (stdout, "Thread statistics for %s:\n",
1400 vtysh_client[i].name);
1401 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1402 fprintf (stdout,"\n");
1403 }
1404 return ret;
1405}
1406
1407DEFUN (vtysh_show_work_queues,
1408 vtysh_show_work_queues_cmd,
1409 "show work-queues",
1410 SHOW_STR
1411 "Work Queue information\n")
1412{
1413 unsigned int i;
1414 int ret = CMD_SUCCESS;
1415 char line[] = "show work-queues\n";
1416
1417 for (i = 0; i < array_size(vtysh_client); i++)
1418 if ( vtysh_client[i].fd >= 0 )
1419 {
1420 fprintf (stdout, "Work queue statistics for %s:\n",
1421 vtysh_client[i].name);
1422 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1423 fprintf (stdout,"\n");
1424 }
1425
1426 return ret;
1427}
1428
Donald Sharp07440402016-02-25 07:39:45 -05001429DEFUN (vtysh_show_work_queues_daemon,
1430 vtysh_show_work_queues_daemon_cmd,
1431 "show work-queues (zebra|ripd|ripngd|ospfd|ospf6d|bgpd|isisd)",
1432 SHOW_STR
1433 "Work Queue information\n"
1434 "For the zebra daemon\n"
1435 "For the rip daemon\n"
1436 "For the ripng daemon\n"
1437 "For the ospf daemon\n"
1438 "For the ospfv6 daemon\n"
1439 "For the bgp daemon\n"
1440 "For the isis daemon\n")
1441{
1442 unsigned int i;
1443 int ret = CMD_SUCCESS;
1444
1445 for (i = 0; i < array_size(vtysh_client); i++)
1446 {
1447 if (begins_with(vtysh_client[i].name, argv[0]))
1448 break;
1449 }
1450
1451 ret = vtysh_client_execute(&vtysh_client[i], "show work-queues\n", stdout);
1452
1453 return ret;
1454}
1455
Olivier Dugeonac10d302016-04-19 18:33:42 +02001456DEFUNSH (VTYSH_ZEBRA,
1457 vtysh_link_params,
1458 vtysh_link_params_cmd,
1459 "link-params",
1460 LINK_PARAMS_STR
1461 )
1462{
1463 vty->node = LINK_PARAMS_NODE;
1464 return CMD_SUCCESS;
1465}
1466
Paul Jakma362b4032006-05-28 07:54:45 +00001467/* Memory */
1468DEFUN (vtysh_show_memory,
1469 vtysh_show_memory_cmd,
1470 "show memory",
1471 SHOW_STR
1472 "Memory statistics\n")
1473{
1474 unsigned int i;
1475 int ret = CMD_SUCCESS;
1476 char line[] = "show memory\n";
1477
Balaji.G837d16c2012-09-26 14:09:10 +05301478 for (i = 0; i < array_size(vtysh_client); i++)
Paul Jakma362b4032006-05-28 07:54:45 +00001479 if ( vtysh_client[i].fd >= 0 )
1480 {
1481 fprintf (stdout, "Memory statistics for %s:\n",
1482 vtysh_client[i].name);
1483 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1484 fprintf (stdout,"\n");
1485 }
1486
1487 return ret;
1488}
1489
hasso95e735b2004-08-26 13:08:30 +00001490/* Logging commands. */
Paul Jakmadbf7d132006-05-23 22:10:01 +00001491DEFUN (vtysh_show_logging,
1492 vtysh_show_logging_cmd,
1493 "show logging",
1494 SHOW_STR
1495 "Show current logging configuration\n")
1496{
1497 unsigned int i;
1498 int ret = CMD_SUCCESS;
1499 char line[] = "show logging\n";
1500
Balaji.G837d16c2012-09-26 14:09:10 +05301501 for (i = 0; i < array_size(vtysh_client); i++)
Paul Jakma4150f332006-05-23 22:10:55 +00001502 if ( vtysh_client[i].fd >= 0 )
1503 {
1504 fprintf (stdout,"Logging configuration for %s:\n",
1505 vtysh_client[i].name);
1506 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1507 fprintf (stdout,"\n");
1508 }
1509
Paul Jakmadbf7d132006-05-23 22:10:01 +00001510 return ret;
1511}
1512
hasso95e735b2004-08-26 13:08:30 +00001513DEFUNSH (VTYSH_ALL,
1514 vtysh_log_stdout,
1515 vtysh_log_stdout_cmd,
1516 "log stdout",
1517 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001518 "Set stdout logging level\n")
1519{
1520 return CMD_SUCCESS;
1521}
1522
1523DEFUNSH (VTYSH_ALL,
1524 vtysh_log_stdout_level,
1525 vtysh_log_stdout_level_cmd,
1526 "log stdout "LOG_LEVELS,
1527 "Logging control\n"
1528 "Set stdout logging level\n"
1529 LOG_LEVEL_DESC)
hasso95e735b2004-08-26 13:08:30 +00001530{
1531 return CMD_SUCCESS;
1532}
1533
1534DEFUNSH (VTYSH_ALL,
1535 no_vtysh_log_stdout,
1536 no_vtysh_log_stdout_cmd,
ajs274a4a42004-12-07 15:39:31 +00001537 "no log stdout [LEVEL]",
hasso95e735b2004-08-26 13:08:30 +00001538 NO_STR
1539 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001540 "Cancel logging to stdout\n"
1541 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001542{
1543 return CMD_SUCCESS;
1544}
1545
1546DEFUNSH (VTYSH_ALL,
1547 vtysh_log_file,
1548 vtysh_log_file_cmd,
1549 "log file FILENAME",
1550 "Logging control\n"
1551 "Logging to file\n"
1552 "Logging filename\n")
1553{
1554 return CMD_SUCCESS;
1555}
1556
1557DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001558 vtysh_log_file_level,
1559 vtysh_log_file_level_cmd,
1560 "log file FILENAME "LOG_LEVELS,
1561 "Logging control\n"
1562 "Logging to file\n"
1563 "Logging filename\n"
1564 LOG_LEVEL_DESC)
1565{
1566 return CMD_SUCCESS;
1567}
1568
1569DEFUNSH (VTYSH_ALL,
hasso95e735b2004-08-26 13:08:30 +00001570 no_vtysh_log_file,
1571 no_vtysh_log_file_cmd,
1572 "no log file [FILENAME]",
1573 NO_STR
1574 "Logging control\n"
1575 "Cancel logging to file\n"
1576 "Logging file name\n")
1577{
1578 return CMD_SUCCESS;
1579}
1580
ajs274a4a42004-12-07 15:39:31 +00001581ALIAS_SH (VTYSH_ALL,
1582 no_vtysh_log_file,
1583 no_vtysh_log_file_level_cmd,
1584 "no log file FILENAME LEVEL",
1585 NO_STR
1586 "Logging control\n"
1587 "Cancel logging to file\n"
1588 "Logging file name\n"
1589 "Logging level\n")
1590
1591DEFUNSH (VTYSH_ALL,
1592 vtysh_log_monitor,
1593 vtysh_log_monitor_cmd,
1594 "log monitor",
1595 "Logging control\n"
1596 "Set terminal line (monitor) logging level\n")
1597{
1598 return CMD_SUCCESS;
1599}
1600
1601DEFUNSH (VTYSH_ALL,
1602 vtysh_log_monitor_level,
1603 vtysh_log_monitor_level_cmd,
1604 "log monitor "LOG_LEVELS,
1605 "Logging control\n"
1606 "Set terminal line (monitor) logging level\n"
1607 LOG_LEVEL_DESC)
1608{
1609 return CMD_SUCCESS;
1610}
1611
1612DEFUNSH (VTYSH_ALL,
1613 no_vtysh_log_monitor,
1614 no_vtysh_log_monitor_cmd,
1615 "no log monitor [LEVEL]",
1616 NO_STR
1617 "Logging control\n"
1618 "Disable terminal line (monitor) logging\n"
1619 "Logging level\n")
1620{
1621 return CMD_SUCCESS;
1622}
1623
hasso95e735b2004-08-26 13:08:30 +00001624DEFUNSH (VTYSH_ALL,
1625 vtysh_log_syslog,
1626 vtysh_log_syslog_cmd,
1627 "log syslog",
1628 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001629 "Set syslog logging level\n")
1630{
1631 return CMD_SUCCESS;
1632}
1633
1634DEFUNSH (VTYSH_ALL,
1635 vtysh_log_syslog_level,
1636 vtysh_log_syslog_level_cmd,
1637 "log syslog "LOG_LEVELS,
1638 "Logging control\n"
1639 "Set syslog logging level\n"
1640 LOG_LEVEL_DESC)
hasso95e735b2004-08-26 13:08:30 +00001641{
1642 return CMD_SUCCESS;
1643}
1644
1645DEFUNSH (VTYSH_ALL,
1646 no_vtysh_log_syslog,
1647 no_vtysh_log_syslog_cmd,
ajs274a4a42004-12-07 15:39:31 +00001648 "no log syslog [LEVEL]",
hasso95e735b2004-08-26 13:08:30 +00001649 NO_STR
1650 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001651 "Cancel logging to syslog\n"
1652 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001653{
1654 return CMD_SUCCESS;
1655}
1656
1657DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001658 vtysh_log_facility,
1659 vtysh_log_facility_cmd,
1660 "log facility "LOG_FACILITIES,
hasso95e735b2004-08-26 13:08:30 +00001661 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001662 "Facility parameter for syslog messages\n"
1663 LOG_FACILITY_DESC)
1664
hasso95e735b2004-08-26 13:08:30 +00001665{
1666 return CMD_SUCCESS;
1667}
1668
1669DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001670 no_vtysh_log_facility,
1671 no_vtysh_log_facility_cmd,
1672 "no log facility [FACILITY]",
hasso95e735b2004-08-26 13:08:30 +00001673 NO_STR
1674 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001675 "Reset syslog facility to default (daemon)\n"
1676 "Syslog facility\n")
1677
1678{
1679 return CMD_SUCCESS;
1680}
1681
1682DEFUNSH_DEPRECATED (VTYSH_ALL,
1683 vtysh_log_trap,
1684 vtysh_log_trap_cmd,
1685 "log trap "LOG_LEVELS,
1686 "Logging control\n"
1687 "(Deprecated) Set logging level and default for all destinations\n"
1688 LOG_LEVEL_DESC)
1689
1690{
1691 return CMD_SUCCESS;
1692}
1693
1694DEFUNSH_DEPRECATED (VTYSH_ALL,
1695 no_vtysh_log_trap,
1696 no_vtysh_log_trap_cmd,
1697 "no log trap [LEVEL]",
1698 NO_STR
1699 "Logging control\n"
1700 "Permit all logging information\n"
1701 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001702{
1703 return CMD_SUCCESS;
1704}
1705
1706DEFUNSH (VTYSH_ALL,
1707 vtysh_log_record_priority,
1708 vtysh_log_record_priority_cmd,
1709 "log record-priority",
1710 "Logging control\n"
1711 "Log the priority of the message within the message\n")
1712{
1713 return CMD_SUCCESS;
1714}
1715
1716DEFUNSH (VTYSH_ALL,
1717 no_vtysh_log_record_priority,
1718 no_vtysh_log_record_priority_cmd,
1719 "no log record-priority",
1720 NO_STR
1721 "Logging control\n"
1722 "Do not log the priority of the message within the message\n")
1723{
1724 return CMD_SUCCESS;
1725}
1726
hassoe7168df2004-10-03 20:11:32 +00001727DEFUNSH (VTYSH_ALL,
Andrew J. Schorrc749b722007-04-29 03:53:31 +00001728 vtysh_log_timestamp_precision,
1729 vtysh_log_timestamp_precision_cmd,
1730 "log timestamp precision <0-6>",
1731 "Logging control\n"
1732 "Timestamp configuration\n"
1733 "Set the timestamp precision\n"
1734 "Number of subsecond digits\n")
1735{
1736 return CMD_SUCCESS;
1737}
1738
1739DEFUNSH (VTYSH_ALL,
1740 no_vtysh_log_timestamp_precision,
1741 no_vtysh_log_timestamp_precision_cmd,
1742 "no log timestamp precision",
1743 NO_STR
1744 "Logging control\n"
1745 "Timestamp configuration\n"
1746 "Reset the timestamp precision to the default value of 0\n")
1747{
1748 return CMD_SUCCESS;
1749}
1750
1751DEFUNSH (VTYSH_ALL,
hassoe7168df2004-10-03 20:11:32 +00001752 vtysh_service_password_encrypt,
1753 vtysh_service_password_encrypt_cmd,
1754 "service password-encryption",
1755 "Set up miscellaneous service\n"
1756 "Enable encrypted passwords\n")
1757{
1758 return CMD_SUCCESS;
1759}
1760
1761DEFUNSH (VTYSH_ALL,
1762 no_vtysh_service_password_encrypt,
1763 no_vtysh_service_password_encrypt_cmd,
1764 "no service password-encryption",
1765 NO_STR
1766 "Set up miscellaneous service\n"
1767 "Enable encrypted passwords\n")
1768{
1769 return CMD_SUCCESS;
1770}
1771
1772DEFUNSH (VTYSH_ALL,
1773 vtysh_config_password,
1774 vtysh_password_cmd,
1775 "password (8|) WORD",
1776 "Assign the terminal connection password\n"
1777 "Specifies a HIDDEN password will follow\n"
1778 "dummy string \n"
1779 "The HIDDEN line password string\n")
1780{
1781 return CMD_SUCCESS;
1782}
1783
1784DEFUNSH (VTYSH_ALL,
1785 vtysh_password_text,
1786 vtysh_password_text_cmd,
1787 "password LINE",
1788 "Assign the terminal connection password\n"
1789 "The UNENCRYPTED (cleartext) line password\n")
1790{
1791 return CMD_SUCCESS;
1792}
1793
1794DEFUNSH (VTYSH_ALL,
1795 vtysh_config_enable_password,
1796 vtysh_enable_password_cmd,
1797 "enable password (8|) WORD",
1798 "Modify enable password parameters\n"
1799 "Assign the privileged level password\n"
1800 "Specifies a HIDDEN password will follow\n"
1801 "dummy string \n"
1802 "The HIDDEN 'enable' password string\n")
1803{
1804 return CMD_SUCCESS;
1805}
1806
1807DEFUNSH (VTYSH_ALL,
1808 vtysh_enable_password_text,
1809 vtysh_enable_password_text_cmd,
1810 "enable password LINE",
1811 "Modify enable password parameters\n"
1812 "Assign the privileged level password\n"
1813 "The UNENCRYPTED (cleartext) 'enable' password\n")
1814{
1815 return CMD_SUCCESS;
1816}
1817
1818DEFUNSH (VTYSH_ALL,
1819 no_vtysh_config_enable_password,
1820 no_vtysh_enable_password_cmd,
1821 "no enable password",
1822 NO_STR
1823 "Modify enable password parameters\n"
1824 "Assign the privileged level password\n")
1825{
1826 return CMD_SUCCESS;
1827}
1828
paul718e3742002-12-13 20:15:29 +00001829DEFUN (vtysh_write_terminal,
1830 vtysh_write_terminal_cmd,
1831 "write terminal",
1832 "Write running configuration to memory, network, or terminal\n"
1833 "Write to terminal\n")
1834{
ajsb1aa1472005-01-28 21:11:46 +00001835 u_int i;
paul718e3742002-12-13 20:15:29 +00001836 char line[] = "write terminal\n";
1837 FILE *fp = NULL;
1838
1839 if (vtysh_pager_name)
1840 {
paul4fc01e62002-12-13 20:49:00 +00001841 fp = popen (vtysh_pager_name, "w");
paul718e3742002-12-13 20:15:29 +00001842 if (fp == NULL)
1843 {
1844 perror ("popen");
1845 exit (1);
1846 }
1847 }
1848 else
1849 fp = stdout;
1850
1851 vty_out (vty, "Building configuration...%s", VTY_NEWLINE);
1852 vty_out (vty, "%sCurrent configuration:%s", VTY_NEWLINE,
1853 VTY_NEWLINE);
hassoe7168df2004-10-03 20:11:32 +00001854 vty_out (vty, "!%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001855
Balaji.G837d16c2012-09-26 14:09:10 +05301856 for (i = 0; i < array_size(vtysh_client); i++)
Gautam Kumarcc216b72015-10-26 13:22:12 -07001857 vtysh_client_execute (&vtysh_client[i], line, NULL);
paul718e3742002-12-13 20:15:29 +00001858
hassoe7168df2004-10-03 20:11:32 +00001859 /* Integrate vtysh specific configuration. */
1860 vtysh_config_write ();
1861
paul718e3742002-12-13 20:15:29 +00001862 vtysh_config_dump (fp);
1863
1864 if (vtysh_pager_name && fp)
1865 {
1866 fflush (fp);
1867 if (pclose (fp) == -1)
1868 {
1869 perror ("pclose");
1870 exit (1);
1871 }
1872 fp = NULL;
1873 }
1874
Chris Caputo6e79f8b2009-06-23 05:55:57 +00001875 vty_out (vty, "end%s", VTY_NEWLINE);
1876
paul718e3742002-12-13 20:15:29 +00001877 return CMD_SUCCESS;
1878}
1879
Donald Sharp9fb73e82015-09-22 11:13:12 -04001880DEFUN (vtysh_write_terminal_daemon,
1881 vtysh_write_terminal_daemon_cmd,
1882 "write terminal (zebra|ripd|ripngd|ospfd|ospf6d|bgpd|isisd|babeld)",
1883 "Write running configuration to memory, network, or terminal\n"
1884 "Write to terminal\n"
1885 "For the zebra daemon\n"
1886 "For the rip daemon\n"
1887 "For the ripng daemon\n"
1888 "For the ospf daemon\n"
1889 "For the ospfv6 daemon\n"
1890 "For the bgp daemon\n"
1891 "For the isis daemon\n"
1892 "For the babel daemon\n")
1893{
1894 unsigned int i;
1895 int ret = CMD_SUCCESS;
1896
1897 for (i = 0; i < array_size(vtysh_client); i++)
1898 {
1899 if (strcmp(vtysh_client[i].name, argv[0]) == 0)
1900 break;
1901 }
1902
Christian Franke5d9fae22016-06-14 20:07:09 +02001903 if (i == array_size(vtysh_client))
1904 return CMD_ERR_NO_MATCH;
1905
Donald Sharp9fb73e82015-09-22 11:13:12 -04001906 ret = vtysh_client_execute(&vtysh_client[i], "show running-config\n", stdout);
1907
1908 return ret;
1909}
1910
hassoe7168df2004-10-03 20:11:32 +00001911DEFUN (vtysh_integrated_config,
1912 vtysh_integrated_config_cmd,
1913 "service integrated-vtysh-config",
1914 "Set up miscellaneous service\n"
1915 "Write configuration into integrated file\n")
paul4fc01e62002-12-13 20:49:00 +00001916{
hassoe7168df2004-10-03 20:11:32 +00001917 vtysh_writeconfig_integrated = 1;
1918 return CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001919}
1920
hassoe7168df2004-10-03 20:11:32 +00001921DEFUN (no_vtysh_integrated_config,
1922 no_vtysh_integrated_config_cmd,
1923 "no service integrated-vtysh-config",
1924 NO_STR
1925 "Set up miscellaneous service\n"
1926 "Write configuration into integrated file\n")
paul4fc01e62002-12-13 20:49:00 +00001927{
hassoe7168df2004-10-03 20:11:32 +00001928 vtysh_writeconfig_integrated = 0;
1929 return CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001930}
1931
ajs274a4a42004-12-07 15:39:31 +00001932static int
1933write_config_integrated(void)
paul718e3742002-12-13 20:15:29 +00001934{
ajsb1aa1472005-01-28 21:11:46 +00001935 u_int i;
paul718e3742002-12-13 20:15:29 +00001936 char line[] = "write terminal\n";
1937 FILE *fp;
1938 char *integrate_sav = NULL;
1939
hasso95e735b2004-08-26 13:08:30 +00001940 integrate_sav = malloc (strlen (integrate_default) +
1941 strlen (CONF_BACKUP_EXT) + 1);
paul718e3742002-12-13 20:15:29 +00001942 strcpy (integrate_sav, integrate_default);
1943 strcat (integrate_sav, CONF_BACKUP_EXT);
1944
paul4fc01e62002-12-13 20:49:00 +00001945 fprintf (stdout,"Building Configuration...\n");
paul718e3742002-12-13 20:15:29 +00001946
hasso95e735b2004-08-26 13:08:30 +00001947 /* Move current configuration file to backup config file. */
paul718e3742002-12-13 20:15:29 +00001948 unlink (integrate_sav);
1949 rename (integrate_default, integrate_sav);
hasso95e735b2004-08-26 13:08:30 +00001950 free (integrate_sav);
paul4fc01e62002-12-13 20:49:00 +00001951
paul718e3742002-12-13 20:15:29 +00001952 fp = fopen (integrate_default, "w");
1953 if (fp == NULL)
1954 {
hasso95e735b2004-08-26 13:08:30 +00001955 fprintf (stdout,"%% Can't open configuration file %s.\n",
1956 integrate_default);
paul718e3742002-12-13 20:15:29 +00001957 return CMD_SUCCESS;
1958 }
paul718e3742002-12-13 20:15:29 +00001959
Balaji.G837d16c2012-09-26 14:09:10 +05301960 for (i = 0; i < array_size(vtysh_client); i++)
Gautam Kumarcc216b72015-10-26 13:22:12 -07001961 vtysh_client_execute (&vtysh_client[i], line, NULL);
paul718e3742002-12-13 20:15:29 +00001962
Donald Sharp147a8122015-05-21 16:06:21 -07001963 vtysh_config_write ();
paul718e3742002-12-13 20:15:29 +00001964 vtysh_config_dump (fp);
1965
1966 fclose (fp);
1967
gdtaa593d52003-12-22 20:15:53 +00001968 if (chmod (integrate_default, CONFIGFILE_MASK) != 0)
1969 {
1970 fprintf (stdout,"%% Can't chmod configuration file %s: %s (%d)\n",
ajs6099b3b2004-11-20 02:06:59 +00001971 integrate_default, safe_strerror(errno), errno);
gdtaa593d52003-12-22 20:15:53 +00001972 return CMD_WARNING;
1973 }
1974
paul4fc01e62002-12-13 20:49:00 +00001975 fprintf(stdout,"Integrated configuration saved to %s\n",integrate_default);
1976
1977 fprintf (stdout,"[OK]\n");
1978
paul718e3742002-12-13 20:15:29 +00001979 return CMD_SUCCESS;
1980}
1981
paul4fc01e62002-12-13 20:49:00 +00001982DEFUN (vtysh_write_memory,
1983 vtysh_write_memory_cmd,
1984 "write memory",
1985 "Write running configuration to memory, network, or terminal\n"
1986 "Write configuration to the file (same as write file)\n")
1987{
pauldfc0d9b2003-04-18 23:55:29 +00001988 int ret = CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001989 char line[] = "write memory\n";
ajsb1aa1472005-01-28 21:11:46 +00001990 u_int i;
paul4fc01e62002-12-13 20:49:00 +00001991
hassoe7168df2004-10-03 20:11:32 +00001992 /* If integrated Quagga.conf explicitely set. */
1993 if (vtysh_writeconfig_integrated)
1994 return write_config_integrated();
paul4fc01e62002-12-13 20:49:00 +00001995
1996 fprintf (stdout,"Building Configuration...\n");
1997
Balaji.G837d16c2012-09-26 14:09:10 +05301998 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00001999 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
hassoe7168df2004-10-03 20:11:32 +00002000
paul4fc01e62002-12-13 20:49:00 +00002001 fprintf (stdout,"[OK]\n");
2002
pauldfc0d9b2003-04-18 23:55:29 +00002003 return ret;
paul4fc01e62002-12-13 20:49:00 +00002004}
2005
paul718e3742002-12-13 20:15:29 +00002006ALIAS (vtysh_write_memory,
2007 vtysh_copy_runningconfig_startupconfig_cmd,
2008 "copy running-config startup-config",
2009 "Copy from one file to another\n"
2010 "Copy from current system configuration\n"
2011 "Copy to startup configuration\n")
2012
2013ALIAS (vtysh_write_memory,
2014 vtysh_write_file_cmd,
2015 "write file",
2016 "Write running configuration to memory, network, or terminal\n"
2017 "Write configuration to the file (same as write memory)\n")
2018
hasso4a6e2252003-05-25 11:51:29 +00002019ALIAS (vtysh_write_memory,
2020 vtysh_write_cmd,
2021 "write",
2022 "Write running configuration to memory, network, or terminal\n")
2023
paul718e3742002-12-13 20:15:29 +00002024ALIAS (vtysh_write_terminal,
2025 vtysh_show_running_config_cmd,
2026 "show running-config",
2027 SHOW_STR
2028 "Current operating configuration\n")
hassob094d262004-08-25 12:22:00 +00002029
Donald Sharp9fb73e82015-09-22 11:13:12 -04002030ALIAS (vtysh_write_terminal_daemon,
2031 vtysh_show_running_config_daemon_cmd,
2032 "show running-config (zebra|ripd|ripngd|ospfd|ospf6d|bgpd|isisd|babeld)",
2033 SHOW_STR
2034 "Current operating configuration\n"
2035 "For the zebra daemon\n"
2036 "For the rip daemon\n"
2037 "For the ripng daemon\n"
2038 "For the ospf daemon\n"
2039 "For the ospfv6 daemon\n"
2040 "For the bgp daemon\n"
2041 "For the isis daemon\n"
2042 "For the babel daemon\n")
2043
hasso34553cc2004-08-27 13:56:39 +00002044DEFUN (vtysh_terminal_length,
2045 vtysh_terminal_length_cmd,
2046 "terminal length <0-512>",
2047 "Set terminal line parameters\n"
2048 "Set number of lines on a screen\n"
2049 "Number of lines on screen (0 for no pausing)\n")
2050{
2051 int lines;
2052 char *endptr = NULL;
2053 char default_pager[10];
2054
2055 lines = strtol (argv[0], &endptr, 10);
2056 if (lines < 0 || lines > 512 || *endptr != '\0')
2057 {
2058 vty_out (vty, "length is malformed%s", VTY_NEWLINE);
2059 return CMD_WARNING;
2060 }
2061
2062 if (vtysh_pager_name)
2063 {
2064 free (vtysh_pager_name);
2065 vtysh_pager_name = NULL;
2066 }
2067
2068 if (lines != 0)
2069 {
2070 snprintf(default_pager, 10, "more -%i", lines);
2071 vtysh_pager_name = strdup (default_pager);
2072 }
2073
2074 return CMD_SUCCESS;
2075}
2076
2077DEFUN (vtysh_terminal_no_length,
2078 vtysh_terminal_no_length_cmd,
2079 "terminal no length",
2080 "Set terminal line parameters\n"
2081 NO_STR
2082 "Set number of lines on a screen\n")
2083{
2084 if (vtysh_pager_name)
2085 {
2086 free (vtysh_pager_name);
2087 vtysh_pager_name = NULL;
2088 }
2089
2090 vtysh_pager_init();
2091 return CMD_SUCCESS;
2092}
2093
hassof2799e62004-10-28 17:43:11 +00002094DEFUN (vtysh_show_daemons,
2095 vtysh_show_daemons_cmd,
2096 "show daemons",
hassoe7168df2004-10-03 20:11:32 +00002097 SHOW_STR
2098 "Show list of running daemons\n")
2099{
ajsb1aa1472005-01-28 21:11:46 +00002100 u_int i;
2101
Balaji.G837d16c2012-09-26 14:09:10 +05302102 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00002103 if ( vtysh_client[i].fd >= 0 )
2104 vty_out(vty, " %s", vtysh_client[i].name);
hassoe7168df2004-10-03 20:11:32 +00002105 vty_out(vty, "%s", VTY_NEWLINE);
2106
2107 return CMD_SUCCESS;
2108}
2109
paul718e3742002-12-13 20:15:29 +00002110/* Execute command in child process. */
ajs274a4a42004-12-07 15:39:31 +00002111static int
hasso5862ff52004-10-11 13:20:40 +00002112execute_command (const char *command, int argc, const char *arg1,
2113 const char *arg2)
paul718e3742002-12-13 20:15:29 +00002114{
paul718e3742002-12-13 20:15:29 +00002115 pid_t pid;
2116 int status;
2117
2118 /* Call fork(). */
2119 pid = fork ();
2120
2121 if (pid < 0)
2122 {
2123 /* Failure of fork(). */
ajs6099b3b2004-11-20 02:06:59 +00002124 fprintf (stderr, "Can't fork: %s\n", safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +00002125 exit (1);
2126 }
2127 else if (pid == 0)
2128 {
2129 /* This is child process. */
2130 switch (argc)
2131 {
2132 case 0:
David Lamparter6769f432015-03-04 07:18:24 +01002133 execlp (command, command, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00002134 break;
2135 case 1:
David Lamparter6769f432015-03-04 07:18:24 +01002136 execlp (command, command, arg1, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00002137 break;
2138 case 2:
David Lamparter6769f432015-03-04 07:18:24 +01002139 execlp (command, command, arg1, arg2, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00002140 break;
2141 }
2142
2143 /* When execlp suceed, this part is not executed. */
ajs6099b3b2004-11-20 02:06:59 +00002144 fprintf (stderr, "Can't execute %s: %s\n", command, safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +00002145 exit (1);
2146 }
2147 else
2148 {
2149 /* This is parent. */
2150 execute_flag = 1;
David Lamparter6769f432015-03-04 07:18:24 +01002151 wait4 (pid, &status, 0, NULL);
paul718e3742002-12-13 20:15:29 +00002152 execute_flag = 0;
2153 }
2154 return 0;
2155}
2156
2157DEFUN (vtysh_ping,
2158 vtysh_ping_cmd,
2159 "ping WORD",
hasso4eeccf12003-06-25 10:49:55 +00002160 "Send echo messages\n"
paul718e3742002-12-13 20:15:29 +00002161 "Ping destination address or hostname\n")
2162{
2163 execute_command ("ping", 1, argv[0], NULL);
2164 return CMD_SUCCESS;
2165}
2166
hasso4eeccf12003-06-25 10:49:55 +00002167ALIAS (vtysh_ping,
2168 vtysh_ping_ip_cmd,
2169 "ping ip WORD",
2170 "Send echo messages\n"
2171 "IP echo\n"
2172 "Ping destination address or hostname\n")
2173
paul718e3742002-12-13 20:15:29 +00002174DEFUN (vtysh_traceroute,
2175 vtysh_traceroute_cmd,
2176 "traceroute WORD",
2177 "Trace route to destination\n"
2178 "Trace route to destination address or hostname\n")
2179{
2180 execute_command ("traceroute", 1, argv[0], NULL);
2181 return CMD_SUCCESS;
2182}
2183
hasso4eeccf12003-06-25 10:49:55 +00002184ALIAS (vtysh_traceroute,
2185 vtysh_traceroute_ip_cmd,
2186 "traceroute ip WORD",
2187 "Trace route to destination\n"
2188 "IP trace\n"
2189 "Trace route to destination address or hostname\n")
2190
2191#ifdef HAVE_IPV6
2192DEFUN (vtysh_ping6,
2193 vtysh_ping6_cmd,
2194 "ping ipv6 WORD",
2195 "Send echo messages\n"
2196 "IPv6 echo\n"
2197 "Ping destination address or hostname\n")
2198{
2199 execute_command ("ping6", 1, argv[0], NULL);
2200 return CMD_SUCCESS;
2201}
2202
2203DEFUN (vtysh_traceroute6,
2204 vtysh_traceroute6_cmd,
2205 "traceroute ipv6 WORD",
2206 "Trace route to destination\n"
2207 "IPv6 trace\n"
2208 "Trace route to destination address or hostname\n")
2209{
2210 execute_command ("traceroute6", 1, argv[0], NULL);
2211 return CMD_SUCCESS;
2212}
2213#endif
2214
paul718e3742002-12-13 20:15:29 +00002215DEFUN (vtysh_telnet,
2216 vtysh_telnet_cmd,
2217 "telnet WORD",
2218 "Open a telnet connection\n"
2219 "IP address or hostname of a remote system\n")
2220{
2221 execute_command ("telnet", 1, argv[0], NULL);
2222 return CMD_SUCCESS;
2223}
2224
2225DEFUN (vtysh_telnet_port,
2226 vtysh_telnet_port_cmd,
2227 "telnet WORD PORT",
2228 "Open a telnet connection\n"
2229 "IP address or hostname of a remote system\n"
2230 "TCP Port number\n")
2231{
2232 execute_command ("telnet", 2, argv[0], argv[1]);
2233 return CMD_SUCCESS;
2234}
2235
paul5087df52003-01-25 06:56:09 +00002236DEFUN (vtysh_ssh,
2237 vtysh_ssh_cmd,
2238 "ssh WORD",
2239 "Open an ssh connection\n"
2240 "[user@]host\n")
2241{
2242 execute_command ("ssh", 1, argv[0], NULL);
2243 return CMD_SUCCESS;
2244}
2245
paul718e3742002-12-13 20:15:29 +00002246DEFUN (vtysh_start_shell,
2247 vtysh_start_shell_cmd,
2248 "start-shell",
2249 "Start UNIX shell\n")
2250{
2251 execute_command ("sh", 0, NULL, NULL);
2252 return CMD_SUCCESS;
2253}
2254
2255DEFUN (vtysh_start_bash,
2256 vtysh_start_bash_cmd,
2257 "start-shell bash",
2258 "Start UNIX shell\n"
2259 "Start bash\n")
2260{
2261 execute_command ("bash", 0, NULL, NULL);
2262 return CMD_SUCCESS;
2263}
2264
2265DEFUN (vtysh_start_zsh,
2266 vtysh_start_zsh_cmd,
2267 "start-shell zsh",
2268 "Start UNIX shell\n"
2269 "Start Z shell\n")
2270{
2271 execute_command ("zsh", 0, NULL, NULL);
2272 return CMD_SUCCESS;
2273}
hassob094d262004-08-25 12:22:00 +00002274
ajs274a4a42004-12-07 15:39:31 +00002275static void
paul718e3742002-12-13 20:15:29 +00002276vtysh_install_default (enum node_type node)
2277{
2278 install_element (node, &config_list_cmd);
2279}
2280
2281/* Making connection to protocol daemon. */
ajs274a4a42004-12-07 15:39:31 +00002282static int
ajsb1aa1472005-01-28 21:11:46 +00002283vtysh_connect (struct vtysh_client *vclient)
paul718e3742002-12-13 20:15:29 +00002284{
2285 int ret;
2286 int sock, len;
2287 struct sockaddr_un addr;
2288 struct stat s_stat;
paul718e3742002-12-13 20:15:29 +00002289
paul718e3742002-12-13 20:15:29 +00002290 /* Stat socket to see if we have permission to access it. */
ajsb1aa1472005-01-28 21:11:46 +00002291 ret = stat (vclient->path, &s_stat);
paul718e3742002-12-13 20:15:29 +00002292 if (ret < 0 && errno != ENOENT)
2293 {
2294 fprintf (stderr, "vtysh_connect(%s): stat = %s\n",
ajsb1aa1472005-01-28 21:11:46 +00002295 vclient->path, safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002296 exit(1);
2297 }
2298
2299 if (ret >= 0)
2300 {
2301 if (! S_ISSOCK(s_stat.st_mode))
2302 {
2303 fprintf (stderr, "vtysh_connect(%s): Not a socket\n",
ajsb1aa1472005-01-28 21:11:46 +00002304 vclient->path);
paul718e3742002-12-13 20:15:29 +00002305 exit (1);
2306 }
2307
paul718e3742002-12-13 20:15:29 +00002308 }
2309
2310 sock = socket (AF_UNIX, SOCK_STREAM, 0);
2311 if (sock < 0)
2312 {
2313#ifdef DEBUG
ajsb1aa1472005-01-28 21:11:46 +00002314 fprintf(stderr, "vtysh_connect(%s): socket = %s\n", vclient->path,
ajs6099b3b2004-11-20 02:06:59 +00002315 safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002316#endif /* DEBUG */
2317 return -1;
2318 }
2319
2320 memset (&addr, 0, sizeof (struct sockaddr_un));
2321 addr.sun_family = AF_UNIX;
ajsb1aa1472005-01-28 21:11:46 +00002322 strncpy (addr.sun_path, vclient->path, strlen (vclient->path));
Paul Jakma6f0e3f62007-05-10 02:38:51 +00002323#ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
paul718e3742002-12-13 20:15:29 +00002324 len = addr.sun_len = SUN_LEN(&addr);
2325#else
2326 len = sizeof (addr.sun_family) + strlen (addr.sun_path);
Paul Jakma6f0e3f62007-05-10 02:38:51 +00002327#endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
paul718e3742002-12-13 20:15:29 +00002328
2329 ret = connect (sock, (struct sockaddr *) &addr, len);
2330 if (ret < 0)
2331 {
2332#ifdef DEBUG
ajsb1aa1472005-01-28 21:11:46 +00002333 fprintf(stderr, "vtysh_connect(%s): connect = %s\n", vclient->path,
ajs6099b3b2004-11-20 02:06:59 +00002334 safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002335#endif /* DEBUG */
2336 close (sock);
2337 return -1;
2338 }
2339 vclient->fd = sock;
2340
2341 return 0;
2342}
2343
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002344int
2345vtysh_connect_all(const char *daemon_name)
paul718e3742002-12-13 20:15:29 +00002346{
ajsb1aa1472005-01-28 21:11:46 +00002347 u_int i;
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002348 int rc = 0;
2349 int matches = 0;
ajsb1aa1472005-01-28 21:11:46 +00002350
Balaji.G837d16c2012-09-26 14:09:10 +05302351 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00002352 {
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002353 if (!daemon_name || !strcmp(daemon_name, vtysh_client[i].name))
2354 {
2355 matches++;
2356 if (vtysh_connect(&vtysh_client[i]) == 0)
2357 rc++;
2358 /* We need direct access to ripd in vtysh_exit_ripd_only. */
2359 if (vtysh_client[i].flag == VTYSH_RIPD)
2360 ripd_client = &vtysh_client[i];
2361 }
ajsb1aa1472005-01-28 21:11:46 +00002362 }
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002363 if (!matches)
2364 fprintf(stderr, "Error: no daemons match name %s!\n", daemon_name);
2365 return rc;
paul718e3742002-12-13 20:15:29 +00002366}
2367
hasso95e735b2004-08-26 13:08:30 +00002368/* To disable readline's filename completion. */
ajs274a4a42004-12-07 15:39:31 +00002369static char *
pauldfc0d9b2003-04-18 23:55:29 +00002370vtysh_completion_entry_function (const char *ignore, int invoking_key)
paul718e3742002-12-13 20:15:29 +00002371{
pauldfc0d9b2003-04-18 23:55:29 +00002372 return NULL;
paul718e3742002-12-13 20:15:29 +00002373}
2374
2375void
ajsb1aa1472005-01-28 21:11:46 +00002376vtysh_readline_init (void)
paul718e3742002-12-13 20:15:29 +00002377{
2378 /* readline related settings. */
Sébastien Luttringer66d2ead2014-05-27 19:55:11 +02002379 rl_bind_key ('?', (rl_command_func_t *) vtysh_rl_describe);
paul68980082003-03-25 05:07:42 +00002380 rl_completion_entry_function = vtysh_completion_entry_function;
Sébastien Luttringer66d2ead2014-05-27 19:55:11 +02002381 rl_attempted_completion_function = (rl_completion_func_t *)new_completion;
paul718e3742002-12-13 20:15:29 +00002382}
2383
2384char *
ajsb1aa1472005-01-28 21:11:46 +00002385vtysh_prompt (void)
paul718e3742002-12-13 20:15:29 +00002386{
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002387 static struct utsname names;
paul718e3742002-12-13 20:15:29 +00002388 static char buf[100];
2389 const char*hostname;
2390 extern struct host host;
2391
2392 hostname = host.name;
2393
2394 if (!hostname)
2395 {
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002396 if (!names.nodename[0])
2397 uname (&names);
paul718e3742002-12-13 20:15:29 +00002398 hostname = names.nodename;
2399 }
2400
2401 snprintf (buf, sizeof buf, cmd_prompt (vty->node), hostname);
2402
2403 return buf;
2404}
2405
2406void
ajsb1aa1472005-01-28 21:11:46 +00002407vtysh_init_vty (void)
paul718e3742002-12-13 20:15:29 +00002408{
2409 /* Make vty structure. */
2410 vty = vty_new ();
2411 vty->type = VTY_SHELL;
2412 vty->node = VIEW_NODE;
2413
2414 /* Initialize commands. */
2415 cmd_init (0);
2416
2417 /* Install nodes. */
2418 install_node (&bgp_node, NULL);
2419 install_node (&rip_node, NULL);
2420 install_node (&interface_node, NULL);
Olivier Dugeonac10d302016-04-19 18:33:42 +02002421 install_node (&link_params_node, NULL);
paul718e3742002-12-13 20:15:29 +00002422 install_node (&rmap_node, NULL);
2423 install_node (&zebra_node, NULL);
2424 install_node (&bgp_vpnv4_node, NULL);
Lou Berger13c378d2016-01-12 13:41:56 -05002425 install_node (&bgp_vpnv6_node, NULL);
Lou Bergera3fda882016-01-12 13:42:04 -05002426 install_node (&bgp_encap_node, NULL);
2427 install_node (&bgp_encapv6_node, NULL);
paul718e3742002-12-13 20:15:29 +00002428 install_node (&bgp_ipv4_node, NULL);
2429 install_node (&bgp_ipv4m_node, NULL);
2430/* #ifdef HAVE_IPV6 */
2431 install_node (&bgp_ipv6_node, NULL);
paul57b5b7e2005-08-22 22:44:29 +00002432 install_node (&bgp_ipv6m_node, NULL);
paul718e3742002-12-13 20:15:29 +00002433/* #endif */
2434 install_node (&ospf_node, NULL);
2435/* #ifdef HAVE_IPV6 */
2436 install_node (&ripng_node, NULL);
2437 install_node (&ospf6_node, NULL);
2438/* #endif */
David Lamparteree53c8b2015-05-23 05:45:59 +02002439 install_node (&babel_node, NULL);
paul718e3742002-12-13 20:15:29 +00002440 install_node (&keychain_node, NULL);
2441 install_node (&keychain_key_node, NULL);
hassoc25e4582003-12-23 10:39:08 +00002442 install_node (&isis_node, NULL);
hassoe7168df2004-10-03 20:11:32 +00002443 install_node (&vty_node, NULL);
paul718e3742002-12-13 20:15:29 +00002444
2445 vtysh_install_default (VIEW_NODE);
2446 vtysh_install_default (ENABLE_NODE);
2447 vtysh_install_default (CONFIG_NODE);
2448 vtysh_install_default (BGP_NODE);
2449 vtysh_install_default (RIP_NODE);
2450 vtysh_install_default (INTERFACE_NODE);
Olivier Dugeonac10d302016-04-19 18:33:42 +02002451 vtysh_install_default (LINK_PARAMS_NODE);
paul718e3742002-12-13 20:15:29 +00002452 vtysh_install_default (RMAP_NODE);
2453 vtysh_install_default (ZEBRA_NODE);
2454 vtysh_install_default (BGP_VPNV4_NODE);
Lou Berger13c378d2016-01-12 13:41:56 -05002455 vtysh_install_default (BGP_VPNV6_NODE);
Lou Bergera3fda882016-01-12 13:42:04 -05002456 vtysh_install_default (BGP_ENCAP_NODE);
2457 vtysh_install_default (BGP_ENCAPV6_NODE);
paul718e3742002-12-13 20:15:29 +00002458 vtysh_install_default (BGP_IPV4_NODE);
2459 vtysh_install_default (BGP_IPV4M_NODE);
2460 vtysh_install_default (BGP_IPV6_NODE);
paul57b5b7e2005-08-22 22:44:29 +00002461 vtysh_install_default (BGP_IPV6M_NODE);
paul718e3742002-12-13 20:15:29 +00002462 vtysh_install_default (OSPF_NODE);
2463 vtysh_install_default (RIPNG_NODE);
2464 vtysh_install_default (OSPF6_NODE);
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +01002465 vtysh_install_default (BABEL_NODE);
hassoc25e4582003-12-23 10:39:08 +00002466 vtysh_install_default (ISIS_NODE);
paul718e3742002-12-13 20:15:29 +00002467 vtysh_install_default (KEYCHAIN_NODE);
2468 vtysh_install_default (KEYCHAIN_KEY_NODE);
hassoe7168df2004-10-03 20:11:32 +00002469 vtysh_install_default (VTY_NODE);
paul718e3742002-12-13 20:15:29 +00002470
2471 install_element (VIEW_NODE, &vtysh_enable_cmd);
2472 install_element (ENABLE_NODE, &vtysh_config_terminal_cmd);
2473 install_element (ENABLE_NODE, &vtysh_disable_cmd);
2474
2475 /* "exit" command. */
2476 install_element (VIEW_NODE, &vtysh_exit_all_cmd);
2477 install_element (VIEW_NODE, &vtysh_quit_all_cmd);
2478 install_element (CONFIG_NODE, &vtysh_exit_all_cmd);
2479 /* install_element (CONFIG_NODE, &vtysh_quit_all_cmd); */
2480 install_element (ENABLE_NODE, &vtysh_exit_all_cmd);
2481 install_element (ENABLE_NODE, &vtysh_quit_all_cmd);
2482 install_element (RIP_NODE, &vtysh_exit_ripd_cmd);
2483 install_element (RIP_NODE, &vtysh_quit_ripd_cmd);
paul68980082003-03-25 05:07:42 +00002484 install_element (RIPNG_NODE, &vtysh_exit_ripngd_cmd);
2485 install_element (RIPNG_NODE, &vtysh_quit_ripngd_cmd);
paul718e3742002-12-13 20:15:29 +00002486 install_element (OSPF_NODE, &vtysh_exit_ospfd_cmd);
2487 install_element (OSPF_NODE, &vtysh_quit_ospfd_cmd);
paul68980082003-03-25 05:07:42 +00002488 install_element (OSPF6_NODE, &vtysh_exit_ospf6d_cmd);
2489 install_element (OSPF6_NODE, &vtysh_quit_ospf6d_cmd);
paul718e3742002-12-13 20:15:29 +00002490 install_element (BGP_NODE, &vtysh_exit_bgpd_cmd);
2491 install_element (BGP_NODE, &vtysh_quit_bgpd_cmd);
2492 install_element (BGP_VPNV4_NODE, &vtysh_exit_bgpd_cmd);
2493 install_element (BGP_VPNV4_NODE, &vtysh_quit_bgpd_cmd);
Lou Berger13c378d2016-01-12 13:41:56 -05002494 install_element (BGP_VPNV6_NODE, &vtysh_exit_bgpd_cmd);
2495 install_element (BGP_VPNV6_NODE, &vtysh_quit_bgpd_cmd);
Lou Bergera3fda882016-01-12 13:42:04 -05002496 install_element (BGP_ENCAP_NODE, &vtysh_exit_bgpd_cmd);
2497 install_element (BGP_ENCAP_NODE, &vtysh_quit_bgpd_cmd);
2498 install_element (BGP_ENCAPV6_NODE, &vtysh_exit_bgpd_cmd);
2499 install_element (BGP_ENCAPV6_NODE, &vtysh_quit_bgpd_cmd);
paul718e3742002-12-13 20:15:29 +00002500 install_element (BGP_IPV4_NODE, &vtysh_exit_bgpd_cmd);
2501 install_element (BGP_IPV4_NODE, &vtysh_quit_bgpd_cmd);
2502 install_element (BGP_IPV4M_NODE, &vtysh_exit_bgpd_cmd);
2503 install_element (BGP_IPV4M_NODE, &vtysh_quit_bgpd_cmd);
2504 install_element (BGP_IPV6_NODE, &vtysh_exit_bgpd_cmd);
2505 install_element (BGP_IPV6_NODE, &vtysh_quit_bgpd_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002506 install_element (BGP_IPV6M_NODE, &vtysh_exit_bgpd_cmd);
2507 install_element (BGP_IPV6M_NODE, &vtysh_quit_bgpd_cmd);
hassoc25e4582003-12-23 10:39:08 +00002508 install_element (ISIS_NODE, &vtysh_exit_isisd_cmd);
2509 install_element (ISIS_NODE, &vtysh_quit_isisd_cmd);
paul718e3742002-12-13 20:15:29 +00002510 install_element (KEYCHAIN_NODE, &vtysh_exit_ripd_cmd);
2511 install_element (KEYCHAIN_NODE, &vtysh_quit_ripd_cmd);
2512 install_element (KEYCHAIN_KEY_NODE, &vtysh_exit_ripd_cmd);
2513 install_element (KEYCHAIN_KEY_NODE, &vtysh_quit_ripd_cmd);
2514 install_element (RMAP_NODE, &vtysh_exit_rmap_cmd);
2515 install_element (RMAP_NODE, &vtysh_quit_rmap_cmd);
hassoe7168df2004-10-03 20:11:32 +00002516 install_element (VTY_NODE, &vtysh_exit_line_vty_cmd);
2517 install_element (VTY_NODE, &vtysh_quit_line_vty_cmd);
paul718e3742002-12-13 20:15:29 +00002518
2519 /* "end" command. */
2520 install_element (CONFIG_NODE, &vtysh_end_all_cmd);
2521 install_element (ENABLE_NODE, &vtysh_end_all_cmd);
2522 install_element (RIP_NODE, &vtysh_end_all_cmd);
2523 install_element (RIPNG_NODE, &vtysh_end_all_cmd);
2524 install_element (OSPF_NODE, &vtysh_end_all_cmd);
2525 install_element (OSPF6_NODE, &vtysh_end_all_cmd);
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +01002526 install_element (BABEL_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002527 install_element (BGP_NODE, &vtysh_end_all_cmd);
2528 install_element (BGP_IPV4_NODE, &vtysh_end_all_cmd);
2529 install_element (BGP_IPV4M_NODE, &vtysh_end_all_cmd);
2530 install_element (BGP_VPNV4_NODE, &vtysh_end_all_cmd);
Lou Berger13c378d2016-01-12 13:41:56 -05002531 install_element (BGP_VPNV6_NODE, &vtysh_end_all_cmd);
Lou Bergera3fda882016-01-12 13:42:04 -05002532 install_element (BGP_ENCAP_NODE, &vtysh_end_all_cmd);
2533 install_element (BGP_ENCAPV6_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002534 install_element (BGP_IPV6_NODE, &vtysh_end_all_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002535 install_element (BGP_IPV6M_NODE, &vtysh_end_all_cmd);
hassoc25e4582003-12-23 10:39:08 +00002536 install_element (ISIS_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002537 install_element (KEYCHAIN_NODE, &vtysh_end_all_cmd);
2538 install_element (KEYCHAIN_KEY_NODE, &vtysh_end_all_cmd);
2539 install_element (RMAP_NODE, &vtysh_end_all_cmd);
hassoe7168df2004-10-03 20:11:32 +00002540 install_element (VTY_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002541
paul338a9912003-03-01 15:44:10 +00002542 install_element (INTERFACE_NODE, &interface_desc_cmd);
paul464dc8d2003-03-28 02:25:45 +00002543 install_element (INTERFACE_NODE, &no_interface_desc_cmd);
paul718e3742002-12-13 20:15:29 +00002544 install_element (INTERFACE_NODE, &vtysh_end_all_cmd);
2545 install_element (INTERFACE_NODE, &vtysh_exit_interface_cmd);
Olivier Dugeonac10d302016-04-19 18:33:42 +02002546 install_element (LINK_PARAMS_NODE, &vtysh_end_all_cmd);
2547 install_element (LINK_PARAMS_NODE, &vtysh_exit_interface_cmd);
paul718e3742002-12-13 20:15:29 +00002548 install_element (INTERFACE_NODE, &vtysh_quit_interface_cmd);
2549 install_element (CONFIG_NODE, &router_rip_cmd);
2550#ifdef HAVE_IPV6
2551 install_element (CONFIG_NODE, &router_ripng_cmd);
2552#endif
2553 install_element (CONFIG_NODE, &router_ospf_cmd);
2554#ifdef HAVE_IPV6
2555 install_element (CONFIG_NODE, &router_ospf6_cmd);
2556#endif
hassoc25e4582003-12-23 10:39:08 +00002557 install_element (CONFIG_NODE, &router_isis_cmd);
paul718e3742002-12-13 20:15:29 +00002558 install_element (CONFIG_NODE, &router_bgp_cmd);
Paul Jakma10895fd2008-07-03 19:34:48 +00002559 install_element (CONFIG_NODE, &router_bgp_view_cmd);
paul718e3742002-12-13 20:15:29 +00002560 install_element (BGP_NODE, &address_family_vpnv4_cmd);
2561 install_element (BGP_NODE, &address_family_vpnv4_unicast_cmd);
Lou Berger13c378d2016-01-12 13:41:56 -05002562 install_element (BGP_NODE, &address_family_vpnv6_cmd);
2563 install_element (BGP_NODE, &address_family_vpnv6_unicast_cmd);
Lou Bergera3fda882016-01-12 13:42:04 -05002564 install_element (BGP_NODE, &address_family_encap_cmd);
2565 install_element (BGP_NODE, &address_family_encapv6_cmd);
paul718e3742002-12-13 20:15:29 +00002566 install_element (BGP_NODE, &address_family_ipv4_unicast_cmd);
2567 install_element (BGP_NODE, &address_family_ipv4_multicast_cmd);
2568#ifdef HAVE_IPV6
2569 install_element (BGP_NODE, &address_family_ipv6_cmd);
2570 install_element (BGP_NODE, &address_family_ipv6_unicast_cmd);
viveka4f40292015-11-09 20:21:46 -05002571 install_element (BGP_NODE, &address_family_ipv6_multicast_cmd);
paul718e3742002-12-13 20:15:29 +00002572#endif
2573 install_element (BGP_VPNV4_NODE, &exit_address_family_cmd);
Lou Berger13c378d2016-01-12 13:41:56 -05002574 install_element (BGP_VPNV6_NODE, &exit_address_family_cmd);
Lou Bergera3fda882016-01-12 13:42:04 -05002575 install_element (BGP_ENCAP_NODE, &exit_address_family_cmd);
2576 install_element (BGP_ENCAPV6_NODE, &exit_address_family_cmd);
paul718e3742002-12-13 20:15:29 +00002577 install_element (BGP_IPV4_NODE, &exit_address_family_cmd);
2578 install_element (BGP_IPV4M_NODE, &exit_address_family_cmd);
2579 install_element (BGP_IPV6_NODE, &exit_address_family_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002580 install_element (BGP_IPV6M_NODE, &exit_address_family_cmd);
paul718e3742002-12-13 20:15:29 +00002581 install_element (CONFIG_NODE, &key_chain_cmd);
2582 install_element (CONFIG_NODE, &route_map_cmd);
hassoe7168df2004-10-03 20:11:32 +00002583 install_element (CONFIG_NODE, &vtysh_line_vty_cmd);
paul718e3742002-12-13 20:15:29 +00002584 install_element (KEYCHAIN_NODE, &key_cmd);
2585 install_element (KEYCHAIN_NODE, &key_chain_cmd);
2586 install_element (KEYCHAIN_KEY_NODE, &key_chain_cmd);
2587 install_element (CONFIG_NODE, &vtysh_interface_cmd);
paul32d24632003-05-23 09:25:20 +00002588 install_element (CONFIG_NODE, &vtysh_no_interface_cmd);
Feng Lu471ea392015-05-22 11:40:00 +02002589 install_element (CONFIG_NODE, &vtysh_interface_vrf_cmd);
2590 install_element (CONFIG_NODE, &vtysh_no_interface_vrf_cmd);
Olivier Dugeonac10d302016-04-19 18:33:42 +02002591 install_element (INTERFACE_NODE, &vtysh_link_params_cmd);
paul718e3742002-12-13 20:15:29 +00002592 install_element (ENABLE_NODE, &vtysh_show_running_config_cmd);
Donald Sharp9fb73e82015-09-22 11:13:12 -04002593 install_element (ENABLE_NODE, &vtysh_show_running_config_daemon_cmd);
paul718e3742002-12-13 20:15:29 +00002594 install_element (ENABLE_NODE, &vtysh_copy_runningconfig_startupconfig_cmd);
2595 install_element (ENABLE_NODE, &vtysh_write_file_cmd);
hasso4a6e2252003-05-25 11:51:29 +00002596 install_element (ENABLE_NODE, &vtysh_write_cmd);
paul718e3742002-12-13 20:15:29 +00002597
hasso95e735b2004-08-26 13:08:30 +00002598 /* "write terminal" command. */
paul718e3742002-12-13 20:15:29 +00002599 install_element (ENABLE_NODE, &vtysh_write_terminal_cmd);
Donald Sharp9fb73e82015-09-22 11:13:12 -04002600 install_element (ENABLE_NODE, &vtysh_write_terminal_daemon_cmd);
Donald Sharp07440402016-02-25 07:39:45 -05002601
hassoe7168df2004-10-03 20:11:32 +00002602 install_element (CONFIG_NODE, &vtysh_integrated_config_cmd);
2603 install_element (CONFIG_NODE, &no_vtysh_integrated_config_cmd);
paul718e3742002-12-13 20:15:29 +00002604
hasso95e735b2004-08-26 13:08:30 +00002605 /* "write memory" command. */
paul718e3742002-12-13 20:15:29 +00002606 install_element (ENABLE_NODE, &vtysh_write_memory_cmd);
paul718e3742002-12-13 20:15:29 +00002607
hasso34553cc2004-08-27 13:56:39 +00002608 install_element (VIEW_NODE, &vtysh_terminal_length_cmd);
2609 install_element (ENABLE_NODE, &vtysh_terminal_length_cmd);
2610 install_element (VIEW_NODE, &vtysh_terminal_no_length_cmd);
2611 install_element (ENABLE_NODE, &vtysh_terminal_no_length_cmd);
hassof2799e62004-10-28 17:43:11 +00002612 install_element (VIEW_NODE, &vtysh_show_daemons_cmd);
2613 install_element (ENABLE_NODE, &vtysh_show_daemons_cmd);
hasso34553cc2004-08-27 13:56:39 +00002614
paul718e3742002-12-13 20:15:29 +00002615 install_element (VIEW_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002616 install_element (VIEW_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00002617 install_element (VIEW_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002618 install_element (VIEW_NODE, &vtysh_traceroute_ip_cmd);
2619#ifdef HAVE_IPV6
2620 install_element (VIEW_NODE, &vtysh_ping6_cmd);
2621 install_element (VIEW_NODE, &vtysh_traceroute6_cmd);
2622#endif
paul718e3742002-12-13 20:15:29 +00002623 install_element (VIEW_NODE, &vtysh_telnet_cmd);
2624 install_element (VIEW_NODE, &vtysh_telnet_port_cmd);
paul5087df52003-01-25 06:56:09 +00002625 install_element (VIEW_NODE, &vtysh_ssh_cmd);
paul718e3742002-12-13 20:15:29 +00002626 install_element (ENABLE_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002627 install_element (ENABLE_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00002628 install_element (ENABLE_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002629 install_element (ENABLE_NODE, &vtysh_traceroute_ip_cmd);
2630#ifdef HAVE_IPV6
2631 install_element (ENABLE_NODE, &vtysh_ping6_cmd);
2632 install_element (ENABLE_NODE, &vtysh_traceroute6_cmd);
2633#endif
paul718e3742002-12-13 20:15:29 +00002634 install_element (ENABLE_NODE, &vtysh_telnet_cmd);
2635 install_element (ENABLE_NODE, &vtysh_telnet_port_cmd);
hasso67e29ab2004-08-26 22:21:31 +00002636 install_element (ENABLE_NODE, &vtysh_ssh_cmd);
paul718e3742002-12-13 20:15:29 +00002637 install_element (ENABLE_NODE, &vtysh_start_shell_cmd);
2638 install_element (ENABLE_NODE, &vtysh_start_bash_cmd);
2639 install_element (ENABLE_NODE, &vtysh_start_zsh_cmd);
Paul Jakmadbf7d132006-05-23 22:10:01 +00002640
Paul Jakma362b4032006-05-28 07:54:45 +00002641 install_element (VIEW_NODE, &vtysh_show_memory_cmd);
2642 install_element (ENABLE_NODE, &vtysh_show_memory_cmd);
2643
Donald Sharp567a6382015-08-19 21:22:17 -04002644 install_element (VIEW_NODE, &vtysh_show_work_queues_cmd);
2645 install_element (ENABLE_NODE, &vtysh_show_work_queues_cmd);
Donald Sharp07440402016-02-25 07:39:45 -05002646 install_element (ENABLE_NODE, &vtysh_show_work_queues_daemon_cmd);
2647 install_element (VIEW_NODE, &vtysh_show_work_queues_daemon_cmd);
Donald Sharp567a6382015-08-19 21:22:17 -04002648
2649 install_element (VIEW_NODE, &vtysh_show_thread_cmd);
2650 install_element (ENABLE_NODE, &vtysh_show_thread_cmd);
2651
Paul Jakmadbf7d132006-05-23 22:10:01 +00002652 /* Logging */
2653 install_element (ENABLE_NODE, &vtysh_show_logging_cmd);
2654 install_element (VIEW_NODE, &vtysh_show_logging_cmd);
paul718e3742002-12-13 20:15:29 +00002655 install_element (CONFIG_NODE, &vtysh_log_stdout_cmd);
ajs274a4a42004-12-07 15:39:31 +00002656 install_element (CONFIG_NODE, &vtysh_log_stdout_level_cmd);
paul718e3742002-12-13 20:15:29 +00002657 install_element (CONFIG_NODE, &no_vtysh_log_stdout_cmd);
2658 install_element (CONFIG_NODE, &vtysh_log_file_cmd);
ajs274a4a42004-12-07 15:39:31 +00002659 install_element (CONFIG_NODE, &vtysh_log_file_level_cmd);
paul718e3742002-12-13 20:15:29 +00002660 install_element (CONFIG_NODE, &no_vtysh_log_file_cmd);
ajs274a4a42004-12-07 15:39:31 +00002661 install_element (CONFIG_NODE, &no_vtysh_log_file_level_cmd);
2662 install_element (CONFIG_NODE, &vtysh_log_monitor_cmd);
2663 install_element (CONFIG_NODE, &vtysh_log_monitor_level_cmd);
2664 install_element (CONFIG_NODE, &no_vtysh_log_monitor_cmd);
paul718e3742002-12-13 20:15:29 +00002665 install_element (CONFIG_NODE, &vtysh_log_syslog_cmd);
ajs274a4a42004-12-07 15:39:31 +00002666 install_element (CONFIG_NODE, &vtysh_log_syslog_level_cmd);
paul718e3742002-12-13 20:15:29 +00002667 install_element (CONFIG_NODE, &no_vtysh_log_syslog_cmd);
2668 install_element (CONFIG_NODE, &vtysh_log_trap_cmd);
2669 install_element (CONFIG_NODE, &no_vtysh_log_trap_cmd);
ajs274a4a42004-12-07 15:39:31 +00002670 install_element (CONFIG_NODE, &vtysh_log_facility_cmd);
2671 install_element (CONFIG_NODE, &no_vtysh_log_facility_cmd);
paul718e3742002-12-13 20:15:29 +00002672 install_element (CONFIG_NODE, &vtysh_log_record_priority_cmd);
2673 install_element (CONFIG_NODE, &no_vtysh_log_record_priority_cmd);
Andrew J. Schorrc749b722007-04-29 03:53:31 +00002674 install_element (CONFIG_NODE, &vtysh_log_timestamp_precision_cmd);
2675 install_element (CONFIG_NODE, &no_vtysh_log_timestamp_precision_cmd);
hassoe7168df2004-10-03 20:11:32 +00002676
2677 install_element (CONFIG_NODE, &vtysh_service_password_encrypt_cmd);
2678 install_element (CONFIG_NODE, &no_vtysh_service_password_encrypt_cmd);
2679
2680 install_element (CONFIG_NODE, &vtysh_password_cmd);
2681 install_element (CONFIG_NODE, &vtysh_password_text_cmd);
2682 install_element (CONFIG_NODE, &vtysh_enable_password_cmd);
2683 install_element (CONFIG_NODE, &vtysh_enable_password_text_cmd);
2684 install_element (CONFIG_NODE, &no_vtysh_enable_password_cmd);
2685
paul718e3742002-12-13 20:15:29 +00002686}