blob: 36b7c5858f64cdb0444a545975913060e4c4fbd5 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* 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 "command.h"
34#include "memory.h"
35#include "vtysh/vtysh.h"
36
37/* Struct VTY. */
38struct vty *vty;
39
40/* VTY shell pager name. */
41char *vtysh_pager_name = NULL;
42
43/* VTY shell client structure. */
44struct vtysh_client
45{
46 int fd;
47} vtysh_client[VTYSH_INDEX_MAX];
48
49/* When '^Z' is received from vty, move down to the enable mode. */
50int
51vtysh_end ()
52{
53 switch (vty->node)
54 {
55 case VIEW_NODE:
56 case ENABLE_NODE:
57 /* Nothing to do. */
58 break;
59 default:
60 vty->node = ENABLE_NODE;
61 break;
62 }
63 return CMD_SUCCESS;
64}
65
66DEFUNSH (VTYSH_ALL,
67 vtysh_end_all,
68 vtysh_end_all_cmd,
69 "end",
70 "End current mode and down to previous mode\n")
71{
72 return vtysh_end (vty);
73}
74
75DEFUNSH (VTYSH_ALL,
76 vtysh_log_stdout,
77 vtysh_log_stdout_cmd,
78 "log stdout",
79 "Logging control\n"
80 "Logging goes to stdout\n")
81{
82 return CMD_SUCCESS;
83}
84
85DEFUNSH (VTYSH_ALL,
86 no_vtysh_log_stdout,
87 no_vtysh_log_stdout_cmd,
88 "no log stdout",
89 NO_STR
90 "Logging control\n"
91 "Logging goes to stdout\n")
92{
93 return CMD_SUCCESS;
94}
95
96DEFUNSH (VTYSH_ALL,
97 vtysh_log_file,
98 vtysh_log_file_cmd,
99 "log file FILENAME",
100 "Logging control\n"
101 "Logging to file\n"
102 "Logging filename\n")
103{
104 return CMD_SUCCESS;
105}
106
107DEFUNSH (VTYSH_ALL,
108 no_vtysh_log_file,
109 no_vtysh_log_file_cmd,
110 "no log file [FILENAME]",
111 NO_STR
112 "Logging control\n"
113 "Cancel logging to file\n"
114 "Logging file name\n")
115{
116 return CMD_SUCCESS;
117}
118
119DEFUNSH (VTYSH_ALL,
120 vtysh_log_syslog,
121 vtysh_log_syslog_cmd,
122 "log syslog",
123 "Logging control\n"
124 "Logging goes to syslog\n")
125{
126 return CMD_SUCCESS;
127}
128
129DEFUNSH (VTYSH_ALL,
130 no_vtysh_log_syslog,
131 no_vtysh_log_syslog_cmd,
132 "no log syslog",
133 NO_STR
134 "Logging control\n"
135 "Cancel logging to syslog\n")
136{
137 return CMD_SUCCESS;
138}
139
140DEFUNSH (VTYSH_ALL,
141 vtysh_log_trap,
142 vtysh_log_trap_cmd,
143 "log trap (emergencies|alerts|critical|errors|warnings|notifications|informational|debugging)",
144 "Logging control\n"
145 "Limit logging to specifed level\n")
146{
147 return CMD_SUCCESS;
148}
149
150DEFUNSH (VTYSH_ALL,
151 no_vtysh_log_trap,
152 no_vtysh_log_trap_cmd,
153 "no log trap",
154 NO_STR
155 "Logging control\n"
156 "Permit all logging information\n")
157{
158 return CMD_SUCCESS;
159}
160
161DEFUNSH (VTYSH_ALL,
162 vtysh_log_record_priority,
163 vtysh_log_record_priority_cmd,
164 "log record-priority",
165 "Logging control\n"
166 "Log the priority of the message within the message\n")
167{
168 return CMD_SUCCESS;
169}
170
171DEFUNSH (VTYSH_ALL,
172 no_vtysh_log_record_priority,
173 no_vtysh_log_record_priority_cmd,
174 "no log record-priority",
175 NO_STR
176 "Logging control\n"
177 "Do not log the priority of the message within the message\n")
178{
179 return CMD_SUCCESS;
180}
181
182void
183vclient_close (struct vtysh_client *vclient)
184{
185 if (vclient->fd > 0)
186 close (vclient->fd);
187 vclient->fd = -1;
188}
189
190
191/* Following filled with debug code to trace a problematic condition
192 under load - it SHOULD handle it.
193*/
194#define ERR_WHERE_STRING "vtysh(): vtysh_client_config(): "
195int
196vtysh_client_config (struct vtysh_client *vclient, char *line)
197{
198 int ret;
199 char *buf;
200 size_t bufsz;
201 char *pbuf;
202 size_t left;
203 char *eoln;
204 int nbytes;
205 int i;
206 int readln;
207
208 if (vclient->fd < 0)
209 return CMD_SUCCESS;
210
211 ret = write (vclient->fd, line, strlen (line) + 1);
212 if (ret <= 0)
213 {
214 vclient_close (vclient);
215 return CMD_SUCCESS;
216 }
217
218 /* Allow enough room for buffer to read more than a few pages from socket
219 */
paule3d29b52003-01-23 18:05:42 +0000220 bufsz = 5 * getpagesize() + 1;
paul718e3742002-12-13 20:15:29 +0000221 buf = XMALLOC(MTYPE_TMP, bufsz);
222 memset(buf, 0, bufsz);
223 pbuf = buf;
224
225 while (1)
226 {
227 if (pbuf >= ((buf + bufsz) -1))
228 {
229 fprintf (stderr, ERR_WHERE_STRING \
230 "warning - pbuf beyond buffer end.\n");
231 return CMD_WARNING;
232 }
233
234 readln = (buf + bufsz) - pbuf - 1;
235 nbytes = read (vclient->fd, pbuf, readln);
236
237 if (nbytes <= 0)
238 {
239
240 if (errno == EINTR)
241 continue;
242
243 fprintf(stderr, ERR_WHERE_STRING "(%u)", errno);
244 perror("");
245
246 if (errno == EAGAIN || errno == EIO)
247 continue;
248
249 vclient_close (vclient);
250 XFREE(MTYPE_TMP, buf);
251 return CMD_SUCCESS;
252 }
253
254 pbuf[nbytes] = '\0';
255
256 if (nbytes >= 4)
257 {
258 i = nbytes - 4;
259 if (pbuf[i] == '\0' && pbuf[i + 1] == '\0' && pbuf[i + 2] == '\0')
260 {
261 ret = pbuf[i + 3];
262 break;
263 }
264 }
265 pbuf += nbytes;
266
267 /* See if a line exists in buffer, if so parse and consume it, and
268 reset read position */
269 if ((eoln = strrchr(buf, '\n')) == NULL)
270 continue;
271
272 if (eoln >= ((buf + bufsz) - 1))
273 {
274 fprintf (stderr, ERR_WHERE_STRING \
275 "warning - eoln beyond buffer end.\n");
276 }
277 vtysh_config_parse(buf);
278
279 eoln++;
280 left = (size_t)(buf + bufsz - eoln);
281 memmove(buf, eoln, left);
282 buf[bufsz-1] = '\0';
283 pbuf = buf + strlen(buf);
284 }
285
286 /* parse anything left in the buffer */
287 vtysh_config_parse (buf);
288
289 XFREE(MTYPE_TMP, buf);
290 return ret;
291}
292
293int
294vtysh_client_execute (struct vtysh_client *vclient, char *line, FILE *fp)
295{
296 int ret;
297 char buf[1001];
298 int nbytes;
299 int i;
300
301 if (vclient->fd < 0)
302 return CMD_SUCCESS;
303
304 ret = write (vclient->fd, line, strlen (line) + 1);
305 if (ret <= 0)
306 {
307 vclient_close (vclient);
308 return CMD_SUCCESS;
309 }
310
311 while (1)
312 {
313 nbytes = read (vclient->fd, buf, sizeof(buf)-1);
314
315 if (nbytes <= 0 && errno != EINTR)
316 {
317 vclient_close (vclient);
318 return CMD_SUCCESS;
319 }
320
321 if (nbytes > 0)
322 {
323 buf[nbytes] = '\0';
324 fprintf (fp, "%s", buf);
325 fflush (fp);
326
327 if (nbytes >= 4)
328 {
329 i = nbytes - 4;
330 if (buf[i] == '\0' && buf[i + 1] == '\0' && buf[i + 2] == '\0')
331 {
332 ret = buf[i + 3];
333 break;
334 }
335 }
336 }
337 }
338 return ret;
339}
340
341void
342vtysh_exit_ripd_only ()
343{
344 vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIP], "exit", stdout);
345}
346
347
348void
349vtysh_pager_init ()
350{
351 vtysh_pager_name = getenv ("VTYSH_PAGER");
352 if (! vtysh_pager_name)
paula805cc22003-05-01 14:29:48 +0000353 vtysh_pager_name = getenv ("PAGER");
354 if (! vtysh_pager_name)
paul718e3742002-12-13 20:15:29 +0000355 vtysh_pager_name = "more";
356}
357
358/* Command execution over the vty interface. */
359void
360vtysh_execute_func (char *line, int pager)
361{
362 int ret, cmd_stat;
363 vector vline;
364 struct cmd_element *cmd;
365 FILE *fp = NULL;
paula805cc22003-05-01 14:29:48 +0000366 int closepager=0;
paul718e3742002-12-13 20:15:29 +0000367
368 /* Split readline string up into the vector */
369 vline = cmd_make_strvec (line);
370
371 if (vline == NULL)
372 return;
373
374 ret = cmd_execute_command (vline, vty, &cmd);
375
376 cmd_free_strvec (vline);
377
378 switch (ret)
379 {
380 case CMD_WARNING:
381 if (vty->type == VTY_FILE)
paul4fc01e62002-12-13 20:49:00 +0000382 fprintf (stdout,"Warning...\n");
paul718e3742002-12-13 20:15:29 +0000383 break;
384 case CMD_ERR_AMBIGUOUS:
paul4fc01e62002-12-13 20:49:00 +0000385 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000386 break;
387 case CMD_ERR_NO_MATCH:
paul4fc01e62002-12-13 20:49:00 +0000388 fprintf (stdout,"%% Unknown command.\n");
paul718e3742002-12-13 20:15:29 +0000389 break;
390 case CMD_ERR_INCOMPLETE:
paul4fc01e62002-12-13 20:49:00 +0000391 fprintf (stdout,"%% Command incomplete.\n");
paul718e3742002-12-13 20:15:29 +0000392 break;
393 case CMD_SUCCESS_DAEMON:
394 {
395 if (pager && vtysh_pager_name)
396 {
paul4fc01e62002-12-13 20:49:00 +0000397 fp = popen (vtysh_pager_name, "w");
paul718e3742002-12-13 20:15:29 +0000398 if (fp == NULL)
399 {
paula805cc22003-05-01 14:29:48 +0000400 perror ("popen failed for pager");
401 fp = stdout;
paul718e3742002-12-13 20:15:29 +0000402 }
paula805cc22003-05-01 14:29:48 +0000403 else
404 closepager=1;
paul718e3742002-12-13 20:15:29 +0000405 }
406 else
407 fp = stdout;
408
409 if (! strcmp(cmd->string,"configure terminal"))
410 {
411 cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ZEBRA],
412 line, fp);
413 if (cmd_stat != CMD_WARNING)
414 cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIP],
415 line, fp);
416 if (cmd_stat != CMD_WARNING)
417 cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIPNG], line, fp);
418 if (cmd_stat != CMD_WARNING)
419 cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF],
420 line, fp);
421 if (cmd_stat != CMD_WARNING)
422 cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF6], line, fp);
423 if (cmd_stat != CMD_WARNING)
424 cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_BGP],
425 line, fp);
hassoc25e4582003-12-23 10:39:08 +0000426 if (cmd_stat != CMD_WARNING)
427 cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ISIS], line, fp);
paul718e3742002-12-13 20:15:29 +0000428 if (cmd_stat)
429 {
430 line = "end";
431 vline = cmd_make_strvec (line);
432
433 if (vline == NULL)
434 {
paula805cc22003-05-01 14:29:48 +0000435 if (pager && vtysh_pager_name && fp && closepager)
paul718e3742002-12-13 20:15:29 +0000436 {
437 if (pclose (fp) == -1)
438 {
paula805cc22003-05-01 14:29:48 +0000439 perror ("pclose failed for pager");
paul718e3742002-12-13 20:15:29 +0000440 }
441 fp = NULL;
442 }
443 return;
444 }
445
446 ret = cmd_execute_command (vline, vty, &cmd);
447 cmd_free_strvec (vline);
448 if (ret != CMD_SUCCESS_DAEMON)
449 break;
450 }
451 else
452 if (cmd->func)
453 {
454 (*cmd->func) (cmd, vty, 0, NULL);
455 break;
456 }
457 }
458
459 if (cmd->daemon & VTYSH_ZEBRA)
460 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ZEBRA], line, fp)
461 != CMD_SUCCESS)
462 break;
463 if (cmd->daemon & VTYSH_RIPD)
464 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIP], line, fp)
465 != CMD_SUCCESS)
466 break;
467 if (cmd->daemon & VTYSH_RIPNGD)
468 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIPNG], line, fp)
469 != CMD_SUCCESS)
470 break;
471 if (cmd->daemon & VTYSH_OSPFD)
472 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF], line, fp)
473 != CMD_SUCCESS)
474 break;
475 if (cmd->daemon & VTYSH_OSPF6D)
476 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF6], line, fp)
477 != CMD_SUCCESS)
478 break;
479 if (cmd->daemon & VTYSH_BGPD)
480 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_BGP], line, fp)
481 != CMD_SUCCESS)
482 break;
hassoc25e4582003-12-23 10:39:08 +0000483 if (cmd->daemon & VTYSH_ISISD)
484 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ISIS], line, fp)
485 != CMD_SUCCESS)
486 break;
paul718e3742002-12-13 20:15:29 +0000487 if (cmd->func)
488 (*cmd->func) (cmd, vty, 0, NULL);
489 }
490 }
paula805cc22003-05-01 14:29:48 +0000491 if (pager && vtysh_pager_name && fp && closepager)
paul718e3742002-12-13 20:15:29 +0000492 {
493 if (pclose (fp) == -1)
494 {
paula805cc22003-05-01 14:29:48 +0000495 perror ("pclose failed for pager");
paul718e3742002-12-13 20:15:29 +0000496 }
497 fp = NULL;
498 }
499}
500
501void
502vtysh_execute_no_pager (char *line)
503{
504 vtysh_execute_func (line, 0);
505}
506
507void
508vtysh_execute (char *line)
509{
510 vtysh_execute_func (line, 1);
511}
512
513/* Configration make from file. */
514int
515vtysh_config_from_file (struct vty *vty, FILE *fp)
516{
517 int ret;
518 vector vline;
519 struct cmd_element *cmd;
520
521 while (fgets (vty->buf, VTY_BUFSIZ, fp))
522 {
523 if (vty->buf[0] == '!' || vty->buf[1] == '#')
524 continue;
525
526 vline = cmd_make_strvec (vty->buf);
527
528 /* In case of comment line */
529 if (vline == NULL)
530 continue;
531
532 /* Execute configuration command : this is strict match */
533 ret = cmd_execute_command_strict (vline, vty, &cmd);
534
535 /* Try again with setting node to CONFIG_NODE */
536 if (ret != CMD_SUCCESS
537 && ret != CMD_SUCCESS_DAEMON
538 && ret != CMD_WARNING)
539 {
540 if (vty->node == KEYCHAIN_KEY_NODE)
541 {
542 vty->node = KEYCHAIN_NODE;
543 vtysh_exit_ripd_only ();
544 ret = cmd_execute_command_strict (vline, vty, &cmd);
545
546 if (ret != CMD_SUCCESS
547 && ret != CMD_SUCCESS_DAEMON
548 && ret != CMD_WARNING)
549 {
550 vtysh_exit_ripd_only ();
551 vty->node = CONFIG_NODE;
552 ret = cmd_execute_command_strict (vline, vty, &cmd);
553 }
554 }
555 else
556 {
557 vtysh_execute ("end");
558 vtysh_execute ("configure terminal");
559 vty->node = CONFIG_NODE;
560 ret = cmd_execute_command_strict (vline, vty, &cmd);
561 }
562 }
563
564 cmd_free_strvec (vline);
565
566 switch (ret)
567 {
568 case CMD_WARNING:
569 if (vty->type == VTY_FILE)
paul4fc01e62002-12-13 20:49:00 +0000570 fprintf (stdout,"Warning...\n");
paul718e3742002-12-13 20:15:29 +0000571 break;
572 case CMD_ERR_AMBIGUOUS:
paul4fc01e62002-12-13 20:49:00 +0000573 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000574 break;
575 case CMD_ERR_NO_MATCH:
paul4fc01e62002-12-13 20:49:00 +0000576 fprintf (stdout,"%% Unknown command: %s", vty->buf);
paul718e3742002-12-13 20:15:29 +0000577 break;
578 case CMD_ERR_INCOMPLETE:
paul4fc01e62002-12-13 20:49:00 +0000579 fprintf (stdout,"%% Command incomplete.\n");
paul718e3742002-12-13 20:15:29 +0000580 break;
581 case CMD_SUCCESS_DAEMON:
582 {
583 if (cmd->daemon & VTYSH_ZEBRA)
584 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ZEBRA],
585 vty->buf, stdout) != CMD_SUCCESS)
586 break;
587 if (cmd->daemon & VTYSH_RIPD)
588 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIP],
589 vty->buf, stdout) != CMD_SUCCESS)
590 break;
591 if (cmd->daemon & VTYSH_RIPNGD)
592 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIPNG],
593 vty->buf, stdout) != CMD_SUCCESS)
594 break;
595 if (cmd->daemon & VTYSH_OSPFD)
596 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF],
597 vty->buf, stdout) != CMD_SUCCESS)
598 break;
599 if (cmd->daemon & VTYSH_OSPF6D)
600 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF6],
601 vty->buf, stdout) != CMD_SUCCESS)
602 break;
603 if (cmd->daemon & VTYSH_BGPD)
604 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_BGP],
605 vty->buf, stdout) != CMD_SUCCESS)
606 break;
hassoc25e4582003-12-23 10:39:08 +0000607 if (cmd->daemon & VTYSH_ISISD)
608 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ISIS],
609 vty->buf, stdout) != CMD_SUCCESS)
610 break;
paul718e3742002-12-13 20:15:29 +0000611 if (cmd->func)
612 (*cmd->func) (cmd, vty, 0, NULL);
613 }
614 }
615 }
616 return CMD_SUCCESS;
617}
618
619/* We don't care about the point of the cursor when '?' is typed. */
620int
621vtysh_rl_describe ()
622{
623 int ret;
624 int i;
625 vector vline;
626 vector describe;
627 int width;
628 struct desc *desc;
629
630 vline = cmd_make_strvec (rl_line_buffer);
631
632 /* In case of '> ?'. */
633 if (vline == NULL)
634 {
635 vline = vector_init (1);
636 vector_set (vline, '\0');
637 }
638 else
639 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
640 vector_set (vline, '\0');
641
642 describe = cmd_describe_command (vline, vty, &ret);
643
paul4fc01e62002-12-13 20:49:00 +0000644 fprintf (stdout,"\n");
paul718e3742002-12-13 20:15:29 +0000645
646 /* Ambiguous and no match error. */
647 switch (ret)
648 {
649 case CMD_ERR_AMBIGUOUS:
650 cmd_free_strvec (vline);
paul4fc01e62002-12-13 20:49:00 +0000651 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000652 rl_on_new_line ();
653 return 0;
654 break;
655 case CMD_ERR_NO_MATCH:
656 cmd_free_strvec (vline);
paul4fc01e62002-12-13 20:49:00 +0000657 fprintf (stdout,"%% There is no matched command.\n");
paul718e3742002-12-13 20:15:29 +0000658 rl_on_new_line ();
659 return 0;
660 break;
661 }
662
663 /* Get width of command string. */
664 width = 0;
665 for (i = 0; i < vector_max (describe); i++)
666 if ((desc = vector_slot (describe, i)) != NULL)
667 {
668 int len;
669
670 if (desc->cmd[0] == '\0')
671 continue;
672
673 len = strlen (desc->cmd);
674 if (desc->cmd[0] == '.')
675 len--;
676
677 if (width < len)
678 width = len;
679 }
680
681 for (i = 0; i < vector_max (describe); i++)
682 if ((desc = vector_slot (describe, i)) != NULL)
683 {
684 if (desc->cmd[0] == '\0')
685 continue;
686
687 if (! desc->str)
paul4fc01e62002-12-13 20:49:00 +0000688 fprintf (stdout," %-s\n",
paul718e3742002-12-13 20:15:29 +0000689 desc->cmd[0] == '.' ? desc->cmd + 1 : desc->cmd);
690 else
paul4fc01e62002-12-13 20:49:00 +0000691 fprintf (stdout," %-*s %s\n",
paul718e3742002-12-13 20:15:29 +0000692 width,
693 desc->cmd[0] == '.' ? desc->cmd + 1 : desc->cmd,
694 desc->str);
695 }
696
697 cmd_free_strvec (vline);
698 vector_free (describe);
699
700 rl_on_new_line();
701
702 return 0;
703}
704
705/* result of cmd_complete_command() call will be stored here
706 and used in new_completion() in order to put the space in
707 correct places only */
708int complete_status;
709
710char *
pauldfc0d9b2003-04-18 23:55:29 +0000711command_generator (const char *text, int state)
paul718e3742002-12-13 20:15:29 +0000712{
713 vector vline;
714 static char **matched = NULL;
715 static int index = 0;
716
717 /* First call. */
718 if (! state)
719 {
720 index = 0;
721
722 if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
723 return NULL;
724
725 vline = cmd_make_strvec (rl_line_buffer);
726 if (vline == NULL)
727 return NULL;
728
729 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
730 vector_set (vline, '\0');
731
732 matched = cmd_complete_command (vline, vty, &complete_status);
733 }
734
735 if (matched && matched[index])
736 return matched[index++];
737
738 return NULL;
739}
740
741char **
742new_completion (char *text, int start, int end)
743{
744 char **matches;
745
pauldfc0d9b2003-04-18 23:55:29 +0000746 matches = rl_completion_matches (text, command_generator);
paul718e3742002-12-13 20:15:29 +0000747
748 if (matches)
749 {
750 rl_point = rl_end;
751 if (complete_status == CMD_COMPLETE_FULL_MATCH)
752 rl_pending_input = ' ';
753 }
754
755 return matches;
756}
757
758char **
759vtysh_completion (char *text, int start, int end)
760{
761 int ret;
762 vector vline;
763 char **matched = NULL;
764
765 if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
766 return NULL;
767
768 vline = cmd_make_strvec (rl_line_buffer);
769 if (vline == NULL)
770 return NULL;
771
772 /* In case of 'help \t'. */
773 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
774 vector_set (vline, '\0');
775
776 matched = cmd_complete_command (vline, vty, &ret);
777
778 cmd_free_strvec (vline);
779
780 return (char **) matched;
781}
782
783/* BGP node structure. */
784struct cmd_node bgp_node =
785{
786 BGP_NODE,
787 "%s(config-router)# ",
788};
789
790/* BGP node structure. */
791struct cmd_node rip_node =
792{
793 RIP_NODE,
794 "%s(config-router)# ",
795};
796
hassoc25e4582003-12-23 10:39:08 +0000797/* ISIS node structure. */
798struct cmd_node isis_node =
799{
800 ISIS_NODE,
801 "%s(config-router)# ",
802 1
803};
804
paul718e3742002-12-13 20:15:29 +0000805struct cmd_node interface_node =
806{
807 INTERFACE_NODE,
808 "%s(config-if)# ",
809};
810
811DEFUNSH (VTYSH_BGPD,
812 router_bgp,
813 router_bgp_cmd,
814 "router bgp <1-65535>",
815 ROUTER_STR
816 BGP_STR
817 AS_STR)
818{
819 vty->node = BGP_NODE;
820 return CMD_SUCCESS;
821}
822
823DEFUNSH (VTYSH_BGPD,
824 address_family_vpnv4,
825 address_family_vpnv4_cmd,
826 "address-family vpnv4",
827 "Enter Address Family command mode\n"
828 "Address family\n")
829{
830 vty->node = BGP_VPNV4_NODE;
831 return CMD_SUCCESS;
832}
833
834DEFUNSH (VTYSH_BGPD,
835 address_family_vpnv4_unicast,
836 address_family_vpnv4_unicast_cmd,
837 "address-family vpnv4 unicast",
838 "Enter Address Family command mode\n"
839 "Address family\n"
840 "Address Family Modifier\n")
841{
842 vty->node = BGP_VPNV4_NODE;
843 return CMD_SUCCESS;
844}
845
846DEFUNSH (VTYSH_BGPD,
847 address_family_ipv4_unicast,
848 address_family_ipv4_unicast_cmd,
849 "address-family ipv4 unicast",
850 "Enter Address Family command mode\n"
851 "Address family\n"
852 "Address Family Modifier\n")
853{
854 vty->node = BGP_IPV4_NODE;
855 return CMD_SUCCESS;
856}
857
858DEFUNSH (VTYSH_BGPD,
859 address_family_ipv4_multicast,
860 address_family_ipv4_multicast_cmd,
861 "address-family ipv4 multicast",
862 "Enter Address Family command mode\n"
863 "Address family\n"
864 "Address Family Modifier\n")
865{
866 vty->node = BGP_IPV4M_NODE;
867 return CMD_SUCCESS;
868}
869
870DEFUNSH (VTYSH_BGPD,
871 address_family_ipv6,
872 address_family_ipv6_cmd,
873 "address-family ipv6",
874 "Enter Address Family command mode\n"
875 "Address family\n")
876{
877 vty->node = BGP_IPV6_NODE;
878 return CMD_SUCCESS;
879}
880
881DEFUNSH (VTYSH_BGPD,
882 address_family_ipv6_unicast,
883 address_family_ipv6_unicast_cmd,
884 "address-family ipv6 unicast",
885 "Enter Address Family command mode\n"
886 "Address family\n"
887 "Address Family Modifier\n")
888{
889 vty->node = BGP_IPV6_NODE;
890 return CMD_SUCCESS;
891}
892
893DEFUNSH (VTYSH_RIPD,
894 key_chain,
895 key_chain_cmd,
896 "key chain WORD",
897 "Authentication key management\n"
898 "Key-chain management\n"
899 "Key-chain name\n")
900{
901 vty->node = KEYCHAIN_NODE;
902 return CMD_SUCCESS;
903}
904
905DEFUNSH (VTYSH_RIPD,
906 key,
907 key_cmd,
908 "key <0-2147483647>",
909 "Configure a key\n"
910 "Key identifier number\n")
911{
912 vty->node = KEYCHAIN_KEY_NODE;
913 return CMD_SUCCESS;
914}
915
916DEFUNSH (VTYSH_RIPD,
917 router_rip,
918 router_rip_cmd,
919 "router rip",
920 ROUTER_STR
921 "RIP")
922{
923 vty->node = RIP_NODE;
924 return CMD_SUCCESS;
925}
926
927DEFUNSH (VTYSH_RIPNGD,
928 router_ripng,
929 router_ripng_cmd,
930 "router ripng",
931 ROUTER_STR
932 "RIPng")
933{
934 vty->node = RIPNG_NODE;
935 return CMD_SUCCESS;
936}
937
938DEFUNSH (VTYSH_OSPFD,
939 router_ospf,
940 router_ospf_cmd,
941 "router ospf",
942 "Enable a routing process\n"
943 "Start OSPF configuration\n")
944{
945 vty->node = OSPF_NODE;
946 return CMD_SUCCESS;
947}
948
949DEFUNSH (VTYSH_OSPF6D,
950 router_ospf6,
951 router_ospf6_cmd,
952 "router ospf6",
953 OSPF6_ROUTER_STR
954 OSPF6_STR)
955{
956 vty->node = OSPF6_NODE;
957 return CMD_SUCCESS;
958}
959
hassoc25e4582003-12-23 10:39:08 +0000960DEFUNSH (VTYSH_ISISD,
961 router_isis,
962 router_isis_cmd,
963 "router isis WORD",
964 ROUTER_STR
965 "ISO IS-IS\n"
966 "ISO Routing area tag")
967{
968 vty->node = ISIS_NODE;
969 return CMD_SUCCESS;
970}
971
paul718e3742002-12-13 20:15:29 +0000972DEFUNSH (VTYSH_RMAP,
973 route_map,
974 route_map_cmd,
975 "route-map WORD (deny|permit) <1-65535>",
976 "Create route-map or enter route-map command mode\n"
977 "Route map tag\n"
978 "Route map denies set operations\n"
979 "Route map permits set operations\n"
980 "Sequence to insert to/delete from existing route-map entry\n")
981{
982 vty->node = RMAP_NODE;
983 return CMD_SUCCESS;
984}
985
986/* Enable command */
987DEFUNSH (VTYSH_ALL,
988 vtysh_enable,
989 vtysh_enable_cmd,
990 "enable",
991 "Turn on privileged mode command\n")
992{
993 vty->node = ENABLE_NODE;
994 return CMD_SUCCESS;
995}
996
997/* Disable command */
998DEFUNSH (VTYSH_ALL,
999 vtysh_disable,
1000 vtysh_disable_cmd,
1001 "disable",
1002 "Turn off privileged mode command\n")
1003{
1004 if (vty->node == ENABLE_NODE)
1005 vty->node = VIEW_NODE;
1006 return CMD_SUCCESS;
1007}
1008
1009/* Configration from terminal */
1010DEFUNSH (VTYSH_ALL,
1011 vtysh_config_terminal,
1012 vtysh_config_terminal_cmd,
1013 "configure terminal",
1014 "Configuration from vty interface\n"
1015 "Configuration terminal\n")
1016{
1017 vty->node = CONFIG_NODE;
1018 return CMD_SUCCESS;
1019}
1020
1021int
1022vtysh_exit (struct vty *vty)
1023{
1024 switch (vty->node)
1025 {
1026 case VIEW_NODE:
1027 case ENABLE_NODE:
1028 exit (0);
1029 break;
1030 case CONFIG_NODE:
1031 vty->node = ENABLE_NODE;
1032 break;
1033 case INTERFACE_NODE:
1034 case ZEBRA_NODE:
1035 case BGP_NODE:
1036 case RIP_NODE:
1037 case RIPNG_NODE:
1038 case OSPF_NODE:
1039 case OSPF6_NODE:
hassoc25e4582003-12-23 10:39:08 +00001040 case ISIS_NODE:
paul718e3742002-12-13 20:15:29 +00001041 case MASC_NODE:
1042 case RMAP_NODE:
1043 case VTY_NODE:
1044 case KEYCHAIN_NODE:
1045 vty->node = CONFIG_NODE;
1046 break;
1047 case BGP_VPNV4_NODE:
1048 case BGP_IPV4_NODE:
1049 case BGP_IPV4M_NODE:
1050 case BGP_IPV6_NODE:
1051 vty->node = BGP_NODE;
1052 break;
1053 case KEYCHAIN_KEY_NODE:
1054 vty->node = KEYCHAIN_NODE;
1055 break;
1056 default:
1057 break;
1058 }
1059 return CMD_SUCCESS;
1060}
1061
1062DEFUNSH (VTYSH_ALL,
1063 vtysh_exit_all,
1064 vtysh_exit_all_cmd,
1065 "exit",
1066 "Exit current mode and down to previous mode\n")
1067{
1068 return vtysh_exit (vty);
1069}
1070
1071ALIAS (vtysh_exit_all,
1072 vtysh_quit_all_cmd,
1073 "quit",
1074 "Exit current mode and down to previous mode\n")
1075
1076DEFUNSH (VTYSH_BGPD,
1077 exit_address_family,
1078 exit_address_family_cmd,
1079 "exit-address-family",
1080 "Exit from Address Family configuration mode\n")
1081{
1082 if (vty->node == BGP_IPV4_NODE
1083 || vty->node == BGP_IPV4M_NODE
1084 || vty->node == BGP_VPNV4_NODE
1085 || vty->node == BGP_IPV6_NODE)
1086 vty->node = BGP_NODE;
1087 return CMD_SUCCESS;
1088}
1089
1090DEFUNSH (VTYSH_ZEBRA,
1091 vtysh_exit_zebra,
1092 vtysh_exit_zebra_cmd,
1093 "exit",
1094 "Exit current mode and down to previous mode\n")
1095{
1096 return vtysh_exit (vty);
1097}
1098
1099ALIAS (vtysh_exit_zebra,
1100 vtysh_quit_zebra_cmd,
1101 "quit",
1102 "Exit current mode and down to previous mode\n")
1103
1104DEFUNSH (VTYSH_RIPD,
1105 vtysh_exit_ripd,
1106 vtysh_exit_ripd_cmd,
1107 "exit",
1108 "Exit current mode and down to previous mode\n")
1109{
1110 return vtysh_exit (vty);
1111}
1112
1113ALIAS (vtysh_exit_ripd,
1114 vtysh_quit_ripd_cmd,
1115 "quit",
1116 "Exit current mode and down to previous mode\n")
1117
paul68980082003-03-25 05:07:42 +00001118DEFUNSH (VTYSH_RIPNGD,
1119 vtysh_exit_ripngd,
1120 vtysh_exit_ripngd_cmd,
1121 "exit",
1122 "Exit current mode and down to previous mode\n")
1123{
1124 return vtysh_exit (vty);
1125}
1126
1127ALIAS (vtysh_exit_ripngd,
1128 vtysh_quit_ripngd_cmd,
1129 "quit",
1130 "Exit current mode and down to previous mode\n")
1131
paul718e3742002-12-13 20:15:29 +00001132DEFUNSH (VTYSH_RMAP,
1133 vtysh_exit_rmap,
1134 vtysh_exit_rmap_cmd,
1135 "exit",
1136 "Exit current mode and down to previous mode\n")
1137{
1138 return vtysh_exit (vty);
1139}
1140
1141ALIAS (vtysh_exit_rmap,
1142 vtysh_quit_rmap_cmd,
1143 "quit",
1144 "Exit current mode and down to previous mode\n")
1145
1146DEFUNSH (VTYSH_BGPD,
1147 vtysh_exit_bgpd,
1148 vtysh_exit_bgpd_cmd,
1149 "exit",
1150 "Exit current mode and down to previous mode\n")
1151{
1152 return vtysh_exit (vty);
1153}
1154
1155ALIAS (vtysh_exit_bgpd,
1156 vtysh_quit_bgpd_cmd,
1157 "quit",
1158 "Exit current mode and down to previous mode\n")
1159
1160DEFUNSH (VTYSH_OSPFD,
1161 vtysh_exit_ospfd,
1162 vtysh_exit_ospfd_cmd,
1163 "exit",
1164 "Exit current mode and down to previous mode\n")
1165{
1166 return vtysh_exit (vty);
1167}
1168
1169ALIAS (vtysh_exit_ospfd,
1170 vtysh_quit_ospfd_cmd,
1171 "quit",
1172 "Exit current mode and down to previous mode\n")
1173
paul68980082003-03-25 05:07:42 +00001174DEFUNSH (VTYSH_OSPF6D,
1175 vtysh_exit_ospf6d,
1176 vtysh_exit_ospf6d_cmd,
1177 "exit",
1178 "Exit current mode and down to previous mode\n")
1179{
1180 return vtysh_exit (vty);
1181}
1182
1183ALIAS (vtysh_exit_ospf6d,
1184 vtysh_quit_ospf6d_cmd,
1185 "quit",
1186 "Exit current mode and down to previous mode\n")
1187
hassoc25e4582003-12-23 10:39:08 +00001188DEFUNSH (VTYSH_ISISD,
1189 vtysh_exit_isisd,
1190 vtysh_exit_isisd_cmd,
1191 "exit",
1192 "Exit current mode and down to previous mode\n")
1193{
1194 return vtysh_exit (vty);
1195}
1196
1197ALIAS (vtysh_exit_isisd,
1198 vtysh_quit_isisd_cmd,
1199 "quit",
1200 "Exit current mode and down to previous mode\n")
1201
1202DEFUNSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_ISISD,
paul718e3742002-12-13 20:15:29 +00001203 vtysh_interface,
1204 vtysh_interface_cmd,
1205 "interface IFNAME",
1206 "Select an interface to configure\n"
1207 "Interface's name\n")
1208{
1209 vty->node = INTERFACE_NODE;
1210 return CMD_SUCCESS;
1211}
1212
paul32d24632003-05-23 09:25:20 +00001213DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D,
1214 vtysh_no_interface_cmd,
1215 "no interface IFNAME",
1216 NO_STR
1217 "Delete a pseudo interface's configuration\n"
1218 "Interface's name\n")
1219
paul338a9912003-03-01 15:44:10 +00001220DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1221 interface_desc_cmd,
1222 "description .LINE",
1223 "Interface specific description\n"
1224 "Characters describing this interface\n")
paul464dc8d2003-03-28 02:25:45 +00001225
1226DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1227 no_interface_desc_cmd,
1228 "no description",
1229 NO_STR
1230 "Interface specific description\n")
paul338a9912003-03-01 15:44:10 +00001231
hassoc25e4582003-12-23 10:39:08 +00001232DEFUNSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_ISISD,
paul718e3742002-12-13 20:15:29 +00001233 vtysh_exit_interface,
1234 vtysh_exit_interface_cmd,
1235 "exit",
1236 "Exit current mode and down to previous mode\n")
1237{
1238 return vtysh_exit (vty);
1239}
1240
1241ALIAS (vtysh_exit_interface,
1242 vtysh_quit_interface_cmd,
1243 "quit",
1244 "Exit current mode and down to previous mode\n")
1245
1246DEFUN (vtysh_write_terminal,
1247 vtysh_write_terminal_cmd,
1248 "write terminal",
1249 "Write running configuration to memory, network, or terminal\n"
1250 "Write to terminal\n")
1251{
1252 int ret;
1253 char line[] = "write terminal\n";
1254 FILE *fp = NULL;
1255
1256 if (vtysh_pager_name)
1257 {
paul4fc01e62002-12-13 20:49:00 +00001258 fp = popen (vtysh_pager_name, "w");
paul718e3742002-12-13 20:15:29 +00001259 if (fp == NULL)
1260 {
1261 perror ("popen");
1262 exit (1);
1263 }
1264 }
1265 else
1266 fp = stdout;
1267
1268 vty_out (vty, "Building configuration...%s", VTY_NEWLINE);
1269 vty_out (vty, "%sCurrent configuration:%s", VTY_NEWLINE,
1270 VTY_NEWLINE);
1271
1272 vtysh_config_write (fp);
1273
1274 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_ZEBRA], line);
1275 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_RIP], line);
1276 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_RIPNG], line);
1277 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_OSPF], line);
1278 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_OSPF6], line);
1279 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_BGP], line);
hassoc25e4582003-12-23 10:39:08 +00001280 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_ISIS], line);
paul718e3742002-12-13 20:15:29 +00001281
1282 vtysh_config_dump (fp);
1283
1284 if (vtysh_pager_name && fp)
1285 {
1286 fflush (fp);
1287 if (pclose (fp) == -1)
1288 {
1289 perror ("pclose");
1290 exit (1);
1291 }
1292 fp = NULL;
1293 }
1294
1295 return CMD_SUCCESS;
1296}
1297
paul4fc01e62002-12-13 20:49:00 +00001298struct vtysh_writeconfig_t {
1299 int daemon;
1300 int integrated;
1301} vtysh_wc = {-1,0};
1302
1303DEFUN (vtysh_write_config,
1304 vtysh_write_config_cmd,
1305 "write-config (daemon|integrated)",
1306 "Specify config files to write to\n"
1307 "Write per daemon file\n"
1308 "Write integrated file\n"
1309)
1310{
1311 if (!strncmp(argv[0],"d",1)) {
1312 vtysh_wc.daemon = 1;
1313 } else if (!strncmp(argv[0],"i",1)) {
1314 vtysh_wc.integrated = 1;
1315 }
1316 return CMD_SUCCESS;
1317}
1318
1319DEFUN (no_vtysh_write_config,
1320 no_vtysh_write_config_cmd,
1321 "no write-config (daemon|integrated)",
1322 "Negate per daemon and/or integrated config files\n"
1323)
1324{
1325 if (!strncmp(argv[0],"d",1)) {
1326 vtysh_wc.daemon = 0;
1327 } else if (!strncmp(argv[0],"i",1)) {
1328 vtysh_wc.integrated = 0;
1329 }
1330 return CMD_SUCCESS;
1331}
1332
1333int write_config_integrated(void)
paul718e3742002-12-13 20:15:29 +00001334{
1335 int ret;
paul718e3742002-12-13 20:15:29 +00001336 char line[] = "write terminal\n";
1337 FILE *fp;
1338 char *integrate_sav = NULL;
1339
paul718e3742002-12-13 20:15:29 +00001340 integrate_sav = malloc (strlen (integrate_default)
1341 + strlen (CONF_BACKUP_EXT) + 1);
1342 strcpy (integrate_sav, integrate_default);
1343 strcat (integrate_sav, CONF_BACKUP_EXT);
1344
1345
paul4fc01e62002-12-13 20:49:00 +00001346 fprintf (stdout,"Building Configuration...\n");
paul718e3742002-12-13 20:15:29 +00001347
1348 /* Move current configuration file to backup config file */
1349 unlink (integrate_sav);
1350 rename (integrate_default, integrate_sav);
paul5087df52003-01-25 06:56:09 +00001351 free (integrate_sav);
paul4fc01e62002-12-13 20:49:00 +00001352
paul718e3742002-12-13 20:15:29 +00001353 fp = fopen (integrate_default, "w");
1354 if (fp == NULL)
1355 {
paul4fc01e62002-12-13 20:49:00 +00001356 fprintf (stdout,"%% Can't open configuration file %s.\n", integrate_default);
paul718e3742002-12-13 20:15:29 +00001357 return CMD_SUCCESS;
1358 }
paul718e3742002-12-13 20:15:29 +00001359
1360 vtysh_config_write (fp);
1361
1362 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_ZEBRA], line);
1363 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_RIP], line);
1364 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_RIPNG], line);
1365 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_OSPF], line);
1366 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_OSPF6], line);
1367 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_BGP], line);
hassoc25e4582003-12-23 10:39:08 +00001368 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_ISIS], line);
paul718e3742002-12-13 20:15:29 +00001369
1370 vtysh_config_dump (fp);
1371
1372 fclose (fp);
1373
gdtaa593d52003-12-22 20:15:53 +00001374 if (chmod (integrate_default, CONFIGFILE_MASK) != 0)
1375 {
1376 fprintf (stdout,"%% Can't chmod configuration file %s: %s (%d)\n",
1377 integrate_default, strerror(errno), errno);
1378 return CMD_WARNING;
1379 }
1380
paul4fc01e62002-12-13 20:49:00 +00001381 fprintf(stdout,"Integrated configuration saved to %s\n",integrate_default);
1382
1383 fprintf (stdout,"[OK]\n");
1384
paul718e3742002-12-13 20:15:29 +00001385 return CMD_SUCCESS;
1386}
1387
paul4fc01e62002-12-13 20:49:00 +00001388DEFUN (vtysh_write_memory,
1389 vtysh_write_memory_cmd,
1390 "write memory",
1391 "Write running configuration to memory, network, or terminal\n"
1392 "Write configuration to the file (same as write file)\n")
1393{
pauldfc0d9b2003-04-18 23:55:29 +00001394 int ret = CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001395 char line[] = "write memory\n";
1396
1397 /* if integrated Zebra.conf explicitely set */
1398 if (vtysh_wc.integrated == 1) {
1399 ret = write_config_integrated();
1400 }
1401
1402 if (!vtysh_wc.daemon) {
1403 return ret;
1404 }
1405
1406 fprintf (stdout,"Building Configuration...\n");
1407
1408 ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ZEBRA], line, stdout);
1409 ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIP], line, stdout);
1410 ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIPNG], line, stdout);
1411 ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF], line, stdout);
1412 ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF6], line, stdout);
1413 ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_BGP], line, stdout);
hassoc25e4582003-12-23 10:39:08 +00001414 ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ISIS], line, stdout);
paul4fc01e62002-12-13 20:49:00 +00001415
1416 fprintf (stdout,"[OK]\n");
1417
pauldfc0d9b2003-04-18 23:55:29 +00001418 return ret;
paul4fc01e62002-12-13 20:49:00 +00001419}
1420
paul718e3742002-12-13 20:15:29 +00001421ALIAS (vtysh_write_memory,
1422 vtysh_copy_runningconfig_startupconfig_cmd,
1423 "copy running-config startup-config",
1424 "Copy from one file to another\n"
1425 "Copy from current system configuration\n"
1426 "Copy to startup configuration\n")
1427
1428ALIAS (vtysh_write_memory,
1429 vtysh_write_file_cmd,
1430 "write file",
1431 "Write running configuration to memory, network, or terminal\n"
1432 "Write configuration to the file (same as write memory)\n")
1433
hasso4a6e2252003-05-25 11:51:29 +00001434ALIAS (vtysh_write_memory,
1435 vtysh_write_cmd,
1436 "write",
1437 "Write running configuration to memory, network, or terminal\n")
1438
paul718e3742002-12-13 20:15:29 +00001439ALIAS (vtysh_write_terminal,
1440 vtysh_show_running_config_cmd,
1441 "show running-config",
1442 SHOW_STR
1443 "Current operating configuration\n")
1444
1445/* Execute command in child process. */
1446int
1447execute_command (char *command, int argc, char *arg1, char *arg2)
1448{
1449 int ret;
1450 pid_t pid;
1451 int status;
1452
1453 /* Call fork(). */
1454 pid = fork ();
1455
1456 if (pid < 0)
1457 {
1458 /* Failure of fork(). */
1459 fprintf (stderr, "Can't fork: %s\n", strerror (errno));
1460 exit (1);
1461 }
1462 else if (pid == 0)
1463 {
1464 /* This is child process. */
1465 switch (argc)
1466 {
1467 case 0:
1468 ret = execlp (command, command, NULL);
1469 break;
1470 case 1:
1471 ret = execlp (command, command, arg1, NULL);
1472 break;
1473 case 2:
1474 ret = execlp (command, command, arg1, arg2, NULL);
1475 break;
1476 }
1477
1478 /* When execlp suceed, this part is not executed. */
1479 fprintf (stderr, "Can't execute %s: %s\n", command, strerror (errno));
1480 exit (1);
1481 }
1482 else
1483 {
1484 /* This is parent. */
1485 execute_flag = 1;
1486 ret = wait4 (pid, &status, 0, NULL);
1487 execute_flag = 0;
1488 }
1489 return 0;
1490}
1491
1492DEFUN (vtysh_ping,
1493 vtysh_ping_cmd,
1494 "ping WORD",
hasso4eeccf12003-06-25 10:49:55 +00001495 "Send echo messages\n"
paul718e3742002-12-13 20:15:29 +00001496 "Ping destination address or hostname\n")
1497{
1498 execute_command ("ping", 1, argv[0], NULL);
1499 return CMD_SUCCESS;
1500}
1501
hasso4eeccf12003-06-25 10:49:55 +00001502ALIAS (vtysh_ping,
1503 vtysh_ping_ip_cmd,
1504 "ping ip WORD",
1505 "Send echo messages\n"
1506 "IP echo\n"
1507 "Ping destination address or hostname\n")
1508
paul718e3742002-12-13 20:15:29 +00001509DEFUN (vtysh_traceroute,
1510 vtysh_traceroute_cmd,
1511 "traceroute WORD",
1512 "Trace route to destination\n"
1513 "Trace route to destination address or hostname\n")
1514{
1515 execute_command ("traceroute", 1, argv[0], NULL);
1516 return CMD_SUCCESS;
1517}
1518
hasso4eeccf12003-06-25 10:49:55 +00001519ALIAS (vtysh_traceroute,
1520 vtysh_traceroute_ip_cmd,
1521 "traceroute ip WORD",
1522 "Trace route to destination\n"
1523 "IP trace\n"
1524 "Trace route to destination address or hostname\n")
1525
1526#ifdef HAVE_IPV6
1527DEFUN (vtysh_ping6,
1528 vtysh_ping6_cmd,
1529 "ping ipv6 WORD",
1530 "Send echo messages\n"
1531 "IPv6 echo\n"
1532 "Ping destination address or hostname\n")
1533{
1534 execute_command ("ping6", 1, argv[0], NULL);
1535 return CMD_SUCCESS;
1536}
1537
1538DEFUN (vtysh_traceroute6,
1539 vtysh_traceroute6_cmd,
1540 "traceroute ipv6 WORD",
1541 "Trace route to destination\n"
1542 "IPv6 trace\n"
1543 "Trace route to destination address or hostname\n")
1544{
1545 execute_command ("traceroute6", 1, argv[0], NULL);
1546 return CMD_SUCCESS;
1547}
1548#endif
1549
paul718e3742002-12-13 20:15:29 +00001550DEFUN (vtysh_telnet,
1551 vtysh_telnet_cmd,
1552 "telnet WORD",
1553 "Open a telnet connection\n"
1554 "IP address or hostname of a remote system\n")
1555{
1556 execute_command ("telnet", 1, argv[0], NULL);
1557 return CMD_SUCCESS;
1558}
1559
1560DEFUN (vtysh_telnet_port,
1561 vtysh_telnet_port_cmd,
1562 "telnet WORD PORT",
1563 "Open a telnet connection\n"
1564 "IP address or hostname of a remote system\n"
1565 "TCP Port number\n")
1566{
1567 execute_command ("telnet", 2, argv[0], argv[1]);
1568 return CMD_SUCCESS;
1569}
1570
paul5087df52003-01-25 06:56:09 +00001571DEFUN (vtysh_ssh,
1572 vtysh_ssh_cmd,
1573 "ssh WORD",
1574 "Open an ssh connection\n"
1575 "[user@]host\n")
1576{
1577 execute_command ("ssh", 1, argv[0], NULL);
1578 return CMD_SUCCESS;
1579}
1580
paul718e3742002-12-13 20:15:29 +00001581DEFUN (vtysh_start_shell,
1582 vtysh_start_shell_cmd,
1583 "start-shell",
1584 "Start UNIX shell\n")
1585{
1586 execute_command ("sh", 0, NULL, NULL);
1587 return CMD_SUCCESS;
1588}
1589
1590DEFUN (vtysh_start_bash,
1591 vtysh_start_bash_cmd,
1592 "start-shell bash",
1593 "Start UNIX shell\n"
1594 "Start bash\n")
1595{
1596 execute_command ("bash", 0, NULL, NULL);
1597 return CMD_SUCCESS;
1598}
1599
1600DEFUN (vtysh_start_zsh,
1601 vtysh_start_zsh_cmd,
1602 "start-shell zsh",
1603 "Start UNIX shell\n"
1604 "Start Z shell\n")
1605{
1606 execute_command ("zsh", 0, NULL, NULL);
1607 return CMD_SUCCESS;
1608}
1609
1610/* Route map node structure. */
1611struct cmd_node rmap_node =
1612{
1613 RMAP_NODE,
1614 "%s(config-route-map)# "
1615};
1616
1617/* Zebra node structure. */
1618struct cmd_node zebra_node =
1619{
1620 ZEBRA_NODE,
1621 "%s(config-router)# "
1622};
1623
1624struct cmd_node bgp_vpnv4_node =
1625{
1626 BGP_VPNV4_NODE,
1627 "%s(config-router-af)# "
1628};
1629
1630struct cmd_node bgp_ipv4_node =
1631{
1632 BGP_IPV4_NODE,
1633 "%s(config-router-af)# "
1634};
1635
1636struct cmd_node bgp_ipv4m_node =
1637{
1638 BGP_IPV4M_NODE,
1639 "%s(config-router-af)# "
1640};
1641
1642struct cmd_node bgp_ipv6_node =
1643{
1644 BGP_IPV6_NODE,
1645 "%s(config-router-af)# "
1646};
1647
1648struct cmd_node ospf_node =
1649{
1650 OSPF_NODE,
1651 "%s(config-router)# "
1652};
1653
1654/* RIPng node structure. */
1655struct cmd_node ripng_node =
1656{
1657 RIPNG_NODE,
1658 "%s(config-router)# "
1659};
1660
1661/* OSPF6 node structure. */
1662struct cmd_node ospf6_node =
1663{
1664 OSPF6_NODE,
1665 "%s(config-ospf6)# "
1666};
1667
1668struct cmd_node keychain_node =
1669{
1670 KEYCHAIN_NODE,
1671 "%s(config-keychain)# "
1672};
1673
1674struct cmd_node keychain_key_node =
1675{
1676 KEYCHAIN_KEY_NODE,
1677 "%s(config-keychain-key)# "
1678};
1679
1680void
1681vtysh_install_default (enum node_type node)
1682{
1683 install_element (node, &config_list_cmd);
1684}
1685
1686/* Making connection to protocol daemon. */
1687int
1688vtysh_connect (struct vtysh_client *vclient, char *path)
1689{
1690 int ret;
1691 int sock, len;
1692 struct sockaddr_un addr;
1693 struct stat s_stat;
1694 uid_t euid;
1695 gid_t egid;
1696
1697 memset (vclient, 0, sizeof (struct vtysh_client));
1698 vclient->fd = -1;
1699
1700 /* Stat socket to see if we have permission to access it. */
1701 euid = geteuid();
1702 egid = getegid();
1703 ret = stat (path, &s_stat);
1704 if (ret < 0 && errno != ENOENT)
1705 {
1706 fprintf (stderr, "vtysh_connect(%s): stat = %s\n",
1707 path, strerror(errno));
1708 exit(1);
1709 }
1710
1711 if (ret >= 0)
1712 {
1713 if (! S_ISSOCK(s_stat.st_mode))
1714 {
1715 fprintf (stderr, "vtysh_connect(%s): Not a socket\n",
1716 path);
1717 exit (1);
1718 }
1719
paul718e3742002-12-13 20:15:29 +00001720 }
1721
1722 sock = socket (AF_UNIX, SOCK_STREAM, 0);
1723 if (sock < 0)
1724 {
1725#ifdef DEBUG
1726 fprintf(stderr, "vtysh_connect(%s): socket = %s\n", path, strerror(errno));
1727#endif /* DEBUG */
1728 return -1;
1729 }
1730
1731 memset (&addr, 0, sizeof (struct sockaddr_un));
1732 addr.sun_family = AF_UNIX;
1733 strncpy (addr.sun_path, path, strlen (path));
1734#ifdef HAVE_SUN_LEN
1735 len = addr.sun_len = SUN_LEN(&addr);
1736#else
1737 len = sizeof (addr.sun_family) + strlen (addr.sun_path);
1738#endif /* HAVE_SUN_LEN */
1739
1740 ret = connect (sock, (struct sockaddr *) &addr, len);
1741 if (ret < 0)
1742 {
1743#ifdef DEBUG
1744 fprintf(stderr, "vtysh_connect(%s): connect = %s\n", path, strerror(errno));
1745#endif /* DEBUG */
1746 close (sock);
1747 return -1;
1748 }
1749 vclient->fd = sock;
1750
1751 return 0;
1752}
1753
1754void
1755vtysh_connect_all()
1756{
1757 /* Clear each daemons client structure. */
paulfe067782003-04-07 16:10:05 +00001758 vtysh_connect (&vtysh_client[VTYSH_INDEX_ZEBRA], ZEBRA_VTYSH_PATH);
1759 vtysh_connect (&vtysh_client[VTYSH_INDEX_RIP], RIP_VTYSH_PATH);
1760 vtysh_connect (&vtysh_client[VTYSH_INDEX_RIPNG], RIPNG_VTYSH_PATH);
1761 vtysh_connect (&vtysh_client[VTYSH_INDEX_OSPF], OSPF_VTYSH_PATH);
1762 vtysh_connect (&vtysh_client[VTYSH_INDEX_OSPF6], OSPF6_VTYSH_PATH);
1763 vtysh_connect (&vtysh_client[VTYSH_INDEX_BGP], BGP_VTYSH_PATH);
hassoc25e4582003-12-23 10:39:08 +00001764 vtysh_connect (&vtysh_client[VTYSH_INDEX_ISIS], ISIS_VTYSH_PATH);
paul718e3742002-12-13 20:15:29 +00001765}
1766
1767
1768/* To disable readline's filename completion */
pauldfc0d9b2003-04-18 23:55:29 +00001769char *
1770vtysh_completion_entry_function (const char *ignore, int invoking_key)
paul718e3742002-12-13 20:15:29 +00001771{
pauldfc0d9b2003-04-18 23:55:29 +00001772 return NULL;
paul718e3742002-12-13 20:15:29 +00001773}
1774
1775void
1776vtysh_readline_init ()
1777{
1778 /* readline related settings. */
1779 rl_bind_key ('?', vtysh_rl_describe);
paul68980082003-03-25 05:07:42 +00001780 rl_completion_entry_function = vtysh_completion_entry_function;
paul718e3742002-12-13 20:15:29 +00001781 rl_attempted_completion_function = (CPPFunction *)new_completion;
1782 /* do not append space after completion. It will be appended
1783 in new_completion() function explicitly */
1784 rl_completion_append_character = '\0';
1785}
1786
1787char *
1788vtysh_prompt ()
1789{
1790 struct utsname names;
1791 static char buf[100];
1792 const char*hostname;
1793 extern struct host host;
1794
1795 hostname = host.name;
1796
1797 if (!hostname)
1798 {
1799 uname (&names);
1800 hostname = names.nodename;
1801 }
1802
1803 snprintf (buf, sizeof buf, cmd_prompt (vty->node), hostname);
1804
1805 return buf;
1806}
1807
1808void
1809vtysh_init_vty ()
1810{
1811 /* Make vty structure. */
1812 vty = vty_new ();
1813 vty->type = VTY_SHELL;
1814 vty->node = VIEW_NODE;
1815
1816 /* Initialize commands. */
1817 cmd_init (0);
1818
1819 /* Install nodes. */
1820 install_node (&bgp_node, NULL);
1821 install_node (&rip_node, NULL);
1822 install_node (&interface_node, NULL);
1823 install_node (&rmap_node, NULL);
1824 install_node (&zebra_node, NULL);
1825 install_node (&bgp_vpnv4_node, NULL);
1826 install_node (&bgp_ipv4_node, NULL);
1827 install_node (&bgp_ipv4m_node, NULL);
1828/* #ifdef HAVE_IPV6 */
1829 install_node (&bgp_ipv6_node, NULL);
1830/* #endif */
1831 install_node (&ospf_node, NULL);
1832/* #ifdef HAVE_IPV6 */
1833 install_node (&ripng_node, NULL);
1834 install_node (&ospf6_node, NULL);
1835/* #endif */
1836 install_node (&keychain_node, NULL);
1837 install_node (&keychain_key_node, NULL);
hassoc25e4582003-12-23 10:39:08 +00001838 install_node (&isis_node, NULL);
paul718e3742002-12-13 20:15:29 +00001839
1840 vtysh_install_default (VIEW_NODE);
1841 vtysh_install_default (ENABLE_NODE);
1842 vtysh_install_default (CONFIG_NODE);
1843 vtysh_install_default (BGP_NODE);
1844 vtysh_install_default (RIP_NODE);
1845 vtysh_install_default (INTERFACE_NODE);
1846 vtysh_install_default (RMAP_NODE);
1847 vtysh_install_default (ZEBRA_NODE);
1848 vtysh_install_default (BGP_VPNV4_NODE);
1849 vtysh_install_default (BGP_IPV4_NODE);
1850 vtysh_install_default (BGP_IPV4M_NODE);
1851 vtysh_install_default (BGP_IPV6_NODE);
1852 vtysh_install_default (OSPF_NODE);
1853 vtysh_install_default (RIPNG_NODE);
1854 vtysh_install_default (OSPF6_NODE);
hassoc25e4582003-12-23 10:39:08 +00001855 vtysh_install_default (ISIS_NODE);
paul718e3742002-12-13 20:15:29 +00001856 vtysh_install_default (KEYCHAIN_NODE);
1857 vtysh_install_default (KEYCHAIN_KEY_NODE);
1858
1859 install_element (VIEW_NODE, &vtysh_enable_cmd);
1860 install_element (ENABLE_NODE, &vtysh_config_terminal_cmd);
1861 install_element (ENABLE_NODE, &vtysh_disable_cmd);
1862
1863 /* "exit" command. */
1864 install_element (VIEW_NODE, &vtysh_exit_all_cmd);
1865 install_element (VIEW_NODE, &vtysh_quit_all_cmd);
1866 install_element (CONFIG_NODE, &vtysh_exit_all_cmd);
1867 /* install_element (CONFIG_NODE, &vtysh_quit_all_cmd); */
1868 install_element (ENABLE_NODE, &vtysh_exit_all_cmd);
1869 install_element (ENABLE_NODE, &vtysh_quit_all_cmd);
1870 install_element (RIP_NODE, &vtysh_exit_ripd_cmd);
1871 install_element (RIP_NODE, &vtysh_quit_ripd_cmd);
paul68980082003-03-25 05:07:42 +00001872 install_element (RIPNG_NODE, &vtysh_exit_ripngd_cmd);
1873 install_element (RIPNG_NODE, &vtysh_quit_ripngd_cmd);
paul718e3742002-12-13 20:15:29 +00001874 install_element (OSPF_NODE, &vtysh_exit_ospfd_cmd);
1875 install_element (OSPF_NODE, &vtysh_quit_ospfd_cmd);
paul68980082003-03-25 05:07:42 +00001876 install_element (OSPF6_NODE, &vtysh_exit_ospf6d_cmd);
1877 install_element (OSPF6_NODE, &vtysh_quit_ospf6d_cmd);
paul718e3742002-12-13 20:15:29 +00001878 install_element (BGP_NODE, &vtysh_exit_bgpd_cmd);
1879 install_element (BGP_NODE, &vtysh_quit_bgpd_cmd);
1880 install_element (BGP_VPNV4_NODE, &vtysh_exit_bgpd_cmd);
1881 install_element (BGP_VPNV4_NODE, &vtysh_quit_bgpd_cmd);
1882 install_element (BGP_IPV4_NODE, &vtysh_exit_bgpd_cmd);
1883 install_element (BGP_IPV4_NODE, &vtysh_quit_bgpd_cmd);
1884 install_element (BGP_IPV4M_NODE, &vtysh_exit_bgpd_cmd);
1885 install_element (BGP_IPV4M_NODE, &vtysh_quit_bgpd_cmd);
1886 install_element (BGP_IPV6_NODE, &vtysh_exit_bgpd_cmd);
1887 install_element (BGP_IPV6_NODE, &vtysh_quit_bgpd_cmd);
hassoc25e4582003-12-23 10:39:08 +00001888 install_element (ISIS_NODE, &vtysh_exit_isisd_cmd);
1889 install_element (ISIS_NODE, &vtysh_quit_isisd_cmd);
paul718e3742002-12-13 20:15:29 +00001890 install_element (KEYCHAIN_NODE, &vtysh_exit_ripd_cmd);
1891 install_element (KEYCHAIN_NODE, &vtysh_quit_ripd_cmd);
1892 install_element (KEYCHAIN_KEY_NODE, &vtysh_exit_ripd_cmd);
1893 install_element (KEYCHAIN_KEY_NODE, &vtysh_quit_ripd_cmd);
1894 install_element (RMAP_NODE, &vtysh_exit_rmap_cmd);
1895 install_element (RMAP_NODE, &vtysh_quit_rmap_cmd);
1896
1897 /* "end" command. */
1898 install_element (CONFIG_NODE, &vtysh_end_all_cmd);
1899 install_element (ENABLE_NODE, &vtysh_end_all_cmd);
1900 install_element (RIP_NODE, &vtysh_end_all_cmd);
1901 install_element (RIPNG_NODE, &vtysh_end_all_cmd);
1902 install_element (OSPF_NODE, &vtysh_end_all_cmd);
1903 install_element (OSPF6_NODE, &vtysh_end_all_cmd);
1904 install_element (BGP_NODE, &vtysh_end_all_cmd);
1905 install_element (BGP_IPV4_NODE, &vtysh_end_all_cmd);
1906 install_element (BGP_IPV4M_NODE, &vtysh_end_all_cmd);
1907 install_element (BGP_VPNV4_NODE, &vtysh_end_all_cmd);
1908 install_element (BGP_IPV6_NODE, &vtysh_end_all_cmd);
hassoc25e4582003-12-23 10:39:08 +00001909 install_element (ISIS_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00001910 install_element (KEYCHAIN_NODE, &vtysh_end_all_cmd);
1911 install_element (KEYCHAIN_KEY_NODE, &vtysh_end_all_cmd);
1912 install_element (RMAP_NODE, &vtysh_end_all_cmd);
1913
paul338a9912003-03-01 15:44:10 +00001914 install_element (INTERFACE_NODE, &interface_desc_cmd);
paul464dc8d2003-03-28 02:25:45 +00001915 install_element (INTERFACE_NODE, &no_interface_desc_cmd);
paul718e3742002-12-13 20:15:29 +00001916 install_element (INTERFACE_NODE, &vtysh_end_all_cmd);
1917 install_element (INTERFACE_NODE, &vtysh_exit_interface_cmd);
1918 install_element (INTERFACE_NODE, &vtysh_quit_interface_cmd);
1919 install_element (CONFIG_NODE, &router_rip_cmd);
1920#ifdef HAVE_IPV6
1921 install_element (CONFIG_NODE, &router_ripng_cmd);
1922#endif
1923 install_element (CONFIG_NODE, &router_ospf_cmd);
1924#ifdef HAVE_IPV6
1925 install_element (CONFIG_NODE, &router_ospf6_cmd);
1926#endif
hassoc25e4582003-12-23 10:39:08 +00001927 install_element (CONFIG_NODE, &router_isis_cmd);
paul718e3742002-12-13 20:15:29 +00001928 install_element (CONFIG_NODE, &router_bgp_cmd);
1929 install_element (BGP_NODE, &address_family_vpnv4_cmd);
1930 install_element (BGP_NODE, &address_family_vpnv4_unicast_cmd);
1931 install_element (BGP_NODE, &address_family_ipv4_unicast_cmd);
1932 install_element (BGP_NODE, &address_family_ipv4_multicast_cmd);
1933#ifdef HAVE_IPV6
1934 install_element (BGP_NODE, &address_family_ipv6_cmd);
1935 install_element (BGP_NODE, &address_family_ipv6_unicast_cmd);
1936#endif
1937 install_element (BGP_VPNV4_NODE, &exit_address_family_cmd);
1938 install_element (BGP_IPV4_NODE, &exit_address_family_cmd);
1939 install_element (BGP_IPV4M_NODE, &exit_address_family_cmd);
1940 install_element (BGP_IPV6_NODE, &exit_address_family_cmd);
1941 install_element (CONFIG_NODE, &key_chain_cmd);
1942 install_element (CONFIG_NODE, &route_map_cmd);
1943 install_element (KEYCHAIN_NODE, &key_cmd);
1944 install_element (KEYCHAIN_NODE, &key_chain_cmd);
1945 install_element (KEYCHAIN_KEY_NODE, &key_chain_cmd);
1946 install_element (CONFIG_NODE, &vtysh_interface_cmd);
paul32d24632003-05-23 09:25:20 +00001947 install_element (CONFIG_NODE, &vtysh_no_interface_cmd);
paul718e3742002-12-13 20:15:29 +00001948 install_element (ENABLE_NODE, &vtysh_show_running_config_cmd);
1949 install_element (ENABLE_NODE, &vtysh_copy_runningconfig_startupconfig_cmd);
1950 install_element (ENABLE_NODE, &vtysh_write_file_cmd);
hasso4a6e2252003-05-25 11:51:29 +00001951 install_element (ENABLE_NODE, &vtysh_write_cmd);
paul718e3742002-12-13 20:15:29 +00001952
1953 /* write terminal command */
1954 install_element (ENABLE_NODE, &vtysh_write_terminal_cmd);
1955 install_element (CONFIG_NODE, &vtysh_write_terminal_cmd);
1956 install_element (BGP_NODE, &vtysh_write_terminal_cmd);
1957 install_element (BGP_VPNV4_NODE, &vtysh_write_terminal_cmd);
1958 install_element (BGP_IPV4_NODE, &vtysh_write_terminal_cmd);
1959 install_element (BGP_IPV4M_NODE, &vtysh_write_terminal_cmd);
1960 install_element (BGP_IPV6_NODE, &vtysh_write_terminal_cmd);
1961 install_element (RIP_NODE, &vtysh_write_terminal_cmd);
1962 install_element (RIPNG_NODE, &vtysh_write_terminal_cmd);
1963 install_element (OSPF_NODE, &vtysh_write_terminal_cmd);
1964 install_element (OSPF6_NODE, &vtysh_write_terminal_cmd);
hassoc25e4582003-12-23 10:39:08 +00001965 install_element (ISIS_NODE, &vtysh_write_terminal_cmd);
paul718e3742002-12-13 20:15:29 +00001966 install_element (INTERFACE_NODE, &vtysh_write_terminal_cmd);
1967 install_element (RMAP_NODE, &vtysh_write_terminal_cmd);
1968 install_element (KEYCHAIN_NODE, &vtysh_write_terminal_cmd);
1969 install_element (KEYCHAIN_KEY_NODE, &vtysh_write_terminal_cmd);
1970
1971 /* write memory command */
1972 install_element (ENABLE_NODE, &vtysh_write_memory_cmd);
1973 install_element (CONFIG_NODE, &vtysh_write_memory_cmd);
1974 install_element (BGP_NODE, &vtysh_write_memory_cmd);
1975 install_element (BGP_VPNV4_NODE, &vtysh_write_memory_cmd);
1976 install_element (BGP_IPV4_NODE, &vtysh_write_memory_cmd);
1977 install_element (BGP_IPV4M_NODE, &vtysh_write_memory_cmd);
1978 install_element (BGP_IPV6_NODE, &vtysh_write_memory_cmd);
1979 install_element (RIP_NODE, &vtysh_write_memory_cmd);
1980 install_element (RIPNG_NODE, &vtysh_write_memory_cmd);
1981 install_element (OSPF_NODE, &vtysh_write_memory_cmd);
1982 install_element (OSPF6_NODE, &vtysh_write_memory_cmd);
hassoc25e4582003-12-23 10:39:08 +00001983 install_element (ISIS_NODE, &vtysh_write_memory_cmd);
paul718e3742002-12-13 20:15:29 +00001984 install_element (INTERFACE_NODE, &vtysh_write_memory_cmd);
1985 install_element (RMAP_NODE, &vtysh_write_memory_cmd);
1986 install_element (KEYCHAIN_NODE, &vtysh_write_memory_cmd);
1987 install_element (KEYCHAIN_KEY_NODE, &vtysh_write_memory_cmd);
1988
1989 install_element (VIEW_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00001990 install_element (VIEW_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00001991 install_element (VIEW_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00001992 install_element (VIEW_NODE, &vtysh_traceroute_ip_cmd);
1993#ifdef HAVE_IPV6
1994 install_element (VIEW_NODE, &vtysh_ping6_cmd);
1995 install_element (VIEW_NODE, &vtysh_traceroute6_cmd);
1996#endif
paul718e3742002-12-13 20:15:29 +00001997 install_element (VIEW_NODE, &vtysh_telnet_cmd);
1998 install_element (VIEW_NODE, &vtysh_telnet_port_cmd);
paul5087df52003-01-25 06:56:09 +00001999 install_element (VIEW_NODE, &vtysh_ssh_cmd);
paul718e3742002-12-13 20:15:29 +00002000 install_element (ENABLE_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002001 install_element (ENABLE_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00002002 install_element (ENABLE_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002003 install_element (ENABLE_NODE, &vtysh_traceroute_ip_cmd);
2004#ifdef HAVE_IPV6
2005 install_element (ENABLE_NODE, &vtysh_ping6_cmd);
2006 install_element (ENABLE_NODE, &vtysh_traceroute6_cmd);
2007#endif
paul718e3742002-12-13 20:15:29 +00002008 install_element (ENABLE_NODE, &vtysh_telnet_cmd);
2009 install_element (ENABLE_NODE, &vtysh_telnet_port_cmd);
2010 install_element (ENABLE_NODE, &vtysh_start_shell_cmd);
2011 install_element (ENABLE_NODE, &vtysh_start_bash_cmd);
2012 install_element (ENABLE_NODE, &vtysh_start_zsh_cmd);
2013
paul718e3742002-12-13 20:15:29 +00002014 install_element (CONFIG_NODE, &vtysh_log_stdout_cmd);
2015 install_element (CONFIG_NODE, &no_vtysh_log_stdout_cmd);
2016 install_element (CONFIG_NODE, &vtysh_log_file_cmd);
2017 install_element (CONFIG_NODE, &no_vtysh_log_file_cmd);
2018 install_element (CONFIG_NODE, &vtysh_log_syslog_cmd);
2019 install_element (CONFIG_NODE, &no_vtysh_log_syslog_cmd);
2020 install_element (CONFIG_NODE, &vtysh_log_trap_cmd);
2021 install_element (CONFIG_NODE, &no_vtysh_log_trap_cmd);
2022 install_element (CONFIG_NODE, &vtysh_log_record_priority_cmd);
2023 install_element (CONFIG_NODE, &no_vtysh_log_record_priority_cmd);
paul4fc01e62002-12-13 20:49:00 +00002024 install_element (CONFIG_NODE, &vtysh_write_config_cmd);
2025 install_element (CONFIG_NODE, &no_vtysh_write_config_cmd);
paul718e3742002-12-13 20:15:29 +00002026}