2 * Copyright (C) 2002 Kunihiro Ishiguro
4 * This file is part of GNU Zebra.
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
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.
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.
30 /* Return route type string for VTY output. */
32 route_type_str (u_char type
)
36 case ZEBRA_ROUTE_SYSTEM
:
38 case ZEBRA_ROUTE_KERNEL
:
40 case ZEBRA_ROUTE_CONNECT
:
42 case ZEBRA_ROUTE_STATIC
:
46 case ZEBRA_ROUTE_RIPNG
:
48 case ZEBRA_ROUTE_OSPF
:
50 case ZEBRA_ROUTE_OSPF6
:
52 case ZEBRA_ROUTE_ISIS
:
61 /* Return route type string for VTY output. */
63 route_type_char (u_char type
)
67 case ZEBRA_ROUTE_SYSTEM
:
69 case ZEBRA_ROUTE_KERNEL
:
71 case ZEBRA_ROUTE_CONNECT
:
73 case ZEBRA_ROUTE_STATIC
:
77 case ZEBRA_ROUTE_RIPNG
:
79 case ZEBRA_ROUTE_OSPF
:
81 case ZEBRA_ROUTE_OSPF6
:
83 case ZEBRA_ROUTE_ISIS
:
92 /* General fucntion for static route. */
94 zebra_static_ipv4 (struct vty
*vty
, int add_cmd
,
95 char *dest_str
, char *mask_str
, char *gate_str
,
96 char *flag_str
, char *distance_str
)
106 ret
= str2prefix (dest_str
, &p
);
109 vty_out (vty
, "%% Malformed address%s", VTY_NEWLINE
);
113 /* Cisco like mask notation. */
116 ret
= inet_aton (mask_str
, &mask
);
119 vty_out (vty
, "%% Malformed address%s", VTY_NEWLINE
);
122 p
.prefixlen
= ip_masklen (mask
);
125 /* Apply mask for given prefix. */
128 /* Administrative distance. */
130 distance
= atoi (distance_str
);
132 distance
= ZEBRA_STATIC_DISTANCE_DEFAULT
;
134 /* Null0 static route. */
135 if ((gate_str
!= NULL
) && (strncasecmp (gate_str
, "Null0", strlen (gate_str
)) == 0))
139 vty_out (vty
, "%% can not have flag %s with Null0%s", flag_str
, VTY_NEWLINE
);
143 static_add_ipv4 (&p
, NULL
, NULL
, ZEBRA_FLAG_BLACKHOLE
, distance
, 0);
145 static_delete_ipv4 (&p
, NULL
, NULL
, distance
, 0);
151 switch(flag_str
[0]) {
154 SET_FLAG (flag
, ZEBRA_FLAG_REJECT
);
158 SET_FLAG (flag
, ZEBRA_FLAG_BLACKHOLE
);
161 vty_out (vty
, "%% Malformed flag %s %s", flag_str
, VTY_NEWLINE
);
166 if (gate_str
== NULL
)
169 static_add_ipv4 (&p
, NULL
, NULL
, flag
, distance
, 0);
171 static_delete_ipv4 (&p
, NULL
, NULL
, distance
, 0);
176 /* When gateway is A.B.C.D format, gate is treated as nexthop
177 address other case gate is treated as interface name. */
178 ret
= inet_aton (gate_str
, &gate
);
185 static_add_ipv4 (&p
, ifname
? NULL
: &gate
, ifname
, flag
, distance
, 0);
187 static_delete_ipv4 (&p
, ifname
? NULL
: &gate
, ifname
, distance
, 0);
192 /* Static route configuration. */
195 "ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0)",
197 "Establish static routes\n"
198 "IP destination prefix (e.g. 10.0.0.0/8)\n"
199 "IP gateway address\n"
200 "IP gateway interface name\n"
203 return zebra_static_ipv4 (vty
, 1, argv
[0], NULL
, argv
[1], NULL
, NULL
);
206 DEFUN (ip_route_flags
,
208 "ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole)",
210 "Establish static routes\n"
211 "IP destination prefix (e.g. 10.0.0.0/8)\n"
212 "IP gateway address\n"
213 "IP gateway interface name\n"
214 "Emit an ICMP unreachable when matched\n"
215 "Silently discard pkts when matched\n")
217 return zebra_static_ipv4 (vty
, 1, argv
[0], NULL
, argv
[1], argv
[2], NULL
);
220 DEFUN (ip_route_flags2
,
222 "ip route A.B.C.D/M (reject|blackhole)",
224 "Establish static routes\n"
225 "IP destination prefix (e.g. 10.0.0.0/8)\n"
226 "Emit an ICMP unreachable when matched\n"
227 "Silently discard pkts when matched\n")
229 return zebra_static_ipv4 (vty
, 1, argv
[0], NULL
, NULL
, argv
[1], NULL
);
232 /* Mask as A.B.C.D format. */
233 DEFUN (ip_route_mask
,
235 "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0)",
237 "Establish static routes\n"
238 "IP destination prefix\n"
239 "IP destination prefix mask\n"
240 "IP gateway address\n"
241 "IP gateway interface name\n"
244 return zebra_static_ipv4 (vty
, 1, argv
[0], argv
[1], argv
[2], NULL
, NULL
);
247 DEFUN (ip_route_mask_flags
,
248 ip_route_mask_flags_cmd
,
249 "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole)",
251 "Establish static routes\n"
252 "IP destination prefix\n"
253 "IP destination prefix mask\n"
254 "IP gateway address\n"
255 "IP gateway interface name\n"
256 "Emit an ICMP unreachable when matched\n"
257 "Silently discard pkts when matched\n")
259 return zebra_static_ipv4 (vty
, 1, argv
[0], argv
[1], argv
[2], argv
[3], NULL
);
262 DEFUN (ip_route_mask_flags2
,
263 ip_route_mask_flags2_cmd
,
264 "ip route A.B.C.D A.B.C.D (reject|blackhole)",
266 "Establish static routes\n"
267 "IP destination prefix\n"
268 "IP destination prefix mask\n"
269 "Emit an ICMP unreachable when matched\n"
270 "Silently discard pkts when matched\n")
272 return zebra_static_ipv4 (vty
, 1, argv
[0], argv
[1], NULL
, argv
[2], NULL
);
275 /* Distance option value. */
276 DEFUN (ip_route_distance
,
277 ip_route_distance_cmd
,
278 "ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0) <1-255>",
280 "Establish static routes\n"
281 "IP destination prefix (e.g. 10.0.0.0/8)\n"
282 "IP gateway address\n"
283 "IP gateway interface name\n"
285 "Distance value for this route\n")
287 return zebra_static_ipv4 (vty
, 1, argv
[0], NULL
, argv
[1], NULL
, argv
[2]);
290 DEFUN (ip_route_flags_distance
,
291 ip_route_flags_distance_cmd
,
292 "ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
294 "Establish static routes\n"
295 "IP destination prefix (e.g. 10.0.0.0/8)\n"
296 "IP gateway address\n"
297 "IP gateway interface name\n"
298 "Emit an ICMP unreachable when matched\n"
299 "Silently discard pkts when matched\n"
300 "Distance value for this route\n")
302 return zebra_static_ipv4 (vty
, 1, argv
[0], NULL
, argv
[1], argv
[2], argv
[3]);
305 DEFUN (ip_route_flags_distance2
,
306 ip_route_flags_distance2_cmd
,
307 "ip route A.B.C.D/M (reject|blackhole) <1-255>",
309 "Establish static routes\n"
310 "IP destination prefix (e.g. 10.0.0.0/8)\n"
311 "Emit an ICMP unreachable when matched\n"
312 "Silently discard pkts when matched\n"
313 "Distance value for this route\n")
315 return zebra_static_ipv4 (vty
, 1, argv
[0], NULL
, NULL
, argv
[1], argv
[2]);
318 DEFUN (ip_route_mask_distance
,
319 ip_route_mask_distance_cmd
,
320 "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0) <1-255>",
322 "Establish static routes\n"
323 "IP destination prefix\n"
324 "IP destination prefix mask\n"
325 "IP gateway address\n"
326 "IP gateway interface name\n"
328 "Distance value for this route\n")
330 return zebra_static_ipv4 (vty
, 1, argv
[0], argv
[1], argv
[2], NULL
, argv
[3]);
333 DEFUN (ip_route_mask_flags_distance
,
334 ip_route_mask_flags_distance_cmd
,
335 "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
337 "Establish static routes\n"
338 "IP destination prefix\n"
339 "IP destination prefix mask\n"
340 "IP gateway address\n"
341 "IP gateway interface name\n"
342 "Distance value for this route\n"
343 "Emit an ICMP unreachable when matched\n"
344 "Silently discard pkts when matched\n")
346 return zebra_static_ipv4 (vty
, 1, argv
[0], argv
[1], argv
[2], argv
[3], argv
[4]);
349 DEFUN (ip_route_mask_flags_distance2
,
350 ip_route_mask_flags_distance2_cmd
,
351 "ip route A.B.C.D A.B.C.D (reject|blackhole) <1-255>",
353 "Establish static routes\n"
354 "IP destination prefix\n"
355 "IP destination prefix mask\n"
356 "Distance value for this route\n"
357 "Emit an ICMP unreachable when matched\n"
358 "Silently discard pkts when matched\n")
360 return zebra_static_ipv4 (vty
, 1, argv
[0], argv
[1], NULL
, argv
[2], argv
[3]);
365 "no ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0)",
368 "Establish static routes\n"
369 "IP destination prefix (e.g. 10.0.0.0/8)\n"
370 "IP gateway address\n"
371 "IP gateway interface name\n"
374 return zebra_static_ipv4 (vty
, 0, argv
[0], NULL
, argv
[1], NULL
, NULL
);
378 no_ip_route_flags_cmd
,
379 "no ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole)",
382 "Establish static routes\n"
383 "IP destination prefix (e.g. 10.0.0.0/8)\n"
384 "IP gateway address\n"
385 "IP gateway interface name\n"
386 "Emit an ICMP unreachable when matched\n"
387 "Silently discard pkts when matched\n")
389 DEFUN (no_ip_route_flags2
,
390 no_ip_route_flags2_cmd
,
391 "no ip route A.B.C.D/M (reject|blackhole)",
394 "Establish static routes\n"
395 "IP destination prefix (e.g. 10.0.0.0/8)\n"
396 "Emit an ICMP unreachable when matched\n"
397 "Silently discard pkts when matched\n")
399 return zebra_static_ipv4 (vty
, 0, argv
[0], NULL
, NULL
, NULL
, NULL
);
402 DEFUN (no_ip_route_mask
,
403 no_ip_route_mask_cmd
,
404 "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0)",
407 "Establish static routes\n"
408 "IP destination prefix\n"
409 "IP destination prefix mask\n"
410 "IP gateway address\n"
411 "IP gateway interface name\n"
414 return zebra_static_ipv4 (vty
, 0, argv
[0], argv
[1], argv
[2], NULL
, NULL
);
417 ALIAS (no_ip_route_mask
,
418 no_ip_route_mask_flags_cmd
,
419 "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole)",
422 "Establish static routes\n"
423 "IP destination prefix\n"
424 "IP destination prefix mask\n"
425 "IP gateway address\n"
426 "IP gateway interface name\n"
427 "Emit an ICMP unreachable when matched\n"
428 "Silently discard pkts when matched\n")
430 DEFUN (no_ip_route_mask_flags2
,
431 no_ip_route_mask_flags2_cmd
,
432 "no ip route A.B.C.D A.B.C.D (reject|blackhole)",
435 "Establish static routes\n"
436 "IP destination prefix\n"
437 "IP destination prefix mask\n"
438 "Emit an ICMP unreachable when matched\n"
439 "Silently discard pkts when matched\n")
441 return zebra_static_ipv4 (vty
, 0, argv
[0], argv
[1], NULL
, NULL
, NULL
);
444 DEFUN (no_ip_route_distance
,
445 no_ip_route_distance_cmd
,
446 "no ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0) <1-255>",
449 "Establish static routes\n"
450 "IP destination prefix (e.g. 10.0.0.0/8)\n"
451 "IP gateway address\n"
452 "IP gateway interface name\n"
454 "Distance value for this route\n")
456 return zebra_static_ipv4 (vty
, 0, argv
[0], NULL
, argv
[1], NULL
, argv
[2]);
459 DEFUN (no_ip_route_flags_distance
,
460 no_ip_route_flags_distance_cmd
,
461 "no ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
464 "Establish static routes\n"
465 "IP destination prefix (e.g. 10.0.0.0/8)\n"
466 "IP gateway address\n"
467 "IP gateway interface name\n"
468 "Emit an ICMP unreachable when matched\n"
469 "Silently discard pkts when matched\n"
470 "Distance value for this route\n")
472 return zebra_static_ipv4 (vty
, 0, argv
[0], NULL
, argv
[1], argv
[2], argv
[3]);
475 DEFUN (no_ip_route_flags_distance2
,
476 no_ip_route_flags_distance2_cmd
,
477 "no ip route A.B.C.D/M (reject|blackhole) <1-255>",
480 "Establish static routes\n"
481 "IP destination prefix (e.g. 10.0.0.0/8)\n"
482 "Emit an ICMP unreachable when matched\n"
483 "Silently discard pkts when matched\n"
484 "Distance value for this route\n")
486 return zebra_static_ipv4 (vty
, 0, argv
[0], NULL
, NULL
, argv
[1], argv
[2]);
489 DEFUN (no_ip_route_mask_distance
,
490 no_ip_route_mask_distance_cmd
,
491 "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0) <1-255>",
494 "Establish static routes\n"
495 "IP destination prefix\n"
496 "IP destination prefix mask\n"
497 "IP gateway address\n"
498 "IP gateway interface name\n"
500 "Distance value for this route\n")
502 return zebra_static_ipv4 (vty
, 0, argv
[0], argv
[1], argv
[2], NULL
, argv
[3]);
505 DEFUN (no_ip_route_mask_flags_distance
,
506 no_ip_route_mask_flags_distance_cmd
,
507 "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
510 "Establish static routes\n"
511 "IP destination prefix\n"
512 "IP destination prefix mask\n"
513 "IP gateway address\n"
514 "IP gateway interface name\n"
515 "Emit an ICMP unreachable when matched\n"
516 "Silently discard pkts when matched\n"
517 "Distance value for this route\n")
519 return zebra_static_ipv4 (vty
, 0, argv
[0], argv
[1], argv
[2], argv
[3], argv
[4]);
522 DEFUN (no_ip_route_mask_flags_distance2
,
523 no_ip_route_mask_flags_distance2_cmd
,
524 "no ip route A.B.C.D A.B.C.D (reject|blackhole) <1-255>",
527 "Establish static routes\n"
528 "IP destination prefix\n"
529 "IP destination prefix mask\n"
530 "Emit an ICMP unreachable when matched\n"
531 "Silently discard pkts when matched\n"
532 "Distance value for this route\n")
534 return zebra_static_ipv4 (vty
, 0, argv
[0], argv
[1], NULL
, argv
[2], argv
[3]);
537 /* New RIB. Detailed information for IPv4 route. */
539 vty_show_ip_route_detail (struct vty
*vty
, struct route_node
*rn
)
542 struct nexthop
*nexthop
;
544 for (rib
= rn
->info
; rib
; rib
= rib
->next
)
546 vty_out (vty
, "Routing entry for %s/%d%s",
547 inet_ntoa (rn
->p
.u
.prefix4
), rn
->p
.prefixlen
,
549 vty_out (vty
, " Known via \"%s\"", route_type_str (rib
->type
));
550 vty_out (vty
, ", distance %d, metric %d", rib
->distance
, rib
->metric
);
551 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_SELECTED
))
552 vty_out (vty
, ", best");
554 vty_out (vty
, ", refcnt %ld", rib
->refcnt
);
555 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_BLACKHOLE
))
556 vty_out (vty
, ", blackhole");
557 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_REJECT
))
558 vty_out (vty
, ", reject");
559 vty_out (vty
, "%s", VTY_NEWLINE
);
561 #define ONE_DAY_SECOND 60*60*24
562 #define ONE_WEEK_SECOND 60*60*24*7
563 if (rib
->type
== ZEBRA_ROUTE_RIP
564 || rib
->type
== ZEBRA_ROUTE_OSPF
565 || rib
->type
== ZEBRA_ROUTE_ISIS
566 || rib
->type
== ZEBRA_ROUTE_BGP
)
571 uptime
= time (NULL
);
572 uptime
-= rib
->uptime
;
573 tm
= gmtime (&uptime
);
575 vty_out (vty
, " Last update ");
577 if (uptime
< ONE_DAY_SECOND
)
578 vty_out (vty
, "%02d:%02d:%02d",
579 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
580 else if (uptime
< ONE_WEEK_SECOND
)
581 vty_out (vty
, "%dd%02dh%02dm",
582 tm
->tm_yday
, tm
->tm_hour
, tm
->tm_min
);
584 vty_out (vty
, "%02dw%dd%02dh",
586 tm
->tm_yday
- ((tm
->tm_yday
/7) * 7), tm
->tm_hour
);
587 vty_out (vty
, " ago%s", VTY_NEWLINE
);
590 for (nexthop
= rib
->nexthop
; nexthop
; nexthop
= nexthop
->next
)
593 CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
) ? '*' : ' ');
595 switch (nexthop
->type
)
597 case NEXTHOP_TYPE_IPV4
:
598 case NEXTHOP_TYPE_IPV4_IFINDEX
:
599 vty_out (vty
, " %s", inet_ntoa (nexthop
->gate
.ipv4
));
600 if (nexthop
->ifindex
)
601 vty_out (vty
, ", via %s", ifindex2ifname (nexthop
->ifindex
));
603 case NEXTHOP_TYPE_IFINDEX
:
604 vty_out (vty
, " directly connected, %s",
605 ifindex2ifname (nexthop
->ifindex
));
607 case NEXTHOP_TYPE_IFNAME
:
608 vty_out (vty
, " directly connected, %s", nexthop
->ifname
);
610 case NEXTHOP_TYPE_BLACKHOLE
:
611 vty_out (vty
, " directly connected, Null0");
616 if (! CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
))
617 vty_out (vty
, " inactive");
619 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_RECURSIVE
))
621 vty_out (vty
, " (recursive");
623 switch (nexthop
->rtype
)
625 case NEXTHOP_TYPE_IPV4
:
626 case NEXTHOP_TYPE_IPV4_IFINDEX
:
627 vty_out (vty
, " via %s)", inet_ntoa (nexthop
->rgate
.ipv4
));
629 case NEXTHOP_TYPE_IFINDEX
:
630 case NEXTHOP_TYPE_IFNAME
:
631 vty_out (vty
, " is directly connected, %s)",
632 ifindex2ifname (nexthop
->rifindex
));
638 vty_out (vty
, "%s", VTY_NEWLINE
);
640 vty_out (vty
, "%s", VTY_NEWLINE
);
645 vty_show_ip_route (struct vty
*vty
, struct route_node
*rn
, struct rib
*rib
)
647 struct nexthop
*nexthop
;
651 /* Nexthop information. */
652 for (nexthop
= rib
->nexthop
; nexthop
; nexthop
= nexthop
->next
)
654 if (nexthop
== rib
->nexthop
)
656 /* Prefix information. */
657 len
= vty_out (vty
, "%c%c%c %s/%d",
658 route_type_char (rib
->type
),
659 CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_SELECTED
)
661 CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
)
663 inet_ntop (AF_INET
, &rn
->p
.u
.prefix
, buf
, BUFSIZ
),
666 /* Distance and metric display. */
667 if (rib
->type
!= ZEBRA_ROUTE_CONNECT
668 && rib
->type
!= ZEBRA_ROUTE_KERNEL
)
669 len
+= vty_out (vty
, " [%d/%d]", rib
->distance
,
673 vty_out (vty
, " %c%*c",
674 CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
)
678 switch (nexthop
->type
)
680 case NEXTHOP_TYPE_IPV4
:
681 case NEXTHOP_TYPE_IPV4_IFINDEX
:
682 vty_out (vty
, " via %s", inet_ntoa (nexthop
->gate
.ipv4
));
683 if (nexthop
->ifindex
)
684 vty_out (vty
, ", %s", ifindex2ifname (nexthop
->ifindex
));
686 case NEXTHOP_TYPE_IFINDEX
:
687 vty_out (vty
, " is directly connected, %s",
688 ifindex2ifname (nexthop
->ifindex
));
690 case NEXTHOP_TYPE_IFNAME
:
691 vty_out (vty
, " is directly connected, %s", nexthop
->ifname
);
693 case NEXTHOP_TYPE_BLACKHOLE
:
694 vty_out (vty
, " is directly connected, Null0");
699 if (! CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
))
700 vty_out (vty
, " inactive");
702 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_RECURSIVE
))
704 vty_out (vty
, " (recursive");
706 switch (nexthop
->rtype
)
708 case NEXTHOP_TYPE_IPV4
:
709 case NEXTHOP_TYPE_IPV4_IFINDEX
:
710 vty_out (vty
, " via %s)", inet_ntoa (nexthop
->rgate
.ipv4
));
712 case NEXTHOP_TYPE_IFINDEX
:
713 case NEXTHOP_TYPE_IFNAME
:
714 vty_out (vty
, " is directly connected, %s)",
715 ifindex2ifname (nexthop
->rifindex
));
722 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_BLACKHOLE
))
723 vty_out (vty
, ", bh");
724 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_REJECT
))
725 vty_out (vty
, ", rej");
727 if (rib
->type
== ZEBRA_ROUTE_RIP
728 || rib
->type
== ZEBRA_ROUTE_OSPF
729 || rib
->type
== ZEBRA_ROUTE_ISIS
730 || rib
->type
== ZEBRA_ROUTE_BGP
)
735 uptime
= time (NULL
);
736 uptime
-= rib
->uptime
;
737 tm
= gmtime (&uptime
);
739 #define ONE_DAY_SECOND 60*60*24
740 #define ONE_WEEK_SECOND 60*60*24*7
742 if (uptime
< ONE_DAY_SECOND
)
743 vty_out (vty
, ", %02d:%02d:%02d",
744 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
745 else if (uptime
< ONE_WEEK_SECOND
)
746 vty_out (vty
, ", %dd%02dh%02dm",
747 tm
->tm_yday
, tm
->tm_hour
, tm
->tm_min
);
749 vty_out (vty
, ", %02dw%dd%02dh",
751 tm
->tm_yday
- ((tm
->tm_yday
/7) * 7), tm
->tm_hour
);
753 vty_out (vty
, "%s", VTY_NEWLINE
);
757 #define SHOW_ROUTE_V4_HEADER "Codes: K - kernel route, C - connected, S - static, R - RIP, O - OSPF,%s I - ISIS, B - BGP, > - selected route, * - FIB route%s%s"
759 DEFUN (show_ip_route
,
764 "IP routing table\n")
766 struct route_table
*table
;
767 struct route_node
*rn
;
771 table
= vrf_table (AFI_IP
, SAFI_UNICAST
, 0);
775 /* Show all IPv4 routes. */
776 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
777 for (rib
= rn
->info
; rib
; rib
= rib
->next
)
781 vty_out (vty
, SHOW_ROUTE_V4_HEADER
, VTY_NEWLINE
, VTY_NEWLINE
,
785 vty_show_ip_route (vty
, rn
, rib
);
790 DEFUN (show_ip_route_prefix_longer
,
791 show_ip_route_prefix_longer_cmd
,
792 "show ip route A.B.C.D/M longer-prefixes",
796 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
797 "Show route matching the specified Network/Mask pair only\n")
799 struct route_table
*table
;
800 struct route_node
*rn
;
806 ret
= str2prefix (argv
[0], &p
);
809 vty_out (vty
, "%% Malformed Prefix%s", VTY_NEWLINE
);
813 table
= vrf_table (AFI_IP
, SAFI_UNICAST
, 0);
817 /* Show matched type IPv4 routes. */
818 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
819 for (rib
= rn
->info
; rib
; rib
= rib
->next
)
820 if (prefix_match (&p
, &rn
->p
))
824 vty_out (vty
, SHOW_ROUTE_V4_HEADER
, VTY_NEWLINE
,
825 VTY_NEWLINE
, VTY_NEWLINE
);
828 vty_show_ip_route (vty
, rn
, rib
);
833 DEFUN (show_ip_route_supernets
,
834 show_ip_route_supernets_cmd
,
835 "show ip route supernets-only",
839 "Show supernet entries only\n")
841 struct route_table
*table
;
842 struct route_node
*rn
;
847 table
= vrf_table (AFI_IP
, SAFI_UNICAST
, 0);
851 /* Show matched type IPv4 routes. */
852 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
853 for (rib
= rn
->info
; rib
; rib
= rib
->next
)
855 addr
= ntohl (rn
->p
.u
.prefix4
.s_addr
);
857 if ((IN_CLASSC (addr
) && rn
->p
.prefixlen
< 24)
858 || (IN_CLASSB (addr
) && rn
->p
.prefixlen
< 16)
859 || (IN_CLASSA (addr
) && rn
->p
.prefixlen
< 8))
863 vty_out (vty
, SHOW_ROUTE_V4_HEADER
, VTY_NEWLINE
,
864 VTY_NEWLINE
, VTY_NEWLINE
);
867 vty_show_ip_route (vty
, rn
, rib
);
873 DEFUN (show_ip_route_protocol
,
874 show_ip_route_protocol_cmd
,
875 "show ip route (bgp|connected|kernel|ospf|rip|static)",
879 "Border Gateway Protocol (BGP)\n"
882 "Open Shortest Path First (OSPF)\n"
884 "Routing Information Protocol (RIP)\n"
888 struct route_table
*table
;
889 struct route_node
*rn
;
893 if (strncmp (argv
[0], "b", 1) == 0)
894 type
= ZEBRA_ROUTE_BGP
;
895 else if (strncmp (argv
[0], "c", 1) == 0)
896 type
= ZEBRA_ROUTE_CONNECT
;
897 else if (strncmp (argv
[0], "k", 1) ==0)
898 type
= ZEBRA_ROUTE_KERNEL
;
899 else if (strncmp (argv
[0], "o", 1) == 0)
900 type
= ZEBRA_ROUTE_OSPF
;
901 else if (strncmp (argv
[0], "i", 1) == 0)
902 type
= ZEBRA_ROUTE_ISIS
;
903 else if (strncmp (argv
[0], "r", 1) == 0)
904 type
= ZEBRA_ROUTE_RIP
;
905 else if (strncmp (argv
[0], "s", 1) == 0)
906 type
= ZEBRA_ROUTE_STATIC
;
909 vty_out (vty
, "Unknown route type%s", VTY_NEWLINE
);
913 table
= vrf_table (AFI_IP
, SAFI_UNICAST
, 0);
917 /* Show matched type IPv4 routes. */
918 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
919 for (rib
= rn
->info
; rib
; rib
= rib
->next
)
920 if (rib
->type
== type
)
924 vty_out (vty
, SHOW_ROUTE_V4_HEADER
,
925 VTY_NEWLINE
, VTY_NEWLINE
, VTY_NEWLINE
);
928 vty_show_ip_route (vty
, rn
, rib
);
933 DEFUN (show_ip_route_addr
,
934 show_ip_route_addr_cmd
,
935 "show ip route A.B.C.D",
939 "Network in the IP routing table to display\n")
942 struct prefix_ipv4 p
;
943 struct route_table
*table
;
944 struct route_node
*rn
;
946 ret
= str2prefix_ipv4 (argv
[0], &p
);
949 vty_out (vty
, "%% Malformed IPv4 address%s", VTY_NEWLINE
);
953 table
= vrf_table (AFI_IP
, SAFI_UNICAST
, 0);
957 rn
= route_node_match (table
, (struct prefix
*) &p
);
960 vty_out (vty
, "%% Network not in table%s", VTY_NEWLINE
);
964 vty_show_ip_route_detail (vty
, rn
);
966 route_unlock_node (rn
);
971 DEFUN (show_ip_route_prefix
,
972 show_ip_route_prefix_cmd
,
973 "show ip route A.B.C.D/M",
977 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
980 struct prefix_ipv4 p
;
981 struct route_table
*table
;
982 struct route_node
*rn
;
984 ret
= str2prefix_ipv4 (argv
[0], &p
);
987 vty_out (vty
, "%% Malformed IPv4 address%s", VTY_NEWLINE
);
991 table
= vrf_table (AFI_IP
, SAFI_UNICAST
, 0);
995 rn
= route_node_match (table
, (struct prefix
*) &p
);
996 if (! rn
|| rn
->p
.prefixlen
!= p
.prefixlen
)
998 vty_out (vty
, "%% Network not in table%s", VTY_NEWLINE
);
1002 vty_show_ip_route_detail (vty
, rn
);
1004 route_unlock_node (rn
);
1010 zebra_show_ip_route (struct vty
*vty
, struct vrf
*vrf
)
1012 vty_out (vty
, "IP routing table name is %s(%d)%s",
1013 vrf
->name
? vrf
->name
: "", vrf
->id
, VTY_NEWLINE
);
1015 vty_out (vty
, "Route Source Networks%s", VTY_NEWLINE
);
1016 vty_out (vty
, "connected %d%s", 0, VTY_NEWLINE
);
1017 vty_out (vty
, "static %d%s", 0, VTY_NEWLINE
);
1018 vty_out (vty
, "rip %d%s", 0, VTY_NEWLINE
);
1020 vty_out (vty
, "bgp %d%s", 0, VTY_NEWLINE
);
1021 vty_out (vty
, " External: %d Internal: %d Local: %d%s",
1022 0, 0, 0, VTY_NEWLINE
);
1024 vty_out (vty
, "ospf %d%s", 0, VTY_NEWLINE
);
1026 " Intra-area: %d Inter-area: %d External-1: %d External-2: %d%s",
1027 0, 0, 0, 0, VTY_NEWLINE
);
1028 vty_out (vty
, " NSSA External-1: %d NSSA External-2: %d%s",
1031 vty_out (vty
, "internal %d%s", 0, VTY_NEWLINE
);
1032 vty_out (vty
, "Total %d%s", 0, VTY_NEWLINE
);
1035 /* Show route summary. */
1036 DEFUN (show_ip_route_summary
,
1037 show_ip_route_summary_cmd
,
1038 "show ip route summary",
1041 "IP routing table\n"
1042 "Summary of all routes\n")
1046 /* Default table id is zero. */
1047 vrf
= vrf_lookup (0);
1050 vty_out (vty
, "%% No Default-IP-Routing-Table%s", VTY_NEWLINE
);
1054 zebra_show_ip_route (vty
, vrf
);
1059 /* Write IPv4 static route configuration. */
1061 static_config_ipv4 (struct vty
*vty
)
1063 struct route_node
*rn
;
1064 struct static_ipv4
*si
;
1065 struct route_table
*stable
;
1071 stable
= vrf_static_table (AFI_IP
, SAFI_UNICAST
, 0);
1075 for (rn
= route_top (stable
); rn
; rn
= route_next (rn
))
1076 for (si
= rn
->info
; si
; si
= si
->next
)
1078 vty_out (vty
, "ip route %s/%d", inet_ntoa (rn
->p
.u
.prefix4
),
1083 case STATIC_IPV4_GATEWAY
:
1084 vty_out (vty
, " %s", inet_ntoa (si
->gate
.ipv4
));
1086 case STATIC_IPV4_IFNAME
:
1087 vty_out (vty
, " %s", si
->gate
.ifname
);
1089 case STATIC_IPV4_BLACKHOLE
:
1090 vty_out (vty
, " Null0");
1094 /* flags are incompatible with STATIC_IPV4_BLACKHOLE */
1095 if (si
->type
!= STATIC_IPV4_BLACKHOLE
)
1097 if (CHECK_FLAG(si
->flags
, ZEBRA_FLAG_REJECT
))
1098 vty_out (vty
, " %s", "reject");
1100 if (CHECK_FLAG(si
->flags
, ZEBRA_FLAG_BLACKHOLE
))
1101 vty_out (vty
, " %s", "blackhole");
1104 if (si
->distance
!= ZEBRA_STATIC_DISTANCE_DEFAULT
)
1105 vty_out (vty
, " %d", si
->distance
);
1107 vty_out (vty
, "%s", VTY_NEWLINE
);
1115 /* General fucntion for IPv6 static route. */
1117 static_ipv6_func (struct vty
*vty
, int add_cmd
, char *dest_str
,
1118 char *gate_str
, char *ifname
, char *flag_str
, char *distance_str
)
1123 struct in6_addr
*gate
= NULL
;
1124 struct in6_addr gate_addr
;
1129 ret
= str2prefix (dest_str
, &p
);
1132 vty_out (vty
, "%% Malformed address%s", VTY_NEWLINE
);
1136 /* Apply mask for given prefix. */
1141 switch(flag_str
[0]) {
1144 SET_FLAG (flag
, ZEBRA_FLAG_REJECT
);
1148 SET_FLAG (flag
, ZEBRA_FLAG_BLACKHOLE
);
1151 vty_out (vty
, "%% Malformed flag %s %s", flag_str
, VTY_NEWLINE
);
1156 /* Administrative distance. */
1158 distance
= atoi (distance_str
);
1160 distance
= ZEBRA_STATIC_DISTANCE_DEFAULT
;
1162 /* When gateway is valid IPv6 addrees, then gate is treated as
1163 nexthop address other case gate is treated as interface name. */
1164 ret
= inet_pton (AF_INET6
, gate_str
, &gate_addr
);
1168 /* When ifname is specified. It must be come with gateway
1172 vty_out (vty
, "%% Malformed address%s", VTY_NEWLINE
);
1175 type
= STATIC_IPV6_GATEWAY_IFNAME
;
1182 type
= STATIC_IPV6_GATEWAY
;
1187 type
= STATIC_IPV6_IFNAME
;
1193 static_add_ipv6 (&p
, type
, gate
, ifname
, flag
, distance
, table
);
1195 static_delete_ipv6 (&p
, type
, gate
, ifname
, distance
, table
);
1202 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE)",
1204 "Establish static routes\n"
1205 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1206 "IPv6 gateway address\n"
1207 "IPv6 gateway interface name\n")
1209 return static_ipv6_func (vty
, 1, argv
[0], argv
[1], NULL
, NULL
, NULL
);
1212 DEFUN (ipv6_route_flags
,
1213 ipv6_route_flags_cmd
,
1214 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole)",
1216 "Establish static routes\n"
1217 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1218 "IPv6 gateway address\n"
1219 "IPv6 gateway interface name\n"
1220 "Emit an ICMP unreachable when matched\n"
1221 "Silently discard pkts when matched\n")
1223 return static_ipv6_func (vty
, 1, argv
[0], argv
[1], NULL
, argv
[2], NULL
);
1226 DEFUN (ipv6_route_ifname
,
1227 ipv6_route_ifname_cmd
,
1228 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE",
1230 "Establish static routes\n"
1231 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1232 "IPv6 gateway address\n"
1233 "IPv6 gateway interface name\n")
1235 return static_ipv6_func (vty
, 1, argv
[0], argv
[1], argv
[2], NULL
, NULL
);
1238 DEFUN (ipv6_route_ifname_flags
,
1239 ipv6_route_ifname_flags_cmd
,
1240 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole)",
1242 "Establish static routes\n"
1243 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1244 "IPv6 gateway address\n"
1245 "IPv6 gateway interface name\n"
1246 "Emit an ICMP unreachable when matched\n"
1247 "Silently discard pkts when matched\n")
1249 return static_ipv6_func (vty
, 1, argv
[0], argv
[1], argv
[2], argv
[3], NULL
);
1252 DEFUN (ipv6_route_pref
,
1253 ipv6_route_pref_cmd
,
1254 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <1-255>",
1256 "Establish static routes\n"
1257 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1258 "IPv6 gateway address\n"
1259 "IPv6 gateway interface name\n"
1260 "Distance value for this prefix\n")
1262 return static_ipv6_func (vty
, 1, argv
[0], argv
[1], NULL
, NULL
, argv
[2]);
1265 DEFUN (ipv6_route_flags_pref
,
1266 ipv6_route_flags_pref_cmd
,
1267 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) <1-255>",
1269 "Establish static routes\n"
1270 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1271 "IPv6 gateway address\n"
1272 "IPv6 gateway interface name\n"
1273 "Emit an ICMP unreachable when matched\n"
1274 "Silently discard pkts when matched\n"
1275 "Distance value for this prefix\n")
1277 return static_ipv6_func (vty
, 1, argv
[0], argv
[1], NULL
, argv
[2], argv
[3]);
1280 DEFUN (ipv6_route_ifname_pref
,
1281 ipv6_route_ifname_pref_cmd
,
1282 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255>",
1284 "Establish static routes\n"
1285 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1286 "IPv6 gateway address\n"
1287 "IPv6 gateway interface name\n"
1288 "Distance value for this prefix\n")
1290 return static_ipv6_func (vty
, 1, argv
[0], argv
[1], argv
[2], NULL
, argv
[3]);
1293 DEFUN (ipv6_route_ifname_flags_pref
,
1294 ipv6_route_ifname_flags_pref_cmd
,
1295 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) <1-255>",
1297 "Establish static routes\n"
1298 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1299 "IPv6 gateway address\n"
1300 "IPv6 gateway interface name\n"
1301 "Emit an ICMP unreachable when matched\n"
1302 "Silently discard pkts when matched\n"
1303 "Distance value for this prefix\n")
1305 return static_ipv6_func (vty
, 1, argv
[0], argv
[1], argv
[2], argv
[3], argv
[4]);
1308 DEFUN (no_ipv6_route
,
1310 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE)",
1313 "Establish static routes\n"
1314 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1315 "IPv6 gateway address\n"
1316 "IPv6 gateway interface name\n")
1318 return static_ipv6_func (vty
, 0, argv
[0], argv
[1], NULL
, NULL
, NULL
);
1321 ALIAS (no_ipv6_route
,
1322 no_ipv6_route_flags_cmd
,
1323 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole)",
1326 "Establish static routes\n"
1327 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1328 "IPv6 gateway address\n"
1329 "IPv6 gateway interface name\n"
1330 "Emit an ICMP unreachable when matched\n"
1331 "Silently discard pkts when matched\n")
1333 DEFUN (no_ipv6_route_ifname
,
1334 no_ipv6_route_ifname_cmd
,
1335 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE",
1338 "Establish static routes\n"
1339 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1340 "IPv6 gateway address\n"
1341 "IPv6 gateway interface name\n")
1343 return static_ipv6_func (vty
, 0, argv
[0], argv
[1], argv
[2], NULL
, NULL
);
1346 ALIAS (no_ipv6_route_ifname
,
1347 no_ipv6_route_ifname_flags_cmd
,
1348 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole)",
1351 "Establish static routes\n"
1352 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1353 "IPv6 gateway address\n"
1354 "IPv6 gateway interface name\n"
1355 "Emit an ICMP unreachable when matched\n"
1356 "Silently discard pkts when matched\n")
1358 DEFUN (no_ipv6_route_pref
,
1359 no_ipv6_route_pref_cmd
,
1360 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <1-255>",
1363 "Establish static routes\n"
1364 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1365 "IPv6 gateway address\n"
1366 "IPv6 gateway interface name\n"
1367 "Distance value for this prefix\n")
1369 return static_ipv6_func (vty
, 0, argv
[0], argv
[1], NULL
, NULL
, argv
[2]);
1372 DEFUN (no_ipv6_route_flags_pref
,
1373 no_ipv6_route_flags_pref_cmd
,
1374 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) <1-255>",
1377 "Establish static routes\n"
1378 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1379 "IPv6 gateway address\n"
1380 "IPv6 gateway interface name\n"
1381 "Emit an ICMP unreachable when matched\n"
1382 "Silently discard pkts when matched\n"
1383 "Distance value for this prefix\n")
1385 /* We do not care about argv[2] */
1386 return static_ipv6_func (vty
, 0, argv
[0], argv
[1], NULL
, argv
[2], argv
[3]);
1389 DEFUN (no_ipv6_route_ifname_pref
,
1390 no_ipv6_route_ifname_pref_cmd
,
1391 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255>",
1394 "Establish static routes\n"
1395 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1396 "IPv6 gateway address\n"
1397 "IPv6 gateway interface name\n"
1398 "Distance value for this prefix\n")
1400 return static_ipv6_func (vty
, 0, argv
[0], argv
[1], argv
[2], NULL
, argv
[3]);
1403 DEFUN (no_ipv6_route_ifname_flags_pref
,
1404 no_ipv6_route_ifname_flags_pref_cmd
,
1405 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) <1-255>",
1408 "Establish static routes\n"
1409 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1410 "IPv6 gateway address\n"
1411 "IPv6 gateway interface name\n"
1412 "Emit an ICMP unreachable when matched\n"
1413 "Silently discard pkts when matched\n"
1414 "Distance value for this prefix\n")
1416 return static_ipv6_func (vty
, 0, argv
[0], argv
[1], argv
[2], argv
[3], argv
[4]);
1419 /* New RIB. Detailed information for IPv6 route. */
1421 vty_show_ipv6_route_detail (struct vty
*vty
, struct route_node
*rn
)
1424 struct nexthop
*nexthop
;
1427 for (rib
= rn
->info
; rib
; rib
= rib
->next
)
1429 vty_out (vty
, "Routing entry for %s/%d%s",
1430 inet_ntop (AF_INET6
, &rn
->p
.u
.prefix6
, buf
, BUFSIZ
),
1433 vty_out (vty
, " Known via \"%s\"", route_type_str (rib
->type
));
1434 vty_out (vty
, ", distance %d, metric %d", rib
->distance
, rib
->metric
);
1435 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_SELECTED
))
1436 vty_out (vty
, ", best");
1438 vty_out (vty
, ", refcnt %ld", rib
->refcnt
);
1439 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_BLACKHOLE
))
1440 vty_out (vty
, ", blackhole");
1441 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_REJECT
))
1442 vty_out (vty
, ", reject");
1443 vty_out (vty
, "%s", VTY_NEWLINE
);
1445 #define ONE_DAY_SECOND 60*60*24
1446 #define ONE_WEEK_SECOND 60*60*24*7
1447 if (rib
->type
== ZEBRA_ROUTE_RIPNG
1448 || rib
->type
== ZEBRA_ROUTE_OSPF6
1449 || rib
->type
== ZEBRA_ROUTE_ISIS
1450 || rib
->type
== ZEBRA_ROUTE_BGP
)
1455 uptime
= time (NULL
);
1456 uptime
-= rib
->uptime
;
1457 tm
= gmtime (&uptime
);
1459 vty_out (vty
, " Last update ");
1461 if (uptime
< ONE_DAY_SECOND
)
1462 vty_out (vty
, "%02d:%02d:%02d",
1463 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
1464 else if (uptime
< ONE_WEEK_SECOND
)
1465 vty_out (vty
, "%dd%02dh%02dm",
1466 tm
->tm_yday
, tm
->tm_hour
, tm
->tm_min
);
1468 vty_out (vty
, "%02dw%dd%02dh",
1470 tm
->tm_yday
- ((tm
->tm_yday
/7) * 7), tm
->tm_hour
);
1471 vty_out (vty
, " ago%s", VTY_NEWLINE
);
1474 for (nexthop
= rib
->nexthop
; nexthop
; nexthop
= nexthop
->next
)
1476 vty_out (vty
, " %c",
1477 CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
) ? '*' : ' ');
1479 switch (nexthop
->type
)
1481 case NEXTHOP_TYPE_IPV6
:
1482 case NEXTHOP_TYPE_IPV6_IFINDEX
:
1483 case NEXTHOP_TYPE_IPV6_IFNAME
:
1484 vty_out (vty
, " %s",
1485 inet_ntop (AF_INET6
, &nexthop
->gate
.ipv6
, buf
, BUFSIZ
));
1486 if (nexthop
->type
== NEXTHOP_TYPE_IPV6_IFNAME
)
1487 vty_out (vty
, ", %s", nexthop
->ifname
);
1488 else if (nexthop
->ifindex
)
1489 vty_out (vty
, ", via %s", ifindex2ifname (nexthop
->ifindex
));
1491 case NEXTHOP_TYPE_IFINDEX
:
1492 vty_out (vty
, " directly connected, %s",
1493 ifindex2ifname (nexthop
->ifindex
));
1495 case NEXTHOP_TYPE_IFNAME
:
1496 vty_out (vty
, " directly connected, %s",
1502 if (! CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
))
1503 vty_out (vty
, " inactive");
1505 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_RECURSIVE
))
1507 vty_out (vty
, " (recursive");
1509 switch (nexthop
->rtype
)
1511 case NEXTHOP_TYPE_IPV6
:
1512 case NEXTHOP_TYPE_IPV6_IFINDEX
:
1513 case NEXTHOP_TYPE_IPV6_IFNAME
:
1514 vty_out (vty
, " via %s)",
1515 inet_ntop (AF_INET6
, &nexthop
->rgate
.ipv6
,
1517 if (nexthop
->rifindex
)
1518 vty_out (vty
, ", %s", ifindex2ifname (nexthop
->rifindex
));
1520 case NEXTHOP_TYPE_IFINDEX
:
1521 case NEXTHOP_TYPE_IFNAME
:
1522 vty_out (vty
, " is directly connected, %s)",
1523 ifindex2ifname (nexthop
->rifindex
));
1529 vty_out (vty
, "%s", VTY_NEWLINE
);
1531 vty_out (vty
, "%s", VTY_NEWLINE
);
1536 vty_show_ipv6_route (struct vty
*vty
, struct route_node
*rn
,
1539 struct nexthop
*nexthop
;
1543 /* Nexthop information. */
1544 for (nexthop
= rib
->nexthop
; nexthop
; nexthop
= nexthop
->next
)
1546 if (nexthop
== rib
->nexthop
)
1548 /* Prefix information. */
1549 len
= vty_out (vty
, "%c%c%c %s/%d",
1550 route_type_char (rib
->type
),
1551 CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_SELECTED
)
1553 CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
)
1555 inet_ntop (AF_INET6
, &rn
->p
.u
.prefix6
, buf
, BUFSIZ
),
1558 /* Distance and metric display. */
1559 if (rib
->type
!= ZEBRA_ROUTE_CONNECT
1560 && rib
->type
!= ZEBRA_ROUTE_KERNEL
)
1561 len
+= vty_out (vty
, " [%d/%d]", rib
->distance
,
1565 vty_out (vty
, " %c%*c",
1566 CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
)
1570 switch (nexthop
->type
)
1572 case NEXTHOP_TYPE_IPV6
:
1573 case NEXTHOP_TYPE_IPV6_IFINDEX
:
1574 case NEXTHOP_TYPE_IPV6_IFNAME
:
1575 vty_out (vty
, " via %s",
1576 inet_ntop (AF_INET6
, &nexthop
->gate
.ipv6
, buf
, BUFSIZ
));
1577 if (nexthop
->type
== NEXTHOP_TYPE_IPV6_IFNAME
)
1578 vty_out (vty
, ", %s", nexthop
->ifname
);
1579 else if (nexthop
->ifindex
)
1580 vty_out (vty
, ", %s", ifindex2ifname (nexthop
->ifindex
));
1582 case NEXTHOP_TYPE_IFINDEX
:
1583 vty_out (vty
, " is directly connected, %s",
1584 ifindex2ifname (nexthop
->ifindex
));
1586 case NEXTHOP_TYPE_IFNAME
:
1587 vty_out (vty
, " is directly connected, %s",
1593 if (! CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
))
1594 vty_out (vty
, " inactive");
1596 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_RECURSIVE
))
1598 vty_out (vty
, " (recursive");
1600 switch (nexthop
->rtype
)
1602 case NEXTHOP_TYPE_IPV6
:
1603 case NEXTHOP_TYPE_IPV6_IFINDEX
:
1604 case NEXTHOP_TYPE_IPV6_IFNAME
:
1605 vty_out (vty
, " via %s)",
1606 inet_ntop (AF_INET6
, &nexthop
->rgate
.ipv6
,
1608 if (nexthop
->rifindex
)
1609 vty_out (vty
, ", %s", ifindex2ifname (nexthop
->rifindex
));
1611 case NEXTHOP_TYPE_IFINDEX
:
1612 case NEXTHOP_TYPE_IFNAME
:
1613 vty_out (vty
, " is directly connected, %s)",
1614 ifindex2ifname (nexthop
->rifindex
));
1621 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_BLACKHOLE
))
1622 vty_out (vty
, ", bh");
1623 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_REJECT
))
1624 vty_out (vty
, ", rej");
1626 if (rib
->type
== ZEBRA_ROUTE_RIPNG
1627 || rib
->type
== ZEBRA_ROUTE_OSPF6
1628 || rib
->type
== ZEBRA_ROUTE_ISIS
1629 || rib
->type
== ZEBRA_ROUTE_BGP
)
1634 uptime
= time (NULL
);
1635 uptime
-= rib
->uptime
;
1636 tm
= gmtime (&uptime
);
1638 #define ONE_DAY_SECOND 60*60*24
1639 #define ONE_WEEK_SECOND 60*60*24*7
1641 if (uptime
< ONE_DAY_SECOND
)
1642 vty_out (vty
, ", %02d:%02d:%02d",
1643 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
1644 else if (uptime
< ONE_WEEK_SECOND
)
1645 vty_out (vty
, ", %dd%02dh%02dm",
1646 tm
->tm_yday
, tm
->tm_hour
, tm
->tm_min
);
1648 vty_out (vty
, ", %02dw%dd%02dh",
1650 tm
->tm_yday
- ((tm
->tm_yday
/7) * 7), tm
->tm_hour
);
1652 vty_out (vty
, "%s", VTY_NEWLINE
);
1656 #define SHOW_ROUTE_V6_HEADER "Codes: K - kernel route, C - connected, S - static, R - RIPng, O - OSPFv3,%s I - ISIS, B - BGP, * - FIB route.%s%s"
1658 DEFUN (show_ipv6_route
,
1659 show_ipv6_route_cmd
,
1663 "IPv6 routing table\n")
1665 struct route_table
*table
;
1666 struct route_node
*rn
;
1670 table
= vrf_table (AFI_IP6
, SAFI_UNICAST
, 0);
1674 /* Show all IPv6 route. */
1675 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
1676 for (rib
= rn
->info
; rib
; rib
= rib
->next
)
1680 vty_out (vty
, SHOW_ROUTE_V6_HEADER
, VTY_NEWLINE
, VTY_NEWLINE
, VTY_NEWLINE
);
1683 vty_show_ipv6_route (vty
, rn
, rib
);
1688 DEFUN (show_ipv6_route_prefix_longer
,
1689 show_ipv6_route_prefix_longer_cmd
,
1690 "show ipv6 route X:X::X:X/M longer-prefixes",
1693 "IPv6 routing table\n"
1695 "Show route matching the specified Network/Mask pair only\n")
1697 struct route_table
*table
;
1698 struct route_node
*rn
;
1704 table
= vrf_table (AFI_IP6
, SAFI_UNICAST
, 0);
1708 ret
= str2prefix (argv
[0], &p
);
1711 vty_out (vty
, "%% Malformed Prefix%s", VTY_NEWLINE
);
1715 /* Show matched type IPv6 routes. */
1716 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
1717 for (rib
= rn
->info
; rib
; rib
= rib
->next
)
1718 if (prefix_match (&p
, &rn
->p
))
1722 vty_out (vty
, SHOW_ROUTE_V6_HEADER
, VTY_NEWLINE
, VTY_NEWLINE
, VTY_NEWLINE
);
1725 vty_show_ipv6_route (vty
, rn
, rib
);
1730 DEFUN (show_ipv6_route_protocol
,
1731 show_ipv6_route_protocol_cmd
,
1732 "show ipv6 route (bgp|connected|kernel|ospf6|ripng|static)",
1735 "IP routing table\n"
1736 "Border Gateway Protocol (BGP)\n"
1739 "Open Shortest Path First (OSPFv3)\n"
1740 "ISO IS-IS (ISIS)\n"
1741 "Routing Information Protocol (RIPng)\n"
1745 struct route_table
*table
;
1746 struct route_node
*rn
;
1750 if (strncmp (argv
[0], "b", 1) == 0)
1751 type
= ZEBRA_ROUTE_BGP
;
1752 else if (strncmp (argv
[0], "c", 1) == 0)
1753 type
= ZEBRA_ROUTE_CONNECT
;
1754 else if (strncmp (argv
[0], "k", 1) ==0)
1755 type
= ZEBRA_ROUTE_KERNEL
;
1756 else if (strncmp (argv
[0], "o", 1) == 0)
1757 type
= ZEBRA_ROUTE_OSPF6
;
1758 else if (strncmp (argv
[0], "i", 1) == 0)
1759 type
= ZEBRA_ROUTE_ISIS
;
1760 else if (strncmp (argv
[0], "r", 1) == 0)
1761 type
= ZEBRA_ROUTE_RIPNG
;
1762 else if (strncmp (argv
[0], "s", 1) == 0)
1763 type
= ZEBRA_ROUTE_STATIC
;
1766 vty_out (vty
, "Unknown route type%s", VTY_NEWLINE
);
1770 table
= vrf_table (AFI_IP6
, SAFI_UNICAST
, 0);
1774 /* Show matched type IPv6 routes. */
1775 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
1776 for (rib
= rn
->info
; rib
; rib
= rib
->next
)
1777 if (rib
->type
== type
)
1781 vty_out (vty
, SHOW_ROUTE_V6_HEADER
, VTY_NEWLINE
, VTY_NEWLINE
, VTY_NEWLINE
);
1784 vty_show_ipv6_route (vty
, rn
, rib
);
1789 DEFUN (show_ipv6_route_addr
,
1790 show_ipv6_route_addr_cmd
,
1791 "show ipv6 route X:X::X:X",
1794 "IPv6 routing table\n"
1798 struct prefix_ipv6 p
;
1799 struct route_table
*table
;
1800 struct route_node
*rn
;
1802 ret
= str2prefix_ipv6 (argv
[0], &p
);
1805 vty_out (vty
, "Malformed IPv6 address%s", VTY_NEWLINE
);
1809 table
= vrf_table (AFI_IP6
, SAFI_UNICAST
, 0);
1813 rn
= route_node_match (table
, (struct prefix
*) &p
);
1816 vty_out (vty
, "%% Network not in table%s", VTY_NEWLINE
);
1820 vty_show_ipv6_route_detail (vty
, rn
);
1822 route_unlock_node (rn
);
1827 DEFUN (show_ipv6_route_prefix
,
1828 show_ipv6_route_prefix_cmd
,
1829 "show ipv6 route X:X::X:X/M",
1832 "IPv6 routing table\n"
1836 struct prefix_ipv6 p
;
1837 struct route_table
*table
;
1838 struct route_node
*rn
;
1840 ret
= str2prefix_ipv6 (argv
[0], &p
);
1843 vty_out (vty
, "Malformed IPv6 prefix%s", VTY_NEWLINE
);
1847 table
= vrf_table (AFI_IP6
, SAFI_UNICAST
, 0);
1851 rn
= route_node_match (table
, (struct prefix
*) &p
);
1852 if (! rn
|| rn
->p
.prefixlen
!= p
.prefixlen
)
1854 vty_out (vty
, "%% Network not in table%s", VTY_NEWLINE
);
1858 vty_show_ipv6_route_detail (vty
, rn
);
1860 route_unlock_node (rn
);
1866 /* Write IPv6 static route configuration. */
1868 static_config_ipv6 (struct vty
*vty
)
1870 struct route_node
*rn
;
1871 struct static_ipv6
*si
;
1874 struct route_table
*stable
;
1879 stable
= vrf_static_table (AFI_IP6
, SAFI_UNICAST
, 0);
1883 for (rn
= route_top (stable
); rn
; rn
= route_next (rn
))
1884 for (si
= rn
->info
; si
; si
= si
->next
)
1886 vty_out (vty
, "ipv6 route %s/%d",
1887 inet_ntop (AF_INET6
, &rn
->p
.u
.prefix6
, buf
, BUFSIZ
),
1892 case STATIC_IPV6_GATEWAY
:
1893 vty_out (vty
, " %s", inet_ntop (AF_INET6
, &si
->ipv6
, buf
, BUFSIZ
));
1895 case STATIC_IPV6_IFNAME
:
1896 vty_out (vty
, " %s", si
->ifname
);
1898 case STATIC_IPV6_GATEWAY_IFNAME
:
1899 vty_out (vty
, " %s %s",
1900 inet_ntop (AF_INET6
, &si
->ipv6
, buf
, BUFSIZ
), si
->ifname
);
1904 if (CHECK_FLAG(si
->flags
, ZEBRA_FLAG_REJECT
))
1905 vty_out (vty
, " %s", "reject");
1907 if (CHECK_FLAG(si
->flags
, ZEBRA_FLAG_BLACKHOLE
))
1908 vty_out (vty
, " %s", "blackhole");
1910 if (si
->distance
!= ZEBRA_STATIC_DISTANCE_DEFAULT
)
1911 vty_out (vty
, " %d", si
->distance
);
1912 vty_out (vty
, "%s", VTY_NEWLINE
);
1918 #endif /* HAVE_IPV6 */
1920 /* Static ip route configuration write function. */
1922 zebra_ip_config (struct vty
*vty
)
1926 write
+= static_config_ipv4 (vty
);
1928 write
+= static_config_ipv6 (vty
);
1929 #endif /* HAVE_IPV6 */
1934 /* IP node for static routes. */
1935 struct cmd_node ip_node
= { IP_NODE
, "", 1 };
1939 zebra_vty_route_init ()
1941 install_node (&ip_node
, zebra_ip_config
);
1943 install_element (CONFIG_NODE
, &ip_route_cmd
);
1944 install_element (CONFIG_NODE
, &ip_route_flags_cmd
);
1945 install_element (CONFIG_NODE
, &ip_route_flags2_cmd
);
1946 install_element (CONFIG_NODE
, &ip_route_mask_cmd
);
1947 install_element (CONFIG_NODE
, &ip_route_mask_flags_cmd
);
1948 install_element (CONFIG_NODE
, &ip_route_mask_flags2_cmd
);
1949 install_element (CONFIG_NODE
, &no_ip_route_cmd
);
1950 install_element (CONFIG_NODE
, &no_ip_route_flags_cmd
);
1951 install_element (CONFIG_NODE
, &no_ip_route_flags2_cmd
);
1952 install_element (CONFIG_NODE
, &no_ip_route_mask_cmd
);
1953 install_element (CONFIG_NODE
, &no_ip_route_mask_flags_cmd
);
1954 install_element (CONFIG_NODE
, &no_ip_route_mask_flags2_cmd
);
1955 install_element (CONFIG_NODE
, &ip_route_distance_cmd
);
1956 install_element (CONFIG_NODE
, &ip_route_flags_distance_cmd
);
1957 install_element (CONFIG_NODE
, &ip_route_flags_distance2_cmd
);
1958 install_element (CONFIG_NODE
, &ip_route_mask_distance_cmd
);
1959 install_element (CONFIG_NODE
, &ip_route_mask_flags_distance_cmd
);
1960 install_element (CONFIG_NODE
, &ip_route_mask_flags_distance2_cmd
);
1961 install_element (CONFIG_NODE
, &no_ip_route_distance_cmd
);
1962 install_element (CONFIG_NODE
, &no_ip_route_flags_distance_cmd
);
1963 install_element (CONFIG_NODE
, &no_ip_route_flags_distance2_cmd
);
1964 install_element (CONFIG_NODE
, &no_ip_route_mask_flags_distance_cmd
);
1965 install_element (CONFIG_NODE
, &no_ip_route_mask_flags_distance2_cmd
);
1967 install_element (VIEW_NODE
, &show_ip_route_cmd
);
1968 install_element (VIEW_NODE
, &show_ip_route_addr_cmd
);
1969 install_element (VIEW_NODE
, &show_ip_route_prefix_cmd
);
1970 install_element (VIEW_NODE
, &show_ip_route_prefix_longer_cmd
);
1971 install_element (VIEW_NODE
, &show_ip_route_protocol_cmd
);
1972 install_element (VIEW_NODE
, &show_ip_route_supernets_cmd
);
1973 install_element (ENABLE_NODE
, &show_ip_route_cmd
);
1974 install_element (ENABLE_NODE
, &show_ip_route_addr_cmd
);
1975 install_element (ENABLE_NODE
, &show_ip_route_prefix_cmd
);
1976 install_element (ENABLE_NODE
, &show_ip_route_prefix_longer_cmd
);
1977 install_element (ENABLE_NODE
, &show_ip_route_protocol_cmd
);
1978 install_element (ENABLE_NODE
, &show_ip_route_supernets_cmd
);
1981 install_element (VIEW_NODE
, &show_ip_route_summary_cmd
);
1982 install_element (ENABLE_NODE
, &show_ip_route_summary_cmd
);
1986 install_element (CONFIG_NODE
, &ipv6_route_cmd
);
1987 install_element (CONFIG_NODE
, &ipv6_route_flags_cmd
);
1988 install_element (CONFIG_NODE
, &ipv6_route_ifname_cmd
);
1989 install_element (CONFIG_NODE
, &ipv6_route_ifname_flags_cmd
);
1990 install_element (CONFIG_NODE
, &no_ipv6_route_cmd
);
1991 install_element (CONFIG_NODE
, &no_ipv6_route_flags_cmd
);
1992 install_element (CONFIG_NODE
, &no_ipv6_route_ifname_cmd
);
1993 install_element (CONFIG_NODE
, &no_ipv6_route_ifname_flags_cmd
);
1994 install_element (CONFIG_NODE
, &ipv6_route_pref_cmd
);
1995 install_element (CONFIG_NODE
, &ipv6_route_flags_pref_cmd
);
1996 install_element (CONFIG_NODE
, &ipv6_route_ifname_pref_cmd
);
1997 install_element (CONFIG_NODE
, &ipv6_route_ifname_flags_pref_cmd
);
1998 install_element (CONFIG_NODE
, &no_ipv6_route_pref_cmd
);
1999 install_element (CONFIG_NODE
, &no_ipv6_route_flags_pref_cmd
);
2000 install_element (CONFIG_NODE
, &no_ipv6_route_ifname_pref_cmd
);
2001 install_element (CONFIG_NODE
, &no_ipv6_route_ifname_flags_pref_cmd
);
2002 install_element (VIEW_NODE
, &show_ipv6_route_cmd
);
2003 install_element (VIEW_NODE
, &show_ipv6_route_protocol_cmd
);
2004 install_element (VIEW_NODE
, &show_ipv6_route_addr_cmd
);
2005 install_element (VIEW_NODE
, &show_ipv6_route_prefix_cmd
);
2006 install_element (VIEW_NODE
, &show_ipv6_route_prefix_longer_cmd
);
2007 install_element (ENABLE_NODE
, &show_ipv6_route_cmd
);
2008 install_element (ENABLE_NODE
, &show_ipv6_route_protocol_cmd
);
2009 install_element (ENABLE_NODE
, &show_ipv6_route_addr_cmd
);
2010 install_element (ENABLE_NODE
, &show_ipv6_route_prefix_cmd
);
2011 install_element (ENABLE_NODE
, &show_ipv6_route_prefix_longer_cmd
);
2012 #endif /* HAVE_IPV6 */
2018 zebra_vty_route_init ();