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