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