blob: 2dbb53379c6e3fd3c83592d3844ed237945682a3 [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"
paul718e3742002-12-13 20:15:29 +000037
38/* Struct VTY. */
39struct vty *vty;
40
41/* VTY shell pager name. */
42char *vtysh_pager_name = NULL;
43
44/* VTY shell client structure. */
45struct vtysh_client
46{
47 int fd;
ajsb1aa1472005-01-28 21:11:46 +000048 const char *name;
49 int flag;
50 const char *path;
51} vtysh_client[] =
52{
53 { .fd = -1, .name = "zebra", .flag = VTYSH_ZEBRA, .path = ZEBRA_VTYSH_PATH},
54 { .fd = -1, .name = "ripd", .flag = VTYSH_RIPD, .path = RIP_VTYSH_PATH},
55 { .fd = -1, .name = "ripngd", .flag = VTYSH_RIPNGD, .path = RIPNG_VTYSH_PATH},
56 { .fd = -1, .name = "ospfd", .flag = VTYSH_OSPFD, .path = OSPF_VTYSH_PATH},
57 { .fd = -1, .name = "ospf6d", .flag = VTYSH_OSPF6D, .path = OSPF6_VTYSH_PATH},
58 { .fd = -1, .name = "bgpd", .flag = VTYSH_BGPD, .path = BGP_VTYSH_PATH},
59 { .fd = -1, .name = "isisd", .flag = VTYSH_ISISD, .path = ISIS_VTYSH_PATH},
60};
61
62#define VTYSH_INDEX_MAX (sizeof(vtysh_client)/sizeof(vtysh_client[0]))
63
64/* We need direct access to ripd to implement vtysh_exit_ripd_only. */
65static struct vtysh_client *ripd_client = NULL;
66
hassob094d262004-08-25 12:22:00 +000067
hassoe7168df2004-10-03 20:11:32 +000068/* Using integrated config from Quagga.conf. Default is no. */
69int vtysh_writeconfig_integrated = 0;
70
71extern char config_default[];
72
ajs274a4a42004-12-07 15:39:31 +000073static void
paul718e3742002-12-13 20:15:29 +000074vclient_close (struct vtysh_client *vclient)
75{
ajsb1aa1472005-01-28 21:11:46 +000076 if (vclient->fd >= 0)
77 {
78 fprintf(stderr,
79 "Warning: closing connection to %s because of an I/O error!\n",
80 vclient->name);
81 close (vclient->fd);
82 vclient->fd = -1;
83 }
paul718e3742002-12-13 20:15:29 +000084}
85
paul718e3742002-12-13 20:15:29 +000086/* Following filled with debug code to trace a problematic condition
hasso95e735b2004-08-26 13:08:30 +000087 * under load - it SHOULD handle it. */
paul718e3742002-12-13 20:15:29 +000088#define ERR_WHERE_STRING "vtysh(): vtysh_client_config(): "
ajs274a4a42004-12-07 15:39:31 +000089static int
paul718e3742002-12-13 20:15:29 +000090vtysh_client_config (struct vtysh_client *vclient, char *line)
91{
92 int ret;
93 char *buf;
94 size_t bufsz;
95 char *pbuf;
96 size_t left;
97 char *eoln;
98 int nbytes;
99 int i;
100 int readln;
101
102 if (vclient->fd < 0)
103 return CMD_SUCCESS;
104
105 ret = write (vclient->fd, line, strlen (line) + 1);
106 if (ret <= 0)
107 {
108 vclient_close (vclient);
109 return CMD_SUCCESS;
110 }
111
hasso95e735b2004-08-26 13:08:30 +0000112 /* Allow enough room for buffer to read more than a few pages from socket. */
paule3d29b52003-01-23 18:05:42 +0000113 bufsz = 5 * getpagesize() + 1;
paul718e3742002-12-13 20:15:29 +0000114 buf = XMALLOC(MTYPE_TMP, bufsz);
115 memset(buf, 0, bufsz);
116 pbuf = buf;
117
118 while (1)
119 {
120 if (pbuf >= ((buf + bufsz) -1))
121 {
122 fprintf (stderr, ERR_WHERE_STRING \
123 "warning - pbuf beyond buffer end.\n");
124 return CMD_WARNING;
125 }
126
127 readln = (buf + bufsz) - pbuf - 1;
128 nbytes = read (vclient->fd, pbuf, readln);
129
130 if (nbytes <= 0)
131 {
132
133 if (errno == EINTR)
134 continue;
135
136 fprintf(stderr, ERR_WHERE_STRING "(%u)", errno);
137 perror("");
138
139 if (errno == EAGAIN || errno == EIO)
140 continue;
141
142 vclient_close (vclient);
143 XFREE(MTYPE_TMP, buf);
144 return CMD_SUCCESS;
145 }
146
147 pbuf[nbytes] = '\0';
148
149 if (nbytes >= 4)
150 {
151 i = nbytes - 4;
152 if (pbuf[i] == '\0' && pbuf[i + 1] == '\0' && pbuf[i + 2] == '\0')
153 {
154 ret = pbuf[i + 3];
155 break;
156 }
157 }
158 pbuf += nbytes;
159
160 /* See if a line exists in buffer, if so parse and consume it, and
hasso95e735b2004-08-26 13:08:30 +0000161 * reset read position. */
paul718e3742002-12-13 20:15:29 +0000162 if ((eoln = strrchr(buf, '\n')) == NULL)
163 continue;
164
165 if (eoln >= ((buf + bufsz) - 1))
166 {
167 fprintf (stderr, ERR_WHERE_STRING \
168 "warning - eoln beyond buffer end.\n");
169 }
170 vtysh_config_parse(buf);
171
172 eoln++;
173 left = (size_t)(buf + bufsz - eoln);
174 memmove(buf, eoln, left);
175 buf[bufsz-1] = '\0';
176 pbuf = buf + strlen(buf);
177 }
178
hasso95e735b2004-08-26 13:08:30 +0000179 /* Parse anything left in the buffer. */
hassoe7168df2004-10-03 20:11:32 +0000180
paul718e3742002-12-13 20:15:29 +0000181 vtysh_config_parse (buf);
182
183 XFREE(MTYPE_TMP, buf);
184 return ret;
185}
186
ajs274a4a42004-12-07 15:39:31 +0000187static int
hassodda09522004-10-07 21:40:25 +0000188vtysh_client_execute (struct vtysh_client *vclient, const char *line, FILE *fp)
paul718e3742002-12-13 20:15:29 +0000189{
190 int ret;
191 char buf[1001];
192 int nbytes;
paul2852de12004-09-17 06:52:16 +0000193 int i;
194 int numnulls = 0;
paul718e3742002-12-13 20:15:29 +0000195
196 if (vclient->fd < 0)
197 return CMD_SUCCESS;
198
199 ret = write (vclient->fd, line, strlen (line) + 1);
200 if (ret <= 0)
201 {
202 vclient_close (vclient);
203 return CMD_SUCCESS;
204 }
205
206 while (1)
207 {
208 nbytes = read (vclient->fd, buf, sizeof(buf)-1);
209
210 if (nbytes <= 0 && errno != EINTR)
211 {
212 vclient_close (vclient);
213 return CMD_SUCCESS;
214 }
215
216 if (nbytes > 0)
217 {
ajs85fb1e62004-11-11 14:03:39 +0000218 if ((numnulls == 3) && (nbytes == 1))
219 return buf[0];
220
paul718e3742002-12-13 20:15:29 +0000221 buf[nbytes] = '\0';
ajs85fb1e62004-11-11 14:03:39 +0000222 fputs (buf, fp);
paul718e3742002-12-13 20:15:29 +0000223 fflush (fp);
paul2852de12004-09-17 06:52:16 +0000224
paul0921d482004-10-11 18:21:55 +0000225 /* check for trailling \0\0\0<ret code>,
226 * even if split across reads
227 * (see lib/vty.c::vtysh_read)
228 */
paul2852de12004-09-17 06:52:16 +0000229 if (nbytes >= 4)
230 {
231 i = nbytes-4;
232 numnulls = 0;
233 }
234 else
235 i = 0;
236
paul0921d482004-10-11 18:21:55 +0000237 while (i < nbytes && numnulls < 3)
paul2852de12004-09-17 06:52:16 +0000238 {
239 if (buf[i++] == '\0')
240 numnulls++;
241 else
ajs85fb1e62004-11-11 14:03:39 +0000242 numnulls = 0;
paul2852de12004-09-17 06:52:16 +0000243 }
paul718e3742002-12-13 20:15:29 +0000244
ajs85fb1e62004-11-11 14:03:39 +0000245 /* got 3 or more trailing NULs? */
246 if ((numnulls >= 3) && (i < nbytes))
paul0921d482004-10-11 18:21:55 +0000247 return (buf[nbytes-1]);
paul718e3742002-12-13 20:15:29 +0000248 }
249 }
paul718e3742002-12-13 20:15:29 +0000250}
251
252void
ajsb1aa1472005-01-28 21:11:46 +0000253vtysh_exit_ripd_only (void)
paul718e3742002-12-13 20:15:29 +0000254{
ajsb1aa1472005-01-28 21:11:46 +0000255 if (ripd_client)
256 vtysh_client_execute (ripd_client, "exit", stdout);
paul718e3742002-12-13 20:15:29 +0000257}
258
259
260void
ajsb1aa1472005-01-28 21:11:46 +0000261vtysh_pager_init (void)
paul718e3742002-12-13 20:15:29 +0000262{
hasso5a9c53d2004-08-27 14:23:28 +0000263 char *pager_defined;
264
265 pager_defined = getenv ("VTYSH_PAGER");
266
267 if (pager_defined)
268 vtysh_pager_name = strdup (pager_defined);
269 else
hasso34553cc2004-08-27 13:56:39 +0000270 vtysh_pager_name = strdup ("more");
paul718e3742002-12-13 20:15:29 +0000271}
272
273/* Command execution over the vty interface. */
ajs274a4a42004-12-07 15:39:31 +0000274static void
hassodda09522004-10-07 21:40:25 +0000275vtysh_execute_func (const char *line, int pager)
paul718e3742002-12-13 20:15:29 +0000276{
277 int ret, cmd_stat;
ajsb1aa1472005-01-28 21:11:46 +0000278 u_int i;
paul718e3742002-12-13 20:15:29 +0000279 vector vline;
280 struct cmd_element *cmd;
281 FILE *fp = NULL;
hasso13bfca72005-01-23 21:42:25 +0000282 int closepager = 0;
283 int tried = 0;
284 int saved_ret, saved_node;
paul718e3742002-12-13 20:15:29 +0000285
hasso95e735b2004-08-26 13:08:30 +0000286 /* Split readline string up into the vector. */
paul718e3742002-12-13 20:15:29 +0000287 vline = cmd_make_strvec (line);
288
289 if (vline == NULL)
290 return;
291
hasso13bfca72005-01-23 21:42:25 +0000292 saved_ret = ret = cmd_execute_command (vline, vty, &cmd, 1);
293 saved_node = vty->node;
294
295 /* If command doesn't succeeded in current node, try to walk up in node tree.
296 * Changing vty->node is enough to try it just out without actual walkup in
297 * the vtysh. */
298 while (ret != CMD_SUCCESS && ret != CMD_SUCCESS_DAEMON && ret != CMD_WARNING
299 && vty->node > CONFIG_NODE)
300 {
301 vty->node = node_parent(vty->node);
302 ret = cmd_execute_command (vline, vty, &cmd, 1);
303 tried++;
304 }
305
306 vty->node = saved_node;
307
308 /* If command succeeded in any other node than current (tried > 0) we have
309 * to move into node in the vtysh where it succeeded. */
310 if (ret == CMD_SUCCESS || ret == CMD_SUCCESS_DAEMON || ret == CMD_WARNING)
311 {
312 if ((saved_node == BGP_VPNV4_NODE || saved_node == BGP_IPV4_NODE
paul57b5b7e2005-08-22 22:44:29 +0000313 || saved_node == BGP_IPV6_NODE || saved_node == BGP_IPV4M_NODE
314 || saved_node == BGP_IPV6M_NODE)
hasso13bfca72005-01-23 21:42:25 +0000315 && (tried == 1))
316 {
317 vtysh_execute("exit-address-family");
318 }
319 else if ((saved_node == KEYCHAIN_KEY_NODE) && (tried == 1))
320 {
321 vtysh_execute("exit");
322 }
323 else if (tried)
324 {
325 vtysh_execute ("end");
326 vtysh_execute ("configure terminal");
327 }
328 }
329 /* If command didn't succeed in any node, continue with return value from
330 * first try. */
331 else if (tried)
332 {
333 ret = saved_ret;
334 }
paul718e3742002-12-13 20:15:29 +0000335
336 cmd_free_strvec (vline);
337
338 switch (ret)
339 {
340 case CMD_WARNING:
341 if (vty->type == VTY_FILE)
paul4fc01e62002-12-13 20:49:00 +0000342 fprintf (stdout,"Warning...\n");
paul718e3742002-12-13 20:15:29 +0000343 break;
344 case CMD_ERR_AMBIGUOUS:
paul4fc01e62002-12-13 20:49:00 +0000345 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000346 break;
347 case CMD_ERR_NO_MATCH:
paul4fc01e62002-12-13 20:49:00 +0000348 fprintf (stdout,"%% Unknown command.\n");
paul718e3742002-12-13 20:15:29 +0000349 break;
350 case CMD_ERR_INCOMPLETE:
paul4fc01e62002-12-13 20:49:00 +0000351 fprintf (stdout,"%% Command incomplete.\n");
paul718e3742002-12-13 20:15:29 +0000352 break;
353 case CMD_SUCCESS_DAEMON:
354 {
hasso97b7db22004-10-20 19:07:48 +0000355 /* FIXME: Don't open pager for exit commands. popen() causes problems
356 * if exited from vtysh at all. This hack shouldn't cause any problem
357 * but is really ugly. */
358 if (pager && vtysh_pager_name && (strncmp(line, "exit", 4) != 0))
paul718e3742002-12-13 20:15:29 +0000359 {
paul4fc01e62002-12-13 20:49:00 +0000360 fp = popen (vtysh_pager_name, "w");
paul718e3742002-12-13 20:15:29 +0000361 if (fp == NULL)
362 {
paula805cc22003-05-01 14:29:48 +0000363 perror ("popen failed for pager");
364 fp = stdout;
paul718e3742002-12-13 20:15:29 +0000365 }
paula805cc22003-05-01 14:29:48 +0000366 else
367 closepager=1;
paul718e3742002-12-13 20:15:29 +0000368 }
369 else
370 fp = stdout;
371
372 if (! strcmp(cmd->string,"configure terminal"))
373 {
ajsb1aa1472005-01-28 21:11:46 +0000374 for (i = 0; i < VTYSH_INDEX_MAX; i++)
375 {
376 cmd_stat = vtysh_client_execute(&vtysh_client[i], line, fp);
377 if (cmd_stat == CMD_WARNING)
378 break;
379 }
380
paul718e3742002-12-13 20:15:29 +0000381 if (cmd_stat)
382 {
hassob094d262004-08-25 12:22:00 +0000383 line = "end";
384 vline = cmd_make_strvec (line);
paul718e3742002-12-13 20:15:29 +0000385
hassob094d262004-08-25 12:22:00 +0000386 if (vline == NULL)
paul718e3742002-12-13 20:15:29 +0000387 {
paula805cc22003-05-01 14:29:48 +0000388 if (pager && vtysh_pager_name && fp && closepager)
paul718e3742002-12-13 20:15:29 +0000389 {
390 if (pclose (fp) == -1)
391 {
paula805cc22003-05-01 14:29:48 +0000392 perror ("pclose failed for pager");
paul718e3742002-12-13 20:15:29 +0000393 }
394 fp = NULL;
395 }
396 return;
397 }
398
hasso87d683b2005-01-16 23:31:54 +0000399 ret = cmd_execute_command (vline, vty, &cmd, 1);
hassob094d262004-08-25 12:22:00 +0000400 cmd_free_strvec (vline);
401 if (ret != CMD_SUCCESS_DAEMON)
402 break;
paul718e3742002-12-13 20:15:29 +0000403 }
404 else
405 if (cmd->func)
406 {
407 (*cmd->func) (cmd, vty, 0, NULL);
408 break;
hassob094d262004-08-25 12:22:00 +0000409 }
paul718e3742002-12-13 20:15:29 +0000410 }
411
ajsb1aa1472005-01-28 21:11:46 +0000412 cmd_stat = CMD_SUCCESS;
413 for (i = 0; i < VTYSH_INDEX_MAX; i++)
414 {
415 if (cmd->daemon & vtysh_client[i].flag)
416 {
417 cmd_stat = vtysh_client_execute(&vtysh_client[i], line, fp);
418 if (cmd_stat != CMD_SUCCESS)
419 break;
420 }
421 }
422 if (cmd_stat != CMD_SUCCESS)
423 break;
424
paul718e3742002-12-13 20:15:29 +0000425 if (cmd->func)
426 (*cmd->func) (cmd, vty, 0, NULL);
427 }
428 }
paula805cc22003-05-01 14:29:48 +0000429 if (pager && vtysh_pager_name && fp && closepager)
paul718e3742002-12-13 20:15:29 +0000430 {
431 if (pclose (fp) == -1)
432 {
paula805cc22003-05-01 14:29:48 +0000433 perror ("pclose failed for pager");
paul718e3742002-12-13 20:15:29 +0000434 }
435 fp = NULL;
436 }
437}
438
439void
hassodda09522004-10-07 21:40:25 +0000440vtysh_execute_no_pager (const char *line)
paul718e3742002-12-13 20:15:29 +0000441{
442 vtysh_execute_func (line, 0);
443}
444
445void
hassodda09522004-10-07 21:40:25 +0000446vtysh_execute (const char *line)
paul718e3742002-12-13 20:15:29 +0000447{
448 vtysh_execute_func (line, 1);
449}
450
451/* Configration make from file. */
452int
453vtysh_config_from_file (struct vty *vty, FILE *fp)
454{
455 int ret;
456 vector vline;
457 struct cmd_element *cmd;
458
459 while (fgets (vty->buf, VTY_BUFSIZ, fp))
460 {
461 if (vty->buf[0] == '!' || vty->buf[1] == '#')
462 continue;
463
464 vline = cmd_make_strvec (vty->buf);
465
hasso95e735b2004-08-26 13:08:30 +0000466 /* In case of comment line. */
paul718e3742002-12-13 20:15:29 +0000467 if (vline == NULL)
468 continue;
469
hasso95e735b2004-08-26 13:08:30 +0000470 /* Execute configuration command : this is strict match. */
paul718e3742002-12-13 20:15:29 +0000471 ret = cmd_execute_command_strict (vline, vty, &cmd);
472
hasso95e735b2004-08-26 13:08:30 +0000473 /* Try again with setting node to CONFIG_NODE. */
paul718e3742002-12-13 20:15:29 +0000474 if (ret != CMD_SUCCESS
475 && ret != CMD_SUCCESS_DAEMON
476 && ret != CMD_WARNING)
477 {
478 if (vty->node == KEYCHAIN_KEY_NODE)
479 {
480 vty->node = KEYCHAIN_NODE;
481 vtysh_exit_ripd_only ();
482 ret = cmd_execute_command_strict (vline, vty, &cmd);
483
484 if (ret != CMD_SUCCESS
485 && ret != CMD_SUCCESS_DAEMON
486 && ret != CMD_WARNING)
487 {
488 vtysh_exit_ripd_only ();
489 vty->node = CONFIG_NODE;
490 ret = cmd_execute_command_strict (vline, vty, &cmd);
491 }
492 }
493 else
494 {
495 vtysh_execute ("end");
496 vtysh_execute ("configure terminal");
497 vty->node = CONFIG_NODE;
498 ret = cmd_execute_command_strict (vline, vty, &cmd);
499 }
500 }
501
502 cmd_free_strvec (vline);
503
504 switch (ret)
505 {
506 case CMD_WARNING:
507 if (vty->type == VTY_FILE)
paul4fc01e62002-12-13 20:49:00 +0000508 fprintf (stdout,"Warning...\n");
paul718e3742002-12-13 20:15:29 +0000509 break;
510 case CMD_ERR_AMBIGUOUS:
paul4fc01e62002-12-13 20:49:00 +0000511 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000512 break;
513 case CMD_ERR_NO_MATCH:
paul4fc01e62002-12-13 20:49:00 +0000514 fprintf (stdout,"%% Unknown command: %s", vty->buf);
paul718e3742002-12-13 20:15:29 +0000515 break;
516 case CMD_ERR_INCOMPLETE:
paul4fc01e62002-12-13 20:49:00 +0000517 fprintf (stdout,"%% Command incomplete.\n");
paul718e3742002-12-13 20:15:29 +0000518 break;
519 case CMD_SUCCESS_DAEMON:
520 {
ajsb1aa1472005-01-28 21:11:46 +0000521 u_int i;
522 int cmd_stat = CMD_SUCCESS;
523
524 for (i = 0; i < VTYSH_INDEX_MAX; i++)
525 {
paul44316fe2006-01-11 01:38:25 +0000526 if (cmd->daemon & vtysh_client[i].flag)
ajsb1aa1472005-01-28 21:11:46 +0000527 {
528 cmd_stat = vtysh_client_execute (&vtysh_client[i],
529 vty->buf, stdout);
530 if (cmd_stat != CMD_SUCCESS)
531 break;
532 }
533 }
534 if (cmd_stat != CMD_SUCCESS)
535 break;
536
paul718e3742002-12-13 20:15:29 +0000537 if (cmd->func)
538 (*cmd->func) (cmd, vty, 0, NULL);
539 }
540 }
541 }
542 return CMD_SUCCESS;
543}
544
545/* We don't care about the point of the cursor when '?' is typed. */
546int
ajsb1aa1472005-01-28 21:11:46 +0000547vtysh_rl_describe (void)
paul718e3742002-12-13 20:15:29 +0000548{
549 int ret;
hassodda09522004-10-07 21:40:25 +0000550 unsigned int i;
paul718e3742002-12-13 20:15:29 +0000551 vector vline;
552 vector describe;
553 int width;
554 struct desc *desc;
555
556 vline = cmd_make_strvec (rl_line_buffer);
557
558 /* In case of '> ?'. */
559 if (vline == NULL)
560 {
561 vline = vector_init (1);
562 vector_set (vline, '\0');
563 }
564 else
565 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
566 vector_set (vline, '\0');
567
568 describe = cmd_describe_command (vline, vty, &ret);
569
paul4fc01e62002-12-13 20:49:00 +0000570 fprintf (stdout,"\n");
paul718e3742002-12-13 20:15:29 +0000571
572 /* Ambiguous and no match error. */
573 switch (ret)
574 {
575 case CMD_ERR_AMBIGUOUS:
576 cmd_free_strvec (vline);
paul4fc01e62002-12-13 20:49:00 +0000577 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000578 rl_on_new_line ();
579 return 0;
580 break;
581 case CMD_ERR_NO_MATCH:
582 cmd_free_strvec (vline);
paul4fc01e62002-12-13 20:49:00 +0000583 fprintf (stdout,"%% There is no matched command.\n");
paul718e3742002-12-13 20:15:29 +0000584 rl_on_new_line ();
585 return 0;
586 break;
587 }
588
589 /* Get width of command string. */
590 width = 0;
paul55468c82005-03-14 20:19:01 +0000591 for (i = 0; i < vector_active (describe); i++)
paul718e3742002-12-13 20:15:29 +0000592 if ((desc = vector_slot (describe, i)) != NULL)
593 {
594 int len;
595
596 if (desc->cmd[0] == '\0')
597 continue;
598
599 len = strlen (desc->cmd);
600 if (desc->cmd[0] == '.')
601 len--;
602
603 if (width < len)
604 width = len;
605 }
606
paul55468c82005-03-14 20:19:01 +0000607 for (i = 0; i < vector_active (describe); i++)
paul718e3742002-12-13 20:15:29 +0000608 if ((desc = vector_slot (describe, i)) != NULL)
609 {
610 if (desc->cmd[0] == '\0')
611 continue;
612
613 if (! desc->str)
paul4fc01e62002-12-13 20:49:00 +0000614 fprintf (stdout," %-s\n",
hassob094d262004-08-25 12:22:00 +0000615 desc->cmd[0] == '.' ? desc->cmd + 1 : desc->cmd);
paul718e3742002-12-13 20:15:29 +0000616 else
paul4fc01e62002-12-13 20:49:00 +0000617 fprintf (stdout," %-*s %s\n",
hassob094d262004-08-25 12:22:00 +0000618 width,
619 desc->cmd[0] == '.' ? desc->cmd + 1 : desc->cmd,
620 desc->str);
paul718e3742002-12-13 20:15:29 +0000621 }
622
623 cmd_free_strvec (vline);
624 vector_free (describe);
625
626 rl_on_new_line();
627
628 return 0;
629}
630
hasso95e735b2004-08-26 13:08:30 +0000631/* Result of cmd_complete_command() call will be stored here
632 * and used in new_completion() in order to put the space in
633 * correct places only. */
paul718e3742002-12-13 20:15:29 +0000634int complete_status;
635
ajs274a4a42004-12-07 15:39:31 +0000636static char *
pauldfc0d9b2003-04-18 23:55:29 +0000637command_generator (const char *text, int state)
paul718e3742002-12-13 20:15:29 +0000638{
639 vector vline;
640 static char **matched = NULL;
641 static int index = 0;
642
643 /* First call. */
644 if (! state)
645 {
646 index = 0;
647
648 if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
649 return NULL;
650
651 vline = cmd_make_strvec (rl_line_buffer);
652 if (vline == NULL)
653 return NULL;
654
655 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
656 vector_set (vline, '\0');
657
658 matched = cmd_complete_command (vline, vty, &complete_status);
659 }
660
661 if (matched && matched[index])
662 return matched[index++];
663
664 return NULL;
665}
666
ajs274a4a42004-12-07 15:39:31 +0000667static char **
paul718e3742002-12-13 20:15:29 +0000668new_completion (char *text, int start, int end)
669{
670 char **matches;
671
pauldfc0d9b2003-04-18 23:55:29 +0000672 matches = rl_completion_matches (text, command_generator);
paul718e3742002-12-13 20:15:29 +0000673
674 if (matches)
675 {
676 rl_point = rl_end;
677 if (complete_status == CMD_COMPLETE_FULL_MATCH)
678 rl_pending_input = ' ';
679 }
680
681 return matches;
682}
683
ajs274a4a42004-12-07 15:39:31 +0000684#if 0
685/* This function is not actually being used. */
686static char **
paul718e3742002-12-13 20:15:29 +0000687vtysh_completion (char *text, int start, int end)
688{
689 int ret;
690 vector vline;
691 char **matched = NULL;
692
693 if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
694 return NULL;
695
696 vline = cmd_make_strvec (rl_line_buffer);
697 if (vline == NULL)
698 return NULL;
699
700 /* In case of 'help \t'. */
701 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
702 vector_set (vline, '\0');
703
704 matched = cmd_complete_command (vline, vty, &ret);
705
706 cmd_free_strvec (vline);
707
708 return (char **) matched;
709}
ajs274a4a42004-12-07 15:39:31 +0000710#endif
paul718e3742002-12-13 20:15:29 +0000711
hasso95e735b2004-08-26 13:08:30 +0000712/* Vty node structures. */
paul718e3742002-12-13 20:15:29 +0000713struct cmd_node bgp_node =
714{
715 BGP_NODE,
716 "%s(config-router)# ",
717};
718
paul718e3742002-12-13 20:15:29 +0000719struct cmd_node rip_node =
720{
721 RIP_NODE,
722 "%s(config-router)# ",
723};
724
hassoc25e4582003-12-23 10:39:08 +0000725struct cmd_node isis_node =
726{
727 ISIS_NODE,
728 "%s(config-router)# ",
hassoc25e4582003-12-23 10:39:08 +0000729};
730
paul718e3742002-12-13 20:15:29 +0000731struct cmd_node interface_node =
732{
733 INTERFACE_NODE,
734 "%s(config-if)# ",
735};
736
hasso95e735b2004-08-26 13:08:30 +0000737struct cmd_node rmap_node =
738{
739 RMAP_NODE,
740 "%s(config-route-map)# "
741};
742
743struct cmd_node zebra_node =
744{
745 ZEBRA_NODE,
746 "%s(config-router)# "
747};
748
749struct cmd_node bgp_vpnv4_node =
750{
751 BGP_VPNV4_NODE,
752 "%s(config-router-af)# "
753};
754
755struct cmd_node bgp_ipv4_node =
756{
757 BGP_IPV4_NODE,
758 "%s(config-router-af)# "
759};
760
761struct cmd_node bgp_ipv4m_node =
762{
763 BGP_IPV4M_NODE,
764 "%s(config-router-af)# "
765};
766
767struct cmd_node bgp_ipv6_node =
768{
769 BGP_IPV6_NODE,
770 "%s(config-router-af)# "
771};
772
paul57b5b7e2005-08-22 22:44:29 +0000773struct cmd_node bgp_ipv6m_node =
774{
775 BGP_IPV6M_NODE,
776 "%s(config-router-af)# "
777};
778
hasso95e735b2004-08-26 13:08:30 +0000779struct cmd_node ospf_node =
780{
781 OSPF_NODE,
782 "%s(config-router)# "
783};
784
785struct cmd_node ripng_node =
786{
787 RIPNG_NODE,
788 "%s(config-router)# "
789};
790
791struct cmd_node ospf6_node =
792{
793 OSPF6_NODE,
794 "%s(config-ospf6)# "
795};
796
797struct cmd_node keychain_node =
798{
799 KEYCHAIN_NODE,
800 "%s(config-keychain)# "
801};
802
803struct cmd_node keychain_key_node =
804{
805 KEYCHAIN_KEY_NODE,
806 "%s(config-keychain-key)# "
807};
808
hassoe7168df2004-10-03 20:11:32 +0000809/* Defined in lib/vty.c */
810extern struct cmd_node vty_node;
811
hasso95e735b2004-08-26 13:08:30 +0000812/* When '^Z' is received from vty, move down to the enable mode. */
813int
ajsb1aa1472005-01-28 21:11:46 +0000814vtysh_end (void)
hasso95e735b2004-08-26 13:08:30 +0000815{
816 switch (vty->node)
817 {
818 case VIEW_NODE:
819 case ENABLE_NODE:
820 /* Nothing to do. */
821 break;
822 default:
823 vty->node = ENABLE_NODE;
824 break;
825 }
826 return CMD_SUCCESS;
827}
828
829DEFUNSH (VTYSH_ALL,
830 vtysh_end_all,
831 vtysh_end_all_cmd,
832 "end",
hassoe7168df2004-10-03 20:11:32 +0000833 "End current mode and change to enable mode\n")
hasso95e735b2004-08-26 13:08:30 +0000834{
hasso42895462004-09-26 16:25:07 +0000835 return vtysh_end ();
hasso95e735b2004-08-26 13:08:30 +0000836}
837
paul718e3742002-12-13 20:15:29 +0000838DEFUNSH (VTYSH_BGPD,
839 router_bgp,
840 router_bgp_cmd,
841 "router bgp <1-65535>",
842 ROUTER_STR
843 BGP_STR
844 AS_STR)
845{
846 vty->node = BGP_NODE;
847 return CMD_SUCCESS;
848}
849
850DEFUNSH (VTYSH_BGPD,
851 address_family_vpnv4,
852 address_family_vpnv4_cmd,
853 "address-family vpnv4",
854 "Enter Address Family command mode\n"
855 "Address family\n")
856{
857 vty->node = BGP_VPNV4_NODE;
858 return CMD_SUCCESS;
859}
860
861DEFUNSH (VTYSH_BGPD,
862 address_family_vpnv4_unicast,
863 address_family_vpnv4_unicast_cmd,
864 "address-family vpnv4 unicast",
865 "Enter Address Family command mode\n"
866 "Address family\n"
867 "Address Family Modifier\n")
868{
869 vty->node = BGP_VPNV4_NODE;
870 return CMD_SUCCESS;
871}
872
873DEFUNSH (VTYSH_BGPD,
874 address_family_ipv4_unicast,
875 address_family_ipv4_unicast_cmd,
876 "address-family ipv4 unicast",
877 "Enter Address Family command mode\n"
878 "Address family\n"
879 "Address Family Modifier\n")
880{
881 vty->node = BGP_IPV4_NODE;
882 return CMD_SUCCESS;
883}
884
885DEFUNSH (VTYSH_BGPD,
886 address_family_ipv4_multicast,
887 address_family_ipv4_multicast_cmd,
888 "address-family ipv4 multicast",
889 "Enter Address Family command mode\n"
890 "Address family\n"
891 "Address Family Modifier\n")
892{
893 vty->node = BGP_IPV4M_NODE;
894 return CMD_SUCCESS;
895}
896
897DEFUNSH (VTYSH_BGPD,
898 address_family_ipv6,
899 address_family_ipv6_cmd,
900 "address-family ipv6",
901 "Enter Address Family command mode\n"
902 "Address family\n")
903{
904 vty->node = BGP_IPV6_NODE;
905 return CMD_SUCCESS;
906}
907
908DEFUNSH (VTYSH_BGPD,
909 address_family_ipv6_unicast,
910 address_family_ipv6_unicast_cmd,
911 "address-family ipv6 unicast",
912 "Enter Address Family command mode\n"
913 "Address family\n"
914 "Address Family Modifier\n")
915{
916 vty->node = BGP_IPV6_NODE;
917 return CMD_SUCCESS;
918}
919
paul57b5b7e2005-08-22 22:44:29 +0000920DEFUNSH (VTYSH_BGPD,
921 address_family_ipv6_multicast,
922 address_family_ipv6_multicast_cmd,
923 "address-family ipv6 multicast",
924 "Enter Address Family command mode\n"
925 "Address family\n"
926 "Address Family Modifier\n")
927{
928 vty->node = BGP_IPV6M_NODE;
929 return CMD_SUCCESS;
930}
931
paul718e3742002-12-13 20:15:29 +0000932DEFUNSH (VTYSH_RIPD,
933 key_chain,
934 key_chain_cmd,
935 "key chain WORD",
936 "Authentication key management\n"
937 "Key-chain management\n"
938 "Key-chain name\n")
939{
940 vty->node = KEYCHAIN_NODE;
941 return CMD_SUCCESS;
942}
943
944DEFUNSH (VTYSH_RIPD,
945 key,
946 key_cmd,
947 "key <0-2147483647>",
948 "Configure a key\n"
949 "Key identifier number\n")
950{
951 vty->node = KEYCHAIN_KEY_NODE;
952 return CMD_SUCCESS;
953}
954
955DEFUNSH (VTYSH_RIPD,
956 router_rip,
957 router_rip_cmd,
958 "router rip",
959 ROUTER_STR
960 "RIP")
961{
962 vty->node = RIP_NODE;
963 return CMD_SUCCESS;
964}
965
966DEFUNSH (VTYSH_RIPNGD,
967 router_ripng,
968 router_ripng_cmd,
969 "router ripng",
970 ROUTER_STR
971 "RIPng")
972{
973 vty->node = RIPNG_NODE;
974 return CMD_SUCCESS;
975}
976
977DEFUNSH (VTYSH_OSPFD,
978 router_ospf,
979 router_ospf_cmd,
980 "router ospf",
981 "Enable a routing process\n"
982 "Start OSPF configuration\n")
983{
984 vty->node = OSPF_NODE;
985 return CMD_SUCCESS;
986}
987
988DEFUNSH (VTYSH_OSPF6D,
989 router_ospf6,
990 router_ospf6_cmd,
991 "router ospf6",
992 OSPF6_ROUTER_STR
993 OSPF6_STR)
994{
995 vty->node = OSPF6_NODE;
996 return CMD_SUCCESS;
997}
998
hassoc25e4582003-12-23 10:39:08 +0000999DEFUNSH (VTYSH_ISISD,
hassob094d262004-08-25 12:22:00 +00001000 router_isis,
1001 router_isis_cmd,
1002 "router isis WORD",
1003 ROUTER_STR
1004 "ISO IS-IS\n"
1005 "ISO Routing area tag")
hassoc25e4582003-12-23 10:39:08 +00001006{
1007 vty->node = ISIS_NODE;
1008 return CMD_SUCCESS;
1009}
1010
paul718e3742002-12-13 20:15:29 +00001011DEFUNSH (VTYSH_RMAP,
1012 route_map,
1013 route_map_cmd,
1014 "route-map WORD (deny|permit) <1-65535>",
1015 "Create route-map or enter route-map command mode\n"
1016 "Route map tag\n"
1017 "Route map denies set operations\n"
1018 "Route map permits set operations\n"
1019 "Sequence to insert to/delete from existing route-map entry\n")
1020{
1021 vty->node = RMAP_NODE;
1022 return CMD_SUCCESS;
1023}
1024
paul718e3742002-12-13 20:15:29 +00001025DEFUNSH (VTYSH_ALL,
hassoe7168df2004-10-03 20:11:32 +00001026 vtysh_line_vty,
1027 vtysh_line_vty_cmd,
1028 "line vty",
1029 "Configure a terminal line\n"
1030 "Virtual terminal\n")
1031{
1032 vty->node = VTY_NODE;
1033 return CMD_SUCCESS;
1034}
1035
1036DEFUNSH (VTYSH_ALL,
paul718e3742002-12-13 20:15:29 +00001037 vtysh_enable,
1038 vtysh_enable_cmd,
1039 "enable",
1040 "Turn on privileged mode command\n")
1041{
1042 vty->node = ENABLE_NODE;
1043 return CMD_SUCCESS;
1044}
1045
paul718e3742002-12-13 20:15:29 +00001046DEFUNSH (VTYSH_ALL,
1047 vtysh_disable,
1048 vtysh_disable_cmd,
1049 "disable",
1050 "Turn off privileged mode command\n")
1051{
1052 if (vty->node == ENABLE_NODE)
1053 vty->node = VIEW_NODE;
1054 return CMD_SUCCESS;
1055}
1056
paul718e3742002-12-13 20:15:29 +00001057DEFUNSH (VTYSH_ALL,
1058 vtysh_config_terminal,
1059 vtysh_config_terminal_cmd,
1060 "configure terminal",
1061 "Configuration from vty interface\n"
1062 "Configuration terminal\n")
1063{
1064 vty->node = CONFIG_NODE;
1065 return CMD_SUCCESS;
1066}
1067
ajs274a4a42004-12-07 15:39:31 +00001068static int
paul718e3742002-12-13 20:15:29 +00001069vtysh_exit (struct vty *vty)
1070{
1071 switch (vty->node)
1072 {
1073 case VIEW_NODE:
1074 case ENABLE_NODE:
1075 exit (0);
1076 break;
1077 case CONFIG_NODE:
1078 vty->node = ENABLE_NODE;
1079 break;
1080 case INTERFACE_NODE:
1081 case ZEBRA_NODE:
1082 case BGP_NODE:
1083 case RIP_NODE:
1084 case RIPNG_NODE:
1085 case OSPF_NODE:
1086 case OSPF6_NODE:
hassoc25e4582003-12-23 10:39:08 +00001087 case ISIS_NODE:
paul718e3742002-12-13 20:15:29 +00001088 case MASC_NODE:
1089 case RMAP_NODE:
1090 case VTY_NODE:
1091 case KEYCHAIN_NODE:
hasso2a56df92004-05-09 23:16:40 +00001092 vtysh_execute("end");
1093 vtysh_execute("configure terminal");
paul718e3742002-12-13 20:15:29 +00001094 vty->node = CONFIG_NODE;
1095 break;
1096 case BGP_VPNV4_NODE:
1097 case BGP_IPV4_NODE:
1098 case BGP_IPV4M_NODE:
1099 case BGP_IPV6_NODE:
paul57b5b7e2005-08-22 22:44:29 +00001100 case BGP_IPV6M_NODE:
paul718e3742002-12-13 20:15:29 +00001101 vty->node = BGP_NODE;
1102 break;
1103 case KEYCHAIN_KEY_NODE:
1104 vty->node = KEYCHAIN_NODE;
1105 break;
1106 default:
1107 break;
1108 }
1109 return CMD_SUCCESS;
1110}
1111
1112DEFUNSH (VTYSH_ALL,
1113 vtysh_exit_all,
1114 vtysh_exit_all_cmd,
1115 "exit",
1116 "Exit current mode and down to previous mode\n")
1117{
1118 return vtysh_exit (vty);
1119}
1120
1121ALIAS (vtysh_exit_all,
1122 vtysh_quit_all_cmd,
1123 "quit",
1124 "Exit current mode and down to previous mode\n")
1125
1126DEFUNSH (VTYSH_BGPD,
1127 exit_address_family,
1128 exit_address_family_cmd,
1129 "exit-address-family",
1130 "Exit from Address Family configuration mode\n")
1131{
1132 if (vty->node == BGP_IPV4_NODE
1133 || vty->node == BGP_IPV4M_NODE
1134 || vty->node == BGP_VPNV4_NODE
paul57b5b7e2005-08-22 22:44:29 +00001135 || vty->node == BGP_IPV6_NODE
1136 || vty->node == BGP_IPV6M_NODE)
paul718e3742002-12-13 20:15:29 +00001137 vty->node = BGP_NODE;
1138 return CMD_SUCCESS;
1139}
1140
1141DEFUNSH (VTYSH_ZEBRA,
1142 vtysh_exit_zebra,
1143 vtysh_exit_zebra_cmd,
1144 "exit",
1145 "Exit current mode and down to previous mode\n")
1146{
1147 return vtysh_exit (vty);
1148}
1149
1150ALIAS (vtysh_exit_zebra,
1151 vtysh_quit_zebra_cmd,
1152 "quit",
1153 "Exit current mode and down to previous mode\n")
1154
1155DEFUNSH (VTYSH_RIPD,
1156 vtysh_exit_ripd,
1157 vtysh_exit_ripd_cmd,
1158 "exit",
1159 "Exit current mode and down to previous mode\n")
1160{
1161 return vtysh_exit (vty);
1162}
1163
1164ALIAS (vtysh_exit_ripd,
1165 vtysh_quit_ripd_cmd,
1166 "quit",
1167 "Exit current mode and down to previous mode\n")
1168
paul68980082003-03-25 05:07:42 +00001169DEFUNSH (VTYSH_RIPNGD,
hassob094d262004-08-25 12:22:00 +00001170 vtysh_exit_ripngd,
1171 vtysh_exit_ripngd_cmd,
1172 "exit",
1173 "Exit current mode and down to previous mode\n")
paul68980082003-03-25 05:07:42 +00001174{
1175 return vtysh_exit (vty);
1176}
1177
1178ALIAS (vtysh_exit_ripngd,
1179 vtysh_quit_ripngd_cmd,
1180 "quit",
1181 "Exit current mode and down to previous mode\n")
1182
paul718e3742002-12-13 20:15:29 +00001183DEFUNSH (VTYSH_RMAP,
1184 vtysh_exit_rmap,
1185 vtysh_exit_rmap_cmd,
1186 "exit",
1187 "Exit current mode and down to previous mode\n")
1188{
1189 return vtysh_exit (vty);
1190}
1191
1192ALIAS (vtysh_exit_rmap,
1193 vtysh_quit_rmap_cmd,
1194 "quit",
1195 "Exit current mode and down to previous mode\n")
1196
1197DEFUNSH (VTYSH_BGPD,
1198 vtysh_exit_bgpd,
1199 vtysh_exit_bgpd_cmd,
1200 "exit",
1201 "Exit current mode and down to previous mode\n")
1202{
1203 return vtysh_exit (vty);
1204}
1205
1206ALIAS (vtysh_exit_bgpd,
1207 vtysh_quit_bgpd_cmd,
1208 "quit",
1209 "Exit current mode and down to previous mode\n")
1210
1211DEFUNSH (VTYSH_OSPFD,
1212 vtysh_exit_ospfd,
1213 vtysh_exit_ospfd_cmd,
1214 "exit",
1215 "Exit current mode and down to previous mode\n")
1216{
1217 return vtysh_exit (vty);
1218}
1219
1220ALIAS (vtysh_exit_ospfd,
1221 vtysh_quit_ospfd_cmd,
1222 "quit",
1223 "Exit current mode and down to previous mode\n")
1224
paul68980082003-03-25 05:07:42 +00001225DEFUNSH (VTYSH_OSPF6D,
hassob094d262004-08-25 12:22:00 +00001226 vtysh_exit_ospf6d,
1227 vtysh_exit_ospf6d_cmd,
1228 "exit",
1229 "Exit current mode and down to previous mode\n")
paul68980082003-03-25 05:07:42 +00001230{
1231 return vtysh_exit (vty);
1232}
1233
1234ALIAS (vtysh_exit_ospf6d,
1235 vtysh_quit_ospf6d_cmd,
1236 "quit",
1237 "Exit current mode and down to previous mode\n")
1238
hassoc25e4582003-12-23 10:39:08 +00001239DEFUNSH (VTYSH_ISISD,
hassob094d262004-08-25 12:22:00 +00001240 vtysh_exit_isisd,
1241 vtysh_exit_isisd_cmd,
1242 "exit",
1243 "Exit current mode and down to previous mode\n")
hassoc25e4582003-12-23 10:39:08 +00001244{
1245 return vtysh_exit (vty);
1246}
1247
1248ALIAS (vtysh_exit_isisd,
1249 vtysh_quit_isisd_cmd,
1250 "quit",
1251 "Exit current mode and down to previous mode\n")
1252
hassoe7168df2004-10-03 20:11:32 +00001253DEFUNSH (VTYSH_ALL,
1254 vtysh_exit_line_vty,
1255 vtysh_exit_line_vty_cmd,
1256 "exit",
1257 "Exit current mode and down to previous mode\n")
1258{
1259 return vtysh_exit (vty);
1260}
1261
1262ALIAS (vtysh_exit_line_vty,
1263 vtysh_quit_line_vty_cmd,
1264 "quit",
1265 "Exit current mode and down to previous mode\n")
1266
hasso95e735b2004-08-26 13:08:30 +00001267DEFUNSH (VTYSH_INTERFACE,
paul718e3742002-12-13 20:15:29 +00001268 vtysh_interface,
1269 vtysh_interface_cmd,
1270 "interface IFNAME",
1271 "Select an interface to configure\n"
1272 "Interface's name\n")
1273{
1274 vty->node = INTERFACE_NODE;
1275 return CMD_SUCCESS;
1276}
1277
hasso95e735b2004-08-26 13:08:30 +00001278/* TODO Implement "no interface command in isisd. */
paul32d24632003-05-23 09:25:20 +00001279DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D,
1280 vtysh_no_interface_cmd,
1281 "no interface IFNAME",
1282 NO_STR
1283 "Delete a pseudo interface's configuration\n"
1284 "Interface's name\n")
1285
hasso95e735b2004-08-26 13:08:30 +00001286/* TODO Implement interface description commands in ripngd, ospf6d
1287 * and isisd. */
paul338a9912003-03-01 15:44:10 +00001288DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1289 interface_desc_cmd,
1290 "description .LINE",
1291 "Interface specific description\n"
1292 "Characters describing this interface\n")
paul464dc8d2003-03-28 02:25:45 +00001293
1294DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1295 no_interface_desc_cmd,
1296 "no description",
1297 NO_STR
1298 "Interface specific description\n")
paul338a9912003-03-01 15:44:10 +00001299
hasso95e735b2004-08-26 13:08:30 +00001300DEFUNSH (VTYSH_INTERFACE,
paul718e3742002-12-13 20:15:29 +00001301 vtysh_exit_interface,
1302 vtysh_exit_interface_cmd,
1303 "exit",
1304 "Exit current mode and down to previous mode\n")
1305{
1306 return vtysh_exit (vty);
1307}
1308
1309ALIAS (vtysh_exit_interface,
1310 vtysh_quit_interface_cmd,
1311 "quit",
1312 "Exit current mode and down to previous mode\n")
1313
hasso95e735b2004-08-26 13:08:30 +00001314/* Logging commands. */
Paul Jakmadbf7d132006-05-23 22:10:01 +00001315DEFUN (vtysh_show_logging,
1316 vtysh_show_logging_cmd,
1317 "show logging",
1318 SHOW_STR
1319 "Show current logging configuration\n")
1320{
1321 unsigned int i;
1322 int ret = CMD_SUCCESS;
1323 char line[] = "show logging\n";
1324
1325 for (i = 0; i < VTYSH_INDEX_MAX; i++)
Paul Jakma4150f332006-05-23 22:10:55 +00001326 if ( vtysh_client[i].fd >= 0 )
1327 {
1328 fprintf (stdout,"Logging configuration for %s:\n",
1329 vtysh_client[i].name);
1330 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1331 fprintf (stdout,"\n");
1332 }
1333
Paul Jakmadbf7d132006-05-23 22:10:01 +00001334 return ret;
1335}
1336
hasso95e735b2004-08-26 13:08:30 +00001337DEFUNSH (VTYSH_ALL,
1338 vtysh_log_stdout,
1339 vtysh_log_stdout_cmd,
1340 "log stdout",
1341 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001342 "Set stdout logging level\n")
1343{
1344 return CMD_SUCCESS;
1345}
1346
1347DEFUNSH (VTYSH_ALL,
1348 vtysh_log_stdout_level,
1349 vtysh_log_stdout_level_cmd,
1350 "log stdout "LOG_LEVELS,
1351 "Logging control\n"
1352 "Set stdout logging level\n"
1353 LOG_LEVEL_DESC)
hasso95e735b2004-08-26 13:08:30 +00001354{
1355 return CMD_SUCCESS;
1356}
1357
1358DEFUNSH (VTYSH_ALL,
1359 no_vtysh_log_stdout,
1360 no_vtysh_log_stdout_cmd,
ajs274a4a42004-12-07 15:39:31 +00001361 "no log stdout [LEVEL]",
hasso95e735b2004-08-26 13:08:30 +00001362 NO_STR
1363 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001364 "Cancel logging to stdout\n"
1365 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001366{
1367 return CMD_SUCCESS;
1368}
1369
1370DEFUNSH (VTYSH_ALL,
1371 vtysh_log_file,
1372 vtysh_log_file_cmd,
1373 "log file FILENAME",
1374 "Logging control\n"
1375 "Logging to file\n"
1376 "Logging filename\n")
1377{
1378 return CMD_SUCCESS;
1379}
1380
1381DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001382 vtysh_log_file_level,
1383 vtysh_log_file_level_cmd,
1384 "log file FILENAME "LOG_LEVELS,
1385 "Logging control\n"
1386 "Logging to file\n"
1387 "Logging filename\n"
1388 LOG_LEVEL_DESC)
1389{
1390 return CMD_SUCCESS;
1391}
1392
1393DEFUNSH (VTYSH_ALL,
hasso95e735b2004-08-26 13:08:30 +00001394 no_vtysh_log_file,
1395 no_vtysh_log_file_cmd,
1396 "no log file [FILENAME]",
1397 NO_STR
1398 "Logging control\n"
1399 "Cancel logging to file\n"
1400 "Logging file name\n")
1401{
1402 return CMD_SUCCESS;
1403}
1404
ajs274a4a42004-12-07 15:39:31 +00001405ALIAS_SH (VTYSH_ALL,
1406 no_vtysh_log_file,
1407 no_vtysh_log_file_level_cmd,
1408 "no log file FILENAME LEVEL",
1409 NO_STR
1410 "Logging control\n"
1411 "Cancel logging to file\n"
1412 "Logging file name\n"
1413 "Logging level\n")
1414
1415DEFUNSH (VTYSH_ALL,
1416 vtysh_log_monitor,
1417 vtysh_log_monitor_cmd,
1418 "log monitor",
1419 "Logging control\n"
1420 "Set terminal line (monitor) logging level\n")
1421{
1422 return CMD_SUCCESS;
1423}
1424
1425DEFUNSH (VTYSH_ALL,
1426 vtysh_log_monitor_level,
1427 vtysh_log_monitor_level_cmd,
1428 "log monitor "LOG_LEVELS,
1429 "Logging control\n"
1430 "Set terminal line (monitor) logging level\n"
1431 LOG_LEVEL_DESC)
1432{
1433 return CMD_SUCCESS;
1434}
1435
1436DEFUNSH (VTYSH_ALL,
1437 no_vtysh_log_monitor,
1438 no_vtysh_log_monitor_cmd,
1439 "no log monitor [LEVEL]",
1440 NO_STR
1441 "Logging control\n"
1442 "Disable terminal line (monitor) logging\n"
1443 "Logging level\n")
1444{
1445 return CMD_SUCCESS;
1446}
1447
hasso95e735b2004-08-26 13:08:30 +00001448DEFUNSH (VTYSH_ALL,
1449 vtysh_log_syslog,
1450 vtysh_log_syslog_cmd,
1451 "log syslog",
1452 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001453 "Set syslog logging level\n")
1454{
1455 return CMD_SUCCESS;
1456}
1457
1458DEFUNSH (VTYSH_ALL,
1459 vtysh_log_syslog_level,
1460 vtysh_log_syslog_level_cmd,
1461 "log syslog "LOG_LEVELS,
1462 "Logging control\n"
1463 "Set syslog logging level\n"
1464 LOG_LEVEL_DESC)
hasso95e735b2004-08-26 13:08:30 +00001465{
1466 return CMD_SUCCESS;
1467}
1468
1469DEFUNSH (VTYSH_ALL,
1470 no_vtysh_log_syslog,
1471 no_vtysh_log_syslog_cmd,
ajs274a4a42004-12-07 15:39:31 +00001472 "no log syslog [LEVEL]",
hasso95e735b2004-08-26 13:08:30 +00001473 NO_STR
1474 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001475 "Cancel logging to syslog\n"
1476 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001477{
1478 return CMD_SUCCESS;
1479}
1480
1481DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001482 vtysh_log_facility,
1483 vtysh_log_facility_cmd,
1484 "log facility "LOG_FACILITIES,
hasso95e735b2004-08-26 13:08:30 +00001485 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001486 "Facility parameter for syslog messages\n"
1487 LOG_FACILITY_DESC)
1488
hasso95e735b2004-08-26 13:08:30 +00001489{
1490 return CMD_SUCCESS;
1491}
1492
1493DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001494 no_vtysh_log_facility,
1495 no_vtysh_log_facility_cmd,
1496 "no log facility [FACILITY]",
hasso95e735b2004-08-26 13:08:30 +00001497 NO_STR
1498 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001499 "Reset syslog facility to default (daemon)\n"
1500 "Syslog facility\n")
1501
1502{
1503 return CMD_SUCCESS;
1504}
1505
1506DEFUNSH_DEPRECATED (VTYSH_ALL,
1507 vtysh_log_trap,
1508 vtysh_log_trap_cmd,
1509 "log trap "LOG_LEVELS,
1510 "Logging control\n"
1511 "(Deprecated) Set logging level and default for all destinations\n"
1512 LOG_LEVEL_DESC)
1513
1514{
1515 return CMD_SUCCESS;
1516}
1517
1518DEFUNSH_DEPRECATED (VTYSH_ALL,
1519 no_vtysh_log_trap,
1520 no_vtysh_log_trap_cmd,
1521 "no log trap [LEVEL]",
1522 NO_STR
1523 "Logging control\n"
1524 "Permit all logging information\n"
1525 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001526{
1527 return CMD_SUCCESS;
1528}
1529
1530DEFUNSH (VTYSH_ALL,
1531 vtysh_log_record_priority,
1532 vtysh_log_record_priority_cmd,
1533 "log record-priority",
1534 "Logging control\n"
1535 "Log the priority of the message within the message\n")
1536{
1537 return CMD_SUCCESS;
1538}
1539
1540DEFUNSH (VTYSH_ALL,
1541 no_vtysh_log_record_priority,
1542 no_vtysh_log_record_priority_cmd,
1543 "no log record-priority",
1544 NO_STR
1545 "Logging control\n"
1546 "Do not log the priority of the message within the message\n")
1547{
1548 return CMD_SUCCESS;
1549}
1550
hassoe7168df2004-10-03 20:11:32 +00001551DEFUNSH (VTYSH_ALL,
1552 vtysh_service_password_encrypt,
1553 vtysh_service_password_encrypt_cmd,
1554 "service password-encryption",
1555 "Set up miscellaneous service\n"
1556 "Enable encrypted passwords\n")
1557{
1558 return CMD_SUCCESS;
1559}
1560
1561DEFUNSH (VTYSH_ALL,
1562 no_vtysh_service_password_encrypt,
1563 no_vtysh_service_password_encrypt_cmd,
1564 "no service password-encryption",
1565 NO_STR
1566 "Set up miscellaneous service\n"
1567 "Enable encrypted passwords\n")
1568{
1569 return CMD_SUCCESS;
1570}
1571
1572DEFUNSH (VTYSH_ALL,
1573 vtysh_config_password,
1574 vtysh_password_cmd,
1575 "password (8|) WORD",
1576 "Assign the terminal connection password\n"
1577 "Specifies a HIDDEN password will follow\n"
1578 "dummy string \n"
1579 "The HIDDEN line password string\n")
1580{
1581 return CMD_SUCCESS;
1582}
1583
1584DEFUNSH (VTYSH_ALL,
1585 vtysh_password_text,
1586 vtysh_password_text_cmd,
1587 "password LINE",
1588 "Assign the terminal connection password\n"
1589 "The UNENCRYPTED (cleartext) line password\n")
1590{
1591 return CMD_SUCCESS;
1592}
1593
1594DEFUNSH (VTYSH_ALL,
1595 vtysh_config_enable_password,
1596 vtysh_enable_password_cmd,
1597 "enable password (8|) WORD",
1598 "Modify enable password parameters\n"
1599 "Assign the privileged level password\n"
1600 "Specifies a HIDDEN password will follow\n"
1601 "dummy string \n"
1602 "The HIDDEN 'enable' password string\n")
1603{
1604 return CMD_SUCCESS;
1605}
1606
1607DEFUNSH (VTYSH_ALL,
1608 vtysh_enable_password_text,
1609 vtysh_enable_password_text_cmd,
1610 "enable password LINE",
1611 "Modify enable password parameters\n"
1612 "Assign the privileged level password\n"
1613 "The UNENCRYPTED (cleartext) 'enable' password\n")
1614{
1615 return CMD_SUCCESS;
1616}
1617
1618DEFUNSH (VTYSH_ALL,
1619 no_vtysh_config_enable_password,
1620 no_vtysh_enable_password_cmd,
1621 "no enable password",
1622 NO_STR
1623 "Modify enable password parameters\n"
1624 "Assign the privileged level password\n")
1625{
1626 return CMD_SUCCESS;
1627}
1628
paul718e3742002-12-13 20:15:29 +00001629DEFUN (vtysh_write_terminal,
1630 vtysh_write_terminal_cmd,
1631 "write terminal",
1632 "Write running configuration to memory, network, or terminal\n"
1633 "Write to terminal\n")
1634{
ajsb1aa1472005-01-28 21:11:46 +00001635 u_int i;
paul718e3742002-12-13 20:15:29 +00001636 int ret;
1637 char line[] = "write terminal\n";
1638 FILE *fp = NULL;
1639
1640 if (vtysh_pager_name)
1641 {
paul4fc01e62002-12-13 20:49:00 +00001642 fp = popen (vtysh_pager_name, "w");
paul718e3742002-12-13 20:15:29 +00001643 if (fp == NULL)
1644 {
1645 perror ("popen");
1646 exit (1);
1647 }
1648 }
1649 else
1650 fp = stdout;
1651
1652 vty_out (vty, "Building configuration...%s", VTY_NEWLINE);
1653 vty_out (vty, "%sCurrent configuration:%s", VTY_NEWLINE,
1654 VTY_NEWLINE);
hassoe7168df2004-10-03 20:11:32 +00001655 vty_out (vty, "!%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001656
ajsb1aa1472005-01-28 21:11:46 +00001657 for (i = 0; i < VTYSH_INDEX_MAX; i++)
1658 ret = vtysh_client_config (&vtysh_client[i], line);
paul718e3742002-12-13 20:15:29 +00001659
hassoe7168df2004-10-03 20:11:32 +00001660 /* Integrate vtysh specific configuration. */
1661 vtysh_config_write ();
1662
paul718e3742002-12-13 20:15:29 +00001663 vtysh_config_dump (fp);
1664
1665 if (vtysh_pager_name && fp)
1666 {
1667 fflush (fp);
1668 if (pclose (fp) == -1)
1669 {
1670 perror ("pclose");
1671 exit (1);
1672 }
1673 fp = NULL;
1674 }
1675
1676 return CMD_SUCCESS;
1677}
1678
hassoe7168df2004-10-03 20:11:32 +00001679DEFUN (vtysh_integrated_config,
1680 vtysh_integrated_config_cmd,
1681 "service integrated-vtysh-config",
1682 "Set up miscellaneous service\n"
1683 "Write configuration into integrated file\n")
paul4fc01e62002-12-13 20:49:00 +00001684{
hassoe7168df2004-10-03 20:11:32 +00001685 vtysh_writeconfig_integrated = 1;
1686 return CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001687}
1688
hassoe7168df2004-10-03 20:11:32 +00001689DEFUN (no_vtysh_integrated_config,
1690 no_vtysh_integrated_config_cmd,
1691 "no service integrated-vtysh-config",
1692 NO_STR
1693 "Set up miscellaneous service\n"
1694 "Write configuration into integrated file\n")
paul4fc01e62002-12-13 20:49:00 +00001695{
hassoe7168df2004-10-03 20:11:32 +00001696 vtysh_writeconfig_integrated = 0;
1697 return CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001698}
1699
ajs274a4a42004-12-07 15:39:31 +00001700static int
1701write_config_integrated(void)
paul718e3742002-12-13 20:15:29 +00001702{
ajsb1aa1472005-01-28 21:11:46 +00001703 u_int i;
paul718e3742002-12-13 20:15:29 +00001704 int ret;
paul718e3742002-12-13 20:15:29 +00001705 char line[] = "write terminal\n";
1706 FILE *fp;
1707 char *integrate_sav = NULL;
1708
hasso95e735b2004-08-26 13:08:30 +00001709 integrate_sav = malloc (strlen (integrate_default) +
1710 strlen (CONF_BACKUP_EXT) + 1);
paul718e3742002-12-13 20:15:29 +00001711 strcpy (integrate_sav, integrate_default);
1712 strcat (integrate_sav, CONF_BACKUP_EXT);
1713
paul4fc01e62002-12-13 20:49:00 +00001714 fprintf (stdout,"Building Configuration...\n");
paul718e3742002-12-13 20:15:29 +00001715
hasso95e735b2004-08-26 13:08:30 +00001716 /* Move current configuration file to backup config file. */
paul718e3742002-12-13 20:15:29 +00001717 unlink (integrate_sav);
1718 rename (integrate_default, integrate_sav);
hasso95e735b2004-08-26 13:08:30 +00001719 free (integrate_sav);
paul4fc01e62002-12-13 20:49:00 +00001720
paul718e3742002-12-13 20:15:29 +00001721 fp = fopen (integrate_default, "w");
1722 if (fp == NULL)
1723 {
hasso95e735b2004-08-26 13:08:30 +00001724 fprintf (stdout,"%% Can't open configuration file %s.\n",
1725 integrate_default);
paul718e3742002-12-13 20:15:29 +00001726 return CMD_SUCCESS;
1727 }
paul718e3742002-12-13 20:15:29 +00001728
ajsb1aa1472005-01-28 21:11:46 +00001729 for (i = 0; i < VTYSH_INDEX_MAX; i++)
1730 ret = vtysh_client_config (&vtysh_client[i], line);
paul718e3742002-12-13 20:15:29 +00001731
1732 vtysh_config_dump (fp);
1733
1734 fclose (fp);
1735
gdtaa593d52003-12-22 20:15:53 +00001736 if (chmod (integrate_default, CONFIGFILE_MASK) != 0)
1737 {
1738 fprintf (stdout,"%% Can't chmod configuration file %s: %s (%d)\n",
ajs6099b3b2004-11-20 02:06:59 +00001739 integrate_default, safe_strerror(errno), errno);
gdtaa593d52003-12-22 20:15:53 +00001740 return CMD_WARNING;
1741 }
1742
paul4fc01e62002-12-13 20:49:00 +00001743 fprintf(stdout,"Integrated configuration saved to %s\n",integrate_default);
1744
1745 fprintf (stdout,"[OK]\n");
1746
paul718e3742002-12-13 20:15:29 +00001747 return CMD_SUCCESS;
1748}
1749
paul4fc01e62002-12-13 20:49:00 +00001750DEFUN (vtysh_write_memory,
1751 vtysh_write_memory_cmd,
1752 "write memory",
1753 "Write running configuration to memory, network, or terminal\n"
1754 "Write configuration to the file (same as write file)\n")
1755{
pauldfc0d9b2003-04-18 23:55:29 +00001756 int ret = CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001757 char line[] = "write memory\n";
ajsb1aa1472005-01-28 21:11:46 +00001758 u_int i;
paul4fc01e62002-12-13 20:49:00 +00001759
hassoe7168df2004-10-03 20:11:32 +00001760 /* If integrated Quagga.conf explicitely set. */
1761 if (vtysh_writeconfig_integrated)
1762 return write_config_integrated();
paul4fc01e62002-12-13 20:49:00 +00001763
1764 fprintf (stdout,"Building Configuration...\n");
1765
ajsb1aa1472005-01-28 21:11:46 +00001766 for (i = 0; i < VTYSH_INDEX_MAX; i++)
1767 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
hassoe7168df2004-10-03 20:11:32 +00001768
paul4fc01e62002-12-13 20:49:00 +00001769 fprintf (stdout,"[OK]\n");
1770
pauldfc0d9b2003-04-18 23:55:29 +00001771 return ret;
paul4fc01e62002-12-13 20:49:00 +00001772}
1773
paul718e3742002-12-13 20:15:29 +00001774ALIAS (vtysh_write_memory,
1775 vtysh_copy_runningconfig_startupconfig_cmd,
1776 "copy running-config startup-config",
1777 "Copy from one file to another\n"
1778 "Copy from current system configuration\n"
1779 "Copy to startup configuration\n")
1780
1781ALIAS (vtysh_write_memory,
1782 vtysh_write_file_cmd,
1783 "write file",
1784 "Write running configuration to memory, network, or terminal\n"
1785 "Write configuration to the file (same as write memory)\n")
1786
hasso4a6e2252003-05-25 11:51:29 +00001787ALIAS (vtysh_write_memory,
1788 vtysh_write_cmd,
1789 "write",
1790 "Write running configuration to memory, network, or terminal\n")
1791
paul718e3742002-12-13 20:15:29 +00001792ALIAS (vtysh_write_terminal,
1793 vtysh_show_running_config_cmd,
1794 "show running-config",
1795 SHOW_STR
1796 "Current operating configuration\n")
hassob094d262004-08-25 12:22:00 +00001797
hasso34553cc2004-08-27 13:56:39 +00001798DEFUN (vtysh_terminal_length,
1799 vtysh_terminal_length_cmd,
1800 "terminal length <0-512>",
1801 "Set terminal line parameters\n"
1802 "Set number of lines on a screen\n"
1803 "Number of lines on screen (0 for no pausing)\n")
1804{
1805 int lines;
1806 char *endptr = NULL;
1807 char default_pager[10];
1808
1809 lines = strtol (argv[0], &endptr, 10);
1810 if (lines < 0 || lines > 512 || *endptr != '\0')
1811 {
1812 vty_out (vty, "length is malformed%s", VTY_NEWLINE);
1813 return CMD_WARNING;
1814 }
1815
1816 if (vtysh_pager_name)
1817 {
1818 free (vtysh_pager_name);
1819 vtysh_pager_name = NULL;
1820 }
1821
1822 if (lines != 0)
1823 {
1824 snprintf(default_pager, 10, "more -%i", lines);
1825 vtysh_pager_name = strdup (default_pager);
1826 }
1827
1828 return CMD_SUCCESS;
1829}
1830
1831DEFUN (vtysh_terminal_no_length,
1832 vtysh_terminal_no_length_cmd,
1833 "terminal no length",
1834 "Set terminal line parameters\n"
1835 NO_STR
1836 "Set number of lines on a screen\n")
1837{
1838 if (vtysh_pager_name)
1839 {
1840 free (vtysh_pager_name);
1841 vtysh_pager_name = NULL;
1842 }
1843
1844 vtysh_pager_init();
1845 return CMD_SUCCESS;
1846}
1847
hassof2799e62004-10-28 17:43:11 +00001848DEFUN (vtysh_show_daemons,
1849 vtysh_show_daemons_cmd,
1850 "show daemons",
hassoe7168df2004-10-03 20:11:32 +00001851 SHOW_STR
1852 "Show list of running daemons\n")
1853{
ajsb1aa1472005-01-28 21:11:46 +00001854 u_int i;
1855
1856 for (i = 0; i < VTYSH_INDEX_MAX; i++)
1857 if ( vtysh_client[i].fd >= 0 )
1858 vty_out(vty, " %s", vtysh_client[i].name);
hassoe7168df2004-10-03 20:11:32 +00001859 vty_out(vty, "%s", VTY_NEWLINE);
1860
1861 return CMD_SUCCESS;
1862}
1863
paul718e3742002-12-13 20:15:29 +00001864/* Execute command in child process. */
ajs274a4a42004-12-07 15:39:31 +00001865static int
hasso5862ff52004-10-11 13:20:40 +00001866execute_command (const char *command, int argc, const char *arg1,
1867 const char *arg2)
paul718e3742002-12-13 20:15:29 +00001868{
1869 int ret;
1870 pid_t pid;
1871 int status;
1872
1873 /* Call fork(). */
1874 pid = fork ();
1875
1876 if (pid < 0)
1877 {
1878 /* Failure of fork(). */
ajs6099b3b2004-11-20 02:06:59 +00001879 fprintf (stderr, "Can't fork: %s\n", safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +00001880 exit (1);
1881 }
1882 else if (pid == 0)
1883 {
1884 /* This is child process. */
1885 switch (argc)
1886 {
1887 case 0:
hassofa2b17e2004-03-04 17:45:00 +00001888 ret = execlp (command, command, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00001889 break;
1890 case 1:
hassofa2b17e2004-03-04 17:45:00 +00001891 ret = execlp (command, command, arg1, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00001892 break;
1893 case 2:
hassofa2b17e2004-03-04 17:45:00 +00001894 ret = execlp (command, command, arg1, arg2, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00001895 break;
1896 }
1897
1898 /* When execlp suceed, this part is not executed. */
ajs6099b3b2004-11-20 02:06:59 +00001899 fprintf (stderr, "Can't execute %s: %s\n", command, safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +00001900 exit (1);
1901 }
1902 else
1903 {
1904 /* This is parent. */
1905 execute_flag = 1;
1906 ret = wait4 (pid, &status, 0, NULL);
1907 execute_flag = 0;
1908 }
1909 return 0;
1910}
1911
1912DEFUN (vtysh_ping,
1913 vtysh_ping_cmd,
1914 "ping WORD",
hasso4eeccf12003-06-25 10:49:55 +00001915 "Send echo messages\n"
paul718e3742002-12-13 20:15:29 +00001916 "Ping destination address or hostname\n")
1917{
1918 execute_command ("ping", 1, argv[0], NULL);
1919 return CMD_SUCCESS;
1920}
1921
hasso4eeccf12003-06-25 10:49:55 +00001922ALIAS (vtysh_ping,
1923 vtysh_ping_ip_cmd,
1924 "ping ip WORD",
1925 "Send echo messages\n"
1926 "IP echo\n"
1927 "Ping destination address or hostname\n")
1928
paul718e3742002-12-13 20:15:29 +00001929DEFUN (vtysh_traceroute,
1930 vtysh_traceroute_cmd,
1931 "traceroute WORD",
1932 "Trace route to destination\n"
1933 "Trace route to destination address or hostname\n")
1934{
1935 execute_command ("traceroute", 1, argv[0], NULL);
1936 return CMD_SUCCESS;
1937}
1938
hasso4eeccf12003-06-25 10:49:55 +00001939ALIAS (vtysh_traceroute,
1940 vtysh_traceroute_ip_cmd,
1941 "traceroute ip WORD",
1942 "Trace route to destination\n"
1943 "IP trace\n"
1944 "Trace route to destination address or hostname\n")
1945
1946#ifdef HAVE_IPV6
1947DEFUN (vtysh_ping6,
1948 vtysh_ping6_cmd,
1949 "ping ipv6 WORD",
1950 "Send echo messages\n"
1951 "IPv6 echo\n"
1952 "Ping destination address or hostname\n")
1953{
1954 execute_command ("ping6", 1, argv[0], NULL);
1955 return CMD_SUCCESS;
1956}
1957
1958DEFUN (vtysh_traceroute6,
1959 vtysh_traceroute6_cmd,
1960 "traceroute ipv6 WORD",
1961 "Trace route to destination\n"
1962 "IPv6 trace\n"
1963 "Trace route to destination address or hostname\n")
1964{
1965 execute_command ("traceroute6", 1, argv[0], NULL);
1966 return CMD_SUCCESS;
1967}
1968#endif
1969
paul718e3742002-12-13 20:15:29 +00001970DEFUN (vtysh_telnet,
1971 vtysh_telnet_cmd,
1972 "telnet WORD",
1973 "Open a telnet connection\n"
1974 "IP address or hostname of a remote system\n")
1975{
1976 execute_command ("telnet", 1, argv[0], NULL);
1977 return CMD_SUCCESS;
1978}
1979
1980DEFUN (vtysh_telnet_port,
1981 vtysh_telnet_port_cmd,
1982 "telnet WORD PORT",
1983 "Open a telnet connection\n"
1984 "IP address or hostname of a remote system\n"
1985 "TCP Port number\n")
1986{
1987 execute_command ("telnet", 2, argv[0], argv[1]);
1988 return CMD_SUCCESS;
1989}
1990
paul5087df52003-01-25 06:56:09 +00001991DEFUN (vtysh_ssh,
1992 vtysh_ssh_cmd,
1993 "ssh WORD",
1994 "Open an ssh connection\n"
1995 "[user@]host\n")
1996{
1997 execute_command ("ssh", 1, argv[0], NULL);
1998 return CMD_SUCCESS;
1999}
2000
paul718e3742002-12-13 20:15:29 +00002001DEFUN (vtysh_start_shell,
2002 vtysh_start_shell_cmd,
2003 "start-shell",
2004 "Start UNIX shell\n")
2005{
2006 execute_command ("sh", 0, NULL, NULL);
2007 return CMD_SUCCESS;
2008}
2009
2010DEFUN (vtysh_start_bash,
2011 vtysh_start_bash_cmd,
2012 "start-shell bash",
2013 "Start UNIX shell\n"
2014 "Start bash\n")
2015{
2016 execute_command ("bash", 0, NULL, NULL);
2017 return CMD_SUCCESS;
2018}
2019
2020DEFUN (vtysh_start_zsh,
2021 vtysh_start_zsh_cmd,
2022 "start-shell zsh",
2023 "Start UNIX shell\n"
2024 "Start Z shell\n")
2025{
2026 execute_command ("zsh", 0, NULL, NULL);
2027 return CMD_SUCCESS;
2028}
hassob094d262004-08-25 12:22:00 +00002029
ajs274a4a42004-12-07 15:39:31 +00002030static void
paul718e3742002-12-13 20:15:29 +00002031vtysh_install_default (enum node_type node)
2032{
2033 install_element (node, &config_list_cmd);
2034}
2035
2036/* Making connection to protocol daemon. */
ajs274a4a42004-12-07 15:39:31 +00002037static int
ajsb1aa1472005-01-28 21:11:46 +00002038vtysh_connect (struct vtysh_client *vclient)
paul718e3742002-12-13 20:15:29 +00002039{
2040 int ret;
2041 int sock, len;
2042 struct sockaddr_un addr;
2043 struct stat s_stat;
paul718e3742002-12-13 20:15:29 +00002044
paul718e3742002-12-13 20:15:29 +00002045 /* Stat socket to see if we have permission to access it. */
ajsb1aa1472005-01-28 21:11:46 +00002046 ret = stat (vclient->path, &s_stat);
paul718e3742002-12-13 20:15:29 +00002047 if (ret < 0 && errno != ENOENT)
2048 {
2049 fprintf (stderr, "vtysh_connect(%s): stat = %s\n",
ajsb1aa1472005-01-28 21:11:46 +00002050 vclient->path, safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002051 exit(1);
2052 }
2053
2054 if (ret >= 0)
2055 {
2056 if (! S_ISSOCK(s_stat.st_mode))
2057 {
2058 fprintf (stderr, "vtysh_connect(%s): Not a socket\n",
ajsb1aa1472005-01-28 21:11:46 +00002059 vclient->path);
paul718e3742002-12-13 20:15:29 +00002060 exit (1);
2061 }
2062
paul718e3742002-12-13 20:15:29 +00002063 }
2064
2065 sock = socket (AF_UNIX, SOCK_STREAM, 0);
2066 if (sock < 0)
2067 {
2068#ifdef DEBUG
ajsb1aa1472005-01-28 21:11:46 +00002069 fprintf(stderr, "vtysh_connect(%s): socket = %s\n", vclient->path,
ajs6099b3b2004-11-20 02:06:59 +00002070 safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002071#endif /* DEBUG */
2072 return -1;
2073 }
2074
2075 memset (&addr, 0, sizeof (struct sockaddr_un));
2076 addr.sun_family = AF_UNIX;
ajsb1aa1472005-01-28 21:11:46 +00002077 strncpy (addr.sun_path, vclient->path, strlen (vclient->path));
paul718e3742002-12-13 20:15:29 +00002078#ifdef HAVE_SUN_LEN
2079 len = addr.sun_len = SUN_LEN(&addr);
2080#else
2081 len = sizeof (addr.sun_family) + strlen (addr.sun_path);
2082#endif /* HAVE_SUN_LEN */
2083
2084 ret = connect (sock, (struct sockaddr *) &addr, len);
2085 if (ret < 0)
2086 {
2087#ifdef DEBUG
ajsb1aa1472005-01-28 21:11:46 +00002088 fprintf(stderr, "vtysh_connect(%s): connect = %s\n", vclient->path,
ajs6099b3b2004-11-20 02:06:59 +00002089 safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002090#endif /* DEBUG */
2091 close (sock);
2092 return -1;
2093 }
2094 vclient->fd = sock;
2095
2096 return 0;
2097}
2098
2099void
ajsb1aa1472005-01-28 21:11:46 +00002100vtysh_connect_all(void)
paul718e3742002-12-13 20:15:29 +00002101{
ajsb1aa1472005-01-28 21:11:46 +00002102 u_int i;
2103
2104 for (i = 0; i < VTYSH_INDEX_MAX; i++)
2105 {
2106 vtysh_connect(&vtysh_client[i]);
2107 /* We need direct access to ripd in vtysh_exit_ripd_only. */
2108 if (vtysh_client[i].flag == VTYSH_RIPD)
2109 ripd_client = &vtysh_client[i];
2110 }
paul718e3742002-12-13 20:15:29 +00002111}
2112
hasso95e735b2004-08-26 13:08:30 +00002113/* To disable readline's filename completion. */
ajs274a4a42004-12-07 15:39:31 +00002114static char *
pauldfc0d9b2003-04-18 23:55:29 +00002115vtysh_completion_entry_function (const char *ignore, int invoking_key)
paul718e3742002-12-13 20:15:29 +00002116{
pauldfc0d9b2003-04-18 23:55:29 +00002117 return NULL;
paul718e3742002-12-13 20:15:29 +00002118}
2119
2120void
ajsb1aa1472005-01-28 21:11:46 +00002121vtysh_readline_init (void)
paul718e3742002-12-13 20:15:29 +00002122{
2123 /* readline related settings. */
hasso53a6f932005-09-15 06:50:53 +00002124 rl_bind_key ('?', (Function *) vtysh_rl_describe);
paul68980082003-03-25 05:07:42 +00002125 rl_completion_entry_function = vtysh_completion_entry_function;
paul718e3742002-12-13 20:15:29 +00002126 rl_attempted_completion_function = (CPPFunction *)new_completion;
2127 /* do not append space after completion. It will be appended
hasso95e735b2004-08-26 13:08:30 +00002128 * in new_completion() function explicitly. */
paul718e3742002-12-13 20:15:29 +00002129 rl_completion_append_character = '\0';
2130}
2131
2132char *
ajsb1aa1472005-01-28 21:11:46 +00002133vtysh_prompt (void)
paul718e3742002-12-13 20:15:29 +00002134{
2135 struct utsname names;
2136 static char buf[100];
2137 const char*hostname;
2138 extern struct host host;
2139
2140 hostname = host.name;
2141
2142 if (!hostname)
2143 {
2144 uname (&names);
2145 hostname = names.nodename;
2146 }
2147
2148 snprintf (buf, sizeof buf, cmd_prompt (vty->node), hostname);
2149
2150 return buf;
2151}
2152
2153void
ajsb1aa1472005-01-28 21:11:46 +00002154vtysh_init_vty (void)
paul718e3742002-12-13 20:15:29 +00002155{
2156 /* Make vty structure. */
2157 vty = vty_new ();
2158 vty->type = VTY_SHELL;
2159 vty->node = VIEW_NODE;
2160
2161 /* Initialize commands. */
2162 cmd_init (0);
2163
2164 /* Install nodes. */
2165 install_node (&bgp_node, NULL);
2166 install_node (&rip_node, NULL);
2167 install_node (&interface_node, NULL);
2168 install_node (&rmap_node, NULL);
2169 install_node (&zebra_node, NULL);
2170 install_node (&bgp_vpnv4_node, NULL);
2171 install_node (&bgp_ipv4_node, NULL);
2172 install_node (&bgp_ipv4m_node, NULL);
2173/* #ifdef HAVE_IPV6 */
2174 install_node (&bgp_ipv6_node, NULL);
paul57b5b7e2005-08-22 22:44:29 +00002175 install_node (&bgp_ipv6m_node, NULL);
paul718e3742002-12-13 20:15:29 +00002176/* #endif */
2177 install_node (&ospf_node, NULL);
2178/* #ifdef HAVE_IPV6 */
2179 install_node (&ripng_node, NULL);
2180 install_node (&ospf6_node, NULL);
2181/* #endif */
2182 install_node (&keychain_node, NULL);
2183 install_node (&keychain_key_node, NULL);
hassoc25e4582003-12-23 10:39:08 +00002184 install_node (&isis_node, NULL);
hassoe7168df2004-10-03 20:11:32 +00002185 install_node (&vty_node, NULL);
paul718e3742002-12-13 20:15:29 +00002186
2187 vtysh_install_default (VIEW_NODE);
2188 vtysh_install_default (ENABLE_NODE);
2189 vtysh_install_default (CONFIG_NODE);
2190 vtysh_install_default (BGP_NODE);
2191 vtysh_install_default (RIP_NODE);
2192 vtysh_install_default (INTERFACE_NODE);
2193 vtysh_install_default (RMAP_NODE);
2194 vtysh_install_default (ZEBRA_NODE);
2195 vtysh_install_default (BGP_VPNV4_NODE);
2196 vtysh_install_default (BGP_IPV4_NODE);
2197 vtysh_install_default (BGP_IPV4M_NODE);
2198 vtysh_install_default (BGP_IPV6_NODE);
paul57b5b7e2005-08-22 22:44:29 +00002199 vtysh_install_default (BGP_IPV6M_NODE);
paul718e3742002-12-13 20:15:29 +00002200 vtysh_install_default (OSPF_NODE);
2201 vtysh_install_default (RIPNG_NODE);
2202 vtysh_install_default (OSPF6_NODE);
hassoc25e4582003-12-23 10:39:08 +00002203 vtysh_install_default (ISIS_NODE);
paul718e3742002-12-13 20:15:29 +00002204 vtysh_install_default (KEYCHAIN_NODE);
2205 vtysh_install_default (KEYCHAIN_KEY_NODE);
hassoe7168df2004-10-03 20:11:32 +00002206 vtysh_install_default (VTY_NODE);
paul718e3742002-12-13 20:15:29 +00002207
2208 install_element (VIEW_NODE, &vtysh_enable_cmd);
2209 install_element (ENABLE_NODE, &vtysh_config_terminal_cmd);
2210 install_element (ENABLE_NODE, &vtysh_disable_cmd);
2211
2212 /* "exit" command. */
2213 install_element (VIEW_NODE, &vtysh_exit_all_cmd);
2214 install_element (VIEW_NODE, &vtysh_quit_all_cmd);
2215 install_element (CONFIG_NODE, &vtysh_exit_all_cmd);
2216 /* install_element (CONFIG_NODE, &vtysh_quit_all_cmd); */
2217 install_element (ENABLE_NODE, &vtysh_exit_all_cmd);
2218 install_element (ENABLE_NODE, &vtysh_quit_all_cmd);
2219 install_element (RIP_NODE, &vtysh_exit_ripd_cmd);
2220 install_element (RIP_NODE, &vtysh_quit_ripd_cmd);
paul68980082003-03-25 05:07:42 +00002221 install_element (RIPNG_NODE, &vtysh_exit_ripngd_cmd);
2222 install_element (RIPNG_NODE, &vtysh_quit_ripngd_cmd);
paul718e3742002-12-13 20:15:29 +00002223 install_element (OSPF_NODE, &vtysh_exit_ospfd_cmd);
2224 install_element (OSPF_NODE, &vtysh_quit_ospfd_cmd);
paul68980082003-03-25 05:07:42 +00002225 install_element (OSPF6_NODE, &vtysh_exit_ospf6d_cmd);
2226 install_element (OSPF6_NODE, &vtysh_quit_ospf6d_cmd);
paul718e3742002-12-13 20:15:29 +00002227 install_element (BGP_NODE, &vtysh_exit_bgpd_cmd);
2228 install_element (BGP_NODE, &vtysh_quit_bgpd_cmd);
2229 install_element (BGP_VPNV4_NODE, &vtysh_exit_bgpd_cmd);
2230 install_element (BGP_VPNV4_NODE, &vtysh_quit_bgpd_cmd);
2231 install_element (BGP_IPV4_NODE, &vtysh_exit_bgpd_cmd);
2232 install_element (BGP_IPV4_NODE, &vtysh_quit_bgpd_cmd);
2233 install_element (BGP_IPV4M_NODE, &vtysh_exit_bgpd_cmd);
2234 install_element (BGP_IPV4M_NODE, &vtysh_quit_bgpd_cmd);
2235 install_element (BGP_IPV6_NODE, &vtysh_exit_bgpd_cmd);
2236 install_element (BGP_IPV6_NODE, &vtysh_quit_bgpd_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002237 install_element (BGP_IPV6M_NODE, &vtysh_exit_bgpd_cmd);
2238 install_element (BGP_IPV6M_NODE, &vtysh_quit_bgpd_cmd);
hassoc25e4582003-12-23 10:39:08 +00002239 install_element (ISIS_NODE, &vtysh_exit_isisd_cmd);
2240 install_element (ISIS_NODE, &vtysh_quit_isisd_cmd);
paul718e3742002-12-13 20:15:29 +00002241 install_element (KEYCHAIN_NODE, &vtysh_exit_ripd_cmd);
2242 install_element (KEYCHAIN_NODE, &vtysh_quit_ripd_cmd);
2243 install_element (KEYCHAIN_KEY_NODE, &vtysh_exit_ripd_cmd);
2244 install_element (KEYCHAIN_KEY_NODE, &vtysh_quit_ripd_cmd);
2245 install_element (RMAP_NODE, &vtysh_exit_rmap_cmd);
2246 install_element (RMAP_NODE, &vtysh_quit_rmap_cmd);
hassoe7168df2004-10-03 20:11:32 +00002247 install_element (VTY_NODE, &vtysh_exit_line_vty_cmd);
2248 install_element (VTY_NODE, &vtysh_quit_line_vty_cmd);
paul718e3742002-12-13 20:15:29 +00002249
2250 /* "end" command. */
2251 install_element (CONFIG_NODE, &vtysh_end_all_cmd);
2252 install_element (ENABLE_NODE, &vtysh_end_all_cmd);
2253 install_element (RIP_NODE, &vtysh_end_all_cmd);
2254 install_element (RIPNG_NODE, &vtysh_end_all_cmd);
2255 install_element (OSPF_NODE, &vtysh_end_all_cmd);
2256 install_element (OSPF6_NODE, &vtysh_end_all_cmd);
2257 install_element (BGP_NODE, &vtysh_end_all_cmd);
2258 install_element (BGP_IPV4_NODE, &vtysh_end_all_cmd);
2259 install_element (BGP_IPV4M_NODE, &vtysh_end_all_cmd);
2260 install_element (BGP_VPNV4_NODE, &vtysh_end_all_cmd);
2261 install_element (BGP_IPV6_NODE, &vtysh_end_all_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002262 install_element (BGP_IPV6M_NODE, &vtysh_end_all_cmd);
hassoc25e4582003-12-23 10:39:08 +00002263 install_element (ISIS_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002264 install_element (KEYCHAIN_NODE, &vtysh_end_all_cmd);
2265 install_element (KEYCHAIN_KEY_NODE, &vtysh_end_all_cmd);
2266 install_element (RMAP_NODE, &vtysh_end_all_cmd);
hassoe7168df2004-10-03 20:11:32 +00002267 install_element (VTY_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002268
paul338a9912003-03-01 15:44:10 +00002269 install_element (INTERFACE_NODE, &interface_desc_cmd);
paul464dc8d2003-03-28 02:25:45 +00002270 install_element (INTERFACE_NODE, &no_interface_desc_cmd);
paul718e3742002-12-13 20:15:29 +00002271 install_element (INTERFACE_NODE, &vtysh_end_all_cmd);
2272 install_element (INTERFACE_NODE, &vtysh_exit_interface_cmd);
2273 install_element (INTERFACE_NODE, &vtysh_quit_interface_cmd);
2274 install_element (CONFIG_NODE, &router_rip_cmd);
2275#ifdef HAVE_IPV6
2276 install_element (CONFIG_NODE, &router_ripng_cmd);
2277#endif
2278 install_element (CONFIG_NODE, &router_ospf_cmd);
2279#ifdef HAVE_IPV6
2280 install_element (CONFIG_NODE, &router_ospf6_cmd);
2281#endif
hassoc25e4582003-12-23 10:39:08 +00002282 install_element (CONFIG_NODE, &router_isis_cmd);
paul718e3742002-12-13 20:15:29 +00002283 install_element (CONFIG_NODE, &router_bgp_cmd);
2284 install_element (BGP_NODE, &address_family_vpnv4_cmd);
2285 install_element (BGP_NODE, &address_family_vpnv4_unicast_cmd);
2286 install_element (BGP_NODE, &address_family_ipv4_unicast_cmd);
2287 install_element (BGP_NODE, &address_family_ipv4_multicast_cmd);
2288#ifdef HAVE_IPV6
2289 install_element (BGP_NODE, &address_family_ipv6_cmd);
2290 install_element (BGP_NODE, &address_family_ipv6_unicast_cmd);
2291#endif
2292 install_element (BGP_VPNV4_NODE, &exit_address_family_cmd);
2293 install_element (BGP_IPV4_NODE, &exit_address_family_cmd);
2294 install_element (BGP_IPV4M_NODE, &exit_address_family_cmd);
2295 install_element (BGP_IPV6_NODE, &exit_address_family_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002296 install_element (BGP_IPV6M_NODE, &exit_address_family_cmd);
paul718e3742002-12-13 20:15:29 +00002297 install_element (CONFIG_NODE, &key_chain_cmd);
2298 install_element (CONFIG_NODE, &route_map_cmd);
hassoe7168df2004-10-03 20:11:32 +00002299 install_element (CONFIG_NODE, &vtysh_line_vty_cmd);
paul718e3742002-12-13 20:15:29 +00002300 install_element (KEYCHAIN_NODE, &key_cmd);
2301 install_element (KEYCHAIN_NODE, &key_chain_cmd);
2302 install_element (KEYCHAIN_KEY_NODE, &key_chain_cmd);
2303 install_element (CONFIG_NODE, &vtysh_interface_cmd);
paul32d24632003-05-23 09:25:20 +00002304 install_element (CONFIG_NODE, &vtysh_no_interface_cmd);
paul718e3742002-12-13 20:15:29 +00002305 install_element (ENABLE_NODE, &vtysh_show_running_config_cmd);
2306 install_element (ENABLE_NODE, &vtysh_copy_runningconfig_startupconfig_cmd);
2307 install_element (ENABLE_NODE, &vtysh_write_file_cmd);
hasso4a6e2252003-05-25 11:51:29 +00002308 install_element (ENABLE_NODE, &vtysh_write_cmd);
paul718e3742002-12-13 20:15:29 +00002309
hasso95e735b2004-08-26 13:08:30 +00002310 /* "write terminal" command. */
paul718e3742002-12-13 20:15:29 +00002311 install_element (ENABLE_NODE, &vtysh_write_terminal_cmd);
hassoe7168df2004-10-03 20:11:32 +00002312
2313 install_element (CONFIG_NODE, &vtysh_integrated_config_cmd);
2314 install_element (CONFIG_NODE, &no_vtysh_integrated_config_cmd);
paul718e3742002-12-13 20:15:29 +00002315
hasso95e735b2004-08-26 13:08:30 +00002316 /* "write memory" command. */
paul718e3742002-12-13 20:15:29 +00002317 install_element (ENABLE_NODE, &vtysh_write_memory_cmd);
paul718e3742002-12-13 20:15:29 +00002318
hasso34553cc2004-08-27 13:56:39 +00002319 install_element (VIEW_NODE, &vtysh_terminal_length_cmd);
2320 install_element (ENABLE_NODE, &vtysh_terminal_length_cmd);
2321 install_element (VIEW_NODE, &vtysh_terminal_no_length_cmd);
2322 install_element (ENABLE_NODE, &vtysh_terminal_no_length_cmd);
hassof2799e62004-10-28 17:43:11 +00002323 install_element (VIEW_NODE, &vtysh_show_daemons_cmd);
2324 install_element (ENABLE_NODE, &vtysh_show_daemons_cmd);
hasso34553cc2004-08-27 13:56:39 +00002325
paul718e3742002-12-13 20:15:29 +00002326 install_element (VIEW_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002327 install_element (VIEW_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00002328 install_element (VIEW_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002329 install_element (VIEW_NODE, &vtysh_traceroute_ip_cmd);
2330#ifdef HAVE_IPV6
2331 install_element (VIEW_NODE, &vtysh_ping6_cmd);
2332 install_element (VIEW_NODE, &vtysh_traceroute6_cmd);
2333#endif
paul718e3742002-12-13 20:15:29 +00002334 install_element (VIEW_NODE, &vtysh_telnet_cmd);
2335 install_element (VIEW_NODE, &vtysh_telnet_port_cmd);
paul5087df52003-01-25 06:56:09 +00002336 install_element (VIEW_NODE, &vtysh_ssh_cmd);
paul718e3742002-12-13 20:15:29 +00002337 install_element (ENABLE_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002338 install_element (ENABLE_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00002339 install_element (ENABLE_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002340 install_element (ENABLE_NODE, &vtysh_traceroute_ip_cmd);
2341#ifdef HAVE_IPV6
2342 install_element (ENABLE_NODE, &vtysh_ping6_cmd);
2343 install_element (ENABLE_NODE, &vtysh_traceroute6_cmd);
2344#endif
paul718e3742002-12-13 20:15:29 +00002345 install_element (ENABLE_NODE, &vtysh_telnet_cmd);
2346 install_element (ENABLE_NODE, &vtysh_telnet_port_cmd);
hasso67e29ab2004-08-26 22:21:31 +00002347 install_element (ENABLE_NODE, &vtysh_ssh_cmd);
paul718e3742002-12-13 20:15:29 +00002348 install_element (ENABLE_NODE, &vtysh_start_shell_cmd);
2349 install_element (ENABLE_NODE, &vtysh_start_bash_cmd);
2350 install_element (ENABLE_NODE, &vtysh_start_zsh_cmd);
Paul Jakmadbf7d132006-05-23 22:10:01 +00002351
2352 /* Logging */
2353 install_element (ENABLE_NODE, &vtysh_show_logging_cmd);
2354 install_element (VIEW_NODE, &vtysh_show_logging_cmd);
paul718e3742002-12-13 20:15:29 +00002355 install_element (CONFIG_NODE, &vtysh_log_stdout_cmd);
ajs274a4a42004-12-07 15:39:31 +00002356 install_element (CONFIG_NODE, &vtysh_log_stdout_level_cmd);
paul718e3742002-12-13 20:15:29 +00002357 install_element (CONFIG_NODE, &no_vtysh_log_stdout_cmd);
2358 install_element (CONFIG_NODE, &vtysh_log_file_cmd);
ajs274a4a42004-12-07 15:39:31 +00002359 install_element (CONFIG_NODE, &vtysh_log_file_level_cmd);
paul718e3742002-12-13 20:15:29 +00002360 install_element (CONFIG_NODE, &no_vtysh_log_file_cmd);
ajs274a4a42004-12-07 15:39:31 +00002361 install_element (CONFIG_NODE, &no_vtysh_log_file_level_cmd);
2362 install_element (CONFIG_NODE, &vtysh_log_monitor_cmd);
2363 install_element (CONFIG_NODE, &vtysh_log_monitor_level_cmd);
2364 install_element (CONFIG_NODE, &no_vtysh_log_monitor_cmd);
paul718e3742002-12-13 20:15:29 +00002365 install_element (CONFIG_NODE, &vtysh_log_syslog_cmd);
ajs274a4a42004-12-07 15:39:31 +00002366 install_element (CONFIG_NODE, &vtysh_log_syslog_level_cmd);
paul718e3742002-12-13 20:15:29 +00002367 install_element (CONFIG_NODE, &no_vtysh_log_syslog_cmd);
2368 install_element (CONFIG_NODE, &vtysh_log_trap_cmd);
2369 install_element (CONFIG_NODE, &no_vtysh_log_trap_cmd);
ajs274a4a42004-12-07 15:39:31 +00002370 install_element (CONFIG_NODE, &vtysh_log_facility_cmd);
2371 install_element (CONFIG_NODE, &no_vtysh_log_facility_cmd);
paul718e3742002-12-13 20:15:29 +00002372 install_element (CONFIG_NODE, &vtysh_log_record_priority_cmd);
2373 install_element (CONFIG_NODE, &no_vtysh_log_record_priority_cmd);
hassoe7168df2004-10-03 20:11:32 +00002374
2375 install_element (CONFIG_NODE, &vtysh_service_password_encrypt_cmd);
2376 install_element (CONFIG_NODE, &no_vtysh_service_password_encrypt_cmd);
2377
2378 install_element (CONFIG_NODE, &vtysh_password_cmd);
2379 install_element (CONFIG_NODE, &vtysh_password_text_cmd);
2380 install_element (CONFIG_NODE, &vtysh_enable_password_cmd);
2381 install_element (CONFIG_NODE, &vtysh_enable_password_text_cmd);
2382 install_element (CONFIG_NODE, &no_vtysh_enable_password_cmd);
2383
paul718e3742002-12-13 20:15:29 +00002384}