blob: 45596b2997001beb8df554d270ceae7442ce406a [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{
hasso5a9c53d2004-08-27 14:23:28 +0000215 char *pager_defined;
216
217 pager_defined = getenv ("VTYSH_PAGER");
218
219 if (pager_defined)
220 vtysh_pager_name = strdup (pager_defined);
221 else
hasso34553cc2004-08-27 13:56:39 +0000222 vtysh_pager_name = strdup ("more");
paul718e3742002-12-13 20:15:29 +0000223}
224
225/* Command execution over the vty interface. */
226void
227vtysh_execute_func (char *line, int pager)
228{
229 int ret, cmd_stat;
230 vector vline;
231 struct cmd_element *cmd;
232 FILE *fp = NULL;
paula805cc22003-05-01 14:29:48 +0000233 int closepager=0;
paul718e3742002-12-13 20:15:29 +0000234
hasso95e735b2004-08-26 13:08:30 +0000235 /* Split readline string up into the vector. */
paul718e3742002-12-13 20:15:29 +0000236 vline = cmd_make_strvec (line);
237
238 if (vline == NULL)
239 return;
240
241 ret = cmd_execute_command (vline, vty, &cmd);
242
243 cmd_free_strvec (vline);
244
245 switch (ret)
246 {
247 case CMD_WARNING:
248 if (vty->type == VTY_FILE)
paul4fc01e62002-12-13 20:49:00 +0000249 fprintf (stdout,"Warning...\n");
paul718e3742002-12-13 20:15:29 +0000250 break;
251 case CMD_ERR_AMBIGUOUS:
paul4fc01e62002-12-13 20:49:00 +0000252 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000253 break;
254 case CMD_ERR_NO_MATCH:
paul4fc01e62002-12-13 20:49:00 +0000255 fprintf (stdout,"%% Unknown command.\n");
paul718e3742002-12-13 20:15:29 +0000256 break;
257 case CMD_ERR_INCOMPLETE:
paul4fc01e62002-12-13 20:49:00 +0000258 fprintf (stdout,"%% Command incomplete.\n");
paul718e3742002-12-13 20:15:29 +0000259 break;
260 case CMD_SUCCESS_DAEMON:
261 {
262 if (pager && vtysh_pager_name)
263 {
paul4fc01e62002-12-13 20:49:00 +0000264 fp = popen (vtysh_pager_name, "w");
paul718e3742002-12-13 20:15:29 +0000265 if (fp == NULL)
266 {
paula805cc22003-05-01 14:29:48 +0000267 perror ("popen failed for pager");
268 fp = stdout;
paul718e3742002-12-13 20:15:29 +0000269 }
paula805cc22003-05-01 14:29:48 +0000270 else
271 closepager=1;
paul718e3742002-12-13 20:15:29 +0000272 }
273 else
274 fp = stdout;
275
276 if (! strcmp(cmd->string,"configure terminal"))
277 {
278 cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ZEBRA],
279 line, fp);
280 if (cmd_stat != CMD_WARNING)
281 cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIP],
282 line, fp);
283 if (cmd_stat != CMD_WARNING)
hasso95e735b2004-08-26 13:08:30 +0000284 cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIPNG],
285 line, fp);
paul718e3742002-12-13 20:15:29 +0000286 if (cmd_stat != CMD_WARNING)
287 cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF],
288 line, fp);
289 if (cmd_stat != CMD_WARNING)
hasso95e735b2004-08-26 13:08:30 +0000290 cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF6],
291 line, fp);
paul718e3742002-12-13 20:15:29 +0000292 if (cmd_stat != CMD_WARNING)
293 cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_BGP],
294 line, fp);
hassob094d262004-08-25 12:22:00 +0000295 if (cmd_stat != CMD_WARNING)
hasso95e735b2004-08-26 13:08:30 +0000296 cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ISIS],
297 line, fp);
paul718e3742002-12-13 20:15:29 +0000298 if (cmd_stat)
299 {
hassob094d262004-08-25 12:22:00 +0000300 line = "end";
301 vline = cmd_make_strvec (line);
paul718e3742002-12-13 20:15:29 +0000302
hassob094d262004-08-25 12:22:00 +0000303 if (vline == NULL)
paul718e3742002-12-13 20:15:29 +0000304 {
paula805cc22003-05-01 14:29:48 +0000305 if (pager && vtysh_pager_name && fp && closepager)
paul718e3742002-12-13 20:15:29 +0000306 {
307 if (pclose (fp) == -1)
308 {
paula805cc22003-05-01 14:29:48 +0000309 perror ("pclose failed for pager");
paul718e3742002-12-13 20:15:29 +0000310 }
311 fp = NULL;
312 }
313 return;
314 }
315
hassob094d262004-08-25 12:22:00 +0000316 ret = cmd_execute_command (vline, vty, &cmd);
317 cmd_free_strvec (vline);
318 if (ret != CMD_SUCCESS_DAEMON)
319 break;
paul718e3742002-12-13 20:15:29 +0000320 }
321 else
322 if (cmd->func)
323 {
324 (*cmd->func) (cmd, vty, 0, NULL);
325 break;
hassob094d262004-08-25 12:22:00 +0000326 }
paul718e3742002-12-13 20:15:29 +0000327 }
328
329 if (cmd->daemon & VTYSH_ZEBRA)
330 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ZEBRA], line, fp)
331 != CMD_SUCCESS)
332 break;
333 if (cmd->daemon & VTYSH_RIPD)
334 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIP], line, fp)
335 != CMD_SUCCESS)
336 break;
337 if (cmd->daemon & VTYSH_RIPNGD)
338 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIPNG], line, fp)
339 != CMD_SUCCESS)
340 break;
341 if (cmd->daemon & VTYSH_OSPFD)
342 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF], line, fp)
343 != CMD_SUCCESS)
344 break;
345 if (cmd->daemon & VTYSH_OSPF6D)
346 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF6], line, fp)
347 != CMD_SUCCESS)
348 break;
349 if (cmd->daemon & VTYSH_BGPD)
350 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_BGP], line, fp)
351 != CMD_SUCCESS)
352 break;
hassob094d262004-08-25 12:22:00 +0000353 if (cmd->daemon & VTYSH_ISISD)
354 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ISIS], line, fp)
355 != CMD_SUCCESS)
356 break;
paul718e3742002-12-13 20:15:29 +0000357 if (cmd->func)
358 (*cmd->func) (cmd, vty, 0, NULL);
359 }
360 }
paula805cc22003-05-01 14:29:48 +0000361 if (pager && vtysh_pager_name && fp && closepager)
paul718e3742002-12-13 20:15:29 +0000362 {
363 if (pclose (fp) == -1)
364 {
paula805cc22003-05-01 14:29:48 +0000365 perror ("pclose failed for pager");
paul718e3742002-12-13 20:15:29 +0000366 }
367 fp = NULL;
368 }
369}
370
371void
372vtysh_execute_no_pager (char *line)
373{
374 vtysh_execute_func (line, 0);
375}
376
377void
378vtysh_execute (char *line)
379{
380 vtysh_execute_func (line, 1);
381}
382
383/* Configration make from file. */
384int
385vtysh_config_from_file (struct vty *vty, FILE *fp)
386{
387 int ret;
388 vector vline;
389 struct cmd_element *cmd;
390
391 while (fgets (vty->buf, VTY_BUFSIZ, fp))
392 {
393 if (vty->buf[0] == '!' || vty->buf[1] == '#')
394 continue;
395
396 vline = cmd_make_strvec (vty->buf);
397
hasso95e735b2004-08-26 13:08:30 +0000398 /* In case of comment line. */
paul718e3742002-12-13 20:15:29 +0000399 if (vline == NULL)
400 continue;
401
hasso95e735b2004-08-26 13:08:30 +0000402 /* Execute configuration command : this is strict match. */
paul718e3742002-12-13 20:15:29 +0000403 ret = cmd_execute_command_strict (vline, vty, &cmd);
404
hasso95e735b2004-08-26 13:08:30 +0000405 /* Try again with setting node to CONFIG_NODE. */
paul718e3742002-12-13 20:15:29 +0000406 if (ret != CMD_SUCCESS
407 && ret != CMD_SUCCESS_DAEMON
408 && ret != CMD_WARNING)
409 {
410 if (vty->node == KEYCHAIN_KEY_NODE)
411 {
412 vty->node = KEYCHAIN_NODE;
413 vtysh_exit_ripd_only ();
414 ret = cmd_execute_command_strict (vline, vty, &cmd);
415
416 if (ret != CMD_SUCCESS
417 && ret != CMD_SUCCESS_DAEMON
418 && ret != CMD_WARNING)
419 {
420 vtysh_exit_ripd_only ();
421 vty->node = CONFIG_NODE;
422 ret = cmd_execute_command_strict (vline, vty, &cmd);
423 }
424 }
425 else
426 {
427 vtysh_execute ("end");
428 vtysh_execute ("configure terminal");
429 vty->node = CONFIG_NODE;
430 ret = cmd_execute_command_strict (vline, vty, &cmd);
431 }
432 }
433
434 cmd_free_strvec (vline);
435
436 switch (ret)
437 {
438 case CMD_WARNING:
439 if (vty->type == VTY_FILE)
paul4fc01e62002-12-13 20:49:00 +0000440 fprintf (stdout,"Warning...\n");
paul718e3742002-12-13 20:15:29 +0000441 break;
442 case CMD_ERR_AMBIGUOUS:
paul4fc01e62002-12-13 20:49:00 +0000443 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000444 break;
445 case CMD_ERR_NO_MATCH:
paul4fc01e62002-12-13 20:49:00 +0000446 fprintf (stdout,"%% Unknown command: %s", vty->buf);
paul718e3742002-12-13 20:15:29 +0000447 break;
448 case CMD_ERR_INCOMPLETE:
paul4fc01e62002-12-13 20:49:00 +0000449 fprintf (stdout,"%% Command incomplete.\n");
paul718e3742002-12-13 20:15:29 +0000450 break;
451 case CMD_SUCCESS_DAEMON:
452 {
453 if (cmd->daemon & VTYSH_ZEBRA)
454 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ZEBRA],
455 vty->buf, stdout) != CMD_SUCCESS)
456 break;
457 if (cmd->daemon & VTYSH_RIPD)
458 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIP],
459 vty->buf, stdout) != CMD_SUCCESS)
460 break;
461 if (cmd->daemon & VTYSH_RIPNGD)
462 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIPNG],
463 vty->buf, stdout) != CMD_SUCCESS)
464 break;
465 if (cmd->daemon & VTYSH_OSPFD)
466 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF],
467 vty->buf, stdout) != CMD_SUCCESS)
468 break;
469 if (cmd->daemon & VTYSH_OSPF6D)
470 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF6],
471 vty->buf, stdout) != CMD_SUCCESS)
472 break;
473 if (cmd->daemon & VTYSH_BGPD)
474 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_BGP],
475 vty->buf, stdout) != CMD_SUCCESS)
476 break;
hassob094d262004-08-25 12:22:00 +0000477 if (cmd->daemon & VTYSH_ISISD)
478 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ISIS],
479 vty->buf, stdout) != CMD_SUCCESS)
480 break;
paul718e3742002-12-13 20:15:29 +0000481 if (cmd->func)
482 (*cmd->func) (cmd, vty, 0, NULL);
483 }
484 }
485 }
486 return CMD_SUCCESS;
487}
488
489/* We don't care about the point of the cursor when '?' is typed. */
490int
491vtysh_rl_describe ()
492{
493 int ret;
494 int i;
495 vector vline;
496 vector describe;
497 int width;
498 struct desc *desc;
499
500 vline = cmd_make_strvec (rl_line_buffer);
501
502 /* In case of '> ?'. */
503 if (vline == NULL)
504 {
505 vline = vector_init (1);
506 vector_set (vline, '\0');
507 }
508 else
509 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
510 vector_set (vline, '\0');
511
512 describe = cmd_describe_command (vline, vty, &ret);
513
paul4fc01e62002-12-13 20:49:00 +0000514 fprintf (stdout,"\n");
paul718e3742002-12-13 20:15:29 +0000515
516 /* Ambiguous and no match error. */
517 switch (ret)
518 {
519 case CMD_ERR_AMBIGUOUS:
520 cmd_free_strvec (vline);
paul4fc01e62002-12-13 20:49:00 +0000521 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000522 rl_on_new_line ();
523 return 0;
524 break;
525 case CMD_ERR_NO_MATCH:
526 cmd_free_strvec (vline);
paul4fc01e62002-12-13 20:49:00 +0000527 fprintf (stdout,"%% There is no matched command.\n");
paul718e3742002-12-13 20:15:29 +0000528 rl_on_new_line ();
529 return 0;
530 break;
531 }
532
533 /* Get width of command string. */
534 width = 0;
535 for (i = 0; i < vector_max (describe); i++)
536 if ((desc = vector_slot (describe, i)) != NULL)
537 {
538 int len;
539
540 if (desc->cmd[0] == '\0')
541 continue;
542
543 len = strlen (desc->cmd);
544 if (desc->cmd[0] == '.')
545 len--;
546
547 if (width < len)
548 width = len;
549 }
550
551 for (i = 0; i < vector_max (describe); i++)
552 if ((desc = vector_slot (describe, i)) != NULL)
553 {
554 if (desc->cmd[0] == '\0')
555 continue;
556
557 if (! desc->str)
paul4fc01e62002-12-13 20:49:00 +0000558 fprintf (stdout," %-s\n",
hassob094d262004-08-25 12:22:00 +0000559 desc->cmd[0] == '.' ? desc->cmd + 1 : desc->cmd);
paul718e3742002-12-13 20:15:29 +0000560 else
paul4fc01e62002-12-13 20:49:00 +0000561 fprintf (stdout," %-*s %s\n",
hassob094d262004-08-25 12:22:00 +0000562 width,
563 desc->cmd[0] == '.' ? desc->cmd + 1 : desc->cmd,
564 desc->str);
paul718e3742002-12-13 20:15:29 +0000565 }
566
567 cmd_free_strvec (vline);
568 vector_free (describe);
569
570 rl_on_new_line();
571
572 return 0;
573}
574
hasso95e735b2004-08-26 13:08:30 +0000575/* Result of cmd_complete_command() call will be stored here
576 * and used in new_completion() in order to put the space in
577 * correct places only. */
paul718e3742002-12-13 20:15:29 +0000578int complete_status;
579
580char *
pauldfc0d9b2003-04-18 23:55:29 +0000581command_generator (const char *text, int state)
paul718e3742002-12-13 20:15:29 +0000582{
583 vector vline;
584 static char **matched = NULL;
585 static int index = 0;
586
587 /* First call. */
588 if (! state)
589 {
590 index = 0;
591
592 if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
593 return NULL;
594
595 vline = cmd_make_strvec (rl_line_buffer);
596 if (vline == NULL)
597 return NULL;
598
599 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
600 vector_set (vline, '\0');
601
602 matched = cmd_complete_command (vline, vty, &complete_status);
603 }
604
605 if (matched && matched[index])
606 return matched[index++];
607
608 return NULL;
609}
610
611char **
612new_completion (char *text, int start, int end)
613{
614 char **matches;
615
pauldfc0d9b2003-04-18 23:55:29 +0000616 matches = rl_completion_matches (text, command_generator);
paul718e3742002-12-13 20:15:29 +0000617
618 if (matches)
619 {
620 rl_point = rl_end;
621 if (complete_status == CMD_COMPLETE_FULL_MATCH)
622 rl_pending_input = ' ';
623 }
624
625 return matches;
626}
627
628char **
629vtysh_completion (char *text, int start, int end)
630{
631 int ret;
632 vector vline;
633 char **matched = NULL;
634
635 if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
636 return NULL;
637
638 vline = cmd_make_strvec (rl_line_buffer);
639 if (vline == NULL)
640 return NULL;
641
642 /* In case of 'help \t'. */
643 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
644 vector_set (vline, '\0');
645
646 matched = cmd_complete_command (vline, vty, &ret);
647
648 cmd_free_strvec (vline);
649
650 return (char **) matched;
651}
652
hasso95e735b2004-08-26 13:08:30 +0000653/* Vty node structures. */
paul718e3742002-12-13 20:15:29 +0000654struct cmd_node bgp_node =
655{
656 BGP_NODE,
657 "%s(config-router)# ",
658};
659
paul718e3742002-12-13 20:15:29 +0000660struct cmd_node rip_node =
661{
662 RIP_NODE,
663 "%s(config-router)# ",
664};
665
hassoc25e4582003-12-23 10:39:08 +0000666struct cmd_node isis_node =
667{
668 ISIS_NODE,
669 "%s(config-router)# ",
hassoc25e4582003-12-23 10:39:08 +0000670};
671
paul718e3742002-12-13 20:15:29 +0000672struct cmd_node interface_node =
673{
674 INTERFACE_NODE,
675 "%s(config-if)# ",
676};
677
hasso95e735b2004-08-26 13:08:30 +0000678struct cmd_node rmap_node =
679{
680 RMAP_NODE,
681 "%s(config-route-map)# "
682};
683
684struct cmd_node zebra_node =
685{
686 ZEBRA_NODE,
687 "%s(config-router)# "
688};
689
690struct cmd_node bgp_vpnv4_node =
691{
692 BGP_VPNV4_NODE,
693 "%s(config-router-af)# "
694};
695
696struct cmd_node bgp_ipv4_node =
697{
698 BGP_IPV4_NODE,
699 "%s(config-router-af)# "
700};
701
702struct cmd_node bgp_ipv4m_node =
703{
704 BGP_IPV4M_NODE,
705 "%s(config-router-af)# "
706};
707
708struct cmd_node bgp_ipv6_node =
709{
710 BGP_IPV6_NODE,
711 "%s(config-router-af)# "
712};
713
714struct cmd_node ospf_node =
715{
716 OSPF_NODE,
717 "%s(config-router)# "
718};
719
720struct cmd_node ripng_node =
721{
722 RIPNG_NODE,
723 "%s(config-router)# "
724};
725
726struct cmd_node ospf6_node =
727{
728 OSPF6_NODE,
729 "%s(config-ospf6)# "
730};
731
732struct cmd_node keychain_node =
733{
734 KEYCHAIN_NODE,
735 "%s(config-keychain)# "
736};
737
738struct cmd_node keychain_key_node =
739{
740 KEYCHAIN_KEY_NODE,
741 "%s(config-keychain-key)# "
742};
743
744/* When '^Z' is received from vty, move down to the enable mode. */
745int
746vtysh_end ()
747{
748 switch (vty->node)
749 {
750 case VIEW_NODE:
751 case ENABLE_NODE:
752 /* Nothing to do. */
753 break;
754 default:
755 vty->node = ENABLE_NODE;
756 break;
757 }
758 return CMD_SUCCESS;
759}
760
761DEFUNSH (VTYSH_ALL,
762 vtysh_end_all,
763 vtysh_end_all_cmd,
764 "end",
765 "End current mode and down to previous mode\n")
766{
767 return vtysh_end (vty);
768}
769
paul718e3742002-12-13 20:15:29 +0000770DEFUNSH (VTYSH_BGPD,
771 router_bgp,
772 router_bgp_cmd,
773 "router bgp <1-65535>",
774 ROUTER_STR
775 BGP_STR
776 AS_STR)
777{
778 vty->node = BGP_NODE;
779 return CMD_SUCCESS;
780}
781
782DEFUNSH (VTYSH_BGPD,
783 address_family_vpnv4,
784 address_family_vpnv4_cmd,
785 "address-family vpnv4",
786 "Enter Address Family command mode\n"
787 "Address family\n")
788{
789 vty->node = BGP_VPNV4_NODE;
790 return CMD_SUCCESS;
791}
792
793DEFUNSH (VTYSH_BGPD,
794 address_family_vpnv4_unicast,
795 address_family_vpnv4_unicast_cmd,
796 "address-family vpnv4 unicast",
797 "Enter Address Family command mode\n"
798 "Address family\n"
799 "Address Family Modifier\n")
800{
801 vty->node = BGP_VPNV4_NODE;
802 return CMD_SUCCESS;
803}
804
805DEFUNSH (VTYSH_BGPD,
806 address_family_ipv4_unicast,
807 address_family_ipv4_unicast_cmd,
808 "address-family ipv4 unicast",
809 "Enter Address Family command mode\n"
810 "Address family\n"
811 "Address Family Modifier\n")
812{
813 vty->node = BGP_IPV4_NODE;
814 return CMD_SUCCESS;
815}
816
817DEFUNSH (VTYSH_BGPD,
818 address_family_ipv4_multicast,
819 address_family_ipv4_multicast_cmd,
820 "address-family ipv4 multicast",
821 "Enter Address Family command mode\n"
822 "Address family\n"
823 "Address Family Modifier\n")
824{
825 vty->node = BGP_IPV4M_NODE;
826 return CMD_SUCCESS;
827}
828
829DEFUNSH (VTYSH_BGPD,
830 address_family_ipv6,
831 address_family_ipv6_cmd,
832 "address-family ipv6",
833 "Enter Address Family command mode\n"
834 "Address family\n")
835{
836 vty->node = BGP_IPV6_NODE;
837 return CMD_SUCCESS;
838}
839
840DEFUNSH (VTYSH_BGPD,
841 address_family_ipv6_unicast,
842 address_family_ipv6_unicast_cmd,
843 "address-family ipv6 unicast",
844 "Enter Address Family command mode\n"
845 "Address family\n"
846 "Address Family Modifier\n")
847{
848 vty->node = BGP_IPV6_NODE;
849 return CMD_SUCCESS;
850}
851
852DEFUNSH (VTYSH_RIPD,
853 key_chain,
854 key_chain_cmd,
855 "key chain WORD",
856 "Authentication key management\n"
857 "Key-chain management\n"
858 "Key-chain name\n")
859{
860 vty->node = KEYCHAIN_NODE;
861 return CMD_SUCCESS;
862}
863
864DEFUNSH (VTYSH_RIPD,
865 key,
866 key_cmd,
867 "key <0-2147483647>",
868 "Configure a key\n"
869 "Key identifier number\n")
870{
871 vty->node = KEYCHAIN_KEY_NODE;
872 return CMD_SUCCESS;
873}
874
875DEFUNSH (VTYSH_RIPD,
876 router_rip,
877 router_rip_cmd,
878 "router rip",
879 ROUTER_STR
880 "RIP")
881{
882 vty->node = RIP_NODE;
883 return CMD_SUCCESS;
884}
885
886DEFUNSH (VTYSH_RIPNGD,
887 router_ripng,
888 router_ripng_cmd,
889 "router ripng",
890 ROUTER_STR
891 "RIPng")
892{
893 vty->node = RIPNG_NODE;
894 return CMD_SUCCESS;
895}
896
897DEFUNSH (VTYSH_OSPFD,
898 router_ospf,
899 router_ospf_cmd,
900 "router ospf",
901 "Enable a routing process\n"
902 "Start OSPF configuration\n")
903{
904 vty->node = OSPF_NODE;
905 return CMD_SUCCESS;
906}
907
908DEFUNSH (VTYSH_OSPF6D,
909 router_ospf6,
910 router_ospf6_cmd,
911 "router ospf6",
912 OSPF6_ROUTER_STR
913 OSPF6_STR)
914{
915 vty->node = OSPF6_NODE;
916 return CMD_SUCCESS;
917}
918
hassoc25e4582003-12-23 10:39:08 +0000919DEFUNSH (VTYSH_ISISD,
hassob094d262004-08-25 12:22:00 +0000920 router_isis,
921 router_isis_cmd,
922 "router isis WORD",
923 ROUTER_STR
924 "ISO IS-IS\n"
925 "ISO Routing area tag")
hassoc25e4582003-12-23 10:39:08 +0000926{
927 vty->node = ISIS_NODE;
928 return CMD_SUCCESS;
929}
930
paul718e3742002-12-13 20:15:29 +0000931DEFUNSH (VTYSH_RMAP,
932 route_map,
933 route_map_cmd,
934 "route-map WORD (deny|permit) <1-65535>",
935 "Create route-map or enter route-map command mode\n"
936 "Route map tag\n"
937 "Route map denies set operations\n"
938 "Route map permits set operations\n"
939 "Sequence to insert to/delete from existing route-map entry\n")
940{
941 vty->node = RMAP_NODE;
942 return CMD_SUCCESS;
943}
944
paul718e3742002-12-13 20:15:29 +0000945DEFUNSH (VTYSH_ALL,
946 vtysh_enable,
947 vtysh_enable_cmd,
948 "enable",
949 "Turn on privileged mode command\n")
950{
951 vty->node = ENABLE_NODE;
952 return CMD_SUCCESS;
953}
954
paul718e3742002-12-13 20:15:29 +0000955DEFUNSH (VTYSH_ALL,
956 vtysh_disable,
957 vtysh_disable_cmd,
958 "disable",
959 "Turn off privileged mode command\n")
960{
961 if (vty->node == ENABLE_NODE)
962 vty->node = VIEW_NODE;
963 return CMD_SUCCESS;
964}
965
paul718e3742002-12-13 20:15:29 +0000966DEFUNSH (VTYSH_ALL,
967 vtysh_config_terminal,
968 vtysh_config_terminal_cmd,
969 "configure terminal",
970 "Configuration from vty interface\n"
971 "Configuration terminal\n")
972{
973 vty->node = CONFIG_NODE;
974 return CMD_SUCCESS;
975}
976
977int
978vtysh_exit (struct vty *vty)
979{
980 switch (vty->node)
981 {
982 case VIEW_NODE:
983 case ENABLE_NODE:
984 exit (0);
985 break;
986 case CONFIG_NODE:
987 vty->node = ENABLE_NODE;
988 break;
989 case INTERFACE_NODE:
990 case ZEBRA_NODE:
991 case BGP_NODE:
992 case RIP_NODE:
993 case RIPNG_NODE:
994 case OSPF_NODE:
995 case OSPF6_NODE:
hassoc25e4582003-12-23 10:39:08 +0000996 case ISIS_NODE:
paul718e3742002-12-13 20:15:29 +0000997 case MASC_NODE:
998 case RMAP_NODE:
999 case VTY_NODE:
1000 case KEYCHAIN_NODE:
hasso2a56df92004-05-09 23:16:40 +00001001 vtysh_execute("end");
1002 vtysh_execute("configure terminal");
paul718e3742002-12-13 20:15:29 +00001003 vty->node = CONFIG_NODE;
1004 break;
1005 case BGP_VPNV4_NODE:
1006 case BGP_IPV4_NODE:
1007 case BGP_IPV4M_NODE:
1008 case BGP_IPV6_NODE:
1009 vty->node = BGP_NODE;
1010 break;
1011 case KEYCHAIN_KEY_NODE:
1012 vty->node = KEYCHAIN_NODE;
1013 break;
1014 default:
1015 break;
1016 }
1017 return CMD_SUCCESS;
1018}
1019
1020DEFUNSH (VTYSH_ALL,
1021 vtysh_exit_all,
1022 vtysh_exit_all_cmd,
1023 "exit",
1024 "Exit current mode and down to previous mode\n")
1025{
1026 return vtysh_exit (vty);
1027}
1028
1029ALIAS (vtysh_exit_all,
1030 vtysh_quit_all_cmd,
1031 "quit",
1032 "Exit current mode and down to previous mode\n")
1033
1034DEFUNSH (VTYSH_BGPD,
1035 exit_address_family,
1036 exit_address_family_cmd,
1037 "exit-address-family",
1038 "Exit from Address Family configuration mode\n")
1039{
1040 if (vty->node == BGP_IPV4_NODE
1041 || vty->node == BGP_IPV4M_NODE
1042 || vty->node == BGP_VPNV4_NODE
1043 || vty->node == BGP_IPV6_NODE)
1044 vty->node = BGP_NODE;
1045 return CMD_SUCCESS;
1046}
1047
1048DEFUNSH (VTYSH_ZEBRA,
1049 vtysh_exit_zebra,
1050 vtysh_exit_zebra_cmd,
1051 "exit",
1052 "Exit current mode and down to previous mode\n")
1053{
1054 return vtysh_exit (vty);
1055}
1056
1057ALIAS (vtysh_exit_zebra,
1058 vtysh_quit_zebra_cmd,
1059 "quit",
1060 "Exit current mode and down to previous mode\n")
1061
1062DEFUNSH (VTYSH_RIPD,
1063 vtysh_exit_ripd,
1064 vtysh_exit_ripd_cmd,
1065 "exit",
1066 "Exit current mode and down to previous mode\n")
1067{
1068 return vtysh_exit (vty);
1069}
1070
1071ALIAS (vtysh_exit_ripd,
1072 vtysh_quit_ripd_cmd,
1073 "quit",
1074 "Exit current mode and down to previous mode\n")
1075
paul68980082003-03-25 05:07:42 +00001076DEFUNSH (VTYSH_RIPNGD,
hassob094d262004-08-25 12:22:00 +00001077 vtysh_exit_ripngd,
1078 vtysh_exit_ripngd_cmd,
1079 "exit",
1080 "Exit current mode and down to previous mode\n")
paul68980082003-03-25 05:07:42 +00001081{
1082 return vtysh_exit (vty);
1083}
1084
1085ALIAS (vtysh_exit_ripngd,
1086 vtysh_quit_ripngd_cmd,
1087 "quit",
1088 "Exit current mode and down to previous mode\n")
1089
paul718e3742002-12-13 20:15:29 +00001090DEFUNSH (VTYSH_RMAP,
1091 vtysh_exit_rmap,
1092 vtysh_exit_rmap_cmd,
1093 "exit",
1094 "Exit current mode and down to previous mode\n")
1095{
1096 return vtysh_exit (vty);
1097}
1098
1099ALIAS (vtysh_exit_rmap,
1100 vtysh_quit_rmap_cmd,
1101 "quit",
1102 "Exit current mode and down to previous mode\n")
1103
1104DEFUNSH (VTYSH_BGPD,
1105 vtysh_exit_bgpd,
1106 vtysh_exit_bgpd_cmd,
1107 "exit",
1108 "Exit current mode and down to previous mode\n")
1109{
1110 return vtysh_exit (vty);
1111}
1112
1113ALIAS (vtysh_exit_bgpd,
1114 vtysh_quit_bgpd_cmd,
1115 "quit",
1116 "Exit current mode and down to previous mode\n")
1117
1118DEFUNSH (VTYSH_OSPFD,
1119 vtysh_exit_ospfd,
1120 vtysh_exit_ospfd_cmd,
1121 "exit",
1122 "Exit current mode and down to previous mode\n")
1123{
1124 return vtysh_exit (vty);
1125}
1126
1127ALIAS (vtysh_exit_ospfd,
1128 vtysh_quit_ospfd_cmd,
1129 "quit",
1130 "Exit current mode and down to previous mode\n")
1131
paul68980082003-03-25 05:07:42 +00001132DEFUNSH (VTYSH_OSPF6D,
hassob094d262004-08-25 12:22:00 +00001133 vtysh_exit_ospf6d,
1134 vtysh_exit_ospf6d_cmd,
1135 "exit",
1136 "Exit current mode and down to previous mode\n")
paul68980082003-03-25 05:07:42 +00001137{
1138 return vtysh_exit (vty);
1139}
1140
1141ALIAS (vtysh_exit_ospf6d,
1142 vtysh_quit_ospf6d_cmd,
1143 "quit",
1144 "Exit current mode and down to previous mode\n")
1145
hassoc25e4582003-12-23 10:39:08 +00001146DEFUNSH (VTYSH_ISISD,
hassob094d262004-08-25 12:22:00 +00001147 vtysh_exit_isisd,
1148 vtysh_exit_isisd_cmd,
1149 "exit",
1150 "Exit current mode and down to previous mode\n")
hassoc25e4582003-12-23 10:39:08 +00001151{
1152 return vtysh_exit (vty);
1153}
1154
1155ALIAS (vtysh_exit_isisd,
1156 vtysh_quit_isisd_cmd,
1157 "quit",
1158 "Exit current mode and down to previous mode\n")
1159
hasso95e735b2004-08-26 13:08:30 +00001160DEFUNSH (VTYSH_INTERFACE,
paul718e3742002-12-13 20:15:29 +00001161 vtysh_interface,
1162 vtysh_interface_cmd,
1163 "interface IFNAME",
1164 "Select an interface to configure\n"
1165 "Interface's name\n")
1166{
1167 vty->node = INTERFACE_NODE;
1168 return CMD_SUCCESS;
1169}
1170
hasso95e735b2004-08-26 13:08:30 +00001171/* TODO Implement "no interface command in isisd. */
paul32d24632003-05-23 09:25:20 +00001172DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D,
1173 vtysh_no_interface_cmd,
1174 "no interface IFNAME",
1175 NO_STR
1176 "Delete a pseudo interface's configuration\n"
1177 "Interface's name\n")
1178
hasso95e735b2004-08-26 13:08:30 +00001179/* TODO Implement interface description commands in ripngd, ospf6d
1180 * and isisd. */
paul338a9912003-03-01 15:44:10 +00001181DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1182 interface_desc_cmd,
1183 "description .LINE",
1184 "Interface specific description\n"
1185 "Characters describing this interface\n")
paul464dc8d2003-03-28 02:25:45 +00001186
1187DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1188 no_interface_desc_cmd,
1189 "no description",
1190 NO_STR
1191 "Interface specific description\n")
paul338a9912003-03-01 15:44:10 +00001192
hasso95e735b2004-08-26 13:08:30 +00001193DEFUNSH (VTYSH_INTERFACE,
paul718e3742002-12-13 20:15:29 +00001194 vtysh_exit_interface,
1195 vtysh_exit_interface_cmd,
1196 "exit",
1197 "Exit current mode and down to previous mode\n")
1198{
1199 return vtysh_exit (vty);
1200}
1201
1202ALIAS (vtysh_exit_interface,
1203 vtysh_quit_interface_cmd,
1204 "quit",
1205 "Exit current mode and down to previous mode\n")
1206
hasso95e735b2004-08-26 13:08:30 +00001207/* Logging commands. */
1208DEFUNSH (VTYSH_ALL,
1209 vtysh_log_stdout,
1210 vtysh_log_stdout_cmd,
1211 "log stdout",
1212 "Logging control\n"
1213 "Logging goes to stdout\n")
1214{
1215 return CMD_SUCCESS;
1216}
1217
1218DEFUNSH (VTYSH_ALL,
1219 no_vtysh_log_stdout,
1220 no_vtysh_log_stdout_cmd,
1221 "no log stdout",
1222 NO_STR
1223 "Logging control\n"
1224 "Logging goes to stdout\n")
1225{
1226 return CMD_SUCCESS;
1227}
1228
1229DEFUNSH (VTYSH_ALL,
1230 vtysh_log_file,
1231 vtysh_log_file_cmd,
1232 "log file FILENAME",
1233 "Logging control\n"
1234 "Logging to file\n"
1235 "Logging filename\n")
1236{
1237 return CMD_SUCCESS;
1238}
1239
1240DEFUNSH (VTYSH_ALL,
1241 no_vtysh_log_file,
1242 no_vtysh_log_file_cmd,
1243 "no log file [FILENAME]",
1244 NO_STR
1245 "Logging control\n"
1246 "Cancel logging to file\n"
1247 "Logging file name\n")
1248{
1249 return CMD_SUCCESS;
1250}
1251
1252DEFUNSH (VTYSH_ALL,
1253 vtysh_log_syslog,
1254 vtysh_log_syslog_cmd,
1255 "log syslog",
1256 "Logging control\n"
1257 "Logging goes to syslog\n")
1258{
1259 return CMD_SUCCESS;
1260}
1261
1262DEFUNSH (VTYSH_ALL,
1263 no_vtysh_log_syslog,
1264 no_vtysh_log_syslog_cmd,
1265 "no log syslog",
1266 NO_STR
1267 "Logging control\n"
1268 "Cancel logging to syslog\n")
1269{
1270 return CMD_SUCCESS;
1271}
1272
1273DEFUNSH (VTYSH_ALL,
1274 vtysh_log_trap,
1275 vtysh_log_trap_cmd,
1276 "log trap (emergencies|alerts|critical|errors|warnings|\
1277 notifications|informational|debugging)",
1278 "Logging control\n"
1279 "Limit logging to specifed level\n")
1280{
1281 return CMD_SUCCESS;
1282}
1283
1284DEFUNSH (VTYSH_ALL,
1285 no_vtysh_log_trap,
1286 no_vtysh_log_trap_cmd,
1287 "no log trap",
1288 NO_STR
1289 "Logging control\n"
1290 "Permit all logging information\n")
1291{
1292 return CMD_SUCCESS;
1293}
1294
1295DEFUNSH (VTYSH_ALL,
1296 vtysh_log_record_priority,
1297 vtysh_log_record_priority_cmd,
1298 "log record-priority",
1299 "Logging control\n"
1300 "Log the priority of the message within the message\n")
1301{
1302 return CMD_SUCCESS;
1303}
1304
1305DEFUNSH (VTYSH_ALL,
1306 no_vtysh_log_record_priority,
1307 no_vtysh_log_record_priority_cmd,
1308 "no log record-priority",
1309 NO_STR
1310 "Logging control\n"
1311 "Do not log the priority of the message within the message\n")
1312{
1313 return CMD_SUCCESS;
1314}
1315
paul718e3742002-12-13 20:15:29 +00001316DEFUN (vtysh_write_terminal,
1317 vtysh_write_terminal_cmd,
1318 "write terminal",
1319 "Write running configuration to memory, network, or terminal\n"
1320 "Write to terminal\n")
1321{
1322 int ret;
1323 char line[] = "write terminal\n";
1324 FILE *fp = NULL;
1325
1326 if (vtysh_pager_name)
1327 {
paul4fc01e62002-12-13 20:49:00 +00001328 fp = popen (vtysh_pager_name, "w");
paul718e3742002-12-13 20:15:29 +00001329 if (fp == NULL)
1330 {
1331 perror ("popen");
1332 exit (1);
1333 }
1334 }
1335 else
1336 fp = stdout;
1337
1338 vty_out (vty, "Building configuration...%s", VTY_NEWLINE);
1339 vty_out (vty, "%sCurrent configuration:%s", VTY_NEWLINE,
1340 VTY_NEWLINE);
1341
1342 vtysh_config_write (fp);
1343
1344 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_ZEBRA], line);
1345 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_RIP], line);
1346 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_RIPNG], line);
1347 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_OSPF], line);
1348 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_OSPF6], line);
1349 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_BGP], line);
hassoc25e4582003-12-23 10:39:08 +00001350 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_ISIS], line);
paul718e3742002-12-13 20:15:29 +00001351
1352 vtysh_config_dump (fp);
1353
1354 if (vtysh_pager_name && fp)
1355 {
1356 fflush (fp);
1357 if (pclose (fp) == -1)
1358 {
1359 perror ("pclose");
1360 exit (1);
1361 }
1362 fp = NULL;
1363 }
1364
1365 return CMD_SUCCESS;
1366}
1367
paul4fc01e62002-12-13 20:49:00 +00001368struct vtysh_writeconfig_t {
1369 int daemon;
1370 int integrated;
1371} vtysh_wc = {-1,0};
1372
1373DEFUN (vtysh_write_config,
hassob094d262004-08-25 12:22:00 +00001374 vtysh_write_config_cmd,
1375 "write-config (daemon|integrated)",
1376 "Specify config files to write to\n"
1377 "Write per daemon file\n"
hasso95e735b2004-08-26 13:08:30 +00001378 "Write integrated file\n")
paul4fc01e62002-12-13 20:49:00 +00001379{
hasso95e735b2004-08-26 13:08:30 +00001380 if (!strncmp(argv[0],"d",1))
1381 vtysh_wc.daemon = 1;
1382 else if (!strncmp(argv[0],"i",1))
1383 vtysh_wc.integrated = 1;
1384
paul4fc01e62002-12-13 20:49:00 +00001385 return CMD_SUCCESS;
1386}
1387
1388DEFUN (no_vtysh_write_config,
hassob094d262004-08-25 12:22:00 +00001389 no_vtysh_write_config_cmd,
1390 "no write-config (daemon|integrated)",
hasso95e735b2004-08-26 13:08:30 +00001391 "Negate per daemon and/or integrated config files\n")
paul4fc01e62002-12-13 20:49:00 +00001392{
hasso95e735b2004-08-26 13:08:30 +00001393 if (!strncmp(argv[0],"d",1))
1394 vtysh_wc.daemon = 0;
1395 else if (!strncmp(argv[0],"i",1))
1396 vtysh_wc.integrated = 0;
1397
paul4fc01e62002-12-13 20:49:00 +00001398 return CMD_SUCCESS;
1399}
1400
1401int write_config_integrated(void)
paul718e3742002-12-13 20:15:29 +00001402{
1403 int ret;
paul718e3742002-12-13 20:15:29 +00001404 char line[] = "write terminal\n";
1405 FILE *fp;
1406 char *integrate_sav = NULL;
1407
hasso95e735b2004-08-26 13:08:30 +00001408 integrate_sav = malloc (strlen (integrate_default) +
1409 strlen (CONF_BACKUP_EXT) + 1);
paul718e3742002-12-13 20:15:29 +00001410 strcpy (integrate_sav, integrate_default);
1411 strcat (integrate_sav, CONF_BACKUP_EXT);
1412
paul4fc01e62002-12-13 20:49:00 +00001413 fprintf (stdout,"Building Configuration...\n");
paul718e3742002-12-13 20:15:29 +00001414
hasso95e735b2004-08-26 13:08:30 +00001415 /* Move current configuration file to backup config file. */
paul718e3742002-12-13 20:15:29 +00001416 unlink (integrate_sav);
1417 rename (integrate_default, integrate_sav);
hasso95e735b2004-08-26 13:08:30 +00001418 free (integrate_sav);
paul4fc01e62002-12-13 20:49:00 +00001419
paul718e3742002-12-13 20:15:29 +00001420 fp = fopen (integrate_default, "w");
1421 if (fp == NULL)
1422 {
hasso95e735b2004-08-26 13:08:30 +00001423 fprintf (stdout,"%% Can't open configuration file %s.\n",
1424 integrate_default);
paul718e3742002-12-13 20:15:29 +00001425 return CMD_SUCCESS;
1426 }
paul718e3742002-12-13 20:15:29 +00001427
1428 vtysh_config_write (fp);
1429
1430 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_ZEBRA], line);
1431 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_RIP], line);
1432 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_RIPNG], line);
1433 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_OSPF], line);
1434 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_OSPF6], line);
1435 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_BGP], line);
hassoc25e4582003-12-23 10:39:08 +00001436 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_ISIS], line);
paul718e3742002-12-13 20:15:29 +00001437
1438 vtysh_config_dump (fp);
1439
1440 fclose (fp);
1441
gdtaa593d52003-12-22 20:15:53 +00001442 if (chmod (integrate_default, CONFIGFILE_MASK) != 0)
1443 {
1444 fprintf (stdout,"%% Can't chmod configuration file %s: %s (%d)\n",
1445 integrate_default, strerror(errno), errno);
1446 return CMD_WARNING;
1447 }
1448
paul4fc01e62002-12-13 20:49:00 +00001449 fprintf(stdout,"Integrated configuration saved to %s\n",integrate_default);
1450
1451 fprintf (stdout,"[OK]\n");
1452
paul718e3742002-12-13 20:15:29 +00001453 return CMD_SUCCESS;
1454}
1455
paul4fc01e62002-12-13 20:49:00 +00001456DEFUN (vtysh_write_memory,
1457 vtysh_write_memory_cmd,
1458 "write memory",
1459 "Write running configuration to memory, network, or terminal\n"
1460 "Write configuration to the file (same as write file)\n")
1461{
pauldfc0d9b2003-04-18 23:55:29 +00001462 int ret = CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001463 char line[] = "write memory\n";
1464
hasso95e735b2004-08-26 13:08:30 +00001465 /* If integrated Zebra.conf explicitely set. */
1466 if (vtysh_wc.integrated == 1)
1467 ret = write_config_integrated();
paul4fc01e62002-12-13 20:49:00 +00001468
hasso95e735b2004-08-26 13:08:30 +00001469 if (!vtysh_wc.daemon)
1470 return ret;
paul4fc01e62002-12-13 20:49:00 +00001471
1472 fprintf (stdout,"Building Configuration...\n");
1473
1474 ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ZEBRA], line, stdout);
1475 ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIP], line, stdout);
1476 ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIPNG], line, stdout);
1477 ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF], line, stdout);
1478 ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF6], line, stdout);
1479 ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_BGP], line, stdout);
hassoc25e4582003-12-23 10:39:08 +00001480 ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ISIS], line, stdout);
paul4fc01e62002-12-13 20:49:00 +00001481
1482 fprintf (stdout,"[OK]\n");
1483
pauldfc0d9b2003-04-18 23:55:29 +00001484 return ret;
paul4fc01e62002-12-13 20:49:00 +00001485}
1486
paul718e3742002-12-13 20:15:29 +00001487ALIAS (vtysh_write_memory,
1488 vtysh_copy_runningconfig_startupconfig_cmd,
1489 "copy running-config startup-config",
1490 "Copy from one file to another\n"
1491 "Copy from current system configuration\n"
1492 "Copy to startup configuration\n")
1493
1494ALIAS (vtysh_write_memory,
1495 vtysh_write_file_cmd,
1496 "write file",
1497 "Write running configuration to memory, network, or terminal\n"
1498 "Write configuration to the file (same as write memory)\n")
1499
hasso4a6e2252003-05-25 11:51:29 +00001500ALIAS (vtysh_write_memory,
1501 vtysh_write_cmd,
1502 "write",
1503 "Write running configuration to memory, network, or terminal\n")
1504
paul718e3742002-12-13 20:15:29 +00001505ALIAS (vtysh_write_terminal,
1506 vtysh_show_running_config_cmd,
1507 "show running-config",
1508 SHOW_STR
1509 "Current operating configuration\n")
hassob094d262004-08-25 12:22:00 +00001510
hasso34553cc2004-08-27 13:56:39 +00001511DEFUN (vtysh_terminal_length,
1512 vtysh_terminal_length_cmd,
1513 "terminal length <0-512>",
1514 "Set terminal line parameters\n"
1515 "Set number of lines on a screen\n"
1516 "Number of lines on screen (0 for no pausing)\n")
1517{
1518 int lines;
1519 char *endptr = NULL;
1520 char default_pager[10];
1521
1522 lines = strtol (argv[0], &endptr, 10);
1523 if (lines < 0 || lines > 512 || *endptr != '\0')
1524 {
1525 vty_out (vty, "length is malformed%s", VTY_NEWLINE);
1526 return CMD_WARNING;
1527 }
1528
1529 if (vtysh_pager_name)
1530 {
1531 free (vtysh_pager_name);
1532 vtysh_pager_name = NULL;
1533 }
1534
1535 if (lines != 0)
1536 {
1537 snprintf(default_pager, 10, "more -%i", lines);
1538 vtysh_pager_name = strdup (default_pager);
1539 }
1540
1541 return CMD_SUCCESS;
1542}
1543
1544DEFUN (vtysh_terminal_no_length,
1545 vtysh_terminal_no_length_cmd,
1546 "terminal no length",
1547 "Set terminal line parameters\n"
1548 NO_STR
1549 "Set number of lines on a screen\n")
1550{
1551 if (vtysh_pager_name)
1552 {
1553 free (vtysh_pager_name);
1554 vtysh_pager_name = NULL;
1555 }
1556
1557 vtysh_pager_init();
1558 return CMD_SUCCESS;
1559}
1560
paul718e3742002-12-13 20:15:29 +00001561/* Execute command in child process. */
1562int
1563execute_command (char *command, int argc, char *arg1, char *arg2)
1564{
1565 int ret;
1566 pid_t pid;
1567 int status;
1568
1569 /* Call fork(). */
1570 pid = fork ();
1571
1572 if (pid < 0)
1573 {
1574 /* Failure of fork(). */
1575 fprintf (stderr, "Can't fork: %s\n", strerror (errno));
1576 exit (1);
1577 }
1578 else if (pid == 0)
1579 {
1580 /* This is child process. */
1581 switch (argc)
1582 {
1583 case 0:
hassofa2b17e2004-03-04 17:45:00 +00001584 ret = execlp (command, command, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00001585 break;
1586 case 1:
hassofa2b17e2004-03-04 17:45:00 +00001587 ret = execlp (command, command, arg1, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00001588 break;
1589 case 2:
hassofa2b17e2004-03-04 17:45:00 +00001590 ret = execlp (command, command, arg1, arg2, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00001591 break;
1592 }
1593
1594 /* When execlp suceed, this part is not executed. */
1595 fprintf (stderr, "Can't execute %s: %s\n", command, strerror (errno));
1596 exit (1);
1597 }
1598 else
1599 {
1600 /* This is parent. */
1601 execute_flag = 1;
1602 ret = wait4 (pid, &status, 0, NULL);
1603 execute_flag = 0;
1604 }
1605 return 0;
1606}
1607
1608DEFUN (vtysh_ping,
1609 vtysh_ping_cmd,
1610 "ping WORD",
hasso4eeccf12003-06-25 10:49:55 +00001611 "Send echo messages\n"
paul718e3742002-12-13 20:15:29 +00001612 "Ping destination address or hostname\n")
1613{
1614 execute_command ("ping", 1, argv[0], NULL);
1615 return CMD_SUCCESS;
1616}
1617
hasso4eeccf12003-06-25 10:49:55 +00001618ALIAS (vtysh_ping,
1619 vtysh_ping_ip_cmd,
1620 "ping ip WORD",
1621 "Send echo messages\n"
1622 "IP echo\n"
1623 "Ping destination address or hostname\n")
1624
paul718e3742002-12-13 20:15:29 +00001625DEFUN (vtysh_traceroute,
1626 vtysh_traceroute_cmd,
1627 "traceroute WORD",
1628 "Trace route to destination\n"
1629 "Trace route to destination address or hostname\n")
1630{
1631 execute_command ("traceroute", 1, argv[0], NULL);
1632 return CMD_SUCCESS;
1633}
1634
hasso4eeccf12003-06-25 10:49:55 +00001635ALIAS (vtysh_traceroute,
1636 vtysh_traceroute_ip_cmd,
1637 "traceroute ip WORD",
1638 "Trace route to destination\n"
1639 "IP trace\n"
1640 "Trace route to destination address or hostname\n")
1641
1642#ifdef HAVE_IPV6
1643DEFUN (vtysh_ping6,
1644 vtysh_ping6_cmd,
1645 "ping ipv6 WORD",
1646 "Send echo messages\n"
1647 "IPv6 echo\n"
1648 "Ping destination address or hostname\n")
1649{
1650 execute_command ("ping6", 1, argv[0], NULL);
1651 return CMD_SUCCESS;
1652}
1653
1654DEFUN (vtysh_traceroute6,
1655 vtysh_traceroute6_cmd,
1656 "traceroute ipv6 WORD",
1657 "Trace route to destination\n"
1658 "IPv6 trace\n"
1659 "Trace route to destination address or hostname\n")
1660{
1661 execute_command ("traceroute6", 1, argv[0], NULL);
1662 return CMD_SUCCESS;
1663}
1664#endif
1665
paul718e3742002-12-13 20:15:29 +00001666DEFUN (vtysh_telnet,
1667 vtysh_telnet_cmd,
1668 "telnet WORD",
1669 "Open a telnet connection\n"
1670 "IP address or hostname of a remote system\n")
1671{
1672 execute_command ("telnet", 1, argv[0], NULL);
1673 return CMD_SUCCESS;
1674}
1675
1676DEFUN (vtysh_telnet_port,
1677 vtysh_telnet_port_cmd,
1678 "telnet WORD PORT",
1679 "Open a telnet connection\n"
1680 "IP address or hostname of a remote system\n"
1681 "TCP Port number\n")
1682{
1683 execute_command ("telnet", 2, argv[0], argv[1]);
1684 return CMD_SUCCESS;
1685}
1686
paul5087df52003-01-25 06:56:09 +00001687DEFUN (vtysh_ssh,
1688 vtysh_ssh_cmd,
1689 "ssh WORD",
1690 "Open an ssh connection\n"
1691 "[user@]host\n")
1692{
1693 execute_command ("ssh", 1, argv[0], NULL);
1694 return CMD_SUCCESS;
1695}
1696
paul718e3742002-12-13 20:15:29 +00001697DEFUN (vtysh_start_shell,
1698 vtysh_start_shell_cmd,
1699 "start-shell",
1700 "Start UNIX shell\n")
1701{
1702 execute_command ("sh", 0, NULL, NULL);
1703 return CMD_SUCCESS;
1704}
1705
1706DEFUN (vtysh_start_bash,
1707 vtysh_start_bash_cmd,
1708 "start-shell bash",
1709 "Start UNIX shell\n"
1710 "Start bash\n")
1711{
1712 execute_command ("bash", 0, NULL, NULL);
1713 return CMD_SUCCESS;
1714}
1715
1716DEFUN (vtysh_start_zsh,
1717 vtysh_start_zsh_cmd,
1718 "start-shell zsh",
1719 "Start UNIX shell\n"
1720 "Start Z shell\n")
1721{
1722 execute_command ("zsh", 0, NULL, NULL);
1723 return CMD_SUCCESS;
1724}
hassob094d262004-08-25 12:22:00 +00001725
paul718e3742002-12-13 20:15:29 +00001726void
1727vtysh_install_default (enum node_type node)
1728{
1729 install_element (node, &config_list_cmd);
1730}
1731
1732/* Making connection to protocol daemon. */
1733int
1734vtysh_connect (struct vtysh_client *vclient, char *path)
1735{
1736 int ret;
1737 int sock, len;
1738 struct sockaddr_un addr;
1739 struct stat s_stat;
1740 uid_t euid;
1741 gid_t egid;
1742
1743 memset (vclient, 0, sizeof (struct vtysh_client));
1744 vclient->fd = -1;
1745
1746 /* Stat socket to see if we have permission to access it. */
1747 euid = geteuid();
1748 egid = getegid();
1749 ret = stat (path, &s_stat);
1750 if (ret < 0 && errno != ENOENT)
1751 {
1752 fprintf (stderr, "vtysh_connect(%s): stat = %s\n",
1753 path, strerror(errno));
1754 exit(1);
1755 }
1756
1757 if (ret >= 0)
1758 {
1759 if (! S_ISSOCK(s_stat.st_mode))
1760 {
1761 fprintf (stderr, "vtysh_connect(%s): Not a socket\n",
1762 path);
1763 exit (1);
1764 }
1765
paul718e3742002-12-13 20:15:29 +00001766 }
1767
1768 sock = socket (AF_UNIX, SOCK_STREAM, 0);
1769 if (sock < 0)
1770 {
1771#ifdef DEBUG
hasso95e735b2004-08-26 13:08:30 +00001772 fprintf(stderr, "vtysh_connect(%s): socket = %s\n", path,
1773 strerror(errno));
paul718e3742002-12-13 20:15:29 +00001774#endif /* DEBUG */
1775 return -1;
1776 }
1777
1778 memset (&addr, 0, sizeof (struct sockaddr_un));
1779 addr.sun_family = AF_UNIX;
1780 strncpy (addr.sun_path, path, strlen (path));
1781#ifdef HAVE_SUN_LEN
1782 len = addr.sun_len = SUN_LEN(&addr);
1783#else
1784 len = sizeof (addr.sun_family) + strlen (addr.sun_path);
1785#endif /* HAVE_SUN_LEN */
1786
1787 ret = connect (sock, (struct sockaddr *) &addr, len);
1788 if (ret < 0)
1789 {
1790#ifdef DEBUG
hasso95e735b2004-08-26 13:08:30 +00001791 fprintf(stderr, "vtysh_connect(%s): connect = %s\n", path,
1792 strerror(errno));
paul718e3742002-12-13 20:15:29 +00001793#endif /* DEBUG */
1794 close (sock);
1795 return -1;
1796 }
1797 vclient->fd = sock;
1798
1799 return 0;
1800}
1801
1802void
1803vtysh_connect_all()
1804{
1805 /* Clear each daemons client structure. */
paulfe067782003-04-07 16:10:05 +00001806 vtysh_connect (&vtysh_client[VTYSH_INDEX_ZEBRA], ZEBRA_VTYSH_PATH);
1807 vtysh_connect (&vtysh_client[VTYSH_INDEX_RIP], RIP_VTYSH_PATH);
1808 vtysh_connect (&vtysh_client[VTYSH_INDEX_RIPNG], RIPNG_VTYSH_PATH);
1809 vtysh_connect (&vtysh_client[VTYSH_INDEX_OSPF], OSPF_VTYSH_PATH);
1810 vtysh_connect (&vtysh_client[VTYSH_INDEX_OSPF6], OSPF6_VTYSH_PATH);
1811 vtysh_connect (&vtysh_client[VTYSH_INDEX_BGP], BGP_VTYSH_PATH);
hassoc25e4582003-12-23 10:39:08 +00001812 vtysh_connect (&vtysh_client[VTYSH_INDEX_ISIS], ISIS_VTYSH_PATH);
paul718e3742002-12-13 20:15:29 +00001813}
1814
hasso95e735b2004-08-26 13:08:30 +00001815/* To disable readline's filename completion. */
pauldfc0d9b2003-04-18 23:55:29 +00001816char *
1817vtysh_completion_entry_function (const char *ignore, int invoking_key)
paul718e3742002-12-13 20:15:29 +00001818{
pauldfc0d9b2003-04-18 23:55:29 +00001819 return NULL;
paul718e3742002-12-13 20:15:29 +00001820}
1821
1822void
1823vtysh_readline_init ()
1824{
1825 /* readline related settings. */
1826 rl_bind_key ('?', vtysh_rl_describe);
paul68980082003-03-25 05:07:42 +00001827 rl_completion_entry_function = vtysh_completion_entry_function;
paul718e3742002-12-13 20:15:29 +00001828 rl_attempted_completion_function = (CPPFunction *)new_completion;
1829 /* do not append space after completion. It will be appended
hasso95e735b2004-08-26 13:08:30 +00001830 * in new_completion() function explicitly. */
paul718e3742002-12-13 20:15:29 +00001831 rl_completion_append_character = '\0';
1832}
1833
1834char *
1835vtysh_prompt ()
1836{
1837 struct utsname names;
1838 static char buf[100];
1839 const char*hostname;
1840 extern struct host host;
1841
1842 hostname = host.name;
1843
1844 if (!hostname)
1845 {
1846 uname (&names);
1847 hostname = names.nodename;
1848 }
1849
1850 snprintf (buf, sizeof buf, cmd_prompt (vty->node), hostname);
1851
1852 return buf;
1853}
1854
1855void
1856vtysh_init_vty ()
1857{
1858 /* Make vty structure. */
1859 vty = vty_new ();
1860 vty->type = VTY_SHELL;
1861 vty->node = VIEW_NODE;
1862
1863 /* Initialize commands. */
1864 cmd_init (0);
1865
1866 /* Install nodes. */
1867 install_node (&bgp_node, NULL);
1868 install_node (&rip_node, NULL);
1869 install_node (&interface_node, NULL);
1870 install_node (&rmap_node, NULL);
1871 install_node (&zebra_node, NULL);
1872 install_node (&bgp_vpnv4_node, NULL);
1873 install_node (&bgp_ipv4_node, NULL);
1874 install_node (&bgp_ipv4m_node, NULL);
1875/* #ifdef HAVE_IPV6 */
1876 install_node (&bgp_ipv6_node, NULL);
1877/* #endif */
1878 install_node (&ospf_node, NULL);
1879/* #ifdef HAVE_IPV6 */
1880 install_node (&ripng_node, NULL);
1881 install_node (&ospf6_node, NULL);
1882/* #endif */
1883 install_node (&keychain_node, NULL);
1884 install_node (&keychain_key_node, NULL);
hassoc25e4582003-12-23 10:39:08 +00001885 install_node (&isis_node, NULL);
paul718e3742002-12-13 20:15:29 +00001886
1887 vtysh_install_default (VIEW_NODE);
1888 vtysh_install_default (ENABLE_NODE);
1889 vtysh_install_default (CONFIG_NODE);
1890 vtysh_install_default (BGP_NODE);
1891 vtysh_install_default (RIP_NODE);
1892 vtysh_install_default (INTERFACE_NODE);
1893 vtysh_install_default (RMAP_NODE);
1894 vtysh_install_default (ZEBRA_NODE);
1895 vtysh_install_default (BGP_VPNV4_NODE);
1896 vtysh_install_default (BGP_IPV4_NODE);
1897 vtysh_install_default (BGP_IPV4M_NODE);
1898 vtysh_install_default (BGP_IPV6_NODE);
1899 vtysh_install_default (OSPF_NODE);
1900 vtysh_install_default (RIPNG_NODE);
1901 vtysh_install_default (OSPF6_NODE);
hassoc25e4582003-12-23 10:39:08 +00001902 vtysh_install_default (ISIS_NODE);
paul718e3742002-12-13 20:15:29 +00001903 vtysh_install_default (KEYCHAIN_NODE);
1904 vtysh_install_default (KEYCHAIN_KEY_NODE);
1905
1906 install_element (VIEW_NODE, &vtysh_enable_cmd);
1907 install_element (ENABLE_NODE, &vtysh_config_terminal_cmd);
1908 install_element (ENABLE_NODE, &vtysh_disable_cmd);
1909
1910 /* "exit" command. */
1911 install_element (VIEW_NODE, &vtysh_exit_all_cmd);
1912 install_element (VIEW_NODE, &vtysh_quit_all_cmd);
1913 install_element (CONFIG_NODE, &vtysh_exit_all_cmd);
1914 /* install_element (CONFIG_NODE, &vtysh_quit_all_cmd); */
1915 install_element (ENABLE_NODE, &vtysh_exit_all_cmd);
1916 install_element (ENABLE_NODE, &vtysh_quit_all_cmd);
1917 install_element (RIP_NODE, &vtysh_exit_ripd_cmd);
1918 install_element (RIP_NODE, &vtysh_quit_ripd_cmd);
paul68980082003-03-25 05:07:42 +00001919 install_element (RIPNG_NODE, &vtysh_exit_ripngd_cmd);
1920 install_element (RIPNG_NODE, &vtysh_quit_ripngd_cmd);
paul718e3742002-12-13 20:15:29 +00001921 install_element (OSPF_NODE, &vtysh_exit_ospfd_cmd);
1922 install_element (OSPF_NODE, &vtysh_quit_ospfd_cmd);
paul68980082003-03-25 05:07:42 +00001923 install_element (OSPF6_NODE, &vtysh_exit_ospf6d_cmd);
1924 install_element (OSPF6_NODE, &vtysh_quit_ospf6d_cmd);
paul718e3742002-12-13 20:15:29 +00001925 install_element (BGP_NODE, &vtysh_exit_bgpd_cmd);
1926 install_element (BGP_NODE, &vtysh_quit_bgpd_cmd);
1927 install_element (BGP_VPNV4_NODE, &vtysh_exit_bgpd_cmd);
1928 install_element (BGP_VPNV4_NODE, &vtysh_quit_bgpd_cmd);
1929 install_element (BGP_IPV4_NODE, &vtysh_exit_bgpd_cmd);
1930 install_element (BGP_IPV4_NODE, &vtysh_quit_bgpd_cmd);
1931 install_element (BGP_IPV4M_NODE, &vtysh_exit_bgpd_cmd);
1932 install_element (BGP_IPV4M_NODE, &vtysh_quit_bgpd_cmd);
1933 install_element (BGP_IPV6_NODE, &vtysh_exit_bgpd_cmd);
1934 install_element (BGP_IPV6_NODE, &vtysh_quit_bgpd_cmd);
hassoc25e4582003-12-23 10:39:08 +00001935 install_element (ISIS_NODE, &vtysh_exit_isisd_cmd);
1936 install_element (ISIS_NODE, &vtysh_quit_isisd_cmd);
paul718e3742002-12-13 20:15:29 +00001937 install_element (KEYCHAIN_NODE, &vtysh_exit_ripd_cmd);
1938 install_element (KEYCHAIN_NODE, &vtysh_quit_ripd_cmd);
1939 install_element (KEYCHAIN_KEY_NODE, &vtysh_exit_ripd_cmd);
1940 install_element (KEYCHAIN_KEY_NODE, &vtysh_quit_ripd_cmd);
1941 install_element (RMAP_NODE, &vtysh_exit_rmap_cmd);
1942 install_element (RMAP_NODE, &vtysh_quit_rmap_cmd);
1943
1944 /* "end" command. */
1945 install_element (CONFIG_NODE, &vtysh_end_all_cmd);
1946 install_element (ENABLE_NODE, &vtysh_end_all_cmd);
1947 install_element (RIP_NODE, &vtysh_end_all_cmd);
1948 install_element (RIPNG_NODE, &vtysh_end_all_cmd);
1949 install_element (OSPF_NODE, &vtysh_end_all_cmd);
1950 install_element (OSPF6_NODE, &vtysh_end_all_cmd);
1951 install_element (BGP_NODE, &vtysh_end_all_cmd);
1952 install_element (BGP_IPV4_NODE, &vtysh_end_all_cmd);
1953 install_element (BGP_IPV4M_NODE, &vtysh_end_all_cmd);
1954 install_element (BGP_VPNV4_NODE, &vtysh_end_all_cmd);
1955 install_element (BGP_IPV6_NODE, &vtysh_end_all_cmd);
hassoc25e4582003-12-23 10:39:08 +00001956 install_element (ISIS_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00001957 install_element (KEYCHAIN_NODE, &vtysh_end_all_cmd);
1958 install_element (KEYCHAIN_KEY_NODE, &vtysh_end_all_cmd);
1959 install_element (RMAP_NODE, &vtysh_end_all_cmd);
1960
paul338a9912003-03-01 15:44:10 +00001961 install_element (INTERFACE_NODE, &interface_desc_cmd);
paul464dc8d2003-03-28 02:25:45 +00001962 install_element (INTERFACE_NODE, &no_interface_desc_cmd);
paul718e3742002-12-13 20:15:29 +00001963 install_element (INTERFACE_NODE, &vtysh_end_all_cmd);
1964 install_element (INTERFACE_NODE, &vtysh_exit_interface_cmd);
1965 install_element (INTERFACE_NODE, &vtysh_quit_interface_cmd);
1966 install_element (CONFIG_NODE, &router_rip_cmd);
1967#ifdef HAVE_IPV6
1968 install_element (CONFIG_NODE, &router_ripng_cmd);
1969#endif
1970 install_element (CONFIG_NODE, &router_ospf_cmd);
1971#ifdef HAVE_IPV6
1972 install_element (CONFIG_NODE, &router_ospf6_cmd);
1973#endif
hassoc25e4582003-12-23 10:39:08 +00001974 install_element (CONFIG_NODE, &router_isis_cmd);
paul718e3742002-12-13 20:15:29 +00001975 install_element (CONFIG_NODE, &router_bgp_cmd);
1976 install_element (BGP_NODE, &address_family_vpnv4_cmd);
1977 install_element (BGP_NODE, &address_family_vpnv4_unicast_cmd);
1978 install_element (BGP_NODE, &address_family_ipv4_unicast_cmd);
1979 install_element (BGP_NODE, &address_family_ipv4_multicast_cmd);
1980#ifdef HAVE_IPV6
1981 install_element (BGP_NODE, &address_family_ipv6_cmd);
1982 install_element (BGP_NODE, &address_family_ipv6_unicast_cmd);
1983#endif
1984 install_element (BGP_VPNV4_NODE, &exit_address_family_cmd);
1985 install_element (BGP_IPV4_NODE, &exit_address_family_cmd);
1986 install_element (BGP_IPV4M_NODE, &exit_address_family_cmd);
1987 install_element (BGP_IPV6_NODE, &exit_address_family_cmd);
1988 install_element (CONFIG_NODE, &key_chain_cmd);
1989 install_element (CONFIG_NODE, &route_map_cmd);
1990 install_element (KEYCHAIN_NODE, &key_cmd);
1991 install_element (KEYCHAIN_NODE, &key_chain_cmd);
1992 install_element (KEYCHAIN_KEY_NODE, &key_chain_cmd);
1993 install_element (CONFIG_NODE, &vtysh_interface_cmd);
paul32d24632003-05-23 09:25:20 +00001994 install_element (CONFIG_NODE, &vtysh_no_interface_cmd);
paul718e3742002-12-13 20:15:29 +00001995 install_element (ENABLE_NODE, &vtysh_show_running_config_cmd);
1996 install_element (ENABLE_NODE, &vtysh_copy_runningconfig_startupconfig_cmd);
1997 install_element (ENABLE_NODE, &vtysh_write_file_cmd);
hasso4a6e2252003-05-25 11:51:29 +00001998 install_element (ENABLE_NODE, &vtysh_write_cmd);
paul718e3742002-12-13 20:15:29 +00001999
hasso95e735b2004-08-26 13:08:30 +00002000 /* "write terminal" command. */
paul718e3742002-12-13 20:15:29 +00002001 install_element (ENABLE_NODE, &vtysh_write_terminal_cmd);
2002 install_element (CONFIG_NODE, &vtysh_write_terminal_cmd);
2003 install_element (BGP_NODE, &vtysh_write_terminal_cmd);
2004 install_element (BGP_VPNV4_NODE, &vtysh_write_terminal_cmd);
2005 install_element (BGP_IPV4_NODE, &vtysh_write_terminal_cmd);
2006 install_element (BGP_IPV4M_NODE, &vtysh_write_terminal_cmd);
2007 install_element (BGP_IPV6_NODE, &vtysh_write_terminal_cmd);
2008 install_element (RIP_NODE, &vtysh_write_terminal_cmd);
2009 install_element (RIPNG_NODE, &vtysh_write_terminal_cmd);
2010 install_element (OSPF_NODE, &vtysh_write_terminal_cmd);
2011 install_element (OSPF6_NODE, &vtysh_write_terminal_cmd);
hassoc25e4582003-12-23 10:39:08 +00002012 install_element (ISIS_NODE, &vtysh_write_terminal_cmd);
paul718e3742002-12-13 20:15:29 +00002013 install_element (INTERFACE_NODE, &vtysh_write_terminal_cmd);
2014 install_element (RMAP_NODE, &vtysh_write_terminal_cmd);
2015 install_element (KEYCHAIN_NODE, &vtysh_write_terminal_cmd);
2016 install_element (KEYCHAIN_KEY_NODE, &vtysh_write_terminal_cmd);
2017
hasso95e735b2004-08-26 13:08:30 +00002018 /* "write memory" command. */
paul718e3742002-12-13 20:15:29 +00002019 install_element (ENABLE_NODE, &vtysh_write_memory_cmd);
2020 install_element (CONFIG_NODE, &vtysh_write_memory_cmd);
2021 install_element (BGP_NODE, &vtysh_write_memory_cmd);
2022 install_element (BGP_VPNV4_NODE, &vtysh_write_memory_cmd);
2023 install_element (BGP_IPV4_NODE, &vtysh_write_memory_cmd);
2024 install_element (BGP_IPV4M_NODE, &vtysh_write_memory_cmd);
2025 install_element (BGP_IPV6_NODE, &vtysh_write_memory_cmd);
2026 install_element (RIP_NODE, &vtysh_write_memory_cmd);
2027 install_element (RIPNG_NODE, &vtysh_write_memory_cmd);
2028 install_element (OSPF_NODE, &vtysh_write_memory_cmd);
2029 install_element (OSPF6_NODE, &vtysh_write_memory_cmd);
hassoc25e4582003-12-23 10:39:08 +00002030 install_element (ISIS_NODE, &vtysh_write_memory_cmd);
paul718e3742002-12-13 20:15:29 +00002031 install_element (INTERFACE_NODE, &vtysh_write_memory_cmd);
2032 install_element (RMAP_NODE, &vtysh_write_memory_cmd);
2033 install_element (KEYCHAIN_NODE, &vtysh_write_memory_cmd);
2034 install_element (KEYCHAIN_KEY_NODE, &vtysh_write_memory_cmd);
2035
hasso34553cc2004-08-27 13:56:39 +00002036 install_element (VIEW_NODE, &vtysh_terminal_length_cmd);
2037 install_element (ENABLE_NODE, &vtysh_terminal_length_cmd);
2038 install_element (VIEW_NODE, &vtysh_terminal_no_length_cmd);
2039 install_element (ENABLE_NODE, &vtysh_terminal_no_length_cmd);
2040
paul718e3742002-12-13 20:15:29 +00002041 install_element (VIEW_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002042 install_element (VIEW_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00002043 install_element (VIEW_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002044 install_element (VIEW_NODE, &vtysh_traceroute_ip_cmd);
2045#ifdef HAVE_IPV6
2046 install_element (VIEW_NODE, &vtysh_ping6_cmd);
2047 install_element (VIEW_NODE, &vtysh_traceroute6_cmd);
2048#endif
paul718e3742002-12-13 20:15:29 +00002049 install_element (VIEW_NODE, &vtysh_telnet_cmd);
2050 install_element (VIEW_NODE, &vtysh_telnet_port_cmd);
paul5087df52003-01-25 06:56:09 +00002051 install_element (VIEW_NODE, &vtysh_ssh_cmd);
paul718e3742002-12-13 20:15:29 +00002052 install_element (ENABLE_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002053 install_element (ENABLE_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00002054 install_element (ENABLE_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002055 install_element (ENABLE_NODE, &vtysh_traceroute_ip_cmd);
2056#ifdef HAVE_IPV6
2057 install_element (ENABLE_NODE, &vtysh_ping6_cmd);
2058 install_element (ENABLE_NODE, &vtysh_traceroute6_cmd);
2059#endif
paul718e3742002-12-13 20:15:29 +00002060 install_element (ENABLE_NODE, &vtysh_telnet_cmd);
2061 install_element (ENABLE_NODE, &vtysh_telnet_port_cmd);
hasso67e29ab2004-08-26 22:21:31 +00002062 install_element (ENABLE_NODE, &vtysh_ssh_cmd);
paul718e3742002-12-13 20:15:29 +00002063 install_element (ENABLE_NODE, &vtysh_start_shell_cmd);
2064 install_element (ENABLE_NODE, &vtysh_start_bash_cmd);
2065 install_element (ENABLE_NODE, &vtysh_start_zsh_cmd);
2066
paul718e3742002-12-13 20:15:29 +00002067 install_element (CONFIG_NODE, &vtysh_log_stdout_cmd);
2068 install_element (CONFIG_NODE, &no_vtysh_log_stdout_cmd);
2069 install_element (CONFIG_NODE, &vtysh_log_file_cmd);
2070 install_element (CONFIG_NODE, &no_vtysh_log_file_cmd);
2071 install_element (CONFIG_NODE, &vtysh_log_syslog_cmd);
2072 install_element (CONFIG_NODE, &no_vtysh_log_syslog_cmd);
2073 install_element (CONFIG_NODE, &vtysh_log_trap_cmd);
2074 install_element (CONFIG_NODE, &no_vtysh_log_trap_cmd);
2075 install_element (CONFIG_NODE, &vtysh_log_record_priority_cmd);
2076 install_element (CONFIG_NODE, &no_vtysh_log_record_priority_cmd);
paul4fc01e62002-12-13 20:49:00 +00002077 install_element (CONFIG_NODE, &vtysh_write_config_cmd);
2078 install_element (CONFIG_NODE, &no_vtysh_write_config_cmd);
paul718e3742002-12-13 20:15:29 +00002079}