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