blob: a39889d001c91b65910b5d390b8031ea69d0a556 [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 {
Lou Berger82dd7072016-01-12 13:41:57 -0500283 if ((saved_node == BGP_VPNV4_NODE || saved_node == BGP_VPNV6_NODE
Lou Berger13c378d2016-01-12 13:41:56 -0500284 || saved_node == BGP_IPV4_NODE
paul57b5b7e2005-08-22 22:44:29 +0000285 || saved_node == BGP_IPV6_NODE || saved_node == BGP_IPV4M_NODE
286 || saved_node == BGP_IPV6M_NODE)
hasso13bfca72005-01-23 21:42:25 +0000287 && (tried == 1))
288 {
289 vtysh_execute("exit-address-family");
290 }
291 else if ((saved_node == KEYCHAIN_KEY_NODE) && (tried == 1))
292 {
293 vtysh_execute("exit");
294 }
295 else if (tried)
296 {
297 vtysh_execute ("end");
298 vtysh_execute ("configure terminal");
299 }
300 }
301 /* If command didn't succeed in any node, continue with return value from
302 * first try. */
303 else if (tried)
304 {
305 ret = saved_ret;
306 }
paul718e3742002-12-13 20:15:29 +0000307
308 cmd_free_strvec (vline);
309
Stephen Hemminger2c4d48b2008-07-28 15:04:56 -0700310 cmd_stat = ret;
paul718e3742002-12-13 20:15:29 +0000311 switch (ret)
312 {
313 case CMD_WARNING:
314 if (vty->type == VTY_FILE)
paul4fc01e62002-12-13 20:49:00 +0000315 fprintf (stdout,"Warning...\n");
paul718e3742002-12-13 20:15:29 +0000316 break;
317 case CMD_ERR_AMBIGUOUS:
paul4fc01e62002-12-13 20:49:00 +0000318 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000319 break;
320 case CMD_ERR_NO_MATCH:
paul4fc01e62002-12-13 20:49:00 +0000321 fprintf (stdout,"%% Unknown command.\n");
paul718e3742002-12-13 20:15:29 +0000322 break;
323 case CMD_ERR_INCOMPLETE:
paul4fc01e62002-12-13 20:49:00 +0000324 fprintf (stdout,"%% Command incomplete.\n");
paul718e3742002-12-13 20:15:29 +0000325 break;
326 case CMD_SUCCESS_DAEMON:
327 {
hasso97b7db22004-10-20 19:07:48 +0000328 /* FIXME: Don't open pager for exit commands. popen() causes problems
329 * if exited from vtysh at all. This hack shouldn't cause any problem
330 * but is really ugly. */
331 if (pager && vtysh_pager_name && (strncmp(line, "exit", 4) != 0))
paul718e3742002-12-13 20:15:29 +0000332 {
paul4fc01e62002-12-13 20:49:00 +0000333 fp = popen (vtysh_pager_name, "w");
paul718e3742002-12-13 20:15:29 +0000334 if (fp == NULL)
335 {
paula805cc22003-05-01 14:29:48 +0000336 perror ("popen failed for pager");
337 fp = stdout;
paul718e3742002-12-13 20:15:29 +0000338 }
paula805cc22003-05-01 14:29:48 +0000339 else
340 closepager=1;
paul718e3742002-12-13 20:15:29 +0000341 }
342 else
343 fp = stdout;
344
345 if (! strcmp(cmd->string,"configure terminal"))
346 {
Balaji.G837d16c2012-09-26 14:09:10 +0530347 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +0000348 {
349 cmd_stat = vtysh_client_execute(&vtysh_client[i], line, fp);
350 if (cmd_stat == CMD_WARNING)
351 break;
352 }
353
paul718e3742002-12-13 20:15:29 +0000354 if (cmd_stat)
355 {
hassob094d262004-08-25 12:22:00 +0000356 line = "end";
357 vline = cmd_make_strvec (line);
paul718e3742002-12-13 20:15:29 +0000358
hassob094d262004-08-25 12:22:00 +0000359 if (vline == NULL)
paul718e3742002-12-13 20:15:29 +0000360 {
paula805cc22003-05-01 14:29:48 +0000361 if (pager && vtysh_pager_name && fp && closepager)
paul718e3742002-12-13 20:15:29 +0000362 {
363 if (pclose (fp) == -1)
364 {
paula805cc22003-05-01 14:29:48 +0000365 perror ("pclose failed for pager");
paul718e3742002-12-13 20:15:29 +0000366 }
367 fp = NULL;
368 }
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700369 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000370 }
371
hasso87d683b2005-01-16 23:31:54 +0000372 ret = cmd_execute_command (vline, vty, &cmd, 1);
hassob094d262004-08-25 12:22:00 +0000373 cmd_free_strvec (vline);
374 if (ret != CMD_SUCCESS_DAEMON)
375 break;
paul718e3742002-12-13 20:15:29 +0000376 }
377 else
378 if (cmd->func)
379 {
380 (*cmd->func) (cmd, vty, 0, NULL);
381 break;
hassob094d262004-08-25 12:22:00 +0000382 }
paul718e3742002-12-13 20:15:29 +0000383 }
384
ajsb1aa1472005-01-28 21:11:46 +0000385 cmd_stat = CMD_SUCCESS;
Balaji.G837d16c2012-09-26 14:09:10 +0530386 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +0000387 {
388 if (cmd->daemon & vtysh_client[i].flag)
389 {
390 cmd_stat = vtysh_client_execute(&vtysh_client[i], line, fp);
391 if (cmd_stat != CMD_SUCCESS)
392 break;
393 }
394 }
395 if (cmd_stat != CMD_SUCCESS)
396 break;
397
paul718e3742002-12-13 20:15:29 +0000398 if (cmd->func)
399 (*cmd->func) (cmd, vty, 0, NULL);
400 }
401 }
paula805cc22003-05-01 14:29:48 +0000402 if (pager && vtysh_pager_name && fp && closepager)
paul718e3742002-12-13 20:15:29 +0000403 {
404 if (pclose (fp) == -1)
405 {
paula805cc22003-05-01 14:29:48 +0000406 perror ("pclose failed for pager");
paul718e3742002-12-13 20:15:29 +0000407 }
408 fp = NULL;
409 }
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700410 return cmd_stat;
paul718e3742002-12-13 20:15:29 +0000411}
412
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700413int
hassodda09522004-10-07 21:40:25 +0000414vtysh_execute_no_pager (const char *line)
paul718e3742002-12-13 20:15:29 +0000415{
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700416 return vtysh_execute_func (line, 0);
paul718e3742002-12-13 20:15:29 +0000417}
418
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700419int
hassodda09522004-10-07 21:40:25 +0000420vtysh_execute (const char *line)
paul718e3742002-12-13 20:15:29 +0000421{
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700422 return vtysh_execute_func (line, 1);
paul718e3742002-12-13 20:15:29 +0000423}
424
425/* Configration make from file. */
426int
427vtysh_config_from_file (struct vty *vty, FILE *fp)
428{
429 int ret;
paul718e3742002-12-13 20:15:29 +0000430 struct cmd_element *cmd;
431
432 while (fgets (vty->buf, VTY_BUFSIZ, fp))
433 {
Donald Sharpd8aa4be2015-09-28 20:10:40 -0400434 ret = command_config_read_one_line (vty, &cmd, 1);
paul718e3742002-12-13 20:15:29 +0000435
436 switch (ret)
437 {
438 case CMD_WARNING:
439 if (vty->type == VTY_FILE)
paul4fc01e62002-12-13 20:49:00 +0000440 fprintf (stdout,"Warning...\n");
paul718e3742002-12-13 20:15:29 +0000441 break;
442 case CMD_ERR_AMBIGUOUS:
paul4fc01e62002-12-13 20:49:00 +0000443 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000444 break;
445 case CMD_ERR_NO_MATCH:
paul4fc01e62002-12-13 20:49:00 +0000446 fprintf (stdout,"%% Unknown command: %s", vty->buf);
paul718e3742002-12-13 20:15:29 +0000447 break;
448 case CMD_ERR_INCOMPLETE:
paul4fc01e62002-12-13 20:49:00 +0000449 fprintf (stdout,"%% Command incomplete.\n");
paul718e3742002-12-13 20:15:29 +0000450 break;
451 case CMD_SUCCESS_DAEMON:
452 {
ajsb1aa1472005-01-28 21:11:46 +0000453 u_int i;
454 int cmd_stat = CMD_SUCCESS;
455
Balaji.G837d16c2012-09-26 14:09:10 +0530456 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +0000457 {
paul44316fe2006-01-11 01:38:25 +0000458 if (cmd->daemon & vtysh_client[i].flag)
ajsb1aa1472005-01-28 21:11:46 +0000459 {
460 cmd_stat = vtysh_client_execute (&vtysh_client[i],
461 vty->buf, stdout);
462 if (cmd_stat != CMD_SUCCESS)
463 break;
464 }
465 }
466 if (cmd_stat != CMD_SUCCESS)
467 break;
468
paul718e3742002-12-13 20:15:29 +0000469 if (cmd->func)
470 (*cmd->func) (cmd, vty, 0, NULL);
471 }
472 }
473 }
474 return CMD_SUCCESS;
475}
476
477/* We don't care about the point of the cursor when '?' is typed. */
David Lampartera9eb9062015-03-04 07:07:01 +0100478static int
ajsb1aa1472005-01-28 21:11:46 +0000479vtysh_rl_describe (void)
paul718e3742002-12-13 20:15:29 +0000480{
481 int ret;
hassodda09522004-10-07 21:40:25 +0000482 unsigned int i;
paul718e3742002-12-13 20:15:29 +0000483 vector vline;
484 vector describe;
485 int width;
Christian Frankecd40b322013-09-30 12:27:51 +0000486 struct cmd_token *token;
paul718e3742002-12-13 20:15:29 +0000487
488 vline = cmd_make_strvec (rl_line_buffer);
489
490 /* In case of '> ?'. */
491 if (vline == NULL)
492 {
493 vline = vector_init (1);
David Lampartera91a3ba2015-03-03 09:06:51 +0100494 vector_set (vline, NULL);
paul718e3742002-12-13 20:15:29 +0000495 }
496 else
497 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
David Lampartera91a3ba2015-03-03 09:06:51 +0100498 vector_set (vline, NULL);
paul718e3742002-12-13 20:15:29 +0000499
500 describe = cmd_describe_command (vline, vty, &ret);
501
paul4fc01e62002-12-13 20:49:00 +0000502 fprintf (stdout,"\n");
paul718e3742002-12-13 20:15:29 +0000503
504 /* Ambiguous and no match error. */
505 switch (ret)
506 {
507 case CMD_ERR_AMBIGUOUS:
508 cmd_free_strvec (vline);
paul4fc01e62002-12-13 20:49:00 +0000509 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000510 rl_on_new_line ();
511 return 0;
512 break;
513 case CMD_ERR_NO_MATCH:
514 cmd_free_strvec (vline);
paul4fc01e62002-12-13 20:49:00 +0000515 fprintf (stdout,"%% There is no matched command.\n");
paul718e3742002-12-13 20:15:29 +0000516 rl_on_new_line ();
517 return 0;
518 break;
519 }
520
521 /* Get width of command string. */
522 width = 0;
paul55468c82005-03-14 20:19:01 +0000523 for (i = 0; i < vector_active (describe); i++)
Christian Frankecd40b322013-09-30 12:27:51 +0000524 if ((token = vector_slot (describe, i)) != NULL)
paul718e3742002-12-13 20:15:29 +0000525 {
526 int len;
527
Christian Frankecd40b322013-09-30 12:27:51 +0000528 if (token->cmd[0] == '\0')
paul718e3742002-12-13 20:15:29 +0000529 continue;
530
Christian Frankecd40b322013-09-30 12:27:51 +0000531 len = strlen (token->cmd);
532 if (token->cmd[0] == '.')
paul718e3742002-12-13 20:15:29 +0000533 len--;
534
535 if (width < len)
536 width = len;
537 }
538
paul55468c82005-03-14 20:19:01 +0000539 for (i = 0; i < vector_active (describe); i++)
Christian Frankecd40b322013-09-30 12:27:51 +0000540 if ((token = vector_slot (describe, i)) != NULL)
paul718e3742002-12-13 20:15:29 +0000541 {
Christian Frankecd40b322013-09-30 12:27:51 +0000542 if (token->cmd[0] == '\0')
paul718e3742002-12-13 20:15:29 +0000543 continue;
544
Christian Frankecd40b322013-09-30 12:27:51 +0000545 if (! token->desc)
paul4fc01e62002-12-13 20:49:00 +0000546 fprintf (stdout," %-s\n",
Christian Frankecd40b322013-09-30 12:27:51 +0000547 token->cmd[0] == '.' ? token->cmd + 1 : token->cmd);
paul718e3742002-12-13 20:15:29 +0000548 else
paul4fc01e62002-12-13 20:49:00 +0000549 fprintf (stdout," %-*s %s\n",
hassob094d262004-08-25 12:22:00 +0000550 width,
Christian Frankecd40b322013-09-30 12:27:51 +0000551 token->cmd[0] == '.' ? token->cmd + 1 : token->cmd,
552 token->desc);
paul718e3742002-12-13 20:15:29 +0000553 }
554
555 cmd_free_strvec (vline);
556 vector_free (describe);
557
558 rl_on_new_line();
559
560 return 0;
561}
562
hasso95e735b2004-08-26 13:08:30 +0000563/* Result of cmd_complete_command() call will be stored here
564 * and used in new_completion() in order to put the space in
565 * correct places only. */
paul718e3742002-12-13 20:15:29 +0000566int complete_status;
567
ajs274a4a42004-12-07 15:39:31 +0000568static char *
pauldfc0d9b2003-04-18 23:55:29 +0000569command_generator (const char *text, int state)
paul718e3742002-12-13 20:15:29 +0000570{
571 vector vline;
572 static char **matched = NULL;
573 static int index = 0;
574
575 /* First call. */
576 if (! state)
577 {
578 index = 0;
579
580 if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
581 return NULL;
582
583 vline = cmd_make_strvec (rl_line_buffer);
584 if (vline == NULL)
585 return NULL;
586
587 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
David Lampartera91a3ba2015-03-03 09:06:51 +0100588 vector_set (vline, NULL);
paul718e3742002-12-13 20:15:29 +0000589
590 matched = cmd_complete_command (vline, vty, &complete_status);
591 }
592
593 if (matched && matched[index])
594 return matched[index++];
595
596 return NULL;
597}
598
ajs274a4a42004-12-07 15:39:31 +0000599static char **
paul718e3742002-12-13 20:15:29 +0000600new_completion (char *text, int start, int end)
601{
602 char **matches;
603
pauldfc0d9b2003-04-18 23:55:29 +0000604 matches = rl_completion_matches (text, command_generator);
paul718e3742002-12-13 20:15:29 +0000605
606 if (matches)
607 {
608 rl_point = rl_end;
Christian Franke67e7a212013-03-04 09:23:30 +0000609 if (complete_status != CMD_COMPLETE_FULL_MATCH)
610 /* only append a space on full match */
611 rl_completion_append_character = '\0';
paul718e3742002-12-13 20:15:29 +0000612 }
613
614 return matches;
615}
616
ajs274a4a42004-12-07 15:39:31 +0000617#if 0
618/* This function is not actually being used. */
619static char **
paul718e3742002-12-13 20:15:29 +0000620vtysh_completion (char *text, int start, int end)
621{
622 int ret;
623 vector vline;
624 char **matched = NULL;
625
626 if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
627 return NULL;
628
629 vline = cmd_make_strvec (rl_line_buffer);
630 if (vline == NULL)
631 return NULL;
632
633 /* In case of 'help \t'. */
634 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
635 vector_set (vline, '\0');
636
637 matched = cmd_complete_command (vline, vty, &ret);
638
639 cmd_free_strvec (vline);
640
641 return (char **) matched;
642}
ajs274a4a42004-12-07 15:39:31 +0000643#endif
paul718e3742002-12-13 20:15:29 +0000644
hasso95e735b2004-08-26 13:08:30 +0000645/* Vty node structures. */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800646static struct cmd_node bgp_node =
paul718e3742002-12-13 20:15:29 +0000647{
648 BGP_NODE,
649 "%s(config-router)# ",
650};
651
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800652static struct cmd_node rip_node =
paul718e3742002-12-13 20:15:29 +0000653{
654 RIP_NODE,
655 "%s(config-router)# ",
656};
657
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800658static struct cmd_node isis_node =
hassoc25e4582003-12-23 10:39:08 +0000659{
660 ISIS_NODE,
661 "%s(config-router)# ",
hassoc25e4582003-12-23 10:39:08 +0000662};
663
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800664static struct cmd_node interface_node =
paul718e3742002-12-13 20:15:29 +0000665{
666 INTERFACE_NODE,
667 "%s(config-if)# ",
668};
669
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800670static struct cmd_node rmap_node =
hasso95e735b2004-08-26 13:08:30 +0000671{
672 RMAP_NODE,
673 "%s(config-route-map)# "
674};
675
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800676static struct cmd_node zebra_node =
hasso95e735b2004-08-26 13:08:30 +0000677{
678 ZEBRA_NODE,
679 "%s(config-router)# "
680};
681
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800682static struct cmd_node bgp_vpnv4_node =
hasso95e735b2004-08-26 13:08:30 +0000683{
684 BGP_VPNV4_NODE,
685 "%s(config-router-af)# "
686};
687
Lou Berger13c378d2016-01-12 13:41:56 -0500688static struct cmd_node bgp_vpnv6_node =
689{
690 BGP_VPNV6_NODE,
691 "%s(config-router-af)# "
692};
693
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800694static struct cmd_node bgp_ipv4_node =
hasso95e735b2004-08-26 13:08:30 +0000695{
696 BGP_IPV4_NODE,
697 "%s(config-router-af)# "
698};
699
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800700static struct cmd_node bgp_ipv4m_node =
hasso95e735b2004-08-26 13:08:30 +0000701{
702 BGP_IPV4M_NODE,
703 "%s(config-router-af)# "
704};
705
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800706static struct cmd_node bgp_ipv6_node =
hasso95e735b2004-08-26 13:08:30 +0000707{
708 BGP_IPV6_NODE,
709 "%s(config-router-af)# "
710};
711
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800712static struct cmd_node bgp_ipv6m_node =
paul57b5b7e2005-08-22 22:44:29 +0000713{
714 BGP_IPV6M_NODE,
715 "%s(config-router-af)# "
716};
717
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800718static struct cmd_node ospf_node =
hasso95e735b2004-08-26 13:08:30 +0000719{
720 OSPF_NODE,
721 "%s(config-router)# "
722};
723
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800724static struct cmd_node ripng_node =
hasso95e735b2004-08-26 13:08:30 +0000725{
726 RIPNG_NODE,
727 "%s(config-router)# "
728};
729
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800730static struct cmd_node ospf6_node =
hasso95e735b2004-08-26 13:08:30 +0000731{
732 OSPF6_NODE,
733 "%s(config-ospf6)# "
734};
735
David Lamparteree53c8b2015-05-23 05:45:59 +0200736static struct cmd_node babel_node =
737{
738 BABEL_NODE,
739 "%s(config-babel)# "
740};
741
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800742static struct cmd_node keychain_node =
hasso95e735b2004-08-26 13:08:30 +0000743{
744 KEYCHAIN_NODE,
745 "%s(config-keychain)# "
746};
747
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800748static struct cmd_node keychain_key_node =
hasso95e735b2004-08-26 13:08:30 +0000749{
750 KEYCHAIN_KEY_NODE,
751 "%s(config-keychain-key)# "
752};
753
hassoe7168df2004-10-03 20:11:32 +0000754/* Defined in lib/vty.c */
755extern struct cmd_node vty_node;
756
hasso95e735b2004-08-26 13:08:30 +0000757/* When '^Z' is received from vty, move down to the enable mode. */
David Lampartera9eb9062015-03-04 07:07:01 +0100758static int
ajsb1aa1472005-01-28 21:11:46 +0000759vtysh_end (void)
hasso95e735b2004-08-26 13:08:30 +0000760{
761 switch (vty->node)
762 {
763 case VIEW_NODE:
764 case ENABLE_NODE:
765 /* Nothing to do. */
766 break;
767 default:
768 vty->node = ENABLE_NODE;
769 break;
770 }
771 return CMD_SUCCESS;
772}
773
774DEFUNSH (VTYSH_ALL,
775 vtysh_end_all,
776 vtysh_end_all_cmd,
777 "end",
hassoe7168df2004-10-03 20:11:32 +0000778 "End current mode and change to enable mode\n")
hasso95e735b2004-08-26 13:08:30 +0000779{
hasso42895462004-09-26 16:25:07 +0000780 return vtysh_end ();
hasso95e735b2004-08-26 13:08:30 +0000781}
782
paul718e3742002-12-13 20:15:29 +0000783DEFUNSH (VTYSH_BGPD,
784 router_bgp,
785 router_bgp_cmd,
Paul Jakma320da872008-07-02 13:40:33 +0000786 "router bgp " CMD_AS_RANGE,
paul718e3742002-12-13 20:15:29 +0000787 ROUTER_STR
788 BGP_STR
789 AS_STR)
790{
791 vty->node = BGP_NODE;
792 return CMD_SUCCESS;
793}
794
Paul Jakma10895fd2008-07-03 19:34:48 +0000795ALIAS_SH (VTYSH_BGPD,
796 router_bgp,
797 router_bgp_view_cmd,
798 "router bgp " CMD_AS_RANGE " view WORD",
799 ROUTER_STR
800 BGP_STR
801 AS_STR
802 "BGP view\n"
803 "view name\n")
804
paul718e3742002-12-13 20:15:29 +0000805DEFUNSH (VTYSH_BGPD,
806 address_family_vpnv4,
807 address_family_vpnv4_cmd,
808 "address-family vpnv4",
809 "Enter Address Family command mode\n"
810 "Address family\n")
811{
812 vty->node = BGP_VPNV4_NODE;
813 return CMD_SUCCESS;
814}
815
816DEFUNSH (VTYSH_BGPD,
817 address_family_vpnv4_unicast,
818 address_family_vpnv4_unicast_cmd,
819 "address-family vpnv4 unicast",
820 "Enter Address Family command mode\n"
821 "Address family\n"
822 "Address Family Modifier\n")
823{
824 vty->node = BGP_VPNV4_NODE;
825 return CMD_SUCCESS;
826}
827
828DEFUNSH (VTYSH_BGPD,
Lou Berger13c378d2016-01-12 13:41:56 -0500829 address_family_vpnv6,
830 address_family_vpnv6_cmd,
831 "address-family vpnv6",
832 "Enter Address Family command mode\n"
833 "Address family\n")
834{
835 vty->node = BGP_VPNV6_NODE;
836 return CMD_SUCCESS;
837}
838
839DEFUNSH (VTYSH_BGPD,
840 address_family_vpnv6_unicast,
841 address_family_vpnv6_unicast_cmd,
842 "address-family vpnv6 unicast",
843 "Enter Address Family command mode\n"
844 "Address family\n"
845 "Address Family Modifier\n")
846{
847 vty->node = BGP_VPNV6_NODE;
848 return CMD_SUCCESS;
849}
850
851DEFUNSH (VTYSH_BGPD,
paul718e3742002-12-13 20:15:29 +0000852 address_family_ipv4_unicast,
853 address_family_ipv4_unicast_cmd,
854 "address-family ipv4 unicast",
855 "Enter Address Family command mode\n"
856 "Address family\n"
857 "Address Family Modifier\n")
858{
859 vty->node = BGP_IPV4_NODE;
860 return CMD_SUCCESS;
861}
862
863DEFUNSH (VTYSH_BGPD,
864 address_family_ipv4_multicast,
865 address_family_ipv4_multicast_cmd,
866 "address-family ipv4 multicast",
867 "Enter Address Family command mode\n"
868 "Address family\n"
869 "Address Family Modifier\n")
870{
871 vty->node = BGP_IPV4M_NODE;
872 return CMD_SUCCESS;
873}
874
875DEFUNSH (VTYSH_BGPD,
876 address_family_ipv6,
877 address_family_ipv6_cmd,
878 "address-family ipv6",
879 "Enter Address Family command mode\n"
880 "Address family\n")
881{
882 vty->node = BGP_IPV6_NODE;
883 return CMD_SUCCESS;
884}
885
886DEFUNSH (VTYSH_BGPD,
887 address_family_ipv6_unicast,
888 address_family_ipv6_unicast_cmd,
889 "address-family ipv6 unicast",
890 "Enter Address Family command mode\n"
891 "Address family\n"
892 "Address Family Modifier\n")
893{
894 vty->node = BGP_IPV6_NODE;
895 return CMD_SUCCESS;
896}
897
paul57b5b7e2005-08-22 22:44:29 +0000898DEFUNSH (VTYSH_BGPD,
899 address_family_ipv6_multicast,
900 address_family_ipv6_multicast_cmd,
901 "address-family ipv6 multicast",
902 "Enter Address Family command mode\n"
903 "Address family\n"
904 "Address Family Modifier\n")
905{
906 vty->node = BGP_IPV6M_NODE;
907 return CMD_SUCCESS;
908}
909
paul718e3742002-12-13 20:15:29 +0000910DEFUNSH (VTYSH_RIPD,
911 key_chain,
912 key_chain_cmd,
913 "key chain WORD",
914 "Authentication key management\n"
915 "Key-chain management\n"
916 "Key-chain name\n")
917{
918 vty->node = KEYCHAIN_NODE;
919 return CMD_SUCCESS;
920}
921
922DEFUNSH (VTYSH_RIPD,
923 key,
924 key_cmd,
925 "key <0-2147483647>",
926 "Configure a key\n"
927 "Key identifier number\n")
928{
929 vty->node = KEYCHAIN_KEY_NODE;
930 return CMD_SUCCESS;
931}
932
933DEFUNSH (VTYSH_RIPD,
934 router_rip,
935 router_rip_cmd,
936 "router rip",
937 ROUTER_STR
938 "RIP")
939{
940 vty->node = RIP_NODE;
941 return CMD_SUCCESS;
942}
943
944DEFUNSH (VTYSH_RIPNGD,
945 router_ripng,
946 router_ripng_cmd,
947 "router ripng",
948 ROUTER_STR
949 "RIPng")
950{
951 vty->node = RIPNG_NODE;
952 return CMD_SUCCESS;
953}
954
955DEFUNSH (VTYSH_OSPFD,
956 router_ospf,
957 router_ospf_cmd,
958 "router ospf",
959 "Enable a routing process\n"
960 "Start OSPF configuration\n")
961{
962 vty->node = OSPF_NODE;
963 return CMD_SUCCESS;
964}
965
966DEFUNSH (VTYSH_OSPF6D,
967 router_ospf6,
968 router_ospf6_cmd,
969 "router ospf6",
970 OSPF6_ROUTER_STR
971 OSPF6_STR)
972{
973 vty->node = OSPF6_NODE;
974 return CMD_SUCCESS;
975}
976
hassoc25e4582003-12-23 10:39:08 +0000977DEFUNSH (VTYSH_ISISD,
hassob094d262004-08-25 12:22:00 +0000978 router_isis,
979 router_isis_cmd,
980 "router isis WORD",
981 ROUTER_STR
982 "ISO IS-IS\n"
983 "ISO Routing area tag")
hassoc25e4582003-12-23 10:39:08 +0000984{
985 vty->node = ISIS_NODE;
986 return CMD_SUCCESS;
987}
988
paul718e3742002-12-13 20:15:29 +0000989DEFUNSH (VTYSH_RMAP,
990 route_map,
991 route_map_cmd,
992 "route-map WORD (deny|permit) <1-65535>",
993 "Create route-map or enter route-map command mode\n"
994 "Route map tag\n"
995 "Route map denies set operations\n"
996 "Route map permits set operations\n"
997 "Sequence to insert to/delete from existing route-map entry\n")
998{
999 vty->node = RMAP_NODE;
1000 return CMD_SUCCESS;
1001}
1002
paul718e3742002-12-13 20:15:29 +00001003DEFUNSH (VTYSH_ALL,
hassoe7168df2004-10-03 20:11:32 +00001004 vtysh_line_vty,
1005 vtysh_line_vty_cmd,
1006 "line vty",
1007 "Configure a terminal line\n"
1008 "Virtual terminal\n")
1009{
1010 vty->node = VTY_NODE;
1011 return CMD_SUCCESS;
1012}
1013
1014DEFUNSH (VTYSH_ALL,
paul718e3742002-12-13 20:15:29 +00001015 vtysh_enable,
1016 vtysh_enable_cmd,
1017 "enable",
1018 "Turn on privileged mode command\n")
1019{
1020 vty->node = ENABLE_NODE;
1021 return CMD_SUCCESS;
1022}
1023
paul718e3742002-12-13 20:15:29 +00001024DEFUNSH (VTYSH_ALL,
1025 vtysh_disable,
1026 vtysh_disable_cmd,
1027 "disable",
1028 "Turn off privileged mode command\n")
1029{
1030 if (vty->node == ENABLE_NODE)
1031 vty->node = VIEW_NODE;
1032 return CMD_SUCCESS;
1033}
1034
paul718e3742002-12-13 20:15:29 +00001035DEFUNSH (VTYSH_ALL,
1036 vtysh_config_terminal,
1037 vtysh_config_terminal_cmd,
1038 "configure terminal",
1039 "Configuration from vty interface\n"
1040 "Configuration terminal\n")
1041{
1042 vty->node = CONFIG_NODE;
1043 return CMD_SUCCESS;
1044}
1045
ajs274a4a42004-12-07 15:39:31 +00001046static int
paul718e3742002-12-13 20:15:29 +00001047vtysh_exit (struct vty *vty)
1048{
1049 switch (vty->node)
1050 {
1051 case VIEW_NODE:
1052 case ENABLE_NODE:
1053 exit (0);
1054 break;
1055 case CONFIG_NODE:
1056 vty->node = ENABLE_NODE;
1057 break;
1058 case INTERFACE_NODE:
1059 case ZEBRA_NODE:
1060 case BGP_NODE:
1061 case RIP_NODE:
1062 case RIPNG_NODE:
1063 case OSPF_NODE:
1064 case OSPF6_NODE:
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +01001065 case BABEL_NODE:
hassoc25e4582003-12-23 10:39:08 +00001066 case ISIS_NODE:
paul718e3742002-12-13 20:15:29 +00001067 case MASC_NODE:
1068 case RMAP_NODE:
1069 case VTY_NODE:
1070 case KEYCHAIN_NODE:
hasso2a56df92004-05-09 23:16:40 +00001071 vtysh_execute("end");
1072 vtysh_execute("configure terminal");
paul718e3742002-12-13 20:15:29 +00001073 vty->node = CONFIG_NODE;
1074 break;
1075 case BGP_VPNV4_NODE:
Lou Berger13c378d2016-01-12 13:41:56 -05001076 case BGP_VPNV6_NODE:
paul718e3742002-12-13 20:15:29 +00001077 case BGP_IPV4_NODE:
1078 case BGP_IPV4M_NODE:
1079 case BGP_IPV6_NODE:
paul57b5b7e2005-08-22 22:44:29 +00001080 case BGP_IPV6M_NODE:
paul718e3742002-12-13 20:15:29 +00001081 vty->node = BGP_NODE;
1082 break;
1083 case KEYCHAIN_KEY_NODE:
1084 vty->node = KEYCHAIN_NODE;
1085 break;
1086 default:
1087 break;
1088 }
1089 return CMD_SUCCESS;
1090}
1091
1092DEFUNSH (VTYSH_ALL,
1093 vtysh_exit_all,
1094 vtysh_exit_all_cmd,
1095 "exit",
1096 "Exit current mode and down to previous mode\n")
1097{
1098 return vtysh_exit (vty);
1099}
1100
1101ALIAS (vtysh_exit_all,
1102 vtysh_quit_all_cmd,
1103 "quit",
1104 "Exit current mode and down to previous mode\n")
1105
1106DEFUNSH (VTYSH_BGPD,
1107 exit_address_family,
1108 exit_address_family_cmd,
1109 "exit-address-family",
1110 "Exit from Address Family configuration mode\n")
1111{
1112 if (vty->node == BGP_IPV4_NODE
1113 || vty->node == BGP_IPV4M_NODE
1114 || vty->node == BGP_VPNV4_NODE
Lou Berger13c378d2016-01-12 13:41:56 -05001115 || vty->node == BGP_VPNV6_NODE
paul57b5b7e2005-08-22 22:44:29 +00001116 || vty->node == BGP_IPV6_NODE
1117 || vty->node == BGP_IPV6M_NODE)
paul718e3742002-12-13 20:15:29 +00001118 vty->node = BGP_NODE;
1119 return CMD_SUCCESS;
1120}
1121
1122DEFUNSH (VTYSH_ZEBRA,
1123 vtysh_exit_zebra,
1124 vtysh_exit_zebra_cmd,
1125 "exit",
1126 "Exit current mode and down to previous mode\n")
1127{
1128 return vtysh_exit (vty);
1129}
1130
1131ALIAS (vtysh_exit_zebra,
1132 vtysh_quit_zebra_cmd,
1133 "quit",
1134 "Exit current mode and down to previous mode\n")
1135
1136DEFUNSH (VTYSH_RIPD,
1137 vtysh_exit_ripd,
1138 vtysh_exit_ripd_cmd,
1139 "exit",
1140 "Exit current mode and down to previous mode\n")
1141{
1142 return vtysh_exit (vty);
1143}
1144
1145ALIAS (vtysh_exit_ripd,
1146 vtysh_quit_ripd_cmd,
1147 "quit",
1148 "Exit current mode and down to previous mode\n")
1149
paul68980082003-03-25 05:07:42 +00001150DEFUNSH (VTYSH_RIPNGD,
hassob094d262004-08-25 12:22:00 +00001151 vtysh_exit_ripngd,
1152 vtysh_exit_ripngd_cmd,
1153 "exit",
1154 "Exit current mode and down to previous mode\n")
paul68980082003-03-25 05:07:42 +00001155{
1156 return vtysh_exit (vty);
1157}
1158
1159ALIAS (vtysh_exit_ripngd,
1160 vtysh_quit_ripngd_cmd,
1161 "quit",
1162 "Exit current mode and down to previous mode\n")
1163
paul718e3742002-12-13 20:15:29 +00001164DEFUNSH (VTYSH_RMAP,
1165 vtysh_exit_rmap,
1166 vtysh_exit_rmap_cmd,
1167 "exit",
1168 "Exit current mode and down to previous mode\n")
1169{
1170 return vtysh_exit (vty);
1171}
1172
1173ALIAS (vtysh_exit_rmap,
1174 vtysh_quit_rmap_cmd,
1175 "quit",
1176 "Exit current mode and down to previous mode\n")
1177
1178DEFUNSH (VTYSH_BGPD,
1179 vtysh_exit_bgpd,
1180 vtysh_exit_bgpd_cmd,
1181 "exit",
1182 "Exit current mode and down to previous mode\n")
1183{
1184 return vtysh_exit (vty);
1185}
1186
1187ALIAS (vtysh_exit_bgpd,
1188 vtysh_quit_bgpd_cmd,
1189 "quit",
1190 "Exit current mode and down to previous mode\n")
1191
1192DEFUNSH (VTYSH_OSPFD,
1193 vtysh_exit_ospfd,
1194 vtysh_exit_ospfd_cmd,
1195 "exit",
1196 "Exit current mode and down to previous mode\n")
1197{
1198 return vtysh_exit (vty);
1199}
1200
1201ALIAS (vtysh_exit_ospfd,
1202 vtysh_quit_ospfd_cmd,
1203 "quit",
1204 "Exit current mode and down to previous mode\n")
1205
paul68980082003-03-25 05:07:42 +00001206DEFUNSH (VTYSH_OSPF6D,
hassob094d262004-08-25 12:22:00 +00001207 vtysh_exit_ospf6d,
1208 vtysh_exit_ospf6d_cmd,
1209 "exit",
1210 "Exit current mode and down to previous mode\n")
paul68980082003-03-25 05:07:42 +00001211{
1212 return vtysh_exit (vty);
1213}
1214
1215ALIAS (vtysh_exit_ospf6d,
1216 vtysh_quit_ospf6d_cmd,
1217 "quit",
1218 "Exit current mode and down to previous mode\n")
1219
hassoc25e4582003-12-23 10:39:08 +00001220DEFUNSH (VTYSH_ISISD,
hassob094d262004-08-25 12:22:00 +00001221 vtysh_exit_isisd,
1222 vtysh_exit_isisd_cmd,
1223 "exit",
1224 "Exit current mode and down to previous mode\n")
hassoc25e4582003-12-23 10:39:08 +00001225{
1226 return vtysh_exit (vty);
1227}
1228
1229ALIAS (vtysh_exit_isisd,
1230 vtysh_quit_isisd_cmd,
1231 "quit",
1232 "Exit current mode and down to previous mode\n")
1233
hassoe7168df2004-10-03 20:11:32 +00001234DEFUNSH (VTYSH_ALL,
1235 vtysh_exit_line_vty,
1236 vtysh_exit_line_vty_cmd,
1237 "exit",
1238 "Exit current mode and down to previous mode\n")
1239{
1240 return vtysh_exit (vty);
1241}
1242
1243ALIAS (vtysh_exit_line_vty,
1244 vtysh_quit_line_vty_cmd,
1245 "quit",
1246 "Exit current mode and down to previous mode\n")
1247
hasso95e735b2004-08-26 13:08:30 +00001248DEFUNSH (VTYSH_INTERFACE,
paul718e3742002-12-13 20:15:29 +00001249 vtysh_interface,
1250 vtysh_interface_cmd,
1251 "interface IFNAME",
1252 "Select an interface to configure\n"
1253 "Interface's name\n")
1254{
1255 vty->node = INTERFACE_NODE;
1256 return CMD_SUCCESS;
1257}
1258
Feng Lu471ea392015-05-22 11:40:00 +02001259ALIAS_SH (VTYSH_ZEBRA,
1260 vtysh_interface,
1261 vtysh_interface_vrf_cmd,
1262 "interface IFNAME " VRF_CMD_STR,
1263 "Select an interface to configure\n"
1264 "Interface's name\n"
1265 VRF_CMD_HELP_STR)
1266
hasso95e735b2004-08-26 13:08:30 +00001267/* TODO Implement "no interface command in isisd. */
paul32d24632003-05-23 09:25:20 +00001268DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D,
1269 vtysh_no_interface_cmd,
1270 "no interface IFNAME",
1271 NO_STR
1272 "Delete a pseudo interface's configuration\n"
1273 "Interface's name\n")
1274
Feng Lu471ea392015-05-22 11:40:00 +02001275DEFSH (VTYSH_ZEBRA,
1276 vtysh_no_interface_vrf_cmd,
1277 "no interface IFNAME " VRF_CMD_STR,
1278 NO_STR
1279 "Delete a pseudo interface's configuration\n"
1280 "Interface's name\n"
1281 VRF_CMD_HELP_STR)
1282
hasso95e735b2004-08-26 13:08:30 +00001283/* TODO Implement interface description commands in ripngd, ospf6d
1284 * and isisd. */
paul338a9912003-03-01 15:44:10 +00001285DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1286 interface_desc_cmd,
1287 "description .LINE",
1288 "Interface specific description\n"
1289 "Characters describing this interface\n")
paul464dc8d2003-03-28 02:25:45 +00001290
1291DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1292 no_interface_desc_cmd,
1293 "no description",
1294 NO_STR
1295 "Interface specific description\n")
paul338a9912003-03-01 15:44:10 +00001296
hasso95e735b2004-08-26 13:08:30 +00001297DEFUNSH (VTYSH_INTERFACE,
paul718e3742002-12-13 20:15:29 +00001298 vtysh_exit_interface,
1299 vtysh_exit_interface_cmd,
1300 "exit",
1301 "Exit current mode and down to previous mode\n")
1302{
1303 return vtysh_exit (vty);
1304}
1305
1306ALIAS (vtysh_exit_interface,
1307 vtysh_quit_interface_cmd,
1308 "quit",
1309 "Exit current mode and down to previous mode\n")
1310
Donald Sharp567a6382015-08-19 21:22:17 -04001311DEFUN (vtysh_show_thread,
1312 vtysh_show_thread_cmd,
1313 "show thread cpu [FILTER]",
1314 SHOW_STR
1315 "Thread information\n"
1316 "Thread CPU usage\n"
1317 "Display filter (rwtexb)\n")
1318{
1319 unsigned int i;
1320 int ret = CMD_SUCCESS;
1321 char line[100];
1322
1323 sprintf(line, "show thread cpu %s\n", (argc == 1) ? argv[0] : "");
1324 for (i = 0; i < array_size(vtysh_client); i++)
1325 if ( vtysh_client[i].fd >= 0 )
1326 {
1327 fprintf (stdout, "Thread statistics for %s:\n",
1328 vtysh_client[i].name);
1329 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1330 fprintf (stdout,"\n");
1331 }
1332 return ret;
1333}
1334
1335DEFUN (vtysh_show_work_queues,
1336 vtysh_show_work_queues_cmd,
1337 "show work-queues",
1338 SHOW_STR
1339 "Work Queue information\n")
1340{
1341 unsigned int i;
1342 int ret = CMD_SUCCESS;
1343 char line[] = "show work-queues\n";
1344
1345 for (i = 0; i < array_size(vtysh_client); i++)
1346 if ( vtysh_client[i].fd >= 0 )
1347 {
1348 fprintf (stdout, "Work queue statistics for %s:\n",
1349 vtysh_client[i].name);
1350 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1351 fprintf (stdout,"\n");
1352 }
1353
1354 return ret;
1355}
1356
Paul Jakma362b4032006-05-28 07:54:45 +00001357/* Memory */
1358DEFUN (vtysh_show_memory,
1359 vtysh_show_memory_cmd,
1360 "show memory",
1361 SHOW_STR
1362 "Memory statistics\n")
1363{
1364 unsigned int i;
1365 int ret = CMD_SUCCESS;
1366 char line[] = "show memory\n";
1367
Balaji.G837d16c2012-09-26 14:09:10 +05301368 for (i = 0; i < array_size(vtysh_client); i++)
Paul Jakma362b4032006-05-28 07:54:45 +00001369 if ( vtysh_client[i].fd >= 0 )
1370 {
1371 fprintf (stdout, "Memory statistics for %s:\n",
1372 vtysh_client[i].name);
1373 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1374 fprintf (stdout,"\n");
1375 }
1376
1377 return ret;
1378}
1379
hasso95e735b2004-08-26 13:08:30 +00001380/* Logging commands. */
Paul Jakmadbf7d132006-05-23 22:10:01 +00001381DEFUN (vtysh_show_logging,
1382 vtysh_show_logging_cmd,
1383 "show logging",
1384 SHOW_STR
1385 "Show current logging configuration\n")
1386{
1387 unsigned int i;
1388 int ret = CMD_SUCCESS;
1389 char line[] = "show logging\n";
1390
Balaji.G837d16c2012-09-26 14:09:10 +05301391 for (i = 0; i < array_size(vtysh_client); i++)
Paul Jakma4150f332006-05-23 22:10:55 +00001392 if ( vtysh_client[i].fd >= 0 )
1393 {
1394 fprintf (stdout,"Logging configuration for %s:\n",
1395 vtysh_client[i].name);
1396 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1397 fprintf (stdout,"\n");
1398 }
1399
Paul Jakmadbf7d132006-05-23 22:10:01 +00001400 return ret;
1401}
1402
hasso95e735b2004-08-26 13:08:30 +00001403DEFUNSH (VTYSH_ALL,
1404 vtysh_log_stdout,
1405 vtysh_log_stdout_cmd,
1406 "log stdout",
1407 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001408 "Set stdout logging level\n")
1409{
1410 return CMD_SUCCESS;
1411}
1412
1413DEFUNSH (VTYSH_ALL,
1414 vtysh_log_stdout_level,
1415 vtysh_log_stdout_level_cmd,
1416 "log stdout "LOG_LEVELS,
1417 "Logging control\n"
1418 "Set stdout logging level\n"
1419 LOG_LEVEL_DESC)
hasso95e735b2004-08-26 13:08:30 +00001420{
1421 return CMD_SUCCESS;
1422}
1423
1424DEFUNSH (VTYSH_ALL,
1425 no_vtysh_log_stdout,
1426 no_vtysh_log_stdout_cmd,
ajs274a4a42004-12-07 15:39:31 +00001427 "no log stdout [LEVEL]",
hasso95e735b2004-08-26 13:08:30 +00001428 NO_STR
1429 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001430 "Cancel logging to stdout\n"
1431 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001432{
1433 return CMD_SUCCESS;
1434}
1435
1436DEFUNSH (VTYSH_ALL,
1437 vtysh_log_file,
1438 vtysh_log_file_cmd,
1439 "log file FILENAME",
1440 "Logging control\n"
1441 "Logging to file\n"
1442 "Logging filename\n")
1443{
1444 return CMD_SUCCESS;
1445}
1446
1447DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001448 vtysh_log_file_level,
1449 vtysh_log_file_level_cmd,
1450 "log file FILENAME "LOG_LEVELS,
1451 "Logging control\n"
1452 "Logging to file\n"
1453 "Logging filename\n"
1454 LOG_LEVEL_DESC)
1455{
1456 return CMD_SUCCESS;
1457}
1458
1459DEFUNSH (VTYSH_ALL,
hasso95e735b2004-08-26 13:08:30 +00001460 no_vtysh_log_file,
1461 no_vtysh_log_file_cmd,
1462 "no log file [FILENAME]",
1463 NO_STR
1464 "Logging control\n"
1465 "Cancel logging to file\n"
1466 "Logging file name\n")
1467{
1468 return CMD_SUCCESS;
1469}
1470
ajs274a4a42004-12-07 15:39:31 +00001471ALIAS_SH (VTYSH_ALL,
1472 no_vtysh_log_file,
1473 no_vtysh_log_file_level_cmd,
1474 "no log file FILENAME LEVEL",
1475 NO_STR
1476 "Logging control\n"
1477 "Cancel logging to file\n"
1478 "Logging file name\n"
1479 "Logging level\n")
1480
1481DEFUNSH (VTYSH_ALL,
1482 vtysh_log_monitor,
1483 vtysh_log_monitor_cmd,
1484 "log monitor",
1485 "Logging control\n"
1486 "Set terminal line (monitor) logging level\n")
1487{
1488 return CMD_SUCCESS;
1489}
1490
1491DEFUNSH (VTYSH_ALL,
1492 vtysh_log_monitor_level,
1493 vtysh_log_monitor_level_cmd,
1494 "log monitor "LOG_LEVELS,
1495 "Logging control\n"
1496 "Set terminal line (monitor) logging level\n"
1497 LOG_LEVEL_DESC)
1498{
1499 return CMD_SUCCESS;
1500}
1501
1502DEFUNSH (VTYSH_ALL,
1503 no_vtysh_log_monitor,
1504 no_vtysh_log_monitor_cmd,
1505 "no log monitor [LEVEL]",
1506 NO_STR
1507 "Logging control\n"
1508 "Disable terminal line (monitor) logging\n"
1509 "Logging level\n")
1510{
1511 return CMD_SUCCESS;
1512}
1513
hasso95e735b2004-08-26 13:08:30 +00001514DEFUNSH (VTYSH_ALL,
1515 vtysh_log_syslog,
1516 vtysh_log_syslog_cmd,
1517 "log syslog",
1518 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001519 "Set syslog logging level\n")
1520{
1521 return CMD_SUCCESS;
1522}
1523
1524DEFUNSH (VTYSH_ALL,
1525 vtysh_log_syslog_level,
1526 vtysh_log_syslog_level_cmd,
1527 "log syslog "LOG_LEVELS,
1528 "Logging control\n"
1529 "Set syslog logging level\n"
1530 LOG_LEVEL_DESC)
hasso95e735b2004-08-26 13:08:30 +00001531{
1532 return CMD_SUCCESS;
1533}
1534
1535DEFUNSH (VTYSH_ALL,
1536 no_vtysh_log_syslog,
1537 no_vtysh_log_syslog_cmd,
ajs274a4a42004-12-07 15:39:31 +00001538 "no log syslog [LEVEL]",
hasso95e735b2004-08-26 13:08:30 +00001539 NO_STR
1540 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001541 "Cancel logging to syslog\n"
1542 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001543{
1544 return CMD_SUCCESS;
1545}
1546
1547DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001548 vtysh_log_facility,
1549 vtysh_log_facility_cmd,
1550 "log facility "LOG_FACILITIES,
hasso95e735b2004-08-26 13:08:30 +00001551 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001552 "Facility parameter for syslog messages\n"
1553 LOG_FACILITY_DESC)
1554
hasso95e735b2004-08-26 13:08:30 +00001555{
1556 return CMD_SUCCESS;
1557}
1558
1559DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001560 no_vtysh_log_facility,
1561 no_vtysh_log_facility_cmd,
1562 "no log facility [FACILITY]",
hasso95e735b2004-08-26 13:08:30 +00001563 NO_STR
1564 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001565 "Reset syslog facility to default (daemon)\n"
1566 "Syslog facility\n")
1567
1568{
1569 return CMD_SUCCESS;
1570}
1571
1572DEFUNSH_DEPRECATED (VTYSH_ALL,
1573 vtysh_log_trap,
1574 vtysh_log_trap_cmd,
1575 "log trap "LOG_LEVELS,
1576 "Logging control\n"
1577 "(Deprecated) Set logging level and default for all destinations\n"
1578 LOG_LEVEL_DESC)
1579
1580{
1581 return CMD_SUCCESS;
1582}
1583
1584DEFUNSH_DEPRECATED (VTYSH_ALL,
1585 no_vtysh_log_trap,
1586 no_vtysh_log_trap_cmd,
1587 "no log trap [LEVEL]",
1588 NO_STR
1589 "Logging control\n"
1590 "Permit all logging information\n"
1591 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001592{
1593 return CMD_SUCCESS;
1594}
1595
1596DEFUNSH (VTYSH_ALL,
1597 vtysh_log_record_priority,
1598 vtysh_log_record_priority_cmd,
1599 "log record-priority",
1600 "Logging control\n"
1601 "Log the priority of the message within the message\n")
1602{
1603 return CMD_SUCCESS;
1604}
1605
1606DEFUNSH (VTYSH_ALL,
1607 no_vtysh_log_record_priority,
1608 no_vtysh_log_record_priority_cmd,
1609 "no log record-priority",
1610 NO_STR
1611 "Logging control\n"
1612 "Do not log the priority of the message within the message\n")
1613{
1614 return CMD_SUCCESS;
1615}
1616
hassoe7168df2004-10-03 20:11:32 +00001617DEFUNSH (VTYSH_ALL,
Andrew J. Schorrc749b722007-04-29 03:53:31 +00001618 vtysh_log_timestamp_precision,
1619 vtysh_log_timestamp_precision_cmd,
1620 "log timestamp precision <0-6>",
1621 "Logging control\n"
1622 "Timestamp configuration\n"
1623 "Set the timestamp precision\n"
1624 "Number of subsecond digits\n")
1625{
1626 return CMD_SUCCESS;
1627}
1628
1629DEFUNSH (VTYSH_ALL,
1630 no_vtysh_log_timestamp_precision,
1631 no_vtysh_log_timestamp_precision_cmd,
1632 "no log timestamp precision",
1633 NO_STR
1634 "Logging control\n"
1635 "Timestamp configuration\n"
1636 "Reset the timestamp precision to the default value of 0\n")
1637{
1638 return CMD_SUCCESS;
1639}
1640
1641DEFUNSH (VTYSH_ALL,
hassoe7168df2004-10-03 20:11:32 +00001642 vtysh_service_password_encrypt,
1643 vtysh_service_password_encrypt_cmd,
1644 "service password-encryption",
1645 "Set up miscellaneous service\n"
1646 "Enable encrypted passwords\n")
1647{
1648 return CMD_SUCCESS;
1649}
1650
1651DEFUNSH (VTYSH_ALL,
1652 no_vtysh_service_password_encrypt,
1653 no_vtysh_service_password_encrypt_cmd,
1654 "no service password-encryption",
1655 NO_STR
1656 "Set up miscellaneous service\n"
1657 "Enable encrypted passwords\n")
1658{
1659 return CMD_SUCCESS;
1660}
1661
1662DEFUNSH (VTYSH_ALL,
1663 vtysh_config_password,
1664 vtysh_password_cmd,
1665 "password (8|) WORD",
1666 "Assign the terminal connection password\n"
1667 "Specifies a HIDDEN password will follow\n"
1668 "dummy string \n"
1669 "The HIDDEN line password string\n")
1670{
1671 return CMD_SUCCESS;
1672}
1673
1674DEFUNSH (VTYSH_ALL,
1675 vtysh_password_text,
1676 vtysh_password_text_cmd,
1677 "password LINE",
1678 "Assign the terminal connection password\n"
1679 "The UNENCRYPTED (cleartext) line password\n")
1680{
1681 return CMD_SUCCESS;
1682}
1683
1684DEFUNSH (VTYSH_ALL,
1685 vtysh_config_enable_password,
1686 vtysh_enable_password_cmd,
1687 "enable password (8|) WORD",
1688 "Modify enable password parameters\n"
1689 "Assign the privileged level password\n"
1690 "Specifies a HIDDEN password will follow\n"
1691 "dummy string \n"
1692 "The HIDDEN 'enable' password string\n")
1693{
1694 return CMD_SUCCESS;
1695}
1696
1697DEFUNSH (VTYSH_ALL,
1698 vtysh_enable_password_text,
1699 vtysh_enable_password_text_cmd,
1700 "enable password LINE",
1701 "Modify enable password parameters\n"
1702 "Assign the privileged level password\n"
1703 "The UNENCRYPTED (cleartext) 'enable' password\n")
1704{
1705 return CMD_SUCCESS;
1706}
1707
1708DEFUNSH (VTYSH_ALL,
1709 no_vtysh_config_enable_password,
1710 no_vtysh_enable_password_cmd,
1711 "no enable password",
1712 NO_STR
1713 "Modify enable password parameters\n"
1714 "Assign the privileged level password\n")
1715{
1716 return CMD_SUCCESS;
1717}
1718
paul718e3742002-12-13 20:15:29 +00001719DEFUN (vtysh_write_terminal,
1720 vtysh_write_terminal_cmd,
1721 "write terminal",
1722 "Write running configuration to memory, network, or terminal\n"
1723 "Write to terminal\n")
1724{
ajsb1aa1472005-01-28 21:11:46 +00001725 u_int i;
paul718e3742002-12-13 20:15:29 +00001726 char line[] = "write terminal\n";
1727 FILE *fp = NULL;
1728
1729 if (vtysh_pager_name)
1730 {
paul4fc01e62002-12-13 20:49:00 +00001731 fp = popen (vtysh_pager_name, "w");
paul718e3742002-12-13 20:15:29 +00001732 if (fp == NULL)
1733 {
1734 perror ("popen");
1735 exit (1);
1736 }
1737 }
1738 else
1739 fp = stdout;
1740
1741 vty_out (vty, "Building configuration...%s", VTY_NEWLINE);
1742 vty_out (vty, "%sCurrent configuration:%s", VTY_NEWLINE,
1743 VTY_NEWLINE);
hassoe7168df2004-10-03 20:11:32 +00001744 vty_out (vty, "!%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001745
Balaji.G837d16c2012-09-26 14:09:10 +05301746 for (i = 0; i < array_size(vtysh_client); i++)
Gautam Kumarcc216b72015-10-26 13:22:12 -07001747 vtysh_client_execute (&vtysh_client[i], line, NULL);
paul718e3742002-12-13 20:15:29 +00001748
hassoe7168df2004-10-03 20:11:32 +00001749 /* Integrate vtysh specific configuration. */
1750 vtysh_config_write ();
1751
paul718e3742002-12-13 20:15:29 +00001752 vtysh_config_dump (fp);
1753
1754 if (vtysh_pager_name && fp)
1755 {
1756 fflush (fp);
1757 if (pclose (fp) == -1)
1758 {
1759 perror ("pclose");
1760 exit (1);
1761 }
1762 fp = NULL;
1763 }
1764
Chris Caputo6e79f8b2009-06-23 05:55:57 +00001765 vty_out (vty, "end%s", VTY_NEWLINE);
1766
paul718e3742002-12-13 20:15:29 +00001767 return CMD_SUCCESS;
1768}
1769
Donald Sharp9fb73e82015-09-22 11:13:12 -04001770DEFUN (vtysh_write_terminal_daemon,
1771 vtysh_write_terminal_daemon_cmd,
1772 "write terminal (zebra|ripd|ripngd|ospfd|ospf6d|bgpd|isisd|babeld)",
1773 "Write running configuration to memory, network, or terminal\n"
1774 "Write to terminal\n"
1775 "For the zebra daemon\n"
1776 "For the rip daemon\n"
1777 "For the ripng daemon\n"
1778 "For the ospf daemon\n"
1779 "For the ospfv6 daemon\n"
1780 "For the bgp daemon\n"
1781 "For the isis daemon\n"
1782 "For the babel daemon\n")
1783{
1784 unsigned int i;
1785 int ret = CMD_SUCCESS;
1786
1787 for (i = 0; i < array_size(vtysh_client); i++)
1788 {
1789 if (strcmp(vtysh_client[i].name, argv[0]) == 0)
1790 break;
1791 }
1792
1793 ret = vtysh_client_execute(&vtysh_client[i], "show running-config\n", stdout);
1794
1795 return ret;
1796}
1797
hassoe7168df2004-10-03 20:11:32 +00001798DEFUN (vtysh_integrated_config,
1799 vtysh_integrated_config_cmd,
1800 "service integrated-vtysh-config",
1801 "Set up miscellaneous service\n"
1802 "Write configuration into integrated file\n")
paul4fc01e62002-12-13 20:49:00 +00001803{
hassoe7168df2004-10-03 20:11:32 +00001804 vtysh_writeconfig_integrated = 1;
1805 return CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001806}
1807
hassoe7168df2004-10-03 20:11:32 +00001808DEFUN (no_vtysh_integrated_config,
1809 no_vtysh_integrated_config_cmd,
1810 "no service integrated-vtysh-config",
1811 NO_STR
1812 "Set up miscellaneous service\n"
1813 "Write configuration into integrated file\n")
paul4fc01e62002-12-13 20:49:00 +00001814{
hassoe7168df2004-10-03 20:11:32 +00001815 vtysh_writeconfig_integrated = 0;
1816 return CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001817}
1818
ajs274a4a42004-12-07 15:39:31 +00001819static int
1820write_config_integrated(void)
paul718e3742002-12-13 20:15:29 +00001821{
ajsb1aa1472005-01-28 21:11:46 +00001822 u_int i;
paul718e3742002-12-13 20:15:29 +00001823 char line[] = "write terminal\n";
1824 FILE *fp;
1825 char *integrate_sav = NULL;
1826
hasso95e735b2004-08-26 13:08:30 +00001827 integrate_sav = malloc (strlen (integrate_default) +
1828 strlen (CONF_BACKUP_EXT) + 1);
paul718e3742002-12-13 20:15:29 +00001829 strcpy (integrate_sav, integrate_default);
1830 strcat (integrate_sav, CONF_BACKUP_EXT);
1831
paul4fc01e62002-12-13 20:49:00 +00001832 fprintf (stdout,"Building Configuration...\n");
paul718e3742002-12-13 20:15:29 +00001833
hasso95e735b2004-08-26 13:08:30 +00001834 /* Move current configuration file to backup config file. */
paul718e3742002-12-13 20:15:29 +00001835 unlink (integrate_sav);
1836 rename (integrate_default, integrate_sav);
hasso95e735b2004-08-26 13:08:30 +00001837 free (integrate_sav);
paul4fc01e62002-12-13 20:49:00 +00001838
paul718e3742002-12-13 20:15:29 +00001839 fp = fopen (integrate_default, "w");
1840 if (fp == NULL)
1841 {
hasso95e735b2004-08-26 13:08:30 +00001842 fprintf (stdout,"%% Can't open configuration file %s.\n",
1843 integrate_default);
paul718e3742002-12-13 20:15:29 +00001844 return CMD_SUCCESS;
1845 }
paul718e3742002-12-13 20:15:29 +00001846
Balaji.G837d16c2012-09-26 14:09:10 +05301847 for (i = 0; i < array_size(vtysh_client); i++)
Gautam Kumarcc216b72015-10-26 13:22:12 -07001848 vtysh_client_execute (&vtysh_client[i], line, NULL);
paul718e3742002-12-13 20:15:29 +00001849
1850 vtysh_config_dump (fp);
1851
1852 fclose (fp);
1853
gdtaa593d52003-12-22 20:15:53 +00001854 if (chmod (integrate_default, CONFIGFILE_MASK) != 0)
1855 {
1856 fprintf (stdout,"%% Can't chmod configuration file %s: %s (%d)\n",
ajs6099b3b2004-11-20 02:06:59 +00001857 integrate_default, safe_strerror(errno), errno);
gdtaa593d52003-12-22 20:15:53 +00001858 return CMD_WARNING;
1859 }
1860
paul4fc01e62002-12-13 20:49:00 +00001861 fprintf(stdout,"Integrated configuration saved to %s\n",integrate_default);
1862
1863 fprintf (stdout,"[OK]\n");
1864
paul718e3742002-12-13 20:15:29 +00001865 return CMD_SUCCESS;
1866}
1867
paul4fc01e62002-12-13 20:49:00 +00001868DEFUN (vtysh_write_memory,
1869 vtysh_write_memory_cmd,
1870 "write memory",
1871 "Write running configuration to memory, network, or terminal\n"
1872 "Write configuration to the file (same as write file)\n")
1873{
pauldfc0d9b2003-04-18 23:55:29 +00001874 int ret = CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001875 char line[] = "write memory\n";
ajsb1aa1472005-01-28 21:11:46 +00001876 u_int i;
paul4fc01e62002-12-13 20:49:00 +00001877
hassoe7168df2004-10-03 20:11:32 +00001878 /* If integrated Quagga.conf explicitely set. */
1879 if (vtysh_writeconfig_integrated)
1880 return write_config_integrated();
paul4fc01e62002-12-13 20:49:00 +00001881
1882 fprintf (stdout,"Building Configuration...\n");
1883
Balaji.G837d16c2012-09-26 14:09:10 +05301884 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00001885 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
hassoe7168df2004-10-03 20:11:32 +00001886
paul4fc01e62002-12-13 20:49:00 +00001887 fprintf (stdout,"[OK]\n");
1888
pauldfc0d9b2003-04-18 23:55:29 +00001889 return ret;
paul4fc01e62002-12-13 20:49:00 +00001890}
1891
paul718e3742002-12-13 20:15:29 +00001892ALIAS (vtysh_write_memory,
1893 vtysh_copy_runningconfig_startupconfig_cmd,
1894 "copy running-config startup-config",
1895 "Copy from one file to another\n"
1896 "Copy from current system configuration\n"
1897 "Copy to startup configuration\n")
1898
1899ALIAS (vtysh_write_memory,
1900 vtysh_write_file_cmd,
1901 "write file",
1902 "Write running configuration to memory, network, or terminal\n"
1903 "Write configuration to the file (same as write memory)\n")
1904
hasso4a6e2252003-05-25 11:51:29 +00001905ALIAS (vtysh_write_memory,
1906 vtysh_write_cmd,
1907 "write",
1908 "Write running configuration to memory, network, or terminal\n")
1909
paul718e3742002-12-13 20:15:29 +00001910ALIAS (vtysh_write_terminal,
1911 vtysh_show_running_config_cmd,
1912 "show running-config",
1913 SHOW_STR
1914 "Current operating configuration\n")
hassob094d262004-08-25 12:22:00 +00001915
Donald Sharp9fb73e82015-09-22 11:13:12 -04001916ALIAS (vtysh_write_terminal_daemon,
1917 vtysh_show_running_config_daemon_cmd,
1918 "show running-config (zebra|ripd|ripngd|ospfd|ospf6d|bgpd|isisd|babeld)",
1919 SHOW_STR
1920 "Current operating configuration\n"
1921 "For the zebra daemon\n"
1922 "For the rip daemon\n"
1923 "For the ripng daemon\n"
1924 "For the ospf daemon\n"
1925 "For the ospfv6 daemon\n"
1926 "For the bgp daemon\n"
1927 "For the isis daemon\n"
1928 "For the babel daemon\n")
1929
hasso34553cc2004-08-27 13:56:39 +00001930DEFUN (vtysh_terminal_length,
1931 vtysh_terminal_length_cmd,
1932 "terminal length <0-512>",
1933 "Set terminal line parameters\n"
1934 "Set number of lines on a screen\n"
1935 "Number of lines on screen (0 for no pausing)\n")
1936{
1937 int lines;
1938 char *endptr = NULL;
1939 char default_pager[10];
1940
1941 lines = strtol (argv[0], &endptr, 10);
1942 if (lines < 0 || lines > 512 || *endptr != '\0')
1943 {
1944 vty_out (vty, "length is malformed%s", VTY_NEWLINE);
1945 return CMD_WARNING;
1946 }
1947
1948 if (vtysh_pager_name)
1949 {
1950 free (vtysh_pager_name);
1951 vtysh_pager_name = NULL;
1952 }
1953
1954 if (lines != 0)
1955 {
1956 snprintf(default_pager, 10, "more -%i", lines);
1957 vtysh_pager_name = strdup (default_pager);
1958 }
1959
1960 return CMD_SUCCESS;
1961}
1962
1963DEFUN (vtysh_terminal_no_length,
1964 vtysh_terminal_no_length_cmd,
1965 "terminal no length",
1966 "Set terminal line parameters\n"
1967 NO_STR
1968 "Set number of lines on a screen\n")
1969{
1970 if (vtysh_pager_name)
1971 {
1972 free (vtysh_pager_name);
1973 vtysh_pager_name = NULL;
1974 }
1975
1976 vtysh_pager_init();
1977 return CMD_SUCCESS;
1978}
1979
hassof2799e62004-10-28 17:43:11 +00001980DEFUN (vtysh_show_daemons,
1981 vtysh_show_daemons_cmd,
1982 "show daemons",
hassoe7168df2004-10-03 20:11:32 +00001983 SHOW_STR
1984 "Show list of running daemons\n")
1985{
ajsb1aa1472005-01-28 21:11:46 +00001986 u_int i;
1987
Balaji.G837d16c2012-09-26 14:09:10 +05301988 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00001989 if ( vtysh_client[i].fd >= 0 )
1990 vty_out(vty, " %s", vtysh_client[i].name);
hassoe7168df2004-10-03 20:11:32 +00001991 vty_out(vty, "%s", VTY_NEWLINE);
1992
1993 return CMD_SUCCESS;
1994}
1995
paul718e3742002-12-13 20:15:29 +00001996/* Execute command in child process. */
ajs274a4a42004-12-07 15:39:31 +00001997static int
hasso5862ff52004-10-11 13:20:40 +00001998execute_command (const char *command, int argc, const char *arg1,
1999 const char *arg2)
paul718e3742002-12-13 20:15:29 +00002000{
paul718e3742002-12-13 20:15:29 +00002001 pid_t pid;
2002 int status;
2003
2004 /* Call fork(). */
2005 pid = fork ();
2006
2007 if (pid < 0)
2008 {
2009 /* Failure of fork(). */
ajs6099b3b2004-11-20 02:06:59 +00002010 fprintf (stderr, "Can't fork: %s\n", safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +00002011 exit (1);
2012 }
2013 else if (pid == 0)
2014 {
2015 /* This is child process. */
2016 switch (argc)
2017 {
2018 case 0:
David Lamparter6769f432015-03-04 07:18:24 +01002019 execlp (command, command, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00002020 break;
2021 case 1:
David Lamparter6769f432015-03-04 07:18:24 +01002022 execlp (command, command, arg1, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00002023 break;
2024 case 2:
David Lamparter6769f432015-03-04 07:18:24 +01002025 execlp (command, command, arg1, arg2, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00002026 break;
2027 }
2028
2029 /* When execlp suceed, this part is not executed. */
ajs6099b3b2004-11-20 02:06:59 +00002030 fprintf (stderr, "Can't execute %s: %s\n", command, safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +00002031 exit (1);
2032 }
2033 else
2034 {
2035 /* This is parent. */
2036 execute_flag = 1;
David Lamparter6769f432015-03-04 07:18:24 +01002037 wait4 (pid, &status, 0, NULL);
paul718e3742002-12-13 20:15:29 +00002038 execute_flag = 0;
2039 }
2040 return 0;
2041}
2042
2043DEFUN (vtysh_ping,
2044 vtysh_ping_cmd,
2045 "ping WORD",
hasso4eeccf12003-06-25 10:49:55 +00002046 "Send echo messages\n"
paul718e3742002-12-13 20:15:29 +00002047 "Ping destination address or hostname\n")
2048{
2049 execute_command ("ping", 1, argv[0], NULL);
2050 return CMD_SUCCESS;
2051}
2052
hasso4eeccf12003-06-25 10:49:55 +00002053ALIAS (vtysh_ping,
2054 vtysh_ping_ip_cmd,
2055 "ping ip WORD",
2056 "Send echo messages\n"
2057 "IP echo\n"
2058 "Ping destination address or hostname\n")
2059
paul718e3742002-12-13 20:15:29 +00002060DEFUN (vtysh_traceroute,
2061 vtysh_traceroute_cmd,
2062 "traceroute WORD",
2063 "Trace route to destination\n"
2064 "Trace route to destination address or hostname\n")
2065{
2066 execute_command ("traceroute", 1, argv[0], NULL);
2067 return CMD_SUCCESS;
2068}
2069
hasso4eeccf12003-06-25 10:49:55 +00002070ALIAS (vtysh_traceroute,
2071 vtysh_traceroute_ip_cmd,
2072 "traceroute ip WORD",
2073 "Trace route to destination\n"
2074 "IP trace\n"
2075 "Trace route to destination address or hostname\n")
2076
2077#ifdef HAVE_IPV6
2078DEFUN (vtysh_ping6,
2079 vtysh_ping6_cmd,
2080 "ping ipv6 WORD",
2081 "Send echo messages\n"
2082 "IPv6 echo\n"
2083 "Ping destination address or hostname\n")
2084{
2085 execute_command ("ping6", 1, argv[0], NULL);
2086 return CMD_SUCCESS;
2087}
2088
2089DEFUN (vtysh_traceroute6,
2090 vtysh_traceroute6_cmd,
2091 "traceroute ipv6 WORD",
2092 "Trace route to destination\n"
2093 "IPv6 trace\n"
2094 "Trace route to destination address or hostname\n")
2095{
2096 execute_command ("traceroute6", 1, argv[0], NULL);
2097 return CMD_SUCCESS;
2098}
2099#endif
2100
paul718e3742002-12-13 20:15:29 +00002101DEFUN (vtysh_telnet,
2102 vtysh_telnet_cmd,
2103 "telnet WORD",
2104 "Open a telnet connection\n"
2105 "IP address or hostname of a remote system\n")
2106{
2107 execute_command ("telnet", 1, argv[0], NULL);
2108 return CMD_SUCCESS;
2109}
2110
2111DEFUN (vtysh_telnet_port,
2112 vtysh_telnet_port_cmd,
2113 "telnet WORD PORT",
2114 "Open a telnet connection\n"
2115 "IP address or hostname of a remote system\n"
2116 "TCP Port number\n")
2117{
2118 execute_command ("telnet", 2, argv[0], argv[1]);
2119 return CMD_SUCCESS;
2120}
2121
paul5087df52003-01-25 06:56:09 +00002122DEFUN (vtysh_ssh,
2123 vtysh_ssh_cmd,
2124 "ssh WORD",
2125 "Open an ssh connection\n"
2126 "[user@]host\n")
2127{
2128 execute_command ("ssh", 1, argv[0], NULL);
2129 return CMD_SUCCESS;
2130}
2131
paul718e3742002-12-13 20:15:29 +00002132DEFUN (vtysh_start_shell,
2133 vtysh_start_shell_cmd,
2134 "start-shell",
2135 "Start UNIX shell\n")
2136{
2137 execute_command ("sh", 0, NULL, NULL);
2138 return CMD_SUCCESS;
2139}
2140
2141DEFUN (vtysh_start_bash,
2142 vtysh_start_bash_cmd,
2143 "start-shell bash",
2144 "Start UNIX shell\n"
2145 "Start bash\n")
2146{
2147 execute_command ("bash", 0, NULL, NULL);
2148 return CMD_SUCCESS;
2149}
2150
2151DEFUN (vtysh_start_zsh,
2152 vtysh_start_zsh_cmd,
2153 "start-shell zsh",
2154 "Start UNIX shell\n"
2155 "Start Z shell\n")
2156{
2157 execute_command ("zsh", 0, NULL, NULL);
2158 return CMD_SUCCESS;
2159}
hassob094d262004-08-25 12:22:00 +00002160
ajs274a4a42004-12-07 15:39:31 +00002161static void
paul718e3742002-12-13 20:15:29 +00002162vtysh_install_default (enum node_type node)
2163{
2164 install_element (node, &config_list_cmd);
2165}
2166
2167/* Making connection to protocol daemon. */
ajs274a4a42004-12-07 15:39:31 +00002168static int
ajsb1aa1472005-01-28 21:11:46 +00002169vtysh_connect (struct vtysh_client *vclient)
paul718e3742002-12-13 20:15:29 +00002170{
2171 int ret;
2172 int sock, len;
2173 struct sockaddr_un addr;
2174 struct stat s_stat;
paul718e3742002-12-13 20:15:29 +00002175
paul718e3742002-12-13 20:15:29 +00002176 /* Stat socket to see if we have permission to access it. */
ajsb1aa1472005-01-28 21:11:46 +00002177 ret = stat (vclient->path, &s_stat);
paul718e3742002-12-13 20:15:29 +00002178 if (ret < 0 && errno != ENOENT)
2179 {
2180 fprintf (stderr, "vtysh_connect(%s): stat = %s\n",
ajsb1aa1472005-01-28 21:11:46 +00002181 vclient->path, safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002182 exit(1);
2183 }
2184
2185 if (ret >= 0)
2186 {
2187 if (! S_ISSOCK(s_stat.st_mode))
2188 {
2189 fprintf (stderr, "vtysh_connect(%s): Not a socket\n",
ajsb1aa1472005-01-28 21:11:46 +00002190 vclient->path);
paul718e3742002-12-13 20:15:29 +00002191 exit (1);
2192 }
2193
paul718e3742002-12-13 20:15:29 +00002194 }
2195
2196 sock = socket (AF_UNIX, SOCK_STREAM, 0);
2197 if (sock < 0)
2198 {
2199#ifdef DEBUG
ajsb1aa1472005-01-28 21:11:46 +00002200 fprintf(stderr, "vtysh_connect(%s): socket = %s\n", vclient->path,
ajs6099b3b2004-11-20 02:06:59 +00002201 safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002202#endif /* DEBUG */
2203 return -1;
2204 }
2205
2206 memset (&addr, 0, sizeof (struct sockaddr_un));
2207 addr.sun_family = AF_UNIX;
ajsb1aa1472005-01-28 21:11:46 +00002208 strncpy (addr.sun_path, vclient->path, strlen (vclient->path));
Paul Jakma6f0e3f62007-05-10 02:38:51 +00002209#ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
paul718e3742002-12-13 20:15:29 +00002210 len = addr.sun_len = SUN_LEN(&addr);
2211#else
2212 len = sizeof (addr.sun_family) + strlen (addr.sun_path);
Paul Jakma6f0e3f62007-05-10 02:38:51 +00002213#endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
paul718e3742002-12-13 20:15:29 +00002214
2215 ret = connect (sock, (struct sockaddr *) &addr, len);
2216 if (ret < 0)
2217 {
2218#ifdef DEBUG
ajsb1aa1472005-01-28 21:11:46 +00002219 fprintf(stderr, "vtysh_connect(%s): connect = %s\n", vclient->path,
ajs6099b3b2004-11-20 02:06:59 +00002220 safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002221#endif /* DEBUG */
2222 close (sock);
2223 return -1;
2224 }
2225 vclient->fd = sock;
2226
2227 return 0;
2228}
2229
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002230int
2231vtysh_connect_all(const char *daemon_name)
paul718e3742002-12-13 20:15:29 +00002232{
ajsb1aa1472005-01-28 21:11:46 +00002233 u_int i;
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002234 int rc = 0;
2235 int matches = 0;
ajsb1aa1472005-01-28 21:11:46 +00002236
Balaji.G837d16c2012-09-26 14:09:10 +05302237 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00002238 {
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002239 if (!daemon_name || !strcmp(daemon_name, vtysh_client[i].name))
2240 {
2241 matches++;
2242 if (vtysh_connect(&vtysh_client[i]) == 0)
2243 rc++;
2244 /* We need direct access to ripd in vtysh_exit_ripd_only. */
2245 if (vtysh_client[i].flag == VTYSH_RIPD)
2246 ripd_client = &vtysh_client[i];
2247 }
ajsb1aa1472005-01-28 21:11:46 +00002248 }
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002249 if (!matches)
2250 fprintf(stderr, "Error: no daemons match name %s!\n", daemon_name);
2251 return rc;
paul718e3742002-12-13 20:15:29 +00002252}
2253
hasso95e735b2004-08-26 13:08:30 +00002254/* To disable readline's filename completion. */
ajs274a4a42004-12-07 15:39:31 +00002255static char *
pauldfc0d9b2003-04-18 23:55:29 +00002256vtysh_completion_entry_function (const char *ignore, int invoking_key)
paul718e3742002-12-13 20:15:29 +00002257{
pauldfc0d9b2003-04-18 23:55:29 +00002258 return NULL;
paul718e3742002-12-13 20:15:29 +00002259}
2260
2261void
ajsb1aa1472005-01-28 21:11:46 +00002262vtysh_readline_init (void)
paul718e3742002-12-13 20:15:29 +00002263{
2264 /* readline related settings. */
Sébastien Luttringer66d2ead2014-05-27 19:55:11 +02002265 rl_bind_key ('?', (rl_command_func_t *) vtysh_rl_describe);
paul68980082003-03-25 05:07:42 +00002266 rl_completion_entry_function = vtysh_completion_entry_function;
Sébastien Luttringer66d2ead2014-05-27 19:55:11 +02002267 rl_attempted_completion_function = (rl_completion_func_t *)new_completion;
paul718e3742002-12-13 20:15:29 +00002268}
2269
2270char *
ajsb1aa1472005-01-28 21:11:46 +00002271vtysh_prompt (void)
paul718e3742002-12-13 20:15:29 +00002272{
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002273 static struct utsname names;
paul718e3742002-12-13 20:15:29 +00002274 static char buf[100];
2275 const char*hostname;
2276 extern struct host host;
2277
2278 hostname = host.name;
2279
2280 if (!hostname)
2281 {
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002282 if (!names.nodename[0])
2283 uname (&names);
paul718e3742002-12-13 20:15:29 +00002284 hostname = names.nodename;
2285 }
2286
2287 snprintf (buf, sizeof buf, cmd_prompt (vty->node), hostname);
2288
2289 return buf;
2290}
2291
2292void
ajsb1aa1472005-01-28 21:11:46 +00002293vtysh_init_vty (void)
paul718e3742002-12-13 20:15:29 +00002294{
2295 /* Make vty structure. */
2296 vty = vty_new ();
2297 vty->type = VTY_SHELL;
2298 vty->node = VIEW_NODE;
2299
2300 /* Initialize commands. */
2301 cmd_init (0);
2302
2303 /* Install nodes. */
2304 install_node (&bgp_node, NULL);
2305 install_node (&rip_node, NULL);
2306 install_node (&interface_node, NULL);
2307 install_node (&rmap_node, NULL);
2308 install_node (&zebra_node, NULL);
2309 install_node (&bgp_vpnv4_node, NULL);
Lou Berger13c378d2016-01-12 13:41:56 -05002310 install_node (&bgp_vpnv6_node, NULL);
paul718e3742002-12-13 20:15:29 +00002311 install_node (&bgp_ipv4_node, NULL);
2312 install_node (&bgp_ipv4m_node, NULL);
2313/* #ifdef HAVE_IPV6 */
2314 install_node (&bgp_ipv6_node, NULL);
paul57b5b7e2005-08-22 22:44:29 +00002315 install_node (&bgp_ipv6m_node, NULL);
paul718e3742002-12-13 20:15:29 +00002316/* #endif */
2317 install_node (&ospf_node, NULL);
2318/* #ifdef HAVE_IPV6 */
2319 install_node (&ripng_node, NULL);
2320 install_node (&ospf6_node, NULL);
2321/* #endif */
David Lamparteree53c8b2015-05-23 05:45:59 +02002322 install_node (&babel_node, NULL);
paul718e3742002-12-13 20:15:29 +00002323 install_node (&keychain_node, NULL);
2324 install_node (&keychain_key_node, NULL);
hassoc25e4582003-12-23 10:39:08 +00002325 install_node (&isis_node, NULL);
hassoe7168df2004-10-03 20:11:32 +00002326 install_node (&vty_node, NULL);
paul718e3742002-12-13 20:15:29 +00002327
2328 vtysh_install_default (VIEW_NODE);
2329 vtysh_install_default (ENABLE_NODE);
2330 vtysh_install_default (CONFIG_NODE);
2331 vtysh_install_default (BGP_NODE);
2332 vtysh_install_default (RIP_NODE);
2333 vtysh_install_default (INTERFACE_NODE);
2334 vtysh_install_default (RMAP_NODE);
2335 vtysh_install_default (ZEBRA_NODE);
2336 vtysh_install_default (BGP_VPNV4_NODE);
Lou Berger13c378d2016-01-12 13:41:56 -05002337 vtysh_install_default (BGP_VPNV6_NODE);
paul718e3742002-12-13 20:15:29 +00002338 vtysh_install_default (BGP_IPV4_NODE);
2339 vtysh_install_default (BGP_IPV4M_NODE);
2340 vtysh_install_default (BGP_IPV6_NODE);
paul57b5b7e2005-08-22 22:44:29 +00002341 vtysh_install_default (BGP_IPV6M_NODE);
paul718e3742002-12-13 20:15:29 +00002342 vtysh_install_default (OSPF_NODE);
2343 vtysh_install_default (RIPNG_NODE);
2344 vtysh_install_default (OSPF6_NODE);
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +01002345 vtysh_install_default (BABEL_NODE);
hassoc25e4582003-12-23 10:39:08 +00002346 vtysh_install_default (ISIS_NODE);
paul718e3742002-12-13 20:15:29 +00002347 vtysh_install_default (KEYCHAIN_NODE);
2348 vtysh_install_default (KEYCHAIN_KEY_NODE);
hassoe7168df2004-10-03 20:11:32 +00002349 vtysh_install_default (VTY_NODE);
paul718e3742002-12-13 20:15:29 +00002350
2351 install_element (VIEW_NODE, &vtysh_enable_cmd);
2352 install_element (ENABLE_NODE, &vtysh_config_terminal_cmd);
2353 install_element (ENABLE_NODE, &vtysh_disable_cmd);
2354
2355 /* "exit" command. */
2356 install_element (VIEW_NODE, &vtysh_exit_all_cmd);
2357 install_element (VIEW_NODE, &vtysh_quit_all_cmd);
2358 install_element (CONFIG_NODE, &vtysh_exit_all_cmd);
2359 /* install_element (CONFIG_NODE, &vtysh_quit_all_cmd); */
2360 install_element (ENABLE_NODE, &vtysh_exit_all_cmd);
2361 install_element (ENABLE_NODE, &vtysh_quit_all_cmd);
2362 install_element (RIP_NODE, &vtysh_exit_ripd_cmd);
2363 install_element (RIP_NODE, &vtysh_quit_ripd_cmd);
paul68980082003-03-25 05:07:42 +00002364 install_element (RIPNG_NODE, &vtysh_exit_ripngd_cmd);
2365 install_element (RIPNG_NODE, &vtysh_quit_ripngd_cmd);
paul718e3742002-12-13 20:15:29 +00002366 install_element (OSPF_NODE, &vtysh_exit_ospfd_cmd);
2367 install_element (OSPF_NODE, &vtysh_quit_ospfd_cmd);
paul68980082003-03-25 05:07:42 +00002368 install_element (OSPF6_NODE, &vtysh_exit_ospf6d_cmd);
2369 install_element (OSPF6_NODE, &vtysh_quit_ospf6d_cmd);
paul718e3742002-12-13 20:15:29 +00002370 install_element (BGP_NODE, &vtysh_exit_bgpd_cmd);
2371 install_element (BGP_NODE, &vtysh_quit_bgpd_cmd);
2372 install_element (BGP_VPNV4_NODE, &vtysh_exit_bgpd_cmd);
2373 install_element (BGP_VPNV4_NODE, &vtysh_quit_bgpd_cmd);
Lou Berger13c378d2016-01-12 13:41:56 -05002374 install_element (BGP_VPNV6_NODE, &vtysh_exit_bgpd_cmd);
2375 install_element (BGP_VPNV6_NODE, &vtysh_quit_bgpd_cmd);
paul718e3742002-12-13 20:15:29 +00002376 install_element (BGP_IPV4_NODE, &vtysh_exit_bgpd_cmd);
2377 install_element (BGP_IPV4_NODE, &vtysh_quit_bgpd_cmd);
2378 install_element (BGP_IPV4M_NODE, &vtysh_exit_bgpd_cmd);
2379 install_element (BGP_IPV4M_NODE, &vtysh_quit_bgpd_cmd);
2380 install_element (BGP_IPV6_NODE, &vtysh_exit_bgpd_cmd);
2381 install_element (BGP_IPV6_NODE, &vtysh_quit_bgpd_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002382 install_element (BGP_IPV6M_NODE, &vtysh_exit_bgpd_cmd);
2383 install_element (BGP_IPV6M_NODE, &vtysh_quit_bgpd_cmd);
hassoc25e4582003-12-23 10:39:08 +00002384 install_element (ISIS_NODE, &vtysh_exit_isisd_cmd);
2385 install_element (ISIS_NODE, &vtysh_quit_isisd_cmd);
paul718e3742002-12-13 20:15:29 +00002386 install_element (KEYCHAIN_NODE, &vtysh_exit_ripd_cmd);
2387 install_element (KEYCHAIN_NODE, &vtysh_quit_ripd_cmd);
2388 install_element (KEYCHAIN_KEY_NODE, &vtysh_exit_ripd_cmd);
2389 install_element (KEYCHAIN_KEY_NODE, &vtysh_quit_ripd_cmd);
2390 install_element (RMAP_NODE, &vtysh_exit_rmap_cmd);
2391 install_element (RMAP_NODE, &vtysh_quit_rmap_cmd);
hassoe7168df2004-10-03 20:11:32 +00002392 install_element (VTY_NODE, &vtysh_exit_line_vty_cmd);
2393 install_element (VTY_NODE, &vtysh_quit_line_vty_cmd);
paul718e3742002-12-13 20:15:29 +00002394
2395 /* "end" command. */
2396 install_element (CONFIG_NODE, &vtysh_end_all_cmd);
2397 install_element (ENABLE_NODE, &vtysh_end_all_cmd);
2398 install_element (RIP_NODE, &vtysh_end_all_cmd);
2399 install_element (RIPNG_NODE, &vtysh_end_all_cmd);
2400 install_element (OSPF_NODE, &vtysh_end_all_cmd);
2401 install_element (OSPF6_NODE, &vtysh_end_all_cmd);
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +01002402 install_element (BABEL_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002403 install_element (BGP_NODE, &vtysh_end_all_cmd);
2404 install_element (BGP_IPV4_NODE, &vtysh_end_all_cmd);
2405 install_element (BGP_IPV4M_NODE, &vtysh_end_all_cmd);
2406 install_element (BGP_VPNV4_NODE, &vtysh_end_all_cmd);
Lou Berger13c378d2016-01-12 13:41:56 -05002407 install_element (BGP_VPNV6_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002408 install_element (BGP_IPV6_NODE, &vtysh_end_all_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002409 install_element (BGP_IPV6M_NODE, &vtysh_end_all_cmd);
hassoc25e4582003-12-23 10:39:08 +00002410 install_element (ISIS_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002411 install_element (KEYCHAIN_NODE, &vtysh_end_all_cmd);
2412 install_element (KEYCHAIN_KEY_NODE, &vtysh_end_all_cmd);
2413 install_element (RMAP_NODE, &vtysh_end_all_cmd);
hassoe7168df2004-10-03 20:11:32 +00002414 install_element (VTY_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002415
paul338a9912003-03-01 15:44:10 +00002416 install_element (INTERFACE_NODE, &interface_desc_cmd);
paul464dc8d2003-03-28 02:25:45 +00002417 install_element (INTERFACE_NODE, &no_interface_desc_cmd);
paul718e3742002-12-13 20:15:29 +00002418 install_element (INTERFACE_NODE, &vtysh_end_all_cmd);
2419 install_element (INTERFACE_NODE, &vtysh_exit_interface_cmd);
2420 install_element (INTERFACE_NODE, &vtysh_quit_interface_cmd);
2421 install_element (CONFIG_NODE, &router_rip_cmd);
2422#ifdef HAVE_IPV6
2423 install_element (CONFIG_NODE, &router_ripng_cmd);
2424#endif
2425 install_element (CONFIG_NODE, &router_ospf_cmd);
2426#ifdef HAVE_IPV6
2427 install_element (CONFIG_NODE, &router_ospf6_cmd);
2428#endif
hassoc25e4582003-12-23 10:39:08 +00002429 install_element (CONFIG_NODE, &router_isis_cmd);
paul718e3742002-12-13 20:15:29 +00002430 install_element (CONFIG_NODE, &router_bgp_cmd);
Paul Jakma10895fd2008-07-03 19:34:48 +00002431 install_element (CONFIG_NODE, &router_bgp_view_cmd);
paul718e3742002-12-13 20:15:29 +00002432 install_element (BGP_NODE, &address_family_vpnv4_cmd);
2433 install_element (BGP_NODE, &address_family_vpnv4_unicast_cmd);
Lou Berger13c378d2016-01-12 13:41:56 -05002434 install_element (BGP_NODE, &address_family_vpnv6_cmd);
2435 install_element (BGP_NODE, &address_family_vpnv6_unicast_cmd);
paul718e3742002-12-13 20:15:29 +00002436 install_element (BGP_NODE, &address_family_ipv4_unicast_cmd);
2437 install_element (BGP_NODE, &address_family_ipv4_multicast_cmd);
2438#ifdef HAVE_IPV6
2439 install_element (BGP_NODE, &address_family_ipv6_cmd);
2440 install_element (BGP_NODE, &address_family_ipv6_unicast_cmd);
2441#endif
2442 install_element (BGP_VPNV4_NODE, &exit_address_family_cmd);
Lou Berger13c378d2016-01-12 13:41:56 -05002443 install_element (BGP_VPNV6_NODE, &exit_address_family_cmd);
paul718e3742002-12-13 20:15:29 +00002444 install_element (BGP_IPV4_NODE, &exit_address_family_cmd);
2445 install_element (BGP_IPV4M_NODE, &exit_address_family_cmd);
2446 install_element (BGP_IPV6_NODE, &exit_address_family_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002447 install_element (BGP_IPV6M_NODE, &exit_address_family_cmd);
paul718e3742002-12-13 20:15:29 +00002448 install_element (CONFIG_NODE, &key_chain_cmd);
2449 install_element (CONFIG_NODE, &route_map_cmd);
hassoe7168df2004-10-03 20:11:32 +00002450 install_element (CONFIG_NODE, &vtysh_line_vty_cmd);
paul718e3742002-12-13 20:15:29 +00002451 install_element (KEYCHAIN_NODE, &key_cmd);
2452 install_element (KEYCHAIN_NODE, &key_chain_cmd);
2453 install_element (KEYCHAIN_KEY_NODE, &key_chain_cmd);
2454 install_element (CONFIG_NODE, &vtysh_interface_cmd);
paul32d24632003-05-23 09:25:20 +00002455 install_element (CONFIG_NODE, &vtysh_no_interface_cmd);
Feng Lu471ea392015-05-22 11:40:00 +02002456 install_element (CONFIG_NODE, &vtysh_interface_vrf_cmd);
2457 install_element (CONFIG_NODE, &vtysh_no_interface_vrf_cmd);
paul718e3742002-12-13 20:15:29 +00002458 install_element (ENABLE_NODE, &vtysh_show_running_config_cmd);
Donald Sharp9fb73e82015-09-22 11:13:12 -04002459 install_element (ENABLE_NODE, &vtysh_show_running_config_daemon_cmd);
paul718e3742002-12-13 20:15:29 +00002460 install_element (ENABLE_NODE, &vtysh_copy_runningconfig_startupconfig_cmd);
2461 install_element (ENABLE_NODE, &vtysh_write_file_cmd);
hasso4a6e2252003-05-25 11:51:29 +00002462 install_element (ENABLE_NODE, &vtysh_write_cmd);
paul718e3742002-12-13 20:15:29 +00002463
hasso95e735b2004-08-26 13:08:30 +00002464 /* "write terminal" command. */
paul718e3742002-12-13 20:15:29 +00002465 install_element (ENABLE_NODE, &vtysh_write_terminal_cmd);
Donald Sharp9fb73e82015-09-22 11:13:12 -04002466 install_element (ENABLE_NODE, &vtysh_write_terminal_daemon_cmd);
hassoe7168df2004-10-03 20:11:32 +00002467
2468 install_element (CONFIG_NODE, &vtysh_integrated_config_cmd);
2469 install_element (CONFIG_NODE, &no_vtysh_integrated_config_cmd);
paul718e3742002-12-13 20:15:29 +00002470
hasso95e735b2004-08-26 13:08:30 +00002471 /* "write memory" command. */
paul718e3742002-12-13 20:15:29 +00002472 install_element (ENABLE_NODE, &vtysh_write_memory_cmd);
paul718e3742002-12-13 20:15:29 +00002473
hasso34553cc2004-08-27 13:56:39 +00002474 install_element (VIEW_NODE, &vtysh_terminal_length_cmd);
2475 install_element (ENABLE_NODE, &vtysh_terminal_length_cmd);
2476 install_element (VIEW_NODE, &vtysh_terminal_no_length_cmd);
2477 install_element (ENABLE_NODE, &vtysh_terminal_no_length_cmd);
hassof2799e62004-10-28 17:43:11 +00002478 install_element (VIEW_NODE, &vtysh_show_daemons_cmd);
2479 install_element (ENABLE_NODE, &vtysh_show_daemons_cmd);
hasso34553cc2004-08-27 13:56:39 +00002480
paul718e3742002-12-13 20:15:29 +00002481 install_element (VIEW_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002482 install_element (VIEW_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00002483 install_element (VIEW_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002484 install_element (VIEW_NODE, &vtysh_traceroute_ip_cmd);
2485#ifdef HAVE_IPV6
2486 install_element (VIEW_NODE, &vtysh_ping6_cmd);
2487 install_element (VIEW_NODE, &vtysh_traceroute6_cmd);
2488#endif
paul718e3742002-12-13 20:15:29 +00002489 install_element (VIEW_NODE, &vtysh_telnet_cmd);
2490 install_element (VIEW_NODE, &vtysh_telnet_port_cmd);
paul5087df52003-01-25 06:56:09 +00002491 install_element (VIEW_NODE, &vtysh_ssh_cmd);
paul718e3742002-12-13 20:15:29 +00002492 install_element (ENABLE_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002493 install_element (ENABLE_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00002494 install_element (ENABLE_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002495 install_element (ENABLE_NODE, &vtysh_traceroute_ip_cmd);
2496#ifdef HAVE_IPV6
2497 install_element (ENABLE_NODE, &vtysh_ping6_cmd);
2498 install_element (ENABLE_NODE, &vtysh_traceroute6_cmd);
2499#endif
paul718e3742002-12-13 20:15:29 +00002500 install_element (ENABLE_NODE, &vtysh_telnet_cmd);
2501 install_element (ENABLE_NODE, &vtysh_telnet_port_cmd);
hasso67e29ab2004-08-26 22:21:31 +00002502 install_element (ENABLE_NODE, &vtysh_ssh_cmd);
paul718e3742002-12-13 20:15:29 +00002503 install_element (ENABLE_NODE, &vtysh_start_shell_cmd);
2504 install_element (ENABLE_NODE, &vtysh_start_bash_cmd);
2505 install_element (ENABLE_NODE, &vtysh_start_zsh_cmd);
Paul Jakmadbf7d132006-05-23 22:10:01 +00002506
Paul Jakma362b4032006-05-28 07:54:45 +00002507 install_element (VIEW_NODE, &vtysh_show_memory_cmd);
2508 install_element (ENABLE_NODE, &vtysh_show_memory_cmd);
2509
Donald Sharp567a6382015-08-19 21:22:17 -04002510 install_element (VIEW_NODE, &vtysh_show_work_queues_cmd);
2511 install_element (ENABLE_NODE, &vtysh_show_work_queues_cmd);
2512
2513 install_element (VIEW_NODE, &vtysh_show_thread_cmd);
2514 install_element (ENABLE_NODE, &vtysh_show_thread_cmd);
2515
Paul Jakmadbf7d132006-05-23 22:10:01 +00002516 /* Logging */
2517 install_element (ENABLE_NODE, &vtysh_show_logging_cmd);
2518 install_element (VIEW_NODE, &vtysh_show_logging_cmd);
paul718e3742002-12-13 20:15:29 +00002519 install_element (CONFIG_NODE, &vtysh_log_stdout_cmd);
ajs274a4a42004-12-07 15:39:31 +00002520 install_element (CONFIG_NODE, &vtysh_log_stdout_level_cmd);
paul718e3742002-12-13 20:15:29 +00002521 install_element (CONFIG_NODE, &no_vtysh_log_stdout_cmd);
2522 install_element (CONFIG_NODE, &vtysh_log_file_cmd);
ajs274a4a42004-12-07 15:39:31 +00002523 install_element (CONFIG_NODE, &vtysh_log_file_level_cmd);
paul718e3742002-12-13 20:15:29 +00002524 install_element (CONFIG_NODE, &no_vtysh_log_file_cmd);
ajs274a4a42004-12-07 15:39:31 +00002525 install_element (CONFIG_NODE, &no_vtysh_log_file_level_cmd);
2526 install_element (CONFIG_NODE, &vtysh_log_monitor_cmd);
2527 install_element (CONFIG_NODE, &vtysh_log_monitor_level_cmd);
2528 install_element (CONFIG_NODE, &no_vtysh_log_monitor_cmd);
paul718e3742002-12-13 20:15:29 +00002529 install_element (CONFIG_NODE, &vtysh_log_syslog_cmd);
ajs274a4a42004-12-07 15:39:31 +00002530 install_element (CONFIG_NODE, &vtysh_log_syslog_level_cmd);
paul718e3742002-12-13 20:15:29 +00002531 install_element (CONFIG_NODE, &no_vtysh_log_syslog_cmd);
2532 install_element (CONFIG_NODE, &vtysh_log_trap_cmd);
2533 install_element (CONFIG_NODE, &no_vtysh_log_trap_cmd);
ajs274a4a42004-12-07 15:39:31 +00002534 install_element (CONFIG_NODE, &vtysh_log_facility_cmd);
2535 install_element (CONFIG_NODE, &no_vtysh_log_facility_cmd);
paul718e3742002-12-13 20:15:29 +00002536 install_element (CONFIG_NODE, &vtysh_log_record_priority_cmd);
2537 install_element (CONFIG_NODE, &no_vtysh_log_record_priority_cmd);
Andrew J. Schorrc749b722007-04-29 03:53:31 +00002538 install_element (CONFIG_NODE, &vtysh_log_timestamp_precision_cmd);
2539 install_element (CONFIG_NODE, &no_vtysh_log_timestamp_precision_cmd);
hassoe7168df2004-10-03 20:11:32 +00002540
2541 install_element (CONFIG_NODE, &vtysh_service_password_encrypt_cmd);
2542 install_element (CONFIG_NODE, &no_vtysh_service_password_encrypt_cmd);
2543
2544 install_element (CONFIG_NODE, &vtysh_password_cmd);
2545 install_element (CONFIG_NODE, &vtysh_password_text_cmd);
2546 install_element (CONFIG_NODE, &vtysh_enable_password_cmd);
2547 install_element (CONFIG_NODE, &vtysh_enable_password_text_cmd);
2548 install_element (CONFIG_NODE, &no_vtysh_enable_password_cmd);
2549
paul718e3742002-12-13 20:15:29 +00002550}