]> git.proxmox.com Git - mirror_frr.git/blame - vtysh/vtysh.c
Merge pull request #7330 from donaldsharp/zebra_use_after_free
[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"
d7b86ae4 41#include "vtysh/vtysh_daemons.h"
6099b3b5 42#include "log.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}
662a1b05
WC
1775
1776DEFUNSH(VTYSH_BGPD, exit_vnc_config, exit_vnc_config_cmd, "exit-vnc",
1777 "Exit from VNC configuration mode\n")
1778{
1779 if (vty->node == BGP_VNC_DEFAULTS_NODE
1780 || vty->node == BGP_VNC_NVE_GROUP_NODE
1781 || vty->node == BGP_VNC_L2_GROUP_NODE)
1782 vty->node = BGP_NODE;
1783 return CMD_SUCCESS;
1784}
1785
1786DEFUNSH(VTYSH_BGPD, exit_vrf_policy, exit_vrf_policy_cmd, "exit-vrf-policy",
1787 "Exit from VRF policy configuration mode\n")
1788{
1789 if (vty->node == BGP_VRF_POLICY_NODE)
1790 vty->node = BGP_NODE;
1791 return CMD_SUCCESS;
1792}
d62a17ae 1793#endif
0eb5751d 1794#endif /* HAVE_BGPD */
718e3744 1795
3a3a24c8 1796DEFUNSH(VTYSH_KEYS, key_chain, key_chain_cmd, "key chain WORD",
d62a17ae 1797 "Authentication key management\n"
1798 "Key-chain management\n"
1799 "Key-chain name\n")
718e3744 1800{
d62a17ae 1801 vty->node = KEYCHAIN_NODE;
1802 return CMD_SUCCESS;
39530dfe 1803}
c7f1274b 1804
3a3a24c8 1805DEFUNSH(VTYSH_KEYS, key, key_cmd, "key (0-2147483647)",
d62a17ae 1806 "Configure a key\n"
1807 "Key identifier number\n")
39530dfe 1808{
d62a17ae 1809 vty->node = KEYCHAIN_KEY_NODE;
1810 return CMD_SUCCESS;
39530dfe 1811}
f51bae9c 1812
0eb5751d 1813#ifdef HAVE_RIPD
ae7b826a
RW
1814DEFUNSH(VTYSH_RIPD, router_rip, router_rip_cmd, "router rip [vrf NAME]",
1815 ROUTER_STR "RIP\n" VRF_CMD_HELP_STR)
39530dfe 1816{
d62a17ae 1817 vty->node = RIP_NODE;
1818 return CMD_SUCCESS;
57b5b7ed 1819}
0eb5751d 1820#endif /* HAVE_RIPD */
718e3744 1821
0eb5751d 1822#ifdef HAVE_RIPNGD
dde7b15b
RW
1823DEFUNSH(VTYSH_RIPNGD, router_ripng, router_ripng_cmd, "router ripng [vrf NAME]",
1824 ROUTER_STR "RIPng\n" VRF_CMD_HELP_STR)
05ba625a 1825{
d62a17ae 1826 vty->node = RIPNG_NODE;
1827 return CMD_SUCCESS;
57b5b7ed 1828}
0eb5751d 1829#endif /* HAVE_RIPNGD */
57b5b7ed 1830
0eb5751d 1831#ifdef HAVE_OSPFD
b5a8894d
CS
1832DEFUNSH(VTYSH_OSPFD, router_ospf, router_ospf_cmd,
1833 "router ospf [(1-65535)] [vrf NAME]",
d62a17ae 1834 "Enable a routing process\n"
1835 "Start OSPF configuration\n"
b86543b8
LB
1836 "Instance ID\n"
1837 VRF_CMD_HELP_STR)
90e60aa7 1838{
d62a17ae 1839 vty->node = OSPF_NODE;
1840 return CMD_SUCCESS;
90e60aa7 1841}
0eb5751d 1842#endif /* HAVE_OSPFD */
90e60aa7 1843
0eb5751d 1844#ifdef HAVE_EIGRPD
e9449961 1845DEFUNSH(VTYSH_EIGRPD, router_eigrp, router_eigrp_cmd, "router eigrp (1-65535) [vrf NAME]",
d62a17ae 1846 "Enable a routing process\n"
1847 "Start EIGRP configuration\n"
e9449961
DS
1848 "AS number to use\n"
1849 VRF_CMD_HELP_STR)
14a227b8 1850{
d62a17ae 1851 vty->node = EIGRP_NODE;
1852 return CMD_SUCCESS;
14a227b8 1853}
0eb5751d 1854#endif /* HAVE_EIGRPD */
90e60aa7 1855
0eb5751d 1856#ifdef HAVE_BABELD
d62a17ae 1857DEFUNSH(VTYSH_BABELD, router_babel, router_babel_cmd, "router babel",
1858 "Enable a routing process\n"
1859 "Make Babel instance command\n")
90e60aa7 1860{
d62a17ae 1861 vty->node = BABEL_NODE;
1862 return CMD_SUCCESS;
90e60aa7 1863}
0eb5751d 1864#endif /* HAVE_BABELD */
14a227b8 1865
0eb5751d 1866#ifdef HAVE_OSPF6D
d62a17ae 1867DEFUNSH(VTYSH_OSPF6D, router_ospf6, router_ospf6_cmd, "router ospf6",
1868 ROUTER_STR OSPF6_STR)
65efcfce 1869{
d62a17ae 1870 vty->node = OSPF6_NODE;
1871 return CMD_SUCCESS;
65efcfce 1872}
0eb5751d 1873#endif
65efcfce 1874
d62a17ae 1875#if defined(HAVE_LDPD)
1876DEFUNSH(VTYSH_LDPD, ldp_mpls_ldp, ldp_mpls_ldp_cmd, "mpls ldp",
1877 "Global MPLS configuration subcommands\n"
1878 "Label Distribution Protocol\n")
65efcfce 1879{
d62a17ae 1880 vty->node = LDP_NODE;
1881 return CMD_SUCCESS;
65efcfce
LB
1882}
1883
d62a17ae 1884DEFUNSH(VTYSH_LDPD, ldp_address_family_ipv4, ldp_address_family_ipv4_cmd,
1885 "address-family ipv4",
1886 "Configure Address Family and its parameters\n"
1887 "IPv4\n")
5ff06872 1888{
d62a17ae 1889 vty->node = LDP_IPV4_NODE;
1890 return CMD_SUCCESS;
5ff06872
LB
1891}
1892
d62a17ae 1893DEFUNSH(VTYSH_LDPD, ldp_address_family_ipv6, ldp_address_family_ipv6_cmd,
1894 "address-family ipv6",
1895 "Configure Address Family and its parameters\n"
1896 "IPv6\n")
65efcfce 1897{
d62a17ae 1898 vty->node = LDP_IPV6_NODE;
1899 return CMD_SUCCESS;
65efcfce
LB
1900}
1901
983bd6f7
RW
1902DEFUNSH(VTYSH_LDPD, ldp_exit_address_family, ldp_exit_address_family_cmd,
1903 "exit-address-family", "Exit from Address Family configuration mode\n")
1904{
1905 if (vty->node == LDP_IPV4_NODE || vty->node == LDP_IPV6_NODE)
1906 vty->node = LDP_NODE;
1907 return CMD_SUCCESS;
1908}
1909
d62a17ae 1910DEFUNSH(VTYSH_LDPD, ldp_interface_ifname, ldp_interface_ifname_cmd,
1911 "interface IFNAME",
1912 "Enable LDP on an interface and enter interface submode\n"
1913 "Interface's name\n")
718e3744 1914{
d62a17ae 1915 switch (vty->node) {
1916 case LDP_IPV4_NODE:
1917 vty->node = LDP_IPV4_IFACE_NODE;
1918 break;
1919 case LDP_IPV6_NODE:
1920 vty->node = LDP_IPV6_IFACE_NODE;
1921 break;
1922 default:
1923 break;
1924 }
1925
1926 return CMD_SUCCESS;
1927}
718e3744 1928
d62a17ae 1929DEFUNSH(VTYSH_LDPD, ldp_l2vpn_word_type_vpls, ldp_l2vpn_word_type_vpls_cmd,
1930 "l2vpn WORD type vpls",
1931 "Configure l2vpn commands\n"
1932 "L2VPN name\n"
1933 "L2VPN type\n"
1934 "Virtual Private LAN Service\n")
718e3744 1935{
d62a17ae 1936 vty->node = LDP_L2VPN_NODE;
1937 return CMD_SUCCESS;
718e3744 1938}
1939
d62a17ae 1940DEFUNSH(VTYSH_LDPD, ldp_member_pseudowire_ifname,
1941 ldp_member_pseudowire_ifname_cmd, "member pseudowire IFNAME",
1942 "L2VPN member configuration\n"
1943 "Pseudowire interface\n"
1944 "Interface's name\n")
718e3744 1945{
d62a17ae 1946 vty->node = LDP_PSEUDOWIRE_NODE;
1947 return CMD_SUCCESS;
718e3744 1948}
d62a17ae 1949#endif
718e3744 1950
0eb5751d 1951#ifdef HAVE_ISISD
65251ce8 1952DEFUNSH(VTYSH_ISISD, router_isis, router_isis_cmd,
1953 "router isis WORD [vrf NAME]",
d62a17ae 1954 ROUTER_STR
1955 "ISO IS-IS\n"
65251ce8 1956 "ISO Routing area tag\n" VRF_CMD_HELP_STR)
d62a17ae 1957{
1958 vty->node = ISIS_NODE;
1959 return CMD_SUCCESS;
1960}
0eb5751d 1961#endif /* HAVE_ISISD */
d62a17ae 1962
0eb5751d 1963#ifdef HAVE_FABRICD
770ccdf8
CF
1964DEFUNSH(VTYSH_FABRICD, router_openfabric, router_openfabric_cmd, "router openfabric WORD",
1965 ROUTER_STR
1966 "OpenFabric routing protocol\n"
1967 "ISO Routing area tag\n")
1968{
1969 vty->node = OPENFABRIC_NODE;
1970 return CMD_SUCCESS;
1971}
0eb5751d 1972#endif /* HAVE_FABRICD */
770ccdf8 1973
d62a17ae 1974DEFUNSH(VTYSH_RMAP, vtysh_route_map, vtysh_route_map_cmd,
1975 "route-map WORD <deny|permit> (1-65535)",
1976 "Create route-map or enter route-map command mode\n"
1977 "Route map tag\n"
1978 "Route map denies set operations\n"
1979 "Route map permits set operations\n"
1980 "Sequence to insert to/delete from existing route-map entry\n")
1981{
1982 vty->node = RMAP_NODE;
1983 return CMD_SUCCESS;
1984}
1985
0eb5751d 1986#ifdef HAVE_PBRD
e5c83d9b 1987DEFUNSH(VTYSH_PBRD, vtysh_pbr_map, vtysh_pbr_map_cmd,
17f8c652 1988 "pbr-map PBRMAP seq (1-700)",
e5c83d9b
DS
1989 "Create pbr-map or enter pbr-map command mode\n"
1990 "The name of the PBR MAP\n"
1991 "Sequence to insert to/delete from existing pbr-map entry\n"
1992 "Sequence number\n")
1993{
1994 vty->node = PBRMAP_NODE;
1995 return CMD_SUCCESS;
1996}
1997
5d574646
IR
1998DEFSH(VTYSH_PBRD, vtysh_no_pbr_map_cmd, "no pbr-map PBRMAP [seq (1-700)]",
1999 NO_STR
2000 "Delete pbr-map\n"
2001 "The name of the PBR MAP\n"
2002 "Sequence to delete from existing pbr-map entry\n"
2003 "Sequence number\n")
0eb5751d 2004#endif /* HAVE_PBRD */
5d574646 2005
c2f29cf3
RZ
2006#if HAVE_BFDD > 0
2007DEFUNSH(VTYSH_BFDD, bfd_enter, bfd_enter_cmd, "bfd", "Configure BFD peers\n")
2008{
2009 vty->node = BFD_NODE;
2010 return CMD_SUCCESS;
2011}
2012
2013DEFUNSH(VTYSH_BFDD, bfd_peer_enter, bfd_peer_enter_cmd,
2014 "peer <A.B.C.D|X:X::X:X> [{multihop|local-address <A.B.C.D|X:X::X:X>|interface IFNAME|vrf NAME}]",
2015 "Configure peer\n"
2016 "IPv4 peer address\n"
2017 "IPv6 peer address\n"
2018 "Configure multihop\n"
2019 "Configure local address\n"
2020 "IPv4 local address\n"
2021 "IPv6 local address\n"
2022 INTERFACE_STR
2023 "Configure interface name to use\n"
2024 "Configure VRF\n"
2025 "Configure VRF name\n")
2026{
2027 vty->node = BFD_PEER_NODE;
2028 return CMD_SUCCESS;
2029}
d40d6c22
RZ
2030
2031DEFUNSH(VTYSH_BFDD, bfd_profile_enter, bfd_profile_enter_cmd,
2032 "profile WORD",
2033 BFD_PROFILE_STR
2034 BFD_PROFILE_NAME_STR)
2035{
2036 vty->node = BFD_PROFILE_NODE;
2037 return CMD_SUCCESS;
2038}
c2f29cf3
RZ
2039#endif /* HAVE_BFDD */
2040
d62a17ae 2041DEFUNSH(VTYSH_ALL, vtysh_line_vty, vtysh_line_vty_cmd, "line vty",
2042 "Configure a terminal line\n"
2043 "Virtual terminal\n")
2044{
2045 vty->node = VTY_NODE;
2046 return CMD_SUCCESS;
2047}
2048
2049DEFUNSH(VTYSH_REALLYALL, vtysh_enable, vtysh_enable_cmd, "enable",
2050 "Turn on privileged mode command\n")
2051{
2052 vty->node = ENABLE_NODE;
2053 return CMD_SUCCESS;
2054}
2055
2056DEFUNSH(VTYSH_REALLYALL, vtysh_disable, vtysh_disable_cmd, "disable",
2057 "Turn off privileged mode command\n")
2058{
2059 if (vty->node == ENABLE_NODE)
2060 vty->node = VIEW_NODE;
2061 return CMD_SUCCESS;
2062}
2063
2064DEFUNSH(VTYSH_REALLYALL, vtysh_config_terminal, vtysh_config_terminal_cmd,
dc1c13c0 2065 "configure [terminal]",
d62a17ae 2066 "Configuration from vty interface\n"
2067 "Configuration terminal\n")
2068{
2069 vty->node = CONFIG_NODE;
2070 return CMD_SUCCESS;
2071}
2072
2073static int vtysh_exit(struct vty *vty)
2074{
d42eb101
DL
2075 struct cmd_node *cnode = vector_lookup(cmdvec, vty->node);
2076
2077 if (vty->node == VIEW_NODE || vty->node == ENABLE_NODE)
d62a17ae 2078 exit(0);
d42eb101
DL
2079 if (cnode->node_exit)
2080 cnode->node_exit(vty);
2081 if (cnode->parent_node)
2082 vty->node = cnode->parent_node;
2083
2084 if (vty->node == CONFIG_NODE) {
2085 /* resync in case one of the daemons is somewhere else */
d62a17ae 2086 vtysh_execute("end");
dc1c13c0 2087 vtysh_execute("configure");
d62a17ae 2088 }
2089 return CMD_SUCCESS;
2090}
2091
2092DEFUNSH(VTYSH_REALLYALL, vtysh_exit_all, vtysh_exit_all_cmd, "exit",
2093 "Exit current mode and down to previous mode\n")
4fcbf6e2 2094{
d62a17ae 2095 return vtysh_exit(vty);
4fcbf6e2
RW
2096}
2097
d62a17ae 2098DEFUNSH(VTYSH_ALL, vtysh_quit_all, vtysh_quit_all_cmd, "quit",
2099 "Exit current mode and down to previous mode\n")
4fcbf6e2 2100{
d62a17ae 2101 return vtysh_exit_all(self, vty, argc, argv);
2102}
4fcbf6e2 2103
0eb5751d 2104#ifdef HAVE_BGPD
d62a17ae 2105DEFUNSH(VTYSH_BGPD, exit_address_family, exit_address_family_cmd,
2106 "exit-address-family", "Exit from Address Family configuration mode\n")
4fcbf6e2 2107{
d62a17ae 2108 if (vty->node == BGP_IPV4_NODE || vty->node == BGP_IPV4M_NODE
2109 || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE
2110 || vty->node == BGP_VPNV6_NODE || vty->node == BGP_IPV6_NODE
2111 || vty->node == BGP_IPV6L_NODE || vty->node == BGP_IPV6M_NODE
e7d78d0f
PG
2112 || vty->node == BGP_EVPN_NODE
2113 || vty->node == BGP_FLOWSPECV4_NODE
2114 || vty->node == BGP_FLOWSPECV6_NODE)
d62a17ae 2115 vty->node = BGP_NODE;
2116 return CMD_SUCCESS;
2117}
4fcbf6e2 2118
d62a17ae 2119DEFUNSH(VTYSH_BGPD, exit_vni, exit_vni_cmd, "exit-vni", "Exit from VNI mode\n")
4fcbf6e2 2120{
d62a17ae 2121 if (vty->node == BGP_EVPN_VNI_NODE)
2122 vty->node = BGP_EVPN_NODE;
2123 return CMD_SUCCESS;
2124}
2125
61a484a9
QY
2126DEFUNSH(VTYSH_BGPD, rpki_exit, rpki_exit_cmd, "exit",
2127 "Exit current mode and down to previous mode\n")
2128{
2129 vtysh_exit(vty);
2130 return CMD_SUCCESS;
2131}
2132
2133DEFUNSH(VTYSH_BGPD, rpki_quit, rpki_quit_cmd, "quit",
2134 "Exit current mode and down to previous mode\n")
2135{
2136 return rpki_exit(self, vty, argc, argv);
4fcbf6e2
RW
2137}
2138
ed18356f
DL
2139DEFUNSH(VTYSH_BGPD, bmp_exit, bmp_exit_cmd, "exit",
2140 "Exit current mode and down to previous mode\n")
2141{
2142 vtysh_exit(vty);
2143 return CMD_SUCCESS;
2144}
2145
2146DEFUNSH(VTYSH_BGPD, bmp_quit, bmp_quit_cmd, "quit",
2147 "Exit current mode and down to previous mode\n")
2148{
2149 return bmp_exit(self, vty, argc, argv);
2150}
0eb5751d 2151#endif /* HAVE_BGPD */
5ff06872 2152
5d574646
IR
2153DEFUNSH(VTYSH_VRF, exit_vrf_config, exit_vrf_config_cmd, "exit-vrf",
2154 "Exit from VRF configuration mode\n")
2155{
2156 if (vty->node == VRF_NODE)
2157 vty->node = CONFIG_NODE;
2158 return CMD_SUCCESS;
2159}
2160
0eb5751d 2161#ifdef HAVE_RIPD
d62a17ae 2162DEFUNSH(VTYSH_RIPD, vtysh_exit_ripd, vtysh_exit_ripd_cmd, "exit",
2163 "Exit current mode and down to previous mode\n")
718e3744 2164{
d62a17ae 2165 return vtysh_exit(vty);
718e3744 2166}
2167
d62a17ae 2168DEFUNSH(VTYSH_RIPD, vtysh_quit_ripd, vtysh_quit_ripd_cmd, "quit",
2169 "Exit current mode and down to previous mode\n")
a98d33ab 2170{
d62a17ae 2171 return vtysh_exit_ripd(self, vty, argc, argv);
a98d33ab 2172}
0eb5751d 2173#endif /* HAVE_RIPD */
718e3744 2174
0eb5751d 2175#ifdef HAVE_RIPNGD
d62a17ae 2176DEFUNSH(VTYSH_RIPNGD, vtysh_exit_ripngd, vtysh_exit_ripngd_cmd, "exit",
2177 "Exit current mode and down to previous mode\n")
68980084 2178{
d62a17ae 2179 return vtysh_exit(vty);
68980084 2180}
2181
d62a17ae 2182DEFUNSH(VTYSH_RIPNGD, vtysh_quit_ripngd, vtysh_quit_ripngd_cmd, "quit",
2183 "Exit current mode and down to previous mode\n")
a98d33ab 2184{
d62a17ae 2185 return vtysh_exit_ripngd(self, vty, argc, argv);
a98d33ab 2186}
0eb5751d 2187#endif /* HAVE_RIPNGD */
68980084 2188
d62a17ae 2189DEFUNSH(VTYSH_RMAP, vtysh_exit_rmap, vtysh_exit_rmap_cmd, "exit",
2190 "Exit current mode and down to previous mode\n")
718e3744 2191{
d62a17ae 2192 return vtysh_exit(vty);
718e3744 2193}
2194
d62a17ae 2195DEFUNSH(VTYSH_RMAP, vtysh_quit_rmap, vtysh_quit_rmap_cmd, "quit",
2196 "Exit current mode and down to previous mode\n")
a98d33ab 2197{
d62a17ae 2198 return vtysh_exit_rmap(self, vty, argc, argv);
a98d33ab 2199}
718e3744 2200
0eb5751d 2201#ifdef HAVE_PBRD
e5c83d9b
DS
2202DEFUNSH(VTYSH_PBRD, vtysh_exit_pbr_map, vtysh_exit_pbr_map_cmd, "exit",
2203 "Exit current mode and down to previous mode\n")
2204{
2205 return vtysh_exit(vty);
2206}
2207
2208DEFUNSH(VTYSH_PBRD, vtysh_quit_pbr_map, vtysh_quit_pbr_map_cmd, "quit",
2209 "Exit current mode and down to previous mode\n")
2210{
2211 return vtysh_exit_rmap(self, vty, argc, argv);
2212}
0eb5751d 2213#endif /* HAVE_PBRD */
e5c83d9b 2214
0eb5751d 2215#ifdef HAVE_BGPD
d62a17ae 2216DEFUNSH(VTYSH_BGPD, vtysh_exit_bgpd, vtysh_exit_bgpd_cmd, "exit",
2217 "Exit current mode and down to previous mode\n")
718e3744 2218{
d62a17ae 2219 return vtysh_exit(vty);
718e3744 2220}
2221
d62a17ae 2222DEFUNSH(VTYSH_BGPD, vtysh_quit_bgpd, vtysh_quit_bgpd_cmd, "quit",
2223 "Exit current mode and down to previous mode\n")
a98d33ab 2224{
d62a17ae 2225 return vtysh_exit_bgpd(self, vty, argc, argv);
a98d33ab 2226}
0eb5751d 2227#endif /* HAVE_BGPD */
718e3744 2228
0eb5751d 2229#ifdef HAVE_OSPFD
d62a17ae 2230DEFUNSH(VTYSH_OSPFD, vtysh_exit_ospfd, vtysh_exit_ospfd_cmd, "exit",
2231 "Exit current mode and down to previous mode\n")
718e3744 2232{
d62a17ae 2233 return vtysh_exit(vty);
718e3744 2234}
2235
d62a17ae 2236DEFUNSH(VTYSH_OSPFD, vtysh_quit_ospfd, vtysh_quit_ospfd_cmd, "quit",
2237 "Exit current mode and down to previous mode\n")
a98d33ab 2238{
d62a17ae 2239 return vtysh_exit_ospfd(self, vty, argc, argv);
a98d33ab 2240}
0eb5751d 2241#endif /* HAVE_OSPFD */
718e3744 2242
0eb5751d 2243#ifdef HAVE_EIGRPD
d62a17ae 2244DEFUNSH(VTYSH_EIGRPD, vtysh_exit_eigrpd, vtysh_exit_eigrpd_cmd, "exit",
2245 "Exit current mode and down to previous mode\n")
7f57883e 2246{
d62a17ae 2247 return vtysh_exit(vty);
7f57883e
DS
2248}
2249
d62a17ae 2250DEFUNSH(VTYSH_EIGRPD, vtysh_quit_eigrpd, vtysh_quit_eigrpd_cmd, "quit",
2251 "Exit current mode and down to previous mode\n")
7f57883e 2252{
d62a17ae 2253 return vtysh_exit(vty);
7f57883e 2254}
0eb5751d 2255#endif /* HAVE_EIGRPD */
7f57883e 2256
0eb5751d 2257#ifdef HAVE_BABELD
460982cf 2258DEFUNSH(VTYSH_BABELD, vtysh_exit_babeld, vtysh_exit_babeld_cmd, "exit",
d62a17ae 2259 "Exit current mode and down to previous mode\n")
a616ea5f 2260{
d62a17ae 2261 return vtysh_exit(vty);
a616ea5f
DS
2262}
2263
d62a17ae 2264DEFUNSH(VTYSH_BABELD, vtysh_quit_babeld, vtysh_quit_babeld_cmd, "quit",
2265 "Exit current mode and down to previous mode\n")
a616ea5f 2266{
d62a17ae 2267 return vtysh_exit(vty);
a616ea5f 2268}
0eb5751d 2269#endif /* HAVE_BABELD */
a616ea5f 2270
0eb5751d 2271#ifdef HAVE_OSPF6D
d62a17ae 2272DEFUNSH(VTYSH_OSPF6D, vtysh_exit_ospf6d, vtysh_exit_ospf6d_cmd, "exit",
2273 "Exit current mode and down to previous mode\n")
68980084 2274{
d62a17ae 2275 return vtysh_exit(vty);
68980084 2276}
2277
d62a17ae 2278DEFUNSH(VTYSH_OSPF6D, vtysh_quit_ospf6d, vtysh_quit_ospf6d_cmd, "quit",
2279 "Exit current mode and down to previous mode\n")
a98d33ab 2280{
d62a17ae 2281 return vtysh_exit_ospf6d(self, vty, argc, argv);
a98d33ab 2282}
0eb5751d 2283#endif /* HAVE_OSPF6D */
68980084 2284
d62a17ae 2285#if defined(HAVE_LDPD)
2286DEFUNSH(VTYSH_LDPD, vtysh_exit_ldpd, vtysh_exit_ldpd_cmd, "exit",
2287 "Exit current mode and down to previous mode\n")
4fcbf6e2 2288{
d62a17ae 2289 return vtysh_exit(vty);
4fcbf6e2
RW
2290}
2291
d62a17ae 2292ALIAS(vtysh_exit_ldpd, vtysh_quit_ldpd_cmd, "quit",
2293 "Exit current mode and down to previous mode\n")
87ab4aec 2294#endif
4fcbf6e2 2295
0eb5751d 2296#ifdef HAVE_ISISD
d62a17ae 2297DEFUNSH(VTYSH_ISISD, vtysh_exit_isisd, vtysh_exit_isisd_cmd, "exit",
2298 "Exit current mode and down to previous mode\n")
c25e458a 2299{
d62a17ae 2300 return vtysh_exit(vty);
c25e458a 2301}
2302
d62a17ae 2303DEFUNSH(VTYSH_ISISD, vtysh_quit_isisd, vtysh_quit_isisd_cmd, "quit",
2304 "Exit current mode and down to previous mode\n")
a98d33ab 2305{
d62a17ae 2306 return vtysh_exit_isisd(self, vty, argc, argv);
a98d33ab 2307}
0eb5751d 2308#endif /* HAVE_ISISD */
c25e458a 2309
c2f29cf3
RZ
2310#if HAVE_BFDD > 0
2311DEFUNSH(VTYSH_BFDD, vtysh_exit_bfdd, vtysh_exit_bfdd_cmd, "exit",
2312 "Exit current mode and down to previous mode\n")
2313{
2314 return vtysh_exit(vty);
2315}
2316
2317ALIAS(vtysh_exit_bfdd, vtysh_quit_bfdd_cmd, "quit",
2318 "Exit current mode and down to previous mode\n")
2319#endif
2320
0eb5751d 2321#ifdef HAVE_FABRICD
770ccdf8
CF
2322DEFUNSH(VTYSH_FABRICD, vtysh_exit_fabricd, vtysh_exit_fabricd_cmd, "exit",
2323 "Exit current mode and down to previous mode\n")
2324{
2325 return vtysh_exit(vty);
2326}
2327
2328DEFUNSH(VTYSH_FABRICD, vtysh_quit_fabricd, vtysh_quit_fabricd_cmd, "quit",
2329 "Exit current mode and down to previous mode\n")
2330{
2331 return vtysh_exit_fabricd(self, vty, argc, argv);
2332}
0eb5751d 2333#endif /* HAVE_FABRICD */
770ccdf8 2334
949467e2
IR
2335DEFUNSH(VTYSH_KEYS, vtysh_exit_keys, vtysh_exit_keys_cmd, "exit",
2336 "Exit current mode and down to previous mode\n")
2337{
2338 return vtysh_exit(vty);
2339}
2340
2341DEFUNSH(VTYSH_KEYS, vtysh_quit_keys, vtysh_quit_keys_cmd, "quit",
2342 "Exit current mode and down to previous mode\n")
2343{
2344 return vtysh_exit_keys(self, vty, argc, argv);
2345}
2346
d62a17ae 2347DEFUNSH(VTYSH_ALL, vtysh_exit_line_vty, vtysh_exit_line_vty_cmd, "exit",
2348 "Exit current mode and down to previous mode\n")
e7168df4 2349{
d62a17ae 2350 return vtysh_exit(vty);
e7168df4 2351}
2352
d62a17ae 2353DEFUNSH(VTYSH_ALL, vtysh_quit_line_vty, vtysh_quit_line_vty_cmd, "quit",
2354 "Exit current mode and down to previous mode\n")
a98d33ab 2355{
d62a17ae 2356 return vtysh_exit_line_vty(self, vty, argc, argv);
a98d33ab 2357}
e7168df4 2358
d62a17ae 2359DEFUNSH(VTYSH_INTERFACE, vtysh_interface, vtysh_interface_cmd,
2360 "interface IFNAME [vrf NAME]",
2361 "Select an interface to configure\n"
2362 "Interface's name\n" VRF_CMD_HELP_STR)
718e3744 2363{
d62a17ae 2364 vty->node = INTERFACE_NODE;
2365 return CMD_SUCCESS;
718e3744 2366}
2367
2dd0d726
RW
2368DEFUNSH(VTYSH_ZEBRA, vtysh_pseudowire, vtysh_pseudowire_cmd,
2369 "pseudowire IFNAME",
2370 "Static pseudowire configuration\n"
2371 "Pseudowire name\n")
2372{
2373 vty->node = PW_NODE;
2374 return CMD_SUCCESS;
2375}
2376
7183a034
MS
2377DEFUNSH(VTYSH_NH_GROUP,
2378 vtysh_nexthop_group, vtysh_nexthop_group_cmd,
868ee86c 2379 "nexthop-group NHGNAME",
e5c83d9b
DS
2380 "Nexthop Group configuration\n"
2381 "Name of the Nexthop Group\n")
2382{
2383 vty->node = NH_GROUP_NODE;
2384 return CMD_SUCCESS;
2385}
2386
7183a034 2387DEFSH(VTYSH_NH_GROUP, vtysh_no_nexthop_group_cmd,
868ee86c 2388 "no nexthop-group NHGNAME",
e5c83d9b
DS
2389 NO_STR
2390 "Nexthop Group Configuration\n"
2391 "Name of the Nexthop Group\n")
2392
d62a17ae 2393DEFUNSH(VTYSH_VRF, vtysh_vrf, vtysh_vrf_cmd, "vrf NAME",
2394 "Select a VRF to configure\n"
2395 "VRF's name\n")
e9d94ea7 2396{
d62a17ae 2397 vty->node = VRF_NODE;
2398 return CMD_SUCCESS;
e9d94ea7
DS
2399}
2400
34c46274
RW
2401DEFSH(VTYSH_ZEBRA, vtysh_vrf_netns_cmd,
2402 "netns NAME",
2403 "Attach VRF to a Namespace\n"
2404 "The file name in " NS_RUN_DIR ", or a full pathname\n")
2405
2406DEFSH(VTYSH_ZEBRA, vtysh_no_vrf_netns_cmd,
2407 "no netns [NAME]",
2408 NO_STR
2409 "Detach VRF from a Namespace\n"
2410 "The file name in " NS_RUN_DIR ", or a full pathname\n")
e9d94ea7 2411
d62a17ae 2412DEFUNSH(VTYSH_VRF, vtysh_exit_vrf, vtysh_exit_vrf_cmd, "exit",
2413 "Exit current mode and down to previous mode\n")
e9d94ea7 2414{
d62a17ae 2415 return vtysh_exit(vty);
e9d94ea7
DS
2416}
2417
d62a17ae 2418DEFUNSH(VTYSH_VRF, vtysh_quit_vrf, vtysh_quit_vrf_cmd, "quit",
2419 "Exit current mode and down to previous mode\n")
a98d33ab 2420{
d62a17ae 2421 return vtysh_exit_vrf(self, vty, argc, argv);
a98d33ab 2422}
e9d94ea7 2423
7183a034
MS
2424DEFUNSH(VTYSH_NH_GROUP,
2425 vtysh_exit_nexthop_group, vtysh_exit_nexthop_group_cmd,
e5c83d9b
DS
2426 "exit", "Exit current mode and down to previous mode\n")
2427{
2428 return vtysh_exit(vty);
2429}
2430
7183a034
MS
2431DEFUNSH(VTYSH_NH_GROUP,
2432 vtysh_quit_nexthop_group, vtysh_quit_nexthop_group_cmd,
e5c83d9b
DS
2433 "quit", "Exit current mode and down to previous mode\n")
2434{
2435 return vtysh_exit_nexthop_group(self, vty, argc, argv);
2436}
2437
d62a17ae 2438DEFUNSH(VTYSH_INTERFACE, vtysh_exit_interface, vtysh_exit_interface_cmd, "exit",
2439 "Exit current mode and down to previous mode\n")
718e3744 2440{
d62a17ae 2441 return vtysh_exit(vty);
718e3744 2442}
2443
d62a17ae 2444DEFUNSH(VTYSH_INTERFACE, vtysh_quit_interface, vtysh_quit_interface_cmd, "quit",
2445 "Exit current mode and down to previous mode\n")
a98d33ab 2446{
d62a17ae 2447 return vtysh_exit_interface(self, vty, argc, argv);
a98d33ab 2448}
718e3744 2449
8872626b
DS
2450DEFUN (vtysh_show_poll,
2451 vtysh_show_poll_cmd,
2452 "show thread poll",
2453 SHOW_STR
2454 "Thread information\n"
2455 "Thread Poll Information\n")
2456{
2457 unsigned int i;
8872626b
DS
2458 int ret = CMD_SUCCESS;
2459 char line[100];
2460
2461 snprintf(line, sizeof(line), "do show thread poll\n");
2462 for (i = 0; i < array_size(vtysh_client); i++)
2463 if (vtysh_client[i].fd >= 0) {
2464 vty_out(vty, "Thread statistics for %s:\n",
2465 vtysh_client[i].name);
2466 ret = vtysh_client_execute(&vtysh_client[i], line);
2467 vty_out(vty, "\n");
2468 }
2469 return ret;
2470}
2471
f75e802d 2472#ifndef EXCLUDE_CPU_TIME
0f69b58c
DS
2473DEFUN (vtysh_show_thread,
2474 vtysh_show_thread_cmd,
2475 "show thread cpu [FILTER]",
c25c6137
QY
2476 SHOW_STR
2477 "Thread information\n"
2478 "Thread CPU usage\n"
2479 "Display filter (rwtexb)\n")
0f69b58c 2480{
d62a17ae 2481 unsigned int i;
2482 int idx = 0;
2483 int ret = CMD_SUCCESS;
2484 char line[100];
0f69b58c 2485
d62a17ae 2486 const char *filter =
2487 argv_find(argv, argc, "FILTER", &idx) ? argv[idx]->arg : "";
c25c6137 2488
d62a17ae 2489 snprintf(line, sizeof(line), "do show thread cpu %s\n", filter);
2490 for (i = 0; i < array_size(vtysh_client); i++)
2491 if (vtysh_client[i].fd >= 0) {
2cddf2ff 2492 vty_out(vty, "Thread statistics for %s:\n",
d62a17ae 2493 vtysh_client[i].name);
2cddf2ff
QY
2494 ret = vtysh_client_execute(&vtysh_client[i], line);
2495 vty_out(vty, "\n");
d62a17ae 2496 }
2497 return ret;
0f69b58c 2498}
f75e802d 2499#endif
0f69b58c
DS
2500
2501DEFUN (vtysh_show_work_queues,
2502 vtysh_show_work_queues_cmd,
2503 "show work-queues",
2504 SHOW_STR
2505 "Work Queue information\n")
2506{
d62a17ae 2507 unsigned int i;
2508 int ret = CMD_SUCCESS;
2509 char line[] = "do show work-queues\n";
0f69b58c 2510
d62a17ae 2511 for (i = 0; i < array_size(vtysh_client); i++)
2512 if (vtysh_client[i].fd >= 0) {
2cddf2ff 2513 vty_out(vty, "Work queue statistics for %s:\n",
d62a17ae 2514 vtysh_client[i].name);
2cddf2ff
QY
2515 ret = vtysh_client_execute(&vtysh_client[i], line);
2516 vty_out(vty, "\n");
d62a17ae 2517 }
0f69b58c 2518
d62a17ae 2519 return ret;
0f69b58c
DS
2520}
2521
b47b0a84
DS
2522DEFUN (vtysh_show_work_queues_daemon,
2523 vtysh_show_work_queues_daemon_cmd,
2e77de95 2524 "show work-queues " DAEMONS_LIST,
b47b0a84
DS
2525 SHOW_STR
2526 "Work Queue information\n"
2e77de95 2527 DAEMONS_STR)
b47b0a84 2528{
d62a17ae 2529 int idx_protocol = 2;
b47b0a84 2530
f9ed934c
SW
2531 return vtysh_client_execute_name(argv[idx_protocol]->text,
2532 "show work-queues\n");
b47b0a84
DS
2533}
2534
d62a17ae 2535DEFUNSH(VTYSH_ZEBRA, vtysh_link_params, vtysh_link_params_cmd, "link-params",
2536 LINK_PARAMS_STR)
16f1b9ee 2537{
d62a17ae 2538 vty->node = LINK_PARAMS_NODE;
2539 return CMD_SUCCESS;
16f1b9ee
OD
2540}
2541
d62a17ae 2542DEFUNSH(VTYSH_ZEBRA, exit_link_params, exit_link_params_cmd, "exit-link-params",
2543 "Exit from Link Params configuration node\n")
03f99d9a 2544{
d62a17ae 2545 if (vty->node == LINK_PARAMS_NODE)
2546 vty->node = INTERFACE_NODE;
2547 return CMD_SUCCESS;
03f99d9a
DS
2548}
2549
d62a17ae 2550static int show_per_daemon(const char *line, const char *headline)
362b4031 2551{
d62a17ae 2552 unsigned int i;
2553 int ret = CMD_SUCCESS;
2a8e27af 2554
d62a17ae 2555 for (i = 0; i < array_size(vtysh_client); i++)
2556 if (vtysh_client[i].fd >= 0) {
2cddf2ff
QY
2557 vty_out(vty, headline, vtysh_client[i].name);
2558 ret = vtysh_client_execute(&vtysh_client[i], line);
2559 vty_out(vty, "\n");
d62a17ae 2560 }
2a8e27af 2561
d62a17ae 2562 return ret;
362b4031
PJ
2563}
2564
aea03ad6
QY
2565DEFUNSH_HIDDEN (0x00,
2566 vtysh_debug_all,
2567 vtysh_debug_all_cmd,
2568 "[no] debug all",
2569 NO_STR
2570 DEBUG_STR
2571 "Toggle all debugs on or off\n")
2572{
2573 return CMD_SUCCESS;
2574}
2575
87f6dc50
DS
2576DEFUN (vtysh_show_debugging,
2577 vtysh_show_debugging_cmd,
2578 "show debugging",
2579 SHOW_STR
2580 DEBUG_STR)
2581{
996c9314 2582 return show_per_daemon("do show debugging\n", "");
87f6dc50
DS
2583}
2584
40818cec
DL
2585DEFUN (vtysh_show_debugging_hashtable,
2586 vtysh_show_debugging_hashtable_cmd,
2587 "show debugging hashtable [statistics]",
2588 SHOW_STR
2589 DEBUG_STR
2590 "Statistics about hash tables\n"
2591 "Statistics about hash tables\n")
2592{
2cddf2ff
QY
2593 vty_out(vty, "\n");
2594 vty_out(vty,
44deef01 2595 "Load factor (LF) - average number of elements across all buckets\n");
2cddf2ff 2596 vty_out(vty,
44deef01 2597 "Full load factor (FLF) - average number of elements across full buckets\n\n");
2cddf2ff 2598 vty_out(vty,
44deef01 2599 "Standard deviation (SD) is calculated for both the LF and FLF\n");
2cddf2ff 2600 vty_out(vty,
44deef01 2601 "and indicates the typical deviation of bucket chain length\n");
2cddf2ff 2602 vty_out(vty, "from the value in the corresponding load factor.\n\n");
44deef01 2603
40818cec
DL
2604 return show_per_daemon("do show debugging hashtable\n",
2605 "Hashtable statistics for %s:\n");
2606}
2607
7b526b61
QY
2608DEFUN (vtysh_show_error_code,
2609 vtysh_show_error_code_cmd,
ed8841d3 2610 "show error <(1-4294967296)|all> [json]",
7b526b61
QY
2611 SHOW_STR
2612 "Information on errors\n"
ed8841d3
QY
2613 "Error code to get info about\n"
2614 "Information on all errors\n"
2615 JSON_STR)
7b526b61 2616{
1f9128d6
QY
2617 uint32_t arg = 0;
2618
2619 if (!strmatch(argv[2]->text, "all"))
2620 arg = strtoul(argv[2]->arg, NULL, 10);
2621
2622 /* If it's not a shared code, send it to all the daemons */
2623 if (arg < LIB_FERR_START || arg > LIB_FERR_END) {
2624 char *fcmd = argv_concat(argv, argc, 0);
2625 char cmd[256];
2d6e4d2e 2626
1f9128d6
QY
2627 snprintf(cmd, sizeof(cmd), "do %s", fcmd);
2628 show_per_daemon(cmd, "");
2629 XFREE(MTYPE_TMP, fcmd);
2630 /* Otherwise, print it ourselves to avoid duplication */
2631 } else {
2632 bool json = strmatch(argv[argc - 1]->text, "json");
2d6e4d2e 2633
1f9128d6
QY
2634 if (!strmatch(argv[2]->text, "all"))
2635 arg = strtoul(argv[2]->arg, NULL, 10);
2636
2637 log_ref_display(vty, arg, json);
2638 }
ed8841d3 2639
1f9128d6 2640 return CMD_SUCCESS;
7b526b61
QY
2641}
2642
4ad77140 2643/* Northbound. */
eba4e1ea
RW
2644DEFUN (show_yang_operational_data,
2645 show_yang_operational_data_cmd,
21f5aade 2646 "show yang operational-data XPATH\
eba4e1ea 2647 [{\
21f5aade
RW
2648 format <json|xml>\
2649 |translate WORD\
eba4e1ea
RW
2650 }]" DAEMONS_LIST,
2651 SHOW_STR
2652 "YANG information\n"
2653 "Show YANG operational data\n"
2654 "XPath expression specifying the YANG data path\n"
2655 "Set the output format\n"
2656 "JavaScript Object Notation\n"
2657 "Extensible Markup Language\n"
2658 "Translate operational data\n"
2659 "YANG module translator\n"
2660 DAEMONS_STR)
2661{
2662 int idx_protocol = argc - 1;
2663 char *fcmd = argv_concat(argv, argc - 1, 0);
2664 int ret = vtysh_client_execute_name(argv[idx_protocol]->text, fcmd);
2665 XFREE(MTYPE_TMP, fcmd);
2666 return ret;
2667}
2668
4ad77140
RW
2669DEFUNSH(VTYSH_ALL, debug_nb,
2670 debug_nb_cmd,
2671 "[no] debug northbound\
2672 [<\
21f5aade
RW
2673 callbacks [{configuration|state|rpc}]\
2674 |notifications\
2675 |events\
62ae9ade 2676 |libyang\
4ad77140
RW
2677 >]",
2678 NO_STR
2679 DEBUG_STR
2680 "Northbound debugging\n"
2681 "Callbacks\n"
2682 "Configuration\n"
2683 "State\n"
2684 "RPC\n"
2685 "Notifications\n"
62ae9ade
RW
2686 "Events\n"
2687 "libyang debugging\n")
4ad77140
RW
2688{
2689 return CMD_SUCCESS;
2690}
2691
2a8e27af
DL
2692/* Memory */
2693DEFUN (vtysh_show_memory,
2694 vtysh_show_memory_cmd,
2695 "show memory",
2696 SHOW_STR
2697 "Memory statistics\n")
2698{
d991a3ea 2699 return show_per_daemon("do show memory\n", "Memory statistics for %s:\n");
2a8e27af
DL
2700}
2701
2702DEFUN (vtysh_show_modules,
2703 vtysh_show_modules_cmd,
2704 "show modules",
2705 SHOW_STR
2706 "Loaded modules\n")
2707{
d991a3ea 2708 return show_per_daemon("do show modules\n",
d62a17ae 2709 "Module information for %s:\n");
2a8e27af
DL
2710}
2711
95e735b5 2712/* Logging commands. */
dbf7d13d
PJ
2713DEFUN (vtysh_show_logging,
2714 vtysh_show_logging_cmd,
2715 "show logging",
2716 SHOW_STR
2717 "Show current logging configuration\n")
2718{
7292d851
DS
2719 return show_per_daemon("do show logging\n",
2720 "Logging configuration for %s:\n");
d62a17ae 2721}
2722
2723DEFUNSH(VTYSH_ALL, vtysh_log_stdout, vtysh_log_stdout_cmd, "log stdout",
2724 "Logging control\n"
2725 "Set stdout logging level\n")
95e735b5 2726{
d62a17ae 2727 return CMD_SUCCESS;
2728}
2729
2730DEFUNSH(VTYSH_ALL, vtysh_log_stdout_level, vtysh_log_stdout_level_cmd,
2731 "log stdout <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
2732 "Logging control\n"
2733 "Set stdout logging level\n" LOG_LEVEL_DESC)
95e735b5 2734{
d62a17ae 2735 return CMD_SUCCESS;
95e735b5 2736}
2737
d62a17ae 2738DEFUNSH(VTYSH_ALL, no_vtysh_log_stdout, no_vtysh_log_stdout_cmd,
9d303b37 2739 "no log stdout [LEVEL]", NO_STR
d62a17ae 2740 "Logging control\n"
2741 "Cancel logging to stdout\n"
2742 "Logging level\n")
95e735b5 2743{
d62a17ae 2744 return CMD_SUCCESS;
95e735b5 2745}
2746
d62a17ae 2747DEFUNSH(VTYSH_ALL, vtysh_log_file, vtysh_log_file_cmd, "log file FILENAME",
2748 "Logging control\n"
2749 "Logging to file\n"
2750 "Logging filename\n")
274a4a44 2751{
d62a17ae 2752 return CMD_SUCCESS;
274a4a44 2753}
2754
d62a17ae 2755DEFUNSH(VTYSH_ALL, vtysh_log_file_level, vtysh_log_file_level_cmd,
2756 "log file FILENAME <emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>",
2757 "Logging control\n"
2758 "Logging to file\n"
2759 "Logging filename\n" LOG_LEVEL_DESC)
95e735b5 2760{
d62a17ae 2761 return CMD_SUCCESS;
95e735b5 2762}
2763
d62a17ae 2764DEFUNSH(VTYSH_ALL, no_vtysh_log_file, no_vtysh_log_file_cmd,
9d303b37 2765 "no log file [FILENAME [LEVEL]]", NO_STR
d62a17ae 2766 "Logging control\n"
2767 "Cancel logging to file\n"
2768 "Logging file name\n"
2769 "Logging level\n")
274a4a44 2770{
d62a17ae 2771 return CMD_SUCCESS;
274a4a44 2772}
2773
d62a17ae 2774DEFUNSH(VTYSH_ALL, vtysh_log_monitor, vtysh_log_monitor_cmd,
2775 "log monitor [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
2776 "Logging control\n"
2777 "Set terminal line (monitor) logging level\n" LOG_LEVEL_DESC)
274a4a44 2778{
d62a17ae 2779 return CMD_SUCCESS;
274a4a44 2780}
2781
d62a17ae 2782DEFUNSH(VTYSH_ALL, no_vtysh_log_monitor, no_vtysh_log_monitor_cmd,
9d303b37 2783 "no log monitor [LEVEL]", NO_STR
d62a17ae 2784 "Logging control\n"
2785 "Disable terminal line (monitor) logging\n"
2786 "Logging level\n")
95e735b5 2787{
d62a17ae 2788 return CMD_SUCCESS;
95e735b5 2789}
2790
d62a17ae 2791DEFUNSH(VTYSH_ALL, vtysh_log_syslog, vtysh_log_syslog_cmd,
2792 "log syslog [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
2793 "Logging control\n"
2794 "Set syslog logging level\n" LOG_LEVEL_DESC)
95e735b5 2795{
d62a17ae 2796 return CMD_SUCCESS;
95e735b5 2797}
2798
d62a17ae 2799DEFUNSH(VTYSH_ALL, no_vtysh_log_syslog, no_vtysh_log_syslog_cmd,
1f143236
DS
2800 "no log syslog [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
2801 NO_STR
d62a17ae 2802 "Logging control\n"
2803 "Cancel logging to syslog\n"
1f143236 2804 LOG_LEVEL_DESC)
d62a17ae 2805{
2806 return CMD_SUCCESS;
2807}
2808
2809DEFUNSH(VTYSH_ALL, vtysh_log_facility, vtysh_log_facility_cmd,
2810 "log facility <kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|local0|local1|local2|local3|local4|local5|local6|local7>",
2811 "Logging control\n"
2812 "Facility parameter for syslog messages\n" LOG_FACILITY_DESC)
95e735b5 2813{
d62a17ae 2814 return CMD_SUCCESS;
95e735b5 2815}
2816
d62a17ae 2817DEFUNSH(VTYSH_ALL, no_vtysh_log_facility, no_vtysh_log_facility_cmd,
b0c36380
IR
2818 "no log facility [<kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|local0|local1|local2|local3|local4|local5|local6|local7>]",
2819 NO_STR
d62a17ae 2820 "Logging control\n"
2821 "Reset syslog facility to default (daemon)\n"
b0c36380 2822 LOG_FACILITY_DESC)
274a4a44 2823{
d62a17ae 2824 return CMD_SUCCESS;
274a4a44 2825}
2826
d62a17ae 2827DEFUNSH(VTYSH_ALL, vtysh_log_record_priority, vtysh_log_record_priority_cmd,
2828 "log record-priority",
2829 "Logging control\n"
2830 "Log the priority of the message within the message\n")
95e735b5 2831{
d62a17ae 2832 return CMD_SUCCESS;
95e735b5 2833}
2834
d62a17ae 2835DEFUNSH(VTYSH_ALL, no_vtysh_log_record_priority,
9d303b37 2836 no_vtysh_log_record_priority_cmd, "no log record-priority", NO_STR
d62a17ae 2837 "Logging control\n"
2838 "Do not log the priority of the message within the message\n")
95e735b5 2839{
d62a17ae 2840 return CMD_SUCCESS;
95e735b5 2841}
2842
d62a17ae 2843DEFUNSH(VTYSH_ALL, vtysh_log_timestamp_precision,
2844 vtysh_log_timestamp_precision_cmd, "log timestamp precision (0-6)",
2845 "Logging control\n"
2846 "Timestamp configuration\n"
2847 "Set the timestamp precision\n"
2848 "Number of subsecond digits\n")
c749b722 2849{
d62a17ae 2850 return CMD_SUCCESS;
c749b722
AS
2851}
2852
85a6806d
MS
2853DEFUNSH(VTYSH_ALL, vtysh_debug_memstats,
2854 vtysh_debug_memstats_cmd, "[no] debug memstats-at-exit",
2855 NO_STR
2856 "Debug\n"
2857 "Print memory statistics at exit\n")
2858{
2859 return CMD_SUCCESS;
2860}
2861
d62a17ae 2862DEFUNSH(VTYSH_ALL, no_vtysh_log_timestamp_precision,
2863 no_vtysh_log_timestamp_precision_cmd, "no log timestamp precision",
2864 NO_STR
2865 "Logging control\n"
2866 "Timestamp configuration\n"
2867 "Reset the timestamp precision to the default value of 0\n")
c749b722 2868{
d62a17ae 2869 return CMD_SUCCESS;
c749b722
AS
2870}
2871
d62a17ae 2872DEFUNSH(VTYSH_ALL, vtysh_service_password_encrypt,
2873 vtysh_service_password_encrypt_cmd, "service password-encryption",
2874 "Set up miscellaneous service\n"
2875 "Enable encrypted passwords\n")
e7168df4 2876{
d62a17ae 2877 return CMD_SUCCESS;
e7168df4 2878}
2879
d62a17ae 2880DEFUNSH(VTYSH_ALL, no_vtysh_service_password_encrypt,
2881 no_vtysh_service_password_encrypt_cmd, "no service password-encryption",
2882 NO_STR
2883 "Set up miscellaneous service\n"
2884 "Enable encrypted passwords\n")
e7168df4 2885{
d62a17ae 2886 return CMD_SUCCESS;
e7168df4 2887}
2888
d62a17ae 2889DEFUNSH(VTYSH_ALL, vtysh_config_password, vtysh_password_cmd,
2890 "password [(8-8)] LINE",
322e2d5c 2891 "Modify the terminal connection password\n"
d62a17ae 2892 "Specifies a HIDDEN password will follow\n"
2893 "The password string\n")
e7168df4 2894{
d62a17ae 2895 return CMD_SUCCESS;
e7168df4 2896}
2897
322e2d5c
PM
2898DEFUNSH(VTYSH_ALL, no_vtysh_config_password, no_vtysh_password_cmd,
2899 "no password", NO_STR
2900 "Modify the terminal connection password\n")
2901{
4911ca9c 2902 vty_out(vty, NO_PASSWD_CMD_WARNING);
eb83f7ce 2903
322e2d5c
PM
2904 return CMD_SUCCESS;
2905}
2906
d62a17ae 2907DEFUNSH(VTYSH_ALL, vtysh_config_enable_password, vtysh_enable_password_cmd,
2908 "enable password [(8-8)] LINE",
2909 "Modify enable password parameters\n"
2910 "Assign the privileged level password\n"
2911 "Specifies a HIDDEN password will follow\n"
2912 "The 'enable' password string\n")
e7168df4 2913{
d62a17ae 2914 return CMD_SUCCESS;
e7168df4 2915}
2916
d62a17ae 2917DEFUNSH(VTYSH_ALL, no_vtysh_config_enable_password,
9d303b37 2918 no_vtysh_enable_password_cmd, "no enable password", NO_STR
d62a17ae 2919 "Modify enable password parameters\n"
2920 "Assign the privileged level password\n")
e7168df4 2921{
4911ca9c 2922 vty_out(vty, NO_PASSWD_CMD_WARNING);
eb83f7ce 2923
d62a17ae 2924 return CMD_SUCCESS;
e7168df4 2925}
2926
718e3744 2927DEFUN (vtysh_write_terminal,
2928 vtysh_write_terminal_cmd,
30941443 2929 "write terminal ["DAEMONS_LIST"] [no-header]",
718e3744 2930 "Write running configuration to memory, network, or terminal\n"
066242b5 2931 "Write to terminal\n"
30941443
DL
2932 DAEMONS_STR
2933 "Skip \"Building configuration...\" header\n")
718e3744 2934{
d7c0a89a 2935 unsigned int i;
d62a17ae 2936 char line[] = "do write terminal\n";
d62a17ae 2937
30941443
DL
2938 if (!strcmp(argv[argc - 1]->arg, "no-header"))
2939 argc--;
2940 else {
2941 vty_out(vty, "Building configuration...\n");
2942 vty_out(vty, "\nCurrent configuration:\n");
2943 vty_out(vty, "!\n");
2944 }
d62a17ae 2945
2946 for (i = 0; i < array_size(vtysh_client); i++)
2947 if ((argc < 3)
2948 || (strmatch(vtysh_client[i].name, argv[2]->text)))
2949 vtysh_client_config(&vtysh_client[i], line);
2950
2951 /* Integrate vtysh specific configuration. */
2cddf2ff 2952 vty_open_pager(vty);
d62a17ae 2953 vtysh_config_write();
2cddf2ff
QY
2954 vtysh_config_dump();
2955 vty_close_pager(vty);
2956 vty_out(vty, "end\n");
d62a17ae 2957
d62a17ae 2958 return CMD_SUCCESS;
718e3744 2959}
2960
a98d33ab
QY
2961DEFUN (vtysh_show_running_config,
2962 vtysh_show_running_config_cmd,
30941443 2963 "show running-config ["DAEMONS_LIST"] [no-header]",
a98d33ab
QY
2964 SHOW_STR
2965 "Current operating configuration\n"
30941443
DL
2966 DAEMONS_STR
2967 "Skip \"Building configuration...\" header\n")
c006e89e 2968{
d62a17ae 2969 return vtysh_write_terminal(self, vty, argc, argv);
c006e89e
DS
2970}
2971
e7168df4 2972DEFUN (vtysh_integrated_config,
2973 vtysh_integrated_config_cmd,
2974 "service integrated-vtysh-config",
2975 "Set up miscellaneous service\n"
2976 "Write configuration into integrated file\n")
4fc01e67 2977{
d62a17ae 2978 vtysh_write_integrated = WRITE_INTEGRATED_YES;
2979 return CMD_SUCCESS;
4fc01e67 2980}
2981
e7168df4 2982DEFUN (no_vtysh_integrated_config,
2983 no_vtysh_integrated_config_cmd,
2984 "no service integrated-vtysh-config",
2985 NO_STR
2986 "Set up miscellaneous service\n"
2987 "Write configuration into integrated file\n")
4fc01e67 2988{
d62a17ae 2989 vtysh_write_integrated = WRITE_INTEGRATED_NO;
2990 return CMD_SUCCESS;
4fc01e67 2991}
2992
d62a17ae 2993static void backup_config_file(const char *fbackup)
718e3744 2994{
d62a17ae 2995 char *integrate_sav = NULL;
718e3744 2996
2e600d75
QY
2997 size_t integrate_sav_sz = strlen(fbackup) + strlen(CONF_BACKUP_EXT) + 1;
2998 integrate_sav = malloc(integrate_sav_sz);
2999 strlcpy(integrate_sav, fbackup, integrate_sav_sz);
3000 strlcat(integrate_sav, CONF_BACKUP_EXT, integrate_sav_sz);
718e3744 3001
d62a17ae 3002 /* Move current configuration file to backup config file. */
9fb05a74
TA
3003 if (unlink(integrate_sav) != 0 && errno != ENOENT)
3004 vty_out(vty, "Unlink failed for %s: %s\n", integrate_sav,
3005 strerror(errno));
3006 if (rename(fbackup, integrate_sav) != 0 && errno != ENOENT)
3007 vty_out(vty, "Error renaming %s to %s: %s\n", fbackup,
3008 integrate_sav, strerror(errno));
d62a17ae 3009 free(integrate_sav);
a7222276
DS
3010}
3011
d62a17ae 3012int vtysh_write_config_integrated(void)
a7222276 3013{
d7c0a89a 3014 unsigned int i;
d62a17ae 3015 char line[] = "do write terminal\n";
3016 FILE *fp;
3017 int fd;
029a775e 3018#ifdef FRR_USER
d62a17ae 3019 struct passwd *pwentry;
029a775e 3020#endif
3021#ifdef FRR_GROUP
d62a17ae 3022 struct group *grentry;
029a775e 3023#endif
d62a17ae 3024 uid_t uid = -1;
3025 gid_t gid = -1;
3026 struct stat st;
3027 int err = 0;
a7222276 3028
2cddf2ff 3029 vty_out(vty, "Building Configuration...\n");
a7222276 3030
9b8a8249
DL
3031 backup_config_file(frr_config);
3032 fp = fopen(frr_config, "w");
d62a17ae 3033 if (fp == NULL) {
2cddf2ff 3034 vty_out(vty,
d62a17ae 3035 "%% Error: failed to open configuration file %s: %s\n",
9b8a8249 3036 frr_config, safe_strerror(errno));
d62a17ae 3037 return CMD_WARNING_CONFIG_FAILED;
3038 }
3039 fd = fileno(fp);
a7222276 3040
d62a17ae 3041 for (i = 0; i < array_size(vtysh_client); i++)
3042 vtysh_client_config(&vtysh_client[i], line);
718e3744 3043
d62a17ae 3044 vtysh_config_write();
b7ae6ac4
QY
3045 vty->of_saved = vty->of;
3046 vty->of = fp;
2cddf2ff 3047 vtysh_config_dump();
b7ae6ac4 3048 vty->of = vty->of_saved;
718e3744 3049
d62a17ae 3050 if (fchmod(fd, CONFIGFILE_MASK) != 0) {
3051 printf("%% Warning: can't chmod configuration file %s: %s\n",
9b8a8249 3052 frr_config, safe_strerror(errno));
d62a17ae 3053 err++;
3054 }
718e3744 3055
9e8df988 3056#ifdef FRR_USER
d62a17ae 3057 pwentry = getpwnam(FRR_USER);
3058 if (pwentry)
3059 uid = pwentry->pw_uid;
3060 else {
3061 printf("%% Warning: could not look up user \"%s\"\n", FRR_USER);
3062 err++;
3063 }
9e8df988
JAG
3064#endif
3065#ifdef FRR_GROUP
d62a17ae 3066 grentry = getgrnam(FRR_GROUP);
3067 if (grentry)
3068 gid = grentry->gr_gid;
3069 else {
3070 printf("%% Warning: could not look up group \"%s\"\n",
3071 FRR_GROUP);
3072 err++;
3073 }
9e8df988 3074#endif
4fc01e67 3075
d62a17ae 3076 if (!fstat(fd, &st)) {
3077 if (st.st_uid == uid)
3078 uid = -1;
3079 if (st.st_gid == gid)
3080 gid = -1;
3081 if ((uid != (uid_t)-1 || gid != (gid_t)-1)
3082 && fchown(fd, uid, gid)) {
3083 printf("%% Warning: can't chown configuration file %s: %s\n",
9b8a8249 3084 frr_config, safe_strerror(errno));
d62a17ae 3085 err++;
3086 }
3087 } else {
9b8a8249 3088 printf("%% Warning: stat() failed on %s: %s\n", frr_config,
d62a17ae 3089 safe_strerror(errno));
3090 err++;
3091 }
3092
3093 fclose(fp);
3094
9b8a8249 3095 printf("Integrated configuration saved to %s\n", frr_config);
d62a17ae 3096 if (err)
3097 return CMD_WARNING;
3098
3099 printf("[OK]\n");
3100 return CMD_SUCCESS;
718e3744 3101}
3102
a68f8616 3103static bool want_config_integrated(void)
039eaca3 3104{
d62a17ae 3105 struct stat s;
3106
3107 switch (vtysh_write_integrated) {
3108 case WRITE_INTEGRATED_UNSPECIFIED:
9b8a8249 3109 if (stat(frr_config, &s) && errno == ENOENT)
d62a17ae 3110 return false;
3111 return true;
3112 case WRITE_INTEGRATED_NO:
3113 return false;
3114 case WRITE_INTEGRATED_YES:
3115 return true;
3116 }
3117 return true;
039eaca3
CF
3118}
3119
4fc01e67 3120DEFUN (vtysh_write_memory,
3121 vtysh_write_memory_cmd,
a98d33ab 3122 "write [<memory|file>]",
4fc01e67 3123 "Write running configuration to memory, network, or terminal\n"
a98d33ab
QY
3124 "Write configuration to the file (same as write file)\n"
3125 "Write configuration to the file (same as write memory)\n")
4fc01e67 3126{
d62a17ae 3127 int ret = CMD_SUCCESS;
3128 char line[] = "do write memory\n";
d7c0a89a 3129 unsigned int i;
d62a17ae 3130
2cddf2ff 3131 vty_out(vty, "Note: this version of vtysh never writes vtysh.conf\n");
d62a17ae 3132
3133 /* If integrated frr.conf explicitely set. */
3134 if (want_config_integrated()) {
3135 ret = CMD_WARNING_CONFIG_FAILED;
869f5586
QY
3136
3137 /* first attempt to use watchfrr if it's available */
3138 bool used_watchfrr = false;
3139
d62a17ae 3140 for (i = 0; i < array_size(vtysh_client); i++)
3141 if (vtysh_client[i].flag == VTYSH_WATCHFRR)
3142 break;
869f5586
QY
3143 if (i < array_size(vtysh_client) && vtysh_client[i].fd != -1) {
3144 used_watchfrr = true;
d62a17ae 3145 ret = vtysh_client_execute(&vtysh_client[i],
2cddf2ff 3146 "do write integrated");
869f5586 3147 }
d62a17ae 3148
470bc619 3149 /*
869f5586
QY
3150 * If we didn't use watchfrr, fallback to writing the config
3151 * ourselves
470bc619 3152 */
869f5586 3153 if (!used_watchfrr) {
3efd0893 3154 printf("\nWarning: attempting direct configuration write without watchfrr.\nFile permissions and ownership may be incorrect, or write may fail.\n\n");
d62a17ae 3155 ret = vtysh_write_config_integrated();
3156 }
3157 return ret;
3158 }
a7222276 3159
2cddf2ff 3160 vty_out(vty, "Building Configuration...\n");
a7222276 3161
d62a17ae 3162 for (i = 0; i < array_size(vtysh_client); i++)
2cddf2ff 3163 ret = vtysh_client_execute(&vtysh_client[i], line);
4fc01e67 3164
d62a17ae 3165 return ret;
4fc01e67 3166}
3167
a98d33ab
QY
3168DEFUN (vtysh_copy_running_config,
3169 vtysh_copy_running_config_cmd,
3170 "copy running-config startup-config",
718e3744 3171 "Copy from one file to another\n"
3172 "Copy from current system configuration\n"
3173 "Copy to startup configuration\n")
a98d33ab 3174{
d62a17ae 3175 return vtysh_write_memory(self, vty, argc, argv);
a98d33ab 3176}
718e3744 3177
874f579d
MS
3178DEFUN (vtysh_copy_to_running,
3179 vtysh_copy_to_running_cmd,
3180 "copy FILENAME running-config",
3181 "Apply a configuration file\n"
3182 "Configuration file to read\n"
3183 "Apply to current configuration\n")
3184{
3185 int ret;
3186 const char *fname = argv[1]->arg;
3187
3188 ret = vtysh_read_config(fname);
3189
3190 /* Return to enable mode - the 'read_config' api leaves us up a level */
3191 vtysh_execute_no_pager("enable");
3192
3193 return ret;
3194}
3195
76fd5262
DL
3196DEFUN (vtysh_terminal_paginate,
3197 vtysh_terminal_paginate_cmd,
3198 "[no] terminal paginate",
3199 NO_STR
3200 "Set terminal line parameters\n"
3201 "Use pager for output scrolling\n")
3202{
3203 free(vtysh_pager_name);
3204 vtysh_pager_name = NULL;
3205
3206 if (strcmp(argv[0]->text, "no"))
1569f224 3207 vtysh_pager_envdef(true);
76fd5262
DL
3208 return CMD_SUCCESS;
3209}
3210
34553cc3 3211DEFUN (vtysh_terminal_length,
3212 vtysh_terminal_length_cmd,
76fd5262
DL
3213 "[no] terminal length (0-4294967295)",
3214 NO_STR
34553cc3 3215 "Set terminal line parameters\n"
3216 "Set number of lines on a screen\n"
76fd5262 3217 "Number of lines on screen (0 for no pausing, nonzero to use pager)\n")
34553cc3 3218{
d62a17ae 3219 int idx_number = 2;
76fd5262 3220 unsigned long lines;
34553cc3 3221
76fd5262
DL
3222 free(vtysh_pager_name);
3223 vtysh_pager_name = NULL;
34553cc3 3224
76fd5262
DL
3225 if (!strcmp(argv[0]->text, "no") || !strcmp(argv[1]->text, "no")) {
3226 /* "terminal no length" = use VTYSH_PAGER */
1569f224 3227 vtysh_pager_envdef(true);
76fd5262 3228 return CMD_SUCCESS;
d62a17ae 3229 }
34553cc3 3230
76fd5262 3231 lines = strtoul(argv[idx_number]->arg, NULL, 10);
d62a17ae 3232 if (lines != 0) {
76fd5262
DL
3233 vty_out(vty,
3234 "%% The \"terminal length\" command is deprecated and its value is ignored.\n"
3235 "%% Please use \"terminal paginate\" instead with OS TTY length handling.\n");
1569f224 3236 vtysh_pager_envdef(true);
d62a17ae 3237 }
34553cc3 3238
d62a17ae 3239 return CMD_SUCCESS;
34553cc3 3240}
3241
76fd5262 3242ALIAS_DEPRECATED(vtysh_terminal_length,
34553cc3 3243 vtysh_terminal_no_length_cmd,
3244 "terminal no length",
3245 "Set terminal line parameters\n"
3246 NO_STR
3247 "Set number of lines on a screen\n")
34553cc3 3248
f2799e69 3249DEFUN (vtysh_show_daemons,
3250 vtysh_show_daemons_cmd,
3251 "show daemons",
e7168df4 3252 SHOW_STR
3253 "Show list of running daemons\n")
3254{
d7c0a89a 3255 unsigned int i;
b1aa147d 3256
d62a17ae 3257 for (i = 0; i < array_size(vtysh_client); i++)
3258 if (vtysh_client[i].fd >= 0)
2cddf2ff
QY
3259 vty_out(vty, " %s", vtysh_client[i].name);
3260 vty_out(vty, "\n");
e7168df4 3261
d62a17ae 3262 return CMD_SUCCESS;
e7168df4 3263}
3264
718e3744 3265/* Execute command in child process. */
996c9314
LB
3266static void execute_command(const char *command, int argc, const char *arg1,
3267 const char *arg2)
d62a17ae 3268{
3269 pid_t pid;
3270 int status;
3271
3272 /* Call fork(). */
3273 pid = fork();
3274
3275 if (pid < 0) {
3276 /* Failure of fork(). */
3277 fprintf(stderr, "Can't fork: %s\n", safe_strerror(errno));
3278 exit(1);
3279 } else if (pid == 0) {
3280 /* This is child process. */
3281 switch (argc) {
3282 case 0:
3283 execlp(command, command, (const char *)NULL);
3284 break;
3285 case 1:
3286 execlp(command, command, arg1, (const char *)NULL);
3287 break;
3288 case 2:
3289 execlp(command, command, arg1, arg2,
3290 (const char *)NULL);
3291 break;
3292 }
718e3744 3293
d62a17ae 3294 /* When execlp suceed, this part is not executed. */
3295 fprintf(stderr, "Can't execute %s: %s\n", command,
3296 safe_strerror(errno));
3297 exit(1);
3298 } else {
3299 /* This is parent. */
3300 execute_flag = 1;
3301 wait4(pid, &status, 0, NULL);
3302 execute_flag = 0;
3303 }
718e3744 3304}
3305
3306DEFUN (vtysh_ping,
3307 vtysh_ping_cmd,
3308 "ping WORD",
4eeccf18 3309 "Send echo messages\n"
718e3744 3310 "Ping destination address or hostname\n")
3311{
137a1684
DS
3312 int idx = 1;
3313
3314 argv_find(argv, argc, "WORD", &idx);
3315 execute_command("ping", 1, argv[idx]->arg, NULL);
d62a17ae 3316 return CMD_SUCCESS;
718e3744 3317}
3318
d62a17ae 3319ALIAS(vtysh_ping, vtysh_ping_ip_cmd, "ping ip WORD",
3320 "Send echo messages\n"
3321 "IP echo\n"
3322 "Ping destination address or hostname\n")
4eeccf18 3323
718e3744 3324DEFUN (vtysh_traceroute,
3325 vtysh_traceroute_cmd,
3326 "traceroute WORD",
3327 "Trace route to destination\n"
3328 "Trace route to destination address or hostname\n")
3329{
137a1684
DS
3330 int idx = 1;
3331
3332 argv_find(argv, argc, "WORD", &idx);
3333 execute_command("traceroute", 1, argv[idx]->arg, NULL);
d62a17ae 3334 return CMD_SUCCESS;
718e3744 3335}
3336
d62a17ae 3337ALIAS(vtysh_traceroute, vtysh_traceroute_ip_cmd, "traceroute ip WORD",
3338 "Trace route to destination\n"
3339 "IP trace\n"
3340 "Trace route to destination address or hostname\n")
4eeccf18 3341
4d9ad5dc
MS
3342DEFUN (vtysh_mtrace,
3343 vtysh_mtrace_cmd,
71e55fb2 3344 "mtrace WORD [WORD]",
4d9ad5dc 3345 "Multicast trace route to multicast source\n"
71e55fb2
MS
3346 "Multicast trace route to multicast source address\n"
3347 "Multicast trace route for multicast group address\n")
4d9ad5dc 3348{
71e55fb2
MS
3349 if (argc == 2)
3350 execute_command("mtracebis", 1, argv[1]->arg, NULL);
3351 else
3352 execute_command("mtracebis", 2, argv[1]->arg, argv[2]->arg);
4d9ad5dc
MS
3353 return CMD_SUCCESS;
3354}
3355
4eeccf18 3356DEFUN (vtysh_ping6,
3357 vtysh_ping6_cmd,
3358 "ping ipv6 WORD",
3359 "Send echo messages\n"
3360 "IPv6 echo\n"
3361 "Ping destination address or hostname\n")
3362{
137a1684 3363 execute_command("ping6", 1, argv[2]->arg, NULL);
d62a17ae 3364 return CMD_SUCCESS;
4eeccf18 3365}
3366
3367DEFUN (vtysh_traceroute6,
3368 vtysh_traceroute6_cmd,
3369 "traceroute ipv6 WORD",
3370 "Trace route to destination\n"
3371 "IPv6 trace\n"
3372 "Trace route to destination address or hostname\n")
3373{
137a1684 3374 execute_command("traceroute6", 1, argv[2]->arg, NULL);
d62a17ae 3375 return CMD_SUCCESS;
4eeccf18 3376}
4eeccf18 3377
576b6b5d 3378#if defined(HAVE_SHELL_ACCESS)
718e3744 3379DEFUN (vtysh_telnet,
3380 vtysh_telnet_cmd,
3381 "telnet WORD",
3382 "Open a telnet connection\n"
3383 "IP address or hostname of a remote system\n")
3384{
137a1684 3385 execute_command("telnet", 1, argv[1]->arg, NULL);
d62a17ae 3386 return CMD_SUCCESS;
718e3744 3387}
3388
3389DEFUN (vtysh_telnet_port,
3390 vtysh_telnet_port_cmd,
3391 "telnet WORD PORT",
3392 "Open a telnet connection\n"
3393 "IP address or hostname of a remote system\n"
3394 "TCP Port number\n")
3395{
137a1684 3396 execute_command("telnet", 2, argv[1]->arg, argv[2]->arg);
d62a17ae 3397 return CMD_SUCCESS;
718e3744 3398}
3399
5087df56 3400DEFUN (vtysh_ssh,
3401 vtysh_ssh_cmd,
3402 "ssh WORD",
3403 "Open an ssh connection\n"
3404 "[user@]host\n")
3405{
137a1684 3406 execute_command("ssh", 1, argv[1]->arg, NULL);
d62a17ae 3407 return CMD_SUCCESS;
5087df56 3408}
3409
718e3744 3410DEFUN (vtysh_start_shell,
3411 vtysh_start_shell_cmd,
3412 "start-shell",
3413 "Start UNIX shell\n")
3414{
d62a17ae 3415 execute_command("sh", 0, NULL, NULL);
3416 return CMD_SUCCESS;
718e3744 3417}
3418
3419DEFUN (vtysh_start_bash,
3420 vtysh_start_bash_cmd,
3421 "start-shell bash",
3422 "Start UNIX shell\n"
3423 "Start bash\n")
3424{
d62a17ae 3425 execute_command("bash", 0, NULL, NULL);
3426 return CMD_SUCCESS;
718e3744 3427}
3428
3429DEFUN (vtysh_start_zsh,
3430 vtysh_start_zsh_cmd,
3431 "start-shell zsh",
3432 "Start UNIX shell\n"
3433 "Start Z shell\n")
3434{
d62a17ae 3435 execute_command("zsh", 0, NULL, NULL);
3436 return CMD_SUCCESS;
718e3744 3437}
576b6b5d 3438#endif
b094d260 3439
0b84f294
DL
3440DEFUN (config_list,
3441 config_list_cmd,
3442 "list [permutations]",
3443 "Print command list\n"
3444 "Print all possible command permutations\n")
3445{
d62a17ae 3446 return cmd_list_cmds(vty, argc == 2);
0b84f294
DL
3447}
3448
193a5a95
QY
3449DEFUN (vtysh_output_file,
3450 vtysh_output_file_cmd,
3451 "output file FILE",
3452 "Direct vtysh output to file\n"
3453 "Direct vtysh output to file\n"
3454 "Path to dump output to\n")
3455{
3456 const char *path = argv[argc - 1]->arg;
2cddf2ff
QY
3457 vty->of = fopen(path, "a");
3458 if (!vty->of) {
3459 vty_out(vty, "Failed to open file '%s': %s\n", path,
193a5a95 3460 safe_strerror(errno));
2cddf2ff 3461 vty->of = stdout;
193a5a95
QY
3462 }
3463 return CMD_SUCCESS;
3464}
3465
3466DEFUN (no_vtysh_output_file,
3467 no_vtysh_output_file_cmd,
3468 "no output file [FILE]",
3469 NO_STR
3470 "Direct vtysh output to file\n"
3471 "Direct vtysh output to file\n"
3472 "Path to dump output to\n")
3473{
2cddf2ff
QY
3474 if (vty->of != stdout) {
3475 fclose(vty->of);
3476 vty->of = stdout;
193a5a95
QY
3477 }
3478 return CMD_SUCCESS;
3479}
3480
cf6c83e7
QY
3481DEFUN(find,
3482 find_cmd,
68912a20
QY
3483 "find REGEX",
3484 "Find CLI command matching a regular expression\n"
3485 "Search pattern (POSIX regex)\n")
cf6c83e7 3486{
68912a20 3487 char *pattern = argv[1]->arg;
cf6c83e7
QY
3488 const struct cmd_node *node;
3489 const struct cmd_element *cli;
3490 vector clis;
3491
68912a20
QY
3492 regex_t exp = {};
3493
3494 int cr = regcomp(&exp, pattern, REG_NOSUB | REG_EXTENDED);
3495
3496 if (cr != 0) {
3497 switch (cr) {
3498 case REG_BADBR:
3499 vty_out(vty, "%% Invalid \\{...\\} expression\n");
3500 break;
3501 case REG_BADRPT:
3502 vty_out(vty, "%% Bad repetition operator\n");
3503 break;
3504 case REG_BADPAT:
3505 vty_out(vty, "%% Regex syntax error\n");
3506 break;
3507 case REG_ECOLLATE:
3508 vty_out(vty, "%% Invalid collating element\n");
3509 break;
3510 case REG_ECTYPE:
3511 vty_out(vty, "%% Invalid character class name\n");
3512 break;
3513 case REG_EESCAPE:
3514 vty_out(vty,
3515 "%% Regex ended with escape character (\\)\n");
3516 break;
3517 case REG_ESUBREG:
3518 vty_out(vty,
3519 "%% Invalid number in \\digit construction\n");
3520 break;
3521 case REG_EBRACK:
3522 vty_out(vty, "%% Unbalanced square brackets\n");
3523 break;
3524 case REG_EPAREN:
3525 vty_out(vty, "%% Unbalanced parentheses\n");
3526 break;
3527 case REG_EBRACE:
3528 vty_out(vty, "%% Unbalanced braces\n");
3529 break;
3530 case REG_ERANGE:
3531 vty_out(vty,
3532 "%% Invalid endpoint in range expression\n");
3533 break;
3534 case REG_ESPACE:
3535 vty_out(vty, "%% Failed to compile (out of memory)\n");
3536 break;
3537 }
3538
3539 goto done;
3540 }
3541
3542
cf6c83e7
QY
3543 for (unsigned int i = 0; i < vector_active(cmdvec); i++) {
3544 node = vector_slot(cmdvec, i);
3545 if (!node)
3546 continue;
3547 clis = node->cmd_vector;
3548 for (unsigned int j = 0; j < vector_active(clis); j++) {
3549 cli = vector_slot(clis, j);
68912a20
QY
3550
3551 if (regexec(&exp, cli->string, 0, NULL, 0) == 0)
2cddf2ff 3552 vty_out(vty, " (%s) %s\n",
f4b8291f 3553 node->name, cli->string);
cf6c83e7
QY
3554 }
3555 }
3556
68912a20
QY
3557done:
3558 regfree(&exp);
cf6c83e7
QY
3559 return CMD_SUCCESS;
3560}
3561
26fbe472
QY
3562DEFUN_HIDDEN(show_cli_graph_vtysh,
3563 show_cli_graph_vtysh_cmd,
3564 "show cli graph",
3565 SHOW_STR
3566 "CLI reflection\n"
3567 "Dump current command space as DOT graph\n")
3568{
3569 struct cmd_node *cn = vector_slot(cmdvec, vty->node);
3570 char *dot = cmd_graph_dump_dot(cn->cmdgraph);
3571
3572 vty_out(vty, "%s\n", dot);
3573 XFREE(MTYPE_TMP, dot);
3574 return CMD_SUCCESS;
3575}
3576
d62a17ae 3577static void vtysh_install_default(enum node_type node)
718e3744 3578{
d62a17ae 3579 install_element(node, &config_list_cmd);
cf6c83e7 3580 install_element(node, &find_cmd);
26fbe472 3581 install_element(node, &show_cli_graph_vtysh_cmd);
193a5a95
QY
3582 install_element(node, &vtysh_output_file_cmd);
3583 install_element(node, &no_vtysh_output_file_cmd);
718e3744 3584}
3585
3586/* Making connection to protocol daemon. */
d62a17ae 3587static int vtysh_connect(struct vtysh_client *vclient)
3588{
3589 int ret;
3590 int sock, len;
3591 struct sockaddr_un addr;
3592 struct stat s_stat;
3593 const char *path;
3594
3595 if (!vclient->path[0])
3596 snprintf(vclient->path, sizeof(vclient->path), "%s/%s.vty",
9b8a8249 3597 vtydir, vclient->name);
d62a17ae 3598 path = vclient->path;
3599
3600 /* Stat socket to see if we have permission to access it. */
3601 ret = stat(path, &s_stat);
3602 if (ret < 0 && errno != ENOENT) {
3603 fprintf(stderr, "vtysh_connect(%s): stat = %s\n", path,
3604 safe_strerror(errno));
3605 exit(1);
3606 }
3607
3608 if (ret >= 0) {
3609 if (!S_ISSOCK(s_stat.st_mode)) {
3610 fprintf(stderr, "vtysh_connect(%s): Not a socket\n",
3611 path);
3612 exit(1);
3613 }
718e3744 3614 }
718e3744 3615
d62a17ae 3616 sock = socket(AF_UNIX, SOCK_STREAM, 0);
3617 if (sock < 0) {
718e3744 3618#ifdef DEBUG
d62a17ae 3619 fprintf(stderr, "vtysh_connect(%s): socket = %s\n", path,
3620 safe_strerror(errno));
718e3744 3621#endif /* DEBUG */
d62a17ae 3622 return -1;
3623 }
718e3744 3624
d62a17ae 3625 memset(&addr, 0, sizeof(struct sockaddr_un));
3626 addr.sun_family = AF_UNIX;
3627 strlcpy(addr.sun_path, path, sizeof(addr.sun_path));
6f0e3f6e 3628#ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
d62a17ae 3629 len = addr.sun_len = SUN_LEN(&addr);
718e3744 3630#else
d62a17ae 3631 len = sizeof(addr.sun_family) + strlen(addr.sun_path);
6f0e3f6e 3632#endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
718e3744 3633
d62a17ae 3634 ret = connect(sock, (struct sockaddr *)&addr, len);
3635 if (ret < 0) {
718e3744 3636#ifdef DEBUG
d62a17ae 3637 fprintf(stderr, "vtysh_connect(%s): connect = %s\n", path,
3638 safe_strerror(errno));
718e3744 3639#endif /* DEBUG */
d62a17ae 3640 close(sock);
3641 return -1;
3642 }
3643 vclient->fd = sock;
718e3744 3644
d62a17ae 3645 return 0;
718e3744 3646}
3647
67736451
MS
3648static int vtysh_reconnect(struct vtysh_client *vclient)
3649{
3650 int ret;
3651
3652 fprintf(stderr, "Warning: connecting to %s...", vclient->name);
3653 ret = vtysh_connect(vclient);
3654 if (ret < 0) {
3655 fprintf(stderr, "failed!\n");
3656 return ret;
3657 }
3658 fprintf(stderr, "success!\n");
2cddf2ff 3659 if (vtysh_client_execute(vclient, "enable") < 0)
67736451
MS
3660 return -1;
3661 return vtysh_execute_no_pager("end");
3662}
3663
7c8ff89e 3664/* Return true if str ends with suffix, else return false */
d62a17ae 3665static int ends_with(const char *str, const char *suffix)
7c8ff89e 3666{
d62a17ae 3667 if (!str || !suffix)
3668 return 0;
3669 size_t lenstr = strlen(str);
3670 size_t lensuffix = strlen(suffix);
3671 if (lensuffix > lenstr)
3672 return 0;
3673 return strncmp(str + lenstr - lensuffix, suffix, lensuffix) == 0;
7c8ff89e
DS
3674}
3675
d62a17ae 3676static void vtysh_client_sorted_insert(struct vtysh_client *head_client,
3677 struct vtysh_client *client)
7c8ff89e 3678{
d62a17ae 3679 struct vtysh_client *prev_node, *current_node;
7c8ff89e 3680
d62a17ae 3681 prev_node = head_client;
3682 current_node = head_client->next;
3683 while (current_node) {
3684 if (strcmp(current_node->path, client->path) > 0)
3685 break;
7c8ff89e 3686
d62a17ae 3687 prev_node = current_node;
3688 current_node = current_node->next;
3689 }
3690 client->next = current_node;
3691 prev_node->next = client;
7c8ff89e
DS
3692}
3693
3694#define MAXIMUM_INSTANCES 10
3695
462ea14a 3696static void vtysh_update_all_instances(struct vtysh_client *head_client)
d62a17ae 3697{
3698 struct vtysh_client *client;
3699 DIR *dir;
3700 struct dirent *file;
3701 int n = 0;
3702
3703 if (head_client->flag != VTYSH_OSPFD)
3704 return;
3705
3706 /* ls vty_sock_dir and look for all files ending in .vty */
9b8a8249 3707 dir = opendir(vtydir);
d62a17ae 3708 if (dir) {
3709 while ((file = readdir(dir)) != NULL) {
90cf59ec 3710 if (frrstr_startswith(file->d_name, "ospfd-")
d62a17ae 3711 && ends_with(file->d_name, ".vty")) {
3712 if (n == MAXIMUM_INSTANCES) {
3713 fprintf(stderr,
3714 "Parsing %s, client limit(%d) reached!\n",
9b8a8249 3715 vtydir, n);
d62a17ae 3716 break;
3717 }
3718 client = (struct vtysh_client *)malloc(
3719 sizeof(struct vtysh_client));
3720 client->fd = -1;
3721 client->name = "ospfd";
3722 client->flag = VTYSH_OSPFD;
3723 snprintf(client->path, sizeof(client->path),
9b8a8249 3724 "%s/%s", vtydir, file->d_name);
d62a17ae 3725 client->next = NULL;
3726 vtysh_client_sorted_insert(head_client, client);
3727 n++;
3728 }
3729 }
3730 closedir(dir);
3731 }
3732}
3733
3734static int vtysh_connect_all_instances(struct vtysh_client *head_client)
3735{
3736 struct vtysh_client *client;
3737 int rc = 0;
3738
462ea14a 3739 vtysh_update_all_instances(head_client);
d62a17ae 3740
3741 client = head_client->next;
3742 while (client) {
3743 if (vtysh_connect(client) == 0)
3744 rc++;
3745 client = client->next;
3746 }
3747
3748 return rc;
3749}
3750
3751int vtysh_connect_all(const char *daemon_name)
3752{
d7c0a89a 3753 unsigned int i;
d62a17ae 3754 int rc = 0;
3755 int matches = 0;
3756
3757 for (i = 0; i < array_size(vtysh_client); i++) {
3758 if (!daemon_name
3759 || !strcmp(daemon_name, vtysh_client[i].name)) {
3760 matches++;
3761 if (vtysh_connect(&vtysh_client[i]) == 0)
3762 rc++;
3763
3764 rc += vtysh_connect_all_instances(&vtysh_client[i]);
3765 }
3766 }
3767 if (!matches)
3768 fprintf(stderr, "Error: no daemons match name %s!\n",
3769 daemon_name);
3770 return rc;
718e3744 3771}
3772
95e735b5 3773/* To disable readline's filename completion. */
d62a17ae 3774static char *vtysh_completion_entry_function(const char *ignore,
3775 int invoking_key)
718e3744 3776{
d62a17ae 3777 return NULL;
718e3744 3778}
3779
d62a17ae 3780void vtysh_readline_init(void)
718e3744 3781{
d62a17ae 3782 /* readline related settings. */
3783 rl_initialize();
3784 rl_bind_key('?', (rl_command_func_t *)vtysh_rl_describe);
3785 rl_completion_entry_function = vtysh_completion_entry_function;
7c70dc57 3786 rl_attempted_completion_function = new_completion;
718e3744 3787}
3788
d62a17ae 3789char *vtysh_prompt(void)
718e3744 3790{
63e653a2 3791 static char buf[512];
718e3744 3792
0d6f7fd6 3793 snprintf(buf, sizeof(buf), cmd_prompt(vty->node), cmd_hostname_get());
d62a17ae 3794 return buf;
718e3744 3795}
3796
7f059ea6
DL
3797static void vtysh_ac_line(void *arg, const char *line)
3798{
d62a17ae 3799 vector comps = arg;
3800 size_t i;
3801 for (i = 0; i < vector_active(comps); i++)
3802 if (!strcmp(line, (char *)vector_slot(comps, i)))
3803 return;
3804 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, line));
7f059ea6
DL
3805}
3806
3807static void vtysh_autocomplete(vector comps, struct cmd_token *token)
3808{
d62a17ae 3809 char accmd[256];
3810 size_t i;
7f059ea6 3811
d62a17ae 3812 snprintf(accmd, sizeof(accmd), "autocomplete %d %s %s", token->type,
3813 token->text, token->varname ? token->varname : "-");
7f059ea6 3814
8d70e7fe
QY
3815 vty->of_saved = vty->of;
3816 vty->of = NULL;
d62a17ae 3817 for (i = 0; i < array_size(vtysh_client); i++)
2cddf2ff
QY
3818 vtysh_client_run_all(&vtysh_client[i], accmd, 1, vtysh_ac_line,
3819 comps);
8d70e7fe 3820 vty->of = vty->of_saved;
7f059ea6
DL
3821}
3822
1d6664e0 3823static const struct cmd_variable_handler vtysh_var_handler[] = {
d62a17ae 3824 {/* match all */
3825 .tokenname = NULL,
3826 .varname = NULL,
3827 .completions = vtysh_autocomplete},
3828 {.completions = NULL}};
3829
4d762f26 3830void vtysh_uninit(void)
193a5a95 3831{
2cddf2ff
QY
3832 if (vty->of != stdout)
3833 fclose(vty->of);
193a5a95
QY
3834}
3835
d62a17ae 3836void vtysh_init_vty(void)
3837{
3838 /* Make vty structure. */
3839 vty = vty_new();
3840 vty->type = VTY_SHELL;
3841 vty->node = VIEW_NODE;
3842
193a5a95 3843 /* set default output */
2cddf2ff 3844 vty->of = stdout;
1569f224 3845 vtysh_pager_envdef(false);
193a5a95 3846
d62a17ae 3847 /* Initialize commands. */
3848 cmd_init(0);
3849 cmd_variable_handler_register(vtysh_var_handler);
3850
5d574646 3851 /* bgpd */
0eb5751d 3852#ifdef HAVE_BGPD
612c2c15 3853 install_node(&bgp_node);
5d574646
IR
3854 install_element(CONFIG_NODE, &router_bgp_cmd);
3855 install_element(BGP_NODE, &vtysh_exit_bgpd_cmd);
3856 install_element(BGP_NODE, &vtysh_quit_bgpd_cmd);
3857 install_element(BGP_NODE, &vtysh_end_all_cmd);
3858
612c2c15 3859 install_node(&bgp_vpnv4_node);
5d574646
IR
3860 install_element(BGP_NODE, &address_family_ipv4_vpn_cmd);
3861#ifdef KEEP_OLD_VPN_COMMANDS
3862 install_element(BGP_NODE, &address_family_vpnv4_cmd);
3863#endif /* KEEP_OLD_VPN_COMMANDS */
3864 install_element(BGP_VPNV4_NODE, &vtysh_exit_bgpd_cmd);
3865 install_element(BGP_VPNV4_NODE, &vtysh_quit_bgpd_cmd);
3866 install_element(BGP_VPNV4_NODE, &vtysh_end_all_cmd);
3867 install_element(BGP_VPNV4_NODE, &exit_address_family_cmd);
3868
612c2c15 3869 install_node(&bgp_vpnv6_node);
5d574646
IR
3870 install_element(BGP_NODE, &address_family_ipv6_vpn_cmd);
3871#ifdef KEEP_OLD_VPN_COMMANDS
3872 install_element(BGP_NODE, &address_family_vpnv6_cmd);
3873#endif /* KEEP_OLD_VPN_COMMANDS */
3874 install_element(BGP_VPNV6_NODE, &vtysh_exit_bgpd_cmd);
3875 install_element(BGP_VPNV6_NODE, &vtysh_quit_bgpd_cmd);
3876 install_element(BGP_VPNV6_NODE, &vtysh_end_all_cmd);
3877 install_element(BGP_VPNV6_NODE, &exit_address_family_cmd);
3878
612c2c15 3879 install_node(&bgp_flowspecv4_node);
5d574646
IR
3880 install_element(BGP_NODE, &address_family_flowspecv4_cmd);
3881 install_element(BGP_FLOWSPECV4_NODE, &vtysh_exit_bgpd_cmd);
3882 install_element(BGP_FLOWSPECV4_NODE, &vtysh_quit_bgpd_cmd);
3883 install_element(BGP_FLOWSPECV4_NODE, &vtysh_end_all_cmd);
3884 install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd);
3885
612c2c15 3886 install_node(&bgp_flowspecv6_node);
5d574646
IR
3887 install_element(BGP_NODE, &address_family_flowspecv6_cmd);
3888 install_element(BGP_FLOWSPECV6_NODE, &vtysh_exit_bgpd_cmd);
3889 install_element(BGP_FLOWSPECV6_NODE, &vtysh_quit_bgpd_cmd);
3890 install_element(BGP_FLOWSPECV6_NODE, &vtysh_end_all_cmd);
3891 install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd);
3892
612c2c15 3893 install_node(&bgp_ipv4_node);
5d574646
IR
3894 install_element(BGP_NODE, &address_family_ipv4_cmd);
3895 install_element(BGP_IPV4_NODE, &vtysh_exit_bgpd_cmd);
3896 install_element(BGP_IPV4_NODE, &vtysh_quit_bgpd_cmd);
3897 install_element(BGP_IPV4_NODE, &vtysh_end_all_cmd);
3898 install_element(BGP_IPV4_NODE, &exit_address_family_cmd);
3899
612c2c15 3900 install_node(&bgp_ipv4m_node);
5d574646
IR
3901 install_element(BGP_NODE, &address_family_ipv4_multicast_cmd);
3902 install_element(BGP_IPV4M_NODE, &vtysh_exit_bgpd_cmd);
3903 install_element(BGP_IPV4M_NODE, &vtysh_quit_bgpd_cmd);
3904 install_element(BGP_IPV4M_NODE, &vtysh_end_all_cmd);
3905 install_element(BGP_IPV4M_NODE, &exit_address_family_cmd);
3906
612c2c15 3907 install_node(&bgp_ipv4l_node);
5d574646
IR
3908 install_element(BGP_NODE, &address_family_ipv4_labeled_unicast_cmd);
3909 install_element(BGP_IPV4L_NODE, &vtysh_exit_bgpd_cmd);
3910 install_element(BGP_IPV4L_NODE, &vtysh_quit_bgpd_cmd);
3911 install_element(BGP_IPV4L_NODE, &vtysh_end_all_cmd);
3912 install_element(BGP_IPV4L_NODE, &exit_address_family_cmd);
3913
612c2c15 3914 install_node(&bgp_ipv6_node);
5d574646
IR
3915 install_element(BGP_NODE, &address_family_ipv6_cmd);
3916 install_element(BGP_IPV6_NODE, &vtysh_exit_bgpd_cmd);
3917 install_element(BGP_IPV6_NODE, &vtysh_quit_bgpd_cmd);
3918 install_element(BGP_IPV6_NODE, &vtysh_end_all_cmd);
3919 install_element(BGP_IPV6_NODE, &exit_address_family_cmd);
3920
612c2c15 3921 install_node(&bgp_ipv6m_node);
5d574646
IR
3922 install_element(BGP_NODE, &address_family_ipv6_multicast_cmd);
3923 install_element(BGP_IPV6M_NODE, &vtysh_exit_bgpd_cmd);
3924 install_element(BGP_IPV6M_NODE, &vtysh_quit_bgpd_cmd);
3925 install_element(BGP_IPV6M_NODE, &vtysh_end_all_cmd);
3926 install_element(BGP_IPV6M_NODE, &exit_address_family_cmd);
3927
612c2c15 3928 install_node(&bgp_ipv6l_node);
5d574646
IR
3929 install_element(BGP_NODE, &address_family_ipv6_labeled_unicast_cmd);
3930 install_element(BGP_IPV6L_NODE, &vtysh_exit_bgpd_cmd);
3931 install_element(BGP_IPV6L_NODE, &vtysh_quit_bgpd_cmd);
3932 install_element(BGP_IPV6L_NODE, &vtysh_end_all_cmd);
3933 install_element(BGP_IPV6L_NODE, &exit_address_family_cmd);
3934
3935#if defined(ENABLE_BGP_VNC)
612c2c15 3936 install_node(&bgp_vrf_policy_node);
5d574646
IR
3937 install_element(BGP_NODE, &vnc_vrf_policy_cmd);
3938 install_element(BGP_VRF_POLICY_NODE, &vtysh_exit_bgpd_cmd);
3939 install_element(BGP_VRF_POLICY_NODE, &vtysh_quit_bgpd_cmd);
3940 install_element(BGP_VRF_POLICY_NODE, &vtysh_end_all_cmd);
3941 install_element(BGP_VRF_POLICY_NODE, &exit_vrf_policy_cmd);
3942
612c2c15 3943 install_node(&bgp_vnc_defaults_node);
5d574646
IR
3944 install_element(BGP_NODE, &vnc_defaults_cmd);
3945 install_element(BGP_VNC_DEFAULTS_NODE, &vtysh_exit_bgpd_cmd);
3946 install_element(BGP_VNC_DEFAULTS_NODE, &vtysh_quit_bgpd_cmd);
3947 install_element(BGP_VNC_DEFAULTS_NODE, &vtysh_end_all_cmd);
3948 install_element(BGP_VNC_DEFAULTS_NODE, &exit_vnc_config_cmd);
3949
612c2c15 3950 install_node(&bgp_vnc_nve_group_node);
5d574646
IR
3951 install_element(BGP_NODE, &vnc_nve_group_cmd);
3952 install_element(BGP_VNC_NVE_GROUP_NODE, &vtysh_exit_bgpd_cmd);
3953 install_element(BGP_VNC_NVE_GROUP_NODE, &vtysh_quit_bgpd_cmd);
3954 install_element(BGP_VNC_NVE_GROUP_NODE, &vtysh_end_all_cmd);
3955 install_element(BGP_VNC_NVE_GROUP_NODE, &exit_vnc_config_cmd);
3956
612c2c15 3957 install_node(&bgp_vnc_l2_group_node);
5d574646
IR
3958 install_element(BGP_NODE, &vnc_l2_group_cmd);
3959 install_element(BGP_VNC_L2_GROUP_NODE, &vtysh_exit_bgpd_cmd);
3960 install_element(BGP_VNC_L2_GROUP_NODE, &vtysh_quit_bgpd_cmd);
3961 install_element(BGP_VNC_L2_GROUP_NODE, &vtysh_end_all_cmd);
3962 install_element(BGP_VNC_L2_GROUP_NODE, &exit_vnc_config_cmd);
3963#endif
d62a17ae 3964
5d574646
IR
3965 install_node(&bgp_evpn_node);
3966 install_element(BGP_NODE, &address_family_evpn_cmd);
3967#if defined(HAVE_CUMULUS)
3968 install_element(BGP_NODE, &address_family_evpn2_cmd);
3969#endif
3970 install_element(BGP_EVPN_NODE, &vtysh_quit_bgpd_cmd);
3971 install_element(BGP_EVPN_NODE, &vtysh_exit_bgpd_cmd);
3972 install_element(BGP_EVPN_NODE, &vtysh_end_all_cmd);
3973 install_element(BGP_EVPN_NODE, &exit_address_family_cmd);
d62a17ae 3974
5d574646
IR
3975 install_node(&bgp_evpn_vni_node);
3976 install_element(BGP_EVPN_NODE, &bgp_evpn_vni_cmd);
3977 install_element(BGP_EVPN_VNI_NODE, &vtysh_exit_bgpd_cmd);
3978 install_element(BGP_EVPN_VNI_NODE, &vtysh_quit_bgpd_cmd);
3979 install_element(BGP_EVPN_VNI_NODE, &vtysh_end_all_cmd);
3980 install_element(BGP_EVPN_VNI_NODE, &exit_vni_cmd);
d62a17ae 3981
5d574646
IR
3982 install_node(&rpki_node);
3983 install_element(CONFIG_NODE, &rpki_cmd);
3984 install_element(RPKI_NODE, &rpki_exit_cmd);
3985 install_element(RPKI_NODE, &rpki_quit_cmd);
3986 install_element(RPKI_NODE, &vtysh_end_all_cmd);
3987
3988 install_node(&bmp_node);
3989 install_element(BGP_NODE, &bmp_targets_cmd);
3990 install_element(BMP_NODE, &bmp_exit_cmd);
3991 install_element(BMP_NODE, &bmp_quit_cmd);
3992 install_element(BMP_NODE, &vtysh_end_all_cmd);
0eb5751d 3993#endif /* HAVE_BGPD */
5d574646
IR
3994
3995 /* ripd */
3996 install_node(&rip_node);
0eb5751d 3997#ifdef HAVE_RIPD
5d574646 3998 install_element(CONFIG_NODE, &router_rip_cmd);
d62a17ae 3999 install_element(RIP_NODE, &vtysh_exit_ripd_cmd);
4000 install_element(RIP_NODE, &vtysh_quit_ripd_cmd);
5d574646 4001 install_element(RIP_NODE, &vtysh_end_all_cmd);
0eb5751d 4002#endif /* HAVE_RIPD */
5d574646
IR
4003
4004 /* ripngd */
4005 install_node(&ripng_node);
0eb5751d 4006#ifdef HAVE_RIPNGD
5d574646 4007 install_element(CONFIG_NODE, &router_ripng_cmd);
d62a17ae 4008 install_element(RIPNG_NODE, &vtysh_exit_ripngd_cmd);
4009 install_element(RIPNG_NODE, &vtysh_quit_ripngd_cmd);
5d574646 4010 install_element(RIPNG_NODE, &vtysh_end_all_cmd);
0eb5751d 4011#endif /* HAVE_RIPNGD */
5d574646
IR
4012
4013 /* ospfd */
0eb5751d 4014#ifdef HAVE_OSPFD
5d574646
IR
4015 install_node(&ospf_node);
4016 install_element(CONFIG_NODE, &router_ospf_cmd);
d62a17ae 4017 install_element(OSPF_NODE, &vtysh_exit_ospfd_cmd);
4018 install_element(OSPF_NODE, &vtysh_quit_ospfd_cmd);
5d574646 4019 install_element(OSPF_NODE, &vtysh_end_all_cmd);
0eb5751d 4020#endif /* HAVE_OSPFD */
5d574646
IR
4021
4022 /* ospf6d */
0eb5751d 4023#ifdef HAVE_OSPF6D
5d574646
IR
4024 install_node(&ospf6_node);
4025 install_element(CONFIG_NODE, &router_ospf6_cmd);
d62a17ae 4026 install_element(OSPF6_NODE, &vtysh_exit_ospf6d_cmd);
4027 install_element(OSPF6_NODE, &vtysh_quit_ospf6d_cmd);
5d574646 4028 install_element(OSPF6_NODE, &vtysh_end_all_cmd);
0eb5751d 4029#endif /* HAVE_OSPF6D */
5d574646
IR
4030
4031 /* ldpd */
d62a17ae 4032#if defined(HAVE_LDPD)
5d574646
IR
4033 install_node(&ldp_node);
4034 install_element(CONFIG_NODE, &ldp_mpls_ldp_cmd);
d62a17ae 4035 install_element(LDP_NODE, &vtysh_exit_ldpd_cmd);
4036 install_element(LDP_NODE, &vtysh_quit_ldpd_cmd);
5d574646
IR
4037 install_element(LDP_NODE, &vtysh_end_all_cmd);
4038
4039 install_node(&ldp_ipv4_node);
4040 install_element(LDP_NODE, &ldp_address_family_ipv4_cmd);
d62a17ae 4041 install_element(LDP_IPV4_NODE, &vtysh_exit_ldpd_cmd);
4042 install_element(LDP_IPV4_NODE, &vtysh_quit_ldpd_cmd);
983bd6f7 4043 install_element(LDP_IPV4_NODE, &ldp_exit_address_family_cmd);
5d574646
IR
4044 install_element(LDP_IPV4_NODE, &vtysh_end_all_cmd);
4045
4046 install_node(&ldp_ipv6_node);
4047 install_element(LDP_NODE, &ldp_address_family_ipv6_cmd);
d62a17ae 4048 install_element(LDP_IPV6_NODE, &vtysh_exit_ldpd_cmd);
4049 install_element(LDP_IPV6_NODE, &vtysh_quit_ldpd_cmd);
983bd6f7 4050 install_element(LDP_IPV6_NODE, &ldp_exit_address_family_cmd);
5d574646
IR
4051 install_element(LDP_IPV6_NODE, &vtysh_end_all_cmd);
4052
4053 install_node(&ldp_ipv4_iface_node);
4054 install_element(LDP_IPV4_NODE, &ldp_interface_ifname_cmd);
d62a17ae 4055 install_element(LDP_IPV4_IFACE_NODE, &vtysh_exit_ldpd_cmd);
4056 install_element(LDP_IPV4_IFACE_NODE, &vtysh_quit_ldpd_cmd);
5d574646
IR
4057 install_element(LDP_IPV4_IFACE_NODE, &vtysh_end_all_cmd);
4058
4059 install_node(&ldp_ipv6_iface_node);
4060 install_element(LDP_IPV6_NODE, &ldp_interface_ifname_cmd);
d62a17ae 4061 install_element(LDP_IPV6_IFACE_NODE, &vtysh_exit_ldpd_cmd);
4062 install_element(LDP_IPV6_IFACE_NODE, &vtysh_quit_ldpd_cmd);
5d574646
IR
4063 install_element(LDP_IPV6_IFACE_NODE, &vtysh_end_all_cmd);
4064
4065 install_node(&ldp_l2vpn_node);
4066 install_element(CONFIG_NODE, &ldp_l2vpn_word_type_vpls_cmd);
d62a17ae 4067 install_element(LDP_L2VPN_NODE, &vtysh_exit_ldpd_cmd);
4068 install_element(LDP_L2VPN_NODE, &vtysh_quit_ldpd_cmd);
5d574646
IR
4069 install_element(LDP_L2VPN_NODE, &vtysh_end_all_cmd);
4070
4071 install_node(&ldp_pseudowire_node);
4072 install_element(LDP_L2VPN_NODE, &ldp_member_pseudowire_ifname_cmd);
d62a17ae 4073 install_element(LDP_PSEUDOWIRE_NODE, &vtysh_exit_ldpd_cmd);
4074 install_element(LDP_PSEUDOWIRE_NODE, &vtysh_quit_ldpd_cmd);
5d574646 4075 install_element(LDP_PSEUDOWIRE_NODE, &vtysh_end_all_cmd);
87ab4aec 4076#endif
5d574646
IR
4077
4078 /* eigrpd */
0eb5751d 4079#ifdef HAVE_EIGRPD
5d574646
IR
4080 install_node(&eigrp_node);
4081 install_element(CONFIG_NODE, &router_eigrp_cmd);
4082 install_element(EIGRP_NODE, &vtysh_exit_eigrpd_cmd);
4083 install_element(EIGRP_NODE, &vtysh_quit_eigrpd_cmd);
4084 install_element(EIGRP_NODE, &vtysh_end_all_cmd);
0eb5751d 4085#endif /* HAVE_EIGRPD */
5d574646
IR
4086
4087 /* babeld */
0eb5751d 4088#ifdef HAVE_BABELD
5d574646
IR
4089 install_node(&babel_node);
4090 install_element(CONFIG_NODE, &router_babel_cmd);
4091 install_element(BABEL_NODE, &vtysh_exit_babeld_cmd);
4092 install_element(BABEL_NODE, &vtysh_quit_babeld_cmd);
4093 install_element(BABEL_NODE, &vtysh_end_all_cmd);
0eb5751d 4094#endif /* HAVE_BABELD */
5d574646
IR
4095
4096 /* isisd */
0eb5751d 4097#ifdef HAVE_ISISD
5d574646
IR
4098 install_node(&isis_node);
4099 install_element(CONFIG_NODE, &router_isis_cmd);
d62a17ae 4100 install_element(ISIS_NODE, &vtysh_exit_isisd_cmd);
4101 install_element(ISIS_NODE, &vtysh_quit_isisd_cmd);
5d574646 4102 install_element(ISIS_NODE, &vtysh_end_all_cmd);
0eb5751d 4103#endif /* HAVE_ISISD */
5d574646
IR
4104
4105 /* fabricd */
0eb5751d 4106#ifdef HAVE_FABRICD
5d574646
IR
4107 install_node(&openfabric_node);
4108 install_element(CONFIG_NODE, &router_openfabric_cmd);
770ccdf8
CF
4109 install_element(OPENFABRIC_NODE, &vtysh_exit_fabricd_cmd);
4110 install_element(OPENFABRIC_NODE, &vtysh_quit_fabricd_cmd);
5d574646 4111 install_element(OPENFABRIC_NODE, &vtysh_end_all_cmd);
0eb5751d 4112#endif /* HAVE_FABRICD */
5d574646
IR
4113
4114 /* pbrd */
0eb5751d 4115#ifdef HAVE_PBRD
5d574646
IR
4116 install_node(&pbr_map_node);
4117 install_element(CONFIG_NODE, &vtysh_pbr_map_cmd);
4118 install_element(CONFIG_NODE, &vtysh_no_pbr_map_cmd);
e5c83d9b
DS
4119 install_element(PBRMAP_NODE, &vtysh_exit_pbr_map_cmd);
4120 install_element(PBRMAP_NODE, &vtysh_quit_pbr_map_cmd);
5d574646 4121 install_element(PBRMAP_NODE, &vtysh_end_all_cmd);
0eb5751d 4122#endif /* HAVE_PBRD */
5d574646
IR
4123
4124 /* bfdd */
c2f29cf3 4125#if HAVE_BFDD > 0
5d574646 4126 install_node(&bfd_node);
c2f29cf3 4127 install_element(CONFIG_NODE, &bfd_enter_cmd);
c2f29cf3
RZ
4128 install_element(BFD_NODE, &vtysh_exit_bfdd_cmd);
4129 install_element(BFD_NODE, &vtysh_quit_bfdd_cmd);
5d574646
IR
4130 install_element(BFD_NODE, &vtysh_end_all_cmd);
4131
4132 install_node(&bfd_peer_node);
4133 install_element(BFD_NODE, &bfd_peer_enter_cmd);
c2f29cf3
RZ
4134 install_element(BFD_PEER_NODE, &vtysh_exit_bfdd_cmd);
4135 install_element(BFD_PEER_NODE, &vtysh_quit_bfdd_cmd);
5d574646
IR
4136 install_element(BFD_PEER_NODE, &vtysh_end_all_cmd);
4137
4138 install_node(&bfd_profile_node);
4139 install_element(BFD_NODE, &bfd_profile_enter_cmd);
d40d6c22
RZ
4140 install_element(BFD_PROFILE_NODE, &vtysh_exit_bfdd_cmd);
4141 install_element(BFD_PROFILE_NODE, &vtysh_quit_bfdd_cmd);
d40d6c22 4142 install_element(BFD_PROFILE_NODE, &vtysh_end_all_cmd);
c2f29cf3 4143#endif /* HAVE_BFDD */
d62a17ae 4144
5d574646
IR
4145 /* keychain */
4146 install_node(&keychain_node);
4147 install_element(CONFIG_NODE, &key_chain_cmd);
4148 install_element(KEYCHAIN_NODE, &key_chain_cmd);
4149 install_element(KEYCHAIN_NODE, &vtysh_exit_keys_cmd);
4150 install_element(KEYCHAIN_NODE, &vtysh_quit_keys_cmd);
d62a17ae 4151 install_element(KEYCHAIN_NODE, &vtysh_end_all_cmd);
5d574646
IR
4152
4153 install_node(&keychain_key_node);
4154 install_element(KEYCHAIN_NODE, &key_cmd);
4155 install_element(KEYCHAIN_KEY_NODE, &key_chain_cmd);
4156 install_element(KEYCHAIN_KEY_NODE, &vtysh_exit_keys_cmd);
4157 install_element(KEYCHAIN_KEY_NODE, &vtysh_quit_keys_cmd);
d62a17ae 4158 install_element(KEYCHAIN_KEY_NODE, &vtysh_end_all_cmd);
d62a17ae 4159
5d574646
IR
4160 /* nexthop-group */
4161 install_node(&nh_group_node);
4162 install_element(CONFIG_NODE, &vtysh_nexthop_group_cmd);
4163 install_element(CONFIG_NODE, &vtysh_no_nexthop_group_cmd);
4164 install_element(NH_GROUP_NODE, &vtysh_end_all_cmd);
4165 install_element(NH_GROUP_NODE, &vtysh_exit_nexthop_group_cmd);
4166 install_element(NH_GROUP_NODE, &vtysh_quit_nexthop_group_cmd);
4167
4168 /* zebra and all */
4169 install_node(&zebra_node);
4170
4171 install_node(&interface_node);
4172 install_element(CONFIG_NODE, &vtysh_interface_cmd);
d62a17ae 4173 install_element(INTERFACE_NODE, &vtysh_end_all_cmd);
4174 install_element(INTERFACE_NODE, &vtysh_exit_interface_cmd);
5d574646
IR
4175 install_element(INTERFACE_NODE, &vtysh_quit_interface_cmd);
4176
4177 install_node(&link_params_node);
4178 install_element(INTERFACE_NODE, &vtysh_link_params_cmd);
d62a17ae 4179 install_element(LINK_PARAMS_NODE, &exit_link_params_cmd);
4180 install_element(LINK_PARAMS_NODE, &vtysh_end_all_cmd);
4181 install_element(LINK_PARAMS_NODE, &vtysh_exit_interface_cmd);
d62a17ae 4182
5d574646
IR
4183 install_node(&pw_node);
4184 install_element(CONFIG_NODE, &vtysh_pseudowire_cmd);
2dd0d726
RW
4185 install_element(PW_NODE, &vtysh_end_all_cmd);
4186 install_element(PW_NODE, &vtysh_exit_interface_cmd);
4187 install_element(PW_NODE, &vtysh_quit_interface_cmd);
4188
5d574646
IR
4189 install_node(&vrf_node);
4190 install_element(CONFIG_NODE, &vtysh_vrf_cmd);
4191 install_element(VRF_NODE, &vtysh_vrf_netns_cmd);
4192 install_element(VRF_NODE, &vtysh_no_vrf_netns_cmd);
4193 install_element(VRF_NODE, &exit_vrf_config_cmd);
d62a17ae 4194 install_element(VRF_NODE, &vtysh_end_all_cmd);
4195 install_element(VRF_NODE, &vtysh_exit_vrf_cmd);
4196 install_element(VRF_NODE, &vtysh_quit_vrf_cmd);
5d574646
IR
4197
4198 install_node(&rmap_node);
4199 install_element(CONFIG_NODE, &vtysh_route_map_cmd);
4200 install_element(RMAP_NODE, &vtysh_exit_rmap_cmd);
4201 install_element(RMAP_NODE, &vtysh_quit_rmap_cmd);
4202 install_element(RMAP_NODE, &vtysh_end_all_cmd);
d62a17ae 4203
5d574646
IR
4204 install_node(&vty_node);
4205 install_element(CONFIG_NODE, &vtysh_line_vty_cmd);
4206 install_element(VTY_NODE, &vtysh_exit_line_vty_cmd);
4207 install_element(VTY_NODE, &vtysh_quit_line_vty_cmd);
4208 install_element(VTY_NODE, &vtysh_end_all_cmd);
d62a17ae 4209
ed18356f 4210
5d574646
IR
4211 struct cmd_node *node;
4212 for (unsigned int i = 0; i < vector_active(cmdvec); i++) {
4213 node = vector_slot(cmdvec, i);
4214 if (!node || node->node == VIEW_NODE)
4215 continue;
4216 vtysh_install_default(node->node);
4217 }
dabecd7c 4218
5d574646 4219 /* vtysh */
d62a17ae 4220
5d574646
IR
4221 install_element(VIEW_NODE, &vtysh_enable_cmd);
4222 install_element(ENABLE_NODE, &vtysh_config_terminal_cmd);
4223 install_element(ENABLE_NODE, &vtysh_disable_cmd);
4224
4225 /* "exit" command. */
4226 install_element(VIEW_NODE, &vtysh_exit_all_cmd);
4227 install_element(CONFIG_NODE, &vtysh_exit_all_cmd);
4228 install_element(VIEW_NODE, &vtysh_quit_all_cmd);
4229 install_element(CONFIG_NODE, &vtysh_quit_all_cmd);
4230
4231 /* "end" command. */
4232 install_element(CONFIG_NODE, &vtysh_end_all_cmd);
4233 install_element(ENABLE_NODE, &vtysh_end_all_cmd);
d62a17ae 4234
d62a17ae 4235 install_element(ENABLE_NODE, &vtysh_show_running_config_cmd);
4236 install_element(ENABLE_NODE, &vtysh_copy_running_config_cmd);
874f579d 4237 install_element(ENABLE_NODE, &vtysh_copy_to_running_cmd);
d62a17ae 4238
d62a17ae 4239 /* "write terminal" command. */
4240 install_element(ENABLE_NODE, &vtysh_write_terminal_cmd);
4241
4242 install_element(CONFIG_NODE, &vtysh_integrated_config_cmd);
4243 install_element(CONFIG_NODE, &no_vtysh_integrated_config_cmd);
4244
4245 /* "write memory" command. */
4246 install_element(ENABLE_NODE, &vtysh_write_memory_cmd);
4247
1569f224 4248 install_element(CONFIG_NODE, &vtysh_terminal_paginate_cmd);
76fd5262 4249 install_element(VIEW_NODE, &vtysh_terminal_paginate_cmd);
d62a17ae 4250 install_element(VIEW_NODE, &vtysh_terminal_length_cmd);
4251 install_element(VIEW_NODE, &vtysh_terminal_no_length_cmd);
4252 install_element(VIEW_NODE, &vtysh_show_daemons_cmd);
4253
4254 install_element(VIEW_NODE, &vtysh_ping_cmd);
4255 install_element(VIEW_NODE, &vtysh_ping_ip_cmd);
4256 install_element(VIEW_NODE, &vtysh_traceroute_cmd);
4257 install_element(VIEW_NODE, &vtysh_traceroute_ip_cmd);
4d9ad5dc 4258 install_element(VIEW_NODE, &vtysh_mtrace_cmd);
d62a17ae 4259 install_element(VIEW_NODE, &vtysh_ping6_cmd);
4260 install_element(VIEW_NODE, &vtysh_traceroute6_cmd);
576b6b5d 4261#if defined(HAVE_SHELL_ACCESS)
d62a17ae 4262 install_element(VIEW_NODE, &vtysh_telnet_cmd);
4263 install_element(VIEW_NODE, &vtysh_telnet_port_cmd);
4264 install_element(VIEW_NODE, &vtysh_ssh_cmd);
4eeccf18 4265#endif
576b6b5d 4266#if defined(HAVE_SHELL_ACCESS)
d62a17ae 4267 install_element(ENABLE_NODE, &vtysh_start_shell_cmd);
4268 install_element(ENABLE_NODE, &vtysh_start_bash_cmd);
4269 install_element(ENABLE_NODE, &vtysh_start_zsh_cmd);
576b6b5d
DS
4270#endif
4271
aea03ad6 4272 /* debugging */
7b526b61 4273 install_element(VIEW_NODE, &vtysh_show_error_code_cmd);
dd73744d
IR
4274 install_element(ENABLE_NODE, &vtysh_show_debugging_cmd);
4275 install_element(ENABLE_NODE, &vtysh_show_debugging_hashtable_cmd);
eb68fbc6 4276 install_element(ENABLE_NODE, &vtysh_debug_all_cmd);
aea03ad6 4277 install_element(CONFIG_NODE, &vtysh_debug_all_cmd);
85a6806d
MS
4278 install_element(ENABLE_NODE, &vtysh_debug_memstats_cmd);
4279 install_element(CONFIG_NODE, &vtysh_debug_memstats_cmd);
aea03ad6 4280
4ad77140 4281 /* northbound */
eba4e1ea 4282 install_element(VIEW_NODE, &show_yang_operational_data_cmd);
4ad77140
RW
4283 install_element(ENABLE_NODE, &debug_nb_cmd);
4284 install_element(CONFIG_NODE, &debug_nb_cmd);
4285
aea03ad6 4286 /* misc lib show commands */
d62a17ae 4287 install_element(VIEW_NODE, &vtysh_show_memory_cmd);
4288 install_element(VIEW_NODE, &vtysh_show_modules_cmd);
d62a17ae 4289 install_element(VIEW_NODE, &vtysh_show_work_queues_cmd);
4290 install_element(VIEW_NODE, &vtysh_show_work_queues_daemon_cmd);
f75e802d 4291#ifndef EXCLUDE_CPU_TIME
d62a17ae 4292 install_element(VIEW_NODE, &vtysh_show_thread_cmd);
f75e802d 4293#endif
8872626b 4294 install_element(VIEW_NODE, &vtysh_show_poll_cmd);
d62a17ae 4295
4296 /* Logging */
4297 install_element(VIEW_NODE, &vtysh_show_logging_cmd);
4298 install_element(CONFIG_NODE, &vtysh_log_stdout_cmd);
4299 install_element(CONFIG_NODE, &vtysh_log_stdout_level_cmd);
4300 install_element(CONFIG_NODE, &no_vtysh_log_stdout_cmd);
4301 install_element(CONFIG_NODE, &vtysh_log_file_cmd);
4302 install_element(CONFIG_NODE, &vtysh_log_file_level_cmd);
4303 install_element(CONFIG_NODE, &no_vtysh_log_file_cmd);
4304 install_element(CONFIG_NODE, &vtysh_log_monitor_cmd);
4305 install_element(CONFIG_NODE, &no_vtysh_log_monitor_cmd);
4306 install_element(CONFIG_NODE, &vtysh_log_syslog_cmd);
4307 install_element(CONFIG_NODE, &no_vtysh_log_syslog_cmd);
d62a17ae 4308 install_element(CONFIG_NODE, &vtysh_log_facility_cmd);
4309 install_element(CONFIG_NODE, &no_vtysh_log_facility_cmd);
4310 install_element(CONFIG_NODE, &vtysh_log_record_priority_cmd);
4311 install_element(CONFIG_NODE, &no_vtysh_log_record_priority_cmd);
4312 install_element(CONFIG_NODE, &vtysh_log_timestamp_precision_cmd);
4313 install_element(CONFIG_NODE, &no_vtysh_log_timestamp_precision_cmd);
4314
4315 install_element(CONFIG_NODE, &vtysh_service_password_encrypt_cmd);
4316 install_element(CONFIG_NODE, &no_vtysh_service_password_encrypt_cmd);
4317
4318 install_element(CONFIG_NODE, &vtysh_password_cmd);
322e2d5c 4319 install_element(CONFIG_NODE, &no_vtysh_password_cmd);
d62a17ae 4320 install_element(CONFIG_NODE, &vtysh_enable_password_cmd);
4321 install_element(CONFIG_NODE, &no_vtysh_enable_password_cmd);
718e3744 4322}