blob: a9929c5257119b17269f9be2042e0303fe2c7dd9 [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"
paul718e3742002-12-13 20:15:29 +000037
38/* Struct VTY. */
39struct vty *vty;
40
41/* VTY shell pager name. */
42char *vtysh_pager_name = NULL;
43
44/* VTY shell client structure. */
45struct vtysh_client
46{
47 int fd;
48} vtysh_client[VTYSH_INDEX_MAX];
hassob094d262004-08-25 12:22:00 +000049
hassoe7168df2004-10-03 20:11:32 +000050/* Using integrated config from Quagga.conf. Default is no. */
51int vtysh_writeconfig_integrated = 0;
52
53extern char config_default[];
54
ajs274a4a42004-12-07 15:39:31 +000055static void
paul718e3742002-12-13 20:15:29 +000056vclient_close (struct vtysh_client *vclient)
57{
58 if (vclient->fd > 0)
59 close (vclient->fd);
60 vclient->fd = -1;
61}
62
paul718e3742002-12-13 20:15:29 +000063/* Following filled with debug code to trace a problematic condition
hasso95e735b2004-08-26 13:08:30 +000064 * under load - it SHOULD handle it. */
paul718e3742002-12-13 20:15:29 +000065#define ERR_WHERE_STRING "vtysh(): vtysh_client_config(): "
ajs274a4a42004-12-07 15:39:31 +000066static int
paul718e3742002-12-13 20:15:29 +000067vtysh_client_config (struct vtysh_client *vclient, char *line)
68{
69 int ret;
70 char *buf;
71 size_t bufsz;
72 char *pbuf;
73 size_t left;
74 char *eoln;
75 int nbytes;
76 int i;
77 int readln;
78
79 if (vclient->fd < 0)
80 return CMD_SUCCESS;
81
82 ret = write (vclient->fd, line, strlen (line) + 1);
83 if (ret <= 0)
84 {
85 vclient_close (vclient);
86 return CMD_SUCCESS;
87 }
88
hasso95e735b2004-08-26 13:08:30 +000089 /* Allow enough room for buffer to read more than a few pages from socket. */
paule3d29b52003-01-23 18:05:42 +000090 bufsz = 5 * getpagesize() + 1;
paul718e3742002-12-13 20:15:29 +000091 buf = XMALLOC(MTYPE_TMP, bufsz);
92 memset(buf, 0, bufsz);
93 pbuf = buf;
94
95 while (1)
96 {
97 if (pbuf >= ((buf + bufsz) -1))
98 {
99 fprintf (stderr, ERR_WHERE_STRING \
100 "warning - pbuf beyond buffer end.\n");
101 return CMD_WARNING;
102 }
103
104 readln = (buf + bufsz) - pbuf - 1;
105 nbytes = read (vclient->fd, pbuf, readln);
106
107 if (nbytes <= 0)
108 {
109
110 if (errno == EINTR)
111 continue;
112
113 fprintf(stderr, ERR_WHERE_STRING "(%u)", errno);
114 perror("");
115
116 if (errno == EAGAIN || errno == EIO)
117 continue;
118
119 vclient_close (vclient);
120 XFREE(MTYPE_TMP, buf);
121 return CMD_SUCCESS;
122 }
123
124 pbuf[nbytes] = '\0';
125
126 if (nbytes >= 4)
127 {
128 i = nbytes - 4;
129 if (pbuf[i] == '\0' && pbuf[i + 1] == '\0' && pbuf[i + 2] == '\0')
130 {
131 ret = pbuf[i + 3];
132 break;
133 }
134 }
135 pbuf += nbytes;
136
137 /* See if a line exists in buffer, if so parse and consume it, and
hasso95e735b2004-08-26 13:08:30 +0000138 * reset read position. */
paul718e3742002-12-13 20:15:29 +0000139 if ((eoln = strrchr(buf, '\n')) == NULL)
140 continue;
141
142 if (eoln >= ((buf + bufsz) - 1))
143 {
144 fprintf (stderr, ERR_WHERE_STRING \
145 "warning - eoln beyond buffer end.\n");
146 }
147 vtysh_config_parse(buf);
148
149 eoln++;
150 left = (size_t)(buf + bufsz - eoln);
151 memmove(buf, eoln, left);
152 buf[bufsz-1] = '\0';
153 pbuf = buf + strlen(buf);
154 }
155
hasso95e735b2004-08-26 13:08:30 +0000156 /* Parse anything left in the buffer. */
hassoe7168df2004-10-03 20:11:32 +0000157
paul718e3742002-12-13 20:15:29 +0000158 vtysh_config_parse (buf);
159
160 XFREE(MTYPE_TMP, buf);
161 return ret;
162}
163
ajs274a4a42004-12-07 15:39:31 +0000164static int
hassodda09522004-10-07 21:40:25 +0000165vtysh_client_execute (struct vtysh_client *vclient, const char *line, FILE *fp)
paul718e3742002-12-13 20:15:29 +0000166{
167 int ret;
168 char buf[1001];
169 int nbytes;
paul2852de12004-09-17 06:52:16 +0000170 int i;
171 int numnulls = 0;
paul718e3742002-12-13 20:15:29 +0000172
173 if (vclient->fd < 0)
174 return CMD_SUCCESS;
175
176 ret = write (vclient->fd, line, strlen (line) + 1);
177 if (ret <= 0)
178 {
179 vclient_close (vclient);
180 return CMD_SUCCESS;
181 }
182
183 while (1)
184 {
185 nbytes = read (vclient->fd, buf, sizeof(buf)-1);
186
187 if (nbytes <= 0 && errno != EINTR)
188 {
189 vclient_close (vclient);
190 return CMD_SUCCESS;
191 }
192
193 if (nbytes > 0)
194 {
ajs85fb1e62004-11-11 14:03:39 +0000195 if ((numnulls == 3) && (nbytes == 1))
196 return buf[0];
197
paul718e3742002-12-13 20:15:29 +0000198 buf[nbytes] = '\0';
ajs85fb1e62004-11-11 14:03:39 +0000199 fputs (buf, fp);
paul718e3742002-12-13 20:15:29 +0000200 fflush (fp);
paul2852de12004-09-17 06:52:16 +0000201
paul0921d482004-10-11 18:21:55 +0000202 /* check for trailling \0\0\0<ret code>,
203 * even if split across reads
204 * (see lib/vty.c::vtysh_read)
205 */
paul2852de12004-09-17 06:52:16 +0000206 if (nbytes >= 4)
207 {
208 i = nbytes-4;
209 numnulls = 0;
210 }
211 else
212 i = 0;
213
paul0921d482004-10-11 18:21:55 +0000214 while (i < nbytes && numnulls < 3)
paul2852de12004-09-17 06:52:16 +0000215 {
216 if (buf[i++] == '\0')
217 numnulls++;
218 else
ajs85fb1e62004-11-11 14:03:39 +0000219 numnulls = 0;
paul2852de12004-09-17 06:52:16 +0000220 }
paul718e3742002-12-13 20:15:29 +0000221
ajs85fb1e62004-11-11 14:03:39 +0000222 /* got 3 or more trailing NULs? */
223 if ((numnulls >= 3) && (i < nbytes))
paul0921d482004-10-11 18:21:55 +0000224 return (buf[nbytes-1]);
paul718e3742002-12-13 20:15:29 +0000225 }
226 }
paul718e3742002-12-13 20:15:29 +0000227}
228
229void
230vtysh_exit_ripd_only ()
231{
232 vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIP], "exit", stdout);
233}
234
235
236void
237vtysh_pager_init ()
238{
hasso5a9c53d2004-08-27 14:23:28 +0000239 char *pager_defined;
240
241 pager_defined = getenv ("VTYSH_PAGER");
242
243 if (pager_defined)
244 vtysh_pager_name = strdup (pager_defined);
245 else
hasso34553cc2004-08-27 13:56:39 +0000246 vtysh_pager_name = strdup ("more");
paul718e3742002-12-13 20:15:29 +0000247}
248
249/* Command execution over the vty interface. */
ajs274a4a42004-12-07 15:39:31 +0000250static void
hassodda09522004-10-07 21:40:25 +0000251vtysh_execute_func (const char *line, int pager)
paul718e3742002-12-13 20:15:29 +0000252{
253 int ret, cmd_stat;
254 vector vline;
255 struct cmd_element *cmd;
256 FILE *fp = NULL;
hasso13bfca72005-01-23 21:42:25 +0000257 int closepager = 0;
258 int tried = 0;
259 int saved_ret, saved_node;
paul718e3742002-12-13 20:15:29 +0000260
hasso95e735b2004-08-26 13:08:30 +0000261 /* Split readline string up into the vector. */
paul718e3742002-12-13 20:15:29 +0000262 vline = cmd_make_strvec (line);
263
264 if (vline == NULL)
265 return;
266
hasso13bfca72005-01-23 21:42:25 +0000267 saved_ret = ret = cmd_execute_command (vline, vty, &cmd, 1);
268 saved_node = vty->node;
269
270 /* If command doesn't succeeded in current node, try to walk up in node tree.
271 * Changing vty->node is enough to try it just out without actual walkup in
272 * the vtysh. */
273 while (ret != CMD_SUCCESS && ret != CMD_SUCCESS_DAEMON && ret != CMD_WARNING
274 && vty->node > CONFIG_NODE)
275 {
276 vty->node = node_parent(vty->node);
277 ret = cmd_execute_command (vline, vty, &cmd, 1);
278 tried++;
279 }
280
281 vty->node = saved_node;
282
283 /* If command succeeded in any other node than current (tried > 0) we have
284 * to move into node in the vtysh where it succeeded. */
285 if (ret == CMD_SUCCESS || ret == CMD_SUCCESS_DAEMON || ret == CMD_WARNING)
286 {
287 if ((saved_node == BGP_VPNV4_NODE || saved_node == BGP_IPV4_NODE
288 || saved_node == BGP_IPV6_NODE || saved_node == BGP_IPV4M_NODE)
289 && (tried == 1))
290 {
291 vtysh_execute("exit-address-family");
292 }
293 else if ((saved_node == KEYCHAIN_KEY_NODE) && (tried == 1))
294 {
295 vtysh_execute("exit");
296 }
297 else if (tried)
298 {
299 vtysh_execute ("end");
300 vtysh_execute ("configure terminal");
301 }
302 }
303 /* If command didn't succeed in any node, continue with return value from
304 * first try. */
305 else if (tried)
306 {
307 ret = saved_ret;
308 }
paul718e3742002-12-13 20:15:29 +0000309
310 cmd_free_strvec (vline);
311
312 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 {
348 cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ZEBRA],
349 line, fp);
350 if (cmd_stat != CMD_WARNING)
351 cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIP],
352 line, fp);
353 if (cmd_stat != CMD_WARNING)
hasso95e735b2004-08-26 13:08:30 +0000354 cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIPNG],
355 line, fp);
paul718e3742002-12-13 20:15:29 +0000356 if (cmd_stat != CMD_WARNING)
357 cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF],
358 line, fp);
359 if (cmd_stat != CMD_WARNING)
hasso95e735b2004-08-26 13:08:30 +0000360 cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF6],
361 line, fp);
paul718e3742002-12-13 20:15:29 +0000362 if (cmd_stat != CMD_WARNING)
363 cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_BGP],
364 line, fp);
hassob094d262004-08-25 12:22:00 +0000365 if (cmd_stat != CMD_WARNING)
hasso95e735b2004-08-26 13:08:30 +0000366 cmd_stat = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ISIS],
367 line, fp);
paul718e3742002-12-13 20:15:29 +0000368 if (cmd_stat)
369 {
hassob094d262004-08-25 12:22:00 +0000370 line = "end";
371 vline = cmd_make_strvec (line);
paul718e3742002-12-13 20:15:29 +0000372
hassob094d262004-08-25 12:22:00 +0000373 if (vline == NULL)
paul718e3742002-12-13 20:15:29 +0000374 {
paula805cc22003-05-01 14:29:48 +0000375 if (pager && vtysh_pager_name && fp && closepager)
paul718e3742002-12-13 20:15:29 +0000376 {
377 if (pclose (fp) == -1)
378 {
paula805cc22003-05-01 14:29:48 +0000379 perror ("pclose failed for pager");
paul718e3742002-12-13 20:15:29 +0000380 }
381 fp = NULL;
382 }
383 return;
384 }
385
hasso87d683b2005-01-16 23:31:54 +0000386 ret = cmd_execute_command (vline, vty, &cmd, 1);
hassob094d262004-08-25 12:22:00 +0000387 cmd_free_strvec (vline);
388 if (ret != CMD_SUCCESS_DAEMON)
389 break;
paul718e3742002-12-13 20:15:29 +0000390 }
391 else
392 if (cmd->func)
393 {
394 (*cmd->func) (cmd, vty, 0, NULL);
395 break;
hassob094d262004-08-25 12:22:00 +0000396 }
paul718e3742002-12-13 20:15:29 +0000397 }
398
399 if (cmd->daemon & VTYSH_ZEBRA)
400 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ZEBRA], line, fp)
401 != CMD_SUCCESS)
402 break;
403 if (cmd->daemon & VTYSH_RIPD)
404 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIP], line, fp)
405 != CMD_SUCCESS)
406 break;
407 if (cmd->daemon & VTYSH_RIPNGD)
408 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIPNG], line, fp)
409 != CMD_SUCCESS)
410 break;
411 if (cmd->daemon & VTYSH_OSPFD)
412 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF], line, fp)
413 != CMD_SUCCESS)
414 break;
415 if (cmd->daemon & VTYSH_OSPF6D)
416 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF6], line, fp)
417 != CMD_SUCCESS)
418 break;
419 if (cmd->daemon & VTYSH_BGPD)
420 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_BGP], line, fp)
421 != CMD_SUCCESS)
422 break;
hassob094d262004-08-25 12:22:00 +0000423 if (cmd->daemon & VTYSH_ISISD)
424 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ISIS], line, fp)
425 != CMD_SUCCESS)
426 break;
paul718e3742002-12-13 20:15:29 +0000427 if (cmd->func)
428 (*cmd->func) (cmd, vty, 0, NULL);
429 }
430 }
paula805cc22003-05-01 14:29:48 +0000431 if (pager && vtysh_pager_name && fp && closepager)
paul718e3742002-12-13 20:15:29 +0000432 {
433 if (pclose (fp) == -1)
434 {
paula805cc22003-05-01 14:29:48 +0000435 perror ("pclose failed for pager");
paul718e3742002-12-13 20:15:29 +0000436 }
437 fp = NULL;
438 }
439}
440
441void
hassodda09522004-10-07 21:40:25 +0000442vtysh_execute_no_pager (const char *line)
paul718e3742002-12-13 20:15:29 +0000443{
444 vtysh_execute_func (line, 0);
445}
446
447void
hassodda09522004-10-07 21:40:25 +0000448vtysh_execute (const char *line)
paul718e3742002-12-13 20:15:29 +0000449{
450 vtysh_execute_func (line, 1);
451}
452
453/* Configration make from file. */
454int
455vtysh_config_from_file (struct vty *vty, FILE *fp)
456{
457 int ret;
458 vector vline;
459 struct cmd_element *cmd;
460
461 while (fgets (vty->buf, VTY_BUFSIZ, fp))
462 {
463 if (vty->buf[0] == '!' || vty->buf[1] == '#')
464 continue;
465
466 vline = cmd_make_strvec (vty->buf);
467
hasso95e735b2004-08-26 13:08:30 +0000468 /* In case of comment line. */
paul718e3742002-12-13 20:15:29 +0000469 if (vline == NULL)
470 continue;
471
hasso95e735b2004-08-26 13:08:30 +0000472 /* Execute configuration command : this is strict match. */
paul718e3742002-12-13 20:15:29 +0000473 ret = cmd_execute_command_strict (vline, vty, &cmd);
474
hasso95e735b2004-08-26 13:08:30 +0000475 /* Try again with setting node to CONFIG_NODE. */
paul718e3742002-12-13 20:15:29 +0000476 if (ret != CMD_SUCCESS
477 && ret != CMD_SUCCESS_DAEMON
478 && ret != CMD_WARNING)
479 {
480 if (vty->node == KEYCHAIN_KEY_NODE)
481 {
482 vty->node = KEYCHAIN_NODE;
483 vtysh_exit_ripd_only ();
484 ret = cmd_execute_command_strict (vline, vty, &cmd);
485
486 if (ret != CMD_SUCCESS
487 && ret != CMD_SUCCESS_DAEMON
488 && ret != CMD_WARNING)
489 {
490 vtysh_exit_ripd_only ();
491 vty->node = CONFIG_NODE;
492 ret = cmd_execute_command_strict (vline, vty, &cmd);
493 }
494 }
495 else
496 {
497 vtysh_execute ("end");
498 vtysh_execute ("configure terminal");
499 vty->node = CONFIG_NODE;
500 ret = cmd_execute_command_strict (vline, vty, &cmd);
501 }
502 }
503
504 cmd_free_strvec (vline);
505
506 switch (ret)
507 {
508 case CMD_WARNING:
509 if (vty->type == VTY_FILE)
paul4fc01e62002-12-13 20:49:00 +0000510 fprintf (stdout,"Warning...\n");
paul718e3742002-12-13 20:15:29 +0000511 break;
512 case CMD_ERR_AMBIGUOUS:
paul4fc01e62002-12-13 20:49:00 +0000513 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000514 break;
515 case CMD_ERR_NO_MATCH:
paul4fc01e62002-12-13 20:49:00 +0000516 fprintf (stdout,"%% Unknown command: %s", vty->buf);
paul718e3742002-12-13 20:15:29 +0000517 break;
518 case CMD_ERR_INCOMPLETE:
paul4fc01e62002-12-13 20:49:00 +0000519 fprintf (stdout,"%% Command incomplete.\n");
paul718e3742002-12-13 20:15:29 +0000520 break;
521 case CMD_SUCCESS_DAEMON:
522 {
523 if (cmd->daemon & VTYSH_ZEBRA)
524 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ZEBRA],
525 vty->buf, stdout) != CMD_SUCCESS)
526 break;
527 if (cmd->daemon & VTYSH_RIPD)
528 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIP],
529 vty->buf, stdout) != CMD_SUCCESS)
530 break;
531 if (cmd->daemon & VTYSH_RIPNGD)
532 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIPNG],
533 vty->buf, stdout) != CMD_SUCCESS)
534 break;
535 if (cmd->daemon & VTYSH_OSPFD)
536 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF],
537 vty->buf, stdout) != CMD_SUCCESS)
538 break;
539 if (cmd->daemon & VTYSH_OSPF6D)
540 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF6],
541 vty->buf, stdout) != CMD_SUCCESS)
542 break;
543 if (cmd->daemon & VTYSH_BGPD)
544 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_BGP],
545 vty->buf, stdout) != CMD_SUCCESS)
546 break;
hassob094d262004-08-25 12:22:00 +0000547 if (cmd->daemon & VTYSH_ISISD)
548 if (vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ISIS],
549 vty->buf, stdout) != CMD_SUCCESS)
550 break;
paul718e3742002-12-13 20:15:29 +0000551 if (cmd->func)
552 (*cmd->func) (cmd, vty, 0, NULL);
553 }
554 }
555 }
556 return CMD_SUCCESS;
557}
558
559/* We don't care about the point of the cursor when '?' is typed. */
560int
561vtysh_rl_describe ()
562{
563 int ret;
hassodda09522004-10-07 21:40:25 +0000564 unsigned int i;
paul718e3742002-12-13 20:15:29 +0000565 vector vline;
566 vector describe;
567 int width;
568 struct desc *desc;
569
570 vline = cmd_make_strvec (rl_line_buffer);
571
572 /* In case of '> ?'. */
573 if (vline == NULL)
574 {
575 vline = vector_init (1);
576 vector_set (vline, '\0');
577 }
578 else
579 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
580 vector_set (vline, '\0');
581
582 describe = cmd_describe_command (vline, vty, &ret);
583
paul4fc01e62002-12-13 20:49:00 +0000584 fprintf (stdout,"\n");
paul718e3742002-12-13 20:15:29 +0000585
586 /* Ambiguous and no match error. */
587 switch (ret)
588 {
589 case CMD_ERR_AMBIGUOUS:
590 cmd_free_strvec (vline);
paul4fc01e62002-12-13 20:49:00 +0000591 fprintf (stdout,"%% Ambiguous command.\n");
paul718e3742002-12-13 20:15:29 +0000592 rl_on_new_line ();
593 return 0;
594 break;
595 case CMD_ERR_NO_MATCH:
596 cmd_free_strvec (vline);
paul4fc01e62002-12-13 20:49:00 +0000597 fprintf (stdout,"%% There is no matched command.\n");
paul718e3742002-12-13 20:15:29 +0000598 rl_on_new_line ();
599 return 0;
600 break;
601 }
602
603 /* Get width of command string. */
604 width = 0;
605 for (i = 0; i < vector_max (describe); i++)
606 if ((desc = vector_slot (describe, i)) != NULL)
607 {
608 int len;
609
610 if (desc->cmd[0] == '\0')
611 continue;
612
613 len = strlen (desc->cmd);
614 if (desc->cmd[0] == '.')
615 len--;
616
617 if (width < len)
618 width = len;
619 }
620
621 for (i = 0; i < vector_max (describe); i++)
622 if ((desc = vector_slot (describe, i)) != NULL)
623 {
624 if (desc->cmd[0] == '\0')
625 continue;
626
627 if (! desc->str)
paul4fc01e62002-12-13 20:49:00 +0000628 fprintf (stdout," %-s\n",
hassob094d262004-08-25 12:22:00 +0000629 desc->cmd[0] == '.' ? desc->cmd + 1 : desc->cmd);
paul718e3742002-12-13 20:15:29 +0000630 else
paul4fc01e62002-12-13 20:49:00 +0000631 fprintf (stdout," %-*s %s\n",
hassob094d262004-08-25 12:22:00 +0000632 width,
633 desc->cmd[0] == '.' ? desc->cmd + 1 : desc->cmd,
634 desc->str);
paul718e3742002-12-13 20:15:29 +0000635 }
636
637 cmd_free_strvec (vline);
638 vector_free (describe);
639
640 rl_on_new_line();
641
642 return 0;
643}
644
hasso95e735b2004-08-26 13:08:30 +0000645/* Result of cmd_complete_command() call will be stored here
646 * and used in new_completion() in order to put the space in
647 * correct places only. */
paul718e3742002-12-13 20:15:29 +0000648int complete_status;
649
ajs274a4a42004-12-07 15:39:31 +0000650static char *
pauldfc0d9b2003-04-18 23:55:29 +0000651command_generator (const char *text, int state)
paul718e3742002-12-13 20:15:29 +0000652{
653 vector vline;
654 static char **matched = NULL;
655 static int index = 0;
656
657 /* First call. */
658 if (! state)
659 {
660 index = 0;
661
662 if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
663 return NULL;
664
665 vline = cmd_make_strvec (rl_line_buffer);
666 if (vline == NULL)
667 return NULL;
668
669 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
670 vector_set (vline, '\0');
671
672 matched = cmd_complete_command (vline, vty, &complete_status);
673 }
674
675 if (matched && matched[index])
676 return matched[index++];
677
678 return NULL;
679}
680
ajs274a4a42004-12-07 15:39:31 +0000681static char **
paul718e3742002-12-13 20:15:29 +0000682new_completion (char *text, int start, int end)
683{
684 char **matches;
685
pauldfc0d9b2003-04-18 23:55:29 +0000686 matches = rl_completion_matches (text, command_generator);
paul718e3742002-12-13 20:15:29 +0000687
688 if (matches)
689 {
690 rl_point = rl_end;
691 if (complete_status == CMD_COMPLETE_FULL_MATCH)
692 rl_pending_input = ' ';
693 }
694
695 return matches;
696}
697
ajs274a4a42004-12-07 15:39:31 +0000698#if 0
699/* This function is not actually being used. */
700static char **
paul718e3742002-12-13 20:15:29 +0000701vtysh_completion (char *text, int start, int end)
702{
703 int ret;
704 vector vline;
705 char **matched = NULL;
706
707 if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
708 return NULL;
709
710 vline = cmd_make_strvec (rl_line_buffer);
711 if (vline == NULL)
712 return NULL;
713
714 /* In case of 'help \t'. */
715 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
716 vector_set (vline, '\0');
717
718 matched = cmd_complete_command (vline, vty, &ret);
719
720 cmd_free_strvec (vline);
721
722 return (char **) matched;
723}
ajs274a4a42004-12-07 15:39:31 +0000724#endif
paul718e3742002-12-13 20:15:29 +0000725
hasso95e735b2004-08-26 13:08:30 +0000726/* Vty node structures. */
paul718e3742002-12-13 20:15:29 +0000727struct cmd_node bgp_node =
728{
729 BGP_NODE,
730 "%s(config-router)# ",
731};
732
paul718e3742002-12-13 20:15:29 +0000733struct cmd_node rip_node =
734{
735 RIP_NODE,
736 "%s(config-router)# ",
737};
738
hassoc25e4582003-12-23 10:39:08 +0000739struct cmd_node isis_node =
740{
741 ISIS_NODE,
742 "%s(config-router)# ",
hassoc25e4582003-12-23 10:39:08 +0000743};
744
paul718e3742002-12-13 20:15:29 +0000745struct cmd_node interface_node =
746{
747 INTERFACE_NODE,
748 "%s(config-if)# ",
749};
750
hasso95e735b2004-08-26 13:08:30 +0000751struct cmd_node rmap_node =
752{
753 RMAP_NODE,
754 "%s(config-route-map)# "
755};
756
757struct cmd_node zebra_node =
758{
759 ZEBRA_NODE,
760 "%s(config-router)# "
761};
762
763struct cmd_node bgp_vpnv4_node =
764{
765 BGP_VPNV4_NODE,
766 "%s(config-router-af)# "
767};
768
769struct cmd_node bgp_ipv4_node =
770{
771 BGP_IPV4_NODE,
772 "%s(config-router-af)# "
773};
774
775struct cmd_node bgp_ipv4m_node =
776{
777 BGP_IPV4M_NODE,
778 "%s(config-router-af)# "
779};
780
781struct cmd_node bgp_ipv6_node =
782{
783 BGP_IPV6_NODE,
784 "%s(config-router-af)# "
785};
786
787struct cmd_node ospf_node =
788{
789 OSPF_NODE,
790 "%s(config-router)# "
791};
792
793struct cmd_node ripng_node =
794{
795 RIPNG_NODE,
796 "%s(config-router)# "
797};
798
799struct cmd_node ospf6_node =
800{
801 OSPF6_NODE,
802 "%s(config-ospf6)# "
803};
804
805struct cmd_node keychain_node =
806{
807 KEYCHAIN_NODE,
808 "%s(config-keychain)# "
809};
810
811struct cmd_node keychain_key_node =
812{
813 KEYCHAIN_KEY_NODE,
814 "%s(config-keychain-key)# "
815};
816
hassoe7168df2004-10-03 20:11:32 +0000817/* Defined in lib/vty.c */
818extern struct cmd_node vty_node;
819
hasso95e735b2004-08-26 13:08:30 +0000820/* When '^Z' is received from vty, move down to the enable mode. */
821int
822vtysh_end ()
823{
824 switch (vty->node)
825 {
826 case VIEW_NODE:
827 case ENABLE_NODE:
828 /* Nothing to do. */
829 break;
830 default:
831 vty->node = ENABLE_NODE;
832 break;
833 }
834 return CMD_SUCCESS;
835}
836
837DEFUNSH (VTYSH_ALL,
838 vtysh_end_all,
839 vtysh_end_all_cmd,
840 "end",
hassoe7168df2004-10-03 20:11:32 +0000841 "End current mode and change to enable mode\n")
hasso95e735b2004-08-26 13:08:30 +0000842{
hasso42895462004-09-26 16:25:07 +0000843 return vtysh_end ();
hasso95e735b2004-08-26 13:08:30 +0000844}
845
paul718e3742002-12-13 20:15:29 +0000846DEFUNSH (VTYSH_BGPD,
847 router_bgp,
848 router_bgp_cmd,
849 "router bgp <1-65535>",
850 ROUTER_STR
851 BGP_STR
852 AS_STR)
853{
854 vty->node = BGP_NODE;
855 return CMD_SUCCESS;
856}
857
858DEFUNSH (VTYSH_BGPD,
859 address_family_vpnv4,
860 address_family_vpnv4_cmd,
861 "address-family vpnv4",
862 "Enter Address Family command mode\n"
863 "Address family\n")
864{
865 vty->node = BGP_VPNV4_NODE;
866 return CMD_SUCCESS;
867}
868
869DEFUNSH (VTYSH_BGPD,
870 address_family_vpnv4_unicast,
871 address_family_vpnv4_unicast_cmd,
872 "address-family vpnv4 unicast",
873 "Enter Address Family command mode\n"
874 "Address family\n"
875 "Address Family Modifier\n")
876{
877 vty->node = BGP_VPNV4_NODE;
878 return CMD_SUCCESS;
879}
880
881DEFUNSH (VTYSH_BGPD,
882 address_family_ipv4_unicast,
883 address_family_ipv4_unicast_cmd,
884 "address-family ipv4 unicast",
885 "Enter Address Family command mode\n"
886 "Address family\n"
887 "Address Family Modifier\n")
888{
889 vty->node = BGP_IPV4_NODE;
890 return CMD_SUCCESS;
891}
892
893DEFUNSH (VTYSH_BGPD,
894 address_family_ipv4_multicast,
895 address_family_ipv4_multicast_cmd,
896 "address-family ipv4 multicast",
897 "Enter Address Family command mode\n"
898 "Address family\n"
899 "Address Family Modifier\n")
900{
901 vty->node = BGP_IPV4M_NODE;
902 return CMD_SUCCESS;
903}
904
905DEFUNSH (VTYSH_BGPD,
906 address_family_ipv6,
907 address_family_ipv6_cmd,
908 "address-family ipv6",
909 "Enter Address Family command mode\n"
910 "Address family\n")
911{
912 vty->node = BGP_IPV6_NODE;
913 return CMD_SUCCESS;
914}
915
916DEFUNSH (VTYSH_BGPD,
917 address_family_ipv6_unicast,
918 address_family_ipv6_unicast_cmd,
919 "address-family ipv6 unicast",
920 "Enter Address Family command mode\n"
921 "Address family\n"
922 "Address Family Modifier\n")
923{
924 vty->node = BGP_IPV6_NODE;
925 return CMD_SUCCESS;
926}
927
928DEFUNSH (VTYSH_RIPD,
929 key_chain,
930 key_chain_cmd,
931 "key chain WORD",
932 "Authentication key management\n"
933 "Key-chain management\n"
934 "Key-chain name\n")
935{
936 vty->node = KEYCHAIN_NODE;
937 return CMD_SUCCESS;
938}
939
940DEFUNSH (VTYSH_RIPD,
941 key,
942 key_cmd,
943 "key <0-2147483647>",
944 "Configure a key\n"
945 "Key identifier number\n")
946{
947 vty->node = KEYCHAIN_KEY_NODE;
948 return CMD_SUCCESS;
949}
950
951DEFUNSH (VTYSH_RIPD,
952 router_rip,
953 router_rip_cmd,
954 "router rip",
955 ROUTER_STR
956 "RIP")
957{
958 vty->node = RIP_NODE;
959 return CMD_SUCCESS;
960}
961
962DEFUNSH (VTYSH_RIPNGD,
963 router_ripng,
964 router_ripng_cmd,
965 "router ripng",
966 ROUTER_STR
967 "RIPng")
968{
969 vty->node = RIPNG_NODE;
970 return CMD_SUCCESS;
971}
972
973DEFUNSH (VTYSH_OSPFD,
974 router_ospf,
975 router_ospf_cmd,
976 "router ospf",
977 "Enable a routing process\n"
978 "Start OSPF configuration\n")
979{
980 vty->node = OSPF_NODE;
981 return CMD_SUCCESS;
982}
983
984DEFUNSH (VTYSH_OSPF6D,
985 router_ospf6,
986 router_ospf6_cmd,
987 "router ospf6",
988 OSPF6_ROUTER_STR
989 OSPF6_STR)
990{
991 vty->node = OSPF6_NODE;
992 return CMD_SUCCESS;
993}
994
hassoc25e4582003-12-23 10:39:08 +0000995DEFUNSH (VTYSH_ISISD,
hassob094d262004-08-25 12:22:00 +0000996 router_isis,
997 router_isis_cmd,
998 "router isis WORD",
999 ROUTER_STR
1000 "ISO IS-IS\n"
1001 "ISO Routing area tag")
hassoc25e4582003-12-23 10:39:08 +00001002{
1003 vty->node = ISIS_NODE;
1004 return CMD_SUCCESS;
1005}
1006
paul718e3742002-12-13 20:15:29 +00001007DEFUNSH (VTYSH_RMAP,
1008 route_map,
1009 route_map_cmd,
1010 "route-map WORD (deny|permit) <1-65535>",
1011 "Create route-map or enter route-map command mode\n"
1012 "Route map tag\n"
1013 "Route map denies set operations\n"
1014 "Route map permits set operations\n"
1015 "Sequence to insert to/delete from existing route-map entry\n")
1016{
1017 vty->node = RMAP_NODE;
1018 return CMD_SUCCESS;
1019}
1020
paul718e3742002-12-13 20:15:29 +00001021DEFUNSH (VTYSH_ALL,
hassoe7168df2004-10-03 20:11:32 +00001022 vtysh_line_vty,
1023 vtysh_line_vty_cmd,
1024 "line vty",
1025 "Configure a terminal line\n"
1026 "Virtual terminal\n")
1027{
1028 vty->node = VTY_NODE;
1029 return CMD_SUCCESS;
1030}
1031
1032DEFUNSH (VTYSH_ALL,
paul718e3742002-12-13 20:15:29 +00001033 vtysh_enable,
1034 vtysh_enable_cmd,
1035 "enable",
1036 "Turn on privileged mode command\n")
1037{
1038 vty->node = ENABLE_NODE;
1039 return CMD_SUCCESS;
1040}
1041
paul718e3742002-12-13 20:15:29 +00001042DEFUNSH (VTYSH_ALL,
1043 vtysh_disable,
1044 vtysh_disable_cmd,
1045 "disable",
1046 "Turn off privileged mode command\n")
1047{
1048 if (vty->node == ENABLE_NODE)
1049 vty->node = VIEW_NODE;
1050 return CMD_SUCCESS;
1051}
1052
paul718e3742002-12-13 20:15:29 +00001053DEFUNSH (VTYSH_ALL,
1054 vtysh_config_terminal,
1055 vtysh_config_terminal_cmd,
1056 "configure terminal",
1057 "Configuration from vty interface\n"
1058 "Configuration terminal\n")
1059{
1060 vty->node = CONFIG_NODE;
1061 return CMD_SUCCESS;
1062}
1063
ajs274a4a42004-12-07 15:39:31 +00001064static int
paul718e3742002-12-13 20:15:29 +00001065vtysh_exit (struct vty *vty)
1066{
1067 switch (vty->node)
1068 {
1069 case VIEW_NODE:
1070 case ENABLE_NODE:
1071 exit (0);
1072 break;
1073 case CONFIG_NODE:
1074 vty->node = ENABLE_NODE;
1075 break;
1076 case INTERFACE_NODE:
1077 case ZEBRA_NODE:
1078 case BGP_NODE:
1079 case RIP_NODE:
1080 case RIPNG_NODE:
1081 case OSPF_NODE:
1082 case OSPF6_NODE:
hassoc25e4582003-12-23 10:39:08 +00001083 case ISIS_NODE:
paul718e3742002-12-13 20:15:29 +00001084 case MASC_NODE:
1085 case RMAP_NODE:
1086 case VTY_NODE:
1087 case KEYCHAIN_NODE:
hasso2a56df92004-05-09 23:16:40 +00001088 vtysh_execute("end");
1089 vtysh_execute("configure terminal");
paul718e3742002-12-13 20:15:29 +00001090 vty->node = CONFIG_NODE;
1091 break;
1092 case BGP_VPNV4_NODE:
1093 case BGP_IPV4_NODE:
1094 case BGP_IPV4M_NODE:
1095 case BGP_IPV6_NODE:
1096 vty->node = BGP_NODE;
1097 break;
1098 case KEYCHAIN_KEY_NODE:
1099 vty->node = KEYCHAIN_NODE;
1100 break;
1101 default:
1102 break;
1103 }
1104 return CMD_SUCCESS;
1105}
1106
1107DEFUNSH (VTYSH_ALL,
1108 vtysh_exit_all,
1109 vtysh_exit_all_cmd,
1110 "exit",
1111 "Exit current mode and down to previous mode\n")
1112{
1113 return vtysh_exit (vty);
1114}
1115
1116ALIAS (vtysh_exit_all,
1117 vtysh_quit_all_cmd,
1118 "quit",
1119 "Exit current mode and down to previous mode\n")
1120
1121DEFUNSH (VTYSH_BGPD,
1122 exit_address_family,
1123 exit_address_family_cmd,
1124 "exit-address-family",
1125 "Exit from Address Family configuration mode\n")
1126{
1127 if (vty->node == BGP_IPV4_NODE
1128 || vty->node == BGP_IPV4M_NODE
1129 || vty->node == BGP_VPNV4_NODE
1130 || vty->node == BGP_IPV6_NODE)
1131 vty->node = BGP_NODE;
1132 return CMD_SUCCESS;
1133}
1134
1135DEFUNSH (VTYSH_ZEBRA,
1136 vtysh_exit_zebra,
1137 vtysh_exit_zebra_cmd,
1138 "exit",
1139 "Exit current mode and down to previous mode\n")
1140{
1141 return vtysh_exit (vty);
1142}
1143
1144ALIAS (vtysh_exit_zebra,
1145 vtysh_quit_zebra_cmd,
1146 "quit",
1147 "Exit current mode and down to previous mode\n")
1148
1149DEFUNSH (VTYSH_RIPD,
1150 vtysh_exit_ripd,
1151 vtysh_exit_ripd_cmd,
1152 "exit",
1153 "Exit current mode and down to previous mode\n")
1154{
1155 return vtysh_exit (vty);
1156}
1157
1158ALIAS (vtysh_exit_ripd,
1159 vtysh_quit_ripd_cmd,
1160 "quit",
1161 "Exit current mode and down to previous mode\n")
1162
paul68980082003-03-25 05:07:42 +00001163DEFUNSH (VTYSH_RIPNGD,
hassob094d262004-08-25 12:22:00 +00001164 vtysh_exit_ripngd,
1165 vtysh_exit_ripngd_cmd,
1166 "exit",
1167 "Exit current mode and down to previous mode\n")
paul68980082003-03-25 05:07:42 +00001168{
1169 return vtysh_exit (vty);
1170}
1171
1172ALIAS (vtysh_exit_ripngd,
1173 vtysh_quit_ripngd_cmd,
1174 "quit",
1175 "Exit current mode and down to previous mode\n")
1176
paul718e3742002-12-13 20:15:29 +00001177DEFUNSH (VTYSH_RMAP,
1178 vtysh_exit_rmap,
1179 vtysh_exit_rmap_cmd,
1180 "exit",
1181 "Exit current mode and down to previous mode\n")
1182{
1183 return vtysh_exit (vty);
1184}
1185
1186ALIAS (vtysh_exit_rmap,
1187 vtysh_quit_rmap_cmd,
1188 "quit",
1189 "Exit current mode and down to previous mode\n")
1190
1191DEFUNSH (VTYSH_BGPD,
1192 vtysh_exit_bgpd,
1193 vtysh_exit_bgpd_cmd,
1194 "exit",
1195 "Exit current mode and down to previous mode\n")
1196{
1197 return vtysh_exit (vty);
1198}
1199
1200ALIAS (vtysh_exit_bgpd,
1201 vtysh_quit_bgpd_cmd,
1202 "quit",
1203 "Exit current mode and down to previous mode\n")
1204
1205DEFUNSH (VTYSH_OSPFD,
1206 vtysh_exit_ospfd,
1207 vtysh_exit_ospfd_cmd,
1208 "exit",
1209 "Exit current mode and down to previous mode\n")
1210{
1211 return vtysh_exit (vty);
1212}
1213
1214ALIAS (vtysh_exit_ospfd,
1215 vtysh_quit_ospfd_cmd,
1216 "quit",
1217 "Exit current mode and down to previous mode\n")
1218
paul68980082003-03-25 05:07:42 +00001219DEFUNSH (VTYSH_OSPF6D,
hassob094d262004-08-25 12:22:00 +00001220 vtysh_exit_ospf6d,
1221 vtysh_exit_ospf6d_cmd,
1222 "exit",
1223 "Exit current mode and down to previous mode\n")
paul68980082003-03-25 05:07:42 +00001224{
1225 return vtysh_exit (vty);
1226}
1227
1228ALIAS (vtysh_exit_ospf6d,
1229 vtysh_quit_ospf6d_cmd,
1230 "quit",
1231 "Exit current mode and down to previous mode\n")
1232
hassoc25e4582003-12-23 10:39:08 +00001233DEFUNSH (VTYSH_ISISD,
hassob094d262004-08-25 12:22:00 +00001234 vtysh_exit_isisd,
1235 vtysh_exit_isisd_cmd,
1236 "exit",
1237 "Exit current mode and down to previous mode\n")
hassoc25e4582003-12-23 10:39:08 +00001238{
1239 return vtysh_exit (vty);
1240}
1241
1242ALIAS (vtysh_exit_isisd,
1243 vtysh_quit_isisd_cmd,
1244 "quit",
1245 "Exit current mode and down to previous mode\n")
1246
hassoe7168df2004-10-03 20:11:32 +00001247DEFUNSH (VTYSH_ALL,
1248 vtysh_exit_line_vty,
1249 vtysh_exit_line_vty_cmd,
1250 "exit",
1251 "Exit current mode and down to previous mode\n")
1252{
1253 return vtysh_exit (vty);
1254}
1255
1256ALIAS (vtysh_exit_line_vty,
1257 vtysh_quit_line_vty_cmd,
1258 "quit",
1259 "Exit current mode and down to previous mode\n")
1260
hasso95e735b2004-08-26 13:08:30 +00001261DEFUNSH (VTYSH_INTERFACE,
paul718e3742002-12-13 20:15:29 +00001262 vtysh_interface,
1263 vtysh_interface_cmd,
1264 "interface IFNAME",
1265 "Select an interface to configure\n"
1266 "Interface's name\n")
1267{
1268 vty->node = INTERFACE_NODE;
1269 return CMD_SUCCESS;
1270}
1271
hasso95e735b2004-08-26 13:08:30 +00001272/* TODO Implement "no interface command in isisd. */
paul32d24632003-05-23 09:25:20 +00001273DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D,
1274 vtysh_no_interface_cmd,
1275 "no interface IFNAME",
1276 NO_STR
1277 "Delete a pseudo interface's configuration\n"
1278 "Interface's name\n")
1279
hasso95e735b2004-08-26 13:08:30 +00001280/* TODO Implement interface description commands in ripngd, ospf6d
1281 * and isisd. */
paul338a9912003-03-01 15:44:10 +00001282DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1283 interface_desc_cmd,
1284 "description .LINE",
1285 "Interface specific description\n"
1286 "Characters describing this interface\n")
paul464dc8d2003-03-28 02:25:45 +00001287
1288DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
1289 no_interface_desc_cmd,
1290 "no description",
1291 NO_STR
1292 "Interface specific description\n")
paul338a9912003-03-01 15:44:10 +00001293
hasso95e735b2004-08-26 13:08:30 +00001294DEFUNSH (VTYSH_INTERFACE,
paul718e3742002-12-13 20:15:29 +00001295 vtysh_exit_interface,
1296 vtysh_exit_interface_cmd,
1297 "exit",
1298 "Exit current mode and down to previous mode\n")
1299{
1300 return vtysh_exit (vty);
1301}
1302
1303ALIAS (vtysh_exit_interface,
1304 vtysh_quit_interface_cmd,
1305 "quit",
1306 "Exit current mode and down to previous mode\n")
1307
hasso95e735b2004-08-26 13:08:30 +00001308/* Logging commands. */
1309DEFUNSH (VTYSH_ALL,
1310 vtysh_log_stdout,
1311 vtysh_log_stdout_cmd,
1312 "log stdout",
1313 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001314 "Set stdout logging level\n")
1315{
1316 return CMD_SUCCESS;
1317}
1318
1319DEFUNSH (VTYSH_ALL,
1320 vtysh_log_stdout_level,
1321 vtysh_log_stdout_level_cmd,
1322 "log stdout "LOG_LEVELS,
1323 "Logging control\n"
1324 "Set stdout logging level\n"
1325 LOG_LEVEL_DESC)
hasso95e735b2004-08-26 13:08:30 +00001326{
1327 return CMD_SUCCESS;
1328}
1329
1330DEFUNSH (VTYSH_ALL,
1331 no_vtysh_log_stdout,
1332 no_vtysh_log_stdout_cmd,
ajs274a4a42004-12-07 15:39:31 +00001333 "no log stdout [LEVEL]",
hasso95e735b2004-08-26 13:08:30 +00001334 NO_STR
1335 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001336 "Cancel logging to stdout\n"
1337 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001338{
1339 return CMD_SUCCESS;
1340}
1341
1342DEFUNSH (VTYSH_ALL,
1343 vtysh_log_file,
1344 vtysh_log_file_cmd,
1345 "log file FILENAME",
1346 "Logging control\n"
1347 "Logging to file\n"
1348 "Logging filename\n")
1349{
1350 return CMD_SUCCESS;
1351}
1352
1353DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001354 vtysh_log_file_level,
1355 vtysh_log_file_level_cmd,
1356 "log file FILENAME "LOG_LEVELS,
1357 "Logging control\n"
1358 "Logging to file\n"
1359 "Logging filename\n"
1360 LOG_LEVEL_DESC)
1361{
1362 return CMD_SUCCESS;
1363}
1364
1365DEFUNSH (VTYSH_ALL,
hasso95e735b2004-08-26 13:08:30 +00001366 no_vtysh_log_file,
1367 no_vtysh_log_file_cmd,
1368 "no log file [FILENAME]",
1369 NO_STR
1370 "Logging control\n"
1371 "Cancel logging to file\n"
1372 "Logging file name\n")
1373{
1374 return CMD_SUCCESS;
1375}
1376
ajs274a4a42004-12-07 15:39:31 +00001377ALIAS_SH (VTYSH_ALL,
1378 no_vtysh_log_file,
1379 no_vtysh_log_file_level_cmd,
1380 "no log file FILENAME LEVEL",
1381 NO_STR
1382 "Logging control\n"
1383 "Cancel logging to file\n"
1384 "Logging file name\n"
1385 "Logging level\n")
1386
1387DEFUNSH (VTYSH_ALL,
1388 vtysh_log_monitor,
1389 vtysh_log_monitor_cmd,
1390 "log monitor",
1391 "Logging control\n"
1392 "Set terminal line (monitor) logging level\n")
1393{
1394 return CMD_SUCCESS;
1395}
1396
1397DEFUNSH (VTYSH_ALL,
1398 vtysh_log_monitor_level,
1399 vtysh_log_monitor_level_cmd,
1400 "log monitor "LOG_LEVELS,
1401 "Logging control\n"
1402 "Set terminal line (monitor) logging level\n"
1403 LOG_LEVEL_DESC)
1404{
1405 return CMD_SUCCESS;
1406}
1407
1408DEFUNSH (VTYSH_ALL,
1409 no_vtysh_log_monitor,
1410 no_vtysh_log_monitor_cmd,
1411 "no log monitor [LEVEL]",
1412 NO_STR
1413 "Logging control\n"
1414 "Disable terminal line (monitor) logging\n"
1415 "Logging level\n")
1416{
1417 return CMD_SUCCESS;
1418}
1419
hasso95e735b2004-08-26 13:08:30 +00001420DEFUNSH (VTYSH_ALL,
1421 vtysh_log_syslog,
1422 vtysh_log_syslog_cmd,
1423 "log syslog",
1424 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001425 "Set syslog logging level\n")
1426{
1427 return CMD_SUCCESS;
1428}
1429
1430DEFUNSH (VTYSH_ALL,
1431 vtysh_log_syslog_level,
1432 vtysh_log_syslog_level_cmd,
1433 "log syslog "LOG_LEVELS,
1434 "Logging control\n"
1435 "Set syslog logging level\n"
1436 LOG_LEVEL_DESC)
hasso95e735b2004-08-26 13:08:30 +00001437{
1438 return CMD_SUCCESS;
1439}
1440
1441DEFUNSH (VTYSH_ALL,
1442 no_vtysh_log_syslog,
1443 no_vtysh_log_syslog_cmd,
ajs274a4a42004-12-07 15:39:31 +00001444 "no log syslog [LEVEL]",
hasso95e735b2004-08-26 13:08:30 +00001445 NO_STR
1446 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001447 "Cancel logging to syslog\n"
1448 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001449{
1450 return CMD_SUCCESS;
1451}
1452
1453DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001454 vtysh_log_facility,
1455 vtysh_log_facility_cmd,
1456 "log facility "LOG_FACILITIES,
hasso95e735b2004-08-26 13:08:30 +00001457 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001458 "Facility parameter for syslog messages\n"
1459 LOG_FACILITY_DESC)
1460
hasso95e735b2004-08-26 13:08:30 +00001461{
1462 return CMD_SUCCESS;
1463}
1464
1465DEFUNSH (VTYSH_ALL,
ajs274a4a42004-12-07 15:39:31 +00001466 no_vtysh_log_facility,
1467 no_vtysh_log_facility_cmd,
1468 "no log facility [FACILITY]",
hasso95e735b2004-08-26 13:08:30 +00001469 NO_STR
1470 "Logging control\n"
ajs274a4a42004-12-07 15:39:31 +00001471 "Reset syslog facility to default (daemon)\n"
1472 "Syslog facility\n")
1473
1474{
1475 return CMD_SUCCESS;
1476}
1477
1478DEFUNSH_DEPRECATED (VTYSH_ALL,
1479 vtysh_log_trap,
1480 vtysh_log_trap_cmd,
1481 "log trap "LOG_LEVELS,
1482 "Logging control\n"
1483 "(Deprecated) Set logging level and default for all destinations\n"
1484 LOG_LEVEL_DESC)
1485
1486{
1487 return CMD_SUCCESS;
1488}
1489
1490DEFUNSH_DEPRECATED (VTYSH_ALL,
1491 no_vtysh_log_trap,
1492 no_vtysh_log_trap_cmd,
1493 "no log trap [LEVEL]",
1494 NO_STR
1495 "Logging control\n"
1496 "Permit all logging information\n"
1497 "Logging level\n")
hasso95e735b2004-08-26 13:08:30 +00001498{
1499 return CMD_SUCCESS;
1500}
1501
1502DEFUNSH (VTYSH_ALL,
1503 vtysh_log_record_priority,
1504 vtysh_log_record_priority_cmd,
1505 "log record-priority",
1506 "Logging control\n"
1507 "Log the priority of the message within the message\n")
1508{
1509 return CMD_SUCCESS;
1510}
1511
1512DEFUNSH (VTYSH_ALL,
1513 no_vtysh_log_record_priority,
1514 no_vtysh_log_record_priority_cmd,
1515 "no log record-priority",
1516 NO_STR
1517 "Logging control\n"
1518 "Do not log the priority of the message within the message\n")
1519{
1520 return CMD_SUCCESS;
1521}
1522
hassoe7168df2004-10-03 20:11:32 +00001523DEFUNSH (VTYSH_ALL,
1524 vtysh_service_password_encrypt,
1525 vtysh_service_password_encrypt_cmd,
1526 "service password-encryption",
1527 "Set up miscellaneous service\n"
1528 "Enable encrypted passwords\n")
1529{
1530 return CMD_SUCCESS;
1531}
1532
1533DEFUNSH (VTYSH_ALL,
1534 no_vtysh_service_password_encrypt,
1535 no_vtysh_service_password_encrypt_cmd,
1536 "no service password-encryption",
1537 NO_STR
1538 "Set up miscellaneous service\n"
1539 "Enable encrypted passwords\n")
1540{
1541 return CMD_SUCCESS;
1542}
1543
1544DEFUNSH (VTYSH_ALL,
1545 vtysh_config_password,
1546 vtysh_password_cmd,
1547 "password (8|) WORD",
1548 "Assign the terminal connection password\n"
1549 "Specifies a HIDDEN password will follow\n"
1550 "dummy string \n"
1551 "The HIDDEN line password string\n")
1552{
1553 return CMD_SUCCESS;
1554}
1555
1556DEFUNSH (VTYSH_ALL,
1557 vtysh_password_text,
1558 vtysh_password_text_cmd,
1559 "password LINE",
1560 "Assign the terminal connection password\n"
1561 "The UNENCRYPTED (cleartext) line password\n")
1562{
1563 return CMD_SUCCESS;
1564}
1565
1566DEFUNSH (VTYSH_ALL,
1567 vtysh_config_enable_password,
1568 vtysh_enable_password_cmd,
1569 "enable password (8|) WORD",
1570 "Modify enable password parameters\n"
1571 "Assign the privileged level password\n"
1572 "Specifies a HIDDEN password will follow\n"
1573 "dummy string \n"
1574 "The HIDDEN 'enable' password string\n")
1575{
1576 return CMD_SUCCESS;
1577}
1578
1579DEFUNSH (VTYSH_ALL,
1580 vtysh_enable_password_text,
1581 vtysh_enable_password_text_cmd,
1582 "enable password LINE",
1583 "Modify enable password parameters\n"
1584 "Assign the privileged level password\n"
1585 "The UNENCRYPTED (cleartext) 'enable' password\n")
1586{
1587 return CMD_SUCCESS;
1588}
1589
1590DEFUNSH (VTYSH_ALL,
1591 no_vtysh_config_enable_password,
1592 no_vtysh_enable_password_cmd,
1593 "no enable password",
1594 NO_STR
1595 "Modify enable password parameters\n"
1596 "Assign the privileged level password\n")
1597{
1598 return CMD_SUCCESS;
1599}
1600
paul718e3742002-12-13 20:15:29 +00001601DEFUN (vtysh_write_terminal,
1602 vtysh_write_terminal_cmd,
1603 "write terminal",
1604 "Write running configuration to memory, network, or terminal\n"
1605 "Write to terminal\n")
1606{
1607 int ret;
1608 char line[] = "write terminal\n";
1609 FILE *fp = NULL;
1610
1611 if (vtysh_pager_name)
1612 {
paul4fc01e62002-12-13 20:49:00 +00001613 fp = popen (vtysh_pager_name, "w");
paul718e3742002-12-13 20:15:29 +00001614 if (fp == NULL)
1615 {
1616 perror ("popen");
1617 exit (1);
1618 }
1619 }
1620 else
1621 fp = stdout;
1622
1623 vty_out (vty, "Building configuration...%s", VTY_NEWLINE);
1624 vty_out (vty, "%sCurrent configuration:%s", VTY_NEWLINE,
1625 VTY_NEWLINE);
hassoe7168df2004-10-03 20:11:32 +00001626 vty_out (vty, "!%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001627
1628 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_ZEBRA], line);
1629 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_RIP], line);
1630 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_RIPNG], line);
1631 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_OSPF], line);
1632 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_OSPF6], line);
1633 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_BGP], line);
hassoc25e4582003-12-23 10:39:08 +00001634 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_ISIS], line);
paul718e3742002-12-13 20:15:29 +00001635
hassoe7168df2004-10-03 20:11:32 +00001636 /* Integrate vtysh specific configuration. */
1637 vtysh_config_write ();
1638
paul718e3742002-12-13 20:15:29 +00001639 vtysh_config_dump (fp);
1640
1641 if (vtysh_pager_name && fp)
1642 {
1643 fflush (fp);
1644 if (pclose (fp) == -1)
1645 {
1646 perror ("pclose");
1647 exit (1);
1648 }
1649 fp = NULL;
1650 }
1651
1652 return CMD_SUCCESS;
1653}
1654
hassoe7168df2004-10-03 20:11:32 +00001655DEFUN (vtysh_integrated_config,
1656 vtysh_integrated_config_cmd,
1657 "service integrated-vtysh-config",
1658 "Set up miscellaneous service\n"
1659 "Write configuration into integrated file\n")
paul4fc01e62002-12-13 20:49:00 +00001660{
hassoe7168df2004-10-03 20:11:32 +00001661 vtysh_writeconfig_integrated = 1;
1662 return CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001663}
1664
hassoe7168df2004-10-03 20:11:32 +00001665DEFUN (no_vtysh_integrated_config,
1666 no_vtysh_integrated_config_cmd,
1667 "no service integrated-vtysh-config",
1668 NO_STR
1669 "Set up miscellaneous service\n"
1670 "Write configuration into integrated file\n")
paul4fc01e62002-12-13 20:49:00 +00001671{
hassoe7168df2004-10-03 20:11:32 +00001672 vtysh_writeconfig_integrated = 0;
1673 return CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001674}
1675
ajs274a4a42004-12-07 15:39:31 +00001676static int
1677write_config_integrated(void)
paul718e3742002-12-13 20:15:29 +00001678{
1679 int ret;
paul718e3742002-12-13 20:15:29 +00001680 char line[] = "write terminal\n";
1681 FILE *fp;
1682 char *integrate_sav = NULL;
1683
hasso95e735b2004-08-26 13:08:30 +00001684 integrate_sav = malloc (strlen (integrate_default) +
1685 strlen (CONF_BACKUP_EXT) + 1);
paul718e3742002-12-13 20:15:29 +00001686 strcpy (integrate_sav, integrate_default);
1687 strcat (integrate_sav, CONF_BACKUP_EXT);
1688
paul4fc01e62002-12-13 20:49:00 +00001689 fprintf (stdout,"Building Configuration...\n");
paul718e3742002-12-13 20:15:29 +00001690
hasso95e735b2004-08-26 13:08:30 +00001691 /* Move current configuration file to backup config file. */
paul718e3742002-12-13 20:15:29 +00001692 unlink (integrate_sav);
1693 rename (integrate_default, integrate_sav);
hasso95e735b2004-08-26 13:08:30 +00001694 free (integrate_sav);
paul4fc01e62002-12-13 20:49:00 +00001695
paul718e3742002-12-13 20:15:29 +00001696 fp = fopen (integrate_default, "w");
1697 if (fp == NULL)
1698 {
hasso95e735b2004-08-26 13:08:30 +00001699 fprintf (stdout,"%% Can't open configuration file %s.\n",
1700 integrate_default);
paul718e3742002-12-13 20:15:29 +00001701 return CMD_SUCCESS;
1702 }
paul718e3742002-12-13 20:15:29 +00001703
paul718e3742002-12-13 20:15:29 +00001704 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_ZEBRA], line);
1705 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_RIP], line);
1706 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_RIPNG], line);
1707 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_OSPF], line);
1708 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_OSPF6], line);
1709 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_BGP], line);
hassoc25e4582003-12-23 10:39:08 +00001710 ret = vtysh_client_config (&vtysh_client[VTYSH_INDEX_ISIS], line);
paul718e3742002-12-13 20:15:29 +00001711
1712 vtysh_config_dump (fp);
1713
1714 fclose (fp);
1715
gdtaa593d52003-12-22 20:15:53 +00001716 if (chmod (integrate_default, CONFIGFILE_MASK) != 0)
1717 {
1718 fprintf (stdout,"%% Can't chmod configuration file %s: %s (%d)\n",
ajs6099b3b2004-11-20 02:06:59 +00001719 integrate_default, safe_strerror(errno), errno);
gdtaa593d52003-12-22 20:15:53 +00001720 return CMD_WARNING;
1721 }
1722
paul4fc01e62002-12-13 20:49:00 +00001723 fprintf(stdout,"Integrated configuration saved to %s\n",integrate_default);
1724
1725 fprintf (stdout,"[OK]\n");
1726
paul718e3742002-12-13 20:15:29 +00001727 return CMD_SUCCESS;
1728}
1729
paul4fc01e62002-12-13 20:49:00 +00001730DEFUN (vtysh_write_memory,
1731 vtysh_write_memory_cmd,
1732 "write memory",
1733 "Write running configuration to memory, network, or terminal\n"
1734 "Write configuration to the file (same as write file)\n")
1735{
pauldfc0d9b2003-04-18 23:55:29 +00001736 int ret = CMD_SUCCESS;
paul4fc01e62002-12-13 20:49:00 +00001737 char line[] = "write memory\n";
1738
hassoe7168df2004-10-03 20:11:32 +00001739 /* If integrated Quagga.conf explicitely set. */
1740 if (vtysh_writeconfig_integrated)
1741 return write_config_integrated();
paul4fc01e62002-12-13 20:49:00 +00001742
1743 fprintf (stdout,"Building Configuration...\n");
1744
1745 ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ZEBRA], line, stdout);
1746 ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIP], line, stdout);
1747 ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_RIPNG], line, stdout);
1748 ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF], line, stdout);
1749 ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_OSPF6], line, stdout);
1750 ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_BGP], line, stdout);
hassoc25e4582003-12-23 10:39:08 +00001751 ret = vtysh_client_execute (&vtysh_client[VTYSH_INDEX_ISIS], line, stdout);
hassoe7168df2004-10-03 20:11:32 +00001752
paul4fc01e62002-12-13 20:49:00 +00001753 fprintf (stdout,"[OK]\n");
1754
pauldfc0d9b2003-04-18 23:55:29 +00001755 return ret;
paul4fc01e62002-12-13 20:49:00 +00001756}
1757
paul718e3742002-12-13 20:15:29 +00001758ALIAS (vtysh_write_memory,
1759 vtysh_copy_runningconfig_startupconfig_cmd,
1760 "copy running-config startup-config",
1761 "Copy from one file to another\n"
1762 "Copy from current system configuration\n"
1763 "Copy to startup configuration\n")
1764
1765ALIAS (vtysh_write_memory,
1766 vtysh_write_file_cmd,
1767 "write file",
1768 "Write running configuration to memory, network, or terminal\n"
1769 "Write configuration to the file (same as write memory)\n")
1770
hasso4a6e2252003-05-25 11:51:29 +00001771ALIAS (vtysh_write_memory,
1772 vtysh_write_cmd,
1773 "write",
1774 "Write running configuration to memory, network, or terminal\n")
1775
paul718e3742002-12-13 20:15:29 +00001776ALIAS (vtysh_write_terminal,
1777 vtysh_show_running_config_cmd,
1778 "show running-config",
1779 SHOW_STR
1780 "Current operating configuration\n")
hassob094d262004-08-25 12:22:00 +00001781
hasso34553cc2004-08-27 13:56:39 +00001782DEFUN (vtysh_terminal_length,
1783 vtysh_terminal_length_cmd,
1784 "terminal length <0-512>",
1785 "Set terminal line parameters\n"
1786 "Set number of lines on a screen\n"
1787 "Number of lines on screen (0 for no pausing)\n")
1788{
1789 int lines;
1790 char *endptr = NULL;
1791 char default_pager[10];
1792
1793 lines = strtol (argv[0], &endptr, 10);
1794 if (lines < 0 || lines > 512 || *endptr != '\0')
1795 {
1796 vty_out (vty, "length is malformed%s", VTY_NEWLINE);
1797 return CMD_WARNING;
1798 }
1799
1800 if (vtysh_pager_name)
1801 {
1802 free (vtysh_pager_name);
1803 vtysh_pager_name = NULL;
1804 }
1805
1806 if (lines != 0)
1807 {
1808 snprintf(default_pager, 10, "more -%i", lines);
1809 vtysh_pager_name = strdup (default_pager);
1810 }
1811
1812 return CMD_SUCCESS;
1813}
1814
1815DEFUN (vtysh_terminal_no_length,
1816 vtysh_terminal_no_length_cmd,
1817 "terminal no length",
1818 "Set terminal line parameters\n"
1819 NO_STR
1820 "Set number of lines on a screen\n")
1821{
1822 if (vtysh_pager_name)
1823 {
1824 free (vtysh_pager_name);
1825 vtysh_pager_name = NULL;
1826 }
1827
1828 vtysh_pager_init();
1829 return CMD_SUCCESS;
1830}
1831
hassof2799e62004-10-28 17:43:11 +00001832DEFUN (vtysh_show_daemons,
1833 vtysh_show_daemons_cmd,
1834 "show daemons",
hassoe7168df2004-10-03 20:11:32 +00001835 SHOW_STR
1836 "Show list of running daemons\n")
1837{
1838 if ( vtysh_client[VTYSH_INDEX_ZEBRA].fd > 0 )
1839 vty_out(vty, " zebra");
1840 if ( vtysh_client[VTYSH_INDEX_RIP].fd > 0 )
1841 vty_out(vty, " ripd");
1842 if ( vtysh_client[VTYSH_INDEX_RIPNG].fd > 0 )
1843 vty_out(vty, " ripngd");
1844 if ( vtysh_client[VTYSH_INDEX_OSPF].fd > 0 )
1845 vty_out(vty, " ospfd");
1846 if ( vtysh_client[VTYSH_INDEX_OSPF6].fd > 0 )
1847 vty_out(vty, " ospf6d");
1848 if ( vtysh_client[VTYSH_INDEX_BGP].fd > 0 )
1849 vty_out(vty, " bgpd");
1850 if ( vtysh_client[VTYSH_INDEX_ISIS].fd > 0 )
1851 vty_out(vty, " isisd");
1852 vty_out(vty, "%s", VTY_NEWLINE);
1853
1854 return CMD_SUCCESS;
1855}
1856
paul718e3742002-12-13 20:15:29 +00001857/* Execute command in child process. */
ajs274a4a42004-12-07 15:39:31 +00001858static int
hasso5862ff52004-10-11 13:20:40 +00001859execute_command (const char *command, int argc, const char *arg1,
1860 const char *arg2)
paul718e3742002-12-13 20:15:29 +00001861{
1862 int ret;
1863 pid_t pid;
1864 int status;
1865
1866 /* Call fork(). */
1867 pid = fork ();
1868
1869 if (pid < 0)
1870 {
1871 /* Failure of fork(). */
ajs6099b3b2004-11-20 02:06:59 +00001872 fprintf (stderr, "Can't fork: %s\n", safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +00001873 exit (1);
1874 }
1875 else if (pid == 0)
1876 {
1877 /* This is child process. */
1878 switch (argc)
1879 {
1880 case 0:
hassofa2b17e2004-03-04 17:45:00 +00001881 ret = execlp (command, command, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00001882 break;
1883 case 1:
hassofa2b17e2004-03-04 17:45:00 +00001884 ret = execlp (command, command, arg1, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00001885 break;
1886 case 2:
hassofa2b17e2004-03-04 17:45:00 +00001887 ret = execlp (command, command, arg1, arg2, (const char *)NULL);
paul718e3742002-12-13 20:15:29 +00001888 break;
1889 }
1890
1891 /* When execlp suceed, this part is not executed. */
ajs6099b3b2004-11-20 02:06:59 +00001892 fprintf (stderr, "Can't execute %s: %s\n", command, safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +00001893 exit (1);
1894 }
1895 else
1896 {
1897 /* This is parent. */
1898 execute_flag = 1;
1899 ret = wait4 (pid, &status, 0, NULL);
1900 execute_flag = 0;
1901 }
1902 return 0;
1903}
1904
1905DEFUN (vtysh_ping,
1906 vtysh_ping_cmd,
1907 "ping WORD",
hasso4eeccf12003-06-25 10:49:55 +00001908 "Send echo messages\n"
paul718e3742002-12-13 20:15:29 +00001909 "Ping destination address or hostname\n")
1910{
1911 execute_command ("ping", 1, argv[0], NULL);
1912 return CMD_SUCCESS;
1913}
1914
hasso4eeccf12003-06-25 10:49:55 +00001915ALIAS (vtysh_ping,
1916 vtysh_ping_ip_cmd,
1917 "ping ip WORD",
1918 "Send echo messages\n"
1919 "IP echo\n"
1920 "Ping destination address or hostname\n")
1921
paul718e3742002-12-13 20:15:29 +00001922DEFUN (vtysh_traceroute,
1923 vtysh_traceroute_cmd,
1924 "traceroute WORD",
1925 "Trace route to destination\n"
1926 "Trace route to destination address or hostname\n")
1927{
1928 execute_command ("traceroute", 1, argv[0], NULL);
1929 return CMD_SUCCESS;
1930}
1931
hasso4eeccf12003-06-25 10:49:55 +00001932ALIAS (vtysh_traceroute,
1933 vtysh_traceroute_ip_cmd,
1934 "traceroute ip WORD",
1935 "Trace route to destination\n"
1936 "IP trace\n"
1937 "Trace route to destination address or hostname\n")
1938
1939#ifdef HAVE_IPV6
1940DEFUN (vtysh_ping6,
1941 vtysh_ping6_cmd,
1942 "ping ipv6 WORD",
1943 "Send echo messages\n"
1944 "IPv6 echo\n"
1945 "Ping destination address or hostname\n")
1946{
1947 execute_command ("ping6", 1, argv[0], NULL);
1948 return CMD_SUCCESS;
1949}
1950
1951DEFUN (vtysh_traceroute6,
1952 vtysh_traceroute6_cmd,
1953 "traceroute ipv6 WORD",
1954 "Trace route to destination\n"
1955 "IPv6 trace\n"
1956 "Trace route to destination address or hostname\n")
1957{
1958 execute_command ("traceroute6", 1, argv[0], NULL);
1959 return CMD_SUCCESS;
1960}
1961#endif
1962
paul718e3742002-12-13 20:15:29 +00001963DEFUN (vtysh_telnet,
1964 vtysh_telnet_cmd,
1965 "telnet WORD",
1966 "Open a telnet connection\n"
1967 "IP address or hostname of a remote system\n")
1968{
1969 execute_command ("telnet", 1, argv[0], NULL);
1970 return CMD_SUCCESS;
1971}
1972
1973DEFUN (vtysh_telnet_port,
1974 vtysh_telnet_port_cmd,
1975 "telnet WORD PORT",
1976 "Open a telnet connection\n"
1977 "IP address or hostname of a remote system\n"
1978 "TCP Port number\n")
1979{
1980 execute_command ("telnet", 2, argv[0], argv[1]);
1981 return CMD_SUCCESS;
1982}
1983
paul5087df52003-01-25 06:56:09 +00001984DEFUN (vtysh_ssh,
1985 vtysh_ssh_cmd,
1986 "ssh WORD",
1987 "Open an ssh connection\n"
1988 "[user@]host\n")
1989{
1990 execute_command ("ssh", 1, argv[0], NULL);
1991 return CMD_SUCCESS;
1992}
1993
paul718e3742002-12-13 20:15:29 +00001994DEFUN (vtysh_start_shell,
1995 vtysh_start_shell_cmd,
1996 "start-shell",
1997 "Start UNIX shell\n")
1998{
1999 execute_command ("sh", 0, NULL, NULL);
2000 return CMD_SUCCESS;
2001}
2002
2003DEFUN (vtysh_start_bash,
2004 vtysh_start_bash_cmd,
2005 "start-shell bash",
2006 "Start UNIX shell\n"
2007 "Start bash\n")
2008{
2009 execute_command ("bash", 0, NULL, NULL);
2010 return CMD_SUCCESS;
2011}
2012
2013DEFUN (vtysh_start_zsh,
2014 vtysh_start_zsh_cmd,
2015 "start-shell zsh",
2016 "Start UNIX shell\n"
2017 "Start Z shell\n")
2018{
2019 execute_command ("zsh", 0, NULL, NULL);
2020 return CMD_SUCCESS;
2021}
hassob094d262004-08-25 12:22:00 +00002022
ajs274a4a42004-12-07 15:39:31 +00002023static void
paul718e3742002-12-13 20:15:29 +00002024vtysh_install_default (enum node_type node)
2025{
2026 install_element (node, &config_list_cmd);
2027}
2028
2029/* Making connection to protocol daemon. */
ajs274a4a42004-12-07 15:39:31 +00002030static int
hassodda09522004-10-07 21:40:25 +00002031vtysh_connect (struct vtysh_client *vclient, const char *path)
paul718e3742002-12-13 20:15:29 +00002032{
2033 int ret;
2034 int sock, len;
2035 struct sockaddr_un addr;
2036 struct stat s_stat;
paul718e3742002-12-13 20:15:29 +00002037
2038 memset (vclient, 0, sizeof (struct vtysh_client));
2039 vclient->fd = -1;
2040
2041 /* Stat socket to see if we have permission to access it. */
paul718e3742002-12-13 20:15:29 +00002042 ret = stat (path, &s_stat);
2043 if (ret < 0 && errno != ENOENT)
2044 {
2045 fprintf (stderr, "vtysh_connect(%s): stat = %s\n",
ajs6099b3b2004-11-20 02:06:59 +00002046 path, safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002047 exit(1);
2048 }
2049
2050 if (ret >= 0)
2051 {
2052 if (! S_ISSOCK(s_stat.st_mode))
2053 {
2054 fprintf (stderr, "vtysh_connect(%s): Not a socket\n",
2055 path);
2056 exit (1);
2057 }
2058
paul718e3742002-12-13 20:15:29 +00002059 }
2060
2061 sock = socket (AF_UNIX, SOCK_STREAM, 0);
2062 if (sock < 0)
2063 {
2064#ifdef DEBUG
hasso95e735b2004-08-26 13:08:30 +00002065 fprintf(stderr, "vtysh_connect(%s): socket = %s\n", path,
ajs6099b3b2004-11-20 02:06:59 +00002066 safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002067#endif /* DEBUG */
2068 return -1;
2069 }
2070
2071 memset (&addr, 0, sizeof (struct sockaddr_un));
2072 addr.sun_family = AF_UNIX;
2073 strncpy (addr.sun_path, path, strlen (path));
2074#ifdef HAVE_SUN_LEN
2075 len = addr.sun_len = SUN_LEN(&addr);
2076#else
2077 len = sizeof (addr.sun_family) + strlen (addr.sun_path);
2078#endif /* HAVE_SUN_LEN */
2079
2080 ret = connect (sock, (struct sockaddr *) &addr, len);
2081 if (ret < 0)
2082 {
2083#ifdef DEBUG
hasso95e735b2004-08-26 13:08:30 +00002084 fprintf(stderr, "vtysh_connect(%s): connect = %s\n", path,
ajs6099b3b2004-11-20 02:06:59 +00002085 safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +00002086#endif /* DEBUG */
2087 close (sock);
2088 return -1;
2089 }
2090 vclient->fd = sock;
2091
2092 return 0;
2093}
2094
2095void
2096vtysh_connect_all()
2097{
2098 /* Clear each daemons client structure. */
paulfe067782003-04-07 16:10:05 +00002099 vtysh_connect (&vtysh_client[VTYSH_INDEX_ZEBRA], ZEBRA_VTYSH_PATH);
2100 vtysh_connect (&vtysh_client[VTYSH_INDEX_RIP], RIP_VTYSH_PATH);
2101 vtysh_connect (&vtysh_client[VTYSH_INDEX_RIPNG], RIPNG_VTYSH_PATH);
2102 vtysh_connect (&vtysh_client[VTYSH_INDEX_OSPF], OSPF_VTYSH_PATH);
2103 vtysh_connect (&vtysh_client[VTYSH_INDEX_OSPF6], OSPF6_VTYSH_PATH);
2104 vtysh_connect (&vtysh_client[VTYSH_INDEX_BGP], BGP_VTYSH_PATH);
hassoc25e4582003-12-23 10:39:08 +00002105 vtysh_connect (&vtysh_client[VTYSH_INDEX_ISIS], ISIS_VTYSH_PATH);
paul718e3742002-12-13 20:15:29 +00002106}
2107
hasso95e735b2004-08-26 13:08:30 +00002108/* To disable readline's filename completion. */
ajs274a4a42004-12-07 15:39:31 +00002109static char *
pauldfc0d9b2003-04-18 23:55:29 +00002110vtysh_completion_entry_function (const char *ignore, int invoking_key)
paul718e3742002-12-13 20:15:29 +00002111{
pauldfc0d9b2003-04-18 23:55:29 +00002112 return NULL;
paul718e3742002-12-13 20:15:29 +00002113}
2114
2115void
2116vtysh_readline_init ()
2117{
2118 /* readline related settings. */
2119 rl_bind_key ('?', vtysh_rl_describe);
paul68980082003-03-25 05:07:42 +00002120 rl_completion_entry_function = vtysh_completion_entry_function;
paul718e3742002-12-13 20:15:29 +00002121 rl_attempted_completion_function = (CPPFunction *)new_completion;
2122 /* do not append space after completion. It will be appended
hasso95e735b2004-08-26 13:08:30 +00002123 * in new_completion() function explicitly. */
paul718e3742002-12-13 20:15:29 +00002124 rl_completion_append_character = '\0';
2125}
2126
2127char *
2128vtysh_prompt ()
2129{
2130 struct utsname names;
2131 static char buf[100];
2132 const char*hostname;
2133 extern struct host host;
2134
2135 hostname = host.name;
2136
2137 if (!hostname)
2138 {
2139 uname (&names);
2140 hostname = names.nodename;
2141 }
2142
2143 snprintf (buf, sizeof buf, cmd_prompt (vty->node), hostname);
2144
2145 return buf;
2146}
2147
2148void
2149vtysh_init_vty ()
2150{
2151 /* Make vty structure. */
2152 vty = vty_new ();
2153 vty->type = VTY_SHELL;
2154 vty->node = VIEW_NODE;
2155
2156 /* Initialize commands. */
2157 cmd_init (0);
2158
2159 /* Install nodes. */
2160 install_node (&bgp_node, NULL);
2161 install_node (&rip_node, NULL);
2162 install_node (&interface_node, NULL);
2163 install_node (&rmap_node, NULL);
2164 install_node (&zebra_node, NULL);
2165 install_node (&bgp_vpnv4_node, NULL);
2166 install_node (&bgp_ipv4_node, NULL);
2167 install_node (&bgp_ipv4m_node, NULL);
2168/* #ifdef HAVE_IPV6 */
2169 install_node (&bgp_ipv6_node, NULL);
2170/* #endif */
2171 install_node (&ospf_node, NULL);
2172/* #ifdef HAVE_IPV6 */
2173 install_node (&ripng_node, NULL);
2174 install_node (&ospf6_node, NULL);
2175/* #endif */
2176 install_node (&keychain_node, NULL);
2177 install_node (&keychain_key_node, NULL);
hassoc25e4582003-12-23 10:39:08 +00002178 install_node (&isis_node, NULL);
hassoe7168df2004-10-03 20:11:32 +00002179 install_node (&vty_node, NULL);
paul718e3742002-12-13 20:15:29 +00002180
2181 vtysh_install_default (VIEW_NODE);
2182 vtysh_install_default (ENABLE_NODE);
2183 vtysh_install_default (CONFIG_NODE);
2184 vtysh_install_default (BGP_NODE);
2185 vtysh_install_default (RIP_NODE);
2186 vtysh_install_default (INTERFACE_NODE);
2187 vtysh_install_default (RMAP_NODE);
2188 vtysh_install_default (ZEBRA_NODE);
2189 vtysh_install_default (BGP_VPNV4_NODE);
2190 vtysh_install_default (BGP_IPV4_NODE);
2191 vtysh_install_default (BGP_IPV4M_NODE);
2192 vtysh_install_default (BGP_IPV6_NODE);
2193 vtysh_install_default (OSPF_NODE);
2194 vtysh_install_default (RIPNG_NODE);
2195 vtysh_install_default (OSPF6_NODE);
hassoc25e4582003-12-23 10:39:08 +00002196 vtysh_install_default (ISIS_NODE);
paul718e3742002-12-13 20:15:29 +00002197 vtysh_install_default (KEYCHAIN_NODE);
2198 vtysh_install_default (KEYCHAIN_KEY_NODE);
hassoe7168df2004-10-03 20:11:32 +00002199 vtysh_install_default (VTY_NODE);
paul718e3742002-12-13 20:15:29 +00002200
2201 install_element (VIEW_NODE, &vtysh_enable_cmd);
2202 install_element (ENABLE_NODE, &vtysh_config_terminal_cmd);
2203 install_element (ENABLE_NODE, &vtysh_disable_cmd);
2204
2205 /* "exit" command. */
2206 install_element (VIEW_NODE, &vtysh_exit_all_cmd);
2207 install_element (VIEW_NODE, &vtysh_quit_all_cmd);
2208 install_element (CONFIG_NODE, &vtysh_exit_all_cmd);
2209 /* install_element (CONFIG_NODE, &vtysh_quit_all_cmd); */
2210 install_element (ENABLE_NODE, &vtysh_exit_all_cmd);
2211 install_element (ENABLE_NODE, &vtysh_quit_all_cmd);
2212 install_element (RIP_NODE, &vtysh_exit_ripd_cmd);
2213 install_element (RIP_NODE, &vtysh_quit_ripd_cmd);
paul68980082003-03-25 05:07:42 +00002214 install_element (RIPNG_NODE, &vtysh_exit_ripngd_cmd);
2215 install_element (RIPNG_NODE, &vtysh_quit_ripngd_cmd);
paul718e3742002-12-13 20:15:29 +00002216 install_element (OSPF_NODE, &vtysh_exit_ospfd_cmd);
2217 install_element (OSPF_NODE, &vtysh_quit_ospfd_cmd);
paul68980082003-03-25 05:07:42 +00002218 install_element (OSPF6_NODE, &vtysh_exit_ospf6d_cmd);
2219 install_element (OSPF6_NODE, &vtysh_quit_ospf6d_cmd);
paul718e3742002-12-13 20:15:29 +00002220 install_element (BGP_NODE, &vtysh_exit_bgpd_cmd);
2221 install_element (BGP_NODE, &vtysh_quit_bgpd_cmd);
2222 install_element (BGP_VPNV4_NODE, &vtysh_exit_bgpd_cmd);
2223 install_element (BGP_VPNV4_NODE, &vtysh_quit_bgpd_cmd);
2224 install_element (BGP_IPV4_NODE, &vtysh_exit_bgpd_cmd);
2225 install_element (BGP_IPV4_NODE, &vtysh_quit_bgpd_cmd);
2226 install_element (BGP_IPV4M_NODE, &vtysh_exit_bgpd_cmd);
2227 install_element (BGP_IPV4M_NODE, &vtysh_quit_bgpd_cmd);
2228 install_element (BGP_IPV6_NODE, &vtysh_exit_bgpd_cmd);
2229 install_element (BGP_IPV6_NODE, &vtysh_quit_bgpd_cmd);
hassoc25e4582003-12-23 10:39:08 +00002230 install_element (ISIS_NODE, &vtysh_exit_isisd_cmd);
2231 install_element (ISIS_NODE, &vtysh_quit_isisd_cmd);
paul718e3742002-12-13 20:15:29 +00002232 install_element (KEYCHAIN_NODE, &vtysh_exit_ripd_cmd);
2233 install_element (KEYCHAIN_NODE, &vtysh_quit_ripd_cmd);
2234 install_element (KEYCHAIN_KEY_NODE, &vtysh_exit_ripd_cmd);
2235 install_element (KEYCHAIN_KEY_NODE, &vtysh_quit_ripd_cmd);
2236 install_element (RMAP_NODE, &vtysh_exit_rmap_cmd);
2237 install_element (RMAP_NODE, &vtysh_quit_rmap_cmd);
hassoe7168df2004-10-03 20:11:32 +00002238 install_element (VTY_NODE, &vtysh_exit_line_vty_cmd);
2239 install_element (VTY_NODE, &vtysh_quit_line_vty_cmd);
paul718e3742002-12-13 20:15:29 +00002240
2241 /* "end" command. */
2242 install_element (CONFIG_NODE, &vtysh_end_all_cmd);
2243 install_element (ENABLE_NODE, &vtysh_end_all_cmd);
2244 install_element (RIP_NODE, &vtysh_end_all_cmd);
2245 install_element (RIPNG_NODE, &vtysh_end_all_cmd);
2246 install_element (OSPF_NODE, &vtysh_end_all_cmd);
2247 install_element (OSPF6_NODE, &vtysh_end_all_cmd);
2248 install_element (BGP_NODE, &vtysh_end_all_cmd);
2249 install_element (BGP_IPV4_NODE, &vtysh_end_all_cmd);
2250 install_element (BGP_IPV4M_NODE, &vtysh_end_all_cmd);
2251 install_element (BGP_VPNV4_NODE, &vtysh_end_all_cmd);
2252 install_element (BGP_IPV6_NODE, &vtysh_end_all_cmd);
hassoc25e4582003-12-23 10:39:08 +00002253 install_element (ISIS_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002254 install_element (KEYCHAIN_NODE, &vtysh_end_all_cmd);
2255 install_element (KEYCHAIN_KEY_NODE, &vtysh_end_all_cmd);
2256 install_element (RMAP_NODE, &vtysh_end_all_cmd);
hassoe7168df2004-10-03 20:11:32 +00002257 install_element (VTY_NODE, &vtysh_end_all_cmd);
paul718e3742002-12-13 20:15:29 +00002258
paul338a9912003-03-01 15:44:10 +00002259 install_element (INTERFACE_NODE, &interface_desc_cmd);
paul464dc8d2003-03-28 02:25:45 +00002260 install_element (INTERFACE_NODE, &no_interface_desc_cmd);
paul718e3742002-12-13 20:15:29 +00002261 install_element (INTERFACE_NODE, &vtysh_end_all_cmd);
2262 install_element (INTERFACE_NODE, &vtysh_exit_interface_cmd);
2263 install_element (INTERFACE_NODE, &vtysh_quit_interface_cmd);
2264 install_element (CONFIG_NODE, &router_rip_cmd);
2265#ifdef HAVE_IPV6
2266 install_element (CONFIG_NODE, &router_ripng_cmd);
2267#endif
2268 install_element (CONFIG_NODE, &router_ospf_cmd);
2269#ifdef HAVE_IPV6
2270 install_element (CONFIG_NODE, &router_ospf6_cmd);
2271#endif
hassoc25e4582003-12-23 10:39:08 +00002272 install_element (CONFIG_NODE, &router_isis_cmd);
paul718e3742002-12-13 20:15:29 +00002273 install_element (CONFIG_NODE, &router_bgp_cmd);
2274 install_element (BGP_NODE, &address_family_vpnv4_cmd);
2275 install_element (BGP_NODE, &address_family_vpnv4_unicast_cmd);
2276 install_element (BGP_NODE, &address_family_ipv4_unicast_cmd);
2277 install_element (BGP_NODE, &address_family_ipv4_multicast_cmd);
2278#ifdef HAVE_IPV6
2279 install_element (BGP_NODE, &address_family_ipv6_cmd);
2280 install_element (BGP_NODE, &address_family_ipv6_unicast_cmd);
2281#endif
2282 install_element (BGP_VPNV4_NODE, &exit_address_family_cmd);
2283 install_element (BGP_IPV4_NODE, &exit_address_family_cmd);
2284 install_element (BGP_IPV4M_NODE, &exit_address_family_cmd);
2285 install_element (BGP_IPV6_NODE, &exit_address_family_cmd);
2286 install_element (CONFIG_NODE, &key_chain_cmd);
2287 install_element (CONFIG_NODE, &route_map_cmd);
hassoe7168df2004-10-03 20:11:32 +00002288 install_element (CONFIG_NODE, &vtysh_line_vty_cmd);
paul718e3742002-12-13 20:15:29 +00002289 install_element (KEYCHAIN_NODE, &key_cmd);
2290 install_element (KEYCHAIN_NODE, &key_chain_cmd);
2291 install_element (KEYCHAIN_KEY_NODE, &key_chain_cmd);
2292 install_element (CONFIG_NODE, &vtysh_interface_cmd);
paul32d24632003-05-23 09:25:20 +00002293 install_element (CONFIG_NODE, &vtysh_no_interface_cmd);
paul718e3742002-12-13 20:15:29 +00002294 install_element (ENABLE_NODE, &vtysh_show_running_config_cmd);
2295 install_element (ENABLE_NODE, &vtysh_copy_runningconfig_startupconfig_cmd);
2296 install_element (ENABLE_NODE, &vtysh_write_file_cmd);
hasso4a6e2252003-05-25 11:51:29 +00002297 install_element (ENABLE_NODE, &vtysh_write_cmd);
paul718e3742002-12-13 20:15:29 +00002298
hasso95e735b2004-08-26 13:08:30 +00002299 /* "write terminal" command. */
paul718e3742002-12-13 20:15:29 +00002300 install_element (ENABLE_NODE, &vtysh_write_terminal_cmd);
hassoe7168df2004-10-03 20:11:32 +00002301
2302 install_element (CONFIG_NODE, &vtysh_integrated_config_cmd);
2303 install_element (CONFIG_NODE, &no_vtysh_integrated_config_cmd);
paul718e3742002-12-13 20:15:29 +00002304
hasso95e735b2004-08-26 13:08:30 +00002305 /* "write memory" command. */
paul718e3742002-12-13 20:15:29 +00002306 install_element (ENABLE_NODE, &vtysh_write_memory_cmd);
paul718e3742002-12-13 20:15:29 +00002307
hasso34553cc2004-08-27 13:56:39 +00002308 install_element (VIEW_NODE, &vtysh_terminal_length_cmd);
2309 install_element (ENABLE_NODE, &vtysh_terminal_length_cmd);
2310 install_element (VIEW_NODE, &vtysh_terminal_no_length_cmd);
2311 install_element (ENABLE_NODE, &vtysh_terminal_no_length_cmd);
hassof2799e62004-10-28 17:43:11 +00002312 install_element (VIEW_NODE, &vtysh_show_daemons_cmd);
2313 install_element (ENABLE_NODE, &vtysh_show_daemons_cmd);
hasso34553cc2004-08-27 13:56:39 +00002314
paul718e3742002-12-13 20:15:29 +00002315 install_element (VIEW_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002316 install_element (VIEW_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00002317 install_element (VIEW_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002318 install_element (VIEW_NODE, &vtysh_traceroute_ip_cmd);
2319#ifdef HAVE_IPV6
2320 install_element (VIEW_NODE, &vtysh_ping6_cmd);
2321 install_element (VIEW_NODE, &vtysh_traceroute6_cmd);
2322#endif
paul718e3742002-12-13 20:15:29 +00002323 install_element (VIEW_NODE, &vtysh_telnet_cmd);
2324 install_element (VIEW_NODE, &vtysh_telnet_port_cmd);
paul5087df52003-01-25 06:56:09 +00002325 install_element (VIEW_NODE, &vtysh_ssh_cmd);
paul718e3742002-12-13 20:15:29 +00002326 install_element (ENABLE_NODE, &vtysh_ping_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002327 install_element (ENABLE_NODE, &vtysh_ping_ip_cmd);
paul718e3742002-12-13 20:15:29 +00002328 install_element (ENABLE_NODE, &vtysh_traceroute_cmd);
hasso4eeccf12003-06-25 10:49:55 +00002329 install_element (ENABLE_NODE, &vtysh_traceroute_ip_cmd);
2330#ifdef HAVE_IPV6
2331 install_element (ENABLE_NODE, &vtysh_ping6_cmd);
2332 install_element (ENABLE_NODE, &vtysh_traceroute6_cmd);
2333#endif
paul718e3742002-12-13 20:15:29 +00002334 install_element (ENABLE_NODE, &vtysh_telnet_cmd);
2335 install_element (ENABLE_NODE, &vtysh_telnet_port_cmd);
hasso67e29ab2004-08-26 22:21:31 +00002336 install_element (ENABLE_NODE, &vtysh_ssh_cmd);
paul718e3742002-12-13 20:15:29 +00002337 install_element (ENABLE_NODE, &vtysh_start_shell_cmd);
2338 install_element (ENABLE_NODE, &vtysh_start_bash_cmd);
2339 install_element (ENABLE_NODE, &vtysh_start_zsh_cmd);
2340
paul718e3742002-12-13 20:15:29 +00002341 install_element (CONFIG_NODE, &vtysh_log_stdout_cmd);
ajs274a4a42004-12-07 15:39:31 +00002342 install_element (CONFIG_NODE, &vtysh_log_stdout_level_cmd);
paul718e3742002-12-13 20:15:29 +00002343 install_element (CONFIG_NODE, &no_vtysh_log_stdout_cmd);
2344 install_element (CONFIG_NODE, &vtysh_log_file_cmd);
ajs274a4a42004-12-07 15:39:31 +00002345 install_element (CONFIG_NODE, &vtysh_log_file_level_cmd);
paul718e3742002-12-13 20:15:29 +00002346 install_element (CONFIG_NODE, &no_vtysh_log_file_cmd);
ajs274a4a42004-12-07 15:39:31 +00002347 install_element (CONFIG_NODE, &no_vtysh_log_file_level_cmd);
2348 install_element (CONFIG_NODE, &vtysh_log_monitor_cmd);
2349 install_element (CONFIG_NODE, &vtysh_log_monitor_level_cmd);
2350 install_element (CONFIG_NODE, &no_vtysh_log_monitor_cmd);
paul718e3742002-12-13 20:15:29 +00002351 install_element (CONFIG_NODE, &vtysh_log_syslog_cmd);
ajs274a4a42004-12-07 15:39:31 +00002352 install_element (CONFIG_NODE, &vtysh_log_syslog_level_cmd);
paul718e3742002-12-13 20:15:29 +00002353 install_element (CONFIG_NODE, &no_vtysh_log_syslog_cmd);
2354 install_element (CONFIG_NODE, &vtysh_log_trap_cmd);
2355 install_element (CONFIG_NODE, &no_vtysh_log_trap_cmd);
ajs274a4a42004-12-07 15:39:31 +00002356 install_element (CONFIG_NODE, &vtysh_log_facility_cmd);
2357 install_element (CONFIG_NODE, &no_vtysh_log_facility_cmd);
paul718e3742002-12-13 20:15:29 +00002358 install_element (CONFIG_NODE, &vtysh_log_record_priority_cmd);
2359 install_element (CONFIG_NODE, &no_vtysh_log_record_priority_cmd);
hassoe7168df2004-10-03 20:11:32 +00002360
2361 install_element (CONFIG_NODE, &vtysh_service_password_encrypt_cmd);
2362 install_element (CONFIG_NODE, &no_vtysh_service_password_encrypt_cmd);
2363
2364 install_element (CONFIG_NODE, &vtysh_password_cmd);
2365 install_element (CONFIG_NODE, &vtysh_password_text_cmd);
2366 install_element (CONFIG_NODE, &vtysh_enable_password_cmd);
2367 install_element (CONFIG_NODE, &vtysh_enable_password_text_cmd);
2368 install_element (CONFIG_NODE, &no_vtysh_enable_password_cmd);
2369
paul718e3742002-12-13 20:15:29 +00002370}