blob: b55c6719bbd69811dafc8696241b7bd3eade42a8 [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. */
paul718e3742002-12-13 20:15:29 +000090#define ERR_WHERE_STRING "vtysh(): vtysh_client_config(): "
ajs274a4a42004-12-07 15:39:31 +000091static int
paul718e3742002-12-13 20:15:29 +000092vtysh_client_config (struct vtysh_client *vclient, char *line)
93{
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;
103
104 if (vclient->fd < 0)
105 return CMD_SUCCESS;
106
107 ret = write (vclient->fd, line, strlen (line) + 1);
108 if (ret <= 0)
109 {
110 vclient_close (vclient);
111 return CMD_SUCCESS;
112 }
113
hasso95e735b2004-08-26 13:08:30 +0000114 /* Allow enough room for buffer to read more than a few pages from socket. */
paule3d29b52003-01-23 18:05:42 +0000115 bufsz = 5 * getpagesize() + 1;
paul718e3742002-12-13 20:15:29 +0000116 buf = XMALLOC(MTYPE_TMP, bufsz);
117 memset(buf, 0, bufsz);
118 pbuf = buf;
119
120 while (1)
121 {
122 if (pbuf >= ((buf + bufsz) -1))
123 {
124 fprintf (stderr, ERR_WHERE_STRING \
125 "warning - pbuf beyond buffer end.\n");
126 return CMD_WARNING;
127 }
128
129 readln = (buf + bufsz) - pbuf - 1;
130 nbytes = read (vclient->fd, pbuf, readln);
131
132 if (nbytes <= 0)
133 {
134
135 if (errno == EINTR)
136 continue;
137
138 fprintf(stderr, ERR_WHERE_STRING "(%u)", errno);
139 perror("");
140
141 if (errno == EAGAIN || errno == EIO)
142 continue;
143
144 vclient_close (vclient);
145 XFREE(MTYPE_TMP, buf);
146 return CMD_SUCCESS;
147 }
148
149 pbuf[nbytes] = '\0';
150
151 if (nbytes >= 4)
152 {
153 i = nbytes - 4;
154 if (pbuf[i] == '\0' && pbuf[i + 1] == '\0' && pbuf[i + 2] == '\0')
155 {
156 ret = pbuf[i + 3];
157 break;
158 }
159 }
160 pbuf += nbytes;
161
162 /* See if a line exists in buffer, if so parse and consume it, and
hasso95e735b2004-08-26 13:08:30 +0000163 * reset read position. */
paul718e3742002-12-13 20:15:29 +0000164 if ((eoln = strrchr(buf, '\n')) == NULL)
165 continue;
166
167 if (eoln >= ((buf + bufsz) - 1))
168 {
169 fprintf (stderr, ERR_WHERE_STRING \
170 "warning - eoln beyond buffer end.\n");
171 }
172 vtysh_config_parse(buf);
173
174 eoln++;
175 left = (size_t)(buf + bufsz - eoln);
176 memmove(buf, eoln, left);
177 buf[bufsz-1] = '\0';
178 pbuf = buf + strlen(buf);
179 }
180
hasso95e735b2004-08-26 13:08:30 +0000181 /* Parse anything left in the buffer. */
hassoe7168df2004-10-03 20:11:32 +0000182
paul718e3742002-12-13 20:15:29 +0000183 vtysh_config_parse (buf);
184
185 XFREE(MTYPE_TMP, buf);
186 return ret;
187}
188
ajs274a4a42004-12-07 15:39:31 +0000189static int
hassodda09522004-10-07 21:40:25 +0000190vtysh_client_execute (struct vtysh_client *vclient, const char *line, FILE *fp)
paul718e3742002-12-13 20:15:29 +0000191{
192 int ret;
193 char buf[1001];
194 int nbytes;
paul2852de12004-09-17 06:52:16 +0000195 int i;
196 int numnulls = 0;
paul718e3742002-12-13 20:15:29 +0000197
198 if (vclient->fd < 0)
199 return CMD_SUCCESS;
200
201 ret = write (vclient->fd, line, strlen (line) + 1);
202 if (ret <= 0)
203 {
204 vclient_close (vclient);
205 return CMD_SUCCESS;
206 }
207
208 while (1)
209 {
210 nbytes = read (vclient->fd, buf, sizeof(buf)-1);
211
212 if (nbytes <= 0 && errno != EINTR)
213 {
214 vclient_close (vclient);
215 return CMD_SUCCESS;
216 }
217
218 if (nbytes > 0)
219 {
ajs85fb1e62004-11-11 14:03:39 +0000220 if ((numnulls == 3) && (nbytes == 1))
221 return buf[0];
222
paul718e3742002-12-13 20:15:29 +0000223 buf[nbytes] = '\0';
ajs85fb1e62004-11-11 14:03:39 +0000224 fputs (buf, fp);
paul718e3742002-12-13 20:15:29 +0000225 fflush (fp);
paul2852de12004-09-17 06:52:16 +0000226
paul0921d482004-10-11 18:21:55 +0000227 /* check for trailling \0\0\0<ret code>,
228 * even if split across reads
229 * (see lib/vty.c::vtysh_read)
230 */
paul2852de12004-09-17 06:52:16 +0000231 if (nbytes >= 4)
232 {
233 i = nbytes-4;
234 numnulls = 0;
235 }
236 else
237 i = 0;
238
paul0921d482004-10-11 18:21:55 +0000239 while (i < nbytes && numnulls < 3)
paul2852de12004-09-17 06:52:16 +0000240 {
241 if (buf[i++] == '\0')
242 numnulls++;
243 else
ajs85fb1e62004-11-11 14:03:39 +0000244 numnulls = 0;
paul2852de12004-09-17 06:52:16 +0000245 }
paul718e3742002-12-13 20:15:29 +0000246
ajs85fb1e62004-11-11 14:03:39 +0000247 /* got 3 or more trailing NULs? */
248 if ((numnulls >= 3) && (i < nbytes))
paul0921d482004-10-11 18:21:55 +0000249 return (buf[nbytes-1]);
paul718e3742002-12-13 20:15:29 +0000250 }
251 }
paul718e3742002-12-13 20:15:29 +0000252}
253
paul718e3742002-12-13 20:15:29 +0000254void
ajsb1aa1472005-01-28 21:11:46 +0000255vtysh_pager_init (void)
paul718e3742002-12-13 20:15:29 +0000256{
hasso5a9c53d2004-08-27 14:23:28 +0000257 char *pager_defined;
258
259 pager_defined = getenv ("VTYSH_PAGER");
260
261 if (pager_defined)
262 vtysh_pager_name = strdup (pager_defined);
263 else
hasso34553cc2004-08-27 13:56:39 +0000264 vtysh_pager_name = strdup ("more");
paul718e3742002-12-13 20:15:29 +0000265}
266
267/* Command execution over the vty interface. */
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700268static int
hassodda09522004-10-07 21:40:25 +0000269vtysh_execute_func (const char *line, int pager)
paul718e3742002-12-13 20:15:29 +0000270{
Stephen Hemminger2c4d48b2008-07-28 15:04:56 -0700271 int ret, cmd_stat;
ajsb1aa1472005-01-28 21:11:46 +0000272 u_int i;
paul718e3742002-12-13 20:15:29 +0000273 vector vline;
274 struct cmd_element *cmd;
275 FILE *fp = NULL;
hasso13bfca72005-01-23 21:42:25 +0000276 int closepager = 0;
277 int tried = 0;
278 int saved_ret, saved_node;
paul718e3742002-12-13 20:15:29 +0000279
hasso95e735b2004-08-26 13:08:30 +0000280 /* Split readline string up into the vector. */
paul718e3742002-12-13 20:15:29 +0000281 vline = cmd_make_strvec (line);
282
283 if (vline == NULL)
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700284 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000285
hasso13bfca72005-01-23 21:42:25 +0000286 saved_ret = ret = cmd_execute_command (vline, vty, &cmd, 1);
287 saved_node = vty->node;
288
289 /* If command doesn't succeeded in current node, try to walk up in node tree.
290 * Changing vty->node is enough to try it just out without actual walkup in
291 * the vtysh. */
292 while (ret != CMD_SUCCESS && ret != CMD_SUCCESS_DAEMON && ret != CMD_WARNING
293 && vty->node > CONFIG_NODE)
294 {
295 vty->node = node_parent(vty->node);
296 ret = cmd_execute_command (vline, vty, &cmd, 1);
297 tried++;
298 }
299
300 vty->node = saved_node;
301
302 /* If command succeeded in any other node than current (tried > 0) we have
303 * to move into node in the vtysh where it succeeded. */
304 if (ret == CMD_SUCCESS || ret == CMD_SUCCESS_DAEMON || ret == CMD_WARNING)
305 {
306 if ((saved_node == BGP_VPNV4_NODE || saved_node == BGP_IPV4_NODE
paul57b5b7e2005-08-22 22:44:29 +0000307 || saved_node == BGP_IPV6_NODE || saved_node == BGP_IPV4M_NODE
308 || saved_node == BGP_IPV6M_NODE)
hasso13bfca72005-01-23 21:42:25 +0000309 && (tried == 1))
310 {
311 vtysh_execute("exit-address-family");
312 }
313 else if ((saved_node == KEYCHAIN_KEY_NODE) && (tried == 1))
314 {
315 vtysh_execute("exit");
316 }
317 else if (tried)
318 {
319 vtysh_execute ("end");
320 vtysh_execute ("configure terminal");
321 }
322 }
323 /* If command didn't succeed in any node, continue with return value from
324 * first try. */
325 else if (tried)
326 {
327 ret = saved_ret;
328 }
paul718e3742002-12-13 20:15:29 +0000329
330 cmd_free_strvec (vline);
331
Stephen Hemminger2c4d48b2008-07-28 15:04:56 -0700332 cmd_stat = ret;
paul718e3742002-12-13 20:15:29 +0000333 switch (ret)
334 {
335 case CMD_WARNING:
336 if (vty->type == VTY_FILE)
paul4fc01e62002-12-13 20:49:00 +0000337 fprintf (stdout,"Warning...\n");
paul718e3742002-12-13 20:15:29 +0000338 break;
339 case CMD_ERR_AMBIGUOUS:
paul4fc01e62002-12-13 20:49:00 +0000340 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000341 break;
342 case CMD_ERR_NO_MATCH:
paul4fc01e62002-12-13 20:49:00 +0000343 fprintf (stdout,"%% Unknown command.\n");
paul718e3742002-12-13 20:15:29 +0000344 break;
345 case CMD_ERR_INCOMPLETE:
paul4fc01e62002-12-13 20:49:00 +0000346 fprintf (stdout,"%% Command incomplete.\n");
paul718e3742002-12-13 20:15:29 +0000347 break;
348 case CMD_SUCCESS_DAEMON:
349 {
hasso97b7db22004-10-20 19:07:48 +0000350 /* FIXME: Don't open pager for exit commands. popen() causes problems
351 * if exited from vtysh at all. This hack shouldn't cause any problem
352 * but is really ugly. */
353 if (pager && vtysh_pager_name && (strncmp(line, "exit", 4) != 0))
paul718e3742002-12-13 20:15:29 +0000354 {
paul4fc01e62002-12-13 20:49:00 +0000355 fp = popen (vtysh_pager_name, "w");
paul718e3742002-12-13 20:15:29 +0000356 if (fp == NULL)
357 {
paula805cc22003-05-01 14:29:48 +0000358 perror ("popen failed for pager");
359 fp = stdout;
paul718e3742002-12-13 20:15:29 +0000360 }
paula805cc22003-05-01 14:29:48 +0000361 else
362 closepager=1;
paul718e3742002-12-13 20:15:29 +0000363 }
364 else
365 fp = stdout;
366
367 if (! strcmp(cmd->string,"configure terminal"))
368 {
Balaji.G837d16c2012-09-26 14:09:10 +0530369 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +0000370 {
371 cmd_stat = vtysh_client_execute(&vtysh_client[i], line, fp);
372 if (cmd_stat == CMD_WARNING)
373 break;
374 }
375
paul718e3742002-12-13 20:15:29 +0000376 if (cmd_stat)
377 {
hassob094d262004-08-25 12:22:00 +0000378 line = "end";
379 vline = cmd_make_strvec (line);
paul718e3742002-12-13 20:15:29 +0000380
hassob094d262004-08-25 12:22:00 +0000381 if (vline == NULL)
paul718e3742002-12-13 20:15:29 +0000382 {
paula805cc22003-05-01 14:29:48 +0000383 if (pager && vtysh_pager_name && fp && closepager)
paul718e3742002-12-13 20:15:29 +0000384 {
385 if (pclose (fp) == -1)
386 {
paula805cc22003-05-01 14:29:48 +0000387 perror ("pclose failed for pager");
paul718e3742002-12-13 20:15:29 +0000388 }
389 fp = NULL;
390 }
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700391 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000392 }
393
hasso87d683b2005-01-16 23:31:54 +0000394 ret = cmd_execute_command (vline, vty, &cmd, 1);
hassob094d262004-08-25 12:22:00 +0000395 cmd_free_strvec (vline);
396 if (ret != CMD_SUCCESS_DAEMON)
397 break;
paul718e3742002-12-13 20:15:29 +0000398 }
399 else
400 if (cmd->func)
401 {
402 (*cmd->func) (cmd, vty, 0, NULL);
403 break;
hassob094d262004-08-25 12:22:00 +0000404 }
paul718e3742002-12-13 20:15:29 +0000405 }
406
ajsb1aa1472005-01-28 21:11:46 +0000407 cmd_stat = CMD_SUCCESS;
Balaji.G837d16c2012-09-26 14:09:10 +0530408 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +0000409 {
410 if (cmd->daemon & vtysh_client[i].flag)
411 {
412 cmd_stat = vtysh_client_execute(&vtysh_client[i], line, fp);
413 if (cmd_stat != CMD_SUCCESS)
414 break;
415 }
416 }
417 if (cmd_stat != CMD_SUCCESS)
418 break;
419
paul718e3742002-12-13 20:15:29 +0000420 if (cmd->func)
421 (*cmd->func) (cmd, vty, 0, NULL);
422 }
423 }
paula805cc22003-05-01 14:29:48 +0000424 if (pager && vtysh_pager_name && fp && closepager)
paul718e3742002-12-13 20:15:29 +0000425 {
426 if (pclose (fp) == -1)
427 {
paula805cc22003-05-01 14:29:48 +0000428 perror ("pclose failed for pager");
paul718e3742002-12-13 20:15:29 +0000429 }
430 fp = NULL;
431 }
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700432 return cmd_stat;
paul718e3742002-12-13 20:15:29 +0000433}
434
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700435int
hassodda09522004-10-07 21:40:25 +0000436vtysh_execute_no_pager (const char *line)
paul718e3742002-12-13 20:15:29 +0000437{
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700438 return vtysh_execute_func (line, 0);
paul718e3742002-12-13 20:15:29 +0000439}
440
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700441int
hassodda09522004-10-07 21:40:25 +0000442vtysh_execute (const char *line)
paul718e3742002-12-13 20:15:29 +0000443{
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700444 return vtysh_execute_func (line, 1);
paul718e3742002-12-13 20:15:29 +0000445}
446
447/* Configration make from file. */
448int
449vtysh_config_from_file (struct vty *vty, FILE *fp)
450{
451 int ret;
paul718e3742002-12-13 20:15:29 +0000452 struct cmd_element *cmd;
453
454 while (fgets (vty->buf, VTY_BUFSIZ, fp))
455 {
Donald Sharpd8aa4be2015-09-28 20:10:40 -0400456 ret = command_config_read_one_line (vty, &cmd, 1);
paul718e3742002-12-13 20:15:29 +0000457
458 switch (ret)
459 {
460 case CMD_WARNING:
461 if (vty->type == VTY_FILE)
paul4fc01e62002-12-13 20:49:00 +0000462 fprintf (stdout,"Warning...\n");
paul718e3742002-12-13 20:15:29 +0000463 break;
464 case CMD_ERR_AMBIGUOUS:
paul4fc01e62002-12-13 20:49:00 +0000465 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000466 break;
467 case CMD_ERR_NO_MATCH:
paul4fc01e62002-12-13 20:49:00 +0000468 fprintf (stdout,"%% Unknown command: %s", vty->buf);
paul718e3742002-12-13 20:15:29 +0000469 break;
470 case CMD_ERR_INCOMPLETE:
paul4fc01e62002-12-13 20:49:00 +0000471 fprintf (stdout,"%% Command incomplete.\n");
paul718e3742002-12-13 20:15:29 +0000472 break;
473 case CMD_SUCCESS_DAEMON:
474 {
ajsb1aa1472005-01-28 21:11:46 +0000475 u_int i;
476 int cmd_stat = CMD_SUCCESS;
477
Balaji.G837d16c2012-09-26 14:09:10 +0530478 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +0000479 {
paul44316fe2006-01-11 01:38:25 +0000480 if (cmd->daemon & vtysh_client[i].flag)
ajsb1aa1472005-01-28 21:11:46 +0000481 {
482 cmd_stat = vtysh_client_execute (&vtysh_client[i],
483 vty->buf, stdout);
484 if (cmd_stat != CMD_SUCCESS)
485 break;
486 }
487 }
488 if (cmd_stat != CMD_SUCCESS)
489 break;
490
paul718e3742002-12-13 20:15:29 +0000491 if (cmd->func)
492 (*cmd->func) (cmd, vty, 0, NULL);
493 }
494 }
495 }
496 return CMD_SUCCESS;
497}
498
499/* We don't care about the point of the cursor when '?' is typed. */
David Lampartera9eb9062015-03-04 07:07:01 +0100500static int
ajsb1aa1472005-01-28 21:11:46 +0000501vtysh_rl_describe (void)
paul718e3742002-12-13 20:15:29 +0000502{
503 int ret;
hassodda09522004-10-07 21:40:25 +0000504 unsigned int i;
paul718e3742002-12-13 20:15:29 +0000505 vector vline;
506 vector describe;
507 int width;
Christian Frankecd40b322013-09-30 12:27:51 +0000508 struct cmd_token *token;
paul718e3742002-12-13 20:15:29 +0000509
510 vline = cmd_make_strvec (rl_line_buffer);
511
512 /* In case of '> ?'. */
513 if (vline == NULL)
514 {
515 vline = vector_init (1);
David Lampartera91a3ba2015-03-03 09:06:51 +0100516 vector_set (vline, NULL);
paul718e3742002-12-13 20:15:29 +0000517 }
518 else
519 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
David Lampartera91a3ba2015-03-03 09:06:51 +0100520 vector_set (vline, NULL);
paul718e3742002-12-13 20:15:29 +0000521
522 describe = cmd_describe_command (vline, vty, &ret);
523
paul4fc01e62002-12-13 20:49:00 +0000524 fprintf (stdout,"\n");
paul718e3742002-12-13 20:15:29 +0000525
526 /* Ambiguous and no match error. */
527 switch (ret)
528 {
529 case CMD_ERR_AMBIGUOUS:
530 cmd_free_strvec (vline);
paul4fc01e62002-12-13 20:49:00 +0000531 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000532 rl_on_new_line ();
533 return 0;
534 break;
535 case CMD_ERR_NO_MATCH:
536 cmd_free_strvec (vline);
paul4fc01e62002-12-13 20:49:00 +0000537 fprintf (stdout,"%% There is no matched command.\n");
paul718e3742002-12-13 20:15:29 +0000538 rl_on_new_line ();
539 return 0;
540 break;
541 }
542
543 /* Get width of command string. */
544 width = 0;
paul55468c82005-03-14 20:19:01 +0000545 for (i = 0; i < vector_active (describe); i++)
Christian Frankecd40b322013-09-30 12:27:51 +0000546 if ((token = vector_slot (describe, i)) != NULL)
paul718e3742002-12-13 20:15:29 +0000547 {
548 int len;
549
Christian Frankecd40b322013-09-30 12:27:51 +0000550 if (token->cmd[0] == '\0')
paul718e3742002-12-13 20:15:29 +0000551 continue;
552
Christian Frankecd40b322013-09-30 12:27:51 +0000553 len = strlen (token->cmd);
554 if (token->cmd[0] == '.')
paul718e3742002-12-13 20:15:29 +0000555 len--;
556
557 if (width < len)
558 width = len;
559 }
560
paul55468c82005-03-14 20:19:01 +0000561 for (i = 0; i < vector_active (describe); i++)
Christian Frankecd40b322013-09-30 12:27:51 +0000562 if ((token = vector_slot (describe, i)) != NULL)
paul718e3742002-12-13 20:15:29 +0000563 {
Christian Frankecd40b322013-09-30 12:27:51 +0000564 if (token->cmd[0] == '\0')
paul718e3742002-12-13 20:15:29 +0000565 continue;
566
Christian Frankecd40b322013-09-30 12:27:51 +0000567 if (! token->desc)
paul4fc01e62002-12-13 20:49:00 +0000568 fprintf (stdout," %-s\n",
Christian Frankecd40b322013-09-30 12:27:51 +0000569 token->cmd[0] == '.' ? token->cmd + 1 : token->cmd);
paul718e3742002-12-13 20:15:29 +0000570 else
paul4fc01e62002-12-13 20:49:00 +0000571 fprintf (stdout," %-*s %s\n",
hassob094d262004-08-25 12:22:00 +0000572 width,
Christian Frankecd40b322013-09-30 12:27:51 +0000573 token->cmd[0] == '.' ? token->cmd + 1 : token->cmd,
574 token->desc);
paul718e3742002-12-13 20:15:29 +0000575 }
576
577 cmd_free_strvec (vline);
578 vector_free (describe);
579
580 rl_on_new_line();
581
582 return 0;
583}
584
hasso95e735b2004-08-26 13:08:30 +0000585/* Result of cmd_complete_command() call will be stored here
586 * and used in new_completion() in order to put the space in
587 * correct places only. */
paul718e3742002-12-13 20:15:29 +0000588int complete_status;
589
ajs274a4a42004-12-07 15:39:31 +0000590static char *
pauldfc0d9b2003-04-18 23:55:29 +0000591command_generator (const char *text, int state)
paul718e3742002-12-13 20:15:29 +0000592{
593 vector vline;
594 static char **matched = NULL;
595 static int index = 0;
596
597 /* First call. */
598 if (! state)
599 {
600 index = 0;
601
602 if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
603 return NULL;
604
605 vline = cmd_make_strvec (rl_line_buffer);
606 if (vline == NULL)
607 return NULL;
608
609 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
David Lampartera91a3ba2015-03-03 09:06:51 +0100610 vector_set (vline, NULL);
paul718e3742002-12-13 20:15:29 +0000611
612 matched = cmd_complete_command (vline, vty, &complete_status);
613 }
614
615 if (matched && matched[index])
616 return matched[index++];
617
618 return NULL;
619}
620
ajs274a4a42004-12-07 15:39:31 +0000621static char **
paul718e3742002-12-13 20:15:29 +0000622new_completion (char *text, int start, int end)
623{
624 char **matches;
625
pauldfc0d9b2003-04-18 23:55:29 +0000626 matches = rl_completion_matches (text, command_generator);
paul718e3742002-12-13 20:15:29 +0000627
628 if (matches)
629 {
630 rl_point = rl_end;
Christian Franke67e7a212013-03-04 09:23:30 +0000631 if (complete_status != CMD_COMPLETE_FULL_MATCH)
632 /* only append a space on full match */
633 rl_completion_append_character = '\0';
paul718e3742002-12-13 20:15:29 +0000634 }
635
636 return matches;
637}
638
ajs274a4a42004-12-07 15:39:31 +0000639#if 0
640/* This function is not actually being used. */
641static char **
paul718e3742002-12-13 20:15:29 +0000642vtysh_completion (char *text, int start, int end)
643{
644 int ret;
645 vector vline;
646 char **matched = NULL;
647
648 if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
649 return NULL;
650
651 vline = cmd_make_strvec (rl_line_buffer);
652 if (vline == NULL)
653 return NULL;
654
655 /* In case of 'help \t'. */
656 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
657 vector_set (vline, '\0');
658
659 matched = cmd_complete_command (vline, vty, &ret);
660
661 cmd_free_strvec (vline);
662
663 return (char **) matched;
664}
ajs274a4a42004-12-07 15:39:31 +0000665#endif
paul718e3742002-12-13 20:15:29 +0000666
hasso95e735b2004-08-26 13:08:30 +0000667/* Vty node structures. */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800668static struct cmd_node bgp_node =
paul718e3742002-12-13 20:15:29 +0000669{
670 BGP_NODE,
671 "%s(config-router)# ",
672};
673
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800674static struct cmd_node rip_node =
paul718e3742002-12-13 20:15:29 +0000675{
676 RIP_NODE,
677 "%s(config-router)# ",
678};
679
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800680static struct cmd_node isis_node =
hassoc25e4582003-12-23 10:39:08 +0000681{
682 ISIS_NODE,
683 "%s(config-router)# ",
hassoc25e4582003-12-23 10:39:08 +0000684};
685
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800686static struct cmd_node interface_node =
paul718e3742002-12-13 20:15:29 +0000687{
688 INTERFACE_NODE,
689 "%s(config-if)# ",
690};
691
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800692static struct cmd_node rmap_node =
hasso95e735b2004-08-26 13:08:30 +0000693{
694 RMAP_NODE,
695 "%s(config-route-map)# "
696};
697
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800698static struct cmd_node zebra_node =
hasso95e735b2004-08-26 13:08:30 +0000699{
700 ZEBRA_NODE,
701 "%s(config-router)# "
702};
703
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800704static struct cmd_node bgp_vpnv4_node =
hasso95e735b2004-08-26 13:08:30 +0000705{
706 BGP_VPNV4_NODE,
707 "%s(config-router-af)# "
708};
709
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800710static struct cmd_node bgp_ipv4_node =
hasso95e735b2004-08-26 13:08:30 +0000711{
712 BGP_IPV4_NODE,
713 "%s(config-router-af)# "
714};
715
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800716static struct cmd_node bgp_ipv4m_node =
hasso95e735b2004-08-26 13:08:30 +0000717{
718 BGP_IPV4M_NODE,
719 "%s(config-router-af)# "
720};
721
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800722static struct cmd_node bgp_ipv6_node =
hasso95e735b2004-08-26 13:08:30 +0000723{
724 BGP_IPV6_NODE,
725 "%s(config-router-af)# "
726};
727
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800728static struct cmd_node bgp_ipv6m_node =
paul57b5b7e2005-08-22 22:44:29 +0000729{
730 BGP_IPV6M_NODE,
731 "%s(config-router-af)# "
732};
733
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800734static struct cmd_node ospf_node =
hasso95e735b2004-08-26 13:08:30 +0000735{
736 OSPF_NODE,
737 "%s(config-router)# "
738};
739
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800740static struct cmd_node ripng_node =
hasso95e735b2004-08-26 13:08:30 +0000741{
742 RIPNG_NODE,
743 "%s(config-router)# "
744};
745
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800746static struct cmd_node ospf6_node =
hasso95e735b2004-08-26 13:08:30 +0000747{
748 OSPF6_NODE,
749 "%s(config-ospf6)# "
750};
751
David Lamparteree53c8b2015-05-23 05:45:59 +0200752static struct cmd_node babel_node =
753{
754 BABEL_NODE,
755 "%s(config-babel)# "
756};
757
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800758static struct cmd_node keychain_node =
hasso95e735b2004-08-26 13:08:30 +0000759{
760 KEYCHAIN_NODE,
761 "%s(config-keychain)# "
762};
763
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800764static struct cmd_node keychain_key_node =
hasso95e735b2004-08-26 13:08:30 +0000765{
766 KEYCHAIN_KEY_NODE,
767 "%s(config-keychain-key)# "
768};
769
hassoe7168df2004-10-03 20:11:32 +0000770/* Defined in lib/vty.c */
771extern struct cmd_node vty_node;
772
hasso95e735b2004-08-26 13:08:30 +0000773/* When '^Z' is received from vty, move down to the enable mode. */
David Lampartera9eb9062015-03-04 07:07:01 +0100774static int
ajsb1aa1472005-01-28 21:11:46 +0000775vtysh_end (void)
hasso95e735b2004-08-26 13:08:30 +0000776{
777 switch (vty->node)
778 {
779 case VIEW_NODE:
780 case ENABLE_NODE:
781 /* Nothing to do. */
782 break;
783 default:
784 vty->node = ENABLE_NODE;
785 break;
786 }
787 return CMD_SUCCESS;
788}
789
790DEFUNSH (VTYSH_ALL,
791 vtysh_end_all,
792 vtysh_end_all_cmd,
793 "end",
hassoe7168df2004-10-03 20:11:32 +0000794 "End current mode and change to enable mode\n")
hasso95e735b2004-08-26 13:08:30 +0000795{
hasso42895462004-09-26 16:25:07 +0000796 return vtysh_end ();
hasso95e735b2004-08-26 13:08:30 +0000797}
798
paul718e3742002-12-13 20:15:29 +0000799DEFUNSH (VTYSH_BGPD,
800 router_bgp,
801 router_bgp_cmd,
Paul Jakma320da872008-07-02 13:40:33 +0000802 "router bgp " CMD_AS_RANGE,
paul718e3742002-12-13 20:15:29 +0000803 ROUTER_STR
804 BGP_STR
805 AS_STR)
806{
807 vty->node = BGP_NODE;
808 return CMD_SUCCESS;
809}
810
Paul Jakma10895fd2008-07-03 19:34:48 +0000811ALIAS_SH (VTYSH_BGPD,
812 router_bgp,
813 router_bgp_view_cmd,
814 "router bgp " CMD_AS_RANGE " view WORD",
815 ROUTER_STR
816 BGP_STR
817 AS_STR
818 "BGP view\n"
819 "view name\n")
820
paul718e3742002-12-13 20:15:29 +0000821DEFUNSH (VTYSH_BGPD,
822 address_family_vpnv4,
823 address_family_vpnv4_cmd,
824 "address-family vpnv4",
825 "Enter Address Family command mode\n"
826 "Address family\n")
827{
828 vty->node = BGP_VPNV4_NODE;
829 return CMD_SUCCESS;
830}
831
832DEFUNSH (VTYSH_BGPD,
833 address_family_vpnv4_unicast,
834 address_family_vpnv4_unicast_cmd,
835 "address-family vpnv4 unicast",
836 "Enter Address Family command mode\n"
837 "Address family\n"
838 "Address Family Modifier\n")
839{
840 vty->node = BGP_VPNV4_NODE;
841 return CMD_SUCCESS;
842}
843
844DEFUNSH (VTYSH_BGPD,
845 address_family_ipv4_unicast,
846 address_family_ipv4_unicast_cmd,
847 "address-family ipv4 unicast",
848 "Enter Address Family command mode\n"
849 "Address family\n"
850 "Address Family Modifier\n")
851{
852 vty->node = BGP_IPV4_NODE;
853 return CMD_SUCCESS;
854}
855
856DEFUNSH (VTYSH_BGPD,
857 address_family_ipv4_multicast,
858 address_family_ipv4_multicast_cmd,
859 "address-family ipv4 multicast",
860 "Enter Address Family command mode\n"
861 "Address family\n"
862 "Address Family Modifier\n")
863{
864 vty->node = BGP_IPV4M_NODE;
865 return CMD_SUCCESS;
866}
867
868DEFUNSH (VTYSH_BGPD,
869 address_family_ipv6,
870 address_family_ipv6_cmd,
871 "address-family ipv6",
872 "Enter Address Family command mode\n"
873 "Address family\n")
874{
875 vty->node = BGP_IPV6_NODE;
876 return CMD_SUCCESS;
877}
878
879DEFUNSH (VTYSH_BGPD,
880 address_family_ipv6_unicast,
881 address_family_ipv6_unicast_cmd,
882 "address-family ipv6 unicast",
883 "Enter Address Family command mode\n"
884 "Address family\n"
885 "Address Family Modifier\n")
886{
887 vty->node = BGP_IPV6_NODE;
888 return CMD_SUCCESS;
889}
890
paul57b5b7e2005-08-22 22:44:29 +0000891DEFUNSH (VTYSH_BGPD,
892 address_family_ipv6_multicast,
893 address_family_ipv6_multicast_cmd,
894 "address-family ipv6 multicast",
895 "Enter Address Family command mode\n"
896 "Address family\n"
897 "Address Family Modifier\n")
898{
899 vty->node = BGP_IPV6M_NODE;
900 return CMD_SUCCESS;
901}
902
paul718e3742002-12-13 20:15:29 +0000903DEFUNSH (VTYSH_RIPD,
904 key_chain,
905 key_chain_cmd,
906 "key chain WORD",
907 "Authentication key management\n"
908 "Key-chain management\n"
909 "Key-chain name\n")
910{
911 vty->node = KEYCHAIN_NODE;
912 return CMD_SUCCESS;
913}
914
915DEFUNSH (VTYSH_RIPD,
916 key,
917 key_cmd,
918 "key <0-2147483647>",
919 "Configure a key\n"
920 "Key identifier number\n")
921{
922 vty->node = KEYCHAIN_KEY_NODE;
923 return CMD_SUCCESS;
924}
925
926DEFUNSH (VTYSH_RIPD,
927 router_rip,
928 router_rip_cmd,
929 "router rip",
930 ROUTER_STR
931 "RIP")
932{
933 vty->node = RIP_NODE;
934 return CMD_SUCCESS;
935}
936
937DEFUNSH (VTYSH_RIPNGD,
938 router_ripng,
939 router_ripng_cmd,
940 "router ripng",
941 ROUTER_STR
942 "RIPng")
943{
944 vty->node = RIPNG_NODE;
945 return CMD_SUCCESS;
946}
947
948DEFUNSH (VTYSH_OSPFD,
949 router_ospf,
950 router_ospf_cmd,
951 "router ospf",
952 "Enable a routing process\n"
953 "Start OSPF configuration\n")
954{
955 vty->node = OSPF_NODE;
956 return CMD_SUCCESS;
957}
958
959DEFUNSH (VTYSH_OSPF6D,
960 router_ospf6,
961 router_ospf6_cmd,
962 "router ospf6",
963 OSPF6_ROUTER_STR
964 OSPF6_STR)
965{
966 vty->node = OSPF6_NODE;
967 return CMD_SUCCESS;
968}
969
hassoc25e4582003-12-23 10:39:08 +0000970DEFUNSH (VTYSH_ISISD,
hassob094d262004-08-25 12:22:00 +0000971 router_isis,
972 router_isis_cmd,
973 "router isis WORD",
974 ROUTER_STR
975 "ISO IS-IS\n"
976 "ISO Routing area tag")
hassoc25e4582003-12-23 10:39:08 +0000977{
978 vty->node = ISIS_NODE;
979 return CMD_SUCCESS;
980}
981
paul718e3742002-12-13 20:15:29 +0000982DEFUNSH (VTYSH_RMAP,
983 route_map,
984 route_map_cmd,
985 "route-map WORD (deny|permit) <1-65535>",
986 "Create route-map or enter route-map command mode\n"
987 "Route map tag\n"
988 "Route map denies set operations\n"
989 "Route map permits set operations\n"
990 "Sequence to insert to/delete from existing route-map entry\n")
991{
992 vty->node = RMAP_NODE;
993 return CMD_SUCCESS;
994}
995
paul718e3742002-12-13 20:15:29 +0000996DEFUNSH (VTYSH_ALL,
hassoe7168df2004-10-03 20:11:32 +0000997 vtysh_line_vty,
998 vtysh_line_vty_cmd,
999 "line vty",
1000 "Configure a terminal line\n"
1001 "Virtual terminal\n")
1002{
1003 vty->node = VTY_NODE;
1004 return CMD_SUCCESS;
1005}
1006
1007DEFUNSH (VTYSH_ALL,
paul718e3742002-12-13 20:15:29 +00001008 vtysh_enable,
1009 vtysh_enable_cmd,
1010 "enable",
1011 "Turn on privileged mode command\n")
1012{
1013 vty->node = ENABLE_NODE;
1014 return CMD_SUCCESS;
1015}
1016
paul718e3742002-12-13 20:15:29 +00001017DEFUNSH (VTYSH_ALL,
1018 vtysh_disable,
1019 vtysh_disable_cmd,
1020 "disable",
1021 "Turn off privileged mode command\n")
1022{
1023 if (vty->node == ENABLE_NODE)
1024 vty->node = VIEW_NODE;
1025 return CMD_SUCCESS;
1026}
1027
paul718e3742002-12-13 20:15:29 +00001028DEFUNSH (VTYSH_ALL,
1029 vtysh_config_terminal,
1030 vtysh_config_terminal_cmd,
1031 "configure terminal",
1032 "Configuration from vty interface\n"
1033 "Configuration terminal\n")
1034{
1035 vty->node = CONFIG_NODE;
1036 return CMD_SUCCESS;
1037}
1038
ajs274a4a42004-12-07 15:39:31 +00001039static int
paul718e3742002-12-13 20:15:29 +00001040vtysh_exit (struct vty *vty)
1041{
1042 switch (vty->node)
1043 {
1044 case VIEW_NODE:
1045 case ENABLE_NODE:
1046 exit (0);
1047 break;
1048 case CONFIG_NODE:
1049 vty->node = ENABLE_NODE;
1050 break;
1051 case INTERFACE_NODE:
1052 case ZEBRA_NODE:
1053 case BGP_NODE:
1054 case RIP_NODE:
1055 case RIPNG_NODE:
1056 case OSPF_NODE:
1057 case OSPF6_NODE:
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +01001058 case BABEL_NODE:
hassoc25e4582003-12-23 10:39:08 +00001059 case ISIS_NODE:
paul718e3742002-12-13 20:15:29 +00001060 case MASC_NODE:
1061 case RMAP_NODE:
1062 case VTY_NODE:
1063 case KEYCHAIN_NODE:
hasso2a56df92004-05-09 23:16:40 +00001064 vtysh_execute("end");
1065 vtysh_execute("configure terminal");
paul718e3742002-12-13 20:15:29 +00001066 vty->node = CONFIG_NODE;
1067 break;
1068 case BGP_VPNV4_NODE:
1069 case BGP_IPV4_NODE:
1070 case BGP_IPV4M_NODE:
1071 case BGP_IPV6_NODE:
paul57b5b7e2005-08-22 22:44:29 +00001072 case BGP_IPV6M_NODE:
paul718e3742002-12-13 20:15:29 +00001073 vty->node = BGP_NODE;
1074 break;
1075 case KEYCHAIN_KEY_NODE:
1076 vty->node = KEYCHAIN_NODE;
1077 break;
1078 default:
1079 break;
1080 }
1081 return CMD_SUCCESS;
1082}
1083
1084DEFUNSH (VTYSH_ALL,
1085 vtysh_exit_all,
1086 vtysh_exit_all_cmd,
1087 "exit",
1088 "Exit current mode and down to previous mode\n")
1089{
1090 return vtysh_exit (vty);
1091}
1092
1093ALIAS (vtysh_exit_all,
1094 vtysh_quit_all_cmd,
1095 "quit",
1096 "Exit current mode and down to previous mode\n")
1097
1098DEFUNSH (VTYSH_BGPD,
1099 exit_address_family,
1100 exit_address_family_cmd,
1101 "exit-address-family",
1102 "Exit from Address Family configuration mode\n")
1103{
1104 if (vty->node == BGP_IPV4_NODE
1105 || vty->node == BGP_IPV4M_NODE
1106 || vty->node == BGP_VPNV4_NODE
paul57b5b7e2005-08-22 22:44:29 +00001107 || vty->node == BGP_IPV6_NODE
1108 || vty->node == BGP_IPV6M_NODE)
paul718e3742002-12-13 20:15:29 +00001109 vty->node = BGP_NODE;
1110 return CMD_SUCCESS;
1111}
1112
1113DEFUNSH (VTYSH_ZEBRA,
1114 vtysh_exit_zebra,
1115 vtysh_exit_zebra_cmd,
1116 "exit",
1117 "Exit current mode and down to previous mode\n")
1118{
1119 return vtysh_exit (vty);
1120}
1121
1122ALIAS (vtysh_exit_zebra,
1123 vtysh_quit_zebra_cmd,
1124 "quit",
1125 "Exit current mode and down to previous mode\n")
1126
1127DEFUNSH (VTYSH_RIPD,
1128 vtysh_exit_ripd,
1129 vtysh_exit_ripd_cmd,
1130 "exit",
1131 "Exit current mode and down to previous mode\n")
1132{
1133 return vtysh_exit (vty);
1134}
1135
1136ALIAS (vtysh_exit_ripd,
1137 vtysh_quit_ripd_cmd,
1138 "quit",
1139 "Exit current mode and down to previous mode\n")
1140
paul68980082003-03-25 05:07:42 +00001141DEFUNSH (VTYSH_RIPNGD,
hassob094d262004-08-25 12:22:00 +00001142 vtysh_exit_ripngd,
1143 vtysh_exit_ripngd_cmd,
1144 "exit",
1145 "Exit current mode and down to previous mode\n")
paul68980082003-03-25 05:07:42 +00001146{
1147 return vtysh_exit (vty);
1148}
1149
1150ALIAS (vtysh_exit_ripngd,
1151 vtysh_quit_ripngd_cmd,
1152 "quit",
1153 "Exit current mode and down to previous mode\n")
1154
paul718e3742002-12-13 20:15:29 +00001155DEFUNSH (VTYSH_RMAP,
1156 vtysh_exit_rmap,
1157 vtysh_exit_rmap_cmd,
1158 "exit",
1159 "Exit current mode and down to previous mode\n")
1160{
1161 return vtysh_exit (vty);
1162}
1163
1164ALIAS (vtysh_exit_rmap,
1165 vtysh_quit_rmap_cmd,
1166 "quit",
1167 "Exit current mode and down to previous mode\n")
1168
1169DEFUNSH (VTYSH_BGPD,
1170 vtysh_exit_bgpd,
1171 vtysh_exit_bgpd_cmd,
1172 "exit",
1173 "Exit current mode and down to previous mode\n")
1174{
1175 return vtysh_exit (vty);
1176}
1177
1178ALIAS (vtysh_exit_bgpd,
1179 vtysh_quit_bgpd_cmd,
1180 "quit",
1181 "Exit current mode and down to previous mode\n")
1182
1183DEFUNSH (VTYSH_OSPFD,
1184 vtysh_exit_ospfd,
1185 vtysh_exit_ospfd_cmd,
1186 "exit",
1187 "Exit current mode and down to previous mode\n")
1188{
1189 return vtysh_exit (vty);
1190}
1191
1192ALIAS (vtysh_exit_ospfd,
1193 vtysh_quit_ospfd_cmd,
1194 "quit",
1195 "Exit current mode and down to previous mode\n")
1196
paul68980082003-03-25 05:07:42 +00001197DEFUNSH (VTYSH_OSPF6D,
hassob094d262004-08-25 12:22:00 +00001198 vtysh_exit_ospf6d,
1199 vtysh_exit_ospf6d_cmd,
1200 "exit",
1201 "Exit current mode and down to previous mode\n")
paul68980082003-03-25 05:07:42 +00001202{
1203 return vtysh_exit (vty);
1204}
1205
1206ALIAS (vtysh_exit_ospf6d,
1207 vtysh_quit_ospf6d_cmd,
1208 "quit",
1209 "Exit current mode and down to previous mode\n")
1210
hassoc25e4582003-12-23 10:39:08 +00001211DEFUNSH (VTYSH_ISISD,
hassob094d262004-08-25 12:22:00 +00001212 vtysh_exit_isisd,
1213 vtysh_exit_isisd_cmd,
1214 "exit",
1215 "Exit current mode and down to previous mode\n")
hassoc25e4582003-12-23 10:39:08 +00001216{
1217 return vtysh_exit (vty);
1218}
1219
1220ALIAS (vtysh_exit_isisd,
1221 vtysh_quit_isisd_cmd,
1222 "quit",
1223 "Exit current mode and down to previous mode\n")
1224
hassoe7168df2004-10-03 20:11:32 +00001225DEFUNSH (VTYSH_ALL,
1226 vtysh_exit_line_vty,
1227 vtysh_exit_line_vty_cmd,
1228 "exit",
1229 "Exit current mode and down to previous mode\n")
1230{
1231 return vtysh_exit (vty);
1232}
1233
1234ALIAS (vtysh_exit_line_vty,
1235 vtysh_quit_line_vty_cmd,
1236 "quit",
1237 "Exit current mode and down to previous mode\n")
1238
hasso95e735b2004-08-26 13:08:30 +00001239DEFUNSH (VTYSH_INTERFACE,
paul718e3742002-12-13 20:15:29 +00001240 vtysh_interface,
1241 vtysh_interface_cmd,
1242 "interface IFNAME",
1243 "Select an interface to configure\n"
1244 "Interface's name\n")
1245{
1246 vty->node = INTERFACE_NODE;
1247 return CMD_SUCCESS;
1248}
1249
Feng Lu471ea392015-05-22 11:40:00 +02001250ALIAS_SH (VTYSH_ZEBRA,
1251 vtysh_interface,
1252 vtysh_interface_vrf_cmd,
1253 "interface IFNAME " VRF_CMD_STR,
1254 "Select an interface to configure\n"
1255 "Interface's name\n"
1256 VRF_CMD_HELP_STR)
1257
hasso95e735b2004-08-26 13:08:30 +00001258/* TODO Implement "no interface command in isisd. */
paul32d24632003-05-23 09:25:20 +00001259DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D,
1260 vtysh_no_interface_cmd,
1261 "no interface IFNAME",
1262 NO_STR
1263 "Delete a pseudo interface's configuration\n"
1264 "Interface's name\n")
1265
Feng Lu471ea392015-05-22 11:40:00 +02001266DEFSH (VTYSH_ZEBRA,
1267 vtysh_no_interface_vrf_cmd,
1268 "no interface IFNAME " VRF_CMD_STR,
1269 NO_STR
1270 "Delete a pseudo interface's configuration\n"
1271 "Interface's name\n"
1272 VRF_CMD_HELP_STR)
1273
hasso95e735b2004-08-26 13:08:30 +00001274/* TODO Implement interface description commands in ripngd, ospf6d
1275 * and isisd. */
paul338a9912003-03-01 15:44:10 +00001276DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1277 interface_desc_cmd,
1278 "description .LINE",
1279 "Interface specific description\n"
1280 "Characters describing this interface\n")
paul464dc8d2003-03-28 02:25:45 +00001281
1282DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1283 no_interface_desc_cmd,
1284 "no description",
1285 NO_STR
1286 "Interface specific description\n")
paul338a9912003-03-01 15:44:10 +00001287
hasso95e735b2004-08-26 13:08:30 +00001288DEFUNSH (VTYSH_INTERFACE,
paul718e3742002-12-13 20:15:29 +00001289 vtysh_exit_interface,
1290 vtysh_exit_interface_cmd,
1291 "exit",
1292 "Exit current mode and down to previous mode\n")
1293{
1294 return vtysh_exit (vty);
1295}
1296
1297ALIAS (vtysh_exit_interface,
1298 vtysh_quit_interface_cmd,
1299 "quit",
1300 "Exit current mode and down to previous mode\n")
1301
Donald Sharp567a6382015-08-19 21:22:17 -04001302DEFUN (vtysh_show_thread,
1303 vtysh_show_thread_cmd,
1304 "show thread cpu [FILTER]",
1305 SHOW_STR
1306 "Thread information\n"
1307 "Thread CPU usage\n"
1308 "Display filter (rwtexb)\n")
1309{
1310 unsigned int i;
1311 int ret = CMD_SUCCESS;
1312 char line[100];
1313
1314 sprintf(line, "show thread cpu %s\n", (argc == 1) ? argv[0] : "");
1315 for (i = 0; i < array_size(vtysh_client); i++)
1316 if ( vtysh_client[i].fd >= 0 )
1317 {
1318 fprintf (stdout, "Thread statistics for %s:\n",
1319 vtysh_client[i].name);
1320 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1321 fprintf (stdout,"\n");
1322 }
1323 return ret;
1324}
1325
1326DEFUN (vtysh_show_work_queues,
1327 vtysh_show_work_queues_cmd,
1328 "show work-queues",
1329 SHOW_STR
1330 "Work Queue information\n")
1331{
1332 unsigned int i;
1333 int ret = CMD_SUCCESS;
1334 char line[] = "show work-queues\n";
1335
1336 for (i = 0; i < array_size(vtysh_client); i++)
1337 if ( vtysh_client[i].fd >= 0 )
1338 {
1339 fprintf (stdout, "Work queue 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
Paul Jakma362b4032006-05-28 07:54:45 +00001348/* Memory */
1349DEFUN (vtysh_show_memory,
1350 vtysh_show_memory_cmd,
1351 "show memory",
1352 SHOW_STR
1353 "Memory statistics\n")
1354{
1355 unsigned int i;
1356 int ret = CMD_SUCCESS;
1357 char line[] = "show memory\n";
1358
Balaji.G837d16c2012-09-26 14:09:10 +05301359 for (i = 0; i < array_size(vtysh_client); i++)
Paul Jakma362b4032006-05-28 07:54:45 +00001360 if ( vtysh_client[i].fd >= 0 )
1361 {
1362 fprintf (stdout, "Memory statistics for %s:\n",
1363 vtysh_client[i].name);
1364 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1365 fprintf (stdout,"\n");
1366 }
1367
1368 return ret;
1369}
1370
hasso95e735b2004-08-26 13:08:30 +00001371/* Logging commands. */
Paul Jakmadbf7d132006-05-23 22:10:01 +00001372DEFUN (vtysh_show_logging,
1373 vtysh_show_logging_cmd,
1374 "show logging",
1375 SHOW_STR
1376 "Show current logging configuration\n")
1377{
1378 unsigned int i;
1379 int ret = CMD_SUCCESS;
1380 char line[] = "show logging\n";
1381
Balaji.G837d16c2012-09-26 14:09:10 +05301382 for (i = 0; i < array_size(vtysh_client); i++)
Paul Jakma4150f332006-05-23 22:10:55 +00001383 if ( vtysh_client[i].fd >= 0 )
1384 {
1385 fprintf (stdout,"Logging configuration for %s:\n",
1386 vtysh_client[i].name);
1387 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1388 fprintf (stdout,"\n");
1389 }
1390
Paul Jakmadbf7d132006-05-23 22:10:01 +00001391 return ret;
1392}
1393
hasso95e735b2004-08-26 13:08:30 +00001394DEFUNSH (VTYSH_ALL,
1395 vtysh_log_stdout,
1396 vtysh_log_stdout_cmd,
1397 "log stdout",
1398 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001399 "Set stdout logging level\n")
1400{
1401 return CMD_SUCCESS;
1402}
1403
1404DEFUNSH (VTYSH_ALL,
1405 vtysh_log_stdout_level,
1406 vtysh_log_stdout_level_cmd,
1407 "log stdout "LOG_LEVELS,
1408 "Logging control\n"
1409 "Set stdout logging level\n"
1410 LOG_LEVEL_DESC)
hasso95e735b2004-08-26 13:08:30 +00001411{
1412 return CMD_SUCCESS;
1413}
1414
1415DEFUNSH (VTYSH_ALL,
1416 no_vtysh_log_stdout,
1417 no_vtysh_log_stdout_cmd,
ajs274a4a42004-12-07 15:39:31 +00001418 "no log stdout [LEVEL]",
hasso95e735b2004-08-26 13:08:30 +00001419 NO_STR
1420 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001421 "Cancel logging to stdout\n"
1422 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001423{
1424 return CMD_SUCCESS;
1425}
1426
1427DEFUNSH (VTYSH_ALL,
1428 vtysh_log_file,
1429 vtysh_log_file_cmd,
1430 "log file FILENAME",
1431 "Logging control\n"
1432 "Logging to file\n"
1433 "Logging filename\n")
1434{
1435 return CMD_SUCCESS;
1436}
1437
1438DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001439 vtysh_log_file_level,
1440 vtysh_log_file_level_cmd,
1441 "log file FILENAME "LOG_LEVELS,
1442 "Logging control\n"
1443 "Logging to file\n"
1444 "Logging filename\n"
1445 LOG_LEVEL_DESC)
1446{
1447 return CMD_SUCCESS;
1448}
1449
1450DEFUNSH (VTYSH_ALL,
hasso95e735b2004-08-26 13:08:30 +00001451 no_vtysh_log_file,
1452 no_vtysh_log_file_cmd,
1453 "no log file [FILENAME]",
1454 NO_STR
1455 "Logging control\n"
1456 "Cancel logging to file\n"
1457 "Logging file name\n")
1458{
1459 return CMD_SUCCESS;
1460}
1461
ajs274a4a42004-12-07 15:39:31 +00001462ALIAS_SH (VTYSH_ALL,
1463 no_vtysh_log_file,
1464 no_vtysh_log_file_level_cmd,
1465 "no log file FILENAME LEVEL",
1466 NO_STR
1467 "Logging control\n"
1468 "Cancel logging to file\n"
1469 "Logging file name\n"
1470 "Logging level\n")
1471
1472DEFUNSH (VTYSH_ALL,
1473 vtysh_log_monitor,
1474 vtysh_log_monitor_cmd,
1475 "log monitor",
1476 "Logging control\n"
1477 "Set terminal line (monitor) logging level\n")
1478{
1479 return CMD_SUCCESS;
1480}
1481
1482DEFUNSH (VTYSH_ALL,
1483 vtysh_log_monitor_level,
1484 vtysh_log_monitor_level_cmd,
1485 "log monitor "LOG_LEVELS,
1486 "Logging control\n"
1487 "Set terminal line (monitor) logging level\n"
1488 LOG_LEVEL_DESC)
1489{
1490 return CMD_SUCCESS;
1491}
1492
1493DEFUNSH (VTYSH_ALL,
1494 no_vtysh_log_monitor,
1495 no_vtysh_log_monitor_cmd,
1496 "no log monitor [LEVEL]",
1497 NO_STR
1498 "Logging control\n"
1499 "Disable terminal line (monitor) logging\n"
1500 "Logging level\n")
1501{
1502 return CMD_SUCCESS;
1503}
1504
hasso95e735b2004-08-26 13:08:30 +00001505DEFUNSH (VTYSH_ALL,
1506 vtysh_log_syslog,
1507 vtysh_log_syslog_cmd,
1508 "log syslog",
1509 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001510 "Set syslog logging level\n")
1511{
1512 return CMD_SUCCESS;
1513}
1514
1515DEFUNSH (VTYSH_ALL,
1516 vtysh_log_syslog_level,
1517 vtysh_log_syslog_level_cmd,
1518 "log syslog "LOG_LEVELS,
1519 "Logging control\n"
1520 "Set syslog logging level\n"
1521 LOG_LEVEL_DESC)
hasso95e735b2004-08-26 13:08:30 +00001522{
1523 return CMD_SUCCESS;
1524}
1525
1526DEFUNSH (VTYSH_ALL,
1527 no_vtysh_log_syslog,
1528 no_vtysh_log_syslog_cmd,
ajs274a4a42004-12-07 15:39:31 +00001529 "no log syslog [LEVEL]",
hasso95e735b2004-08-26 13:08:30 +00001530 NO_STR
1531 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001532 "Cancel logging to syslog\n"
1533 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001534{
1535 return CMD_SUCCESS;
1536}
1537
1538DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001539 vtysh_log_facility,
1540 vtysh_log_facility_cmd,
1541 "log facility "LOG_FACILITIES,
hasso95e735b2004-08-26 13:08:30 +00001542 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001543 "Facility parameter for syslog messages\n"
1544 LOG_FACILITY_DESC)
1545
hasso95e735b2004-08-26 13:08:30 +00001546{
1547 return CMD_SUCCESS;
1548}
1549
1550DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001551 no_vtysh_log_facility,
1552 no_vtysh_log_facility_cmd,
1553 "no log facility [FACILITY]",
hasso95e735b2004-08-26 13:08:30 +00001554 NO_STR
1555 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001556 "Reset syslog facility to default (daemon)\n"
1557 "Syslog facility\n")
1558
1559{
1560 return CMD_SUCCESS;
1561}
1562
1563DEFUNSH_DEPRECATED (VTYSH_ALL,
1564 vtysh_log_trap,
1565 vtysh_log_trap_cmd,
1566 "log trap "LOG_LEVELS,
1567 "Logging control\n"
1568 "(Deprecated) Set logging level and default for all destinations\n"
1569 LOG_LEVEL_DESC)
1570
1571{
1572 return CMD_SUCCESS;
1573}
1574
1575DEFUNSH_DEPRECATED (VTYSH_ALL,
1576 no_vtysh_log_trap,
1577 no_vtysh_log_trap_cmd,
1578 "no log trap [LEVEL]",
1579 NO_STR
1580 "Logging control\n"
1581 "Permit all logging information\n"
1582 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001583{
1584 return CMD_SUCCESS;
1585}
1586
1587DEFUNSH (VTYSH_ALL,
1588 vtysh_log_record_priority,
1589 vtysh_log_record_priority_cmd,
1590 "log record-priority",
1591 "Logging control\n"
1592 "Log the priority of the message within the message\n")
1593{
1594 return CMD_SUCCESS;
1595}
1596
1597DEFUNSH (VTYSH_ALL,
1598 no_vtysh_log_record_priority,
1599 no_vtysh_log_record_priority_cmd,
1600 "no log record-priority",
1601 NO_STR
1602 "Logging control\n"
1603 "Do not log the priority of the message within the message\n")
1604{
1605 return CMD_SUCCESS;
1606}
1607
hassoe7168df2004-10-03 20:11:32 +00001608DEFUNSH (VTYSH_ALL,
Andrew J. Schorrc749b722007-04-29 03:53:31 +00001609 vtysh_log_timestamp_precision,
1610 vtysh_log_timestamp_precision_cmd,
1611 "log timestamp precision <0-6>",
1612 "Logging control\n"
1613 "Timestamp configuration\n"
1614 "Set the timestamp precision\n"
1615 "Number of subsecond digits\n")
1616{
1617 return CMD_SUCCESS;
1618}
1619
1620DEFUNSH (VTYSH_ALL,
1621 no_vtysh_log_timestamp_precision,
1622 no_vtysh_log_timestamp_precision_cmd,
1623 "no log timestamp precision",
1624 NO_STR
1625 "Logging control\n"
1626 "Timestamp configuration\n"
1627 "Reset the timestamp precision to the default value of 0\n")
1628{
1629 return CMD_SUCCESS;
1630}
1631
1632DEFUNSH (VTYSH_ALL,
hassoe7168df2004-10-03 20:11:32 +00001633 vtysh_service_password_encrypt,
1634 vtysh_service_password_encrypt_cmd,
1635 "service password-encryption",
1636 "Set up miscellaneous service\n"
1637 "Enable encrypted passwords\n")
1638{
1639 return CMD_SUCCESS;
1640}
1641
1642DEFUNSH (VTYSH_ALL,
1643 no_vtysh_service_password_encrypt,
1644 no_vtysh_service_password_encrypt_cmd,
1645 "no service password-encryption",
1646 NO_STR
1647 "Set up miscellaneous service\n"
1648 "Enable encrypted passwords\n")
1649{
1650 return CMD_SUCCESS;
1651}
1652
1653DEFUNSH (VTYSH_ALL,
1654 vtysh_config_password,
1655 vtysh_password_cmd,
1656 "password (8|) WORD",
1657 "Assign the terminal connection password\n"
1658 "Specifies a HIDDEN password will follow\n"
1659 "dummy string \n"
1660 "The HIDDEN line password string\n")
1661{
1662 return CMD_SUCCESS;
1663}
1664
1665DEFUNSH (VTYSH_ALL,
1666 vtysh_password_text,
1667 vtysh_password_text_cmd,
1668 "password LINE",
1669 "Assign the terminal connection password\n"
1670 "The UNENCRYPTED (cleartext) line password\n")
1671{
1672 return CMD_SUCCESS;
1673}
1674
1675DEFUNSH (VTYSH_ALL,
1676 vtysh_config_enable_password,
1677 vtysh_enable_password_cmd,
1678 "enable password (8|) WORD",
1679 "Modify enable password parameters\n"
1680 "Assign the privileged level password\n"
1681 "Specifies a HIDDEN password will follow\n"
1682 "dummy string \n"
1683 "The HIDDEN 'enable' password string\n")
1684{
1685 return CMD_SUCCESS;
1686}
1687
1688DEFUNSH (VTYSH_ALL,
1689 vtysh_enable_password_text,
1690 vtysh_enable_password_text_cmd,
1691 "enable password LINE",
1692 "Modify enable password parameters\n"
1693 "Assign the privileged level password\n"
1694 "The UNENCRYPTED (cleartext) 'enable' password\n")
1695{
1696 return CMD_SUCCESS;
1697}
1698
1699DEFUNSH (VTYSH_ALL,
1700 no_vtysh_config_enable_password,
1701 no_vtysh_enable_password_cmd,
1702 "no enable password",
1703 NO_STR
1704 "Modify enable password parameters\n"
1705 "Assign the privileged level password\n")
1706{
1707 return CMD_SUCCESS;
1708}
1709
paul718e3742002-12-13 20:15:29 +00001710DEFUN (vtysh_write_terminal,
1711 vtysh_write_terminal_cmd,
1712 "write terminal",
1713 "Write running configuration to memory, network, or terminal\n"
1714 "Write to terminal\n")
1715{
ajsb1aa1472005-01-28 21:11:46 +00001716 u_int i;
paul718e3742002-12-13 20:15:29 +00001717 char line[] = "write terminal\n";
1718 FILE *fp = NULL;
1719
1720 if (vtysh_pager_name)
1721 {
paul4fc01e62002-12-13 20:49:00 +00001722 fp = popen (vtysh_pager_name, "w");
paul718e3742002-12-13 20:15:29 +00001723 if (fp == NULL)
1724 {
1725 perror ("popen");
1726 exit (1);
1727 }
1728 }
1729 else
1730 fp = stdout;
1731
1732 vty_out (vty, "Building configuration...%s", VTY_NEWLINE);
1733 vty_out (vty, "%sCurrent configuration:%s", VTY_NEWLINE,
1734 VTY_NEWLINE);
hassoe7168df2004-10-03 20:11:32 +00001735 vty_out (vty, "!%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001736
Balaji.G837d16c2012-09-26 14:09:10 +05301737 for (i = 0; i < array_size(vtysh_client); i++)
David Lamparter6769f432015-03-04 07:18:24 +01001738 vtysh_client_config (&vtysh_client[i], line);
paul718e3742002-12-13 20:15:29 +00001739
hassoe7168df2004-10-03 20:11:32 +00001740 /* Integrate vtysh specific configuration. */
1741 vtysh_config_write ();
1742
paul718e3742002-12-13 20:15:29 +00001743 vtysh_config_dump (fp);
1744
1745 if (vtysh_pager_name && fp)
1746 {
1747 fflush (fp);
1748 if (pclose (fp) == -1)
1749 {
1750 perror ("pclose");
1751 exit (1);
1752 }
1753 fp = NULL;
1754 }
1755
Chris Caputo6e79f8b2009-06-23 05:55:57 +00001756 vty_out (vty, "end%s", VTY_NEWLINE);
1757
paul718e3742002-12-13 20:15:29 +00001758 return CMD_SUCCESS;
1759}
1760
Donald Sharp9fb73e82015-09-22 11:13:12 -04001761DEFUN (vtysh_write_terminal_daemon,
1762 vtysh_write_terminal_daemon_cmd,
1763 "write terminal (zebra|ripd|ripngd|ospfd|ospf6d|bgpd|isisd|babeld)",
1764 "Write running configuration to memory, network, or terminal\n"
1765 "Write to terminal\n"
1766 "For the zebra daemon\n"
1767 "For the rip daemon\n"
1768 "For the ripng daemon\n"
1769 "For the ospf daemon\n"
1770 "For the ospfv6 daemon\n"
1771 "For the bgp daemon\n"
1772 "For the isis daemon\n"
1773 "For the babel daemon\n")
1774{
1775 unsigned int i;
1776 int ret = CMD_SUCCESS;
1777
1778 for (i = 0; i < array_size(vtysh_client); i++)
1779 {
1780 if (strcmp(vtysh_client[i].name, argv[0]) == 0)
1781 break;
1782 }
1783
1784 ret = vtysh_client_execute(&vtysh_client[i], "show running-config\n", stdout);
1785
1786 return ret;
1787}
1788
hassoe7168df2004-10-03 20:11:32 +00001789DEFUN (vtysh_integrated_config,
1790 vtysh_integrated_config_cmd,
1791 "service integrated-vtysh-config",
1792 "Set up miscellaneous service\n"
1793 "Write configuration into integrated file\n")
paul4fc01e62002-12-13 20:49:00 +00001794{
hassoe7168df2004-10-03 20:11:32 +00001795 vtysh_writeconfig_integrated = 1;
1796 return CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001797}
1798
hassoe7168df2004-10-03 20:11:32 +00001799DEFUN (no_vtysh_integrated_config,
1800 no_vtysh_integrated_config_cmd,
1801 "no service integrated-vtysh-config",
1802 NO_STR
1803 "Set up miscellaneous service\n"
1804 "Write configuration into integrated file\n")
paul4fc01e62002-12-13 20:49:00 +00001805{
hassoe7168df2004-10-03 20:11:32 +00001806 vtysh_writeconfig_integrated = 0;
1807 return CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001808}
1809
ajs274a4a42004-12-07 15:39:31 +00001810static int
1811write_config_integrated(void)
paul718e3742002-12-13 20:15:29 +00001812{
ajsb1aa1472005-01-28 21:11:46 +00001813 u_int i;
paul718e3742002-12-13 20:15:29 +00001814 char line[] = "write terminal\n";
1815 FILE *fp;
1816 char *integrate_sav = NULL;
1817
hasso95e735b2004-08-26 13:08:30 +00001818 integrate_sav = malloc (strlen (integrate_default) +
1819 strlen (CONF_BACKUP_EXT) + 1);
paul718e3742002-12-13 20:15:29 +00001820 strcpy (integrate_sav, integrate_default);
1821 strcat (integrate_sav, CONF_BACKUP_EXT);
1822
paul4fc01e62002-12-13 20:49:00 +00001823 fprintf (stdout,"Building Configuration...\n");
paul718e3742002-12-13 20:15:29 +00001824
hasso95e735b2004-08-26 13:08:30 +00001825 /* Move current configuration file to backup config file. */
paul718e3742002-12-13 20:15:29 +00001826 unlink (integrate_sav);
1827 rename (integrate_default, integrate_sav);
hasso95e735b2004-08-26 13:08:30 +00001828 free (integrate_sav);
paul4fc01e62002-12-13 20:49:00 +00001829
paul718e3742002-12-13 20:15:29 +00001830 fp = fopen (integrate_default, "w");
1831 if (fp == NULL)
1832 {
hasso95e735b2004-08-26 13:08:30 +00001833 fprintf (stdout,"%% Can't open configuration file %s.\n",
1834 integrate_default);
paul718e3742002-12-13 20:15:29 +00001835 return CMD_SUCCESS;
1836 }
paul718e3742002-12-13 20:15:29 +00001837
Balaji.G837d16c2012-09-26 14:09:10 +05301838 for (i = 0; i < array_size(vtysh_client); i++)
David Lamparter6769f432015-03-04 07:18:24 +01001839 vtysh_client_config (&vtysh_client[i], line);
paul718e3742002-12-13 20:15:29 +00001840
1841 vtysh_config_dump (fp);
1842
1843 fclose (fp);
1844
gdtaa593d52003-12-22 20:15:53 +00001845 if (chmod (integrate_default, CONFIGFILE_MASK) != 0)
1846 {
1847 fprintf (stdout,"%% Can't chmod configuration file %s: %s (%d)\n",
ajs6099b3b2004-11-20 02:06:59 +00001848 integrate_default, safe_strerror(errno), errno);
gdtaa593d52003-12-22 20:15:53 +00001849 return CMD_WARNING;
1850 }
1851
paul4fc01e62002-12-13 20:49:00 +00001852 fprintf(stdout,"Integrated configuration saved to %s\n",integrate_default);
1853
1854 fprintf (stdout,"[OK]\n");
1855
paul718e3742002-12-13 20:15:29 +00001856 return CMD_SUCCESS;
1857}
1858
paul4fc01e62002-12-13 20:49:00 +00001859DEFUN (vtysh_write_memory,
1860 vtysh_write_memory_cmd,
1861 "write memory",
1862 "Write running configuration to memory, network, or terminal\n"
1863 "Write configuration to the file (same as write file)\n")
1864{
pauldfc0d9b2003-04-18 23:55:29 +00001865 int ret = CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001866 char line[] = "write memory\n";
ajsb1aa1472005-01-28 21:11:46 +00001867 u_int i;
paul4fc01e62002-12-13 20:49:00 +00001868
hassoe7168df2004-10-03 20:11:32 +00001869 /* If integrated Quagga.conf explicitely set. */
1870 if (vtysh_writeconfig_integrated)
1871 return write_config_integrated();
paul4fc01e62002-12-13 20:49:00 +00001872
1873 fprintf (stdout,"Building Configuration...\n");
1874
Balaji.G837d16c2012-09-26 14:09:10 +05301875 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00001876 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
hassoe7168df2004-10-03 20:11:32 +00001877
paul4fc01e62002-12-13 20:49:00 +00001878 fprintf (stdout,"[OK]\n");
1879
pauldfc0d9b2003-04-18 23:55:29 +00001880 return ret;
paul4fc01e62002-12-13 20:49:00 +00001881}
1882
paul718e3742002-12-13 20:15:29 +00001883ALIAS (vtysh_write_memory,
1884 vtysh_copy_runningconfig_startupconfig_cmd,
1885 "copy running-config startup-config",
1886 "Copy from one file to another\n"
1887 "Copy from current system configuration\n"
1888 "Copy to startup configuration\n")
1889
1890ALIAS (vtysh_write_memory,
1891 vtysh_write_file_cmd,
1892 "write file",
1893 "Write running configuration to memory, network, or terminal\n"
1894 "Write configuration to the file (same as write memory)\n")
1895
hasso4a6e2252003-05-25 11:51:29 +00001896ALIAS (vtysh_write_memory,
1897 vtysh_write_cmd,
1898 "write",
1899 "Write running configuration to memory, network, or terminal\n")
1900
paul718e3742002-12-13 20:15:29 +00001901ALIAS (vtysh_write_terminal,
1902 vtysh_show_running_config_cmd,
1903 "show running-config",
1904 SHOW_STR
1905 "Current operating configuration\n")
hassob094d262004-08-25 12:22:00 +00001906
Donald Sharp9fb73e82015-09-22 11:13:12 -04001907ALIAS (vtysh_write_terminal_daemon,
1908 vtysh_show_running_config_daemon_cmd,
1909 "show running-config (zebra|ripd|ripngd|ospfd|ospf6d|bgpd|isisd|babeld)",
1910 SHOW_STR
1911 "Current operating configuration\n"
1912 "For the zebra daemon\n"
1913 "For the rip daemon\n"
1914 "For the ripng daemon\n"
1915 "For the ospf daemon\n"
1916 "For the ospfv6 daemon\n"
1917 "For the bgp daemon\n"
1918 "For the isis daemon\n"
1919 "For the babel daemon\n")
1920
hasso34553cc2004-08-27 13:56:39 +00001921DEFUN (vtysh_terminal_length,
1922 vtysh_terminal_length_cmd,
1923 "terminal length <0-512>",
1924 "Set terminal line parameters\n"
1925 "Set number of lines on a screen\n"
1926 "Number of lines on screen (0 for no pausing)\n")
1927{
1928 int lines;
1929 char *endptr = NULL;
1930 char default_pager[10];
1931
1932 lines = strtol (argv[0], &endptr, 10);
1933 if (lines < 0 || lines > 512 || *endptr != '\0')
1934 {
1935 vty_out (vty, "length is malformed%s", VTY_NEWLINE);
1936 return CMD_WARNING;
1937 }
1938
1939 if (vtysh_pager_name)
1940 {
1941 free (vtysh_pager_name);
1942 vtysh_pager_name = NULL;
1943 }
1944
1945 if (lines != 0)
1946 {
1947 snprintf(default_pager, 10, "more -%i", lines);
1948 vtysh_pager_name = strdup (default_pager);
1949 }
1950
1951 return CMD_SUCCESS;
1952}
1953
1954DEFUN (vtysh_terminal_no_length,
1955 vtysh_terminal_no_length_cmd,
1956 "terminal no length",
1957 "Set terminal line parameters\n"
1958 NO_STR
1959 "Set number of lines on a screen\n")
1960{
1961 if (vtysh_pager_name)
1962 {
1963 free (vtysh_pager_name);
1964 vtysh_pager_name = NULL;
1965 }
1966
1967 vtysh_pager_init();
1968 return CMD_SUCCESS;
1969}
1970
hassof2799e62004-10-28 17:43:11 +00001971DEFUN (vtysh_show_daemons,
1972 vtysh_show_daemons_cmd,
1973 "show daemons",
hassoe7168df2004-10-03 20:11:32 +00001974 SHOW_STR
1975 "Show list of running daemons\n")
1976{
ajsb1aa1472005-01-28 21:11:46 +00001977 u_int i;
1978
Balaji.G837d16c2012-09-26 14:09:10 +05301979 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00001980 if ( vtysh_client[i].fd >= 0 )
1981 vty_out(vty, " %s", vtysh_client[i].name);
hassoe7168df2004-10-03 20:11:32 +00001982 vty_out(vty, "%s", VTY_NEWLINE);
1983
1984 return CMD_SUCCESS;
1985}
1986
paul718e3742002-12-13 20:15:29 +00001987/* Execute command in child process. */
ajs274a4a42004-12-07 15:39:31 +00001988static int
hasso5862ff52004-10-11 13:20:40 +00001989execute_command (const char *command, int argc, const char *arg1,
1990 const char *arg2)
paul718e3742002-12-13 20:15:29 +00001991{
paul718e3742002-12-13 20:15:29 +00001992 pid_t pid;
1993 int status;
1994
1995 /* Call fork(). */
1996 pid = fork ();
1997
1998 if (pid < 0)
1999 {
2000 /* Failure of fork(). */
ajs6099b3b2004-11-20 02:06:59 +00002001 fprintf (stderr, "Can't fork: %s\n", safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +00002002 exit (1);
2003 }
2004 else if (pid == 0)
2005 {
2006 /* This is child process. */
2007 switch (argc)
2008 {
2009 case 0:
David Lamparter6769f432015-03-04 07:18:24 +01002010 execlp (command, command, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00002011 break;
2012 case 1:
David Lamparter6769f432015-03-04 07:18:24 +01002013 execlp (command, command, arg1, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00002014 break;
2015 case 2:
David Lamparter6769f432015-03-04 07:18:24 +01002016 execlp (command, command, arg1, arg2, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00002017 break;
2018 }
2019
2020 /* When execlp suceed, this part is not executed. */
ajs6099b3b2004-11-20 02:06:59 +00002021 fprintf (stderr, "Can't execute %s: %s\n", command, safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +00002022 exit (1);
2023 }
2024 else
2025 {
2026 /* This is parent. */
2027 execute_flag = 1;
David Lamparter6769f432015-03-04 07:18:24 +01002028 wait4 (pid, &status, 0, NULL);
paul718e3742002-12-13 20:15:29 +00002029 execute_flag = 0;
2030 }
2031 return 0;
2032}
2033
2034DEFUN (vtysh_ping,
2035 vtysh_ping_cmd,
2036 "ping WORD",
hasso4eeccf12003-06-25 10:49:55 +00002037 "Send echo messages\n"
paul718e3742002-12-13 20:15:29 +00002038 "Ping destination address or hostname\n")
2039{
2040 execute_command ("ping", 1, argv[0], NULL);
2041 return CMD_SUCCESS;
2042}
2043
hasso4eeccf12003-06-25 10:49:55 +00002044ALIAS (vtysh_ping,
2045 vtysh_ping_ip_cmd,
2046 "ping ip WORD",
2047 "Send echo messages\n"
2048 "IP echo\n"
2049 "Ping destination address or hostname\n")
2050
paul718e3742002-12-13 20:15:29 +00002051DEFUN (vtysh_traceroute,
2052 vtysh_traceroute_cmd,
2053 "traceroute WORD",
2054 "Trace route to destination\n"
2055 "Trace route to destination address or hostname\n")
2056{
2057 execute_command ("traceroute", 1, argv[0], NULL);
2058 return CMD_SUCCESS;
2059}
2060
hasso4eeccf12003-06-25 10:49:55 +00002061ALIAS (vtysh_traceroute,
2062 vtysh_traceroute_ip_cmd,
2063 "traceroute ip WORD",
2064 "Trace route to destination\n"
2065 "IP trace\n"
2066 "Trace route to destination address or hostname\n")
2067
2068#ifdef HAVE_IPV6
2069DEFUN (vtysh_ping6,
2070 vtysh_ping6_cmd,
2071 "ping ipv6 WORD",
2072 "Send echo messages\n"
2073 "IPv6 echo\n"
2074 "Ping destination address or hostname\n")
2075{
2076 execute_command ("ping6", 1, argv[0], NULL);
2077 return CMD_SUCCESS;
2078}
2079
2080DEFUN (vtysh_traceroute6,
2081 vtysh_traceroute6_cmd,
2082 "traceroute ipv6 WORD",
2083 "Trace route to destination\n"
2084 "IPv6 trace\n"
2085 "Trace route to destination address or hostname\n")
2086{
2087 execute_command ("traceroute6", 1, argv[0], NULL);
2088 return CMD_SUCCESS;
2089}
2090#endif
2091
paul718e3742002-12-13 20:15:29 +00002092DEFUN (vtysh_telnet,
2093 vtysh_telnet_cmd,
2094 "telnet WORD",
2095 "Open a telnet connection\n"
2096 "IP address or hostname of a remote system\n")
2097{
2098 execute_command ("telnet", 1, argv[0], NULL);
2099 return CMD_SUCCESS;
2100}
2101
2102DEFUN (vtysh_telnet_port,
2103 vtysh_telnet_port_cmd,
2104 "telnet WORD PORT",
2105 "Open a telnet connection\n"
2106 "IP address or hostname of a remote system\n"
2107 "TCP Port number\n")
2108{
2109 execute_command ("telnet", 2, argv[0], argv[1]);
2110 return CMD_SUCCESS;
2111}
2112
paul5087df52003-01-25 06:56:09 +00002113DEFUN (vtysh_ssh,
2114 vtysh_ssh_cmd,
2115 "ssh WORD",
2116 "Open an ssh connection\n"
2117 "[user@]host\n")
2118{
2119 execute_command ("ssh", 1, argv[0], NULL);
2120 return CMD_SUCCESS;
2121}
2122
paul718e3742002-12-13 20:15:29 +00002123DEFUN (vtysh_start_shell,
2124 vtysh_start_shell_cmd,
2125 "start-shell",
2126 "Start UNIX shell\n")
2127{
2128 execute_command ("sh", 0, NULL, NULL);
2129 return CMD_SUCCESS;
2130}
2131
2132DEFUN (vtysh_start_bash,
2133 vtysh_start_bash_cmd,
2134 "start-shell bash",
2135 "Start UNIX shell\n"
2136 "Start bash\n")
2137{
2138 execute_command ("bash", 0, NULL, NULL);
2139 return CMD_SUCCESS;
2140}
2141
2142DEFUN (vtysh_start_zsh,
2143 vtysh_start_zsh_cmd,
2144 "start-shell zsh",
2145 "Start UNIX shell\n"
2146 "Start Z shell\n")
2147{
2148 execute_command ("zsh", 0, NULL, NULL);
2149 return CMD_SUCCESS;
2150}
hassob094d262004-08-25 12:22:00 +00002151
ajs274a4a42004-12-07 15:39:31 +00002152static void
paul718e3742002-12-13 20:15:29 +00002153vtysh_install_default (enum node_type node)
2154{
2155 install_element (node, &config_list_cmd);
2156}
2157
2158/* Making connection to protocol daemon. */
ajs274a4a42004-12-07 15:39:31 +00002159static int
ajsb1aa1472005-01-28 21:11:46 +00002160vtysh_connect (struct vtysh_client *vclient)
paul718e3742002-12-13 20:15:29 +00002161{
2162 int ret;
2163 int sock, len;
2164 struct sockaddr_un addr;
2165 struct stat s_stat;
paul718e3742002-12-13 20:15:29 +00002166
paul718e3742002-12-13 20:15:29 +00002167 /* Stat socket to see if we have permission to access it. */
ajsb1aa1472005-01-28 21:11:46 +00002168 ret = stat (vclient->path, &s_stat);
paul718e3742002-12-13 20:15:29 +00002169 if (ret < 0 && errno != ENOENT)
2170 {
2171 fprintf (stderr, "vtysh_connect(%s): stat = %s\n",
ajsb1aa1472005-01-28 21:11:46 +00002172 vclient->path, safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002173 exit(1);
2174 }
2175
2176 if (ret >= 0)
2177 {
2178 if (! S_ISSOCK(s_stat.st_mode))
2179 {
2180 fprintf (stderr, "vtysh_connect(%s): Not a socket\n",
ajsb1aa1472005-01-28 21:11:46 +00002181 vclient->path);
paul718e3742002-12-13 20:15:29 +00002182 exit (1);
2183 }
2184
paul718e3742002-12-13 20:15:29 +00002185 }
2186
2187 sock = socket (AF_UNIX, SOCK_STREAM, 0);
2188 if (sock < 0)
2189 {
2190#ifdef DEBUG
ajsb1aa1472005-01-28 21:11:46 +00002191 fprintf(stderr, "vtysh_connect(%s): socket = %s\n", vclient->path,
ajs6099b3b2004-11-20 02:06:59 +00002192 safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002193#endif /* DEBUG */
2194 return -1;
2195 }
2196
2197 memset (&addr, 0, sizeof (struct sockaddr_un));
2198 addr.sun_family = AF_UNIX;
ajsb1aa1472005-01-28 21:11:46 +00002199 strncpy (addr.sun_path, vclient->path, strlen (vclient->path));
Paul Jakma6f0e3f62007-05-10 02:38:51 +00002200#ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
paul718e3742002-12-13 20:15:29 +00002201 len = addr.sun_len = SUN_LEN(&addr);
2202#else
2203 len = sizeof (addr.sun_family) + strlen (addr.sun_path);
Paul Jakma6f0e3f62007-05-10 02:38:51 +00002204#endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
paul718e3742002-12-13 20:15:29 +00002205
2206 ret = connect (sock, (struct sockaddr *) &addr, len);
2207 if (ret < 0)
2208 {
2209#ifdef DEBUG
ajsb1aa1472005-01-28 21:11:46 +00002210 fprintf(stderr, "vtysh_connect(%s): connect = %s\n", vclient->path,
ajs6099b3b2004-11-20 02:06:59 +00002211 safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002212#endif /* DEBUG */
2213 close (sock);
2214 return -1;
2215 }
2216 vclient->fd = sock;
2217
2218 return 0;
2219}
2220
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002221int
2222vtysh_connect_all(const char *daemon_name)
paul718e3742002-12-13 20:15:29 +00002223{
ajsb1aa1472005-01-28 21:11:46 +00002224 u_int i;
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002225 int rc = 0;
2226 int matches = 0;
ajsb1aa1472005-01-28 21:11:46 +00002227
Balaji.G837d16c2012-09-26 14:09:10 +05302228 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00002229 {
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002230 if (!daemon_name || !strcmp(daemon_name, vtysh_client[i].name))
2231 {
2232 matches++;
2233 if (vtysh_connect(&vtysh_client[i]) == 0)
2234 rc++;
2235 /* We need direct access to ripd in vtysh_exit_ripd_only. */
2236 if (vtysh_client[i].flag == VTYSH_RIPD)
2237 ripd_client = &vtysh_client[i];
2238 }
ajsb1aa1472005-01-28 21:11:46 +00002239 }
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002240 if (!matches)
2241 fprintf(stderr, "Error: no daemons match name %s!\n", daemon_name);
2242 return rc;
paul718e3742002-12-13 20:15:29 +00002243}
2244
hasso95e735b2004-08-26 13:08:30 +00002245/* To disable readline's filename completion. */
ajs274a4a42004-12-07 15:39:31 +00002246static char *
pauldfc0d9b2003-04-18 23:55:29 +00002247vtysh_completion_entry_function (const char *ignore, int invoking_key)
paul718e3742002-12-13 20:15:29 +00002248{
pauldfc0d9b2003-04-18 23:55:29 +00002249 return NULL;
paul718e3742002-12-13 20:15:29 +00002250}
2251
2252void
ajsb1aa1472005-01-28 21:11:46 +00002253vtysh_readline_init (void)
paul718e3742002-12-13 20:15:29 +00002254{
2255 /* readline related settings. */
Sébastien Luttringer66d2ead2014-05-27 19:55:11 +02002256 rl_bind_key ('?', (rl_command_func_t *) vtysh_rl_describe);
paul68980082003-03-25 05:07:42 +00002257 rl_completion_entry_function = vtysh_completion_entry_function;
Sébastien Luttringer66d2ead2014-05-27 19:55:11 +02002258 rl_attempted_completion_function = (rl_completion_func_t *)new_completion;
paul718e3742002-12-13 20:15:29 +00002259}
2260
2261char *
ajsb1aa1472005-01-28 21:11:46 +00002262vtysh_prompt (void)
paul718e3742002-12-13 20:15:29 +00002263{
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002264 static struct utsname names;
paul718e3742002-12-13 20:15:29 +00002265 static char buf[100];
2266 const char*hostname;
2267 extern struct host host;
2268
2269 hostname = host.name;
2270
2271 if (!hostname)
2272 {
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002273 if (!names.nodename[0])
2274 uname (&names);
paul718e3742002-12-13 20:15:29 +00002275 hostname = names.nodename;
2276 }
2277
2278 snprintf (buf, sizeof buf, cmd_prompt (vty->node), hostname);
2279
2280 return buf;
2281}
2282
2283void
ajsb1aa1472005-01-28 21:11:46 +00002284vtysh_init_vty (void)
paul718e3742002-12-13 20:15:29 +00002285{
2286 /* Make vty structure. */
2287 vty = vty_new ();
2288 vty->type = VTY_SHELL;
2289 vty->node = VIEW_NODE;
2290
2291 /* Initialize commands. */
2292 cmd_init (0);
2293
2294 /* Install nodes. */
2295 install_node (&bgp_node, NULL);
2296 install_node (&rip_node, NULL);
2297 install_node (&interface_node, NULL);
2298 install_node (&rmap_node, NULL);
2299 install_node (&zebra_node, NULL);
2300 install_node (&bgp_vpnv4_node, NULL);
2301 install_node (&bgp_ipv4_node, NULL);
2302 install_node (&bgp_ipv4m_node, NULL);
2303/* #ifdef HAVE_IPV6 */
2304 install_node (&bgp_ipv6_node, NULL);
paul57b5b7e2005-08-22 22:44:29 +00002305 install_node (&bgp_ipv6m_node, NULL);
paul718e3742002-12-13 20:15:29 +00002306/* #endif */
2307 install_node (&ospf_node, NULL);
2308/* #ifdef HAVE_IPV6 */
2309 install_node (&ripng_node, NULL);
2310 install_node (&ospf6_node, NULL);
2311/* #endif */
David Lamparteree53c8b2015-05-23 05:45:59 +02002312 install_node (&babel_node, NULL);
paul718e3742002-12-13 20:15:29 +00002313 install_node (&keychain_node, NULL);
2314 install_node (&keychain_key_node, NULL);
hassoc25e4582003-12-23 10:39:08 +00002315 install_node (&isis_node, NULL);
hassoe7168df2004-10-03 20:11:32 +00002316 install_node (&vty_node, NULL);
paul718e3742002-12-13 20:15:29 +00002317
2318 vtysh_install_default (VIEW_NODE);
2319 vtysh_install_default (ENABLE_NODE);
2320 vtysh_install_default (CONFIG_NODE);
2321 vtysh_install_default (BGP_NODE);
2322 vtysh_install_default (RIP_NODE);
2323 vtysh_install_default (INTERFACE_NODE);
2324 vtysh_install_default (RMAP_NODE);
2325 vtysh_install_default (ZEBRA_NODE);
2326 vtysh_install_default (BGP_VPNV4_NODE);
2327 vtysh_install_default (BGP_IPV4_NODE);
2328 vtysh_install_default (BGP_IPV4M_NODE);
2329 vtysh_install_default (BGP_IPV6_NODE);
paul57b5b7e2005-08-22 22:44:29 +00002330 vtysh_install_default (BGP_IPV6M_NODE);
paul718e3742002-12-13 20:15:29 +00002331 vtysh_install_default (OSPF_NODE);
2332 vtysh_install_default (RIPNG_NODE);
2333 vtysh_install_default (OSPF6_NODE);
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +01002334 vtysh_install_default (BABEL_NODE);
hassoc25e4582003-12-23 10:39:08 +00002335 vtysh_install_default (ISIS_NODE);
paul718e3742002-12-13 20:15:29 +00002336 vtysh_install_default (KEYCHAIN_NODE);
2337 vtysh_install_default (KEYCHAIN_KEY_NODE);
hassoe7168df2004-10-03 20:11:32 +00002338 vtysh_install_default (VTY_NODE);
paul718e3742002-12-13 20:15:29 +00002339
2340 install_element (VIEW_NODE, &vtysh_enable_cmd);
2341 install_element (ENABLE_NODE, &vtysh_config_terminal_cmd);
2342 install_element (ENABLE_NODE, &vtysh_disable_cmd);
2343
2344 /* "exit" command. */
2345 install_element (VIEW_NODE, &vtysh_exit_all_cmd);
2346 install_element (VIEW_NODE, &vtysh_quit_all_cmd);
2347 install_element (CONFIG_NODE, &vtysh_exit_all_cmd);
2348 /* install_element (CONFIG_NODE, &vtysh_quit_all_cmd); */
2349 install_element (ENABLE_NODE, &vtysh_exit_all_cmd);
2350 install_element (ENABLE_NODE, &vtysh_quit_all_cmd);
2351 install_element (RIP_NODE, &vtysh_exit_ripd_cmd);
2352 install_element (RIP_NODE, &vtysh_quit_ripd_cmd);
paul68980082003-03-25 05:07:42 +00002353 install_element (RIPNG_NODE, &vtysh_exit_ripngd_cmd);
2354 install_element (RIPNG_NODE, &vtysh_quit_ripngd_cmd);
paul718e3742002-12-13 20:15:29 +00002355 install_element (OSPF_NODE, &vtysh_exit_ospfd_cmd);
2356 install_element (OSPF_NODE, &vtysh_quit_ospfd_cmd);
paul68980082003-03-25 05:07:42 +00002357 install_element (OSPF6_NODE, &vtysh_exit_ospf6d_cmd);
2358 install_element (OSPF6_NODE, &vtysh_quit_ospf6d_cmd);
paul718e3742002-12-13 20:15:29 +00002359 install_element (BGP_NODE, &vtysh_exit_bgpd_cmd);
2360 install_element (BGP_NODE, &vtysh_quit_bgpd_cmd);
2361 install_element (BGP_VPNV4_NODE, &vtysh_exit_bgpd_cmd);
2362 install_element (BGP_VPNV4_NODE, &vtysh_quit_bgpd_cmd);
2363 install_element (BGP_IPV4_NODE, &vtysh_exit_bgpd_cmd);
2364 install_element (BGP_IPV4_NODE, &vtysh_quit_bgpd_cmd);
2365 install_element (BGP_IPV4M_NODE, &vtysh_exit_bgpd_cmd);
2366 install_element (BGP_IPV4M_NODE, &vtysh_quit_bgpd_cmd);
2367 install_element (BGP_IPV6_NODE, &vtysh_exit_bgpd_cmd);
2368 install_element (BGP_IPV6_NODE, &vtysh_quit_bgpd_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002369 install_element (BGP_IPV6M_NODE, &vtysh_exit_bgpd_cmd);
2370 install_element (BGP_IPV6M_NODE, &vtysh_quit_bgpd_cmd);
hassoc25e4582003-12-23 10:39:08 +00002371 install_element (ISIS_NODE, &vtysh_exit_isisd_cmd);
2372 install_element (ISIS_NODE, &vtysh_quit_isisd_cmd);
paul718e3742002-12-13 20:15:29 +00002373 install_element (KEYCHAIN_NODE, &vtysh_exit_ripd_cmd);
2374 install_element (KEYCHAIN_NODE, &vtysh_quit_ripd_cmd);
2375 install_element (KEYCHAIN_KEY_NODE, &vtysh_exit_ripd_cmd);
2376 install_element (KEYCHAIN_KEY_NODE, &vtysh_quit_ripd_cmd);
2377 install_element (RMAP_NODE, &vtysh_exit_rmap_cmd);
2378 install_element (RMAP_NODE, &vtysh_quit_rmap_cmd);
hassoe7168df2004-10-03 20:11:32 +00002379 install_element (VTY_NODE, &vtysh_exit_line_vty_cmd);
2380 install_element (VTY_NODE, &vtysh_quit_line_vty_cmd);
paul718e3742002-12-13 20:15:29 +00002381
2382 /* "end" command. */
2383 install_element (CONFIG_NODE, &vtysh_end_all_cmd);
2384 install_element (ENABLE_NODE, &vtysh_end_all_cmd);
2385 install_element (RIP_NODE, &vtysh_end_all_cmd);
2386 install_element (RIPNG_NODE, &vtysh_end_all_cmd);
2387 install_element (OSPF_NODE, &vtysh_end_all_cmd);
2388 install_element (OSPF6_NODE, &vtysh_end_all_cmd);
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +01002389 install_element (BABEL_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002390 install_element (BGP_NODE, &vtysh_end_all_cmd);
2391 install_element (BGP_IPV4_NODE, &vtysh_end_all_cmd);
2392 install_element (BGP_IPV4M_NODE, &vtysh_end_all_cmd);
2393 install_element (BGP_VPNV4_NODE, &vtysh_end_all_cmd);
2394 install_element (BGP_IPV6_NODE, &vtysh_end_all_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002395 install_element (BGP_IPV6M_NODE, &vtysh_end_all_cmd);
hassoc25e4582003-12-23 10:39:08 +00002396 install_element (ISIS_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002397 install_element (KEYCHAIN_NODE, &vtysh_end_all_cmd);
2398 install_element (KEYCHAIN_KEY_NODE, &vtysh_end_all_cmd);
2399 install_element (RMAP_NODE, &vtysh_end_all_cmd);
hassoe7168df2004-10-03 20:11:32 +00002400 install_element (VTY_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002401
paul338a9912003-03-01 15:44:10 +00002402 install_element (INTERFACE_NODE, &interface_desc_cmd);
paul464dc8d2003-03-28 02:25:45 +00002403 install_element (INTERFACE_NODE, &no_interface_desc_cmd);
paul718e3742002-12-13 20:15:29 +00002404 install_element (INTERFACE_NODE, &vtysh_end_all_cmd);
2405 install_element (INTERFACE_NODE, &vtysh_exit_interface_cmd);
2406 install_element (INTERFACE_NODE, &vtysh_quit_interface_cmd);
2407 install_element (CONFIG_NODE, &router_rip_cmd);
2408#ifdef HAVE_IPV6
2409 install_element (CONFIG_NODE, &router_ripng_cmd);
2410#endif
2411 install_element (CONFIG_NODE, &router_ospf_cmd);
2412#ifdef HAVE_IPV6
2413 install_element (CONFIG_NODE, &router_ospf6_cmd);
2414#endif
hassoc25e4582003-12-23 10:39:08 +00002415 install_element (CONFIG_NODE, &router_isis_cmd);
paul718e3742002-12-13 20:15:29 +00002416 install_element (CONFIG_NODE, &router_bgp_cmd);
Paul Jakma10895fd2008-07-03 19:34:48 +00002417 install_element (CONFIG_NODE, &router_bgp_view_cmd);
paul718e3742002-12-13 20:15:29 +00002418 install_element (BGP_NODE, &address_family_vpnv4_cmd);
2419 install_element (BGP_NODE, &address_family_vpnv4_unicast_cmd);
2420 install_element (BGP_NODE, &address_family_ipv4_unicast_cmd);
2421 install_element (BGP_NODE, &address_family_ipv4_multicast_cmd);
2422#ifdef HAVE_IPV6
2423 install_element (BGP_NODE, &address_family_ipv6_cmd);
2424 install_element (BGP_NODE, &address_family_ipv6_unicast_cmd);
2425#endif
2426 install_element (BGP_VPNV4_NODE, &exit_address_family_cmd);
2427 install_element (BGP_IPV4_NODE, &exit_address_family_cmd);
2428 install_element (BGP_IPV4M_NODE, &exit_address_family_cmd);
2429 install_element (BGP_IPV6_NODE, &exit_address_family_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002430 install_element (BGP_IPV6M_NODE, &exit_address_family_cmd);
paul718e3742002-12-13 20:15:29 +00002431 install_element (CONFIG_NODE, &key_chain_cmd);
2432 install_element (CONFIG_NODE, &route_map_cmd);
hassoe7168df2004-10-03 20:11:32 +00002433 install_element (CONFIG_NODE, &vtysh_line_vty_cmd);
paul718e3742002-12-13 20:15:29 +00002434 install_element (KEYCHAIN_NODE, &key_cmd);
2435 install_element (KEYCHAIN_NODE, &key_chain_cmd);
2436 install_element (KEYCHAIN_KEY_NODE, &key_chain_cmd);
2437 install_element (CONFIG_NODE, &vtysh_interface_cmd);
paul32d24632003-05-23 09:25:20 +00002438 install_element (CONFIG_NODE, &vtysh_no_interface_cmd);
Feng Lu471ea392015-05-22 11:40:00 +02002439 install_element (CONFIG_NODE, &vtysh_interface_vrf_cmd);
2440 install_element (CONFIG_NODE, &vtysh_no_interface_vrf_cmd);
paul718e3742002-12-13 20:15:29 +00002441 install_element (ENABLE_NODE, &vtysh_show_running_config_cmd);
Donald Sharp9fb73e82015-09-22 11:13:12 -04002442 install_element (ENABLE_NODE, &vtysh_show_running_config_daemon_cmd);
paul718e3742002-12-13 20:15:29 +00002443 install_element (ENABLE_NODE, &vtysh_copy_runningconfig_startupconfig_cmd);
2444 install_element (ENABLE_NODE, &vtysh_write_file_cmd);
hasso4a6e2252003-05-25 11:51:29 +00002445 install_element (ENABLE_NODE, &vtysh_write_cmd);
paul718e3742002-12-13 20:15:29 +00002446
hasso95e735b2004-08-26 13:08:30 +00002447 /* "write terminal" command. */
paul718e3742002-12-13 20:15:29 +00002448 install_element (ENABLE_NODE, &vtysh_write_terminal_cmd);
Donald Sharp9fb73e82015-09-22 11:13:12 -04002449 install_element (ENABLE_NODE, &vtysh_write_terminal_daemon_cmd);
hassoe7168df2004-10-03 20:11:32 +00002450
2451 install_element (CONFIG_NODE, &vtysh_integrated_config_cmd);
2452 install_element (CONFIG_NODE, &no_vtysh_integrated_config_cmd);
paul718e3742002-12-13 20:15:29 +00002453
hasso95e735b2004-08-26 13:08:30 +00002454 /* "write memory" command. */
paul718e3742002-12-13 20:15:29 +00002455 install_element (ENABLE_NODE, &vtysh_write_memory_cmd);
paul718e3742002-12-13 20:15:29 +00002456
hasso34553cc2004-08-27 13:56:39 +00002457 install_element (VIEW_NODE, &vtysh_terminal_length_cmd);
2458 install_element (ENABLE_NODE, &vtysh_terminal_length_cmd);
2459 install_element (VIEW_NODE, &vtysh_terminal_no_length_cmd);
2460 install_element (ENABLE_NODE, &vtysh_terminal_no_length_cmd);
hassof2799e62004-10-28 17:43:11 +00002461 install_element (VIEW_NODE, &vtysh_show_daemons_cmd);
2462 install_element (ENABLE_NODE, &vtysh_show_daemons_cmd);
hasso34553cc2004-08-27 13:56:39 +00002463
paul718e3742002-12-13 20:15:29 +00002464 install_element (VIEW_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002465 install_element (VIEW_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00002466 install_element (VIEW_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002467 install_element (VIEW_NODE, &vtysh_traceroute_ip_cmd);
2468#ifdef HAVE_IPV6
2469 install_element (VIEW_NODE, &vtysh_ping6_cmd);
2470 install_element (VIEW_NODE, &vtysh_traceroute6_cmd);
2471#endif
paul718e3742002-12-13 20:15:29 +00002472 install_element (VIEW_NODE, &vtysh_telnet_cmd);
2473 install_element (VIEW_NODE, &vtysh_telnet_port_cmd);
paul5087df52003-01-25 06:56:09 +00002474 install_element (VIEW_NODE, &vtysh_ssh_cmd);
paul718e3742002-12-13 20:15:29 +00002475 install_element (ENABLE_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002476 install_element (ENABLE_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00002477 install_element (ENABLE_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002478 install_element (ENABLE_NODE, &vtysh_traceroute_ip_cmd);
2479#ifdef HAVE_IPV6
2480 install_element (ENABLE_NODE, &vtysh_ping6_cmd);
2481 install_element (ENABLE_NODE, &vtysh_traceroute6_cmd);
2482#endif
paul718e3742002-12-13 20:15:29 +00002483 install_element (ENABLE_NODE, &vtysh_telnet_cmd);
2484 install_element (ENABLE_NODE, &vtysh_telnet_port_cmd);
hasso67e29ab2004-08-26 22:21:31 +00002485 install_element (ENABLE_NODE, &vtysh_ssh_cmd);
paul718e3742002-12-13 20:15:29 +00002486 install_element (ENABLE_NODE, &vtysh_start_shell_cmd);
2487 install_element (ENABLE_NODE, &vtysh_start_bash_cmd);
2488 install_element (ENABLE_NODE, &vtysh_start_zsh_cmd);
Paul Jakmadbf7d132006-05-23 22:10:01 +00002489
Paul Jakma362b4032006-05-28 07:54:45 +00002490 install_element (VIEW_NODE, &vtysh_show_memory_cmd);
2491 install_element (ENABLE_NODE, &vtysh_show_memory_cmd);
2492
Donald Sharp567a6382015-08-19 21:22:17 -04002493 install_element (VIEW_NODE, &vtysh_show_work_queues_cmd);
2494 install_element (ENABLE_NODE, &vtysh_show_work_queues_cmd);
2495
2496 install_element (VIEW_NODE, &vtysh_show_thread_cmd);
2497 install_element (ENABLE_NODE, &vtysh_show_thread_cmd);
2498
Paul Jakmadbf7d132006-05-23 22:10:01 +00002499 /* Logging */
2500 install_element (ENABLE_NODE, &vtysh_show_logging_cmd);
2501 install_element (VIEW_NODE, &vtysh_show_logging_cmd);
paul718e3742002-12-13 20:15:29 +00002502 install_element (CONFIG_NODE, &vtysh_log_stdout_cmd);
ajs274a4a42004-12-07 15:39:31 +00002503 install_element (CONFIG_NODE, &vtysh_log_stdout_level_cmd);
paul718e3742002-12-13 20:15:29 +00002504 install_element (CONFIG_NODE, &no_vtysh_log_stdout_cmd);
2505 install_element (CONFIG_NODE, &vtysh_log_file_cmd);
ajs274a4a42004-12-07 15:39:31 +00002506 install_element (CONFIG_NODE, &vtysh_log_file_level_cmd);
paul718e3742002-12-13 20:15:29 +00002507 install_element (CONFIG_NODE, &no_vtysh_log_file_cmd);
ajs274a4a42004-12-07 15:39:31 +00002508 install_element (CONFIG_NODE, &no_vtysh_log_file_level_cmd);
2509 install_element (CONFIG_NODE, &vtysh_log_monitor_cmd);
2510 install_element (CONFIG_NODE, &vtysh_log_monitor_level_cmd);
2511 install_element (CONFIG_NODE, &no_vtysh_log_monitor_cmd);
paul718e3742002-12-13 20:15:29 +00002512 install_element (CONFIG_NODE, &vtysh_log_syslog_cmd);
ajs274a4a42004-12-07 15:39:31 +00002513 install_element (CONFIG_NODE, &vtysh_log_syslog_level_cmd);
paul718e3742002-12-13 20:15:29 +00002514 install_element (CONFIG_NODE, &no_vtysh_log_syslog_cmd);
2515 install_element (CONFIG_NODE, &vtysh_log_trap_cmd);
2516 install_element (CONFIG_NODE, &no_vtysh_log_trap_cmd);
ajs274a4a42004-12-07 15:39:31 +00002517 install_element (CONFIG_NODE, &vtysh_log_facility_cmd);
2518 install_element (CONFIG_NODE, &no_vtysh_log_facility_cmd);
paul718e3742002-12-13 20:15:29 +00002519 install_element (CONFIG_NODE, &vtysh_log_record_priority_cmd);
2520 install_element (CONFIG_NODE, &no_vtysh_log_record_priority_cmd);
Andrew J. Schorrc749b722007-04-29 03:53:31 +00002521 install_element (CONFIG_NODE, &vtysh_log_timestamp_precision_cmd);
2522 install_element (CONFIG_NODE, &no_vtysh_log_timestamp_precision_cmd);
hassoe7168df2004-10-03 20:11:32 +00002523
2524 install_element (CONFIG_NODE, &vtysh_service_password_encrypt_cmd);
2525 install_element (CONFIG_NODE, &no_vtysh_service_password_encrypt_cmd);
2526
2527 install_element (CONFIG_NODE, &vtysh_password_cmd);
2528 install_element (CONFIG_NODE, &vtysh_password_text_cmd);
2529 install_element (CONFIG_NODE, &vtysh_enable_password_cmd);
2530 install_element (CONFIG_NODE, &vtysh_enable_password_text_cmd);
2531 install_element (CONFIG_NODE, &no_vtysh_enable_password_cmd);
2532
paul718e3742002-12-13 20:15:29 +00002533}