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