blob: 783c383c8d5b9eb87feb9fb1d14be94597a8c200 [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
paul718e3742002-12-13 20:15:29 +000088/* Following filled with debug code to trace a problematic condition
hasso95e735b2004-08-26 13:08:30 +000089 * under load - it SHOULD handle it. */
paul718e3742002-12-13 20:15:29 +000090#define ERR_WHERE_STRING "vtysh(): vtysh_client_config(): "
ajs274a4a42004-12-07 15:39:31 +000091static int
paul718e3742002-12-13 20:15:29 +000092vtysh_client_config (struct vtysh_client *vclient, char *line)
93{
94 int ret;
95 char *buf;
96 size_t bufsz;
97 char *pbuf;
98 size_t left;
99 char *eoln;
100 int nbytes;
101 int i;
102 int readln;
103
104 if (vclient->fd < 0)
105 return CMD_SUCCESS;
106
107 ret = write (vclient->fd, line, strlen (line) + 1);
108 if (ret <= 0)
109 {
110 vclient_close (vclient);
111 return CMD_SUCCESS;
112 }
113
hasso95e735b2004-08-26 13:08:30 +0000114 /* Allow enough room for buffer to read more than a few pages from socket. */
paule3d29b52003-01-23 18:05:42 +0000115 bufsz = 5 * getpagesize() + 1;
paul718e3742002-12-13 20:15:29 +0000116 buf = XMALLOC(MTYPE_TMP, bufsz);
117 memset(buf, 0, bufsz);
118 pbuf = buf;
119
120 while (1)
121 {
122 if (pbuf >= ((buf + bufsz) -1))
123 {
124 fprintf (stderr, ERR_WHERE_STRING \
125 "warning - pbuf beyond buffer end.\n");
126 return CMD_WARNING;
127 }
128
129 readln = (buf + bufsz) - pbuf - 1;
130 nbytes = read (vclient->fd, pbuf, readln);
131
132 if (nbytes <= 0)
133 {
134
135 if (errno == EINTR)
136 continue;
137
138 fprintf(stderr, ERR_WHERE_STRING "(%u)", errno);
139 perror("");
140
141 if (errno == EAGAIN || errno == EIO)
142 continue;
143
144 vclient_close (vclient);
145 XFREE(MTYPE_TMP, buf);
146 return CMD_SUCCESS;
147 }
148
149 pbuf[nbytes] = '\0';
150
151 if (nbytes >= 4)
152 {
153 i = nbytes - 4;
154 if (pbuf[i] == '\0' && pbuf[i + 1] == '\0' && pbuf[i + 2] == '\0')
155 {
156 ret = pbuf[i + 3];
157 break;
158 }
159 }
160 pbuf += nbytes;
161
162 /* See if a line exists in buffer, if so parse and consume it, and
hasso95e735b2004-08-26 13:08:30 +0000163 * reset read position. */
paul718e3742002-12-13 20:15:29 +0000164 if ((eoln = strrchr(buf, '\n')) == NULL)
165 continue;
166
167 if (eoln >= ((buf + bufsz) - 1))
168 {
169 fprintf (stderr, ERR_WHERE_STRING \
170 "warning - eoln beyond buffer end.\n");
171 }
172 vtysh_config_parse(buf);
173
174 eoln++;
175 left = (size_t)(buf + bufsz - eoln);
176 memmove(buf, eoln, left);
177 buf[bufsz-1] = '\0';
178 pbuf = buf + strlen(buf);
179 }
180
hasso95e735b2004-08-26 13:08:30 +0000181 /* Parse anything left in the buffer. */
hassoe7168df2004-10-03 20:11:32 +0000182
paul718e3742002-12-13 20:15:29 +0000183 vtysh_config_parse (buf);
184
185 XFREE(MTYPE_TMP, buf);
186 return ret;
187}
188
ajs274a4a42004-12-07 15:39:31 +0000189static int
hassodda09522004-10-07 21:40:25 +0000190vtysh_client_execute (struct vtysh_client *vclient, const char *line, FILE *fp)
paul718e3742002-12-13 20:15:29 +0000191{
192 int ret;
193 char buf[1001];
194 int nbytes;
paul2852de12004-09-17 06:52:16 +0000195 int i;
196 int numnulls = 0;
paul718e3742002-12-13 20:15:29 +0000197
198 if (vclient->fd < 0)
199 return CMD_SUCCESS;
200
201 ret = write (vclient->fd, line, strlen (line) + 1);
202 if (ret <= 0)
203 {
204 vclient_close (vclient);
205 return CMD_SUCCESS;
206 }
207
208 while (1)
209 {
210 nbytes = read (vclient->fd, buf, sizeof(buf)-1);
211
212 if (nbytes <= 0 && errno != EINTR)
213 {
214 vclient_close (vclient);
215 return CMD_SUCCESS;
216 }
217
218 if (nbytes > 0)
219 {
ajs85fb1e62004-11-11 14:03:39 +0000220 if ((numnulls == 3) && (nbytes == 1))
221 return buf[0];
222
paul718e3742002-12-13 20:15:29 +0000223 buf[nbytes] = '\0';
ajs85fb1e62004-11-11 14:03:39 +0000224 fputs (buf, fp);
paul718e3742002-12-13 20:15:29 +0000225 fflush (fp);
paul2852de12004-09-17 06:52:16 +0000226
paul0921d482004-10-11 18:21:55 +0000227 /* check for trailling \0\0\0<ret code>,
228 * even if split across reads
229 * (see lib/vty.c::vtysh_read)
230 */
paul2852de12004-09-17 06:52:16 +0000231 if (nbytes >= 4)
232 {
233 i = nbytes-4;
234 numnulls = 0;
235 }
236 else
237 i = 0;
238
paul0921d482004-10-11 18:21:55 +0000239 while (i < nbytes && numnulls < 3)
paul2852de12004-09-17 06:52:16 +0000240 {
241 if (buf[i++] == '\0')
242 numnulls++;
243 else
ajs85fb1e62004-11-11 14:03:39 +0000244 numnulls = 0;
paul2852de12004-09-17 06:52:16 +0000245 }
paul718e3742002-12-13 20:15:29 +0000246
ajs85fb1e62004-11-11 14:03:39 +0000247 /* got 3 or more trailing NULs? */
248 if ((numnulls >= 3) && (i < nbytes))
paul0921d482004-10-11 18:21:55 +0000249 return (buf[nbytes-1]);
paul718e3742002-12-13 20:15:29 +0000250 }
251 }
paul718e3742002-12-13 20:15:29 +0000252}
253
David Lampartera9eb9062015-03-04 07:07:01 +0100254static void
ajsb1aa1472005-01-28 21:11:46 +0000255vtysh_exit_ripd_only (void)
paul718e3742002-12-13 20:15:29 +0000256{
ajsb1aa1472005-01-28 21:11:46 +0000257 if (ripd_client)
258 vtysh_client_execute (ripd_client, "exit", stdout);
paul718e3742002-12-13 20:15:29 +0000259}
260
261
262void
ajsb1aa1472005-01-28 21:11:46 +0000263vtysh_pager_init (void)
paul718e3742002-12-13 20:15:29 +0000264{
hasso5a9c53d2004-08-27 14:23:28 +0000265 char *pager_defined;
266
267 pager_defined = getenv ("VTYSH_PAGER");
268
269 if (pager_defined)
270 vtysh_pager_name = strdup (pager_defined);
271 else
hasso34553cc2004-08-27 13:56:39 +0000272 vtysh_pager_name = strdup ("more");
paul718e3742002-12-13 20:15:29 +0000273}
274
275/* Command execution over the vty interface. */
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700276static int
hassodda09522004-10-07 21:40:25 +0000277vtysh_execute_func (const char *line, int pager)
paul718e3742002-12-13 20:15:29 +0000278{
Stephen Hemminger2c4d48b2008-07-28 15:04:56 -0700279 int ret, cmd_stat;
ajsb1aa1472005-01-28 21:11:46 +0000280 u_int i;
paul718e3742002-12-13 20:15:29 +0000281 vector vline;
282 struct cmd_element *cmd;
283 FILE *fp = NULL;
hasso13bfca72005-01-23 21:42:25 +0000284 int closepager = 0;
285 int tried = 0;
286 int saved_ret, saved_node;
paul718e3742002-12-13 20:15:29 +0000287
hasso95e735b2004-08-26 13:08:30 +0000288 /* Split readline string up into the vector. */
paul718e3742002-12-13 20:15:29 +0000289 vline = cmd_make_strvec (line);
290
291 if (vline == NULL)
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700292 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000293
hasso13bfca72005-01-23 21:42:25 +0000294 saved_ret = ret = cmd_execute_command (vline, vty, &cmd, 1);
295 saved_node = vty->node;
296
297 /* If command doesn't succeeded in current node, try to walk up in node tree.
298 * Changing vty->node is enough to try it just out without actual walkup in
299 * the vtysh. */
300 while (ret != CMD_SUCCESS && ret != CMD_SUCCESS_DAEMON && ret != CMD_WARNING
301 && vty->node > CONFIG_NODE)
302 {
303 vty->node = node_parent(vty->node);
304 ret = cmd_execute_command (vline, vty, &cmd, 1);
305 tried++;
306 }
307
308 vty->node = saved_node;
309
310 /* If command succeeded in any other node than current (tried > 0) we have
311 * to move into node in the vtysh where it succeeded. */
312 if (ret == CMD_SUCCESS || ret == CMD_SUCCESS_DAEMON || ret == CMD_WARNING)
313 {
314 if ((saved_node == BGP_VPNV4_NODE || saved_node == BGP_IPV4_NODE
paul57b5b7e2005-08-22 22:44:29 +0000315 || saved_node == BGP_IPV6_NODE || saved_node == BGP_IPV4M_NODE
316 || saved_node == BGP_IPV6M_NODE)
hasso13bfca72005-01-23 21:42:25 +0000317 && (tried == 1))
318 {
319 vtysh_execute("exit-address-family");
320 }
321 else if ((saved_node == KEYCHAIN_KEY_NODE) && (tried == 1))
322 {
323 vtysh_execute("exit");
324 }
325 else if (tried)
326 {
327 vtysh_execute ("end");
328 vtysh_execute ("configure terminal");
329 }
330 }
331 /* If command didn't succeed in any node, continue with return value from
332 * first try. */
333 else if (tried)
334 {
335 ret = saved_ret;
336 }
paul718e3742002-12-13 20:15:29 +0000337
338 cmd_free_strvec (vline);
339
Stephen Hemminger2c4d48b2008-07-28 15:04:56 -0700340 cmd_stat = ret;
paul718e3742002-12-13 20:15:29 +0000341 switch (ret)
342 {
343 case CMD_WARNING:
344 if (vty->type == VTY_FILE)
paul4fc01e62002-12-13 20:49:00 +0000345 fprintf (stdout,"Warning...\n");
paul718e3742002-12-13 20:15:29 +0000346 break;
347 case CMD_ERR_AMBIGUOUS:
paul4fc01e62002-12-13 20:49:00 +0000348 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000349 break;
350 case CMD_ERR_NO_MATCH:
paul4fc01e62002-12-13 20:49:00 +0000351 fprintf (stdout,"%% Unknown command.\n");
paul718e3742002-12-13 20:15:29 +0000352 break;
353 case CMD_ERR_INCOMPLETE:
paul4fc01e62002-12-13 20:49:00 +0000354 fprintf (stdout,"%% Command incomplete.\n");
paul718e3742002-12-13 20:15:29 +0000355 break;
356 case CMD_SUCCESS_DAEMON:
357 {
hasso97b7db22004-10-20 19:07:48 +0000358 /* FIXME: Don't open pager for exit commands. popen() causes problems
359 * if exited from vtysh at all. This hack shouldn't cause any problem
360 * but is really ugly. */
361 if (pager && vtysh_pager_name && (strncmp(line, "exit", 4) != 0))
paul718e3742002-12-13 20:15:29 +0000362 {
paul4fc01e62002-12-13 20:49:00 +0000363 fp = popen (vtysh_pager_name, "w");
paul718e3742002-12-13 20:15:29 +0000364 if (fp == NULL)
365 {
paula805cc22003-05-01 14:29:48 +0000366 perror ("popen failed for pager");
367 fp = stdout;
paul718e3742002-12-13 20:15:29 +0000368 }
paula805cc22003-05-01 14:29:48 +0000369 else
370 closepager=1;
paul718e3742002-12-13 20:15:29 +0000371 }
372 else
373 fp = stdout;
374
375 if (! strcmp(cmd->string,"configure terminal"))
376 {
Balaji.G837d16c2012-09-26 14:09:10 +0530377 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +0000378 {
379 cmd_stat = vtysh_client_execute(&vtysh_client[i], line, fp);
380 if (cmd_stat == CMD_WARNING)
381 break;
382 }
383
paul718e3742002-12-13 20:15:29 +0000384 if (cmd_stat)
385 {
hassob094d262004-08-25 12:22:00 +0000386 line = "end";
387 vline = cmd_make_strvec (line);
paul718e3742002-12-13 20:15:29 +0000388
hassob094d262004-08-25 12:22:00 +0000389 if (vline == NULL)
paul718e3742002-12-13 20:15:29 +0000390 {
paula805cc22003-05-01 14:29:48 +0000391 if (pager && vtysh_pager_name && fp && closepager)
paul718e3742002-12-13 20:15:29 +0000392 {
393 if (pclose (fp) == -1)
394 {
paula805cc22003-05-01 14:29:48 +0000395 perror ("pclose failed for pager");
paul718e3742002-12-13 20:15:29 +0000396 }
397 fp = NULL;
398 }
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700399 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000400 }
401
hasso87d683b2005-01-16 23:31:54 +0000402 ret = cmd_execute_command (vline, vty, &cmd, 1);
hassob094d262004-08-25 12:22:00 +0000403 cmd_free_strvec (vline);
404 if (ret != CMD_SUCCESS_DAEMON)
405 break;
paul718e3742002-12-13 20:15:29 +0000406 }
407 else
408 if (cmd->func)
409 {
410 (*cmd->func) (cmd, vty, 0, NULL);
411 break;
hassob094d262004-08-25 12:22:00 +0000412 }
paul718e3742002-12-13 20:15:29 +0000413 }
414
ajsb1aa1472005-01-28 21:11:46 +0000415 cmd_stat = CMD_SUCCESS;
Balaji.G837d16c2012-09-26 14:09:10 +0530416 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +0000417 {
418 if (cmd->daemon & vtysh_client[i].flag)
419 {
420 cmd_stat = vtysh_client_execute(&vtysh_client[i], line, fp);
421 if (cmd_stat != CMD_SUCCESS)
422 break;
423 }
424 }
425 if (cmd_stat != CMD_SUCCESS)
426 break;
427
paul718e3742002-12-13 20:15:29 +0000428 if (cmd->func)
429 (*cmd->func) (cmd, vty, 0, NULL);
430 }
431 }
paula805cc22003-05-01 14:29:48 +0000432 if (pager && vtysh_pager_name && fp && closepager)
paul718e3742002-12-13 20:15:29 +0000433 {
434 if (pclose (fp) == -1)
435 {
paula805cc22003-05-01 14:29:48 +0000436 perror ("pclose failed for pager");
paul718e3742002-12-13 20:15:29 +0000437 }
438 fp = NULL;
439 }
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700440 return cmd_stat;
paul718e3742002-12-13 20:15:29 +0000441}
442
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700443int
hassodda09522004-10-07 21:40:25 +0000444vtysh_execute_no_pager (const char *line)
paul718e3742002-12-13 20:15:29 +0000445{
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700446 return vtysh_execute_func (line, 0);
paul718e3742002-12-13 20:15:29 +0000447}
448
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700449int
hassodda09522004-10-07 21:40:25 +0000450vtysh_execute (const char *line)
paul718e3742002-12-13 20:15:29 +0000451{
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700452 return vtysh_execute_func (line, 1);
paul718e3742002-12-13 20:15:29 +0000453}
454
455/* Configration make from file. */
456int
457vtysh_config_from_file (struct vty *vty, FILE *fp)
458{
459 int ret;
460 vector vline;
461 struct cmd_element *cmd;
462
463 while (fgets (vty->buf, VTY_BUFSIZ, fp))
464 {
465 if (vty->buf[0] == '!' || vty->buf[1] == '#')
466 continue;
467
468 vline = cmd_make_strvec (vty->buf);
469
hasso95e735b2004-08-26 13:08:30 +0000470 /* In case of comment line. */
paul718e3742002-12-13 20:15:29 +0000471 if (vline == NULL)
472 continue;
473
hasso95e735b2004-08-26 13:08:30 +0000474 /* Execute configuration command : this is strict match. */
paul718e3742002-12-13 20:15:29 +0000475 ret = cmd_execute_command_strict (vline, vty, &cmd);
476
hasso95e735b2004-08-26 13:08:30 +0000477 /* Try again with setting node to CONFIG_NODE. */
paul718e3742002-12-13 20:15:29 +0000478 if (ret != CMD_SUCCESS
479 && ret != CMD_SUCCESS_DAEMON
480 && ret != CMD_WARNING)
481 {
482 if (vty->node == KEYCHAIN_KEY_NODE)
483 {
484 vty->node = KEYCHAIN_NODE;
485 vtysh_exit_ripd_only ();
486 ret = cmd_execute_command_strict (vline, vty, &cmd);
487
488 if (ret != CMD_SUCCESS
489 && ret != CMD_SUCCESS_DAEMON
490 && ret != CMD_WARNING)
491 {
492 vtysh_exit_ripd_only ();
493 vty->node = CONFIG_NODE;
494 ret = cmd_execute_command_strict (vline, vty, &cmd);
495 }
496 }
497 else
498 {
499 vtysh_execute ("end");
500 vtysh_execute ("configure terminal");
501 vty->node = CONFIG_NODE;
502 ret = cmd_execute_command_strict (vline, vty, &cmd);
503 }
504 }
505
506 cmd_free_strvec (vline);
507
508 switch (ret)
509 {
510 case CMD_WARNING:
511 if (vty->type == VTY_FILE)
paul4fc01e62002-12-13 20:49:00 +0000512 fprintf (stdout,"Warning...\n");
paul718e3742002-12-13 20:15:29 +0000513 break;
514 case CMD_ERR_AMBIGUOUS:
paul4fc01e62002-12-13 20:49:00 +0000515 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000516 break;
517 case CMD_ERR_NO_MATCH:
paul4fc01e62002-12-13 20:49:00 +0000518 fprintf (stdout,"%% Unknown command: %s", vty->buf);
paul718e3742002-12-13 20:15:29 +0000519 break;
520 case CMD_ERR_INCOMPLETE:
paul4fc01e62002-12-13 20:49:00 +0000521 fprintf (stdout,"%% Command incomplete.\n");
paul718e3742002-12-13 20:15:29 +0000522 break;
523 case CMD_SUCCESS_DAEMON:
524 {
ajsb1aa1472005-01-28 21:11:46 +0000525 u_int i;
526 int cmd_stat = CMD_SUCCESS;
527
Balaji.G837d16c2012-09-26 14:09:10 +0530528 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +0000529 {
paul44316fe2006-01-11 01:38:25 +0000530 if (cmd->daemon & vtysh_client[i].flag)
ajsb1aa1472005-01-28 21:11:46 +0000531 {
532 cmd_stat = vtysh_client_execute (&vtysh_client[i],
533 vty->buf, stdout);
534 if (cmd_stat != CMD_SUCCESS)
535 break;
536 }
537 }
538 if (cmd_stat != CMD_SUCCESS)
539 break;
540
paul718e3742002-12-13 20:15:29 +0000541 if (cmd->func)
542 (*cmd->func) (cmd, vty, 0, NULL);
543 }
544 }
545 }
546 return CMD_SUCCESS;
547}
548
549/* We don't care about the point of the cursor when '?' is typed. */
David Lampartera9eb9062015-03-04 07:07:01 +0100550static int
ajsb1aa1472005-01-28 21:11:46 +0000551vtysh_rl_describe (void)
paul718e3742002-12-13 20:15:29 +0000552{
553 int ret;
hassodda09522004-10-07 21:40:25 +0000554 unsigned int i;
paul718e3742002-12-13 20:15:29 +0000555 vector vline;
556 vector describe;
557 int width;
Christian Frankecd40b322013-09-30 12:27:51 +0000558 struct cmd_token *token;
paul718e3742002-12-13 20:15:29 +0000559
560 vline = cmd_make_strvec (rl_line_buffer);
561
562 /* In case of '> ?'. */
563 if (vline == NULL)
564 {
565 vline = vector_init (1);
David Lampartera91a3ba2015-03-03 09:06:51 +0100566 vector_set (vline, NULL);
paul718e3742002-12-13 20:15:29 +0000567 }
568 else
569 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
David Lampartera91a3ba2015-03-03 09:06:51 +0100570 vector_set (vline, NULL);
paul718e3742002-12-13 20:15:29 +0000571
572 describe = cmd_describe_command (vline, vty, &ret);
573
paul4fc01e62002-12-13 20:49:00 +0000574 fprintf (stdout,"\n");
paul718e3742002-12-13 20:15:29 +0000575
576 /* Ambiguous and no match error. */
577 switch (ret)
578 {
579 case CMD_ERR_AMBIGUOUS:
580 cmd_free_strvec (vline);
paul4fc01e62002-12-13 20:49:00 +0000581 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000582 rl_on_new_line ();
583 return 0;
584 break;
585 case CMD_ERR_NO_MATCH:
586 cmd_free_strvec (vline);
paul4fc01e62002-12-13 20:49:00 +0000587 fprintf (stdout,"%% There is no matched command.\n");
paul718e3742002-12-13 20:15:29 +0000588 rl_on_new_line ();
589 return 0;
590 break;
591 }
592
593 /* Get width of command string. */
594 width = 0;
paul55468c82005-03-14 20:19:01 +0000595 for (i = 0; i < vector_active (describe); i++)
Christian Frankecd40b322013-09-30 12:27:51 +0000596 if ((token = vector_slot (describe, i)) != NULL)
paul718e3742002-12-13 20:15:29 +0000597 {
598 int len;
599
Christian Frankecd40b322013-09-30 12:27:51 +0000600 if (token->cmd[0] == '\0')
paul718e3742002-12-13 20:15:29 +0000601 continue;
602
Christian Frankecd40b322013-09-30 12:27:51 +0000603 len = strlen (token->cmd);
604 if (token->cmd[0] == '.')
paul718e3742002-12-13 20:15:29 +0000605 len--;
606
607 if (width < len)
608 width = len;
609 }
610
paul55468c82005-03-14 20:19:01 +0000611 for (i = 0; i < vector_active (describe); i++)
Christian Frankecd40b322013-09-30 12:27:51 +0000612 if ((token = vector_slot (describe, i)) != NULL)
paul718e3742002-12-13 20:15:29 +0000613 {
Christian Frankecd40b322013-09-30 12:27:51 +0000614 if (token->cmd[0] == '\0')
paul718e3742002-12-13 20:15:29 +0000615 continue;
616
Christian Frankecd40b322013-09-30 12:27:51 +0000617 if (! token->desc)
paul4fc01e62002-12-13 20:49:00 +0000618 fprintf (stdout," %-s\n",
Christian Frankecd40b322013-09-30 12:27:51 +0000619 token->cmd[0] == '.' ? token->cmd + 1 : token->cmd);
paul718e3742002-12-13 20:15:29 +0000620 else
paul4fc01e62002-12-13 20:49:00 +0000621 fprintf (stdout," %-*s %s\n",
hassob094d262004-08-25 12:22:00 +0000622 width,
Christian Frankecd40b322013-09-30 12:27:51 +0000623 token->cmd[0] == '.' ? token->cmd + 1 : token->cmd,
624 token->desc);
paul718e3742002-12-13 20:15:29 +0000625 }
626
627 cmd_free_strvec (vline);
628 vector_free (describe);
629
630 rl_on_new_line();
631
632 return 0;
633}
634
hasso95e735b2004-08-26 13:08:30 +0000635/* Result of cmd_complete_command() call will be stored here
636 * and used in new_completion() in order to put the space in
637 * correct places only. */
paul718e3742002-12-13 20:15:29 +0000638int complete_status;
639
ajs274a4a42004-12-07 15:39:31 +0000640static char *
pauldfc0d9b2003-04-18 23:55:29 +0000641command_generator (const char *text, int state)
paul718e3742002-12-13 20:15:29 +0000642{
643 vector vline;
644 static char **matched = NULL;
645 static int index = 0;
646
647 /* First call. */
648 if (! state)
649 {
650 index = 0;
651
652 if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
653 return NULL;
654
655 vline = cmd_make_strvec (rl_line_buffer);
656 if (vline == NULL)
657 return NULL;
658
659 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
David Lampartera91a3ba2015-03-03 09:06:51 +0100660 vector_set (vline, NULL);
paul718e3742002-12-13 20:15:29 +0000661
662 matched = cmd_complete_command (vline, vty, &complete_status);
663 }
664
665 if (matched && matched[index])
666 return matched[index++];
667
668 return NULL;
669}
670
ajs274a4a42004-12-07 15:39:31 +0000671static char **
paul718e3742002-12-13 20:15:29 +0000672new_completion (char *text, int start, int end)
673{
674 char **matches;
675
pauldfc0d9b2003-04-18 23:55:29 +0000676 matches = rl_completion_matches (text, command_generator);
paul718e3742002-12-13 20:15:29 +0000677
678 if (matches)
679 {
680 rl_point = rl_end;
Christian Franke67e7a212013-03-04 09:23:30 +0000681 if (complete_status != CMD_COMPLETE_FULL_MATCH)
682 /* only append a space on full match */
683 rl_completion_append_character = '\0';
paul718e3742002-12-13 20:15:29 +0000684 }
685
686 return matches;
687}
688
ajs274a4a42004-12-07 15:39:31 +0000689#if 0
690/* This function is not actually being used. */
691static char **
paul718e3742002-12-13 20:15:29 +0000692vtysh_completion (char *text, int start, int end)
693{
694 int ret;
695 vector vline;
696 char **matched = NULL;
697
698 if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
699 return NULL;
700
701 vline = cmd_make_strvec (rl_line_buffer);
702 if (vline == NULL)
703 return NULL;
704
705 /* In case of 'help \t'. */
706 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
707 vector_set (vline, '\0');
708
709 matched = cmd_complete_command (vline, vty, &ret);
710
711 cmd_free_strvec (vline);
712
713 return (char **) matched;
714}
ajs274a4a42004-12-07 15:39:31 +0000715#endif
paul718e3742002-12-13 20:15:29 +0000716
hasso95e735b2004-08-26 13:08:30 +0000717/* Vty node structures. */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800718static struct cmd_node bgp_node =
paul718e3742002-12-13 20:15:29 +0000719{
720 BGP_NODE,
721 "%s(config-router)# ",
722};
723
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800724static struct cmd_node rip_node =
paul718e3742002-12-13 20:15:29 +0000725{
726 RIP_NODE,
727 "%s(config-router)# ",
728};
729
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800730static struct cmd_node isis_node =
hassoc25e4582003-12-23 10:39:08 +0000731{
732 ISIS_NODE,
733 "%s(config-router)# ",
hassoc25e4582003-12-23 10:39:08 +0000734};
735
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800736static struct cmd_node interface_node =
paul718e3742002-12-13 20:15:29 +0000737{
738 INTERFACE_NODE,
739 "%s(config-if)# ",
740};
741
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800742static struct cmd_node rmap_node =
hasso95e735b2004-08-26 13:08:30 +0000743{
744 RMAP_NODE,
745 "%s(config-route-map)# "
746};
747
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800748static struct cmd_node zebra_node =
hasso95e735b2004-08-26 13:08:30 +0000749{
750 ZEBRA_NODE,
751 "%s(config-router)# "
752};
753
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800754static struct cmd_node bgp_vpnv4_node =
hasso95e735b2004-08-26 13:08:30 +0000755{
756 BGP_VPNV4_NODE,
757 "%s(config-router-af)# "
758};
759
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800760static struct cmd_node bgp_ipv4_node =
hasso95e735b2004-08-26 13:08:30 +0000761{
762 BGP_IPV4_NODE,
763 "%s(config-router-af)# "
764};
765
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800766static struct cmd_node bgp_ipv4m_node =
hasso95e735b2004-08-26 13:08:30 +0000767{
768 BGP_IPV4M_NODE,
769 "%s(config-router-af)# "
770};
771
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800772static struct cmd_node bgp_ipv6_node =
hasso95e735b2004-08-26 13:08:30 +0000773{
774 BGP_IPV6_NODE,
775 "%s(config-router-af)# "
776};
777
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800778static struct cmd_node bgp_ipv6m_node =
paul57b5b7e2005-08-22 22:44:29 +0000779{
780 BGP_IPV6M_NODE,
781 "%s(config-router-af)# "
782};
783
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800784static struct cmd_node ospf_node =
hasso95e735b2004-08-26 13:08:30 +0000785{
786 OSPF_NODE,
787 "%s(config-router)# "
788};
789
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800790static struct cmd_node ripng_node =
hasso95e735b2004-08-26 13:08:30 +0000791{
792 RIPNG_NODE,
793 "%s(config-router)# "
794};
795
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800796static struct cmd_node ospf6_node =
hasso95e735b2004-08-26 13:08:30 +0000797{
798 OSPF6_NODE,
799 "%s(config-ospf6)# "
800};
801
David Lamparteree53c8b2015-05-23 05:45:59 +0200802static struct cmd_node babel_node =
803{
804 BABEL_NODE,
805 "%s(config-babel)# "
806};
807
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800808static struct cmd_node keychain_node =
hasso95e735b2004-08-26 13:08:30 +0000809{
810 KEYCHAIN_NODE,
811 "%s(config-keychain)# "
812};
813
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800814static struct cmd_node keychain_key_node =
hasso95e735b2004-08-26 13:08:30 +0000815{
816 KEYCHAIN_KEY_NODE,
817 "%s(config-keychain-key)# "
818};
819
hassoe7168df2004-10-03 20:11:32 +0000820/* Defined in lib/vty.c */
821extern struct cmd_node vty_node;
822
hasso95e735b2004-08-26 13:08:30 +0000823/* When '^Z' is received from vty, move down to the enable mode. */
David Lampartera9eb9062015-03-04 07:07:01 +0100824static int
ajsb1aa1472005-01-28 21:11:46 +0000825vtysh_end (void)
hasso95e735b2004-08-26 13:08:30 +0000826{
827 switch (vty->node)
828 {
829 case VIEW_NODE:
830 case ENABLE_NODE:
831 /* Nothing to do. */
832 break;
833 default:
834 vty->node = ENABLE_NODE;
835 break;
836 }
837 return CMD_SUCCESS;
838}
839
840DEFUNSH (VTYSH_ALL,
841 vtysh_end_all,
842 vtysh_end_all_cmd,
843 "end",
hassoe7168df2004-10-03 20:11:32 +0000844 "End current mode and change to enable mode\n")
hasso95e735b2004-08-26 13:08:30 +0000845{
hasso42895462004-09-26 16:25:07 +0000846 return vtysh_end ();
hasso95e735b2004-08-26 13:08:30 +0000847}
848
paul718e3742002-12-13 20:15:29 +0000849DEFUNSH (VTYSH_BGPD,
850 router_bgp,
851 router_bgp_cmd,
Paul Jakma320da872008-07-02 13:40:33 +0000852 "router bgp " CMD_AS_RANGE,
paul718e3742002-12-13 20:15:29 +0000853 ROUTER_STR
854 BGP_STR
855 AS_STR)
856{
857 vty->node = BGP_NODE;
858 return CMD_SUCCESS;
859}
860
Paul Jakma10895fd2008-07-03 19:34:48 +0000861ALIAS_SH (VTYSH_BGPD,
862 router_bgp,
863 router_bgp_view_cmd,
864 "router bgp " CMD_AS_RANGE " view WORD",
865 ROUTER_STR
866 BGP_STR
867 AS_STR
868 "BGP view\n"
869 "view name\n")
870
paul718e3742002-12-13 20:15:29 +0000871DEFUNSH (VTYSH_BGPD,
872 address_family_vpnv4,
873 address_family_vpnv4_cmd,
874 "address-family vpnv4",
875 "Enter Address Family command mode\n"
876 "Address family\n")
877{
878 vty->node = BGP_VPNV4_NODE;
879 return CMD_SUCCESS;
880}
881
882DEFUNSH (VTYSH_BGPD,
883 address_family_vpnv4_unicast,
884 address_family_vpnv4_unicast_cmd,
885 "address-family vpnv4 unicast",
886 "Enter Address Family command mode\n"
887 "Address family\n"
888 "Address Family Modifier\n")
889{
890 vty->node = BGP_VPNV4_NODE;
891 return CMD_SUCCESS;
892}
893
894DEFUNSH (VTYSH_BGPD,
895 address_family_ipv4_unicast,
896 address_family_ipv4_unicast_cmd,
897 "address-family ipv4 unicast",
898 "Enter Address Family command mode\n"
899 "Address family\n"
900 "Address Family Modifier\n")
901{
902 vty->node = BGP_IPV4_NODE;
903 return CMD_SUCCESS;
904}
905
906DEFUNSH (VTYSH_BGPD,
907 address_family_ipv4_multicast,
908 address_family_ipv4_multicast_cmd,
909 "address-family ipv4 multicast",
910 "Enter Address Family command mode\n"
911 "Address family\n"
912 "Address Family Modifier\n")
913{
914 vty->node = BGP_IPV4M_NODE;
915 return CMD_SUCCESS;
916}
917
918DEFUNSH (VTYSH_BGPD,
919 address_family_ipv6,
920 address_family_ipv6_cmd,
921 "address-family ipv6",
922 "Enter Address Family command mode\n"
923 "Address family\n")
924{
925 vty->node = BGP_IPV6_NODE;
926 return CMD_SUCCESS;
927}
928
929DEFUNSH (VTYSH_BGPD,
930 address_family_ipv6_unicast,
931 address_family_ipv6_unicast_cmd,
932 "address-family ipv6 unicast",
933 "Enter Address Family command mode\n"
934 "Address family\n"
935 "Address Family Modifier\n")
936{
937 vty->node = BGP_IPV6_NODE;
938 return CMD_SUCCESS;
939}
940
paul57b5b7e2005-08-22 22:44:29 +0000941DEFUNSH (VTYSH_BGPD,
942 address_family_ipv6_multicast,
943 address_family_ipv6_multicast_cmd,
944 "address-family ipv6 multicast",
945 "Enter Address Family command mode\n"
946 "Address family\n"
947 "Address Family Modifier\n")
948{
949 vty->node = BGP_IPV6M_NODE;
950 return CMD_SUCCESS;
951}
952
paul718e3742002-12-13 20:15:29 +0000953DEFUNSH (VTYSH_RIPD,
954 key_chain,
955 key_chain_cmd,
956 "key chain WORD",
957 "Authentication key management\n"
958 "Key-chain management\n"
959 "Key-chain name\n")
960{
961 vty->node = KEYCHAIN_NODE;
962 return CMD_SUCCESS;
963}
964
965DEFUNSH (VTYSH_RIPD,
966 key,
967 key_cmd,
968 "key <0-2147483647>",
969 "Configure a key\n"
970 "Key identifier number\n")
971{
972 vty->node = KEYCHAIN_KEY_NODE;
973 return CMD_SUCCESS;
974}
975
976DEFUNSH (VTYSH_RIPD,
977 router_rip,
978 router_rip_cmd,
979 "router rip",
980 ROUTER_STR
981 "RIP")
982{
983 vty->node = RIP_NODE;
984 return CMD_SUCCESS;
985}
986
987DEFUNSH (VTYSH_RIPNGD,
988 router_ripng,
989 router_ripng_cmd,
990 "router ripng",
991 ROUTER_STR
992 "RIPng")
993{
994 vty->node = RIPNG_NODE;
995 return CMD_SUCCESS;
996}
997
998DEFUNSH (VTYSH_OSPFD,
999 router_ospf,
1000 router_ospf_cmd,
1001 "router ospf",
1002 "Enable a routing process\n"
1003 "Start OSPF configuration\n")
1004{
1005 vty->node = OSPF_NODE;
1006 return CMD_SUCCESS;
1007}
1008
1009DEFUNSH (VTYSH_OSPF6D,
1010 router_ospf6,
1011 router_ospf6_cmd,
1012 "router ospf6",
1013 OSPF6_ROUTER_STR
1014 OSPF6_STR)
1015{
1016 vty->node = OSPF6_NODE;
1017 return CMD_SUCCESS;
1018}
1019
hassoc25e4582003-12-23 10:39:08 +00001020DEFUNSH (VTYSH_ISISD,
hassob094d262004-08-25 12:22:00 +00001021 router_isis,
1022 router_isis_cmd,
1023 "router isis WORD",
1024 ROUTER_STR
1025 "ISO IS-IS\n"
1026 "ISO Routing area tag")
hassoc25e4582003-12-23 10:39:08 +00001027{
1028 vty->node = ISIS_NODE;
1029 return CMD_SUCCESS;
1030}
1031
paul718e3742002-12-13 20:15:29 +00001032DEFUNSH (VTYSH_RMAP,
1033 route_map,
1034 route_map_cmd,
1035 "route-map WORD (deny|permit) <1-65535>",
1036 "Create route-map or enter route-map command mode\n"
1037 "Route map tag\n"
1038 "Route map denies set operations\n"
1039 "Route map permits set operations\n"
1040 "Sequence to insert to/delete from existing route-map entry\n")
1041{
1042 vty->node = RMAP_NODE;
1043 return CMD_SUCCESS;
1044}
1045
paul718e3742002-12-13 20:15:29 +00001046DEFUNSH (VTYSH_ALL,
hassoe7168df2004-10-03 20:11:32 +00001047 vtysh_line_vty,
1048 vtysh_line_vty_cmd,
1049 "line vty",
1050 "Configure a terminal line\n"
1051 "Virtual terminal\n")
1052{
1053 vty->node = VTY_NODE;
1054 return CMD_SUCCESS;
1055}
1056
1057DEFUNSH (VTYSH_ALL,
paul718e3742002-12-13 20:15:29 +00001058 vtysh_enable,
1059 vtysh_enable_cmd,
1060 "enable",
1061 "Turn on privileged mode command\n")
1062{
1063 vty->node = ENABLE_NODE;
1064 return CMD_SUCCESS;
1065}
1066
paul718e3742002-12-13 20:15:29 +00001067DEFUNSH (VTYSH_ALL,
1068 vtysh_disable,
1069 vtysh_disable_cmd,
1070 "disable",
1071 "Turn off privileged mode command\n")
1072{
1073 if (vty->node == ENABLE_NODE)
1074 vty->node = VIEW_NODE;
1075 return CMD_SUCCESS;
1076}
1077
paul718e3742002-12-13 20:15:29 +00001078DEFUNSH (VTYSH_ALL,
1079 vtysh_config_terminal,
1080 vtysh_config_terminal_cmd,
1081 "configure terminal",
1082 "Configuration from vty interface\n"
1083 "Configuration terminal\n")
1084{
1085 vty->node = CONFIG_NODE;
1086 return CMD_SUCCESS;
1087}
1088
ajs274a4a42004-12-07 15:39:31 +00001089static int
paul718e3742002-12-13 20:15:29 +00001090vtysh_exit (struct vty *vty)
1091{
1092 switch (vty->node)
1093 {
1094 case VIEW_NODE:
1095 case ENABLE_NODE:
1096 exit (0);
1097 break;
1098 case CONFIG_NODE:
1099 vty->node = ENABLE_NODE;
1100 break;
1101 case INTERFACE_NODE:
1102 case ZEBRA_NODE:
1103 case BGP_NODE:
1104 case RIP_NODE:
1105 case RIPNG_NODE:
1106 case OSPF_NODE:
1107 case OSPF6_NODE:
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +01001108 case BABEL_NODE:
hassoc25e4582003-12-23 10:39:08 +00001109 case ISIS_NODE:
paul718e3742002-12-13 20:15:29 +00001110 case MASC_NODE:
1111 case RMAP_NODE:
1112 case VTY_NODE:
1113 case KEYCHAIN_NODE:
hasso2a56df92004-05-09 23:16:40 +00001114 vtysh_execute("end");
1115 vtysh_execute("configure terminal");
paul718e3742002-12-13 20:15:29 +00001116 vty->node = CONFIG_NODE;
1117 break;
1118 case BGP_VPNV4_NODE:
1119 case BGP_IPV4_NODE:
1120 case BGP_IPV4M_NODE:
1121 case BGP_IPV6_NODE:
paul57b5b7e2005-08-22 22:44:29 +00001122 case BGP_IPV6M_NODE:
paul718e3742002-12-13 20:15:29 +00001123 vty->node = BGP_NODE;
1124 break;
1125 case KEYCHAIN_KEY_NODE:
1126 vty->node = KEYCHAIN_NODE;
1127 break;
1128 default:
1129 break;
1130 }
1131 return CMD_SUCCESS;
1132}
1133
1134DEFUNSH (VTYSH_ALL,
1135 vtysh_exit_all,
1136 vtysh_exit_all_cmd,
1137 "exit",
1138 "Exit current mode and down to previous mode\n")
1139{
1140 return vtysh_exit (vty);
1141}
1142
1143ALIAS (vtysh_exit_all,
1144 vtysh_quit_all_cmd,
1145 "quit",
1146 "Exit current mode and down to previous mode\n")
1147
1148DEFUNSH (VTYSH_BGPD,
1149 exit_address_family,
1150 exit_address_family_cmd,
1151 "exit-address-family",
1152 "Exit from Address Family configuration mode\n")
1153{
1154 if (vty->node == BGP_IPV4_NODE
1155 || vty->node == BGP_IPV4M_NODE
1156 || vty->node == BGP_VPNV4_NODE
paul57b5b7e2005-08-22 22:44:29 +00001157 || vty->node == BGP_IPV6_NODE
1158 || vty->node == BGP_IPV6M_NODE)
paul718e3742002-12-13 20:15:29 +00001159 vty->node = BGP_NODE;
1160 return CMD_SUCCESS;
1161}
1162
1163DEFUNSH (VTYSH_ZEBRA,
1164 vtysh_exit_zebra,
1165 vtysh_exit_zebra_cmd,
1166 "exit",
1167 "Exit current mode and down to previous mode\n")
1168{
1169 return vtysh_exit (vty);
1170}
1171
1172ALIAS (vtysh_exit_zebra,
1173 vtysh_quit_zebra_cmd,
1174 "quit",
1175 "Exit current mode and down to previous mode\n")
1176
1177DEFUNSH (VTYSH_RIPD,
1178 vtysh_exit_ripd,
1179 vtysh_exit_ripd_cmd,
1180 "exit",
1181 "Exit current mode and down to previous mode\n")
1182{
1183 return vtysh_exit (vty);
1184}
1185
1186ALIAS (vtysh_exit_ripd,
1187 vtysh_quit_ripd_cmd,
1188 "quit",
1189 "Exit current mode and down to previous mode\n")
1190
paul68980082003-03-25 05:07:42 +00001191DEFUNSH (VTYSH_RIPNGD,
hassob094d262004-08-25 12:22:00 +00001192 vtysh_exit_ripngd,
1193 vtysh_exit_ripngd_cmd,
1194 "exit",
1195 "Exit current mode and down to previous mode\n")
paul68980082003-03-25 05:07:42 +00001196{
1197 return vtysh_exit (vty);
1198}
1199
1200ALIAS (vtysh_exit_ripngd,
1201 vtysh_quit_ripngd_cmd,
1202 "quit",
1203 "Exit current mode and down to previous mode\n")
1204
paul718e3742002-12-13 20:15:29 +00001205DEFUNSH (VTYSH_RMAP,
1206 vtysh_exit_rmap,
1207 vtysh_exit_rmap_cmd,
1208 "exit",
1209 "Exit current mode and down to previous mode\n")
1210{
1211 return vtysh_exit (vty);
1212}
1213
1214ALIAS (vtysh_exit_rmap,
1215 vtysh_quit_rmap_cmd,
1216 "quit",
1217 "Exit current mode and down to previous mode\n")
1218
1219DEFUNSH (VTYSH_BGPD,
1220 vtysh_exit_bgpd,
1221 vtysh_exit_bgpd_cmd,
1222 "exit",
1223 "Exit current mode and down to previous mode\n")
1224{
1225 return vtysh_exit (vty);
1226}
1227
1228ALIAS (vtysh_exit_bgpd,
1229 vtysh_quit_bgpd_cmd,
1230 "quit",
1231 "Exit current mode and down to previous mode\n")
1232
1233DEFUNSH (VTYSH_OSPFD,
1234 vtysh_exit_ospfd,
1235 vtysh_exit_ospfd_cmd,
1236 "exit",
1237 "Exit current mode and down to previous mode\n")
1238{
1239 return vtysh_exit (vty);
1240}
1241
1242ALIAS (vtysh_exit_ospfd,
1243 vtysh_quit_ospfd_cmd,
1244 "quit",
1245 "Exit current mode and down to previous mode\n")
1246
paul68980082003-03-25 05:07:42 +00001247DEFUNSH (VTYSH_OSPF6D,
hassob094d262004-08-25 12:22:00 +00001248 vtysh_exit_ospf6d,
1249 vtysh_exit_ospf6d_cmd,
1250 "exit",
1251 "Exit current mode and down to previous mode\n")
paul68980082003-03-25 05:07:42 +00001252{
1253 return vtysh_exit (vty);
1254}
1255
1256ALIAS (vtysh_exit_ospf6d,
1257 vtysh_quit_ospf6d_cmd,
1258 "quit",
1259 "Exit current mode and down to previous mode\n")
1260
hassoc25e4582003-12-23 10:39:08 +00001261DEFUNSH (VTYSH_ISISD,
hassob094d262004-08-25 12:22:00 +00001262 vtysh_exit_isisd,
1263 vtysh_exit_isisd_cmd,
1264 "exit",
1265 "Exit current mode and down to previous mode\n")
hassoc25e4582003-12-23 10:39:08 +00001266{
1267 return vtysh_exit (vty);
1268}
1269
1270ALIAS (vtysh_exit_isisd,
1271 vtysh_quit_isisd_cmd,
1272 "quit",
1273 "Exit current mode and down to previous mode\n")
1274
hassoe7168df2004-10-03 20:11:32 +00001275DEFUNSH (VTYSH_ALL,
1276 vtysh_exit_line_vty,
1277 vtysh_exit_line_vty_cmd,
1278 "exit",
1279 "Exit current mode and down to previous mode\n")
1280{
1281 return vtysh_exit (vty);
1282}
1283
1284ALIAS (vtysh_exit_line_vty,
1285 vtysh_quit_line_vty_cmd,
1286 "quit",
1287 "Exit current mode and down to previous mode\n")
1288
hasso95e735b2004-08-26 13:08:30 +00001289DEFUNSH (VTYSH_INTERFACE,
paul718e3742002-12-13 20:15:29 +00001290 vtysh_interface,
1291 vtysh_interface_cmd,
1292 "interface IFNAME",
1293 "Select an interface to configure\n"
1294 "Interface's name\n")
1295{
1296 vty->node = INTERFACE_NODE;
1297 return CMD_SUCCESS;
1298}
1299
Feng Lu471ea392015-05-22 11:40:00 +02001300ALIAS_SH (VTYSH_ZEBRA,
1301 vtysh_interface,
1302 vtysh_interface_vrf_cmd,
1303 "interface IFNAME " VRF_CMD_STR,
1304 "Select an interface to configure\n"
1305 "Interface's name\n"
1306 VRF_CMD_HELP_STR)
1307
hasso95e735b2004-08-26 13:08:30 +00001308/* TODO Implement "no interface command in isisd. */
paul32d24632003-05-23 09:25:20 +00001309DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D,
1310 vtysh_no_interface_cmd,
1311 "no interface IFNAME",
1312 NO_STR
1313 "Delete a pseudo interface's configuration\n"
1314 "Interface's name\n")
1315
Feng Lu471ea392015-05-22 11:40:00 +02001316DEFSH (VTYSH_ZEBRA,
1317 vtysh_no_interface_vrf_cmd,
1318 "no interface IFNAME " VRF_CMD_STR,
1319 NO_STR
1320 "Delete a pseudo interface's configuration\n"
1321 "Interface's name\n"
1322 VRF_CMD_HELP_STR)
1323
hasso95e735b2004-08-26 13:08:30 +00001324/* TODO Implement interface description commands in ripngd, ospf6d
1325 * and isisd. */
paul338a9912003-03-01 15:44:10 +00001326DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1327 interface_desc_cmd,
1328 "description .LINE",
1329 "Interface specific description\n"
1330 "Characters describing this interface\n")
paul464dc8d2003-03-28 02:25:45 +00001331
1332DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1333 no_interface_desc_cmd,
1334 "no description",
1335 NO_STR
1336 "Interface specific description\n")
paul338a9912003-03-01 15:44:10 +00001337
hasso95e735b2004-08-26 13:08:30 +00001338DEFUNSH (VTYSH_INTERFACE,
paul718e3742002-12-13 20:15:29 +00001339 vtysh_exit_interface,
1340 vtysh_exit_interface_cmd,
1341 "exit",
1342 "Exit current mode and down to previous mode\n")
1343{
1344 return vtysh_exit (vty);
1345}
1346
1347ALIAS (vtysh_exit_interface,
1348 vtysh_quit_interface_cmd,
1349 "quit",
1350 "Exit current mode and down to previous mode\n")
1351
Donald Sharp567a6382015-08-19 21:22:17 -04001352DEFUN (vtysh_show_thread,
1353 vtysh_show_thread_cmd,
1354 "show thread cpu [FILTER]",
1355 SHOW_STR
1356 "Thread information\n"
1357 "Thread CPU usage\n"
1358 "Display filter (rwtexb)\n")
1359{
1360 unsigned int i;
1361 int ret = CMD_SUCCESS;
1362 char line[100];
1363
1364 sprintf(line, "show thread cpu %s\n", (argc == 1) ? argv[0] : "");
1365 for (i = 0; i < array_size(vtysh_client); i++)
1366 if ( vtysh_client[i].fd >= 0 )
1367 {
1368 fprintf (stdout, "Thread statistics for %s:\n",
1369 vtysh_client[i].name);
1370 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1371 fprintf (stdout,"\n");
1372 }
1373 return ret;
1374}
1375
1376DEFUN (vtysh_show_work_queues,
1377 vtysh_show_work_queues_cmd,
1378 "show work-queues",
1379 SHOW_STR
1380 "Work Queue information\n")
1381{
1382 unsigned int i;
1383 int ret = CMD_SUCCESS;
1384 char line[] = "show work-queues\n";
1385
1386 for (i = 0; i < array_size(vtysh_client); i++)
1387 if ( vtysh_client[i].fd >= 0 )
1388 {
1389 fprintf (stdout, "Work queue statistics for %s:\n",
1390 vtysh_client[i].name);
1391 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1392 fprintf (stdout,"\n");
1393 }
1394
1395 return ret;
1396}
1397
Paul Jakma362b4032006-05-28 07:54:45 +00001398/* Memory */
1399DEFUN (vtysh_show_memory,
1400 vtysh_show_memory_cmd,
1401 "show memory",
1402 SHOW_STR
1403 "Memory statistics\n")
1404{
1405 unsigned int i;
1406 int ret = CMD_SUCCESS;
1407 char line[] = "show memory\n";
1408
Balaji.G837d16c2012-09-26 14:09:10 +05301409 for (i = 0; i < array_size(vtysh_client); i++)
Paul Jakma362b4032006-05-28 07:54:45 +00001410 if ( vtysh_client[i].fd >= 0 )
1411 {
1412 fprintf (stdout, "Memory statistics for %s:\n",
1413 vtysh_client[i].name);
1414 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1415 fprintf (stdout,"\n");
1416 }
1417
1418 return ret;
1419}
1420
hasso95e735b2004-08-26 13:08:30 +00001421/* Logging commands. */
Paul Jakmadbf7d132006-05-23 22:10:01 +00001422DEFUN (vtysh_show_logging,
1423 vtysh_show_logging_cmd,
1424 "show logging",
1425 SHOW_STR
1426 "Show current logging configuration\n")
1427{
1428 unsigned int i;
1429 int ret = CMD_SUCCESS;
1430 char line[] = "show logging\n";
1431
Balaji.G837d16c2012-09-26 14:09:10 +05301432 for (i = 0; i < array_size(vtysh_client); i++)
Paul Jakma4150f332006-05-23 22:10:55 +00001433 if ( vtysh_client[i].fd >= 0 )
1434 {
1435 fprintf (stdout,"Logging configuration for %s:\n",
1436 vtysh_client[i].name);
1437 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1438 fprintf (stdout,"\n");
1439 }
1440
Paul Jakmadbf7d132006-05-23 22:10:01 +00001441 return ret;
1442}
1443
hasso95e735b2004-08-26 13:08:30 +00001444DEFUNSH (VTYSH_ALL,
1445 vtysh_log_stdout,
1446 vtysh_log_stdout_cmd,
1447 "log stdout",
1448 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001449 "Set stdout logging level\n")
1450{
1451 return CMD_SUCCESS;
1452}
1453
1454DEFUNSH (VTYSH_ALL,
1455 vtysh_log_stdout_level,
1456 vtysh_log_stdout_level_cmd,
1457 "log stdout "LOG_LEVELS,
1458 "Logging control\n"
1459 "Set stdout logging level\n"
1460 LOG_LEVEL_DESC)
hasso95e735b2004-08-26 13:08:30 +00001461{
1462 return CMD_SUCCESS;
1463}
1464
1465DEFUNSH (VTYSH_ALL,
1466 no_vtysh_log_stdout,
1467 no_vtysh_log_stdout_cmd,
ajs274a4a42004-12-07 15:39:31 +00001468 "no log stdout [LEVEL]",
hasso95e735b2004-08-26 13:08:30 +00001469 NO_STR
1470 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001471 "Cancel logging to stdout\n"
1472 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001473{
1474 return CMD_SUCCESS;
1475}
1476
1477DEFUNSH (VTYSH_ALL,
1478 vtysh_log_file,
1479 vtysh_log_file_cmd,
1480 "log file FILENAME",
1481 "Logging control\n"
1482 "Logging to file\n"
1483 "Logging filename\n")
1484{
1485 return CMD_SUCCESS;
1486}
1487
1488DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001489 vtysh_log_file_level,
1490 vtysh_log_file_level_cmd,
1491 "log file FILENAME "LOG_LEVELS,
1492 "Logging control\n"
1493 "Logging to file\n"
1494 "Logging filename\n"
1495 LOG_LEVEL_DESC)
1496{
1497 return CMD_SUCCESS;
1498}
1499
1500DEFUNSH (VTYSH_ALL,
hasso95e735b2004-08-26 13:08:30 +00001501 no_vtysh_log_file,
1502 no_vtysh_log_file_cmd,
1503 "no log file [FILENAME]",
1504 NO_STR
1505 "Logging control\n"
1506 "Cancel logging to file\n"
1507 "Logging file name\n")
1508{
1509 return CMD_SUCCESS;
1510}
1511
ajs274a4a42004-12-07 15:39:31 +00001512ALIAS_SH (VTYSH_ALL,
1513 no_vtysh_log_file,
1514 no_vtysh_log_file_level_cmd,
1515 "no log file FILENAME LEVEL",
1516 NO_STR
1517 "Logging control\n"
1518 "Cancel logging to file\n"
1519 "Logging file name\n"
1520 "Logging level\n")
1521
1522DEFUNSH (VTYSH_ALL,
1523 vtysh_log_monitor,
1524 vtysh_log_monitor_cmd,
1525 "log monitor",
1526 "Logging control\n"
1527 "Set terminal line (monitor) logging level\n")
1528{
1529 return CMD_SUCCESS;
1530}
1531
1532DEFUNSH (VTYSH_ALL,
1533 vtysh_log_monitor_level,
1534 vtysh_log_monitor_level_cmd,
1535 "log monitor "LOG_LEVELS,
1536 "Logging control\n"
1537 "Set terminal line (monitor) logging level\n"
1538 LOG_LEVEL_DESC)
1539{
1540 return CMD_SUCCESS;
1541}
1542
1543DEFUNSH (VTYSH_ALL,
1544 no_vtysh_log_monitor,
1545 no_vtysh_log_monitor_cmd,
1546 "no log monitor [LEVEL]",
1547 NO_STR
1548 "Logging control\n"
1549 "Disable terminal line (monitor) logging\n"
1550 "Logging level\n")
1551{
1552 return CMD_SUCCESS;
1553}
1554
hasso95e735b2004-08-26 13:08:30 +00001555DEFUNSH (VTYSH_ALL,
1556 vtysh_log_syslog,
1557 vtysh_log_syslog_cmd,
1558 "log syslog",
1559 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001560 "Set syslog logging level\n")
1561{
1562 return CMD_SUCCESS;
1563}
1564
1565DEFUNSH (VTYSH_ALL,
1566 vtysh_log_syslog_level,
1567 vtysh_log_syslog_level_cmd,
1568 "log syslog "LOG_LEVELS,
1569 "Logging control\n"
1570 "Set syslog logging level\n"
1571 LOG_LEVEL_DESC)
hasso95e735b2004-08-26 13:08:30 +00001572{
1573 return CMD_SUCCESS;
1574}
1575
1576DEFUNSH (VTYSH_ALL,
1577 no_vtysh_log_syslog,
1578 no_vtysh_log_syslog_cmd,
ajs274a4a42004-12-07 15:39:31 +00001579 "no log syslog [LEVEL]",
hasso95e735b2004-08-26 13:08:30 +00001580 NO_STR
1581 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001582 "Cancel logging to syslog\n"
1583 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001584{
1585 return CMD_SUCCESS;
1586}
1587
1588DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001589 vtysh_log_facility,
1590 vtysh_log_facility_cmd,
1591 "log facility "LOG_FACILITIES,
hasso95e735b2004-08-26 13:08:30 +00001592 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001593 "Facility parameter for syslog messages\n"
1594 LOG_FACILITY_DESC)
1595
hasso95e735b2004-08-26 13:08:30 +00001596{
1597 return CMD_SUCCESS;
1598}
1599
1600DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001601 no_vtysh_log_facility,
1602 no_vtysh_log_facility_cmd,
1603 "no log facility [FACILITY]",
hasso95e735b2004-08-26 13:08:30 +00001604 NO_STR
1605 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001606 "Reset syslog facility to default (daemon)\n"
1607 "Syslog facility\n")
1608
1609{
1610 return CMD_SUCCESS;
1611}
1612
1613DEFUNSH_DEPRECATED (VTYSH_ALL,
1614 vtysh_log_trap,
1615 vtysh_log_trap_cmd,
1616 "log trap "LOG_LEVELS,
1617 "Logging control\n"
1618 "(Deprecated) Set logging level and default for all destinations\n"
1619 LOG_LEVEL_DESC)
1620
1621{
1622 return CMD_SUCCESS;
1623}
1624
1625DEFUNSH_DEPRECATED (VTYSH_ALL,
1626 no_vtysh_log_trap,
1627 no_vtysh_log_trap_cmd,
1628 "no log trap [LEVEL]",
1629 NO_STR
1630 "Logging control\n"
1631 "Permit all logging information\n"
1632 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001633{
1634 return CMD_SUCCESS;
1635}
1636
1637DEFUNSH (VTYSH_ALL,
1638 vtysh_log_record_priority,
1639 vtysh_log_record_priority_cmd,
1640 "log record-priority",
1641 "Logging control\n"
1642 "Log the priority of the message within the message\n")
1643{
1644 return CMD_SUCCESS;
1645}
1646
1647DEFUNSH (VTYSH_ALL,
1648 no_vtysh_log_record_priority,
1649 no_vtysh_log_record_priority_cmd,
1650 "no log record-priority",
1651 NO_STR
1652 "Logging control\n"
1653 "Do not log the priority of the message within the message\n")
1654{
1655 return CMD_SUCCESS;
1656}
1657
hassoe7168df2004-10-03 20:11:32 +00001658DEFUNSH (VTYSH_ALL,
Andrew J. Schorrc749b722007-04-29 03:53:31 +00001659 vtysh_log_timestamp_precision,
1660 vtysh_log_timestamp_precision_cmd,
1661 "log timestamp precision <0-6>",
1662 "Logging control\n"
1663 "Timestamp configuration\n"
1664 "Set the timestamp precision\n"
1665 "Number of subsecond digits\n")
1666{
1667 return CMD_SUCCESS;
1668}
1669
1670DEFUNSH (VTYSH_ALL,
1671 no_vtysh_log_timestamp_precision,
1672 no_vtysh_log_timestamp_precision_cmd,
1673 "no log timestamp precision",
1674 NO_STR
1675 "Logging control\n"
1676 "Timestamp configuration\n"
1677 "Reset the timestamp precision to the default value of 0\n")
1678{
1679 return CMD_SUCCESS;
1680}
1681
1682DEFUNSH (VTYSH_ALL,
hassoe7168df2004-10-03 20:11:32 +00001683 vtysh_service_password_encrypt,
1684 vtysh_service_password_encrypt_cmd,
1685 "service password-encryption",
1686 "Set up miscellaneous service\n"
1687 "Enable encrypted passwords\n")
1688{
1689 return CMD_SUCCESS;
1690}
1691
1692DEFUNSH (VTYSH_ALL,
1693 no_vtysh_service_password_encrypt,
1694 no_vtysh_service_password_encrypt_cmd,
1695 "no service password-encryption",
1696 NO_STR
1697 "Set up miscellaneous service\n"
1698 "Enable encrypted passwords\n")
1699{
1700 return CMD_SUCCESS;
1701}
1702
1703DEFUNSH (VTYSH_ALL,
1704 vtysh_config_password,
1705 vtysh_password_cmd,
1706 "password (8|) WORD",
1707 "Assign the terminal connection password\n"
1708 "Specifies a HIDDEN password will follow\n"
1709 "dummy string \n"
1710 "The HIDDEN line password string\n")
1711{
1712 return CMD_SUCCESS;
1713}
1714
1715DEFUNSH (VTYSH_ALL,
1716 vtysh_password_text,
1717 vtysh_password_text_cmd,
1718 "password LINE",
1719 "Assign the terminal connection password\n"
1720 "The UNENCRYPTED (cleartext) line password\n")
1721{
1722 return CMD_SUCCESS;
1723}
1724
1725DEFUNSH (VTYSH_ALL,
1726 vtysh_config_enable_password,
1727 vtysh_enable_password_cmd,
1728 "enable password (8|) WORD",
1729 "Modify enable password parameters\n"
1730 "Assign the privileged level password\n"
1731 "Specifies a HIDDEN password will follow\n"
1732 "dummy string \n"
1733 "The HIDDEN 'enable' password string\n")
1734{
1735 return CMD_SUCCESS;
1736}
1737
1738DEFUNSH (VTYSH_ALL,
1739 vtysh_enable_password_text,
1740 vtysh_enable_password_text_cmd,
1741 "enable password LINE",
1742 "Modify enable password parameters\n"
1743 "Assign the privileged level password\n"
1744 "The UNENCRYPTED (cleartext) 'enable' password\n")
1745{
1746 return CMD_SUCCESS;
1747}
1748
1749DEFUNSH (VTYSH_ALL,
1750 no_vtysh_config_enable_password,
1751 no_vtysh_enable_password_cmd,
1752 "no enable password",
1753 NO_STR
1754 "Modify enable password parameters\n"
1755 "Assign the privileged level password\n")
1756{
1757 return CMD_SUCCESS;
1758}
1759
paul718e3742002-12-13 20:15:29 +00001760DEFUN (vtysh_write_terminal,
1761 vtysh_write_terminal_cmd,
1762 "write terminal",
1763 "Write running configuration to memory, network, or terminal\n"
1764 "Write to terminal\n")
1765{
ajsb1aa1472005-01-28 21:11:46 +00001766 u_int i;
paul718e3742002-12-13 20:15:29 +00001767 char line[] = "write terminal\n";
1768 FILE *fp = NULL;
1769
1770 if (vtysh_pager_name)
1771 {
paul4fc01e62002-12-13 20:49:00 +00001772 fp = popen (vtysh_pager_name, "w");
paul718e3742002-12-13 20:15:29 +00001773 if (fp == NULL)
1774 {
1775 perror ("popen");
1776 exit (1);
1777 }
1778 }
1779 else
1780 fp = stdout;
1781
1782 vty_out (vty, "Building configuration...%s", VTY_NEWLINE);
1783 vty_out (vty, "%sCurrent configuration:%s", VTY_NEWLINE,
1784 VTY_NEWLINE);
hassoe7168df2004-10-03 20:11:32 +00001785 vty_out (vty, "!%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001786
Balaji.G837d16c2012-09-26 14:09:10 +05301787 for (i = 0; i < array_size(vtysh_client); i++)
David Lamparter6769f432015-03-04 07:18:24 +01001788 vtysh_client_config (&vtysh_client[i], line);
paul718e3742002-12-13 20:15:29 +00001789
hassoe7168df2004-10-03 20:11:32 +00001790 /* Integrate vtysh specific configuration. */
1791 vtysh_config_write ();
1792
paul718e3742002-12-13 20:15:29 +00001793 vtysh_config_dump (fp);
1794
1795 if (vtysh_pager_name && fp)
1796 {
1797 fflush (fp);
1798 if (pclose (fp) == -1)
1799 {
1800 perror ("pclose");
1801 exit (1);
1802 }
1803 fp = NULL;
1804 }
1805
Chris Caputo6e79f8b2009-06-23 05:55:57 +00001806 vty_out (vty, "end%s", VTY_NEWLINE);
1807
paul718e3742002-12-13 20:15:29 +00001808 return CMD_SUCCESS;
1809}
1810
Donald Sharp9fb73e82015-09-22 11:13:12 -04001811DEFUN (vtysh_write_terminal_daemon,
1812 vtysh_write_terminal_daemon_cmd,
1813 "write terminal (zebra|ripd|ripngd|ospfd|ospf6d|bgpd|isisd|babeld)",
1814 "Write running configuration to memory, network, or terminal\n"
1815 "Write to terminal\n"
1816 "For the zebra daemon\n"
1817 "For the rip daemon\n"
1818 "For the ripng daemon\n"
1819 "For the ospf daemon\n"
1820 "For the ospfv6 daemon\n"
1821 "For the bgp daemon\n"
1822 "For the isis daemon\n"
1823 "For the babel daemon\n")
1824{
1825 unsigned int i;
1826 int ret = CMD_SUCCESS;
1827
1828 for (i = 0; i < array_size(vtysh_client); i++)
1829 {
1830 if (strcmp(vtysh_client[i].name, argv[0]) == 0)
1831 break;
1832 }
1833
1834 ret = vtysh_client_execute(&vtysh_client[i], "show running-config\n", stdout);
1835
1836 return ret;
1837}
1838
hassoe7168df2004-10-03 20:11:32 +00001839DEFUN (vtysh_integrated_config,
1840 vtysh_integrated_config_cmd,
1841 "service integrated-vtysh-config",
1842 "Set up miscellaneous service\n"
1843 "Write configuration into integrated file\n")
paul4fc01e62002-12-13 20:49:00 +00001844{
hassoe7168df2004-10-03 20:11:32 +00001845 vtysh_writeconfig_integrated = 1;
1846 return CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001847}
1848
hassoe7168df2004-10-03 20:11:32 +00001849DEFUN (no_vtysh_integrated_config,
1850 no_vtysh_integrated_config_cmd,
1851 "no service integrated-vtysh-config",
1852 NO_STR
1853 "Set up miscellaneous service\n"
1854 "Write configuration into integrated file\n")
paul4fc01e62002-12-13 20:49:00 +00001855{
hassoe7168df2004-10-03 20:11:32 +00001856 vtysh_writeconfig_integrated = 0;
1857 return CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001858}
1859
ajs274a4a42004-12-07 15:39:31 +00001860static int
1861write_config_integrated(void)
paul718e3742002-12-13 20:15:29 +00001862{
ajsb1aa1472005-01-28 21:11:46 +00001863 u_int i;
paul718e3742002-12-13 20:15:29 +00001864 char line[] = "write terminal\n";
1865 FILE *fp;
1866 char *integrate_sav = NULL;
1867
hasso95e735b2004-08-26 13:08:30 +00001868 integrate_sav = malloc (strlen (integrate_default) +
1869 strlen (CONF_BACKUP_EXT) + 1);
paul718e3742002-12-13 20:15:29 +00001870 strcpy (integrate_sav, integrate_default);
1871 strcat (integrate_sav, CONF_BACKUP_EXT);
1872
paul4fc01e62002-12-13 20:49:00 +00001873 fprintf (stdout,"Building Configuration...\n");
paul718e3742002-12-13 20:15:29 +00001874
hasso95e735b2004-08-26 13:08:30 +00001875 /* Move current configuration file to backup config file. */
paul718e3742002-12-13 20:15:29 +00001876 unlink (integrate_sav);
1877 rename (integrate_default, integrate_sav);
hasso95e735b2004-08-26 13:08:30 +00001878 free (integrate_sav);
paul4fc01e62002-12-13 20:49:00 +00001879
paul718e3742002-12-13 20:15:29 +00001880 fp = fopen (integrate_default, "w");
1881 if (fp == NULL)
1882 {
hasso95e735b2004-08-26 13:08:30 +00001883 fprintf (stdout,"%% Can't open configuration file %s.\n",
1884 integrate_default);
paul718e3742002-12-13 20:15:29 +00001885 return CMD_SUCCESS;
1886 }
paul718e3742002-12-13 20:15:29 +00001887
Balaji.G837d16c2012-09-26 14:09:10 +05301888 for (i = 0; i < array_size(vtysh_client); i++)
David Lamparter6769f432015-03-04 07:18:24 +01001889 vtysh_client_config (&vtysh_client[i], line);
paul718e3742002-12-13 20:15:29 +00001890
1891 vtysh_config_dump (fp);
1892
1893 fclose (fp);
1894
gdtaa593d52003-12-22 20:15:53 +00001895 if (chmod (integrate_default, CONFIGFILE_MASK) != 0)
1896 {
1897 fprintf (stdout,"%% Can't chmod configuration file %s: %s (%d)\n",
ajs6099b3b2004-11-20 02:06:59 +00001898 integrate_default, safe_strerror(errno), errno);
gdtaa593d52003-12-22 20:15:53 +00001899 return CMD_WARNING;
1900 }
1901
paul4fc01e62002-12-13 20:49:00 +00001902 fprintf(stdout,"Integrated configuration saved to %s\n",integrate_default);
1903
1904 fprintf (stdout,"[OK]\n");
1905
paul718e3742002-12-13 20:15:29 +00001906 return CMD_SUCCESS;
1907}
1908
paul4fc01e62002-12-13 20:49:00 +00001909DEFUN (vtysh_write_memory,
1910 vtysh_write_memory_cmd,
1911 "write memory",
1912 "Write running configuration to memory, network, or terminal\n"
1913 "Write configuration to the file (same as write file)\n")
1914{
pauldfc0d9b2003-04-18 23:55:29 +00001915 int ret = CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001916 char line[] = "write memory\n";
ajsb1aa1472005-01-28 21:11:46 +00001917 u_int i;
paul4fc01e62002-12-13 20:49:00 +00001918
hassoe7168df2004-10-03 20:11:32 +00001919 /* If integrated Quagga.conf explicitely set. */
1920 if (vtysh_writeconfig_integrated)
1921 return write_config_integrated();
paul4fc01e62002-12-13 20:49:00 +00001922
1923 fprintf (stdout,"Building Configuration...\n");
1924
Balaji.G837d16c2012-09-26 14:09:10 +05301925 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00001926 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
hassoe7168df2004-10-03 20:11:32 +00001927
paul4fc01e62002-12-13 20:49:00 +00001928 fprintf (stdout,"[OK]\n");
1929
pauldfc0d9b2003-04-18 23:55:29 +00001930 return ret;
paul4fc01e62002-12-13 20:49:00 +00001931}
1932
paul718e3742002-12-13 20:15:29 +00001933ALIAS (vtysh_write_memory,
1934 vtysh_copy_runningconfig_startupconfig_cmd,
1935 "copy running-config startup-config",
1936 "Copy from one file to another\n"
1937 "Copy from current system configuration\n"
1938 "Copy to startup configuration\n")
1939
1940ALIAS (vtysh_write_memory,
1941 vtysh_write_file_cmd,
1942 "write file",
1943 "Write running configuration to memory, network, or terminal\n"
1944 "Write configuration to the file (same as write memory)\n")
1945
hasso4a6e2252003-05-25 11:51:29 +00001946ALIAS (vtysh_write_memory,
1947 vtysh_write_cmd,
1948 "write",
1949 "Write running configuration to memory, network, or terminal\n")
1950
paul718e3742002-12-13 20:15:29 +00001951ALIAS (vtysh_write_terminal,
1952 vtysh_show_running_config_cmd,
1953 "show running-config",
1954 SHOW_STR
1955 "Current operating configuration\n")
hassob094d262004-08-25 12:22:00 +00001956
Donald Sharp9fb73e82015-09-22 11:13:12 -04001957ALIAS (vtysh_write_terminal_daemon,
1958 vtysh_show_running_config_daemon_cmd,
1959 "show running-config (zebra|ripd|ripngd|ospfd|ospf6d|bgpd|isisd|babeld)",
1960 SHOW_STR
1961 "Current operating configuration\n"
1962 "For the zebra daemon\n"
1963 "For the rip daemon\n"
1964 "For the ripng daemon\n"
1965 "For the ospf daemon\n"
1966 "For the ospfv6 daemon\n"
1967 "For the bgp daemon\n"
1968 "For the isis daemon\n"
1969 "For the babel daemon\n")
1970
hasso34553cc2004-08-27 13:56:39 +00001971DEFUN (vtysh_terminal_length,
1972 vtysh_terminal_length_cmd,
1973 "terminal length <0-512>",
1974 "Set terminal line parameters\n"
1975 "Set number of lines on a screen\n"
1976 "Number of lines on screen (0 for no pausing)\n")
1977{
1978 int lines;
1979 char *endptr = NULL;
1980 char default_pager[10];
1981
1982 lines = strtol (argv[0], &endptr, 10);
1983 if (lines < 0 || lines > 512 || *endptr != '\0')
1984 {
1985 vty_out (vty, "length is malformed%s", VTY_NEWLINE);
1986 return CMD_WARNING;
1987 }
1988
1989 if (vtysh_pager_name)
1990 {
1991 free (vtysh_pager_name);
1992 vtysh_pager_name = NULL;
1993 }
1994
1995 if (lines != 0)
1996 {
1997 snprintf(default_pager, 10, "more -%i", lines);
1998 vtysh_pager_name = strdup (default_pager);
1999 }
2000
2001 return CMD_SUCCESS;
2002}
2003
2004DEFUN (vtysh_terminal_no_length,
2005 vtysh_terminal_no_length_cmd,
2006 "terminal no length",
2007 "Set terminal line parameters\n"
2008 NO_STR
2009 "Set number of lines on a screen\n")
2010{
2011 if (vtysh_pager_name)
2012 {
2013 free (vtysh_pager_name);
2014 vtysh_pager_name = NULL;
2015 }
2016
2017 vtysh_pager_init();
2018 return CMD_SUCCESS;
2019}
2020
hassof2799e62004-10-28 17:43:11 +00002021DEFUN (vtysh_show_daemons,
2022 vtysh_show_daemons_cmd,
2023 "show daemons",
hassoe7168df2004-10-03 20:11:32 +00002024 SHOW_STR
2025 "Show list of running daemons\n")
2026{
ajsb1aa1472005-01-28 21:11:46 +00002027 u_int i;
2028
Balaji.G837d16c2012-09-26 14:09:10 +05302029 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00002030 if ( vtysh_client[i].fd >= 0 )
2031 vty_out(vty, " %s", vtysh_client[i].name);
hassoe7168df2004-10-03 20:11:32 +00002032 vty_out(vty, "%s", VTY_NEWLINE);
2033
2034 return CMD_SUCCESS;
2035}
2036
paul718e3742002-12-13 20:15:29 +00002037/* Execute command in child process. */
ajs274a4a42004-12-07 15:39:31 +00002038static int
hasso5862ff52004-10-11 13:20:40 +00002039execute_command (const char *command, int argc, const char *arg1,
2040 const char *arg2)
paul718e3742002-12-13 20:15:29 +00002041{
paul718e3742002-12-13 20:15:29 +00002042 pid_t pid;
2043 int status;
2044
2045 /* Call fork(). */
2046 pid = fork ();
2047
2048 if (pid < 0)
2049 {
2050 /* Failure of fork(). */
ajs6099b3b2004-11-20 02:06:59 +00002051 fprintf (stderr, "Can't fork: %s\n", safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +00002052 exit (1);
2053 }
2054 else if (pid == 0)
2055 {
2056 /* This is child process. */
2057 switch (argc)
2058 {
2059 case 0:
David Lamparter6769f432015-03-04 07:18:24 +01002060 execlp (command, command, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00002061 break;
2062 case 1:
David Lamparter6769f432015-03-04 07:18:24 +01002063 execlp (command, command, arg1, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00002064 break;
2065 case 2:
David Lamparter6769f432015-03-04 07:18:24 +01002066 execlp (command, command, arg1, arg2, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00002067 break;
2068 }
2069
2070 /* When execlp suceed, this part is not executed. */
ajs6099b3b2004-11-20 02:06:59 +00002071 fprintf (stderr, "Can't execute %s: %s\n", command, safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +00002072 exit (1);
2073 }
2074 else
2075 {
2076 /* This is parent. */
2077 execute_flag = 1;
David Lamparter6769f432015-03-04 07:18:24 +01002078 wait4 (pid, &status, 0, NULL);
paul718e3742002-12-13 20:15:29 +00002079 execute_flag = 0;
2080 }
2081 return 0;
2082}
2083
2084DEFUN (vtysh_ping,
2085 vtysh_ping_cmd,
2086 "ping WORD",
hasso4eeccf12003-06-25 10:49:55 +00002087 "Send echo messages\n"
paul718e3742002-12-13 20:15:29 +00002088 "Ping destination address or hostname\n")
2089{
2090 execute_command ("ping", 1, argv[0], NULL);
2091 return CMD_SUCCESS;
2092}
2093
hasso4eeccf12003-06-25 10:49:55 +00002094ALIAS (vtysh_ping,
2095 vtysh_ping_ip_cmd,
2096 "ping ip WORD",
2097 "Send echo messages\n"
2098 "IP echo\n"
2099 "Ping destination address or hostname\n")
2100
paul718e3742002-12-13 20:15:29 +00002101DEFUN (vtysh_traceroute,
2102 vtysh_traceroute_cmd,
2103 "traceroute WORD",
2104 "Trace route to destination\n"
2105 "Trace route to destination address or hostname\n")
2106{
2107 execute_command ("traceroute", 1, argv[0], NULL);
2108 return CMD_SUCCESS;
2109}
2110
hasso4eeccf12003-06-25 10:49:55 +00002111ALIAS (vtysh_traceroute,
2112 vtysh_traceroute_ip_cmd,
2113 "traceroute ip WORD",
2114 "Trace route to destination\n"
2115 "IP trace\n"
2116 "Trace route to destination address or hostname\n")
2117
2118#ifdef HAVE_IPV6
2119DEFUN (vtysh_ping6,
2120 vtysh_ping6_cmd,
2121 "ping ipv6 WORD",
2122 "Send echo messages\n"
2123 "IPv6 echo\n"
2124 "Ping destination address or hostname\n")
2125{
2126 execute_command ("ping6", 1, argv[0], NULL);
2127 return CMD_SUCCESS;
2128}
2129
2130DEFUN (vtysh_traceroute6,
2131 vtysh_traceroute6_cmd,
2132 "traceroute ipv6 WORD",
2133 "Trace route to destination\n"
2134 "IPv6 trace\n"
2135 "Trace route to destination address or hostname\n")
2136{
2137 execute_command ("traceroute6", 1, argv[0], NULL);
2138 return CMD_SUCCESS;
2139}
2140#endif
2141
paul718e3742002-12-13 20:15:29 +00002142DEFUN (vtysh_telnet,
2143 vtysh_telnet_cmd,
2144 "telnet WORD",
2145 "Open a telnet connection\n"
2146 "IP address or hostname of a remote system\n")
2147{
2148 execute_command ("telnet", 1, argv[0], NULL);
2149 return CMD_SUCCESS;
2150}
2151
2152DEFUN (vtysh_telnet_port,
2153 vtysh_telnet_port_cmd,
2154 "telnet WORD PORT",
2155 "Open a telnet connection\n"
2156 "IP address or hostname of a remote system\n"
2157 "TCP Port number\n")
2158{
2159 execute_command ("telnet", 2, argv[0], argv[1]);
2160 return CMD_SUCCESS;
2161}
2162
paul5087df52003-01-25 06:56:09 +00002163DEFUN (vtysh_ssh,
2164 vtysh_ssh_cmd,
2165 "ssh WORD",
2166 "Open an ssh connection\n"
2167 "[user@]host\n")
2168{
2169 execute_command ("ssh", 1, argv[0], NULL);
2170 return CMD_SUCCESS;
2171}
2172
paul718e3742002-12-13 20:15:29 +00002173DEFUN (vtysh_start_shell,
2174 vtysh_start_shell_cmd,
2175 "start-shell",
2176 "Start UNIX shell\n")
2177{
2178 execute_command ("sh", 0, NULL, NULL);
2179 return CMD_SUCCESS;
2180}
2181
2182DEFUN (vtysh_start_bash,
2183 vtysh_start_bash_cmd,
2184 "start-shell bash",
2185 "Start UNIX shell\n"
2186 "Start bash\n")
2187{
2188 execute_command ("bash", 0, NULL, NULL);
2189 return CMD_SUCCESS;
2190}
2191
2192DEFUN (vtysh_start_zsh,
2193 vtysh_start_zsh_cmd,
2194 "start-shell zsh",
2195 "Start UNIX shell\n"
2196 "Start Z shell\n")
2197{
2198 execute_command ("zsh", 0, NULL, NULL);
2199 return CMD_SUCCESS;
2200}
hassob094d262004-08-25 12:22:00 +00002201
ajs274a4a42004-12-07 15:39:31 +00002202static void
paul718e3742002-12-13 20:15:29 +00002203vtysh_install_default (enum node_type node)
2204{
2205 install_element (node, &config_list_cmd);
2206}
2207
2208/* Making connection to protocol daemon. */
ajs274a4a42004-12-07 15:39:31 +00002209static int
ajsb1aa1472005-01-28 21:11:46 +00002210vtysh_connect (struct vtysh_client *vclient)
paul718e3742002-12-13 20:15:29 +00002211{
2212 int ret;
2213 int sock, len;
2214 struct sockaddr_un addr;
2215 struct stat s_stat;
paul718e3742002-12-13 20:15:29 +00002216
paul718e3742002-12-13 20:15:29 +00002217 /* Stat socket to see if we have permission to access it. */
ajsb1aa1472005-01-28 21:11:46 +00002218 ret = stat (vclient->path, &s_stat);
paul718e3742002-12-13 20:15:29 +00002219 if (ret < 0 && errno != ENOENT)
2220 {
2221 fprintf (stderr, "vtysh_connect(%s): stat = %s\n",
ajsb1aa1472005-01-28 21:11:46 +00002222 vclient->path, safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002223 exit(1);
2224 }
2225
2226 if (ret >= 0)
2227 {
2228 if (! S_ISSOCK(s_stat.st_mode))
2229 {
2230 fprintf (stderr, "vtysh_connect(%s): Not a socket\n",
ajsb1aa1472005-01-28 21:11:46 +00002231 vclient->path);
paul718e3742002-12-13 20:15:29 +00002232 exit (1);
2233 }
2234
paul718e3742002-12-13 20:15:29 +00002235 }
2236
2237 sock = socket (AF_UNIX, SOCK_STREAM, 0);
2238 if (sock < 0)
2239 {
2240#ifdef DEBUG
ajsb1aa1472005-01-28 21:11:46 +00002241 fprintf(stderr, "vtysh_connect(%s): socket = %s\n", vclient->path,
ajs6099b3b2004-11-20 02:06:59 +00002242 safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002243#endif /* DEBUG */
2244 return -1;
2245 }
2246
2247 memset (&addr, 0, sizeof (struct sockaddr_un));
2248 addr.sun_family = AF_UNIX;
ajsb1aa1472005-01-28 21:11:46 +00002249 strncpy (addr.sun_path, vclient->path, strlen (vclient->path));
Paul Jakma6f0e3f62007-05-10 02:38:51 +00002250#ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
paul718e3742002-12-13 20:15:29 +00002251 len = addr.sun_len = SUN_LEN(&addr);
2252#else
2253 len = sizeof (addr.sun_family) + strlen (addr.sun_path);
Paul Jakma6f0e3f62007-05-10 02:38:51 +00002254#endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
paul718e3742002-12-13 20:15:29 +00002255
2256 ret = connect (sock, (struct sockaddr *) &addr, len);
2257 if (ret < 0)
2258 {
2259#ifdef DEBUG
ajsb1aa1472005-01-28 21:11:46 +00002260 fprintf(stderr, "vtysh_connect(%s): connect = %s\n", vclient->path,
ajs6099b3b2004-11-20 02:06:59 +00002261 safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002262#endif /* DEBUG */
2263 close (sock);
2264 return -1;
2265 }
2266 vclient->fd = sock;
2267
2268 return 0;
2269}
2270
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002271int
2272vtysh_connect_all(const char *daemon_name)
paul718e3742002-12-13 20:15:29 +00002273{
ajsb1aa1472005-01-28 21:11:46 +00002274 u_int i;
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002275 int rc = 0;
2276 int matches = 0;
ajsb1aa1472005-01-28 21:11:46 +00002277
Balaji.G837d16c2012-09-26 14:09:10 +05302278 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00002279 {
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002280 if (!daemon_name || !strcmp(daemon_name, vtysh_client[i].name))
2281 {
2282 matches++;
2283 if (vtysh_connect(&vtysh_client[i]) == 0)
2284 rc++;
2285 /* We need direct access to ripd in vtysh_exit_ripd_only. */
2286 if (vtysh_client[i].flag == VTYSH_RIPD)
2287 ripd_client = &vtysh_client[i];
2288 }
ajsb1aa1472005-01-28 21:11:46 +00002289 }
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002290 if (!matches)
2291 fprintf(stderr, "Error: no daemons match name %s!\n", daemon_name);
2292 return rc;
paul718e3742002-12-13 20:15:29 +00002293}
2294
hasso95e735b2004-08-26 13:08:30 +00002295/* To disable readline's filename completion. */
ajs274a4a42004-12-07 15:39:31 +00002296static char *
pauldfc0d9b2003-04-18 23:55:29 +00002297vtysh_completion_entry_function (const char *ignore, int invoking_key)
paul718e3742002-12-13 20:15:29 +00002298{
pauldfc0d9b2003-04-18 23:55:29 +00002299 return NULL;
paul718e3742002-12-13 20:15:29 +00002300}
2301
2302void
ajsb1aa1472005-01-28 21:11:46 +00002303vtysh_readline_init (void)
paul718e3742002-12-13 20:15:29 +00002304{
2305 /* readline related settings. */
Sébastien Luttringer66d2ead2014-05-27 19:55:11 +02002306 rl_bind_key ('?', (rl_command_func_t *) vtysh_rl_describe);
paul68980082003-03-25 05:07:42 +00002307 rl_completion_entry_function = vtysh_completion_entry_function;
Sébastien Luttringer66d2ead2014-05-27 19:55:11 +02002308 rl_attempted_completion_function = (rl_completion_func_t *)new_completion;
paul718e3742002-12-13 20:15:29 +00002309}
2310
2311char *
ajsb1aa1472005-01-28 21:11:46 +00002312vtysh_prompt (void)
paul718e3742002-12-13 20:15:29 +00002313{
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002314 static struct utsname names;
paul718e3742002-12-13 20:15:29 +00002315 static char buf[100];
2316 const char*hostname;
2317 extern struct host host;
2318
2319 hostname = host.name;
2320
2321 if (!hostname)
2322 {
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002323 if (!names.nodename[0])
2324 uname (&names);
paul718e3742002-12-13 20:15:29 +00002325 hostname = names.nodename;
2326 }
2327
2328 snprintf (buf, sizeof buf, cmd_prompt (vty->node), hostname);
2329
2330 return buf;
2331}
2332
2333void
ajsb1aa1472005-01-28 21:11:46 +00002334vtysh_init_vty (void)
paul718e3742002-12-13 20:15:29 +00002335{
2336 /* Make vty structure. */
2337 vty = vty_new ();
2338 vty->type = VTY_SHELL;
2339 vty->node = VIEW_NODE;
2340
2341 /* Initialize commands. */
2342 cmd_init (0);
2343
2344 /* Install nodes. */
2345 install_node (&bgp_node, NULL);
2346 install_node (&rip_node, NULL);
2347 install_node (&interface_node, NULL);
2348 install_node (&rmap_node, NULL);
2349 install_node (&zebra_node, NULL);
2350 install_node (&bgp_vpnv4_node, NULL);
2351 install_node (&bgp_ipv4_node, NULL);
2352 install_node (&bgp_ipv4m_node, NULL);
2353/* #ifdef HAVE_IPV6 */
2354 install_node (&bgp_ipv6_node, NULL);
paul57b5b7e2005-08-22 22:44:29 +00002355 install_node (&bgp_ipv6m_node, NULL);
paul718e3742002-12-13 20:15:29 +00002356/* #endif */
2357 install_node (&ospf_node, NULL);
2358/* #ifdef HAVE_IPV6 */
2359 install_node (&ripng_node, NULL);
2360 install_node (&ospf6_node, NULL);
2361/* #endif */
David Lamparteree53c8b2015-05-23 05:45:59 +02002362 install_node (&babel_node, NULL);
paul718e3742002-12-13 20:15:29 +00002363 install_node (&keychain_node, NULL);
2364 install_node (&keychain_key_node, NULL);
hassoc25e4582003-12-23 10:39:08 +00002365 install_node (&isis_node, NULL);
hassoe7168df2004-10-03 20:11:32 +00002366 install_node (&vty_node, NULL);
paul718e3742002-12-13 20:15:29 +00002367
2368 vtysh_install_default (VIEW_NODE);
2369 vtysh_install_default (ENABLE_NODE);
2370 vtysh_install_default (CONFIG_NODE);
2371 vtysh_install_default (BGP_NODE);
2372 vtysh_install_default (RIP_NODE);
2373 vtysh_install_default (INTERFACE_NODE);
2374 vtysh_install_default (RMAP_NODE);
2375 vtysh_install_default (ZEBRA_NODE);
2376 vtysh_install_default (BGP_VPNV4_NODE);
2377 vtysh_install_default (BGP_IPV4_NODE);
2378 vtysh_install_default (BGP_IPV4M_NODE);
2379 vtysh_install_default (BGP_IPV6_NODE);
paul57b5b7e2005-08-22 22:44:29 +00002380 vtysh_install_default (BGP_IPV6M_NODE);
paul718e3742002-12-13 20:15:29 +00002381 vtysh_install_default (OSPF_NODE);
2382 vtysh_install_default (RIPNG_NODE);
2383 vtysh_install_default (OSPF6_NODE);
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +01002384 vtysh_install_default (BABEL_NODE);
hassoc25e4582003-12-23 10:39:08 +00002385 vtysh_install_default (ISIS_NODE);
paul718e3742002-12-13 20:15:29 +00002386 vtysh_install_default (KEYCHAIN_NODE);
2387 vtysh_install_default (KEYCHAIN_KEY_NODE);
hassoe7168df2004-10-03 20:11:32 +00002388 vtysh_install_default (VTY_NODE);
paul718e3742002-12-13 20:15:29 +00002389
2390 install_element (VIEW_NODE, &vtysh_enable_cmd);
2391 install_element (ENABLE_NODE, &vtysh_config_terminal_cmd);
2392 install_element (ENABLE_NODE, &vtysh_disable_cmd);
2393
2394 /* "exit" command. */
2395 install_element (VIEW_NODE, &vtysh_exit_all_cmd);
2396 install_element (VIEW_NODE, &vtysh_quit_all_cmd);
2397 install_element (CONFIG_NODE, &vtysh_exit_all_cmd);
2398 /* install_element (CONFIG_NODE, &vtysh_quit_all_cmd); */
2399 install_element (ENABLE_NODE, &vtysh_exit_all_cmd);
2400 install_element (ENABLE_NODE, &vtysh_quit_all_cmd);
2401 install_element (RIP_NODE, &vtysh_exit_ripd_cmd);
2402 install_element (RIP_NODE, &vtysh_quit_ripd_cmd);
paul68980082003-03-25 05:07:42 +00002403 install_element (RIPNG_NODE, &vtysh_exit_ripngd_cmd);
2404 install_element (RIPNG_NODE, &vtysh_quit_ripngd_cmd);
paul718e3742002-12-13 20:15:29 +00002405 install_element (OSPF_NODE, &vtysh_exit_ospfd_cmd);
2406 install_element (OSPF_NODE, &vtysh_quit_ospfd_cmd);
paul68980082003-03-25 05:07:42 +00002407 install_element (OSPF6_NODE, &vtysh_exit_ospf6d_cmd);
2408 install_element (OSPF6_NODE, &vtysh_quit_ospf6d_cmd);
paul718e3742002-12-13 20:15:29 +00002409 install_element (BGP_NODE, &vtysh_exit_bgpd_cmd);
2410 install_element (BGP_NODE, &vtysh_quit_bgpd_cmd);
2411 install_element (BGP_VPNV4_NODE, &vtysh_exit_bgpd_cmd);
2412 install_element (BGP_VPNV4_NODE, &vtysh_quit_bgpd_cmd);
2413 install_element (BGP_IPV4_NODE, &vtysh_exit_bgpd_cmd);
2414 install_element (BGP_IPV4_NODE, &vtysh_quit_bgpd_cmd);
2415 install_element (BGP_IPV4M_NODE, &vtysh_exit_bgpd_cmd);
2416 install_element (BGP_IPV4M_NODE, &vtysh_quit_bgpd_cmd);
2417 install_element (BGP_IPV6_NODE, &vtysh_exit_bgpd_cmd);
2418 install_element (BGP_IPV6_NODE, &vtysh_quit_bgpd_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002419 install_element (BGP_IPV6M_NODE, &vtysh_exit_bgpd_cmd);
2420 install_element (BGP_IPV6M_NODE, &vtysh_quit_bgpd_cmd);
hassoc25e4582003-12-23 10:39:08 +00002421 install_element (ISIS_NODE, &vtysh_exit_isisd_cmd);
2422 install_element (ISIS_NODE, &vtysh_quit_isisd_cmd);
paul718e3742002-12-13 20:15:29 +00002423 install_element (KEYCHAIN_NODE, &vtysh_exit_ripd_cmd);
2424 install_element (KEYCHAIN_NODE, &vtysh_quit_ripd_cmd);
2425 install_element (KEYCHAIN_KEY_NODE, &vtysh_exit_ripd_cmd);
2426 install_element (KEYCHAIN_KEY_NODE, &vtysh_quit_ripd_cmd);
2427 install_element (RMAP_NODE, &vtysh_exit_rmap_cmd);
2428 install_element (RMAP_NODE, &vtysh_quit_rmap_cmd);
hassoe7168df2004-10-03 20:11:32 +00002429 install_element (VTY_NODE, &vtysh_exit_line_vty_cmd);
2430 install_element (VTY_NODE, &vtysh_quit_line_vty_cmd);
paul718e3742002-12-13 20:15:29 +00002431
2432 /* "end" command. */
2433 install_element (CONFIG_NODE, &vtysh_end_all_cmd);
2434 install_element (ENABLE_NODE, &vtysh_end_all_cmd);
2435 install_element (RIP_NODE, &vtysh_end_all_cmd);
2436 install_element (RIPNG_NODE, &vtysh_end_all_cmd);
2437 install_element (OSPF_NODE, &vtysh_end_all_cmd);
2438 install_element (OSPF6_NODE, &vtysh_end_all_cmd);
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +01002439 install_element (BABEL_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002440 install_element (BGP_NODE, &vtysh_end_all_cmd);
2441 install_element (BGP_IPV4_NODE, &vtysh_end_all_cmd);
2442 install_element (BGP_IPV4M_NODE, &vtysh_end_all_cmd);
2443 install_element (BGP_VPNV4_NODE, &vtysh_end_all_cmd);
2444 install_element (BGP_IPV6_NODE, &vtysh_end_all_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002445 install_element (BGP_IPV6M_NODE, &vtysh_end_all_cmd);
hassoc25e4582003-12-23 10:39:08 +00002446 install_element (ISIS_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002447 install_element (KEYCHAIN_NODE, &vtysh_end_all_cmd);
2448 install_element (KEYCHAIN_KEY_NODE, &vtysh_end_all_cmd);
2449 install_element (RMAP_NODE, &vtysh_end_all_cmd);
hassoe7168df2004-10-03 20:11:32 +00002450 install_element (VTY_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002451
paul338a9912003-03-01 15:44:10 +00002452 install_element (INTERFACE_NODE, &interface_desc_cmd);
paul464dc8d2003-03-28 02:25:45 +00002453 install_element (INTERFACE_NODE, &no_interface_desc_cmd);
paul718e3742002-12-13 20:15:29 +00002454 install_element (INTERFACE_NODE, &vtysh_end_all_cmd);
2455 install_element (INTERFACE_NODE, &vtysh_exit_interface_cmd);
2456 install_element (INTERFACE_NODE, &vtysh_quit_interface_cmd);
2457 install_element (CONFIG_NODE, &router_rip_cmd);
2458#ifdef HAVE_IPV6
2459 install_element (CONFIG_NODE, &router_ripng_cmd);
2460#endif
2461 install_element (CONFIG_NODE, &router_ospf_cmd);
2462#ifdef HAVE_IPV6
2463 install_element (CONFIG_NODE, &router_ospf6_cmd);
2464#endif
hassoc25e4582003-12-23 10:39:08 +00002465 install_element (CONFIG_NODE, &router_isis_cmd);
paul718e3742002-12-13 20:15:29 +00002466 install_element (CONFIG_NODE, &router_bgp_cmd);
Paul Jakma10895fd2008-07-03 19:34:48 +00002467 install_element (CONFIG_NODE, &router_bgp_view_cmd);
paul718e3742002-12-13 20:15:29 +00002468 install_element (BGP_NODE, &address_family_vpnv4_cmd);
2469 install_element (BGP_NODE, &address_family_vpnv4_unicast_cmd);
2470 install_element (BGP_NODE, &address_family_ipv4_unicast_cmd);
2471 install_element (BGP_NODE, &address_family_ipv4_multicast_cmd);
2472#ifdef HAVE_IPV6
2473 install_element (BGP_NODE, &address_family_ipv6_cmd);
2474 install_element (BGP_NODE, &address_family_ipv6_unicast_cmd);
2475#endif
2476 install_element (BGP_VPNV4_NODE, &exit_address_family_cmd);
2477 install_element (BGP_IPV4_NODE, &exit_address_family_cmd);
2478 install_element (BGP_IPV4M_NODE, &exit_address_family_cmd);
2479 install_element (BGP_IPV6_NODE, &exit_address_family_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002480 install_element (BGP_IPV6M_NODE, &exit_address_family_cmd);
paul718e3742002-12-13 20:15:29 +00002481 install_element (CONFIG_NODE, &key_chain_cmd);
2482 install_element (CONFIG_NODE, &route_map_cmd);
hassoe7168df2004-10-03 20:11:32 +00002483 install_element (CONFIG_NODE, &vtysh_line_vty_cmd);
paul718e3742002-12-13 20:15:29 +00002484 install_element (KEYCHAIN_NODE, &key_cmd);
2485 install_element (KEYCHAIN_NODE, &key_chain_cmd);
2486 install_element (KEYCHAIN_KEY_NODE, &key_chain_cmd);
2487 install_element (CONFIG_NODE, &vtysh_interface_cmd);
paul32d24632003-05-23 09:25:20 +00002488 install_element (CONFIG_NODE, &vtysh_no_interface_cmd);
Feng Lu471ea392015-05-22 11:40:00 +02002489 install_element (CONFIG_NODE, &vtysh_interface_vrf_cmd);
2490 install_element (CONFIG_NODE, &vtysh_no_interface_vrf_cmd);
paul718e3742002-12-13 20:15:29 +00002491 install_element (ENABLE_NODE, &vtysh_show_running_config_cmd);
Donald Sharp9fb73e82015-09-22 11:13:12 -04002492 install_element (ENABLE_NODE, &vtysh_show_running_config_daemon_cmd);
paul718e3742002-12-13 20:15:29 +00002493 install_element (ENABLE_NODE, &vtysh_copy_runningconfig_startupconfig_cmd);
2494 install_element (ENABLE_NODE, &vtysh_write_file_cmd);
hasso4a6e2252003-05-25 11:51:29 +00002495 install_element (ENABLE_NODE, &vtysh_write_cmd);
paul718e3742002-12-13 20:15:29 +00002496
hasso95e735b2004-08-26 13:08:30 +00002497 /* "write terminal" command. */
paul718e3742002-12-13 20:15:29 +00002498 install_element (ENABLE_NODE, &vtysh_write_terminal_cmd);
Donald Sharp9fb73e82015-09-22 11:13:12 -04002499 install_element (ENABLE_NODE, &vtysh_write_terminal_daemon_cmd);
hassoe7168df2004-10-03 20:11:32 +00002500
2501 install_element (CONFIG_NODE, &vtysh_integrated_config_cmd);
2502 install_element (CONFIG_NODE, &no_vtysh_integrated_config_cmd);
paul718e3742002-12-13 20:15:29 +00002503
hasso95e735b2004-08-26 13:08:30 +00002504 /* "write memory" command. */
paul718e3742002-12-13 20:15:29 +00002505 install_element (ENABLE_NODE, &vtysh_write_memory_cmd);
paul718e3742002-12-13 20:15:29 +00002506
hasso34553cc2004-08-27 13:56:39 +00002507 install_element (VIEW_NODE, &vtysh_terminal_length_cmd);
2508 install_element (ENABLE_NODE, &vtysh_terminal_length_cmd);
2509 install_element (VIEW_NODE, &vtysh_terminal_no_length_cmd);
2510 install_element (ENABLE_NODE, &vtysh_terminal_no_length_cmd);
hassof2799e62004-10-28 17:43:11 +00002511 install_element (VIEW_NODE, &vtysh_show_daemons_cmd);
2512 install_element (ENABLE_NODE, &vtysh_show_daemons_cmd);
hasso34553cc2004-08-27 13:56:39 +00002513
paul718e3742002-12-13 20:15:29 +00002514 install_element (VIEW_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002515 install_element (VIEW_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00002516 install_element (VIEW_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002517 install_element (VIEW_NODE, &vtysh_traceroute_ip_cmd);
2518#ifdef HAVE_IPV6
2519 install_element (VIEW_NODE, &vtysh_ping6_cmd);
2520 install_element (VIEW_NODE, &vtysh_traceroute6_cmd);
2521#endif
paul718e3742002-12-13 20:15:29 +00002522 install_element (VIEW_NODE, &vtysh_telnet_cmd);
2523 install_element (VIEW_NODE, &vtysh_telnet_port_cmd);
paul5087df52003-01-25 06:56:09 +00002524 install_element (VIEW_NODE, &vtysh_ssh_cmd);
paul718e3742002-12-13 20:15:29 +00002525 install_element (ENABLE_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002526 install_element (ENABLE_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00002527 install_element (ENABLE_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002528 install_element (ENABLE_NODE, &vtysh_traceroute_ip_cmd);
2529#ifdef HAVE_IPV6
2530 install_element (ENABLE_NODE, &vtysh_ping6_cmd);
2531 install_element (ENABLE_NODE, &vtysh_traceroute6_cmd);
2532#endif
paul718e3742002-12-13 20:15:29 +00002533 install_element (ENABLE_NODE, &vtysh_telnet_cmd);
2534 install_element (ENABLE_NODE, &vtysh_telnet_port_cmd);
hasso67e29ab2004-08-26 22:21:31 +00002535 install_element (ENABLE_NODE, &vtysh_ssh_cmd);
paul718e3742002-12-13 20:15:29 +00002536 install_element (ENABLE_NODE, &vtysh_start_shell_cmd);
2537 install_element (ENABLE_NODE, &vtysh_start_bash_cmd);
2538 install_element (ENABLE_NODE, &vtysh_start_zsh_cmd);
Paul Jakmadbf7d132006-05-23 22:10:01 +00002539
Paul Jakma362b4032006-05-28 07:54:45 +00002540 install_element (VIEW_NODE, &vtysh_show_memory_cmd);
2541 install_element (ENABLE_NODE, &vtysh_show_memory_cmd);
2542
Donald Sharp567a6382015-08-19 21:22:17 -04002543 install_element (VIEW_NODE, &vtysh_show_work_queues_cmd);
2544 install_element (ENABLE_NODE, &vtysh_show_work_queues_cmd);
2545
2546 install_element (VIEW_NODE, &vtysh_show_thread_cmd);
2547 install_element (ENABLE_NODE, &vtysh_show_thread_cmd);
2548
Paul Jakmadbf7d132006-05-23 22:10:01 +00002549 /* Logging */
2550 install_element (ENABLE_NODE, &vtysh_show_logging_cmd);
2551 install_element (VIEW_NODE, &vtysh_show_logging_cmd);
paul718e3742002-12-13 20:15:29 +00002552 install_element (CONFIG_NODE, &vtysh_log_stdout_cmd);
ajs274a4a42004-12-07 15:39:31 +00002553 install_element (CONFIG_NODE, &vtysh_log_stdout_level_cmd);
paul718e3742002-12-13 20:15:29 +00002554 install_element (CONFIG_NODE, &no_vtysh_log_stdout_cmd);
2555 install_element (CONFIG_NODE, &vtysh_log_file_cmd);
ajs274a4a42004-12-07 15:39:31 +00002556 install_element (CONFIG_NODE, &vtysh_log_file_level_cmd);
paul718e3742002-12-13 20:15:29 +00002557 install_element (CONFIG_NODE, &no_vtysh_log_file_cmd);
ajs274a4a42004-12-07 15:39:31 +00002558 install_element (CONFIG_NODE, &no_vtysh_log_file_level_cmd);
2559 install_element (CONFIG_NODE, &vtysh_log_monitor_cmd);
2560 install_element (CONFIG_NODE, &vtysh_log_monitor_level_cmd);
2561 install_element (CONFIG_NODE, &no_vtysh_log_monitor_cmd);
paul718e3742002-12-13 20:15:29 +00002562 install_element (CONFIG_NODE, &vtysh_log_syslog_cmd);
ajs274a4a42004-12-07 15:39:31 +00002563 install_element (CONFIG_NODE, &vtysh_log_syslog_level_cmd);
paul718e3742002-12-13 20:15:29 +00002564 install_element (CONFIG_NODE, &no_vtysh_log_syslog_cmd);
2565 install_element (CONFIG_NODE, &vtysh_log_trap_cmd);
2566 install_element (CONFIG_NODE, &no_vtysh_log_trap_cmd);
ajs274a4a42004-12-07 15:39:31 +00002567 install_element (CONFIG_NODE, &vtysh_log_facility_cmd);
2568 install_element (CONFIG_NODE, &no_vtysh_log_facility_cmd);
paul718e3742002-12-13 20:15:29 +00002569 install_element (CONFIG_NODE, &vtysh_log_record_priority_cmd);
2570 install_element (CONFIG_NODE, &no_vtysh_log_record_priority_cmd);
Andrew J. Schorrc749b722007-04-29 03:53:31 +00002571 install_element (CONFIG_NODE, &vtysh_log_timestamp_precision_cmd);
2572 install_element (CONFIG_NODE, &no_vtysh_log_timestamp_precision_cmd);
hassoe7168df2004-10-03 20:11:32 +00002573
2574 install_element (CONFIG_NODE, &vtysh_service_password_encrypt_cmd);
2575 install_element (CONFIG_NODE, &no_vtysh_service_password_encrypt_cmd);
2576
2577 install_element (CONFIG_NODE, &vtysh_password_cmd);
2578 install_element (CONFIG_NODE, &vtysh_password_text_cmd);
2579 install_element (CONFIG_NODE, &vtysh_enable_password_cmd);
2580 install_element (CONFIG_NODE, &vtysh_enable_password_text_cmd);
2581 install_element (CONFIG_NODE, &no_vtysh_enable_password_cmd);
2582
paul718e3742002-12-13 20:15:29 +00002583}