]> git.proxmox.com Git - mirror_frr.git/blame - vtysh/vtysh.c
[bgpd] Merge AS4 support
[mirror_frr.git] / vtysh / vtysh.c
CommitLineData
718e3744 1/* 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"
6099b3b5 36#include "log.h"
718e3744 37
38/* Struct VTY. */
39struct vty *vty;
40
41/* VTY shell pager name. */
42char *vtysh_pager_name = NULL;
43
44/* VTY shell client structure. */
45struct vtysh_client
46{
47 int fd;
b1aa147d 48 const char *name;
49 int flag;
50 const char *path;
51} vtysh_client[] =
52{
53 { .fd = -1, .name = "zebra", .flag = VTYSH_ZEBRA, .path = ZEBRA_VTYSH_PATH},
54 { .fd = -1, .name = "ripd", .flag = VTYSH_RIPD, .path = RIP_VTYSH_PATH},
55 { .fd = -1, .name = "ripngd", .flag = VTYSH_RIPNGD, .path = RIPNG_VTYSH_PATH},
56 { .fd = -1, .name = "ospfd", .flag = VTYSH_OSPFD, .path = OSPF_VTYSH_PATH},
57 { .fd = -1, .name = "ospf6d", .flag = VTYSH_OSPF6D, .path = OSPF6_VTYSH_PATH},
58 { .fd = -1, .name = "bgpd", .flag = VTYSH_BGPD, .path = BGP_VTYSH_PATH},
59 { .fd = -1, .name = "isisd", .flag = VTYSH_ISISD, .path = ISIS_VTYSH_PATH},
60};
61
62#define VTYSH_INDEX_MAX (sizeof(vtysh_client)/sizeof(vtysh_client[0]))
63
64/* We need direct access to ripd to implement vtysh_exit_ripd_only. */
65static struct vtysh_client *ripd_client = NULL;
66
b094d260 67
e7168df4 68/* Using integrated config from Quagga.conf. Default is no. */
69int vtysh_writeconfig_integrated = 0;
70
71extern char config_default[];
72
274a4a44 73static void
718e3744 74vclient_close (struct vtysh_client *vclient)
75{
b1aa147d 76 if (vclient->fd >= 0)
77 {
78 fprintf(stderr,
79 "Warning: closing connection to %s because of an I/O error!\n",
80 vclient->name);
81 close (vclient->fd);
82 vclient->fd = -1;
83 }
718e3744 84}
85
718e3744 86/* Following filled with debug code to trace a problematic condition
95e735b5 87 * under load - it SHOULD handle it. */
718e3744 88#define ERR_WHERE_STRING "vtysh(): vtysh_client_config(): "
274a4a44 89static int
718e3744 90vtysh_client_config (struct vtysh_client *vclient, char *line)
91{
92 int ret;
93 char *buf;
94 size_t bufsz;
95 char *pbuf;
96 size_t left;
97 char *eoln;
98 int nbytes;
99 int i;
100 int readln;
101
102 if (vclient->fd < 0)
103 return CMD_SUCCESS;
104
105 ret = write (vclient->fd, line, strlen (line) + 1);
106 if (ret <= 0)
107 {
108 vclient_close (vclient);
109 return CMD_SUCCESS;
110 }
111
95e735b5 112 /* Allow enough room for buffer to read more than a few pages from socket. */
e3d29b5f 113 bufsz = 5 * getpagesize() + 1;
718e3744 114 buf = XMALLOC(MTYPE_TMP, bufsz);
115 memset(buf, 0, bufsz);
116 pbuf = buf;
117
118 while (1)
119 {
120 if (pbuf >= ((buf + bufsz) -1))
121 {
122 fprintf (stderr, ERR_WHERE_STRING \
123 "warning - pbuf beyond buffer end.\n");
124 return CMD_WARNING;
125 }
126
127 readln = (buf + bufsz) - pbuf - 1;
128 nbytes = read (vclient->fd, pbuf, readln);
129
130 if (nbytes <= 0)
131 {
132
133 if (errno == EINTR)
134 continue;
135
136 fprintf(stderr, ERR_WHERE_STRING "(%u)", errno);
137 perror("");
138
139 if (errno == EAGAIN || errno == EIO)
140 continue;
141
142 vclient_close (vclient);
143 XFREE(MTYPE_TMP, buf);
144 return CMD_SUCCESS;
145 }
146
147 pbuf[nbytes] = '\0';
148
149 if (nbytes >= 4)
150 {
151 i = nbytes - 4;
152 if (pbuf[i] == '\0' && pbuf[i + 1] == '\0' && pbuf[i + 2] == '\0')
153 {
154 ret = pbuf[i + 3];
155 break;
156 }
157 }
158 pbuf += nbytes;
159
160 /* See if a line exists in buffer, if so parse and consume it, and
95e735b5 161 * reset read position. */
718e3744 162 if ((eoln = strrchr(buf, '\n')) == NULL)
163 continue;
164
165 if (eoln >= ((buf + bufsz) - 1))
166 {
167 fprintf (stderr, ERR_WHERE_STRING \
168 "warning - eoln beyond buffer end.\n");
169 }
170 vtysh_config_parse(buf);
171
172 eoln++;
173 left = (size_t)(buf + bufsz - eoln);
174 memmove(buf, eoln, left);
175 buf[bufsz-1] = '\0';
176 pbuf = buf + strlen(buf);
177 }
178
95e735b5 179 /* Parse anything left in the buffer. */
e7168df4 180
718e3744 181 vtysh_config_parse (buf);
182
183 XFREE(MTYPE_TMP, buf);
184 return ret;
185}
186
274a4a44 187static int
dda09522 188vtysh_client_execute (struct vtysh_client *vclient, const char *line, FILE *fp)
718e3744 189{
190 int ret;
191 char buf[1001];
192 int nbytes;
2852de1c 193 int i;
194 int numnulls = 0;
718e3744 195
196 if (vclient->fd < 0)
197 return CMD_SUCCESS;
198
199 ret = write (vclient->fd, line, strlen (line) + 1);
200 if (ret <= 0)
201 {
202 vclient_close (vclient);
203 return CMD_SUCCESS;
204 }
205
206 while (1)
207 {
208 nbytes = read (vclient->fd, buf, sizeof(buf)-1);
209
210 if (nbytes <= 0 && errno != EINTR)
211 {
212 vclient_close (vclient);
213 return CMD_SUCCESS;
214 }
215
216 if (nbytes > 0)
217 {
85fb1e6d 218 if ((numnulls == 3) && (nbytes == 1))
219 return buf[0];
220
718e3744 221 buf[nbytes] = '\0';
85fb1e6d 222 fputs (buf, fp);
718e3744 223 fflush (fp);
2852de1c 224
0921d48e 225 /* check for trailling \0\0\0<ret code>,
226 * even if split across reads
227 * (see lib/vty.c::vtysh_read)
228 */
2852de1c 229 if (nbytes >= 4)
230 {
231 i = nbytes-4;
232 numnulls = 0;
233 }
234 else
235 i = 0;
236
0921d48e 237 while (i < nbytes && numnulls < 3)
2852de1c 238 {
239 if (buf[i++] == '\0')
240 numnulls++;
241 else
85fb1e6d 242 numnulls = 0;
2852de1c 243 }
244
85fb1e6d 245 /* got 3 or more trailing NULs? */
246 if ((numnulls >= 3) && (i < nbytes))
0921d48e 247 return (buf[nbytes-1]);
718e3744 248 }
249 }
718e3744 250}
251
252void
b1aa147d 253vtysh_exit_ripd_only (void)
718e3744 254{
b1aa147d 255 if (ripd_client)
256 vtysh_client_execute (ripd_client, "exit", stdout);
718e3744 257}
258
259
260void
b1aa147d 261vtysh_pager_init (void)
718e3744 262{
5a9c53de 263 char *pager_defined;
264
265 pager_defined = getenv ("VTYSH_PAGER");
266
267 if (pager_defined)
268 vtysh_pager_name = strdup (pager_defined);
269 else
34553cc3 270 vtysh_pager_name = strdup ("more");
718e3744 271}
272
273/* Command execution over the vty interface. */
274a4a44 274static void
dda09522 275vtysh_execute_func (const char *line, int pager)
718e3744 276{
277 int ret, cmd_stat;
b1aa147d 278 u_int i;
718e3744 279 vector vline;
280 struct cmd_element *cmd;
281 FILE *fp = NULL;
13bfca7a 282 int closepager = 0;
283 int tried = 0;
284 int saved_ret, saved_node;
718e3744 285
95e735b5 286 /* Split readline string up into the vector. */
718e3744 287 vline = cmd_make_strvec (line);
288
289 if (vline == NULL)
290 return;
291
13bfca7a 292 saved_ret = ret = cmd_execute_command (vline, vty, &cmd, 1);
293 saved_node = vty->node;
294
295 /* If command doesn't succeeded in current node, try to walk up in node tree.
296 * Changing vty->node is enough to try it just out without actual walkup in
297 * the vtysh. */
298 while (ret != CMD_SUCCESS && ret != CMD_SUCCESS_DAEMON && ret != CMD_WARNING
299 && vty->node > CONFIG_NODE)
300 {
301 vty->node = node_parent(vty->node);
302 ret = cmd_execute_command (vline, vty, &cmd, 1);
303 tried++;
304 }
305
306 vty->node = saved_node;
307
308 /* If command succeeded in any other node than current (tried > 0) we have
309 * to move into node in the vtysh where it succeeded. */
310 if (ret == CMD_SUCCESS || ret == CMD_SUCCESS_DAEMON || ret == CMD_WARNING)
311 {
312 if ((saved_node == BGP_VPNV4_NODE || saved_node == BGP_IPV4_NODE
57b5b7ed 313 || saved_node == BGP_IPV6_NODE || saved_node == BGP_IPV4M_NODE
314 || saved_node == BGP_IPV6M_NODE)
13bfca7a 315 && (tried == 1))
316 {
317 vtysh_execute("exit-address-family");
318 }
319 else if ((saved_node == KEYCHAIN_KEY_NODE) && (tried == 1))
320 {
321 vtysh_execute("exit");
322 }
323 else if (tried)
324 {
325 vtysh_execute ("end");
326 vtysh_execute ("configure terminal");
327 }
328 }
329 /* If command didn't succeed in any node, continue with return value from
330 * first try. */
331 else if (tried)
332 {
333 ret = saved_ret;
334 }
718e3744 335
336 cmd_free_strvec (vline);
337
338 switch (ret)
339 {
340 case CMD_WARNING:
341 if (vty->type == VTY_FILE)
4fc01e67 342 fprintf (stdout,"Warning...\n");
718e3744 343 break;
344 case CMD_ERR_AMBIGUOUS:
4fc01e67 345 fprintf (stdout,"%% Ambiguous command.\n");
718e3744 346 break;
347 case CMD_ERR_NO_MATCH:
4fc01e67 348 fprintf (stdout,"%% Unknown command.\n");
718e3744 349 break;
350 case CMD_ERR_INCOMPLETE:
4fc01e67 351 fprintf (stdout,"%% Command incomplete.\n");
718e3744 352 break;
353 case CMD_SUCCESS_DAEMON:
354 {
97b7db2d 355 /* FIXME: Don't open pager for exit commands. popen() causes problems
356 * if exited from vtysh at all. This hack shouldn't cause any problem
357 * but is really ugly. */
358 if (pager && vtysh_pager_name && (strncmp(line, "exit", 4) != 0))
718e3744 359 {
4fc01e67 360 fp = popen (vtysh_pager_name, "w");
718e3744 361 if (fp == NULL)
362 {
a805cc2d 363 perror ("popen failed for pager");
364 fp = stdout;
718e3744 365 }
a805cc2d 366 else
367 closepager=1;
718e3744 368 }
369 else
370 fp = stdout;
371
372 if (! strcmp(cmd->string,"configure terminal"))
373 {
b1aa147d 374 for (i = 0; i < VTYSH_INDEX_MAX; i++)
375 {
376 cmd_stat = vtysh_client_execute(&vtysh_client[i], line, fp);
377 if (cmd_stat == CMD_WARNING)
378 break;
379 }
380
718e3744 381 if (cmd_stat)
382 {
b094d260 383 line = "end";
384 vline = cmd_make_strvec (line);
718e3744 385
b094d260 386 if (vline == NULL)
718e3744 387 {
a805cc2d 388 if (pager && vtysh_pager_name && fp && closepager)
718e3744 389 {
390 if (pclose (fp) == -1)
391 {
a805cc2d 392 perror ("pclose failed for pager");
718e3744 393 }
394 fp = NULL;
395 }
396 return;
397 }
398
87d683b0 399 ret = cmd_execute_command (vline, vty, &cmd, 1);
b094d260 400 cmd_free_strvec (vline);
401 if (ret != CMD_SUCCESS_DAEMON)
402 break;
718e3744 403 }
404 else
405 if (cmd->func)
406 {
407 (*cmd->func) (cmd, vty, 0, NULL);
408 break;
b094d260 409 }
718e3744 410 }
411
b1aa147d 412 cmd_stat = CMD_SUCCESS;
413 for (i = 0; i < VTYSH_INDEX_MAX; i++)
414 {
415 if (cmd->daemon & vtysh_client[i].flag)
416 {
417 cmd_stat = vtysh_client_execute(&vtysh_client[i], line, fp);
418 if (cmd_stat != CMD_SUCCESS)
419 break;
420 }
421 }
422 if (cmd_stat != CMD_SUCCESS)
423 break;
424
718e3744 425 if (cmd->func)
426 (*cmd->func) (cmd, vty, 0, NULL);
427 }
428 }
a805cc2d 429 if (pager && vtysh_pager_name && fp && closepager)
718e3744 430 {
431 if (pclose (fp) == -1)
432 {
a805cc2d 433 perror ("pclose failed for pager");
718e3744 434 }
435 fp = NULL;
436 }
437}
438
439void
dda09522 440vtysh_execute_no_pager (const char *line)
718e3744 441{
442 vtysh_execute_func (line, 0);
443}
444
445void
dda09522 446vtysh_execute (const char *line)
718e3744 447{
448 vtysh_execute_func (line, 1);
449}
450
451/* Configration make from file. */
452int
453vtysh_config_from_file (struct vty *vty, FILE *fp)
454{
455 int ret;
456 vector vline;
457 struct cmd_element *cmd;
458
459 while (fgets (vty->buf, VTY_BUFSIZ, fp))
460 {
461 if (vty->buf[0] == '!' || vty->buf[1] == '#')
462 continue;
463
464 vline = cmd_make_strvec (vty->buf);
465
95e735b5 466 /* In case of comment line. */
718e3744 467 if (vline == NULL)
468 continue;
469
95e735b5 470 /* Execute configuration command : this is strict match. */
718e3744 471 ret = cmd_execute_command_strict (vline, vty, &cmd);
472
95e735b5 473 /* Try again with setting node to CONFIG_NODE. */
718e3744 474 if (ret != CMD_SUCCESS
475 && ret != CMD_SUCCESS_DAEMON
476 && ret != CMD_WARNING)
477 {
478 if (vty->node == KEYCHAIN_KEY_NODE)
479 {
480 vty->node = KEYCHAIN_NODE;
481 vtysh_exit_ripd_only ();
482 ret = cmd_execute_command_strict (vline, vty, &cmd);
483
484 if (ret != CMD_SUCCESS
485 && ret != CMD_SUCCESS_DAEMON
486 && ret != CMD_WARNING)
487 {
488 vtysh_exit_ripd_only ();
489 vty->node = CONFIG_NODE;
490 ret = cmd_execute_command_strict (vline, vty, &cmd);
491 }
492 }
493 else
494 {
495 vtysh_execute ("end");
496 vtysh_execute ("configure terminal");
497 vty->node = CONFIG_NODE;
498 ret = cmd_execute_command_strict (vline, vty, &cmd);
499 }
500 }
501
502 cmd_free_strvec (vline);
503
504 switch (ret)
505 {
506 case CMD_WARNING:
507 if (vty->type == VTY_FILE)
4fc01e67 508 fprintf (stdout,"Warning...\n");
718e3744 509 break;
510 case CMD_ERR_AMBIGUOUS:
4fc01e67 511 fprintf (stdout,"%% Ambiguous command.\n");
718e3744 512 break;
513 case CMD_ERR_NO_MATCH:
4fc01e67 514 fprintf (stdout,"%% Unknown command: %s", vty->buf);
718e3744 515 break;
516 case CMD_ERR_INCOMPLETE:
4fc01e67 517 fprintf (stdout,"%% Command incomplete.\n");
718e3744 518 break;
519 case CMD_SUCCESS_DAEMON:
520 {
b1aa147d 521 u_int i;
522 int cmd_stat = CMD_SUCCESS;
523
524 for (i = 0; i < VTYSH_INDEX_MAX; i++)
525 {
44316fef 526 if (cmd->daemon & vtysh_client[i].flag)
b1aa147d 527 {
528 cmd_stat = vtysh_client_execute (&vtysh_client[i],
529 vty->buf, stdout);
530 if (cmd_stat != CMD_SUCCESS)
531 break;
532 }
533 }
534 if (cmd_stat != CMD_SUCCESS)
535 break;
536
718e3744 537 if (cmd->func)
538 (*cmd->func) (cmd, vty, 0, NULL);
539 }
540 }
541 }
542 return CMD_SUCCESS;
543}
544
545/* We don't care about the point of the cursor when '?' is typed. */
546int
b1aa147d 547vtysh_rl_describe (void)
718e3744 548{
549 int ret;
dda09522 550 unsigned int i;
718e3744 551 vector vline;
552 vector describe;
553 int width;
554 struct desc *desc;
555
556 vline = cmd_make_strvec (rl_line_buffer);
557
558 /* In case of '> ?'. */
559 if (vline == NULL)
560 {
561 vline = vector_init (1);
562 vector_set (vline, '\0');
563 }
564 else
565 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
566 vector_set (vline, '\0');
567
568 describe = cmd_describe_command (vline, vty, &ret);
569
4fc01e67 570 fprintf (stdout,"\n");
718e3744 571
572 /* Ambiguous and no match error. */
573 switch (ret)
574 {
575 case CMD_ERR_AMBIGUOUS:
576 cmd_free_strvec (vline);
4fc01e67 577 fprintf (stdout,"%% Ambiguous command.\n");
718e3744 578 rl_on_new_line ();
579 return 0;
580 break;
581 case CMD_ERR_NO_MATCH:
582 cmd_free_strvec (vline);
4fc01e67 583 fprintf (stdout,"%% There is no matched command.\n");
718e3744 584 rl_on_new_line ();
585 return 0;
586 break;
587 }
588
589 /* Get width of command string. */
590 width = 0;
55468c86 591 for (i = 0; i < vector_active (describe); i++)
718e3744 592 if ((desc = vector_slot (describe, i)) != NULL)
593 {
594 int len;
595
596 if (desc->cmd[0] == '\0')
597 continue;
598
599 len = strlen (desc->cmd);
600 if (desc->cmd[0] == '.')
601 len--;
602
603 if (width < len)
604 width = len;
605 }
606
55468c86 607 for (i = 0; i < vector_active (describe); i++)
718e3744 608 if ((desc = vector_slot (describe, i)) != NULL)
609 {
610 if (desc->cmd[0] == '\0')
611 continue;
612
613 if (! desc->str)
4fc01e67 614 fprintf (stdout," %-s\n",
b094d260 615 desc->cmd[0] == '.' ? desc->cmd + 1 : desc->cmd);
718e3744 616 else
4fc01e67 617 fprintf (stdout," %-*s %s\n",
b094d260 618 width,
619 desc->cmd[0] == '.' ? desc->cmd + 1 : desc->cmd,
620 desc->str);
718e3744 621 }
622
623 cmd_free_strvec (vline);
624 vector_free (describe);
625
626 rl_on_new_line();
627
628 return 0;
629}
630
95e735b5 631/* Result of cmd_complete_command() call will be stored here
632 * and used in new_completion() in order to put the space in
633 * correct places only. */
718e3744 634int complete_status;
635
274a4a44 636static char *
dfc0d9ba 637command_generator (const char *text, int state)
718e3744 638{
639 vector vline;
640 static char **matched = NULL;
641 static int index = 0;
642
643 /* First call. */
644 if (! state)
645 {
646 index = 0;
647
648 if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
649 return NULL;
650
651 vline = cmd_make_strvec (rl_line_buffer);
652 if (vline == NULL)
653 return NULL;
654
655 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
656 vector_set (vline, '\0');
657
658 matched = cmd_complete_command (vline, vty, &complete_status);
659 }
660
661 if (matched && matched[index])
662 return matched[index++];
663
664 return NULL;
665}
666
274a4a44 667static char **
718e3744 668new_completion (char *text, int start, int end)
669{
670 char **matches;
671
dfc0d9ba 672 matches = rl_completion_matches (text, command_generator);
718e3744 673
674 if (matches)
675 {
676 rl_point = rl_end;
677 if (complete_status == CMD_COMPLETE_FULL_MATCH)
678 rl_pending_input = ' ';
679 }
680
681 return matches;
682}
683
274a4a44 684#if 0
685/* This function is not actually being used. */
686static char **
718e3744 687vtysh_completion (char *text, int start, int end)
688{
689 int ret;
690 vector vline;
691 char **matched = NULL;
692
693 if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
694 return NULL;
695
696 vline = cmd_make_strvec (rl_line_buffer);
697 if (vline == NULL)
698 return NULL;
699
700 /* In case of 'help \t'. */
701 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
702 vector_set (vline, '\0');
703
704 matched = cmd_complete_command (vline, vty, &ret);
705
706 cmd_free_strvec (vline);
707
708 return (char **) matched;
709}
274a4a44 710#endif
718e3744 711
95e735b5 712/* Vty node structures. */
718e3744 713struct cmd_node bgp_node =
714{
715 BGP_NODE,
716 "%s(config-router)# ",
717};
718
718e3744 719struct cmd_node rip_node =
720{
721 RIP_NODE,
722 "%s(config-router)# ",
723};
724
c25e458a 725struct cmd_node isis_node =
726{
727 ISIS_NODE,
728 "%s(config-router)# ",
c25e458a 729};
730
718e3744 731struct cmd_node interface_node =
732{
733 INTERFACE_NODE,
734 "%s(config-if)# ",
735};
736
95e735b5 737struct cmd_node rmap_node =
738{
739 RMAP_NODE,
740 "%s(config-route-map)# "
741};
742
743struct cmd_node zebra_node =
744{
745 ZEBRA_NODE,
746 "%s(config-router)# "
747};
748
749struct cmd_node bgp_vpnv4_node =
750{
751 BGP_VPNV4_NODE,
752 "%s(config-router-af)# "
753};
754
755struct cmd_node bgp_ipv4_node =
756{
757 BGP_IPV4_NODE,
758 "%s(config-router-af)# "
759};
760
761struct cmd_node bgp_ipv4m_node =
762{
763 BGP_IPV4M_NODE,
764 "%s(config-router-af)# "
765};
766
767struct cmd_node bgp_ipv6_node =
768{
769 BGP_IPV6_NODE,
770 "%s(config-router-af)# "
771};
772
57b5b7ed 773struct cmd_node bgp_ipv6m_node =
774{
775 BGP_IPV6M_NODE,
776 "%s(config-router-af)# "
777};
778
95e735b5 779struct cmd_node ospf_node =
780{
781 OSPF_NODE,
782 "%s(config-router)# "
783};
784
785struct cmd_node ripng_node =
786{
787 RIPNG_NODE,
788 "%s(config-router)# "
789};
790
791struct cmd_node ospf6_node =
792{
793 OSPF6_NODE,
794 "%s(config-ospf6)# "
795};
796
797struct cmd_node keychain_node =
798{
799 KEYCHAIN_NODE,
800 "%s(config-keychain)# "
801};
802
803struct cmd_node keychain_key_node =
804{
805 KEYCHAIN_KEY_NODE,
806 "%s(config-keychain-key)# "
807};
808
e7168df4 809/* Defined in lib/vty.c */
810extern struct cmd_node vty_node;
811
95e735b5 812/* When '^Z' is received from vty, move down to the enable mode. */
813int
b1aa147d 814vtysh_end (void)
95e735b5 815{
816 switch (vty->node)
817 {
818 case VIEW_NODE:
819 case ENABLE_NODE:
820 /* Nothing to do. */
821 break;
822 default:
823 vty->node = ENABLE_NODE;
824 break;
825 }
826 return CMD_SUCCESS;
827}
828
829DEFUNSH (VTYSH_ALL,
830 vtysh_end_all,
831 vtysh_end_all_cmd,
832 "end",
e7168df4 833 "End current mode and change to enable mode\n")
95e735b5 834{
4289546d 835 return vtysh_end ();
95e735b5 836}
837
718e3744 838DEFUNSH (VTYSH_BGPD,
839 router_bgp,
840 router_bgp_cmd,
0b2aa3a0 841 "router bgp CMD_AS_RANGE",
718e3744 842 ROUTER_STR
843 BGP_STR
844 AS_STR)
845{
846 vty->node = BGP_NODE;
847 return CMD_SUCCESS;
848}
849
850DEFUNSH (VTYSH_BGPD,
851 address_family_vpnv4,
852 address_family_vpnv4_cmd,
853 "address-family vpnv4",
854 "Enter Address Family command mode\n"
855 "Address family\n")
856{
857 vty->node = BGP_VPNV4_NODE;
858 return CMD_SUCCESS;
859}
860
861DEFUNSH (VTYSH_BGPD,
862 address_family_vpnv4_unicast,
863 address_family_vpnv4_unicast_cmd,
864 "address-family vpnv4 unicast",
865 "Enter Address Family command mode\n"
866 "Address family\n"
867 "Address Family Modifier\n")
868{
869 vty->node = BGP_VPNV4_NODE;
870 return CMD_SUCCESS;
871}
872
873DEFUNSH (VTYSH_BGPD,
874 address_family_ipv4_unicast,
875 address_family_ipv4_unicast_cmd,
876 "address-family ipv4 unicast",
877 "Enter Address Family command mode\n"
878 "Address family\n"
879 "Address Family Modifier\n")
880{
881 vty->node = BGP_IPV4_NODE;
882 return CMD_SUCCESS;
883}
884
885DEFUNSH (VTYSH_BGPD,
886 address_family_ipv4_multicast,
887 address_family_ipv4_multicast_cmd,
888 "address-family ipv4 multicast",
889 "Enter Address Family command mode\n"
890 "Address family\n"
891 "Address Family Modifier\n")
892{
893 vty->node = BGP_IPV4M_NODE;
894 return CMD_SUCCESS;
895}
896
897DEFUNSH (VTYSH_BGPD,
898 address_family_ipv6,
899 address_family_ipv6_cmd,
900 "address-family ipv6",
901 "Enter Address Family command mode\n"
902 "Address family\n")
903{
904 vty->node = BGP_IPV6_NODE;
905 return CMD_SUCCESS;
906}
907
908DEFUNSH (VTYSH_BGPD,
909 address_family_ipv6_unicast,
910 address_family_ipv6_unicast_cmd,
911 "address-family ipv6 unicast",
912 "Enter Address Family command mode\n"
913 "Address family\n"
914 "Address Family Modifier\n")
915{
916 vty->node = BGP_IPV6_NODE;
917 return CMD_SUCCESS;
918}
919
57b5b7ed 920DEFUNSH (VTYSH_BGPD,
921 address_family_ipv6_multicast,
922 address_family_ipv6_multicast_cmd,
923 "address-family ipv6 multicast",
924 "Enter Address Family command mode\n"
925 "Address family\n"
926 "Address Family Modifier\n")
927{
928 vty->node = BGP_IPV6M_NODE;
929 return CMD_SUCCESS;
930}
931
718e3744 932DEFUNSH (VTYSH_RIPD,
933 key_chain,
934 key_chain_cmd,
935 "key chain WORD",
936 "Authentication key management\n"
937 "Key-chain management\n"
938 "Key-chain name\n")
939{
940 vty->node = KEYCHAIN_NODE;
941 return CMD_SUCCESS;
942}
943
944DEFUNSH (VTYSH_RIPD,
945 key,
946 key_cmd,
947 "key <0-2147483647>",
948 "Configure a key\n"
949 "Key identifier number\n")
950{
951 vty->node = KEYCHAIN_KEY_NODE;
952 return CMD_SUCCESS;
953}
954
955DEFUNSH (VTYSH_RIPD,
956 router_rip,
957 router_rip_cmd,
958 "router rip",
959 ROUTER_STR
960 "RIP")
961{
962 vty->node = RIP_NODE;
963 return CMD_SUCCESS;
964}
965
966DEFUNSH (VTYSH_RIPNGD,
967 router_ripng,
968 router_ripng_cmd,
969 "router ripng",
970 ROUTER_STR
971 "RIPng")
972{
973 vty->node = RIPNG_NODE;
974 return CMD_SUCCESS;
975}
976
977DEFUNSH (VTYSH_OSPFD,
978 router_ospf,
979 router_ospf_cmd,
980 "router ospf",
981 "Enable a routing process\n"
982 "Start OSPF configuration\n")
983{
984 vty->node = OSPF_NODE;
985 return CMD_SUCCESS;
986}
987
988DEFUNSH (VTYSH_OSPF6D,
989 router_ospf6,
990 router_ospf6_cmd,
991 "router ospf6",
992 OSPF6_ROUTER_STR
993 OSPF6_STR)
994{
995 vty->node = OSPF6_NODE;
996 return CMD_SUCCESS;
997}
998
c25e458a 999DEFUNSH (VTYSH_ISISD,
b094d260 1000 router_isis,
1001 router_isis_cmd,
1002 "router isis WORD",
1003 ROUTER_STR
1004 "ISO IS-IS\n"
1005 "ISO Routing area tag")
c25e458a 1006{
1007 vty->node = ISIS_NODE;
1008 return CMD_SUCCESS;
1009}
1010
718e3744 1011DEFUNSH (VTYSH_RMAP,
1012 route_map,
1013 route_map_cmd,
1014 "route-map WORD (deny|permit) <1-65535>",
1015 "Create route-map or enter route-map command mode\n"
1016 "Route map tag\n"
1017 "Route map denies set operations\n"
1018 "Route map permits set operations\n"
1019 "Sequence to insert to/delete from existing route-map entry\n")
1020{
1021 vty->node = RMAP_NODE;
1022 return CMD_SUCCESS;
1023}
1024
e7168df4 1025DEFUNSH (VTYSH_ALL,
1026 vtysh_line_vty,
1027 vtysh_line_vty_cmd,
1028 "line vty",
1029 "Configure a terminal line\n"
1030 "Virtual terminal\n")
1031{
1032 vty->node = VTY_NODE;
1033 return CMD_SUCCESS;
1034}
1035
718e3744 1036DEFUNSH (VTYSH_ALL,
1037 vtysh_enable,
1038 vtysh_enable_cmd,
1039 "enable",
1040 "Turn on privileged mode command\n")
1041{
1042 vty->node = ENABLE_NODE;
1043 return CMD_SUCCESS;
1044}
1045
718e3744 1046DEFUNSH (VTYSH_ALL,
1047 vtysh_disable,
1048 vtysh_disable_cmd,
1049 "disable",
1050 "Turn off privileged mode command\n")
1051{
1052 if (vty->node == ENABLE_NODE)
1053 vty->node = VIEW_NODE;
1054 return CMD_SUCCESS;
1055}
1056
718e3744 1057DEFUNSH (VTYSH_ALL,
1058 vtysh_config_terminal,
1059 vtysh_config_terminal_cmd,
1060 "configure terminal",
1061 "Configuration from vty interface\n"
1062 "Configuration terminal\n")
1063{
1064 vty->node = CONFIG_NODE;
1065 return CMD_SUCCESS;
1066}
1067
274a4a44 1068static int
718e3744 1069vtysh_exit (struct vty *vty)
1070{
1071 switch (vty->node)
1072 {
1073 case VIEW_NODE:
1074 case ENABLE_NODE:
1075 exit (0);
1076 break;
1077 case CONFIG_NODE:
1078 vty->node = ENABLE_NODE;
1079 break;
1080 case INTERFACE_NODE:
1081 case ZEBRA_NODE:
1082 case BGP_NODE:
1083 case RIP_NODE:
1084 case RIPNG_NODE:
1085 case OSPF_NODE:
1086 case OSPF6_NODE:
c25e458a 1087 case ISIS_NODE:
718e3744 1088 case MASC_NODE:
1089 case RMAP_NODE:
1090 case VTY_NODE:
1091 case KEYCHAIN_NODE:
2a56df97 1092 vtysh_execute("end");
1093 vtysh_execute("configure terminal");
718e3744 1094 vty->node = CONFIG_NODE;
1095 break;
1096 case BGP_VPNV4_NODE:
1097 case BGP_IPV4_NODE:
1098 case BGP_IPV4M_NODE:
1099 case BGP_IPV6_NODE:
57b5b7ed 1100 case BGP_IPV6M_NODE:
718e3744 1101 vty->node = BGP_NODE;
1102 break;
1103 case KEYCHAIN_KEY_NODE:
1104 vty->node = KEYCHAIN_NODE;
1105 break;
1106 default:
1107 break;
1108 }
1109 return CMD_SUCCESS;
1110}
1111
1112DEFUNSH (VTYSH_ALL,
1113 vtysh_exit_all,
1114 vtysh_exit_all_cmd,
1115 "exit",
1116 "Exit current mode and down to previous mode\n")
1117{
1118 return vtysh_exit (vty);
1119}
1120
1121ALIAS (vtysh_exit_all,
1122 vtysh_quit_all_cmd,
1123 "quit",
1124 "Exit current mode and down to previous mode\n")
1125
1126DEFUNSH (VTYSH_BGPD,
1127 exit_address_family,
1128 exit_address_family_cmd,
1129 "exit-address-family",
1130 "Exit from Address Family configuration mode\n")
1131{
1132 if (vty->node == BGP_IPV4_NODE
1133 || vty->node == BGP_IPV4M_NODE
1134 || vty->node == BGP_VPNV4_NODE
57b5b7ed 1135 || vty->node == BGP_IPV6_NODE
1136 || vty->node == BGP_IPV6M_NODE)
718e3744 1137 vty->node = BGP_NODE;
1138 return CMD_SUCCESS;
1139}
1140
1141DEFUNSH (VTYSH_ZEBRA,
1142 vtysh_exit_zebra,
1143 vtysh_exit_zebra_cmd,
1144 "exit",
1145 "Exit current mode and down to previous mode\n")
1146{
1147 return vtysh_exit (vty);
1148}
1149
1150ALIAS (vtysh_exit_zebra,
1151 vtysh_quit_zebra_cmd,
1152 "quit",
1153 "Exit current mode and down to previous mode\n")
1154
1155DEFUNSH (VTYSH_RIPD,
1156 vtysh_exit_ripd,
1157 vtysh_exit_ripd_cmd,
1158 "exit",
1159 "Exit current mode and down to previous mode\n")
1160{
1161 return vtysh_exit (vty);
1162}
1163
1164ALIAS (vtysh_exit_ripd,
1165 vtysh_quit_ripd_cmd,
1166 "quit",
1167 "Exit current mode and down to previous mode\n")
1168
68980084 1169DEFUNSH (VTYSH_RIPNGD,
b094d260 1170 vtysh_exit_ripngd,
1171 vtysh_exit_ripngd_cmd,
1172 "exit",
1173 "Exit current mode and down to previous mode\n")
68980084 1174{
1175 return vtysh_exit (vty);
1176}
1177
1178ALIAS (vtysh_exit_ripngd,
1179 vtysh_quit_ripngd_cmd,
1180 "quit",
1181 "Exit current mode and down to previous mode\n")
1182
718e3744 1183DEFUNSH (VTYSH_RMAP,
1184 vtysh_exit_rmap,
1185 vtysh_exit_rmap_cmd,
1186 "exit",
1187 "Exit current mode and down to previous mode\n")
1188{
1189 return vtysh_exit (vty);
1190}
1191
1192ALIAS (vtysh_exit_rmap,
1193 vtysh_quit_rmap_cmd,
1194 "quit",
1195 "Exit current mode and down to previous mode\n")
1196
1197DEFUNSH (VTYSH_BGPD,
1198 vtysh_exit_bgpd,
1199 vtysh_exit_bgpd_cmd,
1200 "exit",
1201 "Exit current mode and down to previous mode\n")
1202{
1203 return vtysh_exit (vty);
1204}
1205
1206ALIAS (vtysh_exit_bgpd,
1207 vtysh_quit_bgpd_cmd,
1208 "quit",
1209 "Exit current mode and down to previous mode\n")
1210
1211DEFUNSH (VTYSH_OSPFD,
1212 vtysh_exit_ospfd,
1213 vtysh_exit_ospfd_cmd,
1214 "exit",
1215 "Exit current mode and down to previous mode\n")
1216{
1217 return vtysh_exit (vty);
1218}
1219
1220ALIAS (vtysh_exit_ospfd,
1221 vtysh_quit_ospfd_cmd,
1222 "quit",
1223 "Exit current mode and down to previous mode\n")
1224
68980084 1225DEFUNSH (VTYSH_OSPF6D,
b094d260 1226 vtysh_exit_ospf6d,
1227 vtysh_exit_ospf6d_cmd,
1228 "exit",
1229 "Exit current mode and down to previous mode\n")
68980084 1230{
1231 return vtysh_exit (vty);
1232}
1233
1234ALIAS (vtysh_exit_ospf6d,
1235 vtysh_quit_ospf6d_cmd,
1236 "quit",
1237 "Exit current mode and down to previous mode\n")
1238
c25e458a 1239DEFUNSH (VTYSH_ISISD,
b094d260 1240 vtysh_exit_isisd,
1241 vtysh_exit_isisd_cmd,
1242 "exit",
1243 "Exit current mode and down to previous mode\n")
c25e458a 1244{
1245 return vtysh_exit (vty);
1246}
1247
1248ALIAS (vtysh_exit_isisd,
1249 vtysh_quit_isisd_cmd,
1250 "quit",
1251 "Exit current mode and down to previous mode\n")
1252
e7168df4 1253DEFUNSH (VTYSH_ALL,
1254 vtysh_exit_line_vty,
1255 vtysh_exit_line_vty_cmd,
1256 "exit",
1257 "Exit current mode and down to previous mode\n")
1258{
1259 return vtysh_exit (vty);
1260}
1261
1262ALIAS (vtysh_exit_line_vty,
1263 vtysh_quit_line_vty_cmd,
1264 "quit",
1265 "Exit current mode and down to previous mode\n")
1266
95e735b5 1267DEFUNSH (VTYSH_INTERFACE,
718e3744 1268 vtysh_interface,
1269 vtysh_interface_cmd,
1270 "interface IFNAME",
1271 "Select an interface to configure\n"
1272 "Interface's name\n")
1273{
1274 vty->node = INTERFACE_NODE;
1275 return CMD_SUCCESS;
1276}
1277
95e735b5 1278/* TODO Implement "no interface command in isisd. */
32d2463c 1279DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D,
1280 vtysh_no_interface_cmd,
1281 "no interface IFNAME",
1282 NO_STR
1283 "Delete a pseudo interface's configuration\n"
1284 "Interface's name\n")
1285
95e735b5 1286/* TODO Implement interface description commands in ripngd, ospf6d
1287 * and isisd. */
338a9916 1288DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1289 interface_desc_cmd,
1290 "description .LINE",
1291 "Interface specific description\n"
1292 "Characters describing this interface\n")
464dc8da 1293
1294DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1295 no_interface_desc_cmd,
1296 "no description",
1297 NO_STR
1298 "Interface specific description\n")
338a9916 1299
95e735b5 1300DEFUNSH (VTYSH_INTERFACE,
718e3744 1301 vtysh_exit_interface,
1302 vtysh_exit_interface_cmd,
1303 "exit",
1304 "Exit current mode and down to previous mode\n")
1305{
1306 return vtysh_exit (vty);
1307}
1308
1309ALIAS (vtysh_exit_interface,
1310 vtysh_quit_interface_cmd,
1311 "quit",
1312 "Exit current mode and down to previous mode\n")
1313
362b4031
PJ
1314/* Memory */
1315DEFUN (vtysh_show_memory,
1316 vtysh_show_memory_cmd,
1317 "show memory",
1318 SHOW_STR
1319 "Memory statistics\n")
1320{
1321 unsigned int i;
1322 int ret = CMD_SUCCESS;
1323 char line[] = "show memory\n";
1324
1325 for (i = 0; i < VTYSH_INDEX_MAX; i++)
1326 if ( vtysh_client[i].fd >= 0 )
1327 {
1328 fprintf (stdout, "Memory statistics for %s:\n",
1329 vtysh_client[i].name);
1330 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1331 fprintf (stdout,"\n");
1332 }
1333
1334 return ret;
1335}
1336
95e735b5 1337/* Logging commands. */
dbf7d13d
PJ
1338DEFUN (vtysh_show_logging,
1339 vtysh_show_logging_cmd,
1340 "show logging",
1341 SHOW_STR
1342 "Show current logging configuration\n")
1343{
1344 unsigned int i;
1345 int ret = CMD_SUCCESS;
1346 char line[] = "show logging\n";
1347
1348 for (i = 0; i < VTYSH_INDEX_MAX; i++)
4150f33e
PJ
1349 if ( vtysh_client[i].fd >= 0 )
1350 {
1351 fprintf (stdout,"Logging configuration for %s:\n",
1352 vtysh_client[i].name);
1353 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1354 fprintf (stdout,"\n");
1355 }
1356
dbf7d13d
PJ
1357 return ret;
1358}
1359
95e735b5 1360DEFUNSH (VTYSH_ALL,
1361 vtysh_log_stdout,
1362 vtysh_log_stdout_cmd,
1363 "log stdout",
1364 "Logging control\n"
274a4a44 1365 "Set stdout logging level\n")
1366{
1367 return CMD_SUCCESS;
1368}
1369
1370DEFUNSH (VTYSH_ALL,
1371 vtysh_log_stdout_level,
1372 vtysh_log_stdout_level_cmd,
1373 "log stdout "LOG_LEVELS,
1374 "Logging control\n"
1375 "Set stdout logging level\n"
1376 LOG_LEVEL_DESC)
95e735b5 1377{
1378 return CMD_SUCCESS;
1379}
1380
1381DEFUNSH (VTYSH_ALL,
1382 no_vtysh_log_stdout,
1383 no_vtysh_log_stdout_cmd,
274a4a44 1384 "no log stdout [LEVEL]",
95e735b5 1385 NO_STR
1386 "Logging control\n"
274a4a44 1387 "Cancel logging to stdout\n"
1388 "Logging level\n")
95e735b5 1389{
1390 return CMD_SUCCESS;
1391}
1392
1393DEFUNSH (VTYSH_ALL,
1394 vtysh_log_file,
1395 vtysh_log_file_cmd,
1396 "log file FILENAME",
1397 "Logging control\n"
1398 "Logging to file\n"
1399 "Logging filename\n")
1400{
1401 return CMD_SUCCESS;
1402}
1403
274a4a44 1404DEFUNSH (VTYSH_ALL,
1405 vtysh_log_file_level,
1406 vtysh_log_file_level_cmd,
1407 "log file FILENAME "LOG_LEVELS,
1408 "Logging control\n"
1409 "Logging to file\n"
1410 "Logging filename\n"
1411 LOG_LEVEL_DESC)
1412{
1413 return CMD_SUCCESS;
1414}
1415
95e735b5 1416DEFUNSH (VTYSH_ALL,
1417 no_vtysh_log_file,
1418 no_vtysh_log_file_cmd,
1419 "no log file [FILENAME]",
1420 NO_STR
1421 "Logging control\n"
1422 "Cancel logging to file\n"
1423 "Logging file name\n")
1424{
1425 return CMD_SUCCESS;
1426}
1427
274a4a44 1428ALIAS_SH (VTYSH_ALL,
1429 no_vtysh_log_file,
1430 no_vtysh_log_file_level_cmd,
1431 "no log file FILENAME LEVEL",
1432 NO_STR
1433 "Logging control\n"
1434 "Cancel logging to file\n"
1435 "Logging file name\n"
1436 "Logging level\n")
1437
1438DEFUNSH (VTYSH_ALL,
1439 vtysh_log_monitor,
1440 vtysh_log_monitor_cmd,
1441 "log monitor",
1442 "Logging control\n"
1443 "Set terminal line (monitor) logging level\n")
1444{
1445 return CMD_SUCCESS;
1446}
1447
1448DEFUNSH (VTYSH_ALL,
1449 vtysh_log_monitor_level,
1450 vtysh_log_monitor_level_cmd,
1451 "log monitor "LOG_LEVELS,
1452 "Logging control\n"
1453 "Set terminal line (monitor) logging level\n"
1454 LOG_LEVEL_DESC)
1455{
1456 return CMD_SUCCESS;
1457}
1458
1459DEFUNSH (VTYSH_ALL,
1460 no_vtysh_log_monitor,
1461 no_vtysh_log_monitor_cmd,
1462 "no log monitor [LEVEL]",
1463 NO_STR
1464 "Logging control\n"
1465 "Disable terminal line (monitor) logging\n"
1466 "Logging level\n")
1467{
1468 return CMD_SUCCESS;
1469}
1470
95e735b5 1471DEFUNSH (VTYSH_ALL,
1472 vtysh_log_syslog,
1473 vtysh_log_syslog_cmd,
1474 "log syslog",
1475 "Logging control\n"
274a4a44 1476 "Set syslog logging level\n")
1477{
1478 return CMD_SUCCESS;
1479}
1480
1481DEFUNSH (VTYSH_ALL,
1482 vtysh_log_syslog_level,
1483 vtysh_log_syslog_level_cmd,
1484 "log syslog "LOG_LEVELS,
1485 "Logging control\n"
1486 "Set syslog logging level\n"
1487 LOG_LEVEL_DESC)
95e735b5 1488{
1489 return CMD_SUCCESS;
1490}
1491
1492DEFUNSH (VTYSH_ALL,
1493 no_vtysh_log_syslog,
1494 no_vtysh_log_syslog_cmd,
274a4a44 1495 "no log syslog [LEVEL]",
95e735b5 1496 NO_STR
1497 "Logging control\n"
274a4a44 1498 "Cancel logging to syslog\n"
1499 "Logging level\n")
95e735b5 1500{
1501 return CMD_SUCCESS;
1502}
1503
1504DEFUNSH (VTYSH_ALL,
274a4a44 1505 vtysh_log_facility,
1506 vtysh_log_facility_cmd,
1507 "log facility "LOG_FACILITIES,
95e735b5 1508 "Logging control\n"
274a4a44 1509 "Facility parameter for syslog messages\n"
1510 LOG_FACILITY_DESC)
1511
95e735b5 1512{
1513 return CMD_SUCCESS;
1514}
1515
1516DEFUNSH (VTYSH_ALL,
274a4a44 1517 no_vtysh_log_facility,
1518 no_vtysh_log_facility_cmd,
1519 "no log facility [FACILITY]",
95e735b5 1520 NO_STR
1521 "Logging control\n"
274a4a44 1522 "Reset syslog facility to default (daemon)\n"
1523 "Syslog facility\n")
1524
1525{
1526 return CMD_SUCCESS;
1527}
1528
1529DEFUNSH_DEPRECATED (VTYSH_ALL,
1530 vtysh_log_trap,
1531 vtysh_log_trap_cmd,
1532 "log trap "LOG_LEVELS,
1533 "Logging control\n"
1534 "(Deprecated) Set logging level and default for all destinations\n"
1535 LOG_LEVEL_DESC)
1536
1537{
1538 return CMD_SUCCESS;
1539}
1540
1541DEFUNSH_DEPRECATED (VTYSH_ALL,
1542 no_vtysh_log_trap,
1543 no_vtysh_log_trap_cmd,
1544 "no log trap [LEVEL]",
1545 NO_STR
1546 "Logging control\n"
1547 "Permit all logging information\n"
1548 "Logging level\n")
95e735b5 1549{
1550 return CMD_SUCCESS;
1551}
1552
1553DEFUNSH (VTYSH_ALL,
1554 vtysh_log_record_priority,
1555 vtysh_log_record_priority_cmd,
1556 "log record-priority",
1557 "Logging control\n"
1558 "Log the priority of the message within the message\n")
1559{
1560 return CMD_SUCCESS;
1561}
1562
1563DEFUNSH (VTYSH_ALL,
1564 no_vtysh_log_record_priority,
1565 no_vtysh_log_record_priority_cmd,
1566 "no log record-priority",
1567 NO_STR
1568 "Logging control\n"
1569 "Do not log the priority of the message within the message\n")
1570{
1571 return CMD_SUCCESS;
1572}
1573
c749b722
AS
1574DEFUNSH (VTYSH_ALL,
1575 vtysh_log_timestamp_precision,
1576 vtysh_log_timestamp_precision_cmd,
1577 "log timestamp precision <0-6>",
1578 "Logging control\n"
1579 "Timestamp configuration\n"
1580 "Set the timestamp precision\n"
1581 "Number of subsecond digits\n")
1582{
1583 return CMD_SUCCESS;
1584}
1585
1586DEFUNSH (VTYSH_ALL,
1587 no_vtysh_log_timestamp_precision,
1588 no_vtysh_log_timestamp_precision_cmd,
1589 "no log timestamp precision",
1590 NO_STR
1591 "Logging control\n"
1592 "Timestamp configuration\n"
1593 "Reset the timestamp precision to the default value of 0\n")
1594{
1595 return CMD_SUCCESS;
1596}
1597
e7168df4 1598DEFUNSH (VTYSH_ALL,
1599 vtysh_service_password_encrypt,
1600 vtysh_service_password_encrypt_cmd,
1601 "service password-encryption",
1602 "Set up miscellaneous service\n"
1603 "Enable encrypted passwords\n")
1604{
1605 return CMD_SUCCESS;
1606}
1607
1608DEFUNSH (VTYSH_ALL,
1609 no_vtysh_service_password_encrypt,
1610 no_vtysh_service_password_encrypt_cmd,
1611 "no service password-encryption",
1612 NO_STR
1613 "Set up miscellaneous service\n"
1614 "Enable encrypted passwords\n")
1615{
1616 return CMD_SUCCESS;
1617}
1618
1619DEFUNSH (VTYSH_ALL,
1620 vtysh_config_password,
1621 vtysh_password_cmd,
1622 "password (8|) WORD",
1623 "Assign the terminal connection password\n"
1624 "Specifies a HIDDEN password will follow\n"
1625 "dummy string \n"
1626 "The HIDDEN line password string\n")
1627{
1628 return CMD_SUCCESS;
1629}
1630
1631DEFUNSH (VTYSH_ALL,
1632 vtysh_password_text,
1633 vtysh_password_text_cmd,
1634 "password LINE",
1635 "Assign the terminal connection password\n"
1636 "The UNENCRYPTED (cleartext) line password\n")
1637{
1638 return CMD_SUCCESS;
1639}
1640
1641DEFUNSH (VTYSH_ALL,
1642 vtysh_config_enable_password,
1643 vtysh_enable_password_cmd,
1644 "enable password (8|) WORD",
1645 "Modify enable password parameters\n"
1646 "Assign the privileged level password\n"
1647 "Specifies a HIDDEN password will follow\n"
1648 "dummy string \n"
1649 "The HIDDEN 'enable' password string\n")
1650{
1651 return CMD_SUCCESS;
1652}
1653
1654DEFUNSH (VTYSH_ALL,
1655 vtysh_enable_password_text,
1656 vtysh_enable_password_text_cmd,
1657 "enable password LINE",
1658 "Modify enable password parameters\n"
1659 "Assign the privileged level password\n"
1660 "The UNENCRYPTED (cleartext) 'enable' password\n")
1661{
1662 return CMD_SUCCESS;
1663}
1664
1665DEFUNSH (VTYSH_ALL,
1666 no_vtysh_config_enable_password,
1667 no_vtysh_enable_password_cmd,
1668 "no enable password",
1669 NO_STR
1670 "Modify enable password parameters\n"
1671 "Assign the privileged level password\n")
1672{
1673 return CMD_SUCCESS;
1674}
1675
718e3744 1676DEFUN (vtysh_write_terminal,
1677 vtysh_write_terminal_cmd,
1678 "write terminal",
1679 "Write running configuration to memory, network, or terminal\n"
1680 "Write to terminal\n")
1681{
b1aa147d 1682 u_int i;
718e3744 1683 int ret;
1684 char line[] = "write terminal\n";
1685 FILE *fp = NULL;
1686
1687 if (vtysh_pager_name)
1688 {
4fc01e67 1689 fp = popen (vtysh_pager_name, "w");
718e3744 1690 if (fp == NULL)
1691 {
1692 perror ("popen");
1693 exit (1);
1694 }
1695 }
1696 else
1697 fp = stdout;
1698
1699 vty_out (vty, "Building configuration...%s", VTY_NEWLINE);
1700 vty_out (vty, "%sCurrent configuration:%s", VTY_NEWLINE,
1701 VTY_NEWLINE);
e7168df4 1702 vty_out (vty, "!%s", VTY_NEWLINE);
718e3744 1703
b1aa147d 1704 for (i = 0; i < VTYSH_INDEX_MAX; i++)
1705 ret = vtysh_client_config (&vtysh_client[i], line);
718e3744 1706
e7168df4 1707 /* Integrate vtysh specific configuration. */
1708 vtysh_config_write ();
1709
718e3744 1710 vtysh_config_dump (fp);
1711
8454b056
PJ
1712 vty_out (vty, "end%s", VTY_NEWLINE);
1713
718e3744 1714 if (vtysh_pager_name && fp)
1715 {
1716 fflush (fp);
1717 if (pclose (fp) == -1)
1718 {
1719 perror ("pclose");
1720 exit (1);
1721 }
1722 fp = NULL;
1723 }
1724
1725 return CMD_SUCCESS;
1726}
1727
e7168df4 1728DEFUN (vtysh_integrated_config,
1729 vtysh_integrated_config_cmd,
1730 "service integrated-vtysh-config",
1731 "Set up miscellaneous service\n"
1732 "Write configuration into integrated file\n")
4fc01e67 1733{
e7168df4 1734 vtysh_writeconfig_integrated = 1;
1735 return CMD_SUCCESS;
4fc01e67 1736}
1737
e7168df4 1738DEFUN (no_vtysh_integrated_config,
1739 no_vtysh_integrated_config_cmd,
1740 "no service integrated-vtysh-config",
1741 NO_STR
1742 "Set up miscellaneous service\n"
1743 "Write configuration into integrated file\n")
4fc01e67 1744{
e7168df4 1745 vtysh_writeconfig_integrated = 0;
1746 return CMD_SUCCESS;
4fc01e67 1747}
1748
274a4a44 1749static int
1750write_config_integrated(void)
718e3744 1751{
b1aa147d 1752 u_int i;
718e3744 1753 int ret;
718e3744 1754 char line[] = "write terminal\n";
1755 FILE *fp;
1756 char *integrate_sav = NULL;
1757
95e735b5 1758 integrate_sav = malloc (strlen (integrate_default) +
1759 strlen (CONF_BACKUP_EXT) + 1);
718e3744 1760 strcpy (integrate_sav, integrate_default);
1761 strcat (integrate_sav, CONF_BACKUP_EXT);
1762
4fc01e67 1763 fprintf (stdout,"Building Configuration...\n");
718e3744 1764
95e735b5 1765 /* Move current configuration file to backup config file. */
718e3744 1766 unlink (integrate_sav);
1767 rename (integrate_default, integrate_sav);
95e735b5 1768 free (integrate_sav);
4fc01e67 1769
718e3744 1770 fp = fopen (integrate_default, "w");
1771 if (fp == NULL)
1772 {
95e735b5 1773 fprintf (stdout,"%% Can't open configuration file %s.\n",
1774 integrate_default);
718e3744 1775 return CMD_SUCCESS;
1776 }
718e3744 1777
b1aa147d 1778 for (i = 0; i < VTYSH_INDEX_MAX; i++)
1779 ret = vtysh_client_config (&vtysh_client[i], line);
718e3744 1780
1781 vtysh_config_dump (fp);
1782
1783 fclose (fp);
1784
aa593d5e 1785 if (chmod (integrate_default, CONFIGFILE_MASK) != 0)
1786 {
1787 fprintf (stdout,"%% Can't chmod configuration file %s: %s (%d)\n",
6099b3b5 1788 integrate_default, safe_strerror(errno), errno);
aa593d5e 1789 return CMD_WARNING;
1790 }
1791
4fc01e67 1792 fprintf(stdout,"Integrated configuration saved to %s\n",integrate_default);
1793
1794 fprintf (stdout,"[OK]\n");
1795
718e3744 1796 return CMD_SUCCESS;
1797}
1798
4fc01e67 1799DEFUN (vtysh_write_memory,
1800 vtysh_write_memory_cmd,
1801 "write memory",
1802 "Write running configuration to memory, network, or terminal\n"
1803 "Write configuration to the file (same as write file)\n")
1804{
dfc0d9ba 1805 int ret = CMD_SUCCESS;
4fc01e67 1806 char line[] = "write memory\n";
b1aa147d 1807 u_int i;
4fc01e67 1808
e7168df4 1809 /* If integrated Quagga.conf explicitely set. */
1810 if (vtysh_writeconfig_integrated)
1811 return write_config_integrated();
4fc01e67 1812
1813 fprintf (stdout,"Building Configuration...\n");
1814
b1aa147d 1815 for (i = 0; i < VTYSH_INDEX_MAX; i++)
1816 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
e7168df4 1817
4fc01e67 1818 fprintf (stdout,"[OK]\n");
1819
dfc0d9ba 1820 return ret;
4fc01e67 1821}
1822
718e3744 1823ALIAS (vtysh_write_memory,
1824 vtysh_copy_runningconfig_startupconfig_cmd,
1825 "copy running-config startup-config",
1826 "Copy from one file to another\n"
1827 "Copy from current system configuration\n"
1828 "Copy to startup configuration\n")
1829
1830ALIAS (vtysh_write_memory,
1831 vtysh_write_file_cmd,
1832 "write file",
1833 "Write running configuration to memory, network, or terminal\n"
1834 "Write configuration to the file (same as write memory)\n")
1835
4a6e2257 1836ALIAS (vtysh_write_memory,
1837 vtysh_write_cmd,
1838 "write",
1839 "Write running configuration to memory, network, or terminal\n")
1840
718e3744 1841ALIAS (vtysh_write_terminal,
1842 vtysh_show_running_config_cmd,
1843 "show running-config",
1844 SHOW_STR
1845 "Current operating configuration\n")
b094d260 1846
34553cc3 1847DEFUN (vtysh_terminal_length,
1848 vtysh_terminal_length_cmd,
1849 "terminal length <0-512>",
1850 "Set terminal line parameters\n"
1851 "Set number of lines on a screen\n"
1852 "Number of lines on screen (0 for no pausing)\n")
1853{
1854 int lines;
1855 char *endptr = NULL;
1856 char default_pager[10];
1857
1858 lines = strtol (argv[0], &endptr, 10);
1859 if (lines < 0 || lines > 512 || *endptr != '\0')
1860 {
1861 vty_out (vty, "length is malformed%s", VTY_NEWLINE);
1862 return CMD_WARNING;
1863 }
1864
1865 if (vtysh_pager_name)
1866 {
1867 free (vtysh_pager_name);
1868 vtysh_pager_name = NULL;
1869 }
1870
1871 if (lines != 0)
1872 {
1873 snprintf(default_pager, 10, "more -%i", lines);
1874 vtysh_pager_name = strdup (default_pager);
1875 }
1876
1877 return CMD_SUCCESS;
1878}
1879
1880DEFUN (vtysh_terminal_no_length,
1881 vtysh_terminal_no_length_cmd,
1882 "terminal no length",
1883 "Set terminal line parameters\n"
1884 NO_STR
1885 "Set number of lines on a screen\n")
1886{
1887 if (vtysh_pager_name)
1888 {
1889 free (vtysh_pager_name);
1890 vtysh_pager_name = NULL;
1891 }
1892
1893 vtysh_pager_init();
1894 return CMD_SUCCESS;
1895}
1896
f2799e69 1897DEFUN (vtysh_show_daemons,
1898 vtysh_show_daemons_cmd,
1899 "show daemons",
e7168df4 1900 SHOW_STR
1901 "Show list of running daemons\n")
1902{
b1aa147d 1903 u_int i;
1904
1905 for (i = 0; i < VTYSH_INDEX_MAX; i++)
1906 if ( vtysh_client[i].fd >= 0 )
1907 vty_out(vty, " %s", vtysh_client[i].name);
e7168df4 1908 vty_out(vty, "%s", VTY_NEWLINE);
1909
1910 return CMD_SUCCESS;
1911}
1912
718e3744 1913/* Execute command in child process. */
274a4a44 1914static int
5862ff52 1915execute_command (const char *command, int argc, const char *arg1,
1916 const char *arg2)
718e3744 1917{
1918 int ret;
1919 pid_t pid;
1920 int status;
1921
1922 /* Call fork(). */
1923 pid = fork ();
1924
1925 if (pid < 0)
1926 {
1927 /* Failure of fork(). */
6099b3b5 1928 fprintf (stderr, "Can't fork: %s\n", safe_strerror (errno));
718e3744 1929 exit (1);
1930 }
1931 else if (pid == 0)
1932 {
1933 /* This is child process. */
1934 switch (argc)
1935 {
1936 case 0:
fa2b17e3 1937 ret = execlp (command, command, (const char *)NULL);
718e3744 1938 break;
1939 case 1:
fa2b17e3 1940 ret = execlp (command, command, arg1, (const char *)NULL);
718e3744 1941 break;
1942 case 2:
fa2b17e3 1943 ret = execlp (command, command, arg1, arg2, (const char *)NULL);
718e3744 1944 break;
1945 }
1946
1947 /* When execlp suceed, this part is not executed. */
6099b3b5 1948 fprintf (stderr, "Can't execute %s: %s\n", command, safe_strerror (errno));
718e3744 1949 exit (1);
1950 }
1951 else
1952 {
1953 /* This is parent. */
1954 execute_flag = 1;
1955 ret = wait4 (pid, &status, 0, NULL);
1956 execute_flag = 0;
1957 }
1958 return 0;
1959}
1960
1961DEFUN (vtysh_ping,
1962 vtysh_ping_cmd,
1963 "ping WORD",
4eeccf18 1964 "Send echo messages\n"
718e3744 1965 "Ping destination address or hostname\n")
1966{
1967 execute_command ("ping", 1, argv[0], NULL);
1968 return CMD_SUCCESS;
1969}
1970
4eeccf18 1971ALIAS (vtysh_ping,
1972 vtysh_ping_ip_cmd,
1973 "ping ip WORD",
1974 "Send echo messages\n"
1975 "IP echo\n"
1976 "Ping destination address or hostname\n")
1977
718e3744 1978DEFUN (vtysh_traceroute,
1979 vtysh_traceroute_cmd,
1980 "traceroute WORD",
1981 "Trace route to destination\n"
1982 "Trace route to destination address or hostname\n")
1983{
1984 execute_command ("traceroute", 1, argv[0], NULL);
1985 return CMD_SUCCESS;
1986}
1987
4eeccf18 1988ALIAS (vtysh_traceroute,
1989 vtysh_traceroute_ip_cmd,
1990 "traceroute ip WORD",
1991 "Trace route to destination\n"
1992 "IP trace\n"
1993 "Trace route to destination address or hostname\n")
1994
1995#ifdef HAVE_IPV6
1996DEFUN (vtysh_ping6,
1997 vtysh_ping6_cmd,
1998 "ping ipv6 WORD",
1999 "Send echo messages\n"
2000 "IPv6 echo\n"
2001 "Ping destination address or hostname\n")
2002{
2003 execute_command ("ping6", 1, argv[0], NULL);
2004 return CMD_SUCCESS;
2005}
2006
2007DEFUN (vtysh_traceroute6,
2008 vtysh_traceroute6_cmd,
2009 "traceroute ipv6 WORD",
2010 "Trace route to destination\n"
2011 "IPv6 trace\n"
2012 "Trace route to destination address or hostname\n")
2013{
2014 execute_command ("traceroute6", 1, argv[0], NULL);
2015 return CMD_SUCCESS;
2016}
2017#endif
2018
718e3744 2019DEFUN (vtysh_telnet,
2020 vtysh_telnet_cmd,
2021 "telnet WORD",
2022 "Open a telnet connection\n"
2023 "IP address or hostname of a remote system\n")
2024{
2025 execute_command ("telnet", 1, argv[0], NULL);
2026 return CMD_SUCCESS;
2027}
2028
2029DEFUN (vtysh_telnet_port,
2030 vtysh_telnet_port_cmd,
2031 "telnet WORD PORT",
2032 "Open a telnet connection\n"
2033 "IP address or hostname of a remote system\n"
2034 "TCP Port number\n")
2035{
2036 execute_command ("telnet", 2, argv[0], argv[1]);
2037 return CMD_SUCCESS;
2038}
2039
5087df56 2040DEFUN (vtysh_ssh,
2041 vtysh_ssh_cmd,
2042 "ssh WORD",
2043 "Open an ssh connection\n"
2044 "[user@]host\n")
2045{
2046 execute_command ("ssh", 1, argv[0], NULL);
2047 return CMD_SUCCESS;
2048}
2049
718e3744 2050DEFUN (vtysh_start_shell,
2051 vtysh_start_shell_cmd,
2052 "start-shell",
2053 "Start UNIX shell\n")
2054{
2055 execute_command ("sh", 0, NULL, NULL);
2056 return CMD_SUCCESS;
2057}
2058
2059DEFUN (vtysh_start_bash,
2060 vtysh_start_bash_cmd,
2061 "start-shell bash",
2062 "Start UNIX shell\n"
2063 "Start bash\n")
2064{
2065 execute_command ("bash", 0, NULL, NULL);
2066 return CMD_SUCCESS;
2067}
2068
2069DEFUN (vtysh_start_zsh,
2070 vtysh_start_zsh_cmd,
2071 "start-shell zsh",
2072 "Start UNIX shell\n"
2073 "Start Z shell\n")
2074{
2075 execute_command ("zsh", 0, NULL, NULL);
2076 return CMD_SUCCESS;
2077}
b094d260 2078
274a4a44 2079static void
718e3744 2080vtysh_install_default (enum node_type node)
2081{
2082 install_element (node, &config_list_cmd);
2083}
2084
2085/* Making connection to protocol daemon. */
274a4a44 2086static int
b1aa147d 2087vtysh_connect (struct vtysh_client *vclient)
718e3744 2088{
2089 int ret;
2090 int sock, len;
2091 struct sockaddr_un addr;
2092 struct stat s_stat;
718e3744 2093
718e3744 2094 /* Stat socket to see if we have permission to access it. */
b1aa147d 2095 ret = stat (vclient->path, &s_stat);
718e3744 2096 if (ret < 0 && errno != ENOENT)
2097 {
2098 fprintf (stderr, "vtysh_connect(%s): stat = %s\n",
b1aa147d 2099 vclient->path, safe_strerror(errno));
718e3744 2100 exit(1);
2101 }
2102
2103 if (ret >= 0)
2104 {
2105 if (! S_ISSOCK(s_stat.st_mode))
2106 {
2107 fprintf (stderr, "vtysh_connect(%s): Not a socket\n",
b1aa147d 2108 vclient->path);
718e3744 2109 exit (1);
2110 }
2111
718e3744 2112 }
2113
2114 sock = socket (AF_UNIX, SOCK_STREAM, 0);
2115 if (sock < 0)
2116 {
2117#ifdef DEBUG
b1aa147d 2118 fprintf(stderr, "vtysh_connect(%s): socket = %s\n", vclient->path,
6099b3b5 2119 safe_strerror(errno));
718e3744 2120#endif /* DEBUG */
2121 return -1;
2122 }
2123
2124 memset (&addr, 0, sizeof (struct sockaddr_un));
2125 addr.sun_family = AF_UNIX;
b1aa147d 2126 strncpy (addr.sun_path, vclient->path, strlen (vclient->path));
6f0e3f6e 2127#ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
718e3744 2128 len = addr.sun_len = SUN_LEN(&addr);
2129#else
2130 len = sizeof (addr.sun_family) + strlen (addr.sun_path);
6f0e3f6e 2131#endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
718e3744 2132
2133 ret = connect (sock, (struct sockaddr *) &addr, len);
2134 if (ret < 0)
2135 {
2136#ifdef DEBUG
b1aa147d 2137 fprintf(stderr, "vtysh_connect(%s): connect = %s\n", vclient->path,
6099b3b5 2138 safe_strerror(errno));
718e3744 2139#endif /* DEBUG */
2140 close (sock);
2141 return -1;
2142 }
2143 vclient->fd = sock;
2144
2145 return 0;
2146}
2147
f366ad31
AS
2148int
2149vtysh_connect_all(const char *daemon_name)
718e3744 2150{
b1aa147d 2151 u_int i;
f366ad31
AS
2152 int rc = 0;
2153 int matches = 0;
b1aa147d 2154
2155 for (i = 0; i < VTYSH_INDEX_MAX; i++)
2156 {
f366ad31
AS
2157 if (!daemon_name || !strcmp(daemon_name, vtysh_client[i].name))
2158 {
2159 matches++;
2160 if (vtysh_connect(&vtysh_client[i]) == 0)
2161 rc++;
2162 /* We need direct access to ripd in vtysh_exit_ripd_only. */
2163 if (vtysh_client[i].flag == VTYSH_RIPD)
2164 ripd_client = &vtysh_client[i];
2165 }
b1aa147d 2166 }
f366ad31
AS
2167 if (!matches)
2168 fprintf(stderr, "Error: no daemons match name %s!\n", daemon_name);
2169 return rc;
718e3744 2170}
2171
95e735b5 2172/* To disable readline's filename completion. */
274a4a44 2173static char *
dfc0d9ba 2174vtysh_completion_entry_function (const char *ignore, int invoking_key)
718e3744 2175{
dfc0d9ba 2176 return NULL;
718e3744 2177}
2178
2179void
b1aa147d 2180vtysh_readline_init (void)
718e3744 2181{
2182 /* readline related settings. */
53a6f932 2183 rl_bind_key ('?', (Function *) vtysh_rl_describe);
68980084 2184 rl_completion_entry_function = vtysh_completion_entry_function;
718e3744 2185 rl_attempted_completion_function = (CPPFunction *)new_completion;
2186 /* do not append space after completion. It will be appended
95e735b5 2187 * in new_completion() function explicitly. */
718e3744 2188 rl_completion_append_character = '\0';
2189}
2190
2191char *
b1aa147d 2192vtysh_prompt (void)
718e3744 2193{
f366ad31 2194 static struct utsname names;
718e3744 2195 static char buf[100];
2196 const char*hostname;
2197 extern struct host host;
2198
2199 hostname = host.name;
2200
2201 if (!hostname)
2202 {
f366ad31
AS
2203 if (!names.nodename[0])
2204 uname (&names);
718e3744 2205 hostname = names.nodename;
2206 }
2207
2208 snprintf (buf, sizeof buf, cmd_prompt (vty->node), hostname);
2209
2210 return buf;
2211}
2212
2213void
b1aa147d 2214vtysh_init_vty (void)
718e3744 2215{
2216 /* Make vty structure. */
2217 vty = vty_new ();
2218 vty->type = VTY_SHELL;
2219 vty->node = VIEW_NODE;
2220
2221 /* Initialize commands. */
2222 cmd_init (0);
2223
2224 /* Install nodes. */
2225 install_node (&bgp_node, NULL);
2226 install_node (&rip_node, NULL);
2227 install_node (&interface_node, NULL);
2228 install_node (&rmap_node, NULL);
2229 install_node (&zebra_node, NULL);
2230 install_node (&bgp_vpnv4_node, NULL);
2231 install_node (&bgp_ipv4_node, NULL);
2232 install_node (&bgp_ipv4m_node, NULL);
2233/* #ifdef HAVE_IPV6 */
2234 install_node (&bgp_ipv6_node, NULL);
57b5b7ed 2235 install_node (&bgp_ipv6m_node, NULL);
718e3744 2236/* #endif */
2237 install_node (&ospf_node, NULL);
2238/* #ifdef HAVE_IPV6 */
2239 install_node (&ripng_node, NULL);
2240 install_node (&ospf6_node, NULL);
2241/* #endif */
2242 install_node (&keychain_node, NULL);
2243 install_node (&keychain_key_node, NULL);
c25e458a 2244 install_node (&isis_node, NULL);
e7168df4 2245 install_node (&vty_node, NULL);
718e3744 2246
2247 vtysh_install_default (VIEW_NODE);
2248 vtysh_install_default (ENABLE_NODE);
2249 vtysh_install_default (CONFIG_NODE);
2250 vtysh_install_default (BGP_NODE);
2251 vtysh_install_default (RIP_NODE);
2252 vtysh_install_default (INTERFACE_NODE);
2253 vtysh_install_default (RMAP_NODE);
2254 vtysh_install_default (ZEBRA_NODE);
2255 vtysh_install_default (BGP_VPNV4_NODE);
2256 vtysh_install_default (BGP_IPV4_NODE);
2257 vtysh_install_default (BGP_IPV4M_NODE);
2258 vtysh_install_default (BGP_IPV6_NODE);
57b5b7ed 2259 vtysh_install_default (BGP_IPV6M_NODE);
718e3744 2260 vtysh_install_default (OSPF_NODE);
2261 vtysh_install_default (RIPNG_NODE);
2262 vtysh_install_default (OSPF6_NODE);
c25e458a 2263 vtysh_install_default (ISIS_NODE);
718e3744 2264 vtysh_install_default (KEYCHAIN_NODE);
2265 vtysh_install_default (KEYCHAIN_KEY_NODE);
e7168df4 2266 vtysh_install_default (VTY_NODE);
718e3744 2267
2268 install_element (VIEW_NODE, &vtysh_enable_cmd);
2269 install_element (ENABLE_NODE, &vtysh_config_terminal_cmd);
2270 install_element (ENABLE_NODE, &vtysh_disable_cmd);
2271
2272 /* "exit" command. */
2273 install_element (VIEW_NODE, &vtysh_exit_all_cmd);
2274 install_element (VIEW_NODE, &vtysh_quit_all_cmd);
2275 install_element (CONFIG_NODE, &vtysh_exit_all_cmd);
2276 /* install_element (CONFIG_NODE, &vtysh_quit_all_cmd); */
2277 install_element (ENABLE_NODE, &vtysh_exit_all_cmd);
2278 install_element (ENABLE_NODE, &vtysh_quit_all_cmd);
2279 install_element (RIP_NODE, &vtysh_exit_ripd_cmd);
2280 install_element (RIP_NODE, &vtysh_quit_ripd_cmd);
68980084 2281 install_element (RIPNG_NODE, &vtysh_exit_ripngd_cmd);
2282 install_element (RIPNG_NODE, &vtysh_quit_ripngd_cmd);
718e3744 2283 install_element (OSPF_NODE, &vtysh_exit_ospfd_cmd);
2284 install_element (OSPF_NODE, &vtysh_quit_ospfd_cmd);
68980084 2285 install_element (OSPF6_NODE, &vtysh_exit_ospf6d_cmd);
2286 install_element (OSPF6_NODE, &vtysh_quit_ospf6d_cmd);
718e3744 2287 install_element (BGP_NODE, &vtysh_exit_bgpd_cmd);
2288 install_element (BGP_NODE, &vtysh_quit_bgpd_cmd);
2289 install_element (BGP_VPNV4_NODE, &vtysh_exit_bgpd_cmd);
2290 install_element (BGP_VPNV4_NODE, &vtysh_quit_bgpd_cmd);
2291 install_element (BGP_IPV4_NODE, &vtysh_exit_bgpd_cmd);
2292 install_element (BGP_IPV4_NODE, &vtysh_quit_bgpd_cmd);
2293 install_element (BGP_IPV4M_NODE, &vtysh_exit_bgpd_cmd);
2294 install_element (BGP_IPV4M_NODE, &vtysh_quit_bgpd_cmd);
2295 install_element (BGP_IPV6_NODE, &vtysh_exit_bgpd_cmd);
2296 install_element (BGP_IPV6_NODE, &vtysh_quit_bgpd_cmd);
57b5b7ed 2297 install_element (BGP_IPV6M_NODE, &vtysh_exit_bgpd_cmd);
2298 install_element (BGP_IPV6M_NODE, &vtysh_quit_bgpd_cmd);
c25e458a 2299 install_element (ISIS_NODE, &vtysh_exit_isisd_cmd);
2300 install_element (ISIS_NODE, &vtysh_quit_isisd_cmd);
718e3744 2301 install_element (KEYCHAIN_NODE, &vtysh_exit_ripd_cmd);
2302 install_element (KEYCHAIN_NODE, &vtysh_quit_ripd_cmd);
2303 install_element (KEYCHAIN_KEY_NODE, &vtysh_exit_ripd_cmd);
2304 install_element (KEYCHAIN_KEY_NODE, &vtysh_quit_ripd_cmd);
2305 install_element (RMAP_NODE, &vtysh_exit_rmap_cmd);
2306 install_element (RMAP_NODE, &vtysh_quit_rmap_cmd);
e7168df4 2307 install_element (VTY_NODE, &vtysh_exit_line_vty_cmd);
2308 install_element (VTY_NODE, &vtysh_quit_line_vty_cmd);
718e3744 2309
2310 /* "end" command. */
2311 install_element (CONFIG_NODE, &vtysh_end_all_cmd);
2312 install_element (ENABLE_NODE, &vtysh_end_all_cmd);
2313 install_element (RIP_NODE, &vtysh_end_all_cmd);
2314 install_element (RIPNG_NODE, &vtysh_end_all_cmd);
2315 install_element (OSPF_NODE, &vtysh_end_all_cmd);
2316 install_element (OSPF6_NODE, &vtysh_end_all_cmd);
2317 install_element (BGP_NODE, &vtysh_end_all_cmd);
2318 install_element (BGP_IPV4_NODE, &vtysh_end_all_cmd);
2319 install_element (BGP_IPV4M_NODE, &vtysh_end_all_cmd);
2320 install_element (BGP_VPNV4_NODE, &vtysh_end_all_cmd);
2321 install_element (BGP_IPV6_NODE, &vtysh_end_all_cmd);
57b5b7ed 2322 install_element (BGP_IPV6M_NODE, &vtysh_end_all_cmd);
c25e458a 2323 install_element (ISIS_NODE, &vtysh_end_all_cmd);
718e3744 2324 install_element (KEYCHAIN_NODE, &vtysh_end_all_cmd);
2325 install_element (KEYCHAIN_KEY_NODE, &vtysh_end_all_cmd);
2326 install_element (RMAP_NODE, &vtysh_end_all_cmd);
e7168df4 2327 install_element (VTY_NODE, &vtysh_end_all_cmd);
718e3744 2328
338a9916 2329 install_element (INTERFACE_NODE, &interface_desc_cmd);
464dc8da 2330 install_element (INTERFACE_NODE, &no_interface_desc_cmd);
718e3744 2331 install_element (INTERFACE_NODE, &vtysh_end_all_cmd);
2332 install_element (INTERFACE_NODE, &vtysh_exit_interface_cmd);
2333 install_element (INTERFACE_NODE, &vtysh_quit_interface_cmd);
2334 install_element (CONFIG_NODE, &router_rip_cmd);
2335#ifdef HAVE_IPV6
2336 install_element (CONFIG_NODE, &router_ripng_cmd);
2337#endif
2338 install_element (CONFIG_NODE, &router_ospf_cmd);
2339#ifdef HAVE_IPV6
2340 install_element (CONFIG_NODE, &router_ospf6_cmd);
2341#endif
c25e458a 2342 install_element (CONFIG_NODE, &router_isis_cmd);
718e3744 2343 install_element (CONFIG_NODE, &router_bgp_cmd);
2344 install_element (BGP_NODE, &address_family_vpnv4_cmd);
2345 install_element (BGP_NODE, &address_family_vpnv4_unicast_cmd);
2346 install_element (BGP_NODE, &address_family_ipv4_unicast_cmd);
2347 install_element (BGP_NODE, &address_family_ipv4_multicast_cmd);
2348#ifdef HAVE_IPV6
2349 install_element (BGP_NODE, &address_family_ipv6_cmd);
2350 install_element (BGP_NODE, &address_family_ipv6_unicast_cmd);
2351#endif
2352 install_element (BGP_VPNV4_NODE, &exit_address_family_cmd);
2353 install_element (BGP_IPV4_NODE, &exit_address_family_cmd);
2354 install_element (BGP_IPV4M_NODE, &exit_address_family_cmd);
2355 install_element (BGP_IPV6_NODE, &exit_address_family_cmd);
57b5b7ed 2356 install_element (BGP_IPV6M_NODE, &exit_address_family_cmd);
718e3744 2357 install_element (CONFIG_NODE, &key_chain_cmd);
2358 install_element (CONFIG_NODE, &route_map_cmd);
e7168df4 2359 install_element (CONFIG_NODE, &vtysh_line_vty_cmd);
718e3744 2360 install_element (KEYCHAIN_NODE, &key_cmd);
2361 install_element (KEYCHAIN_NODE, &key_chain_cmd);
2362 install_element (KEYCHAIN_KEY_NODE, &key_chain_cmd);
2363 install_element (CONFIG_NODE, &vtysh_interface_cmd);
32d2463c 2364 install_element (CONFIG_NODE, &vtysh_no_interface_cmd);
718e3744 2365 install_element (ENABLE_NODE, &vtysh_show_running_config_cmd);
2366 install_element (ENABLE_NODE, &vtysh_copy_runningconfig_startupconfig_cmd);
2367 install_element (ENABLE_NODE, &vtysh_write_file_cmd);
4a6e2257 2368 install_element (ENABLE_NODE, &vtysh_write_cmd);
718e3744 2369
95e735b5 2370 /* "write terminal" command. */
718e3744 2371 install_element (ENABLE_NODE, &vtysh_write_terminal_cmd);
e7168df4 2372
2373 install_element (CONFIG_NODE, &vtysh_integrated_config_cmd);
2374 install_element (CONFIG_NODE, &no_vtysh_integrated_config_cmd);
718e3744 2375
95e735b5 2376 /* "write memory" command. */
718e3744 2377 install_element (ENABLE_NODE, &vtysh_write_memory_cmd);
718e3744 2378
34553cc3 2379 install_element (VIEW_NODE, &vtysh_terminal_length_cmd);
2380 install_element (ENABLE_NODE, &vtysh_terminal_length_cmd);
2381 install_element (VIEW_NODE, &vtysh_terminal_no_length_cmd);
2382 install_element (ENABLE_NODE, &vtysh_terminal_no_length_cmd);
f2799e69 2383 install_element (VIEW_NODE, &vtysh_show_daemons_cmd);
2384 install_element (ENABLE_NODE, &vtysh_show_daemons_cmd);
34553cc3 2385
718e3744 2386 install_element (VIEW_NODE, &vtysh_ping_cmd);
4eeccf18 2387 install_element (VIEW_NODE, &vtysh_ping_ip_cmd);
718e3744 2388 install_element (VIEW_NODE, &vtysh_traceroute_cmd);
4eeccf18 2389 install_element (VIEW_NODE, &vtysh_traceroute_ip_cmd);
2390#ifdef HAVE_IPV6
2391 install_element (VIEW_NODE, &vtysh_ping6_cmd);
2392 install_element (VIEW_NODE, &vtysh_traceroute6_cmd);
2393#endif
718e3744 2394 install_element (VIEW_NODE, &vtysh_telnet_cmd);
2395 install_element (VIEW_NODE, &vtysh_telnet_port_cmd);
5087df56 2396 install_element (VIEW_NODE, &vtysh_ssh_cmd);
718e3744 2397 install_element (ENABLE_NODE, &vtysh_ping_cmd);
4eeccf18 2398 install_element (ENABLE_NODE, &vtysh_ping_ip_cmd);
718e3744 2399 install_element (ENABLE_NODE, &vtysh_traceroute_cmd);
4eeccf18 2400 install_element (ENABLE_NODE, &vtysh_traceroute_ip_cmd);
2401#ifdef HAVE_IPV6
2402 install_element (ENABLE_NODE, &vtysh_ping6_cmd);
2403 install_element (ENABLE_NODE, &vtysh_traceroute6_cmd);
2404#endif
718e3744 2405 install_element (ENABLE_NODE, &vtysh_telnet_cmd);
2406 install_element (ENABLE_NODE, &vtysh_telnet_port_cmd);
67e29abc 2407 install_element (ENABLE_NODE, &vtysh_ssh_cmd);
718e3744 2408 install_element (ENABLE_NODE, &vtysh_start_shell_cmd);
2409 install_element (ENABLE_NODE, &vtysh_start_bash_cmd);
2410 install_element (ENABLE_NODE, &vtysh_start_zsh_cmd);
dbf7d13d 2411
362b4031
PJ
2412 install_element (VIEW_NODE, &vtysh_show_memory_cmd);
2413 install_element (ENABLE_NODE, &vtysh_show_memory_cmd);
2414
dbf7d13d
PJ
2415 /* Logging */
2416 install_element (ENABLE_NODE, &vtysh_show_logging_cmd);
2417 install_element (VIEW_NODE, &vtysh_show_logging_cmd);
718e3744 2418 install_element (CONFIG_NODE, &vtysh_log_stdout_cmd);
274a4a44 2419 install_element (CONFIG_NODE, &vtysh_log_stdout_level_cmd);
718e3744 2420 install_element (CONFIG_NODE, &no_vtysh_log_stdout_cmd);
2421 install_element (CONFIG_NODE, &vtysh_log_file_cmd);
274a4a44 2422 install_element (CONFIG_NODE, &vtysh_log_file_level_cmd);
718e3744 2423 install_element (CONFIG_NODE, &no_vtysh_log_file_cmd);
274a4a44 2424 install_element (CONFIG_NODE, &no_vtysh_log_file_level_cmd);
2425 install_element (CONFIG_NODE, &vtysh_log_monitor_cmd);
2426 install_element (CONFIG_NODE, &vtysh_log_monitor_level_cmd);
2427 install_element (CONFIG_NODE, &no_vtysh_log_monitor_cmd);
718e3744 2428 install_element (CONFIG_NODE, &vtysh_log_syslog_cmd);
274a4a44 2429 install_element (CONFIG_NODE, &vtysh_log_syslog_level_cmd);
718e3744 2430 install_element (CONFIG_NODE, &no_vtysh_log_syslog_cmd);
2431 install_element (CONFIG_NODE, &vtysh_log_trap_cmd);
2432 install_element (CONFIG_NODE, &no_vtysh_log_trap_cmd);
274a4a44 2433 install_element (CONFIG_NODE, &vtysh_log_facility_cmd);
2434 install_element (CONFIG_NODE, &no_vtysh_log_facility_cmd);
718e3744 2435 install_element (CONFIG_NODE, &vtysh_log_record_priority_cmd);
2436 install_element (CONFIG_NODE, &no_vtysh_log_record_priority_cmd);
c749b722
AS
2437 install_element (CONFIG_NODE, &vtysh_log_timestamp_precision_cmd);
2438 install_element (CONFIG_NODE, &no_vtysh_log_timestamp_precision_cmd);
e7168df4 2439
2440 install_element (CONFIG_NODE, &vtysh_service_password_encrypt_cmd);
2441 install_element (CONFIG_NODE, &no_vtysh_service_password_encrypt_cmd);
2442
2443 install_element (CONFIG_NODE, &vtysh_password_cmd);
2444 install_element (CONFIG_NODE, &vtysh_password_text_cmd);
2445 install_element (CONFIG_NODE, &vtysh_enable_password_cmd);
2446 install_element (CONFIG_NODE, &vtysh_enable_password_text_cmd);
2447 install_element (CONFIG_NODE, &no_vtysh_enable_password_cmd);
2448
718e3744 2449}