Line data Source code
1 : /* Zebra VTY functions
2 : * Copyright (C) 2002 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
18 : * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 : * Boston, MA 02111-1307, USA.
20 : */
21 :
22 : #include <zebra.h>
23 :
24 : #include "memory.h"
25 : #include "if.h"
26 : #include "prefix.h"
27 : #include "command.h"
28 : #include "table.h"
29 : #include "rib.h"
30 : #include "srcdest_table.h"
31 :
32 : #include "zebra/zserv.h"
33 :
34 : /* General fucntion for static route. */
35 : static int
36 4 : zebra_static_ipv4 (struct vty *vty, int add_cmd, const char *dest_str,
37 : const char *mask_str, const char *gate_str,
38 : const char *flag_str, const char *distance_str)
39 : {
40 : int ret;
41 : u_char distance;
42 : struct prefix p;
43 : struct in_addr gate;
44 : struct in_addr mask;
45 : const char *ifname;
46 4 : u_char flag = 0;
47 :
48 4 : ret = str2prefix (dest_str, &p);
49 4 : if (ret <= 0)
50 : {
51 0 : vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
52 0 : return CMD_WARNING;
53 : }
54 :
55 : /* Cisco like mask notation. */
56 4 : if (mask_str)
57 : {
58 0 : ret = inet_aton (mask_str, &mask);
59 0 : if (ret == 0)
60 : {
61 0 : vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
62 0 : return CMD_WARNING;
63 : }
64 0 : p.prefixlen = ip_masklen (mask);
65 : }
66 :
67 : /* Apply mask for given prefix. */
68 4 : apply_mask (&p);
69 :
70 : /* Administrative distance. */
71 4 : if (distance_str)
72 0 : distance = atoi (distance_str);
73 : else
74 4 : distance = ZEBRA_STATIC_DISTANCE_DEFAULT;
75 :
76 : /* Null0 static route. */
77 4 : if ((gate_str != NULL) && (strncasecmp (gate_str, "Null0", strlen (gate_str)) == 0))
78 : {
79 1 : if (flag_str)
80 : {
81 0 : vty_out (vty, "%% can not have flag %s with Null0%s", flag_str, VTY_NEWLINE);
82 0 : return CMD_WARNING;
83 : }
84 1 : if (add_cmd)
85 1 : static_add_ipv4 (&p, NULL, NULL, ZEBRA_FLAG_BLACKHOLE, distance, 0);
86 : else
87 0 : static_delete_ipv4 (&p, NULL, NULL, distance, 0);
88 1 : return CMD_SUCCESS;
89 : }
90 :
91 : /* Route flags */
92 3 : if (flag_str) {
93 1 : switch(flag_str[0]) {
94 : case 'r':
95 : case 'R': /* XXX */
96 1 : SET_FLAG (flag, ZEBRA_FLAG_REJECT);
97 1 : break;
98 : case 'b':
99 : case 'B': /* XXX */
100 0 : SET_FLAG (flag, ZEBRA_FLAG_BLACKHOLE);
101 0 : break;
102 : default:
103 0 : vty_out (vty, "%% Malformed flag %s %s", flag_str, VTY_NEWLINE);
104 0 : return CMD_WARNING;
105 : }
106 : }
107 :
108 3 : if (gate_str == NULL)
109 : {
110 2 : if (add_cmd)
111 1 : static_add_ipv4 (&p, NULL, NULL, flag, distance, 0);
112 : else
113 1 : static_delete_ipv4 (&p, NULL, NULL, distance, 0);
114 :
115 2 : return CMD_SUCCESS;
116 : }
117 :
118 : /* When gateway is A.B.C.D format, gate is treated as nexthop
119 : address other case gate is treated as interface name. */
120 1 : ret = inet_aton (gate_str, &gate);
121 1 : if (ret)
122 1 : ifname = NULL;
123 : else
124 0 : ifname = gate_str;
125 :
126 1 : if (add_cmd)
127 1 : static_add_ipv4 (&p, ifname ? NULL : &gate, ifname, flag, distance, 0);
128 : else
129 0 : static_delete_ipv4 (&p, ifname ? NULL : &gate, ifname, distance, 0);
130 :
131 1 : return CMD_SUCCESS;
132 : }
133 :
134 : /* Static route configuration. */
135 2 : DEFUN (ip_route,
136 : ip_route_cmd,
137 : "ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0)",
138 : IP_STR
139 : "Establish static routes\n"
140 : "IP destination prefix (e.g. 10.0.0.0/8)\n"
141 : "IP gateway address\n"
142 : "IP gateway interface name\n"
143 : "Null interface\n")
144 : {
145 2 : return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], NULL, NULL);
146 : }
147 :
148 0 : DEFUN (ip_route_flags,
149 : ip_route_flags_cmd,
150 : "ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole)",
151 : IP_STR
152 : "Establish static routes\n"
153 : "IP destination prefix (e.g. 10.0.0.0/8)\n"
154 : "IP gateway address\n"
155 : "IP gateway interface name\n"
156 : "Emit an ICMP unreachable when matched\n"
157 : "Silently discard pkts when matched\n")
158 : {
159 0 : return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], argv[2], NULL);
160 : }
161 :
162 1 : DEFUN (ip_route_flags2,
163 : ip_route_flags2_cmd,
164 : "ip route A.B.C.D/M (reject|blackhole)",
165 : IP_STR
166 : "Establish static routes\n"
167 : "IP destination prefix (e.g. 10.0.0.0/8)\n"
168 : "Emit an ICMP unreachable when matched\n"
169 : "Silently discard pkts when matched\n")
170 : {
171 1 : return zebra_static_ipv4 (vty, 1, argv[0], NULL, NULL, argv[1], NULL);
172 : }
173 :
174 : /* Mask as A.B.C.D format. */
175 0 : DEFUN (ip_route_mask,
176 : ip_route_mask_cmd,
177 : "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0)",
178 : IP_STR
179 : "Establish static routes\n"
180 : "IP destination prefix\n"
181 : "IP destination prefix mask\n"
182 : "IP gateway address\n"
183 : "IP gateway interface name\n"
184 : "Null interface\n")
185 : {
186 0 : return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], NULL, NULL);
187 : }
188 :
189 0 : DEFUN (ip_route_mask_flags,
190 : ip_route_mask_flags_cmd,
191 : "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole)",
192 : IP_STR
193 : "Establish static routes\n"
194 : "IP destination prefix\n"
195 : "IP destination prefix mask\n"
196 : "IP gateway address\n"
197 : "IP gateway interface name\n"
198 : "Emit an ICMP unreachable when matched\n"
199 : "Silently discard pkts when matched\n")
200 : {
201 0 : return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], argv[3], NULL);
202 : }
203 :
204 0 : DEFUN (ip_route_mask_flags2,
205 : ip_route_mask_flags2_cmd,
206 : "ip route A.B.C.D A.B.C.D (reject|blackhole)",
207 : IP_STR
208 : "Establish static routes\n"
209 : "IP destination prefix\n"
210 : "IP destination prefix mask\n"
211 : "Emit an ICMP unreachable when matched\n"
212 : "Silently discard pkts when matched\n")
213 : {
214 0 : return zebra_static_ipv4 (vty, 1, argv[0], argv[1], NULL, argv[2], NULL);
215 : }
216 :
217 : /* Distance option value. */
218 0 : DEFUN (ip_route_distance,
219 : ip_route_distance_cmd,
220 : "ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0) <1-255>",
221 : IP_STR
222 : "Establish static routes\n"
223 : "IP destination prefix (e.g. 10.0.0.0/8)\n"
224 : "IP gateway address\n"
225 : "IP gateway interface name\n"
226 : "Null interface\n"
227 : "Distance value for this route\n")
228 : {
229 0 : return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], NULL, argv[2]);
230 : }
231 :
232 0 : DEFUN (ip_route_flags_distance,
233 : ip_route_flags_distance_cmd,
234 : "ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
235 : IP_STR
236 : "Establish static routes\n"
237 : "IP destination prefix (e.g. 10.0.0.0/8)\n"
238 : "IP gateway address\n"
239 : "IP gateway interface name\n"
240 : "Emit an ICMP unreachable when matched\n"
241 : "Silently discard pkts when matched\n"
242 : "Distance value for this route\n")
243 : {
244 0 : return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], argv[2], argv[3]);
245 : }
246 :
247 0 : DEFUN (ip_route_flags_distance2,
248 : ip_route_flags_distance2_cmd,
249 : "ip route A.B.C.D/M (reject|blackhole) <1-255>",
250 : IP_STR
251 : "Establish static routes\n"
252 : "IP destination prefix (e.g. 10.0.0.0/8)\n"
253 : "Emit an ICMP unreachable when matched\n"
254 : "Silently discard pkts when matched\n"
255 : "Distance value for this route\n")
256 : {
257 0 : return zebra_static_ipv4 (vty, 1, argv[0], NULL, NULL, argv[1], argv[2]);
258 : }
259 :
260 0 : DEFUN (ip_route_mask_distance,
261 : ip_route_mask_distance_cmd,
262 : "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0) <1-255>",
263 : IP_STR
264 : "Establish static routes\n"
265 : "IP destination prefix\n"
266 : "IP destination prefix mask\n"
267 : "IP gateway address\n"
268 : "IP gateway interface name\n"
269 : "Null interface\n"
270 : "Distance value for this route\n")
271 : {
272 0 : return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], NULL, argv[3]);
273 : }
274 :
275 0 : DEFUN (ip_route_mask_flags_distance,
276 : ip_route_mask_flags_distance_cmd,
277 : "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
278 : IP_STR
279 : "Establish static routes\n"
280 : "IP destination prefix\n"
281 : "IP destination prefix mask\n"
282 : "IP gateway address\n"
283 : "IP gateway interface name\n"
284 : "Emit an ICMP unreachable when matched\n"
285 : "Silently discard pkts when matched\n"
286 : "Distance value for this route\n")
287 : {
288 0 : return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], argv[3], argv[4]);
289 : }
290 :
291 0 : DEFUN (ip_route_mask_flags_distance2,
292 : ip_route_mask_flags_distance2_cmd,
293 : "ip route A.B.C.D A.B.C.D (reject|blackhole) <1-255>",
294 : IP_STR
295 : "Establish static routes\n"
296 : "IP destination prefix\n"
297 : "IP destination prefix mask\n"
298 : "Emit an ICMP unreachable when matched\n"
299 : "Silently discard pkts when matched\n"
300 : "Distance value for this route\n")
301 : {
302 0 : return zebra_static_ipv4 (vty, 1, argv[0], argv[1], NULL, argv[2], argv[3]);
303 : }
304 :
305 0 : DEFUN (no_ip_route,
306 : no_ip_route_cmd,
307 : "no ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0)",
308 : NO_STR
309 : IP_STR
310 : "Establish static routes\n"
311 : "IP destination prefix (e.g. 10.0.0.0/8)\n"
312 : "IP gateway address\n"
313 : "IP gateway interface name\n"
314 : "Null interface\n")
315 : {
316 0 : return zebra_static_ipv4 (vty, 0, argv[0], NULL, argv[1], NULL, NULL);
317 : }
318 :
319 : ALIAS (no_ip_route,
320 : no_ip_route_flags_cmd,
321 : "no ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole)",
322 : NO_STR
323 : IP_STR
324 : "Establish static routes\n"
325 : "IP destination prefix (e.g. 10.0.0.0/8)\n"
326 : "IP gateway address\n"
327 : "IP gateway interface name\n"
328 : "Emit an ICMP unreachable when matched\n"
329 : "Silently discard pkts when matched\n")
330 :
331 1 : DEFUN (no_ip_route_flags2,
332 : no_ip_route_flags2_cmd,
333 : "no ip route A.B.C.D/M (reject|blackhole)",
334 : NO_STR
335 : IP_STR
336 : "Establish static routes\n"
337 : "IP destination prefix (e.g. 10.0.0.0/8)\n"
338 : "Emit an ICMP unreachable when matched\n"
339 : "Silently discard pkts when matched\n")
340 : {
341 1 : return zebra_static_ipv4 (vty, 0, argv[0], NULL, NULL, NULL, NULL);
342 : }
343 :
344 0 : DEFUN (no_ip_route_mask,
345 : no_ip_route_mask_cmd,
346 : "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0)",
347 : NO_STR
348 : IP_STR
349 : "Establish static routes\n"
350 : "IP destination prefix\n"
351 : "IP destination prefix mask\n"
352 : "IP gateway address\n"
353 : "IP gateway interface name\n"
354 : "Null interface\n")
355 : {
356 0 : return zebra_static_ipv4 (vty, 0, argv[0], argv[1], argv[2], NULL, NULL);
357 : }
358 :
359 : ALIAS (no_ip_route_mask,
360 : no_ip_route_mask_flags_cmd,
361 : "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole)",
362 : NO_STR
363 : IP_STR
364 : "Establish static routes\n"
365 : "IP destination prefix\n"
366 : "IP destination prefix mask\n"
367 : "IP gateway address\n"
368 : "IP gateway interface name\n"
369 : "Emit an ICMP unreachable when matched\n"
370 : "Silently discard pkts when matched\n")
371 :
372 0 : DEFUN (no_ip_route_mask_flags2,
373 : no_ip_route_mask_flags2_cmd,
374 : "no ip route A.B.C.D A.B.C.D (reject|blackhole)",
375 : NO_STR
376 : IP_STR
377 : "Establish static routes\n"
378 : "IP destination prefix\n"
379 : "IP destination prefix mask\n"
380 : "Emit an ICMP unreachable when matched\n"
381 : "Silently discard pkts when matched\n")
382 : {
383 0 : return zebra_static_ipv4 (vty, 0, argv[0], argv[1], NULL, NULL, NULL);
384 : }
385 :
386 0 : DEFUN (no_ip_route_distance,
387 : no_ip_route_distance_cmd,
388 : "no ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0) <1-255>",
389 : NO_STR
390 : IP_STR
391 : "Establish static routes\n"
392 : "IP destination prefix (e.g. 10.0.0.0/8)\n"
393 : "IP gateway address\n"
394 : "IP gateway interface name\n"
395 : "Null interface\n"
396 : "Distance value for this route\n")
397 : {
398 0 : return zebra_static_ipv4 (vty, 0, argv[0], NULL, argv[1], NULL, argv[2]);
399 : }
400 :
401 0 : DEFUN (no_ip_route_flags_distance,
402 : no_ip_route_flags_distance_cmd,
403 : "no ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
404 : NO_STR
405 : IP_STR
406 : "Establish static routes\n"
407 : "IP destination prefix (e.g. 10.0.0.0/8)\n"
408 : "IP gateway address\n"
409 : "IP gateway interface name\n"
410 : "Emit an ICMP unreachable when matched\n"
411 : "Silently discard pkts when matched\n"
412 : "Distance value for this route\n")
413 : {
414 0 : return zebra_static_ipv4 (vty, 0, argv[0], NULL, argv[1], argv[2], argv[3]);
415 : }
416 :
417 0 : DEFUN (no_ip_route_flags_distance2,
418 : no_ip_route_flags_distance2_cmd,
419 : "no ip route A.B.C.D/M (reject|blackhole) <1-255>",
420 : NO_STR
421 : IP_STR
422 : "Establish static routes\n"
423 : "IP destination prefix (e.g. 10.0.0.0/8)\n"
424 : "Emit an ICMP unreachable when matched\n"
425 : "Silently discard pkts when matched\n"
426 : "Distance value for this route\n")
427 : {
428 0 : return zebra_static_ipv4 (vty, 0, argv[0], NULL, NULL, argv[1], argv[2]);
429 : }
430 :
431 0 : DEFUN (no_ip_route_mask_distance,
432 : no_ip_route_mask_distance_cmd,
433 : "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0) <1-255>",
434 : NO_STR
435 : IP_STR
436 : "Establish static routes\n"
437 : "IP destination prefix\n"
438 : "IP destination prefix mask\n"
439 : "IP gateway address\n"
440 : "IP gateway interface name\n"
441 : "Null interface\n"
442 : "Distance value for this route\n")
443 : {
444 0 : return zebra_static_ipv4 (vty, 0, argv[0], argv[1], argv[2], NULL, argv[3]);
445 : }
446 :
447 0 : DEFUN (no_ip_route_mask_flags_distance,
448 : no_ip_route_mask_flags_distance_cmd,
449 : "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
450 : NO_STR
451 : IP_STR
452 : "Establish static routes\n"
453 : "IP destination prefix\n"
454 : "IP destination prefix mask\n"
455 : "IP gateway address\n"
456 : "IP gateway interface name\n"
457 : "Emit an ICMP unreachable when matched\n"
458 : "Silently discard pkts when matched\n"
459 : "Distance value for this route\n")
460 : {
461 0 : return zebra_static_ipv4 (vty, 0, argv[0], argv[1], argv[2], argv[3], argv[4]);
462 : }
463 :
464 0 : DEFUN (no_ip_route_mask_flags_distance2,
465 : no_ip_route_mask_flags_distance2_cmd,
466 : "no ip route A.B.C.D A.B.C.D (reject|blackhole) <1-255>",
467 : NO_STR
468 : IP_STR
469 : "Establish static routes\n"
470 : "IP destination prefix\n"
471 : "IP destination prefix mask\n"
472 : "Emit an ICMP unreachable when matched\n"
473 : "Silently discard pkts when matched\n"
474 : "Distance value for this route\n")
475 : {
476 0 : return zebra_static_ipv4 (vty, 0, argv[0], argv[1], NULL, argv[2], argv[3]);
477 : }
478 :
479 : char *proto_rm[AFI_MAX][ZEBRA_ROUTE_MAX+1]; /* "any" == ZEBRA_ROUTE_MAX */
480 :
481 14 : DEFUN (ip_protocol,
482 : ip_protocol_cmd,
483 : "ip protocol PROTO route-map ROUTE-MAP",
484 : NO_STR
485 : "Apply route map to PROTO\n"
486 : "Protocol name\n"
487 : "Route map name\n")
488 : {
489 : int i;
490 :
491 14 : if (strcasecmp(argv[0], "any") == 0)
492 0 : i = ZEBRA_ROUTE_MAX;
493 : else
494 14 : i = proto_name2num(argv[0]);
495 14 : if (i < 0)
496 : {
497 0 : vty_out (vty, "invalid protocol name \"%s\"%s", argv[0] ? argv[0] : "",
498 0 : VTY_NEWLINE);
499 0 : return CMD_WARNING;
500 : }
501 14 : if (proto_rm[AFI_IP][i])
502 0 : XFREE (MTYPE_ROUTE_MAP_NAME, proto_rm[AFI_IP][i]);
503 14 : proto_rm[AFI_IP][i] = XSTRDUP (MTYPE_ROUTE_MAP_NAME, argv[1]);
504 14 : return CMD_SUCCESS;
505 : }
506 :
507 1 : DEFUN (no_ip_protocol,
508 : no_ip_protocol_cmd,
509 : "no ip protocol PROTO",
510 : NO_STR
511 : "Remove route map from PROTO\n"
512 : "Protocol name\n")
513 : {
514 : int i;
515 :
516 1 : if (strcasecmp(argv[0], "any") == 0)
517 0 : i = ZEBRA_ROUTE_MAX;
518 : else
519 1 : i = proto_name2num(argv[0]);
520 1 : if (i < 0)
521 : {
522 0 : vty_out (vty, "invalid protocol name \"%s\"%s", argv[0] ? argv[0] : "",
523 0 : VTY_NEWLINE);
524 0 : return CMD_WARNING;
525 : }
526 1 : if (proto_rm[AFI_IP][i])
527 1 : XFREE (MTYPE_ROUTE_MAP_NAME, proto_rm[AFI_IP][i]);
528 1 : proto_rm[AFI_IP][i] = NULL;
529 1 : return CMD_SUCCESS;
530 : }
531 :
532 : /* New RIB. Detailed information for IPv4 route. */
533 : static void
534 0 : vty_show_ip_route_detail (struct vty *vty, struct route_node *rn)
535 : {
536 : struct rib *rib;
537 : struct nexthop *nexthop, *tnexthop;
538 : int recursing;
539 :
540 0 : RNODE_FOREACH_RIB (rn, rib)
541 : {
542 0 : vty_out (vty, "Routing entry for %s/%d%s",
543 0 : inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
544 0 : VTY_NEWLINE);
545 0 : vty_out (vty, " Known via \"%s\"", zebra_route_string (rib->type));
546 0 : vty_out (vty, ", distance %u, metric %u", rib->distance, rib->metric);
547 0 : if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
548 0 : vty_out (vty, ", best");
549 0 : if (rib->refcnt)
550 0 : vty_out (vty, ", refcnt %ld", rib->refcnt);
551 0 : if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
552 0 : vty_out (vty, ", blackhole");
553 0 : if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT))
554 0 : vty_out (vty, ", reject");
555 0 : vty_out (vty, "%s", VTY_NEWLINE);
556 :
557 : #define ONE_DAY_SECOND 60*60*24
558 : #define ONE_WEEK_SECOND 60*60*24*7
559 0 : if (rib->type == ZEBRA_ROUTE_RIP
560 0 : || rib->type == ZEBRA_ROUTE_OSPF
561 0 : || rib->type == ZEBRA_ROUTE_BABEL
562 0 : || rib->type == ZEBRA_ROUTE_ISIS
563 0 : || rib->type == ZEBRA_ROUTE_BGP)
564 : {
565 : time_t uptime;
566 : struct tm *tm;
567 :
568 0 : uptime = time (NULL);
569 0 : uptime -= rib->uptime;
570 0 : tm = gmtime (&uptime);
571 :
572 0 : vty_out (vty, " Last update ");
573 :
574 0 : if (uptime < ONE_DAY_SECOND)
575 0 : vty_out (vty, "%02d:%02d:%02d",
576 : tm->tm_hour, tm->tm_min, tm->tm_sec);
577 0 : else if (uptime < ONE_WEEK_SECOND)
578 0 : vty_out (vty, "%dd%02dh%02dm",
579 : tm->tm_yday, tm->tm_hour, tm->tm_min);
580 : else
581 0 : vty_out (vty, "%02dw%dd%02dh",
582 0 : tm->tm_yday/7,
583 0 : tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
584 0 : vty_out (vty, " ago%s", VTY_NEWLINE);
585 : }
586 :
587 0 : for (ALL_NEXTHOPS_RO(rib->nexthop, nexthop, tnexthop, recursing))
588 : {
589 : char addrstr[32];
590 :
591 0 : vty_out (vty, " %c%s",
592 0 : CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB) ? '*' : ' ',
593 : recursing ? " " : "");
594 :
595 0 : switch (nexthop->type)
596 : {
597 : case NEXTHOP_TYPE_IPV4:
598 : case NEXTHOP_TYPE_IPV4_IFINDEX:
599 0 : vty_out (vty, " %s", inet_ntoa (nexthop->gate.ipv4));
600 0 : if (nexthop->ifindex)
601 0 : vty_out (vty, ", via %s", ifindex2ifname (nexthop->ifindex));
602 0 : break;
603 : case NEXTHOP_TYPE_IFINDEX:
604 0 : vty_out (vty, " directly connected, %s",
605 : ifindex2ifname (nexthop->ifindex));
606 0 : break;
607 : case NEXTHOP_TYPE_IFNAME:
608 0 : vty_out (vty, " directly connected, %s", nexthop->ifname);
609 0 : break;
610 : case NEXTHOP_TYPE_BLACKHOLE:
611 0 : vty_out (vty, " directly connected, Null0");
612 0 : break;
613 : default:
614 0 : break;
615 : }
616 0 : if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
617 0 : vty_out (vty, " inactive");
618 :
619 0 : if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ONLINK))
620 0 : vty_out (vty, " onlink");
621 :
622 0 : if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
623 0 : vty_out (vty, " (recursive)");
624 :
625 0 : switch (nexthop->type)
626 : {
627 : case NEXTHOP_TYPE_IPV4:
628 : case NEXTHOP_TYPE_IPV4_IFINDEX:
629 : case NEXTHOP_TYPE_IPV4_IFNAME:
630 0 : if (nexthop->src.ipv4.s_addr)
631 : {
632 0 : if (inet_ntop(AF_INET, &nexthop->src.ipv4, addrstr,
633 : sizeof addrstr))
634 0 : vty_out (vty, ", src %s", addrstr);
635 : }
636 0 : break;
637 : #ifdef HAVE_IPV6
638 : case NEXTHOP_TYPE_IPV6:
639 : case NEXTHOP_TYPE_IPV6_IFINDEX:
640 : case NEXTHOP_TYPE_IPV6_IFNAME:
641 0 : if (!IPV6_ADDR_SAME(&nexthop->src.ipv6, &in6addr_any))
642 : {
643 0 : if (inet_ntop(AF_INET6, &nexthop->src.ipv6, addrstr,
644 : sizeof addrstr))
645 0 : vty_out (vty, ", src %s", addrstr);
646 : }
647 0 : break;
648 : #endif /* HAVE_IPV6 */
649 : default:
650 0 : break;
651 : }
652 0 : vty_out (vty, "%s", VTY_NEWLINE);
653 : }
654 0 : vty_out (vty, "%s", VTY_NEWLINE);
655 : }
656 0 : }
657 :
658 : static void
659 329 : vty_show_ip_route (struct vty *vty, struct route_node *rn, struct rib *rib)
660 : {
661 : struct nexthop *nexthop, *tnexthop;
662 : int recursing;
663 329 : int len = 0;
664 : char buf[BUFSIZ];
665 :
666 : /* Nexthop information. */
667 810 : for (ALL_NEXTHOPS_RO(rib->nexthop, nexthop, tnexthop, recursing))
668 : {
669 481 : if (nexthop == rib->nexthop)
670 : {
671 : /* Prefix information. */
672 1645 : len = vty_out (vty, "%c%c%c %s/%d",
673 329 : zebra_route_char (rib->type),
674 329 : CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED)
675 : ? '>' : ' ',
676 329 : CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
677 : ? '*' : ' ',
678 329 : inet_ntop (AF_INET, &rn->p.u.prefix, buf, BUFSIZ),
679 329 : rn->p.prefixlen);
680 :
681 : /* Distance and metric display. */
682 329 : if (rib->type != ZEBRA_ROUTE_CONNECT
683 106 : && rib->type != ZEBRA_ROUTE_KERNEL)
684 106 : len += vty_out (vty, " [%d/%d]", rib->distance,
685 : rib->metric);
686 : }
687 : else
688 304 : vty_out (vty, " %c%*c",
689 152 : CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
690 : ? '*' : ' ',
691 152 : len - 3 + (2 * recursing), ' ');
692 :
693 481 : switch (nexthop->type)
694 : {
695 : case NEXTHOP_TYPE_IPV4:
696 : case NEXTHOP_TYPE_IPV4_IFINDEX:
697 214 : vty_out (vty, " via %s", inet_ntoa (nexthop->gate.ipv4));
698 214 : if (nexthop->ifindex)
699 204 : vty_out (vty, ", %s", ifindex2ifname (nexthop->ifindex));
700 214 : break;
701 : case NEXTHOP_TYPE_IFINDEX:
702 263 : vty_out (vty, " is directly connected, %s",
703 : ifindex2ifname (nexthop->ifindex));
704 263 : break;
705 : case NEXTHOP_TYPE_IFNAME:
706 0 : vty_out (vty, " is directly connected, %s", nexthop->ifname);
707 0 : break;
708 : case NEXTHOP_TYPE_BLACKHOLE:
709 4 : vty_out (vty, " is directly connected, Null0");
710 4 : break;
711 : default:
712 0 : break;
713 : }
714 481 : if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
715 11 : vty_out (vty, " inactive");
716 :
717 481 : if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ONLINK))
718 3 : vty_out (vty, " onlink");
719 :
720 481 : if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
721 5 : vty_out (vty, " (recursive)");
722 :
723 481 : switch (nexthop->type)
724 : {
725 : case NEXTHOP_TYPE_IPV4:
726 : case NEXTHOP_TYPE_IPV4_IFINDEX:
727 : case NEXTHOP_TYPE_IPV4_IFNAME:
728 214 : if (nexthop->src.ipv4.s_addr)
729 : {
730 6 : if (inet_ntop(AF_INET, &nexthop->src.ipv4, buf, sizeof buf))
731 6 : vty_out (vty, ", src %s", buf);
732 : }
733 214 : break;
734 : #ifdef HAVE_IPV6
735 : case NEXTHOP_TYPE_IPV6:
736 : case NEXTHOP_TYPE_IPV6_IFINDEX:
737 : case NEXTHOP_TYPE_IPV6_IFNAME:
738 0 : if (!IPV6_ADDR_SAME(&nexthop->src.ipv6, &in6addr_any))
739 : {
740 0 : if (inet_ntop(AF_INET6, &nexthop->src.ipv6, buf, sizeof buf))
741 0 : vty_out (vty, ", src %s", buf);
742 : }
743 0 : break;
744 : #endif /* HAVE_IPV6 */
745 : default:
746 267 : break;
747 : }
748 :
749 481 : if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
750 2 : vty_out (vty, ", bh");
751 481 : if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT))
752 2 : vty_out (vty, ", rej");
753 :
754 481 : if (rib->type == ZEBRA_ROUTE_RIP
755 481 : || rib->type == ZEBRA_ROUTE_OSPF
756 245 : || rib->type == ZEBRA_ROUTE_BABEL
757 245 : || rib->type == ZEBRA_ROUTE_ISIS
758 245 : || rib->type == ZEBRA_ROUTE_BGP)
759 : {
760 : time_t uptime;
761 : struct tm *tm;
762 :
763 251 : uptime = time (NULL);
764 251 : uptime -= rib->uptime;
765 251 : tm = gmtime (&uptime);
766 :
767 : #define ONE_DAY_SECOND 60*60*24
768 : #define ONE_WEEK_SECOND 60*60*24*7
769 :
770 251 : if (uptime < ONE_DAY_SECOND)
771 251 : vty_out (vty, ", %02d:%02d:%02d",
772 : tm->tm_hour, tm->tm_min, tm->tm_sec);
773 0 : else if (uptime < ONE_WEEK_SECOND)
774 0 : vty_out (vty, ", %dd%02dh%02dm",
775 : tm->tm_yday, tm->tm_hour, tm->tm_min);
776 : else
777 0 : vty_out (vty, ", %02dw%dd%02dh",
778 0 : tm->tm_yday/7,
779 0 : tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
780 : }
781 481 : vty_out (vty, "%s", VTY_NEWLINE);
782 : }
783 329 : }
784 :
785 72 : DEFUN (show_ip_route,
786 : show_ip_route_cmd,
787 : "show ip route",
788 : SHOW_STR
789 : IP_STR
790 : "IP routing table\n")
791 : {
792 : struct route_table *table;
793 : struct route_node *rn;
794 : struct rib *rib;
795 72 : int first = 1;
796 :
797 72 : table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
798 72 : if (! table)
799 0 : return CMD_SUCCESS;
800 :
801 : /* Show all IPv4 routes. */
802 654 : for (rn = route_top (table); rn; rn = route_next (rn))
803 911 : RNODE_FOREACH_RIB (rn, rib)
804 : {
805 329 : if (first)
806 : {
807 72 : vty_out (vty, SHOW_ROUTE_V4_HEADER);
808 72 : first = 0;
809 : }
810 329 : vty_show_ip_route (vty, rn, rib);
811 : }
812 72 : return CMD_SUCCESS;
813 : }
814 :
815 0 : DEFUN (show_ip_route_prefix_longer,
816 : show_ip_route_prefix_longer_cmd,
817 : "show ip route A.B.C.D/M longer-prefixes",
818 : SHOW_STR
819 : IP_STR
820 : "IP routing table\n"
821 : "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
822 : "Show route matching the specified Network/Mask pair only\n")
823 : {
824 : struct route_table *table;
825 : struct route_node *rn;
826 : struct rib *rib;
827 : struct prefix p;
828 : int ret;
829 0 : int first = 1;
830 :
831 0 : ret = str2prefix (argv[0], &p);
832 0 : if (! ret)
833 : {
834 0 : vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
835 0 : return CMD_WARNING;
836 : }
837 :
838 0 : table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
839 0 : if (! table)
840 0 : return CMD_SUCCESS;
841 :
842 : /* Show matched type IPv4 routes. */
843 0 : for (rn = route_top (table); rn; rn = route_next (rn))
844 0 : RNODE_FOREACH_RIB (rn, rib)
845 0 : if (prefix_match (&p, &rn->p))
846 : {
847 0 : if (first)
848 : {
849 0 : vty_out (vty, SHOW_ROUTE_V4_HEADER);
850 0 : first = 0;
851 : }
852 0 : vty_show_ip_route (vty, rn, rib);
853 : }
854 0 : return CMD_SUCCESS;
855 : }
856 :
857 0 : DEFUN (show_ip_route_supernets,
858 : show_ip_route_supernets_cmd,
859 : "show ip route supernets-only",
860 : SHOW_STR
861 : IP_STR
862 : "IP routing table\n"
863 : "Show supernet entries only\n")
864 : {
865 : struct route_table *table;
866 : struct route_node *rn;
867 : struct rib *rib;
868 : u_int32_t addr;
869 0 : int first = 1;
870 :
871 0 : table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
872 0 : if (! table)
873 0 : return CMD_SUCCESS;
874 :
875 : /* Show matched type IPv4 routes. */
876 0 : for (rn = route_top (table); rn; rn = route_next (rn))
877 0 : RNODE_FOREACH_RIB (rn, rib)
878 : {
879 0 : addr = ntohl (rn->p.u.prefix4.s_addr);
880 :
881 0 : if ((IN_CLASSC (addr) && rn->p.prefixlen < 24)
882 0 : || (IN_CLASSB (addr) && rn->p.prefixlen < 16)
883 0 : || (IN_CLASSA (addr) && rn->p.prefixlen < 8))
884 : {
885 0 : if (first)
886 : {
887 0 : vty_out (vty, SHOW_ROUTE_V4_HEADER);
888 0 : first = 0;
889 : }
890 0 : vty_show_ip_route (vty, rn, rib);
891 : }
892 : }
893 0 : return CMD_SUCCESS;
894 : }
895 :
896 0 : DEFUN (show_ip_route_protocol,
897 : show_ip_route_protocol_cmd,
898 : "show ip route " QUAGGA_IP_REDIST_STR_ZEBRA,
899 : SHOW_STR
900 : IP_STR
901 : "IP routing table\n"
902 : QUAGGA_IP_REDIST_HELP_STR_ZEBRA)
903 : {
904 : int type;
905 : struct route_table *table;
906 : struct route_node *rn;
907 : struct rib *rib;
908 0 : int first = 1;
909 :
910 0 : type = proto_redistnum (AFI_IP, argv[0]);
911 0 : if (type < 0)
912 : {
913 0 : vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
914 0 : return CMD_WARNING;
915 : }
916 :
917 0 : table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
918 0 : if (! table)
919 0 : return CMD_SUCCESS;
920 :
921 : /* Show matched type IPv4 routes. */
922 0 : for (rn = route_top (table); rn; rn = route_next (rn))
923 0 : RNODE_FOREACH_RIB (rn, rib)
924 0 : if (rib->type == type)
925 : {
926 0 : if (first)
927 : {
928 0 : vty_out (vty, SHOW_ROUTE_V4_HEADER);
929 0 : first = 0;
930 : }
931 0 : vty_show_ip_route (vty, rn, rib);
932 : }
933 0 : return CMD_SUCCESS;
934 : }
935 :
936 0 : DEFUN (show_ip_route_addr,
937 : show_ip_route_addr_cmd,
938 : "show ip route A.B.C.D",
939 : SHOW_STR
940 : IP_STR
941 : "IP routing table\n"
942 : "Network in the IP routing table to display\n")
943 : {
944 : int ret;
945 : struct prefix_ipv4 p;
946 : struct route_table *table;
947 : struct route_node *rn;
948 :
949 0 : ret = str2prefix_ipv4 (argv[0], &p);
950 0 : if (ret <= 0)
951 : {
952 0 : vty_out (vty, "%% Malformed IPv4 address%s", VTY_NEWLINE);
953 0 : return CMD_WARNING;
954 : }
955 :
956 0 : table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
957 0 : if (! table)
958 0 : return CMD_SUCCESS;
959 :
960 0 : rn = route_node_match (table, (struct prefix *) &p);
961 0 : if (! rn)
962 : {
963 0 : vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
964 0 : return CMD_WARNING;
965 : }
966 :
967 0 : vty_show_ip_route_detail (vty, rn);
968 :
969 0 : route_unlock_node (rn);
970 :
971 0 : return CMD_SUCCESS;
972 : }
973 :
974 0 : DEFUN (show_ip_route_prefix,
975 : show_ip_route_prefix_cmd,
976 : "show ip route A.B.C.D/M",
977 : SHOW_STR
978 : IP_STR
979 : "IP routing table\n"
980 : "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
981 : {
982 : int ret;
983 : struct prefix_ipv4 p;
984 : struct route_table *table;
985 : struct route_node *rn;
986 :
987 0 : ret = str2prefix_ipv4 (argv[0], &p);
988 0 : if (ret <= 0)
989 : {
990 0 : vty_out (vty, "%% Malformed IPv4 address%s", VTY_NEWLINE);
991 0 : return CMD_WARNING;
992 : }
993 :
994 0 : table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
995 0 : if (! table)
996 0 : return CMD_SUCCESS;
997 :
998 0 : rn = route_node_match (table, (struct prefix *) &p);
999 0 : if (! rn || rn->p.prefixlen != p.prefixlen)
1000 : {
1001 0 : vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
1002 0 : return CMD_WARNING;
1003 : }
1004 :
1005 0 : vty_show_ip_route_detail (vty, rn);
1006 :
1007 0 : route_unlock_node (rn);
1008 :
1009 0 : return CMD_SUCCESS;
1010 : }
1011 :
1012 : static void
1013 0 : vty_show_ip_route_summary (struct vty *vty, struct route_table *table)
1014 : {
1015 : struct route_node *rn;
1016 : struct rib *rib;
1017 : struct nexthop *nexthop;
1018 : #define ZEBRA_ROUTE_IBGP ZEBRA_ROUTE_MAX
1019 : #define ZEBRA_ROUTE_TOTAL (ZEBRA_ROUTE_IBGP + 1)
1020 : u_int32_t rib_cnt[ZEBRA_ROUTE_TOTAL + 1];
1021 : u_int32_t fib_cnt[ZEBRA_ROUTE_TOTAL + 1];
1022 : u_int32_t i;
1023 :
1024 0 : memset (&rib_cnt, 0, sizeof(rib_cnt));
1025 0 : memset (&fib_cnt, 0, sizeof(fib_cnt));
1026 0 : for (rn = route_top (table); rn; rn = route_next (rn))
1027 0 : RNODE_FOREACH_RIB (rn, rib)
1028 0 : for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
1029 : {
1030 0 : rib_cnt[ZEBRA_ROUTE_TOTAL]++;
1031 0 : rib_cnt[rib->type]++;
1032 0 : if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
1033 0 : || nexthop_has_fib_child(nexthop))
1034 : {
1035 0 : fib_cnt[ZEBRA_ROUTE_TOTAL]++;
1036 0 : fib_cnt[rib->type]++;
1037 : }
1038 0 : if (rib->type == ZEBRA_ROUTE_BGP &&
1039 0 : CHECK_FLAG (rib->flags, ZEBRA_FLAG_IBGP))
1040 : {
1041 0 : rib_cnt[ZEBRA_ROUTE_IBGP]++;
1042 0 : if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
1043 0 : || nexthop_has_fib_child(nexthop))
1044 0 : fib_cnt[ZEBRA_ROUTE_IBGP]++;
1045 : }
1046 : }
1047 :
1048 0 : vty_out (vty, "%-20s %-20s %-20s %s",
1049 0 : "Route Source", "Routes", "FIB", VTY_NEWLINE);
1050 :
1051 0 : for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
1052 : {
1053 0 : if (rib_cnt[i] > 0)
1054 : {
1055 0 : if (i == ZEBRA_ROUTE_BGP)
1056 : {
1057 0 : vty_out (vty, "%-20s %-20d %-20d %s", "ebgp",
1058 0 : rib_cnt[ZEBRA_ROUTE_BGP] - rib_cnt[ZEBRA_ROUTE_IBGP],
1059 0 : fib_cnt[ZEBRA_ROUTE_BGP] - fib_cnt[ZEBRA_ROUTE_IBGP],
1060 0 : VTY_NEWLINE);
1061 0 : vty_out (vty, "%-20s %-20d %-20d %s", "ibgp",
1062 : rib_cnt[ZEBRA_ROUTE_IBGP], fib_cnt[ZEBRA_ROUTE_IBGP],
1063 0 : VTY_NEWLINE);
1064 : }
1065 : else
1066 0 : vty_out (vty, "%-20s %-20d %-20d %s", zebra_route_string(i),
1067 0 : rib_cnt[i], fib_cnt[i], VTY_NEWLINE);
1068 : }
1069 : }
1070 :
1071 0 : vty_out (vty, "------%s", VTY_NEWLINE);
1072 0 : vty_out (vty, "%-20s %-20d %-20d %s", "Totals", rib_cnt[ZEBRA_ROUTE_TOTAL],
1073 0 : fib_cnt[ZEBRA_ROUTE_TOTAL], VTY_NEWLINE);
1074 0 : }
1075 :
1076 : /* Show route summary. */
1077 0 : DEFUN (show_ip_route_summary,
1078 : show_ip_route_summary_cmd,
1079 : "show ip route summary",
1080 : SHOW_STR
1081 : IP_STR
1082 : "IP routing table\n"
1083 : "Summary of all routes\n")
1084 : {
1085 : struct route_table *table;
1086 :
1087 0 : table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
1088 0 : if (! table)
1089 0 : return CMD_SUCCESS;
1090 :
1091 0 : vty_show_ip_route_summary (vty, table);
1092 :
1093 0 : return CMD_SUCCESS;
1094 : }
1095 :
1096 : /* Write IPv4 static route configuration. */
1097 : static int
1098 0 : static_config_ipv4 (struct vty *vty)
1099 : {
1100 : struct route_node *rn;
1101 : struct static_ipv4 *si;
1102 : struct route_table *stable;
1103 : int write;
1104 :
1105 0 : write = 0;
1106 :
1107 : /* Lookup table. */
1108 0 : stable = vrf_static_table (AFI_IP, SAFI_UNICAST, 0);
1109 0 : if (! stable)
1110 0 : return -1;
1111 :
1112 0 : for (rn = route_top (stable); rn; rn = route_next (rn))
1113 0 : for (si = rn->info; si; si = si->next)
1114 : {
1115 0 : vty_out (vty, "ip route %s/%d", inet_ntoa (rn->p.u.prefix4),
1116 0 : rn->p.prefixlen);
1117 :
1118 0 : switch (si->type)
1119 : {
1120 : case STATIC_IPV4_GATEWAY:
1121 0 : vty_out (vty, " %s", inet_ntoa (si->gate.ipv4));
1122 0 : break;
1123 : case STATIC_IPV4_IFNAME:
1124 0 : vty_out (vty, " %s", si->gate.ifname);
1125 0 : break;
1126 : case STATIC_IPV4_BLACKHOLE:
1127 0 : vty_out (vty, " Null0");
1128 0 : break;
1129 : }
1130 :
1131 : /* flags are incompatible with STATIC_IPV4_BLACKHOLE */
1132 0 : if (si->type != STATIC_IPV4_BLACKHOLE)
1133 : {
1134 0 : if (CHECK_FLAG(si->flags, ZEBRA_FLAG_REJECT))
1135 0 : vty_out (vty, " %s", "reject");
1136 :
1137 0 : if (CHECK_FLAG(si->flags, ZEBRA_FLAG_BLACKHOLE))
1138 0 : vty_out (vty, " %s", "blackhole");
1139 : }
1140 :
1141 0 : if (si->distance != ZEBRA_STATIC_DISTANCE_DEFAULT)
1142 0 : vty_out (vty, " %d", si->distance);
1143 :
1144 0 : vty_out (vty, "%s", VTY_NEWLINE);
1145 :
1146 0 : write = 1;
1147 : }
1148 0 : return write;
1149 : }
1150 :
1151 0 : DEFUN (show_ip_protocol,
1152 : show_ip_protocol_cmd,
1153 : "show ip protocol",
1154 : SHOW_STR
1155 : IP_STR
1156 : "IP protocol filtering status\n")
1157 : {
1158 : int i;
1159 :
1160 0 : vty_out(vty, "Protocol : route-map %s", VTY_NEWLINE);
1161 0 : vty_out(vty, "------------------------%s", VTY_NEWLINE);
1162 0 : for (i=0;i<ZEBRA_ROUTE_MAX;i++)
1163 : {
1164 0 : if (proto_rm[AFI_IP][i])
1165 0 : vty_out (vty, "%-10s : %-10s%s", zebra_route_string(i),
1166 : proto_rm[AFI_IP][i],
1167 0 : VTY_NEWLINE);
1168 : else
1169 0 : vty_out (vty, "%-10s : none%s", zebra_route_string(i), VTY_NEWLINE);
1170 : }
1171 0 : if (proto_rm[AFI_IP][i])
1172 0 : vty_out (vty, "%-10s : %-10s%s", "any", proto_rm[AFI_IP][i],
1173 0 : VTY_NEWLINE);
1174 : else
1175 0 : vty_out (vty, "%-10s : none%s", "any", VTY_NEWLINE);
1176 :
1177 0 : return CMD_SUCCESS;
1178 : }
1179 :
1180 : /*
1181 : * Show IP mroute command to dump the BGP Multicast
1182 : * routing table
1183 : */
1184 0 : DEFUN (show_ip_mroute,
1185 : show_ip_mroute_cmd,
1186 : "show ip mroute",
1187 : SHOW_STR
1188 : IP_STR
1189 : "IP Multicast routing table\n")
1190 : {
1191 : struct route_table *table;
1192 : struct route_node *rn;
1193 : struct rib *rib;
1194 0 : int first = 1;
1195 :
1196 0 : table = vrf_table (AFI_IP, SAFI_MULTICAST, 0);
1197 0 : if (! table)
1198 0 : return CMD_SUCCESS;
1199 :
1200 : /* Show all IPv4 routes. */
1201 0 : for (rn = route_top (table); rn; rn = route_next (rn))
1202 0 : RNODE_FOREACH_RIB (rn, rib)
1203 : {
1204 0 : if (first)
1205 : {
1206 0 : vty_out (vty, SHOW_ROUTE_V4_HEADER);
1207 0 : first = 0;
1208 : }
1209 0 : vty_show_ip_route (vty, rn, rib);
1210 : }
1211 0 : return CMD_SUCCESS;
1212 : }
1213 :
1214 :
1215 : #ifdef HAVE_IPV6
1216 : /* General fucntion for IPv6 static route. */
1217 : static int
1218 0 : static_ipv6_func (struct vty *vty, int add_cmd, const char *dest_str,
1219 : const char *from_str,
1220 : const char *gate_str, const char *ifname,
1221 : const char *flag_str, const char *distance_str)
1222 : {
1223 : int ret;
1224 : u_char distance;
1225 : struct prefix p;
1226 : struct prefix src_p;
1227 0 : struct in6_addr *gate = NULL;
1228 : struct in6_addr gate_addr;
1229 0 : u_char type = 0;
1230 0 : int table = 0;
1231 0 : u_char flag = 0;
1232 :
1233 0 : ret = str2prefix (dest_str, &p);
1234 0 : if (ret <= 0)
1235 : {
1236 0 : vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
1237 0 : return CMD_WARNING;
1238 : }
1239 :
1240 0 : if (from_str)
1241 0 : ret = str2prefix (from_str, &src_p);
1242 : else
1243 0 : ret = str2prefix ("::/0", &src_p);
1244 :
1245 0 : if (ret <= 0)
1246 : {
1247 0 : vty_out (vty, "%% Malformed from prefix%s", VTY_NEWLINE);
1248 0 : return CMD_WARNING;
1249 : }
1250 :
1251 : /* Apply mask for given prefix. */
1252 0 : apply_mask (&p);
1253 0 : apply_mask (&src_p);
1254 :
1255 : /* Route flags */
1256 0 : if (flag_str) {
1257 0 : switch(flag_str[0]) {
1258 : case 'r':
1259 : case 'R': /* XXX */
1260 0 : SET_FLAG (flag, ZEBRA_FLAG_REJECT);
1261 0 : break;
1262 : case 'b':
1263 : case 'B': /* XXX */
1264 0 : SET_FLAG (flag, ZEBRA_FLAG_BLACKHOLE);
1265 0 : break;
1266 : default:
1267 0 : vty_out (vty, "%% Malformed flag %s %s", flag_str, VTY_NEWLINE);
1268 0 : return CMD_WARNING;
1269 : }
1270 : }
1271 :
1272 : /* Administrative distance. */
1273 0 : if (distance_str)
1274 0 : distance = atoi (distance_str);
1275 : else
1276 0 : distance = ZEBRA_STATIC_DISTANCE_DEFAULT;
1277 :
1278 : /* When gateway is valid IPv6 addrees, then gate is treated as
1279 : nexthop address other case gate is treated as interface name. */
1280 0 : ret = inet_pton (AF_INET6, gate_str, &gate_addr);
1281 :
1282 0 : if (ifname)
1283 : {
1284 : /* When ifname is specified. It must be come with gateway
1285 : address. */
1286 0 : if (ret != 1)
1287 : {
1288 0 : vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
1289 0 : return CMD_WARNING;
1290 : }
1291 0 : type = STATIC_IPV6_GATEWAY_IFNAME;
1292 0 : gate = &gate_addr;
1293 : }
1294 : else
1295 : {
1296 0 : if (ret == 1)
1297 : {
1298 0 : type = STATIC_IPV6_GATEWAY;
1299 0 : gate = &gate_addr;
1300 : }
1301 : else
1302 : {
1303 0 : type = STATIC_IPV6_IFNAME;
1304 0 : ifname = gate_str;
1305 : }
1306 : }
1307 :
1308 0 : if (add_cmd)
1309 0 : static_add_ipv6 (&p, &src_p, type, gate, ifname, flag, distance, table);
1310 : else
1311 0 : static_delete_ipv6 (&p, &src_p, type, gate, ifname, distance, table);
1312 :
1313 0 : return CMD_SUCCESS;
1314 : }
1315 :
1316 0 : DEFUN (ipv6_route,
1317 : ipv6_route_cmd,
1318 : "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE)",
1319 : IP_STR
1320 : "Establish static routes\n"
1321 : "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1322 : "IPv6 gateway address\n"
1323 : "IPv6 gateway interface name\n")
1324 : {
1325 0 : return static_ipv6_func (vty, 1, argv[0], NULL, argv[1], NULL, NULL, NULL);
1326 : }
1327 :
1328 0 : DEFUN (ipv6_route_flags,
1329 : ipv6_route_flags_cmd,
1330 : "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole)",
1331 : IP_STR
1332 : "Establish static routes\n"
1333 : "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1334 : "IPv6 gateway address\n"
1335 : "IPv6 gateway interface name\n"
1336 : "Emit an ICMP unreachable when matched\n"
1337 : "Silently discard pkts when matched\n")
1338 : {
1339 0 : return static_ipv6_func (vty, 1, argv[0], NULL, argv[1], NULL, argv[2], NULL);
1340 : }
1341 :
1342 0 : DEFUN (ipv6_route_ifname,
1343 : ipv6_route_ifname_cmd,
1344 : "ipv6 route X:X::X:X/M X:X::X:X INTERFACE",
1345 : IP_STR
1346 : "Establish static routes\n"
1347 : "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1348 : "IPv6 gateway address\n"
1349 : "IPv6 gateway interface name\n")
1350 : {
1351 0 : return static_ipv6_func (vty, 1, argv[0], NULL, argv[1], argv[2], NULL, NULL);
1352 : }
1353 :
1354 0 : DEFUN (ipv6_route_ifname_flags,
1355 : ipv6_route_ifname_flags_cmd,
1356 : "ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole)",
1357 : IP_STR
1358 : "Establish static routes\n"
1359 : "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1360 : "IPv6 gateway address\n"
1361 : "IPv6 gateway interface name\n"
1362 : "Emit an ICMP unreachable when matched\n"
1363 : "Silently discard pkts when matched\n")
1364 : {
1365 0 : return static_ipv6_func (vty, 1, argv[0], NULL, argv[1], argv[2], argv[3], NULL);
1366 : }
1367 :
1368 0 : DEFUN (ipv6_route_pref,
1369 : ipv6_route_pref_cmd,
1370 : "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <1-255>",
1371 : IP_STR
1372 : "Establish static routes\n"
1373 : "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1374 : "IPv6 gateway address\n"
1375 : "IPv6 gateway interface name\n"
1376 : "Distance value for this prefix\n")
1377 : {
1378 0 : return static_ipv6_func (vty, 1, argv[0], NULL, argv[1], NULL, NULL, argv[2]);
1379 : }
1380 :
1381 0 : DEFUN (ipv6_route_flags_pref,
1382 : ipv6_route_flags_pref_cmd,
1383 : "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) <1-255>",
1384 : IP_STR
1385 : "Establish static routes\n"
1386 : "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1387 : "IPv6 gateway address\n"
1388 : "IPv6 gateway interface name\n"
1389 : "Emit an ICMP unreachable when matched\n"
1390 : "Silently discard pkts when matched\n"
1391 : "Distance value for this prefix\n")
1392 : {
1393 0 : return static_ipv6_func (vty, 1, argv[0], NULL, argv[1], NULL, argv[2], argv[3]);
1394 : }
1395 :
1396 0 : DEFUN (ipv6_route_ifname_pref,
1397 : ipv6_route_ifname_pref_cmd,
1398 : "ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255>",
1399 : IP_STR
1400 : "Establish static routes\n"
1401 : "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1402 : "IPv6 gateway address\n"
1403 : "IPv6 gateway interface name\n"
1404 : "Distance value for this prefix\n")
1405 : {
1406 0 : return static_ipv6_func (vty, 1, argv[0], NULL, argv[1], argv[2], NULL, argv[3]);
1407 : }
1408 :
1409 0 : DEFUN (ipv6_route_ifname_flags_pref,
1410 : ipv6_route_ifname_flags_pref_cmd,
1411 : "ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) <1-255>",
1412 : IP_STR
1413 : "Establish static routes\n"
1414 : "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1415 : "IPv6 gateway address\n"
1416 : "IPv6 gateway interface name\n"
1417 : "Emit an ICMP unreachable when matched\n"
1418 : "Silently discard pkts when matched\n"
1419 : "Distance value for this prefix\n")
1420 : {
1421 0 : return static_ipv6_func (vty, 1, argv[0], NULL, argv[1], argv[2], argv[3], argv[4]);
1422 : }
1423 :
1424 0 : DEFUN (no_ipv6_route,
1425 : no_ipv6_route_cmd,
1426 : "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE)",
1427 : NO_STR
1428 : IP_STR
1429 : "Establish static routes\n"
1430 : "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1431 : "IPv6 gateway address\n"
1432 : "IPv6 gateway interface name\n")
1433 : {
1434 0 : return static_ipv6_func (vty, 0, argv[0], NULL, argv[1], NULL, NULL, NULL);
1435 : }
1436 :
1437 : ALIAS (no_ipv6_route,
1438 : no_ipv6_route_flags_cmd,
1439 : "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole)",
1440 : NO_STR
1441 : IP_STR
1442 : "Establish static routes\n"
1443 : "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1444 : "IPv6 gateway address\n"
1445 : "IPv6 gateway interface name\n"
1446 : "Emit an ICMP unreachable when matched\n"
1447 : "Silently discard pkts when matched\n")
1448 :
1449 0 : DEFUN (no_ipv6_route_ifname,
1450 : no_ipv6_route_ifname_cmd,
1451 : "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE",
1452 : NO_STR
1453 : IP_STR
1454 : "Establish static routes\n"
1455 : "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1456 : "IPv6 gateway address\n"
1457 : "IPv6 gateway interface name\n")
1458 : {
1459 0 : return static_ipv6_func (vty, 0, argv[0], NULL, argv[1], argv[2], NULL, NULL);
1460 : }
1461 :
1462 : ALIAS (no_ipv6_route_ifname,
1463 : no_ipv6_route_ifname_flags_cmd,
1464 : "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole)",
1465 : NO_STR
1466 : IP_STR
1467 : "Establish static routes\n"
1468 : "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1469 : "IPv6 gateway address\n"
1470 : "IPv6 gateway interface name\n"
1471 : "Emit an ICMP unreachable when matched\n"
1472 : "Silently discard pkts when matched\n")
1473 :
1474 0 : DEFUN (no_ipv6_route_pref,
1475 : no_ipv6_route_pref_cmd,
1476 : "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <1-255>",
1477 : NO_STR
1478 : IP_STR
1479 : "Establish static routes\n"
1480 : "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1481 : "IPv6 gateway address\n"
1482 : "IPv6 gateway interface name\n"
1483 : "Distance value for this prefix\n")
1484 : {
1485 0 : return static_ipv6_func (vty, 0, argv[0], NULL, argv[1], NULL, NULL, argv[2]);
1486 : }
1487 :
1488 0 : DEFUN (no_ipv6_route_flags_pref,
1489 : no_ipv6_route_flags_pref_cmd,
1490 : "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) <1-255>",
1491 : NO_STR
1492 : IP_STR
1493 : "Establish static routes\n"
1494 : "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1495 : "IPv6 gateway address\n"
1496 : "IPv6 gateway interface name\n"
1497 : "Emit an ICMP unreachable when matched\n"
1498 : "Silently discard pkts when matched\n"
1499 : "Distance value for this prefix\n")
1500 : {
1501 : /* We do not care about argv[2] */
1502 0 : return static_ipv6_func (vty, 0, argv[0], NULL, argv[1], NULL, argv[2], argv[3]);
1503 : }
1504 :
1505 0 : DEFUN (no_ipv6_route_ifname_pref,
1506 : no_ipv6_route_ifname_pref_cmd,
1507 : "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255>",
1508 : NO_STR
1509 : IP_STR
1510 : "Establish static routes\n"
1511 : "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1512 : "IPv6 gateway address\n"
1513 : "IPv6 gateway interface name\n"
1514 : "Distance value for this prefix\n")
1515 : {
1516 0 : return static_ipv6_func (vty, 0, argv[0], NULL, argv[1], argv[2], NULL, argv[3]);
1517 : }
1518 :
1519 0 : DEFUN (no_ipv6_route_ifname_flags_pref,
1520 : no_ipv6_route_ifname_flags_pref_cmd,
1521 : "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) <1-255>",
1522 : NO_STR
1523 : IP_STR
1524 : "Establish static routes\n"
1525 : "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1526 : "IPv6 gateway address\n"
1527 : "IPv6 gateway interface name\n"
1528 : "Emit an ICMP unreachable when matched\n"
1529 : "Silently discard pkts when matched\n"
1530 : "Distance value for this prefix\n")
1531 : {
1532 0 : return static_ipv6_func (vty, 0, argv[0], NULL, argv[1], argv[2], argv[3], argv[4]);
1533 : }
1534 :
1535 : /* IPv6 static routes with source sensitivity */
1536 0 : DEFUN (ipv6_route_from,
1537 : ipv6_route_from_cmd,
1538 : "ipv6 route X:X::X:X/M from X:X::X:X/M (X:X::X:X|INTERFACE)",
1539 : IP_STR
1540 : "Establish static routes\n"
1541 : "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1542 : "Install a source specific route\n"
1543 : "IPv6 source prefix (e.g. 3ffe:506::/32)\n"
1544 : "IPv6 gateway address\n"
1545 : "IPv6 gateway interface name\n")
1546 : {
1547 0 : return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], NULL, NULL, NULL);
1548 : }
1549 :
1550 0 : DEFUN (ipv6_route_from_flags,
1551 : ipv6_route_from_flags_cmd,
1552 : "ipv6 route X:X::X:X/M from X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole)",
1553 : IP_STR
1554 : "Establish static routes\n"
1555 : "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1556 : "Install a source specific route\n"
1557 : "IPv6 source prefix (e.g. 3ffe:506::/32)\n"
1558 : "IPv6 gateway address\n"
1559 : "IPv6 gateway interface name\n"
1560 : "Emit an ICMP unreachable when matched\n"
1561 : "Silently discard pkts when matched\n")
1562 : {
1563 0 : return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], NULL, argv[3], NULL);
1564 : }
1565 :
1566 0 : DEFUN (ipv6_route_from_ifname,
1567 : ipv6_route_from_ifname_cmd,
1568 : "ipv6 route X:X::X:X/M from X:X::X:X/M X:X::X:X INTERFACE",
1569 : IP_STR
1570 : "Establish static routes\n"
1571 : "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1572 : "Install a source specific route\n"
1573 : "IPv6 source prefix (e.g. 3ffe:506::/32)\n"
1574 : "IPv6 gateway address\n"
1575 : "IPv6 gateway interface name\n")
1576 : {
1577 0 : return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], argv[3], NULL, NULL);
1578 : }
1579 :
1580 0 : DEFUN (ipv6_route_from_ifname_flags,
1581 : ipv6_route_from_ifname_flags_cmd,
1582 : "ipv6 route X:X::X:X/M from X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole)",
1583 : IP_STR
1584 : "Establish static routes\n"
1585 : "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1586 : "Install a source specific route\n"
1587 : "IPv6 source prefix (e.g. 3ffe:506::/32)\n"
1588 : "IPv6 gateway address\n"
1589 : "IPv6 gateway interface name\n"
1590 : "Emit an ICMP unreachable when matched\n"
1591 : "Silently discard pkts when matched\n")
1592 : {
1593 0 : return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], argv[3], argv[4], NULL);
1594 : }
1595 :
1596 0 : DEFUN (ipv6_route_from_pref,
1597 : ipv6_route_from_pref_cmd,
1598 : "ipv6 route X:X::X:X/M from X:X::X:X/M (X:X::X:X|INTERFACE) <1-255>",
1599 : IP_STR
1600 : "Establish static routes\n"
1601 : "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1602 : "Install a source specific route\n"
1603 : "IPv6 source prefix (e.g. 3ffe:506::/32)\n"
1604 : "IPv6 gateway address\n"
1605 : "IPv6 gateway interface name\n"
1606 : "Distance value for this prefix\n")
1607 : {
1608 0 : return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], NULL, NULL, argv[3]);
1609 : }
1610 :
1611 0 : DEFUN (ipv6_route_from_flags_pref,
1612 : ipv6_route_from_flags_pref_cmd,
1613 : "ipv6 route X:X::X:X/M from X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) <1-255>",
1614 : IP_STR
1615 : "Establish static routes\n"
1616 : "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1617 : "Install a source specific route\n"
1618 : "IPv6 source prefix (e.g. 3ffe:506::/32)\n"
1619 : "IPv6 gateway address\n"
1620 : "IPv6 gateway interface name\n"
1621 : "Emit an ICMP unreachable when matched\n"
1622 : "Silently discard pkts when matched\n"
1623 : "Distance value for this prefix\n")
1624 : {
1625 0 : return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], NULL, argv[3], argv[4]);
1626 : }
1627 :
1628 0 : DEFUN (ipv6_route_from_ifname_pref,
1629 : ipv6_route_from_ifname_pref_cmd,
1630 : "ipv6 route X:X::X:X/M from X:X::X:X/M X:X::X:X INTERFACE <1-255>",
1631 : IP_STR
1632 : "Establish static routes\n"
1633 : "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1634 : "Install a source specific route\n"
1635 : "IPv6 source prefix (e.g. 3ffe:506::/32)\n"
1636 : "IPv6 gateway address\n"
1637 : "IPv6 gateway interface name\n"
1638 : "Distance value for this prefix\n")
1639 : {
1640 0 : return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], argv[3], NULL, argv[4]);
1641 : }
1642 :
1643 0 : DEFUN (ipv6_route_from_ifname_flags_pref,
1644 : ipv6_route_from_ifname_flags_pref_cmd,
1645 : "ipv6 route X:X::X:X/M from X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) <1-255>",
1646 : IP_STR
1647 : "Establish static routes\n"
1648 : "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1649 : "Install a source specific route\n"
1650 : "IPv6 source prefix (e.g. 3ffe:506::/32)\n"
1651 : "IPv6 gateway address\n"
1652 : "IPv6 gateway interface name\n"
1653 : "Emit an ICMP unreachable when matched\n"
1654 : "Silently discard pkts when matched\n"
1655 : "Distance value for this prefix\n")
1656 : {
1657 0 : return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]);
1658 : }
1659 :
1660 0 : DEFUN (no_ipv6_route_from,
1661 : no_ipv6_route_from_cmd,
1662 : "no ipv6 route X:X::X:X/M from X:X::X:X/M (X:X::X:X|INTERFACE)",
1663 : NO_STR
1664 : IP_STR
1665 : "Establish static routes\n"
1666 : "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1667 : "Install a source specific route\n"
1668 : "IPv6 source prefix (e.g. 3ffe:506::/32)\n"
1669 : "IPv6 gateway address\n"
1670 : "IPv6 gateway interface name\n")
1671 : {
1672 0 : return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], NULL, NULL, NULL);
1673 : }
1674 :
1675 : ALIAS (no_ipv6_route_from,
1676 : no_ipv6_route_from_flags_cmd,
1677 : "no ipv6 route X:X::X:X/M from X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole)",
1678 : NO_STR
1679 : IP_STR
1680 : "Establish static routes\n"
1681 : "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1682 : "Install a source specific route\n"
1683 : "IPv6 source prefix (e.g. 3ffe:506::/32)\n"
1684 : "IPv6 gateway address\n"
1685 : "IPv6 gateway interface name\n"
1686 : "Emit an ICMP unreachable when matched\n"
1687 : "Silently discard pkts when matched\n")
1688 :
1689 0 : DEFUN (no_ipv6_route_from_ifname,
1690 : no_ipv6_route_from_ifname_cmd,
1691 : "no ipv6 route X:X::X:X/M from X:X::X:X/M X:X::X:X INTERFACE",
1692 : NO_STR
1693 : IP_STR
1694 : "Establish static routes\n"
1695 : "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1696 : "Install a source specific route\n"
1697 : "IPv6 source prefix (e.g. 3ffe:506::/32)\n"
1698 : "IPv6 gateway address\n"
1699 : "IPv6 gateway interface name\n")
1700 : {
1701 0 : return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], argv[3], NULL, NULL);
1702 : }
1703 :
1704 : ALIAS (no_ipv6_route_from_ifname,
1705 : no_ipv6_route_from_ifname_flags_cmd,
1706 : "no ipv6 route X:X::X:X/M from X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole)",
1707 : NO_STR
1708 : IP_STR
1709 : "Establish static routes\n"
1710 : "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1711 : "Install a source specific route\n"
1712 : "IPv6 source prefix (e.g. 3ffe:506::/32)\n"
1713 : "IPv6 gateway address\n"
1714 : "IPv6 gateway interface name\n"
1715 : "Emit an ICMP unreachable when matched\n"
1716 : "Silently discard pkts when matched\n")
1717 :
1718 0 : DEFUN (no_ipv6_route_from_pref,
1719 : no_ipv6_route_from_pref_cmd,
1720 : "no ipv6 route X:X::X:X/M from X:X::X:X/M (X:X::X:X|INTERFACE) <1-255>",
1721 : NO_STR
1722 : IP_STR
1723 : "Establish static routes\n"
1724 : "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1725 : "Install a source specific route\n"
1726 : "IPv6 source prefix (e.g. 3ffe:506::/32)\n"
1727 : "IPv6 gateway address\n"
1728 : "IPv6 gateway interface name\n"
1729 : "Distance value for this prefix\n")
1730 : {
1731 0 : return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], NULL, NULL, argv[3]);
1732 : }
1733 :
1734 0 : DEFUN (no_ipv6_route_from_flags_pref,
1735 : no_ipv6_route_from_flags_pref_cmd,
1736 : "no ipv6 route X:X::X:X/M from X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) <1-255>",
1737 : NO_STR
1738 : IP_STR
1739 : "Establish static routes\n"
1740 : "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1741 : "Install a source specific route\n"
1742 : "IPv6 source prefix (e.g. 3ffe:506::/32)\n"
1743 : "IPv6 gateway address\n"
1744 : "IPv6 gateway interface name\n"
1745 : "Emit an ICMP unreachable when matched\n"
1746 : "Silently discard pkts when matched\n"
1747 : "Distance value for this prefix\n")
1748 : {
1749 : /* We do not care about argv[2] */
1750 0 : return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], NULL, argv[3], argv[4]);
1751 : }
1752 :
1753 0 : DEFUN (no_ipv6_route_from_ifname_pref,
1754 : no_ipv6_route_from_ifname_pref_cmd,
1755 : "no ipv6 route X:X::X:X/M from X:X::X:X/M X:X::X:X INTERFACE <1-255>",
1756 : NO_STR
1757 : IP_STR
1758 : "Establish static routes\n"
1759 : "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1760 : "Install a source specific route\n"
1761 : "IPv6 source prefix (e.g. 3ffe:506::/32)\n"
1762 : "IPv6 gateway address\n"
1763 : "IPv6 gateway interface name\n"
1764 : "Distance value for this prefix\n")
1765 : {
1766 0 : return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], argv[3], NULL, argv[4]);
1767 : }
1768 :
1769 0 : DEFUN (no_ipv6_route_from_ifname_flags_pref,
1770 : no_ipv6_route_from_ifname_flags_pref_cmd,
1771 : "no ipv6 route X:X::X:X/M from X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) <1-255>",
1772 : NO_STR
1773 : IP_STR
1774 : "Establish static routes\n"
1775 : "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1776 : "Install a source specific route\n"
1777 : "IPv6 source prefix (e.g. 3ffe:506::/32)\n"
1778 : "IPv6 gateway address\n"
1779 : "IPv6 gateway interface name\n"
1780 : "Emit an ICMP unreachable when matched\n"
1781 : "Silently discard pkts when matched\n"
1782 : "Distance value for this prefix\n")
1783 : {
1784 0 : return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]);
1785 : }
1786 :
1787 : /* New RIB. Detailed information for IPv6 route. */
1788 : static void
1789 0 : vty_show_ipv6_route_detail (struct vty *vty, struct route_node *rn)
1790 : {
1791 : struct rib *rib;
1792 : struct nexthop *nexthop, *tnexthop;
1793 : int recursing;
1794 : char buf[BUFSIZ];
1795 :
1796 0 : RNODE_FOREACH_RIB (rn, rib)
1797 : {
1798 0 : vty_out (vty, "Routing entry for %s/%d%s",
1799 0 : inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, BUFSIZ),
1800 0 : rn->p.prefixlen,
1801 0 : VTY_NEWLINE);
1802 0 : vty_out (vty, " Known via \"%s\"", zebra_route_string (rib->type));
1803 0 : vty_out (vty, ", distance %u, metric %u", rib->distance, rib->metric);
1804 0 : if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
1805 0 : vty_out (vty, ", best");
1806 0 : if (rib->refcnt)
1807 0 : vty_out (vty, ", refcnt %ld", rib->refcnt);
1808 0 : if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
1809 0 : vty_out (vty, ", blackhole");
1810 0 : if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT))
1811 0 : vty_out (vty, ", reject");
1812 0 : vty_out (vty, "%s", VTY_NEWLINE);
1813 :
1814 : #define ONE_DAY_SECOND 60*60*24
1815 : #define ONE_WEEK_SECOND 60*60*24*7
1816 0 : if (rib->type == ZEBRA_ROUTE_RIPNG
1817 0 : || rib->type == ZEBRA_ROUTE_OSPF6
1818 0 : || rib->type == ZEBRA_ROUTE_BABEL
1819 0 : || rib->type == ZEBRA_ROUTE_ISIS
1820 0 : || rib->type == ZEBRA_ROUTE_BGP)
1821 : {
1822 : time_t uptime;
1823 : struct tm *tm;
1824 :
1825 0 : uptime = time (NULL);
1826 0 : uptime -= rib->uptime;
1827 0 : tm = gmtime (&uptime);
1828 :
1829 0 : vty_out (vty, " Last update ");
1830 :
1831 0 : if (uptime < ONE_DAY_SECOND)
1832 0 : vty_out (vty, "%02d:%02d:%02d",
1833 : tm->tm_hour, tm->tm_min, tm->tm_sec);
1834 0 : else if (uptime < ONE_WEEK_SECOND)
1835 0 : vty_out (vty, "%dd%02dh%02dm",
1836 : tm->tm_yday, tm->tm_hour, tm->tm_min);
1837 : else
1838 0 : vty_out (vty, "%02dw%dd%02dh",
1839 0 : tm->tm_yday/7,
1840 0 : tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
1841 0 : vty_out (vty, " ago%s", VTY_NEWLINE);
1842 : }
1843 :
1844 0 : for (ALL_NEXTHOPS_RO(rib->nexthop, nexthop, tnexthop, recursing))
1845 : {
1846 0 : vty_out (vty, " %c%s",
1847 0 : CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB) ? '*' : ' ',
1848 : recursing ? " " : "");
1849 :
1850 0 : switch (nexthop->type)
1851 : {
1852 : case NEXTHOP_TYPE_IPV6:
1853 : case NEXTHOP_TYPE_IPV6_IFINDEX:
1854 : case NEXTHOP_TYPE_IPV6_IFNAME:
1855 0 : vty_out (vty, " %s",
1856 0 : inet_ntop (AF_INET6, &nexthop->gate.ipv6, buf, BUFSIZ));
1857 0 : if (nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME)
1858 0 : vty_out (vty, ", %s", nexthop->ifname);
1859 0 : else if (nexthop->ifindex)
1860 0 : vty_out (vty, ", via %s", ifindex2ifname (nexthop->ifindex));
1861 0 : break;
1862 : case NEXTHOP_TYPE_IFINDEX:
1863 0 : vty_out (vty, " directly connected, %s",
1864 : ifindex2ifname (nexthop->ifindex));
1865 0 : break;
1866 : case NEXTHOP_TYPE_IFNAME:
1867 0 : vty_out (vty, " directly connected, %s",
1868 : nexthop->ifname);
1869 0 : break;
1870 : default:
1871 0 : break;
1872 : }
1873 0 : if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
1874 0 : vty_out (vty, " inactive");
1875 :
1876 0 : if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ONLINK))
1877 0 : vty_out (vty, " onlink");
1878 :
1879 0 : if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
1880 0 : vty_out (vty, " (recursive)");
1881 :
1882 0 : vty_out (vty, "%s", VTY_NEWLINE);
1883 : }
1884 0 : vty_out (vty, "%s", VTY_NEWLINE);
1885 : }
1886 0 : }
1887 :
1888 : static void
1889 204 : vty_show_ipv6_route (struct vty *vty, struct route_node *rn,
1890 : struct rib *rib)
1891 : {
1892 : struct nexthop *nexthop, *tnexthop;
1893 : struct prefix *dst_p, *src_p;
1894 :
1895 204 : srcdest_rnode_prefixes(rn, &dst_p, &src_p);
1896 : int recursing;
1897 204 : int len = 0;
1898 : char buf[BUFSIZ];
1899 204 : char srcdest_info[BUFSIZ] = "";
1900 :
1901 204 : if (src_p)
1902 : {
1903 16 : snprintf (srcdest_info, sizeof (srcdest_info), " from %s/%d",
1904 8 : inet_ntop (AF_INET6, &src_p->u.prefix6, buf, BUFSIZ),
1905 8 : src_p->prefixlen);
1906 : }
1907 :
1908 : /* Nexthop information. */
1909 411 : for (ALL_NEXTHOPS_RO(rib->nexthop, nexthop, tnexthop, recursing))
1910 : {
1911 207 : if (nexthop == rib->nexthop)
1912 : {
1913 : /* Prefix information. */
1914 1020 : len = vty_out (vty, "%c%c%c %s/%d%s",
1915 204 : zebra_route_char (rib->type),
1916 204 : CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED)
1917 : ? '>' : ' ',
1918 204 : CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
1919 : ? '*' : ' ',
1920 204 : inet_ntop (AF_INET6, &dst_p->u.prefix6, buf, BUFSIZ),
1921 204 : dst_p->prefixlen,
1922 : srcdest_info);
1923 :
1924 : /* Distance and metric display. */
1925 204 : if (rib->type != ZEBRA_ROUTE_CONNECT
1926 41 : && rib->type != ZEBRA_ROUTE_KERNEL)
1927 41 : len += vty_out (vty, " [%d/%d]", rib->distance,
1928 : rib->metric);
1929 : }
1930 : else
1931 6 : vty_out (vty, " %c%*c",
1932 3 : CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
1933 : ? '*' : ' ',
1934 3 : len - 3 + (2 * recursing), ' ');
1935 :
1936 207 : switch (nexthop->type)
1937 : {
1938 : case NEXTHOP_TYPE_IPV6:
1939 : case NEXTHOP_TYPE_IPV6_IFINDEX:
1940 : case NEXTHOP_TYPE_IPV6_IFNAME:
1941 35 : vty_out (vty, " via %s",
1942 35 : inet_ntop (AF_INET6, &nexthop->gate.ipv6, buf, BUFSIZ));
1943 35 : if (nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME)
1944 0 : vty_out (vty, ", %s", nexthop->ifname);
1945 35 : else if (nexthop->ifindex)
1946 29 : vty_out (vty, ", %s", ifindex2ifname (nexthop->ifindex));
1947 35 : break;
1948 : case NEXTHOP_TYPE_IFINDEX:
1949 172 : vty_out (vty, " is directly connected, %s",
1950 : ifindex2ifname (nexthop->ifindex));
1951 172 : break;
1952 : case NEXTHOP_TYPE_IFNAME:
1953 0 : vty_out (vty, " is directly connected, %s",
1954 : nexthop->ifname);
1955 0 : break;
1956 : default:
1957 0 : break;
1958 : }
1959 207 : if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
1960 3 : vty_out (vty, " inactive");
1961 :
1962 207 : if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
1963 3 : vty_out (vty, " (recursive)");
1964 :
1965 207 : if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
1966 0 : vty_out (vty, ", bh");
1967 207 : if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT))
1968 0 : vty_out (vty, ", rej");
1969 :
1970 207 : if (rib->type == ZEBRA_ROUTE_RIPNG
1971 207 : || rib->type == ZEBRA_ROUTE_OSPF6
1972 191 : || rib->type == ZEBRA_ROUTE_BABEL
1973 191 : || rib->type == ZEBRA_ROUTE_ISIS
1974 191 : || rib->type == ZEBRA_ROUTE_BGP)
1975 : {
1976 : time_t uptime;
1977 : struct tm *tm;
1978 :
1979 23 : uptime = time (NULL);
1980 23 : uptime -= rib->uptime;
1981 23 : tm = gmtime (&uptime);
1982 :
1983 : #define ONE_DAY_SECOND 60*60*24
1984 : #define ONE_WEEK_SECOND 60*60*24*7
1985 :
1986 23 : if (uptime < ONE_DAY_SECOND)
1987 23 : vty_out (vty, ", %02d:%02d:%02d",
1988 : tm->tm_hour, tm->tm_min, tm->tm_sec);
1989 0 : else if (uptime < ONE_WEEK_SECOND)
1990 0 : vty_out (vty, ", %dd%02dh%02dm",
1991 : tm->tm_yday, tm->tm_hour, tm->tm_min);
1992 : else
1993 0 : vty_out (vty, ", %02dw%dd%02dh",
1994 0 : tm->tm_yday/7,
1995 0 : tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
1996 : }
1997 207 : vty_out (vty, "%s", VTY_NEWLINE);
1998 : }
1999 204 : }
2000 :
2001 35 : DEFUN (show_ipv6_route,
2002 : show_ipv6_route_cmd,
2003 : "show ipv6 route",
2004 : SHOW_STR
2005 : IP_STR
2006 : "IPv6 routing table\n")
2007 : {
2008 : struct route_table *table;
2009 : struct route_node *rn;
2010 : struct rib *rib;
2011 35 : int first = 1;
2012 :
2013 35 : table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
2014 35 : if (! table)
2015 0 : return CMD_SUCCESS;
2016 :
2017 : /* Show all IPv6 route. */
2018 352 : for (rn = route_top (table); rn; rn = srcdest_route_next (rn))
2019 : {
2020 521 : RNODE_FOREACH_RIB (rn, rib)
2021 : {
2022 204 : if (first)
2023 : {
2024 35 : vty_out (vty, SHOW_ROUTE_V6_HEADER);
2025 35 : first = 0;
2026 : }
2027 204 : vty_show_ipv6_route (vty, rn, rib);
2028 : }
2029 : }
2030 35 : return CMD_SUCCESS;
2031 : }
2032 :
2033 0 : DEFUN (show_ipv6_route_prefix_longer,
2034 : show_ipv6_route_prefix_longer_cmd,
2035 : "show ipv6 route X:X::X:X/M longer-prefixes",
2036 : SHOW_STR
2037 : IP_STR
2038 : "IPv6 routing table\n"
2039 : "IPv6 prefix\n"
2040 : "Show route matching the specified Network/Mask pair only\n")
2041 : {
2042 : struct route_table *table;
2043 : struct route_node *rn;
2044 : struct rib *rib;
2045 : struct prefix p;
2046 : int ret;
2047 0 : int first = 1;
2048 :
2049 0 : table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
2050 0 : if (! table)
2051 0 : return CMD_SUCCESS;
2052 :
2053 0 : ret = str2prefix (argv[0], &p);
2054 0 : if (! ret)
2055 : {
2056 0 : vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
2057 0 : return CMD_WARNING;
2058 : }
2059 :
2060 : /* Show matched type IPv6 routes. */
2061 0 : for (rn = route_top (table); rn; rn = route_next (rn))
2062 0 : RNODE_FOREACH_RIB (rn, rib)
2063 0 : if (prefix_match (&p, &rn->p))
2064 : {
2065 0 : if (first)
2066 : {
2067 0 : vty_out (vty, SHOW_ROUTE_V6_HEADER);
2068 0 : first = 0;
2069 : }
2070 0 : vty_show_ipv6_route (vty, rn, rib);
2071 : }
2072 0 : return CMD_SUCCESS;
2073 : }
2074 :
2075 0 : DEFUN (show_ipv6_route_protocol,
2076 : show_ipv6_route_protocol_cmd,
2077 : "show ipv6 route " QUAGGA_IP6_REDIST_STR_ZEBRA,
2078 : SHOW_STR
2079 : IP_STR
2080 : "IP routing table\n"
2081 : QUAGGA_IP6_REDIST_HELP_STR_ZEBRA)
2082 : {
2083 : int type;
2084 : struct route_table *table;
2085 : struct route_node *rn;
2086 : struct rib *rib;
2087 0 : int first = 1;
2088 :
2089 0 : type = proto_redistnum (AFI_IP6, argv[0]);
2090 0 : if (type < 0)
2091 : {
2092 0 : vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
2093 0 : return CMD_WARNING;
2094 : }
2095 :
2096 0 : table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
2097 0 : if (! table)
2098 0 : return CMD_SUCCESS;
2099 :
2100 : /* Show matched type IPv6 routes. */
2101 0 : for (rn = route_top (table); rn; rn = route_next (rn))
2102 0 : RNODE_FOREACH_RIB (rn, rib)
2103 0 : if (rib->type == type)
2104 : {
2105 0 : if (first)
2106 : {
2107 0 : vty_out (vty, SHOW_ROUTE_V6_HEADER);
2108 0 : first = 0;
2109 : }
2110 0 : vty_show_ipv6_route (vty, rn, rib);
2111 : }
2112 0 : return CMD_SUCCESS;
2113 : }
2114 :
2115 0 : DEFUN (show_ipv6_route_addr,
2116 : show_ipv6_route_addr_cmd,
2117 : "show ipv6 route X:X::X:X",
2118 : SHOW_STR
2119 : IP_STR
2120 : "IPv6 routing table\n"
2121 : "IPv6 Address\n")
2122 : {
2123 : int ret;
2124 : struct prefix_ipv6 p;
2125 : struct route_table *table;
2126 : struct route_node *rn;
2127 :
2128 0 : ret = str2prefix_ipv6 (argv[0], &p);
2129 0 : if (ret <= 0)
2130 : {
2131 0 : vty_out (vty, "Malformed IPv6 address%s", VTY_NEWLINE);
2132 0 : return CMD_WARNING;
2133 : }
2134 :
2135 0 : table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
2136 0 : if (! table)
2137 0 : return CMD_SUCCESS;
2138 :
2139 0 : rn = route_node_match (table, (struct prefix *) &p);
2140 0 : if (! rn)
2141 : {
2142 0 : vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
2143 0 : return CMD_WARNING;
2144 : }
2145 :
2146 0 : vty_show_ipv6_route_detail (vty, rn);
2147 :
2148 0 : route_unlock_node (rn);
2149 :
2150 0 : return CMD_SUCCESS;
2151 : }
2152 :
2153 0 : DEFUN (show_ipv6_route_prefix,
2154 : show_ipv6_route_prefix_cmd,
2155 : "show ipv6 route X:X::X:X/M",
2156 : SHOW_STR
2157 : IP_STR
2158 : "IPv6 routing table\n"
2159 : "IPv6 prefix\n")
2160 : {
2161 : int ret;
2162 : struct prefix_ipv6 p;
2163 : struct route_table *table;
2164 : struct route_node *rn;
2165 :
2166 0 : ret = str2prefix_ipv6 (argv[0], &p);
2167 0 : if (ret <= 0)
2168 : {
2169 0 : vty_out (vty, "Malformed IPv6 prefix%s", VTY_NEWLINE);
2170 0 : return CMD_WARNING;
2171 : }
2172 :
2173 0 : table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
2174 0 : if (! table)
2175 0 : return CMD_SUCCESS;
2176 :
2177 0 : rn = route_node_match (table, (struct prefix *) &p);
2178 0 : if (! rn || rn->p.prefixlen != p.prefixlen)
2179 : {
2180 0 : vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
2181 0 : return CMD_WARNING;
2182 : }
2183 :
2184 0 : vty_show_ipv6_route_detail (vty, rn);
2185 :
2186 0 : route_unlock_node (rn);
2187 :
2188 0 : return CMD_SUCCESS;
2189 : }
2190 :
2191 : /* Show route summary. */
2192 0 : DEFUN (show_ipv6_route_summary,
2193 : show_ipv6_route_summary_cmd,
2194 : "show ipv6 route summary",
2195 : SHOW_STR
2196 : IP_STR
2197 : "IPv6 routing table\n"
2198 : "Summary of all IPv6 routes\n")
2199 : {
2200 : struct route_table *table;
2201 :
2202 0 : table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
2203 0 : if (! table)
2204 0 : return CMD_SUCCESS;
2205 :
2206 0 : vty_show_ip_route_summary (vty, table);
2207 :
2208 0 : return CMD_SUCCESS;
2209 : }
2210 :
2211 : /*
2212 : * Show IPv6 mroute command.Used to dump
2213 : * the Multicast routing table.
2214 : */
2215 :
2216 0 : DEFUN (show_ipv6_mroute,
2217 : show_ipv6_mroute_cmd,
2218 : "show ipv6 mroute",
2219 : SHOW_STR
2220 : IP_STR
2221 : "IPv6 Multicast routing table\n")
2222 : {
2223 : struct route_table *table;
2224 : struct route_node *rn;
2225 : struct rib *rib;
2226 0 : int first = 1;
2227 :
2228 0 : table = vrf_table (AFI_IP6, SAFI_MULTICAST, 0);
2229 0 : if (! table)
2230 0 : return CMD_SUCCESS;
2231 :
2232 : /* Show all IPv6 route. */
2233 0 : for (rn = route_top (table); rn; rn = route_next (rn))
2234 0 : RNODE_FOREACH_RIB (rn, rib)
2235 : {
2236 0 : if (first)
2237 : {
2238 0 : vty_out (vty, SHOW_ROUTE_V6_HEADER);
2239 0 : first = 0;
2240 : }
2241 0 : vty_show_ipv6_route (vty, rn, rib);
2242 : }
2243 0 : return CMD_SUCCESS;
2244 : }
2245 :
2246 : /* Write IPv6 static route configuration. */
2247 : static int
2248 0 : static_config_ipv6 (struct vty *vty)
2249 : {
2250 : struct route_node *rn;
2251 : struct static_ipv6 *si;
2252 : int write;
2253 : struct prefix *dst_p, *src_p;
2254 : char buf[BUFSIZ];
2255 : char src_buf[BUFSIZ];
2256 : struct route_table *stable;
2257 :
2258 0 : write = 0;
2259 :
2260 : /* Lookup table. */
2261 0 : stable = vrf_static_table (AFI_IP6, SAFI_UNICAST, 0);
2262 0 : if (! stable)
2263 0 : return -1;
2264 :
2265 0 : for (rn = route_top (stable); rn; rn = srcdest_route_next (rn))
2266 0 : for (si = rn->info; si; si = si->next)
2267 : {
2268 0 : srcdest_rnode_prefixes(rn, &dst_p, &src_p);
2269 0 : prefix2str(dst_p, buf, sizeof(buf));
2270 0 : if (src_p)
2271 0 : prefix2str(src_p, src_buf, sizeof(src_buf));
2272 : else
2273 0 : strncpy(src_buf, "", sizeof(src_buf));
2274 :
2275 0 : vty_out (vty, "ipv6 route %s%s%s", buf,
2276 0 : src_p ? " from " : "",
2277 : src_buf);
2278 :
2279 0 : switch (si->type)
2280 : {
2281 : case STATIC_IPV6_GATEWAY:
2282 0 : vty_out (vty, " %s", inet_ntop (AF_INET6, &si->ipv6, buf, BUFSIZ));
2283 0 : break;
2284 : case STATIC_IPV6_IFNAME:
2285 0 : vty_out (vty, " %s", si->ifname);
2286 0 : break;
2287 : case STATIC_IPV6_GATEWAY_IFNAME:
2288 0 : vty_out (vty, " %s %s",
2289 0 : inet_ntop (AF_INET6, &si->ipv6, buf, BUFSIZ), si->ifname);
2290 0 : break;
2291 : }
2292 :
2293 0 : if (CHECK_FLAG(si->flags, ZEBRA_FLAG_REJECT))
2294 0 : vty_out (vty, " %s", "reject");
2295 :
2296 0 : if (CHECK_FLAG(si->flags, ZEBRA_FLAG_BLACKHOLE))
2297 0 : vty_out (vty, " %s", "blackhole");
2298 :
2299 0 : if (si->distance != ZEBRA_STATIC_DISTANCE_DEFAULT)
2300 0 : vty_out (vty, " %d", si->distance);
2301 0 : vty_out (vty, "%s", VTY_NEWLINE);
2302 :
2303 0 : write = 1;
2304 : }
2305 0 : return write;
2306 : }
2307 : #endif /* HAVE_IPV6 */
2308 :
2309 : /* Static ip route configuration write function. */
2310 : static int
2311 0 : zebra_ip_config (struct vty *vty)
2312 : {
2313 0 : int write = 0;
2314 :
2315 0 : write += static_config_ipv4 (vty);
2316 : #ifdef HAVE_IPV6
2317 0 : write += static_config_ipv6 (vty);
2318 : #endif /* HAVE_IPV6 */
2319 :
2320 0 : return write;
2321 : }
2322 :
2323 : /* ip protocol configuration write function */
2324 0 : static int config_write_protocol(struct vty *vty)
2325 : {
2326 : int i;
2327 :
2328 0 : for (i=0;i<ZEBRA_ROUTE_MAX;i++)
2329 : {
2330 0 : if (proto_rm[AFI_IP][i])
2331 0 : vty_out (vty, "ip protocol %s route-map %s%s", zebra_route_string(i),
2332 0 : proto_rm[AFI_IP][i], VTY_NEWLINE);
2333 : }
2334 0 : if (proto_rm[AFI_IP][ZEBRA_ROUTE_MAX])
2335 0 : vty_out (vty, "ip protocol %s route-map %s%s", "any",
2336 0 : proto_rm[AFI_IP][ZEBRA_ROUTE_MAX], VTY_NEWLINE);
2337 :
2338 0 : return 1;
2339 : }
2340 :
2341 : /* table node for protocol filtering */
2342 : static struct cmd_node protocol_node = { PROTOCOL_NODE, "", 1 };
2343 :
2344 : /* IP node for static routes. */
2345 : static struct cmd_node ip_node = { IP_NODE, "", 1 };
2346 :
2347 : /* Route VTY. */
2348 : void
2349 45 : zebra_vty_init (void)
2350 : {
2351 45 : install_node (&ip_node, zebra_ip_config);
2352 45 : install_node (&protocol_node, config_write_protocol);
2353 :
2354 45 : install_element (CONFIG_NODE, &ip_protocol_cmd);
2355 45 : install_element (CONFIG_NODE, &no_ip_protocol_cmd);
2356 45 : install_element (VIEW_NODE, &show_ip_protocol_cmd);
2357 45 : install_element (ENABLE_NODE, &show_ip_protocol_cmd);
2358 45 : install_element (CONFIG_NODE, &ip_route_cmd);
2359 45 : install_element (CONFIG_NODE, &ip_route_flags_cmd);
2360 45 : install_element (CONFIG_NODE, &ip_route_flags2_cmd);
2361 45 : install_element (CONFIG_NODE, &ip_route_mask_cmd);
2362 45 : install_element (CONFIG_NODE, &ip_route_mask_flags_cmd);
2363 45 : install_element (CONFIG_NODE, &ip_route_mask_flags2_cmd);
2364 45 : install_element (CONFIG_NODE, &no_ip_route_cmd);
2365 45 : install_element (CONFIG_NODE, &no_ip_route_flags_cmd);
2366 45 : install_element (CONFIG_NODE, &no_ip_route_flags2_cmd);
2367 45 : install_element (CONFIG_NODE, &no_ip_route_mask_cmd);
2368 45 : install_element (CONFIG_NODE, &no_ip_route_mask_flags_cmd);
2369 45 : install_element (CONFIG_NODE, &no_ip_route_mask_flags2_cmd);
2370 45 : install_element (CONFIG_NODE, &ip_route_distance_cmd);
2371 45 : install_element (CONFIG_NODE, &ip_route_flags_distance_cmd);
2372 45 : install_element (CONFIG_NODE, &ip_route_flags_distance2_cmd);
2373 45 : install_element (CONFIG_NODE, &ip_route_mask_distance_cmd);
2374 45 : install_element (CONFIG_NODE, &ip_route_mask_flags_distance_cmd);
2375 45 : install_element (CONFIG_NODE, &ip_route_mask_flags_distance2_cmd);
2376 45 : install_element (CONFIG_NODE, &no_ip_route_distance_cmd);
2377 45 : install_element (CONFIG_NODE, &no_ip_route_flags_distance_cmd);
2378 45 : install_element (CONFIG_NODE, &no_ip_route_flags_distance2_cmd);
2379 45 : install_element (CONFIG_NODE, &no_ip_route_mask_flags_distance_cmd);
2380 45 : install_element (CONFIG_NODE, &no_ip_route_mask_flags_distance2_cmd);
2381 :
2382 45 : install_element (VIEW_NODE, &show_ip_route_cmd);
2383 45 : install_element (VIEW_NODE, &show_ip_route_addr_cmd);
2384 45 : install_element (VIEW_NODE, &show_ip_route_prefix_cmd);
2385 45 : install_element (VIEW_NODE, &show_ip_route_prefix_longer_cmd);
2386 45 : install_element (VIEW_NODE, &show_ip_route_protocol_cmd);
2387 45 : install_element (VIEW_NODE, &show_ip_route_supernets_cmd);
2388 45 : install_element (VIEW_NODE, &show_ip_route_summary_cmd);
2389 45 : install_element (ENABLE_NODE, &show_ip_route_cmd);
2390 45 : install_element (ENABLE_NODE, &show_ip_route_addr_cmd);
2391 45 : install_element (ENABLE_NODE, &show_ip_route_prefix_cmd);
2392 45 : install_element (ENABLE_NODE, &show_ip_route_prefix_longer_cmd);
2393 45 : install_element (ENABLE_NODE, &show_ip_route_protocol_cmd);
2394 45 : install_element (ENABLE_NODE, &show_ip_route_supernets_cmd);
2395 45 : install_element (ENABLE_NODE, &show_ip_route_summary_cmd);
2396 :
2397 45 : install_element (VIEW_NODE, &show_ip_mroute_cmd);
2398 45 : install_element (ENABLE_NODE, &show_ip_mroute_cmd);
2399 :
2400 :
2401 : #ifdef HAVE_IPV6
2402 45 : install_element (CONFIG_NODE, &ipv6_route_cmd);
2403 45 : install_element (CONFIG_NODE, &ipv6_route_flags_cmd);
2404 45 : install_element (CONFIG_NODE, &ipv6_route_ifname_cmd);
2405 45 : install_element (CONFIG_NODE, &ipv6_route_ifname_flags_cmd);
2406 45 : install_element (CONFIG_NODE, &no_ipv6_route_cmd);
2407 45 : install_element (CONFIG_NODE, &no_ipv6_route_flags_cmd);
2408 45 : install_element (CONFIG_NODE, &no_ipv6_route_ifname_cmd);
2409 45 : install_element (CONFIG_NODE, &no_ipv6_route_ifname_flags_cmd);
2410 45 : install_element (CONFIG_NODE, &ipv6_route_pref_cmd);
2411 45 : install_element (CONFIG_NODE, &ipv6_route_flags_pref_cmd);
2412 45 : install_element (CONFIG_NODE, &ipv6_route_ifname_pref_cmd);
2413 45 : install_element (CONFIG_NODE, &ipv6_route_ifname_flags_pref_cmd);
2414 45 : install_element (CONFIG_NODE, &no_ipv6_route_pref_cmd);
2415 45 : install_element (CONFIG_NODE, &no_ipv6_route_flags_pref_cmd);
2416 45 : install_element (CONFIG_NODE, &no_ipv6_route_ifname_pref_cmd);
2417 45 : install_element (CONFIG_NODE, &no_ipv6_route_ifname_flags_pref_cmd);
2418 :
2419 45 : install_element (CONFIG_NODE, &ipv6_route_from_cmd);
2420 45 : install_element (CONFIG_NODE, &ipv6_route_from_flags_cmd);
2421 45 : install_element (CONFIG_NODE, &ipv6_route_from_ifname_cmd);
2422 45 : install_element (CONFIG_NODE, &ipv6_route_from_ifname_flags_cmd);
2423 45 : install_element (CONFIG_NODE, &no_ipv6_route_from_cmd);
2424 45 : install_element (CONFIG_NODE, &no_ipv6_route_from_flags_cmd);
2425 45 : install_element (CONFIG_NODE, &no_ipv6_route_from_ifname_cmd);
2426 45 : install_element (CONFIG_NODE, &no_ipv6_route_from_ifname_flags_cmd);
2427 45 : install_element (CONFIG_NODE, &ipv6_route_from_pref_cmd);
2428 45 : install_element (CONFIG_NODE, &ipv6_route_from_flags_pref_cmd);
2429 45 : install_element (CONFIG_NODE, &ipv6_route_from_ifname_pref_cmd);
2430 45 : install_element (CONFIG_NODE, &ipv6_route_from_ifname_flags_pref_cmd);
2431 45 : install_element (CONFIG_NODE, &no_ipv6_route_from_pref_cmd);
2432 45 : install_element (CONFIG_NODE, &no_ipv6_route_from_flags_pref_cmd);
2433 45 : install_element (CONFIG_NODE, &no_ipv6_route_from_ifname_pref_cmd);
2434 45 : install_element (CONFIG_NODE, &no_ipv6_route_from_ifname_flags_pref_cmd);
2435 :
2436 45 : install_element (VIEW_NODE, &show_ipv6_route_cmd);
2437 45 : install_element (VIEW_NODE, &show_ipv6_route_summary_cmd);
2438 45 : install_element (VIEW_NODE, &show_ipv6_route_protocol_cmd);
2439 45 : install_element (VIEW_NODE, &show_ipv6_route_addr_cmd);
2440 45 : install_element (VIEW_NODE, &show_ipv6_route_prefix_cmd);
2441 45 : install_element (VIEW_NODE, &show_ipv6_route_prefix_longer_cmd);
2442 45 : install_element (ENABLE_NODE, &show_ipv6_route_cmd);
2443 45 : install_element (ENABLE_NODE, &show_ipv6_route_protocol_cmd);
2444 45 : install_element (ENABLE_NODE, &show_ipv6_route_addr_cmd);
2445 45 : install_element (ENABLE_NODE, &show_ipv6_route_prefix_cmd);
2446 45 : install_element (ENABLE_NODE, &show_ipv6_route_prefix_longer_cmd);
2447 45 : install_element (ENABLE_NODE, &show_ipv6_route_summary_cmd);
2448 :
2449 45 : install_element (VIEW_NODE, &show_ipv6_mroute_cmd);
2450 45 : install_element (ENABLE_NODE, &show_ipv6_mroute_cmd);
2451 : #endif /* HAVE_IPV6 */
2452 45 : }
|