]> git.proxmox.com Git - mirror_frr.git/blame - vtysh/vtysh.c
eigrp: Initial Commit
[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
4201dd11 37#include "linklist.h"
718e3744 38#include "command.h"
39#include "memory.h"
039f3a34 40#include "filter.h"
718e3744 41#include "vtysh/vtysh.h"
6099b3b5 42#include "log.h"
320da874 43#include "bgpd/bgp_vty.h"
13460c44 44#include "ns.h"
cd2a8a42 45#include "vrf.h"
eb05883f 46#include "libfrr.h"
718e3744 47
4a1ab8e4
DL
48DEFINE_MTYPE_STATIC(MVTYSH, VTYSH_CMD, "Vtysh cmd copy")
49
718e3744 50/* Struct VTY. */
51struct vty *vty;
52
53/* VTY shell pager name. */
54char *vtysh_pager_name = NULL;
55
56/* VTY shell client structure. */
57struct vtysh_client
58{
59 int fd;
c0e8c16f 60 const char *name;
b1aa147d 61 int flag;
eb05883f 62 char path[MAXPATHLEN];
7c8ff89e
DS
63 struct vtysh_client *next;
64};
65
66struct vtysh_client vtysh_client[] =
67{
eb05883f
DL
68 { .fd = -1, .name = "zebra", .flag = VTYSH_ZEBRA, .next = NULL},
69 { .fd = -1, .name = "ripd", .flag = VTYSH_RIPD, .next = NULL},
70 { .fd = -1, .name = "ripngd", .flag = VTYSH_RIPNGD, .next = NULL},
71 { .fd = -1, .name = "ospfd", .flag = VTYSH_OSPFD, .next = NULL},
72 { .fd = -1, .name = "ospf6d", .flag = VTYSH_OSPF6D, .next = NULL},
73 { .fd = -1, .name = "ldpd", .flag = VTYSH_LDPD, .next = NULL},
74 { .fd = -1, .name = "bgpd", .flag = VTYSH_BGPD, .next = NULL},
75 { .fd = -1, .name = "isisd", .flag = VTYSH_ISISD, .next = NULL},
76 { .fd = -1, .name = "pimd", .flag = VTYSH_PIMD, .next = NULL},
77 { .fd = -1, .name = "nhrpd", .flag = VTYSH_NHRPD, .next = NULL},
7f57883e 78 { .fd = -1, .name = "eigrpd", .flag = VTYSH_EIGRPD, .next = NULL},
eb05883f 79 { .fd = -1, .name = "watchfrr", .flag = VTYSH_WATCHFRR, .next = NULL},
b1aa147d 80};
81
039eaca3 82enum vtysh_write_integrated vtysh_write_integrated = WRITE_INTEGRATED_UNSPECIFIED;
e7168df4 83
274a4a44 84static void
718e3744 85vclient_close (struct vtysh_client *vclient)
86{
b1aa147d 87 if (vclient->fd >= 0)
88 {
89 fprintf(stderr,
90 "Warning: closing connection to %s because of an I/O error!\n",
91 vclient->name);
92 close (vclient->fd);
93 vclient->fd = -1;
94 }
718e3744 95}
96
f35a5350
DW
97/* Return true if str begins with prefix, else return false */
98static int
99begins_with(const char *str, const char *prefix)
100{
101 if (!str || !prefix)
102 return 0;
103 size_t lenstr = strlen(str);
104 size_t lenprefix = strlen(prefix);
105 if (lenprefix > lenstr)
106 return 0;
107 return strncmp(str, prefix, lenprefix) == 0;
108}
109
7526a182
DL
110/* NB: multiplexed function:
111 * if fp == NULL, this calls vtysh_config_parse_line
112 * if fp != NULL, this prints lines to fp
113 */
274a4a44 114static int
7526a182 115vtysh_client_run (struct vtysh_client *vclient, const char *line, FILE *fp)
718e3744 116{
117 int ret;
7526a182
DL
118 char stackbuf[4096];
119 char *buf = stackbuf;
120 size_t bufsz = sizeof(stackbuf);
121 char *bufvalid, *end = NULL;
122 char terminator[3] = {0, 0, 0};
718e3744 123
124 if (vclient->fd < 0)
125 return CMD_SUCCESS;
126
127 ret = write (vclient->fd, line, strlen (line) + 1);
128 if (ret <= 0)
7526a182 129 goto out_err;
7c8ff89e 130
7526a182
DL
131 bufvalid = buf;
132 do
7c8ff89e 133 {
7526a182
DL
134 ssize_t nread = read (vclient->fd, bufvalid, buf + bufsz - bufvalid);
135
136 if (nread < 0 && (errno == EINTR || errno == EAGAIN))
137 continue;
138
139 if (nread <= 0)
140 {
141 fprintf (stderr, "vtysh: error reading from %s: %s (%d)",
142 vclient->name, safe_strerror(errno), errno);
143 goto out_err;
144 }
145
146 bufvalid += nread;
147
148 end = memmem (buf, bufvalid - buf, terminator, sizeof(terminator));
149 if (end + sizeof(terminator) + 1 > bufvalid)
150 /* found \0\0\0 but return code hasn't been read yet */
151 end = NULL;
152 if (end)
153 ret = end[sizeof(terminator)];
154
155 while (bufvalid > buf && (end > buf || !end))
156 {
157 size_t textlen = (end ? end : bufvalid) - buf;
158 char *eol = memchr (buf, '\n', textlen);
159 if (eol)
160 /* line break */
161 *eol++ = '\0';
162 else if (end == buf)
163 /* no line break, end of input, no text left before end
164 * => don't insert an empty line at the end */
165 break;
166 else if (end)
167 /* no line break, end of input, but some text left */
168 eol = end;
169 else
170 /* continue reading */
171 break;
718e3744 172
7526a182
DL
173 /* eol is at a line end now, either \n => \0 or \0\0\0 */
174 assert(eol && eol <= bufvalid);
718e3744 175
7526a182 176 if (fp)
2852de1c 177 {
7526a182
DL
178 fputs (buf, fp);
179 fputc ('\n', fp);
2852de1c 180 }
181 else
7526a182
DL
182 vtysh_config_parse_line (buf);
183
184 if (eol == end)
185 /* \n\0\0\0 */
186 break;
187
188 memmove (buf, eol, bufvalid - eol);
189 bufvalid -= eol - buf;
2d35a720
DL
190 if (end)
191 end -= eol - buf;
7526a182
DL
192 }
193
194 if (bufvalid == buf + bufsz)
195 {
196 char *new;
197 bufsz *= 2;
198 if (buf == stackbuf)
2852de1c 199 {
7526a182
DL
200 new = XMALLOC (MTYPE_TMP, bufsz);
201 memcpy (new, stackbuf, sizeof(stackbuf));
2852de1c 202 }
7526a182
DL
203 else
204 new = XREALLOC (MTYPE_TMP, buf, bufsz);
2852de1c 205
7526a182
DL
206 bufvalid = bufvalid - buf + new;
207 buf = new;
208 /* if end != NULL, we won't be reading more data... */
209 assert (end == NULL);
210 }
718e3744 211 }
7526a182
DL
212 while (!end);
213 goto out;
214
215out_err:
216 vclient_close (vclient);
217 ret = CMD_SUCCESS;
218out:
219 if (buf != stackbuf)
220 XFREE (MTYPE_TMP, buf);
221 return ret;
718e3744 222}
223
7c8ff89e 224static int
7526a182
DL
225vtysh_client_run_all (struct vtysh_client *head_client, const char *line,
226 int continue_on_err, FILE *fp)
7c8ff89e
DS
227{
228 struct vtysh_client *client;
7526a182 229 int rc, rc_all = CMD_SUCCESS;
7c8ff89e 230
7526a182 231 for (client = head_client; client; client = client->next)
7c8ff89e 232 {
7526a182 233 rc = vtysh_client_run(client, line, fp);
7c8ff89e 234 if (rc != CMD_SUCCESS)
7526a182
DL
235 {
236 if (!continue_on_err)
237 return rc;
238 rc_all = rc;
239 }
7c8ff89e 240 }
7526a182
DL
241 return rc_all;
242}
243
244static int
245vtysh_client_execute (struct vtysh_client *head_client, const char *line,
246 FILE *fp)
247{
248 return vtysh_client_run_all (head_client, line, 0, fp);
249}
250
251static void
252vtysh_client_config (struct vtysh_client *head_client, char *line)
253{
254 vtysh_client_run_all (head_client, line, 1, NULL);
7c8ff89e
DS
255}
256
718e3744 257void
b1aa147d 258vtysh_pager_init (void)
718e3744 259{
5a9c53de 260 char *pager_defined;
261
262 pager_defined = getenv ("VTYSH_PAGER");
263
264 if (pager_defined)
265 vtysh_pager_name = strdup (pager_defined);
266 else
34553cc3 267 vtysh_pager_name = strdup ("more");
718e3744 268}
269
270/* Command execution over the vty interface. */
57fb9748 271static int
dda09522 272vtysh_execute_func (const char *line, int pager)
718e3744 273{
2c4d48bc 274 int ret, cmd_stat;
b1aa147d 275 u_int i;
718e3744 276 vector vline;
17aca20b 277 const struct cmd_element *cmd;
718e3744 278 FILE *fp = NULL;
13bfca7a 279 int closepager = 0;
280 int tried = 0;
281 int saved_ret, saved_node;
718e3744 282
95e735b5 283 /* Split readline string up into the vector. */
718e3744 284 vline = cmd_make_strvec (line);
285
286 if (vline == NULL)
57fb9748 287 return CMD_SUCCESS;
718e3744 288
13bfca7a 289 saved_ret = ret = cmd_execute_command (vline, vty, &cmd, 1);
290 saved_node = vty->node;
291
292 /* If command doesn't succeeded in current node, try to walk up in node tree.
293 * Changing vty->node is enough to try it just out without actual walkup in
294 * the vtysh. */
295 while (ret != CMD_SUCCESS && ret != CMD_SUCCESS_DAEMON && ret != CMD_WARNING
296 && vty->node > CONFIG_NODE)
297 {
298 vty->node = node_parent(vty->node);
299 ret = cmd_execute_command (vline, vty, &cmd, 1);
300 tried++;
301 }
302
303 vty->node = saved_node;
304
305 /* If command succeeded in any other node than current (tried > 0) we have
306 * to move into node in the vtysh where it succeeded. */
307 if (ret == CMD_SUCCESS || ret == CMD_SUCCESS_DAEMON || ret == CMD_WARNING)
308 {
bb86c601 309 if ((saved_node == BGP_VPNV4_NODE || saved_node == BGP_VPNV6_NODE
8b1fb8be 310 || saved_node == BGP_ENCAP_NODE || saved_node == BGP_ENCAPV6_NODE
8ecd3266 311 || saved_node == BGP_IPV4_NODE
57b5b7ed 312 || saved_node == BGP_IPV6_NODE || saved_node == BGP_IPV4M_NODE
14a227b8 313 || saved_node == BGP_IPV6M_NODE || saved_node == BGP_EVPN_NODE)
13bfca7a 314 && (tried == 1))
315 {
316 vtysh_execute("exit-address-family");
317 }
5ff06872
LB
318 else if (saved_node == BGP_VRF_POLICY_NODE && (tried == 1))
319 {
320 vtysh_execute("exit-vrf-policy");
321 }
65efcfce
LB
322 else if ((saved_node == BGP_VNC_DEFAULTS_NODE
323 || saved_node == BGP_VNC_NVE_GROUP_NODE
324 || saved_node == BGP_VNC_L2_GROUP_NODE) && (tried == 1))
325 {
326 vtysh_execute("exit-vnc");
327 }
13bfca7a 328 else if ((saved_node == KEYCHAIN_KEY_NODE) && (tried == 1))
329 {
330 vtysh_execute("exit");
331 }
332 else if (tried)
333 {
334 vtysh_execute ("end");
335 vtysh_execute ("configure terminal");
336 }
337 }
338 /* If command didn't succeed in any node, continue with return value from
339 * first try. */
340 else if (tried)
341 {
342 ret = saved_ret;
343 }
718e3744 344
345 cmd_free_strvec (vline);
346
2c4d48bc 347 cmd_stat = ret;
718e3744 348 switch (ret)
349 {
350 case CMD_WARNING:
351 if (vty->type == VTY_FILE)
4fc01e67 352 fprintf (stdout,"Warning...\n");
718e3744 353 break;
354 case CMD_ERR_AMBIGUOUS:
4fc01e67 355 fprintf (stdout,"%% Ambiguous command.\n");
718e3744 356 break;
357 case CMD_ERR_NO_MATCH:
4fc01e67 358 fprintf (stdout,"%% Unknown command.\n");
718e3744 359 break;
360 case CMD_ERR_INCOMPLETE:
4fc01e67 361 fprintf (stdout,"%% Command incomplete.\n");
718e3744 362 break;
363 case CMD_SUCCESS_DAEMON:
364 {
97b7db2d 365 /* FIXME: Don't open pager for exit commands. popen() causes problems
366 * if exited from vtysh at all. This hack shouldn't cause any problem
367 * but is really ugly. */
368 if (pager && vtysh_pager_name && (strncmp(line, "exit", 4) != 0))
718e3744 369 {
4fc01e67 370 fp = popen (vtysh_pager_name, "w");
718e3744 371 if (fp == NULL)
372 {
a805cc2d 373 perror ("popen failed for pager");
374 fp = stdout;
718e3744 375 }
a805cc2d 376 else
377 closepager=1;
718e3744 378 }
379 else
380 fp = stdout;
381
382 if (! strcmp(cmd->string,"configure terminal"))
383 {
837d16cc 384 for (i = 0; i < array_size(vtysh_client); i++)
b1aa147d 385 {
386 cmd_stat = vtysh_client_execute(&vtysh_client[i], line, fp);
387 if (cmd_stat == CMD_WARNING)
388 break;
389 }
390
718e3744 391 if (cmd_stat)
392 {
b094d260 393 line = "end";
394 vline = cmd_make_strvec (line);
718e3744 395
b094d260 396 if (vline == NULL)
718e3744 397 {
a805cc2d 398 if (pager && vtysh_pager_name && fp && closepager)
718e3744 399 {
400 if (pclose (fp) == -1)
401 {
a805cc2d 402 perror ("pclose failed for pager");
718e3744 403 }
404 fp = NULL;
405 }
57fb9748 406 return CMD_SUCCESS;
718e3744 407 }
408
87d683b0 409 ret = cmd_execute_command (vline, vty, &cmd, 1);
b094d260 410 cmd_free_strvec (vline);
411 if (ret != CMD_SUCCESS_DAEMON)
412 break;
718e3744 413 }
414 else
415 if (cmd->func)
416 {
417 (*cmd->func) (cmd, vty, 0, NULL);
418 break;
b094d260 419 }
718e3744 420 }
421
b1aa147d 422 cmd_stat = CMD_SUCCESS;
837d16cc 423 for (i = 0; i < array_size(vtysh_client); i++)
b1aa147d 424 {
425 if (cmd->daemon & vtysh_client[i].flag)
426 {
427 cmd_stat = vtysh_client_execute(&vtysh_client[i], line, fp);
428 if (cmd_stat != CMD_SUCCESS)
429 break;
430 }
431 }
432 if (cmd_stat != CMD_SUCCESS)
433 break;
434
718e3744 435 if (cmd->func)
436 (*cmd->func) (cmd, vty, 0, NULL);
437 }
438 }
a805cc2d 439 if (pager && vtysh_pager_name && fp && closepager)
718e3744 440 {
441 if (pclose (fp) == -1)
442 {
a805cc2d 443 perror ("pclose failed for pager");
718e3744 444 }
445 fp = NULL;
446 }
57fb9748 447 return cmd_stat;
718e3744 448}
449
57fb9748 450int
dda09522 451vtysh_execute_no_pager (const char *line)
718e3744 452{
57fb9748 453 return vtysh_execute_func (line, 0);
718e3744 454}
455
57fb9748 456int
dda09522 457vtysh_execute (const char *line)
718e3744 458{
57fb9748 459 return vtysh_execute_func (line, 1);
718e3744 460}
461
a5b89524
DW
462static char *
463trim (char *s)
464{
465 size_t size;
466 char *end;
467
468 size = strlen(s);
469
470 if (!size)
471 return s;
472
473 end = s + size - 1;
474 while (end >= s && isspace(*end))
475 end--;
476 *(end + 1) = '\0';
477
478 while (*s && isspace(*s))
479 s++;
480
481 return s;
482}
483
0846286b 484int
c0e8c16f 485vtysh_mark_file (const char *filename)
0846286b
DS
486{
487 struct vty *vty;
488 FILE *confp = NULL;
489 int ret;
490 vector vline;
491 int tried = 0;
17aca20b 492 const struct cmd_element *cmd;
0846286b
DS
493 int saved_ret, prev_node;
494 int lineno = 0;
a5b89524
DW
495 char *vty_buf_copy = NULL;
496 char *vty_buf_trimmed = NULL;
0846286b
DS
497
498 if (strncmp("-", filename, 1) == 0)
499 confp = stdin;
500 else
501 confp = fopen (filename, "r");
502
503 if (confp == NULL)
1db63918
DS
504 {
505 fprintf (stderr, "%% Can't open config file %s due to '%s'.\n",
506 filename, safe_strerror (errno));
507 return (CMD_ERR_NO_FILE);
508 }
0846286b
DS
509
510 vty = vty_new ();
511 vty->fd = 0; /* stdout */
512 vty->type = VTY_TERM;
513 vty->node = CONFIG_NODE;
514
515 vtysh_execute_no_pager ("enable");
516 vtysh_execute_no_pager ("configure terminal");
4a1ab8e4 517 vty_buf_copy = XCALLOC (MTYPE_VTYSH_CMD, VTY_BUFSIZ);
0846286b
DS
518
519 while (fgets (vty->buf, VTY_BUFSIZ, confp))
520 {
521 lineno++;
522 tried = 0;
a5b89524
DW
523 strcpy(vty_buf_copy, vty->buf);
524 vty_buf_trimmed = trim(vty_buf_copy);
0846286b 525
a5b89524 526 if (vty_buf_trimmed[0] == '!' || vty_buf_trimmed[0] == '#')
0846286b
DS
527 {
528 fprintf(stdout, "%s", vty->buf);
529 continue;
530 }
531
532 /* Split readline string up into the vector. */
533 vline = cmd_make_strvec (vty->buf);
534
535 if (vline == NULL)
536 {
537 fprintf(stdout, "%s", vty->buf);
538 continue;
539 }
540
a5b89524
DW
541 /* Ignore the "end" lines, we will generate these where appropriate */
542 if (strlen(vty_buf_trimmed) == 3 && strncmp("end", vty_buf_trimmed, 3) == 0)
543 {
544 continue;
545 }
546
0846286b
DS
547 prev_node = vty->node;
548 saved_ret = ret = cmd_execute_command_strict (vline, vty, &cmd);
549
550 /* If command doesn't succeeded in current node, try to walk up in node tree.
551 * Changing vty->node is enough to try it just out without actual walkup in
552 * the vtysh. */
553 while (ret != CMD_SUCCESS && ret != CMD_SUCCESS_DAEMON && ret != CMD_WARNING
554 && vty->node > CONFIG_NODE)
555 {
556 vty->node = node_parent(vty->node);
557 ret = cmd_execute_command_strict (vline, vty, &cmd);
558 tried++;
559 }
560
561 /* If command succeeded in any other node than current (tried > 0) we have
562 * to move into node in the vtysh where it succeeded. */
563 if (ret == CMD_SUCCESS || ret == CMD_SUCCESS_DAEMON || ret == CMD_WARNING)
564 {
565 if ((prev_node == BGP_VPNV4_NODE || prev_node == BGP_IPV4_NODE
566 || prev_node == BGP_IPV6_NODE || prev_node == BGP_IPV4M_NODE
14a227b8
PG
567 || prev_node == BGP_IPV6M_NODE || prev_node == BGP_VPNV6_NODE
568 || prev_node == BGP_EVPN_NODE)
0846286b
DS
569 && (tried == 1))
570 {
571 fprintf(stdout, "exit-address-family\n");
572 }
573 else if ((prev_node == KEYCHAIN_KEY_NODE) && (tried == 1))
574 {
575 fprintf(stdout, "exit\n");
576 }
577 else if (tried)
578 {
579 fprintf(stdout, "end\n");
580 }
581 }
582 /* If command didn't succeed in any node, continue with return value from
583 * first try. */
584 else if (tried)
585 {
586 ret = saved_ret;
587 vty->node = prev_node;
588 }
589
590 cmd_free_strvec (vline);
591 switch (ret)
592 {
593 case CMD_WARNING:
594 if (vty->type == VTY_FILE)
595 fprintf (stderr,"line %d: Warning...: %s\n", lineno, vty->buf);
596 fclose(confp);
597 vty_close(vty);
4a1ab8e4 598 XFREE(MTYPE_VTYSH_CMD, vty_buf_copy);
1db63918 599 return CMD_WARNING;
0846286b
DS
600 case CMD_ERR_AMBIGUOUS:
601 fprintf (stderr,"line %d: %% Ambiguous command: %s\n", lineno, vty->buf);
602 fclose(confp);
603 vty_close(vty);
4a1ab8e4 604 XFREE(MTYPE_VTYSH_CMD, vty_buf_copy);
1db63918 605 return CMD_ERR_AMBIGUOUS;
0846286b
DS
606 case CMD_ERR_NO_MATCH:
607 fprintf (stderr,"line %d: %% Unknown command: %s\n", lineno, vty->buf);
608 fclose(confp);
609 vty_close(vty);
4a1ab8e4 610 XFREE(MTYPE_VTYSH_CMD, vty_buf_copy);
1db63918 611 return CMD_ERR_NO_MATCH;
0846286b
DS
612 case CMD_ERR_INCOMPLETE:
613 fprintf (stderr,"line %d: %% Command incomplete: %s\n", lineno, vty->buf);
614 fclose(confp);
615 vty_close(vty);
4a1ab8e4 616 XFREE(MTYPE_VTYSH_CMD, vty_buf_copy);
1db63918 617 return CMD_ERR_INCOMPLETE;
0846286b
DS
618 case CMD_SUCCESS:
619 fprintf(stdout, "%s", vty->buf);
620 break;
621 case CMD_SUCCESS_DAEMON:
622 {
623 u_int i;
624 int cmd_stat = CMD_SUCCESS;
625
626 fprintf(stdout, "%s", vty->buf);
627 for (i = 0; i < array_size(vtysh_client); i++)
628 {
629 if (cmd->daemon & vtysh_client[i].flag)
630 {
631 cmd_stat = vtysh_client_execute (&vtysh_client[i],
632 vty->buf, stdout);
633 if (cmd_stat != CMD_SUCCESS)
634 break;
635 }
636 }
637 if (cmd_stat != CMD_SUCCESS)
638 break;
639
640 if (cmd->func)
641 (*cmd->func) (cmd, vty, 0, NULL);
642 }
643 }
644 }
645 /* This is the end */
646 fprintf(stdout, "end\n");
647 vty_close(vty);
4a1ab8e4 648 XFREE(MTYPE_VTYSH_CMD, vty_buf_copy);
0846286b
DS
649
650 if (confp != stdin)
651 fclose(confp);
652
653 return (0);
654}
655
718e3744 656/* Configration make from file. */
3221dca8 657int
718e3744 658vtysh_config_from_file (struct vty *vty, FILE *fp)
659{
660 int ret;
17aca20b 661 const struct cmd_element *cmd;
9117f21e 662 int lineno = 0;
3221dca8 663 int retcode = CMD_SUCCESS;
718e3744 664
665 while (fgets (vty->buf, VTY_BUFSIZ, fp))
666 {
9117f21e 667 lineno++;
718e3744 668
bed578b8 669 ret = command_config_read_one_line (vty, &cmd, 1);
718e3744 670
671 switch (ret)
672 {
673 case CMD_WARNING:
674 if (vty->type == VTY_FILE)
1db63918
DS
675 fprintf (stderr,"line %d: Warning[%d]...: %s\n", lineno, vty->node, vty->buf);
676 retcode = CMD_WARNING; /* once we have an error, we remember & return that */
718e3744 677 break;
678 case CMD_ERR_AMBIGUOUS:
1db63918
DS
679 fprintf (stderr,"line %d: %% Ambiguous command[%d]: %s\n", lineno, vty->node, vty->buf);
680 retcode = CMD_ERR_AMBIGUOUS; /* once we have an error, we remember & return that */
718e3744 681 break;
682 case CMD_ERR_NO_MATCH:
1db63918
DS
683 fprintf (stderr,"line %d: %% Unknown command[%d]: %s", lineno, vty->node, vty->buf);
684 retcode = CMD_ERR_NO_MATCH; /* once we have an error, we remember & return that */
718e3744 685 break;
686 case CMD_ERR_INCOMPLETE:
1db63918
DS
687 fprintf (stderr,"line %d: %% Command incomplete[%d]: %s\n", lineno, vty->node, vty->buf);
688 retcode = CMD_ERR_INCOMPLETE; /* once we have an error, we remember & return that */
718e3744 689 break;
690 case CMD_SUCCESS_DAEMON:
691 {
b1aa147d 692 u_int i;
693 int cmd_stat = CMD_SUCCESS;
694
837d16cc 695 for (i = 0; i < array_size(vtysh_client); i++)
b1aa147d 696 {
44316fef 697 if (cmd->daemon & vtysh_client[i].flag)
b1aa147d 698 {
699 cmd_stat = vtysh_client_execute (&vtysh_client[i],
700 vty->buf, stdout);
279c6956
DS
701 /*
702 * CMD_WARNING - Can mean that the command was
703 * parsed successfully but it was already entered
704 * in a few spots. As such if we receive a
705 * CMD_WARNING from a daemon we shouldn't stop
706 * talking to the other daemons for the particular
707 * command.
708 */
709 if (cmd_stat != CMD_SUCCESS && cmd_stat != CMD_WARNING)
1db63918
DS
710 {
711 fprintf (stderr, "line %d: Failure to communicate[%d] to %s, line: %s\n",
712 lineno, cmd_stat, vtysh_client[i].name, vty->buf);
713 break;
714 }
b1aa147d 715 }
716 }
717 if (cmd_stat != CMD_SUCCESS)
718 break;
719
718e3744 720 if (cmd->func)
721 (*cmd->func) (cmd, vty, 0, NULL);
722 }
723 }
724 }
3221dca8
DS
725
726 return (retcode);
718e3744 727}
728
729/* We don't care about the point of the cursor when '?' is typed. */
4201dd11 730static int
b1aa147d 731vtysh_rl_describe (void)
718e3744 732{
733 int ret;
dda09522 734 unsigned int i;
718e3744 735 vector vline;
736 vector describe;
737 int width;
cd40b329 738 struct cmd_token *token;
718e3744 739
740 vline = cmd_make_strvec (rl_line_buffer);
741
742 /* In case of '> ?'. */
743 if (vline == NULL)
744 {
745 vline = vector_init (1);
9f7d541a 746 vector_set (vline, NULL);
718e3744 747 }
748 else
749 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
9f7d541a 750 vector_set (vline, NULL);
718e3744 751
752 describe = cmd_describe_command (vline, vty, &ret);
753
4fc01e67 754 fprintf (stdout,"\n");
718e3744 755
756 /* Ambiguous and no match error. */
757 switch (ret)
758 {
759 case CMD_ERR_AMBIGUOUS:
760 cmd_free_strvec (vline);
4fc01e67 761 fprintf (stdout,"%% Ambiguous command.\n");
718e3744 762 rl_on_new_line ();
763 return 0;
764 break;
765 case CMD_ERR_NO_MATCH:
766 cmd_free_strvec (vline);
4fc01e67 767 fprintf (stdout,"%% There is no matched command.\n");
718e3744 768 rl_on_new_line ();
769 return 0;
770 break;
771 }
772
773 /* Get width of command string. */
774 width = 0;
55468c86 775 for (i = 0; i < vector_active (describe); i++)
cd40b329 776 if ((token = vector_slot (describe, i)) != NULL)
718e3744 777 {
c3f24f06
QY
778 if (token->text[0] == '\0')
779 continue;
718e3744 780
c3f24f06 781 int len = strlen (token->text);
718e3744 782
c3f24f06
QY
783 if (width < len)
784 width = len;
718e3744 785 }
786
55468c86 787 for (i = 0; i < vector_active (describe); i++)
cd40b329 788 if ((token = vector_slot (describe, i)) != NULL)
718e3744 789 {
cd40b329 790 if (! token->desc)
4fc01e67 791 fprintf (stdout," %-s\n",
c3f24f06 792 token->text);
718e3744 793 else
4fc01e67 794 fprintf (stdout," %-*s %s\n",
b094d260 795 width,
c3f24f06 796 token->text,
cd40b329 797 token->desc);
718e3744 798 }
799
800 cmd_free_strvec (vline);
801 vector_free (describe);
802
803 rl_on_new_line();
804
805 return 0;
806}
807
95e735b5 808/* Result of cmd_complete_command() call will be stored here
809 * and used in new_completion() in order to put the space in
810 * correct places only. */
718e3744 811int complete_status;
812
274a4a44 813static char *
dfc0d9ba 814command_generator (const char *text, int state)
718e3744 815{
816 vector vline;
817 static char **matched = NULL;
818 static int index = 0;
819
820 /* First call. */
821 if (! state)
822 {
823 index = 0;
824
825 if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
826 return NULL;
827
828 vline = cmd_make_strvec (rl_line_buffer);
829 if (vline == NULL)
830 return NULL;
831
832 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
9f7d541a 833 vector_set (vline, NULL);
718e3744 834
835 matched = cmd_complete_command (vline, vty, &complete_status);
039dc612 836 cmd_free_strvec (vline);
718e3744 837 }
838
839 if (matched && matched[index])
840 return matched[index++];
841
66d29a54
DL
842 XFREE (MTYPE_TMP, matched);
843 matched = NULL;
844
718e3744 845 return NULL;
846}
847
274a4a44 848static char **
718e3744 849new_completion (char *text, int start, int end)
850{
851 char **matches;
852
dfc0d9ba 853 matches = rl_completion_matches (text, command_generator);
718e3744 854
855 if (matches)
856 {
857 rl_point = rl_end;
67e7a212
CF
858 if (complete_status != CMD_COMPLETE_FULL_MATCH)
859 /* only append a space on full match */
860 rl_completion_append_character = '\0';
718e3744 861 }
862
863 return matches;
864}
865
95e735b5 866/* Vty node structures. */
7fc626de 867static struct cmd_node bgp_node =
718e3744 868{
869 BGP_NODE,
870 "%s(config-router)# ",
871};
872
7fc626de 873static struct cmd_node rip_node =
718e3744 874{
875 RIP_NODE,
876 "%s(config-router)# ",
877};
878
7fc626de 879static struct cmd_node isis_node =
c25e458a 880{
881 ISIS_NODE,
882 "%s(config-router)# ",
c25e458a 883};
884
7fc626de 885static struct cmd_node interface_node =
718e3744 886{
887 INTERFACE_NODE,
888 "%s(config-if)# ",
889};
890
13460c44
FL
891static struct cmd_node ns_node =
892{
893 NS_NODE,
894 "%s(config-logical-router)# ",
895};
896
e9d94ea7
DS
897static struct cmd_node vrf_node =
898{
899 VRF_NODE,
900 "%s(config-vrf)# ",
901};
902
7fc626de 903static struct cmd_node rmap_node =
95e735b5 904{
905 RMAP_NODE,
906 "%s(config-route-map)# "
907};
908
7fc626de 909static struct cmd_node zebra_node =
95e735b5 910{
911 ZEBRA_NODE,
912 "%s(config-router)# "
913};
914
7fc626de 915static struct cmd_node bgp_vpnv4_node =
95e735b5 916{
917 BGP_VPNV4_NODE,
918 "%s(config-router-af)# "
919};
920
8ecd3266 921static struct cmd_node bgp_vpnv6_node =
922{
923 BGP_VPNV6_NODE,
924 "%s(config-router-af)# "
925};
926
8b1fb8be
LB
927static struct cmd_node bgp_encap_node =
928{
929 BGP_ENCAP_NODE,
930 "%s(config-router-af)# "
931};
932
933static struct cmd_node bgp_encapv6_node =
934{
935 BGP_ENCAPV6_NODE,
936 "%s(config-router-af)# "
937};
938
7fc626de 939static struct cmd_node bgp_ipv4_node =
95e735b5 940{
941 BGP_IPV4_NODE,
942 "%s(config-router-af)# "
943};
944
7fc626de 945static struct cmd_node bgp_ipv4m_node =
95e735b5 946{
947 BGP_IPV4M_NODE,
948 "%s(config-router-af)# "
949};
950
7fc626de 951static struct cmd_node bgp_ipv6_node =
95e735b5 952{
953 BGP_IPV6_NODE,
954 "%s(config-router-af)# "
955};
956
7fc626de 957static struct cmd_node bgp_ipv6m_node =
57b5b7ed 958{
959 BGP_IPV6M_NODE,
960 "%s(config-router-af)# "
961};
962
14a227b8
PG
963static struct cmd_node bgp_evpn_node =
964{
965 BGP_EVPN_NODE,
966 "%s(config-router-af)# "
967};
968
65efcfce
LB
969static struct cmd_node bgp_vnc_defaults_node =
970{
971 BGP_VNC_DEFAULTS_NODE,
972 "%s(config-router-vnc-defaults)# "
973};
974
975static struct cmd_node bgp_vnc_nve_group_node =
976{
977 BGP_VNC_NVE_GROUP_NODE,
978 "%s(config-router-vnc-nve-group)# "
979};
980
5ff06872
LB
981static struct cmd_node bgp_vrf_policy_node = {
982 BGP_VRF_POLICY_NODE,
983 "%s(config-router-vrf-policy)# "
984};
985
65efcfce
LB
986static struct cmd_node bgp_vnc_l2_group_node =
987{
988 BGP_VNC_L2_GROUP_NODE,
989 "%s(config-router-vnc-l2-group)# "
990};
991
7fc626de 992static struct cmd_node ospf_node =
95e735b5 993{
994 OSPF_NODE,
995 "%s(config-router)# "
996};
997
7f57883e
DS
998static struct cmd_node eigrp_node =
999{
1000 EIGRP_NODE,
1001 "%s(config-router)# "
1002};
1003
7fc626de 1004static struct cmd_node ripng_node =
95e735b5 1005{
1006 RIPNG_NODE,
1007 "%s(config-router)# "
1008};
1009
7fc626de 1010static struct cmd_node ospf6_node =
95e735b5 1011{
1012 OSPF6_NODE,
1013 "%s(config-ospf6)# "
1014};
1015
4fcbf6e2
RW
1016static struct cmd_node ldp_node =
1017{
1018 LDP_NODE,
1019 "%s(config-ldp)# "
1020};
1021
1022static struct cmd_node ldp_ipv4_node =
1023{
1024 LDP_IPV4_NODE,
1025 "%s(config-ldp-af)# "
1026};
1027
1028static struct cmd_node ldp_ipv6_node =
1029{
1030 LDP_IPV6_NODE,
1031 "%s(config-ldp-af)# "
1032};
1033
1034static struct cmd_node ldp_ipv4_iface_node =
1035{
1036 LDP_IPV4_IFACE_NODE,
1037 "%s(config-ldp-af-if)# "
1038};
1039
1040static struct cmd_node ldp_ipv6_iface_node =
1041{
1042 LDP_IPV6_IFACE_NODE,
1043 "%s(config-ldp-af-if)# "
1044};
1045
1046static struct cmd_node ldp_l2vpn_node =
1047{
1048 LDP_L2VPN_NODE,
1049 "%s(config-l2vpn)# "
1050};
1051
1052static struct cmd_node ldp_pseudowire_node =
1053{
1054 LDP_PSEUDOWIRE_NODE,
1055 "%s(config-l2vpn-pw)# "
1056};
1057
7fc626de 1058static struct cmd_node keychain_node =
95e735b5 1059{
1060 KEYCHAIN_NODE,
1061 "%s(config-keychain)# "
1062};
1063
7fc626de 1064static struct cmd_node keychain_key_node =
95e735b5 1065{
1066 KEYCHAIN_KEY_NODE,
1067 "%s(config-keychain-key)# "
1068};
1069
16f1b9ee
OD
1070struct cmd_node link_params_node =
1071{
1072 LINK_PARAMS_NODE,
1073 "%s(config-link-params)# ",
1074};
1075
e7168df4 1076/* Defined in lib/vty.c */
1077extern struct cmd_node vty_node;
1078
95e735b5 1079/* When '^Z' is received from vty, move down to the enable mode. */
4201dd11 1080static int
b1aa147d 1081vtysh_end (void)
95e735b5 1082{
1083 switch (vty->node)
1084 {
1085 case VIEW_NODE:
1086 case ENABLE_NODE:
1087 /* Nothing to do. */
1088 break;
1089 default:
1090 vty->node = ENABLE_NODE;
1091 break;
1092 }
1093 return CMD_SUCCESS;
1094}
1095
4a96e944 1096DEFUNSH (VTYSH_REALLYALL,
95e735b5 1097 vtysh_end_all,
1098 vtysh_end_all_cmd,
1099 "end",
e7168df4 1100 "End current mode and change to enable mode\n")
95e735b5 1101{
4289546d 1102 return vtysh_end ();
95e735b5 1103}
1104
718e3744 1105DEFUNSH (VTYSH_BGPD,
1106 router_bgp,
1107 router_bgp_cmd,
a98d33ab 1108 "router bgp [(1-4294967295) [<view|vrf> WORD]]",
718e3744 1109 ROUTER_STR
1110 BGP_STR
a98d33ab
QY
1111 AS_STR
1112 "BGP view\nBGP VRF\n"
1113 "View/VRF name\n")
718e3744 1114{
1115 vty->node = BGP_NODE;
1116 return CMD_SUCCESS;
1117}
1118
1119DEFUNSH (VTYSH_BGPD,
1120 address_family_vpnv4,
1121 address_family_vpnv4_cmd,
843d75b1 1122 "address-family vpnv4 [unicast]",
718e3744 1123 "Enter Address Family command mode\n"
843d75b1 1124 "Address Family\n"
718e3744 1125 "Address Family Modifier\n")
1126{
1127 vty->node = BGP_VPNV4_NODE;
1128 return CMD_SUCCESS;
1129}
1130
8ecd3266 1131DEFUNSH (VTYSH_BGPD,
1132 address_family_vpnv6,
1133 address_family_vpnv6_cmd,
843d75b1 1134 "address-family vpnv6 [unicast]",
8ecd3266 1135 "Enter Address Family command mode\n"
843d75b1 1136 "Address Family\n"
8ecd3266 1137 "Address Family Modifier\n")
1138{
1139 vty->node = BGP_VPNV6_NODE;
1140 return CMD_SUCCESS;
1141}
1142
8b1fb8be
LB
1143DEFUNSH (VTYSH_BGPD,
1144 address_family_encapv4,
1145 address_family_encapv4_cmd,
4c4ff4c1 1146 "address-family <encap|encapv4>",
8b1fb8be 1147 "Enter Address Family command mode\n"
4c4ff4c1 1148 "Address Family\n"
843d75b1 1149 "Address Family\n")
8b1fb8be
LB
1150{
1151 vty->node = BGP_ENCAP_NODE;
1152 return CMD_SUCCESS;
1153}
1154
1155DEFUNSH (VTYSH_BGPD,
1156 address_family_encapv6,
1157 address_family_encapv6_cmd,
1158 "address-family encapv6",
1159 "Enter Address Family command mode\n"
843d75b1 1160 "Address Family\n")
8b1fb8be
LB
1161{
1162 vty->node = BGP_ENCAPV6_NODE;
1163 return CMD_SUCCESS;
1164}
1165
718e3744 1166DEFUNSH (VTYSH_BGPD,
1167 address_family_ipv4_unicast,
1168 address_family_ipv4_unicast_cmd,
c7f1274b 1169 "address-family ipv4 [<unicast|multicast|vpn|encap>]",
718e3744 1170 "Enter Address Family command mode\n"
843d75b1 1171 "Address Family\n"
c7f1274b
DS
1172 "Address Family Modifier\n"
1173 "Address Family Modifier\n"
1174 "Address Family Modifier\n"
1175 "Address Family Modifier\n")
718e3744 1176{
c7f1274b
DS
1177 int idx = 0;
1178
1179 if (argv_find (argv, argc, "multicast", &idx))
1180 vty->node = BGP_IPV4M_NODE;
1181
1182 else if (argv_find (argv, argc, "encap", &idx))
1183 vty->node = BGP_ENCAP_NODE;
1184
1185 else if (argv_find (argv, argc, "vpn", &idx))
1186 vty->node = BGP_VPNV4_NODE;
1187
1188 else
1189 vty->node = BGP_IPV4_NODE;
718e3744 1190
718e3744 1191 return CMD_SUCCESS;
1192}
1193
1194DEFUNSH (VTYSH_BGPD,
1195 address_family_ipv6,
1196 address_family_ipv6_cmd,
c7f1274b 1197 "address-family ipv6 [<unicast|multicast|vpn|encap>]",
718e3744 1198 "Enter Address Family command mode\n"
843d75b1 1199 "Address Family\n"
c7f1274b
DS
1200 "Address Family Modifier\n"
1201 "Address Family Modifier\n"
1202 "Address Family Modifier\n"
1203 "Address Family Modifier\n")
718e3744 1204{
c7f1274b
DS
1205 int idx = 0;
1206
1207 if (argv_find (argv, argc, "multicast", &idx))
1208 vty->node = BGP_IPV6M_NODE;
1209
1210 else if (argv_find (argv, argc, "encap", &idx))
1211 vty->node = BGP_ENCAPV6_NODE;
1212
1213 else if (argv_find (argv, argc, "vpn", &idx))
1214 vty->node = BGP_VPNV6_NODE;
1215
1216 else
1217 vty->node = BGP_IPV6_NODE;
718e3744 1218
57b5b7ed 1219 return CMD_SUCCESS;
1220}
1221
14a227b8
PG
1222DEFUNSH (VTYSH_BGPD,
1223 address_family_evpn,
1224 address_family_evpn_cmd,
b194703e 1225 "address-family <l2vpn evpn>",
14a227b8 1226 "Enter Address Family command mode\n"
61a51962
PG
1227 "EVPN Address family\n"
1228 "Layer2 VPN Address family\n"
1229 "Ethernet Virtual Private Network Subsequent Address Family\n")
14a227b8
PG
1230{
1231#if defined(HAVE_EVPN)
1232 vty->node = BGP_EVPN_NODE;
1233#endif /* HAVE_EVPN */
1234 return CMD_SUCCESS;
1235}
1236
87ab4aec 1237#if defined (ENABLE_BGP_VNC)
65efcfce
LB
1238DEFUNSH (VTYSH_BGPD,
1239 vnc_defaults,
1240 vnc_defaults_cmd,
1241 "vnc defaults",
1242 "VNC/RFP related configuration\n"
1243 "Configure default NVE group\n")
1244{
1245 vty->node = BGP_VNC_DEFAULTS_NODE;
1246 return CMD_SUCCESS;
1247}
1248
1249DEFUNSH (VTYSH_BGPD,
1250 vnc_nve_group,
1251 vnc_nve_group_cmd,
1252 "vnc nve-group NAME",
1253 "VNC/RFP related configuration\n"
1254 "Configure a NVE group\n"
1255 "Group name\n")
1256{
1257 vty->node = BGP_VNC_NVE_GROUP_NODE;
1258 return CMD_SUCCESS;
1259}
1260
5ff06872
LB
1261DEFUNSH (VTYSH_BGPD,
1262 vnc_vrf_policy,
1263 vnc_vrf_policy_cmd,
1264 "vrf-policy NAME",
1265 "Configure a VRF policy group\n"
1266 "Group name\n")
1267{
1268 vty->node = BGP_VRF_POLICY_NODE;
1269 return CMD_SUCCESS;
1270}
1271
65efcfce
LB
1272DEFUNSH (VTYSH_BGPD,
1273 vnc_l2_group,
1274 vnc_l2_group_cmd,
1275 "vnc l2-group NAME",
1276 "VNC/RFP related configuration\n"
1277 "Configure a L2 group\n"
1278 "Group name\n")
1279{
1280 vty->node = BGP_VNC_L2_GROUP_NODE;
1281 return CMD_SUCCESS;
1282}
87ab4aec 1283#endif
65efcfce 1284
718e3744 1285DEFUNSH (VTYSH_RIPD,
1286 key_chain,
1287 key_chain_cmd,
1288 "key chain WORD",
1289 "Authentication key management\n"
1290 "Key-chain management\n"
1291 "Key-chain name\n")
1292{
1293 vty->node = KEYCHAIN_NODE;
1294 return CMD_SUCCESS;
1295}
1296
1297DEFUNSH (VTYSH_RIPD,
1298 key,
1299 key_cmd,
a98d33ab 1300 "key (0-2147483647)",
718e3744 1301 "Configure a key\n"
1302 "Key identifier number\n")
1303{
1304 vty->node = KEYCHAIN_KEY_NODE;
1305 return CMD_SUCCESS;
1306}
1307
1308DEFUNSH (VTYSH_RIPD,
1309 router_rip,
1310 router_rip_cmd,
1311 "router rip",
1312 ROUTER_STR
1313 "RIP")
1314{
1315 vty->node = RIP_NODE;
1316 return CMD_SUCCESS;
1317}
1318
1319DEFUNSH (VTYSH_RIPNGD,
1320 router_ripng,
1321 router_ripng_cmd,
1322 "router ripng",
1323 ROUTER_STR
1324 "RIPng")
1325{
1326 vty->node = RIPNG_NODE;
1327 return CMD_SUCCESS;
1328}
1329
1330DEFUNSH (VTYSH_OSPFD,
1331 router_ospf,
1332 router_ospf_cmd,
a98d33ab 1333 "router ospf [(1-65535)]",
718e3744 1334 "Enable a routing process\n"
a98d33ab
QY
1335 "Start OSPF configuration\n"
1336 "Instance ID\n")
718e3744 1337{
1338 vty->node = OSPF_NODE;
1339 return CMD_SUCCESS;
1340}
1341
7f57883e
DS
1342DEFUNSH (VTYSH_EIGRPD,
1343 router_eigrp,
1344 router_eigrp_cmd,
1345 "router eigrp (1-65535)",
1346 "Enable a routing process\n"
1347 "Start EIGRP configuration\n"
1348 "AS number to use\n")
1349{
1350 vty->node = EIGRP_NODE;
1351 return CMD_SUCCESS;
1352}
1353
718e3744 1354DEFUNSH (VTYSH_OSPF6D,
1355 router_ospf6,
1356 router_ospf6_cmd,
1357 "router ospf6",
16cedbb0 1358 ROUTER_STR
718e3744 1359 OSPF6_STR)
1360{
1361 vty->node = OSPF6_NODE;
1362 return CMD_SUCCESS;
1363}
1364
87ab4aec 1365#if defined (HAVE_LDPD)
4fcbf6e2
RW
1366DEFUNSH (VTYSH_LDPD,
1367 ldp_mpls_ldp,
1368 ldp_mpls_ldp_cmd,
1369 "mpls ldp",
1370 "Global MPLS configuration subcommands\n"
1371 "Label Distribution Protocol\n")
1372{
1373 vty->node = LDP_NODE;
1374 return CMD_SUCCESS;
1375}
1376
1377DEFUNSH (VTYSH_LDPD,
1378 ldp_address_family_ipv4,
1379 ldp_address_family_ipv4_cmd,
1380 "address-family ipv4",
1381 "Configure Address Family and its parameters\n"
1382 "IPv4\n")
1383{
1384 vty->node = LDP_IPV4_NODE;
1385 return CMD_SUCCESS;
1386}
1387
1388DEFUNSH (VTYSH_LDPD,
1389 ldp_address_family_ipv6,
1390 ldp_address_family_ipv6_cmd,
1391 "address-family ipv6",
1392 "Configure Address Family and its parameters\n"
1393 "IPv6\n")
1394{
1395 vty->node = LDP_IPV6_NODE;
1396 return CMD_SUCCESS;
1397}
1398
1399DEFUNSH (VTYSH_LDPD,
1400 ldp_interface_ifname,
1401 ldp_interface_ifname_cmd,
1402 "interface IFNAME",
1403 "Enable LDP on an interface and enter interface submode\n"
1404 "Interface's name\n")
1405{
1406 switch (vty->node)
1407 {
1408 case LDP_IPV4_NODE:
1409 vty->node = LDP_IPV4_IFACE_NODE;
1410 break;
1411 case LDP_IPV6_NODE:
1412 vty->node = LDP_IPV6_IFACE_NODE;
1413 break;
1414 default:
1415 break;
1416 }
1417
1418 return CMD_SUCCESS;
1419}
1420
1421DEFUNSH (VTYSH_LDPD,
1422 ldp_l2vpn_word_type_vpls,
1423 ldp_l2vpn_word_type_vpls_cmd,
1424 "l2vpn WORD type vpls",
1425 "Configure l2vpn commands\n"
1426 "L2VPN name\n"
1427 "L2VPN type\n"
1428 "Virtual Private LAN Service\n")
1429{
1430 vty->node = LDP_L2VPN_NODE;
1431 return CMD_SUCCESS;
1432}
1433
1434DEFUNSH (VTYSH_LDPD,
1435 ldp_member_pseudowire_ifname,
1436 ldp_member_pseudowire_ifname_cmd,
1437 "member pseudowire IFNAME",
1438 "L2VPN member configuration\n"
1439 "Pseudowire interface\n"
1440 "Interface's name\n")
1441{
1442 vty->node = LDP_PSEUDOWIRE_NODE;
1443 return CMD_SUCCESS;
1444}
87ab4aec 1445#endif
4fcbf6e2 1446
c25e458a 1447DEFUNSH (VTYSH_ISISD,
b094d260 1448 router_isis,
1449 router_isis_cmd,
1450 "router isis WORD",
1451 ROUTER_STR
1452 "ISO IS-IS\n"
1453 "ISO Routing area tag")
c25e458a 1454{
1455 vty->node = ISIS_NODE;
1456 return CMD_SUCCESS;
1457}
1458
718e3744 1459DEFUNSH (VTYSH_RMAP,
dd2ecded
DS
1460 vtysh_route_map,
1461 vtysh_route_map_cmd,
a98d33ab 1462 "route-map WORD <deny|permit> (1-65535)",
718e3744 1463 "Create route-map or enter route-map command mode\n"
1464 "Route map tag\n"
1465 "Route map denies set operations\n"
1466 "Route map permits set operations\n"
1467 "Sequence to insert to/delete from existing route-map entry\n")
1468{
1469 vty->node = RMAP_NODE;
1470 return CMD_SUCCESS;
1471}
1472
e7168df4 1473DEFUNSH (VTYSH_ALL,
1474 vtysh_line_vty,
1475 vtysh_line_vty_cmd,
1476 "line vty",
1477 "Configure a terminal line\n"
1478 "Virtual terminal\n")
1479{
1480 vty->node = VTY_NODE;
1481 return CMD_SUCCESS;
1482}
1483
4a96e944
DL
1484DEFUNSH (VTYSH_REALLYALL,
1485 vtysh_enable,
718e3744 1486 vtysh_enable_cmd,
1487 "enable",
1488 "Turn on privileged mode command\n")
1489{
1490 vty->node = ENABLE_NODE;
1491 return CMD_SUCCESS;
1492}
1493
4a96e944
DL
1494DEFUNSH (VTYSH_REALLYALL,
1495 vtysh_disable,
718e3744 1496 vtysh_disable_cmd,
1497 "disable",
1498 "Turn off privileged mode command\n")
1499{
1500 if (vty->node == ENABLE_NODE)
1501 vty->node = VIEW_NODE;
1502 return CMD_SUCCESS;
1503}
1504
4a96e944 1505DEFUNSH (VTYSH_REALLYALL,
718e3744 1506 vtysh_config_terminal,
1507 vtysh_config_terminal_cmd,
1508 "configure terminal",
1509 "Configuration from vty interface\n"
1510 "Configuration terminal\n")
1511{
1512 vty->node = CONFIG_NODE;
1513 return CMD_SUCCESS;
1514}
1515
274a4a44 1516static int
718e3744 1517vtysh_exit (struct vty *vty)
1518{
1519 switch (vty->node)
1520 {
1521 case VIEW_NODE:
1522 case ENABLE_NODE:
1523 exit (0);
1524 break;
1525 case CONFIG_NODE:
1526 vty->node = ENABLE_NODE;
1527 break;
1528 case INTERFACE_NODE:
13460c44 1529 case NS_NODE:
e9d94ea7 1530 case VRF_NODE:
718e3744 1531 case ZEBRA_NODE:
1532 case BGP_NODE:
1533 case RIP_NODE:
1534 case RIPNG_NODE:
1535 case OSPF_NODE:
1536 case OSPF6_NODE:
7f57883e 1537 case EIGRP_NODE:
4fcbf6e2
RW
1538 case LDP_NODE:
1539 case LDP_L2VPN_NODE:
c25e458a 1540 case ISIS_NODE:
718e3744 1541 case MASC_NODE:
1542 case RMAP_NODE:
1543 case VTY_NODE:
1544 case KEYCHAIN_NODE:
2a56df97 1545 vtysh_execute("end");
1546 vtysh_execute("configure terminal");
718e3744 1547 vty->node = CONFIG_NODE;
1548 break;
1549 case BGP_VPNV4_NODE:
8ecd3266 1550 case BGP_VPNV6_NODE:
8b1fb8be
LB
1551 case BGP_ENCAP_NODE:
1552 case BGP_ENCAPV6_NODE:
718e3744 1553 case BGP_IPV4_NODE:
1554 case BGP_IPV4M_NODE:
1555 case BGP_IPV6_NODE:
57b5b7ed 1556 case BGP_IPV6M_NODE:
5ff06872 1557 case BGP_VRF_POLICY_NODE:
14a227b8 1558 case BGP_EVPN_NODE:
65efcfce
LB
1559 case BGP_VNC_DEFAULTS_NODE:
1560 case BGP_VNC_NVE_GROUP_NODE:
1561 case BGP_VNC_L2_GROUP_NODE:
718e3744 1562 vty->node = BGP_NODE;
1563 break;
4fcbf6e2
RW
1564 case LDP_IPV4_NODE:
1565 case LDP_IPV6_NODE:
1566 vty->node = LDP_NODE;
1567 break;
1568 case LDP_IPV4_IFACE_NODE:
1569 vty->node = LDP_IPV4_NODE;
1570 break;
1571 case LDP_IPV6_IFACE_NODE:
1572 vty->node = LDP_IPV6_NODE;
1573 break;
1574 case LDP_PSEUDOWIRE_NODE:
1575 vty->node = LDP_L2VPN_NODE;
1576 break;
718e3744 1577 case KEYCHAIN_KEY_NODE:
1578 vty->node = KEYCHAIN_NODE;
1579 break;
16f1b9ee
OD
1580 case LINK_PARAMS_NODE:
1581 vty->node = INTERFACE_NODE;
1582 break;
718e3744 1583 default:
1584 break;
1585 }
1586 return CMD_SUCCESS;
1587}
1588
4a96e944 1589DEFUNSH (VTYSH_REALLYALL,
718e3744 1590 vtysh_exit_all,
1591 vtysh_exit_all_cmd,
1592 "exit",
1593 "Exit current mode and down to previous mode\n")
1594{
1595 return vtysh_exit (vty);
1596}
1597
a98d33ab
QY
1598DEFUNSH (VTYSH_ALL,
1599 vtysh_quit_all,
1600 vtysh_quit_all_cmd,
1601 "quit",
1602 "Exit current mode and down to previous mode\n")
1603{
1604 return vtysh_exit_all (self, vty, argc, argv);
1605}
718e3744 1606
1607DEFUNSH (VTYSH_BGPD,
1608 exit_address_family,
1609 exit_address_family_cmd,
1610 "exit-address-family",
1611 "Exit from Address Family configuration mode\n")
1612{
1613 if (vty->node == BGP_IPV4_NODE
1614 || vty->node == BGP_IPV4M_NODE
1615 || vty->node == BGP_VPNV4_NODE
8ecd3266 1616 || vty->node == BGP_VPNV6_NODE
8b1fb8be
LB
1617 || vty->node == BGP_ENCAP_NODE
1618 || vty->node == BGP_ENCAPV6_NODE
57b5b7ed 1619 || vty->node == BGP_IPV6_NODE
1620 || vty->node == BGP_IPV6M_NODE)
718e3744 1621 vty->node = BGP_NODE;
1622 return CMD_SUCCESS;
1623}
1624
65efcfce
LB
1625DEFUNSH (VTYSH_BGPD,
1626 exit_vnc_config,
1627 exit_vnc_config_cmd,
1628 "exit-vnc",
1629 "Exit from VNC configuration mode\n")
1630{
1631 if (vty->node == BGP_VNC_DEFAULTS_NODE
1632 || vty->node == BGP_VNC_NVE_GROUP_NODE
1633 || vty->node == BGP_VNC_L2_GROUP_NODE)
1634 vty->node = BGP_NODE;
1635 return CMD_SUCCESS;
1636}
1637
5ff06872
LB
1638DEFUNSH (VTYSH_BGPD,
1639 exit_vrf_policy,
1640 exit_vrf_policy_cmd,
1641 "exit-vrf-policy",
1642 "Exit from VRF configuration mode\n")
1643{
1644 if (vty->node == BGP_VRF_POLICY_NODE)
1645 vty->node = BGP_NODE;
1646 return CMD_SUCCESS;
1647}
1648
718e3744 1649DEFUNSH (VTYSH_RIPD,
1650 vtysh_exit_ripd,
1651 vtysh_exit_ripd_cmd,
1652 "exit",
1653 "Exit current mode and down to previous mode\n")
1654{
1655 return vtysh_exit (vty);
1656}
1657
a98d33ab
QY
1658DEFUNSH (VTYSH_RIPD,
1659 vtysh_quit_ripd,
1660 vtysh_quit_ripd_cmd,
1661 "quit",
1662 "Exit current mode and down to previous mode\n")
1663{
1664 return vtysh_exit_ripd (self, vty, argc, argv);
1665}
718e3744 1666
68980084 1667DEFUNSH (VTYSH_RIPNGD,
b094d260 1668 vtysh_exit_ripngd,
1669 vtysh_exit_ripngd_cmd,
1670 "exit",
1671 "Exit current mode and down to previous mode\n")
68980084 1672{
1673 return vtysh_exit (vty);
1674}
1675
a98d33ab
QY
1676DEFUNSH (VTYSH_RIPNGD,
1677 vtysh_quit_ripngd,
1678 vtysh_quit_ripngd_cmd,
1679 "quit",
1680 "Exit current mode and down to previous mode\n")
1681{
1682 return vtysh_exit_ripngd (self, vty, argc, argv);
1683}
68980084 1684
718e3744 1685DEFUNSH (VTYSH_RMAP,
1686 vtysh_exit_rmap,
1687 vtysh_exit_rmap_cmd,
1688 "exit",
1689 "Exit current mode and down to previous mode\n")
1690{
1691 return vtysh_exit (vty);
1692}
1693
a98d33ab
QY
1694DEFUNSH (VTYSH_RMAP,
1695 vtysh_quit_rmap,
1696 vtysh_quit_rmap_cmd,
1697 "quit",
1698 "Exit current mode and down to previous mode\n")
1699{
1700 return vtysh_exit_rmap (self, vty, argc, argv);
1701}
718e3744 1702
1703DEFUNSH (VTYSH_BGPD,
1704 vtysh_exit_bgpd,
1705 vtysh_exit_bgpd_cmd,
1706 "exit",
1707 "Exit current mode and down to previous mode\n")
1708{
1709 return vtysh_exit (vty);
1710}
1711
a98d33ab
QY
1712DEFUNSH (VTYSH_BGPD,
1713 vtysh_quit_bgpd,
1714 vtysh_quit_bgpd_cmd,
1715 "quit",
1716 "Exit current mode and down to previous mode\n")
1717{
1718 return vtysh_exit_bgpd (self, vty, argc, argv);
1719}
718e3744 1720
1721DEFUNSH (VTYSH_OSPFD,
1722 vtysh_exit_ospfd,
1723 vtysh_exit_ospfd_cmd,
1724 "exit",
1725 "Exit current mode and down to previous mode\n")
1726{
1727 return vtysh_exit (vty);
1728}
1729
a98d33ab
QY
1730DEFUNSH (VTYSH_OSPFD,
1731 vtysh_quit_ospfd,
1732 vtysh_quit_ospfd_cmd,
1733 "quit",
1734 "Exit current mode and down to previous mode\n")
1735{
1736 return vtysh_exit_ospfd (self, vty, argc, argv);
1737}
718e3744 1738
7f57883e
DS
1739DEFUNSH (VTYSH_EIGRPD,
1740 vtysh_exit_eigrpd,
1741 vtysh_exit_eigrpd_cmd,
1742 "exit",
1743 "Exit current mode and down to previous mode\n")
1744{
1745 return vtysh_exit (vty);
1746}
1747
1748DEFUNSH (VTYSH_EIGRPD,
1749 vtysh_quit_eigrpd,
1750 vtysh_quit_eigrpd_cmd,
1751 "quit",
1752 "Exit current mode and down to previous mode\n")
1753{
1754 return vtysh_exit (vty);
1755}
1756
68980084 1757DEFUNSH (VTYSH_OSPF6D,
b094d260 1758 vtysh_exit_ospf6d,
1759 vtysh_exit_ospf6d_cmd,
1760 "exit",
1761 "Exit current mode and down to previous mode\n")
68980084 1762{
1763 return vtysh_exit (vty);
1764}
1765
a98d33ab
QY
1766DEFUNSH (VTYSH_OSPF6D,
1767 vtysh_quit_ospf6d,
1768 vtysh_quit_ospf6d_cmd,
1769 "quit",
1770 "Exit current mode and down to previous mode\n")
1771{
1772 return vtysh_exit_ospf6d (self, vty, argc, argv);
1773}
68980084 1774
87ab4aec 1775#if defined (HAVE_LDPD)
4fcbf6e2
RW
1776DEFUNSH (VTYSH_LDPD,
1777 vtysh_exit_ldpd,
1778 vtysh_exit_ldpd_cmd,
1779 "exit",
1780 "Exit current mode and down to previous mode\n")
1781{
1782 return vtysh_exit (vty);
1783}
1784
1785ALIAS (vtysh_exit_ldpd,
1786 vtysh_quit_ldpd_cmd,
1787 "quit",
1788 "Exit current mode and down to previous mode\n")
87ab4aec 1789#endif
4fcbf6e2 1790
c25e458a 1791DEFUNSH (VTYSH_ISISD,
b094d260 1792 vtysh_exit_isisd,
1793 vtysh_exit_isisd_cmd,
1794 "exit",
1795 "Exit current mode and down to previous mode\n")
c25e458a 1796{
1797 return vtysh_exit (vty);
1798}
1799
a98d33ab
QY
1800DEFUNSH (VTYSH_ISISD,
1801 vtysh_quit_isisd,
1802 vtysh_quit_isisd_cmd,
1803 "quit",
1804 "Exit current mode and down to previous mode\n")
1805{
1806 return vtysh_exit_isisd (self, vty, argc, argv);
1807}
c25e458a 1808
e7168df4 1809DEFUNSH (VTYSH_ALL,
1810 vtysh_exit_line_vty,
1811 vtysh_exit_line_vty_cmd,
1812 "exit",
1813 "Exit current mode and down to previous mode\n")
1814{
1815 return vtysh_exit (vty);
1816}
1817
a98d33ab
QY
1818DEFUNSH (VTYSH_ALL,
1819 vtysh_quit_line_vty,
1820 vtysh_quit_line_vty_cmd,
1821 "quit",
1822 "Exit current mode and down to previous mode\n")
1823{
1824 return vtysh_exit_line_vty (self, vty, argc, argv);
1825}
e7168df4 1826
95e735b5 1827DEFUNSH (VTYSH_INTERFACE,
718e3744 1828 vtysh_interface,
1829 vtysh_interface_cmd,
a98d33ab 1830 "interface IFNAME [vrf NAME]",
718e3744 1831 "Select an interface to configure\n"
a98d33ab
QY
1832 "Interface's name\n"
1833 VRF_CMD_HELP_STR)
718e3744 1834{
1835 vty->node = INTERFACE_NODE;
1836 return CMD_SUCCESS;
1837}
1838
95e735b5 1839/* TODO Implement "no interface command in isisd. */
7f57883e 1840DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_EIGRPD|VTYSH_LDPD,
32d2463c 1841 vtysh_no_interface_cmd,
1842 "no interface IFNAME",
1843 NO_STR
1844 "Delete a pseudo interface's configuration\n"
1845 "Interface's name\n")
1846
cd2a8a42
FL
1847DEFSH (VTYSH_ZEBRA,
1848 vtysh_no_interface_vrf_cmd,
199d90a1 1849 "no interface IFNAME vrf NAME",
cd2a8a42
FL
1850 NO_STR
1851 "Delete a pseudo interface's configuration\n"
1852 "Interface's name\n"
1853 VRF_CMD_HELP_STR)
1854
13460c44
FL
1855DEFUNSH (VTYSH_NS,
1856 vtysh_ns,
1857 vtysh_ns_cmd,
a98d33ab 1858 "logical-router (1-65535) ns NAME",
13460c44
FL
1859 "Enable a logical-router\n"
1860 "Specify the logical-router indentifier\n"
1861 "The Name Space\n"
1862 "The file name in " NS_RUN_DIR ", or a full pathname\n")
1863{
1864 vty->node = NS_NODE;
1865 return CMD_SUCCESS;
1866}
1867
e9d94ea7
DS
1868DEFUNSH (VTYSH_VRF,
1869 vtysh_vrf,
1870 vtysh_vrf_cmd,
1871 "vrf NAME",
1872 "Select a VRF to configure\n"
1873 "VRF's name\n")
1874{
1875 vty->node = VRF_NODE;
1876 return CMD_SUCCESS;
1877}
1878
1879DEFSH (VTYSH_ZEBRA,
1880 vtysh_no_vrf_cmd,
1881 "no vrf NAME",
1882 NO_STR
1883 "Delete a pseudo vrf's configuration\n"
1884 "VRF's name\n")
1885
13460c44
FL
1886DEFUNSH (VTYSH_NS,
1887 vtysh_exit_ns,
1888 vtysh_exit_ns_cmd,
1889 "exit",
1890 "Exit current mode and down to previous mode\n")
1891{
1892 return vtysh_exit (vty);
1893}
1894
a98d33ab
QY
1895DEFUNSH (VTYSH_NS,
1896 vtysh_quit_ns,
1897 vtysh_quit_ns_cmd,
1898 "quit",
1899 "Exit current mode and down to previous mode\n")
1900{
030204c7 1901 return vtysh_exit_ns(self, vty, argc, argv);
a98d33ab 1902}
13460c44 1903
e9d94ea7
DS
1904DEFUNSH (VTYSH_VRF,
1905 vtysh_exit_vrf,
1906 vtysh_exit_vrf_cmd,
1907 "exit",
1908 "Exit current mode and down to previous mode\n")
1909{
1910 return vtysh_exit (vty);
1911}
1912
a98d33ab
QY
1913DEFUNSH (VTYSH_VRF,
1914 vtysh_quit_vrf,
1915 vtysh_quit_vrf_cmd,
1916 "quit",
1917 "Exit current mode and down to previous mode\n")
1918{
1919 return vtysh_exit_vrf (self, vty, argc, argv);
1920}
e9d94ea7 1921
95e735b5 1922/* TODO Implement interface description commands in ripngd, ospf6d
1923 * and isisd. */
7f57883e 1924DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD|VTYSH_EIGRPD|VTYSH_LDPD,
dd2ecded 1925 vtysh_interface_desc_cmd,
e961923c 1926 "description LINE...",
338a9916 1927 "Interface specific description\n"
1928 "Characters describing this interface\n")
464dc8da 1929
7f57883e 1930DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD|VTYSH_EIGRPD,
dd2ecded 1931 vtysh_no_interface_desc_cmd,
464dc8da 1932 "no description",
1933 NO_STR
1934 "Interface specific description\n")
338a9916 1935
95e735b5 1936DEFUNSH (VTYSH_INTERFACE,
718e3744 1937 vtysh_exit_interface,
1938 vtysh_exit_interface_cmd,
1939 "exit",
1940 "Exit current mode and down to previous mode\n")
1941{
1942 return vtysh_exit (vty);
1943}
1944
a98d33ab
QY
1945DEFUNSH (VTYSH_INTERFACE,
1946 vtysh_quit_interface,
1947 vtysh_quit_interface_cmd,
1948 "quit",
1949 "Exit current mode and down to previous mode\n")
1950{
1951 return vtysh_exit_interface (self, vty, argc, argv);
1952}
718e3744 1953
0f69b58c
DS
1954DEFUN (vtysh_show_thread,
1955 vtysh_show_thread_cmd,
1956 "show thread cpu [FILTER]",
1957 SHOW_STR
1958 "Thread information\n"
1959 "Thread CPU usage\n"
1960 "Display filter (rwtexb)\n")
1961{
abddf075 1962 int idx_filter = 3;
0f69b58c
DS
1963 unsigned int i;
1964 int ret = CMD_SUCCESS;
1965 char line[100];
1966
bfbc035b 1967 sprintf(line, "show thread cpu %s\n", (argc == 4) ? argv[idx_filter]->arg : "");
0f69b58c
DS
1968 for (i = 0; i < array_size(vtysh_client); i++)
1969 if ( vtysh_client[i].fd >= 0 )
1970 {
1971 fprintf (stdout, "Thread statistics for %s:\n",
1972 vtysh_client[i].name);
1973 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1974 fprintf (stdout,"\n");
1975 }
1976 return ret;
1977}
1978
1979DEFUN (vtysh_show_work_queues,
1980 vtysh_show_work_queues_cmd,
1981 "show work-queues",
1982 SHOW_STR
1983 "Work Queue information\n")
1984{
1985 unsigned int i;
1986 int ret = CMD_SUCCESS;
1987 char line[] = "show work-queues\n";
1988
1989 for (i = 0; i < array_size(vtysh_client); i++)
1990 if ( vtysh_client[i].fd >= 0 )
1991 {
1992 fprintf (stdout, "Work queue statistics for %s:\n",
1993 vtysh_client[i].name);
1994 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1995 fprintf (stdout,"\n");
1996 }
1997
1998 return ret;
1999}
2000
b47b0a84
DS
2001DEFUN (vtysh_show_work_queues_daemon,
2002 vtysh_show_work_queues_daemon_cmd,
6147e2c6 2003 "show work-queues <zebra|ripd|ripngd|ospfd|ospf6d|bgpd|isisd>",
b47b0a84
DS
2004 SHOW_STR
2005 "Work Queue information\n"
2006 "For the zebra daemon\n"
2007 "For the rip daemon\n"
2008 "For the ripng daemon\n"
2009 "For the ospf daemon\n"
2010 "For the ospfv6 daemon\n"
2011 "For the bgp daemon\n"
2012 "For the isis daemon\n")
2013{
bfbc035b 2014 int idx_protocol = 2;
b47b0a84
DS
2015 unsigned int i;
2016 int ret = CMD_SUCCESS;
2017
2018 for (i = 0; i < array_size(vtysh_client); i++)
2019 {
6d681bd8 2020 if (strmatch(vtysh_client[i].name, argv[idx_protocol]->text))
b47b0a84
DS
2021 break;
2022 }
2023
2024 ret = vtysh_client_execute(&vtysh_client[i], "show work-queues\n", stdout);
2025
2026 return ret;
2027}
2028
16f1b9ee
OD
2029DEFUNSH (VTYSH_ZEBRA,
2030 vtysh_link_params,
2031 vtysh_link_params_cmd,
2032 "link-params",
2033 LINK_PARAMS_STR
2034 )
2035{
2036 vty->node = LINK_PARAMS_NODE;
2037 return CMD_SUCCESS;
2038}
2039
03f99d9a
DS
2040DEFUNSH (VTYSH_ZEBRA,
2041 exit_link_params,
2042 exit_link_params_cmd,
2043 "exit-link-params",
2044 "Exit from Link Params configuration node\n")
2045{
2046 if (vty->node == LINK_PARAMS_NODE)
2047 vty->node = INTERFACE_NODE;
2048 return CMD_SUCCESS;
2049}
2050
362b4031
PJ
2051/* Memory */
2052DEFUN (vtysh_show_memory,
2053 vtysh_show_memory_cmd,
2054 "show memory",
2055 SHOW_STR
2056 "Memory statistics\n")
2057{
2058 unsigned int i;
2059 int ret = CMD_SUCCESS;
2060 char line[] = "show memory\n";
2061
837d16cc 2062 for (i = 0; i < array_size(vtysh_client); i++)
362b4031
PJ
2063 if ( vtysh_client[i].fd >= 0 )
2064 {
2065 fprintf (stdout, "Memory statistics for %s:\n",
2066 vtysh_client[i].name);
2067 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
2068 fprintf (stdout,"\n");
2069 }
2070
2071 return ret;
2072}
2073
95e735b5 2074/* Logging commands. */
dbf7d13d
PJ
2075DEFUN (vtysh_show_logging,
2076 vtysh_show_logging_cmd,
2077 "show logging",
2078 SHOW_STR
2079 "Show current logging configuration\n")
2080{
2081 unsigned int i;
2082 int ret = CMD_SUCCESS;
2083 char line[] = "show logging\n";
2084
837d16cc 2085 for (i = 0; i < array_size(vtysh_client); i++)
4150f33e
PJ
2086 if ( vtysh_client[i].fd >= 0 )
2087 {
2088 fprintf (stdout,"Logging configuration for %s:\n",
2089 vtysh_client[i].name);
2090 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
2091 fprintf (stdout,"\n");
2092 }
2093
dbf7d13d
PJ
2094 return ret;
2095}
2096
95e735b5 2097DEFUNSH (VTYSH_ALL,
2098 vtysh_log_stdout,
2099 vtysh_log_stdout_cmd,
2100 "log stdout",
2101 "Logging control\n"
274a4a44 2102 "Set stdout logging level\n")
2103{
2104 return CMD_SUCCESS;
2105}
2106
2107DEFUNSH (VTYSH_ALL,
2108 vtysh_log_stdout_level,
2109 vtysh_log_stdout_level_cmd,
199d90a1 2110 "log stdout <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
274a4a44 2111 "Logging control\n"
2112 "Set stdout logging level\n"
2113 LOG_LEVEL_DESC)
95e735b5 2114{
2115 return CMD_SUCCESS;
2116}
2117
2118DEFUNSH (VTYSH_ALL,
2119 no_vtysh_log_stdout,
2120 no_vtysh_log_stdout_cmd,
274a4a44 2121 "no log stdout [LEVEL]",
95e735b5 2122 NO_STR
2123 "Logging control\n"
274a4a44 2124 "Cancel logging to stdout\n"
2125 "Logging level\n")
95e735b5 2126{
2127 return CMD_SUCCESS;
2128}
2129
2130DEFUNSH (VTYSH_ALL,
2131 vtysh_log_file,
2132 vtysh_log_file_cmd,
2133 "log file FILENAME",
2134 "Logging control\n"
2135 "Logging to file\n"
2136 "Logging filename\n")
2137{
2138 return CMD_SUCCESS;
2139}
2140
274a4a44 2141DEFUNSH (VTYSH_ALL,
2142 vtysh_log_file_level,
2143 vtysh_log_file_level_cmd,
199d90a1 2144 "log file FILENAME <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
274a4a44 2145 "Logging control\n"
2146 "Logging to file\n"
2147 "Logging filename\n"
2148 LOG_LEVEL_DESC)
2149{
2150 return CMD_SUCCESS;
2151}
2152
95e735b5 2153DEFUNSH (VTYSH_ALL,
2154 no_vtysh_log_file,
2155 no_vtysh_log_file_cmd,
a98d33ab 2156 "no log file [FILENAME [LEVEL]]",
95e735b5 2157 NO_STR
2158 "Logging control\n"
2159 "Cancel logging to file\n"
a98d33ab
QY
2160 "Logging file name\n"
2161 "Logging level\n")
95e735b5 2162{
2163 return CMD_SUCCESS;
2164}
2165
274a4a44 2166DEFUNSH (VTYSH_ALL,
2167 vtysh_log_monitor,
2168 vtysh_log_monitor_cmd,
e83a9414 2169 "log monitor [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
274a4a44 2170 "Logging control\n"
2171 "Set terminal line (monitor) logging level\n"
a98d33ab 2172 LOG_LEVEL_DESC)
274a4a44 2173{
2174 return CMD_SUCCESS;
2175}
2176
2177DEFUNSH (VTYSH_ALL,
2178 no_vtysh_log_monitor,
2179 no_vtysh_log_monitor_cmd,
2180 "no log monitor [LEVEL]",
2181 NO_STR
2182 "Logging control\n"
2183 "Disable terminal line (monitor) logging\n"
2184 "Logging level\n")
2185{
2186 return CMD_SUCCESS;
2187}
2188
95e735b5 2189DEFUNSH (VTYSH_ALL,
2190 vtysh_log_syslog,
2191 vtysh_log_syslog_cmd,
199d90a1 2192 "log syslog <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
274a4a44 2193 "Logging control\n"
2194 "Set syslog logging level\n"
a98d33ab 2195 LOG_LEVEL_DESC)
95e735b5 2196{
2197 return CMD_SUCCESS;
2198}
2199
2200DEFUNSH (VTYSH_ALL,
2201 no_vtysh_log_syslog,
2202 no_vtysh_log_syslog_cmd,
274a4a44 2203 "no log syslog [LEVEL]",
95e735b5 2204 NO_STR
2205 "Logging control\n"
274a4a44 2206 "Cancel logging to syslog\n"
2207 "Logging level\n")
95e735b5 2208{
2209 return CMD_SUCCESS;
2210}
2211
2212DEFUNSH (VTYSH_ALL,
274a4a44 2213 vtysh_log_facility,
2214 vtysh_log_facility_cmd,
199d90a1 2215 "log facility <kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|local0|local1|local2|local3|local4|local5|local6|local7>",
95e735b5 2216 "Logging control\n"
274a4a44 2217 "Facility parameter for syslog messages\n"
2218 LOG_FACILITY_DESC)
2219
95e735b5 2220{
2221 return CMD_SUCCESS;
2222}
2223
2224DEFUNSH (VTYSH_ALL,
274a4a44 2225 no_vtysh_log_facility,
2226 no_vtysh_log_facility_cmd,
2227 "no log facility [FACILITY]",
95e735b5 2228 NO_STR
2229 "Logging control\n"
274a4a44 2230 "Reset syslog facility to default (daemon)\n"
2231 "Syslog facility\n")
2232
2233{
2234 return CMD_SUCCESS;
2235}
2236
2237DEFUNSH_DEPRECATED (VTYSH_ALL,
2238 vtysh_log_trap,
2239 vtysh_log_trap_cmd,
199d90a1 2240 "log trap <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
274a4a44 2241 "Logging control\n"
2242 "(Deprecated) Set logging level and default for all destinations\n"
2243 LOG_LEVEL_DESC)
2244
2245{
2246 return CMD_SUCCESS;
2247}
2248
2249DEFUNSH_DEPRECATED (VTYSH_ALL,
2250 no_vtysh_log_trap,
2251 no_vtysh_log_trap_cmd,
2252 "no log trap [LEVEL]",
2253 NO_STR
2254 "Logging control\n"
2255 "Permit all logging information\n"
2256 "Logging level\n")
95e735b5 2257{
2258 return CMD_SUCCESS;
2259}
2260
2261DEFUNSH (VTYSH_ALL,
2262 vtysh_log_record_priority,
2263 vtysh_log_record_priority_cmd,
2264 "log record-priority",
2265 "Logging control\n"
2266 "Log the priority of the message within the message\n")
2267{
2268 return CMD_SUCCESS;
2269}
2270
2271DEFUNSH (VTYSH_ALL,
2272 no_vtysh_log_record_priority,
2273 no_vtysh_log_record_priority_cmd,
2274 "no log record-priority",
2275 NO_STR
2276 "Logging control\n"
2277 "Do not log the priority of the message within the message\n")
2278{
2279 return CMD_SUCCESS;
2280}
2281
c749b722
AS
2282DEFUNSH (VTYSH_ALL,
2283 vtysh_log_timestamp_precision,
2284 vtysh_log_timestamp_precision_cmd,
a98d33ab 2285 "log timestamp precision (0-6)",
c749b722
AS
2286 "Logging control\n"
2287 "Timestamp configuration\n"
2288 "Set the timestamp precision\n"
2289 "Number of subsecond digits\n")
2290{
2291 return CMD_SUCCESS;
2292}
2293
2294DEFUNSH (VTYSH_ALL,
2295 no_vtysh_log_timestamp_precision,
2296 no_vtysh_log_timestamp_precision_cmd,
2297 "no log timestamp precision",
2298 NO_STR
2299 "Logging control\n"
2300 "Timestamp configuration\n"
2301 "Reset the timestamp precision to the default value of 0\n")
2302{
2303 return CMD_SUCCESS;
2304}
2305
e7168df4 2306DEFUNSH (VTYSH_ALL,
2307 vtysh_service_password_encrypt,
2308 vtysh_service_password_encrypt_cmd,
2309 "service password-encryption",
2310 "Set up miscellaneous service\n"
2311 "Enable encrypted passwords\n")
2312{
2313 return CMD_SUCCESS;
2314}
2315
2316DEFUNSH (VTYSH_ALL,
2317 no_vtysh_service_password_encrypt,
2318 no_vtysh_service_password_encrypt_cmd,
2319 "no service password-encryption",
2320 NO_STR
2321 "Set up miscellaneous service\n"
2322 "Enable encrypted passwords\n")
2323{
2324 return CMD_SUCCESS;
2325}
2326
2327DEFUNSH (VTYSH_ALL,
2328 vtysh_config_password,
2329 vtysh_password_cmd,
a98d33ab 2330 "password (8-8) WORD",
e7168df4 2331 "Assign the terminal connection password\n"
2332 "Specifies a HIDDEN password will follow\n"
2333 "dummy string \n"
2334 "The HIDDEN line password string\n")
2335{
2336 return CMD_SUCCESS;
2337}
2338
2339DEFUNSH (VTYSH_ALL,
2340 vtysh_password_text,
2341 vtysh_password_text_cmd,
2342 "password LINE",
2343 "Assign the terminal connection password\n"
2344 "The UNENCRYPTED (cleartext) line password\n")
2345{
2346 return CMD_SUCCESS;
2347}
2348
2349DEFUNSH (VTYSH_ALL,
2350 vtysh_config_enable_password,
2351 vtysh_enable_password_cmd,
a98d33ab 2352 "enable password (8-8) WORD",
e7168df4 2353 "Modify enable password parameters\n"
2354 "Assign the privileged level password\n"
2355 "Specifies a HIDDEN password will follow\n"
e7168df4 2356 "The HIDDEN 'enable' password string\n")
2357{
2358 return CMD_SUCCESS;
2359}
2360
2361DEFUNSH (VTYSH_ALL,
2362 vtysh_enable_password_text,
2363 vtysh_enable_password_text_cmd,
2364 "enable password LINE",
2365 "Modify enable password parameters\n"
2366 "Assign the privileged level password\n"
2367 "The UNENCRYPTED (cleartext) 'enable' password\n")
2368{
2369 return CMD_SUCCESS;
2370}
2371
2372DEFUNSH (VTYSH_ALL,
2373 no_vtysh_config_enable_password,
2374 no_vtysh_enable_password_cmd,
2375 "no enable password",
2376 NO_STR
2377 "Modify enable password parameters\n"
2378 "Assign the privileged level password\n")
2379{
2380 return CMD_SUCCESS;
2381}
2382
718e3744 2383DEFUN (vtysh_write_terminal,
2384 vtysh_write_terminal_cmd,
e52702f2 2385 "write terminal [<zebra|ripd|ripngd|ospfd|ospf6d|ldpd|bgpd|isisd|pimd>]",
718e3744 2386 "Write running configuration to memory, network, or terminal\n"
066242b5
QY
2387 "Write to terminal\n"
2388 "For the zebra daemon\n"
2389 "For the rip daemon\n"
2390 "For the ripng daemon\n"
2391 "For the ospf daemon\n"
2392 "For the ospfv6 daemon\n"
16cedbb0 2393 "For the ldpd daemon\n"
066242b5
QY
2394 "For the bgp daemon\n"
2395 "For the isis daemon\n"
2396 "For the pim daemon\n")
718e3744 2397{
066242b5
QY
2398 u_int i;
2399 char line[] = "write terminal\n";
718e3744 2400 FILE *fp = NULL;
2401
2402 if (vtysh_pager_name)
2403 {
4fc01e67 2404 fp = popen (vtysh_pager_name, "w");
718e3744 2405 if (fp == NULL)
066242b5
QY
2406 {
2407 perror ("popen");
2408 exit (1);
2409 }
718e3744 2410 }
2411 else
2412 fp = stdout;
2413
2414 vty_out (vty, "Building configuration...%s", VTY_NEWLINE);
2415 vty_out (vty, "%sCurrent configuration:%s", VTY_NEWLINE,
066242b5 2416 VTY_NEWLINE);
e7168df4 2417 vty_out (vty, "!%s", VTY_NEWLINE);
718e3744 2418
066242b5
QY
2419 for (i = 0; i < array_size(vtysh_client); i++)
2420 if ((argc < 3 ) || (strmatch (vtysh_client[i].name, argv[2]->text)))
2421 vtysh_client_config (&vtysh_client[i], line);
2422
e7168df4 2423 /* Integrate vtysh specific configuration. */
2424 vtysh_config_write ();
2425
718e3744 2426 vtysh_config_dump (fp);
2427
2428 if (vtysh_pager_name && fp)
2429 {
2430 fflush (fp);
2431 if (pclose (fp) == -1)
066242b5
QY
2432 {
2433 perror ("pclose");
2434 exit (1);
2435 }
718e3744 2436 fp = NULL;
2437 }
2438
6e79f8bb 2439 vty_out (vty, "end%s", VTY_NEWLINE);
718e3744 2440 return CMD_SUCCESS;
2441}
2442
a98d33ab
QY
2443DEFUN (vtysh_show_running_config,
2444 vtysh_show_running_config_cmd,
e52702f2 2445 "show running-config [<zebra|ripd|ripngd|ospfd|ospf6d|ldpd|bgpd|isisd|pimd>]",
a98d33ab
QY
2446 SHOW_STR
2447 "Current operating configuration\n"
c006e89e
DS
2448 "For the zebra daemon\n"
2449 "For the rip daemon\n"
2450 "For the ripng daemon\n"
2451 "For the ospf daemon\n"
2452 "For the ospfv6 daemon\n"
4fcbf6e2 2453 "For the ldp daemon\n"
c006e89e 2454 "For the bgp daemon\n"
0fab7646
DS
2455 "For the isis daemon\n"
2456 "For the pim daemon\n")
c006e89e 2457{
a98d33ab 2458 return vtysh_write_terminal (self, vty, argc, argv);
c006e89e
DS
2459}
2460
e7168df4 2461DEFUN (vtysh_integrated_config,
2462 vtysh_integrated_config_cmd,
2463 "service integrated-vtysh-config",
2464 "Set up miscellaneous service\n"
2465 "Write configuration into integrated file\n")
4fc01e67 2466{
039eaca3 2467 vtysh_write_integrated = WRITE_INTEGRATED_YES;
e7168df4 2468 return CMD_SUCCESS;
4fc01e67 2469}
2470
e7168df4 2471DEFUN (no_vtysh_integrated_config,
2472 no_vtysh_integrated_config_cmd,
2473 "no service integrated-vtysh-config",
2474 NO_STR
2475 "Set up miscellaneous service\n"
2476 "Write configuration into integrated file\n")
4fc01e67 2477{
039eaca3 2478 vtysh_write_integrated = WRITE_INTEGRATED_NO;
e7168df4 2479 return CMD_SUCCESS;
4fc01e67 2480}
2481
a7222276
DS
2482static void
2483backup_config_file (const char *fbackup)
718e3744 2484{
718e3744 2485 char *integrate_sav = NULL;
2486
a7222276 2487 integrate_sav = malloc (strlen (fbackup) +
95e735b5 2488 strlen (CONF_BACKUP_EXT) + 1);
a7222276 2489 strcpy (integrate_sav, fbackup);
718e3744 2490 strcat (integrate_sav, CONF_BACKUP_EXT);
2491
95e735b5 2492 /* Move current configuration file to backup config file. */
718e3744 2493 unlink (integrate_sav);
a7222276 2494 rename (fbackup, integrate_sav);
95e735b5 2495 free (integrate_sav);
a7222276
DS
2496}
2497
a68f8616
DL
2498int
2499vtysh_write_config_integrated(void)
a7222276
DS
2500{
2501 u_int i;
2502 char line[] = "write terminal\n";
cb947ba3 2503 FILE *fp;
367988ee
DL
2504 int fd;
2505 struct passwd *pwentry;
2506 struct group *grentry;
2507 uid_t uid = -1;
2508 gid_t gid = -1;
2509 struct stat st;
2510 int err = 0;
a7222276
DS
2511
2512 fprintf (stdout,"Building Configuration...\n");
2513
cb947ba3
DL
2514 backup_config_file(quagga_config);
2515 fp = fopen (quagga_config, "w");
718e3744 2516 if (fp == NULL)
2517 {
c10c5926 2518 fprintf (stdout,"%% Error: failed to open configuration file %s: %s\n",
cb947ba3 2519 quagga_config, safe_strerror(errno));
c10c5926 2520 return CMD_WARNING;
a7222276 2521 }
367988ee 2522 fd = fileno (fp);
a7222276 2523
837d16cc 2524 for (i = 0; i < array_size(vtysh_client); i++)
c0e8c16f 2525 vtysh_client_config (&vtysh_client[i], line);
718e3744 2526
f64e741e 2527 vtysh_config_write ();
718e3744 2528 vtysh_config_dump (fp);
2529
367988ee
DL
2530 if (fchmod (fd, CONFIGFILE_MASK) != 0)
2531 {
2532 printf ("%% Warning: can't chmod configuration file %s: %s\n",
2533 quagga_config, safe_strerror(errno));
2534 err++;
2535 }
718e3744 2536
b2f36157 2537 pwentry = getpwnam (FRR_USER);
367988ee
DL
2538 if (pwentry)
2539 uid = pwentry->pw_uid;
2540 else
aa593d5e 2541 {
b2f36157 2542 printf ("%% Warning: could not look up user \"%s\"\n", FRR_USER);
367988ee 2543 err++;
aa593d5e 2544 }
2545
b2f36157 2546 grentry = getgrnam (FRR_GROUP);
367988ee
DL
2547 if (grentry)
2548 gid = grentry->gr_gid;
2549 else
a7222276 2550 {
b2f36157 2551 printf ("%% Warning: could not look up group \"%s\"\n", FRR_GROUP);
367988ee 2552 err++;
a7222276 2553 }
4fc01e67 2554
367988ee
DL
2555 if (!fstat (fd, &st))
2556 {
2557 if (st.st_uid == uid)
2558 uid = -1;
2559 if (st.st_gid == gid)
2560 gid = -1;
2561 if ((uid != (uid_t)-1 || gid != (gid_t)-1) && fchown (fd, uid, gid))
2562 {
2563 printf ("%% Warning: can't chown configuration file %s: %s\n",
2564 quagga_config, safe_strerror(errno));
2565 err++;
2566 }
2567 }
2568 else
2569 {
2570 printf ("%% Warning: stat() failed on %s: %s\n",
2571 quagga_config, safe_strerror(errno));
2572 err++;
2573 }
2574
2575 fclose (fp);
4fc01e67 2576
c10c5926 2577 printf ("Integrated configuration saved to %s\n", quagga_config);
367988ee
DL
2578 if (err)
2579 return CMD_WARNING;
4fc01e67 2580
c10c5926 2581 printf ("[OK]\n");
718e3744 2582 return CMD_SUCCESS;
2583}
2584
a68f8616 2585static bool want_config_integrated(void)
039eaca3
CF
2586{
2587 struct stat s;
2588
2589 switch (vtysh_write_integrated)
2590 {
2591 case WRITE_INTEGRATED_UNSPECIFIED:
cb947ba3 2592 if (stat(quagga_config, &s) && errno == ENOENT)
039eaca3
CF
2593 return false;
2594 return true;
2595 case WRITE_INTEGRATED_NO:
2596 return false;
2597 case WRITE_INTEGRATED_YES:
2598 return true;
2599 }
3d3c3cbd 2600 return true;
039eaca3
CF
2601}
2602
4fc01e67 2603DEFUN (vtysh_write_memory,
2604 vtysh_write_memory_cmd,
a98d33ab 2605 "write [<memory|file>]",
4fc01e67 2606 "Write running configuration to memory, network, or terminal\n"
a98d33ab
QY
2607 "Write configuration to the file (same as write file)\n"
2608 "Write configuration to the file (same as write memory)\n")
4fc01e67 2609{
dfc0d9ba 2610 int ret = CMD_SUCCESS;
4fc01e67 2611 char line[] = "write memory\n";
b1aa147d 2612 u_int i;
a7222276 2613
cb947ba3 2614 fprintf (stdout, "Note: this version of vtysh never writes vtysh.conf\n");
a7222276 2615
e20dc2ba 2616 /* If integrated frr.conf explicitely set. */
a68f8616 2617 if (want_config_integrated())
a7222276 2618 {
e10ca9b6
DL
2619 ret = CMD_WARNING;
2620 for (i = 0; i < array_size(vtysh_client); i++)
9473e340 2621 if (vtysh_client[i].flag == VTYSH_WATCHFRR)
e10ca9b6
DL
2622 break;
2623 if (i < array_size(vtysh_client) && vtysh_client[i].fd != -1)
2624 ret = vtysh_client_execute (&vtysh_client[i], "write integrated", stdout);
2625
2626 if (ret != CMD_SUCCESS)
2627 {
c10c5926 2628 printf("\nWarning: attempting direct configuration write without "
9473e340 2629 "watchfrr.\nFile permissions and ownership may be "
c10c5926 2630 "incorrect, or write may fail.\n\n");
e10ca9b6
DL
2631 ret = vtysh_write_config_integrated();
2632 }
2633 return ret;
a7222276
DS
2634 }
2635
4fc01e67 2636 fprintf (stdout,"Building Configuration...\n");
a7222276 2637
837d16cc 2638 for (i = 0; i < array_size(vtysh_client); i++)
b1aa147d 2639 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
4fc01e67 2640
dfc0d9ba 2641 return ret;
4fc01e67 2642}
2643
a98d33ab
QY
2644DEFUN (vtysh_copy_running_config,
2645 vtysh_copy_running_config_cmd,
2646 "copy running-config startup-config",
718e3744 2647 "Copy from one file to another\n"
2648 "Copy from current system configuration\n"
2649 "Copy to startup configuration\n")
a98d33ab
QY
2650{
2651 return vtysh_write_memory (self, vty, argc, argv);
2652}
718e3744 2653
34553cc3 2654DEFUN (vtysh_terminal_length,
2655 vtysh_terminal_length_cmd,
6147e2c6 2656 "terminal length (0-512)",
34553cc3 2657 "Set terminal line parameters\n"
2658 "Set number of lines on a screen\n"
2659 "Number of lines on screen (0 for no pausing)\n")
2660{
bfbc035b 2661 int idx_number = 2;
34553cc3 2662 int lines;
2663 char *endptr = NULL;
2664 char default_pager[10];
2665
bfbc035b 2666 lines = strtol (argv[idx_number]->arg, &endptr, 10);
34553cc3 2667 if (lines < 0 || lines > 512 || *endptr != '\0')
2668 {
2669 vty_out (vty, "length is malformed%s", VTY_NEWLINE);
2670 return CMD_WARNING;
2671 }
2672
2673 if (vtysh_pager_name)
2674 {
2675 free (vtysh_pager_name);
2676 vtysh_pager_name = NULL;
2677 }
2678
2679 if (lines != 0)
2680 {
2681 snprintf(default_pager, 10, "more -%i", lines);
2682 vtysh_pager_name = strdup (default_pager);
2683 }
2684
2685 return CMD_SUCCESS;
2686}
2687
2688DEFUN (vtysh_terminal_no_length,
2689 vtysh_terminal_no_length_cmd,
2690 "terminal no length",
2691 "Set terminal line parameters\n"
2692 NO_STR
2693 "Set number of lines on a screen\n")
2694{
2695 if (vtysh_pager_name)
2696 {
2697 free (vtysh_pager_name);
2698 vtysh_pager_name = NULL;
2699 }
2700
2701 vtysh_pager_init();
2702 return CMD_SUCCESS;
2703}
2704
f2799e69 2705DEFUN (vtysh_show_daemons,
2706 vtysh_show_daemons_cmd,
2707 "show daemons",
e7168df4 2708 SHOW_STR
2709 "Show list of running daemons\n")
2710{
b1aa147d 2711 u_int i;
2712
837d16cc 2713 for (i = 0; i < array_size(vtysh_client); i++)
b1aa147d 2714 if ( vtysh_client[i].fd >= 0 )
2715 vty_out(vty, " %s", vtysh_client[i].name);
e7168df4 2716 vty_out(vty, "%s", VTY_NEWLINE);
2717
2718 return CMD_SUCCESS;
2719}
2720
718e3744 2721/* Execute command in child process. */
c0e8c16f 2722static void
bfbc035b 2723execute_command (const char *command, int argc, struct cmd_token *arg1,
5862ff52 2724 const char *arg2)
718e3744 2725{
718e3744 2726 pid_t pid;
2727 int status;
2728
2729 /* Call fork(). */
2730 pid = fork ();
2731
2732 if (pid < 0)
2733 {
2734 /* Failure of fork(). */
6099b3b5 2735 fprintf (stderr, "Can't fork: %s\n", safe_strerror (errno));
718e3744 2736 exit (1);
2737 }
2738 else if (pid == 0)
2739 {
2740 /* This is child process. */
2741 switch (argc)
2742 {
2743 case 0:
c0e8c16f 2744 execlp (command, command, (const char *)NULL);
718e3744 2745 break;
2746 case 1:
c0e8c16f 2747 execlp (command, command, arg1, (const char *)NULL);
718e3744 2748 break;
2749 case 2:
c0e8c16f 2750 execlp (command, command, arg1, arg2, (const char *)NULL);
718e3744 2751 break;
2752 }
2753
2754 /* When execlp suceed, this part is not executed. */
6099b3b5 2755 fprintf (stderr, "Can't execute %s: %s\n", command, safe_strerror (errno));
718e3744 2756 exit (1);
2757 }
2758 else
2759 {
2760 /* This is parent. */
2761 execute_flag = 1;
c0e8c16f 2762 wait4 (pid, &status, 0, NULL);
718e3744 2763 execute_flag = 0;
2764 }
718e3744 2765}
2766
2767DEFUN (vtysh_ping,
2768 vtysh_ping_cmd,
2769 "ping WORD",
4eeccf18 2770 "Send echo messages\n"
718e3744 2771 "Ping destination address or hostname\n")
2772{
2773 execute_command ("ping", 1, argv[0], NULL);
2774 return CMD_SUCCESS;
2775}
2776
4eeccf18 2777ALIAS (vtysh_ping,
2778 vtysh_ping_ip_cmd,
2779 "ping ip WORD",
2780 "Send echo messages\n"
2781 "IP echo\n"
2782 "Ping destination address or hostname\n")
2783
718e3744 2784DEFUN (vtysh_traceroute,
2785 vtysh_traceroute_cmd,
2786 "traceroute WORD",
2787 "Trace route to destination\n"
2788 "Trace route to destination address or hostname\n")
2789{
2790 execute_command ("traceroute", 1, argv[0], NULL);
2791 return CMD_SUCCESS;
2792}
2793
4eeccf18 2794ALIAS (vtysh_traceroute,
2795 vtysh_traceroute_ip_cmd,
2796 "traceroute ip WORD",
2797 "Trace route to destination\n"
2798 "IP trace\n"
2799 "Trace route to destination address or hostname\n")
2800
4eeccf18 2801DEFUN (vtysh_ping6,
2802 vtysh_ping6_cmd,
2803 "ping ipv6 WORD",
2804 "Send echo messages\n"
2805 "IPv6 echo\n"
2806 "Ping destination address or hostname\n")
2807{
2808 execute_command ("ping6", 1, argv[0], NULL);
2809 return CMD_SUCCESS;
2810}
2811
2812DEFUN (vtysh_traceroute6,
2813 vtysh_traceroute6_cmd,
2814 "traceroute ipv6 WORD",
2815 "Trace route to destination\n"
2816 "IPv6 trace\n"
2817 "Trace route to destination address or hostname\n")
2818{
2819 execute_command ("traceroute6", 1, argv[0], NULL);
2820 return CMD_SUCCESS;
2821}
4eeccf18 2822
576b6b5d 2823#if defined(HAVE_SHELL_ACCESS)
718e3744 2824DEFUN (vtysh_telnet,
2825 vtysh_telnet_cmd,
2826 "telnet WORD",
2827 "Open a telnet connection\n"
2828 "IP address or hostname of a remote system\n")
2829{
2830 execute_command ("telnet", 1, argv[0], NULL);
2831 return CMD_SUCCESS;
2832}
2833
2834DEFUN (vtysh_telnet_port,
2835 vtysh_telnet_port_cmd,
2836 "telnet WORD PORT",
2837 "Open a telnet connection\n"
2838 "IP address or hostname of a remote system\n"
2839 "TCP Port number\n")
2840{
2841 execute_command ("telnet", 2, argv[0], argv[1]);
2842 return CMD_SUCCESS;
2843}
2844
5087df56 2845DEFUN (vtysh_ssh,
2846 vtysh_ssh_cmd,
2847 "ssh WORD",
2848 "Open an ssh connection\n"
2849 "[user@]host\n")
2850{
2851 execute_command ("ssh", 1, argv[0], NULL);
2852 return CMD_SUCCESS;
2853}
2854
718e3744 2855DEFUN (vtysh_start_shell,
2856 vtysh_start_shell_cmd,
2857 "start-shell",
2858 "Start UNIX shell\n")
2859{
2860 execute_command ("sh", 0, NULL, NULL);
2861 return CMD_SUCCESS;
2862}
2863
2864DEFUN (vtysh_start_bash,
2865 vtysh_start_bash_cmd,
2866 "start-shell bash",
2867 "Start UNIX shell\n"
2868 "Start bash\n")
2869{
2870 execute_command ("bash", 0, NULL, NULL);
2871 return CMD_SUCCESS;
2872}
2873
2874DEFUN (vtysh_start_zsh,
2875 vtysh_start_zsh_cmd,
2876 "start-shell zsh",
2877 "Start UNIX shell\n"
2878 "Start Z shell\n")
2879{
2880 execute_command ("zsh", 0, NULL, NULL);
2881 return CMD_SUCCESS;
2882}
576b6b5d 2883#endif
b094d260 2884
0b84f294
DL
2885DEFUN (config_list,
2886 config_list_cmd,
2887 "list [permutations]",
2888 "Print command list\n"
2889 "Print all possible command permutations\n")
2890{
2891 return cmd_list_cmds (vty, argc == 2);
2892}
2893
274a4a44 2894static void
718e3744 2895vtysh_install_default (enum node_type node)
2896{
2897 install_element (node, &config_list_cmd);
2898}
2899
2900/* Making connection to protocol daemon. */
274a4a44 2901static int
b1aa147d 2902vtysh_connect (struct vtysh_client *vclient)
718e3744 2903{
2904 int ret;
2905 int sock, len;
2906 struct sockaddr_un addr;
2907 struct stat s_stat;
eb05883f 2908 const char *path;
87d79a9f 2909
eb05883f
DL
2910 if (!vclient->path[0])
2911 snprintf(vclient->path, sizeof(vclient->path), "%s/%s.vty",
2912 vty_sock_path, vclient->name);
2913 path = vclient->path;
718e3744 2914
718e3744 2915 /* Stat socket to see if we have permission to access it. */
87d79a9f 2916 ret = stat (path, &s_stat);
718e3744 2917 if (ret < 0 && errno != ENOENT)
2918 {
2919 fprintf (stderr, "vtysh_connect(%s): stat = %s\n",
87d79a9f 2920 path, safe_strerror(errno));
718e3744 2921 exit(1);
2922 }
2923
2924 if (ret >= 0)
2925 {
2926 if (! S_ISSOCK(s_stat.st_mode))
2927 {
2928 fprintf (stderr, "vtysh_connect(%s): Not a socket\n",
87d79a9f 2929 path);
718e3744 2930 exit (1);
2931 }
2932
718e3744 2933 }
2934
2935 sock = socket (AF_UNIX, SOCK_STREAM, 0);
2936 if (sock < 0)
2937 {
2938#ifdef DEBUG
87d79a9f 2939 fprintf(stderr, "vtysh_connect(%s): socket = %s\n", path,
6099b3b5 2940 safe_strerror(errno));
718e3744 2941#endif /* DEBUG */
2942 return -1;
2943 }
2944
2945 memset (&addr, 0, sizeof (struct sockaddr_un));
2946 addr.sun_family = AF_UNIX;
fa389c27 2947 strlcpy (addr.sun_path, path, sizeof (addr.sun_path));
6f0e3f6e 2948#ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
718e3744 2949 len = addr.sun_len = SUN_LEN(&addr);
2950#else
2951 len = sizeof (addr.sun_family) + strlen (addr.sun_path);
6f0e3f6e 2952#endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
718e3744 2953
2954 ret = connect (sock, (struct sockaddr *) &addr, len);
2955 if (ret < 0)
2956 {
2957#ifdef DEBUG
87d79a9f 2958 fprintf(stderr, "vtysh_connect(%s): connect = %s\n", path,
6099b3b5 2959 safe_strerror(errno));
718e3744 2960#endif /* DEBUG */
2961 close (sock);
2962 return -1;
2963 }
2964 vclient->fd = sock;
2965
2966 return 0;
2967}
2968
7c8ff89e
DS
2969/* Return true if str ends with suffix, else return false */
2970static int
2971ends_with(const char *str, const char *suffix)
2972{
2973 if (!str || !suffix)
2974 return 0;
2975 size_t lenstr = strlen(str);
2976 size_t lensuffix = strlen(suffix);
2977 if (lensuffix > lenstr)
2978 return 0;
2979 return strncmp(str + lenstr - lensuffix, suffix, lensuffix) == 0;
2980}
2981
2982static void
2983vtysh_client_sorted_insert (struct vtysh_client *head_client,
2984 struct vtysh_client *client)
2985{
2986 struct vtysh_client *prev_node, *current_node;
2987
2988 prev_node = head_client;
2989 current_node = head_client->next;
2990 while (current_node)
2991 {
2992 if (strcmp(current_node->path, client->path) > 0)
2993 break;
2994
2995 prev_node = current_node;
2996 current_node = current_node->next;
2997 }
2998 client->next = current_node;
2999 prev_node->next = client;
3000}
3001
3002#define MAXIMUM_INSTANCES 10
3003
3004static void
3005vtysh_update_all_insances(struct vtysh_client * head_client)
3006{
3007 struct vtysh_client *client;
7c8ff89e
DS
3008 DIR *dir;
3009 struct dirent *file;
3010 int n = 0;
3011
3012 if (head_client->flag != VTYSH_OSPFD) return;
3013
eb05883f
DL
3014 /* ls vty_sock_dir and look for all files ending in .vty */
3015 dir = opendir(vty_sock_path);
7c8ff89e
DS
3016 if (dir)
3017 {
3018 while ((file = readdir(dir)) != NULL)
3019 {
3020 if (begins_with(file->d_name, "ospfd-") && ends_with(file->d_name, ".vty"))
3021 {
3022 if (n == MAXIMUM_INSTANCES)
3023 {
3024 fprintf(stderr,
87d79a9f 3025 "Parsing %s, client limit(%d) reached!\n",
eb05883f 3026 vty_sock_path, n);
7c8ff89e
DS
3027 break;
3028 }
3029 client = (struct vtysh_client *) malloc(sizeof(struct vtysh_client));
3030 client->fd = -1;
c0e8c16f 3031 client->name = "ospfd";
7c8ff89e 3032 client->flag = VTYSH_OSPFD;
eb05883f
DL
3033 snprintf(client->path, sizeof(client->path), "%s/%s",
3034 vty_sock_path, file->d_name);
7c8ff89e
DS
3035 client->next = NULL;
3036 vtysh_client_sorted_insert(head_client, client);
3037 n++;
3038 }
3039 }
3040 closedir(dir);
3041 }
3042}
3043
4201dd11 3044static int
7c8ff89e
DS
3045vtysh_connect_all_instances (struct vtysh_client *head_client)
3046{
3047 struct vtysh_client *client;
3048 int rc = 0;
3049
3050 vtysh_update_all_insances(head_client);
3051
3052 client = head_client->next;
3053 while (client)
3054 {
3055 if (vtysh_connect(client) == 0)
3056 rc++;
3057 client = client->next;
3058 }
3059
3060 return rc;
3061}
3062
f366ad31
AS
3063int
3064vtysh_connect_all(const char *daemon_name)
718e3744 3065{
b1aa147d 3066 u_int i;
f366ad31
AS
3067 int rc = 0;
3068 int matches = 0;
b1aa147d 3069
837d16cc 3070 for (i = 0; i < array_size(vtysh_client); i++)
b1aa147d 3071 {
f366ad31
AS
3072 if (!daemon_name || !strcmp(daemon_name, vtysh_client[i].name))
3073 {
3074 matches++;
3075 if (vtysh_connect(&vtysh_client[i]) == 0)
3076 rc++;
7c8ff89e
DS
3077
3078 rc += vtysh_connect_all_instances(&vtysh_client[i]);
3079 }
b1aa147d 3080 }
f366ad31
AS
3081 if (!matches)
3082 fprintf(stderr, "Error: no daemons match name %s!\n", daemon_name);
3083 return rc;
718e3744 3084}
3085
95e735b5 3086/* To disable readline's filename completion. */
274a4a44 3087static char *
dfc0d9ba 3088vtysh_completion_entry_function (const char *ignore, int invoking_key)
718e3744 3089{
dfc0d9ba 3090 return NULL;
718e3744 3091}
3092
3093void
b1aa147d 3094vtysh_readline_init (void)
718e3744 3095{
3096 /* readline related settings. */
a7c36d85 3097 rl_initialize ();
66d2ead7 3098 rl_bind_key ('?', (rl_command_func_t *) vtysh_rl_describe);
68980084 3099 rl_completion_entry_function = vtysh_completion_entry_function;
66d2ead7 3100 rl_attempted_completion_function = (rl_completion_func_t *)new_completion;
718e3744 3101}
3102
3103char *
b1aa147d 3104vtysh_prompt (void)
718e3744 3105{
f366ad31 3106 static struct utsname names;
718e3744 3107 static char buf[100];
3108 const char*hostname;
3109 extern struct host host;
3110
3111 hostname = host.name;
3112
3113 if (!hostname)
3114 {
f366ad31
AS
3115 if (!names.nodename[0])
3116 uname (&names);
718e3744 3117 hostname = names.nodename;
3118 }
3119
3120 snprintf (buf, sizeof buf, cmd_prompt (vty->node), hostname);
3121
3122 return buf;
3123}
3124
3125void
b1aa147d 3126vtysh_init_vty (void)
718e3744 3127{
3128 /* Make vty structure. */
3129 vty = vty_new ();
3130 vty->type = VTY_SHELL;
3131 vty->node = VIEW_NODE;
3132
3133 /* Initialize commands. */
3134 cmd_init (0);
3135
3136 /* Install nodes. */
3137 install_node (&bgp_node, NULL);
3138 install_node (&rip_node, NULL);
3139 install_node (&interface_node, NULL);
16f1b9ee 3140 install_node (&link_params_node, NULL);
13460c44 3141 install_node (&ns_node, NULL);
e9d94ea7 3142 install_node (&vrf_node, NULL);
718e3744 3143 install_node (&rmap_node, NULL);
3144 install_node (&zebra_node, NULL);
3145 install_node (&bgp_vpnv4_node, NULL);
8ecd3266 3146 install_node (&bgp_vpnv6_node, NULL);
8b1fb8be
LB
3147 install_node (&bgp_encap_node, NULL);
3148 install_node (&bgp_encapv6_node, NULL);
718e3744 3149 install_node (&bgp_ipv4_node, NULL);
3150 install_node (&bgp_ipv4m_node, NULL);
718e3744 3151 install_node (&bgp_ipv6_node, NULL);
57b5b7ed 3152 install_node (&bgp_ipv6m_node, NULL);
5ff06872 3153 install_node (&bgp_vrf_policy_node, NULL);
14a227b8 3154 install_node (&bgp_evpn_node, NULL);
65efcfce
LB
3155 install_node (&bgp_vnc_defaults_node, NULL);
3156 install_node (&bgp_vnc_nve_group_node, NULL);
3157 install_node (&bgp_vnc_l2_group_node, NULL);
718e3744 3158 install_node (&ospf_node, NULL);
7f57883e 3159 install_node (&eigrp_node, NULL);
718e3744 3160 install_node (&ripng_node, NULL);
3161 install_node (&ospf6_node, NULL);
4fcbf6e2
RW
3162 install_node (&ldp_node, NULL);
3163 install_node (&ldp_ipv4_node, NULL);
3164 install_node (&ldp_ipv6_node, NULL);
3165 install_node (&ldp_ipv4_iface_node, NULL);
3166 install_node (&ldp_ipv6_iface_node, NULL);
3167 install_node (&ldp_l2vpn_node, NULL);
3168 install_node (&ldp_pseudowire_node, NULL);
718e3744 3169 install_node (&keychain_node, NULL);
3170 install_node (&keychain_key_node, NULL);
c25e458a 3171 install_node (&isis_node, NULL);
e7168df4 3172 install_node (&vty_node, NULL);
718e3744 3173
3174 vtysh_install_default (VIEW_NODE);
718e3744 3175 vtysh_install_default (CONFIG_NODE);
3176 vtysh_install_default (BGP_NODE);
3177 vtysh_install_default (RIP_NODE);
3178 vtysh_install_default (INTERFACE_NODE);
16f1b9ee 3179 vtysh_install_default (LINK_PARAMS_NODE);
13460c44 3180 vtysh_install_default (NS_NODE);
e9d94ea7 3181 vtysh_install_default (VRF_NODE);
718e3744 3182 vtysh_install_default (RMAP_NODE);
3183 vtysh_install_default (ZEBRA_NODE);
3184 vtysh_install_default (BGP_VPNV4_NODE);
8ecd3266 3185 vtysh_install_default (BGP_VPNV6_NODE);
8b1fb8be
LB
3186 vtysh_install_default (BGP_ENCAP_NODE);
3187 vtysh_install_default (BGP_ENCAPV6_NODE);
718e3744 3188 vtysh_install_default (BGP_IPV4_NODE);
3189 vtysh_install_default (BGP_IPV4M_NODE);
3190 vtysh_install_default (BGP_IPV6_NODE);
57b5b7ed 3191 vtysh_install_default (BGP_IPV6M_NODE);
14a227b8 3192 vtysh_install_default (BGP_EVPN_NODE);
87ab4aec 3193#if ENABLE_BGP_VNC
5ff06872 3194 vtysh_install_default (BGP_VRF_POLICY_NODE);
65efcfce
LB
3195 vtysh_install_default (BGP_VNC_DEFAULTS_NODE);
3196 vtysh_install_default (BGP_VNC_NVE_GROUP_NODE);
3197 vtysh_install_default (BGP_VNC_L2_GROUP_NODE);
87ab4aec 3198#endif
718e3744 3199 vtysh_install_default (OSPF_NODE);
7f57883e 3200 vtysh_install_default (EIGRP_NODE);
718e3744 3201 vtysh_install_default (RIPNG_NODE);
3202 vtysh_install_default (OSPF6_NODE);
4fcbf6e2
RW
3203 vtysh_install_default (LDP_NODE);
3204 vtysh_install_default (LDP_IPV4_NODE);
3205 vtysh_install_default (LDP_IPV6_NODE);
3206 vtysh_install_default (LDP_IPV4_IFACE_NODE);
3207 vtysh_install_default (LDP_IPV6_IFACE_NODE);
3208 vtysh_install_default (LDP_L2VPN_NODE);
3209 vtysh_install_default (LDP_PSEUDOWIRE_NODE);
c25e458a 3210 vtysh_install_default (ISIS_NODE);
718e3744 3211 vtysh_install_default (KEYCHAIN_NODE);
3212 vtysh_install_default (KEYCHAIN_KEY_NODE);
e7168df4 3213 vtysh_install_default (VTY_NODE);
718e3744 3214
3215 install_element (VIEW_NODE, &vtysh_enable_cmd);
3216 install_element (ENABLE_NODE, &vtysh_config_terminal_cmd);
3217 install_element (ENABLE_NODE, &vtysh_disable_cmd);
3218
3219 /* "exit" command. */
3220 install_element (VIEW_NODE, &vtysh_exit_all_cmd);
718e3744 3221 install_element (CONFIG_NODE, &vtysh_exit_all_cmd);
d7d73ffc
DL
3222 install_element (VIEW_NODE, &vtysh_quit_all_cmd);
3223 install_element (CONFIG_NODE, &vtysh_quit_all_cmd);
718e3744 3224 install_element (RIP_NODE, &vtysh_exit_ripd_cmd);
3225 install_element (RIP_NODE, &vtysh_quit_ripd_cmd);
68980084 3226 install_element (RIPNG_NODE, &vtysh_exit_ripngd_cmd);
3227 install_element (RIPNG_NODE, &vtysh_quit_ripngd_cmd);
718e3744 3228 install_element (OSPF_NODE, &vtysh_exit_ospfd_cmd);
3229 install_element (OSPF_NODE, &vtysh_quit_ospfd_cmd);
7f57883e
DS
3230 install_element (EIGRP_NODE, &vtysh_exit_eigrpd_cmd);
3231 install_element (EIGRP_NODE, &vtysh_quit_eigrpd_cmd);
68980084 3232 install_element (OSPF6_NODE, &vtysh_exit_ospf6d_cmd);
3233 install_element (OSPF6_NODE, &vtysh_quit_ospf6d_cmd);
87ab4aec 3234#if defined (HAVE_LDPD)
4fcbf6e2
RW
3235 install_element (LDP_NODE, &vtysh_exit_ldpd_cmd);
3236 install_element (LDP_NODE, &vtysh_quit_ldpd_cmd);
3237 install_element (LDP_IPV4_NODE, &vtysh_exit_ldpd_cmd);
3238 install_element (LDP_IPV4_NODE, &vtysh_quit_ldpd_cmd);
3239 install_element (LDP_IPV6_NODE, &vtysh_exit_ldpd_cmd);
3240 install_element (LDP_IPV6_NODE, &vtysh_quit_ldpd_cmd);
3241 install_element (LDP_IPV4_IFACE_NODE, &vtysh_exit_ldpd_cmd);
3242 install_element (LDP_IPV4_IFACE_NODE, &vtysh_quit_ldpd_cmd);
3243 install_element (LDP_IPV6_IFACE_NODE, &vtysh_exit_ldpd_cmd);
3244 install_element (LDP_IPV6_IFACE_NODE, &vtysh_quit_ldpd_cmd);
3245 install_element (LDP_L2VPN_NODE, &vtysh_exit_ldpd_cmd);
3246 install_element (LDP_L2VPN_NODE, &vtysh_quit_ldpd_cmd);
3247 install_element (LDP_PSEUDOWIRE_NODE, &vtysh_exit_ldpd_cmd);
3248 install_element (LDP_PSEUDOWIRE_NODE, &vtysh_quit_ldpd_cmd);
87ab4aec 3249#endif
718e3744 3250 install_element (BGP_NODE, &vtysh_exit_bgpd_cmd);
3251 install_element (BGP_NODE, &vtysh_quit_bgpd_cmd);
3252 install_element (BGP_VPNV4_NODE, &vtysh_exit_bgpd_cmd);
3253 install_element (BGP_VPNV4_NODE, &vtysh_quit_bgpd_cmd);
8ecd3266 3254 install_element (BGP_VPNV6_NODE, &vtysh_exit_bgpd_cmd);
3255 install_element (BGP_VPNV6_NODE, &vtysh_quit_bgpd_cmd);
8b1fb8be
LB
3256 install_element (BGP_ENCAP_NODE, &vtysh_exit_bgpd_cmd);
3257 install_element (BGP_ENCAP_NODE, &vtysh_quit_bgpd_cmd);
3258 install_element (BGP_ENCAPV6_NODE, &vtysh_exit_bgpd_cmd);
3259 install_element (BGP_ENCAPV6_NODE, &vtysh_quit_bgpd_cmd);
718e3744 3260 install_element (BGP_IPV4_NODE, &vtysh_exit_bgpd_cmd);
3261 install_element (BGP_IPV4_NODE, &vtysh_quit_bgpd_cmd);
3262 install_element (BGP_IPV4M_NODE, &vtysh_exit_bgpd_cmd);
3263 install_element (BGP_IPV4M_NODE, &vtysh_quit_bgpd_cmd);
3264 install_element (BGP_IPV6_NODE, &vtysh_exit_bgpd_cmd);
3265 install_element (BGP_IPV6_NODE, &vtysh_quit_bgpd_cmd);
57b5b7ed 3266 install_element (BGP_IPV6M_NODE, &vtysh_exit_bgpd_cmd);
3267 install_element (BGP_IPV6M_NODE, &vtysh_quit_bgpd_cmd);
14a227b8 3268 install_element (BGP_EVPN_NODE, &vtysh_quit_bgpd_cmd);
87ab4aec 3269#if defined (ENABLE_BGP_VNC)
5ff06872
LB
3270 install_element (BGP_VRF_POLICY_NODE, &vtysh_exit_bgpd_cmd);
3271 install_element (BGP_VRF_POLICY_NODE, &vtysh_quit_bgpd_cmd);
65efcfce
LB
3272 install_element (BGP_VNC_DEFAULTS_NODE, &vtysh_exit_bgpd_cmd);
3273 install_element (BGP_VNC_DEFAULTS_NODE, &vtysh_quit_bgpd_cmd);
3274 install_element (BGP_VNC_NVE_GROUP_NODE, &vtysh_exit_bgpd_cmd);
3275 install_element (BGP_VNC_NVE_GROUP_NODE, &vtysh_quit_bgpd_cmd);
3276 install_element (BGP_VNC_L2_GROUP_NODE, &vtysh_exit_bgpd_cmd);
3277 install_element (BGP_VNC_L2_GROUP_NODE, &vtysh_quit_bgpd_cmd);
87ab4aec 3278#endif
c25e458a 3279 install_element (ISIS_NODE, &vtysh_exit_isisd_cmd);
3280 install_element (ISIS_NODE, &vtysh_quit_isisd_cmd);
718e3744 3281 install_element (KEYCHAIN_NODE, &vtysh_exit_ripd_cmd);
3282 install_element (KEYCHAIN_NODE, &vtysh_quit_ripd_cmd);
3283 install_element (KEYCHAIN_KEY_NODE, &vtysh_exit_ripd_cmd);
3284 install_element (KEYCHAIN_KEY_NODE, &vtysh_quit_ripd_cmd);
3285 install_element (RMAP_NODE, &vtysh_exit_rmap_cmd);
3286 install_element (RMAP_NODE, &vtysh_quit_rmap_cmd);
e7168df4 3287 install_element (VTY_NODE, &vtysh_exit_line_vty_cmd);
3288 install_element (VTY_NODE, &vtysh_quit_line_vty_cmd);
718e3744 3289
3290 /* "end" command. */
3291 install_element (CONFIG_NODE, &vtysh_end_all_cmd);
3292 install_element (ENABLE_NODE, &vtysh_end_all_cmd);
3293 install_element (RIP_NODE, &vtysh_end_all_cmd);
3294 install_element (RIPNG_NODE, &vtysh_end_all_cmd);
3295 install_element (OSPF_NODE, &vtysh_end_all_cmd);
7f57883e 3296 install_element (EIGRP_NODE, &vtysh_end_all_cmd);
718e3744 3297 install_element (OSPF6_NODE, &vtysh_end_all_cmd);
4fcbf6e2
RW
3298 install_element (LDP_NODE, &vtysh_end_all_cmd);
3299 install_element (LDP_IPV4_NODE, &vtysh_end_all_cmd);
3300 install_element (LDP_IPV6_NODE, &vtysh_end_all_cmd);
3301 install_element (LDP_IPV4_IFACE_NODE, &vtysh_end_all_cmd);
3302 install_element (LDP_IPV6_IFACE_NODE, &vtysh_end_all_cmd);
3303 install_element (LDP_L2VPN_NODE, &vtysh_end_all_cmd);
3304 install_element (LDP_PSEUDOWIRE_NODE, &vtysh_end_all_cmd);
718e3744 3305 install_element (BGP_NODE, &vtysh_end_all_cmd);
3306 install_element (BGP_IPV4_NODE, &vtysh_end_all_cmd);
3307 install_element (BGP_IPV4M_NODE, &vtysh_end_all_cmd);
3308 install_element (BGP_VPNV4_NODE, &vtysh_end_all_cmd);
8ecd3266 3309 install_element (BGP_VPNV6_NODE, &vtysh_end_all_cmd);
8b1fb8be
LB
3310 install_element (BGP_ENCAP_NODE, &vtysh_end_all_cmd);
3311 install_element (BGP_ENCAPV6_NODE, &vtysh_end_all_cmd);
718e3744 3312 install_element (BGP_IPV6_NODE, &vtysh_end_all_cmd);
57b5b7ed 3313 install_element (BGP_IPV6M_NODE, &vtysh_end_all_cmd);
5ff06872 3314 install_element (BGP_VRF_POLICY_NODE, &vtysh_end_all_cmd);
14a227b8 3315 install_element (BGP_EVPN_NODE, &vtysh_end_all_cmd);
65efcfce
LB
3316 install_element (BGP_VNC_DEFAULTS_NODE, &vtysh_end_all_cmd);
3317 install_element (BGP_VNC_NVE_GROUP_NODE, &vtysh_end_all_cmd);
3318 install_element (BGP_VNC_L2_GROUP_NODE, &vtysh_end_all_cmd);
c25e458a 3319 install_element (ISIS_NODE, &vtysh_end_all_cmd);
718e3744 3320 install_element (KEYCHAIN_NODE, &vtysh_end_all_cmd);
3321 install_element (KEYCHAIN_KEY_NODE, &vtysh_end_all_cmd);
3322 install_element (RMAP_NODE, &vtysh_end_all_cmd);
e7168df4 3323 install_element (VTY_NODE, &vtysh_end_all_cmd);
718e3744 3324
dd2ecded
DS
3325 install_element (INTERFACE_NODE, &vtysh_interface_desc_cmd);
3326 install_element (INTERFACE_NODE, &vtysh_no_interface_desc_cmd);
718e3744 3327 install_element (INTERFACE_NODE, &vtysh_end_all_cmd);
3328 install_element (INTERFACE_NODE, &vtysh_exit_interface_cmd);
03f99d9a 3329 install_element (LINK_PARAMS_NODE, &exit_link_params_cmd);
16f1b9ee
OD
3330 install_element (LINK_PARAMS_NODE, &vtysh_end_all_cmd);
3331 install_element (LINK_PARAMS_NODE, &vtysh_exit_interface_cmd);
718e3744 3332 install_element (INTERFACE_NODE, &vtysh_quit_interface_cmd);
e9d94ea7 3333
13460c44 3334 install_element (NS_NODE, &vtysh_end_all_cmd);
d7d73ffc
DL
3335
3336 install_element (CONFIG_NODE, &vtysh_ns_cmd);
13460c44
FL
3337 install_element (NS_NODE, &vtysh_exit_ns_cmd);
3338 install_element (NS_NODE, &vtysh_quit_ns_cmd);
3339
e9d94ea7
DS
3340 install_element (VRF_NODE, &vtysh_end_all_cmd);
3341 install_element (VRF_NODE, &vtysh_exit_vrf_cmd);
3342 install_element (VRF_NODE, &vtysh_quit_vrf_cmd);
3343
7f57883e 3344 install_element (CONFIG_NODE, &router_eigrp_cmd);
718e3744 3345 install_element (CONFIG_NODE, &router_rip_cmd);
718e3744 3346 install_element (CONFIG_NODE, &router_ripng_cmd);
718e3744 3347 install_element (CONFIG_NODE, &router_ospf_cmd);
718e3744 3348 install_element (CONFIG_NODE, &router_ospf6_cmd);
87ab4aec 3349#if defined (HAVE_LDPD)
4fcbf6e2
RW
3350 install_element (CONFIG_NODE, &ldp_mpls_ldp_cmd);
3351 install_element (LDP_NODE, &ldp_address_family_ipv4_cmd);
3352 install_element (LDP_NODE, &ldp_address_family_ipv6_cmd);
3353 install_element (LDP_IPV4_NODE, &ldp_interface_ifname_cmd);
3354 install_element (LDP_IPV6_NODE, &ldp_interface_ifname_cmd);
3355 install_element (CONFIG_NODE, &ldp_l2vpn_word_type_vpls_cmd);
3356 install_element (LDP_L2VPN_NODE, &ldp_member_pseudowire_ifname_cmd);
87ab4aec 3357#endif
c25e458a 3358 install_element (CONFIG_NODE, &router_isis_cmd);
718e3744 3359 install_element (CONFIG_NODE, &router_bgp_cmd);
3360 install_element (BGP_NODE, &address_family_vpnv4_cmd);
8ecd3266 3361 install_element (BGP_NODE, &address_family_vpnv6_cmd);
4c4ff4c1 3362 install_element (BGP_NODE, &address_family_encapv4_cmd);
8b1fb8be 3363 install_element (BGP_NODE, &address_family_encapv6_cmd);
87ab4aec 3364#if defined(ENABLE_BGP_VNC)
5ff06872 3365 install_element (BGP_NODE, &vnc_vrf_policy_cmd);
65efcfce
LB
3366 install_element (BGP_NODE, &vnc_defaults_cmd);
3367 install_element (BGP_NODE, &vnc_nve_group_cmd);
d7d73ffc 3368 install_element (BGP_NODE, &vnc_l2_group_cmd);
87ab4aec 3369#endif
718e3744 3370 install_element (BGP_NODE, &address_family_ipv4_unicast_cmd);
718e3744 3371 install_element (BGP_NODE, &address_family_ipv6_cmd);
14a227b8 3372 install_element (BGP_NODE, &address_family_evpn_cmd);
718e3744 3373 install_element (BGP_VPNV4_NODE, &exit_address_family_cmd);
8ecd3266 3374 install_element (BGP_VPNV6_NODE, &exit_address_family_cmd);
8b1fb8be
LB
3375 install_element (BGP_ENCAP_NODE, &exit_address_family_cmd);
3376 install_element (BGP_ENCAPV6_NODE, &exit_address_family_cmd);
718e3744 3377 install_element (BGP_IPV4_NODE, &exit_address_family_cmd);
3378 install_element (BGP_IPV4M_NODE, &exit_address_family_cmd);
3379 install_element (BGP_IPV6_NODE, &exit_address_family_cmd);
57b5b7ed 3380 install_element (BGP_IPV6M_NODE, &exit_address_family_cmd);
14a227b8 3381 install_element (BGP_EVPN_NODE, &exit_address_family_cmd);
65efcfce 3382
5ff06872 3383 install_element (BGP_VRF_POLICY_NODE, &exit_vrf_policy_cmd);
65efcfce
LB
3384 install_element (BGP_VNC_DEFAULTS_NODE, &exit_vnc_config_cmd);
3385 install_element (BGP_VNC_NVE_GROUP_NODE, &exit_vnc_config_cmd);
3386 install_element (BGP_VNC_L2_GROUP_NODE, &exit_vnc_config_cmd);
3387
718e3744 3388 install_element (CONFIG_NODE, &key_chain_cmd);
dd2ecded 3389 install_element (CONFIG_NODE, &vtysh_route_map_cmd);
e7168df4 3390 install_element (CONFIG_NODE, &vtysh_line_vty_cmd);
718e3744 3391 install_element (KEYCHAIN_NODE, &key_cmd);
3392 install_element (KEYCHAIN_NODE, &key_chain_cmd);
3393 install_element (KEYCHAIN_KEY_NODE, &key_chain_cmd);
3394 install_element (CONFIG_NODE, &vtysh_interface_cmd);
32d2463c 3395 install_element (CONFIG_NODE, &vtysh_no_interface_cmd);
cd2a8a42 3396 install_element (CONFIG_NODE, &vtysh_no_interface_vrf_cmd);
16f1b9ee 3397 install_element (INTERFACE_NODE, &vtysh_link_params_cmd);
718e3744 3398 install_element (ENABLE_NODE, &vtysh_show_running_config_cmd);
a98d33ab 3399 install_element (ENABLE_NODE, &vtysh_copy_running_config_cmd);
718e3744 3400
e9d94ea7
DS
3401 install_element (CONFIG_NODE, &vtysh_vrf_cmd);
3402 install_element (CONFIG_NODE, &vtysh_no_vrf_cmd);
3403
95e735b5 3404 /* "write terminal" command. */
718e3744 3405 install_element (ENABLE_NODE, &vtysh_write_terminal_cmd);
b47b0a84 3406
e7168df4 3407 install_element (CONFIG_NODE, &vtysh_integrated_config_cmd);
3408 install_element (CONFIG_NODE, &no_vtysh_integrated_config_cmd);
718e3744 3409
95e735b5 3410 /* "write memory" command. */
718e3744 3411 install_element (ENABLE_NODE, &vtysh_write_memory_cmd);
718e3744 3412
34553cc3 3413 install_element (VIEW_NODE, &vtysh_terminal_length_cmd);
34553cc3 3414 install_element (VIEW_NODE, &vtysh_terminal_no_length_cmd);
f2799e69 3415 install_element (VIEW_NODE, &vtysh_show_daemons_cmd);
34553cc3 3416
718e3744 3417 install_element (VIEW_NODE, &vtysh_ping_cmd);
4eeccf18 3418 install_element (VIEW_NODE, &vtysh_ping_ip_cmd);
718e3744 3419 install_element (VIEW_NODE, &vtysh_traceroute_cmd);
4eeccf18 3420 install_element (VIEW_NODE, &vtysh_traceroute_ip_cmd);
4eeccf18 3421 install_element (VIEW_NODE, &vtysh_ping6_cmd);
3422 install_element (VIEW_NODE, &vtysh_traceroute6_cmd);
576b6b5d 3423#if defined(HAVE_SHELL_ACCESS)
718e3744 3424 install_element (VIEW_NODE, &vtysh_telnet_cmd);
3425 install_element (VIEW_NODE, &vtysh_telnet_port_cmd);
5087df56 3426 install_element (VIEW_NODE, &vtysh_ssh_cmd);
4eeccf18 3427#endif
576b6b5d 3428#if defined(HAVE_SHELL_ACCESS)
718e3744 3429 install_element (ENABLE_NODE, &vtysh_start_shell_cmd);
3430 install_element (ENABLE_NODE, &vtysh_start_bash_cmd);
3431 install_element (ENABLE_NODE, &vtysh_start_zsh_cmd);
576b6b5d
DS
3432#endif
3433
362b4031 3434 install_element (VIEW_NODE, &vtysh_show_memory_cmd);
362b4031 3435
0f69b58c 3436 install_element (VIEW_NODE, &vtysh_show_work_queues_cmd);
b47b0a84 3437 install_element (VIEW_NODE, &vtysh_show_work_queues_daemon_cmd);
0f69b58c
DS
3438
3439 install_element (VIEW_NODE, &vtysh_show_thread_cmd);
0f69b58c 3440
dbf7d13d 3441 /* Logging */
dbf7d13d 3442 install_element (VIEW_NODE, &vtysh_show_logging_cmd);
718e3744 3443 install_element (CONFIG_NODE, &vtysh_log_stdout_cmd);
274a4a44 3444 install_element (CONFIG_NODE, &vtysh_log_stdout_level_cmd);
718e3744 3445 install_element (CONFIG_NODE, &no_vtysh_log_stdout_cmd);
3446 install_element (CONFIG_NODE, &vtysh_log_file_cmd);
274a4a44 3447 install_element (CONFIG_NODE, &vtysh_log_file_level_cmd);
718e3744 3448 install_element (CONFIG_NODE, &no_vtysh_log_file_cmd);
274a4a44 3449 install_element (CONFIG_NODE, &vtysh_log_monitor_cmd);
274a4a44 3450 install_element (CONFIG_NODE, &no_vtysh_log_monitor_cmd);
718e3744 3451 install_element (CONFIG_NODE, &vtysh_log_syslog_cmd);
3452 install_element (CONFIG_NODE, &no_vtysh_log_syslog_cmd);
3453 install_element (CONFIG_NODE, &vtysh_log_trap_cmd);
3454 install_element (CONFIG_NODE, &no_vtysh_log_trap_cmd);
274a4a44 3455 install_element (CONFIG_NODE, &vtysh_log_facility_cmd);
3456 install_element (CONFIG_NODE, &no_vtysh_log_facility_cmd);
718e3744 3457 install_element (CONFIG_NODE, &vtysh_log_record_priority_cmd);
3458 install_element (CONFIG_NODE, &no_vtysh_log_record_priority_cmd);
c749b722
AS
3459 install_element (CONFIG_NODE, &vtysh_log_timestamp_precision_cmd);
3460 install_element (CONFIG_NODE, &no_vtysh_log_timestamp_precision_cmd);
e7168df4 3461
3462 install_element (CONFIG_NODE, &vtysh_service_password_encrypt_cmd);
3463 install_element (CONFIG_NODE, &no_vtysh_service_password_encrypt_cmd);
3464
3465 install_element (CONFIG_NODE, &vtysh_password_cmd);
3466 install_element (CONFIG_NODE, &vtysh_password_text_cmd);
3467 install_element (CONFIG_NODE, &vtysh_enable_password_cmd);
3468 install_element (CONFIG_NODE, &vtysh_enable_password_text_cmd);
3469 install_element (CONFIG_NODE, &no_vtysh_enable_password_cmd);
718e3744 3470}