blob: 2e2203da61d7becd0188e48adb7ed1bfde65ff43 [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");
140 return CMD_WARNING;
141 }
142
143 readln = (buf + bufsz) - pbuf - 1;
144 nbytes = read (vclient->fd, pbuf, readln);
145
146 if (nbytes <= 0)
147 {
148
149 if (errno == EINTR)
150 continue;
151
152 fprintf(stderr, ERR_WHERE_STRING "(%u)", errno);
153 perror("");
154
155 if (errno == EAGAIN || errno == EIO)
156 continue;
157
158 vclient_close (vclient);
159 XFREE(MTYPE_TMP, buf);
160 return CMD_SUCCESS;
161 }
Gautam Kumarcc216b72015-10-26 13:22:12 -0700162 /* If we have already seen 3 nulls, then current byte is ret code */
163 if ((numnulls == 3) && (nbytes == 1))
164 {
165 ret = pbuf[0];
166 break;
167 }
paul718e3742002-12-13 20:15:29 +0000168
169 pbuf[nbytes] = '\0';
170
Gautam Kumarcc216b72015-10-26 13:22:12 -0700171 /* If the config needs to be written in file or stdout */
172 if (fp)
173 {
174 fputs(pbuf, fp);
175 fflush (fp);
176 }
paul718e3742002-12-13 20:15:29 +0000177
Gautam Kumarcc216b72015-10-26 13:22:12 -0700178 /* At max look last four bytes */
179 if (nbytes >= 4)
180 {
181 i = nbytes - 4;
182 numnulls = 0;
183 }
184 else
185 i = 0;
paul718e3742002-12-13 20:15:29 +0000186
Gautam Kumarcc216b72015-10-26 13:22:12 -0700187 /* Count the numnulls */
188 while (i < nbytes && numnulls <3)
189 {
190 if (pbuf[i++] == '\0')
191 numnulls++;
192 else
193 numnulls = 0;
194 }
195 /* We might have seen 3 consecutive nulls so store the ret code before updating pbuf*/
196 ret = pbuf[nbytes-1];
197 pbuf += nbytes;
paul718e3742002-12-13 20:15:29 +0000198
Gautam Kumarcc216b72015-10-26 13:22:12 -0700199 /* See if a line exists in buffer, if so parse and consume it, and
200 * reset read position. If 3 nulls has been encountered consume the buffer before
201 * next read.
202 */
203 if (((eoln = strrchr(buf, '\n')) == NULL) && (numnulls<3))
204 continue;
205
206 if (eoln >= ((buf + bufsz) - 1))
207 {
208 fprintf (stderr, ERR_WHERE_STRING \
209 "warning - eoln beyond buffer end.\n");
210 }
211
212 /* If the config needs parsing, consume it */
213 if(!fp)
214 vtysh_config_parse(buf);
215
216 eoln++;
217 left = (size_t)(buf + bufsz - eoln);
218 /*
219 * This check is required since when a config line split between two consecutive reads,
220 * then buf will have first half of config line and current read will bring rest of the
221 * line. So in this case eoln will be 1 here, hence calculation of left will be wrong.
222 * In this case we don't need to do memmove, because we have already seen 3 nulls.
223 */
224 if(left < bufsz)
225 memmove(buf, eoln, left);
226
227 buf[bufsz-1] = '\0';
228 pbuf = buf + strlen(buf);
229 /* got 3 or more trailing NULs? */
230 if ((numnulls >=3) && (i < nbytes))
231 {
232 break;
233 }
paul718e3742002-12-13 20:15:29 +0000234 }
235
Gautam Kumarcc216b72015-10-26 13:22:12 -0700236 if(!fp)
237 vtysh_config_parse (buf);
paul718e3742002-12-13 20:15:29 +0000238
239 XFREE(MTYPE_TMP, buf);
240 return ret;
241}
Gautam Kumarcc216b72015-10-26 13:22:12 -0700242
paul718e3742002-12-13 20:15:29 +0000243
paul718e3742002-12-13 20:15:29 +0000244void
ajsb1aa1472005-01-28 21:11:46 +0000245vtysh_pager_init (void)
paul718e3742002-12-13 20:15:29 +0000246{
hasso5a9c53d2004-08-27 14:23:28 +0000247 char *pager_defined;
248
249 pager_defined = getenv ("VTYSH_PAGER");
250
251 if (pager_defined)
252 vtysh_pager_name = strdup (pager_defined);
253 else
hasso34553cc2004-08-27 13:56:39 +0000254 vtysh_pager_name = strdup ("more");
paul718e3742002-12-13 20:15:29 +0000255}
256
257/* Command execution over the vty interface. */
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700258static int
hassodda09522004-10-07 21:40:25 +0000259vtysh_execute_func (const char *line, int pager)
paul718e3742002-12-13 20:15:29 +0000260{
Stephen Hemminger2c4d48b2008-07-28 15:04:56 -0700261 int ret, cmd_stat;
ajsb1aa1472005-01-28 21:11:46 +0000262 u_int i;
paul718e3742002-12-13 20:15:29 +0000263 vector vline;
264 struct cmd_element *cmd;
265 FILE *fp = NULL;
hasso13bfca72005-01-23 21:42:25 +0000266 int closepager = 0;
267 int tried = 0;
268 int saved_ret, saved_node;
paul718e3742002-12-13 20:15:29 +0000269
hasso95e735b2004-08-26 13:08:30 +0000270 /* Split readline string up into the vector. */
paul718e3742002-12-13 20:15:29 +0000271 vline = cmd_make_strvec (line);
272
273 if (vline == NULL)
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700274 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000275
hasso13bfca72005-01-23 21:42:25 +0000276 saved_ret = ret = cmd_execute_command (vline, vty, &cmd, 1);
277 saved_node = vty->node;
278
279 /* If command doesn't succeeded in current node, try to walk up in node tree.
280 * Changing vty->node is enough to try it just out without actual walkup in
281 * the vtysh. */
282 while (ret != CMD_SUCCESS && ret != CMD_SUCCESS_DAEMON && ret != CMD_WARNING
283 && vty->node > CONFIG_NODE)
284 {
285 vty->node = node_parent(vty->node);
286 ret = cmd_execute_command (vline, vty, &cmd, 1);
287 tried++;
288 }
289
290 vty->node = saved_node;
291
292 /* If command succeeded in any other node than current (tried > 0) we have
293 * to move into node in the vtysh where it succeeded. */
294 if (ret == CMD_SUCCESS || ret == CMD_SUCCESS_DAEMON || ret == CMD_WARNING)
295 {
Lou Berger82dd7072016-01-12 13:41:57 -0500296 if ((saved_node == BGP_VPNV4_NODE || saved_node == BGP_VPNV6_NODE
Lou Bergera3fda882016-01-12 13:42:04 -0500297 || saved_node == BGP_ENCAP_NODE || saved_node == BGP_ENCAPV6_NODE
Lou Berger13c378d2016-01-12 13:41:56 -0500298 || saved_node == BGP_IPV4_NODE
paul57b5b7e2005-08-22 22:44:29 +0000299 || saved_node == BGP_IPV6_NODE || saved_node == BGP_IPV4M_NODE
300 || saved_node == BGP_IPV6M_NODE)
hasso13bfca72005-01-23 21:42:25 +0000301 && (tried == 1))
302 {
303 vtysh_execute("exit-address-family");
304 }
305 else if ((saved_node == KEYCHAIN_KEY_NODE) && (tried == 1))
306 {
307 vtysh_execute("exit");
308 }
309 else if (tried)
310 {
311 vtysh_execute ("end");
312 vtysh_execute ("configure terminal");
313 }
314 }
315 /* If command didn't succeed in any node, continue with return value from
316 * first try. */
317 else if (tried)
318 {
319 ret = saved_ret;
320 }
paul718e3742002-12-13 20:15:29 +0000321
322 cmd_free_strvec (vline);
323
Stephen Hemminger2c4d48b2008-07-28 15:04:56 -0700324 cmd_stat = ret;
paul718e3742002-12-13 20:15:29 +0000325 switch (ret)
326 {
327 case CMD_WARNING:
328 if (vty->type == VTY_FILE)
paul4fc01e62002-12-13 20:49:00 +0000329 fprintf (stdout,"Warning...\n");
paul718e3742002-12-13 20:15:29 +0000330 break;
331 case CMD_ERR_AMBIGUOUS:
paul4fc01e62002-12-13 20:49:00 +0000332 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000333 break;
334 case CMD_ERR_NO_MATCH:
paul4fc01e62002-12-13 20:49:00 +0000335 fprintf (stdout,"%% Unknown command.\n");
paul718e3742002-12-13 20:15:29 +0000336 break;
337 case CMD_ERR_INCOMPLETE:
paul4fc01e62002-12-13 20:49:00 +0000338 fprintf (stdout,"%% Command incomplete.\n");
paul718e3742002-12-13 20:15:29 +0000339 break;
340 case CMD_SUCCESS_DAEMON:
341 {
hasso97b7db22004-10-20 19:07:48 +0000342 /* FIXME: Don't open pager for exit commands. popen() causes problems
343 * if exited from vtysh at all. This hack shouldn't cause any problem
344 * but is really ugly. */
345 if (pager && vtysh_pager_name && (strncmp(line, "exit", 4) != 0))
paul718e3742002-12-13 20:15:29 +0000346 {
paul4fc01e62002-12-13 20:49:00 +0000347 fp = popen (vtysh_pager_name, "w");
paul718e3742002-12-13 20:15:29 +0000348 if (fp == NULL)
349 {
paula805cc22003-05-01 14:29:48 +0000350 perror ("popen failed for pager");
351 fp = stdout;
paul718e3742002-12-13 20:15:29 +0000352 }
paula805cc22003-05-01 14:29:48 +0000353 else
354 closepager=1;
paul718e3742002-12-13 20:15:29 +0000355 }
356 else
357 fp = stdout;
358
359 if (! strcmp(cmd->string,"configure terminal"))
360 {
Balaji.G837d16c2012-09-26 14:09:10 +0530361 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +0000362 {
363 cmd_stat = vtysh_client_execute(&vtysh_client[i], line, fp);
364 if (cmd_stat == CMD_WARNING)
365 break;
366 }
367
paul718e3742002-12-13 20:15:29 +0000368 if (cmd_stat)
369 {
hassob094d262004-08-25 12:22:00 +0000370 line = "end";
371 vline = cmd_make_strvec (line);
paul718e3742002-12-13 20:15:29 +0000372
hassob094d262004-08-25 12:22:00 +0000373 if (vline == NULL)
paul718e3742002-12-13 20:15:29 +0000374 {
paula805cc22003-05-01 14:29:48 +0000375 if (pager && vtysh_pager_name && fp && closepager)
paul718e3742002-12-13 20:15:29 +0000376 {
377 if (pclose (fp) == -1)
378 {
paula805cc22003-05-01 14:29:48 +0000379 perror ("pclose failed for pager");
paul718e3742002-12-13 20:15:29 +0000380 }
381 fp = NULL;
382 }
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700383 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000384 }
385
hasso87d683b2005-01-16 23:31:54 +0000386 ret = cmd_execute_command (vline, vty, &cmd, 1);
hassob094d262004-08-25 12:22:00 +0000387 cmd_free_strvec (vline);
388 if (ret != CMD_SUCCESS_DAEMON)
389 break;
paul718e3742002-12-13 20:15:29 +0000390 }
391 else
392 if (cmd->func)
393 {
394 (*cmd->func) (cmd, vty, 0, NULL);
395 break;
hassob094d262004-08-25 12:22:00 +0000396 }
paul718e3742002-12-13 20:15:29 +0000397 }
398
ajsb1aa1472005-01-28 21:11:46 +0000399 cmd_stat = CMD_SUCCESS;
Balaji.G837d16c2012-09-26 14:09:10 +0530400 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +0000401 {
402 if (cmd->daemon & vtysh_client[i].flag)
403 {
404 cmd_stat = vtysh_client_execute(&vtysh_client[i], line, fp);
405 if (cmd_stat != CMD_SUCCESS)
406 break;
407 }
408 }
409 if (cmd_stat != CMD_SUCCESS)
410 break;
411
paul718e3742002-12-13 20:15:29 +0000412 if (cmd->func)
413 (*cmd->func) (cmd, vty, 0, NULL);
414 }
415 }
paula805cc22003-05-01 14:29:48 +0000416 if (pager && vtysh_pager_name && fp && closepager)
paul718e3742002-12-13 20:15:29 +0000417 {
418 if (pclose (fp) == -1)
419 {
paula805cc22003-05-01 14:29:48 +0000420 perror ("pclose failed for pager");
paul718e3742002-12-13 20:15:29 +0000421 }
422 fp = NULL;
423 }
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700424 return cmd_stat;
paul718e3742002-12-13 20:15:29 +0000425}
426
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700427int
hassodda09522004-10-07 21:40:25 +0000428vtysh_execute_no_pager (const char *line)
paul718e3742002-12-13 20:15:29 +0000429{
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700430 return vtysh_execute_func (line, 0);
paul718e3742002-12-13 20:15:29 +0000431}
432
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700433int
hassodda09522004-10-07 21:40:25 +0000434vtysh_execute (const char *line)
paul718e3742002-12-13 20:15:29 +0000435{
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700436 return vtysh_execute_func (line, 1);
paul718e3742002-12-13 20:15:29 +0000437}
438
439/* Configration make from file. */
440int
441vtysh_config_from_file (struct vty *vty, FILE *fp)
442{
443 int ret;
paul718e3742002-12-13 20:15:29 +0000444 struct cmd_element *cmd;
445
446 while (fgets (vty->buf, VTY_BUFSIZ, fp))
447 {
Donald Sharpd8aa4be2015-09-28 20:10:40 -0400448 ret = command_config_read_one_line (vty, &cmd, 1);
paul718e3742002-12-13 20:15:29 +0000449
450 switch (ret)
451 {
452 case CMD_WARNING:
453 if (vty->type == VTY_FILE)
paul4fc01e62002-12-13 20:49:00 +0000454 fprintf (stdout,"Warning...\n");
paul718e3742002-12-13 20:15:29 +0000455 break;
456 case CMD_ERR_AMBIGUOUS:
paul4fc01e62002-12-13 20:49:00 +0000457 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000458 break;
459 case CMD_ERR_NO_MATCH:
paul4fc01e62002-12-13 20:49:00 +0000460 fprintf (stdout,"%% Unknown command: %s", vty->buf);
paul718e3742002-12-13 20:15:29 +0000461 break;
462 case CMD_ERR_INCOMPLETE:
paul4fc01e62002-12-13 20:49:00 +0000463 fprintf (stdout,"%% Command incomplete.\n");
paul718e3742002-12-13 20:15:29 +0000464 break;
465 case CMD_SUCCESS_DAEMON:
466 {
ajsb1aa1472005-01-28 21:11:46 +0000467 u_int i;
468 int cmd_stat = CMD_SUCCESS;
469
Balaji.G837d16c2012-09-26 14:09:10 +0530470 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +0000471 {
paul44316fe2006-01-11 01:38:25 +0000472 if (cmd->daemon & vtysh_client[i].flag)
ajsb1aa1472005-01-28 21:11:46 +0000473 {
474 cmd_stat = vtysh_client_execute (&vtysh_client[i],
475 vty->buf, stdout);
476 if (cmd_stat != CMD_SUCCESS)
477 break;
478 }
479 }
480 if (cmd_stat != CMD_SUCCESS)
481 break;
482
paul718e3742002-12-13 20:15:29 +0000483 if (cmd->func)
484 (*cmd->func) (cmd, vty, 0, NULL);
485 }
486 }
487 }
488 return CMD_SUCCESS;
489}
490
491/* We don't care about the point of the cursor when '?' is typed. */
David Lampartera9eb9062015-03-04 07:07:01 +0100492static int
ajsb1aa1472005-01-28 21:11:46 +0000493vtysh_rl_describe (void)
paul718e3742002-12-13 20:15:29 +0000494{
495 int ret;
hassodda09522004-10-07 21:40:25 +0000496 unsigned int i;
paul718e3742002-12-13 20:15:29 +0000497 vector vline;
498 vector describe;
499 int width;
Christian Frankecd40b322013-09-30 12:27:51 +0000500 struct cmd_token *token;
paul718e3742002-12-13 20:15:29 +0000501
502 vline = cmd_make_strvec (rl_line_buffer);
503
504 /* In case of '> ?'. */
505 if (vline == NULL)
506 {
507 vline = vector_init (1);
David Lampartera91a3ba2015-03-03 09:06:51 +0100508 vector_set (vline, NULL);
paul718e3742002-12-13 20:15:29 +0000509 }
510 else
511 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
David Lampartera91a3ba2015-03-03 09:06:51 +0100512 vector_set (vline, NULL);
paul718e3742002-12-13 20:15:29 +0000513
514 describe = cmd_describe_command (vline, vty, &ret);
515
paul4fc01e62002-12-13 20:49:00 +0000516 fprintf (stdout,"\n");
paul718e3742002-12-13 20:15:29 +0000517
518 /* Ambiguous and no match error. */
519 switch (ret)
520 {
521 case CMD_ERR_AMBIGUOUS:
522 cmd_free_strvec (vline);
paul4fc01e62002-12-13 20:49:00 +0000523 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000524 rl_on_new_line ();
525 return 0;
526 break;
527 case CMD_ERR_NO_MATCH:
528 cmd_free_strvec (vline);
paul4fc01e62002-12-13 20:49:00 +0000529 fprintf (stdout,"%% There is no matched command.\n");
paul718e3742002-12-13 20:15:29 +0000530 rl_on_new_line ();
531 return 0;
532 break;
533 }
534
535 /* Get width of command string. */
536 width = 0;
paul55468c82005-03-14 20:19:01 +0000537 for (i = 0; i < vector_active (describe); i++)
Christian Frankecd40b322013-09-30 12:27:51 +0000538 if ((token = vector_slot (describe, i)) != NULL)
paul718e3742002-12-13 20:15:29 +0000539 {
540 int len;
541
Christian Frankecd40b322013-09-30 12:27:51 +0000542 if (token->cmd[0] == '\0')
paul718e3742002-12-13 20:15:29 +0000543 continue;
544
Christian Frankecd40b322013-09-30 12:27:51 +0000545 len = strlen (token->cmd);
546 if (token->cmd[0] == '.')
paul718e3742002-12-13 20:15:29 +0000547 len--;
548
549 if (width < len)
550 width = len;
551 }
552
paul55468c82005-03-14 20:19:01 +0000553 for (i = 0; i < vector_active (describe); i++)
Christian Frankecd40b322013-09-30 12:27:51 +0000554 if ((token = vector_slot (describe, i)) != NULL)
paul718e3742002-12-13 20:15:29 +0000555 {
Christian Frankecd40b322013-09-30 12:27:51 +0000556 if (token->cmd[0] == '\0')
paul718e3742002-12-13 20:15:29 +0000557 continue;
558
Christian Frankecd40b322013-09-30 12:27:51 +0000559 if (! token->desc)
paul4fc01e62002-12-13 20:49:00 +0000560 fprintf (stdout," %-s\n",
Christian Frankecd40b322013-09-30 12:27:51 +0000561 token->cmd[0] == '.' ? token->cmd + 1 : token->cmd);
paul718e3742002-12-13 20:15:29 +0000562 else
paul4fc01e62002-12-13 20:49:00 +0000563 fprintf (stdout," %-*s %s\n",
hassob094d262004-08-25 12:22:00 +0000564 width,
Christian Frankecd40b322013-09-30 12:27:51 +0000565 token->cmd[0] == '.' ? token->cmd + 1 : token->cmd,
566 token->desc);
paul718e3742002-12-13 20:15:29 +0000567 }
568
569 cmd_free_strvec (vline);
570 vector_free (describe);
571
572 rl_on_new_line();
573
574 return 0;
575}
576
hasso95e735b2004-08-26 13:08:30 +0000577/* Result of cmd_complete_command() call will be stored here
578 * and used in new_completion() in order to put the space in
579 * correct places only. */
paul718e3742002-12-13 20:15:29 +0000580int complete_status;
581
ajs274a4a42004-12-07 15:39:31 +0000582static char *
pauldfc0d9b2003-04-18 23:55:29 +0000583command_generator (const char *text, int state)
paul718e3742002-12-13 20:15:29 +0000584{
585 vector vline;
586 static char **matched = NULL;
587 static int index = 0;
588
589 /* First call. */
590 if (! state)
591 {
592 index = 0;
593
594 if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
595 return NULL;
596
597 vline = cmd_make_strvec (rl_line_buffer);
598 if (vline == NULL)
599 return NULL;
600
601 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
David Lampartera91a3ba2015-03-03 09:06:51 +0100602 vector_set (vline, NULL);
paul718e3742002-12-13 20:15:29 +0000603
604 matched = cmd_complete_command (vline, vty, &complete_status);
605 }
606
607 if (matched && matched[index])
608 return matched[index++];
609
610 return NULL;
611}
612
ajs274a4a42004-12-07 15:39:31 +0000613static char **
paul718e3742002-12-13 20:15:29 +0000614new_completion (char *text, int start, int end)
615{
616 char **matches;
617
pauldfc0d9b2003-04-18 23:55:29 +0000618 matches = rl_completion_matches (text, command_generator);
paul718e3742002-12-13 20:15:29 +0000619
620 if (matches)
621 {
622 rl_point = rl_end;
Christian Franke67e7a212013-03-04 09:23:30 +0000623 if (complete_status != CMD_COMPLETE_FULL_MATCH)
624 /* only append a space on full match */
625 rl_completion_append_character = '\0';
paul718e3742002-12-13 20:15:29 +0000626 }
627
628 return matches;
629}
630
ajs274a4a42004-12-07 15:39:31 +0000631#if 0
632/* This function is not actually being used. */
633static char **
paul718e3742002-12-13 20:15:29 +0000634vtysh_completion (char *text, int start, int end)
635{
636 int ret;
637 vector vline;
638 char **matched = NULL;
639
640 if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
641 return NULL;
642
643 vline = cmd_make_strvec (rl_line_buffer);
644 if (vline == NULL)
645 return NULL;
646
647 /* In case of 'help \t'. */
648 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
649 vector_set (vline, '\0');
650
651 matched = cmd_complete_command (vline, vty, &ret);
652
653 cmd_free_strvec (vline);
654
655 return (char **) matched;
656}
ajs274a4a42004-12-07 15:39:31 +0000657#endif
paul718e3742002-12-13 20:15:29 +0000658
hasso95e735b2004-08-26 13:08:30 +0000659/* Vty node structures. */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800660static struct cmd_node bgp_node =
paul718e3742002-12-13 20:15:29 +0000661{
662 BGP_NODE,
663 "%s(config-router)# ",
664};
665
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800666static struct cmd_node rip_node =
paul718e3742002-12-13 20:15:29 +0000667{
668 RIP_NODE,
669 "%s(config-router)# ",
670};
671
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800672static struct cmd_node isis_node =
hassoc25e4582003-12-23 10:39:08 +0000673{
674 ISIS_NODE,
675 "%s(config-router)# ",
hassoc25e4582003-12-23 10:39:08 +0000676};
677
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800678static struct cmd_node interface_node =
paul718e3742002-12-13 20:15:29 +0000679{
680 INTERFACE_NODE,
681 "%s(config-if)# ",
682};
683
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800684static struct cmd_node rmap_node =
hasso95e735b2004-08-26 13:08:30 +0000685{
686 RMAP_NODE,
687 "%s(config-route-map)# "
688};
689
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800690static struct cmd_node zebra_node =
hasso95e735b2004-08-26 13:08:30 +0000691{
692 ZEBRA_NODE,
693 "%s(config-router)# "
694};
695
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800696static struct cmd_node bgp_vpnv4_node =
hasso95e735b2004-08-26 13:08:30 +0000697{
698 BGP_VPNV4_NODE,
699 "%s(config-router-af)# "
700};
701
Lou Berger13c378d2016-01-12 13:41:56 -0500702static struct cmd_node bgp_vpnv6_node =
703{
704 BGP_VPNV6_NODE,
705 "%s(config-router-af)# "
706};
707
Lou Bergera3fda882016-01-12 13:42:04 -0500708static struct cmd_node bgp_encap_node =
709{
710 BGP_ENCAP_NODE,
711 "%s(config-router-af)# "
712};
713
714static struct cmd_node bgp_encapv6_node =
715{
716 BGP_ENCAPV6_NODE,
717 "%s(config-router-af)# "
718};
719
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800720static struct cmd_node bgp_ipv4_node =
hasso95e735b2004-08-26 13:08:30 +0000721{
722 BGP_IPV4_NODE,
723 "%s(config-router-af)# "
724};
725
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800726static struct cmd_node bgp_ipv4m_node =
hasso95e735b2004-08-26 13:08:30 +0000727{
728 BGP_IPV4M_NODE,
729 "%s(config-router-af)# "
730};
731
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800732static struct cmd_node bgp_ipv6_node =
hasso95e735b2004-08-26 13:08:30 +0000733{
734 BGP_IPV6_NODE,
735 "%s(config-router-af)# "
736};
737
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800738static struct cmd_node bgp_ipv6m_node =
paul57b5b7e2005-08-22 22:44:29 +0000739{
740 BGP_IPV6M_NODE,
741 "%s(config-router-af)# "
742};
743
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800744static struct cmd_node ospf_node =
hasso95e735b2004-08-26 13:08:30 +0000745{
746 OSPF_NODE,
747 "%s(config-router)# "
748};
749
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800750static struct cmd_node ripng_node =
hasso95e735b2004-08-26 13:08:30 +0000751{
752 RIPNG_NODE,
753 "%s(config-router)# "
754};
755
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800756static struct cmd_node ospf6_node =
hasso95e735b2004-08-26 13:08:30 +0000757{
758 OSPF6_NODE,
759 "%s(config-ospf6)# "
760};
761
David Lamparteree53c8b2015-05-23 05:45:59 +0200762static struct cmd_node babel_node =
763{
764 BABEL_NODE,
765 "%s(config-babel)# "
766};
767
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800768static struct cmd_node keychain_node =
hasso95e735b2004-08-26 13:08:30 +0000769{
770 KEYCHAIN_NODE,
771 "%s(config-keychain)# "
772};
773
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800774static struct cmd_node keychain_key_node =
hasso95e735b2004-08-26 13:08:30 +0000775{
776 KEYCHAIN_KEY_NODE,
777 "%s(config-keychain-key)# "
778};
779
Olivier Dugeonac10d302016-04-19 18:33:42 +0200780struct cmd_node link_params_node =
781{
782 LINK_PARAMS_NODE,
783 "%s(config-link-params)# ",
784};
785
hassoe7168df2004-10-03 20:11:32 +0000786/* Defined in lib/vty.c */
787extern struct cmd_node vty_node;
788
hasso95e735b2004-08-26 13:08:30 +0000789/* When '^Z' is received from vty, move down to the enable mode. */
David Lampartera9eb9062015-03-04 07:07:01 +0100790static int
ajsb1aa1472005-01-28 21:11:46 +0000791vtysh_end (void)
hasso95e735b2004-08-26 13:08:30 +0000792{
793 switch (vty->node)
794 {
795 case VIEW_NODE:
796 case ENABLE_NODE:
797 /* Nothing to do. */
798 break;
799 default:
800 vty->node = ENABLE_NODE;
801 break;
802 }
803 return CMD_SUCCESS;
804}
805
806DEFUNSH (VTYSH_ALL,
807 vtysh_end_all,
808 vtysh_end_all_cmd,
809 "end",
hassoe7168df2004-10-03 20:11:32 +0000810 "End current mode and change to enable mode\n")
hasso95e735b2004-08-26 13:08:30 +0000811{
hasso42895462004-09-26 16:25:07 +0000812 return vtysh_end ();
hasso95e735b2004-08-26 13:08:30 +0000813}
814
paul718e3742002-12-13 20:15:29 +0000815DEFUNSH (VTYSH_BGPD,
816 router_bgp,
817 router_bgp_cmd,
Paul Jakma320da872008-07-02 13:40:33 +0000818 "router bgp " CMD_AS_RANGE,
paul718e3742002-12-13 20:15:29 +0000819 ROUTER_STR
820 BGP_STR
821 AS_STR)
822{
823 vty->node = BGP_NODE;
824 return CMD_SUCCESS;
825}
826
Paul Jakma10895fd2008-07-03 19:34:48 +0000827ALIAS_SH (VTYSH_BGPD,
828 router_bgp,
829 router_bgp_view_cmd,
830 "router bgp " CMD_AS_RANGE " view WORD",
831 ROUTER_STR
832 BGP_STR
833 AS_STR
834 "BGP view\n"
835 "view name\n")
836
paul718e3742002-12-13 20:15:29 +0000837DEFUNSH (VTYSH_BGPD,
838 address_family_vpnv4,
839 address_family_vpnv4_cmd,
840 "address-family vpnv4",
841 "Enter Address Family command mode\n"
842 "Address family\n")
843{
844 vty->node = BGP_VPNV4_NODE;
845 return CMD_SUCCESS;
846}
847
848DEFUNSH (VTYSH_BGPD,
849 address_family_vpnv4_unicast,
850 address_family_vpnv4_unicast_cmd,
851 "address-family vpnv4 unicast",
852 "Enter Address Family command mode\n"
853 "Address family\n"
854 "Address Family Modifier\n")
855{
856 vty->node = BGP_VPNV4_NODE;
857 return CMD_SUCCESS;
858}
859
860DEFUNSH (VTYSH_BGPD,
Lou Berger13c378d2016-01-12 13:41:56 -0500861 address_family_vpnv6,
862 address_family_vpnv6_cmd,
863 "address-family vpnv6",
864 "Enter Address Family command mode\n"
865 "Address family\n")
866{
867 vty->node = BGP_VPNV6_NODE;
868 return CMD_SUCCESS;
869}
870
871DEFUNSH (VTYSH_BGPD,
872 address_family_vpnv6_unicast,
873 address_family_vpnv6_unicast_cmd,
874 "address-family vpnv6 unicast",
875 "Enter Address Family command mode\n"
876 "Address family\n"
877 "Address Family Modifier\n")
878{
879 vty->node = BGP_VPNV6_NODE;
880 return CMD_SUCCESS;
881}
882
883DEFUNSH (VTYSH_BGPD,
Lou Bergera3fda882016-01-12 13:42:04 -0500884 address_family_encap,
885 address_family_encap_cmd,
886 "address-family encap",
887 "Enter Address Family command mode\n"
888 "Address family\n")
889{
890 vty->node = BGP_ENCAP_NODE;
891 return CMD_SUCCESS;
892}
893
894DEFUNSH (VTYSH_BGPD,
895 address_family_encapv4,
896 address_family_encapv4_cmd,
897 "address-family encapv4",
898 "Enter Address Family command mode\n"
899 "Address family\n")
900{
901 vty->node = BGP_ENCAP_NODE;
902 return CMD_SUCCESS;
903}
904
905DEFUNSH (VTYSH_BGPD,
906 address_family_encapv6,
907 address_family_encapv6_cmd,
908 "address-family encapv6",
909 "Enter Address Family command mode\n"
910 "Address family\n")
911{
912 vty->node = BGP_ENCAPV6_NODE;
913 return CMD_SUCCESS;
914}
915
916DEFUNSH (VTYSH_BGPD,
paul718e3742002-12-13 20:15:29 +0000917 address_family_ipv4_unicast,
918 address_family_ipv4_unicast_cmd,
919 "address-family ipv4 unicast",
920 "Enter Address Family command mode\n"
921 "Address family\n"
922 "Address Family Modifier\n")
923{
924 vty->node = BGP_IPV4_NODE;
925 return CMD_SUCCESS;
926}
927
928DEFUNSH (VTYSH_BGPD,
929 address_family_ipv4_multicast,
930 address_family_ipv4_multicast_cmd,
931 "address-family ipv4 multicast",
932 "Enter Address Family command mode\n"
933 "Address family\n"
934 "Address Family Modifier\n")
935{
936 vty->node = BGP_IPV4M_NODE;
937 return CMD_SUCCESS;
938}
939
940DEFUNSH (VTYSH_BGPD,
941 address_family_ipv6,
942 address_family_ipv6_cmd,
943 "address-family ipv6",
944 "Enter Address Family command mode\n"
945 "Address family\n")
946{
947 vty->node = BGP_IPV6_NODE;
948 return CMD_SUCCESS;
949}
950
951DEFUNSH (VTYSH_BGPD,
952 address_family_ipv6_unicast,
953 address_family_ipv6_unicast_cmd,
954 "address-family ipv6 unicast",
955 "Enter Address Family command mode\n"
956 "Address family\n"
957 "Address Family Modifier\n")
958{
959 vty->node = BGP_IPV6_NODE;
960 return CMD_SUCCESS;
961}
962
paul57b5b7e2005-08-22 22:44:29 +0000963DEFUNSH (VTYSH_BGPD,
964 address_family_ipv6_multicast,
965 address_family_ipv6_multicast_cmd,
966 "address-family ipv6 multicast",
967 "Enter Address Family command mode\n"
968 "Address family\n"
969 "Address Family Modifier\n")
970{
971 vty->node = BGP_IPV6M_NODE;
972 return CMD_SUCCESS;
973}
974
paul718e3742002-12-13 20:15:29 +0000975DEFUNSH (VTYSH_RIPD,
976 key_chain,
977 key_chain_cmd,
978 "key chain WORD",
979 "Authentication key management\n"
980 "Key-chain management\n"
981 "Key-chain name\n")
982{
983 vty->node = KEYCHAIN_NODE;
984 return CMD_SUCCESS;
985}
986
987DEFUNSH (VTYSH_RIPD,
988 key,
989 key_cmd,
990 "key <0-2147483647>",
991 "Configure a key\n"
992 "Key identifier number\n")
993{
994 vty->node = KEYCHAIN_KEY_NODE;
995 return CMD_SUCCESS;
996}
997
998DEFUNSH (VTYSH_RIPD,
999 router_rip,
1000 router_rip_cmd,
1001 "router rip",
1002 ROUTER_STR
1003 "RIP")
1004{
1005 vty->node = RIP_NODE;
1006 return CMD_SUCCESS;
1007}
1008
1009DEFUNSH (VTYSH_RIPNGD,
1010 router_ripng,
1011 router_ripng_cmd,
1012 "router ripng",
1013 ROUTER_STR
1014 "RIPng")
1015{
1016 vty->node = RIPNG_NODE;
1017 return CMD_SUCCESS;
1018}
1019
1020DEFUNSH (VTYSH_OSPFD,
1021 router_ospf,
1022 router_ospf_cmd,
1023 "router ospf",
1024 "Enable a routing process\n"
1025 "Start OSPF configuration\n")
1026{
1027 vty->node = OSPF_NODE;
1028 return CMD_SUCCESS;
1029}
1030
1031DEFUNSH (VTYSH_OSPF6D,
1032 router_ospf6,
1033 router_ospf6_cmd,
1034 "router ospf6",
1035 OSPF6_ROUTER_STR
1036 OSPF6_STR)
1037{
1038 vty->node = OSPF6_NODE;
1039 return CMD_SUCCESS;
1040}
1041
hassoc25e4582003-12-23 10:39:08 +00001042DEFUNSH (VTYSH_ISISD,
hassob094d262004-08-25 12:22:00 +00001043 router_isis,
1044 router_isis_cmd,
1045 "router isis WORD",
1046 ROUTER_STR
1047 "ISO IS-IS\n"
1048 "ISO Routing area tag")
hassoc25e4582003-12-23 10:39:08 +00001049{
1050 vty->node = ISIS_NODE;
1051 return CMD_SUCCESS;
1052}
1053
paul718e3742002-12-13 20:15:29 +00001054DEFUNSH (VTYSH_RMAP,
1055 route_map,
1056 route_map_cmd,
1057 "route-map WORD (deny|permit) <1-65535>",
1058 "Create route-map or enter route-map command mode\n"
1059 "Route map tag\n"
1060 "Route map denies set operations\n"
1061 "Route map permits set operations\n"
1062 "Sequence to insert to/delete from existing route-map entry\n")
1063{
1064 vty->node = RMAP_NODE;
1065 return CMD_SUCCESS;
1066}
1067
paul718e3742002-12-13 20:15:29 +00001068DEFUNSH (VTYSH_ALL,
hassoe7168df2004-10-03 20:11:32 +00001069 vtysh_line_vty,
1070 vtysh_line_vty_cmd,
1071 "line vty",
1072 "Configure a terminal line\n"
1073 "Virtual terminal\n")
1074{
1075 vty->node = VTY_NODE;
1076 return CMD_SUCCESS;
1077}
1078
1079DEFUNSH (VTYSH_ALL,
paul718e3742002-12-13 20:15:29 +00001080 vtysh_enable,
1081 vtysh_enable_cmd,
1082 "enable",
1083 "Turn on privileged mode command\n")
1084{
1085 vty->node = ENABLE_NODE;
1086 return CMD_SUCCESS;
1087}
1088
paul718e3742002-12-13 20:15:29 +00001089DEFUNSH (VTYSH_ALL,
1090 vtysh_disable,
1091 vtysh_disable_cmd,
1092 "disable",
1093 "Turn off privileged mode command\n")
1094{
1095 if (vty->node == ENABLE_NODE)
1096 vty->node = VIEW_NODE;
1097 return CMD_SUCCESS;
1098}
1099
paul718e3742002-12-13 20:15:29 +00001100DEFUNSH (VTYSH_ALL,
1101 vtysh_config_terminal,
1102 vtysh_config_terminal_cmd,
1103 "configure terminal",
1104 "Configuration from vty interface\n"
1105 "Configuration terminal\n")
1106{
1107 vty->node = CONFIG_NODE;
1108 return CMD_SUCCESS;
1109}
1110
ajs274a4a42004-12-07 15:39:31 +00001111static int
paul718e3742002-12-13 20:15:29 +00001112vtysh_exit (struct vty *vty)
1113{
1114 switch (vty->node)
1115 {
1116 case VIEW_NODE:
1117 case ENABLE_NODE:
1118 exit (0);
1119 break;
1120 case CONFIG_NODE:
1121 vty->node = ENABLE_NODE;
1122 break;
1123 case INTERFACE_NODE:
1124 case ZEBRA_NODE:
1125 case BGP_NODE:
1126 case RIP_NODE:
1127 case RIPNG_NODE:
1128 case OSPF_NODE:
1129 case OSPF6_NODE:
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +01001130 case BABEL_NODE:
hassoc25e4582003-12-23 10:39:08 +00001131 case ISIS_NODE:
paul718e3742002-12-13 20:15:29 +00001132 case MASC_NODE:
1133 case RMAP_NODE:
1134 case VTY_NODE:
1135 case KEYCHAIN_NODE:
hasso2a56df92004-05-09 23:16:40 +00001136 vtysh_execute("end");
1137 vtysh_execute("configure terminal");
paul718e3742002-12-13 20:15:29 +00001138 vty->node = CONFIG_NODE;
1139 break;
1140 case BGP_VPNV4_NODE:
Lou Berger13c378d2016-01-12 13:41:56 -05001141 case BGP_VPNV6_NODE:
Lou Bergera3fda882016-01-12 13:42:04 -05001142 case BGP_ENCAP_NODE:
1143 case BGP_ENCAPV6_NODE:
paul718e3742002-12-13 20:15:29 +00001144 case BGP_IPV4_NODE:
1145 case BGP_IPV4M_NODE:
1146 case BGP_IPV6_NODE:
paul57b5b7e2005-08-22 22:44:29 +00001147 case BGP_IPV6M_NODE:
paul718e3742002-12-13 20:15:29 +00001148 vty->node = BGP_NODE;
1149 break;
1150 case KEYCHAIN_KEY_NODE:
1151 vty->node = KEYCHAIN_NODE;
1152 break;
Olivier Dugeonac10d302016-04-19 18:33:42 +02001153 case LINK_PARAMS_NODE:
1154 vty->node = INTERFACE_NODE;
1155 break;
paul718e3742002-12-13 20:15:29 +00001156 default:
1157 break;
1158 }
1159 return CMD_SUCCESS;
1160}
1161
1162DEFUNSH (VTYSH_ALL,
1163 vtysh_exit_all,
1164 vtysh_exit_all_cmd,
1165 "exit",
1166 "Exit current mode and down to previous mode\n")
1167{
1168 return vtysh_exit (vty);
1169}
1170
1171ALIAS (vtysh_exit_all,
1172 vtysh_quit_all_cmd,
1173 "quit",
1174 "Exit current mode and down to previous mode\n")
1175
1176DEFUNSH (VTYSH_BGPD,
1177 exit_address_family,
1178 exit_address_family_cmd,
1179 "exit-address-family",
1180 "Exit from Address Family configuration mode\n")
1181{
1182 if (vty->node == BGP_IPV4_NODE
1183 || vty->node == BGP_IPV4M_NODE
1184 || vty->node == BGP_VPNV4_NODE
Lou Berger13c378d2016-01-12 13:41:56 -05001185 || vty->node == BGP_VPNV6_NODE
Lou Bergera3fda882016-01-12 13:42:04 -05001186 || vty->node == BGP_ENCAP_NODE
1187 || vty->node == BGP_ENCAPV6_NODE
paul57b5b7e2005-08-22 22:44:29 +00001188 || vty->node == BGP_IPV6_NODE
1189 || vty->node == BGP_IPV6M_NODE)
paul718e3742002-12-13 20:15:29 +00001190 vty->node = BGP_NODE;
1191 return CMD_SUCCESS;
1192}
1193
1194DEFUNSH (VTYSH_ZEBRA,
1195 vtysh_exit_zebra,
1196 vtysh_exit_zebra_cmd,
1197 "exit",
1198 "Exit current mode and down to previous mode\n")
1199{
1200 return vtysh_exit (vty);
1201}
1202
1203ALIAS (vtysh_exit_zebra,
1204 vtysh_quit_zebra_cmd,
1205 "quit",
1206 "Exit current mode and down to previous mode\n")
1207
1208DEFUNSH (VTYSH_RIPD,
1209 vtysh_exit_ripd,
1210 vtysh_exit_ripd_cmd,
1211 "exit",
1212 "Exit current mode and down to previous mode\n")
1213{
1214 return vtysh_exit (vty);
1215}
1216
1217ALIAS (vtysh_exit_ripd,
1218 vtysh_quit_ripd_cmd,
1219 "quit",
1220 "Exit current mode and down to previous mode\n")
1221
paul68980082003-03-25 05:07:42 +00001222DEFUNSH (VTYSH_RIPNGD,
hassob094d262004-08-25 12:22:00 +00001223 vtysh_exit_ripngd,
1224 vtysh_exit_ripngd_cmd,
1225 "exit",
1226 "Exit current mode and down to previous mode\n")
paul68980082003-03-25 05:07:42 +00001227{
1228 return vtysh_exit (vty);
1229}
1230
1231ALIAS (vtysh_exit_ripngd,
1232 vtysh_quit_ripngd_cmd,
1233 "quit",
1234 "Exit current mode and down to previous mode\n")
1235
paul718e3742002-12-13 20:15:29 +00001236DEFUNSH (VTYSH_RMAP,
1237 vtysh_exit_rmap,
1238 vtysh_exit_rmap_cmd,
1239 "exit",
1240 "Exit current mode and down to previous mode\n")
1241{
1242 return vtysh_exit (vty);
1243}
1244
1245ALIAS (vtysh_exit_rmap,
1246 vtysh_quit_rmap_cmd,
1247 "quit",
1248 "Exit current mode and down to previous mode\n")
1249
1250DEFUNSH (VTYSH_BGPD,
1251 vtysh_exit_bgpd,
1252 vtysh_exit_bgpd_cmd,
1253 "exit",
1254 "Exit current mode and down to previous mode\n")
1255{
1256 return vtysh_exit (vty);
1257}
1258
1259ALIAS (vtysh_exit_bgpd,
1260 vtysh_quit_bgpd_cmd,
1261 "quit",
1262 "Exit current mode and down to previous mode\n")
1263
1264DEFUNSH (VTYSH_OSPFD,
1265 vtysh_exit_ospfd,
1266 vtysh_exit_ospfd_cmd,
1267 "exit",
1268 "Exit current mode and down to previous mode\n")
1269{
1270 return vtysh_exit (vty);
1271}
1272
1273ALIAS (vtysh_exit_ospfd,
1274 vtysh_quit_ospfd_cmd,
1275 "quit",
1276 "Exit current mode and down to previous mode\n")
1277
paul68980082003-03-25 05:07:42 +00001278DEFUNSH (VTYSH_OSPF6D,
hassob094d262004-08-25 12:22:00 +00001279 vtysh_exit_ospf6d,
1280 vtysh_exit_ospf6d_cmd,
1281 "exit",
1282 "Exit current mode and down to previous mode\n")
paul68980082003-03-25 05:07:42 +00001283{
1284 return vtysh_exit (vty);
1285}
1286
1287ALIAS (vtysh_exit_ospf6d,
1288 vtysh_quit_ospf6d_cmd,
1289 "quit",
1290 "Exit current mode and down to previous mode\n")
1291
hassoc25e4582003-12-23 10:39:08 +00001292DEFUNSH (VTYSH_ISISD,
hassob094d262004-08-25 12:22:00 +00001293 vtysh_exit_isisd,
1294 vtysh_exit_isisd_cmd,
1295 "exit",
1296 "Exit current mode and down to previous mode\n")
hassoc25e4582003-12-23 10:39:08 +00001297{
1298 return vtysh_exit (vty);
1299}
1300
1301ALIAS (vtysh_exit_isisd,
1302 vtysh_quit_isisd_cmd,
1303 "quit",
1304 "Exit current mode and down to previous mode\n")
1305
hassoe7168df2004-10-03 20:11:32 +00001306DEFUNSH (VTYSH_ALL,
1307 vtysh_exit_line_vty,
1308 vtysh_exit_line_vty_cmd,
1309 "exit",
1310 "Exit current mode and down to previous mode\n")
1311{
1312 return vtysh_exit (vty);
1313}
1314
1315ALIAS (vtysh_exit_line_vty,
1316 vtysh_quit_line_vty_cmd,
1317 "quit",
1318 "Exit current mode and down to previous mode\n")
1319
hasso95e735b2004-08-26 13:08:30 +00001320DEFUNSH (VTYSH_INTERFACE,
paul718e3742002-12-13 20:15:29 +00001321 vtysh_interface,
1322 vtysh_interface_cmd,
1323 "interface IFNAME",
1324 "Select an interface to configure\n"
1325 "Interface's name\n")
1326{
1327 vty->node = INTERFACE_NODE;
1328 return CMD_SUCCESS;
1329}
1330
Feng Lu471ea392015-05-22 11:40:00 +02001331ALIAS_SH (VTYSH_ZEBRA,
1332 vtysh_interface,
1333 vtysh_interface_vrf_cmd,
1334 "interface IFNAME " VRF_CMD_STR,
1335 "Select an interface to configure\n"
1336 "Interface's name\n"
1337 VRF_CMD_HELP_STR)
1338
hasso95e735b2004-08-26 13:08:30 +00001339/* TODO Implement "no interface command in isisd. */
paul32d24632003-05-23 09:25:20 +00001340DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D,
1341 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
1903 ret = vtysh_client_execute(&vtysh_client[i], "show running-config\n", stdout);
1904
1905 return ret;
1906}
1907
hassoe7168df2004-10-03 20:11:32 +00001908DEFUN (vtysh_integrated_config,
1909 vtysh_integrated_config_cmd,
1910 "service integrated-vtysh-config",
1911 "Set up miscellaneous service\n"
1912 "Write configuration into integrated file\n")
paul4fc01e62002-12-13 20:49:00 +00001913{
hassoe7168df2004-10-03 20:11:32 +00001914 vtysh_writeconfig_integrated = 1;
1915 return CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001916}
1917
hassoe7168df2004-10-03 20:11:32 +00001918DEFUN (no_vtysh_integrated_config,
1919 no_vtysh_integrated_config_cmd,
1920 "no service integrated-vtysh-config",
1921 NO_STR
1922 "Set up miscellaneous service\n"
1923 "Write configuration into integrated file\n")
paul4fc01e62002-12-13 20:49:00 +00001924{
hassoe7168df2004-10-03 20:11:32 +00001925 vtysh_writeconfig_integrated = 0;
1926 return CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001927}
1928
ajs274a4a42004-12-07 15:39:31 +00001929static int
1930write_config_integrated(void)
paul718e3742002-12-13 20:15:29 +00001931{
ajsb1aa1472005-01-28 21:11:46 +00001932 u_int i;
paul718e3742002-12-13 20:15:29 +00001933 char line[] = "write terminal\n";
1934 FILE *fp;
1935 char *integrate_sav = NULL;
1936
hasso95e735b2004-08-26 13:08:30 +00001937 integrate_sav = malloc (strlen (integrate_default) +
1938 strlen (CONF_BACKUP_EXT) + 1);
paul718e3742002-12-13 20:15:29 +00001939 strcpy (integrate_sav, integrate_default);
1940 strcat (integrate_sav, CONF_BACKUP_EXT);
1941
paul4fc01e62002-12-13 20:49:00 +00001942 fprintf (stdout,"Building Configuration...\n");
paul718e3742002-12-13 20:15:29 +00001943
hasso95e735b2004-08-26 13:08:30 +00001944 /* Move current configuration file to backup config file. */
paul718e3742002-12-13 20:15:29 +00001945 unlink (integrate_sav);
1946 rename (integrate_default, integrate_sav);
hasso95e735b2004-08-26 13:08:30 +00001947 free (integrate_sav);
paul4fc01e62002-12-13 20:49:00 +00001948
paul718e3742002-12-13 20:15:29 +00001949 fp = fopen (integrate_default, "w");
1950 if (fp == NULL)
1951 {
hasso95e735b2004-08-26 13:08:30 +00001952 fprintf (stdout,"%% Can't open configuration file %s.\n",
1953 integrate_default);
paul718e3742002-12-13 20:15:29 +00001954 return CMD_SUCCESS;
1955 }
paul718e3742002-12-13 20:15:29 +00001956
Balaji.G837d16c2012-09-26 14:09:10 +05301957 for (i = 0; i < array_size(vtysh_client); i++)
Gautam Kumarcc216b72015-10-26 13:22:12 -07001958 vtysh_client_execute (&vtysh_client[i], line, NULL);
paul718e3742002-12-13 20:15:29 +00001959
Donald Sharp147a8122015-05-21 16:06:21 -07001960 vtysh_config_write ();
paul718e3742002-12-13 20:15:29 +00001961 vtysh_config_dump (fp);
1962
1963 fclose (fp);
1964
gdtaa593d52003-12-22 20:15:53 +00001965 if (chmod (integrate_default, CONFIGFILE_MASK) != 0)
1966 {
1967 fprintf (stdout,"%% Can't chmod configuration file %s: %s (%d)\n",
ajs6099b3b2004-11-20 02:06:59 +00001968 integrate_default, safe_strerror(errno), errno);
gdtaa593d52003-12-22 20:15:53 +00001969 return CMD_WARNING;
1970 }
1971
paul4fc01e62002-12-13 20:49:00 +00001972 fprintf(stdout,"Integrated configuration saved to %s\n",integrate_default);
1973
1974 fprintf (stdout,"[OK]\n");
1975
paul718e3742002-12-13 20:15:29 +00001976 return CMD_SUCCESS;
1977}
1978
paul4fc01e62002-12-13 20:49:00 +00001979DEFUN (vtysh_write_memory,
1980 vtysh_write_memory_cmd,
1981 "write memory",
1982 "Write running configuration to memory, network, or terminal\n"
1983 "Write configuration to the file (same as write file)\n")
1984{
pauldfc0d9b2003-04-18 23:55:29 +00001985 int ret = CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001986 char line[] = "write memory\n";
ajsb1aa1472005-01-28 21:11:46 +00001987 u_int i;
paul4fc01e62002-12-13 20:49:00 +00001988
hassoe7168df2004-10-03 20:11:32 +00001989 /* If integrated Quagga.conf explicitely set. */
1990 if (vtysh_writeconfig_integrated)
1991 return write_config_integrated();
paul4fc01e62002-12-13 20:49:00 +00001992
1993 fprintf (stdout,"Building Configuration...\n");
1994
Balaji.G837d16c2012-09-26 14:09:10 +05301995 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00001996 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
hassoe7168df2004-10-03 20:11:32 +00001997
paul4fc01e62002-12-13 20:49:00 +00001998 fprintf (stdout,"[OK]\n");
1999
pauldfc0d9b2003-04-18 23:55:29 +00002000 return ret;
paul4fc01e62002-12-13 20:49:00 +00002001}
2002
paul718e3742002-12-13 20:15:29 +00002003ALIAS (vtysh_write_memory,
2004 vtysh_copy_runningconfig_startupconfig_cmd,
2005 "copy running-config startup-config",
2006 "Copy from one file to another\n"
2007 "Copy from current system configuration\n"
2008 "Copy to startup configuration\n")
2009
2010ALIAS (vtysh_write_memory,
2011 vtysh_write_file_cmd,
2012 "write file",
2013 "Write running configuration to memory, network, or terminal\n"
2014 "Write configuration to the file (same as write memory)\n")
2015
hasso4a6e2252003-05-25 11:51:29 +00002016ALIAS (vtysh_write_memory,
2017 vtysh_write_cmd,
2018 "write",
2019 "Write running configuration to memory, network, or terminal\n")
2020
paul718e3742002-12-13 20:15:29 +00002021ALIAS (vtysh_write_terminal,
2022 vtysh_show_running_config_cmd,
2023 "show running-config",
2024 SHOW_STR
2025 "Current operating configuration\n")
hassob094d262004-08-25 12:22:00 +00002026
Donald Sharp9fb73e82015-09-22 11:13:12 -04002027ALIAS (vtysh_write_terminal_daemon,
2028 vtysh_show_running_config_daemon_cmd,
2029 "show running-config (zebra|ripd|ripngd|ospfd|ospf6d|bgpd|isisd|babeld)",
2030 SHOW_STR
2031 "Current operating configuration\n"
2032 "For the zebra daemon\n"
2033 "For the rip daemon\n"
2034 "For the ripng daemon\n"
2035 "For the ospf daemon\n"
2036 "For the ospfv6 daemon\n"
2037 "For the bgp daemon\n"
2038 "For the isis daemon\n"
2039 "For the babel daemon\n")
2040
hasso34553cc2004-08-27 13:56:39 +00002041DEFUN (vtysh_terminal_length,
2042 vtysh_terminal_length_cmd,
2043 "terminal length <0-512>",
2044 "Set terminal line parameters\n"
2045 "Set number of lines on a screen\n"
2046 "Number of lines on screen (0 for no pausing)\n")
2047{
2048 int lines;
2049 char *endptr = NULL;
2050 char default_pager[10];
2051
2052 lines = strtol (argv[0], &endptr, 10);
2053 if (lines < 0 || lines > 512 || *endptr != '\0')
2054 {
2055 vty_out (vty, "length is malformed%s", VTY_NEWLINE);
2056 return CMD_WARNING;
2057 }
2058
2059 if (vtysh_pager_name)
2060 {
2061 free (vtysh_pager_name);
2062 vtysh_pager_name = NULL;
2063 }
2064
2065 if (lines != 0)
2066 {
2067 snprintf(default_pager, 10, "more -%i", lines);
2068 vtysh_pager_name = strdup (default_pager);
2069 }
2070
2071 return CMD_SUCCESS;
2072}
2073
2074DEFUN (vtysh_terminal_no_length,
2075 vtysh_terminal_no_length_cmd,
2076 "terminal no length",
2077 "Set terminal line parameters\n"
2078 NO_STR
2079 "Set number of lines on a screen\n")
2080{
2081 if (vtysh_pager_name)
2082 {
2083 free (vtysh_pager_name);
2084 vtysh_pager_name = NULL;
2085 }
2086
2087 vtysh_pager_init();
2088 return CMD_SUCCESS;
2089}
2090
hassof2799e62004-10-28 17:43:11 +00002091DEFUN (vtysh_show_daemons,
2092 vtysh_show_daemons_cmd,
2093 "show daemons",
hassoe7168df2004-10-03 20:11:32 +00002094 SHOW_STR
2095 "Show list of running daemons\n")
2096{
ajsb1aa1472005-01-28 21:11:46 +00002097 u_int i;
2098
Balaji.G837d16c2012-09-26 14:09:10 +05302099 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00002100 if ( vtysh_client[i].fd >= 0 )
2101 vty_out(vty, " %s", vtysh_client[i].name);
hassoe7168df2004-10-03 20:11:32 +00002102 vty_out(vty, "%s", VTY_NEWLINE);
2103
2104 return CMD_SUCCESS;
2105}
2106
paul718e3742002-12-13 20:15:29 +00002107/* Execute command in child process. */
ajs274a4a42004-12-07 15:39:31 +00002108static int
hasso5862ff52004-10-11 13:20:40 +00002109execute_command (const char *command, int argc, const char *arg1,
2110 const char *arg2)
paul718e3742002-12-13 20:15:29 +00002111{
paul718e3742002-12-13 20:15:29 +00002112 pid_t pid;
2113 int status;
2114
2115 /* Call fork(). */
2116 pid = fork ();
2117
2118 if (pid < 0)
2119 {
2120 /* Failure of fork(). */
ajs6099b3b2004-11-20 02:06:59 +00002121 fprintf (stderr, "Can't fork: %s\n", safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +00002122 exit (1);
2123 }
2124 else if (pid == 0)
2125 {
2126 /* This is child process. */
2127 switch (argc)
2128 {
2129 case 0:
David Lamparter6769f432015-03-04 07:18:24 +01002130 execlp (command, command, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00002131 break;
2132 case 1:
David Lamparter6769f432015-03-04 07:18:24 +01002133 execlp (command, command, arg1, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00002134 break;
2135 case 2:
David Lamparter6769f432015-03-04 07:18:24 +01002136 execlp (command, command, arg1, arg2, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00002137 break;
2138 }
2139
2140 /* When execlp suceed, this part is not executed. */
ajs6099b3b2004-11-20 02:06:59 +00002141 fprintf (stderr, "Can't execute %s: %s\n", command, safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +00002142 exit (1);
2143 }
2144 else
2145 {
2146 /* This is parent. */
2147 execute_flag = 1;
David Lamparter6769f432015-03-04 07:18:24 +01002148 wait4 (pid, &status, 0, NULL);
paul718e3742002-12-13 20:15:29 +00002149 execute_flag = 0;
2150 }
2151 return 0;
2152}
2153
2154DEFUN (vtysh_ping,
2155 vtysh_ping_cmd,
2156 "ping WORD",
hasso4eeccf12003-06-25 10:49:55 +00002157 "Send echo messages\n"
paul718e3742002-12-13 20:15:29 +00002158 "Ping destination address or hostname\n")
2159{
2160 execute_command ("ping", 1, argv[0], NULL);
2161 return CMD_SUCCESS;
2162}
2163
hasso4eeccf12003-06-25 10:49:55 +00002164ALIAS (vtysh_ping,
2165 vtysh_ping_ip_cmd,
2166 "ping ip WORD",
2167 "Send echo messages\n"
2168 "IP echo\n"
2169 "Ping destination address or hostname\n")
2170
paul718e3742002-12-13 20:15:29 +00002171DEFUN (vtysh_traceroute,
2172 vtysh_traceroute_cmd,
2173 "traceroute WORD",
2174 "Trace route to destination\n"
2175 "Trace route to destination address or hostname\n")
2176{
2177 execute_command ("traceroute", 1, argv[0], NULL);
2178 return CMD_SUCCESS;
2179}
2180
hasso4eeccf12003-06-25 10:49:55 +00002181ALIAS (vtysh_traceroute,
2182 vtysh_traceroute_ip_cmd,
2183 "traceroute ip WORD",
2184 "Trace route to destination\n"
2185 "IP trace\n"
2186 "Trace route to destination address or hostname\n")
2187
2188#ifdef HAVE_IPV6
2189DEFUN (vtysh_ping6,
2190 vtysh_ping6_cmd,
2191 "ping ipv6 WORD",
2192 "Send echo messages\n"
2193 "IPv6 echo\n"
2194 "Ping destination address or hostname\n")
2195{
2196 execute_command ("ping6", 1, argv[0], NULL);
2197 return CMD_SUCCESS;
2198}
2199
2200DEFUN (vtysh_traceroute6,
2201 vtysh_traceroute6_cmd,
2202 "traceroute ipv6 WORD",
2203 "Trace route to destination\n"
2204 "IPv6 trace\n"
2205 "Trace route to destination address or hostname\n")
2206{
2207 execute_command ("traceroute6", 1, argv[0], NULL);
2208 return CMD_SUCCESS;
2209}
2210#endif
2211
paul718e3742002-12-13 20:15:29 +00002212DEFUN (vtysh_telnet,
2213 vtysh_telnet_cmd,
2214 "telnet WORD",
2215 "Open a telnet connection\n"
2216 "IP address or hostname of a remote system\n")
2217{
2218 execute_command ("telnet", 1, argv[0], NULL);
2219 return CMD_SUCCESS;
2220}
2221
2222DEFUN (vtysh_telnet_port,
2223 vtysh_telnet_port_cmd,
2224 "telnet WORD PORT",
2225 "Open a telnet connection\n"
2226 "IP address or hostname of a remote system\n"
2227 "TCP Port number\n")
2228{
2229 execute_command ("telnet", 2, argv[0], argv[1]);
2230 return CMD_SUCCESS;
2231}
2232
paul5087df52003-01-25 06:56:09 +00002233DEFUN (vtysh_ssh,
2234 vtysh_ssh_cmd,
2235 "ssh WORD",
2236 "Open an ssh connection\n"
2237 "[user@]host\n")
2238{
2239 execute_command ("ssh", 1, argv[0], NULL);
2240 return CMD_SUCCESS;
2241}
2242
paul718e3742002-12-13 20:15:29 +00002243DEFUN (vtysh_start_shell,
2244 vtysh_start_shell_cmd,
2245 "start-shell",
2246 "Start UNIX shell\n")
2247{
2248 execute_command ("sh", 0, NULL, NULL);
2249 return CMD_SUCCESS;
2250}
2251
2252DEFUN (vtysh_start_bash,
2253 vtysh_start_bash_cmd,
2254 "start-shell bash",
2255 "Start UNIX shell\n"
2256 "Start bash\n")
2257{
2258 execute_command ("bash", 0, NULL, NULL);
2259 return CMD_SUCCESS;
2260}
2261
2262DEFUN (vtysh_start_zsh,
2263 vtysh_start_zsh_cmd,
2264 "start-shell zsh",
2265 "Start UNIX shell\n"
2266 "Start Z shell\n")
2267{
2268 execute_command ("zsh", 0, NULL, NULL);
2269 return CMD_SUCCESS;
2270}
hassob094d262004-08-25 12:22:00 +00002271
ajs274a4a42004-12-07 15:39:31 +00002272static void
paul718e3742002-12-13 20:15:29 +00002273vtysh_install_default (enum node_type node)
2274{
2275 install_element (node, &config_list_cmd);
2276}
2277
2278/* Making connection to protocol daemon. */
ajs274a4a42004-12-07 15:39:31 +00002279static int
ajsb1aa1472005-01-28 21:11:46 +00002280vtysh_connect (struct vtysh_client *vclient)
paul718e3742002-12-13 20:15:29 +00002281{
2282 int ret;
2283 int sock, len;
2284 struct sockaddr_un addr;
2285 struct stat s_stat;
paul718e3742002-12-13 20:15:29 +00002286
paul718e3742002-12-13 20:15:29 +00002287 /* Stat socket to see if we have permission to access it. */
ajsb1aa1472005-01-28 21:11:46 +00002288 ret = stat (vclient->path, &s_stat);
paul718e3742002-12-13 20:15:29 +00002289 if (ret < 0 && errno != ENOENT)
2290 {
2291 fprintf (stderr, "vtysh_connect(%s): stat = %s\n",
ajsb1aa1472005-01-28 21:11:46 +00002292 vclient->path, safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002293 exit(1);
2294 }
2295
2296 if (ret >= 0)
2297 {
2298 if (! S_ISSOCK(s_stat.st_mode))
2299 {
2300 fprintf (stderr, "vtysh_connect(%s): Not a socket\n",
ajsb1aa1472005-01-28 21:11:46 +00002301 vclient->path);
paul718e3742002-12-13 20:15:29 +00002302 exit (1);
2303 }
2304
paul718e3742002-12-13 20:15:29 +00002305 }
2306
2307 sock = socket (AF_UNIX, SOCK_STREAM, 0);
2308 if (sock < 0)
2309 {
2310#ifdef DEBUG
ajsb1aa1472005-01-28 21:11:46 +00002311 fprintf(stderr, "vtysh_connect(%s): socket = %s\n", vclient->path,
ajs6099b3b2004-11-20 02:06:59 +00002312 safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002313#endif /* DEBUG */
2314 return -1;
2315 }
2316
2317 memset (&addr, 0, sizeof (struct sockaddr_un));
2318 addr.sun_family = AF_UNIX;
ajsb1aa1472005-01-28 21:11:46 +00002319 strncpy (addr.sun_path, vclient->path, strlen (vclient->path));
Paul Jakma6f0e3f62007-05-10 02:38:51 +00002320#ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
paul718e3742002-12-13 20:15:29 +00002321 len = addr.sun_len = SUN_LEN(&addr);
2322#else
2323 len = sizeof (addr.sun_family) + strlen (addr.sun_path);
Paul Jakma6f0e3f62007-05-10 02:38:51 +00002324#endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
paul718e3742002-12-13 20:15:29 +00002325
2326 ret = connect (sock, (struct sockaddr *) &addr, len);
2327 if (ret < 0)
2328 {
2329#ifdef DEBUG
ajsb1aa1472005-01-28 21:11:46 +00002330 fprintf(stderr, "vtysh_connect(%s): connect = %s\n", vclient->path,
ajs6099b3b2004-11-20 02:06:59 +00002331 safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002332#endif /* DEBUG */
2333 close (sock);
2334 return -1;
2335 }
2336 vclient->fd = sock;
2337
2338 return 0;
2339}
2340
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002341int
2342vtysh_connect_all(const char *daemon_name)
paul718e3742002-12-13 20:15:29 +00002343{
ajsb1aa1472005-01-28 21:11:46 +00002344 u_int i;
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002345 int rc = 0;
2346 int matches = 0;
ajsb1aa1472005-01-28 21:11:46 +00002347
Balaji.G837d16c2012-09-26 14:09:10 +05302348 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00002349 {
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002350 if (!daemon_name || !strcmp(daemon_name, vtysh_client[i].name))
2351 {
2352 matches++;
2353 if (vtysh_connect(&vtysh_client[i]) == 0)
2354 rc++;
2355 /* We need direct access to ripd in vtysh_exit_ripd_only. */
2356 if (vtysh_client[i].flag == VTYSH_RIPD)
2357 ripd_client = &vtysh_client[i];
2358 }
ajsb1aa1472005-01-28 21:11:46 +00002359 }
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002360 if (!matches)
2361 fprintf(stderr, "Error: no daemons match name %s!\n", daemon_name);
2362 return rc;
paul718e3742002-12-13 20:15:29 +00002363}
2364
hasso95e735b2004-08-26 13:08:30 +00002365/* To disable readline's filename completion. */
ajs274a4a42004-12-07 15:39:31 +00002366static char *
pauldfc0d9b2003-04-18 23:55:29 +00002367vtysh_completion_entry_function (const char *ignore, int invoking_key)
paul718e3742002-12-13 20:15:29 +00002368{
pauldfc0d9b2003-04-18 23:55:29 +00002369 return NULL;
paul718e3742002-12-13 20:15:29 +00002370}
2371
2372void
ajsb1aa1472005-01-28 21:11:46 +00002373vtysh_readline_init (void)
paul718e3742002-12-13 20:15:29 +00002374{
2375 /* readline related settings. */
Sébastien Luttringer66d2ead2014-05-27 19:55:11 +02002376 rl_bind_key ('?', (rl_command_func_t *) vtysh_rl_describe);
paul68980082003-03-25 05:07:42 +00002377 rl_completion_entry_function = vtysh_completion_entry_function;
Sébastien Luttringer66d2ead2014-05-27 19:55:11 +02002378 rl_attempted_completion_function = (rl_completion_func_t *)new_completion;
paul718e3742002-12-13 20:15:29 +00002379}
2380
2381char *
ajsb1aa1472005-01-28 21:11:46 +00002382vtysh_prompt (void)
paul718e3742002-12-13 20:15:29 +00002383{
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002384 static struct utsname names;
paul718e3742002-12-13 20:15:29 +00002385 static char buf[100];
2386 const char*hostname;
2387 extern struct host host;
2388
2389 hostname = host.name;
2390
2391 if (!hostname)
2392 {
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002393 if (!names.nodename[0])
2394 uname (&names);
paul718e3742002-12-13 20:15:29 +00002395 hostname = names.nodename;
2396 }
2397
2398 snprintf (buf, sizeof buf, cmd_prompt (vty->node), hostname);
2399
2400 return buf;
2401}
2402
2403void
ajsb1aa1472005-01-28 21:11:46 +00002404vtysh_init_vty (void)
paul718e3742002-12-13 20:15:29 +00002405{
2406 /* Make vty structure. */
2407 vty = vty_new ();
2408 vty->type = VTY_SHELL;
2409 vty->node = VIEW_NODE;
2410
2411 /* Initialize commands. */
2412 cmd_init (0);
2413
2414 /* Install nodes. */
2415 install_node (&bgp_node, NULL);
2416 install_node (&rip_node, NULL);
2417 install_node (&interface_node, NULL);
Olivier Dugeonac10d302016-04-19 18:33:42 +02002418 install_node (&link_params_node, NULL);
paul718e3742002-12-13 20:15:29 +00002419 install_node (&rmap_node, NULL);
2420 install_node (&zebra_node, NULL);
2421 install_node (&bgp_vpnv4_node, NULL);
Lou Berger13c378d2016-01-12 13:41:56 -05002422 install_node (&bgp_vpnv6_node, NULL);
Lou Bergera3fda882016-01-12 13:42:04 -05002423 install_node (&bgp_encap_node, NULL);
2424 install_node (&bgp_encapv6_node, NULL);
paul718e3742002-12-13 20:15:29 +00002425 install_node (&bgp_ipv4_node, NULL);
2426 install_node (&bgp_ipv4m_node, NULL);
2427/* #ifdef HAVE_IPV6 */
2428 install_node (&bgp_ipv6_node, NULL);
paul57b5b7e2005-08-22 22:44:29 +00002429 install_node (&bgp_ipv6m_node, NULL);
paul718e3742002-12-13 20:15:29 +00002430/* #endif */
2431 install_node (&ospf_node, NULL);
2432/* #ifdef HAVE_IPV6 */
2433 install_node (&ripng_node, NULL);
2434 install_node (&ospf6_node, NULL);
2435/* #endif */
David Lamparteree53c8b2015-05-23 05:45:59 +02002436 install_node (&babel_node, NULL);
paul718e3742002-12-13 20:15:29 +00002437 install_node (&keychain_node, NULL);
2438 install_node (&keychain_key_node, NULL);
hassoc25e4582003-12-23 10:39:08 +00002439 install_node (&isis_node, NULL);
hassoe7168df2004-10-03 20:11:32 +00002440 install_node (&vty_node, NULL);
paul718e3742002-12-13 20:15:29 +00002441
2442 vtysh_install_default (VIEW_NODE);
2443 vtysh_install_default (ENABLE_NODE);
2444 vtysh_install_default (CONFIG_NODE);
2445 vtysh_install_default (BGP_NODE);
2446 vtysh_install_default (RIP_NODE);
2447 vtysh_install_default (INTERFACE_NODE);
Olivier Dugeonac10d302016-04-19 18:33:42 +02002448 vtysh_install_default (LINK_PARAMS_NODE);
paul718e3742002-12-13 20:15:29 +00002449 vtysh_install_default (RMAP_NODE);
2450 vtysh_install_default (ZEBRA_NODE);
2451 vtysh_install_default (BGP_VPNV4_NODE);
Lou Berger13c378d2016-01-12 13:41:56 -05002452 vtysh_install_default (BGP_VPNV6_NODE);
Lou Bergera3fda882016-01-12 13:42:04 -05002453 vtysh_install_default (BGP_ENCAP_NODE);
2454 vtysh_install_default (BGP_ENCAPV6_NODE);
paul718e3742002-12-13 20:15:29 +00002455 vtysh_install_default (BGP_IPV4_NODE);
2456 vtysh_install_default (BGP_IPV4M_NODE);
2457 vtysh_install_default (BGP_IPV6_NODE);
paul57b5b7e2005-08-22 22:44:29 +00002458 vtysh_install_default (BGP_IPV6M_NODE);
paul718e3742002-12-13 20:15:29 +00002459 vtysh_install_default (OSPF_NODE);
2460 vtysh_install_default (RIPNG_NODE);
2461 vtysh_install_default (OSPF6_NODE);
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +01002462 vtysh_install_default (BABEL_NODE);
hassoc25e4582003-12-23 10:39:08 +00002463 vtysh_install_default (ISIS_NODE);
paul718e3742002-12-13 20:15:29 +00002464 vtysh_install_default (KEYCHAIN_NODE);
2465 vtysh_install_default (KEYCHAIN_KEY_NODE);
hassoe7168df2004-10-03 20:11:32 +00002466 vtysh_install_default (VTY_NODE);
paul718e3742002-12-13 20:15:29 +00002467
2468 install_element (VIEW_NODE, &vtysh_enable_cmd);
2469 install_element (ENABLE_NODE, &vtysh_config_terminal_cmd);
2470 install_element (ENABLE_NODE, &vtysh_disable_cmd);
2471
2472 /* "exit" command. */
2473 install_element (VIEW_NODE, &vtysh_exit_all_cmd);
2474 install_element (VIEW_NODE, &vtysh_quit_all_cmd);
2475 install_element (CONFIG_NODE, &vtysh_exit_all_cmd);
2476 /* install_element (CONFIG_NODE, &vtysh_quit_all_cmd); */
2477 install_element (ENABLE_NODE, &vtysh_exit_all_cmd);
2478 install_element (ENABLE_NODE, &vtysh_quit_all_cmd);
2479 install_element (RIP_NODE, &vtysh_exit_ripd_cmd);
2480 install_element (RIP_NODE, &vtysh_quit_ripd_cmd);
paul68980082003-03-25 05:07:42 +00002481 install_element (RIPNG_NODE, &vtysh_exit_ripngd_cmd);
2482 install_element (RIPNG_NODE, &vtysh_quit_ripngd_cmd);
paul718e3742002-12-13 20:15:29 +00002483 install_element (OSPF_NODE, &vtysh_exit_ospfd_cmd);
2484 install_element (OSPF_NODE, &vtysh_quit_ospfd_cmd);
paul68980082003-03-25 05:07:42 +00002485 install_element (OSPF6_NODE, &vtysh_exit_ospf6d_cmd);
2486 install_element (OSPF6_NODE, &vtysh_quit_ospf6d_cmd);
paul718e3742002-12-13 20:15:29 +00002487 install_element (BGP_NODE, &vtysh_exit_bgpd_cmd);
2488 install_element (BGP_NODE, &vtysh_quit_bgpd_cmd);
2489 install_element (BGP_VPNV4_NODE, &vtysh_exit_bgpd_cmd);
2490 install_element (BGP_VPNV4_NODE, &vtysh_quit_bgpd_cmd);
Lou Berger13c378d2016-01-12 13:41:56 -05002491 install_element (BGP_VPNV6_NODE, &vtysh_exit_bgpd_cmd);
2492 install_element (BGP_VPNV6_NODE, &vtysh_quit_bgpd_cmd);
Lou Bergera3fda882016-01-12 13:42:04 -05002493 install_element (BGP_ENCAP_NODE, &vtysh_exit_bgpd_cmd);
2494 install_element (BGP_ENCAP_NODE, &vtysh_quit_bgpd_cmd);
2495 install_element (BGP_ENCAPV6_NODE, &vtysh_exit_bgpd_cmd);
2496 install_element (BGP_ENCAPV6_NODE, &vtysh_quit_bgpd_cmd);
paul718e3742002-12-13 20:15:29 +00002497 install_element (BGP_IPV4_NODE, &vtysh_exit_bgpd_cmd);
2498 install_element (BGP_IPV4_NODE, &vtysh_quit_bgpd_cmd);
2499 install_element (BGP_IPV4M_NODE, &vtysh_exit_bgpd_cmd);
2500 install_element (BGP_IPV4M_NODE, &vtysh_quit_bgpd_cmd);
2501 install_element (BGP_IPV6_NODE, &vtysh_exit_bgpd_cmd);
2502 install_element (BGP_IPV6_NODE, &vtysh_quit_bgpd_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002503 install_element (BGP_IPV6M_NODE, &vtysh_exit_bgpd_cmd);
2504 install_element (BGP_IPV6M_NODE, &vtysh_quit_bgpd_cmd);
hassoc25e4582003-12-23 10:39:08 +00002505 install_element (ISIS_NODE, &vtysh_exit_isisd_cmd);
2506 install_element (ISIS_NODE, &vtysh_quit_isisd_cmd);
paul718e3742002-12-13 20:15:29 +00002507 install_element (KEYCHAIN_NODE, &vtysh_exit_ripd_cmd);
2508 install_element (KEYCHAIN_NODE, &vtysh_quit_ripd_cmd);
2509 install_element (KEYCHAIN_KEY_NODE, &vtysh_exit_ripd_cmd);
2510 install_element (KEYCHAIN_KEY_NODE, &vtysh_quit_ripd_cmd);
2511 install_element (RMAP_NODE, &vtysh_exit_rmap_cmd);
2512 install_element (RMAP_NODE, &vtysh_quit_rmap_cmd);
hassoe7168df2004-10-03 20:11:32 +00002513 install_element (VTY_NODE, &vtysh_exit_line_vty_cmd);
2514 install_element (VTY_NODE, &vtysh_quit_line_vty_cmd);
paul718e3742002-12-13 20:15:29 +00002515
2516 /* "end" command. */
2517 install_element (CONFIG_NODE, &vtysh_end_all_cmd);
2518 install_element (ENABLE_NODE, &vtysh_end_all_cmd);
2519 install_element (RIP_NODE, &vtysh_end_all_cmd);
2520 install_element (RIPNG_NODE, &vtysh_end_all_cmd);
2521 install_element (OSPF_NODE, &vtysh_end_all_cmd);
2522 install_element (OSPF6_NODE, &vtysh_end_all_cmd);
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +01002523 install_element (BABEL_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002524 install_element (BGP_NODE, &vtysh_end_all_cmd);
2525 install_element (BGP_IPV4_NODE, &vtysh_end_all_cmd);
2526 install_element (BGP_IPV4M_NODE, &vtysh_end_all_cmd);
2527 install_element (BGP_VPNV4_NODE, &vtysh_end_all_cmd);
Lou Berger13c378d2016-01-12 13:41:56 -05002528 install_element (BGP_VPNV6_NODE, &vtysh_end_all_cmd);
Lou Bergera3fda882016-01-12 13:42:04 -05002529 install_element (BGP_ENCAP_NODE, &vtysh_end_all_cmd);
2530 install_element (BGP_ENCAPV6_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002531 install_element (BGP_IPV6_NODE, &vtysh_end_all_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002532 install_element (BGP_IPV6M_NODE, &vtysh_end_all_cmd);
hassoc25e4582003-12-23 10:39:08 +00002533 install_element (ISIS_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002534 install_element (KEYCHAIN_NODE, &vtysh_end_all_cmd);
2535 install_element (KEYCHAIN_KEY_NODE, &vtysh_end_all_cmd);
2536 install_element (RMAP_NODE, &vtysh_end_all_cmd);
hassoe7168df2004-10-03 20:11:32 +00002537 install_element (VTY_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002538
paul338a9912003-03-01 15:44:10 +00002539 install_element (INTERFACE_NODE, &interface_desc_cmd);
paul464dc8d2003-03-28 02:25:45 +00002540 install_element (INTERFACE_NODE, &no_interface_desc_cmd);
paul718e3742002-12-13 20:15:29 +00002541 install_element (INTERFACE_NODE, &vtysh_end_all_cmd);
2542 install_element (INTERFACE_NODE, &vtysh_exit_interface_cmd);
Olivier Dugeonac10d302016-04-19 18:33:42 +02002543 install_element (LINK_PARAMS_NODE, &vtysh_end_all_cmd);
2544 install_element (LINK_PARAMS_NODE, &vtysh_exit_interface_cmd);
paul718e3742002-12-13 20:15:29 +00002545 install_element (INTERFACE_NODE, &vtysh_quit_interface_cmd);
2546 install_element (CONFIG_NODE, &router_rip_cmd);
2547#ifdef HAVE_IPV6
2548 install_element (CONFIG_NODE, &router_ripng_cmd);
2549#endif
2550 install_element (CONFIG_NODE, &router_ospf_cmd);
2551#ifdef HAVE_IPV6
2552 install_element (CONFIG_NODE, &router_ospf6_cmd);
2553#endif
hassoc25e4582003-12-23 10:39:08 +00002554 install_element (CONFIG_NODE, &router_isis_cmd);
paul718e3742002-12-13 20:15:29 +00002555 install_element (CONFIG_NODE, &router_bgp_cmd);
Paul Jakma10895fd2008-07-03 19:34:48 +00002556 install_element (CONFIG_NODE, &router_bgp_view_cmd);
paul718e3742002-12-13 20:15:29 +00002557 install_element (BGP_NODE, &address_family_vpnv4_cmd);
2558 install_element (BGP_NODE, &address_family_vpnv4_unicast_cmd);
Lou Berger13c378d2016-01-12 13:41:56 -05002559 install_element (BGP_NODE, &address_family_vpnv6_cmd);
2560 install_element (BGP_NODE, &address_family_vpnv6_unicast_cmd);
Lou Bergera3fda882016-01-12 13:42:04 -05002561 install_element (BGP_NODE, &address_family_encap_cmd);
2562 install_element (BGP_NODE, &address_family_encapv6_cmd);
paul718e3742002-12-13 20:15:29 +00002563 install_element (BGP_NODE, &address_family_ipv4_unicast_cmd);
2564 install_element (BGP_NODE, &address_family_ipv4_multicast_cmd);
2565#ifdef HAVE_IPV6
2566 install_element (BGP_NODE, &address_family_ipv6_cmd);
2567 install_element (BGP_NODE, &address_family_ipv6_unicast_cmd);
viveka4f40292015-11-09 20:21:46 -05002568 install_element (BGP_NODE, &address_family_ipv6_multicast_cmd);
paul718e3742002-12-13 20:15:29 +00002569#endif
2570 install_element (BGP_VPNV4_NODE, &exit_address_family_cmd);
Lou Berger13c378d2016-01-12 13:41:56 -05002571 install_element (BGP_VPNV6_NODE, &exit_address_family_cmd);
Lou Bergera3fda882016-01-12 13:42:04 -05002572 install_element (BGP_ENCAP_NODE, &exit_address_family_cmd);
2573 install_element (BGP_ENCAPV6_NODE, &exit_address_family_cmd);
paul718e3742002-12-13 20:15:29 +00002574 install_element (BGP_IPV4_NODE, &exit_address_family_cmd);
2575 install_element (BGP_IPV4M_NODE, &exit_address_family_cmd);
2576 install_element (BGP_IPV6_NODE, &exit_address_family_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002577 install_element (BGP_IPV6M_NODE, &exit_address_family_cmd);
paul718e3742002-12-13 20:15:29 +00002578 install_element (CONFIG_NODE, &key_chain_cmd);
2579 install_element (CONFIG_NODE, &route_map_cmd);
hassoe7168df2004-10-03 20:11:32 +00002580 install_element (CONFIG_NODE, &vtysh_line_vty_cmd);
paul718e3742002-12-13 20:15:29 +00002581 install_element (KEYCHAIN_NODE, &key_cmd);
2582 install_element (KEYCHAIN_NODE, &key_chain_cmd);
2583 install_element (KEYCHAIN_KEY_NODE, &key_chain_cmd);
2584 install_element (CONFIG_NODE, &vtysh_interface_cmd);
paul32d24632003-05-23 09:25:20 +00002585 install_element (CONFIG_NODE, &vtysh_no_interface_cmd);
Feng Lu471ea392015-05-22 11:40:00 +02002586 install_element (CONFIG_NODE, &vtysh_interface_vrf_cmd);
2587 install_element (CONFIG_NODE, &vtysh_no_interface_vrf_cmd);
Olivier Dugeonac10d302016-04-19 18:33:42 +02002588 install_element (INTERFACE_NODE, &vtysh_link_params_cmd);
paul718e3742002-12-13 20:15:29 +00002589 install_element (ENABLE_NODE, &vtysh_show_running_config_cmd);
Donald Sharp9fb73e82015-09-22 11:13:12 -04002590 install_element (ENABLE_NODE, &vtysh_show_running_config_daemon_cmd);
paul718e3742002-12-13 20:15:29 +00002591 install_element (ENABLE_NODE, &vtysh_copy_runningconfig_startupconfig_cmd);
2592 install_element (ENABLE_NODE, &vtysh_write_file_cmd);
hasso4a6e2252003-05-25 11:51:29 +00002593 install_element (ENABLE_NODE, &vtysh_write_cmd);
paul718e3742002-12-13 20:15:29 +00002594
hasso95e735b2004-08-26 13:08:30 +00002595 /* "write terminal" command. */
paul718e3742002-12-13 20:15:29 +00002596 install_element (ENABLE_NODE, &vtysh_write_terminal_cmd);
Donald Sharp9fb73e82015-09-22 11:13:12 -04002597 install_element (ENABLE_NODE, &vtysh_write_terminal_daemon_cmd);
Donald Sharp07440402016-02-25 07:39:45 -05002598
hassoe7168df2004-10-03 20:11:32 +00002599 install_element (CONFIG_NODE, &vtysh_integrated_config_cmd);
2600 install_element (CONFIG_NODE, &no_vtysh_integrated_config_cmd);
paul718e3742002-12-13 20:15:29 +00002601
hasso95e735b2004-08-26 13:08:30 +00002602 /* "write memory" command. */
paul718e3742002-12-13 20:15:29 +00002603 install_element (ENABLE_NODE, &vtysh_write_memory_cmd);
paul718e3742002-12-13 20:15:29 +00002604
hasso34553cc2004-08-27 13:56:39 +00002605 install_element (VIEW_NODE, &vtysh_terminal_length_cmd);
2606 install_element (ENABLE_NODE, &vtysh_terminal_length_cmd);
2607 install_element (VIEW_NODE, &vtysh_terminal_no_length_cmd);
2608 install_element (ENABLE_NODE, &vtysh_terminal_no_length_cmd);
hassof2799e62004-10-28 17:43:11 +00002609 install_element (VIEW_NODE, &vtysh_show_daemons_cmd);
2610 install_element (ENABLE_NODE, &vtysh_show_daemons_cmd);
hasso34553cc2004-08-27 13:56:39 +00002611
paul718e3742002-12-13 20:15:29 +00002612 install_element (VIEW_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002613 install_element (VIEW_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00002614 install_element (VIEW_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002615 install_element (VIEW_NODE, &vtysh_traceroute_ip_cmd);
2616#ifdef HAVE_IPV6
2617 install_element (VIEW_NODE, &vtysh_ping6_cmd);
2618 install_element (VIEW_NODE, &vtysh_traceroute6_cmd);
2619#endif
paul718e3742002-12-13 20:15:29 +00002620 install_element (VIEW_NODE, &vtysh_telnet_cmd);
2621 install_element (VIEW_NODE, &vtysh_telnet_port_cmd);
paul5087df52003-01-25 06:56:09 +00002622 install_element (VIEW_NODE, &vtysh_ssh_cmd);
paul718e3742002-12-13 20:15:29 +00002623 install_element (ENABLE_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002624 install_element (ENABLE_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00002625 install_element (ENABLE_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002626 install_element (ENABLE_NODE, &vtysh_traceroute_ip_cmd);
2627#ifdef HAVE_IPV6
2628 install_element (ENABLE_NODE, &vtysh_ping6_cmd);
2629 install_element (ENABLE_NODE, &vtysh_traceroute6_cmd);
2630#endif
paul718e3742002-12-13 20:15:29 +00002631 install_element (ENABLE_NODE, &vtysh_telnet_cmd);
2632 install_element (ENABLE_NODE, &vtysh_telnet_port_cmd);
hasso67e29ab2004-08-26 22:21:31 +00002633 install_element (ENABLE_NODE, &vtysh_ssh_cmd);
paul718e3742002-12-13 20:15:29 +00002634 install_element (ENABLE_NODE, &vtysh_start_shell_cmd);
2635 install_element (ENABLE_NODE, &vtysh_start_bash_cmd);
2636 install_element (ENABLE_NODE, &vtysh_start_zsh_cmd);
Paul Jakmadbf7d132006-05-23 22:10:01 +00002637
Paul Jakma362b4032006-05-28 07:54:45 +00002638 install_element (VIEW_NODE, &vtysh_show_memory_cmd);
2639 install_element (ENABLE_NODE, &vtysh_show_memory_cmd);
2640
Donald Sharp567a6382015-08-19 21:22:17 -04002641 install_element (VIEW_NODE, &vtysh_show_work_queues_cmd);
2642 install_element (ENABLE_NODE, &vtysh_show_work_queues_cmd);
Donald Sharp07440402016-02-25 07:39:45 -05002643 install_element (ENABLE_NODE, &vtysh_show_work_queues_daemon_cmd);
2644 install_element (VIEW_NODE, &vtysh_show_work_queues_daemon_cmd);
Donald Sharp567a6382015-08-19 21:22:17 -04002645
2646 install_element (VIEW_NODE, &vtysh_show_thread_cmd);
2647 install_element (ENABLE_NODE, &vtysh_show_thread_cmd);
2648
Paul Jakmadbf7d132006-05-23 22:10:01 +00002649 /* Logging */
2650 install_element (ENABLE_NODE, &vtysh_show_logging_cmd);
2651 install_element (VIEW_NODE, &vtysh_show_logging_cmd);
paul718e3742002-12-13 20:15:29 +00002652 install_element (CONFIG_NODE, &vtysh_log_stdout_cmd);
ajs274a4a42004-12-07 15:39:31 +00002653 install_element (CONFIG_NODE, &vtysh_log_stdout_level_cmd);
paul718e3742002-12-13 20:15:29 +00002654 install_element (CONFIG_NODE, &no_vtysh_log_stdout_cmd);
2655 install_element (CONFIG_NODE, &vtysh_log_file_cmd);
ajs274a4a42004-12-07 15:39:31 +00002656 install_element (CONFIG_NODE, &vtysh_log_file_level_cmd);
paul718e3742002-12-13 20:15:29 +00002657 install_element (CONFIG_NODE, &no_vtysh_log_file_cmd);
ajs274a4a42004-12-07 15:39:31 +00002658 install_element (CONFIG_NODE, &no_vtysh_log_file_level_cmd);
2659 install_element (CONFIG_NODE, &vtysh_log_monitor_cmd);
2660 install_element (CONFIG_NODE, &vtysh_log_monitor_level_cmd);
2661 install_element (CONFIG_NODE, &no_vtysh_log_monitor_cmd);
paul718e3742002-12-13 20:15:29 +00002662 install_element (CONFIG_NODE, &vtysh_log_syslog_cmd);
ajs274a4a42004-12-07 15:39:31 +00002663 install_element (CONFIG_NODE, &vtysh_log_syslog_level_cmd);
paul718e3742002-12-13 20:15:29 +00002664 install_element (CONFIG_NODE, &no_vtysh_log_syslog_cmd);
2665 install_element (CONFIG_NODE, &vtysh_log_trap_cmd);
2666 install_element (CONFIG_NODE, &no_vtysh_log_trap_cmd);
ajs274a4a42004-12-07 15:39:31 +00002667 install_element (CONFIG_NODE, &vtysh_log_facility_cmd);
2668 install_element (CONFIG_NODE, &no_vtysh_log_facility_cmd);
paul718e3742002-12-13 20:15:29 +00002669 install_element (CONFIG_NODE, &vtysh_log_record_priority_cmd);
2670 install_element (CONFIG_NODE, &no_vtysh_log_record_priority_cmd);
Andrew J. Schorrc749b722007-04-29 03:53:31 +00002671 install_element (CONFIG_NODE, &vtysh_log_timestamp_precision_cmd);
2672 install_element (CONFIG_NODE, &no_vtysh_log_timestamp_precision_cmd);
hassoe7168df2004-10-03 20:11:32 +00002673
2674 install_element (CONFIG_NODE, &vtysh_service_password_encrypt_cmd);
2675 install_element (CONFIG_NODE, &no_vtysh_service_password_encrypt_cmd);
2676
2677 install_element (CONFIG_NODE, &vtysh_password_cmd);
2678 install_element (CONFIG_NODE, &vtysh_password_text_cmd);
2679 install_element (CONFIG_NODE, &vtysh_enable_password_cmd);
2680 install_element (CONFIG_NODE, &vtysh_enable_password_text_cmd);
2681 install_element (CONFIG_NODE, &no_vtysh_enable_password_cmd);
2682
paul718e3742002-12-13 20:15:29 +00002683}