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