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