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