blob: 75d1fc076faa4cf9289f602c87fae40874d2f013 [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
Quentin Youngb7ceefe2017-01-10 23:33:50 +0000446 while (fgets (vty->buf, vty->max, fp))
paul718e3742002-12-13 20:15:29 +0000447 {
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
Igor Ryzhov6ff2acd2016-06-09 16:44:21 +03001339DEFSH (VTYSH_INTERFACE,
paul32d24632003-05-23 09:25:20 +00001340 vtysh_no_interface_cmd,
1341 "no interface IFNAME",
1342 NO_STR
1343 "Delete a pseudo interface's configuration\n"
1344 "Interface's name\n")
1345
Feng Lu471ea392015-05-22 11:40:00 +02001346DEFSH (VTYSH_ZEBRA,
1347 vtysh_no_interface_vrf_cmd,
1348 "no interface IFNAME " VRF_CMD_STR,
1349 NO_STR
1350 "Delete a pseudo interface's configuration\n"
1351 "Interface's name\n"
1352 VRF_CMD_HELP_STR)
1353
hasso95e735b2004-08-26 13:08:30 +00001354/* TODO Implement interface description commands in ripngd, ospf6d
1355 * and isisd. */
paul338a9912003-03-01 15:44:10 +00001356DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1357 interface_desc_cmd,
1358 "description .LINE",
1359 "Interface specific description\n"
1360 "Characters describing this interface\n")
paul464dc8d2003-03-28 02:25:45 +00001361
1362DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1363 no_interface_desc_cmd,
1364 "no description",
1365 NO_STR
1366 "Interface specific description\n")
paul338a9912003-03-01 15:44:10 +00001367
hasso95e735b2004-08-26 13:08:30 +00001368DEFUNSH (VTYSH_INTERFACE,
paul718e3742002-12-13 20:15:29 +00001369 vtysh_exit_interface,
1370 vtysh_exit_interface_cmd,
1371 "exit",
1372 "Exit current mode and down to previous mode\n")
1373{
1374 return vtysh_exit (vty);
1375}
1376
1377ALIAS (vtysh_exit_interface,
1378 vtysh_quit_interface_cmd,
1379 "quit",
1380 "Exit current mode and down to previous mode\n")
1381
Donald Sharp567a6382015-08-19 21:22:17 -04001382DEFUN (vtysh_show_thread,
1383 vtysh_show_thread_cmd,
1384 "show thread cpu [FILTER]",
1385 SHOW_STR
1386 "Thread information\n"
1387 "Thread CPU usage\n"
1388 "Display filter (rwtexb)\n")
1389{
1390 unsigned int i;
1391 int ret = CMD_SUCCESS;
1392 char line[100];
1393
1394 sprintf(line, "show thread cpu %s\n", (argc == 1) ? argv[0] : "");
1395 for (i = 0; i < array_size(vtysh_client); i++)
1396 if ( vtysh_client[i].fd >= 0 )
1397 {
1398 fprintf (stdout, "Thread statistics for %s:\n",
1399 vtysh_client[i].name);
1400 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1401 fprintf (stdout,"\n");
1402 }
1403 return ret;
1404}
1405
1406DEFUN (vtysh_show_work_queues,
1407 vtysh_show_work_queues_cmd,
1408 "show work-queues",
1409 SHOW_STR
1410 "Work Queue information\n")
1411{
1412 unsigned int i;
1413 int ret = CMD_SUCCESS;
1414 char line[] = "show work-queues\n";
1415
1416 for (i = 0; i < array_size(vtysh_client); i++)
1417 if ( vtysh_client[i].fd >= 0 )
1418 {
1419 fprintf (stdout, "Work queue statistics for %s:\n",
1420 vtysh_client[i].name);
1421 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1422 fprintf (stdout,"\n");
1423 }
1424
1425 return ret;
1426}
1427
Donald Sharp07440402016-02-25 07:39:45 -05001428DEFUN (vtysh_show_work_queues_daemon,
1429 vtysh_show_work_queues_daemon_cmd,
1430 "show work-queues (zebra|ripd|ripngd|ospfd|ospf6d|bgpd|isisd)",
1431 SHOW_STR
1432 "Work Queue information\n"
1433 "For the zebra daemon\n"
1434 "For the rip daemon\n"
1435 "For the ripng daemon\n"
1436 "For the ospf daemon\n"
1437 "For the ospfv6 daemon\n"
1438 "For the bgp daemon\n"
1439 "For the isis daemon\n")
1440{
1441 unsigned int i;
1442 int ret = CMD_SUCCESS;
1443
1444 for (i = 0; i < array_size(vtysh_client); i++)
1445 {
1446 if (begins_with(vtysh_client[i].name, argv[0]))
1447 break;
1448 }
1449
1450 ret = vtysh_client_execute(&vtysh_client[i], "show work-queues\n", stdout);
1451
1452 return ret;
1453}
1454
Olivier Dugeonac10d302016-04-19 18:33:42 +02001455DEFUNSH (VTYSH_ZEBRA,
1456 vtysh_link_params,
1457 vtysh_link_params_cmd,
1458 "link-params",
1459 LINK_PARAMS_STR
1460 )
1461{
1462 vty->node = LINK_PARAMS_NODE;
1463 return CMD_SUCCESS;
1464}
1465
Paul Jakma362b4032006-05-28 07:54:45 +00001466/* Memory */
1467DEFUN (vtysh_show_memory,
1468 vtysh_show_memory_cmd,
1469 "show memory",
1470 SHOW_STR
1471 "Memory statistics\n")
1472{
1473 unsigned int i;
1474 int ret = CMD_SUCCESS;
1475 char line[] = "show memory\n";
1476
Balaji.G837d16c2012-09-26 14:09:10 +05301477 for (i = 0; i < array_size(vtysh_client); i++)
Paul Jakma362b4032006-05-28 07:54:45 +00001478 if ( vtysh_client[i].fd >= 0 )
1479 {
1480 fprintf (stdout, "Memory statistics for %s:\n",
1481 vtysh_client[i].name);
1482 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1483 fprintf (stdout,"\n");
1484 }
1485
1486 return ret;
1487}
1488
hasso95e735b2004-08-26 13:08:30 +00001489/* Logging commands. */
Paul Jakmadbf7d132006-05-23 22:10:01 +00001490DEFUN (vtysh_show_logging,
1491 vtysh_show_logging_cmd,
1492 "show logging",
1493 SHOW_STR
1494 "Show current logging configuration\n")
1495{
1496 unsigned int i;
1497 int ret = CMD_SUCCESS;
1498 char line[] = "show logging\n";
1499
Balaji.G837d16c2012-09-26 14:09:10 +05301500 for (i = 0; i < array_size(vtysh_client); i++)
Paul Jakma4150f332006-05-23 22:10:55 +00001501 if ( vtysh_client[i].fd >= 0 )
1502 {
1503 fprintf (stdout,"Logging configuration for %s:\n",
1504 vtysh_client[i].name);
1505 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1506 fprintf (stdout,"\n");
1507 }
1508
Paul Jakmadbf7d132006-05-23 22:10:01 +00001509 return ret;
1510}
1511
hasso95e735b2004-08-26 13:08:30 +00001512DEFUNSH (VTYSH_ALL,
1513 vtysh_log_stdout,
1514 vtysh_log_stdout_cmd,
1515 "log stdout",
1516 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001517 "Set stdout logging level\n")
1518{
1519 return CMD_SUCCESS;
1520}
1521
1522DEFUNSH (VTYSH_ALL,
1523 vtysh_log_stdout_level,
1524 vtysh_log_stdout_level_cmd,
1525 "log stdout "LOG_LEVELS,
1526 "Logging control\n"
1527 "Set stdout logging level\n"
1528 LOG_LEVEL_DESC)
hasso95e735b2004-08-26 13:08:30 +00001529{
1530 return CMD_SUCCESS;
1531}
1532
1533DEFUNSH (VTYSH_ALL,
1534 no_vtysh_log_stdout,
1535 no_vtysh_log_stdout_cmd,
ajs274a4a42004-12-07 15:39:31 +00001536 "no log stdout [LEVEL]",
hasso95e735b2004-08-26 13:08:30 +00001537 NO_STR
1538 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001539 "Cancel logging to stdout\n"
1540 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001541{
1542 return CMD_SUCCESS;
1543}
1544
1545DEFUNSH (VTYSH_ALL,
1546 vtysh_log_file,
1547 vtysh_log_file_cmd,
1548 "log file FILENAME",
1549 "Logging control\n"
1550 "Logging to file\n"
1551 "Logging filename\n")
1552{
1553 return CMD_SUCCESS;
1554}
1555
1556DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001557 vtysh_log_file_level,
1558 vtysh_log_file_level_cmd,
1559 "log file FILENAME "LOG_LEVELS,
1560 "Logging control\n"
1561 "Logging to file\n"
1562 "Logging filename\n"
1563 LOG_LEVEL_DESC)
1564{
1565 return CMD_SUCCESS;
1566}
1567
1568DEFUNSH (VTYSH_ALL,
hasso95e735b2004-08-26 13:08:30 +00001569 no_vtysh_log_file,
1570 no_vtysh_log_file_cmd,
1571 "no log file [FILENAME]",
1572 NO_STR
1573 "Logging control\n"
1574 "Cancel logging to file\n"
1575 "Logging file name\n")
1576{
1577 return CMD_SUCCESS;
1578}
1579
ajs274a4a42004-12-07 15:39:31 +00001580ALIAS_SH (VTYSH_ALL,
1581 no_vtysh_log_file,
1582 no_vtysh_log_file_level_cmd,
1583 "no log file FILENAME LEVEL",
1584 NO_STR
1585 "Logging control\n"
1586 "Cancel logging to file\n"
1587 "Logging file name\n"
1588 "Logging level\n")
1589
1590DEFUNSH (VTYSH_ALL,
1591 vtysh_log_monitor,
1592 vtysh_log_monitor_cmd,
1593 "log monitor",
1594 "Logging control\n"
1595 "Set terminal line (monitor) logging level\n")
1596{
1597 return CMD_SUCCESS;
1598}
1599
1600DEFUNSH (VTYSH_ALL,
1601 vtysh_log_monitor_level,
1602 vtysh_log_monitor_level_cmd,
1603 "log monitor "LOG_LEVELS,
1604 "Logging control\n"
1605 "Set terminal line (monitor) logging level\n"
1606 LOG_LEVEL_DESC)
1607{
1608 return CMD_SUCCESS;
1609}
1610
1611DEFUNSH (VTYSH_ALL,
1612 no_vtysh_log_monitor,
1613 no_vtysh_log_monitor_cmd,
1614 "no log monitor [LEVEL]",
1615 NO_STR
1616 "Logging control\n"
1617 "Disable terminal line (monitor) logging\n"
1618 "Logging level\n")
1619{
1620 return CMD_SUCCESS;
1621}
1622
hasso95e735b2004-08-26 13:08:30 +00001623DEFUNSH (VTYSH_ALL,
1624 vtysh_log_syslog,
1625 vtysh_log_syslog_cmd,
1626 "log syslog",
1627 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001628 "Set syslog logging level\n")
1629{
1630 return CMD_SUCCESS;
1631}
1632
1633DEFUNSH (VTYSH_ALL,
1634 vtysh_log_syslog_level,
1635 vtysh_log_syslog_level_cmd,
1636 "log syslog "LOG_LEVELS,
1637 "Logging control\n"
1638 "Set syslog logging level\n"
1639 LOG_LEVEL_DESC)
hasso95e735b2004-08-26 13:08:30 +00001640{
1641 return CMD_SUCCESS;
1642}
1643
1644DEFUNSH (VTYSH_ALL,
1645 no_vtysh_log_syslog,
1646 no_vtysh_log_syslog_cmd,
ajs274a4a42004-12-07 15:39:31 +00001647 "no log syslog [LEVEL]",
hasso95e735b2004-08-26 13:08:30 +00001648 NO_STR
1649 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001650 "Cancel logging to syslog\n"
1651 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001652{
1653 return CMD_SUCCESS;
1654}
1655
1656DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001657 vtysh_log_facility,
1658 vtysh_log_facility_cmd,
1659 "log facility "LOG_FACILITIES,
hasso95e735b2004-08-26 13:08:30 +00001660 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001661 "Facility parameter for syslog messages\n"
1662 LOG_FACILITY_DESC)
1663
hasso95e735b2004-08-26 13:08:30 +00001664{
1665 return CMD_SUCCESS;
1666}
1667
1668DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001669 no_vtysh_log_facility,
1670 no_vtysh_log_facility_cmd,
1671 "no log facility [FACILITY]",
hasso95e735b2004-08-26 13:08:30 +00001672 NO_STR
1673 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001674 "Reset syslog facility to default (daemon)\n"
1675 "Syslog facility\n")
1676
1677{
1678 return CMD_SUCCESS;
1679}
1680
1681DEFUNSH_DEPRECATED (VTYSH_ALL,
1682 vtysh_log_trap,
1683 vtysh_log_trap_cmd,
1684 "log trap "LOG_LEVELS,
1685 "Logging control\n"
1686 "(Deprecated) Set logging level and default for all destinations\n"
1687 LOG_LEVEL_DESC)
1688
1689{
1690 return CMD_SUCCESS;
1691}
1692
1693DEFUNSH_DEPRECATED (VTYSH_ALL,
1694 no_vtysh_log_trap,
1695 no_vtysh_log_trap_cmd,
1696 "no log trap [LEVEL]",
1697 NO_STR
1698 "Logging control\n"
1699 "Permit all logging information\n"
1700 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001701{
1702 return CMD_SUCCESS;
1703}
1704
1705DEFUNSH (VTYSH_ALL,
1706 vtysh_log_record_priority,
1707 vtysh_log_record_priority_cmd,
1708 "log record-priority",
1709 "Logging control\n"
1710 "Log the priority of the message within the message\n")
1711{
1712 return CMD_SUCCESS;
1713}
1714
1715DEFUNSH (VTYSH_ALL,
1716 no_vtysh_log_record_priority,
1717 no_vtysh_log_record_priority_cmd,
1718 "no log record-priority",
1719 NO_STR
1720 "Logging control\n"
1721 "Do not log the priority of the message within the message\n")
1722{
1723 return CMD_SUCCESS;
1724}
1725
hassoe7168df2004-10-03 20:11:32 +00001726DEFUNSH (VTYSH_ALL,
Andrew J. Schorrc749b722007-04-29 03:53:31 +00001727 vtysh_log_timestamp_precision,
1728 vtysh_log_timestamp_precision_cmd,
1729 "log timestamp precision <0-6>",
1730 "Logging control\n"
1731 "Timestamp configuration\n"
1732 "Set the timestamp precision\n"
1733 "Number of subsecond digits\n")
1734{
1735 return CMD_SUCCESS;
1736}
1737
1738DEFUNSH (VTYSH_ALL,
1739 no_vtysh_log_timestamp_precision,
1740 no_vtysh_log_timestamp_precision_cmd,
1741 "no log timestamp precision",
1742 NO_STR
1743 "Logging control\n"
1744 "Timestamp configuration\n"
1745 "Reset the timestamp precision to the default value of 0\n")
1746{
1747 return CMD_SUCCESS;
1748}
1749
1750DEFUNSH (VTYSH_ALL,
hassoe7168df2004-10-03 20:11:32 +00001751 vtysh_service_password_encrypt,
1752 vtysh_service_password_encrypt_cmd,
1753 "service password-encryption",
1754 "Set up miscellaneous service\n"
1755 "Enable encrypted passwords\n")
1756{
1757 return CMD_SUCCESS;
1758}
1759
1760DEFUNSH (VTYSH_ALL,
1761 no_vtysh_service_password_encrypt,
1762 no_vtysh_service_password_encrypt_cmd,
1763 "no service password-encryption",
1764 NO_STR
1765 "Set up miscellaneous service\n"
1766 "Enable encrypted passwords\n")
1767{
1768 return CMD_SUCCESS;
1769}
1770
1771DEFUNSH (VTYSH_ALL,
1772 vtysh_config_password,
1773 vtysh_password_cmd,
1774 "password (8|) WORD",
1775 "Assign the terminal connection password\n"
1776 "Specifies a HIDDEN password will follow\n"
1777 "dummy string \n"
1778 "The HIDDEN line password string\n")
1779{
1780 return CMD_SUCCESS;
1781}
1782
1783DEFUNSH (VTYSH_ALL,
1784 vtysh_password_text,
1785 vtysh_password_text_cmd,
1786 "password LINE",
1787 "Assign the terminal connection password\n"
1788 "The UNENCRYPTED (cleartext) line password\n")
1789{
1790 return CMD_SUCCESS;
1791}
1792
1793DEFUNSH (VTYSH_ALL,
1794 vtysh_config_enable_password,
1795 vtysh_enable_password_cmd,
1796 "enable password (8|) WORD",
1797 "Modify enable password parameters\n"
1798 "Assign the privileged level password\n"
1799 "Specifies a HIDDEN password will follow\n"
1800 "dummy string \n"
1801 "The HIDDEN 'enable' password string\n")
1802{
1803 return CMD_SUCCESS;
1804}
1805
1806DEFUNSH (VTYSH_ALL,
1807 vtysh_enable_password_text,
1808 vtysh_enable_password_text_cmd,
1809 "enable password LINE",
1810 "Modify enable password parameters\n"
1811 "Assign the privileged level password\n"
1812 "The UNENCRYPTED (cleartext) 'enable' password\n")
1813{
1814 return CMD_SUCCESS;
1815}
1816
1817DEFUNSH (VTYSH_ALL,
1818 no_vtysh_config_enable_password,
1819 no_vtysh_enable_password_cmd,
1820 "no enable password",
1821 NO_STR
1822 "Modify enable password parameters\n"
1823 "Assign the privileged level password\n")
1824{
1825 return CMD_SUCCESS;
1826}
1827
paul718e3742002-12-13 20:15:29 +00001828DEFUN (vtysh_write_terminal,
1829 vtysh_write_terminal_cmd,
1830 "write terminal",
1831 "Write running configuration to memory, network, or terminal\n"
1832 "Write to terminal\n")
1833{
ajsb1aa1472005-01-28 21:11:46 +00001834 u_int i;
paul718e3742002-12-13 20:15:29 +00001835 char line[] = "write terminal\n";
1836 FILE *fp = NULL;
1837
1838 if (vtysh_pager_name)
1839 {
paul4fc01e62002-12-13 20:49:00 +00001840 fp = popen (vtysh_pager_name, "w");
paul718e3742002-12-13 20:15:29 +00001841 if (fp == NULL)
1842 {
1843 perror ("popen");
1844 exit (1);
1845 }
1846 }
1847 else
1848 fp = stdout;
1849
1850 vty_out (vty, "Building configuration...%s", VTY_NEWLINE);
1851 vty_out (vty, "%sCurrent configuration:%s", VTY_NEWLINE,
1852 VTY_NEWLINE);
hassoe7168df2004-10-03 20:11:32 +00001853 vty_out (vty, "!%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001854
Balaji.G837d16c2012-09-26 14:09:10 +05301855 for (i = 0; i < array_size(vtysh_client); i++)
Gautam Kumarcc216b72015-10-26 13:22:12 -07001856 vtysh_client_execute (&vtysh_client[i], line, NULL);
paul718e3742002-12-13 20:15:29 +00001857
hassoe7168df2004-10-03 20:11:32 +00001858 /* Integrate vtysh specific configuration. */
1859 vtysh_config_write ();
1860
paul718e3742002-12-13 20:15:29 +00001861 vtysh_config_dump (fp);
1862
1863 if (vtysh_pager_name && fp)
1864 {
1865 fflush (fp);
1866 if (pclose (fp) == -1)
1867 {
1868 perror ("pclose");
1869 exit (1);
1870 }
1871 fp = NULL;
1872 }
1873
Chris Caputo6e79f8b2009-06-23 05:55:57 +00001874 vty_out (vty, "end%s", VTY_NEWLINE);
1875
paul718e3742002-12-13 20:15:29 +00001876 return CMD_SUCCESS;
1877}
1878
Donald Sharp9fb73e82015-09-22 11:13:12 -04001879DEFUN (vtysh_write_terminal_daemon,
1880 vtysh_write_terminal_daemon_cmd,
1881 "write terminal (zebra|ripd|ripngd|ospfd|ospf6d|bgpd|isisd|babeld)",
1882 "Write running configuration to memory, network, or terminal\n"
1883 "Write to terminal\n"
1884 "For the zebra daemon\n"
1885 "For the rip daemon\n"
1886 "For the ripng daemon\n"
1887 "For the ospf daemon\n"
1888 "For the ospfv6 daemon\n"
1889 "For the bgp daemon\n"
1890 "For the isis daemon\n"
1891 "For the babel daemon\n")
1892{
1893 unsigned int i;
1894 int ret = CMD_SUCCESS;
1895
1896 for (i = 0; i < array_size(vtysh_client); i++)
1897 {
1898 if (strcmp(vtysh_client[i].name, argv[0]) == 0)
1899 break;
1900 }
1901
1902 ret = vtysh_client_execute(&vtysh_client[i], "show running-config\n", stdout);
1903
1904 return ret;
1905}
1906
hassoe7168df2004-10-03 20:11:32 +00001907DEFUN (vtysh_integrated_config,
1908 vtysh_integrated_config_cmd,
1909 "service integrated-vtysh-config",
1910 "Set up miscellaneous service\n"
1911 "Write configuration into integrated file\n")
paul4fc01e62002-12-13 20:49:00 +00001912{
hassoe7168df2004-10-03 20:11:32 +00001913 vtysh_writeconfig_integrated = 1;
1914 return CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001915}
1916
hassoe7168df2004-10-03 20:11:32 +00001917DEFUN (no_vtysh_integrated_config,
1918 no_vtysh_integrated_config_cmd,
1919 "no service integrated-vtysh-config",
1920 NO_STR
1921 "Set up miscellaneous service\n"
1922 "Write configuration into integrated file\n")
paul4fc01e62002-12-13 20:49:00 +00001923{
hassoe7168df2004-10-03 20:11:32 +00001924 vtysh_writeconfig_integrated = 0;
1925 return CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001926}
1927
ajs274a4a42004-12-07 15:39:31 +00001928static int
1929write_config_integrated(void)
paul718e3742002-12-13 20:15:29 +00001930{
ajsb1aa1472005-01-28 21:11:46 +00001931 u_int i;
paul718e3742002-12-13 20:15:29 +00001932 char line[] = "write terminal\n";
1933 FILE *fp;
1934 char *integrate_sav = NULL;
1935
hasso95e735b2004-08-26 13:08:30 +00001936 integrate_sav = malloc (strlen (integrate_default) +
1937 strlen (CONF_BACKUP_EXT) + 1);
paul718e3742002-12-13 20:15:29 +00001938 strcpy (integrate_sav, integrate_default);
1939 strcat (integrate_sav, CONF_BACKUP_EXT);
1940
paul4fc01e62002-12-13 20:49:00 +00001941 fprintf (stdout,"Building Configuration...\n");
paul718e3742002-12-13 20:15:29 +00001942
hasso95e735b2004-08-26 13:08:30 +00001943 /* Move current configuration file to backup config file. */
paul718e3742002-12-13 20:15:29 +00001944 unlink (integrate_sav);
1945 rename (integrate_default, integrate_sav);
hasso95e735b2004-08-26 13:08:30 +00001946 free (integrate_sav);
paul4fc01e62002-12-13 20:49:00 +00001947
paul718e3742002-12-13 20:15:29 +00001948 fp = fopen (integrate_default, "w");
1949 if (fp == NULL)
1950 {
hasso95e735b2004-08-26 13:08:30 +00001951 fprintf (stdout,"%% Can't open configuration file %s.\n",
1952 integrate_default);
paul718e3742002-12-13 20:15:29 +00001953 return CMD_SUCCESS;
1954 }
paul718e3742002-12-13 20:15:29 +00001955
Balaji.G837d16c2012-09-26 14:09:10 +05301956 for (i = 0; i < array_size(vtysh_client); i++)
Gautam Kumarcc216b72015-10-26 13:22:12 -07001957 vtysh_client_execute (&vtysh_client[i], line, NULL);
paul718e3742002-12-13 20:15:29 +00001958
Donald Sharp147a8122015-05-21 16:06:21 -07001959 vtysh_config_write ();
paul718e3742002-12-13 20:15:29 +00001960 vtysh_config_dump (fp);
1961
1962 fclose (fp);
1963
gdtaa593d52003-12-22 20:15:53 +00001964 if (chmod (integrate_default, CONFIGFILE_MASK) != 0)
1965 {
1966 fprintf (stdout,"%% Can't chmod configuration file %s: %s (%d)\n",
ajs6099b3b2004-11-20 02:06:59 +00001967 integrate_default, safe_strerror(errno), errno);
gdtaa593d52003-12-22 20:15:53 +00001968 return CMD_WARNING;
1969 }
1970
paul4fc01e62002-12-13 20:49:00 +00001971 fprintf(stdout,"Integrated configuration saved to %s\n",integrate_default);
1972
1973 fprintf (stdout,"[OK]\n");
1974
paul718e3742002-12-13 20:15:29 +00001975 return CMD_SUCCESS;
1976}
1977
paul4fc01e62002-12-13 20:49:00 +00001978DEFUN (vtysh_write_memory,
1979 vtysh_write_memory_cmd,
1980 "write memory",
1981 "Write running configuration to memory, network, or terminal\n"
1982 "Write configuration to the file (same as write file)\n")
1983{
pauldfc0d9b2003-04-18 23:55:29 +00001984 int ret = CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001985 char line[] = "write memory\n";
ajsb1aa1472005-01-28 21:11:46 +00001986 u_int i;
paul4fc01e62002-12-13 20:49:00 +00001987
hassoe7168df2004-10-03 20:11:32 +00001988 /* If integrated Quagga.conf explicitely set. */
1989 if (vtysh_writeconfig_integrated)
1990 return write_config_integrated();
paul4fc01e62002-12-13 20:49:00 +00001991
1992 fprintf (stdout,"Building Configuration...\n");
1993
Balaji.G837d16c2012-09-26 14:09:10 +05301994 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00001995 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
hassoe7168df2004-10-03 20:11:32 +00001996
paul4fc01e62002-12-13 20:49:00 +00001997 fprintf (stdout,"[OK]\n");
1998
pauldfc0d9b2003-04-18 23:55:29 +00001999 return ret;
paul4fc01e62002-12-13 20:49:00 +00002000}
2001
paul718e3742002-12-13 20:15:29 +00002002ALIAS (vtysh_write_memory,
2003 vtysh_copy_runningconfig_startupconfig_cmd,
2004 "copy running-config startup-config",
2005 "Copy from one file to another\n"
2006 "Copy from current system configuration\n"
2007 "Copy to startup configuration\n")
2008
2009ALIAS (vtysh_write_memory,
2010 vtysh_write_file_cmd,
2011 "write file",
2012 "Write running configuration to memory, network, or terminal\n"
2013 "Write configuration to the file (same as write memory)\n")
2014
hasso4a6e2252003-05-25 11:51:29 +00002015ALIAS (vtysh_write_memory,
2016 vtysh_write_cmd,
2017 "write",
2018 "Write running configuration to memory, network, or terminal\n")
2019
paul718e3742002-12-13 20:15:29 +00002020ALIAS (vtysh_write_terminal,
2021 vtysh_show_running_config_cmd,
2022 "show running-config",
2023 SHOW_STR
2024 "Current operating configuration\n")
hassob094d262004-08-25 12:22:00 +00002025
Donald Sharp9fb73e82015-09-22 11:13:12 -04002026ALIAS (vtysh_write_terminal_daemon,
2027 vtysh_show_running_config_daemon_cmd,
2028 "show running-config (zebra|ripd|ripngd|ospfd|ospf6d|bgpd|isisd|babeld)",
2029 SHOW_STR
2030 "Current operating configuration\n"
2031 "For the zebra daemon\n"
2032 "For the rip daemon\n"
2033 "For the ripng daemon\n"
2034 "For the ospf daemon\n"
2035 "For the ospfv6 daemon\n"
2036 "For the bgp daemon\n"
2037 "For the isis daemon\n"
2038 "For the babel daemon\n")
2039
hasso34553cc2004-08-27 13:56:39 +00002040DEFUN (vtysh_terminal_length,
2041 vtysh_terminal_length_cmd,
2042 "terminal length <0-512>",
2043 "Set terminal line parameters\n"
2044 "Set number of lines on a screen\n"
2045 "Number of lines on screen (0 for no pausing)\n")
2046{
2047 int lines;
2048 char *endptr = NULL;
2049 char default_pager[10];
2050
2051 lines = strtol (argv[0], &endptr, 10);
2052 if (lines < 0 || lines > 512 || *endptr != '\0')
2053 {
2054 vty_out (vty, "length is malformed%s", VTY_NEWLINE);
2055 return CMD_WARNING;
2056 }
2057
2058 if (vtysh_pager_name)
2059 {
2060 free (vtysh_pager_name);
2061 vtysh_pager_name = NULL;
2062 }
2063
2064 if (lines != 0)
2065 {
2066 snprintf(default_pager, 10, "more -%i", lines);
2067 vtysh_pager_name = strdup (default_pager);
2068 }
2069
2070 return CMD_SUCCESS;
2071}
2072
2073DEFUN (vtysh_terminal_no_length,
2074 vtysh_terminal_no_length_cmd,
2075 "terminal no length",
2076 "Set terminal line parameters\n"
2077 NO_STR
2078 "Set number of lines on a screen\n")
2079{
2080 if (vtysh_pager_name)
2081 {
2082 free (vtysh_pager_name);
2083 vtysh_pager_name = NULL;
2084 }
2085
2086 vtysh_pager_init();
2087 return CMD_SUCCESS;
2088}
2089
hassof2799e62004-10-28 17:43:11 +00002090DEFUN (vtysh_show_daemons,
2091 vtysh_show_daemons_cmd,
2092 "show daemons",
hassoe7168df2004-10-03 20:11:32 +00002093 SHOW_STR
2094 "Show list of running daemons\n")
2095{
ajsb1aa1472005-01-28 21:11:46 +00002096 u_int i;
2097
Balaji.G837d16c2012-09-26 14:09:10 +05302098 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00002099 if ( vtysh_client[i].fd >= 0 )
2100 vty_out(vty, " %s", vtysh_client[i].name);
hassoe7168df2004-10-03 20:11:32 +00002101 vty_out(vty, "%s", VTY_NEWLINE);
2102
2103 return CMD_SUCCESS;
2104}
2105
paul718e3742002-12-13 20:15:29 +00002106/* Execute command in child process. */
ajs274a4a42004-12-07 15:39:31 +00002107static int
hasso5862ff52004-10-11 13:20:40 +00002108execute_command (const char *command, int argc, const char *arg1,
2109 const char *arg2)
paul718e3742002-12-13 20:15:29 +00002110{
paul718e3742002-12-13 20:15:29 +00002111 pid_t pid;
2112 int status;
2113
2114 /* Call fork(). */
2115 pid = fork ();
2116
2117 if (pid < 0)
2118 {
2119 /* Failure of fork(). */
ajs6099b3b2004-11-20 02:06:59 +00002120 fprintf (stderr, "Can't fork: %s\n", safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +00002121 exit (1);
2122 }
2123 else if (pid == 0)
2124 {
2125 /* This is child process. */
2126 switch (argc)
2127 {
2128 case 0:
David Lamparter6769f432015-03-04 07:18:24 +01002129 execlp (command, command, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00002130 break;
2131 case 1:
David Lamparter6769f432015-03-04 07:18:24 +01002132 execlp (command, command, arg1, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00002133 break;
2134 case 2:
David Lamparter6769f432015-03-04 07:18:24 +01002135 execlp (command, command, arg1, arg2, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00002136 break;
2137 }
2138
2139 /* When execlp suceed, this part is not executed. */
ajs6099b3b2004-11-20 02:06:59 +00002140 fprintf (stderr, "Can't execute %s: %s\n", command, safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +00002141 exit (1);
2142 }
2143 else
2144 {
2145 /* This is parent. */
2146 execute_flag = 1;
David Lamparter6769f432015-03-04 07:18:24 +01002147 wait4 (pid, &status, 0, NULL);
paul718e3742002-12-13 20:15:29 +00002148 execute_flag = 0;
2149 }
2150 return 0;
2151}
2152
2153DEFUN (vtysh_ping,
2154 vtysh_ping_cmd,
2155 "ping WORD",
hasso4eeccf12003-06-25 10:49:55 +00002156 "Send echo messages\n"
paul718e3742002-12-13 20:15:29 +00002157 "Ping destination address or hostname\n")
2158{
2159 execute_command ("ping", 1, argv[0], NULL);
2160 return CMD_SUCCESS;
2161}
2162
hasso4eeccf12003-06-25 10:49:55 +00002163ALIAS (vtysh_ping,
2164 vtysh_ping_ip_cmd,
2165 "ping ip WORD",
2166 "Send echo messages\n"
2167 "IP echo\n"
2168 "Ping destination address or hostname\n")
2169
paul718e3742002-12-13 20:15:29 +00002170DEFUN (vtysh_traceroute,
2171 vtysh_traceroute_cmd,
2172 "traceroute WORD",
2173 "Trace route to destination\n"
2174 "Trace route to destination address or hostname\n")
2175{
2176 execute_command ("traceroute", 1, argv[0], NULL);
2177 return CMD_SUCCESS;
2178}
2179
hasso4eeccf12003-06-25 10:49:55 +00002180ALIAS (vtysh_traceroute,
2181 vtysh_traceroute_ip_cmd,
2182 "traceroute ip WORD",
2183 "Trace route to destination\n"
2184 "IP trace\n"
2185 "Trace route to destination address or hostname\n")
2186
2187#ifdef HAVE_IPV6
2188DEFUN (vtysh_ping6,
2189 vtysh_ping6_cmd,
2190 "ping ipv6 WORD",
2191 "Send echo messages\n"
2192 "IPv6 echo\n"
2193 "Ping destination address or hostname\n")
2194{
2195 execute_command ("ping6", 1, argv[0], NULL);
2196 return CMD_SUCCESS;
2197}
2198
2199DEFUN (vtysh_traceroute6,
2200 vtysh_traceroute6_cmd,
2201 "traceroute ipv6 WORD",
2202 "Trace route to destination\n"
2203 "IPv6 trace\n"
2204 "Trace route to destination address or hostname\n")
2205{
2206 execute_command ("traceroute6", 1, argv[0], NULL);
2207 return CMD_SUCCESS;
2208}
2209#endif
2210
paul718e3742002-12-13 20:15:29 +00002211DEFUN (vtysh_telnet,
2212 vtysh_telnet_cmd,
2213 "telnet WORD",
2214 "Open a telnet connection\n"
2215 "IP address or hostname of a remote system\n")
2216{
2217 execute_command ("telnet", 1, argv[0], NULL);
2218 return CMD_SUCCESS;
2219}
2220
2221DEFUN (vtysh_telnet_port,
2222 vtysh_telnet_port_cmd,
2223 "telnet WORD PORT",
2224 "Open a telnet connection\n"
2225 "IP address or hostname of a remote system\n"
2226 "TCP Port number\n")
2227{
2228 execute_command ("telnet", 2, argv[0], argv[1]);
2229 return CMD_SUCCESS;
2230}
2231
paul5087df52003-01-25 06:56:09 +00002232DEFUN (vtysh_ssh,
2233 vtysh_ssh_cmd,
2234 "ssh WORD",
2235 "Open an ssh connection\n"
2236 "[user@]host\n")
2237{
2238 execute_command ("ssh", 1, argv[0], NULL);
2239 return CMD_SUCCESS;
2240}
2241
paul718e3742002-12-13 20:15:29 +00002242DEFUN (vtysh_start_shell,
2243 vtysh_start_shell_cmd,
2244 "start-shell",
2245 "Start UNIX shell\n")
2246{
2247 execute_command ("sh", 0, NULL, NULL);
2248 return CMD_SUCCESS;
2249}
2250
2251DEFUN (vtysh_start_bash,
2252 vtysh_start_bash_cmd,
2253 "start-shell bash",
2254 "Start UNIX shell\n"
2255 "Start bash\n")
2256{
2257 execute_command ("bash", 0, NULL, NULL);
2258 return CMD_SUCCESS;
2259}
2260
2261DEFUN (vtysh_start_zsh,
2262 vtysh_start_zsh_cmd,
2263 "start-shell zsh",
2264 "Start UNIX shell\n"
2265 "Start Z shell\n")
2266{
2267 execute_command ("zsh", 0, NULL, NULL);
2268 return CMD_SUCCESS;
2269}
hassob094d262004-08-25 12:22:00 +00002270
ajs274a4a42004-12-07 15:39:31 +00002271static void
paul718e3742002-12-13 20:15:29 +00002272vtysh_install_default (enum node_type node)
2273{
2274 install_element (node, &config_list_cmd);
2275}
2276
2277/* Making connection to protocol daemon. */
ajs274a4a42004-12-07 15:39:31 +00002278static int
ajsb1aa1472005-01-28 21:11:46 +00002279vtysh_connect (struct vtysh_client *vclient)
paul718e3742002-12-13 20:15:29 +00002280{
2281 int ret;
2282 int sock, len;
2283 struct sockaddr_un addr;
2284 struct stat s_stat;
paul718e3742002-12-13 20:15:29 +00002285
paul718e3742002-12-13 20:15:29 +00002286 /* Stat socket to see if we have permission to access it. */
ajsb1aa1472005-01-28 21:11:46 +00002287 ret = stat (vclient->path, &s_stat);
paul718e3742002-12-13 20:15:29 +00002288 if (ret < 0 && errno != ENOENT)
2289 {
2290 fprintf (stderr, "vtysh_connect(%s): stat = %s\n",
ajsb1aa1472005-01-28 21:11:46 +00002291 vclient->path, safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002292 exit(1);
2293 }
2294
2295 if (ret >= 0)
2296 {
2297 if (! S_ISSOCK(s_stat.st_mode))
2298 {
2299 fprintf (stderr, "vtysh_connect(%s): Not a socket\n",
ajsb1aa1472005-01-28 21:11:46 +00002300 vclient->path);
paul718e3742002-12-13 20:15:29 +00002301 exit (1);
2302 }
2303
paul718e3742002-12-13 20:15:29 +00002304 }
2305
2306 sock = socket (AF_UNIX, SOCK_STREAM, 0);
2307 if (sock < 0)
2308 {
2309#ifdef DEBUG
ajsb1aa1472005-01-28 21:11:46 +00002310 fprintf(stderr, "vtysh_connect(%s): socket = %s\n", vclient->path,
ajs6099b3b2004-11-20 02:06:59 +00002311 safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002312#endif /* DEBUG */
2313 return -1;
2314 }
2315
2316 memset (&addr, 0, sizeof (struct sockaddr_un));
2317 addr.sun_family = AF_UNIX;
ajsb1aa1472005-01-28 21:11:46 +00002318 strncpy (addr.sun_path, vclient->path, strlen (vclient->path));
Paul Jakma6f0e3f62007-05-10 02:38:51 +00002319#ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
paul718e3742002-12-13 20:15:29 +00002320 len = addr.sun_len = SUN_LEN(&addr);
2321#else
2322 len = sizeof (addr.sun_family) + strlen (addr.sun_path);
Paul Jakma6f0e3f62007-05-10 02:38:51 +00002323#endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
paul718e3742002-12-13 20:15:29 +00002324
2325 ret = connect (sock, (struct sockaddr *) &addr, len);
2326 if (ret < 0)
2327 {
2328#ifdef DEBUG
ajsb1aa1472005-01-28 21:11:46 +00002329 fprintf(stderr, "vtysh_connect(%s): connect = %s\n", vclient->path,
ajs6099b3b2004-11-20 02:06:59 +00002330 safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002331#endif /* DEBUG */
2332 close (sock);
2333 return -1;
2334 }
2335 vclient->fd = sock;
2336
2337 return 0;
2338}
2339
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002340int
2341vtysh_connect_all(const char *daemon_name)
paul718e3742002-12-13 20:15:29 +00002342{
ajsb1aa1472005-01-28 21:11:46 +00002343 u_int i;
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002344 int rc = 0;
2345 int matches = 0;
ajsb1aa1472005-01-28 21:11:46 +00002346
Balaji.G837d16c2012-09-26 14:09:10 +05302347 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00002348 {
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002349 if (!daemon_name || !strcmp(daemon_name, vtysh_client[i].name))
2350 {
2351 matches++;
2352 if (vtysh_connect(&vtysh_client[i]) == 0)
2353 rc++;
2354 /* We need direct access to ripd in vtysh_exit_ripd_only. */
2355 if (vtysh_client[i].flag == VTYSH_RIPD)
2356 ripd_client = &vtysh_client[i];
2357 }
ajsb1aa1472005-01-28 21:11:46 +00002358 }
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002359 if (!matches)
2360 fprintf(stderr, "Error: no daemons match name %s!\n", daemon_name);
2361 return rc;
paul718e3742002-12-13 20:15:29 +00002362}
2363
hasso95e735b2004-08-26 13:08:30 +00002364/* To disable readline's filename completion. */
ajs274a4a42004-12-07 15:39:31 +00002365static char *
pauldfc0d9b2003-04-18 23:55:29 +00002366vtysh_completion_entry_function (const char *ignore, int invoking_key)
paul718e3742002-12-13 20:15:29 +00002367{
pauldfc0d9b2003-04-18 23:55:29 +00002368 return NULL;
paul718e3742002-12-13 20:15:29 +00002369}
2370
2371void
ajsb1aa1472005-01-28 21:11:46 +00002372vtysh_readline_init (void)
paul718e3742002-12-13 20:15:29 +00002373{
2374 /* readline related settings. */
Sébastien Luttringer66d2ead2014-05-27 19:55:11 +02002375 rl_bind_key ('?', (rl_command_func_t *) vtysh_rl_describe);
paul68980082003-03-25 05:07:42 +00002376 rl_completion_entry_function = vtysh_completion_entry_function;
Sébastien Luttringer66d2ead2014-05-27 19:55:11 +02002377 rl_attempted_completion_function = (rl_completion_func_t *)new_completion;
paul718e3742002-12-13 20:15:29 +00002378}
2379
2380char *
ajsb1aa1472005-01-28 21:11:46 +00002381vtysh_prompt (void)
paul718e3742002-12-13 20:15:29 +00002382{
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002383 static struct utsname names;
paul718e3742002-12-13 20:15:29 +00002384 static char buf[100];
2385 const char*hostname;
2386 extern struct host host;
2387
2388 hostname = host.name;
2389
2390 if (!hostname)
2391 {
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002392 if (!names.nodename[0])
2393 uname (&names);
paul718e3742002-12-13 20:15:29 +00002394 hostname = names.nodename;
2395 }
2396
2397 snprintf (buf, sizeof buf, cmd_prompt (vty->node), hostname);
2398
2399 return buf;
2400}
2401
2402void
ajsb1aa1472005-01-28 21:11:46 +00002403vtysh_init_vty (void)
paul718e3742002-12-13 20:15:29 +00002404{
2405 /* Make vty structure. */
2406 vty = vty_new ();
2407 vty->type = VTY_SHELL;
2408 vty->node = VIEW_NODE;
2409
2410 /* Initialize commands. */
2411 cmd_init (0);
2412
2413 /* Install nodes. */
2414 install_node (&bgp_node, NULL);
2415 install_node (&rip_node, NULL);
2416 install_node (&interface_node, NULL);
Olivier Dugeonac10d302016-04-19 18:33:42 +02002417 install_node (&link_params_node, NULL);
paul718e3742002-12-13 20:15:29 +00002418 install_node (&rmap_node, NULL);
2419 install_node (&zebra_node, NULL);
2420 install_node (&bgp_vpnv4_node, NULL);
Lou Berger13c378d2016-01-12 13:41:56 -05002421 install_node (&bgp_vpnv6_node, NULL);
Lou Bergera3fda882016-01-12 13:42:04 -05002422 install_node (&bgp_encap_node, NULL);
2423 install_node (&bgp_encapv6_node, NULL);
paul718e3742002-12-13 20:15:29 +00002424 install_node (&bgp_ipv4_node, NULL);
2425 install_node (&bgp_ipv4m_node, NULL);
2426/* #ifdef HAVE_IPV6 */
2427 install_node (&bgp_ipv6_node, NULL);
paul57b5b7e2005-08-22 22:44:29 +00002428 install_node (&bgp_ipv6m_node, NULL);
paul718e3742002-12-13 20:15:29 +00002429/* #endif */
2430 install_node (&ospf_node, NULL);
2431/* #ifdef HAVE_IPV6 */
2432 install_node (&ripng_node, NULL);
2433 install_node (&ospf6_node, NULL);
2434/* #endif */
David Lamparteree53c8b2015-05-23 05:45:59 +02002435 install_node (&babel_node, NULL);
paul718e3742002-12-13 20:15:29 +00002436 install_node (&keychain_node, NULL);
2437 install_node (&keychain_key_node, NULL);
hassoc25e4582003-12-23 10:39:08 +00002438 install_node (&isis_node, NULL);
hassoe7168df2004-10-03 20:11:32 +00002439 install_node (&vty_node, NULL);
paul718e3742002-12-13 20:15:29 +00002440
2441 vtysh_install_default (VIEW_NODE);
2442 vtysh_install_default (ENABLE_NODE);
2443 vtysh_install_default (CONFIG_NODE);
2444 vtysh_install_default (BGP_NODE);
2445 vtysh_install_default (RIP_NODE);
2446 vtysh_install_default (INTERFACE_NODE);
Olivier Dugeonac10d302016-04-19 18:33:42 +02002447 vtysh_install_default (LINK_PARAMS_NODE);
paul718e3742002-12-13 20:15:29 +00002448 vtysh_install_default (RMAP_NODE);
2449 vtysh_install_default (ZEBRA_NODE);
2450 vtysh_install_default (BGP_VPNV4_NODE);
Lou Berger13c378d2016-01-12 13:41:56 -05002451 vtysh_install_default (BGP_VPNV6_NODE);
Lou Bergera3fda882016-01-12 13:42:04 -05002452 vtysh_install_default (BGP_ENCAP_NODE);
2453 vtysh_install_default (BGP_ENCAPV6_NODE);
paul718e3742002-12-13 20:15:29 +00002454 vtysh_install_default (BGP_IPV4_NODE);
2455 vtysh_install_default (BGP_IPV4M_NODE);
2456 vtysh_install_default (BGP_IPV6_NODE);
paul57b5b7e2005-08-22 22:44:29 +00002457 vtysh_install_default (BGP_IPV6M_NODE);
paul718e3742002-12-13 20:15:29 +00002458 vtysh_install_default (OSPF_NODE);
2459 vtysh_install_default (RIPNG_NODE);
2460 vtysh_install_default (OSPF6_NODE);
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +01002461 vtysh_install_default (BABEL_NODE);
hassoc25e4582003-12-23 10:39:08 +00002462 vtysh_install_default (ISIS_NODE);
paul718e3742002-12-13 20:15:29 +00002463 vtysh_install_default (KEYCHAIN_NODE);
2464 vtysh_install_default (KEYCHAIN_KEY_NODE);
hassoe7168df2004-10-03 20:11:32 +00002465 vtysh_install_default (VTY_NODE);
paul718e3742002-12-13 20:15:29 +00002466
2467 install_element (VIEW_NODE, &vtysh_enable_cmd);
2468 install_element (ENABLE_NODE, &vtysh_config_terminal_cmd);
2469 install_element (ENABLE_NODE, &vtysh_disable_cmd);
2470
2471 /* "exit" command. */
2472 install_element (VIEW_NODE, &vtysh_exit_all_cmd);
2473 install_element (VIEW_NODE, &vtysh_quit_all_cmd);
2474 install_element (CONFIG_NODE, &vtysh_exit_all_cmd);
2475 /* install_element (CONFIG_NODE, &vtysh_quit_all_cmd); */
2476 install_element (ENABLE_NODE, &vtysh_exit_all_cmd);
2477 install_element (ENABLE_NODE, &vtysh_quit_all_cmd);
2478 install_element (RIP_NODE, &vtysh_exit_ripd_cmd);
2479 install_element (RIP_NODE, &vtysh_quit_ripd_cmd);
paul68980082003-03-25 05:07:42 +00002480 install_element (RIPNG_NODE, &vtysh_exit_ripngd_cmd);
2481 install_element (RIPNG_NODE, &vtysh_quit_ripngd_cmd);
paul718e3742002-12-13 20:15:29 +00002482 install_element (OSPF_NODE, &vtysh_exit_ospfd_cmd);
2483 install_element (OSPF_NODE, &vtysh_quit_ospfd_cmd);
paul68980082003-03-25 05:07:42 +00002484 install_element (OSPF6_NODE, &vtysh_exit_ospf6d_cmd);
2485 install_element (OSPF6_NODE, &vtysh_quit_ospf6d_cmd);
paul718e3742002-12-13 20:15:29 +00002486 install_element (BGP_NODE, &vtysh_exit_bgpd_cmd);
2487 install_element (BGP_NODE, &vtysh_quit_bgpd_cmd);
2488 install_element (BGP_VPNV4_NODE, &vtysh_exit_bgpd_cmd);
2489 install_element (BGP_VPNV4_NODE, &vtysh_quit_bgpd_cmd);
Lou Berger13c378d2016-01-12 13:41:56 -05002490 install_element (BGP_VPNV6_NODE, &vtysh_exit_bgpd_cmd);
2491 install_element (BGP_VPNV6_NODE, &vtysh_quit_bgpd_cmd);
Lou Bergera3fda882016-01-12 13:42:04 -05002492 install_element (BGP_ENCAP_NODE, &vtysh_exit_bgpd_cmd);
2493 install_element (BGP_ENCAP_NODE, &vtysh_quit_bgpd_cmd);
2494 install_element (BGP_ENCAPV6_NODE, &vtysh_exit_bgpd_cmd);
2495 install_element (BGP_ENCAPV6_NODE, &vtysh_quit_bgpd_cmd);
paul718e3742002-12-13 20:15:29 +00002496 install_element (BGP_IPV4_NODE, &vtysh_exit_bgpd_cmd);
2497 install_element (BGP_IPV4_NODE, &vtysh_quit_bgpd_cmd);
2498 install_element (BGP_IPV4M_NODE, &vtysh_exit_bgpd_cmd);
2499 install_element (BGP_IPV4M_NODE, &vtysh_quit_bgpd_cmd);
2500 install_element (BGP_IPV6_NODE, &vtysh_exit_bgpd_cmd);
2501 install_element (BGP_IPV6_NODE, &vtysh_quit_bgpd_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002502 install_element (BGP_IPV6M_NODE, &vtysh_exit_bgpd_cmd);
2503 install_element (BGP_IPV6M_NODE, &vtysh_quit_bgpd_cmd);
hassoc25e4582003-12-23 10:39:08 +00002504 install_element (ISIS_NODE, &vtysh_exit_isisd_cmd);
2505 install_element (ISIS_NODE, &vtysh_quit_isisd_cmd);
paul718e3742002-12-13 20:15:29 +00002506 install_element (KEYCHAIN_NODE, &vtysh_exit_ripd_cmd);
2507 install_element (KEYCHAIN_NODE, &vtysh_quit_ripd_cmd);
2508 install_element (KEYCHAIN_KEY_NODE, &vtysh_exit_ripd_cmd);
2509 install_element (KEYCHAIN_KEY_NODE, &vtysh_quit_ripd_cmd);
2510 install_element (RMAP_NODE, &vtysh_exit_rmap_cmd);
2511 install_element (RMAP_NODE, &vtysh_quit_rmap_cmd);
hassoe7168df2004-10-03 20:11:32 +00002512 install_element (VTY_NODE, &vtysh_exit_line_vty_cmd);
2513 install_element (VTY_NODE, &vtysh_quit_line_vty_cmd);
paul718e3742002-12-13 20:15:29 +00002514
2515 /* "end" command. */
2516 install_element (CONFIG_NODE, &vtysh_end_all_cmd);
2517 install_element (ENABLE_NODE, &vtysh_end_all_cmd);
2518 install_element (RIP_NODE, &vtysh_end_all_cmd);
2519 install_element (RIPNG_NODE, &vtysh_end_all_cmd);
2520 install_element (OSPF_NODE, &vtysh_end_all_cmd);
2521 install_element (OSPF6_NODE, &vtysh_end_all_cmd);
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +01002522 install_element (BABEL_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002523 install_element (BGP_NODE, &vtysh_end_all_cmd);
2524 install_element (BGP_IPV4_NODE, &vtysh_end_all_cmd);
2525 install_element (BGP_IPV4M_NODE, &vtysh_end_all_cmd);
2526 install_element (BGP_VPNV4_NODE, &vtysh_end_all_cmd);
Lou Berger13c378d2016-01-12 13:41:56 -05002527 install_element (BGP_VPNV6_NODE, &vtysh_end_all_cmd);
Lou Bergera3fda882016-01-12 13:42:04 -05002528 install_element (BGP_ENCAP_NODE, &vtysh_end_all_cmd);
2529 install_element (BGP_ENCAPV6_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002530 install_element (BGP_IPV6_NODE, &vtysh_end_all_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002531 install_element (BGP_IPV6M_NODE, &vtysh_end_all_cmd);
hassoc25e4582003-12-23 10:39:08 +00002532 install_element (ISIS_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002533 install_element (KEYCHAIN_NODE, &vtysh_end_all_cmd);
2534 install_element (KEYCHAIN_KEY_NODE, &vtysh_end_all_cmd);
2535 install_element (RMAP_NODE, &vtysh_end_all_cmd);
hassoe7168df2004-10-03 20:11:32 +00002536 install_element (VTY_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002537
paul338a9912003-03-01 15:44:10 +00002538 install_element (INTERFACE_NODE, &interface_desc_cmd);
paul464dc8d2003-03-28 02:25:45 +00002539 install_element (INTERFACE_NODE, &no_interface_desc_cmd);
paul718e3742002-12-13 20:15:29 +00002540 install_element (INTERFACE_NODE, &vtysh_end_all_cmd);
2541 install_element (INTERFACE_NODE, &vtysh_exit_interface_cmd);
Olivier Dugeonac10d302016-04-19 18:33:42 +02002542 install_element (LINK_PARAMS_NODE, &vtysh_end_all_cmd);
2543 install_element (LINK_PARAMS_NODE, &vtysh_exit_interface_cmd);
paul718e3742002-12-13 20:15:29 +00002544 install_element (INTERFACE_NODE, &vtysh_quit_interface_cmd);
2545 install_element (CONFIG_NODE, &router_rip_cmd);
2546#ifdef HAVE_IPV6
2547 install_element (CONFIG_NODE, &router_ripng_cmd);
2548#endif
2549 install_element (CONFIG_NODE, &router_ospf_cmd);
2550#ifdef HAVE_IPV6
2551 install_element (CONFIG_NODE, &router_ospf6_cmd);
2552#endif
hassoc25e4582003-12-23 10:39:08 +00002553 install_element (CONFIG_NODE, &router_isis_cmd);
paul718e3742002-12-13 20:15:29 +00002554 install_element (CONFIG_NODE, &router_bgp_cmd);
Paul Jakma10895fd2008-07-03 19:34:48 +00002555 install_element (CONFIG_NODE, &router_bgp_view_cmd);
paul718e3742002-12-13 20:15:29 +00002556 install_element (BGP_NODE, &address_family_vpnv4_cmd);
2557 install_element (BGP_NODE, &address_family_vpnv4_unicast_cmd);
Lou Berger13c378d2016-01-12 13:41:56 -05002558 install_element (BGP_NODE, &address_family_vpnv6_cmd);
2559 install_element (BGP_NODE, &address_family_vpnv6_unicast_cmd);
Lou Bergera3fda882016-01-12 13:42:04 -05002560 install_element (BGP_NODE, &address_family_encap_cmd);
2561 install_element (BGP_NODE, &address_family_encapv6_cmd);
paul718e3742002-12-13 20:15:29 +00002562 install_element (BGP_NODE, &address_family_ipv4_unicast_cmd);
2563 install_element (BGP_NODE, &address_family_ipv4_multicast_cmd);
2564#ifdef HAVE_IPV6
2565 install_element (BGP_NODE, &address_family_ipv6_cmd);
2566 install_element (BGP_NODE, &address_family_ipv6_unicast_cmd);
viveka4f40292015-11-09 20:21:46 -05002567 install_element (BGP_NODE, &address_family_ipv6_multicast_cmd);
paul718e3742002-12-13 20:15:29 +00002568#endif
2569 install_element (BGP_VPNV4_NODE, &exit_address_family_cmd);
Lou Berger13c378d2016-01-12 13:41:56 -05002570 install_element (BGP_VPNV6_NODE, &exit_address_family_cmd);
Lou Bergera3fda882016-01-12 13:42:04 -05002571 install_element (BGP_ENCAP_NODE, &exit_address_family_cmd);
2572 install_element (BGP_ENCAPV6_NODE, &exit_address_family_cmd);
paul718e3742002-12-13 20:15:29 +00002573 install_element (BGP_IPV4_NODE, &exit_address_family_cmd);
2574 install_element (BGP_IPV4M_NODE, &exit_address_family_cmd);
2575 install_element (BGP_IPV6_NODE, &exit_address_family_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002576 install_element (BGP_IPV6M_NODE, &exit_address_family_cmd);
paul718e3742002-12-13 20:15:29 +00002577 install_element (CONFIG_NODE, &key_chain_cmd);
2578 install_element (CONFIG_NODE, &route_map_cmd);
hassoe7168df2004-10-03 20:11:32 +00002579 install_element (CONFIG_NODE, &vtysh_line_vty_cmd);
paul718e3742002-12-13 20:15:29 +00002580 install_element (KEYCHAIN_NODE, &key_cmd);
2581 install_element (KEYCHAIN_NODE, &key_chain_cmd);
2582 install_element (KEYCHAIN_KEY_NODE, &key_chain_cmd);
2583 install_element (CONFIG_NODE, &vtysh_interface_cmd);
paul32d24632003-05-23 09:25:20 +00002584 install_element (CONFIG_NODE, &vtysh_no_interface_cmd);
Feng Lu471ea392015-05-22 11:40:00 +02002585 install_element (CONFIG_NODE, &vtysh_interface_vrf_cmd);
2586 install_element (CONFIG_NODE, &vtysh_no_interface_vrf_cmd);
Olivier Dugeonac10d302016-04-19 18:33:42 +02002587 install_element (INTERFACE_NODE, &vtysh_link_params_cmd);
paul718e3742002-12-13 20:15:29 +00002588 install_element (ENABLE_NODE, &vtysh_show_running_config_cmd);
Donald Sharp9fb73e82015-09-22 11:13:12 -04002589 install_element (ENABLE_NODE, &vtysh_show_running_config_daemon_cmd);
paul718e3742002-12-13 20:15:29 +00002590 install_element (ENABLE_NODE, &vtysh_copy_runningconfig_startupconfig_cmd);
2591 install_element (ENABLE_NODE, &vtysh_write_file_cmd);
hasso4a6e2252003-05-25 11:51:29 +00002592 install_element (ENABLE_NODE, &vtysh_write_cmd);
paul718e3742002-12-13 20:15:29 +00002593
hasso95e735b2004-08-26 13:08:30 +00002594 /* "write terminal" command. */
paul718e3742002-12-13 20:15:29 +00002595 install_element (ENABLE_NODE, &vtysh_write_terminal_cmd);
Donald Sharp9fb73e82015-09-22 11:13:12 -04002596 install_element (ENABLE_NODE, &vtysh_write_terminal_daemon_cmd);
Donald Sharp07440402016-02-25 07:39:45 -05002597
hassoe7168df2004-10-03 20:11:32 +00002598 install_element (CONFIG_NODE, &vtysh_integrated_config_cmd);
2599 install_element (CONFIG_NODE, &no_vtysh_integrated_config_cmd);
paul718e3742002-12-13 20:15:29 +00002600
hasso95e735b2004-08-26 13:08:30 +00002601 /* "write memory" command. */
paul718e3742002-12-13 20:15:29 +00002602 install_element (ENABLE_NODE, &vtysh_write_memory_cmd);
paul718e3742002-12-13 20:15:29 +00002603
hasso34553cc2004-08-27 13:56:39 +00002604 install_element (VIEW_NODE, &vtysh_terminal_length_cmd);
2605 install_element (ENABLE_NODE, &vtysh_terminal_length_cmd);
2606 install_element (VIEW_NODE, &vtysh_terminal_no_length_cmd);
2607 install_element (ENABLE_NODE, &vtysh_terminal_no_length_cmd);
hassof2799e62004-10-28 17:43:11 +00002608 install_element (VIEW_NODE, &vtysh_show_daemons_cmd);
2609 install_element (ENABLE_NODE, &vtysh_show_daemons_cmd);
hasso34553cc2004-08-27 13:56:39 +00002610
paul718e3742002-12-13 20:15:29 +00002611 install_element (VIEW_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002612 install_element (VIEW_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00002613 install_element (VIEW_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002614 install_element (VIEW_NODE, &vtysh_traceroute_ip_cmd);
2615#ifdef HAVE_IPV6
2616 install_element (VIEW_NODE, &vtysh_ping6_cmd);
2617 install_element (VIEW_NODE, &vtysh_traceroute6_cmd);
2618#endif
paul718e3742002-12-13 20:15:29 +00002619 install_element (VIEW_NODE, &vtysh_telnet_cmd);
2620 install_element (VIEW_NODE, &vtysh_telnet_port_cmd);
paul5087df52003-01-25 06:56:09 +00002621 install_element (VIEW_NODE, &vtysh_ssh_cmd);
paul718e3742002-12-13 20:15:29 +00002622 install_element (ENABLE_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002623 install_element (ENABLE_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00002624 install_element (ENABLE_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002625 install_element (ENABLE_NODE, &vtysh_traceroute_ip_cmd);
2626#ifdef HAVE_IPV6
2627 install_element (ENABLE_NODE, &vtysh_ping6_cmd);
2628 install_element (ENABLE_NODE, &vtysh_traceroute6_cmd);
2629#endif
paul718e3742002-12-13 20:15:29 +00002630 install_element (ENABLE_NODE, &vtysh_telnet_cmd);
2631 install_element (ENABLE_NODE, &vtysh_telnet_port_cmd);
hasso67e29ab2004-08-26 22:21:31 +00002632 install_element (ENABLE_NODE, &vtysh_ssh_cmd);
paul718e3742002-12-13 20:15:29 +00002633 install_element (ENABLE_NODE, &vtysh_start_shell_cmd);
2634 install_element (ENABLE_NODE, &vtysh_start_bash_cmd);
2635 install_element (ENABLE_NODE, &vtysh_start_zsh_cmd);
Paul Jakmadbf7d132006-05-23 22:10:01 +00002636
Paul Jakma362b4032006-05-28 07:54:45 +00002637 install_element (VIEW_NODE, &vtysh_show_memory_cmd);
2638 install_element (ENABLE_NODE, &vtysh_show_memory_cmd);
2639
Donald Sharp567a6382015-08-19 21:22:17 -04002640 install_element (VIEW_NODE, &vtysh_show_work_queues_cmd);
2641 install_element (ENABLE_NODE, &vtysh_show_work_queues_cmd);
Donald Sharp07440402016-02-25 07:39:45 -05002642 install_element (ENABLE_NODE, &vtysh_show_work_queues_daemon_cmd);
2643 install_element (VIEW_NODE, &vtysh_show_work_queues_daemon_cmd);
Donald Sharp567a6382015-08-19 21:22:17 -04002644
2645 install_element (VIEW_NODE, &vtysh_show_thread_cmd);
2646 install_element (ENABLE_NODE, &vtysh_show_thread_cmd);
2647
Paul Jakmadbf7d132006-05-23 22:10:01 +00002648 /* Logging */
2649 install_element (ENABLE_NODE, &vtysh_show_logging_cmd);
2650 install_element (VIEW_NODE, &vtysh_show_logging_cmd);
paul718e3742002-12-13 20:15:29 +00002651 install_element (CONFIG_NODE, &vtysh_log_stdout_cmd);
ajs274a4a42004-12-07 15:39:31 +00002652 install_element (CONFIG_NODE, &vtysh_log_stdout_level_cmd);
paul718e3742002-12-13 20:15:29 +00002653 install_element (CONFIG_NODE, &no_vtysh_log_stdout_cmd);
2654 install_element (CONFIG_NODE, &vtysh_log_file_cmd);
ajs274a4a42004-12-07 15:39:31 +00002655 install_element (CONFIG_NODE, &vtysh_log_file_level_cmd);
paul718e3742002-12-13 20:15:29 +00002656 install_element (CONFIG_NODE, &no_vtysh_log_file_cmd);
ajs274a4a42004-12-07 15:39:31 +00002657 install_element (CONFIG_NODE, &no_vtysh_log_file_level_cmd);
2658 install_element (CONFIG_NODE, &vtysh_log_monitor_cmd);
2659 install_element (CONFIG_NODE, &vtysh_log_monitor_level_cmd);
2660 install_element (CONFIG_NODE, &no_vtysh_log_monitor_cmd);
paul718e3742002-12-13 20:15:29 +00002661 install_element (CONFIG_NODE, &vtysh_log_syslog_cmd);
ajs274a4a42004-12-07 15:39:31 +00002662 install_element (CONFIG_NODE, &vtysh_log_syslog_level_cmd);
paul718e3742002-12-13 20:15:29 +00002663 install_element (CONFIG_NODE, &no_vtysh_log_syslog_cmd);
2664 install_element (CONFIG_NODE, &vtysh_log_trap_cmd);
2665 install_element (CONFIG_NODE, &no_vtysh_log_trap_cmd);
ajs274a4a42004-12-07 15:39:31 +00002666 install_element (CONFIG_NODE, &vtysh_log_facility_cmd);
2667 install_element (CONFIG_NODE, &no_vtysh_log_facility_cmd);
paul718e3742002-12-13 20:15:29 +00002668 install_element (CONFIG_NODE, &vtysh_log_record_priority_cmd);
2669 install_element (CONFIG_NODE, &no_vtysh_log_record_priority_cmd);
Andrew J. Schorrc749b722007-04-29 03:53:31 +00002670 install_element (CONFIG_NODE, &vtysh_log_timestamp_precision_cmd);
2671 install_element (CONFIG_NODE, &no_vtysh_log_timestamp_precision_cmd);
hassoe7168df2004-10-03 20:11:32 +00002672
2673 install_element (CONFIG_NODE, &vtysh_service_password_encrypt_cmd);
2674 install_element (CONFIG_NODE, &no_vtysh_service_password_encrypt_cmd);
2675
2676 install_element (CONFIG_NODE, &vtysh_password_cmd);
2677 install_element (CONFIG_NODE, &vtysh_password_text_cmd);
2678 install_element (CONFIG_NODE, &vtysh_enable_password_cmd);
2679 install_element (CONFIG_NODE, &vtysh_enable_password_text_cmd);
2680 install_element (CONFIG_NODE, &no_vtysh_enable_password_cmd);
2681
paul718e3742002-12-13 20:15:29 +00002682}