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