blob: 63b596a580b7d2434dd5224f4858667a3723b4a1 [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 Bergera3fda882016-01-12 13:42:04 -0500284 || saved_node == BGP_ENCAP_NODE || saved_node == BGP_ENCAPV6_NODE
Lou Berger13c378d2016-01-12 13:41:56 -0500285 || saved_node == BGP_IPV4_NODE
paul57b5b7e2005-08-22 22:44:29 +0000286 || saved_node == BGP_IPV6_NODE || saved_node == BGP_IPV4M_NODE
287 || saved_node == BGP_IPV6M_NODE)
hasso13bfca72005-01-23 21:42:25 +0000288 && (tried == 1))
289 {
290 vtysh_execute("exit-address-family");
291 }
292 else if ((saved_node == KEYCHAIN_KEY_NODE) && (tried == 1))
293 {
294 vtysh_execute("exit");
295 }
296 else if (tried)
297 {
298 vtysh_execute ("end");
299 vtysh_execute ("configure terminal");
300 }
301 }
302 /* If command didn't succeed in any node, continue with return value from
303 * first try. */
304 else if (tried)
305 {
306 ret = saved_ret;
307 }
paul718e3742002-12-13 20:15:29 +0000308
309 cmd_free_strvec (vline);
310
Stephen Hemminger2c4d48b2008-07-28 15:04:56 -0700311 cmd_stat = ret;
paul718e3742002-12-13 20:15:29 +0000312 switch (ret)
313 {
314 case CMD_WARNING:
315 if (vty->type == VTY_FILE)
paul4fc01e62002-12-13 20:49:00 +0000316 fprintf (stdout,"Warning...\n");
paul718e3742002-12-13 20:15:29 +0000317 break;
318 case CMD_ERR_AMBIGUOUS:
paul4fc01e62002-12-13 20:49:00 +0000319 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000320 break;
321 case CMD_ERR_NO_MATCH:
paul4fc01e62002-12-13 20:49:00 +0000322 fprintf (stdout,"%% Unknown command.\n");
paul718e3742002-12-13 20:15:29 +0000323 break;
324 case CMD_ERR_INCOMPLETE:
paul4fc01e62002-12-13 20:49:00 +0000325 fprintf (stdout,"%% Command incomplete.\n");
paul718e3742002-12-13 20:15:29 +0000326 break;
327 case CMD_SUCCESS_DAEMON:
328 {
hasso97b7db22004-10-20 19:07:48 +0000329 /* FIXME: Don't open pager for exit commands. popen() causes problems
330 * if exited from vtysh at all. This hack shouldn't cause any problem
331 * but is really ugly. */
332 if (pager && vtysh_pager_name && (strncmp(line, "exit", 4) != 0))
paul718e3742002-12-13 20:15:29 +0000333 {
paul4fc01e62002-12-13 20:49:00 +0000334 fp = popen (vtysh_pager_name, "w");
paul718e3742002-12-13 20:15:29 +0000335 if (fp == NULL)
336 {
paula805cc22003-05-01 14:29:48 +0000337 perror ("popen failed for pager");
338 fp = stdout;
paul718e3742002-12-13 20:15:29 +0000339 }
paula805cc22003-05-01 14:29:48 +0000340 else
341 closepager=1;
paul718e3742002-12-13 20:15:29 +0000342 }
343 else
344 fp = stdout;
345
346 if (! strcmp(cmd->string,"configure terminal"))
347 {
Balaji.G837d16c2012-09-26 14:09:10 +0530348 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +0000349 {
350 cmd_stat = vtysh_client_execute(&vtysh_client[i], line, fp);
351 if (cmd_stat == CMD_WARNING)
352 break;
353 }
354
paul718e3742002-12-13 20:15:29 +0000355 if (cmd_stat)
356 {
hassob094d262004-08-25 12:22:00 +0000357 line = "end";
358 vline = cmd_make_strvec (line);
paul718e3742002-12-13 20:15:29 +0000359
hassob094d262004-08-25 12:22:00 +0000360 if (vline == NULL)
paul718e3742002-12-13 20:15:29 +0000361 {
paula805cc22003-05-01 14:29:48 +0000362 if (pager && vtysh_pager_name && fp && closepager)
paul718e3742002-12-13 20:15:29 +0000363 {
364 if (pclose (fp) == -1)
365 {
paula805cc22003-05-01 14:29:48 +0000366 perror ("pclose failed for pager");
paul718e3742002-12-13 20:15:29 +0000367 }
368 fp = NULL;
369 }
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700370 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000371 }
372
hasso87d683b2005-01-16 23:31:54 +0000373 ret = cmd_execute_command (vline, vty, &cmd, 1);
hassob094d262004-08-25 12:22:00 +0000374 cmd_free_strvec (vline);
375 if (ret != CMD_SUCCESS_DAEMON)
376 break;
paul718e3742002-12-13 20:15:29 +0000377 }
378 else
379 if (cmd->func)
380 {
381 (*cmd->func) (cmd, vty, 0, NULL);
382 break;
hassob094d262004-08-25 12:22:00 +0000383 }
paul718e3742002-12-13 20:15:29 +0000384 }
385
ajsb1aa1472005-01-28 21:11:46 +0000386 cmd_stat = CMD_SUCCESS;
Balaji.G837d16c2012-09-26 14:09:10 +0530387 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +0000388 {
389 if (cmd->daemon & vtysh_client[i].flag)
390 {
391 cmd_stat = vtysh_client_execute(&vtysh_client[i], line, fp);
392 if (cmd_stat != CMD_SUCCESS)
393 break;
394 }
395 }
396 if (cmd_stat != CMD_SUCCESS)
397 break;
398
paul718e3742002-12-13 20:15:29 +0000399 if (cmd->func)
400 (*cmd->func) (cmd, vty, 0, NULL);
401 }
402 }
paula805cc22003-05-01 14:29:48 +0000403 if (pager && vtysh_pager_name && fp && closepager)
paul718e3742002-12-13 20:15:29 +0000404 {
405 if (pclose (fp) == -1)
406 {
paula805cc22003-05-01 14:29:48 +0000407 perror ("pclose failed for pager");
paul718e3742002-12-13 20:15:29 +0000408 }
409 fp = NULL;
410 }
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700411 return cmd_stat;
paul718e3742002-12-13 20:15:29 +0000412}
413
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700414int
hassodda09522004-10-07 21:40:25 +0000415vtysh_execute_no_pager (const char *line)
paul718e3742002-12-13 20:15:29 +0000416{
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700417 return vtysh_execute_func (line, 0);
paul718e3742002-12-13 20:15:29 +0000418}
419
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700420int
hassodda09522004-10-07 21:40:25 +0000421vtysh_execute (const char *line)
paul718e3742002-12-13 20:15:29 +0000422{
Stephen Hemminger57fb9742008-07-28 12:19:04 -0700423 return vtysh_execute_func (line, 1);
paul718e3742002-12-13 20:15:29 +0000424}
425
426/* Configration make from file. */
427int
428vtysh_config_from_file (struct vty *vty, FILE *fp)
429{
430 int ret;
paul718e3742002-12-13 20:15:29 +0000431 struct cmd_element *cmd;
432
433 while (fgets (vty->buf, VTY_BUFSIZ, fp))
434 {
Donald Sharpd8aa4be2015-09-28 20:10:40 -0400435 ret = command_config_read_one_line (vty, &cmd, 1);
paul718e3742002-12-13 20:15:29 +0000436
437 switch (ret)
438 {
439 case CMD_WARNING:
440 if (vty->type == VTY_FILE)
paul4fc01e62002-12-13 20:49:00 +0000441 fprintf (stdout,"Warning...\n");
paul718e3742002-12-13 20:15:29 +0000442 break;
443 case CMD_ERR_AMBIGUOUS:
paul4fc01e62002-12-13 20:49:00 +0000444 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000445 break;
446 case CMD_ERR_NO_MATCH:
paul4fc01e62002-12-13 20:49:00 +0000447 fprintf (stdout,"%% Unknown command: %s", vty->buf);
paul718e3742002-12-13 20:15:29 +0000448 break;
449 case CMD_ERR_INCOMPLETE:
paul4fc01e62002-12-13 20:49:00 +0000450 fprintf (stdout,"%% Command incomplete.\n");
paul718e3742002-12-13 20:15:29 +0000451 break;
452 case CMD_SUCCESS_DAEMON:
453 {
ajsb1aa1472005-01-28 21:11:46 +0000454 u_int i;
455 int cmd_stat = CMD_SUCCESS;
456
Balaji.G837d16c2012-09-26 14:09:10 +0530457 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +0000458 {
paul44316fe2006-01-11 01:38:25 +0000459 if (cmd->daemon & vtysh_client[i].flag)
ajsb1aa1472005-01-28 21:11:46 +0000460 {
461 cmd_stat = vtysh_client_execute (&vtysh_client[i],
462 vty->buf, stdout);
463 if (cmd_stat != CMD_SUCCESS)
464 break;
465 }
466 }
467 if (cmd_stat != CMD_SUCCESS)
468 break;
469
paul718e3742002-12-13 20:15:29 +0000470 if (cmd->func)
471 (*cmd->func) (cmd, vty, 0, NULL);
472 }
473 }
474 }
475 return CMD_SUCCESS;
476}
477
478/* We don't care about the point of the cursor when '?' is typed. */
David Lampartera9eb9062015-03-04 07:07:01 +0100479static int
ajsb1aa1472005-01-28 21:11:46 +0000480vtysh_rl_describe (void)
paul718e3742002-12-13 20:15:29 +0000481{
482 int ret;
hassodda09522004-10-07 21:40:25 +0000483 unsigned int i;
paul718e3742002-12-13 20:15:29 +0000484 vector vline;
485 vector describe;
486 int width;
Christian Frankecd40b322013-09-30 12:27:51 +0000487 struct cmd_token *token;
paul718e3742002-12-13 20:15:29 +0000488
489 vline = cmd_make_strvec (rl_line_buffer);
490
491 /* In case of '> ?'. */
492 if (vline == NULL)
493 {
494 vline = vector_init (1);
David Lampartera91a3ba2015-03-03 09:06:51 +0100495 vector_set (vline, NULL);
paul718e3742002-12-13 20:15:29 +0000496 }
497 else
498 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
David Lampartera91a3ba2015-03-03 09:06:51 +0100499 vector_set (vline, NULL);
paul718e3742002-12-13 20:15:29 +0000500
501 describe = cmd_describe_command (vline, vty, &ret);
502
paul4fc01e62002-12-13 20:49:00 +0000503 fprintf (stdout,"\n");
paul718e3742002-12-13 20:15:29 +0000504
505 /* Ambiguous and no match error. */
506 switch (ret)
507 {
508 case CMD_ERR_AMBIGUOUS:
509 cmd_free_strvec (vline);
paul4fc01e62002-12-13 20:49:00 +0000510 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000511 rl_on_new_line ();
512 return 0;
513 break;
514 case CMD_ERR_NO_MATCH:
515 cmd_free_strvec (vline);
paul4fc01e62002-12-13 20:49:00 +0000516 fprintf (stdout,"%% There is no matched command.\n");
paul718e3742002-12-13 20:15:29 +0000517 rl_on_new_line ();
518 return 0;
519 break;
520 }
521
522 /* Get width of command string. */
523 width = 0;
paul55468c82005-03-14 20:19:01 +0000524 for (i = 0; i < vector_active (describe); i++)
Christian Frankecd40b322013-09-30 12:27:51 +0000525 if ((token = vector_slot (describe, i)) != NULL)
paul718e3742002-12-13 20:15:29 +0000526 {
527 int len;
528
Christian Frankecd40b322013-09-30 12:27:51 +0000529 if (token->cmd[0] == '\0')
paul718e3742002-12-13 20:15:29 +0000530 continue;
531
Christian Frankecd40b322013-09-30 12:27:51 +0000532 len = strlen (token->cmd);
533 if (token->cmd[0] == '.')
paul718e3742002-12-13 20:15:29 +0000534 len--;
535
536 if (width < len)
537 width = len;
538 }
539
paul55468c82005-03-14 20:19:01 +0000540 for (i = 0; i < vector_active (describe); i++)
Christian Frankecd40b322013-09-30 12:27:51 +0000541 if ((token = vector_slot (describe, i)) != NULL)
paul718e3742002-12-13 20:15:29 +0000542 {
Christian Frankecd40b322013-09-30 12:27:51 +0000543 if (token->cmd[0] == '\0')
paul718e3742002-12-13 20:15:29 +0000544 continue;
545
Christian Frankecd40b322013-09-30 12:27:51 +0000546 if (! token->desc)
paul4fc01e62002-12-13 20:49:00 +0000547 fprintf (stdout," %-s\n",
Christian Frankecd40b322013-09-30 12:27:51 +0000548 token->cmd[0] == '.' ? token->cmd + 1 : token->cmd);
paul718e3742002-12-13 20:15:29 +0000549 else
paul4fc01e62002-12-13 20:49:00 +0000550 fprintf (stdout," %-*s %s\n",
hassob094d262004-08-25 12:22:00 +0000551 width,
Christian Frankecd40b322013-09-30 12:27:51 +0000552 token->cmd[0] == '.' ? token->cmd + 1 : token->cmd,
553 token->desc);
paul718e3742002-12-13 20:15:29 +0000554 }
555
556 cmd_free_strvec (vline);
557 vector_free (describe);
558
559 rl_on_new_line();
560
561 return 0;
562}
563
hasso95e735b2004-08-26 13:08:30 +0000564/* Result of cmd_complete_command() call will be stored here
565 * and used in new_completion() in order to put the space in
566 * correct places only. */
paul718e3742002-12-13 20:15:29 +0000567int complete_status;
568
ajs274a4a42004-12-07 15:39:31 +0000569static char *
pauldfc0d9b2003-04-18 23:55:29 +0000570command_generator (const char *text, int state)
paul718e3742002-12-13 20:15:29 +0000571{
572 vector vline;
573 static char **matched = NULL;
574 static int index = 0;
575
576 /* First call. */
577 if (! state)
578 {
579 index = 0;
580
581 if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
582 return NULL;
583
584 vline = cmd_make_strvec (rl_line_buffer);
585 if (vline == NULL)
586 return NULL;
587
588 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
David Lampartera91a3ba2015-03-03 09:06:51 +0100589 vector_set (vline, NULL);
paul718e3742002-12-13 20:15:29 +0000590
591 matched = cmd_complete_command (vline, vty, &complete_status);
592 }
593
594 if (matched && matched[index])
595 return matched[index++];
596
597 return NULL;
598}
599
ajs274a4a42004-12-07 15:39:31 +0000600static char **
paul718e3742002-12-13 20:15:29 +0000601new_completion (char *text, int start, int end)
602{
603 char **matches;
604
pauldfc0d9b2003-04-18 23:55:29 +0000605 matches = rl_completion_matches (text, command_generator);
paul718e3742002-12-13 20:15:29 +0000606
607 if (matches)
608 {
609 rl_point = rl_end;
Christian Franke67e7a212013-03-04 09:23:30 +0000610 if (complete_status != CMD_COMPLETE_FULL_MATCH)
611 /* only append a space on full match */
612 rl_completion_append_character = '\0';
paul718e3742002-12-13 20:15:29 +0000613 }
614
615 return matches;
616}
617
ajs274a4a42004-12-07 15:39:31 +0000618#if 0
619/* This function is not actually being used. */
620static char **
paul718e3742002-12-13 20:15:29 +0000621vtysh_completion (char *text, int start, int end)
622{
623 int ret;
624 vector vline;
625 char **matched = NULL;
626
627 if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
628 return NULL;
629
630 vline = cmd_make_strvec (rl_line_buffer);
631 if (vline == NULL)
632 return NULL;
633
634 /* In case of 'help \t'. */
635 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
636 vector_set (vline, '\0');
637
638 matched = cmd_complete_command (vline, vty, &ret);
639
640 cmd_free_strvec (vline);
641
642 return (char **) matched;
643}
ajs274a4a42004-12-07 15:39:31 +0000644#endif
paul718e3742002-12-13 20:15:29 +0000645
hasso95e735b2004-08-26 13:08:30 +0000646/* Vty node structures. */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800647static struct cmd_node bgp_node =
paul718e3742002-12-13 20:15:29 +0000648{
649 BGP_NODE,
650 "%s(config-router)# ",
651};
652
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800653static struct cmd_node rip_node =
paul718e3742002-12-13 20:15:29 +0000654{
655 RIP_NODE,
656 "%s(config-router)# ",
657};
658
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800659static struct cmd_node isis_node =
hassoc25e4582003-12-23 10:39:08 +0000660{
661 ISIS_NODE,
662 "%s(config-router)# ",
hassoc25e4582003-12-23 10:39:08 +0000663};
664
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800665static struct cmd_node interface_node =
paul718e3742002-12-13 20:15:29 +0000666{
667 INTERFACE_NODE,
668 "%s(config-if)# ",
669};
670
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800671static struct cmd_node rmap_node =
hasso95e735b2004-08-26 13:08:30 +0000672{
673 RMAP_NODE,
674 "%s(config-route-map)# "
675};
676
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800677static struct cmd_node zebra_node =
hasso95e735b2004-08-26 13:08:30 +0000678{
679 ZEBRA_NODE,
680 "%s(config-router)# "
681};
682
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800683static struct cmd_node bgp_vpnv4_node =
hasso95e735b2004-08-26 13:08:30 +0000684{
685 BGP_VPNV4_NODE,
686 "%s(config-router-af)# "
687};
688
Lou Berger13c378d2016-01-12 13:41:56 -0500689static struct cmd_node bgp_vpnv6_node =
690{
691 BGP_VPNV6_NODE,
692 "%s(config-router-af)# "
693};
694
Lou Bergera3fda882016-01-12 13:42:04 -0500695static struct cmd_node bgp_encap_node =
696{
697 BGP_ENCAP_NODE,
698 "%s(config-router-af)# "
699};
700
701static struct cmd_node bgp_encapv6_node =
702{
703 BGP_ENCAPV6_NODE,
704 "%s(config-router-af)# "
705};
706
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800707static struct cmd_node bgp_ipv4_node =
hasso95e735b2004-08-26 13:08:30 +0000708{
709 BGP_IPV4_NODE,
710 "%s(config-router-af)# "
711};
712
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800713static struct cmd_node bgp_ipv4m_node =
hasso95e735b2004-08-26 13:08:30 +0000714{
715 BGP_IPV4M_NODE,
716 "%s(config-router-af)# "
717};
718
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800719static struct cmd_node bgp_ipv6_node =
hasso95e735b2004-08-26 13:08:30 +0000720{
721 BGP_IPV6_NODE,
722 "%s(config-router-af)# "
723};
724
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800725static struct cmd_node bgp_ipv6m_node =
paul57b5b7e2005-08-22 22:44:29 +0000726{
727 BGP_IPV6M_NODE,
728 "%s(config-router-af)# "
729};
730
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800731static struct cmd_node ospf_node =
hasso95e735b2004-08-26 13:08:30 +0000732{
733 OSPF_NODE,
734 "%s(config-router)# "
735};
736
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800737static struct cmd_node ripng_node =
hasso95e735b2004-08-26 13:08:30 +0000738{
739 RIPNG_NODE,
740 "%s(config-router)# "
741};
742
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800743static struct cmd_node ospf6_node =
hasso95e735b2004-08-26 13:08:30 +0000744{
745 OSPF6_NODE,
746 "%s(config-ospf6)# "
747};
748
David Lamparteree53c8b2015-05-23 05:45:59 +0200749static struct cmd_node babel_node =
750{
751 BABEL_NODE,
752 "%s(config-babel)# "
753};
754
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800755static struct cmd_node keychain_node =
hasso95e735b2004-08-26 13:08:30 +0000756{
757 KEYCHAIN_NODE,
758 "%s(config-keychain)# "
759};
760
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800761static struct cmd_node keychain_key_node =
hasso95e735b2004-08-26 13:08:30 +0000762{
763 KEYCHAIN_KEY_NODE,
764 "%s(config-keychain-key)# "
765};
766
hassoe7168df2004-10-03 20:11:32 +0000767/* Defined in lib/vty.c */
768extern struct cmd_node vty_node;
769
hasso95e735b2004-08-26 13:08:30 +0000770/* When '^Z' is received from vty, move down to the enable mode. */
David Lampartera9eb9062015-03-04 07:07:01 +0100771static int
ajsb1aa1472005-01-28 21:11:46 +0000772vtysh_end (void)
hasso95e735b2004-08-26 13:08:30 +0000773{
774 switch (vty->node)
775 {
776 case VIEW_NODE:
777 case ENABLE_NODE:
778 /* Nothing to do. */
779 break;
780 default:
781 vty->node = ENABLE_NODE;
782 break;
783 }
784 return CMD_SUCCESS;
785}
786
787DEFUNSH (VTYSH_ALL,
788 vtysh_end_all,
789 vtysh_end_all_cmd,
790 "end",
hassoe7168df2004-10-03 20:11:32 +0000791 "End current mode and change to enable mode\n")
hasso95e735b2004-08-26 13:08:30 +0000792{
hasso42895462004-09-26 16:25:07 +0000793 return vtysh_end ();
hasso95e735b2004-08-26 13:08:30 +0000794}
795
paul718e3742002-12-13 20:15:29 +0000796DEFUNSH (VTYSH_BGPD,
797 router_bgp,
798 router_bgp_cmd,
Paul Jakma320da872008-07-02 13:40:33 +0000799 "router bgp " CMD_AS_RANGE,
paul718e3742002-12-13 20:15:29 +0000800 ROUTER_STR
801 BGP_STR
802 AS_STR)
803{
804 vty->node = BGP_NODE;
805 return CMD_SUCCESS;
806}
807
Paul Jakma10895fd2008-07-03 19:34:48 +0000808ALIAS_SH (VTYSH_BGPD,
809 router_bgp,
810 router_bgp_view_cmd,
811 "router bgp " CMD_AS_RANGE " view WORD",
812 ROUTER_STR
813 BGP_STR
814 AS_STR
815 "BGP view\n"
816 "view name\n")
817
paul718e3742002-12-13 20:15:29 +0000818DEFUNSH (VTYSH_BGPD,
819 address_family_vpnv4,
820 address_family_vpnv4_cmd,
821 "address-family vpnv4",
822 "Enter Address Family command mode\n"
823 "Address family\n")
824{
825 vty->node = BGP_VPNV4_NODE;
826 return CMD_SUCCESS;
827}
828
829DEFUNSH (VTYSH_BGPD,
830 address_family_vpnv4_unicast,
831 address_family_vpnv4_unicast_cmd,
832 "address-family vpnv4 unicast",
833 "Enter Address Family command mode\n"
834 "Address family\n"
835 "Address Family Modifier\n")
836{
837 vty->node = BGP_VPNV4_NODE;
838 return CMD_SUCCESS;
839}
840
841DEFUNSH (VTYSH_BGPD,
Lou Berger13c378d2016-01-12 13:41:56 -0500842 address_family_vpnv6,
843 address_family_vpnv6_cmd,
844 "address-family vpnv6",
845 "Enter Address Family command mode\n"
846 "Address family\n")
847{
848 vty->node = BGP_VPNV6_NODE;
849 return CMD_SUCCESS;
850}
851
852DEFUNSH (VTYSH_BGPD,
853 address_family_vpnv6_unicast,
854 address_family_vpnv6_unicast_cmd,
855 "address-family vpnv6 unicast",
856 "Enter Address Family command mode\n"
857 "Address family\n"
858 "Address Family Modifier\n")
859{
860 vty->node = BGP_VPNV6_NODE;
861 return CMD_SUCCESS;
862}
863
864DEFUNSH (VTYSH_BGPD,
Lou Bergera3fda882016-01-12 13:42:04 -0500865 address_family_encap,
866 address_family_encap_cmd,
867 "address-family encap",
868 "Enter Address Family command mode\n"
869 "Address family\n")
870{
871 vty->node = BGP_ENCAP_NODE;
872 return CMD_SUCCESS;
873}
874
875DEFUNSH (VTYSH_BGPD,
876 address_family_encapv4,
877 address_family_encapv4_cmd,
878 "address-family encapv4",
879 "Enter Address Family command mode\n"
880 "Address family\n")
881{
882 vty->node = BGP_ENCAP_NODE;
883 return CMD_SUCCESS;
884}
885
886DEFUNSH (VTYSH_BGPD,
887 address_family_encapv6,
888 address_family_encapv6_cmd,
889 "address-family encapv6",
890 "Enter Address Family command mode\n"
891 "Address family\n")
892{
893 vty->node = BGP_ENCAPV6_NODE;
894 return CMD_SUCCESS;
895}
896
897DEFUNSH (VTYSH_BGPD,
paul718e3742002-12-13 20:15:29 +0000898 address_family_ipv4_unicast,
899 address_family_ipv4_unicast_cmd,
900 "address-family ipv4 unicast",
901 "Enter Address Family command mode\n"
902 "Address family\n"
903 "Address Family Modifier\n")
904{
905 vty->node = BGP_IPV4_NODE;
906 return CMD_SUCCESS;
907}
908
909DEFUNSH (VTYSH_BGPD,
910 address_family_ipv4_multicast,
911 address_family_ipv4_multicast_cmd,
912 "address-family ipv4 multicast",
913 "Enter Address Family command mode\n"
914 "Address family\n"
915 "Address Family Modifier\n")
916{
917 vty->node = BGP_IPV4M_NODE;
918 return CMD_SUCCESS;
919}
920
921DEFUNSH (VTYSH_BGPD,
922 address_family_ipv6,
923 address_family_ipv6_cmd,
924 "address-family ipv6",
925 "Enter Address Family command mode\n"
926 "Address family\n")
927{
928 vty->node = BGP_IPV6_NODE;
929 return CMD_SUCCESS;
930}
931
932DEFUNSH (VTYSH_BGPD,
933 address_family_ipv6_unicast,
934 address_family_ipv6_unicast_cmd,
935 "address-family ipv6 unicast",
936 "Enter Address Family command mode\n"
937 "Address family\n"
938 "Address Family Modifier\n")
939{
940 vty->node = BGP_IPV6_NODE;
941 return CMD_SUCCESS;
942}
943
paul57b5b7e2005-08-22 22:44:29 +0000944DEFUNSH (VTYSH_BGPD,
945 address_family_ipv6_multicast,
946 address_family_ipv6_multicast_cmd,
947 "address-family ipv6 multicast",
948 "Enter Address Family command mode\n"
949 "Address family\n"
950 "Address Family Modifier\n")
951{
952 vty->node = BGP_IPV6M_NODE;
953 return CMD_SUCCESS;
954}
955
paul718e3742002-12-13 20:15:29 +0000956DEFUNSH (VTYSH_RIPD,
957 key_chain,
958 key_chain_cmd,
959 "key chain WORD",
960 "Authentication key management\n"
961 "Key-chain management\n"
962 "Key-chain name\n")
963{
964 vty->node = KEYCHAIN_NODE;
965 return CMD_SUCCESS;
966}
967
968DEFUNSH (VTYSH_RIPD,
969 key,
970 key_cmd,
971 "key <0-2147483647>",
972 "Configure a key\n"
973 "Key identifier number\n")
974{
975 vty->node = KEYCHAIN_KEY_NODE;
976 return CMD_SUCCESS;
977}
978
979DEFUNSH (VTYSH_RIPD,
980 router_rip,
981 router_rip_cmd,
982 "router rip",
983 ROUTER_STR
984 "RIP")
985{
986 vty->node = RIP_NODE;
987 return CMD_SUCCESS;
988}
989
990DEFUNSH (VTYSH_RIPNGD,
991 router_ripng,
992 router_ripng_cmd,
993 "router ripng",
994 ROUTER_STR
995 "RIPng")
996{
997 vty->node = RIPNG_NODE;
998 return CMD_SUCCESS;
999}
1000
1001DEFUNSH (VTYSH_OSPFD,
1002 router_ospf,
1003 router_ospf_cmd,
1004 "router ospf",
1005 "Enable a routing process\n"
1006 "Start OSPF configuration\n")
1007{
1008 vty->node = OSPF_NODE;
1009 return CMD_SUCCESS;
1010}
1011
1012DEFUNSH (VTYSH_OSPF6D,
1013 router_ospf6,
1014 router_ospf6_cmd,
1015 "router ospf6",
1016 OSPF6_ROUTER_STR
1017 OSPF6_STR)
1018{
1019 vty->node = OSPF6_NODE;
1020 return CMD_SUCCESS;
1021}
1022
hassoc25e4582003-12-23 10:39:08 +00001023DEFUNSH (VTYSH_ISISD,
hassob094d262004-08-25 12:22:00 +00001024 router_isis,
1025 router_isis_cmd,
1026 "router isis WORD",
1027 ROUTER_STR
1028 "ISO IS-IS\n"
1029 "ISO Routing area tag")
hassoc25e4582003-12-23 10:39:08 +00001030{
1031 vty->node = ISIS_NODE;
1032 return CMD_SUCCESS;
1033}
1034
paul718e3742002-12-13 20:15:29 +00001035DEFUNSH (VTYSH_RMAP,
1036 route_map,
1037 route_map_cmd,
1038 "route-map WORD (deny|permit) <1-65535>",
1039 "Create route-map or enter route-map command mode\n"
1040 "Route map tag\n"
1041 "Route map denies set operations\n"
1042 "Route map permits set operations\n"
1043 "Sequence to insert to/delete from existing route-map entry\n")
1044{
1045 vty->node = RMAP_NODE;
1046 return CMD_SUCCESS;
1047}
1048
paul718e3742002-12-13 20:15:29 +00001049DEFUNSH (VTYSH_ALL,
hassoe7168df2004-10-03 20:11:32 +00001050 vtysh_line_vty,
1051 vtysh_line_vty_cmd,
1052 "line vty",
1053 "Configure a terminal line\n"
1054 "Virtual terminal\n")
1055{
1056 vty->node = VTY_NODE;
1057 return CMD_SUCCESS;
1058}
1059
1060DEFUNSH (VTYSH_ALL,
paul718e3742002-12-13 20:15:29 +00001061 vtysh_enable,
1062 vtysh_enable_cmd,
1063 "enable",
1064 "Turn on privileged mode command\n")
1065{
1066 vty->node = ENABLE_NODE;
1067 return CMD_SUCCESS;
1068}
1069
paul718e3742002-12-13 20:15:29 +00001070DEFUNSH (VTYSH_ALL,
1071 vtysh_disable,
1072 vtysh_disable_cmd,
1073 "disable",
1074 "Turn off privileged mode command\n")
1075{
1076 if (vty->node == ENABLE_NODE)
1077 vty->node = VIEW_NODE;
1078 return CMD_SUCCESS;
1079}
1080
paul718e3742002-12-13 20:15:29 +00001081DEFUNSH (VTYSH_ALL,
1082 vtysh_config_terminal,
1083 vtysh_config_terminal_cmd,
1084 "configure terminal",
1085 "Configuration from vty interface\n"
1086 "Configuration terminal\n")
1087{
1088 vty->node = CONFIG_NODE;
1089 return CMD_SUCCESS;
1090}
1091
ajs274a4a42004-12-07 15:39:31 +00001092static int
paul718e3742002-12-13 20:15:29 +00001093vtysh_exit (struct vty *vty)
1094{
1095 switch (vty->node)
1096 {
1097 case VIEW_NODE:
1098 case ENABLE_NODE:
1099 exit (0);
1100 break;
1101 case CONFIG_NODE:
1102 vty->node = ENABLE_NODE;
1103 break;
1104 case INTERFACE_NODE:
1105 case ZEBRA_NODE:
1106 case BGP_NODE:
1107 case RIP_NODE:
1108 case RIPNG_NODE:
1109 case OSPF_NODE:
1110 case OSPF6_NODE:
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +01001111 case BABEL_NODE:
hassoc25e4582003-12-23 10:39:08 +00001112 case ISIS_NODE:
paul718e3742002-12-13 20:15:29 +00001113 case MASC_NODE:
1114 case RMAP_NODE:
1115 case VTY_NODE:
1116 case KEYCHAIN_NODE:
hasso2a56df92004-05-09 23:16:40 +00001117 vtysh_execute("end");
1118 vtysh_execute("configure terminal");
paul718e3742002-12-13 20:15:29 +00001119 vty->node = CONFIG_NODE;
1120 break;
1121 case BGP_VPNV4_NODE:
Lou Berger13c378d2016-01-12 13:41:56 -05001122 case BGP_VPNV6_NODE:
Lou Bergera3fda882016-01-12 13:42:04 -05001123 case BGP_ENCAP_NODE:
1124 case BGP_ENCAPV6_NODE:
paul718e3742002-12-13 20:15:29 +00001125 case BGP_IPV4_NODE:
1126 case BGP_IPV4M_NODE:
1127 case BGP_IPV6_NODE:
paul57b5b7e2005-08-22 22:44:29 +00001128 case BGP_IPV6M_NODE:
paul718e3742002-12-13 20:15:29 +00001129 vty->node = BGP_NODE;
1130 break;
1131 case KEYCHAIN_KEY_NODE:
1132 vty->node = KEYCHAIN_NODE;
1133 break;
1134 default:
1135 break;
1136 }
1137 return CMD_SUCCESS;
1138}
1139
1140DEFUNSH (VTYSH_ALL,
1141 vtysh_exit_all,
1142 vtysh_exit_all_cmd,
1143 "exit",
1144 "Exit current mode and down to previous mode\n")
1145{
1146 return vtysh_exit (vty);
1147}
1148
1149ALIAS (vtysh_exit_all,
1150 vtysh_quit_all_cmd,
1151 "quit",
1152 "Exit current mode and down to previous mode\n")
1153
1154DEFUNSH (VTYSH_BGPD,
1155 exit_address_family,
1156 exit_address_family_cmd,
1157 "exit-address-family",
1158 "Exit from Address Family configuration mode\n")
1159{
1160 if (vty->node == BGP_IPV4_NODE
1161 || vty->node == BGP_IPV4M_NODE
1162 || vty->node == BGP_VPNV4_NODE
Lou Berger13c378d2016-01-12 13:41:56 -05001163 || vty->node == BGP_VPNV6_NODE
Lou Bergera3fda882016-01-12 13:42:04 -05001164 || vty->node == BGP_ENCAP_NODE
1165 || vty->node == BGP_ENCAPV6_NODE
paul57b5b7e2005-08-22 22:44:29 +00001166 || vty->node == BGP_IPV6_NODE
1167 || vty->node == BGP_IPV6M_NODE)
paul718e3742002-12-13 20:15:29 +00001168 vty->node = BGP_NODE;
1169 return CMD_SUCCESS;
1170}
1171
1172DEFUNSH (VTYSH_ZEBRA,
1173 vtysh_exit_zebra,
1174 vtysh_exit_zebra_cmd,
1175 "exit",
1176 "Exit current mode and down to previous mode\n")
1177{
1178 return vtysh_exit (vty);
1179}
1180
1181ALIAS (vtysh_exit_zebra,
1182 vtysh_quit_zebra_cmd,
1183 "quit",
1184 "Exit current mode and down to previous mode\n")
1185
1186DEFUNSH (VTYSH_RIPD,
1187 vtysh_exit_ripd,
1188 vtysh_exit_ripd_cmd,
1189 "exit",
1190 "Exit current mode and down to previous mode\n")
1191{
1192 return vtysh_exit (vty);
1193}
1194
1195ALIAS (vtysh_exit_ripd,
1196 vtysh_quit_ripd_cmd,
1197 "quit",
1198 "Exit current mode and down to previous mode\n")
1199
paul68980082003-03-25 05:07:42 +00001200DEFUNSH (VTYSH_RIPNGD,
hassob094d262004-08-25 12:22:00 +00001201 vtysh_exit_ripngd,
1202 vtysh_exit_ripngd_cmd,
1203 "exit",
1204 "Exit current mode and down to previous mode\n")
paul68980082003-03-25 05:07:42 +00001205{
1206 return vtysh_exit (vty);
1207}
1208
1209ALIAS (vtysh_exit_ripngd,
1210 vtysh_quit_ripngd_cmd,
1211 "quit",
1212 "Exit current mode and down to previous mode\n")
1213
paul718e3742002-12-13 20:15:29 +00001214DEFUNSH (VTYSH_RMAP,
1215 vtysh_exit_rmap,
1216 vtysh_exit_rmap_cmd,
1217 "exit",
1218 "Exit current mode and down to previous mode\n")
1219{
1220 return vtysh_exit (vty);
1221}
1222
1223ALIAS (vtysh_exit_rmap,
1224 vtysh_quit_rmap_cmd,
1225 "quit",
1226 "Exit current mode and down to previous mode\n")
1227
1228DEFUNSH (VTYSH_BGPD,
1229 vtysh_exit_bgpd,
1230 vtysh_exit_bgpd_cmd,
1231 "exit",
1232 "Exit current mode and down to previous mode\n")
1233{
1234 return vtysh_exit (vty);
1235}
1236
1237ALIAS (vtysh_exit_bgpd,
1238 vtysh_quit_bgpd_cmd,
1239 "quit",
1240 "Exit current mode and down to previous mode\n")
1241
1242DEFUNSH (VTYSH_OSPFD,
1243 vtysh_exit_ospfd,
1244 vtysh_exit_ospfd_cmd,
1245 "exit",
1246 "Exit current mode and down to previous mode\n")
1247{
1248 return vtysh_exit (vty);
1249}
1250
1251ALIAS (vtysh_exit_ospfd,
1252 vtysh_quit_ospfd_cmd,
1253 "quit",
1254 "Exit current mode and down to previous mode\n")
1255
paul68980082003-03-25 05:07:42 +00001256DEFUNSH (VTYSH_OSPF6D,
hassob094d262004-08-25 12:22:00 +00001257 vtysh_exit_ospf6d,
1258 vtysh_exit_ospf6d_cmd,
1259 "exit",
1260 "Exit current mode and down to previous mode\n")
paul68980082003-03-25 05:07:42 +00001261{
1262 return vtysh_exit (vty);
1263}
1264
1265ALIAS (vtysh_exit_ospf6d,
1266 vtysh_quit_ospf6d_cmd,
1267 "quit",
1268 "Exit current mode and down to previous mode\n")
1269
hassoc25e4582003-12-23 10:39:08 +00001270DEFUNSH (VTYSH_ISISD,
hassob094d262004-08-25 12:22:00 +00001271 vtysh_exit_isisd,
1272 vtysh_exit_isisd_cmd,
1273 "exit",
1274 "Exit current mode and down to previous mode\n")
hassoc25e4582003-12-23 10:39:08 +00001275{
1276 return vtysh_exit (vty);
1277}
1278
1279ALIAS (vtysh_exit_isisd,
1280 vtysh_quit_isisd_cmd,
1281 "quit",
1282 "Exit current mode and down to previous mode\n")
1283
hassoe7168df2004-10-03 20:11:32 +00001284DEFUNSH (VTYSH_ALL,
1285 vtysh_exit_line_vty,
1286 vtysh_exit_line_vty_cmd,
1287 "exit",
1288 "Exit current mode and down to previous mode\n")
1289{
1290 return vtysh_exit (vty);
1291}
1292
1293ALIAS (vtysh_exit_line_vty,
1294 vtysh_quit_line_vty_cmd,
1295 "quit",
1296 "Exit current mode and down to previous mode\n")
1297
hasso95e735b2004-08-26 13:08:30 +00001298DEFUNSH (VTYSH_INTERFACE,
paul718e3742002-12-13 20:15:29 +00001299 vtysh_interface,
1300 vtysh_interface_cmd,
1301 "interface IFNAME",
1302 "Select an interface to configure\n"
1303 "Interface's name\n")
1304{
1305 vty->node = INTERFACE_NODE;
1306 return CMD_SUCCESS;
1307}
1308
Feng Lu471ea392015-05-22 11:40:00 +02001309ALIAS_SH (VTYSH_ZEBRA,
1310 vtysh_interface,
1311 vtysh_interface_vrf_cmd,
1312 "interface IFNAME " VRF_CMD_STR,
1313 "Select an interface to configure\n"
1314 "Interface's name\n"
1315 VRF_CMD_HELP_STR)
1316
hasso95e735b2004-08-26 13:08:30 +00001317/* TODO Implement "no interface command in isisd. */
paul32d24632003-05-23 09:25:20 +00001318DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D,
1319 vtysh_no_interface_cmd,
1320 "no interface IFNAME",
1321 NO_STR
1322 "Delete a pseudo interface's configuration\n"
1323 "Interface's name\n")
1324
Feng Lu471ea392015-05-22 11:40:00 +02001325DEFSH (VTYSH_ZEBRA,
1326 vtysh_no_interface_vrf_cmd,
1327 "no interface IFNAME " VRF_CMD_STR,
1328 NO_STR
1329 "Delete a pseudo interface's configuration\n"
1330 "Interface's name\n"
1331 VRF_CMD_HELP_STR)
1332
hasso95e735b2004-08-26 13:08:30 +00001333/* TODO Implement interface description commands in ripngd, ospf6d
1334 * and isisd. */
paul338a9912003-03-01 15:44:10 +00001335DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1336 interface_desc_cmd,
1337 "description .LINE",
1338 "Interface specific description\n"
1339 "Characters describing this interface\n")
paul464dc8d2003-03-28 02:25:45 +00001340
1341DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1342 no_interface_desc_cmd,
1343 "no description",
1344 NO_STR
1345 "Interface specific description\n")
paul338a9912003-03-01 15:44:10 +00001346
hasso95e735b2004-08-26 13:08:30 +00001347DEFUNSH (VTYSH_INTERFACE,
paul718e3742002-12-13 20:15:29 +00001348 vtysh_exit_interface,
1349 vtysh_exit_interface_cmd,
1350 "exit",
1351 "Exit current mode and down to previous mode\n")
1352{
1353 return vtysh_exit (vty);
1354}
1355
1356ALIAS (vtysh_exit_interface,
1357 vtysh_quit_interface_cmd,
1358 "quit",
1359 "Exit current mode and down to previous mode\n")
1360
Donald Sharp567a6382015-08-19 21:22:17 -04001361DEFUN (vtysh_show_thread,
1362 vtysh_show_thread_cmd,
1363 "show thread cpu [FILTER]",
1364 SHOW_STR
1365 "Thread information\n"
1366 "Thread CPU usage\n"
1367 "Display filter (rwtexb)\n")
1368{
1369 unsigned int i;
1370 int ret = CMD_SUCCESS;
1371 char line[100];
1372
1373 sprintf(line, "show thread cpu %s\n", (argc == 1) ? argv[0] : "");
1374 for (i = 0; i < array_size(vtysh_client); i++)
1375 if ( vtysh_client[i].fd >= 0 )
1376 {
1377 fprintf (stdout, "Thread statistics for %s:\n",
1378 vtysh_client[i].name);
1379 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1380 fprintf (stdout,"\n");
1381 }
1382 return ret;
1383}
1384
1385DEFUN (vtysh_show_work_queues,
1386 vtysh_show_work_queues_cmd,
1387 "show work-queues",
1388 SHOW_STR
1389 "Work Queue information\n")
1390{
1391 unsigned int i;
1392 int ret = CMD_SUCCESS;
1393 char line[] = "show work-queues\n";
1394
1395 for (i = 0; i < array_size(vtysh_client); i++)
1396 if ( vtysh_client[i].fd >= 0 )
1397 {
1398 fprintf (stdout, "Work queue statistics for %s:\n",
1399 vtysh_client[i].name);
1400 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1401 fprintf (stdout,"\n");
1402 }
1403
1404 return ret;
1405}
1406
Paul Jakma362b4032006-05-28 07:54:45 +00001407/* Memory */
1408DEFUN (vtysh_show_memory,
1409 vtysh_show_memory_cmd,
1410 "show memory",
1411 SHOW_STR
1412 "Memory statistics\n")
1413{
1414 unsigned int i;
1415 int ret = CMD_SUCCESS;
1416 char line[] = "show memory\n";
1417
Balaji.G837d16c2012-09-26 14:09:10 +05301418 for (i = 0; i < array_size(vtysh_client); i++)
Paul Jakma362b4032006-05-28 07:54:45 +00001419 if ( vtysh_client[i].fd >= 0 )
1420 {
1421 fprintf (stdout, "Memory statistics for %s:\n",
1422 vtysh_client[i].name);
1423 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1424 fprintf (stdout,"\n");
1425 }
1426
1427 return ret;
1428}
1429
hasso95e735b2004-08-26 13:08:30 +00001430/* Logging commands. */
Paul Jakmadbf7d132006-05-23 22:10:01 +00001431DEFUN (vtysh_show_logging,
1432 vtysh_show_logging_cmd,
1433 "show logging",
1434 SHOW_STR
1435 "Show current logging configuration\n")
1436{
1437 unsigned int i;
1438 int ret = CMD_SUCCESS;
1439 char line[] = "show logging\n";
1440
Balaji.G837d16c2012-09-26 14:09:10 +05301441 for (i = 0; i < array_size(vtysh_client); i++)
Paul Jakma4150f332006-05-23 22:10:55 +00001442 if ( vtysh_client[i].fd >= 0 )
1443 {
1444 fprintf (stdout,"Logging configuration for %s:\n",
1445 vtysh_client[i].name);
1446 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1447 fprintf (stdout,"\n");
1448 }
1449
Paul Jakmadbf7d132006-05-23 22:10:01 +00001450 return ret;
1451}
1452
hasso95e735b2004-08-26 13:08:30 +00001453DEFUNSH (VTYSH_ALL,
1454 vtysh_log_stdout,
1455 vtysh_log_stdout_cmd,
1456 "log stdout",
1457 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001458 "Set stdout logging level\n")
1459{
1460 return CMD_SUCCESS;
1461}
1462
1463DEFUNSH (VTYSH_ALL,
1464 vtysh_log_stdout_level,
1465 vtysh_log_stdout_level_cmd,
1466 "log stdout "LOG_LEVELS,
1467 "Logging control\n"
1468 "Set stdout logging level\n"
1469 LOG_LEVEL_DESC)
hasso95e735b2004-08-26 13:08:30 +00001470{
1471 return CMD_SUCCESS;
1472}
1473
1474DEFUNSH (VTYSH_ALL,
1475 no_vtysh_log_stdout,
1476 no_vtysh_log_stdout_cmd,
ajs274a4a42004-12-07 15:39:31 +00001477 "no log stdout [LEVEL]",
hasso95e735b2004-08-26 13:08:30 +00001478 NO_STR
1479 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001480 "Cancel logging to stdout\n"
1481 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001482{
1483 return CMD_SUCCESS;
1484}
1485
1486DEFUNSH (VTYSH_ALL,
1487 vtysh_log_file,
1488 vtysh_log_file_cmd,
1489 "log file FILENAME",
1490 "Logging control\n"
1491 "Logging to file\n"
1492 "Logging filename\n")
1493{
1494 return CMD_SUCCESS;
1495}
1496
1497DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001498 vtysh_log_file_level,
1499 vtysh_log_file_level_cmd,
1500 "log file FILENAME "LOG_LEVELS,
1501 "Logging control\n"
1502 "Logging to file\n"
1503 "Logging filename\n"
1504 LOG_LEVEL_DESC)
1505{
1506 return CMD_SUCCESS;
1507}
1508
1509DEFUNSH (VTYSH_ALL,
hasso95e735b2004-08-26 13:08:30 +00001510 no_vtysh_log_file,
1511 no_vtysh_log_file_cmd,
1512 "no log file [FILENAME]",
1513 NO_STR
1514 "Logging control\n"
1515 "Cancel logging to file\n"
1516 "Logging file name\n")
1517{
1518 return CMD_SUCCESS;
1519}
1520
ajs274a4a42004-12-07 15:39:31 +00001521ALIAS_SH (VTYSH_ALL,
1522 no_vtysh_log_file,
1523 no_vtysh_log_file_level_cmd,
1524 "no log file FILENAME LEVEL",
1525 NO_STR
1526 "Logging control\n"
1527 "Cancel logging to file\n"
1528 "Logging file name\n"
1529 "Logging level\n")
1530
1531DEFUNSH (VTYSH_ALL,
1532 vtysh_log_monitor,
1533 vtysh_log_monitor_cmd,
1534 "log monitor",
1535 "Logging control\n"
1536 "Set terminal line (monitor) logging level\n")
1537{
1538 return CMD_SUCCESS;
1539}
1540
1541DEFUNSH (VTYSH_ALL,
1542 vtysh_log_monitor_level,
1543 vtysh_log_monitor_level_cmd,
1544 "log monitor "LOG_LEVELS,
1545 "Logging control\n"
1546 "Set terminal line (monitor) logging level\n"
1547 LOG_LEVEL_DESC)
1548{
1549 return CMD_SUCCESS;
1550}
1551
1552DEFUNSH (VTYSH_ALL,
1553 no_vtysh_log_monitor,
1554 no_vtysh_log_monitor_cmd,
1555 "no log monitor [LEVEL]",
1556 NO_STR
1557 "Logging control\n"
1558 "Disable terminal line (monitor) logging\n"
1559 "Logging level\n")
1560{
1561 return CMD_SUCCESS;
1562}
1563
hasso95e735b2004-08-26 13:08:30 +00001564DEFUNSH (VTYSH_ALL,
1565 vtysh_log_syslog,
1566 vtysh_log_syslog_cmd,
1567 "log syslog",
1568 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001569 "Set syslog logging level\n")
1570{
1571 return CMD_SUCCESS;
1572}
1573
1574DEFUNSH (VTYSH_ALL,
1575 vtysh_log_syslog_level,
1576 vtysh_log_syslog_level_cmd,
1577 "log syslog "LOG_LEVELS,
1578 "Logging control\n"
1579 "Set syslog logging level\n"
1580 LOG_LEVEL_DESC)
hasso95e735b2004-08-26 13:08:30 +00001581{
1582 return CMD_SUCCESS;
1583}
1584
1585DEFUNSH (VTYSH_ALL,
1586 no_vtysh_log_syslog,
1587 no_vtysh_log_syslog_cmd,
ajs274a4a42004-12-07 15:39:31 +00001588 "no log syslog [LEVEL]",
hasso95e735b2004-08-26 13:08:30 +00001589 NO_STR
1590 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001591 "Cancel logging to syslog\n"
1592 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001593{
1594 return CMD_SUCCESS;
1595}
1596
1597DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001598 vtysh_log_facility,
1599 vtysh_log_facility_cmd,
1600 "log facility "LOG_FACILITIES,
hasso95e735b2004-08-26 13:08:30 +00001601 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001602 "Facility parameter for syslog messages\n"
1603 LOG_FACILITY_DESC)
1604
hasso95e735b2004-08-26 13:08:30 +00001605{
1606 return CMD_SUCCESS;
1607}
1608
1609DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001610 no_vtysh_log_facility,
1611 no_vtysh_log_facility_cmd,
1612 "no log facility [FACILITY]",
hasso95e735b2004-08-26 13:08:30 +00001613 NO_STR
1614 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001615 "Reset syslog facility to default (daemon)\n"
1616 "Syslog facility\n")
1617
1618{
1619 return CMD_SUCCESS;
1620}
1621
1622DEFUNSH_DEPRECATED (VTYSH_ALL,
1623 vtysh_log_trap,
1624 vtysh_log_trap_cmd,
1625 "log trap "LOG_LEVELS,
1626 "Logging control\n"
1627 "(Deprecated) Set logging level and default for all destinations\n"
1628 LOG_LEVEL_DESC)
1629
1630{
1631 return CMD_SUCCESS;
1632}
1633
1634DEFUNSH_DEPRECATED (VTYSH_ALL,
1635 no_vtysh_log_trap,
1636 no_vtysh_log_trap_cmd,
1637 "no log trap [LEVEL]",
1638 NO_STR
1639 "Logging control\n"
1640 "Permit all logging information\n"
1641 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001642{
1643 return CMD_SUCCESS;
1644}
1645
1646DEFUNSH (VTYSH_ALL,
1647 vtysh_log_record_priority,
1648 vtysh_log_record_priority_cmd,
1649 "log record-priority",
1650 "Logging control\n"
1651 "Log the priority of the message within the message\n")
1652{
1653 return CMD_SUCCESS;
1654}
1655
1656DEFUNSH (VTYSH_ALL,
1657 no_vtysh_log_record_priority,
1658 no_vtysh_log_record_priority_cmd,
1659 "no log record-priority",
1660 NO_STR
1661 "Logging control\n"
1662 "Do not log the priority of the message within the message\n")
1663{
1664 return CMD_SUCCESS;
1665}
1666
hassoe7168df2004-10-03 20:11:32 +00001667DEFUNSH (VTYSH_ALL,
Andrew J. Schorrc749b722007-04-29 03:53:31 +00001668 vtysh_log_timestamp_precision,
1669 vtysh_log_timestamp_precision_cmd,
1670 "log timestamp precision <0-6>",
1671 "Logging control\n"
1672 "Timestamp configuration\n"
1673 "Set the timestamp precision\n"
1674 "Number of subsecond digits\n")
1675{
1676 return CMD_SUCCESS;
1677}
1678
1679DEFUNSH (VTYSH_ALL,
1680 no_vtysh_log_timestamp_precision,
1681 no_vtysh_log_timestamp_precision_cmd,
1682 "no log timestamp precision",
1683 NO_STR
1684 "Logging control\n"
1685 "Timestamp configuration\n"
1686 "Reset the timestamp precision to the default value of 0\n")
1687{
1688 return CMD_SUCCESS;
1689}
1690
1691DEFUNSH (VTYSH_ALL,
hassoe7168df2004-10-03 20:11:32 +00001692 vtysh_service_password_encrypt,
1693 vtysh_service_password_encrypt_cmd,
1694 "service password-encryption",
1695 "Set up miscellaneous service\n"
1696 "Enable encrypted passwords\n")
1697{
1698 return CMD_SUCCESS;
1699}
1700
1701DEFUNSH (VTYSH_ALL,
1702 no_vtysh_service_password_encrypt,
1703 no_vtysh_service_password_encrypt_cmd,
1704 "no service password-encryption",
1705 NO_STR
1706 "Set up miscellaneous service\n"
1707 "Enable encrypted passwords\n")
1708{
1709 return CMD_SUCCESS;
1710}
1711
1712DEFUNSH (VTYSH_ALL,
1713 vtysh_config_password,
1714 vtysh_password_cmd,
1715 "password (8|) WORD",
1716 "Assign the terminal connection password\n"
1717 "Specifies a HIDDEN password will follow\n"
1718 "dummy string \n"
1719 "The HIDDEN line password string\n")
1720{
1721 return CMD_SUCCESS;
1722}
1723
1724DEFUNSH (VTYSH_ALL,
1725 vtysh_password_text,
1726 vtysh_password_text_cmd,
1727 "password LINE",
1728 "Assign the terminal connection password\n"
1729 "The UNENCRYPTED (cleartext) line password\n")
1730{
1731 return CMD_SUCCESS;
1732}
1733
1734DEFUNSH (VTYSH_ALL,
1735 vtysh_config_enable_password,
1736 vtysh_enable_password_cmd,
1737 "enable password (8|) WORD",
1738 "Modify enable password parameters\n"
1739 "Assign the privileged level password\n"
1740 "Specifies a HIDDEN password will follow\n"
1741 "dummy string \n"
1742 "The HIDDEN 'enable' password string\n")
1743{
1744 return CMD_SUCCESS;
1745}
1746
1747DEFUNSH (VTYSH_ALL,
1748 vtysh_enable_password_text,
1749 vtysh_enable_password_text_cmd,
1750 "enable password LINE",
1751 "Modify enable password parameters\n"
1752 "Assign the privileged level password\n"
1753 "The UNENCRYPTED (cleartext) 'enable' password\n")
1754{
1755 return CMD_SUCCESS;
1756}
1757
1758DEFUNSH (VTYSH_ALL,
1759 no_vtysh_config_enable_password,
1760 no_vtysh_enable_password_cmd,
1761 "no enable password",
1762 NO_STR
1763 "Modify enable password parameters\n"
1764 "Assign the privileged level password\n")
1765{
1766 return CMD_SUCCESS;
1767}
1768
paul718e3742002-12-13 20:15:29 +00001769DEFUN (vtysh_write_terminal,
1770 vtysh_write_terminal_cmd,
1771 "write terminal",
1772 "Write running configuration to memory, network, or terminal\n"
1773 "Write to terminal\n")
1774{
ajsb1aa1472005-01-28 21:11:46 +00001775 u_int i;
paul718e3742002-12-13 20:15:29 +00001776 char line[] = "write terminal\n";
1777 FILE *fp = NULL;
1778
1779 if (vtysh_pager_name)
1780 {
paul4fc01e62002-12-13 20:49:00 +00001781 fp = popen (vtysh_pager_name, "w");
paul718e3742002-12-13 20:15:29 +00001782 if (fp == NULL)
1783 {
1784 perror ("popen");
1785 exit (1);
1786 }
1787 }
1788 else
1789 fp = stdout;
1790
1791 vty_out (vty, "Building configuration...%s", VTY_NEWLINE);
1792 vty_out (vty, "%sCurrent configuration:%s", VTY_NEWLINE,
1793 VTY_NEWLINE);
hassoe7168df2004-10-03 20:11:32 +00001794 vty_out (vty, "!%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001795
Balaji.G837d16c2012-09-26 14:09:10 +05301796 for (i = 0; i < array_size(vtysh_client); i++)
Gautam Kumarcc216b72015-10-26 13:22:12 -07001797 vtysh_client_execute (&vtysh_client[i], line, NULL);
paul718e3742002-12-13 20:15:29 +00001798
hassoe7168df2004-10-03 20:11:32 +00001799 /* Integrate vtysh specific configuration. */
1800 vtysh_config_write ();
1801
paul718e3742002-12-13 20:15:29 +00001802 vtysh_config_dump (fp);
1803
1804 if (vtysh_pager_name && fp)
1805 {
1806 fflush (fp);
1807 if (pclose (fp) == -1)
1808 {
1809 perror ("pclose");
1810 exit (1);
1811 }
1812 fp = NULL;
1813 }
1814
Chris Caputo6e79f8b2009-06-23 05:55:57 +00001815 vty_out (vty, "end%s", VTY_NEWLINE);
1816
paul718e3742002-12-13 20:15:29 +00001817 return CMD_SUCCESS;
1818}
1819
Donald Sharp9fb73e82015-09-22 11:13:12 -04001820DEFUN (vtysh_write_terminal_daemon,
1821 vtysh_write_terminal_daemon_cmd,
1822 "write terminal (zebra|ripd|ripngd|ospfd|ospf6d|bgpd|isisd|babeld)",
1823 "Write running configuration to memory, network, or terminal\n"
1824 "Write to terminal\n"
1825 "For the zebra daemon\n"
1826 "For the rip daemon\n"
1827 "For the ripng daemon\n"
1828 "For the ospf daemon\n"
1829 "For the ospfv6 daemon\n"
1830 "For the bgp daemon\n"
1831 "For the isis daemon\n"
1832 "For the babel daemon\n")
1833{
1834 unsigned int i;
1835 int ret = CMD_SUCCESS;
1836
1837 for (i = 0; i < array_size(vtysh_client); i++)
1838 {
1839 if (strcmp(vtysh_client[i].name, argv[0]) == 0)
1840 break;
1841 }
1842
1843 ret = vtysh_client_execute(&vtysh_client[i], "show running-config\n", stdout);
1844
1845 return ret;
1846}
1847
hassoe7168df2004-10-03 20:11:32 +00001848DEFUN (vtysh_integrated_config,
1849 vtysh_integrated_config_cmd,
1850 "service integrated-vtysh-config",
1851 "Set up miscellaneous service\n"
1852 "Write configuration into integrated file\n")
paul4fc01e62002-12-13 20:49:00 +00001853{
hassoe7168df2004-10-03 20:11:32 +00001854 vtysh_writeconfig_integrated = 1;
1855 return CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001856}
1857
hassoe7168df2004-10-03 20:11:32 +00001858DEFUN (no_vtysh_integrated_config,
1859 no_vtysh_integrated_config_cmd,
1860 "no service integrated-vtysh-config",
1861 NO_STR
1862 "Set up miscellaneous service\n"
1863 "Write configuration into integrated file\n")
paul4fc01e62002-12-13 20:49:00 +00001864{
hassoe7168df2004-10-03 20:11:32 +00001865 vtysh_writeconfig_integrated = 0;
1866 return CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001867}
1868
ajs274a4a42004-12-07 15:39:31 +00001869static int
1870write_config_integrated(void)
paul718e3742002-12-13 20:15:29 +00001871{
ajsb1aa1472005-01-28 21:11:46 +00001872 u_int i;
paul718e3742002-12-13 20:15:29 +00001873 char line[] = "write terminal\n";
1874 FILE *fp;
1875 char *integrate_sav = NULL;
1876
hasso95e735b2004-08-26 13:08:30 +00001877 integrate_sav = malloc (strlen (integrate_default) +
1878 strlen (CONF_BACKUP_EXT) + 1);
paul718e3742002-12-13 20:15:29 +00001879 strcpy (integrate_sav, integrate_default);
1880 strcat (integrate_sav, CONF_BACKUP_EXT);
1881
paul4fc01e62002-12-13 20:49:00 +00001882 fprintf (stdout,"Building Configuration...\n");
paul718e3742002-12-13 20:15:29 +00001883
hasso95e735b2004-08-26 13:08:30 +00001884 /* Move current configuration file to backup config file. */
paul718e3742002-12-13 20:15:29 +00001885 unlink (integrate_sav);
1886 rename (integrate_default, integrate_sav);
hasso95e735b2004-08-26 13:08:30 +00001887 free (integrate_sav);
paul4fc01e62002-12-13 20:49:00 +00001888
paul718e3742002-12-13 20:15:29 +00001889 fp = fopen (integrate_default, "w");
1890 if (fp == NULL)
1891 {
hasso95e735b2004-08-26 13:08:30 +00001892 fprintf (stdout,"%% Can't open configuration file %s.\n",
1893 integrate_default);
paul718e3742002-12-13 20:15:29 +00001894 return CMD_SUCCESS;
1895 }
paul718e3742002-12-13 20:15:29 +00001896
Balaji.G837d16c2012-09-26 14:09:10 +05301897 for (i = 0; i < array_size(vtysh_client); i++)
Gautam Kumarcc216b72015-10-26 13:22:12 -07001898 vtysh_client_execute (&vtysh_client[i], line, NULL);
paul718e3742002-12-13 20:15:29 +00001899
1900 vtysh_config_dump (fp);
1901
1902 fclose (fp);
1903
gdtaa593d52003-12-22 20:15:53 +00001904 if (chmod (integrate_default, CONFIGFILE_MASK) != 0)
1905 {
1906 fprintf (stdout,"%% Can't chmod configuration file %s: %s (%d)\n",
ajs6099b3b2004-11-20 02:06:59 +00001907 integrate_default, safe_strerror(errno), errno);
gdtaa593d52003-12-22 20:15:53 +00001908 return CMD_WARNING;
1909 }
1910
paul4fc01e62002-12-13 20:49:00 +00001911 fprintf(stdout,"Integrated configuration saved to %s\n",integrate_default);
1912
1913 fprintf (stdout,"[OK]\n");
1914
paul718e3742002-12-13 20:15:29 +00001915 return CMD_SUCCESS;
1916}
1917
paul4fc01e62002-12-13 20:49:00 +00001918DEFUN (vtysh_write_memory,
1919 vtysh_write_memory_cmd,
1920 "write memory",
1921 "Write running configuration to memory, network, or terminal\n"
1922 "Write configuration to the file (same as write file)\n")
1923{
pauldfc0d9b2003-04-18 23:55:29 +00001924 int ret = CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001925 char line[] = "write memory\n";
ajsb1aa1472005-01-28 21:11:46 +00001926 u_int i;
paul4fc01e62002-12-13 20:49:00 +00001927
hassoe7168df2004-10-03 20:11:32 +00001928 /* If integrated Quagga.conf explicitely set. */
1929 if (vtysh_writeconfig_integrated)
1930 return write_config_integrated();
paul4fc01e62002-12-13 20:49:00 +00001931
1932 fprintf (stdout,"Building Configuration...\n");
1933
Balaji.G837d16c2012-09-26 14:09:10 +05301934 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00001935 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
hassoe7168df2004-10-03 20:11:32 +00001936
paul4fc01e62002-12-13 20:49:00 +00001937 fprintf (stdout,"[OK]\n");
1938
pauldfc0d9b2003-04-18 23:55:29 +00001939 return ret;
paul4fc01e62002-12-13 20:49:00 +00001940}
1941
paul718e3742002-12-13 20:15:29 +00001942ALIAS (vtysh_write_memory,
1943 vtysh_copy_runningconfig_startupconfig_cmd,
1944 "copy running-config startup-config",
1945 "Copy from one file to another\n"
1946 "Copy from current system configuration\n"
1947 "Copy to startup configuration\n")
1948
1949ALIAS (vtysh_write_memory,
1950 vtysh_write_file_cmd,
1951 "write file",
1952 "Write running configuration to memory, network, or terminal\n"
1953 "Write configuration to the file (same as write memory)\n")
1954
hasso4a6e2252003-05-25 11:51:29 +00001955ALIAS (vtysh_write_memory,
1956 vtysh_write_cmd,
1957 "write",
1958 "Write running configuration to memory, network, or terminal\n")
1959
paul718e3742002-12-13 20:15:29 +00001960ALIAS (vtysh_write_terminal,
1961 vtysh_show_running_config_cmd,
1962 "show running-config",
1963 SHOW_STR
1964 "Current operating configuration\n")
hassob094d262004-08-25 12:22:00 +00001965
Donald Sharp9fb73e82015-09-22 11:13:12 -04001966ALIAS (vtysh_write_terminal_daemon,
1967 vtysh_show_running_config_daemon_cmd,
1968 "show running-config (zebra|ripd|ripngd|ospfd|ospf6d|bgpd|isisd|babeld)",
1969 SHOW_STR
1970 "Current operating configuration\n"
1971 "For the zebra daemon\n"
1972 "For the rip daemon\n"
1973 "For the ripng daemon\n"
1974 "For the ospf daemon\n"
1975 "For the ospfv6 daemon\n"
1976 "For the bgp daemon\n"
1977 "For the isis daemon\n"
1978 "For the babel daemon\n")
1979
hasso34553cc2004-08-27 13:56:39 +00001980DEFUN (vtysh_terminal_length,
1981 vtysh_terminal_length_cmd,
1982 "terminal length <0-512>",
1983 "Set terminal line parameters\n"
1984 "Set number of lines on a screen\n"
1985 "Number of lines on screen (0 for no pausing)\n")
1986{
1987 int lines;
1988 char *endptr = NULL;
1989 char default_pager[10];
1990
1991 lines = strtol (argv[0], &endptr, 10);
1992 if (lines < 0 || lines > 512 || *endptr != '\0')
1993 {
1994 vty_out (vty, "length is malformed%s", VTY_NEWLINE);
1995 return CMD_WARNING;
1996 }
1997
1998 if (vtysh_pager_name)
1999 {
2000 free (vtysh_pager_name);
2001 vtysh_pager_name = NULL;
2002 }
2003
2004 if (lines != 0)
2005 {
2006 snprintf(default_pager, 10, "more -%i", lines);
2007 vtysh_pager_name = strdup (default_pager);
2008 }
2009
2010 return CMD_SUCCESS;
2011}
2012
2013DEFUN (vtysh_terminal_no_length,
2014 vtysh_terminal_no_length_cmd,
2015 "terminal no length",
2016 "Set terminal line parameters\n"
2017 NO_STR
2018 "Set number of lines on a screen\n")
2019{
2020 if (vtysh_pager_name)
2021 {
2022 free (vtysh_pager_name);
2023 vtysh_pager_name = NULL;
2024 }
2025
2026 vtysh_pager_init();
2027 return CMD_SUCCESS;
2028}
2029
hassof2799e62004-10-28 17:43:11 +00002030DEFUN (vtysh_show_daemons,
2031 vtysh_show_daemons_cmd,
2032 "show daemons",
hassoe7168df2004-10-03 20:11:32 +00002033 SHOW_STR
2034 "Show list of running daemons\n")
2035{
ajsb1aa1472005-01-28 21:11:46 +00002036 u_int i;
2037
Balaji.G837d16c2012-09-26 14:09:10 +05302038 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00002039 if ( vtysh_client[i].fd >= 0 )
2040 vty_out(vty, " %s", vtysh_client[i].name);
hassoe7168df2004-10-03 20:11:32 +00002041 vty_out(vty, "%s", VTY_NEWLINE);
2042
2043 return CMD_SUCCESS;
2044}
2045
paul718e3742002-12-13 20:15:29 +00002046/* Execute command in child process. */
ajs274a4a42004-12-07 15:39:31 +00002047static int
hasso5862ff52004-10-11 13:20:40 +00002048execute_command (const char *command, int argc, const char *arg1,
2049 const char *arg2)
paul718e3742002-12-13 20:15:29 +00002050{
paul718e3742002-12-13 20:15:29 +00002051 pid_t pid;
2052 int status;
2053
2054 /* Call fork(). */
2055 pid = fork ();
2056
2057 if (pid < 0)
2058 {
2059 /* Failure of fork(). */
ajs6099b3b2004-11-20 02:06:59 +00002060 fprintf (stderr, "Can't fork: %s\n", safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +00002061 exit (1);
2062 }
2063 else if (pid == 0)
2064 {
2065 /* This is child process. */
2066 switch (argc)
2067 {
2068 case 0:
David Lamparter6769f432015-03-04 07:18:24 +01002069 execlp (command, command, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00002070 break;
2071 case 1:
David Lamparter6769f432015-03-04 07:18:24 +01002072 execlp (command, command, arg1, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00002073 break;
2074 case 2:
David Lamparter6769f432015-03-04 07:18:24 +01002075 execlp (command, command, arg1, arg2, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00002076 break;
2077 }
2078
2079 /* When execlp suceed, this part is not executed. */
ajs6099b3b2004-11-20 02:06:59 +00002080 fprintf (stderr, "Can't execute %s: %s\n", command, safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +00002081 exit (1);
2082 }
2083 else
2084 {
2085 /* This is parent. */
2086 execute_flag = 1;
David Lamparter6769f432015-03-04 07:18:24 +01002087 wait4 (pid, &status, 0, NULL);
paul718e3742002-12-13 20:15:29 +00002088 execute_flag = 0;
2089 }
2090 return 0;
2091}
2092
2093DEFUN (vtysh_ping,
2094 vtysh_ping_cmd,
2095 "ping WORD",
hasso4eeccf12003-06-25 10:49:55 +00002096 "Send echo messages\n"
paul718e3742002-12-13 20:15:29 +00002097 "Ping destination address or hostname\n")
2098{
2099 execute_command ("ping", 1, argv[0], NULL);
2100 return CMD_SUCCESS;
2101}
2102
hasso4eeccf12003-06-25 10:49:55 +00002103ALIAS (vtysh_ping,
2104 vtysh_ping_ip_cmd,
2105 "ping ip WORD",
2106 "Send echo messages\n"
2107 "IP echo\n"
2108 "Ping destination address or hostname\n")
2109
paul718e3742002-12-13 20:15:29 +00002110DEFUN (vtysh_traceroute,
2111 vtysh_traceroute_cmd,
2112 "traceroute WORD",
2113 "Trace route to destination\n"
2114 "Trace route to destination address or hostname\n")
2115{
2116 execute_command ("traceroute", 1, argv[0], NULL);
2117 return CMD_SUCCESS;
2118}
2119
hasso4eeccf12003-06-25 10:49:55 +00002120ALIAS (vtysh_traceroute,
2121 vtysh_traceroute_ip_cmd,
2122 "traceroute ip WORD",
2123 "Trace route to destination\n"
2124 "IP trace\n"
2125 "Trace route to destination address or hostname\n")
2126
2127#ifdef HAVE_IPV6
2128DEFUN (vtysh_ping6,
2129 vtysh_ping6_cmd,
2130 "ping ipv6 WORD",
2131 "Send echo messages\n"
2132 "IPv6 echo\n"
2133 "Ping destination address or hostname\n")
2134{
2135 execute_command ("ping6", 1, argv[0], NULL);
2136 return CMD_SUCCESS;
2137}
2138
2139DEFUN (vtysh_traceroute6,
2140 vtysh_traceroute6_cmd,
2141 "traceroute ipv6 WORD",
2142 "Trace route to destination\n"
2143 "IPv6 trace\n"
2144 "Trace route to destination address or hostname\n")
2145{
2146 execute_command ("traceroute6", 1, argv[0], NULL);
2147 return CMD_SUCCESS;
2148}
2149#endif
2150
paul718e3742002-12-13 20:15:29 +00002151DEFUN (vtysh_telnet,
2152 vtysh_telnet_cmd,
2153 "telnet WORD",
2154 "Open a telnet connection\n"
2155 "IP address or hostname of a remote system\n")
2156{
2157 execute_command ("telnet", 1, argv[0], NULL);
2158 return CMD_SUCCESS;
2159}
2160
2161DEFUN (vtysh_telnet_port,
2162 vtysh_telnet_port_cmd,
2163 "telnet WORD PORT",
2164 "Open a telnet connection\n"
2165 "IP address or hostname of a remote system\n"
2166 "TCP Port number\n")
2167{
2168 execute_command ("telnet", 2, argv[0], argv[1]);
2169 return CMD_SUCCESS;
2170}
2171
paul5087df52003-01-25 06:56:09 +00002172DEFUN (vtysh_ssh,
2173 vtysh_ssh_cmd,
2174 "ssh WORD",
2175 "Open an ssh connection\n"
2176 "[user@]host\n")
2177{
2178 execute_command ("ssh", 1, argv[0], NULL);
2179 return CMD_SUCCESS;
2180}
2181
paul718e3742002-12-13 20:15:29 +00002182DEFUN (vtysh_start_shell,
2183 vtysh_start_shell_cmd,
2184 "start-shell",
2185 "Start UNIX shell\n")
2186{
2187 execute_command ("sh", 0, NULL, NULL);
2188 return CMD_SUCCESS;
2189}
2190
2191DEFUN (vtysh_start_bash,
2192 vtysh_start_bash_cmd,
2193 "start-shell bash",
2194 "Start UNIX shell\n"
2195 "Start bash\n")
2196{
2197 execute_command ("bash", 0, NULL, NULL);
2198 return CMD_SUCCESS;
2199}
2200
2201DEFUN (vtysh_start_zsh,
2202 vtysh_start_zsh_cmd,
2203 "start-shell zsh",
2204 "Start UNIX shell\n"
2205 "Start Z shell\n")
2206{
2207 execute_command ("zsh", 0, NULL, NULL);
2208 return CMD_SUCCESS;
2209}
hassob094d262004-08-25 12:22:00 +00002210
ajs274a4a42004-12-07 15:39:31 +00002211static void
paul718e3742002-12-13 20:15:29 +00002212vtysh_install_default (enum node_type node)
2213{
2214 install_element (node, &config_list_cmd);
2215}
2216
2217/* Making connection to protocol daemon. */
ajs274a4a42004-12-07 15:39:31 +00002218static int
ajsb1aa1472005-01-28 21:11:46 +00002219vtysh_connect (struct vtysh_client *vclient)
paul718e3742002-12-13 20:15:29 +00002220{
2221 int ret;
2222 int sock, len;
2223 struct sockaddr_un addr;
2224 struct stat s_stat;
paul718e3742002-12-13 20:15:29 +00002225
paul718e3742002-12-13 20:15:29 +00002226 /* Stat socket to see if we have permission to access it. */
ajsb1aa1472005-01-28 21:11:46 +00002227 ret = stat (vclient->path, &s_stat);
paul718e3742002-12-13 20:15:29 +00002228 if (ret < 0 && errno != ENOENT)
2229 {
2230 fprintf (stderr, "vtysh_connect(%s): stat = %s\n",
ajsb1aa1472005-01-28 21:11:46 +00002231 vclient->path, safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002232 exit(1);
2233 }
2234
2235 if (ret >= 0)
2236 {
2237 if (! S_ISSOCK(s_stat.st_mode))
2238 {
2239 fprintf (stderr, "vtysh_connect(%s): Not a socket\n",
ajsb1aa1472005-01-28 21:11:46 +00002240 vclient->path);
paul718e3742002-12-13 20:15:29 +00002241 exit (1);
2242 }
2243
paul718e3742002-12-13 20:15:29 +00002244 }
2245
2246 sock = socket (AF_UNIX, SOCK_STREAM, 0);
2247 if (sock < 0)
2248 {
2249#ifdef DEBUG
ajsb1aa1472005-01-28 21:11:46 +00002250 fprintf(stderr, "vtysh_connect(%s): socket = %s\n", vclient->path,
ajs6099b3b2004-11-20 02:06:59 +00002251 safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002252#endif /* DEBUG */
2253 return -1;
2254 }
2255
2256 memset (&addr, 0, sizeof (struct sockaddr_un));
2257 addr.sun_family = AF_UNIX;
ajsb1aa1472005-01-28 21:11:46 +00002258 strncpy (addr.sun_path, vclient->path, strlen (vclient->path));
Paul Jakma6f0e3f62007-05-10 02:38:51 +00002259#ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
paul718e3742002-12-13 20:15:29 +00002260 len = addr.sun_len = SUN_LEN(&addr);
2261#else
2262 len = sizeof (addr.sun_family) + strlen (addr.sun_path);
Paul Jakma6f0e3f62007-05-10 02:38:51 +00002263#endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
paul718e3742002-12-13 20:15:29 +00002264
2265 ret = connect (sock, (struct sockaddr *) &addr, len);
2266 if (ret < 0)
2267 {
2268#ifdef DEBUG
ajsb1aa1472005-01-28 21:11:46 +00002269 fprintf(stderr, "vtysh_connect(%s): connect = %s\n", vclient->path,
ajs6099b3b2004-11-20 02:06:59 +00002270 safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002271#endif /* DEBUG */
2272 close (sock);
2273 return -1;
2274 }
2275 vclient->fd = sock;
2276
2277 return 0;
2278}
2279
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002280int
2281vtysh_connect_all(const char *daemon_name)
paul718e3742002-12-13 20:15:29 +00002282{
ajsb1aa1472005-01-28 21:11:46 +00002283 u_int i;
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002284 int rc = 0;
2285 int matches = 0;
ajsb1aa1472005-01-28 21:11:46 +00002286
Balaji.G837d16c2012-09-26 14:09:10 +05302287 for (i = 0; i < array_size(vtysh_client); i++)
ajsb1aa1472005-01-28 21:11:46 +00002288 {
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002289 if (!daemon_name || !strcmp(daemon_name, vtysh_client[i].name))
2290 {
2291 matches++;
2292 if (vtysh_connect(&vtysh_client[i]) == 0)
2293 rc++;
2294 /* We need direct access to ripd in vtysh_exit_ripd_only. */
2295 if (vtysh_client[i].flag == VTYSH_RIPD)
2296 ripd_client = &vtysh_client[i];
2297 }
ajsb1aa1472005-01-28 21:11:46 +00002298 }
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002299 if (!matches)
2300 fprintf(stderr, "Error: no daemons match name %s!\n", daemon_name);
2301 return rc;
paul718e3742002-12-13 20:15:29 +00002302}
2303
hasso95e735b2004-08-26 13:08:30 +00002304/* To disable readline's filename completion. */
ajs274a4a42004-12-07 15:39:31 +00002305static char *
pauldfc0d9b2003-04-18 23:55:29 +00002306vtysh_completion_entry_function (const char *ignore, int invoking_key)
paul718e3742002-12-13 20:15:29 +00002307{
pauldfc0d9b2003-04-18 23:55:29 +00002308 return NULL;
paul718e3742002-12-13 20:15:29 +00002309}
2310
2311void
ajsb1aa1472005-01-28 21:11:46 +00002312vtysh_readline_init (void)
paul718e3742002-12-13 20:15:29 +00002313{
2314 /* readline related settings. */
Sébastien Luttringer66d2ead2014-05-27 19:55:11 +02002315 rl_bind_key ('?', (rl_command_func_t *) vtysh_rl_describe);
paul68980082003-03-25 05:07:42 +00002316 rl_completion_entry_function = vtysh_completion_entry_function;
Sébastien Luttringer66d2ead2014-05-27 19:55:11 +02002317 rl_attempted_completion_function = (rl_completion_func_t *)new_completion;
paul718e3742002-12-13 20:15:29 +00002318}
2319
2320char *
ajsb1aa1472005-01-28 21:11:46 +00002321vtysh_prompt (void)
paul718e3742002-12-13 20:15:29 +00002322{
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002323 static struct utsname names;
paul718e3742002-12-13 20:15:29 +00002324 static char buf[100];
2325 const char*hostname;
2326 extern struct host host;
2327
2328 hostname = host.name;
2329
2330 if (!hostname)
2331 {
Andrew J. Schorrf366ad32006-07-27 18:01:41 +00002332 if (!names.nodename[0])
2333 uname (&names);
paul718e3742002-12-13 20:15:29 +00002334 hostname = names.nodename;
2335 }
2336
2337 snprintf (buf, sizeof buf, cmd_prompt (vty->node), hostname);
2338
2339 return buf;
2340}
2341
2342void
ajsb1aa1472005-01-28 21:11:46 +00002343vtysh_init_vty (void)
paul718e3742002-12-13 20:15:29 +00002344{
2345 /* Make vty structure. */
2346 vty = vty_new ();
2347 vty->type = VTY_SHELL;
2348 vty->node = VIEW_NODE;
2349
2350 /* Initialize commands. */
2351 cmd_init (0);
2352
2353 /* Install nodes. */
2354 install_node (&bgp_node, NULL);
2355 install_node (&rip_node, NULL);
2356 install_node (&interface_node, NULL);
2357 install_node (&rmap_node, NULL);
2358 install_node (&zebra_node, NULL);
2359 install_node (&bgp_vpnv4_node, NULL);
Lou Berger13c378d2016-01-12 13:41:56 -05002360 install_node (&bgp_vpnv6_node, NULL);
Lou Bergera3fda882016-01-12 13:42:04 -05002361 install_node (&bgp_encap_node, NULL);
2362 install_node (&bgp_encapv6_node, NULL);
paul718e3742002-12-13 20:15:29 +00002363 install_node (&bgp_ipv4_node, NULL);
2364 install_node (&bgp_ipv4m_node, NULL);
2365/* #ifdef HAVE_IPV6 */
2366 install_node (&bgp_ipv6_node, NULL);
paul57b5b7e2005-08-22 22:44:29 +00002367 install_node (&bgp_ipv6m_node, NULL);
paul718e3742002-12-13 20:15:29 +00002368/* #endif */
2369 install_node (&ospf_node, NULL);
2370/* #ifdef HAVE_IPV6 */
2371 install_node (&ripng_node, NULL);
2372 install_node (&ospf6_node, NULL);
2373/* #endif */
David Lamparteree53c8b2015-05-23 05:45:59 +02002374 install_node (&babel_node, NULL);
paul718e3742002-12-13 20:15:29 +00002375 install_node (&keychain_node, NULL);
2376 install_node (&keychain_key_node, NULL);
hassoc25e4582003-12-23 10:39:08 +00002377 install_node (&isis_node, NULL);
hassoe7168df2004-10-03 20:11:32 +00002378 install_node (&vty_node, NULL);
paul718e3742002-12-13 20:15:29 +00002379
2380 vtysh_install_default (VIEW_NODE);
2381 vtysh_install_default (ENABLE_NODE);
2382 vtysh_install_default (CONFIG_NODE);
2383 vtysh_install_default (BGP_NODE);
2384 vtysh_install_default (RIP_NODE);
2385 vtysh_install_default (INTERFACE_NODE);
2386 vtysh_install_default (RMAP_NODE);
2387 vtysh_install_default (ZEBRA_NODE);
2388 vtysh_install_default (BGP_VPNV4_NODE);
Lou Berger13c378d2016-01-12 13:41:56 -05002389 vtysh_install_default (BGP_VPNV6_NODE);
Lou Bergera3fda882016-01-12 13:42:04 -05002390 vtysh_install_default (BGP_ENCAP_NODE);
2391 vtysh_install_default (BGP_ENCAPV6_NODE);
paul718e3742002-12-13 20:15:29 +00002392 vtysh_install_default (BGP_IPV4_NODE);
2393 vtysh_install_default (BGP_IPV4M_NODE);
2394 vtysh_install_default (BGP_IPV6_NODE);
paul57b5b7e2005-08-22 22:44:29 +00002395 vtysh_install_default (BGP_IPV6M_NODE);
paul718e3742002-12-13 20:15:29 +00002396 vtysh_install_default (OSPF_NODE);
2397 vtysh_install_default (RIPNG_NODE);
2398 vtysh_install_default (OSPF6_NODE);
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +01002399 vtysh_install_default (BABEL_NODE);
hassoc25e4582003-12-23 10:39:08 +00002400 vtysh_install_default (ISIS_NODE);
paul718e3742002-12-13 20:15:29 +00002401 vtysh_install_default (KEYCHAIN_NODE);
2402 vtysh_install_default (KEYCHAIN_KEY_NODE);
hassoe7168df2004-10-03 20:11:32 +00002403 vtysh_install_default (VTY_NODE);
paul718e3742002-12-13 20:15:29 +00002404
2405 install_element (VIEW_NODE, &vtysh_enable_cmd);
2406 install_element (ENABLE_NODE, &vtysh_config_terminal_cmd);
2407 install_element (ENABLE_NODE, &vtysh_disable_cmd);
2408
2409 /* "exit" command. */
2410 install_element (VIEW_NODE, &vtysh_exit_all_cmd);
2411 install_element (VIEW_NODE, &vtysh_quit_all_cmd);
2412 install_element (CONFIG_NODE, &vtysh_exit_all_cmd);
2413 /* install_element (CONFIG_NODE, &vtysh_quit_all_cmd); */
2414 install_element (ENABLE_NODE, &vtysh_exit_all_cmd);
2415 install_element (ENABLE_NODE, &vtysh_quit_all_cmd);
2416 install_element (RIP_NODE, &vtysh_exit_ripd_cmd);
2417 install_element (RIP_NODE, &vtysh_quit_ripd_cmd);
paul68980082003-03-25 05:07:42 +00002418 install_element (RIPNG_NODE, &vtysh_exit_ripngd_cmd);
2419 install_element (RIPNG_NODE, &vtysh_quit_ripngd_cmd);
paul718e3742002-12-13 20:15:29 +00002420 install_element (OSPF_NODE, &vtysh_exit_ospfd_cmd);
2421 install_element (OSPF_NODE, &vtysh_quit_ospfd_cmd);
paul68980082003-03-25 05:07:42 +00002422 install_element (OSPF6_NODE, &vtysh_exit_ospf6d_cmd);
2423 install_element (OSPF6_NODE, &vtysh_quit_ospf6d_cmd);
paul718e3742002-12-13 20:15:29 +00002424 install_element (BGP_NODE, &vtysh_exit_bgpd_cmd);
2425 install_element (BGP_NODE, &vtysh_quit_bgpd_cmd);
2426 install_element (BGP_VPNV4_NODE, &vtysh_exit_bgpd_cmd);
2427 install_element (BGP_VPNV4_NODE, &vtysh_quit_bgpd_cmd);
Lou Berger13c378d2016-01-12 13:41:56 -05002428 install_element (BGP_VPNV6_NODE, &vtysh_exit_bgpd_cmd);
2429 install_element (BGP_VPNV6_NODE, &vtysh_quit_bgpd_cmd);
Lou Bergera3fda882016-01-12 13:42:04 -05002430 install_element (BGP_ENCAP_NODE, &vtysh_exit_bgpd_cmd);
2431 install_element (BGP_ENCAP_NODE, &vtysh_quit_bgpd_cmd);
2432 install_element (BGP_ENCAPV6_NODE, &vtysh_exit_bgpd_cmd);
2433 install_element (BGP_ENCAPV6_NODE, &vtysh_quit_bgpd_cmd);
paul718e3742002-12-13 20:15:29 +00002434 install_element (BGP_IPV4_NODE, &vtysh_exit_bgpd_cmd);
2435 install_element (BGP_IPV4_NODE, &vtysh_quit_bgpd_cmd);
2436 install_element (BGP_IPV4M_NODE, &vtysh_exit_bgpd_cmd);
2437 install_element (BGP_IPV4M_NODE, &vtysh_quit_bgpd_cmd);
2438 install_element (BGP_IPV6_NODE, &vtysh_exit_bgpd_cmd);
2439 install_element (BGP_IPV6_NODE, &vtysh_quit_bgpd_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002440 install_element (BGP_IPV6M_NODE, &vtysh_exit_bgpd_cmd);
2441 install_element (BGP_IPV6M_NODE, &vtysh_quit_bgpd_cmd);
hassoc25e4582003-12-23 10:39:08 +00002442 install_element (ISIS_NODE, &vtysh_exit_isisd_cmd);
2443 install_element (ISIS_NODE, &vtysh_quit_isisd_cmd);
paul718e3742002-12-13 20:15:29 +00002444 install_element (KEYCHAIN_NODE, &vtysh_exit_ripd_cmd);
2445 install_element (KEYCHAIN_NODE, &vtysh_quit_ripd_cmd);
2446 install_element (KEYCHAIN_KEY_NODE, &vtysh_exit_ripd_cmd);
2447 install_element (KEYCHAIN_KEY_NODE, &vtysh_quit_ripd_cmd);
2448 install_element (RMAP_NODE, &vtysh_exit_rmap_cmd);
2449 install_element (RMAP_NODE, &vtysh_quit_rmap_cmd);
hassoe7168df2004-10-03 20:11:32 +00002450 install_element (VTY_NODE, &vtysh_exit_line_vty_cmd);
2451 install_element (VTY_NODE, &vtysh_quit_line_vty_cmd);
paul718e3742002-12-13 20:15:29 +00002452
2453 /* "end" command. */
2454 install_element (CONFIG_NODE, &vtysh_end_all_cmd);
2455 install_element (ENABLE_NODE, &vtysh_end_all_cmd);
2456 install_element (RIP_NODE, &vtysh_end_all_cmd);
2457 install_element (RIPNG_NODE, &vtysh_end_all_cmd);
2458 install_element (OSPF_NODE, &vtysh_end_all_cmd);
2459 install_element (OSPF6_NODE, &vtysh_end_all_cmd);
Juliusz Chroboczekfeb6c532012-02-07 04:58:49 +01002460 install_element (BABEL_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002461 install_element (BGP_NODE, &vtysh_end_all_cmd);
2462 install_element (BGP_IPV4_NODE, &vtysh_end_all_cmd);
2463 install_element (BGP_IPV4M_NODE, &vtysh_end_all_cmd);
2464 install_element (BGP_VPNV4_NODE, &vtysh_end_all_cmd);
Lou Berger13c378d2016-01-12 13:41:56 -05002465 install_element (BGP_VPNV6_NODE, &vtysh_end_all_cmd);
Lou Bergera3fda882016-01-12 13:42:04 -05002466 install_element (BGP_ENCAP_NODE, &vtysh_end_all_cmd);
2467 install_element (BGP_ENCAPV6_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002468 install_element (BGP_IPV6_NODE, &vtysh_end_all_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002469 install_element (BGP_IPV6M_NODE, &vtysh_end_all_cmd);
hassoc25e4582003-12-23 10:39:08 +00002470 install_element (ISIS_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002471 install_element (KEYCHAIN_NODE, &vtysh_end_all_cmd);
2472 install_element (KEYCHAIN_KEY_NODE, &vtysh_end_all_cmd);
2473 install_element (RMAP_NODE, &vtysh_end_all_cmd);
hassoe7168df2004-10-03 20:11:32 +00002474 install_element (VTY_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002475
paul338a9912003-03-01 15:44:10 +00002476 install_element (INTERFACE_NODE, &interface_desc_cmd);
paul464dc8d2003-03-28 02:25:45 +00002477 install_element (INTERFACE_NODE, &no_interface_desc_cmd);
paul718e3742002-12-13 20:15:29 +00002478 install_element (INTERFACE_NODE, &vtysh_end_all_cmd);
2479 install_element (INTERFACE_NODE, &vtysh_exit_interface_cmd);
2480 install_element (INTERFACE_NODE, &vtysh_quit_interface_cmd);
2481 install_element (CONFIG_NODE, &router_rip_cmd);
2482#ifdef HAVE_IPV6
2483 install_element (CONFIG_NODE, &router_ripng_cmd);
2484#endif
2485 install_element (CONFIG_NODE, &router_ospf_cmd);
2486#ifdef HAVE_IPV6
2487 install_element (CONFIG_NODE, &router_ospf6_cmd);
2488#endif
hassoc25e4582003-12-23 10:39:08 +00002489 install_element (CONFIG_NODE, &router_isis_cmd);
paul718e3742002-12-13 20:15:29 +00002490 install_element (CONFIG_NODE, &router_bgp_cmd);
Paul Jakma10895fd2008-07-03 19:34:48 +00002491 install_element (CONFIG_NODE, &router_bgp_view_cmd);
paul718e3742002-12-13 20:15:29 +00002492 install_element (BGP_NODE, &address_family_vpnv4_cmd);
2493 install_element (BGP_NODE, &address_family_vpnv4_unicast_cmd);
Lou Berger13c378d2016-01-12 13:41:56 -05002494 install_element (BGP_NODE, &address_family_vpnv6_cmd);
2495 install_element (BGP_NODE, &address_family_vpnv6_unicast_cmd);
Lou Bergera3fda882016-01-12 13:42:04 -05002496 install_element (BGP_NODE, &address_family_encap_cmd);
2497 install_element (BGP_NODE, &address_family_encapv6_cmd);
paul718e3742002-12-13 20:15:29 +00002498 install_element (BGP_NODE, &address_family_ipv4_unicast_cmd);
2499 install_element (BGP_NODE, &address_family_ipv4_multicast_cmd);
2500#ifdef HAVE_IPV6
2501 install_element (BGP_NODE, &address_family_ipv6_cmd);
2502 install_element (BGP_NODE, &address_family_ipv6_unicast_cmd);
2503#endif
2504 install_element (BGP_VPNV4_NODE, &exit_address_family_cmd);
Lou Berger13c378d2016-01-12 13:41:56 -05002505 install_element (BGP_VPNV6_NODE, &exit_address_family_cmd);
Lou Bergera3fda882016-01-12 13:42:04 -05002506 install_element (BGP_ENCAP_NODE, &exit_address_family_cmd);
2507 install_element (BGP_ENCAPV6_NODE, &exit_address_family_cmd);
paul718e3742002-12-13 20:15:29 +00002508 install_element (BGP_IPV4_NODE, &exit_address_family_cmd);
2509 install_element (BGP_IPV4M_NODE, &exit_address_family_cmd);
2510 install_element (BGP_IPV6_NODE, &exit_address_family_cmd);
paul57b5b7e2005-08-22 22:44:29 +00002511 install_element (BGP_IPV6M_NODE, &exit_address_family_cmd);
paul718e3742002-12-13 20:15:29 +00002512 install_element (CONFIG_NODE, &key_chain_cmd);
2513 install_element (CONFIG_NODE, &route_map_cmd);
hassoe7168df2004-10-03 20:11:32 +00002514 install_element (CONFIG_NODE, &vtysh_line_vty_cmd);
paul718e3742002-12-13 20:15:29 +00002515 install_element (KEYCHAIN_NODE, &key_cmd);
2516 install_element (KEYCHAIN_NODE, &key_chain_cmd);
2517 install_element (KEYCHAIN_KEY_NODE, &key_chain_cmd);
2518 install_element (CONFIG_NODE, &vtysh_interface_cmd);
paul32d24632003-05-23 09:25:20 +00002519 install_element (CONFIG_NODE, &vtysh_no_interface_cmd);
Feng Lu471ea392015-05-22 11:40:00 +02002520 install_element (CONFIG_NODE, &vtysh_interface_vrf_cmd);
2521 install_element (CONFIG_NODE, &vtysh_no_interface_vrf_cmd);
paul718e3742002-12-13 20:15:29 +00002522 install_element (ENABLE_NODE, &vtysh_show_running_config_cmd);
Donald Sharp9fb73e82015-09-22 11:13:12 -04002523 install_element (ENABLE_NODE, &vtysh_show_running_config_daemon_cmd);
paul718e3742002-12-13 20:15:29 +00002524 install_element (ENABLE_NODE, &vtysh_copy_runningconfig_startupconfig_cmd);
2525 install_element (ENABLE_NODE, &vtysh_write_file_cmd);
hasso4a6e2252003-05-25 11:51:29 +00002526 install_element (ENABLE_NODE, &vtysh_write_cmd);
paul718e3742002-12-13 20:15:29 +00002527
hasso95e735b2004-08-26 13:08:30 +00002528 /* "write terminal" command. */
paul718e3742002-12-13 20:15:29 +00002529 install_element (ENABLE_NODE, &vtysh_write_terminal_cmd);
Donald Sharp9fb73e82015-09-22 11:13:12 -04002530 install_element (ENABLE_NODE, &vtysh_write_terminal_daemon_cmd);
hassoe7168df2004-10-03 20:11:32 +00002531
2532 install_element (CONFIG_NODE, &vtysh_integrated_config_cmd);
2533 install_element (CONFIG_NODE, &no_vtysh_integrated_config_cmd);
paul718e3742002-12-13 20:15:29 +00002534
hasso95e735b2004-08-26 13:08:30 +00002535 /* "write memory" command. */
paul718e3742002-12-13 20:15:29 +00002536 install_element (ENABLE_NODE, &vtysh_write_memory_cmd);
paul718e3742002-12-13 20:15:29 +00002537
hasso34553cc2004-08-27 13:56:39 +00002538 install_element (VIEW_NODE, &vtysh_terminal_length_cmd);
2539 install_element (ENABLE_NODE, &vtysh_terminal_length_cmd);
2540 install_element (VIEW_NODE, &vtysh_terminal_no_length_cmd);
2541 install_element (ENABLE_NODE, &vtysh_terminal_no_length_cmd);
hassof2799e62004-10-28 17:43:11 +00002542 install_element (VIEW_NODE, &vtysh_show_daemons_cmd);
2543 install_element (ENABLE_NODE, &vtysh_show_daemons_cmd);
hasso34553cc2004-08-27 13:56:39 +00002544
paul718e3742002-12-13 20:15:29 +00002545 install_element (VIEW_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002546 install_element (VIEW_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00002547 install_element (VIEW_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002548 install_element (VIEW_NODE, &vtysh_traceroute_ip_cmd);
2549#ifdef HAVE_IPV6
2550 install_element (VIEW_NODE, &vtysh_ping6_cmd);
2551 install_element (VIEW_NODE, &vtysh_traceroute6_cmd);
2552#endif
paul718e3742002-12-13 20:15:29 +00002553 install_element (VIEW_NODE, &vtysh_telnet_cmd);
2554 install_element (VIEW_NODE, &vtysh_telnet_port_cmd);
paul5087df52003-01-25 06:56:09 +00002555 install_element (VIEW_NODE, &vtysh_ssh_cmd);
paul718e3742002-12-13 20:15:29 +00002556 install_element (ENABLE_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002557 install_element (ENABLE_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00002558 install_element (ENABLE_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002559 install_element (ENABLE_NODE, &vtysh_traceroute_ip_cmd);
2560#ifdef HAVE_IPV6
2561 install_element (ENABLE_NODE, &vtysh_ping6_cmd);
2562 install_element (ENABLE_NODE, &vtysh_traceroute6_cmd);
2563#endif
paul718e3742002-12-13 20:15:29 +00002564 install_element (ENABLE_NODE, &vtysh_telnet_cmd);
2565 install_element (ENABLE_NODE, &vtysh_telnet_port_cmd);
hasso67e29ab2004-08-26 22:21:31 +00002566 install_element (ENABLE_NODE, &vtysh_ssh_cmd);
paul718e3742002-12-13 20:15:29 +00002567 install_element (ENABLE_NODE, &vtysh_start_shell_cmd);
2568 install_element (ENABLE_NODE, &vtysh_start_bash_cmd);
2569 install_element (ENABLE_NODE, &vtysh_start_zsh_cmd);
Paul Jakmadbf7d132006-05-23 22:10:01 +00002570
Paul Jakma362b4032006-05-28 07:54:45 +00002571 install_element (VIEW_NODE, &vtysh_show_memory_cmd);
2572 install_element (ENABLE_NODE, &vtysh_show_memory_cmd);
2573
Donald Sharp567a6382015-08-19 21:22:17 -04002574 install_element (VIEW_NODE, &vtysh_show_work_queues_cmd);
2575 install_element (ENABLE_NODE, &vtysh_show_work_queues_cmd);
2576
2577 install_element (VIEW_NODE, &vtysh_show_thread_cmd);
2578 install_element (ENABLE_NODE, &vtysh_show_thread_cmd);
2579
Paul Jakmadbf7d132006-05-23 22:10:01 +00002580 /* Logging */
2581 install_element (ENABLE_NODE, &vtysh_show_logging_cmd);
2582 install_element (VIEW_NODE, &vtysh_show_logging_cmd);
paul718e3742002-12-13 20:15:29 +00002583 install_element (CONFIG_NODE, &vtysh_log_stdout_cmd);
ajs274a4a42004-12-07 15:39:31 +00002584 install_element (CONFIG_NODE, &vtysh_log_stdout_level_cmd);
paul718e3742002-12-13 20:15:29 +00002585 install_element (CONFIG_NODE, &no_vtysh_log_stdout_cmd);
2586 install_element (CONFIG_NODE, &vtysh_log_file_cmd);
ajs274a4a42004-12-07 15:39:31 +00002587 install_element (CONFIG_NODE, &vtysh_log_file_level_cmd);
paul718e3742002-12-13 20:15:29 +00002588 install_element (CONFIG_NODE, &no_vtysh_log_file_cmd);
ajs274a4a42004-12-07 15:39:31 +00002589 install_element (CONFIG_NODE, &no_vtysh_log_file_level_cmd);
2590 install_element (CONFIG_NODE, &vtysh_log_monitor_cmd);
2591 install_element (CONFIG_NODE, &vtysh_log_monitor_level_cmd);
2592 install_element (CONFIG_NODE, &no_vtysh_log_monitor_cmd);
paul718e3742002-12-13 20:15:29 +00002593 install_element (CONFIG_NODE, &vtysh_log_syslog_cmd);
ajs274a4a42004-12-07 15:39:31 +00002594 install_element (CONFIG_NODE, &vtysh_log_syslog_level_cmd);
paul718e3742002-12-13 20:15:29 +00002595 install_element (CONFIG_NODE, &no_vtysh_log_syslog_cmd);
2596 install_element (CONFIG_NODE, &vtysh_log_trap_cmd);
2597 install_element (CONFIG_NODE, &no_vtysh_log_trap_cmd);
ajs274a4a42004-12-07 15:39:31 +00002598 install_element (CONFIG_NODE, &vtysh_log_facility_cmd);
2599 install_element (CONFIG_NODE, &no_vtysh_log_facility_cmd);
paul718e3742002-12-13 20:15:29 +00002600 install_element (CONFIG_NODE, &vtysh_log_record_priority_cmd);
2601 install_element (CONFIG_NODE, &no_vtysh_log_record_priority_cmd);
Andrew J. Schorrc749b722007-04-29 03:53:31 +00002602 install_element (CONFIG_NODE, &vtysh_log_timestamp_precision_cmd);
2603 install_element (CONFIG_NODE, &no_vtysh_log_timestamp_precision_cmd);
hassoe7168df2004-10-03 20:11:32 +00002604
2605 install_element (CONFIG_NODE, &vtysh_service_password_encrypt_cmd);
2606 install_element (CONFIG_NODE, &no_vtysh_service_password_encrypt_cmd);
2607
2608 install_element (CONFIG_NODE, &vtysh_password_cmd);
2609 install_element (CONFIG_NODE, &vtysh_password_text_cmd);
2610 install_element (CONFIG_NODE, &vtysh_enable_password_cmd);
2611 install_element (CONFIG_NODE, &vtysh_enable_password_text_cmd);
2612 install_element (CONFIG_NODE, &no_vtysh_enable_password_cmd);
2613
paul718e3742002-12-13 20:15:29 +00002614}