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