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