]>
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 | ||
33 | #include "command.h" | |
34 | #include "memory.h" | |
35 | #include "vtysh/vtysh.h" | |
6099b3b5 | 36 | #include "log.h" |
320da874 | 37 | #include "bgpd/bgp_vty.h" |
718e3744 | 38 | |
39 | /* Struct VTY. */ | |
40 | struct vty *vty; | |
41 | ||
42 | /* VTY shell pager name. */ | |
43 | char *vtysh_pager_name = NULL; | |
44 | ||
45 | /* VTY shell client structure. */ | |
46 | struct vtysh_client | |
47 | { | |
48 | int fd; | |
b1aa147d | 49 | const char *name; |
50 | int flag; | |
51 | const char *path; | |
52 | } vtysh_client[] = | |
53 | { | |
54 | { .fd = -1, .name = "zebra", .flag = VTYSH_ZEBRA, .path = ZEBRA_VTYSH_PATH}, | |
55 | { .fd = -1, .name = "ripd", .flag = VTYSH_RIPD, .path = RIP_VTYSH_PATH}, | |
56 | { .fd = -1, .name = "ripngd", .flag = VTYSH_RIPNGD, .path = RIPNG_VTYSH_PATH}, | |
57 | { .fd = -1, .name = "ospfd", .flag = VTYSH_OSPFD, .path = OSPF_VTYSH_PATH}, | |
58 | { .fd = -1, .name = "ospf6d", .flag = VTYSH_OSPF6D, .path = OSPF6_VTYSH_PATH}, | |
59 | { .fd = -1, .name = "bgpd", .flag = VTYSH_BGPD, .path = BGP_VTYSH_PATH}, | |
60 | { .fd = -1, .name = "isisd", .flag = VTYSH_ISISD, .path = ISIS_VTYSH_PATH}, | |
61 | }; | |
62 | ||
63 | #define VTYSH_INDEX_MAX (sizeof(vtysh_client)/sizeof(vtysh_client[0])) | |
64 | ||
65 | /* We need direct access to ripd to implement vtysh_exit_ripd_only. */ | |
66 | static struct vtysh_client *ripd_client = NULL; | |
67 | ||
b094d260 | 68 | |
e7168df4 | 69 | /* Using integrated config from Quagga.conf. Default is no. */ |
70 | int vtysh_writeconfig_integrated = 0; | |
71 | ||
72 | extern char config_default[]; | |
73 | ||
274a4a44 | 74 | static void |
718e3744 | 75 | vclient_close (struct vtysh_client *vclient) |
76 | { | |
b1aa147d | 77 | if (vclient->fd >= 0) |
78 | { | |
79 | fprintf(stderr, | |
80 | "Warning: closing connection to %s because of an I/O error!\n", | |
81 | vclient->name); | |
82 | close (vclient->fd); | |
83 | vclient->fd = -1; | |
84 | } | |
718e3744 | 85 | } |
86 | ||
718e3744 | 87 | /* Following filled with debug code to trace a problematic condition |
95e735b5 | 88 | * under load - it SHOULD handle it. */ |
718e3744 | 89 | #define ERR_WHERE_STRING "vtysh(): vtysh_client_config(): " |
274a4a44 | 90 | static int |
718e3744 | 91 | vtysh_client_config (struct vtysh_client *vclient, char *line) |
92 | { | |
93 | int ret; | |
94 | char *buf; | |
95 | size_t bufsz; | |
96 | char *pbuf; | |
97 | size_t left; | |
98 | char *eoln; | |
99 | int nbytes; | |
100 | int i; | |
101 | int readln; | |
102 | ||
103 | if (vclient->fd < 0) | |
104 | return CMD_SUCCESS; | |
105 | ||
106 | ret = write (vclient->fd, line, strlen (line) + 1); | |
107 | if (ret <= 0) | |
108 | { | |
109 | vclient_close (vclient); | |
110 | return CMD_SUCCESS; | |
111 | } | |
112 | ||
95e735b5 | 113 | /* Allow enough room for buffer to read more than a few pages from socket. */ |
e3d29b5f | 114 | bufsz = 5 * getpagesize() + 1; |
718e3744 | 115 | buf = XMALLOC(MTYPE_TMP, bufsz); |
116 | memset(buf, 0, bufsz); | |
117 | pbuf = buf; | |
118 | ||
119 | while (1) | |
120 | { | |
121 | if (pbuf >= ((buf + bufsz) -1)) | |
122 | { | |
123 | fprintf (stderr, ERR_WHERE_STRING \ | |
124 | "warning - pbuf beyond buffer end.\n"); | |
125 | return CMD_WARNING; | |
126 | } | |
127 | ||
128 | readln = (buf + bufsz) - pbuf - 1; | |
129 | nbytes = read (vclient->fd, pbuf, readln); | |
130 | ||
131 | if (nbytes <= 0) | |
132 | { | |
133 | ||
134 | if (errno == EINTR) | |
135 | continue; | |
136 | ||
137 | fprintf(stderr, ERR_WHERE_STRING "(%u)", errno); | |
138 | perror(""); | |
139 | ||
140 | if (errno == EAGAIN || errno == EIO) | |
141 | continue; | |
142 | ||
143 | vclient_close (vclient); | |
144 | XFREE(MTYPE_TMP, buf); | |
145 | return CMD_SUCCESS; | |
146 | } | |
147 | ||
148 | pbuf[nbytes] = '\0'; | |
149 | ||
150 | if (nbytes >= 4) | |
151 | { | |
152 | i = nbytes - 4; | |
153 | if (pbuf[i] == '\0' && pbuf[i + 1] == '\0' && pbuf[i + 2] == '\0') | |
154 | { | |
155 | ret = pbuf[i + 3]; | |
156 | break; | |
157 | } | |
158 | } | |
159 | pbuf += nbytes; | |
160 | ||
161 | /* See if a line exists in buffer, if so parse and consume it, and | |
95e735b5 | 162 | * reset read position. */ |
718e3744 | 163 | if ((eoln = strrchr(buf, '\n')) == NULL) |
164 | continue; | |
165 | ||
166 | if (eoln >= ((buf + bufsz) - 1)) | |
167 | { | |
168 | fprintf (stderr, ERR_WHERE_STRING \ | |
169 | "warning - eoln beyond buffer end.\n"); | |
170 | } | |
171 | vtysh_config_parse(buf); | |
172 | ||
173 | eoln++; | |
174 | left = (size_t)(buf + bufsz - eoln); | |
175 | memmove(buf, eoln, left); | |
176 | buf[bufsz-1] = '\0'; | |
177 | pbuf = buf + strlen(buf); | |
178 | } | |
179 | ||
95e735b5 | 180 | /* Parse anything left in the buffer. */ |
e7168df4 | 181 | |
718e3744 | 182 | vtysh_config_parse (buf); |
183 | ||
184 | XFREE(MTYPE_TMP, buf); | |
185 | return ret; | |
186 | } | |
187 | ||
274a4a44 | 188 | static int |
dda09522 | 189 | vtysh_client_execute (struct vtysh_client *vclient, const char *line, FILE *fp) |
718e3744 | 190 | { |
191 | int ret; | |
192 | char buf[1001]; | |
193 | int nbytes; | |
2852de1c | 194 | int i; |
195 | int numnulls = 0; | |
718e3744 | 196 | |
197 | if (vclient->fd < 0) | |
198 | return CMD_SUCCESS; | |
199 | ||
200 | ret = write (vclient->fd, line, strlen (line) + 1); | |
201 | if (ret <= 0) | |
202 | { | |
203 | vclient_close (vclient); | |
204 | return CMD_SUCCESS; | |
205 | } | |
206 | ||
207 | while (1) | |
208 | { | |
209 | nbytes = read (vclient->fd, buf, sizeof(buf)-1); | |
210 | ||
211 | if (nbytes <= 0 && errno != EINTR) | |
212 | { | |
213 | vclient_close (vclient); | |
214 | return CMD_SUCCESS; | |
215 | } | |
216 | ||
217 | if (nbytes > 0) | |
218 | { | |
85fb1e6d | 219 | if ((numnulls == 3) && (nbytes == 1)) |
220 | return buf[0]; | |
221 | ||
718e3744 | 222 | buf[nbytes] = '\0'; |
85fb1e6d | 223 | fputs (buf, fp); |
718e3744 | 224 | fflush (fp); |
2852de1c | 225 | |
0921d48e | 226 | /* check for trailling \0\0\0<ret code>, |
227 | * even if split across reads | |
228 | * (see lib/vty.c::vtysh_read) | |
229 | */ | |
2852de1c | 230 | if (nbytes >= 4) |
231 | { | |
232 | i = nbytes-4; | |
233 | numnulls = 0; | |
234 | } | |
235 | else | |
236 | i = 0; | |
237 | ||
0921d48e | 238 | while (i < nbytes && numnulls < 3) |
2852de1c | 239 | { |
240 | if (buf[i++] == '\0') | |
241 | numnulls++; | |
242 | else | |
85fb1e6d | 243 | numnulls = 0; |
2852de1c | 244 | } |
245 | ||
85fb1e6d | 246 | /* got 3 or more trailing NULs? */ |
247 | if ((numnulls >= 3) && (i < nbytes)) | |
0921d48e | 248 | return (buf[nbytes-1]); |
718e3744 | 249 | } |
250 | } | |
718e3744 | 251 | } |
252 | ||
253 | void | |
b1aa147d | 254 | vtysh_exit_ripd_only (void) |
718e3744 | 255 | { |
b1aa147d | 256 | if (ripd_client) |
257 | vtysh_client_execute (ripd_client, "exit", stdout); | |
718e3744 | 258 | } |
259 | ||
260 | ||
261 | void | |
b1aa147d | 262 | vtysh_pager_init (void) |
718e3744 | 263 | { |
5a9c53de | 264 | char *pager_defined; |
265 | ||
266 | pager_defined = getenv ("VTYSH_PAGER"); | |
267 | ||
268 | if (pager_defined) | |
269 | vtysh_pager_name = strdup (pager_defined); | |
270 | else | |
34553cc3 | 271 | vtysh_pager_name = strdup ("more"); |
718e3744 | 272 | } |
273 | ||
274 | /* Command execution over the vty interface. */ | |
274a4a44 | 275 | static void |
dda09522 | 276 | vtysh_execute_func (const char *line, int pager) |
718e3744 | 277 | { |
278 | int ret, cmd_stat; | |
b1aa147d | 279 | u_int i; |
718e3744 | 280 | vector vline; |
281 | struct cmd_element *cmd; | |
282 | FILE *fp = NULL; | |
13bfca7a | 283 | int closepager = 0; |
284 | int tried = 0; | |
285 | int saved_ret, saved_node; | |
718e3744 | 286 | |
95e735b5 | 287 | /* Split readline string up into the vector. */ |
718e3744 | 288 | vline = cmd_make_strvec (line); |
289 | ||
290 | if (vline == NULL) | |
291 | return; | |
292 | ||
13bfca7a | 293 | saved_ret = ret = cmd_execute_command (vline, vty, &cmd, 1); |
294 | saved_node = vty->node; | |
295 | ||
296 | /* If command doesn't succeeded in current node, try to walk up in node tree. | |
297 | * Changing vty->node is enough to try it just out without actual walkup in | |
298 | * the vtysh. */ | |
299 | while (ret != CMD_SUCCESS && ret != CMD_SUCCESS_DAEMON && ret != CMD_WARNING | |
300 | && vty->node > CONFIG_NODE) | |
301 | { | |
302 | vty->node = node_parent(vty->node); | |
303 | ret = cmd_execute_command (vline, vty, &cmd, 1); | |
304 | tried++; | |
305 | } | |
306 | ||
307 | vty->node = saved_node; | |
308 | ||
309 | /* If command succeeded in any other node than current (tried > 0) we have | |
310 | * to move into node in the vtysh where it succeeded. */ | |
311 | if (ret == CMD_SUCCESS || ret == CMD_SUCCESS_DAEMON || ret == CMD_WARNING) | |
312 | { | |
313 | if ((saved_node == BGP_VPNV4_NODE || saved_node == BGP_IPV4_NODE | |
57b5b7ed | 314 | || saved_node == BGP_IPV6_NODE || saved_node == BGP_IPV4M_NODE |
315 | || saved_node == BGP_IPV6M_NODE) | |
13bfca7a | 316 | && (tried == 1)) |
317 | { | |
318 | vtysh_execute("exit-address-family"); | |
319 | } | |
320 | else if ((saved_node == KEYCHAIN_KEY_NODE) && (tried == 1)) | |
321 | { | |
322 | vtysh_execute("exit"); | |
323 | } | |
324 | else if (tried) | |
325 | { | |
326 | vtysh_execute ("end"); | |
327 | vtysh_execute ("configure terminal"); | |
328 | } | |
329 | } | |
330 | /* If command didn't succeed in any node, continue with return value from | |
331 | * first try. */ | |
332 | else if (tried) | |
333 | { | |
334 | ret = saved_ret; | |
335 | } | |
718e3744 | 336 | |
337 | cmd_free_strvec (vline); | |
338 | ||
339 | switch (ret) | |
340 | { | |
341 | case CMD_WARNING: | |
342 | if (vty->type == VTY_FILE) | |
4fc01e67 | 343 | fprintf (stdout,"Warning...\n"); |
718e3744 | 344 | break; |
345 | case CMD_ERR_AMBIGUOUS: | |
4fc01e67 | 346 | fprintf (stdout,"%% Ambiguous command.\n"); |
718e3744 | 347 | break; |
348 | case CMD_ERR_NO_MATCH: | |
4fc01e67 | 349 | fprintf (stdout,"%% Unknown command.\n"); |
718e3744 | 350 | break; |
351 | case CMD_ERR_INCOMPLETE: | |
4fc01e67 | 352 | fprintf (stdout,"%% Command incomplete.\n"); |
718e3744 | 353 | break; |
354 | case CMD_SUCCESS_DAEMON: | |
355 | { | |
97b7db2d | 356 | /* FIXME: Don't open pager for exit commands. popen() causes problems |
357 | * if exited from vtysh at all. This hack shouldn't cause any problem | |
358 | * but is really ugly. */ | |
359 | if (pager && vtysh_pager_name && (strncmp(line, "exit", 4) != 0)) | |
718e3744 | 360 | { |
4fc01e67 | 361 | fp = popen (vtysh_pager_name, "w"); |
718e3744 | 362 | if (fp == NULL) |
363 | { | |
a805cc2d | 364 | perror ("popen failed for pager"); |
365 | fp = stdout; | |
718e3744 | 366 | } |
a805cc2d | 367 | else |
368 | closepager=1; | |
718e3744 | 369 | } |
370 | else | |
371 | fp = stdout; | |
372 | ||
373 | if (! strcmp(cmd->string,"configure terminal")) | |
374 | { | |
b1aa147d | 375 | for (i = 0; i < VTYSH_INDEX_MAX; i++) |
376 | { | |
377 | cmd_stat = vtysh_client_execute(&vtysh_client[i], line, fp); | |
378 | if (cmd_stat == CMD_WARNING) | |
379 | break; | |
380 | } | |
381 | ||
718e3744 | 382 | if (cmd_stat) |
383 | { | |
b094d260 | 384 | line = "end"; |
385 | vline = cmd_make_strvec (line); | |
718e3744 | 386 | |
b094d260 | 387 | if (vline == NULL) |
718e3744 | 388 | { |
a805cc2d | 389 | if (pager && vtysh_pager_name && fp && closepager) |
718e3744 | 390 | { |
391 | if (pclose (fp) == -1) | |
392 | { | |
a805cc2d | 393 | perror ("pclose failed for pager"); |
718e3744 | 394 | } |
395 | fp = NULL; | |
396 | } | |
397 | return; | |
398 | } | |
399 | ||
87d683b0 | 400 | ret = cmd_execute_command (vline, vty, &cmd, 1); |
b094d260 | 401 | cmd_free_strvec (vline); |
402 | if (ret != CMD_SUCCESS_DAEMON) | |
403 | break; | |
718e3744 | 404 | } |
405 | else | |
406 | if (cmd->func) | |
407 | { | |
408 | (*cmd->func) (cmd, vty, 0, NULL); | |
409 | break; | |
b094d260 | 410 | } |
718e3744 | 411 | } |
412 | ||
b1aa147d | 413 | cmd_stat = CMD_SUCCESS; |
414 | for (i = 0; i < VTYSH_INDEX_MAX; i++) | |
415 | { | |
416 | if (cmd->daemon & vtysh_client[i].flag) | |
417 | { | |
418 | cmd_stat = vtysh_client_execute(&vtysh_client[i], line, fp); | |
419 | if (cmd_stat != CMD_SUCCESS) | |
420 | break; | |
421 | } | |
422 | } | |
423 | if (cmd_stat != CMD_SUCCESS) | |
424 | break; | |
425 | ||
718e3744 | 426 | if (cmd->func) |
427 | (*cmd->func) (cmd, vty, 0, NULL); | |
428 | } | |
429 | } | |
a805cc2d | 430 | if (pager && vtysh_pager_name && fp && closepager) |
718e3744 | 431 | { |
432 | if (pclose (fp) == -1) | |
433 | { | |
a805cc2d | 434 | perror ("pclose failed for pager"); |
718e3744 | 435 | } |
436 | fp = NULL; | |
437 | } | |
438 | } | |
439 | ||
440 | void | |
dda09522 | 441 | vtysh_execute_no_pager (const char *line) |
718e3744 | 442 | { |
443 | vtysh_execute_func (line, 0); | |
444 | } | |
445 | ||
446 | void | |
dda09522 | 447 | vtysh_execute (const char *line) |
718e3744 | 448 | { |
449 | vtysh_execute_func (line, 1); | |
450 | } | |
451 | ||
452 | /* Configration make from file. */ | |
453 | int | |
454 | vtysh_config_from_file (struct vty *vty, FILE *fp) | |
455 | { | |
456 | int ret; | |
457 | vector vline; | |
458 | struct cmd_element *cmd; | |
459 | ||
460 | while (fgets (vty->buf, VTY_BUFSIZ, fp)) | |
461 | { | |
462 | if (vty->buf[0] == '!' || vty->buf[1] == '#') | |
463 | continue; | |
464 | ||
465 | vline = cmd_make_strvec (vty->buf); | |
466 | ||
95e735b5 | 467 | /* In case of comment line. */ |
718e3744 | 468 | if (vline == NULL) |
469 | continue; | |
470 | ||
95e735b5 | 471 | /* Execute configuration command : this is strict match. */ |
718e3744 | 472 | ret = cmd_execute_command_strict (vline, vty, &cmd); |
473 | ||
95e735b5 | 474 | /* Try again with setting node to CONFIG_NODE. */ |
718e3744 | 475 | if (ret != CMD_SUCCESS |
476 | && ret != CMD_SUCCESS_DAEMON | |
477 | && ret != CMD_WARNING) | |
478 | { | |
479 | if (vty->node == KEYCHAIN_KEY_NODE) | |
480 | { | |
481 | vty->node = KEYCHAIN_NODE; | |
482 | vtysh_exit_ripd_only (); | |
483 | ret = cmd_execute_command_strict (vline, vty, &cmd); | |
484 | ||
485 | if (ret != CMD_SUCCESS | |
486 | && ret != CMD_SUCCESS_DAEMON | |
487 | && ret != CMD_WARNING) | |
488 | { | |
489 | vtysh_exit_ripd_only (); | |
490 | vty->node = CONFIG_NODE; | |
491 | ret = cmd_execute_command_strict (vline, vty, &cmd); | |
492 | } | |
493 | } | |
494 | else | |
495 | { | |
496 | vtysh_execute ("end"); | |
497 | vtysh_execute ("configure terminal"); | |
498 | vty->node = CONFIG_NODE; | |
499 | ret = cmd_execute_command_strict (vline, vty, &cmd); | |
500 | } | |
501 | } | |
502 | ||
503 | cmd_free_strvec (vline); | |
504 | ||
505 | switch (ret) | |
506 | { | |
507 | case CMD_WARNING: | |
508 | if (vty->type == VTY_FILE) | |
4fc01e67 | 509 | fprintf (stdout,"Warning...\n"); |
718e3744 | 510 | break; |
511 | case CMD_ERR_AMBIGUOUS: | |
4fc01e67 | 512 | fprintf (stdout,"%% Ambiguous command.\n"); |
718e3744 | 513 | break; |
514 | case CMD_ERR_NO_MATCH: | |
4fc01e67 | 515 | fprintf (stdout,"%% Unknown command: %s", vty->buf); |
718e3744 | 516 | break; |
517 | case CMD_ERR_INCOMPLETE: | |
4fc01e67 | 518 | fprintf (stdout,"%% Command incomplete.\n"); |
718e3744 | 519 | break; |
520 | case CMD_SUCCESS_DAEMON: | |
521 | { | |
b1aa147d | 522 | u_int i; |
523 | int cmd_stat = CMD_SUCCESS; | |
524 | ||
525 | for (i = 0; i < VTYSH_INDEX_MAX; i++) | |
526 | { | |
44316fef | 527 | if (cmd->daemon & vtysh_client[i].flag) |
b1aa147d | 528 | { |
529 | cmd_stat = vtysh_client_execute (&vtysh_client[i], | |
530 | vty->buf, stdout); | |
531 | if (cmd_stat != CMD_SUCCESS) | |
532 | break; | |
533 | } | |
534 | } | |
535 | if (cmd_stat != CMD_SUCCESS) | |
536 | break; | |
537 | ||
718e3744 | 538 | if (cmd->func) |
539 | (*cmd->func) (cmd, vty, 0, NULL); | |
540 | } | |
541 | } | |
542 | } | |
543 | return CMD_SUCCESS; | |
544 | } | |
545 | ||
546 | /* We don't care about the point of the cursor when '?' is typed. */ | |
547 | int | |
b1aa147d | 548 | vtysh_rl_describe (void) |
718e3744 | 549 | { |
550 | int ret; | |
dda09522 | 551 | unsigned int i; |
718e3744 | 552 | vector vline; |
553 | vector describe; | |
554 | int width; | |
555 | struct desc *desc; | |
556 | ||
557 | vline = cmd_make_strvec (rl_line_buffer); | |
558 | ||
559 | /* In case of '> ?'. */ | |
560 | if (vline == NULL) | |
561 | { | |
562 | vline = vector_init (1); | |
563 | vector_set (vline, '\0'); | |
564 | } | |
565 | else | |
566 | if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1])) | |
567 | vector_set (vline, '\0'); | |
568 | ||
569 | describe = cmd_describe_command (vline, vty, &ret); | |
570 | ||
4fc01e67 | 571 | fprintf (stdout,"\n"); |
718e3744 | 572 | |
573 | /* Ambiguous and no match error. */ | |
574 | switch (ret) | |
575 | { | |
576 | case CMD_ERR_AMBIGUOUS: | |
577 | cmd_free_strvec (vline); | |
4fc01e67 | 578 | fprintf (stdout,"%% Ambiguous command.\n"); |
718e3744 | 579 | rl_on_new_line (); |
580 | return 0; | |
581 | break; | |
582 | case CMD_ERR_NO_MATCH: | |
583 | cmd_free_strvec (vline); | |
4fc01e67 | 584 | fprintf (stdout,"%% There is no matched command.\n"); |
718e3744 | 585 | rl_on_new_line (); |
586 | return 0; | |
587 | break; | |
588 | } | |
589 | ||
590 | /* Get width of command string. */ | |
591 | width = 0; | |
55468c86 | 592 | for (i = 0; i < vector_active (describe); i++) |
718e3744 | 593 | if ((desc = vector_slot (describe, i)) != NULL) |
594 | { | |
595 | int len; | |
596 | ||
597 | if (desc->cmd[0] == '\0') | |
598 | continue; | |
599 | ||
600 | len = strlen (desc->cmd); | |
601 | if (desc->cmd[0] == '.') | |
602 | len--; | |
603 | ||
604 | if (width < len) | |
605 | width = len; | |
606 | } | |
607 | ||
55468c86 | 608 | for (i = 0; i < vector_active (describe); i++) |
718e3744 | 609 | if ((desc = vector_slot (describe, i)) != NULL) |
610 | { | |
611 | if (desc->cmd[0] == '\0') | |
612 | continue; | |
613 | ||
614 | if (! desc->str) | |
4fc01e67 | 615 | fprintf (stdout," %-s\n", |
b094d260 | 616 | desc->cmd[0] == '.' ? desc->cmd + 1 : desc->cmd); |
718e3744 | 617 | else |
4fc01e67 | 618 | fprintf (stdout," %-*s %s\n", |
b094d260 | 619 | width, |
620 | desc->cmd[0] == '.' ? desc->cmd + 1 : desc->cmd, | |
621 | desc->str); | |
718e3744 | 622 | } |
623 | ||
624 | cmd_free_strvec (vline); | |
625 | vector_free (describe); | |
626 | ||
627 | rl_on_new_line(); | |
628 | ||
629 | return 0; | |
630 | } | |
631 | ||
95e735b5 | 632 | /* Result of cmd_complete_command() call will be stored here |
633 | * and used in new_completion() in order to put the space in | |
634 | * correct places only. */ | |
718e3744 | 635 | int complete_status; |
636 | ||
274a4a44 | 637 | static char * |
dfc0d9ba | 638 | command_generator (const char *text, int state) |
718e3744 | 639 | { |
640 | vector vline; | |
641 | static char **matched = NULL; | |
642 | static int index = 0; | |
643 | ||
644 | /* First call. */ | |
645 | if (! state) | |
646 | { | |
647 | index = 0; | |
648 | ||
649 | if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE) | |
650 | return NULL; | |
651 | ||
652 | vline = cmd_make_strvec (rl_line_buffer); | |
653 | if (vline == NULL) | |
654 | return NULL; | |
655 | ||
656 | if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1])) | |
657 | vector_set (vline, '\0'); | |
658 | ||
659 | matched = cmd_complete_command (vline, vty, &complete_status); | |
660 | } | |
661 | ||
662 | if (matched && matched[index]) | |
663 | return matched[index++]; | |
664 | ||
665 | return NULL; | |
666 | } | |
667 | ||
274a4a44 | 668 | static char ** |
718e3744 | 669 | new_completion (char *text, int start, int end) |
670 | { | |
671 | char **matches; | |
672 | ||
dfc0d9ba | 673 | matches = rl_completion_matches (text, command_generator); |
718e3744 | 674 | |
675 | if (matches) | |
676 | { | |
677 | rl_point = rl_end; | |
678 | if (complete_status == CMD_COMPLETE_FULL_MATCH) | |
679 | rl_pending_input = ' '; | |
680 | } | |
681 | ||
682 | return matches; | |
683 | } | |
684 | ||
274a4a44 | 685 | #if 0 |
686 | /* This function is not actually being used. */ | |
687 | static char ** | |
718e3744 | 688 | vtysh_completion (char *text, int start, int end) |
689 | { | |
690 | int ret; | |
691 | vector vline; | |
692 | char **matched = NULL; | |
693 | ||
694 | if (vty->node == AUTH_NODE || vty->node == AUTH_ENABLE_NODE) | |
695 | return NULL; | |
696 | ||
697 | vline = cmd_make_strvec (rl_line_buffer); | |
698 | if (vline == NULL) | |
699 | return NULL; | |
700 | ||
701 | /* In case of 'help \t'. */ | |
702 | if (rl_end && isspace ((int) rl_line_buffer[rl_end - 1])) | |
703 | vector_set (vline, '\0'); | |
704 | ||
705 | matched = cmd_complete_command (vline, vty, &ret); | |
706 | ||
707 | cmd_free_strvec (vline); | |
708 | ||
709 | return (char **) matched; | |
710 | } | |
274a4a44 | 711 | #endif |
718e3744 | 712 | |
95e735b5 | 713 | /* Vty node structures. */ |
7fc626de | 714 | static struct cmd_node bgp_node = |
718e3744 | 715 | { |
716 | BGP_NODE, | |
717 | "%s(config-router)# ", | |
718 | }; | |
719 | ||
7fc626de | 720 | static struct cmd_node rip_node = |
718e3744 | 721 | { |
722 | RIP_NODE, | |
723 | "%s(config-router)# ", | |
724 | }; | |
725 | ||
7fc626de | 726 | static struct cmd_node isis_node = |
c25e458a | 727 | { |
728 | ISIS_NODE, | |
729 | "%s(config-router)# ", | |
c25e458a | 730 | }; |
731 | ||
7fc626de | 732 | static struct cmd_node interface_node = |
718e3744 | 733 | { |
734 | INTERFACE_NODE, | |
735 | "%s(config-if)# ", | |
736 | }; | |
737 | ||
7fc626de | 738 | static struct cmd_node rmap_node = |
95e735b5 | 739 | { |
740 | RMAP_NODE, | |
741 | "%s(config-route-map)# " | |
742 | }; | |
743 | ||
7fc626de | 744 | static struct cmd_node zebra_node = |
95e735b5 | 745 | { |
746 | ZEBRA_NODE, | |
747 | "%s(config-router)# " | |
748 | }; | |
749 | ||
7fc626de | 750 | static struct cmd_node bgp_vpnv4_node = |
95e735b5 | 751 | { |
752 | BGP_VPNV4_NODE, | |
753 | "%s(config-router-af)# " | |
754 | }; | |
755 | ||
7fc626de | 756 | static struct cmd_node bgp_ipv4_node = |
95e735b5 | 757 | { |
758 | BGP_IPV4_NODE, | |
759 | "%s(config-router-af)# " | |
760 | }; | |
761 | ||
7fc626de | 762 | static struct cmd_node bgp_ipv4m_node = |
95e735b5 | 763 | { |
764 | BGP_IPV4M_NODE, | |
765 | "%s(config-router-af)# " | |
766 | }; | |
767 | ||
7fc626de | 768 | static struct cmd_node bgp_ipv6_node = |
95e735b5 | 769 | { |
770 | BGP_IPV6_NODE, | |
771 | "%s(config-router-af)# " | |
772 | }; | |
773 | ||
7fc626de | 774 | static struct cmd_node bgp_ipv6m_node = |
57b5b7ed | 775 | { |
776 | BGP_IPV6M_NODE, | |
777 | "%s(config-router-af)# " | |
778 | }; | |
779 | ||
7fc626de | 780 | static struct cmd_node ospf_node = |
95e735b5 | 781 | { |
782 | OSPF_NODE, | |
783 | "%s(config-router)# " | |
784 | }; | |
785 | ||
7fc626de | 786 | static struct cmd_node ripng_node = |
95e735b5 | 787 | { |
788 | RIPNG_NODE, | |
789 | "%s(config-router)# " | |
790 | }; | |
791 | ||
7fc626de | 792 | static struct cmd_node ospf6_node = |
95e735b5 | 793 | { |
794 | OSPF6_NODE, | |
795 | "%s(config-ospf6)# " | |
796 | }; | |
797 | ||
7fc626de | 798 | static struct cmd_node keychain_node = |
95e735b5 | 799 | { |
800 | KEYCHAIN_NODE, | |
801 | "%s(config-keychain)# " | |
802 | }; | |
803 | ||
7fc626de | 804 | static struct cmd_node keychain_key_node = |
95e735b5 | 805 | { |
806 | KEYCHAIN_KEY_NODE, | |
807 | "%s(config-keychain-key)# " | |
808 | }; | |
809 | ||
e7168df4 | 810 | /* Defined in lib/vty.c */ |
811 | extern struct cmd_node vty_node; | |
812 | ||
95e735b5 | 813 | /* When '^Z' is received from vty, move down to the enable mode. */ |
814 | int | |
b1aa147d | 815 | vtysh_end (void) |
95e735b5 | 816 | { |
817 | switch (vty->node) | |
818 | { | |
819 | case VIEW_NODE: | |
820 | case ENABLE_NODE: | |
821 | /* Nothing to do. */ | |
822 | break; | |
823 | default: | |
824 | vty->node = ENABLE_NODE; | |
825 | break; | |
826 | } | |
827 | return CMD_SUCCESS; | |
828 | } | |
829 | ||
830 | DEFUNSH (VTYSH_ALL, | |
831 | vtysh_end_all, | |
832 | vtysh_end_all_cmd, | |
833 | "end", | |
e7168df4 | 834 | "End current mode and change to enable mode\n") |
95e735b5 | 835 | { |
4289546d | 836 | return vtysh_end (); |
95e735b5 | 837 | } |
838 | ||
718e3744 | 839 | DEFUNSH (VTYSH_BGPD, |
840 | router_bgp, | |
841 | router_bgp_cmd, | |
320da874 | 842 | "router bgp " CMD_AS_RANGE, |
718e3744 | 843 | ROUTER_STR |
844 | BGP_STR | |
845 | AS_STR) | |
846 | { | |
847 | vty->node = BGP_NODE; | |
848 | return CMD_SUCCESS; | |
849 | } | |
850 | ||
10895fd6 PJ |
851 | ALIAS_SH (VTYSH_BGPD, |
852 | router_bgp, | |
853 | router_bgp_view_cmd, | |
854 | "router bgp " CMD_AS_RANGE " view WORD", | |
855 | ROUTER_STR | |
856 | BGP_STR | |
857 | AS_STR | |
858 | "BGP view\n" | |
859 | "view name\n") | |
860 | ||
718e3744 | 861 | DEFUNSH (VTYSH_BGPD, |
862 | address_family_vpnv4, | |
863 | address_family_vpnv4_cmd, | |
864 | "address-family vpnv4", | |
865 | "Enter Address Family command mode\n" | |
866 | "Address family\n") | |
867 | { | |
868 | vty->node = BGP_VPNV4_NODE; | |
869 | return CMD_SUCCESS; | |
870 | } | |
871 | ||
872 | DEFUNSH (VTYSH_BGPD, | |
873 | address_family_vpnv4_unicast, | |
874 | address_family_vpnv4_unicast_cmd, | |
875 | "address-family vpnv4 unicast", | |
876 | "Enter Address Family command mode\n" | |
877 | "Address family\n" | |
878 | "Address Family Modifier\n") | |
879 | { | |
880 | vty->node = BGP_VPNV4_NODE; | |
881 | return CMD_SUCCESS; | |
882 | } | |
883 | ||
884 | DEFUNSH (VTYSH_BGPD, | |
885 | address_family_ipv4_unicast, | |
886 | address_family_ipv4_unicast_cmd, | |
887 | "address-family ipv4 unicast", | |
888 | "Enter Address Family command mode\n" | |
889 | "Address family\n" | |
890 | "Address Family Modifier\n") | |
891 | { | |
892 | vty->node = BGP_IPV4_NODE; | |
893 | return CMD_SUCCESS; | |
894 | } | |
895 | ||
896 | DEFUNSH (VTYSH_BGPD, | |
897 | address_family_ipv4_multicast, | |
898 | address_family_ipv4_multicast_cmd, | |
899 | "address-family ipv4 multicast", | |
900 | "Enter Address Family command mode\n" | |
901 | "Address family\n" | |
902 | "Address Family Modifier\n") | |
903 | { | |
904 | vty->node = BGP_IPV4M_NODE; | |
905 | return CMD_SUCCESS; | |
906 | } | |
907 | ||
908 | DEFUNSH (VTYSH_BGPD, | |
909 | address_family_ipv6, | |
910 | address_family_ipv6_cmd, | |
911 | "address-family ipv6", | |
912 | "Enter Address Family command mode\n" | |
913 | "Address family\n") | |
914 | { | |
915 | vty->node = BGP_IPV6_NODE; | |
916 | return CMD_SUCCESS; | |
917 | } | |
918 | ||
919 | DEFUNSH (VTYSH_BGPD, | |
920 | address_family_ipv6_unicast, | |
921 | address_family_ipv6_unicast_cmd, | |
922 | "address-family ipv6 unicast", | |
923 | "Enter Address Family command mode\n" | |
924 | "Address family\n" | |
925 | "Address Family Modifier\n") | |
926 | { | |
927 | vty->node = BGP_IPV6_NODE; | |
928 | return CMD_SUCCESS; | |
929 | } | |
930 | ||
57b5b7ed | 931 | DEFUNSH (VTYSH_BGPD, |
932 | address_family_ipv6_multicast, | |
933 | address_family_ipv6_multicast_cmd, | |
934 | "address-family ipv6 multicast", | |
935 | "Enter Address Family command mode\n" | |
936 | "Address family\n" | |
937 | "Address Family Modifier\n") | |
938 | { | |
939 | vty->node = BGP_IPV6M_NODE; | |
940 | return CMD_SUCCESS; | |
941 | } | |
942 | ||
718e3744 | 943 | DEFUNSH (VTYSH_RIPD, |
944 | key_chain, | |
945 | key_chain_cmd, | |
946 | "key chain WORD", | |
947 | "Authentication key management\n" | |
948 | "Key-chain management\n" | |
949 | "Key-chain name\n") | |
950 | { | |
951 | vty->node = KEYCHAIN_NODE; | |
952 | return CMD_SUCCESS; | |
953 | } | |
954 | ||
955 | DEFUNSH (VTYSH_RIPD, | |
956 | key, | |
957 | key_cmd, | |
958 | "key <0-2147483647>", | |
959 | "Configure a key\n" | |
960 | "Key identifier number\n") | |
961 | { | |
962 | vty->node = KEYCHAIN_KEY_NODE; | |
963 | return CMD_SUCCESS; | |
964 | } | |
965 | ||
966 | DEFUNSH (VTYSH_RIPD, | |
967 | router_rip, | |
968 | router_rip_cmd, | |
969 | "router rip", | |
970 | ROUTER_STR | |
971 | "RIP") | |
972 | { | |
973 | vty->node = RIP_NODE; | |
974 | return CMD_SUCCESS; | |
975 | } | |
976 | ||
977 | DEFUNSH (VTYSH_RIPNGD, | |
978 | router_ripng, | |
979 | router_ripng_cmd, | |
980 | "router ripng", | |
981 | ROUTER_STR | |
982 | "RIPng") | |
983 | { | |
984 | vty->node = RIPNG_NODE; | |
985 | return CMD_SUCCESS; | |
986 | } | |
987 | ||
988 | DEFUNSH (VTYSH_OSPFD, | |
989 | router_ospf, | |
990 | router_ospf_cmd, | |
991 | "router ospf", | |
992 | "Enable a routing process\n" | |
993 | "Start OSPF configuration\n") | |
994 | { | |
995 | vty->node = OSPF_NODE; | |
996 | return CMD_SUCCESS; | |
997 | } | |
998 | ||
999 | DEFUNSH (VTYSH_OSPF6D, | |
1000 | router_ospf6, | |
1001 | router_ospf6_cmd, | |
1002 | "router ospf6", | |
1003 | OSPF6_ROUTER_STR | |
1004 | OSPF6_STR) | |
1005 | { | |
1006 | vty->node = OSPF6_NODE; | |
1007 | return CMD_SUCCESS; | |
1008 | } | |
1009 | ||
c25e458a | 1010 | DEFUNSH (VTYSH_ISISD, |
b094d260 | 1011 | router_isis, |
1012 | router_isis_cmd, | |
1013 | "router isis WORD", | |
1014 | ROUTER_STR | |
1015 | "ISO IS-IS\n" | |
1016 | "ISO Routing area tag") | |
c25e458a | 1017 | { |
1018 | vty->node = ISIS_NODE; | |
1019 | return CMD_SUCCESS; | |
1020 | } | |
1021 | ||
718e3744 | 1022 | DEFUNSH (VTYSH_RMAP, |
1023 | route_map, | |
1024 | route_map_cmd, | |
1025 | "route-map WORD (deny|permit) <1-65535>", | |
1026 | "Create route-map or enter route-map command mode\n" | |
1027 | "Route map tag\n" | |
1028 | "Route map denies set operations\n" | |
1029 | "Route map permits set operations\n" | |
1030 | "Sequence to insert to/delete from existing route-map entry\n") | |
1031 | { | |
1032 | vty->node = RMAP_NODE; | |
1033 | return CMD_SUCCESS; | |
1034 | } | |
1035 | ||
e7168df4 | 1036 | DEFUNSH (VTYSH_ALL, |
1037 | vtysh_line_vty, | |
1038 | vtysh_line_vty_cmd, | |
1039 | "line vty", | |
1040 | "Configure a terminal line\n" | |
1041 | "Virtual terminal\n") | |
1042 | { | |
1043 | vty->node = VTY_NODE; | |
1044 | return CMD_SUCCESS; | |
1045 | } | |
1046 | ||
718e3744 | 1047 | DEFUNSH (VTYSH_ALL, |
1048 | vtysh_enable, | |
1049 | vtysh_enable_cmd, | |
1050 | "enable", | |
1051 | "Turn on privileged mode command\n") | |
1052 | { | |
1053 | vty->node = ENABLE_NODE; | |
1054 | return CMD_SUCCESS; | |
1055 | } | |
1056 | ||
718e3744 | 1057 | DEFUNSH (VTYSH_ALL, |
1058 | vtysh_disable, | |
1059 | vtysh_disable_cmd, | |
1060 | "disable", | |
1061 | "Turn off privileged mode command\n") | |
1062 | { | |
1063 | if (vty->node == ENABLE_NODE) | |
1064 | vty->node = VIEW_NODE; | |
1065 | return CMD_SUCCESS; | |
1066 | } | |
1067 | ||
718e3744 | 1068 | DEFUNSH (VTYSH_ALL, |
1069 | vtysh_config_terminal, | |
1070 | vtysh_config_terminal_cmd, | |
1071 | "configure terminal", | |
1072 | "Configuration from vty interface\n" | |
1073 | "Configuration terminal\n") | |
1074 | { | |
1075 | vty->node = CONFIG_NODE; | |
1076 | return CMD_SUCCESS; | |
1077 | } | |
1078 | ||
274a4a44 | 1079 | static int |
718e3744 | 1080 | vtysh_exit (struct vty *vty) |
1081 | { | |
1082 | switch (vty->node) | |
1083 | { | |
1084 | case VIEW_NODE: | |
1085 | case ENABLE_NODE: | |
1086 | exit (0); | |
1087 | break; | |
1088 | case CONFIG_NODE: | |
1089 | vty->node = ENABLE_NODE; | |
1090 | break; | |
1091 | case INTERFACE_NODE: | |
1092 | case ZEBRA_NODE: | |
1093 | case BGP_NODE: | |
1094 | case RIP_NODE: | |
1095 | case RIPNG_NODE: | |
1096 | case OSPF_NODE: | |
1097 | case OSPF6_NODE: | |
c25e458a | 1098 | case ISIS_NODE: |
718e3744 | 1099 | case MASC_NODE: |
1100 | case RMAP_NODE: | |
1101 | case VTY_NODE: | |
1102 | case KEYCHAIN_NODE: | |
2a56df97 | 1103 | vtysh_execute("end"); |
1104 | vtysh_execute("configure terminal"); | |
718e3744 | 1105 | vty->node = CONFIG_NODE; |
1106 | break; | |
1107 | case BGP_VPNV4_NODE: | |
1108 | case BGP_IPV4_NODE: | |
1109 | case BGP_IPV4M_NODE: | |
1110 | case BGP_IPV6_NODE: | |
57b5b7ed | 1111 | case BGP_IPV6M_NODE: |
718e3744 | 1112 | vty->node = BGP_NODE; |
1113 | break; | |
1114 | case KEYCHAIN_KEY_NODE: | |
1115 | vty->node = KEYCHAIN_NODE; | |
1116 | break; | |
1117 | default: | |
1118 | break; | |
1119 | } | |
1120 | return CMD_SUCCESS; | |
1121 | } | |
1122 | ||
1123 | DEFUNSH (VTYSH_ALL, | |
1124 | vtysh_exit_all, | |
1125 | vtysh_exit_all_cmd, | |
1126 | "exit", | |
1127 | "Exit current mode and down to previous mode\n") | |
1128 | { | |
1129 | return vtysh_exit (vty); | |
1130 | } | |
1131 | ||
1132 | ALIAS (vtysh_exit_all, | |
1133 | vtysh_quit_all_cmd, | |
1134 | "quit", | |
1135 | "Exit current mode and down to previous mode\n") | |
1136 | ||
1137 | DEFUNSH (VTYSH_BGPD, | |
1138 | exit_address_family, | |
1139 | exit_address_family_cmd, | |
1140 | "exit-address-family", | |
1141 | "Exit from Address Family configuration mode\n") | |
1142 | { | |
1143 | if (vty->node == BGP_IPV4_NODE | |
1144 | || vty->node == BGP_IPV4M_NODE | |
1145 | || vty->node == BGP_VPNV4_NODE | |
57b5b7ed | 1146 | || vty->node == BGP_IPV6_NODE |
1147 | || vty->node == BGP_IPV6M_NODE) | |
718e3744 | 1148 | vty->node = BGP_NODE; |
1149 | return CMD_SUCCESS; | |
1150 | } | |
1151 | ||
1152 | DEFUNSH (VTYSH_ZEBRA, | |
1153 | vtysh_exit_zebra, | |
1154 | vtysh_exit_zebra_cmd, | |
1155 | "exit", | |
1156 | "Exit current mode and down to previous mode\n") | |
1157 | { | |
1158 | return vtysh_exit (vty); | |
1159 | } | |
1160 | ||
1161 | ALIAS (vtysh_exit_zebra, | |
1162 | vtysh_quit_zebra_cmd, | |
1163 | "quit", | |
1164 | "Exit current mode and down to previous mode\n") | |
1165 | ||
1166 | DEFUNSH (VTYSH_RIPD, | |
1167 | vtysh_exit_ripd, | |
1168 | vtysh_exit_ripd_cmd, | |
1169 | "exit", | |
1170 | "Exit current mode and down to previous mode\n") | |
1171 | { | |
1172 | return vtysh_exit (vty); | |
1173 | } | |
1174 | ||
1175 | ALIAS (vtysh_exit_ripd, | |
1176 | vtysh_quit_ripd_cmd, | |
1177 | "quit", | |
1178 | "Exit current mode and down to previous mode\n") | |
1179 | ||
68980084 | 1180 | DEFUNSH (VTYSH_RIPNGD, |
b094d260 | 1181 | vtysh_exit_ripngd, |
1182 | vtysh_exit_ripngd_cmd, | |
1183 | "exit", | |
1184 | "Exit current mode and down to previous mode\n") | |
68980084 | 1185 | { |
1186 | return vtysh_exit (vty); | |
1187 | } | |
1188 | ||
1189 | ALIAS (vtysh_exit_ripngd, | |
1190 | vtysh_quit_ripngd_cmd, | |
1191 | "quit", | |
1192 | "Exit current mode and down to previous mode\n") | |
1193 | ||
718e3744 | 1194 | DEFUNSH (VTYSH_RMAP, |
1195 | vtysh_exit_rmap, | |
1196 | vtysh_exit_rmap_cmd, | |
1197 | "exit", | |
1198 | "Exit current mode and down to previous mode\n") | |
1199 | { | |
1200 | return vtysh_exit (vty); | |
1201 | } | |
1202 | ||
1203 | ALIAS (vtysh_exit_rmap, | |
1204 | vtysh_quit_rmap_cmd, | |
1205 | "quit", | |
1206 | "Exit current mode and down to previous mode\n") | |
1207 | ||
1208 | DEFUNSH (VTYSH_BGPD, | |
1209 | vtysh_exit_bgpd, | |
1210 | vtysh_exit_bgpd_cmd, | |
1211 | "exit", | |
1212 | "Exit current mode and down to previous mode\n") | |
1213 | { | |
1214 | return vtysh_exit (vty); | |
1215 | } | |
1216 | ||
1217 | ALIAS (vtysh_exit_bgpd, | |
1218 | vtysh_quit_bgpd_cmd, | |
1219 | "quit", | |
1220 | "Exit current mode and down to previous mode\n") | |
1221 | ||
1222 | DEFUNSH (VTYSH_OSPFD, | |
1223 | vtysh_exit_ospfd, | |
1224 | vtysh_exit_ospfd_cmd, | |
1225 | "exit", | |
1226 | "Exit current mode and down to previous mode\n") | |
1227 | { | |
1228 | return vtysh_exit (vty); | |
1229 | } | |
1230 | ||
1231 | ALIAS (vtysh_exit_ospfd, | |
1232 | vtysh_quit_ospfd_cmd, | |
1233 | "quit", | |
1234 | "Exit current mode and down to previous mode\n") | |
1235 | ||
68980084 | 1236 | DEFUNSH (VTYSH_OSPF6D, |
b094d260 | 1237 | vtysh_exit_ospf6d, |
1238 | vtysh_exit_ospf6d_cmd, | |
1239 | "exit", | |
1240 | "Exit current mode and down to previous mode\n") | |
68980084 | 1241 | { |
1242 | return vtysh_exit (vty); | |
1243 | } | |
1244 | ||
1245 | ALIAS (vtysh_exit_ospf6d, | |
1246 | vtysh_quit_ospf6d_cmd, | |
1247 | "quit", | |
1248 | "Exit current mode and down to previous mode\n") | |
1249 | ||
c25e458a | 1250 | DEFUNSH (VTYSH_ISISD, |
b094d260 | 1251 | vtysh_exit_isisd, |
1252 | vtysh_exit_isisd_cmd, | |
1253 | "exit", | |
1254 | "Exit current mode and down to previous mode\n") | |
c25e458a | 1255 | { |
1256 | return vtysh_exit (vty); | |
1257 | } | |
1258 | ||
1259 | ALIAS (vtysh_exit_isisd, | |
1260 | vtysh_quit_isisd_cmd, | |
1261 | "quit", | |
1262 | "Exit current mode and down to previous mode\n") | |
1263 | ||
e7168df4 | 1264 | DEFUNSH (VTYSH_ALL, |
1265 | vtysh_exit_line_vty, | |
1266 | vtysh_exit_line_vty_cmd, | |
1267 | "exit", | |
1268 | "Exit current mode and down to previous mode\n") | |
1269 | { | |
1270 | return vtysh_exit (vty); | |
1271 | } | |
1272 | ||
1273 | ALIAS (vtysh_exit_line_vty, | |
1274 | vtysh_quit_line_vty_cmd, | |
1275 | "quit", | |
1276 | "Exit current mode and down to previous mode\n") | |
1277 | ||
95e735b5 | 1278 | DEFUNSH (VTYSH_INTERFACE, |
718e3744 | 1279 | vtysh_interface, |
1280 | vtysh_interface_cmd, | |
1281 | "interface IFNAME", | |
1282 | "Select an interface to configure\n" | |
1283 | "Interface's name\n") | |
1284 | { | |
1285 | vty->node = INTERFACE_NODE; | |
1286 | return CMD_SUCCESS; | |
1287 | } | |
1288 | ||
95e735b5 | 1289 | /* TODO Implement "no interface command in isisd. */ |
32d2463c | 1290 | DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D, |
1291 | vtysh_no_interface_cmd, | |
1292 | "no interface IFNAME", | |
1293 | NO_STR | |
1294 | "Delete a pseudo interface's configuration\n" | |
1295 | "Interface's name\n") | |
1296 | ||
95e735b5 | 1297 | /* TODO Implement interface description commands in ripngd, ospf6d |
1298 | * and isisd. */ | |
338a9916 | 1299 | DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD, |
1300 | interface_desc_cmd, | |
1301 | "description .LINE", | |
1302 | "Interface specific description\n" | |
1303 | "Characters describing this interface\n") | |
464dc8da | 1304 | |
1305 | DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD, | |
1306 | no_interface_desc_cmd, | |
1307 | "no description", | |
1308 | NO_STR | |
1309 | "Interface specific description\n") | |
338a9916 | 1310 | |
95e735b5 | 1311 | DEFUNSH (VTYSH_INTERFACE, |
718e3744 | 1312 | vtysh_exit_interface, |
1313 | vtysh_exit_interface_cmd, | |
1314 | "exit", | |
1315 | "Exit current mode and down to previous mode\n") | |
1316 | { | |
1317 | return vtysh_exit (vty); | |
1318 | } | |
1319 | ||
1320 | ALIAS (vtysh_exit_interface, | |
1321 | vtysh_quit_interface_cmd, | |
1322 | "quit", | |
1323 | "Exit current mode and down to previous mode\n") | |
1324 | ||
362b4031 PJ |
1325 | /* Memory */ |
1326 | DEFUN (vtysh_show_memory, | |
1327 | vtysh_show_memory_cmd, | |
1328 | "show memory", | |
1329 | SHOW_STR | |
1330 | "Memory statistics\n") | |
1331 | { | |
1332 | unsigned int i; | |
1333 | int ret = CMD_SUCCESS; | |
1334 | char line[] = "show memory\n"; | |
1335 | ||
1336 | for (i = 0; i < VTYSH_INDEX_MAX; i++) | |
1337 | if ( vtysh_client[i].fd >= 0 ) | |
1338 | { | |
1339 | fprintf (stdout, "Memory statistics for %s:\n", | |
1340 | vtysh_client[i].name); | |
1341 | ret = vtysh_client_execute (&vtysh_client[i], line, stdout); | |
1342 | fprintf (stdout,"\n"); | |
1343 | } | |
1344 | ||
1345 | return ret; | |
1346 | } | |
1347 | ||
95e735b5 | 1348 | /* Logging commands. */ |
dbf7d13d PJ |
1349 | DEFUN (vtysh_show_logging, |
1350 | vtysh_show_logging_cmd, | |
1351 | "show logging", | |
1352 | SHOW_STR | |
1353 | "Show current logging configuration\n") | |
1354 | { | |
1355 | unsigned int i; | |
1356 | int ret = CMD_SUCCESS; | |
1357 | char line[] = "show logging\n"; | |
1358 | ||
1359 | for (i = 0; i < VTYSH_INDEX_MAX; i++) | |
4150f33e PJ |
1360 | if ( vtysh_client[i].fd >= 0 ) |
1361 | { | |
1362 | fprintf (stdout,"Logging configuration for %s:\n", | |
1363 | vtysh_client[i].name); | |
1364 | ret = vtysh_client_execute (&vtysh_client[i], line, stdout); | |
1365 | fprintf (stdout,"\n"); | |
1366 | } | |
1367 | ||
dbf7d13d PJ |
1368 | return ret; |
1369 | } | |
1370 | ||
95e735b5 | 1371 | DEFUNSH (VTYSH_ALL, |
1372 | vtysh_log_stdout, | |
1373 | vtysh_log_stdout_cmd, | |
1374 | "log stdout", | |
1375 | "Logging control\n" | |
274a4a44 | 1376 | "Set stdout logging level\n") |
1377 | { | |
1378 | return CMD_SUCCESS; | |
1379 | } | |
1380 | ||
1381 | DEFUNSH (VTYSH_ALL, | |
1382 | vtysh_log_stdout_level, | |
1383 | vtysh_log_stdout_level_cmd, | |
1384 | "log stdout "LOG_LEVELS, | |
1385 | "Logging control\n" | |
1386 | "Set stdout logging level\n" | |
1387 | LOG_LEVEL_DESC) | |
95e735b5 | 1388 | { |
1389 | return CMD_SUCCESS; | |
1390 | } | |
1391 | ||
1392 | DEFUNSH (VTYSH_ALL, | |
1393 | no_vtysh_log_stdout, | |
1394 | no_vtysh_log_stdout_cmd, | |
274a4a44 | 1395 | "no log stdout [LEVEL]", |
95e735b5 | 1396 | NO_STR |
1397 | "Logging control\n" | |
274a4a44 | 1398 | "Cancel logging to stdout\n" |
1399 | "Logging level\n") | |
95e735b5 | 1400 | { |
1401 | return CMD_SUCCESS; | |
1402 | } | |
1403 | ||
1404 | DEFUNSH (VTYSH_ALL, | |
1405 | vtysh_log_file, | |
1406 | vtysh_log_file_cmd, | |
1407 | "log file FILENAME", | |
1408 | "Logging control\n" | |
1409 | "Logging to file\n" | |
1410 | "Logging filename\n") | |
1411 | { | |
1412 | return CMD_SUCCESS; | |
1413 | } | |
1414 | ||
274a4a44 | 1415 | DEFUNSH (VTYSH_ALL, |
1416 | vtysh_log_file_level, | |
1417 | vtysh_log_file_level_cmd, | |
1418 | "log file FILENAME "LOG_LEVELS, | |
1419 | "Logging control\n" | |
1420 | "Logging to file\n" | |
1421 | "Logging filename\n" | |
1422 | LOG_LEVEL_DESC) | |
1423 | { | |
1424 | return CMD_SUCCESS; | |
1425 | } | |
1426 | ||
95e735b5 | 1427 | DEFUNSH (VTYSH_ALL, |
1428 | no_vtysh_log_file, | |
1429 | no_vtysh_log_file_cmd, | |
1430 | "no log file [FILENAME]", | |
1431 | NO_STR | |
1432 | "Logging control\n" | |
1433 | "Cancel logging to file\n" | |
1434 | "Logging file name\n") | |
1435 | { | |
1436 | return CMD_SUCCESS; | |
1437 | } | |
1438 | ||
274a4a44 | 1439 | ALIAS_SH (VTYSH_ALL, |
1440 | no_vtysh_log_file, | |
1441 | no_vtysh_log_file_level_cmd, | |
1442 | "no log file FILENAME LEVEL", | |
1443 | NO_STR | |
1444 | "Logging control\n" | |
1445 | "Cancel logging to file\n" | |
1446 | "Logging file name\n" | |
1447 | "Logging level\n") | |
1448 | ||
1449 | DEFUNSH (VTYSH_ALL, | |
1450 | vtysh_log_monitor, | |
1451 | vtysh_log_monitor_cmd, | |
1452 | "log monitor", | |
1453 | "Logging control\n" | |
1454 | "Set terminal line (monitor) logging level\n") | |
1455 | { | |
1456 | return CMD_SUCCESS; | |
1457 | } | |
1458 | ||
1459 | DEFUNSH (VTYSH_ALL, | |
1460 | vtysh_log_monitor_level, | |
1461 | vtysh_log_monitor_level_cmd, | |
1462 | "log monitor "LOG_LEVELS, | |
1463 | "Logging control\n" | |
1464 | "Set terminal line (monitor) logging level\n" | |
1465 | LOG_LEVEL_DESC) | |
1466 | { | |
1467 | return CMD_SUCCESS; | |
1468 | } | |
1469 | ||
1470 | DEFUNSH (VTYSH_ALL, | |
1471 | no_vtysh_log_monitor, | |
1472 | no_vtysh_log_monitor_cmd, | |
1473 | "no log monitor [LEVEL]", | |
1474 | NO_STR | |
1475 | "Logging control\n" | |
1476 | "Disable terminal line (monitor) logging\n" | |
1477 | "Logging level\n") | |
1478 | { | |
1479 | return CMD_SUCCESS; | |
1480 | } | |
1481 | ||
95e735b5 | 1482 | DEFUNSH (VTYSH_ALL, |
1483 | vtysh_log_syslog, | |
1484 | vtysh_log_syslog_cmd, | |
1485 | "log syslog", | |
1486 | "Logging control\n" | |
274a4a44 | 1487 | "Set syslog logging level\n") |
1488 | { | |
1489 | return CMD_SUCCESS; | |
1490 | } | |
1491 | ||
1492 | DEFUNSH (VTYSH_ALL, | |
1493 | vtysh_log_syslog_level, | |
1494 | vtysh_log_syslog_level_cmd, | |
1495 | "log syslog "LOG_LEVELS, | |
1496 | "Logging control\n" | |
1497 | "Set syslog logging level\n" | |
1498 | LOG_LEVEL_DESC) | |
95e735b5 | 1499 | { |
1500 | return CMD_SUCCESS; | |
1501 | } | |
1502 | ||
1503 | DEFUNSH (VTYSH_ALL, | |
1504 | no_vtysh_log_syslog, | |
1505 | no_vtysh_log_syslog_cmd, | |
274a4a44 | 1506 | "no log syslog [LEVEL]", |
95e735b5 | 1507 | NO_STR |
1508 | "Logging control\n" | |
274a4a44 | 1509 | "Cancel logging to syslog\n" |
1510 | "Logging level\n") | |
95e735b5 | 1511 | { |
1512 | return CMD_SUCCESS; | |
1513 | } | |
1514 | ||
1515 | DEFUNSH (VTYSH_ALL, | |
274a4a44 | 1516 | vtysh_log_facility, |
1517 | vtysh_log_facility_cmd, | |
1518 | "log facility "LOG_FACILITIES, | |
95e735b5 | 1519 | "Logging control\n" |
274a4a44 | 1520 | "Facility parameter for syslog messages\n" |
1521 | LOG_FACILITY_DESC) | |
1522 | ||
95e735b5 | 1523 | { |
1524 | return CMD_SUCCESS; | |
1525 | } | |
1526 | ||
1527 | DEFUNSH (VTYSH_ALL, | |
274a4a44 | 1528 | no_vtysh_log_facility, |
1529 | no_vtysh_log_facility_cmd, | |
1530 | "no log facility [FACILITY]", | |
95e735b5 | 1531 | NO_STR |
1532 | "Logging control\n" | |
274a4a44 | 1533 | "Reset syslog facility to default (daemon)\n" |
1534 | "Syslog facility\n") | |
1535 | ||
1536 | { | |
1537 | return CMD_SUCCESS; | |
1538 | } | |
1539 | ||
1540 | DEFUNSH_DEPRECATED (VTYSH_ALL, | |
1541 | vtysh_log_trap, | |
1542 | vtysh_log_trap_cmd, | |
1543 | "log trap "LOG_LEVELS, | |
1544 | "Logging control\n" | |
1545 | "(Deprecated) Set logging level and default for all destinations\n" | |
1546 | LOG_LEVEL_DESC) | |
1547 | ||
1548 | { | |
1549 | return CMD_SUCCESS; | |
1550 | } | |
1551 | ||
1552 | DEFUNSH_DEPRECATED (VTYSH_ALL, | |
1553 | no_vtysh_log_trap, | |
1554 | no_vtysh_log_trap_cmd, | |
1555 | "no log trap [LEVEL]", | |
1556 | NO_STR | |
1557 | "Logging control\n" | |
1558 | "Permit all logging information\n" | |
1559 | "Logging level\n") | |
95e735b5 | 1560 | { |
1561 | return CMD_SUCCESS; | |
1562 | } | |
1563 | ||
1564 | DEFUNSH (VTYSH_ALL, | |
1565 | vtysh_log_record_priority, | |
1566 | vtysh_log_record_priority_cmd, | |
1567 | "log record-priority", | |
1568 | "Logging control\n" | |
1569 | "Log the priority of the message within the message\n") | |
1570 | { | |
1571 | return CMD_SUCCESS; | |
1572 | } | |
1573 | ||
1574 | DEFUNSH (VTYSH_ALL, | |
1575 | no_vtysh_log_record_priority, | |
1576 | no_vtysh_log_record_priority_cmd, | |
1577 | "no log record-priority", | |
1578 | NO_STR | |
1579 | "Logging control\n" | |
1580 | "Do not log the priority of the message within the message\n") | |
1581 | { | |
1582 | return CMD_SUCCESS; | |
1583 | } | |
1584 | ||
c749b722 AS |
1585 | DEFUNSH (VTYSH_ALL, |
1586 | vtysh_log_timestamp_precision, | |
1587 | vtysh_log_timestamp_precision_cmd, | |
1588 | "log timestamp precision <0-6>", | |
1589 | "Logging control\n" | |
1590 | "Timestamp configuration\n" | |
1591 | "Set the timestamp precision\n" | |
1592 | "Number of subsecond digits\n") | |
1593 | { | |
1594 | return CMD_SUCCESS; | |
1595 | } | |
1596 | ||
1597 | DEFUNSH (VTYSH_ALL, | |
1598 | no_vtysh_log_timestamp_precision, | |
1599 | no_vtysh_log_timestamp_precision_cmd, | |
1600 | "no log timestamp precision", | |
1601 | NO_STR | |
1602 | "Logging control\n" | |
1603 | "Timestamp configuration\n" | |
1604 | "Reset the timestamp precision to the default value of 0\n") | |
1605 | { | |
1606 | return CMD_SUCCESS; | |
1607 | } | |
1608 | ||
e7168df4 | 1609 | DEFUNSH (VTYSH_ALL, |
1610 | vtysh_service_password_encrypt, | |
1611 | vtysh_service_password_encrypt_cmd, | |
1612 | "service password-encryption", | |
1613 | "Set up miscellaneous service\n" | |
1614 | "Enable encrypted passwords\n") | |
1615 | { | |
1616 | return CMD_SUCCESS; | |
1617 | } | |
1618 | ||
1619 | DEFUNSH (VTYSH_ALL, | |
1620 | no_vtysh_service_password_encrypt, | |
1621 | no_vtysh_service_password_encrypt_cmd, | |
1622 | "no service password-encryption", | |
1623 | NO_STR | |
1624 | "Set up miscellaneous service\n" | |
1625 | "Enable encrypted passwords\n") | |
1626 | { | |
1627 | return CMD_SUCCESS; | |
1628 | } | |
1629 | ||
1630 | DEFUNSH (VTYSH_ALL, | |
1631 | vtysh_config_password, | |
1632 | vtysh_password_cmd, | |
1633 | "password (8|) WORD", | |
1634 | "Assign the terminal connection password\n" | |
1635 | "Specifies a HIDDEN password will follow\n" | |
1636 | "dummy string \n" | |
1637 | "The HIDDEN line password string\n") | |
1638 | { | |
1639 | return CMD_SUCCESS; | |
1640 | } | |
1641 | ||
1642 | DEFUNSH (VTYSH_ALL, | |
1643 | vtysh_password_text, | |
1644 | vtysh_password_text_cmd, | |
1645 | "password LINE", | |
1646 | "Assign the terminal connection password\n" | |
1647 | "The UNENCRYPTED (cleartext) line password\n") | |
1648 | { | |
1649 | return CMD_SUCCESS; | |
1650 | } | |
1651 | ||
1652 | DEFUNSH (VTYSH_ALL, | |
1653 | vtysh_config_enable_password, | |
1654 | vtysh_enable_password_cmd, | |
1655 | "enable password (8|) WORD", | |
1656 | "Modify enable password parameters\n" | |
1657 | "Assign the privileged level password\n" | |
1658 | "Specifies a HIDDEN password will follow\n" | |
1659 | "dummy string \n" | |
1660 | "The HIDDEN 'enable' password string\n") | |
1661 | { | |
1662 | return CMD_SUCCESS; | |
1663 | } | |
1664 | ||
1665 | DEFUNSH (VTYSH_ALL, | |
1666 | vtysh_enable_password_text, | |
1667 | vtysh_enable_password_text_cmd, | |
1668 | "enable password LINE", | |
1669 | "Modify enable password parameters\n" | |
1670 | "Assign the privileged level password\n" | |
1671 | "The UNENCRYPTED (cleartext) 'enable' password\n") | |
1672 | { | |
1673 | return CMD_SUCCESS; | |
1674 | } | |
1675 | ||
1676 | DEFUNSH (VTYSH_ALL, | |
1677 | no_vtysh_config_enable_password, | |
1678 | no_vtysh_enable_password_cmd, | |
1679 | "no enable password", | |
1680 | NO_STR | |
1681 | "Modify enable password parameters\n" | |
1682 | "Assign the privileged level password\n") | |
1683 | { | |
1684 | return CMD_SUCCESS; | |
1685 | } | |
1686 | ||
718e3744 | 1687 | DEFUN (vtysh_write_terminal, |
1688 | vtysh_write_terminal_cmd, | |
1689 | "write terminal", | |
1690 | "Write running configuration to memory, network, or terminal\n" | |
1691 | "Write to terminal\n") | |
1692 | { | |
b1aa147d | 1693 | u_int i; |
718e3744 | 1694 | int ret; |
1695 | char line[] = "write terminal\n"; | |
1696 | FILE *fp = NULL; | |
1697 | ||
1698 | if (vtysh_pager_name) | |
1699 | { | |
4fc01e67 | 1700 | fp = popen (vtysh_pager_name, "w"); |
718e3744 | 1701 | if (fp == NULL) |
1702 | { | |
1703 | perror ("popen"); | |
1704 | exit (1); | |
1705 | } | |
1706 | } | |
1707 | else | |
1708 | fp = stdout; | |
1709 | ||
1710 | vty_out (vty, "Building configuration...%s", VTY_NEWLINE); | |
1711 | vty_out (vty, "%sCurrent configuration:%s", VTY_NEWLINE, | |
1712 | VTY_NEWLINE); | |
e7168df4 | 1713 | vty_out (vty, "!%s", VTY_NEWLINE); |
718e3744 | 1714 | |
b1aa147d | 1715 | for (i = 0; i < VTYSH_INDEX_MAX; i++) |
1716 | ret = vtysh_client_config (&vtysh_client[i], line); | |
718e3744 | 1717 | |
e7168df4 | 1718 | /* Integrate vtysh specific configuration. */ |
1719 | vtysh_config_write (); | |
1720 | ||
718e3744 | 1721 | vtysh_config_dump (fp); |
1722 | ||
8454b056 PJ |
1723 | vty_out (vty, "end%s", VTY_NEWLINE); |
1724 | ||
718e3744 | 1725 | if (vtysh_pager_name && fp) |
1726 | { | |
1727 | fflush (fp); | |
1728 | if (pclose (fp) == -1) | |
1729 | { | |
1730 | perror ("pclose"); | |
1731 | exit (1); | |
1732 | } | |
1733 | fp = NULL; | |
1734 | } | |
1735 | ||
1736 | return CMD_SUCCESS; | |
1737 | } | |
1738 | ||
e7168df4 | 1739 | DEFUN (vtysh_integrated_config, |
1740 | vtysh_integrated_config_cmd, | |
1741 | "service integrated-vtysh-config", | |
1742 | "Set up miscellaneous service\n" | |
1743 | "Write configuration into integrated file\n") | |
4fc01e67 | 1744 | { |
e7168df4 | 1745 | vtysh_writeconfig_integrated = 1; |
1746 | return CMD_SUCCESS; | |
4fc01e67 | 1747 | } |
1748 | ||
e7168df4 | 1749 | DEFUN (no_vtysh_integrated_config, |
1750 | no_vtysh_integrated_config_cmd, | |
1751 | "no service integrated-vtysh-config", | |
1752 | NO_STR | |
1753 | "Set up miscellaneous service\n" | |
1754 | "Write configuration into integrated file\n") | |
4fc01e67 | 1755 | { |
e7168df4 | 1756 | vtysh_writeconfig_integrated = 0; |
1757 | return CMD_SUCCESS; | |
4fc01e67 | 1758 | } |
1759 | ||
274a4a44 | 1760 | static int |
1761 | write_config_integrated(void) | |
718e3744 | 1762 | { |
b1aa147d | 1763 | u_int i; |
718e3744 | 1764 | int ret; |
718e3744 | 1765 | char line[] = "write terminal\n"; |
1766 | FILE *fp; | |
1767 | char *integrate_sav = NULL; | |
1768 | ||
95e735b5 | 1769 | integrate_sav = malloc (strlen (integrate_default) + |
1770 | strlen (CONF_BACKUP_EXT) + 1); | |
718e3744 | 1771 | strcpy (integrate_sav, integrate_default); |
1772 | strcat (integrate_sav, CONF_BACKUP_EXT); | |
1773 | ||
4fc01e67 | 1774 | fprintf (stdout,"Building Configuration...\n"); |
718e3744 | 1775 | |
95e735b5 | 1776 | /* Move current configuration file to backup config file. */ |
718e3744 | 1777 | unlink (integrate_sav); |
1778 | rename (integrate_default, integrate_sav); | |
95e735b5 | 1779 | free (integrate_sav); |
4fc01e67 | 1780 | |
718e3744 | 1781 | fp = fopen (integrate_default, "w"); |
1782 | if (fp == NULL) | |
1783 | { | |
95e735b5 | 1784 | fprintf (stdout,"%% Can't open configuration file %s.\n", |
1785 | integrate_default); | |
718e3744 | 1786 | return CMD_SUCCESS; |
1787 | } | |
718e3744 | 1788 | |
b1aa147d | 1789 | for (i = 0; i < VTYSH_INDEX_MAX; i++) |
1790 | ret = vtysh_client_config (&vtysh_client[i], line); | |
718e3744 | 1791 | |
1792 | vtysh_config_dump (fp); | |
1793 | ||
1794 | fclose (fp); | |
1795 | ||
aa593d5e | 1796 | if (chmod (integrate_default, CONFIGFILE_MASK) != 0) |
1797 | { | |
1798 | fprintf (stdout,"%% Can't chmod configuration file %s: %s (%d)\n", | |
6099b3b5 | 1799 | integrate_default, safe_strerror(errno), errno); |
aa593d5e | 1800 | return CMD_WARNING; |
1801 | } | |
1802 | ||
4fc01e67 | 1803 | fprintf(stdout,"Integrated configuration saved to %s\n",integrate_default); |
1804 | ||
1805 | fprintf (stdout,"[OK]\n"); | |
1806 | ||
718e3744 | 1807 | return CMD_SUCCESS; |
1808 | } | |
1809 | ||
4fc01e67 | 1810 | DEFUN (vtysh_write_memory, |
1811 | vtysh_write_memory_cmd, | |
1812 | "write memory", | |
1813 | "Write running configuration to memory, network, or terminal\n" | |
1814 | "Write configuration to the file (same as write file)\n") | |
1815 | { | |
dfc0d9ba | 1816 | int ret = CMD_SUCCESS; |
4fc01e67 | 1817 | char line[] = "write memory\n"; |
b1aa147d | 1818 | u_int i; |
4fc01e67 | 1819 | |
e7168df4 | 1820 | /* If integrated Quagga.conf explicitely set. */ |
1821 | if (vtysh_writeconfig_integrated) | |
1822 | return write_config_integrated(); | |
4fc01e67 | 1823 | |
1824 | fprintf (stdout,"Building Configuration...\n"); | |
1825 | ||
b1aa147d | 1826 | for (i = 0; i < VTYSH_INDEX_MAX; i++) |
1827 | ret = vtysh_client_execute (&vtysh_client[i], line, stdout); | |
e7168df4 | 1828 | |
4fc01e67 | 1829 | fprintf (stdout,"[OK]\n"); |
1830 | ||
dfc0d9ba | 1831 | return ret; |
4fc01e67 | 1832 | } |
1833 | ||
718e3744 | 1834 | ALIAS (vtysh_write_memory, |
1835 | vtysh_copy_runningconfig_startupconfig_cmd, | |
1836 | "copy running-config startup-config", | |
1837 | "Copy from one file to another\n" | |
1838 | "Copy from current system configuration\n" | |
1839 | "Copy to startup configuration\n") | |
1840 | ||
1841 | ALIAS (vtysh_write_memory, | |
1842 | vtysh_write_file_cmd, | |
1843 | "write file", | |
1844 | "Write running configuration to memory, network, or terminal\n" | |
1845 | "Write configuration to the file (same as write memory)\n") | |
1846 | ||
4a6e2257 | 1847 | ALIAS (vtysh_write_memory, |
1848 | vtysh_write_cmd, | |
1849 | "write", | |
1850 | "Write running configuration to memory, network, or terminal\n") | |
1851 | ||
718e3744 | 1852 | ALIAS (vtysh_write_terminal, |
1853 | vtysh_show_running_config_cmd, | |
1854 | "show running-config", | |
1855 | SHOW_STR | |
1856 | "Current operating configuration\n") | |
b094d260 | 1857 | |
34553cc3 | 1858 | DEFUN (vtysh_terminal_length, |
1859 | vtysh_terminal_length_cmd, | |
1860 | "terminal length <0-512>", | |
1861 | "Set terminal line parameters\n" | |
1862 | "Set number of lines on a screen\n" | |
1863 | "Number of lines on screen (0 for no pausing)\n") | |
1864 | { | |
1865 | int lines; | |
1866 | char *endptr = NULL; | |
1867 | char default_pager[10]; | |
1868 | ||
1869 | lines = strtol (argv[0], &endptr, 10); | |
1870 | if (lines < 0 || lines > 512 || *endptr != '\0') | |
1871 | { | |
1872 | vty_out (vty, "length is malformed%s", VTY_NEWLINE); | |
1873 | return CMD_WARNING; | |
1874 | } | |
1875 | ||
1876 | if (vtysh_pager_name) | |
1877 | { | |
1878 | free (vtysh_pager_name); | |
1879 | vtysh_pager_name = NULL; | |
1880 | } | |
1881 | ||
1882 | if (lines != 0) | |
1883 | { | |
1884 | snprintf(default_pager, 10, "more -%i", lines); | |
1885 | vtysh_pager_name = strdup (default_pager); | |
1886 | } | |
1887 | ||
1888 | return CMD_SUCCESS; | |
1889 | } | |
1890 | ||
1891 | DEFUN (vtysh_terminal_no_length, | |
1892 | vtysh_terminal_no_length_cmd, | |
1893 | "terminal no length", | |
1894 | "Set terminal line parameters\n" | |
1895 | NO_STR | |
1896 | "Set number of lines on a screen\n") | |
1897 | { | |
1898 | if (vtysh_pager_name) | |
1899 | { | |
1900 | free (vtysh_pager_name); | |
1901 | vtysh_pager_name = NULL; | |
1902 | } | |
1903 | ||
1904 | vtysh_pager_init(); | |
1905 | return CMD_SUCCESS; | |
1906 | } | |
1907 | ||
f2799e69 | 1908 | DEFUN (vtysh_show_daemons, |
1909 | vtysh_show_daemons_cmd, | |
1910 | "show daemons", | |
e7168df4 | 1911 | SHOW_STR |
1912 | "Show list of running daemons\n") | |
1913 | { | |
b1aa147d | 1914 | u_int i; |
1915 | ||
1916 | for (i = 0; i < VTYSH_INDEX_MAX; i++) | |
1917 | if ( vtysh_client[i].fd >= 0 ) | |
1918 | vty_out(vty, " %s", vtysh_client[i].name); | |
e7168df4 | 1919 | vty_out(vty, "%s", VTY_NEWLINE); |
1920 | ||
1921 | return CMD_SUCCESS; | |
1922 | } | |
1923 | ||
718e3744 | 1924 | /* Execute command in child process. */ |
274a4a44 | 1925 | static int |
5862ff52 | 1926 | execute_command (const char *command, int argc, const char *arg1, |
1927 | const char *arg2) | |
718e3744 | 1928 | { |
1929 | int ret; | |
1930 | pid_t pid; | |
1931 | int status; | |
1932 | ||
1933 | /* Call fork(). */ | |
1934 | pid = fork (); | |
1935 | ||
1936 | if (pid < 0) | |
1937 | { | |
1938 | /* Failure of fork(). */ | |
6099b3b5 | 1939 | fprintf (stderr, "Can't fork: %s\n", safe_strerror (errno)); |
718e3744 | 1940 | exit (1); |
1941 | } | |
1942 | else if (pid == 0) | |
1943 | { | |
1944 | /* This is child process. */ | |
1945 | switch (argc) | |
1946 | { | |
1947 | case 0: | |
fa2b17e3 | 1948 | ret = execlp (command, command, (const char *)NULL); |
718e3744 | 1949 | break; |
1950 | case 1: | |
fa2b17e3 | 1951 | ret = execlp (command, command, arg1, (const char *)NULL); |
718e3744 | 1952 | break; |
1953 | case 2: | |
fa2b17e3 | 1954 | ret = execlp (command, command, arg1, arg2, (const char *)NULL); |
718e3744 | 1955 | break; |
1956 | } | |
1957 | ||
1958 | /* When execlp suceed, this part is not executed. */ | |
6099b3b5 | 1959 | fprintf (stderr, "Can't execute %s: %s\n", command, safe_strerror (errno)); |
718e3744 | 1960 | exit (1); |
1961 | } | |
1962 | else | |
1963 | { | |
1964 | /* This is parent. */ | |
1965 | execute_flag = 1; | |
1966 | ret = wait4 (pid, &status, 0, NULL); | |
1967 | execute_flag = 0; | |
1968 | } | |
1969 | return 0; | |
1970 | } | |
1971 | ||
1972 | DEFUN (vtysh_ping, | |
1973 | vtysh_ping_cmd, | |
1974 | "ping WORD", | |
4eeccf18 | 1975 | "Send echo messages\n" |
718e3744 | 1976 | "Ping destination address or hostname\n") |
1977 | { | |
1978 | execute_command ("ping", 1, argv[0], NULL); | |
1979 | return CMD_SUCCESS; | |
1980 | } | |
1981 | ||
4eeccf18 | 1982 | ALIAS (vtysh_ping, |
1983 | vtysh_ping_ip_cmd, | |
1984 | "ping ip WORD", | |
1985 | "Send echo messages\n" | |
1986 | "IP echo\n" | |
1987 | "Ping destination address or hostname\n") | |
1988 | ||
718e3744 | 1989 | DEFUN (vtysh_traceroute, |
1990 | vtysh_traceroute_cmd, | |
1991 | "traceroute WORD", | |
1992 | "Trace route to destination\n" | |
1993 | "Trace route to destination address or hostname\n") | |
1994 | { | |
1995 | execute_command ("traceroute", 1, argv[0], NULL); | |
1996 | return CMD_SUCCESS; | |
1997 | } | |
1998 | ||
4eeccf18 | 1999 | ALIAS (vtysh_traceroute, |
2000 | vtysh_traceroute_ip_cmd, | |
2001 | "traceroute ip WORD", | |
2002 | "Trace route to destination\n" | |
2003 | "IP trace\n" | |
2004 | "Trace route to destination address or hostname\n") | |
2005 | ||
2006 | #ifdef HAVE_IPV6 | |
2007 | DEFUN (vtysh_ping6, | |
2008 | vtysh_ping6_cmd, | |
2009 | "ping ipv6 WORD", | |
2010 | "Send echo messages\n" | |
2011 | "IPv6 echo\n" | |
2012 | "Ping destination address or hostname\n") | |
2013 | { | |
2014 | execute_command ("ping6", 1, argv[0], NULL); | |
2015 | return CMD_SUCCESS; | |
2016 | } | |
2017 | ||
2018 | DEFUN (vtysh_traceroute6, | |
2019 | vtysh_traceroute6_cmd, | |
2020 | "traceroute ipv6 WORD", | |
2021 | "Trace route to destination\n" | |
2022 | "IPv6 trace\n" | |
2023 | "Trace route to destination address or hostname\n") | |
2024 | { | |
2025 | execute_command ("traceroute6", 1, argv[0], NULL); | |
2026 | return CMD_SUCCESS; | |
2027 | } | |
2028 | #endif | |
2029 | ||
718e3744 | 2030 | DEFUN (vtysh_telnet, |
2031 | vtysh_telnet_cmd, | |
2032 | "telnet WORD", | |
2033 | "Open a telnet connection\n" | |
2034 | "IP address or hostname of a remote system\n") | |
2035 | { | |
2036 | execute_command ("telnet", 1, argv[0], NULL); | |
2037 | return CMD_SUCCESS; | |
2038 | } | |
2039 | ||
2040 | DEFUN (vtysh_telnet_port, | |
2041 | vtysh_telnet_port_cmd, | |
2042 | "telnet WORD PORT", | |
2043 | "Open a telnet connection\n" | |
2044 | "IP address or hostname of a remote system\n" | |
2045 | "TCP Port number\n") | |
2046 | { | |
2047 | execute_command ("telnet", 2, argv[0], argv[1]); | |
2048 | return CMD_SUCCESS; | |
2049 | } | |
2050 | ||
5087df56 | 2051 | DEFUN (vtysh_ssh, |
2052 | vtysh_ssh_cmd, | |
2053 | "ssh WORD", | |
2054 | "Open an ssh connection\n" | |
2055 | "[user@]host\n") | |
2056 | { | |
2057 | execute_command ("ssh", 1, argv[0], NULL); | |
2058 | return CMD_SUCCESS; | |
2059 | } | |
2060 | ||
718e3744 | 2061 | DEFUN (vtysh_start_shell, |
2062 | vtysh_start_shell_cmd, | |
2063 | "start-shell", | |
2064 | "Start UNIX shell\n") | |
2065 | { | |
2066 | execute_command ("sh", 0, NULL, NULL); | |
2067 | return CMD_SUCCESS; | |
2068 | } | |
2069 | ||
2070 | DEFUN (vtysh_start_bash, | |
2071 | vtysh_start_bash_cmd, | |
2072 | "start-shell bash", | |
2073 | "Start UNIX shell\n" | |
2074 | "Start bash\n") | |
2075 | { | |
2076 | execute_command ("bash", 0, NULL, NULL); | |
2077 | return CMD_SUCCESS; | |
2078 | } | |
2079 | ||
2080 | DEFUN (vtysh_start_zsh, | |
2081 | vtysh_start_zsh_cmd, | |
2082 | "start-shell zsh", | |
2083 | "Start UNIX shell\n" | |
2084 | "Start Z shell\n") | |
2085 | { | |
2086 | execute_command ("zsh", 0, NULL, NULL); | |
2087 | return CMD_SUCCESS; | |
2088 | } | |
b094d260 | 2089 | |
274a4a44 | 2090 | static void |
718e3744 | 2091 | vtysh_install_default (enum node_type node) |
2092 | { | |
2093 | install_element (node, &config_list_cmd); | |
2094 | } | |
2095 | ||
2096 | /* Making connection to protocol daemon. */ | |
274a4a44 | 2097 | static int |
b1aa147d | 2098 | vtysh_connect (struct vtysh_client *vclient) |
718e3744 | 2099 | { |
2100 | int ret; | |
2101 | int sock, len; | |
2102 | struct sockaddr_un addr; | |
2103 | struct stat s_stat; | |
718e3744 | 2104 | |
718e3744 | 2105 | /* Stat socket to see if we have permission to access it. */ |
b1aa147d | 2106 | ret = stat (vclient->path, &s_stat); |
718e3744 | 2107 | if (ret < 0 && errno != ENOENT) |
2108 | { | |
2109 | fprintf (stderr, "vtysh_connect(%s): stat = %s\n", | |
b1aa147d | 2110 | vclient->path, safe_strerror(errno)); |
718e3744 | 2111 | exit(1); |
2112 | } | |
2113 | ||
2114 | if (ret >= 0) | |
2115 | { | |
2116 | if (! S_ISSOCK(s_stat.st_mode)) | |
2117 | { | |
2118 | fprintf (stderr, "vtysh_connect(%s): Not a socket\n", | |
b1aa147d | 2119 | vclient->path); |
718e3744 | 2120 | exit (1); |
2121 | } | |
2122 | ||
718e3744 | 2123 | } |
2124 | ||
2125 | sock = socket (AF_UNIX, SOCK_STREAM, 0); | |
2126 | if (sock < 0) | |
2127 | { | |
2128 | #ifdef DEBUG | |
b1aa147d | 2129 | fprintf(stderr, "vtysh_connect(%s): socket = %s\n", vclient->path, |
6099b3b5 | 2130 | safe_strerror(errno)); |
718e3744 | 2131 | #endif /* DEBUG */ |
2132 | return -1; | |
2133 | } | |
2134 | ||
2135 | memset (&addr, 0, sizeof (struct sockaddr_un)); | |
2136 | addr.sun_family = AF_UNIX; | |
b1aa147d | 2137 | strncpy (addr.sun_path, vclient->path, strlen (vclient->path)); |
6f0e3f6e | 2138 | #ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN |
718e3744 | 2139 | len = addr.sun_len = SUN_LEN(&addr); |
2140 | #else | |
2141 | len = sizeof (addr.sun_family) + strlen (addr.sun_path); | |
6f0e3f6e | 2142 | #endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */ |
718e3744 | 2143 | |
2144 | ret = connect (sock, (struct sockaddr *) &addr, len); | |
2145 | if (ret < 0) | |
2146 | { | |
2147 | #ifdef DEBUG | |
b1aa147d | 2148 | fprintf(stderr, "vtysh_connect(%s): connect = %s\n", vclient->path, |
6099b3b5 | 2149 | safe_strerror(errno)); |
718e3744 | 2150 | #endif /* DEBUG */ |
2151 | close (sock); | |
2152 | return -1; | |
2153 | } | |
2154 | vclient->fd = sock; | |
2155 | ||
2156 | return 0; | |
2157 | } | |
2158 | ||
f366ad31 AS |
2159 | int |
2160 | vtysh_connect_all(const char *daemon_name) | |
718e3744 | 2161 | { |
b1aa147d | 2162 | u_int i; |
f366ad31 AS |
2163 | int rc = 0; |
2164 | int matches = 0; | |
b1aa147d | 2165 | |
2166 | for (i = 0; i < VTYSH_INDEX_MAX; i++) | |
2167 | { | |
f366ad31 AS |
2168 | if (!daemon_name || !strcmp(daemon_name, vtysh_client[i].name)) |
2169 | { | |
2170 | matches++; | |
2171 | if (vtysh_connect(&vtysh_client[i]) == 0) | |
2172 | rc++; | |
2173 | /* We need direct access to ripd in vtysh_exit_ripd_only. */ | |
2174 | if (vtysh_client[i].flag == VTYSH_RIPD) | |
2175 | ripd_client = &vtysh_client[i]; | |
2176 | } | |
b1aa147d | 2177 | } |
f366ad31 AS |
2178 | if (!matches) |
2179 | fprintf(stderr, "Error: no daemons match name %s!\n", daemon_name); | |
2180 | return rc; | |
718e3744 | 2181 | } |
2182 | ||
95e735b5 | 2183 | /* To disable readline's filename completion. */ |
274a4a44 | 2184 | static char * |
dfc0d9ba | 2185 | vtysh_completion_entry_function (const char *ignore, int invoking_key) |
718e3744 | 2186 | { |
dfc0d9ba | 2187 | return NULL; |
718e3744 | 2188 | } |
2189 | ||
2190 | void | |
b1aa147d | 2191 | vtysh_readline_init (void) |
718e3744 | 2192 | { |
2193 | /* readline related settings. */ | |
53a6f932 | 2194 | rl_bind_key ('?', (Function *) vtysh_rl_describe); |
68980084 | 2195 | rl_completion_entry_function = vtysh_completion_entry_function; |
718e3744 | 2196 | rl_attempted_completion_function = (CPPFunction *)new_completion; |
2197 | /* do not append space after completion. It will be appended | |
95e735b5 | 2198 | * in new_completion() function explicitly. */ |
718e3744 | 2199 | rl_completion_append_character = '\0'; |
2200 | } | |
2201 | ||
2202 | char * | |
b1aa147d | 2203 | vtysh_prompt (void) |
718e3744 | 2204 | { |
f366ad31 | 2205 | static struct utsname names; |
718e3744 | 2206 | static char buf[100]; |
2207 | const char*hostname; | |
2208 | extern struct host host; | |
2209 | ||
2210 | hostname = host.name; | |
2211 | ||
2212 | if (!hostname) | |
2213 | { | |
f366ad31 AS |
2214 | if (!names.nodename[0]) |
2215 | uname (&names); | |
718e3744 | 2216 | hostname = names.nodename; |
2217 | } | |
2218 | ||
2219 | snprintf (buf, sizeof buf, cmd_prompt (vty->node), hostname); | |
2220 | ||
2221 | return buf; | |
2222 | } | |
2223 | ||
2224 | void | |
b1aa147d | 2225 | vtysh_init_vty (void) |
718e3744 | 2226 | { |
2227 | /* Make vty structure. */ | |
2228 | vty = vty_new (); | |
2229 | vty->type = VTY_SHELL; | |
2230 | vty->node = VIEW_NODE; | |
2231 | ||
2232 | /* Initialize commands. */ | |
2233 | cmd_init (0); | |
2234 | ||
2235 | /* Install nodes. */ | |
2236 | install_node (&bgp_node, NULL); | |
2237 | install_node (&rip_node, NULL); | |
2238 | install_node (&interface_node, NULL); | |
2239 | install_node (&rmap_node, NULL); | |
2240 | install_node (&zebra_node, NULL); | |
2241 | install_node (&bgp_vpnv4_node, NULL); | |
2242 | install_node (&bgp_ipv4_node, NULL); | |
2243 | install_node (&bgp_ipv4m_node, NULL); | |
2244 | /* #ifdef HAVE_IPV6 */ | |
2245 | install_node (&bgp_ipv6_node, NULL); | |
57b5b7ed | 2246 | install_node (&bgp_ipv6m_node, NULL); |
718e3744 | 2247 | /* #endif */ |
2248 | install_node (&ospf_node, NULL); | |
2249 | /* #ifdef HAVE_IPV6 */ | |
2250 | install_node (&ripng_node, NULL); | |
2251 | install_node (&ospf6_node, NULL); | |
2252 | /* #endif */ | |
2253 | install_node (&keychain_node, NULL); | |
2254 | install_node (&keychain_key_node, NULL); | |
c25e458a | 2255 | install_node (&isis_node, NULL); |
e7168df4 | 2256 | install_node (&vty_node, NULL); |
718e3744 | 2257 | |
2258 | vtysh_install_default (VIEW_NODE); | |
2259 | vtysh_install_default (ENABLE_NODE); | |
2260 | vtysh_install_default (CONFIG_NODE); | |
2261 | vtysh_install_default (BGP_NODE); | |
2262 | vtysh_install_default (RIP_NODE); | |
2263 | vtysh_install_default (INTERFACE_NODE); | |
2264 | vtysh_install_default (RMAP_NODE); | |
2265 | vtysh_install_default (ZEBRA_NODE); | |
2266 | vtysh_install_default (BGP_VPNV4_NODE); | |
2267 | vtysh_install_default (BGP_IPV4_NODE); | |
2268 | vtysh_install_default (BGP_IPV4M_NODE); | |
2269 | vtysh_install_default (BGP_IPV6_NODE); | |
57b5b7ed | 2270 | vtysh_install_default (BGP_IPV6M_NODE); |
718e3744 | 2271 | vtysh_install_default (OSPF_NODE); |
2272 | vtysh_install_default (RIPNG_NODE); | |
2273 | vtysh_install_default (OSPF6_NODE); | |
c25e458a | 2274 | vtysh_install_default (ISIS_NODE); |
718e3744 | 2275 | vtysh_install_default (KEYCHAIN_NODE); |
2276 | vtysh_install_default (KEYCHAIN_KEY_NODE); | |
e7168df4 | 2277 | vtysh_install_default (VTY_NODE); |
718e3744 | 2278 | |
2279 | install_element (VIEW_NODE, &vtysh_enable_cmd); | |
2280 | install_element (ENABLE_NODE, &vtysh_config_terminal_cmd); | |
2281 | install_element (ENABLE_NODE, &vtysh_disable_cmd); | |
2282 | ||
2283 | /* "exit" command. */ | |
2284 | install_element (VIEW_NODE, &vtysh_exit_all_cmd); | |
2285 | install_element (VIEW_NODE, &vtysh_quit_all_cmd); | |
2286 | install_element (CONFIG_NODE, &vtysh_exit_all_cmd); | |
2287 | /* install_element (CONFIG_NODE, &vtysh_quit_all_cmd); */ | |
2288 | install_element (ENABLE_NODE, &vtysh_exit_all_cmd); | |
2289 | install_element (ENABLE_NODE, &vtysh_quit_all_cmd); | |
2290 | install_element (RIP_NODE, &vtysh_exit_ripd_cmd); | |
2291 | install_element (RIP_NODE, &vtysh_quit_ripd_cmd); | |
68980084 | 2292 | install_element (RIPNG_NODE, &vtysh_exit_ripngd_cmd); |
2293 | install_element (RIPNG_NODE, &vtysh_quit_ripngd_cmd); | |
718e3744 | 2294 | install_element (OSPF_NODE, &vtysh_exit_ospfd_cmd); |
2295 | install_element (OSPF_NODE, &vtysh_quit_ospfd_cmd); | |
68980084 | 2296 | install_element (OSPF6_NODE, &vtysh_exit_ospf6d_cmd); |
2297 | install_element (OSPF6_NODE, &vtysh_quit_ospf6d_cmd); | |
718e3744 | 2298 | install_element (BGP_NODE, &vtysh_exit_bgpd_cmd); |
2299 | install_element (BGP_NODE, &vtysh_quit_bgpd_cmd); | |
2300 | install_element (BGP_VPNV4_NODE, &vtysh_exit_bgpd_cmd); | |
2301 | install_element (BGP_VPNV4_NODE, &vtysh_quit_bgpd_cmd); | |
2302 | install_element (BGP_IPV4_NODE, &vtysh_exit_bgpd_cmd); | |
2303 | install_element (BGP_IPV4_NODE, &vtysh_quit_bgpd_cmd); | |
2304 | install_element (BGP_IPV4M_NODE, &vtysh_exit_bgpd_cmd); | |
2305 | install_element (BGP_IPV4M_NODE, &vtysh_quit_bgpd_cmd); | |
2306 | install_element (BGP_IPV6_NODE, &vtysh_exit_bgpd_cmd); | |
2307 | install_element (BGP_IPV6_NODE, &vtysh_quit_bgpd_cmd); | |
57b5b7ed | 2308 | install_element (BGP_IPV6M_NODE, &vtysh_exit_bgpd_cmd); |
2309 | install_element (BGP_IPV6M_NODE, &vtysh_quit_bgpd_cmd); | |
c25e458a | 2310 | install_element (ISIS_NODE, &vtysh_exit_isisd_cmd); |
2311 | install_element (ISIS_NODE, &vtysh_quit_isisd_cmd); | |
718e3744 | 2312 | install_element (KEYCHAIN_NODE, &vtysh_exit_ripd_cmd); |
2313 | install_element (KEYCHAIN_NODE, &vtysh_quit_ripd_cmd); | |
2314 | install_element (KEYCHAIN_KEY_NODE, &vtysh_exit_ripd_cmd); | |
2315 | install_element (KEYCHAIN_KEY_NODE, &vtysh_quit_ripd_cmd); | |
2316 | install_element (RMAP_NODE, &vtysh_exit_rmap_cmd); | |
2317 | install_element (RMAP_NODE, &vtysh_quit_rmap_cmd); | |
e7168df4 | 2318 | install_element (VTY_NODE, &vtysh_exit_line_vty_cmd); |
2319 | install_element (VTY_NODE, &vtysh_quit_line_vty_cmd); | |
718e3744 | 2320 | |
2321 | /* "end" command. */ | |
2322 | install_element (CONFIG_NODE, &vtysh_end_all_cmd); | |
2323 | install_element (ENABLE_NODE, &vtysh_end_all_cmd); | |
2324 | install_element (RIP_NODE, &vtysh_end_all_cmd); | |
2325 | install_element (RIPNG_NODE, &vtysh_end_all_cmd); | |
2326 | install_element (OSPF_NODE, &vtysh_end_all_cmd); | |
2327 | install_element (OSPF6_NODE, &vtysh_end_all_cmd); | |
2328 | install_element (BGP_NODE, &vtysh_end_all_cmd); | |
2329 | install_element (BGP_IPV4_NODE, &vtysh_end_all_cmd); | |
2330 | install_element (BGP_IPV4M_NODE, &vtysh_end_all_cmd); | |
2331 | install_element (BGP_VPNV4_NODE, &vtysh_end_all_cmd); | |
2332 | install_element (BGP_IPV6_NODE, &vtysh_end_all_cmd); | |
57b5b7ed | 2333 | install_element (BGP_IPV6M_NODE, &vtysh_end_all_cmd); |
c25e458a | 2334 | install_element (ISIS_NODE, &vtysh_end_all_cmd); |
718e3744 | 2335 | install_element (KEYCHAIN_NODE, &vtysh_end_all_cmd); |
2336 | install_element (KEYCHAIN_KEY_NODE, &vtysh_end_all_cmd); | |
2337 | install_element (RMAP_NODE, &vtysh_end_all_cmd); | |
e7168df4 | 2338 | install_element (VTY_NODE, &vtysh_end_all_cmd); |
718e3744 | 2339 | |
338a9916 | 2340 | install_element (INTERFACE_NODE, &interface_desc_cmd); |
464dc8da | 2341 | install_element (INTERFACE_NODE, &no_interface_desc_cmd); |
718e3744 | 2342 | install_element (INTERFACE_NODE, &vtysh_end_all_cmd); |
2343 | install_element (INTERFACE_NODE, &vtysh_exit_interface_cmd); | |
2344 | install_element (INTERFACE_NODE, &vtysh_quit_interface_cmd); | |
2345 | install_element (CONFIG_NODE, &router_rip_cmd); | |
2346 | #ifdef HAVE_IPV6 | |
2347 | install_element (CONFIG_NODE, &router_ripng_cmd); | |
2348 | #endif | |
2349 | install_element (CONFIG_NODE, &router_ospf_cmd); | |
2350 | #ifdef HAVE_IPV6 | |
2351 | install_element (CONFIG_NODE, &router_ospf6_cmd); | |
2352 | #endif | |
c25e458a | 2353 | install_element (CONFIG_NODE, &router_isis_cmd); |
718e3744 | 2354 | install_element (CONFIG_NODE, &router_bgp_cmd); |
10895fd6 | 2355 | install_element (CONFIG_NODE, &router_bgp_view_cmd); |
718e3744 | 2356 | install_element (BGP_NODE, &address_family_vpnv4_cmd); |
2357 | install_element (BGP_NODE, &address_family_vpnv4_unicast_cmd); | |
2358 | install_element (BGP_NODE, &address_family_ipv4_unicast_cmd); | |
2359 | install_element (BGP_NODE, &address_family_ipv4_multicast_cmd); | |
2360 | #ifdef HAVE_IPV6 | |
2361 | install_element (BGP_NODE, &address_family_ipv6_cmd); | |
2362 | install_element (BGP_NODE, &address_family_ipv6_unicast_cmd); | |
2363 | #endif | |
2364 | install_element (BGP_VPNV4_NODE, &exit_address_family_cmd); | |
2365 | install_element (BGP_IPV4_NODE, &exit_address_family_cmd); | |
2366 | install_element (BGP_IPV4M_NODE, &exit_address_family_cmd); | |
2367 | install_element (BGP_IPV6_NODE, &exit_address_family_cmd); | |
57b5b7ed | 2368 | install_element (BGP_IPV6M_NODE, &exit_address_family_cmd); |
718e3744 | 2369 | install_element (CONFIG_NODE, &key_chain_cmd); |
2370 | install_element (CONFIG_NODE, &route_map_cmd); | |
e7168df4 | 2371 | install_element (CONFIG_NODE, &vtysh_line_vty_cmd); |
718e3744 | 2372 | install_element (KEYCHAIN_NODE, &key_cmd); |
2373 | install_element (KEYCHAIN_NODE, &key_chain_cmd); | |
2374 | install_element (KEYCHAIN_KEY_NODE, &key_chain_cmd); | |
2375 | install_element (CONFIG_NODE, &vtysh_interface_cmd); | |
32d2463c | 2376 | install_element (CONFIG_NODE, &vtysh_no_interface_cmd); |
718e3744 | 2377 | install_element (ENABLE_NODE, &vtysh_show_running_config_cmd); |
2378 | install_element (ENABLE_NODE, &vtysh_copy_runningconfig_startupconfig_cmd); | |
2379 | install_element (ENABLE_NODE, &vtysh_write_file_cmd); | |
4a6e2257 | 2380 | install_element (ENABLE_NODE, &vtysh_write_cmd); |
718e3744 | 2381 | |
95e735b5 | 2382 | /* "write terminal" command. */ |
718e3744 | 2383 | install_element (ENABLE_NODE, &vtysh_write_terminal_cmd); |
e7168df4 | 2384 | |
2385 | install_element (CONFIG_NODE, &vtysh_integrated_config_cmd); | |
2386 | install_element (CONFIG_NODE, &no_vtysh_integrated_config_cmd); | |
718e3744 | 2387 | |
95e735b5 | 2388 | /* "write memory" command. */ |
718e3744 | 2389 | install_element (ENABLE_NODE, &vtysh_write_memory_cmd); |
718e3744 | 2390 | |
34553cc3 | 2391 | install_element (VIEW_NODE, &vtysh_terminal_length_cmd); |
2392 | install_element (ENABLE_NODE, &vtysh_terminal_length_cmd); | |
2393 | install_element (VIEW_NODE, &vtysh_terminal_no_length_cmd); | |
2394 | install_element (ENABLE_NODE, &vtysh_terminal_no_length_cmd); | |
f2799e69 | 2395 | install_element (VIEW_NODE, &vtysh_show_daemons_cmd); |
2396 | install_element (ENABLE_NODE, &vtysh_show_daemons_cmd); | |
34553cc3 | 2397 | |
718e3744 | 2398 | install_element (VIEW_NODE, &vtysh_ping_cmd); |
4eeccf18 | 2399 | install_element (VIEW_NODE, &vtysh_ping_ip_cmd); |
718e3744 | 2400 | install_element (VIEW_NODE, &vtysh_traceroute_cmd); |
4eeccf18 | 2401 | install_element (VIEW_NODE, &vtysh_traceroute_ip_cmd); |
2402 | #ifdef HAVE_IPV6 | |
2403 | install_element (VIEW_NODE, &vtysh_ping6_cmd); | |
2404 | install_element (VIEW_NODE, &vtysh_traceroute6_cmd); | |
2405 | #endif | |
718e3744 | 2406 | install_element (VIEW_NODE, &vtysh_telnet_cmd); |
2407 | install_element (VIEW_NODE, &vtysh_telnet_port_cmd); | |
5087df56 | 2408 | install_element (VIEW_NODE, &vtysh_ssh_cmd); |
718e3744 | 2409 | install_element (ENABLE_NODE, &vtysh_ping_cmd); |
4eeccf18 | 2410 | install_element (ENABLE_NODE, &vtysh_ping_ip_cmd); |
718e3744 | 2411 | install_element (ENABLE_NODE, &vtysh_traceroute_cmd); |
4eeccf18 | 2412 | install_element (ENABLE_NODE, &vtysh_traceroute_ip_cmd); |
2413 | #ifdef HAVE_IPV6 | |
2414 | install_element (ENABLE_NODE, &vtysh_ping6_cmd); | |
2415 | install_element (ENABLE_NODE, &vtysh_traceroute6_cmd); | |
2416 | #endif | |
718e3744 | 2417 | install_element (ENABLE_NODE, &vtysh_telnet_cmd); |
2418 | install_element (ENABLE_NODE, &vtysh_telnet_port_cmd); | |
67e29abc | 2419 | install_element (ENABLE_NODE, &vtysh_ssh_cmd); |
718e3744 | 2420 | install_element (ENABLE_NODE, &vtysh_start_shell_cmd); |
2421 | install_element (ENABLE_NODE, &vtysh_start_bash_cmd); | |
2422 | install_element (ENABLE_NODE, &vtysh_start_zsh_cmd); | |
dbf7d13d | 2423 | |
362b4031 PJ |
2424 | install_element (VIEW_NODE, &vtysh_show_memory_cmd); |
2425 | install_element (ENABLE_NODE, &vtysh_show_memory_cmd); | |
2426 | ||
dbf7d13d PJ |
2427 | /* Logging */ |
2428 | install_element (ENABLE_NODE, &vtysh_show_logging_cmd); | |
2429 | install_element (VIEW_NODE, &vtysh_show_logging_cmd); | |
718e3744 | 2430 | install_element (CONFIG_NODE, &vtysh_log_stdout_cmd); |
274a4a44 | 2431 | install_element (CONFIG_NODE, &vtysh_log_stdout_level_cmd); |
718e3744 | 2432 | install_element (CONFIG_NODE, &no_vtysh_log_stdout_cmd); |
2433 | install_element (CONFIG_NODE, &vtysh_log_file_cmd); | |
274a4a44 | 2434 | install_element (CONFIG_NODE, &vtysh_log_file_level_cmd); |
718e3744 | 2435 | install_element (CONFIG_NODE, &no_vtysh_log_file_cmd); |
274a4a44 | 2436 | install_element (CONFIG_NODE, &no_vtysh_log_file_level_cmd); |
2437 | install_element (CONFIG_NODE, &vtysh_log_monitor_cmd); | |
2438 | install_element (CONFIG_NODE, &vtysh_log_monitor_level_cmd); | |
2439 | install_element (CONFIG_NODE, &no_vtysh_log_monitor_cmd); | |
718e3744 | 2440 | install_element (CONFIG_NODE, &vtysh_log_syslog_cmd); |
274a4a44 | 2441 | install_element (CONFIG_NODE, &vtysh_log_syslog_level_cmd); |
718e3744 | 2442 | install_element (CONFIG_NODE, &no_vtysh_log_syslog_cmd); |
2443 | install_element (CONFIG_NODE, &vtysh_log_trap_cmd); | |
2444 | install_element (CONFIG_NODE, &no_vtysh_log_trap_cmd); | |
274a4a44 | 2445 | install_element (CONFIG_NODE, &vtysh_log_facility_cmd); |
2446 | install_element (CONFIG_NODE, &no_vtysh_log_facility_cmd); | |
718e3744 | 2447 | install_element (CONFIG_NODE, &vtysh_log_record_priority_cmd); |
2448 | install_element (CONFIG_NODE, &no_vtysh_log_record_priority_cmd); | |
c749b722 AS |
2449 | install_element (CONFIG_NODE, &vtysh_log_timestamp_precision_cmd); |
2450 | install_element (CONFIG_NODE, &no_vtysh_log_timestamp_precision_cmd); | |
e7168df4 | 2451 | |
2452 | install_element (CONFIG_NODE, &vtysh_service_password_encrypt_cmd); | |
2453 | install_element (CONFIG_NODE, &no_vtysh_service_password_encrypt_cmd); | |
2454 | ||
2455 | install_element (CONFIG_NODE, &vtysh_password_cmd); | |
2456 | install_element (CONFIG_NODE, &vtysh_password_text_cmd); | |
2457 | install_element (CONFIG_NODE, &vtysh_enable_password_cmd); | |
2458 | install_element (CONFIG_NODE, &vtysh_enable_password_text_cmd); | |
2459 | install_element (CONFIG_NODE, &no_vtysh_enable_password_cmd); | |
2460 | ||
718e3744 | 2461 | } |