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