blob: bad05d98548a17434f2757a9c2b7a7d66b16c36b [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"
ajs6099b3b2004-11-20 02:06:59 +000036#include "log.h"
Paul Jakma320da872008-07-02 13:40:33 +000037#include "bgpd/bgp_vty.h"
paul718e3742002-12-13 20:15:29 +000038
39/* Struct VTY. */
40struct vty *vty;
41
42/* VTY shell pager name. */
43char *vtysh_pager_name = NULL;
44
45/* VTY shell client structure. */
46struct vtysh_client
47{
48 int fd;
ajsb1aa1472005-01-28 21:11:46 +000049 const char *name;
50 int flag;
51 const char *path;
52} vtysh_client[] =
53{
54 { .fd = -1, .name = "zebra", .flag = VTYSH_ZEBRA, .path = ZEBRA_VTYSH_PATH},
55 { .fd = -1, .name = "ripd", .flag = VTYSH_RIPD, .path = RIP_VTYSH_PATH},
56 { .fd = -1, .name = "ripngd", .flag = VTYSH_RIPNGD, .path = RIPNG_VTYSH_PATH},
57 { .fd = -1, .name = "ospfd", .flag = VTYSH_OSPFD, .path = OSPF_VTYSH_PATH},
58 { .fd = -1, .name = "ospf6d", .flag = VTYSH_OSPF6D, .path = OSPF6_VTYSH_PATH},
59 { .fd = -1, .name = "bgpd", .flag = VTYSH_BGPD, .path = BGP_VTYSH_PATH},
60 { .fd = -1, .name = "isisd", .flag = VTYSH_ISISD, .path = ISIS_VTYSH_PATH},
61};
62
63#define VTYSH_INDEX_MAX (sizeof(vtysh_client)/sizeof(vtysh_client[0]))
64
65/* We need direct access to ripd to implement vtysh_exit_ripd_only. */
66static struct vtysh_client *ripd_client = NULL;
67
hassob094d262004-08-25 12:22:00 +000068
hassoe7168df2004-10-03 20:11:32 +000069/* Using integrated config from Quagga.conf. Default is no. */
70int vtysh_writeconfig_integrated = 0;
71
72extern char config_default[];
73
ajs274a4a42004-12-07 15:39:31 +000074static void
paul718e3742002-12-13 20:15:29 +000075vclient_close (struct vtysh_client *vclient)
76{
ajsb1aa1472005-01-28 21:11:46 +000077 if (vclient->fd >= 0)
78 {
79 fprintf(stderr,
80 "Warning: closing connection to %s because of an I/O error!\n",
81 vclient->name);
82 close (vclient->fd);
83 vclient->fd = -1;
84 }
paul718e3742002-12-13 20:15:29 +000085}
86
paul718e3742002-12-13 20:15:29 +000087/* Following filled with debug code to trace a problematic condition
hasso95e735b2004-08-26 13:08:30 +000088 * under load - it SHOULD handle it. */
paul718e3742002-12-13 20:15:29 +000089#define ERR_WHERE_STRING "vtysh(): vtysh_client_config(): "
ajs274a4a42004-12-07 15:39:31 +000090static int
paul718e3742002-12-13 20:15:29 +000091vtysh_client_config (struct vtysh_client *vclient, char *line)
92{
93 int ret;
94 char *buf;
95 size_t bufsz;
96 char *pbuf;
97 size_t left;
98 char *eoln;
99 int nbytes;
100 int i;
101 int readln;
102
103 if (vclient->fd < 0)
104 return CMD_SUCCESS;
105
106 ret = write (vclient->fd, line, strlen (line) + 1);
107 if (ret <= 0)
108 {
109 vclient_close (vclient);
110 return CMD_SUCCESS;
111 }
112
hasso95e735b2004-08-26 13:08:30 +0000113 /* Allow enough room for buffer to read more than a few pages from socket. */
paule3d29b52003-01-23 18:05:42 +0000114 bufsz = 5 * getpagesize() + 1;
paul718e3742002-12-13 20:15:29 +0000115 buf = XMALLOC(MTYPE_TMP, bufsz);
116 memset(buf, 0, bufsz);
117 pbuf = buf;
118
119 while (1)
120 {
121 if (pbuf >= ((buf + bufsz) -1))
122 {
123 fprintf (stderr, ERR_WHERE_STRING \
124 "warning - pbuf beyond buffer end.\n");
125 return CMD_WARNING;
126 }
127
128 readln = (buf + bufsz) - pbuf - 1;
129 nbytes = read (vclient->fd, pbuf, readln);
130
131 if (nbytes <= 0)
132 {
133
134 if (errno == EINTR)
135 continue;
136
137 fprintf(stderr, ERR_WHERE_STRING "(%u)", errno);
138 perror("");
139
140 if (errno == EAGAIN || errno == EIO)
141 continue;
142
143 vclient_close (vclient);
144 XFREE(MTYPE_TMP, buf);
145 return CMD_SUCCESS;
146 }
147
148 pbuf[nbytes] = '\0';
149
150 if (nbytes >= 4)
151 {
152 i = nbytes - 4;
153 if (pbuf[i] == '\0' && pbuf[i + 1] == '\0' && pbuf[i + 2] == '\0')
154 {
155 ret = pbuf[i + 3];
156 break;
157 }
158 }
159 pbuf += nbytes;
160
161 /* See if a line exists in buffer, if so parse and consume it, and
hasso95e735b2004-08-26 13:08:30 +0000162 * reset read position. */
paul718e3742002-12-13 20:15:29 +0000163 if ((eoln = strrchr(buf, '\n')) == NULL)
164 continue;
165
166 if (eoln >= ((buf + bufsz) - 1))
167 {
168 fprintf (stderr, ERR_WHERE_STRING \
169 "warning - eoln beyond buffer end.\n");
170 }
171 vtysh_config_parse(buf);
172
173 eoln++;
174 left = (size_t)(buf + bufsz - eoln);
175 memmove(buf, eoln, left);
176 buf[bufsz-1] = '\0';
177 pbuf = buf + strlen(buf);
178 }
179
hasso95e735b2004-08-26 13:08:30 +0000180 /* Parse anything left in the buffer. */
hassoe7168df2004-10-03 20:11:32 +0000181
paul718e3742002-12-13 20:15:29 +0000182 vtysh_config_parse (buf);
183
184 XFREE(MTYPE_TMP, buf);
185 return ret;
186}
187
ajs274a4a42004-12-07 15:39:31 +0000188static int
hassodda09522004-10-07 21:40:25 +0000189vtysh_client_execute (struct vtysh_client *vclient, const char *line, FILE *fp)
paul718e3742002-12-13 20:15:29 +0000190{
191 int ret;
192 char buf[1001];
193 int nbytes;
paul2852de12004-09-17 06:52:16 +0000194 int i;
195 int numnulls = 0;
paul718e3742002-12-13 20:15:29 +0000196
197 if (vclient->fd < 0)
198 return CMD_SUCCESS;
199
200 ret = write (vclient->fd, line, strlen (line) + 1);
201 if (ret <= 0)
202 {
203 vclient_close (vclient);
204 return CMD_SUCCESS;
205 }
206
207 while (1)
208 {
209 nbytes = read (vclient->fd, buf, sizeof(buf)-1);
210
211 if (nbytes <= 0 && errno != EINTR)
212 {
213 vclient_close (vclient);
214 return CMD_SUCCESS;
215 }
216
217 if (nbytes > 0)
218 {
ajs85fb1e62004-11-11 14:03:39 +0000219 if ((numnulls == 3) && (nbytes == 1))
220 return buf[0];
221
paul718e3742002-12-13 20:15:29 +0000222 buf[nbytes] = '\0';
ajs85fb1e62004-11-11 14:03:39 +0000223 fputs (buf, fp);
paul718e3742002-12-13 20:15:29 +0000224 fflush (fp);
paul2852de12004-09-17 06:52:16 +0000225
paul0921d482004-10-11 18:21:55 +0000226 /* check for trailling \0\0\0<ret code>,
227 * even if split across reads
228 * (see lib/vty.c::vtysh_read)
229 */
paul2852de12004-09-17 06:52:16 +0000230 if (nbytes >= 4)
231 {
232 i = nbytes-4;
233 numnulls = 0;
234 }
235 else
236 i = 0;
237
paul0921d482004-10-11 18:21:55 +0000238 while (i < nbytes && numnulls < 3)
paul2852de12004-09-17 06:52:16 +0000239 {
240 if (buf[i++] == '\0')
241 numnulls++;
242 else
ajs85fb1e62004-11-11 14:03:39 +0000243 numnulls = 0;
paul2852de12004-09-17 06:52:16 +0000244 }
paul718e3742002-12-13 20:15:29 +0000245
ajs85fb1e62004-11-11 14:03:39 +0000246 /* got 3 or more trailing NULs? */
247 if ((numnulls >= 3) && (i < nbytes))
paul0921d482004-10-11 18:21:55 +0000248 return (buf[nbytes-1]);
paul718e3742002-12-13 20:15:29 +0000249 }
250 }
paul718e3742002-12-13 20:15:29 +0000251}
252
253void
ajsb1aa1472005-01-28 21:11:46 +0000254vtysh_exit_ripd_only (void)
paul718e3742002-12-13 20:15:29 +0000255{
ajsb1aa1472005-01-28 21:11:46 +0000256 if (ripd_client)
257 vtysh_client_execute (ripd_client, "exit", stdout);
paul718e3742002-12-13 20:15:29 +0000258}
259
260
261void
ajsb1aa1472005-01-28 21:11:46 +0000262vtysh_pager_init (void)
paul718e3742002-12-13 20:15:29 +0000263{
hasso5a9c53d2004-08-27 14:23:28 +0000264 char *pager_defined;
265
266 pager_defined = getenv ("VTYSH_PAGER");
267
268 if (pager_defined)
269 vtysh_pager_name = strdup (pager_defined);
270 else
hasso34553cc2004-08-27 13:56:39 +0000271 vtysh_pager_name = strdup ("more");
paul718e3742002-12-13 20:15:29 +0000272}
273
274/* Command execution over the vty interface. */
ajs274a4a42004-12-07 15:39:31 +0000275static void
hassodda09522004-10-07 21:40:25 +0000276vtysh_execute_func (const char *line, int pager)
paul718e3742002-12-13 20:15:29 +0000277{
278 int ret, cmd_stat;
ajsb1aa1472005-01-28 21:11:46 +0000279 u_int i;
paul718e3742002-12-13 20:15:29 +0000280 vector vline;
281 struct cmd_element *cmd;
282 FILE *fp = NULL;
hasso13bfca72005-01-23 21:42:25 +0000283 int closepager = 0;
284 int tried = 0;
285 int saved_ret, saved_node;
paul718e3742002-12-13 20:15:29 +0000286
hasso95e735b2004-08-26 13:08:30 +0000287 /* Split readline string up into the vector. */
paul718e3742002-12-13 20:15:29 +0000288 vline = cmd_make_strvec (line);
289
290 if (vline == NULL)
291 return;
292
hasso13bfca72005-01-23 21:42:25 +0000293 saved_ret = ret = cmd_execute_command (vline, vty, &cmd, 1);
294 saved_node = vty->node;
295
296 /* If command doesn't succeeded in current node, try to walk up in node tree.
297 * Changing vty->node is enough to try it just out without actual walkup in
298 * the vtysh. */
299 while (ret != CMD_SUCCESS && ret != CMD_SUCCESS_DAEMON && ret != CMD_WARNING
300 && vty->node > CONFIG_NODE)
301 {
302 vty->node = node_parent(vty->node);
303 ret = cmd_execute_command (vline, vty, &cmd, 1);
304 tried++;
305 }
306
307 vty->node = saved_node;
308
309 /* If command succeeded in any other node than current (tried > 0) we have
310 * to move into node in the vtysh where it succeeded. */
311 if (ret == CMD_SUCCESS || ret == CMD_SUCCESS_DAEMON || ret == CMD_WARNING)
312 {
313 if ((saved_node == BGP_VPNV4_NODE || saved_node == BGP_IPV4_NODE
paul57b5b7e2005-08-22 22:44:29 +0000314 || saved_node == BGP_IPV6_NODE || saved_node == BGP_IPV4M_NODE
315 || saved_node == BGP_IPV6M_NODE)
hasso13bfca72005-01-23 21:42:25 +0000316 && (tried == 1))
317 {
318 vtysh_execute("exit-address-family");
319 }
320 else if ((saved_node == KEYCHAIN_KEY_NODE) && (tried == 1))
321 {
322 vtysh_execute("exit");
323 }
324 else if (tried)
325 {
326 vtysh_execute ("end");
327 vtysh_execute ("configure terminal");
328 }
329 }
330 /* If command didn't succeed in any node, continue with return value from
331 * first try. */
332 else if (tried)
333 {
334 ret = saved_ret;
335 }
paul718e3742002-12-13 20:15:29 +0000336
337 cmd_free_strvec (vline);
338
339 switch (ret)
340 {
341 case CMD_WARNING:
342 if (vty->type == VTY_FILE)
paul4fc01e62002-12-13 20:49:00 +0000343 fprintf (stdout,"Warning...\n");
paul718e3742002-12-13 20:15:29 +0000344 break;
345 case CMD_ERR_AMBIGUOUS:
paul4fc01e62002-12-13 20:49:00 +0000346 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000347 break;
348 case CMD_ERR_NO_MATCH:
paul4fc01e62002-12-13 20:49:00 +0000349 fprintf (stdout,"%% Unknown command.\n");
paul718e3742002-12-13 20:15:29 +0000350 break;
351 case CMD_ERR_INCOMPLETE:
paul4fc01e62002-12-13 20:49:00 +0000352 fprintf (stdout,"%% Command incomplete.\n");
paul718e3742002-12-13 20:15:29 +0000353 break;
354 case CMD_SUCCESS_DAEMON:
355 {
hasso97b7db22004-10-20 19:07:48 +0000356 /* FIXME: Don't open pager for exit commands. popen() causes problems
357 * if exited from vtysh at all. This hack shouldn't cause any problem
358 * but is really ugly. */
359 if (pager && vtysh_pager_name && (strncmp(line, "exit", 4) != 0))
paul718e3742002-12-13 20:15:29 +0000360 {
paul4fc01e62002-12-13 20:49:00 +0000361 fp = popen (vtysh_pager_name, "w");
paul718e3742002-12-13 20:15:29 +0000362 if (fp == NULL)
363 {
paula805cc22003-05-01 14:29:48 +0000364 perror ("popen failed for pager");
365 fp = stdout;
paul718e3742002-12-13 20:15:29 +0000366 }
paula805cc22003-05-01 14:29:48 +0000367 else
368 closepager=1;
paul718e3742002-12-13 20:15:29 +0000369 }
370 else
371 fp = stdout;
372
373 if (! strcmp(cmd->string,"configure terminal"))
374 {
ajsb1aa1472005-01-28 21:11:46 +0000375 for (i = 0; i < VTYSH_INDEX_MAX; i++)
376 {
377 cmd_stat = vtysh_client_execute(&vtysh_client[i], line, fp);
378 if (cmd_stat == CMD_WARNING)
379 break;
380 }
381
paul718e3742002-12-13 20:15:29 +0000382 if (cmd_stat)
383 {
hassob094d262004-08-25 12:22:00 +0000384 line = "end";
385 vline = cmd_make_strvec (line);
paul718e3742002-12-13 20:15:29 +0000386
hassob094d262004-08-25 12:22:00 +0000387 if (vline == NULL)
paul718e3742002-12-13 20:15:29 +0000388 {
paula805cc22003-05-01 14:29:48 +0000389 if (pager && vtysh_pager_name && fp && closepager)
paul718e3742002-12-13 20:15:29 +0000390 {
391 if (pclose (fp) == -1)
392 {
paula805cc22003-05-01 14:29:48 +0000393 perror ("pclose failed for pager");
paul718e3742002-12-13 20:15:29 +0000394 }
395 fp = NULL;
396 }
397 return;
398 }
399
hasso87d683b2005-01-16 23:31:54 +0000400 ret = cmd_execute_command (vline, vty, &cmd, 1);
hassob094d262004-08-25 12:22:00 +0000401 cmd_free_strvec (vline);
402 if (ret != CMD_SUCCESS_DAEMON)
403 break;
paul718e3742002-12-13 20:15:29 +0000404 }
405 else
406 if (cmd->func)
407 {
408 (*cmd->func) (cmd, vty, 0, NULL);
409 break;
hassob094d262004-08-25 12:22:00 +0000410 }
paul718e3742002-12-13 20:15:29 +0000411 }
412
ajsb1aa1472005-01-28 21:11:46 +0000413 cmd_stat = CMD_SUCCESS;
414 for (i = 0; i < VTYSH_INDEX_MAX; i++)
415 {
416 if (cmd->daemon & vtysh_client[i].flag)
417 {
418 cmd_stat = vtysh_client_execute(&vtysh_client[i], line, fp);
419 if (cmd_stat != CMD_SUCCESS)
420 break;
421 }
422 }
423 if (cmd_stat != CMD_SUCCESS)
424 break;
425
paul718e3742002-12-13 20:15:29 +0000426 if (cmd->func)
427 (*cmd->func) (cmd, vty, 0, NULL);
428 }
429 }
paula805cc22003-05-01 14:29:48 +0000430 if (pager && vtysh_pager_name && fp && closepager)
paul718e3742002-12-13 20:15:29 +0000431 {
432 if (pclose (fp) == -1)
433 {
paula805cc22003-05-01 14:29:48 +0000434 perror ("pclose failed for pager");
paul718e3742002-12-13 20:15:29 +0000435 }
436 fp = NULL;
437 }
438}
439
440void
hassodda09522004-10-07 21:40:25 +0000441vtysh_execute_no_pager (const char *line)
paul718e3742002-12-13 20:15:29 +0000442{
443 vtysh_execute_func (line, 0);
444}
445
446void
hassodda09522004-10-07 21:40:25 +0000447vtysh_execute (const char *line)
paul718e3742002-12-13 20:15:29 +0000448{
449 vtysh_execute_func (line, 1);
450}
451
452/* Configration make from file. */
453int
454vtysh_config_from_file (struct vty *vty, FILE *fp)
455{
456 int ret;
457 vector vline;
458 struct cmd_element *cmd;
459
460 while (fgets (vty->buf, VTY_BUFSIZ, fp))
461 {
462 if (vty->buf[0] == '!' || vty->buf[1] == '#')
463 continue;
464
465 vline = cmd_make_strvec (vty->buf);
466
hasso95e735b2004-08-26 13:08:30 +0000467 /* In case of comment line. */
paul718e3742002-12-13 20:15:29 +0000468 if (vline == NULL)
469 continue;
470
hasso95e735b2004-08-26 13:08:30 +0000471 /* Execute configuration command : this is strict match. */
paul718e3742002-12-13 20:15:29 +0000472 ret = cmd_execute_command_strict (vline, vty, &cmd);
473
hasso95e735b2004-08-26 13:08:30 +0000474 /* Try again with setting node to CONFIG_NODE. */
paul718e3742002-12-13 20:15:29 +0000475 if (ret != CMD_SUCCESS
476 && ret != CMD_SUCCESS_DAEMON
477 && ret != CMD_WARNING)
478 {
479 if (vty->node == KEYCHAIN_KEY_NODE)
480 {
481 vty->node = KEYCHAIN_NODE;
482 vtysh_exit_ripd_only ();
483 ret = cmd_execute_command_strict (vline, vty, &cmd);
484
485 if (ret != CMD_SUCCESS
486 && ret != CMD_SUCCESS_DAEMON
487 && ret != CMD_WARNING)
488 {
489 vtysh_exit_ripd_only ();
490 vty->node = CONFIG_NODE;
491 ret = cmd_execute_command_strict (vline, vty, &cmd);
492 }
493 }
494 else
495 {
496 vtysh_execute ("end");
497 vtysh_execute ("configure terminal");
498 vty->node = CONFIG_NODE;
499 ret = cmd_execute_command_strict (vline, vty, &cmd);
500 }
501 }
502
503 cmd_free_strvec (vline);
504
505 switch (ret)
506 {
507 case CMD_WARNING:
508 if (vty->type == VTY_FILE)
paul4fc01e62002-12-13 20:49:00 +0000509 fprintf (stdout,"Warning...\n");
paul718e3742002-12-13 20:15:29 +0000510 break;
511 case CMD_ERR_AMBIGUOUS:
paul4fc01e62002-12-13 20:49:00 +0000512 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000513 break;
514 case CMD_ERR_NO_MATCH:
paul4fc01e62002-12-13 20:49:00 +0000515 fprintf (stdout,"%% Unknown command: %s", vty->buf);
paul718e3742002-12-13 20:15:29 +0000516 break;
517 case CMD_ERR_INCOMPLETE:
paul4fc01e62002-12-13 20:49:00 +0000518 fprintf (stdout,"%% Command incomplete.\n");
paul718e3742002-12-13 20:15:29 +0000519 break;
520 case CMD_SUCCESS_DAEMON:
521 {
ajsb1aa1472005-01-28 21:11:46 +0000522 u_int i;
523 int cmd_stat = CMD_SUCCESS;
524
525 for (i = 0; i < VTYSH_INDEX_MAX; i++)
526 {
paul44316fe2006-01-11 01:38:25 +0000527 if (cmd->daemon & vtysh_client[i].flag)
ajsb1aa1472005-01-28 21:11:46 +0000528 {
529 cmd_stat = vtysh_client_execute (&vtysh_client[i],
530 vty->buf, stdout);
531 if (cmd_stat != CMD_SUCCESS)
532 break;
533 }
534 }
535 if (cmd_stat != CMD_SUCCESS)
536 break;
537
paul718e3742002-12-13 20:15:29 +0000538 if (cmd->func)
539 (*cmd->func) (cmd, vty, 0, NULL);
540 }
541 }
542 }
543 return CMD_SUCCESS;
544}
545
546/* We don't care about the point of the cursor when '?' is typed. */
547int
ajsb1aa1472005-01-28 21:11:46 +0000548vtysh_rl_describe (void)
paul718e3742002-12-13 20:15:29 +0000549{
550 int ret;
hassodda09522004-10-07 21:40:25 +0000551 unsigned int i;
paul718e3742002-12-13 20:15:29 +0000552 vector vline;
553 vector describe;
554 int width;
555 struct desc *desc;
556
557 vline = cmd_make_strvec (rl_line_buffer);
558
559 /* In case of '> ?'. */
560 if (vline == NULL)
561 {
562 vline = vector_init (1);
563 vector_set (vline, '\0');
564 }
565 else
566 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
567 vector_set (vline, '\0');
568
569 describe = cmd_describe_command (vline, vty, &ret);
570
paul4fc01e62002-12-13 20:49:00 +0000571 fprintf (stdout,"\n");
paul718e3742002-12-13 20:15:29 +0000572
573 /* Ambiguous and no match error. */
574 switch (ret)
575 {
576 case CMD_ERR_AMBIGUOUS:
577 cmd_free_strvec (vline);
paul4fc01e62002-12-13 20:49:00 +0000578 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000579 rl_on_new_line ();
580 return 0;
581 break;
582 case CMD_ERR_NO_MATCH:
583 cmd_free_strvec (vline);
paul4fc01e62002-12-13 20:49:00 +0000584 fprintf (stdout,"%% There is no matched command.\n");
paul718e3742002-12-13 20:15:29 +0000585 rl_on_new_line ();
586 return 0;
587 break;
588 }
589
590 /* Get width of command string. */
591 width = 0;
paul55468c82005-03-14 20:19:01 +0000592 for (i = 0; i < vector_active (describe); i++)
paul718e3742002-12-13 20:15:29 +0000593 if ((desc = vector_slot (describe, i)) != NULL)
594 {
595 int len;
596
597 if (desc->cmd[0] == '\0')
598 continue;
599
600 len = strlen (desc->cmd);
601 if (desc->cmd[0] == '.')
602 len--;
603
604 if (width < len)
605 width = len;
606 }
607
paul55468c82005-03-14 20:19:01 +0000608 for (i = 0; i < vector_active (describe); i++)
paul718e3742002-12-13 20:15:29 +0000609 if ((desc = vector_slot (describe, i)) != NULL)
610 {
611 if (desc->cmd[0] == '\0')
612 continue;
613
614 if (! desc->str)
paul4fc01e62002-12-13 20:49:00 +0000615 fprintf (stdout," %-s\n",
hassob094d262004-08-25 12:22:00 +0000616 desc->cmd[0] == '.' ? desc->cmd + 1 : desc->cmd);
paul718e3742002-12-13 20:15:29 +0000617 else
paul4fc01e62002-12-13 20:49:00 +0000618 fprintf (stdout," %-*s %s\n",
hassob094d262004-08-25 12:22:00 +0000619 width,
620 desc->cmd[0] == '.' ? desc->cmd + 1 : desc->cmd,
621 desc->str);
paul718e3742002-12-13 20:15:29 +0000622 }
623
624 cmd_free_strvec (vline);
625 vector_free (describe);
626
627 rl_on_new_line();
628
629 return 0;
630}
631
hasso95e735b2004-08-26 13:08:30 +0000632/* Result of cmd_complete_command() call will be stored here
633 * and used in new_completion() in order to put the space in
634 * correct places only. */
paul718e3742002-12-13 20:15:29 +0000635int complete_status;
636
ajs274a4a42004-12-07 15:39:31 +0000637static char *
pauldfc0d9b2003-04-18 23:55:29 +0000638command_generator (const char *text, int state)
paul718e3742002-12-13 20:15:29 +0000639{
640 vector vline;
641 static char **matched = NULL;
642 static int index = 0;
643
644 /* First call. */
645 if (! state)
646 {
647 index = 0;
648
649 if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
650 return NULL;
651
652 vline = cmd_make_strvec (rl_line_buffer);
653 if (vline == NULL)
654 return NULL;
655
656 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
657 vector_set (vline, '\0');
658
659 matched = cmd_complete_command (vline, vty, &complete_status);
660 }
661
662 if (matched && matched[index])
663 return matched[index++];
664
665 return NULL;
666}
667
ajs274a4a42004-12-07 15:39:31 +0000668static char **
paul718e3742002-12-13 20:15:29 +0000669new_completion (char *text, int start, int end)
670{
671 char **matches;
672
pauldfc0d9b2003-04-18 23:55:29 +0000673 matches = rl_completion_matches (text, command_generator);
paul718e3742002-12-13 20:15:29 +0000674
675 if (matches)
676 {
677 rl_point = rl_end;
678 if (complete_status == CMD_COMPLETE_FULL_MATCH)
679 rl_pending_input = ' ';
680 }
681
682 return matches;
683}
684
ajs274a4a42004-12-07 15:39:31 +0000685#if 0
686/* This function is not actually being used. */
687static char **
paul718e3742002-12-13 20:15:29 +0000688vtysh_completion (char *text, int start, int end)
689{
690 int ret;
691 vector vline;
692 char **matched = NULL;
693
694 if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
695 return NULL;
696
697 vline = cmd_make_strvec (rl_line_buffer);
698 if (vline == NULL)
699 return NULL;
700
701 /* In case of 'help \t'. */
702 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
703 vector_set (vline, '\0');
704
705 matched = cmd_complete_command (vline, vty, &ret);
706
707 cmd_free_strvec (vline);
708
709 return (char **) matched;
710}
ajs274a4a42004-12-07 15:39:31 +0000711#endif
paul718e3742002-12-13 20:15:29 +0000712
hasso95e735b2004-08-26 13:08:30 +0000713/* Vty node structures. */
paul718e3742002-12-13 20:15:29 +0000714struct cmd_node bgp_node =
715{
716 BGP_NODE,
717 "%s(config-router)# ",
718};
719
paul718e3742002-12-13 20:15:29 +0000720struct cmd_node rip_node =
721{
722 RIP_NODE,
723 "%s(config-router)# ",
724};
725
hassoc25e4582003-12-23 10:39:08 +0000726struct cmd_node isis_node =
727{
728 ISIS_NODE,
729 "%s(config-router)# ",
hassoc25e4582003-12-23 10:39:08 +0000730};
731
paul718e3742002-12-13 20:15:29 +0000732struct cmd_node interface_node =
733{
734 INTERFACE_NODE,
735 "%s(config-if)# ",
736};
737
hasso95e735b2004-08-26 13:08:30 +0000738struct cmd_node rmap_node =
739{
740 RMAP_NODE,
741 "%s(config-route-map)# "
742};
743
744struct cmd_node zebra_node =
745{
746 ZEBRA_NODE,
747 "%s(config-router)# "
748};
749
750struct cmd_node bgp_vpnv4_node =
751{
752 BGP_VPNV4_NODE,
753 "%s(config-router-af)# "
754};
755
756struct cmd_node bgp_ipv4_node =
757{
758 BGP_IPV4_NODE,
759 "%s(config-router-af)# "
760};
761
762struct cmd_node bgp_ipv4m_node =
763{
764 BGP_IPV4M_NODE,
765 "%s(config-router-af)# "
766};
767
768struct cmd_node bgp_ipv6_node =
769{
770 BGP_IPV6_NODE,
771 "%s(config-router-af)# "
772};
773
paul57b5b7e2005-08-22 22:44:29 +0000774struct cmd_node bgp_ipv6m_node =
775{
776 BGP_IPV6M_NODE,
777 "%s(config-router-af)# "
778};
779
hasso95e735b2004-08-26 13:08:30 +0000780struct cmd_node ospf_node =
781{
782 OSPF_NODE,
783 "%s(config-router)# "
784};
785
786struct cmd_node ripng_node =
787{
788 RIPNG_NODE,
789 "%s(config-router)# "
790};
791
792struct cmd_node ospf6_node =
793{
794 OSPF6_NODE,
795 "%s(config-ospf6)# "
796};
797
798struct cmd_node keychain_node =
799{
800 KEYCHAIN_NODE,
801 "%s(config-keychain)# "
802};
803
804struct cmd_node keychain_key_node =
805{
806 KEYCHAIN_KEY_NODE,
807 "%s(config-keychain-key)# "
808};
809
hassoe7168df2004-10-03 20:11:32 +0000810/* Defined in lib/vty.c */
811extern struct cmd_node vty_node;
812
hasso95e735b2004-08-26 13:08:30 +0000813/* When '^Z' is received from vty, move down to the enable mode. */
814int
ajsb1aa1472005-01-28 21:11:46 +0000815vtysh_end (void)
hasso95e735b2004-08-26 13:08:30 +0000816{
817 switch (vty->node)
818 {
819 case VIEW_NODE:
820 case ENABLE_NODE:
821 /* Nothing to do. */
822 break;
823 default:
824 vty->node = ENABLE_NODE;
825 break;
826 }
827 return CMD_SUCCESS;
828}
829
830DEFUNSH (VTYSH_ALL,
831 vtysh_end_all,
832 vtysh_end_all_cmd,
833 "end",
hassoe7168df2004-10-03 20:11:32 +0000834 "End current mode and change to enable mode\n")
hasso95e735b2004-08-26 13:08:30 +0000835{
hasso42895462004-09-26 16:25:07 +0000836 return vtysh_end ();
hasso95e735b2004-08-26 13:08:30 +0000837}
838
paul718e3742002-12-13 20:15:29 +0000839DEFUNSH (VTYSH_BGPD,
840 router_bgp,
841 router_bgp_cmd,
Paul Jakma320da872008-07-02 13:40:33 +0000842 "router bgp " CMD_AS_RANGE,
paul718e3742002-12-13 20:15:29 +0000843 ROUTER_STR
844 BGP_STR
845 AS_STR)
846{
847 vty->node = BGP_NODE;
848 return CMD_SUCCESS;
849}
850
Paul Jakma10895fd2008-07-03 19:34:48 +0000851ALIAS_SH (VTYSH_BGPD,
852 router_bgp,
853 router_bgp_view_cmd,
854 "router bgp " CMD_AS_RANGE " view WORD",
855 ROUTER_STR
856 BGP_STR
857 AS_STR
858 "BGP view\n"
859 "view name\n")
860
paul718e3742002-12-13 20:15:29 +0000861DEFUNSH (VTYSH_BGPD,
862 address_family_vpnv4,
863 address_family_vpnv4_cmd,
864 "address-family vpnv4",
865 "Enter Address Family command mode\n"
866 "Address family\n")
867{
868 vty->node = BGP_VPNV4_NODE;
869 return CMD_SUCCESS;
870}
871
872DEFUNSH (VTYSH_BGPD,
873 address_family_vpnv4_unicast,
874 address_family_vpnv4_unicast_cmd,
875 "address-family vpnv4 unicast",
876 "Enter Address Family command mode\n"
877 "Address family\n"
878 "Address Family Modifier\n")
879{
880 vty->node = BGP_VPNV4_NODE;
881 return CMD_SUCCESS;
882}
883
884DEFUNSH (VTYSH_BGPD,
885 address_family_ipv4_unicast,
886 address_family_ipv4_unicast_cmd,
887 "address-family ipv4 unicast",
888 "Enter Address Family command mode\n"
889 "Address family\n"
890 "Address Family Modifier\n")
891{
892 vty->node = BGP_IPV4_NODE;
893 return CMD_SUCCESS;
894}
895
896DEFUNSH (VTYSH_BGPD,
897 address_family_ipv4_multicast,
898 address_family_ipv4_multicast_cmd,
899 "address-family ipv4 multicast",
900 "Enter Address Family command mode\n"
901 "Address family\n"
902 "Address Family Modifier\n")
903{
904 vty->node = BGP_IPV4M_NODE;
905 return CMD_SUCCESS;
906}
907
908DEFUNSH (VTYSH_BGPD,
909 address_family_ipv6,
910 address_family_ipv6_cmd,
911 "address-family ipv6",
912 "Enter Address Family command mode\n"
913 "Address family\n")
914{
915 vty->node = BGP_IPV6_NODE;
916 return CMD_SUCCESS;
917}
918
919DEFUNSH (VTYSH_BGPD,
920 address_family_ipv6_unicast,
921 address_family_ipv6_unicast_cmd,
922 "address-family ipv6 unicast",
923 "Enter Address Family command mode\n"
924 "Address family\n"
925 "Address Family Modifier\n")
926{
927 vty->node = BGP_IPV6_NODE;
928 return CMD_SUCCESS;
929}
930
paul57b5b7e2005-08-22 22:44:29 +0000931DEFUNSH (VTYSH_BGPD,
932 address_family_ipv6_multicast,
933 address_family_ipv6_multicast_cmd,
934 "address-family ipv6 multicast",
935 "Enter Address Family command mode\n"
936 "Address family\n"
937 "Address Family Modifier\n")
938{
939 vty->node = BGP_IPV6M_NODE;
940 return CMD_SUCCESS;
941}
942
paul718e3742002-12-13 20:15:29 +0000943DEFUNSH (VTYSH_RIPD,
944 key_chain,
945 key_chain_cmd,
946 "key chain WORD",
947 "Authentication key management\n"
948 "Key-chain management\n"
949 "Key-chain name\n")
950{
951 vty->node = KEYCHAIN_NODE;
952 return CMD_SUCCESS;
953}
954
955DEFUNSH (VTYSH_RIPD,
956 key,
957 key_cmd,
958 "key <0-2147483647>",
959 "Configure a key\n"
960 "Key identifier number\n")
961{
962 vty->node = KEYCHAIN_KEY_NODE;
963 return CMD_SUCCESS;
964}
965
966DEFUNSH (VTYSH_RIPD,
967 router_rip,
968 router_rip_cmd,
969 "router rip",
970 ROUTER_STR
971 "RIP")
972{
973 vty->node = RIP_NODE;
974 return CMD_SUCCESS;
975}
976
977DEFUNSH (VTYSH_RIPNGD,
978 router_ripng,
979 router_ripng_cmd,
980 "router ripng",
981 ROUTER_STR
982 "RIPng")
983{
984 vty->node = RIPNG_NODE;
985 return CMD_SUCCESS;
986}
987
988DEFUNSH (VTYSH_OSPFD,
989 router_ospf,
990 router_ospf_cmd,
991 "router ospf",
992 "Enable a routing process\n"
993 "Start OSPF configuration\n")
994{
995 vty->node = OSPF_NODE;
996 return CMD_SUCCESS;
997}
998
999DEFUNSH (VTYSH_OSPF6D,
1000 router_ospf6,
1001 router_ospf6_cmd,
1002 "router ospf6",
1003 OSPF6_ROUTER_STR
1004 OSPF6_STR)
1005{
1006 vty->node = OSPF6_NODE;
1007 return CMD_SUCCESS;
1008}
1009
hassoc25e4582003-12-23 10:39:08 +00001010DEFUNSH (VTYSH_ISISD,
hassob094d262004-08-25 12:22:00 +00001011 router_isis,
1012 router_isis_cmd,
1013 "router isis WORD",
1014 ROUTER_STR
1015 "ISO IS-IS\n"
1016 "ISO Routing area tag")
hassoc25e4582003-12-23 10:39:08 +00001017{
1018 vty->node = ISIS_NODE;
1019 return CMD_SUCCESS;
1020}
1021
paul718e3742002-12-13 20:15:29 +00001022DEFUNSH (VTYSH_RMAP,
1023 route_map,
1024 route_map_cmd,
1025 "route-map WORD (deny|permit) <1-65535>",
1026 "Create route-map or enter route-map command mode\n"
1027 "Route map tag\n"
1028 "Route map denies set operations\n"
1029 "Route map permits set operations\n"
1030 "Sequence to insert to/delete from existing route-map entry\n")
1031{
1032 vty->node = RMAP_NODE;
1033 return CMD_SUCCESS;
1034}
1035
paul718e3742002-12-13 20:15:29 +00001036DEFUNSH (VTYSH_ALL,
hassoe7168df2004-10-03 20:11:32 +00001037 vtysh_line_vty,
1038 vtysh_line_vty_cmd,
1039 "line vty",
1040 "Configure a terminal line\n"
1041 "Virtual terminal\n")
1042{
1043 vty->node = VTY_NODE;
1044 return CMD_SUCCESS;
1045}
1046
1047DEFUNSH (VTYSH_ALL,
paul718e3742002-12-13 20:15:29 +00001048 vtysh_enable,
1049 vtysh_enable_cmd,
1050 "enable",
1051 "Turn on privileged mode command\n")
1052{
1053 vty->node = ENABLE_NODE;
1054 return CMD_SUCCESS;
1055}
1056
paul718e3742002-12-13 20:15:29 +00001057DEFUNSH (VTYSH_ALL,
1058 vtysh_disable,
1059 vtysh_disable_cmd,
1060 "disable",
1061 "Turn off privileged mode command\n")
1062{
1063 if (vty->node == ENABLE_NODE)
1064 vty->node = VIEW_NODE;
1065 return CMD_SUCCESS;
1066}
1067
paul718e3742002-12-13 20:15:29 +00001068DEFUNSH (VTYSH_ALL,
1069 vtysh_config_terminal,
1070 vtysh_config_terminal_cmd,
1071 "configure terminal",
1072 "Configuration from vty interface\n"
1073 "Configuration terminal\n")
1074{
1075 vty->node = CONFIG_NODE;
1076 return CMD_SUCCESS;
1077}
1078
ajs274a4a42004-12-07 15:39:31 +00001079static int
paul718e3742002-12-13 20:15:29 +00001080vtysh_exit (struct vty *vty)
1081{
1082 switch (vty->node)
1083 {
1084 case VIEW_NODE:
1085 case ENABLE_NODE:
1086 exit (0);
1087 break;
1088 case CONFIG_NODE:
1089 vty->node = ENABLE_NODE;
1090 break;
1091 case INTERFACE_NODE:
1092 case ZEBRA_NODE:
1093 case BGP_NODE:
1094 case RIP_NODE:
1095 case RIPNG_NODE:
1096 case OSPF_NODE:
1097 case OSPF6_NODE:
hassoc25e4582003-12-23 10:39:08 +00001098 case ISIS_NODE:
paul718e3742002-12-13 20:15:29 +00001099 case MASC_NODE:
1100 case RMAP_NODE:
1101 case VTY_NODE:
1102 case KEYCHAIN_NODE:
hasso2a56df92004-05-09 23:16:40 +00001103 vtysh_execute("end");
1104 vtysh_execute("configure terminal");
paul718e3742002-12-13 20:15:29 +00001105 vty->node = CONFIG_NODE;
1106 break;
1107 case BGP_VPNV4_NODE:
1108 case BGP_IPV4_NODE:
1109 case BGP_IPV4M_NODE:
1110 case BGP_IPV6_NODE:
paul57b5b7e2005-08-22 22:44:29 +00001111 case BGP_IPV6M_NODE:
paul718e3742002-12-13 20:15:29 +00001112 vty->node = BGP_NODE;
1113 break;
1114 case KEYCHAIN_KEY_NODE:
1115 vty->node = KEYCHAIN_NODE;
1116 break;
1117 default:
1118 break;
1119 }
1120 return CMD_SUCCESS;
1121}
1122
1123DEFUNSH (VTYSH_ALL,
1124 vtysh_exit_all,
1125 vtysh_exit_all_cmd,
1126 "exit",
1127 "Exit current mode and down to previous mode\n")
1128{
1129 return vtysh_exit (vty);
1130}
1131
1132ALIAS (vtysh_exit_all,
1133 vtysh_quit_all_cmd,
1134 "quit",
1135 "Exit current mode and down to previous mode\n")
1136
1137DEFUNSH (VTYSH_BGPD,
1138 exit_address_family,
1139 exit_address_family_cmd,
1140 "exit-address-family",
1141 "Exit from Address Family configuration mode\n")
1142{
1143 if (vty->node == BGP_IPV4_NODE
1144 || vty->node == BGP_IPV4M_NODE
1145 || vty->node == BGP_VPNV4_NODE
paul57b5b7e2005-08-22 22:44:29 +00001146 || vty->node == BGP_IPV6_NODE
1147 || vty->node == BGP_IPV6M_NODE)
paul718e3742002-12-13 20:15:29 +00001148 vty->node = BGP_NODE;
1149 return CMD_SUCCESS;
1150}
1151
1152DEFUNSH (VTYSH_ZEBRA,
1153 vtysh_exit_zebra,
1154 vtysh_exit_zebra_cmd,
1155 "exit",
1156 "Exit current mode and down to previous mode\n")
1157{
1158 return vtysh_exit (vty);
1159}
1160
1161ALIAS (vtysh_exit_zebra,
1162 vtysh_quit_zebra_cmd,
1163 "quit",
1164 "Exit current mode and down to previous mode\n")
1165
1166DEFUNSH (VTYSH_RIPD,
1167 vtysh_exit_ripd,
1168 vtysh_exit_ripd_cmd,
1169 "exit",
1170 "Exit current mode and down to previous mode\n")
1171{
1172 return vtysh_exit (vty);
1173}
1174
1175ALIAS (vtysh_exit_ripd,
1176 vtysh_quit_ripd_cmd,
1177 "quit",
1178 "Exit current mode and down to previous mode\n")
1179
paul68980082003-03-25 05:07:42 +00001180DEFUNSH (VTYSH_RIPNGD,
hassob094d262004-08-25 12:22:00 +00001181 vtysh_exit_ripngd,
1182 vtysh_exit_ripngd_cmd,
1183 "exit",
1184 "Exit current mode and down to previous mode\n")
paul68980082003-03-25 05:07:42 +00001185{
1186 return vtysh_exit (vty);
1187}
1188
1189ALIAS (vtysh_exit_ripngd,
1190 vtysh_quit_ripngd_cmd,
1191 "quit",
1192 "Exit current mode and down to previous mode\n")
1193
paul718e3742002-12-13 20:15:29 +00001194DEFUNSH (VTYSH_RMAP,
1195 vtysh_exit_rmap,
1196 vtysh_exit_rmap_cmd,
1197 "exit",
1198 "Exit current mode and down to previous mode\n")
1199{
1200 return vtysh_exit (vty);
1201}
1202
1203ALIAS (vtysh_exit_rmap,
1204 vtysh_quit_rmap_cmd,
1205 "quit",
1206 "Exit current mode and down to previous mode\n")
1207
1208DEFUNSH (VTYSH_BGPD,
1209 vtysh_exit_bgpd,
1210 vtysh_exit_bgpd_cmd,
1211 "exit",
1212 "Exit current mode and down to previous mode\n")
1213{
1214 return vtysh_exit (vty);
1215}
1216
1217ALIAS (vtysh_exit_bgpd,
1218 vtysh_quit_bgpd_cmd,
1219 "quit",
1220 "Exit current mode and down to previous mode\n")
1221
1222DEFUNSH (VTYSH_OSPFD,
1223 vtysh_exit_ospfd,
1224 vtysh_exit_ospfd_cmd,
1225 "exit",
1226 "Exit current mode and down to previous mode\n")
1227{
1228 return vtysh_exit (vty);
1229}
1230
1231ALIAS (vtysh_exit_ospfd,
1232 vtysh_quit_ospfd_cmd,
1233 "quit",
1234 "Exit current mode and down to previous mode\n")
1235
paul68980082003-03-25 05:07:42 +00001236DEFUNSH (VTYSH_OSPF6D,
hassob094d262004-08-25 12:22:00 +00001237 vtysh_exit_ospf6d,
1238 vtysh_exit_ospf6d_cmd,
1239 "exit",
1240 "Exit current mode and down to previous mode\n")
paul68980082003-03-25 05:07:42 +00001241{
1242 return vtysh_exit (vty);
1243}
1244
1245ALIAS (vtysh_exit_ospf6d,
1246 vtysh_quit_ospf6d_cmd,
1247 "quit",
1248 "Exit current mode and down to previous mode\n")
1249
hassoc25e4582003-12-23 10:39:08 +00001250DEFUNSH (VTYSH_ISISD,
hassob094d262004-08-25 12:22:00 +00001251 vtysh_exit_isisd,
1252 vtysh_exit_isisd_cmd,
1253 "exit",
1254 "Exit current mode and down to previous mode\n")
hassoc25e4582003-12-23 10:39:08 +00001255{
1256 return vtysh_exit (vty);
1257}
1258
1259ALIAS (vtysh_exit_isisd,
1260 vtysh_quit_isisd_cmd,
1261 "quit",
1262 "Exit current mode and down to previous mode\n")
1263
hassoe7168df2004-10-03 20:11:32 +00001264DEFUNSH (VTYSH_ALL,
1265 vtysh_exit_line_vty,
1266 vtysh_exit_line_vty_cmd,
1267 "exit",
1268 "Exit current mode and down to previous mode\n")
1269{
1270 return vtysh_exit (vty);
1271}
1272
1273ALIAS (vtysh_exit_line_vty,
1274 vtysh_quit_line_vty_cmd,
1275 "quit",
1276 "Exit current mode and down to previous mode\n")
1277
hasso95e735b2004-08-26 13:08:30 +00001278DEFUNSH (VTYSH_INTERFACE,
paul718e3742002-12-13 20:15:29 +00001279 vtysh_interface,
1280 vtysh_interface_cmd,
1281 "interface IFNAME",
1282 "Select an interface to configure\n"
1283 "Interface's name\n")
1284{
1285 vty->node = INTERFACE_NODE;
1286 return CMD_SUCCESS;
1287}
1288
hasso95e735b2004-08-26 13:08:30 +00001289/* TODO Implement "no interface command in isisd. */
paul32d24632003-05-23 09:25:20 +00001290DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D,
1291 vtysh_no_interface_cmd,
1292 "no interface IFNAME",
1293 NO_STR
1294 "Delete a pseudo interface's configuration\n"
1295 "Interface's name\n")
1296
hasso95e735b2004-08-26 13:08:30 +00001297/* TODO Implement interface description commands in ripngd, ospf6d
1298 * and isisd. */
paul338a9912003-03-01 15:44:10 +00001299DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1300 interface_desc_cmd,
1301 "description .LINE",
1302 "Interface specific description\n"
1303 "Characters describing this interface\n")
paul464dc8d2003-03-28 02:25:45 +00001304
1305DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1306 no_interface_desc_cmd,
1307 "no description",
1308 NO_STR
1309 "Interface specific description\n")
paul338a9912003-03-01 15:44:10 +00001310
hasso95e735b2004-08-26 13:08:30 +00001311DEFUNSH (VTYSH_INTERFACE,
paul718e3742002-12-13 20:15:29 +00001312 vtysh_exit_interface,
1313 vtysh_exit_interface_cmd,
1314 "exit",
1315 "Exit current mode and down to previous mode\n")
1316{
1317 return vtysh_exit (vty);
1318}
1319
1320ALIAS (vtysh_exit_interface,
1321 vtysh_quit_interface_cmd,
1322 "quit",
1323 "Exit current mode and down to previous mode\n")
1324
Paul Jakma362b4032006-05-28 07:54:45 +00001325/* Memory */
1326DEFUN (vtysh_show_memory,
1327 vtysh_show_memory_cmd,
1328 "show memory",
1329 SHOW_STR
1330 "Memory statistics\n")
1331{
1332 unsigned int i;
1333 int ret = CMD_SUCCESS;
1334 char line[] = "show memory\n";
1335
1336 for (i = 0; i < VTYSH_INDEX_MAX; i++)
1337 if ( vtysh_client[i].fd >= 0 )
1338 {
1339 fprintf (stdout, "Memory statistics for %s:\n",
1340 vtysh_client[i].name);
1341 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1342 fprintf (stdout,"\n");
1343 }
1344
1345 return ret;
1346}
1347
hasso95e735b2004-08-26 13:08:30 +00001348/* Logging commands. */
Paul Jakmadbf7d132006-05-23 22:10:01 +00001349DEFUN (vtysh_show_logging,
1350 vtysh_show_logging_cmd,
1351 "show logging",
1352 SHOW_STR
1353 "Show current logging configuration\n")
1354{
1355 unsigned int i;
1356 int ret = CMD_SUCCESS;
1357 char line[] = "show logging\n";
1358
1359 for (i = 0; i < VTYSH_INDEX_MAX; i++)
Paul Jakma4150f332006-05-23 22:10:55 +00001360 if ( vtysh_client[i].fd >= 0 )
1361 {
1362 fprintf (stdout,"Logging configuration for %s:\n",
1363 vtysh_client[i].name);
1364 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1365 fprintf (stdout,"\n");
1366 }
1367
Paul Jakmadbf7d132006-05-23 22:10:01 +00001368 return ret;
1369}
1370
hasso95e735b2004-08-26 13:08:30 +00001371DEFUNSH (VTYSH_ALL,
1372 vtysh_log_stdout,
1373 vtysh_log_stdout_cmd,
1374 "log stdout",
1375 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001376 "Set stdout logging level\n")
1377{
1378 return CMD_SUCCESS;
1379}
1380
1381DEFUNSH (VTYSH_ALL,
1382 vtysh_log_stdout_level,
1383 vtysh_log_stdout_level_cmd,
1384 "log stdout "LOG_LEVELS,
1385 "Logging control\n"
1386 "Set stdout logging level\n"
1387 LOG_LEVEL_DESC)
hasso95e735b2004-08-26 13:08:30 +00001388{
1389 return CMD_SUCCESS;
1390}
1391
1392DEFUNSH (VTYSH_ALL,
1393 no_vtysh_log_stdout,
1394 no_vtysh_log_stdout_cmd,
ajs274a4a42004-12-07 15:39:31 +00001395 "no log stdout [LEVEL]",
hasso95e735b2004-08-26 13:08:30 +00001396 NO_STR
1397 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001398 "Cancel logging to stdout\n"
1399 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001400{
1401 return CMD_SUCCESS;
1402}
1403
1404DEFUNSH (VTYSH_ALL,
1405 vtysh_log_file,
1406 vtysh_log_file_cmd,
1407 "log file FILENAME",
1408 "Logging control\n"
1409 "Logging to file\n"
1410 "Logging filename\n")
1411{
1412 return CMD_SUCCESS;
1413}
1414
1415DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001416 vtysh_log_file_level,
1417 vtysh_log_file_level_cmd,
1418 "log file FILENAME "LOG_LEVELS,
1419 "Logging control\n"
1420 "Logging to file\n"
1421 "Logging filename\n"
1422 LOG_LEVEL_DESC)
1423{
1424 return CMD_SUCCESS;
1425}
1426
1427DEFUNSH (VTYSH_ALL,
hasso95e735b2004-08-26 13:08:30 +00001428 no_vtysh_log_file,
1429 no_vtysh_log_file_cmd,
1430 "no log file [FILENAME]",
1431 NO_STR
1432 "Logging control\n"
1433 "Cancel logging to file\n"
1434 "Logging file name\n")
1435{
1436 return CMD_SUCCESS;
1437}
1438
ajs274a4a42004-12-07 15:39:31 +00001439ALIAS_SH (VTYSH_ALL,
1440 no_vtysh_log_file,
1441 no_vtysh_log_file_level_cmd,
1442 "no log file FILENAME LEVEL",
1443 NO_STR
1444 "Logging control\n"
1445 "Cancel logging to file\n"
1446 "Logging file name\n"
1447 "Logging level\n")
1448
1449DEFUNSH (VTYSH_ALL,
1450 vtysh_log_monitor,
1451 vtysh_log_monitor_cmd,
1452 "log monitor",
1453 "Logging control\n"
1454 "Set terminal line (monitor) logging level\n")
1455{
1456 return CMD_SUCCESS;
1457}
1458
1459DEFUNSH (VTYSH_ALL,
1460 vtysh_log_monitor_level,
1461 vtysh_log_monitor_level_cmd,
1462 "log monitor "LOG_LEVELS,
1463 "Logging control\n"
1464 "Set terminal line (monitor) logging level\n"
1465 LOG_LEVEL_DESC)
1466{
1467 return CMD_SUCCESS;
1468}
1469
1470DEFUNSH (VTYSH_ALL,
1471 no_vtysh_log_monitor,
1472 no_vtysh_log_monitor_cmd,
1473 "no log monitor [LEVEL]",
1474 NO_STR
1475 "Logging control\n"
1476 "Disable terminal line (monitor) logging\n"
1477 "Logging level\n")
1478{
1479 return CMD_SUCCESS;
1480}
1481
hasso95e735b2004-08-26 13:08:30 +00001482DEFUNSH (VTYSH_ALL,
1483 vtysh_log_syslog,
1484 vtysh_log_syslog_cmd,
1485 "log syslog",
1486 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001487 "Set syslog logging level\n")
1488{
1489 return CMD_SUCCESS;
1490}
1491
1492DEFUNSH (VTYSH_ALL,
1493 vtysh_log_syslog_level,
1494 vtysh_log_syslog_level_cmd,
1495 "log syslog "LOG_LEVELS,
1496 "Logging control\n"
1497 "Set syslog logging level\n"
1498 LOG_LEVEL_DESC)
hasso95e735b2004-08-26 13:08:30 +00001499{
1500 return CMD_SUCCESS;
1501}
1502
1503DEFUNSH (VTYSH_ALL,
1504 no_vtysh_log_syslog,
1505 no_vtysh_log_syslog_cmd,
ajs274a4a42004-12-07 15:39:31 +00001506 "no log syslog [LEVEL]",
hasso95e735b2004-08-26 13:08:30 +00001507 NO_STR
1508 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001509 "Cancel logging to syslog\n"
1510 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001511{
1512 return CMD_SUCCESS;
1513}
1514
1515DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001516 vtysh_log_facility,
1517 vtysh_log_facility_cmd,
1518 "log facility "LOG_FACILITIES,
hasso95e735b2004-08-26 13:08:30 +00001519 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001520 "Facility parameter for syslog messages\n"
1521 LOG_FACILITY_DESC)
1522
hasso95e735b2004-08-26 13:08:30 +00001523{
1524 return CMD_SUCCESS;
1525}
1526
1527DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001528 no_vtysh_log_facility,
1529 no_vtysh_log_facility_cmd,
1530 "no log facility [FACILITY]",
hasso95e735b2004-08-26 13:08:30 +00001531 NO_STR
1532 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001533 "Reset syslog facility to default (daemon)\n"
1534 "Syslog facility\n")
1535
1536{
1537 return CMD_SUCCESS;
1538}
1539
1540DEFUNSH_DEPRECATED (VTYSH_ALL,
1541 vtysh_log_trap,
1542 vtysh_log_trap_cmd,
1543 "log trap "LOG_LEVELS,
1544 "Logging control\n"
1545 "(Deprecated) Set logging level and default for all destinations\n"
1546 LOG_LEVEL_DESC)
1547
1548{
1549 return CMD_SUCCESS;
1550}
1551
1552DEFUNSH_DEPRECATED (VTYSH_ALL,
1553 no_vtysh_log_trap,
1554 no_vtysh_log_trap_cmd,
1555 "no log trap [LEVEL]",
1556 NO_STR
1557 "Logging control\n"
1558 "Permit all logging information\n"
1559 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001560{
1561 return CMD_SUCCESS;
1562}
1563
1564DEFUNSH (VTYSH_ALL,
1565 vtysh_log_record_priority,
1566 vtysh_log_record_priority_cmd,
1567 "log record-priority",
1568 "Logging control\n"
1569 "Log the priority of the message within the message\n")
1570{
1571 return CMD_SUCCESS;
1572}
1573
1574DEFUNSH (VTYSH_ALL,
1575 no_vtysh_log_record_priority,
1576 no_vtysh_log_record_priority_cmd,
1577 "no log record-priority",
1578 NO_STR
1579 "Logging control\n"
1580 "Do not log the priority of the message within the message\n")
1581{
1582 return CMD_SUCCESS;
1583}
1584
hassoe7168df2004-10-03 20:11:32 +00001585DEFUNSH (VTYSH_ALL,
Andrew J. Schorrc749b722007-04-29 03:53:31 +00001586 vtysh_log_timestamp_precision,
1587 vtysh_log_timestamp_precision_cmd,
1588 "log timestamp precision <0-6>",
1589 "Logging control\n"
1590 "Timestamp configuration\n"
1591 "Set the timestamp precision\n"
1592 "Number of subsecond digits\n")
1593{
1594 return CMD_SUCCESS;
1595}
1596
1597DEFUNSH (VTYSH_ALL,
1598 no_vtysh_log_timestamp_precision,
1599 no_vtysh_log_timestamp_precision_cmd,
1600 "no log timestamp precision",
1601 NO_STR
1602 "Logging control\n"
1603 "Timestamp configuration\n"
1604 "Reset the timestamp precision to the default value of 0\n")
1605{
1606 return CMD_SUCCESS;
1607}
1608
1609DEFUNSH (VTYSH_ALL,
hassoe7168df2004-10-03 20:11:32 +00001610 vtysh_service_password_encrypt,
1611 vtysh_service_password_encrypt_cmd,
1612 "service password-encryption",
1613 "Set up miscellaneous service\n"
1614 "Enable encrypted passwords\n")
1615{
1616 return CMD_SUCCESS;
1617}
1618
1619DEFUNSH (VTYSH_ALL,
1620 no_vtysh_service_password_encrypt,
1621 no_vtysh_service_password_encrypt_cmd,
1622 "no service password-encryption",
1623 NO_STR
1624 "Set up miscellaneous service\n"
1625 "Enable encrypted passwords\n")
1626{
1627 return CMD_SUCCESS;
1628}
1629
1630DEFUNSH (VTYSH_ALL,
1631 vtysh_config_password,
1632 vtysh_password_cmd,
1633 "password (8|) WORD",
1634 "Assign the terminal connection password\n"
1635 "Specifies a HIDDEN password will follow\n"
1636 "dummy string \n"
1637 "The HIDDEN line password string\n")
1638{
1639 return CMD_SUCCESS;
1640}
1641
1642DEFUNSH (VTYSH_ALL,
1643 vtysh_password_text,
1644 vtysh_password_text_cmd,
1645 "password LINE",
1646 "Assign the terminal connection password\n"
1647 "The UNENCRYPTED (cleartext) line password\n")
1648{
1649 return CMD_SUCCESS;
1650}
1651
1652DEFUNSH (VTYSH_ALL,
1653 vtysh_config_enable_password,
1654 vtysh_enable_password_cmd,
1655 "enable password (8|) WORD",
1656 "Modify enable password parameters\n"
1657 "Assign the privileged level password\n"
1658 "Specifies a HIDDEN password will follow\n"
1659 "dummy string \n"
1660 "The HIDDEN 'enable' password string\n")
1661{
1662 return CMD_SUCCESS;
1663}
1664
1665DEFUNSH (VTYSH_ALL,
1666 vtysh_enable_password_text,
1667 vtysh_enable_password_text_cmd,
1668 "enable password LINE",
1669 "Modify enable password parameters\n"
1670 "Assign the privileged level password\n"
1671 "The UNENCRYPTED (cleartext) 'enable' password\n")
1672{
1673 return CMD_SUCCESS;
1674}
1675
1676DEFUNSH (VTYSH_ALL,
1677 no_vtysh_config_enable_password,
1678 no_vtysh_enable_password_cmd,
1679 "no enable password",
1680 NO_STR
1681 "Modify enable password parameters\n"
1682 "Assign the privileged level password\n")
1683{
1684 return CMD_SUCCESS;
1685}
1686
paul718e3742002-12-13 20:15:29 +00001687DEFUN (vtysh_write_terminal,
1688 vtysh_write_terminal_cmd,
1689 "write terminal",
1690 "Write running configuration to memory, network, or terminal\n"
1691 "Write to terminal\n")
1692{
ajsb1aa1472005-01-28 21:11:46 +00001693 u_int i;
paul718e3742002-12-13 20:15:29 +00001694 int ret;
1695 char line[] = "write terminal\n";
1696 FILE *fp = NULL;
1697
1698 if (vtysh_pager_name)
1699 {
paul4fc01e62002-12-13 20:49:00 +00001700 fp = popen (vtysh_pager_name, "w");
paul718e3742002-12-13 20:15:29 +00001701 if (fp == NULL)
1702 {
1703 perror ("popen");
1704 exit (1);
1705 }
1706 }
1707 else
1708 fp = stdout;
1709
1710 vty_out (vty, "Building configuration...%s", VTY_NEWLINE);
1711 vty_out (vty, "%sCurrent configuration:%s", VTY_NEWLINE,
1712 VTY_NEWLINE);
hassoe7168df2004-10-03 20:11:32 +00001713 vty_out (vty, "!%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001714
ajsb1aa1472005-01-28 21:11:46 +00001715 for (i = 0; i < VTYSH_INDEX_MAX; i++)
1716 ret = vtysh_client_config (&vtysh_client[i], line);
paul718e3742002-12-13 20:15:29 +00001717
hassoe7168df2004-10-03 20:11:32 +00001718 /* Integrate vtysh specific configuration. */
1719 vtysh_config_write ();
1720
paul718e3742002-12-13 20:15:29 +00001721 vtysh_config_dump (fp);
1722
Paul Jakma8454b052007-06-20 15:22:14 +00001723 vty_out (vty, "end%s", VTY_NEWLINE);
1724
paul718e3742002-12-13 20:15:29 +00001725 if (vtysh_pager_name && fp)
1726 {
1727 fflush (fp);
1728 if (pclose (fp) == -1)
1729 {
1730 perror ("pclose");
1731 exit (1);
1732 }
1733 fp = NULL;
1734 }
1735
1736 return CMD_SUCCESS;
1737}
1738
hassoe7168df2004-10-03 20:11:32 +00001739DEFUN (vtysh_integrated_config,
1740 vtysh_integrated_config_cmd,
1741 "service integrated-vtysh-config",
1742 "Set up miscellaneous service\n"
1743 "Write configuration into integrated file\n")
paul4fc01e62002-12-13 20:49:00 +00001744{
hassoe7168df2004-10-03 20:11:32 +00001745 vtysh_writeconfig_integrated = 1;
1746 return CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001747}
1748
hassoe7168df2004-10-03 20:11:32 +00001749DEFUN (no_vtysh_integrated_config,
1750 no_vtysh_integrated_config_cmd,
1751 "no service integrated-vtysh-config",
1752 NO_STR
1753 "Set up miscellaneous service\n"
1754 "Write configuration into integrated file\n")
paul4fc01e62002-12-13 20:49:00 +00001755{
hassoe7168df2004-10-03 20:11:32 +00001756 vtysh_writeconfig_integrated = 0;
1757 return CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001758}
1759
ajs274a4a42004-12-07 15:39:31 +00001760static int
1761write_config_integrated(void)
paul718e3742002-12-13 20:15:29 +00001762{
ajsb1aa1472005-01-28 21:11:46 +00001763 u_int i;
paul718e3742002-12-13 20:15:29 +00001764 int ret;
paul718e3742002-12-13 20:15:29 +00001765 char line[] = "write terminal\n";
1766 FILE *fp;
1767 char *integrate_sav = NULL;
1768
hasso95e735b2004-08-26 13:08:30 +00001769 integrate_sav = malloc (strlen (integrate_default) +
1770 strlen (CONF_BACKUP_EXT) + 1);
paul718e3742002-12-13 20:15:29 +00001771 strcpy (integrate_sav, integrate_default);
1772 strcat (integrate_sav, CONF_BACKUP_EXT);
1773
paul4fc01e62002-12-13 20:49:00 +00001774 fprintf (stdout,"Building Configuration...\n");
paul718e3742002-12-13 20:15:29 +00001775
hasso95e735b2004-08-26 13:08:30 +00001776 /* Move current configuration file to backup config file. */
paul718e3742002-12-13 20:15:29 +00001777 unlink (integrate_sav);
1778 rename (integrate_default, integrate_sav);
hasso95e735b2004-08-26 13:08:30 +00001779 free (integrate_sav);
paul4fc01e62002-12-13 20:49:00 +00001780
paul718e3742002-12-13 20:15:29 +00001781 fp = fopen (integrate_default, "w");
1782 if (fp == NULL)
1783 {
hasso95e735b2004-08-26 13:08:30 +00001784 fprintf (stdout,"%% Can't open configuration file %s.\n",
1785 integrate_default);
paul718e3742002-12-13 20:15:29 +00001786 return CMD_SUCCESS;
1787 }
paul718e3742002-12-13 20:15:29 +00001788
ajsb1aa1472005-01-28 21:11:46 +00001789 for (i = 0; i < VTYSH_INDEX_MAX; i++)
1790 ret = vtysh_client_config (&vtysh_client[i], line);
paul718e3742002-12-13 20:15:29 +00001791
1792 vtysh_config_dump (fp);
1793
1794 fclose (fp);
1795
gdtaa593d52003-12-22 20:15:53 +00001796 if (chmod (integrate_default, CONFIGFILE_MASK) != 0)
1797 {
1798 fprintf (stdout,"%% Can't chmod configuration file %s: %s (%d)\n",
ajs6099b3b2004-11-20 02:06:59 +00001799 integrate_default, safe_strerror(errno), errno);
gdtaa593d52003-12-22 20:15:53 +00001800 return CMD_WARNING;
1801 }
1802
paul4fc01e62002-12-13 20:49:00 +00001803 fprintf(stdout,"Integrated configuration saved to %s\n",integrate_default);
1804
1805 fprintf (stdout,"[OK]\n");
1806
paul718e3742002-12-13 20:15:29 +00001807 return CMD_SUCCESS;
1808}
1809
paul4fc01e62002-12-13 20:49:00 +00001810DEFUN (vtysh_write_memory,
1811 vtysh_write_memory_cmd,
1812 "write memory",
1813 "Write running configuration to memory, network, or terminal\n"
1814 "Write configuration to the file (same as write file)\n")
1815{
pauldfc0d9b2003-04-18 23:55:29 +00001816 int ret = CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001817 char line[] = "write memory\n";
ajsb1aa1472005-01-28 21:11:46 +00001818 u_int i;
paul4fc01e62002-12-13 20:49:00 +00001819
hassoe7168df2004-10-03 20:11:32 +00001820 /* If integrated Quagga.conf explicitely set. */
1821 if (vtysh_writeconfig_integrated)
1822 return write_config_integrated();
paul4fc01e62002-12-13 20:49:00 +00001823
1824 fprintf (stdout,"Building Configuration...\n");
1825
ajsb1aa1472005-01-28 21:11:46 +00001826 for (i = 0; i < VTYSH_INDEX_MAX; i++)
1827 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
hassoe7168df2004-10-03 20:11:32 +00001828
paul4fc01e62002-12-13 20:49:00 +00001829 fprintf (stdout,"[OK]\n");
1830
pauldfc0d9b2003-04-18 23:55:29 +00001831 return ret;
paul4fc01e62002-12-13 20:49:00 +00001832}
1833
paul718e3742002-12-13 20:15:29 +00001834ALIAS (vtysh_write_memory,
1835 vtysh_copy_runningconfig_startupconfig_cmd,
1836 "copy running-config startup-config",
1837 "Copy from one file to another\n"
1838 "Copy from current system configuration\n"
1839 "Copy to startup configuration\n")
1840
1841ALIAS (vtysh_write_memory,
1842 vtysh_write_file_cmd,
1843 "write file",
1844 "Write running configuration to memory, network, or terminal\n"
1845 "Write configuration to the file (same as write memory)\n")
1846
hasso4a6e2252003-05-25 11:51:29 +00001847ALIAS (vtysh_write_memory,
1848 vtysh_write_cmd,
1849 "write",
1850 "Write running configuration to memory, network, or terminal\n")
1851
paul718e3742002-12-13 20:15:29 +00001852ALIAS (vtysh_write_terminal,
1853 vtysh_show_running_config_cmd,
1854 "show running-config",
1855 SHOW_STR
1856 "Current operating configuration\n")
hassob094d262004-08-25 12:22:00 +00001857
hasso34553cc2004-08-27 13:56:39 +00001858DEFUN (vtysh_terminal_length,
1859 vtysh_terminal_length_cmd,
1860 "terminal length <0-512>",
1861 "Set terminal line parameters\n"
1862 "Set number of lines on a screen\n"
1863 "Number of lines on screen (0 for no pausing)\n")
1864{
1865 int lines;
1866 char *endptr = NULL;
1867 char default_pager[10];
1868
1869 lines = strtol (argv[0], &endptr, 10);
1870 if (lines < 0 || lines > 512 || *endptr != '\0')
1871 {
1872 vty_out (vty, "length is malformed%s", VTY_NEWLINE);
1873 return CMD_WARNING;
1874 }
1875
1876 if (vtysh_pager_name)
1877 {
1878 free (vtysh_pager_name);
1879 vtysh_pager_name = NULL;
1880 }
1881
1882 if (lines != 0)
1883 {
1884 snprintf(default_pager, 10, "more -%i", lines);
1885 vtysh_pager_name = strdup (default_pager);
1886 }
1887
1888 return CMD_SUCCESS;
1889}
1890
1891DEFUN (vtysh_terminal_no_length,
1892 vtysh_terminal_no_length_cmd,
1893 "terminal no length",
1894 "Set terminal line parameters\n"
1895 NO_STR
1896 "Set number of lines on a screen\n")
1897{
1898 if (vtysh_pager_name)
1899 {
1900 free (vtysh_pager_name);
1901 vtysh_pager_name = NULL;
1902 }
1903
1904 vtysh_pager_init();
1905 return CMD_SUCCESS;
1906}
1907
hassof2799e62004-10-28 17:43:11 +00001908DEFUN (vtysh_show_daemons,
1909 vtysh_show_daemons_cmd,
1910 "show daemons",
hassoe7168df2004-10-03 20:11:32 +00001911 SHOW_STR
1912 "Show list of running daemons\n")
1913{
ajsb1aa1472005-01-28 21:11:46 +00001914 u_int i;
1915
1916 for (i = 0; i < VTYSH_INDEX_MAX; i++)
1917 if ( vtysh_client[i].fd >= 0 )
1918 vty_out(vty, " %s", vtysh_client[i].name);
hassoe7168df2004-10-03 20:11:32 +00001919 vty_out(vty, "%s", VTY_NEWLINE);
1920
1921 return CMD_SUCCESS;
1922}
1923
paul718e3742002-12-13 20:15:29 +00001924/* Execute command in child process. */
ajs274a4a42004-12-07 15:39:31 +00001925static int
hasso5862ff52004-10-11 13:20:40 +00001926execute_command (const char *command, int argc, const char *arg1,
1927 const char *arg2)
paul718e3742002-12-13 20:15:29 +00001928{
1929 int ret;
1930 pid_t pid;
1931 int status;
1932
1933 /* Call fork(). */
1934 pid = fork ();
1935
1936 if (pid < 0)
1937 {
1938 /* Failure of fork(). */
ajs6099b3b2004-11-20 02:06:59 +00001939 fprintf (stderr, "Can't fork: %s\n", safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +00001940 exit (1);
1941 }
1942 else if (pid == 0)
1943 {
1944 /* This is child process. */
1945 switch (argc)
1946 {
1947 case 0:
hassofa2b17e2004-03-04 17:45:00 +00001948 ret = execlp (command, command, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00001949 break;
1950 case 1:
hassofa2b17e2004-03-04 17:45:00 +00001951 ret = execlp (command, command, arg1, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00001952 break;
1953 case 2:
hassofa2b17e2004-03-04 17:45:00 +00001954 ret = execlp (command, command, arg1, arg2, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00001955 break;
1956 }
1957
1958 /* When execlp suceed, this part is not executed. */
ajs6099b3b2004-11-20 02:06:59 +00001959 fprintf (stderr, "Can't execute %s: %s\n", command, safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +00001960 exit (1);
1961 }
1962 else
1963 {
1964 /* This is parent. */
1965 execute_flag = 1;
1966 ret = wait4 (pid, &status, 0, NULL);
1967 execute_flag = 0;
1968 }
1969 return 0;
1970}
1971
1972DEFUN (vtysh_ping,
1973 vtysh_ping_cmd,
1974 "ping WORD",
hasso4eeccf12003-06-25 10:49:55 +00001975 "Send echo messages\n"
paul718e3742002-12-13 20:15:29 +00001976 "Ping destination address or hostname\n")
1977{
1978 execute_command ("ping", 1, argv[0], NULL);
1979 return CMD_SUCCESS;
1980}
1981
hasso4eeccf12003-06-25 10:49:55 +00001982ALIAS (vtysh_ping,
1983 vtysh_ping_ip_cmd,
1984 "ping ip WORD",
1985 "Send echo messages\n"
1986 "IP echo\n"
1987 "Ping destination address or hostname\n")
1988
paul718e3742002-12-13 20:15:29 +00001989DEFUN (vtysh_traceroute,
1990 vtysh_traceroute_cmd,
1991 "traceroute WORD",
1992 "Trace route to destination\n"
1993 "Trace route to destination address or hostname\n")
1994{
1995 execute_command ("traceroute", 1, argv[0], NULL);
1996 return CMD_SUCCESS;
1997}
1998
hasso4eeccf12003-06-25 10:49:55 +00001999ALIAS (vtysh_traceroute,
2000 vtysh_traceroute_ip_cmd,
2001 "traceroute ip WORD",
2002 "Trace route to destination\n"
2003 "IP trace\n"
2004 "Trace route to destination address or hostname\n")
2005
2006#ifdef HAVE_IPV6
2007DEFUN (vtysh_ping6,
2008 vtysh_ping6_cmd,
2009 "ping ipv6 WORD",
2010 "Send echo messages\n"
2011 "IPv6 echo\n"
2012 "Ping destination address or hostname\n")
2013{
2014 execute_command ("ping6", 1, argv[0], NULL);
2015 return CMD_SUCCESS;
2016}
2017
2018DEFUN (vtysh_traceroute6,
2019 vtysh_traceroute6_cmd,
2020 "traceroute ipv6 WORD",
2021 "Trace route to destination\n"
2022 "IPv6 trace\n"
2023 "Trace route to destination address or hostname\n")
2024{
2025 execute_command ("traceroute6", 1, argv[0], NULL);
2026 return CMD_SUCCESS;
2027}
2028#endif
2029
paul718e3742002-12-13 20:15:29 +00002030DEFUN (vtysh_telnet,
2031 vtysh_telnet_cmd,
2032 "telnet WORD",
2033 "Open a telnet connection\n"
2034 "IP address or hostname of a remote system\n")
2035{
2036 execute_command ("telnet", 1, argv[0], NULL);
2037 return CMD_SUCCESS;
2038}
2039
2040DEFUN (vtysh_telnet_port,
2041 vtysh_telnet_port_cmd,
2042 "telnet WORD PORT",
2043 "Open a telnet connection\n"
2044 "IP address or hostname of a remote system\n"
2045 "TCP Port number\n")
2046{
2047 execute_command ("telnet", 2, argv[0], argv[1]);
2048 return CMD_SUCCESS;
2049}
2050
paul5087df52003-01-25 06:56:09 +00002051DEFUN (vtysh_ssh,
2052 vtysh_ssh_cmd,
2053 "ssh WORD",
2054 "Open an ssh connection\n"
2055 "[user@]host\n")
2056{
2057 execute_command ("ssh", 1, argv[0], NULL);
2058 return CMD_SUCCESS;
2059}
2060
paul718e3742002-12-13 20:15:29 +00002061DEFUN (vtysh_start_shell,
2062 vtysh_start_shell_cmd,
2063 "start-shell",
2064 "Start UNIX shell\n")
2065{
2066 execute_command ("sh", 0, NULL, NULL);
2067 return CMD_SUCCESS;
2068}
2069
2070DEFUN (vtysh_start_bash,
2071 vtysh_start_bash_cmd,
2072 "start-shell bash",
2073 "Start UNIX shell\n"
2074 "Start bash\n")
2075{
2076 execute_command ("bash", 0, NULL, NULL);
2077 return CMD_SUCCESS;
2078}
2079
2080DEFUN (vtysh_start_zsh,
2081 vtysh_start_zsh_cmd,
2082 "start-shell zsh",
2083 "Start UNIX shell\n"
2084 "Start Z shell\n")
2085{
2086 execute_command ("zsh", 0, NULL, NULL);
2087 return CMD_SUCCESS;
2088}
hassob094d262004-08-25 12:22:00 +00002089
ajs274a4a42004-12-07 15:39:31 +00002090static void
paul718e3742002-12-13 20:15:29 +00002091vtysh_install_default (enum node_type node)
2092{
2093 install_element (node, &config_list_cmd);
2094}
2095
2096/* Making connection to protocol daemon. */
ajs274a4a42004-12-07 15:39:31 +00002097static int
ajsb1aa1472005-01-28 21:11:46 +00002098vtysh_connect (struct vtysh_client *vclient)
paul718e3742002-12-13 20:15:29 +00002099{
2100 int ret;
2101 int sock, len;
2102 struct sockaddr_un addr;
2103 struct stat s_stat;
paul718e3742002-12-13 20:15:29 +00002104
paul718e3742002-12-13 20:15:29 +00002105 /* Stat socket to see if we have permission to access it. */
ajsb1aa1472005-01-28 21:11:46 +00002106 ret = stat (vclient->path, &s_stat);
paul718e3742002-12-13 20:15:29 +00002107 if (ret < 0 && errno != ENOENT)
2108 {
2109 fprintf (stderr, "vtysh_connect(%s): stat = %s\n",
ajsb1aa1472005-01-28 21:11:46 +00002110 vclient->path, safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002111 exit(1);
2112 }
2113
2114 if (ret >= 0)
2115 {
2116 if (! S_ISSOCK(s_stat.st_mode))
2117 {
2118 fprintf (stderr, "vtysh_connect(%s): Not a socket\n",
ajsb1aa1472005-01-28 21:11:46 +00002119 vclient->path);
paul718e3742002-12-13 20:15:29 +00002120 exit (1);
2121 }
2122
paul718e3742002-12-13 20:15:29 +00002123 }
2124
2125 sock = socket (AF_UNIX, SOCK_STREAM, 0);
2126 if (sock < 0)
2127 {
2128#ifdef DEBUG
ajsb1aa1472005-01-28 21:11:46 +00002129 fprintf(stderr, "vtysh_connect(%s): socket = %s\n", vclient->path,
ajs6099b3b2004-11-20 02:06:59 +00002130 safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002131#endif /* DEBUG */
2132 return -1;
2133 }
2134
2135 memset (&addr, 0, sizeof (struct sockaddr_un));
2136 addr.sun_family = AF_UNIX;
ajsb1aa1472005-01-28 21:11:46 +00002137 strncpy (addr.sun_path, vclient->path, strlen (vclient->path));
Paul Jakma6f0e3f62007-05-10 02:38:51 +00002138#ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
paul718e3742002-12-13 20:15:29 +00002139 len = addr.sun_len = SUN_LEN(&addr);
2140#else
2141 len = sizeof (addr.sun_family) + strlen (addr.sun_path);
Paul Jakma6f0e3f62007-05-10 02:38:51 +00002142#endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
paul718e3742002-12-13 20:15:29 +00002143
2144 ret = connect (sock, (struct sockaddr *) &addr, len);
2145 if (ret < 0)
2146 {
2147#ifdef DEBUG
ajsb1aa1472005-01-28 21:11:46 +00002148 fprintf(stderr, "vtysh_connect(%s): connect = %s\n", vclient->path,
ajs6099b3b2004-11-20 02:06:59 +00002149 safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002150#endif /* DEBUG */
2151 close (sock);
2152 return -1;
2153 }
2154 vclient->fd = sock;
2155
2156 return 0;
2157}
2158
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002159int
2160vtysh_connect_all(const char *daemon_name)
paul718e3742002-12-13 20:15:29 +00002161{
ajsb1aa1472005-01-28 21:11:46 +00002162 u_int i;
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002163 int rc = 0;
2164 int matches = 0;
ajsb1aa1472005-01-28 21:11:46 +00002165
2166 for (i = 0; i < VTYSH_INDEX_MAX; i++)
2167 {
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002168 if (!daemon_name || !strcmp(daemon_name, vtysh_client[i].name))
2169 {
2170 matches++;
2171 if (vtysh_connect(&vtysh_client[i]) == 0)
2172 rc++;
2173 /* We need direct access to ripd in vtysh_exit_ripd_only. */
2174 if (vtysh_client[i].flag == VTYSH_RIPD)
2175 ripd_client = &vtysh_client[i];
2176 }
ajsb1aa1472005-01-28 21:11:46 +00002177 }
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002178 if (!matches)
2179 fprintf(stderr, "Error: no daemons match name %s!\n", daemon_name);
2180 return rc;
paul718e3742002-12-13 20:15:29 +00002181}
2182
hasso95e735b2004-08-26 13:08:30 +00002183/* To disable readline's filename completion. */
ajs274a4a42004-12-07 15:39:31 +00002184static char *
pauldfc0d9b2003-04-18 23:55:29 +00002185vtysh_completion_entry_function (const char *ignore, int invoking_key)
paul718e3742002-12-13 20:15:29 +00002186{
pauldfc0d9b2003-04-18 23:55:29 +00002187 return NULL;
paul718e3742002-12-13 20:15:29 +00002188}
2189
2190void
ajsb1aa1472005-01-28 21:11:46 +00002191vtysh_readline_init (void)
paul718e3742002-12-13 20:15:29 +00002192{
2193 /* readline related settings. */
hasso53a6f932005-09-15 06:50:53 +00002194 rl_bind_key ('?', (Function *) vtysh_rl_describe);
paul68980082003-03-25 05:07:42 +00002195 rl_completion_entry_function = vtysh_completion_entry_function;
paul718e3742002-12-13 20:15:29 +00002196 rl_attempted_completion_function = (CPPFunction *)new_completion;
2197 /* do not append space after completion. It will be appended
hasso95e735b2004-08-26 13:08:30 +00002198 * in new_completion() function explicitly. */
paul718e3742002-12-13 20:15:29 +00002199 rl_completion_append_character = '\0';
2200}
2201
2202char *
ajsb1aa1472005-01-28 21:11:46 +00002203vtysh_prompt (void)
paul718e3742002-12-13 20:15:29 +00002204{
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002205 static struct utsname names;
paul718e3742002-12-13 20:15:29 +00002206 static char buf[100];
2207 const char*hostname;
2208 extern struct host host;
2209
2210 hostname = host.name;
2211
2212 if (!hostname)
2213 {
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002214 if (!names.nodename[0])
2215 uname (&names);
paul718e3742002-12-13 20:15:29 +00002216 hostname = names.nodename;
2217 }
2218
2219 snprintf (buf, sizeof buf, cmd_prompt (vty->node), hostname);
2220
2221 return buf;
2222}
2223
2224void
ajsb1aa1472005-01-28 21:11:46 +00002225vtysh_init_vty (void)
paul718e3742002-12-13 20:15:29 +00002226{
2227 /* Make vty structure. */
2228 vty = vty_new ();
2229 vty->type = VTY_SHELL;
2230 vty->node = VIEW_NODE;
2231
2232 /* Initialize commands. */
2233 cmd_init (0);
2234
2235 /* Install nodes. */
2236 install_node (&bgp_node, NULL);
2237 install_node (&rip_node, NULL);
2238 install_node (&interface_node, NULL);
2239 install_node (&rmap_node, NULL);
2240 install_node (&zebra_node, NULL);
2241 install_node (&bgp_vpnv4_node, NULL);
2242 install_node (&bgp_ipv4_node, NULL);
2243 install_node (&bgp_ipv4m_node, NULL);
2244/* #ifdef HAVE_IPV6 */
2245 install_node (&bgp_ipv6_node, NULL);
paul57b5b7e2005-08-22 22:44:29 +00002246 install_node (&bgp_ipv6m_node, NULL);
paul718e3742002-12-13 20:15:29 +00002247/* #endif */
2248 install_node (&ospf_node, NULL);
2249/* #ifdef HAVE_IPV6 */
2250 install_node (&ripng_node, NULL);
2251 install_node (&ospf6_node, NULL);
2252/* #endif */
2253 install_node (&keychain_node, NULL);
2254 install_node (&keychain_key_node, NULL);
hassoc25e4582003-12-23 10:39:08 +00002255 install_node (&isis_node, NULL);
hassoe7168df2004-10-03 20:11:32 +00002256 install_node (&vty_node, NULL);
paul718e3742002-12-13 20:15:29 +00002257
2258 vtysh_install_default (VIEW_NODE);
2259 vtysh_install_default (ENABLE_NODE);
2260 vtysh_install_default (CONFIG_NODE);
2261 vtysh_install_default (BGP_NODE);
2262 vtysh_install_default (RIP_NODE);
2263 vtysh_install_default (INTERFACE_NODE);
2264 vtysh_install_default (RMAP_NODE);
2265 vtysh_install_default (ZEBRA_NODE);
2266 vtysh_install_default (BGP_VPNV4_NODE);
2267 vtysh_install_default (BGP_IPV4_NODE);
2268 vtysh_install_default (BGP_IPV4M_NODE);
2269 vtysh_install_default (BGP_IPV6_NODE);
paul57b5b7e2005-08-22 22:44:29 +00002270 vtysh_install_default (BGP_IPV6M_NODE);
paul718e3742002-12-13 20:15:29 +00002271 vtysh_install_default (OSPF_NODE);
2272 vtysh_install_default (RIPNG_NODE);
2273 vtysh_install_default (OSPF6_NODE);
hassoc25e4582003-12-23 10:39:08 +00002274 vtysh_install_default (ISIS_NODE);
paul718e3742002-12-13 20:15:29 +00002275 vtysh_install_default (KEYCHAIN_NODE);
2276 vtysh_install_default (KEYCHAIN_KEY_NODE);
hassoe7168df2004-10-03 20:11:32 +00002277 vtysh_install_default (VTY_NODE);
paul718e3742002-12-13 20:15:29 +00002278
2279 install_element (VIEW_NODE, &vtysh_enable_cmd);
2280 install_element (ENABLE_NODE, &vtysh_config_terminal_cmd);
2281 install_element (ENABLE_NODE, &vtysh_disable_cmd);
2282
2283 /* "exit" command. */
2284 install_element (VIEW_NODE, &vtysh_exit_all_cmd);
2285 install_element (VIEW_NODE, &vtysh_quit_all_cmd);
2286 install_element (CONFIG_NODE, &vtysh_exit_all_cmd);
2287 /* install_element (CONFIG_NODE, &vtysh_quit_all_cmd); */
2288 install_element (ENABLE_NODE, &vtysh_exit_all_cmd);
2289 install_element (ENABLE_NODE, &vtysh_quit_all_cmd);
2290 install_element (RIP_NODE, &vtysh_exit_ripd_cmd);
2291 install_element (RIP_NODE, &vtysh_quit_ripd_cmd);
paul68980082003-03-25 05:07:42 +00002292 install_element (RIPNG_NODE, &vtysh_exit_ripngd_cmd);
2293 install_element (RIPNG_NODE, &vtysh_quit_ripngd_cmd);
paul718e3742002-12-13 20:15:29 +00002294 install_element (OSPF_NODE, &vtysh_exit_ospfd_cmd);
2295 install_element (OSPF_NODE, &vtysh_quit_ospfd_cmd);
paul68980082003-03-25 05:07:42 +00002296 install_element (OSPF6_NODE, &vtysh_exit_ospf6d_cmd);
2297 install_element (OSPF6_NODE, &vtysh_quit_ospf6d_cmd);
paul718e3742002-12-13 20:15:29 +00002298 install_element (BGP_NODE, &vtysh_exit_bgpd_cmd);
2299 install_element (BGP_NODE, &vtysh_quit_bgpd_cmd);
2300 install_element (BGP_VPNV4_NODE, &vtysh_exit_bgpd_cmd);
2301 install_element (BGP_VPNV4_NODE, &vtysh_quit_bgpd_cmd);
2302 install_element (BGP_IPV4_NODE, &vtysh_exit_bgpd_cmd);
2303 install_element (BGP_IPV4_NODE, &vtysh_quit_bgpd_cmd);
2304 install_element (BGP_IPV4M_NODE, &vtysh_exit_bgpd_cmd);
2305 install_element (BGP_IPV4M_NODE, &vtysh_quit_bgpd_cmd);
2306 install_element (BGP_IPV6_NODE, &vtysh_exit_bgpd_cmd);
2307 install_element (BGP_IPV6_NODE, &vtysh_quit_bgpd_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002308 install_element (BGP_IPV6M_NODE, &vtysh_exit_bgpd_cmd);
2309 install_element (BGP_IPV6M_NODE, &vtysh_quit_bgpd_cmd);
hassoc25e4582003-12-23 10:39:08 +00002310 install_element (ISIS_NODE, &vtysh_exit_isisd_cmd);
2311 install_element (ISIS_NODE, &vtysh_quit_isisd_cmd);
paul718e3742002-12-13 20:15:29 +00002312 install_element (KEYCHAIN_NODE, &vtysh_exit_ripd_cmd);
2313 install_element (KEYCHAIN_NODE, &vtysh_quit_ripd_cmd);
2314 install_element (KEYCHAIN_KEY_NODE, &vtysh_exit_ripd_cmd);
2315 install_element (KEYCHAIN_KEY_NODE, &vtysh_quit_ripd_cmd);
2316 install_element (RMAP_NODE, &vtysh_exit_rmap_cmd);
2317 install_element (RMAP_NODE, &vtysh_quit_rmap_cmd);
hassoe7168df2004-10-03 20:11:32 +00002318 install_element (VTY_NODE, &vtysh_exit_line_vty_cmd);
2319 install_element (VTY_NODE, &vtysh_quit_line_vty_cmd);
paul718e3742002-12-13 20:15:29 +00002320
2321 /* "end" command. */
2322 install_element (CONFIG_NODE, &vtysh_end_all_cmd);
2323 install_element (ENABLE_NODE, &vtysh_end_all_cmd);
2324 install_element (RIP_NODE, &vtysh_end_all_cmd);
2325 install_element (RIPNG_NODE, &vtysh_end_all_cmd);
2326 install_element (OSPF_NODE, &vtysh_end_all_cmd);
2327 install_element (OSPF6_NODE, &vtysh_end_all_cmd);
2328 install_element (BGP_NODE, &vtysh_end_all_cmd);
2329 install_element (BGP_IPV4_NODE, &vtysh_end_all_cmd);
2330 install_element (BGP_IPV4M_NODE, &vtysh_end_all_cmd);
2331 install_element (BGP_VPNV4_NODE, &vtysh_end_all_cmd);
2332 install_element (BGP_IPV6_NODE, &vtysh_end_all_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002333 install_element (BGP_IPV6M_NODE, &vtysh_end_all_cmd);
hassoc25e4582003-12-23 10:39:08 +00002334 install_element (ISIS_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002335 install_element (KEYCHAIN_NODE, &vtysh_end_all_cmd);
2336 install_element (KEYCHAIN_KEY_NODE, &vtysh_end_all_cmd);
2337 install_element (RMAP_NODE, &vtysh_end_all_cmd);
hassoe7168df2004-10-03 20:11:32 +00002338 install_element (VTY_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002339
paul338a9912003-03-01 15:44:10 +00002340 install_element (INTERFACE_NODE, &interface_desc_cmd);
paul464dc8d2003-03-28 02:25:45 +00002341 install_element (INTERFACE_NODE, &no_interface_desc_cmd);
paul718e3742002-12-13 20:15:29 +00002342 install_element (INTERFACE_NODE, &vtysh_end_all_cmd);
2343 install_element (INTERFACE_NODE, &vtysh_exit_interface_cmd);
2344 install_element (INTERFACE_NODE, &vtysh_quit_interface_cmd);
2345 install_element (CONFIG_NODE, &router_rip_cmd);
2346#ifdef HAVE_IPV6
2347 install_element (CONFIG_NODE, &router_ripng_cmd);
2348#endif
2349 install_element (CONFIG_NODE, &router_ospf_cmd);
2350#ifdef HAVE_IPV6
2351 install_element (CONFIG_NODE, &router_ospf6_cmd);
2352#endif
hassoc25e4582003-12-23 10:39:08 +00002353 install_element (CONFIG_NODE, &router_isis_cmd);
paul718e3742002-12-13 20:15:29 +00002354 install_element (CONFIG_NODE, &router_bgp_cmd);
Paul Jakma10895fd2008-07-03 19:34:48 +00002355 install_element (CONFIG_NODE, &router_bgp_view_cmd);
paul718e3742002-12-13 20:15:29 +00002356 install_element (BGP_NODE, &address_family_vpnv4_cmd);
2357 install_element (BGP_NODE, &address_family_vpnv4_unicast_cmd);
2358 install_element (BGP_NODE, &address_family_ipv4_unicast_cmd);
2359 install_element (BGP_NODE, &address_family_ipv4_multicast_cmd);
2360#ifdef HAVE_IPV6
2361 install_element (BGP_NODE, &address_family_ipv6_cmd);
2362 install_element (BGP_NODE, &address_family_ipv6_unicast_cmd);
2363#endif
2364 install_element (BGP_VPNV4_NODE, &exit_address_family_cmd);
2365 install_element (BGP_IPV4_NODE, &exit_address_family_cmd);
2366 install_element (BGP_IPV4M_NODE, &exit_address_family_cmd);
2367 install_element (BGP_IPV6_NODE, &exit_address_family_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002368 install_element (BGP_IPV6M_NODE, &exit_address_family_cmd);
paul718e3742002-12-13 20:15:29 +00002369 install_element (CONFIG_NODE, &key_chain_cmd);
2370 install_element (CONFIG_NODE, &route_map_cmd);
hassoe7168df2004-10-03 20:11:32 +00002371 install_element (CONFIG_NODE, &vtysh_line_vty_cmd);
paul718e3742002-12-13 20:15:29 +00002372 install_element (KEYCHAIN_NODE, &key_cmd);
2373 install_element (KEYCHAIN_NODE, &key_chain_cmd);
2374 install_element (KEYCHAIN_KEY_NODE, &key_chain_cmd);
2375 install_element (CONFIG_NODE, &vtysh_interface_cmd);
paul32d24632003-05-23 09:25:20 +00002376 install_element (CONFIG_NODE, &vtysh_no_interface_cmd);
paul718e3742002-12-13 20:15:29 +00002377 install_element (ENABLE_NODE, &vtysh_show_running_config_cmd);
2378 install_element (ENABLE_NODE, &vtysh_copy_runningconfig_startupconfig_cmd);
2379 install_element (ENABLE_NODE, &vtysh_write_file_cmd);
hasso4a6e2252003-05-25 11:51:29 +00002380 install_element (ENABLE_NODE, &vtysh_write_cmd);
paul718e3742002-12-13 20:15:29 +00002381
hasso95e735b2004-08-26 13:08:30 +00002382 /* "write terminal" command. */
paul718e3742002-12-13 20:15:29 +00002383 install_element (ENABLE_NODE, &vtysh_write_terminal_cmd);
hassoe7168df2004-10-03 20:11:32 +00002384
2385 install_element (CONFIG_NODE, &vtysh_integrated_config_cmd);
2386 install_element (CONFIG_NODE, &no_vtysh_integrated_config_cmd);
paul718e3742002-12-13 20:15:29 +00002387
hasso95e735b2004-08-26 13:08:30 +00002388 /* "write memory" command. */
paul718e3742002-12-13 20:15:29 +00002389 install_element (ENABLE_NODE, &vtysh_write_memory_cmd);
paul718e3742002-12-13 20:15:29 +00002390
hasso34553cc2004-08-27 13:56:39 +00002391 install_element (VIEW_NODE, &vtysh_terminal_length_cmd);
2392 install_element (ENABLE_NODE, &vtysh_terminal_length_cmd);
2393 install_element (VIEW_NODE, &vtysh_terminal_no_length_cmd);
2394 install_element (ENABLE_NODE, &vtysh_terminal_no_length_cmd);
hassof2799e62004-10-28 17:43:11 +00002395 install_element (VIEW_NODE, &vtysh_show_daemons_cmd);
2396 install_element (ENABLE_NODE, &vtysh_show_daemons_cmd);
hasso34553cc2004-08-27 13:56:39 +00002397
paul718e3742002-12-13 20:15:29 +00002398 install_element (VIEW_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002399 install_element (VIEW_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00002400 install_element (VIEW_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002401 install_element (VIEW_NODE, &vtysh_traceroute_ip_cmd);
2402#ifdef HAVE_IPV6
2403 install_element (VIEW_NODE, &vtysh_ping6_cmd);
2404 install_element (VIEW_NODE, &vtysh_traceroute6_cmd);
2405#endif
paul718e3742002-12-13 20:15:29 +00002406 install_element (VIEW_NODE, &vtysh_telnet_cmd);
2407 install_element (VIEW_NODE, &vtysh_telnet_port_cmd);
paul5087df52003-01-25 06:56:09 +00002408 install_element (VIEW_NODE, &vtysh_ssh_cmd);
paul718e3742002-12-13 20:15:29 +00002409 install_element (ENABLE_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002410 install_element (ENABLE_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00002411 install_element (ENABLE_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002412 install_element (ENABLE_NODE, &vtysh_traceroute_ip_cmd);
2413#ifdef HAVE_IPV6
2414 install_element (ENABLE_NODE, &vtysh_ping6_cmd);
2415 install_element (ENABLE_NODE, &vtysh_traceroute6_cmd);
2416#endif
paul718e3742002-12-13 20:15:29 +00002417 install_element (ENABLE_NODE, &vtysh_telnet_cmd);
2418 install_element (ENABLE_NODE, &vtysh_telnet_port_cmd);
hasso67e29ab2004-08-26 22:21:31 +00002419 install_element (ENABLE_NODE, &vtysh_ssh_cmd);
paul718e3742002-12-13 20:15:29 +00002420 install_element (ENABLE_NODE, &vtysh_start_shell_cmd);
2421 install_element (ENABLE_NODE, &vtysh_start_bash_cmd);
2422 install_element (ENABLE_NODE, &vtysh_start_zsh_cmd);
Paul Jakmadbf7d132006-05-23 22:10:01 +00002423
Paul Jakma362b4032006-05-28 07:54:45 +00002424 install_element (VIEW_NODE, &vtysh_show_memory_cmd);
2425 install_element (ENABLE_NODE, &vtysh_show_memory_cmd);
2426
Paul Jakmadbf7d132006-05-23 22:10:01 +00002427 /* Logging */
2428 install_element (ENABLE_NODE, &vtysh_show_logging_cmd);
2429 install_element (VIEW_NODE, &vtysh_show_logging_cmd);
paul718e3742002-12-13 20:15:29 +00002430 install_element (CONFIG_NODE, &vtysh_log_stdout_cmd);
ajs274a4a42004-12-07 15:39:31 +00002431 install_element (CONFIG_NODE, &vtysh_log_stdout_level_cmd);
paul718e3742002-12-13 20:15:29 +00002432 install_element (CONFIG_NODE, &no_vtysh_log_stdout_cmd);
2433 install_element (CONFIG_NODE, &vtysh_log_file_cmd);
ajs274a4a42004-12-07 15:39:31 +00002434 install_element (CONFIG_NODE, &vtysh_log_file_level_cmd);
paul718e3742002-12-13 20:15:29 +00002435 install_element (CONFIG_NODE, &no_vtysh_log_file_cmd);
ajs274a4a42004-12-07 15:39:31 +00002436 install_element (CONFIG_NODE, &no_vtysh_log_file_level_cmd);
2437 install_element (CONFIG_NODE, &vtysh_log_monitor_cmd);
2438 install_element (CONFIG_NODE, &vtysh_log_monitor_level_cmd);
2439 install_element (CONFIG_NODE, &no_vtysh_log_monitor_cmd);
paul718e3742002-12-13 20:15:29 +00002440 install_element (CONFIG_NODE, &vtysh_log_syslog_cmd);
ajs274a4a42004-12-07 15:39:31 +00002441 install_element (CONFIG_NODE, &vtysh_log_syslog_level_cmd);
paul718e3742002-12-13 20:15:29 +00002442 install_element (CONFIG_NODE, &no_vtysh_log_syslog_cmd);
2443 install_element (CONFIG_NODE, &vtysh_log_trap_cmd);
2444 install_element (CONFIG_NODE, &no_vtysh_log_trap_cmd);
ajs274a4a42004-12-07 15:39:31 +00002445 install_element (CONFIG_NODE, &vtysh_log_facility_cmd);
2446 install_element (CONFIG_NODE, &no_vtysh_log_facility_cmd);
paul718e3742002-12-13 20:15:29 +00002447 install_element (CONFIG_NODE, &vtysh_log_record_priority_cmd);
2448 install_element (CONFIG_NODE, &no_vtysh_log_record_priority_cmd);
Andrew J. Schorrc749b722007-04-29 03:53:31 +00002449 install_element (CONFIG_NODE, &vtysh_log_timestamp_precision_cmd);
2450 install_element (CONFIG_NODE, &no_vtysh_log_timestamp_precision_cmd);
hassoe7168df2004-10-03 20:11:32 +00002451
2452 install_element (CONFIG_NODE, &vtysh_service_password_encrypt_cmd);
2453 install_element (CONFIG_NODE, &no_vtysh_service_password_encrypt_cmd);
2454
2455 install_element (CONFIG_NODE, &vtysh_password_cmd);
2456 install_element (CONFIG_NODE, &vtysh_password_text_cmd);
2457 install_element (CONFIG_NODE, &vtysh_enable_password_cmd);
2458 install_element (CONFIG_NODE, &vtysh_enable_password_text_cmd);
2459 install_element (CONFIG_NODE, &no_vtysh_enable_password_cmd);
2460
paul718e3742002-12-13 20:15:29 +00002461}