blob: 2703bb99fa94b93dc08d1bfc401adc1143e2ec8d [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"
Feng Lu471ea392015-05-22 11:40:00 +020038#include "vrf.h"
paul718e3742002-12-13 20:15:29 +000039
40/* Struct VTY. */
41struct vty *vty;
42
43/* VTY shell pager name. */
44char *vtysh_pager_name = NULL;
45
46/* VTY shell client structure. */
47struct vtysh_client
48{
49 int fd;
ajsb1aa1472005-01-28 21:11:46 +000050 const char *name;
51 int flag;
52 const char *path;
53} vtysh_client[] =
54{
55 { .fd = -1, .name = "zebra", .flag = VTYSH_ZEBRA, .path = ZEBRA_VTYSH_PATH},
56 { .fd = -1, .name = "ripd", .flag = VTYSH_RIPD, .path = RIP_VTYSH_PATH},
57 { .fd = -1, .name = "ripngd", .flag = VTYSH_RIPNGD, .path = RIPNG_VTYSH_PATH},
58 { .fd = -1, .name = "ospfd", .flag = VTYSH_OSPFD, .path = OSPF_VTYSH_PATH},
59 { .fd = -1, .name = "ospf6d", .flag = VTYSH_OSPF6D, .path = OSPF6_VTYSH_PATH},
60 { .fd = -1, .name = "bgpd", .flag = VTYSH_BGPD, .path = BGP_VTYSH_PATH},
61 { .fd = -1, .name = "isisd", .flag = VTYSH_ISISD, .path = ISIS_VTYSH_PATH},
Leonard Herve596470f2009-08-11 15:45:26 -030062 { .fd = -1, .name = "pimd", .flag = VTYSH_PIMD, .path = PIM_VTYSH_PATH},
ajsb1aa1472005-01-28 21:11:46 +000063};
64
ajsb1aa1472005-01-28 21:11:46 +000065
66/* We need direct access to ripd to implement vtysh_exit_ripd_only. */
67static struct vtysh_client *ripd_client = NULL;
68
hassob094d262004-08-25 12:22:00 +000069
hassoe7168df2004-10-03 20:11:32 +000070/* Using integrated config from Quagga.conf. Default is no. */
71int vtysh_writeconfig_integrated = 0;
72
73extern char config_default[];
74
ajs274a4a42004-12-07 15:39:31 +000075static void
paul718e3742002-12-13 20:15:29 +000076vclient_close (struct vtysh_client *vclient)
77{
ajsb1aa1472005-01-28 21:11:46 +000078 if (vclient->fd >= 0)
79 {
80 fprintf(stderr,
81 "Warning: closing connection to %s because of an I/O error!\n",
82 vclient->name);
83 close (vclient->fd);
84 vclient->fd = -1;
85 }
paul718e3742002-12-13 20:15:29 +000086}
87
paul718e3742002-12-13 20:15:29 +000088/* Following filled with debug code to trace a problematic condition
hasso95e735b2004-08-26 13:08:30 +000089 * under load - it SHOULD handle it. */
Gautam Kumarcc216b72015-10-26 13:22:12 -070090#define ERR_WHERE_STRING "vtysh(): vtysh_client_execute(): "
ajs274a4a42004-12-07 15:39:31 +000091static int
Gautam Kumarcc216b72015-10-26 13:22:12 -070092vtysh_client_execute (struct vtysh_client *vclient, const char *line, FILE *fp)
paul718e3742002-12-13 20:15:29 +000093{
94 int ret;
95 char *buf;
96 size_t bufsz;
97 char *pbuf;
98 size_t left;
99 char *eoln;
100 int nbytes;
101 int i;
102 int readln;
Gautam Kumarcc216b72015-10-26 13:22:12 -0700103 int numnulls = 0;
paul718e3742002-12-13 20:15:29 +0000104
105 if (vclient->fd < 0)
106 return CMD_SUCCESS;
107
108 ret = write (vclient->fd, line, strlen (line) + 1);
109 if (ret <= 0)
110 {
111 vclient_close (vclient);
112 return CMD_SUCCESS;
113 }
114
hasso95e735b2004-08-26 13:08:30 +0000115 /* Allow enough room for buffer to read more than a few pages from socket. */
paule3d29b52003-01-23 18:05:42 +0000116 bufsz = 5 * getpagesize() + 1;
paul718e3742002-12-13 20:15:29 +0000117 buf = XMALLOC(MTYPE_TMP, bufsz);
118 memset(buf, 0, bufsz);
119 pbuf = buf;
120
121 while (1)
122 {
123 if (pbuf >= ((buf + bufsz) -1))
124 {
125 fprintf (stderr, ERR_WHERE_STRING \
126 "warning - pbuf beyond buffer end.\n");
127 return CMD_WARNING;
128 }
129
130 readln = (buf + bufsz) - pbuf - 1;
131 nbytes = read (vclient->fd, pbuf, readln);
132
133 if (nbytes <= 0)
134 {
135
136 if (errno == EINTR)
137 continue;
138
139 fprintf(stderr, ERR_WHERE_STRING "(%u)", errno);
140 perror("");
141
142 if (errno == EAGAIN || errno == EIO)
143 continue;
144
145 vclient_close (vclient);
146 XFREE(MTYPE_TMP, buf);
147 return CMD_SUCCESS;
148 }
Gautam Kumarcc216b72015-10-26 13:22:12 -0700149 /* If we have already seen 3 nulls, then current byte is ret code */
150 if ((numnulls == 3) && (nbytes == 1))
151 {
152 ret = pbuf[0];
153 break;
154 }
paul718e3742002-12-13 20:15:29 +0000155
156 pbuf[nbytes] = '\0';
157
Gautam Kumarcc216b72015-10-26 13:22:12 -0700158 /* If the config needs to be written in file or stdout */
159 if (fp)
160 {
161 fputs(pbuf, fp);
162 fflush (fp);
163 }
paul718e3742002-12-13 20:15:29 +0000164
Gautam Kumarcc216b72015-10-26 13:22:12 -0700165 /* At max look last four bytes */
166 if (nbytes >= 4)
167 {
168 i = nbytes - 4;
169 numnulls = 0;
170 }
171 else
172 i = 0;
paul718e3742002-12-13 20:15:29 +0000173
Gautam Kumarcc216b72015-10-26 13:22:12 -0700174 /* Count the numnulls */
175 while (i < nbytes && numnulls <3)
176 {
177 if (pbuf[i++] == '\0')
178 numnulls++;
179 else
180 numnulls = 0;
181 }
182 /* We might have seen 3 consecutive nulls so store the ret code before updating pbuf*/
183 ret = pbuf[nbytes-1];
184 pbuf += nbytes;
paul718e3742002-12-13 20:15:29 +0000185
Gautam Kumarcc216b72015-10-26 13:22:12 -0700186 /* See if a line exists in buffer, if so parse and consume it, and
187 * reset read position. If 3 nulls has been encountered consume the buffer before
188 * next read.
189 */
190 if (((eoln = strrchr(buf, '\n')) == NULL) && (numnulls<3))
191 continue;
192
193 if (eoln >= ((buf + bufsz) - 1))
194 {
195 fprintf (stderr, ERR_WHERE_STRING \
196 "warning - eoln beyond buffer end.\n");
197 }
198
199 /* If the config needs parsing, consume it */
200 if(!fp)
201 vtysh_config_parse(buf);
202
203 eoln++;
204 left = (size_t)(buf + bufsz - eoln);
205 /*
206 * This check is required since when a config line split between two consecutive reads,
207 * then buf will have first half of config line and current read will bring rest of the
208 * line. So in this case eoln will be 1 here, hence calculation of left will be wrong.
209 * In this case we don't need to do memmove, because we have already seen 3 nulls.
210 */
211 if(left < bufsz)
212 memmove(buf, eoln, left);
213
214 buf[bufsz-1] = '\0';
215 pbuf = buf + strlen(buf);
216 /* got 3 or more trailing NULs? */
217 if ((numnulls >=3) && (i < nbytes))
218 {
219 break;
220 }
paul718e3742002-12-13 20:15:29 +0000221 }
222
Gautam Kumarcc216b72015-10-26 13:22:12 -0700223 if(!fp)
224 vtysh_config_parse (buf);
paul718e3742002-12-13 20:15:29 +0000225
226 XFREE(MTYPE_TMP, buf);
227 return ret;
228}
Gautam Kumarcc216b72015-10-26 13:22:12 -0700229
paul718e3742002-12-13 20:15:29 +0000230
paul718e3742002-12-13 20:15:29 +0000231void
ajsb1aa1472005-01-28 21:11:46 +0000232vtysh_pager_init (void)
paul718e3742002-12-13 20:15:29 +0000233{
hasso5a9c53d2004-08-27 14:23:28 +0000234 char *pager_defined;
235
236 pager_defined = getenv ("VTYSH_PAGER");
237
238 if (pager_defined)
239 vtysh_pager_name = strdup (pager_defined);
240 else
hasso34553cc2004-08-27 13:56:39 +0000241 vtysh_pager_name = strdup ("more");
paul718e3742002-12-13 20:15:29 +0000242}
243
244/* Command execution over the vty interface. */
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700245static int
hassodda09522004-10-07 21:40:25 +0000246vtysh_execute_func (const char *line, int pager)
paul718e3742002-12-13 20:15:29 +0000247{
Stephen Hemminger2c4d48b2008-07-28 15:04:56 -0700248 int ret, cmd_stat;
ajsb1aa1472005-01-28 21:11:46 +0000249 u_int i;
paul718e3742002-12-13 20:15:29 +0000250 vector vline;
251 struct cmd_element *cmd;
252 FILE *fp = NULL;
hasso13bfca72005-01-23 21:42:25 +0000253 int closepager = 0;
254 int tried = 0;
255 int saved_ret, saved_node;
paul718e3742002-12-13 20:15:29 +0000256
hasso95e735b2004-08-26 13:08:30 +0000257 /* Split readline string up into the vector. */
paul718e3742002-12-13 20:15:29 +0000258 vline = cmd_make_strvec (line);
259
260 if (vline == NULL)
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700261 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000262
hasso13bfca72005-01-23 21:42:25 +0000263 saved_ret = ret = cmd_execute_command (vline, vty, &cmd, 1);
264 saved_node = vty->node;
265
266 /* If command doesn't succeeded in current node, try to walk up in node tree.
267 * Changing vty->node is enough to try it just out without actual walkup in
268 * the vtysh. */
269 while (ret != CMD_SUCCESS && ret != CMD_SUCCESS_DAEMON && ret != CMD_WARNING
270 && vty->node > CONFIG_NODE)
271 {
272 vty->node = node_parent(vty->node);
273 ret = cmd_execute_command (vline, vty, &cmd, 1);
274 tried++;
275 }
276
277 vty->node = saved_node;
278
279 /* If command succeeded in any other node than current (tried > 0) we have
280 * to move into node in the vtysh where it succeeded. */
281 if (ret == CMD_SUCCESS || ret == CMD_SUCCESS_DAEMON || ret == CMD_WARNING)
282 {
283 if ((saved_node == BGP_VPNV4_NODE || saved_node == BGP_IPV4_NODE
paul57b5b7e2005-08-22 22:44:29 +0000284 || saved_node == BGP_IPV6_NODE || saved_node == BGP_IPV4M_NODE
285 || saved_node == BGP_IPV6M_NODE)
hasso13bfca72005-01-23 21:42:25 +0000286 && (tried == 1))
287 {
288 vtysh_execute("exit-address-family");
289 }
290 else if ((saved_node == KEYCHAIN_KEY_NODE) && (tried == 1))
291 {
292 vtysh_execute("exit");
293 }
294 else if (tried)
295 {
296 vtysh_execute ("end");
297 vtysh_execute ("configure terminal");
298 }
299 }
300 /* If command didn't succeed in any node, continue with return value from
301 * first try. */
302 else if (tried)
303 {
304 ret = saved_ret;
305 }
paul718e3742002-12-13 20:15:29 +0000306
307 cmd_free_strvec (vline);
308
Stephen Hemminger2c4d48b2008-07-28 15:04:56 -0700309 cmd_stat = ret;
paul718e3742002-12-13 20:15:29 +0000310 switch (ret)
311 {
312 case CMD_WARNING:
313 if (vty->type == VTY_FILE)
paul4fc01e62002-12-13 20:49:00 +0000314 fprintf (stdout,"Warning...\n");
paul718e3742002-12-13 20:15:29 +0000315 break;
316 case CMD_ERR_AMBIGUOUS:
paul4fc01e62002-12-13 20:49:00 +0000317 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000318 break;
319 case CMD_ERR_NO_MATCH:
paul4fc01e62002-12-13 20:49:00 +0000320 fprintf (stdout,"%% Unknown command.\n");
paul718e3742002-12-13 20:15:29 +0000321 break;
322 case CMD_ERR_INCOMPLETE:
paul4fc01e62002-12-13 20:49:00 +0000323 fprintf (stdout,"%% Command incomplete.\n");
paul718e3742002-12-13 20:15:29 +0000324 break;
325 case CMD_SUCCESS_DAEMON:
326 {
hasso97b7db22004-10-20 19:07:48 +0000327 /* FIXME: Don't open pager for exit commands. popen() causes problems
328 * if exited from vtysh at all. This hack shouldn't cause any problem
329 * but is really ugly. */
330 if (pager && vtysh_pager_name && (strncmp(line, "exit", 4) != 0))
paul718e3742002-12-13 20:15:29 +0000331 {
paul4fc01e62002-12-13 20:49:00 +0000332 fp = popen (vtysh_pager_name, "w");
paul718e3742002-12-13 20:15:29 +0000333 if (fp == NULL)
334 {
paula805cc22003-05-01 14:29:48 +0000335 perror ("popen failed for pager");
336 fp = stdout;
paul718e3742002-12-13 20:15:29 +0000337 }
paula805cc22003-05-01 14:29:48 +0000338 else
339 closepager=1;
paul718e3742002-12-13 20:15:29 +0000340 }
341 else
342 fp = stdout;
343
344 if (! strcmp(cmd->string,"configure terminal"))
345 {
Balaji.G837d16c2012-09-26 14:09:10 +0530346 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +0000347 {
348 cmd_stat = vtysh_client_execute(&vtysh_client[i], line, fp);
349 if (cmd_stat == CMD_WARNING)
350 break;
351 }
352
paul718e3742002-12-13 20:15:29 +0000353 if (cmd_stat)
354 {
hassob094d262004-08-25 12:22:00 +0000355 line = "end";
356 vline = cmd_make_strvec (line);
paul718e3742002-12-13 20:15:29 +0000357
hassob094d262004-08-25 12:22:00 +0000358 if (vline == NULL)
paul718e3742002-12-13 20:15:29 +0000359 {
paula805cc22003-05-01 14:29:48 +0000360 if (pager && vtysh_pager_name && fp && closepager)
paul718e3742002-12-13 20:15:29 +0000361 {
362 if (pclose (fp) == -1)
363 {
paula805cc22003-05-01 14:29:48 +0000364 perror ("pclose failed for pager");
paul718e3742002-12-13 20:15:29 +0000365 }
366 fp = NULL;
367 }
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700368 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000369 }
370
hasso87d683b2005-01-16 23:31:54 +0000371 ret = cmd_execute_command (vline, vty, &cmd, 1);
hassob094d262004-08-25 12:22:00 +0000372 cmd_free_strvec (vline);
373 if (ret != CMD_SUCCESS_DAEMON)
374 break;
paul718e3742002-12-13 20:15:29 +0000375 }
376 else
377 if (cmd->func)
378 {
379 (*cmd->func) (cmd, vty, 0, NULL);
380 break;
hassob094d262004-08-25 12:22:00 +0000381 }
paul718e3742002-12-13 20:15:29 +0000382 }
383
ajsb1aa1472005-01-28 21:11:46 +0000384 cmd_stat = CMD_SUCCESS;
Balaji.G837d16c2012-09-26 14:09:10 +0530385 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +0000386 {
387 if (cmd->daemon & vtysh_client[i].flag)
388 {
389 cmd_stat = vtysh_client_execute(&vtysh_client[i], line, fp);
390 if (cmd_stat != CMD_SUCCESS)
391 break;
392 }
393 }
394 if (cmd_stat != CMD_SUCCESS)
395 break;
396
paul718e3742002-12-13 20:15:29 +0000397 if (cmd->func)
398 (*cmd->func) (cmd, vty, 0, NULL);
399 }
400 }
paula805cc22003-05-01 14:29:48 +0000401 if (pager && vtysh_pager_name && fp && closepager)
paul718e3742002-12-13 20:15:29 +0000402 {
403 if (pclose (fp) == -1)
404 {
paula805cc22003-05-01 14:29:48 +0000405 perror ("pclose failed for pager");
paul718e3742002-12-13 20:15:29 +0000406 }
407 fp = NULL;
408 }
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700409 return cmd_stat;
paul718e3742002-12-13 20:15:29 +0000410}
411
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700412int
hassodda09522004-10-07 21:40:25 +0000413vtysh_execute_no_pager (const char *line)
paul718e3742002-12-13 20:15:29 +0000414{
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700415 return vtysh_execute_func (line, 0);
paul718e3742002-12-13 20:15:29 +0000416}
417
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700418int
hassodda09522004-10-07 21:40:25 +0000419vtysh_execute (const char *line)
paul718e3742002-12-13 20:15:29 +0000420{
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700421 return vtysh_execute_func (line, 1);
paul718e3742002-12-13 20:15:29 +0000422}
423
424/* Configration make from file. */
425int
426vtysh_config_from_file (struct vty *vty, FILE *fp)
427{
428 int ret;
paul718e3742002-12-13 20:15:29 +0000429 struct cmd_element *cmd;
430
431 while (fgets (vty->buf, VTY_BUFSIZ, fp))
432 {
Donald Sharpd8aa4be2015-09-28 20:10:40 -0400433 ret = command_config_read_one_line (vty, &cmd, 1);
paul718e3742002-12-13 20:15:29 +0000434
435 switch (ret)
436 {
437 case CMD_WARNING:
438 if (vty->type == VTY_FILE)
paul4fc01e62002-12-13 20:49:00 +0000439 fprintf (stdout,"Warning...\n");
paul718e3742002-12-13 20:15:29 +0000440 break;
441 case CMD_ERR_AMBIGUOUS:
paul4fc01e62002-12-13 20:49:00 +0000442 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000443 break;
444 case CMD_ERR_NO_MATCH:
paul4fc01e62002-12-13 20:49:00 +0000445 fprintf (stdout,"%% Unknown command: %s", vty->buf);
paul718e3742002-12-13 20:15:29 +0000446 break;
447 case CMD_ERR_INCOMPLETE:
paul4fc01e62002-12-13 20:49:00 +0000448 fprintf (stdout,"%% Command incomplete.\n");
paul718e3742002-12-13 20:15:29 +0000449 break;
450 case CMD_SUCCESS_DAEMON:
451 {
ajsb1aa1472005-01-28 21:11:46 +0000452 u_int i;
453 int cmd_stat = CMD_SUCCESS;
454
Balaji.G837d16c2012-09-26 14:09:10 +0530455 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +0000456 {
paul44316fe2006-01-11 01:38:25 +0000457 if (cmd->daemon & vtysh_client[i].flag)
ajsb1aa1472005-01-28 21:11:46 +0000458 {
459 cmd_stat = vtysh_client_execute (&vtysh_client[i],
460 vty->buf, stdout);
461 if (cmd_stat != CMD_SUCCESS)
462 break;
463 }
464 }
465 if (cmd_stat != CMD_SUCCESS)
466 break;
467
paul718e3742002-12-13 20:15:29 +0000468 if (cmd->func)
469 (*cmd->func) (cmd, vty, 0, NULL);
470 }
471 }
472 }
473 return CMD_SUCCESS;
474}
475
476/* We don't care about the point of the cursor when '?' is typed. */
David Lampartera9eb9062015-03-04 07:07:01 +0100477static int
ajsb1aa1472005-01-28 21:11:46 +0000478vtysh_rl_describe (void)
paul718e3742002-12-13 20:15:29 +0000479{
480 int ret;
hassodda09522004-10-07 21:40:25 +0000481 unsigned int i;
paul718e3742002-12-13 20:15:29 +0000482 vector vline;
483 vector describe;
484 int width;
Christian Frankecd40b322013-09-30 12:27:51 +0000485 struct cmd_token *token;
paul718e3742002-12-13 20:15:29 +0000486
487 vline = cmd_make_strvec (rl_line_buffer);
488
489 /* In case of '> ?'. */
490 if (vline == NULL)
491 {
492 vline = vector_init (1);
David Lampartera91a3ba2015-03-03 09:06:51 +0100493 vector_set (vline, NULL);
paul718e3742002-12-13 20:15:29 +0000494 }
495 else
496 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
David Lampartera91a3ba2015-03-03 09:06:51 +0100497 vector_set (vline, NULL);
paul718e3742002-12-13 20:15:29 +0000498
499 describe = cmd_describe_command (vline, vty, &ret);
500
paul4fc01e62002-12-13 20:49:00 +0000501 fprintf (stdout,"\n");
paul718e3742002-12-13 20:15:29 +0000502
503 /* Ambiguous and no match error. */
504 switch (ret)
505 {
506 case CMD_ERR_AMBIGUOUS:
507 cmd_free_strvec (vline);
paul4fc01e62002-12-13 20:49:00 +0000508 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000509 rl_on_new_line ();
510 return 0;
511 break;
512 case CMD_ERR_NO_MATCH:
513 cmd_free_strvec (vline);
paul4fc01e62002-12-13 20:49:00 +0000514 fprintf (stdout,"%% There is no matched command.\n");
paul718e3742002-12-13 20:15:29 +0000515 rl_on_new_line ();
516 return 0;
517 break;
518 }
519
520 /* Get width of command string. */
521 width = 0;
paul55468c82005-03-14 20:19:01 +0000522 for (i = 0; i < vector_active (describe); i++)
Christian Frankecd40b322013-09-30 12:27:51 +0000523 if ((token = vector_slot (describe, i)) != NULL)
paul718e3742002-12-13 20:15:29 +0000524 {
525 int len;
526
Christian Frankecd40b322013-09-30 12:27:51 +0000527 if (token->cmd[0] == '\0')
paul718e3742002-12-13 20:15:29 +0000528 continue;
529
Christian Frankecd40b322013-09-30 12:27:51 +0000530 len = strlen (token->cmd);
531 if (token->cmd[0] == '.')
paul718e3742002-12-13 20:15:29 +0000532 len--;
533
534 if (width < len)
535 width = len;
536 }
537
paul55468c82005-03-14 20:19:01 +0000538 for (i = 0; i < vector_active (describe); i++)
Christian Frankecd40b322013-09-30 12:27:51 +0000539 if ((token = vector_slot (describe, i)) != NULL)
paul718e3742002-12-13 20:15:29 +0000540 {
Christian Frankecd40b322013-09-30 12:27:51 +0000541 if (token->cmd[0] == '\0')
paul718e3742002-12-13 20:15:29 +0000542 continue;
543
Christian Frankecd40b322013-09-30 12:27:51 +0000544 if (! token->desc)
paul4fc01e62002-12-13 20:49:00 +0000545 fprintf (stdout," %-s\n",
Christian Frankecd40b322013-09-30 12:27:51 +0000546 token->cmd[0] == '.' ? token->cmd + 1 : token->cmd);
paul718e3742002-12-13 20:15:29 +0000547 else
paul4fc01e62002-12-13 20:49:00 +0000548 fprintf (stdout," %-*s %s\n",
hassob094d262004-08-25 12:22:00 +0000549 width,
Christian Frankecd40b322013-09-30 12:27:51 +0000550 token->cmd[0] == '.' ? token->cmd + 1 : token->cmd,
551 token->desc);
paul718e3742002-12-13 20:15:29 +0000552 }
553
554 cmd_free_strvec (vline);
555 vector_free (describe);
556
557 rl_on_new_line();
558
559 return 0;
560}
561
hasso95e735b2004-08-26 13:08:30 +0000562/* Result of cmd_complete_command() call will be stored here
563 * and used in new_completion() in order to put the space in
564 * correct places only. */
paul718e3742002-12-13 20:15:29 +0000565int complete_status;
566
ajs274a4a42004-12-07 15:39:31 +0000567static char *
pauldfc0d9b2003-04-18 23:55:29 +0000568command_generator (const char *text, int state)
paul718e3742002-12-13 20:15:29 +0000569{
570 vector vline;
571 static char **matched = NULL;
572 static int index = 0;
573
574 /* First call. */
575 if (! state)
576 {
577 index = 0;
578
579 if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
580 return NULL;
581
582 vline = cmd_make_strvec (rl_line_buffer);
583 if (vline == NULL)
584 return NULL;
585
586 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
David Lampartera91a3ba2015-03-03 09:06:51 +0100587 vector_set (vline, NULL);
paul718e3742002-12-13 20:15:29 +0000588
589 matched = cmd_complete_command (vline, vty, &complete_status);
590 }
591
592 if (matched && matched[index])
593 return matched[index++];
594
595 return NULL;
596}
597
ajs274a4a42004-12-07 15:39:31 +0000598static char **
paul718e3742002-12-13 20:15:29 +0000599new_completion (char *text, int start, int end)
600{
601 char **matches;
602
pauldfc0d9b2003-04-18 23:55:29 +0000603 matches = rl_completion_matches (text, command_generator);
paul718e3742002-12-13 20:15:29 +0000604
605 if (matches)
606 {
607 rl_point = rl_end;
Christian Franke67e7a212013-03-04 09:23:30 +0000608 if (complete_status != CMD_COMPLETE_FULL_MATCH)
609 /* only append a space on full match */
610 rl_completion_append_character = '\0';
paul718e3742002-12-13 20:15:29 +0000611 }
612
613 return matches;
614}
615
ajs274a4a42004-12-07 15:39:31 +0000616#if 0
617/* This function is not actually being used. */
618static char **
paul718e3742002-12-13 20:15:29 +0000619vtysh_completion (char *text, int start, int end)
620{
621 int ret;
622 vector vline;
623 char **matched = NULL;
624
625 if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
626 return NULL;
627
628 vline = cmd_make_strvec (rl_line_buffer);
629 if (vline == NULL)
630 return NULL;
631
632 /* In case of 'help \t'. */
633 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
634 vector_set (vline, '\0');
635
636 matched = cmd_complete_command (vline, vty, &ret);
637
638 cmd_free_strvec (vline);
639
640 return (char **) matched;
641}
ajs274a4a42004-12-07 15:39:31 +0000642#endif
paul718e3742002-12-13 20:15:29 +0000643
hasso95e735b2004-08-26 13:08:30 +0000644/* Vty node structures. */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800645static struct cmd_node bgp_node =
paul718e3742002-12-13 20:15:29 +0000646{
647 BGP_NODE,
648 "%s(config-router)# ",
649};
650
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800651static struct cmd_node rip_node =
paul718e3742002-12-13 20:15:29 +0000652{
653 RIP_NODE,
654 "%s(config-router)# ",
655};
656
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800657static struct cmd_node isis_node =
hassoc25e4582003-12-23 10:39:08 +0000658{
659 ISIS_NODE,
660 "%s(config-router)# ",
hassoc25e4582003-12-23 10:39:08 +0000661};
662
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800663static struct cmd_node interface_node =
paul718e3742002-12-13 20:15:29 +0000664{
665 INTERFACE_NODE,
666 "%s(config-if)# ",
667};
668
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800669static struct cmd_node rmap_node =
hasso95e735b2004-08-26 13:08:30 +0000670{
671 RMAP_NODE,
672 "%s(config-route-map)# "
673};
674
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800675static struct cmd_node zebra_node =
hasso95e735b2004-08-26 13:08:30 +0000676{
677 ZEBRA_NODE,
678 "%s(config-router)# "
679};
680
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800681static struct cmd_node bgp_vpnv4_node =
hasso95e735b2004-08-26 13:08:30 +0000682{
683 BGP_VPNV4_NODE,
684 "%s(config-router-af)# "
685};
686
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800687static struct cmd_node bgp_ipv4_node =
hasso95e735b2004-08-26 13:08:30 +0000688{
689 BGP_IPV4_NODE,
690 "%s(config-router-af)# "
691};
692
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800693static struct cmd_node bgp_ipv4m_node =
hasso95e735b2004-08-26 13:08:30 +0000694{
695 BGP_IPV4M_NODE,
696 "%s(config-router-af)# "
697};
698
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800699static struct cmd_node bgp_ipv6_node =
hasso95e735b2004-08-26 13:08:30 +0000700{
701 BGP_IPV6_NODE,
702 "%s(config-router-af)# "
703};
704
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800705static struct cmd_node bgp_ipv6m_node =
paul57b5b7e2005-08-22 22:44:29 +0000706{
707 BGP_IPV6M_NODE,
708 "%s(config-router-af)# "
709};
710
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800711static struct cmd_node ospf_node =
hasso95e735b2004-08-26 13:08:30 +0000712{
713 OSPF_NODE,
714 "%s(config-router)# "
715};
716
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800717static struct cmd_node ripng_node =
hasso95e735b2004-08-26 13:08:30 +0000718{
719 RIPNG_NODE,
720 "%s(config-router)# "
721};
722
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800723static struct cmd_node ospf6_node =
hasso95e735b2004-08-26 13:08:30 +0000724{
725 OSPF6_NODE,
726 "%s(config-ospf6)# "
727};
728
David Lamparteree53c8b2015-05-23 05:45:59 +0200729static struct cmd_node babel_node =
730{
731 BABEL_NODE,
732 "%s(config-babel)# "
733};
734
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800735static struct cmd_node keychain_node =
hasso95e735b2004-08-26 13:08:30 +0000736{
737 KEYCHAIN_NODE,
738 "%s(config-keychain)# "
739};
740
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800741static struct cmd_node keychain_key_node =
hasso95e735b2004-08-26 13:08:30 +0000742{
743 KEYCHAIN_KEY_NODE,
744 "%s(config-keychain-key)# "
745};
746
hassoe7168df2004-10-03 20:11:32 +0000747/* Defined in lib/vty.c */
748extern struct cmd_node vty_node;
749
hasso95e735b2004-08-26 13:08:30 +0000750/* When '^Z' is received from vty, move down to the enable mode. */
David Lampartera9eb9062015-03-04 07:07:01 +0100751static int
ajsb1aa1472005-01-28 21:11:46 +0000752vtysh_end (void)
hasso95e735b2004-08-26 13:08:30 +0000753{
754 switch (vty->node)
755 {
756 case VIEW_NODE:
757 case ENABLE_NODE:
758 /* Nothing to do. */
759 break;
760 default:
761 vty->node = ENABLE_NODE;
762 break;
763 }
764 return CMD_SUCCESS;
765}
766
767DEFUNSH (VTYSH_ALL,
768 vtysh_end_all,
769 vtysh_end_all_cmd,
770 "end",
hassoe7168df2004-10-03 20:11:32 +0000771 "End current mode and change to enable mode\n")
hasso95e735b2004-08-26 13:08:30 +0000772{
hasso42895462004-09-26 16:25:07 +0000773 return vtysh_end ();
hasso95e735b2004-08-26 13:08:30 +0000774}
775
paul718e3742002-12-13 20:15:29 +0000776DEFUNSH (VTYSH_BGPD,
777 router_bgp,
778 router_bgp_cmd,
Paul Jakma320da872008-07-02 13:40:33 +0000779 "router bgp " CMD_AS_RANGE,
paul718e3742002-12-13 20:15:29 +0000780 ROUTER_STR
781 BGP_STR
782 AS_STR)
783{
784 vty->node = BGP_NODE;
785 return CMD_SUCCESS;
786}
787
Paul Jakma10895fd2008-07-03 19:34:48 +0000788ALIAS_SH (VTYSH_BGPD,
789 router_bgp,
790 router_bgp_view_cmd,
791 "router bgp " CMD_AS_RANGE " view WORD",
792 ROUTER_STR
793 BGP_STR
794 AS_STR
795 "BGP view\n"
796 "view name\n")
797
paul718e3742002-12-13 20:15:29 +0000798DEFUNSH (VTYSH_BGPD,
799 address_family_vpnv4,
800 address_family_vpnv4_cmd,
801 "address-family vpnv4",
802 "Enter Address Family command mode\n"
803 "Address family\n")
804{
805 vty->node = BGP_VPNV4_NODE;
806 return CMD_SUCCESS;
807}
808
809DEFUNSH (VTYSH_BGPD,
810 address_family_vpnv4_unicast,
811 address_family_vpnv4_unicast_cmd,
812 "address-family vpnv4 unicast",
813 "Enter Address Family command mode\n"
814 "Address family\n"
815 "Address Family Modifier\n")
816{
817 vty->node = BGP_VPNV4_NODE;
818 return CMD_SUCCESS;
819}
820
821DEFUNSH (VTYSH_BGPD,
822 address_family_ipv4_unicast,
823 address_family_ipv4_unicast_cmd,
824 "address-family ipv4 unicast",
825 "Enter Address Family command mode\n"
826 "Address family\n"
827 "Address Family Modifier\n")
828{
829 vty->node = BGP_IPV4_NODE;
830 return CMD_SUCCESS;
831}
832
833DEFUNSH (VTYSH_BGPD,
834 address_family_ipv4_multicast,
835 address_family_ipv4_multicast_cmd,
836 "address-family ipv4 multicast",
837 "Enter Address Family command mode\n"
838 "Address family\n"
839 "Address Family Modifier\n")
840{
841 vty->node = BGP_IPV4M_NODE;
842 return CMD_SUCCESS;
843}
844
845DEFUNSH (VTYSH_BGPD,
846 address_family_ipv6,
847 address_family_ipv6_cmd,
848 "address-family ipv6",
849 "Enter Address Family command mode\n"
850 "Address family\n")
851{
852 vty->node = BGP_IPV6_NODE;
853 return CMD_SUCCESS;
854}
855
856DEFUNSH (VTYSH_BGPD,
857 address_family_ipv6_unicast,
858 address_family_ipv6_unicast_cmd,
859 "address-family ipv6 unicast",
860 "Enter Address Family command mode\n"
861 "Address family\n"
862 "Address Family Modifier\n")
863{
864 vty->node = BGP_IPV6_NODE;
865 return CMD_SUCCESS;
866}
867
paul57b5b7e2005-08-22 22:44:29 +0000868DEFUNSH (VTYSH_BGPD,
869 address_family_ipv6_multicast,
870 address_family_ipv6_multicast_cmd,
871 "address-family ipv6 multicast",
872 "Enter Address Family command mode\n"
873 "Address family\n"
874 "Address Family Modifier\n")
875{
876 vty->node = BGP_IPV6M_NODE;
877 return CMD_SUCCESS;
878}
879
paul718e3742002-12-13 20:15:29 +0000880DEFUNSH (VTYSH_RIPD,
881 key_chain,
882 key_chain_cmd,
883 "key chain WORD",
884 "Authentication key management\n"
885 "Key-chain management\n"
886 "Key-chain name\n")
887{
888 vty->node = KEYCHAIN_NODE;
889 return CMD_SUCCESS;
890}
891
892DEFUNSH (VTYSH_RIPD,
893 key,
894 key_cmd,
895 "key <0-2147483647>",
896 "Configure a key\n"
897 "Key identifier number\n")
898{
899 vty->node = KEYCHAIN_KEY_NODE;
900 return CMD_SUCCESS;
901}
902
903DEFUNSH (VTYSH_RIPD,
904 router_rip,
905 router_rip_cmd,
906 "router rip",
907 ROUTER_STR
908 "RIP")
909{
910 vty->node = RIP_NODE;
911 return CMD_SUCCESS;
912}
913
914DEFUNSH (VTYSH_RIPNGD,
915 router_ripng,
916 router_ripng_cmd,
917 "router ripng",
918 ROUTER_STR
919 "RIPng")
920{
921 vty->node = RIPNG_NODE;
922 return CMD_SUCCESS;
923}
924
925DEFUNSH (VTYSH_OSPFD,
926 router_ospf,
927 router_ospf_cmd,
928 "router ospf",
929 "Enable a routing process\n"
930 "Start OSPF configuration\n")
931{
932 vty->node = OSPF_NODE;
933 return CMD_SUCCESS;
934}
935
936DEFUNSH (VTYSH_OSPF6D,
937 router_ospf6,
938 router_ospf6_cmd,
939 "router ospf6",
940 OSPF6_ROUTER_STR
941 OSPF6_STR)
942{
943 vty->node = OSPF6_NODE;
944 return CMD_SUCCESS;
945}
946
hassoc25e4582003-12-23 10:39:08 +0000947DEFUNSH (VTYSH_ISISD,
hassob094d262004-08-25 12:22:00 +0000948 router_isis,
949 router_isis_cmd,
950 "router isis WORD",
951 ROUTER_STR
952 "ISO IS-IS\n"
953 "ISO Routing area tag")
hassoc25e4582003-12-23 10:39:08 +0000954{
955 vty->node = ISIS_NODE;
956 return CMD_SUCCESS;
957}
958
paul718e3742002-12-13 20:15:29 +0000959DEFUNSH (VTYSH_RMAP,
960 route_map,
961 route_map_cmd,
962 "route-map WORD (deny|permit) <1-65535>",
963 "Create route-map or enter route-map command mode\n"
964 "Route map tag\n"
965 "Route map denies set operations\n"
966 "Route map permits set operations\n"
967 "Sequence to insert to/delete from existing route-map entry\n")
968{
969 vty->node = RMAP_NODE;
970 return CMD_SUCCESS;
971}
972
paul718e3742002-12-13 20:15:29 +0000973DEFUNSH (VTYSH_ALL,
hassoe7168df2004-10-03 20:11:32 +0000974 vtysh_line_vty,
975 vtysh_line_vty_cmd,
976 "line vty",
977 "Configure a terminal line\n"
978 "Virtual terminal\n")
979{
980 vty->node = VTY_NODE;
981 return CMD_SUCCESS;
982}
983
984DEFUNSH (VTYSH_ALL,
paul718e3742002-12-13 20:15:29 +0000985 vtysh_enable,
986 vtysh_enable_cmd,
987 "enable",
988 "Turn on privileged mode command\n")
989{
990 vty->node = ENABLE_NODE;
991 return CMD_SUCCESS;
992}
993
paul718e3742002-12-13 20:15:29 +0000994DEFUNSH (VTYSH_ALL,
995 vtysh_disable,
996 vtysh_disable_cmd,
997 "disable",
998 "Turn off privileged mode command\n")
999{
1000 if (vty->node == ENABLE_NODE)
1001 vty->node = VIEW_NODE;
1002 return CMD_SUCCESS;
1003}
1004
paul718e3742002-12-13 20:15:29 +00001005DEFUNSH (VTYSH_ALL,
1006 vtysh_config_terminal,
1007 vtysh_config_terminal_cmd,
1008 "configure terminal",
1009 "Configuration from vty interface\n"
1010 "Configuration terminal\n")
1011{
1012 vty->node = CONFIG_NODE;
1013 return CMD_SUCCESS;
1014}
1015
ajs274a4a42004-12-07 15:39:31 +00001016static int
paul718e3742002-12-13 20:15:29 +00001017vtysh_exit (struct vty *vty)
1018{
1019 switch (vty->node)
1020 {
1021 case VIEW_NODE:
1022 case ENABLE_NODE:
1023 exit (0);
1024 break;
1025 case CONFIG_NODE:
1026 vty->node = ENABLE_NODE;
1027 break;
1028 case INTERFACE_NODE:
1029 case ZEBRA_NODE:
1030 case BGP_NODE:
1031 case RIP_NODE:
1032 case RIPNG_NODE:
1033 case OSPF_NODE:
1034 case OSPF6_NODE:
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +01001035 case BABEL_NODE:
hassoc25e4582003-12-23 10:39:08 +00001036 case ISIS_NODE:
paul718e3742002-12-13 20:15:29 +00001037 case MASC_NODE:
1038 case RMAP_NODE:
1039 case VTY_NODE:
1040 case KEYCHAIN_NODE:
hasso2a56df92004-05-09 23:16:40 +00001041 vtysh_execute("end");
1042 vtysh_execute("configure terminal");
paul718e3742002-12-13 20:15:29 +00001043 vty->node = CONFIG_NODE;
1044 break;
1045 case BGP_VPNV4_NODE:
1046 case BGP_IPV4_NODE:
1047 case BGP_IPV4M_NODE:
1048 case BGP_IPV6_NODE:
paul57b5b7e2005-08-22 22:44:29 +00001049 case BGP_IPV6M_NODE:
paul718e3742002-12-13 20:15:29 +00001050 vty->node = BGP_NODE;
1051 break;
1052 case KEYCHAIN_KEY_NODE:
1053 vty->node = KEYCHAIN_NODE;
1054 break;
1055 default:
1056 break;
1057 }
1058 return CMD_SUCCESS;
1059}
1060
1061DEFUNSH (VTYSH_ALL,
1062 vtysh_exit_all,
1063 vtysh_exit_all_cmd,
1064 "exit",
1065 "Exit current mode and down to previous mode\n")
1066{
1067 return vtysh_exit (vty);
1068}
1069
1070ALIAS (vtysh_exit_all,
1071 vtysh_quit_all_cmd,
1072 "quit",
1073 "Exit current mode and down to previous mode\n")
1074
1075DEFUNSH (VTYSH_BGPD,
1076 exit_address_family,
1077 exit_address_family_cmd,
1078 "exit-address-family",
1079 "Exit from Address Family configuration mode\n")
1080{
1081 if (vty->node == BGP_IPV4_NODE
1082 || vty->node == BGP_IPV4M_NODE
1083 || vty->node == BGP_VPNV4_NODE
paul57b5b7e2005-08-22 22:44:29 +00001084 || vty->node == BGP_IPV6_NODE
1085 || vty->node == BGP_IPV6M_NODE)
paul718e3742002-12-13 20:15:29 +00001086 vty->node = BGP_NODE;
1087 return CMD_SUCCESS;
1088}
1089
1090DEFUNSH (VTYSH_ZEBRA,
1091 vtysh_exit_zebra,
1092 vtysh_exit_zebra_cmd,
1093 "exit",
1094 "Exit current mode and down to previous mode\n")
1095{
1096 return vtysh_exit (vty);
1097}
1098
1099ALIAS (vtysh_exit_zebra,
1100 vtysh_quit_zebra_cmd,
1101 "quit",
1102 "Exit current mode and down to previous mode\n")
1103
1104DEFUNSH (VTYSH_RIPD,
1105 vtysh_exit_ripd,
1106 vtysh_exit_ripd_cmd,
1107 "exit",
1108 "Exit current mode and down to previous mode\n")
1109{
1110 return vtysh_exit (vty);
1111}
1112
1113ALIAS (vtysh_exit_ripd,
1114 vtysh_quit_ripd_cmd,
1115 "quit",
1116 "Exit current mode and down to previous mode\n")
1117
paul68980082003-03-25 05:07:42 +00001118DEFUNSH (VTYSH_RIPNGD,
hassob094d262004-08-25 12:22:00 +00001119 vtysh_exit_ripngd,
1120 vtysh_exit_ripngd_cmd,
1121 "exit",
1122 "Exit current mode and down to previous mode\n")
paul68980082003-03-25 05:07:42 +00001123{
1124 return vtysh_exit (vty);
1125}
1126
1127ALIAS (vtysh_exit_ripngd,
1128 vtysh_quit_ripngd_cmd,
1129 "quit",
1130 "Exit current mode and down to previous mode\n")
1131
paul718e3742002-12-13 20:15:29 +00001132DEFUNSH (VTYSH_RMAP,
1133 vtysh_exit_rmap,
1134 vtysh_exit_rmap_cmd,
1135 "exit",
1136 "Exit current mode and down to previous mode\n")
1137{
1138 return vtysh_exit (vty);
1139}
1140
1141ALIAS (vtysh_exit_rmap,
1142 vtysh_quit_rmap_cmd,
1143 "quit",
1144 "Exit current mode and down to previous mode\n")
1145
1146DEFUNSH (VTYSH_BGPD,
1147 vtysh_exit_bgpd,
1148 vtysh_exit_bgpd_cmd,
1149 "exit",
1150 "Exit current mode and down to previous mode\n")
1151{
1152 return vtysh_exit (vty);
1153}
1154
1155ALIAS (vtysh_exit_bgpd,
1156 vtysh_quit_bgpd_cmd,
1157 "quit",
1158 "Exit current mode and down to previous mode\n")
1159
1160DEFUNSH (VTYSH_OSPFD,
1161 vtysh_exit_ospfd,
1162 vtysh_exit_ospfd_cmd,
1163 "exit",
1164 "Exit current mode and down to previous mode\n")
1165{
1166 return vtysh_exit (vty);
1167}
1168
1169ALIAS (vtysh_exit_ospfd,
1170 vtysh_quit_ospfd_cmd,
1171 "quit",
1172 "Exit current mode and down to previous mode\n")
1173
paul68980082003-03-25 05:07:42 +00001174DEFUNSH (VTYSH_OSPF6D,
hassob094d262004-08-25 12:22:00 +00001175 vtysh_exit_ospf6d,
1176 vtysh_exit_ospf6d_cmd,
1177 "exit",
1178 "Exit current mode and down to previous mode\n")
paul68980082003-03-25 05:07:42 +00001179{
1180 return vtysh_exit (vty);
1181}
1182
1183ALIAS (vtysh_exit_ospf6d,
1184 vtysh_quit_ospf6d_cmd,
1185 "quit",
1186 "Exit current mode and down to previous mode\n")
1187
hassoc25e4582003-12-23 10:39:08 +00001188DEFUNSH (VTYSH_ISISD,
hassob094d262004-08-25 12:22:00 +00001189 vtysh_exit_isisd,
1190 vtysh_exit_isisd_cmd,
1191 "exit",
1192 "Exit current mode and down to previous mode\n")
hassoc25e4582003-12-23 10:39:08 +00001193{
1194 return vtysh_exit (vty);
1195}
1196
1197ALIAS (vtysh_exit_isisd,
1198 vtysh_quit_isisd_cmd,
1199 "quit",
1200 "Exit current mode and down to previous mode\n")
1201
hassoe7168df2004-10-03 20:11:32 +00001202DEFUNSH (VTYSH_ALL,
1203 vtysh_exit_line_vty,
1204 vtysh_exit_line_vty_cmd,
1205 "exit",
1206 "Exit current mode and down to previous mode\n")
1207{
1208 return vtysh_exit (vty);
1209}
1210
1211ALIAS (vtysh_exit_line_vty,
1212 vtysh_quit_line_vty_cmd,
1213 "quit",
1214 "Exit current mode and down to previous mode\n")
1215
hasso95e735b2004-08-26 13:08:30 +00001216DEFUNSH (VTYSH_INTERFACE,
paul718e3742002-12-13 20:15:29 +00001217 vtysh_interface,
1218 vtysh_interface_cmd,
1219 "interface IFNAME",
1220 "Select an interface to configure\n"
1221 "Interface's name\n")
1222{
1223 vty->node = INTERFACE_NODE;
1224 return CMD_SUCCESS;
1225}
1226
Feng Lu471ea392015-05-22 11:40:00 +02001227ALIAS_SH (VTYSH_ZEBRA,
1228 vtysh_interface,
1229 vtysh_interface_vrf_cmd,
1230 "interface IFNAME " VRF_CMD_STR,
1231 "Select an interface to configure\n"
1232 "Interface's name\n"
1233 VRF_CMD_HELP_STR)
1234
hasso95e735b2004-08-26 13:08:30 +00001235/* TODO Implement "no interface command in isisd. */
paul32d24632003-05-23 09:25:20 +00001236DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D,
1237 vtysh_no_interface_cmd,
1238 "no interface IFNAME",
1239 NO_STR
1240 "Delete a pseudo interface's configuration\n"
1241 "Interface's name\n")
1242
Feng Lu471ea392015-05-22 11:40:00 +02001243DEFSH (VTYSH_ZEBRA,
1244 vtysh_no_interface_vrf_cmd,
1245 "no interface IFNAME " VRF_CMD_STR,
1246 NO_STR
1247 "Delete a pseudo interface's configuration\n"
1248 "Interface's name\n"
1249 VRF_CMD_HELP_STR)
1250
hasso95e735b2004-08-26 13:08:30 +00001251/* TODO Implement interface description commands in ripngd, ospf6d
1252 * and isisd. */
paul338a9912003-03-01 15:44:10 +00001253DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1254 interface_desc_cmd,
1255 "description .LINE",
1256 "Interface specific description\n"
1257 "Characters describing this interface\n")
paul464dc8d2003-03-28 02:25:45 +00001258
1259DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1260 no_interface_desc_cmd,
1261 "no description",
1262 NO_STR
1263 "Interface specific description\n")
paul338a9912003-03-01 15:44:10 +00001264
hasso95e735b2004-08-26 13:08:30 +00001265DEFUNSH (VTYSH_INTERFACE,
paul718e3742002-12-13 20:15:29 +00001266 vtysh_exit_interface,
1267 vtysh_exit_interface_cmd,
1268 "exit",
1269 "Exit current mode and down to previous mode\n")
1270{
1271 return vtysh_exit (vty);
1272}
1273
1274ALIAS (vtysh_exit_interface,
1275 vtysh_quit_interface_cmd,
1276 "quit",
1277 "Exit current mode and down to previous mode\n")
1278
Donald Sharp567a6382015-08-19 21:22:17 -04001279DEFUN (vtysh_show_thread,
1280 vtysh_show_thread_cmd,
1281 "show thread cpu [FILTER]",
1282 SHOW_STR
1283 "Thread information\n"
1284 "Thread CPU usage\n"
1285 "Display filter (rwtexb)\n")
1286{
1287 unsigned int i;
1288 int ret = CMD_SUCCESS;
1289 char line[100];
1290
1291 sprintf(line, "show thread cpu %s\n", (argc == 1) ? argv[0] : "");
1292 for (i = 0; i < array_size(vtysh_client); i++)
1293 if ( vtysh_client[i].fd >= 0 )
1294 {
1295 fprintf (stdout, "Thread statistics for %s:\n",
1296 vtysh_client[i].name);
1297 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1298 fprintf (stdout,"\n");
1299 }
1300 return ret;
1301}
1302
1303DEFUN (vtysh_show_work_queues,
1304 vtysh_show_work_queues_cmd,
1305 "show work-queues",
1306 SHOW_STR
1307 "Work Queue information\n")
1308{
1309 unsigned int i;
1310 int ret = CMD_SUCCESS;
1311 char line[] = "show work-queues\n";
1312
1313 for (i = 0; i < array_size(vtysh_client); i++)
1314 if ( vtysh_client[i].fd >= 0 )
1315 {
1316 fprintf (stdout, "Work queue statistics for %s:\n",
1317 vtysh_client[i].name);
1318 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1319 fprintf (stdout,"\n");
1320 }
1321
1322 return ret;
1323}
1324
Paul Jakma362b4032006-05-28 07:54:45 +00001325/* Memory */
1326DEFUN (vtysh_show_memory,
1327 vtysh_show_memory_cmd,
1328 "show memory",
1329 SHOW_STR
1330 "Memory statistics\n")
1331{
1332 unsigned int i;
1333 int ret = CMD_SUCCESS;
1334 char line[] = "show memory\n";
1335
Balaji.G837d16c2012-09-26 14:09:10 +05301336 for (i = 0; i < array_size(vtysh_client); i++)
Paul Jakma362b4032006-05-28 07:54:45 +00001337 if ( vtysh_client[i].fd >= 0 )
1338 {
1339 fprintf (stdout, "Memory statistics for %s:\n",
1340 vtysh_client[i].name);
1341 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1342 fprintf (stdout,"\n");
1343 }
1344
1345 return ret;
1346}
1347
hasso95e735b2004-08-26 13:08:30 +00001348/* Logging commands. */
Paul Jakmadbf7d132006-05-23 22:10:01 +00001349DEFUN (vtysh_show_logging,
1350 vtysh_show_logging_cmd,
1351 "show logging",
1352 SHOW_STR
1353 "Show current logging configuration\n")
1354{
1355 unsigned int i;
1356 int ret = CMD_SUCCESS;
1357 char line[] = "show logging\n";
1358
Balaji.G837d16c2012-09-26 14:09:10 +05301359 for (i = 0; i < array_size(vtysh_client); i++)
Paul Jakma4150f332006-05-23 22:10:55 +00001360 if ( vtysh_client[i].fd >= 0 )
1361 {
1362 fprintf (stdout,"Logging configuration for %s:\n",
1363 vtysh_client[i].name);
1364 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1365 fprintf (stdout,"\n");
1366 }
1367
Paul Jakmadbf7d132006-05-23 22:10:01 +00001368 return ret;
1369}
1370
hasso95e735b2004-08-26 13:08:30 +00001371DEFUNSH (VTYSH_ALL,
1372 vtysh_log_stdout,
1373 vtysh_log_stdout_cmd,
1374 "log stdout",
1375 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001376 "Set stdout logging level\n")
1377{
1378 return CMD_SUCCESS;
1379}
1380
1381DEFUNSH (VTYSH_ALL,
1382 vtysh_log_stdout_level,
1383 vtysh_log_stdout_level_cmd,
1384 "log stdout "LOG_LEVELS,
1385 "Logging control\n"
1386 "Set stdout logging level\n"
1387 LOG_LEVEL_DESC)
hasso95e735b2004-08-26 13:08:30 +00001388{
1389 return CMD_SUCCESS;
1390}
1391
1392DEFUNSH (VTYSH_ALL,
1393 no_vtysh_log_stdout,
1394 no_vtysh_log_stdout_cmd,
ajs274a4a42004-12-07 15:39:31 +00001395 "no log stdout [LEVEL]",
hasso95e735b2004-08-26 13:08:30 +00001396 NO_STR
1397 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001398 "Cancel logging to stdout\n"
1399 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001400{
1401 return CMD_SUCCESS;
1402}
1403
1404DEFUNSH (VTYSH_ALL,
1405 vtysh_log_file,
1406 vtysh_log_file_cmd,
1407 "log file FILENAME",
1408 "Logging control\n"
1409 "Logging to file\n"
1410 "Logging filename\n")
1411{
1412 return CMD_SUCCESS;
1413}
1414
1415DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001416 vtysh_log_file_level,
1417 vtysh_log_file_level_cmd,
1418 "log file FILENAME "LOG_LEVELS,
1419 "Logging control\n"
1420 "Logging to file\n"
1421 "Logging filename\n"
1422 LOG_LEVEL_DESC)
1423{
1424 return CMD_SUCCESS;
1425}
1426
1427DEFUNSH (VTYSH_ALL,
hasso95e735b2004-08-26 13:08:30 +00001428 no_vtysh_log_file,
1429 no_vtysh_log_file_cmd,
1430 "no log file [FILENAME]",
1431 NO_STR
1432 "Logging control\n"
1433 "Cancel logging to file\n"
1434 "Logging file name\n")
1435{
1436 return CMD_SUCCESS;
1437}
1438
ajs274a4a42004-12-07 15:39:31 +00001439ALIAS_SH (VTYSH_ALL,
1440 no_vtysh_log_file,
1441 no_vtysh_log_file_level_cmd,
1442 "no log file FILENAME LEVEL",
1443 NO_STR
1444 "Logging control\n"
1445 "Cancel logging to file\n"
1446 "Logging file name\n"
1447 "Logging level\n")
1448
1449DEFUNSH (VTYSH_ALL,
1450 vtysh_log_monitor,
1451 vtysh_log_monitor_cmd,
1452 "log monitor",
1453 "Logging control\n"
1454 "Set terminal line (monitor) logging level\n")
1455{
1456 return CMD_SUCCESS;
1457}
1458
1459DEFUNSH (VTYSH_ALL,
1460 vtysh_log_monitor_level,
1461 vtysh_log_monitor_level_cmd,
1462 "log monitor "LOG_LEVELS,
1463 "Logging control\n"
1464 "Set terminal line (monitor) logging level\n"
1465 LOG_LEVEL_DESC)
1466{
1467 return CMD_SUCCESS;
1468}
1469
1470DEFUNSH (VTYSH_ALL,
1471 no_vtysh_log_monitor,
1472 no_vtysh_log_monitor_cmd,
1473 "no log monitor [LEVEL]",
1474 NO_STR
1475 "Logging control\n"
1476 "Disable terminal line (monitor) logging\n"
1477 "Logging level\n")
1478{
1479 return CMD_SUCCESS;
1480}
1481
hasso95e735b2004-08-26 13:08:30 +00001482DEFUNSH (VTYSH_ALL,
1483 vtysh_log_syslog,
1484 vtysh_log_syslog_cmd,
1485 "log syslog",
1486 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001487 "Set syslog logging level\n")
1488{
1489 return CMD_SUCCESS;
1490}
1491
1492DEFUNSH (VTYSH_ALL,
1493 vtysh_log_syslog_level,
1494 vtysh_log_syslog_level_cmd,
1495 "log syslog "LOG_LEVELS,
1496 "Logging control\n"
1497 "Set syslog logging level\n"
1498 LOG_LEVEL_DESC)
hasso95e735b2004-08-26 13:08:30 +00001499{
1500 return CMD_SUCCESS;
1501}
1502
1503DEFUNSH (VTYSH_ALL,
1504 no_vtysh_log_syslog,
1505 no_vtysh_log_syslog_cmd,
ajs274a4a42004-12-07 15:39:31 +00001506 "no log syslog [LEVEL]",
hasso95e735b2004-08-26 13:08:30 +00001507 NO_STR
1508 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001509 "Cancel logging to syslog\n"
1510 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001511{
1512 return CMD_SUCCESS;
1513}
1514
1515DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001516 vtysh_log_facility,
1517 vtysh_log_facility_cmd,
1518 "log facility "LOG_FACILITIES,
hasso95e735b2004-08-26 13:08:30 +00001519 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001520 "Facility parameter for syslog messages\n"
1521 LOG_FACILITY_DESC)
1522
hasso95e735b2004-08-26 13:08:30 +00001523{
1524 return CMD_SUCCESS;
1525}
1526
1527DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001528 no_vtysh_log_facility,
1529 no_vtysh_log_facility_cmd,
1530 "no log facility [FACILITY]",
hasso95e735b2004-08-26 13:08:30 +00001531 NO_STR
1532 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001533 "Reset syslog facility to default (daemon)\n"
1534 "Syslog facility\n")
1535
1536{
1537 return CMD_SUCCESS;
1538}
1539
1540DEFUNSH_DEPRECATED (VTYSH_ALL,
1541 vtysh_log_trap,
1542 vtysh_log_trap_cmd,
1543 "log trap "LOG_LEVELS,
1544 "Logging control\n"
1545 "(Deprecated) Set logging level and default for all destinations\n"
1546 LOG_LEVEL_DESC)
1547
1548{
1549 return CMD_SUCCESS;
1550}
1551
1552DEFUNSH_DEPRECATED (VTYSH_ALL,
1553 no_vtysh_log_trap,
1554 no_vtysh_log_trap_cmd,
1555 "no log trap [LEVEL]",
1556 NO_STR
1557 "Logging control\n"
1558 "Permit all logging information\n"
1559 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001560{
1561 return CMD_SUCCESS;
1562}
1563
1564DEFUNSH (VTYSH_ALL,
1565 vtysh_log_record_priority,
1566 vtysh_log_record_priority_cmd,
1567 "log record-priority",
1568 "Logging control\n"
1569 "Log the priority of the message within the message\n")
1570{
1571 return CMD_SUCCESS;
1572}
1573
1574DEFUNSH (VTYSH_ALL,
1575 no_vtysh_log_record_priority,
1576 no_vtysh_log_record_priority_cmd,
1577 "no log record-priority",
1578 NO_STR
1579 "Logging control\n"
1580 "Do not log the priority of the message within the message\n")
1581{
1582 return CMD_SUCCESS;
1583}
1584
hassoe7168df2004-10-03 20:11:32 +00001585DEFUNSH (VTYSH_ALL,
Andrew J. Schorrc749b722007-04-29 03:53:31 +00001586 vtysh_log_timestamp_precision,
1587 vtysh_log_timestamp_precision_cmd,
1588 "log timestamp precision <0-6>",
1589 "Logging control\n"
1590 "Timestamp configuration\n"
1591 "Set the timestamp precision\n"
1592 "Number of subsecond digits\n")
1593{
1594 return CMD_SUCCESS;
1595}
1596
1597DEFUNSH (VTYSH_ALL,
1598 no_vtysh_log_timestamp_precision,
1599 no_vtysh_log_timestamp_precision_cmd,
1600 "no log timestamp precision",
1601 NO_STR
1602 "Logging control\n"
1603 "Timestamp configuration\n"
1604 "Reset the timestamp precision to the default value of 0\n")
1605{
1606 return CMD_SUCCESS;
1607}
1608
1609DEFUNSH (VTYSH_ALL,
hassoe7168df2004-10-03 20:11:32 +00001610 vtysh_service_password_encrypt,
1611 vtysh_service_password_encrypt_cmd,
1612 "service password-encryption",
1613 "Set up miscellaneous service\n"
1614 "Enable encrypted passwords\n")
1615{
1616 return CMD_SUCCESS;
1617}
1618
1619DEFUNSH (VTYSH_ALL,
1620 no_vtysh_service_password_encrypt,
1621 no_vtysh_service_password_encrypt_cmd,
1622 "no service password-encryption",
1623 NO_STR
1624 "Set up miscellaneous service\n"
1625 "Enable encrypted passwords\n")
1626{
1627 return CMD_SUCCESS;
1628}
1629
1630DEFUNSH (VTYSH_ALL,
1631 vtysh_config_password,
1632 vtysh_password_cmd,
1633 "password (8|) WORD",
1634 "Assign the terminal connection password\n"
1635 "Specifies a HIDDEN password will follow\n"
1636 "dummy string \n"
1637 "The HIDDEN line password string\n")
1638{
1639 return CMD_SUCCESS;
1640}
1641
1642DEFUNSH (VTYSH_ALL,
1643 vtysh_password_text,
1644 vtysh_password_text_cmd,
1645 "password LINE",
1646 "Assign the terminal connection password\n"
1647 "The UNENCRYPTED (cleartext) line password\n")
1648{
1649 return CMD_SUCCESS;
1650}
1651
1652DEFUNSH (VTYSH_ALL,
1653 vtysh_config_enable_password,
1654 vtysh_enable_password_cmd,
1655 "enable password (8|) WORD",
1656 "Modify enable password parameters\n"
1657 "Assign the privileged level password\n"
1658 "Specifies a HIDDEN password will follow\n"
1659 "dummy string \n"
1660 "The HIDDEN 'enable' password string\n")
1661{
1662 return CMD_SUCCESS;
1663}
1664
1665DEFUNSH (VTYSH_ALL,
1666 vtysh_enable_password_text,
1667 vtysh_enable_password_text_cmd,
1668 "enable password LINE",
1669 "Modify enable password parameters\n"
1670 "Assign the privileged level password\n"
1671 "The UNENCRYPTED (cleartext) 'enable' password\n")
1672{
1673 return CMD_SUCCESS;
1674}
1675
1676DEFUNSH (VTYSH_ALL,
1677 no_vtysh_config_enable_password,
1678 no_vtysh_enable_password_cmd,
1679 "no enable password",
1680 NO_STR
1681 "Modify enable password parameters\n"
1682 "Assign the privileged level password\n")
1683{
1684 return CMD_SUCCESS;
1685}
1686
paul718e3742002-12-13 20:15:29 +00001687DEFUN (vtysh_write_terminal,
1688 vtysh_write_terminal_cmd,
1689 "write terminal",
1690 "Write running configuration to memory, network, or terminal\n"
1691 "Write to terminal\n")
1692{
ajsb1aa1472005-01-28 21:11:46 +00001693 u_int i;
paul718e3742002-12-13 20:15:29 +00001694 char line[] = "write terminal\n";
1695 FILE *fp = NULL;
1696
1697 if (vtysh_pager_name)
1698 {
paul4fc01e62002-12-13 20:49:00 +00001699 fp = popen (vtysh_pager_name, "w");
paul718e3742002-12-13 20:15:29 +00001700 if (fp == NULL)
1701 {
1702 perror ("popen");
1703 exit (1);
1704 }
1705 }
1706 else
1707 fp = stdout;
1708
1709 vty_out (vty, "Building configuration...%s", VTY_NEWLINE);
1710 vty_out (vty, "%sCurrent configuration:%s", VTY_NEWLINE,
1711 VTY_NEWLINE);
hassoe7168df2004-10-03 20:11:32 +00001712 vty_out (vty, "!%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001713
Balaji.G837d16c2012-09-26 14:09:10 +05301714 for (i = 0; i < array_size(vtysh_client); i++)
Gautam Kumarcc216b72015-10-26 13:22:12 -07001715 vtysh_client_execute (&vtysh_client[i], line, NULL);
paul718e3742002-12-13 20:15:29 +00001716
hassoe7168df2004-10-03 20:11:32 +00001717 /* Integrate vtysh specific configuration. */
1718 vtysh_config_write ();
1719
paul718e3742002-12-13 20:15:29 +00001720 vtysh_config_dump (fp);
1721
1722 if (vtysh_pager_name && fp)
1723 {
1724 fflush (fp);
1725 if (pclose (fp) == -1)
1726 {
1727 perror ("pclose");
1728 exit (1);
1729 }
1730 fp = NULL;
1731 }
1732
Chris Caputo6e79f8b2009-06-23 05:55:57 +00001733 vty_out (vty, "end%s", VTY_NEWLINE);
1734
paul718e3742002-12-13 20:15:29 +00001735 return CMD_SUCCESS;
1736}
1737
Donald Sharp9fb73e82015-09-22 11:13:12 -04001738DEFUN (vtysh_write_terminal_daemon,
1739 vtysh_write_terminal_daemon_cmd,
1740 "write terminal (zebra|ripd|ripngd|ospfd|ospf6d|bgpd|isisd|babeld)",
1741 "Write running configuration to memory, network, or terminal\n"
1742 "Write to terminal\n"
1743 "For the zebra daemon\n"
1744 "For the rip daemon\n"
1745 "For the ripng daemon\n"
1746 "For the ospf daemon\n"
1747 "For the ospfv6 daemon\n"
1748 "For the bgp daemon\n"
1749 "For the isis daemon\n"
1750 "For the babel daemon\n")
1751{
1752 unsigned int i;
1753 int ret = CMD_SUCCESS;
1754
1755 for (i = 0; i < array_size(vtysh_client); i++)
1756 {
1757 if (strcmp(vtysh_client[i].name, argv[0]) == 0)
1758 break;
1759 }
1760
1761 ret = vtysh_client_execute(&vtysh_client[i], "show running-config\n", stdout);
1762
1763 return ret;
1764}
1765
hassoe7168df2004-10-03 20:11:32 +00001766DEFUN (vtysh_integrated_config,
1767 vtysh_integrated_config_cmd,
1768 "service integrated-vtysh-config",
1769 "Set up miscellaneous service\n"
1770 "Write configuration into integrated file\n")
paul4fc01e62002-12-13 20:49:00 +00001771{
hassoe7168df2004-10-03 20:11:32 +00001772 vtysh_writeconfig_integrated = 1;
1773 return CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001774}
1775
hassoe7168df2004-10-03 20:11:32 +00001776DEFUN (no_vtysh_integrated_config,
1777 no_vtysh_integrated_config_cmd,
1778 "no service integrated-vtysh-config",
1779 NO_STR
1780 "Set up miscellaneous service\n"
1781 "Write configuration into integrated file\n")
paul4fc01e62002-12-13 20:49:00 +00001782{
hassoe7168df2004-10-03 20:11:32 +00001783 vtysh_writeconfig_integrated = 0;
1784 return CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001785}
1786
ajs274a4a42004-12-07 15:39:31 +00001787static int
1788write_config_integrated(void)
paul718e3742002-12-13 20:15:29 +00001789{
ajsb1aa1472005-01-28 21:11:46 +00001790 u_int i;
paul718e3742002-12-13 20:15:29 +00001791 char line[] = "write terminal\n";
1792 FILE *fp;
1793 char *integrate_sav = NULL;
1794
hasso95e735b2004-08-26 13:08:30 +00001795 integrate_sav = malloc (strlen (integrate_default) +
1796 strlen (CONF_BACKUP_EXT) + 1);
paul718e3742002-12-13 20:15:29 +00001797 strcpy (integrate_sav, integrate_default);
1798 strcat (integrate_sav, CONF_BACKUP_EXT);
1799
paul4fc01e62002-12-13 20:49:00 +00001800 fprintf (stdout,"Building Configuration...\n");
paul718e3742002-12-13 20:15:29 +00001801
hasso95e735b2004-08-26 13:08:30 +00001802 /* Move current configuration file to backup config file. */
paul718e3742002-12-13 20:15:29 +00001803 unlink (integrate_sav);
1804 rename (integrate_default, integrate_sav);
hasso95e735b2004-08-26 13:08:30 +00001805 free (integrate_sav);
paul4fc01e62002-12-13 20:49:00 +00001806
paul718e3742002-12-13 20:15:29 +00001807 fp = fopen (integrate_default, "w");
1808 if (fp == NULL)
1809 {
hasso95e735b2004-08-26 13:08:30 +00001810 fprintf (stdout,"%% Can't open configuration file %s.\n",
1811 integrate_default);
paul718e3742002-12-13 20:15:29 +00001812 return CMD_SUCCESS;
1813 }
paul718e3742002-12-13 20:15:29 +00001814
Balaji.G837d16c2012-09-26 14:09:10 +05301815 for (i = 0; i < array_size(vtysh_client); i++)
Gautam Kumarcc216b72015-10-26 13:22:12 -07001816 vtysh_client_execute (&vtysh_client[i], line, NULL);
paul718e3742002-12-13 20:15:29 +00001817
1818 vtysh_config_dump (fp);
1819
1820 fclose (fp);
1821
gdtaa593d52003-12-22 20:15:53 +00001822 if (chmod (integrate_default, CONFIGFILE_MASK) != 0)
1823 {
1824 fprintf (stdout,"%% Can't chmod configuration file %s: %s (%d)\n",
ajs6099b3b2004-11-20 02:06:59 +00001825 integrate_default, safe_strerror(errno), errno);
gdtaa593d52003-12-22 20:15:53 +00001826 return CMD_WARNING;
1827 }
1828
paul4fc01e62002-12-13 20:49:00 +00001829 fprintf(stdout,"Integrated configuration saved to %s\n",integrate_default);
1830
1831 fprintf (stdout,"[OK]\n");
1832
paul718e3742002-12-13 20:15:29 +00001833 return CMD_SUCCESS;
1834}
1835
paul4fc01e62002-12-13 20:49:00 +00001836DEFUN (vtysh_write_memory,
1837 vtysh_write_memory_cmd,
1838 "write memory",
1839 "Write running configuration to memory, network, or terminal\n"
1840 "Write configuration to the file (same as write file)\n")
1841{
pauldfc0d9b2003-04-18 23:55:29 +00001842 int ret = CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001843 char line[] = "write memory\n";
ajsb1aa1472005-01-28 21:11:46 +00001844 u_int i;
paul4fc01e62002-12-13 20:49:00 +00001845
hassoe7168df2004-10-03 20:11:32 +00001846 /* If integrated Quagga.conf explicitely set. */
1847 if (vtysh_writeconfig_integrated)
1848 return write_config_integrated();
paul4fc01e62002-12-13 20:49:00 +00001849
1850 fprintf (stdout,"Building Configuration...\n");
1851
Balaji.G837d16c2012-09-26 14:09:10 +05301852 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00001853 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
hassoe7168df2004-10-03 20:11:32 +00001854
paul4fc01e62002-12-13 20:49:00 +00001855 fprintf (stdout,"[OK]\n");
1856
pauldfc0d9b2003-04-18 23:55:29 +00001857 return ret;
paul4fc01e62002-12-13 20:49:00 +00001858}
1859
paul718e3742002-12-13 20:15:29 +00001860ALIAS (vtysh_write_memory,
1861 vtysh_copy_runningconfig_startupconfig_cmd,
1862 "copy running-config startup-config",
1863 "Copy from one file to another\n"
1864 "Copy from current system configuration\n"
1865 "Copy to startup configuration\n")
1866
1867ALIAS (vtysh_write_memory,
1868 vtysh_write_file_cmd,
1869 "write file",
1870 "Write running configuration to memory, network, or terminal\n"
1871 "Write configuration to the file (same as write memory)\n")
1872
hasso4a6e2252003-05-25 11:51:29 +00001873ALIAS (vtysh_write_memory,
1874 vtysh_write_cmd,
1875 "write",
1876 "Write running configuration to memory, network, or terminal\n")
1877
paul718e3742002-12-13 20:15:29 +00001878ALIAS (vtysh_write_terminal,
1879 vtysh_show_running_config_cmd,
1880 "show running-config",
1881 SHOW_STR
1882 "Current operating configuration\n")
hassob094d262004-08-25 12:22:00 +00001883
Donald Sharp9fb73e82015-09-22 11:13:12 -04001884ALIAS (vtysh_write_terminal_daemon,
1885 vtysh_show_running_config_daemon_cmd,
1886 "show running-config (zebra|ripd|ripngd|ospfd|ospf6d|bgpd|isisd|babeld)",
1887 SHOW_STR
1888 "Current operating configuration\n"
1889 "For the zebra daemon\n"
1890 "For the rip daemon\n"
1891 "For the ripng daemon\n"
1892 "For the ospf daemon\n"
1893 "For the ospfv6 daemon\n"
1894 "For the bgp daemon\n"
1895 "For the isis daemon\n"
1896 "For the babel daemon\n")
1897
hasso34553cc2004-08-27 13:56:39 +00001898DEFUN (vtysh_terminal_length,
1899 vtysh_terminal_length_cmd,
1900 "terminal length <0-512>",
1901 "Set terminal line parameters\n"
1902 "Set number of lines on a screen\n"
1903 "Number of lines on screen (0 for no pausing)\n")
1904{
1905 int lines;
1906 char *endptr = NULL;
1907 char default_pager[10];
1908
1909 lines = strtol (argv[0], &endptr, 10);
1910 if (lines < 0 || lines > 512 || *endptr != '\0')
1911 {
1912 vty_out (vty, "length is malformed%s", VTY_NEWLINE);
1913 return CMD_WARNING;
1914 }
1915
1916 if (vtysh_pager_name)
1917 {
1918 free (vtysh_pager_name);
1919 vtysh_pager_name = NULL;
1920 }
1921
1922 if (lines != 0)
1923 {
1924 snprintf(default_pager, 10, "more -%i", lines);
1925 vtysh_pager_name = strdup (default_pager);
1926 }
1927
1928 return CMD_SUCCESS;
1929}
1930
1931DEFUN (vtysh_terminal_no_length,
1932 vtysh_terminal_no_length_cmd,
1933 "terminal no length",
1934 "Set terminal line parameters\n"
1935 NO_STR
1936 "Set number of lines on a screen\n")
1937{
1938 if (vtysh_pager_name)
1939 {
1940 free (vtysh_pager_name);
1941 vtysh_pager_name = NULL;
1942 }
1943
1944 vtysh_pager_init();
1945 return CMD_SUCCESS;
1946}
1947
hassof2799e62004-10-28 17:43:11 +00001948DEFUN (vtysh_show_daemons,
1949 vtysh_show_daemons_cmd,
1950 "show daemons",
hassoe7168df2004-10-03 20:11:32 +00001951 SHOW_STR
1952 "Show list of running daemons\n")
1953{
ajsb1aa1472005-01-28 21:11:46 +00001954 u_int i;
1955
Balaji.G837d16c2012-09-26 14:09:10 +05301956 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00001957 if ( vtysh_client[i].fd >= 0 )
1958 vty_out(vty, " %s", vtysh_client[i].name);
hassoe7168df2004-10-03 20:11:32 +00001959 vty_out(vty, "%s", VTY_NEWLINE);
1960
1961 return CMD_SUCCESS;
1962}
1963
paul718e3742002-12-13 20:15:29 +00001964/* Execute command in child process. */
ajs274a4a42004-12-07 15:39:31 +00001965static int
hasso5862ff52004-10-11 13:20:40 +00001966execute_command (const char *command, int argc, const char *arg1,
1967 const char *arg2)
paul718e3742002-12-13 20:15:29 +00001968{
paul718e3742002-12-13 20:15:29 +00001969 pid_t pid;
1970 int status;
1971
1972 /* Call fork(). */
1973 pid = fork ();
1974
1975 if (pid < 0)
1976 {
1977 /* Failure of fork(). */
ajs6099b3b2004-11-20 02:06:59 +00001978 fprintf (stderr, "Can't fork: %s\n", safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +00001979 exit (1);
1980 }
1981 else if (pid == 0)
1982 {
1983 /* This is child process. */
1984 switch (argc)
1985 {
1986 case 0:
David Lamparter6769f432015-03-04 07:18:24 +01001987 execlp (command, command, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00001988 break;
1989 case 1:
David Lamparter6769f432015-03-04 07:18:24 +01001990 execlp (command, command, arg1, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00001991 break;
1992 case 2:
David Lamparter6769f432015-03-04 07:18:24 +01001993 execlp (command, command, arg1, arg2, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00001994 break;
1995 }
1996
1997 /* When execlp suceed, this part is not executed. */
ajs6099b3b2004-11-20 02:06:59 +00001998 fprintf (stderr, "Can't execute %s: %s\n", command, safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +00001999 exit (1);
2000 }
2001 else
2002 {
2003 /* This is parent. */
2004 execute_flag = 1;
David Lamparter6769f432015-03-04 07:18:24 +01002005 wait4 (pid, &status, 0, NULL);
paul718e3742002-12-13 20:15:29 +00002006 execute_flag = 0;
2007 }
2008 return 0;
2009}
2010
2011DEFUN (vtysh_ping,
2012 vtysh_ping_cmd,
2013 "ping WORD",
hasso4eeccf12003-06-25 10:49:55 +00002014 "Send echo messages\n"
paul718e3742002-12-13 20:15:29 +00002015 "Ping destination address or hostname\n")
2016{
2017 execute_command ("ping", 1, argv[0], NULL);
2018 return CMD_SUCCESS;
2019}
2020
hasso4eeccf12003-06-25 10:49:55 +00002021ALIAS (vtysh_ping,
2022 vtysh_ping_ip_cmd,
2023 "ping ip WORD",
2024 "Send echo messages\n"
2025 "IP echo\n"
2026 "Ping destination address or hostname\n")
2027
paul718e3742002-12-13 20:15:29 +00002028DEFUN (vtysh_traceroute,
2029 vtysh_traceroute_cmd,
2030 "traceroute WORD",
2031 "Trace route to destination\n"
2032 "Trace route to destination address or hostname\n")
2033{
2034 execute_command ("traceroute", 1, argv[0], NULL);
2035 return CMD_SUCCESS;
2036}
2037
hasso4eeccf12003-06-25 10:49:55 +00002038ALIAS (vtysh_traceroute,
2039 vtysh_traceroute_ip_cmd,
2040 "traceroute ip WORD",
2041 "Trace route to destination\n"
2042 "IP trace\n"
2043 "Trace route to destination address or hostname\n")
2044
2045#ifdef HAVE_IPV6
2046DEFUN (vtysh_ping6,
2047 vtysh_ping6_cmd,
2048 "ping ipv6 WORD",
2049 "Send echo messages\n"
2050 "IPv6 echo\n"
2051 "Ping destination address or hostname\n")
2052{
2053 execute_command ("ping6", 1, argv[0], NULL);
2054 return CMD_SUCCESS;
2055}
2056
2057DEFUN (vtysh_traceroute6,
2058 vtysh_traceroute6_cmd,
2059 "traceroute ipv6 WORD",
2060 "Trace route to destination\n"
2061 "IPv6 trace\n"
2062 "Trace route to destination address or hostname\n")
2063{
2064 execute_command ("traceroute6", 1, argv[0], NULL);
2065 return CMD_SUCCESS;
2066}
2067#endif
2068
paul718e3742002-12-13 20:15:29 +00002069DEFUN (vtysh_telnet,
2070 vtysh_telnet_cmd,
2071 "telnet WORD",
2072 "Open a telnet connection\n"
2073 "IP address or hostname of a remote system\n")
2074{
2075 execute_command ("telnet", 1, argv[0], NULL);
2076 return CMD_SUCCESS;
2077}
2078
2079DEFUN (vtysh_telnet_port,
2080 vtysh_telnet_port_cmd,
2081 "telnet WORD PORT",
2082 "Open a telnet connection\n"
2083 "IP address or hostname of a remote system\n"
2084 "TCP Port number\n")
2085{
2086 execute_command ("telnet", 2, argv[0], argv[1]);
2087 return CMD_SUCCESS;
2088}
2089
paul5087df52003-01-25 06:56:09 +00002090DEFUN (vtysh_ssh,
2091 vtysh_ssh_cmd,
2092 "ssh WORD",
2093 "Open an ssh connection\n"
2094 "[user@]host\n")
2095{
2096 execute_command ("ssh", 1, argv[0], NULL);
2097 return CMD_SUCCESS;
2098}
2099
paul718e3742002-12-13 20:15:29 +00002100DEFUN (vtysh_start_shell,
2101 vtysh_start_shell_cmd,
2102 "start-shell",
2103 "Start UNIX shell\n")
2104{
2105 execute_command ("sh", 0, NULL, NULL);
2106 return CMD_SUCCESS;
2107}
2108
2109DEFUN (vtysh_start_bash,
2110 vtysh_start_bash_cmd,
2111 "start-shell bash",
2112 "Start UNIX shell\n"
2113 "Start bash\n")
2114{
2115 execute_command ("bash", 0, NULL, NULL);
2116 return CMD_SUCCESS;
2117}
2118
2119DEFUN (vtysh_start_zsh,
2120 vtysh_start_zsh_cmd,
2121 "start-shell zsh",
2122 "Start UNIX shell\n"
2123 "Start Z shell\n")
2124{
2125 execute_command ("zsh", 0, NULL, NULL);
2126 return CMD_SUCCESS;
2127}
hassob094d262004-08-25 12:22:00 +00002128
ajs274a4a42004-12-07 15:39:31 +00002129static void
paul718e3742002-12-13 20:15:29 +00002130vtysh_install_default (enum node_type node)
2131{
2132 install_element (node, &config_list_cmd);
2133}
2134
2135/* Making connection to protocol daemon. */
ajs274a4a42004-12-07 15:39:31 +00002136static int
ajsb1aa1472005-01-28 21:11:46 +00002137vtysh_connect (struct vtysh_client *vclient)
paul718e3742002-12-13 20:15:29 +00002138{
2139 int ret;
2140 int sock, len;
2141 struct sockaddr_un addr;
2142 struct stat s_stat;
paul718e3742002-12-13 20:15:29 +00002143
paul718e3742002-12-13 20:15:29 +00002144 /* Stat socket to see if we have permission to access it. */
ajsb1aa1472005-01-28 21:11:46 +00002145 ret = stat (vclient->path, &s_stat);
paul718e3742002-12-13 20:15:29 +00002146 if (ret < 0 && errno != ENOENT)
2147 {
2148 fprintf (stderr, "vtysh_connect(%s): stat = %s\n",
ajsb1aa1472005-01-28 21:11:46 +00002149 vclient->path, safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002150 exit(1);
2151 }
2152
2153 if (ret >= 0)
2154 {
2155 if (! S_ISSOCK(s_stat.st_mode))
2156 {
2157 fprintf (stderr, "vtysh_connect(%s): Not a socket\n",
ajsb1aa1472005-01-28 21:11:46 +00002158 vclient->path);
paul718e3742002-12-13 20:15:29 +00002159 exit (1);
2160 }
2161
paul718e3742002-12-13 20:15:29 +00002162 }
2163
2164 sock = socket (AF_UNIX, SOCK_STREAM, 0);
2165 if (sock < 0)
2166 {
2167#ifdef DEBUG
ajsb1aa1472005-01-28 21:11:46 +00002168 fprintf(stderr, "vtysh_connect(%s): socket = %s\n", vclient->path,
ajs6099b3b2004-11-20 02:06:59 +00002169 safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002170#endif /* DEBUG */
2171 return -1;
2172 }
2173
2174 memset (&addr, 0, sizeof (struct sockaddr_un));
2175 addr.sun_family = AF_UNIX;
ajsb1aa1472005-01-28 21:11:46 +00002176 strncpy (addr.sun_path, vclient->path, strlen (vclient->path));
Paul Jakma6f0e3f62007-05-10 02:38:51 +00002177#ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
paul718e3742002-12-13 20:15:29 +00002178 len = addr.sun_len = SUN_LEN(&addr);
2179#else
2180 len = sizeof (addr.sun_family) + strlen (addr.sun_path);
Paul Jakma6f0e3f62007-05-10 02:38:51 +00002181#endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
paul718e3742002-12-13 20:15:29 +00002182
2183 ret = connect (sock, (struct sockaddr *) &addr, len);
2184 if (ret < 0)
2185 {
2186#ifdef DEBUG
ajsb1aa1472005-01-28 21:11:46 +00002187 fprintf(stderr, "vtysh_connect(%s): connect = %s\n", vclient->path,
ajs6099b3b2004-11-20 02:06:59 +00002188 safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002189#endif /* DEBUG */
2190 close (sock);
2191 return -1;
2192 }
2193 vclient->fd = sock;
2194
2195 return 0;
2196}
2197
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002198int
2199vtysh_connect_all(const char *daemon_name)
paul718e3742002-12-13 20:15:29 +00002200{
ajsb1aa1472005-01-28 21:11:46 +00002201 u_int i;
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002202 int rc = 0;
2203 int matches = 0;
ajsb1aa1472005-01-28 21:11:46 +00002204
Balaji.G837d16c2012-09-26 14:09:10 +05302205 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00002206 {
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002207 if (!daemon_name || !strcmp(daemon_name, vtysh_client[i].name))
2208 {
2209 matches++;
2210 if (vtysh_connect(&vtysh_client[i]) == 0)
2211 rc++;
2212 /* We need direct access to ripd in vtysh_exit_ripd_only. */
2213 if (vtysh_client[i].flag == VTYSH_RIPD)
2214 ripd_client = &vtysh_client[i];
2215 }
ajsb1aa1472005-01-28 21:11:46 +00002216 }
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002217 if (!matches)
2218 fprintf(stderr, "Error: no daemons match name %s!\n", daemon_name);
2219 return rc;
paul718e3742002-12-13 20:15:29 +00002220}
2221
hasso95e735b2004-08-26 13:08:30 +00002222/* To disable readline's filename completion. */
ajs274a4a42004-12-07 15:39:31 +00002223static char *
pauldfc0d9b2003-04-18 23:55:29 +00002224vtysh_completion_entry_function (const char *ignore, int invoking_key)
paul718e3742002-12-13 20:15:29 +00002225{
pauldfc0d9b2003-04-18 23:55:29 +00002226 return NULL;
paul718e3742002-12-13 20:15:29 +00002227}
2228
2229void
ajsb1aa1472005-01-28 21:11:46 +00002230vtysh_readline_init (void)
paul718e3742002-12-13 20:15:29 +00002231{
2232 /* readline related settings. */
Sébastien Luttringer66d2ead2014-05-27 19:55:11 +02002233 rl_bind_key ('?', (rl_command_func_t *) vtysh_rl_describe);
paul68980082003-03-25 05:07:42 +00002234 rl_completion_entry_function = vtysh_completion_entry_function;
Sébastien Luttringer66d2ead2014-05-27 19:55:11 +02002235 rl_attempted_completion_function = (rl_completion_func_t *)new_completion;
paul718e3742002-12-13 20:15:29 +00002236}
2237
2238char *
ajsb1aa1472005-01-28 21:11:46 +00002239vtysh_prompt (void)
paul718e3742002-12-13 20:15:29 +00002240{
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002241 static struct utsname names;
paul718e3742002-12-13 20:15:29 +00002242 static char buf[100];
2243 const char*hostname;
2244 extern struct host host;
2245
2246 hostname = host.name;
2247
2248 if (!hostname)
2249 {
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002250 if (!names.nodename[0])
2251 uname (&names);
paul718e3742002-12-13 20:15:29 +00002252 hostname = names.nodename;
2253 }
2254
2255 snprintf (buf, sizeof buf, cmd_prompt (vty->node), hostname);
2256
2257 return buf;
2258}
2259
2260void
ajsb1aa1472005-01-28 21:11:46 +00002261vtysh_init_vty (void)
paul718e3742002-12-13 20:15:29 +00002262{
2263 /* Make vty structure. */
2264 vty = vty_new ();
2265 vty->type = VTY_SHELL;
2266 vty->node = VIEW_NODE;
2267
2268 /* Initialize commands. */
2269 cmd_init (0);
2270
2271 /* Install nodes. */
2272 install_node (&bgp_node, NULL);
2273 install_node (&rip_node, NULL);
2274 install_node (&interface_node, NULL);
2275 install_node (&rmap_node, NULL);
2276 install_node (&zebra_node, NULL);
2277 install_node (&bgp_vpnv4_node, NULL);
2278 install_node (&bgp_ipv4_node, NULL);
2279 install_node (&bgp_ipv4m_node, NULL);
2280/* #ifdef HAVE_IPV6 */
2281 install_node (&bgp_ipv6_node, NULL);
paul57b5b7e2005-08-22 22:44:29 +00002282 install_node (&bgp_ipv6m_node, NULL);
paul718e3742002-12-13 20:15:29 +00002283/* #endif */
2284 install_node (&ospf_node, NULL);
2285/* #ifdef HAVE_IPV6 */
2286 install_node (&ripng_node, NULL);
2287 install_node (&ospf6_node, NULL);
2288/* #endif */
David Lamparteree53c8b2015-05-23 05:45:59 +02002289 install_node (&babel_node, NULL);
paul718e3742002-12-13 20:15:29 +00002290 install_node (&keychain_node, NULL);
2291 install_node (&keychain_key_node, NULL);
hassoc25e4582003-12-23 10:39:08 +00002292 install_node (&isis_node, NULL);
hassoe7168df2004-10-03 20:11:32 +00002293 install_node (&vty_node, NULL);
paul718e3742002-12-13 20:15:29 +00002294
2295 vtysh_install_default (VIEW_NODE);
2296 vtysh_install_default (ENABLE_NODE);
2297 vtysh_install_default (CONFIG_NODE);
2298 vtysh_install_default (BGP_NODE);
2299 vtysh_install_default (RIP_NODE);
2300 vtysh_install_default (INTERFACE_NODE);
2301 vtysh_install_default (RMAP_NODE);
2302 vtysh_install_default (ZEBRA_NODE);
2303 vtysh_install_default (BGP_VPNV4_NODE);
2304 vtysh_install_default (BGP_IPV4_NODE);
2305 vtysh_install_default (BGP_IPV4M_NODE);
2306 vtysh_install_default (BGP_IPV6_NODE);
paul57b5b7e2005-08-22 22:44:29 +00002307 vtysh_install_default (BGP_IPV6M_NODE);
paul718e3742002-12-13 20:15:29 +00002308 vtysh_install_default (OSPF_NODE);
2309 vtysh_install_default (RIPNG_NODE);
2310 vtysh_install_default (OSPF6_NODE);
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +01002311 vtysh_install_default (BABEL_NODE);
hassoc25e4582003-12-23 10:39:08 +00002312 vtysh_install_default (ISIS_NODE);
paul718e3742002-12-13 20:15:29 +00002313 vtysh_install_default (KEYCHAIN_NODE);
2314 vtysh_install_default (KEYCHAIN_KEY_NODE);
hassoe7168df2004-10-03 20:11:32 +00002315 vtysh_install_default (VTY_NODE);
paul718e3742002-12-13 20:15:29 +00002316
2317 install_element (VIEW_NODE, &vtysh_enable_cmd);
2318 install_element (ENABLE_NODE, &vtysh_config_terminal_cmd);
2319 install_element (ENABLE_NODE, &vtysh_disable_cmd);
2320
2321 /* "exit" command. */
2322 install_element (VIEW_NODE, &vtysh_exit_all_cmd);
2323 install_element (VIEW_NODE, &vtysh_quit_all_cmd);
2324 install_element (CONFIG_NODE, &vtysh_exit_all_cmd);
2325 /* install_element (CONFIG_NODE, &vtysh_quit_all_cmd); */
2326 install_element (ENABLE_NODE, &vtysh_exit_all_cmd);
2327 install_element (ENABLE_NODE, &vtysh_quit_all_cmd);
2328 install_element (RIP_NODE, &vtysh_exit_ripd_cmd);
2329 install_element (RIP_NODE, &vtysh_quit_ripd_cmd);
paul68980082003-03-25 05:07:42 +00002330 install_element (RIPNG_NODE, &vtysh_exit_ripngd_cmd);
2331 install_element (RIPNG_NODE, &vtysh_quit_ripngd_cmd);
paul718e3742002-12-13 20:15:29 +00002332 install_element (OSPF_NODE, &vtysh_exit_ospfd_cmd);
2333 install_element (OSPF_NODE, &vtysh_quit_ospfd_cmd);
paul68980082003-03-25 05:07:42 +00002334 install_element (OSPF6_NODE, &vtysh_exit_ospf6d_cmd);
2335 install_element (OSPF6_NODE, &vtysh_quit_ospf6d_cmd);
paul718e3742002-12-13 20:15:29 +00002336 install_element (BGP_NODE, &vtysh_exit_bgpd_cmd);
2337 install_element (BGP_NODE, &vtysh_quit_bgpd_cmd);
2338 install_element (BGP_VPNV4_NODE, &vtysh_exit_bgpd_cmd);
2339 install_element (BGP_VPNV4_NODE, &vtysh_quit_bgpd_cmd);
2340 install_element (BGP_IPV4_NODE, &vtysh_exit_bgpd_cmd);
2341 install_element (BGP_IPV4_NODE, &vtysh_quit_bgpd_cmd);
2342 install_element (BGP_IPV4M_NODE, &vtysh_exit_bgpd_cmd);
2343 install_element (BGP_IPV4M_NODE, &vtysh_quit_bgpd_cmd);
2344 install_element (BGP_IPV6_NODE, &vtysh_exit_bgpd_cmd);
2345 install_element (BGP_IPV6_NODE, &vtysh_quit_bgpd_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002346 install_element (BGP_IPV6M_NODE, &vtysh_exit_bgpd_cmd);
2347 install_element (BGP_IPV6M_NODE, &vtysh_quit_bgpd_cmd);
hassoc25e4582003-12-23 10:39:08 +00002348 install_element (ISIS_NODE, &vtysh_exit_isisd_cmd);
2349 install_element (ISIS_NODE, &vtysh_quit_isisd_cmd);
paul718e3742002-12-13 20:15:29 +00002350 install_element (KEYCHAIN_NODE, &vtysh_exit_ripd_cmd);
2351 install_element (KEYCHAIN_NODE, &vtysh_quit_ripd_cmd);
2352 install_element (KEYCHAIN_KEY_NODE, &vtysh_exit_ripd_cmd);
2353 install_element (KEYCHAIN_KEY_NODE, &vtysh_quit_ripd_cmd);
2354 install_element (RMAP_NODE, &vtysh_exit_rmap_cmd);
2355 install_element (RMAP_NODE, &vtysh_quit_rmap_cmd);
hassoe7168df2004-10-03 20:11:32 +00002356 install_element (VTY_NODE, &vtysh_exit_line_vty_cmd);
2357 install_element (VTY_NODE, &vtysh_quit_line_vty_cmd);
paul718e3742002-12-13 20:15:29 +00002358
2359 /* "end" command. */
2360 install_element (CONFIG_NODE, &vtysh_end_all_cmd);
2361 install_element (ENABLE_NODE, &vtysh_end_all_cmd);
2362 install_element (RIP_NODE, &vtysh_end_all_cmd);
2363 install_element (RIPNG_NODE, &vtysh_end_all_cmd);
2364 install_element (OSPF_NODE, &vtysh_end_all_cmd);
2365 install_element (OSPF6_NODE, &vtysh_end_all_cmd);
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +01002366 install_element (BABEL_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002367 install_element (BGP_NODE, &vtysh_end_all_cmd);
2368 install_element (BGP_IPV4_NODE, &vtysh_end_all_cmd);
2369 install_element (BGP_IPV4M_NODE, &vtysh_end_all_cmd);
2370 install_element (BGP_VPNV4_NODE, &vtysh_end_all_cmd);
2371 install_element (BGP_IPV6_NODE, &vtysh_end_all_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002372 install_element (BGP_IPV6M_NODE, &vtysh_end_all_cmd);
hassoc25e4582003-12-23 10:39:08 +00002373 install_element (ISIS_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002374 install_element (KEYCHAIN_NODE, &vtysh_end_all_cmd);
2375 install_element (KEYCHAIN_KEY_NODE, &vtysh_end_all_cmd);
2376 install_element (RMAP_NODE, &vtysh_end_all_cmd);
hassoe7168df2004-10-03 20:11:32 +00002377 install_element (VTY_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002378
paul338a9912003-03-01 15:44:10 +00002379 install_element (INTERFACE_NODE, &interface_desc_cmd);
paul464dc8d2003-03-28 02:25:45 +00002380 install_element (INTERFACE_NODE, &no_interface_desc_cmd);
paul718e3742002-12-13 20:15:29 +00002381 install_element (INTERFACE_NODE, &vtysh_end_all_cmd);
2382 install_element (INTERFACE_NODE, &vtysh_exit_interface_cmd);
2383 install_element (INTERFACE_NODE, &vtysh_quit_interface_cmd);
2384 install_element (CONFIG_NODE, &router_rip_cmd);
2385#ifdef HAVE_IPV6
2386 install_element (CONFIG_NODE, &router_ripng_cmd);
2387#endif
2388 install_element (CONFIG_NODE, &router_ospf_cmd);
2389#ifdef HAVE_IPV6
2390 install_element (CONFIG_NODE, &router_ospf6_cmd);
2391#endif
hassoc25e4582003-12-23 10:39:08 +00002392 install_element (CONFIG_NODE, &router_isis_cmd);
paul718e3742002-12-13 20:15:29 +00002393 install_element (CONFIG_NODE, &router_bgp_cmd);
Paul Jakma10895fd2008-07-03 19:34:48 +00002394 install_element (CONFIG_NODE, &router_bgp_view_cmd);
paul718e3742002-12-13 20:15:29 +00002395 install_element (BGP_NODE, &address_family_vpnv4_cmd);
2396 install_element (BGP_NODE, &address_family_vpnv4_unicast_cmd);
2397 install_element (BGP_NODE, &address_family_ipv4_unicast_cmd);
2398 install_element (BGP_NODE, &address_family_ipv4_multicast_cmd);
2399#ifdef HAVE_IPV6
2400 install_element (BGP_NODE, &address_family_ipv6_cmd);
2401 install_element (BGP_NODE, &address_family_ipv6_unicast_cmd);
2402#endif
2403 install_element (BGP_VPNV4_NODE, &exit_address_family_cmd);
2404 install_element (BGP_IPV4_NODE, &exit_address_family_cmd);
2405 install_element (BGP_IPV4M_NODE, &exit_address_family_cmd);
2406 install_element (BGP_IPV6_NODE, &exit_address_family_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002407 install_element (BGP_IPV6M_NODE, &exit_address_family_cmd);
paul718e3742002-12-13 20:15:29 +00002408 install_element (CONFIG_NODE, &key_chain_cmd);
2409 install_element (CONFIG_NODE, &route_map_cmd);
hassoe7168df2004-10-03 20:11:32 +00002410 install_element (CONFIG_NODE, &vtysh_line_vty_cmd);
paul718e3742002-12-13 20:15:29 +00002411 install_element (KEYCHAIN_NODE, &key_cmd);
2412 install_element (KEYCHAIN_NODE, &key_chain_cmd);
2413 install_element (KEYCHAIN_KEY_NODE, &key_chain_cmd);
2414 install_element (CONFIG_NODE, &vtysh_interface_cmd);
paul32d24632003-05-23 09:25:20 +00002415 install_element (CONFIG_NODE, &vtysh_no_interface_cmd);
Feng Lu471ea392015-05-22 11:40:00 +02002416 install_element (CONFIG_NODE, &vtysh_interface_vrf_cmd);
2417 install_element (CONFIG_NODE, &vtysh_no_interface_vrf_cmd);
paul718e3742002-12-13 20:15:29 +00002418 install_element (ENABLE_NODE, &vtysh_show_running_config_cmd);
Donald Sharp9fb73e82015-09-22 11:13:12 -04002419 install_element (ENABLE_NODE, &vtysh_show_running_config_daemon_cmd);
paul718e3742002-12-13 20:15:29 +00002420 install_element (ENABLE_NODE, &vtysh_copy_runningconfig_startupconfig_cmd);
2421 install_element (ENABLE_NODE, &vtysh_write_file_cmd);
hasso4a6e2252003-05-25 11:51:29 +00002422 install_element (ENABLE_NODE, &vtysh_write_cmd);
paul718e3742002-12-13 20:15:29 +00002423
hasso95e735b2004-08-26 13:08:30 +00002424 /* "write terminal" command. */
paul718e3742002-12-13 20:15:29 +00002425 install_element (ENABLE_NODE, &vtysh_write_terminal_cmd);
Donald Sharp9fb73e82015-09-22 11:13:12 -04002426 install_element (ENABLE_NODE, &vtysh_write_terminal_daemon_cmd);
hassoe7168df2004-10-03 20:11:32 +00002427
2428 install_element (CONFIG_NODE, &vtysh_integrated_config_cmd);
2429 install_element (CONFIG_NODE, &no_vtysh_integrated_config_cmd);
paul718e3742002-12-13 20:15:29 +00002430
hasso95e735b2004-08-26 13:08:30 +00002431 /* "write memory" command. */
paul718e3742002-12-13 20:15:29 +00002432 install_element (ENABLE_NODE, &vtysh_write_memory_cmd);
paul718e3742002-12-13 20:15:29 +00002433
hasso34553cc2004-08-27 13:56:39 +00002434 install_element (VIEW_NODE, &vtysh_terminal_length_cmd);
2435 install_element (ENABLE_NODE, &vtysh_terminal_length_cmd);
2436 install_element (VIEW_NODE, &vtysh_terminal_no_length_cmd);
2437 install_element (ENABLE_NODE, &vtysh_terminal_no_length_cmd);
hassof2799e62004-10-28 17:43:11 +00002438 install_element (VIEW_NODE, &vtysh_show_daemons_cmd);
2439 install_element (ENABLE_NODE, &vtysh_show_daemons_cmd);
hasso34553cc2004-08-27 13:56:39 +00002440
paul718e3742002-12-13 20:15:29 +00002441 install_element (VIEW_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002442 install_element (VIEW_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00002443 install_element (VIEW_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002444 install_element (VIEW_NODE, &vtysh_traceroute_ip_cmd);
2445#ifdef HAVE_IPV6
2446 install_element (VIEW_NODE, &vtysh_ping6_cmd);
2447 install_element (VIEW_NODE, &vtysh_traceroute6_cmd);
2448#endif
paul718e3742002-12-13 20:15:29 +00002449 install_element (VIEW_NODE, &vtysh_telnet_cmd);
2450 install_element (VIEW_NODE, &vtysh_telnet_port_cmd);
paul5087df52003-01-25 06:56:09 +00002451 install_element (VIEW_NODE, &vtysh_ssh_cmd);
paul718e3742002-12-13 20:15:29 +00002452 install_element (ENABLE_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002453 install_element (ENABLE_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00002454 install_element (ENABLE_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002455 install_element (ENABLE_NODE, &vtysh_traceroute_ip_cmd);
2456#ifdef HAVE_IPV6
2457 install_element (ENABLE_NODE, &vtysh_ping6_cmd);
2458 install_element (ENABLE_NODE, &vtysh_traceroute6_cmd);
2459#endif
paul718e3742002-12-13 20:15:29 +00002460 install_element (ENABLE_NODE, &vtysh_telnet_cmd);
2461 install_element (ENABLE_NODE, &vtysh_telnet_port_cmd);
hasso67e29ab2004-08-26 22:21:31 +00002462 install_element (ENABLE_NODE, &vtysh_ssh_cmd);
paul718e3742002-12-13 20:15:29 +00002463 install_element (ENABLE_NODE, &vtysh_start_shell_cmd);
2464 install_element (ENABLE_NODE, &vtysh_start_bash_cmd);
2465 install_element (ENABLE_NODE, &vtysh_start_zsh_cmd);
Paul Jakmadbf7d132006-05-23 22:10:01 +00002466
Paul Jakma362b4032006-05-28 07:54:45 +00002467 install_element (VIEW_NODE, &vtysh_show_memory_cmd);
2468 install_element (ENABLE_NODE, &vtysh_show_memory_cmd);
2469
Donald Sharp567a6382015-08-19 21:22:17 -04002470 install_element (VIEW_NODE, &vtysh_show_work_queues_cmd);
2471 install_element (ENABLE_NODE, &vtysh_show_work_queues_cmd);
2472
2473 install_element (VIEW_NODE, &vtysh_show_thread_cmd);
2474 install_element (ENABLE_NODE, &vtysh_show_thread_cmd);
2475
Paul Jakmadbf7d132006-05-23 22:10:01 +00002476 /* Logging */
2477 install_element (ENABLE_NODE, &vtysh_show_logging_cmd);
2478 install_element (VIEW_NODE, &vtysh_show_logging_cmd);
paul718e3742002-12-13 20:15:29 +00002479 install_element (CONFIG_NODE, &vtysh_log_stdout_cmd);
ajs274a4a42004-12-07 15:39:31 +00002480 install_element (CONFIG_NODE, &vtysh_log_stdout_level_cmd);
paul718e3742002-12-13 20:15:29 +00002481 install_element (CONFIG_NODE, &no_vtysh_log_stdout_cmd);
2482 install_element (CONFIG_NODE, &vtysh_log_file_cmd);
ajs274a4a42004-12-07 15:39:31 +00002483 install_element (CONFIG_NODE, &vtysh_log_file_level_cmd);
paul718e3742002-12-13 20:15:29 +00002484 install_element (CONFIG_NODE, &no_vtysh_log_file_cmd);
ajs274a4a42004-12-07 15:39:31 +00002485 install_element (CONFIG_NODE, &no_vtysh_log_file_level_cmd);
2486 install_element (CONFIG_NODE, &vtysh_log_monitor_cmd);
2487 install_element (CONFIG_NODE, &vtysh_log_monitor_level_cmd);
2488 install_element (CONFIG_NODE, &no_vtysh_log_monitor_cmd);
paul718e3742002-12-13 20:15:29 +00002489 install_element (CONFIG_NODE, &vtysh_log_syslog_cmd);
ajs274a4a42004-12-07 15:39:31 +00002490 install_element (CONFIG_NODE, &vtysh_log_syslog_level_cmd);
paul718e3742002-12-13 20:15:29 +00002491 install_element (CONFIG_NODE, &no_vtysh_log_syslog_cmd);
2492 install_element (CONFIG_NODE, &vtysh_log_trap_cmd);
2493 install_element (CONFIG_NODE, &no_vtysh_log_trap_cmd);
ajs274a4a42004-12-07 15:39:31 +00002494 install_element (CONFIG_NODE, &vtysh_log_facility_cmd);
2495 install_element (CONFIG_NODE, &no_vtysh_log_facility_cmd);
paul718e3742002-12-13 20:15:29 +00002496 install_element (CONFIG_NODE, &vtysh_log_record_priority_cmd);
2497 install_element (CONFIG_NODE, &no_vtysh_log_record_priority_cmd);
Andrew J. Schorrc749b722007-04-29 03:53:31 +00002498 install_element (CONFIG_NODE, &vtysh_log_timestamp_precision_cmd);
2499 install_element (CONFIG_NODE, &no_vtysh_log_timestamp_precision_cmd);
hassoe7168df2004-10-03 20:11:32 +00002500
2501 install_element (CONFIG_NODE, &vtysh_service_password_encrypt_cmd);
2502 install_element (CONFIG_NODE, &no_vtysh_service_password_encrypt_cmd);
2503
2504 install_element (CONFIG_NODE, &vtysh_password_cmd);
2505 install_element (CONFIG_NODE, &vtysh_password_text_cmd);
2506 install_element (CONFIG_NODE, &vtysh_enable_password_cmd);
2507 install_element (CONFIG_NODE, &vtysh_enable_password_text_cmd);
2508 install_element (CONFIG_NODE, &no_vtysh_enable_password_cmd);
2509
paul718e3742002-12-13 20:15:29 +00002510}