blob: e3709e07e3c303255a2cc6ec670ba08e68bc7e7a [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},
ajsb1aa1472005-01-28 21:11:46 +000062};
63
ajsb1aa1472005-01-28 21:11:46 +000064
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 {
Balaji.G837d16c2012-09-26 14:09:10 +0530376 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +0000377 {
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;
Balaji.G837d16c2012-09-26 14:09:10 +0530415 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +0000416 {
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
Balaji.G837d16c2012-09-26 14:09:10 +0530527 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +0000528 {
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
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +0100800static struct cmd_node babel_node =
801{
802 BABEL_NODE,
803 "%s(config-babel)# "
804};
805
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800806static struct cmd_node keychain_node =
hasso95e735b2004-08-26 13:08:30 +0000807{
808 KEYCHAIN_NODE,
809 "%s(config-keychain)# "
810};
811
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800812static struct cmd_node keychain_key_node =
hasso95e735b2004-08-26 13:08:30 +0000813{
814 KEYCHAIN_KEY_NODE,
815 "%s(config-keychain-key)# "
816};
817
hassoe7168df2004-10-03 20:11:32 +0000818/* Defined in lib/vty.c */
819extern struct cmd_node vty_node;
820
hasso95e735b2004-08-26 13:08:30 +0000821/* When '^Z' is received from vty, move down to the enable mode. */
822int
ajsb1aa1472005-01-28 21:11:46 +0000823vtysh_end (void)
hasso95e735b2004-08-26 13:08:30 +0000824{
825 switch (vty->node)
826 {
827 case VIEW_NODE:
828 case ENABLE_NODE:
829 /* Nothing to do. */
830 break;
831 default:
832 vty->node = ENABLE_NODE;
833 break;
834 }
835 return CMD_SUCCESS;
836}
837
838DEFUNSH (VTYSH_ALL,
839 vtysh_end_all,
840 vtysh_end_all_cmd,
841 "end",
hassoe7168df2004-10-03 20:11:32 +0000842 "End current mode and change to enable mode\n")
hasso95e735b2004-08-26 13:08:30 +0000843{
hasso42895462004-09-26 16:25:07 +0000844 return vtysh_end ();
hasso95e735b2004-08-26 13:08:30 +0000845}
846
paul718e3742002-12-13 20:15:29 +0000847DEFUNSH (VTYSH_BGPD,
848 router_bgp,
849 router_bgp_cmd,
Paul Jakma320da872008-07-02 13:40:33 +0000850 "router bgp " CMD_AS_RANGE,
paul718e3742002-12-13 20:15:29 +0000851 ROUTER_STR
852 BGP_STR
853 AS_STR)
854{
855 vty->node = BGP_NODE;
856 return CMD_SUCCESS;
857}
858
Paul Jakma10895fd2008-07-03 19:34:48 +0000859ALIAS_SH (VTYSH_BGPD,
860 router_bgp,
861 router_bgp_view_cmd,
862 "router bgp " CMD_AS_RANGE " view WORD",
863 ROUTER_STR
864 BGP_STR
865 AS_STR
866 "BGP view\n"
867 "view name\n")
868
paul718e3742002-12-13 20:15:29 +0000869DEFUNSH (VTYSH_BGPD,
870 address_family_vpnv4,
871 address_family_vpnv4_cmd,
872 "address-family vpnv4",
873 "Enter Address Family command mode\n"
874 "Address family\n")
875{
876 vty->node = BGP_VPNV4_NODE;
877 return CMD_SUCCESS;
878}
879
880DEFUNSH (VTYSH_BGPD,
881 address_family_vpnv4_unicast,
882 address_family_vpnv4_unicast_cmd,
883 "address-family vpnv4 unicast",
884 "Enter Address Family command mode\n"
885 "Address family\n"
886 "Address Family Modifier\n")
887{
888 vty->node = BGP_VPNV4_NODE;
889 return CMD_SUCCESS;
890}
891
892DEFUNSH (VTYSH_BGPD,
893 address_family_ipv4_unicast,
894 address_family_ipv4_unicast_cmd,
895 "address-family ipv4 unicast",
896 "Enter Address Family command mode\n"
897 "Address family\n"
898 "Address Family Modifier\n")
899{
900 vty->node = BGP_IPV4_NODE;
901 return CMD_SUCCESS;
902}
903
904DEFUNSH (VTYSH_BGPD,
905 address_family_ipv4_multicast,
906 address_family_ipv4_multicast_cmd,
907 "address-family ipv4 multicast",
908 "Enter Address Family command mode\n"
909 "Address family\n"
910 "Address Family Modifier\n")
911{
912 vty->node = BGP_IPV4M_NODE;
913 return CMD_SUCCESS;
914}
915
916DEFUNSH (VTYSH_BGPD,
917 address_family_ipv6,
918 address_family_ipv6_cmd,
919 "address-family ipv6",
920 "Enter Address Family command mode\n"
921 "Address family\n")
922{
923 vty->node = BGP_IPV6_NODE;
924 return CMD_SUCCESS;
925}
926
927DEFUNSH (VTYSH_BGPD,
928 address_family_ipv6_unicast,
929 address_family_ipv6_unicast_cmd,
930 "address-family ipv6 unicast",
931 "Enter Address Family command mode\n"
932 "Address family\n"
933 "Address Family Modifier\n")
934{
935 vty->node = BGP_IPV6_NODE;
936 return CMD_SUCCESS;
937}
938
paul57b5b7e2005-08-22 22:44:29 +0000939DEFUNSH (VTYSH_BGPD,
940 address_family_ipv6_multicast,
941 address_family_ipv6_multicast_cmd,
942 "address-family ipv6 multicast",
943 "Enter Address Family command mode\n"
944 "Address family\n"
945 "Address Family Modifier\n")
946{
947 vty->node = BGP_IPV6M_NODE;
948 return CMD_SUCCESS;
949}
950
paul718e3742002-12-13 20:15:29 +0000951DEFUNSH (VTYSH_RIPD,
952 key_chain,
953 key_chain_cmd,
954 "key chain WORD",
955 "Authentication key management\n"
956 "Key-chain management\n"
957 "Key-chain name\n")
958{
959 vty->node = KEYCHAIN_NODE;
960 return CMD_SUCCESS;
961}
962
963DEFUNSH (VTYSH_RIPD,
964 key,
965 key_cmd,
966 "key <0-2147483647>",
967 "Configure a key\n"
968 "Key identifier number\n")
969{
970 vty->node = KEYCHAIN_KEY_NODE;
971 return CMD_SUCCESS;
972}
973
974DEFUNSH (VTYSH_RIPD,
975 router_rip,
976 router_rip_cmd,
977 "router rip",
978 ROUTER_STR
979 "RIP")
980{
981 vty->node = RIP_NODE;
982 return CMD_SUCCESS;
983}
984
985DEFUNSH (VTYSH_RIPNGD,
986 router_ripng,
987 router_ripng_cmd,
988 "router ripng",
989 ROUTER_STR
990 "RIPng")
991{
992 vty->node = RIPNG_NODE;
993 return CMD_SUCCESS;
994}
995
996DEFUNSH (VTYSH_OSPFD,
997 router_ospf,
998 router_ospf_cmd,
999 "router ospf",
1000 "Enable a routing process\n"
1001 "Start OSPF configuration\n")
1002{
1003 vty->node = OSPF_NODE;
1004 return CMD_SUCCESS;
1005}
1006
1007DEFUNSH (VTYSH_OSPF6D,
1008 router_ospf6,
1009 router_ospf6_cmd,
1010 "router ospf6",
1011 OSPF6_ROUTER_STR
1012 OSPF6_STR)
1013{
1014 vty->node = OSPF6_NODE;
1015 return CMD_SUCCESS;
1016}
1017
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +01001018DEFUNSH (VTYSH_BABELD,
1019 router_babel,
1020 router_babel_cmd,
1021 "router babel",
1022 ROUTER_STR
1023 "Babel")
1024{
1025 vty->node = BABEL_NODE;
1026 return CMD_SUCCESS;
1027}
1028
hassoc25e4582003-12-23 10:39:08 +00001029DEFUNSH (VTYSH_ISISD,
hassob094d262004-08-25 12:22:00 +00001030 router_isis,
1031 router_isis_cmd,
1032 "router isis WORD",
1033 ROUTER_STR
1034 "ISO IS-IS\n"
1035 "ISO Routing area tag")
hassoc25e4582003-12-23 10:39:08 +00001036{
1037 vty->node = ISIS_NODE;
1038 return CMD_SUCCESS;
1039}
1040
paul718e3742002-12-13 20:15:29 +00001041DEFUNSH (VTYSH_RMAP,
1042 route_map,
1043 route_map_cmd,
1044 "route-map WORD (deny|permit) <1-65535>",
1045 "Create route-map or enter route-map command mode\n"
1046 "Route map tag\n"
1047 "Route map denies set operations\n"
1048 "Route map permits set operations\n"
1049 "Sequence to insert to/delete from existing route-map entry\n")
1050{
1051 vty->node = RMAP_NODE;
1052 return CMD_SUCCESS;
1053}
1054
paul718e3742002-12-13 20:15:29 +00001055DEFUNSH (VTYSH_ALL,
hassoe7168df2004-10-03 20:11:32 +00001056 vtysh_line_vty,
1057 vtysh_line_vty_cmd,
1058 "line vty",
1059 "Configure a terminal line\n"
1060 "Virtual terminal\n")
1061{
1062 vty->node = VTY_NODE;
1063 return CMD_SUCCESS;
1064}
1065
1066DEFUNSH (VTYSH_ALL,
paul718e3742002-12-13 20:15:29 +00001067 vtysh_enable,
1068 vtysh_enable_cmd,
1069 "enable",
1070 "Turn on privileged mode command\n")
1071{
1072 vty->node = ENABLE_NODE;
1073 return CMD_SUCCESS;
1074}
1075
paul718e3742002-12-13 20:15:29 +00001076DEFUNSH (VTYSH_ALL,
1077 vtysh_disable,
1078 vtysh_disable_cmd,
1079 "disable",
1080 "Turn off privileged mode command\n")
1081{
1082 if (vty->node == ENABLE_NODE)
1083 vty->node = VIEW_NODE;
1084 return CMD_SUCCESS;
1085}
1086
paul718e3742002-12-13 20:15:29 +00001087DEFUNSH (VTYSH_ALL,
1088 vtysh_config_terminal,
1089 vtysh_config_terminal_cmd,
1090 "configure terminal",
1091 "Configuration from vty interface\n"
1092 "Configuration terminal\n")
1093{
1094 vty->node = CONFIG_NODE;
1095 return CMD_SUCCESS;
1096}
1097
ajs274a4a42004-12-07 15:39:31 +00001098static int
paul718e3742002-12-13 20:15:29 +00001099vtysh_exit (struct vty *vty)
1100{
1101 switch (vty->node)
1102 {
1103 case VIEW_NODE:
1104 case ENABLE_NODE:
1105 exit (0);
1106 break;
1107 case CONFIG_NODE:
1108 vty->node = ENABLE_NODE;
1109 break;
1110 case INTERFACE_NODE:
1111 case ZEBRA_NODE:
1112 case BGP_NODE:
1113 case RIP_NODE:
1114 case RIPNG_NODE:
1115 case OSPF_NODE:
1116 case OSPF6_NODE:
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +01001117 case BABEL_NODE:
hassoc25e4582003-12-23 10:39:08 +00001118 case ISIS_NODE:
paul718e3742002-12-13 20:15:29 +00001119 case MASC_NODE:
1120 case RMAP_NODE:
1121 case VTY_NODE:
1122 case KEYCHAIN_NODE:
hasso2a56df92004-05-09 23:16:40 +00001123 vtysh_execute("end");
1124 vtysh_execute("configure terminal");
paul718e3742002-12-13 20:15:29 +00001125 vty->node = CONFIG_NODE;
1126 break;
1127 case BGP_VPNV4_NODE:
1128 case BGP_IPV4_NODE:
1129 case BGP_IPV4M_NODE:
1130 case BGP_IPV6_NODE:
paul57b5b7e2005-08-22 22:44:29 +00001131 case BGP_IPV6M_NODE:
paul718e3742002-12-13 20:15:29 +00001132 vty->node = BGP_NODE;
1133 break;
1134 case KEYCHAIN_KEY_NODE:
1135 vty->node = KEYCHAIN_NODE;
1136 break;
1137 default:
1138 break;
1139 }
1140 return CMD_SUCCESS;
1141}
1142
1143DEFUNSH (VTYSH_ALL,
1144 vtysh_exit_all,
1145 vtysh_exit_all_cmd,
1146 "exit",
1147 "Exit current mode and down to previous mode\n")
1148{
1149 return vtysh_exit (vty);
1150}
1151
1152ALIAS (vtysh_exit_all,
1153 vtysh_quit_all_cmd,
1154 "quit",
1155 "Exit current mode and down to previous mode\n")
1156
1157DEFUNSH (VTYSH_BGPD,
1158 exit_address_family,
1159 exit_address_family_cmd,
1160 "exit-address-family",
1161 "Exit from Address Family configuration mode\n")
1162{
1163 if (vty->node == BGP_IPV4_NODE
1164 || vty->node == BGP_IPV4M_NODE
1165 || vty->node == BGP_VPNV4_NODE
paul57b5b7e2005-08-22 22:44:29 +00001166 || vty->node == BGP_IPV6_NODE
1167 || vty->node == BGP_IPV6M_NODE)
paul718e3742002-12-13 20:15:29 +00001168 vty->node = BGP_NODE;
1169 return CMD_SUCCESS;
1170}
1171
1172DEFUNSH (VTYSH_ZEBRA,
1173 vtysh_exit_zebra,
1174 vtysh_exit_zebra_cmd,
1175 "exit",
1176 "Exit current mode and down to previous mode\n")
1177{
1178 return vtysh_exit (vty);
1179}
1180
1181ALIAS (vtysh_exit_zebra,
1182 vtysh_quit_zebra_cmd,
1183 "quit",
1184 "Exit current mode and down to previous mode\n")
1185
1186DEFUNSH (VTYSH_RIPD,
1187 vtysh_exit_ripd,
1188 vtysh_exit_ripd_cmd,
1189 "exit",
1190 "Exit current mode and down to previous mode\n")
1191{
1192 return vtysh_exit (vty);
1193}
1194
1195ALIAS (vtysh_exit_ripd,
1196 vtysh_quit_ripd_cmd,
1197 "quit",
1198 "Exit current mode and down to previous mode\n")
1199
paul68980082003-03-25 05:07:42 +00001200DEFUNSH (VTYSH_RIPNGD,
hassob094d262004-08-25 12:22:00 +00001201 vtysh_exit_ripngd,
1202 vtysh_exit_ripngd_cmd,
1203 "exit",
1204 "Exit current mode and down to previous mode\n")
paul68980082003-03-25 05:07:42 +00001205{
1206 return vtysh_exit (vty);
1207}
1208
1209ALIAS (vtysh_exit_ripngd,
1210 vtysh_quit_ripngd_cmd,
1211 "quit",
1212 "Exit current mode and down to previous mode\n")
1213
paul718e3742002-12-13 20:15:29 +00001214DEFUNSH (VTYSH_RMAP,
1215 vtysh_exit_rmap,
1216 vtysh_exit_rmap_cmd,
1217 "exit",
1218 "Exit current mode and down to previous mode\n")
1219{
1220 return vtysh_exit (vty);
1221}
1222
1223ALIAS (vtysh_exit_rmap,
1224 vtysh_quit_rmap_cmd,
1225 "quit",
1226 "Exit current mode and down to previous mode\n")
1227
1228DEFUNSH (VTYSH_BGPD,
1229 vtysh_exit_bgpd,
1230 vtysh_exit_bgpd_cmd,
1231 "exit",
1232 "Exit current mode and down to previous mode\n")
1233{
1234 return vtysh_exit (vty);
1235}
1236
1237ALIAS (vtysh_exit_bgpd,
1238 vtysh_quit_bgpd_cmd,
1239 "quit",
1240 "Exit current mode and down to previous mode\n")
1241
1242DEFUNSH (VTYSH_OSPFD,
1243 vtysh_exit_ospfd,
1244 vtysh_exit_ospfd_cmd,
1245 "exit",
1246 "Exit current mode and down to previous mode\n")
1247{
1248 return vtysh_exit (vty);
1249}
1250
1251ALIAS (vtysh_exit_ospfd,
1252 vtysh_quit_ospfd_cmd,
1253 "quit",
1254 "Exit current mode and down to previous mode\n")
1255
paul68980082003-03-25 05:07:42 +00001256DEFUNSH (VTYSH_OSPF6D,
hassob094d262004-08-25 12:22:00 +00001257 vtysh_exit_ospf6d,
1258 vtysh_exit_ospf6d_cmd,
1259 "exit",
1260 "Exit current mode and down to previous mode\n")
paul68980082003-03-25 05:07:42 +00001261{
1262 return vtysh_exit (vty);
1263}
1264
1265ALIAS (vtysh_exit_ospf6d,
1266 vtysh_quit_ospf6d_cmd,
1267 "quit",
1268 "Exit current mode and down to previous mode\n")
1269
hassoc25e4582003-12-23 10:39:08 +00001270DEFUNSH (VTYSH_ISISD,
hassob094d262004-08-25 12:22:00 +00001271 vtysh_exit_isisd,
1272 vtysh_exit_isisd_cmd,
1273 "exit",
1274 "Exit current mode and down to previous mode\n")
hassoc25e4582003-12-23 10:39:08 +00001275{
1276 return vtysh_exit (vty);
1277}
1278
1279ALIAS (vtysh_exit_isisd,
1280 vtysh_quit_isisd_cmd,
1281 "quit",
1282 "Exit current mode and down to previous mode\n")
1283
hassoe7168df2004-10-03 20:11:32 +00001284DEFUNSH (VTYSH_ALL,
1285 vtysh_exit_line_vty,
1286 vtysh_exit_line_vty_cmd,
1287 "exit",
1288 "Exit current mode and down to previous mode\n")
1289{
1290 return vtysh_exit (vty);
1291}
1292
1293ALIAS (vtysh_exit_line_vty,
1294 vtysh_quit_line_vty_cmd,
1295 "quit",
1296 "Exit current mode and down to previous mode\n")
1297
hasso95e735b2004-08-26 13:08:30 +00001298DEFUNSH (VTYSH_INTERFACE,
paul718e3742002-12-13 20:15:29 +00001299 vtysh_interface,
1300 vtysh_interface_cmd,
1301 "interface IFNAME",
1302 "Select an interface to configure\n"
1303 "Interface's name\n")
1304{
1305 vty->node = INTERFACE_NODE;
1306 return CMD_SUCCESS;
1307}
1308
hasso95e735b2004-08-26 13:08:30 +00001309/* TODO Implement "no interface command in isisd. */
paul32d24632003-05-23 09:25:20 +00001310DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D,
1311 vtysh_no_interface_cmd,
1312 "no interface IFNAME",
1313 NO_STR
1314 "Delete a pseudo interface's configuration\n"
1315 "Interface's name\n")
1316
hasso95e735b2004-08-26 13:08:30 +00001317/* TODO Implement interface description commands in ripngd, ospf6d
1318 * and isisd. */
paul338a9912003-03-01 15:44:10 +00001319DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1320 interface_desc_cmd,
1321 "description .LINE",
1322 "Interface specific description\n"
1323 "Characters describing this interface\n")
paul464dc8d2003-03-28 02:25:45 +00001324
1325DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1326 no_interface_desc_cmd,
1327 "no description",
1328 NO_STR
1329 "Interface specific description\n")
paul338a9912003-03-01 15:44:10 +00001330
hasso95e735b2004-08-26 13:08:30 +00001331DEFUNSH (VTYSH_INTERFACE,
paul718e3742002-12-13 20:15:29 +00001332 vtysh_exit_interface,
1333 vtysh_exit_interface_cmd,
1334 "exit",
1335 "Exit current mode and down to previous mode\n")
1336{
1337 return vtysh_exit (vty);
1338}
1339
1340ALIAS (vtysh_exit_interface,
1341 vtysh_quit_interface_cmd,
1342 "quit",
1343 "Exit current mode and down to previous mode\n")
1344
Paul Jakma362b4032006-05-28 07:54:45 +00001345/* Memory */
1346DEFUN (vtysh_show_memory,
1347 vtysh_show_memory_cmd,
1348 "show memory",
1349 SHOW_STR
1350 "Memory statistics\n")
1351{
1352 unsigned int i;
1353 int ret = CMD_SUCCESS;
1354 char line[] = "show memory\n";
1355
Balaji.G837d16c2012-09-26 14:09:10 +05301356 for (i = 0; i < array_size(vtysh_client); i++)
Paul Jakma362b4032006-05-28 07:54:45 +00001357 if ( vtysh_client[i].fd >= 0 )
1358 {
1359 fprintf (stdout, "Memory statistics for %s:\n",
1360 vtysh_client[i].name);
1361 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1362 fprintf (stdout,"\n");
1363 }
1364
1365 return ret;
1366}
1367
hasso95e735b2004-08-26 13:08:30 +00001368/* Logging commands. */
Paul Jakmadbf7d132006-05-23 22:10:01 +00001369DEFUN (vtysh_show_logging,
1370 vtysh_show_logging_cmd,
1371 "show logging",
1372 SHOW_STR
1373 "Show current logging configuration\n")
1374{
1375 unsigned int i;
1376 int ret = CMD_SUCCESS;
1377 char line[] = "show logging\n";
1378
Balaji.G837d16c2012-09-26 14:09:10 +05301379 for (i = 0; i < array_size(vtysh_client); i++)
Paul Jakma4150f332006-05-23 22:10:55 +00001380 if ( vtysh_client[i].fd >= 0 )
1381 {
1382 fprintf (stdout,"Logging configuration for %s:\n",
1383 vtysh_client[i].name);
1384 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1385 fprintf (stdout,"\n");
1386 }
1387
Paul Jakmadbf7d132006-05-23 22:10:01 +00001388 return ret;
1389}
1390
hasso95e735b2004-08-26 13:08:30 +00001391DEFUNSH (VTYSH_ALL,
1392 vtysh_log_stdout,
1393 vtysh_log_stdout_cmd,
1394 "log stdout",
1395 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001396 "Set stdout logging level\n")
1397{
1398 return CMD_SUCCESS;
1399}
1400
1401DEFUNSH (VTYSH_ALL,
1402 vtysh_log_stdout_level,
1403 vtysh_log_stdout_level_cmd,
1404 "log stdout "LOG_LEVELS,
1405 "Logging control\n"
1406 "Set stdout logging level\n"
1407 LOG_LEVEL_DESC)
hasso95e735b2004-08-26 13:08:30 +00001408{
1409 return CMD_SUCCESS;
1410}
1411
1412DEFUNSH (VTYSH_ALL,
1413 no_vtysh_log_stdout,
1414 no_vtysh_log_stdout_cmd,
ajs274a4a42004-12-07 15:39:31 +00001415 "no log stdout [LEVEL]",
hasso95e735b2004-08-26 13:08:30 +00001416 NO_STR
1417 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001418 "Cancel logging to stdout\n"
1419 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001420{
1421 return CMD_SUCCESS;
1422}
1423
1424DEFUNSH (VTYSH_ALL,
1425 vtysh_log_file,
1426 vtysh_log_file_cmd,
1427 "log file FILENAME",
1428 "Logging control\n"
1429 "Logging to file\n"
1430 "Logging filename\n")
1431{
1432 return CMD_SUCCESS;
1433}
1434
1435DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001436 vtysh_log_file_level,
1437 vtysh_log_file_level_cmd,
1438 "log file FILENAME "LOG_LEVELS,
1439 "Logging control\n"
1440 "Logging to file\n"
1441 "Logging filename\n"
1442 LOG_LEVEL_DESC)
1443{
1444 return CMD_SUCCESS;
1445}
1446
1447DEFUNSH (VTYSH_ALL,
hasso95e735b2004-08-26 13:08:30 +00001448 no_vtysh_log_file,
1449 no_vtysh_log_file_cmd,
1450 "no log file [FILENAME]",
1451 NO_STR
1452 "Logging control\n"
1453 "Cancel logging to file\n"
1454 "Logging file name\n")
1455{
1456 return CMD_SUCCESS;
1457}
1458
ajs274a4a42004-12-07 15:39:31 +00001459ALIAS_SH (VTYSH_ALL,
1460 no_vtysh_log_file,
1461 no_vtysh_log_file_level_cmd,
1462 "no log file FILENAME LEVEL",
1463 NO_STR
1464 "Logging control\n"
1465 "Cancel logging to file\n"
1466 "Logging file name\n"
1467 "Logging level\n")
1468
1469DEFUNSH (VTYSH_ALL,
1470 vtysh_log_monitor,
1471 vtysh_log_monitor_cmd,
1472 "log monitor",
1473 "Logging control\n"
1474 "Set terminal line (monitor) logging level\n")
1475{
1476 return CMD_SUCCESS;
1477}
1478
1479DEFUNSH (VTYSH_ALL,
1480 vtysh_log_monitor_level,
1481 vtysh_log_monitor_level_cmd,
1482 "log monitor "LOG_LEVELS,
1483 "Logging control\n"
1484 "Set terminal line (monitor) logging level\n"
1485 LOG_LEVEL_DESC)
1486{
1487 return CMD_SUCCESS;
1488}
1489
1490DEFUNSH (VTYSH_ALL,
1491 no_vtysh_log_monitor,
1492 no_vtysh_log_monitor_cmd,
1493 "no log monitor [LEVEL]",
1494 NO_STR
1495 "Logging control\n"
1496 "Disable terminal line (monitor) logging\n"
1497 "Logging level\n")
1498{
1499 return CMD_SUCCESS;
1500}
1501
hasso95e735b2004-08-26 13:08:30 +00001502DEFUNSH (VTYSH_ALL,
1503 vtysh_log_syslog,
1504 vtysh_log_syslog_cmd,
1505 "log syslog",
1506 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001507 "Set syslog logging level\n")
1508{
1509 return CMD_SUCCESS;
1510}
1511
1512DEFUNSH (VTYSH_ALL,
1513 vtysh_log_syslog_level,
1514 vtysh_log_syslog_level_cmd,
1515 "log syslog "LOG_LEVELS,
1516 "Logging control\n"
1517 "Set syslog logging level\n"
1518 LOG_LEVEL_DESC)
hasso95e735b2004-08-26 13:08:30 +00001519{
1520 return CMD_SUCCESS;
1521}
1522
1523DEFUNSH (VTYSH_ALL,
1524 no_vtysh_log_syslog,
1525 no_vtysh_log_syslog_cmd,
ajs274a4a42004-12-07 15:39:31 +00001526 "no log syslog [LEVEL]",
hasso95e735b2004-08-26 13:08:30 +00001527 NO_STR
1528 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001529 "Cancel logging to syslog\n"
1530 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001531{
1532 return CMD_SUCCESS;
1533}
1534
1535DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001536 vtysh_log_facility,
1537 vtysh_log_facility_cmd,
1538 "log facility "LOG_FACILITIES,
hasso95e735b2004-08-26 13:08:30 +00001539 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001540 "Facility parameter for syslog messages\n"
1541 LOG_FACILITY_DESC)
1542
hasso95e735b2004-08-26 13:08:30 +00001543{
1544 return CMD_SUCCESS;
1545}
1546
1547DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001548 no_vtysh_log_facility,
1549 no_vtysh_log_facility_cmd,
1550 "no log facility [FACILITY]",
hasso95e735b2004-08-26 13:08:30 +00001551 NO_STR
1552 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001553 "Reset syslog facility to default (daemon)\n"
1554 "Syslog facility\n")
1555
1556{
1557 return CMD_SUCCESS;
1558}
1559
1560DEFUNSH_DEPRECATED (VTYSH_ALL,
1561 vtysh_log_trap,
1562 vtysh_log_trap_cmd,
1563 "log trap "LOG_LEVELS,
1564 "Logging control\n"
1565 "(Deprecated) Set logging level and default for all destinations\n"
1566 LOG_LEVEL_DESC)
1567
1568{
1569 return CMD_SUCCESS;
1570}
1571
1572DEFUNSH_DEPRECATED (VTYSH_ALL,
1573 no_vtysh_log_trap,
1574 no_vtysh_log_trap_cmd,
1575 "no log trap [LEVEL]",
1576 NO_STR
1577 "Logging control\n"
1578 "Permit all logging information\n"
1579 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001580{
1581 return CMD_SUCCESS;
1582}
1583
1584DEFUNSH (VTYSH_ALL,
1585 vtysh_log_record_priority,
1586 vtysh_log_record_priority_cmd,
1587 "log record-priority",
1588 "Logging control\n"
1589 "Log the priority of the message within the message\n")
1590{
1591 return CMD_SUCCESS;
1592}
1593
1594DEFUNSH (VTYSH_ALL,
1595 no_vtysh_log_record_priority,
1596 no_vtysh_log_record_priority_cmd,
1597 "no log record-priority",
1598 NO_STR
1599 "Logging control\n"
1600 "Do not log the priority of the message within the message\n")
1601{
1602 return CMD_SUCCESS;
1603}
1604
hassoe7168df2004-10-03 20:11:32 +00001605DEFUNSH (VTYSH_ALL,
Andrew J. Schorrc749b722007-04-29 03:53:31 +00001606 vtysh_log_timestamp_precision,
1607 vtysh_log_timestamp_precision_cmd,
1608 "log timestamp precision <0-6>",
1609 "Logging control\n"
1610 "Timestamp configuration\n"
1611 "Set the timestamp precision\n"
1612 "Number of subsecond digits\n")
1613{
1614 return CMD_SUCCESS;
1615}
1616
1617DEFUNSH (VTYSH_ALL,
1618 no_vtysh_log_timestamp_precision,
1619 no_vtysh_log_timestamp_precision_cmd,
1620 "no log timestamp precision",
1621 NO_STR
1622 "Logging control\n"
1623 "Timestamp configuration\n"
1624 "Reset the timestamp precision to the default value of 0\n")
1625{
1626 return CMD_SUCCESS;
1627}
1628
1629DEFUNSH (VTYSH_ALL,
hassoe7168df2004-10-03 20:11:32 +00001630 vtysh_service_password_encrypt,
1631 vtysh_service_password_encrypt_cmd,
1632 "service password-encryption",
1633 "Set up miscellaneous service\n"
1634 "Enable encrypted passwords\n")
1635{
1636 return CMD_SUCCESS;
1637}
1638
1639DEFUNSH (VTYSH_ALL,
1640 no_vtysh_service_password_encrypt,
1641 no_vtysh_service_password_encrypt_cmd,
1642 "no service password-encryption",
1643 NO_STR
1644 "Set up miscellaneous service\n"
1645 "Enable encrypted passwords\n")
1646{
1647 return CMD_SUCCESS;
1648}
1649
1650DEFUNSH (VTYSH_ALL,
1651 vtysh_config_password,
1652 vtysh_password_cmd,
1653 "password (8|) WORD",
1654 "Assign the terminal connection password\n"
1655 "Specifies a HIDDEN password will follow\n"
1656 "dummy string \n"
1657 "The HIDDEN line password string\n")
1658{
1659 return CMD_SUCCESS;
1660}
1661
1662DEFUNSH (VTYSH_ALL,
1663 vtysh_password_text,
1664 vtysh_password_text_cmd,
1665 "password LINE",
1666 "Assign the terminal connection password\n"
1667 "The UNENCRYPTED (cleartext) line password\n")
1668{
1669 return CMD_SUCCESS;
1670}
1671
1672DEFUNSH (VTYSH_ALL,
1673 vtysh_config_enable_password,
1674 vtysh_enable_password_cmd,
1675 "enable password (8|) WORD",
1676 "Modify enable password parameters\n"
1677 "Assign the privileged level password\n"
1678 "Specifies a HIDDEN password will follow\n"
1679 "dummy string \n"
1680 "The HIDDEN 'enable' password string\n")
1681{
1682 return CMD_SUCCESS;
1683}
1684
1685DEFUNSH (VTYSH_ALL,
1686 vtysh_enable_password_text,
1687 vtysh_enable_password_text_cmd,
1688 "enable password LINE",
1689 "Modify enable password parameters\n"
1690 "Assign the privileged level password\n"
1691 "The UNENCRYPTED (cleartext) 'enable' password\n")
1692{
1693 return CMD_SUCCESS;
1694}
1695
1696DEFUNSH (VTYSH_ALL,
1697 no_vtysh_config_enable_password,
1698 no_vtysh_enable_password_cmd,
1699 "no enable password",
1700 NO_STR
1701 "Modify enable password parameters\n"
1702 "Assign the privileged level password\n")
1703{
1704 return CMD_SUCCESS;
1705}
1706
paul718e3742002-12-13 20:15:29 +00001707DEFUN (vtysh_write_terminal,
1708 vtysh_write_terminal_cmd,
1709 "write terminal",
1710 "Write running configuration to memory, network, or terminal\n"
1711 "Write to terminal\n")
1712{
ajsb1aa1472005-01-28 21:11:46 +00001713 u_int i;
paul718e3742002-12-13 20:15:29 +00001714 int ret;
1715 char line[] = "write terminal\n";
1716 FILE *fp = NULL;
1717
1718 if (vtysh_pager_name)
1719 {
paul4fc01e62002-12-13 20:49:00 +00001720 fp = popen (vtysh_pager_name, "w");
paul718e3742002-12-13 20:15:29 +00001721 if (fp == NULL)
1722 {
1723 perror ("popen");
1724 exit (1);
1725 }
1726 }
1727 else
1728 fp = stdout;
1729
1730 vty_out (vty, "Building configuration...%s", VTY_NEWLINE);
1731 vty_out (vty, "%sCurrent configuration:%s", VTY_NEWLINE,
1732 VTY_NEWLINE);
hassoe7168df2004-10-03 20:11:32 +00001733 vty_out (vty, "!%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001734
Balaji.G837d16c2012-09-26 14:09:10 +05301735 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00001736 ret = vtysh_client_config (&vtysh_client[i], line);
paul718e3742002-12-13 20:15:29 +00001737
hassoe7168df2004-10-03 20:11:32 +00001738 /* Integrate vtysh specific configuration. */
1739 vtysh_config_write ();
1740
paul718e3742002-12-13 20:15:29 +00001741 vtysh_config_dump (fp);
1742
1743 if (vtysh_pager_name && fp)
1744 {
1745 fflush (fp);
1746 if (pclose (fp) == -1)
1747 {
1748 perror ("pclose");
1749 exit (1);
1750 }
1751 fp = NULL;
1752 }
1753
Chris Caputo6e79f8b2009-06-23 05:55:57 +00001754 vty_out (vty, "end%s", VTY_NEWLINE);
1755
paul718e3742002-12-13 20:15:29 +00001756 return CMD_SUCCESS;
1757}
1758
hassoe7168df2004-10-03 20:11:32 +00001759DEFUN (vtysh_integrated_config,
1760 vtysh_integrated_config_cmd,
1761 "service integrated-vtysh-config",
1762 "Set up miscellaneous service\n"
1763 "Write configuration into integrated file\n")
paul4fc01e62002-12-13 20:49:00 +00001764{
hassoe7168df2004-10-03 20:11:32 +00001765 vtysh_writeconfig_integrated = 1;
1766 return CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001767}
1768
hassoe7168df2004-10-03 20:11:32 +00001769DEFUN (no_vtysh_integrated_config,
1770 no_vtysh_integrated_config_cmd,
1771 "no service integrated-vtysh-config",
1772 NO_STR
1773 "Set up miscellaneous service\n"
1774 "Write configuration into integrated file\n")
paul4fc01e62002-12-13 20:49:00 +00001775{
hassoe7168df2004-10-03 20:11:32 +00001776 vtysh_writeconfig_integrated = 0;
1777 return CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001778}
1779
ajs274a4a42004-12-07 15:39:31 +00001780static int
1781write_config_integrated(void)
paul718e3742002-12-13 20:15:29 +00001782{
ajsb1aa1472005-01-28 21:11:46 +00001783 u_int i;
paul718e3742002-12-13 20:15:29 +00001784 int ret;
paul718e3742002-12-13 20:15:29 +00001785 char line[] = "write terminal\n";
1786 FILE *fp;
1787 char *integrate_sav = NULL;
1788
hasso95e735b2004-08-26 13:08:30 +00001789 integrate_sav = malloc (strlen (integrate_default) +
1790 strlen (CONF_BACKUP_EXT) + 1);
paul718e3742002-12-13 20:15:29 +00001791 strcpy (integrate_sav, integrate_default);
1792 strcat (integrate_sav, CONF_BACKUP_EXT);
1793
paul4fc01e62002-12-13 20:49:00 +00001794 fprintf (stdout,"Building Configuration...\n");
paul718e3742002-12-13 20:15:29 +00001795
hasso95e735b2004-08-26 13:08:30 +00001796 /* Move current configuration file to backup config file. */
paul718e3742002-12-13 20:15:29 +00001797 unlink (integrate_sav);
1798 rename (integrate_default, integrate_sav);
hasso95e735b2004-08-26 13:08:30 +00001799 free (integrate_sav);
paul4fc01e62002-12-13 20:49:00 +00001800
paul718e3742002-12-13 20:15:29 +00001801 fp = fopen (integrate_default, "w");
1802 if (fp == NULL)
1803 {
hasso95e735b2004-08-26 13:08:30 +00001804 fprintf (stdout,"%% Can't open configuration file %s.\n",
1805 integrate_default);
paul718e3742002-12-13 20:15:29 +00001806 return CMD_SUCCESS;
1807 }
paul718e3742002-12-13 20:15:29 +00001808
Balaji.G837d16c2012-09-26 14:09:10 +05301809 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00001810 ret = vtysh_client_config (&vtysh_client[i], line);
paul718e3742002-12-13 20:15:29 +00001811
1812 vtysh_config_dump (fp);
1813
1814 fclose (fp);
1815
gdtaa593d52003-12-22 20:15:53 +00001816 if (chmod (integrate_default, CONFIGFILE_MASK) != 0)
1817 {
1818 fprintf (stdout,"%% Can't chmod configuration file %s: %s (%d)\n",
ajs6099b3b2004-11-20 02:06:59 +00001819 integrate_default, safe_strerror(errno), errno);
gdtaa593d52003-12-22 20:15:53 +00001820 return CMD_WARNING;
1821 }
1822
paul4fc01e62002-12-13 20:49:00 +00001823 fprintf(stdout,"Integrated configuration saved to %s\n",integrate_default);
1824
1825 fprintf (stdout,"[OK]\n");
1826
paul718e3742002-12-13 20:15:29 +00001827 return CMD_SUCCESS;
1828}
1829
paul4fc01e62002-12-13 20:49:00 +00001830DEFUN (vtysh_write_memory,
1831 vtysh_write_memory_cmd,
1832 "write memory",
1833 "Write running configuration to memory, network, or terminal\n"
1834 "Write configuration to the file (same as write file)\n")
1835{
pauldfc0d9b2003-04-18 23:55:29 +00001836 int ret = CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001837 char line[] = "write memory\n";
ajsb1aa1472005-01-28 21:11:46 +00001838 u_int i;
paul4fc01e62002-12-13 20:49:00 +00001839
hassoe7168df2004-10-03 20:11:32 +00001840 /* If integrated Quagga.conf explicitely set. */
1841 if (vtysh_writeconfig_integrated)
1842 return write_config_integrated();
paul4fc01e62002-12-13 20:49:00 +00001843
1844 fprintf (stdout,"Building Configuration...\n");
1845
Balaji.G837d16c2012-09-26 14:09:10 +05301846 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00001847 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
hassoe7168df2004-10-03 20:11:32 +00001848
paul4fc01e62002-12-13 20:49:00 +00001849 fprintf (stdout,"[OK]\n");
1850
pauldfc0d9b2003-04-18 23:55:29 +00001851 return ret;
paul4fc01e62002-12-13 20:49:00 +00001852}
1853
paul718e3742002-12-13 20:15:29 +00001854ALIAS (vtysh_write_memory,
1855 vtysh_copy_runningconfig_startupconfig_cmd,
1856 "copy running-config startup-config",
1857 "Copy from one file to another\n"
1858 "Copy from current system configuration\n"
1859 "Copy to startup configuration\n")
1860
1861ALIAS (vtysh_write_memory,
1862 vtysh_write_file_cmd,
1863 "write file",
1864 "Write running configuration to memory, network, or terminal\n"
1865 "Write configuration to the file (same as write memory)\n")
1866
hasso4a6e2252003-05-25 11:51:29 +00001867ALIAS (vtysh_write_memory,
1868 vtysh_write_cmd,
1869 "write",
1870 "Write running configuration to memory, network, or terminal\n")
1871
paul718e3742002-12-13 20:15:29 +00001872ALIAS (vtysh_write_terminal,
1873 vtysh_show_running_config_cmd,
1874 "show running-config",
1875 SHOW_STR
1876 "Current operating configuration\n")
hassob094d262004-08-25 12:22:00 +00001877
hasso34553cc2004-08-27 13:56:39 +00001878DEFUN (vtysh_terminal_length,
1879 vtysh_terminal_length_cmd,
1880 "terminal length <0-512>",
1881 "Set terminal line parameters\n"
1882 "Set number of lines on a screen\n"
1883 "Number of lines on screen (0 for no pausing)\n")
1884{
1885 int lines;
1886 char *endptr = NULL;
1887 char default_pager[10];
1888
1889 lines = strtol (argv[0], &endptr, 10);
1890 if (lines < 0 || lines > 512 || *endptr != '\0')
1891 {
1892 vty_out (vty, "length is malformed%s", VTY_NEWLINE);
1893 return CMD_WARNING;
1894 }
1895
1896 if (vtysh_pager_name)
1897 {
1898 free (vtysh_pager_name);
1899 vtysh_pager_name = NULL;
1900 }
1901
1902 if (lines != 0)
1903 {
1904 snprintf(default_pager, 10, "more -%i", lines);
1905 vtysh_pager_name = strdup (default_pager);
1906 }
1907
1908 return CMD_SUCCESS;
1909}
1910
1911DEFUN (vtysh_terminal_no_length,
1912 vtysh_terminal_no_length_cmd,
1913 "terminal no length",
1914 "Set terminal line parameters\n"
1915 NO_STR
1916 "Set number of lines on a screen\n")
1917{
1918 if (vtysh_pager_name)
1919 {
1920 free (vtysh_pager_name);
1921 vtysh_pager_name = NULL;
1922 }
1923
1924 vtysh_pager_init();
1925 return CMD_SUCCESS;
1926}
1927
hassof2799e62004-10-28 17:43:11 +00001928DEFUN (vtysh_show_daemons,
1929 vtysh_show_daemons_cmd,
1930 "show daemons",
hassoe7168df2004-10-03 20:11:32 +00001931 SHOW_STR
1932 "Show list of running daemons\n")
1933{
ajsb1aa1472005-01-28 21:11:46 +00001934 u_int i;
1935
Balaji.G837d16c2012-09-26 14:09:10 +05301936 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00001937 if ( vtysh_client[i].fd >= 0 )
1938 vty_out(vty, " %s", vtysh_client[i].name);
hassoe7168df2004-10-03 20:11:32 +00001939 vty_out(vty, "%s", VTY_NEWLINE);
1940
1941 return CMD_SUCCESS;
1942}
1943
paul718e3742002-12-13 20:15:29 +00001944/* Execute command in child process. */
ajs274a4a42004-12-07 15:39:31 +00001945static int
hasso5862ff52004-10-11 13:20:40 +00001946execute_command (const char *command, int argc, const char *arg1,
1947 const char *arg2)
paul718e3742002-12-13 20:15:29 +00001948{
1949 int ret;
1950 pid_t pid;
1951 int status;
1952
1953 /* Call fork(). */
1954 pid = fork ();
1955
1956 if (pid < 0)
1957 {
1958 /* Failure of fork(). */
ajs6099b3b2004-11-20 02:06:59 +00001959 fprintf (stderr, "Can't fork: %s\n", safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +00001960 exit (1);
1961 }
1962 else if (pid == 0)
1963 {
1964 /* This is child process. */
1965 switch (argc)
1966 {
1967 case 0:
hassofa2b17e2004-03-04 17:45:00 +00001968 ret = execlp (command, command, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00001969 break;
1970 case 1:
hassofa2b17e2004-03-04 17:45:00 +00001971 ret = execlp (command, command, arg1, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00001972 break;
1973 case 2:
hassofa2b17e2004-03-04 17:45:00 +00001974 ret = execlp (command, command, arg1, arg2, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00001975 break;
1976 }
1977
1978 /* When execlp suceed, this part is not executed. */
ajs6099b3b2004-11-20 02:06:59 +00001979 fprintf (stderr, "Can't execute %s: %s\n", command, safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +00001980 exit (1);
1981 }
1982 else
1983 {
1984 /* This is parent. */
1985 execute_flag = 1;
1986 ret = wait4 (pid, &status, 0, NULL);
1987 execute_flag = 0;
1988 }
1989 return 0;
1990}
1991
1992DEFUN (vtysh_ping,
1993 vtysh_ping_cmd,
1994 "ping WORD",
hasso4eeccf12003-06-25 10:49:55 +00001995 "Send echo messages\n"
paul718e3742002-12-13 20:15:29 +00001996 "Ping destination address or hostname\n")
1997{
1998 execute_command ("ping", 1, argv[0], NULL);
1999 return CMD_SUCCESS;
2000}
2001
hasso4eeccf12003-06-25 10:49:55 +00002002ALIAS (vtysh_ping,
2003 vtysh_ping_ip_cmd,
2004 "ping ip WORD",
2005 "Send echo messages\n"
2006 "IP echo\n"
2007 "Ping destination address or hostname\n")
2008
paul718e3742002-12-13 20:15:29 +00002009DEFUN (vtysh_traceroute,
2010 vtysh_traceroute_cmd,
2011 "traceroute WORD",
2012 "Trace route to destination\n"
2013 "Trace route to destination address or hostname\n")
2014{
2015 execute_command ("traceroute", 1, argv[0], NULL);
2016 return CMD_SUCCESS;
2017}
2018
hasso4eeccf12003-06-25 10:49:55 +00002019ALIAS (vtysh_traceroute,
2020 vtysh_traceroute_ip_cmd,
2021 "traceroute ip WORD",
2022 "Trace route to destination\n"
2023 "IP trace\n"
2024 "Trace route to destination address or hostname\n")
2025
2026#ifdef HAVE_IPV6
2027DEFUN (vtysh_ping6,
2028 vtysh_ping6_cmd,
2029 "ping ipv6 WORD",
2030 "Send echo messages\n"
2031 "IPv6 echo\n"
2032 "Ping destination address or hostname\n")
2033{
2034 execute_command ("ping6", 1, argv[0], NULL);
2035 return CMD_SUCCESS;
2036}
2037
2038DEFUN (vtysh_traceroute6,
2039 vtysh_traceroute6_cmd,
2040 "traceroute ipv6 WORD",
2041 "Trace route to destination\n"
2042 "IPv6 trace\n"
2043 "Trace route to destination address or hostname\n")
2044{
2045 execute_command ("traceroute6", 1, argv[0], NULL);
2046 return CMD_SUCCESS;
2047}
2048#endif
2049
paul718e3742002-12-13 20:15:29 +00002050DEFUN (vtysh_telnet,
2051 vtysh_telnet_cmd,
2052 "telnet WORD",
2053 "Open a telnet connection\n"
2054 "IP address or hostname of a remote system\n")
2055{
2056 execute_command ("telnet", 1, argv[0], NULL);
2057 return CMD_SUCCESS;
2058}
2059
2060DEFUN (vtysh_telnet_port,
2061 vtysh_telnet_port_cmd,
2062 "telnet WORD PORT",
2063 "Open a telnet connection\n"
2064 "IP address or hostname of a remote system\n"
2065 "TCP Port number\n")
2066{
2067 execute_command ("telnet", 2, argv[0], argv[1]);
2068 return CMD_SUCCESS;
2069}
2070
paul5087df52003-01-25 06:56:09 +00002071DEFUN (vtysh_ssh,
2072 vtysh_ssh_cmd,
2073 "ssh WORD",
2074 "Open an ssh connection\n"
2075 "[user@]host\n")
2076{
2077 execute_command ("ssh", 1, argv[0], NULL);
2078 return CMD_SUCCESS;
2079}
2080
paul718e3742002-12-13 20:15:29 +00002081DEFUN (vtysh_start_shell,
2082 vtysh_start_shell_cmd,
2083 "start-shell",
2084 "Start UNIX shell\n")
2085{
2086 execute_command ("sh", 0, NULL, NULL);
2087 return CMD_SUCCESS;
2088}
2089
2090DEFUN (vtysh_start_bash,
2091 vtysh_start_bash_cmd,
2092 "start-shell bash",
2093 "Start UNIX shell\n"
2094 "Start bash\n")
2095{
2096 execute_command ("bash", 0, NULL, NULL);
2097 return CMD_SUCCESS;
2098}
2099
2100DEFUN (vtysh_start_zsh,
2101 vtysh_start_zsh_cmd,
2102 "start-shell zsh",
2103 "Start UNIX shell\n"
2104 "Start Z shell\n")
2105{
2106 execute_command ("zsh", 0, NULL, NULL);
2107 return CMD_SUCCESS;
2108}
hassob094d262004-08-25 12:22:00 +00002109
ajs274a4a42004-12-07 15:39:31 +00002110static void
paul718e3742002-12-13 20:15:29 +00002111vtysh_install_default (enum node_type node)
2112{
2113 install_element (node, &config_list_cmd);
2114}
2115
2116/* Making connection to protocol daemon. */
ajs274a4a42004-12-07 15:39:31 +00002117static int
ajsb1aa1472005-01-28 21:11:46 +00002118vtysh_connect (struct vtysh_client *vclient)
paul718e3742002-12-13 20:15:29 +00002119{
2120 int ret;
2121 int sock, len;
2122 struct sockaddr_un addr;
2123 struct stat s_stat;
paul718e3742002-12-13 20:15:29 +00002124
paul718e3742002-12-13 20:15:29 +00002125 /* Stat socket to see if we have permission to access it. */
ajsb1aa1472005-01-28 21:11:46 +00002126 ret = stat (vclient->path, &s_stat);
paul718e3742002-12-13 20:15:29 +00002127 if (ret < 0 && errno != ENOENT)
2128 {
2129 fprintf (stderr, "vtysh_connect(%s): stat = %s\n",
ajsb1aa1472005-01-28 21:11:46 +00002130 vclient->path, safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002131 exit(1);
2132 }
2133
2134 if (ret >= 0)
2135 {
2136 if (! S_ISSOCK(s_stat.st_mode))
2137 {
2138 fprintf (stderr, "vtysh_connect(%s): Not a socket\n",
ajsb1aa1472005-01-28 21:11:46 +00002139 vclient->path);
paul718e3742002-12-13 20:15:29 +00002140 exit (1);
2141 }
2142
paul718e3742002-12-13 20:15:29 +00002143 }
2144
2145 sock = socket (AF_UNIX, SOCK_STREAM, 0);
2146 if (sock < 0)
2147 {
2148#ifdef DEBUG
ajsb1aa1472005-01-28 21:11:46 +00002149 fprintf(stderr, "vtysh_connect(%s): socket = %s\n", vclient->path,
ajs6099b3b2004-11-20 02:06:59 +00002150 safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002151#endif /* DEBUG */
2152 return -1;
2153 }
2154
2155 memset (&addr, 0, sizeof (struct sockaddr_un));
2156 addr.sun_family = AF_UNIX;
ajsb1aa1472005-01-28 21:11:46 +00002157 strncpy (addr.sun_path, vclient->path, strlen (vclient->path));
Paul Jakma6f0e3f62007-05-10 02:38:51 +00002158#ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
paul718e3742002-12-13 20:15:29 +00002159 len = addr.sun_len = SUN_LEN(&addr);
2160#else
2161 len = sizeof (addr.sun_family) + strlen (addr.sun_path);
Paul Jakma6f0e3f62007-05-10 02:38:51 +00002162#endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
paul718e3742002-12-13 20:15:29 +00002163
2164 ret = connect (sock, (struct sockaddr *) &addr, len);
2165 if (ret < 0)
2166 {
2167#ifdef DEBUG
ajsb1aa1472005-01-28 21:11:46 +00002168 fprintf(stderr, "vtysh_connect(%s): connect = %s\n", vclient->path,
ajs6099b3b2004-11-20 02:06:59 +00002169 safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002170#endif /* DEBUG */
2171 close (sock);
2172 return -1;
2173 }
2174 vclient->fd = sock;
2175
2176 return 0;
2177}
2178
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002179int
2180vtysh_connect_all(const char *daemon_name)
paul718e3742002-12-13 20:15:29 +00002181{
ajsb1aa1472005-01-28 21:11:46 +00002182 u_int i;
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002183 int rc = 0;
2184 int matches = 0;
ajsb1aa1472005-01-28 21:11:46 +00002185
Balaji.G837d16c2012-09-26 14:09:10 +05302186 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00002187 {
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002188 if (!daemon_name || !strcmp(daemon_name, vtysh_client[i].name))
2189 {
2190 matches++;
2191 if (vtysh_connect(&vtysh_client[i]) == 0)
2192 rc++;
2193 /* We need direct access to ripd in vtysh_exit_ripd_only. */
2194 if (vtysh_client[i].flag == VTYSH_RIPD)
2195 ripd_client = &vtysh_client[i];
2196 }
ajsb1aa1472005-01-28 21:11:46 +00002197 }
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002198 if (!matches)
2199 fprintf(stderr, "Error: no daemons match name %s!\n", daemon_name);
2200 return rc;
paul718e3742002-12-13 20:15:29 +00002201}
2202
hasso95e735b2004-08-26 13:08:30 +00002203/* To disable readline's filename completion. */
ajs274a4a42004-12-07 15:39:31 +00002204static char *
pauldfc0d9b2003-04-18 23:55:29 +00002205vtysh_completion_entry_function (const char *ignore, int invoking_key)
paul718e3742002-12-13 20:15:29 +00002206{
pauldfc0d9b2003-04-18 23:55:29 +00002207 return NULL;
paul718e3742002-12-13 20:15:29 +00002208}
2209
2210void
ajsb1aa1472005-01-28 21:11:46 +00002211vtysh_readline_init (void)
paul718e3742002-12-13 20:15:29 +00002212{
2213 /* readline related settings. */
hasso53a6f932005-09-15 06:50:53 +00002214 rl_bind_key ('?', (Function *) vtysh_rl_describe);
paul68980082003-03-25 05:07:42 +00002215 rl_completion_entry_function = vtysh_completion_entry_function;
paul718e3742002-12-13 20:15:29 +00002216 rl_attempted_completion_function = (CPPFunction *)new_completion;
2217 /* do not append space after completion. It will be appended
hasso95e735b2004-08-26 13:08:30 +00002218 * in new_completion() function explicitly. */
paul718e3742002-12-13 20:15:29 +00002219 rl_completion_append_character = '\0';
2220}
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}