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 along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "zebra_memory.h"
34 #include "srcdest_table.h"
36 #include "zebra/zserv.h"
37 #include "zebra/zebra_vrf.h"
38 #include "zebra/zebra_mpls.h"
39 #include "zebra/zebra_rnh.h"
40 #include "zebra/redistribute.h"
41 #include "zebra/zebra_routemap.h"
42 #include "zebra/zebra_static.h"
45 extern int allow_delete
;
47 static int do_show_ip_route(struct vty
*vty
, const char *vrf_name
,
48 safi_t safi
, bool use_fib
, u_char use_json
);
49 static void vty_show_ip_route_detail (struct vty
*vty
, struct route_node
*rn
,
52 #define ONE_DAY_SECOND 60*60*24
53 #define ONE_WEEK_SECOND 60*60*24*7
55 /* General function for static route. */
57 zebra_static_ipv4 (struct vty
*vty
, safi_t safi
, int add_cmd
,
58 const char *dest_str
, const char *mask_str
,
59 const char *gate_str
, const char *flag_str
,
60 const char *tag_str
, const char *distance_str
,
61 const char *vrf_id_str
, const char *label_str
)
70 struct zebra_vrf
*zvrf
= NULL
;
71 unsigned int ifindex
= 0;
72 const char *ifname
= NULL
;
73 u_char type
= STATIC_BLACKHOLE
;
74 struct static_nh_label snh_label
;
76 memset (&snh_label
, 0, sizeof (struct static_nh_label
));
77 ret
= str2prefix (dest_str
, &p
);
80 vty_out (vty
, "%% Malformed address%s", VTY_NEWLINE
);
84 /* Cisco like mask notation. */
87 ret
= inet_aton (mask_str
, &mask
);
90 vty_out (vty
, "%% Malformed address%s", VTY_NEWLINE
);
93 p
.prefixlen
= ip_masklen (mask
);
96 /* Apply mask for given prefix. */
99 /* Administrative distance. */
101 distance
= atoi (distance_str
);
103 distance
= ZEBRA_STATIC_DISTANCE_DEFAULT
;
107 VTY_GET_INTEGER_RANGE("tag", tag
, tag_str
, 0, 4294967295);
110 zvrf
= zebra_vrf_lookup_by_name (vrf_id_str
);
114 vty_out (vty
, "%% vrf %s is not defined%s", vrf_id_str
, VTY_NEWLINE
);
123 vty_out (vty
, "%% MPLS not turned on in kernel, ignoring command%s",
127 if (mpls_str2label (label_str
, &snh_label
.num_labels
,
130 vty_out (vty
, "%% Malformed label(s)%s", VTY_NEWLINE
);
135 /* Null0 static route. */
136 if ((gate_str
!= NULL
) && (strncasecmp (gate_str
, "Null0", strlen (gate_str
)) == 0))
140 vty_out (vty
, "%% can not have flag %s with Null0%s", flag_str
, VTY_NEWLINE
);
144 static_add_route (AFI_IP
, safi
, type
, &p
, NULL
, NULL
, ifindex
, ifname
,
145 ZEBRA_FLAG_BLACKHOLE
, tag
, distance
, zvrf
, &snh_label
);
147 static_delete_route (AFI_IP
, safi
, type
, &p
, NULL
, NULL
, ifindex
, tag
,
148 distance
, zvrf
, &snh_label
);
154 switch(flag_str
[0]) {
157 SET_FLAG (flag
, ZEBRA_FLAG_REJECT
);
161 SET_FLAG (flag
, ZEBRA_FLAG_BLACKHOLE
);
164 vty_out (vty
, "%% Malformed flag %s %s", flag_str
, VTY_NEWLINE
);
169 if (gate_str
== NULL
)
172 static_add_route (AFI_IP
, safi
, type
, &p
, NULL
, NULL
, ifindex
, ifname
, flag
,
173 tag
, distance
, zvrf
, &snh_label
);
175 static_delete_route (AFI_IP
, safi
, type
, &p
, NULL
, NULL
, ifindex
, tag
, distance
,
181 /* When gateway is A.B.C.D format, gate is treated as nexthop
182 address other case gate is treated as interface name. */
183 ret
= inet_aton (gate_str
, &gate
);
186 struct interface
*ifp
= if_lookup_by_name (gate_str
, zvrf_id (zvrf
));
189 vty_out (vty
, "%% Unknown interface: %s%s", gate_str
, VTY_NEWLINE
);
190 ifindex
= IFINDEX_DELETED
;
193 ifindex
= ifp
->ifindex
;
195 type
= STATIC_IFINDEX
;
198 type
= STATIC_IPV4_GATEWAY
;
201 static_add_route (AFI_IP
, safi
, type
, &p
, NULL
,
202 ifindex
? NULL
: (union g_addr
*)&gate
, ifindex
, ifname
,
203 flag
, tag
, distance
, zvrf
, &snh_label
);
205 static_delete_route (AFI_IP
, safi
, type
, &p
, NULL
,
206 ifindex
? NULL
: (union g_addr
*)&gate
, ifindex
, tag
,
207 distance
, zvrf
, &snh_label
);
212 /* Static unicast routes for multicast RPF lookup. */
213 DEFUN (ip_mroute_dist
,
215 "ip mroute A.B.C.D/M <A.B.C.D|INTERFACE> [(1-255)]",
217 "Configure static unicast route into MRIB for multicast RPF lookup\n"
218 "IP destination prefix (e.g. 10.0.0.0/8)\n"
220 "Nexthop interface name\n"
223 char *destprefix
= argv
[2]->arg
;
224 char *nexthop
= argv
[3]->arg
;
225 char *distance
= (argc
== 5) ? argv
[4]->arg
: NULL
;
227 return zebra_static_ipv4 (vty
, SAFI_MULTICAST
, 1, destprefix
, NULL
, nexthop
, NULL
, NULL
, distance
, NULL
, NULL
);
230 DEFUN (no_ip_mroute_dist
,
231 no_ip_mroute_dist_cmd
,
232 "no ip mroute A.B.C.D/M <A.B.C.D|INTERFACE> [(1-255)]",
235 "Configure static unicast route into MRIB for multicast RPF lookup\n"
236 "IP destination prefix (e.g. 10.0.0.0/8)\n"
238 "Nexthop interface name\n"
241 char *destprefix
= argv
[3]->arg
;
242 char *nexthop
= argv
[4]->arg
;
243 char *distance
= (argc
== 6) ? argv
[5]->arg
: NULL
;
245 return zebra_static_ipv4 (vty
, SAFI_MULTICAST
, 0, destprefix
, NULL
, nexthop
, NULL
, NULL
, distance
, NULL
, NULL
);
248 DEFUN (ip_multicast_mode
,
249 ip_multicast_mode_cmd
,
250 "ip multicast rpf-lookup-mode <urib-only|mrib-only|mrib-then-urib|lower-distance|longer-prefix>",
252 "Multicast options\n"
253 "RPF lookup behavior\n"
254 "Lookup in unicast RIB only\n"
255 "Lookup in multicast RIB only\n"
256 "Try multicast RIB first, fall back to unicast RIB\n"
257 "Lookup both, use entry with lower distance\n"
258 "Lookup both, use entry with longer prefix\n")
260 char *mode
= argv
[3]->text
;
262 if (strmatch (mode
, "urib-only"))
263 multicast_mode_ipv4_set (MCAST_URIB_ONLY
);
264 else if (strmatch (mode
, "mrib-only"))
265 multicast_mode_ipv4_set (MCAST_MRIB_ONLY
);
266 else if (strmatch (mode
, "mrib-then-urib"))
267 multicast_mode_ipv4_set (MCAST_MIX_MRIB_FIRST
);
268 else if (strmatch (mode
, "lower-distance"))
269 multicast_mode_ipv4_set (MCAST_MIX_DISTANCE
);
270 else if (strmatch (mode
, "longer-prefix"))
271 multicast_mode_ipv4_set (MCAST_MIX_PFXLEN
);
274 vty_out (vty
, "Invalid mode specified%s", VTY_NEWLINE
);
281 DEFUN (no_ip_multicast_mode
,
282 no_ip_multicast_mode_cmd
,
283 "no ip multicast rpf-lookup-mode [<urib-only|mrib-only|mrib-then-urib|lower-distance|longer-prefix>]",
286 "Multicast options\n"
287 "RPF lookup behavior\n"
288 "Lookup in unicast RIB only\n"
289 "Lookup in multicast RIB only\n"
290 "Try multicast RIB first, fall back to unicast RIB\n"
291 "Lookup both, use entry with lower distance\n"
292 "Lookup both, use entry with longer prefix\n")
294 multicast_mode_ipv4_set (MCAST_NO_CONFIG
);
304 "Display RPF information for multicast source\n")
306 return do_show_ip_route(vty
, VRF_DEFAULT_NAME
, SAFI_MULTICAST
, false, 0);
309 DEFUN (show_ip_rpf_addr
,
310 show_ip_rpf_addr_cmd
,
311 "show ip rpf A.B.C.D",
314 "Display RPF information for multicast source\n"
315 "IP multicast source address (e.g. 10.0.0.0)\n")
319 struct route_node
*rn
;
323 ret
= inet_aton (argv
[idx_ipv4
]->arg
, &addr
);
326 vty_out (vty
, "%% Malformed address%s", VTY_NEWLINE
);
330 rib
= rib_match_ipv4_multicast (VRF_DEFAULT
, addr
, &rn
);
333 vty_show_ip_route_detail (vty
, rn
, 1);
335 vty_out (vty
, "%% No match for RPF lookup%s", VTY_NEWLINE
);
341 zebra_vty_ip_route_tdv_helper (int argc
, struct cmd_token
*argv
[],
342 int idx_curr
, char **tag
,
343 char **distance
, char **vrf
, char **labels
)
346 while (idx_curr
< argc
)
348 if (strmatch (argv
[idx_curr
]->text
, "tag"))
351 *tag
= argv
[idx_curr
+1]->arg
;
354 else if (strmatch (argv
[idx_curr
]->text
, "vrf"))
357 *vrf
= argv
[idx_curr
+1]->arg
;
360 else if (strmatch (argv
[idx_curr
]->text
, "label"))
363 *labels
= argv
[idx_curr
+1]->arg
;
369 *distance
= argv
[idx_curr
]->arg
;
377 /* Static route configuration. */
380 "ip route A.B.C.D/M <A.B.C.D|INTERFACE|null0> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
382 "Establish static routes\n"
383 "IP destination prefix (e.g. 10.0.0.0/8)\n"
384 "IP gateway address\n"
385 "IP gateway interface name\n"
387 "Set tag for this route\n"
389 "Distance value for this route\n"
392 int idx_ipv4_prefixlen
= 2;
393 int idx_ipv4_ifname_null
= 3;
395 char *tag
, *distance
, *vrf
;
397 tag
= distance
= vrf
= NULL
;
398 zebra_vty_ip_route_tdv_helper (argc
, argv
, idx_curr
, &tag
, &distance
, &vrf
, NULL
);
400 return zebra_static_ipv4 (vty
, SAFI_UNICAST
, 1,
401 argv
[idx_ipv4_prefixlen
]->arg
,
403 argv
[idx_ipv4_ifname_null
]->arg
,
405 tag
, distance
, vrf
, NULL
);
408 DEFUN (ip_route_flags
,
410 "ip route A.B.C.D/M <reject|blackhole> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
412 "Establish static routes\n"
413 "IP destination prefix (e.g. 10.0.0.0/8)\n"
414 "Emit an ICMP unreachable when matched\n"
415 "Silently discard pkts when matched\n"
416 "Set tag for this route\n"
418 "Distance value for this route\n"
420 "Specify labels for this route\n"
421 "One or more labels separated by '/'\n")
423 int idx_ipv4_prefixlen
= 2;
424 int idx_reject_blackhole
= 3;
426 char *tag
, *distance
, *vrf
;
428 tag
= distance
= vrf
= NULL
;
429 zebra_vty_ip_route_tdv_helper (argc
, argv
, idx_curr
, &tag
, &distance
, &vrf
, NULL
);
431 return zebra_static_ipv4 (vty
, SAFI_UNICAST
, 1,
432 argv
[idx_ipv4_prefixlen
]->arg
,
435 argv
[idx_reject_blackhole
]->arg
,
436 tag
, distance
, vrf
, NULL
);
439 /* Mask as A.B.C.D format. */
440 DEFUN (ip_route_mask
,
442 "ip route A.B.C.D A.B.C.D <A.B.C.D|INTERFACE|null0> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
444 "Establish static routes\n"
445 "IP destination prefix\n"
446 "IP destination prefix mask\n"
447 "IP gateway address\n"
448 "IP gateway interface name\n"
450 "Set tag for this route\n"
452 "Distance value for this route\n"
454 "Specify labels for this route\n"
455 "One or more labels separated by '/'\n")
459 int idx_ipv4_ifname_null
= 4;
461 char *tag
, *distance
, *vrf
;
463 tag
= distance
= vrf
= NULL
;
464 zebra_vty_ip_route_tdv_helper (argc
, argv
, idx_curr
, &tag
, &distance
, &vrf
, NULL
);
466 return zebra_static_ipv4 (vty
, SAFI_UNICAST
, 1,
468 argv
[idx_ipv4_2
]->arg
,
469 argv
[idx_ipv4_ifname_null
]->arg
,
470 NULL
, tag
, distance
, vrf
, NULL
);
473 DEFUN (ip_route_mask_flags
,
474 ip_route_mask_flags_cmd
,
475 "ip route A.B.C.D A.B.C.D <reject|blackhole> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
477 "Establish static routes\n"
478 "IP destination prefix\n"
479 "IP destination prefix mask\n"
480 "Emit an ICMP unreachable when matched\n"
481 "Silently discard pkts when matched\n"
482 "Set tag for this route\n"
484 "Distance value for this route\n"
486 "Specify labels for this route\n"
487 "One or more labels separated by '/'\n")
491 int idx_reject_blackhole
= 4;
493 char *tag
, *distance
, *vrf
;
495 tag
= distance
= vrf
= NULL
;
496 zebra_vty_ip_route_tdv_helper (argc
, argv
, idx_curr
, &tag
, &distance
, &vrf
, NULL
);
498 return zebra_static_ipv4 (vty
, SAFI_UNICAST
, 1,
500 argv
[idx_ipv4_2
]->arg
,
502 argv
[idx_reject_blackhole
]->arg
,
503 tag
, distance
, vrf
, NULL
);
508 "no ip route A.B.C.D/M <A.B.C.D|INTERFACE|null0> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
511 "Establish static routes\n"
512 "IP destination prefix (e.g. 10.0.0.0/8)\n"
513 "IP gateway address\n"
514 "IP gateway interface name\n"
516 "Tag of this route\n"
518 "Distance value for this route\n"
520 "Specify labels for this route\n"
521 "One or more labels separated by '/'\n")
523 int idx_ipv4_prefixlen
= 3;
524 int idx_ipv4_ifname_null
= 4;
526 char *tag
, *distance
, *vrf
;
528 tag
= distance
= vrf
= NULL
;
529 zebra_vty_ip_route_tdv_helper (argc
, argv
, idx_curr
, &tag
, &distance
, &vrf
, NULL
);
531 return zebra_static_ipv4 (vty
, SAFI_UNICAST
, 0,
532 argv
[idx_ipv4_prefixlen
]->arg
,
534 argv
[idx_ipv4_ifname_null
]->arg
,
536 tag
, distance
, vrf
, NULL
);
539 DEFUN (no_ip_route_flags
,
540 no_ip_route_flags_cmd
,
541 "no ip route A.B.C.D/M <reject|blackhole> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
544 "Establish static routes\n"
545 "IP destination prefix (e.g. 10.0.0.0/8)\n"
546 "Emit an ICMP unreachable when matched\n"
547 "Silently discard pkts when matched\n"
548 "Tag of this route\n"
550 "Distance value for this route\n"
552 "Specify labels for this route\n"
553 "One or more labels separated by '/'\n")
555 int idx_ipv4_prefixlen
= 3;
557 char *tag
, *distance
, *vrf
;
559 tag
= distance
= vrf
= NULL
;
560 zebra_vty_ip_route_tdv_helper (argc
, argv
, idx_curr
, &tag
, &distance
, &vrf
, NULL
);
562 return zebra_static_ipv4 (vty
, SAFI_UNICAST
, 0,
563 argv
[idx_ipv4_prefixlen
]->arg
,
565 tag
, distance
, vrf
, NULL
);
568 DEFUN (no_ip_route_mask
,
569 no_ip_route_mask_cmd
,
570 "no ip route A.B.C.D A.B.C.D <A.B.C.D|INTERFACE|null0> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
573 "Establish static routes\n"
574 "IP destination prefix\n"
575 "IP destination prefix mask\n"
576 "IP gateway address\n"
577 "IP gateway interface name\n"
579 "Tag of this route\n"
581 "Distance value for this route\n"
583 "Specify labels for this route\n"
584 "One or more labels separated by '/'\n")
588 int idx_ipv4_ifname_null
= 5;
590 char *tag
, *distance
, *vrf
;
592 tag
= distance
= vrf
= NULL
;
593 zebra_vty_ip_route_tdv_helper (argc
, argv
, idx_curr
, &tag
, &distance
, &vrf
, NULL
);
595 return zebra_static_ipv4 (vty
, SAFI_UNICAST
, 0,
597 argv
[idx_ipv4_2
]->arg
,
598 argv
[idx_ipv4_ifname_null
]->arg
,
600 tag
, distance
, vrf
, NULL
);
603 DEFUN (no_ip_route_mask_flags
,
604 no_ip_route_mask_flags_cmd
,
605 "no ip route A.B.C.D A.B.C.D <reject|blackhole> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
608 "Establish static routes\n"
609 "IP destination prefix\n"
610 "IP destination prefix mask\n"
611 "Emit an ICMP unreachable when matched\n"
612 "Silently discard pkts when matched\n"
613 "Tag of this route\n"
615 "Distance value for this route\n"
617 "Specify labels for this route\n"
618 "One or more labels separated by '/'\n")
623 char *tag
, *distance
, *vrf
;
625 tag
= distance
= vrf
= NULL
;
626 zebra_vty_ip_route_tdv_helper (argc
, argv
, idx_curr
, &tag
, &distance
, &vrf
, NULL
);
628 return zebra_static_ipv4 (vty
, SAFI_UNICAST
, 0,
630 argv
[idx_ipv4_2
]->arg
,
632 tag
, distance
, vrf
, NULL
);
635 /* New RIB. Detailed information for IPv4 route. */
637 vty_show_ip_route_detail (struct vty
*vty
, struct route_node
*rn
, int mcast
)
640 struct nexthop
*nexthop
, *tnexthop
;
642 char buf
[SRCDEST2STR_BUFFER
];
643 struct zebra_vrf
*zvrf
;
645 RNODE_FOREACH_RIB (rn
, rib
)
647 const char *mcast_info
= "";
650 rib_table_info_t
*info
= srcdest_rnode_table_info(rn
);
651 mcast_info
= (info
->safi
== SAFI_MULTICAST
)
652 ? " using Multicast RIB"
653 : " using Unicast RIB";
656 vty_out (vty
, "Routing entry for %s%s%s",
657 srcdest_rnode2str(rn
, buf
, sizeof(buf
)), mcast_info
,
659 vty_out (vty
, " Known via \"%s", zebra_route_string (rib
->type
));
661 vty_out (vty
, "[%d]", rib
->instance
);
663 vty_out (vty
, ", distance %u, metric %u", rib
->distance
, rib
->metric
);
665 vty_out (vty
, ", tag %d", rib
->tag
);
667 vty_out (vty
, ", mtu %u", rib
->mtu
);
668 if (rib
->vrf_id
!= VRF_DEFAULT
)
670 zvrf
= vrf_info_lookup(rib
->vrf_id
);
671 vty_out (vty
, ", vrf %s", zvrf_name (zvrf
));
673 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_SELECTED
))
674 vty_out (vty
, ", best");
676 vty_out (vty
, ", refcnt %ld", rib
->refcnt
);
677 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_BLACKHOLE
))
678 vty_out (vty
, ", blackhole");
679 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_REJECT
))
680 vty_out (vty
, ", reject");
681 vty_out (vty
, "%s", VTY_NEWLINE
);
683 if (rib
->type
== ZEBRA_ROUTE_RIP
684 || rib
->type
== ZEBRA_ROUTE_OSPF
685 || rib
->type
== ZEBRA_ROUTE_ISIS
686 || rib
->type
== ZEBRA_ROUTE_NHRP
687 || rib
->type
== ZEBRA_ROUTE_TABLE
688 || rib
->type
== ZEBRA_ROUTE_BGP
)
693 uptime
= time (NULL
);
694 uptime
-= rib
->uptime
;
695 tm
= gmtime (&uptime
);
697 vty_out (vty
, " Last update ");
699 if (uptime
< ONE_DAY_SECOND
)
700 vty_out (vty
, "%02d:%02d:%02d",
701 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
702 else if (uptime
< ONE_WEEK_SECOND
)
703 vty_out (vty
, "%dd%02dh%02dm",
704 tm
->tm_yday
, tm
->tm_hour
, tm
->tm_min
);
706 vty_out (vty
, "%02dw%dd%02dh",
708 tm
->tm_yday
- ((tm
->tm_yday
/7) * 7), tm
->tm_hour
);
709 vty_out (vty
, " ago%s", VTY_NEWLINE
);
712 for (ALL_NEXTHOPS_RO(rib
->nexthop
, nexthop
, tnexthop
, recursing
))
716 vty_out (vty
, " %c%s",
717 CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
) ? '*' : ' ',
718 recursing
? " " : "");
720 switch (nexthop
->type
)
722 case NEXTHOP_TYPE_IPV4
:
723 case NEXTHOP_TYPE_IPV4_IFINDEX
:
724 vty_out (vty
, " %s", inet_ntoa (nexthop
->gate
.ipv4
));
725 if (nexthop
->ifindex
)
726 vty_out (vty
, ", via %s",
727 ifindex2ifname (nexthop
->ifindex
, rib
->vrf_id
));
729 case NEXTHOP_TYPE_IPV6
:
730 case NEXTHOP_TYPE_IPV6_IFINDEX
:
732 inet_ntop (AF_INET6
, &nexthop
->gate
.ipv6
, buf
, BUFSIZ
));
733 if (nexthop
->ifindex
)
734 vty_out (vty
, ", via %s",
735 ifindex2ifname (nexthop
->ifindex
, rib
->vrf_id
));
737 case NEXTHOP_TYPE_IFINDEX
:
738 vty_out (vty
, " directly connected, %s",
739 ifindex2ifname (nexthop
->ifindex
, rib
->vrf_id
));
741 case NEXTHOP_TYPE_BLACKHOLE
:
742 vty_out (vty
, " directly connected, Null0");
747 if (! CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
))
748 vty_out (vty
, " inactive");
750 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_ONLINK
))
751 vty_out (vty
, " onlink");
753 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_RECURSIVE
))
754 vty_out (vty
, " (recursive)");
756 switch (nexthop
->type
)
758 case NEXTHOP_TYPE_IPV4
:
759 case NEXTHOP_TYPE_IPV4_IFINDEX
:
760 if (nexthop
->src
.ipv4
.s_addr
)
762 if (inet_ntop(AF_INET
, &nexthop
->src
.ipv4
, addrstr
,
764 vty_out (vty
, ", src %s", addrstr
);
767 case NEXTHOP_TYPE_IPV6
:
768 case NEXTHOP_TYPE_IPV6_IFINDEX
:
769 if (!IPV6_ADDR_SAME(&nexthop
->src
.ipv6
, &in6addr_any
))
771 if (inet_ntop(AF_INET6
, &nexthop
->src
.ipv6
, addrstr
,
773 vty_out (vty
, ", src %s", addrstr
);
780 /* Label information */
781 if (nexthop
->nh_label
&& nexthop
->nh_label
->num_labels
)
783 vty_out (vty
, ", label %s",
784 mpls_label2str (nexthop
->nh_label
->num_labels
,
785 nexthop
->nh_label
->label
, buf
, BUFSIZ
, 1));
788 vty_out (vty
, "%s", VTY_NEWLINE
);
790 vty_out (vty
, "%s", VTY_NEWLINE
);
795 vty_show_ip_route (struct vty
*vty
, struct route_node
*rn
, struct rib
*rib
,
798 struct nexthop
*nexthop
, *tnexthop
;
801 char buf
[SRCDEST2STR_BUFFER
];
802 json_object
*json_nexthops
= NULL
;
803 json_object
*json_nexthop
= NULL
;
804 json_object
*json_route
= NULL
;
805 json_object
*json_labels
= NULL
;
809 json_route
= json_object_new_object();
810 json_nexthops
= json_object_new_array();
812 json_object_string_add(json_route
, "prefix", srcdest_rnode2str (rn
, buf
, sizeof buf
));
813 json_object_string_add(json_route
, "protocol", zebra_route_string(rib
->type
));
816 json_object_int_add(json_route
, "instance", rib
->instance
);
819 json_object_int_add(json_route
, "vrfId", rib
->vrf_id
);
821 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_SELECTED
))
822 json_object_boolean_true_add(json_route
, "selected");
824 if (rib
->type
!= ZEBRA_ROUTE_CONNECT
&& rib
->type
!= ZEBRA_ROUTE_KERNEL
)
826 json_object_int_add(json_route
, "distance", rib
->distance
);
827 json_object_int_add(json_route
, "metric", rib
->metric
);
830 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_BLACKHOLE
))
831 json_object_boolean_true_add(json_route
, "blackhole");
833 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_REJECT
))
834 json_object_boolean_true_add(json_route
, "reject");
836 if (rib
->type
== ZEBRA_ROUTE_RIP
837 || rib
->type
== ZEBRA_ROUTE_OSPF
838 || rib
->type
== ZEBRA_ROUTE_ISIS
839 || rib
->type
== ZEBRA_ROUTE_NHRP
840 || rib
->type
== ZEBRA_ROUTE_TABLE
841 || rib
->type
== ZEBRA_ROUTE_BGP
)
846 uptime
= time (NULL
);
847 uptime
-= rib
->uptime
;
848 tm
= gmtime (&uptime
);
850 if (uptime
< ONE_DAY_SECOND
)
851 sprintf(buf
, "%02d:%02d:%02d", tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
852 else if (uptime
< ONE_WEEK_SECOND
)
853 sprintf(buf
, "%dd%02dh%02dm", tm
->tm_yday
, tm
->tm_hour
, tm
->tm_min
);
855 sprintf(buf
, "%02dw%dd%02dh", tm
->tm_yday
/7, tm
->tm_yday
- ((tm
->tm_yday
/7) * 7), tm
->tm_hour
);
857 json_object_string_add(json_route
, "uptime", buf
);
860 for (ALL_NEXTHOPS_RO(rib
->nexthop
, nexthop
, tnexthop
, recursing
))
862 json_nexthop
= json_object_new_object();
864 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
))
865 json_object_boolean_true_add(json_nexthop
, "fib");
867 switch (nexthop
->type
)
869 case NEXTHOP_TYPE_IPV4
:
870 case NEXTHOP_TYPE_IPV4_IFINDEX
:
871 json_object_string_add(json_nexthop
, "ip", inet_ntoa (nexthop
->gate
.ipv4
));
872 json_object_string_add(json_nexthop
, "afi", "ipv4");
874 if (nexthop
->ifindex
)
876 json_object_int_add(json_nexthop
, "interfaceIndex", nexthop
->ifindex
);
877 json_object_string_add(json_nexthop
, "interfaceName", ifindex2ifname (nexthop
->ifindex
, rib
->vrf_id
));
880 case NEXTHOP_TYPE_IPV6
:
881 case NEXTHOP_TYPE_IPV6_IFINDEX
:
882 json_object_string_add(json_nexthop
, "ip", inet_ntop (AF_INET6
, &nexthop
->gate
.ipv6
, buf
, BUFSIZ
));
883 json_object_string_add(json_nexthop
, "afi", "ipv6");
885 if (nexthop
->ifindex
)
887 json_object_int_add(json_nexthop
, "interfaceIndex", nexthop
->ifindex
);
888 json_object_string_add(json_nexthop
, "interfaceName", ifindex2ifname (nexthop
->ifindex
, rib
->vrf_id
));
892 case NEXTHOP_TYPE_IFINDEX
:
893 json_object_boolean_true_add(json_nexthop
, "directlyConnected");
894 json_object_int_add(json_nexthop
, "interfaceIndex", nexthop
->ifindex
);
895 json_object_string_add(json_nexthop
, "interfaceName", ifindex2ifname (nexthop
->ifindex
, rib
->vrf_id
));
897 case NEXTHOP_TYPE_BLACKHOLE
:
898 json_object_boolean_true_add(json_nexthop
, "blackhole");
904 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
))
905 json_object_boolean_true_add(json_nexthop
, "active");
907 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_ONLINK
))
908 json_object_boolean_true_add(json_nexthop
, "onLink");
910 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_RECURSIVE
))
911 json_object_boolean_true_add(json_nexthop
, "recursive");
913 switch (nexthop
->type
)
915 case NEXTHOP_TYPE_IPV4
:
916 case NEXTHOP_TYPE_IPV4_IFINDEX
:
917 if (nexthop
->src
.ipv4
.s_addr
)
919 if (inet_ntop(AF_INET
, &nexthop
->src
.ipv4
, buf
, sizeof buf
))
920 json_object_string_add(json_nexthop
, "source", buf
);
923 case NEXTHOP_TYPE_IPV6
:
924 case NEXTHOP_TYPE_IPV6_IFINDEX
:
925 if (!IPV6_ADDR_SAME(&nexthop
->src
.ipv6
, &in6addr_any
))
927 if (inet_ntop(AF_INET6
, &nexthop
->src
.ipv6
, buf
, sizeof buf
))
928 json_object_string_add(json_nexthop
, "source", buf
);
935 if (nexthop
->nh_label
&& nexthop
->nh_label
->num_labels
)
937 json_labels
= json_object_new_array();
939 for (int label_index
= 0; label_index
< nexthop
->nh_label
->num_labels
; label_index
++)
940 json_object_array_add(json_labels
, json_object_new_int(nexthop
->nh_label
->label
[label_index
]));
942 json_object_object_add(json_nexthop
, "labels", json_labels
);
945 json_object_array_add(json_nexthops
, json_nexthop
);
948 json_object_object_add(json_route
, "nexthops", json_nexthops
);
949 json_object_array_add(json
, json_route
);
953 /* Nexthop information. */
954 for (ALL_NEXTHOPS_RO(rib
->nexthop
, nexthop
, tnexthop
, recursing
))
956 if (nexthop
== rib
->nexthop
)
958 /* Prefix information. */
959 len
= vty_out (vty
, "%c", zebra_route_char (rib
->type
));
961 len
+= vty_out (vty
, "[%d]", rib
->instance
);
962 len
+= vty_out (vty
, "%c%c %s",
963 CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_SELECTED
)
965 CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
)
967 srcdest_rnode2str (rn
, buf
, sizeof buf
));
969 /* Distance and metric display. */
970 if (rib
->type
!= ZEBRA_ROUTE_CONNECT
971 && rib
->type
!= ZEBRA_ROUTE_KERNEL
)
972 len
+= vty_out (vty
, " [%d/%d]", rib
->distance
,
976 vty_out (vty
, " %c%*c",
977 CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
)
979 len
- 3 + (2 * recursing
), ' ');
981 switch (nexthop
->type
)
983 case NEXTHOP_TYPE_IPV4
:
984 case NEXTHOP_TYPE_IPV4_IFINDEX
:
985 vty_out (vty
, " via %s", inet_ntoa (nexthop
->gate
.ipv4
));
986 if (nexthop
->ifindex
)
987 vty_out (vty
, ", %s",
988 ifindex2ifname (nexthop
->ifindex
, rib
->vrf_id
));
990 case NEXTHOP_TYPE_IPV6
:
991 case NEXTHOP_TYPE_IPV6_IFINDEX
:
992 vty_out (vty
, " via %s",
993 inet_ntop (AF_INET6
, &nexthop
->gate
.ipv6
, buf
, BUFSIZ
));
994 if (nexthop
->ifindex
)
995 vty_out (vty
, ", %s",
996 ifindex2ifname (nexthop
->ifindex
, rib
->vrf_id
));
999 case NEXTHOP_TYPE_IFINDEX
:
1000 vty_out (vty
, " is directly connected, %s",
1001 ifindex2ifname (nexthop
->ifindex
, rib
->vrf_id
));
1003 case NEXTHOP_TYPE_BLACKHOLE
:
1004 vty_out (vty
, " is directly connected, Null0");
1009 if (! CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
))
1010 vty_out (vty
, " inactive");
1012 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_ONLINK
))
1013 vty_out (vty
, " onlink");
1015 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_RECURSIVE
))
1016 vty_out (vty
, " (recursive)");
1018 switch (nexthop
->type
)
1020 case NEXTHOP_TYPE_IPV4
:
1021 case NEXTHOP_TYPE_IPV4_IFINDEX
:
1022 if (nexthop
->src
.ipv4
.s_addr
)
1024 if (inet_ntop(AF_INET
, &nexthop
->src
.ipv4
, buf
, sizeof buf
))
1025 vty_out (vty
, ", src %s", buf
);
1028 case NEXTHOP_TYPE_IPV6
:
1029 case NEXTHOP_TYPE_IPV6_IFINDEX
:
1030 if (!IPV6_ADDR_SAME(&nexthop
->src
.ipv6
, &in6addr_any
))
1032 if (inet_ntop(AF_INET6
, &nexthop
->src
.ipv6
, buf
, sizeof buf
))
1033 vty_out (vty
, ", src %s", buf
);
1040 /* Label information */
1041 if (nexthop
->nh_label
&& nexthop
->nh_label
->num_labels
)
1043 vty_out (vty
, ", label %s",
1044 mpls_label2str (nexthop
->nh_label
->num_labels
,
1045 nexthop
->nh_label
->label
, buf
, BUFSIZ
, 1));
1048 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_BLACKHOLE
))
1049 vty_out (vty
, ", bh");
1050 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_REJECT
))
1051 vty_out (vty
, ", rej");
1053 if (rib
->type
== ZEBRA_ROUTE_RIP
1054 || rib
->type
== ZEBRA_ROUTE_OSPF
1055 || rib
->type
== ZEBRA_ROUTE_ISIS
1056 || rib
->type
== ZEBRA_ROUTE_NHRP
1057 || rib
->type
== ZEBRA_ROUTE_TABLE
1058 || rib
->type
== ZEBRA_ROUTE_BGP
)
1063 uptime
= time (NULL
);
1064 uptime
-= rib
->uptime
;
1065 tm
= gmtime (&uptime
);
1067 if (uptime
< ONE_DAY_SECOND
)
1068 vty_out (vty
, ", %02d:%02d:%02d",
1069 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
1070 else if (uptime
< ONE_WEEK_SECOND
)
1071 vty_out (vty
, ", %dd%02dh%02dm",
1072 tm
->tm_yday
, tm
->tm_hour
, tm
->tm_min
);
1074 vty_out (vty
, ", %02dw%dd%02dh",
1076 tm
->tm_yday
- ((tm
->tm_yday
/7) * 7), tm
->tm_hour
);
1078 vty_out (vty
, "%s", VTY_NEWLINE
);
1083 use_fib (struct cmd_token
*token
)
1085 return strncmp(token
->arg
, "route", strlen(token
->arg
));
1088 DEFUN (show_ip_route
,
1090 "show ip <fib|route> [json]",
1093 "IP forwarding table\n"
1094 "IP routing table\n"
1097 return do_show_ip_route (vty
, VRF_DEFAULT_NAME
, SAFI_UNICAST
,
1098 use_fib(argv
[2]), use_json(argc
, argv
));
1102 do_show_ip_route (struct vty
*vty
, const char *vrf_name
, safi_t safi
,
1103 bool use_fib
, u_char use_json
)
1105 struct route_table
*table
;
1106 struct route_node
*rn
;
1109 struct zebra_vrf
*zvrf
= NULL
;
1111 json_object
*json
= NULL
;
1112 json_object
*json_prefix
= NULL
;
1114 if (!(zvrf
= zebra_vrf_lookup_by_name (vrf_name
)))
1117 vty_out (vty
, "{}%s", VTY_NEWLINE
);
1119 vty_out (vty
, "vrf %s not defined%s", vrf_name
, VTY_NEWLINE
);
1123 if (zvrf_id (zvrf
) == VRF_UNKNOWN
)
1126 vty_out (vty
, "{}%s", VTY_NEWLINE
);
1128 vty_out (vty
, "vrf %s inactive%s", vrf_name
, VTY_NEWLINE
);
1132 table
= zebra_vrf_table (AFI_IP
, safi
, zvrf_id (zvrf
));
1136 vty_out (vty
, "{}%s", VTY_NEWLINE
);
1142 json
= json_object_new_object();
1144 /* Show all IPv4 routes. */
1145 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
1147 RNODE_FOREACH_RIB (rn
, rib
)
1149 if (use_fib
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
1152 json_prefix
= json_object_new_array();
1153 vty_show_ip_route (vty
, rn
, rib
, json_prefix
);
1158 prefix2str (&rn
->p
, buf
, sizeof buf
);
1159 json_object_object_add(json
, buf
, json_prefix
);
1164 vty_out (vty
, "%s%s", json_object_to_json_string_ext(json
, JSON_C_TO_STRING_PRETTY
), VTY_NEWLINE
);
1165 json_object_free(json
);
1169 /* Show all IPv4 routes. */
1170 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
1172 RNODE_FOREACH_RIB (rn
, rib
)
1174 if (use_fib
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
1178 vty_out (vty
, SHOW_ROUTE_V4_HEADER
);
1181 vty_show_ip_route (vty
, rn
, rib
, NULL
);
1189 DEFUN (show_ip_route_vrf
,
1190 show_ip_route_vrf_cmd
,
1191 "show ip <fib|route> vrf NAME [json]",
1194 "IP forwarding table\n"
1195 "IP routing table\n"
1200 bool uf
= use_fib(argv
[2]);
1201 u_char uj
= use_json(argc
, argv
);
1203 return do_show_ip_route (vty
, argv
[idx_vrf
]->arg
, SAFI_UNICAST
, uf
, uj
);
1208 "show ip nht [vrf NAME]",
1211 "IP nexthop tracking table\n"
1215 vrf_id_t vrf_id
= VRF_DEFAULT
;
1218 VRF_GET_ID (vrf_id
, argv
[idx_vrf
]->arg
);
1220 zebra_print_rnh_table(vrf_id
, AF_INET
, vty
, RNH_NEXTHOP_TYPE
);
1225 DEFUN (show_ip_nht_vrf_all
,
1226 show_ip_nht_vrf_all_cmd
,
1227 "show ip nht vrf all",
1230 "IP nexthop tracking table\n"
1231 VRF_ALL_CMD_HELP_STR
)
1234 struct zebra_vrf
*zvrf
;
1236 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
1237 if ((zvrf
= vrf
->info
) != NULL
)
1239 vty_out (vty
, "%sVRF %s:%s", VTY_NEWLINE
, zvrf_name (zvrf
), VTY_NEWLINE
);
1240 zebra_print_rnh_table(zvrf_id (zvrf
), AF_INET
, vty
, RNH_NEXTHOP_TYPE
);
1246 DEFUN (show_ipv6_nht
,
1248 "show ipv6 nht [vrf NAME]",
1251 "IPv6 nexthop tracking table\n"
1255 vrf_id_t vrf_id
= VRF_DEFAULT
;
1258 VRF_GET_ID (vrf_id
, argv
[idx_vrf
]->arg
);
1260 zebra_print_rnh_table(vrf_id
, AF_INET6
, vty
, RNH_NEXTHOP_TYPE
);
1265 DEFUN (show_ipv6_nht_vrf_all
,
1266 show_ipv6_nht_vrf_all_cmd
,
1267 "show ipv6 nht vrf all",
1270 "IPv6 nexthop tracking table\n"
1271 VRF_ALL_CMD_HELP_STR
)
1274 struct zebra_vrf
*zvrf
;
1276 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
1277 if ((zvrf
= vrf
->info
) != NULL
)
1279 vty_out (vty
, "%sVRF %s:%s", VTY_NEWLINE
, zvrf_name (zvrf
), VTY_NEWLINE
);
1280 zebra_print_rnh_table(zvrf_id (zvrf
), AF_INET6
, vty
, RNH_NEXTHOP_TYPE
);
1286 DEFUN (ip_nht_default_route
,
1287 ip_nht_default_route_cmd
,
1288 "ip nht resolve-via-default",
1290 "Filter Next Hop tracking route resolution\n"
1291 "Resolve via default route\n")
1293 if (zebra_rnh_ip_default_route
)
1296 zebra_rnh_ip_default_route
= 1;
1297 zebra_evaluate_rnh(0, AF_INET
, 1, RNH_NEXTHOP_TYPE
, NULL
);
1301 DEFUN (no_ip_nht_default_route
,
1302 no_ip_nht_default_route_cmd
,
1303 "no ip nht resolve-via-default",
1306 "Filter Next Hop tracking route resolution\n"
1307 "Resolve via default route\n")
1309 if (!zebra_rnh_ip_default_route
)
1312 zebra_rnh_ip_default_route
= 0;
1313 zebra_evaluate_rnh(0, AF_INET
, 1, RNH_NEXTHOP_TYPE
, NULL
);
1317 DEFUN (ipv6_nht_default_route
,
1318 ipv6_nht_default_route_cmd
,
1319 "ipv6 nht resolve-via-default",
1321 "Filter Next Hop tracking route resolution\n"
1322 "Resolve via default route\n")
1324 if (zebra_rnh_ipv6_default_route
)
1327 zebra_rnh_ipv6_default_route
= 1;
1328 zebra_evaluate_rnh(0, AF_INET6
, 1, RNH_NEXTHOP_TYPE
, NULL
);
1332 DEFUN (no_ipv6_nht_default_route
,
1333 no_ipv6_nht_default_route_cmd
,
1334 "no ipv6 nht resolve-via-default",
1337 "Filter Next Hop tracking route resolution\n"
1338 "Resolve via default route\n")
1340 if (!zebra_rnh_ipv6_default_route
)
1343 zebra_rnh_ipv6_default_route
= 0;
1344 zebra_evaluate_rnh(0, AF_INET6
, 1, RNH_NEXTHOP_TYPE
, NULL
);
1348 DEFUN (show_ip_route_tag
,
1349 show_ip_route_tag_cmd
,
1350 "show ip <fib|route> [vrf NAME] tag (1-4294967295)",
1353 "IP forwarding table\n"
1354 "IP routing table\n"
1356 "Show only routes with tag\n"
1359 bool uf
= use_fib(argv
[2]);
1363 struct route_table
*table
;
1364 struct route_node
*rn
;
1367 route_tag_t tag
= 0;
1368 vrf_id_t vrf_id
= VRF_DEFAULT
;
1370 if (strmatch(argv
[idx_vrf
]->text
, "vrf"))
1372 VRF_GET_ID (vrf_id
, argv
[idx_name
]->arg
);
1373 VTY_GET_INTEGER_RANGE("tag", tag
, argv
[idx_tag
]->arg
, 0, 4294967295);
1378 VTY_GET_INTEGER_RANGE("tag", tag
, argv
[idx_tag
]->arg
, 0, 4294967295);
1381 table
= zebra_vrf_table (AFI_IP
, SAFI_UNICAST
, vrf_id
);
1385 /* Show all IPv4 routes with matching tag value. */
1386 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
1387 RNODE_FOREACH_RIB (rn
, rib
)
1389 if (uf
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
1391 if (rib
->tag
!= tag
)
1396 vty_out (vty
, SHOW_ROUTE_V4_HEADER
);
1399 vty_show_ip_route (vty
, rn
, rib
, NULL
);
1404 DEFUN (show_ip_route_prefix_longer
,
1405 show_ip_route_prefix_longer_cmd
,
1406 "show ip <fib|route> [vrf NAME] A.B.C.D/M longer-prefixes",
1409 "IP forwarding table\n"
1410 "IP routing table\n"
1412 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1413 "Show route matching the specified Network/Mask pair only\n")
1415 struct route_table
*table
;
1416 struct route_node
*rn
;
1421 bool uf
= use_fib(argv
[2]);
1422 vrf_id_t vrf_id
= VRF_DEFAULT
;
1424 if (strmatch(argv
[3]->text
, "vrf"))
1426 VRF_GET_ID (vrf_id
, argv
[4]->arg
);
1427 ret
= str2prefix (argv
[5]->arg
, &p
);
1431 ret
= str2prefix (argv
[3]->arg
, &p
);
1436 vty_out (vty
, "%% Malformed Prefix%s", VTY_NEWLINE
);
1440 table
= zebra_vrf_table (AFI_IP
, SAFI_UNICAST
, vrf_id
);
1444 /* Show matched type IPv4 routes. */
1445 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
1446 RNODE_FOREACH_RIB (rn
, rib
)
1447 if (prefix_match (&p
, &rn
->p
))
1449 if (uf
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
1453 vty_out (vty
, SHOW_ROUTE_V4_HEADER
);
1456 vty_show_ip_route (vty
, rn
, rib
, NULL
);
1461 DEFUN (show_ip_route_supernets
,
1462 show_ip_route_supernets_cmd
,
1463 "show ip <fib|route> [vrf NAME] supernets-only",
1466 "IP forwarding table\n"
1467 "IP routing table\n"
1469 "Show supernet entries only\n")
1471 struct route_table
*table
;
1472 struct route_node
*rn
;
1476 vrf_id_t vrf_id
= VRF_DEFAULT
;
1477 bool uf
= use_fib(argv
[2]);
1479 if (strmatch(argv
[3]->text
, "vrf"))
1480 VRF_GET_ID (vrf_id
, argv
[4]->arg
);
1482 table
= zebra_vrf_table (AFI_IP
, SAFI_UNICAST
, vrf_id
);
1486 /* Show matched type IPv4 routes. */
1487 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
1488 RNODE_FOREACH_RIB (rn
, rib
)
1490 if (uf
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
1492 addr
= ntohl (rn
->p
.u
.prefix4
.s_addr
);
1494 if ((IN_CLASSC (addr
) && rn
->p
.prefixlen
< 24)
1495 || (IN_CLASSB (addr
) && rn
->p
.prefixlen
< 16)
1496 || (IN_CLASSA (addr
) && rn
->p
.prefixlen
< 8))
1500 vty_out (vty
, SHOW_ROUTE_V4_HEADER
);
1503 vty_show_ip_route (vty
, rn
, rib
, NULL
);
1509 DEFUN (show_ip_route_protocol
,
1510 show_ip_route_protocol_cmd
,
1511 "show ip <fib|route> [vrf NAME] " FRR_IP_REDIST_STR_ZEBRA
,
1514 "IP forwarding table\n"
1515 "IP routing table\n"
1517 FRR_IP_REDIST_HELP_STR_ZEBRA
)
1520 struct route_table
*table
;
1521 struct route_node
*rn
;
1524 vrf_id_t vrf_id
= VRF_DEFAULT
;
1525 bool uf
= use_fib(argv
[2]);
1528 if (argv_find (argv
, argc
, "NAME", &idx
))
1529 VRF_GET_ID (vrf_id
, argv
[idx
]->arg
);
1531 char *proto
= argv
[argc
- 1]->text
;
1532 type
= proto_redistnum (AFI_IP
, proto
);
1536 vty_out (vty
, "Unknown route type%s", VTY_NEWLINE
);
1540 table
= zebra_vrf_table (AFI_IP
, SAFI_UNICAST
, vrf_id
);
1544 /* Show matched type IPv4 routes. */
1545 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
1546 RNODE_FOREACH_RIB (rn
, rib
)
1547 if (rib
->type
== type
)
1549 if (uf
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
1553 vty_out (vty
, SHOW_ROUTE_V4_HEADER
);
1556 vty_show_ip_route (vty
, rn
, rib
, NULL
);
1562 DEFUN (show_ip_route_ospf_instance
,
1563 show_ip_route_ospf_instance_cmd
,
1564 "show ip <fib|route> ospf (1-65535)",
1567 "IP forwarding table\n"
1568 "IP routing table\n"
1569 "Open Shortest Path First (OSPFv2)\n"
1573 struct route_table
*table
;
1574 struct route_node
*rn
;
1577 u_short instance
= 0;
1578 bool uf
= use_fib(argv
[2]);
1580 VTY_GET_INTEGER ("Instance", instance
, argv
[idx_number
]->arg
);
1582 table
= zebra_vrf_table (AFI_IP
, SAFI_UNICAST
, VRF_DEFAULT
);
1586 /* Show matched type IPv4 routes. */
1587 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
1588 RNODE_FOREACH_RIB (rn
, rib
)
1589 if (rib
->type
== ZEBRA_ROUTE_OSPF
&& rib
->instance
== instance
)
1591 if (uf
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
1595 vty_out (vty
, SHOW_ROUTE_V4_HEADER
);
1598 vty_show_ip_route (vty
, rn
, rib
, NULL
);
1603 DEFUN (show_ip_route_addr
,
1604 show_ip_route_addr_cmd
,
1605 "show ip route [vrf NAME] A.B.C.D",
1608 "IP routing table\n"
1610 "Network in the IP routing table to display\n")
1613 struct prefix_ipv4 p
;
1614 struct route_table
*table
;
1615 struct route_node
*rn
;
1616 vrf_id_t vrf_id
= VRF_DEFAULT
;
1618 if (strmatch(argv
[3]->text
, "vrf"))
1620 VRF_GET_ID (vrf_id
, argv
[4]->arg
);
1621 ret
= str2prefix_ipv4 (argv
[5]->arg
, &p
);
1625 ret
= str2prefix_ipv4 (argv
[3]->arg
, &p
);
1630 vty_out (vty
, "%% Malformed IPv4 address%s", VTY_NEWLINE
);
1634 table
= zebra_vrf_table (AFI_IP
, SAFI_UNICAST
, vrf_id
);
1638 rn
= route_node_match (table
, (struct prefix
*) &p
);
1641 vty_out (vty
, "%% Network not in table%s", VTY_NEWLINE
);
1645 vty_show_ip_route_detail (vty
, rn
, 0);
1647 route_unlock_node (rn
);
1652 DEFUN (show_ip_route_prefix
,
1653 show_ip_route_prefix_cmd
,
1654 "show ip route [vrf NAME] A.B.C.D/M",
1657 "IP routing table\n"
1659 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
1662 struct prefix_ipv4 p
;
1663 struct route_table
*table
;
1664 struct route_node
*rn
;
1665 vrf_id_t vrf_id
= VRF_DEFAULT
;
1667 if (strmatch(argv
[3]->text
, "vrf"))
1669 VRF_GET_ID (vrf_id
, argv
[4]->arg
);
1670 ret
= str2prefix_ipv4 (argv
[5]->arg
, &p
);
1674 ret
= str2prefix_ipv4 (argv
[3]->arg
, &p
);
1679 vty_out (vty
, "%% Malformed IPv4 address%s", VTY_NEWLINE
);
1683 table
= zebra_vrf_table (AFI_IP
, SAFI_UNICAST
, vrf_id
);
1687 rn
= route_node_match (table
, (struct prefix
*) &p
);
1688 if (! rn
|| rn
->p
.prefixlen
!= p
.prefixlen
)
1690 vty_out (vty
, "%% Network not in table%s", VTY_NEWLINE
);
1694 vty_show_ip_route_detail (vty
, rn
, 0);
1696 route_unlock_node (rn
);
1703 vty_show_ip_route_summary (struct vty
*vty
, struct route_table
*table
)
1705 struct route_node
*rn
;
1707 #define ZEBRA_ROUTE_IBGP ZEBRA_ROUTE_MAX
1708 #define ZEBRA_ROUTE_TOTAL (ZEBRA_ROUTE_IBGP + 1)
1709 u_int32_t rib_cnt
[ZEBRA_ROUTE_TOTAL
+ 1];
1710 u_int32_t fib_cnt
[ZEBRA_ROUTE_TOTAL
+ 1];
1714 memset (&rib_cnt
, 0, sizeof(rib_cnt
));
1715 memset (&fib_cnt
, 0, sizeof(fib_cnt
));
1716 for (rn
= route_top (table
); rn
; rn
= srcdest_route_next (rn
))
1717 RNODE_FOREACH_RIB (rn
, rib
)
1719 is_ibgp
= (rib
->type
== ZEBRA_ROUTE_BGP
&&
1720 CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_IBGP
));
1722 rib_cnt
[ZEBRA_ROUTE_TOTAL
]++;
1724 rib_cnt
[ZEBRA_ROUTE_IBGP
]++;
1726 rib_cnt
[rib
->type
]++;
1728 if (CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_SELECTED
))
1730 fib_cnt
[ZEBRA_ROUTE_TOTAL
]++;
1733 fib_cnt
[ZEBRA_ROUTE_IBGP
]++;
1735 fib_cnt
[rib
->type
]++;
1739 vty_out (vty
, "%-20s %-20s %s (vrf %s)%s",
1740 "Route Source", "Routes", "FIB",
1741 zvrf_name (((rib_table_info_t
*)table
->info
)->zvrf
),
1744 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
1746 if ((rib_cnt
[i
] > 0) ||
1747 (i
== ZEBRA_ROUTE_BGP
&& rib_cnt
[ZEBRA_ROUTE_IBGP
] > 0))
1749 if (i
== ZEBRA_ROUTE_BGP
)
1751 vty_out (vty
, "%-20s %-20d %-20d %s", "ebgp",
1752 rib_cnt
[ZEBRA_ROUTE_BGP
], fib_cnt
[ZEBRA_ROUTE_BGP
],
1754 vty_out (vty
, "%-20s %-20d %-20d %s", "ibgp",
1755 rib_cnt
[ZEBRA_ROUTE_IBGP
], fib_cnt
[ZEBRA_ROUTE_IBGP
],
1759 vty_out (vty
, "%-20s %-20d %-20d %s", zebra_route_string(i
),
1760 rib_cnt
[i
], fib_cnt
[i
], VTY_NEWLINE
);
1764 vty_out (vty
, "------%s", VTY_NEWLINE
);
1765 vty_out (vty
, "%-20s %-20d %-20d %s", "Totals", rib_cnt
[ZEBRA_ROUTE_TOTAL
],
1766 fib_cnt
[ZEBRA_ROUTE_TOTAL
], VTY_NEWLINE
);
1767 vty_out (vty
, "%s", VTY_NEWLINE
);
1771 * Implementation of the ip route summary prefix command.
1773 * This command prints the primary prefixes that have been installed by various
1774 * protocols on the box.
1778 vty_show_ip_route_summary_prefix (struct vty
*vty
, struct route_table
*table
)
1780 struct route_node
*rn
;
1782 struct nexthop
*nexthop
;
1783 #define ZEBRA_ROUTE_IBGP ZEBRA_ROUTE_MAX
1784 #define ZEBRA_ROUTE_TOTAL (ZEBRA_ROUTE_IBGP + 1)
1785 u_int32_t rib_cnt
[ZEBRA_ROUTE_TOTAL
+ 1];
1786 u_int32_t fib_cnt
[ZEBRA_ROUTE_TOTAL
+ 1];
1790 memset (&rib_cnt
, 0, sizeof(rib_cnt
));
1791 memset (&fib_cnt
, 0, sizeof(fib_cnt
));
1792 for (rn
= route_top (table
); rn
; rn
= srcdest_route_next (rn
))
1793 RNODE_FOREACH_RIB (rn
, rib
)
1797 * In case of ECMP, count only once.
1800 for (nexthop
= rib
->nexthop
; (!cnt
&& nexthop
); nexthop
= nexthop
->next
)
1803 rib_cnt
[ZEBRA_ROUTE_TOTAL
]++;
1804 rib_cnt
[rib
->type
]++;
1805 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
))
1807 fib_cnt
[ZEBRA_ROUTE_TOTAL
]++;
1808 fib_cnt
[rib
->type
]++;
1810 if (rib
->type
== ZEBRA_ROUTE_BGP
&&
1811 CHECK_FLAG (rib
->flags
, ZEBRA_FLAG_IBGP
))
1813 rib_cnt
[ZEBRA_ROUTE_IBGP
]++;
1814 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
))
1815 fib_cnt
[ZEBRA_ROUTE_IBGP
]++;
1820 vty_out (vty
, "%-20s %-20s %s (vrf %s)%s",
1821 "Route Source", "Prefix Routes", "FIB",
1822 zvrf_name (((rib_table_info_t
*)table
->info
)->zvrf
),
1825 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
1829 if (i
== ZEBRA_ROUTE_BGP
)
1831 vty_out (vty
, "%-20s %-20d %-20d %s", "ebgp",
1832 rib_cnt
[ZEBRA_ROUTE_BGP
] - rib_cnt
[ZEBRA_ROUTE_IBGP
],
1833 fib_cnt
[ZEBRA_ROUTE_BGP
] - fib_cnt
[ZEBRA_ROUTE_IBGP
],
1835 vty_out (vty
, "%-20s %-20d %-20d %s", "ibgp",
1836 rib_cnt
[ZEBRA_ROUTE_IBGP
], fib_cnt
[ZEBRA_ROUTE_IBGP
],
1840 vty_out (vty
, "%-20s %-20d %-20d %s", zebra_route_string(i
),
1841 rib_cnt
[i
], fib_cnt
[i
], VTY_NEWLINE
);
1845 vty_out (vty
, "------%s", VTY_NEWLINE
);
1846 vty_out (vty
, "%-20s %-20d %-20d %s", "Totals", rib_cnt
[ZEBRA_ROUTE_TOTAL
],
1847 fib_cnt
[ZEBRA_ROUTE_TOTAL
], VTY_NEWLINE
);
1848 vty_out (vty
, "%s", VTY_NEWLINE
);
1851 /* Show route summary. */
1852 DEFUN (show_ip_route_summary
,
1853 show_ip_route_summary_cmd
,
1854 "show ip route [vrf NAME] summary",
1857 "IP routing table\n"
1859 "Summary of all routes\n")
1861 struct route_table
*table
;
1862 vrf_id_t vrf_id
= VRF_DEFAULT
;
1864 if (strmatch(argv
[3]->text
, "vrf"))
1865 VRF_GET_ID (vrf_id
, argv
[4]->arg
);
1867 table
= zebra_vrf_table (AFI_IP
, SAFI_UNICAST
, vrf_id
);
1871 vty_show_ip_route_summary (vty
, table
);
1876 /* Show route summary prefix. */
1877 DEFUN (show_ip_route_summary_prefix
,
1878 show_ip_route_summary_prefix_cmd
,
1879 "show ip route [vrf NAME] summary prefix",
1882 "IP routing table\n"
1884 "Summary of all routes\n"
1887 struct route_table
*table
;
1888 vrf_id_t vrf_id
= VRF_DEFAULT
;
1890 if (strmatch(argv
[3]->text
, "vrf"))
1891 VRF_GET_ID (vrf_id
, argv
[4]->arg
);
1893 table
= zebra_vrf_table (AFI_IP
, SAFI_UNICAST
, vrf_id
);
1897 vty_show_ip_route_summary_prefix (vty
, table
);
1903 DEFUN (show_ip_route_vrf_all
,
1904 show_ip_route_vrf_all_cmd
,
1905 "show ip <fib|route> vrf all",
1908 "IP forwarding table\n"
1909 "IP routing table\n"
1910 VRF_ALL_CMD_HELP_STR
)
1912 struct route_table
*table
;
1913 struct route_node
*rn
;
1916 struct zebra_vrf
*zvrf
;
1919 bool uf
= use_fib(argv
[2]);
1921 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
1923 if ((zvrf
= vrf
->info
) == NULL
||
1924 (table
= zvrf
->table
[AFI_IP
][SAFI_UNICAST
]) == NULL
)
1927 /* Show all IPv4 routes. */
1928 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
1929 RNODE_FOREACH_RIB (rn
, rib
)
1931 if (uf
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
1935 vty_out (vty
, SHOW_ROUTE_V4_HEADER
);
1941 vty_out (vty
, "%sVRF %s:%s", VTY_NEWLINE
, zvrf_name (zvrf
), VTY_NEWLINE
);
1944 vty_show_ip_route (vty
, rn
, rib
, NULL
);
1952 DEFUN (show_ip_route_vrf_all_tag
,
1953 show_ip_route_vrf_all_tag_cmd
,
1954 "show ip <fib|route> vrf all tag (1-4294967295)",
1957 "IP forwarding table\n"
1958 "IP routing table\n"
1959 VRF_ALL_CMD_HELP_STR
1960 "Show only routes with tag\n"
1964 struct route_table
*table
;
1965 struct route_node
*rn
;
1968 struct zebra_vrf
*zvrf
;
1971 route_tag_t tag
= 0;
1972 bool uf
= use_fib(argv
[2]);
1974 if (argv
[idx_number
]->arg
)
1975 VTY_GET_INTEGER_RANGE("tag", tag
, argv
[idx_number
]->arg
, 0, 4294967295);
1977 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
1979 if ((zvrf
= vrf
->info
) == NULL
||
1980 (table
= zvrf
->table
[AFI_IP
][SAFI_UNICAST
]) == NULL
)
1983 /* Show all IPv4 routes with matching tag value. */
1984 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
1985 RNODE_FOREACH_RIB (rn
, rib
)
1987 if (uf
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
1989 if (rib
->tag
!= tag
)
1994 vty_out (vty
, SHOW_ROUTE_V4_HEADER
);
2000 vty_out (vty
, "%sVRF %s:%s", VTY_NEWLINE
, zvrf_name (zvrf
), VTY_NEWLINE
);
2003 vty_show_ip_route (vty
, rn
, rib
, NULL
);
2010 DEFUN (show_ip_route_vrf_all_prefix_longer
,
2011 show_ip_route_vrf_all_prefix_longer_cmd
,
2012 "show ip <fib|route> vrf all A.B.C.D/M longer-prefixes",
2015 "IP forwarding table\n"
2016 "IP routing table\n"
2017 VRF_ALL_CMD_HELP_STR
2018 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
2019 "Show route matching the specified Network/Mask pair only\n")
2021 int idx_ipv4_prefixlen
= 5;
2022 struct route_table
*table
;
2023 struct route_node
*rn
;
2027 struct zebra_vrf
*zvrf
;
2031 bool uf
= use_fib(argv
[2]);
2033 ret
= str2prefix (argv
[idx_ipv4_prefixlen
]->arg
, &p
);
2036 vty_out (vty
, "%% Malformed Prefix%s", VTY_NEWLINE
);
2040 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
2042 if ((zvrf
= vrf
->info
) == NULL
||
2043 (table
= zvrf
->table
[AFI_IP
][SAFI_UNICAST
]) == NULL
)
2046 /* Show matched type IPv4 routes. */
2047 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
2048 RNODE_FOREACH_RIB (rn
, rib
)
2049 if (prefix_match (&p
, &rn
->p
))
2051 if (uf
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
2055 vty_out (vty
, SHOW_ROUTE_V4_HEADER
);
2061 vty_out (vty
, "%sVRF %s:%s", VTY_NEWLINE
, zvrf_name (zvrf
), VTY_NEWLINE
);
2064 vty_show_ip_route (vty
, rn
, rib
, NULL
);
2072 DEFUN (show_ip_route_vrf_all_supernets
,
2073 show_ip_route_vrf_all_supernets_cmd
,
2074 "show ip <fib|route> vrf all supernets-only",
2077 "IP forwarding table\n"
2078 "IP routing table\n"
2079 VRF_ALL_CMD_HELP_STR
2080 "Show supernet entries only\n")
2082 struct route_table
*table
;
2083 struct route_node
*rn
;
2086 struct zebra_vrf
*zvrf
;
2090 bool uf
= use_fib(argv
[2]);
2092 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
2094 if ((zvrf
= vrf
->info
) == NULL
||
2095 (table
= zvrf
->table
[AFI_IP
][SAFI_UNICAST
]) == NULL
)
2098 /* Show matched type IPv4 routes. */
2099 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
2100 RNODE_FOREACH_RIB (rn
, rib
)
2102 if (uf
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
2105 addr
= ntohl (rn
->p
.u
.prefix4
.s_addr
);
2107 if ((IN_CLASSC (addr
) && rn
->p
.prefixlen
< 24)
2108 || (IN_CLASSB (addr
) && rn
->p
.prefixlen
< 16)
2109 || (IN_CLASSA (addr
) && rn
->p
.prefixlen
< 8))
2113 vty_out (vty
, SHOW_ROUTE_V4_HEADER
);
2118 vty_out (vty
, "%sVRF %s:%s", VTY_NEWLINE
, zvrf_name (zvrf
), VTY_NEWLINE
);
2121 vty_show_ip_route (vty
, rn
, rib
, NULL
);
2130 DEFUN (show_ip_route_vrf_all_protocol
,
2131 show_ip_route_vrf_all_protocol_cmd
,
2132 "show ip <fib|route> vrf all " FRR_IP_REDIST_STR_ZEBRA
,
2135 "IP forwarding table\n"
2136 "IP routing table\n"
2137 VRF_ALL_CMD_HELP_STR
2138 FRR_IP_REDIST_HELP_STR_ZEBRA
"\n")
2141 struct route_table
*table
;
2142 struct route_node
*rn
;
2145 struct zebra_vrf
*zvrf
;
2148 bool uf
= use_fib(argv
[2]);
2150 char *proto
= argv
[argc
- 1]->text
;
2151 type
= proto_redistnum (AFI_IP
, proto
);
2155 vty_out (vty
, "Unknown route type%s", VTY_NEWLINE
);
2159 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
2161 if ((zvrf
= vrf
->info
) == NULL
||
2162 (table
= zvrf
->table
[AFI_IP
][SAFI_UNICAST
]) == NULL
)
2165 /* Show matched type IPv4 routes. */
2166 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
2167 RNODE_FOREACH_RIB (rn
, rib
)
2168 if (rib
->type
== type
)
2170 if (uf
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
2174 vty_out (vty
, SHOW_ROUTE_V4_HEADER
);
2180 vty_out (vty
, "%sVRF %s:%s", VTY_NEWLINE
, zvrf_name (zvrf
), VTY_NEWLINE
);
2183 vty_show_ip_route (vty
, rn
, rib
, NULL
);
2191 DEFUN (show_ip_route_vrf_all_addr
,
2192 show_ip_route_vrf_all_addr_cmd
,
2193 "show ip route vrf all A.B.C.D",
2196 "IP routing table\n"
2197 VRF_ALL_CMD_HELP_STR
2198 "Network in the IP routing table to display\n")
2202 struct prefix_ipv4 p
;
2203 struct route_table
*table
;
2204 struct route_node
*rn
;
2206 struct zebra_vrf
*zvrf
;
2208 ret
= str2prefix_ipv4 (argv
[idx_ipv4
]->arg
, &p
);
2211 vty_out (vty
, "%% Malformed IPv4 address%s", VTY_NEWLINE
);
2215 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
2217 if ((zvrf
= vrf
->info
) == NULL
||
2218 (table
= zvrf
->table
[AFI_IP
][SAFI_UNICAST
]) == NULL
)
2221 rn
= route_node_match (table
, (struct prefix
*) &p
);
2225 vty_show_ip_route_detail (vty
, rn
, 0);
2227 route_unlock_node (rn
);
2233 DEFUN (show_ip_route_vrf_all_prefix
,
2234 show_ip_route_vrf_all_prefix_cmd
,
2235 "show ip route vrf all A.B.C.D/M",
2238 "IP routing table\n"
2239 VRF_ALL_CMD_HELP_STR
2240 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
2242 int idx_ipv4_prefixlen
= 5;
2244 struct prefix_ipv4 p
;
2245 struct route_table
*table
;
2246 struct route_node
*rn
;
2248 struct zebra_vrf
*zvrf
;
2250 ret
= str2prefix_ipv4 (argv
[idx_ipv4_prefixlen
]->arg
, &p
);
2253 vty_out (vty
, "%% Malformed IPv4 address%s", VTY_NEWLINE
);
2257 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
2259 if ((zvrf
= vrf
->info
) == NULL
||
2260 (table
= zvrf
->table
[AFI_IP
][SAFI_UNICAST
]) == NULL
)
2263 rn
= route_node_match (table
, (struct prefix
*) &p
);
2266 if (rn
->p
.prefixlen
!= p
.prefixlen
)
2268 route_unlock_node (rn
);
2272 vty_show_ip_route_detail (vty
, rn
, 0);
2274 route_unlock_node (rn
);
2280 DEFUN (show_ip_route_vrf_all_summary
,
2281 show_ip_route_vrf_all_summary_cmd
,
2282 "show ip route vrf all summary ",
2285 "IP routing table\n"
2286 VRF_ALL_CMD_HELP_STR
2287 "Summary of all routes\n")
2290 struct zebra_vrf
*zvrf
;
2292 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
2293 if ((zvrf
= vrf
->info
) != NULL
)
2294 vty_show_ip_route_summary (vty
, zvrf
->table
[AFI_IP
][SAFI_UNICAST
]);
2299 DEFUN (show_ip_route_vrf_all_summary_prefix
,
2300 show_ip_route_vrf_all_summary_prefix_cmd
,
2301 "show ip route vrf all summary prefix",
2304 "IP routing table\n"
2305 VRF_ALL_CMD_HELP_STR
2306 "Summary of all routes\n"
2310 struct zebra_vrf
*zvrf
;
2312 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
2313 if ((zvrf
= vrf
->info
) != NULL
)
2314 vty_show_ip_route_summary_prefix (vty
, zvrf
->table
[AFI_IP
][SAFI_UNICAST
]);
2319 /* Write static route configuration. */
2321 static_config (struct vty
*vty
, afi_t afi
, safi_t safi
, const char *cmd
)
2323 struct route_node
*rn
;
2324 struct static_route
*si
;
2325 struct route_table
*stable
;
2327 struct zebra_vrf
*zvrf
;
2328 char buf
[SRCDEST2STR_BUFFER
];
2331 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
2333 if (!(zvrf
= vrf
->info
))
2335 if ((stable
= zvrf
->stable
[afi
][safi
]) == NULL
)
2338 for (rn
= route_top (stable
); rn
; rn
= srcdest_route_next (rn
))
2339 for (si
= rn
->info
; si
; si
= si
->next
)
2341 vty_out (vty
, "%s %s", cmd
, srcdest_rnode2str (rn
, buf
, sizeof buf
));
2345 case STATIC_IPV4_GATEWAY
:
2346 vty_out (vty
, " %s", inet_ntoa (si
->addr
.ipv4
));
2348 case STATIC_IPV6_GATEWAY
:
2349 vty_out (vty
, " %s", inet_ntop (AF_INET6
, &si
->addr
.ipv6
, buf
, BUFSIZ
));
2351 case STATIC_IFINDEX
:
2352 vty_out (vty
, " %s", si
->ifname
);
2354 case STATIC_BLACKHOLE
:
2355 vty_out (vty
, " Null0");
2357 case STATIC_IPV6_GATEWAY_IFINDEX
:
2358 vty_out (vty
, " %s %s",
2359 inet_ntop (AF_INET6
, &si
->addr
.ipv6
, buf
, BUFSIZ
),
2360 ifindex2ifname (si
->ifindex
, si
->vrf_id
));
2364 /* flags are incompatible with STATIC_BLACKHOLE */
2365 if (si
->type
!= STATIC_BLACKHOLE
)
2367 if (CHECK_FLAG(si
->flags
, ZEBRA_FLAG_REJECT
))
2368 vty_out (vty
, " %s", "reject");
2370 if (CHECK_FLAG(si
->flags
, ZEBRA_FLAG_BLACKHOLE
))
2371 vty_out (vty
, " %s", "blackhole");
2375 vty_out (vty
, " tag %"ROUTE_TAG_PRI
, si
->tag
);
2377 if (si
->distance
!= ZEBRA_STATIC_DISTANCE_DEFAULT
)
2378 vty_out (vty
, " %d", si
->distance
);
2380 if (si
->vrf_id
!= VRF_DEFAULT
)
2381 vty_out (vty
, " vrf %s", zvrf_name (zvrf
));
2383 /* Label information */
2384 if (si
->snh_label
.num_labels
)
2385 vty_out (vty
, " label %s",
2386 mpls_label2str (si
->snh_label
.num_labels
,
2387 si
->snh_label
.label
, buf
, sizeof buf
, 0));
2389 vty_out (vty
, "%s", VTY_NEWLINE
);
2397 /* General fucntion for IPv6 static route. */
2399 static_ipv6_func (struct vty
*vty
, int add_cmd
, const char *dest_str
,
2400 const char *src_str
,
2401 const char *gate_str
, const char *ifname
,
2402 const char *flag_str
, const char *tag_str
,
2403 const char *distance_str
, const char *vrf_id_str
,
2404 const char *label_str
)
2408 struct prefix p
, src
;
2409 struct prefix_ipv6
*src_p
= NULL
;
2410 struct in6_addr
*gate
= NULL
;
2411 struct in6_addr gate_addr
;
2412 u_char type
= STATIC_BLACKHOLE
;
2414 route_tag_t tag
= 0;
2415 unsigned int ifindex
= 0;
2416 struct interface
*ifp
= NULL
;
2417 struct zebra_vrf
*zvrf
;
2418 struct static_nh_label snh_label
;
2420 ret
= str2prefix (dest_str
, &p
);
2423 vty_out (vty
, "%% Malformed address%s", VTY_NEWLINE
);
2429 ret
= str2prefix (src_str
, &src
);
2430 if (ret
<= 0 || src
.family
!= AF_INET6
)
2432 vty_out (vty
, "%% Malformed source address%s", VTY_NEWLINE
);
2435 src_p
= (struct prefix_ipv6
*)&src
;
2438 /* Apply mask for given prefix. */
2441 /* Administrative distance. */
2443 distance
= atoi (distance_str
);
2445 distance
= ZEBRA_STATIC_DISTANCE_DEFAULT
;
2449 VTY_GET_INTEGER_RANGE("tag", tag
, tag_str
, 0, 4294967295);
2451 /* When gateway is valid IPv6 addrees, then gate is treated as
2452 nexthop address other case gate is treated as interface name. */
2453 ret
= inet_pton (AF_INET6
, gate_str
, &gate_addr
);
2456 zvrf
= zebra_vrf_lookup_by_name (vrf_id_str
);
2460 vty_out (vty
, "%% vrf %s is not defined%s", vrf_id_str
, VTY_NEWLINE
);
2465 memset (&snh_label
, 0, sizeof (struct static_nh_label
));
2470 vty_out (vty
, "%% MPLS not turned on in kernel, ignoring command%s",
2474 if (mpls_str2label (label_str
, &snh_label
.num_labels
,
2477 vty_out (vty
, "%% Malformed label(s)%s", VTY_NEWLINE
);
2482 /* Null0 static route. */
2483 if ((gate_str
!= NULL
) && (strncasecmp (gate_str
, "Null0", strlen (gate_str
)) == 0))
2487 vty_out (vty
, "%% can not have flag %s with Null0%s", flag_str
, VTY_NEWLINE
);
2491 static_add_route (AFI_IP6
, SAFI_UNICAST
, type
, &p
, NULL
, NULL
, ifindex
, ifname
,
2492 ZEBRA_FLAG_BLACKHOLE
, tag
, distance
, zvrf
, &snh_label
);
2494 static_delete_route (AFI_IP6
, SAFI_UNICAST
, type
, &p
, NULL
, NULL
, ifindex
, tag
,
2495 distance
, zvrf
, &snh_label
);
2501 switch(flag_str
[0]) {
2504 SET_FLAG (flag
, ZEBRA_FLAG_REJECT
);
2508 SET_FLAG (flag
, ZEBRA_FLAG_BLACKHOLE
);
2511 vty_out (vty
, "%% Malformed flag %s %s", flag_str
, VTY_NEWLINE
);
2518 /* When ifname is specified. It must be come with gateway
2522 vty_out (vty
, "%% Malformed address%s", VTY_NEWLINE
);
2525 type
= STATIC_IPV6_GATEWAY_IFINDEX
;
2527 ifp
= if_lookup_by_name (ifname
, zvrf_id (zvrf
));
2530 vty_out (vty
, "%% Malformed Interface name %s%s", ifname
, VTY_NEWLINE
);
2533 ifindex
= ifp
->ifindex
;
2539 type
= STATIC_IPV6_GATEWAY
;
2544 type
= STATIC_IFINDEX
;
2545 ifp
= if_lookup_by_name (gate_str
, zvrf_id (zvrf
));
2548 vty_out (vty
, "%% Malformed Interface name %s%s", gate_str
, VTY_NEWLINE
);
2549 ifindex
= IFINDEX_DELETED
;
2552 ifindex
= ifp
->ifindex
;
2558 static_add_route (AFI_IP6
, SAFI_UNICAST
, type
, &p
, src_p
, (union g_addr
*)gate
,
2559 ifindex
, ifname
, flag
, tag
, distance
, zvrf
, &snh_label
);
2561 static_delete_route (AFI_IP6
, SAFI_UNICAST
, type
, &p
, src_p
, (union g_addr
*)gate
,
2562 ifindex
, tag
, distance
, zvrf
, &snh_label
);
2569 "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]",
2571 "Establish static routes\n"
2572 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
2573 "IPv6 source-dest route\n"
2574 "IPv6 source prefix\n"
2575 "IPv6 gateway address\n"
2576 "IPv6 gateway interface name\n"
2579 "Set tag for this route\n"
2581 "Distance value for this prefix\n"
2583 "Specify labels for this route\n"
2584 "One or more labels separated by '/'\n")
2586 int idx_ipv6_prefixlen
= 2;
2587 int idx_ipv6_ifname
;
2589 char *src
, *tag
, *distance
, *vrf
;
2591 if (!strcmp(argv
[3]->text
, "from"))
2594 idx_ipv6_ifname
= 5;
2600 idx_ipv6_ifname
= 3;
2604 tag
= distance
= vrf
= NULL
;
2605 zebra_vty_ip_route_tdv_helper (argc
, argv
, idx_curr
, &tag
, &distance
, &vrf
, NULL
);
2607 return static_ipv6_func (vty
, 1,
2608 argv
[idx_ipv6_prefixlen
]->arg
,
2610 argv
[idx_ipv6_ifname
]->arg
,
2612 tag
, distance
, vrf
, NULL
);
2615 DEFUN (ipv6_route_flags
,
2616 ipv6_route_flags_cmd
,
2617 "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]",
2619 "Establish static routes\n"
2620 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
2621 "IPv6 source-dest route\n"
2622 "IPv6 source prefix\n"
2623 "IPv6 gateway address\n"
2624 "IPv6 gateway interface name\n"
2625 "Emit an ICMP unreachable when matched\n"
2626 "Silently discard pkts when matched\n"
2627 "Silently discard pkts when matched\n"
2628 "Set tag for this route\n"
2630 "Distance value for this prefix\n"
2632 "Specify labels for this route\n"
2633 "One or more labels separated by '/'\n")
2635 int idx_ipv6_prefixlen
= 2;
2636 int idx_ipv6_ifname
;
2637 int idx_reject_blackhole
;
2639 char *src
, *tag
, *distance
, *vrf
;
2641 if (!strcmp(argv
[3]->text
, "from"))
2644 idx_ipv6_ifname
= 5;
2645 idx_reject_blackhole
= 6;
2651 idx_ipv6_ifname
= 3;
2652 idx_reject_blackhole
= 4;
2656 tag
= distance
= vrf
= NULL
;
2657 zebra_vty_ip_route_tdv_helper (argc
, argv
, idx_curr
, &tag
, &distance
, &vrf
, NULL
);
2659 return static_ipv6_func (vty
, 1,
2660 argv
[idx_ipv6_prefixlen
]->arg
,
2662 argv
[idx_ipv6_ifname
]->arg
,
2664 argv
[idx_reject_blackhole
]->arg
,
2665 tag
, distance
, vrf
, NULL
);
2668 DEFUN (ipv6_route_ifname
,
2669 ipv6_route_ifname_cmd
,
2670 "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]",
2672 "Establish static routes\n"
2673 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
2674 "IPv6 source-dest route\n"
2675 "IPv6 source prefix\n"
2676 "IPv6 gateway address\n"
2677 "IPv6 gateway interface name\n"
2678 "Set tag for this route\n"
2680 "Distance value for this prefix\n"
2682 "Specify labels for this route\n"
2683 "One or more labels separated by '/'\n")
2685 int idx_ipv6_prefixlen
= 2;
2687 int idx_interface
= 4;
2689 char *src
, *tag
, *distance
, *vrf
;
2691 if (!strcmp(argv
[3]->text
, "from"))
2706 tag
= distance
= vrf
= NULL
;
2707 zebra_vty_ip_route_tdv_helper (argc
, argv
, idx_curr
, &tag
, &distance
, &vrf
, NULL
);
2709 return static_ipv6_func (vty
, 1,
2710 argv
[idx_ipv6_prefixlen
]->arg
,
2712 argv
[idx_ipv6
]->arg
,
2713 argv
[idx_interface
]->arg
,
2715 tag
, distance
, vrf
, NULL
);
2718 DEFUN (ipv6_route_ifname_flags
,
2719 ipv6_route_ifname_flags_cmd
,
2720 "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]",
2722 "Establish static routes\n"
2723 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
2724 "IPv6 source-dest route\n"
2725 "IPv6 source prefix\n"
2726 "IPv6 gateway address\n"
2727 "IPv6 gateway interface name\n"
2728 "Emit an ICMP unreachable when matched\n"
2729 "Silently discard pkts when matched\n"
2730 "Set tag for this route\n"
2732 "Distance value for this prefix\n"
2734 "Specify labels for this route\n"
2735 "One or more labels separated by '/'\n")
2737 int idx_ipv6_prefixlen
= 2;
2740 int idx_reject_blackhole
;
2742 char *src
, *tag
, *distance
, *vrf
;
2744 if (!strcmp(argv
[3]->text
, "from"))
2749 idx_reject_blackhole
= 7;
2757 idx_reject_blackhole
= 5;
2761 tag
= distance
= vrf
= NULL
;
2762 zebra_vty_ip_route_tdv_helper (argc
, argv
, idx_curr
, &tag
, &distance
, &vrf
, NULL
);
2764 return static_ipv6_func (vty
, 1,
2765 argv
[idx_ipv6_prefixlen
]->arg
,
2767 argv
[idx_ipv6
]->arg
,
2768 argv
[idx_interface
]->arg
,
2769 argv
[idx_reject_blackhole
]->arg
,
2770 tag
, distance
, vrf
, NULL
);
2773 DEFUN (no_ipv6_route
,
2775 "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]",
2778 "Establish static routes\n"
2779 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
2780 "IPv6 source-dest route\n"
2781 "IPv6 source prefix\n"
2782 "IPv6 gateway address\n"
2783 "IPv6 gateway interface name\n"
2785 "Set tag for this route\n"
2787 "Distance value for this prefix\n"
2789 "Specify labels for this route\n"
2790 "One or more labels separated by '/'\n")
2792 int idx_ipv6_prefixlen
= 3;
2793 int idx_ipv6_ifname
;
2795 char *src
, *tag
, *distance
, *vrf
;
2797 if (!strcmp(argv
[4]->text
, "from"))
2800 idx_ipv6_ifname
= 6;
2806 idx_ipv6_ifname
= 4;
2810 tag
= distance
= vrf
= NULL
;
2811 zebra_vty_ip_route_tdv_helper (argc
, argv
, idx_curr
, &tag
, &distance
, &vrf
, NULL
);
2813 return static_ipv6_func (vty
, 0,
2814 argv
[idx_ipv6_prefixlen
]->arg
,
2816 argv
[idx_ipv6_ifname
]->arg
,
2818 tag
, distance
, vrf
, NULL
);
2821 DEFUN (no_ipv6_route_flags
,
2822 no_ipv6_route_flags_cmd
,
2823 "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]",
2826 "Establish static routes\n"
2827 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
2828 "IPv6 source-dest route\n"
2829 "IPv6 source prefix\n"
2830 "IPv6 gateway address\n"
2831 "IPv6 gateway interface name\n"
2832 "Emit an ICMP unreachable when matched\n"
2833 "Silently discard pkts when matched\n"
2834 "Set tag for this route\n"
2836 "Distance value for this prefix\n"
2838 "Specify labels for this route\n"
2839 "One or more labels separated by '/'\n")
2841 int idx_ipv6_prefixlen
= 3;
2842 int idx_ipv6_ifname
;
2843 int idx_reject_blackhole
;
2845 char *src
, *tag
, *distance
, *vrf
;
2847 if (!strcmp(argv
[4]->text
, "from"))
2850 idx_ipv6_ifname
= 6;
2851 idx_reject_blackhole
= 7;
2857 idx_ipv6_ifname
= 4;
2858 idx_reject_blackhole
= 5;
2862 tag
= distance
= vrf
= NULL
;
2863 zebra_vty_ip_route_tdv_helper (argc
, argv
, idx_curr
, &tag
, &distance
, &vrf
, NULL
);
2865 return static_ipv6_func (vty
, 0,
2866 argv
[idx_ipv6_prefixlen
]->arg
,
2868 argv
[idx_ipv6_ifname
]->arg
,
2870 argv
[idx_reject_blackhole
]->arg
,
2871 tag
, distance
, vrf
, NULL
);
2874 DEFUN (no_ipv6_route_ifname
,
2875 no_ipv6_route_ifname_cmd
,
2876 "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]",
2879 "Establish static routes\n"
2880 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
2881 "IPv6 source-dest route\n"
2882 "IPv6 source prefix\n"
2883 "IPv6 gateway address\n"
2884 "IPv6 gateway interface name\n"
2885 "Set tag for this route\n"
2887 "Distance value for this prefix\n"
2889 "Specify labels for this route\n"
2890 "One or more labels separated by '/'\n")
2892 int idx_ipv6_prefixlen
= 3;
2896 char *src
, *tag
, *distance
, *vrf
;
2898 if (!strcmp(argv
[4]->text
, "from"))
2913 tag
= distance
= vrf
= NULL
;
2914 zebra_vty_ip_route_tdv_helper (argc
, argv
, idx_curr
, &tag
, &distance
, &vrf
, NULL
);
2916 return static_ipv6_func (vty
, 0,
2917 argv
[idx_ipv6_prefixlen
]->arg
,
2919 argv
[idx_ipv6
]->arg
,
2920 argv
[idx_interface
]->arg
,
2922 tag
, distance
, vrf
, NULL
);
2925 DEFUN (no_ipv6_route_ifname_flags
,
2926 no_ipv6_route_ifname_flags_cmd
,
2927 "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]",
2930 "Establish static routes\n"
2931 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
2932 "IPv6 source-dest route\n"
2933 "IPv6 source prefix\n"
2934 "IPv6 gateway address\n"
2935 "IPv6 gateway interface name\n"
2936 "Emit an ICMP unreachable when matched\n"
2937 "Silently discard pkts when matched\n"
2938 "Set tag for this route\n"
2940 "Distance value for this prefix\n"
2942 "Specify labels for this route\n"
2943 "One or more labels separated by '/'\n")
2945 int idx_ipv6_prefixlen
= 3;
2948 int idx_reject_blackhole
;
2950 char *src
, *tag
, *distance
, *vrf
;
2952 if (!strcmp(argv
[4]->text
, "from"))
2957 idx_reject_blackhole
= 8;
2965 idx_reject_blackhole
= 6;
2969 tag
= distance
= vrf
= NULL
;
2970 zebra_vty_ip_route_tdv_helper (argc
, argv
, idx_curr
, &tag
, &distance
, &vrf
, NULL
);
2972 return static_ipv6_func (vty
, 0,
2973 argv
[idx_ipv6_prefixlen
]->arg
,
2975 argv
[idx_ipv6
]->arg
,
2976 argv
[idx_interface
]->arg
,
2977 argv
[idx_reject_blackhole
]->arg
,
2978 tag
, distance
, vrf
, NULL
);
2981 DEFUN (show_ipv6_route
,
2982 show_ipv6_route_cmd
,
2983 "show ipv6 <fib|route> [vrf NAME] [json]",
2986 "IPv6 forwarding table\n"
2987 "IPv6 routing table\n"
2991 struct route_table
*table
;
2992 struct route_node
*rn
;
2995 vrf_id_t vrf_id
= VRF_DEFAULT
;
2996 struct zebra_vrf
*zvrf
= NULL
;
2997 char buf
[SRCDEST2STR_BUFFER
];
2998 json_object
*json
= NULL
;
2999 json_object
*json_prefix
= NULL
;
3000 bool uf
= use_fib(argv
[2]);
3002 int vrf
= (argc
> 3 && strmatch (argv
[3]->text
, "vrf"));
3003 int uj
= vrf
? argc
== 6 : argc
== 4;
3004 char *vrfname
= vrf
? argv
[4]->arg
: NULL
;
3008 if (!(zvrf
= zebra_vrf_lookup_by_name (vrfname
)))
3011 vty_out (vty
, "{}%s", VTY_NEWLINE
);
3013 vty_out (vty
, "vrf %s not defined%s", vrfname
, VTY_NEWLINE
);
3017 if (zvrf_id (zvrf
) == VRF_UNKNOWN
)
3020 vty_out (vty
, "{}%s", VTY_NEWLINE
);
3022 vty_out (vty
, "vrf %s inactive%s", vrfname
, VTY_NEWLINE
);
3026 vrf_id
= zvrf_id (zvrf
);
3029 table
= zebra_vrf_table (AFI_IP6
, SAFI_UNICAST
, vrf_id
);
3033 vty_out (vty
, "{}%s", VTY_NEWLINE
);
3039 json
= json_object_new_object();
3041 /* Show all IPv6 route. */
3042 for (rn
= route_top (table
); rn
; rn
= srcdest_route_next (rn
))
3044 RNODE_FOREACH_RIB (rn
, rib
)
3046 if (uf
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
3049 json_prefix
= json_object_new_array();
3050 vty_show_ip_route (vty
, rn
, rib
, json_prefix
);
3055 srcdest_rnode2str (rn
, buf
, sizeof buf
);
3056 json_object_object_add(json
, buf
, json_prefix
);
3061 vty_out (vty
, "%s%s", json_object_to_json_string_ext(json
, JSON_C_TO_STRING_PRETTY
), VTY_NEWLINE
);
3062 json_object_free(json
);
3066 /* Show all IPv6 route. */
3067 for (rn
= route_top (table
); rn
; rn
= srcdest_route_next (rn
))
3069 RNODE_FOREACH_RIB (rn
, rib
)
3071 if (uf
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
3075 vty_out (vty
, SHOW_ROUTE_V6_HEADER
);
3078 vty_show_ip_route (vty
, rn
, rib
, NULL
);
3086 DEFUN (show_ipv6_route_tag
,
3087 show_ipv6_route_tag_cmd
,
3088 "show ipv6 <fib|route> [vrf NAME] tag (1-4294967295)",
3091 "IPv6 forwarding table\n"
3092 "IPv6 routing table\n"
3094 "Show only routes with tag\n"
3100 struct route_table
*table
;
3101 struct route_node
*rn
;
3104 route_tag_t tag
= 0;
3105 vrf_id_t vrf_id
= VRF_DEFAULT
;
3106 bool uf
= use_fib(argv
[2]);
3108 if (strmatch(argv
[idx_vrf
]->text
, "vrf"))
3110 VRF_GET_ID (vrf_id
, argv
[idx_name
]->arg
);
3111 VTY_GET_INTEGER_RANGE("tag", tag
, argv
[idx_tag
]->arg
, 0, 4294967295);
3116 VTY_GET_INTEGER_RANGE("tag", tag
, argv
[idx_tag
]->arg
, 0, 4294967295);
3119 table
= zebra_vrf_table (AFI_IP6
, SAFI_UNICAST
, vrf_id
);
3123 /* Show all IPv6 routes with matching tag value. */
3124 for (rn
= route_top (table
); rn
; rn
= srcdest_route_next (rn
))
3125 RNODE_FOREACH_RIB (rn
, rib
)
3127 if (uf
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
3129 if (rib
->tag
!= tag
)
3134 vty_out (vty
, SHOW_ROUTE_V6_HEADER
);
3137 vty_show_ip_route (vty
, rn
, rib
, NULL
);
3142 DEFUN (show_ipv6_route_prefix_longer
,
3143 show_ipv6_route_prefix_longer_cmd
,
3144 "show ipv6 <fib|route> [vrf NAME] X:X::X:X/M longer-prefixes",
3147 "IPv6 forwarding table\n"
3148 "IPv6 routing table\n"
3151 "Show route matching the specified Network/Mask pair only\n")
3153 struct route_table
*table
;
3154 struct route_node
*rn
;
3159 vrf_id_t vrf_id
= VRF_DEFAULT
;
3160 bool uf
= use_fib(argv
[2]);
3162 if (strmatch(argv
[3]->text
, "vrf"))
3164 VRF_GET_ID (vrf_id
, argv
[4]->arg
);
3165 ret
= str2prefix (argv
[5]->arg
, &p
);
3169 ret
= str2prefix (argv
[3]->arg
, &p
);
3174 vty_out (vty
, "%% Malformed Prefix%s", VTY_NEWLINE
);
3178 table
= zebra_vrf_table (AFI_IP6
, SAFI_UNICAST
, vrf_id
);
3182 /* Show matched type IPv6 routes. */
3183 for (rn
= route_top (table
); rn
; rn
= srcdest_route_next (rn
))
3184 RNODE_FOREACH_RIB (rn
, rib
)
3186 struct prefix
*p
, *src_p
;
3187 srcdest_rnode_prefixes(rn
, &p
, &src_p
);
3189 if (uf
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
3191 if (prefix_match (p
, &rn
->p
))
3195 vty_out (vty
, SHOW_ROUTE_V6_HEADER
);
3198 vty_show_ip_route (vty
, rn
, rib
, NULL
);
3204 DEFUN (show_ipv6_route_protocol
,
3205 show_ipv6_route_protocol_cmd
,
3206 "show ipv6 <fib|route> [vrf NAME] " FRR_IP6_REDIST_STR_ZEBRA
,
3209 "IPv6 forwarding table\n"
3210 "IPv6 routing table\n"
3212 FRR_IP6_REDIST_HELP_STR_ZEBRA
)
3215 struct route_table
*table
;
3216 struct route_node
*rn
;
3219 vrf_id_t vrf_id
= VRF_DEFAULT
;
3220 bool uf
= use_fib(argv
[2]);
3223 if (argv_find (argv
, argc
, "NAME", &idx
))
3224 VRF_GET_ID (vrf_id
, argv
[idx
]->arg
);
3226 char *proto
= argv
[argc
- 1]->text
;
3227 type
= proto_redistnum (AFI_IP6
, proto
);
3231 vty_out (vty
, "Unknown route type%s", VTY_NEWLINE
);
3235 table
= zebra_vrf_table (AFI_IP6
, SAFI_UNICAST
, vrf_id
);
3239 /* Show matched type IPv6 routes. */
3240 for (rn
= route_top (table
); rn
; rn
= srcdest_route_next (rn
))
3241 RNODE_FOREACH_RIB (rn
, rib
)
3242 if (rib
->type
== type
)
3244 if (uf
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
3248 vty_out (vty
, SHOW_ROUTE_V6_HEADER
);
3251 vty_show_ip_route (vty
, rn
, rib
, NULL
);
3256 DEFUN (show_ipv6_route_addr
,
3257 show_ipv6_route_addr_cmd
,
3258 "show ipv6 route [vrf NAME] X:X::X:X",
3261 "IPv6 routing table\n"
3266 struct prefix_ipv6 p
;
3267 struct route_table
*table
;
3268 struct route_node
*rn
;
3269 vrf_id_t vrf_id
= VRF_DEFAULT
;
3271 if (strmatch(argv
[3]->text
, "vrf"))
3273 VRF_GET_ID (vrf_id
, argv
[4]->arg
);
3274 ret
= str2prefix_ipv6 (argv
[5]->arg
, &p
);
3278 ret
= str2prefix_ipv6 (argv
[3]->arg
, &p
);
3283 vty_out (vty
, "Malformed IPv6 address%s", VTY_NEWLINE
);
3287 table
= zebra_vrf_table (AFI_IP6
, SAFI_UNICAST
, vrf_id
);
3291 rn
= route_node_match (table
, (struct prefix
*) &p
);
3294 vty_out (vty
, "%% Network not in table%s", VTY_NEWLINE
);
3298 vty_show_ip_route_detail (vty
, rn
, 0);
3300 route_unlock_node (rn
);
3305 DEFUN (show_ipv6_route_prefix
,
3306 show_ipv6_route_prefix_cmd
,
3307 "show ipv6 route [vrf NAME] X:X::X:X/M",
3310 "IPv6 routing table\n"
3315 struct prefix_ipv6 p
;
3316 struct route_table
*table
;
3317 struct route_node
*rn
;
3318 vrf_id_t vrf_id
= VRF_DEFAULT
;
3320 if (strmatch(argv
[3]->text
, "vrf"))
3322 VRF_GET_ID (vrf_id
, argv
[4]->arg
);
3323 ret
= str2prefix_ipv6 (argv
[5]->arg
, &p
);
3326 ret
= str2prefix_ipv6 (argv
[3]->arg
, &p
);
3330 vty_out (vty
, "Malformed IPv6 prefix%s", VTY_NEWLINE
);
3334 table
= zebra_vrf_table (AFI_IP6
, SAFI_UNICAST
, vrf_id
);
3338 rn
= route_node_match (table
, (struct prefix
*) &p
);
3339 if (! rn
|| rn
->p
.prefixlen
!= p
.prefixlen
)
3341 vty_out (vty
, "%% Network not in table%s", VTY_NEWLINE
);
3345 vty_show_ip_route_detail (vty
, rn
, 0);
3347 route_unlock_node (rn
);
3353 /* Show route summary. */
3354 DEFUN (show_ipv6_route_summary
,
3355 show_ipv6_route_summary_cmd
,
3356 "show ipv6 route [vrf NAME] summary",
3359 "IPv6 routing table\n"
3361 "Summary of all IPv6 routes\n")
3363 struct route_table
*table
;
3364 vrf_id_t vrf_id
= VRF_DEFAULT
;
3366 if (strmatch(argv
[3]->text
, "vrf"))
3367 VRF_GET_ID (vrf_id
, argv
[4]->arg
);
3369 table
= zebra_vrf_table (AFI_IP6
, SAFI_UNICAST
, vrf_id
);
3373 vty_show_ip_route_summary (vty
, table
);
3379 /* Show ipv6 route summary prefix. */
3380 DEFUN (show_ipv6_route_summary_prefix
,
3381 show_ipv6_route_summary_prefix_cmd
,
3382 "show ipv6 route [vrf NAME] summary prefix",
3385 "IPv6 routing table\n"
3387 "Summary of all IPv6 routes\n"
3390 struct route_table
*table
;
3391 vrf_id_t vrf_id
= VRF_DEFAULT
;
3393 if (strmatch(argv
[3]->text
, "vrf"))
3394 VRF_GET_ID (vrf_id
, argv
[4]->arg
);
3396 table
= zebra_vrf_table (AFI_IP6
, SAFI_UNICAST
, vrf_id
);
3400 vty_show_ip_route_summary_prefix (vty
, table
);
3407 * Show IPv6 mroute command.Used to dump
3408 * the Multicast routing table.
3410 DEFUN (show_ipv6_mroute
,
3411 show_ipv6_mroute_cmd
,
3412 "show ipv6 mroute [vrf NAME]",
3415 "IPv6 Multicast routing table\n"
3418 struct route_table
*table
;
3419 struct route_node
*rn
;
3422 vrf_id_t vrf_id
= VRF_DEFAULT
;
3425 VRF_GET_ID (vrf_id
, argv
[4]->arg
);
3427 table
= zebra_vrf_table (AFI_IP6
, SAFI_MULTICAST
, vrf_id
);
3431 /* Show all IPv6 route. */
3432 for (rn
= route_top (table
); rn
; rn
= srcdest_route_next (rn
))
3433 RNODE_FOREACH_RIB (rn
, rib
)
3437 vty_out (vty
, SHOW_ROUTE_V6_HEADER
);
3440 vty_show_ip_route (vty
, rn
, rib
, NULL
);
3446 DEFUN (show_ipv6_route_vrf_all
,
3447 show_ipv6_route_vrf_all_cmd
,
3448 "show ipv6 <fib|route> vrf all",
3451 "IPv6 forwarding table\n"
3452 "IPv6 routing table\n"
3453 VRF_ALL_CMD_HELP_STR
)
3455 struct route_table
*table
;
3456 struct route_node
*rn
;
3459 struct zebra_vrf
*zvrf
;
3462 bool uf
= use_fib(argv
[2]);
3464 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
3466 if ((zvrf
= vrf
->info
) == NULL
||
3467 (table
= zvrf
->table
[AFI_IP6
][SAFI_UNICAST
]) == NULL
)
3470 /* Show all IPv6 route. */
3471 for (rn
= route_top (table
); rn
; rn
= srcdest_route_next (rn
))
3472 RNODE_FOREACH_RIB (rn
, rib
)
3474 if (uf
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
3478 vty_out (vty
, SHOW_ROUTE_V6_HEADER
);
3484 vty_out (vty
, "%sVRF %s:%s", VTY_NEWLINE
, zvrf_name (zvrf
), VTY_NEWLINE
);
3487 vty_show_ip_route (vty
, rn
, rib
, NULL
);
3495 DEFUN (show_ipv6_route_vrf_all_tag
,
3496 show_ipv6_route_vrf_all_tag_cmd
,
3497 "show ipv6 <fib|route> vrf all tag (1-4294967295)",
3500 "IPv6 forwarding table\n"
3501 "IPv6 routing table\n"
3502 VRF_ALL_CMD_HELP_STR
3503 "Show only routes with tag\n"
3507 struct route_table
*table
;
3508 struct route_node
*rn
;
3511 struct zebra_vrf
*zvrf
;
3514 route_tag_t tag
= 0;
3515 bool uf
= use_fib(argv
[2]);
3517 if (argv
[idx_number
]->arg
)
3518 VTY_GET_INTEGER_RANGE("tag", tag
, argv
[idx_number
]->arg
, 0, 4294967295);
3520 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
3522 if ((zvrf
= vrf
->info
) == NULL
||
3523 (table
= zvrf
->table
[AFI_IP6
][SAFI_UNICAST
]) == NULL
)
3526 /* Show all IPv6 routes with matching tag value. */
3527 for (rn
= route_top (table
); rn
; rn
= srcdest_route_next (rn
))
3528 RNODE_FOREACH_RIB (rn
, rib
)
3530 if (uf
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
3532 if (rib
->tag
!= tag
)
3537 vty_out (vty
, SHOW_ROUTE_V6_HEADER
);
3543 vty_out (vty
, "%sVRF %s:%s", VTY_NEWLINE
, zvrf_name (zvrf
), VTY_NEWLINE
);
3546 vty_show_ip_route (vty
, rn
, rib
, NULL
);
3554 DEFUN (show_ipv6_route_vrf_all_prefix_longer
,
3555 show_ipv6_route_vrf_all_prefix_longer_cmd
,
3556 "show ipv6 <fib|route> vrf all X:X::X:X/M longer-prefixes",
3559 "IPv6 forwarding table\n"
3560 "IPv6 routing table\n"
3561 VRF_ALL_CMD_HELP_STR
3563 "Show route matching the specified Network/Mask pair only\n")
3565 int idx_ipv6_prefixlen
= 5;
3566 struct route_table
*table
;
3567 struct route_node
*rn
;
3571 struct zebra_vrf
*zvrf
;
3575 bool uf
= use_fib(argv
[2]);
3577 ret
= str2prefix (argv
[idx_ipv6_prefixlen
]->arg
, &p
);
3580 vty_out (vty
, "%% Malformed Prefix%s", VTY_NEWLINE
);
3584 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
3586 if ((zvrf
= vrf
->info
) == NULL
||
3587 (table
= zvrf
->table
[AFI_IP6
][SAFI_UNICAST
]) == NULL
)
3590 /* Show matched type IPv6 routes. */
3591 for (rn
= route_top (table
); rn
; rn
= srcdest_route_next (rn
))
3592 RNODE_FOREACH_RIB (rn
, rib
)
3594 struct prefix
*p
, *src_p
;
3595 srcdest_rnode_prefixes(rn
, &p
, &src_p
);
3596 if (uf
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
3598 if (prefix_match (p
, &rn
->p
))
3602 vty_out (vty
, SHOW_ROUTE_V6_HEADER
);
3608 vty_out (vty
, "%sVRF %s:%s", VTY_NEWLINE
, zvrf_name (zvrf
), VTY_NEWLINE
);
3611 vty_show_ip_route (vty
, rn
, rib
, NULL
);
3620 DEFUN (show_ipv6_route_vrf_all_protocol
,
3621 show_ipv6_route_vrf_all_protocol_cmd
,
3622 "show ipv6 <fib|route> vrf all " FRR_IP6_REDIST_STR_ZEBRA
,
3625 "IPv6 forwarding table\n"
3626 "IPv6 routing table\n"
3627 VRF_ALL_CMD_HELP_STR
3628 FRR_IP6_REDIST_HELP_STR_ZEBRA
)
3631 struct route_table
*table
;
3632 struct route_node
*rn
;
3635 struct zebra_vrf
*zvrf
;
3638 bool uf
= use_fib(argv
[2]);
3640 char *proto
= argv
[argc
- 1]->text
;
3641 type
= proto_redistnum (AFI_IP6
, proto
);
3645 vty_out (vty
, "Unknown route type%s", VTY_NEWLINE
);
3649 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
3651 if ((zvrf
= vrf
->info
) == NULL
||
3652 (table
= zvrf
->table
[AFI_IP6
][SAFI_UNICAST
]) == NULL
)
3655 /* Show matched type IPv6 routes. */
3656 for (rn
= route_top (table
); rn
; rn
= srcdest_route_next (rn
))
3657 RNODE_FOREACH_RIB (rn
, rib
)
3658 if (rib
->type
== type
)
3660 if (uf
&& !CHECK_FLAG(rib
->status
, RIB_ENTRY_SELECTED_FIB
))
3664 vty_out (vty
, SHOW_ROUTE_V6_HEADER
);
3670 vty_out (vty
, "%sVRF %s:%s", VTY_NEWLINE
, zvrf_name (zvrf
), VTY_NEWLINE
);
3673 vty_show_ip_route (vty
, rn
, rib
, NULL
);
3681 DEFUN (show_ipv6_route_vrf_all_addr
,
3682 show_ipv6_route_vrf_all_addr_cmd
,
3683 "show ipv6 route vrf all X:X::X:X",
3686 "IPv6 routing table\n"
3687 VRF_ALL_CMD_HELP_STR
3692 struct prefix_ipv6 p
;
3693 struct route_table
*table
;
3694 struct route_node
*rn
;
3696 struct zebra_vrf
*zvrf
;
3698 ret
= str2prefix_ipv6 (argv
[idx_ipv6
]->arg
, &p
);
3701 vty_out (vty
, "Malformed IPv6 address%s", VTY_NEWLINE
);
3705 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
3707 if ((zvrf
= vrf
->info
) == NULL
||
3708 (table
= zvrf
->table
[AFI_IP6
][SAFI_UNICAST
]) == NULL
)
3711 rn
= route_node_match (table
, (struct prefix
*) &p
);
3715 vty_show_ip_route_detail (vty
, rn
, 0);
3717 route_unlock_node (rn
);
3723 DEFUN (show_ipv6_route_vrf_all_prefix
,
3724 show_ipv6_route_vrf_all_prefix_cmd
,
3725 "show ipv6 route vrf all X:X::X:X/M",
3728 "IPv6 routing table\n"
3729 VRF_ALL_CMD_HELP_STR
3732 int idx_ipv6_prefixlen
= 5;
3734 struct prefix_ipv6 p
;
3735 struct route_table
*table
;
3736 struct route_node
*rn
;
3738 struct zebra_vrf
*zvrf
;
3740 ret
= str2prefix_ipv6 (argv
[idx_ipv6_prefixlen
]->arg
, &p
);
3743 vty_out (vty
, "Malformed IPv6 prefix%s", VTY_NEWLINE
);
3747 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
3749 if ((zvrf
= vrf
->info
) == NULL
||
3750 (table
= zvrf
->table
[AFI_IP6
][SAFI_UNICAST
]) == NULL
)
3753 rn
= route_node_match (table
, (struct prefix
*) &p
);
3756 if (rn
->p
.prefixlen
!= p
.prefixlen
)
3758 route_unlock_node (rn
);
3762 vty_show_ip_route_detail (vty
, rn
, 0);
3764 route_unlock_node (rn
);
3770 DEFUN (show_ipv6_route_vrf_all_summary
,
3771 show_ipv6_route_vrf_all_summary_cmd
,
3772 "show ipv6 route vrf all summary",
3775 "IPv6 routing table\n"
3776 VRF_ALL_CMD_HELP_STR
3777 "Summary of all IPv6 routes\n")
3780 struct zebra_vrf
*zvrf
;
3782 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
3783 if ((zvrf
= vrf
->info
) != NULL
)
3784 vty_show_ip_route_summary (vty
, zvrf
->table
[AFI_IP6
][SAFI_UNICAST
]);
3789 DEFUN (show_ipv6_mroute_vrf_all
,
3790 show_ipv6_mroute_vrf_all_cmd
,
3791 "show ipv6 mroute vrf all",
3794 "IPv6 Multicast routing table\n"
3795 VRF_ALL_CMD_HELP_STR
)
3797 struct route_table
*table
;
3798 struct route_node
*rn
;
3801 struct zebra_vrf
*zvrf
;
3804 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
3806 if ((zvrf
= vrf
->info
) == NULL
||
3807 (table
= zvrf
->table
[AFI_IP6
][SAFI_MULTICAST
]) == NULL
)
3810 /* Show all IPv6 route. */
3811 for (rn
= route_top (table
); rn
; rn
= srcdest_route_next (rn
))
3812 RNODE_FOREACH_RIB (rn
, rib
)
3816 vty_out (vty
, SHOW_ROUTE_V6_HEADER
);
3819 vty_show_ip_route (vty
, rn
, rib
, NULL
);
3825 DEFUN (show_ipv6_route_vrf_all_summary_prefix
,
3826 show_ipv6_route_vrf_all_summary_prefix_cmd
,
3827 "show ipv6 route vrf all summary prefix",
3830 "IPv6 routing table\n"
3831 VRF_ALL_CMD_HELP_STR
3832 "Summary of all IPv6 routes\n"
3836 struct zebra_vrf
*zvrf
;
3838 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
3839 if ((zvrf
= vrf
->info
) != NULL
)
3840 vty_show_ip_route_summary_prefix (vty
, zvrf
->table
[AFI_IP6
][SAFI_UNICAST
]);
3845 DEFUN (allow_external_route_update
,
3846 allow_external_route_update_cmd
,
3847 "allow-external-route-update",
3848 "Allow FRR routes to be overwritten by external processes\n")
3855 DEFUN (no_allow_external_route_update
,
3856 no_allow_external_route_update_cmd
,
3857 "no allow-external-route-update",
3859 "Allow FRR routes to be overwritten by external processes\n")
3874 struct zebra_vrf
*zvrf
;
3876 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
3878 if (!(zvrf
= vrf
->info
))
3880 if (!zvrf_id (zvrf
))
3883 vty_out (vty
, "vrf %s ", zvrf_name (zvrf
));
3884 if (zvrf_id (zvrf
) == VRF_UNKNOWN
)
3885 vty_out (vty
, "inactive");
3887 vty_out (vty
, "id %u table %u", zvrf_id (zvrf
), zvrf
->table_id
);
3888 vty_out (vty
, "%s", VTY_NEWLINE
);
3895 /* Static ip route configuration write function. */
3897 zebra_ip_config (struct vty
*vty
)
3901 write
+= static_config (vty
, AFI_IP
, SAFI_UNICAST
, "ip route");
3902 write
+= static_config (vty
, AFI_IP
, SAFI_MULTICAST
, "ip mroute");
3903 write
+= static_config (vty
, AFI_IP6
, SAFI_UNICAST
, "ipv6 route");
3905 write
+= zebra_import_table_config (vty
);
3909 DEFUN (ip_zebra_import_table_distance
,
3910 ip_zebra_import_table_distance_cmd
,
3911 "ip import-table (1-252) [distance (1-255)] [route-map WORD]",
3913 "import routes from non-main kernel table\n"
3914 "kernel routing table id\n"
3915 "Distance for imported routes\n"
3916 "Default distance value\n"
3917 "route-map for filtering\n"
3920 u_int32_t table_id
= 0;
3922 VTY_GET_INTEGER("table", table_id
, argv
[2]->arg
);
3923 int distance
= ZEBRA_TABLE_DISTANCE_DEFAULT
;
3924 char *rmap
= strmatch (argv
[argc
- 2]->text
, "route-map") ?
3925 XSTRDUP(MTYPE_ROUTE_MAP_NAME
, argv
[argc
- 1]->arg
) : NULL
;
3926 if (argc
== 7 || (argc
== 5 && !rmap
))
3927 VTY_GET_INTEGER_RANGE("distance", distance
, argv
[4]->arg
, 1, 255);
3929 if (!is_zebra_valid_kernel_table(table_id
))
3931 vty_out(vty
, "Invalid routing table ID, %d. Must be in range 1-252%s",
3932 table_id
, VTY_NEWLINE
);
3936 if (is_zebra_main_routing_table(table_id
))
3938 vty_out(vty
, "Invalid routing table ID, %d. Must be non-default table%s",
3939 table_id
, VTY_NEWLINE
);
3943 return (zebra_import_table(AFI_IP
, table_id
, distance
, rmap
, 1));
3946 DEFUN (no_ip_zebra_import_table
,
3947 no_ip_zebra_import_table_cmd
,
3948 "no ip import-table (1-252) [distance (1-255)] [route-map NAME]",
3951 "import routes from non-main kernel table\n"
3952 "kernel routing table id\n"
3953 "Distance for imported routes\n"
3954 "Default distance value\n"
3955 "route-map for filtering\n"
3958 u_int32_t table_id
= 0;
3959 VTY_GET_INTEGER("table", table_id
, argv
[3]->arg
);
3961 if (!is_zebra_valid_kernel_table(table_id
))
3963 vty_out(vty
, "Invalid routing table ID. Must be in range 1-252%s",
3968 if (is_zebra_main_routing_table(table_id
))
3970 vty_out(vty
, "Invalid routing table ID, %d. Must be non-default table%s",
3971 table_id
, VTY_NEWLINE
);
3975 if (!is_zebra_import_table_enabled(AFI_IP
, table_id
))
3978 return (zebra_import_table(AFI_IP
, table_id
, 0, NULL
, 0));
3982 config_write_protocol (struct vty
*vty
)
3985 vty_out(vty
, "allow-external-route-update%s", VTY_NEWLINE
);
3987 if (zebra_rnh_ip_default_route
)
3988 vty_out(vty
, "ip nht resolve-via-default%s", VTY_NEWLINE
);
3990 if (zebra_rnh_ipv6_default_route
)
3991 vty_out(vty
, "ipv6 nht resolve-via-default%s", VTY_NEWLINE
);
3993 enum multicast_mode ipv4_multicast_mode
= multicast_mode_ipv4_get ();
3995 if (ipv4_multicast_mode
!= MCAST_NO_CONFIG
)
3996 vty_out (vty
, "ip multicast rpf-lookup-mode %s%s",
3997 ipv4_multicast_mode
== MCAST_URIB_ONLY
? "urib-only" :
3998 ipv4_multicast_mode
== MCAST_MRIB_ONLY
? "mrib-only" :
3999 ipv4_multicast_mode
== MCAST_MIX_MRIB_FIRST
? "mrib-then-urib" :
4000 ipv4_multicast_mode
== MCAST_MIX_DISTANCE
? "lower-distance" :
4004 zebra_routemap_config_write_protocol(vty
);
4009 /* IP node for static routes. */
4010 static struct cmd_node ip_node
= { IP_NODE
, "", 1 };
4011 static struct cmd_node protocol_node
= { PROTOCOL_NODE
, "", 1 };
4015 zebra_vty_init (void)
4017 install_node (&ip_node
, zebra_ip_config
);
4018 install_node (&protocol_node
, config_write_protocol
);
4020 install_element (CONFIG_NODE
, &allow_external_route_update_cmd
);
4021 install_element (CONFIG_NODE
, &no_allow_external_route_update_cmd
);
4022 install_element (CONFIG_NODE
, &ip_mroute_dist_cmd
);
4023 install_element (CONFIG_NODE
, &no_ip_mroute_dist_cmd
);
4024 install_element (CONFIG_NODE
, &ip_multicast_mode_cmd
);
4025 install_element (CONFIG_NODE
, &no_ip_multicast_mode_cmd
);
4026 install_element (CONFIG_NODE
, &ip_route_cmd
);
4027 install_element (CONFIG_NODE
, &ip_route_flags_cmd
);
4028 install_element (CONFIG_NODE
, &ip_route_mask_cmd
);
4029 install_element (CONFIG_NODE
, &ip_route_mask_flags_cmd
);
4030 install_element (CONFIG_NODE
, &no_ip_route_cmd
);
4031 install_element (CONFIG_NODE
, &no_ip_route_mask_cmd
);
4032 install_element (CONFIG_NODE
, &ip_zebra_import_table_distance_cmd
);
4033 install_element (CONFIG_NODE
, &no_ip_zebra_import_table_cmd
);
4035 install_element (VIEW_NODE
, &show_vrf_cmd
);
4036 install_element (VIEW_NODE
, &show_ip_route_cmd
);
4037 install_element (VIEW_NODE
, &show_ip_route_ospf_instance_cmd
);
4038 install_element (VIEW_NODE
, &show_ip_route_tag_cmd
);
4039 install_element (VIEW_NODE
, &show_ip_nht_cmd
);
4040 install_element (VIEW_NODE
, &show_ip_nht_vrf_all_cmd
);
4041 install_element (VIEW_NODE
, &show_ipv6_nht_cmd
);
4042 install_element (VIEW_NODE
, &show_ipv6_nht_vrf_all_cmd
);
4043 install_element (VIEW_NODE
, &show_ip_route_addr_cmd
);
4044 install_element (VIEW_NODE
, &show_ip_route_prefix_cmd
);
4045 install_element (VIEW_NODE
, &show_ip_route_prefix_longer_cmd
);
4046 install_element (VIEW_NODE
, &show_ip_route_protocol_cmd
);
4047 install_element (VIEW_NODE
, &show_ip_route_supernets_cmd
);
4048 install_element (VIEW_NODE
, &show_ip_route_summary_cmd
);
4049 install_element (VIEW_NODE
, &show_ip_route_summary_prefix_cmd
);
4051 install_element (VIEW_NODE
, &show_ip_rpf_cmd
);
4052 install_element (VIEW_NODE
, &show_ip_rpf_addr_cmd
);
4054 /* Commands for VRF */
4056 install_element (CONFIG_NODE
, &no_ip_route_flags_cmd
);
4057 install_element (CONFIG_NODE
, &no_ip_route_mask_flags_cmd
);
4059 install_element (VIEW_NODE
, &show_ip_route_vrf_cmd
);
4061 install_element (VIEW_NODE
, &show_ip_route_vrf_all_cmd
);
4062 install_element (VIEW_NODE
, &show_ip_route_vrf_all_tag_cmd
);
4063 install_element (VIEW_NODE
, &show_ip_route_vrf_all_addr_cmd
);
4064 install_element (VIEW_NODE
, &show_ip_route_vrf_all_prefix_cmd
);
4065 install_element (VIEW_NODE
, &show_ip_route_vrf_all_prefix_longer_cmd
);
4066 install_element (VIEW_NODE
, &show_ip_route_vrf_all_protocol_cmd
);
4067 install_element (VIEW_NODE
, &show_ip_route_vrf_all_supernets_cmd
);
4068 install_element (VIEW_NODE
, &show_ip_route_vrf_all_summary_cmd
);
4069 install_element (VIEW_NODE
, &show_ip_route_vrf_all_summary_prefix_cmd
);
4071 install_element (CONFIG_NODE
, &ipv6_route_cmd
);
4072 install_element (CONFIG_NODE
, &ipv6_route_flags_cmd
);
4073 install_element (CONFIG_NODE
, &ipv6_route_ifname_cmd
);
4074 install_element (CONFIG_NODE
, &ipv6_route_ifname_flags_cmd
);
4075 install_element (CONFIG_NODE
, &no_ipv6_route_cmd
);
4076 install_element (CONFIG_NODE
, &no_ipv6_route_flags_cmd
);
4077 install_element (CONFIG_NODE
, &no_ipv6_route_ifname_cmd
);
4078 install_element (CONFIG_NODE
, &no_ipv6_route_ifname_flags_cmd
);
4079 install_element (CONFIG_NODE
, &ip_nht_default_route_cmd
);
4080 install_element (CONFIG_NODE
, &no_ip_nht_default_route_cmd
);
4081 install_element (CONFIG_NODE
, &ipv6_nht_default_route_cmd
);
4082 install_element (CONFIG_NODE
, &no_ipv6_nht_default_route_cmd
);
4083 install_element (VIEW_NODE
, &show_ipv6_route_cmd
);
4084 install_element (VIEW_NODE
, &show_ipv6_route_tag_cmd
);
4085 install_element (VIEW_NODE
, &show_ipv6_route_summary_cmd
);
4086 install_element (VIEW_NODE
, &show_ipv6_route_summary_prefix_cmd
);
4087 install_element (VIEW_NODE
, &show_ipv6_route_protocol_cmd
);
4088 install_element (VIEW_NODE
, &show_ipv6_route_addr_cmd
);
4089 install_element (VIEW_NODE
, &show_ipv6_route_prefix_cmd
);
4090 install_element (VIEW_NODE
, &show_ipv6_route_prefix_longer_cmd
);
4092 install_element (VIEW_NODE
, &show_ipv6_mroute_cmd
);
4094 /* Commands for VRF */
4095 install_element (VIEW_NODE
, &show_ipv6_route_vrf_all_cmd
);
4096 install_element (VIEW_NODE
, &show_ipv6_route_vrf_all_tag_cmd
);
4097 install_element (VIEW_NODE
, &show_ipv6_route_vrf_all_summary_cmd
);
4098 install_element (VIEW_NODE
, &show_ipv6_route_vrf_all_summary_prefix_cmd
);
4099 install_element (VIEW_NODE
, &show_ipv6_route_vrf_all_protocol_cmd
);
4100 install_element (VIEW_NODE
, &show_ipv6_route_vrf_all_addr_cmd
);
4101 install_element (VIEW_NODE
, &show_ipv6_route_vrf_all_prefix_cmd
);
4102 install_element (VIEW_NODE
, &show_ipv6_route_vrf_all_prefix_longer_cmd
);
4104 install_element (VIEW_NODE
, &show_ipv6_mroute_vrf_all_cmd
);