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 /* General fucntion for static route. */
34 zebra_static_ipv4 (struct vty
*vty
, int add_cmd
, const char *dest_str
,
35 const char *mask_str
, const char *gate_str
,
36 const char *flag_str
, const char *distance_str
)
46 ret
= str2prefix (dest_str
, &p
);
49 vty_out (vty
, "%% Malformed address%s", VTY_NEWLINE
);
53 /* Cisco like mask notation. */
56 ret
= inet_aton (mask_str
, &mask
);
59 vty_out (vty
, "%% Malformed address%s", VTY_NEWLINE
);
62 p
.prefixlen
= ip_masklen (mask
);
65 /* Apply mask for given prefix. */
68 /* Administrative distance. */
70 distance
= atoi (distance_str
);
72 distance
= ZEBRA_STATIC_DISTANCE_DEFAULT
;
74 /* Null0 static route. */
75 if ((gate_str
!= NULL
) && (strncasecmp (gate_str
, "Null0", strlen (gate_str
)) == 0))
79 vty_out (vty
, "%% can not have flag %s with Null0%s", flag_str
, VTY_NEWLINE
);
83 static_add_ipv4 (&p
, NULL
, NULL
, ZEBRA_FLAG_BLACKHOLE
, distance
, 0);
85 static_delete_ipv4 (&p
, NULL
, NULL
, distance
, 0);
94 SET_FLAG (flag
, ZEBRA_FLAG_REJECT
);
98 SET_FLAG (flag
, ZEBRA_FLAG_BLACKHOLE
);
101 vty_out (vty
, "%% Malformed flag %s %s", flag_str
, VTY_NEWLINE
);
106 if (gate_str
== NULL
)
109 static_add_ipv4 (&p
, NULL
, NULL
, flag
, distance
, 0);
111 static_delete_ipv4 (&p
, NULL
, NULL
, distance
, 0);
116 /* When gateway is A.B.C.D format, gate is treated as nexthop
117 address other case gate is treated as interface name. */
118 ret
= inet_aton (gate_str
, &gate
);
125 static_add_ipv4 (&p
, ifname
? NULL
: &gate
, ifname
, flag
, distance
, 0);
127 static_delete_ipv4 (&p
, ifname
? NULL
: &gate
, ifname
, distance
, 0);
132 /* Static route configuration. */
135 "ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0)",
137 "Establish static routes\n"
138 "IP destination prefix (e.g. 10.0.0.0/8)\n"
139 "IP gateway address\n"
140 "IP gateway interface name\n"
143 return zebra_static_ipv4 (vty
, 1, argv
[0], NULL
, argv
[1], NULL
, NULL
);
146 DEFUN (ip_route_flags
,
148 "ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole)",
150 "Establish static routes\n"
151 "IP destination prefix (e.g. 10.0.0.0/8)\n"
152 "IP gateway address\n"
153 "IP gateway interface name\n"
154 "Emit an ICMP unreachable when matched\n"
155 "Silently discard pkts when matched\n")
157 return zebra_static_ipv4 (vty
, 1, argv
[0], NULL
, argv
[1], argv
[2], NULL
);
160 DEFUN (ip_route_flags2
,
162 "ip route A.B.C.D/M (reject|blackhole)",
164 "Establish static routes\n"
165 "IP destination prefix (e.g. 10.0.0.0/8)\n"
166 "Emit an ICMP unreachable when matched\n"
167 "Silently discard pkts when matched\n")
169 return zebra_static_ipv4 (vty
, 1, argv
[0], NULL
, NULL
, argv
[1], NULL
);
172 /* Mask as A.B.C.D format. */
173 DEFUN (ip_route_mask
,
175 "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0)",
177 "Establish static routes\n"
178 "IP destination prefix\n"
179 "IP destination prefix mask\n"
180 "IP gateway address\n"
181 "IP gateway interface name\n"
184 return zebra_static_ipv4 (vty
, 1, argv
[0], argv
[1], argv
[2], NULL
, NULL
);
187 DEFUN (ip_route_mask_flags
,
188 ip_route_mask_flags_cmd
,
189 "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole)",
191 "Establish static routes\n"
192 "IP destination prefix\n"
193 "IP destination prefix mask\n"
194 "IP gateway address\n"
195 "IP gateway interface name\n"
196 "Emit an ICMP unreachable when matched\n"
197 "Silently discard pkts when matched\n")
199 return zebra_static_ipv4 (vty
, 1, argv
[0], argv
[1], argv
[2], argv
[3], NULL
);
202 DEFUN (ip_route_mask_flags2
,
203 ip_route_mask_flags2_cmd
,
204 "ip route A.B.C.D A.B.C.D (reject|blackhole)",
206 "Establish static routes\n"
207 "IP destination prefix\n"
208 "IP destination prefix mask\n"
209 "Emit an ICMP unreachable when matched\n"
210 "Silently discard pkts when matched\n")
212 return zebra_static_ipv4 (vty
, 1, argv
[0], argv
[1], NULL
, argv
[2], NULL
);
215 /* Distance option value. */
216 DEFUN (ip_route_distance
,
217 ip_route_distance_cmd
,
218 "ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0) <1-255>",
220 "Establish static routes\n"
221 "IP destination prefix (e.g. 10.0.0.0/8)\n"
222 "IP gateway address\n"
223 "IP gateway interface name\n"
225 "Distance value for this route\n")
227 return zebra_static_ipv4 (vty
, 1, argv
[0], NULL
, argv
[1], NULL
, argv
[2]);
230 DEFUN (ip_route_flags_distance
,
231 ip_route_flags_distance_cmd
,
232 "ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
234 "Establish static routes\n"
235 "IP destination prefix (e.g. 10.0.0.0/8)\n"
236 "IP gateway address\n"
237 "IP gateway interface name\n"
238 "Emit an ICMP unreachable when matched\n"
239 "Silently discard pkts when matched\n"
240 "Distance value for this route\n")
242 return zebra_static_ipv4 (vty
, 1, argv
[0], NULL
, argv
[1], argv
[2], argv
[3]);
245 DEFUN (ip_route_flags_distance2
,
246 ip_route_flags_distance2_cmd
,
247 "ip route A.B.C.D/M (reject|blackhole) <1-255>",
249 "Establish static routes\n"
250 "IP destination prefix (e.g. 10.0.0.0/8)\n"
251 "Emit an ICMP unreachable when matched\n"
252 "Silently discard pkts when matched\n"
253 "Distance value for this route\n")
255 return zebra_static_ipv4 (vty
, 1, argv
[0], NULL
, NULL
, argv
[1], argv
[2]);
258 DEFUN (ip_route_mask_distance
,
259 ip_route_mask_distance_cmd
,
260 "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0) <1-255>",
262 "Establish static routes\n"
263 "IP destination prefix\n"
264 "IP destination prefix mask\n"
265 "IP gateway address\n"
266 "IP gateway interface name\n"
268 "Distance value for this route\n")
270 return zebra_static_ipv4 (vty
, 1, argv
[0], argv
[1], argv
[2], NULL
, argv
[3]);
273 DEFUN (ip_route_mask_flags_distance
,
274 ip_route_mask_flags_distance_cmd
,
275 "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
277 "Establish static routes\n"
278 "IP destination prefix\n"
279 "IP destination prefix mask\n"
280 "IP gateway address\n"
281 "IP gateway interface name\n"
282 "Distance value for this route\n"
283 "Emit an ICMP unreachable when matched\n"
284 "Silently discard pkts when matched\n")
286 return zebra_static_ipv4 (vty
, 1, argv
[0], argv
[1], argv
[2], argv
[3], argv
[4]);
289 DEFUN (ip_route_mask_flags_distance2
,
290 ip_route_mask_flags_distance2_cmd
,
291 "ip route A.B.C.D A.B.C.D (reject|blackhole) <1-255>",
293 "Establish static routes\n"
294 "IP destination prefix\n"
295 "IP destination prefix mask\n"
296 "Distance value for this route\n"
297 "Emit an ICMP unreachable when matched\n"
298 "Silently discard pkts when matched\n")
300 return zebra_static_ipv4 (vty
, 1, argv
[0], argv
[1], NULL
, argv
[2], argv
[3]);
305 "no ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0)",
308 "Establish static routes\n"
309 "IP destination prefix (e.g. 10.0.0.0/8)\n"
310 "IP gateway address\n"
311 "IP gateway interface name\n"
314 return zebra_static_ipv4 (vty
, 0, argv
[0], NULL
, argv
[1], NULL
, NULL
);
318 no_ip_route_flags_cmd
,
319 "no ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole)",
322 "Establish static routes\n"
323 "IP destination prefix (e.g. 10.0.0.0/8)\n"
324 "IP gateway address\n"
325 "IP gateway interface name\n"
326 "Emit an ICMP unreachable when matched\n"
327 "Silently discard pkts when matched\n")
329 DEFUN (no_ip_route_flags2
,
330 no_ip_route_flags2_cmd
,
331 "no ip route A.B.C.D/M (reject|blackhole)",
334 "Establish static routes\n"
335 "IP destination prefix (e.g. 10.0.0.0/8)\n"
336 "Emit an ICMP unreachable when matched\n"
337 "Silently discard pkts when matched\n")
339 return zebra_static_ipv4 (vty
, 0, argv
[0], NULL
, NULL
, NULL
, NULL
);
342 DEFUN (no_ip_route_mask
,
343 no_ip_route_mask_cmd
,
344 "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0)",
347 "Establish static routes\n"
348 "IP destination prefix\n"
349 "IP destination prefix mask\n"
350 "IP gateway address\n"
351 "IP gateway interface name\n"
354 return zebra_static_ipv4 (vty
, 0, argv
[0], argv
[1], argv
[2], NULL
, NULL
);
357 ALIAS (no_ip_route_mask
,
358 no_ip_route_mask_flags_cmd
,
359 "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole)",
362 "Establish static routes\n"
363 "IP destination prefix\n"
364 "IP destination prefix mask\n"
365 "IP gateway address\n"
366 "IP gateway interface name\n"
367 "Emit an ICMP unreachable when matched\n"
368 "Silently discard pkts when matched\n")
370 DEFUN (no_ip_route_mask_flags2
,
371 no_ip_route_mask_flags2_cmd
,
372 "no ip route A.B.C.D A.B.C.D (reject|blackhole)",
375 "Establish static routes\n"
376 "IP destination prefix\n"
377 "IP destination prefix mask\n"
378 "Emit an ICMP unreachable when matched\n"
379 "Silently discard pkts when matched\n")
381 return zebra_static_ipv4 (vty
, 0, argv
[0], argv
[1], NULL
, NULL
, NULL
);
384 DEFUN (no_ip_route_distance
,
385 no_ip_route_distance_cmd
,
386 "no ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0) <1-255>",
389 "Establish static routes\n"
390 "IP destination prefix (e.g. 10.0.0.0/8)\n"
391 "IP gateway address\n"
392 "IP gateway interface name\n"
394 "Distance value for this route\n")
396 return zebra_static_ipv4 (vty
, 0, argv
[0], NULL
, argv
[1], NULL
, argv
[2]);
399 DEFUN (no_ip_route_flags_distance
,
400 no_ip_route_flags_distance_cmd
,
401 "no ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
404 "Establish static routes\n"
405 "IP destination prefix (e.g. 10.0.0.0/8)\n"
406 "IP gateway address\n"
407 "IP gateway interface name\n"
408 "Emit an ICMP unreachable when matched\n"
409 "Silently discard pkts when matched\n"
410 "Distance value for this route\n")
412 return zebra_static_ipv4 (vty
, 0, argv
[0], NULL
, argv
[1], argv
[2], argv
[3]);
415 DEFUN (no_ip_route_flags_distance2
,
416 no_ip_route_flags_distance2_cmd
,
417 "no ip route A.B.C.D/M (reject|blackhole) <1-255>",
420 "Establish static routes\n"
421 "IP destination prefix (e.g. 10.0.0.0/8)\n"
422 "Emit an ICMP unreachable when matched\n"
423 "Silently discard pkts when matched\n"
424 "Distance value for this route\n")
426 return zebra_static_ipv4 (vty
, 0, argv
[0], NULL
, NULL
, argv
[1], argv
[2]);
429 DEFUN (no_ip_route_mask_distance
,
430 no_ip_route_mask_distance_cmd
,
431 "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0) <1-255>",
434 "Establish static routes\n"
435 "IP destination prefix\n"
436 "IP destination prefix mask\n"
437 "IP gateway address\n"
438 "IP gateway interface name\n"
440 "Distance value for this route\n")
442 return zebra_static_ipv4 (vty
, 0, argv
[0], argv
[1], argv
[2], NULL
, argv
[3]);
445 DEFUN (no_ip_route_mask_flags_distance
,
446 no_ip_route_mask_flags_distance_cmd
,
447 "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
450 "Establish static routes\n"
451 "IP destination prefix\n"
452 "IP destination prefix mask\n"
453 "IP gateway address\n"
454 "IP gateway interface name\n"
455 "Emit an ICMP unreachable when matched\n"
456 "Silently discard pkts when matched\n"
457 "Distance value for this route\n")
459 return zebra_static_ipv4 (vty
, 0, argv
[0], argv
[1], argv
[2], argv
[3], argv
[4]);
462 DEFUN (no_ip_route_mask_flags_distance2
,
463 no_ip_route_mask_flags_distance2_cmd
,
464 "no ip route A.B.C.D A.B.C.D (reject|blackhole) <1-255>",
467 "Establish static routes\n"
468 "IP destination prefix\n"
469 "IP destination prefix mask\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], argv
[1], NULL
, argv
[2], argv
[3]);
477 /* New RIB. Detailed information for IPv4 route. */
479 vty_show_ip_route_detail (struct vty
*vty
, struct route_node
*rn
)
482 struct nexthop
*nexthop
;
484 for (rib
= rn
->info
; rib
; rib
= rib
->next
)
486 vty_out (vty
, "Routing entry for %s/%d%s",
487 inet_ntoa (rn
->p
.u
.prefix4
), rn
->p
.prefixlen
,
489 vty_out (vty
, " Known via \"%s\"", zebra_route_string (rib
->type
));
490 vty_out (vty
, ", distance %d, metric %d", rib
->distance
, rib
->metric
);
491 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_SELECTED
))
492 vty_out (vty
, ", best");
494 vty_out (vty
, ", refcnt %ld", rib
->refcnt
);
495 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_BLACKHOLE
))
496 vty_out (vty
, ", blackhole");
497 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_REJECT
))
498 vty_out (vty
, ", reject");
499 vty_out (vty
, "%s", VTY_NEWLINE
);
501 #define ONE_DAY_SECOND 60*60*24
502 #define ONE_WEEK_SECOND 60*60*24*7
503 if (rib
->type
== ZEBRA_ROUTE_RIP
504 || rib
->type
== ZEBRA_ROUTE_OSPF
505 || rib
->type
== ZEBRA_ROUTE_ISIS
506 || rib
->type
== ZEBRA_ROUTE_BGP
)
511 uptime
= time (NULL
);
512 uptime
-= rib
->uptime
;
513 tm
= gmtime (&uptime
);
515 vty_out (vty
, " Last update ");
517 if (uptime
< ONE_DAY_SECOND
)
518 vty_out (vty
, "%02d:%02d:%02d",
519 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
520 else if (uptime
< ONE_WEEK_SECOND
)
521 vty_out (vty
, "%dd%02dh%02dm",
522 tm
->tm_yday
, tm
->tm_hour
, tm
->tm_min
);
524 vty_out (vty
, "%02dw%dd%02dh",
526 tm
->tm_yday
- ((tm
->tm_yday
/7) * 7), tm
->tm_hour
);
527 vty_out (vty
, " ago%s", VTY_NEWLINE
);
530 for (nexthop
= rib
->nexthop
; nexthop
; nexthop
= nexthop
->next
)
533 CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
) ? '*' : ' ');
535 switch (nexthop
->type
)
537 case NEXTHOP_TYPE_IPV4
:
538 case NEXTHOP_TYPE_IPV4_IFINDEX
:
539 vty_out (vty
, " %s", inet_ntoa (nexthop
->gate
.ipv4
));
540 if (nexthop
->ifindex
)
541 vty_out (vty
, ", via %s", ifindex2ifname (nexthop
->ifindex
));
543 case NEXTHOP_TYPE_IFINDEX
:
544 vty_out (vty
, " directly connected, %s",
545 ifindex2ifname (nexthop
->ifindex
));
547 case NEXTHOP_TYPE_IFNAME
:
548 vty_out (vty
, " directly connected, %s", nexthop
->ifname
);
550 case NEXTHOP_TYPE_BLACKHOLE
:
551 vty_out (vty
, " directly connected, Null0");
556 if (! CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
))
557 vty_out (vty
, " inactive");
559 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_RECURSIVE
))
561 vty_out (vty
, " (recursive");
563 switch (nexthop
->rtype
)
565 case NEXTHOP_TYPE_IPV4
:
566 case NEXTHOP_TYPE_IPV4_IFINDEX
:
567 vty_out (vty
, " via %s)", inet_ntoa (nexthop
->rgate
.ipv4
));
569 case NEXTHOP_TYPE_IFINDEX
:
570 case NEXTHOP_TYPE_IFNAME
:
571 vty_out (vty
, " is directly connected, %s)",
572 ifindex2ifname (nexthop
->rifindex
));
578 vty_out (vty
, "%s", VTY_NEWLINE
);
580 vty_out (vty
, "%s", VTY_NEWLINE
);
585 vty_show_ip_route (struct vty
*vty
, struct route_node
*rn
, struct rib
*rib
)
587 struct nexthop
*nexthop
;
591 /* Nexthop information. */
592 for (nexthop
= rib
->nexthop
; nexthop
; nexthop
= nexthop
->next
)
594 if (nexthop
== rib
->nexthop
)
596 /* Prefix information. */
597 len
= vty_out (vty
, "%c%c%c %s/%d",
598 zebra_route_char (rib
->type
),
599 CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_SELECTED
)
601 CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
)
603 inet_ntop (AF_INET
, &rn
->p
.u
.prefix
, buf
, BUFSIZ
),
606 /* Distance and metric display. */
607 if (rib
->type
!= ZEBRA_ROUTE_CONNECT
608 && rib
->type
!= ZEBRA_ROUTE_KERNEL
)
609 len
+= vty_out (vty
, " [%d/%d]", rib
->distance
,
613 vty_out (vty
, " %c%*c",
614 CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
)
618 switch (nexthop
->type
)
620 case NEXTHOP_TYPE_IPV4
:
621 case NEXTHOP_TYPE_IPV4_IFINDEX
:
622 vty_out (vty
, " via %s", inet_ntoa (nexthop
->gate
.ipv4
));
623 if (nexthop
->ifindex
)
624 vty_out (vty
, ", %s", ifindex2ifname (nexthop
->ifindex
));
626 case NEXTHOP_TYPE_IFINDEX
:
627 vty_out (vty
, " is directly connected, %s",
628 ifindex2ifname (nexthop
->ifindex
));
630 case NEXTHOP_TYPE_IFNAME
:
631 vty_out (vty
, " is directly connected, %s", nexthop
->ifname
);
633 case NEXTHOP_TYPE_BLACKHOLE
:
634 vty_out (vty
, " is directly connected, Null0");
639 if (! CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
))
640 vty_out (vty
, " inactive");
642 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_RECURSIVE
))
644 vty_out (vty
, " (recursive");
646 switch (nexthop
->rtype
)
648 case NEXTHOP_TYPE_IPV4
:
649 case NEXTHOP_TYPE_IPV4_IFINDEX
:
650 vty_out (vty
, " via %s)", inet_ntoa (nexthop
->rgate
.ipv4
));
652 case NEXTHOP_TYPE_IFINDEX
:
653 case NEXTHOP_TYPE_IFNAME
:
654 vty_out (vty
, " is directly connected, %s)",
655 ifindex2ifname (nexthop
->rifindex
));
662 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_BLACKHOLE
))
663 vty_out (vty
, ", bh");
664 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_REJECT
))
665 vty_out (vty
, ", rej");
667 if (rib
->type
== ZEBRA_ROUTE_RIP
668 || rib
->type
== ZEBRA_ROUTE_OSPF
669 || rib
->type
== ZEBRA_ROUTE_ISIS
670 || rib
->type
== ZEBRA_ROUTE_BGP
)
675 uptime
= time (NULL
);
676 uptime
-= rib
->uptime
;
677 tm
= gmtime (&uptime
);
679 #define ONE_DAY_SECOND 60*60*24
680 #define ONE_WEEK_SECOND 60*60*24*7
682 if (uptime
< ONE_DAY_SECOND
)
683 vty_out (vty
, ", %02d:%02d:%02d",
684 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
685 else if (uptime
< ONE_WEEK_SECOND
)
686 vty_out (vty
, ", %dd%02dh%02dm",
687 tm
->tm_yday
, tm
->tm_hour
, tm
->tm_min
);
689 vty_out (vty
, ", %02dw%dd%02dh",
691 tm
->tm_yday
- ((tm
->tm_yday
/7) * 7), tm
->tm_hour
);
693 vty_out (vty
, "%s", VTY_NEWLINE
);
697 #define SHOW_ROUTE_V4_HEADER "Codes: K - kernel route, C - connected, " \
698 "S - static, R - RIP, O - OSPF,%s I - ISIS, B - BGP, " \
699 "> - selected route, * - FIB route%s%s"
701 DEFUN (show_ip_route
,
706 "IP routing table\n")
708 struct route_table
*table
;
709 struct route_node
*rn
;
713 table
= vrf_table (AFI_IP
, SAFI_UNICAST
, 0);
717 /* Show all IPv4 routes. */
718 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
719 for (rib
= rn
->info
; rib
; rib
= rib
->next
)
723 vty_out (vty
, SHOW_ROUTE_V4_HEADER
, VTY_NEWLINE
, VTY_NEWLINE
,
727 vty_show_ip_route (vty
, rn
, rib
);
732 DEFUN (show_ip_route_prefix_longer
,
733 show_ip_route_prefix_longer_cmd
,
734 "show ip route A.B.C.D/M longer-prefixes",
738 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
739 "Show route matching the specified Network/Mask pair only\n")
741 struct route_table
*table
;
742 struct route_node
*rn
;
748 ret
= str2prefix (argv
[0], &p
);
751 vty_out (vty
, "%% Malformed Prefix%s", VTY_NEWLINE
);
755 table
= vrf_table (AFI_IP
, SAFI_UNICAST
, 0);
759 /* Show matched type IPv4 routes. */
760 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
761 for (rib
= rn
->info
; rib
; rib
= rib
->next
)
762 if (prefix_match (&p
, &rn
->p
))
766 vty_out (vty
, SHOW_ROUTE_V4_HEADER
, VTY_NEWLINE
,
767 VTY_NEWLINE
, VTY_NEWLINE
);
770 vty_show_ip_route (vty
, rn
, rib
);
775 DEFUN (show_ip_route_supernets
,
776 show_ip_route_supernets_cmd
,
777 "show ip route supernets-only",
781 "Show supernet entries only\n")
783 struct route_table
*table
;
784 struct route_node
*rn
;
789 table
= vrf_table (AFI_IP
, SAFI_UNICAST
, 0);
793 /* Show matched type IPv4 routes. */
794 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
795 for (rib
= rn
->info
; rib
; rib
= rib
->next
)
797 addr
= ntohl (rn
->p
.u
.prefix4
.s_addr
);
799 if ((IN_CLASSC (addr
) && rn
->p
.prefixlen
< 24)
800 || (IN_CLASSB (addr
) && rn
->p
.prefixlen
< 16)
801 || (IN_CLASSA (addr
) && rn
->p
.prefixlen
< 8))
805 vty_out (vty
, SHOW_ROUTE_V4_HEADER
, VTY_NEWLINE
,
806 VTY_NEWLINE
, VTY_NEWLINE
);
809 vty_show_ip_route (vty
, rn
, rib
);
815 DEFUN (show_ip_route_protocol
,
816 show_ip_route_protocol_cmd
,
817 "show ip route (bgp|connected|isis|kernel|ospf|rip|static)",
821 "Border Gateway Protocol (BGP)\n"
825 "Open Shortest Path First (OSPF)\n"
826 "Routing Information Protocol (RIP)\n"
830 struct route_table
*table
;
831 struct route_node
*rn
;
835 if (strncmp (argv
[0], "b", 1) == 0)
836 type
= ZEBRA_ROUTE_BGP
;
837 else if (strncmp (argv
[0], "c", 1) == 0)
838 type
= ZEBRA_ROUTE_CONNECT
;
839 else if (strncmp (argv
[0], "k", 1) ==0)
840 type
= ZEBRA_ROUTE_KERNEL
;
841 else if (strncmp (argv
[0], "o", 1) == 0)
842 type
= ZEBRA_ROUTE_OSPF
;
843 else if (strncmp (argv
[0], "i", 1) == 0)
844 type
= ZEBRA_ROUTE_ISIS
;
845 else if (strncmp (argv
[0], "r", 1) == 0)
846 type
= ZEBRA_ROUTE_RIP
;
847 else if (strncmp (argv
[0], "s", 1) == 0)
848 type
= ZEBRA_ROUTE_STATIC
;
851 vty_out (vty
, "Unknown route type%s", VTY_NEWLINE
);
855 table
= vrf_table (AFI_IP
, SAFI_UNICAST
, 0);
859 /* Show matched type IPv4 routes. */
860 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
861 for (rib
= rn
->info
; rib
; rib
= rib
->next
)
862 if (rib
->type
== type
)
866 vty_out (vty
, SHOW_ROUTE_V4_HEADER
,
867 VTY_NEWLINE
, VTY_NEWLINE
, VTY_NEWLINE
);
870 vty_show_ip_route (vty
, rn
, rib
);
875 DEFUN (show_ip_route_addr
,
876 show_ip_route_addr_cmd
,
877 "show ip route A.B.C.D",
881 "Network in the IP routing table to display\n")
884 struct prefix_ipv4 p
;
885 struct route_table
*table
;
886 struct route_node
*rn
;
888 ret
= str2prefix_ipv4 (argv
[0], &p
);
891 vty_out (vty
, "%% Malformed IPv4 address%s", VTY_NEWLINE
);
895 table
= vrf_table (AFI_IP
, SAFI_UNICAST
, 0);
899 rn
= route_node_match (table
, (struct prefix
*) &p
);
902 vty_out (vty
, "%% Network not in table%s", VTY_NEWLINE
);
906 vty_show_ip_route_detail (vty
, rn
);
908 route_unlock_node (rn
);
913 DEFUN (show_ip_route_prefix
,
914 show_ip_route_prefix_cmd
,
915 "show ip route A.B.C.D/M",
919 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
922 struct prefix_ipv4 p
;
923 struct route_table
*table
;
924 struct route_node
*rn
;
926 ret
= str2prefix_ipv4 (argv
[0], &p
);
929 vty_out (vty
, "%% Malformed IPv4 address%s", VTY_NEWLINE
);
933 table
= vrf_table (AFI_IP
, SAFI_UNICAST
, 0);
937 rn
= route_node_match (table
, (struct prefix
*) &p
);
938 if (! rn
|| rn
->p
.prefixlen
!= p
.prefixlen
)
940 vty_out (vty
, "%% Network not in table%s", VTY_NEWLINE
);
944 vty_show_ip_route_detail (vty
, rn
);
946 route_unlock_node (rn
);
952 zebra_show_ip_route (struct vty
*vty
, struct vrf
*vrf
)
954 vty_out (vty
, "IP routing table name is %s(%d)%s",
955 vrf
->name
? vrf
->name
: "", vrf
->id
, VTY_NEWLINE
);
957 vty_out (vty
, "Route Source Networks%s", VTY_NEWLINE
);
958 vty_out (vty
, "connected %d%s", 0, VTY_NEWLINE
);
959 vty_out (vty
, "static %d%s", 0, VTY_NEWLINE
);
960 vty_out (vty
, "rip %d%s", 0, VTY_NEWLINE
);
962 vty_out (vty
, "bgp %d%s", 0, VTY_NEWLINE
);
963 vty_out (vty
, " External: %d Internal: %d Local: %d%s",
964 0, 0, 0, VTY_NEWLINE
);
966 vty_out (vty
, "ospf %d%s", 0, VTY_NEWLINE
);
968 " Intra-area: %d Inter-area: %d External-1: %d External-2: %d%s",
969 0, 0, 0, 0, VTY_NEWLINE
);
970 vty_out (vty
, " NSSA External-1: %d NSSA External-2: %d%s",
973 vty_out (vty
, "internal %d%s", 0, VTY_NEWLINE
);
974 vty_out (vty
, "Total %d%s", 0, VTY_NEWLINE
);
977 /* Show route summary. */
978 DEFUN (show_ip_route_summary
,
979 show_ip_route_summary_cmd
,
980 "show ip route summary",
984 "Summary of all routes\n")
988 /* Default table id is zero. */
989 vrf
= vrf_lookup (0);
992 vty_out (vty
, "%% No Default-IP-Routing-Table%s", VTY_NEWLINE
);
996 zebra_show_ip_route (vty
, vrf
);
1001 /* Write IPv4 static route configuration. */
1003 static_config_ipv4 (struct vty
*vty
)
1005 struct route_node
*rn
;
1006 struct static_ipv4
*si
;
1007 struct route_table
*stable
;
1013 stable
= vrf_static_table (AFI_IP
, SAFI_UNICAST
, 0);
1017 for (rn
= route_top (stable
); rn
; rn
= route_next (rn
))
1018 for (si
= rn
->info
; si
; si
= si
->next
)
1020 vty_out (vty
, "ip route %s/%d", inet_ntoa (rn
->p
.u
.prefix4
),
1025 case STATIC_IPV4_GATEWAY
:
1026 vty_out (vty
, " %s", inet_ntoa (si
->gate
.ipv4
));
1028 case STATIC_IPV4_IFNAME
:
1029 vty_out (vty
, " %s", si
->gate
.ifname
);
1031 case STATIC_IPV4_BLACKHOLE
:
1032 vty_out (vty
, " Null0");
1036 /* flags are incompatible with STATIC_IPV4_BLACKHOLE */
1037 if (si
->type
!= STATIC_IPV4_BLACKHOLE
)
1039 if (CHECK_FLAG(si
->flags
, ZEBRA_FLAG_REJECT
))
1040 vty_out (vty
, " %s", "reject");
1042 if (CHECK_FLAG(si
->flags
, ZEBRA_FLAG_BLACKHOLE
))
1043 vty_out (vty
, " %s", "blackhole");
1046 if (si
->distance
!= ZEBRA_STATIC_DISTANCE_DEFAULT
)
1047 vty_out (vty
, " %d", si
->distance
);
1049 vty_out (vty
, "%s", VTY_NEWLINE
);
1057 /* General fucntion for IPv6 static route. */
1059 static_ipv6_func (struct vty
*vty
, int add_cmd
, const char *dest_str
,
1060 const char *gate_str
, const char *ifname
,
1061 const char *flag_str
, const char *distance_str
)
1066 struct in6_addr
*gate
= NULL
;
1067 struct in6_addr gate_addr
;
1072 ret
= str2prefix (dest_str
, &p
);
1075 vty_out (vty
, "%% Malformed address%s", VTY_NEWLINE
);
1079 /* Apply mask for given prefix. */
1084 switch(flag_str
[0]) {
1087 SET_FLAG (flag
, ZEBRA_FLAG_REJECT
);
1091 SET_FLAG (flag
, ZEBRA_FLAG_BLACKHOLE
);
1094 vty_out (vty
, "%% Malformed flag %s %s", flag_str
, VTY_NEWLINE
);
1099 /* Administrative distance. */
1101 distance
= atoi (distance_str
);
1103 distance
= ZEBRA_STATIC_DISTANCE_DEFAULT
;
1105 /* When gateway is valid IPv6 addrees, then gate is treated as
1106 nexthop address other case gate is treated as interface name. */
1107 ret
= inet_pton (AF_INET6
, gate_str
, &gate_addr
);
1111 /* When ifname is specified. It must be come with gateway
1115 vty_out (vty
, "%% Malformed address%s", VTY_NEWLINE
);
1118 type
= STATIC_IPV6_GATEWAY_IFNAME
;
1125 type
= STATIC_IPV6_GATEWAY
;
1130 type
= STATIC_IPV6_IFNAME
;
1136 static_add_ipv6 (&p
, type
, gate
, ifname
, flag
, distance
, table
);
1138 static_delete_ipv6 (&p
, type
, gate
, ifname
, distance
, table
);
1145 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE)",
1147 "Establish static routes\n"
1148 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1149 "IPv6 gateway address\n"
1150 "IPv6 gateway interface name\n")
1152 return static_ipv6_func (vty
, 1, argv
[0], argv
[1], NULL
, NULL
, NULL
);
1155 DEFUN (ipv6_route_flags
,
1156 ipv6_route_flags_cmd
,
1157 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole)",
1159 "Establish static routes\n"
1160 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1161 "IPv6 gateway address\n"
1162 "IPv6 gateway interface name\n"
1163 "Emit an ICMP unreachable when matched\n"
1164 "Silently discard pkts when matched\n")
1166 return static_ipv6_func (vty
, 1, argv
[0], argv
[1], NULL
, argv
[2], NULL
);
1169 DEFUN (ipv6_route_ifname
,
1170 ipv6_route_ifname_cmd
,
1171 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE",
1173 "Establish static routes\n"
1174 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1175 "IPv6 gateway address\n"
1176 "IPv6 gateway interface name\n")
1178 return static_ipv6_func (vty
, 1, argv
[0], argv
[1], argv
[2], NULL
, NULL
);
1181 DEFUN (ipv6_route_ifname_flags
,
1182 ipv6_route_ifname_flags_cmd
,
1183 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole)",
1185 "Establish static routes\n"
1186 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1187 "IPv6 gateway address\n"
1188 "IPv6 gateway interface name\n"
1189 "Emit an ICMP unreachable when matched\n"
1190 "Silently discard pkts when matched\n")
1192 return static_ipv6_func (vty
, 1, argv
[0], argv
[1], argv
[2], argv
[3], NULL
);
1195 DEFUN (ipv6_route_pref
,
1196 ipv6_route_pref_cmd
,
1197 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <1-255>",
1199 "Establish static routes\n"
1200 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1201 "IPv6 gateway address\n"
1202 "IPv6 gateway interface name\n"
1203 "Distance value for this prefix\n")
1205 return static_ipv6_func (vty
, 1, argv
[0], argv
[1], NULL
, NULL
, argv
[2]);
1208 DEFUN (ipv6_route_flags_pref
,
1209 ipv6_route_flags_pref_cmd
,
1210 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) <1-255>",
1212 "Establish static routes\n"
1213 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1214 "IPv6 gateway address\n"
1215 "IPv6 gateway interface name\n"
1216 "Emit an ICMP unreachable when matched\n"
1217 "Silently discard pkts when matched\n"
1218 "Distance value for this prefix\n")
1220 return static_ipv6_func (vty
, 1, argv
[0], argv
[1], NULL
, argv
[2], argv
[3]);
1223 DEFUN (ipv6_route_ifname_pref
,
1224 ipv6_route_ifname_pref_cmd
,
1225 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255>",
1227 "Establish static routes\n"
1228 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1229 "IPv6 gateway address\n"
1230 "IPv6 gateway interface name\n"
1231 "Distance value for this prefix\n")
1233 return static_ipv6_func (vty
, 1, argv
[0], argv
[1], argv
[2], NULL
, argv
[3]);
1236 DEFUN (ipv6_route_ifname_flags_pref
,
1237 ipv6_route_ifname_flags_pref_cmd
,
1238 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) <1-255>",
1240 "Establish static routes\n"
1241 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1242 "IPv6 gateway address\n"
1243 "IPv6 gateway interface name\n"
1244 "Emit an ICMP unreachable when matched\n"
1245 "Silently discard pkts when matched\n"
1246 "Distance value for this prefix\n")
1248 return static_ipv6_func (vty
, 1, argv
[0], argv
[1], argv
[2], argv
[3], argv
[4]);
1251 DEFUN (no_ipv6_route
,
1253 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE)",
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")
1261 return static_ipv6_func (vty
, 0, argv
[0], argv
[1], NULL
, NULL
, NULL
);
1264 ALIAS (no_ipv6_route
,
1265 no_ipv6_route_flags_cmd
,
1266 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole)",
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")
1276 DEFUN (no_ipv6_route_ifname
,
1277 no_ipv6_route_ifname_cmd
,
1278 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE",
1281 "Establish static routes\n"
1282 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1283 "IPv6 gateway address\n"
1284 "IPv6 gateway interface name\n")
1286 return static_ipv6_func (vty
, 0, argv
[0], argv
[1], argv
[2], NULL
, NULL
);
1289 ALIAS (no_ipv6_route_ifname
,
1290 no_ipv6_route_ifname_flags_cmd
,
1291 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole)",
1294 "Establish static routes\n"
1295 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1296 "IPv6 gateway address\n"
1297 "IPv6 gateway interface name\n"
1298 "Emit an ICMP unreachable when matched\n"
1299 "Silently discard pkts when matched\n")
1301 DEFUN (no_ipv6_route_pref
,
1302 no_ipv6_route_pref_cmd
,
1303 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <1-255>",
1306 "Establish static routes\n"
1307 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1308 "IPv6 gateway address\n"
1309 "IPv6 gateway interface name\n"
1310 "Distance value for this prefix\n")
1312 return static_ipv6_func (vty
, 0, argv
[0], argv
[1], NULL
, NULL
, argv
[2]);
1315 DEFUN (no_ipv6_route_flags_pref
,
1316 no_ipv6_route_flags_pref_cmd
,
1317 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) <1-255>",
1320 "Establish static routes\n"
1321 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1322 "IPv6 gateway address\n"
1323 "IPv6 gateway interface name\n"
1324 "Emit an ICMP unreachable when matched\n"
1325 "Silently discard pkts when matched\n"
1326 "Distance value for this prefix\n")
1328 /* We do not care about argv[2] */
1329 return static_ipv6_func (vty
, 0, argv
[0], argv
[1], NULL
, argv
[2], argv
[3]);
1332 DEFUN (no_ipv6_route_ifname_pref
,
1333 no_ipv6_route_ifname_pref_cmd
,
1334 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255>",
1337 "Establish static routes\n"
1338 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1339 "IPv6 gateway address\n"
1340 "IPv6 gateway interface name\n"
1341 "Distance value for this prefix\n")
1343 return static_ipv6_func (vty
, 0, argv
[0], argv
[1], argv
[2], NULL
, argv
[3]);
1346 DEFUN (no_ipv6_route_ifname_flags_pref
,
1347 no_ipv6_route_ifname_flags_pref_cmd
,
1348 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) <1-255>",
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"
1357 "Distance value for this prefix\n")
1359 return static_ipv6_func (vty
, 0, argv
[0], argv
[1], argv
[2], argv
[3], argv
[4]);
1362 /* New RIB. Detailed information for IPv6 route. */
1364 vty_show_ipv6_route_detail (struct vty
*vty
, struct route_node
*rn
)
1367 struct nexthop
*nexthop
;
1370 for (rib
= rn
->info
; rib
; rib
= rib
->next
)
1372 vty_out (vty
, "Routing entry for %s/%d%s",
1373 inet_ntop (AF_INET6
, &rn
->p
.u
.prefix6
, buf
, BUFSIZ
),
1376 vty_out (vty
, " Known via \"%s\"", zebra_route_string (rib
->type
));
1377 vty_out (vty
, ", distance %d, metric %d", rib
->distance
, rib
->metric
);
1378 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_SELECTED
))
1379 vty_out (vty
, ", best");
1381 vty_out (vty
, ", refcnt %ld", rib
->refcnt
);
1382 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_BLACKHOLE
))
1383 vty_out (vty
, ", blackhole");
1384 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_REJECT
))
1385 vty_out (vty
, ", reject");
1386 vty_out (vty
, "%s", VTY_NEWLINE
);
1388 #define ONE_DAY_SECOND 60*60*24
1389 #define ONE_WEEK_SECOND 60*60*24*7
1390 if (rib
->type
== ZEBRA_ROUTE_RIPNG
1391 || rib
->type
== ZEBRA_ROUTE_OSPF6
1392 || rib
->type
== ZEBRA_ROUTE_ISIS
1393 || rib
->type
== ZEBRA_ROUTE_BGP
)
1398 uptime
= time (NULL
);
1399 uptime
-= rib
->uptime
;
1400 tm
= gmtime (&uptime
);
1402 vty_out (vty
, " Last update ");
1404 if (uptime
< ONE_DAY_SECOND
)
1405 vty_out (vty
, "%02d:%02d:%02d",
1406 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
1407 else if (uptime
< ONE_WEEK_SECOND
)
1408 vty_out (vty
, "%dd%02dh%02dm",
1409 tm
->tm_yday
, tm
->tm_hour
, tm
->tm_min
);
1411 vty_out (vty
, "%02dw%dd%02dh",
1413 tm
->tm_yday
- ((tm
->tm_yday
/7) * 7), tm
->tm_hour
);
1414 vty_out (vty
, " ago%s", VTY_NEWLINE
);
1417 for (nexthop
= rib
->nexthop
; nexthop
; nexthop
= nexthop
->next
)
1419 vty_out (vty
, " %c",
1420 CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
) ? '*' : ' ');
1422 switch (nexthop
->type
)
1424 case NEXTHOP_TYPE_IPV6
:
1425 case NEXTHOP_TYPE_IPV6_IFINDEX
:
1426 case NEXTHOP_TYPE_IPV6_IFNAME
:
1427 vty_out (vty
, " %s",
1428 inet_ntop (AF_INET6
, &nexthop
->gate
.ipv6
, buf
, BUFSIZ
));
1429 if (nexthop
->type
== NEXTHOP_TYPE_IPV6_IFNAME
)
1430 vty_out (vty
, ", %s", nexthop
->ifname
);
1431 else if (nexthop
->ifindex
)
1432 vty_out (vty
, ", via %s", ifindex2ifname (nexthop
->ifindex
));
1434 case NEXTHOP_TYPE_IFINDEX
:
1435 vty_out (vty
, " directly connected, %s",
1436 ifindex2ifname (nexthop
->ifindex
));
1438 case NEXTHOP_TYPE_IFNAME
:
1439 vty_out (vty
, " directly connected, %s",
1445 if (! CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
))
1446 vty_out (vty
, " inactive");
1448 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_RECURSIVE
))
1450 vty_out (vty
, " (recursive");
1452 switch (nexthop
->rtype
)
1454 case NEXTHOP_TYPE_IPV6
:
1455 case NEXTHOP_TYPE_IPV6_IFINDEX
:
1456 case NEXTHOP_TYPE_IPV6_IFNAME
:
1457 vty_out (vty
, " via %s)",
1458 inet_ntop (AF_INET6
, &nexthop
->rgate
.ipv6
,
1460 if (nexthop
->rifindex
)
1461 vty_out (vty
, ", %s", ifindex2ifname (nexthop
->rifindex
));
1463 case NEXTHOP_TYPE_IFINDEX
:
1464 case NEXTHOP_TYPE_IFNAME
:
1465 vty_out (vty
, " is directly connected, %s)",
1466 ifindex2ifname (nexthop
->rifindex
));
1472 vty_out (vty
, "%s", VTY_NEWLINE
);
1474 vty_out (vty
, "%s", VTY_NEWLINE
);
1479 vty_show_ipv6_route (struct vty
*vty
, struct route_node
*rn
,
1482 struct nexthop
*nexthop
;
1486 /* Nexthop information. */
1487 for (nexthop
= rib
->nexthop
; nexthop
; nexthop
= nexthop
->next
)
1489 if (nexthop
== rib
->nexthop
)
1491 /* Prefix information. */
1492 len
= vty_out (vty
, "%c%c%c %s/%d",
1493 zebra_route_char (rib
->type
),
1494 CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_SELECTED
)
1496 CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
)
1498 inet_ntop (AF_INET6
, &rn
->p
.u
.prefix6
, buf
, BUFSIZ
),
1501 /* Distance and metric display. */
1502 if (rib
->type
!= ZEBRA_ROUTE_CONNECT
1503 && rib
->type
!= ZEBRA_ROUTE_KERNEL
)
1504 len
+= vty_out (vty
, " [%d/%d]", rib
->distance
,
1508 vty_out (vty
, " %c%*c",
1509 CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
)
1513 switch (nexthop
->type
)
1515 case NEXTHOP_TYPE_IPV6
:
1516 case NEXTHOP_TYPE_IPV6_IFINDEX
:
1517 case NEXTHOP_TYPE_IPV6_IFNAME
:
1518 vty_out (vty
, " via %s",
1519 inet_ntop (AF_INET6
, &nexthop
->gate
.ipv6
, buf
, BUFSIZ
));
1520 if (nexthop
->type
== NEXTHOP_TYPE_IPV6_IFNAME
)
1521 vty_out (vty
, ", %s", nexthop
->ifname
);
1522 else if (nexthop
->ifindex
)
1523 vty_out (vty
, ", %s", ifindex2ifname (nexthop
->ifindex
));
1525 case NEXTHOP_TYPE_IFINDEX
:
1526 vty_out (vty
, " is directly connected, %s",
1527 ifindex2ifname (nexthop
->ifindex
));
1529 case NEXTHOP_TYPE_IFNAME
:
1530 vty_out (vty
, " is directly connected, %s",
1536 if (! CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
))
1537 vty_out (vty
, " inactive");
1539 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_RECURSIVE
))
1541 vty_out (vty
, " (recursive");
1543 switch (nexthop
->rtype
)
1545 case NEXTHOP_TYPE_IPV6
:
1546 case NEXTHOP_TYPE_IPV6_IFINDEX
:
1547 case NEXTHOP_TYPE_IPV6_IFNAME
:
1548 vty_out (vty
, " via %s)",
1549 inet_ntop (AF_INET6
, &nexthop
->rgate
.ipv6
,
1551 if (nexthop
->rifindex
)
1552 vty_out (vty
, ", %s", ifindex2ifname (nexthop
->rifindex
));
1554 case NEXTHOP_TYPE_IFINDEX
:
1555 case NEXTHOP_TYPE_IFNAME
:
1556 vty_out (vty
, " is directly connected, %s)",
1557 ifindex2ifname (nexthop
->rifindex
));
1564 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_BLACKHOLE
))
1565 vty_out (vty
, ", bh");
1566 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_REJECT
))
1567 vty_out (vty
, ", rej");
1569 if (rib
->type
== ZEBRA_ROUTE_RIPNG
1570 || rib
->type
== ZEBRA_ROUTE_OSPF6
1571 || rib
->type
== ZEBRA_ROUTE_ISIS
1572 || rib
->type
== ZEBRA_ROUTE_BGP
)
1577 uptime
= time (NULL
);
1578 uptime
-= rib
->uptime
;
1579 tm
= gmtime (&uptime
);
1581 #define ONE_DAY_SECOND 60*60*24
1582 #define ONE_WEEK_SECOND 60*60*24*7
1584 if (uptime
< ONE_DAY_SECOND
)
1585 vty_out (vty
, ", %02d:%02d:%02d",
1586 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
1587 else if (uptime
< ONE_WEEK_SECOND
)
1588 vty_out (vty
, ", %dd%02dh%02dm",
1589 tm
->tm_yday
, tm
->tm_hour
, tm
->tm_min
);
1591 vty_out (vty
, ", %02dw%dd%02dh",
1593 tm
->tm_yday
- ((tm
->tm_yday
/7) * 7), tm
->tm_hour
);
1595 vty_out (vty
, "%s", VTY_NEWLINE
);
1599 #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"
1601 DEFUN (show_ipv6_route
,
1602 show_ipv6_route_cmd
,
1606 "IPv6 routing table\n")
1608 struct route_table
*table
;
1609 struct route_node
*rn
;
1613 table
= vrf_table (AFI_IP6
, SAFI_UNICAST
, 0);
1617 /* Show all IPv6 route. */
1618 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
1619 for (rib
= rn
->info
; rib
; rib
= rib
->next
)
1623 vty_out (vty
, SHOW_ROUTE_V6_HEADER
, VTY_NEWLINE
, VTY_NEWLINE
, VTY_NEWLINE
);
1626 vty_show_ipv6_route (vty
, rn
, rib
);
1631 DEFUN (show_ipv6_route_prefix_longer
,
1632 show_ipv6_route_prefix_longer_cmd
,
1633 "show ipv6 route X:X::X:X/M longer-prefixes",
1636 "IPv6 routing table\n"
1638 "Show route matching the specified Network/Mask pair only\n")
1640 struct route_table
*table
;
1641 struct route_node
*rn
;
1647 table
= vrf_table (AFI_IP6
, SAFI_UNICAST
, 0);
1651 ret
= str2prefix (argv
[0], &p
);
1654 vty_out (vty
, "%% Malformed Prefix%s", VTY_NEWLINE
);
1658 /* Show matched type IPv6 routes. */
1659 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
1660 for (rib
= rn
->info
; rib
; rib
= rib
->next
)
1661 if (prefix_match (&p
, &rn
->p
))
1665 vty_out (vty
, SHOW_ROUTE_V6_HEADER
, VTY_NEWLINE
, VTY_NEWLINE
, VTY_NEWLINE
);
1668 vty_show_ipv6_route (vty
, rn
, rib
);
1673 DEFUN (show_ipv6_route_protocol
,
1674 show_ipv6_route_protocol_cmd
,
1675 "show ipv6 route (bgp|connected|isis|kernel|ospf6|ripng|static)",
1678 "IP routing table\n"
1679 "Border Gateway Protocol (BGP)\n"
1681 "ISO IS-IS (ISIS)\n"
1683 "Open Shortest Path First (OSPFv3)\n"
1684 "Routing Information Protocol (RIPng)\n"
1688 struct route_table
*table
;
1689 struct route_node
*rn
;
1693 if (strncmp (argv
[0], "b", 1) == 0)
1694 type
= ZEBRA_ROUTE_BGP
;
1695 else if (strncmp (argv
[0], "c", 1) == 0)
1696 type
= ZEBRA_ROUTE_CONNECT
;
1697 else if (strncmp (argv
[0], "k", 1) ==0)
1698 type
= ZEBRA_ROUTE_KERNEL
;
1699 else if (strncmp (argv
[0], "o", 1) == 0)
1700 type
= ZEBRA_ROUTE_OSPF6
;
1701 else if (strncmp (argv
[0], "i", 1) == 0)
1702 type
= ZEBRA_ROUTE_ISIS
;
1703 else if (strncmp (argv
[0], "r", 1) == 0)
1704 type
= ZEBRA_ROUTE_RIPNG
;
1705 else if (strncmp (argv
[0], "s", 1) == 0)
1706 type
= ZEBRA_ROUTE_STATIC
;
1709 vty_out (vty
, "Unknown route type%s", VTY_NEWLINE
);
1713 table
= vrf_table (AFI_IP6
, SAFI_UNICAST
, 0);
1717 /* Show matched type IPv6 routes. */
1718 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
1719 for (rib
= rn
->info
; rib
; rib
= rib
->next
)
1720 if (rib
->type
== type
)
1724 vty_out (vty
, SHOW_ROUTE_V6_HEADER
, VTY_NEWLINE
, VTY_NEWLINE
, VTY_NEWLINE
);
1727 vty_show_ipv6_route (vty
, rn
, rib
);
1732 DEFUN (show_ipv6_route_addr
,
1733 show_ipv6_route_addr_cmd
,
1734 "show ipv6 route X:X::X:X",
1737 "IPv6 routing table\n"
1741 struct prefix_ipv6 p
;
1742 struct route_table
*table
;
1743 struct route_node
*rn
;
1745 ret
= str2prefix_ipv6 (argv
[0], &p
);
1748 vty_out (vty
, "Malformed IPv6 address%s", VTY_NEWLINE
);
1752 table
= vrf_table (AFI_IP6
, SAFI_UNICAST
, 0);
1756 rn
= route_node_match (table
, (struct prefix
*) &p
);
1759 vty_out (vty
, "%% Network not in table%s", VTY_NEWLINE
);
1763 vty_show_ipv6_route_detail (vty
, rn
);
1765 route_unlock_node (rn
);
1770 DEFUN (show_ipv6_route_prefix
,
1771 show_ipv6_route_prefix_cmd
,
1772 "show ipv6 route X:X::X:X/M",
1775 "IPv6 routing table\n"
1779 struct prefix_ipv6 p
;
1780 struct route_table
*table
;
1781 struct route_node
*rn
;
1783 ret
= str2prefix_ipv6 (argv
[0], &p
);
1786 vty_out (vty
, "Malformed IPv6 prefix%s", VTY_NEWLINE
);
1790 table
= vrf_table (AFI_IP6
, SAFI_UNICAST
, 0);
1794 rn
= route_node_match (table
, (struct prefix
*) &p
);
1795 if (! rn
|| rn
->p
.prefixlen
!= p
.prefixlen
)
1797 vty_out (vty
, "%% Network not in table%s", VTY_NEWLINE
);
1801 vty_show_ipv6_route_detail (vty
, rn
);
1803 route_unlock_node (rn
);
1809 /* Write IPv6 static route configuration. */
1811 static_config_ipv6 (struct vty
*vty
)
1813 struct route_node
*rn
;
1814 struct static_ipv6
*si
;
1817 struct route_table
*stable
;
1822 stable
= vrf_static_table (AFI_IP6
, SAFI_UNICAST
, 0);
1826 for (rn
= route_top (stable
); rn
; rn
= route_next (rn
))
1827 for (si
= rn
->info
; si
; si
= si
->next
)
1829 vty_out (vty
, "ipv6 route %s/%d",
1830 inet_ntop (AF_INET6
, &rn
->p
.u
.prefix6
, buf
, BUFSIZ
),
1835 case STATIC_IPV6_GATEWAY
:
1836 vty_out (vty
, " %s", inet_ntop (AF_INET6
, &si
->ipv6
, buf
, BUFSIZ
));
1838 case STATIC_IPV6_IFNAME
:
1839 vty_out (vty
, " %s", si
->ifname
);
1841 case STATIC_IPV6_GATEWAY_IFNAME
:
1842 vty_out (vty
, " %s %s",
1843 inet_ntop (AF_INET6
, &si
->ipv6
, buf
, BUFSIZ
), si
->ifname
);
1847 if (CHECK_FLAG(si
->flags
, ZEBRA_FLAG_REJECT
))
1848 vty_out (vty
, " %s", "reject");
1850 if (CHECK_FLAG(si
->flags
, ZEBRA_FLAG_BLACKHOLE
))
1851 vty_out (vty
, " %s", "blackhole");
1853 if (si
->distance
!= ZEBRA_STATIC_DISTANCE_DEFAULT
)
1854 vty_out (vty
, " %d", si
->distance
);
1855 vty_out (vty
, "%s", VTY_NEWLINE
);
1861 #endif /* HAVE_IPV6 */
1863 /* Static ip route configuration write function. */
1865 zebra_ip_config (struct vty
*vty
)
1869 write
+= static_config_ipv4 (vty
);
1871 write
+= static_config_ipv6 (vty
);
1872 #endif /* HAVE_IPV6 */
1877 /* IP node for static routes. */
1878 struct cmd_node ip_node
= { IP_NODE
, "", 1 };
1882 zebra_vty_init (void)
1884 install_node (&ip_node
, zebra_ip_config
);
1886 install_element (CONFIG_NODE
, &ip_route_cmd
);
1887 install_element (CONFIG_NODE
, &ip_route_flags_cmd
);
1888 install_element (CONFIG_NODE
, &ip_route_flags2_cmd
);
1889 install_element (CONFIG_NODE
, &ip_route_mask_cmd
);
1890 install_element (CONFIG_NODE
, &ip_route_mask_flags_cmd
);
1891 install_element (CONFIG_NODE
, &ip_route_mask_flags2_cmd
);
1892 install_element (CONFIG_NODE
, &no_ip_route_cmd
);
1893 install_element (CONFIG_NODE
, &no_ip_route_flags_cmd
);
1894 install_element (CONFIG_NODE
, &no_ip_route_flags2_cmd
);
1895 install_element (CONFIG_NODE
, &no_ip_route_mask_cmd
);
1896 install_element (CONFIG_NODE
, &no_ip_route_mask_flags_cmd
);
1897 install_element (CONFIG_NODE
, &no_ip_route_mask_flags2_cmd
);
1898 install_element (CONFIG_NODE
, &ip_route_distance_cmd
);
1899 install_element (CONFIG_NODE
, &ip_route_flags_distance_cmd
);
1900 install_element (CONFIG_NODE
, &ip_route_flags_distance2_cmd
);
1901 install_element (CONFIG_NODE
, &ip_route_mask_distance_cmd
);
1902 install_element (CONFIG_NODE
, &ip_route_mask_flags_distance_cmd
);
1903 install_element (CONFIG_NODE
, &ip_route_mask_flags_distance2_cmd
);
1904 install_element (CONFIG_NODE
, &no_ip_route_distance_cmd
);
1905 install_element (CONFIG_NODE
, &no_ip_route_flags_distance_cmd
);
1906 install_element (CONFIG_NODE
, &no_ip_route_flags_distance2_cmd
);
1907 install_element (CONFIG_NODE
, &no_ip_route_mask_flags_distance_cmd
);
1908 install_element (CONFIG_NODE
, &no_ip_route_mask_flags_distance2_cmd
);
1910 install_element (VIEW_NODE
, &show_ip_route_cmd
);
1911 install_element (VIEW_NODE
, &show_ip_route_addr_cmd
);
1912 install_element (VIEW_NODE
, &show_ip_route_prefix_cmd
);
1913 install_element (VIEW_NODE
, &show_ip_route_prefix_longer_cmd
);
1914 install_element (VIEW_NODE
, &show_ip_route_protocol_cmd
);
1915 install_element (VIEW_NODE
, &show_ip_route_supernets_cmd
);
1916 install_element (ENABLE_NODE
, &show_ip_route_cmd
);
1917 install_element (ENABLE_NODE
, &show_ip_route_addr_cmd
);
1918 install_element (ENABLE_NODE
, &show_ip_route_prefix_cmd
);
1919 install_element (ENABLE_NODE
, &show_ip_route_prefix_longer_cmd
);
1920 install_element (ENABLE_NODE
, &show_ip_route_protocol_cmd
);
1921 install_element (ENABLE_NODE
, &show_ip_route_supernets_cmd
);
1924 install_element (VIEW_NODE
, &show_ip_route_summary_cmd
);
1925 install_element (ENABLE_NODE
, &show_ip_route_summary_cmd
);
1929 install_element (CONFIG_NODE
, &ipv6_route_cmd
);
1930 install_element (CONFIG_NODE
, &ipv6_route_flags_cmd
);
1931 install_element (CONFIG_NODE
, &ipv6_route_ifname_cmd
);
1932 install_element (CONFIG_NODE
, &ipv6_route_ifname_flags_cmd
);
1933 install_element (CONFIG_NODE
, &no_ipv6_route_cmd
);
1934 install_element (CONFIG_NODE
, &no_ipv6_route_flags_cmd
);
1935 install_element (CONFIG_NODE
, &no_ipv6_route_ifname_cmd
);
1936 install_element (CONFIG_NODE
, &no_ipv6_route_ifname_flags_cmd
);
1937 install_element (CONFIG_NODE
, &ipv6_route_pref_cmd
);
1938 install_element (CONFIG_NODE
, &ipv6_route_flags_pref_cmd
);
1939 install_element (CONFIG_NODE
, &ipv6_route_ifname_pref_cmd
);
1940 install_element (CONFIG_NODE
, &ipv6_route_ifname_flags_pref_cmd
);
1941 install_element (CONFIG_NODE
, &no_ipv6_route_pref_cmd
);
1942 install_element (CONFIG_NODE
, &no_ipv6_route_flags_pref_cmd
);
1943 install_element (CONFIG_NODE
, &no_ipv6_route_ifname_pref_cmd
);
1944 install_element (CONFIG_NODE
, &no_ipv6_route_ifname_flags_pref_cmd
);
1945 install_element (VIEW_NODE
, &show_ipv6_route_cmd
);
1946 install_element (VIEW_NODE
, &show_ipv6_route_protocol_cmd
);
1947 install_element (VIEW_NODE
, &show_ipv6_route_addr_cmd
);
1948 install_element (VIEW_NODE
, &show_ipv6_route_prefix_cmd
);
1949 install_element (VIEW_NODE
, &show_ipv6_route_prefix_longer_cmd
);
1950 install_element (ENABLE_NODE
, &show_ipv6_route_cmd
);
1951 install_element (ENABLE_NODE
, &show_ipv6_route_protocol_cmd
);
1952 install_element (ENABLE_NODE
, &show_ipv6_route_addr_cmd
);
1953 install_element (ENABLE_NODE
, &show_ipv6_route_prefix_cmd
);
1954 install_element (ENABLE_NODE
, &show_ipv6_route_prefix_longer_cmd
);
1955 #endif /* HAVE_IPV6 */