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