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