blob: ba49edee98eaf7d4760abb4489019522d0411bfc [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;
paul2852de12004-09-17 06:52:16 +0000163 int i;
164 int numnulls = 0;
paul718e3742002-12-13 20:15:29 +0000165
166 if (vclient->fd < 0)
167 return CMD_SUCCESS;
168
169 ret = write (vclient->fd, line, strlen (line) + 1);
170 if (ret <= 0)
171 {
172 vclient_close (vclient);
173 return CMD_SUCCESS;
174 }
175
176 while (1)
177 {
178 nbytes = read (vclient->fd, buf, sizeof(buf)-1);
179
180 if (nbytes <= 0 && errno != EINTR)
181 {
182 vclient_close (vclient);
183 return CMD_SUCCESS;
184 }
185
186 if (nbytes > 0)
187 {
188 buf[nbytes] = '\0';
189 fprintf (fp, "%s", buf);
190 fflush (fp);
paul2852de12004-09-17 06:52:16 +0000191
192 /* check for trailling \0\0\0\0, even if split across reads */
193 if (nbytes >= 4)
194 {
195 i = nbytes-4;
196 numnulls = 0;
197 }
198 else
199 i = 0;
200
201 while (i < nbytes)
202 {
203 if (buf[i++] == '\0')
204 numnulls++;
205 else
206 {
207 numnulls = 0;
208 break;
209 }
210 }
paul718e3742002-12-13 20:15:29 +0000211
paul2852de12004-09-17 06:52:16 +0000212 /* got 3 or more trailling nulls? */
213 if (numnulls >= 3)
214 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000215 }
216 }
217 return ret;
218}
219
220void
221vtysh_exit_ripd_only ()
222{
223 vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIP], "exit", stdout);
224}
225
226
227void
228vtysh_pager_init ()
229{
hasso5a9c53d2004-08-27 14:23:28 +0000230 char *pager_defined;
231
232 pager_defined = getenv ("VTYSH_PAGER");
233
234 if (pager_defined)
235 vtysh_pager_name = strdup (pager_defined);
236 else
hasso34553cc2004-08-27 13:56:39 +0000237 vtysh_pager_name = strdup ("more");
paul718e3742002-12-13 20:15:29 +0000238}
239
240/* Command execution over the vty interface. */
241void
242vtysh_execute_func (char *line, int pager)
243{
244 int ret, cmd_stat;
245 vector vline;
246 struct cmd_element *cmd;
247 FILE *fp = NULL;
paula805cc22003-05-01 14:29:48 +0000248 int closepager=0;
paul718e3742002-12-13 20:15:29 +0000249
hasso95e735b2004-08-26 13:08:30 +0000250 /* Split readline string up into the vector. */
paul718e3742002-12-13 20:15:29 +0000251 vline = cmd_make_strvec (line);
252
253 if (vline == NULL)
254 return;
255
256 ret = cmd_execute_command (vline, vty, &cmd);
257
258 cmd_free_strvec (vline);
259
260 switch (ret)
261 {
262 case CMD_WARNING:
263 if (vty->type == VTY_FILE)
paul4fc01e62002-12-13 20:49:00 +0000264 fprintf (stdout,"Warning...\n");
paul718e3742002-12-13 20:15:29 +0000265 break;
266 case CMD_ERR_AMBIGUOUS:
paul4fc01e62002-12-13 20:49:00 +0000267 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000268 break;
269 case CMD_ERR_NO_MATCH:
paul4fc01e62002-12-13 20:49:00 +0000270 fprintf (stdout,"%% Unknown command.\n");
paul718e3742002-12-13 20:15:29 +0000271 break;
272 case CMD_ERR_INCOMPLETE:
paul4fc01e62002-12-13 20:49:00 +0000273 fprintf (stdout,"%% Command incomplete.\n");
paul718e3742002-12-13 20:15:29 +0000274 break;
275 case CMD_SUCCESS_DAEMON:
276 {
277 if (pager && vtysh_pager_name)
278 {
paul4fc01e62002-12-13 20:49:00 +0000279 fp = popen (vtysh_pager_name, "w");
paul718e3742002-12-13 20:15:29 +0000280 if (fp == NULL)
281 {
paula805cc22003-05-01 14:29:48 +0000282 perror ("popen failed for pager");
283 fp = stdout;
paul718e3742002-12-13 20:15:29 +0000284 }
paula805cc22003-05-01 14:29:48 +0000285 else
286 closepager=1;
paul718e3742002-12-13 20:15:29 +0000287 }
288 else
289 fp = stdout;
290
291 if (! strcmp(cmd->string,"configure terminal"))
292 {
293 cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ZEBRA],
294 line, fp);
295 if (cmd_stat != CMD_WARNING)
296 cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIP],
297 line, fp);
298 if (cmd_stat != CMD_WARNING)
hasso95e735b2004-08-26 13:08:30 +0000299 cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIPNG],
300 line, fp);
paul718e3742002-12-13 20:15:29 +0000301 if (cmd_stat != CMD_WARNING)
302 cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF],
303 line, fp);
304 if (cmd_stat != CMD_WARNING)
hasso95e735b2004-08-26 13:08:30 +0000305 cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF6],
306 line, fp);
paul718e3742002-12-13 20:15:29 +0000307 if (cmd_stat != CMD_WARNING)
308 cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_BGP],
309 line, fp);
hassob094d262004-08-25 12:22:00 +0000310 if (cmd_stat != CMD_WARNING)
hasso95e735b2004-08-26 13:08:30 +0000311 cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ISIS],
312 line, fp);
paul718e3742002-12-13 20:15:29 +0000313 if (cmd_stat)
314 {
hassob094d262004-08-25 12:22:00 +0000315 line = "end";
316 vline = cmd_make_strvec (line);
paul718e3742002-12-13 20:15:29 +0000317
hassob094d262004-08-25 12:22:00 +0000318 if (vline == NULL)
paul718e3742002-12-13 20:15:29 +0000319 {
paula805cc22003-05-01 14:29:48 +0000320 if (pager && vtysh_pager_name && fp && closepager)
paul718e3742002-12-13 20:15:29 +0000321 {
322 if (pclose (fp) == -1)
323 {
paula805cc22003-05-01 14:29:48 +0000324 perror ("pclose failed for pager");
paul718e3742002-12-13 20:15:29 +0000325 }
326 fp = NULL;
327 }
328 return;
329 }
330
hassob094d262004-08-25 12:22:00 +0000331 ret = cmd_execute_command (vline, vty, &cmd);
332 cmd_free_strvec (vline);
333 if (ret != CMD_SUCCESS_DAEMON)
334 break;
paul718e3742002-12-13 20:15:29 +0000335 }
336 else
337 if (cmd->func)
338 {
339 (*cmd->func) (cmd, vty, 0, NULL);
340 break;
hassob094d262004-08-25 12:22:00 +0000341 }
paul718e3742002-12-13 20:15:29 +0000342 }
343
344 if (cmd->daemon & VTYSH_ZEBRA)
345 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ZEBRA], line, fp)
346 != CMD_SUCCESS)
347 break;
348 if (cmd->daemon & VTYSH_RIPD)
349 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIP], line, fp)
350 != CMD_SUCCESS)
351 break;
352 if (cmd->daemon & VTYSH_RIPNGD)
353 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIPNG], line, fp)
354 != CMD_SUCCESS)
355 break;
356 if (cmd->daemon & VTYSH_OSPFD)
357 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF], line, fp)
358 != CMD_SUCCESS)
359 break;
360 if (cmd->daemon & VTYSH_OSPF6D)
361 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF6], line, fp)
362 != CMD_SUCCESS)
363 break;
364 if (cmd->daemon & VTYSH_BGPD)
365 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_BGP], line, fp)
366 != CMD_SUCCESS)
367 break;
hassob094d262004-08-25 12:22:00 +0000368 if (cmd->daemon & VTYSH_ISISD)
369 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ISIS], line, fp)
370 != CMD_SUCCESS)
371 break;
paul718e3742002-12-13 20:15:29 +0000372 if (cmd->func)
373 (*cmd->func) (cmd, vty, 0, NULL);
374 }
375 }
paula805cc22003-05-01 14:29:48 +0000376 if (pager && vtysh_pager_name && fp && closepager)
paul718e3742002-12-13 20:15:29 +0000377 {
378 if (pclose (fp) == -1)
379 {
paula805cc22003-05-01 14:29:48 +0000380 perror ("pclose failed for pager");
paul718e3742002-12-13 20:15:29 +0000381 }
382 fp = NULL;
383 }
384}
385
386void
387vtysh_execute_no_pager (char *line)
388{
389 vtysh_execute_func (line, 0);
390}
391
392void
393vtysh_execute (char *line)
394{
395 vtysh_execute_func (line, 1);
396}
397
398/* Configration make from file. */
399int
400vtysh_config_from_file (struct vty *vty, FILE *fp)
401{
402 int ret;
403 vector vline;
404 struct cmd_element *cmd;
405
406 while (fgets (vty->buf, VTY_BUFSIZ, fp))
407 {
408 if (vty->buf[0] == '!' || vty->buf[1] == '#')
409 continue;
410
411 vline = cmd_make_strvec (vty->buf);
412
hasso95e735b2004-08-26 13:08:30 +0000413 /* In case of comment line. */
paul718e3742002-12-13 20:15:29 +0000414 if (vline == NULL)
415 continue;
416
hasso95e735b2004-08-26 13:08:30 +0000417 /* Execute configuration command : this is strict match. */
paul718e3742002-12-13 20:15:29 +0000418 ret = cmd_execute_command_strict (vline, vty, &cmd);
419
hasso95e735b2004-08-26 13:08:30 +0000420 /* Try again with setting node to CONFIG_NODE. */
paul718e3742002-12-13 20:15:29 +0000421 if (ret != CMD_SUCCESS
422 && ret != CMD_SUCCESS_DAEMON
423 && ret != CMD_WARNING)
424 {
425 if (vty->node == KEYCHAIN_KEY_NODE)
426 {
427 vty->node = KEYCHAIN_NODE;
428 vtysh_exit_ripd_only ();
429 ret = cmd_execute_command_strict (vline, vty, &cmd);
430
431 if (ret != CMD_SUCCESS
432 && ret != CMD_SUCCESS_DAEMON
433 && ret != CMD_WARNING)
434 {
435 vtysh_exit_ripd_only ();
436 vty->node = CONFIG_NODE;
437 ret = cmd_execute_command_strict (vline, vty, &cmd);
438 }
439 }
440 else
441 {
442 vtysh_execute ("end");
443 vtysh_execute ("configure terminal");
444 vty->node = CONFIG_NODE;
445 ret = cmd_execute_command_strict (vline, vty, &cmd);
446 }
447 }
448
449 cmd_free_strvec (vline);
450
451 switch (ret)
452 {
453 case CMD_WARNING:
454 if (vty->type == VTY_FILE)
paul4fc01e62002-12-13 20:49:00 +0000455 fprintf (stdout,"Warning...\n");
paul718e3742002-12-13 20:15:29 +0000456 break;
457 case CMD_ERR_AMBIGUOUS:
paul4fc01e62002-12-13 20:49:00 +0000458 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000459 break;
460 case CMD_ERR_NO_MATCH:
paul4fc01e62002-12-13 20:49:00 +0000461 fprintf (stdout,"%% Unknown command: %s", vty->buf);
paul718e3742002-12-13 20:15:29 +0000462 break;
463 case CMD_ERR_INCOMPLETE:
paul4fc01e62002-12-13 20:49:00 +0000464 fprintf (stdout,"%% Command incomplete.\n");
paul718e3742002-12-13 20:15:29 +0000465 break;
466 case CMD_SUCCESS_DAEMON:
467 {
468 if (cmd->daemon & VTYSH_ZEBRA)
469 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ZEBRA],
470 vty->buf, stdout) != CMD_SUCCESS)
471 break;
472 if (cmd->daemon & VTYSH_RIPD)
473 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIP],
474 vty->buf, stdout) != CMD_SUCCESS)
475 break;
476 if (cmd->daemon & VTYSH_RIPNGD)
477 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIPNG],
478 vty->buf, stdout) != CMD_SUCCESS)
479 break;
480 if (cmd->daemon & VTYSH_OSPFD)
481 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF],
482 vty->buf, stdout) != CMD_SUCCESS)
483 break;
484 if (cmd->daemon & VTYSH_OSPF6D)
485 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF6],
486 vty->buf, stdout) != CMD_SUCCESS)
487 break;
488 if (cmd->daemon & VTYSH_BGPD)
489 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_BGP],
490 vty->buf, stdout) != CMD_SUCCESS)
491 break;
hassob094d262004-08-25 12:22:00 +0000492 if (cmd->daemon & VTYSH_ISISD)
493 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ISIS],
494 vty->buf, stdout) != CMD_SUCCESS)
495 break;
paul718e3742002-12-13 20:15:29 +0000496 if (cmd->func)
497 (*cmd->func) (cmd, vty, 0, NULL);
498 }
499 }
500 }
501 return CMD_SUCCESS;
502}
503
504/* We don't care about the point of the cursor when '?' is typed. */
505int
506vtysh_rl_describe ()
507{
508 int ret;
509 int i;
510 vector vline;
511 vector describe;
512 int width;
513 struct desc *desc;
514
515 vline = cmd_make_strvec (rl_line_buffer);
516
517 /* In case of '> ?'. */
518 if (vline == NULL)
519 {
520 vline = vector_init (1);
521 vector_set (vline, '\0');
522 }
523 else
524 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
525 vector_set (vline, '\0');
526
527 describe = cmd_describe_command (vline, vty, &ret);
528
paul4fc01e62002-12-13 20:49:00 +0000529 fprintf (stdout,"\n");
paul718e3742002-12-13 20:15:29 +0000530
531 /* Ambiguous and no match error. */
532 switch (ret)
533 {
534 case CMD_ERR_AMBIGUOUS:
535 cmd_free_strvec (vline);
paul4fc01e62002-12-13 20:49:00 +0000536 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000537 rl_on_new_line ();
538 return 0;
539 break;
540 case CMD_ERR_NO_MATCH:
541 cmd_free_strvec (vline);
paul4fc01e62002-12-13 20:49:00 +0000542 fprintf (stdout,"%% There is no matched command.\n");
paul718e3742002-12-13 20:15:29 +0000543 rl_on_new_line ();
544 return 0;
545 break;
546 }
547
548 /* Get width of command string. */
549 width = 0;
550 for (i = 0; i < vector_max (describe); i++)
551 if ((desc = vector_slot (describe, i)) != NULL)
552 {
553 int len;
554
555 if (desc->cmd[0] == '\0')
556 continue;
557
558 len = strlen (desc->cmd);
559 if (desc->cmd[0] == '.')
560 len--;
561
562 if (width < len)
563 width = len;
564 }
565
566 for (i = 0; i < vector_max (describe); i++)
567 if ((desc = vector_slot (describe, i)) != NULL)
568 {
569 if (desc->cmd[0] == '\0')
570 continue;
571
572 if (! desc->str)
paul4fc01e62002-12-13 20:49:00 +0000573 fprintf (stdout," %-s\n",
hassob094d262004-08-25 12:22:00 +0000574 desc->cmd[0] == '.' ? desc->cmd + 1 : desc->cmd);
paul718e3742002-12-13 20:15:29 +0000575 else
paul4fc01e62002-12-13 20:49:00 +0000576 fprintf (stdout," %-*s %s\n",
hassob094d262004-08-25 12:22:00 +0000577 width,
578 desc->cmd[0] == '.' ? desc->cmd + 1 : desc->cmd,
579 desc->str);
paul718e3742002-12-13 20:15:29 +0000580 }
581
582 cmd_free_strvec (vline);
583 vector_free (describe);
584
585 rl_on_new_line();
586
587 return 0;
588}
589
hasso95e735b2004-08-26 13:08:30 +0000590/* Result of cmd_complete_command() call will be stored here
591 * and used in new_completion() in order to put the space in
592 * correct places only. */
paul718e3742002-12-13 20:15:29 +0000593int complete_status;
594
595char *
pauldfc0d9b2003-04-18 23:55:29 +0000596command_generator (const char *text, int state)
paul718e3742002-12-13 20:15:29 +0000597{
598 vector vline;
599 static char **matched = NULL;
600 static int index = 0;
601
602 /* First call. */
603 if (! state)
604 {
605 index = 0;
606
607 if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
608 return NULL;
609
610 vline = cmd_make_strvec (rl_line_buffer);
611 if (vline == NULL)
612 return NULL;
613
614 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
615 vector_set (vline, '\0');
616
617 matched = cmd_complete_command (vline, vty, &complete_status);
618 }
619
620 if (matched && matched[index])
621 return matched[index++];
622
623 return NULL;
624}
625
626char **
627new_completion (char *text, int start, int end)
628{
629 char **matches;
630
pauldfc0d9b2003-04-18 23:55:29 +0000631 matches = rl_completion_matches (text, command_generator);
paul718e3742002-12-13 20:15:29 +0000632
633 if (matches)
634 {
635 rl_point = rl_end;
636 if (complete_status == CMD_COMPLETE_FULL_MATCH)
637 rl_pending_input = ' ';
638 }
639
640 return matches;
641}
642
643char **
644vtysh_completion (char *text, int start, int end)
645{
646 int ret;
647 vector vline;
648 char **matched = NULL;
649
650 if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
651 return NULL;
652
653 vline = cmd_make_strvec (rl_line_buffer);
654 if (vline == NULL)
655 return NULL;
656
657 /* In case of 'help \t'. */
658 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
659 vector_set (vline, '\0');
660
661 matched = cmd_complete_command (vline, vty, &ret);
662
663 cmd_free_strvec (vline);
664
665 return (char **) matched;
666}
667
hasso95e735b2004-08-26 13:08:30 +0000668/* Vty node structures. */
paul718e3742002-12-13 20:15:29 +0000669struct cmd_node bgp_node =
670{
671 BGP_NODE,
672 "%s(config-router)# ",
673};
674
paul718e3742002-12-13 20:15:29 +0000675struct cmd_node rip_node =
676{
677 RIP_NODE,
678 "%s(config-router)# ",
679};
680
hassoc25e4582003-12-23 10:39:08 +0000681struct cmd_node isis_node =
682{
683 ISIS_NODE,
684 "%s(config-router)# ",
hassoc25e4582003-12-23 10:39:08 +0000685};
686
paul718e3742002-12-13 20:15:29 +0000687struct cmd_node interface_node =
688{
689 INTERFACE_NODE,
690 "%s(config-if)# ",
691};
692
hasso95e735b2004-08-26 13:08:30 +0000693struct cmd_node rmap_node =
694{
695 RMAP_NODE,
696 "%s(config-route-map)# "
697};
698
699struct cmd_node zebra_node =
700{
701 ZEBRA_NODE,
702 "%s(config-router)# "
703};
704
705struct cmd_node bgp_vpnv4_node =
706{
707 BGP_VPNV4_NODE,
708 "%s(config-router-af)# "
709};
710
711struct cmd_node bgp_ipv4_node =
712{
713 BGP_IPV4_NODE,
714 "%s(config-router-af)# "
715};
716
717struct cmd_node bgp_ipv4m_node =
718{
719 BGP_IPV4M_NODE,
720 "%s(config-router-af)# "
721};
722
723struct cmd_node bgp_ipv6_node =
724{
725 BGP_IPV6_NODE,
726 "%s(config-router-af)# "
727};
728
729struct cmd_node ospf_node =
730{
731 OSPF_NODE,
732 "%s(config-router)# "
733};
734
735struct cmd_node ripng_node =
736{
737 RIPNG_NODE,
738 "%s(config-router)# "
739};
740
741struct cmd_node ospf6_node =
742{
743 OSPF6_NODE,
744 "%s(config-ospf6)# "
745};
746
747struct cmd_node keychain_node =
748{
749 KEYCHAIN_NODE,
750 "%s(config-keychain)# "
751};
752
753struct cmd_node keychain_key_node =
754{
755 KEYCHAIN_KEY_NODE,
756 "%s(config-keychain-key)# "
757};
758
759/* When '^Z' is received from vty, move down to the enable mode. */
760int
761vtysh_end ()
762{
763 switch (vty->node)
764 {
765 case VIEW_NODE:
766 case ENABLE_NODE:
767 /* Nothing to do. */
768 break;
769 default:
770 vty->node = ENABLE_NODE;
771 break;
772 }
773 return CMD_SUCCESS;
774}
775
776DEFUNSH (VTYSH_ALL,
777 vtysh_end_all,
778 vtysh_end_all_cmd,
779 "end",
780 "End current mode and down to previous mode\n")
781{
hasso42895462004-09-26 16:25:07 +0000782 return vtysh_end ();
hasso95e735b2004-08-26 13:08:30 +0000783}
784
paul718e3742002-12-13 20:15:29 +0000785DEFUNSH (VTYSH_BGPD,
786 router_bgp,
787 router_bgp_cmd,
788 "router bgp <1-65535>",
789 ROUTER_STR
790 BGP_STR
791 AS_STR)
792{
793 vty->node = BGP_NODE;
794 return CMD_SUCCESS;
795}
796
797DEFUNSH (VTYSH_BGPD,
798 address_family_vpnv4,
799 address_family_vpnv4_cmd,
800 "address-family vpnv4",
801 "Enter Address Family command mode\n"
802 "Address family\n")
803{
804 vty->node = BGP_VPNV4_NODE;
805 return CMD_SUCCESS;
806}
807
808DEFUNSH (VTYSH_BGPD,
809 address_family_vpnv4_unicast,
810 address_family_vpnv4_unicast_cmd,
811 "address-family vpnv4 unicast",
812 "Enter Address Family command mode\n"
813 "Address family\n"
814 "Address Family Modifier\n")
815{
816 vty->node = BGP_VPNV4_NODE;
817 return CMD_SUCCESS;
818}
819
820DEFUNSH (VTYSH_BGPD,
821 address_family_ipv4_unicast,
822 address_family_ipv4_unicast_cmd,
823 "address-family ipv4 unicast",
824 "Enter Address Family command mode\n"
825 "Address family\n"
826 "Address Family Modifier\n")
827{
828 vty->node = BGP_IPV4_NODE;
829 return CMD_SUCCESS;
830}
831
832DEFUNSH (VTYSH_BGPD,
833 address_family_ipv4_multicast,
834 address_family_ipv4_multicast_cmd,
835 "address-family ipv4 multicast",
836 "Enter Address Family command mode\n"
837 "Address family\n"
838 "Address Family Modifier\n")
839{
840 vty->node = BGP_IPV4M_NODE;
841 return CMD_SUCCESS;
842}
843
844DEFUNSH (VTYSH_BGPD,
845 address_family_ipv6,
846 address_family_ipv6_cmd,
847 "address-family ipv6",
848 "Enter Address Family command mode\n"
849 "Address family\n")
850{
851 vty->node = BGP_IPV6_NODE;
852 return CMD_SUCCESS;
853}
854
855DEFUNSH (VTYSH_BGPD,
856 address_family_ipv6_unicast,
857 address_family_ipv6_unicast_cmd,
858 "address-family ipv6 unicast",
859 "Enter Address Family command mode\n"
860 "Address family\n"
861 "Address Family Modifier\n")
862{
863 vty->node = BGP_IPV6_NODE;
864 return CMD_SUCCESS;
865}
866
867DEFUNSH (VTYSH_RIPD,
868 key_chain,
869 key_chain_cmd,
870 "key chain WORD",
871 "Authentication key management\n"
872 "Key-chain management\n"
873 "Key-chain name\n")
874{
875 vty->node = KEYCHAIN_NODE;
876 return CMD_SUCCESS;
877}
878
879DEFUNSH (VTYSH_RIPD,
880 key,
881 key_cmd,
882 "key <0-2147483647>",
883 "Configure a key\n"
884 "Key identifier number\n")
885{
886 vty->node = KEYCHAIN_KEY_NODE;
887 return CMD_SUCCESS;
888}
889
890DEFUNSH (VTYSH_RIPD,
891 router_rip,
892 router_rip_cmd,
893 "router rip",
894 ROUTER_STR
895 "RIP")
896{
897 vty->node = RIP_NODE;
898 return CMD_SUCCESS;
899}
900
901DEFUNSH (VTYSH_RIPNGD,
902 router_ripng,
903 router_ripng_cmd,
904 "router ripng",
905 ROUTER_STR
906 "RIPng")
907{
908 vty->node = RIPNG_NODE;
909 return CMD_SUCCESS;
910}
911
912DEFUNSH (VTYSH_OSPFD,
913 router_ospf,
914 router_ospf_cmd,
915 "router ospf",
916 "Enable a routing process\n"
917 "Start OSPF configuration\n")
918{
919 vty->node = OSPF_NODE;
920 return CMD_SUCCESS;
921}
922
923DEFUNSH (VTYSH_OSPF6D,
924 router_ospf6,
925 router_ospf6_cmd,
926 "router ospf6",
927 OSPF6_ROUTER_STR
928 OSPF6_STR)
929{
930 vty->node = OSPF6_NODE;
931 return CMD_SUCCESS;
932}
933
hassoc25e4582003-12-23 10:39:08 +0000934DEFUNSH (VTYSH_ISISD,
hassob094d262004-08-25 12:22:00 +0000935 router_isis,
936 router_isis_cmd,
937 "router isis WORD",
938 ROUTER_STR
939 "ISO IS-IS\n"
940 "ISO Routing area tag")
hassoc25e4582003-12-23 10:39:08 +0000941{
942 vty->node = ISIS_NODE;
943 return CMD_SUCCESS;
944}
945
paul718e3742002-12-13 20:15:29 +0000946DEFUNSH (VTYSH_RMAP,
947 route_map,
948 route_map_cmd,
949 "route-map WORD (deny|permit) <1-65535>",
950 "Create route-map or enter route-map command mode\n"
951 "Route map tag\n"
952 "Route map denies set operations\n"
953 "Route map permits set operations\n"
954 "Sequence to insert to/delete from existing route-map entry\n")
955{
956 vty->node = RMAP_NODE;
957 return CMD_SUCCESS;
958}
959
paul718e3742002-12-13 20:15:29 +0000960DEFUNSH (VTYSH_ALL,
961 vtysh_enable,
962 vtysh_enable_cmd,
963 "enable",
964 "Turn on privileged mode command\n")
965{
966 vty->node = ENABLE_NODE;
967 return CMD_SUCCESS;
968}
969
paul718e3742002-12-13 20:15:29 +0000970DEFUNSH (VTYSH_ALL,
971 vtysh_disable,
972 vtysh_disable_cmd,
973 "disable",
974 "Turn off privileged mode command\n")
975{
976 if (vty->node == ENABLE_NODE)
977 vty->node = VIEW_NODE;
978 return CMD_SUCCESS;
979}
980
paul718e3742002-12-13 20:15:29 +0000981DEFUNSH (VTYSH_ALL,
982 vtysh_config_terminal,
983 vtysh_config_terminal_cmd,
984 "configure terminal",
985 "Configuration from vty interface\n"
986 "Configuration terminal\n")
987{
988 vty->node = CONFIG_NODE;
989 return CMD_SUCCESS;
990}
991
992int
993vtysh_exit (struct vty *vty)
994{
995 switch (vty->node)
996 {
997 case VIEW_NODE:
998 case ENABLE_NODE:
999 exit (0);
1000 break;
1001 case CONFIG_NODE:
1002 vty->node = ENABLE_NODE;
1003 break;
1004 case INTERFACE_NODE:
1005 case ZEBRA_NODE:
1006 case BGP_NODE:
1007 case RIP_NODE:
1008 case RIPNG_NODE:
1009 case OSPF_NODE:
1010 case OSPF6_NODE:
hassoc25e4582003-12-23 10:39:08 +00001011 case ISIS_NODE:
paul718e3742002-12-13 20:15:29 +00001012 case MASC_NODE:
1013 case RMAP_NODE:
1014 case VTY_NODE:
1015 case KEYCHAIN_NODE:
hasso2a56df92004-05-09 23:16:40 +00001016 vtysh_execute("end");
1017 vtysh_execute("configure terminal");
paul718e3742002-12-13 20:15:29 +00001018 vty->node = CONFIG_NODE;
1019 break;
1020 case BGP_VPNV4_NODE:
1021 case BGP_IPV4_NODE:
1022 case BGP_IPV4M_NODE:
1023 case BGP_IPV6_NODE:
1024 vty->node = BGP_NODE;
1025 break;
1026 case KEYCHAIN_KEY_NODE:
1027 vty->node = KEYCHAIN_NODE;
1028 break;
1029 default:
1030 break;
1031 }
1032 return CMD_SUCCESS;
1033}
1034
1035DEFUNSH (VTYSH_ALL,
1036 vtysh_exit_all,
1037 vtysh_exit_all_cmd,
1038 "exit",
1039 "Exit current mode and down to previous mode\n")
1040{
1041 return vtysh_exit (vty);
1042}
1043
1044ALIAS (vtysh_exit_all,
1045 vtysh_quit_all_cmd,
1046 "quit",
1047 "Exit current mode and down to previous mode\n")
1048
1049DEFUNSH (VTYSH_BGPD,
1050 exit_address_family,
1051 exit_address_family_cmd,
1052 "exit-address-family",
1053 "Exit from Address Family configuration mode\n")
1054{
1055 if (vty->node == BGP_IPV4_NODE
1056 || vty->node == BGP_IPV4M_NODE
1057 || vty->node == BGP_VPNV4_NODE
1058 || vty->node == BGP_IPV6_NODE)
1059 vty->node = BGP_NODE;
1060 return CMD_SUCCESS;
1061}
1062
1063DEFUNSH (VTYSH_ZEBRA,
1064 vtysh_exit_zebra,
1065 vtysh_exit_zebra_cmd,
1066 "exit",
1067 "Exit current mode and down to previous mode\n")
1068{
1069 return vtysh_exit (vty);
1070}
1071
1072ALIAS (vtysh_exit_zebra,
1073 vtysh_quit_zebra_cmd,
1074 "quit",
1075 "Exit current mode and down to previous mode\n")
1076
1077DEFUNSH (VTYSH_RIPD,
1078 vtysh_exit_ripd,
1079 vtysh_exit_ripd_cmd,
1080 "exit",
1081 "Exit current mode and down to previous mode\n")
1082{
1083 return vtysh_exit (vty);
1084}
1085
1086ALIAS (vtysh_exit_ripd,
1087 vtysh_quit_ripd_cmd,
1088 "quit",
1089 "Exit current mode and down to previous mode\n")
1090
paul68980082003-03-25 05:07:42 +00001091DEFUNSH (VTYSH_RIPNGD,
hassob094d262004-08-25 12:22:00 +00001092 vtysh_exit_ripngd,
1093 vtysh_exit_ripngd_cmd,
1094 "exit",
1095 "Exit current mode and down to previous mode\n")
paul68980082003-03-25 05:07:42 +00001096{
1097 return vtysh_exit (vty);
1098}
1099
1100ALIAS (vtysh_exit_ripngd,
1101 vtysh_quit_ripngd_cmd,
1102 "quit",
1103 "Exit current mode and down to previous mode\n")
1104
paul718e3742002-12-13 20:15:29 +00001105DEFUNSH (VTYSH_RMAP,
1106 vtysh_exit_rmap,
1107 vtysh_exit_rmap_cmd,
1108 "exit",
1109 "Exit current mode and down to previous mode\n")
1110{
1111 return vtysh_exit (vty);
1112}
1113
1114ALIAS (vtysh_exit_rmap,
1115 vtysh_quit_rmap_cmd,
1116 "quit",
1117 "Exit current mode and down to previous mode\n")
1118
1119DEFUNSH (VTYSH_BGPD,
1120 vtysh_exit_bgpd,
1121 vtysh_exit_bgpd_cmd,
1122 "exit",
1123 "Exit current mode and down to previous mode\n")
1124{
1125 return vtysh_exit (vty);
1126}
1127
1128ALIAS (vtysh_exit_bgpd,
1129 vtysh_quit_bgpd_cmd,
1130 "quit",
1131 "Exit current mode and down to previous mode\n")
1132
1133DEFUNSH (VTYSH_OSPFD,
1134 vtysh_exit_ospfd,
1135 vtysh_exit_ospfd_cmd,
1136 "exit",
1137 "Exit current mode and down to previous mode\n")
1138{
1139 return vtysh_exit (vty);
1140}
1141
1142ALIAS (vtysh_exit_ospfd,
1143 vtysh_quit_ospfd_cmd,
1144 "quit",
1145 "Exit current mode and down to previous mode\n")
1146
paul68980082003-03-25 05:07:42 +00001147DEFUNSH (VTYSH_OSPF6D,
hassob094d262004-08-25 12:22:00 +00001148 vtysh_exit_ospf6d,
1149 vtysh_exit_ospf6d_cmd,
1150 "exit",
1151 "Exit current mode and down to previous mode\n")
paul68980082003-03-25 05:07:42 +00001152{
1153 return vtysh_exit (vty);
1154}
1155
1156ALIAS (vtysh_exit_ospf6d,
1157 vtysh_quit_ospf6d_cmd,
1158 "quit",
1159 "Exit current mode and down to previous mode\n")
1160
hassoc25e4582003-12-23 10:39:08 +00001161DEFUNSH (VTYSH_ISISD,
hassob094d262004-08-25 12:22:00 +00001162 vtysh_exit_isisd,
1163 vtysh_exit_isisd_cmd,
1164 "exit",
1165 "Exit current mode and down to previous mode\n")
hassoc25e4582003-12-23 10:39:08 +00001166{
1167 return vtysh_exit (vty);
1168}
1169
1170ALIAS (vtysh_exit_isisd,
1171 vtysh_quit_isisd_cmd,
1172 "quit",
1173 "Exit current mode and down to previous mode\n")
1174
hasso95e735b2004-08-26 13:08:30 +00001175DEFUNSH (VTYSH_INTERFACE,
paul718e3742002-12-13 20:15:29 +00001176 vtysh_interface,
1177 vtysh_interface_cmd,
1178 "interface IFNAME",
1179 "Select an interface to configure\n"
1180 "Interface's name\n")
1181{
1182 vty->node = INTERFACE_NODE;
1183 return CMD_SUCCESS;
1184}
1185
hasso95e735b2004-08-26 13:08:30 +00001186/* TODO Implement "no interface command in isisd. */
paul32d24632003-05-23 09:25:20 +00001187DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D,
1188 vtysh_no_interface_cmd,
1189 "no interface IFNAME",
1190 NO_STR
1191 "Delete a pseudo interface's configuration\n"
1192 "Interface's name\n")
1193
hasso95e735b2004-08-26 13:08:30 +00001194/* TODO Implement interface description commands in ripngd, ospf6d
1195 * and isisd. */
paul338a9912003-03-01 15:44:10 +00001196DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1197 interface_desc_cmd,
1198 "description .LINE",
1199 "Interface specific description\n"
1200 "Characters describing this interface\n")
paul464dc8d2003-03-28 02:25:45 +00001201
1202DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1203 no_interface_desc_cmd,
1204 "no description",
1205 NO_STR
1206 "Interface specific description\n")
paul338a9912003-03-01 15:44:10 +00001207
hasso95e735b2004-08-26 13:08:30 +00001208DEFUNSH (VTYSH_INTERFACE,
paul718e3742002-12-13 20:15:29 +00001209 vtysh_exit_interface,
1210 vtysh_exit_interface_cmd,
1211 "exit",
1212 "Exit current mode and down to previous mode\n")
1213{
1214 return vtysh_exit (vty);
1215}
1216
1217ALIAS (vtysh_exit_interface,
1218 vtysh_quit_interface_cmd,
1219 "quit",
1220 "Exit current mode and down to previous mode\n")
1221
hasso95e735b2004-08-26 13:08:30 +00001222/* Logging commands. */
1223DEFUNSH (VTYSH_ALL,
1224 vtysh_log_stdout,
1225 vtysh_log_stdout_cmd,
1226 "log stdout",
1227 "Logging control\n"
1228 "Logging goes to stdout\n")
1229{
1230 return CMD_SUCCESS;
1231}
1232
1233DEFUNSH (VTYSH_ALL,
1234 no_vtysh_log_stdout,
1235 no_vtysh_log_stdout_cmd,
1236 "no log stdout",
1237 NO_STR
1238 "Logging control\n"
1239 "Logging goes to stdout\n")
1240{
1241 return CMD_SUCCESS;
1242}
1243
1244DEFUNSH (VTYSH_ALL,
1245 vtysh_log_file,
1246 vtysh_log_file_cmd,
1247 "log file FILENAME",
1248 "Logging control\n"
1249 "Logging to file\n"
1250 "Logging filename\n")
1251{
1252 return CMD_SUCCESS;
1253}
1254
1255DEFUNSH (VTYSH_ALL,
1256 no_vtysh_log_file,
1257 no_vtysh_log_file_cmd,
1258 "no log file [FILENAME]",
1259 NO_STR
1260 "Logging control\n"
1261 "Cancel logging to file\n"
1262 "Logging file name\n")
1263{
1264 return CMD_SUCCESS;
1265}
1266
1267DEFUNSH (VTYSH_ALL,
1268 vtysh_log_syslog,
1269 vtysh_log_syslog_cmd,
1270 "log syslog",
1271 "Logging control\n"
1272 "Logging goes to syslog\n")
1273{
1274 return CMD_SUCCESS;
1275}
1276
1277DEFUNSH (VTYSH_ALL,
1278 no_vtysh_log_syslog,
1279 no_vtysh_log_syslog_cmd,
1280 "no log syslog",
1281 NO_STR
1282 "Logging control\n"
1283 "Cancel logging to syslog\n")
1284{
1285 return CMD_SUCCESS;
1286}
1287
1288DEFUNSH (VTYSH_ALL,
1289 vtysh_log_trap,
1290 vtysh_log_trap_cmd,
1291 "log trap (emergencies|alerts|critical|errors|warnings|\
1292 notifications|informational|debugging)",
1293 "Logging control\n"
1294 "Limit logging to specifed level\n")
1295{
1296 return CMD_SUCCESS;
1297}
1298
1299DEFUNSH (VTYSH_ALL,
1300 no_vtysh_log_trap,
1301 no_vtysh_log_trap_cmd,
1302 "no log trap",
1303 NO_STR
1304 "Logging control\n"
1305 "Permit all logging information\n")
1306{
1307 return CMD_SUCCESS;
1308}
1309
1310DEFUNSH (VTYSH_ALL,
1311 vtysh_log_record_priority,
1312 vtysh_log_record_priority_cmd,
1313 "log record-priority",
1314 "Logging control\n"
1315 "Log the priority of the message within the message\n")
1316{
1317 return CMD_SUCCESS;
1318}
1319
1320DEFUNSH (VTYSH_ALL,
1321 no_vtysh_log_record_priority,
1322 no_vtysh_log_record_priority_cmd,
1323 "no log record-priority",
1324 NO_STR
1325 "Logging control\n"
1326 "Do not log the priority of the message within the message\n")
1327{
1328 return CMD_SUCCESS;
1329}
1330
paul718e3742002-12-13 20:15:29 +00001331DEFUN (vtysh_write_terminal,
1332 vtysh_write_terminal_cmd,
1333 "write terminal",
1334 "Write running configuration to memory, network, or terminal\n"
1335 "Write to terminal\n")
1336{
1337 int ret;
1338 char line[] = "write terminal\n";
1339 FILE *fp = NULL;
1340
1341 if (vtysh_pager_name)
1342 {
paul4fc01e62002-12-13 20:49:00 +00001343 fp = popen (vtysh_pager_name, "w");
paul718e3742002-12-13 20:15:29 +00001344 if (fp == NULL)
1345 {
1346 perror ("popen");
1347 exit (1);
1348 }
1349 }
1350 else
1351 fp = stdout;
1352
1353 vty_out (vty, "Building configuration...%s", VTY_NEWLINE);
1354 vty_out (vty, "%sCurrent configuration:%s", VTY_NEWLINE,
1355 VTY_NEWLINE);
1356
1357 vtysh_config_write (fp);
1358
1359 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_ZEBRA], line);
1360 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_RIP], line);
1361 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_RIPNG], line);
1362 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_OSPF], line);
1363 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_OSPF6], line);
1364 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_BGP], line);
hassoc25e4582003-12-23 10:39:08 +00001365 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_ISIS], line);
paul718e3742002-12-13 20:15:29 +00001366
1367 vtysh_config_dump (fp);
1368
1369 if (vtysh_pager_name && fp)
1370 {
1371 fflush (fp);
1372 if (pclose (fp) == -1)
1373 {
1374 perror ("pclose");
1375 exit (1);
1376 }
1377 fp = NULL;
1378 }
1379
1380 return CMD_SUCCESS;
1381}
1382
paul4fc01e62002-12-13 20:49:00 +00001383struct vtysh_writeconfig_t {
1384 int daemon;
1385 int integrated;
1386} vtysh_wc = {-1,0};
1387
1388DEFUN (vtysh_write_config,
hassob094d262004-08-25 12:22:00 +00001389 vtysh_write_config_cmd,
1390 "write-config (daemon|integrated)",
1391 "Specify config files to write to\n"
1392 "Write per daemon file\n"
hasso95e735b2004-08-26 13:08:30 +00001393 "Write integrated file\n")
paul4fc01e62002-12-13 20:49:00 +00001394{
hasso95e735b2004-08-26 13:08:30 +00001395 if (!strncmp(argv[0],"d",1))
1396 vtysh_wc.daemon = 1;
1397 else if (!strncmp(argv[0],"i",1))
1398 vtysh_wc.integrated = 1;
1399
paul4fc01e62002-12-13 20:49:00 +00001400 return CMD_SUCCESS;
1401}
1402
1403DEFUN (no_vtysh_write_config,
hassob094d262004-08-25 12:22:00 +00001404 no_vtysh_write_config_cmd,
1405 "no write-config (daemon|integrated)",
hasso95e735b2004-08-26 13:08:30 +00001406 "Negate per daemon and/or integrated config files\n")
paul4fc01e62002-12-13 20:49:00 +00001407{
hasso95e735b2004-08-26 13:08:30 +00001408 if (!strncmp(argv[0],"d",1))
1409 vtysh_wc.daemon = 0;
1410 else if (!strncmp(argv[0],"i",1))
1411 vtysh_wc.integrated = 0;
1412
paul4fc01e62002-12-13 20:49:00 +00001413 return CMD_SUCCESS;
1414}
1415
1416int write_config_integrated(void)
paul718e3742002-12-13 20:15:29 +00001417{
1418 int ret;
paul718e3742002-12-13 20:15:29 +00001419 char line[] = "write terminal\n";
1420 FILE *fp;
1421 char *integrate_sav = NULL;
1422
hasso95e735b2004-08-26 13:08:30 +00001423 integrate_sav = malloc (strlen (integrate_default) +
1424 strlen (CONF_BACKUP_EXT) + 1);
paul718e3742002-12-13 20:15:29 +00001425 strcpy (integrate_sav, integrate_default);
1426 strcat (integrate_sav, CONF_BACKUP_EXT);
1427
paul4fc01e62002-12-13 20:49:00 +00001428 fprintf (stdout,"Building Configuration...\n");
paul718e3742002-12-13 20:15:29 +00001429
hasso95e735b2004-08-26 13:08:30 +00001430 /* Move current configuration file to backup config file. */
paul718e3742002-12-13 20:15:29 +00001431 unlink (integrate_sav);
1432 rename (integrate_default, integrate_sav);
hasso95e735b2004-08-26 13:08:30 +00001433 free (integrate_sav);
paul4fc01e62002-12-13 20:49:00 +00001434
paul718e3742002-12-13 20:15:29 +00001435 fp = fopen (integrate_default, "w");
1436 if (fp == NULL)
1437 {
hasso95e735b2004-08-26 13:08:30 +00001438 fprintf (stdout,"%% Can't open configuration file %s.\n",
1439 integrate_default);
paul718e3742002-12-13 20:15:29 +00001440 return CMD_SUCCESS;
1441 }
paul718e3742002-12-13 20:15:29 +00001442
1443 vtysh_config_write (fp);
1444
1445 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_ZEBRA], line);
1446 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_RIP], line);
1447 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_RIPNG], line);
1448 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_OSPF], line);
1449 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_OSPF6], line);
1450 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_BGP], line);
hassoc25e4582003-12-23 10:39:08 +00001451 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_ISIS], line);
paul718e3742002-12-13 20:15:29 +00001452
1453 vtysh_config_dump (fp);
1454
1455 fclose (fp);
1456
gdtaa593d52003-12-22 20:15:53 +00001457 if (chmod (integrate_default, CONFIGFILE_MASK) != 0)
1458 {
1459 fprintf (stdout,"%% Can't chmod configuration file %s: %s (%d)\n",
1460 integrate_default, strerror(errno), errno);
1461 return CMD_WARNING;
1462 }
1463
paul4fc01e62002-12-13 20:49:00 +00001464 fprintf(stdout,"Integrated configuration saved to %s\n",integrate_default);
1465
1466 fprintf (stdout,"[OK]\n");
1467
paul718e3742002-12-13 20:15:29 +00001468 return CMD_SUCCESS;
1469}
1470
paul4fc01e62002-12-13 20:49:00 +00001471DEFUN (vtysh_write_memory,
1472 vtysh_write_memory_cmd,
1473 "write memory",
1474 "Write running configuration to memory, network, or terminal\n"
1475 "Write configuration to the file (same as write file)\n")
1476{
pauldfc0d9b2003-04-18 23:55:29 +00001477 int ret = CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001478 char line[] = "write memory\n";
1479
hasso95e735b2004-08-26 13:08:30 +00001480 /* If integrated Zebra.conf explicitely set. */
1481 if (vtysh_wc.integrated == 1)
1482 ret = write_config_integrated();
paul4fc01e62002-12-13 20:49:00 +00001483
hasso95e735b2004-08-26 13:08:30 +00001484 if (!vtysh_wc.daemon)
1485 return ret;
paul4fc01e62002-12-13 20:49:00 +00001486
1487 fprintf (stdout,"Building Configuration...\n");
1488
1489 ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ZEBRA], line, stdout);
1490 ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIP], line, stdout);
1491 ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIPNG], line, stdout);
1492 ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF], line, stdout);
1493 ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF6], line, stdout);
1494 ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_BGP], line, stdout);
hassoc25e4582003-12-23 10:39:08 +00001495 ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ISIS], line, stdout);
paul4fc01e62002-12-13 20:49:00 +00001496
1497 fprintf (stdout,"[OK]\n");
1498
pauldfc0d9b2003-04-18 23:55:29 +00001499 return ret;
paul4fc01e62002-12-13 20:49:00 +00001500}
1501
paul718e3742002-12-13 20:15:29 +00001502ALIAS (vtysh_write_memory,
1503 vtysh_copy_runningconfig_startupconfig_cmd,
1504 "copy running-config startup-config",
1505 "Copy from one file to another\n"
1506 "Copy from current system configuration\n"
1507 "Copy to startup configuration\n")
1508
1509ALIAS (vtysh_write_memory,
1510 vtysh_write_file_cmd,
1511 "write file",
1512 "Write running configuration to memory, network, or terminal\n"
1513 "Write configuration to the file (same as write memory)\n")
1514
hasso4a6e2252003-05-25 11:51:29 +00001515ALIAS (vtysh_write_memory,
1516 vtysh_write_cmd,
1517 "write",
1518 "Write running configuration to memory, network, or terminal\n")
1519
paul718e3742002-12-13 20:15:29 +00001520ALIAS (vtysh_write_terminal,
1521 vtysh_show_running_config_cmd,
1522 "show running-config",
1523 SHOW_STR
1524 "Current operating configuration\n")
hassob094d262004-08-25 12:22:00 +00001525
hasso34553cc2004-08-27 13:56:39 +00001526DEFUN (vtysh_terminal_length,
1527 vtysh_terminal_length_cmd,
1528 "terminal length <0-512>",
1529 "Set terminal line parameters\n"
1530 "Set number of lines on a screen\n"
1531 "Number of lines on screen (0 for no pausing)\n")
1532{
1533 int lines;
1534 char *endptr = NULL;
1535 char default_pager[10];
1536
1537 lines = strtol (argv[0], &endptr, 10);
1538 if (lines < 0 || lines > 512 || *endptr != '\0')
1539 {
1540 vty_out (vty, "length is malformed%s", VTY_NEWLINE);
1541 return CMD_WARNING;
1542 }
1543
1544 if (vtysh_pager_name)
1545 {
1546 free (vtysh_pager_name);
1547 vtysh_pager_name = NULL;
1548 }
1549
1550 if (lines != 0)
1551 {
1552 snprintf(default_pager, 10, "more -%i", lines);
1553 vtysh_pager_name = strdup (default_pager);
1554 }
1555
1556 return CMD_SUCCESS;
1557}
1558
1559DEFUN (vtysh_terminal_no_length,
1560 vtysh_terminal_no_length_cmd,
1561 "terminal no length",
1562 "Set terminal line parameters\n"
1563 NO_STR
1564 "Set number of lines on a screen\n")
1565{
1566 if (vtysh_pager_name)
1567 {
1568 free (vtysh_pager_name);
1569 vtysh_pager_name = NULL;
1570 }
1571
1572 vtysh_pager_init();
1573 return CMD_SUCCESS;
1574}
1575
paul718e3742002-12-13 20:15:29 +00001576/* Execute command in child process. */
1577int
1578execute_command (char *command, int argc, char *arg1, char *arg2)
1579{
1580 int ret;
1581 pid_t pid;
1582 int status;
1583
1584 /* Call fork(). */
1585 pid = fork ();
1586
1587 if (pid < 0)
1588 {
1589 /* Failure of fork(). */
1590 fprintf (stderr, "Can't fork: %s\n", strerror (errno));
1591 exit (1);
1592 }
1593 else if (pid == 0)
1594 {
1595 /* This is child process. */
1596 switch (argc)
1597 {
1598 case 0:
hassofa2b17e2004-03-04 17:45:00 +00001599 ret = execlp (command, command, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00001600 break;
1601 case 1:
hassofa2b17e2004-03-04 17:45:00 +00001602 ret = execlp (command, command, arg1, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00001603 break;
1604 case 2:
hassofa2b17e2004-03-04 17:45:00 +00001605 ret = execlp (command, command, arg1, arg2, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00001606 break;
1607 }
1608
1609 /* When execlp suceed, this part is not executed. */
1610 fprintf (stderr, "Can't execute %s: %s\n", command, strerror (errno));
1611 exit (1);
1612 }
1613 else
1614 {
1615 /* This is parent. */
1616 execute_flag = 1;
1617 ret = wait4 (pid, &status, 0, NULL);
1618 execute_flag = 0;
1619 }
1620 return 0;
1621}
1622
1623DEFUN (vtysh_ping,
1624 vtysh_ping_cmd,
1625 "ping WORD",
hasso4eeccf12003-06-25 10:49:55 +00001626 "Send echo messages\n"
paul718e3742002-12-13 20:15:29 +00001627 "Ping destination address or hostname\n")
1628{
1629 execute_command ("ping", 1, argv[0], NULL);
1630 return CMD_SUCCESS;
1631}
1632
hasso4eeccf12003-06-25 10:49:55 +00001633ALIAS (vtysh_ping,
1634 vtysh_ping_ip_cmd,
1635 "ping ip WORD",
1636 "Send echo messages\n"
1637 "IP echo\n"
1638 "Ping destination address or hostname\n")
1639
paul718e3742002-12-13 20:15:29 +00001640DEFUN (vtysh_traceroute,
1641 vtysh_traceroute_cmd,
1642 "traceroute WORD",
1643 "Trace route to destination\n"
1644 "Trace route to destination address or hostname\n")
1645{
1646 execute_command ("traceroute", 1, argv[0], NULL);
1647 return CMD_SUCCESS;
1648}
1649
hasso4eeccf12003-06-25 10:49:55 +00001650ALIAS (vtysh_traceroute,
1651 vtysh_traceroute_ip_cmd,
1652 "traceroute ip WORD",
1653 "Trace route to destination\n"
1654 "IP trace\n"
1655 "Trace route to destination address or hostname\n")
1656
1657#ifdef HAVE_IPV6
1658DEFUN (vtysh_ping6,
1659 vtysh_ping6_cmd,
1660 "ping ipv6 WORD",
1661 "Send echo messages\n"
1662 "IPv6 echo\n"
1663 "Ping destination address or hostname\n")
1664{
1665 execute_command ("ping6", 1, argv[0], NULL);
1666 return CMD_SUCCESS;
1667}
1668
1669DEFUN (vtysh_traceroute6,
1670 vtysh_traceroute6_cmd,
1671 "traceroute ipv6 WORD",
1672 "Trace route to destination\n"
1673 "IPv6 trace\n"
1674 "Trace route to destination address or hostname\n")
1675{
1676 execute_command ("traceroute6", 1, argv[0], NULL);
1677 return CMD_SUCCESS;
1678}
1679#endif
1680
paul718e3742002-12-13 20:15:29 +00001681DEFUN (vtysh_telnet,
1682 vtysh_telnet_cmd,
1683 "telnet WORD",
1684 "Open a telnet connection\n"
1685 "IP address or hostname of a remote system\n")
1686{
1687 execute_command ("telnet", 1, argv[0], NULL);
1688 return CMD_SUCCESS;
1689}
1690
1691DEFUN (vtysh_telnet_port,
1692 vtysh_telnet_port_cmd,
1693 "telnet WORD PORT",
1694 "Open a telnet connection\n"
1695 "IP address or hostname of a remote system\n"
1696 "TCP Port number\n")
1697{
1698 execute_command ("telnet", 2, argv[0], argv[1]);
1699 return CMD_SUCCESS;
1700}
1701
paul5087df52003-01-25 06:56:09 +00001702DEFUN (vtysh_ssh,
1703 vtysh_ssh_cmd,
1704 "ssh WORD",
1705 "Open an ssh connection\n"
1706 "[user@]host\n")
1707{
1708 execute_command ("ssh", 1, argv[0], NULL);
1709 return CMD_SUCCESS;
1710}
1711
paul718e3742002-12-13 20:15:29 +00001712DEFUN (vtysh_start_shell,
1713 vtysh_start_shell_cmd,
1714 "start-shell",
1715 "Start UNIX shell\n")
1716{
1717 execute_command ("sh", 0, NULL, NULL);
1718 return CMD_SUCCESS;
1719}
1720
1721DEFUN (vtysh_start_bash,
1722 vtysh_start_bash_cmd,
1723 "start-shell bash",
1724 "Start UNIX shell\n"
1725 "Start bash\n")
1726{
1727 execute_command ("bash", 0, NULL, NULL);
1728 return CMD_SUCCESS;
1729}
1730
1731DEFUN (vtysh_start_zsh,
1732 vtysh_start_zsh_cmd,
1733 "start-shell zsh",
1734 "Start UNIX shell\n"
1735 "Start Z shell\n")
1736{
1737 execute_command ("zsh", 0, NULL, NULL);
1738 return CMD_SUCCESS;
1739}
hassob094d262004-08-25 12:22:00 +00001740
paul718e3742002-12-13 20:15:29 +00001741void
1742vtysh_install_default (enum node_type node)
1743{
1744 install_element (node, &config_list_cmd);
1745}
1746
1747/* Making connection to protocol daemon. */
1748int
1749vtysh_connect (struct vtysh_client *vclient, char *path)
1750{
1751 int ret;
1752 int sock, len;
1753 struct sockaddr_un addr;
1754 struct stat s_stat;
1755 uid_t euid;
1756 gid_t egid;
1757
1758 memset (vclient, 0, sizeof (struct vtysh_client));
1759 vclient->fd = -1;
1760
1761 /* Stat socket to see if we have permission to access it. */
1762 euid = geteuid();
1763 egid = getegid();
1764 ret = stat (path, &s_stat);
1765 if (ret < 0 && errno != ENOENT)
1766 {
1767 fprintf (stderr, "vtysh_connect(%s): stat = %s\n",
1768 path, strerror(errno));
1769 exit(1);
1770 }
1771
1772 if (ret >= 0)
1773 {
1774 if (! S_ISSOCK(s_stat.st_mode))
1775 {
1776 fprintf (stderr, "vtysh_connect(%s): Not a socket\n",
1777 path);
1778 exit (1);
1779 }
1780
paul718e3742002-12-13 20:15:29 +00001781 }
1782
1783 sock = socket (AF_UNIX, SOCK_STREAM, 0);
1784 if (sock < 0)
1785 {
1786#ifdef DEBUG
hasso95e735b2004-08-26 13:08:30 +00001787 fprintf(stderr, "vtysh_connect(%s): socket = %s\n", path,
1788 strerror(errno));
paul718e3742002-12-13 20:15:29 +00001789#endif /* DEBUG */
1790 return -1;
1791 }
1792
1793 memset (&addr, 0, sizeof (struct sockaddr_un));
1794 addr.sun_family = AF_UNIX;
1795 strncpy (addr.sun_path, path, strlen (path));
1796#ifdef HAVE_SUN_LEN
1797 len = addr.sun_len = SUN_LEN(&addr);
1798#else
1799 len = sizeof (addr.sun_family) + strlen (addr.sun_path);
1800#endif /* HAVE_SUN_LEN */
1801
1802 ret = connect (sock, (struct sockaddr *) &addr, len);
1803 if (ret < 0)
1804 {
1805#ifdef DEBUG
hasso95e735b2004-08-26 13:08:30 +00001806 fprintf(stderr, "vtysh_connect(%s): connect = %s\n", path,
1807 strerror(errno));
paul718e3742002-12-13 20:15:29 +00001808#endif /* DEBUG */
1809 close (sock);
1810 return -1;
1811 }
1812 vclient->fd = sock;
1813
1814 return 0;
1815}
1816
1817void
1818vtysh_connect_all()
1819{
1820 /* Clear each daemons client structure. */
paulfe067782003-04-07 16:10:05 +00001821 vtysh_connect (&vtysh_client[VTYSH_INDEX_ZEBRA], ZEBRA_VTYSH_PATH);
1822 vtysh_connect (&vtysh_client[VTYSH_INDEX_RIP], RIP_VTYSH_PATH);
1823 vtysh_connect (&vtysh_client[VTYSH_INDEX_RIPNG], RIPNG_VTYSH_PATH);
1824 vtysh_connect (&vtysh_client[VTYSH_INDEX_OSPF], OSPF_VTYSH_PATH);
1825 vtysh_connect (&vtysh_client[VTYSH_INDEX_OSPF6], OSPF6_VTYSH_PATH);
1826 vtysh_connect (&vtysh_client[VTYSH_INDEX_BGP], BGP_VTYSH_PATH);
hassoc25e4582003-12-23 10:39:08 +00001827 vtysh_connect (&vtysh_client[VTYSH_INDEX_ISIS], ISIS_VTYSH_PATH);
paul718e3742002-12-13 20:15:29 +00001828}
1829
hasso95e735b2004-08-26 13:08:30 +00001830/* To disable readline's filename completion. */
pauldfc0d9b2003-04-18 23:55:29 +00001831char *
1832vtysh_completion_entry_function (const char *ignore, int invoking_key)
paul718e3742002-12-13 20:15:29 +00001833{
pauldfc0d9b2003-04-18 23:55:29 +00001834 return NULL;
paul718e3742002-12-13 20:15:29 +00001835}
1836
1837void
1838vtysh_readline_init ()
1839{
1840 /* readline related settings. */
1841 rl_bind_key ('?', vtysh_rl_describe);
paul68980082003-03-25 05:07:42 +00001842 rl_completion_entry_function = vtysh_completion_entry_function;
paul718e3742002-12-13 20:15:29 +00001843 rl_attempted_completion_function = (CPPFunction *)new_completion;
1844 /* do not append space after completion. It will be appended
hasso95e735b2004-08-26 13:08:30 +00001845 * in new_completion() function explicitly. */
paul718e3742002-12-13 20:15:29 +00001846 rl_completion_append_character = '\0';
1847}
1848
1849char *
1850vtysh_prompt ()
1851{
1852 struct utsname names;
1853 static char buf[100];
1854 const char*hostname;
1855 extern struct host host;
1856
1857 hostname = host.name;
1858
1859 if (!hostname)
1860 {
1861 uname (&names);
1862 hostname = names.nodename;
1863 }
1864
1865 snprintf (buf, sizeof buf, cmd_prompt (vty->node), hostname);
1866
1867 return buf;
1868}
1869
1870void
1871vtysh_init_vty ()
1872{
1873 /* Make vty structure. */
1874 vty = vty_new ();
1875 vty->type = VTY_SHELL;
1876 vty->node = VIEW_NODE;
1877
1878 /* Initialize commands. */
1879 cmd_init (0);
1880
1881 /* Install nodes. */
1882 install_node (&bgp_node, NULL);
1883 install_node (&rip_node, NULL);
1884 install_node (&interface_node, NULL);
1885 install_node (&rmap_node, NULL);
1886 install_node (&zebra_node, NULL);
1887 install_node (&bgp_vpnv4_node, NULL);
1888 install_node (&bgp_ipv4_node, NULL);
1889 install_node (&bgp_ipv4m_node, NULL);
1890/* #ifdef HAVE_IPV6 */
1891 install_node (&bgp_ipv6_node, NULL);
1892/* #endif */
1893 install_node (&ospf_node, NULL);
1894/* #ifdef HAVE_IPV6 */
1895 install_node (&ripng_node, NULL);
1896 install_node (&ospf6_node, NULL);
1897/* #endif */
1898 install_node (&keychain_node, NULL);
1899 install_node (&keychain_key_node, NULL);
hassoc25e4582003-12-23 10:39:08 +00001900 install_node (&isis_node, NULL);
paul718e3742002-12-13 20:15:29 +00001901
1902 vtysh_install_default (VIEW_NODE);
1903 vtysh_install_default (ENABLE_NODE);
1904 vtysh_install_default (CONFIG_NODE);
1905 vtysh_install_default (BGP_NODE);
1906 vtysh_install_default (RIP_NODE);
1907 vtysh_install_default (INTERFACE_NODE);
1908 vtysh_install_default (RMAP_NODE);
1909 vtysh_install_default (ZEBRA_NODE);
1910 vtysh_install_default (BGP_VPNV4_NODE);
1911 vtysh_install_default (BGP_IPV4_NODE);
1912 vtysh_install_default (BGP_IPV4M_NODE);
1913 vtysh_install_default (BGP_IPV6_NODE);
1914 vtysh_install_default (OSPF_NODE);
1915 vtysh_install_default (RIPNG_NODE);
1916 vtysh_install_default (OSPF6_NODE);
hassoc25e4582003-12-23 10:39:08 +00001917 vtysh_install_default (ISIS_NODE);
paul718e3742002-12-13 20:15:29 +00001918 vtysh_install_default (KEYCHAIN_NODE);
1919 vtysh_install_default (KEYCHAIN_KEY_NODE);
1920
1921 install_element (VIEW_NODE, &vtysh_enable_cmd);
1922 install_element (ENABLE_NODE, &vtysh_config_terminal_cmd);
1923 install_element (ENABLE_NODE, &vtysh_disable_cmd);
1924
1925 /* "exit" command. */
1926 install_element (VIEW_NODE, &vtysh_exit_all_cmd);
1927 install_element (VIEW_NODE, &vtysh_quit_all_cmd);
1928 install_element (CONFIG_NODE, &vtysh_exit_all_cmd);
1929 /* install_element (CONFIG_NODE, &vtysh_quit_all_cmd); */
1930 install_element (ENABLE_NODE, &vtysh_exit_all_cmd);
1931 install_element (ENABLE_NODE, &vtysh_quit_all_cmd);
1932 install_element (RIP_NODE, &vtysh_exit_ripd_cmd);
1933 install_element (RIP_NODE, &vtysh_quit_ripd_cmd);
paul68980082003-03-25 05:07:42 +00001934 install_element (RIPNG_NODE, &vtysh_exit_ripngd_cmd);
1935 install_element (RIPNG_NODE, &vtysh_quit_ripngd_cmd);
paul718e3742002-12-13 20:15:29 +00001936 install_element (OSPF_NODE, &vtysh_exit_ospfd_cmd);
1937 install_element (OSPF_NODE, &vtysh_quit_ospfd_cmd);
paul68980082003-03-25 05:07:42 +00001938 install_element (OSPF6_NODE, &vtysh_exit_ospf6d_cmd);
1939 install_element (OSPF6_NODE, &vtysh_quit_ospf6d_cmd);
paul718e3742002-12-13 20:15:29 +00001940 install_element (BGP_NODE, &vtysh_exit_bgpd_cmd);
1941 install_element (BGP_NODE, &vtysh_quit_bgpd_cmd);
1942 install_element (BGP_VPNV4_NODE, &vtysh_exit_bgpd_cmd);
1943 install_element (BGP_VPNV4_NODE, &vtysh_quit_bgpd_cmd);
1944 install_element (BGP_IPV4_NODE, &vtysh_exit_bgpd_cmd);
1945 install_element (BGP_IPV4_NODE, &vtysh_quit_bgpd_cmd);
1946 install_element (BGP_IPV4M_NODE, &vtysh_exit_bgpd_cmd);
1947 install_element (BGP_IPV4M_NODE, &vtysh_quit_bgpd_cmd);
1948 install_element (BGP_IPV6_NODE, &vtysh_exit_bgpd_cmd);
1949 install_element (BGP_IPV6_NODE, &vtysh_quit_bgpd_cmd);
hassoc25e4582003-12-23 10:39:08 +00001950 install_element (ISIS_NODE, &vtysh_exit_isisd_cmd);
1951 install_element (ISIS_NODE, &vtysh_quit_isisd_cmd);
paul718e3742002-12-13 20:15:29 +00001952 install_element (KEYCHAIN_NODE, &vtysh_exit_ripd_cmd);
1953 install_element (KEYCHAIN_NODE, &vtysh_quit_ripd_cmd);
1954 install_element (KEYCHAIN_KEY_NODE, &vtysh_exit_ripd_cmd);
1955 install_element (KEYCHAIN_KEY_NODE, &vtysh_quit_ripd_cmd);
1956 install_element (RMAP_NODE, &vtysh_exit_rmap_cmd);
1957 install_element (RMAP_NODE, &vtysh_quit_rmap_cmd);
1958
1959 /* "end" command. */
1960 install_element (CONFIG_NODE, &vtysh_end_all_cmd);
1961 install_element (ENABLE_NODE, &vtysh_end_all_cmd);
1962 install_element (RIP_NODE, &vtysh_end_all_cmd);
1963 install_element (RIPNG_NODE, &vtysh_end_all_cmd);
1964 install_element (OSPF_NODE, &vtysh_end_all_cmd);
1965 install_element (OSPF6_NODE, &vtysh_end_all_cmd);
1966 install_element (BGP_NODE, &vtysh_end_all_cmd);
1967 install_element (BGP_IPV4_NODE, &vtysh_end_all_cmd);
1968 install_element (BGP_IPV4M_NODE, &vtysh_end_all_cmd);
1969 install_element (BGP_VPNV4_NODE, &vtysh_end_all_cmd);
1970 install_element (BGP_IPV6_NODE, &vtysh_end_all_cmd);
hassoc25e4582003-12-23 10:39:08 +00001971 install_element (ISIS_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00001972 install_element (KEYCHAIN_NODE, &vtysh_end_all_cmd);
1973 install_element (KEYCHAIN_KEY_NODE, &vtysh_end_all_cmd);
1974 install_element (RMAP_NODE, &vtysh_end_all_cmd);
1975
paul338a9912003-03-01 15:44:10 +00001976 install_element (INTERFACE_NODE, &interface_desc_cmd);
paul464dc8d2003-03-28 02:25:45 +00001977 install_element (INTERFACE_NODE, &no_interface_desc_cmd);
paul718e3742002-12-13 20:15:29 +00001978 install_element (INTERFACE_NODE, &vtysh_end_all_cmd);
1979 install_element (INTERFACE_NODE, &vtysh_exit_interface_cmd);
1980 install_element (INTERFACE_NODE, &vtysh_quit_interface_cmd);
1981 install_element (CONFIG_NODE, &router_rip_cmd);
1982#ifdef HAVE_IPV6
1983 install_element (CONFIG_NODE, &router_ripng_cmd);
1984#endif
1985 install_element (CONFIG_NODE, &router_ospf_cmd);
1986#ifdef HAVE_IPV6
1987 install_element (CONFIG_NODE, &router_ospf6_cmd);
1988#endif
hassoc25e4582003-12-23 10:39:08 +00001989 install_element (CONFIG_NODE, &router_isis_cmd);
paul718e3742002-12-13 20:15:29 +00001990 install_element (CONFIG_NODE, &router_bgp_cmd);
1991 install_element (BGP_NODE, &address_family_vpnv4_cmd);
1992 install_element (BGP_NODE, &address_family_vpnv4_unicast_cmd);
1993 install_element (BGP_NODE, &address_family_ipv4_unicast_cmd);
1994 install_element (BGP_NODE, &address_family_ipv4_multicast_cmd);
1995#ifdef HAVE_IPV6
1996 install_element (BGP_NODE, &address_family_ipv6_cmd);
1997 install_element (BGP_NODE, &address_family_ipv6_unicast_cmd);
1998#endif
1999 install_element (BGP_VPNV4_NODE, &exit_address_family_cmd);
2000 install_element (BGP_IPV4_NODE, &exit_address_family_cmd);
2001 install_element (BGP_IPV4M_NODE, &exit_address_family_cmd);
2002 install_element (BGP_IPV6_NODE, &exit_address_family_cmd);
2003 install_element (CONFIG_NODE, &key_chain_cmd);
2004 install_element (CONFIG_NODE, &route_map_cmd);
2005 install_element (KEYCHAIN_NODE, &key_cmd);
2006 install_element (KEYCHAIN_NODE, &key_chain_cmd);
2007 install_element (KEYCHAIN_KEY_NODE, &key_chain_cmd);
2008 install_element (CONFIG_NODE, &vtysh_interface_cmd);
paul32d24632003-05-23 09:25:20 +00002009 install_element (CONFIG_NODE, &vtysh_no_interface_cmd);
paul718e3742002-12-13 20:15:29 +00002010 install_element (ENABLE_NODE, &vtysh_show_running_config_cmd);
2011 install_element (ENABLE_NODE, &vtysh_copy_runningconfig_startupconfig_cmd);
2012 install_element (ENABLE_NODE, &vtysh_write_file_cmd);
hasso4a6e2252003-05-25 11:51:29 +00002013 install_element (ENABLE_NODE, &vtysh_write_cmd);
paul718e3742002-12-13 20:15:29 +00002014
hasso95e735b2004-08-26 13:08:30 +00002015 /* "write terminal" command. */
paul718e3742002-12-13 20:15:29 +00002016 install_element (ENABLE_NODE, &vtysh_write_terminal_cmd);
2017 install_element (CONFIG_NODE, &vtysh_write_terminal_cmd);
2018 install_element (BGP_NODE, &vtysh_write_terminal_cmd);
2019 install_element (BGP_VPNV4_NODE, &vtysh_write_terminal_cmd);
2020 install_element (BGP_IPV4_NODE, &vtysh_write_terminal_cmd);
2021 install_element (BGP_IPV4M_NODE, &vtysh_write_terminal_cmd);
2022 install_element (BGP_IPV6_NODE, &vtysh_write_terminal_cmd);
2023 install_element (RIP_NODE, &vtysh_write_terminal_cmd);
2024 install_element (RIPNG_NODE, &vtysh_write_terminal_cmd);
2025 install_element (OSPF_NODE, &vtysh_write_terminal_cmd);
2026 install_element (OSPF6_NODE, &vtysh_write_terminal_cmd);
hassoc25e4582003-12-23 10:39:08 +00002027 install_element (ISIS_NODE, &vtysh_write_terminal_cmd);
paul718e3742002-12-13 20:15:29 +00002028 install_element (INTERFACE_NODE, &vtysh_write_terminal_cmd);
2029 install_element (RMAP_NODE, &vtysh_write_terminal_cmd);
2030 install_element (KEYCHAIN_NODE, &vtysh_write_terminal_cmd);
2031 install_element (KEYCHAIN_KEY_NODE, &vtysh_write_terminal_cmd);
2032
hasso95e735b2004-08-26 13:08:30 +00002033 /* "write memory" command. */
paul718e3742002-12-13 20:15:29 +00002034 install_element (ENABLE_NODE, &vtysh_write_memory_cmd);
2035 install_element (CONFIG_NODE, &vtysh_write_memory_cmd);
2036 install_element (BGP_NODE, &vtysh_write_memory_cmd);
2037 install_element (BGP_VPNV4_NODE, &vtysh_write_memory_cmd);
2038 install_element (BGP_IPV4_NODE, &vtysh_write_memory_cmd);
2039 install_element (BGP_IPV4M_NODE, &vtysh_write_memory_cmd);
2040 install_element (BGP_IPV6_NODE, &vtysh_write_memory_cmd);
2041 install_element (RIP_NODE, &vtysh_write_memory_cmd);
2042 install_element (RIPNG_NODE, &vtysh_write_memory_cmd);
2043 install_element (OSPF_NODE, &vtysh_write_memory_cmd);
2044 install_element (OSPF6_NODE, &vtysh_write_memory_cmd);
hassoc25e4582003-12-23 10:39:08 +00002045 install_element (ISIS_NODE, &vtysh_write_memory_cmd);
paul718e3742002-12-13 20:15:29 +00002046 install_element (INTERFACE_NODE, &vtysh_write_memory_cmd);
2047 install_element (RMAP_NODE, &vtysh_write_memory_cmd);
2048 install_element (KEYCHAIN_NODE, &vtysh_write_memory_cmd);
2049 install_element (KEYCHAIN_KEY_NODE, &vtysh_write_memory_cmd);
2050
hasso34553cc2004-08-27 13:56:39 +00002051 install_element (VIEW_NODE, &vtysh_terminal_length_cmd);
2052 install_element (ENABLE_NODE, &vtysh_terminal_length_cmd);
2053 install_element (VIEW_NODE, &vtysh_terminal_no_length_cmd);
2054 install_element (ENABLE_NODE, &vtysh_terminal_no_length_cmd);
2055
paul718e3742002-12-13 20:15:29 +00002056 install_element (VIEW_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002057 install_element (VIEW_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00002058 install_element (VIEW_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002059 install_element (VIEW_NODE, &vtysh_traceroute_ip_cmd);
2060#ifdef HAVE_IPV6
2061 install_element (VIEW_NODE, &vtysh_ping6_cmd);
2062 install_element (VIEW_NODE, &vtysh_traceroute6_cmd);
2063#endif
paul718e3742002-12-13 20:15:29 +00002064 install_element (VIEW_NODE, &vtysh_telnet_cmd);
2065 install_element (VIEW_NODE, &vtysh_telnet_port_cmd);
paul5087df52003-01-25 06:56:09 +00002066 install_element (VIEW_NODE, &vtysh_ssh_cmd);
paul718e3742002-12-13 20:15:29 +00002067 install_element (ENABLE_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002068 install_element (ENABLE_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00002069 install_element (ENABLE_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002070 install_element (ENABLE_NODE, &vtysh_traceroute_ip_cmd);
2071#ifdef HAVE_IPV6
2072 install_element (ENABLE_NODE, &vtysh_ping6_cmd);
2073 install_element (ENABLE_NODE, &vtysh_traceroute6_cmd);
2074#endif
paul718e3742002-12-13 20:15:29 +00002075 install_element (ENABLE_NODE, &vtysh_telnet_cmd);
2076 install_element (ENABLE_NODE, &vtysh_telnet_port_cmd);
hasso67e29ab2004-08-26 22:21:31 +00002077 install_element (ENABLE_NODE, &vtysh_ssh_cmd);
paul718e3742002-12-13 20:15:29 +00002078 install_element (ENABLE_NODE, &vtysh_start_shell_cmd);
2079 install_element (ENABLE_NODE, &vtysh_start_bash_cmd);
2080 install_element (ENABLE_NODE, &vtysh_start_zsh_cmd);
2081
paul718e3742002-12-13 20:15:29 +00002082 install_element (CONFIG_NODE, &vtysh_log_stdout_cmd);
2083 install_element (CONFIG_NODE, &no_vtysh_log_stdout_cmd);
2084 install_element (CONFIG_NODE, &vtysh_log_file_cmd);
2085 install_element (CONFIG_NODE, &no_vtysh_log_file_cmd);
2086 install_element (CONFIG_NODE, &vtysh_log_syslog_cmd);
2087 install_element (CONFIG_NODE, &no_vtysh_log_syslog_cmd);
2088 install_element (CONFIG_NODE, &vtysh_log_trap_cmd);
2089 install_element (CONFIG_NODE, &no_vtysh_log_trap_cmd);
2090 install_element (CONFIG_NODE, &vtysh_log_record_priority_cmd);
2091 install_element (CONFIG_NODE, &no_vtysh_log_record_priority_cmd);
paul4fc01e62002-12-13 20:49:00 +00002092 install_element (CONFIG_NODE, &vtysh_write_config_cmd);
2093 install_element (CONFIG_NODE, &no_vtysh_write_config_cmd);
paul718e3742002-12-13 20:15:29 +00002094}