blob: bff06323bbc75ca6fe99dcee2a4526e422d8d5b6 [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 Hemminger2c4d48b2008-07-28 15:04:56 -0700278 int ret, cmd_stat;
ajsb1aa1472005-01-28 21:11:46 +0000279 u_int i;
paul718e3742002-12-13 20:15:29 +0000280 vector vline;
281 struct cmd_element *cmd;
282 FILE *fp = NULL;
hasso13bfca72005-01-23 21:42:25 +0000283 int closepager = 0;
284 int tried = 0;
285 int saved_ret, saved_node;
paul718e3742002-12-13 20:15:29 +0000286
hasso95e735b2004-08-26 13:08:30 +0000287 /* Split readline string up into the vector. */
paul718e3742002-12-13 20:15:29 +0000288 vline = cmd_make_strvec (line);
289
290 if (vline == NULL)
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
Stephen Hemminger2c4d48b2008-07-28 15:04:56 -0700339 cmd_stat = ret;
paul718e3742002-12-13 20:15:29 +0000340 switch (ret)
341 {
342 case CMD_WARNING:
343 if (vty->type == VTY_FILE)
paul4fc01e62002-12-13 20:49:00 +0000344 fprintf (stdout,"Warning...\n");
paul718e3742002-12-13 20:15:29 +0000345 break;
346 case CMD_ERR_AMBIGUOUS:
paul4fc01e62002-12-13 20:49:00 +0000347 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000348 break;
349 case CMD_ERR_NO_MATCH:
paul4fc01e62002-12-13 20:49:00 +0000350 fprintf (stdout,"%% Unknown command.\n");
paul718e3742002-12-13 20:15:29 +0000351 break;
352 case CMD_ERR_INCOMPLETE:
paul4fc01e62002-12-13 20:49:00 +0000353 fprintf (stdout,"%% Command incomplete.\n");
paul718e3742002-12-13 20:15:29 +0000354 break;
355 case CMD_SUCCESS_DAEMON:
356 {
hasso97b7db22004-10-20 19:07:48 +0000357 /* FIXME: Don't open pager for exit commands. popen() causes problems
358 * if exited from vtysh at all. This hack shouldn't cause any problem
359 * but is really ugly. */
360 if (pager && vtysh_pager_name && (strncmp(line, "exit", 4) != 0))
paul718e3742002-12-13 20:15:29 +0000361 {
paul4fc01e62002-12-13 20:49:00 +0000362 fp = popen (vtysh_pager_name, "w");
paul718e3742002-12-13 20:15:29 +0000363 if (fp == NULL)
364 {
paula805cc22003-05-01 14:29:48 +0000365 perror ("popen failed for pager");
366 fp = stdout;
paul718e3742002-12-13 20:15:29 +0000367 }
paula805cc22003-05-01 14:29:48 +0000368 else
369 closepager=1;
paul718e3742002-12-13 20:15:29 +0000370 }
371 else
372 fp = stdout;
373
374 if (! strcmp(cmd->string,"configure terminal"))
375 {
ajsb1aa1472005-01-28 21:11:46 +0000376 for (i = 0; i < VTYSH_INDEX_MAX; i++)
377 {
378 cmd_stat = vtysh_client_execute(&vtysh_client[i], line, fp);
379 if (cmd_stat == CMD_WARNING)
380 break;
381 }
382
paul718e3742002-12-13 20:15:29 +0000383 if (cmd_stat)
384 {
hassob094d262004-08-25 12:22:00 +0000385 line = "end";
386 vline = cmd_make_strvec (line);
paul718e3742002-12-13 20:15:29 +0000387
hassob094d262004-08-25 12:22:00 +0000388 if (vline == NULL)
paul718e3742002-12-13 20:15:29 +0000389 {
paula805cc22003-05-01 14:29:48 +0000390 if (pager && vtysh_pager_name && fp && closepager)
paul718e3742002-12-13 20:15:29 +0000391 {
392 if (pclose (fp) == -1)
393 {
paula805cc22003-05-01 14:29:48 +0000394 perror ("pclose failed for pager");
paul718e3742002-12-13 20:15:29 +0000395 }
396 fp = NULL;
397 }
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700398 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000399 }
400
hasso87d683b2005-01-16 23:31:54 +0000401 ret = cmd_execute_command (vline, vty, &cmd, 1);
hassob094d262004-08-25 12:22:00 +0000402 cmd_free_strvec (vline);
403 if (ret != CMD_SUCCESS_DAEMON)
404 break;
paul718e3742002-12-13 20:15:29 +0000405 }
406 else
407 if (cmd->func)
408 {
409 (*cmd->func) (cmd, vty, 0, NULL);
410 break;
hassob094d262004-08-25 12:22:00 +0000411 }
paul718e3742002-12-13 20:15:29 +0000412 }
413
ajsb1aa1472005-01-28 21:11:46 +0000414 cmd_stat = CMD_SUCCESS;
415 for (i = 0; i < VTYSH_INDEX_MAX; i++)
416 {
417 if (cmd->daemon & vtysh_client[i].flag)
418 {
419 cmd_stat = vtysh_client_execute(&vtysh_client[i], line, fp);
420 if (cmd_stat != CMD_SUCCESS)
421 break;
422 }
423 }
424 if (cmd_stat != CMD_SUCCESS)
425 break;
426
paul718e3742002-12-13 20:15:29 +0000427 if (cmd->func)
428 (*cmd->func) (cmd, vty, 0, NULL);
429 }
430 }
paula805cc22003-05-01 14:29:48 +0000431 if (pager && vtysh_pager_name && fp && closepager)
paul718e3742002-12-13 20:15:29 +0000432 {
433 if (pclose (fp) == -1)
434 {
paula805cc22003-05-01 14:29:48 +0000435 perror ("pclose failed for pager");
paul718e3742002-12-13 20:15:29 +0000436 }
437 fp = NULL;
438 }
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700439 return cmd_stat;
paul718e3742002-12-13 20:15:29 +0000440}
441
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700442int
hassodda09522004-10-07 21:40:25 +0000443vtysh_execute_no_pager (const char *line)
paul718e3742002-12-13 20:15:29 +0000444{
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700445 return vtysh_execute_func (line, 0);
paul718e3742002-12-13 20:15:29 +0000446}
447
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700448int
hassodda09522004-10-07 21:40:25 +0000449vtysh_execute (const char *line)
paul718e3742002-12-13 20:15:29 +0000450{
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700451 return vtysh_execute_func (line, 1);
paul718e3742002-12-13 20:15:29 +0000452}
453
454/* Configration make from file. */
455int
456vtysh_config_from_file (struct vty *vty, FILE *fp)
457{
458 int ret;
459 vector vline;
460 struct cmd_element *cmd;
461
462 while (fgets (vty->buf, VTY_BUFSIZ, fp))
463 {
464 if (vty->buf[0] == '!' || vty->buf[1] == '#')
465 continue;
466
467 vline = cmd_make_strvec (vty->buf);
468
hasso95e735b2004-08-26 13:08:30 +0000469 /* In case of comment line. */
paul718e3742002-12-13 20:15:29 +0000470 if (vline == NULL)
471 continue;
472
hasso95e735b2004-08-26 13:08:30 +0000473 /* Execute configuration command : this is strict match. */
paul718e3742002-12-13 20:15:29 +0000474 ret = cmd_execute_command_strict (vline, vty, &cmd);
475
hasso95e735b2004-08-26 13:08:30 +0000476 /* Try again with setting node to CONFIG_NODE. */
paul718e3742002-12-13 20:15:29 +0000477 if (ret != CMD_SUCCESS
478 && ret != CMD_SUCCESS_DAEMON
479 && ret != CMD_WARNING)
480 {
481 if (vty->node == KEYCHAIN_KEY_NODE)
482 {
483 vty->node = KEYCHAIN_NODE;
484 vtysh_exit_ripd_only ();
485 ret = cmd_execute_command_strict (vline, vty, &cmd);
486
487 if (ret != CMD_SUCCESS
488 && ret != CMD_SUCCESS_DAEMON
489 && ret != CMD_WARNING)
490 {
491 vtysh_exit_ripd_only ();
492 vty->node = CONFIG_NODE;
493 ret = cmd_execute_command_strict (vline, vty, &cmd);
494 }
495 }
496 else
497 {
498 vtysh_execute ("end");
499 vtysh_execute ("configure terminal");
500 vty->node = CONFIG_NODE;
501 ret = cmd_execute_command_strict (vline, vty, &cmd);
502 }
503 }
504
505 cmd_free_strvec (vline);
506
507 switch (ret)
508 {
509 case CMD_WARNING:
510 if (vty->type == VTY_FILE)
paul4fc01e62002-12-13 20:49:00 +0000511 fprintf (stdout,"Warning...\n");
paul718e3742002-12-13 20:15:29 +0000512 break;
513 case CMD_ERR_AMBIGUOUS:
paul4fc01e62002-12-13 20:49:00 +0000514 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000515 break;
516 case CMD_ERR_NO_MATCH:
paul4fc01e62002-12-13 20:49:00 +0000517 fprintf (stdout,"%% Unknown command: %s", vty->buf);
paul718e3742002-12-13 20:15:29 +0000518 break;
519 case CMD_ERR_INCOMPLETE:
paul4fc01e62002-12-13 20:49:00 +0000520 fprintf (stdout,"%% Command incomplete.\n");
paul718e3742002-12-13 20:15:29 +0000521 break;
522 case CMD_SUCCESS_DAEMON:
523 {
ajsb1aa1472005-01-28 21:11:46 +0000524 u_int i;
525 int cmd_stat = CMD_SUCCESS;
526
527 for (i = 0; i < VTYSH_INDEX_MAX; i++)
528 {
paul44316fe2006-01-11 01:38:25 +0000529 if (cmd->daemon & vtysh_client[i].flag)
ajsb1aa1472005-01-28 21:11:46 +0000530 {
531 cmd_stat = vtysh_client_execute (&vtysh_client[i],
532 vty->buf, stdout);
533 if (cmd_stat != CMD_SUCCESS)
534 break;
535 }
536 }
537 if (cmd_stat != CMD_SUCCESS)
538 break;
539
paul718e3742002-12-13 20:15:29 +0000540 if (cmd->func)
541 (*cmd->func) (cmd, vty, 0, NULL);
542 }
543 }
544 }
545 return CMD_SUCCESS;
546}
547
548/* We don't care about the point of the cursor when '?' is typed. */
549int
ajsb1aa1472005-01-28 21:11:46 +0000550vtysh_rl_describe (void)
paul718e3742002-12-13 20:15:29 +0000551{
552 int ret;
hassodda09522004-10-07 21:40:25 +0000553 unsigned int i;
paul718e3742002-12-13 20:15:29 +0000554 vector vline;
555 vector describe;
556 int width;
557 struct desc *desc;
558
559 vline = cmd_make_strvec (rl_line_buffer);
560
561 /* In case of '> ?'. */
562 if (vline == NULL)
563 {
564 vline = vector_init (1);
565 vector_set (vline, '\0');
566 }
567 else
568 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
569 vector_set (vline, '\0');
570
571 describe = cmd_describe_command (vline, vty, &ret);
572
paul4fc01e62002-12-13 20:49:00 +0000573 fprintf (stdout,"\n");
paul718e3742002-12-13 20:15:29 +0000574
575 /* Ambiguous and no match error. */
576 switch (ret)
577 {
578 case CMD_ERR_AMBIGUOUS:
579 cmd_free_strvec (vline);
paul4fc01e62002-12-13 20:49:00 +0000580 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000581 rl_on_new_line ();
582 return 0;
583 break;
584 case CMD_ERR_NO_MATCH:
585 cmd_free_strvec (vline);
paul4fc01e62002-12-13 20:49:00 +0000586 fprintf (stdout,"%% There is no matched command.\n");
paul718e3742002-12-13 20:15:29 +0000587 rl_on_new_line ();
588 return 0;
589 break;
590 }
591
592 /* Get width of command string. */
593 width = 0;
paul55468c82005-03-14 20:19:01 +0000594 for (i = 0; i < vector_active (describe); i++)
paul718e3742002-12-13 20:15:29 +0000595 if ((desc = vector_slot (describe, i)) != NULL)
596 {
597 int len;
598
599 if (desc->cmd[0] == '\0')
600 continue;
601
602 len = strlen (desc->cmd);
603 if (desc->cmd[0] == '.')
604 len--;
605
606 if (width < len)
607 width = len;
608 }
609
paul55468c82005-03-14 20:19:01 +0000610 for (i = 0; i < vector_active (describe); i++)
paul718e3742002-12-13 20:15:29 +0000611 if ((desc = vector_slot (describe, i)) != NULL)
612 {
613 if (desc->cmd[0] == '\0')
614 continue;
615
616 if (! desc->str)
paul4fc01e62002-12-13 20:49:00 +0000617 fprintf (stdout," %-s\n",
hassob094d262004-08-25 12:22:00 +0000618 desc->cmd[0] == '.' ? desc->cmd + 1 : desc->cmd);
paul718e3742002-12-13 20:15:29 +0000619 else
paul4fc01e62002-12-13 20:49:00 +0000620 fprintf (stdout," %-*s %s\n",
hassob094d262004-08-25 12:22:00 +0000621 width,
622 desc->cmd[0] == '.' ? desc->cmd + 1 : desc->cmd,
623 desc->str);
paul718e3742002-12-13 20:15:29 +0000624 }
625
626 cmd_free_strvec (vline);
627 vector_free (describe);
628
629 rl_on_new_line();
630
631 return 0;
632}
633
hasso95e735b2004-08-26 13:08:30 +0000634/* Result of cmd_complete_command() call will be stored here
635 * and used in new_completion() in order to put the space in
636 * correct places only. */
paul718e3742002-12-13 20:15:29 +0000637int complete_status;
638
ajs274a4a42004-12-07 15:39:31 +0000639static char *
pauldfc0d9b2003-04-18 23:55:29 +0000640command_generator (const char *text, int state)
paul718e3742002-12-13 20:15:29 +0000641{
642 vector vline;
643 static char **matched = NULL;
644 static int index = 0;
645
646 /* First call. */
647 if (! state)
648 {
649 index = 0;
650
651 if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
652 return NULL;
653
654 vline = cmd_make_strvec (rl_line_buffer);
655 if (vline == NULL)
656 return NULL;
657
658 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
659 vector_set (vline, '\0');
660
661 matched = cmd_complete_command (vline, vty, &complete_status);
662 }
663
664 if (matched && matched[index])
665 return matched[index++];
666
667 return NULL;
668}
669
ajs274a4a42004-12-07 15:39:31 +0000670static char **
paul718e3742002-12-13 20:15:29 +0000671new_completion (char *text, int start, int end)
672{
673 char **matches;
674
pauldfc0d9b2003-04-18 23:55:29 +0000675 matches = rl_completion_matches (text, command_generator);
paul718e3742002-12-13 20:15:29 +0000676
677 if (matches)
678 {
679 rl_point = rl_end;
680 if (complete_status == CMD_COMPLETE_FULL_MATCH)
681 rl_pending_input = ' ';
682 }
683
684 return matches;
685}
686
ajs274a4a42004-12-07 15:39:31 +0000687#if 0
688/* This function is not actually being used. */
689static char **
paul718e3742002-12-13 20:15:29 +0000690vtysh_completion (char *text, int start, int end)
691{
692 int ret;
693 vector vline;
694 char **matched = NULL;
695
696 if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
697 return NULL;
698
699 vline = cmd_make_strvec (rl_line_buffer);
700 if (vline == NULL)
701 return NULL;
702
703 /* In case of 'help \t'. */
704 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
705 vector_set (vline, '\0');
706
707 matched = cmd_complete_command (vline, vty, &ret);
708
709 cmd_free_strvec (vline);
710
711 return (char **) matched;
712}
ajs274a4a42004-12-07 15:39:31 +0000713#endif
paul718e3742002-12-13 20:15:29 +0000714
hasso95e735b2004-08-26 13:08:30 +0000715/* Vty node structures. */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800716static struct cmd_node bgp_node =
paul718e3742002-12-13 20:15:29 +0000717{
718 BGP_NODE,
719 "%s(config-router)# ",
720};
721
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800722static struct cmd_node rip_node =
paul718e3742002-12-13 20:15:29 +0000723{
724 RIP_NODE,
725 "%s(config-router)# ",
726};
727
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800728static struct cmd_node isis_node =
hassoc25e4582003-12-23 10:39:08 +0000729{
730 ISIS_NODE,
731 "%s(config-router)# ",
hassoc25e4582003-12-23 10:39:08 +0000732};
733
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800734static struct cmd_node interface_node =
paul718e3742002-12-13 20:15:29 +0000735{
736 INTERFACE_NODE,
737 "%s(config-if)# ",
738};
739
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800740static struct cmd_node rmap_node =
hasso95e735b2004-08-26 13:08:30 +0000741{
742 RMAP_NODE,
743 "%s(config-route-map)# "
744};
745
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800746static struct cmd_node zebra_node =
hasso95e735b2004-08-26 13:08:30 +0000747{
748 ZEBRA_NODE,
749 "%s(config-router)# "
750};
751
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800752static struct cmd_node bgp_vpnv4_node =
hasso95e735b2004-08-26 13:08:30 +0000753{
754 BGP_VPNV4_NODE,
755 "%s(config-router-af)# "
756};
757
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800758static struct cmd_node bgp_ipv4_node =
hasso95e735b2004-08-26 13:08:30 +0000759{
760 BGP_IPV4_NODE,
761 "%s(config-router-af)# "
762};
763
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800764static struct cmd_node bgp_ipv4m_node =
hasso95e735b2004-08-26 13:08:30 +0000765{
766 BGP_IPV4M_NODE,
767 "%s(config-router-af)# "
768};
769
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800770static struct cmd_node bgp_ipv6_node =
hasso95e735b2004-08-26 13:08:30 +0000771{
772 BGP_IPV6_NODE,
773 "%s(config-router-af)# "
774};
775
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800776static struct cmd_node bgp_ipv6m_node =
paul57b5b7e2005-08-22 22:44:29 +0000777{
778 BGP_IPV6M_NODE,
779 "%s(config-router-af)# "
780};
781
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800782static struct cmd_node ospf_node =
hasso95e735b2004-08-26 13:08:30 +0000783{
784 OSPF_NODE,
785 "%s(config-router)# "
786};
787
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800788static struct cmd_node ripng_node =
hasso95e735b2004-08-26 13:08:30 +0000789{
790 RIPNG_NODE,
791 "%s(config-router)# "
792};
793
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800794static struct cmd_node ospf6_node =
hasso95e735b2004-08-26 13:08:30 +0000795{
796 OSPF6_NODE,
797 "%s(config-ospf6)# "
798};
799
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800800static struct cmd_node keychain_node =
hasso95e735b2004-08-26 13:08:30 +0000801{
802 KEYCHAIN_NODE,
803 "%s(config-keychain)# "
804};
805
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800806static struct cmd_node keychain_key_node =
hasso95e735b2004-08-26 13:08:30 +0000807{
808 KEYCHAIN_KEY_NODE,
809 "%s(config-keychain-key)# "
810};
811
hassoe7168df2004-10-03 20:11:32 +0000812/* Defined in lib/vty.c */
813extern struct cmd_node vty_node;
814
hasso95e735b2004-08-26 13:08:30 +0000815/* When '^Z' is received from vty, move down to the enable mode. */
816int
ajsb1aa1472005-01-28 21:11:46 +0000817vtysh_end (void)
hasso95e735b2004-08-26 13:08:30 +0000818{
819 switch (vty->node)
820 {
821 case VIEW_NODE:
822 case ENABLE_NODE:
823 /* Nothing to do. */
824 break;
825 default:
826 vty->node = ENABLE_NODE;
827 break;
828 }
829 return CMD_SUCCESS;
830}
831
832DEFUNSH (VTYSH_ALL,
833 vtysh_end_all,
834 vtysh_end_all_cmd,
835 "end",
hassoe7168df2004-10-03 20:11:32 +0000836 "End current mode and change to enable mode\n")
hasso95e735b2004-08-26 13:08:30 +0000837{
hasso42895462004-09-26 16:25:07 +0000838 return vtysh_end ();
hasso95e735b2004-08-26 13:08:30 +0000839}
840
paul718e3742002-12-13 20:15:29 +0000841DEFUNSH (VTYSH_BGPD,
842 router_bgp,
843 router_bgp_cmd,
Paul Jakma320da872008-07-02 13:40:33 +0000844 "router bgp " CMD_AS_RANGE,
paul718e3742002-12-13 20:15:29 +0000845 ROUTER_STR
846 BGP_STR
847 AS_STR)
848{
849 vty->node = BGP_NODE;
850 return CMD_SUCCESS;
851}
852
Paul Jakma10895fd2008-07-03 19:34:48 +0000853ALIAS_SH (VTYSH_BGPD,
854 router_bgp,
855 router_bgp_view_cmd,
856 "router bgp " CMD_AS_RANGE " view WORD",
857 ROUTER_STR
858 BGP_STR
859 AS_STR
860 "BGP view\n"
861 "view name\n")
862
paul718e3742002-12-13 20:15:29 +0000863DEFUNSH (VTYSH_BGPD,
864 address_family_vpnv4,
865 address_family_vpnv4_cmd,
866 "address-family vpnv4",
867 "Enter Address Family command mode\n"
868 "Address family\n")
869{
870 vty->node = BGP_VPNV4_NODE;
871 return CMD_SUCCESS;
872}
873
874DEFUNSH (VTYSH_BGPD,
875 address_family_vpnv4_unicast,
876 address_family_vpnv4_unicast_cmd,
877 "address-family vpnv4 unicast",
878 "Enter Address Family command mode\n"
879 "Address family\n"
880 "Address Family Modifier\n")
881{
882 vty->node = BGP_VPNV4_NODE;
883 return CMD_SUCCESS;
884}
885
886DEFUNSH (VTYSH_BGPD,
887 address_family_ipv4_unicast,
888 address_family_ipv4_unicast_cmd,
889 "address-family ipv4 unicast",
890 "Enter Address Family command mode\n"
891 "Address family\n"
892 "Address Family Modifier\n")
893{
894 vty->node = BGP_IPV4_NODE;
895 return CMD_SUCCESS;
896}
897
898DEFUNSH (VTYSH_BGPD,
899 address_family_ipv4_multicast,
900 address_family_ipv4_multicast_cmd,
901 "address-family ipv4 multicast",
902 "Enter Address Family command mode\n"
903 "Address family\n"
904 "Address Family Modifier\n")
905{
906 vty->node = BGP_IPV4M_NODE;
907 return CMD_SUCCESS;
908}
909
910DEFUNSH (VTYSH_BGPD,
911 address_family_ipv6,
912 address_family_ipv6_cmd,
913 "address-family ipv6",
914 "Enter Address Family command mode\n"
915 "Address family\n")
916{
917 vty->node = BGP_IPV6_NODE;
918 return CMD_SUCCESS;
919}
920
921DEFUNSH (VTYSH_BGPD,
922 address_family_ipv6_unicast,
923 address_family_ipv6_unicast_cmd,
924 "address-family ipv6 unicast",
925 "Enter Address Family command mode\n"
926 "Address family\n"
927 "Address Family Modifier\n")
928{
929 vty->node = BGP_IPV6_NODE;
930 return CMD_SUCCESS;
931}
932
paul57b5b7e2005-08-22 22:44:29 +0000933DEFUNSH (VTYSH_BGPD,
934 address_family_ipv6_multicast,
935 address_family_ipv6_multicast_cmd,
936 "address-family ipv6 multicast",
937 "Enter Address Family command mode\n"
938 "Address family\n"
939 "Address Family Modifier\n")
940{
941 vty->node = BGP_IPV6M_NODE;
942 return CMD_SUCCESS;
943}
944
paul718e3742002-12-13 20:15:29 +0000945DEFUNSH (VTYSH_RIPD,
946 key_chain,
947 key_chain_cmd,
948 "key chain WORD",
949 "Authentication key management\n"
950 "Key-chain management\n"
951 "Key-chain name\n")
952{
953 vty->node = KEYCHAIN_NODE;
954 return CMD_SUCCESS;
955}
956
957DEFUNSH (VTYSH_RIPD,
958 key,
959 key_cmd,
960 "key <0-2147483647>",
961 "Configure a key\n"
962 "Key identifier number\n")
963{
964 vty->node = KEYCHAIN_KEY_NODE;
965 return CMD_SUCCESS;
966}
967
968DEFUNSH (VTYSH_RIPD,
969 router_rip,
970 router_rip_cmd,
971 "router rip",
972 ROUTER_STR
973 "RIP")
974{
975 vty->node = RIP_NODE;
976 return CMD_SUCCESS;
977}
978
979DEFUNSH (VTYSH_RIPNGD,
980 router_ripng,
981 router_ripng_cmd,
982 "router ripng",
983 ROUTER_STR
984 "RIPng")
985{
986 vty->node = RIPNG_NODE;
987 return CMD_SUCCESS;
988}
989
990DEFUNSH (VTYSH_OSPFD,
991 router_ospf,
992 router_ospf_cmd,
993 "router ospf",
994 "Enable a routing process\n"
995 "Start OSPF configuration\n")
996{
997 vty->node = OSPF_NODE;
998 return CMD_SUCCESS;
999}
1000
1001DEFUNSH (VTYSH_OSPF6D,
1002 router_ospf6,
1003 router_ospf6_cmd,
1004 "router ospf6",
1005 OSPF6_ROUTER_STR
1006 OSPF6_STR)
1007{
1008 vty->node = OSPF6_NODE;
1009 return CMD_SUCCESS;
1010}
1011
hassoc25e4582003-12-23 10:39:08 +00001012DEFUNSH (VTYSH_ISISD,
hassob094d262004-08-25 12:22:00 +00001013 router_isis,
1014 router_isis_cmd,
1015 "router isis WORD",
1016 ROUTER_STR
1017 "ISO IS-IS\n"
1018 "ISO Routing area tag")
hassoc25e4582003-12-23 10:39:08 +00001019{
1020 vty->node = ISIS_NODE;
1021 return CMD_SUCCESS;
1022}
1023
paul718e3742002-12-13 20:15:29 +00001024DEFUNSH (VTYSH_RMAP,
1025 route_map,
1026 route_map_cmd,
1027 "route-map WORD (deny|permit) <1-65535>",
1028 "Create route-map or enter route-map command mode\n"
1029 "Route map tag\n"
1030 "Route map denies set operations\n"
1031 "Route map permits set operations\n"
1032 "Sequence to insert to/delete from existing route-map entry\n")
1033{
1034 vty->node = RMAP_NODE;
1035 return CMD_SUCCESS;
1036}
1037
paul718e3742002-12-13 20:15:29 +00001038DEFUNSH (VTYSH_ALL,
hassoe7168df2004-10-03 20:11:32 +00001039 vtysh_line_vty,
1040 vtysh_line_vty_cmd,
1041 "line vty",
1042 "Configure a terminal line\n"
1043 "Virtual terminal\n")
1044{
1045 vty->node = VTY_NODE;
1046 return CMD_SUCCESS;
1047}
1048
1049DEFUNSH (VTYSH_ALL,
paul718e3742002-12-13 20:15:29 +00001050 vtysh_enable,
1051 vtysh_enable_cmd,
1052 "enable",
1053 "Turn on privileged mode command\n")
1054{
1055 vty->node = ENABLE_NODE;
1056 return CMD_SUCCESS;
1057}
1058
paul718e3742002-12-13 20:15:29 +00001059DEFUNSH (VTYSH_ALL,
1060 vtysh_disable,
1061 vtysh_disable_cmd,
1062 "disable",
1063 "Turn off privileged mode command\n")
1064{
1065 if (vty->node == ENABLE_NODE)
1066 vty->node = VIEW_NODE;
1067 return CMD_SUCCESS;
1068}
1069
paul718e3742002-12-13 20:15:29 +00001070DEFUNSH (VTYSH_ALL,
1071 vtysh_config_terminal,
1072 vtysh_config_terminal_cmd,
1073 "configure terminal",
1074 "Configuration from vty interface\n"
1075 "Configuration terminal\n")
1076{
1077 vty->node = CONFIG_NODE;
1078 return CMD_SUCCESS;
1079}
1080
ajs274a4a42004-12-07 15:39:31 +00001081static int
paul718e3742002-12-13 20:15:29 +00001082vtysh_exit (struct vty *vty)
1083{
1084 switch (vty->node)
1085 {
1086 case VIEW_NODE:
1087 case ENABLE_NODE:
1088 exit (0);
1089 break;
1090 case CONFIG_NODE:
1091 vty->node = ENABLE_NODE;
1092 break;
1093 case INTERFACE_NODE:
1094 case ZEBRA_NODE:
1095 case BGP_NODE:
1096 case RIP_NODE:
1097 case RIPNG_NODE:
1098 case OSPF_NODE:
1099 case OSPF6_NODE:
hassoc25e4582003-12-23 10:39:08 +00001100 case ISIS_NODE:
paul718e3742002-12-13 20:15:29 +00001101 case MASC_NODE:
1102 case RMAP_NODE:
1103 case VTY_NODE:
1104 case KEYCHAIN_NODE:
hasso2a56df92004-05-09 23:16:40 +00001105 vtysh_execute("end");
1106 vtysh_execute("configure terminal");
paul718e3742002-12-13 20:15:29 +00001107 vty->node = CONFIG_NODE;
1108 break;
1109 case BGP_VPNV4_NODE:
1110 case BGP_IPV4_NODE:
1111 case BGP_IPV4M_NODE:
1112 case BGP_IPV6_NODE:
paul57b5b7e2005-08-22 22:44:29 +00001113 case BGP_IPV6M_NODE:
paul718e3742002-12-13 20:15:29 +00001114 vty->node = BGP_NODE;
1115 break;
1116 case KEYCHAIN_KEY_NODE:
1117 vty->node = KEYCHAIN_NODE;
1118 break;
1119 default:
1120 break;
1121 }
1122 return CMD_SUCCESS;
1123}
1124
1125DEFUNSH (VTYSH_ALL,
1126 vtysh_exit_all,
1127 vtysh_exit_all_cmd,
1128 "exit",
1129 "Exit current mode and down to previous mode\n")
1130{
1131 return vtysh_exit (vty);
1132}
1133
1134ALIAS (vtysh_exit_all,
1135 vtysh_quit_all_cmd,
1136 "quit",
1137 "Exit current mode and down to previous mode\n")
1138
1139DEFUNSH (VTYSH_BGPD,
1140 exit_address_family,
1141 exit_address_family_cmd,
1142 "exit-address-family",
1143 "Exit from Address Family configuration mode\n")
1144{
1145 if (vty->node == BGP_IPV4_NODE
1146 || vty->node == BGP_IPV4M_NODE
1147 || vty->node == BGP_VPNV4_NODE
paul57b5b7e2005-08-22 22:44:29 +00001148 || vty->node == BGP_IPV6_NODE
1149 || vty->node == BGP_IPV6M_NODE)
paul718e3742002-12-13 20:15:29 +00001150 vty->node = BGP_NODE;
1151 return CMD_SUCCESS;
1152}
1153
1154DEFUNSH (VTYSH_ZEBRA,
1155 vtysh_exit_zebra,
1156 vtysh_exit_zebra_cmd,
1157 "exit",
1158 "Exit current mode and down to previous mode\n")
1159{
1160 return vtysh_exit (vty);
1161}
1162
1163ALIAS (vtysh_exit_zebra,
1164 vtysh_quit_zebra_cmd,
1165 "quit",
1166 "Exit current mode and down to previous mode\n")
1167
1168DEFUNSH (VTYSH_RIPD,
1169 vtysh_exit_ripd,
1170 vtysh_exit_ripd_cmd,
1171 "exit",
1172 "Exit current mode and down to previous mode\n")
1173{
1174 return vtysh_exit (vty);
1175}
1176
1177ALIAS (vtysh_exit_ripd,
1178 vtysh_quit_ripd_cmd,
1179 "quit",
1180 "Exit current mode and down to previous mode\n")
1181
paul68980082003-03-25 05:07:42 +00001182DEFUNSH (VTYSH_RIPNGD,
hassob094d262004-08-25 12:22:00 +00001183 vtysh_exit_ripngd,
1184 vtysh_exit_ripngd_cmd,
1185 "exit",
1186 "Exit current mode and down to previous mode\n")
paul68980082003-03-25 05:07:42 +00001187{
1188 return vtysh_exit (vty);
1189}
1190
1191ALIAS (vtysh_exit_ripngd,
1192 vtysh_quit_ripngd_cmd,
1193 "quit",
1194 "Exit current mode and down to previous mode\n")
1195
paul718e3742002-12-13 20:15:29 +00001196DEFUNSH (VTYSH_RMAP,
1197 vtysh_exit_rmap,
1198 vtysh_exit_rmap_cmd,
1199 "exit",
1200 "Exit current mode and down to previous mode\n")
1201{
1202 return vtysh_exit (vty);
1203}
1204
1205ALIAS (vtysh_exit_rmap,
1206 vtysh_quit_rmap_cmd,
1207 "quit",
1208 "Exit current mode and down to previous mode\n")
1209
1210DEFUNSH (VTYSH_BGPD,
1211 vtysh_exit_bgpd,
1212 vtysh_exit_bgpd_cmd,
1213 "exit",
1214 "Exit current mode and down to previous mode\n")
1215{
1216 return vtysh_exit (vty);
1217}
1218
1219ALIAS (vtysh_exit_bgpd,
1220 vtysh_quit_bgpd_cmd,
1221 "quit",
1222 "Exit current mode and down to previous mode\n")
1223
1224DEFUNSH (VTYSH_OSPFD,
1225 vtysh_exit_ospfd,
1226 vtysh_exit_ospfd_cmd,
1227 "exit",
1228 "Exit current mode and down to previous mode\n")
1229{
1230 return vtysh_exit (vty);
1231}
1232
1233ALIAS (vtysh_exit_ospfd,
1234 vtysh_quit_ospfd_cmd,
1235 "quit",
1236 "Exit current mode and down to previous mode\n")
1237
paul68980082003-03-25 05:07:42 +00001238DEFUNSH (VTYSH_OSPF6D,
hassob094d262004-08-25 12:22:00 +00001239 vtysh_exit_ospf6d,
1240 vtysh_exit_ospf6d_cmd,
1241 "exit",
1242 "Exit current mode and down to previous mode\n")
paul68980082003-03-25 05:07:42 +00001243{
1244 return vtysh_exit (vty);
1245}
1246
1247ALIAS (vtysh_exit_ospf6d,
1248 vtysh_quit_ospf6d_cmd,
1249 "quit",
1250 "Exit current mode and down to previous mode\n")
1251
hassoc25e4582003-12-23 10:39:08 +00001252DEFUNSH (VTYSH_ISISD,
hassob094d262004-08-25 12:22:00 +00001253 vtysh_exit_isisd,
1254 vtysh_exit_isisd_cmd,
1255 "exit",
1256 "Exit current mode and down to previous mode\n")
hassoc25e4582003-12-23 10:39:08 +00001257{
1258 return vtysh_exit (vty);
1259}
1260
1261ALIAS (vtysh_exit_isisd,
1262 vtysh_quit_isisd_cmd,
1263 "quit",
1264 "Exit current mode and down to previous mode\n")
1265
hassoe7168df2004-10-03 20:11:32 +00001266DEFUNSH (VTYSH_ALL,
1267 vtysh_exit_line_vty,
1268 vtysh_exit_line_vty_cmd,
1269 "exit",
1270 "Exit current mode and down to previous mode\n")
1271{
1272 return vtysh_exit (vty);
1273}
1274
1275ALIAS (vtysh_exit_line_vty,
1276 vtysh_quit_line_vty_cmd,
1277 "quit",
1278 "Exit current mode and down to previous mode\n")
1279
hasso95e735b2004-08-26 13:08:30 +00001280DEFUNSH (VTYSH_INTERFACE,
paul718e3742002-12-13 20:15:29 +00001281 vtysh_interface,
1282 vtysh_interface_cmd,
1283 "interface IFNAME",
1284 "Select an interface to configure\n"
1285 "Interface's name\n")
1286{
1287 vty->node = INTERFACE_NODE;
1288 return CMD_SUCCESS;
1289}
1290
hasso95e735b2004-08-26 13:08:30 +00001291/* TODO Implement "no interface command in isisd. */
paul32d24632003-05-23 09:25:20 +00001292DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D,
1293 vtysh_no_interface_cmd,
1294 "no interface IFNAME",
1295 NO_STR
1296 "Delete a pseudo interface's configuration\n"
1297 "Interface's name\n")
1298
hasso95e735b2004-08-26 13:08:30 +00001299/* TODO Implement interface description commands in ripngd, ospf6d
1300 * and isisd. */
paul338a9912003-03-01 15:44:10 +00001301DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1302 interface_desc_cmd,
1303 "description .LINE",
1304 "Interface specific description\n"
1305 "Characters describing this interface\n")
paul464dc8d2003-03-28 02:25:45 +00001306
1307DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1308 no_interface_desc_cmd,
1309 "no description",
1310 NO_STR
1311 "Interface specific description\n")
paul338a9912003-03-01 15:44:10 +00001312
hasso95e735b2004-08-26 13:08:30 +00001313DEFUNSH (VTYSH_INTERFACE,
paul718e3742002-12-13 20:15:29 +00001314 vtysh_exit_interface,
1315 vtysh_exit_interface_cmd,
1316 "exit",
1317 "Exit current mode and down to previous mode\n")
1318{
1319 return vtysh_exit (vty);
1320}
1321
1322ALIAS (vtysh_exit_interface,
1323 vtysh_quit_interface_cmd,
1324 "quit",
1325 "Exit current mode and down to previous mode\n")
1326
Paul Jakma362b4032006-05-28 07:54:45 +00001327/* Memory */
1328DEFUN (vtysh_show_memory,
1329 vtysh_show_memory_cmd,
1330 "show memory",
1331 SHOW_STR
1332 "Memory statistics\n")
1333{
1334 unsigned int i;
1335 int ret = CMD_SUCCESS;
1336 char line[] = "show memory\n";
1337
1338 for (i = 0; i < VTYSH_INDEX_MAX; i++)
1339 if ( vtysh_client[i].fd >= 0 )
1340 {
1341 fprintf (stdout, "Memory statistics for %s:\n",
1342 vtysh_client[i].name);
1343 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1344 fprintf (stdout,"\n");
1345 }
1346
1347 return ret;
1348}
1349
hasso95e735b2004-08-26 13:08:30 +00001350/* Logging commands. */
Paul Jakmadbf7d132006-05-23 22:10:01 +00001351DEFUN (vtysh_show_logging,
1352 vtysh_show_logging_cmd,
1353 "show logging",
1354 SHOW_STR
1355 "Show current logging configuration\n")
1356{
1357 unsigned int i;
1358 int ret = CMD_SUCCESS;
1359 char line[] = "show logging\n";
1360
1361 for (i = 0; i < VTYSH_INDEX_MAX; i++)
Paul Jakma4150f332006-05-23 22:10:55 +00001362 if ( vtysh_client[i].fd >= 0 )
1363 {
1364 fprintf (stdout,"Logging configuration for %s:\n",
1365 vtysh_client[i].name);
1366 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1367 fprintf (stdout,"\n");
1368 }
1369
Paul Jakmadbf7d132006-05-23 22:10:01 +00001370 return ret;
1371}
1372
hasso95e735b2004-08-26 13:08:30 +00001373DEFUNSH (VTYSH_ALL,
1374 vtysh_log_stdout,
1375 vtysh_log_stdout_cmd,
1376 "log stdout",
1377 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001378 "Set stdout logging level\n")
1379{
1380 return CMD_SUCCESS;
1381}
1382
1383DEFUNSH (VTYSH_ALL,
1384 vtysh_log_stdout_level,
1385 vtysh_log_stdout_level_cmd,
1386 "log stdout "LOG_LEVELS,
1387 "Logging control\n"
1388 "Set stdout logging level\n"
1389 LOG_LEVEL_DESC)
hasso95e735b2004-08-26 13:08:30 +00001390{
1391 return CMD_SUCCESS;
1392}
1393
1394DEFUNSH (VTYSH_ALL,
1395 no_vtysh_log_stdout,
1396 no_vtysh_log_stdout_cmd,
ajs274a4a42004-12-07 15:39:31 +00001397 "no log stdout [LEVEL]",
hasso95e735b2004-08-26 13:08:30 +00001398 NO_STR
1399 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001400 "Cancel logging to stdout\n"
1401 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001402{
1403 return CMD_SUCCESS;
1404}
1405
1406DEFUNSH (VTYSH_ALL,
1407 vtysh_log_file,
1408 vtysh_log_file_cmd,
1409 "log file FILENAME",
1410 "Logging control\n"
1411 "Logging to file\n"
1412 "Logging filename\n")
1413{
1414 return CMD_SUCCESS;
1415}
1416
1417DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001418 vtysh_log_file_level,
1419 vtysh_log_file_level_cmd,
1420 "log file FILENAME "LOG_LEVELS,
1421 "Logging control\n"
1422 "Logging to file\n"
1423 "Logging filename\n"
1424 LOG_LEVEL_DESC)
1425{
1426 return CMD_SUCCESS;
1427}
1428
1429DEFUNSH (VTYSH_ALL,
hasso95e735b2004-08-26 13:08:30 +00001430 no_vtysh_log_file,
1431 no_vtysh_log_file_cmd,
1432 "no log file [FILENAME]",
1433 NO_STR
1434 "Logging control\n"
1435 "Cancel logging to file\n"
1436 "Logging file name\n")
1437{
1438 return CMD_SUCCESS;
1439}
1440
ajs274a4a42004-12-07 15:39:31 +00001441ALIAS_SH (VTYSH_ALL,
1442 no_vtysh_log_file,
1443 no_vtysh_log_file_level_cmd,
1444 "no log file FILENAME LEVEL",
1445 NO_STR
1446 "Logging control\n"
1447 "Cancel logging to file\n"
1448 "Logging file name\n"
1449 "Logging level\n")
1450
1451DEFUNSH (VTYSH_ALL,
1452 vtysh_log_monitor,
1453 vtysh_log_monitor_cmd,
1454 "log monitor",
1455 "Logging control\n"
1456 "Set terminal line (monitor) logging level\n")
1457{
1458 return CMD_SUCCESS;
1459}
1460
1461DEFUNSH (VTYSH_ALL,
1462 vtysh_log_monitor_level,
1463 vtysh_log_monitor_level_cmd,
1464 "log monitor "LOG_LEVELS,
1465 "Logging control\n"
1466 "Set terminal line (monitor) logging level\n"
1467 LOG_LEVEL_DESC)
1468{
1469 return CMD_SUCCESS;
1470}
1471
1472DEFUNSH (VTYSH_ALL,
1473 no_vtysh_log_monitor,
1474 no_vtysh_log_monitor_cmd,
1475 "no log monitor [LEVEL]",
1476 NO_STR
1477 "Logging control\n"
1478 "Disable terminal line (monitor) logging\n"
1479 "Logging level\n")
1480{
1481 return CMD_SUCCESS;
1482}
1483
hasso95e735b2004-08-26 13:08:30 +00001484DEFUNSH (VTYSH_ALL,
1485 vtysh_log_syslog,
1486 vtysh_log_syslog_cmd,
1487 "log syslog",
1488 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001489 "Set syslog logging level\n")
1490{
1491 return CMD_SUCCESS;
1492}
1493
1494DEFUNSH (VTYSH_ALL,
1495 vtysh_log_syslog_level,
1496 vtysh_log_syslog_level_cmd,
1497 "log syslog "LOG_LEVELS,
1498 "Logging control\n"
1499 "Set syslog logging level\n"
1500 LOG_LEVEL_DESC)
hasso95e735b2004-08-26 13:08:30 +00001501{
1502 return CMD_SUCCESS;
1503}
1504
1505DEFUNSH (VTYSH_ALL,
1506 no_vtysh_log_syslog,
1507 no_vtysh_log_syslog_cmd,
ajs274a4a42004-12-07 15:39:31 +00001508 "no log syslog [LEVEL]",
hasso95e735b2004-08-26 13:08:30 +00001509 NO_STR
1510 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001511 "Cancel logging to syslog\n"
1512 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001513{
1514 return CMD_SUCCESS;
1515}
1516
1517DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001518 vtysh_log_facility,
1519 vtysh_log_facility_cmd,
1520 "log facility "LOG_FACILITIES,
hasso95e735b2004-08-26 13:08:30 +00001521 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001522 "Facility parameter for syslog messages\n"
1523 LOG_FACILITY_DESC)
1524
hasso95e735b2004-08-26 13:08:30 +00001525{
1526 return CMD_SUCCESS;
1527}
1528
1529DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001530 no_vtysh_log_facility,
1531 no_vtysh_log_facility_cmd,
1532 "no log facility [FACILITY]",
hasso95e735b2004-08-26 13:08:30 +00001533 NO_STR
1534 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001535 "Reset syslog facility to default (daemon)\n"
1536 "Syslog facility\n")
1537
1538{
1539 return CMD_SUCCESS;
1540}
1541
1542DEFUNSH_DEPRECATED (VTYSH_ALL,
1543 vtysh_log_trap,
1544 vtysh_log_trap_cmd,
1545 "log trap "LOG_LEVELS,
1546 "Logging control\n"
1547 "(Deprecated) Set logging level and default for all destinations\n"
1548 LOG_LEVEL_DESC)
1549
1550{
1551 return CMD_SUCCESS;
1552}
1553
1554DEFUNSH_DEPRECATED (VTYSH_ALL,
1555 no_vtysh_log_trap,
1556 no_vtysh_log_trap_cmd,
1557 "no log trap [LEVEL]",
1558 NO_STR
1559 "Logging control\n"
1560 "Permit all logging information\n"
1561 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001562{
1563 return CMD_SUCCESS;
1564}
1565
1566DEFUNSH (VTYSH_ALL,
1567 vtysh_log_record_priority,
1568 vtysh_log_record_priority_cmd,
1569 "log record-priority",
1570 "Logging control\n"
1571 "Log the priority of the message within the message\n")
1572{
1573 return CMD_SUCCESS;
1574}
1575
1576DEFUNSH (VTYSH_ALL,
1577 no_vtysh_log_record_priority,
1578 no_vtysh_log_record_priority_cmd,
1579 "no log record-priority",
1580 NO_STR
1581 "Logging control\n"
1582 "Do not log the priority of the message within the message\n")
1583{
1584 return CMD_SUCCESS;
1585}
1586
hassoe7168df2004-10-03 20:11:32 +00001587DEFUNSH (VTYSH_ALL,
Andrew J. Schorrc749b722007-04-29 03:53:31 +00001588 vtysh_log_timestamp_precision,
1589 vtysh_log_timestamp_precision_cmd,
1590 "log timestamp precision <0-6>",
1591 "Logging control\n"
1592 "Timestamp configuration\n"
1593 "Set the timestamp precision\n"
1594 "Number of subsecond digits\n")
1595{
1596 return CMD_SUCCESS;
1597}
1598
1599DEFUNSH (VTYSH_ALL,
1600 no_vtysh_log_timestamp_precision,
1601 no_vtysh_log_timestamp_precision_cmd,
1602 "no log timestamp precision",
1603 NO_STR
1604 "Logging control\n"
1605 "Timestamp configuration\n"
1606 "Reset the timestamp precision to the default value of 0\n")
1607{
1608 return CMD_SUCCESS;
1609}
1610
1611DEFUNSH (VTYSH_ALL,
hassoe7168df2004-10-03 20:11:32 +00001612 vtysh_service_password_encrypt,
1613 vtysh_service_password_encrypt_cmd,
1614 "service password-encryption",
1615 "Set up miscellaneous service\n"
1616 "Enable encrypted passwords\n")
1617{
1618 return CMD_SUCCESS;
1619}
1620
1621DEFUNSH (VTYSH_ALL,
1622 no_vtysh_service_password_encrypt,
1623 no_vtysh_service_password_encrypt_cmd,
1624 "no service password-encryption",
1625 NO_STR
1626 "Set up miscellaneous service\n"
1627 "Enable encrypted passwords\n")
1628{
1629 return CMD_SUCCESS;
1630}
1631
1632DEFUNSH (VTYSH_ALL,
1633 vtysh_config_password,
1634 vtysh_password_cmd,
1635 "password (8|) WORD",
1636 "Assign the terminal connection password\n"
1637 "Specifies a HIDDEN password will follow\n"
1638 "dummy string \n"
1639 "The HIDDEN line password string\n")
1640{
1641 return CMD_SUCCESS;
1642}
1643
1644DEFUNSH (VTYSH_ALL,
1645 vtysh_password_text,
1646 vtysh_password_text_cmd,
1647 "password LINE",
1648 "Assign the terminal connection password\n"
1649 "The UNENCRYPTED (cleartext) line password\n")
1650{
1651 return CMD_SUCCESS;
1652}
1653
1654DEFUNSH (VTYSH_ALL,
1655 vtysh_config_enable_password,
1656 vtysh_enable_password_cmd,
1657 "enable password (8|) WORD",
1658 "Modify enable password parameters\n"
1659 "Assign the privileged level password\n"
1660 "Specifies a HIDDEN password will follow\n"
1661 "dummy string \n"
1662 "The HIDDEN 'enable' password string\n")
1663{
1664 return CMD_SUCCESS;
1665}
1666
1667DEFUNSH (VTYSH_ALL,
1668 vtysh_enable_password_text,
1669 vtysh_enable_password_text_cmd,
1670 "enable password LINE",
1671 "Modify enable password parameters\n"
1672 "Assign the privileged level password\n"
1673 "The UNENCRYPTED (cleartext) 'enable' password\n")
1674{
1675 return CMD_SUCCESS;
1676}
1677
1678DEFUNSH (VTYSH_ALL,
1679 no_vtysh_config_enable_password,
1680 no_vtysh_enable_password_cmd,
1681 "no enable password",
1682 NO_STR
1683 "Modify enable password parameters\n"
1684 "Assign the privileged level password\n")
1685{
1686 return CMD_SUCCESS;
1687}
1688
paul718e3742002-12-13 20:15:29 +00001689DEFUN (vtysh_write_terminal,
1690 vtysh_write_terminal_cmd,
1691 "write terminal",
1692 "Write running configuration to memory, network, or terminal\n"
1693 "Write to terminal\n")
1694{
ajsb1aa1472005-01-28 21:11:46 +00001695 u_int i;
paul718e3742002-12-13 20:15:29 +00001696 int ret;
1697 char line[] = "write terminal\n";
1698 FILE *fp = NULL;
1699
1700 if (vtysh_pager_name)
1701 {
paul4fc01e62002-12-13 20:49:00 +00001702 fp = popen (vtysh_pager_name, "w");
paul718e3742002-12-13 20:15:29 +00001703 if (fp == NULL)
1704 {
1705 perror ("popen");
1706 exit (1);
1707 }
1708 }
1709 else
1710 fp = stdout;
1711
1712 vty_out (vty, "Building configuration...%s", VTY_NEWLINE);
1713 vty_out (vty, "%sCurrent configuration:%s", VTY_NEWLINE,
1714 VTY_NEWLINE);
hassoe7168df2004-10-03 20:11:32 +00001715 vty_out (vty, "!%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001716
ajsb1aa1472005-01-28 21:11:46 +00001717 for (i = 0; i < VTYSH_INDEX_MAX; i++)
1718 ret = vtysh_client_config (&vtysh_client[i], line);
paul718e3742002-12-13 20:15:29 +00001719
hassoe7168df2004-10-03 20:11:32 +00001720 /* Integrate vtysh specific configuration. */
1721 vtysh_config_write ();
1722
paul718e3742002-12-13 20:15:29 +00001723 vtysh_config_dump (fp);
1724
Paul Jakma8454b052007-06-20 15:22:14 +00001725 vty_out (vty, "end%s", VTY_NEWLINE);
1726
paul718e3742002-12-13 20:15:29 +00001727 if (vtysh_pager_name && fp)
1728 {
1729 fflush (fp);
1730 if (pclose (fp) == -1)
1731 {
1732 perror ("pclose");
1733 exit (1);
1734 }
1735 fp = NULL;
1736 }
1737
1738 return CMD_SUCCESS;
1739}
1740
hassoe7168df2004-10-03 20:11:32 +00001741DEFUN (vtysh_integrated_config,
1742 vtysh_integrated_config_cmd,
1743 "service integrated-vtysh-config",
1744 "Set up miscellaneous service\n"
1745 "Write configuration into integrated file\n")
paul4fc01e62002-12-13 20:49:00 +00001746{
hassoe7168df2004-10-03 20:11:32 +00001747 vtysh_writeconfig_integrated = 1;
1748 return CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001749}
1750
hassoe7168df2004-10-03 20:11:32 +00001751DEFUN (no_vtysh_integrated_config,
1752 no_vtysh_integrated_config_cmd,
1753 "no service integrated-vtysh-config",
1754 NO_STR
1755 "Set up miscellaneous service\n"
1756 "Write configuration into integrated file\n")
paul4fc01e62002-12-13 20:49:00 +00001757{
hassoe7168df2004-10-03 20:11:32 +00001758 vtysh_writeconfig_integrated = 0;
1759 return CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001760}
1761
ajs274a4a42004-12-07 15:39:31 +00001762static int
1763write_config_integrated(void)
paul718e3742002-12-13 20:15:29 +00001764{
ajsb1aa1472005-01-28 21:11:46 +00001765 u_int i;
paul718e3742002-12-13 20:15:29 +00001766 int ret;
paul718e3742002-12-13 20:15:29 +00001767 char line[] = "write terminal\n";
1768 FILE *fp;
1769 char *integrate_sav = NULL;
1770
hasso95e735b2004-08-26 13:08:30 +00001771 integrate_sav = malloc (strlen (integrate_default) +
1772 strlen (CONF_BACKUP_EXT) + 1);
paul718e3742002-12-13 20:15:29 +00001773 strcpy (integrate_sav, integrate_default);
1774 strcat (integrate_sav, CONF_BACKUP_EXT);
1775
paul4fc01e62002-12-13 20:49:00 +00001776 fprintf (stdout,"Building Configuration...\n");
paul718e3742002-12-13 20:15:29 +00001777
hasso95e735b2004-08-26 13:08:30 +00001778 /* Move current configuration file to backup config file. */
paul718e3742002-12-13 20:15:29 +00001779 unlink (integrate_sav);
1780 rename (integrate_default, integrate_sav);
hasso95e735b2004-08-26 13:08:30 +00001781 free (integrate_sav);
paul4fc01e62002-12-13 20:49:00 +00001782
paul718e3742002-12-13 20:15:29 +00001783 fp = fopen (integrate_default, "w");
1784 if (fp == NULL)
1785 {
hasso95e735b2004-08-26 13:08:30 +00001786 fprintf (stdout,"%% Can't open configuration file %s.\n",
1787 integrate_default);
paul718e3742002-12-13 20:15:29 +00001788 return CMD_SUCCESS;
1789 }
paul718e3742002-12-13 20:15:29 +00001790
ajsb1aa1472005-01-28 21:11:46 +00001791 for (i = 0; i < VTYSH_INDEX_MAX; i++)
1792 ret = vtysh_client_config (&vtysh_client[i], line);
paul718e3742002-12-13 20:15:29 +00001793
1794 vtysh_config_dump (fp);
1795
1796 fclose (fp);
1797
gdtaa593d52003-12-22 20:15:53 +00001798 if (chmod (integrate_default, CONFIGFILE_MASK) != 0)
1799 {
1800 fprintf (stdout,"%% Can't chmod configuration file %s: %s (%d)\n",
ajs6099b3b2004-11-20 02:06:59 +00001801 integrate_default, safe_strerror(errno), errno);
gdtaa593d52003-12-22 20:15:53 +00001802 return CMD_WARNING;
1803 }
1804
paul4fc01e62002-12-13 20:49:00 +00001805 fprintf(stdout,"Integrated configuration saved to %s\n",integrate_default);
1806
1807 fprintf (stdout,"[OK]\n");
1808
paul718e3742002-12-13 20:15:29 +00001809 return CMD_SUCCESS;
1810}
1811
paul4fc01e62002-12-13 20:49:00 +00001812DEFUN (vtysh_write_memory,
1813 vtysh_write_memory_cmd,
1814 "write memory",
1815 "Write running configuration to memory, network, or terminal\n"
1816 "Write configuration to the file (same as write file)\n")
1817{
pauldfc0d9b2003-04-18 23:55:29 +00001818 int ret = CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001819 char line[] = "write memory\n";
ajsb1aa1472005-01-28 21:11:46 +00001820 u_int i;
paul4fc01e62002-12-13 20:49:00 +00001821
hassoe7168df2004-10-03 20:11:32 +00001822 /* If integrated Quagga.conf explicitely set. */
1823 if (vtysh_writeconfig_integrated)
1824 return write_config_integrated();
paul4fc01e62002-12-13 20:49:00 +00001825
1826 fprintf (stdout,"Building Configuration...\n");
1827
ajsb1aa1472005-01-28 21:11:46 +00001828 for (i = 0; i < VTYSH_INDEX_MAX; i++)
1829 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
hassoe7168df2004-10-03 20:11:32 +00001830
paul4fc01e62002-12-13 20:49:00 +00001831 fprintf (stdout,"[OK]\n");
1832
pauldfc0d9b2003-04-18 23:55:29 +00001833 return ret;
paul4fc01e62002-12-13 20:49:00 +00001834}
1835
paul718e3742002-12-13 20:15:29 +00001836ALIAS (vtysh_write_memory,
1837 vtysh_copy_runningconfig_startupconfig_cmd,
1838 "copy running-config startup-config",
1839 "Copy from one file to another\n"
1840 "Copy from current system configuration\n"
1841 "Copy to startup configuration\n")
1842
1843ALIAS (vtysh_write_memory,
1844 vtysh_write_file_cmd,
1845 "write file",
1846 "Write running configuration to memory, network, or terminal\n"
1847 "Write configuration to the file (same as write memory)\n")
1848
hasso4a6e2252003-05-25 11:51:29 +00001849ALIAS (vtysh_write_memory,
1850 vtysh_write_cmd,
1851 "write",
1852 "Write running configuration to memory, network, or terminal\n")
1853
paul718e3742002-12-13 20:15:29 +00001854ALIAS (vtysh_write_terminal,
1855 vtysh_show_running_config_cmd,
1856 "show running-config",
1857 SHOW_STR
1858 "Current operating configuration\n")
hassob094d262004-08-25 12:22:00 +00001859
hasso34553cc2004-08-27 13:56:39 +00001860DEFUN (vtysh_terminal_length,
1861 vtysh_terminal_length_cmd,
1862 "terminal length <0-512>",
1863 "Set terminal line parameters\n"
1864 "Set number of lines on a screen\n"
1865 "Number of lines on screen (0 for no pausing)\n")
1866{
1867 int lines;
1868 char *endptr = NULL;
1869 char default_pager[10];
1870
1871 lines = strtol (argv[0], &endptr, 10);
1872 if (lines < 0 || lines > 512 || *endptr != '\0')
1873 {
1874 vty_out (vty, "length is malformed%s", VTY_NEWLINE);
1875 return CMD_WARNING;
1876 }
1877
1878 if (vtysh_pager_name)
1879 {
1880 free (vtysh_pager_name);
1881 vtysh_pager_name = NULL;
1882 }
1883
1884 if (lines != 0)
1885 {
1886 snprintf(default_pager, 10, "more -%i", lines);
1887 vtysh_pager_name = strdup (default_pager);
1888 }
1889
1890 return CMD_SUCCESS;
1891}
1892
1893DEFUN (vtysh_terminal_no_length,
1894 vtysh_terminal_no_length_cmd,
1895 "terminal no length",
1896 "Set terminal line parameters\n"
1897 NO_STR
1898 "Set number of lines on a screen\n")
1899{
1900 if (vtysh_pager_name)
1901 {
1902 free (vtysh_pager_name);
1903 vtysh_pager_name = NULL;
1904 }
1905
1906 vtysh_pager_init();
1907 return CMD_SUCCESS;
1908}
1909
hassof2799e62004-10-28 17:43:11 +00001910DEFUN (vtysh_show_daemons,
1911 vtysh_show_daemons_cmd,
1912 "show daemons",
hassoe7168df2004-10-03 20:11:32 +00001913 SHOW_STR
1914 "Show list of running daemons\n")
1915{
ajsb1aa1472005-01-28 21:11:46 +00001916 u_int i;
1917
1918 for (i = 0; i < VTYSH_INDEX_MAX; i++)
1919 if ( vtysh_client[i].fd >= 0 )
1920 vty_out(vty, " %s", vtysh_client[i].name);
hassoe7168df2004-10-03 20:11:32 +00001921 vty_out(vty, "%s", VTY_NEWLINE);
1922
1923 return CMD_SUCCESS;
1924}
1925
paul718e3742002-12-13 20:15:29 +00001926/* Execute command in child process. */
ajs274a4a42004-12-07 15:39:31 +00001927static int
hasso5862ff52004-10-11 13:20:40 +00001928execute_command (const char *command, int argc, const char *arg1,
1929 const char *arg2)
paul718e3742002-12-13 20:15:29 +00001930{
1931 int ret;
1932 pid_t pid;
1933 int status;
1934
1935 /* Call fork(). */
1936 pid = fork ();
1937
1938 if (pid < 0)
1939 {
1940 /* Failure of fork(). */
ajs6099b3b2004-11-20 02:06:59 +00001941 fprintf (stderr, "Can't fork: %s\n", safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +00001942 exit (1);
1943 }
1944 else if (pid == 0)
1945 {
1946 /* This is child process. */
1947 switch (argc)
1948 {
1949 case 0:
hassofa2b17e2004-03-04 17:45:00 +00001950 ret = execlp (command, command, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00001951 break;
1952 case 1:
hassofa2b17e2004-03-04 17:45:00 +00001953 ret = execlp (command, command, arg1, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00001954 break;
1955 case 2:
hassofa2b17e2004-03-04 17:45:00 +00001956 ret = execlp (command, command, arg1, arg2, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00001957 break;
1958 }
1959
1960 /* When execlp suceed, this part is not executed. */
ajs6099b3b2004-11-20 02:06:59 +00001961 fprintf (stderr, "Can't execute %s: %s\n", command, safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +00001962 exit (1);
1963 }
1964 else
1965 {
1966 /* This is parent. */
1967 execute_flag = 1;
1968 ret = wait4 (pid, &status, 0, NULL);
1969 execute_flag = 0;
1970 }
1971 return 0;
1972}
1973
1974DEFUN (vtysh_ping,
1975 vtysh_ping_cmd,
1976 "ping WORD",
hasso4eeccf12003-06-25 10:49:55 +00001977 "Send echo messages\n"
paul718e3742002-12-13 20:15:29 +00001978 "Ping destination address or hostname\n")
1979{
1980 execute_command ("ping", 1, argv[0], NULL);
1981 return CMD_SUCCESS;
1982}
1983
hasso4eeccf12003-06-25 10:49:55 +00001984ALIAS (vtysh_ping,
1985 vtysh_ping_ip_cmd,
1986 "ping ip WORD",
1987 "Send echo messages\n"
1988 "IP echo\n"
1989 "Ping destination address or hostname\n")
1990
paul718e3742002-12-13 20:15:29 +00001991DEFUN (vtysh_traceroute,
1992 vtysh_traceroute_cmd,
1993 "traceroute WORD",
1994 "Trace route to destination\n"
1995 "Trace route to destination address or hostname\n")
1996{
1997 execute_command ("traceroute", 1, argv[0], NULL);
1998 return CMD_SUCCESS;
1999}
2000
hasso4eeccf12003-06-25 10:49:55 +00002001ALIAS (vtysh_traceroute,
2002 vtysh_traceroute_ip_cmd,
2003 "traceroute ip WORD",
2004 "Trace route to destination\n"
2005 "IP trace\n"
2006 "Trace route to destination address or hostname\n")
2007
2008#ifdef HAVE_IPV6
2009DEFUN (vtysh_ping6,
2010 vtysh_ping6_cmd,
2011 "ping ipv6 WORD",
2012 "Send echo messages\n"
2013 "IPv6 echo\n"
2014 "Ping destination address or hostname\n")
2015{
2016 execute_command ("ping6", 1, argv[0], NULL);
2017 return CMD_SUCCESS;
2018}
2019
2020DEFUN (vtysh_traceroute6,
2021 vtysh_traceroute6_cmd,
2022 "traceroute ipv6 WORD",
2023 "Trace route to destination\n"
2024 "IPv6 trace\n"
2025 "Trace route to destination address or hostname\n")
2026{
2027 execute_command ("traceroute6", 1, argv[0], NULL);
2028 return CMD_SUCCESS;
2029}
2030#endif
2031
paul718e3742002-12-13 20:15:29 +00002032DEFUN (vtysh_telnet,
2033 vtysh_telnet_cmd,
2034 "telnet WORD",
2035 "Open a telnet connection\n"
2036 "IP address or hostname of a remote system\n")
2037{
2038 execute_command ("telnet", 1, argv[0], NULL);
2039 return CMD_SUCCESS;
2040}
2041
2042DEFUN (vtysh_telnet_port,
2043 vtysh_telnet_port_cmd,
2044 "telnet WORD PORT",
2045 "Open a telnet connection\n"
2046 "IP address or hostname of a remote system\n"
2047 "TCP Port number\n")
2048{
2049 execute_command ("telnet", 2, argv[0], argv[1]);
2050 return CMD_SUCCESS;
2051}
2052
paul5087df52003-01-25 06:56:09 +00002053DEFUN (vtysh_ssh,
2054 vtysh_ssh_cmd,
2055 "ssh WORD",
2056 "Open an ssh connection\n"
2057 "[user@]host\n")
2058{
2059 execute_command ("ssh", 1, argv[0], NULL);
2060 return CMD_SUCCESS;
2061}
2062
paul718e3742002-12-13 20:15:29 +00002063DEFUN (vtysh_start_shell,
2064 vtysh_start_shell_cmd,
2065 "start-shell",
2066 "Start UNIX shell\n")
2067{
2068 execute_command ("sh", 0, NULL, NULL);
2069 return CMD_SUCCESS;
2070}
2071
2072DEFUN (vtysh_start_bash,
2073 vtysh_start_bash_cmd,
2074 "start-shell bash",
2075 "Start UNIX shell\n"
2076 "Start bash\n")
2077{
2078 execute_command ("bash", 0, NULL, NULL);
2079 return CMD_SUCCESS;
2080}
2081
2082DEFUN (vtysh_start_zsh,
2083 vtysh_start_zsh_cmd,
2084 "start-shell zsh",
2085 "Start UNIX shell\n"
2086 "Start Z shell\n")
2087{
2088 execute_command ("zsh", 0, NULL, NULL);
2089 return CMD_SUCCESS;
2090}
hassob094d262004-08-25 12:22:00 +00002091
ajs274a4a42004-12-07 15:39:31 +00002092static void
paul718e3742002-12-13 20:15:29 +00002093vtysh_install_default (enum node_type node)
2094{
2095 install_element (node, &config_list_cmd);
2096}
2097
2098/* Making connection to protocol daemon. */
ajs274a4a42004-12-07 15:39:31 +00002099static int
ajsb1aa1472005-01-28 21:11:46 +00002100vtysh_connect (struct vtysh_client *vclient)
paul718e3742002-12-13 20:15:29 +00002101{
2102 int ret;
2103 int sock, len;
2104 struct sockaddr_un addr;
2105 struct stat s_stat;
paul718e3742002-12-13 20:15:29 +00002106
paul718e3742002-12-13 20:15:29 +00002107 /* Stat socket to see if we have permission to access it. */
ajsb1aa1472005-01-28 21:11:46 +00002108 ret = stat (vclient->path, &s_stat);
paul718e3742002-12-13 20:15:29 +00002109 if (ret < 0 && errno != ENOENT)
2110 {
2111 fprintf (stderr, "vtysh_connect(%s): stat = %s\n",
ajsb1aa1472005-01-28 21:11:46 +00002112 vclient->path, safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002113 exit(1);
2114 }
2115
2116 if (ret >= 0)
2117 {
2118 if (! S_ISSOCK(s_stat.st_mode))
2119 {
2120 fprintf (stderr, "vtysh_connect(%s): Not a socket\n",
ajsb1aa1472005-01-28 21:11:46 +00002121 vclient->path);
paul718e3742002-12-13 20:15:29 +00002122 exit (1);
2123 }
2124
paul718e3742002-12-13 20:15:29 +00002125 }
2126
2127 sock = socket (AF_UNIX, SOCK_STREAM, 0);
2128 if (sock < 0)
2129 {
2130#ifdef DEBUG
ajsb1aa1472005-01-28 21:11:46 +00002131 fprintf(stderr, "vtysh_connect(%s): socket = %s\n", vclient->path,
ajs6099b3b2004-11-20 02:06:59 +00002132 safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002133#endif /* DEBUG */
2134 return -1;
2135 }
2136
2137 memset (&addr, 0, sizeof (struct sockaddr_un));
2138 addr.sun_family = AF_UNIX;
ajsb1aa1472005-01-28 21:11:46 +00002139 strncpy (addr.sun_path, vclient->path, strlen (vclient->path));
Paul Jakma6f0e3f62007-05-10 02:38:51 +00002140#ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
paul718e3742002-12-13 20:15:29 +00002141 len = addr.sun_len = SUN_LEN(&addr);
2142#else
2143 len = sizeof (addr.sun_family) + strlen (addr.sun_path);
Paul Jakma6f0e3f62007-05-10 02:38:51 +00002144#endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
paul718e3742002-12-13 20:15:29 +00002145
2146 ret = connect (sock, (struct sockaddr *) &addr, len);
2147 if (ret < 0)
2148 {
2149#ifdef DEBUG
ajsb1aa1472005-01-28 21:11:46 +00002150 fprintf(stderr, "vtysh_connect(%s): connect = %s\n", vclient->path,
ajs6099b3b2004-11-20 02:06:59 +00002151 safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002152#endif /* DEBUG */
2153 close (sock);
2154 return -1;
2155 }
2156 vclient->fd = sock;
2157
2158 return 0;
2159}
2160
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002161int
2162vtysh_connect_all(const char *daemon_name)
paul718e3742002-12-13 20:15:29 +00002163{
ajsb1aa1472005-01-28 21:11:46 +00002164 u_int i;
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002165 int rc = 0;
2166 int matches = 0;
ajsb1aa1472005-01-28 21:11:46 +00002167
2168 for (i = 0; i < VTYSH_INDEX_MAX; i++)
2169 {
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002170 if (!daemon_name || !strcmp(daemon_name, vtysh_client[i].name))
2171 {
2172 matches++;
2173 if (vtysh_connect(&vtysh_client[i]) == 0)
2174 rc++;
2175 /* We need direct access to ripd in vtysh_exit_ripd_only. */
2176 if (vtysh_client[i].flag == VTYSH_RIPD)
2177 ripd_client = &vtysh_client[i];
2178 }
ajsb1aa1472005-01-28 21:11:46 +00002179 }
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002180 if (!matches)
2181 fprintf(stderr, "Error: no daemons match name %s!\n", daemon_name);
2182 return rc;
paul718e3742002-12-13 20:15:29 +00002183}
2184
hasso95e735b2004-08-26 13:08:30 +00002185/* To disable readline's filename completion. */
ajs274a4a42004-12-07 15:39:31 +00002186static char *
pauldfc0d9b2003-04-18 23:55:29 +00002187vtysh_completion_entry_function (const char *ignore, int invoking_key)
paul718e3742002-12-13 20:15:29 +00002188{
pauldfc0d9b2003-04-18 23:55:29 +00002189 return NULL;
paul718e3742002-12-13 20:15:29 +00002190}
2191
2192void
ajsb1aa1472005-01-28 21:11:46 +00002193vtysh_readline_init (void)
paul718e3742002-12-13 20:15:29 +00002194{
2195 /* readline related settings. */
hasso53a6f932005-09-15 06:50:53 +00002196 rl_bind_key ('?', (Function *) vtysh_rl_describe);
paul68980082003-03-25 05:07:42 +00002197 rl_completion_entry_function = vtysh_completion_entry_function;
paul718e3742002-12-13 20:15:29 +00002198 rl_attempted_completion_function = (CPPFunction *)new_completion;
2199 /* do not append space after completion. It will be appended
hasso95e735b2004-08-26 13:08:30 +00002200 * in new_completion() function explicitly. */
paul718e3742002-12-13 20:15:29 +00002201 rl_completion_append_character = '\0';
2202}
2203
2204char *
ajsb1aa1472005-01-28 21:11:46 +00002205vtysh_prompt (void)
paul718e3742002-12-13 20:15:29 +00002206{
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002207 static struct utsname names;
paul718e3742002-12-13 20:15:29 +00002208 static char buf[100];
2209 const char*hostname;
2210 extern struct host host;
2211
2212 hostname = host.name;
2213
2214 if (!hostname)
2215 {
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002216 if (!names.nodename[0])
2217 uname (&names);
paul718e3742002-12-13 20:15:29 +00002218 hostname = names.nodename;
2219 }
2220
2221 snprintf (buf, sizeof buf, cmd_prompt (vty->node), hostname);
2222
2223 return buf;
2224}
2225
2226void
ajsb1aa1472005-01-28 21:11:46 +00002227vtysh_init_vty (void)
paul718e3742002-12-13 20:15:29 +00002228{
2229 /* Make vty structure. */
2230 vty = vty_new ();
2231 vty->type = VTY_SHELL;
2232 vty->node = VIEW_NODE;
2233
2234 /* Initialize commands. */
2235 cmd_init (0);
2236
2237 /* Install nodes. */
2238 install_node (&bgp_node, NULL);
2239 install_node (&rip_node, NULL);
2240 install_node (&interface_node, NULL);
2241 install_node (&rmap_node, NULL);
2242 install_node (&zebra_node, NULL);
2243 install_node (&bgp_vpnv4_node, NULL);
2244 install_node (&bgp_ipv4_node, NULL);
2245 install_node (&bgp_ipv4m_node, NULL);
2246/* #ifdef HAVE_IPV6 */
2247 install_node (&bgp_ipv6_node, NULL);
paul57b5b7e2005-08-22 22:44:29 +00002248 install_node (&bgp_ipv6m_node, NULL);
paul718e3742002-12-13 20:15:29 +00002249/* #endif */
2250 install_node (&ospf_node, NULL);
2251/* #ifdef HAVE_IPV6 */
2252 install_node (&ripng_node, NULL);
2253 install_node (&ospf6_node, NULL);
2254/* #endif */
2255 install_node (&keychain_node, NULL);
2256 install_node (&keychain_key_node, NULL);
hassoc25e4582003-12-23 10:39:08 +00002257 install_node (&isis_node, NULL);
hassoe7168df2004-10-03 20:11:32 +00002258 install_node (&vty_node, NULL);
paul718e3742002-12-13 20:15:29 +00002259
2260 vtysh_install_default (VIEW_NODE);
2261 vtysh_install_default (ENABLE_NODE);
2262 vtysh_install_default (CONFIG_NODE);
2263 vtysh_install_default (BGP_NODE);
2264 vtysh_install_default (RIP_NODE);
2265 vtysh_install_default (INTERFACE_NODE);
2266 vtysh_install_default (RMAP_NODE);
2267 vtysh_install_default (ZEBRA_NODE);
2268 vtysh_install_default (BGP_VPNV4_NODE);
2269 vtysh_install_default (BGP_IPV4_NODE);
2270 vtysh_install_default (BGP_IPV4M_NODE);
2271 vtysh_install_default (BGP_IPV6_NODE);
paul57b5b7e2005-08-22 22:44:29 +00002272 vtysh_install_default (BGP_IPV6M_NODE);
paul718e3742002-12-13 20:15:29 +00002273 vtysh_install_default (OSPF_NODE);
2274 vtysh_install_default (RIPNG_NODE);
2275 vtysh_install_default (OSPF6_NODE);
hassoc25e4582003-12-23 10:39:08 +00002276 vtysh_install_default (ISIS_NODE);
paul718e3742002-12-13 20:15:29 +00002277 vtysh_install_default (KEYCHAIN_NODE);
2278 vtysh_install_default (KEYCHAIN_KEY_NODE);
hassoe7168df2004-10-03 20:11:32 +00002279 vtysh_install_default (VTY_NODE);
paul718e3742002-12-13 20:15:29 +00002280
2281 install_element (VIEW_NODE, &vtysh_enable_cmd);
2282 install_element (ENABLE_NODE, &vtysh_config_terminal_cmd);
2283 install_element (ENABLE_NODE, &vtysh_disable_cmd);
2284
2285 /* "exit" command. */
2286 install_element (VIEW_NODE, &vtysh_exit_all_cmd);
2287 install_element (VIEW_NODE, &vtysh_quit_all_cmd);
2288 install_element (CONFIG_NODE, &vtysh_exit_all_cmd);
2289 /* install_element (CONFIG_NODE, &vtysh_quit_all_cmd); */
2290 install_element (ENABLE_NODE, &vtysh_exit_all_cmd);
2291 install_element (ENABLE_NODE, &vtysh_quit_all_cmd);
2292 install_element (RIP_NODE, &vtysh_exit_ripd_cmd);
2293 install_element (RIP_NODE, &vtysh_quit_ripd_cmd);
paul68980082003-03-25 05:07:42 +00002294 install_element (RIPNG_NODE, &vtysh_exit_ripngd_cmd);
2295 install_element (RIPNG_NODE, &vtysh_quit_ripngd_cmd);
paul718e3742002-12-13 20:15:29 +00002296 install_element (OSPF_NODE, &vtysh_exit_ospfd_cmd);
2297 install_element (OSPF_NODE, &vtysh_quit_ospfd_cmd);
paul68980082003-03-25 05:07:42 +00002298 install_element (OSPF6_NODE, &vtysh_exit_ospf6d_cmd);
2299 install_element (OSPF6_NODE, &vtysh_quit_ospf6d_cmd);
paul718e3742002-12-13 20:15:29 +00002300 install_element (BGP_NODE, &vtysh_exit_bgpd_cmd);
2301 install_element (BGP_NODE, &vtysh_quit_bgpd_cmd);
2302 install_element (BGP_VPNV4_NODE, &vtysh_exit_bgpd_cmd);
2303 install_element (BGP_VPNV4_NODE, &vtysh_quit_bgpd_cmd);
2304 install_element (BGP_IPV4_NODE, &vtysh_exit_bgpd_cmd);
2305 install_element (BGP_IPV4_NODE, &vtysh_quit_bgpd_cmd);
2306 install_element (BGP_IPV4M_NODE, &vtysh_exit_bgpd_cmd);
2307 install_element (BGP_IPV4M_NODE, &vtysh_quit_bgpd_cmd);
2308 install_element (BGP_IPV6_NODE, &vtysh_exit_bgpd_cmd);
2309 install_element (BGP_IPV6_NODE, &vtysh_quit_bgpd_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002310 install_element (BGP_IPV6M_NODE, &vtysh_exit_bgpd_cmd);
2311 install_element (BGP_IPV6M_NODE, &vtysh_quit_bgpd_cmd);
hassoc25e4582003-12-23 10:39:08 +00002312 install_element (ISIS_NODE, &vtysh_exit_isisd_cmd);
2313 install_element (ISIS_NODE, &vtysh_quit_isisd_cmd);
paul718e3742002-12-13 20:15:29 +00002314 install_element (KEYCHAIN_NODE, &vtysh_exit_ripd_cmd);
2315 install_element (KEYCHAIN_NODE, &vtysh_quit_ripd_cmd);
2316 install_element (KEYCHAIN_KEY_NODE, &vtysh_exit_ripd_cmd);
2317 install_element (KEYCHAIN_KEY_NODE, &vtysh_quit_ripd_cmd);
2318 install_element (RMAP_NODE, &vtysh_exit_rmap_cmd);
2319 install_element (RMAP_NODE, &vtysh_quit_rmap_cmd);
hassoe7168df2004-10-03 20:11:32 +00002320 install_element (VTY_NODE, &vtysh_exit_line_vty_cmd);
2321 install_element (VTY_NODE, &vtysh_quit_line_vty_cmd);
paul718e3742002-12-13 20:15:29 +00002322
2323 /* "end" command. */
2324 install_element (CONFIG_NODE, &vtysh_end_all_cmd);
2325 install_element (ENABLE_NODE, &vtysh_end_all_cmd);
2326 install_element (RIP_NODE, &vtysh_end_all_cmd);
2327 install_element (RIPNG_NODE, &vtysh_end_all_cmd);
2328 install_element (OSPF_NODE, &vtysh_end_all_cmd);
2329 install_element (OSPF6_NODE, &vtysh_end_all_cmd);
2330 install_element (BGP_NODE, &vtysh_end_all_cmd);
2331 install_element (BGP_IPV4_NODE, &vtysh_end_all_cmd);
2332 install_element (BGP_IPV4M_NODE, &vtysh_end_all_cmd);
2333 install_element (BGP_VPNV4_NODE, &vtysh_end_all_cmd);
2334 install_element (BGP_IPV6_NODE, &vtysh_end_all_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002335 install_element (BGP_IPV6M_NODE, &vtysh_end_all_cmd);
hassoc25e4582003-12-23 10:39:08 +00002336 install_element (ISIS_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002337 install_element (KEYCHAIN_NODE, &vtysh_end_all_cmd);
2338 install_element (KEYCHAIN_KEY_NODE, &vtysh_end_all_cmd);
2339 install_element (RMAP_NODE, &vtysh_end_all_cmd);
hassoe7168df2004-10-03 20:11:32 +00002340 install_element (VTY_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002341
paul338a9912003-03-01 15:44:10 +00002342 install_element (INTERFACE_NODE, &interface_desc_cmd);
paul464dc8d2003-03-28 02:25:45 +00002343 install_element (INTERFACE_NODE, &no_interface_desc_cmd);
paul718e3742002-12-13 20:15:29 +00002344 install_element (INTERFACE_NODE, &vtysh_end_all_cmd);
2345 install_element (INTERFACE_NODE, &vtysh_exit_interface_cmd);
2346 install_element (INTERFACE_NODE, &vtysh_quit_interface_cmd);
2347 install_element (CONFIG_NODE, &router_rip_cmd);
2348#ifdef HAVE_IPV6
2349 install_element (CONFIG_NODE, &router_ripng_cmd);
2350#endif
2351 install_element (CONFIG_NODE, &router_ospf_cmd);
2352#ifdef HAVE_IPV6
2353 install_element (CONFIG_NODE, &router_ospf6_cmd);
2354#endif
hassoc25e4582003-12-23 10:39:08 +00002355 install_element (CONFIG_NODE, &router_isis_cmd);
paul718e3742002-12-13 20:15:29 +00002356 install_element (CONFIG_NODE, &router_bgp_cmd);
Paul Jakma10895fd2008-07-03 19:34:48 +00002357 install_element (CONFIG_NODE, &router_bgp_view_cmd);
paul718e3742002-12-13 20:15:29 +00002358 install_element (BGP_NODE, &address_family_vpnv4_cmd);
2359 install_element (BGP_NODE, &address_family_vpnv4_unicast_cmd);
2360 install_element (BGP_NODE, &address_family_ipv4_unicast_cmd);
2361 install_element (BGP_NODE, &address_family_ipv4_multicast_cmd);
2362#ifdef HAVE_IPV6
2363 install_element (BGP_NODE, &address_family_ipv6_cmd);
2364 install_element (BGP_NODE, &address_family_ipv6_unicast_cmd);
2365#endif
2366 install_element (BGP_VPNV4_NODE, &exit_address_family_cmd);
2367 install_element (BGP_IPV4_NODE, &exit_address_family_cmd);
2368 install_element (BGP_IPV4M_NODE, &exit_address_family_cmd);
2369 install_element (BGP_IPV6_NODE, &exit_address_family_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002370 install_element (BGP_IPV6M_NODE, &exit_address_family_cmd);
paul718e3742002-12-13 20:15:29 +00002371 install_element (CONFIG_NODE, &key_chain_cmd);
2372 install_element (CONFIG_NODE, &route_map_cmd);
hassoe7168df2004-10-03 20:11:32 +00002373 install_element (CONFIG_NODE, &vtysh_line_vty_cmd);
paul718e3742002-12-13 20:15:29 +00002374 install_element (KEYCHAIN_NODE, &key_cmd);
2375 install_element (KEYCHAIN_NODE, &key_chain_cmd);
2376 install_element (KEYCHAIN_KEY_NODE, &key_chain_cmd);
2377 install_element (CONFIG_NODE, &vtysh_interface_cmd);
paul32d24632003-05-23 09:25:20 +00002378 install_element (CONFIG_NODE, &vtysh_no_interface_cmd);
paul718e3742002-12-13 20:15:29 +00002379 install_element (ENABLE_NODE, &vtysh_show_running_config_cmd);
2380 install_element (ENABLE_NODE, &vtysh_copy_runningconfig_startupconfig_cmd);
2381 install_element (ENABLE_NODE, &vtysh_write_file_cmd);
hasso4a6e2252003-05-25 11:51:29 +00002382 install_element (ENABLE_NODE, &vtysh_write_cmd);
paul718e3742002-12-13 20:15:29 +00002383
hasso95e735b2004-08-26 13:08:30 +00002384 /* "write terminal" command. */
paul718e3742002-12-13 20:15:29 +00002385 install_element (ENABLE_NODE, &vtysh_write_terminal_cmd);
hassoe7168df2004-10-03 20:11:32 +00002386
2387 install_element (CONFIG_NODE, &vtysh_integrated_config_cmd);
2388 install_element (CONFIG_NODE, &no_vtysh_integrated_config_cmd);
paul718e3742002-12-13 20:15:29 +00002389
hasso95e735b2004-08-26 13:08:30 +00002390 /* "write memory" command. */
paul718e3742002-12-13 20:15:29 +00002391 install_element (ENABLE_NODE, &vtysh_write_memory_cmd);
paul718e3742002-12-13 20:15:29 +00002392
hasso34553cc2004-08-27 13:56:39 +00002393 install_element (VIEW_NODE, &vtysh_terminal_length_cmd);
2394 install_element (ENABLE_NODE, &vtysh_terminal_length_cmd);
2395 install_element (VIEW_NODE, &vtysh_terminal_no_length_cmd);
2396 install_element (ENABLE_NODE, &vtysh_terminal_no_length_cmd);
hassof2799e62004-10-28 17:43:11 +00002397 install_element (VIEW_NODE, &vtysh_show_daemons_cmd);
2398 install_element (ENABLE_NODE, &vtysh_show_daemons_cmd);
hasso34553cc2004-08-27 13:56:39 +00002399
paul718e3742002-12-13 20:15:29 +00002400 install_element (VIEW_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002401 install_element (VIEW_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00002402 install_element (VIEW_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002403 install_element (VIEW_NODE, &vtysh_traceroute_ip_cmd);
2404#ifdef HAVE_IPV6
2405 install_element (VIEW_NODE, &vtysh_ping6_cmd);
2406 install_element (VIEW_NODE, &vtysh_traceroute6_cmd);
2407#endif
paul718e3742002-12-13 20:15:29 +00002408 install_element (VIEW_NODE, &vtysh_telnet_cmd);
2409 install_element (VIEW_NODE, &vtysh_telnet_port_cmd);
paul5087df52003-01-25 06:56:09 +00002410 install_element (VIEW_NODE, &vtysh_ssh_cmd);
paul718e3742002-12-13 20:15:29 +00002411 install_element (ENABLE_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002412 install_element (ENABLE_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00002413 install_element (ENABLE_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002414 install_element (ENABLE_NODE, &vtysh_traceroute_ip_cmd);
2415#ifdef HAVE_IPV6
2416 install_element (ENABLE_NODE, &vtysh_ping6_cmd);
2417 install_element (ENABLE_NODE, &vtysh_traceroute6_cmd);
2418#endif
paul718e3742002-12-13 20:15:29 +00002419 install_element (ENABLE_NODE, &vtysh_telnet_cmd);
2420 install_element (ENABLE_NODE, &vtysh_telnet_port_cmd);
hasso67e29ab2004-08-26 22:21:31 +00002421 install_element (ENABLE_NODE, &vtysh_ssh_cmd);
paul718e3742002-12-13 20:15:29 +00002422 install_element (ENABLE_NODE, &vtysh_start_shell_cmd);
2423 install_element (ENABLE_NODE, &vtysh_start_bash_cmd);
2424 install_element (ENABLE_NODE, &vtysh_start_zsh_cmd);
Paul Jakmadbf7d132006-05-23 22:10:01 +00002425
Paul Jakma362b4032006-05-28 07:54:45 +00002426 install_element (VIEW_NODE, &vtysh_show_memory_cmd);
2427 install_element (ENABLE_NODE, &vtysh_show_memory_cmd);
2428
Paul Jakmadbf7d132006-05-23 22:10:01 +00002429 /* Logging */
2430 install_element (ENABLE_NODE, &vtysh_show_logging_cmd);
2431 install_element (VIEW_NODE, &vtysh_show_logging_cmd);
paul718e3742002-12-13 20:15:29 +00002432 install_element (CONFIG_NODE, &vtysh_log_stdout_cmd);
ajs274a4a42004-12-07 15:39:31 +00002433 install_element (CONFIG_NODE, &vtysh_log_stdout_level_cmd);
paul718e3742002-12-13 20:15:29 +00002434 install_element (CONFIG_NODE, &no_vtysh_log_stdout_cmd);
2435 install_element (CONFIG_NODE, &vtysh_log_file_cmd);
ajs274a4a42004-12-07 15:39:31 +00002436 install_element (CONFIG_NODE, &vtysh_log_file_level_cmd);
paul718e3742002-12-13 20:15:29 +00002437 install_element (CONFIG_NODE, &no_vtysh_log_file_cmd);
ajs274a4a42004-12-07 15:39:31 +00002438 install_element (CONFIG_NODE, &no_vtysh_log_file_level_cmd);
2439 install_element (CONFIG_NODE, &vtysh_log_monitor_cmd);
2440 install_element (CONFIG_NODE, &vtysh_log_monitor_level_cmd);
2441 install_element (CONFIG_NODE, &no_vtysh_log_monitor_cmd);
paul718e3742002-12-13 20:15:29 +00002442 install_element (CONFIG_NODE, &vtysh_log_syslog_cmd);
ajs274a4a42004-12-07 15:39:31 +00002443 install_element (CONFIG_NODE, &vtysh_log_syslog_level_cmd);
paul718e3742002-12-13 20:15:29 +00002444 install_element (CONFIG_NODE, &no_vtysh_log_syslog_cmd);
2445 install_element (CONFIG_NODE, &vtysh_log_trap_cmd);
2446 install_element (CONFIG_NODE, &no_vtysh_log_trap_cmd);
ajs274a4a42004-12-07 15:39:31 +00002447 install_element (CONFIG_NODE, &vtysh_log_facility_cmd);
2448 install_element (CONFIG_NODE, &no_vtysh_log_facility_cmd);
paul718e3742002-12-13 20:15:29 +00002449 install_element (CONFIG_NODE, &vtysh_log_record_priority_cmd);
2450 install_element (CONFIG_NODE, &no_vtysh_log_record_priority_cmd);
Andrew J. Schorrc749b722007-04-29 03:53:31 +00002451 install_element (CONFIG_NODE, &vtysh_log_timestamp_precision_cmd);
2452 install_element (CONFIG_NODE, &no_vtysh_log_timestamp_precision_cmd);
hassoe7168df2004-10-03 20:11:32 +00002453
2454 install_element (CONFIG_NODE, &vtysh_service_password_encrypt_cmd);
2455 install_element (CONFIG_NODE, &no_vtysh_service_password_encrypt_cmd);
2456
2457 install_element (CONFIG_NODE, &vtysh_password_cmd);
2458 install_element (CONFIG_NODE, &vtysh_password_text_cmd);
2459 install_element (CONFIG_NODE, &vtysh_enable_password_cmd);
2460 install_element (CONFIG_NODE, &vtysh_enable_password_text_cmd);
2461 install_element (CONFIG_NODE, &no_vtysh_enable_password_cmd);
2462
paul718e3742002-12-13 20:15:29 +00002463}