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.
25 #include "zebra_memory.h"
35 #include "srcdest_table.h"
37 #include "zebra/zserv.h"
38 #include "zebra/zebra_vrf.h"
39 #include "zebra/zebra_mpls.h"
40 #include "zebra/zebra_rnh.h"
41 #include "zebra/redistribute.h"
42 #include "zebra/zebra_routemap.h"
43 #include "zebra/zebra_static.h"
46 extern int allow_delete
;
48 static int do_show_ip_route(struct vty
*vty
, const char *vrf_name
,
49 safi_t safi
, bool use_fib
, u_char use_json
);
50 static void vty_show_ip_route_detail (struct vty
*vty
, struct route_node
*rn
,
53 #define ONE_DAY_SECOND 60*60*24
54 #define ONE_WEEK_SECOND 60*60*24*7
56 /* General function for static route. */
58 zebra_static_ipv4 (struct vty
*vty
, safi_t safi
, int add_cmd
,
59 const char *dest_str
, const char *mask_str
,
60 const char *gate_str
, const char *flag_str
,
61 const char *tag_str
, const char *distance_str
,
62 const char *vrf_id_str
, const char *label_str
)
71 struct zebra_vrf
*zvrf
= NULL
;
72 unsigned int ifindex
= 0;
73 const char *ifname
= NULL
;
74 u_char type
= STATIC_BLACKHOLE
;
75 struct static_nh_label snh_label
;
77 memset (&snh_label
, 0, sizeof (struct static_nh_label
));
78 ret
= str2prefix (dest_str
, &p
);
81 vty_out (vty
, "%% Malformed address%s", VTY_NEWLINE
);
85 /* Cisco like mask notation. */
88 ret
= inet_aton (mask_str
, &mask
);
91 vty_out (vty
, "%% Malformed address%s", VTY_NEWLINE
);
94 p
.prefixlen
= ip_masklen (mask
);
97 /* Apply mask for given prefix. */
100 /* Administrative distance. */
102 distance
= atoi (distance_str
);
104 distance
= ZEBRA_STATIC_DISTANCE_DEFAULT
;
108 VTY_GET_INTEGER_RANGE("tag", tag
, tag_str
, 0, 4294967295);
111 zvrf
= zebra_vrf_lookup_by_name (vrf_id_str
);
115 vty_out (vty
, "%% vrf %s is not defined%s", vrf_id_str
, VTY_NEWLINE
);
124 vty_out (vty
, "%% MPLS not turned on in kernel, ignoring command%s",
128 if (mpls_str2label (label_str
, &snh_label
.num_labels
,
131 vty_out (vty
, "%% Malformed label(s)%s", VTY_NEWLINE
);
136 /* Null0 static route. */
137 if ((gate_str
!= NULL
) && (strncasecmp (gate_str
, "Null0", strlen (gate_str
)) == 0))
141 vty_out (vty
, "%% can not have flag %s with Null0%s", flag_str
, VTY_NEWLINE
);
145 static_add_route (AFI_IP
, safi
, type
, &p
, NULL
, NULL
, ifindex
, ifname
,
146 ZEBRA_FLAG_BLACKHOLE
, tag
, distance
, zvrf
, &snh_label
);
148 static_delete_route (AFI_IP
, safi
, type
, &p
, NULL
, NULL
, ifindex
, tag
,
149 distance
, zvrf
, &snh_label
);
155 switch(flag_str
[0]) {
158 SET_FLAG (flag
, ZEBRA_FLAG_REJECT
);
162 SET_FLAG (flag
, ZEBRA_FLAG_BLACKHOLE
);
165 vty_out (vty
, "%% Malformed flag %s %s", flag_str
, VTY_NEWLINE
);
170 if (gate_str
== NULL
)
173 static_add_route (AFI_IP
, safi
, type
, &p
, NULL
, NULL
, ifindex
, ifname
, flag
,
174 tag
, distance
, zvrf
, &snh_label
);
176 static_delete_route (AFI_IP
, safi
, type
, &p
, NULL
, NULL
, ifindex
, tag
, distance
,
182 /* When gateway is A.B.C.D format, gate is treated as nexthop
183 address other case gate is treated as interface name. */
184 ret
= inet_aton (gate_str
, &gate
);
187 struct interface
*ifp
= if_lookup_by_name (gate_str
, zvrf_id (zvrf
));
190 vty_out (vty
, "%% Unknown interface: %s%s", gate_str
, VTY_NEWLINE
);
191 ifindex
= IFINDEX_DELETED
;
194 ifindex
= ifp
->ifindex
;
196 type
= STATIC_IFINDEX
;
199 type
= STATIC_IPV4_GATEWAY
;
202 static_add_route (AFI_IP
, safi
, type
, &p
, NULL
,
203 ifindex
? NULL
: (union g_addr
*)&gate
, ifindex
, ifname
,
204 flag
, tag
, distance
, zvrf
, &snh_label
);
206 static_delete_route (AFI_IP
, safi
, type
, &p
, NULL
,
207 ifindex
? NULL
: (union g_addr
*)&gate
, ifindex
, tag
,
208 distance
, zvrf
, &snh_label
);
213 /* Static unicast routes for multicast RPF lookup. */
214 DEFUN (ip_mroute_dist
,
216 "ip mroute A.B.C.D/M <A.B.C.D|INTERFACE> [(1-255)]",
218 "Configure static unicast route into MRIB for multicast RPF lookup\n"
219 "IP destination prefix (e.g. 10.0.0.0/8)\n"
221 "Nexthop interface name\n"
224 char *destprefix
= argv
[2]->arg
;
225 char *nexthop
= argv
[3]->arg
;
226 char *distance
= (argc
== 5) ? argv
[4]->arg
: NULL
;
228 return zebra_static_ipv4 (vty
, SAFI_MULTICAST
, 1, destprefix
, NULL
, nexthop
, NULL
, NULL
, distance
, NULL
, NULL
);
231 DEFUN (no_ip_mroute_dist
,
232 no_ip_mroute_dist_cmd
,
233 "no ip mroute A.B.C.D/M <A.B.C.D|INTERFACE> [(1-255)]",
236 "Configure static unicast route into MRIB for multicast RPF lookup\n"
237 "IP destination prefix (e.g. 10.0.0.0/8)\n"
239 "Nexthop interface name\n"
242 char *destprefix
= argv
[3]->arg
;
243 char *nexthop
= argv
[4]->arg
;
244 char *distance
= (argc
== 6) ? argv
[5]->arg
: NULL
;
246 return zebra_static_ipv4 (vty
, SAFI_MULTICAST
, 0, destprefix
, NULL
, nexthop
, NULL
, NULL
, distance
, NULL
, NULL
);
249 DEFUN (ip_multicast_mode
,
250 ip_multicast_mode_cmd
,
251 "ip multicast rpf-lookup-mode <urib-only|mrib-only|mrib-then-urib|lower-distance|longer-prefix>",
253 "Multicast options\n"
254 "RPF lookup behavior\n"
255 "Lookup in unicast RIB only\n"
256 "Lookup in multicast RIB only\n"
257 "Try multicast RIB first, fall back to unicast RIB\n"
258 "Lookup both, use entry with lower distance\n"
259 "Lookup both, use entry with longer prefix\n")
261 char *mode
= argv
[3]->text
;
263 if (strmatch (mode
, "urib-only"))
264 multicast_mode_ipv4_set (MCAST_URIB_ONLY
);
265 else if (strmatch (mode
, "mrib-only"))
266 multicast_mode_ipv4_set (MCAST_MRIB_ONLY
);
267 else if (strmatch (mode
, "mrib-then-urib"))
268 multicast_mode_ipv4_set (MCAST_MIX_MRIB_FIRST
);
269 else if (strmatch (mode
, "lower-distance"))
270 multicast_mode_ipv4_set (MCAST_MIX_DISTANCE
);
271 else if (strmatch (mode
, "longer-prefix"))
272 multicast_mode_ipv4_set (MCAST_MIX_PFXLEN
);
275 vty_out (vty
, "Invalid mode specified%s", VTY_NEWLINE
);
282 DEFUN (no_ip_multicast_mode
,
283 no_ip_multicast_mode_cmd
,
284 "no ip multicast rpf-lookup-mode [<urib-only|mrib-only|mrib-then-urib|lower-distance|longer-prefix>]",
287 "Multicast options\n"
288 "RPF lookup behavior\n"
289 "Lookup in unicast RIB only\n"
290 "Lookup in multicast RIB only\n"
291 "Try multicast RIB first, fall back to unicast RIB\n"
292 "Lookup both, use entry with lower distance\n"
293 "Lookup both, use entry with longer prefix\n")
295 multicast_mode_ipv4_set (MCAST_NO_CONFIG
);
305 "Display RPF information for multicast source\n")
307 return do_show_ip_route(vty
, VRF_DEFAULT_NAME
, SAFI_MULTICAST
, false, 0);
310 DEFUN (show_ip_rpf_addr
,
311 show_ip_rpf_addr_cmd
,
312 "show ip rpf A.B.C.D",
315 "Display RPF information for multicast source\n"
316 "IP multicast source address (e.g. 10.0.0.0)\n")
320 struct route_node
*rn
;
324 ret
= inet_aton (argv
[idx_ipv4
]->arg
, &addr
);
327 vty_out (vty
, "%% Malformed address%s", VTY_NEWLINE
);
331 rib
= rib_match_ipv4_multicast (VRF_DEFAULT
, addr
, &rn
);
334 vty_show_ip_route_detail (vty
, rn
, 1);
336 vty_out (vty
, "%% No match for RPF lookup%s", VTY_NEWLINE
);
342 zebra_vty_ip_route_tdv_helper (int argc
, struct cmd_token
*argv
[],
343 int idx_curr
, char **tag
,
344 char **distance
, char **vrf
, char **labels
)
347 while (idx_curr
< argc
)
349 if (strmatch (argv
[idx_curr
]->text
, "tag"))
352 *tag
= argv
[idx_curr
+1]->arg
;
355 else if (strmatch (argv
[idx_curr
]->text
, "vrf"))
358 *vrf
= argv
[idx_curr
+1]->arg
;
361 else if (strmatch (argv
[idx_curr
]->text
, "label"))
364 *labels
= argv
[idx_curr
+1]->arg
;
370 *distance
= argv
[idx_curr
]->arg
;
378 /* Static route configuration. */
381 "ip route A.B.C.D/M <A.B.C.D|INTERFACE|null0> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
383 "Establish static routes\n"
384 "IP destination prefix (e.g. 10.0.0.0/8)\n"
385 "IP gateway address\n"
386 "IP gateway interface name\n"
388 "Set tag for this route\n"
390 "Distance value for this route\n"
393 int idx_ipv4_prefixlen
= 2;
394 int idx_ipv4_ifname_null
= 3;
396 char *tag
, *distance
, *vrf
;
398 tag
= distance
= vrf
= NULL
;
399 zebra_vty_ip_route_tdv_helper (argc
, argv
, idx_curr
, &tag
, &distance
, &vrf
, NULL
);
401 return zebra_static_ipv4 (vty
, SAFI_UNICAST
, 1,
402 argv
[idx_ipv4_prefixlen
]->arg
,
404 argv
[idx_ipv4_ifname_null
]->arg
,
406 tag
, distance
, vrf
, NULL
);
409 DEFUN (ip_route_flags
,
411 "ip route A.B.C.D/M <reject|blackhole> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
413 "Establish static routes\n"
414 "IP destination prefix (e.g. 10.0.0.0/8)\n"
415 "Emit an ICMP unreachable when matched\n"
416 "Silently discard pkts when matched\n"
417 "Set tag for this route\n"
419 "Distance value for this route\n"
421 "Specify labels for this route\n"
422 "One or more labels separated by '/'\n")
424 int idx_ipv4_prefixlen
= 2;
425 int idx_reject_blackhole
= 3;
427 char *tag
, *distance
, *vrf
;
429 tag
= distance
= vrf
= NULL
;
430 zebra_vty_ip_route_tdv_helper (argc
, argv
, idx_curr
, &tag
, &distance
, &vrf
, NULL
);
432 return zebra_static_ipv4 (vty
, SAFI_UNICAST
, 1,
433 argv
[idx_ipv4_prefixlen
]->arg
,
436 argv
[idx_reject_blackhole
]->arg
,
437 tag
, distance
, vrf
, NULL
);
440 /* Mask as A.B.C.D format. */
441 DEFUN (ip_route_mask
,
443 "ip route A.B.C.D A.B.C.D <A.B.C.D|INTERFACE|null0> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
445 "Establish static routes\n"
446 "IP destination prefix\n"
447 "IP destination prefix mask\n"
448 "IP gateway address\n"
449 "IP gateway interface name\n"
451 "Set tag for this route\n"
453 "Distance value for this route\n"
455 "Specify labels for this route\n"
456 "One or more labels separated by '/'\n")
460 int idx_ipv4_ifname_null
= 4;
462 char *tag
, *distance
, *vrf
;
464 tag
= distance
= vrf
= NULL
;
465 zebra_vty_ip_route_tdv_helper (argc
, argv
, idx_curr
, &tag
, &distance
, &vrf
, NULL
);
467 return zebra_static_ipv4 (vty
, SAFI_UNICAST
, 1,
469 argv
[idx_ipv4_2
]->arg
,
470 argv
[idx_ipv4_ifname_null
]->arg
,
471 NULL
, tag
, distance
, vrf
, NULL
);
474 DEFUN (ip_route_mask_flags
,
475 ip_route_mask_flags_cmd
,
476 "ip route A.B.C.D A.B.C.D <reject|blackhole> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
478 "Establish static routes\n"
479 "IP destination prefix\n"
480 "IP destination prefix mask\n"
481 "Emit an ICMP unreachable when matched\n"
482 "Silently discard pkts when matched\n"
483 "Set tag for this route\n"
485 "Distance value for this route\n"
487 "Specify labels for this route\n"
488 "One or more labels separated by '/'\n")
492 int idx_reject_blackhole
= 4;
494 char *tag
, *distance
, *vrf
;
496 tag
= distance
= vrf
= NULL
;
497 zebra_vty_ip_route_tdv_helper (argc
, argv
, idx_curr
, &tag
, &distance
, &vrf
, NULL
);
499 return zebra_static_ipv4 (vty
, SAFI_UNICAST
, 1,
501 argv
[idx_ipv4_2
]->arg
,
503 argv
[idx_reject_blackhole
]->arg
,
504 tag
, distance
, vrf
, NULL
);
509 "no ip route A.B.C.D/M <A.B.C.D|INTERFACE|null0> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
512 "Establish static routes\n"
513 "IP destination prefix (e.g. 10.0.0.0/8)\n"
514 "IP gateway address\n"
515 "IP gateway interface name\n"
517 "Tag of this route\n"
519 "Distance value for this route\n"
521 "Specify labels for this route\n"
522 "One or more labels separated by '/'\n")
524 int idx_ipv4_prefixlen
= 3;
525 int idx_ipv4_ifname_null
= 4;
527 char *tag
, *distance
, *vrf
;
529 tag
= distance
= vrf
= NULL
;
530 zebra_vty_ip_route_tdv_helper (argc
, argv
, idx_curr
, &tag
, &distance
, &vrf
, NULL
);
532 return zebra_static_ipv4 (vty
, SAFI_UNICAST
, 0,
533 argv
[idx_ipv4_prefixlen
]->arg
,
535 argv
[idx_ipv4_ifname_null
]->arg
,
537 tag
, distance
, vrf
, NULL
);
540 DEFUN (no_ip_route_flags
,
541 no_ip_route_flags_cmd
,
542 "no ip route A.B.C.D/M <reject|blackhole> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
545 "Establish static routes\n"
546 "IP destination prefix (e.g. 10.0.0.0/8)\n"
547 "Emit an ICMP unreachable when matched\n"
548 "Silently discard pkts when matched\n"
549 "Tag of this route\n"
551 "Distance value for this route\n"
553 "Specify labels for this route\n"
554 "One or more labels separated by '/'\n")
556 int idx_ipv4_prefixlen
= 3;
558 char *tag
, *distance
, *vrf
;
560 tag
= distance
= vrf
= NULL
;
561 zebra_vty_ip_route_tdv_helper (argc
, argv
, idx_curr
, &tag
, &distance
, &vrf
, NULL
);
563 return zebra_static_ipv4 (vty
, SAFI_UNICAST
, 0,
564 argv
[idx_ipv4_prefixlen
]->arg
,
566 tag
, distance
, vrf
, NULL
);
569 DEFUN (no_ip_route_mask
,
570 no_ip_route_mask_cmd
,
571 "no ip route A.B.C.D A.B.C.D <A.B.C.D|INTERFACE|null0> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
574 "Establish static routes\n"
575 "IP destination prefix\n"
576 "IP destination prefix mask\n"
577 "IP gateway address\n"
578 "IP gateway interface name\n"
580 "Tag of this route\n"
582 "Distance value for this route\n"
584 "Specify labels for this route\n"
585 "One or more labels separated by '/'\n")
589 int idx_ipv4_ifname_null
= 5;
591 char *tag
, *distance
, *vrf
;
593 tag
= distance
= vrf
= NULL
;
594 zebra_vty_ip_route_tdv_helper (argc
, argv
, idx_curr
, &tag
, &distance
, &vrf
, NULL
);
596 return zebra_static_ipv4 (vty
, SAFI_UNICAST
, 0,
598 argv
[idx_ipv4_2
]->arg
,
599 argv
[idx_ipv4_ifname_null
]->arg
,
601 tag
, distance
, vrf
, NULL
);
604 DEFUN (no_ip_route_mask_flags
,
605 no_ip_route_mask_flags_cmd
,
606 "no ip route A.B.C.D A.B.C.D <reject|blackhole> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
609 "Establish static routes\n"
610 "IP destination prefix\n"
611 "IP destination prefix mask\n"
612 "Emit an ICMP unreachable when matched\n"
613 "Silently discard pkts when matched\n"
614 "Tag of this route\n"
616 "Distance value for this route\n"
618 "Specify labels for this route\n"
619 "One or more labels separated by '/'\n")
624 char *tag
, *distance
, *vrf
;
626 tag
= distance
= vrf
= NULL
;
627 zebra_vty_ip_route_tdv_helper (argc
, argv
, idx_curr
, &tag
, &distance
, &vrf
, NULL
);
629 return zebra_static_ipv4 (vty
, SAFI_UNICAST
, 0,
631 argv
[idx_ipv4_2
]->arg
,
633 tag
, distance
, vrf
, NULL
);
636 /* New RIB. Detailed information for IPv4 route. */
638 vty_show_ip_route_detail (struct vty
*vty
, struct route_node
*rn
, int mcast
)
641 struct nexthop
*nexthop
, *tnexthop
;
643 char buf
[SRCDEST2STR_BUFFER
];
644 struct zebra_vrf
*zvrf
;
646 RNODE_FOREACH_RIB (rn
, rib
)
648 const char *mcast_info
= "";
651 rib_table_info_t
*info
= srcdest_rnode_table_info(rn
);
652 mcast_info
= (info
->safi
== SAFI_MULTICAST
)
653 ? " using Multicast RIB"
654 : " using Unicast RIB";
657 vty_out (vty
, "Routing entry for %s%s%s",
658 srcdest_rnode2str(rn
, buf
, sizeof(buf
)), mcast_info
,
660 vty_out (vty
, " Known via \"%s", zebra_route_string (rib
->type
));
662 vty_out (vty
, "[%d]", rib
->instance
);
664 vty_out (vty
, ", distance %u, metric %u", rib
->distance
, rib
->metric
);
666 vty_out (vty
, ", tag %d", rib
->tag
);
668 vty_out (vty
, ", mtu %u", rib
->mtu
);
669 if (rib
->vrf_id
!= VRF_DEFAULT
)
671 zvrf
= vrf_info_lookup(rib
->vrf_id
);
672 vty_out (vty
, ", vrf %s", zvrf_name (zvrf
));
674 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_SELECTED
))
675 vty_out (vty
, ", best");
677 vty_out (vty
, ", refcnt %ld", rib
->refcnt
);
678 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_BLACKHOLE
))
679 vty_out (vty
, ", blackhole");
680 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_REJECT
))
681 vty_out (vty
, ", reject");
682 vty_out (vty
, "%s", VTY_NEWLINE
);
684 if (rib
->type
== ZEBRA_ROUTE_RIP
685 || rib
->type
== ZEBRA_ROUTE_OSPF
686 || rib
->type
== ZEBRA_ROUTE_ISIS
687 || rib
->type
== ZEBRA_ROUTE_NHRP
688 || rib
->type
== ZEBRA_ROUTE_TABLE
689 || rib
->type
== ZEBRA_ROUTE_BGP
)
694 uptime
= time (NULL
);
695 uptime
-= rib
->uptime
;
696 tm
= gmtime (&uptime
);
698 vty_out (vty
, " Last update ");
700 if (uptime
< ONE_DAY_SECOND
)
701 vty_out (vty
, "%02d:%02d:%02d",
702 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
703 else if (uptime
< ONE_WEEK_SECOND
)
704 vty_out (vty
, "%dd%02dh%02dm",
705 tm
->tm_yday
, tm
->tm_hour
, tm
->tm_min
);
707 vty_out (vty
, "%02dw%dd%02dh",
709 tm
->tm_yday
- ((tm
->tm_yday
/7) * 7), tm
->tm_hour
);
710 vty_out (vty
, " ago%s", VTY_NEWLINE
);
713 for (ALL_NEXTHOPS_RO(rib
->nexthop
, nexthop
, tnexthop
, recursing
))
717 vty_out (vty
, " %c%s",
718 CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
) ? '*' : ' ',
719 recursing
? " " : "");
721 switch (nexthop
->type
)
723 case NEXTHOP_TYPE_IPV4
:
724 case NEXTHOP_TYPE_IPV4_IFINDEX
:
725 vty_out (vty
, " %s", inet_ntoa (nexthop
->gate
.ipv4
));
726 if (nexthop
->ifindex
)
727 vty_out (vty
, ", via %s",
728 ifindex2ifname (nexthop
->ifindex
, rib
->vrf_id
));
730 case NEXTHOP_TYPE_IPV6
:
731 case NEXTHOP_TYPE_IPV6_IFINDEX
:
733 inet_ntop (AF_INET6
, &nexthop
->gate
.ipv6
, buf
, BUFSIZ
));
734 if (nexthop
->ifindex
)
735 vty_out (vty
, ", via %s",
736 ifindex2ifname (nexthop
->ifindex
, rib
->vrf_id
));
738 case NEXTHOP_TYPE_IFINDEX
:
739 vty_out (vty
, " directly connected, %s",
740 ifindex2ifname (nexthop
->ifindex
, rib
->vrf_id
));
742 case NEXTHOP_TYPE_BLACKHOLE
:
743 vty_out (vty
, " directly connected, Null0");
748 if (! CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
))
749 vty_out (vty
, " inactive");
751 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_ONLINK
))
752 vty_out (vty
, " onlink");
754 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_RECURSIVE
))
755 vty_out (vty
, " (recursive)");
757 switch (nexthop
->type
)
759 case NEXTHOP_TYPE_IPV4
:
760 case NEXTHOP_TYPE_IPV4_IFINDEX
:
761 if (nexthop
->src
.ipv4
.s_addr
)
763 if (inet_ntop(AF_INET
, &nexthop
->src
.ipv4
, addrstr
,
765 vty_out (vty
, ", src %s", addrstr
);
768 case NEXTHOP_TYPE_IPV6
:
769 case NEXTHOP_TYPE_IPV6_IFINDEX
:
770 if (!IPV6_ADDR_SAME(&nexthop
->src
.ipv6
, &in6addr_any
))
772 if (inet_ntop(AF_INET6
, &nexthop
->src
.ipv6
, addrstr
,
774 vty_out (vty
, ", src %s", addrstr
);
781 /* Label information */
782 if (nexthop
->nh_label
&& nexthop
->nh_label
->num_labels
)
784 vty_out (vty
, ", label %s",
785 mpls_label2str (nexthop
->nh_label
->num_labels
,
786 nexthop
->nh_label
->label
, buf
, BUFSIZ
, 1));
789 vty_out (vty
, "%s", VTY_NEWLINE
);
791 vty_out (vty
, "%s", VTY_NEWLINE
);
796 vty_show_ip_route (struct vty
*vty
, struct route_node
*rn
, struct rib
*rib
,
799 struct nexthop
*nexthop
, *tnexthop
;
802 char buf
[SRCDEST2STR_BUFFER
];
803 json_object
*json_nexthops
= NULL
;
804 json_object
*json_nexthop
= NULL
;
805 json_object
*json_route
= NULL
;
806 json_object
*json_labels
= NULL
;
810 json_route
= json_object_new_object();
811 json_nexthops
= json_object_new_array();
813 json_object_string_add(json_route
, "prefix", srcdest_rnode2str (rn
, buf
, sizeof buf
));
814 json_object_string_add(json_route
, "protocol", zebra_route_string(rib
->type
));
817 json_object_int_add(json_route
, "instance", rib
->instance
);
820 json_object_int_add(json_route
, "vrfId", rib
->vrf_id
);
822 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_SELECTED
))
823 json_object_boolean_true_add(json_route
, "selected");
825 if (rib
->type
!= ZEBRA_ROUTE_CONNECT
&& rib
->type
!= ZEBRA_ROUTE_KERNEL
)
827 json_object_int_add(json_route
, "distance", rib
->distance
);
828 json_object_int_add(json_route
, "metric", rib
->metric
);
831 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_BLACKHOLE
))
832 json_object_boolean_true_add(json_route
, "blackhole");
834 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_REJECT
))
835 json_object_boolean_true_add(json_route
, "reject");
837 if (rib
->type
== ZEBRA_ROUTE_RIP
838 || rib
->type
== ZEBRA_ROUTE_OSPF
839 || rib
->type
== ZEBRA_ROUTE_ISIS
840 || rib
->type
== ZEBRA_ROUTE_NHRP
841 || rib
->type
== ZEBRA_ROUTE_TABLE
842 || rib
->type
== ZEBRA_ROUTE_BGP
)
847 uptime
= time (NULL
);
848 uptime
-= rib
->uptime
;
849 tm
= gmtime (&uptime
);
851 if (uptime
< ONE_DAY_SECOND
)
852 sprintf(buf
, "%02d:%02d:%02d", tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
853 else if (uptime
< ONE_WEEK_SECOND
)
854 sprintf(buf
, "%dd%02dh%02dm", tm
->tm_yday
, tm
->tm_hour
, tm
->tm_min
);
856 sprintf(buf
, "%02dw%dd%02dh", tm
->tm_yday
/7, tm
->tm_yday
- ((tm
->tm_yday
/7) * 7), tm
->tm_hour
);
858 json_object_string_add(json_route
, "uptime", buf
);
861 for (ALL_NEXTHOPS_RO(rib
->nexthop
, nexthop
, tnexthop
, recursing
))
863 json_nexthop
= json_object_new_object();
865 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
))
866 json_object_boolean_true_add(json_nexthop
, "fib");
868 switch (nexthop
->type
)
870 case NEXTHOP_TYPE_IPV4
:
871 case NEXTHOP_TYPE_IPV4_IFINDEX
:
872 json_object_string_add(json_nexthop
, "ip", inet_ntoa (nexthop
->gate
.ipv4
));
873 json_object_string_add(json_nexthop
, "afi", "ipv4");
875 if (nexthop
->ifindex
)
877 json_object_int_add(json_nexthop
, "interfaceIndex", nexthop
->ifindex
);
878 json_object_string_add(json_nexthop
, "interfaceName", ifindex2ifname (nexthop
->ifindex
, rib
->vrf_id
));
881 case NEXTHOP_TYPE_IPV6
:
882 case NEXTHOP_TYPE_IPV6_IFINDEX
:
883 json_object_string_add(json_nexthop
, "ip", inet_ntop (AF_INET6
, &nexthop
->gate
.ipv6
, buf
, BUFSIZ
));
884 json_object_string_add(json_nexthop
, "afi", "ipv6");
886 if (nexthop
->ifindex
)
888 json_object_int_add(json_nexthop
, "interfaceIndex", nexthop
->ifindex
);
889 json_object_string_add(json_nexthop
, "interfaceName", ifindex2ifname (nexthop
->ifindex
, rib
->vrf_id
));
893 case NEXTHOP_TYPE_IFINDEX
:
894 json_object_boolean_true_add(json_nexthop
, "directlyConnected");
895 json_object_int_add(json_nexthop
, "interfaceIndex", nexthop
->ifindex
);
896 json_object_string_add(json_nexthop
, "interfaceName", ifindex2ifname (nexthop
->ifindex
, rib
->vrf_id
));
898 case NEXTHOP_TYPE_BLACKHOLE
:
899 json_object_boolean_true_add(json_nexthop
, "blackhole");
905 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
))
906 json_object_boolean_true_add(json_nexthop
, "active");
908 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_ONLINK
))
909 json_object_boolean_true_add(json_nexthop
, "onLink");
911 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_RECURSIVE
))
912 json_object_boolean_true_add(json_nexthop
, "recursive");
914 switch (nexthop
->type
)
916 case NEXTHOP_TYPE_IPV4
:
917 case NEXTHOP_TYPE_IPV4_IFINDEX
:
918 if (nexthop
->src
.ipv4
.s_addr
)
920 if (inet_ntop(AF_INET
, &nexthop
->src
.ipv4
, buf
, sizeof buf
))
921 json_object_string_add(json_nexthop
, "source", buf
);
924 case NEXTHOP_TYPE_IPV6
:
925 case NEXTHOP_TYPE_IPV6_IFINDEX
:
926 if (!IPV6_ADDR_SAME(&nexthop
->src
.ipv6
, &in6addr_any
))
928 if (inet_ntop(AF_INET6
, &nexthop
->src
.ipv6
, buf
, sizeof buf
))
929 json_object_string_add(json_nexthop
, "source", buf
);
936 if (nexthop
->nh_label
&& nexthop
->nh_label
->num_labels
)
938 json_labels
= json_object_new_array();
940 for (int label_index
= 0; label_index
< nexthop
->nh_label
->num_labels
; label_index
++)
941 json_object_array_add(json_labels
, json_object_new_int(nexthop
->nh_label
->label
[label_index
]));
943 json_object_object_add(json_nexthop
, "labels", json_labels
);
946 json_object_array_add(json_nexthops
, json_nexthop
);
949 json_object_object_add(json_route
, "nexthops", json_nexthops
);
950 json_object_array_add(json
, json_route
);
954 /* Nexthop information. */
955 for (ALL_NEXTHOPS_RO(rib
->nexthop
, nexthop
, tnexthop
, recursing
))
957 if (nexthop
== rib
->nexthop
)
959 /* Prefix information. */
960 len
= vty_out (vty
, "%c", zebra_route_char (rib
->type
));
962 len
+= vty_out (vty
, "[%d]", rib
->instance
);
963 len
+= vty_out (vty
, "%c%c %s",
964 CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_SELECTED
)
966 CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
)
968 srcdest_rnode2str (rn
, buf
, sizeof buf
));
970 /* Distance and metric display. */
971 if (rib
->type
!= ZEBRA_ROUTE_CONNECT
972 && rib
->type
!= ZEBRA_ROUTE_KERNEL
)
973 len
+= vty_out (vty
, " [%d/%d]", rib
->distance
,
977 vty_out (vty
, " %c%*c",
978 CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
)
980 len
- 3 + (2 * recursing
), ' ');
982 switch (nexthop
->type
)
984 case NEXTHOP_TYPE_IPV4
:
985 case NEXTHOP_TYPE_IPV4_IFINDEX
:
986 vty_out (vty
, " via %s", inet_ntoa (nexthop
->gate
.ipv4
));
987 if (nexthop
->ifindex
)
988 vty_out (vty
, ", %s",
989 ifindex2ifname (nexthop
->ifindex
, rib
->vrf_id
));
991 case NEXTHOP_TYPE_IPV6
:
992 case NEXTHOP_TYPE_IPV6_IFINDEX
:
993 vty_out (vty
, " via %s",
994 inet_ntop (AF_INET6
, &nexthop
->gate
.ipv6
, buf
, BUFSIZ
));
995 if (nexthop
->ifindex
)
996 vty_out (vty
, ", %s",
997 ifindex2ifname (nexthop
->ifindex
, rib
->vrf_id
));
1000 case NEXTHOP_TYPE_IFINDEX
:
1001 vty_out (vty
, " is directly connected, %s",
1002 ifindex2ifname (nexthop
->ifindex
, rib
->vrf_id
));
1004 case NEXTHOP_TYPE_BLACKHOLE
:
1005 vty_out (vty
, " is directly connected, Null0");
1010 if (! CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
))
1011 vty_out (vty
, " inactive");
1013 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_ONLINK
))
1014 vty_out (vty
, " onlink");
1016 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_RECURSIVE
))
1017 vty_out (vty
, " (recursive)");
1019 switch (nexthop
->type
)
1021 case NEXTHOP_TYPE_IPV4
:
1022 case NEXTHOP_TYPE_IPV4_IFINDEX
:
1023 if (nexthop
->src
.ipv4
.s_addr
)
1025 if (inet_ntop(AF_INET
, &nexthop
->src
.ipv4
, buf
, sizeof buf
))
1026 vty_out (vty
, ", src %s", buf
);
1029 case NEXTHOP_TYPE_IPV6
:
1030 case NEXTHOP_TYPE_IPV6_IFINDEX
:
1031 if (!IPV6_ADDR_SAME(&nexthop
->src
.ipv6
, &in6addr_any
))
1033 if (inet_ntop(AF_INET6
, &nexthop
->src
.ipv6
, buf
, sizeof buf
))
1034 vty_out (vty
, ", src %s", buf
);
1041 /* Label information */
1042 if (nexthop
->nh_label
&& nexthop
->nh_label
->num_labels
)
1044 vty_out (vty
, ", label %s",
1045 mpls_label2str (nexthop
->nh_label
->num_labels
,
1046 nexthop
->nh_label
->label
, buf
, BUFSIZ
, 1));
1049 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_BLACKHOLE
))
1050 vty_out (vty
, ", bh");
1051 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_REJECT
))
1052 vty_out (vty
, ", rej");
1054 if (rib
->type
== ZEBRA_ROUTE_RIP
1055 || rib
->type
== ZEBRA_ROUTE_OSPF
1056 || rib
->type
== ZEBRA_ROUTE_ISIS
1057 || rib
->type
== ZEBRA_ROUTE_NHRP
1058 || rib
->type
== ZEBRA_ROUTE_TABLE
1059 || rib
->type
== ZEBRA_ROUTE_BGP
)
1064 uptime
= time (NULL
);
1065 uptime
-= rib
->uptime
;
1066 tm
= gmtime (&uptime
);
1068 if (uptime
< ONE_DAY_SECOND
)
1069 vty_out (vty
, ", %02d:%02d:%02d",
1070 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
1071 else if (uptime
< ONE_WEEK_SECOND
)
1072 vty_out (vty
, ", %dd%02dh%02dm",
1073 tm
->tm_yday
, tm
->tm_hour
, tm
->tm_min
);
1075 vty_out (vty
, ", %02dw%dd%02dh",
1077 tm
->tm_yday
- ((tm
->tm_yday
/7) * 7), tm
->tm_hour
);
1079 vty_out (vty
, "%s", VTY_NEWLINE
);
1084 use_fib (struct cmd_token
*token
)
1086 return strncmp(token
->arg
, "route", strlen(token
->arg
));
1089 DEFUN (show_ip_route
,
1091 "show ip <fib|route> [json]",
1094 "IP forwarding table\n"
1095 "IP routing table\n"
1098 return do_show_ip_route (vty
, VRF_DEFAULT_NAME
, SAFI_UNICAST
,
1099 use_fib(argv
[2]), use_json(argc
, argv
));
1103 do_show_ip_route (struct vty
*vty
, const char *vrf_name
, safi_t safi
,
1104 bool use_fib
, u_char use_json
)
1106 struct route_table
*table
;
1107 struct route_node
*rn
;
1110 struct zebra_vrf
*zvrf
= NULL
;
1112 json_object
*json
= NULL
;
1113 json_object
*json_prefix
= NULL
;
1115 if (!(zvrf
= zebra_vrf_lookup_by_name (vrf_name
)))
1118 vty_out (vty
, "{}%s", VTY_NEWLINE
);
1120 vty_out (vty
, "vrf %s not defined%s", vrf_name
, VTY_NEWLINE
);
1124 if (zvrf_id (zvrf
) == VRF_UNKNOWN
)
1127 vty_out (vty
, "{}%s", VTY_NEWLINE
);
1129 vty_out (vty
, "vrf %s inactive%s", vrf_name
, VTY_NEWLINE
);
1133 table
= zebra_vrf_table (AFI_IP
, safi
, zvrf_id (zvrf
));
1137 vty_out (vty
, "{}%s", VTY_NEWLINE
);
1143 json
= json_object_new_object();
1145 /* Show all IPv4 routes. */
1146 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
1148 RNODE_FOREACH_RIB (rn
, rib
)
1150 if (use_fib
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
1153 json_prefix
= json_object_new_array();
1154 vty_show_ip_route (vty
, rn
, rib
, json_prefix
);
1159 prefix2str (&rn
->p
, buf
, sizeof buf
);
1160 json_object_object_add(json
, buf
, json_prefix
);
1165 vty_out (vty
, "%s%s", json_object_to_json_string_ext(json
, JSON_C_TO_STRING_PRETTY
), VTY_NEWLINE
);
1166 json_object_free(json
);
1170 /* Show all IPv4 routes. */
1171 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
1173 RNODE_FOREACH_RIB (rn
, rib
)
1175 if (use_fib
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
1179 vty_out (vty
, SHOW_ROUTE_V4_HEADER
);
1182 vty_show_ip_route (vty
, rn
, rib
, NULL
);
1190 DEFUN (show_ip_route_vrf
,
1191 show_ip_route_vrf_cmd
,
1192 "show ip <fib|route> vrf NAME [json]",
1195 "IP forwarding table\n"
1196 "IP routing table\n"
1201 bool uf
= use_fib(argv
[2]);
1202 u_char uj
= use_json(argc
, argv
);
1204 return do_show_ip_route (vty
, argv
[idx_vrf
]->arg
, SAFI_UNICAST
, uf
, uj
);
1209 "show ip nht [vrf NAME]",
1212 "IP nexthop tracking table\n"
1216 vrf_id_t vrf_id
= VRF_DEFAULT
;
1219 VRF_GET_ID (vrf_id
, argv
[idx_vrf
]->arg
);
1221 zebra_print_rnh_table(vrf_id
, AF_INET
, vty
, RNH_NEXTHOP_TYPE
);
1226 DEFUN (show_ip_nht_vrf_all
,
1227 show_ip_nht_vrf_all_cmd
,
1228 "show ip nht vrf all",
1231 "IP nexthop tracking table\n"
1232 VRF_ALL_CMD_HELP_STR
)
1235 struct zebra_vrf
*zvrf
;
1237 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
1238 if ((zvrf
= vrf
->info
) != NULL
)
1240 vty_out (vty
, "%sVRF %s:%s", VTY_NEWLINE
, zvrf_name (zvrf
), VTY_NEWLINE
);
1241 zebra_print_rnh_table(zvrf_id (zvrf
), AF_INET
, vty
, RNH_NEXTHOP_TYPE
);
1247 DEFUN (show_ipv6_nht
,
1249 "show ipv6 nht [vrf NAME]",
1252 "IPv6 nexthop tracking table\n"
1256 vrf_id_t vrf_id
= VRF_DEFAULT
;
1259 VRF_GET_ID (vrf_id
, argv
[idx_vrf
]->arg
);
1261 zebra_print_rnh_table(vrf_id
, AF_INET6
, vty
, RNH_NEXTHOP_TYPE
);
1266 DEFUN (show_ipv6_nht_vrf_all
,
1267 show_ipv6_nht_vrf_all_cmd
,
1268 "show ipv6 nht vrf all",
1271 "IPv6 nexthop tracking table\n"
1272 VRF_ALL_CMD_HELP_STR
)
1275 struct zebra_vrf
*zvrf
;
1277 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
1278 if ((zvrf
= vrf
->info
) != NULL
)
1280 vty_out (vty
, "%sVRF %s:%s", VTY_NEWLINE
, zvrf_name (zvrf
), VTY_NEWLINE
);
1281 zebra_print_rnh_table(zvrf_id (zvrf
), AF_INET6
, vty
, RNH_NEXTHOP_TYPE
);
1287 DEFUN (ip_nht_default_route
,
1288 ip_nht_default_route_cmd
,
1289 "ip nht resolve-via-default",
1291 "Filter Next Hop tracking route resolution\n"
1292 "Resolve via default route\n")
1294 if (zebra_rnh_ip_default_route
)
1297 zebra_rnh_ip_default_route
= 1;
1298 zebra_evaluate_rnh(0, AF_INET
, 1, RNH_NEXTHOP_TYPE
, NULL
);
1302 DEFUN (no_ip_nht_default_route
,
1303 no_ip_nht_default_route_cmd
,
1304 "no ip nht resolve-via-default",
1307 "Filter Next Hop tracking route resolution\n"
1308 "Resolve via default route\n")
1310 if (!zebra_rnh_ip_default_route
)
1313 zebra_rnh_ip_default_route
= 0;
1314 zebra_evaluate_rnh(0, AF_INET
, 1, RNH_NEXTHOP_TYPE
, NULL
);
1318 DEFUN (ipv6_nht_default_route
,
1319 ipv6_nht_default_route_cmd
,
1320 "ipv6 nht resolve-via-default",
1322 "Filter Next Hop tracking route resolution\n"
1323 "Resolve via default route\n")
1325 if (zebra_rnh_ipv6_default_route
)
1328 zebra_rnh_ipv6_default_route
= 1;
1329 zebra_evaluate_rnh(0, AF_INET6
, 1, RNH_NEXTHOP_TYPE
, NULL
);
1333 DEFUN (no_ipv6_nht_default_route
,
1334 no_ipv6_nht_default_route_cmd
,
1335 "no ipv6 nht resolve-via-default",
1338 "Filter Next Hop tracking route resolution\n"
1339 "Resolve via default route\n")
1341 if (!zebra_rnh_ipv6_default_route
)
1344 zebra_rnh_ipv6_default_route
= 0;
1345 zebra_evaluate_rnh(0, AF_INET6
, 1, RNH_NEXTHOP_TYPE
, NULL
);
1349 DEFUN (show_ip_route_tag
,
1350 show_ip_route_tag_cmd
,
1351 "show ip <fib|route> [vrf NAME] tag (1-4294967295)",
1354 "IP forwarding table\n"
1355 "IP routing table\n"
1357 "Show only routes with tag\n"
1360 bool uf
= use_fib(argv
[2]);
1364 struct route_table
*table
;
1365 struct route_node
*rn
;
1368 route_tag_t tag
= 0;
1369 vrf_id_t vrf_id
= VRF_DEFAULT
;
1371 if (strmatch(argv
[idx_vrf
]->text
, "vrf"))
1373 VRF_GET_ID (vrf_id
, argv
[idx_name
]->arg
);
1374 VTY_GET_INTEGER_RANGE("tag", tag
, argv
[idx_tag
]->arg
, 0, 4294967295);
1379 VTY_GET_INTEGER_RANGE("tag", tag
, argv
[idx_tag
]->arg
, 0, 4294967295);
1382 table
= zebra_vrf_table (AFI_IP
, SAFI_UNICAST
, vrf_id
);
1386 /* Show all IPv4 routes with matching tag value. */
1387 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
1388 RNODE_FOREACH_RIB (rn
, rib
)
1390 if (uf
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
1392 if (rib
->tag
!= tag
)
1397 vty_out (vty
, SHOW_ROUTE_V4_HEADER
);
1400 vty_show_ip_route (vty
, rn
, rib
, NULL
);
1405 DEFUN (show_ip_route_prefix_longer
,
1406 show_ip_route_prefix_longer_cmd
,
1407 "show ip <fib|route> [vrf NAME] A.B.C.D/M longer-prefixes",
1410 "IP forwarding table\n"
1411 "IP routing table\n"
1413 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1414 "Show route matching the specified Network/Mask pair only\n")
1416 struct route_table
*table
;
1417 struct route_node
*rn
;
1422 bool uf
= use_fib(argv
[2]);
1423 vrf_id_t vrf_id
= VRF_DEFAULT
;
1425 if (strmatch(argv
[3]->text
, "vrf"))
1427 VRF_GET_ID (vrf_id
, argv
[4]->arg
);
1428 ret
= str2prefix (argv
[5]->arg
, &p
);
1432 ret
= str2prefix (argv
[3]->arg
, &p
);
1437 vty_out (vty
, "%% Malformed Prefix%s", VTY_NEWLINE
);
1441 table
= zebra_vrf_table (AFI_IP
, SAFI_UNICAST
, vrf_id
);
1445 /* Show matched type IPv4 routes. */
1446 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
1447 RNODE_FOREACH_RIB (rn
, rib
)
1448 if (prefix_match (&p
, &rn
->p
))
1450 if (uf
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
1454 vty_out (vty
, SHOW_ROUTE_V4_HEADER
);
1457 vty_show_ip_route (vty
, rn
, rib
, NULL
);
1462 DEFUN (show_ip_route_supernets
,
1463 show_ip_route_supernets_cmd
,
1464 "show ip <fib|route> [vrf NAME] supernets-only",
1467 "IP forwarding table\n"
1468 "IP routing table\n"
1470 "Show supernet entries only\n")
1472 struct route_table
*table
;
1473 struct route_node
*rn
;
1477 vrf_id_t vrf_id
= VRF_DEFAULT
;
1478 bool uf
= use_fib(argv
[2]);
1480 if (strmatch(argv
[3]->text
, "vrf"))
1481 VRF_GET_ID (vrf_id
, argv
[4]->arg
);
1483 table
= zebra_vrf_table (AFI_IP
, SAFI_UNICAST
, vrf_id
);
1487 /* Show matched type IPv4 routes. */
1488 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
1489 RNODE_FOREACH_RIB (rn
, rib
)
1491 if (uf
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
1493 addr
= ntohl (rn
->p
.u
.prefix4
.s_addr
);
1495 if ((IN_CLASSC (addr
) && rn
->p
.prefixlen
< 24)
1496 || (IN_CLASSB (addr
) && rn
->p
.prefixlen
< 16)
1497 || (IN_CLASSA (addr
) && rn
->p
.prefixlen
< 8))
1501 vty_out (vty
, SHOW_ROUTE_V4_HEADER
);
1504 vty_show_ip_route (vty
, rn
, rib
, NULL
);
1510 DEFUN (show_ip_route_protocol
,
1511 show_ip_route_protocol_cmd
,
1512 "show ip <fib|route> [vrf NAME] " FRR_IP_REDIST_STR_ZEBRA
,
1515 "IP forwarding table\n"
1516 "IP routing table\n"
1518 FRR_IP_REDIST_HELP_STR_ZEBRA
)
1521 struct route_table
*table
;
1522 struct route_node
*rn
;
1525 vrf_id_t vrf_id
= VRF_DEFAULT
;
1526 bool uf
= use_fib(argv
[2]);
1529 if (argv_find (argv
, argc
, "NAME", &idx
))
1530 VRF_GET_ID (vrf_id
, argv
[idx
]->arg
);
1532 char *proto
= argv
[argc
- 1]->text
;
1533 type
= proto_redistnum (AFI_IP
, proto
);
1537 vty_out (vty
, "Unknown route type%s", VTY_NEWLINE
);
1541 table
= zebra_vrf_table (AFI_IP
, SAFI_UNICAST
, vrf_id
);
1545 /* Show matched type IPv4 routes. */
1546 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
1547 RNODE_FOREACH_RIB (rn
, rib
)
1548 if (rib
->type
== type
)
1550 if (uf
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
1554 vty_out (vty
, SHOW_ROUTE_V4_HEADER
);
1557 vty_show_ip_route (vty
, rn
, rib
, NULL
);
1563 DEFUN (show_ip_route_ospf_instance
,
1564 show_ip_route_ospf_instance_cmd
,
1565 "show ip <fib|route> ospf (1-65535)",
1568 "IP forwarding table\n"
1569 "IP routing table\n"
1570 "Open Shortest Path First (OSPFv2)\n"
1574 struct route_table
*table
;
1575 struct route_node
*rn
;
1578 u_short instance
= 0;
1579 bool uf
= use_fib(argv
[2]);
1581 VTY_GET_INTEGER ("Instance", instance
, argv
[idx_number
]->arg
);
1583 table
= zebra_vrf_table (AFI_IP
, SAFI_UNICAST
, VRF_DEFAULT
);
1587 /* Show matched type IPv4 routes. */
1588 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
1589 RNODE_FOREACH_RIB (rn
, rib
)
1590 if (rib
->type
== ZEBRA_ROUTE_OSPF
&& rib
->instance
== instance
)
1592 if (uf
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
1596 vty_out (vty
, SHOW_ROUTE_V4_HEADER
);
1599 vty_show_ip_route (vty
, rn
, rib
, NULL
);
1604 DEFUN (show_ip_route_addr
,
1605 show_ip_route_addr_cmd
,
1606 "show ip route [vrf NAME] A.B.C.D",
1609 "IP routing table\n"
1611 "Network in the IP routing table to display\n")
1614 struct prefix_ipv4 p
;
1615 struct route_table
*table
;
1616 struct route_node
*rn
;
1617 vrf_id_t vrf_id
= VRF_DEFAULT
;
1619 if (strmatch(argv
[3]->text
, "vrf"))
1621 VRF_GET_ID (vrf_id
, argv
[4]->arg
);
1622 ret
= str2prefix_ipv4 (argv
[5]->arg
, &p
);
1626 ret
= str2prefix_ipv4 (argv
[3]->arg
, &p
);
1631 vty_out (vty
, "%% Malformed IPv4 address%s", VTY_NEWLINE
);
1635 table
= zebra_vrf_table (AFI_IP
, SAFI_UNICAST
, vrf_id
);
1639 rn
= route_node_match (table
, (struct prefix
*) &p
);
1642 vty_out (vty
, "%% Network not in table%s", VTY_NEWLINE
);
1646 vty_show_ip_route_detail (vty
, rn
, 0);
1648 route_unlock_node (rn
);
1653 DEFUN (show_ip_route_prefix
,
1654 show_ip_route_prefix_cmd
,
1655 "show ip route [vrf NAME] A.B.C.D/M",
1658 "IP routing table\n"
1660 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
1663 struct prefix_ipv4 p
;
1664 struct route_table
*table
;
1665 struct route_node
*rn
;
1666 vrf_id_t vrf_id
= VRF_DEFAULT
;
1668 if (strmatch(argv
[3]->text
, "vrf"))
1670 VRF_GET_ID (vrf_id
, argv
[4]->arg
);
1671 ret
= str2prefix_ipv4 (argv
[5]->arg
, &p
);
1675 ret
= str2prefix_ipv4 (argv
[3]->arg
, &p
);
1680 vty_out (vty
, "%% Malformed IPv4 address%s", VTY_NEWLINE
);
1684 table
= zebra_vrf_table (AFI_IP
, SAFI_UNICAST
, vrf_id
);
1688 rn
= route_node_match (table
, (struct prefix
*) &p
);
1689 if (! rn
|| rn
->p
.prefixlen
!= p
.prefixlen
)
1691 vty_out (vty
, "%% Network not in table%s", VTY_NEWLINE
);
1695 vty_show_ip_route_detail (vty
, rn
, 0);
1697 route_unlock_node (rn
);
1704 vty_show_ip_route_summary (struct vty
*vty
, struct route_table
*table
)
1706 struct route_node
*rn
;
1708 #define ZEBRA_ROUTE_IBGP ZEBRA_ROUTE_MAX
1709 #define ZEBRA_ROUTE_TOTAL (ZEBRA_ROUTE_IBGP + 1)
1710 u_int32_t rib_cnt
[ZEBRA_ROUTE_TOTAL
+ 1];
1711 u_int32_t fib_cnt
[ZEBRA_ROUTE_TOTAL
+ 1];
1715 memset (&rib_cnt
, 0, sizeof(rib_cnt
));
1716 memset (&fib_cnt
, 0, sizeof(fib_cnt
));
1717 for (rn
= route_top (table
); rn
; rn
= srcdest_route_next (rn
))
1718 RNODE_FOREACH_RIB (rn
, rib
)
1720 is_ibgp
= (rib
->type
== ZEBRA_ROUTE_BGP
&&
1721 CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_IBGP
));
1723 rib_cnt
[ZEBRA_ROUTE_TOTAL
]++;
1725 rib_cnt
[ZEBRA_ROUTE_IBGP
]++;
1727 rib_cnt
[rib
->type
]++;
1729 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_SELECTED
))
1731 fib_cnt
[ZEBRA_ROUTE_TOTAL
]++;
1734 fib_cnt
[ZEBRA_ROUTE_IBGP
]++;
1736 fib_cnt
[rib
->type
]++;
1740 vty_out (vty
, "%-20s %-20s %s (vrf %s)%s",
1741 "Route Source", "Routes", "FIB",
1742 zvrf_name (((rib_table_info_t
*)table
->info
)->zvrf
),
1745 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
1747 if ((rib_cnt
[i
] > 0) ||
1748 (i
== ZEBRA_ROUTE_BGP
&& rib_cnt
[ZEBRA_ROUTE_IBGP
] > 0))
1750 if (i
== ZEBRA_ROUTE_BGP
)
1752 vty_out (vty
, "%-20s %-20d %-20d %s", "ebgp",
1753 rib_cnt
[ZEBRA_ROUTE_BGP
], fib_cnt
[ZEBRA_ROUTE_BGP
],
1755 vty_out (vty
, "%-20s %-20d %-20d %s", "ibgp",
1756 rib_cnt
[ZEBRA_ROUTE_IBGP
], fib_cnt
[ZEBRA_ROUTE_IBGP
],
1760 vty_out (vty
, "%-20s %-20d %-20d %s", zebra_route_string(i
),
1761 rib_cnt
[i
], fib_cnt
[i
], VTY_NEWLINE
);
1765 vty_out (vty
, "------%s", VTY_NEWLINE
);
1766 vty_out (vty
, "%-20s %-20d %-20d %s", "Totals", rib_cnt
[ZEBRA_ROUTE_TOTAL
],
1767 fib_cnt
[ZEBRA_ROUTE_TOTAL
], VTY_NEWLINE
);
1768 vty_out (vty
, "%s", VTY_NEWLINE
);
1772 * Implementation of the ip route summary prefix command.
1774 * This command prints the primary prefixes that have been installed by various
1775 * protocols on the box.
1779 vty_show_ip_route_summary_prefix (struct vty
*vty
, struct route_table
*table
)
1781 struct route_node
*rn
;
1783 struct nexthop
*nexthop
;
1784 #define ZEBRA_ROUTE_IBGP ZEBRA_ROUTE_MAX
1785 #define ZEBRA_ROUTE_TOTAL (ZEBRA_ROUTE_IBGP + 1)
1786 u_int32_t rib_cnt
[ZEBRA_ROUTE_TOTAL
+ 1];
1787 u_int32_t fib_cnt
[ZEBRA_ROUTE_TOTAL
+ 1];
1791 memset (&rib_cnt
, 0, sizeof(rib_cnt
));
1792 memset (&fib_cnt
, 0, sizeof(fib_cnt
));
1793 for (rn
= route_top (table
); rn
; rn
= srcdest_route_next (rn
))
1794 RNODE_FOREACH_RIB (rn
, rib
)
1798 * In case of ECMP, count only once.
1801 for (nexthop
= rib
->nexthop
; (!cnt
&& nexthop
); nexthop
= nexthop
->next
)
1804 rib_cnt
[ZEBRA_ROUTE_TOTAL
]++;
1805 rib_cnt
[rib
->type
]++;
1806 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
))
1808 fib_cnt
[ZEBRA_ROUTE_TOTAL
]++;
1809 fib_cnt
[rib
->type
]++;
1811 if (rib
->type
== ZEBRA_ROUTE_BGP
&&
1812 CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_IBGP
))
1814 rib_cnt
[ZEBRA_ROUTE_IBGP
]++;
1815 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
))
1816 fib_cnt
[ZEBRA_ROUTE_IBGP
]++;
1821 vty_out (vty
, "%-20s %-20s %s (vrf %s)%s",
1822 "Route Source", "Prefix Routes", "FIB",
1823 zvrf_name (((rib_table_info_t
*)table
->info
)->zvrf
),
1826 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
1830 if (i
== ZEBRA_ROUTE_BGP
)
1832 vty_out (vty
, "%-20s %-20d %-20d %s", "ebgp",
1833 rib_cnt
[ZEBRA_ROUTE_BGP
] - rib_cnt
[ZEBRA_ROUTE_IBGP
],
1834 fib_cnt
[ZEBRA_ROUTE_BGP
] - fib_cnt
[ZEBRA_ROUTE_IBGP
],
1836 vty_out (vty
, "%-20s %-20d %-20d %s", "ibgp",
1837 rib_cnt
[ZEBRA_ROUTE_IBGP
], fib_cnt
[ZEBRA_ROUTE_IBGP
],
1841 vty_out (vty
, "%-20s %-20d %-20d %s", zebra_route_string(i
),
1842 rib_cnt
[i
], fib_cnt
[i
], VTY_NEWLINE
);
1846 vty_out (vty
, "------%s", VTY_NEWLINE
);
1847 vty_out (vty
, "%-20s %-20d %-20d %s", "Totals", rib_cnt
[ZEBRA_ROUTE_TOTAL
],
1848 fib_cnt
[ZEBRA_ROUTE_TOTAL
], VTY_NEWLINE
);
1849 vty_out (vty
, "%s", VTY_NEWLINE
);
1852 /* Show route summary. */
1853 DEFUN (show_ip_route_summary
,
1854 show_ip_route_summary_cmd
,
1855 "show ip route [vrf NAME] summary",
1858 "IP routing table\n"
1860 "Summary of all routes\n")
1862 struct route_table
*table
;
1863 vrf_id_t vrf_id
= VRF_DEFAULT
;
1865 if (strmatch(argv
[3]->text
, "vrf"))
1866 VRF_GET_ID (vrf_id
, argv
[4]->arg
);
1868 table
= zebra_vrf_table (AFI_IP
, SAFI_UNICAST
, vrf_id
);
1872 vty_show_ip_route_summary (vty
, table
);
1877 /* Show route summary prefix. */
1878 DEFUN (show_ip_route_summary_prefix
,
1879 show_ip_route_summary_prefix_cmd
,
1880 "show ip route [vrf NAME] summary prefix",
1883 "IP routing table\n"
1885 "Summary of all routes\n"
1888 struct route_table
*table
;
1889 vrf_id_t vrf_id
= VRF_DEFAULT
;
1891 if (strmatch(argv
[3]->text
, "vrf"))
1892 VRF_GET_ID (vrf_id
, argv
[4]->arg
);
1894 table
= zebra_vrf_table (AFI_IP
, SAFI_UNICAST
, vrf_id
);
1898 vty_show_ip_route_summary_prefix (vty
, table
);
1904 DEFUN (show_ip_route_vrf_all
,
1905 show_ip_route_vrf_all_cmd
,
1906 "show ip <fib|route> vrf all",
1909 "IP forwarding table\n"
1910 "IP routing table\n"
1911 VRF_ALL_CMD_HELP_STR
)
1913 struct route_table
*table
;
1914 struct route_node
*rn
;
1917 struct zebra_vrf
*zvrf
;
1920 bool uf
= use_fib(argv
[2]);
1922 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
1924 if ((zvrf
= vrf
->info
) == NULL
||
1925 (table
= zvrf
->table
[AFI_IP
][SAFI_UNICAST
]) == NULL
)
1928 /* Show all IPv4 routes. */
1929 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
1930 RNODE_FOREACH_RIB (rn
, rib
)
1932 if (uf
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
1936 vty_out (vty
, SHOW_ROUTE_V4_HEADER
);
1942 vty_out (vty
, "%sVRF %s:%s", VTY_NEWLINE
, zvrf_name (zvrf
), VTY_NEWLINE
);
1945 vty_show_ip_route (vty
, rn
, rib
, NULL
);
1953 DEFUN (show_ip_route_vrf_all_tag
,
1954 show_ip_route_vrf_all_tag_cmd
,
1955 "show ip <fib|route> vrf all tag (1-4294967295)",
1958 "IP forwarding table\n"
1959 "IP routing table\n"
1960 VRF_ALL_CMD_HELP_STR
1961 "Show only routes with tag\n"
1965 struct route_table
*table
;
1966 struct route_node
*rn
;
1969 struct zebra_vrf
*zvrf
;
1972 route_tag_t tag
= 0;
1973 bool uf
= use_fib(argv
[2]);
1975 if (argv
[idx_number
]->arg
)
1976 VTY_GET_INTEGER_RANGE("tag", tag
, argv
[idx_number
]->arg
, 0, 4294967295);
1978 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
1980 if ((zvrf
= vrf
->info
) == NULL
||
1981 (table
= zvrf
->table
[AFI_IP
][SAFI_UNICAST
]) == NULL
)
1984 /* Show all IPv4 routes with matching tag value. */
1985 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
1986 RNODE_FOREACH_RIB (rn
, rib
)
1988 if (uf
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
1990 if (rib
->tag
!= tag
)
1995 vty_out (vty
, SHOW_ROUTE_V4_HEADER
);
2001 vty_out (vty
, "%sVRF %s:%s", VTY_NEWLINE
, zvrf_name (zvrf
), VTY_NEWLINE
);
2004 vty_show_ip_route (vty
, rn
, rib
, NULL
);
2011 DEFUN (show_ip_route_vrf_all_prefix_longer
,
2012 show_ip_route_vrf_all_prefix_longer_cmd
,
2013 "show ip <fib|route> vrf all A.B.C.D/M longer-prefixes",
2016 "IP forwarding table\n"
2017 "IP routing table\n"
2018 VRF_ALL_CMD_HELP_STR
2019 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
2020 "Show route matching the specified Network/Mask pair only\n")
2022 int idx_ipv4_prefixlen
= 5;
2023 struct route_table
*table
;
2024 struct route_node
*rn
;
2028 struct zebra_vrf
*zvrf
;
2032 bool uf
= use_fib(argv
[2]);
2034 ret
= str2prefix (argv
[idx_ipv4_prefixlen
]->arg
, &p
);
2037 vty_out (vty
, "%% Malformed Prefix%s", VTY_NEWLINE
);
2041 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
2043 if ((zvrf
= vrf
->info
) == NULL
||
2044 (table
= zvrf
->table
[AFI_IP
][SAFI_UNICAST
]) == NULL
)
2047 /* Show matched type IPv4 routes. */
2048 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
2049 RNODE_FOREACH_RIB (rn
, rib
)
2050 if (prefix_match (&p
, &rn
->p
))
2052 if (uf
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
2056 vty_out (vty
, SHOW_ROUTE_V4_HEADER
);
2062 vty_out (vty
, "%sVRF %s:%s", VTY_NEWLINE
, zvrf_name (zvrf
), VTY_NEWLINE
);
2065 vty_show_ip_route (vty
, rn
, rib
, NULL
);
2073 DEFUN (show_ip_route_vrf_all_supernets
,
2074 show_ip_route_vrf_all_supernets_cmd
,
2075 "show ip <fib|route> vrf all supernets-only",
2078 "IP forwarding table\n"
2079 "IP routing table\n"
2080 VRF_ALL_CMD_HELP_STR
2081 "Show supernet entries only\n")
2083 struct route_table
*table
;
2084 struct route_node
*rn
;
2087 struct zebra_vrf
*zvrf
;
2091 bool uf
= use_fib(argv
[2]);
2093 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
2095 if ((zvrf
= vrf
->info
) == NULL
||
2096 (table
= zvrf
->table
[AFI_IP
][SAFI_UNICAST
]) == NULL
)
2099 /* Show matched type IPv4 routes. */
2100 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
2101 RNODE_FOREACH_RIB (rn
, rib
)
2103 if (uf
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
2106 addr
= ntohl (rn
->p
.u
.prefix4
.s_addr
);
2108 if ((IN_CLASSC (addr
) && rn
->p
.prefixlen
< 24)
2109 || (IN_CLASSB (addr
) && rn
->p
.prefixlen
< 16)
2110 || (IN_CLASSA (addr
) && rn
->p
.prefixlen
< 8))
2114 vty_out (vty
, SHOW_ROUTE_V4_HEADER
);
2119 vty_out (vty
, "%sVRF %s:%s", VTY_NEWLINE
, zvrf_name (zvrf
), VTY_NEWLINE
);
2122 vty_show_ip_route (vty
, rn
, rib
, NULL
);
2131 DEFUN (show_ip_route_vrf_all_protocol
,
2132 show_ip_route_vrf_all_protocol_cmd
,
2133 "show ip <fib|route> vrf all " FRR_IP_REDIST_STR_ZEBRA
,
2136 "IP forwarding table\n"
2137 "IP routing table\n"
2138 VRF_ALL_CMD_HELP_STR
2139 FRR_IP_REDIST_HELP_STR_ZEBRA
"\n")
2142 struct route_table
*table
;
2143 struct route_node
*rn
;
2146 struct zebra_vrf
*zvrf
;
2149 bool uf
= use_fib(argv
[2]);
2151 char *proto
= argv
[argc
- 1]->text
;
2152 type
= proto_redistnum (AFI_IP
, proto
);
2156 vty_out (vty
, "Unknown route type%s", VTY_NEWLINE
);
2160 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
2162 if ((zvrf
= vrf
->info
) == NULL
||
2163 (table
= zvrf
->table
[AFI_IP
][SAFI_UNICAST
]) == NULL
)
2166 /* Show matched type IPv4 routes. */
2167 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
2168 RNODE_FOREACH_RIB (rn
, rib
)
2169 if (rib
->type
== type
)
2171 if (uf
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
2175 vty_out (vty
, SHOW_ROUTE_V4_HEADER
);
2181 vty_out (vty
, "%sVRF %s:%s", VTY_NEWLINE
, zvrf_name (zvrf
), VTY_NEWLINE
);
2184 vty_show_ip_route (vty
, rn
, rib
, NULL
);
2192 DEFUN (show_ip_route_vrf_all_addr
,
2193 show_ip_route_vrf_all_addr_cmd
,
2194 "show ip route vrf all A.B.C.D",
2197 "IP routing table\n"
2198 VRF_ALL_CMD_HELP_STR
2199 "Network in the IP routing table to display\n")
2203 struct prefix_ipv4 p
;
2204 struct route_table
*table
;
2205 struct route_node
*rn
;
2207 struct zebra_vrf
*zvrf
;
2209 ret
= str2prefix_ipv4 (argv
[idx_ipv4
]->arg
, &p
);
2212 vty_out (vty
, "%% Malformed IPv4 address%s", VTY_NEWLINE
);
2216 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
2218 if ((zvrf
= vrf
->info
) == NULL
||
2219 (table
= zvrf
->table
[AFI_IP
][SAFI_UNICAST
]) == NULL
)
2222 rn
= route_node_match (table
, (struct prefix
*) &p
);
2226 vty_show_ip_route_detail (vty
, rn
, 0);
2228 route_unlock_node (rn
);
2234 DEFUN (show_ip_route_vrf_all_prefix
,
2235 show_ip_route_vrf_all_prefix_cmd
,
2236 "show ip route vrf all A.B.C.D/M",
2239 "IP routing table\n"
2240 VRF_ALL_CMD_HELP_STR
2241 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
2243 int idx_ipv4_prefixlen
= 5;
2245 struct prefix_ipv4 p
;
2246 struct route_table
*table
;
2247 struct route_node
*rn
;
2249 struct zebra_vrf
*zvrf
;
2251 ret
= str2prefix_ipv4 (argv
[idx_ipv4_prefixlen
]->arg
, &p
);
2254 vty_out (vty
, "%% Malformed IPv4 address%s", VTY_NEWLINE
);
2258 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
2260 if ((zvrf
= vrf
->info
) == NULL
||
2261 (table
= zvrf
->table
[AFI_IP
][SAFI_UNICAST
]) == NULL
)
2264 rn
= route_node_match (table
, (struct prefix
*) &p
);
2267 if (rn
->p
.prefixlen
!= p
.prefixlen
)
2269 route_unlock_node (rn
);
2273 vty_show_ip_route_detail (vty
, rn
, 0);
2275 route_unlock_node (rn
);
2281 DEFUN (show_ip_route_vrf_all_summary
,
2282 show_ip_route_vrf_all_summary_cmd
,
2283 "show ip route vrf all summary ",
2286 "IP routing table\n"
2287 VRF_ALL_CMD_HELP_STR
2288 "Summary of all routes\n")
2291 struct zebra_vrf
*zvrf
;
2293 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
2294 if ((zvrf
= vrf
->info
) != NULL
)
2295 vty_show_ip_route_summary (vty
, zvrf
->table
[AFI_IP
][SAFI_UNICAST
]);
2300 DEFUN (show_ip_route_vrf_all_summary_prefix
,
2301 show_ip_route_vrf_all_summary_prefix_cmd
,
2302 "show ip route vrf all summary prefix",
2305 "IP routing table\n"
2306 VRF_ALL_CMD_HELP_STR
2307 "Summary of all routes\n"
2311 struct zebra_vrf
*zvrf
;
2313 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
2314 if ((zvrf
= vrf
->info
) != NULL
)
2315 vty_show_ip_route_summary_prefix (vty
, zvrf
->table
[AFI_IP
][SAFI_UNICAST
]);
2320 /* Write IPv4 static route configuration. */
2322 static_config_ipv4 (struct vty
*vty
, safi_t safi
, const char *cmd
)
2324 struct route_node
*rn
;
2325 struct static_route
*si
;
2326 struct route_table
*stable
;
2328 struct zebra_vrf
*zvrf
;
2332 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
2334 if (!(zvrf
= vrf
->info
))
2336 if ((stable
= zvrf
->stable
[AFI_IP
][safi
]) == NULL
)
2339 for (rn
= route_top (stable
); rn
; rn
= route_next (rn
))
2340 for (si
= rn
->info
; si
; si
= si
->next
)
2342 vty_out (vty
, "%s %s", cmd
, prefix2str (&rn
->p
, buf
, sizeof buf
));
2346 case STATIC_IPV4_GATEWAY
:
2347 vty_out (vty
, " %s", inet_ntoa (si
->addr
.ipv4
));
2349 case STATIC_IFINDEX
:
2350 vty_out (vty
, " %s", si
->ifname
);
2352 case STATIC_BLACKHOLE
:
2353 vty_out (vty
, " Null0");
2355 case STATIC_IPV6_GATEWAY
:
2356 vty_out (vty
, " %s", inet_ntop (AF_INET6
, &si
->addr
.ipv6
, buf
, BUFSIZ
));
2358 case STATIC_IPV6_GATEWAY_IFINDEX
:
2359 vty_out (vty
, " %s %s",
2360 inet_ntop (AF_INET6
, &si
->addr
.ipv6
, buf
, BUFSIZ
),
2361 ifindex2ifname (si
->ifindex
, si
->vrf_id
));
2365 /* flags are incompatible with STATIC_BLACKHOLE */
2366 if (si
->type
!= STATIC_BLACKHOLE
)
2368 if (CHECK_FLAG(si
->flags
, ZEBRA_FLAG_REJECT
))
2369 vty_out (vty
, " %s", "reject");
2371 if (CHECK_FLAG(si
->flags
, ZEBRA_FLAG_BLACKHOLE
))
2372 vty_out (vty
, " %s", "blackhole");
2376 vty_out (vty
, " tag %"ROUTE_TAG_PRI
, si
->tag
);
2378 if (si
->distance
!= ZEBRA_STATIC_DISTANCE_DEFAULT
)
2379 vty_out (vty
, " %d", si
->distance
);
2381 if (si
->vrf_id
!= VRF_DEFAULT
)
2382 vty_out (vty
, " vrf %s", zvrf
? zvrf_name (zvrf
) : "");
2384 /* Label information */
2385 if (si
->snh_label
.num_labels
)
2386 vty_out (vty
, " label %s",
2387 mpls_label2str (si
->snh_label
.num_labels
,
2388 si
->snh_label
.label
, buf
, sizeof buf
, 0));
2390 vty_out (vty
, "%s", VTY_NEWLINE
);
2398 /* General fucntion for IPv6 static route. */
2400 static_ipv6_func (struct vty
*vty
, int add_cmd
, const char *dest_str
,
2401 const char *src_str
,
2402 const char *gate_str
, const char *ifname
,
2403 const char *flag_str
, const char *tag_str
,
2404 const char *distance_str
, const char *vrf_id_str
,
2405 const char *label_str
)
2409 struct prefix p
, src
;
2410 struct prefix_ipv6
*src_p
= NULL
;
2411 struct in6_addr
*gate
= NULL
;
2412 struct in6_addr gate_addr
;
2413 u_char type
= STATIC_BLACKHOLE
;
2415 route_tag_t tag
= 0;
2416 unsigned int ifindex
= 0;
2417 struct interface
*ifp
= NULL
;
2418 struct zebra_vrf
*zvrf
;
2419 struct static_nh_label snh_label
;
2421 ret
= str2prefix (dest_str
, &p
);
2424 vty_out (vty
, "%% Malformed address%s", VTY_NEWLINE
);
2430 ret
= str2prefix (src_str
, &src
);
2431 if (ret
<= 0 || src
.family
!= AF_INET6
)
2433 vty_out (vty
, "%% Malformed source address%s", VTY_NEWLINE
);
2436 src_p
= (struct prefix_ipv6
*)&src
;
2439 /* Apply mask for given prefix. */
2442 /* Administrative distance. */
2444 distance
= atoi (distance_str
);
2446 distance
= ZEBRA_STATIC_DISTANCE_DEFAULT
;
2450 VTY_GET_INTEGER_RANGE("tag", tag
, tag_str
, 0, 4294967295);
2452 /* When gateway is valid IPv6 addrees, then gate is treated as
2453 nexthop address other case gate is treated as interface name. */
2454 ret
= inet_pton (AF_INET6
, gate_str
, &gate_addr
);
2457 zvrf
= zebra_vrf_lookup_by_name (vrf_id_str
);
2461 vty_out (vty
, "%% vrf %s is not defined%s", vrf_id_str
, VTY_NEWLINE
);
2466 memset (&snh_label
, 0, sizeof (struct static_nh_label
));
2471 vty_out (vty
, "%% MPLS not turned on in kernel, ignoring command%s",
2475 if (mpls_str2label (label_str
, &snh_label
.num_labels
,
2478 vty_out (vty
, "%% Malformed label(s)%s", VTY_NEWLINE
);
2483 /* Null0 static route. */
2484 if ((gate_str
!= NULL
) && (strncasecmp (gate_str
, "Null0", strlen (gate_str
)) == 0))
2488 vty_out (vty
, "%% can not have flag %s with Null0%s", flag_str
, VTY_NEWLINE
);
2492 static_add_route (AFI_IP6
, SAFI_UNICAST
, type
, &p
, NULL
, NULL
, ifindex
, ifname
,
2493 ZEBRA_FLAG_BLACKHOLE
, tag
, distance
, zvrf
, &snh_label
);
2495 static_delete_route (AFI_IP6
, SAFI_UNICAST
, type
, &p
, NULL
, NULL
, ifindex
, tag
,
2496 distance
, zvrf
, &snh_label
);
2502 switch(flag_str
[0]) {
2505 SET_FLAG (flag
, ZEBRA_FLAG_REJECT
);
2509 SET_FLAG (flag
, ZEBRA_FLAG_BLACKHOLE
);
2512 vty_out (vty
, "%% Malformed flag %s %s", flag_str
, VTY_NEWLINE
);
2519 /* When ifname is specified. It must be come with gateway
2523 vty_out (vty
, "%% Malformed address%s", VTY_NEWLINE
);
2526 type
= STATIC_IPV6_GATEWAY_IFINDEX
;
2528 ifp
= if_lookup_by_name (ifname
, zvrf_id (zvrf
));
2531 vty_out (vty
, "%% Malformed Interface name %s%s", ifname
, VTY_NEWLINE
);
2534 ifindex
= ifp
->ifindex
;
2540 type
= STATIC_IPV6_GATEWAY
;
2545 type
= STATIC_IFINDEX
;
2546 ifp
= if_lookup_by_name (gate_str
, zvrf_id (zvrf
));
2549 vty_out (vty
, "%% Malformed Interface name %s%s", gate_str
, VTY_NEWLINE
);
2550 ifindex
= IFINDEX_DELETED
;
2553 ifindex
= ifp
->ifindex
;
2559 static_add_route (AFI_IP6
, SAFI_UNICAST
, type
, &p
, src_p
, (union g_addr
*)gate
,
2560 ifindex
, ifname
, flag
, tag
, distance
, zvrf
, &snh_label
);
2562 static_delete_route (AFI_IP6
, SAFI_UNICAST
, type
, &p
, src_p
, (union g_addr
*)gate
,
2563 ifindex
, tag
, distance
, zvrf
, &snh_label
);
2570 "ipv6 route X:X::X:X/M [from X:X::X:X/M] <X:X::X:X|INTERFACE|null0> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
2572 "Establish static routes\n"
2573 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
2574 "IPv6 source-dest route\n"
2575 "IPv6 source prefix\n"
2576 "IPv6 gateway address\n"
2577 "IPv6 gateway interface name\n"
2580 "Set tag for this route\n"
2582 "Distance value for this prefix\n"
2584 "Specify labels for this route\n"
2585 "One or more labels separated by '/'\n")
2587 int idx_ipv6_prefixlen
= 2;
2588 int idx_ipv6_ifname
;
2590 char *src
, *tag
, *distance
, *vrf
;
2592 if (!strcmp(argv
[3]->text
, "from"))
2595 idx_ipv6_ifname
= 5;
2601 idx_ipv6_ifname
= 3;
2605 tag
= distance
= vrf
= NULL
;
2606 zebra_vty_ip_route_tdv_helper (argc
, argv
, idx_curr
, &tag
, &distance
, &vrf
, NULL
);
2608 return static_ipv6_func (vty
, 1,
2609 argv
[idx_ipv6_prefixlen
]->arg
,
2611 argv
[idx_ipv6_ifname
]->arg
,
2613 tag
, distance
, vrf
, NULL
);
2616 DEFUN (ipv6_route_flags
,
2617 ipv6_route_flags_cmd
,
2618 "ipv6 route X:X::X:X/M [from X:X::X:X/M] <X:X::X:X|INTERFACE> <reject|blackhole> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
2620 "Establish static routes\n"
2621 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
2622 "IPv6 source-dest route\n"
2623 "IPv6 source prefix\n"
2624 "IPv6 gateway address\n"
2625 "IPv6 gateway interface name\n"
2626 "Emit an ICMP unreachable when matched\n"
2627 "Silently discard pkts when matched\n"
2628 "Silently discard pkts when matched\n"
2629 "Set tag for this route\n"
2631 "Distance value for this prefix\n"
2633 "Specify labels for this route\n"
2634 "One or more labels separated by '/'\n")
2636 int idx_ipv6_prefixlen
= 2;
2637 int idx_ipv6_ifname
;
2638 int idx_reject_blackhole
;
2640 char *src
, *tag
, *distance
, *vrf
;
2642 if (!strcmp(argv
[3]->text
, "from"))
2645 idx_ipv6_ifname
= 5;
2646 idx_reject_blackhole
= 6;
2652 idx_ipv6_ifname
= 3;
2653 idx_reject_blackhole
= 4;
2657 tag
= distance
= vrf
= NULL
;
2658 zebra_vty_ip_route_tdv_helper (argc
, argv
, idx_curr
, &tag
, &distance
, &vrf
, NULL
);
2660 return static_ipv6_func (vty
, 1,
2661 argv
[idx_ipv6_prefixlen
]->arg
,
2663 argv
[idx_ipv6_ifname
]->arg
,
2665 argv
[idx_reject_blackhole
]->arg
,
2666 tag
, distance
, vrf
, NULL
);
2669 DEFUN (ipv6_route_ifname
,
2670 ipv6_route_ifname_cmd
,
2671 "ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE [tag (1-4294967295)] [(1-255)] [vrf NAME]",
2673 "Establish static routes\n"
2674 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
2675 "IPv6 source-dest route\n"
2676 "IPv6 source prefix\n"
2677 "IPv6 gateway address\n"
2678 "IPv6 gateway interface name\n"
2679 "Set tag for this route\n"
2681 "Distance value for this prefix\n"
2683 "Specify labels for this route\n"
2684 "One or more labels separated by '/'\n")
2686 int idx_ipv6_prefixlen
= 2;
2688 int idx_interface
= 4;
2690 char *src
, *tag
, *distance
, *vrf
;
2692 if (!strcmp(argv
[3]->text
, "from"))
2707 tag
= distance
= vrf
= NULL
;
2708 zebra_vty_ip_route_tdv_helper (argc
, argv
, idx_curr
, &tag
, &distance
, &vrf
, NULL
);
2710 return static_ipv6_func (vty
, 1,
2711 argv
[idx_ipv6_prefixlen
]->arg
,
2713 argv
[idx_ipv6
]->arg
,
2714 argv
[idx_interface
]->arg
,
2716 tag
, distance
, vrf
, NULL
);
2719 DEFUN (ipv6_route_ifname_flags
,
2720 ipv6_route_ifname_flags_cmd
,
2721 "ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE <reject|blackhole> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
2723 "Establish static routes\n"
2724 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
2725 "IPv6 source-dest route\n"
2726 "IPv6 source prefix\n"
2727 "IPv6 gateway address\n"
2728 "IPv6 gateway interface name\n"
2729 "Emit an ICMP unreachable when matched\n"
2730 "Silently discard pkts when matched\n"
2731 "Set tag for this route\n"
2733 "Distance value for this prefix\n"
2735 "Specify labels for this route\n"
2736 "One or more labels separated by '/'\n")
2738 int idx_ipv6_prefixlen
= 2;
2741 int idx_reject_blackhole
;
2743 char *src
, *tag
, *distance
, *vrf
;
2745 if (!strcmp(argv
[3]->text
, "from"))
2750 idx_reject_blackhole
= 7;
2758 idx_reject_blackhole
= 5;
2762 tag
= distance
= vrf
= NULL
;
2763 zebra_vty_ip_route_tdv_helper (argc
, argv
, idx_curr
, &tag
, &distance
, &vrf
, NULL
);
2765 return static_ipv6_func (vty
, 1,
2766 argv
[idx_ipv6_prefixlen
]->arg
,
2768 argv
[idx_ipv6
]->arg
,
2769 argv
[idx_interface
]->arg
,
2770 argv
[idx_reject_blackhole
]->arg
,
2771 tag
, distance
, vrf
, NULL
);
2774 DEFUN (no_ipv6_route
,
2776 "no ipv6 route X:X::X:X/M [from X:X::X:X/M] <X:X::X:X|INTERFACE|null0> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
2779 "Establish static routes\n"
2780 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
2781 "IPv6 source-dest route\n"
2782 "IPv6 source prefix\n"
2783 "IPv6 gateway address\n"
2784 "IPv6 gateway interface name\n"
2786 "Set tag for this route\n"
2788 "Distance value for this prefix\n"
2790 "Specify labels for this route\n"
2791 "One or more labels separated by '/'\n")
2793 int idx_ipv6_prefixlen
= 3;
2794 int idx_ipv6_ifname
;
2796 char *src
, *tag
, *distance
, *vrf
;
2798 if (!strcmp(argv
[4]->text
, "from"))
2801 idx_ipv6_ifname
= 6;
2807 idx_ipv6_ifname
= 4;
2811 tag
= distance
= vrf
= NULL
;
2812 zebra_vty_ip_route_tdv_helper (argc
, argv
, idx_curr
, &tag
, &distance
, &vrf
, NULL
);
2814 return static_ipv6_func (vty
, 0,
2815 argv
[idx_ipv6_prefixlen
]->arg
,
2817 argv
[idx_ipv6_ifname
]->arg
,
2819 tag
, distance
, vrf
, NULL
);
2822 DEFUN (no_ipv6_route_flags
,
2823 no_ipv6_route_flags_cmd
,
2824 "no ipv6 route X:X::X:X/M [from X:X::X:X/M] <X:X::X:X|INTERFACE> <reject|blackhole> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
2827 "Establish static routes\n"
2828 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
2829 "IPv6 source-dest route\n"
2830 "IPv6 source prefix\n"
2831 "IPv6 gateway address\n"
2832 "IPv6 gateway interface name\n"
2833 "Emit an ICMP unreachable when matched\n"
2834 "Silently discard pkts when matched\n"
2835 "Set tag for this route\n"
2837 "Distance value for this prefix\n"
2839 "Specify labels for this route\n"
2840 "One or more labels separated by '/'\n")
2842 int idx_ipv6_prefixlen
= 3;
2843 int idx_ipv6_ifname
;
2844 int idx_reject_blackhole
;
2846 char *src
, *tag
, *distance
, *vrf
;
2848 if (!strcmp(argv
[4]->text
, "from"))
2851 idx_ipv6_ifname
= 6;
2852 idx_reject_blackhole
= 7;
2858 idx_ipv6_ifname
= 4;
2859 idx_reject_blackhole
= 5;
2863 tag
= distance
= vrf
= NULL
;
2864 zebra_vty_ip_route_tdv_helper (argc
, argv
, idx_curr
, &tag
, &distance
, &vrf
, NULL
);
2866 return static_ipv6_func (vty
, 0,
2867 argv
[idx_ipv6_prefixlen
]->arg
,
2869 argv
[idx_ipv6_ifname
]->arg
,
2871 argv
[idx_reject_blackhole
]->arg
,
2872 tag
, distance
, vrf
, NULL
);
2875 DEFUN (no_ipv6_route_ifname
,
2876 no_ipv6_route_ifname_cmd
,
2877 "no ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE [tag (1-4294967295)] [(1-255)] [vrf NAME]",
2880 "Establish static routes\n"
2881 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
2882 "IPv6 source-dest route\n"
2883 "IPv6 source prefix\n"
2884 "IPv6 gateway address\n"
2885 "IPv6 gateway interface name\n"
2886 "Set tag for this route\n"
2888 "Distance value for this prefix\n"
2890 "Specify labels for this route\n"
2891 "One or more labels separated by '/'\n")
2893 int idx_ipv6_prefixlen
= 3;
2897 char *src
, *tag
, *distance
, *vrf
;
2899 if (!strcmp(argv
[4]->text
, "from"))
2914 tag
= distance
= vrf
= NULL
;
2915 zebra_vty_ip_route_tdv_helper (argc
, argv
, idx_curr
, &tag
, &distance
, &vrf
, NULL
);
2917 return static_ipv6_func (vty
, 0,
2918 argv
[idx_ipv6_prefixlen
]->arg
,
2920 argv
[idx_ipv6
]->arg
,
2921 argv
[idx_interface
]->arg
,
2923 tag
, distance
, vrf
, NULL
);
2926 DEFUN (no_ipv6_route_ifname_flags
,
2927 no_ipv6_route_ifname_flags_cmd
,
2928 "no ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE <reject|blackhole> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
2931 "Establish static routes\n"
2932 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
2933 "IPv6 source-dest route\n"
2934 "IPv6 source prefix\n"
2935 "IPv6 gateway address\n"
2936 "IPv6 gateway interface name\n"
2937 "Emit an ICMP unreachable when matched\n"
2938 "Silently discard pkts when matched\n"
2939 "Set tag for this route\n"
2941 "Distance value for this prefix\n"
2943 "Specify labels for this route\n"
2944 "One or more labels separated by '/'\n")
2946 int idx_ipv6_prefixlen
= 3;
2949 int idx_reject_blackhole
;
2951 char *src
, *tag
, *distance
, *vrf
;
2953 if (!strcmp(argv
[4]->text
, "from"))
2958 idx_reject_blackhole
= 8;
2966 idx_reject_blackhole
= 6;
2970 tag
= distance
= vrf
= NULL
;
2971 zebra_vty_ip_route_tdv_helper (argc
, argv
, idx_curr
, &tag
, &distance
, &vrf
, NULL
);
2973 return static_ipv6_func (vty
, 0,
2974 argv
[idx_ipv6_prefixlen
]->arg
,
2976 argv
[idx_ipv6
]->arg
,
2977 argv
[idx_interface
]->arg
,
2978 argv
[idx_reject_blackhole
]->arg
,
2979 tag
, distance
, vrf
, NULL
);
2982 DEFUN (show_ipv6_route
,
2983 show_ipv6_route_cmd
,
2984 "show ipv6 <fib|route> [vrf NAME] [json]",
2987 "IPv6 forwarding table\n"
2988 "IPv6 routing table\n"
2992 struct route_table
*table
;
2993 struct route_node
*rn
;
2996 vrf_id_t vrf_id
= VRF_DEFAULT
;
2997 struct zebra_vrf
*zvrf
= NULL
;
2998 char buf
[SRCDEST2STR_BUFFER
];
2999 json_object
*json
= NULL
;
3000 json_object
*json_prefix
= NULL
;
3001 bool uf
= use_fib(argv
[2]);
3003 int vrf
= (argc
> 3 && strmatch (argv
[3]->text
, "vrf"));
3004 int uj
= vrf
? argc
== 6 : argc
== 4;
3005 char *vrfname
= vrf
? argv
[4]->arg
: NULL
;
3009 if (!(zvrf
= zebra_vrf_lookup_by_name (vrfname
)))
3012 vty_out (vty
, "{}%s", VTY_NEWLINE
);
3014 vty_out (vty
, "vrf %s not defined%s", vrfname
, VTY_NEWLINE
);
3018 if (zvrf_id (zvrf
) == VRF_UNKNOWN
)
3021 vty_out (vty
, "{}%s", VTY_NEWLINE
);
3023 vty_out (vty
, "vrf %s inactive%s", vrfname
, VTY_NEWLINE
);
3027 vrf_id
= zvrf_id (zvrf
);
3030 table
= zebra_vrf_table (AFI_IP6
, SAFI_UNICAST
, vrf_id
);
3034 vty_out (vty
, "{}%s", VTY_NEWLINE
);
3040 json
= json_object_new_object();
3042 /* Show all IPv6 route. */
3043 for (rn
= route_top (table
); rn
; rn
= srcdest_route_next (rn
))
3045 RNODE_FOREACH_RIB (rn
, rib
)
3047 if (uf
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
3050 json_prefix
= json_object_new_array();
3051 vty_show_ip_route (vty
, rn
, rib
, json_prefix
);
3056 srcdest_rnode2str (rn
, buf
, sizeof buf
);
3057 json_object_object_add(json
, buf
, json_prefix
);
3062 vty_out (vty
, "%s%s", json_object_to_json_string_ext(json
, JSON_C_TO_STRING_PRETTY
), VTY_NEWLINE
);
3063 json_object_free(json
);
3067 /* Show all IPv6 route. */
3068 for (rn
= route_top (table
); rn
; rn
= srcdest_route_next (rn
))
3070 RNODE_FOREACH_RIB (rn
, rib
)
3072 if (uf
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
3076 vty_out (vty
, SHOW_ROUTE_V6_HEADER
);
3079 vty_show_ip_route (vty
, rn
, rib
, NULL
);
3087 DEFUN (show_ipv6_route_tag
,
3088 show_ipv6_route_tag_cmd
,
3089 "show ipv6 <fib|route> [vrf NAME] tag (1-4294967295)",
3092 "IPv6 forwarding table\n"
3093 "IPv6 routing table\n"
3095 "Show only routes with tag\n"
3101 struct route_table
*table
;
3102 struct route_node
*rn
;
3105 route_tag_t tag
= 0;
3106 vrf_id_t vrf_id
= VRF_DEFAULT
;
3107 bool uf
= use_fib(argv
[2]);
3109 if (strmatch(argv
[idx_vrf
]->text
, "vrf"))
3111 VRF_GET_ID (vrf_id
, argv
[idx_name
]->arg
);
3112 VTY_GET_INTEGER_RANGE("tag", tag
, argv
[idx_tag
]->arg
, 0, 4294967295);
3117 VTY_GET_INTEGER_RANGE("tag", tag
, argv
[idx_tag
]->arg
, 0, 4294967295);
3120 table
= zebra_vrf_table (AFI_IP6
, SAFI_UNICAST
, vrf_id
);
3124 /* Show all IPv6 routes with matching tag value. */
3125 for (rn
= route_top (table
); rn
; rn
= srcdest_route_next (rn
))
3126 RNODE_FOREACH_RIB (rn
, rib
)
3128 if (uf
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
3130 if (rib
->tag
!= tag
)
3135 vty_out (vty
, SHOW_ROUTE_V6_HEADER
);
3138 vty_show_ip_route (vty
, rn
, rib
, NULL
);
3143 DEFUN (show_ipv6_route_prefix_longer
,
3144 show_ipv6_route_prefix_longer_cmd
,
3145 "show ipv6 <fib|route> [vrf NAME] X:X::X:X/M longer-prefixes",
3148 "IPv6 forwarding table\n"
3149 "IPv6 routing table\n"
3152 "Show route matching the specified Network/Mask pair only\n")
3154 struct route_table
*table
;
3155 struct route_node
*rn
;
3160 vrf_id_t vrf_id
= VRF_DEFAULT
;
3161 bool uf
= use_fib(argv
[2]);
3163 if (strmatch(argv
[3]->text
, "vrf"))
3165 VRF_GET_ID (vrf_id
, argv
[4]->arg
);
3166 ret
= str2prefix (argv
[5]->arg
, &p
);
3170 ret
= str2prefix (argv
[3]->arg
, &p
);
3175 vty_out (vty
, "%% Malformed Prefix%s", VTY_NEWLINE
);
3179 table
= zebra_vrf_table (AFI_IP6
, SAFI_UNICAST
, vrf_id
);
3183 /* Show matched type IPv6 routes. */
3184 for (rn
= route_top (table
); rn
; rn
= srcdest_route_next (rn
))
3185 RNODE_FOREACH_RIB (rn
, rib
)
3187 struct prefix
*p
, *src_p
;
3188 srcdest_rnode_prefixes(rn
, &p
, &src_p
);
3190 if (uf
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
3192 if (prefix_match (p
, &rn
->p
))
3196 vty_out (vty
, SHOW_ROUTE_V6_HEADER
);
3199 vty_show_ip_route (vty
, rn
, rib
, NULL
);
3205 DEFUN (show_ipv6_route_protocol
,
3206 show_ipv6_route_protocol_cmd
,
3207 "show ipv6 <fib|route> [vrf NAME] " FRR_IP6_REDIST_STR_ZEBRA
,
3210 "IPv6 forwarding table\n"
3211 "IPv6 routing table\n"
3213 FRR_IP6_REDIST_HELP_STR_ZEBRA
)
3216 struct route_table
*table
;
3217 struct route_node
*rn
;
3220 vrf_id_t vrf_id
= VRF_DEFAULT
;
3221 bool uf
= use_fib(argv
[2]);
3224 if (argv_find (argv
, argc
, "NAME", &idx
))
3225 VRF_GET_ID (vrf_id
, argv
[idx
]->arg
);
3227 char *proto
= argv
[argc
- 1]->text
;
3228 type
= proto_redistnum (AFI_IP6
, proto
);
3232 vty_out (vty
, "Unknown route type%s", VTY_NEWLINE
);
3236 table
= zebra_vrf_table (AFI_IP6
, SAFI_UNICAST
, vrf_id
);
3240 /* Show matched type IPv6 routes. */
3241 for (rn
= route_top (table
); rn
; rn
= srcdest_route_next (rn
))
3242 RNODE_FOREACH_RIB (rn
, rib
)
3243 if (rib
->type
== type
)
3245 if (uf
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
3249 vty_out (vty
, SHOW_ROUTE_V6_HEADER
);
3252 vty_show_ip_route (vty
, rn
, rib
, NULL
);
3257 DEFUN (show_ipv6_route_addr
,
3258 show_ipv6_route_addr_cmd
,
3259 "show ipv6 route [vrf NAME] X:X::X:X",
3262 "IPv6 routing table\n"
3267 struct prefix_ipv6 p
;
3268 struct route_table
*table
;
3269 struct route_node
*rn
;
3270 vrf_id_t vrf_id
= VRF_DEFAULT
;
3272 if (strmatch(argv
[3]->text
, "vrf"))
3274 VRF_GET_ID (vrf_id
, argv
[4]->arg
);
3275 ret
= str2prefix_ipv6 (argv
[5]->arg
, &p
);
3279 ret
= str2prefix_ipv6 (argv
[3]->arg
, &p
);
3284 vty_out (vty
, "Malformed IPv6 address%s", VTY_NEWLINE
);
3288 table
= zebra_vrf_table (AFI_IP6
, SAFI_UNICAST
, vrf_id
);
3292 rn
= route_node_match (table
, (struct prefix
*) &p
);
3295 vty_out (vty
, "%% Network not in table%s", VTY_NEWLINE
);
3299 vty_show_ip_route_detail (vty
, rn
, 0);
3301 route_unlock_node (rn
);
3306 DEFUN (show_ipv6_route_prefix
,
3307 show_ipv6_route_prefix_cmd
,
3308 "show ipv6 route [vrf NAME] X:X::X:X/M",
3311 "IPv6 routing table\n"
3316 struct prefix_ipv6 p
;
3317 struct route_table
*table
;
3318 struct route_node
*rn
;
3319 vrf_id_t vrf_id
= VRF_DEFAULT
;
3321 if (strmatch(argv
[3]->text
, "vrf"))
3323 VRF_GET_ID (vrf_id
, argv
[4]->arg
);
3324 ret
= str2prefix_ipv6 (argv
[5]->arg
, &p
);
3327 ret
= str2prefix_ipv6 (argv
[3]->arg
, &p
);
3331 vty_out (vty
, "Malformed IPv6 prefix%s", VTY_NEWLINE
);
3335 table
= zebra_vrf_table (AFI_IP6
, SAFI_UNICAST
, vrf_id
);
3339 rn
= route_node_match (table
, (struct prefix
*) &p
);
3340 if (! rn
|| rn
->p
.prefixlen
!= p
.prefixlen
)
3342 vty_out (vty
, "%% Network not in table%s", VTY_NEWLINE
);
3346 vty_show_ip_route_detail (vty
, rn
, 0);
3348 route_unlock_node (rn
);
3354 /* Show route summary. */
3355 DEFUN (show_ipv6_route_summary
,
3356 show_ipv6_route_summary_cmd
,
3357 "show ipv6 route [vrf NAME] summary",
3360 "IPv6 routing table\n"
3362 "Summary of all IPv6 routes\n")
3364 struct route_table
*table
;
3365 vrf_id_t vrf_id
= VRF_DEFAULT
;
3367 if (strmatch(argv
[3]->text
, "vrf"))
3368 VRF_GET_ID (vrf_id
, argv
[4]->arg
);
3370 table
= zebra_vrf_table (AFI_IP6
, SAFI_UNICAST
, vrf_id
);
3374 vty_show_ip_route_summary (vty
, table
);
3380 /* Show ipv6 route summary prefix. */
3381 DEFUN (show_ipv6_route_summary_prefix
,
3382 show_ipv6_route_summary_prefix_cmd
,
3383 "show ipv6 route [vrf NAME] summary prefix",
3386 "IPv6 routing table\n"
3388 "Summary of all IPv6 routes\n"
3391 struct route_table
*table
;
3392 vrf_id_t vrf_id
= VRF_DEFAULT
;
3394 if (strmatch(argv
[3]->text
, "vrf"))
3395 VRF_GET_ID (vrf_id
, argv
[4]->arg
);
3397 table
= zebra_vrf_table (AFI_IP6
, SAFI_UNICAST
, vrf_id
);
3401 vty_show_ip_route_summary_prefix (vty
, table
);
3408 * Show IPv6 mroute command.Used to dump
3409 * the Multicast routing table.
3411 DEFUN (show_ipv6_mroute
,
3412 show_ipv6_mroute_cmd
,
3413 "show ipv6 mroute [vrf NAME]",
3416 "IPv6 Multicast routing table\n"
3419 struct route_table
*table
;
3420 struct route_node
*rn
;
3423 vrf_id_t vrf_id
= VRF_DEFAULT
;
3426 VRF_GET_ID (vrf_id
, argv
[4]->arg
);
3428 table
= zebra_vrf_table (AFI_IP6
, SAFI_MULTICAST
, vrf_id
);
3432 /* Show all IPv6 route. */
3433 for (rn
= route_top (table
); rn
; rn
= srcdest_route_next (rn
))
3434 RNODE_FOREACH_RIB (rn
, rib
)
3438 vty_out (vty
, SHOW_ROUTE_V6_HEADER
);
3441 vty_show_ip_route (vty
, rn
, rib
, NULL
);
3447 DEFUN (show_ipv6_route_vrf_all
,
3448 show_ipv6_route_vrf_all_cmd
,
3449 "show ipv6 <fib|route> vrf all",
3452 "IPv6 forwarding table\n"
3453 "IPv6 routing table\n"
3454 VRF_ALL_CMD_HELP_STR
)
3456 struct route_table
*table
;
3457 struct route_node
*rn
;
3460 struct zebra_vrf
*zvrf
;
3463 bool uf
= use_fib(argv
[2]);
3465 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
3467 if ((zvrf
= vrf
->info
) == NULL
||
3468 (table
= zvrf
->table
[AFI_IP6
][SAFI_UNICAST
]) == NULL
)
3471 /* Show all IPv6 route. */
3472 for (rn
= route_top (table
); rn
; rn
= srcdest_route_next (rn
))
3473 RNODE_FOREACH_RIB (rn
, rib
)
3475 if (uf
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
3479 vty_out (vty
, SHOW_ROUTE_V6_HEADER
);
3485 vty_out (vty
, "%sVRF %s:%s", VTY_NEWLINE
, zvrf_name (zvrf
), VTY_NEWLINE
);
3488 vty_show_ip_route (vty
, rn
, rib
, NULL
);
3496 DEFUN (show_ipv6_route_vrf_all_tag
,
3497 show_ipv6_route_vrf_all_tag_cmd
,
3498 "show ipv6 <fib|route> vrf all tag (1-4294967295)",
3501 "IPv6 forwarding table\n"
3502 "IPv6 routing table\n"
3503 VRF_ALL_CMD_HELP_STR
3504 "Show only routes with tag\n"
3508 struct route_table
*table
;
3509 struct route_node
*rn
;
3512 struct zebra_vrf
*zvrf
;
3515 route_tag_t tag
= 0;
3516 bool uf
= use_fib(argv
[2]);
3518 if (argv
[idx_number
]->arg
)
3519 VTY_GET_INTEGER_RANGE("tag", tag
, argv
[idx_number
]->arg
, 0, 4294967295);
3521 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
3523 if ((zvrf
= vrf
->info
) == NULL
||
3524 (table
= zvrf
->table
[AFI_IP6
][SAFI_UNICAST
]) == NULL
)
3527 /* Show all IPv6 routes with matching tag value. */
3528 for (rn
= route_top (table
); rn
; rn
= srcdest_route_next (rn
))
3529 RNODE_FOREACH_RIB (rn
, rib
)
3531 if (uf
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
3533 if (rib
->tag
!= tag
)
3538 vty_out (vty
, SHOW_ROUTE_V6_HEADER
);
3544 vty_out (vty
, "%sVRF %s:%s", VTY_NEWLINE
, zvrf_name (zvrf
), VTY_NEWLINE
);
3547 vty_show_ip_route (vty
, rn
, rib
, NULL
);
3555 DEFUN (show_ipv6_route_vrf_all_prefix_longer
,
3556 show_ipv6_route_vrf_all_prefix_longer_cmd
,
3557 "show ipv6 <fib|route> vrf all X:X::X:X/M longer-prefixes",
3560 "IPv6 forwarding table\n"
3561 "IPv6 routing table\n"
3562 VRF_ALL_CMD_HELP_STR
3564 "Show route matching the specified Network/Mask pair only\n")
3566 int idx_ipv6_prefixlen
= 5;
3567 struct route_table
*table
;
3568 struct route_node
*rn
;
3572 struct zebra_vrf
*zvrf
;
3576 bool uf
= use_fib(argv
[2]);
3578 ret
= str2prefix (argv
[idx_ipv6_prefixlen
]->arg
, &p
);
3581 vty_out (vty
, "%% Malformed Prefix%s", VTY_NEWLINE
);
3585 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
3587 if ((zvrf
= vrf
->info
) == NULL
||
3588 (table
= zvrf
->table
[AFI_IP6
][SAFI_UNICAST
]) == NULL
)
3591 /* Show matched type IPv6 routes. */
3592 for (rn
= route_top (table
); rn
; rn
= srcdest_route_next (rn
))
3593 RNODE_FOREACH_RIB (rn
, rib
)
3595 struct prefix
*p
, *src_p
;
3596 srcdest_rnode_prefixes(rn
, &p
, &src_p
);
3597 if (uf
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
3599 if (prefix_match (p
, &rn
->p
))
3603 vty_out (vty
, SHOW_ROUTE_V6_HEADER
);
3609 vty_out (vty
, "%sVRF %s:%s", VTY_NEWLINE
, zvrf_name (zvrf
), VTY_NEWLINE
);
3612 vty_show_ip_route (vty
, rn
, rib
, NULL
);
3621 DEFUN (show_ipv6_route_vrf_all_protocol
,
3622 show_ipv6_route_vrf_all_protocol_cmd
,
3623 "show ipv6 <fib|route> vrf all " FRR_IP6_REDIST_STR_ZEBRA
,
3626 "IPv6 forwarding table\n"
3627 "IPv6 routing table\n"
3628 VRF_ALL_CMD_HELP_STR
3629 FRR_IP6_REDIST_HELP_STR_ZEBRA
)
3632 struct route_table
*table
;
3633 struct route_node
*rn
;
3636 struct zebra_vrf
*zvrf
;
3639 bool uf
= use_fib(argv
[2]);
3641 char *proto
= argv
[argc
- 1]->text
;
3642 type
= proto_redistnum (AFI_IP6
, proto
);
3646 vty_out (vty
, "Unknown route type%s", VTY_NEWLINE
);
3650 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
3652 if ((zvrf
= vrf
->info
) == NULL
||
3653 (table
= zvrf
->table
[AFI_IP6
][SAFI_UNICAST
]) == NULL
)
3656 /* Show matched type IPv6 routes. */
3657 for (rn
= route_top (table
); rn
; rn
= srcdest_route_next (rn
))
3658 RNODE_FOREACH_RIB (rn
, rib
)
3659 if (rib
->type
== type
)
3661 if (uf
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
3665 vty_out (vty
, SHOW_ROUTE_V6_HEADER
);
3671 vty_out (vty
, "%sVRF %s:%s", VTY_NEWLINE
, zvrf_name (zvrf
), VTY_NEWLINE
);
3674 vty_show_ip_route (vty
, rn
, rib
, NULL
);
3682 DEFUN (show_ipv6_route_vrf_all_addr
,
3683 show_ipv6_route_vrf_all_addr_cmd
,
3684 "show ipv6 route vrf all X:X::X:X",
3687 "IPv6 routing table\n"
3688 VRF_ALL_CMD_HELP_STR
3693 struct prefix_ipv6 p
;
3694 struct route_table
*table
;
3695 struct route_node
*rn
;
3697 struct zebra_vrf
*zvrf
;
3699 ret
= str2prefix_ipv6 (argv
[idx_ipv6
]->arg
, &p
);
3702 vty_out (vty
, "Malformed IPv6 address%s", VTY_NEWLINE
);
3706 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
3708 if ((zvrf
= vrf
->info
) == NULL
||
3709 (table
= zvrf
->table
[AFI_IP6
][SAFI_UNICAST
]) == NULL
)
3712 rn
= route_node_match (table
, (struct prefix
*) &p
);
3716 vty_show_ip_route_detail (vty
, rn
, 0);
3718 route_unlock_node (rn
);
3724 DEFUN (show_ipv6_route_vrf_all_prefix
,
3725 show_ipv6_route_vrf_all_prefix_cmd
,
3726 "show ipv6 route vrf all X:X::X:X/M",
3729 "IPv6 routing table\n"
3730 VRF_ALL_CMD_HELP_STR
3733 int idx_ipv6_prefixlen
= 5;
3735 struct prefix_ipv6 p
;
3736 struct route_table
*table
;
3737 struct route_node
*rn
;
3739 struct zebra_vrf
*zvrf
;
3741 ret
= str2prefix_ipv6 (argv
[idx_ipv6_prefixlen
]->arg
, &p
);
3744 vty_out (vty
, "Malformed IPv6 prefix%s", VTY_NEWLINE
);
3748 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
3750 if ((zvrf
= vrf
->info
) == NULL
||
3751 (table
= zvrf
->table
[AFI_IP6
][SAFI_UNICAST
]) == NULL
)
3754 rn
= route_node_match (table
, (struct prefix
*) &p
);
3757 if (rn
->p
.prefixlen
!= p
.prefixlen
)
3759 route_unlock_node (rn
);
3763 vty_show_ip_route_detail (vty
, rn
, 0);
3765 route_unlock_node (rn
);
3771 DEFUN (show_ipv6_route_vrf_all_summary
,
3772 show_ipv6_route_vrf_all_summary_cmd
,
3773 "show ipv6 route vrf all summary",
3776 "IPv6 routing table\n"
3777 VRF_ALL_CMD_HELP_STR
3778 "Summary of all IPv6 routes\n")
3781 struct zebra_vrf
*zvrf
;
3783 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
3784 if ((zvrf
= vrf
->info
) != NULL
)
3785 vty_show_ip_route_summary (vty
, zvrf
->table
[AFI_IP6
][SAFI_UNICAST
]);
3790 DEFUN (show_ipv6_mroute_vrf_all
,
3791 show_ipv6_mroute_vrf_all_cmd
,
3792 "show ipv6 mroute vrf all",
3795 "IPv6 Multicast routing table\n"
3796 VRF_ALL_CMD_HELP_STR
)
3798 struct route_table
*table
;
3799 struct route_node
*rn
;
3802 struct zebra_vrf
*zvrf
;
3805 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
3807 if ((zvrf
= vrf
->info
) == NULL
||
3808 (table
= zvrf
->table
[AFI_IP6
][SAFI_MULTICAST
]) == NULL
)
3811 /* Show all IPv6 route. */
3812 for (rn
= route_top (table
); rn
; rn
= srcdest_route_next (rn
))
3813 RNODE_FOREACH_RIB (rn
, rib
)
3817 vty_out (vty
, SHOW_ROUTE_V6_HEADER
);
3820 vty_show_ip_route (vty
, rn
, rib
, NULL
);
3826 DEFUN (show_ipv6_route_vrf_all_summary_prefix
,
3827 show_ipv6_route_vrf_all_summary_prefix_cmd
,
3828 "show ipv6 route vrf all summary prefix",
3831 "IPv6 routing table\n"
3832 VRF_ALL_CMD_HELP_STR
3833 "Summary of all IPv6 routes\n"
3837 struct zebra_vrf
*zvrf
;
3839 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
3840 if ((zvrf
= vrf
->info
) != NULL
)
3841 vty_show_ip_route_summary_prefix (vty
, zvrf
->table
[AFI_IP6
][SAFI_UNICAST
]);
3846 /* Write IPv6 static route configuration. */
3848 static_config_ipv6 (struct vty
*vty
)
3850 struct route_node
*rn
;
3851 struct static_route
*si
;
3853 char buf
[SRCDEST2STR_BUFFER
];
3854 struct route_table
*stable
;
3856 struct zebra_vrf
*zvrf
;
3858 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
3860 if (!(zvrf
= vrf
->info
))
3862 if ((stable
= zvrf
->stable
[AFI_IP6
][SAFI_UNICAST
]) == NULL
)
3865 for (rn
= route_top (stable
); rn
; rn
= srcdest_route_next (rn
))
3866 for (si
= rn
->info
; si
; si
= si
->next
)
3868 vty_out (vty
, "ipv6 route %s", srcdest_rnode2str (rn
, buf
, sizeof buf
));
3872 case STATIC_IPV4_GATEWAY
:
3873 vty_out (vty
, " %s", inet_ntoa (si
->addr
.ipv4
));
3875 case STATIC_IPV6_GATEWAY
:
3876 vty_out (vty
, " %s", inet_ntop (AF_INET6
, &si
->addr
.ipv6
, buf
, BUFSIZ
));
3878 case STATIC_IFINDEX
:
3879 vty_out (vty
, " %s", si
->ifname
);
3881 case STATIC_BLACKHOLE
:
3882 vty_out (vty
, " Null0" );
3884 case STATIC_IPV6_GATEWAY_IFINDEX
:
3885 vty_out (vty
, " %s %s",
3886 inet_ntop (AF_INET6
, &si
->addr
.ipv6
, buf
, BUFSIZ
),
3887 ifindex2ifname (si
->ifindex
, si
->vrf_id
));
3891 /* flags are incompatible with STATIC_BLACKHOLE */
3892 if (si
->type
!= STATIC_BLACKHOLE
)
3894 if (CHECK_FLAG(si
->flags
, ZEBRA_FLAG_REJECT
))
3895 vty_out (vty
, " %s", "reject");
3896 if (CHECK_FLAG(si
->flags
, ZEBRA_FLAG_BLACKHOLE
))
3897 vty_out (vty
, " %s", "blackhole");
3901 vty_out (vty
, " tag %"ROUTE_TAG_PRI
, si
->tag
);
3903 if (si
->distance
!= ZEBRA_STATIC_DISTANCE_DEFAULT
)
3904 vty_out (vty
, " %d", si
->distance
);
3906 if (si
->vrf_id
!= VRF_DEFAULT
)
3908 vty_out (vty
, " vrf %s", zvrf_name (zvrf
));
3911 /* Label information */
3912 if (si
->snh_label
.num_labels
)
3913 vty_out (vty
, " label %s",
3914 mpls_label2str (si
->snh_label
.num_labels
,
3915 si
->snh_label
.label
, buf
, sizeof buf
, 0));
3917 vty_out (vty
, "%s", VTY_NEWLINE
);
3925 DEFUN (allow_external_route_update
,
3926 allow_external_route_update_cmd
,
3927 "allow-external-route-update",
3928 "Allow FRR routes to be overwritten by external processes\n")
3935 DEFUN (no_allow_external_route_update
,
3936 no_allow_external_route_update_cmd
,
3937 "no allow-external-route-update",
3939 "Allow FRR routes to be overwritten by external processes\n")
3954 struct zebra_vrf
*zvrf
;
3956 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
3958 if (!(zvrf
= vrf
->info
))
3960 if (!zvrf_id (zvrf
))
3963 vty_out (vty
, "vrf %s ", zvrf_name (zvrf
));
3964 if (zvrf_id (zvrf
) == VRF_UNKNOWN
)
3965 vty_out (vty
, "inactive");
3967 vty_out (vty
, "id %u table %u", zvrf_id (zvrf
), zvrf
->table_id
);
3968 vty_out (vty
, "%s", VTY_NEWLINE
);
3975 /* Static ip route configuration write function. */
3977 zebra_ip_config (struct vty
*vty
)
3981 write
+= static_config_ipv4 (vty
, SAFI_UNICAST
, "ip route");
3982 write
+= static_config_ipv4 (vty
, SAFI_MULTICAST
, "ip mroute");
3983 write
+= static_config_ipv6 (vty
);
3985 write
+= zebra_import_table_config (vty
);
3989 DEFUN (ip_zebra_import_table_distance
,
3990 ip_zebra_import_table_distance_cmd
,
3991 "ip import-table (1-252) [distance (1-255)] [route-map WORD]",
3993 "import routes from non-main kernel table\n"
3994 "kernel routing table id\n"
3995 "Distance for imported routes\n"
3996 "Default distance value\n"
3997 "route-map for filtering\n"
4000 u_int32_t table_id
= 0;
4002 VTY_GET_INTEGER("table", table_id
, argv
[2]->arg
);
4003 int distance
= ZEBRA_TABLE_DISTANCE_DEFAULT
;
4004 char *rmap
= strmatch (argv
[argc
- 2]->text
, "route-map") ?
4005 XSTRDUP(MTYPE_ROUTE_MAP_NAME
, argv
[argc
- 1]->arg
) : NULL
;
4006 if (argc
== 7 || (argc
== 5 && !rmap
))
4007 VTY_GET_INTEGER_RANGE("distance", distance
, argv
[4]->arg
, 1, 255);
4009 if (!is_zebra_valid_kernel_table(table_id
))
4011 vty_out(vty
, "Invalid routing table ID, %d. Must be in range 1-252%s",
4012 table_id
, VTY_NEWLINE
);
4016 if (is_zebra_main_routing_table(table_id
))
4018 vty_out(vty
, "Invalid routing table ID, %d. Must be non-default table%s",
4019 table_id
, VTY_NEWLINE
);
4023 return (zebra_import_table(AFI_IP
, table_id
, distance
, rmap
, 1));
4026 DEFUN (no_ip_zebra_import_table
,
4027 no_ip_zebra_import_table_cmd
,
4028 "no ip import-table (1-252) [distance (1-255)] [route-map NAME]",
4031 "import routes from non-main kernel table\n"
4032 "kernel routing table id\n"
4033 "Distance for imported routes\n"
4034 "Default distance value\n"
4035 "route-map for filtering\n"
4038 u_int32_t table_id
= 0;
4039 VTY_GET_INTEGER("table", table_id
, argv
[3]->arg
);
4041 if (!is_zebra_valid_kernel_table(table_id
))
4043 vty_out(vty
, "Invalid routing table ID. Must be in range 1-252%s",
4048 if (is_zebra_main_routing_table(table_id
))
4050 vty_out(vty
, "Invalid routing table ID, %d. Must be non-default table%s",
4051 table_id
, VTY_NEWLINE
);
4055 if (!is_zebra_import_table_enabled(AFI_IP
, table_id
))
4058 return (zebra_import_table(AFI_IP
, table_id
, 0, NULL
, 0));
4062 config_write_protocol (struct vty
*vty
)
4065 vty_out(vty
, "allow-external-route-update%s", VTY_NEWLINE
);
4067 if (zebra_rnh_ip_default_route
)
4068 vty_out(vty
, "ip nht resolve-via-default%s", VTY_NEWLINE
);
4070 if (zebra_rnh_ipv6_default_route
)
4071 vty_out(vty
, "ipv6 nht resolve-via-default%s", VTY_NEWLINE
);
4073 enum multicast_mode ipv4_multicast_mode
= multicast_mode_ipv4_get ();
4075 if (ipv4_multicast_mode
!= MCAST_NO_CONFIG
)
4076 vty_out (vty
, "ip multicast rpf-lookup-mode %s%s",
4077 ipv4_multicast_mode
== MCAST_URIB_ONLY
? "urib-only" :
4078 ipv4_multicast_mode
== MCAST_MRIB_ONLY
? "mrib-only" :
4079 ipv4_multicast_mode
== MCAST_MIX_MRIB_FIRST
? "mrib-then-urib" :
4080 ipv4_multicast_mode
== MCAST_MIX_DISTANCE
? "lower-distance" :
4084 zebra_routemap_config_write_protocol(vty
);
4089 /* IP node for static routes. */
4090 static struct cmd_node ip_node
= { IP_NODE
, "", 1 };
4091 static struct cmd_node protocol_node
= { PROTOCOL_NODE
, "", 1 };
4095 zebra_vty_init (void)
4097 install_node (&ip_node
, zebra_ip_config
);
4098 install_node (&protocol_node
, config_write_protocol
);
4100 install_element (CONFIG_NODE
, &allow_external_route_update_cmd
);
4101 install_element (CONFIG_NODE
, &no_allow_external_route_update_cmd
);
4102 install_element (CONFIG_NODE
, &ip_mroute_dist_cmd
);
4103 install_element (CONFIG_NODE
, &no_ip_mroute_dist_cmd
);
4104 install_element (CONFIG_NODE
, &ip_multicast_mode_cmd
);
4105 install_element (CONFIG_NODE
, &no_ip_multicast_mode_cmd
);
4106 install_element (CONFIG_NODE
, &ip_route_cmd
);
4107 install_element (CONFIG_NODE
, &ip_route_flags_cmd
);
4108 install_element (CONFIG_NODE
, &ip_route_mask_cmd
);
4109 install_element (CONFIG_NODE
, &ip_route_mask_flags_cmd
);
4110 install_element (CONFIG_NODE
, &no_ip_route_cmd
);
4111 install_element (CONFIG_NODE
, &no_ip_route_mask_cmd
);
4112 install_element (CONFIG_NODE
, &ip_zebra_import_table_distance_cmd
);
4113 install_element (CONFIG_NODE
, &no_ip_zebra_import_table_cmd
);
4115 install_element (VIEW_NODE
, &show_vrf_cmd
);
4116 install_element (VIEW_NODE
, &show_ip_route_cmd
);
4117 install_element (VIEW_NODE
, &show_ip_route_ospf_instance_cmd
);
4118 install_element (VIEW_NODE
, &show_ip_route_tag_cmd
);
4119 install_element (VIEW_NODE
, &show_ip_nht_cmd
);
4120 install_element (VIEW_NODE
, &show_ip_nht_vrf_all_cmd
);
4121 install_element (VIEW_NODE
, &show_ipv6_nht_cmd
);
4122 install_element (VIEW_NODE
, &show_ipv6_nht_vrf_all_cmd
);
4123 install_element (VIEW_NODE
, &show_ip_route_addr_cmd
);
4124 install_element (VIEW_NODE
, &show_ip_route_prefix_cmd
);
4125 install_element (VIEW_NODE
, &show_ip_route_prefix_longer_cmd
);
4126 install_element (VIEW_NODE
, &show_ip_route_protocol_cmd
);
4127 install_element (VIEW_NODE
, &show_ip_route_supernets_cmd
);
4128 install_element (VIEW_NODE
, &show_ip_route_summary_cmd
);
4129 install_element (VIEW_NODE
, &show_ip_route_summary_prefix_cmd
);
4131 install_element (VIEW_NODE
, &show_ip_rpf_cmd
);
4132 install_element (VIEW_NODE
, &show_ip_rpf_addr_cmd
);
4134 /* Commands for VRF */
4136 install_element (CONFIG_NODE
, &no_ip_route_flags_cmd
);
4137 install_element (CONFIG_NODE
, &no_ip_route_mask_flags_cmd
);
4139 install_element (VIEW_NODE
, &show_ip_route_vrf_cmd
);
4141 install_element (VIEW_NODE
, &show_ip_route_vrf_all_cmd
);
4142 install_element (VIEW_NODE
, &show_ip_route_vrf_all_tag_cmd
);
4143 install_element (VIEW_NODE
, &show_ip_route_vrf_all_addr_cmd
);
4144 install_element (VIEW_NODE
, &show_ip_route_vrf_all_prefix_cmd
);
4145 install_element (VIEW_NODE
, &show_ip_route_vrf_all_prefix_longer_cmd
);
4146 install_element (VIEW_NODE
, &show_ip_route_vrf_all_protocol_cmd
);
4147 install_element (VIEW_NODE
, &show_ip_route_vrf_all_supernets_cmd
);
4148 install_element (VIEW_NODE
, &show_ip_route_vrf_all_summary_cmd
);
4149 install_element (VIEW_NODE
, &show_ip_route_vrf_all_summary_prefix_cmd
);
4151 install_element (CONFIG_NODE
, &ipv6_route_cmd
);
4152 install_element (CONFIG_NODE
, &ipv6_route_flags_cmd
);
4153 install_element (CONFIG_NODE
, &ipv6_route_ifname_cmd
);
4154 install_element (CONFIG_NODE
, &ipv6_route_ifname_flags_cmd
);
4155 install_element (CONFIG_NODE
, &no_ipv6_route_cmd
);
4156 install_element (CONFIG_NODE
, &no_ipv6_route_flags_cmd
);
4157 install_element (CONFIG_NODE
, &no_ipv6_route_ifname_cmd
);
4158 install_element (CONFIG_NODE
, &no_ipv6_route_ifname_flags_cmd
);
4159 install_element (CONFIG_NODE
, &ip_nht_default_route_cmd
);
4160 install_element (CONFIG_NODE
, &no_ip_nht_default_route_cmd
);
4161 install_element (CONFIG_NODE
, &ipv6_nht_default_route_cmd
);
4162 install_element (CONFIG_NODE
, &no_ipv6_nht_default_route_cmd
);
4163 install_element (VIEW_NODE
, &show_ipv6_route_cmd
);
4164 install_element (VIEW_NODE
, &show_ipv6_route_tag_cmd
);
4165 install_element (VIEW_NODE
, &show_ipv6_route_summary_cmd
);
4166 install_element (VIEW_NODE
, &show_ipv6_route_summary_prefix_cmd
);
4167 install_element (VIEW_NODE
, &show_ipv6_route_protocol_cmd
);
4168 install_element (VIEW_NODE
, &show_ipv6_route_addr_cmd
);
4169 install_element (VIEW_NODE
, &show_ipv6_route_prefix_cmd
);
4170 install_element (VIEW_NODE
, &show_ipv6_route_prefix_longer_cmd
);
4172 install_element (VIEW_NODE
, &show_ipv6_mroute_cmd
);
4174 /* Commands for VRF */
4175 install_element (VIEW_NODE
, &show_ipv6_route_vrf_all_cmd
);
4176 install_element (VIEW_NODE
, &show_ipv6_route_vrf_all_tag_cmd
);
4177 install_element (VIEW_NODE
, &show_ipv6_route_vrf_all_summary_cmd
);
4178 install_element (VIEW_NODE
, &show_ipv6_route_vrf_all_summary_prefix_cmd
);
4179 install_element (VIEW_NODE
, &show_ipv6_route_vrf_all_protocol_cmd
);
4180 install_element (VIEW_NODE
, &show_ipv6_route_vrf_all_addr_cmd
);
4181 install_element (VIEW_NODE
, &show_ipv6_route_vrf_all_prefix_cmd
);
4182 install_element (VIEW_NODE
, &show_ipv6_route_vrf_all_prefix_longer_cmd
);
4184 install_element (VIEW_NODE
, &show_ipv6_mroute_vrf_all_cmd
);