]> git.proxmox.com Git - mirror_frr.git/blame - vtysh/vtysh.c
nhrpd: implement next hop resolution protocol
[mirror_frr.git] / vtysh / vtysh.c
CommitLineData
718e3744 1/* 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
7c8ff89e
DS
33#include <dirent.h>
34#include <stdio.h>
35#include <string.h>
36
4201dd11 37#include "linklist.h"
718e3744 38#include "command.h"
39#include "memory.h"
039f3a34 40#include "filter.h"
718e3744 41#include "vtysh/vtysh.h"
6099b3b5 42#include "log.h"
320da874 43#include "bgpd/bgp_vty.h"
13460c44 44#include "ns.h"
cd2a8a42 45#include "vrf.h"
718e3744 46
4a1ab8e4
DL
47DEFINE_MTYPE_STATIC(MVTYSH, VTYSH_CMD, "Vtysh cmd copy")
48
718e3744 49/* Struct VTY. */
50struct vty *vty;
51
52/* VTY shell pager name. */
53char *vtysh_pager_name = NULL;
54
55/* VTY shell client structure. */
56struct vtysh_client
57{
58 int fd;
c0e8c16f 59 const char *name;
b1aa147d 60 int flag;
c0e8c16f 61 const char *path;
7c8ff89e
DS
62 struct vtysh_client *next;
63};
64
65struct vtysh_client vtysh_client[] =
66{
67 { .fd = -1, .name = "zebra", .flag = VTYSH_ZEBRA, .path = ZEBRA_VTYSH_PATH, .next = NULL},
68 { .fd = -1, .name = "ripd", .flag = VTYSH_RIPD, .path = RIP_VTYSH_PATH, .next = NULL},
69 { .fd = -1, .name = "ripngd", .flag = VTYSH_RIPNGD, .path = RIPNG_VTYSH_PATH, .next = NULL},
70 { .fd = -1, .name = "ospfd", .flag = VTYSH_OSPFD, .path = OSPF_VTYSH_PATH, .next = NULL},
71 { .fd = -1, .name = "ospf6d", .flag = VTYSH_OSPF6D, .path = OSPF6_VTYSH_PATH, .next = NULL},
4fcbf6e2 72 { .fd = -1, .name = "ldpd", .flag = VTYSH_LDPD, .path = LDP_VTYSH_PATH, .next = NULL},
7c8ff89e
DS
73 { .fd = -1, .name = "bgpd", .flag = VTYSH_BGPD, .path = BGP_VTYSH_PATH, .next = NULL},
74 { .fd = -1, .name = "isisd", .flag = VTYSH_ISISD, .path = ISIS_VTYSH_PATH, .next = NULL},
12e41d03 75 { .fd = -1, .name = "pimd", .flag = VTYSH_PIMD, .path = PIM_VTYSH_PATH, .next = NULL},
2fb975da 76 { .fd = -1, .name = "nhrpd", .flag = VTYSH_NHRPD, .path = NHRP_VTYSH_PATH, .next = NULL},
9473e340 77 { .fd = -1, .name = "watchfrr", .flag = VTYSH_WATCHFRR, .path = WATCHFRR_VTYSH_PATH, .next = NULL},
b1aa147d 78};
79
039eaca3 80enum vtysh_write_integrated vtysh_write_integrated = WRITE_INTEGRATED_UNSPECIFIED;
e7168df4 81
274a4a44 82static void
718e3744 83vclient_close (struct vtysh_client *vclient)
84{
b1aa147d 85 if (vclient->fd >= 0)
86 {
87 fprintf(stderr,
88 "Warning: closing connection to %s because of an I/O error!\n",
89 vclient->name);
90 close (vclient->fd);
91 vclient->fd = -1;
92 }
718e3744 93}
94
f35a5350
DW
95/* Return true if str begins with prefix, else return false */
96static int
97begins_with(const char *str, const char *prefix)
98{
99 if (!str || !prefix)
100 return 0;
101 size_t lenstr = strlen(str);
102 size_t lenprefix = strlen(prefix);
103 if (lenprefix > lenstr)
104 return 0;
105 return strncmp(str, prefix, lenprefix) == 0;
106}
107
7526a182
DL
108/* NB: multiplexed function:
109 * if fp == NULL, this calls vtysh_config_parse_line
110 * if fp != NULL, this prints lines to fp
111 */
274a4a44 112static int
7526a182 113vtysh_client_run (struct vtysh_client *vclient, const char *line, FILE *fp)
718e3744 114{
115 int ret;
7526a182
DL
116 char stackbuf[4096];
117 char *buf = stackbuf;
118 size_t bufsz = sizeof(stackbuf);
119 char *bufvalid, *end = NULL;
120 char terminator[3] = {0, 0, 0};
718e3744 121
122 if (vclient->fd < 0)
123 return CMD_SUCCESS;
124
125 ret = write (vclient->fd, line, strlen (line) + 1);
126 if (ret <= 0)
7526a182 127 goto out_err;
7c8ff89e 128
7526a182
DL
129 bufvalid = buf;
130 do
7c8ff89e 131 {
7526a182
DL
132 ssize_t nread = read (vclient->fd, bufvalid, buf + bufsz - bufvalid);
133
134 if (nread < 0 && (errno == EINTR || errno == EAGAIN))
135 continue;
136
137 if (nread <= 0)
138 {
139 fprintf (stderr, "vtysh: error reading from %s: %s (%d)",
140 vclient->name, safe_strerror(errno), errno);
141 goto out_err;
142 }
143
144 bufvalid += nread;
145
146 end = memmem (buf, bufvalid - buf, terminator, sizeof(terminator));
147 if (end + sizeof(terminator) + 1 > bufvalid)
148 /* found \0\0\0 but return code hasn't been read yet */
149 end = NULL;
150 if (end)
151 ret = end[sizeof(terminator)];
152
153 while (bufvalid > buf && (end > buf || !end))
154 {
155 size_t textlen = (end ? end : bufvalid) - buf;
156 char *eol = memchr (buf, '\n', textlen);
157 if (eol)
158 /* line break */
159 *eol++ = '\0';
160 else if (end == buf)
161 /* no line break, end of input, no text left before end
162 * => don't insert an empty line at the end */
163 break;
164 else if (end)
165 /* no line break, end of input, but some text left */
166 eol = end;
167 else
168 /* continue reading */
169 break;
718e3744 170
7526a182
DL
171 /* eol is at a line end now, either \n => \0 or \0\0\0 */
172 assert(eol && eol <= bufvalid);
718e3744 173
7526a182 174 if (fp)
2852de1c 175 {
7526a182
DL
176 fputs (buf, fp);
177 fputc ('\n', fp);
2852de1c 178 }
179 else
7526a182
DL
180 vtysh_config_parse_line (buf);
181
182 if (eol == end)
183 /* \n\0\0\0 */
184 break;
185
186 memmove (buf, eol, bufvalid - eol);
187 bufvalid -= eol - buf;
2d35a720
DL
188 if (end)
189 end -= eol - buf;
7526a182
DL
190 }
191
192 if (bufvalid == buf + bufsz)
193 {
194 char *new;
195 bufsz *= 2;
196 if (buf == stackbuf)
2852de1c 197 {
7526a182
DL
198 new = XMALLOC (MTYPE_TMP, bufsz);
199 memcpy (new, stackbuf, sizeof(stackbuf));
2852de1c 200 }
7526a182
DL
201 else
202 new = XREALLOC (MTYPE_TMP, buf, bufsz);
2852de1c 203
7526a182
DL
204 bufvalid = bufvalid - buf + new;
205 buf = new;
206 /* if end != NULL, we won't be reading more data... */
207 assert (end == NULL);
208 }
718e3744 209 }
7526a182
DL
210 while (!end);
211 goto out;
212
213out_err:
214 vclient_close (vclient);
215 ret = CMD_SUCCESS;
216out:
217 if (buf != stackbuf)
218 XFREE (MTYPE_TMP, buf);
219 return ret;
718e3744 220}
221
7c8ff89e 222static int
7526a182
DL
223vtysh_client_run_all (struct vtysh_client *head_client, const char *line,
224 int continue_on_err, FILE *fp)
7c8ff89e
DS
225{
226 struct vtysh_client *client;
7526a182 227 int rc, rc_all = CMD_SUCCESS;
7c8ff89e 228
7526a182 229 for (client = head_client; client; client = client->next)
7c8ff89e 230 {
7526a182 231 rc = vtysh_client_run(client, line, fp);
7c8ff89e 232 if (rc != CMD_SUCCESS)
7526a182
DL
233 {
234 if (!continue_on_err)
235 return rc;
236 rc_all = rc;
237 }
7c8ff89e 238 }
7526a182
DL
239 return rc_all;
240}
241
242static int
243vtysh_client_execute (struct vtysh_client *head_client, const char *line,
244 FILE *fp)
245{
246 return vtysh_client_run_all (head_client, line, 0, fp);
247}
248
249static void
250vtysh_client_config (struct vtysh_client *head_client, char *line)
251{
252 vtysh_client_run_all (head_client, line, 1, NULL);
7c8ff89e
DS
253}
254
718e3744 255void
b1aa147d 256vtysh_pager_init (void)
718e3744 257{
5a9c53de 258 char *pager_defined;
259
260 pager_defined = getenv ("VTYSH_PAGER");
261
262 if (pager_defined)
263 vtysh_pager_name = strdup (pager_defined);
264 else
34553cc3 265 vtysh_pager_name = strdup ("more");
718e3744 266}
267
268/* Command execution over the vty interface. */
57fb9748 269static int
dda09522 270vtysh_execute_func (const char *line, int pager)
718e3744 271{
2c4d48bc 272 int ret, cmd_stat;
b1aa147d 273 u_int i;
718e3744 274 vector vline;
17aca20b 275 const struct cmd_element *cmd;
718e3744 276 FILE *fp = NULL;
13bfca7a 277 int closepager = 0;
278 int tried = 0;
279 int saved_ret, saved_node;
718e3744 280
95e735b5 281 /* Split readline string up into the vector. */
718e3744 282 vline = cmd_make_strvec (line);
283
284 if (vline == NULL)
57fb9748 285 return CMD_SUCCESS;
718e3744 286
13bfca7a 287 saved_ret = ret = cmd_execute_command (vline, vty, &cmd, 1);
288 saved_node = vty->node;
289
290 /* If command doesn't succeeded in current node, try to walk up in node tree.
291 * Changing vty->node is enough to try it just out without actual walkup in
292 * the vtysh. */
293 while (ret != CMD_SUCCESS && ret != CMD_SUCCESS_DAEMON && ret != CMD_WARNING
294 && vty->node > CONFIG_NODE)
295 {
296 vty->node = node_parent(vty->node);
297 ret = cmd_execute_command (vline, vty, &cmd, 1);
298 tried++;
299 }
300
301 vty->node = saved_node;
302
303 /* If command succeeded in any other node than current (tried > 0) we have
304 * to move into node in the vtysh where it succeeded. */
305 if (ret == CMD_SUCCESS || ret == CMD_SUCCESS_DAEMON || ret == CMD_WARNING)
306 {
bb86c601 307 if ((saved_node == BGP_VPNV4_NODE || saved_node == BGP_VPNV6_NODE
8b1fb8be 308 || saved_node == BGP_ENCAP_NODE || saved_node == BGP_ENCAPV6_NODE
8ecd3266 309 || saved_node == BGP_IPV4_NODE
57b5b7ed 310 || saved_node == BGP_IPV6_NODE || saved_node == BGP_IPV4M_NODE
14a227b8 311 || saved_node == BGP_IPV6M_NODE || saved_node == BGP_EVPN_NODE)
13bfca7a 312 && (tried == 1))
313 {
314 vtysh_execute("exit-address-family");
315 }
5ff06872
LB
316 else if (saved_node == BGP_VRF_POLICY_NODE && (tried == 1))
317 {
318 vtysh_execute("exit-vrf-policy");
319 }
65efcfce
LB
320 else if ((saved_node == BGP_VNC_DEFAULTS_NODE
321 || saved_node == BGP_VNC_NVE_GROUP_NODE
322 || saved_node == BGP_VNC_L2_GROUP_NODE) && (tried == 1))
323 {
324 vtysh_execute("exit-vnc");
325 }
13bfca7a 326 else if ((saved_node == KEYCHAIN_KEY_NODE) && (tried == 1))
327 {
328 vtysh_execute("exit");
329 }
330 else if (tried)
331 {
332 vtysh_execute ("end");
333 vtysh_execute ("configure terminal");
334 }
335 }
336 /* If command didn't succeed in any node, continue with return value from
337 * first try. */
338 else if (tried)
339 {
340 ret = saved_ret;
341 }
718e3744 342
343 cmd_free_strvec (vline);
344
2c4d48bc 345 cmd_stat = ret;
718e3744 346 switch (ret)
347 {
348 case CMD_WARNING:
349 if (vty->type == VTY_FILE)
4fc01e67 350 fprintf (stdout,"Warning...\n");
718e3744 351 break;
352 case CMD_ERR_AMBIGUOUS:
4fc01e67 353 fprintf (stdout,"%% Ambiguous command.\n");
718e3744 354 break;
355 case CMD_ERR_NO_MATCH:
4fc01e67 356 fprintf (stdout,"%% Unknown command.\n");
718e3744 357 break;
358 case CMD_ERR_INCOMPLETE:
4fc01e67 359 fprintf (stdout,"%% Command incomplete.\n");
718e3744 360 break;
361 case CMD_SUCCESS_DAEMON:
362 {
97b7db2d 363 /* FIXME: Don't open pager for exit commands. popen() causes problems
364 * if exited from vtysh at all. This hack shouldn't cause any problem
365 * but is really ugly. */
366 if (pager && vtysh_pager_name && (strncmp(line, "exit", 4) != 0))
718e3744 367 {
4fc01e67 368 fp = popen (vtysh_pager_name, "w");
718e3744 369 if (fp == NULL)
370 {
a805cc2d 371 perror ("popen failed for pager");
372 fp = stdout;
718e3744 373 }
a805cc2d 374 else
375 closepager=1;
718e3744 376 }
377 else
378 fp = stdout;
379
380 if (! strcmp(cmd->string,"configure terminal"))
381 {
837d16cc 382 for (i = 0; i < array_size(vtysh_client); i++)
b1aa147d 383 {
384 cmd_stat = vtysh_client_execute(&vtysh_client[i], line, fp);
385 if (cmd_stat == CMD_WARNING)
386 break;
387 }
388
718e3744 389 if (cmd_stat)
390 {
b094d260 391 line = "end";
392 vline = cmd_make_strvec (line);
718e3744 393
b094d260 394 if (vline == NULL)
718e3744 395 {
a805cc2d 396 if (pager && vtysh_pager_name && fp && closepager)
718e3744 397 {
398 if (pclose (fp) == -1)
399 {
a805cc2d 400 perror ("pclose failed for pager");
718e3744 401 }
402 fp = NULL;
403 }
57fb9748 404 return CMD_SUCCESS;
718e3744 405 }
406
87d683b0 407 ret = cmd_execute_command (vline, vty, &cmd, 1);
b094d260 408 cmd_free_strvec (vline);
409 if (ret != CMD_SUCCESS_DAEMON)
410 break;
718e3744 411 }
412 else
413 if (cmd->func)
414 {
415 (*cmd->func) (cmd, vty, 0, NULL);
416 break;
b094d260 417 }
718e3744 418 }
419
b1aa147d 420 cmd_stat = CMD_SUCCESS;
837d16cc 421 for (i = 0; i < array_size(vtysh_client); i++)
b1aa147d 422 {
423 if (cmd->daemon & vtysh_client[i].flag)
424 {
425 cmd_stat = vtysh_client_execute(&vtysh_client[i], line, fp);
426 if (cmd_stat != CMD_SUCCESS)
427 break;
428 }
429 }
430 if (cmd_stat != CMD_SUCCESS)
431 break;
432
718e3744 433 if (cmd->func)
434 (*cmd->func) (cmd, vty, 0, NULL);
435 }
436 }
a805cc2d 437 if (pager && vtysh_pager_name && fp && closepager)
718e3744 438 {
439 if (pclose (fp) == -1)
440 {
a805cc2d 441 perror ("pclose failed for pager");
718e3744 442 }
443 fp = NULL;
444 }
57fb9748 445 return cmd_stat;
718e3744 446}
447
57fb9748 448int
dda09522 449vtysh_execute_no_pager (const char *line)
718e3744 450{
57fb9748 451 return vtysh_execute_func (line, 0);
718e3744 452}
453
57fb9748 454int
dda09522 455vtysh_execute (const char *line)
718e3744 456{
57fb9748 457 return vtysh_execute_func (line, 1);
718e3744 458}
459
a5b89524
DW
460static char *
461trim (char *s)
462{
463 size_t size;
464 char *end;
465
466 size = strlen(s);
467
468 if (!size)
469 return s;
470
471 end = s + size - 1;
472 while (end >= s && isspace(*end))
473 end--;
474 *(end + 1) = '\0';
475
476 while (*s && isspace(*s))
477 s++;
478
479 return s;
480}
481
0846286b 482int
c0e8c16f 483vtysh_mark_file (const char *filename)
0846286b
DS
484{
485 struct vty *vty;
486 FILE *confp = NULL;
487 int ret;
488 vector vline;
489 int tried = 0;
17aca20b 490 const struct cmd_element *cmd;
0846286b
DS
491 int saved_ret, prev_node;
492 int lineno = 0;
a5b89524
DW
493 char *vty_buf_copy = NULL;
494 char *vty_buf_trimmed = NULL;
0846286b
DS
495
496 if (strncmp("-", filename, 1) == 0)
497 confp = stdin;
498 else
499 confp = fopen (filename, "r");
500
501 if (confp == NULL)
1db63918
DS
502 {
503 fprintf (stderr, "%% Can't open config file %s due to '%s'.\n",
504 filename, safe_strerror (errno));
505 return (CMD_ERR_NO_FILE);
506 }
0846286b
DS
507
508 vty = vty_new ();
509 vty->fd = 0; /* stdout */
510 vty->type = VTY_TERM;
511 vty->node = CONFIG_NODE;
512
513 vtysh_execute_no_pager ("enable");
514 vtysh_execute_no_pager ("configure terminal");
4a1ab8e4 515 vty_buf_copy = XCALLOC (MTYPE_VTYSH_CMD, VTY_BUFSIZ);
0846286b
DS
516
517 while (fgets (vty->buf, VTY_BUFSIZ, confp))
518 {
519 lineno++;
520 tried = 0;
a5b89524
DW
521 strcpy(vty_buf_copy, vty->buf);
522 vty_buf_trimmed = trim(vty_buf_copy);
0846286b 523
a5b89524 524 if (vty_buf_trimmed[0] == '!' || vty_buf_trimmed[0] == '#')
0846286b
DS
525 {
526 fprintf(stdout, "%s", vty->buf);
527 continue;
528 }
529
530 /* Split readline string up into the vector. */
531 vline = cmd_make_strvec (vty->buf);
532
533 if (vline == NULL)
534 {
535 fprintf(stdout, "%s", vty->buf);
536 continue;
537 }
538
a5b89524
DW
539 /* Ignore the "end" lines, we will generate these where appropriate */
540 if (strlen(vty_buf_trimmed) == 3 && strncmp("end", vty_buf_trimmed, 3) == 0)
541 {
542 continue;
543 }
544
0846286b
DS
545 prev_node = vty->node;
546 saved_ret = ret = cmd_execute_command_strict (vline, vty, &cmd);
547
548 /* If command doesn't succeeded in current node, try to walk up in node tree.
549 * Changing vty->node is enough to try it just out without actual walkup in
550 * the vtysh. */
551 while (ret != CMD_SUCCESS && ret != CMD_SUCCESS_DAEMON && ret != CMD_WARNING
552 && vty->node > CONFIG_NODE)
553 {
554 vty->node = node_parent(vty->node);
555 ret = cmd_execute_command_strict (vline, vty, &cmd);
556 tried++;
557 }
558
559 /* If command succeeded in any other node than current (tried > 0) we have
560 * to move into node in the vtysh where it succeeded. */
561 if (ret == CMD_SUCCESS || ret == CMD_SUCCESS_DAEMON || ret == CMD_WARNING)
562 {
563 if ((prev_node == BGP_VPNV4_NODE || prev_node == BGP_IPV4_NODE
564 || prev_node == BGP_IPV6_NODE || prev_node == BGP_IPV4M_NODE
14a227b8
PG
565 || prev_node == BGP_IPV6M_NODE || prev_node == BGP_VPNV6_NODE
566 || prev_node == BGP_EVPN_NODE)
0846286b
DS
567 && (tried == 1))
568 {
569 fprintf(stdout, "exit-address-family\n");
570 }
571 else if ((prev_node == KEYCHAIN_KEY_NODE) && (tried == 1))
572 {
573 fprintf(stdout, "exit\n");
574 }
575 else if (tried)
576 {
577 fprintf(stdout, "end\n");
578 }
579 }
580 /* If command didn't succeed in any node, continue with return value from
581 * first try. */
582 else if (tried)
583 {
584 ret = saved_ret;
585 vty->node = prev_node;
586 }
587
588 cmd_free_strvec (vline);
589 switch (ret)
590 {
591 case CMD_WARNING:
592 if (vty->type == VTY_FILE)
593 fprintf (stderr,"line %d: Warning...: %s\n", lineno, vty->buf);
594 fclose(confp);
595 vty_close(vty);
4a1ab8e4 596 XFREE(MTYPE_VTYSH_CMD, vty_buf_copy);
1db63918 597 return CMD_WARNING;
0846286b
DS
598 case CMD_ERR_AMBIGUOUS:
599 fprintf (stderr,"line %d: %% Ambiguous command: %s\n", lineno, vty->buf);
600 fclose(confp);
601 vty_close(vty);
4a1ab8e4 602 XFREE(MTYPE_VTYSH_CMD, vty_buf_copy);
1db63918 603 return CMD_ERR_AMBIGUOUS;
0846286b
DS
604 case CMD_ERR_NO_MATCH:
605 fprintf (stderr,"line %d: %% Unknown command: %s\n", lineno, vty->buf);
606 fclose(confp);
607 vty_close(vty);
4a1ab8e4 608 XFREE(MTYPE_VTYSH_CMD, vty_buf_copy);
1db63918 609 return CMD_ERR_NO_MATCH;
0846286b
DS
610 case CMD_ERR_INCOMPLETE:
611 fprintf (stderr,"line %d: %% Command incomplete: %s\n", lineno, vty->buf);
612 fclose(confp);
613 vty_close(vty);
4a1ab8e4 614 XFREE(MTYPE_VTYSH_CMD, vty_buf_copy);
1db63918 615 return CMD_ERR_INCOMPLETE;
0846286b
DS
616 case CMD_SUCCESS:
617 fprintf(stdout, "%s", vty->buf);
618 break;
619 case CMD_SUCCESS_DAEMON:
620 {
621 u_int i;
622 int cmd_stat = CMD_SUCCESS;
623
624 fprintf(stdout, "%s", vty->buf);
625 for (i = 0; i < array_size(vtysh_client); i++)
626 {
627 if (cmd->daemon & vtysh_client[i].flag)
628 {
629 cmd_stat = vtysh_client_execute (&vtysh_client[i],
630 vty->buf, stdout);
631 if (cmd_stat != CMD_SUCCESS)
632 break;
633 }
634 }
635 if (cmd_stat != CMD_SUCCESS)
636 break;
637
638 if (cmd->func)
639 (*cmd->func) (cmd, vty, 0, NULL);
640 }
641 }
642 }
643 /* This is the end */
644 fprintf(stdout, "end\n");
645 vty_close(vty);
4a1ab8e4 646 XFREE(MTYPE_VTYSH_CMD, vty_buf_copy);
0846286b
DS
647
648 if (confp != stdin)
649 fclose(confp);
650
651 return (0);
652}
653
718e3744 654/* Configration make from file. */
3221dca8 655int
718e3744 656vtysh_config_from_file (struct vty *vty, FILE *fp)
657{
658 int ret;
17aca20b 659 const struct cmd_element *cmd;
9117f21e 660 int lineno = 0;
3221dca8 661 int retcode = CMD_SUCCESS;
718e3744 662
663 while (fgets (vty->buf, VTY_BUFSIZ, fp))
664 {
9117f21e 665 lineno++;
718e3744 666
bed578b8 667 ret = command_config_read_one_line (vty, &cmd, 1);
718e3744 668
669 switch (ret)
670 {
671 case CMD_WARNING:
672 if (vty->type == VTY_FILE)
1db63918
DS
673 fprintf (stderr,"line %d: Warning[%d]...: %s\n", lineno, vty->node, vty->buf);
674 retcode = CMD_WARNING; /* once we have an error, we remember & return that */
718e3744 675 break;
676 case CMD_ERR_AMBIGUOUS:
1db63918
DS
677 fprintf (stderr,"line %d: %% Ambiguous command[%d]: %s\n", lineno, vty->node, vty->buf);
678 retcode = CMD_ERR_AMBIGUOUS; /* once we have an error, we remember & return that */
718e3744 679 break;
680 case CMD_ERR_NO_MATCH:
1db63918
DS
681 fprintf (stderr,"line %d: %% Unknown command[%d]: %s", lineno, vty->node, vty->buf);
682 retcode = CMD_ERR_NO_MATCH; /* once we have an error, we remember & return that */
718e3744 683 break;
684 case CMD_ERR_INCOMPLETE:
1db63918
DS
685 fprintf (stderr,"line %d: %% Command incomplete[%d]: %s\n", lineno, vty->node, vty->buf);
686 retcode = CMD_ERR_INCOMPLETE; /* once we have an error, we remember & return that */
718e3744 687 break;
688 case CMD_SUCCESS_DAEMON:
689 {
b1aa147d 690 u_int i;
691 int cmd_stat = CMD_SUCCESS;
692
837d16cc 693 for (i = 0; i < array_size(vtysh_client); i++)
b1aa147d 694 {
44316fef 695 if (cmd->daemon & vtysh_client[i].flag)
b1aa147d 696 {
697 cmd_stat = vtysh_client_execute (&vtysh_client[i],
698 vty->buf, stdout);
279c6956
DS
699 /*
700 * CMD_WARNING - Can mean that the command was
701 * parsed successfully but it was already entered
702 * in a few spots. As such if we receive a
703 * CMD_WARNING from a daemon we shouldn't stop
704 * talking to the other daemons for the particular
705 * command.
706 */
707 if (cmd_stat != CMD_SUCCESS && cmd_stat != CMD_WARNING)
1db63918
DS
708 {
709 fprintf (stderr, "line %d: Failure to communicate[%d] to %s, line: %s\n",
710 lineno, cmd_stat, vtysh_client[i].name, vty->buf);
711 break;
712 }
b1aa147d 713 }
714 }
715 if (cmd_stat != CMD_SUCCESS)
716 break;
717
718e3744 718 if (cmd->func)
719 (*cmd->func) (cmd, vty, 0, NULL);
720 }
721 }
722 }
3221dca8
DS
723
724 return (retcode);
718e3744 725}
726
727/* We don't care about the point of the cursor when '?' is typed. */
4201dd11 728static int
b1aa147d 729vtysh_rl_describe (void)
718e3744 730{
731 int ret;
dda09522 732 unsigned int i;
718e3744 733 vector vline;
734 vector describe;
735 int width;
cd40b329 736 struct cmd_token *token;
718e3744 737
738 vline = cmd_make_strvec (rl_line_buffer);
739
740 /* In case of '> ?'. */
741 if (vline == NULL)
742 {
743 vline = vector_init (1);
9f7d541a 744 vector_set (vline, NULL);
718e3744 745 }
746 else
747 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
9f7d541a 748 vector_set (vline, NULL);
718e3744 749
750 describe = cmd_describe_command (vline, vty, &ret);
751
4fc01e67 752 fprintf (stdout,"\n");
718e3744 753
754 /* Ambiguous and no match error. */
755 switch (ret)
756 {
757 case CMD_ERR_AMBIGUOUS:
758 cmd_free_strvec (vline);
4fc01e67 759 fprintf (stdout,"%% Ambiguous command.\n");
718e3744 760 rl_on_new_line ();
761 return 0;
762 break;
763 case CMD_ERR_NO_MATCH:
764 cmd_free_strvec (vline);
4fc01e67 765 fprintf (stdout,"%% There is no matched command.\n");
718e3744 766 rl_on_new_line ();
767 return 0;
768 break;
769 }
770
771 /* Get width of command string. */
772 width = 0;
55468c86 773 for (i = 0; i < vector_active (describe); i++)
cd40b329 774 if ((token = vector_slot (describe, i)) != NULL)
718e3744 775 {
c3f24f06
QY
776 if (token->text[0] == '\0')
777 continue;
718e3744 778
c3f24f06 779 int len = strlen (token->text);
718e3744 780
c3f24f06
QY
781 if (width < len)
782 width = len;
718e3744 783 }
784
55468c86 785 for (i = 0; i < vector_active (describe); i++)
cd40b329 786 if ((token = vector_slot (describe, i)) != NULL)
718e3744 787 {
cd40b329 788 if (! token->desc)
4fc01e67 789 fprintf (stdout," %-s\n",
c3f24f06 790 token->text);
718e3744 791 else
4fc01e67 792 fprintf (stdout," %-*s %s\n",
b094d260 793 width,
c3f24f06 794 token->text,
cd40b329 795 token->desc);
718e3744 796 }
797
798 cmd_free_strvec (vline);
799 vector_free (describe);
800
801 rl_on_new_line();
802
803 return 0;
804}
805
95e735b5 806/* Result of cmd_complete_command() call will be stored here
807 * and used in new_completion() in order to put the space in
808 * correct places only. */
718e3744 809int complete_status;
810
274a4a44 811static char *
dfc0d9ba 812command_generator (const char *text, int state)
718e3744 813{
814 vector vline;
815 static char **matched = NULL;
816 static int index = 0;
817
818 /* First call. */
819 if (! state)
820 {
821 index = 0;
822
823 if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE)
824 return NULL;
825
826 vline = cmd_make_strvec (rl_line_buffer);
827 if (vline == NULL)
828 return NULL;
829
830 if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1]))
9f7d541a 831 vector_set (vline, NULL);
718e3744 832
833 matched = cmd_complete_command (vline, vty, &complete_status);
039dc612 834 cmd_free_strvec (vline);
718e3744 835 }
836
837 if (matched && matched[index])
838 return matched[index++];
839
66d29a54
DL
840 XFREE (MTYPE_TMP, matched);
841 matched = NULL;
842
718e3744 843 return NULL;
844}
845
274a4a44 846static char **
718e3744 847new_completion (char *text, int start, int end)
848{
849 char **matches;
850
dfc0d9ba 851 matches = rl_completion_matches (text, command_generator);
718e3744 852
853 if (matches)
854 {
855 rl_point = rl_end;
67e7a212
CF
856 if (complete_status != CMD_COMPLETE_FULL_MATCH)
857 /* only append a space on full match */
858 rl_completion_append_character = '\0';
718e3744 859 }
860
861 return matches;
862}
863
95e735b5 864/* Vty node structures. */
7fc626de 865static struct cmd_node bgp_node =
718e3744 866{
867 BGP_NODE,
868 "%s(config-router)# ",
869};
870
7fc626de 871static struct cmd_node rip_node =
718e3744 872{
873 RIP_NODE,
874 "%s(config-router)# ",
875};
876
7fc626de 877static struct cmd_node isis_node =
c25e458a 878{
879 ISIS_NODE,
880 "%s(config-router)# ",
c25e458a 881};
882
7fc626de 883static struct cmd_node interface_node =
718e3744 884{
885 INTERFACE_NODE,
886 "%s(config-if)# ",
887};
888
13460c44
FL
889static struct cmd_node ns_node =
890{
891 NS_NODE,
892 "%s(config-logical-router)# ",
893};
894
e9d94ea7
DS
895static struct cmd_node vrf_node =
896{
897 VRF_NODE,
898 "%s(config-vrf)# ",
899};
900
7fc626de 901static struct cmd_node rmap_node =
95e735b5 902{
903 RMAP_NODE,
904 "%s(config-route-map)# "
905};
906
7fc626de 907static struct cmd_node zebra_node =
95e735b5 908{
909 ZEBRA_NODE,
910 "%s(config-router)# "
911};
912
7fc626de 913static struct cmd_node bgp_vpnv4_node =
95e735b5 914{
915 BGP_VPNV4_NODE,
916 "%s(config-router-af)# "
917};
918
8ecd3266 919static struct cmd_node bgp_vpnv6_node =
920{
921 BGP_VPNV6_NODE,
922 "%s(config-router-af)# "
923};
924
8b1fb8be
LB
925static struct cmd_node bgp_encap_node =
926{
927 BGP_ENCAP_NODE,
928 "%s(config-router-af)# "
929};
930
931static struct cmd_node bgp_encapv6_node =
932{
933 BGP_ENCAPV6_NODE,
934 "%s(config-router-af)# "
935};
936
7fc626de 937static struct cmd_node bgp_ipv4_node =
95e735b5 938{
939 BGP_IPV4_NODE,
940 "%s(config-router-af)# "
941};
942
7fc626de 943static struct cmd_node bgp_ipv4m_node =
95e735b5 944{
945 BGP_IPV4M_NODE,
946 "%s(config-router-af)# "
947};
948
7fc626de 949static struct cmd_node bgp_ipv6_node =
95e735b5 950{
951 BGP_IPV6_NODE,
952 "%s(config-router-af)# "
953};
954
7fc626de 955static struct cmd_node bgp_ipv6m_node =
57b5b7ed 956{
957 BGP_IPV6M_NODE,
958 "%s(config-router-af)# "
959};
960
14a227b8
PG
961static struct cmd_node bgp_evpn_node =
962{
963 BGP_EVPN_NODE,
964 "%s(config-router-af)# "
965};
966
65efcfce
LB
967static struct cmd_node bgp_vnc_defaults_node =
968{
969 BGP_VNC_DEFAULTS_NODE,
970 "%s(config-router-vnc-defaults)# "
971};
972
973static struct cmd_node bgp_vnc_nve_group_node =
974{
975 BGP_VNC_NVE_GROUP_NODE,
976 "%s(config-router-vnc-nve-group)# "
977};
978
5ff06872
LB
979static struct cmd_node bgp_vrf_policy_node = {
980 BGP_VRF_POLICY_NODE,
981 "%s(config-router-vrf-policy)# "
982};
983
65efcfce
LB
984static struct cmd_node bgp_vnc_l2_group_node =
985{
986 BGP_VNC_L2_GROUP_NODE,
987 "%s(config-router-vnc-l2-group)# "
988};
989
7fc626de 990static struct cmd_node ospf_node =
95e735b5 991{
992 OSPF_NODE,
993 "%s(config-router)# "
994};
995
7fc626de 996static struct cmd_node ripng_node =
95e735b5 997{
998 RIPNG_NODE,
999 "%s(config-router)# "
1000};
1001
7fc626de 1002static struct cmd_node ospf6_node =
95e735b5 1003{
1004 OSPF6_NODE,
1005 "%s(config-ospf6)# "
1006};
1007
4fcbf6e2
RW
1008static struct cmd_node ldp_node =
1009{
1010 LDP_NODE,
1011 "%s(config-ldp)# "
1012};
1013
1014static struct cmd_node ldp_ipv4_node =
1015{
1016 LDP_IPV4_NODE,
1017 "%s(config-ldp-af)# "
1018};
1019
1020static struct cmd_node ldp_ipv6_node =
1021{
1022 LDP_IPV6_NODE,
1023 "%s(config-ldp-af)# "
1024};
1025
1026static struct cmd_node ldp_ipv4_iface_node =
1027{
1028 LDP_IPV4_IFACE_NODE,
1029 "%s(config-ldp-af-if)# "
1030};
1031
1032static struct cmd_node ldp_ipv6_iface_node =
1033{
1034 LDP_IPV6_IFACE_NODE,
1035 "%s(config-ldp-af-if)# "
1036};
1037
1038static struct cmd_node ldp_l2vpn_node =
1039{
1040 LDP_L2VPN_NODE,
1041 "%s(config-l2vpn)# "
1042};
1043
1044static struct cmd_node ldp_pseudowire_node =
1045{
1046 LDP_PSEUDOWIRE_NODE,
1047 "%s(config-l2vpn-pw)# "
1048};
1049
7fc626de 1050static struct cmd_node keychain_node =
95e735b5 1051{
1052 KEYCHAIN_NODE,
1053 "%s(config-keychain)# "
1054};
1055
7fc626de 1056static struct cmd_node keychain_key_node =
95e735b5 1057{
1058 KEYCHAIN_KEY_NODE,
1059 "%s(config-keychain-key)# "
1060};
1061
16f1b9ee
OD
1062struct cmd_node link_params_node =
1063{
1064 LINK_PARAMS_NODE,
1065 "%s(config-link-params)# ",
1066};
1067
e7168df4 1068/* Defined in lib/vty.c */
1069extern struct cmd_node vty_node;
1070
95e735b5 1071/* When '^Z' is received from vty, move down to the enable mode. */
4201dd11 1072static int
b1aa147d 1073vtysh_end (void)
95e735b5 1074{
1075 switch (vty->node)
1076 {
1077 case VIEW_NODE:
1078 case ENABLE_NODE:
1079 /* Nothing to do. */
1080 break;
1081 default:
1082 vty->node = ENABLE_NODE;
1083 break;
1084 }
1085 return CMD_SUCCESS;
1086}
1087
4a96e944 1088DEFUNSH (VTYSH_REALLYALL,
95e735b5 1089 vtysh_end_all,
1090 vtysh_end_all_cmd,
1091 "end",
e7168df4 1092 "End current mode and change to enable mode\n")
95e735b5 1093{
4289546d 1094 return vtysh_end ();
95e735b5 1095}
1096
718e3744 1097DEFUNSH (VTYSH_BGPD,
1098 router_bgp,
1099 router_bgp_cmd,
a98d33ab 1100 "router bgp [(1-4294967295) [<view|vrf> WORD]]",
718e3744 1101 ROUTER_STR
1102 BGP_STR
a98d33ab
QY
1103 AS_STR
1104 "BGP view\nBGP VRF\n"
1105 "View/VRF name\n")
718e3744 1106{
1107 vty->node = BGP_NODE;
1108 return CMD_SUCCESS;
1109}
1110
1111DEFUNSH (VTYSH_BGPD,
1112 address_family_vpnv4,
1113 address_family_vpnv4_cmd,
843d75b1 1114 "address-family vpnv4 [unicast]",
718e3744 1115 "Enter Address Family command mode\n"
843d75b1 1116 "Address Family\n"
718e3744 1117 "Address Family Modifier\n")
1118{
1119 vty->node = BGP_VPNV4_NODE;
1120 return CMD_SUCCESS;
1121}
1122
8ecd3266 1123DEFUNSH (VTYSH_BGPD,
1124 address_family_vpnv6,
1125 address_family_vpnv6_cmd,
843d75b1 1126 "address-family vpnv6 [unicast]",
8ecd3266 1127 "Enter Address Family command mode\n"
843d75b1 1128 "Address Family\n"
8ecd3266 1129 "Address Family Modifier\n")
1130{
1131 vty->node = BGP_VPNV6_NODE;
1132 return CMD_SUCCESS;
1133}
1134
8b1fb8be
LB
1135DEFUNSH (VTYSH_BGPD,
1136 address_family_encapv4,
1137 address_family_encapv4_cmd,
4c4ff4c1 1138 "address-family <encap|encapv4>",
8b1fb8be 1139 "Enter Address Family command mode\n"
4c4ff4c1 1140 "Address Family\n"
843d75b1 1141 "Address Family\n")
8b1fb8be
LB
1142{
1143 vty->node = BGP_ENCAP_NODE;
1144 return CMD_SUCCESS;
1145}
1146
1147DEFUNSH (VTYSH_BGPD,
1148 address_family_encapv6,
1149 address_family_encapv6_cmd,
1150 "address-family encapv6",
1151 "Enter Address Family command mode\n"
843d75b1 1152 "Address Family\n")
8b1fb8be
LB
1153{
1154 vty->node = BGP_ENCAPV6_NODE;
1155 return CMD_SUCCESS;
1156}
1157
718e3744 1158DEFUNSH (VTYSH_BGPD,
1159 address_family_ipv4_unicast,
1160 address_family_ipv4_unicast_cmd,
c7f1274b 1161 "address-family ipv4 [<unicast|multicast|vpn|encap>]",
718e3744 1162 "Enter Address Family command mode\n"
843d75b1 1163 "Address Family\n"
c7f1274b
DS
1164 "Address Family Modifier\n"
1165 "Address Family Modifier\n"
1166 "Address Family Modifier\n"
1167 "Address Family Modifier\n")
718e3744 1168{
c7f1274b
DS
1169 int idx = 0;
1170
1171 if (argv_find (argv, argc, "multicast", &idx))
1172 vty->node = BGP_IPV4M_NODE;
1173
1174 else if (argv_find (argv, argc, "encap", &idx))
1175 vty->node = BGP_ENCAP_NODE;
1176
1177 else if (argv_find (argv, argc, "vpn", &idx))
1178 vty->node = BGP_VPNV4_NODE;
1179
1180 else
1181 vty->node = BGP_IPV4_NODE;
718e3744 1182
718e3744 1183 return CMD_SUCCESS;
1184}
1185
1186DEFUNSH (VTYSH_BGPD,
1187 address_family_ipv6,
1188 address_family_ipv6_cmd,
c7f1274b 1189 "address-family ipv6 [<unicast|multicast|vpn|encap>]",
718e3744 1190 "Enter Address Family command mode\n"
843d75b1 1191 "Address Family\n"
c7f1274b
DS
1192 "Address Family Modifier\n"
1193 "Address Family Modifier\n"
1194 "Address Family Modifier\n"
1195 "Address Family Modifier\n")
718e3744 1196{
c7f1274b
DS
1197 int idx = 0;
1198
1199 if (argv_find (argv, argc, "multicast", &idx))
1200 vty->node = BGP_IPV6M_NODE;
1201
1202 else if (argv_find (argv, argc, "encap", &idx))
1203 vty->node = BGP_ENCAPV6_NODE;
1204
1205 else if (argv_find (argv, argc, "vpn", &idx))
1206 vty->node = BGP_VPNV6_NODE;
1207
1208 else
1209 vty->node = BGP_IPV6_NODE;
718e3744 1210
57b5b7ed 1211 return CMD_SUCCESS;
1212}
1213
14a227b8
PG
1214DEFUNSH (VTYSH_BGPD,
1215 address_family_evpn,
1216 address_family_evpn_cmd,
b194703e 1217 "address-family <l2vpn evpn>",
14a227b8 1218 "Enter Address Family command mode\n"
61a51962
PG
1219 "EVPN Address family\n"
1220 "Layer2 VPN Address family\n"
1221 "Ethernet Virtual Private Network Subsequent Address Family\n")
14a227b8
PG
1222{
1223#if defined(HAVE_EVPN)
1224 vty->node = BGP_EVPN_NODE;
1225#endif /* HAVE_EVPN */
1226 return CMD_SUCCESS;
1227}
1228
87ab4aec 1229#if defined (ENABLE_BGP_VNC)
65efcfce
LB
1230DEFUNSH (VTYSH_BGPD,
1231 vnc_defaults,
1232 vnc_defaults_cmd,
1233 "vnc defaults",
1234 "VNC/RFP related configuration\n"
1235 "Configure default NVE group\n")
1236{
1237 vty->node = BGP_VNC_DEFAULTS_NODE;
1238 return CMD_SUCCESS;
1239}
1240
1241DEFUNSH (VTYSH_BGPD,
1242 vnc_nve_group,
1243 vnc_nve_group_cmd,
1244 "vnc nve-group NAME",
1245 "VNC/RFP related configuration\n"
1246 "Configure a NVE group\n"
1247 "Group name\n")
1248{
1249 vty->node = BGP_VNC_NVE_GROUP_NODE;
1250 return CMD_SUCCESS;
1251}
1252
5ff06872
LB
1253DEFUNSH (VTYSH_BGPD,
1254 vnc_vrf_policy,
1255 vnc_vrf_policy_cmd,
1256 "vrf-policy NAME",
1257 "Configure a VRF policy group\n"
1258 "Group name\n")
1259{
1260 vty->node = BGP_VRF_POLICY_NODE;
1261 return CMD_SUCCESS;
1262}
1263
65efcfce
LB
1264DEFUNSH (VTYSH_BGPD,
1265 vnc_l2_group,
1266 vnc_l2_group_cmd,
1267 "vnc l2-group NAME",
1268 "VNC/RFP related configuration\n"
1269 "Configure a L2 group\n"
1270 "Group name\n")
1271{
1272 vty->node = BGP_VNC_L2_GROUP_NODE;
1273 return CMD_SUCCESS;
1274}
87ab4aec 1275#endif
65efcfce 1276
718e3744 1277DEFUNSH (VTYSH_RIPD,
1278 key_chain,
1279 key_chain_cmd,
1280 "key chain WORD",
1281 "Authentication key management\n"
1282 "Key-chain management\n"
1283 "Key-chain name\n")
1284{
1285 vty->node = KEYCHAIN_NODE;
1286 return CMD_SUCCESS;
1287}
1288
1289DEFUNSH (VTYSH_RIPD,
1290 key,
1291 key_cmd,
a98d33ab 1292 "key (0-2147483647)",
718e3744 1293 "Configure a key\n"
1294 "Key identifier number\n")
1295{
1296 vty->node = KEYCHAIN_KEY_NODE;
1297 return CMD_SUCCESS;
1298}
1299
1300DEFUNSH (VTYSH_RIPD,
1301 router_rip,
1302 router_rip_cmd,
1303 "router rip",
1304 ROUTER_STR
1305 "RIP")
1306{
1307 vty->node = RIP_NODE;
1308 return CMD_SUCCESS;
1309}
1310
1311DEFUNSH (VTYSH_RIPNGD,
1312 router_ripng,
1313 router_ripng_cmd,
1314 "router ripng",
1315 ROUTER_STR
1316 "RIPng")
1317{
1318 vty->node = RIPNG_NODE;
1319 return CMD_SUCCESS;
1320}
1321
1322DEFUNSH (VTYSH_OSPFD,
1323 router_ospf,
1324 router_ospf_cmd,
a98d33ab 1325 "router ospf [(1-65535)]",
718e3744 1326 "Enable a routing process\n"
a98d33ab
QY
1327 "Start OSPF configuration\n"
1328 "Instance ID\n")
718e3744 1329{
1330 vty->node = OSPF_NODE;
1331 return CMD_SUCCESS;
1332}
1333
1334DEFUNSH (VTYSH_OSPF6D,
1335 router_ospf6,
1336 router_ospf6_cmd,
1337 "router ospf6",
16cedbb0 1338 ROUTER_STR
718e3744 1339 OSPF6_STR)
1340{
1341 vty->node = OSPF6_NODE;
1342 return CMD_SUCCESS;
1343}
1344
87ab4aec 1345#if defined (HAVE_LDPD)
4fcbf6e2
RW
1346DEFUNSH (VTYSH_LDPD,
1347 ldp_mpls_ldp,
1348 ldp_mpls_ldp_cmd,
1349 "mpls ldp",
1350 "Global MPLS configuration subcommands\n"
1351 "Label Distribution Protocol\n")
1352{
1353 vty->node = LDP_NODE;
1354 return CMD_SUCCESS;
1355}
1356
1357DEFUNSH (VTYSH_LDPD,
1358 ldp_address_family_ipv4,
1359 ldp_address_family_ipv4_cmd,
1360 "address-family ipv4",
1361 "Configure Address Family and its parameters\n"
1362 "IPv4\n")
1363{
1364 vty->node = LDP_IPV4_NODE;
1365 return CMD_SUCCESS;
1366}
1367
1368DEFUNSH (VTYSH_LDPD,
1369 ldp_address_family_ipv6,
1370 ldp_address_family_ipv6_cmd,
1371 "address-family ipv6",
1372 "Configure Address Family and its parameters\n"
1373 "IPv6\n")
1374{
1375 vty->node = LDP_IPV6_NODE;
1376 return CMD_SUCCESS;
1377}
1378
1379DEFUNSH (VTYSH_LDPD,
1380 ldp_interface_ifname,
1381 ldp_interface_ifname_cmd,
1382 "interface IFNAME",
1383 "Enable LDP on an interface and enter interface submode\n"
1384 "Interface's name\n")
1385{
1386 switch (vty->node)
1387 {
1388 case LDP_IPV4_NODE:
1389 vty->node = LDP_IPV4_IFACE_NODE;
1390 break;
1391 case LDP_IPV6_NODE:
1392 vty->node = LDP_IPV6_IFACE_NODE;
1393 break;
1394 default:
1395 break;
1396 }
1397
1398 return CMD_SUCCESS;
1399}
1400
1401DEFUNSH (VTYSH_LDPD,
1402 ldp_l2vpn_word_type_vpls,
1403 ldp_l2vpn_word_type_vpls_cmd,
1404 "l2vpn WORD type vpls",
1405 "Configure l2vpn commands\n"
1406 "L2VPN name\n"
1407 "L2VPN type\n"
1408 "Virtual Private LAN Service\n")
1409{
1410 vty->node = LDP_L2VPN_NODE;
1411 return CMD_SUCCESS;
1412}
1413
1414DEFUNSH (VTYSH_LDPD,
1415 ldp_member_pseudowire_ifname,
1416 ldp_member_pseudowire_ifname_cmd,
1417 "member pseudowire IFNAME",
1418 "L2VPN member configuration\n"
1419 "Pseudowire interface\n"
1420 "Interface's name\n")
1421{
1422 vty->node = LDP_PSEUDOWIRE_NODE;
1423 return CMD_SUCCESS;
1424}
87ab4aec 1425#endif
4fcbf6e2 1426
c25e458a 1427DEFUNSH (VTYSH_ISISD,
b094d260 1428 router_isis,
1429 router_isis_cmd,
1430 "router isis WORD",
1431 ROUTER_STR
1432 "ISO IS-IS\n"
1433 "ISO Routing area tag")
c25e458a 1434{
1435 vty->node = ISIS_NODE;
1436 return CMD_SUCCESS;
1437}
1438
718e3744 1439DEFUNSH (VTYSH_RMAP,
dd2ecded
DS
1440 vtysh_route_map,
1441 vtysh_route_map_cmd,
a98d33ab 1442 "route-map WORD <deny|permit> (1-65535)",
718e3744 1443 "Create route-map or enter route-map command mode\n"
1444 "Route map tag\n"
1445 "Route map denies set operations\n"
1446 "Route map permits set operations\n"
1447 "Sequence to insert to/delete from existing route-map entry\n")
1448{
1449 vty->node = RMAP_NODE;
1450 return CMD_SUCCESS;
1451}
1452
e7168df4 1453DEFUNSH (VTYSH_ALL,
1454 vtysh_line_vty,
1455 vtysh_line_vty_cmd,
1456 "line vty",
1457 "Configure a terminal line\n"
1458 "Virtual terminal\n")
1459{
1460 vty->node = VTY_NODE;
1461 return CMD_SUCCESS;
1462}
1463
4a96e944
DL
1464DEFUNSH (VTYSH_REALLYALL,
1465 vtysh_enable,
718e3744 1466 vtysh_enable_cmd,
1467 "enable",
1468 "Turn on privileged mode command\n")
1469{
1470 vty->node = ENABLE_NODE;
1471 return CMD_SUCCESS;
1472}
1473
4a96e944
DL
1474DEFUNSH (VTYSH_REALLYALL,
1475 vtysh_disable,
718e3744 1476 vtysh_disable_cmd,
1477 "disable",
1478 "Turn off privileged mode command\n")
1479{
1480 if (vty->node == ENABLE_NODE)
1481 vty->node = VIEW_NODE;
1482 return CMD_SUCCESS;
1483}
1484
4a96e944 1485DEFUNSH (VTYSH_REALLYALL,
718e3744 1486 vtysh_config_terminal,
1487 vtysh_config_terminal_cmd,
1488 "configure terminal",
1489 "Configuration from vty interface\n"
1490 "Configuration terminal\n")
1491{
1492 vty->node = CONFIG_NODE;
1493 return CMD_SUCCESS;
1494}
1495
274a4a44 1496static int
718e3744 1497vtysh_exit (struct vty *vty)
1498{
1499 switch (vty->node)
1500 {
1501 case VIEW_NODE:
1502 case ENABLE_NODE:
1503 exit (0);
1504 break;
1505 case CONFIG_NODE:
1506 vty->node = ENABLE_NODE;
1507 break;
1508 case INTERFACE_NODE:
13460c44 1509 case NS_NODE:
e9d94ea7 1510 case VRF_NODE:
718e3744 1511 case ZEBRA_NODE:
1512 case BGP_NODE:
1513 case RIP_NODE:
1514 case RIPNG_NODE:
1515 case OSPF_NODE:
1516 case OSPF6_NODE:
4fcbf6e2
RW
1517 case LDP_NODE:
1518 case LDP_L2VPN_NODE:
c25e458a 1519 case ISIS_NODE:
718e3744 1520 case MASC_NODE:
1521 case RMAP_NODE:
1522 case VTY_NODE:
1523 case KEYCHAIN_NODE:
2a56df97 1524 vtysh_execute("end");
1525 vtysh_execute("configure terminal");
718e3744 1526 vty->node = CONFIG_NODE;
1527 break;
1528 case BGP_VPNV4_NODE:
8ecd3266 1529 case BGP_VPNV6_NODE:
8b1fb8be
LB
1530 case BGP_ENCAP_NODE:
1531 case BGP_ENCAPV6_NODE:
718e3744 1532 case BGP_IPV4_NODE:
1533 case BGP_IPV4M_NODE:
1534 case BGP_IPV6_NODE:
57b5b7ed 1535 case BGP_IPV6M_NODE:
5ff06872 1536 case BGP_VRF_POLICY_NODE:
14a227b8 1537 case BGP_EVPN_NODE:
65efcfce
LB
1538 case BGP_VNC_DEFAULTS_NODE:
1539 case BGP_VNC_NVE_GROUP_NODE:
1540 case BGP_VNC_L2_GROUP_NODE:
718e3744 1541 vty->node = BGP_NODE;
1542 break;
4fcbf6e2
RW
1543 case LDP_IPV4_NODE:
1544 case LDP_IPV6_NODE:
1545 vty->node = LDP_NODE;
1546 break;
1547 case LDP_IPV4_IFACE_NODE:
1548 vty->node = LDP_IPV4_NODE;
1549 break;
1550 case LDP_IPV6_IFACE_NODE:
1551 vty->node = LDP_IPV6_NODE;
1552 break;
1553 case LDP_PSEUDOWIRE_NODE:
1554 vty->node = LDP_L2VPN_NODE;
1555 break;
718e3744 1556 case KEYCHAIN_KEY_NODE:
1557 vty->node = KEYCHAIN_NODE;
1558 break;
16f1b9ee
OD
1559 case LINK_PARAMS_NODE:
1560 vty->node = INTERFACE_NODE;
1561 break;
718e3744 1562 default:
1563 break;
1564 }
1565 return CMD_SUCCESS;
1566}
1567
4a96e944 1568DEFUNSH (VTYSH_REALLYALL,
718e3744 1569 vtysh_exit_all,
1570 vtysh_exit_all_cmd,
1571 "exit",
1572 "Exit current mode and down to previous mode\n")
1573{
1574 return vtysh_exit (vty);
1575}
1576
a98d33ab
QY
1577DEFUNSH (VTYSH_ALL,
1578 vtysh_quit_all,
1579 vtysh_quit_all_cmd,
1580 "quit",
1581 "Exit current mode and down to previous mode\n")
1582{
1583 return vtysh_exit_all (self, vty, argc, argv);
1584}
718e3744 1585
1586DEFUNSH (VTYSH_BGPD,
1587 exit_address_family,
1588 exit_address_family_cmd,
1589 "exit-address-family",
1590 "Exit from Address Family configuration mode\n")
1591{
1592 if (vty->node == BGP_IPV4_NODE
1593 || vty->node == BGP_IPV4M_NODE
1594 || vty->node == BGP_VPNV4_NODE
8ecd3266 1595 || vty->node == BGP_VPNV6_NODE
8b1fb8be
LB
1596 || vty->node == BGP_ENCAP_NODE
1597 || vty->node == BGP_ENCAPV6_NODE
57b5b7ed 1598 || vty->node == BGP_IPV6_NODE
1599 || vty->node == BGP_IPV6M_NODE)
718e3744 1600 vty->node = BGP_NODE;
1601 return CMD_SUCCESS;
1602}
1603
65efcfce
LB
1604DEFUNSH (VTYSH_BGPD,
1605 exit_vnc_config,
1606 exit_vnc_config_cmd,
1607 "exit-vnc",
1608 "Exit from VNC configuration mode\n")
1609{
1610 if (vty->node == BGP_VNC_DEFAULTS_NODE
1611 || vty->node == BGP_VNC_NVE_GROUP_NODE
1612 || vty->node == BGP_VNC_L2_GROUP_NODE)
1613 vty->node = BGP_NODE;
1614 return CMD_SUCCESS;
1615}
1616
5ff06872
LB
1617DEFUNSH (VTYSH_BGPD,
1618 exit_vrf_policy,
1619 exit_vrf_policy_cmd,
1620 "exit-vrf-policy",
1621 "Exit from VRF configuration mode\n")
1622{
1623 if (vty->node == BGP_VRF_POLICY_NODE)
1624 vty->node = BGP_NODE;
1625 return CMD_SUCCESS;
1626}
1627
718e3744 1628DEFUNSH (VTYSH_RIPD,
1629 vtysh_exit_ripd,
1630 vtysh_exit_ripd_cmd,
1631 "exit",
1632 "Exit current mode and down to previous mode\n")
1633{
1634 return vtysh_exit (vty);
1635}
1636
a98d33ab
QY
1637DEFUNSH (VTYSH_RIPD,
1638 vtysh_quit_ripd,
1639 vtysh_quit_ripd_cmd,
1640 "quit",
1641 "Exit current mode and down to previous mode\n")
1642{
1643 return vtysh_exit_ripd (self, vty, argc, argv);
1644}
718e3744 1645
68980084 1646DEFUNSH (VTYSH_RIPNGD,
b094d260 1647 vtysh_exit_ripngd,
1648 vtysh_exit_ripngd_cmd,
1649 "exit",
1650 "Exit current mode and down to previous mode\n")
68980084 1651{
1652 return vtysh_exit (vty);
1653}
1654
a98d33ab
QY
1655DEFUNSH (VTYSH_RIPNGD,
1656 vtysh_quit_ripngd,
1657 vtysh_quit_ripngd_cmd,
1658 "quit",
1659 "Exit current mode and down to previous mode\n")
1660{
1661 return vtysh_exit_ripngd (self, vty, argc, argv);
1662}
68980084 1663
718e3744 1664DEFUNSH (VTYSH_RMAP,
1665 vtysh_exit_rmap,
1666 vtysh_exit_rmap_cmd,
1667 "exit",
1668 "Exit current mode and down to previous mode\n")
1669{
1670 return vtysh_exit (vty);
1671}
1672
a98d33ab
QY
1673DEFUNSH (VTYSH_RMAP,
1674 vtysh_quit_rmap,
1675 vtysh_quit_rmap_cmd,
1676 "quit",
1677 "Exit current mode and down to previous mode\n")
1678{
1679 return vtysh_exit_rmap (self, vty, argc, argv);
1680}
718e3744 1681
1682DEFUNSH (VTYSH_BGPD,
1683 vtysh_exit_bgpd,
1684 vtysh_exit_bgpd_cmd,
1685 "exit",
1686 "Exit current mode and down to previous mode\n")
1687{
1688 return vtysh_exit (vty);
1689}
1690
a98d33ab
QY
1691DEFUNSH (VTYSH_BGPD,
1692 vtysh_quit_bgpd,
1693 vtysh_quit_bgpd_cmd,
1694 "quit",
1695 "Exit current mode and down to previous mode\n")
1696{
1697 return vtysh_exit_bgpd (self, vty, argc, argv);
1698}
718e3744 1699
1700DEFUNSH (VTYSH_OSPFD,
1701 vtysh_exit_ospfd,
1702 vtysh_exit_ospfd_cmd,
1703 "exit",
1704 "Exit current mode and down to previous mode\n")
1705{
1706 return vtysh_exit (vty);
1707}
1708
a98d33ab
QY
1709DEFUNSH (VTYSH_OSPFD,
1710 vtysh_quit_ospfd,
1711 vtysh_quit_ospfd_cmd,
1712 "quit",
1713 "Exit current mode and down to previous mode\n")
1714{
1715 return vtysh_exit_ospfd (self, vty, argc, argv);
1716}
718e3744 1717
68980084 1718DEFUNSH (VTYSH_OSPF6D,
b094d260 1719 vtysh_exit_ospf6d,
1720 vtysh_exit_ospf6d_cmd,
1721 "exit",
1722 "Exit current mode and down to previous mode\n")
68980084 1723{
1724 return vtysh_exit (vty);
1725}
1726
a98d33ab
QY
1727DEFUNSH (VTYSH_OSPF6D,
1728 vtysh_quit_ospf6d,
1729 vtysh_quit_ospf6d_cmd,
1730 "quit",
1731 "Exit current mode and down to previous mode\n")
1732{
1733 return vtysh_exit_ospf6d (self, vty, argc, argv);
1734}
68980084 1735
87ab4aec 1736#if defined (HAVE_LDPD)
4fcbf6e2
RW
1737DEFUNSH (VTYSH_LDPD,
1738 vtysh_exit_ldpd,
1739 vtysh_exit_ldpd_cmd,
1740 "exit",
1741 "Exit current mode and down to previous mode\n")
1742{
1743 return vtysh_exit (vty);
1744}
1745
1746ALIAS (vtysh_exit_ldpd,
1747 vtysh_quit_ldpd_cmd,
1748 "quit",
1749 "Exit current mode and down to previous mode\n")
87ab4aec 1750#endif
4fcbf6e2 1751
c25e458a 1752DEFUNSH (VTYSH_ISISD,
b094d260 1753 vtysh_exit_isisd,
1754 vtysh_exit_isisd_cmd,
1755 "exit",
1756 "Exit current mode and down to previous mode\n")
c25e458a 1757{
1758 return vtysh_exit (vty);
1759}
1760
a98d33ab
QY
1761DEFUNSH (VTYSH_ISISD,
1762 vtysh_quit_isisd,
1763 vtysh_quit_isisd_cmd,
1764 "quit",
1765 "Exit current mode and down to previous mode\n")
1766{
1767 return vtysh_exit_isisd (self, vty, argc, argv);
1768}
c25e458a 1769
e7168df4 1770DEFUNSH (VTYSH_ALL,
1771 vtysh_exit_line_vty,
1772 vtysh_exit_line_vty_cmd,
1773 "exit",
1774 "Exit current mode and down to previous mode\n")
1775{
1776 return vtysh_exit (vty);
1777}
1778
a98d33ab
QY
1779DEFUNSH (VTYSH_ALL,
1780 vtysh_quit_line_vty,
1781 vtysh_quit_line_vty_cmd,
1782 "quit",
1783 "Exit current mode and down to previous mode\n")
1784{
1785 return vtysh_exit_line_vty (self, vty, argc, argv);
1786}
e7168df4 1787
95e735b5 1788DEFUNSH (VTYSH_INTERFACE,
718e3744 1789 vtysh_interface,
1790 vtysh_interface_cmd,
a98d33ab 1791 "interface IFNAME [vrf NAME]",
718e3744 1792 "Select an interface to configure\n"
a98d33ab
QY
1793 "Interface's name\n"
1794 VRF_CMD_HELP_STR)
718e3744 1795{
1796 vty->node = INTERFACE_NODE;
1797 return CMD_SUCCESS;
1798}
1799
95e735b5 1800/* TODO Implement "no interface command in isisd. */
4fcbf6e2 1801DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_LDPD,
32d2463c 1802 vtysh_no_interface_cmd,
1803 "no interface IFNAME",
1804 NO_STR
1805 "Delete a pseudo interface's configuration\n"
1806 "Interface's name\n")
1807
cd2a8a42
FL
1808DEFSH (VTYSH_ZEBRA,
1809 vtysh_no_interface_vrf_cmd,
199d90a1 1810 "no interface IFNAME vrf NAME",
cd2a8a42
FL
1811 NO_STR
1812 "Delete a pseudo interface's configuration\n"
1813 "Interface's name\n"
1814 VRF_CMD_HELP_STR)
1815
13460c44
FL
1816DEFUNSH (VTYSH_NS,
1817 vtysh_ns,
1818 vtysh_ns_cmd,
a98d33ab 1819 "logical-router (1-65535) ns NAME",
13460c44
FL
1820 "Enable a logical-router\n"
1821 "Specify the logical-router indentifier\n"
1822 "The Name Space\n"
1823 "The file name in " NS_RUN_DIR ", or a full pathname\n")
1824{
1825 vty->node = NS_NODE;
1826 return CMD_SUCCESS;
1827}
1828
e9d94ea7
DS
1829DEFUNSH (VTYSH_VRF,
1830 vtysh_vrf,
1831 vtysh_vrf_cmd,
1832 "vrf NAME",
1833 "Select a VRF to configure\n"
1834 "VRF's name\n")
1835{
1836 vty->node = VRF_NODE;
1837 return CMD_SUCCESS;
1838}
1839
1840DEFSH (VTYSH_ZEBRA,
1841 vtysh_no_vrf_cmd,
1842 "no vrf NAME",
1843 NO_STR
1844 "Delete a pseudo vrf's configuration\n"
1845 "VRF's name\n")
1846
13460c44
FL
1847DEFUNSH (VTYSH_NS,
1848 vtysh_exit_ns,
1849 vtysh_exit_ns_cmd,
1850 "exit",
1851 "Exit current mode and down to previous mode\n")
1852{
1853 return vtysh_exit (vty);
1854}
1855
a98d33ab
QY
1856DEFUNSH (VTYSH_NS,
1857 vtysh_quit_ns,
1858 vtysh_quit_ns_cmd,
1859 "quit",
1860 "Exit current mode and down to previous mode\n")
1861{
030204c7 1862 return vtysh_exit_ns(self, vty, argc, argv);
a98d33ab 1863}
13460c44 1864
e9d94ea7
DS
1865DEFUNSH (VTYSH_VRF,
1866 vtysh_exit_vrf,
1867 vtysh_exit_vrf_cmd,
1868 "exit",
1869 "Exit current mode and down to previous mode\n")
1870{
1871 return vtysh_exit (vty);
1872}
1873
a98d33ab
QY
1874DEFUNSH (VTYSH_VRF,
1875 vtysh_quit_vrf,
1876 vtysh_quit_vrf_cmd,
1877 "quit",
1878 "Exit current mode and down to previous mode\n")
1879{
1880 return vtysh_exit_vrf (self, vty, argc, argv);
1881}
e9d94ea7 1882
95e735b5 1883/* TODO Implement interface description commands in ripngd, ospf6d
1884 * and isisd. */
4fcbf6e2 1885DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD|VTYSH_LDPD,
dd2ecded 1886 vtysh_interface_desc_cmd,
e961923c 1887 "description LINE...",
338a9916 1888 "Interface specific description\n"
1889 "Characters describing this interface\n")
464dc8da 1890
1891DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD,
dd2ecded 1892 vtysh_no_interface_desc_cmd,
464dc8da 1893 "no description",
1894 NO_STR
1895 "Interface specific description\n")
338a9916 1896
95e735b5 1897DEFUNSH (VTYSH_INTERFACE,
718e3744 1898 vtysh_exit_interface,
1899 vtysh_exit_interface_cmd,
1900 "exit",
1901 "Exit current mode and down to previous mode\n")
1902{
1903 return vtysh_exit (vty);
1904}
1905
a98d33ab
QY
1906DEFUNSH (VTYSH_INTERFACE,
1907 vtysh_quit_interface,
1908 vtysh_quit_interface_cmd,
1909 "quit",
1910 "Exit current mode and down to previous mode\n")
1911{
1912 return vtysh_exit_interface (self, vty, argc, argv);
1913}
718e3744 1914
0f69b58c
DS
1915DEFUN (vtysh_show_thread,
1916 vtysh_show_thread_cmd,
1917 "show thread cpu [FILTER]",
1918 SHOW_STR
1919 "Thread information\n"
1920 "Thread CPU usage\n"
1921 "Display filter (rwtexb)\n")
1922{
abddf075 1923 int idx_filter = 3;
0f69b58c
DS
1924 unsigned int i;
1925 int ret = CMD_SUCCESS;
1926 char line[100];
1927
bfbc035b 1928 sprintf(line, "show thread cpu %s\n", (argc == 4) ? argv[idx_filter]->arg : "");
0f69b58c
DS
1929 for (i = 0; i < array_size(vtysh_client); i++)
1930 if ( vtysh_client[i].fd >= 0 )
1931 {
1932 fprintf (stdout, "Thread statistics for %s:\n",
1933 vtysh_client[i].name);
1934 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1935 fprintf (stdout,"\n");
1936 }
1937 return ret;
1938}
1939
1940DEFUN (vtysh_show_work_queues,
1941 vtysh_show_work_queues_cmd,
1942 "show work-queues",
1943 SHOW_STR
1944 "Work Queue information\n")
1945{
1946 unsigned int i;
1947 int ret = CMD_SUCCESS;
1948 char line[] = "show work-queues\n";
1949
1950 for (i = 0; i < array_size(vtysh_client); i++)
1951 if ( vtysh_client[i].fd >= 0 )
1952 {
1953 fprintf (stdout, "Work queue statistics for %s:\n",
1954 vtysh_client[i].name);
1955 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
1956 fprintf (stdout,"\n");
1957 }
1958
1959 return ret;
1960}
1961
b47b0a84
DS
1962DEFUN (vtysh_show_work_queues_daemon,
1963 vtysh_show_work_queues_daemon_cmd,
6147e2c6 1964 "show work-queues <zebra|ripd|ripngd|ospfd|ospf6d|bgpd|isisd>",
b47b0a84
DS
1965 SHOW_STR
1966 "Work Queue information\n"
1967 "For the zebra daemon\n"
1968 "For the rip daemon\n"
1969 "For the ripng daemon\n"
1970 "For the ospf daemon\n"
1971 "For the ospfv6 daemon\n"
1972 "For the bgp daemon\n"
1973 "For the isis daemon\n")
1974{
bfbc035b 1975 int idx_protocol = 2;
b47b0a84
DS
1976 unsigned int i;
1977 int ret = CMD_SUCCESS;
1978
1979 for (i = 0; i < array_size(vtysh_client); i++)
1980 {
6d681bd8 1981 if (strmatch(vtysh_client[i].name, argv[idx_protocol]->text))
b47b0a84
DS
1982 break;
1983 }
1984
1985 ret = vtysh_client_execute(&vtysh_client[i], "show work-queues\n", stdout);
1986
1987 return ret;
1988}
1989
16f1b9ee
OD
1990DEFUNSH (VTYSH_ZEBRA,
1991 vtysh_link_params,
1992 vtysh_link_params_cmd,
1993 "link-params",
1994 LINK_PARAMS_STR
1995 )
1996{
1997 vty->node = LINK_PARAMS_NODE;
1998 return CMD_SUCCESS;
1999}
2000
03f99d9a
DS
2001DEFUNSH (VTYSH_ZEBRA,
2002 exit_link_params,
2003 exit_link_params_cmd,
2004 "exit-link-params",
2005 "Exit from Link Params configuration node\n")
2006{
2007 if (vty->node == LINK_PARAMS_NODE)
2008 vty->node = INTERFACE_NODE;
2009 return CMD_SUCCESS;
2010}
2011
362b4031
PJ
2012/* Memory */
2013DEFUN (vtysh_show_memory,
2014 vtysh_show_memory_cmd,
2015 "show memory",
2016 SHOW_STR
2017 "Memory statistics\n")
2018{
2019 unsigned int i;
2020 int ret = CMD_SUCCESS;
2021 char line[] = "show memory\n";
2022
837d16cc 2023 for (i = 0; i < array_size(vtysh_client); i++)
362b4031
PJ
2024 if ( vtysh_client[i].fd >= 0 )
2025 {
2026 fprintf (stdout, "Memory statistics for %s:\n",
2027 vtysh_client[i].name);
2028 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
2029 fprintf (stdout,"\n");
2030 }
2031
2032 return ret;
2033}
2034
95e735b5 2035/* Logging commands. */
dbf7d13d
PJ
2036DEFUN (vtysh_show_logging,
2037 vtysh_show_logging_cmd,
2038 "show logging",
2039 SHOW_STR
2040 "Show current logging configuration\n")
2041{
2042 unsigned int i;
2043 int ret = CMD_SUCCESS;
2044 char line[] = "show logging\n";
2045
837d16cc 2046 for (i = 0; i < array_size(vtysh_client); i++)
4150f33e
PJ
2047 if ( vtysh_client[i].fd >= 0 )
2048 {
2049 fprintf (stdout,"Logging configuration for %s:\n",
2050 vtysh_client[i].name);
2051 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
2052 fprintf (stdout,"\n");
2053 }
2054
dbf7d13d
PJ
2055 return ret;
2056}
2057
95e735b5 2058DEFUNSH (VTYSH_ALL,
2059 vtysh_log_stdout,
2060 vtysh_log_stdout_cmd,
2061 "log stdout",
2062 "Logging control\n"
274a4a44 2063 "Set stdout logging level\n")
2064{
2065 return CMD_SUCCESS;
2066}
2067
2068DEFUNSH (VTYSH_ALL,
2069 vtysh_log_stdout_level,
2070 vtysh_log_stdout_level_cmd,
199d90a1 2071 "log stdout <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
274a4a44 2072 "Logging control\n"
2073 "Set stdout logging level\n"
2074 LOG_LEVEL_DESC)
95e735b5 2075{
2076 return CMD_SUCCESS;
2077}
2078
2079DEFUNSH (VTYSH_ALL,
2080 no_vtysh_log_stdout,
2081 no_vtysh_log_stdout_cmd,
274a4a44 2082 "no log stdout [LEVEL]",
95e735b5 2083 NO_STR
2084 "Logging control\n"
274a4a44 2085 "Cancel logging to stdout\n"
2086 "Logging level\n")
95e735b5 2087{
2088 return CMD_SUCCESS;
2089}
2090
2091DEFUNSH (VTYSH_ALL,
2092 vtysh_log_file,
2093 vtysh_log_file_cmd,
2094 "log file FILENAME",
2095 "Logging control\n"
2096 "Logging to file\n"
2097 "Logging filename\n")
2098{
2099 return CMD_SUCCESS;
2100}
2101
274a4a44 2102DEFUNSH (VTYSH_ALL,
2103 vtysh_log_file_level,
2104 vtysh_log_file_level_cmd,
199d90a1 2105 "log file FILENAME <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
274a4a44 2106 "Logging control\n"
2107 "Logging to file\n"
2108 "Logging filename\n"
2109 LOG_LEVEL_DESC)
2110{
2111 return CMD_SUCCESS;
2112}
2113
95e735b5 2114DEFUNSH (VTYSH_ALL,
2115 no_vtysh_log_file,
2116 no_vtysh_log_file_cmd,
a98d33ab 2117 "no log file [FILENAME [LEVEL]]",
95e735b5 2118 NO_STR
2119 "Logging control\n"
2120 "Cancel logging to file\n"
a98d33ab
QY
2121 "Logging file name\n"
2122 "Logging level\n")
95e735b5 2123{
2124 return CMD_SUCCESS;
2125}
2126
274a4a44 2127DEFUNSH (VTYSH_ALL,
2128 vtysh_log_monitor,
2129 vtysh_log_monitor_cmd,
e83a9414 2130 "log monitor [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
274a4a44 2131 "Logging control\n"
2132 "Set terminal line (monitor) logging level\n"
a98d33ab 2133 LOG_LEVEL_DESC)
274a4a44 2134{
2135 return CMD_SUCCESS;
2136}
2137
2138DEFUNSH (VTYSH_ALL,
2139 no_vtysh_log_monitor,
2140 no_vtysh_log_monitor_cmd,
2141 "no log monitor [LEVEL]",
2142 NO_STR
2143 "Logging control\n"
2144 "Disable terminal line (monitor) logging\n"
2145 "Logging level\n")
2146{
2147 return CMD_SUCCESS;
2148}
2149
95e735b5 2150DEFUNSH (VTYSH_ALL,
2151 vtysh_log_syslog,
2152 vtysh_log_syslog_cmd,
199d90a1 2153 "log syslog <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
274a4a44 2154 "Logging control\n"
2155 "Set syslog logging level\n"
a98d33ab 2156 LOG_LEVEL_DESC)
95e735b5 2157{
2158 return CMD_SUCCESS;
2159}
2160
2161DEFUNSH (VTYSH_ALL,
2162 no_vtysh_log_syslog,
2163 no_vtysh_log_syslog_cmd,
274a4a44 2164 "no log syslog [LEVEL]",
95e735b5 2165 NO_STR
2166 "Logging control\n"
274a4a44 2167 "Cancel logging to syslog\n"
2168 "Logging level\n")
95e735b5 2169{
2170 return CMD_SUCCESS;
2171}
2172
2173DEFUNSH (VTYSH_ALL,
274a4a44 2174 vtysh_log_facility,
2175 vtysh_log_facility_cmd,
199d90a1 2176 "log facility <kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|local0|local1|local2|local3|local4|local5|local6|local7>",
95e735b5 2177 "Logging control\n"
274a4a44 2178 "Facility parameter for syslog messages\n"
2179 LOG_FACILITY_DESC)
2180
95e735b5 2181{
2182 return CMD_SUCCESS;
2183}
2184
2185DEFUNSH (VTYSH_ALL,
274a4a44 2186 no_vtysh_log_facility,
2187 no_vtysh_log_facility_cmd,
2188 "no log facility [FACILITY]",
95e735b5 2189 NO_STR
2190 "Logging control\n"
274a4a44 2191 "Reset syslog facility to default (daemon)\n"
2192 "Syslog facility\n")
2193
2194{
2195 return CMD_SUCCESS;
2196}
2197
2198DEFUNSH_DEPRECATED (VTYSH_ALL,
2199 vtysh_log_trap,
2200 vtysh_log_trap_cmd,
199d90a1 2201 "log trap <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
274a4a44 2202 "Logging control\n"
2203 "(Deprecated) Set logging level and default for all destinations\n"
2204 LOG_LEVEL_DESC)
2205
2206{
2207 return CMD_SUCCESS;
2208}
2209
2210DEFUNSH_DEPRECATED (VTYSH_ALL,
2211 no_vtysh_log_trap,
2212 no_vtysh_log_trap_cmd,
2213 "no log trap [LEVEL]",
2214 NO_STR
2215 "Logging control\n"
2216 "Permit all logging information\n"
2217 "Logging level\n")
95e735b5 2218{
2219 return CMD_SUCCESS;
2220}
2221
2222DEFUNSH (VTYSH_ALL,
2223 vtysh_log_record_priority,
2224 vtysh_log_record_priority_cmd,
2225 "log record-priority",
2226 "Logging control\n"
2227 "Log the priority of the message within the message\n")
2228{
2229 return CMD_SUCCESS;
2230}
2231
2232DEFUNSH (VTYSH_ALL,
2233 no_vtysh_log_record_priority,
2234 no_vtysh_log_record_priority_cmd,
2235 "no log record-priority",
2236 NO_STR
2237 "Logging control\n"
2238 "Do not log the priority of the message within the message\n")
2239{
2240 return CMD_SUCCESS;
2241}
2242
c749b722
AS
2243DEFUNSH (VTYSH_ALL,
2244 vtysh_log_timestamp_precision,
2245 vtysh_log_timestamp_precision_cmd,
a98d33ab 2246 "log timestamp precision (0-6)",
c749b722
AS
2247 "Logging control\n"
2248 "Timestamp configuration\n"
2249 "Set the timestamp precision\n"
2250 "Number of subsecond digits\n")
2251{
2252 return CMD_SUCCESS;
2253}
2254
2255DEFUNSH (VTYSH_ALL,
2256 no_vtysh_log_timestamp_precision,
2257 no_vtysh_log_timestamp_precision_cmd,
2258 "no log timestamp precision",
2259 NO_STR
2260 "Logging control\n"
2261 "Timestamp configuration\n"
2262 "Reset the timestamp precision to the default value of 0\n")
2263{
2264 return CMD_SUCCESS;
2265}
2266
e7168df4 2267DEFUNSH (VTYSH_ALL,
2268 vtysh_service_password_encrypt,
2269 vtysh_service_password_encrypt_cmd,
2270 "service password-encryption",
2271 "Set up miscellaneous service\n"
2272 "Enable encrypted passwords\n")
2273{
2274 return CMD_SUCCESS;
2275}
2276
2277DEFUNSH (VTYSH_ALL,
2278 no_vtysh_service_password_encrypt,
2279 no_vtysh_service_password_encrypt_cmd,
2280 "no service password-encryption",
2281 NO_STR
2282 "Set up miscellaneous service\n"
2283 "Enable encrypted passwords\n")
2284{
2285 return CMD_SUCCESS;
2286}
2287
2288DEFUNSH (VTYSH_ALL,
2289 vtysh_config_password,
2290 vtysh_password_cmd,
a98d33ab 2291 "password (8-8) WORD",
e7168df4 2292 "Assign the terminal connection password\n"
2293 "Specifies a HIDDEN password will follow\n"
2294 "dummy string \n"
2295 "The HIDDEN line password string\n")
2296{
2297 return CMD_SUCCESS;
2298}
2299
2300DEFUNSH (VTYSH_ALL,
2301 vtysh_password_text,
2302 vtysh_password_text_cmd,
2303 "password LINE",
2304 "Assign the terminal connection password\n"
2305 "The UNENCRYPTED (cleartext) line password\n")
2306{
2307 return CMD_SUCCESS;
2308}
2309
2310DEFUNSH (VTYSH_ALL,
2311 vtysh_config_enable_password,
2312 vtysh_enable_password_cmd,
a98d33ab 2313 "enable password (8-8) WORD",
e7168df4 2314 "Modify enable password parameters\n"
2315 "Assign the privileged level password\n"
2316 "Specifies a HIDDEN password will follow\n"
e7168df4 2317 "The HIDDEN 'enable' password string\n")
2318{
2319 return CMD_SUCCESS;
2320}
2321
2322DEFUNSH (VTYSH_ALL,
2323 vtysh_enable_password_text,
2324 vtysh_enable_password_text_cmd,
2325 "enable password LINE",
2326 "Modify enable password parameters\n"
2327 "Assign the privileged level password\n"
2328 "The UNENCRYPTED (cleartext) 'enable' password\n")
2329{
2330 return CMD_SUCCESS;
2331}
2332
2333DEFUNSH (VTYSH_ALL,
2334 no_vtysh_config_enable_password,
2335 no_vtysh_enable_password_cmd,
2336 "no enable password",
2337 NO_STR
2338 "Modify enable password parameters\n"
2339 "Assign the privileged level password\n")
2340{
2341 return CMD_SUCCESS;
2342}
2343
718e3744 2344DEFUN (vtysh_write_terminal,
2345 vtysh_write_terminal_cmd,
e52702f2 2346 "write terminal [<zebra|ripd|ripngd|ospfd|ospf6d|ldpd|bgpd|isisd|pimd>]",
718e3744 2347 "Write running configuration to memory, network, or terminal\n"
066242b5
QY
2348 "Write to terminal\n"
2349 "For the zebra daemon\n"
2350 "For the rip daemon\n"
2351 "For the ripng daemon\n"
2352 "For the ospf daemon\n"
2353 "For the ospfv6 daemon\n"
16cedbb0 2354 "For the ldpd daemon\n"
066242b5
QY
2355 "For the bgp daemon\n"
2356 "For the isis daemon\n"
2357 "For the pim daemon\n")
718e3744 2358{
066242b5
QY
2359 u_int i;
2360 char line[] = "write terminal\n";
718e3744 2361 FILE *fp = NULL;
2362
2363 if (vtysh_pager_name)
2364 {
4fc01e67 2365 fp = popen (vtysh_pager_name, "w");
718e3744 2366 if (fp == NULL)
066242b5
QY
2367 {
2368 perror ("popen");
2369 exit (1);
2370 }
718e3744 2371 }
2372 else
2373 fp = stdout;
2374
2375 vty_out (vty, "Building configuration...%s", VTY_NEWLINE);
2376 vty_out (vty, "%sCurrent configuration:%s", VTY_NEWLINE,
066242b5 2377 VTY_NEWLINE);
e7168df4 2378 vty_out (vty, "!%s", VTY_NEWLINE);
718e3744 2379
066242b5
QY
2380 for (i = 0; i < array_size(vtysh_client); i++)
2381 if ((argc < 3 ) || (strmatch (vtysh_client[i].name, argv[2]->text)))
2382 vtysh_client_config (&vtysh_client[i], line);
2383
e7168df4 2384 /* Integrate vtysh specific configuration. */
2385 vtysh_config_write ();
2386
718e3744 2387 vtysh_config_dump (fp);
2388
2389 if (vtysh_pager_name && fp)
2390 {
2391 fflush (fp);
2392 if (pclose (fp) == -1)
066242b5
QY
2393 {
2394 perror ("pclose");
2395 exit (1);
2396 }
718e3744 2397 fp = NULL;
2398 }
2399
6e79f8bb 2400 vty_out (vty, "end%s", VTY_NEWLINE);
718e3744 2401 return CMD_SUCCESS;
2402}
2403
a98d33ab
QY
2404DEFUN (vtysh_show_running_config,
2405 vtysh_show_running_config_cmd,
e52702f2 2406 "show running-config [<zebra|ripd|ripngd|ospfd|ospf6d|ldpd|bgpd|isisd|pimd>]",
a98d33ab
QY
2407 SHOW_STR
2408 "Current operating configuration\n"
c006e89e
DS
2409 "For the zebra daemon\n"
2410 "For the rip daemon\n"
2411 "For the ripng daemon\n"
2412 "For the ospf daemon\n"
2413 "For the ospfv6 daemon\n"
4fcbf6e2 2414 "For the ldp daemon\n"
c006e89e 2415 "For the bgp daemon\n"
0fab7646
DS
2416 "For the isis daemon\n"
2417 "For the pim daemon\n")
c006e89e 2418{
a98d33ab 2419 return vtysh_write_terminal (self, vty, argc, argv);
c006e89e
DS
2420}
2421
e7168df4 2422DEFUN (vtysh_integrated_config,
2423 vtysh_integrated_config_cmd,
2424 "service integrated-vtysh-config",
2425 "Set up miscellaneous service\n"
2426 "Write configuration into integrated file\n")
4fc01e67 2427{
039eaca3 2428 vtysh_write_integrated = WRITE_INTEGRATED_YES;
e7168df4 2429 return CMD_SUCCESS;
4fc01e67 2430}
2431
e7168df4 2432DEFUN (no_vtysh_integrated_config,
2433 no_vtysh_integrated_config_cmd,
2434 "no service integrated-vtysh-config",
2435 NO_STR
2436 "Set up miscellaneous service\n"
2437 "Write configuration into integrated file\n")
4fc01e67 2438{
039eaca3 2439 vtysh_write_integrated = WRITE_INTEGRATED_NO;
e7168df4 2440 return CMD_SUCCESS;
4fc01e67 2441}
2442
a7222276
DS
2443static void
2444backup_config_file (const char *fbackup)
718e3744 2445{
718e3744 2446 char *integrate_sav = NULL;
2447
a7222276 2448 integrate_sav = malloc (strlen (fbackup) +
95e735b5 2449 strlen (CONF_BACKUP_EXT) + 1);
a7222276 2450 strcpy (integrate_sav, fbackup);
718e3744 2451 strcat (integrate_sav, CONF_BACKUP_EXT);
2452
95e735b5 2453 /* Move current configuration file to backup config file. */
718e3744 2454 unlink (integrate_sav);
a7222276 2455 rename (fbackup, integrate_sav);
95e735b5 2456 free (integrate_sav);
a7222276
DS
2457}
2458
a68f8616
DL
2459int
2460vtysh_write_config_integrated(void)
a7222276
DS
2461{
2462 u_int i;
2463 char line[] = "write terminal\n";
cb947ba3 2464 FILE *fp;
367988ee
DL
2465 int fd;
2466 struct passwd *pwentry;
2467 struct group *grentry;
2468 uid_t uid = -1;
2469 gid_t gid = -1;
2470 struct stat st;
2471 int err = 0;
a7222276
DS
2472
2473 fprintf (stdout,"Building Configuration...\n");
2474
cb947ba3
DL
2475 backup_config_file(quagga_config);
2476 fp = fopen (quagga_config, "w");
718e3744 2477 if (fp == NULL)
2478 {
c10c5926 2479 fprintf (stdout,"%% Error: failed to open configuration file %s: %s\n",
cb947ba3 2480 quagga_config, safe_strerror(errno));
c10c5926 2481 return CMD_WARNING;
a7222276 2482 }
367988ee 2483 fd = fileno (fp);
a7222276 2484
837d16cc 2485 for (i = 0; i < array_size(vtysh_client); i++)
c0e8c16f 2486 vtysh_client_config (&vtysh_client[i], line);
718e3744 2487
f64e741e 2488 vtysh_config_write ();
718e3744 2489 vtysh_config_dump (fp);
2490
367988ee
DL
2491 if (fchmod (fd, CONFIGFILE_MASK) != 0)
2492 {
2493 printf ("%% Warning: can't chmod configuration file %s: %s\n",
2494 quagga_config, safe_strerror(errno));
2495 err++;
2496 }
718e3744 2497
b2f36157 2498 pwentry = getpwnam (FRR_USER);
367988ee
DL
2499 if (pwentry)
2500 uid = pwentry->pw_uid;
2501 else
aa593d5e 2502 {
b2f36157 2503 printf ("%% Warning: could not look up user \"%s\"\n", FRR_USER);
367988ee 2504 err++;
aa593d5e 2505 }
2506
b2f36157 2507 grentry = getgrnam (FRR_GROUP);
367988ee
DL
2508 if (grentry)
2509 gid = grentry->gr_gid;
2510 else
a7222276 2511 {
b2f36157 2512 printf ("%% Warning: could not look up group \"%s\"\n", FRR_GROUP);
367988ee 2513 err++;
a7222276 2514 }
4fc01e67 2515
367988ee
DL
2516 if (!fstat (fd, &st))
2517 {
2518 if (st.st_uid == uid)
2519 uid = -1;
2520 if (st.st_gid == gid)
2521 gid = -1;
2522 if ((uid != (uid_t)-1 || gid != (gid_t)-1) && fchown (fd, uid, gid))
2523 {
2524 printf ("%% Warning: can't chown configuration file %s: %s\n",
2525 quagga_config, safe_strerror(errno));
2526 err++;
2527 }
2528 }
2529 else
2530 {
2531 printf ("%% Warning: stat() failed on %s: %s\n",
2532 quagga_config, safe_strerror(errno));
2533 err++;
2534 }
2535
2536 fclose (fp);
4fc01e67 2537
c10c5926 2538 printf ("Integrated configuration saved to %s\n", quagga_config);
367988ee
DL
2539 if (err)
2540 return CMD_WARNING;
4fc01e67 2541
c10c5926 2542 printf ("[OK]\n");
718e3744 2543 return CMD_SUCCESS;
2544}
2545
a68f8616 2546static bool want_config_integrated(void)
039eaca3
CF
2547{
2548 struct stat s;
2549
2550 switch (vtysh_write_integrated)
2551 {
2552 case WRITE_INTEGRATED_UNSPECIFIED:
cb947ba3 2553 if (stat(quagga_config, &s) && errno == ENOENT)
039eaca3
CF
2554 return false;
2555 return true;
2556 case WRITE_INTEGRATED_NO:
2557 return false;
2558 case WRITE_INTEGRATED_YES:
2559 return true;
2560 }
3d3c3cbd 2561 return true;
039eaca3
CF
2562}
2563
4fc01e67 2564DEFUN (vtysh_write_memory,
2565 vtysh_write_memory_cmd,
a98d33ab 2566 "write [<memory|file>]",
4fc01e67 2567 "Write running configuration to memory, network, or terminal\n"
a98d33ab
QY
2568 "Write configuration to the file (same as write file)\n"
2569 "Write configuration to the file (same as write memory)\n")
4fc01e67 2570{
dfc0d9ba 2571 int ret = CMD_SUCCESS;
4fc01e67 2572 char line[] = "write memory\n";
b1aa147d 2573 u_int i;
a7222276 2574
cb947ba3 2575 fprintf (stdout, "Note: this version of vtysh never writes vtysh.conf\n");
a7222276 2576
e20dc2ba 2577 /* If integrated frr.conf explicitely set. */
a68f8616 2578 if (want_config_integrated())
a7222276 2579 {
e10ca9b6
DL
2580 ret = CMD_WARNING;
2581 for (i = 0; i < array_size(vtysh_client); i++)
9473e340 2582 if (vtysh_client[i].flag == VTYSH_WATCHFRR)
e10ca9b6
DL
2583 break;
2584 if (i < array_size(vtysh_client) && vtysh_client[i].fd != -1)
2585 ret = vtysh_client_execute (&vtysh_client[i], "write integrated", stdout);
2586
2587 if (ret != CMD_SUCCESS)
2588 {
c10c5926 2589 printf("\nWarning: attempting direct configuration write without "
9473e340 2590 "watchfrr.\nFile permissions and ownership may be "
c10c5926 2591 "incorrect, or write may fail.\n\n");
e10ca9b6
DL
2592 ret = vtysh_write_config_integrated();
2593 }
2594 return ret;
a7222276
DS
2595 }
2596
4fc01e67 2597 fprintf (stdout,"Building Configuration...\n");
a7222276 2598
837d16cc 2599 for (i = 0; i < array_size(vtysh_client); i++)
b1aa147d 2600 ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
4fc01e67 2601
dfc0d9ba 2602 return ret;
4fc01e67 2603}
2604
a98d33ab
QY
2605DEFUN (vtysh_copy_running_config,
2606 vtysh_copy_running_config_cmd,
2607 "copy running-config startup-config",
718e3744 2608 "Copy from one file to another\n"
2609 "Copy from current system configuration\n"
2610 "Copy to startup configuration\n")
a98d33ab
QY
2611{
2612 return vtysh_write_memory (self, vty, argc, argv);
2613}
718e3744 2614
34553cc3 2615DEFUN (vtysh_terminal_length,
2616 vtysh_terminal_length_cmd,
6147e2c6 2617 "terminal length (0-512)",
34553cc3 2618 "Set terminal line parameters\n"
2619 "Set number of lines on a screen\n"
2620 "Number of lines on screen (0 for no pausing)\n")
2621{
bfbc035b 2622 int idx_number = 2;
34553cc3 2623 int lines;
2624 char *endptr = NULL;
2625 char default_pager[10];
2626
bfbc035b 2627 lines = strtol (argv[idx_number]->arg, &endptr, 10);
34553cc3 2628 if (lines < 0 || lines > 512 || *endptr != '\0')
2629 {
2630 vty_out (vty, "length is malformed%s", VTY_NEWLINE);
2631 return CMD_WARNING;
2632 }
2633
2634 if (vtysh_pager_name)
2635 {
2636 free (vtysh_pager_name);
2637 vtysh_pager_name = NULL;
2638 }
2639
2640 if (lines != 0)
2641 {
2642 snprintf(default_pager, 10, "more -%i", lines);
2643 vtysh_pager_name = strdup (default_pager);
2644 }
2645
2646 return CMD_SUCCESS;
2647}
2648
2649DEFUN (vtysh_terminal_no_length,
2650 vtysh_terminal_no_length_cmd,
2651 "terminal no length",
2652 "Set terminal line parameters\n"
2653 NO_STR
2654 "Set number of lines on a screen\n")
2655{
2656 if (vtysh_pager_name)
2657 {
2658 free (vtysh_pager_name);
2659 vtysh_pager_name = NULL;
2660 }
2661
2662 vtysh_pager_init();
2663 return CMD_SUCCESS;
2664}
2665
f2799e69 2666DEFUN (vtysh_show_daemons,
2667 vtysh_show_daemons_cmd,
2668 "show daemons",
e7168df4 2669 SHOW_STR
2670 "Show list of running daemons\n")
2671{
b1aa147d 2672 u_int i;
2673
837d16cc 2674 for (i = 0; i < array_size(vtysh_client); i++)
b1aa147d 2675 if ( vtysh_client[i].fd >= 0 )
2676 vty_out(vty, " %s", vtysh_client[i].name);
e7168df4 2677 vty_out(vty, "%s", VTY_NEWLINE);
2678
2679 return CMD_SUCCESS;
2680}
2681
718e3744 2682/* Execute command in child process. */
c0e8c16f 2683static void
bfbc035b 2684execute_command (const char *command, int argc, struct cmd_token *arg1,
5862ff52 2685 const char *arg2)
718e3744 2686{
718e3744 2687 pid_t pid;
2688 int status;
2689
2690 /* Call fork(). */
2691 pid = fork ();
2692
2693 if (pid < 0)
2694 {
2695 /* Failure of fork(). */
6099b3b5 2696 fprintf (stderr, "Can't fork: %s\n", safe_strerror (errno));
718e3744 2697 exit (1);
2698 }
2699 else if (pid == 0)
2700 {
2701 /* This is child process. */
2702 switch (argc)
2703 {
2704 case 0:
c0e8c16f 2705 execlp (command, command, (const char *)NULL);
718e3744 2706 break;
2707 case 1:
c0e8c16f 2708 execlp (command, command, arg1, (const char *)NULL);
718e3744 2709 break;
2710 case 2:
c0e8c16f 2711 execlp (command, command, arg1, arg2, (const char *)NULL);
718e3744 2712 break;
2713 }
2714
2715 /* When execlp suceed, this part is not executed. */
6099b3b5 2716 fprintf (stderr, "Can't execute %s: %s\n", command, safe_strerror (errno));
718e3744 2717 exit (1);
2718 }
2719 else
2720 {
2721 /* This is parent. */
2722 execute_flag = 1;
c0e8c16f 2723 wait4 (pid, &status, 0, NULL);
718e3744 2724 execute_flag = 0;
2725 }
718e3744 2726}
2727
2728DEFUN (vtysh_ping,
2729 vtysh_ping_cmd,
2730 "ping WORD",
4eeccf18 2731 "Send echo messages\n"
718e3744 2732 "Ping destination address or hostname\n")
2733{
2734 execute_command ("ping", 1, argv[0], NULL);
2735 return CMD_SUCCESS;
2736}
2737
4eeccf18 2738ALIAS (vtysh_ping,
2739 vtysh_ping_ip_cmd,
2740 "ping ip WORD",
2741 "Send echo messages\n"
2742 "IP echo\n"
2743 "Ping destination address or hostname\n")
2744
718e3744 2745DEFUN (vtysh_traceroute,
2746 vtysh_traceroute_cmd,
2747 "traceroute WORD",
2748 "Trace route to destination\n"
2749 "Trace route to destination address or hostname\n")
2750{
2751 execute_command ("traceroute", 1, argv[0], NULL);
2752 return CMD_SUCCESS;
2753}
2754
4eeccf18 2755ALIAS (vtysh_traceroute,
2756 vtysh_traceroute_ip_cmd,
2757 "traceroute ip WORD",
2758 "Trace route to destination\n"
2759 "IP trace\n"
2760 "Trace route to destination address or hostname\n")
2761
4eeccf18 2762DEFUN (vtysh_ping6,
2763 vtysh_ping6_cmd,
2764 "ping ipv6 WORD",
2765 "Send echo messages\n"
2766 "IPv6 echo\n"
2767 "Ping destination address or hostname\n")
2768{
2769 execute_command ("ping6", 1, argv[0], NULL);
2770 return CMD_SUCCESS;
2771}
2772
2773DEFUN (vtysh_traceroute6,
2774 vtysh_traceroute6_cmd,
2775 "traceroute ipv6 WORD",
2776 "Trace route to destination\n"
2777 "IPv6 trace\n"
2778 "Trace route to destination address or hostname\n")
2779{
2780 execute_command ("traceroute6", 1, argv[0], NULL);
2781 return CMD_SUCCESS;
2782}
4eeccf18 2783
576b6b5d 2784#if defined(HAVE_SHELL_ACCESS)
718e3744 2785DEFUN (vtysh_telnet,
2786 vtysh_telnet_cmd,
2787 "telnet WORD",
2788 "Open a telnet connection\n"
2789 "IP address or hostname of a remote system\n")
2790{
2791 execute_command ("telnet", 1, argv[0], NULL);
2792 return CMD_SUCCESS;
2793}
2794
2795DEFUN (vtysh_telnet_port,
2796 vtysh_telnet_port_cmd,
2797 "telnet WORD PORT",
2798 "Open a telnet connection\n"
2799 "IP address or hostname of a remote system\n"
2800 "TCP Port number\n")
2801{
2802 execute_command ("telnet", 2, argv[0], argv[1]);
2803 return CMD_SUCCESS;
2804}
2805
5087df56 2806DEFUN (vtysh_ssh,
2807 vtysh_ssh_cmd,
2808 "ssh WORD",
2809 "Open an ssh connection\n"
2810 "[user@]host\n")
2811{
2812 execute_command ("ssh", 1, argv[0], NULL);
2813 return CMD_SUCCESS;
2814}
2815
718e3744 2816DEFUN (vtysh_start_shell,
2817 vtysh_start_shell_cmd,
2818 "start-shell",
2819 "Start UNIX shell\n")
2820{
2821 execute_command ("sh", 0, NULL, NULL);
2822 return CMD_SUCCESS;
2823}
2824
2825DEFUN (vtysh_start_bash,
2826 vtysh_start_bash_cmd,
2827 "start-shell bash",
2828 "Start UNIX shell\n"
2829 "Start bash\n")
2830{
2831 execute_command ("bash", 0, NULL, NULL);
2832 return CMD_SUCCESS;
2833}
2834
2835DEFUN (vtysh_start_zsh,
2836 vtysh_start_zsh_cmd,
2837 "start-shell zsh",
2838 "Start UNIX shell\n"
2839 "Start Z shell\n")
2840{
2841 execute_command ("zsh", 0, NULL, NULL);
2842 return CMD_SUCCESS;
2843}
576b6b5d 2844#endif
b094d260 2845
0b84f294
DL
2846DEFUN (config_list,
2847 config_list_cmd,
2848 "list [permutations]",
2849 "Print command list\n"
2850 "Print all possible command permutations\n")
2851{
2852 return cmd_list_cmds (vty, argc == 2);
2853}
2854
274a4a44 2855static void
718e3744 2856vtysh_install_default (enum node_type node)
2857{
2858 install_element (node, &config_list_cmd);
2859}
2860
2861/* Making connection to protocol daemon. */
274a4a44 2862static int
b1aa147d 2863vtysh_connect (struct vtysh_client *vclient)
718e3744 2864{
2865 int ret;
2866 int sock, len;
2867 struct sockaddr_un addr;
2868 struct stat s_stat;
87d79a9f
MW
2869 char path[MAXPATHLEN];
2870
2871 if (vty_sock_path == NULL)
2872 strlcpy (path, vclient->path, sizeof (path));
2873 else {
2874 /* Different path for VTY Socket specified
2875 overriding the default path, but keep the filename */
2876 strlcpy (path, vty_sock_path, sizeof (path));
2877
2878 if (strrchr (vclient->path, '/') != NULL)
2879 strlcat (path, strrchr (vclient->path, '/'), sizeof (path));
2880 else {
2881 /*
2882 * vclient->path configured as relative path during config? Should
2883 * really never happen for sensible config
2884 */
2885 strlcat (path, "/", sizeof (path));
2886 strlcat (path, vclient->path, sizeof (path));
2887 }
2888 }
2889 path[sizeof(path)-1] = '\0';
718e3744 2890
718e3744 2891 /* Stat socket to see if we have permission to access it. */
87d79a9f 2892 ret = stat (path, &s_stat);
718e3744 2893 if (ret < 0 && errno != ENOENT)
2894 {
2895 fprintf (stderr, "vtysh_connect(%s): stat = %s\n",
87d79a9f 2896 path, safe_strerror(errno));
718e3744 2897 exit(1);
2898 }
2899
2900 if (ret >= 0)
2901 {
2902 if (! S_ISSOCK(s_stat.st_mode))
2903 {
2904 fprintf (stderr, "vtysh_connect(%s): Not a socket\n",
87d79a9f 2905 path);
718e3744 2906 exit (1);
2907 }
2908
718e3744 2909 }
2910
2911 sock = socket (AF_UNIX, SOCK_STREAM, 0);
2912 if (sock < 0)
2913 {
2914#ifdef DEBUG
87d79a9f 2915 fprintf(stderr, "vtysh_connect(%s): socket = %s\n", path,
6099b3b5 2916 safe_strerror(errno));
718e3744 2917#endif /* DEBUG */
2918 return -1;
2919 }
2920
2921 memset (&addr, 0, sizeof (struct sockaddr_un));
2922 addr.sun_family = AF_UNIX;
fa389c27 2923 strlcpy (addr.sun_path, path, sizeof (addr.sun_path));
6f0e3f6e 2924#ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
718e3744 2925 len = addr.sun_len = SUN_LEN(&addr);
2926#else
2927 len = sizeof (addr.sun_family) + strlen (addr.sun_path);
6f0e3f6e 2928#endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
718e3744 2929
2930 ret = connect (sock, (struct sockaddr *) &addr, len);
2931 if (ret < 0)
2932 {
2933#ifdef DEBUG
87d79a9f 2934 fprintf(stderr, "vtysh_connect(%s): connect = %s\n", path,
6099b3b5 2935 safe_strerror(errno));
718e3744 2936#endif /* DEBUG */
2937 close (sock);
2938 return -1;
2939 }
2940 vclient->fd = sock;
2941
2942 return 0;
2943}
2944
7c8ff89e
DS
2945/* Return true if str ends with suffix, else return false */
2946static int
2947ends_with(const char *str, const char *suffix)
2948{
2949 if (!str || !suffix)
2950 return 0;
2951 size_t lenstr = strlen(str);
2952 size_t lensuffix = strlen(suffix);
2953 if (lensuffix > lenstr)
2954 return 0;
2955 return strncmp(str + lenstr - lensuffix, suffix, lensuffix) == 0;
2956}
2957
2958static void
2959vtysh_client_sorted_insert (struct vtysh_client *head_client,
2960 struct vtysh_client *client)
2961{
2962 struct vtysh_client *prev_node, *current_node;
2963
2964 prev_node = head_client;
2965 current_node = head_client->next;
2966 while (current_node)
2967 {
2968 if (strcmp(current_node->path, client->path) > 0)
2969 break;
2970
2971 prev_node = current_node;
2972 current_node = current_node->next;
2973 }
2974 client->next = current_node;
2975 prev_node->next = client;
2976}
2977
2978#define MAXIMUM_INSTANCES 10
2979
2980static void
2981vtysh_update_all_insances(struct vtysh_client * head_client)
2982{
2983 struct vtysh_client *client;
c0e8c16f 2984 char *ptr;
87d79a9f 2985 char vty_dir[MAXPATHLEN];
7c8ff89e
DS
2986 DIR *dir;
2987 struct dirent *file;
2988 int n = 0;
2989
2990 if (head_client->flag != VTYSH_OSPFD) return;
2991
87d79a9f
MW
2992 if (vty_sock_path == NULL)
2993 /* ls DAEMON_VTY_DIR and look for all files ending in .vty */
2994 strlcpy(vty_dir, DAEMON_VTY_DIR "/", MAXPATHLEN);
2995 else
2996 {
2997 /* ls vty_sock_dir and look for all files ending in .vty */
2998 strlcpy(vty_dir, vty_sock_path, MAXPATHLEN);
2999 strlcat(vty_dir, "/", MAXPATHLEN);
3000 }
3001 dir = opendir(vty_dir);
7c8ff89e
DS
3002 if (dir)
3003 {
3004 while ((file = readdir(dir)) != NULL)
3005 {
3006 if (begins_with(file->d_name, "ospfd-") && ends_with(file->d_name, ".vty"))
3007 {
3008 if (n == MAXIMUM_INSTANCES)
3009 {
3010 fprintf(stderr,
87d79a9f
MW
3011 "Parsing %s, client limit(%d) reached!\n",
3012 vty_dir, n);
7c8ff89e
DS
3013 break;
3014 }
3015 client = (struct vtysh_client *) malloc(sizeof(struct vtysh_client));
3016 client->fd = -1;
c0e8c16f 3017 client->name = "ospfd";
7c8ff89e 3018 client->flag = VTYSH_OSPFD;
c0e8c16f 3019 ptr = (char *) malloc(100);
87d79a9f 3020 sprintf(ptr, "%s%s", vty_dir, file->d_name);
c0e8c16f 3021 client->path = (const char *)ptr;
7c8ff89e
DS
3022 client->next = NULL;
3023 vtysh_client_sorted_insert(head_client, client);
3024 n++;
3025 }
3026 }
3027 closedir(dir);
3028 }
3029}
3030
4201dd11 3031static int
7c8ff89e
DS
3032vtysh_connect_all_instances (struct vtysh_client *head_client)
3033{
3034 struct vtysh_client *client;
3035 int rc = 0;
3036
3037 vtysh_update_all_insances(head_client);
3038
3039 client = head_client->next;
3040 while (client)
3041 {
3042 if (vtysh_connect(client) == 0)
3043 rc++;
3044 client = client->next;
3045 }
3046
3047 return rc;
3048}
3049
f366ad31
AS
3050int
3051vtysh_connect_all(const char *daemon_name)
718e3744 3052{
b1aa147d 3053 u_int i;
f366ad31
AS
3054 int rc = 0;
3055 int matches = 0;
b1aa147d 3056
837d16cc 3057 for (i = 0; i < array_size(vtysh_client); i++)
b1aa147d 3058 {
f366ad31
AS
3059 if (!daemon_name || !strcmp(daemon_name, vtysh_client[i].name))
3060 {
3061 matches++;
3062 if (vtysh_connect(&vtysh_client[i]) == 0)
3063 rc++;
7c8ff89e
DS
3064
3065 rc += vtysh_connect_all_instances(&vtysh_client[i]);
3066 }
b1aa147d 3067 }
f366ad31
AS
3068 if (!matches)
3069 fprintf(stderr, "Error: no daemons match name %s!\n", daemon_name);
3070 return rc;
718e3744 3071}
3072
95e735b5 3073/* To disable readline's filename completion. */
274a4a44 3074static char *
dfc0d9ba 3075vtysh_completion_entry_function (const char *ignore, int invoking_key)
718e3744 3076{
dfc0d9ba 3077 return NULL;
718e3744 3078}
3079
3080void
b1aa147d 3081vtysh_readline_init (void)
718e3744 3082{
3083 /* readline related settings. */
a7c36d85 3084 rl_initialize ();
66d2ead7 3085 rl_bind_key ('?', (rl_command_func_t *) vtysh_rl_describe);
68980084 3086 rl_completion_entry_function = vtysh_completion_entry_function;
66d2ead7 3087 rl_attempted_completion_function = (rl_completion_func_t *)new_completion;
718e3744 3088}
3089
3090char *
b1aa147d 3091vtysh_prompt (void)
718e3744 3092{
f366ad31 3093 static struct utsname names;
718e3744 3094 static char buf[100];
3095 const char*hostname;
3096 extern struct host host;
3097
3098 hostname = host.name;
3099
3100 if (!hostname)
3101 {
f366ad31
AS
3102 if (!names.nodename[0])
3103 uname (&names);
718e3744 3104 hostname = names.nodename;
3105 }
3106
3107 snprintf (buf, sizeof buf, cmd_prompt (vty->node), hostname);
3108
3109 return buf;
3110}
3111
3112void
b1aa147d 3113vtysh_init_vty (void)
718e3744 3114{
3115 /* Make vty structure. */
3116 vty = vty_new ();
3117 vty->type = VTY_SHELL;
3118 vty->node = VIEW_NODE;
3119
3120 /* Initialize commands. */
3121 cmd_init (0);
3122
3123 /* Install nodes. */
3124 install_node (&bgp_node, NULL);
3125 install_node (&rip_node, NULL);
3126 install_node (&interface_node, NULL);
16f1b9ee 3127 install_node (&link_params_node, NULL);
13460c44 3128 install_node (&ns_node, NULL);
e9d94ea7 3129 install_node (&vrf_node, NULL);
718e3744 3130 install_node (&rmap_node, NULL);
3131 install_node (&zebra_node, NULL);
3132 install_node (&bgp_vpnv4_node, NULL);
8ecd3266 3133 install_node (&bgp_vpnv6_node, NULL);
8b1fb8be
LB
3134 install_node (&bgp_encap_node, NULL);
3135 install_node (&bgp_encapv6_node, NULL);
718e3744 3136 install_node (&bgp_ipv4_node, NULL);
3137 install_node (&bgp_ipv4m_node, NULL);
718e3744 3138 install_node (&bgp_ipv6_node, NULL);
57b5b7ed 3139 install_node (&bgp_ipv6m_node, NULL);
5ff06872 3140 install_node (&bgp_vrf_policy_node, NULL);
14a227b8 3141 install_node (&bgp_evpn_node, NULL);
65efcfce
LB
3142 install_node (&bgp_vnc_defaults_node, NULL);
3143 install_node (&bgp_vnc_nve_group_node, NULL);
3144 install_node (&bgp_vnc_l2_group_node, NULL);
718e3744 3145 install_node (&ospf_node, NULL);
718e3744 3146 install_node (&ripng_node, NULL);
3147 install_node (&ospf6_node, NULL);
4fcbf6e2
RW
3148 install_node (&ldp_node, NULL);
3149 install_node (&ldp_ipv4_node, NULL);
3150 install_node (&ldp_ipv6_node, NULL);
3151 install_node (&ldp_ipv4_iface_node, NULL);
3152 install_node (&ldp_ipv6_iface_node, NULL);
3153 install_node (&ldp_l2vpn_node, NULL);
3154 install_node (&ldp_pseudowire_node, NULL);
718e3744 3155 install_node (&keychain_node, NULL);
3156 install_node (&keychain_key_node, NULL);
c25e458a 3157 install_node (&isis_node, NULL);
e7168df4 3158 install_node (&vty_node, NULL);
718e3744 3159
3160 vtysh_install_default (VIEW_NODE);
718e3744 3161 vtysh_install_default (CONFIG_NODE);
3162 vtysh_install_default (BGP_NODE);
3163 vtysh_install_default (RIP_NODE);
3164 vtysh_install_default (INTERFACE_NODE);
16f1b9ee 3165 vtysh_install_default (LINK_PARAMS_NODE);
13460c44 3166 vtysh_install_default (NS_NODE);
e9d94ea7 3167 vtysh_install_default (VRF_NODE);
718e3744 3168 vtysh_install_default (RMAP_NODE);
3169 vtysh_install_default (ZEBRA_NODE);
3170 vtysh_install_default (BGP_VPNV4_NODE);
8ecd3266 3171 vtysh_install_default (BGP_VPNV6_NODE);
8b1fb8be
LB
3172 vtysh_install_default (BGP_ENCAP_NODE);
3173 vtysh_install_default (BGP_ENCAPV6_NODE);
718e3744 3174 vtysh_install_default (BGP_IPV4_NODE);
3175 vtysh_install_default (BGP_IPV4M_NODE);
3176 vtysh_install_default (BGP_IPV6_NODE);
57b5b7ed 3177 vtysh_install_default (BGP_IPV6M_NODE);
14a227b8 3178 vtysh_install_default (BGP_EVPN_NODE);
87ab4aec 3179#if ENABLE_BGP_VNC
5ff06872 3180 vtysh_install_default (BGP_VRF_POLICY_NODE);
65efcfce
LB
3181 vtysh_install_default (BGP_VNC_DEFAULTS_NODE);
3182 vtysh_install_default (BGP_VNC_NVE_GROUP_NODE);
3183 vtysh_install_default (BGP_VNC_L2_GROUP_NODE);
87ab4aec 3184#endif
718e3744 3185 vtysh_install_default (OSPF_NODE);
3186 vtysh_install_default (RIPNG_NODE);
3187 vtysh_install_default (OSPF6_NODE);
4fcbf6e2
RW
3188 vtysh_install_default (LDP_NODE);
3189 vtysh_install_default (LDP_IPV4_NODE);
3190 vtysh_install_default (LDP_IPV6_NODE);
3191 vtysh_install_default (LDP_IPV4_IFACE_NODE);
3192 vtysh_install_default (LDP_IPV6_IFACE_NODE);
3193 vtysh_install_default (LDP_L2VPN_NODE);
3194 vtysh_install_default (LDP_PSEUDOWIRE_NODE);
c25e458a 3195 vtysh_install_default (ISIS_NODE);
718e3744 3196 vtysh_install_default (KEYCHAIN_NODE);
3197 vtysh_install_default (KEYCHAIN_KEY_NODE);
e7168df4 3198 vtysh_install_default (VTY_NODE);
718e3744 3199
3200 install_element (VIEW_NODE, &vtysh_enable_cmd);
3201 install_element (ENABLE_NODE, &vtysh_config_terminal_cmd);
3202 install_element (ENABLE_NODE, &vtysh_disable_cmd);
3203
3204 /* "exit" command. */
3205 install_element (VIEW_NODE, &vtysh_exit_all_cmd);
718e3744 3206 install_element (CONFIG_NODE, &vtysh_exit_all_cmd);
d7d73ffc
DL
3207 install_element (VIEW_NODE, &vtysh_quit_all_cmd);
3208 install_element (CONFIG_NODE, &vtysh_quit_all_cmd);
718e3744 3209 install_element (RIP_NODE, &vtysh_exit_ripd_cmd);
3210 install_element (RIP_NODE, &vtysh_quit_ripd_cmd);
68980084 3211 install_element (RIPNG_NODE, &vtysh_exit_ripngd_cmd);
3212 install_element (RIPNG_NODE, &vtysh_quit_ripngd_cmd);
718e3744 3213 install_element (OSPF_NODE, &vtysh_exit_ospfd_cmd);
3214 install_element (OSPF_NODE, &vtysh_quit_ospfd_cmd);
68980084 3215 install_element (OSPF6_NODE, &vtysh_exit_ospf6d_cmd);
3216 install_element (OSPF6_NODE, &vtysh_quit_ospf6d_cmd);
87ab4aec 3217#if defined (HAVE_LDPD)
4fcbf6e2
RW
3218 install_element (LDP_NODE, &vtysh_exit_ldpd_cmd);
3219 install_element (LDP_NODE, &vtysh_quit_ldpd_cmd);
3220 install_element (LDP_IPV4_NODE, &vtysh_exit_ldpd_cmd);
3221 install_element (LDP_IPV4_NODE, &vtysh_quit_ldpd_cmd);
3222 install_element (LDP_IPV6_NODE, &vtysh_exit_ldpd_cmd);
3223 install_element (LDP_IPV6_NODE, &vtysh_quit_ldpd_cmd);
3224 install_element (LDP_IPV4_IFACE_NODE, &vtysh_exit_ldpd_cmd);
3225 install_element (LDP_IPV4_IFACE_NODE, &vtysh_quit_ldpd_cmd);
3226 install_element (LDP_IPV6_IFACE_NODE, &vtysh_exit_ldpd_cmd);
3227 install_element (LDP_IPV6_IFACE_NODE, &vtysh_quit_ldpd_cmd);
3228 install_element (LDP_L2VPN_NODE, &vtysh_exit_ldpd_cmd);
3229 install_element (LDP_L2VPN_NODE, &vtysh_quit_ldpd_cmd);
3230 install_element (LDP_PSEUDOWIRE_NODE, &vtysh_exit_ldpd_cmd);
3231 install_element (LDP_PSEUDOWIRE_NODE, &vtysh_quit_ldpd_cmd);
87ab4aec 3232#endif
718e3744 3233 install_element (BGP_NODE, &vtysh_exit_bgpd_cmd);
3234 install_element (BGP_NODE, &vtysh_quit_bgpd_cmd);
3235 install_element (BGP_VPNV4_NODE, &vtysh_exit_bgpd_cmd);
3236 install_element (BGP_VPNV4_NODE, &vtysh_quit_bgpd_cmd);
8ecd3266 3237 install_element (BGP_VPNV6_NODE, &vtysh_exit_bgpd_cmd);
3238 install_element (BGP_VPNV6_NODE, &vtysh_quit_bgpd_cmd);
8b1fb8be
LB
3239 install_element (BGP_ENCAP_NODE, &vtysh_exit_bgpd_cmd);
3240 install_element (BGP_ENCAP_NODE, &vtysh_quit_bgpd_cmd);
3241 install_element (BGP_ENCAPV6_NODE, &vtysh_exit_bgpd_cmd);
3242 install_element (BGP_ENCAPV6_NODE, &vtysh_quit_bgpd_cmd);
718e3744 3243 install_element (BGP_IPV4_NODE, &vtysh_exit_bgpd_cmd);
3244 install_element (BGP_IPV4_NODE, &vtysh_quit_bgpd_cmd);
3245 install_element (BGP_IPV4M_NODE, &vtysh_exit_bgpd_cmd);
3246 install_element (BGP_IPV4M_NODE, &vtysh_quit_bgpd_cmd);
3247 install_element (BGP_IPV6_NODE, &vtysh_exit_bgpd_cmd);
3248 install_element (BGP_IPV6_NODE, &vtysh_quit_bgpd_cmd);
57b5b7ed 3249 install_element (BGP_IPV6M_NODE, &vtysh_exit_bgpd_cmd);
3250 install_element (BGP_IPV6M_NODE, &vtysh_quit_bgpd_cmd);
14a227b8 3251 install_element (BGP_EVPN_NODE, &vtysh_quit_bgpd_cmd);
87ab4aec 3252#if defined (ENABLE_BGP_VNC)
5ff06872
LB
3253 install_element (BGP_VRF_POLICY_NODE, &vtysh_exit_bgpd_cmd);
3254 install_element (BGP_VRF_POLICY_NODE, &vtysh_quit_bgpd_cmd);
65efcfce
LB
3255 install_element (BGP_VNC_DEFAULTS_NODE, &vtysh_exit_bgpd_cmd);
3256 install_element (BGP_VNC_DEFAULTS_NODE, &vtysh_quit_bgpd_cmd);
3257 install_element (BGP_VNC_NVE_GROUP_NODE, &vtysh_exit_bgpd_cmd);
3258 install_element (BGP_VNC_NVE_GROUP_NODE, &vtysh_quit_bgpd_cmd);
3259 install_element (BGP_VNC_L2_GROUP_NODE, &vtysh_exit_bgpd_cmd);
3260 install_element (BGP_VNC_L2_GROUP_NODE, &vtysh_quit_bgpd_cmd);
87ab4aec 3261#endif
c25e458a 3262 install_element (ISIS_NODE, &vtysh_exit_isisd_cmd);
3263 install_element (ISIS_NODE, &vtysh_quit_isisd_cmd);
718e3744 3264 install_element (KEYCHAIN_NODE, &vtysh_exit_ripd_cmd);
3265 install_element (KEYCHAIN_NODE, &vtysh_quit_ripd_cmd);
3266 install_element (KEYCHAIN_KEY_NODE, &vtysh_exit_ripd_cmd);
3267 install_element (KEYCHAIN_KEY_NODE, &vtysh_quit_ripd_cmd);
3268 install_element (RMAP_NODE, &vtysh_exit_rmap_cmd);
3269 install_element (RMAP_NODE, &vtysh_quit_rmap_cmd);
e7168df4 3270 install_element (VTY_NODE, &vtysh_exit_line_vty_cmd);
3271 install_element (VTY_NODE, &vtysh_quit_line_vty_cmd);
718e3744 3272
3273 /* "end" command. */
3274 install_element (CONFIG_NODE, &vtysh_end_all_cmd);
3275 install_element (ENABLE_NODE, &vtysh_end_all_cmd);
3276 install_element (RIP_NODE, &vtysh_end_all_cmd);
3277 install_element (RIPNG_NODE, &vtysh_end_all_cmd);
3278 install_element (OSPF_NODE, &vtysh_end_all_cmd);
3279 install_element (OSPF6_NODE, &vtysh_end_all_cmd);
4fcbf6e2
RW
3280 install_element (LDP_NODE, &vtysh_end_all_cmd);
3281 install_element (LDP_IPV4_NODE, &vtysh_end_all_cmd);
3282 install_element (LDP_IPV6_NODE, &vtysh_end_all_cmd);
3283 install_element (LDP_IPV4_IFACE_NODE, &vtysh_end_all_cmd);
3284 install_element (LDP_IPV6_IFACE_NODE, &vtysh_end_all_cmd);
3285 install_element (LDP_L2VPN_NODE, &vtysh_end_all_cmd);
3286 install_element (LDP_PSEUDOWIRE_NODE, &vtysh_end_all_cmd);
718e3744 3287 install_element (BGP_NODE, &vtysh_end_all_cmd);
3288 install_element (BGP_IPV4_NODE, &vtysh_end_all_cmd);
3289 install_element (BGP_IPV4M_NODE, &vtysh_end_all_cmd);
3290 install_element (BGP_VPNV4_NODE, &vtysh_end_all_cmd);
8ecd3266 3291 install_element (BGP_VPNV6_NODE, &vtysh_end_all_cmd);
8b1fb8be
LB
3292 install_element (BGP_ENCAP_NODE, &vtysh_end_all_cmd);
3293 install_element (BGP_ENCAPV6_NODE, &vtysh_end_all_cmd);
718e3744 3294 install_element (BGP_IPV6_NODE, &vtysh_end_all_cmd);
57b5b7ed 3295 install_element (BGP_IPV6M_NODE, &vtysh_end_all_cmd);
5ff06872 3296 install_element (BGP_VRF_POLICY_NODE, &vtysh_end_all_cmd);
14a227b8 3297 install_element (BGP_EVPN_NODE, &vtysh_end_all_cmd);
65efcfce
LB
3298 install_element (BGP_VNC_DEFAULTS_NODE, &vtysh_end_all_cmd);
3299 install_element (BGP_VNC_NVE_GROUP_NODE, &vtysh_end_all_cmd);
3300 install_element (BGP_VNC_L2_GROUP_NODE, &vtysh_end_all_cmd);
c25e458a 3301 install_element (ISIS_NODE, &vtysh_end_all_cmd);
718e3744 3302 install_element (KEYCHAIN_NODE, &vtysh_end_all_cmd);
3303 install_element (KEYCHAIN_KEY_NODE, &vtysh_end_all_cmd);
3304 install_element (RMAP_NODE, &vtysh_end_all_cmd);
e7168df4 3305 install_element (VTY_NODE, &vtysh_end_all_cmd);
718e3744 3306
dd2ecded
DS
3307 install_element (INTERFACE_NODE, &vtysh_interface_desc_cmd);
3308 install_element (INTERFACE_NODE, &vtysh_no_interface_desc_cmd);
718e3744 3309 install_element (INTERFACE_NODE, &vtysh_end_all_cmd);
3310 install_element (INTERFACE_NODE, &vtysh_exit_interface_cmd);
03f99d9a 3311 install_element (LINK_PARAMS_NODE, &exit_link_params_cmd);
16f1b9ee
OD
3312 install_element (LINK_PARAMS_NODE, &vtysh_end_all_cmd);
3313 install_element (LINK_PARAMS_NODE, &vtysh_exit_interface_cmd);
718e3744 3314 install_element (INTERFACE_NODE, &vtysh_quit_interface_cmd);
e9d94ea7 3315
13460c44 3316 install_element (NS_NODE, &vtysh_end_all_cmd);
d7d73ffc
DL
3317
3318 install_element (CONFIG_NODE, &vtysh_ns_cmd);
13460c44
FL
3319 install_element (NS_NODE, &vtysh_exit_ns_cmd);
3320 install_element (NS_NODE, &vtysh_quit_ns_cmd);
3321
e9d94ea7
DS
3322 install_element (VRF_NODE, &vtysh_end_all_cmd);
3323 install_element (VRF_NODE, &vtysh_exit_vrf_cmd);
3324 install_element (VRF_NODE, &vtysh_quit_vrf_cmd);
3325
718e3744 3326 install_element (CONFIG_NODE, &router_rip_cmd);
718e3744 3327 install_element (CONFIG_NODE, &router_ripng_cmd);
718e3744 3328 install_element (CONFIG_NODE, &router_ospf_cmd);
718e3744 3329 install_element (CONFIG_NODE, &router_ospf6_cmd);
87ab4aec 3330#if defined (HAVE_LDPD)
4fcbf6e2
RW
3331 install_element (CONFIG_NODE, &ldp_mpls_ldp_cmd);
3332 install_element (LDP_NODE, &ldp_address_family_ipv4_cmd);
3333 install_element (LDP_NODE, &ldp_address_family_ipv6_cmd);
3334 install_element (LDP_IPV4_NODE, &ldp_interface_ifname_cmd);
3335 install_element (LDP_IPV6_NODE, &ldp_interface_ifname_cmd);
3336 install_element (CONFIG_NODE, &ldp_l2vpn_word_type_vpls_cmd);
3337 install_element (LDP_L2VPN_NODE, &ldp_member_pseudowire_ifname_cmd);
87ab4aec 3338#endif
c25e458a 3339 install_element (CONFIG_NODE, &router_isis_cmd);
718e3744 3340 install_element (CONFIG_NODE, &router_bgp_cmd);
3341 install_element (BGP_NODE, &address_family_vpnv4_cmd);
8ecd3266 3342 install_element (BGP_NODE, &address_family_vpnv6_cmd);
4c4ff4c1 3343 install_element (BGP_NODE, &address_family_encapv4_cmd);
8b1fb8be 3344 install_element (BGP_NODE, &address_family_encapv6_cmd);
87ab4aec 3345#if defined(ENABLE_BGP_VNC)
5ff06872 3346 install_element (BGP_NODE, &vnc_vrf_policy_cmd);
65efcfce
LB
3347 install_element (BGP_NODE, &vnc_defaults_cmd);
3348 install_element (BGP_NODE, &vnc_nve_group_cmd);
d7d73ffc 3349 install_element (BGP_NODE, &vnc_l2_group_cmd);
87ab4aec 3350#endif
718e3744 3351 install_element (BGP_NODE, &address_family_ipv4_unicast_cmd);
718e3744 3352 install_element (BGP_NODE, &address_family_ipv6_cmd);
14a227b8 3353 install_element (BGP_NODE, &address_family_evpn_cmd);
718e3744 3354 install_element (BGP_VPNV4_NODE, &exit_address_family_cmd);
8ecd3266 3355 install_element (BGP_VPNV6_NODE, &exit_address_family_cmd);
8b1fb8be
LB
3356 install_element (BGP_ENCAP_NODE, &exit_address_family_cmd);
3357 install_element (BGP_ENCAPV6_NODE, &exit_address_family_cmd);
718e3744 3358 install_element (BGP_IPV4_NODE, &exit_address_family_cmd);
3359 install_element (BGP_IPV4M_NODE, &exit_address_family_cmd);
3360 install_element (BGP_IPV6_NODE, &exit_address_family_cmd);
57b5b7ed 3361 install_element (BGP_IPV6M_NODE, &exit_address_family_cmd);
14a227b8 3362 install_element (BGP_EVPN_NODE, &exit_address_family_cmd);
65efcfce 3363
5ff06872 3364 install_element (BGP_VRF_POLICY_NODE, &exit_vrf_policy_cmd);
65efcfce
LB
3365 install_element (BGP_VNC_DEFAULTS_NODE, &exit_vnc_config_cmd);
3366 install_element (BGP_VNC_NVE_GROUP_NODE, &exit_vnc_config_cmd);
3367 install_element (BGP_VNC_L2_GROUP_NODE, &exit_vnc_config_cmd);
3368
718e3744 3369 install_element (CONFIG_NODE, &key_chain_cmd);
dd2ecded 3370 install_element (CONFIG_NODE, &vtysh_route_map_cmd);
e7168df4 3371 install_element (CONFIG_NODE, &vtysh_line_vty_cmd);
718e3744 3372 install_element (KEYCHAIN_NODE, &key_cmd);
3373 install_element (KEYCHAIN_NODE, &key_chain_cmd);
3374 install_element (KEYCHAIN_KEY_NODE, &key_chain_cmd);
3375 install_element (CONFIG_NODE, &vtysh_interface_cmd);
32d2463c 3376 install_element (CONFIG_NODE, &vtysh_no_interface_cmd);
cd2a8a42 3377 install_element (CONFIG_NODE, &vtysh_no_interface_vrf_cmd);
16f1b9ee 3378 install_element (INTERFACE_NODE, &vtysh_link_params_cmd);
718e3744 3379 install_element (ENABLE_NODE, &vtysh_show_running_config_cmd);
a98d33ab 3380 install_element (ENABLE_NODE, &vtysh_copy_running_config_cmd);
718e3744 3381
e9d94ea7
DS
3382 install_element (CONFIG_NODE, &vtysh_vrf_cmd);
3383 install_element (CONFIG_NODE, &vtysh_no_vrf_cmd);
3384
95e735b5 3385 /* "write terminal" command. */
718e3744 3386 install_element (ENABLE_NODE, &vtysh_write_terminal_cmd);
b47b0a84 3387
e7168df4 3388 install_element (CONFIG_NODE, &vtysh_integrated_config_cmd);
3389 install_element (CONFIG_NODE, &no_vtysh_integrated_config_cmd);
718e3744 3390
95e735b5 3391 /* "write memory" command. */
718e3744 3392 install_element (ENABLE_NODE, &vtysh_write_memory_cmd);
718e3744 3393
34553cc3 3394 install_element (VIEW_NODE, &vtysh_terminal_length_cmd);
34553cc3 3395 install_element (VIEW_NODE, &vtysh_terminal_no_length_cmd);
f2799e69 3396 install_element (VIEW_NODE, &vtysh_show_daemons_cmd);
34553cc3 3397
718e3744 3398 install_element (VIEW_NODE, &vtysh_ping_cmd);
4eeccf18 3399 install_element (VIEW_NODE, &vtysh_ping_ip_cmd);
718e3744 3400 install_element (VIEW_NODE, &vtysh_traceroute_cmd);
4eeccf18 3401 install_element (VIEW_NODE, &vtysh_traceroute_ip_cmd);
4eeccf18 3402 install_element (VIEW_NODE, &vtysh_ping6_cmd);
3403 install_element (VIEW_NODE, &vtysh_traceroute6_cmd);
576b6b5d 3404#if defined(HAVE_SHELL_ACCESS)
718e3744 3405 install_element (VIEW_NODE, &vtysh_telnet_cmd);
3406 install_element (VIEW_NODE, &vtysh_telnet_port_cmd);
5087df56 3407 install_element (VIEW_NODE, &vtysh_ssh_cmd);
4eeccf18 3408#endif
576b6b5d 3409#if defined(HAVE_SHELL_ACCESS)
718e3744 3410 install_element (ENABLE_NODE, &vtysh_start_shell_cmd);
3411 install_element (ENABLE_NODE, &vtysh_start_bash_cmd);
3412 install_element (ENABLE_NODE, &vtysh_start_zsh_cmd);
576b6b5d
DS
3413#endif
3414
362b4031 3415 install_element (VIEW_NODE, &vtysh_show_memory_cmd);
362b4031 3416
0f69b58c 3417 install_element (VIEW_NODE, &vtysh_show_work_queues_cmd);
b47b0a84 3418 install_element (VIEW_NODE, &vtysh_show_work_queues_daemon_cmd);
0f69b58c
DS
3419
3420 install_element (VIEW_NODE, &vtysh_show_thread_cmd);
0f69b58c 3421
dbf7d13d 3422 /* Logging */
dbf7d13d 3423 install_element (VIEW_NODE, &vtysh_show_logging_cmd);
718e3744 3424 install_element (CONFIG_NODE, &vtysh_log_stdout_cmd);
274a4a44 3425 install_element (CONFIG_NODE, &vtysh_log_stdout_level_cmd);
718e3744 3426 install_element (CONFIG_NODE, &no_vtysh_log_stdout_cmd);
3427 install_element (CONFIG_NODE, &vtysh_log_file_cmd);
274a4a44 3428 install_element (CONFIG_NODE, &vtysh_log_file_level_cmd);
718e3744 3429 install_element (CONFIG_NODE, &no_vtysh_log_file_cmd);
274a4a44 3430 install_element (CONFIG_NODE, &vtysh_log_monitor_cmd);
274a4a44 3431 install_element (CONFIG_NODE, &no_vtysh_log_monitor_cmd);
718e3744 3432 install_element (CONFIG_NODE, &vtysh_log_syslog_cmd);
3433 install_element (CONFIG_NODE, &no_vtysh_log_syslog_cmd);
3434 install_element (CONFIG_NODE, &vtysh_log_trap_cmd);
3435 install_element (CONFIG_NODE, &no_vtysh_log_trap_cmd);
274a4a44 3436 install_element (CONFIG_NODE, &vtysh_log_facility_cmd);
3437 install_element (CONFIG_NODE, &no_vtysh_log_facility_cmd);
718e3744 3438 install_element (CONFIG_NODE, &vtysh_log_record_priority_cmd);
3439 install_element (CONFIG_NODE, &no_vtysh_log_record_priority_cmd);
c749b722
AS
3440 install_element (CONFIG_NODE, &vtysh_log_timestamp_precision_cmd);
3441 install_element (CONFIG_NODE, &no_vtysh_log_timestamp_precision_cmd);
e7168df4 3442
3443 install_element (CONFIG_NODE, &vtysh_service_password_encrypt_cmd);
3444 install_element (CONFIG_NODE, &no_vtysh_service_password_encrypt_cmd);
3445
3446 install_element (CONFIG_NODE, &vtysh_password_cmd);
3447 install_element (CONFIG_NODE, &vtysh_password_text_cmd);
3448 install_element (CONFIG_NODE, &vtysh_enable_password_cmd);
3449 install_element (CONFIG_NODE, &vtysh_enable_password_text_cmd);
3450 install_element (CONFIG_NODE, &no_vtysh_enable_password_cmd);
718e3744 3451}