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 #include "zebra/zserv.h"
32 /* Return route type string for VTY output. */
34 route_type_str (u_char type
)
38 case ZEBRA_ROUTE_SYSTEM
:
40 case ZEBRA_ROUTE_KERNEL
:
42 case ZEBRA_ROUTE_CONNECT
:
44 case ZEBRA_ROUTE_STATIC
:
48 case ZEBRA_ROUTE_RIPNG
:
50 case ZEBRA_ROUTE_OSPF
:
52 case ZEBRA_ROUTE_OSPF6
:
54 case ZEBRA_ROUTE_ISIS
:
63 /* Return route type string for VTY output. */
65 route_type_char (u_char type
)
69 case ZEBRA_ROUTE_SYSTEM
:
71 case ZEBRA_ROUTE_KERNEL
:
73 case ZEBRA_ROUTE_CONNECT
:
75 case ZEBRA_ROUTE_STATIC
:
79 case ZEBRA_ROUTE_RIPNG
:
81 case ZEBRA_ROUTE_OSPF
:
83 case ZEBRA_ROUTE_OSPF6
:
85 case ZEBRA_ROUTE_ISIS
:
94 /* General fucntion for static route. */
96 zebra_static_ipv4 (struct vty
*vty
, int add_cmd
, const char *dest_str
,
97 const char *mask_str
, const char *gate_str
,
98 const char *flag_str
, const char *distance_str
)
108 ret
= str2prefix (dest_str
, &p
);
111 vty_out (vty
, "%% Malformed address%s", VTY_NEWLINE
);
115 /* Cisco like mask notation. */
118 ret
= inet_aton (mask_str
, &mask
);
121 vty_out (vty
, "%% Malformed address%s", VTY_NEWLINE
);
124 p
.prefixlen
= ip_masklen (mask
);
127 /* Apply mask for given prefix. */
130 /* Administrative distance. */
132 distance
= atoi (distance_str
);
134 distance
= ZEBRA_STATIC_DISTANCE_DEFAULT
;
136 /* Null0 static route. */
137 if ((gate_str
!= NULL
) && (strncasecmp (gate_str
, "Null0", strlen (gate_str
)) == 0))
141 vty_out (vty
, "%% can not have flag %s with Null0%s", flag_str
, VTY_NEWLINE
);
145 static_add_ipv4 (&p
, NULL
, NULL
, ZEBRA_FLAG_BLACKHOLE
, distance
, 0);
147 static_delete_ipv4 (&p
, NULL
, NULL
, distance
, 0);
153 switch(flag_str
[0]) {
156 SET_FLAG (flag
, ZEBRA_FLAG_REJECT
);
160 SET_FLAG (flag
, ZEBRA_FLAG_BLACKHOLE
);
163 vty_out (vty
, "%% Malformed flag %s %s", flag_str
, VTY_NEWLINE
);
168 if (gate_str
== NULL
)
171 static_add_ipv4 (&p
, NULL
, NULL
, flag
, distance
, 0);
173 static_delete_ipv4 (&p
, NULL
, NULL
, distance
, 0);
178 /* When gateway is A.B.C.D format, gate is treated as nexthop
179 address other case gate is treated as interface name. */
180 ret
= inet_aton (gate_str
, &gate
);
187 static_add_ipv4 (&p
, ifname
? NULL
: &gate
, ifname
, flag
, distance
, 0);
189 static_delete_ipv4 (&p
, ifname
? NULL
: &gate
, ifname
, distance
, 0);
194 /* Static route configuration. */
197 "ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0)",
199 "Establish static routes\n"
200 "IP destination prefix (e.g. 10.0.0.0/8)\n"
201 "IP gateway address\n"
202 "IP gateway interface name\n"
205 return zebra_static_ipv4 (vty
, 1, argv
[0], NULL
, argv
[1], NULL
, NULL
);
208 DEFUN (ip_route_flags
,
210 "ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole)",
212 "Establish static routes\n"
213 "IP destination prefix (e.g. 10.0.0.0/8)\n"
214 "IP gateway address\n"
215 "IP gateway interface name\n"
216 "Emit an ICMP unreachable when matched\n"
217 "Silently discard pkts when matched\n")
219 return zebra_static_ipv4 (vty
, 1, argv
[0], NULL
, argv
[1], argv
[2], NULL
);
222 DEFUN (ip_route_flags2
,
224 "ip route A.B.C.D/M (reject|blackhole)",
226 "Establish static routes\n"
227 "IP destination prefix (e.g. 10.0.0.0/8)\n"
228 "Emit an ICMP unreachable when matched\n"
229 "Silently discard pkts when matched\n")
231 return zebra_static_ipv4 (vty
, 1, argv
[0], NULL
, NULL
, argv
[1], NULL
);
234 /* Mask as A.B.C.D format. */
235 DEFUN (ip_route_mask
,
237 "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0)",
239 "Establish static routes\n"
240 "IP destination prefix\n"
241 "IP destination prefix mask\n"
242 "IP gateway address\n"
243 "IP gateway interface name\n"
246 return zebra_static_ipv4 (vty
, 1, argv
[0], argv
[1], argv
[2], NULL
, NULL
);
249 DEFUN (ip_route_mask_flags
,
250 ip_route_mask_flags_cmd
,
251 "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole)",
253 "Establish static routes\n"
254 "IP destination prefix\n"
255 "IP destination prefix mask\n"
256 "IP gateway address\n"
257 "IP gateway interface name\n"
258 "Emit an ICMP unreachable when matched\n"
259 "Silently discard pkts when matched\n")
261 return zebra_static_ipv4 (vty
, 1, argv
[0], argv
[1], argv
[2], argv
[3], NULL
);
264 DEFUN (ip_route_mask_flags2
,
265 ip_route_mask_flags2_cmd
,
266 "ip route A.B.C.D A.B.C.D (reject|blackhole)",
268 "Establish static routes\n"
269 "IP destination prefix\n"
270 "IP destination prefix mask\n"
271 "Emit an ICMP unreachable when matched\n"
272 "Silently discard pkts when matched\n")
274 return zebra_static_ipv4 (vty
, 1, argv
[0], argv
[1], NULL
, argv
[2], NULL
);
277 /* Distance option value. */
278 DEFUN (ip_route_distance
,
279 ip_route_distance_cmd
,
280 "ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0) <1-255>",
282 "Establish static routes\n"
283 "IP destination prefix (e.g. 10.0.0.0/8)\n"
284 "IP gateway address\n"
285 "IP gateway interface name\n"
287 "Distance value for this route\n")
289 return zebra_static_ipv4 (vty
, 1, argv
[0], NULL
, argv
[1], NULL
, argv
[2]);
292 DEFUN (ip_route_flags_distance
,
293 ip_route_flags_distance_cmd
,
294 "ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
296 "Establish static routes\n"
297 "IP destination prefix (e.g. 10.0.0.0/8)\n"
298 "IP gateway address\n"
299 "IP gateway interface name\n"
300 "Emit an ICMP unreachable when matched\n"
301 "Silently discard pkts when matched\n"
302 "Distance value for this route\n")
304 return zebra_static_ipv4 (vty
, 1, argv
[0], NULL
, argv
[1], argv
[2], argv
[3]);
307 DEFUN (ip_route_flags_distance2
,
308 ip_route_flags_distance2_cmd
,
309 "ip route A.B.C.D/M (reject|blackhole) <1-255>",
311 "Establish static routes\n"
312 "IP destination prefix (e.g. 10.0.0.0/8)\n"
313 "Emit an ICMP unreachable when matched\n"
314 "Silently discard pkts when matched\n"
315 "Distance value for this route\n")
317 return zebra_static_ipv4 (vty
, 1, argv
[0], NULL
, NULL
, argv
[1], argv
[2]);
320 DEFUN (ip_route_mask_distance
,
321 ip_route_mask_distance_cmd
,
322 "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0) <1-255>",
324 "Establish static routes\n"
325 "IP destination prefix\n"
326 "IP destination prefix mask\n"
327 "IP gateway address\n"
328 "IP gateway interface name\n"
330 "Distance value for this route\n")
332 return zebra_static_ipv4 (vty
, 1, argv
[0], argv
[1], argv
[2], NULL
, argv
[3]);
335 DEFUN (ip_route_mask_flags_distance
,
336 ip_route_mask_flags_distance_cmd
,
337 "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
339 "Establish static routes\n"
340 "IP destination prefix\n"
341 "IP destination prefix mask\n"
342 "IP gateway address\n"
343 "IP gateway interface name\n"
344 "Distance value for this route\n"
345 "Emit an ICMP unreachable when matched\n"
346 "Silently discard pkts when matched\n")
348 return zebra_static_ipv4 (vty
, 1, argv
[0], argv
[1], argv
[2], argv
[3], argv
[4]);
351 DEFUN (ip_route_mask_flags_distance2
,
352 ip_route_mask_flags_distance2_cmd
,
353 "ip route A.B.C.D A.B.C.D (reject|blackhole) <1-255>",
355 "Establish static routes\n"
356 "IP destination prefix\n"
357 "IP destination prefix mask\n"
358 "Distance value for this route\n"
359 "Emit an ICMP unreachable when matched\n"
360 "Silently discard pkts when matched\n")
362 return zebra_static_ipv4 (vty
, 1, argv
[0], argv
[1], NULL
, argv
[2], argv
[3]);
367 "no ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0)",
370 "Establish static routes\n"
371 "IP destination prefix (e.g. 10.0.0.0/8)\n"
372 "IP gateway address\n"
373 "IP gateway interface name\n"
376 return zebra_static_ipv4 (vty
, 0, argv
[0], NULL
, argv
[1], NULL
, NULL
);
380 no_ip_route_flags_cmd
,
381 "no ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole)",
384 "Establish static routes\n"
385 "IP destination prefix (e.g. 10.0.0.0/8)\n"
386 "IP gateway address\n"
387 "IP gateway interface name\n"
388 "Emit an ICMP unreachable when matched\n"
389 "Silently discard pkts when matched\n")
391 DEFUN (no_ip_route_flags2
,
392 no_ip_route_flags2_cmd
,
393 "no ip route A.B.C.D/M (reject|blackhole)",
396 "Establish static routes\n"
397 "IP destination prefix (e.g. 10.0.0.0/8)\n"
398 "Emit an ICMP unreachable when matched\n"
399 "Silently discard pkts when matched\n")
401 return zebra_static_ipv4 (vty
, 0, argv
[0], NULL
, NULL
, NULL
, NULL
);
404 DEFUN (no_ip_route_mask
,
405 no_ip_route_mask_cmd
,
406 "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0)",
409 "Establish static routes\n"
410 "IP destination prefix\n"
411 "IP destination prefix mask\n"
412 "IP gateway address\n"
413 "IP gateway interface name\n"
416 return zebra_static_ipv4 (vty
, 0, argv
[0], argv
[1], argv
[2], NULL
, NULL
);
419 ALIAS (no_ip_route_mask
,
420 no_ip_route_mask_flags_cmd
,
421 "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole)",
424 "Establish static routes\n"
425 "IP destination prefix\n"
426 "IP destination prefix mask\n"
427 "IP gateway address\n"
428 "IP gateway interface name\n"
429 "Emit an ICMP unreachable when matched\n"
430 "Silently discard pkts when matched\n")
432 DEFUN (no_ip_route_mask_flags2
,
433 no_ip_route_mask_flags2_cmd
,
434 "no ip route A.B.C.D A.B.C.D (reject|blackhole)",
437 "Establish static routes\n"
438 "IP destination prefix\n"
439 "IP destination prefix mask\n"
440 "Emit an ICMP unreachable when matched\n"
441 "Silently discard pkts when matched\n")
443 return zebra_static_ipv4 (vty
, 0, argv
[0], argv
[1], NULL
, NULL
, NULL
);
446 DEFUN (no_ip_route_distance
,
447 no_ip_route_distance_cmd
,
448 "no ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0) <1-255>",
451 "Establish static routes\n"
452 "IP destination prefix (e.g. 10.0.0.0/8)\n"
453 "IP gateway address\n"
454 "IP gateway interface name\n"
456 "Distance value for this route\n")
458 return zebra_static_ipv4 (vty
, 0, argv
[0], NULL
, argv
[1], NULL
, argv
[2]);
461 DEFUN (no_ip_route_flags_distance
,
462 no_ip_route_flags_distance_cmd
,
463 "no ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
466 "Establish static routes\n"
467 "IP destination prefix (e.g. 10.0.0.0/8)\n"
468 "IP gateway address\n"
469 "IP gateway interface name\n"
470 "Emit an ICMP unreachable when matched\n"
471 "Silently discard pkts when matched\n"
472 "Distance value for this route\n")
474 return zebra_static_ipv4 (vty
, 0, argv
[0], NULL
, argv
[1], argv
[2], argv
[3]);
477 DEFUN (no_ip_route_flags_distance2
,
478 no_ip_route_flags_distance2_cmd
,
479 "no ip route A.B.C.D/M (reject|blackhole) <1-255>",
482 "Establish static routes\n"
483 "IP destination prefix (e.g. 10.0.0.0/8)\n"
484 "Emit an ICMP unreachable when matched\n"
485 "Silently discard pkts when matched\n"
486 "Distance value for this route\n")
488 return zebra_static_ipv4 (vty
, 0, argv
[0], NULL
, NULL
, argv
[1], argv
[2]);
491 DEFUN (no_ip_route_mask_distance
,
492 no_ip_route_mask_distance_cmd
,
493 "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0) <1-255>",
496 "Establish static routes\n"
497 "IP destination prefix\n"
498 "IP destination prefix mask\n"
499 "IP gateway address\n"
500 "IP gateway interface name\n"
502 "Distance value for this route\n")
504 return zebra_static_ipv4 (vty
, 0, argv
[0], argv
[1], argv
[2], NULL
, argv
[3]);
507 DEFUN (no_ip_route_mask_flags_distance
,
508 no_ip_route_mask_flags_distance_cmd
,
509 "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
512 "Establish static routes\n"
513 "IP destination prefix\n"
514 "IP destination prefix mask\n"
515 "IP gateway address\n"
516 "IP gateway interface name\n"
517 "Emit an ICMP unreachable when matched\n"
518 "Silently discard pkts when matched\n"
519 "Distance value for this route\n")
521 return zebra_static_ipv4 (vty
, 0, argv
[0], argv
[1], argv
[2], argv
[3], argv
[4]);
524 DEFUN (no_ip_route_mask_flags_distance2
,
525 no_ip_route_mask_flags_distance2_cmd
,
526 "no ip route A.B.C.D A.B.C.D (reject|blackhole) <1-255>",
529 "Establish static routes\n"
530 "IP destination prefix\n"
531 "IP destination prefix mask\n"
532 "Emit an ICMP unreachable when matched\n"
533 "Silently discard pkts when matched\n"
534 "Distance value for this route\n")
536 return zebra_static_ipv4 (vty
, 0, argv
[0], argv
[1], NULL
, argv
[2], argv
[3]);
539 /* New RIB. Detailed information for IPv4 route. */
541 vty_show_ip_route_detail (struct vty
*vty
, struct route_node
*rn
)
544 struct nexthop
*nexthop
;
546 for (rib
= rn
->info
; rib
; rib
= rib
->next
)
548 vty_out (vty
, "Routing entry for %s/%d%s",
549 inet_ntoa (rn
->p
.u
.prefix4
), rn
->p
.prefixlen
,
551 vty_out (vty
, " Known via \"%s\"", route_type_str (rib
->type
));
552 vty_out (vty
, ", distance %d, metric %d", rib
->distance
, rib
->metric
);
553 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_SELECTED
))
554 vty_out (vty
, ", best");
556 vty_out (vty
, ", refcnt %ld", rib
->refcnt
);
557 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_BLACKHOLE
))
558 vty_out (vty
, ", blackhole");
559 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_REJECT
))
560 vty_out (vty
, ", reject");
561 vty_out (vty
, "%s", VTY_NEWLINE
);
563 #define ONE_DAY_SECOND 60*60*24
564 #define ONE_WEEK_SECOND 60*60*24*7
565 if (rib
->type
== ZEBRA_ROUTE_RIP
566 || rib
->type
== ZEBRA_ROUTE_OSPF
567 || rib
->type
== ZEBRA_ROUTE_ISIS
568 || rib
->type
== ZEBRA_ROUTE_BGP
)
573 uptime
= time (NULL
);
574 uptime
-= rib
->uptime
;
575 tm
= gmtime (&uptime
);
577 vty_out (vty
, " Last update ");
579 if (uptime
< ONE_DAY_SECOND
)
580 vty_out (vty
, "%02d:%02d:%02d",
581 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
582 else if (uptime
< ONE_WEEK_SECOND
)
583 vty_out (vty
, "%dd%02dh%02dm",
584 tm
->tm_yday
, tm
->tm_hour
, tm
->tm_min
);
586 vty_out (vty
, "%02dw%dd%02dh",
588 tm
->tm_yday
- ((tm
->tm_yday
/7) * 7), tm
->tm_hour
);
589 vty_out (vty
, " ago%s", VTY_NEWLINE
);
592 for (nexthop
= rib
->nexthop
; nexthop
; nexthop
= nexthop
->next
)
595 CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
) ? '*' : ' ');
597 switch (nexthop
->type
)
599 case NEXTHOP_TYPE_IPV4
:
600 case NEXTHOP_TYPE_IPV4_IFINDEX
:
601 vty_out (vty
, " %s", inet_ntoa (nexthop
->gate
.ipv4
));
602 if (nexthop
->ifindex
)
603 vty_out (vty
, ", via %s", ifindex2ifname (nexthop
->ifindex
));
605 case NEXTHOP_TYPE_IFINDEX
:
606 vty_out (vty
, " directly connected, %s",
607 ifindex2ifname (nexthop
->ifindex
));
609 case NEXTHOP_TYPE_IFNAME
:
610 vty_out (vty
, " directly connected, %s", nexthop
->ifname
);
612 case NEXTHOP_TYPE_BLACKHOLE
:
613 vty_out (vty
, " directly connected, Null0");
618 if (! CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
))
619 vty_out (vty
, " inactive");
621 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_RECURSIVE
))
623 vty_out (vty
, " (recursive");
625 switch (nexthop
->rtype
)
627 case NEXTHOP_TYPE_IPV4
:
628 case NEXTHOP_TYPE_IPV4_IFINDEX
:
629 vty_out (vty
, " via %s)", inet_ntoa (nexthop
->rgate
.ipv4
));
631 case NEXTHOP_TYPE_IFINDEX
:
632 case NEXTHOP_TYPE_IFNAME
:
633 vty_out (vty
, " is directly connected, %s)",
634 ifindex2ifname (nexthop
->rifindex
));
640 vty_out (vty
, "%s", VTY_NEWLINE
);
642 vty_out (vty
, "%s", VTY_NEWLINE
);
647 vty_show_ip_route (struct vty
*vty
, struct route_node
*rn
, struct rib
*rib
)
649 struct nexthop
*nexthop
;
653 /* Nexthop information. */
654 for (nexthop
= rib
->nexthop
; nexthop
; nexthop
= nexthop
->next
)
656 if (nexthop
== rib
->nexthop
)
658 /* Prefix information. */
659 len
= vty_out (vty
, "%c%c%c %s/%d",
660 route_type_char (rib
->type
),
661 CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_SELECTED
)
663 CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
)
665 inet_ntop (AF_INET
, &rn
->p
.u
.prefix
, buf
, BUFSIZ
),
668 /* Distance and metric display. */
669 if (rib
->type
!= ZEBRA_ROUTE_CONNECT
670 && rib
->type
!= ZEBRA_ROUTE_KERNEL
)
671 len
+= vty_out (vty
, " [%d/%d]", rib
->distance
,
675 vty_out (vty
, " %c%*c",
676 CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
)
680 switch (nexthop
->type
)
682 case NEXTHOP_TYPE_IPV4
:
683 case NEXTHOP_TYPE_IPV4_IFINDEX
:
684 vty_out (vty
, " via %s", inet_ntoa (nexthop
->gate
.ipv4
));
685 if (nexthop
->ifindex
)
686 vty_out (vty
, ", %s", ifindex2ifname (nexthop
->ifindex
));
688 case NEXTHOP_TYPE_IFINDEX
:
689 vty_out (vty
, " is directly connected, %s",
690 ifindex2ifname (nexthop
->ifindex
));
692 case NEXTHOP_TYPE_IFNAME
:
693 vty_out (vty
, " is directly connected, %s", nexthop
->ifname
);
695 case NEXTHOP_TYPE_BLACKHOLE
:
696 vty_out (vty
, " is directly connected, Null0");
701 if (! CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
))
702 vty_out (vty
, " inactive");
704 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_RECURSIVE
))
706 vty_out (vty
, " (recursive");
708 switch (nexthop
->rtype
)
710 case NEXTHOP_TYPE_IPV4
:
711 case NEXTHOP_TYPE_IPV4_IFINDEX
:
712 vty_out (vty
, " via %s)", inet_ntoa (nexthop
->rgate
.ipv4
));
714 case NEXTHOP_TYPE_IFINDEX
:
715 case NEXTHOP_TYPE_IFNAME
:
716 vty_out (vty
, " is directly connected, %s)",
717 ifindex2ifname (nexthop
->rifindex
));
724 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_BLACKHOLE
))
725 vty_out (vty
, ", bh");
726 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_REJECT
))
727 vty_out (vty
, ", rej");
729 if (rib
->type
== ZEBRA_ROUTE_RIP
730 || rib
->type
== ZEBRA_ROUTE_OSPF
731 || rib
->type
== ZEBRA_ROUTE_ISIS
732 || rib
->type
== ZEBRA_ROUTE_BGP
)
737 uptime
= time (NULL
);
738 uptime
-= rib
->uptime
;
739 tm
= gmtime (&uptime
);
741 #define ONE_DAY_SECOND 60*60*24
742 #define ONE_WEEK_SECOND 60*60*24*7
744 if (uptime
< ONE_DAY_SECOND
)
745 vty_out (vty
, ", %02d:%02d:%02d",
746 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
747 else if (uptime
< ONE_WEEK_SECOND
)
748 vty_out (vty
, ", %dd%02dh%02dm",
749 tm
->tm_yday
, tm
->tm_hour
, tm
->tm_min
);
751 vty_out (vty
, ", %02dw%dd%02dh",
753 tm
->tm_yday
- ((tm
->tm_yday
/7) * 7), tm
->tm_hour
);
755 vty_out (vty
, "%s", VTY_NEWLINE
);
759 #define SHOW_ROUTE_V4_HEADER "Codes: K - kernel route, C - connected, " \
760 "S - static, R - RIP, O - OSPF,%s I - ISIS, B - BGP, " \
761 "> - selected route, * - FIB route%s%s"
763 DEFUN (show_ip_route
,
768 "IP routing table\n")
770 struct route_table
*table
;
771 struct route_node
*rn
;
775 table
= vrf_table (AFI_IP
, SAFI_UNICAST
, 0);
779 /* Show all IPv4 routes. */
780 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
781 for (rib
= rn
->info
; rib
; rib
= rib
->next
)
785 vty_out (vty
, SHOW_ROUTE_V4_HEADER
, VTY_NEWLINE
, VTY_NEWLINE
,
789 vty_show_ip_route (vty
, rn
, rib
);
794 DEFUN (show_ip_route_prefix_longer
,
795 show_ip_route_prefix_longer_cmd
,
796 "show ip route A.B.C.D/M longer-prefixes",
800 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
801 "Show route matching the specified Network/Mask pair only\n")
803 struct route_table
*table
;
804 struct route_node
*rn
;
810 ret
= str2prefix (argv
[0], &p
);
813 vty_out (vty
, "%% Malformed Prefix%s", VTY_NEWLINE
);
817 table
= vrf_table (AFI_IP
, SAFI_UNICAST
, 0);
821 /* Show matched type IPv4 routes. */
822 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
823 for (rib
= rn
->info
; rib
; rib
= rib
->next
)
824 if (prefix_match (&p
, &rn
->p
))
828 vty_out (vty
, SHOW_ROUTE_V4_HEADER
, VTY_NEWLINE
,
829 VTY_NEWLINE
, VTY_NEWLINE
);
832 vty_show_ip_route (vty
, rn
, rib
);
837 DEFUN (show_ip_route_supernets
,
838 show_ip_route_supernets_cmd
,
839 "show ip route supernets-only",
843 "Show supernet entries only\n")
845 struct route_table
*table
;
846 struct route_node
*rn
;
851 table
= vrf_table (AFI_IP
, SAFI_UNICAST
, 0);
855 /* Show matched type IPv4 routes. */
856 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
857 for (rib
= rn
->info
; rib
; rib
= rib
->next
)
859 addr
= ntohl (rn
->p
.u
.prefix4
.s_addr
);
861 if ((IN_CLASSC (addr
) && rn
->p
.prefixlen
< 24)
862 || (IN_CLASSB (addr
) && rn
->p
.prefixlen
< 16)
863 || (IN_CLASSA (addr
) && rn
->p
.prefixlen
< 8))
867 vty_out (vty
, SHOW_ROUTE_V4_HEADER
, VTY_NEWLINE
,
868 VTY_NEWLINE
, VTY_NEWLINE
);
871 vty_show_ip_route (vty
, rn
, rib
);
877 DEFUN (show_ip_route_protocol
,
878 show_ip_route_protocol_cmd
,
879 "show ip route (bgp|connected|isis|kernel|ospf|rip|static)",
883 "Border Gateway Protocol (BGP)\n"
887 "Open Shortest Path First (OSPF)\n"
888 "Routing Information Protocol (RIP)\n"
892 struct route_table
*table
;
893 struct route_node
*rn
;
897 if (strncmp (argv
[0], "b", 1) == 0)
898 type
= ZEBRA_ROUTE_BGP
;
899 else if (strncmp (argv
[0], "c", 1) == 0)
900 type
= ZEBRA_ROUTE_CONNECT
;
901 else if (strncmp (argv
[0], "k", 1) ==0)
902 type
= ZEBRA_ROUTE_KERNEL
;
903 else if (strncmp (argv
[0], "o", 1) == 0)
904 type
= ZEBRA_ROUTE_OSPF
;
905 else if (strncmp (argv
[0], "i", 1) == 0)
906 type
= ZEBRA_ROUTE_ISIS
;
907 else if (strncmp (argv
[0], "r", 1) == 0)
908 type
= ZEBRA_ROUTE_RIP
;
909 else if (strncmp (argv
[0], "s", 1) == 0)
910 type
= ZEBRA_ROUTE_STATIC
;
913 vty_out (vty
, "Unknown route type%s", VTY_NEWLINE
);
917 table
= vrf_table (AFI_IP
, SAFI_UNICAST
, 0);
921 /* Show matched type IPv4 routes. */
922 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
923 for (rib
= rn
->info
; rib
; rib
= rib
->next
)
924 if (rib
->type
== type
)
928 vty_out (vty
, SHOW_ROUTE_V4_HEADER
,
929 VTY_NEWLINE
, VTY_NEWLINE
, VTY_NEWLINE
);
932 vty_show_ip_route (vty
, rn
, rib
);
937 DEFUN (show_ip_route_addr
,
938 show_ip_route_addr_cmd
,
939 "show ip route A.B.C.D",
943 "Network in the IP routing table to display\n")
946 struct prefix_ipv4 p
;
947 struct route_table
*table
;
948 struct route_node
*rn
;
950 ret
= str2prefix_ipv4 (argv
[0], &p
);
953 vty_out (vty
, "%% Malformed IPv4 address%s", VTY_NEWLINE
);
957 table
= vrf_table (AFI_IP
, SAFI_UNICAST
, 0);
961 rn
= route_node_match (table
, (struct prefix
*) &p
);
964 vty_out (vty
, "%% Network not in table%s", VTY_NEWLINE
);
968 vty_show_ip_route_detail (vty
, rn
);
970 route_unlock_node (rn
);
975 DEFUN (show_ip_route_prefix
,
976 show_ip_route_prefix_cmd
,
977 "show ip route A.B.C.D/M",
981 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
984 struct prefix_ipv4 p
;
985 struct route_table
*table
;
986 struct route_node
*rn
;
988 ret
= str2prefix_ipv4 (argv
[0], &p
);
991 vty_out (vty
, "%% Malformed IPv4 address%s", VTY_NEWLINE
);
995 table
= vrf_table (AFI_IP
, SAFI_UNICAST
, 0);
999 rn
= route_node_match (table
, (struct prefix
*) &p
);
1000 if (! rn
|| rn
->p
.prefixlen
!= p
.prefixlen
)
1002 vty_out (vty
, "%% Network not in table%s", VTY_NEWLINE
);
1006 vty_show_ip_route_detail (vty
, rn
);
1008 route_unlock_node (rn
);
1014 zebra_show_ip_route (struct vty
*vty
, struct vrf
*vrf
)
1016 vty_out (vty
, "IP routing table name is %s(%d)%s",
1017 vrf
->name
? vrf
->name
: "", vrf
->id
, VTY_NEWLINE
);
1019 vty_out (vty
, "Route Source Networks%s", VTY_NEWLINE
);
1020 vty_out (vty
, "connected %d%s", 0, VTY_NEWLINE
);
1021 vty_out (vty
, "static %d%s", 0, VTY_NEWLINE
);
1022 vty_out (vty
, "rip %d%s", 0, VTY_NEWLINE
);
1024 vty_out (vty
, "bgp %d%s", 0, VTY_NEWLINE
);
1025 vty_out (vty
, " External: %d Internal: %d Local: %d%s",
1026 0, 0, 0, VTY_NEWLINE
);
1028 vty_out (vty
, "ospf %d%s", 0, VTY_NEWLINE
);
1030 " Intra-area: %d Inter-area: %d External-1: %d External-2: %d%s",
1031 0, 0, 0, 0, VTY_NEWLINE
);
1032 vty_out (vty
, " NSSA External-1: %d NSSA External-2: %d%s",
1035 vty_out (vty
, "internal %d%s", 0, VTY_NEWLINE
);
1036 vty_out (vty
, "Total %d%s", 0, VTY_NEWLINE
);
1039 /* Show route summary. */
1040 DEFUN (show_ip_route_summary
,
1041 show_ip_route_summary_cmd
,
1042 "show ip route summary",
1045 "IP routing table\n"
1046 "Summary of all routes\n")
1050 /* Default table id is zero. */
1051 vrf
= vrf_lookup (0);
1054 vty_out (vty
, "%% No Default-IP-Routing-Table%s", VTY_NEWLINE
);
1058 zebra_show_ip_route (vty
, vrf
);
1063 /* Write IPv4 static route configuration. */
1065 static_config_ipv4 (struct vty
*vty
)
1067 struct route_node
*rn
;
1068 struct static_ipv4
*si
;
1069 struct route_table
*stable
;
1075 stable
= vrf_static_table (AFI_IP
, SAFI_UNICAST
, 0);
1079 for (rn
= route_top (stable
); rn
; rn
= route_next (rn
))
1080 for (si
= rn
->info
; si
; si
= si
->next
)
1082 vty_out (vty
, "ip route %s/%d", inet_ntoa (rn
->p
.u
.prefix4
),
1087 case STATIC_IPV4_GATEWAY
:
1088 vty_out (vty
, " %s", inet_ntoa (si
->gate
.ipv4
));
1090 case STATIC_IPV4_IFNAME
:
1091 vty_out (vty
, " %s", si
->gate
.ifname
);
1093 case STATIC_IPV4_BLACKHOLE
:
1094 vty_out (vty
, " Null0");
1098 /* flags are incompatible with STATIC_IPV4_BLACKHOLE */
1099 if (si
->type
!= STATIC_IPV4_BLACKHOLE
)
1101 if (CHECK_FLAG(si
->flags
, ZEBRA_FLAG_REJECT
))
1102 vty_out (vty
, " %s", "reject");
1104 if (CHECK_FLAG(si
->flags
, ZEBRA_FLAG_BLACKHOLE
))
1105 vty_out (vty
, " %s", "blackhole");
1108 if (si
->distance
!= ZEBRA_STATIC_DISTANCE_DEFAULT
)
1109 vty_out (vty
, " %d", si
->distance
);
1111 vty_out (vty
, "%s", VTY_NEWLINE
);
1119 /* General fucntion for IPv6 static route. */
1121 static_ipv6_func (struct vty
*vty
, int add_cmd
, const char *dest_str
,
1122 const char *gate_str
, const char *ifname
,
1123 const char *flag_str
, const char *distance_str
)
1128 struct in6_addr
*gate
= NULL
;
1129 struct in6_addr gate_addr
;
1134 ret
= str2prefix (dest_str
, &p
);
1137 vty_out (vty
, "%% Malformed address%s", VTY_NEWLINE
);
1141 /* Apply mask for given prefix. */
1146 switch(flag_str
[0]) {
1149 SET_FLAG (flag
, ZEBRA_FLAG_REJECT
);
1153 SET_FLAG (flag
, ZEBRA_FLAG_BLACKHOLE
);
1156 vty_out (vty
, "%% Malformed flag %s %s", flag_str
, VTY_NEWLINE
);
1161 /* Administrative distance. */
1163 distance
= atoi (distance_str
);
1165 distance
= ZEBRA_STATIC_DISTANCE_DEFAULT
;
1167 /* When gateway is valid IPv6 addrees, then gate is treated as
1168 nexthop address other case gate is treated as interface name. */
1169 ret
= inet_pton (AF_INET6
, gate_str
, &gate_addr
);
1173 /* When ifname is specified. It must be come with gateway
1177 vty_out (vty
, "%% Malformed address%s", VTY_NEWLINE
);
1180 type
= STATIC_IPV6_GATEWAY_IFNAME
;
1187 type
= STATIC_IPV6_GATEWAY
;
1192 type
= STATIC_IPV6_IFNAME
;
1198 static_add_ipv6 (&p
, type
, gate
, ifname
, flag
, distance
, table
);
1200 static_delete_ipv6 (&p
, type
, gate
, ifname
, distance
, table
);
1207 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE)",
1209 "Establish static routes\n"
1210 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1211 "IPv6 gateway address\n"
1212 "IPv6 gateway interface name\n")
1214 return static_ipv6_func (vty
, 1, argv
[0], argv
[1], NULL
, NULL
, NULL
);
1217 DEFUN (ipv6_route_flags
,
1218 ipv6_route_flags_cmd
,
1219 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole)",
1221 "Establish static routes\n"
1222 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1223 "IPv6 gateway address\n"
1224 "IPv6 gateway interface name\n"
1225 "Emit an ICMP unreachable when matched\n"
1226 "Silently discard pkts when matched\n")
1228 return static_ipv6_func (vty
, 1, argv
[0], argv
[1], NULL
, argv
[2], NULL
);
1231 DEFUN (ipv6_route_ifname
,
1232 ipv6_route_ifname_cmd
,
1233 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE",
1235 "Establish static routes\n"
1236 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1237 "IPv6 gateway address\n"
1238 "IPv6 gateway interface name\n")
1240 return static_ipv6_func (vty
, 1, argv
[0], argv
[1], argv
[2], NULL
, NULL
);
1243 DEFUN (ipv6_route_ifname_flags
,
1244 ipv6_route_ifname_flags_cmd
,
1245 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole)",
1247 "Establish static routes\n"
1248 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1249 "IPv6 gateway address\n"
1250 "IPv6 gateway interface name\n"
1251 "Emit an ICMP unreachable when matched\n"
1252 "Silently discard pkts when matched\n")
1254 return static_ipv6_func (vty
, 1, argv
[0], argv
[1], argv
[2], argv
[3], NULL
);
1257 DEFUN (ipv6_route_pref
,
1258 ipv6_route_pref_cmd
,
1259 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <1-255>",
1261 "Establish static routes\n"
1262 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1263 "IPv6 gateway address\n"
1264 "IPv6 gateway interface name\n"
1265 "Distance value for this prefix\n")
1267 return static_ipv6_func (vty
, 1, argv
[0], argv
[1], NULL
, NULL
, argv
[2]);
1270 DEFUN (ipv6_route_flags_pref
,
1271 ipv6_route_flags_pref_cmd
,
1272 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) <1-255>",
1274 "Establish static routes\n"
1275 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1276 "IPv6 gateway address\n"
1277 "IPv6 gateway interface name\n"
1278 "Emit an ICMP unreachable when matched\n"
1279 "Silently discard pkts when matched\n"
1280 "Distance value for this prefix\n")
1282 return static_ipv6_func (vty
, 1, argv
[0], argv
[1], NULL
, argv
[2], argv
[3]);
1285 DEFUN (ipv6_route_ifname_pref
,
1286 ipv6_route_ifname_pref_cmd
,
1287 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255>",
1289 "Establish static routes\n"
1290 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1291 "IPv6 gateway address\n"
1292 "IPv6 gateway interface name\n"
1293 "Distance value for this prefix\n")
1295 return static_ipv6_func (vty
, 1, argv
[0], argv
[1], argv
[2], NULL
, argv
[3]);
1298 DEFUN (ipv6_route_ifname_flags_pref
,
1299 ipv6_route_ifname_flags_pref_cmd
,
1300 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) <1-255>",
1302 "Establish static routes\n"
1303 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1304 "IPv6 gateway address\n"
1305 "IPv6 gateway interface name\n"
1306 "Emit an ICMP unreachable when matched\n"
1307 "Silently discard pkts when matched\n"
1308 "Distance value for this prefix\n")
1310 return static_ipv6_func (vty
, 1, argv
[0], argv
[1], argv
[2], argv
[3], argv
[4]);
1313 DEFUN (no_ipv6_route
,
1315 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE)",
1318 "Establish static routes\n"
1319 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1320 "IPv6 gateway address\n"
1321 "IPv6 gateway interface name\n")
1323 return static_ipv6_func (vty
, 0, argv
[0], argv
[1], NULL
, NULL
, NULL
);
1326 ALIAS (no_ipv6_route
,
1327 no_ipv6_route_flags_cmd
,
1328 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole)",
1331 "Establish static routes\n"
1332 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1333 "IPv6 gateway address\n"
1334 "IPv6 gateway interface name\n"
1335 "Emit an ICMP unreachable when matched\n"
1336 "Silently discard pkts when matched\n")
1338 DEFUN (no_ipv6_route_ifname
,
1339 no_ipv6_route_ifname_cmd
,
1340 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE",
1343 "Establish static routes\n"
1344 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1345 "IPv6 gateway address\n"
1346 "IPv6 gateway interface name\n")
1348 return static_ipv6_func (vty
, 0, argv
[0], argv
[1], argv
[2], NULL
, NULL
);
1351 ALIAS (no_ipv6_route_ifname
,
1352 no_ipv6_route_ifname_flags_cmd
,
1353 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole)",
1356 "Establish static routes\n"
1357 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1358 "IPv6 gateway address\n"
1359 "IPv6 gateway interface name\n"
1360 "Emit an ICMP unreachable when matched\n"
1361 "Silently discard pkts when matched\n")
1363 DEFUN (no_ipv6_route_pref
,
1364 no_ipv6_route_pref_cmd
,
1365 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <1-255>",
1368 "Establish static routes\n"
1369 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1370 "IPv6 gateway address\n"
1371 "IPv6 gateway interface name\n"
1372 "Distance value for this prefix\n")
1374 return static_ipv6_func (vty
, 0, argv
[0], argv
[1], NULL
, NULL
, argv
[2]);
1377 DEFUN (no_ipv6_route_flags_pref
,
1378 no_ipv6_route_flags_pref_cmd
,
1379 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) <1-255>",
1382 "Establish static routes\n"
1383 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1384 "IPv6 gateway address\n"
1385 "IPv6 gateway interface name\n"
1386 "Emit an ICMP unreachable when matched\n"
1387 "Silently discard pkts when matched\n"
1388 "Distance value for this prefix\n")
1390 /* We do not care about argv[2] */
1391 return static_ipv6_func (vty
, 0, argv
[0], argv
[1], NULL
, argv
[2], argv
[3]);
1394 DEFUN (no_ipv6_route_ifname_pref
,
1395 no_ipv6_route_ifname_pref_cmd
,
1396 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255>",
1399 "Establish static routes\n"
1400 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1401 "IPv6 gateway address\n"
1402 "IPv6 gateway interface name\n"
1403 "Distance value for this prefix\n")
1405 return static_ipv6_func (vty
, 0, argv
[0], argv
[1], argv
[2], NULL
, argv
[3]);
1408 DEFUN (no_ipv6_route_ifname_flags_pref
,
1409 no_ipv6_route_ifname_flags_pref_cmd
,
1410 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) <1-255>",
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")
1421 return static_ipv6_func (vty
, 0, argv
[0], argv
[1], argv
[2], argv
[3], argv
[4]);
1424 /* New RIB. Detailed information for IPv6 route. */
1426 vty_show_ipv6_route_detail (struct vty
*vty
, struct route_node
*rn
)
1429 struct nexthop
*nexthop
;
1432 for (rib
= rn
->info
; rib
; rib
= rib
->next
)
1434 vty_out (vty
, "Routing entry for %s/%d%s",
1435 inet_ntop (AF_INET6
, &rn
->p
.u
.prefix6
, buf
, BUFSIZ
),
1438 vty_out (vty
, " Known via \"%s\"", route_type_str (rib
->type
));
1439 vty_out (vty
, ", distance %d, metric %d", rib
->distance
, rib
->metric
);
1440 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_SELECTED
))
1441 vty_out (vty
, ", best");
1443 vty_out (vty
, ", refcnt %ld", rib
->refcnt
);
1444 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_BLACKHOLE
))
1445 vty_out (vty
, ", blackhole");
1446 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_REJECT
))
1447 vty_out (vty
, ", reject");
1448 vty_out (vty
, "%s", VTY_NEWLINE
);
1450 #define ONE_DAY_SECOND 60*60*24
1451 #define ONE_WEEK_SECOND 60*60*24*7
1452 if (rib
->type
== ZEBRA_ROUTE_RIPNG
1453 || rib
->type
== ZEBRA_ROUTE_OSPF6
1454 || rib
->type
== ZEBRA_ROUTE_ISIS
1455 || rib
->type
== ZEBRA_ROUTE_BGP
)
1460 uptime
= time (NULL
);
1461 uptime
-= rib
->uptime
;
1462 tm
= gmtime (&uptime
);
1464 vty_out (vty
, " Last update ");
1466 if (uptime
< ONE_DAY_SECOND
)
1467 vty_out (vty
, "%02d:%02d:%02d",
1468 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
1469 else if (uptime
< ONE_WEEK_SECOND
)
1470 vty_out (vty
, "%dd%02dh%02dm",
1471 tm
->tm_yday
, tm
->tm_hour
, tm
->tm_min
);
1473 vty_out (vty
, "%02dw%dd%02dh",
1475 tm
->tm_yday
- ((tm
->tm_yday
/7) * 7), tm
->tm_hour
);
1476 vty_out (vty
, " ago%s", VTY_NEWLINE
);
1479 for (nexthop
= rib
->nexthop
; nexthop
; nexthop
= nexthop
->next
)
1481 vty_out (vty
, " %c",
1482 CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
) ? '*' : ' ');
1484 switch (nexthop
->type
)
1486 case NEXTHOP_TYPE_IPV6
:
1487 case NEXTHOP_TYPE_IPV6_IFINDEX
:
1488 case NEXTHOP_TYPE_IPV6_IFNAME
:
1489 vty_out (vty
, " %s",
1490 inet_ntop (AF_INET6
, &nexthop
->gate
.ipv6
, buf
, BUFSIZ
));
1491 if (nexthop
->type
== NEXTHOP_TYPE_IPV6_IFNAME
)
1492 vty_out (vty
, ", %s", nexthop
->ifname
);
1493 else if (nexthop
->ifindex
)
1494 vty_out (vty
, ", via %s", ifindex2ifname (nexthop
->ifindex
));
1496 case NEXTHOP_TYPE_IFINDEX
:
1497 vty_out (vty
, " directly connected, %s",
1498 ifindex2ifname (nexthop
->ifindex
));
1500 case NEXTHOP_TYPE_IFNAME
:
1501 vty_out (vty
, " directly connected, %s",
1507 if (! CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
))
1508 vty_out (vty
, " inactive");
1510 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_RECURSIVE
))
1512 vty_out (vty
, " (recursive");
1514 switch (nexthop
->rtype
)
1516 case NEXTHOP_TYPE_IPV6
:
1517 case NEXTHOP_TYPE_IPV6_IFINDEX
:
1518 case NEXTHOP_TYPE_IPV6_IFNAME
:
1519 vty_out (vty
, " via %s)",
1520 inet_ntop (AF_INET6
, &nexthop
->rgate
.ipv6
,
1522 if (nexthop
->rifindex
)
1523 vty_out (vty
, ", %s", ifindex2ifname (nexthop
->rifindex
));
1525 case NEXTHOP_TYPE_IFINDEX
:
1526 case NEXTHOP_TYPE_IFNAME
:
1527 vty_out (vty
, " is directly connected, %s)",
1528 ifindex2ifname (nexthop
->rifindex
));
1534 vty_out (vty
, "%s", VTY_NEWLINE
);
1536 vty_out (vty
, "%s", VTY_NEWLINE
);
1541 vty_show_ipv6_route (struct vty
*vty
, struct route_node
*rn
,
1544 struct nexthop
*nexthop
;
1548 /* Nexthop information. */
1549 for (nexthop
= rib
->nexthop
; nexthop
; nexthop
= nexthop
->next
)
1551 if (nexthop
== rib
->nexthop
)
1553 /* Prefix information. */
1554 len
= vty_out (vty
, "%c%c%c %s/%d",
1555 route_type_char (rib
->type
),
1556 CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_SELECTED
)
1558 CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
)
1560 inet_ntop (AF_INET6
, &rn
->p
.u
.prefix6
, buf
, BUFSIZ
),
1563 /* Distance and metric display. */
1564 if (rib
->type
!= ZEBRA_ROUTE_CONNECT
1565 && rib
->type
!= ZEBRA_ROUTE_KERNEL
)
1566 len
+= vty_out (vty
, " [%d/%d]", rib
->distance
,
1570 vty_out (vty
, " %c%*c",
1571 CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
)
1575 switch (nexthop
->type
)
1577 case NEXTHOP_TYPE_IPV6
:
1578 case NEXTHOP_TYPE_IPV6_IFINDEX
:
1579 case NEXTHOP_TYPE_IPV6_IFNAME
:
1580 vty_out (vty
, " via %s",
1581 inet_ntop (AF_INET6
, &nexthop
->gate
.ipv6
, buf
, BUFSIZ
));
1582 if (nexthop
->type
== NEXTHOP_TYPE_IPV6_IFNAME
)
1583 vty_out (vty
, ", %s", nexthop
->ifname
);
1584 else if (nexthop
->ifindex
)
1585 vty_out (vty
, ", %s", ifindex2ifname (nexthop
->ifindex
));
1587 case NEXTHOP_TYPE_IFINDEX
:
1588 vty_out (vty
, " is directly connected, %s",
1589 ifindex2ifname (nexthop
->ifindex
));
1591 case NEXTHOP_TYPE_IFNAME
:
1592 vty_out (vty
, " is directly connected, %s",
1598 if (! CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
))
1599 vty_out (vty
, " inactive");
1601 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_RECURSIVE
))
1603 vty_out (vty
, " (recursive");
1605 switch (nexthop
->rtype
)
1607 case NEXTHOP_TYPE_IPV6
:
1608 case NEXTHOP_TYPE_IPV6_IFINDEX
:
1609 case NEXTHOP_TYPE_IPV6_IFNAME
:
1610 vty_out (vty
, " via %s)",
1611 inet_ntop (AF_INET6
, &nexthop
->rgate
.ipv6
,
1613 if (nexthop
->rifindex
)
1614 vty_out (vty
, ", %s", ifindex2ifname (nexthop
->rifindex
));
1616 case NEXTHOP_TYPE_IFINDEX
:
1617 case NEXTHOP_TYPE_IFNAME
:
1618 vty_out (vty
, " is directly connected, %s)",
1619 ifindex2ifname (nexthop
->rifindex
));
1626 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_BLACKHOLE
))
1627 vty_out (vty
, ", bh");
1628 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_REJECT
))
1629 vty_out (vty
, ", rej");
1631 if (rib
->type
== ZEBRA_ROUTE_RIPNG
1632 || rib
->type
== ZEBRA_ROUTE_OSPF6
1633 || rib
->type
== ZEBRA_ROUTE_ISIS
1634 || rib
->type
== ZEBRA_ROUTE_BGP
)
1639 uptime
= time (NULL
);
1640 uptime
-= rib
->uptime
;
1641 tm
= gmtime (&uptime
);
1643 #define ONE_DAY_SECOND 60*60*24
1644 #define ONE_WEEK_SECOND 60*60*24*7
1646 if (uptime
< ONE_DAY_SECOND
)
1647 vty_out (vty
, ", %02d:%02d:%02d",
1648 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
1649 else if (uptime
< ONE_WEEK_SECOND
)
1650 vty_out (vty
, ", %dd%02dh%02dm",
1651 tm
->tm_yday
, tm
->tm_hour
, tm
->tm_min
);
1653 vty_out (vty
, ", %02dw%dd%02dh",
1655 tm
->tm_yday
- ((tm
->tm_yday
/7) * 7), tm
->tm_hour
);
1657 vty_out (vty
, "%s", VTY_NEWLINE
);
1661 #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"
1663 DEFUN (show_ipv6_route
,
1664 show_ipv6_route_cmd
,
1668 "IPv6 routing table\n")
1670 struct route_table
*table
;
1671 struct route_node
*rn
;
1675 table
= vrf_table (AFI_IP6
, SAFI_UNICAST
, 0);
1679 /* Show all IPv6 route. */
1680 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
1681 for (rib
= rn
->info
; rib
; rib
= rib
->next
)
1685 vty_out (vty
, SHOW_ROUTE_V6_HEADER
, VTY_NEWLINE
, VTY_NEWLINE
, VTY_NEWLINE
);
1688 vty_show_ipv6_route (vty
, rn
, rib
);
1693 DEFUN (show_ipv6_route_prefix_longer
,
1694 show_ipv6_route_prefix_longer_cmd
,
1695 "show ipv6 route X:X::X:X/M longer-prefixes",
1698 "IPv6 routing table\n"
1700 "Show route matching the specified Network/Mask pair only\n")
1702 struct route_table
*table
;
1703 struct route_node
*rn
;
1709 table
= vrf_table (AFI_IP6
, SAFI_UNICAST
, 0);
1713 ret
= str2prefix (argv
[0], &p
);
1716 vty_out (vty
, "%% Malformed Prefix%s", VTY_NEWLINE
);
1720 /* Show matched type IPv6 routes. */
1721 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
1722 for (rib
= rn
->info
; rib
; rib
= rib
->next
)
1723 if (prefix_match (&p
, &rn
->p
))
1727 vty_out (vty
, SHOW_ROUTE_V6_HEADER
, VTY_NEWLINE
, VTY_NEWLINE
, VTY_NEWLINE
);
1730 vty_show_ipv6_route (vty
, rn
, rib
);
1735 DEFUN (show_ipv6_route_protocol
,
1736 show_ipv6_route_protocol_cmd
,
1737 "show ipv6 route (bgp|connected|isis|kernel|ospf6|ripng|static)",
1740 "IP routing table\n"
1741 "Border Gateway Protocol (BGP)\n"
1743 "ISO IS-IS (ISIS)\n"
1745 "Open Shortest Path First (OSPFv3)\n"
1746 "Routing Information Protocol (RIPng)\n"
1750 struct route_table
*table
;
1751 struct route_node
*rn
;
1755 if (strncmp (argv
[0], "b", 1) == 0)
1756 type
= ZEBRA_ROUTE_BGP
;
1757 else if (strncmp (argv
[0], "c", 1) == 0)
1758 type
= ZEBRA_ROUTE_CONNECT
;
1759 else if (strncmp (argv
[0], "k", 1) ==0)
1760 type
= ZEBRA_ROUTE_KERNEL
;
1761 else if (strncmp (argv
[0], "o", 1) == 0)
1762 type
= ZEBRA_ROUTE_OSPF6
;
1763 else if (strncmp (argv
[0], "i", 1) == 0)
1764 type
= ZEBRA_ROUTE_ISIS
;
1765 else if (strncmp (argv
[0], "r", 1) == 0)
1766 type
= ZEBRA_ROUTE_RIPNG
;
1767 else if (strncmp (argv
[0], "s", 1) == 0)
1768 type
= ZEBRA_ROUTE_STATIC
;
1771 vty_out (vty
, "Unknown route type%s", VTY_NEWLINE
);
1775 table
= vrf_table (AFI_IP6
, SAFI_UNICAST
, 0);
1779 /* Show matched type IPv6 routes. */
1780 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
1781 for (rib
= rn
->info
; rib
; rib
= rib
->next
)
1782 if (rib
->type
== type
)
1786 vty_out (vty
, SHOW_ROUTE_V6_HEADER
, VTY_NEWLINE
, VTY_NEWLINE
, VTY_NEWLINE
);
1789 vty_show_ipv6_route (vty
, rn
, rib
);
1794 DEFUN (show_ipv6_route_addr
,
1795 show_ipv6_route_addr_cmd
,
1796 "show ipv6 route X:X::X:X",
1799 "IPv6 routing table\n"
1803 struct prefix_ipv6 p
;
1804 struct route_table
*table
;
1805 struct route_node
*rn
;
1807 ret
= str2prefix_ipv6 (argv
[0], &p
);
1810 vty_out (vty
, "Malformed IPv6 address%s", VTY_NEWLINE
);
1814 table
= vrf_table (AFI_IP6
, SAFI_UNICAST
, 0);
1818 rn
= route_node_match (table
, (struct prefix
*) &p
);
1821 vty_out (vty
, "%% Network not in table%s", VTY_NEWLINE
);
1825 vty_show_ipv6_route_detail (vty
, rn
);
1827 route_unlock_node (rn
);
1832 DEFUN (show_ipv6_route_prefix
,
1833 show_ipv6_route_prefix_cmd
,
1834 "show ipv6 route X:X::X:X/M",
1837 "IPv6 routing table\n"
1841 struct prefix_ipv6 p
;
1842 struct route_table
*table
;
1843 struct route_node
*rn
;
1845 ret
= str2prefix_ipv6 (argv
[0], &p
);
1848 vty_out (vty
, "Malformed IPv6 prefix%s", VTY_NEWLINE
);
1852 table
= vrf_table (AFI_IP6
, SAFI_UNICAST
, 0);
1856 rn
= route_node_match (table
, (struct prefix
*) &p
);
1857 if (! rn
|| rn
->p
.prefixlen
!= p
.prefixlen
)
1859 vty_out (vty
, "%% Network not in table%s", VTY_NEWLINE
);
1863 vty_show_ipv6_route_detail (vty
, rn
);
1865 route_unlock_node (rn
);
1871 /* Write IPv6 static route configuration. */
1873 static_config_ipv6 (struct vty
*vty
)
1875 struct route_node
*rn
;
1876 struct static_ipv6
*si
;
1879 struct route_table
*stable
;
1884 stable
= vrf_static_table (AFI_IP6
, SAFI_UNICAST
, 0);
1888 for (rn
= route_top (stable
); rn
; rn
= route_next (rn
))
1889 for (si
= rn
->info
; si
; si
= si
->next
)
1891 vty_out (vty
, "ipv6 route %s/%d",
1892 inet_ntop (AF_INET6
, &rn
->p
.u
.prefix6
, buf
, BUFSIZ
),
1897 case STATIC_IPV6_GATEWAY
:
1898 vty_out (vty
, " %s", inet_ntop (AF_INET6
, &si
->ipv6
, buf
, BUFSIZ
));
1900 case STATIC_IPV6_IFNAME
:
1901 vty_out (vty
, " %s", si
->ifname
);
1903 case STATIC_IPV6_GATEWAY_IFNAME
:
1904 vty_out (vty
, " %s %s",
1905 inet_ntop (AF_INET6
, &si
->ipv6
, buf
, BUFSIZ
), si
->ifname
);
1909 if (CHECK_FLAG(si
->flags
, ZEBRA_FLAG_REJECT
))
1910 vty_out (vty
, " %s", "reject");
1912 if (CHECK_FLAG(si
->flags
, ZEBRA_FLAG_BLACKHOLE
))
1913 vty_out (vty
, " %s", "blackhole");
1915 if (si
->distance
!= ZEBRA_STATIC_DISTANCE_DEFAULT
)
1916 vty_out (vty
, " %d", si
->distance
);
1917 vty_out (vty
, "%s", VTY_NEWLINE
);
1923 #endif /* HAVE_IPV6 */
1925 /* Static ip route configuration write function. */
1927 zebra_ip_config (struct vty
*vty
)
1931 write
+= static_config_ipv4 (vty
);
1933 write
+= static_config_ipv6 (vty
);
1934 #endif /* HAVE_IPV6 */
1939 /* IP node for static routes. */
1940 struct cmd_node ip_node
= { IP_NODE
, "", 1 };
1944 zebra_vty_init (void)
1946 install_node (&ip_node
, zebra_ip_config
);
1948 install_element (CONFIG_NODE
, &ip_route_cmd
);
1949 install_element (CONFIG_NODE
, &ip_route_flags_cmd
);
1950 install_element (CONFIG_NODE
, &ip_route_flags2_cmd
);
1951 install_element (CONFIG_NODE
, &ip_route_mask_cmd
);
1952 install_element (CONFIG_NODE
, &ip_route_mask_flags_cmd
);
1953 install_element (CONFIG_NODE
, &ip_route_mask_flags2_cmd
);
1954 install_element (CONFIG_NODE
, &no_ip_route_cmd
);
1955 install_element (CONFIG_NODE
, &no_ip_route_flags_cmd
);
1956 install_element (CONFIG_NODE
, &no_ip_route_flags2_cmd
);
1957 install_element (CONFIG_NODE
, &no_ip_route_mask_cmd
);
1958 install_element (CONFIG_NODE
, &no_ip_route_mask_flags_cmd
);
1959 install_element (CONFIG_NODE
, &no_ip_route_mask_flags2_cmd
);
1960 install_element (CONFIG_NODE
, &ip_route_distance_cmd
);
1961 install_element (CONFIG_NODE
, &ip_route_flags_distance_cmd
);
1962 install_element (CONFIG_NODE
, &ip_route_flags_distance2_cmd
);
1963 install_element (CONFIG_NODE
, &ip_route_mask_distance_cmd
);
1964 install_element (CONFIG_NODE
, &ip_route_mask_flags_distance_cmd
);
1965 install_element (CONFIG_NODE
, &ip_route_mask_flags_distance2_cmd
);
1966 install_element (CONFIG_NODE
, &no_ip_route_distance_cmd
);
1967 install_element (CONFIG_NODE
, &no_ip_route_flags_distance_cmd
);
1968 install_element (CONFIG_NODE
, &no_ip_route_flags_distance2_cmd
);
1969 install_element (CONFIG_NODE
, &no_ip_route_mask_flags_distance_cmd
);
1970 install_element (CONFIG_NODE
, &no_ip_route_mask_flags_distance2_cmd
);
1972 install_element (VIEW_NODE
, &show_ip_route_cmd
);
1973 install_element (VIEW_NODE
, &show_ip_route_addr_cmd
);
1974 install_element (VIEW_NODE
, &show_ip_route_prefix_cmd
);
1975 install_element (VIEW_NODE
, &show_ip_route_prefix_longer_cmd
);
1976 install_element (VIEW_NODE
, &show_ip_route_protocol_cmd
);
1977 install_element (VIEW_NODE
, &show_ip_route_supernets_cmd
);
1978 install_element (ENABLE_NODE
, &show_ip_route_cmd
);
1979 install_element (ENABLE_NODE
, &show_ip_route_addr_cmd
);
1980 install_element (ENABLE_NODE
, &show_ip_route_prefix_cmd
);
1981 install_element (ENABLE_NODE
, &show_ip_route_prefix_longer_cmd
);
1982 install_element (ENABLE_NODE
, &show_ip_route_protocol_cmd
);
1983 install_element (ENABLE_NODE
, &show_ip_route_supernets_cmd
);
1986 install_element (VIEW_NODE
, &show_ip_route_summary_cmd
);
1987 install_element (ENABLE_NODE
, &show_ip_route_summary_cmd
);
1991 install_element (CONFIG_NODE
, &ipv6_route_cmd
);
1992 install_element (CONFIG_NODE
, &ipv6_route_flags_cmd
);
1993 install_element (CONFIG_NODE
, &ipv6_route_ifname_cmd
);
1994 install_element (CONFIG_NODE
, &ipv6_route_ifname_flags_cmd
);
1995 install_element (CONFIG_NODE
, &no_ipv6_route_cmd
);
1996 install_element (CONFIG_NODE
, &no_ipv6_route_flags_cmd
);
1997 install_element (CONFIG_NODE
, &no_ipv6_route_ifname_cmd
);
1998 install_element (CONFIG_NODE
, &no_ipv6_route_ifname_flags_cmd
);
1999 install_element (CONFIG_NODE
, &ipv6_route_pref_cmd
);
2000 install_element (CONFIG_NODE
, &ipv6_route_flags_pref_cmd
);
2001 install_element (CONFIG_NODE
, &ipv6_route_ifname_pref_cmd
);
2002 install_element (CONFIG_NODE
, &ipv6_route_ifname_flags_pref_cmd
);
2003 install_element (CONFIG_NODE
, &no_ipv6_route_pref_cmd
);
2004 install_element (CONFIG_NODE
, &no_ipv6_route_flags_pref_cmd
);
2005 install_element (CONFIG_NODE
, &no_ipv6_route_ifname_pref_cmd
);
2006 install_element (CONFIG_NODE
, &no_ipv6_route_ifname_flags_pref_cmd
);
2007 install_element (VIEW_NODE
, &show_ipv6_route_cmd
);
2008 install_element (VIEW_NODE
, &show_ipv6_route_protocol_cmd
);
2009 install_element (VIEW_NODE
, &show_ipv6_route_addr_cmd
);
2010 install_element (VIEW_NODE
, &show_ipv6_route_prefix_cmd
);
2011 install_element (VIEW_NODE
, &show_ipv6_route_prefix_longer_cmd
);
2012 install_element (ENABLE_NODE
, &show_ipv6_route_cmd
);
2013 install_element (ENABLE_NODE
, &show_ipv6_route_protocol_cmd
);
2014 install_element (ENABLE_NODE
, &show_ipv6_route_addr_cmd
);
2015 install_element (ENABLE_NODE
, &show_ipv6_route_prefix_cmd
);
2016 install_element (ENABLE_NODE
, &show_ipv6_route_prefix_longer_cmd
);
2017 #endif /* HAVE_IPV6 */