blob: e8310d7c6abad00fc8aa2fcbc3636b234ae8bf9c [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];
hassob094d262004-08-25 12:22:00 +000048
paul718e3742002-12-13 20:15:29 +000049void
50vclient_close (struct vtysh_client *vclient)
51{
52 if (vclient->fd > 0)
53 close (vclient->fd);
54 vclient->fd = -1;
55}
56
paul718e3742002-12-13 20:15:29 +000057/* Following filled with debug code to trace a problematic condition
hasso95e735b2004-08-26 13:08:30 +000058 * under load - it SHOULD handle it. */
paul718e3742002-12-13 20:15:29 +000059#define ERR_WHERE_STRING "vtysh(): vtysh_client_config(): "
60int
61vtysh_client_config (struct vtysh_client *vclient, char *line)
62{
63 int ret;
64 char *buf;
65 size_t bufsz;
66 char *pbuf;
67 size_t left;
68 char *eoln;
69 int nbytes;
70 int i;
71 int readln;
72
73 if (vclient->fd < 0)
74 return CMD_SUCCESS;
75
76 ret = write (vclient->fd, line, strlen (line) + 1);
77 if (ret <= 0)
78 {
79 vclient_close (vclient);
80 return CMD_SUCCESS;
81 }
82
hasso95e735b2004-08-26 13:08:30 +000083 /* Allow enough room for buffer to read more than a few pages from socket. */
paule3d29b52003-01-23 18:05:42 +000084 bufsz = 5 * getpagesize() + 1;
paul718e3742002-12-13 20:15:29 +000085 buf = XMALLOC(MTYPE_TMP, bufsz);
86 memset(buf, 0, bufsz);
87 pbuf = buf;
88
89 while (1)
90 {
91 if (pbuf >= ((buf + bufsz) -1))
92 {
93 fprintf (stderr, ERR_WHERE_STRING \
94 "warning - pbuf beyond buffer end.\n");
95 return CMD_WARNING;
96 }
97
98 readln = (buf + bufsz) - pbuf - 1;
99 nbytes = read (vclient->fd, pbuf, readln);
100
101 if (nbytes <= 0)
102 {
103
104 if (errno == EINTR)
105 continue;
106
107 fprintf(stderr, ERR_WHERE_STRING "(%u)", errno);
108 perror("");
109
110 if (errno == EAGAIN || errno == EIO)
111 continue;
112
113 vclient_close (vclient);
114 XFREE(MTYPE_TMP, buf);
115 return CMD_SUCCESS;
116 }
117
118 pbuf[nbytes] = '\0';
119
120 if (nbytes >= 4)
121 {
122 i = nbytes - 4;
123 if (pbuf[i] == '\0' && pbuf[i + 1] == '\0' && pbuf[i + 2] == '\0')
124 {
125 ret = pbuf[i + 3];
126 break;
127 }
128 }
129 pbuf += nbytes;
130
131 /* See if a line exists in buffer, if so parse and consume it, and
hasso95e735b2004-08-26 13:08:30 +0000132 * reset read position. */
paul718e3742002-12-13 20:15:29 +0000133 if ((eoln = strrchr(buf, '\n')) == NULL)
134 continue;
135
136 if (eoln >= ((buf + bufsz) - 1))
137 {
138 fprintf (stderr, ERR_WHERE_STRING \
139 "warning - eoln beyond buffer end.\n");
140 }
141 vtysh_config_parse(buf);
142
143 eoln++;
144 left = (size_t)(buf + bufsz - eoln);
145 memmove(buf, eoln, left);
146 buf[bufsz-1] = '\0';
147 pbuf = buf + strlen(buf);
148 }
149
hasso95e735b2004-08-26 13:08:30 +0000150 /* Parse anything left in the buffer. */
paul718e3742002-12-13 20:15:29 +0000151 vtysh_config_parse (buf);
152
153 XFREE(MTYPE_TMP, buf);
154 return ret;
155}
156
157int
158vtysh_client_execute (struct vtysh_client *vclient, char *line, FILE *fp)
159{
160 int ret;
161 char buf[1001];
162 int nbytes;
163 int i;
164
165 if (vclient->fd < 0)
166 return CMD_SUCCESS;
167
168 ret = write (vclient->fd, line, strlen (line) + 1);
169 if (ret <= 0)
170 {
171 vclient_close (vclient);
172 return CMD_SUCCESS;
173 }
174
175 while (1)
176 {
177 nbytes = read (vclient->fd, buf, sizeof(buf)-1);
178
179 if (nbytes <= 0 && errno != EINTR)
180 {
181 vclient_close (vclient);
182 return CMD_SUCCESS;
183 }
184
185 if (nbytes > 0)
186 {
187 buf[nbytes] = '\0';
188 fprintf (fp, "%s", buf);
189 fflush (fp);
190
191 if (nbytes >= 4)
192 {
193 i = nbytes - 4;
194 if (buf[i] == '\0' && buf[i + 1] == '\0' && buf[i + 2] == '\0')
195 {
196 ret = buf[i + 3];
197 break;
198 }
199 }
200 }
201 }
202 return ret;
203}
204
205void
206vtysh_exit_ripd_only ()
207{
208 vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIP], "exit", stdout);
209}
210
211
212void
213vtysh_pager_init ()
214{
215 vtysh_pager_name = getenv ("VTYSH_PAGER");
216 if (! vtysh_pager_name)
217 vtysh_pager_name = "more";
218}
219
220/* Command execution over the vty interface. */
221void
222vtysh_execute_func (char *line, int pager)
223{
224 int ret, cmd_stat;
225 vector vline;
226 struct cmd_element *cmd;
227 FILE *fp = NULL;
paula805cc22003-05-01 14:29:48 +0000228 int closepager=0;
paul718e3742002-12-13 20:15:29 +0000229
hasso95e735b2004-08-26 13:08:30 +0000230 /* Split readline string up into the vector. */
paul718e3742002-12-13 20:15:29 +0000231 vline = cmd_make_strvec (line);
232
233 if (vline == NULL)
234 return;
235
236 ret = cmd_execute_command (vline, vty, &cmd);
237
238 cmd_free_strvec (vline);
239
240 switch (ret)
241 {
242 case CMD_WARNING:
243 if (vty->type == VTY_FILE)
paul4fc01e62002-12-13 20:49:00 +0000244 fprintf (stdout,"Warning...\n");
paul718e3742002-12-13 20:15:29 +0000245 break;
246 case CMD_ERR_AMBIGUOUS:
paul4fc01e62002-12-13 20:49:00 +0000247 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000248 break;
249 case CMD_ERR_NO_MATCH:
paul4fc01e62002-12-13 20:49:00 +0000250 fprintf (stdout,"%% Unknown command.\n");
paul718e3742002-12-13 20:15:29 +0000251 break;
252 case CMD_ERR_INCOMPLETE:
paul4fc01e62002-12-13 20:49:00 +0000253 fprintf (stdout,"%% Command incomplete.\n");
paul718e3742002-12-13 20:15:29 +0000254 break;
255 case CMD_SUCCESS_DAEMON:
256 {
257 if (pager && vtysh_pager_name)
258 {
paul4fc01e62002-12-13 20:49:00 +0000259 fp = popen (vtysh_pager_name, "w");
paul718e3742002-12-13 20:15:29 +0000260 if (fp == NULL)
261 {
paula805cc22003-05-01 14:29:48 +0000262 perror ("popen failed for pager");
263 fp = stdout;
paul718e3742002-12-13 20:15:29 +0000264 }
paula805cc22003-05-01 14:29:48 +0000265 else
266 closepager=1;
paul718e3742002-12-13 20:15:29 +0000267 }
268 else
269 fp = stdout;
270
271 if (! strcmp(cmd->string,"configure terminal"))
272 {
273 cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ZEBRA],
274 line, fp);
275 if (cmd_stat != CMD_WARNING)
276 cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIP],
277 line, fp);
278 if (cmd_stat != CMD_WARNING)
hasso95e735b2004-08-26 13:08:30 +0000279 cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIPNG],
280 line, fp);
paul718e3742002-12-13 20:15:29 +0000281 if (cmd_stat != CMD_WARNING)
282 cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF],
283 line, fp);
284 if (cmd_stat != CMD_WARNING)
hasso95e735b2004-08-26 13:08:30 +0000285 cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF6],
286 line, fp);
paul718e3742002-12-13 20:15:29 +0000287 if (cmd_stat != CMD_WARNING)
288 cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_BGP],
289 line, fp);
hassob094d262004-08-25 12:22:00 +0000290 if (cmd_stat != CMD_WARNING)
hasso95e735b2004-08-26 13:08:30 +0000291 cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ISIS],
292 line, fp);
paul718e3742002-12-13 20:15:29 +0000293 if (cmd_stat)
294 {
hassob094d262004-08-25 12:22:00 +0000295 line = "end";
296 vline = cmd_make_strvec (line);
paul718e3742002-12-13 20:15:29 +0000297
hassob094d262004-08-25 12:22:00 +0000298 if (vline == NULL)
paul718e3742002-12-13 20:15:29 +0000299 {
paula805cc22003-05-01 14:29:48 +0000300 if (pager && vtysh_pager_name && fp && closepager)
paul718e3742002-12-13 20:15:29 +0000301 {
302 if (pclose (fp) == -1)
303 {
paula805cc22003-05-01 14:29:48 +0000304 perror ("pclose failed for pager");
paul718e3742002-12-13 20:15:29 +0000305 }
306 fp = NULL;
307 }
308 return;
309 }
310
hassob094d262004-08-25 12:22:00 +0000311 ret = cmd_execute_command (vline, vty, &cmd);
312 cmd_free_strvec (vline);
313 if (ret != CMD_SUCCESS_DAEMON)
314 break;
paul718e3742002-12-13 20:15:29 +0000315 }
316 else
317 if (cmd->func)
318 {
319 (*cmd->func) (cmd, vty, 0, NULL);
320 break;
hassob094d262004-08-25 12:22:00 +0000321 }
paul718e3742002-12-13 20:15:29 +0000322 }
323
324 if (cmd->daemon & VTYSH_ZEBRA)
325 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ZEBRA], line, fp)
326 != CMD_SUCCESS)
327 break;
328 if (cmd->daemon & VTYSH_RIPD)
329 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIP], line, fp)
330 != CMD_SUCCESS)
331 break;
332 if (cmd->daemon & VTYSH_RIPNGD)
333 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIPNG], line, fp)
334 != CMD_SUCCESS)
335 break;
336 if (cmd->daemon & VTYSH_OSPFD)
337 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF], line, fp)
338 != CMD_SUCCESS)
339 break;
340 if (cmd->daemon & VTYSH_OSPF6D)
341 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF6], line, fp)
342 != CMD_SUCCESS)
343 break;
344 if (cmd->daemon & VTYSH_BGPD)
345 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_BGP], line, fp)
346 != CMD_SUCCESS)
347 break;
hassob094d262004-08-25 12:22:00 +0000348 if (cmd->daemon & VTYSH_ISISD)
349 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ISIS], line, fp)
350 != CMD_SUCCESS)
351 break;
paul718e3742002-12-13 20:15:29 +0000352 if (cmd->func)
353 (*cmd->func) (cmd, vty, 0, NULL);
354 }
355 }
paula805cc22003-05-01 14:29:48 +0000356 if (pager && vtysh_pager_name && fp && closepager)
paul718e3742002-12-13 20:15:29 +0000357 {
358 if (pclose (fp) == -1)
359 {
paula805cc22003-05-01 14:29:48 +0000360 perror ("pclose failed for pager");
paul718e3742002-12-13 20:15:29 +0000361 }
362 fp = NULL;
363 }
364}
365
366void
367vtysh_execute_no_pager (char *line)
368{
369 vtysh_execute_func (line, 0);
370}
371
372void
373vtysh_execute (char *line)
374{
375 vtysh_execute_func (line, 1);
376}
377
378/* Configration make from file. */
379int
380vtysh_config_from_file (struct vty *vty, FILE *fp)
381{
382 int ret;
383 vector vline;
384 struct cmd_element *cmd;
385
386 while (fgets (vty->buf, VTY_BUFSIZ, fp))
387 {
388 if (vty->buf[0] == '!' || vty->buf[1] == '#')
389 continue;
390
391 vline = cmd_make_strvec (vty->buf);
392
hasso95e735b2004-08-26 13:08:30 +0000393 /* In case of comment line. */
paul718e3742002-12-13 20:15:29 +0000394 if (vline == NULL)
395 continue;
396
hasso95e735b2004-08-26 13:08:30 +0000397 /* Execute configuration command : this is strict match. */
paul718e3742002-12-13 20:15:29 +0000398 ret = cmd_execute_command_strict (vline, vty, &cmd);
399
hasso95e735b2004-08-26 13:08:30 +0000400 /* Try again with setting node to CONFIG_NODE. */
paul718e3742002-12-13 20:15:29 +0000401 if (ret != CMD_SUCCESS
402 && ret != CMD_SUCCESS_DAEMON
403 && ret != CMD_WARNING)
404 {
405 if (vty->node == KEYCHAIN_KEY_NODE)
406 {
407 vty->node = KEYCHAIN_NODE;
408 vtysh_exit_ripd_only ();
409 ret = cmd_execute_command_strict (vline, vty, &cmd);
410
411 if (ret != CMD_SUCCESS
412 && ret != CMD_SUCCESS_DAEMON
413 && ret != CMD_WARNING)
414 {
415 vtysh_exit_ripd_only ();
416 vty->node = CONFIG_NODE;
417 ret = cmd_execute_command_strict (vline, vty, &cmd);
418 }
419 }
420 else
421 {
422 vtysh_execute ("end");
423 vtysh_execute ("configure terminal");
424 vty->node = CONFIG_NODE;
425 ret = cmd_execute_command_strict (vline, vty, &cmd);
426 }
427 }
428
429 cmd_free_strvec (vline);
430
431 switch (ret)
432 {
433 case CMD_WARNING:
434 if (vty->type == VTY_FILE)
paul4fc01e62002-12-13 20:49:00 +0000435 fprintf (stdout,"Warning...\n");
paul718e3742002-12-13 20:15:29 +0000436 break;
437 case CMD_ERR_AMBIGUOUS:
paul4fc01e62002-12-13 20:49:00 +0000438 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000439 break;
440 case CMD_ERR_NO_MATCH:
paul4fc01e62002-12-13 20:49:00 +0000441 fprintf (stdout,"%% Unknown command: %s", vty->buf);
paul718e3742002-12-13 20:15:29 +0000442 break;
443 case CMD_ERR_INCOMPLETE:
paul4fc01e62002-12-13 20:49:00 +0000444 fprintf (stdout,"%% Command incomplete.\n");
paul718e3742002-12-13 20:15:29 +0000445 break;
446 case CMD_SUCCESS_DAEMON:
447 {
448 if (cmd->daemon & VTYSH_ZEBRA)
449 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ZEBRA],
450 vty->buf, stdout) != CMD_SUCCESS)
451 break;
452 if (cmd->daemon & VTYSH_RIPD)
453 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIP],
454 vty->buf, stdout) != CMD_SUCCESS)
455 break;
456 if (cmd->daemon & VTYSH_RIPNGD)
457 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIPNG],
458 vty->buf, stdout) != CMD_SUCCESS)
459 break;
460 if (cmd->daemon & VTYSH_OSPFD)
461 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF],
462 vty->buf, stdout) != CMD_SUCCESS)
463 break;
464 if (cmd->daemon & VTYSH_OSPF6D)
465 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF6],
466 vty->buf, stdout) != CMD_SUCCESS)
467 break;
468 if (cmd->daemon & VTYSH_BGPD)
469 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_BGP],
470 vty->buf, stdout) != CMD_SUCCESS)
471 break;
hassob094d262004-08-25 12:22:00 +0000472 if (cmd->daemon & VTYSH_ISISD)
473 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ISIS],
474 vty->buf, stdout) != CMD_SUCCESS)
475 break;
paul718e3742002-12-13 20:15:29 +0000476 if (cmd->func)
477 (*cmd->func) (cmd, vty, 0, NULL);
478 }
479 }
480 }
481 return CMD_SUCCESS;
482}
483
484/* We don't care about the point of the cursor when '?' is typed. */
485int
486vtysh_rl_describe ()
487{
488 int ret;
489 int i;
490 vector vline;
491 vector describe;
492 int width;
493 struct desc *desc;
494
495 vline = cmd_make_strvec (rl_line_buffer);
496
497 /* In case of '> ?'. */
498 if (vline == NULL)
499 {
500 vline = vector_init (1);
501 vector_set (vline, '\0');
502 }
503 else
504 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
505 vector_set (vline, '\0');
506
507 describe = cmd_describe_command (vline, vty, &ret);
508
paul4fc01e62002-12-13 20:49:00 +0000509 fprintf (stdout,"\n");
paul718e3742002-12-13 20:15:29 +0000510
511 /* Ambiguous and no match error. */
512 switch (ret)
513 {
514 case CMD_ERR_AMBIGUOUS:
515 cmd_free_strvec (vline);
paul4fc01e62002-12-13 20:49:00 +0000516 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000517 rl_on_new_line ();
518 return 0;
519 break;
520 case CMD_ERR_NO_MATCH:
521 cmd_free_strvec (vline);
paul4fc01e62002-12-13 20:49:00 +0000522 fprintf (stdout,"%% There is no matched command.\n");
paul718e3742002-12-13 20:15:29 +0000523 rl_on_new_line ();
524 return 0;
525 break;
526 }
527
528 /* Get width of command string. */
529 width = 0;
530 for (i = 0; i < vector_max (describe); i++)
531 if ((desc = vector_slot (describe, i)) != NULL)
532 {
533 int len;
534
535 if (desc->cmd[0] == '\0')
536 continue;
537
538 len = strlen (desc->cmd);
539 if (desc->cmd[0] == '.')
540 len--;
541
542 if (width < len)
543 width = len;
544 }
545
546 for (i = 0; i < vector_max (describe); i++)
547 if ((desc = vector_slot (describe, i)) != NULL)
548 {
549 if (desc->cmd[0] == '\0')
550 continue;
551
552 if (! desc->str)
paul4fc01e62002-12-13 20:49:00 +0000553 fprintf (stdout," %-s\n",
hassob094d262004-08-25 12:22:00 +0000554 desc->cmd[0] == '.' ? desc->cmd + 1 : desc->cmd);
paul718e3742002-12-13 20:15:29 +0000555 else
paul4fc01e62002-12-13 20:49:00 +0000556 fprintf (stdout," %-*s %s\n",
hassob094d262004-08-25 12:22:00 +0000557 width,
558 desc->cmd[0] == '.' ? desc->cmd + 1 : desc->cmd,
559 desc->str);
paul718e3742002-12-13 20:15:29 +0000560 }
561
562 cmd_free_strvec (vline);
563 vector_free (describe);
564
565 rl_on_new_line();
566
567 return 0;
568}
569
hasso95e735b2004-08-26 13:08:30 +0000570/* Result of cmd_complete_command() call will be stored here
571 * and used in new_completion() in order to put the space in
572 * correct places only. */
paul718e3742002-12-13 20:15:29 +0000573int complete_status;
574
575char *
pauldfc0d9b2003-04-18 23:55:29 +0000576command_generator (const char *text, int state)
paul718e3742002-12-13 20:15:29 +0000577{
578 vector vline;
579 static char **matched = NULL;
580 static int index = 0;
581
582 /* First call. */
583 if (! state)
584 {
585 index = 0;
586
587 if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
588 return NULL;
589
590 vline = cmd_make_strvec (rl_line_buffer);
591 if (vline == NULL)
592 return NULL;
593
594 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
595 vector_set (vline, '\0');
596
597 matched = cmd_complete_command (vline, vty, &complete_status);
598 }
599
600 if (matched && matched[index])
601 return matched[index++];
602
603 return NULL;
604}
605
606char **
607new_completion (char *text, int start, int end)
608{
609 char **matches;
610
pauldfc0d9b2003-04-18 23:55:29 +0000611 matches = rl_completion_matches (text, command_generator);
paul718e3742002-12-13 20:15:29 +0000612
613 if (matches)
614 {
615 rl_point = rl_end;
616 if (complete_status == CMD_COMPLETE_FULL_MATCH)
617 rl_pending_input = ' ';
618 }
619
620 return matches;
621}
622
623char **
624vtysh_completion (char *text, int start, int end)
625{
626 int ret;
627 vector vline;
628 char **matched = NULL;
629
630 if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
631 return NULL;
632
633 vline = cmd_make_strvec (rl_line_buffer);
634 if (vline == NULL)
635 return NULL;
636
637 /* In case of 'help \t'. */
638 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
639 vector_set (vline, '\0');
640
641 matched = cmd_complete_command (vline, vty, &ret);
642
643 cmd_free_strvec (vline);
644
645 return (char **) matched;
646}
647
hasso95e735b2004-08-26 13:08:30 +0000648/* Vty node structures. */
paul718e3742002-12-13 20:15:29 +0000649struct cmd_node bgp_node =
650{
651 BGP_NODE,
652 "%s(config-router)# ",
653};
654
paul718e3742002-12-13 20:15:29 +0000655struct cmd_node rip_node =
656{
657 RIP_NODE,
658 "%s(config-router)# ",
659};
660
hassoc25e4582003-12-23 10:39:08 +0000661struct cmd_node isis_node =
662{
663 ISIS_NODE,
664 "%s(config-router)# ",
hassoc25e4582003-12-23 10:39:08 +0000665};
666
paul718e3742002-12-13 20:15:29 +0000667struct cmd_node interface_node =
668{
669 INTERFACE_NODE,
670 "%s(config-if)# ",
671};
672
hasso95e735b2004-08-26 13:08:30 +0000673struct cmd_node rmap_node =
674{
675 RMAP_NODE,
676 "%s(config-route-map)# "
677};
678
679struct cmd_node zebra_node =
680{
681 ZEBRA_NODE,
682 "%s(config-router)# "
683};
684
685struct cmd_node bgp_vpnv4_node =
686{
687 BGP_VPNV4_NODE,
688 "%s(config-router-af)# "
689};
690
691struct cmd_node bgp_ipv4_node =
692{
693 BGP_IPV4_NODE,
694 "%s(config-router-af)# "
695};
696
697struct cmd_node bgp_ipv4m_node =
698{
699 BGP_IPV4M_NODE,
700 "%s(config-router-af)# "
701};
702
703struct cmd_node bgp_ipv6_node =
704{
705 BGP_IPV6_NODE,
706 "%s(config-router-af)# "
707};
708
709struct cmd_node ospf_node =
710{
711 OSPF_NODE,
712 "%s(config-router)# "
713};
714
715struct cmd_node ripng_node =
716{
717 RIPNG_NODE,
718 "%s(config-router)# "
719};
720
721struct cmd_node ospf6_node =
722{
723 OSPF6_NODE,
724 "%s(config-ospf6)# "
725};
726
727struct cmd_node keychain_node =
728{
729 KEYCHAIN_NODE,
730 "%s(config-keychain)# "
731};
732
733struct cmd_node keychain_key_node =
734{
735 KEYCHAIN_KEY_NODE,
736 "%s(config-keychain-key)# "
737};
738
739/* When '^Z' is received from vty, move down to the enable mode. */
740int
741vtysh_end ()
742{
743 switch (vty->node)
744 {
745 case VIEW_NODE:
746 case ENABLE_NODE:
747 /* Nothing to do. */
748 break;
749 default:
750 vty->node = ENABLE_NODE;
751 break;
752 }
753 return CMD_SUCCESS;
754}
755
756DEFUNSH (VTYSH_ALL,
757 vtysh_end_all,
758 vtysh_end_all_cmd,
759 "end",
760 "End current mode and down to previous mode\n")
761{
762 return vtysh_end (vty);
763}
764
paul718e3742002-12-13 20:15:29 +0000765DEFUNSH (VTYSH_BGPD,
766 router_bgp,
767 router_bgp_cmd,
768 "router bgp <1-65535>",
769 ROUTER_STR
770 BGP_STR
771 AS_STR)
772{
773 vty->node = BGP_NODE;
774 return CMD_SUCCESS;
775}
776
777DEFUNSH (VTYSH_BGPD,
778 address_family_vpnv4,
779 address_family_vpnv4_cmd,
780 "address-family vpnv4",
781 "Enter Address Family command mode\n"
782 "Address family\n")
783{
784 vty->node = BGP_VPNV4_NODE;
785 return CMD_SUCCESS;
786}
787
788DEFUNSH (VTYSH_BGPD,
789 address_family_vpnv4_unicast,
790 address_family_vpnv4_unicast_cmd,
791 "address-family vpnv4 unicast",
792 "Enter Address Family command mode\n"
793 "Address family\n"
794 "Address Family Modifier\n")
795{
796 vty->node = BGP_VPNV4_NODE;
797 return CMD_SUCCESS;
798}
799
800DEFUNSH (VTYSH_BGPD,
801 address_family_ipv4_unicast,
802 address_family_ipv4_unicast_cmd,
803 "address-family ipv4 unicast",
804 "Enter Address Family command mode\n"
805 "Address family\n"
806 "Address Family Modifier\n")
807{
808 vty->node = BGP_IPV4_NODE;
809 return CMD_SUCCESS;
810}
811
812DEFUNSH (VTYSH_BGPD,
813 address_family_ipv4_multicast,
814 address_family_ipv4_multicast_cmd,
815 "address-family ipv4 multicast",
816 "Enter Address Family command mode\n"
817 "Address family\n"
818 "Address Family Modifier\n")
819{
820 vty->node = BGP_IPV4M_NODE;
821 return CMD_SUCCESS;
822}
823
824DEFUNSH (VTYSH_BGPD,
825 address_family_ipv6,
826 address_family_ipv6_cmd,
827 "address-family ipv6",
828 "Enter Address Family command mode\n"
829 "Address family\n")
830{
831 vty->node = BGP_IPV6_NODE;
832 return CMD_SUCCESS;
833}
834
835DEFUNSH (VTYSH_BGPD,
836 address_family_ipv6_unicast,
837 address_family_ipv6_unicast_cmd,
838 "address-family ipv6 unicast",
839 "Enter Address Family command mode\n"
840 "Address family\n"
841 "Address Family Modifier\n")
842{
843 vty->node = BGP_IPV6_NODE;
844 return CMD_SUCCESS;
845}
846
847DEFUNSH (VTYSH_RIPD,
848 key_chain,
849 key_chain_cmd,
850 "key chain WORD",
851 "Authentication key management\n"
852 "Key-chain management\n"
853 "Key-chain name\n")
854{
855 vty->node = KEYCHAIN_NODE;
856 return CMD_SUCCESS;
857}
858
859DEFUNSH (VTYSH_RIPD,
860 key,
861 key_cmd,
862 "key <0-2147483647>",
863 "Configure a key\n"
864 "Key identifier number\n")
865{
866 vty->node = KEYCHAIN_KEY_NODE;
867 return CMD_SUCCESS;
868}
869
870DEFUNSH (VTYSH_RIPD,
871 router_rip,
872 router_rip_cmd,
873 "router rip",
874 ROUTER_STR
875 "RIP")
876{
877 vty->node = RIP_NODE;
878 return CMD_SUCCESS;
879}
880
881DEFUNSH (VTYSH_RIPNGD,
882 router_ripng,
883 router_ripng_cmd,
884 "router ripng",
885 ROUTER_STR
886 "RIPng")
887{
888 vty->node = RIPNG_NODE;
889 return CMD_SUCCESS;
890}
891
892DEFUNSH (VTYSH_OSPFD,
893 router_ospf,
894 router_ospf_cmd,
895 "router ospf",
896 "Enable a routing process\n"
897 "Start OSPF configuration\n")
898{
899 vty->node = OSPF_NODE;
900 return CMD_SUCCESS;
901}
902
903DEFUNSH (VTYSH_OSPF6D,
904 router_ospf6,
905 router_ospf6_cmd,
906 "router ospf6",
907 OSPF6_ROUTER_STR
908 OSPF6_STR)
909{
910 vty->node = OSPF6_NODE;
911 return CMD_SUCCESS;
912}
913
hassoc25e4582003-12-23 10:39:08 +0000914DEFUNSH (VTYSH_ISISD,
hassob094d262004-08-25 12:22:00 +0000915 router_isis,
916 router_isis_cmd,
917 "router isis WORD",
918 ROUTER_STR
919 "ISO IS-IS\n"
920 "ISO Routing area tag")
hassoc25e4582003-12-23 10:39:08 +0000921{
922 vty->node = ISIS_NODE;
923 return CMD_SUCCESS;
924}
925
paul718e3742002-12-13 20:15:29 +0000926DEFUNSH (VTYSH_RMAP,
927 route_map,
928 route_map_cmd,
929 "route-map WORD (deny|permit) <1-65535>",
930 "Create route-map or enter route-map command mode\n"
931 "Route map tag\n"
932 "Route map denies set operations\n"
933 "Route map permits set operations\n"
934 "Sequence to insert to/delete from existing route-map entry\n")
935{
936 vty->node = RMAP_NODE;
937 return CMD_SUCCESS;
938}
939
paul718e3742002-12-13 20:15:29 +0000940DEFUNSH (VTYSH_ALL,
941 vtysh_enable,
942 vtysh_enable_cmd,
943 "enable",
944 "Turn on privileged mode command\n")
945{
946 vty->node = ENABLE_NODE;
947 return CMD_SUCCESS;
948}
949
paul718e3742002-12-13 20:15:29 +0000950DEFUNSH (VTYSH_ALL,
951 vtysh_disable,
952 vtysh_disable_cmd,
953 "disable",
954 "Turn off privileged mode command\n")
955{
956 if (vty->node == ENABLE_NODE)
957 vty->node = VIEW_NODE;
958 return CMD_SUCCESS;
959}
960
paul718e3742002-12-13 20:15:29 +0000961DEFUNSH (VTYSH_ALL,
962 vtysh_config_terminal,
963 vtysh_config_terminal_cmd,
964 "configure terminal",
965 "Configuration from vty interface\n"
966 "Configuration terminal\n")
967{
968 vty->node = CONFIG_NODE;
969 return CMD_SUCCESS;
970}
971
972int
973vtysh_exit (struct vty *vty)
974{
975 switch (vty->node)
976 {
977 case VIEW_NODE:
978 case ENABLE_NODE:
979 exit (0);
980 break;
981 case CONFIG_NODE:
982 vty->node = ENABLE_NODE;
983 break;
984 case INTERFACE_NODE:
985 case ZEBRA_NODE:
986 case BGP_NODE:
987 case RIP_NODE:
988 case RIPNG_NODE:
989 case OSPF_NODE:
990 case OSPF6_NODE:
hassoc25e4582003-12-23 10:39:08 +0000991 case ISIS_NODE:
paul718e3742002-12-13 20:15:29 +0000992 case MASC_NODE:
993 case RMAP_NODE:
994 case VTY_NODE:
995 case KEYCHAIN_NODE:
hasso2a56df92004-05-09 23:16:40 +0000996 vtysh_execute("end");
997 vtysh_execute("configure terminal");
paul718e3742002-12-13 20:15:29 +0000998 vty->node = CONFIG_NODE;
999 break;
1000 case BGP_VPNV4_NODE:
1001 case BGP_IPV4_NODE:
1002 case BGP_IPV4M_NODE:
1003 case BGP_IPV6_NODE:
1004 vty->node = BGP_NODE;
1005 break;
1006 case KEYCHAIN_KEY_NODE:
1007 vty->node = KEYCHAIN_NODE;
1008 break;
1009 default:
1010 break;
1011 }
1012 return CMD_SUCCESS;
1013}
1014
1015DEFUNSH (VTYSH_ALL,
1016 vtysh_exit_all,
1017 vtysh_exit_all_cmd,
1018 "exit",
1019 "Exit current mode and down to previous mode\n")
1020{
1021 return vtysh_exit (vty);
1022}
1023
1024ALIAS (vtysh_exit_all,
1025 vtysh_quit_all_cmd,
1026 "quit",
1027 "Exit current mode and down to previous mode\n")
1028
1029DEFUNSH (VTYSH_BGPD,
1030 exit_address_family,
1031 exit_address_family_cmd,
1032 "exit-address-family",
1033 "Exit from Address Family configuration mode\n")
1034{
1035 if (vty->node == BGP_IPV4_NODE
1036 || vty->node == BGP_IPV4M_NODE
1037 || vty->node == BGP_VPNV4_NODE
1038 || vty->node == BGP_IPV6_NODE)
1039 vty->node = BGP_NODE;
1040 return CMD_SUCCESS;
1041}
1042
1043DEFUNSH (VTYSH_ZEBRA,
1044 vtysh_exit_zebra,
1045 vtysh_exit_zebra_cmd,
1046 "exit",
1047 "Exit current mode and down to previous mode\n")
1048{
1049 return vtysh_exit (vty);
1050}
1051
1052ALIAS (vtysh_exit_zebra,
1053 vtysh_quit_zebra_cmd,
1054 "quit",
1055 "Exit current mode and down to previous mode\n")
1056
1057DEFUNSH (VTYSH_RIPD,
1058 vtysh_exit_ripd,
1059 vtysh_exit_ripd_cmd,
1060 "exit",
1061 "Exit current mode and down to previous mode\n")
1062{
1063 return vtysh_exit (vty);
1064}
1065
1066ALIAS (vtysh_exit_ripd,
1067 vtysh_quit_ripd_cmd,
1068 "quit",
1069 "Exit current mode and down to previous mode\n")
1070
paul68980082003-03-25 05:07:42 +00001071DEFUNSH (VTYSH_RIPNGD,
hassob094d262004-08-25 12:22:00 +00001072 vtysh_exit_ripngd,
1073 vtysh_exit_ripngd_cmd,
1074 "exit",
1075 "Exit current mode and down to previous mode\n")
paul68980082003-03-25 05:07:42 +00001076{
1077 return vtysh_exit (vty);
1078}
1079
1080ALIAS (vtysh_exit_ripngd,
1081 vtysh_quit_ripngd_cmd,
1082 "quit",
1083 "Exit current mode and down to previous mode\n")
1084
paul718e3742002-12-13 20:15:29 +00001085DEFUNSH (VTYSH_RMAP,
1086 vtysh_exit_rmap,
1087 vtysh_exit_rmap_cmd,
1088 "exit",
1089 "Exit current mode and down to previous mode\n")
1090{
1091 return vtysh_exit (vty);
1092}
1093
1094ALIAS (vtysh_exit_rmap,
1095 vtysh_quit_rmap_cmd,
1096 "quit",
1097 "Exit current mode and down to previous mode\n")
1098
1099DEFUNSH (VTYSH_BGPD,
1100 vtysh_exit_bgpd,
1101 vtysh_exit_bgpd_cmd,
1102 "exit",
1103 "Exit current mode and down to previous mode\n")
1104{
1105 return vtysh_exit (vty);
1106}
1107
1108ALIAS (vtysh_exit_bgpd,
1109 vtysh_quit_bgpd_cmd,
1110 "quit",
1111 "Exit current mode and down to previous mode\n")
1112
1113DEFUNSH (VTYSH_OSPFD,
1114 vtysh_exit_ospfd,
1115 vtysh_exit_ospfd_cmd,
1116 "exit",
1117 "Exit current mode and down to previous mode\n")
1118{
1119 return vtysh_exit (vty);
1120}
1121
1122ALIAS (vtysh_exit_ospfd,
1123 vtysh_quit_ospfd_cmd,
1124 "quit",
1125 "Exit current mode and down to previous mode\n")
1126
paul68980082003-03-25 05:07:42 +00001127DEFUNSH (VTYSH_OSPF6D,
hassob094d262004-08-25 12:22:00 +00001128 vtysh_exit_ospf6d,
1129 vtysh_exit_ospf6d_cmd,
1130 "exit",
1131 "Exit current mode and down to previous mode\n")
paul68980082003-03-25 05:07:42 +00001132{
1133 return vtysh_exit (vty);
1134}
1135
1136ALIAS (vtysh_exit_ospf6d,
1137 vtysh_quit_ospf6d_cmd,
1138 "quit",
1139 "Exit current mode and down to previous mode\n")
1140
hassoc25e4582003-12-23 10:39:08 +00001141DEFUNSH (VTYSH_ISISD,
hassob094d262004-08-25 12:22:00 +00001142 vtysh_exit_isisd,
1143 vtysh_exit_isisd_cmd,
1144 "exit",
1145 "Exit current mode and down to previous mode\n")
hassoc25e4582003-12-23 10:39:08 +00001146{
1147 return vtysh_exit (vty);
1148}
1149
1150ALIAS (vtysh_exit_isisd,
1151 vtysh_quit_isisd_cmd,
1152 "quit",
1153 "Exit current mode and down to previous mode\n")
1154
hasso95e735b2004-08-26 13:08:30 +00001155DEFUNSH (VTYSH_INTERFACE,
paul718e3742002-12-13 20:15:29 +00001156 vtysh_interface,
1157 vtysh_interface_cmd,
1158 "interface IFNAME",
1159 "Select an interface to configure\n"
1160 "Interface's name\n")
1161{
1162 vty->node = INTERFACE_NODE;
1163 return CMD_SUCCESS;
1164}
1165
hasso95e735b2004-08-26 13:08:30 +00001166/* TODO Implement "no interface command in isisd. */
paul32d24632003-05-23 09:25:20 +00001167DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D,
1168 vtysh_no_interface_cmd,
1169 "no interface IFNAME",
1170 NO_STR
1171 "Delete a pseudo interface's configuration\n"
1172 "Interface's name\n")
1173
hasso95e735b2004-08-26 13:08:30 +00001174/* TODO Implement interface description commands in ripngd, ospf6d
1175 * and isisd. */
paul338a9912003-03-01 15:44:10 +00001176DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1177 interface_desc_cmd,
1178 "description .LINE",
1179 "Interface specific description\n"
1180 "Characters describing this interface\n")
paul464dc8d2003-03-28 02:25:45 +00001181
1182DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1183 no_interface_desc_cmd,
1184 "no description",
1185 NO_STR
1186 "Interface specific description\n")
paul338a9912003-03-01 15:44:10 +00001187
hasso95e735b2004-08-26 13:08:30 +00001188DEFUNSH (VTYSH_INTERFACE,
paul718e3742002-12-13 20:15:29 +00001189 vtysh_exit_interface,
1190 vtysh_exit_interface_cmd,
1191 "exit",
1192 "Exit current mode and down to previous mode\n")
1193{
1194 return vtysh_exit (vty);
1195}
1196
1197ALIAS (vtysh_exit_interface,
1198 vtysh_quit_interface_cmd,
1199 "quit",
1200 "Exit current mode and down to previous mode\n")
1201
hasso95e735b2004-08-26 13:08:30 +00001202/* Logging commands. */
1203DEFUNSH (VTYSH_ALL,
1204 vtysh_log_stdout,
1205 vtysh_log_stdout_cmd,
1206 "log stdout",
1207 "Logging control\n"
1208 "Logging goes to stdout\n")
1209{
1210 return CMD_SUCCESS;
1211}
1212
1213DEFUNSH (VTYSH_ALL,
1214 no_vtysh_log_stdout,
1215 no_vtysh_log_stdout_cmd,
1216 "no log stdout",
1217 NO_STR
1218 "Logging control\n"
1219 "Logging goes to stdout\n")
1220{
1221 return CMD_SUCCESS;
1222}
1223
1224DEFUNSH (VTYSH_ALL,
1225 vtysh_log_file,
1226 vtysh_log_file_cmd,
1227 "log file FILENAME",
1228 "Logging control\n"
1229 "Logging to file\n"
1230 "Logging filename\n")
1231{
1232 return CMD_SUCCESS;
1233}
1234
1235DEFUNSH (VTYSH_ALL,
1236 no_vtysh_log_file,
1237 no_vtysh_log_file_cmd,
1238 "no log file [FILENAME]",
1239 NO_STR
1240 "Logging control\n"
1241 "Cancel logging to file\n"
1242 "Logging file name\n")
1243{
1244 return CMD_SUCCESS;
1245}
1246
1247DEFUNSH (VTYSH_ALL,
1248 vtysh_log_syslog,
1249 vtysh_log_syslog_cmd,
1250 "log syslog",
1251 "Logging control\n"
1252 "Logging goes to syslog\n")
1253{
1254 return CMD_SUCCESS;
1255}
1256
1257DEFUNSH (VTYSH_ALL,
1258 no_vtysh_log_syslog,
1259 no_vtysh_log_syslog_cmd,
1260 "no log syslog",
1261 NO_STR
1262 "Logging control\n"
1263 "Cancel logging to syslog\n")
1264{
1265 return CMD_SUCCESS;
1266}
1267
1268DEFUNSH (VTYSH_ALL,
1269 vtysh_log_trap,
1270 vtysh_log_trap_cmd,
1271 "log trap (emergencies|alerts|critical|errors|warnings|\
1272 notifications|informational|debugging)",
1273 "Logging control\n"
1274 "Limit logging to specifed level\n")
1275{
1276 return CMD_SUCCESS;
1277}
1278
1279DEFUNSH (VTYSH_ALL,
1280 no_vtysh_log_trap,
1281 no_vtysh_log_trap_cmd,
1282 "no log trap",
1283 NO_STR
1284 "Logging control\n"
1285 "Permit all logging information\n")
1286{
1287 return CMD_SUCCESS;
1288}
1289
1290DEFUNSH (VTYSH_ALL,
1291 vtysh_log_record_priority,
1292 vtysh_log_record_priority_cmd,
1293 "log record-priority",
1294 "Logging control\n"
1295 "Log the priority of the message within the message\n")
1296{
1297 return CMD_SUCCESS;
1298}
1299
1300DEFUNSH (VTYSH_ALL,
1301 no_vtysh_log_record_priority,
1302 no_vtysh_log_record_priority_cmd,
1303 "no log record-priority",
1304 NO_STR
1305 "Logging control\n"
1306 "Do not log the priority of the message within the message\n")
1307{
1308 return CMD_SUCCESS;
1309}
1310
paul718e3742002-12-13 20:15:29 +00001311DEFUN (vtysh_write_terminal,
1312 vtysh_write_terminal_cmd,
1313 "write terminal",
1314 "Write running configuration to memory, network, or terminal\n"
1315 "Write to terminal\n")
1316{
1317 int ret;
1318 char line[] = "write terminal\n";
1319 FILE *fp = NULL;
1320
1321 if (vtysh_pager_name)
1322 {
paul4fc01e62002-12-13 20:49:00 +00001323 fp = popen (vtysh_pager_name, "w");
paul718e3742002-12-13 20:15:29 +00001324 if (fp == NULL)
1325 {
1326 perror ("popen");
1327 exit (1);
1328 }
1329 }
1330 else
1331 fp = stdout;
1332
1333 vty_out (vty, "Building configuration...%s", VTY_NEWLINE);
1334 vty_out (vty, "%sCurrent configuration:%s", VTY_NEWLINE,
1335 VTY_NEWLINE);
1336
1337 vtysh_config_write (fp);
1338
1339 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_ZEBRA], line);
1340 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_RIP], line);
1341 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_RIPNG], line);
1342 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_OSPF], line);
1343 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_OSPF6], line);
1344 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_BGP], line);
hassoc25e4582003-12-23 10:39:08 +00001345 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_ISIS], line);
paul718e3742002-12-13 20:15:29 +00001346
1347 vtysh_config_dump (fp);
1348
1349 if (vtysh_pager_name && fp)
1350 {
1351 fflush (fp);
1352 if (pclose (fp) == -1)
1353 {
1354 perror ("pclose");
1355 exit (1);
1356 }
1357 fp = NULL;
1358 }
1359
1360 return CMD_SUCCESS;
1361}
1362
paul4fc01e62002-12-13 20:49:00 +00001363struct vtysh_writeconfig_t {
1364 int daemon;
1365 int integrated;
1366} vtysh_wc = {-1,0};
1367
1368DEFUN (vtysh_write_config,
hassob094d262004-08-25 12:22:00 +00001369 vtysh_write_config_cmd,
1370 "write-config (daemon|integrated)",
1371 "Specify config files to write to\n"
1372 "Write per daemon file\n"
hasso95e735b2004-08-26 13:08:30 +00001373 "Write integrated file\n")
paul4fc01e62002-12-13 20:49:00 +00001374{
hasso95e735b2004-08-26 13:08:30 +00001375 if (!strncmp(argv[0],"d",1))
1376 vtysh_wc.daemon = 1;
1377 else if (!strncmp(argv[0],"i",1))
1378 vtysh_wc.integrated = 1;
1379
paul4fc01e62002-12-13 20:49:00 +00001380 return CMD_SUCCESS;
1381}
1382
1383DEFUN (no_vtysh_write_config,
hassob094d262004-08-25 12:22:00 +00001384 no_vtysh_write_config_cmd,
1385 "no write-config (daemon|integrated)",
hasso95e735b2004-08-26 13:08:30 +00001386 "Negate per daemon and/or integrated config files\n")
paul4fc01e62002-12-13 20:49:00 +00001387{
hasso95e735b2004-08-26 13:08:30 +00001388 if (!strncmp(argv[0],"d",1))
1389 vtysh_wc.daemon = 0;
1390 else if (!strncmp(argv[0],"i",1))
1391 vtysh_wc.integrated = 0;
1392
paul4fc01e62002-12-13 20:49:00 +00001393 return CMD_SUCCESS;
1394}
1395
1396int write_config_integrated(void)
paul718e3742002-12-13 20:15:29 +00001397{
1398 int ret;
paul718e3742002-12-13 20:15:29 +00001399 char line[] = "write terminal\n";
1400 FILE *fp;
1401 char *integrate_sav = NULL;
1402
hasso95e735b2004-08-26 13:08:30 +00001403 integrate_sav = malloc (strlen (integrate_default) +
1404 strlen (CONF_BACKUP_EXT) + 1);
paul718e3742002-12-13 20:15:29 +00001405 strcpy (integrate_sav, integrate_default);
1406 strcat (integrate_sav, CONF_BACKUP_EXT);
1407
paul4fc01e62002-12-13 20:49:00 +00001408 fprintf (stdout,"Building Configuration...\n");
paul718e3742002-12-13 20:15:29 +00001409
hasso95e735b2004-08-26 13:08:30 +00001410 /* Move current configuration file to backup config file. */
paul718e3742002-12-13 20:15:29 +00001411 unlink (integrate_sav);
1412 rename (integrate_default, integrate_sav);
hasso95e735b2004-08-26 13:08:30 +00001413 free (integrate_sav);
paul4fc01e62002-12-13 20:49:00 +00001414
paul718e3742002-12-13 20:15:29 +00001415 fp = fopen (integrate_default, "w");
1416 if (fp == NULL)
1417 {
hasso95e735b2004-08-26 13:08:30 +00001418 fprintf (stdout,"%% Can't open configuration file %s.\n",
1419 integrate_default);
paul718e3742002-12-13 20:15:29 +00001420 return CMD_SUCCESS;
1421 }
paul718e3742002-12-13 20:15:29 +00001422
1423 vtysh_config_write (fp);
1424
1425 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_ZEBRA], line);
1426 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_RIP], line);
1427 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_RIPNG], line);
1428 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_OSPF], line);
1429 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_OSPF6], line);
1430 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_BGP], line);
hassoc25e4582003-12-23 10:39:08 +00001431 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_ISIS], line);
paul718e3742002-12-13 20:15:29 +00001432
1433 vtysh_config_dump (fp);
1434
1435 fclose (fp);
1436
gdtaa593d52003-12-22 20:15:53 +00001437 if (chmod (integrate_default, CONFIGFILE_MASK) != 0)
1438 {
1439 fprintf (stdout,"%% Can't chmod configuration file %s: %s (%d)\n",
1440 integrate_default, strerror(errno), errno);
1441 return CMD_WARNING;
1442 }
1443
paul4fc01e62002-12-13 20:49:00 +00001444 fprintf(stdout,"Integrated configuration saved to %s\n",integrate_default);
1445
1446 fprintf (stdout,"[OK]\n");
1447
paul718e3742002-12-13 20:15:29 +00001448 return CMD_SUCCESS;
1449}
1450
paul4fc01e62002-12-13 20:49:00 +00001451DEFUN (vtysh_write_memory,
1452 vtysh_write_memory_cmd,
1453 "write memory",
1454 "Write running configuration to memory, network, or terminal\n"
1455 "Write configuration to the file (same as write file)\n")
1456{
pauldfc0d9b2003-04-18 23:55:29 +00001457 int ret = CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001458 char line[] = "write memory\n";
1459
hasso95e735b2004-08-26 13:08:30 +00001460 /* If integrated Zebra.conf explicitely set. */
1461 if (vtysh_wc.integrated == 1)
1462 ret = write_config_integrated();
paul4fc01e62002-12-13 20:49:00 +00001463
hasso95e735b2004-08-26 13:08:30 +00001464 if (!vtysh_wc.daemon)
1465 return ret;
paul4fc01e62002-12-13 20:49:00 +00001466
1467 fprintf (stdout,"Building Configuration...\n");
1468
1469 ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ZEBRA], line, stdout);
1470 ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIP], line, stdout);
1471 ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIPNG], line, stdout);
1472 ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF], line, stdout);
1473 ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF6], line, stdout);
1474 ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_BGP], line, stdout);
hassoc25e4582003-12-23 10:39:08 +00001475 ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ISIS], line, stdout);
paul4fc01e62002-12-13 20:49:00 +00001476
1477 fprintf (stdout,"[OK]\n");
1478
pauldfc0d9b2003-04-18 23:55:29 +00001479 return ret;
paul4fc01e62002-12-13 20:49:00 +00001480}
1481
paul718e3742002-12-13 20:15:29 +00001482ALIAS (vtysh_write_memory,
1483 vtysh_copy_runningconfig_startupconfig_cmd,
1484 "copy running-config startup-config",
1485 "Copy from one file to another\n"
1486 "Copy from current system configuration\n"
1487 "Copy to startup configuration\n")
1488
1489ALIAS (vtysh_write_memory,
1490 vtysh_write_file_cmd,
1491 "write file",
1492 "Write running configuration to memory, network, or terminal\n"
1493 "Write configuration to the file (same as write memory)\n")
1494
hasso4a6e2252003-05-25 11:51:29 +00001495ALIAS (vtysh_write_memory,
1496 vtysh_write_cmd,
1497 "write",
1498 "Write running configuration to memory, network, or terminal\n")
1499
paul718e3742002-12-13 20:15:29 +00001500ALIAS (vtysh_write_terminal,
1501 vtysh_show_running_config_cmd,
1502 "show running-config",
1503 SHOW_STR
1504 "Current operating configuration\n")
hassob094d262004-08-25 12:22:00 +00001505
paul718e3742002-12-13 20:15:29 +00001506/* Execute command in child process. */
1507int
1508execute_command (char *command, int argc, char *arg1, char *arg2)
1509{
1510 int ret;
1511 pid_t pid;
1512 int status;
1513
1514 /* Call fork(). */
1515 pid = fork ();
1516
1517 if (pid < 0)
1518 {
1519 /* Failure of fork(). */
1520 fprintf (stderr, "Can't fork: %s\n", strerror (errno));
1521 exit (1);
1522 }
1523 else if (pid == 0)
1524 {
1525 /* This is child process. */
1526 switch (argc)
1527 {
1528 case 0:
hassofa2b17e2004-03-04 17:45:00 +00001529 ret = execlp (command, command, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00001530 break;
1531 case 1:
hassofa2b17e2004-03-04 17:45:00 +00001532 ret = execlp (command, command, arg1, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00001533 break;
1534 case 2:
hassofa2b17e2004-03-04 17:45:00 +00001535 ret = execlp (command, command, arg1, arg2, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00001536 break;
1537 }
1538
1539 /* When execlp suceed, this part is not executed. */
1540 fprintf (stderr, "Can't execute %s: %s\n", command, strerror (errno));
1541 exit (1);
1542 }
1543 else
1544 {
1545 /* This is parent. */
1546 execute_flag = 1;
1547 ret = wait4 (pid, &status, 0, NULL);
1548 execute_flag = 0;
1549 }
1550 return 0;
1551}
1552
1553DEFUN (vtysh_ping,
1554 vtysh_ping_cmd,
1555 "ping WORD",
hasso4eeccf12003-06-25 10:49:55 +00001556 "Send echo messages\n"
paul718e3742002-12-13 20:15:29 +00001557 "Ping destination address or hostname\n")
1558{
1559 execute_command ("ping", 1, argv[0], NULL);
1560 return CMD_SUCCESS;
1561}
1562
hasso4eeccf12003-06-25 10:49:55 +00001563ALIAS (vtysh_ping,
1564 vtysh_ping_ip_cmd,
1565 "ping ip WORD",
1566 "Send echo messages\n"
1567 "IP echo\n"
1568 "Ping destination address or hostname\n")
1569
paul718e3742002-12-13 20:15:29 +00001570DEFUN (vtysh_traceroute,
1571 vtysh_traceroute_cmd,
1572 "traceroute WORD",
1573 "Trace route to destination\n"
1574 "Trace route to destination address or hostname\n")
1575{
1576 execute_command ("traceroute", 1, argv[0], NULL);
1577 return CMD_SUCCESS;
1578}
1579
hasso4eeccf12003-06-25 10:49:55 +00001580ALIAS (vtysh_traceroute,
1581 vtysh_traceroute_ip_cmd,
1582 "traceroute ip WORD",
1583 "Trace route to destination\n"
1584 "IP trace\n"
1585 "Trace route to destination address or hostname\n")
1586
1587#ifdef HAVE_IPV6
1588DEFUN (vtysh_ping6,
1589 vtysh_ping6_cmd,
1590 "ping ipv6 WORD",
1591 "Send echo messages\n"
1592 "IPv6 echo\n"
1593 "Ping destination address or hostname\n")
1594{
1595 execute_command ("ping6", 1, argv[0], NULL);
1596 return CMD_SUCCESS;
1597}
1598
1599DEFUN (vtysh_traceroute6,
1600 vtysh_traceroute6_cmd,
1601 "traceroute ipv6 WORD",
1602 "Trace route to destination\n"
1603 "IPv6 trace\n"
1604 "Trace route to destination address or hostname\n")
1605{
1606 execute_command ("traceroute6", 1, argv[0], NULL);
1607 return CMD_SUCCESS;
1608}
1609#endif
1610
paul718e3742002-12-13 20:15:29 +00001611DEFUN (vtysh_telnet,
1612 vtysh_telnet_cmd,
1613 "telnet WORD",
1614 "Open a telnet connection\n"
1615 "IP address or hostname of a remote system\n")
1616{
1617 execute_command ("telnet", 1, argv[0], NULL);
1618 return CMD_SUCCESS;
1619}
1620
1621DEFUN (vtysh_telnet_port,
1622 vtysh_telnet_port_cmd,
1623 "telnet WORD PORT",
1624 "Open a telnet connection\n"
1625 "IP address or hostname of a remote system\n"
1626 "TCP Port number\n")
1627{
1628 execute_command ("telnet", 2, argv[0], argv[1]);
1629 return CMD_SUCCESS;
1630}
1631
paul5087df52003-01-25 06:56:09 +00001632DEFUN (vtysh_ssh,
1633 vtysh_ssh_cmd,
1634 "ssh WORD",
1635 "Open an ssh connection\n"
1636 "[user@]host\n")
1637{
1638 execute_command ("ssh", 1, argv[0], NULL);
1639 return CMD_SUCCESS;
1640}
1641
paul718e3742002-12-13 20:15:29 +00001642DEFUN (vtysh_start_shell,
1643 vtysh_start_shell_cmd,
1644 "start-shell",
1645 "Start UNIX shell\n")
1646{
1647 execute_command ("sh", 0, NULL, NULL);
1648 return CMD_SUCCESS;
1649}
1650
1651DEFUN (vtysh_start_bash,
1652 vtysh_start_bash_cmd,
1653 "start-shell bash",
1654 "Start UNIX shell\n"
1655 "Start bash\n")
1656{
1657 execute_command ("bash", 0, NULL, NULL);
1658 return CMD_SUCCESS;
1659}
1660
1661DEFUN (vtysh_start_zsh,
1662 vtysh_start_zsh_cmd,
1663 "start-shell zsh",
1664 "Start UNIX shell\n"
1665 "Start Z shell\n")
1666{
1667 execute_command ("zsh", 0, NULL, NULL);
1668 return CMD_SUCCESS;
1669}
hassob094d262004-08-25 12:22:00 +00001670
paul718e3742002-12-13 20:15:29 +00001671void
1672vtysh_install_default (enum node_type node)
1673{
1674 install_element (node, &config_list_cmd);
1675}
1676
1677/* Making connection to protocol daemon. */
1678int
1679vtysh_connect (struct vtysh_client *vclient, char *path)
1680{
1681 int ret;
1682 int sock, len;
1683 struct sockaddr_un addr;
1684 struct stat s_stat;
1685 uid_t euid;
1686 gid_t egid;
1687
1688 memset (vclient, 0, sizeof (struct vtysh_client));
1689 vclient->fd = -1;
1690
1691 /* Stat socket to see if we have permission to access it. */
1692 euid = geteuid();
1693 egid = getegid();
1694 ret = stat (path, &s_stat);
1695 if (ret < 0 && errno != ENOENT)
1696 {
1697 fprintf (stderr, "vtysh_connect(%s): stat = %s\n",
1698 path, strerror(errno));
1699 exit(1);
1700 }
1701
1702 if (ret >= 0)
1703 {
1704 if (! S_ISSOCK(s_stat.st_mode))
1705 {
1706 fprintf (stderr, "vtysh_connect(%s): Not a socket\n",
1707 path);
1708 exit (1);
1709 }
1710
paul718e3742002-12-13 20:15:29 +00001711 }
1712
1713 sock = socket (AF_UNIX, SOCK_STREAM, 0);
1714 if (sock < 0)
1715 {
1716#ifdef DEBUG
hasso95e735b2004-08-26 13:08:30 +00001717 fprintf(stderr, "vtysh_connect(%s): socket = %s\n", path,
1718 strerror(errno));
paul718e3742002-12-13 20:15:29 +00001719#endif /* DEBUG */
1720 return -1;
1721 }
1722
1723 memset (&addr, 0, sizeof (struct sockaddr_un));
1724 addr.sun_family = AF_UNIX;
1725 strncpy (addr.sun_path, path, strlen (path));
1726#ifdef HAVE_SUN_LEN
1727 len = addr.sun_len = SUN_LEN(&addr);
1728#else
1729 len = sizeof (addr.sun_family) + strlen (addr.sun_path);
1730#endif /* HAVE_SUN_LEN */
1731
1732 ret = connect (sock, (struct sockaddr *) &addr, len);
1733 if (ret < 0)
1734 {
1735#ifdef DEBUG
hasso95e735b2004-08-26 13:08:30 +00001736 fprintf(stderr, "vtysh_connect(%s): connect = %s\n", path,
1737 strerror(errno));
paul718e3742002-12-13 20:15:29 +00001738#endif /* DEBUG */
1739 close (sock);
1740 return -1;
1741 }
1742 vclient->fd = sock;
1743
1744 return 0;
1745}
1746
1747void
1748vtysh_connect_all()
1749{
1750 /* Clear each daemons client structure. */
paulfe067782003-04-07 16:10:05 +00001751 vtysh_connect (&vtysh_client[VTYSH_INDEX_ZEBRA], ZEBRA_VTYSH_PATH);
1752 vtysh_connect (&vtysh_client[VTYSH_INDEX_RIP], RIP_VTYSH_PATH);
1753 vtysh_connect (&vtysh_client[VTYSH_INDEX_RIPNG], RIPNG_VTYSH_PATH);
1754 vtysh_connect (&vtysh_client[VTYSH_INDEX_OSPF], OSPF_VTYSH_PATH);
1755 vtysh_connect (&vtysh_client[VTYSH_INDEX_OSPF6], OSPF6_VTYSH_PATH);
1756 vtysh_connect (&vtysh_client[VTYSH_INDEX_BGP], BGP_VTYSH_PATH);
hassoc25e4582003-12-23 10:39:08 +00001757 vtysh_connect (&vtysh_client[VTYSH_INDEX_ISIS], ISIS_VTYSH_PATH);
paul718e3742002-12-13 20:15:29 +00001758}
1759
hasso95e735b2004-08-26 13:08:30 +00001760/* To disable readline's filename completion. */
pauldfc0d9b2003-04-18 23:55:29 +00001761char *
1762vtysh_completion_entry_function (const char *ignore, int invoking_key)
paul718e3742002-12-13 20:15:29 +00001763{
pauldfc0d9b2003-04-18 23:55:29 +00001764 return NULL;
paul718e3742002-12-13 20:15:29 +00001765}
1766
1767void
1768vtysh_readline_init ()
1769{
1770 /* readline related settings. */
1771 rl_bind_key ('?', vtysh_rl_describe);
paul68980082003-03-25 05:07:42 +00001772 rl_completion_entry_function = vtysh_completion_entry_function;
paul718e3742002-12-13 20:15:29 +00001773 rl_attempted_completion_function = (CPPFunction *)new_completion;
1774 /* do not append space after completion. It will be appended
hasso95e735b2004-08-26 13:08:30 +00001775 * in new_completion() function explicitly. */
paul718e3742002-12-13 20:15:29 +00001776 rl_completion_append_character = '\0';
1777}
1778
1779char *
1780vtysh_prompt ()
1781{
1782 struct utsname names;
1783 static char buf[100];
1784 const char*hostname;
1785 extern struct host host;
1786
1787 hostname = host.name;
1788
1789 if (!hostname)
1790 {
1791 uname (&names);
1792 hostname = names.nodename;
1793 }
1794
1795 snprintf (buf, sizeof buf, cmd_prompt (vty->node), hostname);
1796
1797 return buf;
1798}
1799
1800void
1801vtysh_init_vty ()
1802{
1803 /* Make vty structure. */
1804 vty = vty_new ();
1805 vty->type = VTY_SHELL;
1806 vty->node = VIEW_NODE;
1807
1808 /* Initialize commands. */
1809 cmd_init (0);
1810
1811 /* Install nodes. */
1812 install_node (&bgp_node, NULL);
1813 install_node (&rip_node, NULL);
1814 install_node (&interface_node, NULL);
1815 install_node (&rmap_node, NULL);
1816 install_node (&zebra_node, NULL);
1817 install_node (&bgp_vpnv4_node, NULL);
1818 install_node (&bgp_ipv4_node, NULL);
1819 install_node (&bgp_ipv4m_node, NULL);
1820/* #ifdef HAVE_IPV6 */
1821 install_node (&bgp_ipv6_node, NULL);
1822/* #endif */
1823 install_node (&ospf_node, NULL);
1824/* #ifdef HAVE_IPV6 */
1825 install_node (&ripng_node, NULL);
1826 install_node (&ospf6_node, NULL);
1827/* #endif */
1828 install_node (&keychain_node, NULL);
1829 install_node (&keychain_key_node, NULL);
hassoc25e4582003-12-23 10:39:08 +00001830 install_node (&isis_node, NULL);
paul718e3742002-12-13 20:15:29 +00001831
1832 vtysh_install_default (VIEW_NODE);
1833 vtysh_install_default (ENABLE_NODE);
1834 vtysh_install_default (CONFIG_NODE);
1835 vtysh_install_default (BGP_NODE);
1836 vtysh_install_default (RIP_NODE);
1837 vtysh_install_default (INTERFACE_NODE);
1838 vtysh_install_default (RMAP_NODE);
1839 vtysh_install_default (ZEBRA_NODE);
1840 vtysh_install_default (BGP_VPNV4_NODE);
1841 vtysh_install_default (BGP_IPV4_NODE);
1842 vtysh_install_default (BGP_IPV4M_NODE);
1843 vtysh_install_default (BGP_IPV6_NODE);
1844 vtysh_install_default (OSPF_NODE);
1845 vtysh_install_default (RIPNG_NODE);
1846 vtysh_install_default (OSPF6_NODE);
hassoc25e4582003-12-23 10:39:08 +00001847 vtysh_install_default (ISIS_NODE);
paul718e3742002-12-13 20:15:29 +00001848 vtysh_install_default (KEYCHAIN_NODE);
1849 vtysh_install_default (KEYCHAIN_KEY_NODE);
1850
1851 install_element (VIEW_NODE, &vtysh_enable_cmd);
1852 install_element (ENABLE_NODE, &vtysh_config_terminal_cmd);
1853 install_element (ENABLE_NODE, &vtysh_disable_cmd);
1854
1855 /* "exit" command. */
1856 install_element (VIEW_NODE, &vtysh_exit_all_cmd);
1857 install_element (VIEW_NODE, &vtysh_quit_all_cmd);
1858 install_element (CONFIG_NODE, &vtysh_exit_all_cmd);
1859 /* install_element (CONFIG_NODE, &vtysh_quit_all_cmd); */
1860 install_element (ENABLE_NODE, &vtysh_exit_all_cmd);
1861 install_element (ENABLE_NODE, &vtysh_quit_all_cmd);
1862 install_element (RIP_NODE, &vtysh_exit_ripd_cmd);
1863 install_element (RIP_NODE, &vtysh_quit_ripd_cmd);
paul68980082003-03-25 05:07:42 +00001864 install_element (RIPNG_NODE, &vtysh_exit_ripngd_cmd);
1865 install_element (RIPNG_NODE, &vtysh_quit_ripngd_cmd);
paul718e3742002-12-13 20:15:29 +00001866 install_element (OSPF_NODE, &vtysh_exit_ospfd_cmd);
1867 install_element (OSPF_NODE, &vtysh_quit_ospfd_cmd);
paul68980082003-03-25 05:07:42 +00001868 install_element (OSPF6_NODE, &vtysh_exit_ospf6d_cmd);
1869 install_element (OSPF6_NODE, &vtysh_quit_ospf6d_cmd);
paul718e3742002-12-13 20:15:29 +00001870 install_element (BGP_NODE, &vtysh_exit_bgpd_cmd);
1871 install_element (BGP_NODE, &vtysh_quit_bgpd_cmd);
1872 install_element (BGP_VPNV4_NODE, &vtysh_exit_bgpd_cmd);
1873 install_element (BGP_VPNV4_NODE, &vtysh_quit_bgpd_cmd);
1874 install_element (BGP_IPV4_NODE, &vtysh_exit_bgpd_cmd);
1875 install_element (BGP_IPV4_NODE, &vtysh_quit_bgpd_cmd);
1876 install_element (BGP_IPV4M_NODE, &vtysh_exit_bgpd_cmd);
1877 install_element (BGP_IPV4M_NODE, &vtysh_quit_bgpd_cmd);
1878 install_element (BGP_IPV6_NODE, &vtysh_exit_bgpd_cmd);
1879 install_element (BGP_IPV6_NODE, &vtysh_quit_bgpd_cmd);
hassoc25e4582003-12-23 10:39:08 +00001880 install_element (ISIS_NODE, &vtysh_exit_isisd_cmd);
1881 install_element (ISIS_NODE, &vtysh_quit_isisd_cmd);
paul718e3742002-12-13 20:15:29 +00001882 install_element (KEYCHAIN_NODE, &vtysh_exit_ripd_cmd);
1883 install_element (KEYCHAIN_NODE, &vtysh_quit_ripd_cmd);
1884 install_element (KEYCHAIN_KEY_NODE, &vtysh_exit_ripd_cmd);
1885 install_element (KEYCHAIN_KEY_NODE, &vtysh_quit_ripd_cmd);
1886 install_element (RMAP_NODE, &vtysh_exit_rmap_cmd);
1887 install_element (RMAP_NODE, &vtysh_quit_rmap_cmd);
1888
1889 /* "end" command. */
1890 install_element (CONFIG_NODE, &vtysh_end_all_cmd);
1891 install_element (ENABLE_NODE, &vtysh_end_all_cmd);
1892 install_element (RIP_NODE, &vtysh_end_all_cmd);
1893 install_element (RIPNG_NODE, &vtysh_end_all_cmd);
1894 install_element (OSPF_NODE, &vtysh_end_all_cmd);
1895 install_element (OSPF6_NODE, &vtysh_end_all_cmd);
1896 install_element (BGP_NODE, &vtysh_end_all_cmd);
1897 install_element (BGP_IPV4_NODE, &vtysh_end_all_cmd);
1898 install_element (BGP_IPV4M_NODE, &vtysh_end_all_cmd);
1899 install_element (BGP_VPNV4_NODE, &vtysh_end_all_cmd);
1900 install_element (BGP_IPV6_NODE, &vtysh_end_all_cmd);
hassoc25e4582003-12-23 10:39:08 +00001901 install_element (ISIS_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00001902 install_element (KEYCHAIN_NODE, &vtysh_end_all_cmd);
1903 install_element (KEYCHAIN_KEY_NODE, &vtysh_end_all_cmd);
1904 install_element (RMAP_NODE, &vtysh_end_all_cmd);
1905
paul338a9912003-03-01 15:44:10 +00001906 install_element (INTERFACE_NODE, &interface_desc_cmd);
paul464dc8d2003-03-28 02:25:45 +00001907 install_element (INTERFACE_NODE, &no_interface_desc_cmd);
paul718e3742002-12-13 20:15:29 +00001908 install_element (INTERFACE_NODE, &vtysh_end_all_cmd);
1909 install_element (INTERFACE_NODE, &vtysh_exit_interface_cmd);
1910 install_element (INTERFACE_NODE, &vtysh_quit_interface_cmd);
1911 install_element (CONFIG_NODE, &router_rip_cmd);
1912#ifdef HAVE_IPV6
1913 install_element (CONFIG_NODE, &router_ripng_cmd);
1914#endif
1915 install_element (CONFIG_NODE, &router_ospf_cmd);
1916#ifdef HAVE_IPV6
1917 install_element (CONFIG_NODE, &router_ospf6_cmd);
1918#endif
hassoc25e4582003-12-23 10:39:08 +00001919 install_element (CONFIG_NODE, &router_isis_cmd);
paul718e3742002-12-13 20:15:29 +00001920 install_element (CONFIG_NODE, &router_bgp_cmd);
1921 install_element (BGP_NODE, &address_family_vpnv4_cmd);
1922 install_element (BGP_NODE, &address_family_vpnv4_unicast_cmd);
1923 install_element (BGP_NODE, &address_family_ipv4_unicast_cmd);
1924 install_element (BGP_NODE, &address_family_ipv4_multicast_cmd);
1925#ifdef HAVE_IPV6
1926 install_element (BGP_NODE, &address_family_ipv6_cmd);
1927 install_element (BGP_NODE, &address_family_ipv6_unicast_cmd);
1928#endif
1929 install_element (BGP_VPNV4_NODE, &exit_address_family_cmd);
1930 install_element (BGP_IPV4_NODE, &exit_address_family_cmd);
1931 install_element (BGP_IPV4M_NODE, &exit_address_family_cmd);
1932 install_element (BGP_IPV6_NODE, &exit_address_family_cmd);
1933 install_element (CONFIG_NODE, &key_chain_cmd);
1934 install_element (CONFIG_NODE, &route_map_cmd);
1935 install_element (KEYCHAIN_NODE, &key_cmd);
1936 install_element (KEYCHAIN_NODE, &key_chain_cmd);
1937 install_element (KEYCHAIN_KEY_NODE, &key_chain_cmd);
1938 install_element (CONFIG_NODE, &vtysh_interface_cmd);
paul32d24632003-05-23 09:25:20 +00001939 install_element (CONFIG_NODE, &vtysh_no_interface_cmd);
paul718e3742002-12-13 20:15:29 +00001940 install_element (ENABLE_NODE, &vtysh_show_running_config_cmd);
1941 install_element (ENABLE_NODE, &vtysh_copy_runningconfig_startupconfig_cmd);
1942 install_element (ENABLE_NODE, &vtysh_write_file_cmd);
hasso4a6e2252003-05-25 11:51:29 +00001943 install_element (ENABLE_NODE, &vtysh_write_cmd);
paul718e3742002-12-13 20:15:29 +00001944
hasso95e735b2004-08-26 13:08:30 +00001945 /* "write terminal" command. */
paul718e3742002-12-13 20:15:29 +00001946 install_element (ENABLE_NODE, &vtysh_write_terminal_cmd);
1947 install_element (CONFIG_NODE, &vtysh_write_terminal_cmd);
1948 install_element (BGP_NODE, &vtysh_write_terminal_cmd);
1949 install_element (BGP_VPNV4_NODE, &vtysh_write_terminal_cmd);
1950 install_element (BGP_IPV4_NODE, &vtysh_write_terminal_cmd);
1951 install_element (BGP_IPV4M_NODE, &vtysh_write_terminal_cmd);
1952 install_element (BGP_IPV6_NODE, &vtysh_write_terminal_cmd);
1953 install_element (RIP_NODE, &vtysh_write_terminal_cmd);
1954 install_element (RIPNG_NODE, &vtysh_write_terminal_cmd);
1955 install_element (OSPF_NODE, &vtysh_write_terminal_cmd);
1956 install_element (OSPF6_NODE, &vtysh_write_terminal_cmd);
hassoc25e4582003-12-23 10:39:08 +00001957 install_element (ISIS_NODE, &vtysh_write_terminal_cmd);
paul718e3742002-12-13 20:15:29 +00001958 install_element (INTERFACE_NODE, &vtysh_write_terminal_cmd);
1959 install_element (RMAP_NODE, &vtysh_write_terminal_cmd);
1960 install_element (KEYCHAIN_NODE, &vtysh_write_terminal_cmd);
1961 install_element (KEYCHAIN_KEY_NODE, &vtysh_write_terminal_cmd);
1962
hasso95e735b2004-08-26 13:08:30 +00001963 /* "write memory" command. */
paul718e3742002-12-13 20:15:29 +00001964 install_element (ENABLE_NODE, &vtysh_write_memory_cmd);
1965 install_element (CONFIG_NODE, &vtysh_write_memory_cmd);
1966 install_element (BGP_NODE, &vtysh_write_memory_cmd);
1967 install_element (BGP_VPNV4_NODE, &vtysh_write_memory_cmd);
1968 install_element (BGP_IPV4_NODE, &vtysh_write_memory_cmd);
1969 install_element (BGP_IPV4M_NODE, &vtysh_write_memory_cmd);
1970 install_element (BGP_IPV6_NODE, &vtysh_write_memory_cmd);
1971 install_element (RIP_NODE, &vtysh_write_memory_cmd);
1972 install_element (RIPNG_NODE, &vtysh_write_memory_cmd);
1973 install_element (OSPF_NODE, &vtysh_write_memory_cmd);
1974 install_element (OSPF6_NODE, &vtysh_write_memory_cmd);
hassoc25e4582003-12-23 10:39:08 +00001975 install_element (ISIS_NODE, &vtysh_write_memory_cmd);
paul718e3742002-12-13 20:15:29 +00001976 install_element (INTERFACE_NODE, &vtysh_write_memory_cmd);
1977 install_element (RMAP_NODE, &vtysh_write_memory_cmd);
1978 install_element (KEYCHAIN_NODE, &vtysh_write_memory_cmd);
1979 install_element (KEYCHAIN_KEY_NODE, &vtysh_write_memory_cmd);
1980
1981 install_element (VIEW_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00001982 install_element (VIEW_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00001983 install_element (VIEW_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00001984 install_element (VIEW_NODE, &vtysh_traceroute_ip_cmd);
1985#ifdef HAVE_IPV6
1986 install_element (VIEW_NODE, &vtysh_ping6_cmd);
1987 install_element (VIEW_NODE, &vtysh_traceroute6_cmd);
1988#endif
paul718e3742002-12-13 20:15:29 +00001989 install_element (VIEW_NODE, &vtysh_telnet_cmd);
1990 install_element (VIEW_NODE, &vtysh_telnet_port_cmd);
paul5087df52003-01-25 06:56:09 +00001991 install_element (VIEW_NODE, &vtysh_ssh_cmd);
paul718e3742002-12-13 20:15:29 +00001992 install_element (ENABLE_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00001993 install_element (ENABLE_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00001994 install_element (ENABLE_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00001995 install_element (ENABLE_NODE, &vtysh_traceroute_ip_cmd);
1996#ifdef HAVE_IPV6
1997 install_element (ENABLE_NODE, &vtysh_ping6_cmd);
1998 install_element (ENABLE_NODE, &vtysh_traceroute6_cmd);
1999#endif
paul718e3742002-12-13 20:15:29 +00002000 install_element (ENABLE_NODE, &vtysh_telnet_cmd);
2001 install_element (ENABLE_NODE, &vtysh_telnet_port_cmd);
2002 install_element (ENABLE_NODE, &vtysh_start_shell_cmd);
2003 install_element (ENABLE_NODE, &vtysh_start_bash_cmd);
2004 install_element (ENABLE_NODE, &vtysh_start_zsh_cmd);
2005
paul718e3742002-12-13 20:15:29 +00002006 install_element (CONFIG_NODE, &vtysh_log_stdout_cmd);
2007 install_element (CONFIG_NODE, &no_vtysh_log_stdout_cmd);
2008 install_element (CONFIG_NODE, &vtysh_log_file_cmd);
2009 install_element (CONFIG_NODE, &no_vtysh_log_file_cmd);
2010 install_element (CONFIG_NODE, &vtysh_log_syslog_cmd);
2011 install_element (CONFIG_NODE, &no_vtysh_log_syslog_cmd);
2012 install_element (CONFIG_NODE, &vtysh_log_trap_cmd);
2013 install_element (CONFIG_NODE, &no_vtysh_log_trap_cmd);
2014 install_element (CONFIG_NODE, &vtysh_log_record_priority_cmd);
2015 install_element (CONFIG_NODE, &no_vtysh_log_record_priority_cmd);
paul4fc01e62002-12-13 20:49:00 +00002016 install_element (CONFIG_NODE, &vtysh_write_config_cmd);
2017 install_element (CONFIG_NODE, &no_vtysh_write_config_cmd);
paul718e3742002-12-13 20:15:29 +00002018}