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