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