blob: a5e29dc916a6a585701dff1da506797c2dde2b6a [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},
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +010061 { .fd = -1, .name = "babeld", .flag = VTYSH_BABELD, .path = BABEL_VTYSH_PATH},
Leonard Herve596470f2009-08-11 15:45:26 -030062 { .fd = -1, .name = "pimd", .flag = VTYSH_PIMD, .path = PIM_VTYSH_PATH},
63>>>>>>> [pim] pim commands added to vtysh
ajsb1aa1472005-01-28 21:11:46 +000064};
65
ajsb1aa1472005-01-28 21:11:46 +000066
67/* We need direct access to ripd to implement vtysh_exit_ripd_only. */
68static struct vtysh_client *ripd_client = NULL;
69
hassob094d262004-08-25 12:22:00 +000070
hassoe7168df2004-10-03 20:11:32 +000071/* Using integrated config from Quagga.conf. Default is no. */
72int vtysh_writeconfig_integrated = 0;
73
74extern char config_default[];
75
ajs274a4a42004-12-07 15:39:31 +000076static void
paul718e3742002-12-13 20:15:29 +000077vclient_close (struct vtysh_client *vclient)
78{
ajsb1aa1472005-01-28 21:11:46 +000079 if (vclient->fd >= 0)
80 {
81 fprintf(stderr,
82 "Warning: closing connection to %s because of an I/O error!\n",
83 vclient->name);
84 close (vclient->fd);
85 vclient->fd = -1;
86 }
paul718e3742002-12-13 20:15:29 +000087}
88
paul718e3742002-12-13 20:15:29 +000089/* Following filled with debug code to trace a problematic condition
hasso95e735b2004-08-26 13:08:30 +000090 * under load - it SHOULD handle it. */
paul718e3742002-12-13 20:15:29 +000091#define ERR_WHERE_STRING "vtysh(): vtysh_client_config(): "
ajs274a4a42004-12-07 15:39:31 +000092static int
paul718e3742002-12-13 20:15:29 +000093vtysh_client_config (struct vtysh_client *vclient, char *line)
94{
95 int ret;
96 char *buf;
97 size_t bufsz;
98 char *pbuf;
99 size_t left;
100 char *eoln;
101 int nbytes;
102 int i;
103 int readln;
104
105 if (vclient->fd < 0)
106 return CMD_SUCCESS;
107
108 ret = write (vclient->fd, line, strlen (line) + 1);
109 if (ret <= 0)
110 {
111 vclient_close (vclient);
112 return CMD_SUCCESS;
113 }
114
hasso95e735b2004-08-26 13:08:30 +0000115 /* Allow enough room for buffer to read more than a few pages from socket. */
paule3d29b52003-01-23 18:05:42 +0000116 bufsz = 5 * getpagesize() + 1;
paul718e3742002-12-13 20:15:29 +0000117 buf = XMALLOC(MTYPE_TMP, bufsz);
118 memset(buf, 0, bufsz);
119 pbuf = buf;
120
121 while (1)
122 {
123 if (pbuf >= ((buf + bufsz) -1))
124 {
125 fprintf (stderr, ERR_WHERE_STRING \
126 "warning - pbuf beyond buffer end.\n");
127 return CMD_WARNING;
128 }
129
130 readln = (buf + bufsz) - pbuf - 1;
131 nbytes = read (vclient->fd, pbuf, readln);
132
133 if (nbytes <= 0)
134 {
135
136 if (errno == EINTR)
137 continue;
138
139 fprintf(stderr, ERR_WHERE_STRING "(%u)", errno);
140 perror("");
141
142 if (errno == EAGAIN || errno == EIO)
143 continue;
144
145 vclient_close (vclient);
146 XFREE(MTYPE_TMP, buf);
147 return CMD_SUCCESS;
148 }
149
150 pbuf[nbytes] = '\0';
151
152 if (nbytes >= 4)
153 {
154 i = nbytes - 4;
155 if (pbuf[i] == '\0' && pbuf[i + 1] == '\0' && pbuf[i + 2] == '\0')
156 {
157 ret = pbuf[i + 3];
158 break;
159 }
160 }
161 pbuf += nbytes;
162
163 /* See if a line exists in buffer, if so parse and consume it, and
hasso95e735b2004-08-26 13:08:30 +0000164 * reset read position. */
paul718e3742002-12-13 20:15:29 +0000165 if ((eoln = strrchr(buf, '\n')) == NULL)
166 continue;
167
168 if (eoln >= ((buf + bufsz) - 1))
169 {
170 fprintf (stderr, ERR_WHERE_STRING \
171 "warning - eoln beyond buffer end.\n");
172 }
173 vtysh_config_parse(buf);
174
175 eoln++;
176 left = (size_t)(buf + bufsz - eoln);
177 memmove(buf, eoln, left);
178 buf[bufsz-1] = '\0';
179 pbuf = buf + strlen(buf);
180 }
181
hasso95e735b2004-08-26 13:08:30 +0000182 /* Parse anything left in the buffer. */
hassoe7168df2004-10-03 20:11:32 +0000183
paul718e3742002-12-13 20:15:29 +0000184 vtysh_config_parse (buf);
185
186 XFREE(MTYPE_TMP, buf);
187 return ret;
188}
189
ajs274a4a42004-12-07 15:39:31 +0000190static int
hassodda09522004-10-07 21:40:25 +0000191vtysh_client_execute (struct vtysh_client *vclient, const char *line, FILE *fp)
paul718e3742002-12-13 20:15:29 +0000192{
193 int ret;
194 char buf[1001];
195 int nbytes;
paul2852de12004-09-17 06:52:16 +0000196 int i;
197 int numnulls = 0;
paul718e3742002-12-13 20:15:29 +0000198
199 if (vclient->fd < 0)
200 return CMD_SUCCESS;
201
202 ret = write (vclient->fd, line, strlen (line) + 1);
203 if (ret <= 0)
204 {
205 vclient_close (vclient);
206 return CMD_SUCCESS;
207 }
208
209 while (1)
210 {
211 nbytes = read (vclient->fd, buf, sizeof(buf)-1);
212
213 if (nbytes <= 0 && errno != EINTR)
214 {
215 vclient_close (vclient);
216 return CMD_SUCCESS;
217 }
218
219 if (nbytes > 0)
220 {
ajs85fb1e62004-11-11 14:03:39 +0000221 if ((numnulls == 3) && (nbytes == 1))
222 return buf[0];
223
paul718e3742002-12-13 20:15:29 +0000224 buf[nbytes] = '\0';
ajs85fb1e62004-11-11 14:03:39 +0000225 fputs (buf, fp);
paul718e3742002-12-13 20:15:29 +0000226 fflush (fp);
paul2852de12004-09-17 06:52:16 +0000227
paul0921d482004-10-11 18:21:55 +0000228 /* check for trailling \0\0\0<ret code>,
229 * even if split across reads
230 * (see lib/vty.c::vtysh_read)
231 */
paul2852de12004-09-17 06:52:16 +0000232 if (nbytes >= 4)
233 {
234 i = nbytes-4;
235 numnulls = 0;
236 }
237 else
238 i = 0;
239
paul0921d482004-10-11 18:21:55 +0000240 while (i < nbytes && numnulls < 3)
paul2852de12004-09-17 06:52:16 +0000241 {
242 if (buf[i++] == '\0')
243 numnulls++;
244 else
ajs85fb1e62004-11-11 14:03:39 +0000245 numnulls = 0;
paul2852de12004-09-17 06:52:16 +0000246 }
paul718e3742002-12-13 20:15:29 +0000247
ajs85fb1e62004-11-11 14:03:39 +0000248 /* got 3 or more trailing NULs? */
249 if ((numnulls >= 3) && (i < nbytes))
paul0921d482004-10-11 18:21:55 +0000250 return (buf[nbytes-1]);
paul718e3742002-12-13 20:15:29 +0000251 }
252 }
paul718e3742002-12-13 20:15:29 +0000253}
254
255void
ajsb1aa1472005-01-28 21:11:46 +0000256vtysh_exit_ripd_only (void)
paul718e3742002-12-13 20:15:29 +0000257{
ajsb1aa1472005-01-28 21:11:46 +0000258 if (ripd_client)
259 vtysh_client_execute (ripd_client, "exit", stdout);
paul718e3742002-12-13 20:15:29 +0000260}
261
262
263void
ajsb1aa1472005-01-28 21:11:46 +0000264vtysh_pager_init (void)
paul718e3742002-12-13 20:15:29 +0000265{
hasso5a9c53d2004-08-27 14:23:28 +0000266 char *pager_defined;
267
268 pager_defined = getenv ("VTYSH_PAGER");
269
270 if (pager_defined)
271 vtysh_pager_name = strdup (pager_defined);
272 else
hasso34553cc2004-08-27 13:56:39 +0000273 vtysh_pager_name = strdup ("more");
paul718e3742002-12-13 20:15:29 +0000274}
275
276/* Command execution over the vty interface. */
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700277static int
hassodda09522004-10-07 21:40:25 +0000278vtysh_execute_func (const char *line, int pager)
paul718e3742002-12-13 20:15:29 +0000279{
Stephen Hemminger2c4d48b2008-07-28 15:04:56 -0700280 int ret, cmd_stat;
ajsb1aa1472005-01-28 21:11:46 +0000281 u_int i;
paul718e3742002-12-13 20:15:29 +0000282 vector vline;
283 struct cmd_element *cmd;
284 FILE *fp = NULL;
hasso13bfca72005-01-23 21:42:25 +0000285 int closepager = 0;
286 int tried = 0;
287 int saved_ret, saved_node;
paul718e3742002-12-13 20:15:29 +0000288
hasso95e735b2004-08-26 13:08:30 +0000289 /* Split readline string up into the vector. */
paul718e3742002-12-13 20:15:29 +0000290 vline = cmd_make_strvec (line);
291
292 if (vline == NULL)
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700293 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000294
hasso13bfca72005-01-23 21:42:25 +0000295 saved_ret = ret = cmd_execute_command (vline, vty, &cmd, 1);
296 saved_node = vty->node;
297
298 /* If command doesn't succeeded in current node, try to walk up in node tree.
299 * Changing vty->node is enough to try it just out without actual walkup in
300 * the vtysh. */
301 while (ret != CMD_SUCCESS && ret != CMD_SUCCESS_DAEMON && ret != CMD_WARNING
302 && vty->node > CONFIG_NODE)
303 {
304 vty->node = node_parent(vty->node);
305 ret = cmd_execute_command (vline, vty, &cmd, 1);
306 tried++;
307 }
308
309 vty->node = saved_node;
310
311 /* If command succeeded in any other node than current (tried > 0) we have
312 * to move into node in the vtysh where it succeeded. */
313 if (ret == CMD_SUCCESS || ret == CMD_SUCCESS_DAEMON || ret == CMD_WARNING)
314 {
315 if ((saved_node == BGP_VPNV4_NODE || saved_node == BGP_IPV4_NODE
paul57b5b7e2005-08-22 22:44:29 +0000316 || saved_node == BGP_IPV6_NODE || saved_node == BGP_IPV4M_NODE
317 || saved_node == BGP_IPV6M_NODE)
hasso13bfca72005-01-23 21:42:25 +0000318 && (tried == 1))
319 {
320 vtysh_execute("exit-address-family");
321 }
322 else if ((saved_node == KEYCHAIN_KEY_NODE) && (tried == 1))
323 {
324 vtysh_execute("exit");
325 }
326 else if (tried)
327 {
328 vtysh_execute ("end");
329 vtysh_execute ("configure terminal");
330 }
331 }
332 /* If command didn't succeed in any node, continue with return value from
333 * first try. */
334 else if (tried)
335 {
336 ret = saved_ret;
337 }
paul718e3742002-12-13 20:15:29 +0000338
339 cmd_free_strvec (vline);
340
Stephen Hemminger2c4d48b2008-07-28 15:04:56 -0700341 cmd_stat = ret;
paul718e3742002-12-13 20:15:29 +0000342 switch (ret)
343 {
344 case CMD_WARNING:
345 if (vty->type == VTY_FILE)
paul4fc01e62002-12-13 20:49:00 +0000346 fprintf (stdout,"Warning...\n");
paul718e3742002-12-13 20:15:29 +0000347 break;
348 case CMD_ERR_AMBIGUOUS:
paul4fc01e62002-12-13 20:49:00 +0000349 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000350 break;
351 case CMD_ERR_NO_MATCH:
paul4fc01e62002-12-13 20:49:00 +0000352 fprintf (stdout,"%% Unknown command.\n");
paul718e3742002-12-13 20:15:29 +0000353 break;
354 case CMD_ERR_INCOMPLETE:
paul4fc01e62002-12-13 20:49:00 +0000355 fprintf (stdout,"%% Command incomplete.\n");
paul718e3742002-12-13 20:15:29 +0000356 break;
357 case CMD_SUCCESS_DAEMON:
358 {
hasso97b7db22004-10-20 19:07:48 +0000359 /* FIXME: Don't open pager for exit commands. popen() causes problems
360 * if exited from vtysh at all. This hack shouldn't cause any problem
361 * but is really ugly. */
362 if (pager && vtysh_pager_name && (strncmp(line, "exit", 4) != 0))
paul718e3742002-12-13 20:15:29 +0000363 {
paul4fc01e62002-12-13 20:49:00 +0000364 fp = popen (vtysh_pager_name, "w");
paul718e3742002-12-13 20:15:29 +0000365 if (fp == NULL)
366 {
paula805cc22003-05-01 14:29:48 +0000367 perror ("popen failed for pager");
368 fp = stdout;
paul718e3742002-12-13 20:15:29 +0000369 }
paula805cc22003-05-01 14:29:48 +0000370 else
371 closepager=1;
paul718e3742002-12-13 20:15:29 +0000372 }
373 else
374 fp = stdout;
375
376 if (! strcmp(cmd->string,"configure terminal"))
377 {
Balaji.G837d16c2012-09-26 14:09:10 +0530378 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +0000379 {
380 cmd_stat = vtysh_client_execute(&vtysh_client[i], line, fp);
381 if (cmd_stat == CMD_WARNING)
382 break;
383 }
384
paul718e3742002-12-13 20:15:29 +0000385 if (cmd_stat)
386 {
hassob094d262004-08-25 12:22:00 +0000387 line = "end";
388 vline = cmd_make_strvec (line);
paul718e3742002-12-13 20:15:29 +0000389
hassob094d262004-08-25 12:22:00 +0000390 if (vline == NULL)
paul718e3742002-12-13 20:15:29 +0000391 {
paula805cc22003-05-01 14:29:48 +0000392 if (pager && vtysh_pager_name && fp && closepager)
paul718e3742002-12-13 20:15:29 +0000393 {
394 if (pclose (fp) == -1)
395 {
paula805cc22003-05-01 14:29:48 +0000396 perror ("pclose failed for pager");
paul718e3742002-12-13 20:15:29 +0000397 }
398 fp = NULL;
399 }
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700400 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000401 }
402
hasso87d683b2005-01-16 23:31:54 +0000403 ret = cmd_execute_command (vline, vty, &cmd, 1);
hassob094d262004-08-25 12:22:00 +0000404 cmd_free_strvec (vline);
405 if (ret != CMD_SUCCESS_DAEMON)
406 break;
paul718e3742002-12-13 20:15:29 +0000407 }
408 else
409 if (cmd->func)
410 {
411 (*cmd->func) (cmd, vty, 0, NULL);
412 break;
hassob094d262004-08-25 12:22:00 +0000413 }
paul718e3742002-12-13 20:15:29 +0000414 }
415
ajsb1aa1472005-01-28 21:11:46 +0000416 cmd_stat = CMD_SUCCESS;
Balaji.G837d16c2012-09-26 14:09:10 +0530417 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +0000418 {
419 if (cmd->daemon & vtysh_client[i].flag)
420 {
421 cmd_stat = vtysh_client_execute(&vtysh_client[i], line, fp);
422 if (cmd_stat != CMD_SUCCESS)
423 break;
424 }
425 }
426 if (cmd_stat != CMD_SUCCESS)
427 break;
428
paul718e3742002-12-13 20:15:29 +0000429 if (cmd->func)
430 (*cmd->func) (cmd, vty, 0, NULL);
431 }
432 }
paula805cc22003-05-01 14:29:48 +0000433 if (pager && vtysh_pager_name && fp && closepager)
paul718e3742002-12-13 20:15:29 +0000434 {
435 if (pclose (fp) == -1)
436 {
paula805cc22003-05-01 14:29:48 +0000437 perror ("pclose failed for pager");
paul718e3742002-12-13 20:15:29 +0000438 }
439 fp = NULL;
440 }
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700441 return cmd_stat;
paul718e3742002-12-13 20:15:29 +0000442}
443
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700444int
hassodda09522004-10-07 21:40:25 +0000445vtysh_execute_no_pager (const char *line)
paul718e3742002-12-13 20:15:29 +0000446{
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700447 return vtysh_execute_func (line, 0);
paul718e3742002-12-13 20:15:29 +0000448}
449
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700450int
hassodda09522004-10-07 21:40:25 +0000451vtysh_execute (const char *line)
paul718e3742002-12-13 20:15:29 +0000452{
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700453 return vtysh_execute_func (line, 1);
paul718e3742002-12-13 20:15:29 +0000454}
455
456/* Configration make from file. */
457int
458vtysh_config_from_file (struct vty *vty, FILE *fp)
459{
460 int ret;
461 vector vline;
462 struct cmd_element *cmd;
463
464 while (fgets (vty->buf, VTY_BUFSIZ, fp))
465 {
466 if (vty->buf[0] == '!' || vty->buf[1] == '#')
467 continue;
468
469 vline = cmd_make_strvec (vty->buf);
470
hasso95e735b2004-08-26 13:08:30 +0000471 /* In case of comment line. */
paul718e3742002-12-13 20:15:29 +0000472 if (vline == NULL)
473 continue;
474
hasso95e735b2004-08-26 13:08:30 +0000475 /* Execute configuration command : this is strict match. */
paul718e3742002-12-13 20:15:29 +0000476 ret = cmd_execute_command_strict (vline, vty, &cmd);
477
hasso95e735b2004-08-26 13:08:30 +0000478 /* Try again with setting node to CONFIG_NODE. */
paul718e3742002-12-13 20:15:29 +0000479 if (ret != CMD_SUCCESS
480 && ret != CMD_SUCCESS_DAEMON
481 && ret != CMD_WARNING)
482 {
483 if (vty->node == KEYCHAIN_KEY_NODE)
484 {
485 vty->node = KEYCHAIN_NODE;
486 vtysh_exit_ripd_only ();
487 ret = cmd_execute_command_strict (vline, vty, &cmd);
488
489 if (ret != CMD_SUCCESS
490 && ret != CMD_SUCCESS_DAEMON
491 && ret != CMD_WARNING)
492 {
493 vtysh_exit_ripd_only ();
494 vty->node = CONFIG_NODE;
495 ret = cmd_execute_command_strict (vline, vty, &cmd);
496 }
497 }
498 else
499 {
500 vtysh_execute ("end");
501 vtysh_execute ("configure terminal");
502 vty->node = CONFIG_NODE;
503 ret = cmd_execute_command_strict (vline, vty, &cmd);
504 }
505 }
506
507 cmd_free_strvec (vline);
508
509 switch (ret)
510 {
511 case CMD_WARNING:
512 if (vty->type == VTY_FILE)
paul4fc01e62002-12-13 20:49:00 +0000513 fprintf (stdout,"Warning...\n");
paul718e3742002-12-13 20:15:29 +0000514 break;
515 case CMD_ERR_AMBIGUOUS:
paul4fc01e62002-12-13 20:49:00 +0000516 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000517 break;
518 case CMD_ERR_NO_MATCH:
paul4fc01e62002-12-13 20:49:00 +0000519 fprintf (stdout,"%% Unknown command: %s", vty->buf);
paul718e3742002-12-13 20:15:29 +0000520 break;
521 case CMD_ERR_INCOMPLETE:
paul4fc01e62002-12-13 20:49:00 +0000522 fprintf (stdout,"%% Command incomplete.\n");
paul718e3742002-12-13 20:15:29 +0000523 break;
524 case CMD_SUCCESS_DAEMON:
525 {
ajsb1aa1472005-01-28 21:11:46 +0000526 u_int i;
527 int cmd_stat = CMD_SUCCESS;
528
Balaji.G837d16c2012-09-26 14:09:10 +0530529 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +0000530 {
paul44316fe2006-01-11 01:38:25 +0000531 if (cmd->daemon & vtysh_client[i].flag)
ajsb1aa1472005-01-28 21:11:46 +0000532 {
533 cmd_stat = vtysh_client_execute (&vtysh_client[i],
534 vty->buf, stdout);
535 if (cmd_stat != CMD_SUCCESS)
536 break;
537 }
538 }
539 if (cmd_stat != CMD_SUCCESS)
540 break;
541
paul718e3742002-12-13 20:15:29 +0000542 if (cmd->func)
543 (*cmd->func) (cmd, vty, 0, NULL);
544 }
545 }
546 }
547 return CMD_SUCCESS;
548}
549
550/* We don't care about the point of the cursor when '?' is typed. */
551int
ajsb1aa1472005-01-28 21:11:46 +0000552vtysh_rl_describe (void)
paul718e3742002-12-13 20:15:29 +0000553{
554 int ret;
hassodda09522004-10-07 21:40:25 +0000555 unsigned int i;
paul718e3742002-12-13 20:15:29 +0000556 vector vline;
557 vector describe;
558 int width;
Christian Frankecd40b322013-09-30 12:27:51 +0000559 struct cmd_token *token;
paul718e3742002-12-13 20:15:29 +0000560
561 vline = cmd_make_strvec (rl_line_buffer);
562
563 /* In case of '> ?'. */
564 if (vline == NULL)
565 {
566 vline = vector_init (1);
567 vector_set (vline, '\0');
568 }
569 else
570 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
571 vector_set (vline, '\0');
572
573 describe = cmd_describe_command (vline, vty, &ret);
574
paul4fc01e62002-12-13 20:49:00 +0000575 fprintf (stdout,"\n");
paul718e3742002-12-13 20:15:29 +0000576
577 /* Ambiguous and no match error. */
578 switch (ret)
579 {
580 case CMD_ERR_AMBIGUOUS:
581 cmd_free_strvec (vline);
paul4fc01e62002-12-13 20:49:00 +0000582 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000583 rl_on_new_line ();
584 return 0;
585 break;
586 case CMD_ERR_NO_MATCH:
587 cmd_free_strvec (vline);
paul4fc01e62002-12-13 20:49:00 +0000588 fprintf (stdout,"%% There is no matched command.\n");
paul718e3742002-12-13 20:15:29 +0000589 rl_on_new_line ();
590 return 0;
591 break;
592 }
593
594 /* Get width of command string. */
595 width = 0;
paul55468c82005-03-14 20:19:01 +0000596 for (i = 0; i < vector_active (describe); i++)
Christian Frankecd40b322013-09-30 12:27:51 +0000597 if ((token = vector_slot (describe, i)) != NULL)
paul718e3742002-12-13 20:15:29 +0000598 {
599 int len;
600
Christian Frankecd40b322013-09-30 12:27:51 +0000601 if (token->cmd[0] == '\0')
paul718e3742002-12-13 20:15:29 +0000602 continue;
603
Christian Frankecd40b322013-09-30 12:27:51 +0000604 len = strlen (token->cmd);
605 if (token->cmd[0] == '.')
paul718e3742002-12-13 20:15:29 +0000606 len--;
607
608 if (width < len)
609 width = len;
610 }
611
paul55468c82005-03-14 20:19:01 +0000612 for (i = 0; i < vector_active (describe); i++)
Christian Frankecd40b322013-09-30 12:27:51 +0000613 if ((token = vector_slot (describe, i)) != NULL)
paul718e3742002-12-13 20:15:29 +0000614 {
Christian Frankecd40b322013-09-30 12:27:51 +0000615 if (token->cmd[0] == '\0')
paul718e3742002-12-13 20:15:29 +0000616 continue;
617
Christian Frankecd40b322013-09-30 12:27:51 +0000618 if (! token->desc)
paul4fc01e62002-12-13 20:49:00 +0000619 fprintf (stdout," %-s\n",
Christian Frankecd40b322013-09-30 12:27:51 +0000620 token->cmd[0] == '.' ? token->cmd + 1 : token->cmd);
paul718e3742002-12-13 20:15:29 +0000621 else
paul4fc01e62002-12-13 20:49:00 +0000622 fprintf (stdout," %-*s %s\n",
hassob094d262004-08-25 12:22:00 +0000623 width,
Christian Frankecd40b322013-09-30 12:27:51 +0000624 token->cmd[0] == '.' ? token->cmd + 1 : token->cmd,
625 token->desc);
paul718e3742002-12-13 20:15:29 +0000626 }
627
628 cmd_free_strvec (vline);
629 vector_free (describe);
630
631 rl_on_new_line();
632
633 return 0;
634}
635
hasso95e735b2004-08-26 13:08:30 +0000636/* Result of cmd_complete_command() call will be stored here
637 * and used in new_completion() in order to put the space in
638 * correct places only. */
paul718e3742002-12-13 20:15:29 +0000639int complete_status;
640
ajs274a4a42004-12-07 15:39:31 +0000641static char *
pauldfc0d9b2003-04-18 23:55:29 +0000642command_generator (const char *text, int state)
paul718e3742002-12-13 20:15:29 +0000643{
644 vector vline;
645 static char **matched = NULL;
646 static int index = 0;
647
648 /* First call. */
649 if (! state)
650 {
651 index = 0;
652
653 if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
654 return NULL;
655
656 vline = cmd_make_strvec (rl_line_buffer);
657 if (vline == NULL)
658 return NULL;
659
660 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
661 vector_set (vline, '\0');
662
663 matched = cmd_complete_command (vline, vty, &complete_status);
664 }
665
666 if (matched && matched[index])
667 return matched[index++];
668
669 return NULL;
670}
671
ajs274a4a42004-12-07 15:39:31 +0000672static char **
paul718e3742002-12-13 20:15:29 +0000673new_completion (char *text, int start, int end)
674{
675 char **matches;
676
pauldfc0d9b2003-04-18 23:55:29 +0000677 matches = rl_completion_matches (text, command_generator);
paul718e3742002-12-13 20:15:29 +0000678
679 if (matches)
680 {
681 rl_point = rl_end;
Christian Franke67e7a212013-03-04 09:23:30 +0000682 if (complete_status != CMD_COMPLETE_FULL_MATCH)
683 /* only append a space on full match */
684 rl_completion_append_character = '\0';
paul718e3742002-12-13 20:15:29 +0000685 }
686
687 return matches;
688}
689
ajs274a4a42004-12-07 15:39:31 +0000690#if 0
691/* This function is not actually being used. */
692static char **
paul718e3742002-12-13 20:15:29 +0000693vtysh_completion (char *text, int start, int end)
694{
695 int ret;
696 vector vline;
697 char **matched = NULL;
698
699 if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
700 return NULL;
701
702 vline = cmd_make_strvec (rl_line_buffer);
703 if (vline == NULL)
704 return NULL;
705
706 /* In case of 'help \t'. */
707 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
708 vector_set (vline, '\0');
709
710 matched = cmd_complete_command (vline, vty, &ret);
711
712 cmd_free_strvec (vline);
713
714 return (char **) matched;
715}
ajs274a4a42004-12-07 15:39:31 +0000716#endif
paul718e3742002-12-13 20:15:29 +0000717
hasso95e735b2004-08-26 13:08:30 +0000718/* Vty node structures. */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800719static struct cmd_node bgp_node =
paul718e3742002-12-13 20:15:29 +0000720{
721 BGP_NODE,
722 "%s(config-router)# ",
723};
724
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800725static struct cmd_node rip_node =
paul718e3742002-12-13 20:15:29 +0000726{
727 RIP_NODE,
728 "%s(config-router)# ",
729};
730
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800731static struct cmd_node isis_node =
hassoc25e4582003-12-23 10:39:08 +0000732{
733 ISIS_NODE,
734 "%s(config-router)# ",
hassoc25e4582003-12-23 10:39:08 +0000735};
736
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800737static struct cmd_node interface_node =
paul718e3742002-12-13 20:15:29 +0000738{
739 INTERFACE_NODE,
740 "%s(config-if)# ",
741};
742
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800743static struct cmd_node rmap_node =
hasso95e735b2004-08-26 13:08:30 +0000744{
745 RMAP_NODE,
746 "%s(config-route-map)# "
747};
748
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800749static struct cmd_node zebra_node =
hasso95e735b2004-08-26 13:08:30 +0000750{
751 ZEBRA_NODE,
752 "%s(config-router)# "
753};
754
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800755static struct cmd_node bgp_vpnv4_node =
hasso95e735b2004-08-26 13:08:30 +0000756{
757 BGP_VPNV4_NODE,
758 "%s(config-router-af)# "
759};
760
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800761static struct cmd_node bgp_ipv4_node =
hasso95e735b2004-08-26 13:08:30 +0000762{
763 BGP_IPV4_NODE,
764 "%s(config-router-af)# "
765};
766
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800767static struct cmd_node bgp_ipv4m_node =
hasso95e735b2004-08-26 13:08:30 +0000768{
769 BGP_IPV4M_NODE,
770 "%s(config-router-af)# "
771};
772
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800773static struct cmd_node bgp_ipv6_node =
hasso95e735b2004-08-26 13:08:30 +0000774{
775 BGP_IPV6_NODE,
776 "%s(config-router-af)# "
777};
778
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800779static struct cmd_node bgp_ipv6m_node =
paul57b5b7e2005-08-22 22:44:29 +0000780{
781 BGP_IPV6M_NODE,
782 "%s(config-router-af)# "
783};
784
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800785static struct cmd_node ospf_node =
hasso95e735b2004-08-26 13:08:30 +0000786{
787 OSPF_NODE,
788 "%s(config-router)# "
789};
790
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800791static struct cmd_node ripng_node =
hasso95e735b2004-08-26 13:08:30 +0000792{
793 RIPNG_NODE,
794 "%s(config-router)# "
795};
796
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800797static struct cmd_node ospf6_node =
hasso95e735b2004-08-26 13:08:30 +0000798{
799 OSPF6_NODE,
800 "%s(config-ospf6)# "
801};
802
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +0100803static struct cmd_node babel_node =
804{
805 BABEL_NODE,
806 "%s(config-babel)# "
807};
808
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800809static struct cmd_node keychain_node =
hasso95e735b2004-08-26 13:08:30 +0000810{
811 KEYCHAIN_NODE,
812 "%s(config-keychain)# "
813};
814
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800815static struct cmd_node keychain_key_node =
hasso95e735b2004-08-26 13:08:30 +0000816{
817 KEYCHAIN_KEY_NODE,
818 "%s(config-keychain-key)# "
819};
820
hassoe7168df2004-10-03 20:11:32 +0000821/* Defined in lib/vty.c */
822extern struct cmd_node vty_node;
823
hasso95e735b2004-08-26 13:08:30 +0000824/* When '^Z' is received from vty, move down to the enable mode. */
825int
ajsb1aa1472005-01-28 21:11:46 +0000826vtysh_end (void)
hasso95e735b2004-08-26 13:08:30 +0000827{
828 switch (vty->node)
829 {
830 case VIEW_NODE:
831 case ENABLE_NODE:
832 /* Nothing to do. */
833 break;
834 default:
835 vty->node = ENABLE_NODE;
836 break;
837 }
838 return CMD_SUCCESS;
839}
840
841DEFUNSH (VTYSH_ALL,
842 vtysh_end_all,
843 vtysh_end_all_cmd,
844 "end",
hassoe7168df2004-10-03 20:11:32 +0000845 "End current mode and change to enable mode\n")
hasso95e735b2004-08-26 13:08:30 +0000846{
hasso42895462004-09-26 16:25:07 +0000847 return vtysh_end ();
hasso95e735b2004-08-26 13:08:30 +0000848}
849
paul718e3742002-12-13 20:15:29 +0000850DEFUNSH (VTYSH_BGPD,
851 router_bgp,
852 router_bgp_cmd,
Paul Jakma320da872008-07-02 13:40:33 +0000853 "router bgp " CMD_AS_RANGE,
paul718e3742002-12-13 20:15:29 +0000854 ROUTER_STR
855 BGP_STR
856 AS_STR)
857{
858 vty->node = BGP_NODE;
859 return CMD_SUCCESS;
860}
861
Paul Jakma10895fd2008-07-03 19:34:48 +0000862ALIAS_SH (VTYSH_BGPD,
863 router_bgp,
864 router_bgp_view_cmd,
865 "router bgp " CMD_AS_RANGE " view WORD",
866 ROUTER_STR
867 BGP_STR
868 AS_STR
869 "BGP view\n"
870 "view name\n")
871
paul718e3742002-12-13 20:15:29 +0000872DEFUNSH (VTYSH_BGPD,
873 address_family_vpnv4,
874 address_family_vpnv4_cmd,
875 "address-family vpnv4",
876 "Enter Address Family command mode\n"
877 "Address family\n")
878{
879 vty->node = BGP_VPNV4_NODE;
880 return CMD_SUCCESS;
881}
882
883DEFUNSH (VTYSH_BGPD,
884 address_family_vpnv4_unicast,
885 address_family_vpnv4_unicast_cmd,
886 "address-family vpnv4 unicast",
887 "Enter Address Family command mode\n"
888 "Address family\n"
889 "Address Family Modifier\n")
890{
891 vty->node = BGP_VPNV4_NODE;
892 return CMD_SUCCESS;
893}
894
895DEFUNSH (VTYSH_BGPD,
896 address_family_ipv4_unicast,
897 address_family_ipv4_unicast_cmd,
898 "address-family ipv4 unicast",
899 "Enter Address Family command mode\n"
900 "Address family\n"
901 "Address Family Modifier\n")
902{
903 vty->node = BGP_IPV4_NODE;
904 return CMD_SUCCESS;
905}
906
907DEFUNSH (VTYSH_BGPD,
908 address_family_ipv4_multicast,
909 address_family_ipv4_multicast_cmd,
910 "address-family ipv4 multicast",
911 "Enter Address Family command mode\n"
912 "Address family\n"
913 "Address Family Modifier\n")
914{
915 vty->node = BGP_IPV4M_NODE;
916 return CMD_SUCCESS;
917}
918
919DEFUNSH (VTYSH_BGPD,
920 address_family_ipv6,
921 address_family_ipv6_cmd,
922 "address-family ipv6",
923 "Enter Address Family command mode\n"
924 "Address family\n")
925{
926 vty->node = BGP_IPV6_NODE;
927 return CMD_SUCCESS;
928}
929
930DEFUNSH (VTYSH_BGPD,
931 address_family_ipv6_unicast,
932 address_family_ipv6_unicast_cmd,
933 "address-family ipv6 unicast",
934 "Enter Address Family command mode\n"
935 "Address family\n"
936 "Address Family Modifier\n")
937{
938 vty->node = BGP_IPV6_NODE;
939 return CMD_SUCCESS;
940}
941
paul57b5b7e2005-08-22 22:44:29 +0000942DEFUNSH (VTYSH_BGPD,
943 address_family_ipv6_multicast,
944 address_family_ipv6_multicast_cmd,
945 "address-family ipv6 multicast",
946 "Enter Address Family command mode\n"
947 "Address family\n"
948 "Address Family Modifier\n")
949{
950 vty->node = BGP_IPV6M_NODE;
951 return CMD_SUCCESS;
952}
953
paul718e3742002-12-13 20:15:29 +0000954DEFUNSH (VTYSH_RIPD,
955 key_chain,
956 key_chain_cmd,
957 "key chain WORD",
958 "Authentication key management\n"
959 "Key-chain management\n"
960 "Key-chain name\n")
961{
962 vty->node = KEYCHAIN_NODE;
963 return CMD_SUCCESS;
964}
965
966DEFUNSH (VTYSH_RIPD,
967 key,
968 key_cmd,
969 "key <0-2147483647>",
970 "Configure a key\n"
971 "Key identifier number\n")
972{
973 vty->node = KEYCHAIN_KEY_NODE;
974 return CMD_SUCCESS;
975}
976
977DEFUNSH (VTYSH_RIPD,
978 router_rip,
979 router_rip_cmd,
980 "router rip",
981 ROUTER_STR
982 "RIP")
983{
984 vty->node = RIP_NODE;
985 return CMD_SUCCESS;
986}
987
988DEFUNSH (VTYSH_RIPNGD,
989 router_ripng,
990 router_ripng_cmd,
991 "router ripng",
992 ROUTER_STR
993 "RIPng")
994{
995 vty->node = RIPNG_NODE;
996 return CMD_SUCCESS;
997}
998
999DEFUNSH (VTYSH_OSPFD,
1000 router_ospf,
1001 router_ospf_cmd,
1002 "router ospf",
1003 "Enable a routing process\n"
1004 "Start OSPF configuration\n")
1005{
1006 vty->node = OSPF_NODE;
1007 return CMD_SUCCESS;
1008}
1009
1010DEFUNSH (VTYSH_OSPF6D,
1011 router_ospf6,
1012 router_ospf6_cmd,
1013 "router ospf6",
1014 OSPF6_ROUTER_STR
1015 OSPF6_STR)
1016{
1017 vty->node = OSPF6_NODE;
1018 return CMD_SUCCESS;
1019}
1020
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +01001021DEFUNSH (VTYSH_BABELD,
1022 router_babel,
1023 router_babel_cmd,
1024 "router babel",
1025 ROUTER_STR
1026 "Babel")
1027{
1028 vty->node = BABEL_NODE;
1029 return CMD_SUCCESS;
1030}
1031
hassoc25e4582003-12-23 10:39:08 +00001032DEFUNSH (VTYSH_ISISD,
hassob094d262004-08-25 12:22:00 +00001033 router_isis,
1034 router_isis_cmd,
1035 "router isis WORD",
1036 ROUTER_STR
1037 "ISO IS-IS\n"
1038 "ISO Routing area tag")
hassoc25e4582003-12-23 10:39:08 +00001039{
1040 vty->node = ISIS_NODE;
1041 return CMD_SUCCESS;
1042}
1043
paul718e3742002-12-13 20:15:29 +00001044DEFUNSH (VTYSH_RMAP,
1045 route_map,
1046 route_map_cmd,
1047 "route-map WORD (deny|permit) <1-65535>",
1048 "Create route-map or enter route-map command mode\n"
1049 "Route map tag\n"
1050 "Route map denies set operations\n"
1051 "Route map permits set operations\n"
1052 "Sequence to insert to/delete from existing route-map entry\n")
1053{
1054 vty->node = RMAP_NODE;
1055 return CMD_SUCCESS;
1056}
1057
paul718e3742002-12-13 20:15:29 +00001058DEFUNSH (VTYSH_ALL,
hassoe7168df2004-10-03 20:11:32 +00001059 vtysh_line_vty,
1060 vtysh_line_vty_cmd,
1061 "line vty",
1062 "Configure a terminal line\n"
1063 "Virtual terminal\n")
1064{
1065 vty->node = VTY_NODE;
1066 return CMD_SUCCESS;
1067}
1068
1069DEFUNSH (VTYSH_ALL,
paul718e3742002-12-13 20:15:29 +00001070 vtysh_enable,
1071 vtysh_enable_cmd,
1072 "enable",
1073 "Turn on privileged mode command\n")
1074{
1075 vty->node = ENABLE_NODE;
1076 return CMD_SUCCESS;
1077}
1078
paul718e3742002-12-13 20:15:29 +00001079DEFUNSH (VTYSH_ALL,
1080 vtysh_disable,
1081 vtysh_disable_cmd,
1082 "disable",
1083 "Turn off privileged mode command\n")
1084{
1085 if (vty->node == ENABLE_NODE)
1086 vty->node = VIEW_NODE;
1087 return CMD_SUCCESS;
1088}
1089
paul718e3742002-12-13 20:15:29 +00001090DEFUNSH (VTYSH_ALL,
1091 vtysh_config_terminal,
1092 vtysh_config_terminal_cmd,
1093 "configure terminal",
1094 "Configuration from vty interface\n"
1095 "Configuration terminal\n")
1096{
1097 vty->node = CONFIG_NODE;
1098 return CMD_SUCCESS;
1099}
1100
ajs274a4a42004-12-07 15:39:31 +00001101static int
paul718e3742002-12-13 20:15:29 +00001102vtysh_exit (struct vty *vty)
1103{
1104 switch (vty->node)
1105 {
1106 case VIEW_NODE:
1107 case ENABLE_NODE:
1108 exit (0);
1109 break;
1110 case CONFIG_NODE:
1111 vty->node = ENABLE_NODE;
1112 break;
1113 case INTERFACE_NODE:
1114 case ZEBRA_NODE:
1115 case BGP_NODE:
1116 case RIP_NODE:
1117 case RIPNG_NODE:
1118 case OSPF_NODE:
1119 case OSPF6_NODE:
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +01001120 case BABEL_NODE:
hassoc25e4582003-12-23 10:39:08 +00001121 case ISIS_NODE:
paul718e3742002-12-13 20:15:29 +00001122 case MASC_NODE:
1123 case RMAP_NODE:
1124 case VTY_NODE:
1125 case KEYCHAIN_NODE:
hasso2a56df92004-05-09 23:16:40 +00001126 vtysh_execute("end");
1127 vtysh_execute("configure terminal");
paul718e3742002-12-13 20:15:29 +00001128 vty->node = CONFIG_NODE;
1129 break;
1130 case BGP_VPNV4_NODE:
1131 case BGP_IPV4_NODE:
1132 case BGP_IPV4M_NODE:
1133 case BGP_IPV6_NODE:
paul57b5b7e2005-08-22 22:44:29 +00001134 case BGP_IPV6M_NODE:
paul718e3742002-12-13 20:15:29 +00001135 vty->node = BGP_NODE;
1136 break;
1137 case KEYCHAIN_KEY_NODE:
1138 vty->node = KEYCHAIN_NODE;
1139 break;
1140 default:
1141 break;
1142 }
1143 return CMD_SUCCESS;
1144}
1145
1146DEFUNSH (VTYSH_ALL,
1147 vtysh_exit_all,
1148 vtysh_exit_all_cmd,
1149 "exit",
1150 "Exit current mode and down to previous mode\n")
1151{
1152 return vtysh_exit (vty);
1153}
1154
1155ALIAS (vtysh_exit_all,
1156 vtysh_quit_all_cmd,
1157 "quit",
1158 "Exit current mode and down to previous mode\n")
1159
1160DEFUNSH (VTYSH_BGPD,
1161 exit_address_family,
1162 exit_address_family_cmd,
1163 "exit-address-family",
1164 "Exit from Address Family configuration mode\n")
1165{
1166 if (vty->node == BGP_IPV4_NODE
1167 || vty->node == BGP_IPV4M_NODE
1168 || vty->node == BGP_VPNV4_NODE
paul57b5b7e2005-08-22 22:44:29 +00001169 || vty->node == BGP_IPV6_NODE
1170 || vty->node == BGP_IPV6M_NODE)
paul718e3742002-12-13 20:15:29 +00001171 vty->node = BGP_NODE;
1172 return CMD_SUCCESS;
1173}
1174
1175DEFUNSH (VTYSH_ZEBRA,
1176 vtysh_exit_zebra,
1177 vtysh_exit_zebra_cmd,
1178 "exit",
1179 "Exit current mode and down to previous mode\n")
1180{
1181 return vtysh_exit (vty);
1182}
1183
1184ALIAS (vtysh_exit_zebra,
1185 vtysh_quit_zebra_cmd,
1186 "quit",
1187 "Exit current mode and down to previous mode\n")
1188
1189DEFUNSH (VTYSH_RIPD,
1190 vtysh_exit_ripd,
1191 vtysh_exit_ripd_cmd,
1192 "exit",
1193 "Exit current mode and down to previous mode\n")
1194{
1195 return vtysh_exit (vty);
1196}
1197
1198ALIAS (vtysh_exit_ripd,
1199 vtysh_quit_ripd_cmd,
1200 "quit",
1201 "Exit current mode and down to previous mode\n")
1202
paul68980082003-03-25 05:07:42 +00001203DEFUNSH (VTYSH_RIPNGD,
hassob094d262004-08-25 12:22:00 +00001204 vtysh_exit_ripngd,
1205 vtysh_exit_ripngd_cmd,
1206 "exit",
1207 "Exit current mode and down to previous mode\n")
paul68980082003-03-25 05:07:42 +00001208{
1209 return vtysh_exit (vty);
1210}
1211
1212ALIAS (vtysh_exit_ripngd,
1213 vtysh_quit_ripngd_cmd,
1214 "quit",
1215 "Exit current mode and down to previous mode\n")
1216
paul718e3742002-12-13 20:15:29 +00001217DEFUNSH (VTYSH_RMAP,
1218 vtysh_exit_rmap,
1219 vtysh_exit_rmap_cmd,
1220 "exit",
1221 "Exit current mode and down to previous mode\n")
1222{
1223 return vtysh_exit (vty);
1224}
1225
1226ALIAS (vtysh_exit_rmap,
1227 vtysh_quit_rmap_cmd,
1228 "quit",
1229 "Exit current mode and down to previous mode\n")
1230
1231DEFUNSH (VTYSH_BGPD,
1232 vtysh_exit_bgpd,
1233 vtysh_exit_bgpd_cmd,
1234 "exit",
1235 "Exit current mode and down to previous mode\n")
1236{
1237 return vtysh_exit (vty);
1238}
1239
1240ALIAS (vtysh_exit_bgpd,
1241 vtysh_quit_bgpd_cmd,
1242 "quit",
1243 "Exit current mode and down to previous mode\n")
1244
1245DEFUNSH (VTYSH_OSPFD,
1246 vtysh_exit_ospfd,
1247 vtysh_exit_ospfd_cmd,
1248 "exit",
1249 "Exit current mode and down to previous mode\n")
1250{
1251 return vtysh_exit (vty);
1252}
1253
1254ALIAS (vtysh_exit_ospfd,
1255 vtysh_quit_ospfd_cmd,
1256 "quit",
1257 "Exit current mode and down to previous mode\n")
1258
paul68980082003-03-25 05:07:42 +00001259DEFUNSH (VTYSH_OSPF6D,
hassob094d262004-08-25 12:22:00 +00001260 vtysh_exit_ospf6d,
1261 vtysh_exit_ospf6d_cmd,
1262 "exit",
1263 "Exit current mode and down to previous mode\n")
paul68980082003-03-25 05:07:42 +00001264{
1265 return vtysh_exit (vty);
1266}
1267
1268ALIAS (vtysh_exit_ospf6d,
1269 vtysh_quit_ospf6d_cmd,
1270 "quit",
1271 "Exit current mode and down to previous mode\n")
1272
hassoc25e4582003-12-23 10:39:08 +00001273DEFUNSH (VTYSH_ISISD,
hassob094d262004-08-25 12:22:00 +00001274 vtysh_exit_isisd,
1275 vtysh_exit_isisd_cmd,
1276 "exit",
1277 "Exit current mode and down to previous mode\n")
hassoc25e4582003-12-23 10:39:08 +00001278{
1279 return vtysh_exit (vty);
1280}
1281
1282ALIAS (vtysh_exit_isisd,
1283 vtysh_quit_isisd_cmd,
1284 "quit",
1285 "Exit current mode and down to previous mode\n")
1286
hassoe7168df2004-10-03 20:11:32 +00001287DEFUNSH (VTYSH_ALL,
1288 vtysh_exit_line_vty,
1289 vtysh_exit_line_vty_cmd,
1290 "exit",
1291 "Exit current mode and down to previous mode\n")
1292{
1293 return vtysh_exit (vty);
1294}
1295
1296ALIAS (vtysh_exit_line_vty,
1297 vtysh_quit_line_vty_cmd,
1298 "quit",
1299 "Exit current mode and down to previous mode\n")
1300
hasso95e735b2004-08-26 13:08:30 +00001301DEFUNSH (VTYSH_INTERFACE,
paul718e3742002-12-13 20:15:29 +00001302 vtysh_interface,
1303 vtysh_interface_cmd,
1304 "interface IFNAME",
1305 "Select an interface to configure\n"
1306 "Interface's name\n")
1307{
1308 vty->node = INTERFACE_NODE;
1309 return CMD_SUCCESS;
1310}
1311
hasso95e735b2004-08-26 13:08:30 +00001312/* TODO Implement "no interface command in isisd. */
paul32d24632003-05-23 09:25:20 +00001313DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D,
1314 vtysh_no_interface_cmd,
1315 "no interface IFNAME",
1316 NO_STR
1317 "Delete a pseudo interface's configuration\n"
1318 "Interface's name\n")
1319
hasso95e735b2004-08-26 13:08:30 +00001320/* TODO Implement interface description commands in ripngd, ospf6d
1321 * and isisd. */
paul338a9912003-03-01 15:44:10 +00001322DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1323 interface_desc_cmd,
1324 "description .LINE",
1325 "Interface specific description\n"
1326 "Characters describing this interface\n")
paul464dc8d2003-03-28 02:25:45 +00001327
1328DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1329 no_interface_desc_cmd,
1330 "no description",
1331 NO_STR
1332 "Interface specific description\n")
paul338a9912003-03-01 15:44:10 +00001333
hasso95e735b2004-08-26 13:08:30 +00001334DEFUNSH (VTYSH_INTERFACE,
paul718e3742002-12-13 20:15:29 +00001335 vtysh_exit_interface,
1336 vtysh_exit_interface_cmd,
1337 "exit",
1338 "Exit current mode and down to previous mode\n")
1339{
1340 return vtysh_exit (vty);
1341}
1342
1343ALIAS (vtysh_exit_interface,
1344 vtysh_quit_interface_cmd,
1345 "quit",
1346 "Exit current mode and down to previous mode\n")
1347
Paul Jakma362b4032006-05-28 07:54:45 +00001348/* Memory */
1349DEFUN (vtysh_show_memory,
1350 vtysh_show_memory_cmd,
1351 "show memory",
1352 SHOW_STR
1353 "Memory statistics\n")
1354{
1355 unsigned int i;
1356 int ret = CMD_SUCCESS;
1357 char line[] = "show memory\n";
1358
Balaji.G837d16c2012-09-26 14:09:10 +05301359 for (i = 0; i < array_size(vtysh_client); i++)
Paul Jakma362b4032006-05-28 07:54:45 +00001360 if ( vtysh_client[i].fd >= 0 )
1361 {
1362 fprintf (stdout, "Memory statistics for %s:\n",
1363 vtysh_client[i].name);
1364 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1365 fprintf (stdout,"\n");
1366 }
1367
1368 return ret;
1369}
1370
hasso95e735b2004-08-26 13:08:30 +00001371/* Logging commands. */
Paul Jakmadbf7d132006-05-23 22:10:01 +00001372DEFUN (vtysh_show_logging,
1373 vtysh_show_logging_cmd,
1374 "show logging",
1375 SHOW_STR
1376 "Show current logging configuration\n")
1377{
1378 unsigned int i;
1379 int ret = CMD_SUCCESS;
1380 char line[] = "show logging\n";
1381
Balaji.G837d16c2012-09-26 14:09:10 +05301382 for (i = 0; i < array_size(vtysh_client); i++)
Paul Jakma4150f332006-05-23 22:10:55 +00001383 if ( vtysh_client[i].fd >= 0 )
1384 {
1385 fprintf (stdout,"Logging configuration for %s:\n",
1386 vtysh_client[i].name);
1387 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1388 fprintf (stdout,"\n");
1389 }
1390
Paul Jakmadbf7d132006-05-23 22:10:01 +00001391 return ret;
1392}
1393
hasso95e735b2004-08-26 13:08:30 +00001394DEFUNSH (VTYSH_ALL,
1395 vtysh_log_stdout,
1396 vtysh_log_stdout_cmd,
1397 "log stdout",
1398 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001399 "Set stdout logging level\n")
1400{
1401 return CMD_SUCCESS;
1402}
1403
1404DEFUNSH (VTYSH_ALL,
1405 vtysh_log_stdout_level,
1406 vtysh_log_stdout_level_cmd,
1407 "log stdout "LOG_LEVELS,
1408 "Logging control\n"
1409 "Set stdout logging level\n"
1410 LOG_LEVEL_DESC)
hasso95e735b2004-08-26 13:08:30 +00001411{
1412 return CMD_SUCCESS;
1413}
1414
1415DEFUNSH (VTYSH_ALL,
1416 no_vtysh_log_stdout,
1417 no_vtysh_log_stdout_cmd,
ajs274a4a42004-12-07 15:39:31 +00001418 "no log stdout [LEVEL]",
hasso95e735b2004-08-26 13:08:30 +00001419 NO_STR
1420 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001421 "Cancel logging to stdout\n"
1422 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001423{
1424 return CMD_SUCCESS;
1425}
1426
1427DEFUNSH (VTYSH_ALL,
1428 vtysh_log_file,
1429 vtysh_log_file_cmd,
1430 "log file FILENAME",
1431 "Logging control\n"
1432 "Logging to file\n"
1433 "Logging filename\n")
1434{
1435 return CMD_SUCCESS;
1436}
1437
1438DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001439 vtysh_log_file_level,
1440 vtysh_log_file_level_cmd,
1441 "log file FILENAME "LOG_LEVELS,
1442 "Logging control\n"
1443 "Logging to file\n"
1444 "Logging filename\n"
1445 LOG_LEVEL_DESC)
1446{
1447 return CMD_SUCCESS;
1448}
1449
1450DEFUNSH (VTYSH_ALL,
hasso95e735b2004-08-26 13:08:30 +00001451 no_vtysh_log_file,
1452 no_vtysh_log_file_cmd,
1453 "no log file [FILENAME]",
1454 NO_STR
1455 "Logging control\n"
1456 "Cancel logging to file\n"
1457 "Logging file name\n")
1458{
1459 return CMD_SUCCESS;
1460}
1461
ajs274a4a42004-12-07 15:39:31 +00001462ALIAS_SH (VTYSH_ALL,
1463 no_vtysh_log_file,
1464 no_vtysh_log_file_level_cmd,
1465 "no log file FILENAME LEVEL",
1466 NO_STR
1467 "Logging control\n"
1468 "Cancel logging to file\n"
1469 "Logging file name\n"
1470 "Logging level\n")
1471
1472DEFUNSH (VTYSH_ALL,
1473 vtysh_log_monitor,
1474 vtysh_log_monitor_cmd,
1475 "log monitor",
1476 "Logging control\n"
1477 "Set terminal line (monitor) logging level\n")
1478{
1479 return CMD_SUCCESS;
1480}
1481
1482DEFUNSH (VTYSH_ALL,
1483 vtysh_log_monitor_level,
1484 vtysh_log_monitor_level_cmd,
1485 "log monitor "LOG_LEVELS,
1486 "Logging control\n"
1487 "Set terminal line (monitor) logging level\n"
1488 LOG_LEVEL_DESC)
1489{
1490 return CMD_SUCCESS;
1491}
1492
1493DEFUNSH (VTYSH_ALL,
1494 no_vtysh_log_monitor,
1495 no_vtysh_log_monitor_cmd,
1496 "no log monitor [LEVEL]",
1497 NO_STR
1498 "Logging control\n"
1499 "Disable terminal line (monitor) logging\n"
1500 "Logging level\n")
1501{
1502 return CMD_SUCCESS;
1503}
1504
hasso95e735b2004-08-26 13:08:30 +00001505DEFUNSH (VTYSH_ALL,
1506 vtysh_log_syslog,
1507 vtysh_log_syslog_cmd,
1508 "log syslog",
1509 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001510 "Set syslog logging level\n")
1511{
1512 return CMD_SUCCESS;
1513}
1514
1515DEFUNSH (VTYSH_ALL,
1516 vtysh_log_syslog_level,
1517 vtysh_log_syslog_level_cmd,
1518 "log syslog "LOG_LEVELS,
1519 "Logging control\n"
1520 "Set syslog logging level\n"
1521 LOG_LEVEL_DESC)
hasso95e735b2004-08-26 13:08:30 +00001522{
1523 return CMD_SUCCESS;
1524}
1525
1526DEFUNSH (VTYSH_ALL,
1527 no_vtysh_log_syslog,
1528 no_vtysh_log_syslog_cmd,
ajs274a4a42004-12-07 15:39:31 +00001529 "no log syslog [LEVEL]",
hasso95e735b2004-08-26 13:08:30 +00001530 NO_STR
1531 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001532 "Cancel logging to syslog\n"
1533 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001534{
1535 return CMD_SUCCESS;
1536}
1537
1538DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001539 vtysh_log_facility,
1540 vtysh_log_facility_cmd,
1541 "log facility "LOG_FACILITIES,
hasso95e735b2004-08-26 13:08:30 +00001542 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001543 "Facility parameter for syslog messages\n"
1544 LOG_FACILITY_DESC)
1545
hasso95e735b2004-08-26 13:08:30 +00001546{
1547 return CMD_SUCCESS;
1548}
1549
1550DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001551 no_vtysh_log_facility,
1552 no_vtysh_log_facility_cmd,
1553 "no log facility [FACILITY]",
hasso95e735b2004-08-26 13:08:30 +00001554 NO_STR
1555 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001556 "Reset syslog facility to default (daemon)\n"
1557 "Syslog facility\n")
1558
1559{
1560 return CMD_SUCCESS;
1561}
1562
1563DEFUNSH_DEPRECATED (VTYSH_ALL,
1564 vtysh_log_trap,
1565 vtysh_log_trap_cmd,
1566 "log trap "LOG_LEVELS,
1567 "Logging control\n"
1568 "(Deprecated) Set logging level and default for all destinations\n"
1569 LOG_LEVEL_DESC)
1570
1571{
1572 return CMD_SUCCESS;
1573}
1574
1575DEFUNSH_DEPRECATED (VTYSH_ALL,
1576 no_vtysh_log_trap,
1577 no_vtysh_log_trap_cmd,
1578 "no log trap [LEVEL]",
1579 NO_STR
1580 "Logging control\n"
1581 "Permit all logging information\n"
1582 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001583{
1584 return CMD_SUCCESS;
1585}
1586
1587DEFUNSH (VTYSH_ALL,
1588 vtysh_log_record_priority,
1589 vtysh_log_record_priority_cmd,
1590 "log record-priority",
1591 "Logging control\n"
1592 "Log the priority of the message within the message\n")
1593{
1594 return CMD_SUCCESS;
1595}
1596
1597DEFUNSH (VTYSH_ALL,
1598 no_vtysh_log_record_priority,
1599 no_vtysh_log_record_priority_cmd,
1600 "no log record-priority",
1601 NO_STR
1602 "Logging control\n"
1603 "Do not log the priority of the message within the message\n")
1604{
1605 return CMD_SUCCESS;
1606}
1607
hassoe7168df2004-10-03 20:11:32 +00001608DEFUNSH (VTYSH_ALL,
Andrew J. Schorrc749b722007-04-29 03:53:31 +00001609 vtysh_log_timestamp_precision,
1610 vtysh_log_timestamp_precision_cmd,
1611 "log timestamp precision <0-6>",
1612 "Logging control\n"
1613 "Timestamp configuration\n"
1614 "Set the timestamp precision\n"
1615 "Number of subsecond digits\n")
1616{
1617 return CMD_SUCCESS;
1618}
1619
1620DEFUNSH (VTYSH_ALL,
1621 no_vtysh_log_timestamp_precision,
1622 no_vtysh_log_timestamp_precision_cmd,
1623 "no log timestamp precision",
1624 NO_STR
1625 "Logging control\n"
1626 "Timestamp configuration\n"
1627 "Reset the timestamp precision to the default value of 0\n")
1628{
1629 return CMD_SUCCESS;
1630}
1631
1632DEFUNSH (VTYSH_ALL,
hassoe7168df2004-10-03 20:11:32 +00001633 vtysh_service_password_encrypt,
1634 vtysh_service_password_encrypt_cmd,
1635 "service password-encryption",
1636 "Set up miscellaneous service\n"
1637 "Enable encrypted passwords\n")
1638{
1639 return CMD_SUCCESS;
1640}
1641
1642DEFUNSH (VTYSH_ALL,
1643 no_vtysh_service_password_encrypt,
1644 no_vtysh_service_password_encrypt_cmd,
1645 "no service password-encryption",
1646 NO_STR
1647 "Set up miscellaneous service\n"
1648 "Enable encrypted passwords\n")
1649{
1650 return CMD_SUCCESS;
1651}
1652
1653DEFUNSH (VTYSH_ALL,
1654 vtysh_config_password,
1655 vtysh_password_cmd,
1656 "password (8|) WORD",
1657 "Assign the terminal connection password\n"
1658 "Specifies a HIDDEN password will follow\n"
1659 "dummy string \n"
1660 "The HIDDEN line password string\n")
1661{
1662 return CMD_SUCCESS;
1663}
1664
1665DEFUNSH (VTYSH_ALL,
1666 vtysh_password_text,
1667 vtysh_password_text_cmd,
1668 "password LINE",
1669 "Assign the terminal connection password\n"
1670 "The UNENCRYPTED (cleartext) line password\n")
1671{
1672 return CMD_SUCCESS;
1673}
1674
1675DEFUNSH (VTYSH_ALL,
1676 vtysh_config_enable_password,
1677 vtysh_enable_password_cmd,
1678 "enable password (8|) WORD",
1679 "Modify enable password parameters\n"
1680 "Assign the privileged level password\n"
1681 "Specifies a HIDDEN password will follow\n"
1682 "dummy string \n"
1683 "The HIDDEN 'enable' password string\n")
1684{
1685 return CMD_SUCCESS;
1686}
1687
1688DEFUNSH (VTYSH_ALL,
1689 vtysh_enable_password_text,
1690 vtysh_enable_password_text_cmd,
1691 "enable password LINE",
1692 "Modify enable password parameters\n"
1693 "Assign the privileged level password\n"
1694 "The UNENCRYPTED (cleartext) 'enable' password\n")
1695{
1696 return CMD_SUCCESS;
1697}
1698
1699DEFUNSH (VTYSH_ALL,
1700 no_vtysh_config_enable_password,
1701 no_vtysh_enable_password_cmd,
1702 "no enable password",
1703 NO_STR
1704 "Modify enable password parameters\n"
1705 "Assign the privileged level password\n")
1706{
1707 return CMD_SUCCESS;
1708}
1709
paul718e3742002-12-13 20:15:29 +00001710DEFUN (vtysh_write_terminal,
1711 vtysh_write_terminal_cmd,
1712 "write terminal",
1713 "Write running configuration to memory, network, or terminal\n"
1714 "Write to terminal\n")
1715{
ajsb1aa1472005-01-28 21:11:46 +00001716 u_int i;
paul718e3742002-12-13 20:15:29 +00001717 int ret;
1718 char line[] = "write terminal\n";
1719 FILE *fp = NULL;
1720
1721 if (vtysh_pager_name)
1722 {
paul4fc01e62002-12-13 20:49:00 +00001723 fp = popen (vtysh_pager_name, "w");
paul718e3742002-12-13 20:15:29 +00001724 if (fp == NULL)
1725 {
1726 perror ("popen");
1727 exit (1);
1728 }
1729 }
1730 else
1731 fp = stdout;
1732
1733 vty_out (vty, "Building configuration...%s", VTY_NEWLINE);
1734 vty_out (vty, "%sCurrent configuration:%s", VTY_NEWLINE,
1735 VTY_NEWLINE);
hassoe7168df2004-10-03 20:11:32 +00001736 vty_out (vty, "!%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001737
Balaji.G837d16c2012-09-26 14:09:10 +05301738 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00001739 ret = vtysh_client_config (&vtysh_client[i], line);
paul718e3742002-12-13 20:15:29 +00001740
hassoe7168df2004-10-03 20:11:32 +00001741 /* Integrate vtysh specific configuration. */
1742 vtysh_config_write ();
1743
paul718e3742002-12-13 20:15:29 +00001744 vtysh_config_dump (fp);
1745
1746 if (vtysh_pager_name && fp)
1747 {
1748 fflush (fp);
1749 if (pclose (fp) == -1)
1750 {
1751 perror ("pclose");
1752 exit (1);
1753 }
1754 fp = NULL;
1755 }
1756
Chris Caputo6e79f8b2009-06-23 05:55:57 +00001757 vty_out (vty, "end%s", VTY_NEWLINE);
1758
paul718e3742002-12-13 20:15:29 +00001759 return CMD_SUCCESS;
1760}
1761
hassoe7168df2004-10-03 20:11:32 +00001762DEFUN (vtysh_integrated_config,
1763 vtysh_integrated_config_cmd,
1764 "service integrated-vtysh-config",
1765 "Set up miscellaneous service\n"
1766 "Write configuration into integrated file\n")
paul4fc01e62002-12-13 20:49:00 +00001767{
hassoe7168df2004-10-03 20:11:32 +00001768 vtysh_writeconfig_integrated = 1;
1769 return CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001770}
1771
hassoe7168df2004-10-03 20:11:32 +00001772DEFUN (no_vtysh_integrated_config,
1773 no_vtysh_integrated_config_cmd,
1774 "no service integrated-vtysh-config",
1775 NO_STR
1776 "Set up miscellaneous service\n"
1777 "Write configuration into integrated file\n")
paul4fc01e62002-12-13 20:49:00 +00001778{
hassoe7168df2004-10-03 20:11:32 +00001779 vtysh_writeconfig_integrated = 0;
1780 return CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001781}
1782
ajs274a4a42004-12-07 15:39:31 +00001783static int
1784write_config_integrated(void)
paul718e3742002-12-13 20:15:29 +00001785{
ajsb1aa1472005-01-28 21:11:46 +00001786 u_int i;
paul718e3742002-12-13 20:15:29 +00001787 int ret;
paul718e3742002-12-13 20:15:29 +00001788 char line[] = "write terminal\n";
1789 FILE *fp;
1790 char *integrate_sav = NULL;
1791
hasso95e735b2004-08-26 13:08:30 +00001792 integrate_sav = malloc (strlen (integrate_default) +
1793 strlen (CONF_BACKUP_EXT) + 1);
paul718e3742002-12-13 20:15:29 +00001794 strcpy (integrate_sav, integrate_default);
1795 strcat (integrate_sav, CONF_BACKUP_EXT);
1796
paul4fc01e62002-12-13 20:49:00 +00001797 fprintf (stdout,"Building Configuration...\n");
paul718e3742002-12-13 20:15:29 +00001798
hasso95e735b2004-08-26 13:08:30 +00001799 /* Move current configuration file to backup config file. */
paul718e3742002-12-13 20:15:29 +00001800 unlink (integrate_sav);
1801 rename (integrate_default, integrate_sav);
hasso95e735b2004-08-26 13:08:30 +00001802 free (integrate_sav);
paul4fc01e62002-12-13 20:49:00 +00001803
paul718e3742002-12-13 20:15:29 +00001804 fp = fopen (integrate_default, "w");
1805 if (fp == NULL)
1806 {
hasso95e735b2004-08-26 13:08:30 +00001807 fprintf (stdout,"%% Can't open configuration file %s.\n",
1808 integrate_default);
paul718e3742002-12-13 20:15:29 +00001809 return CMD_SUCCESS;
1810 }
paul718e3742002-12-13 20:15:29 +00001811
Balaji.G837d16c2012-09-26 14:09:10 +05301812 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00001813 ret = vtysh_client_config (&vtysh_client[i], line);
paul718e3742002-12-13 20:15:29 +00001814
1815 vtysh_config_dump (fp);
1816
1817 fclose (fp);
1818
gdtaa593d52003-12-22 20:15:53 +00001819 if (chmod (integrate_default, CONFIGFILE_MASK) != 0)
1820 {
1821 fprintf (stdout,"%% Can't chmod configuration file %s: %s (%d)\n",
ajs6099b3b2004-11-20 02:06:59 +00001822 integrate_default, safe_strerror(errno), errno);
gdtaa593d52003-12-22 20:15:53 +00001823 return CMD_WARNING;
1824 }
1825
paul4fc01e62002-12-13 20:49:00 +00001826 fprintf(stdout,"Integrated configuration saved to %s\n",integrate_default);
1827
1828 fprintf (stdout,"[OK]\n");
1829
paul718e3742002-12-13 20:15:29 +00001830 return CMD_SUCCESS;
1831}
1832
paul4fc01e62002-12-13 20:49:00 +00001833DEFUN (vtysh_write_memory,
1834 vtysh_write_memory_cmd,
1835 "write memory",
1836 "Write running configuration to memory, network, or terminal\n"
1837 "Write configuration to the file (same as write file)\n")
1838{
pauldfc0d9b2003-04-18 23:55:29 +00001839 int ret = CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001840 char line[] = "write memory\n";
ajsb1aa1472005-01-28 21:11:46 +00001841 u_int i;
paul4fc01e62002-12-13 20:49:00 +00001842
hassoe7168df2004-10-03 20:11:32 +00001843 /* If integrated Quagga.conf explicitely set. */
1844 if (vtysh_writeconfig_integrated)
1845 return write_config_integrated();
paul4fc01e62002-12-13 20:49:00 +00001846
1847 fprintf (stdout,"Building Configuration...\n");
1848
Balaji.G837d16c2012-09-26 14:09:10 +05301849 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00001850 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
hassoe7168df2004-10-03 20:11:32 +00001851
paul4fc01e62002-12-13 20:49:00 +00001852 fprintf (stdout,"[OK]\n");
1853
pauldfc0d9b2003-04-18 23:55:29 +00001854 return ret;
paul4fc01e62002-12-13 20:49:00 +00001855}
1856
paul718e3742002-12-13 20:15:29 +00001857ALIAS (vtysh_write_memory,
1858 vtysh_copy_runningconfig_startupconfig_cmd,
1859 "copy running-config startup-config",
1860 "Copy from one file to another\n"
1861 "Copy from current system configuration\n"
1862 "Copy to startup configuration\n")
1863
1864ALIAS (vtysh_write_memory,
1865 vtysh_write_file_cmd,
1866 "write file",
1867 "Write running configuration to memory, network, or terminal\n"
1868 "Write configuration to the file (same as write memory)\n")
1869
hasso4a6e2252003-05-25 11:51:29 +00001870ALIAS (vtysh_write_memory,
1871 vtysh_write_cmd,
1872 "write",
1873 "Write running configuration to memory, network, or terminal\n")
1874
paul718e3742002-12-13 20:15:29 +00001875ALIAS (vtysh_write_terminal,
1876 vtysh_show_running_config_cmd,
1877 "show running-config",
1878 SHOW_STR
1879 "Current operating configuration\n")
hassob094d262004-08-25 12:22:00 +00001880
hasso34553cc2004-08-27 13:56:39 +00001881DEFUN (vtysh_terminal_length,
1882 vtysh_terminal_length_cmd,
1883 "terminal length <0-512>",
1884 "Set terminal line parameters\n"
1885 "Set number of lines on a screen\n"
1886 "Number of lines on screen (0 for no pausing)\n")
1887{
1888 int lines;
1889 char *endptr = NULL;
1890 char default_pager[10];
1891
1892 lines = strtol (argv[0], &endptr, 10);
1893 if (lines < 0 || lines > 512 || *endptr != '\0')
1894 {
1895 vty_out (vty, "length is malformed%s", VTY_NEWLINE);
1896 return CMD_WARNING;
1897 }
1898
1899 if (vtysh_pager_name)
1900 {
1901 free (vtysh_pager_name);
1902 vtysh_pager_name = NULL;
1903 }
1904
1905 if (lines != 0)
1906 {
1907 snprintf(default_pager, 10, "more -%i", lines);
1908 vtysh_pager_name = strdup (default_pager);
1909 }
1910
1911 return CMD_SUCCESS;
1912}
1913
1914DEFUN (vtysh_terminal_no_length,
1915 vtysh_terminal_no_length_cmd,
1916 "terminal no length",
1917 "Set terminal line parameters\n"
1918 NO_STR
1919 "Set number of lines on a screen\n")
1920{
1921 if (vtysh_pager_name)
1922 {
1923 free (vtysh_pager_name);
1924 vtysh_pager_name = NULL;
1925 }
1926
1927 vtysh_pager_init();
1928 return CMD_SUCCESS;
1929}
1930
hassof2799e62004-10-28 17:43:11 +00001931DEFUN (vtysh_show_daemons,
1932 vtysh_show_daemons_cmd,
1933 "show daemons",
hassoe7168df2004-10-03 20:11:32 +00001934 SHOW_STR
1935 "Show list of running daemons\n")
1936{
ajsb1aa1472005-01-28 21:11:46 +00001937 u_int i;
1938
Balaji.G837d16c2012-09-26 14:09:10 +05301939 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00001940 if ( vtysh_client[i].fd >= 0 )
1941 vty_out(vty, " %s", vtysh_client[i].name);
hassoe7168df2004-10-03 20:11:32 +00001942 vty_out(vty, "%s", VTY_NEWLINE);
1943
1944 return CMD_SUCCESS;
1945}
1946
paul718e3742002-12-13 20:15:29 +00001947/* Execute command in child process. */
ajs274a4a42004-12-07 15:39:31 +00001948static int
hasso5862ff52004-10-11 13:20:40 +00001949execute_command (const char *command, int argc, const char *arg1,
1950 const char *arg2)
paul718e3742002-12-13 20:15:29 +00001951{
1952 int ret;
1953 pid_t pid;
1954 int status;
1955
1956 /* Call fork(). */
1957 pid = fork ();
1958
1959 if (pid < 0)
1960 {
1961 /* Failure of fork(). */
ajs6099b3b2004-11-20 02:06:59 +00001962 fprintf (stderr, "Can't fork: %s\n", safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +00001963 exit (1);
1964 }
1965 else if (pid == 0)
1966 {
1967 /* This is child process. */
1968 switch (argc)
1969 {
1970 case 0:
hassofa2b17e2004-03-04 17:45:00 +00001971 ret = execlp (command, command, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00001972 break;
1973 case 1:
hassofa2b17e2004-03-04 17:45:00 +00001974 ret = execlp (command, command, arg1, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00001975 break;
1976 case 2:
hassofa2b17e2004-03-04 17:45:00 +00001977 ret = execlp (command, command, arg1, arg2, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00001978 break;
1979 }
1980
1981 /* When execlp suceed, this part is not executed. */
ajs6099b3b2004-11-20 02:06:59 +00001982 fprintf (stderr, "Can't execute %s: %s\n", command, safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +00001983 exit (1);
1984 }
1985 else
1986 {
1987 /* This is parent. */
1988 execute_flag = 1;
1989 ret = wait4 (pid, &status, 0, NULL);
1990 execute_flag = 0;
1991 }
1992 return 0;
1993}
1994
1995DEFUN (vtysh_ping,
1996 vtysh_ping_cmd,
1997 "ping WORD",
hasso4eeccf12003-06-25 10:49:55 +00001998 "Send echo messages\n"
paul718e3742002-12-13 20:15:29 +00001999 "Ping destination address or hostname\n")
2000{
2001 execute_command ("ping", 1, argv[0], NULL);
2002 return CMD_SUCCESS;
2003}
2004
hasso4eeccf12003-06-25 10:49:55 +00002005ALIAS (vtysh_ping,
2006 vtysh_ping_ip_cmd,
2007 "ping ip WORD",
2008 "Send echo messages\n"
2009 "IP echo\n"
2010 "Ping destination address or hostname\n")
2011
paul718e3742002-12-13 20:15:29 +00002012DEFUN (vtysh_traceroute,
2013 vtysh_traceroute_cmd,
2014 "traceroute WORD",
2015 "Trace route to destination\n"
2016 "Trace route to destination address or hostname\n")
2017{
2018 execute_command ("traceroute", 1, argv[0], NULL);
2019 return CMD_SUCCESS;
2020}
2021
hasso4eeccf12003-06-25 10:49:55 +00002022ALIAS (vtysh_traceroute,
2023 vtysh_traceroute_ip_cmd,
2024 "traceroute ip WORD",
2025 "Trace route to destination\n"
2026 "IP trace\n"
2027 "Trace route to destination address or hostname\n")
2028
2029#ifdef HAVE_IPV6
2030DEFUN (vtysh_ping6,
2031 vtysh_ping6_cmd,
2032 "ping ipv6 WORD",
2033 "Send echo messages\n"
2034 "IPv6 echo\n"
2035 "Ping destination address or hostname\n")
2036{
2037 execute_command ("ping6", 1, argv[0], NULL);
2038 return CMD_SUCCESS;
2039}
2040
2041DEFUN (vtysh_traceroute6,
2042 vtysh_traceroute6_cmd,
2043 "traceroute ipv6 WORD",
2044 "Trace route to destination\n"
2045 "IPv6 trace\n"
2046 "Trace route to destination address or hostname\n")
2047{
2048 execute_command ("traceroute6", 1, argv[0], NULL);
2049 return CMD_SUCCESS;
2050}
2051#endif
2052
paul718e3742002-12-13 20:15:29 +00002053DEFUN (vtysh_telnet,
2054 vtysh_telnet_cmd,
2055 "telnet WORD",
2056 "Open a telnet connection\n"
2057 "IP address or hostname of a remote system\n")
2058{
2059 execute_command ("telnet", 1, argv[0], NULL);
2060 return CMD_SUCCESS;
2061}
2062
2063DEFUN (vtysh_telnet_port,
2064 vtysh_telnet_port_cmd,
2065 "telnet WORD PORT",
2066 "Open a telnet connection\n"
2067 "IP address or hostname of a remote system\n"
2068 "TCP Port number\n")
2069{
2070 execute_command ("telnet", 2, argv[0], argv[1]);
2071 return CMD_SUCCESS;
2072}
2073
paul5087df52003-01-25 06:56:09 +00002074DEFUN (vtysh_ssh,
2075 vtysh_ssh_cmd,
2076 "ssh WORD",
2077 "Open an ssh connection\n"
2078 "[user@]host\n")
2079{
2080 execute_command ("ssh", 1, argv[0], NULL);
2081 return CMD_SUCCESS;
2082}
2083
paul718e3742002-12-13 20:15:29 +00002084DEFUN (vtysh_start_shell,
2085 vtysh_start_shell_cmd,
2086 "start-shell",
2087 "Start UNIX shell\n")
2088{
2089 execute_command ("sh", 0, NULL, NULL);
2090 return CMD_SUCCESS;
2091}
2092
2093DEFUN (vtysh_start_bash,
2094 vtysh_start_bash_cmd,
2095 "start-shell bash",
2096 "Start UNIX shell\n"
2097 "Start bash\n")
2098{
2099 execute_command ("bash", 0, NULL, NULL);
2100 return CMD_SUCCESS;
2101}
2102
2103DEFUN (vtysh_start_zsh,
2104 vtysh_start_zsh_cmd,
2105 "start-shell zsh",
2106 "Start UNIX shell\n"
2107 "Start Z shell\n")
2108{
2109 execute_command ("zsh", 0, NULL, NULL);
2110 return CMD_SUCCESS;
2111}
hassob094d262004-08-25 12:22:00 +00002112
ajs274a4a42004-12-07 15:39:31 +00002113static void
paul718e3742002-12-13 20:15:29 +00002114vtysh_install_default (enum node_type node)
2115{
2116 install_element (node, &config_list_cmd);
2117}
2118
2119/* Making connection to protocol daemon. */
ajs274a4a42004-12-07 15:39:31 +00002120static int
ajsb1aa1472005-01-28 21:11:46 +00002121vtysh_connect (struct vtysh_client *vclient)
paul718e3742002-12-13 20:15:29 +00002122{
2123 int ret;
2124 int sock, len;
2125 struct sockaddr_un addr;
2126 struct stat s_stat;
paul718e3742002-12-13 20:15:29 +00002127
paul718e3742002-12-13 20:15:29 +00002128 /* Stat socket to see if we have permission to access it. */
ajsb1aa1472005-01-28 21:11:46 +00002129 ret = stat (vclient->path, &s_stat);
paul718e3742002-12-13 20:15:29 +00002130 if (ret < 0 && errno != ENOENT)
2131 {
2132 fprintf (stderr, "vtysh_connect(%s): stat = %s\n",
ajsb1aa1472005-01-28 21:11:46 +00002133 vclient->path, safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002134 exit(1);
2135 }
2136
2137 if (ret >= 0)
2138 {
2139 if (! S_ISSOCK(s_stat.st_mode))
2140 {
2141 fprintf (stderr, "vtysh_connect(%s): Not a socket\n",
ajsb1aa1472005-01-28 21:11:46 +00002142 vclient->path);
paul718e3742002-12-13 20:15:29 +00002143 exit (1);
2144 }
2145
paul718e3742002-12-13 20:15:29 +00002146 }
2147
2148 sock = socket (AF_UNIX, SOCK_STREAM, 0);
2149 if (sock < 0)
2150 {
2151#ifdef DEBUG
ajsb1aa1472005-01-28 21:11:46 +00002152 fprintf(stderr, "vtysh_connect(%s): socket = %s\n", vclient->path,
ajs6099b3b2004-11-20 02:06:59 +00002153 safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002154#endif /* DEBUG */
2155 return -1;
2156 }
2157
2158 memset (&addr, 0, sizeof (struct sockaddr_un));
2159 addr.sun_family = AF_UNIX;
ajsb1aa1472005-01-28 21:11:46 +00002160 strncpy (addr.sun_path, vclient->path, strlen (vclient->path));
Paul Jakma6f0e3f62007-05-10 02:38:51 +00002161#ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
paul718e3742002-12-13 20:15:29 +00002162 len = addr.sun_len = SUN_LEN(&addr);
2163#else
2164 len = sizeof (addr.sun_family) + strlen (addr.sun_path);
Paul Jakma6f0e3f62007-05-10 02:38:51 +00002165#endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
paul718e3742002-12-13 20:15:29 +00002166
2167 ret = connect (sock, (struct sockaddr *) &addr, len);
2168 if (ret < 0)
2169 {
2170#ifdef DEBUG
ajsb1aa1472005-01-28 21:11:46 +00002171 fprintf(stderr, "vtysh_connect(%s): connect = %s\n", vclient->path,
ajs6099b3b2004-11-20 02:06:59 +00002172 safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002173#endif /* DEBUG */
2174 close (sock);
2175 return -1;
2176 }
2177 vclient->fd = sock;
2178
2179 return 0;
2180}
2181
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002182int
2183vtysh_connect_all(const char *daemon_name)
paul718e3742002-12-13 20:15:29 +00002184{
ajsb1aa1472005-01-28 21:11:46 +00002185 u_int i;
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002186 int rc = 0;
2187 int matches = 0;
ajsb1aa1472005-01-28 21:11:46 +00002188
Balaji.G837d16c2012-09-26 14:09:10 +05302189 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00002190 {
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002191 if (!daemon_name || !strcmp(daemon_name, vtysh_client[i].name))
2192 {
2193 matches++;
2194 if (vtysh_connect(&vtysh_client[i]) == 0)
2195 rc++;
2196 /* We need direct access to ripd in vtysh_exit_ripd_only. */
2197 if (vtysh_client[i].flag == VTYSH_RIPD)
2198 ripd_client = &vtysh_client[i];
2199 }
ajsb1aa1472005-01-28 21:11:46 +00002200 }
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002201 if (!matches)
2202 fprintf(stderr, "Error: no daemons match name %s!\n", daemon_name);
2203 return rc;
paul718e3742002-12-13 20:15:29 +00002204}
2205
hasso95e735b2004-08-26 13:08:30 +00002206/* To disable readline's filename completion. */
ajs274a4a42004-12-07 15:39:31 +00002207static char *
pauldfc0d9b2003-04-18 23:55:29 +00002208vtysh_completion_entry_function (const char *ignore, int invoking_key)
paul718e3742002-12-13 20:15:29 +00002209{
pauldfc0d9b2003-04-18 23:55:29 +00002210 return NULL;
paul718e3742002-12-13 20:15:29 +00002211}
2212
2213void
ajsb1aa1472005-01-28 21:11:46 +00002214vtysh_readline_init (void)
paul718e3742002-12-13 20:15:29 +00002215{
2216 /* readline related settings. */
Sébastien Luttringer66d2ead2014-05-27 19:55:11 +02002217 rl_bind_key ('?', (rl_command_func_t *) vtysh_rl_describe);
paul68980082003-03-25 05:07:42 +00002218 rl_completion_entry_function = vtysh_completion_entry_function;
Sébastien Luttringer66d2ead2014-05-27 19:55:11 +02002219 rl_attempted_completion_function = (rl_completion_func_t *)new_completion;
paul718e3742002-12-13 20:15:29 +00002220}
2221
2222char *
ajsb1aa1472005-01-28 21:11:46 +00002223vtysh_prompt (void)
paul718e3742002-12-13 20:15:29 +00002224{
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002225 static struct utsname names;
paul718e3742002-12-13 20:15:29 +00002226 static char buf[100];
2227 const char*hostname;
2228 extern struct host host;
2229
2230 hostname = host.name;
2231
2232 if (!hostname)
2233 {
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002234 if (!names.nodename[0])
2235 uname (&names);
paul718e3742002-12-13 20:15:29 +00002236 hostname = names.nodename;
2237 }
2238
2239 snprintf (buf, sizeof buf, cmd_prompt (vty->node), hostname);
2240
2241 return buf;
2242}
2243
2244void
ajsb1aa1472005-01-28 21:11:46 +00002245vtysh_init_vty (void)
paul718e3742002-12-13 20:15:29 +00002246{
2247 /* Make vty structure. */
2248 vty = vty_new ();
2249 vty->type = VTY_SHELL;
2250 vty->node = VIEW_NODE;
2251
2252 /* Initialize commands. */
2253 cmd_init (0);
2254
2255 /* Install nodes. */
2256 install_node (&bgp_node, NULL);
2257 install_node (&rip_node, NULL);
2258 install_node (&interface_node, NULL);
2259 install_node (&rmap_node, NULL);
2260 install_node (&zebra_node, NULL);
2261 install_node (&bgp_vpnv4_node, NULL);
2262 install_node (&bgp_ipv4_node, NULL);
2263 install_node (&bgp_ipv4m_node, NULL);
2264/* #ifdef HAVE_IPV6 */
2265 install_node (&bgp_ipv6_node, NULL);
paul57b5b7e2005-08-22 22:44:29 +00002266 install_node (&bgp_ipv6m_node, NULL);
paul718e3742002-12-13 20:15:29 +00002267/* #endif */
2268 install_node (&ospf_node, NULL);
2269/* #ifdef HAVE_IPV6 */
2270 install_node (&ripng_node, NULL);
2271 install_node (&ospf6_node, NULL);
2272/* #endif */
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +01002273 install_node (&babel_node, NULL);
paul718e3742002-12-13 20:15:29 +00002274 install_node (&keychain_node, NULL);
2275 install_node (&keychain_key_node, NULL);
hassoc25e4582003-12-23 10:39:08 +00002276 install_node (&isis_node, NULL);
hassoe7168df2004-10-03 20:11:32 +00002277 install_node (&vty_node, NULL);
paul718e3742002-12-13 20:15:29 +00002278
2279 vtysh_install_default (VIEW_NODE);
2280 vtysh_install_default (ENABLE_NODE);
2281 vtysh_install_default (CONFIG_NODE);
2282 vtysh_install_default (BGP_NODE);
2283 vtysh_install_default (RIP_NODE);
2284 vtysh_install_default (INTERFACE_NODE);
2285 vtysh_install_default (RMAP_NODE);
2286 vtysh_install_default (ZEBRA_NODE);
2287 vtysh_install_default (BGP_VPNV4_NODE);
2288 vtysh_install_default (BGP_IPV4_NODE);
2289 vtysh_install_default (BGP_IPV4M_NODE);
2290 vtysh_install_default (BGP_IPV6_NODE);
paul57b5b7e2005-08-22 22:44:29 +00002291 vtysh_install_default (BGP_IPV6M_NODE);
paul718e3742002-12-13 20:15:29 +00002292 vtysh_install_default (OSPF_NODE);
2293 vtysh_install_default (RIPNG_NODE);
2294 vtysh_install_default (OSPF6_NODE);
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +01002295 vtysh_install_default (BABEL_NODE);
hassoc25e4582003-12-23 10:39:08 +00002296 vtysh_install_default (ISIS_NODE);
paul718e3742002-12-13 20:15:29 +00002297 vtysh_install_default (KEYCHAIN_NODE);
2298 vtysh_install_default (KEYCHAIN_KEY_NODE);
hassoe7168df2004-10-03 20:11:32 +00002299 vtysh_install_default (VTY_NODE);
paul718e3742002-12-13 20:15:29 +00002300
2301 install_element (VIEW_NODE, &vtysh_enable_cmd);
2302 install_element (ENABLE_NODE, &vtysh_config_terminal_cmd);
2303 install_element (ENABLE_NODE, &vtysh_disable_cmd);
2304
2305 /* "exit" command. */
2306 install_element (VIEW_NODE, &vtysh_exit_all_cmd);
2307 install_element (VIEW_NODE, &vtysh_quit_all_cmd);
2308 install_element (CONFIG_NODE, &vtysh_exit_all_cmd);
2309 /* install_element (CONFIG_NODE, &vtysh_quit_all_cmd); */
2310 install_element (ENABLE_NODE, &vtysh_exit_all_cmd);
2311 install_element (ENABLE_NODE, &vtysh_quit_all_cmd);
2312 install_element (RIP_NODE, &vtysh_exit_ripd_cmd);
2313 install_element (RIP_NODE, &vtysh_quit_ripd_cmd);
paul68980082003-03-25 05:07:42 +00002314 install_element (RIPNG_NODE, &vtysh_exit_ripngd_cmd);
2315 install_element (RIPNG_NODE, &vtysh_quit_ripngd_cmd);
paul718e3742002-12-13 20:15:29 +00002316 install_element (OSPF_NODE, &vtysh_exit_ospfd_cmd);
2317 install_element (OSPF_NODE, &vtysh_quit_ospfd_cmd);
paul68980082003-03-25 05:07:42 +00002318 install_element (OSPF6_NODE, &vtysh_exit_ospf6d_cmd);
2319 install_element (OSPF6_NODE, &vtysh_quit_ospf6d_cmd);
paul718e3742002-12-13 20:15:29 +00002320 install_element (BGP_NODE, &vtysh_exit_bgpd_cmd);
2321 install_element (BGP_NODE, &vtysh_quit_bgpd_cmd);
2322 install_element (BGP_VPNV4_NODE, &vtysh_exit_bgpd_cmd);
2323 install_element (BGP_VPNV4_NODE, &vtysh_quit_bgpd_cmd);
2324 install_element (BGP_IPV4_NODE, &vtysh_exit_bgpd_cmd);
2325 install_element (BGP_IPV4_NODE, &vtysh_quit_bgpd_cmd);
2326 install_element (BGP_IPV4M_NODE, &vtysh_exit_bgpd_cmd);
2327 install_element (BGP_IPV4M_NODE, &vtysh_quit_bgpd_cmd);
2328 install_element (BGP_IPV6_NODE, &vtysh_exit_bgpd_cmd);
2329 install_element (BGP_IPV6_NODE, &vtysh_quit_bgpd_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002330 install_element (BGP_IPV6M_NODE, &vtysh_exit_bgpd_cmd);
2331 install_element (BGP_IPV6M_NODE, &vtysh_quit_bgpd_cmd);
hassoc25e4582003-12-23 10:39:08 +00002332 install_element (ISIS_NODE, &vtysh_exit_isisd_cmd);
2333 install_element (ISIS_NODE, &vtysh_quit_isisd_cmd);
paul718e3742002-12-13 20:15:29 +00002334 install_element (KEYCHAIN_NODE, &vtysh_exit_ripd_cmd);
2335 install_element (KEYCHAIN_NODE, &vtysh_quit_ripd_cmd);
2336 install_element (KEYCHAIN_KEY_NODE, &vtysh_exit_ripd_cmd);
2337 install_element (KEYCHAIN_KEY_NODE, &vtysh_quit_ripd_cmd);
2338 install_element (RMAP_NODE, &vtysh_exit_rmap_cmd);
2339 install_element (RMAP_NODE, &vtysh_quit_rmap_cmd);
hassoe7168df2004-10-03 20:11:32 +00002340 install_element (VTY_NODE, &vtysh_exit_line_vty_cmd);
2341 install_element (VTY_NODE, &vtysh_quit_line_vty_cmd);
paul718e3742002-12-13 20:15:29 +00002342
2343 /* "end" command. */
2344 install_element (CONFIG_NODE, &vtysh_end_all_cmd);
2345 install_element (ENABLE_NODE, &vtysh_end_all_cmd);
2346 install_element (RIP_NODE, &vtysh_end_all_cmd);
2347 install_element (RIPNG_NODE, &vtysh_end_all_cmd);
2348 install_element (OSPF_NODE, &vtysh_end_all_cmd);
2349 install_element (OSPF6_NODE, &vtysh_end_all_cmd);
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +01002350 install_element (BABEL_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002351 install_element (BGP_NODE, &vtysh_end_all_cmd);
2352 install_element (BGP_IPV4_NODE, &vtysh_end_all_cmd);
2353 install_element (BGP_IPV4M_NODE, &vtysh_end_all_cmd);
2354 install_element (BGP_VPNV4_NODE, &vtysh_end_all_cmd);
2355 install_element (BGP_IPV6_NODE, &vtysh_end_all_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002356 install_element (BGP_IPV6M_NODE, &vtysh_end_all_cmd);
hassoc25e4582003-12-23 10:39:08 +00002357 install_element (ISIS_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002358 install_element (KEYCHAIN_NODE, &vtysh_end_all_cmd);
2359 install_element (KEYCHAIN_KEY_NODE, &vtysh_end_all_cmd);
2360 install_element (RMAP_NODE, &vtysh_end_all_cmd);
hassoe7168df2004-10-03 20:11:32 +00002361 install_element (VTY_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002362
paul338a9912003-03-01 15:44:10 +00002363 install_element (INTERFACE_NODE, &interface_desc_cmd);
paul464dc8d2003-03-28 02:25:45 +00002364 install_element (INTERFACE_NODE, &no_interface_desc_cmd);
paul718e3742002-12-13 20:15:29 +00002365 install_element (INTERFACE_NODE, &vtysh_end_all_cmd);
2366 install_element (INTERFACE_NODE, &vtysh_exit_interface_cmd);
2367 install_element (INTERFACE_NODE, &vtysh_quit_interface_cmd);
2368 install_element (CONFIG_NODE, &router_rip_cmd);
2369#ifdef HAVE_IPV6
2370 install_element (CONFIG_NODE, &router_ripng_cmd);
2371#endif
2372 install_element (CONFIG_NODE, &router_ospf_cmd);
2373#ifdef HAVE_IPV6
2374 install_element (CONFIG_NODE, &router_ospf6_cmd);
2375#endif
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +01002376 install_element (CONFIG_NODE, &router_babel_cmd);
hassoc25e4582003-12-23 10:39:08 +00002377 install_element (CONFIG_NODE, &router_isis_cmd);
paul718e3742002-12-13 20:15:29 +00002378 install_element (CONFIG_NODE, &router_bgp_cmd);
Paul Jakma10895fd2008-07-03 19:34:48 +00002379 install_element (CONFIG_NODE, &router_bgp_view_cmd);
paul718e3742002-12-13 20:15:29 +00002380 install_element (BGP_NODE, &address_family_vpnv4_cmd);
2381 install_element (BGP_NODE, &address_family_vpnv4_unicast_cmd);
2382 install_element (BGP_NODE, &address_family_ipv4_unicast_cmd);
2383 install_element (BGP_NODE, &address_family_ipv4_multicast_cmd);
2384#ifdef HAVE_IPV6
2385 install_element (BGP_NODE, &address_family_ipv6_cmd);
2386 install_element (BGP_NODE, &address_family_ipv6_unicast_cmd);
2387#endif
2388 install_element (BGP_VPNV4_NODE, &exit_address_family_cmd);
2389 install_element (BGP_IPV4_NODE, &exit_address_family_cmd);
2390 install_element (BGP_IPV4M_NODE, &exit_address_family_cmd);
2391 install_element (BGP_IPV6_NODE, &exit_address_family_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002392 install_element (BGP_IPV6M_NODE, &exit_address_family_cmd);
paul718e3742002-12-13 20:15:29 +00002393 install_element (CONFIG_NODE, &key_chain_cmd);
2394 install_element (CONFIG_NODE, &route_map_cmd);
hassoe7168df2004-10-03 20:11:32 +00002395 install_element (CONFIG_NODE, &vtysh_line_vty_cmd);
paul718e3742002-12-13 20:15:29 +00002396 install_element (KEYCHAIN_NODE, &key_cmd);
2397 install_element (KEYCHAIN_NODE, &key_chain_cmd);
2398 install_element (KEYCHAIN_KEY_NODE, &key_chain_cmd);
2399 install_element (CONFIG_NODE, &vtysh_interface_cmd);
paul32d24632003-05-23 09:25:20 +00002400 install_element (CONFIG_NODE, &vtysh_no_interface_cmd);
paul718e3742002-12-13 20:15:29 +00002401 install_element (ENABLE_NODE, &vtysh_show_running_config_cmd);
2402 install_element (ENABLE_NODE, &vtysh_copy_runningconfig_startupconfig_cmd);
2403 install_element (ENABLE_NODE, &vtysh_write_file_cmd);
hasso4a6e2252003-05-25 11:51:29 +00002404 install_element (ENABLE_NODE, &vtysh_write_cmd);
paul718e3742002-12-13 20:15:29 +00002405
hasso95e735b2004-08-26 13:08:30 +00002406 /* "write terminal" command. */
paul718e3742002-12-13 20:15:29 +00002407 install_element (ENABLE_NODE, &vtysh_write_terminal_cmd);
hassoe7168df2004-10-03 20:11:32 +00002408
2409 install_element (CONFIG_NODE, &vtysh_integrated_config_cmd);
2410 install_element (CONFIG_NODE, &no_vtysh_integrated_config_cmd);
paul718e3742002-12-13 20:15:29 +00002411
hasso95e735b2004-08-26 13:08:30 +00002412 /* "write memory" command. */
paul718e3742002-12-13 20:15:29 +00002413 install_element (ENABLE_NODE, &vtysh_write_memory_cmd);
paul718e3742002-12-13 20:15:29 +00002414
hasso34553cc2004-08-27 13:56:39 +00002415 install_element (VIEW_NODE, &vtysh_terminal_length_cmd);
2416 install_element (ENABLE_NODE, &vtysh_terminal_length_cmd);
2417 install_element (VIEW_NODE, &vtysh_terminal_no_length_cmd);
2418 install_element (ENABLE_NODE, &vtysh_terminal_no_length_cmd);
hassof2799e62004-10-28 17:43:11 +00002419 install_element (VIEW_NODE, &vtysh_show_daemons_cmd);
2420 install_element (ENABLE_NODE, &vtysh_show_daemons_cmd);
hasso34553cc2004-08-27 13:56:39 +00002421
paul718e3742002-12-13 20:15:29 +00002422 install_element (VIEW_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002423 install_element (VIEW_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00002424 install_element (VIEW_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002425 install_element (VIEW_NODE, &vtysh_traceroute_ip_cmd);
2426#ifdef HAVE_IPV6
2427 install_element (VIEW_NODE, &vtysh_ping6_cmd);
2428 install_element (VIEW_NODE, &vtysh_traceroute6_cmd);
2429#endif
paul718e3742002-12-13 20:15:29 +00002430 install_element (VIEW_NODE, &vtysh_telnet_cmd);
2431 install_element (VIEW_NODE, &vtysh_telnet_port_cmd);
paul5087df52003-01-25 06:56:09 +00002432 install_element (VIEW_NODE, &vtysh_ssh_cmd);
paul718e3742002-12-13 20:15:29 +00002433 install_element (ENABLE_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002434 install_element (ENABLE_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00002435 install_element (ENABLE_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002436 install_element (ENABLE_NODE, &vtysh_traceroute_ip_cmd);
2437#ifdef HAVE_IPV6
2438 install_element (ENABLE_NODE, &vtysh_ping6_cmd);
2439 install_element (ENABLE_NODE, &vtysh_traceroute6_cmd);
2440#endif
paul718e3742002-12-13 20:15:29 +00002441 install_element (ENABLE_NODE, &vtysh_telnet_cmd);
2442 install_element (ENABLE_NODE, &vtysh_telnet_port_cmd);
hasso67e29ab2004-08-26 22:21:31 +00002443 install_element (ENABLE_NODE, &vtysh_ssh_cmd);
paul718e3742002-12-13 20:15:29 +00002444 install_element (ENABLE_NODE, &vtysh_start_shell_cmd);
2445 install_element (ENABLE_NODE, &vtysh_start_bash_cmd);
2446 install_element (ENABLE_NODE, &vtysh_start_zsh_cmd);
Paul Jakmadbf7d132006-05-23 22:10:01 +00002447
Paul Jakma362b4032006-05-28 07:54:45 +00002448 install_element (VIEW_NODE, &vtysh_show_memory_cmd);
2449 install_element (ENABLE_NODE, &vtysh_show_memory_cmd);
2450
Paul Jakmadbf7d132006-05-23 22:10:01 +00002451 /* Logging */
2452 install_element (ENABLE_NODE, &vtysh_show_logging_cmd);
2453 install_element (VIEW_NODE, &vtysh_show_logging_cmd);
paul718e3742002-12-13 20:15:29 +00002454 install_element (CONFIG_NODE, &vtysh_log_stdout_cmd);
ajs274a4a42004-12-07 15:39:31 +00002455 install_element (CONFIG_NODE, &vtysh_log_stdout_level_cmd);
paul718e3742002-12-13 20:15:29 +00002456 install_element (CONFIG_NODE, &no_vtysh_log_stdout_cmd);
2457 install_element (CONFIG_NODE, &vtysh_log_file_cmd);
ajs274a4a42004-12-07 15:39:31 +00002458 install_element (CONFIG_NODE, &vtysh_log_file_level_cmd);
paul718e3742002-12-13 20:15:29 +00002459 install_element (CONFIG_NODE, &no_vtysh_log_file_cmd);
ajs274a4a42004-12-07 15:39:31 +00002460 install_element (CONFIG_NODE, &no_vtysh_log_file_level_cmd);
2461 install_element (CONFIG_NODE, &vtysh_log_monitor_cmd);
2462 install_element (CONFIG_NODE, &vtysh_log_monitor_level_cmd);
2463 install_element (CONFIG_NODE, &no_vtysh_log_monitor_cmd);
paul718e3742002-12-13 20:15:29 +00002464 install_element (CONFIG_NODE, &vtysh_log_syslog_cmd);
ajs274a4a42004-12-07 15:39:31 +00002465 install_element (CONFIG_NODE, &vtysh_log_syslog_level_cmd);
paul718e3742002-12-13 20:15:29 +00002466 install_element (CONFIG_NODE, &no_vtysh_log_syslog_cmd);
2467 install_element (CONFIG_NODE, &vtysh_log_trap_cmd);
2468 install_element (CONFIG_NODE, &no_vtysh_log_trap_cmd);
ajs274a4a42004-12-07 15:39:31 +00002469 install_element (CONFIG_NODE, &vtysh_log_facility_cmd);
2470 install_element (CONFIG_NODE, &no_vtysh_log_facility_cmd);
paul718e3742002-12-13 20:15:29 +00002471 install_element (CONFIG_NODE, &vtysh_log_record_priority_cmd);
2472 install_element (CONFIG_NODE, &no_vtysh_log_record_priority_cmd);
Andrew J. Schorrc749b722007-04-29 03:53:31 +00002473 install_element (CONFIG_NODE, &vtysh_log_timestamp_precision_cmd);
2474 install_element (CONFIG_NODE, &no_vtysh_log_timestamp_precision_cmd);
hassoe7168df2004-10-03 20:11:32 +00002475
2476 install_element (CONFIG_NODE, &vtysh_service_password_encrypt_cmd);
2477 install_element (CONFIG_NODE, &no_vtysh_service_password_encrypt_cmd);
2478
2479 install_element (CONFIG_NODE, &vtysh_password_cmd);
2480 install_element (CONFIG_NODE, &vtysh_password_text_cmd);
2481 install_element (CONFIG_NODE, &vtysh_enable_password_cmd);
2482 install_element (CONFIG_NODE, &vtysh_enable_password_text_cmd);
2483 install_element (CONFIG_NODE, &no_vtysh_enable_password_cmd);
2484
paul718e3742002-12-13 20:15:29 +00002485}