blob: e2d63f9f05b4d98219c7a1a95545457108afb0f7 [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
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800801static struct cmd_node keychain_node =
hasso95e735b2004-08-26 13:08:30 +0000802{
803 KEYCHAIN_NODE,
804 "%s(config-keychain)# "
805};
806
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800807static struct cmd_node keychain_key_node =
hasso95e735b2004-08-26 13:08:30 +0000808{
809 KEYCHAIN_KEY_NODE,
810 "%s(config-keychain-key)# "
811};
812
hassoe7168df2004-10-03 20:11:32 +0000813/* Defined in lib/vty.c */
814extern struct cmd_node vty_node;
815
hasso95e735b2004-08-26 13:08:30 +0000816/* When '^Z' is received from vty, move down to the enable mode. */
David Lampartera9eb9062015-03-04 07:07:01 +0100817static int
ajsb1aa1472005-01-28 21:11:46 +0000818vtysh_end (void)
hasso95e735b2004-08-26 13:08:30 +0000819{
820 switch (vty->node)
821 {
822 case VIEW_NODE:
823 case ENABLE_NODE:
824 /* Nothing to do. */
825 break;
826 default:
827 vty->node = ENABLE_NODE;
828 break;
829 }
830 return CMD_SUCCESS;
831}
832
833DEFUNSH (VTYSH_ALL,
834 vtysh_end_all,
835 vtysh_end_all_cmd,
836 "end",
hassoe7168df2004-10-03 20:11:32 +0000837 "End current mode and change to enable mode\n")
hasso95e735b2004-08-26 13:08:30 +0000838{
hasso42895462004-09-26 16:25:07 +0000839 return vtysh_end ();
hasso95e735b2004-08-26 13:08:30 +0000840}
841
paul718e3742002-12-13 20:15:29 +0000842DEFUNSH (VTYSH_BGPD,
843 router_bgp,
844 router_bgp_cmd,
Paul Jakma320da872008-07-02 13:40:33 +0000845 "router bgp " CMD_AS_RANGE,
paul718e3742002-12-13 20:15:29 +0000846 ROUTER_STR
847 BGP_STR
848 AS_STR)
849{
850 vty->node = BGP_NODE;
851 return CMD_SUCCESS;
852}
853
Paul Jakma10895fd2008-07-03 19:34:48 +0000854ALIAS_SH (VTYSH_BGPD,
855 router_bgp,
856 router_bgp_view_cmd,
857 "router bgp " CMD_AS_RANGE " view WORD",
858 ROUTER_STR
859 BGP_STR
860 AS_STR
861 "BGP view\n"
862 "view name\n")
863
paul718e3742002-12-13 20:15:29 +0000864DEFUNSH (VTYSH_BGPD,
865 address_family_vpnv4,
866 address_family_vpnv4_cmd,
867 "address-family vpnv4",
868 "Enter Address Family command mode\n"
869 "Address family\n")
870{
871 vty->node = BGP_VPNV4_NODE;
872 return CMD_SUCCESS;
873}
874
875DEFUNSH (VTYSH_BGPD,
876 address_family_vpnv4_unicast,
877 address_family_vpnv4_unicast_cmd,
878 "address-family vpnv4 unicast",
879 "Enter Address Family command mode\n"
880 "Address family\n"
881 "Address Family Modifier\n")
882{
883 vty->node = BGP_VPNV4_NODE;
884 return CMD_SUCCESS;
885}
886
887DEFUNSH (VTYSH_BGPD,
888 address_family_ipv4_unicast,
889 address_family_ipv4_unicast_cmd,
890 "address-family ipv4 unicast",
891 "Enter Address Family command mode\n"
892 "Address family\n"
893 "Address Family Modifier\n")
894{
895 vty->node = BGP_IPV4_NODE;
896 return CMD_SUCCESS;
897}
898
899DEFUNSH (VTYSH_BGPD,
900 address_family_ipv4_multicast,
901 address_family_ipv4_multicast_cmd,
902 "address-family ipv4 multicast",
903 "Enter Address Family command mode\n"
904 "Address family\n"
905 "Address Family Modifier\n")
906{
907 vty->node = BGP_IPV4M_NODE;
908 return CMD_SUCCESS;
909}
910
911DEFUNSH (VTYSH_BGPD,
912 address_family_ipv6,
913 address_family_ipv6_cmd,
914 "address-family ipv6",
915 "Enter Address Family command mode\n"
916 "Address family\n")
917{
918 vty->node = BGP_IPV6_NODE;
919 return CMD_SUCCESS;
920}
921
922DEFUNSH (VTYSH_BGPD,
923 address_family_ipv6_unicast,
924 address_family_ipv6_unicast_cmd,
925 "address-family ipv6 unicast",
926 "Enter Address Family command mode\n"
927 "Address family\n"
928 "Address Family Modifier\n")
929{
930 vty->node = BGP_IPV6_NODE;
931 return CMD_SUCCESS;
932}
933
paul57b5b7e2005-08-22 22:44:29 +0000934DEFUNSH (VTYSH_BGPD,
935 address_family_ipv6_multicast,
936 address_family_ipv6_multicast_cmd,
937 "address-family ipv6 multicast",
938 "Enter Address Family command mode\n"
939 "Address family\n"
940 "Address Family Modifier\n")
941{
942 vty->node = BGP_IPV6M_NODE;
943 return CMD_SUCCESS;
944}
945
paul718e3742002-12-13 20:15:29 +0000946DEFUNSH (VTYSH_RIPD,
947 key_chain,
948 key_chain_cmd,
949 "key chain WORD",
950 "Authentication key management\n"
951 "Key-chain management\n"
952 "Key-chain name\n")
953{
954 vty->node = KEYCHAIN_NODE;
955 return CMD_SUCCESS;
956}
957
958DEFUNSH (VTYSH_RIPD,
959 key,
960 key_cmd,
961 "key <0-2147483647>",
962 "Configure a key\n"
963 "Key identifier number\n")
964{
965 vty->node = KEYCHAIN_KEY_NODE;
966 return CMD_SUCCESS;
967}
968
969DEFUNSH (VTYSH_RIPD,
970 router_rip,
971 router_rip_cmd,
972 "router rip",
973 ROUTER_STR
974 "RIP")
975{
976 vty->node = RIP_NODE;
977 return CMD_SUCCESS;
978}
979
980DEFUNSH (VTYSH_RIPNGD,
981 router_ripng,
982 router_ripng_cmd,
983 "router ripng",
984 ROUTER_STR
985 "RIPng")
986{
987 vty->node = RIPNG_NODE;
988 return CMD_SUCCESS;
989}
990
991DEFUNSH (VTYSH_OSPFD,
992 router_ospf,
993 router_ospf_cmd,
994 "router ospf",
995 "Enable a routing process\n"
996 "Start OSPF configuration\n")
997{
998 vty->node = OSPF_NODE;
999 return CMD_SUCCESS;
1000}
1001
1002DEFUNSH (VTYSH_OSPF6D,
1003 router_ospf6,
1004 router_ospf6_cmd,
1005 "router ospf6",
1006 OSPF6_ROUTER_STR
1007 OSPF6_STR)
1008{
1009 vty->node = OSPF6_NODE;
1010 return CMD_SUCCESS;
1011}
1012
hassoc25e4582003-12-23 10:39:08 +00001013DEFUNSH (VTYSH_ISISD,
hassob094d262004-08-25 12:22:00 +00001014 router_isis,
1015 router_isis_cmd,
1016 "router isis WORD",
1017 ROUTER_STR
1018 "ISO IS-IS\n"
1019 "ISO Routing area tag")
hassoc25e4582003-12-23 10:39:08 +00001020{
1021 vty->node = ISIS_NODE;
1022 return CMD_SUCCESS;
1023}
1024
paul718e3742002-12-13 20:15:29 +00001025DEFUNSH (VTYSH_RMAP,
1026 route_map,
1027 route_map_cmd,
1028 "route-map WORD (deny|permit) <1-65535>",
1029 "Create route-map or enter route-map command mode\n"
1030 "Route map tag\n"
1031 "Route map denies set operations\n"
1032 "Route map permits set operations\n"
1033 "Sequence to insert to/delete from existing route-map entry\n")
1034{
1035 vty->node = RMAP_NODE;
1036 return CMD_SUCCESS;
1037}
1038
paul718e3742002-12-13 20:15:29 +00001039DEFUNSH (VTYSH_ALL,
hassoe7168df2004-10-03 20:11:32 +00001040 vtysh_line_vty,
1041 vtysh_line_vty_cmd,
1042 "line vty",
1043 "Configure a terminal line\n"
1044 "Virtual terminal\n")
1045{
1046 vty->node = VTY_NODE;
1047 return CMD_SUCCESS;
1048}
1049
1050DEFUNSH (VTYSH_ALL,
paul718e3742002-12-13 20:15:29 +00001051 vtysh_enable,
1052 vtysh_enable_cmd,
1053 "enable",
1054 "Turn on privileged mode command\n")
1055{
1056 vty->node = ENABLE_NODE;
1057 return CMD_SUCCESS;
1058}
1059
paul718e3742002-12-13 20:15:29 +00001060DEFUNSH (VTYSH_ALL,
1061 vtysh_disable,
1062 vtysh_disable_cmd,
1063 "disable",
1064 "Turn off privileged mode command\n")
1065{
1066 if (vty->node == ENABLE_NODE)
1067 vty->node = VIEW_NODE;
1068 return CMD_SUCCESS;
1069}
1070
paul718e3742002-12-13 20:15:29 +00001071DEFUNSH (VTYSH_ALL,
1072 vtysh_config_terminal,
1073 vtysh_config_terminal_cmd,
1074 "configure terminal",
1075 "Configuration from vty interface\n"
1076 "Configuration terminal\n")
1077{
1078 vty->node = CONFIG_NODE;
1079 return CMD_SUCCESS;
1080}
1081
ajs274a4a42004-12-07 15:39:31 +00001082static int
paul718e3742002-12-13 20:15:29 +00001083vtysh_exit (struct vty *vty)
1084{
1085 switch (vty->node)
1086 {
1087 case VIEW_NODE:
1088 case ENABLE_NODE:
1089 exit (0);
1090 break;
1091 case CONFIG_NODE:
1092 vty->node = ENABLE_NODE;
1093 break;
1094 case INTERFACE_NODE:
1095 case ZEBRA_NODE:
1096 case BGP_NODE:
1097 case RIP_NODE:
1098 case RIPNG_NODE:
1099 case OSPF_NODE:
1100 case OSPF6_NODE:
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +01001101 case BABEL_NODE:
hassoc25e4582003-12-23 10:39:08 +00001102 case ISIS_NODE:
paul718e3742002-12-13 20:15:29 +00001103 case MASC_NODE:
1104 case RMAP_NODE:
1105 case VTY_NODE:
1106 case KEYCHAIN_NODE:
hasso2a56df92004-05-09 23:16:40 +00001107 vtysh_execute("end");
1108 vtysh_execute("configure terminal");
paul718e3742002-12-13 20:15:29 +00001109 vty->node = CONFIG_NODE;
1110 break;
1111 case BGP_VPNV4_NODE:
1112 case BGP_IPV4_NODE:
1113 case BGP_IPV4M_NODE:
1114 case BGP_IPV6_NODE:
paul57b5b7e2005-08-22 22:44:29 +00001115 case BGP_IPV6M_NODE:
paul718e3742002-12-13 20:15:29 +00001116 vty->node = BGP_NODE;
1117 break;
1118 case KEYCHAIN_KEY_NODE:
1119 vty->node = KEYCHAIN_NODE;
1120 break;
1121 default:
1122 break;
1123 }
1124 return CMD_SUCCESS;
1125}
1126
1127DEFUNSH (VTYSH_ALL,
1128 vtysh_exit_all,
1129 vtysh_exit_all_cmd,
1130 "exit",
1131 "Exit current mode and down to previous mode\n")
1132{
1133 return vtysh_exit (vty);
1134}
1135
1136ALIAS (vtysh_exit_all,
1137 vtysh_quit_all_cmd,
1138 "quit",
1139 "Exit current mode and down to previous mode\n")
1140
1141DEFUNSH (VTYSH_BGPD,
1142 exit_address_family,
1143 exit_address_family_cmd,
1144 "exit-address-family",
1145 "Exit from Address Family configuration mode\n")
1146{
1147 if (vty->node == BGP_IPV4_NODE
1148 || vty->node == BGP_IPV4M_NODE
1149 || vty->node == BGP_VPNV4_NODE
paul57b5b7e2005-08-22 22:44:29 +00001150 || vty->node == BGP_IPV6_NODE
1151 || vty->node == BGP_IPV6M_NODE)
paul718e3742002-12-13 20:15:29 +00001152 vty->node = BGP_NODE;
1153 return CMD_SUCCESS;
1154}
1155
1156DEFUNSH (VTYSH_ZEBRA,
1157 vtysh_exit_zebra,
1158 vtysh_exit_zebra_cmd,
1159 "exit",
1160 "Exit current mode and down to previous mode\n")
1161{
1162 return vtysh_exit (vty);
1163}
1164
1165ALIAS (vtysh_exit_zebra,
1166 vtysh_quit_zebra_cmd,
1167 "quit",
1168 "Exit current mode and down to previous mode\n")
1169
1170DEFUNSH (VTYSH_RIPD,
1171 vtysh_exit_ripd,
1172 vtysh_exit_ripd_cmd,
1173 "exit",
1174 "Exit current mode and down to previous mode\n")
1175{
1176 return vtysh_exit (vty);
1177}
1178
1179ALIAS (vtysh_exit_ripd,
1180 vtysh_quit_ripd_cmd,
1181 "quit",
1182 "Exit current mode and down to previous mode\n")
1183
paul68980082003-03-25 05:07:42 +00001184DEFUNSH (VTYSH_RIPNGD,
hassob094d262004-08-25 12:22:00 +00001185 vtysh_exit_ripngd,
1186 vtysh_exit_ripngd_cmd,
1187 "exit",
1188 "Exit current mode and down to previous mode\n")
paul68980082003-03-25 05:07:42 +00001189{
1190 return vtysh_exit (vty);
1191}
1192
1193ALIAS (vtysh_exit_ripngd,
1194 vtysh_quit_ripngd_cmd,
1195 "quit",
1196 "Exit current mode and down to previous mode\n")
1197
paul718e3742002-12-13 20:15:29 +00001198DEFUNSH (VTYSH_RMAP,
1199 vtysh_exit_rmap,
1200 vtysh_exit_rmap_cmd,
1201 "exit",
1202 "Exit current mode and down to previous mode\n")
1203{
1204 return vtysh_exit (vty);
1205}
1206
1207ALIAS (vtysh_exit_rmap,
1208 vtysh_quit_rmap_cmd,
1209 "quit",
1210 "Exit current mode and down to previous mode\n")
1211
1212DEFUNSH (VTYSH_BGPD,
1213 vtysh_exit_bgpd,
1214 vtysh_exit_bgpd_cmd,
1215 "exit",
1216 "Exit current mode and down to previous mode\n")
1217{
1218 return vtysh_exit (vty);
1219}
1220
1221ALIAS (vtysh_exit_bgpd,
1222 vtysh_quit_bgpd_cmd,
1223 "quit",
1224 "Exit current mode and down to previous mode\n")
1225
1226DEFUNSH (VTYSH_OSPFD,
1227 vtysh_exit_ospfd,
1228 vtysh_exit_ospfd_cmd,
1229 "exit",
1230 "Exit current mode and down to previous mode\n")
1231{
1232 return vtysh_exit (vty);
1233}
1234
1235ALIAS (vtysh_exit_ospfd,
1236 vtysh_quit_ospfd_cmd,
1237 "quit",
1238 "Exit current mode and down to previous mode\n")
1239
paul68980082003-03-25 05:07:42 +00001240DEFUNSH (VTYSH_OSPF6D,
hassob094d262004-08-25 12:22:00 +00001241 vtysh_exit_ospf6d,
1242 vtysh_exit_ospf6d_cmd,
1243 "exit",
1244 "Exit current mode and down to previous mode\n")
paul68980082003-03-25 05:07:42 +00001245{
1246 return vtysh_exit (vty);
1247}
1248
1249ALIAS (vtysh_exit_ospf6d,
1250 vtysh_quit_ospf6d_cmd,
1251 "quit",
1252 "Exit current mode and down to previous mode\n")
1253
hassoc25e4582003-12-23 10:39:08 +00001254DEFUNSH (VTYSH_ISISD,
hassob094d262004-08-25 12:22:00 +00001255 vtysh_exit_isisd,
1256 vtysh_exit_isisd_cmd,
1257 "exit",
1258 "Exit current mode and down to previous mode\n")
hassoc25e4582003-12-23 10:39:08 +00001259{
1260 return vtysh_exit (vty);
1261}
1262
1263ALIAS (vtysh_exit_isisd,
1264 vtysh_quit_isisd_cmd,
1265 "quit",
1266 "Exit current mode and down to previous mode\n")
1267
hassoe7168df2004-10-03 20:11:32 +00001268DEFUNSH (VTYSH_ALL,
1269 vtysh_exit_line_vty,
1270 vtysh_exit_line_vty_cmd,
1271 "exit",
1272 "Exit current mode and down to previous mode\n")
1273{
1274 return vtysh_exit (vty);
1275}
1276
1277ALIAS (vtysh_exit_line_vty,
1278 vtysh_quit_line_vty_cmd,
1279 "quit",
1280 "Exit current mode and down to previous mode\n")
1281
hasso95e735b2004-08-26 13:08:30 +00001282DEFUNSH (VTYSH_INTERFACE,
paul718e3742002-12-13 20:15:29 +00001283 vtysh_interface,
1284 vtysh_interface_cmd,
1285 "interface IFNAME",
1286 "Select an interface to configure\n"
1287 "Interface's name\n")
1288{
1289 vty->node = INTERFACE_NODE;
1290 return CMD_SUCCESS;
1291}
1292
hasso95e735b2004-08-26 13:08:30 +00001293/* TODO Implement "no interface command in isisd. */
paul32d24632003-05-23 09:25:20 +00001294DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D,
1295 vtysh_no_interface_cmd,
1296 "no interface IFNAME",
1297 NO_STR
1298 "Delete a pseudo interface's configuration\n"
1299 "Interface's name\n")
1300
hasso95e735b2004-08-26 13:08:30 +00001301/* TODO Implement interface description commands in ripngd, ospf6d
1302 * and isisd. */
paul338a9912003-03-01 15:44:10 +00001303DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1304 interface_desc_cmd,
1305 "description .LINE",
1306 "Interface specific description\n"
1307 "Characters describing this interface\n")
paul464dc8d2003-03-28 02:25:45 +00001308
1309DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1310 no_interface_desc_cmd,
1311 "no description",
1312 NO_STR
1313 "Interface specific description\n")
paul338a9912003-03-01 15:44:10 +00001314
hasso95e735b2004-08-26 13:08:30 +00001315DEFUNSH (VTYSH_INTERFACE,
paul718e3742002-12-13 20:15:29 +00001316 vtysh_exit_interface,
1317 vtysh_exit_interface_cmd,
1318 "exit",
1319 "Exit current mode and down to previous mode\n")
1320{
1321 return vtysh_exit (vty);
1322}
1323
1324ALIAS (vtysh_exit_interface,
1325 vtysh_quit_interface_cmd,
1326 "quit",
1327 "Exit current mode and down to previous mode\n")
1328
Paul Jakma362b4032006-05-28 07:54:45 +00001329/* Memory */
1330DEFUN (vtysh_show_memory,
1331 vtysh_show_memory_cmd,
1332 "show memory",
1333 SHOW_STR
1334 "Memory statistics\n")
1335{
1336 unsigned int i;
1337 int ret = CMD_SUCCESS;
1338 char line[] = "show memory\n";
1339
Balaji.G837d16c2012-09-26 14:09:10 +05301340 for (i = 0; i < array_size(vtysh_client); i++)
Paul Jakma362b4032006-05-28 07:54:45 +00001341 if ( vtysh_client[i].fd >= 0 )
1342 {
1343 fprintf (stdout, "Memory statistics for %s:\n",
1344 vtysh_client[i].name);
1345 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1346 fprintf (stdout,"\n");
1347 }
1348
1349 return ret;
1350}
1351
hasso95e735b2004-08-26 13:08:30 +00001352/* Logging commands. */
Paul Jakmadbf7d132006-05-23 22:10:01 +00001353DEFUN (vtysh_show_logging,
1354 vtysh_show_logging_cmd,
1355 "show logging",
1356 SHOW_STR
1357 "Show current logging configuration\n")
1358{
1359 unsigned int i;
1360 int ret = CMD_SUCCESS;
1361 char line[] = "show logging\n";
1362
Balaji.G837d16c2012-09-26 14:09:10 +05301363 for (i = 0; i < array_size(vtysh_client); i++)
Paul Jakma4150f332006-05-23 22:10:55 +00001364 if ( vtysh_client[i].fd >= 0 )
1365 {
1366 fprintf (stdout,"Logging configuration for %s:\n",
1367 vtysh_client[i].name);
1368 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1369 fprintf (stdout,"\n");
1370 }
1371
Paul Jakmadbf7d132006-05-23 22:10:01 +00001372 return ret;
1373}
1374
hasso95e735b2004-08-26 13:08:30 +00001375DEFUNSH (VTYSH_ALL,
1376 vtysh_log_stdout,
1377 vtysh_log_stdout_cmd,
1378 "log stdout",
1379 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001380 "Set stdout logging level\n")
1381{
1382 return CMD_SUCCESS;
1383}
1384
1385DEFUNSH (VTYSH_ALL,
1386 vtysh_log_stdout_level,
1387 vtysh_log_stdout_level_cmd,
1388 "log stdout "LOG_LEVELS,
1389 "Logging control\n"
1390 "Set stdout logging level\n"
1391 LOG_LEVEL_DESC)
hasso95e735b2004-08-26 13:08:30 +00001392{
1393 return CMD_SUCCESS;
1394}
1395
1396DEFUNSH (VTYSH_ALL,
1397 no_vtysh_log_stdout,
1398 no_vtysh_log_stdout_cmd,
ajs274a4a42004-12-07 15:39:31 +00001399 "no log stdout [LEVEL]",
hasso95e735b2004-08-26 13:08:30 +00001400 NO_STR
1401 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001402 "Cancel logging to stdout\n"
1403 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001404{
1405 return CMD_SUCCESS;
1406}
1407
1408DEFUNSH (VTYSH_ALL,
1409 vtysh_log_file,
1410 vtysh_log_file_cmd,
1411 "log file FILENAME",
1412 "Logging control\n"
1413 "Logging to file\n"
1414 "Logging filename\n")
1415{
1416 return CMD_SUCCESS;
1417}
1418
1419DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001420 vtysh_log_file_level,
1421 vtysh_log_file_level_cmd,
1422 "log file FILENAME "LOG_LEVELS,
1423 "Logging control\n"
1424 "Logging to file\n"
1425 "Logging filename\n"
1426 LOG_LEVEL_DESC)
1427{
1428 return CMD_SUCCESS;
1429}
1430
1431DEFUNSH (VTYSH_ALL,
hasso95e735b2004-08-26 13:08:30 +00001432 no_vtysh_log_file,
1433 no_vtysh_log_file_cmd,
1434 "no log file [FILENAME]",
1435 NO_STR
1436 "Logging control\n"
1437 "Cancel logging to file\n"
1438 "Logging file name\n")
1439{
1440 return CMD_SUCCESS;
1441}
1442
ajs274a4a42004-12-07 15:39:31 +00001443ALIAS_SH (VTYSH_ALL,
1444 no_vtysh_log_file,
1445 no_vtysh_log_file_level_cmd,
1446 "no log file FILENAME LEVEL",
1447 NO_STR
1448 "Logging control\n"
1449 "Cancel logging to file\n"
1450 "Logging file name\n"
1451 "Logging level\n")
1452
1453DEFUNSH (VTYSH_ALL,
1454 vtysh_log_monitor,
1455 vtysh_log_monitor_cmd,
1456 "log monitor",
1457 "Logging control\n"
1458 "Set terminal line (monitor) logging level\n")
1459{
1460 return CMD_SUCCESS;
1461}
1462
1463DEFUNSH (VTYSH_ALL,
1464 vtysh_log_monitor_level,
1465 vtysh_log_monitor_level_cmd,
1466 "log monitor "LOG_LEVELS,
1467 "Logging control\n"
1468 "Set terminal line (monitor) logging level\n"
1469 LOG_LEVEL_DESC)
1470{
1471 return CMD_SUCCESS;
1472}
1473
1474DEFUNSH (VTYSH_ALL,
1475 no_vtysh_log_monitor,
1476 no_vtysh_log_monitor_cmd,
1477 "no log monitor [LEVEL]",
1478 NO_STR
1479 "Logging control\n"
1480 "Disable terminal line (monitor) logging\n"
1481 "Logging level\n")
1482{
1483 return CMD_SUCCESS;
1484}
1485
hasso95e735b2004-08-26 13:08:30 +00001486DEFUNSH (VTYSH_ALL,
1487 vtysh_log_syslog,
1488 vtysh_log_syslog_cmd,
1489 "log syslog",
1490 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001491 "Set syslog logging level\n")
1492{
1493 return CMD_SUCCESS;
1494}
1495
1496DEFUNSH (VTYSH_ALL,
1497 vtysh_log_syslog_level,
1498 vtysh_log_syslog_level_cmd,
1499 "log syslog "LOG_LEVELS,
1500 "Logging control\n"
1501 "Set syslog logging level\n"
1502 LOG_LEVEL_DESC)
hasso95e735b2004-08-26 13:08:30 +00001503{
1504 return CMD_SUCCESS;
1505}
1506
1507DEFUNSH (VTYSH_ALL,
1508 no_vtysh_log_syslog,
1509 no_vtysh_log_syslog_cmd,
ajs274a4a42004-12-07 15:39:31 +00001510 "no log syslog [LEVEL]",
hasso95e735b2004-08-26 13:08:30 +00001511 NO_STR
1512 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001513 "Cancel logging to syslog\n"
1514 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001515{
1516 return CMD_SUCCESS;
1517}
1518
1519DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001520 vtysh_log_facility,
1521 vtysh_log_facility_cmd,
1522 "log facility "LOG_FACILITIES,
hasso95e735b2004-08-26 13:08:30 +00001523 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001524 "Facility parameter for syslog messages\n"
1525 LOG_FACILITY_DESC)
1526
hasso95e735b2004-08-26 13:08:30 +00001527{
1528 return CMD_SUCCESS;
1529}
1530
1531DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001532 no_vtysh_log_facility,
1533 no_vtysh_log_facility_cmd,
1534 "no log facility [FACILITY]",
hasso95e735b2004-08-26 13:08:30 +00001535 NO_STR
1536 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001537 "Reset syslog facility to default (daemon)\n"
1538 "Syslog facility\n")
1539
1540{
1541 return CMD_SUCCESS;
1542}
1543
1544DEFUNSH_DEPRECATED (VTYSH_ALL,
1545 vtysh_log_trap,
1546 vtysh_log_trap_cmd,
1547 "log trap "LOG_LEVELS,
1548 "Logging control\n"
1549 "(Deprecated) Set logging level and default for all destinations\n"
1550 LOG_LEVEL_DESC)
1551
1552{
1553 return CMD_SUCCESS;
1554}
1555
1556DEFUNSH_DEPRECATED (VTYSH_ALL,
1557 no_vtysh_log_trap,
1558 no_vtysh_log_trap_cmd,
1559 "no log trap [LEVEL]",
1560 NO_STR
1561 "Logging control\n"
1562 "Permit all logging information\n"
1563 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001564{
1565 return CMD_SUCCESS;
1566}
1567
1568DEFUNSH (VTYSH_ALL,
1569 vtysh_log_record_priority,
1570 vtysh_log_record_priority_cmd,
1571 "log record-priority",
1572 "Logging control\n"
1573 "Log the priority of the message within the message\n")
1574{
1575 return CMD_SUCCESS;
1576}
1577
1578DEFUNSH (VTYSH_ALL,
1579 no_vtysh_log_record_priority,
1580 no_vtysh_log_record_priority_cmd,
1581 "no log record-priority",
1582 NO_STR
1583 "Logging control\n"
1584 "Do not log the priority of the message within the message\n")
1585{
1586 return CMD_SUCCESS;
1587}
1588
hassoe7168df2004-10-03 20:11:32 +00001589DEFUNSH (VTYSH_ALL,
Andrew J. Schorrc749b722007-04-29 03:53:31 +00001590 vtysh_log_timestamp_precision,
1591 vtysh_log_timestamp_precision_cmd,
1592 "log timestamp precision <0-6>",
1593 "Logging control\n"
1594 "Timestamp configuration\n"
1595 "Set the timestamp precision\n"
1596 "Number of subsecond digits\n")
1597{
1598 return CMD_SUCCESS;
1599}
1600
1601DEFUNSH (VTYSH_ALL,
1602 no_vtysh_log_timestamp_precision,
1603 no_vtysh_log_timestamp_precision_cmd,
1604 "no log timestamp precision",
1605 NO_STR
1606 "Logging control\n"
1607 "Timestamp configuration\n"
1608 "Reset the timestamp precision to the default value of 0\n")
1609{
1610 return CMD_SUCCESS;
1611}
1612
1613DEFUNSH (VTYSH_ALL,
hassoe7168df2004-10-03 20:11:32 +00001614 vtysh_service_password_encrypt,
1615 vtysh_service_password_encrypt_cmd,
1616 "service password-encryption",
1617 "Set up miscellaneous service\n"
1618 "Enable encrypted passwords\n")
1619{
1620 return CMD_SUCCESS;
1621}
1622
1623DEFUNSH (VTYSH_ALL,
1624 no_vtysh_service_password_encrypt,
1625 no_vtysh_service_password_encrypt_cmd,
1626 "no service password-encryption",
1627 NO_STR
1628 "Set up miscellaneous service\n"
1629 "Enable encrypted passwords\n")
1630{
1631 return CMD_SUCCESS;
1632}
1633
1634DEFUNSH (VTYSH_ALL,
1635 vtysh_config_password,
1636 vtysh_password_cmd,
1637 "password (8|) WORD",
1638 "Assign the terminal connection password\n"
1639 "Specifies a HIDDEN password will follow\n"
1640 "dummy string \n"
1641 "The HIDDEN line password string\n")
1642{
1643 return CMD_SUCCESS;
1644}
1645
1646DEFUNSH (VTYSH_ALL,
1647 vtysh_password_text,
1648 vtysh_password_text_cmd,
1649 "password LINE",
1650 "Assign the terminal connection password\n"
1651 "The UNENCRYPTED (cleartext) line password\n")
1652{
1653 return CMD_SUCCESS;
1654}
1655
1656DEFUNSH (VTYSH_ALL,
1657 vtysh_config_enable_password,
1658 vtysh_enable_password_cmd,
1659 "enable password (8|) WORD",
1660 "Modify enable password parameters\n"
1661 "Assign the privileged level password\n"
1662 "Specifies a HIDDEN password will follow\n"
1663 "dummy string \n"
1664 "The HIDDEN 'enable' password string\n")
1665{
1666 return CMD_SUCCESS;
1667}
1668
1669DEFUNSH (VTYSH_ALL,
1670 vtysh_enable_password_text,
1671 vtysh_enable_password_text_cmd,
1672 "enable password LINE",
1673 "Modify enable password parameters\n"
1674 "Assign the privileged level password\n"
1675 "The UNENCRYPTED (cleartext) 'enable' password\n")
1676{
1677 return CMD_SUCCESS;
1678}
1679
1680DEFUNSH (VTYSH_ALL,
1681 no_vtysh_config_enable_password,
1682 no_vtysh_enable_password_cmd,
1683 "no enable password",
1684 NO_STR
1685 "Modify enable password parameters\n"
1686 "Assign the privileged level password\n")
1687{
1688 return CMD_SUCCESS;
1689}
1690
paul718e3742002-12-13 20:15:29 +00001691DEFUN (vtysh_write_terminal,
1692 vtysh_write_terminal_cmd,
1693 "write terminal",
1694 "Write running configuration to memory, network, or terminal\n"
1695 "Write to terminal\n")
1696{
ajsb1aa1472005-01-28 21:11:46 +00001697 u_int i;
paul718e3742002-12-13 20:15:29 +00001698 char line[] = "write terminal\n";
1699 FILE *fp = NULL;
1700
1701 if (vtysh_pager_name)
1702 {
paul4fc01e62002-12-13 20:49:00 +00001703 fp = popen (vtysh_pager_name, "w");
paul718e3742002-12-13 20:15:29 +00001704 if (fp == NULL)
1705 {
1706 perror ("popen");
1707 exit (1);
1708 }
1709 }
1710 else
1711 fp = stdout;
1712
1713 vty_out (vty, "Building configuration...%s", VTY_NEWLINE);
1714 vty_out (vty, "%sCurrent configuration:%s", VTY_NEWLINE,
1715 VTY_NEWLINE);
hassoe7168df2004-10-03 20:11:32 +00001716 vty_out (vty, "!%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001717
Balaji.G837d16c2012-09-26 14:09:10 +05301718 for (i = 0; i < array_size(vtysh_client); i++)
David Lamparter6769f432015-03-04 07:18:24 +01001719 vtysh_client_config (&vtysh_client[i], line);
paul718e3742002-12-13 20:15:29 +00001720
hassoe7168df2004-10-03 20:11:32 +00001721 /* Integrate vtysh specific configuration. */
1722 vtysh_config_write ();
1723
paul718e3742002-12-13 20:15:29 +00001724 vtysh_config_dump (fp);
1725
1726 if (vtysh_pager_name && fp)
1727 {
1728 fflush (fp);
1729 if (pclose (fp) == -1)
1730 {
1731 perror ("pclose");
1732 exit (1);
1733 }
1734 fp = NULL;
1735 }
1736
Chris Caputo6e79f8b2009-06-23 05:55:57 +00001737 vty_out (vty, "end%s", VTY_NEWLINE);
1738
paul718e3742002-12-13 20:15:29 +00001739 return CMD_SUCCESS;
1740}
1741
hassoe7168df2004-10-03 20:11:32 +00001742DEFUN (vtysh_integrated_config,
1743 vtysh_integrated_config_cmd,
1744 "service integrated-vtysh-config",
1745 "Set up miscellaneous service\n"
1746 "Write configuration into integrated file\n")
paul4fc01e62002-12-13 20:49:00 +00001747{
hassoe7168df2004-10-03 20:11:32 +00001748 vtysh_writeconfig_integrated = 1;
1749 return CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001750}
1751
hassoe7168df2004-10-03 20:11:32 +00001752DEFUN (no_vtysh_integrated_config,
1753 no_vtysh_integrated_config_cmd,
1754 "no service integrated-vtysh-config",
1755 NO_STR
1756 "Set up miscellaneous service\n"
1757 "Write configuration into integrated file\n")
paul4fc01e62002-12-13 20:49:00 +00001758{
hassoe7168df2004-10-03 20:11:32 +00001759 vtysh_writeconfig_integrated = 0;
1760 return CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001761}
1762
ajs274a4a42004-12-07 15:39:31 +00001763static int
1764write_config_integrated(void)
paul718e3742002-12-13 20:15:29 +00001765{
ajsb1aa1472005-01-28 21:11:46 +00001766 u_int i;
paul718e3742002-12-13 20:15:29 +00001767 char line[] = "write terminal\n";
1768 FILE *fp;
1769 char *integrate_sav = NULL;
1770
hasso95e735b2004-08-26 13:08:30 +00001771 integrate_sav = malloc (strlen (integrate_default) +
1772 strlen (CONF_BACKUP_EXT) + 1);
paul718e3742002-12-13 20:15:29 +00001773 strcpy (integrate_sav, integrate_default);
1774 strcat (integrate_sav, CONF_BACKUP_EXT);
1775
paul4fc01e62002-12-13 20:49:00 +00001776 fprintf (stdout,"Building Configuration...\n");
paul718e3742002-12-13 20:15:29 +00001777
hasso95e735b2004-08-26 13:08:30 +00001778 /* Move current configuration file to backup config file. */
paul718e3742002-12-13 20:15:29 +00001779 unlink (integrate_sav);
1780 rename (integrate_default, integrate_sav);
hasso95e735b2004-08-26 13:08:30 +00001781 free (integrate_sav);
paul4fc01e62002-12-13 20:49:00 +00001782
paul718e3742002-12-13 20:15:29 +00001783 fp = fopen (integrate_default, "w");
1784 if (fp == NULL)
1785 {
hasso95e735b2004-08-26 13:08:30 +00001786 fprintf (stdout,"%% Can't open configuration file %s.\n",
1787 integrate_default);
paul718e3742002-12-13 20:15:29 +00001788 return CMD_SUCCESS;
1789 }
paul718e3742002-12-13 20:15:29 +00001790
Balaji.G837d16c2012-09-26 14:09:10 +05301791 for (i = 0; i < array_size(vtysh_client); i++)
David Lamparter6769f432015-03-04 07:18:24 +01001792 vtysh_client_config (&vtysh_client[i], line);
paul718e3742002-12-13 20:15:29 +00001793
1794 vtysh_config_dump (fp);
1795
1796 fclose (fp);
1797
gdtaa593d52003-12-22 20:15:53 +00001798 if (chmod (integrate_default, CONFIGFILE_MASK) != 0)
1799 {
1800 fprintf (stdout,"%% Can't chmod configuration file %s: %s (%d)\n",
ajs6099b3b2004-11-20 02:06:59 +00001801 integrate_default, safe_strerror(errno), errno);
gdtaa593d52003-12-22 20:15:53 +00001802 return CMD_WARNING;
1803 }
1804
paul4fc01e62002-12-13 20:49:00 +00001805 fprintf(stdout,"Integrated configuration saved to %s\n",integrate_default);
1806
1807 fprintf (stdout,"[OK]\n");
1808
paul718e3742002-12-13 20:15:29 +00001809 return CMD_SUCCESS;
1810}
1811
paul4fc01e62002-12-13 20:49:00 +00001812DEFUN (vtysh_write_memory,
1813 vtysh_write_memory_cmd,
1814 "write memory",
1815 "Write running configuration to memory, network, or terminal\n"
1816 "Write configuration to the file (same as write file)\n")
1817{
pauldfc0d9b2003-04-18 23:55:29 +00001818 int ret = CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001819 char line[] = "write memory\n";
ajsb1aa1472005-01-28 21:11:46 +00001820 u_int i;
paul4fc01e62002-12-13 20:49:00 +00001821
hassoe7168df2004-10-03 20:11:32 +00001822 /* If integrated Quagga.conf explicitely set. */
1823 if (vtysh_writeconfig_integrated)
1824 return write_config_integrated();
paul4fc01e62002-12-13 20:49:00 +00001825
1826 fprintf (stdout,"Building Configuration...\n");
1827
Balaji.G837d16c2012-09-26 14:09:10 +05301828 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00001829 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
hassoe7168df2004-10-03 20:11:32 +00001830
paul4fc01e62002-12-13 20:49:00 +00001831 fprintf (stdout,"[OK]\n");
1832
pauldfc0d9b2003-04-18 23:55:29 +00001833 return ret;
paul4fc01e62002-12-13 20:49:00 +00001834}
1835
paul718e3742002-12-13 20:15:29 +00001836ALIAS (vtysh_write_memory,
1837 vtysh_copy_runningconfig_startupconfig_cmd,
1838 "copy running-config startup-config",
1839 "Copy from one file to another\n"
1840 "Copy from current system configuration\n"
1841 "Copy to startup configuration\n")
1842
1843ALIAS (vtysh_write_memory,
1844 vtysh_write_file_cmd,
1845 "write file",
1846 "Write running configuration to memory, network, or terminal\n"
1847 "Write configuration to the file (same as write memory)\n")
1848
hasso4a6e2252003-05-25 11:51:29 +00001849ALIAS (vtysh_write_memory,
1850 vtysh_write_cmd,
1851 "write",
1852 "Write running configuration to memory, network, or terminal\n")
1853
paul718e3742002-12-13 20:15:29 +00001854ALIAS (vtysh_write_terminal,
1855 vtysh_show_running_config_cmd,
1856 "show running-config",
1857 SHOW_STR
1858 "Current operating configuration\n")
hassob094d262004-08-25 12:22:00 +00001859
hasso34553cc2004-08-27 13:56:39 +00001860DEFUN (vtysh_terminal_length,
1861 vtysh_terminal_length_cmd,
1862 "terminal length <0-512>",
1863 "Set terminal line parameters\n"
1864 "Set number of lines on a screen\n"
1865 "Number of lines on screen (0 for no pausing)\n")
1866{
1867 int lines;
1868 char *endptr = NULL;
1869 char default_pager[10];
1870
1871 lines = strtol (argv[0], &endptr, 10);
1872 if (lines < 0 || lines > 512 || *endptr != '\0')
1873 {
1874 vty_out (vty, "length is malformed%s", VTY_NEWLINE);
1875 return CMD_WARNING;
1876 }
1877
1878 if (vtysh_pager_name)
1879 {
1880 free (vtysh_pager_name);
1881 vtysh_pager_name = NULL;
1882 }
1883
1884 if (lines != 0)
1885 {
1886 snprintf(default_pager, 10, "more -%i", lines);
1887 vtysh_pager_name = strdup (default_pager);
1888 }
1889
1890 return CMD_SUCCESS;
1891}
1892
1893DEFUN (vtysh_terminal_no_length,
1894 vtysh_terminal_no_length_cmd,
1895 "terminal no length",
1896 "Set terminal line parameters\n"
1897 NO_STR
1898 "Set number of lines on a screen\n")
1899{
1900 if (vtysh_pager_name)
1901 {
1902 free (vtysh_pager_name);
1903 vtysh_pager_name = NULL;
1904 }
1905
1906 vtysh_pager_init();
1907 return CMD_SUCCESS;
1908}
1909
hassof2799e62004-10-28 17:43:11 +00001910DEFUN (vtysh_show_daemons,
1911 vtysh_show_daemons_cmd,
1912 "show daemons",
hassoe7168df2004-10-03 20:11:32 +00001913 SHOW_STR
1914 "Show list of running daemons\n")
1915{
ajsb1aa1472005-01-28 21:11:46 +00001916 u_int i;
1917
Balaji.G837d16c2012-09-26 14:09:10 +05301918 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00001919 if ( vtysh_client[i].fd >= 0 )
1920 vty_out(vty, " %s", vtysh_client[i].name);
hassoe7168df2004-10-03 20:11:32 +00001921 vty_out(vty, "%s", VTY_NEWLINE);
1922
1923 return CMD_SUCCESS;
1924}
1925
paul718e3742002-12-13 20:15:29 +00001926/* Execute command in child process. */
ajs274a4a42004-12-07 15:39:31 +00001927static int
hasso5862ff52004-10-11 13:20:40 +00001928execute_command (const char *command, int argc, const char *arg1,
1929 const char *arg2)
paul718e3742002-12-13 20:15:29 +00001930{
paul718e3742002-12-13 20:15:29 +00001931 pid_t pid;
1932 int status;
1933
1934 /* Call fork(). */
1935 pid = fork ();
1936
1937 if (pid < 0)
1938 {
1939 /* Failure of fork(). */
ajs6099b3b2004-11-20 02:06:59 +00001940 fprintf (stderr, "Can't fork: %s\n", safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +00001941 exit (1);
1942 }
1943 else if (pid == 0)
1944 {
1945 /* This is child process. */
1946 switch (argc)
1947 {
1948 case 0:
David Lamparter6769f432015-03-04 07:18:24 +01001949 execlp (command, command, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00001950 break;
1951 case 1:
David Lamparter6769f432015-03-04 07:18:24 +01001952 execlp (command, command, arg1, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00001953 break;
1954 case 2:
David Lamparter6769f432015-03-04 07:18:24 +01001955 execlp (command, command, arg1, arg2, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00001956 break;
1957 }
1958
1959 /* When execlp suceed, this part is not executed. */
ajs6099b3b2004-11-20 02:06:59 +00001960 fprintf (stderr, "Can't execute %s: %s\n", command, safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +00001961 exit (1);
1962 }
1963 else
1964 {
1965 /* This is parent. */
1966 execute_flag = 1;
David Lamparter6769f432015-03-04 07:18:24 +01001967 wait4 (pid, &status, 0, NULL);
paul718e3742002-12-13 20:15:29 +00001968 execute_flag = 0;
1969 }
1970 return 0;
1971}
1972
1973DEFUN (vtysh_ping,
1974 vtysh_ping_cmd,
1975 "ping WORD",
hasso4eeccf12003-06-25 10:49:55 +00001976 "Send echo messages\n"
paul718e3742002-12-13 20:15:29 +00001977 "Ping destination address or hostname\n")
1978{
1979 execute_command ("ping", 1, argv[0], NULL);
1980 return CMD_SUCCESS;
1981}
1982
hasso4eeccf12003-06-25 10:49:55 +00001983ALIAS (vtysh_ping,
1984 vtysh_ping_ip_cmd,
1985 "ping ip WORD",
1986 "Send echo messages\n"
1987 "IP echo\n"
1988 "Ping destination address or hostname\n")
1989
paul718e3742002-12-13 20:15:29 +00001990DEFUN (vtysh_traceroute,
1991 vtysh_traceroute_cmd,
1992 "traceroute WORD",
1993 "Trace route to destination\n"
1994 "Trace route to destination address or hostname\n")
1995{
1996 execute_command ("traceroute", 1, argv[0], NULL);
1997 return CMD_SUCCESS;
1998}
1999
hasso4eeccf12003-06-25 10:49:55 +00002000ALIAS (vtysh_traceroute,
2001 vtysh_traceroute_ip_cmd,
2002 "traceroute ip WORD",
2003 "Trace route to destination\n"
2004 "IP trace\n"
2005 "Trace route to destination address or hostname\n")
2006
2007#ifdef HAVE_IPV6
2008DEFUN (vtysh_ping6,
2009 vtysh_ping6_cmd,
2010 "ping ipv6 WORD",
2011 "Send echo messages\n"
2012 "IPv6 echo\n"
2013 "Ping destination address or hostname\n")
2014{
2015 execute_command ("ping6", 1, argv[0], NULL);
2016 return CMD_SUCCESS;
2017}
2018
2019DEFUN (vtysh_traceroute6,
2020 vtysh_traceroute6_cmd,
2021 "traceroute ipv6 WORD",
2022 "Trace route to destination\n"
2023 "IPv6 trace\n"
2024 "Trace route to destination address or hostname\n")
2025{
2026 execute_command ("traceroute6", 1, argv[0], NULL);
2027 return CMD_SUCCESS;
2028}
2029#endif
2030
paul718e3742002-12-13 20:15:29 +00002031DEFUN (vtysh_telnet,
2032 vtysh_telnet_cmd,
2033 "telnet WORD",
2034 "Open a telnet connection\n"
2035 "IP address or hostname of a remote system\n")
2036{
2037 execute_command ("telnet", 1, argv[0], NULL);
2038 return CMD_SUCCESS;
2039}
2040
2041DEFUN (vtysh_telnet_port,
2042 vtysh_telnet_port_cmd,
2043 "telnet WORD PORT",
2044 "Open a telnet connection\n"
2045 "IP address or hostname of a remote system\n"
2046 "TCP Port number\n")
2047{
2048 execute_command ("telnet", 2, argv[0], argv[1]);
2049 return CMD_SUCCESS;
2050}
2051
paul5087df52003-01-25 06:56:09 +00002052DEFUN (vtysh_ssh,
2053 vtysh_ssh_cmd,
2054 "ssh WORD",
2055 "Open an ssh connection\n"
2056 "[user@]host\n")
2057{
2058 execute_command ("ssh", 1, argv[0], NULL);
2059 return CMD_SUCCESS;
2060}
2061
paul718e3742002-12-13 20:15:29 +00002062DEFUN (vtysh_start_shell,
2063 vtysh_start_shell_cmd,
2064 "start-shell",
2065 "Start UNIX shell\n")
2066{
2067 execute_command ("sh", 0, NULL, NULL);
2068 return CMD_SUCCESS;
2069}
2070
2071DEFUN (vtysh_start_bash,
2072 vtysh_start_bash_cmd,
2073 "start-shell bash",
2074 "Start UNIX shell\n"
2075 "Start bash\n")
2076{
2077 execute_command ("bash", 0, NULL, NULL);
2078 return CMD_SUCCESS;
2079}
2080
2081DEFUN (vtysh_start_zsh,
2082 vtysh_start_zsh_cmd,
2083 "start-shell zsh",
2084 "Start UNIX shell\n"
2085 "Start Z shell\n")
2086{
2087 execute_command ("zsh", 0, NULL, NULL);
2088 return CMD_SUCCESS;
2089}
hassob094d262004-08-25 12:22:00 +00002090
ajs274a4a42004-12-07 15:39:31 +00002091static void
paul718e3742002-12-13 20:15:29 +00002092vtysh_install_default (enum node_type node)
2093{
2094 install_element (node, &config_list_cmd);
2095}
2096
2097/* Making connection to protocol daemon. */
ajs274a4a42004-12-07 15:39:31 +00002098static int
ajsb1aa1472005-01-28 21:11:46 +00002099vtysh_connect (struct vtysh_client *vclient)
paul718e3742002-12-13 20:15:29 +00002100{
2101 int ret;
2102 int sock, len;
2103 struct sockaddr_un addr;
2104 struct stat s_stat;
paul718e3742002-12-13 20:15:29 +00002105
paul718e3742002-12-13 20:15:29 +00002106 /* Stat socket to see if we have permission to access it. */
ajsb1aa1472005-01-28 21:11:46 +00002107 ret = stat (vclient->path, &s_stat);
paul718e3742002-12-13 20:15:29 +00002108 if (ret < 0 && errno != ENOENT)
2109 {
2110 fprintf (stderr, "vtysh_connect(%s): stat = %s\n",
ajsb1aa1472005-01-28 21:11:46 +00002111 vclient->path, safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002112 exit(1);
2113 }
2114
2115 if (ret >= 0)
2116 {
2117 if (! S_ISSOCK(s_stat.st_mode))
2118 {
2119 fprintf (stderr, "vtysh_connect(%s): Not a socket\n",
ajsb1aa1472005-01-28 21:11:46 +00002120 vclient->path);
paul718e3742002-12-13 20:15:29 +00002121 exit (1);
2122 }
2123
paul718e3742002-12-13 20:15:29 +00002124 }
2125
2126 sock = socket (AF_UNIX, SOCK_STREAM, 0);
2127 if (sock < 0)
2128 {
2129#ifdef DEBUG
ajsb1aa1472005-01-28 21:11:46 +00002130 fprintf(stderr, "vtysh_connect(%s): socket = %s\n", vclient->path,
ajs6099b3b2004-11-20 02:06:59 +00002131 safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002132#endif /* DEBUG */
2133 return -1;
2134 }
2135
2136 memset (&addr, 0, sizeof (struct sockaddr_un));
2137 addr.sun_family = AF_UNIX;
ajsb1aa1472005-01-28 21:11:46 +00002138 strncpy (addr.sun_path, vclient->path, strlen (vclient->path));
Paul Jakma6f0e3f62007-05-10 02:38:51 +00002139#ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
paul718e3742002-12-13 20:15:29 +00002140 len = addr.sun_len = SUN_LEN(&addr);
2141#else
2142 len = sizeof (addr.sun_family) + strlen (addr.sun_path);
Paul Jakma6f0e3f62007-05-10 02:38:51 +00002143#endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
paul718e3742002-12-13 20:15:29 +00002144
2145 ret = connect (sock, (struct sockaddr *) &addr, len);
2146 if (ret < 0)
2147 {
2148#ifdef DEBUG
ajsb1aa1472005-01-28 21:11:46 +00002149 fprintf(stderr, "vtysh_connect(%s): connect = %s\n", vclient->path,
ajs6099b3b2004-11-20 02:06:59 +00002150 safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002151#endif /* DEBUG */
2152 close (sock);
2153 return -1;
2154 }
2155 vclient->fd = sock;
2156
2157 return 0;
2158}
2159
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002160int
2161vtysh_connect_all(const char *daemon_name)
paul718e3742002-12-13 20:15:29 +00002162{
ajsb1aa1472005-01-28 21:11:46 +00002163 u_int i;
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002164 int rc = 0;
2165 int matches = 0;
ajsb1aa1472005-01-28 21:11:46 +00002166
Balaji.G837d16c2012-09-26 14:09:10 +05302167 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00002168 {
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002169 if (!daemon_name || !strcmp(daemon_name, vtysh_client[i].name))
2170 {
2171 matches++;
2172 if (vtysh_connect(&vtysh_client[i]) == 0)
2173 rc++;
2174 /* We need direct access to ripd in vtysh_exit_ripd_only. */
2175 if (vtysh_client[i].flag == VTYSH_RIPD)
2176 ripd_client = &vtysh_client[i];
2177 }
ajsb1aa1472005-01-28 21:11:46 +00002178 }
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002179 if (!matches)
2180 fprintf(stderr, "Error: no daemons match name %s!\n", daemon_name);
2181 return rc;
paul718e3742002-12-13 20:15:29 +00002182}
2183
hasso95e735b2004-08-26 13:08:30 +00002184/* To disable readline's filename completion. */
ajs274a4a42004-12-07 15:39:31 +00002185static char *
pauldfc0d9b2003-04-18 23:55:29 +00002186vtysh_completion_entry_function (const char *ignore, int invoking_key)
paul718e3742002-12-13 20:15:29 +00002187{
pauldfc0d9b2003-04-18 23:55:29 +00002188 return NULL;
paul718e3742002-12-13 20:15:29 +00002189}
2190
2191void
ajsb1aa1472005-01-28 21:11:46 +00002192vtysh_readline_init (void)
paul718e3742002-12-13 20:15:29 +00002193{
2194 /* readline related settings. */
Sébastien Luttringer66d2ead2014-05-27 19:55:11 +02002195 rl_bind_key ('?', (rl_command_func_t *) vtysh_rl_describe);
paul68980082003-03-25 05:07:42 +00002196 rl_completion_entry_function = vtysh_completion_entry_function;
Sébastien Luttringer66d2ead2014-05-27 19:55:11 +02002197 rl_attempted_completion_function = (rl_completion_func_t *)new_completion;
paul718e3742002-12-13 20:15:29 +00002198}
2199
2200char *
ajsb1aa1472005-01-28 21:11:46 +00002201vtysh_prompt (void)
paul718e3742002-12-13 20:15:29 +00002202{
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002203 static struct utsname names;
paul718e3742002-12-13 20:15:29 +00002204 static char buf[100];
2205 const char*hostname;
2206 extern struct host host;
2207
2208 hostname = host.name;
2209
2210 if (!hostname)
2211 {
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002212 if (!names.nodename[0])
2213 uname (&names);
paul718e3742002-12-13 20:15:29 +00002214 hostname = names.nodename;
2215 }
2216
2217 snprintf (buf, sizeof buf, cmd_prompt (vty->node), hostname);
2218
2219 return buf;
2220}
2221
2222void
ajsb1aa1472005-01-28 21:11:46 +00002223vtysh_init_vty (void)
paul718e3742002-12-13 20:15:29 +00002224{
2225 /* Make vty structure. */
2226 vty = vty_new ();
2227 vty->type = VTY_SHELL;
2228 vty->node = VIEW_NODE;
2229
2230 /* Initialize commands. */
2231 cmd_init (0);
2232
2233 /* Install nodes. */
2234 install_node (&bgp_node, NULL);
2235 install_node (&rip_node, NULL);
2236 install_node (&interface_node, NULL);
2237 install_node (&rmap_node, NULL);
2238 install_node (&zebra_node, NULL);
2239 install_node (&bgp_vpnv4_node, NULL);
2240 install_node (&bgp_ipv4_node, NULL);
2241 install_node (&bgp_ipv4m_node, NULL);
2242/* #ifdef HAVE_IPV6 */
2243 install_node (&bgp_ipv6_node, NULL);
paul57b5b7e2005-08-22 22:44:29 +00002244 install_node (&bgp_ipv6m_node, NULL);
paul718e3742002-12-13 20:15:29 +00002245/* #endif */
2246 install_node (&ospf_node, NULL);
2247/* #ifdef HAVE_IPV6 */
2248 install_node (&ripng_node, NULL);
2249 install_node (&ospf6_node, NULL);
2250/* #endif */
2251 install_node (&keychain_node, NULL);
2252 install_node (&keychain_key_node, NULL);
hassoc25e4582003-12-23 10:39:08 +00002253 install_node (&isis_node, NULL);
hassoe7168df2004-10-03 20:11:32 +00002254 install_node (&vty_node, NULL);
paul718e3742002-12-13 20:15:29 +00002255
2256 vtysh_install_default (VIEW_NODE);
2257 vtysh_install_default (ENABLE_NODE);
2258 vtysh_install_default (CONFIG_NODE);
2259 vtysh_install_default (BGP_NODE);
2260 vtysh_install_default (RIP_NODE);
2261 vtysh_install_default (INTERFACE_NODE);
2262 vtysh_install_default (RMAP_NODE);
2263 vtysh_install_default (ZEBRA_NODE);
2264 vtysh_install_default (BGP_VPNV4_NODE);
2265 vtysh_install_default (BGP_IPV4_NODE);
2266 vtysh_install_default (BGP_IPV4M_NODE);
2267 vtysh_install_default (BGP_IPV6_NODE);
paul57b5b7e2005-08-22 22:44:29 +00002268 vtysh_install_default (BGP_IPV6M_NODE);
paul718e3742002-12-13 20:15:29 +00002269 vtysh_install_default (OSPF_NODE);
2270 vtysh_install_default (RIPNG_NODE);
2271 vtysh_install_default (OSPF6_NODE);
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +01002272 vtysh_install_default (BABEL_NODE);
hassoc25e4582003-12-23 10:39:08 +00002273 vtysh_install_default (ISIS_NODE);
paul718e3742002-12-13 20:15:29 +00002274 vtysh_install_default (KEYCHAIN_NODE);
2275 vtysh_install_default (KEYCHAIN_KEY_NODE);
hassoe7168df2004-10-03 20:11:32 +00002276 vtysh_install_default (VTY_NODE);
paul718e3742002-12-13 20:15:29 +00002277
2278 install_element (VIEW_NODE, &vtysh_enable_cmd);
2279 install_element (ENABLE_NODE, &vtysh_config_terminal_cmd);
2280 install_element (ENABLE_NODE, &vtysh_disable_cmd);
2281
2282 /* "exit" command. */
2283 install_element (VIEW_NODE, &vtysh_exit_all_cmd);
2284 install_element (VIEW_NODE, &vtysh_quit_all_cmd);
2285 install_element (CONFIG_NODE, &vtysh_exit_all_cmd);
2286 /* install_element (CONFIG_NODE, &vtysh_quit_all_cmd); */
2287 install_element (ENABLE_NODE, &vtysh_exit_all_cmd);
2288 install_element (ENABLE_NODE, &vtysh_quit_all_cmd);
2289 install_element (RIP_NODE, &vtysh_exit_ripd_cmd);
2290 install_element (RIP_NODE, &vtysh_quit_ripd_cmd);
paul68980082003-03-25 05:07:42 +00002291 install_element (RIPNG_NODE, &vtysh_exit_ripngd_cmd);
2292 install_element (RIPNG_NODE, &vtysh_quit_ripngd_cmd);
paul718e3742002-12-13 20:15:29 +00002293 install_element (OSPF_NODE, &vtysh_exit_ospfd_cmd);
2294 install_element (OSPF_NODE, &vtysh_quit_ospfd_cmd);
paul68980082003-03-25 05:07:42 +00002295 install_element (OSPF6_NODE, &vtysh_exit_ospf6d_cmd);
2296 install_element (OSPF6_NODE, &vtysh_quit_ospf6d_cmd);
paul718e3742002-12-13 20:15:29 +00002297 install_element (BGP_NODE, &vtysh_exit_bgpd_cmd);
2298 install_element (BGP_NODE, &vtysh_quit_bgpd_cmd);
2299 install_element (BGP_VPNV4_NODE, &vtysh_exit_bgpd_cmd);
2300 install_element (BGP_VPNV4_NODE, &vtysh_quit_bgpd_cmd);
2301 install_element (BGP_IPV4_NODE, &vtysh_exit_bgpd_cmd);
2302 install_element (BGP_IPV4_NODE, &vtysh_quit_bgpd_cmd);
2303 install_element (BGP_IPV4M_NODE, &vtysh_exit_bgpd_cmd);
2304 install_element (BGP_IPV4M_NODE, &vtysh_quit_bgpd_cmd);
2305 install_element (BGP_IPV6_NODE, &vtysh_exit_bgpd_cmd);
2306 install_element (BGP_IPV6_NODE, &vtysh_quit_bgpd_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002307 install_element (BGP_IPV6M_NODE, &vtysh_exit_bgpd_cmd);
2308 install_element (BGP_IPV6M_NODE, &vtysh_quit_bgpd_cmd);
hassoc25e4582003-12-23 10:39:08 +00002309 install_element (ISIS_NODE, &vtysh_exit_isisd_cmd);
2310 install_element (ISIS_NODE, &vtysh_quit_isisd_cmd);
paul718e3742002-12-13 20:15:29 +00002311 install_element (KEYCHAIN_NODE, &vtysh_exit_ripd_cmd);
2312 install_element (KEYCHAIN_NODE, &vtysh_quit_ripd_cmd);
2313 install_element (KEYCHAIN_KEY_NODE, &vtysh_exit_ripd_cmd);
2314 install_element (KEYCHAIN_KEY_NODE, &vtysh_quit_ripd_cmd);
2315 install_element (RMAP_NODE, &vtysh_exit_rmap_cmd);
2316 install_element (RMAP_NODE, &vtysh_quit_rmap_cmd);
hassoe7168df2004-10-03 20:11:32 +00002317 install_element (VTY_NODE, &vtysh_exit_line_vty_cmd);
2318 install_element (VTY_NODE, &vtysh_quit_line_vty_cmd);
paul718e3742002-12-13 20:15:29 +00002319
2320 /* "end" command. */
2321 install_element (CONFIG_NODE, &vtysh_end_all_cmd);
2322 install_element (ENABLE_NODE, &vtysh_end_all_cmd);
2323 install_element (RIP_NODE, &vtysh_end_all_cmd);
2324 install_element (RIPNG_NODE, &vtysh_end_all_cmd);
2325 install_element (OSPF_NODE, &vtysh_end_all_cmd);
2326 install_element (OSPF6_NODE, &vtysh_end_all_cmd);
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +01002327 install_element (BABEL_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002328 install_element (BGP_NODE, &vtysh_end_all_cmd);
2329 install_element (BGP_IPV4_NODE, &vtysh_end_all_cmd);
2330 install_element (BGP_IPV4M_NODE, &vtysh_end_all_cmd);
2331 install_element (BGP_VPNV4_NODE, &vtysh_end_all_cmd);
2332 install_element (BGP_IPV6_NODE, &vtysh_end_all_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002333 install_element (BGP_IPV6M_NODE, &vtysh_end_all_cmd);
hassoc25e4582003-12-23 10:39:08 +00002334 install_element (ISIS_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002335 install_element (KEYCHAIN_NODE, &vtysh_end_all_cmd);
2336 install_element (KEYCHAIN_KEY_NODE, &vtysh_end_all_cmd);
2337 install_element (RMAP_NODE, &vtysh_end_all_cmd);
hassoe7168df2004-10-03 20:11:32 +00002338 install_element (VTY_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002339
paul338a9912003-03-01 15:44:10 +00002340 install_element (INTERFACE_NODE, &interface_desc_cmd);
paul464dc8d2003-03-28 02:25:45 +00002341 install_element (INTERFACE_NODE, &no_interface_desc_cmd);
paul718e3742002-12-13 20:15:29 +00002342 install_element (INTERFACE_NODE, &vtysh_end_all_cmd);
2343 install_element (INTERFACE_NODE, &vtysh_exit_interface_cmd);
2344 install_element (INTERFACE_NODE, &vtysh_quit_interface_cmd);
2345 install_element (CONFIG_NODE, &router_rip_cmd);
2346#ifdef HAVE_IPV6
2347 install_element (CONFIG_NODE, &router_ripng_cmd);
2348#endif
2349 install_element (CONFIG_NODE, &router_ospf_cmd);
2350#ifdef HAVE_IPV6
2351 install_element (CONFIG_NODE, &router_ospf6_cmd);
2352#endif
hassoc25e4582003-12-23 10:39:08 +00002353 install_element (CONFIG_NODE, &router_isis_cmd);
paul718e3742002-12-13 20:15:29 +00002354 install_element (CONFIG_NODE, &router_bgp_cmd);
Paul Jakma10895fd2008-07-03 19:34:48 +00002355 install_element (CONFIG_NODE, &router_bgp_view_cmd);
paul718e3742002-12-13 20:15:29 +00002356 install_element (BGP_NODE, &address_family_vpnv4_cmd);
2357 install_element (BGP_NODE, &address_family_vpnv4_unicast_cmd);
2358 install_element (BGP_NODE, &address_family_ipv4_unicast_cmd);
2359 install_element (BGP_NODE, &address_family_ipv4_multicast_cmd);
2360#ifdef HAVE_IPV6
2361 install_element (BGP_NODE, &address_family_ipv6_cmd);
2362 install_element (BGP_NODE, &address_family_ipv6_unicast_cmd);
2363#endif
2364 install_element (BGP_VPNV4_NODE, &exit_address_family_cmd);
2365 install_element (BGP_IPV4_NODE, &exit_address_family_cmd);
2366 install_element (BGP_IPV4M_NODE, &exit_address_family_cmd);
2367 install_element (BGP_IPV6_NODE, &exit_address_family_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002368 install_element (BGP_IPV6M_NODE, &exit_address_family_cmd);
paul718e3742002-12-13 20:15:29 +00002369 install_element (CONFIG_NODE, &key_chain_cmd);
2370 install_element (CONFIG_NODE, &route_map_cmd);
hassoe7168df2004-10-03 20:11:32 +00002371 install_element (CONFIG_NODE, &vtysh_line_vty_cmd);
paul718e3742002-12-13 20:15:29 +00002372 install_element (KEYCHAIN_NODE, &key_cmd);
2373 install_element (KEYCHAIN_NODE, &key_chain_cmd);
2374 install_element (KEYCHAIN_KEY_NODE, &key_chain_cmd);
2375 install_element (CONFIG_NODE, &vtysh_interface_cmd);
paul32d24632003-05-23 09:25:20 +00002376 install_element (CONFIG_NODE, &vtysh_no_interface_cmd);
paul718e3742002-12-13 20:15:29 +00002377 install_element (ENABLE_NODE, &vtysh_show_running_config_cmd);
2378 install_element (ENABLE_NODE, &vtysh_copy_runningconfig_startupconfig_cmd);
2379 install_element (ENABLE_NODE, &vtysh_write_file_cmd);
hasso4a6e2252003-05-25 11:51:29 +00002380 install_element (ENABLE_NODE, &vtysh_write_cmd);
paul718e3742002-12-13 20:15:29 +00002381
hasso95e735b2004-08-26 13:08:30 +00002382 /* "write terminal" command. */
paul718e3742002-12-13 20:15:29 +00002383 install_element (ENABLE_NODE, &vtysh_write_terminal_cmd);
hassoe7168df2004-10-03 20:11:32 +00002384
2385 install_element (CONFIG_NODE, &vtysh_integrated_config_cmd);
2386 install_element (CONFIG_NODE, &no_vtysh_integrated_config_cmd);
paul718e3742002-12-13 20:15:29 +00002387
hasso95e735b2004-08-26 13:08:30 +00002388 /* "write memory" command. */
paul718e3742002-12-13 20:15:29 +00002389 install_element (ENABLE_NODE, &vtysh_write_memory_cmd);
paul718e3742002-12-13 20:15:29 +00002390
hasso34553cc2004-08-27 13:56:39 +00002391 install_element (VIEW_NODE, &vtysh_terminal_length_cmd);
2392 install_element (ENABLE_NODE, &vtysh_terminal_length_cmd);
2393 install_element (VIEW_NODE, &vtysh_terminal_no_length_cmd);
2394 install_element (ENABLE_NODE, &vtysh_terminal_no_length_cmd);
hassof2799e62004-10-28 17:43:11 +00002395 install_element (VIEW_NODE, &vtysh_show_daemons_cmd);
2396 install_element (ENABLE_NODE, &vtysh_show_daemons_cmd);
hasso34553cc2004-08-27 13:56:39 +00002397
paul718e3742002-12-13 20:15:29 +00002398 install_element (VIEW_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002399 install_element (VIEW_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00002400 install_element (VIEW_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002401 install_element (VIEW_NODE, &vtysh_traceroute_ip_cmd);
2402#ifdef HAVE_IPV6
2403 install_element (VIEW_NODE, &vtysh_ping6_cmd);
2404 install_element (VIEW_NODE, &vtysh_traceroute6_cmd);
2405#endif
paul718e3742002-12-13 20:15:29 +00002406 install_element (VIEW_NODE, &vtysh_telnet_cmd);
2407 install_element (VIEW_NODE, &vtysh_telnet_port_cmd);
paul5087df52003-01-25 06:56:09 +00002408 install_element (VIEW_NODE, &vtysh_ssh_cmd);
paul718e3742002-12-13 20:15:29 +00002409 install_element (ENABLE_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002410 install_element (ENABLE_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00002411 install_element (ENABLE_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002412 install_element (ENABLE_NODE, &vtysh_traceroute_ip_cmd);
2413#ifdef HAVE_IPV6
2414 install_element (ENABLE_NODE, &vtysh_ping6_cmd);
2415 install_element (ENABLE_NODE, &vtysh_traceroute6_cmd);
2416#endif
paul718e3742002-12-13 20:15:29 +00002417 install_element (ENABLE_NODE, &vtysh_telnet_cmd);
2418 install_element (ENABLE_NODE, &vtysh_telnet_port_cmd);
hasso67e29ab2004-08-26 22:21:31 +00002419 install_element (ENABLE_NODE, &vtysh_ssh_cmd);
paul718e3742002-12-13 20:15:29 +00002420 install_element (ENABLE_NODE, &vtysh_start_shell_cmd);
2421 install_element (ENABLE_NODE, &vtysh_start_bash_cmd);
2422 install_element (ENABLE_NODE, &vtysh_start_zsh_cmd);
Paul Jakmadbf7d132006-05-23 22:10:01 +00002423
Paul Jakma362b4032006-05-28 07:54:45 +00002424 install_element (VIEW_NODE, &vtysh_show_memory_cmd);
2425 install_element (ENABLE_NODE, &vtysh_show_memory_cmd);
2426
Paul Jakmadbf7d132006-05-23 22:10:01 +00002427 /* Logging */
2428 install_element (ENABLE_NODE, &vtysh_show_logging_cmd);
2429 install_element (VIEW_NODE, &vtysh_show_logging_cmd);
paul718e3742002-12-13 20:15:29 +00002430 install_element (CONFIG_NODE, &vtysh_log_stdout_cmd);
ajs274a4a42004-12-07 15:39:31 +00002431 install_element (CONFIG_NODE, &vtysh_log_stdout_level_cmd);
paul718e3742002-12-13 20:15:29 +00002432 install_element (CONFIG_NODE, &no_vtysh_log_stdout_cmd);
2433 install_element (CONFIG_NODE, &vtysh_log_file_cmd);
ajs274a4a42004-12-07 15:39:31 +00002434 install_element (CONFIG_NODE, &vtysh_log_file_level_cmd);
paul718e3742002-12-13 20:15:29 +00002435 install_element (CONFIG_NODE, &no_vtysh_log_file_cmd);
ajs274a4a42004-12-07 15:39:31 +00002436 install_element (CONFIG_NODE, &no_vtysh_log_file_level_cmd);
2437 install_element (CONFIG_NODE, &vtysh_log_monitor_cmd);
2438 install_element (CONFIG_NODE, &vtysh_log_monitor_level_cmd);
2439 install_element (CONFIG_NODE, &no_vtysh_log_monitor_cmd);
paul718e3742002-12-13 20:15:29 +00002440 install_element (CONFIG_NODE, &vtysh_log_syslog_cmd);
ajs274a4a42004-12-07 15:39:31 +00002441 install_element (CONFIG_NODE, &vtysh_log_syslog_level_cmd);
paul718e3742002-12-13 20:15:29 +00002442 install_element (CONFIG_NODE, &no_vtysh_log_syslog_cmd);
2443 install_element (CONFIG_NODE, &vtysh_log_trap_cmd);
2444 install_element (CONFIG_NODE, &no_vtysh_log_trap_cmd);
ajs274a4a42004-12-07 15:39:31 +00002445 install_element (CONFIG_NODE, &vtysh_log_facility_cmd);
2446 install_element (CONFIG_NODE, &no_vtysh_log_facility_cmd);
paul718e3742002-12-13 20:15:29 +00002447 install_element (CONFIG_NODE, &vtysh_log_record_priority_cmd);
2448 install_element (CONFIG_NODE, &no_vtysh_log_record_priority_cmd);
Andrew J. Schorrc749b722007-04-29 03:53:31 +00002449 install_element (CONFIG_NODE, &vtysh_log_timestamp_precision_cmd);
2450 install_element (CONFIG_NODE, &no_vtysh_log_timestamp_precision_cmd);
hassoe7168df2004-10-03 20:11:32 +00002451
2452 install_element (CONFIG_NODE, &vtysh_service_password_encrypt_cmd);
2453 install_element (CONFIG_NODE, &no_vtysh_service_password_encrypt_cmd);
2454
2455 install_element (CONFIG_NODE, &vtysh_password_cmd);
2456 install_element (CONFIG_NODE, &vtysh_password_text_cmd);
2457 install_element (CONFIG_NODE, &vtysh_enable_password_cmd);
2458 install_element (CONFIG_NODE, &vtysh_enable_password_text_cmd);
2459 install_element (CONFIG_NODE, &no_vtysh_enable_password_cmd);
2460
paul718e3742002-12-13 20:15:29 +00002461}