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.
31 #include "zebra/zserv.h"
33 /* General fucntion for static route. */
35 zebra_static_ipv4 (struct vty
*vty
, int add_cmd
, const char *dest_str
,
36 const char *mask_str
, const char *gate_str
,
37 const char *flag_str
, const char *distance_str
)
47 ret
= str2prefix (dest_str
, &p
);
50 vty_out (vty
, "%% Malformed address%s", VTY_NEWLINE
);
54 /* Cisco like mask notation. */
57 ret
= inet_aton (mask_str
, &mask
);
60 vty_out (vty
, "%% Malformed address%s", VTY_NEWLINE
);
63 p
.prefixlen
= ip_masklen (mask
);
66 /* Apply mask for given prefix. */
69 /* Administrative distance. */
71 distance
= atoi (distance_str
);
73 distance
= ZEBRA_STATIC_DISTANCE_DEFAULT
;
75 /* Null0 static route. */
76 if ((gate_str
!= NULL
) && (strncasecmp (gate_str
, "Null0", strlen (gate_str
)) == 0))
80 vty_out (vty
, "%% can not have flag %s with Null0%s", flag_str
, VTY_NEWLINE
);
84 static_add_ipv4 (&p
, NULL
, NULL
, ZEBRA_FLAG_BLACKHOLE
, distance
, 0);
86 static_delete_ipv4 (&p
, NULL
, NULL
, distance
, 0);
95 SET_FLAG (flag
, ZEBRA_FLAG_REJECT
);
99 SET_FLAG (flag
, ZEBRA_FLAG_BLACKHOLE
);
102 vty_out (vty
, "%% Malformed flag %s %s", flag_str
, VTY_NEWLINE
);
107 if (gate_str
== NULL
)
110 static_add_ipv4 (&p
, NULL
, NULL
, flag
, distance
, 0);
112 static_delete_ipv4 (&p
, NULL
, NULL
, distance
, 0);
117 /* When gateway is A.B.C.D format, gate is treated as nexthop
118 address other case gate is treated as interface name. */
119 ret
= inet_aton (gate_str
, &gate
);
126 static_add_ipv4 (&p
, ifname
? NULL
: &gate
, ifname
, flag
, distance
, 0);
128 static_delete_ipv4 (&p
, ifname
? NULL
: &gate
, ifname
, distance
, 0);
133 /* Static route configuration. */
136 "ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0)",
138 "Establish static routes\n"
139 "IP destination prefix (e.g. 10.0.0.0/8)\n"
140 "IP gateway address\n"
141 "IP gateway interface name\n"
144 return zebra_static_ipv4 (vty
, 1, argv
[0], NULL
, argv
[1], NULL
, NULL
);
147 DEFUN (ip_route_flags
,
149 "ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole)",
151 "Establish static routes\n"
152 "IP destination prefix (e.g. 10.0.0.0/8)\n"
153 "IP gateway address\n"
154 "IP gateway interface name\n"
155 "Emit an ICMP unreachable when matched\n"
156 "Silently discard pkts when matched\n")
158 return zebra_static_ipv4 (vty
, 1, argv
[0], NULL
, argv
[1], argv
[2], NULL
);
161 DEFUN (ip_route_flags2
,
163 "ip route A.B.C.D/M (reject|blackhole)",
165 "Establish static routes\n"
166 "IP destination prefix (e.g. 10.0.0.0/8)\n"
167 "Emit an ICMP unreachable when matched\n"
168 "Silently discard pkts when matched\n")
170 return zebra_static_ipv4 (vty
, 1, argv
[0], NULL
, NULL
, argv
[1], NULL
);
173 /* Mask as A.B.C.D format. */
174 DEFUN (ip_route_mask
,
176 "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0)",
178 "Establish static routes\n"
179 "IP destination prefix\n"
180 "IP destination prefix mask\n"
181 "IP gateway address\n"
182 "IP gateway interface name\n"
185 return zebra_static_ipv4 (vty
, 1, argv
[0], argv
[1], argv
[2], NULL
, NULL
);
188 DEFUN (ip_route_mask_flags
,
189 ip_route_mask_flags_cmd
,
190 "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole)",
192 "Establish static routes\n"
193 "IP destination prefix\n"
194 "IP destination prefix mask\n"
195 "IP gateway address\n"
196 "IP gateway interface name\n"
197 "Emit an ICMP unreachable when matched\n"
198 "Silently discard pkts when matched\n")
200 return zebra_static_ipv4 (vty
, 1, argv
[0], argv
[1], argv
[2], argv
[3], NULL
);
203 DEFUN (ip_route_mask_flags2
,
204 ip_route_mask_flags2_cmd
,
205 "ip route A.B.C.D A.B.C.D (reject|blackhole)",
207 "Establish static routes\n"
208 "IP destination prefix\n"
209 "IP destination prefix mask\n"
210 "Emit an ICMP unreachable when matched\n"
211 "Silently discard pkts when matched\n")
213 return zebra_static_ipv4 (vty
, 1, argv
[0], argv
[1], NULL
, argv
[2], NULL
);
216 /* Distance option value. */
217 DEFUN (ip_route_distance
,
218 ip_route_distance_cmd
,
219 "ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0) <1-255>",
221 "Establish static routes\n"
222 "IP destination prefix (e.g. 10.0.0.0/8)\n"
223 "IP gateway address\n"
224 "IP gateway interface name\n"
226 "Distance value for this route\n")
228 return zebra_static_ipv4 (vty
, 1, argv
[0], NULL
, argv
[1], NULL
, argv
[2]);
231 DEFUN (ip_route_flags_distance
,
232 ip_route_flags_distance_cmd
,
233 "ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
235 "Establish static routes\n"
236 "IP destination prefix (e.g. 10.0.0.0/8)\n"
237 "IP gateway address\n"
238 "IP gateway interface name\n"
239 "Emit an ICMP unreachable when matched\n"
240 "Silently discard pkts when matched\n"
241 "Distance value for this route\n")
243 return zebra_static_ipv4 (vty
, 1, argv
[0], NULL
, argv
[1], argv
[2], argv
[3]);
246 DEFUN (ip_route_flags_distance2
,
247 ip_route_flags_distance2_cmd
,
248 "ip route A.B.C.D/M (reject|blackhole) <1-255>",
250 "Establish static routes\n"
251 "IP destination prefix (e.g. 10.0.0.0/8)\n"
252 "Emit an ICMP unreachable when matched\n"
253 "Silently discard pkts when matched\n"
254 "Distance value for this route\n")
256 return zebra_static_ipv4 (vty
, 1, argv
[0], NULL
, NULL
, argv
[1], argv
[2]);
259 DEFUN (ip_route_mask_distance
,
260 ip_route_mask_distance_cmd
,
261 "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0) <1-255>",
263 "Establish static routes\n"
264 "IP destination prefix\n"
265 "IP destination prefix mask\n"
266 "IP gateway address\n"
267 "IP gateway interface name\n"
269 "Distance value for this route\n")
271 return zebra_static_ipv4 (vty
, 1, argv
[0], argv
[1], argv
[2], NULL
, argv
[3]);
274 DEFUN (ip_route_mask_flags_distance
,
275 ip_route_mask_flags_distance_cmd
,
276 "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
278 "Establish static routes\n"
279 "IP destination prefix\n"
280 "IP destination prefix mask\n"
281 "IP gateway address\n"
282 "IP gateway interface name\n"
283 "Distance value for this route\n"
284 "Emit an ICMP unreachable when matched\n"
285 "Silently discard pkts when matched\n")
287 return zebra_static_ipv4 (vty
, 1, argv
[0], argv
[1], argv
[2], argv
[3], argv
[4]);
290 DEFUN (ip_route_mask_flags_distance2
,
291 ip_route_mask_flags_distance2_cmd
,
292 "ip route A.B.C.D A.B.C.D (reject|blackhole) <1-255>",
294 "Establish static routes\n"
295 "IP destination prefix\n"
296 "IP destination prefix mask\n"
297 "Distance value for this route\n"
298 "Emit an ICMP unreachable when matched\n"
299 "Silently discard pkts when matched\n")
301 return zebra_static_ipv4 (vty
, 1, argv
[0], argv
[1], NULL
, argv
[2], argv
[3]);
306 "no ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0)",
309 "Establish static routes\n"
310 "IP destination prefix (e.g. 10.0.0.0/8)\n"
311 "IP gateway address\n"
312 "IP gateway interface name\n"
315 return zebra_static_ipv4 (vty
, 0, argv
[0], NULL
, argv
[1], NULL
, NULL
);
319 no_ip_route_flags_cmd
,
320 "no ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole)",
323 "Establish static routes\n"
324 "IP destination prefix (e.g. 10.0.0.0/8)\n"
325 "IP gateway address\n"
326 "IP gateway interface name\n"
327 "Emit an ICMP unreachable when matched\n"
328 "Silently discard pkts when matched\n")
330 DEFUN (no_ip_route_flags2
,
331 no_ip_route_flags2_cmd
,
332 "no ip route A.B.C.D/M (reject|blackhole)",
335 "Establish static routes\n"
336 "IP destination prefix (e.g. 10.0.0.0/8)\n"
337 "Emit an ICMP unreachable when matched\n"
338 "Silently discard pkts when matched\n")
340 return zebra_static_ipv4 (vty
, 0, argv
[0], NULL
, NULL
, NULL
, NULL
);
343 DEFUN (no_ip_route_mask
,
344 no_ip_route_mask_cmd
,
345 "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0)",
348 "Establish static routes\n"
349 "IP destination prefix\n"
350 "IP destination prefix mask\n"
351 "IP gateway address\n"
352 "IP gateway interface name\n"
355 return zebra_static_ipv4 (vty
, 0, argv
[0], argv
[1], argv
[2], NULL
, NULL
);
358 ALIAS (no_ip_route_mask
,
359 no_ip_route_mask_flags_cmd
,
360 "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole)",
363 "Establish static routes\n"
364 "IP destination prefix\n"
365 "IP destination prefix mask\n"
366 "IP gateway address\n"
367 "IP gateway interface name\n"
368 "Emit an ICMP unreachable when matched\n"
369 "Silently discard pkts when matched\n")
371 DEFUN (no_ip_route_mask_flags2
,
372 no_ip_route_mask_flags2_cmd
,
373 "no ip route A.B.C.D A.B.C.D (reject|blackhole)",
376 "Establish static routes\n"
377 "IP destination prefix\n"
378 "IP destination prefix mask\n"
379 "Emit an ICMP unreachable when matched\n"
380 "Silently discard pkts when matched\n")
382 return zebra_static_ipv4 (vty
, 0, argv
[0], argv
[1], NULL
, NULL
, NULL
);
385 DEFUN (no_ip_route_distance
,
386 no_ip_route_distance_cmd
,
387 "no ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0) <1-255>",
390 "Establish static routes\n"
391 "IP destination prefix (e.g. 10.0.0.0/8)\n"
392 "IP gateway address\n"
393 "IP gateway interface name\n"
395 "Distance value for this route\n")
397 return zebra_static_ipv4 (vty
, 0, argv
[0], NULL
, argv
[1], NULL
, argv
[2]);
400 DEFUN (no_ip_route_flags_distance
,
401 no_ip_route_flags_distance_cmd
,
402 "no ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
405 "Establish static routes\n"
406 "IP destination prefix (e.g. 10.0.0.0/8)\n"
407 "IP gateway address\n"
408 "IP gateway interface name\n"
409 "Emit an ICMP unreachable when matched\n"
410 "Silently discard pkts when matched\n"
411 "Distance value for this route\n")
413 return zebra_static_ipv4 (vty
, 0, argv
[0], NULL
, argv
[1], argv
[2], argv
[3]);
416 DEFUN (no_ip_route_flags_distance2
,
417 no_ip_route_flags_distance2_cmd
,
418 "no ip route A.B.C.D/M (reject|blackhole) <1-255>",
421 "Establish static routes\n"
422 "IP destination prefix (e.g. 10.0.0.0/8)\n"
423 "Emit an ICMP unreachable when matched\n"
424 "Silently discard pkts when matched\n"
425 "Distance value for this route\n")
427 return zebra_static_ipv4 (vty
, 0, argv
[0], NULL
, NULL
, argv
[1], argv
[2]);
430 DEFUN (no_ip_route_mask_distance
,
431 no_ip_route_mask_distance_cmd
,
432 "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0) <1-255>",
435 "Establish static routes\n"
436 "IP destination prefix\n"
437 "IP destination prefix mask\n"
438 "IP gateway address\n"
439 "IP gateway interface name\n"
441 "Distance value for this route\n")
443 return zebra_static_ipv4 (vty
, 0, argv
[0], argv
[1], argv
[2], NULL
, argv
[3]);
446 DEFUN (no_ip_route_mask_flags_distance
,
447 no_ip_route_mask_flags_distance_cmd
,
448 "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
451 "Establish static routes\n"
452 "IP destination prefix\n"
453 "IP destination prefix mask\n"
454 "IP gateway address\n"
455 "IP gateway interface name\n"
456 "Emit an ICMP unreachable when matched\n"
457 "Silently discard pkts when matched\n"
458 "Distance value for this route\n")
460 return zebra_static_ipv4 (vty
, 0, argv
[0], argv
[1], argv
[2], argv
[3], argv
[4]);
463 DEFUN (no_ip_route_mask_flags_distance2
,
464 no_ip_route_mask_flags_distance2_cmd
,
465 "no ip route A.B.C.D A.B.C.D (reject|blackhole) <1-255>",
468 "Establish static routes\n"
469 "IP destination prefix\n"
470 "IP destination prefix mask\n"
471 "Emit an ICMP unreachable when matched\n"
472 "Silently discard pkts when matched\n"
473 "Distance value for this route\n")
475 return zebra_static_ipv4 (vty
, 0, argv
[0], argv
[1], NULL
, argv
[2], argv
[3]);
478 char *proto_rm
[AFI_MAX
][ZEBRA_ROUTE_MAX
+1]; /* "any" == ZEBRA_ROUTE_MAX */
482 "ip protocol PROTO route-map ROUTE-MAP",
484 "Apply route map to PROTO\n"
490 if (strcasecmp(argv
[0], "any") == 0)
493 i
= proto_name2num(argv
[0]);
496 vty_out (vty
, "invalid protocol name \"%s\"%s", argv
[0] ? argv
[0] : "",
500 if (proto_rm
[AFI_IP
][i
])
501 XFREE (MTYPE_ROUTE_MAP_NAME
, proto_rm
[AFI_IP
][i
]);
502 proto_rm
[AFI_IP
][i
] = XSTRDUP (MTYPE_ROUTE_MAP_NAME
, argv
[1]);
506 DEFUN (no_ip_protocol
,
508 "no ip protocol PROTO",
510 "Remove route map from PROTO\n"
515 if (strcasecmp(argv
[0], "any") == 0)
518 i
= proto_name2num(argv
[0]);
521 vty_out (vty
, "invalid protocol name \"%s\"%s", argv
[0] ? argv
[0] : "",
525 if (proto_rm
[AFI_IP
][i
])
526 XFREE (MTYPE_ROUTE_MAP_NAME
, proto_rm
[AFI_IP
][i
]);
527 proto_rm
[AFI_IP
][i
] = NULL
;
531 /* New RIB. Detailed information for IPv4 route. */
533 vty_show_ip_route_detail (struct vty
*vty
, struct route_node
*rn
)
536 struct nexthop
*nexthop
, *tnexthop
;
539 RNODE_FOREACH_RIB (rn
, rib
)
541 vty_out (vty
, "Routing entry for %s/%d%s",
542 inet_ntoa (rn
->p
.u
.prefix4
), rn
->p
.prefixlen
,
544 vty_out (vty
, " Known via \"%s\"", zebra_route_string (rib
->type
));
545 vty_out (vty
, ", distance %u, metric %u", rib
->distance
, rib
->metric
);
546 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_SELECTED
))
547 vty_out (vty
, ", best");
549 vty_out (vty
, ", refcnt %ld", rib
->refcnt
);
550 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_BLACKHOLE
))
551 vty_out (vty
, ", blackhole");
552 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_REJECT
))
553 vty_out (vty
, ", reject");
554 vty_out (vty
, "%s", VTY_NEWLINE
);
556 #define ONE_DAY_SECOND 60*60*24
557 #define ONE_WEEK_SECOND 60*60*24*7
558 if (rib
->type
== ZEBRA_ROUTE_RIP
559 || rib
->type
== ZEBRA_ROUTE_OSPF
560 || rib
->type
== ZEBRA_ROUTE_BABEL
561 || rib
->type
== ZEBRA_ROUTE_ISIS
562 || rib
->type
== ZEBRA_ROUTE_BGP
)
567 uptime
= time (NULL
);
568 uptime
-= rib
->uptime
;
569 tm
= gmtime (&uptime
);
571 vty_out (vty
, " Last update ");
573 if (uptime
< ONE_DAY_SECOND
)
574 vty_out (vty
, "%02d:%02d:%02d",
575 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
576 else if (uptime
< ONE_WEEK_SECOND
)
577 vty_out (vty
, "%dd%02dh%02dm",
578 tm
->tm_yday
, tm
->tm_hour
, tm
->tm_min
);
580 vty_out (vty
, "%02dw%dd%02dh",
582 tm
->tm_yday
- ((tm
->tm_yday
/7) * 7), tm
->tm_hour
);
583 vty_out (vty
, " ago%s", VTY_NEWLINE
);
586 for (ALL_NEXTHOPS_RO(rib
->nexthop
, nexthop
, tnexthop
, recursing
))
590 vty_out (vty
, " %c%s",
591 CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
) ? '*' : ' ',
592 recursing
? " " : "");
594 switch (nexthop
->type
)
596 case NEXTHOP_TYPE_IPV4
:
597 case NEXTHOP_TYPE_IPV4_IFINDEX
:
598 vty_out (vty
, " %s", inet_ntoa (nexthop
->gate
.ipv4
));
599 if (nexthop
->ifindex
)
600 vty_out (vty
, ", via %s", ifindex2ifname (nexthop
->ifindex
));
602 case NEXTHOP_TYPE_IFINDEX
:
603 vty_out (vty
, " directly connected, %s",
604 ifindex2ifname (nexthop
->ifindex
));
606 case NEXTHOP_TYPE_IFNAME
:
607 vty_out (vty
, " directly connected, %s", nexthop
->ifname
);
609 case NEXTHOP_TYPE_BLACKHOLE
:
610 vty_out (vty
, " directly connected, Null0");
615 if (! CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
))
616 vty_out (vty
, " inactive");
618 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_RECURSIVE
))
619 vty_out (vty
, " (recursive)");
621 switch (nexthop
->type
)
623 case NEXTHOP_TYPE_IPV4
:
624 case NEXTHOP_TYPE_IPV4_IFINDEX
:
625 case NEXTHOP_TYPE_IPV4_IFNAME
:
626 if (nexthop
->src
.ipv4
.s_addr
)
628 if (inet_ntop(AF_INET
, &nexthop
->src
.ipv4
, addrstr
,
630 vty_out (vty
, ", src %s", addrstr
);
634 case NEXTHOP_TYPE_IPV6
:
635 case NEXTHOP_TYPE_IPV6_IFINDEX
:
636 case NEXTHOP_TYPE_IPV6_IFNAME
:
637 if (!IPV6_ADDR_SAME(&nexthop
->src
.ipv6
, &in6addr_any
))
639 if (inet_ntop(AF_INET6
, &nexthop
->src
.ipv6
, addrstr
,
641 vty_out (vty
, ", src %s", addrstr
);
644 #endif /* HAVE_IPV6 */
648 vty_out (vty
, "%s", VTY_NEWLINE
);
650 vty_out (vty
, "%s", VTY_NEWLINE
);
655 vty_show_ip_route (struct vty
*vty
, struct route_node
*rn
, struct rib
*rib
)
657 struct nexthop
*nexthop
, *tnexthop
;
662 /* Nexthop information. */
663 for (ALL_NEXTHOPS_RO(rib
->nexthop
, nexthop
, tnexthop
, recursing
))
665 if (nexthop
== rib
->nexthop
)
667 /* Prefix information. */
668 len
= vty_out (vty
, "%c%c%c %s/%d",
669 zebra_route_char (rib
->type
),
670 CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_SELECTED
)
672 CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
)
674 inet_ntop (AF_INET
, &rn
->p
.u
.prefix
, buf
, BUFSIZ
),
677 /* Distance and metric display. */
678 if (rib
->type
!= ZEBRA_ROUTE_CONNECT
679 && rib
->type
!= ZEBRA_ROUTE_KERNEL
)
680 len
+= vty_out (vty
, " [%d/%d]", rib
->distance
,
684 vty_out (vty
, " %c%*c",
685 CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
)
687 len
- 3 + (2 * recursing
), ' ');
689 switch (nexthop
->type
)
691 case NEXTHOP_TYPE_IPV4
:
692 case NEXTHOP_TYPE_IPV4_IFINDEX
:
693 vty_out (vty
, " via %s", inet_ntoa (nexthop
->gate
.ipv4
));
694 if (nexthop
->ifindex
)
695 vty_out (vty
, ", %s", ifindex2ifname (nexthop
->ifindex
));
697 case NEXTHOP_TYPE_IFINDEX
:
698 vty_out (vty
, " is directly connected, %s",
699 ifindex2ifname (nexthop
->ifindex
));
701 case NEXTHOP_TYPE_IFNAME
:
702 vty_out (vty
, " is directly connected, %s", nexthop
->ifname
);
704 case NEXTHOP_TYPE_BLACKHOLE
:
705 vty_out (vty
, " is directly connected, Null0");
710 if (! CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
))
711 vty_out (vty
, " inactive");
713 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_RECURSIVE
))
714 vty_out (vty
, " (recursive)");
716 switch (nexthop
->type
)
718 case NEXTHOP_TYPE_IPV4
:
719 case NEXTHOP_TYPE_IPV4_IFINDEX
:
720 case NEXTHOP_TYPE_IPV4_IFNAME
:
721 if (nexthop
->src
.ipv4
.s_addr
)
723 if (inet_ntop(AF_INET
, &nexthop
->src
.ipv4
, buf
, sizeof buf
))
724 vty_out (vty
, ", src %s", buf
);
728 case NEXTHOP_TYPE_IPV6
:
729 case NEXTHOP_TYPE_IPV6_IFINDEX
:
730 case NEXTHOP_TYPE_IPV6_IFNAME
:
731 if (!IPV6_ADDR_SAME(&nexthop
->src
.ipv6
, &in6addr_any
))
733 if (inet_ntop(AF_INET6
, &nexthop
->src
.ipv6
, buf
, sizeof buf
))
734 vty_out (vty
, ", src %s", buf
);
737 #endif /* HAVE_IPV6 */
742 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_BLACKHOLE
))
743 vty_out (vty
, ", bh");
744 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_REJECT
))
745 vty_out (vty
, ", rej");
747 if (rib
->type
== ZEBRA_ROUTE_RIP
748 || rib
->type
== ZEBRA_ROUTE_OSPF
749 || rib
->type
== ZEBRA_ROUTE_BABEL
750 || rib
->type
== ZEBRA_ROUTE_ISIS
751 || rib
->type
== ZEBRA_ROUTE_BGP
)
756 uptime
= time (NULL
);
757 uptime
-= rib
->uptime
;
758 tm
= gmtime (&uptime
);
760 #define ONE_DAY_SECOND 60*60*24
761 #define ONE_WEEK_SECOND 60*60*24*7
763 if (uptime
< ONE_DAY_SECOND
)
764 vty_out (vty
, ", %02d:%02d:%02d",
765 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
766 else if (uptime
< ONE_WEEK_SECOND
)
767 vty_out (vty
, ", %dd%02dh%02dm",
768 tm
->tm_yday
, tm
->tm_hour
, tm
->tm_min
);
770 vty_out (vty
, ", %02dw%dd%02dh",
772 tm
->tm_yday
- ((tm
->tm_yday
/7) * 7), tm
->tm_hour
);
774 vty_out (vty
, "%s", VTY_NEWLINE
);
778 DEFUN (show_ip_route
,
783 "IP routing table\n")
785 struct route_table
*table
;
786 struct route_node
*rn
;
790 table
= vrf_table (AFI_IP
, SAFI_UNICAST
, 0);
794 /* Show all IPv4 routes. */
795 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
796 RNODE_FOREACH_RIB (rn
, rib
)
800 vty_out (vty
, SHOW_ROUTE_V4_HEADER
);
803 vty_show_ip_route (vty
, rn
, rib
);
808 DEFUN (show_ip_route_prefix_longer
,
809 show_ip_route_prefix_longer_cmd
,
810 "show ip route A.B.C.D/M longer-prefixes",
814 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
815 "Show route matching the specified Network/Mask pair only\n")
817 struct route_table
*table
;
818 struct route_node
*rn
;
824 ret
= str2prefix (argv
[0], &p
);
827 vty_out (vty
, "%% Malformed Prefix%s", VTY_NEWLINE
);
831 table
= vrf_table (AFI_IP
, SAFI_UNICAST
, 0);
835 /* Show matched type IPv4 routes. */
836 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
837 RNODE_FOREACH_RIB (rn
, rib
)
838 if (prefix_match (&p
, &rn
->p
))
842 vty_out (vty
, SHOW_ROUTE_V4_HEADER
);
845 vty_show_ip_route (vty
, rn
, rib
);
850 DEFUN (show_ip_route_supernets
,
851 show_ip_route_supernets_cmd
,
852 "show ip route supernets-only",
856 "Show supernet entries only\n")
858 struct route_table
*table
;
859 struct route_node
*rn
;
864 table
= vrf_table (AFI_IP
, SAFI_UNICAST
, 0);
868 /* Show matched type IPv4 routes. */
869 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
870 RNODE_FOREACH_RIB (rn
, rib
)
872 addr
= ntohl (rn
->p
.u
.prefix4
.s_addr
);
874 if ((IN_CLASSC (addr
) && rn
->p
.prefixlen
< 24)
875 || (IN_CLASSB (addr
) && rn
->p
.prefixlen
< 16)
876 || (IN_CLASSA (addr
) && rn
->p
.prefixlen
< 8))
880 vty_out (vty
, SHOW_ROUTE_V4_HEADER
);
883 vty_show_ip_route (vty
, rn
, rib
);
889 DEFUN (show_ip_route_protocol
,
890 show_ip_route_protocol_cmd
,
891 "show ip route " QUAGGA_IP_REDIST_STR_ZEBRA
,
895 QUAGGA_IP_REDIST_HELP_STR_ZEBRA
)
898 struct route_table
*table
;
899 struct route_node
*rn
;
903 type
= proto_redistnum (AFI_IP
, argv
[0]);
906 vty_out (vty
, "Unknown route type%s", VTY_NEWLINE
);
910 table
= vrf_table (AFI_IP
, SAFI_UNICAST
, 0);
914 /* Show matched type IPv4 routes. */
915 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
916 RNODE_FOREACH_RIB (rn
, rib
)
917 if (rib
->type
== type
)
921 vty_out (vty
, SHOW_ROUTE_V4_HEADER
);
924 vty_show_ip_route (vty
, rn
, rib
);
929 DEFUN (show_ip_route_addr
,
930 show_ip_route_addr_cmd
,
931 "show ip route A.B.C.D",
935 "Network in the IP routing table to display\n")
938 struct prefix_ipv4 p
;
939 struct route_table
*table
;
940 struct route_node
*rn
;
942 ret
= str2prefix_ipv4 (argv
[0], &p
);
945 vty_out (vty
, "%% Malformed IPv4 address%s", VTY_NEWLINE
);
949 table
= vrf_table (AFI_IP
, SAFI_UNICAST
, 0);
953 rn
= route_node_match (table
, (struct prefix
*) &p
);
956 vty_out (vty
, "%% Network not in table%s", VTY_NEWLINE
);
960 vty_show_ip_route_detail (vty
, rn
);
962 route_unlock_node (rn
);
967 DEFUN (show_ip_route_prefix
,
968 show_ip_route_prefix_cmd
,
969 "show ip route A.B.C.D/M",
973 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
976 struct prefix_ipv4 p
;
977 struct route_table
*table
;
978 struct route_node
*rn
;
980 ret
= str2prefix_ipv4 (argv
[0], &p
);
983 vty_out (vty
, "%% Malformed IPv4 address%s", VTY_NEWLINE
);
987 table
= vrf_table (AFI_IP
, SAFI_UNICAST
, 0);
991 rn
= route_node_match (table
, (struct prefix
*) &p
);
992 if (! rn
|| rn
->p
.prefixlen
!= p
.prefixlen
)
994 vty_out (vty
, "%% Network not in table%s", VTY_NEWLINE
);
998 vty_show_ip_route_detail (vty
, rn
);
1000 route_unlock_node (rn
);
1006 vty_show_ip_route_summary (struct vty
*vty
, struct route_table
*table
)
1008 struct route_node
*rn
;
1010 struct nexthop
*nexthop
;
1011 #define ZEBRA_ROUTE_IBGP ZEBRA_ROUTE_MAX
1012 #define ZEBRA_ROUTE_TOTAL (ZEBRA_ROUTE_IBGP + 1)
1013 u_int32_t rib_cnt
[ZEBRA_ROUTE_TOTAL
+ 1];
1014 u_int32_t fib_cnt
[ZEBRA_ROUTE_TOTAL
+ 1];
1017 memset (&rib_cnt
, 0, sizeof(rib_cnt
));
1018 memset (&fib_cnt
, 0, sizeof(fib_cnt
));
1019 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
1020 RNODE_FOREACH_RIB (rn
, rib
)
1021 for (nexthop
= rib
->nexthop
; nexthop
; nexthop
= nexthop
->next
)
1023 rib_cnt
[ZEBRA_ROUTE_TOTAL
]++;
1024 rib_cnt
[rib
->type
]++;
1025 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
)
1026 || nexthop_has_fib_child(nexthop
))
1028 fib_cnt
[ZEBRA_ROUTE_TOTAL
]++;
1029 fib_cnt
[rib
->type
]++;
1031 if (rib
->type
== ZEBRA_ROUTE_BGP
&&
1032 CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_IBGP
))
1034 rib_cnt
[ZEBRA_ROUTE_IBGP
]++;
1035 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
)
1036 || nexthop_has_fib_child(nexthop
))
1037 fib_cnt
[ZEBRA_ROUTE_IBGP
]++;
1041 vty_out (vty
, "%-20s %-20s %-20s %s",
1042 "Route Source", "Routes", "FIB", VTY_NEWLINE
);
1044 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
1048 if (i
== ZEBRA_ROUTE_BGP
)
1050 vty_out (vty
, "%-20s %-20d %-20d %s", "ebgp",
1051 rib_cnt
[ZEBRA_ROUTE_BGP
] - rib_cnt
[ZEBRA_ROUTE_IBGP
],
1052 fib_cnt
[ZEBRA_ROUTE_BGP
] - fib_cnt
[ZEBRA_ROUTE_IBGP
],
1054 vty_out (vty
, "%-20s %-20d %-20d %s", "ibgp",
1055 rib_cnt
[ZEBRA_ROUTE_IBGP
], fib_cnt
[ZEBRA_ROUTE_IBGP
],
1059 vty_out (vty
, "%-20s %-20d %-20d %s", zebra_route_string(i
),
1060 rib_cnt
[i
], fib_cnt
[i
], VTY_NEWLINE
);
1064 vty_out (vty
, "------%s", VTY_NEWLINE
);
1065 vty_out (vty
, "%-20s %-20d %-20d %s", "Totals", rib_cnt
[ZEBRA_ROUTE_TOTAL
],
1066 fib_cnt
[ZEBRA_ROUTE_TOTAL
], VTY_NEWLINE
);
1069 /* Show route summary. */
1070 DEFUN (show_ip_route_summary
,
1071 show_ip_route_summary_cmd
,
1072 "show ip route summary",
1075 "IP routing table\n"
1076 "Summary of all routes\n")
1078 struct route_table
*table
;
1080 table
= vrf_table (AFI_IP
, SAFI_UNICAST
, 0);
1084 vty_show_ip_route_summary (vty
, table
);
1089 /* Write IPv4 static route configuration. */
1091 static_config_ipv4 (struct vty
*vty
)
1093 struct route_node
*rn
;
1094 struct static_ipv4
*si
;
1095 struct route_table
*stable
;
1101 stable
= vrf_static_table (AFI_IP
, SAFI_UNICAST
, 0);
1105 for (rn
= route_top (stable
); rn
; rn
= route_next (rn
))
1106 for (si
= rn
->info
; si
; si
= si
->next
)
1108 vty_out (vty
, "ip route %s/%d", inet_ntoa (rn
->p
.u
.prefix4
),
1113 case STATIC_IPV4_GATEWAY
:
1114 vty_out (vty
, " %s", inet_ntoa (si
->gate
.ipv4
));
1116 case STATIC_IPV4_IFNAME
:
1117 vty_out (vty
, " %s", si
->gate
.ifname
);
1119 case STATIC_IPV4_BLACKHOLE
:
1120 vty_out (vty
, " Null0");
1124 /* flags are incompatible with STATIC_IPV4_BLACKHOLE */
1125 if (si
->type
!= STATIC_IPV4_BLACKHOLE
)
1127 if (CHECK_FLAG(si
->flags
, ZEBRA_FLAG_REJECT
))
1128 vty_out (vty
, " %s", "reject");
1130 if (CHECK_FLAG(si
->flags
, ZEBRA_FLAG_BLACKHOLE
))
1131 vty_out (vty
, " %s", "blackhole");
1134 if (si
->distance
!= ZEBRA_STATIC_DISTANCE_DEFAULT
)
1135 vty_out (vty
, " %d", si
->distance
);
1137 vty_out (vty
, "%s", VTY_NEWLINE
);
1144 DEFUN (show_ip_protocol
,
1145 show_ip_protocol_cmd
,
1149 "IP protocol filtering status\n")
1153 vty_out(vty
, "Protocol : route-map %s", VTY_NEWLINE
);
1154 vty_out(vty
, "------------------------%s", VTY_NEWLINE
);
1155 for (i
=0;i
<ZEBRA_ROUTE_MAX
;i
++)
1157 if (proto_rm
[AFI_IP
][i
])
1158 vty_out (vty
, "%-10s : %-10s%s", zebra_route_string(i
),
1159 proto_rm
[AFI_IP
][i
],
1162 vty_out (vty
, "%-10s : none%s", zebra_route_string(i
), VTY_NEWLINE
);
1164 if (proto_rm
[AFI_IP
][i
])
1165 vty_out (vty
, "%-10s : %-10s%s", "any", proto_rm
[AFI_IP
][i
],
1168 vty_out (vty
, "%-10s : none%s", "any", VTY_NEWLINE
);
1174 * Show IP mroute command to dump the BGP Multicast
1177 DEFUN (show_ip_mroute
,
1182 "IP Multicast routing table\n")
1184 struct route_table
*table
;
1185 struct route_node
*rn
;
1189 table
= vrf_table (AFI_IP
, SAFI_MULTICAST
, 0);
1193 /* Show all IPv4 routes. */
1194 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
1195 RNODE_FOREACH_RIB (rn
, rib
)
1199 vty_out (vty
, SHOW_ROUTE_V4_HEADER
);
1202 vty_show_ip_route (vty
, rn
, rib
);
1209 /* General fucntion for IPv6 static route. */
1211 static_ipv6_func (struct vty
*vty
, int add_cmd
, const char *dest_str
,
1212 const char *gate_str
, const char *ifname
,
1213 const char *flag_str
, const char *distance_str
)
1218 struct in6_addr
*gate
= NULL
;
1219 struct in6_addr gate_addr
;
1224 ret
= str2prefix (dest_str
, &p
);
1227 vty_out (vty
, "%% Malformed address%s", VTY_NEWLINE
);
1231 /* Apply mask for given prefix. */
1236 switch(flag_str
[0]) {
1239 SET_FLAG (flag
, ZEBRA_FLAG_REJECT
);
1243 SET_FLAG (flag
, ZEBRA_FLAG_BLACKHOLE
);
1246 vty_out (vty
, "%% Malformed flag %s %s", flag_str
, VTY_NEWLINE
);
1251 /* Administrative distance. */
1253 distance
= atoi (distance_str
);
1255 distance
= ZEBRA_STATIC_DISTANCE_DEFAULT
;
1257 /* When gateway is valid IPv6 addrees, then gate is treated as
1258 nexthop address other case gate is treated as interface name. */
1259 ret
= inet_pton (AF_INET6
, gate_str
, &gate_addr
);
1263 /* When ifname is specified. It must be come with gateway
1267 vty_out (vty
, "%% Malformed address%s", VTY_NEWLINE
);
1270 type
= STATIC_IPV6_GATEWAY_IFNAME
;
1277 type
= STATIC_IPV6_GATEWAY
;
1282 type
= STATIC_IPV6_IFNAME
;
1288 static_add_ipv6 (&p
, type
, gate
, ifname
, flag
, distance
, table
);
1290 static_delete_ipv6 (&p
, type
, gate
, ifname
, distance
, table
);
1297 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE)",
1299 "Establish static routes\n"
1300 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1301 "IPv6 gateway address\n"
1302 "IPv6 gateway interface name\n")
1304 return static_ipv6_func (vty
, 1, argv
[0], argv
[1], NULL
, NULL
, NULL
);
1307 DEFUN (ipv6_route_flags
,
1308 ipv6_route_flags_cmd
,
1309 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole)",
1311 "Establish static routes\n"
1312 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1313 "IPv6 gateway address\n"
1314 "IPv6 gateway interface name\n"
1315 "Emit an ICMP unreachable when matched\n"
1316 "Silently discard pkts when matched\n")
1318 return static_ipv6_func (vty
, 1, argv
[0], argv
[1], NULL
, argv
[2], NULL
);
1321 DEFUN (ipv6_route_ifname
,
1322 ipv6_route_ifname_cmd
,
1323 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE",
1325 "Establish static routes\n"
1326 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1327 "IPv6 gateway address\n"
1328 "IPv6 gateway interface name\n")
1330 return static_ipv6_func (vty
, 1, argv
[0], argv
[1], argv
[2], NULL
, NULL
);
1333 DEFUN (ipv6_route_ifname_flags
,
1334 ipv6_route_ifname_flags_cmd
,
1335 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole)",
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 "Emit an ICMP unreachable when matched\n"
1342 "Silently discard pkts when matched\n")
1344 return static_ipv6_func (vty
, 1, argv
[0], argv
[1], argv
[2], argv
[3], NULL
);
1347 DEFUN (ipv6_route_pref
,
1348 ipv6_route_pref_cmd
,
1349 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <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 "Distance value for this prefix\n")
1357 return static_ipv6_func (vty
, 1, argv
[0], argv
[1], NULL
, NULL
, argv
[2]);
1360 DEFUN (ipv6_route_flags_pref
,
1361 ipv6_route_flags_pref_cmd
,
1362 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) <1-255>",
1364 "Establish static routes\n"
1365 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1366 "IPv6 gateway address\n"
1367 "IPv6 gateway interface name\n"
1368 "Emit an ICMP unreachable when matched\n"
1369 "Silently discard pkts when matched\n"
1370 "Distance value for this prefix\n")
1372 return static_ipv6_func (vty
, 1, argv
[0], argv
[1], NULL
, argv
[2], argv
[3]);
1375 DEFUN (ipv6_route_ifname_pref
,
1376 ipv6_route_ifname_pref_cmd
,
1377 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255>",
1379 "Establish static routes\n"
1380 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1381 "IPv6 gateway address\n"
1382 "IPv6 gateway interface name\n"
1383 "Distance value for this prefix\n")
1385 return static_ipv6_func (vty
, 1, argv
[0], argv
[1], argv
[2], NULL
, argv
[3]);
1388 DEFUN (ipv6_route_ifname_flags_pref
,
1389 ipv6_route_ifname_flags_pref_cmd
,
1390 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) <1-255>",
1392 "Establish static routes\n"
1393 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1394 "IPv6 gateway address\n"
1395 "IPv6 gateway interface name\n"
1396 "Emit an ICMP unreachable when matched\n"
1397 "Silently discard pkts when matched\n"
1398 "Distance value for this prefix\n")
1400 return static_ipv6_func (vty
, 1, argv
[0], argv
[1], argv
[2], argv
[3], argv
[4]);
1403 DEFUN (no_ipv6_route
,
1405 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE)",
1408 "Establish static routes\n"
1409 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1410 "IPv6 gateway address\n"
1411 "IPv6 gateway interface name\n")
1413 return static_ipv6_func (vty
, 0, argv
[0], argv
[1], NULL
, NULL
, NULL
);
1416 ALIAS (no_ipv6_route
,
1417 no_ipv6_route_flags_cmd
,
1418 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole)",
1421 "Establish static routes\n"
1422 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1423 "IPv6 gateway address\n"
1424 "IPv6 gateway interface name\n"
1425 "Emit an ICMP unreachable when matched\n"
1426 "Silently discard pkts when matched\n")
1428 DEFUN (no_ipv6_route_ifname
,
1429 no_ipv6_route_ifname_cmd
,
1430 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE",
1433 "Establish static routes\n"
1434 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1435 "IPv6 gateway address\n"
1436 "IPv6 gateway interface name\n")
1438 return static_ipv6_func (vty
, 0, argv
[0], argv
[1], argv
[2], NULL
, NULL
);
1441 ALIAS (no_ipv6_route_ifname
,
1442 no_ipv6_route_ifname_flags_cmd
,
1443 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole)",
1446 "Establish static routes\n"
1447 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1448 "IPv6 gateway address\n"
1449 "IPv6 gateway interface name\n"
1450 "Emit an ICMP unreachable when matched\n"
1451 "Silently discard pkts when matched\n")
1453 DEFUN (no_ipv6_route_pref
,
1454 no_ipv6_route_pref_cmd
,
1455 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <1-255>",
1458 "Establish static routes\n"
1459 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1460 "IPv6 gateway address\n"
1461 "IPv6 gateway interface name\n"
1462 "Distance value for this prefix\n")
1464 return static_ipv6_func (vty
, 0, argv
[0], argv
[1], NULL
, NULL
, argv
[2]);
1467 DEFUN (no_ipv6_route_flags_pref
,
1468 no_ipv6_route_flags_pref_cmd
,
1469 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) <1-255>",
1472 "Establish static routes\n"
1473 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1474 "IPv6 gateway address\n"
1475 "IPv6 gateway interface name\n"
1476 "Emit an ICMP unreachable when matched\n"
1477 "Silently discard pkts when matched\n"
1478 "Distance value for this prefix\n")
1480 /* We do not care about argv[2] */
1481 return static_ipv6_func (vty
, 0, argv
[0], argv
[1], NULL
, argv
[2], argv
[3]);
1484 DEFUN (no_ipv6_route_ifname_pref
,
1485 no_ipv6_route_ifname_pref_cmd
,
1486 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255>",
1489 "Establish static routes\n"
1490 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1491 "IPv6 gateway address\n"
1492 "IPv6 gateway interface name\n"
1493 "Distance value for this prefix\n")
1495 return static_ipv6_func (vty
, 0, argv
[0], argv
[1], argv
[2], NULL
, argv
[3]);
1498 DEFUN (no_ipv6_route_ifname_flags_pref
,
1499 no_ipv6_route_ifname_flags_pref_cmd
,
1500 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) <1-255>",
1503 "Establish static routes\n"
1504 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1505 "IPv6 gateway address\n"
1506 "IPv6 gateway interface name\n"
1507 "Emit an ICMP unreachable when matched\n"
1508 "Silently discard pkts when matched\n"
1509 "Distance value for this prefix\n")
1511 return static_ipv6_func (vty
, 0, argv
[0], argv
[1], argv
[2], argv
[3], argv
[4]);
1514 /* New RIB. Detailed information for IPv6 route. */
1516 vty_show_ipv6_route_detail (struct vty
*vty
, struct route_node
*rn
)
1519 struct nexthop
*nexthop
, *tnexthop
;
1523 RNODE_FOREACH_RIB (rn
, rib
)
1525 vty_out (vty
, "Routing entry for %s/%d%s",
1526 inet_ntop (AF_INET6
, &rn
->p
.u
.prefix6
, buf
, BUFSIZ
),
1529 vty_out (vty
, " Known via \"%s\"", zebra_route_string (rib
->type
));
1530 vty_out (vty
, ", distance %u, metric %u", rib
->distance
, rib
->metric
);
1531 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_SELECTED
))
1532 vty_out (vty
, ", best");
1534 vty_out (vty
, ", refcnt %ld", rib
->refcnt
);
1535 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_BLACKHOLE
))
1536 vty_out (vty
, ", blackhole");
1537 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_REJECT
))
1538 vty_out (vty
, ", reject");
1539 vty_out (vty
, "%s", VTY_NEWLINE
);
1541 #define ONE_DAY_SECOND 60*60*24
1542 #define ONE_WEEK_SECOND 60*60*24*7
1543 if (rib
->type
== ZEBRA_ROUTE_RIPNG
1544 || rib
->type
== ZEBRA_ROUTE_OSPF6
1545 || rib
->type
== ZEBRA_ROUTE_BABEL
1546 || rib
->type
== ZEBRA_ROUTE_ISIS
1547 || rib
->type
== ZEBRA_ROUTE_BGP
)
1552 uptime
= time (NULL
);
1553 uptime
-= rib
->uptime
;
1554 tm
= gmtime (&uptime
);
1556 vty_out (vty
, " Last update ");
1558 if (uptime
< ONE_DAY_SECOND
)
1559 vty_out (vty
, "%02d:%02d:%02d",
1560 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
1561 else if (uptime
< ONE_WEEK_SECOND
)
1562 vty_out (vty
, "%dd%02dh%02dm",
1563 tm
->tm_yday
, tm
->tm_hour
, tm
->tm_min
);
1565 vty_out (vty
, "%02dw%dd%02dh",
1567 tm
->tm_yday
- ((tm
->tm_yday
/7) * 7), tm
->tm_hour
);
1568 vty_out (vty
, " ago%s", VTY_NEWLINE
);
1571 for (ALL_NEXTHOPS_RO(rib
->nexthop
, nexthop
, tnexthop
, recursing
))
1573 vty_out (vty
, " %c%s",
1574 CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
) ? '*' : ' ',
1575 recursing
? " " : "");
1577 switch (nexthop
->type
)
1579 case NEXTHOP_TYPE_IPV6
:
1580 case NEXTHOP_TYPE_IPV6_IFINDEX
:
1581 case NEXTHOP_TYPE_IPV6_IFNAME
:
1582 vty_out (vty
, " %s",
1583 inet_ntop (AF_INET6
, &nexthop
->gate
.ipv6
, buf
, BUFSIZ
));
1584 if (nexthop
->type
== NEXTHOP_TYPE_IPV6_IFNAME
)
1585 vty_out (vty
, ", %s", nexthop
->ifname
);
1586 else if (nexthop
->ifindex
)
1587 vty_out (vty
, ", via %s", ifindex2ifname (nexthop
->ifindex
));
1589 case NEXTHOP_TYPE_IFINDEX
:
1590 vty_out (vty
, " directly connected, %s",
1591 ifindex2ifname (nexthop
->ifindex
));
1593 case NEXTHOP_TYPE_IFNAME
:
1594 vty_out (vty
, " directly connected, %s",
1600 if (! CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
))
1601 vty_out (vty
, " inactive");
1603 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_RECURSIVE
))
1604 vty_out (vty
, " (recursive)");
1606 vty_out (vty
, "%s", VTY_NEWLINE
);
1608 vty_out (vty
, "%s", VTY_NEWLINE
);
1613 vty_show_ipv6_route (struct vty
*vty
, struct route_node
*rn
,
1616 struct nexthop
*nexthop
, *tnexthop
;
1621 /* Nexthop information. */
1622 for (ALL_NEXTHOPS_RO(rib
->nexthop
, nexthop
, tnexthop
, recursing
))
1624 if (nexthop
== rib
->nexthop
)
1626 /* Prefix information. */
1627 len
= vty_out (vty
, "%c%c%c %s/%d",
1628 zebra_route_char (rib
->type
),
1629 CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_SELECTED
)
1631 CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
)
1633 inet_ntop (AF_INET6
, &rn
->p
.u
.prefix6
, buf
, BUFSIZ
),
1636 /* Distance and metric display. */
1637 if (rib
->type
!= ZEBRA_ROUTE_CONNECT
1638 && rib
->type
!= ZEBRA_ROUTE_KERNEL
)
1639 len
+= vty_out (vty
, " [%d/%d]", rib
->distance
,
1643 vty_out (vty
, " %c%*c",
1644 CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
)
1646 len
- 3 + (2 * recursing
), ' ');
1648 switch (nexthop
->type
)
1650 case NEXTHOP_TYPE_IPV6
:
1651 case NEXTHOP_TYPE_IPV6_IFINDEX
:
1652 case NEXTHOP_TYPE_IPV6_IFNAME
:
1653 vty_out (vty
, " via %s",
1654 inet_ntop (AF_INET6
, &nexthop
->gate
.ipv6
, buf
, BUFSIZ
));
1655 if (nexthop
->type
== NEXTHOP_TYPE_IPV6_IFNAME
)
1656 vty_out (vty
, ", %s", nexthop
->ifname
);
1657 else if (nexthop
->ifindex
)
1658 vty_out (vty
, ", %s", ifindex2ifname (nexthop
->ifindex
));
1660 case NEXTHOP_TYPE_IFINDEX
:
1661 vty_out (vty
, " is directly connected, %s",
1662 ifindex2ifname (nexthop
->ifindex
));
1664 case NEXTHOP_TYPE_IFNAME
:
1665 vty_out (vty
, " is directly connected, %s",
1671 if (! CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
))
1672 vty_out (vty
, " inactive");
1674 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_RECURSIVE
))
1675 vty_out (vty
, " (recursive)");
1677 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_BLACKHOLE
))
1678 vty_out (vty
, ", bh");
1679 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_REJECT
))
1680 vty_out (vty
, ", rej");
1682 if (rib
->type
== ZEBRA_ROUTE_RIPNG
1683 || rib
->type
== ZEBRA_ROUTE_OSPF6
1684 || rib
->type
== ZEBRA_ROUTE_BABEL
1685 || rib
->type
== ZEBRA_ROUTE_ISIS
1686 || rib
->type
== ZEBRA_ROUTE_BGP
)
1691 uptime
= time (NULL
);
1692 uptime
-= rib
->uptime
;
1693 tm
= gmtime (&uptime
);
1695 #define ONE_DAY_SECOND 60*60*24
1696 #define ONE_WEEK_SECOND 60*60*24*7
1698 if (uptime
< ONE_DAY_SECOND
)
1699 vty_out (vty
, ", %02d:%02d:%02d",
1700 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
1701 else if (uptime
< ONE_WEEK_SECOND
)
1702 vty_out (vty
, ", %dd%02dh%02dm",
1703 tm
->tm_yday
, tm
->tm_hour
, tm
->tm_min
);
1705 vty_out (vty
, ", %02dw%dd%02dh",
1707 tm
->tm_yday
- ((tm
->tm_yday
/7) * 7), tm
->tm_hour
);
1709 vty_out (vty
, "%s", VTY_NEWLINE
);
1713 DEFUN (show_ipv6_route
,
1714 show_ipv6_route_cmd
,
1718 "IPv6 routing table\n")
1720 struct route_table
*table
;
1721 struct route_node
*rn
;
1725 table
= vrf_table (AFI_IP6
, SAFI_UNICAST
, 0);
1729 /* Show all IPv6 route. */
1730 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
1731 RNODE_FOREACH_RIB (rn
, rib
)
1735 vty_out (vty
, SHOW_ROUTE_V6_HEADER
);
1738 vty_show_ipv6_route (vty
, rn
, rib
);
1743 DEFUN (show_ipv6_route_prefix_longer
,
1744 show_ipv6_route_prefix_longer_cmd
,
1745 "show ipv6 route X:X::X:X/M longer-prefixes",
1748 "IPv6 routing table\n"
1750 "Show route matching the specified Network/Mask pair only\n")
1752 struct route_table
*table
;
1753 struct route_node
*rn
;
1759 table
= vrf_table (AFI_IP6
, SAFI_UNICAST
, 0);
1763 ret
= str2prefix (argv
[0], &p
);
1766 vty_out (vty
, "%% Malformed Prefix%s", VTY_NEWLINE
);
1770 /* Show matched type IPv6 routes. */
1771 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
1772 RNODE_FOREACH_RIB (rn
, rib
)
1773 if (prefix_match (&p
, &rn
->p
))
1777 vty_out (vty
, SHOW_ROUTE_V6_HEADER
);
1780 vty_show_ipv6_route (vty
, rn
, rib
);
1785 DEFUN (show_ipv6_route_protocol
,
1786 show_ipv6_route_protocol_cmd
,
1787 "show ipv6 route " QUAGGA_IP6_REDIST_STR_ZEBRA
,
1790 "IP routing table\n"
1791 QUAGGA_IP6_REDIST_HELP_STR_ZEBRA
)
1794 struct route_table
*table
;
1795 struct route_node
*rn
;
1799 type
= proto_redistnum (AFI_IP6
, argv
[0]);
1802 vty_out (vty
, "Unknown route type%s", VTY_NEWLINE
);
1806 table
= vrf_table (AFI_IP6
, SAFI_UNICAST
, 0);
1810 /* Show matched type IPv6 routes. */
1811 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
1812 RNODE_FOREACH_RIB (rn
, rib
)
1813 if (rib
->type
== type
)
1817 vty_out (vty
, SHOW_ROUTE_V6_HEADER
);
1820 vty_show_ipv6_route (vty
, rn
, rib
);
1825 DEFUN (show_ipv6_route_addr
,
1826 show_ipv6_route_addr_cmd
,
1827 "show ipv6 route X:X::X:X",
1830 "IPv6 routing table\n"
1834 struct prefix_ipv6 p
;
1835 struct route_table
*table
;
1836 struct route_node
*rn
;
1838 ret
= str2prefix_ipv6 (argv
[0], &p
);
1841 vty_out (vty
, "Malformed IPv6 address%s", VTY_NEWLINE
);
1845 table
= vrf_table (AFI_IP6
, SAFI_UNICAST
, 0);
1849 rn
= route_node_match (table
, (struct prefix
*) &p
);
1852 vty_out (vty
, "%% Network not in table%s", VTY_NEWLINE
);
1856 vty_show_ipv6_route_detail (vty
, rn
);
1858 route_unlock_node (rn
);
1863 DEFUN (show_ipv6_route_prefix
,
1864 show_ipv6_route_prefix_cmd
,
1865 "show ipv6 route X:X::X:X/M",
1868 "IPv6 routing table\n"
1872 struct prefix_ipv6 p
;
1873 struct route_table
*table
;
1874 struct route_node
*rn
;
1876 ret
= str2prefix_ipv6 (argv
[0], &p
);
1879 vty_out (vty
, "Malformed IPv6 prefix%s", VTY_NEWLINE
);
1883 table
= vrf_table (AFI_IP6
, SAFI_UNICAST
, 0);
1887 rn
= route_node_match (table
, (struct prefix
*) &p
);
1888 if (! rn
|| rn
->p
.prefixlen
!= p
.prefixlen
)
1890 vty_out (vty
, "%% Network not in table%s", VTY_NEWLINE
);
1894 vty_show_ipv6_route_detail (vty
, rn
);
1896 route_unlock_node (rn
);
1901 /* Show route summary. */
1902 DEFUN (show_ipv6_route_summary
,
1903 show_ipv6_route_summary_cmd
,
1904 "show ipv6 route summary",
1907 "IPv6 routing table\n"
1908 "Summary of all IPv6 routes\n")
1910 struct route_table
*table
;
1912 table
= vrf_table (AFI_IP6
, SAFI_UNICAST
, 0);
1916 vty_show_ip_route_summary (vty
, table
);
1922 * Show IPv6 mroute command.Used to dump
1923 * the Multicast routing table.
1926 DEFUN (show_ipv6_mroute
,
1927 show_ipv6_mroute_cmd
,
1931 "IPv6 Multicast routing table\n")
1933 struct route_table
*table
;
1934 struct route_node
*rn
;
1938 table
= vrf_table (AFI_IP6
, SAFI_MULTICAST
, 0);
1942 /* Show all IPv6 route. */
1943 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
1944 RNODE_FOREACH_RIB (rn
, rib
)
1948 vty_out (vty
, SHOW_ROUTE_V6_HEADER
);
1951 vty_show_ipv6_route (vty
, rn
, rib
);
1956 /* Write IPv6 static route configuration. */
1958 static_config_ipv6 (struct vty
*vty
)
1960 struct route_node
*rn
;
1961 struct static_ipv6
*si
;
1964 struct route_table
*stable
;
1969 stable
= vrf_static_table (AFI_IP6
, SAFI_UNICAST
, 0);
1973 for (rn
= route_top (stable
); rn
; rn
= route_next (rn
))
1974 for (si
= rn
->info
; si
; si
= si
->next
)
1976 vty_out (vty
, "ipv6 route %s/%d",
1977 inet_ntop (AF_INET6
, &rn
->p
.u
.prefix6
, buf
, BUFSIZ
),
1982 case STATIC_IPV6_GATEWAY
:
1983 vty_out (vty
, " %s", inet_ntop (AF_INET6
, &si
->ipv6
, buf
, BUFSIZ
));
1985 case STATIC_IPV6_IFNAME
:
1986 vty_out (vty
, " %s", si
->ifname
);
1988 case STATIC_IPV6_GATEWAY_IFNAME
:
1989 vty_out (vty
, " %s %s",
1990 inet_ntop (AF_INET6
, &si
->ipv6
, buf
, BUFSIZ
), si
->ifname
);
1994 if (CHECK_FLAG(si
->flags
, ZEBRA_FLAG_REJECT
))
1995 vty_out (vty
, " %s", "reject");
1997 if (CHECK_FLAG(si
->flags
, ZEBRA_FLAG_BLACKHOLE
))
1998 vty_out (vty
, " %s", "blackhole");
2000 if (si
->distance
!= ZEBRA_STATIC_DISTANCE_DEFAULT
)
2001 vty_out (vty
, " %d", si
->distance
);
2002 vty_out (vty
, "%s", VTY_NEWLINE
);
2008 #endif /* HAVE_IPV6 */
2010 /* Static ip route configuration write function. */
2012 zebra_ip_config (struct vty
*vty
)
2016 write
+= static_config_ipv4 (vty
);
2018 write
+= static_config_ipv6 (vty
);
2019 #endif /* HAVE_IPV6 */
2024 /* ip protocol configuration write function */
2025 static int config_write_protocol(struct vty
*vty
)
2029 for (i
=0;i
<ZEBRA_ROUTE_MAX
;i
++)
2031 if (proto_rm
[AFI_IP
][i
])
2032 vty_out (vty
, "ip protocol %s route-map %s%s", zebra_route_string(i
),
2033 proto_rm
[AFI_IP
][i
], VTY_NEWLINE
);
2035 if (proto_rm
[AFI_IP
][ZEBRA_ROUTE_MAX
])
2036 vty_out (vty
, "ip protocol %s route-map %s%s", "any",
2037 proto_rm
[AFI_IP
][ZEBRA_ROUTE_MAX
], VTY_NEWLINE
);
2042 /* table node for protocol filtering */
2043 static struct cmd_node protocol_node
= { PROTOCOL_NODE
, "", 1 };
2045 /* IP node for static routes. */
2046 static struct cmd_node ip_node
= { IP_NODE
, "", 1 };
2050 zebra_vty_init (void)
2052 install_node (&ip_node
, zebra_ip_config
);
2053 install_node (&protocol_node
, config_write_protocol
);
2055 install_element (CONFIG_NODE
, &ip_protocol_cmd
);
2056 install_element (CONFIG_NODE
, &no_ip_protocol_cmd
);
2057 install_element (VIEW_NODE
, &show_ip_protocol_cmd
);
2058 install_element (ENABLE_NODE
, &show_ip_protocol_cmd
);
2059 install_element (CONFIG_NODE
, &ip_route_cmd
);
2060 install_element (CONFIG_NODE
, &ip_route_flags_cmd
);
2061 install_element (CONFIG_NODE
, &ip_route_flags2_cmd
);
2062 install_element (CONFIG_NODE
, &ip_route_mask_cmd
);
2063 install_element (CONFIG_NODE
, &ip_route_mask_flags_cmd
);
2064 install_element (CONFIG_NODE
, &ip_route_mask_flags2_cmd
);
2065 install_element (CONFIG_NODE
, &no_ip_route_cmd
);
2066 install_element (CONFIG_NODE
, &no_ip_route_flags_cmd
);
2067 install_element (CONFIG_NODE
, &no_ip_route_flags2_cmd
);
2068 install_element (CONFIG_NODE
, &no_ip_route_mask_cmd
);
2069 install_element (CONFIG_NODE
, &no_ip_route_mask_flags_cmd
);
2070 install_element (CONFIG_NODE
, &no_ip_route_mask_flags2_cmd
);
2071 install_element (CONFIG_NODE
, &ip_route_distance_cmd
);
2072 install_element (CONFIG_NODE
, &ip_route_flags_distance_cmd
);
2073 install_element (CONFIG_NODE
, &ip_route_flags_distance2_cmd
);
2074 install_element (CONFIG_NODE
, &ip_route_mask_distance_cmd
);
2075 install_element (CONFIG_NODE
, &ip_route_mask_flags_distance_cmd
);
2076 install_element (CONFIG_NODE
, &ip_route_mask_flags_distance2_cmd
);
2077 install_element (CONFIG_NODE
, &no_ip_route_distance_cmd
);
2078 install_element (CONFIG_NODE
, &no_ip_route_flags_distance_cmd
);
2079 install_element (CONFIG_NODE
, &no_ip_route_flags_distance2_cmd
);
2080 install_element (CONFIG_NODE
, &no_ip_route_mask_flags_distance_cmd
);
2081 install_element (CONFIG_NODE
, &no_ip_route_mask_flags_distance2_cmd
);
2083 install_element (VIEW_NODE
, &show_ip_route_cmd
);
2084 install_element (VIEW_NODE
, &show_ip_route_addr_cmd
);
2085 install_element (VIEW_NODE
, &show_ip_route_prefix_cmd
);
2086 install_element (VIEW_NODE
, &show_ip_route_prefix_longer_cmd
);
2087 install_element (VIEW_NODE
, &show_ip_route_protocol_cmd
);
2088 install_element (VIEW_NODE
, &show_ip_route_supernets_cmd
);
2089 install_element (VIEW_NODE
, &show_ip_route_summary_cmd
);
2090 install_element (ENABLE_NODE
, &show_ip_route_cmd
);
2091 install_element (ENABLE_NODE
, &show_ip_route_addr_cmd
);
2092 install_element (ENABLE_NODE
, &show_ip_route_prefix_cmd
);
2093 install_element (ENABLE_NODE
, &show_ip_route_prefix_longer_cmd
);
2094 install_element (ENABLE_NODE
, &show_ip_route_protocol_cmd
);
2095 install_element (ENABLE_NODE
, &show_ip_route_supernets_cmd
);
2096 install_element (ENABLE_NODE
, &show_ip_route_summary_cmd
);
2098 install_element (VIEW_NODE
, &show_ip_mroute_cmd
);
2099 install_element (ENABLE_NODE
, &show_ip_mroute_cmd
);
2103 install_element (CONFIG_NODE
, &ipv6_route_cmd
);
2104 install_element (CONFIG_NODE
, &ipv6_route_flags_cmd
);
2105 install_element (CONFIG_NODE
, &ipv6_route_ifname_cmd
);
2106 install_element (CONFIG_NODE
, &ipv6_route_ifname_flags_cmd
);
2107 install_element (CONFIG_NODE
, &no_ipv6_route_cmd
);
2108 install_element (CONFIG_NODE
, &no_ipv6_route_flags_cmd
);
2109 install_element (CONFIG_NODE
, &no_ipv6_route_ifname_cmd
);
2110 install_element (CONFIG_NODE
, &no_ipv6_route_ifname_flags_cmd
);
2111 install_element (CONFIG_NODE
, &ipv6_route_pref_cmd
);
2112 install_element (CONFIG_NODE
, &ipv6_route_flags_pref_cmd
);
2113 install_element (CONFIG_NODE
, &ipv6_route_ifname_pref_cmd
);
2114 install_element (CONFIG_NODE
, &ipv6_route_ifname_flags_pref_cmd
);
2115 install_element (CONFIG_NODE
, &no_ipv6_route_pref_cmd
);
2116 install_element (CONFIG_NODE
, &no_ipv6_route_flags_pref_cmd
);
2117 install_element (CONFIG_NODE
, &no_ipv6_route_ifname_pref_cmd
);
2118 install_element (CONFIG_NODE
, &no_ipv6_route_ifname_flags_pref_cmd
);
2119 install_element (VIEW_NODE
, &show_ipv6_route_cmd
);
2120 install_element (VIEW_NODE
, &show_ipv6_route_summary_cmd
);
2121 install_element (VIEW_NODE
, &show_ipv6_route_protocol_cmd
);
2122 install_element (VIEW_NODE
, &show_ipv6_route_addr_cmd
);
2123 install_element (VIEW_NODE
, &show_ipv6_route_prefix_cmd
);
2124 install_element (VIEW_NODE
, &show_ipv6_route_prefix_longer_cmd
);
2125 install_element (ENABLE_NODE
, &show_ipv6_route_cmd
);
2126 install_element (ENABLE_NODE
, &show_ipv6_route_protocol_cmd
);
2127 install_element (ENABLE_NODE
, &show_ipv6_route_addr_cmd
);
2128 install_element (ENABLE_NODE
, &show_ipv6_route_prefix_cmd
);
2129 install_element (ENABLE_NODE
, &show_ipv6_route_prefix_longer_cmd
);
2130 install_element (ENABLE_NODE
, &show_ipv6_route_summary_cmd
);
2132 install_element (VIEW_NODE
, &show_ipv6_mroute_cmd
);
2133 install_element (ENABLE_NODE
, &show_ipv6_mroute_cmd
);
2134 #endif /* HAVE_IPV6 */