]> git.proxmox.com Git - mirror_frr.git/blob - vtysh/vtysh.c
Merge remote-tracking branch 'origin/master' into EIGRP
[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 vty->node = BGP_EVPN_NODE;
1232 return CMD_SUCCESS;
1233 }
1234
1235 #if defined (ENABLE_BGP_VNC)
1236 DEFUNSH (VTYSH_BGPD,
1237 vnc_defaults,
1238 vnc_defaults_cmd,
1239 "vnc defaults",
1240 "VNC/RFP related configuration\n"
1241 "Configure default NVE group\n")
1242 {
1243 vty->node = BGP_VNC_DEFAULTS_NODE;
1244 return CMD_SUCCESS;
1245 }
1246
1247 DEFUNSH (VTYSH_BGPD,
1248 vnc_nve_group,
1249 vnc_nve_group_cmd,
1250 "vnc nve-group NAME",
1251 "VNC/RFP related configuration\n"
1252 "Configure a NVE group\n"
1253 "Group name\n")
1254 {
1255 vty->node = BGP_VNC_NVE_GROUP_NODE;
1256 return CMD_SUCCESS;
1257 }
1258
1259 DEFUNSH (VTYSH_BGPD,
1260 vnc_vrf_policy,
1261 vnc_vrf_policy_cmd,
1262 "vrf-policy NAME",
1263 "Configure a VRF policy group\n"
1264 "Group name\n")
1265 {
1266 vty->node = BGP_VRF_POLICY_NODE;
1267 return CMD_SUCCESS;
1268 }
1269
1270 DEFUNSH (VTYSH_BGPD,
1271 vnc_l2_group,
1272 vnc_l2_group_cmd,
1273 "vnc l2-group NAME",
1274 "VNC/RFP related configuration\n"
1275 "Configure a L2 group\n"
1276 "Group name\n")
1277 {
1278 vty->node = BGP_VNC_L2_GROUP_NODE;
1279 return CMD_SUCCESS;
1280 }
1281 #endif
1282
1283 DEFUNSH (VTYSH_RIPD,
1284 key_chain,
1285 key_chain_cmd,
1286 "key chain WORD",
1287 "Authentication key management\n"
1288 "Key-chain management\n"
1289 "Key-chain name\n")
1290 {
1291 vty->node = KEYCHAIN_NODE;
1292 return CMD_SUCCESS;
1293 }
1294
1295 DEFUNSH (VTYSH_RIPD,
1296 key,
1297 key_cmd,
1298 "key (0-2147483647)",
1299 "Configure a key\n"
1300 "Key identifier number\n")
1301 {
1302 vty->node = KEYCHAIN_KEY_NODE;
1303 return CMD_SUCCESS;
1304 }
1305
1306 DEFUNSH (VTYSH_RIPD,
1307 router_rip,
1308 router_rip_cmd,
1309 "router rip",
1310 ROUTER_STR
1311 "RIP")
1312 {
1313 vty->node = RIP_NODE;
1314 return CMD_SUCCESS;
1315 }
1316
1317 DEFUNSH (VTYSH_RIPNGD,
1318 router_ripng,
1319 router_ripng_cmd,
1320 "router ripng",
1321 ROUTER_STR
1322 "RIPng")
1323 {
1324 vty->node = RIPNG_NODE;
1325 return CMD_SUCCESS;
1326 }
1327
1328 DEFUNSH (VTYSH_OSPFD,
1329 router_ospf,
1330 router_ospf_cmd,
1331 "router ospf [(1-65535)]",
1332 "Enable a routing process\n"
1333 "Start OSPF configuration\n"
1334 "Instance ID\n")
1335 {
1336 vty->node = OSPF_NODE;
1337 return CMD_SUCCESS;
1338 }
1339
1340 DEFUNSH (VTYSH_EIGRPD,
1341 router_eigrp,
1342 router_eigrp_cmd,
1343 "router eigrp (1-65535)",
1344 "Enable a routing process\n"
1345 "Start EIGRP configuration\n"
1346 "AS number to use\n")
1347 {
1348 vty->node = EIGRP_NODE;
1349 return CMD_SUCCESS;
1350 }
1351
1352 DEFUNSH (VTYSH_OSPF6D,
1353 router_ospf6,
1354 router_ospf6_cmd,
1355 "router ospf6",
1356 ROUTER_STR
1357 OSPF6_STR)
1358 {
1359 vty->node = OSPF6_NODE;
1360 return CMD_SUCCESS;
1361 }
1362
1363 #if defined (HAVE_LDPD)
1364 DEFUNSH (VTYSH_LDPD,
1365 ldp_mpls_ldp,
1366 ldp_mpls_ldp_cmd,
1367 "mpls ldp",
1368 "Global MPLS configuration subcommands\n"
1369 "Label Distribution Protocol\n")
1370 {
1371 vty->node = LDP_NODE;
1372 return CMD_SUCCESS;
1373 }
1374
1375 DEFUNSH (VTYSH_LDPD,
1376 ldp_address_family_ipv4,
1377 ldp_address_family_ipv4_cmd,
1378 "address-family ipv4",
1379 "Configure Address Family and its parameters\n"
1380 "IPv4\n")
1381 {
1382 vty->node = LDP_IPV4_NODE;
1383 return CMD_SUCCESS;
1384 }
1385
1386 DEFUNSH (VTYSH_LDPD,
1387 ldp_address_family_ipv6,
1388 ldp_address_family_ipv6_cmd,
1389 "address-family ipv6",
1390 "Configure Address Family and its parameters\n"
1391 "IPv6\n")
1392 {
1393 vty->node = LDP_IPV6_NODE;
1394 return CMD_SUCCESS;
1395 }
1396
1397 DEFUNSH (VTYSH_LDPD,
1398 ldp_interface_ifname,
1399 ldp_interface_ifname_cmd,
1400 "interface IFNAME",
1401 "Enable LDP on an interface and enter interface submode\n"
1402 "Interface's name\n")
1403 {
1404 switch (vty->node)
1405 {
1406 case LDP_IPV4_NODE:
1407 vty->node = LDP_IPV4_IFACE_NODE;
1408 break;
1409 case LDP_IPV6_NODE:
1410 vty->node = LDP_IPV6_IFACE_NODE;
1411 break;
1412 default:
1413 break;
1414 }
1415
1416 return CMD_SUCCESS;
1417 }
1418
1419 DEFUNSH (VTYSH_LDPD,
1420 ldp_l2vpn_word_type_vpls,
1421 ldp_l2vpn_word_type_vpls_cmd,
1422 "l2vpn WORD type vpls",
1423 "Configure l2vpn commands\n"
1424 "L2VPN name\n"
1425 "L2VPN type\n"
1426 "Virtual Private LAN Service\n")
1427 {
1428 vty->node = LDP_L2VPN_NODE;
1429 return CMD_SUCCESS;
1430 }
1431
1432 DEFUNSH (VTYSH_LDPD,
1433 ldp_member_pseudowire_ifname,
1434 ldp_member_pseudowire_ifname_cmd,
1435 "member pseudowire IFNAME",
1436 "L2VPN member configuration\n"
1437 "Pseudowire interface\n"
1438 "Interface's name\n")
1439 {
1440 vty->node = LDP_PSEUDOWIRE_NODE;
1441 return CMD_SUCCESS;
1442 }
1443 #endif
1444
1445 DEFUNSH (VTYSH_ISISD,
1446 router_isis,
1447 router_isis_cmd,
1448 "router isis WORD",
1449 ROUTER_STR
1450 "ISO IS-IS\n"
1451 "ISO Routing area tag")
1452 {
1453 vty->node = ISIS_NODE;
1454 return CMD_SUCCESS;
1455 }
1456
1457 DEFUNSH (VTYSH_RMAP,
1458 vtysh_route_map,
1459 vtysh_route_map_cmd,
1460 "route-map WORD <deny|permit> (1-65535)",
1461 "Create route-map or enter route-map command mode\n"
1462 "Route map tag\n"
1463 "Route map denies set operations\n"
1464 "Route map permits set operations\n"
1465 "Sequence to insert to/delete from existing route-map entry\n")
1466 {
1467 vty->node = RMAP_NODE;
1468 return CMD_SUCCESS;
1469 }
1470
1471 DEFUNSH (VTYSH_ALL,
1472 vtysh_line_vty,
1473 vtysh_line_vty_cmd,
1474 "line vty",
1475 "Configure a terminal line\n"
1476 "Virtual terminal\n")
1477 {
1478 vty->node = VTY_NODE;
1479 return CMD_SUCCESS;
1480 }
1481
1482 DEFUNSH (VTYSH_REALLYALL,
1483 vtysh_enable,
1484 vtysh_enable_cmd,
1485 "enable",
1486 "Turn on privileged mode command\n")
1487 {
1488 vty->node = ENABLE_NODE;
1489 return CMD_SUCCESS;
1490 }
1491
1492 DEFUNSH (VTYSH_REALLYALL,
1493 vtysh_disable,
1494 vtysh_disable_cmd,
1495 "disable",
1496 "Turn off privileged mode command\n")
1497 {
1498 if (vty->node == ENABLE_NODE)
1499 vty->node = VIEW_NODE;
1500 return CMD_SUCCESS;
1501 }
1502
1503 DEFUNSH (VTYSH_REALLYALL,
1504 vtysh_config_terminal,
1505 vtysh_config_terminal_cmd,
1506 "configure terminal",
1507 "Configuration from vty interface\n"
1508 "Configuration terminal\n")
1509 {
1510 vty->node = CONFIG_NODE;
1511 return CMD_SUCCESS;
1512 }
1513
1514 static int
1515 vtysh_exit (struct vty *vty)
1516 {
1517 switch (vty->node)
1518 {
1519 case VIEW_NODE:
1520 case ENABLE_NODE:
1521 exit (0);
1522 break;
1523 case CONFIG_NODE:
1524 vty->node = ENABLE_NODE;
1525 break;
1526 case INTERFACE_NODE:
1527 case NS_NODE:
1528 case VRF_NODE:
1529 case ZEBRA_NODE:
1530 case BGP_NODE:
1531 case RIP_NODE:
1532 case RIPNG_NODE:
1533 case OSPF_NODE:
1534 case OSPF6_NODE:
1535 case EIGRP_NODE:
1536 case LDP_NODE:
1537 case LDP_L2VPN_NODE:
1538 case ISIS_NODE:
1539 case MASC_NODE:
1540 case RMAP_NODE:
1541 case VTY_NODE:
1542 case KEYCHAIN_NODE:
1543 vtysh_execute("end");
1544 vtysh_execute("configure terminal");
1545 vty->node = CONFIG_NODE;
1546 break;
1547 case BGP_VPNV4_NODE:
1548 case BGP_VPNV6_NODE:
1549 case BGP_ENCAP_NODE:
1550 case BGP_ENCAPV6_NODE:
1551 case BGP_IPV4_NODE:
1552 case BGP_IPV4M_NODE:
1553 case BGP_IPV6_NODE:
1554 case BGP_IPV6M_NODE:
1555 case BGP_VRF_POLICY_NODE:
1556 case BGP_EVPN_NODE:
1557 case BGP_VNC_DEFAULTS_NODE:
1558 case BGP_VNC_NVE_GROUP_NODE:
1559 case BGP_VNC_L2_GROUP_NODE:
1560 vty->node = BGP_NODE;
1561 break;
1562 case LDP_IPV4_NODE:
1563 case LDP_IPV6_NODE:
1564 vty->node = LDP_NODE;
1565 break;
1566 case LDP_IPV4_IFACE_NODE:
1567 vty->node = LDP_IPV4_NODE;
1568 break;
1569 case LDP_IPV6_IFACE_NODE:
1570 vty->node = LDP_IPV6_NODE;
1571 break;
1572 case LDP_PSEUDOWIRE_NODE:
1573 vty->node = LDP_L2VPN_NODE;
1574 break;
1575 case KEYCHAIN_KEY_NODE:
1576 vty->node = KEYCHAIN_NODE;
1577 break;
1578 case LINK_PARAMS_NODE:
1579 vty->node = INTERFACE_NODE;
1580 break;
1581 default:
1582 break;
1583 }
1584 return CMD_SUCCESS;
1585 }
1586
1587 DEFUNSH (VTYSH_REALLYALL,
1588 vtysh_exit_all,
1589 vtysh_exit_all_cmd,
1590 "exit",
1591 "Exit current mode and down to previous mode\n")
1592 {
1593 return vtysh_exit (vty);
1594 }
1595
1596 DEFUNSH (VTYSH_ALL,
1597 vtysh_quit_all,
1598 vtysh_quit_all_cmd,
1599 "quit",
1600 "Exit current mode and down to previous mode\n")
1601 {
1602 return vtysh_exit_all (self, vty, argc, argv);
1603 }
1604
1605 DEFUNSH (VTYSH_BGPD,
1606 exit_address_family,
1607 exit_address_family_cmd,
1608 "exit-address-family",
1609 "Exit from Address Family configuration mode\n")
1610 {
1611 if (vty->node == BGP_IPV4_NODE
1612 || vty->node == BGP_IPV4M_NODE
1613 || vty->node == BGP_VPNV4_NODE
1614 || vty->node == BGP_VPNV6_NODE
1615 || vty->node == BGP_ENCAP_NODE
1616 || vty->node == BGP_ENCAPV6_NODE
1617 || vty->node == BGP_IPV6_NODE
1618 || vty->node == BGP_IPV6M_NODE)
1619 vty->node = BGP_NODE;
1620 return CMD_SUCCESS;
1621 }
1622
1623 DEFUNSH (VTYSH_BGPD,
1624 exit_vnc_config,
1625 exit_vnc_config_cmd,
1626 "exit-vnc",
1627 "Exit from VNC configuration mode\n")
1628 {
1629 if (vty->node == BGP_VNC_DEFAULTS_NODE
1630 || vty->node == BGP_VNC_NVE_GROUP_NODE
1631 || vty->node == BGP_VNC_L2_GROUP_NODE)
1632 vty->node = BGP_NODE;
1633 return CMD_SUCCESS;
1634 }
1635
1636 DEFUNSH (VTYSH_BGPD,
1637 exit_vrf_policy,
1638 exit_vrf_policy_cmd,
1639 "exit-vrf-policy",
1640 "Exit from VRF configuration mode\n")
1641 {
1642 if (vty->node == BGP_VRF_POLICY_NODE)
1643 vty->node = BGP_NODE;
1644 return CMD_SUCCESS;
1645 }
1646
1647 DEFUNSH (VTYSH_RIPD,
1648 vtysh_exit_ripd,
1649 vtysh_exit_ripd_cmd,
1650 "exit",
1651 "Exit current mode and down to previous mode\n")
1652 {
1653 return vtysh_exit (vty);
1654 }
1655
1656 DEFUNSH (VTYSH_RIPD,
1657 vtysh_quit_ripd,
1658 vtysh_quit_ripd_cmd,
1659 "quit",
1660 "Exit current mode and down to previous mode\n")
1661 {
1662 return vtysh_exit_ripd (self, vty, argc, argv);
1663 }
1664
1665 DEFUNSH (VTYSH_RIPNGD,
1666 vtysh_exit_ripngd,
1667 vtysh_exit_ripngd_cmd,
1668 "exit",
1669 "Exit current mode and down to previous mode\n")
1670 {
1671 return vtysh_exit (vty);
1672 }
1673
1674 DEFUNSH (VTYSH_RIPNGD,
1675 vtysh_quit_ripngd,
1676 vtysh_quit_ripngd_cmd,
1677 "quit",
1678 "Exit current mode and down to previous mode\n")
1679 {
1680 return vtysh_exit_ripngd (self, vty, argc, argv);
1681 }
1682
1683 DEFUNSH (VTYSH_RMAP,
1684 vtysh_exit_rmap,
1685 vtysh_exit_rmap_cmd,
1686 "exit",
1687 "Exit current mode and down to previous mode\n")
1688 {
1689 return vtysh_exit (vty);
1690 }
1691
1692 DEFUNSH (VTYSH_RMAP,
1693 vtysh_quit_rmap,
1694 vtysh_quit_rmap_cmd,
1695 "quit",
1696 "Exit current mode and down to previous mode\n")
1697 {
1698 return vtysh_exit_rmap (self, vty, argc, argv);
1699 }
1700
1701 DEFUNSH (VTYSH_BGPD,
1702 vtysh_exit_bgpd,
1703 vtysh_exit_bgpd_cmd,
1704 "exit",
1705 "Exit current mode and down to previous mode\n")
1706 {
1707 return vtysh_exit (vty);
1708 }
1709
1710 DEFUNSH (VTYSH_BGPD,
1711 vtysh_quit_bgpd,
1712 vtysh_quit_bgpd_cmd,
1713 "quit",
1714 "Exit current mode and down to previous mode\n")
1715 {
1716 return vtysh_exit_bgpd (self, vty, argc, argv);
1717 }
1718
1719 DEFUNSH (VTYSH_OSPFD,
1720 vtysh_exit_ospfd,
1721 vtysh_exit_ospfd_cmd,
1722 "exit",
1723 "Exit current mode and down to previous mode\n")
1724 {
1725 return vtysh_exit (vty);
1726 }
1727
1728 DEFUNSH (VTYSH_OSPFD,
1729 vtysh_quit_ospfd,
1730 vtysh_quit_ospfd_cmd,
1731 "quit",
1732 "Exit current mode and down to previous mode\n")
1733 {
1734 return vtysh_exit_ospfd (self, vty, argc, argv);
1735 }
1736
1737 DEFUNSH (VTYSH_EIGRPD,
1738 vtysh_exit_eigrpd,
1739 vtysh_exit_eigrpd_cmd,
1740 "exit",
1741 "Exit current mode and down to previous mode\n")
1742 {
1743 return vtysh_exit (vty);
1744 }
1745
1746 DEFUNSH (VTYSH_EIGRPD,
1747 vtysh_quit_eigrpd,
1748 vtysh_quit_eigrpd_cmd,
1749 "quit",
1750 "Exit current mode and down to previous mode\n")
1751 {
1752 return vtysh_exit (vty);
1753 }
1754
1755 DEFUNSH (VTYSH_OSPF6D,
1756 vtysh_exit_ospf6d,
1757 vtysh_exit_ospf6d_cmd,
1758 "exit",
1759 "Exit current mode and down to previous mode\n")
1760 {
1761 return vtysh_exit (vty);
1762 }
1763
1764 DEFUNSH (VTYSH_OSPF6D,
1765 vtysh_quit_ospf6d,
1766 vtysh_quit_ospf6d_cmd,
1767 "quit",
1768 "Exit current mode and down to previous mode\n")
1769 {
1770 return vtysh_exit_ospf6d (self, vty, argc, argv);
1771 }
1772
1773 #if defined (HAVE_LDPD)
1774 DEFUNSH (VTYSH_LDPD,
1775 vtysh_exit_ldpd,
1776 vtysh_exit_ldpd_cmd,
1777 "exit",
1778 "Exit current mode and down to previous mode\n")
1779 {
1780 return vtysh_exit (vty);
1781 }
1782
1783 ALIAS (vtysh_exit_ldpd,
1784 vtysh_quit_ldpd_cmd,
1785 "quit",
1786 "Exit current mode and down to previous mode\n")
1787 #endif
1788
1789 DEFUNSH (VTYSH_ISISD,
1790 vtysh_exit_isisd,
1791 vtysh_exit_isisd_cmd,
1792 "exit",
1793 "Exit current mode and down to previous mode\n")
1794 {
1795 return vtysh_exit (vty);
1796 }
1797
1798 DEFUNSH (VTYSH_ISISD,
1799 vtysh_quit_isisd,
1800 vtysh_quit_isisd_cmd,
1801 "quit",
1802 "Exit current mode and down to previous mode\n")
1803 {
1804 return vtysh_exit_isisd (self, vty, argc, argv);
1805 }
1806
1807 DEFUNSH (VTYSH_ALL,
1808 vtysh_exit_line_vty,
1809 vtysh_exit_line_vty_cmd,
1810 "exit",
1811 "Exit current mode and down to previous mode\n")
1812 {
1813 return vtysh_exit (vty);
1814 }
1815
1816 DEFUNSH (VTYSH_ALL,
1817 vtysh_quit_line_vty,
1818 vtysh_quit_line_vty_cmd,
1819 "quit",
1820 "Exit current mode and down to previous mode\n")
1821 {
1822 return vtysh_exit_line_vty (self, vty, argc, argv);
1823 }
1824
1825 DEFUNSH (VTYSH_INTERFACE,
1826 vtysh_interface,
1827 vtysh_interface_cmd,
1828 "interface IFNAME [vrf NAME]",
1829 "Select an interface to configure\n"
1830 "Interface's name\n"
1831 VRF_CMD_HELP_STR)
1832 {
1833 vty->node = INTERFACE_NODE;
1834 return CMD_SUCCESS;
1835 }
1836
1837 /* TODO Implement "no interface command in isisd. */
1838 DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_EIGRPD,
1839 vtysh_no_interface_cmd,
1840 "no interface IFNAME",
1841 NO_STR
1842 "Delete a pseudo interface's configuration\n"
1843 "Interface's name\n")
1844
1845 DEFSH (VTYSH_ZEBRA,
1846 vtysh_no_interface_vrf_cmd,
1847 "no interface IFNAME vrf NAME",
1848 NO_STR
1849 "Delete a pseudo interface's configuration\n"
1850 "Interface's name\n"
1851 VRF_CMD_HELP_STR)
1852
1853 DEFUNSH (VTYSH_NS,
1854 vtysh_ns,
1855 vtysh_ns_cmd,
1856 "logical-router (1-65535) ns NAME",
1857 "Enable a logical-router\n"
1858 "Specify the logical-router indentifier\n"
1859 "The Name Space\n"
1860 "The file name in " NS_RUN_DIR ", or a full pathname\n")
1861 {
1862 vty->node = NS_NODE;
1863 return CMD_SUCCESS;
1864 }
1865
1866 DEFUNSH (VTYSH_VRF,
1867 vtysh_vrf,
1868 vtysh_vrf_cmd,
1869 "vrf NAME",
1870 "Select a VRF to configure\n"
1871 "VRF's name\n")
1872 {
1873 vty->node = VRF_NODE;
1874 return CMD_SUCCESS;
1875 }
1876
1877 DEFSH (VTYSH_ZEBRA,
1878 vtysh_no_vrf_cmd,
1879 "no vrf NAME",
1880 NO_STR
1881 "Delete a pseudo vrf's configuration\n"
1882 "VRF's name\n")
1883
1884 DEFUNSH (VTYSH_NS,
1885 vtysh_exit_ns,
1886 vtysh_exit_ns_cmd,
1887 "exit",
1888 "Exit current mode and down to previous mode\n")
1889 {
1890 return vtysh_exit (vty);
1891 }
1892
1893 DEFUNSH (VTYSH_NS,
1894 vtysh_quit_ns,
1895 vtysh_quit_ns_cmd,
1896 "quit",
1897 "Exit current mode and down to previous mode\n")
1898 {
1899 return vtysh_exit_ns(self, vty, argc, argv);
1900 }
1901
1902 DEFUNSH (VTYSH_VRF,
1903 vtysh_exit_vrf,
1904 vtysh_exit_vrf_cmd,
1905 "exit",
1906 "Exit current mode and down to previous mode\n")
1907 {
1908 return vtysh_exit (vty);
1909 }
1910
1911 DEFUNSH (VTYSH_VRF,
1912 vtysh_quit_vrf,
1913 vtysh_quit_vrf_cmd,
1914 "quit",
1915 "Exit current mode and down to previous mode\n")
1916 {
1917 return vtysh_exit_vrf (self, vty, argc, argv);
1918 }
1919
1920 /* TODO Implement interface description commands in ripngd, ospf6d
1921 * and isisd. */
1922 DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD|VTYSH_EIGRPD,
1923 vtysh_interface_desc_cmd,
1924 "description LINE...",
1925 "Interface specific description\n"
1926 "Characters describing this interface\n")
1927
1928 DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD|VTYSH_EIGRPD,
1929 vtysh_no_interface_desc_cmd,
1930 "no description",
1931 NO_STR
1932 "Interface specific description\n")
1933
1934 DEFUNSH (VTYSH_INTERFACE,
1935 vtysh_exit_interface,
1936 vtysh_exit_interface_cmd,
1937 "exit",
1938 "Exit current mode and down to previous mode\n")
1939 {
1940 return vtysh_exit (vty);
1941 }
1942
1943 DEFUNSH (VTYSH_INTERFACE,
1944 vtysh_quit_interface,
1945 vtysh_quit_interface_cmd,
1946 "quit",
1947 "Exit current mode and down to previous mode\n")
1948 {
1949 return vtysh_exit_interface (self, vty, argc, argv);
1950 }
1951
1952 DEFUN (vtysh_show_thread,
1953 vtysh_show_thread_cmd,
1954 "show thread cpu [FILTER]",
1955 SHOW_STR
1956 "Thread information\n"
1957 "Thread CPU usage\n"
1958 "Display filter (rwtexb)\n")
1959 {
1960 int idx_filter = 3;
1961 unsigned int i;
1962 int ret = CMD_SUCCESS;
1963 char line[100];
1964
1965 sprintf(line, "show thread cpu %s\n", (argc == 4) ? argv[idx_filter]->arg : "");
1966 for (i = 0; i < array_size(vtysh_client); i++)
1967 if ( vtysh_client[i].fd >= 0 )
1968 {
1969 fprintf (stdout, "Thread statistics for %s:\n",
1970 vtysh_client[i].name);
1971 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1972 fprintf (stdout,"\n");
1973 }
1974 return ret;
1975 }
1976
1977 DEFUN (vtysh_show_work_queues,
1978 vtysh_show_work_queues_cmd,
1979 "show work-queues",
1980 SHOW_STR
1981 "Work Queue information\n")
1982 {
1983 unsigned int i;
1984 int ret = CMD_SUCCESS;
1985 char line[] = "show work-queues\n";
1986
1987 for (i = 0; i < array_size(vtysh_client); i++)
1988 if ( vtysh_client[i].fd >= 0 )
1989 {
1990 fprintf (stdout, "Work queue statistics for %s:\n",
1991 vtysh_client[i].name);
1992 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1993 fprintf (stdout,"\n");
1994 }
1995
1996 return ret;
1997 }
1998
1999 DEFUN (vtysh_show_work_queues_daemon,
2000 vtysh_show_work_queues_daemon_cmd,
2001 "show work-queues <zebra|ripd|ripngd|ospfd|ospf6d|bgpd|isisd>",
2002 SHOW_STR
2003 "Work Queue information\n"
2004 "For the zebra daemon\n"
2005 "For the rip daemon\n"
2006 "For the ripng daemon\n"
2007 "For the ospf daemon\n"
2008 "For the ospfv6 daemon\n"
2009 "For the bgp daemon\n"
2010 "For the isis daemon\n")
2011 {
2012 int idx_protocol = 2;
2013 unsigned int i;
2014 int ret = CMD_SUCCESS;
2015
2016 for (i = 0; i < array_size(vtysh_client); i++)
2017 {
2018 if (strmatch(vtysh_client[i].name, argv[idx_protocol]->text))
2019 break;
2020 }
2021
2022 ret = vtysh_client_execute(&vtysh_client[i], "show work-queues\n", stdout);
2023
2024 return ret;
2025 }
2026
2027 DEFUNSH (VTYSH_ZEBRA,
2028 vtysh_link_params,
2029 vtysh_link_params_cmd,
2030 "link-params",
2031 LINK_PARAMS_STR
2032 )
2033 {
2034 vty->node = LINK_PARAMS_NODE;
2035 return CMD_SUCCESS;
2036 }
2037
2038 DEFUNSH (VTYSH_ZEBRA,
2039 exit_link_params,
2040 exit_link_params_cmd,
2041 "exit-link-params",
2042 "Exit from Link Params configuration node\n")
2043 {
2044 if (vty->node == LINK_PARAMS_NODE)
2045 vty->node = INTERFACE_NODE;
2046 return CMD_SUCCESS;
2047 }
2048
2049 static int
2050 show_per_daemon (const char *line, const char *headline)
2051 {
2052 unsigned int i;
2053 int ret = CMD_SUCCESS;
2054
2055 for (i = 0; i < array_size(vtysh_client); i++)
2056 if ( vtysh_client[i].fd >= 0 )
2057 {
2058 fprintf (stdout, headline,
2059 vtysh_client[i].name);
2060 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
2061 fprintf (stdout,"\n");
2062 }
2063
2064 return ret;
2065 }
2066
2067 /* Memory */
2068 DEFUN (vtysh_show_memory,
2069 vtysh_show_memory_cmd,
2070 "show memory",
2071 SHOW_STR
2072 "Memory statistics\n")
2073 {
2074 return show_per_daemon ("show memory\n", "Memory statistics for %s:\n");
2075 }
2076
2077 DEFUN (vtysh_show_modules,
2078 vtysh_show_modules_cmd,
2079 "show modules",
2080 SHOW_STR
2081 "Loaded modules\n")
2082 {
2083 return show_per_daemon ("show modules\n", "Module information for %s:\n");
2084 }
2085
2086 /* Logging commands. */
2087 DEFUN (vtysh_show_logging,
2088 vtysh_show_logging_cmd,
2089 "show logging",
2090 SHOW_STR
2091 "Show current logging configuration\n")
2092 {
2093 unsigned int i;
2094 int ret = CMD_SUCCESS;
2095 char line[] = "show logging\n";
2096
2097 for (i = 0; i < array_size(vtysh_client); i++)
2098 if ( vtysh_client[i].fd >= 0 )
2099 {
2100 fprintf (stdout,"Logging configuration for %s:\n",
2101 vtysh_client[i].name);
2102 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
2103 fprintf (stdout,"\n");
2104 }
2105
2106 return ret;
2107 }
2108
2109 DEFUNSH (VTYSH_ALL,
2110 vtysh_log_stdout,
2111 vtysh_log_stdout_cmd,
2112 "log stdout",
2113 "Logging control\n"
2114 "Set stdout logging level\n")
2115 {
2116 return CMD_SUCCESS;
2117 }
2118
2119 DEFUNSH (VTYSH_ALL,
2120 vtysh_log_stdout_level,
2121 vtysh_log_stdout_level_cmd,
2122 "log stdout <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
2123 "Logging control\n"
2124 "Set stdout logging level\n"
2125 LOG_LEVEL_DESC)
2126 {
2127 return CMD_SUCCESS;
2128 }
2129
2130 DEFUNSH (VTYSH_ALL,
2131 no_vtysh_log_stdout,
2132 no_vtysh_log_stdout_cmd,
2133 "no log stdout [LEVEL]",
2134 NO_STR
2135 "Logging control\n"
2136 "Cancel logging to stdout\n"
2137 "Logging level\n")
2138 {
2139 return CMD_SUCCESS;
2140 }
2141
2142 DEFUNSH (VTYSH_ALL,
2143 vtysh_log_file,
2144 vtysh_log_file_cmd,
2145 "log file FILENAME",
2146 "Logging control\n"
2147 "Logging to file\n"
2148 "Logging filename\n")
2149 {
2150 return CMD_SUCCESS;
2151 }
2152
2153 DEFUNSH (VTYSH_ALL,
2154 vtysh_log_file_level,
2155 vtysh_log_file_level_cmd,
2156 "log file FILENAME <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
2157 "Logging control\n"
2158 "Logging to file\n"
2159 "Logging filename\n"
2160 LOG_LEVEL_DESC)
2161 {
2162 return CMD_SUCCESS;
2163 }
2164
2165 DEFUNSH (VTYSH_ALL,
2166 no_vtysh_log_file,
2167 no_vtysh_log_file_cmd,
2168 "no log file [FILENAME [LEVEL]]",
2169 NO_STR
2170 "Logging control\n"
2171 "Cancel logging to file\n"
2172 "Logging file name\n"
2173 "Logging level\n")
2174 {
2175 return CMD_SUCCESS;
2176 }
2177
2178 DEFUNSH (VTYSH_ALL,
2179 vtysh_log_monitor,
2180 vtysh_log_monitor_cmd,
2181 "log monitor [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
2182 "Logging control\n"
2183 "Set terminal line (monitor) logging level\n"
2184 LOG_LEVEL_DESC)
2185 {
2186 return CMD_SUCCESS;
2187 }
2188
2189 DEFUNSH (VTYSH_ALL,
2190 no_vtysh_log_monitor,
2191 no_vtysh_log_monitor_cmd,
2192 "no log monitor [LEVEL]",
2193 NO_STR
2194 "Logging control\n"
2195 "Disable terminal line (monitor) logging\n"
2196 "Logging level\n")
2197 {
2198 return CMD_SUCCESS;
2199 }
2200
2201 DEFUNSH (VTYSH_ALL,
2202 vtysh_log_syslog,
2203 vtysh_log_syslog_cmd,
2204 "log syslog [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
2205 "Logging control\n"
2206 "Set syslog logging level\n"
2207 LOG_LEVEL_DESC)
2208 {
2209 return CMD_SUCCESS;
2210 }
2211
2212 DEFUNSH (VTYSH_ALL,
2213 no_vtysh_log_syslog,
2214 no_vtysh_log_syslog_cmd,
2215 "no log syslog [LEVEL]",
2216 NO_STR
2217 "Logging control\n"
2218 "Cancel logging to syslog\n"
2219 "Logging level\n")
2220 {
2221 return CMD_SUCCESS;
2222 }
2223
2224 DEFUNSH (VTYSH_ALL,
2225 vtysh_log_facility,
2226 vtysh_log_facility_cmd,
2227 "log facility <kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|local0|local1|local2|local3|local4|local5|local6|local7>",
2228 "Logging control\n"
2229 "Facility parameter for syslog messages\n"
2230 LOG_FACILITY_DESC)
2231
2232 {
2233 return CMD_SUCCESS;
2234 }
2235
2236 DEFUNSH (VTYSH_ALL,
2237 no_vtysh_log_facility,
2238 no_vtysh_log_facility_cmd,
2239 "no log facility [FACILITY]",
2240 NO_STR
2241 "Logging control\n"
2242 "Reset syslog facility to default (daemon)\n"
2243 "Syslog facility\n")
2244
2245 {
2246 return CMD_SUCCESS;
2247 }
2248
2249 DEFUNSH_DEPRECATED (VTYSH_ALL,
2250 vtysh_log_trap,
2251 vtysh_log_trap_cmd,
2252 "log trap <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
2253 "Logging control\n"
2254 "(Deprecated) Set logging level and default for all destinations\n"
2255 LOG_LEVEL_DESC)
2256
2257 {
2258 return CMD_SUCCESS;
2259 }
2260
2261 DEFUNSH_DEPRECATED (VTYSH_ALL,
2262 no_vtysh_log_trap,
2263 no_vtysh_log_trap_cmd,
2264 "no log trap [LEVEL]",
2265 NO_STR
2266 "Logging control\n"
2267 "Permit all logging information\n"
2268 "Logging level\n")
2269 {
2270 return CMD_SUCCESS;
2271 }
2272
2273 DEFUNSH (VTYSH_ALL,
2274 vtysh_log_record_priority,
2275 vtysh_log_record_priority_cmd,
2276 "log record-priority",
2277 "Logging control\n"
2278 "Log the priority of the message within the message\n")
2279 {
2280 return CMD_SUCCESS;
2281 }
2282
2283 DEFUNSH (VTYSH_ALL,
2284 no_vtysh_log_record_priority,
2285 no_vtysh_log_record_priority_cmd,
2286 "no log record-priority",
2287 NO_STR
2288 "Logging control\n"
2289 "Do not log the priority of the message within the message\n")
2290 {
2291 return CMD_SUCCESS;
2292 }
2293
2294 DEFUNSH (VTYSH_ALL,
2295 vtysh_log_timestamp_precision,
2296 vtysh_log_timestamp_precision_cmd,
2297 "log timestamp precision (0-6)",
2298 "Logging control\n"
2299 "Timestamp configuration\n"
2300 "Set the timestamp precision\n"
2301 "Number of subsecond digits\n")
2302 {
2303 return CMD_SUCCESS;
2304 }
2305
2306 DEFUNSH (VTYSH_ALL,
2307 no_vtysh_log_timestamp_precision,
2308 no_vtysh_log_timestamp_precision_cmd,
2309 "no log timestamp precision",
2310 NO_STR
2311 "Logging control\n"
2312 "Timestamp configuration\n"
2313 "Reset the timestamp precision to the default value of 0\n")
2314 {
2315 return CMD_SUCCESS;
2316 }
2317
2318 DEFUNSH (VTYSH_ALL,
2319 vtysh_service_password_encrypt,
2320 vtysh_service_password_encrypt_cmd,
2321 "service password-encryption",
2322 "Set up miscellaneous service\n"
2323 "Enable encrypted passwords\n")
2324 {
2325 return CMD_SUCCESS;
2326 }
2327
2328 DEFUNSH (VTYSH_ALL,
2329 no_vtysh_service_password_encrypt,
2330 no_vtysh_service_password_encrypt_cmd,
2331 "no service password-encryption",
2332 NO_STR
2333 "Set up miscellaneous service\n"
2334 "Enable encrypted passwords\n")
2335 {
2336 return CMD_SUCCESS;
2337 }
2338
2339 DEFUNSH (VTYSH_ALL,
2340 vtysh_config_password,
2341 vtysh_password_cmd,
2342 "password (8-8) WORD",
2343 "Assign the terminal connection password\n"
2344 "Specifies a HIDDEN password will follow\n"
2345 "dummy string \n"
2346 "The HIDDEN line password string\n")
2347 {
2348 return CMD_SUCCESS;
2349 }
2350
2351 DEFUNSH (VTYSH_ALL,
2352 vtysh_password_text,
2353 vtysh_password_text_cmd,
2354 "password LINE",
2355 "Assign the terminal connection password\n"
2356 "The UNENCRYPTED (cleartext) line password\n")
2357 {
2358 return CMD_SUCCESS;
2359 }
2360
2361 DEFUNSH (VTYSH_ALL,
2362 vtysh_config_enable_password,
2363 vtysh_enable_password_cmd,
2364 "enable password (8-8) WORD",
2365 "Modify enable password parameters\n"
2366 "Assign the privileged level password\n"
2367 "Specifies a HIDDEN password will follow\n"
2368 "The HIDDEN 'enable' password string\n")
2369 {
2370 return CMD_SUCCESS;
2371 }
2372
2373 DEFUNSH (VTYSH_ALL,
2374 vtysh_enable_password_text,
2375 vtysh_enable_password_text_cmd,
2376 "enable password LINE",
2377 "Modify enable password parameters\n"
2378 "Assign the privileged level password\n"
2379 "The UNENCRYPTED (cleartext) 'enable' password\n")
2380 {
2381 return CMD_SUCCESS;
2382 }
2383
2384 DEFUNSH (VTYSH_ALL,
2385 no_vtysh_config_enable_password,
2386 no_vtysh_enable_password_cmd,
2387 "no enable password",
2388 NO_STR
2389 "Modify enable password parameters\n"
2390 "Assign the privileged level password\n")
2391 {
2392 return CMD_SUCCESS;
2393 }
2394
2395 DEFUN (vtysh_write_terminal,
2396 vtysh_write_terminal_cmd,
2397 "write terminal [<zebra|ripd|ripngd|ospfd|ospf6d|ldpd|bgpd|isisd|pimd>]",
2398 "Write running configuration to memory, network, or terminal\n"
2399 "Write to terminal\n"
2400 "For the zebra daemon\n"
2401 "For the rip daemon\n"
2402 "For the ripng daemon\n"
2403 "For the ospf daemon\n"
2404 "For the ospfv6 daemon\n"
2405 "For the ldpd daemon\n"
2406 "For the bgp daemon\n"
2407 "For the isis daemon\n"
2408 "For the pim daemon\n")
2409 {
2410 u_int i;
2411 char line[] = "write terminal\n";
2412 FILE *fp = NULL;
2413
2414 if (vtysh_pager_name)
2415 {
2416 fp = popen (vtysh_pager_name, "w");
2417 if (fp == NULL)
2418 {
2419 perror ("popen");
2420 exit (1);
2421 }
2422 }
2423 else
2424 fp = stdout;
2425
2426 vty_out (vty, "Building configuration...%s", VTY_NEWLINE);
2427 vty_out (vty, "%sCurrent configuration:%s", VTY_NEWLINE,
2428 VTY_NEWLINE);
2429 vty_out (vty, "!%s", VTY_NEWLINE);
2430
2431 for (i = 0; i < array_size(vtysh_client); i++)
2432 if ((argc < 3 ) || (strmatch (vtysh_client[i].name, argv[2]->text)))
2433 vtysh_client_config (&vtysh_client[i], line);
2434
2435 /* Integrate vtysh specific configuration. */
2436 vtysh_config_write ();
2437
2438 vtysh_config_dump (fp);
2439
2440 if (vtysh_pager_name && fp)
2441 {
2442 fflush (fp);
2443 if (pclose (fp) == -1)
2444 {
2445 perror ("pclose");
2446 exit (1);
2447 }
2448 fp = NULL;
2449 }
2450
2451 vty_out (vty, "end%s", VTY_NEWLINE);
2452 return CMD_SUCCESS;
2453 }
2454
2455 DEFUN (vtysh_show_running_config,
2456 vtysh_show_running_config_cmd,
2457 "show running-config [<zebra|ripd|ripngd|ospfd|ospf6d|ldpd|bgpd|isisd|pimd>]",
2458 SHOW_STR
2459 "Current operating configuration\n"
2460 "For the zebra daemon\n"
2461 "For the rip daemon\n"
2462 "For the ripng daemon\n"
2463 "For the ospf daemon\n"
2464 "For the ospfv6 daemon\n"
2465 "For the ldp daemon\n"
2466 "For the bgp daemon\n"
2467 "For the isis daemon\n"
2468 "For the pim daemon\n")
2469 {
2470 return vtysh_write_terminal (self, vty, argc, argv);
2471 }
2472
2473 DEFUN (vtysh_integrated_config,
2474 vtysh_integrated_config_cmd,
2475 "service integrated-vtysh-config",
2476 "Set up miscellaneous service\n"
2477 "Write configuration into integrated file\n")
2478 {
2479 vtysh_write_integrated = WRITE_INTEGRATED_YES;
2480 return CMD_SUCCESS;
2481 }
2482
2483 DEFUN (no_vtysh_integrated_config,
2484 no_vtysh_integrated_config_cmd,
2485 "no service integrated-vtysh-config",
2486 NO_STR
2487 "Set up miscellaneous service\n"
2488 "Write configuration into integrated file\n")
2489 {
2490 vtysh_write_integrated = WRITE_INTEGRATED_NO;
2491 return CMD_SUCCESS;
2492 }
2493
2494 static void
2495 backup_config_file (const char *fbackup)
2496 {
2497 char *integrate_sav = NULL;
2498
2499 integrate_sav = malloc (strlen (fbackup) +
2500 strlen (CONF_BACKUP_EXT) + 1);
2501 strcpy (integrate_sav, fbackup);
2502 strcat (integrate_sav, CONF_BACKUP_EXT);
2503
2504 /* Move current configuration file to backup config file. */
2505 unlink (integrate_sav);
2506 rename (fbackup, integrate_sav);
2507 free (integrate_sav);
2508 }
2509
2510 int
2511 vtysh_write_config_integrated(void)
2512 {
2513 u_int i;
2514 char line[] = "write terminal\n";
2515 FILE *fp;
2516 int fd;
2517 struct passwd *pwentry;
2518 struct group *grentry;
2519 uid_t uid = -1;
2520 gid_t gid = -1;
2521 struct stat st;
2522 int err = 0;
2523
2524 fprintf (stdout,"Building Configuration...\n");
2525
2526 backup_config_file(quagga_config);
2527 fp = fopen (quagga_config, "w");
2528 if (fp == NULL)
2529 {
2530 fprintf (stdout,"%% Error: failed to open configuration file %s: %s\n",
2531 quagga_config, safe_strerror(errno));
2532 return CMD_WARNING;
2533 }
2534 fd = fileno (fp);
2535
2536 for (i = 0; i < array_size(vtysh_client); i++)
2537 vtysh_client_config (&vtysh_client[i], line);
2538
2539 vtysh_config_write ();
2540 vtysh_config_dump (fp);
2541
2542 if (fchmod (fd, CONFIGFILE_MASK) != 0)
2543 {
2544 printf ("%% Warning: can't chmod configuration file %s: %s\n",
2545 quagga_config, safe_strerror(errno));
2546 err++;
2547 }
2548
2549 pwentry = getpwnam (FRR_USER);
2550 if (pwentry)
2551 uid = pwentry->pw_uid;
2552 else
2553 {
2554 printf ("%% Warning: could not look up user \"%s\"\n", FRR_USER);
2555 err++;
2556 }
2557
2558 grentry = getgrnam (FRR_GROUP);
2559 if (grentry)
2560 gid = grentry->gr_gid;
2561 else
2562 {
2563 printf ("%% Warning: could not look up group \"%s\"\n", FRR_GROUP);
2564 err++;
2565 }
2566
2567 if (!fstat (fd, &st))
2568 {
2569 if (st.st_uid == uid)
2570 uid = -1;
2571 if (st.st_gid == gid)
2572 gid = -1;
2573 if ((uid != (uid_t)-1 || gid != (gid_t)-1) && fchown (fd, uid, gid))
2574 {
2575 printf ("%% Warning: can't chown configuration file %s: %s\n",
2576 quagga_config, safe_strerror(errno));
2577 err++;
2578 }
2579 }
2580 else
2581 {
2582 printf ("%% Warning: stat() failed on %s: %s\n",
2583 quagga_config, safe_strerror(errno));
2584 err++;
2585 }
2586
2587 fclose (fp);
2588
2589 printf ("Integrated configuration saved to %s\n", quagga_config);
2590 if (err)
2591 return CMD_WARNING;
2592
2593 printf ("[OK]\n");
2594 return CMD_SUCCESS;
2595 }
2596
2597 static bool want_config_integrated(void)
2598 {
2599 struct stat s;
2600
2601 switch (vtysh_write_integrated)
2602 {
2603 case WRITE_INTEGRATED_UNSPECIFIED:
2604 if (stat(quagga_config, &s) && errno == ENOENT)
2605 return false;
2606 return true;
2607 case WRITE_INTEGRATED_NO:
2608 return false;
2609 case WRITE_INTEGRATED_YES:
2610 return true;
2611 }
2612 return true;
2613 }
2614
2615 DEFUN (vtysh_write_memory,
2616 vtysh_write_memory_cmd,
2617 "write [<memory|file>]",
2618 "Write running configuration to memory, network, or terminal\n"
2619 "Write configuration to the file (same as write file)\n"
2620 "Write configuration to the file (same as write memory)\n")
2621 {
2622 int ret = CMD_SUCCESS;
2623 char line[] = "write memory\n";
2624 u_int i;
2625
2626 fprintf (stdout, "Note: this version of vtysh never writes vtysh.conf\n");
2627
2628 /* If integrated frr.conf explicitely set. */
2629 if (want_config_integrated())
2630 {
2631 ret = CMD_WARNING;
2632 for (i = 0; i < array_size(vtysh_client); i++)
2633 if (vtysh_client[i].flag == VTYSH_WATCHFRR)
2634 break;
2635 if (i < array_size(vtysh_client) && vtysh_client[i].fd != -1)
2636 ret = vtysh_client_execute (&vtysh_client[i], "write integrated", stdout);
2637
2638 if (ret != CMD_SUCCESS)
2639 {
2640 printf("\nWarning: attempting direct configuration write without "
2641 "watchfrr.\nFile permissions and ownership may be "
2642 "incorrect, or write may fail.\n\n");
2643 ret = vtysh_write_config_integrated();
2644 }
2645 return ret;
2646 }
2647
2648 fprintf (stdout,"Building Configuration...\n");
2649
2650 for (i = 0; i < array_size(vtysh_client); i++)
2651 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
2652
2653 return ret;
2654 }
2655
2656 DEFUN (vtysh_copy_running_config,
2657 vtysh_copy_running_config_cmd,
2658 "copy running-config startup-config",
2659 "Copy from one file to another\n"
2660 "Copy from current system configuration\n"
2661 "Copy to startup configuration\n")
2662 {
2663 return vtysh_write_memory (self, vty, argc, argv);
2664 }
2665
2666 DEFUN (vtysh_terminal_length,
2667 vtysh_terminal_length_cmd,
2668 "terminal length (0-512)",
2669 "Set terminal line parameters\n"
2670 "Set number of lines on a screen\n"
2671 "Number of lines on screen (0 for no pausing)\n")
2672 {
2673 int idx_number = 2;
2674 int lines;
2675 char *endptr = NULL;
2676 char default_pager[10];
2677
2678 lines = strtol (argv[idx_number]->arg, &endptr, 10);
2679 if (lines < 0 || lines > 512 || *endptr != '\0')
2680 {
2681 vty_out (vty, "length is malformed%s", VTY_NEWLINE);
2682 return CMD_WARNING;
2683 }
2684
2685 if (vtysh_pager_name)
2686 {
2687 free (vtysh_pager_name);
2688 vtysh_pager_name = NULL;
2689 }
2690
2691 if (lines != 0)
2692 {
2693 snprintf(default_pager, 10, "more -%i", lines);
2694 vtysh_pager_name = strdup (default_pager);
2695 }
2696
2697 return CMD_SUCCESS;
2698 }
2699
2700 DEFUN (vtysh_terminal_no_length,
2701 vtysh_terminal_no_length_cmd,
2702 "terminal no length",
2703 "Set terminal line parameters\n"
2704 NO_STR
2705 "Set number of lines on a screen\n")
2706 {
2707 if (vtysh_pager_name)
2708 {
2709 free (vtysh_pager_name);
2710 vtysh_pager_name = NULL;
2711 }
2712
2713 vtysh_pager_init();
2714 return CMD_SUCCESS;
2715 }
2716
2717 DEFUN (vtysh_show_daemons,
2718 vtysh_show_daemons_cmd,
2719 "show daemons",
2720 SHOW_STR
2721 "Show list of running daemons\n")
2722 {
2723 u_int i;
2724
2725 for (i = 0; i < array_size(vtysh_client); i++)
2726 if ( vtysh_client[i].fd >= 0 )
2727 vty_out(vty, " %s", vtysh_client[i].name);
2728 vty_out(vty, "%s", VTY_NEWLINE);
2729
2730 return CMD_SUCCESS;
2731 }
2732
2733 /* Execute command in child process. */
2734 static void
2735 execute_command (const char *command, int argc, struct cmd_token *arg1,
2736 const char *arg2)
2737 {
2738 pid_t pid;
2739 int status;
2740
2741 /* Call fork(). */
2742 pid = fork ();
2743
2744 if (pid < 0)
2745 {
2746 /* Failure of fork(). */
2747 fprintf (stderr, "Can't fork: %s\n", safe_strerror (errno));
2748 exit (1);
2749 }
2750 else if (pid == 0)
2751 {
2752 /* This is child process. */
2753 switch (argc)
2754 {
2755 case 0:
2756 execlp (command, command, (const char *)NULL);
2757 break;
2758 case 1:
2759 execlp (command, command, arg1, (const char *)NULL);
2760 break;
2761 case 2:
2762 execlp (command, command, arg1, arg2, (const char *)NULL);
2763 break;
2764 }
2765
2766 /* When execlp suceed, this part is not executed. */
2767 fprintf (stderr, "Can't execute %s: %s\n", command, safe_strerror (errno));
2768 exit (1);
2769 }
2770 else
2771 {
2772 /* This is parent. */
2773 execute_flag = 1;
2774 wait4 (pid, &status, 0, NULL);
2775 execute_flag = 0;
2776 }
2777 }
2778
2779 DEFUN (vtysh_ping,
2780 vtysh_ping_cmd,
2781 "ping WORD",
2782 "Send echo messages\n"
2783 "Ping destination address or hostname\n")
2784 {
2785 execute_command ("ping", 1, argv[0], NULL);
2786 return CMD_SUCCESS;
2787 }
2788
2789 ALIAS (vtysh_ping,
2790 vtysh_ping_ip_cmd,
2791 "ping ip WORD",
2792 "Send echo messages\n"
2793 "IP echo\n"
2794 "Ping destination address or hostname\n")
2795
2796 DEFUN (vtysh_traceroute,
2797 vtysh_traceroute_cmd,
2798 "traceroute WORD",
2799 "Trace route to destination\n"
2800 "Trace route to destination address or hostname\n")
2801 {
2802 execute_command ("traceroute", 1, argv[0], NULL);
2803 return CMD_SUCCESS;
2804 }
2805
2806 ALIAS (vtysh_traceroute,
2807 vtysh_traceroute_ip_cmd,
2808 "traceroute ip WORD",
2809 "Trace route to destination\n"
2810 "IP trace\n"
2811 "Trace route to destination address or hostname\n")
2812
2813 DEFUN (vtysh_ping6,
2814 vtysh_ping6_cmd,
2815 "ping ipv6 WORD",
2816 "Send echo messages\n"
2817 "IPv6 echo\n"
2818 "Ping destination address or hostname\n")
2819 {
2820 execute_command ("ping6", 1, argv[0], NULL);
2821 return CMD_SUCCESS;
2822 }
2823
2824 DEFUN (vtysh_traceroute6,
2825 vtysh_traceroute6_cmd,
2826 "traceroute ipv6 WORD",
2827 "Trace route to destination\n"
2828 "IPv6 trace\n"
2829 "Trace route to destination address or hostname\n")
2830 {
2831 execute_command ("traceroute6", 1, argv[0], NULL);
2832 return CMD_SUCCESS;
2833 }
2834
2835 #if defined(HAVE_SHELL_ACCESS)
2836 DEFUN (vtysh_telnet,
2837 vtysh_telnet_cmd,
2838 "telnet WORD",
2839 "Open a telnet connection\n"
2840 "IP address or hostname of a remote system\n")
2841 {
2842 execute_command ("telnet", 1, argv[0], NULL);
2843 return CMD_SUCCESS;
2844 }
2845
2846 DEFUN (vtysh_telnet_port,
2847 vtysh_telnet_port_cmd,
2848 "telnet WORD PORT",
2849 "Open a telnet connection\n"
2850 "IP address or hostname of a remote system\n"
2851 "TCP Port number\n")
2852 {
2853 execute_command ("telnet", 2, argv[0], argv[1]);
2854 return CMD_SUCCESS;
2855 }
2856
2857 DEFUN (vtysh_ssh,
2858 vtysh_ssh_cmd,
2859 "ssh WORD",
2860 "Open an ssh connection\n"
2861 "[user@]host\n")
2862 {
2863 execute_command ("ssh", 1, argv[0], NULL);
2864 return CMD_SUCCESS;
2865 }
2866
2867 DEFUN (vtysh_start_shell,
2868 vtysh_start_shell_cmd,
2869 "start-shell",
2870 "Start UNIX shell\n")
2871 {
2872 execute_command ("sh", 0, NULL, NULL);
2873 return CMD_SUCCESS;
2874 }
2875
2876 DEFUN (vtysh_start_bash,
2877 vtysh_start_bash_cmd,
2878 "start-shell bash",
2879 "Start UNIX shell\n"
2880 "Start bash\n")
2881 {
2882 execute_command ("bash", 0, NULL, NULL);
2883 return CMD_SUCCESS;
2884 }
2885
2886 DEFUN (vtysh_start_zsh,
2887 vtysh_start_zsh_cmd,
2888 "start-shell zsh",
2889 "Start UNIX shell\n"
2890 "Start Z shell\n")
2891 {
2892 execute_command ("zsh", 0, NULL, NULL);
2893 return CMD_SUCCESS;
2894 }
2895 #endif
2896
2897 DEFUN (config_list,
2898 config_list_cmd,
2899 "list [permutations]",
2900 "Print command list\n"
2901 "Print all possible command permutations\n")
2902 {
2903 return cmd_list_cmds (vty, argc == 2);
2904 }
2905
2906 static void
2907 vtysh_install_default (enum node_type node)
2908 {
2909 install_element (node, &config_list_cmd);
2910 }
2911
2912 /* Making connection to protocol daemon. */
2913 static int
2914 vtysh_connect (struct vtysh_client *vclient)
2915 {
2916 int ret;
2917 int sock, len;
2918 struct sockaddr_un addr;
2919 struct stat s_stat;
2920 const char *path;
2921
2922 if (!vclient->path[0])
2923 snprintf(vclient->path, sizeof(vclient->path), "%s/%s.vty",
2924 vty_sock_path, vclient->name);
2925 path = vclient->path;
2926
2927 /* Stat socket to see if we have permission to access it. */
2928 ret = stat (path, &s_stat);
2929 if (ret < 0 && errno != ENOENT)
2930 {
2931 fprintf (stderr, "vtysh_connect(%s): stat = %s\n",
2932 path, safe_strerror(errno));
2933 exit(1);
2934 }
2935
2936 if (ret >= 0)
2937 {
2938 if (! S_ISSOCK(s_stat.st_mode))
2939 {
2940 fprintf (stderr, "vtysh_connect(%s): Not a socket\n",
2941 path);
2942 exit (1);
2943 }
2944
2945 }
2946
2947 sock = socket (AF_UNIX, SOCK_STREAM, 0);
2948 if (sock < 0)
2949 {
2950 #ifdef DEBUG
2951 fprintf(stderr, "vtysh_connect(%s): socket = %s\n", path,
2952 safe_strerror(errno));
2953 #endif /* DEBUG */
2954 return -1;
2955 }
2956
2957 memset (&addr, 0, sizeof (struct sockaddr_un));
2958 addr.sun_family = AF_UNIX;
2959 strlcpy (addr.sun_path, path, sizeof (addr.sun_path));
2960 #ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
2961 len = addr.sun_len = SUN_LEN(&addr);
2962 #else
2963 len = sizeof (addr.sun_family) + strlen (addr.sun_path);
2964 #endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
2965
2966 ret = connect (sock, (struct sockaddr *) &addr, len);
2967 if (ret < 0)
2968 {
2969 #ifdef DEBUG
2970 fprintf(stderr, "vtysh_connect(%s): connect = %s\n", path,
2971 safe_strerror(errno));
2972 #endif /* DEBUG */
2973 close (sock);
2974 return -1;
2975 }
2976 vclient->fd = sock;
2977
2978 return 0;
2979 }
2980
2981 /* Return true if str ends with suffix, else return false */
2982 static int
2983 ends_with(const char *str, const char *suffix)
2984 {
2985 if (!str || !suffix)
2986 return 0;
2987 size_t lenstr = strlen(str);
2988 size_t lensuffix = strlen(suffix);
2989 if (lensuffix > lenstr)
2990 return 0;
2991 return strncmp(str + lenstr - lensuffix, suffix, lensuffix) == 0;
2992 }
2993
2994 static void
2995 vtysh_client_sorted_insert (struct vtysh_client *head_client,
2996 struct vtysh_client *client)
2997 {
2998 struct vtysh_client *prev_node, *current_node;
2999
3000 prev_node = head_client;
3001 current_node = head_client->next;
3002 while (current_node)
3003 {
3004 if (strcmp(current_node->path, client->path) > 0)
3005 break;
3006
3007 prev_node = current_node;
3008 current_node = current_node->next;
3009 }
3010 client->next = current_node;
3011 prev_node->next = client;
3012 }
3013
3014 #define MAXIMUM_INSTANCES 10
3015
3016 static void
3017 vtysh_update_all_insances(struct vtysh_client * head_client)
3018 {
3019 struct vtysh_client *client;
3020 DIR *dir;
3021 struct dirent *file;
3022 int n = 0;
3023
3024 if (head_client->flag != VTYSH_OSPFD) return;
3025
3026 /* ls vty_sock_dir and look for all files ending in .vty */
3027 dir = opendir(vty_sock_path);
3028 if (dir)
3029 {
3030 while ((file = readdir(dir)) != NULL)
3031 {
3032 if (begins_with(file->d_name, "ospfd-") && ends_with(file->d_name, ".vty"))
3033 {
3034 if (n == MAXIMUM_INSTANCES)
3035 {
3036 fprintf(stderr,
3037 "Parsing %s, client limit(%d) reached!\n",
3038 vty_sock_path, n);
3039 break;
3040 }
3041 client = (struct vtysh_client *) malloc(sizeof(struct vtysh_client));
3042 client->fd = -1;
3043 client->name = "ospfd";
3044 client->flag = VTYSH_OSPFD;
3045 snprintf(client->path, sizeof(client->path), "%s/%s",
3046 vty_sock_path, file->d_name);
3047 client->next = NULL;
3048 vtysh_client_sorted_insert(head_client, client);
3049 n++;
3050 }
3051 }
3052 closedir(dir);
3053 }
3054 }
3055
3056 static int
3057 vtysh_connect_all_instances (struct vtysh_client *head_client)
3058 {
3059 struct vtysh_client *client;
3060 int rc = 0;
3061
3062 vtysh_update_all_insances(head_client);
3063
3064 client = head_client->next;
3065 while (client)
3066 {
3067 if (vtysh_connect(client) == 0)
3068 rc++;
3069 client = client->next;
3070 }
3071
3072 return rc;
3073 }
3074
3075 int
3076 vtysh_connect_all(const char *daemon_name)
3077 {
3078 u_int i;
3079 int rc = 0;
3080 int matches = 0;
3081
3082 for (i = 0; i < array_size(vtysh_client); i++)
3083 {
3084 if (!daemon_name || !strcmp(daemon_name, vtysh_client[i].name))
3085 {
3086 matches++;
3087 if (vtysh_connect(&vtysh_client[i]) == 0)
3088 rc++;
3089
3090 rc += vtysh_connect_all_instances(&vtysh_client[i]);
3091 }
3092 }
3093 if (!matches)
3094 fprintf(stderr, "Error: no daemons match name %s!\n", daemon_name);
3095 return rc;
3096 }
3097
3098 /* To disable readline's filename completion. */
3099 static char *
3100 vtysh_completion_entry_function (const char *ignore, int invoking_key)
3101 {
3102 return NULL;
3103 }
3104
3105 void
3106 vtysh_readline_init (void)
3107 {
3108 /* readline related settings. */
3109 rl_initialize ();
3110 rl_bind_key ('?', (rl_command_func_t *) vtysh_rl_describe);
3111 rl_completion_entry_function = vtysh_completion_entry_function;
3112 rl_attempted_completion_function = (rl_completion_func_t *)new_completion;
3113 }
3114
3115 char *
3116 vtysh_prompt (void)
3117 {
3118 static struct utsname names;
3119 static char buf[100];
3120 const char*hostname;
3121 extern struct host host;
3122
3123 hostname = host.name;
3124
3125 if (!hostname)
3126 {
3127 if (!names.nodename[0])
3128 uname (&names);
3129 hostname = names.nodename;
3130 }
3131
3132 snprintf (buf, sizeof buf, cmd_prompt (vty->node), hostname);
3133
3134 return buf;
3135 }
3136
3137 void
3138 vtysh_init_vty (void)
3139 {
3140 /* Make vty structure. */
3141 vty = vty_new ();
3142 vty->type = VTY_SHELL;
3143 vty->node = VIEW_NODE;
3144
3145 /* Initialize commands. */
3146 cmd_init (0);
3147
3148 /* Install nodes. */
3149 install_node (&bgp_node, NULL);
3150 install_node (&rip_node, NULL);
3151 install_node (&interface_node, NULL);
3152 install_node (&link_params_node, NULL);
3153 install_node (&ns_node, NULL);
3154 install_node (&vrf_node, NULL);
3155 install_node (&rmap_node, NULL);
3156 install_node (&zebra_node, NULL);
3157 install_node (&bgp_vpnv4_node, NULL);
3158 install_node (&bgp_vpnv6_node, NULL);
3159 install_node (&bgp_encap_node, NULL);
3160 install_node (&bgp_encapv6_node, NULL);
3161 install_node (&bgp_ipv4_node, NULL);
3162 install_node (&bgp_ipv4m_node, NULL);
3163 install_node (&bgp_ipv6_node, NULL);
3164 install_node (&bgp_ipv6m_node, NULL);
3165 install_node (&bgp_vrf_policy_node, NULL);
3166 install_node (&bgp_evpn_node, NULL);
3167 install_node (&bgp_vnc_defaults_node, NULL);
3168 install_node (&bgp_vnc_nve_group_node, NULL);
3169 install_node (&bgp_vnc_l2_group_node, NULL);
3170 install_node (&ospf_node, NULL);
3171 install_node (&eigrp_node, NULL);
3172 install_node (&ripng_node, NULL);
3173 install_node (&ospf6_node, NULL);
3174 install_node (&ldp_node, NULL);
3175 install_node (&ldp_ipv4_node, NULL);
3176 install_node (&ldp_ipv6_node, NULL);
3177 install_node (&ldp_ipv4_iface_node, NULL);
3178 install_node (&ldp_ipv6_iface_node, NULL);
3179 install_node (&ldp_l2vpn_node, NULL);
3180 install_node (&ldp_pseudowire_node, NULL);
3181 install_node (&keychain_node, NULL);
3182 install_node (&keychain_key_node, NULL);
3183 install_node (&isis_node, NULL);
3184 install_node (&vty_node, NULL);
3185
3186 vtysh_install_default (VIEW_NODE);
3187 vtysh_install_default (CONFIG_NODE);
3188 vtysh_install_default (BGP_NODE);
3189 vtysh_install_default (RIP_NODE);
3190 vtysh_install_default (INTERFACE_NODE);
3191 vtysh_install_default (LINK_PARAMS_NODE);
3192 vtysh_install_default (NS_NODE);
3193 vtysh_install_default (VRF_NODE);
3194 vtysh_install_default (RMAP_NODE);
3195 vtysh_install_default (ZEBRA_NODE);
3196 vtysh_install_default (BGP_VPNV4_NODE);
3197 vtysh_install_default (BGP_VPNV6_NODE);
3198 vtysh_install_default (BGP_ENCAP_NODE);
3199 vtysh_install_default (BGP_ENCAPV6_NODE);
3200 vtysh_install_default (BGP_IPV4_NODE);
3201 vtysh_install_default (BGP_IPV4M_NODE);
3202 vtysh_install_default (BGP_IPV6_NODE);
3203 vtysh_install_default (BGP_IPV6M_NODE);
3204 vtysh_install_default (BGP_EVPN_NODE);
3205 #if ENABLE_BGP_VNC
3206 vtysh_install_default (BGP_VRF_POLICY_NODE);
3207 vtysh_install_default (BGP_VNC_DEFAULTS_NODE);
3208 vtysh_install_default (BGP_VNC_NVE_GROUP_NODE);
3209 vtysh_install_default (BGP_VNC_L2_GROUP_NODE);
3210 #endif
3211 vtysh_install_default (OSPF_NODE);
3212 vtysh_install_default (EIGRP_NODE);
3213 vtysh_install_default (RIPNG_NODE);
3214 vtysh_install_default (OSPF6_NODE);
3215 vtysh_install_default (LDP_NODE);
3216 vtysh_install_default (LDP_IPV4_NODE);
3217 vtysh_install_default (LDP_IPV6_NODE);
3218 vtysh_install_default (LDP_IPV4_IFACE_NODE);
3219 vtysh_install_default (LDP_IPV6_IFACE_NODE);
3220 vtysh_install_default (LDP_L2VPN_NODE);
3221 vtysh_install_default (LDP_PSEUDOWIRE_NODE);
3222 vtysh_install_default (ISIS_NODE);
3223 vtysh_install_default (KEYCHAIN_NODE);
3224 vtysh_install_default (KEYCHAIN_KEY_NODE);
3225 vtysh_install_default (VTY_NODE);
3226
3227 install_element (VIEW_NODE, &vtysh_enable_cmd);
3228 install_element (ENABLE_NODE, &vtysh_config_terminal_cmd);
3229 install_element (ENABLE_NODE, &vtysh_disable_cmd);
3230
3231 /* "exit" command. */
3232 install_element (VIEW_NODE, &vtysh_exit_all_cmd);
3233 install_element (CONFIG_NODE, &vtysh_exit_all_cmd);
3234 install_element (VIEW_NODE, &vtysh_quit_all_cmd);
3235 install_element (CONFIG_NODE, &vtysh_quit_all_cmd);
3236 install_element (RIP_NODE, &vtysh_exit_ripd_cmd);
3237 install_element (RIP_NODE, &vtysh_quit_ripd_cmd);
3238 install_element (RIPNG_NODE, &vtysh_exit_ripngd_cmd);
3239 install_element (RIPNG_NODE, &vtysh_quit_ripngd_cmd);
3240 install_element (OSPF_NODE, &vtysh_exit_ospfd_cmd);
3241 install_element (OSPF_NODE, &vtysh_quit_ospfd_cmd);
3242 install_element (EIGRP_NODE, &vtysh_exit_eigrpd_cmd);
3243 install_element (EIGRP_NODE, &vtysh_quit_eigrpd_cmd);
3244 install_element (OSPF6_NODE, &vtysh_exit_ospf6d_cmd);
3245 install_element (OSPF6_NODE, &vtysh_quit_ospf6d_cmd);
3246 #if defined (HAVE_LDPD)
3247 install_element (LDP_NODE, &vtysh_exit_ldpd_cmd);
3248 install_element (LDP_NODE, &vtysh_quit_ldpd_cmd);
3249 install_element (LDP_IPV4_NODE, &vtysh_exit_ldpd_cmd);
3250 install_element (LDP_IPV4_NODE, &vtysh_quit_ldpd_cmd);
3251 install_element (LDP_IPV6_NODE, &vtysh_exit_ldpd_cmd);
3252 install_element (LDP_IPV6_NODE, &vtysh_quit_ldpd_cmd);
3253 install_element (LDP_IPV4_IFACE_NODE, &vtysh_exit_ldpd_cmd);
3254 install_element (LDP_IPV4_IFACE_NODE, &vtysh_quit_ldpd_cmd);
3255 install_element (LDP_IPV6_IFACE_NODE, &vtysh_exit_ldpd_cmd);
3256 install_element (LDP_IPV6_IFACE_NODE, &vtysh_quit_ldpd_cmd);
3257 install_element (LDP_L2VPN_NODE, &vtysh_exit_ldpd_cmd);
3258 install_element (LDP_L2VPN_NODE, &vtysh_quit_ldpd_cmd);
3259 install_element (LDP_PSEUDOWIRE_NODE, &vtysh_exit_ldpd_cmd);
3260 install_element (LDP_PSEUDOWIRE_NODE, &vtysh_quit_ldpd_cmd);
3261 #endif
3262 install_element (BGP_NODE, &vtysh_exit_bgpd_cmd);
3263 install_element (BGP_NODE, &vtysh_quit_bgpd_cmd);
3264 install_element (BGP_VPNV4_NODE, &vtysh_exit_bgpd_cmd);
3265 install_element (BGP_VPNV4_NODE, &vtysh_quit_bgpd_cmd);
3266 install_element (BGP_VPNV6_NODE, &vtysh_exit_bgpd_cmd);
3267 install_element (BGP_VPNV6_NODE, &vtysh_quit_bgpd_cmd);
3268 install_element (BGP_ENCAP_NODE, &vtysh_exit_bgpd_cmd);
3269 install_element (BGP_ENCAP_NODE, &vtysh_quit_bgpd_cmd);
3270 install_element (BGP_ENCAPV6_NODE, &vtysh_exit_bgpd_cmd);
3271 install_element (BGP_ENCAPV6_NODE, &vtysh_quit_bgpd_cmd);
3272 install_element (BGP_IPV4_NODE, &vtysh_exit_bgpd_cmd);
3273 install_element (BGP_IPV4_NODE, &vtysh_quit_bgpd_cmd);
3274 install_element (BGP_IPV4M_NODE, &vtysh_exit_bgpd_cmd);
3275 install_element (BGP_IPV4M_NODE, &vtysh_quit_bgpd_cmd);
3276 install_element (BGP_IPV6_NODE, &vtysh_exit_bgpd_cmd);
3277 install_element (BGP_IPV6_NODE, &vtysh_quit_bgpd_cmd);
3278 install_element (BGP_IPV6M_NODE, &vtysh_exit_bgpd_cmd);
3279 install_element (BGP_IPV6M_NODE, &vtysh_quit_bgpd_cmd);
3280 install_element (BGP_EVPN_NODE, &vtysh_quit_bgpd_cmd);
3281 #if defined (ENABLE_BGP_VNC)
3282 install_element (BGP_VRF_POLICY_NODE, &vtysh_exit_bgpd_cmd);
3283 install_element (BGP_VRF_POLICY_NODE, &vtysh_quit_bgpd_cmd);
3284 install_element (BGP_VNC_DEFAULTS_NODE, &vtysh_exit_bgpd_cmd);
3285 install_element (BGP_VNC_DEFAULTS_NODE, &vtysh_quit_bgpd_cmd);
3286 install_element (BGP_VNC_NVE_GROUP_NODE, &vtysh_exit_bgpd_cmd);
3287 install_element (BGP_VNC_NVE_GROUP_NODE, &vtysh_quit_bgpd_cmd);
3288 install_element (BGP_VNC_L2_GROUP_NODE, &vtysh_exit_bgpd_cmd);
3289 install_element (BGP_VNC_L2_GROUP_NODE, &vtysh_quit_bgpd_cmd);
3290 #endif
3291 install_element (ISIS_NODE, &vtysh_exit_isisd_cmd);
3292 install_element (ISIS_NODE, &vtysh_quit_isisd_cmd);
3293 install_element (KEYCHAIN_NODE, &vtysh_exit_ripd_cmd);
3294 install_element (KEYCHAIN_NODE, &vtysh_quit_ripd_cmd);
3295 install_element (KEYCHAIN_KEY_NODE, &vtysh_exit_ripd_cmd);
3296 install_element (KEYCHAIN_KEY_NODE, &vtysh_quit_ripd_cmd);
3297 install_element (RMAP_NODE, &vtysh_exit_rmap_cmd);
3298 install_element (RMAP_NODE, &vtysh_quit_rmap_cmd);
3299 install_element (VTY_NODE, &vtysh_exit_line_vty_cmd);
3300 install_element (VTY_NODE, &vtysh_quit_line_vty_cmd);
3301
3302 /* "end" command. */
3303 install_element (CONFIG_NODE, &vtysh_end_all_cmd);
3304 install_element (ENABLE_NODE, &vtysh_end_all_cmd);
3305 install_element (RIP_NODE, &vtysh_end_all_cmd);
3306 install_element (RIPNG_NODE, &vtysh_end_all_cmd);
3307 install_element (OSPF_NODE, &vtysh_end_all_cmd);
3308 install_element (EIGRP_NODE, &vtysh_end_all_cmd);
3309 install_element (OSPF6_NODE, &vtysh_end_all_cmd);
3310 install_element (LDP_NODE, &vtysh_end_all_cmd);
3311 install_element (LDP_IPV4_NODE, &vtysh_end_all_cmd);
3312 install_element (LDP_IPV6_NODE, &vtysh_end_all_cmd);
3313 install_element (LDP_IPV4_IFACE_NODE, &vtysh_end_all_cmd);
3314 install_element (LDP_IPV6_IFACE_NODE, &vtysh_end_all_cmd);
3315 install_element (LDP_L2VPN_NODE, &vtysh_end_all_cmd);
3316 install_element (LDP_PSEUDOWIRE_NODE, &vtysh_end_all_cmd);
3317 install_element (BGP_NODE, &vtysh_end_all_cmd);
3318 install_element (BGP_IPV4_NODE, &vtysh_end_all_cmd);
3319 install_element (BGP_IPV4M_NODE, &vtysh_end_all_cmd);
3320 install_element (BGP_VPNV4_NODE, &vtysh_end_all_cmd);
3321 install_element (BGP_VPNV6_NODE, &vtysh_end_all_cmd);
3322 install_element (BGP_ENCAP_NODE, &vtysh_end_all_cmd);
3323 install_element (BGP_ENCAPV6_NODE, &vtysh_end_all_cmd);
3324 install_element (BGP_IPV6_NODE, &vtysh_end_all_cmd);
3325 install_element (BGP_IPV6M_NODE, &vtysh_end_all_cmd);
3326 install_element (BGP_VRF_POLICY_NODE, &vtysh_end_all_cmd);
3327 install_element (BGP_EVPN_NODE, &vtysh_end_all_cmd);
3328 install_element (BGP_VNC_DEFAULTS_NODE, &vtysh_end_all_cmd);
3329 install_element (BGP_VNC_NVE_GROUP_NODE, &vtysh_end_all_cmd);
3330 install_element (BGP_VNC_L2_GROUP_NODE, &vtysh_end_all_cmd);
3331 install_element (ISIS_NODE, &vtysh_end_all_cmd);
3332 install_element (KEYCHAIN_NODE, &vtysh_end_all_cmd);
3333 install_element (KEYCHAIN_KEY_NODE, &vtysh_end_all_cmd);
3334 install_element (RMAP_NODE, &vtysh_end_all_cmd);
3335 install_element (VTY_NODE, &vtysh_end_all_cmd);
3336
3337 install_element (INTERFACE_NODE, &vtysh_interface_desc_cmd);
3338 install_element (INTERFACE_NODE, &vtysh_no_interface_desc_cmd);
3339 install_element (INTERFACE_NODE, &vtysh_end_all_cmd);
3340 install_element (INTERFACE_NODE, &vtysh_exit_interface_cmd);
3341 install_element (LINK_PARAMS_NODE, &exit_link_params_cmd);
3342 install_element (LINK_PARAMS_NODE, &vtysh_end_all_cmd);
3343 install_element (LINK_PARAMS_NODE, &vtysh_exit_interface_cmd);
3344 install_element (INTERFACE_NODE, &vtysh_quit_interface_cmd);
3345
3346 install_element (NS_NODE, &vtysh_end_all_cmd);
3347
3348 install_element (CONFIG_NODE, &vtysh_ns_cmd);
3349 install_element (NS_NODE, &vtysh_exit_ns_cmd);
3350 install_element (NS_NODE, &vtysh_quit_ns_cmd);
3351
3352 install_element (VRF_NODE, &vtysh_end_all_cmd);
3353 install_element (VRF_NODE, &vtysh_exit_vrf_cmd);
3354 install_element (VRF_NODE, &vtysh_quit_vrf_cmd);
3355
3356 install_element (CONFIG_NODE, &router_eigrp_cmd);
3357 install_element (CONFIG_NODE, &router_rip_cmd);
3358 install_element (CONFIG_NODE, &router_ripng_cmd);
3359 install_element (CONFIG_NODE, &router_ospf_cmd);
3360 install_element (CONFIG_NODE, &router_ospf6_cmd);
3361 #if defined (HAVE_LDPD)
3362 install_element (CONFIG_NODE, &ldp_mpls_ldp_cmd);
3363 install_element (LDP_NODE, &ldp_address_family_ipv4_cmd);
3364 install_element (LDP_NODE, &ldp_address_family_ipv6_cmd);
3365 install_element (LDP_IPV4_NODE, &ldp_interface_ifname_cmd);
3366 install_element (LDP_IPV6_NODE, &ldp_interface_ifname_cmd);
3367 install_element (CONFIG_NODE, &ldp_l2vpn_word_type_vpls_cmd);
3368 install_element (LDP_L2VPN_NODE, &ldp_member_pseudowire_ifname_cmd);
3369 #endif
3370 install_element (CONFIG_NODE, &router_isis_cmd);
3371 install_element (CONFIG_NODE, &router_bgp_cmd);
3372 install_element (BGP_NODE, &address_family_vpnv4_cmd);
3373 install_element (BGP_NODE, &address_family_vpnv6_cmd);
3374 install_element (BGP_NODE, &address_family_encapv4_cmd);
3375 install_element (BGP_NODE, &address_family_encapv6_cmd);
3376 #if defined(ENABLE_BGP_VNC)
3377 install_element (BGP_NODE, &vnc_vrf_policy_cmd);
3378 install_element (BGP_NODE, &vnc_defaults_cmd);
3379 install_element (BGP_NODE, &vnc_nve_group_cmd);
3380 install_element (BGP_NODE, &vnc_l2_group_cmd);
3381 #endif
3382 install_element (BGP_NODE, &address_family_ipv4_unicast_cmd);
3383 install_element (BGP_NODE, &address_family_ipv6_cmd);
3384 install_element (BGP_NODE, &address_family_evpn_cmd);
3385 install_element (BGP_VPNV4_NODE, &exit_address_family_cmd);
3386 install_element (BGP_VPNV6_NODE, &exit_address_family_cmd);
3387 install_element (BGP_ENCAP_NODE, &exit_address_family_cmd);
3388 install_element (BGP_ENCAPV6_NODE, &exit_address_family_cmd);
3389 install_element (BGP_IPV4_NODE, &exit_address_family_cmd);
3390 install_element (BGP_IPV4M_NODE, &exit_address_family_cmd);
3391 install_element (BGP_IPV6_NODE, &exit_address_family_cmd);
3392 install_element (BGP_IPV6M_NODE, &exit_address_family_cmd);
3393 install_element (BGP_EVPN_NODE, &exit_address_family_cmd);
3394
3395 install_element (BGP_VRF_POLICY_NODE, &exit_vrf_policy_cmd);
3396 install_element (BGP_VNC_DEFAULTS_NODE, &exit_vnc_config_cmd);
3397 install_element (BGP_VNC_NVE_GROUP_NODE, &exit_vnc_config_cmd);
3398 install_element (BGP_VNC_L2_GROUP_NODE, &exit_vnc_config_cmd);
3399
3400 install_element (CONFIG_NODE, &key_chain_cmd);
3401 install_element (CONFIG_NODE, &vtysh_route_map_cmd);
3402 install_element (CONFIG_NODE, &vtysh_line_vty_cmd);
3403 install_element (KEYCHAIN_NODE, &key_cmd);
3404 install_element (KEYCHAIN_NODE, &key_chain_cmd);
3405 install_element (KEYCHAIN_KEY_NODE, &key_chain_cmd);
3406 install_element (CONFIG_NODE, &vtysh_interface_cmd);
3407 install_element (CONFIG_NODE, &vtysh_no_interface_cmd);
3408 install_element (CONFIG_NODE, &vtysh_no_interface_vrf_cmd);
3409 install_element (INTERFACE_NODE, &vtysh_link_params_cmd);
3410 install_element (ENABLE_NODE, &vtysh_show_running_config_cmd);
3411 install_element (ENABLE_NODE, &vtysh_copy_running_config_cmd);
3412
3413 install_element (CONFIG_NODE, &vtysh_vrf_cmd);
3414 install_element (CONFIG_NODE, &vtysh_no_vrf_cmd);
3415
3416 /* "write terminal" command. */
3417 install_element (ENABLE_NODE, &vtysh_write_terminal_cmd);
3418
3419 install_element (CONFIG_NODE, &vtysh_integrated_config_cmd);
3420 install_element (CONFIG_NODE, &no_vtysh_integrated_config_cmd);
3421
3422 /* "write memory" command. */
3423 install_element (ENABLE_NODE, &vtysh_write_memory_cmd);
3424
3425 install_element (VIEW_NODE, &vtysh_terminal_length_cmd);
3426 install_element (VIEW_NODE, &vtysh_terminal_no_length_cmd);
3427 install_element (VIEW_NODE, &vtysh_show_daemons_cmd);
3428
3429 install_element (VIEW_NODE, &vtysh_ping_cmd);
3430 install_element (VIEW_NODE, &vtysh_ping_ip_cmd);
3431 install_element (VIEW_NODE, &vtysh_traceroute_cmd);
3432 install_element (VIEW_NODE, &vtysh_traceroute_ip_cmd);
3433 install_element (VIEW_NODE, &vtysh_ping6_cmd);
3434 install_element (VIEW_NODE, &vtysh_traceroute6_cmd);
3435 #if defined(HAVE_SHELL_ACCESS)
3436 install_element (VIEW_NODE, &vtysh_telnet_cmd);
3437 install_element (VIEW_NODE, &vtysh_telnet_port_cmd);
3438 install_element (VIEW_NODE, &vtysh_ssh_cmd);
3439 #endif
3440 #if defined(HAVE_SHELL_ACCESS)
3441 install_element (ENABLE_NODE, &vtysh_start_shell_cmd);
3442 install_element (ENABLE_NODE, &vtysh_start_bash_cmd);
3443 install_element (ENABLE_NODE, &vtysh_start_zsh_cmd);
3444 #endif
3445
3446 install_element (VIEW_NODE, &vtysh_show_memory_cmd);
3447 install_element (VIEW_NODE, &vtysh_show_modules_cmd);
3448
3449 install_element (VIEW_NODE, &vtysh_show_work_queues_cmd);
3450 install_element (VIEW_NODE, &vtysh_show_work_queues_daemon_cmd);
3451
3452 install_element (VIEW_NODE, &vtysh_show_thread_cmd);
3453
3454 /* Logging */
3455 install_element (VIEW_NODE, &vtysh_show_logging_cmd);
3456 install_element (CONFIG_NODE, &vtysh_log_stdout_cmd);
3457 install_element (CONFIG_NODE, &vtysh_log_stdout_level_cmd);
3458 install_element (CONFIG_NODE, &no_vtysh_log_stdout_cmd);
3459 install_element (CONFIG_NODE, &vtysh_log_file_cmd);
3460 install_element (CONFIG_NODE, &vtysh_log_file_level_cmd);
3461 install_element (CONFIG_NODE, &no_vtysh_log_file_cmd);
3462 install_element (CONFIG_NODE, &vtysh_log_monitor_cmd);
3463 install_element (CONFIG_NODE, &no_vtysh_log_monitor_cmd);
3464 install_element (CONFIG_NODE, &vtysh_log_syslog_cmd);
3465 install_element (CONFIG_NODE, &no_vtysh_log_syslog_cmd);
3466 install_element (CONFIG_NODE, &vtysh_log_trap_cmd);
3467 install_element (CONFIG_NODE, &no_vtysh_log_trap_cmd);
3468 install_element (CONFIG_NODE, &vtysh_log_facility_cmd);
3469 install_element (CONFIG_NODE, &no_vtysh_log_facility_cmd);
3470 install_element (CONFIG_NODE, &vtysh_log_record_priority_cmd);
3471 install_element (CONFIG_NODE, &no_vtysh_log_record_priority_cmd);
3472 install_element (CONFIG_NODE, &vtysh_log_timestamp_precision_cmd);
3473 install_element (CONFIG_NODE, &no_vtysh_log_timestamp_precision_cmd);
3474
3475 install_element (CONFIG_NODE, &vtysh_service_password_encrypt_cmd);
3476 install_element (CONFIG_NODE, &no_vtysh_service_password_encrypt_cmd);
3477
3478 install_element (CONFIG_NODE, &vtysh_password_cmd);
3479 install_element (CONFIG_NODE, &vtysh_password_text_cmd);
3480 install_element (CONFIG_NODE, &vtysh_enable_password_cmd);
3481 install_element (CONFIG_NODE, &vtysh_enable_password_text_cmd);
3482 install_element (CONFIG_NODE, &no_vtysh_enable_password_cmd);
3483 }