blob: b33ac90bd75639608cc387fea793ae28f43da22b [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},
Leonard Herve596470f2009-08-11 15:45:26 -030061 { .fd = -1, .name = "pimd", .flag = VTYSH_PIMD, .path = PIM_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
David Lampartera9eb9062015-03-04 07:07:01 +0100253static void
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. */
David Lampartera9eb9062015-03-04 07:07:01 +0100549static int
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;
Christian Frankecd40b322013-09-30 12:27:51 +0000557 struct cmd_token *token;
paul718e3742002-12-13 20:15:29 +0000558
559 vline = cmd_make_strvec (rl_line_buffer);
560
561 /* In case of '> ?'. */
562 if (vline == NULL)
563 {
564 vline = vector_init (1);
David Lampartera91a3ba2015-03-03 09:06:51 +0100565 vector_set (vline, NULL);
paul718e3742002-12-13 20:15:29 +0000566 }
567 else
568 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
David Lampartera91a3ba2015-03-03 09:06:51 +0100569 vector_set (vline, NULL);
paul718e3742002-12-13 20:15:29 +0000570
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++)
Christian Frankecd40b322013-09-30 12:27:51 +0000595 if ((token = vector_slot (describe, i)) != NULL)
paul718e3742002-12-13 20:15:29 +0000596 {
597 int len;
598
Christian Frankecd40b322013-09-30 12:27:51 +0000599 if (token->cmd[0] == '\0')
paul718e3742002-12-13 20:15:29 +0000600 continue;
601
Christian Frankecd40b322013-09-30 12:27:51 +0000602 len = strlen (token->cmd);
603 if (token->cmd[0] == '.')
paul718e3742002-12-13 20:15:29 +0000604 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++)
Christian Frankecd40b322013-09-30 12:27:51 +0000611 if ((token = vector_slot (describe, i)) != NULL)
paul718e3742002-12-13 20:15:29 +0000612 {
Christian Frankecd40b322013-09-30 12:27:51 +0000613 if (token->cmd[0] == '\0')
paul718e3742002-12-13 20:15:29 +0000614 continue;
615
Christian Frankecd40b322013-09-30 12:27:51 +0000616 if (! token->desc)
paul4fc01e62002-12-13 20:49:00 +0000617 fprintf (stdout," %-s\n",
Christian Frankecd40b322013-09-30 12:27:51 +0000618 token->cmd[0] == '.' ? token->cmd + 1 : token->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,
Christian Frankecd40b322013-09-30 12:27:51 +0000622 token->cmd[0] == '.' ? token->cmd + 1 : token->cmd,
623 token->desc);
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]))
David Lampartera91a3ba2015-03-03 09:06:51 +0100659 vector_set (vline, NULL);
paul718e3742002-12-13 20:15:29 +0000660
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;
Christian Franke67e7a212013-03-04 09:23:30 +0000680 if (complete_status != CMD_COMPLETE_FULL_MATCH)
681 /* only append a space on full match */
682 rl_completion_append_character = '\0';
paul718e3742002-12-13 20:15:29 +0000683 }
684
685 return matches;
686}
687
ajs274a4a42004-12-07 15:39:31 +0000688#if 0
689/* This function is not actually being used. */
690static char **
paul718e3742002-12-13 20:15:29 +0000691vtysh_completion (char *text, int start, int end)
692{
693 int ret;
694 vector vline;
695 char **matched = NULL;
696
697 if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
698 return NULL;
699
700 vline = cmd_make_strvec (rl_line_buffer);
701 if (vline == NULL)
702 return NULL;
703
704 /* In case of 'help \t'. */
705 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
706 vector_set (vline, '\0');
707
708 matched = cmd_complete_command (vline, vty, &ret);
709
710 cmd_free_strvec (vline);
711
712 return (char **) matched;
713}
ajs274a4a42004-12-07 15:39:31 +0000714#endif
paul718e3742002-12-13 20:15:29 +0000715
hasso95e735b2004-08-26 13:08:30 +0000716/* Vty node structures. */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800717static struct cmd_node bgp_node =
paul718e3742002-12-13 20:15:29 +0000718{
719 BGP_NODE,
720 "%s(config-router)# ",
721};
722
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800723static struct cmd_node rip_node =
paul718e3742002-12-13 20:15:29 +0000724{
725 RIP_NODE,
726 "%s(config-router)# ",
727};
728
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800729static struct cmd_node isis_node =
hassoc25e4582003-12-23 10:39:08 +0000730{
731 ISIS_NODE,
732 "%s(config-router)# ",
hassoc25e4582003-12-23 10:39:08 +0000733};
734
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800735static struct cmd_node interface_node =
paul718e3742002-12-13 20:15:29 +0000736{
737 INTERFACE_NODE,
738 "%s(config-if)# ",
739};
740
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800741static struct cmd_node rmap_node =
hasso95e735b2004-08-26 13:08:30 +0000742{
743 RMAP_NODE,
744 "%s(config-route-map)# "
745};
746
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800747static struct cmd_node zebra_node =
hasso95e735b2004-08-26 13:08:30 +0000748{
749 ZEBRA_NODE,
750 "%s(config-router)# "
751};
752
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800753static struct cmd_node bgp_vpnv4_node =
hasso95e735b2004-08-26 13:08:30 +0000754{
755 BGP_VPNV4_NODE,
756 "%s(config-router-af)# "
757};
758
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800759static struct cmd_node bgp_ipv4_node =
hasso95e735b2004-08-26 13:08:30 +0000760{
761 BGP_IPV4_NODE,
762 "%s(config-router-af)# "
763};
764
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800765static struct cmd_node bgp_ipv4m_node =
hasso95e735b2004-08-26 13:08:30 +0000766{
767 BGP_IPV4M_NODE,
768 "%s(config-router-af)# "
769};
770
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800771static struct cmd_node bgp_ipv6_node =
hasso95e735b2004-08-26 13:08:30 +0000772{
773 BGP_IPV6_NODE,
774 "%s(config-router-af)# "
775};
776
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800777static struct cmd_node bgp_ipv6m_node =
paul57b5b7e2005-08-22 22:44:29 +0000778{
779 BGP_IPV6M_NODE,
780 "%s(config-router-af)# "
781};
782
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800783static struct cmd_node ospf_node =
hasso95e735b2004-08-26 13:08:30 +0000784{
785 OSPF_NODE,
786 "%s(config-router)# "
787};
788
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800789static struct cmd_node ripng_node =
hasso95e735b2004-08-26 13:08:30 +0000790{
791 RIPNG_NODE,
792 "%s(config-router)# "
793};
794
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800795static struct cmd_node ospf6_node =
hasso95e735b2004-08-26 13:08:30 +0000796{
797 OSPF6_NODE,
798 "%s(config-ospf6)# "
799};
800
David Lamparteree53c8b2015-05-23 05:45:59 +0200801static struct cmd_node babel_node =
802{
803 BABEL_NODE,
804 "%s(config-babel)# "
805};
806
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800807static struct cmd_node keychain_node =
hasso95e735b2004-08-26 13:08:30 +0000808{
809 KEYCHAIN_NODE,
810 "%s(config-keychain)# "
811};
812
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800813static struct cmd_node keychain_key_node =
hasso95e735b2004-08-26 13:08:30 +0000814{
815 KEYCHAIN_KEY_NODE,
816 "%s(config-keychain-key)# "
817};
818
hassoe7168df2004-10-03 20:11:32 +0000819/* Defined in lib/vty.c */
820extern struct cmd_node vty_node;
821
hasso95e735b2004-08-26 13:08:30 +0000822/* When '^Z' is received from vty, move down to the enable mode. */
David Lampartera9eb9062015-03-04 07:07:01 +0100823static int
ajsb1aa1472005-01-28 21:11:46 +0000824vtysh_end (void)
hasso95e735b2004-08-26 13:08:30 +0000825{
826 switch (vty->node)
827 {
828 case VIEW_NODE:
829 case ENABLE_NODE:
830 /* Nothing to do. */
831 break;
832 default:
833 vty->node = ENABLE_NODE;
834 break;
835 }
836 return CMD_SUCCESS;
837}
838
839DEFUNSH (VTYSH_ALL,
840 vtysh_end_all,
841 vtysh_end_all_cmd,
842 "end",
hassoe7168df2004-10-03 20:11:32 +0000843 "End current mode and change to enable mode\n")
hasso95e735b2004-08-26 13:08:30 +0000844{
hasso42895462004-09-26 16:25:07 +0000845 return vtysh_end ();
hasso95e735b2004-08-26 13:08:30 +0000846}
847
paul718e3742002-12-13 20:15:29 +0000848DEFUNSH (VTYSH_BGPD,
849 router_bgp,
850 router_bgp_cmd,
Paul Jakma320da872008-07-02 13:40:33 +0000851 "router bgp " CMD_AS_RANGE,
paul718e3742002-12-13 20:15:29 +0000852 ROUTER_STR
853 BGP_STR
854 AS_STR)
855{
856 vty->node = BGP_NODE;
857 return CMD_SUCCESS;
858}
859
Paul Jakma10895fd2008-07-03 19:34:48 +0000860ALIAS_SH (VTYSH_BGPD,
861 router_bgp,
862 router_bgp_view_cmd,
863 "router bgp " CMD_AS_RANGE " view WORD",
864 ROUTER_STR
865 BGP_STR
866 AS_STR
867 "BGP view\n"
868 "view name\n")
869
paul718e3742002-12-13 20:15:29 +0000870DEFUNSH (VTYSH_BGPD,
871 address_family_vpnv4,
872 address_family_vpnv4_cmd,
873 "address-family vpnv4",
874 "Enter Address Family command mode\n"
875 "Address family\n")
876{
877 vty->node = BGP_VPNV4_NODE;
878 return CMD_SUCCESS;
879}
880
881DEFUNSH (VTYSH_BGPD,
882 address_family_vpnv4_unicast,
883 address_family_vpnv4_unicast_cmd,
884 "address-family vpnv4 unicast",
885 "Enter Address Family command mode\n"
886 "Address family\n"
887 "Address Family Modifier\n")
888{
889 vty->node = BGP_VPNV4_NODE;
890 return CMD_SUCCESS;
891}
892
893DEFUNSH (VTYSH_BGPD,
894 address_family_ipv4_unicast,
895 address_family_ipv4_unicast_cmd,
896 "address-family ipv4 unicast",
897 "Enter Address Family command mode\n"
898 "Address family\n"
899 "Address Family Modifier\n")
900{
901 vty->node = BGP_IPV4_NODE;
902 return CMD_SUCCESS;
903}
904
905DEFUNSH (VTYSH_BGPD,
906 address_family_ipv4_multicast,
907 address_family_ipv4_multicast_cmd,
908 "address-family ipv4 multicast",
909 "Enter Address Family command mode\n"
910 "Address family\n"
911 "Address Family Modifier\n")
912{
913 vty->node = BGP_IPV4M_NODE;
914 return CMD_SUCCESS;
915}
916
917DEFUNSH (VTYSH_BGPD,
918 address_family_ipv6,
919 address_family_ipv6_cmd,
920 "address-family ipv6",
921 "Enter Address Family command mode\n"
922 "Address family\n")
923{
924 vty->node = BGP_IPV6_NODE;
925 return CMD_SUCCESS;
926}
927
928DEFUNSH (VTYSH_BGPD,
929 address_family_ipv6_unicast,
930 address_family_ipv6_unicast_cmd,
931 "address-family ipv6 unicast",
932 "Enter Address Family command mode\n"
933 "Address family\n"
934 "Address Family Modifier\n")
935{
936 vty->node = BGP_IPV6_NODE;
937 return CMD_SUCCESS;
938}
939
paul57b5b7e2005-08-22 22:44:29 +0000940DEFUNSH (VTYSH_BGPD,
941 address_family_ipv6_multicast,
942 address_family_ipv6_multicast_cmd,
943 "address-family ipv6 multicast",
944 "Enter Address Family command mode\n"
945 "Address family\n"
946 "Address Family Modifier\n")
947{
948 vty->node = BGP_IPV6M_NODE;
949 return CMD_SUCCESS;
950}
951
paul718e3742002-12-13 20:15:29 +0000952DEFUNSH (VTYSH_RIPD,
953 key_chain,
954 key_chain_cmd,
955 "key chain WORD",
956 "Authentication key management\n"
957 "Key-chain management\n"
958 "Key-chain name\n")
959{
960 vty->node = KEYCHAIN_NODE;
961 return CMD_SUCCESS;
962}
963
964DEFUNSH (VTYSH_RIPD,
965 key,
966 key_cmd,
967 "key <0-2147483647>",
968 "Configure a key\n"
969 "Key identifier number\n")
970{
971 vty->node = KEYCHAIN_KEY_NODE;
972 return CMD_SUCCESS;
973}
974
975DEFUNSH (VTYSH_RIPD,
976 router_rip,
977 router_rip_cmd,
978 "router rip",
979 ROUTER_STR
980 "RIP")
981{
982 vty->node = RIP_NODE;
983 return CMD_SUCCESS;
984}
985
986DEFUNSH (VTYSH_RIPNGD,
987 router_ripng,
988 router_ripng_cmd,
989 "router ripng",
990 ROUTER_STR
991 "RIPng")
992{
993 vty->node = RIPNG_NODE;
994 return CMD_SUCCESS;
995}
996
997DEFUNSH (VTYSH_OSPFD,
998 router_ospf,
999 router_ospf_cmd,
1000 "router ospf",
1001 "Enable a routing process\n"
1002 "Start OSPF configuration\n")
1003{
1004 vty->node = OSPF_NODE;
1005 return CMD_SUCCESS;
1006}
1007
1008DEFUNSH (VTYSH_OSPF6D,
1009 router_ospf6,
1010 router_ospf6_cmd,
1011 "router ospf6",
1012 OSPF6_ROUTER_STR
1013 OSPF6_STR)
1014{
1015 vty->node = OSPF6_NODE;
1016 return CMD_SUCCESS;
1017}
1018
hassoc25e4582003-12-23 10:39:08 +00001019DEFUNSH (VTYSH_ISISD,
hassob094d262004-08-25 12:22:00 +00001020 router_isis,
1021 router_isis_cmd,
1022 "router isis WORD",
1023 ROUTER_STR
1024 "ISO IS-IS\n"
1025 "ISO Routing area tag")
hassoc25e4582003-12-23 10:39:08 +00001026{
1027 vty->node = ISIS_NODE;
1028 return CMD_SUCCESS;
1029}
1030
paul718e3742002-12-13 20:15:29 +00001031DEFUNSH (VTYSH_RMAP,
1032 route_map,
1033 route_map_cmd,
1034 "route-map WORD (deny|permit) <1-65535>",
1035 "Create route-map or enter route-map command mode\n"
1036 "Route map tag\n"
1037 "Route map denies set operations\n"
1038 "Route map permits set operations\n"
1039 "Sequence to insert to/delete from existing route-map entry\n")
1040{
1041 vty->node = RMAP_NODE;
1042 return CMD_SUCCESS;
1043}
1044
paul718e3742002-12-13 20:15:29 +00001045DEFUNSH (VTYSH_ALL,
hassoe7168df2004-10-03 20:11:32 +00001046 vtysh_line_vty,
1047 vtysh_line_vty_cmd,
1048 "line vty",
1049 "Configure a terminal line\n"
1050 "Virtual terminal\n")
1051{
1052 vty->node = VTY_NODE;
1053 return CMD_SUCCESS;
1054}
1055
1056DEFUNSH (VTYSH_ALL,
paul718e3742002-12-13 20:15:29 +00001057 vtysh_enable,
1058 vtysh_enable_cmd,
1059 "enable",
1060 "Turn on privileged mode command\n")
1061{
1062 vty->node = ENABLE_NODE;
1063 return CMD_SUCCESS;
1064}
1065
paul718e3742002-12-13 20:15:29 +00001066DEFUNSH (VTYSH_ALL,
1067 vtysh_disable,
1068 vtysh_disable_cmd,
1069 "disable",
1070 "Turn off privileged mode command\n")
1071{
1072 if (vty->node == ENABLE_NODE)
1073 vty->node = VIEW_NODE;
1074 return CMD_SUCCESS;
1075}
1076
paul718e3742002-12-13 20:15:29 +00001077DEFUNSH (VTYSH_ALL,
1078 vtysh_config_terminal,
1079 vtysh_config_terminal_cmd,
1080 "configure terminal",
1081 "Configuration from vty interface\n"
1082 "Configuration terminal\n")
1083{
1084 vty->node = CONFIG_NODE;
1085 return CMD_SUCCESS;
1086}
1087
ajs274a4a42004-12-07 15:39:31 +00001088static int
paul718e3742002-12-13 20:15:29 +00001089vtysh_exit (struct vty *vty)
1090{
1091 switch (vty->node)
1092 {
1093 case VIEW_NODE:
1094 case ENABLE_NODE:
1095 exit (0);
1096 break;
1097 case CONFIG_NODE:
1098 vty->node = ENABLE_NODE;
1099 break;
1100 case INTERFACE_NODE:
1101 case ZEBRA_NODE:
1102 case BGP_NODE:
1103 case RIP_NODE:
1104 case RIPNG_NODE:
1105 case OSPF_NODE:
1106 case OSPF6_NODE:
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +01001107 case BABEL_NODE:
hassoc25e4582003-12-23 10:39:08 +00001108 case ISIS_NODE:
paul718e3742002-12-13 20:15:29 +00001109 case MASC_NODE:
1110 case RMAP_NODE:
1111 case VTY_NODE:
1112 case KEYCHAIN_NODE:
hasso2a56df92004-05-09 23:16:40 +00001113 vtysh_execute("end");
1114 vtysh_execute("configure terminal");
paul718e3742002-12-13 20:15:29 +00001115 vty->node = CONFIG_NODE;
1116 break;
1117 case BGP_VPNV4_NODE:
1118 case BGP_IPV4_NODE:
1119 case BGP_IPV4M_NODE:
1120 case BGP_IPV6_NODE:
paul57b5b7e2005-08-22 22:44:29 +00001121 case BGP_IPV6M_NODE:
paul718e3742002-12-13 20:15:29 +00001122 vty->node = BGP_NODE;
1123 break;
1124 case KEYCHAIN_KEY_NODE:
1125 vty->node = KEYCHAIN_NODE;
1126 break;
1127 default:
1128 break;
1129 }
1130 return CMD_SUCCESS;
1131}
1132
1133DEFUNSH (VTYSH_ALL,
1134 vtysh_exit_all,
1135 vtysh_exit_all_cmd,
1136 "exit",
1137 "Exit current mode and down to previous mode\n")
1138{
1139 return vtysh_exit (vty);
1140}
1141
1142ALIAS (vtysh_exit_all,
1143 vtysh_quit_all_cmd,
1144 "quit",
1145 "Exit current mode and down to previous mode\n")
1146
1147DEFUNSH (VTYSH_BGPD,
1148 exit_address_family,
1149 exit_address_family_cmd,
1150 "exit-address-family",
1151 "Exit from Address Family configuration mode\n")
1152{
1153 if (vty->node == BGP_IPV4_NODE
1154 || vty->node == BGP_IPV4M_NODE
1155 || vty->node == BGP_VPNV4_NODE
paul57b5b7e2005-08-22 22:44:29 +00001156 || vty->node == BGP_IPV6_NODE
1157 || vty->node == BGP_IPV6M_NODE)
paul718e3742002-12-13 20:15:29 +00001158 vty->node = BGP_NODE;
1159 return CMD_SUCCESS;
1160}
1161
1162DEFUNSH (VTYSH_ZEBRA,
1163 vtysh_exit_zebra,
1164 vtysh_exit_zebra_cmd,
1165 "exit",
1166 "Exit current mode and down to previous mode\n")
1167{
1168 return vtysh_exit (vty);
1169}
1170
1171ALIAS (vtysh_exit_zebra,
1172 vtysh_quit_zebra_cmd,
1173 "quit",
1174 "Exit current mode and down to previous mode\n")
1175
1176DEFUNSH (VTYSH_RIPD,
1177 vtysh_exit_ripd,
1178 vtysh_exit_ripd_cmd,
1179 "exit",
1180 "Exit current mode and down to previous mode\n")
1181{
1182 return vtysh_exit (vty);
1183}
1184
1185ALIAS (vtysh_exit_ripd,
1186 vtysh_quit_ripd_cmd,
1187 "quit",
1188 "Exit current mode and down to previous mode\n")
1189
paul68980082003-03-25 05:07:42 +00001190DEFUNSH (VTYSH_RIPNGD,
hassob094d262004-08-25 12:22:00 +00001191 vtysh_exit_ripngd,
1192 vtysh_exit_ripngd_cmd,
1193 "exit",
1194 "Exit current mode and down to previous mode\n")
paul68980082003-03-25 05:07:42 +00001195{
1196 return vtysh_exit (vty);
1197}
1198
1199ALIAS (vtysh_exit_ripngd,
1200 vtysh_quit_ripngd_cmd,
1201 "quit",
1202 "Exit current mode and down to previous mode\n")
1203
paul718e3742002-12-13 20:15:29 +00001204DEFUNSH (VTYSH_RMAP,
1205 vtysh_exit_rmap,
1206 vtysh_exit_rmap_cmd,
1207 "exit",
1208 "Exit current mode and down to previous mode\n")
1209{
1210 return vtysh_exit (vty);
1211}
1212
1213ALIAS (vtysh_exit_rmap,
1214 vtysh_quit_rmap_cmd,
1215 "quit",
1216 "Exit current mode and down to previous mode\n")
1217
1218DEFUNSH (VTYSH_BGPD,
1219 vtysh_exit_bgpd,
1220 vtysh_exit_bgpd_cmd,
1221 "exit",
1222 "Exit current mode and down to previous mode\n")
1223{
1224 return vtysh_exit (vty);
1225}
1226
1227ALIAS (vtysh_exit_bgpd,
1228 vtysh_quit_bgpd_cmd,
1229 "quit",
1230 "Exit current mode and down to previous mode\n")
1231
1232DEFUNSH (VTYSH_OSPFD,
1233 vtysh_exit_ospfd,
1234 vtysh_exit_ospfd_cmd,
1235 "exit",
1236 "Exit current mode and down to previous mode\n")
1237{
1238 return vtysh_exit (vty);
1239}
1240
1241ALIAS (vtysh_exit_ospfd,
1242 vtysh_quit_ospfd_cmd,
1243 "quit",
1244 "Exit current mode and down to previous mode\n")
1245
paul68980082003-03-25 05:07:42 +00001246DEFUNSH (VTYSH_OSPF6D,
hassob094d262004-08-25 12:22:00 +00001247 vtysh_exit_ospf6d,
1248 vtysh_exit_ospf6d_cmd,
1249 "exit",
1250 "Exit current mode and down to previous mode\n")
paul68980082003-03-25 05:07:42 +00001251{
1252 return vtysh_exit (vty);
1253}
1254
1255ALIAS (vtysh_exit_ospf6d,
1256 vtysh_quit_ospf6d_cmd,
1257 "quit",
1258 "Exit current mode and down to previous mode\n")
1259
hassoc25e4582003-12-23 10:39:08 +00001260DEFUNSH (VTYSH_ISISD,
hassob094d262004-08-25 12:22:00 +00001261 vtysh_exit_isisd,
1262 vtysh_exit_isisd_cmd,
1263 "exit",
1264 "Exit current mode and down to previous mode\n")
hassoc25e4582003-12-23 10:39:08 +00001265{
1266 return vtysh_exit (vty);
1267}
1268
1269ALIAS (vtysh_exit_isisd,
1270 vtysh_quit_isisd_cmd,
1271 "quit",
1272 "Exit current mode and down to previous mode\n")
1273
hassoe7168df2004-10-03 20:11:32 +00001274DEFUNSH (VTYSH_ALL,
1275 vtysh_exit_line_vty,
1276 vtysh_exit_line_vty_cmd,
1277 "exit",
1278 "Exit current mode and down to previous mode\n")
1279{
1280 return vtysh_exit (vty);
1281}
1282
1283ALIAS (vtysh_exit_line_vty,
1284 vtysh_quit_line_vty_cmd,
1285 "quit",
1286 "Exit current mode and down to previous mode\n")
1287
hasso95e735b2004-08-26 13:08:30 +00001288DEFUNSH (VTYSH_INTERFACE,
paul718e3742002-12-13 20:15:29 +00001289 vtysh_interface,
1290 vtysh_interface_cmd,
1291 "interface IFNAME",
1292 "Select an interface to configure\n"
1293 "Interface's name\n")
1294{
1295 vty->node = INTERFACE_NODE;
1296 return CMD_SUCCESS;
1297}
1298
hasso95e735b2004-08-26 13:08:30 +00001299/* TODO Implement "no interface command in isisd. */
paul32d24632003-05-23 09:25:20 +00001300DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D,
1301 vtysh_no_interface_cmd,
1302 "no interface IFNAME",
1303 NO_STR
1304 "Delete a pseudo interface's configuration\n"
1305 "Interface's name\n")
1306
hasso95e735b2004-08-26 13:08:30 +00001307/* TODO Implement interface description commands in ripngd, ospf6d
1308 * and isisd. */
paul338a9912003-03-01 15:44:10 +00001309DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1310 interface_desc_cmd,
1311 "description .LINE",
1312 "Interface specific description\n"
1313 "Characters describing this interface\n")
paul464dc8d2003-03-28 02:25:45 +00001314
1315DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1316 no_interface_desc_cmd,
1317 "no description",
1318 NO_STR
1319 "Interface specific description\n")
paul338a9912003-03-01 15:44:10 +00001320
hasso95e735b2004-08-26 13:08:30 +00001321DEFUNSH (VTYSH_INTERFACE,
paul718e3742002-12-13 20:15:29 +00001322 vtysh_exit_interface,
1323 vtysh_exit_interface_cmd,
1324 "exit",
1325 "Exit current mode and down to previous mode\n")
1326{
1327 return vtysh_exit (vty);
1328}
1329
1330ALIAS (vtysh_exit_interface,
1331 vtysh_quit_interface_cmd,
1332 "quit",
1333 "Exit current mode and down to previous mode\n")
1334
Paul Jakma362b4032006-05-28 07:54:45 +00001335/* Memory */
1336DEFUN (vtysh_show_memory,
1337 vtysh_show_memory_cmd,
1338 "show memory",
1339 SHOW_STR
1340 "Memory statistics\n")
1341{
1342 unsigned int i;
1343 int ret = CMD_SUCCESS;
1344 char line[] = "show memory\n";
1345
Balaji.G837d16c2012-09-26 14:09:10 +05301346 for (i = 0; i < array_size(vtysh_client); i++)
Paul Jakma362b4032006-05-28 07:54:45 +00001347 if ( vtysh_client[i].fd >= 0 )
1348 {
1349 fprintf (stdout, "Memory statistics for %s:\n",
1350 vtysh_client[i].name);
1351 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1352 fprintf (stdout,"\n");
1353 }
1354
1355 return ret;
1356}
1357
hasso95e735b2004-08-26 13:08:30 +00001358/* Logging commands. */
Paul Jakmadbf7d132006-05-23 22:10:01 +00001359DEFUN (vtysh_show_logging,
1360 vtysh_show_logging_cmd,
1361 "show logging",
1362 SHOW_STR
1363 "Show current logging configuration\n")
1364{
1365 unsigned int i;
1366 int ret = CMD_SUCCESS;
1367 char line[] = "show logging\n";
1368
Balaji.G837d16c2012-09-26 14:09:10 +05301369 for (i = 0; i < array_size(vtysh_client); i++)
Paul Jakma4150f332006-05-23 22:10:55 +00001370 if ( vtysh_client[i].fd >= 0 )
1371 {
1372 fprintf (stdout,"Logging configuration for %s:\n",
1373 vtysh_client[i].name);
1374 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1375 fprintf (stdout,"\n");
1376 }
1377
Paul Jakmadbf7d132006-05-23 22:10:01 +00001378 return ret;
1379}
1380
hasso95e735b2004-08-26 13:08:30 +00001381DEFUNSH (VTYSH_ALL,
1382 vtysh_log_stdout,
1383 vtysh_log_stdout_cmd,
1384 "log stdout",
1385 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001386 "Set stdout logging level\n")
1387{
1388 return CMD_SUCCESS;
1389}
1390
1391DEFUNSH (VTYSH_ALL,
1392 vtysh_log_stdout_level,
1393 vtysh_log_stdout_level_cmd,
1394 "log stdout "LOG_LEVELS,
1395 "Logging control\n"
1396 "Set stdout logging level\n"
1397 LOG_LEVEL_DESC)
hasso95e735b2004-08-26 13:08:30 +00001398{
1399 return CMD_SUCCESS;
1400}
1401
1402DEFUNSH (VTYSH_ALL,
1403 no_vtysh_log_stdout,
1404 no_vtysh_log_stdout_cmd,
ajs274a4a42004-12-07 15:39:31 +00001405 "no log stdout [LEVEL]",
hasso95e735b2004-08-26 13:08:30 +00001406 NO_STR
1407 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001408 "Cancel logging to stdout\n"
1409 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001410{
1411 return CMD_SUCCESS;
1412}
1413
1414DEFUNSH (VTYSH_ALL,
1415 vtysh_log_file,
1416 vtysh_log_file_cmd,
1417 "log file FILENAME",
1418 "Logging control\n"
1419 "Logging to file\n"
1420 "Logging filename\n")
1421{
1422 return CMD_SUCCESS;
1423}
1424
1425DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001426 vtysh_log_file_level,
1427 vtysh_log_file_level_cmd,
1428 "log file FILENAME "LOG_LEVELS,
1429 "Logging control\n"
1430 "Logging to file\n"
1431 "Logging filename\n"
1432 LOG_LEVEL_DESC)
1433{
1434 return CMD_SUCCESS;
1435}
1436
1437DEFUNSH (VTYSH_ALL,
hasso95e735b2004-08-26 13:08:30 +00001438 no_vtysh_log_file,
1439 no_vtysh_log_file_cmd,
1440 "no log file [FILENAME]",
1441 NO_STR
1442 "Logging control\n"
1443 "Cancel logging to file\n"
1444 "Logging file name\n")
1445{
1446 return CMD_SUCCESS;
1447}
1448
ajs274a4a42004-12-07 15:39:31 +00001449ALIAS_SH (VTYSH_ALL,
1450 no_vtysh_log_file,
1451 no_vtysh_log_file_level_cmd,
1452 "no log file FILENAME LEVEL",
1453 NO_STR
1454 "Logging control\n"
1455 "Cancel logging to file\n"
1456 "Logging file name\n"
1457 "Logging level\n")
1458
1459DEFUNSH (VTYSH_ALL,
1460 vtysh_log_monitor,
1461 vtysh_log_monitor_cmd,
1462 "log monitor",
1463 "Logging control\n"
1464 "Set terminal line (monitor) logging level\n")
1465{
1466 return CMD_SUCCESS;
1467}
1468
1469DEFUNSH (VTYSH_ALL,
1470 vtysh_log_monitor_level,
1471 vtysh_log_monitor_level_cmd,
1472 "log monitor "LOG_LEVELS,
1473 "Logging control\n"
1474 "Set terminal line (monitor) logging level\n"
1475 LOG_LEVEL_DESC)
1476{
1477 return CMD_SUCCESS;
1478}
1479
1480DEFUNSH (VTYSH_ALL,
1481 no_vtysh_log_monitor,
1482 no_vtysh_log_monitor_cmd,
1483 "no log monitor [LEVEL]",
1484 NO_STR
1485 "Logging control\n"
1486 "Disable terminal line (monitor) logging\n"
1487 "Logging level\n")
1488{
1489 return CMD_SUCCESS;
1490}
1491
hasso95e735b2004-08-26 13:08:30 +00001492DEFUNSH (VTYSH_ALL,
1493 vtysh_log_syslog,
1494 vtysh_log_syslog_cmd,
1495 "log syslog",
1496 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001497 "Set syslog logging level\n")
1498{
1499 return CMD_SUCCESS;
1500}
1501
1502DEFUNSH (VTYSH_ALL,
1503 vtysh_log_syslog_level,
1504 vtysh_log_syslog_level_cmd,
1505 "log syslog "LOG_LEVELS,
1506 "Logging control\n"
1507 "Set syslog logging level\n"
1508 LOG_LEVEL_DESC)
hasso95e735b2004-08-26 13:08:30 +00001509{
1510 return CMD_SUCCESS;
1511}
1512
1513DEFUNSH (VTYSH_ALL,
1514 no_vtysh_log_syslog,
1515 no_vtysh_log_syslog_cmd,
ajs274a4a42004-12-07 15:39:31 +00001516 "no log syslog [LEVEL]",
hasso95e735b2004-08-26 13:08:30 +00001517 NO_STR
1518 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001519 "Cancel logging to syslog\n"
1520 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001521{
1522 return CMD_SUCCESS;
1523}
1524
1525DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001526 vtysh_log_facility,
1527 vtysh_log_facility_cmd,
1528 "log facility "LOG_FACILITIES,
hasso95e735b2004-08-26 13:08:30 +00001529 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001530 "Facility parameter for syslog messages\n"
1531 LOG_FACILITY_DESC)
1532
hasso95e735b2004-08-26 13:08:30 +00001533{
1534 return CMD_SUCCESS;
1535}
1536
1537DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001538 no_vtysh_log_facility,
1539 no_vtysh_log_facility_cmd,
1540 "no log facility [FACILITY]",
hasso95e735b2004-08-26 13:08:30 +00001541 NO_STR
1542 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001543 "Reset syslog facility to default (daemon)\n"
1544 "Syslog facility\n")
1545
1546{
1547 return CMD_SUCCESS;
1548}
1549
1550DEFUNSH_DEPRECATED (VTYSH_ALL,
1551 vtysh_log_trap,
1552 vtysh_log_trap_cmd,
1553 "log trap "LOG_LEVELS,
1554 "Logging control\n"
1555 "(Deprecated) Set logging level and default for all destinations\n"
1556 LOG_LEVEL_DESC)
1557
1558{
1559 return CMD_SUCCESS;
1560}
1561
1562DEFUNSH_DEPRECATED (VTYSH_ALL,
1563 no_vtysh_log_trap,
1564 no_vtysh_log_trap_cmd,
1565 "no log trap [LEVEL]",
1566 NO_STR
1567 "Logging control\n"
1568 "Permit all logging information\n"
1569 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001570{
1571 return CMD_SUCCESS;
1572}
1573
1574DEFUNSH (VTYSH_ALL,
1575 vtysh_log_record_priority,
1576 vtysh_log_record_priority_cmd,
1577 "log record-priority",
1578 "Logging control\n"
1579 "Log the priority of the message within the message\n")
1580{
1581 return CMD_SUCCESS;
1582}
1583
1584DEFUNSH (VTYSH_ALL,
1585 no_vtysh_log_record_priority,
1586 no_vtysh_log_record_priority_cmd,
1587 "no log record-priority",
1588 NO_STR
1589 "Logging control\n"
1590 "Do not log the priority of the message within the message\n")
1591{
1592 return CMD_SUCCESS;
1593}
1594
hassoe7168df2004-10-03 20:11:32 +00001595DEFUNSH (VTYSH_ALL,
Andrew J. Schorrc749b722007-04-29 03:53:31 +00001596 vtysh_log_timestamp_precision,
1597 vtysh_log_timestamp_precision_cmd,
1598 "log timestamp precision <0-6>",
1599 "Logging control\n"
1600 "Timestamp configuration\n"
1601 "Set the timestamp precision\n"
1602 "Number of subsecond digits\n")
1603{
1604 return CMD_SUCCESS;
1605}
1606
1607DEFUNSH (VTYSH_ALL,
1608 no_vtysh_log_timestamp_precision,
1609 no_vtysh_log_timestamp_precision_cmd,
1610 "no log timestamp precision",
1611 NO_STR
1612 "Logging control\n"
1613 "Timestamp configuration\n"
1614 "Reset the timestamp precision to the default value of 0\n")
1615{
1616 return CMD_SUCCESS;
1617}
1618
1619DEFUNSH (VTYSH_ALL,
hassoe7168df2004-10-03 20:11:32 +00001620 vtysh_service_password_encrypt,
1621 vtysh_service_password_encrypt_cmd,
1622 "service password-encryption",
1623 "Set up miscellaneous service\n"
1624 "Enable encrypted passwords\n")
1625{
1626 return CMD_SUCCESS;
1627}
1628
1629DEFUNSH (VTYSH_ALL,
1630 no_vtysh_service_password_encrypt,
1631 no_vtysh_service_password_encrypt_cmd,
1632 "no service password-encryption",
1633 NO_STR
1634 "Set up miscellaneous service\n"
1635 "Enable encrypted passwords\n")
1636{
1637 return CMD_SUCCESS;
1638}
1639
1640DEFUNSH (VTYSH_ALL,
1641 vtysh_config_password,
1642 vtysh_password_cmd,
1643 "password (8|) WORD",
1644 "Assign the terminal connection password\n"
1645 "Specifies a HIDDEN password will follow\n"
1646 "dummy string \n"
1647 "The HIDDEN line password string\n")
1648{
1649 return CMD_SUCCESS;
1650}
1651
1652DEFUNSH (VTYSH_ALL,
1653 vtysh_password_text,
1654 vtysh_password_text_cmd,
1655 "password LINE",
1656 "Assign the terminal connection password\n"
1657 "The UNENCRYPTED (cleartext) line password\n")
1658{
1659 return CMD_SUCCESS;
1660}
1661
1662DEFUNSH (VTYSH_ALL,
1663 vtysh_config_enable_password,
1664 vtysh_enable_password_cmd,
1665 "enable password (8|) WORD",
1666 "Modify enable password parameters\n"
1667 "Assign the privileged level password\n"
1668 "Specifies a HIDDEN password will follow\n"
1669 "dummy string \n"
1670 "The HIDDEN 'enable' password string\n")
1671{
1672 return CMD_SUCCESS;
1673}
1674
1675DEFUNSH (VTYSH_ALL,
1676 vtysh_enable_password_text,
1677 vtysh_enable_password_text_cmd,
1678 "enable password LINE",
1679 "Modify enable password parameters\n"
1680 "Assign the privileged level password\n"
1681 "The UNENCRYPTED (cleartext) 'enable' password\n")
1682{
1683 return CMD_SUCCESS;
1684}
1685
1686DEFUNSH (VTYSH_ALL,
1687 no_vtysh_config_enable_password,
1688 no_vtysh_enable_password_cmd,
1689 "no enable password",
1690 NO_STR
1691 "Modify enable password parameters\n"
1692 "Assign the privileged level password\n")
1693{
1694 return CMD_SUCCESS;
1695}
1696
paul718e3742002-12-13 20:15:29 +00001697DEFUN (vtysh_write_terminal,
1698 vtysh_write_terminal_cmd,
1699 "write terminal",
1700 "Write running configuration to memory, network, or terminal\n"
1701 "Write to terminal\n")
1702{
ajsb1aa1472005-01-28 21:11:46 +00001703 u_int i;
paul718e3742002-12-13 20:15:29 +00001704 char line[] = "write terminal\n";
1705 FILE *fp = NULL;
1706
1707 if (vtysh_pager_name)
1708 {
paul4fc01e62002-12-13 20:49:00 +00001709 fp = popen (vtysh_pager_name, "w");
paul718e3742002-12-13 20:15:29 +00001710 if (fp == NULL)
1711 {
1712 perror ("popen");
1713 exit (1);
1714 }
1715 }
1716 else
1717 fp = stdout;
1718
1719 vty_out (vty, "Building configuration...%s", VTY_NEWLINE);
1720 vty_out (vty, "%sCurrent configuration:%s", VTY_NEWLINE,
1721 VTY_NEWLINE);
hassoe7168df2004-10-03 20:11:32 +00001722 vty_out (vty, "!%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001723
Balaji.G837d16c2012-09-26 14:09:10 +05301724 for (i = 0; i < array_size(vtysh_client); i++)
David Lamparter6769f432015-03-04 07:18:24 +01001725 vtysh_client_config (&vtysh_client[i], line);
paul718e3742002-12-13 20:15:29 +00001726
hassoe7168df2004-10-03 20:11:32 +00001727 /* Integrate vtysh specific configuration. */
1728 vtysh_config_write ();
1729
paul718e3742002-12-13 20:15:29 +00001730 vtysh_config_dump (fp);
1731
1732 if (vtysh_pager_name && fp)
1733 {
1734 fflush (fp);
1735 if (pclose (fp) == -1)
1736 {
1737 perror ("pclose");
1738 exit (1);
1739 }
1740 fp = NULL;
1741 }
1742
Chris Caputo6e79f8b2009-06-23 05:55:57 +00001743 vty_out (vty, "end%s", VTY_NEWLINE);
1744
paul718e3742002-12-13 20:15:29 +00001745 return CMD_SUCCESS;
1746}
1747
hassoe7168df2004-10-03 20:11:32 +00001748DEFUN (vtysh_integrated_config,
1749 vtysh_integrated_config_cmd,
1750 "service integrated-vtysh-config",
1751 "Set up miscellaneous service\n"
1752 "Write configuration into integrated file\n")
paul4fc01e62002-12-13 20:49:00 +00001753{
hassoe7168df2004-10-03 20:11:32 +00001754 vtysh_writeconfig_integrated = 1;
1755 return CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001756}
1757
hassoe7168df2004-10-03 20:11:32 +00001758DEFUN (no_vtysh_integrated_config,
1759 no_vtysh_integrated_config_cmd,
1760 "no service integrated-vtysh-config",
1761 NO_STR
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 = 0;
1766 return CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001767}
1768
ajs274a4a42004-12-07 15:39:31 +00001769static int
1770write_config_integrated(void)
paul718e3742002-12-13 20:15:29 +00001771{
ajsb1aa1472005-01-28 21:11:46 +00001772 u_int i;
paul718e3742002-12-13 20:15:29 +00001773 char line[] = "write terminal\n";
1774 FILE *fp;
1775 char *integrate_sav = NULL;
1776
hasso95e735b2004-08-26 13:08:30 +00001777 integrate_sav = malloc (strlen (integrate_default) +
1778 strlen (CONF_BACKUP_EXT) + 1);
paul718e3742002-12-13 20:15:29 +00001779 strcpy (integrate_sav, integrate_default);
1780 strcat (integrate_sav, CONF_BACKUP_EXT);
1781
paul4fc01e62002-12-13 20:49:00 +00001782 fprintf (stdout,"Building Configuration...\n");
paul718e3742002-12-13 20:15:29 +00001783
hasso95e735b2004-08-26 13:08:30 +00001784 /* Move current configuration file to backup config file. */
paul718e3742002-12-13 20:15:29 +00001785 unlink (integrate_sav);
1786 rename (integrate_default, integrate_sav);
hasso95e735b2004-08-26 13:08:30 +00001787 free (integrate_sav);
paul4fc01e62002-12-13 20:49:00 +00001788
paul718e3742002-12-13 20:15:29 +00001789 fp = fopen (integrate_default, "w");
1790 if (fp == NULL)
1791 {
hasso95e735b2004-08-26 13:08:30 +00001792 fprintf (stdout,"%% Can't open configuration file %s.\n",
1793 integrate_default);
paul718e3742002-12-13 20:15:29 +00001794 return CMD_SUCCESS;
1795 }
paul718e3742002-12-13 20:15:29 +00001796
Balaji.G837d16c2012-09-26 14:09:10 +05301797 for (i = 0; i < array_size(vtysh_client); i++)
David Lamparter6769f432015-03-04 07:18:24 +01001798 vtysh_client_config (&vtysh_client[i], line);
paul718e3742002-12-13 20:15:29 +00001799
1800 vtysh_config_dump (fp);
1801
1802 fclose (fp);
1803
gdtaa593d52003-12-22 20:15:53 +00001804 if (chmod (integrate_default, CONFIGFILE_MASK) != 0)
1805 {
1806 fprintf (stdout,"%% Can't chmod configuration file %s: %s (%d)\n",
ajs6099b3b2004-11-20 02:06:59 +00001807 integrate_default, safe_strerror(errno), errno);
gdtaa593d52003-12-22 20:15:53 +00001808 return CMD_WARNING;
1809 }
1810
paul4fc01e62002-12-13 20:49:00 +00001811 fprintf(stdout,"Integrated configuration saved to %s\n",integrate_default);
1812
1813 fprintf (stdout,"[OK]\n");
1814
paul718e3742002-12-13 20:15:29 +00001815 return CMD_SUCCESS;
1816}
1817
paul4fc01e62002-12-13 20:49:00 +00001818DEFUN (vtysh_write_memory,
1819 vtysh_write_memory_cmd,
1820 "write memory",
1821 "Write running configuration to memory, network, or terminal\n"
1822 "Write configuration to the file (same as write file)\n")
1823{
pauldfc0d9b2003-04-18 23:55:29 +00001824 int ret = CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001825 char line[] = "write memory\n";
ajsb1aa1472005-01-28 21:11:46 +00001826 u_int i;
paul4fc01e62002-12-13 20:49:00 +00001827
hassoe7168df2004-10-03 20:11:32 +00001828 /* If integrated Quagga.conf explicitely set. */
1829 if (vtysh_writeconfig_integrated)
1830 return write_config_integrated();
paul4fc01e62002-12-13 20:49:00 +00001831
1832 fprintf (stdout,"Building Configuration...\n");
1833
Balaji.G837d16c2012-09-26 14:09:10 +05301834 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00001835 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
hassoe7168df2004-10-03 20:11:32 +00001836
paul4fc01e62002-12-13 20:49:00 +00001837 fprintf (stdout,"[OK]\n");
1838
pauldfc0d9b2003-04-18 23:55:29 +00001839 return ret;
paul4fc01e62002-12-13 20:49:00 +00001840}
1841
paul718e3742002-12-13 20:15:29 +00001842ALIAS (vtysh_write_memory,
1843 vtysh_copy_runningconfig_startupconfig_cmd,
1844 "copy running-config startup-config",
1845 "Copy from one file to another\n"
1846 "Copy from current system configuration\n"
1847 "Copy to startup configuration\n")
1848
1849ALIAS (vtysh_write_memory,
1850 vtysh_write_file_cmd,
1851 "write file",
1852 "Write running configuration to memory, network, or terminal\n"
1853 "Write configuration to the file (same as write memory)\n")
1854
hasso4a6e2252003-05-25 11:51:29 +00001855ALIAS (vtysh_write_memory,
1856 vtysh_write_cmd,
1857 "write",
1858 "Write running configuration to memory, network, or terminal\n")
1859
paul718e3742002-12-13 20:15:29 +00001860ALIAS (vtysh_write_terminal,
1861 vtysh_show_running_config_cmd,
1862 "show running-config",
1863 SHOW_STR
1864 "Current operating configuration\n")
hassob094d262004-08-25 12:22:00 +00001865
hasso34553cc2004-08-27 13:56:39 +00001866DEFUN (vtysh_terminal_length,
1867 vtysh_terminal_length_cmd,
1868 "terminal length <0-512>",
1869 "Set terminal line parameters\n"
1870 "Set number of lines on a screen\n"
1871 "Number of lines on screen (0 for no pausing)\n")
1872{
1873 int lines;
1874 char *endptr = NULL;
1875 char default_pager[10];
1876
1877 lines = strtol (argv[0], &endptr, 10);
1878 if (lines < 0 || lines > 512 || *endptr != '\0')
1879 {
1880 vty_out (vty, "length is malformed%s", VTY_NEWLINE);
1881 return CMD_WARNING;
1882 }
1883
1884 if (vtysh_pager_name)
1885 {
1886 free (vtysh_pager_name);
1887 vtysh_pager_name = NULL;
1888 }
1889
1890 if (lines != 0)
1891 {
1892 snprintf(default_pager, 10, "more -%i", lines);
1893 vtysh_pager_name = strdup (default_pager);
1894 }
1895
1896 return CMD_SUCCESS;
1897}
1898
1899DEFUN (vtysh_terminal_no_length,
1900 vtysh_terminal_no_length_cmd,
1901 "terminal no length",
1902 "Set terminal line parameters\n"
1903 NO_STR
1904 "Set number of lines on a screen\n")
1905{
1906 if (vtysh_pager_name)
1907 {
1908 free (vtysh_pager_name);
1909 vtysh_pager_name = NULL;
1910 }
1911
1912 vtysh_pager_init();
1913 return CMD_SUCCESS;
1914}
1915
hassof2799e62004-10-28 17:43:11 +00001916DEFUN (vtysh_show_daemons,
1917 vtysh_show_daemons_cmd,
1918 "show daemons",
hassoe7168df2004-10-03 20:11:32 +00001919 SHOW_STR
1920 "Show list of running daemons\n")
1921{
ajsb1aa1472005-01-28 21:11:46 +00001922 u_int i;
1923
Balaji.G837d16c2012-09-26 14:09:10 +05301924 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00001925 if ( vtysh_client[i].fd >= 0 )
1926 vty_out(vty, " %s", vtysh_client[i].name);
hassoe7168df2004-10-03 20:11:32 +00001927 vty_out(vty, "%s", VTY_NEWLINE);
1928
1929 return CMD_SUCCESS;
1930}
1931
paul718e3742002-12-13 20:15:29 +00001932/* Execute command in child process. */
ajs274a4a42004-12-07 15:39:31 +00001933static int
hasso5862ff52004-10-11 13:20:40 +00001934execute_command (const char *command, int argc, const char *arg1,
1935 const char *arg2)
paul718e3742002-12-13 20:15:29 +00001936{
paul718e3742002-12-13 20:15:29 +00001937 pid_t pid;
1938 int status;
1939
1940 /* Call fork(). */
1941 pid = fork ();
1942
1943 if (pid < 0)
1944 {
1945 /* Failure of fork(). */
ajs6099b3b2004-11-20 02:06:59 +00001946 fprintf (stderr, "Can't fork: %s\n", safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +00001947 exit (1);
1948 }
1949 else if (pid == 0)
1950 {
1951 /* This is child process. */
1952 switch (argc)
1953 {
1954 case 0:
David Lamparter6769f432015-03-04 07:18:24 +01001955 execlp (command, command, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00001956 break;
1957 case 1:
David Lamparter6769f432015-03-04 07:18:24 +01001958 execlp (command, command, arg1, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00001959 break;
1960 case 2:
David Lamparter6769f432015-03-04 07:18:24 +01001961 execlp (command, command, arg1, arg2, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00001962 break;
1963 }
1964
1965 /* When execlp suceed, this part is not executed. */
ajs6099b3b2004-11-20 02:06:59 +00001966 fprintf (stderr, "Can't execute %s: %s\n", command, safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +00001967 exit (1);
1968 }
1969 else
1970 {
1971 /* This is parent. */
1972 execute_flag = 1;
David Lamparter6769f432015-03-04 07:18:24 +01001973 wait4 (pid, &status, 0, NULL);
paul718e3742002-12-13 20:15:29 +00001974 execute_flag = 0;
1975 }
1976 return 0;
1977}
1978
1979DEFUN (vtysh_ping,
1980 vtysh_ping_cmd,
1981 "ping WORD",
hasso4eeccf12003-06-25 10:49:55 +00001982 "Send echo messages\n"
paul718e3742002-12-13 20:15:29 +00001983 "Ping destination address or hostname\n")
1984{
1985 execute_command ("ping", 1, argv[0], NULL);
1986 return CMD_SUCCESS;
1987}
1988
hasso4eeccf12003-06-25 10:49:55 +00001989ALIAS (vtysh_ping,
1990 vtysh_ping_ip_cmd,
1991 "ping ip WORD",
1992 "Send echo messages\n"
1993 "IP echo\n"
1994 "Ping destination address or hostname\n")
1995
paul718e3742002-12-13 20:15:29 +00001996DEFUN (vtysh_traceroute,
1997 vtysh_traceroute_cmd,
1998 "traceroute WORD",
1999 "Trace route to destination\n"
2000 "Trace route to destination address or hostname\n")
2001{
2002 execute_command ("traceroute", 1, argv[0], NULL);
2003 return CMD_SUCCESS;
2004}
2005
hasso4eeccf12003-06-25 10:49:55 +00002006ALIAS (vtysh_traceroute,
2007 vtysh_traceroute_ip_cmd,
2008 "traceroute ip WORD",
2009 "Trace route to destination\n"
2010 "IP trace\n"
2011 "Trace route to destination address or hostname\n")
2012
2013#ifdef HAVE_IPV6
2014DEFUN (vtysh_ping6,
2015 vtysh_ping6_cmd,
2016 "ping ipv6 WORD",
2017 "Send echo messages\n"
2018 "IPv6 echo\n"
2019 "Ping destination address or hostname\n")
2020{
2021 execute_command ("ping6", 1, argv[0], NULL);
2022 return CMD_SUCCESS;
2023}
2024
2025DEFUN (vtysh_traceroute6,
2026 vtysh_traceroute6_cmd,
2027 "traceroute ipv6 WORD",
2028 "Trace route to destination\n"
2029 "IPv6 trace\n"
2030 "Trace route to destination address or hostname\n")
2031{
2032 execute_command ("traceroute6", 1, argv[0], NULL);
2033 return CMD_SUCCESS;
2034}
2035#endif
2036
paul718e3742002-12-13 20:15:29 +00002037DEFUN (vtysh_telnet,
2038 vtysh_telnet_cmd,
2039 "telnet WORD",
2040 "Open a telnet connection\n"
2041 "IP address or hostname of a remote system\n")
2042{
2043 execute_command ("telnet", 1, argv[0], NULL);
2044 return CMD_SUCCESS;
2045}
2046
2047DEFUN (vtysh_telnet_port,
2048 vtysh_telnet_port_cmd,
2049 "telnet WORD PORT",
2050 "Open a telnet connection\n"
2051 "IP address or hostname of a remote system\n"
2052 "TCP Port number\n")
2053{
2054 execute_command ("telnet", 2, argv[0], argv[1]);
2055 return CMD_SUCCESS;
2056}
2057
paul5087df52003-01-25 06:56:09 +00002058DEFUN (vtysh_ssh,
2059 vtysh_ssh_cmd,
2060 "ssh WORD",
2061 "Open an ssh connection\n"
2062 "[user@]host\n")
2063{
2064 execute_command ("ssh", 1, argv[0], NULL);
2065 return CMD_SUCCESS;
2066}
2067
paul718e3742002-12-13 20:15:29 +00002068DEFUN (vtysh_start_shell,
2069 vtysh_start_shell_cmd,
2070 "start-shell",
2071 "Start UNIX shell\n")
2072{
2073 execute_command ("sh", 0, NULL, NULL);
2074 return CMD_SUCCESS;
2075}
2076
2077DEFUN (vtysh_start_bash,
2078 vtysh_start_bash_cmd,
2079 "start-shell bash",
2080 "Start UNIX shell\n"
2081 "Start bash\n")
2082{
2083 execute_command ("bash", 0, NULL, NULL);
2084 return CMD_SUCCESS;
2085}
2086
2087DEFUN (vtysh_start_zsh,
2088 vtysh_start_zsh_cmd,
2089 "start-shell zsh",
2090 "Start UNIX shell\n"
2091 "Start Z shell\n")
2092{
2093 execute_command ("zsh", 0, NULL, NULL);
2094 return CMD_SUCCESS;
2095}
hassob094d262004-08-25 12:22:00 +00002096
ajs274a4a42004-12-07 15:39:31 +00002097static void
paul718e3742002-12-13 20:15:29 +00002098vtysh_install_default (enum node_type node)
2099{
2100 install_element (node, &config_list_cmd);
2101}
2102
2103/* Making connection to protocol daemon. */
ajs274a4a42004-12-07 15:39:31 +00002104static int
ajsb1aa1472005-01-28 21:11:46 +00002105vtysh_connect (struct vtysh_client *vclient)
paul718e3742002-12-13 20:15:29 +00002106{
2107 int ret;
2108 int sock, len;
2109 struct sockaddr_un addr;
2110 struct stat s_stat;
paul718e3742002-12-13 20:15:29 +00002111
paul718e3742002-12-13 20:15:29 +00002112 /* Stat socket to see if we have permission to access it. */
ajsb1aa1472005-01-28 21:11:46 +00002113 ret = stat (vclient->path, &s_stat);
paul718e3742002-12-13 20:15:29 +00002114 if (ret < 0 && errno != ENOENT)
2115 {
2116 fprintf (stderr, "vtysh_connect(%s): stat = %s\n",
ajsb1aa1472005-01-28 21:11:46 +00002117 vclient->path, safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002118 exit(1);
2119 }
2120
2121 if (ret >= 0)
2122 {
2123 if (! S_ISSOCK(s_stat.st_mode))
2124 {
2125 fprintf (stderr, "vtysh_connect(%s): Not a socket\n",
ajsb1aa1472005-01-28 21:11:46 +00002126 vclient->path);
paul718e3742002-12-13 20:15:29 +00002127 exit (1);
2128 }
2129
paul718e3742002-12-13 20:15:29 +00002130 }
2131
2132 sock = socket (AF_UNIX, SOCK_STREAM, 0);
2133 if (sock < 0)
2134 {
2135#ifdef DEBUG
ajsb1aa1472005-01-28 21:11:46 +00002136 fprintf(stderr, "vtysh_connect(%s): socket = %s\n", vclient->path,
ajs6099b3b2004-11-20 02:06:59 +00002137 safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002138#endif /* DEBUG */
2139 return -1;
2140 }
2141
2142 memset (&addr, 0, sizeof (struct sockaddr_un));
2143 addr.sun_family = AF_UNIX;
ajsb1aa1472005-01-28 21:11:46 +00002144 strncpy (addr.sun_path, vclient->path, strlen (vclient->path));
Paul Jakma6f0e3f62007-05-10 02:38:51 +00002145#ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
paul718e3742002-12-13 20:15:29 +00002146 len = addr.sun_len = SUN_LEN(&addr);
2147#else
2148 len = sizeof (addr.sun_family) + strlen (addr.sun_path);
Paul Jakma6f0e3f62007-05-10 02:38:51 +00002149#endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
paul718e3742002-12-13 20:15:29 +00002150
2151 ret = connect (sock, (struct sockaddr *) &addr, len);
2152 if (ret < 0)
2153 {
2154#ifdef DEBUG
ajsb1aa1472005-01-28 21:11:46 +00002155 fprintf(stderr, "vtysh_connect(%s): connect = %s\n", vclient->path,
ajs6099b3b2004-11-20 02:06:59 +00002156 safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002157#endif /* DEBUG */
2158 close (sock);
2159 return -1;
2160 }
2161 vclient->fd = sock;
2162
2163 return 0;
2164}
2165
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002166int
2167vtysh_connect_all(const char *daemon_name)
paul718e3742002-12-13 20:15:29 +00002168{
ajsb1aa1472005-01-28 21:11:46 +00002169 u_int i;
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002170 int rc = 0;
2171 int matches = 0;
ajsb1aa1472005-01-28 21:11:46 +00002172
Balaji.G837d16c2012-09-26 14:09:10 +05302173 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00002174 {
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002175 if (!daemon_name || !strcmp(daemon_name, vtysh_client[i].name))
2176 {
2177 matches++;
2178 if (vtysh_connect(&vtysh_client[i]) == 0)
2179 rc++;
2180 /* We need direct access to ripd in vtysh_exit_ripd_only. */
2181 if (vtysh_client[i].flag == VTYSH_RIPD)
2182 ripd_client = &vtysh_client[i];
2183 }
ajsb1aa1472005-01-28 21:11:46 +00002184 }
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002185 if (!matches)
2186 fprintf(stderr, "Error: no daemons match name %s!\n", daemon_name);
2187 return rc;
paul718e3742002-12-13 20:15:29 +00002188}
2189
hasso95e735b2004-08-26 13:08:30 +00002190/* To disable readline's filename completion. */
ajs274a4a42004-12-07 15:39:31 +00002191static char *
pauldfc0d9b2003-04-18 23:55:29 +00002192vtysh_completion_entry_function (const char *ignore, int invoking_key)
paul718e3742002-12-13 20:15:29 +00002193{
pauldfc0d9b2003-04-18 23:55:29 +00002194 return NULL;
paul718e3742002-12-13 20:15:29 +00002195}
2196
2197void
ajsb1aa1472005-01-28 21:11:46 +00002198vtysh_readline_init (void)
paul718e3742002-12-13 20:15:29 +00002199{
2200 /* readline related settings. */
Sébastien Luttringer66d2ead2014-05-27 19:55:11 +02002201 rl_bind_key ('?', (rl_command_func_t *) vtysh_rl_describe);
paul68980082003-03-25 05:07:42 +00002202 rl_completion_entry_function = vtysh_completion_entry_function;
Sébastien Luttringer66d2ead2014-05-27 19:55:11 +02002203 rl_attempted_completion_function = (rl_completion_func_t *)new_completion;
paul718e3742002-12-13 20:15:29 +00002204}
2205
2206char *
ajsb1aa1472005-01-28 21:11:46 +00002207vtysh_prompt (void)
paul718e3742002-12-13 20:15:29 +00002208{
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002209 static struct utsname names;
paul718e3742002-12-13 20:15:29 +00002210 static char buf[100];
2211 const char*hostname;
2212 extern struct host host;
2213
2214 hostname = host.name;
2215
2216 if (!hostname)
2217 {
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002218 if (!names.nodename[0])
2219 uname (&names);
paul718e3742002-12-13 20:15:29 +00002220 hostname = names.nodename;
2221 }
2222
2223 snprintf (buf, sizeof buf, cmd_prompt (vty->node), hostname);
2224
2225 return buf;
2226}
2227
2228void
ajsb1aa1472005-01-28 21:11:46 +00002229vtysh_init_vty (void)
paul718e3742002-12-13 20:15:29 +00002230{
2231 /* Make vty structure. */
2232 vty = vty_new ();
2233 vty->type = VTY_SHELL;
2234 vty->node = VIEW_NODE;
2235
2236 /* Initialize commands. */
2237 cmd_init (0);
2238
2239 /* Install nodes. */
2240 install_node (&bgp_node, NULL);
2241 install_node (&rip_node, NULL);
2242 install_node (&interface_node, NULL);
2243 install_node (&rmap_node, NULL);
2244 install_node (&zebra_node, NULL);
2245 install_node (&bgp_vpnv4_node, NULL);
2246 install_node (&bgp_ipv4_node, NULL);
2247 install_node (&bgp_ipv4m_node, NULL);
2248/* #ifdef HAVE_IPV6 */
2249 install_node (&bgp_ipv6_node, NULL);
paul57b5b7e2005-08-22 22:44:29 +00002250 install_node (&bgp_ipv6m_node, NULL);
paul718e3742002-12-13 20:15:29 +00002251/* #endif */
2252 install_node (&ospf_node, NULL);
2253/* #ifdef HAVE_IPV6 */
2254 install_node (&ripng_node, NULL);
2255 install_node (&ospf6_node, NULL);
2256/* #endif */
David Lamparteree53c8b2015-05-23 05:45:59 +02002257 install_node (&babel_node, NULL);
paul718e3742002-12-13 20:15:29 +00002258 install_node (&keychain_node, NULL);
2259 install_node (&keychain_key_node, NULL);
hassoc25e4582003-12-23 10:39:08 +00002260 install_node (&isis_node, NULL);
hassoe7168df2004-10-03 20:11:32 +00002261 install_node (&vty_node, NULL);
paul718e3742002-12-13 20:15:29 +00002262
2263 vtysh_install_default (VIEW_NODE);
2264 vtysh_install_default (ENABLE_NODE);
2265 vtysh_install_default (CONFIG_NODE);
2266 vtysh_install_default (BGP_NODE);
2267 vtysh_install_default (RIP_NODE);
2268 vtysh_install_default (INTERFACE_NODE);
2269 vtysh_install_default (RMAP_NODE);
2270 vtysh_install_default (ZEBRA_NODE);
2271 vtysh_install_default (BGP_VPNV4_NODE);
2272 vtysh_install_default (BGP_IPV4_NODE);
2273 vtysh_install_default (BGP_IPV4M_NODE);
2274 vtysh_install_default (BGP_IPV6_NODE);
paul57b5b7e2005-08-22 22:44:29 +00002275 vtysh_install_default (BGP_IPV6M_NODE);
paul718e3742002-12-13 20:15:29 +00002276 vtysh_install_default (OSPF_NODE);
2277 vtysh_install_default (RIPNG_NODE);
2278 vtysh_install_default (OSPF6_NODE);
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +01002279 vtysh_install_default (BABEL_NODE);
hassoc25e4582003-12-23 10:39:08 +00002280 vtysh_install_default (ISIS_NODE);
paul718e3742002-12-13 20:15:29 +00002281 vtysh_install_default (KEYCHAIN_NODE);
2282 vtysh_install_default (KEYCHAIN_KEY_NODE);
hassoe7168df2004-10-03 20:11:32 +00002283 vtysh_install_default (VTY_NODE);
paul718e3742002-12-13 20:15:29 +00002284
2285 install_element (VIEW_NODE, &vtysh_enable_cmd);
2286 install_element (ENABLE_NODE, &vtysh_config_terminal_cmd);
2287 install_element (ENABLE_NODE, &vtysh_disable_cmd);
2288
2289 /* "exit" command. */
2290 install_element (VIEW_NODE, &vtysh_exit_all_cmd);
2291 install_element (VIEW_NODE, &vtysh_quit_all_cmd);
2292 install_element (CONFIG_NODE, &vtysh_exit_all_cmd);
2293 /* install_element (CONFIG_NODE, &vtysh_quit_all_cmd); */
2294 install_element (ENABLE_NODE, &vtysh_exit_all_cmd);
2295 install_element (ENABLE_NODE, &vtysh_quit_all_cmd);
2296 install_element (RIP_NODE, &vtysh_exit_ripd_cmd);
2297 install_element (RIP_NODE, &vtysh_quit_ripd_cmd);
paul68980082003-03-25 05:07:42 +00002298 install_element (RIPNG_NODE, &vtysh_exit_ripngd_cmd);
2299 install_element (RIPNG_NODE, &vtysh_quit_ripngd_cmd);
paul718e3742002-12-13 20:15:29 +00002300 install_element (OSPF_NODE, &vtysh_exit_ospfd_cmd);
2301 install_element (OSPF_NODE, &vtysh_quit_ospfd_cmd);
paul68980082003-03-25 05:07:42 +00002302 install_element (OSPF6_NODE, &vtysh_exit_ospf6d_cmd);
2303 install_element (OSPF6_NODE, &vtysh_quit_ospf6d_cmd);
paul718e3742002-12-13 20:15:29 +00002304 install_element (BGP_NODE, &vtysh_exit_bgpd_cmd);
2305 install_element (BGP_NODE, &vtysh_quit_bgpd_cmd);
2306 install_element (BGP_VPNV4_NODE, &vtysh_exit_bgpd_cmd);
2307 install_element (BGP_VPNV4_NODE, &vtysh_quit_bgpd_cmd);
2308 install_element (BGP_IPV4_NODE, &vtysh_exit_bgpd_cmd);
2309 install_element (BGP_IPV4_NODE, &vtysh_quit_bgpd_cmd);
2310 install_element (BGP_IPV4M_NODE, &vtysh_exit_bgpd_cmd);
2311 install_element (BGP_IPV4M_NODE, &vtysh_quit_bgpd_cmd);
2312 install_element (BGP_IPV6_NODE, &vtysh_exit_bgpd_cmd);
2313 install_element (BGP_IPV6_NODE, &vtysh_quit_bgpd_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002314 install_element (BGP_IPV6M_NODE, &vtysh_exit_bgpd_cmd);
2315 install_element (BGP_IPV6M_NODE, &vtysh_quit_bgpd_cmd);
hassoc25e4582003-12-23 10:39:08 +00002316 install_element (ISIS_NODE, &vtysh_exit_isisd_cmd);
2317 install_element (ISIS_NODE, &vtysh_quit_isisd_cmd);
paul718e3742002-12-13 20:15:29 +00002318 install_element (KEYCHAIN_NODE, &vtysh_exit_ripd_cmd);
2319 install_element (KEYCHAIN_NODE, &vtysh_quit_ripd_cmd);
2320 install_element (KEYCHAIN_KEY_NODE, &vtysh_exit_ripd_cmd);
2321 install_element (KEYCHAIN_KEY_NODE, &vtysh_quit_ripd_cmd);
2322 install_element (RMAP_NODE, &vtysh_exit_rmap_cmd);
2323 install_element (RMAP_NODE, &vtysh_quit_rmap_cmd);
hassoe7168df2004-10-03 20:11:32 +00002324 install_element (VTY_NODE, &vtysh_exit_line_vty_cmd);
2325 install_element (VTY_NODE, &vtysh_quit_line_vty_cmd);
paul718e3742002-12-13 20:15:29 +00002326
2327 /* "end" command. */
2328 install_element (CONFIG_NODE, &vtysh_end_all_cmd);
2329 install_element (ENABLE_NODE, &vtysh_end_all_cmd);
2330 install_element (RIP_NODE, &vtysh_end_all_cmd);
2331 install_element (RIPNG_NODE, &vtysh_end_all_cmd);
2332 install_element (OSPF_NODE, &vtysh_end_all_cmd);
2333 install_element (OSPF6_NODE, &vtysh_end_all_cmd);
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +01002334 install_element (BABEL_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002335 install_element (BGP_NODE, &vtysh_end_all_cmd);
2336 install_element (BGP_IPV4_NODE, &vtysh_end_all_cmd);
2337 install_element (BGP_IPV4M_NODE, &vtysh_end_all_cmd);
2338 install_element (BGP_VPNV4_NODE, &vtysh_end_all_cmd);
2339 install_element (BGP_IPV6_NODE, &vtysh_end_all_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002340 install_element (BGP_IPV6M_NODE, &vtysh_end_all_cmd);
hassoc25e4582003-12-23 10:39:08 +00002341 install_element (ISIS_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002342 install_element (KEYCHAIN_NODE, &vtysh_end_all_cmd);
2343 install_element (KEYCHAIN_KEY_NODE, &vtysh_end_all_cmd);
2344 install_element (RMAP_NODE, &vtysh_end_all_cmd);
hassoe7168df2004-10-03 20:11:32 +00002345 install_element (VTY_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002346
paul338a9912003-03-01 15:44:10 +00002347 install_element (INTERFACE_NODE, &interface_desc_cmd);
paul464dc8d2003-03-28 02:25:45 +00002348 install_element (INTERFACE_NODE, &no_interface_desc_cmd);
paul718e3742002-12-13 20:15:29 +00002349 install_element (INTERFACE_NODE, &vtysh_end_all_cmd);
2350 install_element (INTERFACE_NODE, &vtysh_exit_interface_cmd);
2351 install_element (INTERFACE_NODE, &vtysh_quit_interface_cmd);
2352 install_element (CONFIG_NODE, &router_rip_cmd);
2353#ifdef HAVE_IPV6
2354 install_element (CONFIG_NODE, &router_ripng_cmd);
2355#endif
2356 install_element (CONFIG_NODE, &router_ospf_cmd);
2357#ifdef HAVE_IPV6
2358 install_element (CONFIG_NODE, &router_ospf6_cmd);
2359#endif
hassoc25e4582003-12-23 10:39:08 +00002360 install_element (CONFIG_NODE, &router_isis_cmd);
paul718e3742002-12-13 20:15:29 +00002361 install_element (CONFIG_NODE, &router_bgp_cmd);
Paul Jakma10895fd2008-07-03 19:34:48 +00002362 install_element (CONFIG_NODE, &router_bgp_view_cmd);
paul718e3742002-12-13 20:15:29 +00002363 install_element (BGP_NODE, &address_family_vpnv4_cmd);
2364 install_element (BGP_NODE, &address_family_vpnv4_unicast_cmd);
2365 install_element (BGP_NODE, &address_family_ipv4_unicast_cmd);
2366 install_element (BGP_NODE, &address_family_ipv4_multicast_cmd);
2367#ifdef HAVE_IPV6
2368 install_element (BGP_NODE, &address_family_ipv6_cmd);
2369 install_element (BGP_NODE, &address_family_ipv6_unicast_cmd);
2370#endif
2371 install_element (BGP_VPNV4_NODE, &exit_address_family_cmd);
2372 install_element (BGP_IPV4_NODE, &exit_address_family_cmd);
2373 install_element (BGP_IPV4M_NODE, &exit_address_family_cmd);
2374 install_element (BGP_IPV6_NODE, &exit_address_family_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002375 install_element (BGP_IPV6M_NODE, &exit_address_family_cmd);
paul718e3742002-12-13 20:15:29 +00002376 install_element (CONFIG_NODE, &key_chain_cmd);
2377 install_element (CONFIG_NODE, &route_map_cmd);
hassoe7168df2004-10-03 20:11:32 +00002378 install_element (CONFIG_NODE, &vtysh_line_vty_cmd);
paul718e3742002-12-13 20:15:29 +00002379 install_element (KEYCHAIN_NODE, &key_cmd);
2380 install_element (KEYCHAIN_NODE, &key_chain_cmd);
2381 install_element (KEYCHAIN_KEY_NODE, &key_chain_cmd);
2382 install_element (CONFIG_NODE, &vtysh_interface_cmd);
paul32d24632003-05-23 09:25:20 +00002383 install_element (CONFIG_NODE, &vtysh_no_interface_cmd);
paul718e3742002-12-13 20:15:29 +00002384 install_element (ENABLE_NODE, &vtysh_show_running_config_cmd);
2385 install_element (ENABLE_NODE, &vtysh_copy_runningconfig_startupconfig_cmd);
2386 install_element (ENABLE_NODE, &vtysh_write_file_cmd);
hasso4a6e2252003-05-25 11:51:29 +00002387 install_element (ENABLE_NODE, &vtysh_write_cmd);
paul718e3742002-12-13 20:15:29 +00002388
hasso95e735b2004-08-26 13:08:30 +00002389 /* "write terminal" command. */
paul718e3742002-12-13 20:15:29 +00002390 install_element (ENABLE_NODE, &vtysh_write_terminal_cmd);
hassoe7168df2004-10-03 20:11:32 +00002391
2392 install_element (CONFIG_NODE, &vtysh_integrated_config_cmd);
2393 install_element (CONFIG_NODE, &no_vtysh_integrated_config_cmd);
paul718e3742002-12-13 20:15:29 +00002394
hasso95e735b2004-08-26 13:08:30 +00002395 /* "write memory" command. */
paul718e3742002-12-13 20:15:29 +00002396 install_element (ENABLE_NODE, &vtysh_write_memory_cmd);
paul718e3742002-12-13 20:15:29 +00002397
hasso34553cc2004-08-27 13:56:39 +00002398 install_element (VIEW_NODE, &vtysh_terminal_length_cmd);
2399 install_element (ENABLE_NODE, &vtysh_terminal_length_cmd);
2400 install_element (VIEW_NODE, &vtysh_terminal_no_length_cmd);
2401 install_element (ENABLE_NODE, &vtysh_terminal_no_length_cmd);
hassof2799e62004-10-28 17:43:11 +00002402 install_element (VIEW_NODE, &vtysh_show_daemons_cmd);
2403 install_element (ENABLE_NODE, &vtysh_show_daemons_cmd);
hasso34553cc2004-08-27 13:56:39 +00002404
paul718e3742002-12-13 20:15:29 +00002405 install_element (VIEW_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002406 install_element (VIEW_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00002407 install_element (VIEW_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002408 install_element (VIEW_NODE, &vtysh_traceroute_ip_cmd);
2409#ifdef HAVE_IPV6
2410 install_element (VIEW_NODE, &vtysh_ping6_cmd);
2411 install_element (VIEW_NODE, &vtysh_traceroute6_cmd);
2412#endif
paul718e3742002-12-13 20:15:29 +00002413 install_element (VIEW_NODE, &vtysh_telnet_cmd);
2414 install_element (VIEW_NODE, &vtysh_telnet_port_cmd);
paul5087df52003-01-25 06:56:09 +00002415 install_element (VIEW_NODE, &vtysh_ssh_cmd);
paul718e3742002-12-13 20:15:29 +00002416 install_element (ENABLE_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002417 install_element (ENABLE_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00002418 install_element (ENABLE_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002419 install_element (ENABLE_NODE, &vtysh_traceroute_ip_cmd);
2420#ifdef HAVE_IPV6
2421 install_element (ENABLE_NODE, &vtysh_ping6_cmd);
2422 install_element (ENABLE_NODE, &vtysh_traceroute6_cmd);
2423#endif
paul718e3742002-12-13 20:15:29 +00002424 install_element (ENABLE_NODE, &vtysh_telnet_cmd);
2425 install_element (ENABLE_NODE, &vtysh_telnet_port_cmd);
hasso67e29ab2004-08-26 22:21:31 +00002426 install_element (ENABLE_NODE, &vtysh_ssh_cmd);
paul718e3742002-12-13 20:15:29 +00002427 install_element (ENABLE_NODE, &vtysh_start_shell_cmd);
2428 install_element (ENABLE_NODE, &vtysh_start_bash_cmd);
2429 install_element (ENABLE_NODE, &vtysh_start_zsh_cmd);
Paul Jakmadbf7d132006-05-23 22:10:01 +00002430
Paul Jakma362b4032006-05-28 07:54:45 +00002431 install_element (VIEW_NODE, &vtysh_show_memory_cmd);
2432 install_element (ENABLE_NODE, &vtysh_show_memory_cmd);
2433
Paul Jakmadbf7d132006-05-23 22:10:01 +00002434 /* Logging */
2435 install_element (ENABLE_NODE, &vtysh_show_logging_cmd);
2436 install_element (VIEW_NODE, &vtysh_show_logging_cmd);
paul718e3742002-12-13 20:15:29 +00002437 install_element (CONFIG_NODE, &vtysh_log_stdout_cmd);
ajs274a4a42004-12-07 15:39:31 +00002438 install_element (CONFIG_NODE, &vtysh_log_stdout_level_cmd);
paul718e3742002-12-13 20:15:29 +00002439 install_element (CONFIG_NODE, &no_vtysh_log_stdout_cmd);
2440 install_element (CONFIG_NODE, &vtysh_log_file_cmd);
ajs274a4a42004-12-07 15:39:31 +00002441 install_element (CONFIG_NODE, &vtysh_log_file_level_cmd);
paul718e3742002-12-13 20:15:29 +00002442 install_element (CONFIG_NODE, &no_vtysh_log_file_cmd);
ajs274a4a42004-12-07 15:39:31 +00002443 install_element (CONFIG_NODE, &no_vtysh_log_file_level_cmd);
2444 install_element (CONFIG_NODE, &vtysh_log_monitor_cmd);
2445 install_element (CONFIG_NODE, &vtysh_log_monitor_level_cmd);
2446 install_element (CONFIG_NODE, &no_vtysh_log_monitor_cmd);
paul718e3742002-12-13 20:15:29 +00002447 install_element (CONFIG_NODE, &vtysh_log_syslog_cmd);
ajs274a4a42004-12-07 15:39:31 +00002448 install_element (CONFIG_NODE, &vtysh_log_syslog_level_cmd);
paul718e3742002-12-13 20:15:29 +00002449 install_element (CONFIG_NODE, &no_vtysh_log_syslog_cmd);
2450 install_element (CONFIG_NODE, &vtysh_log_trap_cmd);
2451 install_element (CONFIG_NODE, &no_vtysh_log_trap_cmd);
ajs274a4a42004-12-07 15:39:31 +00002452 install_element (CONFIG_NODE, &vtysh_log_facility_cmd);
2453 install_element (CONFIG_NODE, &no_vtysh_log_facility_cmd);
paul718e3742002-12-13 20:15:29 +00002454 install_element (CONFIG_NODE, &vtysh_log_record_priority_cmd);
2455 install_element (CONFIG_NODE, &no_vtysh_log_record_priority_cmd);
Andrew J. Schorrc749b722007-04-29 03:53:31 +00002456 install_element (CONFIG_NODE, &vtysh_log_timestamp_precision_cmd);
2457 install_element (CONFIG_NODE, &no_vtysh_log_timestamp_precision_cmd);
hassoe7168df2004-10-03 20:11:32 +00002458
2459 install_element (CONFIG_NODE, &vtysh_service_password_encrypt_cmd);
2460 install_element (CONFIG_NODE, &no_vtysh_service_password_encrypt_cmd);
2461
2462 install_element (CONFIG_NODE, &vtysh_password_cmd);
2463 install_element (CONFIG_NODE, &vtysh_password_text_cmd);
2464 install_element (CONFIG_NODE, &vtysh_enable_password_cmd);
2465 install_element (CONFIG_NODE, &vtysh_enable_password_text_cmd);
2466 install_element (CONFIG_NODE, &no_vtysh_enable_password_cmd);
2467
paul718e3742002-12-13 20:15:29 +00002468}