blob: 20f7df445fd9ce1fdc984cbb33abe31380bd8c59 [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. */
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700275static int
hassodda09522004-10-07 21:40:25 +0000276vtysh_execute_func (const char *line, int pager)
paul718e3742002-12-13 20:15:29 +0000277{
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700278 int ret, cmd_stat = CMD_SUCCESS;
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)
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700291 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000292
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 }
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700397 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000398 }
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 }
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700438 return cmd_stat;
paul718e3742002-12-13 20:15:29 +0000439}
440
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700441int
hassodda09522004-10-07 21:40:25 +0000442vtysh_execute_no_pager (const char *line)
paul718e3742002-12-13 20:15:29 +0000443{
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700444 return vtysh_execute_func (line, 0);
paul718e3742002-12-13 20:15:29 +0000445}
446
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700447int
hassodda09522004-10-07 21:40:25 +0000448vtysh_execute (const char *line)
paul718e3742002-12-13 20:15:29 +0000449{
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700450 return vtysh_execute_func (line, 1);
paul718e3742002-12-13 20:15:29 +0000451}
452
453/* Configration make from file. */
454int
455vtysh_config_from_file (struct vty *vty, FILE *fp)
456{
457 int ret;
458 vector vline;
459 struct cmd_element *cmd;
460
461 while (fgets (vty->buf, VTY_BUFSIZ, fp))
462 {
463 if (vty->buf[0] == '!' || vty->buf[1] == '#')
464 continue;
465
466 vline = cmd_make_strvec (vty->buf);
467
hasso95e735b2004-08-26 13:08:30 +0000468 /* In case of comment line. */
paul718e3742002-12-13 20:15:29 +0000469 if (vline == NULL)
470 continue;
471
hasso95e735b2004-08-26 13:08:30 +0000472 /* Execute configuration command : this is strict match. */
paul718e3742002-12-13 20:15:29 +0000473 ret = cmd_execute_command_strict (vline, vty, &cmd);
474
hasso95e735b2004-08-26 13:08:30 +0000475 /* Try again with setting node to CONFIG_NODE. */
paul718e3742002-12-13 20:15:29 +0000476 if (ret != CMD_SUCCESS
477 && ret != CMD_SUCCESS_DAEMON
478 && ret != CMD_WARNING)
479 {
480 if (vty->node == KEYCHAIN_KEY_NODE)
481 {
482 vty->node = KEYCHAIN_NODE;
483 vtysh_exit_ripd_only ();
484 ret = cmd_execute_command_strict (vline, vty, &cmd);
485
486 if (ret != CMD_SUCCESS
487 && ret != CMD_SUCCESS_DAEMON
488 && ret != CMD_WARNING)
489 {
490 vtysh_exit_ripd_only ();
491 vty->node = CONFIG_NODE;
492 ret = cmd_execute_command_strict (vline, vty, &cmd);
493 }
494 }
495 else
496 {
497 vtysh_execute ("end");
498 vtysh_execute ("configure terminal");
499 vty->node = CONFIG_NODE;
500 ret = cmd_execute_command_strict (vline, vty, &cmd);
501 }
502 }
503
504 cmd_free_strvec (vline);
505
506 switch (ret)
507 {
508 case CMD_WARNING:
509 if (vty->type == VTY_FILE)
paul4fc01e62002-12-13 20:49:00 +0000510 fprintf (stdout,"Warning...\n");
paul718e3742002-12-13 20:15:29 +0000511 break;
512 case CMD_ERR_AMBIGUOUS:
paul4fc01e62002-12-13 20:49:00 +0000513 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000514 break;
515 case CMD_ERR_NO_MATCH:
paul4fc01e62002-12-13 20:49:00 +0000516 fprintf (stdout,"%% Unknown command: %s", vty->buf);
paul718e3742002-12-13 20:15:29 +0000517 break;
518 case CMD_ERR_INCOMPLETE:
paul4fc01e62002-12-13 20:49:00 +0000519 fprintf (stdout,"%% Command incomplete.\n");
paul718e3742002-12-13 20:15:29 +0000520 break;
521 case CMD_SUCCESS_DAEMON:
522 {
ajsb1aa1472005-01-28 21:11:46 +0000523 u_int i;
524 int cmd_stat = CMD_SUCCESS;
525
526 for (i = 0; i < VTYSH_INDEX_MAX; i++)
527 {
paul44316fe2006-01-11 01:38:25 +0000528 if (cmd->daemon & vtysh_client[i].flag)
ajsb1aa1472005-01-28 21:11:46 +0000529 {
530 cmd_stat = vtysh_client_execute (&vtysh_client[i],
531 vty->buf, stdout);
532 if (cmd_stat != CMD_SUCCESS)
533 break;
534 }
535 }
536 if (cmd_stat != CMD_SUCCESS)
537 break;
538
paul718e3742002-12-13 20:15:29 +0000539 if (cmd->func)
540 (*cmd->func) (cmd, vty, 0, NULL);
541 }
542 }
543 }
544 return CMD_SUCCESS;
545}
546
547/* We don't care about the point of the cursor when '?' is typed. */
548int
ajsb1aa1472005-01-28 21:11:46 +0000549vtysh_rl_describe (void)
paul718e3742002-12-13 20:15:29 +0000550{
551 int ret;
hassodda09522004-10-07 21:40:25 +0000552 unsigned int i;
paul718e3742002-12-13 20:15:29 +0000553 vector vline;
554 vector describe;
555 int width;
556 struct desc *desc;
557
558 vline = cmd_make_strvec (rl_line_buffer);
559
560 /* In case of '> ?'. */
561 if (vline == NULL)
562 {
563 vline = vector_init (1);
564 vector_set (vline, '\0');
565 }
566 else
567 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
568 vector_set (vline, '\0');
569
570 describe = cmd_describe_command (vline, vty, &ret);
571
paul4fc01e62002-12-13 20:49:00 +0000572 fprintf (stdout,"\n");
paul718e3742002-12-13 20:15:29 +0000573
574 /* Ambiguous and no match error. */
575 switch (ret)
576 {
577 case CMD_ERR_AMBIGUOUS:
578 cmd_free_strvec (vline);
paul4fc01e62002-12-13 20:49:00 +0000579 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000580 rl_on_new_line ();
581 return 0;
582 break;
583 case CMD_ERR_NO_MATCH:
584 cmd_free_strvec (vline);
paul4fc01e62002-12-13 20:49:00 +0000585 fprintf (stdout,"%% There is no matched command.\n");
paul718e3742002-12-13 20:15:29 +0000586 rl_on_new_line ();
587 return 0;
588 break;
589 }
590
591 /* Get width of command string. */
592 width = 0;
paul55468c82005-03-14 20:19:01 +0000593 for (i = 0; i < vector_active (describe); i++)
paul718e3742002-12-13 20:15:29 +0000594 if ((desc = vector_slot (describe, i)) != NULL)
595 {
596 int len;
597
598 if (desc->cmd[0] == '\0')
599 continue;
600
601 len = strlen (desc->cmd);
602 if (desc->cmd[0] == '.')
603 len--;
604
605 if (width < len)
606 width = len;
607 }
608
paul55468c82005-03-14 20:19:01 +0000609 for (i = 0; i < vector_active (describe); i++)
paul718e3742002-12-13 20:15:29 +0000610 if ((desc = vector_slot (describe, i)) != NULL)
611 {
612 if (desc->cmd[0] == '\0')
613 continue;
614
615 if (! desc->str)
paul4fc01e62002-12-13 20:49:00 +0000616 fprintf (stdout," %-s\n",
hassob094d262004-08-25 12:22:00 +0000617 desc->cmd[0] == '.' ? desc->cmd + 1 : desc->cmd);
paul718e3742002-12-13 20:15:29 +0000618 else
paul4fc01e62002-12-13 20:49:00 +0000619 fprintf (stdout," %-*s %s\n",
hassob094d262004-08-25 12:22:00 +0000620 width,
621 desc->cmd[0] == '.' ? desc->cmd + 1 : desc->cmd,
622 desc->str);
paul718e3742002-12-13 20:15:29 +0000623 }
624
625 cmd_free_strvec (vline);
626 vector_free (describe);
627
628 rl_on_new_line();
629
630 return 0;
631}
632
hasso95e735b2004-08-26 13:08:30 +0000633/* Result of cmd_complete_command() call will be stored here
634 * and used in new_completion() in order to put the space in
635 * correct places only. */
paul718e3742002-12-13 20:15:29 +0000636int complete_status;
637
ajs274a4a42004-12-07 15:39:31 +0000638static char *
pauldfc0d9b2003-04-18 23:55:29 +0000639command_generator (const char *text, int state)
paul718e3742002-12-13 20:15:29 +0000640{
641 vector vline;
642 static char **matched = NULL;
643 static int index = 0;
644
645 /* First call. */
646 if (! state)
647 {
648 index = 0;
649
650 if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
651 return NULL;
652
653 vline = cmd_make_strvec (rl_line_buffer);
654 if (vline == NULL)
655 return NULL;
656
657 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
658 vector_set (vline, '\0');
659
660 matched = cmd_complete_command (vline, vty, &complete_status);
661 }
662
663 if (matched && matched[index])
664 return matched[index++];
665
666 return NULL;
667}
668
ajs274a4a42004-12-07 15:39:31 +0000669static char **
paul718e3742002-12-13 20:15:29 +0000670new_completion (char *text, int start, int end)
671{
672 char **matches;
673
pauldfc0d9b2003-04-18 23:55:29 +0000674 matches = rl_completion_matches (text, command_generator);
paul718e3742002-12-13 20:15:29 +0000675
676 if (matches)
677 {
678 rl_point = rl_end;
679 if (complete_status == CMD_COMPLETE_FULL_MATCH)
680 rl_pending_input = ' ';
681 }
682
683 return matches;
684}
685
ajs274a4a42004-12-07 15:39:31 +0000686#if 0
687/* This function is not actually being used. */
688static char **
paul718e3742002-12-13 20:15:29 +0000689vtysh_completion (char *text, int start, int end)
690{
691 int ret;
692 vector vline;
693 char **matched = NULL;
694
695 if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
696 return NULL;
697
698 vline = cmd_make_strvec (rl_line_buffer);
699 if (vline == NULL)
700 return NULL;
701
702 /* In case of 'help \t'. */
703 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
704 vector_set (vline, '\0');
705
706 matched = cmd_complete_command (vline, vty, &ret);
707
708 cmd_free_strvec (vline);
709
710 return (char **) matched;
711}
ajs274a4a42004-12-07 15:39:31 +0000712#endif
paul718e3742002-12-13 20:15:29 +0000713
hasso95e735b2004-08-26 13:08:30 +0000714/* Vty node structures. */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800715static struct cmd_node bgp_node =
paul718e3742002-12-13 20:15:29 +0000716{
717 BGP_NODE,
718 "%s(config-router)# ",
719};
720
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800721static struct cmd_node rip_node =
paul718e3742002-12-13 20:15:29 +0000722{
723 RIP_NODE,
724 "%s(config-router)# ",
725};
726
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800727static struct cmd_node isis_node =
hassoc25e4582003-12-23 10:39:08 +0000728{
729 ISIS_NODE,
730 "%s(config-router)# ",
hassoc25e4582003-12-23 10:39:08 +0000731};
732
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800733static struct cmd_node interface_node =
paul718e3742002-12-13 20:15:29 +0000734{
735 INTERFACE_NODE,
736 "%s(config-if)# ",
737};
738
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800739static struct cmd_node rmap_node =
hasso95e735b2004-08-26 13:08:30 +0000740{
741 RMAP_NODE,
742 "%s(config-route-map)# "
743};
744
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800745static struct cmd_node zebra_node =
hasso95e735b2004-08-26 13:08:30 +0000746{
747 ZEBRA_NODE,
748 "%s(config-router)# "
749};
750
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800751static struct cmd_node bgp_vpnv4_node =
hasso95e735b2004-08-26 13:08:30 +0000752{
753 BGP_VPNV4_NODE,
754 "%s(config-router-af)# "
755};
756
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800757static struct cmd_node bgp_ipv4_node =
hasso95e735b2004-08-26 13:08:30 +0000758{
759 BGP_IPV4_NODE,
760 "%s(config-router-af)# "
761};
762
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800763static struct cmd_node bgp_ipv4m_node =
hasso95e735b2004-08-26 13:08:30 +0000764{
765 BGP_IPV4M_NODE,
766 "%s(config-router-af)# "
767};
768
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800769static struct cmd_node bgp_ipv6_node =
hasso95e735b2004-08-26 13:08:30 +0000770{
771 BGP_IPV6_NODE,
772 "%s(config-router-af)# "
773};
774
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800775static struct cmd_node bgp_ipv6m_node =
paul57b5b7e2005-08-22 22:44:29 +0000776{
777 BGP_IPV6M_NODE,
778 "%s(config-router-af)# "
779};
780
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800781static struct cmd_node ospf_node =
hasso95e735b2004-08-26 13:08:30 +0000782{
783 OSPF_NODE,
784 "%s(config-router)# "
785};
786
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800787static struct cmd_node ripng_node =
hasso95e735b2004-08-26 13:08:30 +0000788{
789 RIPNG_NODE,
790 "%s(config-router)# "
791};
792
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800793static struct cmd_node ospf6_node =
hasso95e735b2004-08-26 13:08:30 +0000794{
795 OSPF6_NODE,
796 "%s(config-ospf6)# "
797};
798
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800799static struct cmd_node keychain_node =
hasso95e735b2004-08-26 13:08:30 +0000800{
801 KEYCHAIN_NODE,
802 "%s(config-keychain)# "
803};
804
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800805static struct cmd_node keychain_key_node =
hasso95e735b2004-08-26 13:08:30 +0000806{
807 KEYCHAIN_KEY_NODE,
808 "%s(config-keychain-key)# "
809};
810
hassoe7168df2004-10-03 20:11:32 +0000811/* Defined in lib/vty.c */
812extern struct cmd_node vty_node;
813
hasso95e735b2004-08-26 13:08:30 +0000814/* When '^Z' is received from vty, move down to the enable mode. */
815int
ajsb1aa1472005-01-28 21:11:46 +0000816vtysh_end (void)
hasso95e735b2004-08-26 13:08:30 +0000817{
818 switch (vty->node)
819 {
820 case VIEW_NODE:
821 case ENABLE_NODE:
822 /* Nothing to do. */
823 break;
824 default:
825 vty->node = ENABLE_NODE;
826 break;
827 }
828 return CMD_SUCCESS;
829}
830
831DEFUNSH (VTYSH_ALL,
832 vtysh_end_all,
833 vtysh_end_all_cmd,
834 "end",
hassoe7168df2004-10-03 20:11:32 +0000835 "End current mode and change to enable mode\n")
hasso95e735b2004-08-26 13:08:30 +0000836{
hasso42895462004-09-26 16:25:07 +0000837 return vtysh_end ();
hasso95e735b2004-08-26 13:08:30 +0000838}
839
paul718e3742002-12-13 20:15:29 +0000840DEFUNSH (VTYSH_BGPD,
841 router_bgp,
842 router_bgp_cmd,
Paul Jakma320da872008-07-02 13:40:33 +0000843 "router bgp " CMD_AS_RANGE,
paul718e3742002-12-13 20:15:29 +0000844 ROUTER_STR
845 BGP_STR
846 AS_STR)
847{
848 vty->node = BGP_NODE;
849 return CMD_SUCCESS;
850}
851
Paul Jakma10895fd2008-07-03 19:34:48 +0000852ALIAS_SH (VTYSH_BGPD,
853 router_bgp,
854 router_bgp_view_cmd,
855 "router bgp " CMD_AS_RANGE " view WORD",
856 ROUTER_STR
857 BGP_STR
858 AS_STR
859 "BGP view\n"
860 "view name\n")
861
paul718e3742002-12-13 20:15:29 +0000862DEFUNSH (VTYSH_BGPD,
863 address_family_vpnv4,
864 address_family_vpnv4_cmd,
865 "address-family vpnv4",
866 "Enter Address Family command mode\n"
867 "Address family\n")
868{
869 vty->node = BGP_VPNV4_NODE;
870 return CMD_SUCCESS;
871}
872
873DEFUNSH (VTYSH_BGPD,
874 address_family_vpnv4_unicast,
875 address_family_vpnv4_unicast_cmd,
876 "address-family vpnv4 unicast",
877 "Enter Address Family command mode\n"
878 "Address family\n"
879 "Address Family Modifier\n")
880{
881 vty->node = BGP_VPNV4_NODE;
882 return CMD_SUCCESS;
883}
884
885DEFUNSH (VTYSH_BGPD,
886 address_family_ipv4_unicast,
887 address_family_ipv4_unicast_cmd,
888 "address-family ipv4 unicast",
889 "Enter Address Family command mode\n"
890 "Address family\n"
891 "Address Family Modifier\n")
892{
893 vty->node = BGP_IPV4_NODE;
894 return CMD_SUCCESS;
895}
896
897DEFUNSH (VTYSH_BGPD,
898 address_family_ipv4_multicast,
899 address_family_ipv4_multicast_cmd,
900 "address-family ipv4 multicast",
901 "Enter Address Family command mode\n"
902 "Address family\n"
903 "Address Family Modifier\n")
904{
905 vty->node = BGP_IPV4M_NODE;
906 return CMD_SUCCESS;
907}
908
909DEFUNSH (VTYSH_BGPD,
910 address_family_ipv6,
911 address_family_ipv6_cmd,
912 "address-family ipv6",
913 "Enter Address Family command mode\n"
914 "Address family\n")
915{
916 vty->node = BGP_IPV6_NODE;
917 return CMD_SUCCESS;
918}
919
920DEFUNSH (VTYSH_BGPD,
921 address_family_ipv6_unicast,
922 address_family_ipv6_unicast_cmd,
923 "address-family ipv6 unicast",
924 "Enter Address Family command mode\n"
925 "Address family\n"
926 "Address Family Modifier\n")
927{
928 vty->node = BGP_IPV6_NODE;
929 return CMD_SUCCESS;
930}
931
paul57b5b7e2005-08-22 22:44:29 +0000932DEFUNSH (VTYSH_BGPD,
933 address_family_ipv6_multicast,
934 address_family_ipv6_multicast_cmd,
935 "address-family ipv6 multicast",
936 "Enter Address Family command mode\n"
937 "Address family\n"
938 "Address Family Modifier\n")
939{
940 vty->node = BGP_IPV6M_NODE;
941 return CMD_SUCCESS;
942}
943
paul718e3742002-12-13 20:15:29 +0000944DEFUNSH (VTYSH_RIPD,
945 key_chain,
946 key_chain_cmd,
947 "key chain WORD",
948 "Authentication key management\n"
949 "Key-chain management\n"
950 "Key-chain name\n")
951{
952 vty->node = KEYCHAIN_NODE;
953 return CMD_SUCCESS;
954}
955
956DEFUNSH (VTYSH_RIPD,
957 key,
958 key_cmd,
959 "key <0-2147483647>",
960 "Configure a key\n"
961 "Key identifier number\n")
962{
963 vty->node = KEYCHAIN_KEY_NODE;
964 return CMD_SUCCESS;
965}
966
967DEFUNSH (VTYSH_RIPD,
968 router_rip,
969 router_rip_cmd,
970 "router rip",
971 ROUTER_STR
972 "RIP")
973{
974 vty->node = RIP_NODE;
975 return CMD_SUCCESS;
976}
977
978DEFUNSH (VTYSH_RIPNGD,
979 router_ripng,
980 router_ripng_cmd,
981 "router ripng",
982 ROUTER_STR
983 "RIPng")
984{
985 vty->node = RIPNG_NODE;
986 return CMD_SUCCESS;
987}
988
989DEFUNSH (VTYSH_OSPFD,
990 router_ospf,
991 router_ospf_cmd,
992 "router ospf",
993 "Enable a routing process\n"
994 "Start OSPF configuration\n")
995{
996 vty->node = OSPF_NODE;
997 return CMD_SUCCESS;
998}
999
1000DEFUNSH (VTYSH_OSPF6D,
1001 router_ospf6,
1002 router_ospf6_cmd,
1003 "router ospf6",
1004 OSPF6_ROUTER_STR
1005 OSPF6_STR)
1006{
1007 vty->node = OSPF6_NODE;
1008 return CMD_SUCCESS;
1009}
1010
hassoc25e4582003-12-23 10:39:08 +00001011DEFUNSH (VTYSH_ISISD,
hassob094d262004-08-25 12:22:00 +00001012 router_isis,
1013 router_isis_cmd,
1014 "router isis WORD",
1015 ROUTER_STR
1016 "ISO IS-IS\n"
1017 "ISO Routing area tag")
hassoc25e4582003-12-23 10:39:08 +00001018{
1019 vty->node = ISIS_NODE;
1020 return CMD_SUCCESS;
1021}
1022
paul718e3742002-12-13 20:15:29 +00001023DEFUNSH (VTYSH_RMAP,
1024 route_map,
1025 route_map_cmd,
1026 "route-map WORD (deny|permit) <1-65535>",
1027 "Create route-map or enter route-map command mode\n"
1028 "Route map tag\n"
1029 "Route map denies set operations\n"
1030 "Route map permits set operations\n"
1031 "Sequence to insert to/delete from existing route-map entry\n")
1032{
1033 vty->node = RMAP_NODE;
1034 return CMD_SUCCESS;
1035}
1036
paul718e3742002-12-13 20:15:29 +00001037DEFUNSH (VTYSH_ALL,
hassoe7168df2004-10-03 20:11:32 +00001038 vtysh_line_vty,
1039 vtysh_line_vty_cmd,
1040 "line vty",
1041 "Configure a terminal line\n"
1042 "Virtual terminal\n")
1043{
1044 vty->node = VTY_NODE;
1045 return CMD_SUCCESS;
1046}
1047
1048DEFUNSH (VTYSH_ALL,
paul718e3742002-12-13 20:15:29 +00001049 vtysh_enable,
1050 vtysh_enable_cmd,
1051 "enable",
1052 "Turn on privileged mode command\n")
1053{
1054 vty->node = ENABLE_NODE;
1055 return CMD_SUCCESS;
1056}
1057
paul718e3742002-12-13 20:15:29 +00001058DEFUNSH (VTYSH_ALL,
1059 vtysh_disable,
1060 vtysh_disable_cmd,
1061 "disable",
1062 "Turn off privileged mode command\n")
1063{
1064 if (vty->node == ENABLE_NODE)
1065 vty->node = VIEW_NODE;
1066 return CMD_SUCCESS;
1067}
1068
paul718e3742002-12-13 20:15:29 +00001069DEFUNSH (VTYSH_ALL,
1070 vtysh_config_terminal,
1071 vtysh_config_terminal_cmd,
1072 "configure terminal",
1073 "Configuration from vty interface\n"
1074 "Configuration terminal\n")
1075{
1076 vty->node = CONFIG_NODE;
1077 return CMD_SUCCESS;
1078}
1079
ajs274a4a42004-12-07 15:39:31 +00001080static int
paul718e3742002-12-13 20:15:29 +00001081vtysh_exit (struct vty *vty)
1082{
1083 switch (vty->node)
1084 {
1085 case VIEW_NODE:
1086 case ENABLE_NODE:
1087 exit (0);
1088 break;
1089 case CONFIG_NODE:
1090 vty->node = ENABLE_NODE;
1091 break;
1092 case INTERFACE_NODE:
1093 case ZEBRA_NODE:
1094 case BGP_NODE:
1095 case RIP_NODE:
1096 case RIPNG_NODE:
1097 case OSPF_NODE:
1098 case OSPF6_NODE:
hassoc25e4582003-12-23 10:39:08 +00001099 case ISIS_NODE:
paul718e3742002-12-13 20:15:29 +00001100 case MASC_NODE:
1101 case RMAP_NODE:
1102 case VTY_NODE:
1103 case KEYCHAIN_NODE:
hasso2a56df92004-05-09 23:16:40 +00001104 vtysh_execute("end");
1105 vtysh_execute("configure terminal");
paul718e3742002-12-13 20:15:29 +00001106 vty->node = CONFIG_NODE;
1107 break;
1108 case BGP_VPNV4_NODE:
1109 case BGP_IPV4_NODE:
1110 case BGP_IPV4M_NODE:
1111 case BGP_IPV6_NODE:
paul57b5b7e2005-08-22 22:44:29 +00001112 case BGP_IPV6M_NODE:
paul718e3742002-12-13 20:15:29 +00001113 vty->node = BGP_NODE;
1114 break;
1115 case KEYCHAIN_KEY_NODE:
1116 vty->node = KEYCHAIN_NODE;
1117 break;
1118 default:
1119 break;
1120 }
1121 return CMD_SUCCESS;
1122}
1123
1124DEFUNSH (VTYSH_ALL,
1125 vtysh_exit_all,
1126 vtysh_exit_all_cmd,
1127 "exit",
1128 "Exit current mode and down to previous mode\n")
1129{
1130 return vtysh_exit (vty);
1131}
1132
1133ALIAS (vtysh_exit_all,
1134 vtysh_quit_all_cmd,
1135 "quit",
1136 "Exit current mode and down to previous mode\n")
1137
1138DEFUNSH (VTYSH_BGPD,
1139 exit_address_family,
1140 exit_address_family_cmd,
1141 "exit-address-family",
1142 "Exit from Address Family configuration mode\n")
1143{
1144 if (vty->node == BGP_IPV4_NODE
1145 || vty->node == BGP_IPV4M_NODE
1146 || vty->node == BGP_VPNV4_NODE
paul57b5b7e2005-08-22 22:44:29 +00001147 || vty->node == BGP_IPV6_NODE
1148 || vty->node == BGP_IPV6M_NODE)
paul718e3742002-12-13 20:15:29 +00001149 vty->node = BGP_NODE;
1150 return CMD_SUCCESS;
1151}
1152
1153DEFUNSH (VTYSH_ZEBRA,
1154 vtysh_exit_zebra,
1155 vtysh_exit_zebra_cmd,
1156 "exit",
1157 "Exit current mode and down to previous mode\n")
1158{
1159 return vtysh_exit (vty);
1160}
1161
1162ALIAS (vtysh_exit_zebra,
1163 vtysh_quit_zebra_cmd,
1164 "quit",
1165 "Exit current mode and down to previous mode\n")
1166
1167DEFUNSH (VTYSH_RIPD,
1168 vtysh_exit_ripd,
1169 vtysh_exit_ripd_cmd,
1170 "exit",
1171 "Exit current mode and down to previous mode\n")
1172{
1173 return vtysh_exit (vty);
1174}
1175
1176ALIAS (vtysh_exit_ripd,
1177 vtysh_quit_ripd_cmd,
1178 "quit",
1179 "Exit current mode and down to previous mode\n")
1180
paul68980082003-03-25 05:07:42 +00001181DEFUNSH (VTYSH_RIPNGD,
hassob094d262004-08-25 12:22:00 +00001182 vtysh_exit_ripngd,
1183 vtysh_exit_ripngd_cmd,
1184 "exit",
1185 "Exit current mode and down to previous mode\n")
paul68980082003-03-25 05:07:42 +00001186{
1187 return vtysh_exit (vty);
1188}
1189
1190ALIAS (vtysh_exit_ripngd,
1191 vtysh_quit_ripngd_cmd,
1192 "quit",
1193 "Exit current mode and down to previous mode\n")
1194
paul718e3742002-12-13 20:15:29 +00001195DEFUNSH (VTYSH_RMAP,
1196 vtysh_exit_rmap,
1197 vtysh_exit_rmap_cmd,
1198 "exit",
1199 "Exit current mode and down to previous mode\n")
1200{
1201 return vtysh_exit (vty);
1202}
1203
1204ALIAS (vtysh_exit_rmap,
1205 vtysh_quit_rmap_cmd,
1206 "quit",
1207 "Exit current mode and down to previous mode\n")
1208
1209DEFUNSH (VTYSH_BGPD,
1210 vtysh_exit_bgpd,
1211 vtysh_exit_bgpd_cmd,
1212 "exit",
1213 "Exit current mode and down to previous mode\n")
1214{
1215 return vtysh_exit (vty);
1216}
1217
1218ALIAS (vtysh_exit_bgpd,
1219 vtysh_quit_bgpd_cmd,
1220 "quit",
1221 "Exit current mode and down to previous mode\n")
1222
1223DEFUNSH (VTYSH_OSPFD,
1224 vtysh_exit_ospfd,
1225 vtysh_exit_ospfd_cmd,
1226 "exit",
1227 "Exit current mode and down to previous mode\n")
1228{
1229 return vtysh_exit (vty);
1230}
1231
1232ALIAS (vtysh_exit_ospfd,
1233 vtysh_quit_ospfd_cmd,
1234 "quit",
1235 "Exit current mode and down to previous mode\n")
1236
paul68980082003-03-25 05:07:42 +00001237DEFUNSH (VTYSH_OSPF6D,
hassob094d262004-08-25 12:22:00 +00001238 vtysh_exit_ospf6d,
1239 vtysh_exit_ospf6d_cmd,
1240 "exit",
1241 "Exit current mode and down to previous mode\n")
paul68980082003-03-25 05:07:42 +00001242{
1243 return vtysh_exit (vty);
1244}
1245
1246ALIAS (vtysh_exit_ospf6d,
1247 vtysh_quit_ospf6d_cmd,
1248 "quit",
1249 "Exit current mode and down to previous mode\n")
1250
hassoc25e4582003-12-23 10:39:08 +00001251DEFUNSH (VTYSH_ISISD,
hassob094d262004-08-25 12:22:00 +00001252 vtysh_exit_isisd,
1253 vtysh_exit_isisd_cmd,
1254 "exit",
1255 "Exit current mode and down to previous mode\n")
hassoc25e4582003-12-23 10:39:08 +00001256{
1257 return vtysh_exit (vty);
1258}
1259
1260ALIAS (vtysh_exit_isisd,
1261 vtysh_quit_isisd_cmd,
1262 "quit",
1263 "Exit current mode and down to previous mode\n")
1264
hassoe7168df2004-10-03 20:11:32 +00001265DEFUNSH (VTYSH_ALL,
1266 vtysh_exit_line_vty,
1267 vtysh_exit_line_vty_cmd,
1268 "exit",
1269 "Exit current mode and down to previous mode\n")
1270{
1271 return vtysh_exit (vty);
1272}
1273
1274ALIAS (vtysh_exit_line_vty,
1275 vtysh_quit_line_vty_cmd,
1276 "quit",
1277 "Exit current mode and down to previous mode\n")
1278
hasso95e735b2004-08-26 13:08:30 +00001279DEFUNSH (VTYSH_INTERFACE,
paul718e3742002-12-13 20:15:29 +00001280 vtysh_interface,
1281 vtysh_interface_cmd,
1282 "interface IFNAME",
1283 "Select an interface to configure\n"
1284 "Interface's name\n")
1285{
1286 vty->node = INTERFACE_NODE;
1287 return CMD_SUCCESS;
1288}
1289
hasso95e735b2004-08-26 13:08:30 +00001290/* TODO Implement "no interface command in isisd. */
paul32d24632003-05-23 09:25:20 +00001291DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D,
1292 vtysh_no_interface_cmd,
1293 "no interface IFNAME",
1294 NO_STR
1295 "Delete a pseudo interface's configuration\n"
1296 "Interface's name\n")
1297
hasso95e735b2004-08-26 13:08:30 +00001298/* TODO Implement interface description commands in ripngd, ospf6d
1299 * and isisd. */
paul338a9912003-03-01 15:44:10 +00001300DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1301 interface_desc_cmd,
1302 "description .LINE",
1303 "Interface specific description\n"
1304 "Characters describing this interface\n")
paul464dc8d2003-03-28 02:25:45 +00001305
1306DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1307 no_interface_desc_cmd,
1308 "no description",
1309 NO_STR
1310 "Interface specific description\n")
paul338a9912003-03-01 15:44:10 +00001311
hasso95e735b2004-08-26 13:08:30 +00001312DEFUNSH (VTYSH_INTERFACE,
paul718e3742002-12-13 20:15:29 +00001313 vtysh_exit_interface,
1314 vtysh_exit_interface_cmd,
1315 "exit",
1316 "Exit current mode and down to previous mode\n")
1317{
1318 return vtysh_exit (vty);
1319}
1320
1321ALIAS (vtysh_exit_interface,
1322 vtysh_quit_interface_cmd,
1323 "quit",
1324 "Exit current mode and down to previous mode\n")
1325
Paul Jakma362b4032006-05-28 07:54:45 +00001326/* Memory */
1327DEFUN (vtysh_show_memory,
1328 vtysh_show_memory_cmd,
1329 "show memory",
1330 SHOW_STR
1331 "Memory statistics\n")
1332{
1333 unsigned int i;
1334 int ret = CMD_SUCCESS;
1335 char line[] = "show memory\n";
1336
1337 for (i = 0; i < VTYSH_INDEX_MAX; i++)
1338 if ( vtysh_client[i].fd >= 0 )
1339 {
1340 fprintf (stdout, "Memory statistics for %s:\n",
1341 vtysh_client[i].name);
1342 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1343 fprintf (stdout,"\n");
1344 }
1345
1346 return ret;
1347}
1348
hasso95e735b2004-08-26 13:08:30 +00001349/* Logging commands. */
Paul Jakmadbf7d132006-05-23 22:10:01 +00001350DEFUN (vtysh_show_logging,
1351 vtysh_show_logging_cmd,
1352 "show logging",
1353 SHOW_STR
1354 "Show current logging configuration\n")
1355{
1356 unsigned int i;
1357 int ret = CMD_SUCCESS;
1358 char line[] = "show logging\n";
1359
1360 for (i = 0; i < VTYSH_INDEX_MAX; i++)
Paul Jakma4150f332006-05-23 22:10:55 +00001361 if ( vtysh_client[i].fd >= 0 )
1362 {
1363 fprintf (stdout,"Logging configuration for %s:\n",
1364 vtysh_client[i].name);
1365 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1366 fprintf (stdout,"\n");
1367 }
1368
Paul Jakmadbf7d132006-05-23 22:10:01 +00001369 return ret;
1370}
1371
hasso95e735b2004-08-26 13:08:30 +00001372DEFUNSH (VTYSH_ALL,
1373 vtysh_log_stdout,
1374 vtysh_log_stdout_cmd,
1375 "log stdout",
1376 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001377 "Set stdout logging level\n")
1378{
1379 return CMD_SUCCESS;
1380}
1381
1382DEFUNSH (VTYSH_ALL,
1383 vtysh_log_stdout_level,
1384 vtysh_log_stdout_level_cmd,
1385 "log stdout "LOG_LEVELS,
1386 "Logging control\n"
1387 "Set stdout logging level\n"
1388 LOG_LEVEL_DESC)
hasso95e735b2004-08-26 13:08:30 +00001389{
1390 return CMD_SUCCESS;
1391}
1392
1393DEFUNSH (VTYSH_ALL,
1394 no_vtysh_log_stdout,
1395 no_vtysh_log_stdout_cmd,
ajs274a4a42004-12-07 15:39:31 +00001396 "no log stdout [LEVEL]",
hasso95e735b2004-08-26 13:08:30 +00001397 NO_STR
1398 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001399 "Cancel logging to stdout\n"
1400 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001401{
1402 return CMD_SUCCESS;
1403}
1404
1405DEFUNSH (VTYSH_ALL,
1406 vtysh_log_file,
1407 vtysh_log_file_cmd,
1408 "log file FILENAME",
1409 "Logging control\n"
1410 "Logging to file\n"
1411 "Logging filename\n")
1412{
1413 return CMD_SUCCESS;
1414}
1415
1416DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001417 vtysh_log_file_level,
1418 vtysh_log_file_level_cmd,
1419 "log file FILENAME "LOG_LEVELS,
1420 "Logging control\n"
1421 "Logging to file\n"
1422 "Logging filename\n"
1423 LOG_LEVEL_DESC)
1424{
1425 return CMD_SUCCESS;
1426}
1427
1428DEFUNSH (VTYSH_ALL,
hasso95e735b2004-08-26 13:08:30 +00001429 no_vtysh_log_file,
1430 no_vtysh_log_file_cmd,
1431 "no log file [FILENAME]",
1432 NO_STR
1433 "Logging control\n"
1434 "Cancel logging to file\n"
1435 "Logging file name\n")
1436{
1437 return CMD_SUCCESS;
1438}
1439
ajs274a4a42004-12-07 15:39:31 +00001440ALIAS_SH (VTYSH_ALL,
1441 no_vtysh_log_file,
1442 no_vtysh_log_file_level_cmd,
1443 "no log file FILENAME LEVEL",
1444 NO_STR
1445 "Logging control\n"
1446 "Cancel logging to file\n"
1447 "Logging file name\n"
1448 "Logging level\n")
1449
1450DEFUNSH (VTYSH_ALL,
1451 vtysh_log_monitor,
1452 vtysh_log_monitor_cmd,
1453 "log monitor",
1454 "Logging control\n"
1455 "Set terminal line (monitor) logging level\n")
1456{
1457 return CMD_SUCCESS;
1458}
1459
1460DEFUNSH (VTYSH_ALL,
1461 vtysh_log_monitor_level,
1462 vtysh_log_monitor_level_cmd,
1463 "log monitor "LOG_LEVELS,
1464 "Logging control\n"
1465 "Set terminal line (monitor) logging level\n"
1466 LOG_LEVEL_DESC)
1467{
1468 return CMD_SUCCESS;
1469}
1470
1471DEFUNSH (VTYSH_ALL,
1472 no_vtysh_log_monitor,
1473 no_vtysh_log_monitor_cmd,
1474 "no log monitor [LEVEL]",
1475 NO_STR
1476 "Logging control\n"
1477 "Disable terminal line (monitor) logging\n"
1478 "Logging level\n")
1479{
1480 return CMD_SUCCESS;
1481}
1482
hasso95e735b2004-08-26 13:08:30 +00001483DEFUNSH (VTYSH_ALL,
1484 vtysh_log_syslog,
1485 vtysh_log_syslog_cmd,
1486 "log syslog",
1487 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001488 "Set syslog logging level\n")
1489{
1490 return CMD_SUCCESS;
1491}
1492
1493DEFUNSH (VTYSH_ALL,
1494 vtysh_log_syslog_level,
1495 vtysh_log_syslog_level_cmd,
1496 "log syslog "LOG_LEVELS,
1497 "Logging control\n"
1498 "Set syslog logging level\n"
1499 LOG_LEVEL_DESC)
hasso95e735b2004-08-26 13:08:30 +00001500{
1501 return CMD_SUCCESS;
1502}
1503
1504DEFUNSH (VTYSH_ALL,
1505 no_vtysh_log_syslog,
1506 no_vtysh_log_syslog_cmd,
ajs274a4a42004-12-07 15:39:31 +00001507 "no log syslog [LEVEL]",
hasso95e735b2004-08-26 13:08:30 +00001508 NO_STR
1509 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001510 "Cancel logging to syslog\n"
1511 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001512{
1513 return CMD_SUCCESS;
1514}
1515
1516DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001517 vtysh_log_facility,
1518 vtysh_log_facility_cmd,
1519 "log facility "LOG_FACILITIES,
hasso95e735b2004-08-26 13:08:30 +00001520 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001521 "Facility parameter for syslog messages\n"
1522 LOG_FACILITY_DESC)
1523
hasso95e735b2004-08-26 13:08:30 +00001524{
1525 return CMD_SUCCESS;
1526}
1527
1528DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001529 no_vtysh_log_facility,
1530 no_vtysh_log_facility_cmd,
1531 "no log facility [FACILITY]",
hasso95e735b2004-08-26 13:08:30 +00001532 NO_STR
1533 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001534 "Reset syslog facility to default (daemon)\n"
1535 "Syslog facility\n")
1536
1537{
1538 return CMD_SUCCESS;
1539}
1540
1541DEFUNSH_DEPRECATED (VTYSH_ALL,
1542 vtysh_log_trap,
1543 vtysh_log_trap_cmd,
1544 "log trap "LOG_LEVELS,
1545 "Logging control\n"
1546 "(Deprecated) Set logging level and default for all destinations\n"
1547 LOG_LEVEL_DESC)
1548
1549{
1550 return CMD_SUCCESS;
1551}
1552
1553DEFUNSH_DEPRECATED (VTYSH_ALL,
1554 no_vtysh_log_trap,
1555 no_vtysh_log_trap_cmd,
1556 "no log trap [LEVEL]",
1557 NO_STR
1558 "Logging control\n"
1559 "Permit all logging information\n"
1560 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001561{
1562 return CMD_SUCCESS;
1563}
1564
1565DEFUNSH (VTYSH_ALL,
1566 vtysh_log_record_priority,
1567 vtysh_log_record_priority_cmd,
1568 "log record-priority",
1569 "Logging control\n"
1570 "Log the priority of the message within the message\n")
1571{
1572 return CMD_SUCCESS;
1573}
1574
1575DEFUNSH (VTYSH_ALL,
1576 no_vtysh_log_record_priority,
1577 no_vtysh_log_record_priority_cmd,
1578 "no log record-priority",
1579 NO_STR
1580 "Logging control\n"
1581 "Do not log the priority of the message within the message\n")
1582{
1583 return CMD_SUCCESS;
1584}
1585
hassoe7168df2004-10-03 20:11:32 +00001586DEFUNSH (VTYSH_ALL,
Andrew J. Schorrc749b722007-04-29 03:53:31 +00001587 vtysh_log_timestamp_precision,
1588 vtysh_log_timestamp_precision_cmd,
1589 "log timestamp precision <0-6>",
1590 "Logging control\n"
1591 "Timestamp configuration\n"
1592 "Set the timestamp precision\n"
1593 "Number of subsecond digits\n")
1594{
1595 return CMD_SUCCESS;
1596}
1597
1598DEFUNSH (VTYSH_ALL,
1599 no_vtysh_log_timestamp_precision,
1600 no_vtysh_log_timestamp_precision_cmd,
1601 "no log timestamp precision",
1602 NO_STR
1603 "Logging control\n"
1604 "Timestamp configuration\n"
1605 "Reset the timestamp precision to the default value of 0\n")
1606{
1607 return CMD_SUCCESS;
1608}
1609
1610DEFUNSH (VTYSH_ALL,
hassoe7168df2004-10-03 20:11:32 +00001611 vtysh_service_password_encrypt,
1612 vtysh_service_password_encrypt_cmd,
1613 "service password-encryption",
1614 "Set up miscellaneous service\n"
1615 "Enable encrypted passwords\n")
1616{
1617 return CMD_SUCCESS;
1618}
1619
1620DEFUNSH (VTYSH_ALL,
1621 no_vtysh_service_password_encrypt,
1622 no_vtysh_service_password_encrypt_cmd,
1623 "no service password-encryption",
1624 NO_STR
1625 "Set up miscellaneous service\n"
1626 "Enable encrypted passwords\n")
1627{
1628 return CMD_SUCCESS;
1629}
1630
1631DEFUNSH (VTYSH_ALL,
1632 vtysh_config_password,
1633 vtysh_password_cmd,
1634 "password (8|) WORD",
1635 "Assign the terminal connection password\n"
1636 "Specifies a HIDDEN password will follow\n"
1637 "dummy string \n"
1638 "The HIDDEN line password string\n")
1639{
1640 return CMD_SUCCESS;
1641}
1642
1643DEFUNSH (VTYSH_ALL,
1644 vtysh_password_text,
1645 vtysh_password_text_cmd,
1646 "password LINE",
1647 "Assign the terminal connection password\n"
1648 "The UNENCRYPTED (cleartext) line password\n")
1649{
1650 return CMD_SUCCESS;
1651}
1652
1653DEFUNSH (VTYSH_ALL,
1654 vtysh_config_enable_password,
1655 vtysh_enable_password_cmd,
1656 "enable password (8|) WORD",
1657 "Modify enable password parameters\n"
1658 "Assign the privileged level password\n"
1659 "Specifies a HIDDEN password will follow\n"
1660 "dummy string \n"
1661 "The HIDDEN 'enable' password string\n")
1662{
1663 return CMD_SUCCESS;
1664}
1665
1666DEFUNSH (VTYSH_ALL,
1667 vtysh_enable_password_text,
1668 vtysh_enable_password_text_cmd,
1669 "enable password LINE",
1670 "Modify enable password parameters\n"
1671 "Assign the privileged level password\n"
1672 "The UNENCRYPTED (cleartext) 'enable' password\n")
1673{
1674 return CMD_SUCCESS;
1675}
1676
1677DEFUNSH (VTYSH_ALL,
1678 no_vtysh_config_enable_password,
1679 no_vtysh_enable_password_cmd,
1680 "no enable password",
1681 NO_STR
1682 "Modify enable password parameters\n"
1683 "Assign the privileged level password\n")
1684{
1685 return CMD_SUCCESS;
1686}
1687
paul718e3742002-12-13 20:15:29 +00001688DEFUN (vtysh_write_terminal,
1689 vtysh_write_terminal_cmd,
1690 "write terminal",
1691 "Write running configuration to memory, network, or terminal\n"
1692 "Write to terminal\n")
1693{
ajsb1aa1472005-01-28 21:11:46 +00001694 u_int i;
paul718e3742002-12-13 20:15:29 +00001695 int ret;
1696 char line[] = "write terminal\n";
1697 FILE *fp = NULL;
1698
1699 if (vtysh_pager_name)
1700 {
paul4fc01e62002-12-13 20:49:00 +00001701 fp = popen (vtysh_pager_name, "w");
paul718e3742002-12-13 20:15:29 +00001702 if (fp == NULL)
1703 {
1704 perror ("popen");
1705 exit (1);
1706 }
1707 }
1708 else
1709 fp = stdout;
1710
1711 vty_out (vty, "Building configuration...%s", VTY_NEWLINE);
1712 vty_out (vty, "%sCurrent configuration:%s", VTY_NEWLINE,
1713 VTY_NEWLINE);
hassoe7168df2004-10-03 20:11:32 +00001714 vty_out (vty, "!%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001715
ajsb1aa1472005-01-28 21:11:46 +00001716 for (i = 0; i < VTYSH_INDEX_MAX; i++)
1717 ret = vtysh_client_config (&vtysh_client[i], line);
paul718e3742002-12-13 20:15:29 +00001718
hassoe7168df2004-10-03 20:11:32 +00001719 /* Integrate vtysh specific configuration. */
1720 vtysh_config_write ();
1721
paul718e3742002-12-13 20:15:29 +00001722 vtysh_config_dump (fp);
1723
Paul Jakma8454b052007-06-20 15:22:14 +00001724 vty_out (vty, "end%s", VTY_NEWLINE);
1725
paul718e3742002-12-13 20:15:29 +00001726 if (vtysh_pager_name && fp)
1727 {
1728 fflush (fp);
1729 if (pclose (fp) == -1)
1730 {
1731 perror ("pclose");
1732 exit (1);
1733 }
1734 fp = NULL;
1735 }
1736
1737 return CMD_SUCCESS;
1738}
1739
hassoe7168df2004-10-03 20:11:32 +00001740DEFUN (vtysh_integrated_config,
1741 vtysh_integrated_config_cmd,
1742 "service integrated-vtysh-config",
1743 "Set up miscellaneous service\n"
1744 "Write configuration into integrated file\n")
paul4fc01e62002-12-13 20:49:00 +00001745{
hassoe7168df2004-10-03 20:11:32 +00001746 vtysh_writeconfig_integrated = 1;
1747 return CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001748}
1749
hassoe7168df2004-10-03 20:11:32 +00001750DEFUN (no_vtysh_integrated_config,
1751 no_vtysh_integrated_config_cmd,
1752 "no service integrated-vtysh-config",
1753 NO_STR
1754 "Set up miscellaneous service\n"
1755 "Write configuration into integrated file\n")
paul4fc01e62002-12-13 20:49:00 +00001756{
hassoe7168df2004-10-03 20:11:32 +00001757 vtysh_writeconfig_integrated = 0;
1758 return CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001759}
1760
ajs274a4a42004-12-07 15:39:31 +00001761static int
1762write_config_integrated(void)
paul718e3742002-12-13 20:15:29 +00001763{
ajsb1aa1472005-01-28 21:11:46 +00001764 u_int i;
paul718e3742002-12-13 20:15:29 +00001765 int ret;
paul718e3742002-12-13 20:15:29 +00001766 char line[] = "write terminal\n";
1767 FILE *fp;
1768 char *integrate_sav = NULL;
1769
hasso95e735b2004-08-26 13:08:30 +00001770 integrate_sav = malloc (strlen (integrate_default) +
1771 strlen (CONF_BACKUP_EXT) + 1);
paul718e3742002-12-13 20:15:29 +00001772 strcpy (integrate_sav, integrate_default);
1773 strcat (integrate_sav, CONF_BACKUP_EXT);
1774
paul4fc01e62002-12-13 20:49:00 +00001775 fprintf (stdout,"Building Configuration...\n");
paul718e3742002-12-13 20:15:29 +00001776
hasso95e735b2004-08-26 13:08:30 +00001777 /* Move current configuration file to backup config file. */
paul718e3742002-12-13 20:15:29 +00001778 unlink (integrate_sav);
1779 rename (integrate_default, integrate_sav);
hasso95e735b2004-08-26 13:08:30 +00001780 free (integrate_sav);
paul4fc01e62002-12-13 20:49:00 +00001781
paul718e3742002-12-13 20:15:29 +00001782 fp = fopen (integrate_default, "w");
1783 if (fp == NULL)
1784 {
hasso95e735b2004-08-26 13:08:30 +00001785 fprintf (stdout,"%% Can't open configuration file %s.\n",
1786 integrate_default);
paul718e3742002-12-13 20:15:29 +00001787 return CMD_SUCCESS;
1788 }
paul718e3742002-12-13 20:15:29 +00001789
ajsb1aa1472005-01-28 21:11:46 +00001790 for (i = 0; i < VTYSH_INDEX_MAX; i++)
1791 ret = vtysh_client_config (&vtysh_client[i], line);
paul718e3742002-12-13 20:15:29 +00001792
1793 vtysh_config_dump (fp);
1794
1795 fclose (fp);
1796
gdtaa593d52003-12-22 20:15:53 +00001797 if (chmod (integrate_default, CONFIGFILE_MASK) != 0)
1798 {
1799 fprintf (stdout,"%% Can't chmod configuration file %s: %s (%d)\n",
ajs6099b3b2004-11-20 02:06:59 +00001800 integrate_default, safe_strerror(errno), errno);
gdtaa593d52003-12-22 20:15:53 +00001801 return CMD_WARNING;
1802 }
1803
paul4fc01e62002-12-13 20:49:00 +00001804 fprintf(stdout,"Integrated configuration saved to %s\n",integrate_default);
1805
1806 fprintf (stdout,"[OK]\n");
1807
paul718e3742002-12-13 20:15:29 +00001808 return CMD_SUCCESS;
1809}
1810
paul4fc01e62002-12-13 20:49:00 +00001811DEFUN (vtysh_write_memory,
1812 vtysh_write_memory_cmd,
1813 "write memory",
1814 "Write running configuration to memory, network, or terminal\n"
1815 "Write configuration to the file (same as write file)\n")
1816{
pauldfc0d9b2003-04-18 23:55:29 +00001817 int ret = CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001818 char line[] = "write memory\n";
ajsb1aa1472005-01-28 21:11:46 +00001819 u_int i;
paul4fc01e62002-12-13 20:49:00 +00001820
hassoe7168df2004-10-03 20:11:32 +00001821 /* If integrated Quagga.conf explicitely set. */
1822 if (vtysh_writeconfig_integrated)
1823 return write_config_integrated();
paul4fc01e62002-12-13 20:49:00 +00001824
1825 fprintf (stdout,"Building Configuration...\n");
1826
ajsb1aa1472005-01-28 21:11:46 +00001827 for (i = 0; i < VTYSH_INDEX_MAX; i++)
1828 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
hassoe7168df2004-10-03 20:11:32 +00001829
paul4fc01e62002-12-13 20:49:00 +00001830 fprintf (stdout,"[OK]\n");
1831
pauldfc0d9b2003-04-18 23:55:29 +00001832 return ret;
paul4fc01e62002-12-13 20:49:00 +00001833}
1834
paul718e3742002-12-13 20:15:29 +00001835ALIAS (vtysh_write_memory,
1836 vtysh_copy_runningconfig_startupconfig_cmd,
1837 "copy running-config startup-config",
1838 "Copy from one file to another\n"
1839 "Copy from current system configuration\n"
1840 "Copy to startup configuration\n")
1841
1842ALIAS (vtysh_write_memory,
1843 vtysh_write_file_cmd,
1844 "write file",
1845 "Write running configuration to memory, network, or terminal\n"
1846 "Write configuration to the file (same as write memory)\n")
1847
hasso4a6e2252003-05-25 11:51:29 +00001848ALIAS (vtysh_write_memory,
1849 vtysh_write_cmd,
1850 "write",
1851 "Write running configuration to memory, network, or terminal\n")
1852
paul718e3742002-12-13 20:15:29 +00001853ALIAS (vtysh_write_terminal,
1854 vtysh_show_running_config_cmd,
1855 "show running-config",
1856 SHOW_STR
1857 "Current operating configuration\n")
hassob094d262004-08-25 12:22:00 +00001858
hasso34553cc2004-08-27 13:56:39 +00001859DEFUN (vtysh_terminal_length,
1860 vtysh_terminal_length_cmd,
1861 "terminal length <0-512>",
1862 "Set terminal line parameters\n"
1863 "Set number of lines on a screen\n"
1864 "Number of lines on screen (0 for no pausing)\n")
1865{
1866 int lines;
1867 char *endptr = NULL;
1868 char default_pager[10];
1869
1870 lines = strtol (argv[0], &endptr, 10);
1871 if (lines < 0 || lines > 512 || *endptr != '\0')
1872 {
1873 vty_out (vty, "length is malformed%s", VTY_NEWLINE);
1874 return CMD_WARNING;
1875 }
1876
1877 if (vtysh_pager_name)
1878 {
1879 free (vtysh_pager_name);
1880 vtysh_pager_name = NULL;
1881 }
1882
1883 if (lines != 0)
1884 {
1885 snprintf(default_pager, 10, "more -%i", lines);
1886 vtysh_pager_name = strdup (default_pager);
1887 }
1888
1889 return CMD_SUCCESS;
1890}
1891
1892DEFUN (vtysh_terminal_no_length,
1893 vtysh_terminal_no_length_cmd,
1894 "terminal no length",
1895 "Set terminal line parameters\n"
1896 NO_STR
1897 "Set number of lines on a screen\n")
1898{
1899 if (vtysh_pager_name)
1900 {
1901 free (vtysh_pager_name);
1902 vtysh_pager_name = NULL;
1903 }
1904
1905 vtysh_pager_init();
1906 return CMD_SUCCESS;
1907}
1908
hassof2799e62004-10-28 17:43:11 +00001909DEFUN (vtysh_show_daemons,
1910 vtysh_show_daemons_cmd,
1911 "show daemons",
hassoe7168df2004-10-03 20:11:32 +00001912 SHOW_STR
1913 "Show list of running daemons\n")
1914{
ajsb1aa1472005-01-28 21:11:46 +00001915 u_int i;
1916
1917 for (i = 0; i < VTYSH_INDEX_MAX; i++)
1918 if ( vtysh_client[i].fd >= 0 )
1919 vty_out(vty, " %s", vtysh_client[i].name);
hassoe7168df2004-10-03 20:11:32 +00001920 vty_out(vty, "%s", VTY_NEWLINE);
1921
1922 return CMD_SUCCESS;
1923}
1924
paul718e3742002-12-13 20:15:29 +00001925/* Execute command in child process. */
ajs274a4a42004-12-07 15:39:31 +00001926static int
hasso5862ff52004-10-11 13:20:40 +00001927execute_command (const char *command, int argc, const char *arg1,
1928 const char *arg2)
paul718e3742002-12-13 20:15:29 +00001929{
1930 int ret;
1931 pid_t pid;
1932 int status;
1933
1934 /* Call fork(). */
1935 pid = fork ();
1936
1937 if (pid < 0)
1938 {
1939 /* Failure of fork(). */
ajs6099b3b2004-11-20 02:06:59 +00001940 fprintf (stderr, "Can't fork: %s\n", safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +00001941 exit (1);
1942 }
1943 else if (pid == 0)
1944 {
1945 /* This is child process. */
1946 switch (argc)
1947 {
1948 case 0:
hassofa2b17e2004-03-04 17:45:00 +00001949 ret = execlp (command, command, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00001950 break;
1951 case 1:
hassofa2b17e2004-03-04 17:45:00 +00001952 ret = execlp (command, command, arg1, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00001953 break;
1954 case 2:
hassofa2b17e2004-03-04 17:45:00 +00001955 ret = execlp (command, command, arg1, arg2, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00001956 break;
1957 }
1958
1959 /* When execlp suceed, this part is not executed. */
ajs6099b3b2004-11-20 02:06:59 +00001960 fprintf (stderr, "Can't execute %s: %s\n", command, safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +00001961 exit (1);
1962 }
1963 else
1964 {
1965 /* This is parent. */
1966 execute_flag = 1;
1967 ret = wait4 (pid, &status, 0, NULL);
1968 execute_flag = 0;
1969 }
1970 return 0;
1971}
1972
1973DEFUN (vtysh_ping,
1974 vtysh_ping_cmd,
1975 "ping WORD",
hasso4eeccf12003-06-25 10:49:55 +00001976 "Send echo messages\n"
paul718e3742002-12-13 20:15:29 +00001977 "Ping destination address or hostname\n")
1978{
1979 execute_command ("ping", 1, argv[0], NULL);
1980 return CMD_SUCCESS;
1981}
1982
hasso4eeccf12003-06-25 10:49:55 +00001983ALIAS (vtysh_ping,
1984 vtysh_ping_ip_cmd,
1985 "ping ip WORD",
1986 "Send echo messages\n"
1987 "IP echo\n"
1988 "Ping destination address or hostname\n")
1989
paul718e3742002-12-13 20:15:29 +00001990DEFUN (vtysh_traceroute,
1991 vtysh_traceroute_cmd,
1992 "traceroute WORD",
1993 "Trace route to destination\n"
1994 "Trace route to destination address or hostname\n")
1995{
1996 execute_command ("traceroute", 1, argv[0], NULL);
1997 return CMD_SUCCESS;
1998}
1999
hasso4eeccf12003-06-25 10:49:55 +00002000ALIAS (vtysh_traceroute,
2001 vtysh_traceroute_ip_cmd,
2002 "traceroute ip WORD",
2003 "Trace route to destination\n"
2004 "IP trace\n"
2005 "Trace route to destination address or hostname\n")
2006
2007#ifdef HAVE_IPV6
2008DEFUN (vtysh_ping6,
2009 vtysh_ping6_cmd,
2010 "ping ipv6 WORD",
2011 "Send echo messages\n"
2012 "IPv6 echo\n"
2013 "Ping destination address or hostname\n")
2014{
2015 execute_command ("ping6", 1, argv[0], NULL);
2016 return CMD_SUCCESS;
2017}
2018
2019DEFUN (vtysh_traceroute6,
2020 vtysh_traceroute6_cmd,
2021 "traceroute ipv6 WORD",
2022 "Trace route to destination\n"
2023 "IPv6 trace\n"
2024 "Trace route to destination address or hostname\n")
2025{
2026 execute_command ("traceroute6", 1, argv[0], NULL);
2027 return CMD_SUCCESS;
2028}
2029#endif
2030
paul718e3742002-12-13 20:15:29 +00002031DEFUN (vtysh_telnet,
2032 vtysh_telnet_cmd,
2033 "telnet WORD",
2034 "Open a telnet connection\n"
2035 "IP address or hostname of a remote system\n")
2036{
2037 execute_command ("telnet", 1, argv[0], NULL);
2038 return CMD_SUCCESS;
2039}
2040
2041DEFUN (vtysh_telnet_port,
2042 vtysh_telnet_port_cmd,
2043 "telnet WORD PORT",
2044 "Open a telnet connection\n"
2045 "IP address or hostname of a remote system\n"
2046 "TCP Port number\n")
2047{
2048 execute_command ("telnet", 2, argv[0], argv[1]);
2049 return CMD_SUCCESS;
2050}
2051
paul5087df52003-01-25 06:56:09 +00002052DEFUN (vtysh_ssh,
2053 vtysh_ssh_cmd,
2054 "ssh WORD",
2055 "Open an ssh connection\n"
2056 "[user@]host\n")
2057{
2058 execute_command ("ssh", 1, argv[0], NULL);
2059 return CMD_SUCCESS;
2060}
2061
paul718e3742002-12-13 20:15:29 +00002062DEFUN (vtysh_start_shell,
2063 vtysh_start_shell_cmd,
2064 "start-shell",
2065 "Start UNIX shell\n")
2066{
2067 execute_command ("sh", 0, NULL, NULL);
2068 return CMD_SUCCESS;
2069}
2070
2071DEFUN (vtysh_start_bash,
2072 vtysh_start_bash_cmd,
2073 "start-shell bash",
2074 "Start UNIX shell\n"
2075 "Start bash\n")
2076{
2077 execute_command ("bash", 0, NULL, NULL);
2078 return CMD_SUCCESS;
2079}
2080
2081DEFUN (vtysh_start_zsh,
2082 vtysh_start_zsh_cmd,
2083 "start-shell zsh",
2084 "Start UNIX shell\n"
2085 "Start Z shell\n")
2086{
2087 execute_command ("zsh", 0, NULL, NULL);
2088 return CMD_SUCCESS;
2089}
hassob094d262004-08-25 12:22:00 +00002090
ajs274a4a42004-12-07 15:39:31 +00002091static void
paul718e3742002-12-13 20:15:29 +00002092vtysh_install_default (enum node_type node)
2093{
2094 install_element (node, &config_list_cmd);
2095}
2096
2097/* Making connection to protocol daemon. */
ajs274a4a42004-12-07 15:39:31 +00002098static int
ajsb1aa1472005-01-28 21:11:46 +00002099vtysh_connect (struct vtysh_client *vclient)
paul718e3742002-12-13 20:15:29 +00002100{
2101 int ret;
2102 int sock, len;
2103 struct sockaddr_un addr;
2104 struct stat s_stat;
paul718e3742002-12-13 20:15:29 +00002105
paul718e3742002-12-13 20:15:29 +00002106 /* Stat socket to see if we have permission to access it. */
ajsb1aa1472005-01-28 21:11:46 +00002107 ret = stat (vclient->path, &s_stat);
paul718e3742002-12-13 20:15:29 +00002108 if (ret < 0 && errno != ENOENT)
2109 {
2110 fprintf (stderr, "vtysh_connect(%s): stat = %s\n",
ajsb1aa1472005-01-28 21:11:46 +00002111 vclient->path, safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002112 exit(1);
2113 }
2114
2115 if (ret >= 0)
2116 {
2117 if (! S_ISSOCK(s_stat.st_mode))
2118 {
2119 fprintf (stderr, "vtysh_connect(%s): Not a socket\n",
ajsb1aa1472005-01-28 21:11:46 +00002120 vclient->path);
paul718e3742002-12-13 20:15:29 +00002121 exit (1);
2122 }
2123
paul718e3742002-12-13 20:15:29 +00002124 }
2125
2126 sock = socket (AF_UNIX, SOCK_STREAM, 0);
2127 if (sock < 0)
2128 {
2129#ifdef DEBUG
ajsb1aa1472005-01-28 21:11:46 +00002130 fprintf(stderr, "vtysh_connect(%s): socket = %s\n", vclient->path,
ajs6099b3b2004-11-20 02:06:59 +00002131 safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002132#endif /* DEBUG */
2133 return -1;
2134 }
2135
2136 memset (&addr, 0, sizeof (struct sockaddr_un));
2137 addr.sun_family = AF_UNIX;
ajsb1aa1472005-01-28 21:11:46 +00002138 strncpy (addr.sun_path, vclient->path, strlen (vclient->path));
Paul Jakma6f0e3f62007-05-10 02:38:51 +00002139#ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
paul718e3742002-12-13 20:15:29 +00002140 len = addr.sun_len = SUN_LEN(&addr);
2141#else
2142 len = sizeof (addr.sun_family) + strlen (addr.sun_path);
Paul Jakma6f0e3f62007-05-10 02:38:51 +00002143#endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
paul718e3742002-12-13 20:15:29 +00002144
2145 ret = connect (sock, (struct sockaddr *) &addr, len);
2146 if (ret < 0)
2147 {
2148#ifdef DEBUG
ajsb1aa1472005-01-28 21:11:46 +00002149 fprintf(stderr, "vtysh_connect(%s): connect = %s\n", vclient->path,
ajs6099b3b2004-11-20 02:06:59 +00002150 safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002151#endif /* DEBUG */
2152 close (sock);
2153 return -1;
2154 }
2155 vclient->fd = sock;
2156
2157 return 0;
2158}
2159
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002160int
2161vtysh_connect_all(const char *daemon_name)
paul718e3742002-12-13 20:15:29 +00002162{
ajsb1aa1472005-01-28 21:11:46 +00002163 u_int i;
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002164 int rc = 0;
2165 int matches = 0;
ajsb1aa1472005-01-28 21:11:46 +00002166
2167 for (i = 0; i < VTYSH_INDEX_MAX; i++)
2168 {
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002169 if (!daemon_name || !strcmp(daemon_name, vtysh_client[i].name))
2170 {
2171 matches++;
2172 if (vtysh_connect(&vtysh_client[i]) == 0)
2173 rc++;
2174 /* We need direct access to ripd in vtysh_exit_ripd_only. */
2175 if (vtysh_client[i].flag == VTYSH_RIPD)
2176 ripd_client = &vtysh_client[i];
2177 }
ajsb1aa1472005-01-28 21:11:46 +00002178 }
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002179 if (!matches)
2180 fprintf(stderr, "Error: no daemons match name %s!\n", daemon_name);
2181 return rc;
paul718e3742002-12-13 20:15:29 +00002182}
2183
hasso95e735b2004-08-26 13:08:30 +00002184/* To disable readline's filename completion. */
ajs274a4a42004-12-07 15:39:31 +00002185static char *
pauldfc0d9b2003-04-18 23:55:29 +00002186vtysh_completion_entry_function (const char *ignore, int invoking_key)
paul718e3742002-12-13 20:15:29 +00002187{
pauldfc0d9b2003-04-18 23:55:29 +00002188 return NULL;
paul718e3742002-12-13 20:15:29 +00002189}
2190
2191void
ajsb1aa1472005-01-28 21:11:46 +00002192vtysh_readline_init (void)
paul718e3742002-12-13 20:15:29 +00002193{
2194 /* readline related settings. */
hasso53a6f932005-09-15 06:50:53 +00002195 rl_bind_key ('?', (Function *) vtysh_rl_describe);
paul68980082003-03-25 05:07:42 +00002196 rl_completion_entry_function = vtysh_completion_entry_function;
paul718e3742002-12-13 20:15:29 +00002197 rl_attempted_completion_function = (CPPFunction *)new_completion;
2198 /* do not append space after completion. It will be appended
hasso95e735b2004-08-26 13:08:30 +00002199 * in new_completion() function explicitly. */
paul718e3742002-12-13 20:15:29 +00002200 rl_completion_append_character = '\0';
2201}
2202
2203char *
ajsb1aa1472005-01-28 21:11:46 +00002204vtysh_prompt (void)
paul718e3742002-12-13 20:15:29 +00002205{
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002206 static struct utsname names;
paul718e3742002-12-13 20:15:29 +00002207 static char buf[100];
2208 const char*hostname;
2209 extern struct host host;
2210
2211 hostname = host.name;
2212
2213 if (!hostname)
2214 {
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002215 if (!names.nodename[0])
2216 uname (&names);
paul718e3742002-12-13 20:15:29 +00002217 hostname = names.nodename;
2218 }
2219
2220 snprintf (buf, sizeof buf, cmd_prompt (vty->node), hostname);
2221
2222 return buf;
2223}
2224
2225void
ajsb1aa1472005-01-28 21:11:46 +00002226vtysh_init_vty (void)
paul718e3742002-12-13 20:15:29 +00002227{
2228 /* Make vty structure. */
2229 vty = vty_new ();
2230 vty->type = VTY_SHELL;
2231 vty->node = VIEW_NODE;
2232
2233 /* Initialize commands. */
2234 cmd_init (0);
2235
2236 /* Install nodes. */
2237 install_node (&bgp_node, NULL);
2238 install_node (&rip_node, NULL);
2239 install_node (&interface_node, NULL);
2240 install_node (&rmap_node, NULL);
2241 install_node (&zebra_node, NULL);
2242 install_node (&bgp_vpnv4_node, NULL);
2243 install_node (&bgp_ipv4_node, NULL);
2244 install_node (&bgp_ipv4m_node, NULL);
2245/* #ifdef HAVE_IPV6 */
2246 install_node (&bgp_ipv6_node, NULL);
paul57b5b7e2005-08-22 22:44:29 +00002247 install_node (&bgp_ipv6m_node, NULL);
paul718e3742002-12-13 20:15:29 +00002248/* #endif */
2249 install_node (&ospf_node, NULL);
2250/* #ifdef HAVE_IPV6 */
2251 install_node (&ripng_node, NULL);
2252 install_node (&ospf6_node, NULL);
2253/* #endif */
2254 install_node (&keychain_node, NULL);
2255 install_node (&keychain_key_node, NULL);
hassoc25e4582003-12-23 10:39:08 +00002256 install_node (&isis_node, NULL);
hassoe7168df2004-10-03 20:11:32 +00002257 install_node (&vty_node, NULL);
paul718e3742002-12-13 20:15:29 +00002258
2259 vtysh_install_default (VIEW_NODE);
2260 vtysh_install_default (ENABLE_NODE);
2261 vtysh_install_default (CONFIG_NODE);
2262 vtysh_install_default (BGP_NODE);
2263 vtysh_install_default (RIP_NODE);
2264 vtysh_install_default (INTERFACE_NODE);
2265 vtysh_install_default (RMAP_NODE);
2266 vtysh_install_default (ZEBRA_NODE);
2267 vtysh_install_default (BGP_VPNV4_NODE);
2268 vtysh_install_default (BGP_IPV4_NODE);
2269 vtysh_install_default (BGP_IPV4M_NODE);
2270 vtysh_install_default (BGP_IPV6_NODE);
paul57b5b7e2005-08-22 22:44:29 +00002271 vtysh_install_default (BGP_IPV6M_NODE);
paul718e3742002-12-13 20:15:29 +00002272 vtysh_install_default (OSPF_NODE);
2273 vtysh_install_default (RIPNG_NODE);
2274 vtysh_install_default (OSPF6_NODE);
hassoc25e4582003-12-23 10:39:08 +00002275 vtysh_install_default (ISIS_NODE);
paul718e3742002-12-13 20:15:29 +00002276 vtysh_install_default (KEYCHAIN_NODE);
2277 vtysh_install_default (KEYCHAIN_KEY_NODE);
hassoe7168df2004-10-03 20:11:32 +00002278 vtysh_install_default (VTY_NODE);
paul718e3742002-12-13 20:15:29 +00002279
2280 install_element (VIEW_NODE, &vtysh_enable_cmd);
2281 install_element (ENABLE_NODE, &vtysh_config_terminal_cmd);
2282 install_element (ENABLE_NODE, &vtysh_disable_cmd);
2283
2284 /* "exit" command. */
2285 install_element (VIEW_NODE, &vtysh_exit_all_cmd);
2286 install_element (VIEW_NODE, &vtysh_quit_all_cmd);
2287 install_element (CONFIG_NODE, &vtysh_exit_all_cmd);
2288 /* install_element (CONFIG_NODE, &vtysh_quit_all_cmd); */
2289 install_element (ENABLE_NODE, &vtysh_exit_all_cmd);
2290 install_element (ENABLE_NODE, &vtysh_quit_all_cmd);
2291 install_element (RIP_NODE, &vtysh_exit_ripd_cmd);
2292 install_element (RIP_NODE, &vtysh_quit_ripd_cmd);
paul68980082003-03-25 05:07:42 +00002293 install_element (RIPNG_NODE, &vtysh_exit_ripngd_cmd);
2294 install_element (RIPNG_NODE, &vtysh_quit_ripngd_cmd);
paul718e3742002-12-13 20:15:29 +00002295 install_element (OSPF_NODE, &vtysh_exit_ospfd_cmd);
2296 install_element (OSPF_NODE, &vtysh_quit_ospfd_cmd);
paul68980082003-03-25 05:07:42 +00002297 install_element (OSPF6_NODE, &vtysh_exit_ospf6d_cmd);
2298 install_element (OSPF6_NODE, &vtysh_quit_ospf6d_cmd);
paul718e3742002-12-13 20:15:29 +00002299 install_element (BGP_NODE, &vtysh_exit_bgpd_cmd);
2300 install_element (BGP_NODE, &vtysh_quit_bgpd_cmd);
2301 install_element (BGP_VPNV4_NODE, &vtysh_exit_bgpd_cmd);
2302 install_element (BGP_VPNV4_NODE, &vtysh_quit_bgpd_cmd);
2303 install_element (BGP_IPV4_NODE, &vtysh_exit_bgpd_cmd);
2304 install_element (BGP_IPV4_NODE, &vtysh_quit_bgpd_cmd);
2305 install_element (BGP_IPV4M_NODE, &vtysh_exit_bgpd_cmd);
2306 install_element (BGP_IPV4M_NODE, &vtysh_quit_bgpd_cmd);
2307 install_element (BGP_IPV6_NODE, &vtysh_exit_bgpd_cmd);
2308 install_element (BGP_IPV6_NODE, &vtysh_quit_bgpd_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002309 install_element (BGP_IPV6M_NODE, &vtysh_exit_bgpd_cmd);
2310 install_element (BGP_IPV6M_NODE, &vtysh_quit_bgpd_cmd);
hassoc25e4582003-12-23 10:39:08 +00002311 install_element (ISIS_NODE, &vtysh_exit_isisd_cmd);
2312 install_element (ISIS_NODE, &vtysh_quit_isisd_cmd);
paul718e3742002-12-13 20:15:29 +00002313 install_element (KEYCHAIN_NODE, &vtysh_exit_ripd_cmd);
2314 install_element (KEYCHAIN_NODE, &vtysh_quit_ripd_cmd);
2315 install_element (KEYCHAIN_KEY_NODE, &vtysh_exit_ripd_cmd);
2316 install_element (KEYCHAIN_KEY_NODE, &vtysh_quit_ripd_cmd);
2317 install_element (RMAP_NODE, &vtysh_exit_rmap_cmd);
2318 install_element (RMAP_NODE, &vtysh_quit_rmap_cmd);
hassoe7168df2004-10-03 20:11:32 +00002319 install_element (VTY_NODE, &vtysh_exit_line_vty_cmd);
2320 install_element (VTY_NODE, &vtysh_quit_line_vty_cmd);
paul718e3742002-12-13 20:15:29 +00002321
2322 /* "end" command. */
2323 install_element (CONFIG_NODE, &vtysh_end_all_cmd);
2324 install_element (ENABLE_NODE, &vtysh_end_all_cmd);
2325 install_element (RIP_NODE, &vtysh_end_all_cmd);
2326 install_element (RIPNG_NODE, &vtysh_end_all_cmd);
2327 install_element (OSPF_NODE, &vtysh_end_all_cmd);
2328 install_element (OSPF6_NODE, &vtysh_end_all_cmd);
2329 install_element (BGP_NODE, &vtysh_end_all_cmd);
2330 install_element (BGP_IPV4_NODE, &vtysh_end_all_cmd);
2331 install_element (BGP_IPV4M_NODE, &vtysh_end_all_cmd);
2332 install_element (BGP_VPNV4_NODE, &vtysh_end_all_cmd);
2333 install_element (BGP_IPV6_NODE, &vtysh_end_all_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002334 install_element (BGP_IPV6M_NODE, &vtysh_end_all_cmd);
hassoc25e4582003-12-23 10:39:08 +00002335 install_element (ISIS_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002336 install_element (KEYCHAIN_NODE, &vtysh_end_all_cmd);
2337 install_element (KEYCHAIN_KEY_NODE, &vtysh_end_all_cmd);
2338 install_element (RMAP_NODE, &vtysh_end_all_cmd);
hassoe7168df2004-10-03 20:11:32 +00002339 install_element (VTY_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002340
paul338a9912003-03-01 15:44:10 +00002341 install_element (INTERFACE_NODE, &interface_desc_cmd);
paul464dc8d2003-03-28 02:25:45 +00002342 install_element (INTERFACE_NODE, &no_interface_desc_cmd);
paul718e3742002-12-13 20:15:29 +00002343 install_element (INTERFACE_NODE, &vtysh_end_all_cmd);
2344 install_element (INTERFACE_NODE, &vtysh_exit_interface_cmd);
2345 install_element (INTERFACE_NODE, &vtysh_quit_interface_cmd);
2346 install_element (CONFIG_NODE, &router_rip_cmd);
2347#ifdef HAVE_IPV6
2348 install_element (CONFIG_NODE, &router_ripng_cmd);
2349#endif
2350 install_element (CONFIG_NODE, &router_ospf_cmd);
2351#ifdef HAVE_IPV6
2352 install_element (CONFIG_NODE, &router_ospf6_cmd);
2353#endif
hassoc25e4582003-12-23 10:39:08 +00002354 install_element (CONFIG_NODE, &router_isis_cmd);
paul718e3742002-12-13 20:15:29 +00002355 install_element (CONFIG_NODE, &router_bgp_cmd);
Paul Jakma10895fd2008-07-03 19:34:48 +00002356 install_element (CONFIG_NODE, &router_bgp_view_cmd);
paul718e3742002-12-13 20:15:29 +00002357 install_element (BGP_NODE, &address_family_vpnv4_cmd);
2358 install_element (BGP_NODE, &address_family_vpnv4_unicast_cmd);
2359 install_element (BGP_NODE, &address_family_ipv4_unicast_cmd);
2360 install_element (BGP_NODE, &address_family_ipv4_multicast_cmd);
2361#ifdef HAVE_IPV6
2362 install_element (BGP_NODE, &address_family_ipv6_cmd);
2363 install_element (BGP_NODE, &address_family_ipv6_unicast_cmd);
2364#endif
2365 install_element (BGP_VPNV4_NODE, &exit_address_family_cmd);
2366 install_element (BGP_IPV4_NODE, &exit_address_family_cmd);
2367 install_element (BGP_IPV4M_NODE, &exit_address_family_cmd);
2368 install_element (BGP_IPV6_NODE, &exit_address_family_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002369 install_element (BGP_IPV6M_NODE, &exit_address_family_cmd);
paul718e3742002-12-13 20:15:29 +00002370 install_element (CONFIG_NODE, &key_chain_cmd);
2371 install_element (CONFIG_NODE, &route_map_cmd);
hassoe7168df2004-10-03 20:11:32 +00002372 install_element (CONFIG_NODE, &vtysh_line_vty_cmd);
paul718e3742002-12-13 20:15:29 +00002373 install_element (KEYCHAIN_NODE, &key_cmd);
2374 install_element (KEYCHAIN_NODE, &key_chain_cmd);
2375 install_element (KEYCHAIN_KEY_NODE, &key_chain_cmd);
2376 install_element (CONFIG_NODE, &vtysh_interface_cmd);
paul32d24632003-05-23 09:25:20 +00002377 install_element (CONFIG_NODE, &vtysh_no_interface_cmd);
paul718e3742002-12-13 20:15:29 +00002378 install_element (ENABLE_NODE, &vtysh_show_running_config_cmd);
2379 install_element (ENABLE_NODE, &vtysh_copy_runningconfig_startupconfig_cmd);
2380 install_element (ENABLE_NODE, &vtysh_write_file_cmd);
hasso4a6e2252003-05-25 11:51:29 +00002381 install_element (ENABLE_NODE, &vtysh_write_cmd);
paul718e3742002-12-13 20:15:29 +00002382
hasso95e735b2004-08-26 13:08:30 +00002383 /* "write terminal" command. */
paul718e3742002-12-13 20:15:29 +00002384 install_element (ENABLE_NODE, &vtysh_write_terminal_cmd);
hassoe7168df2004-10-03 20:11:32 +00002385
2386 install_element (CONFIG_NODE, &vtysh_integrated_config_cmd);
2387 install_element (CONFIG_NODE, &no_vtysh_integrated_config_cmd);
paul718e3742002-12-13 20:15:29 +00002388
hasso95e735b2004-08-26 13:08:30 +00002389 /* "write memory" command. */
paul718e3742002-12-13 20:15:29 +00002390 install_element (ENABLE_NODE, &vtysh_write_memory_cmd);
paul718e3742002-12-13 20:15:29 +00002391
hasso34553cc2004-08-27 13:56:39 +00002392 install_element (VIEW_NODE, &vtysh_terminal_length_cmd);
2393 install_element (ENABLE_NODE, &vtysh_terminal_length_cmd);
2394 install_element (VIEW_NODE, &vtysh_terminal_no_length_cmd);
2395 install_element (ENABLE_NODE, &vtysh_terminal_no_length_cmd);
hassof2799e62004-10-28 17:43:11 +00002396 install_element (VIEW_NODE, &vtysh_show_daemons_cmd);
2397 install_element (ENABLE_NODE, &vtysh_show_daemons_cmd);
hasso34553cc2004-08-27 13:56:39 +00002398
paul718e3742002-12-13 20:15:29 +00002399 install_element (VIEW_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002400 install_element (VIEW_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00002401 install_element (VIEW_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002402 install_element (VIEW_NODE, &vtysh_traceroute_ip_cmd);
2403#ifdef HAVE_IPV6
2404 install_element (VIEW_NODE, &vtysh_ping6_cmd);
2405 install_element (VIEW_NODE, &vtysh_traceroute6_cmd);
2406#endif
paul718e3742002-12-13 20:15:29 +00002407 install_element (VIEW_NODE, &vtysh_telnet_cmd);
2408 install_element (VIEW_NODE, &vtysh_telnet_port_cmd);
paul5087df52003-01-25 06:56:09 +00002409 install_element (VIEW_NODE, &vtysh_ssh_cmd);
paul718e3742002-12-13 20:15:29 +00002410 install_element (ENABLE_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002411 install_element (ENABLE_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00002412 install_element (ENABLE_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002413 install_element (ENABLE_NODE, &vtysh_traceroute_ip_cmd);
2414#ifdef HAVE_IPV6
2415 install_element (ENABLE_NODE, &vtysh_ping6_cmd);
2416 install_element (ENABLE_NODE, &vtysh_traceroute6_cmd);
2417#endif
paul718e3742002-12-13 20:15:29 +00002418 install_element (ENABLE_NODE, &vtysh_telnet_cmd);
2419 install_element (ENABLE_NODE, &vtysh_telnet_port_cmd);
hasso67e29ab2004-08-26 22:21:31 +00002420 install_element (ENABLE_NODE, &vtysh_ssh_cmd);
paul718e3742002-12-13 20:15:29 +00002421 install_element (ENABLE_NODE, &vtysh_start_shell_cmd);
2422 install_element (ENABLE_NODE, &vtysh_start_bash_cmd);
2423 install_element (ENABLE_NODE, &vtysh_start_zsh_cmd);
Paul Jakmadbf7d132006-05-23 22:10:01 +00002424
Paul Jakma362b4032006-05-28 07:54:45 +00002425 install_element (VIEW_NODE, &vtysh_show_memory_cmd);
2426 install_element (ENABLE_NODE, &vtysh_show_memory_cmd);
2427
Paul Jakmadbf7d132006-05-23 22:10:01 +00002428 /* Logging */
2429 install_element (ENABLE_NODE, &vtysh_show_logging_cmd);
2430 install_element (VIEW_NODE, &vtysh_show_logging_cmd);
paul718e3742002-12-13 20:15:29 +00002431 install_element (CONFIG_NODE, &vtysh_log_stdout_cmd);
ajs274a4a42004-12-07 15:39:31 +00002432 install_element (CONFIG_NODE, &vtysh_log_stdout_level_cmd);
paul718e3742002-12-13 20:15:29 +00002433 install_element (CONFIG_NODE, &no_vtysh_log_stdout_cmd);
2434 install_element (CONFIG_NODE, &vtysh_log_file_cmd);
ajs274a4a42004-12-07 15:39:31 +00002435 install_element (CONFIG_NODE, &vtysh_log_file_level_cmd);
paul718e3742002-12-13 20:15:29 +00002436 install_element (CONFIG_NODE, &no_vtysh_log_file_cmd);
ajs274a4a42004-12-07 15:39:31 +00002437 install_element (CONFIG_NODE, &no_vtysh_log_file_level_cmd);
2438 install_element (CONFIG_NODE, &vtysh_log_monitor_cmd);
2439 install_element (CONFIG_NODE, &vtysh_log_monitor_level_cmd);
2440 install_element (CONFIG_NODE, &no_vtysh_log_monitor_cmd);
paul718e3742002-12-13 20:15:29 +00002441 install_element (CONFIG_NODE, &vtysh_log_syslog_cmd);
ajs274a4a42004-12-07 15:39:31 +00002442 install_element (CONFIG_NODE, &vtysh_log_syslog_level_cmd);
paul718e3742002-12-13 20:15:29 +00002443 install_element (CONFIG_NODE, &no_vtysh_log_syslog_cmd);
2444 install_element (CONFIG_NODE, &vtysh_log_trap_cmd);
2445 install_element (CONFIG_NODE, &no_vtysh_log_trap_cmd);
ajs274a4a42004-12-07 15:39:31 +00002446 install_element (CONFIG_NODE, &vtysh_log_facility_cmd);
2447 install_element (CONFIG_NODE, &no_vtysh_log_facility_cmd);
paul718e3742002-12-13 20:15:29 +00002448 install_element (CONFIG_NODE, &vtysh_log_record_priority_cmd);
2449 install_element (CONFIG_NODE, &no_vtysh_log_record_priority_cmd);
Andrew J. Schorrc749b722007-04-29 03:53:31 +00002450 install_element (CONFIG_NODE, &vtysh_log_timestamp_precision_cmd);
2451 install_element (CONFIG_NODE, &no_vtysh_log_timestamp_precision_cmd);
hassoe7168df2004-10-03 20:11:32 +00002452
2453 install_element (CONFIG_NODE, &vtysh_service_password_encrypt_cmd);
2454 install_element (CONFIG_NODE, &no_vtysh_service_password_encrypt_cmd);
2455
2456 install_element (CONFIG_NODE, &vtysh_password_cmd);
2457 install_element (CONFIG_NODE, &vtysh_password_text_cmd);
2458 install_element (CONFIG_NODE, &vtysh_enable_password_cmd);
2459 install_element (CONFIG_NODE, &vtysh_enable_password_text_cmd);
2460 install_element (CONFIG_NODE, &no_vtysh_enable_password_cmd);
2461
paul718e3742002-12-13 20:15:29 +00002462}