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