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