]> git.proxmox.com Git - mirror_frr.git/blob - zebra/zebra_vty.c
Merge remote-tracking branch 'origin/stable/2.0'
[mirror_frr.git] / zebra / zebra_vty.c
1 /* Zebra VTY functions
2 * Copyright (C) 2002 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
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
9 * later version.
10 *
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.
15 *
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.
20 */
21
22 #include <zebra.h>
23
24 #include "memory.h"
25 #include "zebra_memory.h"
26 #include "if.h"
27 #include "prefix.h"
28 #include "command.h"
29 #include "table.h"
30 #include "rib.h"
31 #include "nexthop.h"
32 #include "vrf.h"
33 #include "mpls.h"
34 #include "lib/json.h"
35 #include "routemap.h"
36
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"
44
45 extern int allow_delete;
46
47 static int do_show_ip_route(struct vty *vty, const char *vrf_name,
48 safi_t safi, u_char use_json);
49 static void vty_show_ip_route_detail (struct vty *vty, struct route_node *rn,
50 int mcast);
51
52 #define ONE_DAY_SECOND 60*60*24
53 #define ONE_WEEK_SECOND 60*60*24*7
54
55 /* General function for static route. */
56 int
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)
62 {
63 int ret;
64 u_char distance;
65 struct prefix p;
66 struct in_addr gate;
67 struct in_addr mask;
68 u_char flag = 0;
69 route_tag_t tag = 0;
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;
75
76 memset (&snh_label, 0, sizeof (struct static_nh_label));
77 ret = str2prefix (dest_str, &p);
78 if (ret <= 0)
79 {
80 vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
81 return CMD_WARNING;
82 }
83
84 /* Cisco like mask notation. */
85 if (mask_str)
86 {
87 ret = inet_aton (mask_str, &mask);
88 if (ret == 0)
89 {
90 vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
91 return CMD_WARNING;
92 }
93 p.prefixlen = ip_masklen (mask);
94 }
95
96 /* Apply mask for given prefix. */
97 apply_mask (&p);
98
99 /* Administrative distance. */
100 if (distance_str)
101 distance = atoi (distance_str);
102 else
103 distance = ZEBRA_STATIC_DISTANCE_DEFAULT;
104
105 /* tag */
106 if (tag_str)
107 VTY_GET_INTEGER_RANGE("tag", tag, tag_str, 0, 4294967295);
108
109 /* VRF id */
110 zvrf = zebra_vrf_lookup_by_name (vrf_id_str);
111
112 if (!zvrf)
113 {
114 vty_out (vty, "%% vrf %s is not defined%s", vrf_id_str, VTY_NEWLINE);
115 return CMD_WARNING;
116 }
117
118 /* Labels */
119 if (label_str)
120 {
121 if (!mpls_enabled)
122 {
123 vty_out (vty, "%% MPLS not turned on in kernel, ignoring command%s",
124 VTY_NEWLINE);
125 return CMD_WARNING;
126 }
127 if (mpls_str2label (label_str, &snh_label.num_labels,
128 snh_label.label))
129 {
130 vty_out (vty, "%% Malformed label(s)%s", VTY_NEWLINE);
131 return CMD_WARNING;
132 }
133 }
134
135 /* Null0 static route. */
136 if ((gate_str != NULL) && (strncasecmp (gate_str, "Null0", strlen (gate_str)) == 0))
137 {
138 if (flag_str)
139 {
140 vty_out (vty, "%% can not have flag %s with Null0%s", flag_str, VTY_NEWLINE);
141 return CMD_WARNING;
142 }
143 if (add_cmd)
144 static_add_route (AFI_IP, safi, type, &p, NULL, ifindex, ifname,
145 ZEBRA_FLAG_BLACKHOLE, tag, distance, zvrf, &snh_label);
146 else
147 static_delete_route (AFI_IP, safi, type, &p, NULL, ifindex, tag,
148 distance, zvrf, &snh_label);
149 return CMD_SUCCESS;
150 }
151
152 /* Route flags */
153 if (flag_str) {
154 switch(flag_str[0]) {
155 case 'r':
156 case 'R': /* XXX */
157 SET_FLAG (flag, ZEBRA_FLAG_REJECT);
158 break;
159 case 'b':
160 case 'B': /* XXX */
161 SET_FLAG (flag, ZEBRA_FLAG_BLACKHOLE);
162 break;
163 default:
164 vty_out (vty, "%% Malformed flag %s %s", flag_str, VTY_NEWLINE);
165 return CMD_WARNING;
166 }
167 }
168
169 if (gate_str == NULL)
170 {
171 if (add_cmd)
172 static_add_route (AFI_IP, safi, type, &p, NULL, ifindex, ifname, flag,
173 tag, distance, zvrf, &snh_label);
174 else
175 static_delete_route (AFI_IP, safi, type, &p, NULL, ifindex, tag, distance,
176 zvrf, &snh_label);
177
178 return CMD_SUCCESS;
179 }
180
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);
184 if (!ret)
185 {
186 struct interface *ifp = if_lookup_by_name_vrf (gate_str, zvrf_id (zvrf));
187 if (!ifp)
188 {
189 vty_out (vty, "%% Unknown interface: %s%s", gate_str, VTY_NEWLINE);
190 ifindex = IFINDEX_DELETED;
191 }
192 else
193 ifindex = ifp->ifindex;
194 ifname = gate_str;
195 type = STATIC_IFINDEX;
196 }
197 else
198 type = STATIC_IPV4_GATEWAY;
199
200 if (add_cmd)
201 static_add_route (AFI_IP, safi, type, &p,
202 ifindex ? NULL : (union g_addr *)&gate, ifindex, ifname,
203 flag, tag, distance, zvrf, &snh_label);
204 else
205 static_delete_route (AFI_IP, safi, type, &p,
206 ifindex ? NULL : (union g_addr *)&gate, ifindex, tag,
207 distance, zvrf, &snh_label);
208
209 return CMD_SUCCESS;
210 }
211
212 /* Static unicast routes for multicast RPF lookup. */
213 DEFUN (ip_mroute_dist,
214 ip_mroute_dist_cmd,
215 "ip mroute A.B.C.D/M <A.B.C.D|INTERFACE> [(1-255)]",
216 IP_STR
217 "Configure static unicast route into MRIB for multicast RPF lookup\n"
218 "IP destination prefix (e.g. 10.0.0.0/8)\n"
219 "Nexthop address\n"
220 "Nexthop interface name\n"
221 "Distance\n")
222 {
223 char *destprefix = argv[2]->arg;
224 char *nexthop = argv[3]->arg;
225 char *distance = (argc == 5) ? argv[4]->arg : NULL;
226
227 return zebra_static_ipv4 (vty, SAFI_MULTICAST, 1, destprefix, NULL, nexthop, NULL, NULL, distance, NULL, NULL);
228 }
229
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)]",
233 NO_STR
234 IP_STR
235 "Configure static unicast route into MRIB for multicast RPF lookup\n"
236 "IP destination prefix (e.g. 10.0.0.0/8)\n"
237 "Nexthop address\n"
238 "Nexthop interface name\n"
239 "Distance\n")
240 {
241 char *destprefix = argv[3]->arg;
242 char *nexthop = argv[4]->arg;
243 char *distance = (argc == 6) ? argv[5]->arg : NULL;
244
245 return zebra_static_ipv4 (vty, SAFI_MULTICAST, 0, destprefix, NULL, nexthop, NULL, NULL, distance, NULL, NULL);
246 }
247
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>",
251 IP_STR
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")
259 {
260 char *mode = argv[3]->text;
261
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);
272 else
273 {
274 vty_out (vty, "Invalid mode specified%s", VTY_NEWLINE);
275 return CMD_WARNING;
276 }
277
278 return CMD_SUCCESS;
279 }
280
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>]",
284 NO_STR
285 IP_STR
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")
293 {
294 multicast_mode_ipv4_set (MCAST_NO_CONFIG);
295 return CMD_SUCCESS;
296 }
297
298
299 DEFUN (show_ip_rpf,
300 show_ip_rpf_cmd,
301 "show ip rpf",
302 SHOW_STR
303 IP_STR
304 "Display RPF information for multicast source\n")
305 {
306 return do_show_ip_route(vty, VRF_DEFAULT_NAME, SAFI_MULTICAST, 0);
307 }
308
309 DEFUN (show_ip_rpf_addr,
310 show_ip_rpf_addr_cmd,
311 "show ip rpf A.B.C.D",
312 SHOW_STR
313 IP_STR
314 "Display RPF information for multicast source\n"
315 "IP multicast source address (e.g. 10.0.0.0)\n")
316 {
317 int idx_ipv4 = 3;
318 struct in_addr addr;
319 struct route_node *rn;
320 struct rib *rib;
321 int ret;
322
323 ret = inet_aton (argv[idx_ipv4]->arg, &addr);
324 if (ret == 0)
325 {
326 vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
327 return CMD_WARNING;
328 }
329
330 rib = rib_match_ipv4_multicast (VRF_DEFAULT, addr, &rn);
331
332 if (rib)
333 vty_show_ip_route_detail (vty, rn, 1);
334 else
335 vty_out (vty, "%% No match for RPF lookup%s", VTY_NEWLINE);
336
337 return CMD_SUCCESS;
338 }
339
340 static void
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)
344 {
345 *distance = NULL;
346 while (idx_curr < argc)
347 {
348 if (strmatch (argv[idx_curr]->text, "tag"))
349 {
350 if (tag)
351 *tag = argv[idx_curr+1]->arg;
352 idx_curr += 2;
353 }
354 else if (strmatch (argv[idx_curr]->text, "vrf"))
355 {
356 if (vrf)
357 *vrf = argv[idx_curr+1]->arg;
358 idx_curr += 2;
359 }
360 else if (strmatch (argv[idx_curr]->text, "label"))
361 {
362 if (labels)
363 *labels = argv[idx_curr+1]->arg;
364 idx_curr += 2;
365 }
366 else
367 {
368 if (distance)
369 *distance = argv[idx_curr]->arg;
370 idx_curr++;
371 }
372 }
373
374 return;
375 }
376
377 /* Static route configuration. */
378 DEFUN (ip_route,
379 ip_route_cmd,
380 "ip route A.B.C.D/M <A.B.C.D|INTERFACE|null0> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
381 IP_STR
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"
386 "Null interface\n"
387 "Set tag for this route\n"
388 "Tag value\n"
389 "Distance value for this route\n"
390 VRF_CMD_HELP_STR)
391 {
392 int idx_ipv4_prefixlen = 2;
393 int idx_ipv4_ifname_null = 3;
394 int idx_curr = 4;
395 char *tag, *distance, *vrf;
396
397 tag = distance = vrf = NULL;
398 zebra_vty_ip_route_tdv_helper (argc, argv, idx_curr, &tag, &distance, &vrf, NULL);
399
400 return zebra_static_ipv4 (vty, SAFI_UNICAST, 1,
401 argv[idx_ipv4_prefixlen]->arg,
402 NULL,
403 argv[idx_ipv4_ifname_null]->arg,
404 NULL,
405 tag, distance, vrf, NULL);
406 }
407
408 DEFUN (ip_route_flags,
409 ip_route_flags_cmd,
410 "ip route A.B.C.D/M <reject|blackhole> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
411 IP_STR
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"
417 "Tag value\n"
418 "Distance value for this route\n"
419 VRF_CMD_HELP_STR
420 "Specify labels for this route\n"
421 "One or more labels separated by '/'\n")
422 {
423 int idx_ipv4_prefixlen = 2;
424 int idx_reject_blackhole = 3;
425 int idx_curr = 4;
426 char *tag, *distance, *vrf;
427
428 tag = distance = vrf = NULL;
429 zebra_vty_ip_route_tdv_helper (argc, argv, idx_curr, &tag, &distance, &vrf, NULL);
430
431 return zebra_static_ipv4 (vty, SAFI_UNICAST, 1,
432 argv[idx_ipv4_prefixlen]->arg,
433 NULL,
434 NULL,
435 argv[idx_reject_blackhole]->arg,
436 tag, distance, vrf, NULL);
437 }
438
439 /* Mask as A.B.C.D format. */
440 DEFUN (ip_route_mask,
441 ip_route_mask_cmd,
442 "ip route A.B.C.D A.B.C.D <A.B.C.D|INTERFACE|null0> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
443 IP_STR
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"
449 "Null interface\n"
450 "Set tag for this route\n"
451 "Tag value\n"
452 "Distance value for this route\n"
453 VRF_CMD_HELP_STR
454 "Specify labels for this route\n"
455 "One or more labels separated by '/'\n")
456 {
457 int idx_ipv4 = 2;
458 int idx_ipv4_2 = 3;
459 int idx_ipv4_ifname_null = 4;
460 int idx_curr = 5;
461 char *tag, *distance, *vrf;
462
463 tag = distance = vrf = NULL;
464 zebra_vty_ip_route_tdv_helper (argc, argv, idx_curr, &tag, &distance, &vrf, NULL);
465
466 return zebra_static_ipv4 (vty, SAFI_UNICAST, 1,
467 argv[idx_ipv4]->arg,
468 argv[idx_ipv4_2]->arg,
469 argv[idx_ipv4_ifname_null]->arg,
470 NULL, tag, distance, vrf, NULL);
471 }
472
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]",
476 IP_STR
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"
483 "Tag value\n"
484 "Distance value for this route\n"
485 VRF_CMD_HELP_STR
486 "Specify labels for this route\n"
487 "One or more labels separated by '/'\n")
488 {
489 int idx_ipv4 = 2;
490 int idx_ipv4_2 = 3;
491 int idx_reject_blackhole = 4;
492 int idx_curr = 5;
493 char *tag, *distance, *vrf;
494
495 tag = distance = vrf = NULL;
496 zebra_vty_ip_route_tdv_helper (argc, argv, idx_curr, &tag, &distance, &vrf, NULL);
497
498 return zebra_static_ipv4 (vty, SAFI_UNICAST, 1,
499 argv[idx_ipv4]->arg,
500 argv[idx_ipv4_2]->arg,
501 NULL,
502 argv[idx_reject_blackhole]->arg,
503 tag, distance, vrf, NULL);
504 }
505
506 DEFUN (no_ip_route,
507 no_ip_route_cmd,
508 "no ip route A.B.C.D/M <A.B.C.D|INTERFACE|null0> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
509 NO_STR
510 IP_STR
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"
515 "Null interface\n"
516 "Tag of this route\n"
517 "Tag value\n"
518 "Distance value for this route\n"
519 VRF_CMD_HELP_STR
520 "Specify labels for this route\n"
521 "One or more labels separated by '/'\n")
522 {
523 int idx_ipv4_prefixlen = 3;
524 int idx_ipv4_ifname_null = 4;
525 int idx_curr = 5;
526 char *tag, *distance, *vrf;
527
528 tag = distance = vrf = NULL;
529 zebra_vty_ip_route_tdv_helper (argc, argv, idx_curr, &tag, &distance, &vrf, NULL);
530
531 return zebra_static_ipv4 (vty, SAFI_UNICAST, 0,
532 argv[idx_ipv4_prefixlen]->arg,
533 NULL,
534 argv[idx_ipv4_ifname_null]->arg,
535 NULL,
536 tag, distance, vrf, NULL);
537 }
538
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]",
542 NO_STR
543 IP_STR
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"
549 "Tag value\n"
550 "Distance value for this route\n"
551 VRF_CMD_HELP_STR
552 "Specify labels for this route\n"
553 "One or more labels separated by '/'\n")
554 {
555 int idx_ipv4_prefixlen = 3;
556 int idx_curr = 5;
557 char *tag, *distance, *vrf;
558
559 tag = distance = vrf = NULL;
560 zebra_vty_ip_route_tdv_helper (argc, argv, idx_curr, &tag, &distance, &vrf, NULL);
561
562 return zebra_static_ipv4 (vty, SAFI_UNICAST, 0,
563 argv[idx_ipv4_prefixlen]->arg,
564 NULL, NULL, NULL,
565 tag, distance, vrf, NULL);
566 }
567
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]",
571 NO_STR
572 IP_STR
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"
578 "Null interface\n"
579 "Tag of this route\n"
580 "Tag value\n"
581 "Distance value for this route\n"
582 VRF_CMD_HELP_STR
583 "Specify labels for this route\n"
584 "One or more labels separated by '/'\n")
585 {
586 int idx_ipv4 = 3;
587 int idx_ipv4_2 = 4;
588 int idx_ipv4_ifname_null = 5;
589 int idx_curr = 6;
590 char *tag, *distance, *vrf;
591
592 tag = distance = vrf = NULL;
593 zebra_vty_ip_route_tdv_helper (argc, argv, idx_curr, &tag, &distance, &vrf, NULL);
594
595 return zebra_static_ipv4 (vty, SAFI_UNICAST, 0,
596 argv[idx_ipv4]->arg,
597 argv[idx_ipv4_2]->arg,
598 argv[idx_ipv4_ifname_null]->arg,
599 NULL,
600 tag, distance, vrf, NULL);
601 }
602
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]",
606 NO_STR
607 IP_STR
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"
614 "Tag value\n"
615 "Distance value for this route\n"
616 VRF_CMD_HELP_STR
617 "Specify labels for this route\n"
618 "One or more labels separated by '/'\n")
619 {
620 int idx_ipv4 = 3;
621 int idx_ipv4_2 = 4;
622 int idx_curr = 6;
623 char *tag, *distance, *vrf;
624
625 tag = distance = vrf = NULL;
626 zebra_vty_ip_route_tdv_helper (argc, argv, idx_curr, &tag, &distance, &vrf, NULL);
627
628 return zebra_static_ipv4 (vty, SAFI_UNICAST, 0,
629 argv[idx_ipv4]->arg,
630 argv[idx_ipv4_2]->arg,
631 NULL, NULL,
632 tag, distance, vrf, NULL);
633 }
634
635 /* New RIB. Detailed information for IPv4 route. */
636 static void
637 vty_show_ip_route_detail (struct vty *vty, struct route_node *rn, int mcast)
638 {
639 struct rib *rib;
640 struct nexthop *nexthop, *tnexthop;
641 int recursing;
642 char buf[PREFIX_STRLEN];
643 struct zebra_vrf *zvrf;
644
645 RNODE_FOREACH_RIB (rn, rib)
646 {
647 const char *mcast_info = "";
648 if (mcast)
649 {
650 rib_table_info_t *info = rn->table->info;
651 mcast_info = (info->safi == SAFI_MULTICAST)
652 ? " using Multicast RIB"
653 : " using Unicast RIB";
654 }
655
656 vty_out (vty, "Routing entry for %s%s%s",
657 prefix2str (&rn->p, buf, sizeof(buf)), mcast_info,
658 VTY_NEWLINE);
659 vty_out (vty, " Known via \"%s", zebra_route_string (rib->type));
660 if (rib->instance)
661 vty_out (vty, "[%d]", rib->instance);
662 vty_out (vty, "\"");
663 vty_out (vty, ", distance %u, metric %u", rib->distance, rib->metric);
664 if (rib->tag)
665 vty_out (vty, ", tag %d", rib->tag);
666 if (rib->mtu)
667 vty_out (vty, ", mtu %u", rib->mtu);
668 if (rib->vrf_id != VRF_DEFAULT)
669 {
670 zvrf = vrf_info_lookup(rib->vrf_id);
671 vty_out (vty, ", vrf %s", zvrf_name (zvrf));
672 }
673 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
674 vty_out (vty, ", best");
675 if (rib->refcnt)
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);
682
683 if (rib->type == ZEBRA_ROUTE_RIP
684 || rib->type == ZEBRA_ROUTE_OSPF
685 || rib->type == ZEBRA_ROUTE_ISIS
686 || rib->type == ZEBRA_ROUTE_TABLE
687 || rib->type == ZEBRA_ROUTE_BGP)
688 {
689 time_t uptime;
690 struct tm *tm;
691
692 uptime = time (NULL);
693 uptime -= rib->uptime;
694 tm = gmtime (&uptime);
695
696 vty_out (vty, " Last update ");
697
698 if (uptime < ONE_DAY_SECOND)
699 vty_out (vty, "%02d:%02d:%02d",
700 tm->tm_hour, tm->tm_min, tm->tm_sec);
701 else if (uptime < ONE_WEEK_SECOND)
702 vty_out (vty, "%dd%02dh%02dm",
703 tm->tm_yday, tm->tm_hour, tm->tm_min);
704 else
705 vty_out (vty, "%02dw%dd%02dh",
706 tm->tm_yday/7,
707 tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
708 vty_out (vty, " ago%s", VTY_NEWLINE);
709 }
710
711 for (ALL_NEXTHOPS_RO(rib->nexthop, nexthop, tnexthop, recursing))
712 {
713 char addrstr[32];
714
715 vty_out (vty, " %c%s",
716 CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB) ? '*' : ' ',
717 recursing ? " " : "");
718
719 switch (nexthop->type)
720 {
721 case NEXTHOP_TYPE_IPV4:
722 case NEXTHOP_TYPE_IPV4_IFINDEX:
723 vty_out (vty, " %s", inet_ntoa (nexthop->gate.ipv4));
724 if (nexthop->ifindex)
725 vty_out (vty, ", via %s",
726 ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id));
727 break;
728 case NEXTHOP_TYPE_IPV6:
729 case NEXTHOP_TYPE_IPV6_IFINDEX:
730 vty_out (vty, " %s",
731 inet_ntop (AF_INET6, &nexthop->gate.ipv6, buf, BUFSIZ));
732 if (nexthop->ifindex)
733 vty_out (vty, ", via %s",
734 ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id));
735 break;
736 case NEXTHOP_TYPE_IFINDEX:
737 vty_out (vty, " directly connected, %s",
738 ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id));
739 break;
740 case NEXTHOP_TYPE_BLACKHOLE:
741 vty_out (vty, " directly connected, Null0");
742 break;
743 default:
744 break;
745 }
746 if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
747 vty_out (vty, " inactive");
748
749 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ONLINK))
750 vty_out (vty, " onlink");
751
752 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
753 vty_out (vty, " (recursive)");
754
755 switch (nexthop->type)
756 {
757 case NEXTHOP_TYPE_IPV4:
758 case NEXTHOP_TYPE_IPV4_IFINDEX:
759 if (nexthop->src.ipv4.s_addr)
760 {
761 if (inet_ntop(AF_INET, &nexthop->src.ipv4, addrstr,
762 sizeof addrstr))
763 vty_out (vty, ", src %s", addrstr);
764 }
765 break;
766 case NEXTHOP_TYPE_IPV6:
767 case NEXTHOP_TYPE_IPV6_IFINDEX:
768 if (!IPV6_ADDR_SAME(&nexthop->src.ipv6, &in6addr_any))
769 {
770 if (inet_ntop(AF_INET6, &nexthop->src.ipv6, addrstr,
771 sizeof addrstr))
772 vty_out (vty, ", src %s", addrstr);
773 }
774 break;
775 default:
776 break;
777 }
778
779 /* Label information */
780 if (nexthop->nh_label && nexthop->nh_label->num_labels)
781 {
782 vty_out (vty, " label %s",
783 mpls_label2str (nexthop->nh_label->num_labels,
784 nexthop->nh_label->label, buf, BUFSIZ));
785 }
786
787 vty_out (vty, "%s", VTY_NEWLINE);
788 }
789 vty_out (vty, "%s", VTY_NEWLINE);
790 }
791 }
792
793 static void
794 vty_show_ip_route (struct vty *vty, struct route_node *rn, struct rib *rib,
795 json_object *json)
796 {
797 struct nexthop *nexthop, *tnexthop;
798 int recursing;
799 int len = 0;
800 char buf[BUFSIZ];
801 json_object *json_nexthops = NULL;
802 json_object *json_nexthop = NULL;
803 json_object *json_route = NULL;
804
805 if (json)
806 {
807 json_route = json_object_new_object();
808 json_nexthops = json_object_new_array();
809
810 json_object_string_add(json_route, "prefix", prefix2str (&rn->p, buf, sizeof buf));
811 json_object_string_add(json_route, "protocol", zebra_route_string(rib->type));
812
813 if (rib->instance)
814 json_object_int_add(json_route, "instance", rib->instance);
815
816 if (rib->vrf_id)
817 json_object_int_add(json_route, "vrfId", rib->vrf_id);
818
819 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
820 json_object_boolean_true_add(json_route, "selected");
821
822 if (rib->type != ZEBRA_ROUTE_CONNECT && rib->type != ZEBRA_ROUTE_KERNEL)
823 {
824 json_object_int_add(json_route, "distance", rib->distance);
825 json_object_int_add(json_route, "metric", rib->metric);
826 }
827
828 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
829 json_object_boolean_true_add(json_route, "blackhole");
830
831 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT))
832 json_object_boolean_true_add(json_route, "reject");
833
834 if (rib->type == ZEBRA_ROUTE_RIP
835 || rib->type == ZEBRA_ROUTE_OSPF
836 || rib->type == ZEBRA_ROUTE_ISIS
837 || rib->type == ZEBRA_ROUTE_TABLE
838 || rib->type == ZEBRA_ROUTE_BGP)
839 {
840 time_t uptime;
841 struct tm *tm;
842
843 uptime = time (NULL);
844 uptime -= rib->uptime;
845 tm = gmtime (&uptime);
846
847 if (uptime < ONE_DAY_SECOND)
848 sprintf(buf, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min, tm->tm_sec);
849 else if (uptime < ONE_WEEK_SECOND)
850 sprintf(buf, "%dd%02dh%02dm", tm->tm_yday, tm->tm_hour, tm->tm_min);
851 else
852 sprintf(buf, "%02dw%dd%02dh", tm->tm_yday/7, tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
853
854 json_object_string_add(json_route, "uptime", buf);
855 }
856
857 for (ALL_NEXTHOPS_RO(rib->nexthop, nexthop, tnexthop, recursing))
858 {
859 json_nexthop = json_object_new_object();
860
861 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB))
862 json_object_boolean_true_add(json_nexthop, "fib");
863
864 switch (nexthop->type)
865 {
866 case NEXTHOP_TYPE_IPV4:
867 case NEXTHOP_TYPE_IPV4_IFINDEX:
868 json_object_string_add(json_nexthop, "ip", inet_ntoa (nexthop->gate.ipv4));
869 json_object_string_add(json_nexthop, "afi", "ipv4");
870
871 if (nexthop->ifindex)
872 {
873 json_object_int_add(json_nexthop, "interfaceIndex", nexthop->ifindex);
874 json_object_string_add(json_nexthop, "interfaceName", ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id));
875 }
876 break;
877 case NEXTHOP_TYPE_IPV6:
878 case NEXTHOP_TYPE_IPV6_IFINDEX:
879 json_object_string_add(json_nexthop, "ip", inet_ntop (AF_INET6, &nexthop->gate.ipv6, buf, BUFSIZ));
880 json_object_string_add(json_nexthop, "afi", "ipv6");
881
882 if (nexthop->ifindex)
883 {
884 json_object_int_add(json_nexthop, "interfaceIndex", nexthop->ifindex);
885 json_object_string_add(json_nexthop, "interfaceName", ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id));
886 }
887 break;
888
889 case NEXTHOP_TYPE_IFINDEX:
890 json_object_boolean_true_add(json_nexthop, "directlyConnected");
891 json_object_int_add(json_nexthop, "interfaceIndex", nexthop->ifindex);
892 json_object_string_add(json_nexthop, "interfaceName", ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id));
893 break;
894 case NEXTHOP_TYPE_BLACKHOLE:
895 json_object_boolean_true_add(json_nexthop, "blackhole");
896 break;
897 default:
898 break;
899 }
900
901 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
902 json_object_boolean_true_add(json_nexthop, "active");
903
904 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ONLINK))
905 json_object_boolean_true_add(json_nexthop, "onLink");
906
907 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
908 json_object_boolean_true_add(json_nexthop, "recursive");
909
910 switch (nexthop->type)
911 {
912 case NEXTHOP_TYPE_IPV4:
913 case NEXTHOP_TYPE_IPV4_IFINDEX:
914 if (nexthop->src.ipv4.s_addr)
915 {
916 if (inet_ntop(AF_INET, &nexthop->src.ipv4, buf, sizeof buf))
917 json_object_string_add(json_nexthop, "source", buf);
918 }
919 break;
920 case NEXTHOP_TYPE_IPV6:
921 case NEXTHOP_TYPE_IPV6_IFINDEX:
922 if (!IPV6_ADDR_SAME(&nexthop->src.ipv6, &in6addr_any))
923 {
924 if (inet_ntop(AF_INET6, &nexthop->src.ipv6, buf, sizeof buf))
925 json_object_string_add(json_nexthop, "source", buf);
926 }
927 break;
928 default:
929 break;
930 }
931
932 json_object_array_add(json_nexthops, json_nexthop);
933 }
934
935 json_object_object_add(json_route, "nexthops", json_nexthops);
936 json_object_array_add(json, json_route);
937 return;
938 }
939
940 /* Nexthop information. */
941 for (ALL_NEXTHOPS_RO(rib->nexthop, nexthop, tnexthop, recursing))
942 {
943 if (nexthop == rib->nexthop)
944 {
945 /* Prefix information. */
946 len = vty_out (vty, "%c", zebra_route_char (rib->type));
947 if (rib->instance)
948 len += vty_out (vty, "[%d]", rib->instance);
949 len += vty_out (vty, "%c%c %s",
950 CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED)
951 ? '>' : ' ',
952 CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
953 ? '*' : ' ',
954 prefix2str (&rn->p, buf, sizeof buf));
955
956 /* Distance and metric display. */
957 if (rib->type != ZEBRA_ROUTE_CONNECT
958 && rib->type != ZEBRA_ROUTE_KERNEL)
959 len += vty_out (vty, " [%d/%d]", rib->distance,
960 rib->metric);
961 }
962 else
963 vty_out (vty, " %c%*c",
964 CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
965 ? '*' : ' ',
966 len - 3 + (2 * recursing), ' ');
967
968 switch (nexthop->type)
969 {
970 case NEXTHOP_TYPE_IPV4:
971 case NEXTHOP_TYPE_IPV4_IFINDEX:
972 vty_out (vty, " via %s", inet_ntoa (nexthop->gate.ipv4));
973 if (nexthop->ifindex)
974 vty_out (vty, ", %s",
975 ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id));
976 break;
977 case NEXTHOP_TYPE_IPV6:
978 case NEXTHOP_TYPE_IPV6_IFINDEX:
979 vty_out (vty, " via %s",
980 inet_ntop (AF_INET6, &nexthop->gate.ipv6, buf, BUFSIZ));
981 if (nexthop->ifindex)
982 vty_out (vty, ", %s",
983 ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id));
984 break;
985
986 case NEXTHOP_TYPE_IFINDEX:
987 vty_out (vty, " is directly connected, %s",
988 ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id));
989 break;
990 case NEXTHOP_TYPE_BLACKHOLE:
991 vty_out (vty, " is directly connected, Null0");
992 break;
993 default:
994 break;
995 }
996 if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
997 vty_out (vty, " inactive");
998
999 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ONLINK))
1000 vty_out (vty, " onlink");
1001
1002 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
1003 vty_out (vty, " (recursive)");
1004
1005 switch (nexthop->type)
1006 {
1007 case NEXTHOP_TYPE_IPV4:
1008 case NEXTHOP_TYPE_IPV4_IFINDEX:
1009 if (nexthop->src.ipv4.s_addr)
1010 {
1011 if (inet_ntop(AF_INET, &nexthop->src.ipv4, buf, sizeof buf))
1012 vty_out (vty, ", src %s", buf);
1013 }
1014 break;
1015 case NEXTHOP_TYPE_IPV6:
1016 case NEXTHOP_TYPE_IPV6_IFINDEX:
1017 if (!IPV6_ADDR_SAME(&nexthop->src.ipv6, &in6addr_any))
1018 {
1019 if (inet_ntop(AF_INET6, &nexthop->src.ipv6, buf, sizeof buf))
1020 vty_out (vty, ", src %s", buf);
1021 }
1022 break;
1023 default:
1024 break;
1025 }
1026
1027 /* Label information */
1028 if (nexthop->nh_label && nexthop->nh_label->num_labels)
1029 {
1030 vty_out (vty, " label %s",
1031 mpls_label2str (nexthop->nh_label->num_labels,
1032 nexthop->nh_label->label, buf, BUFSIZ));
1033 }
1034
1035 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
1036 vty_out (vty, ", bh");
1037 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT))
1038 vty_out (vty, ", rej");
1039
1040 if (rib->type == ZEBRA_ROUTE_RIP
1041 || rib->type == ZEBRA_ROUTE_OSPF
1042 || rib->type == ZEBRA_ROUTE_ISIS
1043 || rib->type == ZEBRA_ROUTE_TABLE
1044 || rib->type == ZEBRA_ROUTE_BGP)
1045 {
1046 time_t uptime;
1047 struct tm *tm;
1048
1049 uptime = time (NULL);
1050 uptime -= rib->uptime;
1051 tm = gmtime (&uptime);
1052
1053 if (uptime < ONE_DAY_SECOND)
1054 vty_out (vty, ", %02d:%02d:%02d",
1055 tm->tm_hour, tm->tm_min, tm->tm_sec);
1056 else if (uptime < ONE_WEEK_SECOND)
1057 vty_out (vty, ", %dd%02dh%02dm",
1058 tm->tm_yday, tm->tm_hour, tm->tm_min);
1059 else
1060 vty_out (vty, ", %02dw%dd%02dh",
1061 tm->tm_yday/7,
1062 tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
1063 }
1064 vty_out (vty, "%s", VTY_NEWLINE);
1065 }
1066 }
1067
1068 DEFUN (show_ip_route,
1069 show_ip_route_cmd,
1070 "show ip route [json]",
1071 SHOW_STR
1072 IP_STR
1073 "IP routing table\n"
1074 JSON_STR)
1075 {
1076 return do_show_ip_route (vty, VRF_DEFAULT_NAME, SAFI_UNICAST, use_json(argc, argv));
1077 }
1078
1079 static int
1080 do_show_ip_route (struct vty *vty, const char *vrf_name, safi_t safi,
1081 u_char use_json)
1082 {
1083 struct route_table *table;
1084 struct route_node *rn;
1085 struct rib *rib;
1086 int first = 1;
1087 struct zebra_vrf *zvrf = NULL;
1088 char buf[BUFSIZ];
1089 json_object *json = NULL;
1090 json_object *json_prefix = NULL;
1091
1092 if (!(zvrf = zebra_vrf_lookup_by_name (vrf_name)))
1093 {
1094 if (use_json)
1095 vty_out (vty, "{}%s", VTY_NEWLINE);
1096 else
1097 vty_out (vty, "vrf %s not defined%s", vrf_name, VTY_NEWLINE);
1098 return CMD_SUCCESS;
1099 }
1100
1101 if (zvrf_id (zvrf) == VRF_UNKNOWN)
1102 {
1103 if (use_json)
1104 vty_out (vty, "{}%s", VTY_NEWLINE);
1105 else
1106 vty_out (vty, "vrf %s inactive%s", vrf_name, VTY_NEWLINE);
1107 return CMD_SUCCESS;
1108 }
1109
1110 table = zebra_vrf_table (AFI_IP, safi, zvrf_id (zvrf));
1111 if (! table)
1112 {
1113 if (use_json)
1114 vty_out (vty, "{}%s", VTY_NEWLINE);
1115 return CMD_SUCCESS;
1116 }
1117
1118 if (use_json)
1119 {
1120 json = json_object_new_object();
1121
1122 /* Show all IPv4 routes. */
1123 for (rn = route_top (table); rn; rn = route_next (rn))
1124 {
1125 RNODE_FOREACH_RIB (rn, rib)
1126 {
1127 if (!json_prefix)
1128 json_prefix = json_object_new_array();
1129 vty_show_ip_route (vty, rn, rib, json_prefix);
1130 }
1131
1132 if (json_prefix)
1133 {
1134 prefix2str (&rn->p, buf, sizeof buf);
1135 json_object_object_add(json, buf, json_prefix);
1136 json_prefix = NULL;
1137 }
1138 }
1139
1140 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
1141 json_object_free(json);
1142 }
1143 else
1144 {
1145 /* Show all IPv4 routes. */
1146 for (rn = route_top (table); rn; rn = route_next (rn))
1147 {
1148 RNODE_FOREACH_RIB (rn, rib)
1149 {
1150 if (first)
1151 {
1152 vty_out (vty, SHOW_ROUTE_V4_HEADER);
1153 first = 0;
1154 }
1155 vty_show_ip_route (vty, rn, rib, NULL);
1156 }
1157 }
1158 }
1159
1160 return CMD_SUCCESS;
1161 }
1162
1163 DEFUN (show_ip_route_vrf,
1164 show_ip_route_vrf_cmd,
1165 "show ip route vrf NAME [json]",
1166 SHOW_STR
1167 IP_STR
1168 "IP routing table\n"
1169 VRF_CMD_HELP_STR
1170 JSON_STR)
1171 {
1172 int idx_vrf = 4;
1173 u_char uj = use_json(argc, argv);
1174
1175 return do_show_ip_route (vty, argv[idx_vrf]->arg, SAFI_UNICAST, uj);
1176 }
1177
1178 DEFUN (show_ip_nht,
1179 show_ip_nht_cmd,
1180 "show ip nht [vrf NAME]",
1181 SHOW_STR
1182 IP_STR
1183 "IP nexthop tracking table\n"
1184 VRF_CMD_HELP_STR)
1185 {
1186 int idx_vrf = 4;
1187 vrf_id_t vrf_id = VRF_DEFAULT;
1188
1189 if (argc == 5)
1190 VRF_GET_ID (vrf_id, argv[idx_vrf]->arg);
1191
1192 zebra_print_rnh_table(vrf_id, AF_INET, vty, RNH_NEXTHOP_TYPE);
1193 return CMD_SUCCESS;
1194 }
1195
1196
1197 DEFUN (show_ip_nht_vrf_all,
1198 show_ip_nht_vrf_all_cmd,
1199 "show ip nht vrf all",
1200 SHOW_STR
1201 IP_STR
1202 "IP nexthop tracking table\n"
1203 VRF_ALL_CMD_HELP_STR)
1204 {
1205 struct vrf *vrf;
1206 struct zebra_vrf *zvrf;
1207
1208 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
1209 if ((zvrf = vrf->info) != NULL)
1210 {
1211 vty_out (vty, "%sVRF %s:%s", VTY_NEWLINE, zvrf_name (zvrf), VTY_NEWLINE);
1212 zebra_print_rnh_table(zvrf_id (zvrf), AF_INET, vty, RNH_NEXTHOP_TYPE);
1213 }
1214
1215 return CMD_SUCCESS;
1216 }
1217
1218 DEFUN (show_ipv6_nht,
1219 show_ipv6_nht_cmd,
1220 "show ipv6 nht [vrf NAME]",
1221 SHOW_STR
1222 IPV6_STR
1223 "IPv6 nexthop tracking table\n"
1224 VRF_CMD_HELP_STR)
1225 {
1226 int idx_vrf = 4;
1227 vrf_id_t vrf_id = VRF_DEFAULT;
1228
1229 if (argc == 5)
1230 VRF_GET_ID (vrf_id, argv[idx_vrf]->arg);
1231
1232 zebra_print_rnh_table(vrf_id, AF_INET6, vty, RNH_NEXTHOP_TYPE);
1233 return CMD_SUCCESS;
1234 }
1235
1236
1237 DEFUN (show_ipv6_nht_vrf_all,
1238 show_ipv6_nht_vrf_all_cmd,
1239 "show ipv6 nht vrf all",
1240 SHOW_STR
1241 IP_STR
1242 "IPv6 nexthop tracking table\n"
1243 VRF_ALL_CMD_HELP_STR)
1244 {
1245 struct vrf *vrf;
1246 struct zebra_vrf *zvrf;
1247
1248 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
1249 if ((zvrf = vrf->info) != NULL)
1250 {
1251 vty_out (vty, "%sVRF %s:%s", VTY_NEWLINE, zvrf_name (zvrf), VTY_NEWLINE);
1252 zebra_print_rnh_table(zvrf_id (zvrf), AF_INET6, vty, RNH_NEXTHOP_TYPE);
1253 }
1254
1255 return CMD_SUCCESS;
1256 }
1257
1258 DEFUN (ip_nht_default_route,
1259 ip_nht_default_route_cmd,
1260 "ip nht resolve-via-default",
1261 IP_STR
1262 "Filter Next Hop tracking route resolution\n"
1263 "Resolve via default route\n")
1264 {
1265 if (zebra_rnh_ip_default_route)
1266 return CMD_SUCCESS;
1267
1268 zebra_rnh_ip_default_route = 1;
1269 zebra_evaluate_rnh(0, AF_INET, 1, RNH_NEXTHOP_TYPE, NULL);
1270 return CMD_SUCCESS;
1271 }
1272
1273 DEFUN (no_ip_nht_default_route,
1274 no_ip_nht_default_route_cmd,
1275 "no ip nht resolve-via-default",
1276 NO_STR
1277 IP_STR
1278 "Filter Next Hop tracking route resolution\n"
1279 "Resolve via default route\n")
1280 {
1281 if (!zebra_rnh_ip_default_route)
1282 return CMD_SUCCESS;
1283
1284 zebra_rnh_ip_default_route = 0;
1285 zebra_evaluate_rnh(0, AF_INET, 1, RNH_NEXTHOP_TYPE, NULL);
1286 return CMD_SUCCESS;
1287 }
1288
1289 DEFUN (ipv6_nht_default_route,
1290 ipv6_nht_default_route_cmd,
1291 "ipv6 nht resolve-via-default",
1292 IP6_STR
1293 "Filter Next Hop tracking route resolution\n"
1294 "Resolve via default route\n")
1295 {
1296 if (zebra_rnh_ipv6_default_route)
1297 return CMD_SUCCESS;
1298
1299 zebra_rnh_ipv6_default_route = 1;
1300 zebra_evaluate_rnh(0, AF_INET6, 1, RNH_NEXTHOP_TYPE, NULL);
1301 return CMD_SUCCESS;
1302 }
1303
1304 DEFUN (no_ipv6_nht_default_route,
1305 no_ipv6_nht_default_route_cmd,
1306 "no ipv6 nht resolve-via-default",
1307 NO_STR
1308 IP6_STR
1309 "Filter Next Hop tracking route resolution\n"
1310 "Resolve via default route\n")
1311 {
1312 if (!zebra_rnh_ipv6_default_route)
1313 return CMD_SUCCESS;
1314
1315 zebra_rnh_ipv6_default_route = 0;
1316 zebra_evaluate_rnh(0, AF_INET6, 1, RNH_NEXTHOP_TYPE, NULL);
1317 return CMD_SUCCESS;
1318 }
1319
1320 DEFUN (show_ip_route_tag,
1321 show_ip_route_tag_cmd,
1322 "show ip route [vrf NAME] tag (1-4294967295)",
1323 SHOW_STR
1324 IP_STR
1325 "IP routing table\n"
1326 VRF_CMD_HELP_STR
1327 "Show only routes with tag\n"
1328 "Tag value\n")
1329 {
1330 int idx_vrf = 3;
1331 int idx_name = 4;
1332 int idx_tag = 6;
1333 struct route_table *table;
1334 struct route_node *rn;
1335 struct rib *rib;
1336 int first = 1;
1337 route_tag_t tag = 0;
1338 vrf_id_t vrf_id = VRF_DEFAULT;
1339
1340 if (strmatch(argv[idx_vrf]->text, "vrf"))
1341 {
1342 VRF_GET_ID (vrf_id, argv[idx_name]->arg);
1343 VTY_GET_INTEGER_RANGE("tag", tag, argv[idx_tag]->arg, 0, 4294967295);
1344 }
1345 else
1346 {
1347 idx_tag -= 2;
1348 VTY_GET_INTEGER_RANGE("tag", tag, argv[idx_tag]->arg, 0, 4294967295);
1349 }
1350
1351 table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
1352 if (! table)
1353 return CMD_SUCCESS;
1354
1355 /* Show all IPv4 routes with matching tag value. */
1356 for (rn = route_top (table); rn; rn = route_next (rn))
1357 RNODE_FOREACH_RIB (rn, rib)
1358 {
1359 if (rib->tag != tag)
1360 continue;
1361
1362 if (first)
1363 {
1364 vty_out (vty, SHOW_ROUTE_V4_HEADER);
1365 first = 0;
1366 }
1367 vty_show_ip_route (vty, rn, rib, NULL);
1368 }
1369 return CMD_SUCCESS;
1370 }
1371
1372 DEFUN (show_ip_route_prefix_longer,
1373 show_ip_route_prefix_longer_cmd,
1374 "show ip route [vrf NAME] A.B.C.D/M longer-prefixes",
1375 SHOW_STR
1376 IP_STR
1377 "IP routing table\n"
1378 VRF_CMD_HELP_STR
1379 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1380 "Show route matching the specified Network/Mask pair only\n")
1381 {
1382 struct route_table *table;
1383 struct route_node *rn;
1384 struct rib *rib;
1385 struct prefix p;
1386 int ret;
1387 int first = 1;
1388 vrf_id_t vrf_id = VRF_DEFAULT;
1389
1390 if (strmatch(argv[3]->text, "vrf"))
1391 {
1392 VRF_GET_ID (vrf_id, argv[4]->arg);
1393 ret = str2prefix (argv[5]->arg, &p);
1394 }
1395 else
1396 {
1397 ret = str2prefix (argv[3]->arg, &p);
1398 }
1399
1400 if (! ret)
1401 {
1402 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
1403 return CMD_WARNING;
1404 }
1405
1406 table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
1407 if (! table)
1408 return CMD_SUCCESS;
1409
1410 /* Show matched type IPv4 routes. */
1411 for (rn = route_top (table); rn; rn = route_next (rn))
1412 RNODE_FOREACH_RIB (rn, rib)
1413 if (prefix_match (&p, &rn->p))
1414 {
1415 if (first)
1416 {
1417 vty_out (vty, SHOW_ROUTE_V4_HEADER);
1418 first = 0;
1419 }
1420 vty_show_ip_route (vty, rn, rib, NULL);
1421 }
1422 return CMD_SUCCESS;
1423 }
1424
1425 DEFUN (show_ip_route_supernets,
1426 show_ip_route_supernets_cmd,
1427 "show ip route [vrf NAME] supernets-only",
1428 SHOW_STR
1429 IP_STR
1430 "IP routing table\n"
1431 VRF_CMD_HELP_STR
1432 "Show supernet entries only\n")
1433 {
1434 struct route_table *table;
1435 struct route_node *rn;
1436 struct rib *rib;
1437 u_int32_t addr;
1438 int first = 1;
1439 vrf_id_t vrf_id = VRF_DEFAULT;
1440
1441 if (strmatch(argv[3]->text, "vrf"))
1442 VRF_GET_ID (vrf_id, argv[4]->arg);
1443
1444 table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
1445 if (! table)
1446 return CMD_SUCCESS;
1447
1448 /* Show matched type IPv4 routes. */
1449 for (rn = route_top (table); rn; rn = route_next (rn))
1450 RNODE_FOREACH_RIB (rn, rib)
1451 {
1452 addr = ntohl (rn->p.u.prefix4.s_addr);
1453
1454 if ((IN_CLASSC (addr) && rn->p.prefixlen < 24)
1455 || (IN_CLASSB (addr) && rn->p.prefixlen < 16)
1456 || (IN_CLASSA (addr) && rn->p.prefixlen < 8))
1457 {
1458 if (first)
1459 {
1460 vty_out (vty, SHOW_ROUTE_V4_HEADER);
1461 first = 0;
1462 }
1463 vty_show_ip_route (vty, rn, rib, NULL);
1464 }
1465 }
1466 return CMD_SUCCESS;
1467 }
1468
1469 DEFUN (show_ip_route_protocol,
1470 show_ip_route_protocol_cmd,
1471 "show ip route [vrf NAME] <kernel|connected|static|rip|ospf|isis|bgp|pim|table>",
1472 SHOW_STR
1473 IP_STR
1474 "IP routing table\n"
1475 VRF_CMD_HELP_STR
1476 FRR_IP_REDIST_HELP_STR_ZEBRA)
1477 {
1478 int type;
1479 struct route_table *table;
1480 struct route_node *rn;
1481 struct rib *rib;
1482 int first = 1;
1483 vrf_id_t vrf_id = VRF_DEFAULT;
1484
1485 int idx = 0;
1486 if (argv_find (argv, argc, "NAME", &idx))
1487 VRF_GET_ID (vrf_id, argv[idx]->arg);
1488
1489 char *proto = argv[argc - 1]->text;
1490 type = proto_redistnum (AFI_IP, proto);
1491
1492 if (type < 0)
1493 {
1494 vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
1495 return CMD_WARNING;
1496 }
1497
1498 table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
1499 if (! table)
1500 return CMD_SUCCESS;
1501
1502 /* Show matched type IPv4 routes. */
1503 for (rn = route_top (table); rn; rn = route_next (rn))
1504 RNODE_FOREACH_RIB (rn, rib)
1505 if (rib->type == type)
1506 {
1507 if (first)
1508 {
1509 vty_out (vty, SHOW_ROUTE_V4_HEADER);
1510 first = 0;
1511 }
1512 vty_show_ip_route (vty, rn, rib, NULL);
1513 }
1514 return CMD_SUCCESS;
1515 }
1516
1517
1518 DEFUN (show_ip_route_ospf_instance,
1519 show_ip_route_ospf_instance_cmd,
1520 "show ip route ospf (1-65535)",
1521 SHOW_STR
1522 IP_STR
1523 "IP routing table\n"
1524 "Open Shortest Path First (OSPFv2)\n"
1525 "Instance ID\n")
1526 {
1527 int idx_number = 4;
1528 struct route_table *table;
1529 struct route_node *rn;
1530 struct rib *rib;
1531 int first = 1;
1532 u_short instance = 0;
1533
1534 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
1535
1536 table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
1537 if (! table)
1538 return CMD_SUCCESS;
1539
1540 /* Show matched type IPv4 routes. */
1541 for (rn = route_top (table); rn; rn = route_next (rn))
1542 RNODE_FOREACH_RIB (rn, rib)
1543 if (rib->type == ZEBRA_ROUTE_OSPF && rib->instance == instance)
1544 {
1545 if (first)
1546 {
1547 vty_out (vty, SHOW_ROUTE_V4_HEADER);
1548 first = 0;
1549 }
1550 vty_show_ip_route (vty, rn, rib, NULL);
1551 }
1552 return CMD_SUCCESS;
1553 }
1554
1555 DEFUN (show_ip_route_addr,
1556 show_ip_route_addr_cmd,
1557 "show ip route [vrf NAME] A.B.C.D",
1558 SHOW_STR
1559 IP_STR
1560 "IP routing table\n"
1561 VRF_CMD_HELP_STR
1562 "Network in the IP routing table to display\n")
1563 {
1564 int ret;
1565 struct prefix_ipv4 p;
1566 struct route_table *table;
1567 struct route_node *rn;
1568 vrf_id_t vrf_id = VRF_DEFAULT;
1569
1570 if (strmatch(argv[3]->text, "vrf"))
1571 {
1572 VRF_GET_ID (vrf_id, argv[4]->arg);
1573 ret = str2prefix_ipv4 (argv[5]->arg, &p);
1574 }
1575 else
1576 {
1577 ret = str2prefix_ipv4 (argv[3]->arg, &p);
1578 }
1579
1580 if (ret <= 0)
1581 {
1582 vty_out (vty, "%% Malformed IPv4 address%s", VTY_NEWLINE);
1583 return CMD_WARNING;
1584 }
1585
1586 table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
1587 if (! table)
1588 return CMD_SUCCESS;
1589
1590 rn = route_node_match (table, (struct prefix *) &p);
1591 if (! rn)
1592 {
1593 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
1594 return CMD_WARNING;
1595 }
1596
1597 vty_show_ip_route_detail (vty, rn, 0);
1598
1599 route_unlock_node (rn);
1600
1601 return CMD_SUCCESS;
1602 }
1603
1604 DEFUN (show_ip_route_prefix,
1605 show_ip_route_prefix_cmd,
1606 "show ip route [vrf NAME] A.B.C.D/M",
1607 SHOW_STR
1608 IP_STR
1609 "IP routing table\n"
1610 VRF_CMD_HELP_STR
1611 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
1612 {
1613 int ret;
1614 struct prefix_ipv4 p;
1615 struct route_table *table;
1616 struct route_node *rn;
1617 vrf_id_t vrf_id = VRF_DEFAULT;
1618
1619 if (strmatch(argv[3]->text, "vrf"))
1620 {
1621 VRF_GET_ID (vrf_id, argv[4]->arg);
1622 ret = str2prefix_ipv4 (argv[5]->arg, &p);
1623 }
1624 else
1625 {
1626 ret = str2prefix_ipv4 (argv[3]->arg, &p);
1627 }
1628
1629 if (ret <= 0)
1630 {
1631 vty_out (vty, "%% Malformed IPv4 address%s", VTY_NEWLINE);
1632 return CMD_WARNING;
1633 }
1634
1635 table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
1636 if (! table)
1637 return CMD_SUCCESS;
1638
1639 rn = route_node_match (table, (struct prefix *) &p);
1640 if (! rn || rn->p.prefixlen != p.prefixlen)
1641 {
1642 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
1643 return CMD_WARNING;
1644 }
1645
1646 vty_show_ip_route_detail (vty, rn, 0);
1647
1648 route_unlock_node (rn);
1649
1650 return CMD_SUCCESS;
1651 }
1652
1653
1654 static void
1655 vty_show_ip_route_summary (struct vty *vty, struct route_table *table)
1656 {
1657 struct route_node *rn;
1658 struct rib *rib;
1659 #define ZEBRA_ROUTE_IBGP ZEBRA_ROUTE_MAX
1660 #define ZEBRA_ROUTE_TOTAL (ZEBRA_ROUTE_IBGP + 1)
1661 u_int32_t rib_cnt[ZEBRA_ROUTE_TOTAL + 1];
1662 u_int32_t fib_cnt[ZEBRA_ROUTE_TOTAL + 1];
1663 u_int32_t i;
1664 u_int32_t is_ibgp;
1665
1666 memset (&rib_cnt, 0, sizeof(rib_cnt));
1667 memset (&fib_cnt, 0, sizeof(fib_cnt));
1668 for (rn = route_top (table); rn; rn = route_next (rn))
1669 RNODE_FOREACH_RIB (rn, rib)
1670 {
1671 is_ibgp = (rib->type == ZEBRA_ROUTE_BGP &&
1672 CHECK_FLAG (rib->flags, ZEBRA_FLAG_IBGP));
1673
1674 rib_cnt[ZEBRA_ROUTE_TOTAL]++;
1675 if (is_ibgp)
1676 rib_cnt[ZEBRA_ROUTE_IBGP]++;
1677 else
1678 rib_cnt[rib->type]++;
1679
1680 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
1681 {
1682 fib_cnt[ZEBRA_ROUTE_TOTAL]++;
1683
1684 if (is_ibgp)
1685 fib_cnt[ZEBRA_ROUTE_IBGP]++;
1686 else
1687 fib_cnt[rib->type]++;
1688 }
1689 }
1690
1691 vty_out (vty, "%-20s %-20s %s (vrf %s)%s",
1692 "Route Source", "Routes", "FIB",
1693 zvrf_name (((rib_table_info_t *)table->info)->zvrf),
1694 VTY_NEWLINE);
1695
1696 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
1697 {
1698 if ((rib_cnt[i] > 0) ||
1699 (i == ZEBRA_ROUTE_BGP && rib_cnt[ZEBRA_ROUTE_IBGP] > 0))
1700 {
1701 if (i == ZEBRA_ROUTE_BGP)
1702 {
1703 vty_out (vty, "%-20s %-20d %-20d %s", "ebgp",
1704 rib_cnt[ZEBRA_ROUTE_BGP], fib_cnt[ZEBRA_ROUTE_BGP],
1705 VTY_NEWLINE);
1706 vty_out (vty, "%-20s %-20d %-20d %s", "ibgp",
1707 rib_cnt[ZEBRA_ROUTE_IBGP], fib_cnt[ZEBRA_ROUTE_IBGP],
1708 VTY_NEWLINE);
1709 }
1710 else
1711 vty_out (vty, "%-20s %-20d %-20d %s", zebra_route_string(i),
1712 rib_cnt[i], fib_cnt[i], VTY_NEWLINE);
1713 }
1714 }
1715
1716 vty_out (vty, "------%s", VTY_NEWLINE);
1717 vty_out (vty, "%-20s %-20d %-20d %s", "Totals", rib_cnt[ZEBRA_ROUTE_TOTAL],
1718 fib_cnt[ZEBRA_ROUTE_TOTAL], VTY_NEWLINE);
1719 vty_out (vty, "%s", VTY_NEWLINE);
1720 }
1721
1722 /*
1723 * Implementation of the ip route summary prefix command.
1724 *
1725 * This command prints the primary prefixes that have been installed by various
1726 * protocols on the box.
1727 *
1728 */
1729 static void
1730 vty_show_ip_route_summary_prefix (struct vty *vty, struct route_table *table)
1731 {
1732 struct route_node *rn;
1733 struct rib *rib;
1734 struct nexthop *nexthop;
1735 #define ZEBRA_ROUTE_IBGP ZEBRA_ROUTE_MAX
1736 #define ZEBRA_ROUTE_TOTAL (ZEBRA_ROUTE_IBGP + 1)
1737 u_int32_t rib_cnt[ZEBRA_ROUTE_TOTAL + 1];
1738 u_int32_t fib_cnt[ZEBRA_ROUTE_TOTAL + 1];
1739 u_int32_t i;
1740 int cnt;
1741
1742 memset (&rib_cnt, 0, sizeof(rib_cnt));
1743 memset (&fib_cnt, 0, sizeof(fib_cnt));
1744 for (rn = route_top (table); rn; rn = route_next (rn))
1745 RNODE_FOREACH_RIB (rn, rib)
1746 {
1747
1748 /*
1749 * In case of ECMP, count only once.
1750 */
1751 cnt = 0;
1752 for (nexthop = rib->nexthop; (!cnt && nexthop); nexthop = nexthop->next)
1753 {
1754 cnt++;
1755 rib_cnt[ZEBRA_ROUTE_TOTAL]++;
1756 rib_cnt[rib->type]++;
1757 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB))
1758 {
1759 fib_cnt[ZEBRA_ROUTE_TOTAL]++;
1760 fib_cnt[rib->type]++;
1761 }
1762 if (rib->type == ZEBRA_ROUTE_BGP &&
1763 CHECK_FLAG (rib->flags, ZEBRA_FLAG_IBGP))
1764 {
1765 rib_cnt[ZEBRA_ROUTE_IBGP]++;
1766 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB))
1767 fib_cnt[ZEBRA_ROUTE_IBGP]++;
1768 }
1769 }
1770 }
1771
1772 vty_out (vty, "%-20s %-20s %s (vrf %s)%s",
1773 "Route Source", "Prefix Routes", "FIB",
1774 zvrf_name (((rib_table_info_t *)table->info)->zvrf),
1775 VTY_NEWLINE);
1776
1777 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
1778 {
1779 if (rib_cnt[i] > 0)
1780 {
1781 if (i == ZEBRA_ROUTE_BGP)
1782 {
1783 vty_out (vty, "%-20s %-20d %-20d %s", "ebgp",
1784 rib_cnt[ZEBRA_ROUTE_BGP] - rib_cnt[ZEBRA_ROUTE_IBGP],
1785 fib_cnt[ZEBRA_ROUTE_BGP] - fib_cnt[ZEBRA_ROUTE_IBGP],
1786 VTY_NEWLINE);
1787 vty_out (vty, "%-20s %-20d %-20d %s", "ibgp",
1788 rib_cnt[ZEBRA_ROUTE_IBGP], fib_cnt[ZEBRA_ROUTE_IBGP],
1789 VTY_NEWLINE);
1790 }
1791 else
1792 vty_out (vty, "%-20s %-20d %-20d %s", zebra_route_string(i),
1793 rib_cnt[i], fib_cnt[i], VTY_NEWLINE);
1794 }
1795 }
1796
1797 vty_out (vty, "------%s", VTY_NEWLINE);
1798 vty_out (vty, "%-20s %-20d %-20d %s", "Totals", rib_cnt[ZEBRA_ROUTE_TOTAL],
1799 fib_cnt[ZEBRA_ROUTE_TOTAL], VTY_NEWLINE);
1800 vty_out (vty, "%s", VTY_NEWLINE);
1801 }
1802
1803 /* Show route summary. */
1804 DEFUN (show_ip_route_summary,
1805 show_ip_route_summary_cmd,
1806 "show ip route [vrf NAME] summary",
1807 SHOW_STR
1808 IP_STR
1809 "IP routing table\n"
1810 VRF_CMD_HELP_STR
1811 "Summary of all routes\n")
1812 {
1813 struct route_table *table;
1814 vrf_id_t vrf_id = VRF_DEFAULT;
1815
1816 if (strmatch(argv[3]->text, "vrf"))
1817 VRF_GET_ID (vrf_id, argv[4]->arg);
1818
1819 table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
1820 if (! table)
1821 return CMD_SUCCESS;
1822
1823 vty_show_ip_route_summary (vty, table);
1824
1825 return CMD_SUCCESS;
1826 }
1827
1828 /* Show route summary prefix. */
1829 DEFUN (show_ip_route_summary_prefix,
1830 show_ip_route_summary_prefix_cmd,
1831 "show ip route [vrf NAME] summary prefix",
1832 SHOW_STR
1833 IP_STR
1834 "IP routing table\n"
1835 VRF_CMD_HELP_STR
1836 "Summary of all routes\n"
1837 "Prefix routes\n")
1838 {
1839 struct route_table *table;
1840 vrf_id_t vrf_id = VRF_DEFAULT;
1841
1842 if (strmatch(argv[3]->text, "vrf"))
1843 VRF_GET_ID (vrf_id, argv[4]->arg);
1844
1845 table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
1846 if (! table)
1847 return CMD_SUCCESS;
1848
1849 vty_show_ip_route_summary_prefix (vty, table);
1850
1851 return CMD_SUCCESS;
1852 }
1853
1854
1855 DEFUN (show_ip_route_vrf_all,
1856 show_ip_route_vrf_all_cmd,
1857 "show ip route vrf all",
1858 SHOW_STR
1859 IP_STR
1860 "IP routing table\n"
1861 VRF_ALL_CMD_HELP_STR)
1862 {
1863 struct route_table *table;
1864 struct route_node *rn;
1865 struct rib *rib;
1866 struct vrf *vrf;
1867 struct zebra_vrf *zvrf;
1868 int first = 1;
1869 int vrf_header = 1;
1870
1871 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
1872 {
1873 if ((zvrf = vrf->info) == NULL ||
1874 (table = zvrf->table[AFI_IP][SAFI_UNICAST]) == NULL)
1875 continue;
1876
1877 /* Show all IPv4 routes. */
1878 for (rn = route_top (table); rn; rn = route_next (rn))
1879 RNODE_FOREACH_RIB (rn, rib)
1880 {
1881 if (first)
1882 {
1883 vty_out (vty, SHOW_ROUTE_V4_HEADER);
1884 first = 0;
1885 }
1886
1887 if (vrf_header)
1888 {
1889 vty_out (vty, "%sVRF %s:%s", VTY_NEWLINE, zvrf_name (zvrf), VTY_NEWLINE);
1890 vrf_header = 0;
1891 }
1892 vty_show_ip_route (vty, rn, rib, NULL);
1893 }
1894 vrf_header = 1;
1895 }
1896
1897 return CMD_SUCCESS;
1898 }
1899
1900 DEFUN (show_ip_route_vrf_all_tag,
1901 show_ip_route_vrf_all_tag_cmd,
1902 "show ip route vrf all tag (1-4294967295)",
1903 SHOW_STR
1904 IP_STR
1905 "IP routing table\n"
1906 VRF_ALL_CMD_HELP_STR
1907 "Show only routes with tag\n"
1908 "Tag value\n")
1909 {
1910 int idx_number = 6;
1911 struct route_table *table;
1912 struct route_node *rn;
1913 struct rib *rib;
1914 struct vrf *vrf;
1915 struct zebra_vrf *zvrf;
1916 int first = 1;
1917 int vrf_header = 1;
1918 route_tag_t tag = 0;
1919
1920 if (argv[idx_number]->arg)
1921 VTY_GET_INTEGER_RANGE("tag", tag, argv[idx_number]->arg, 0, 4294967295);
1922
1923 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
1924 {
1925 if ((zvrf = vrf->info) == NULL ||
1926 (table = zvrf->table[AFI_IP][SAFI_UNICAST]) == NULL)
1927 continue;
1928
1929 /* Show all IPv4 routes with matching tag value. */
1930 for (rn = route_top (table); rn; rn = route_next (rn))
1931 RNODE_FOREACH_RIB (rn, rib)
1932 {
1933 if (rib->tag != tag)
1934 continue;
1935
1936 if (first)
1937 {
1938 vty_out (vty, SHOW_ROUTE_V4_HEADER);
1939 first = 0;
1940 }
1941
1942 if (vrf_header)
1943 {
1944 vty_out (vty, "%sVRF %s:%s", VTY_NEWLINE, zvrf_name (zvrf), VTY_NEWLINE);
1945 vrf_header = 0;
1946 }
1947 vty_show_ip_route (vty, rn, rib, NULL);
1948 }
1949 vrf_header = 1;
1950 }
1951 return CMD_SUCCESS;
1952 }
1953
1954 DEFUN (show_ip_route_vrf_all_prefix_longer,
1955 show_ip_route_vrf_all_prefix_longer_cmd,
1956 "show ip route vrf all A.B.C.D/M longer-prefixes",
1957 SHOW_STR
1958 IP_STR
1959 "IP routing table\n"
1960 VRF_ALL_CMD_HELP_STR
1961 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1962 "Show route matching the specified Network/Mask pair only\n")
1963 {
1964 int idx_ipv4_prefixlen = 5;
1965 struct route_table *table;
1966 struct route_node *rn;
1967 struct rib *rib;
1968 struct prefix p;
1969 struct vrf *vrf;
1970 struct zebra_vrf *zvrf;
1971 int ret;
1972 int first = 1;
1973 int vrf_header = 1;
1974
1975 ret = str2prefix (argv[idx_ipv4_prefixlen]->arg, &p);
1976 if (! ret)
1977 {
1978 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
1979 return CMD_WARNING;
1980 }
1981
1982 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
1983 {
1984 if ((zvrf = vrf->info) == NULL ||
1985 (table = zvrf->table[AFI_IP][SAFI_UNICAST]) == NULL)
1986 continue;
1987
1988 /* Show matched type IPv4 routes. */
1989 for (rn = route_top (table); rn; rn = route_next (rn))
1990 RNODE_FOREACH_RIB (rn, rib)
1991 if (prefix_match (&p, &rn->p))
1992 {
1993 if (first)
1994 {
1995 vty_out (vty, SHOW_ROUTE_V4_HEADER);
1996 first = 0;
1997 }
1998
1999 if (vrf_header)
2000 {
2001 vty_out (vty, "%sVRF %s:%s", VTY_NEWLINE, zvrf_name (zvrf), VTY_NEWLINE);
2002 vrf_header = 0;
2003 }
2004 vty_show_ip_route (vty, rn, rib, NULL);
2005 }
2006 vrf_header = 1;
2007 }
2008
2009 return CMD_SUCCESS;
2010 }
2011
2012 DEFUN (show_ip_route_vrf_all_supernets,
2013 show_ip_route_vrf_all_supernets_cmd,
2014 "show ip route vrf all supernets-only",
2015 SHOW_STR
2016 IP_STR
2017 "IP routing table\n"
2018 VRF_ALL_CMD_HELP_STR
2019 "Show supernet entries only\n")
2020 {
2021 struct route_table *table;
2022 struct route_node *rn;
2023 struct rib *rib;
2024 struct vrf *vrf;
2025 struct zebra_vrf *zvrf;
2026 u_int32_t addr;
2027 int first = 1;
2028 int vrf_header = 1;
2029
2030 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
2031 {
2032 if ((zvrf = vrf->info) == NULL ||
2033 (table = zvrf->table[AFI_IP][SAFI_UNICAST]) == NULL)
2034 continue;
2035
2036 /* Show matched type IPv4 routes. */
2037 for (rn = route_top (table); rn; rn = route_next (rn))
2038 RNODE_FOREACH_RIB (rn, rib)
2039 {
2040 addr = ntohl (rn->p.u.prefix4.s_addr);
2041
2042 if ((IN_CLASSC (addr) && rn->p.prefixlen < 24)
2043 || (IN_CLASSB (addr) && rn->p.prefixlen < 16)
2044 || (IN_CLASSA (addr) && rn->p.prefixlen < 8))
2045 {
2046 if (first)
2047 {
2048 vty_out (vty, SHOW_ROUTE_V4_HEADER);
2049 first = 0;
2050 }
2051 if (vrf_header)
2052 {
2053 vty_out (vty, "%sVRF %s:%s", VTY_NEWLINE, zvrf_name (zvrf), VTY_NEWLINE);
2054 vrf_header = 0;
2055 }
2056 vty_show_ip_route (vty, rn, rib, NULL);
2057 }
2058 }
2059 vrf_header = 1;
2060 }
2061
2062 return CMD_SUCCESS;
2063 }
2064
2065 DEFUN (show_ip_route_vrf_all_protocol,
2066 show_ip_route_vrf_all_protocol_cmd,
2067 "show ip route vrf all <kernel|connected|static|rip|ospf|isis|bgp|pim|table>",
2068 SHOW_STR
2069 IP_STR
2070 "IP routing table\n"
2071 VRF_ALL_CMD_HELP_STR
2072 FRR_IP_REDIST_HELP_STR_ZEBRA"\n")
2073 {
2074 int type;
2075 struct route_table *table;
2076 struct route_node *rn;
2077 struct rib *rib;
2078 struct vrf *vrf;
2079 struct zebra_vrf *zvrf;
2080 int first = 1;
2081 int vrf_header = 1;
2082
2083 char *proto = argv[argc - 1]->text;
2084 type = proto_redistnum (AFI_IP, proto);
2085
2086 if (type < 0)
2087 {
2088 vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
2089 return CMD_WARNING;
2090 }
2091
2092 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
2093 {
2094 if ((zvrf = vrf->info) == NULL ||
2095 (table = zvrf->table[AFI_IP][SAFI_UNICAST]) == NULL)
2096 continue;
2097
2098 /* Show matched type IPv4 routes. */
2099 for (rn = route_top (table); rn; rn = route_next (rn))
2100 RNODE_FOREACH_RIB (rn, rib)
2101 if (rib->type == type)
2102 {
2103 if (first)
2104 {
2105 vty_out (vty, SHOW_ROUTE_V4_HEADER);
2106 first = 0;
2107 }
2108
2109 if (vrf_header)
2110 {
2111 vty_out (vty, "%sVRF %s:%s", VTY_NEWLINE, zvrf_name (zvrf), VTY_NEWLINE);
2112 vrf_header = 0;
2113 }
2114 vty_show_ip_route (vty, rn, rib, NULL);
2115 }
2116 vrf_header = 1;
2117 }
2118
2119 return CMD_SUCCESS;
2120 }
2121
2122 DEFUN (show_ip_route_vrf_all_addr,
2123 show_ip_route_vrf_all_addr_cmd,
2124 "show ip route vrf all A.B.C.D",
2125 SHOW_STR
2126 IP_STR
2127 "IP routing table\n"
2128 VRF_ALL_CMD_HELP_STR
2129 "Network in the IP routing table to display\n")
2130 {
2131 int idx_ipv4 = 5;
2132 int ret;
2133 struct prefix_ipv4 p;
2134 struct route_table *table;
2135 struct route_node *rn;
2136 struct vrf *vrf;
2137 struct zebra_vrf *zvrf;
2138
2139 ret = str2prefix_ipv4 (argv[idx_ipv4]->arg, &p);
2140 if (ret <= 0)
2141 {
2142 vty_out (vty, "%% Malformed IPv4 address%s", VTY_NEWLINE);
2143 return CMD_WARNING;
2144 }
2145
2146 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
2147 {
2148 if ((zvrf = vrf->info) == NULL ||
2149 (table = zvrf->table[AFI_IP][SAFI_UNICAST]) == NULL)
2150 continue;
2151
2152 rn = route_node_match (table, (struct prefix *) &p);
2153 if (! rn)
2154 continue;
2155
2156 vty_show_ip_route_detail (vty, rn, 0);
2157
2158 route_unlock_node (rn);
2159 }
2160
2161 return CMD_SUCCESS;
2162 }
2163
2164 DEFUN (show_ip_route_vrf_all_prefix,
2165 show_ip_route_vrf_all_prefix_cmd,
2166 "show ip route vrf all A.B.C.D/M",
2167 SHOW_STR
2168 IP_STR
2169 "IP routing table\n"
2170 VRF_ALL_CMD_HELP_STR
2171 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
2172 {
2173 int idx_ipv4_prefixlen = 5;
2174 int ret;
2175 struct prefix_ipv4 p;
2176 struct route_table *table;
2177 struct route_node *rn;
2178 struct vrf *vrf;
2179 struct zebra_vrf *zvrf;
2180
2181 ret = str2prefix_ipv4 (argv[idx_ipv4_prefixlen]->arg, &p);
2182 if (ret <= 0)
2183 {
2184 vty_out (vty, "%% Malformed IPv4 address%s", VTY_NEWLINE);
2185 return CMD_WARNING;
2186 }
2187
2188 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
2189 {
2190 if ((zvrf = vrf->info) == NULL ||
2191 (table = zvrf->table[AFI_IP][SAFI_UNICAST]) == NULL)
2192 continue;
2193
2194 rn = route_node_match (table, (struct prefix *) &p);
2195 if (! rn)
2196 continue;
2197 if (rn->p.prefixlen != p.prefixlen)
2198 {
2199 route_unlock_node (rn);
2200 continue;
2201 }
2202
2203 vty_show_ip_route_detail (vty, rn, 0);
2204
2205 route_unlock_node (rn);
2206 }
2207
2208 return CMD_SUCCESS;
2209 }
2210
2211 DEFUN (show_ip_route_vrf_all_summary,
2212 show_ip_route_vrf_all_summary_cmd,
2213 "show ip route vrf all summary ",
2214 SHOW_STR
2215 IP_STR
2216 "IP routing table\n"
2217 VRF_ALL_CMD_HELP_STR
2218 "Summary of all routes\n")
2219 {
2220 struct vrf *vrf;
2221 struct zebra_vrf *zvrf;
2222
2223 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
2224 if ((zvrf = vrf->info) != NULL)
2225 vty_show_ip_route_summary (vty, zvrf->table[AFI_IP][SAFI_UNICAST]);
2226
2227 return CMD_SUCCESS;
2228 }
2229
2230 DEFUN (show_ip_route_vrf_all_summary_prefix,
2231 show_ip_route_vrf_all_summary_prefix_cmd,
2232 "show ip route vrf all summary prefix",
2233 SHOW_STR
2234 IP_STR
2235 "IP routing table\n"
2236 VRF_ALL_CMD_HELP_STR
2237 "Summary of all routes\n"
2238 "Prefix routes\n")
2239 {
2240 struct vrf *vrf;
2241 struct zebra_vrf *zvrf;
2242
2243 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
2244 if ((zvrf = vrf->info) != NULL)
2245 vty_show_ip_route_summary_prefix (vty, zvrf->table[AFI_IP][SAFI_UNICAST]);
2246
2247 return CMD_SUCCESS;
2248 }
2249
2250 /* Write IPv4 static route configuration. */
2251 static int
2252 static_config_ipv4 (struct vty *vty, safi_t safi, const char *cmd)
2253 {
2254 struct route_node *rn;
2255 struct static_route *si;
2256 struct route_table *stable;
2257 struct vrf *vrf;
2258 struct zebra_vrf *zvrf;
2259 char buf[BUFSIZ];
2260 int write =0;
2261
2262 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
2263 {
2264 if (!(zvrf = vrf->info))
2265 continue;
2266 if ((stable = zvrf->stable[AFI_IP][safi]) == NULL)
2267 continue;
2268
2269 for (rn = route_top (stable); rn; rn = route_next (rn))
2270 for (si = rn->info; si; si = si->next)
2271 {
2272 vty_out (vty, "%s %s", cmd, prefix2str (&rn->p, buf, sizeof buf));
2273
2274 switch (si->type)
2275 {
2276 case STATIC_IPV4_GATEWAY:
2277 vty_out (vty, " %s", inet_ntoa (si->addr.ipv4));
2278 break;
2279 case STATIC_IFINDEX:
2280 vty_out (vty, " %s", si->ifname);
2281 break;
2282 case STATIC_BLACKHOLE:
2283 vty_out (vty, " Null0");
2284 break;
2285 }
2286
2287 /* flags are incompatible with STATIC_BLACKHOLE */
2288 if (si->type != STATIC_BLACKHOLE)
2289 {
2290 if (CHECK_FLAG(si->flags, ZEBRA_FLAG_REJECT))
2291 vty_out (vty, " %s", "reject");
2292
2293 if (CHECK_FLAG(si->flags, ZEBRA_FLAG_BLACKHOLE))
2294 vty_out (vty, " %s", "blackhole");
2295 }
2296
2297 if (si->tag)
2298 vty_out (vty, " tag %"ROUTE_TAG_PRI, si->tag);
2299
2300 if (si->distance != ZEBRA_STATIC_DISTANCE_DEFAULT)
2301 vty_out (vty, " %d", si->distance);
2302
2303 if (si->vrf_id != VRF_DEFAULT)
2304 vty_out (vty, " vrf %s", zvrf ? zvrf_name (zvrf) : "");
2305
2306 /* Label information */
2307 if (si->snh_label.num_labels)
2308 vty_out (vty, " label %s",
2309 mpls_label2str (si->snh_label.num_labels,
2310 si->snh_label.label, buf, sizeof buf));
2311
2312 vty_out (vty, "%s", VTY_NEWLINE);
2313
2314 write = 1;
2315 }
2316 }
2317 return write;
2318 }
2319
2320 /* General fucntion for IPv6 static route. */
2321 int
2322 static_ipv6_func (struct vty *vty, int add_cmd, const char *dest_str,
2323 const char *gate_str, const char *ifname,
2324 const char *flag_str, const char *tag_str,
2325 const char *distance_str, const char *vrf_id_str,
2326 const char *label_str)
2327 {
2328 int ret;
2329 u_char distance;
2330 struct prefix p;
2331 struct in6_addr *gate = NULL;
2332 struct in6_addr gate_addr;
2333 u_char type = STATIC_BLACKHOLE;
2334 u_char flag = 0;
2335 route_tag_t tag = 0;
2336 unsigned int ifindex = 0;
2337 struct interface *ifp = NULL;
2338 struct zebra_vrf *zvrf;
2339 struct static_nh_label snh_label;
2340
2341 ret = str2prefix (dest_str, &p);
2342 if (ret <= 0)
2343 {
2344 vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
2345 return CMD_WARNING;
2346 }
2347
2348 /* Apply mask for given prefix. */
2349 apply_mask (&p);
2350
2351 /* Administrative distance. */
2352 if (distance_str)
2353 distance = atoi (distance_str);
2354 else
2355 distance = ZEBRA_STATIC_DISTANCE_DEFAULT;
2356
2357 /* tag */
2358 if (tag_str)
2359 VTY_GET_INTEGER_RANGE("tag", tag, tag_str, 0, 4294967295);
2360
2361 /* When gateway is valid IPv6 addrees, then gate is treated as
2362 nexthop address other case gate is treated as interface name. */
2363 ret = inet_pton (AF_INET6, gate_str, &gate_addr);
2364
2365 /* VRF id */
2366 zvrf = zebra_vrf_lookup_by_name (vrf_id_str);
2367
2368 if (!zvrf)
2369 {
2370 vty_out (vty, "%% vrf %s is not defined%s", vrf_id_str, VTY_NEWLINE);
2371 return CMD_WARNING;
2372 }
2373
2374 /* Labels */
2375 memset (&snh_label, 0, sizeof (struct static_nh_label));
2376 if (label_str)
2377 {
2378 if (!mpls_enabled)
2379 {
2380 vty_out (vty, "%% MPLS not turned on in kernel, ignoring command%s",
2381 VTY_NEWLINE);
2382 return CMD_WARNING;
2383 }
2384 if (mpls_str2label (label_str, &snh_label.num_labels,
2385 snh_label.label))
2386 {
2387 vty_out (vty, "%% Malformed label(s)%s", VTY_NEWLINE);
2388 return CMD_WARNING;
2389 }
2390 }
2391
2392 /* Null0 static route. */
2393 if ((gate_str != NULL) && (strncasecmp (gate_str, "Null0", strlen (gate_str)) == 0))
2394 {
2395 if (flag_str)
2396 {
2397 vty_out (vty, "%% can not have flag %s with Null0%s", flag_str, VTY_NEWLINE);
2398 return CMD_WARNING;
2399 }
2400 if (add_cmd)
2401 static_add_route (AFI_IP6, SAFI_UNICAST, type, &p, NULL, ifindex, ifname,
2402 ZEBRA_FLAG_BLACKHOLE, tag, distance, zvrf, &snh_label);
2403 else
2404 static_delete_route (AFI_IP6, SAFI_UNICAST, type, &p, NULL, ifindex, tag,
2405 distance, zvrf, &snh_label);
2406 return CMD_SUCCESS;
2407 }
2408
2409 /* Route flags */
2410 if (flag_str) {
2411 switch(flag_str[0]) {
2412 case 'r':
2413 case 'R': /* XXX */
2414 SET_FLAG (flag, ZEBRA_FLAG_REJECT);
2415 break;
2416 case 'b':
2417 case 'B': /* XXX */
2418 SET_FLAG (flag, ZEBRA_FLAG_BLACKHOLE);
2419 break;
2420 default:
2421 vty_out (vty, "%% Malformed flag %s %s", flag_str, VTY_NEWLINE);
2422 return CMD_WARNING;
2423 }
2424 }
2425
2426 if (ifname)
2427 {
2428 /* When ifname is specified. It must be come with gateway
2429 address. */
2430 if (ret != 1)
2431 {
2432 vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
2433 return CMD_WARNING;
2434 }
2435 type = STATIC_IPV6_GATEWAY_IFINDEX;
2436 gate = &gate_addr;
2437 ifp = if_lookup_by_name_vrf (ifname, zvrf_id (zvrf));
2438 if (!ifp)
2439 {
2440 vty_out (vty, "%% Malformed Interface name %s%s", ifname, VTY_NEWLINE);
2441 return CMD_WARNING;
2442 }
2443 ifindex = ifp->ifindex;
2444 }
2445 else
2446 {
2447 if (ret == 1)
2448 {
2449 type = STATIC_IPV6_GATEWAY;
2450 gate = &gate_addr;
2451 }
2452 else
2453 {
2454 type = STATIC_IFINDEX;
2455 ifp = if_lookup_by_name_vrf (gate_str, zvrf_id (zvrf));
2456 if (!ifp)
2457 {
2458 vty_out (vty, "%% Malformed Interface name %s%s", gate_str, VTY_NEWLINE);
2459 ifindex = IFINDEX_DELETED;
2460 }
2461 else
2462 ifindex = ifp->ifindex;
2463 ifname = gate_str;
2464 }
2465 }
2466
2467 if (add_cmd)
2468 static_add_route (AFI_IP6, SAFI_UNICAST, type, &p, (union g_addr *)gate,
2469 ifindex, ifname, flag, tag, distance, zvrf, &snh_label);
2470 else
2471 static_delete_route (AFI_IP6, SAFI_UNICAST, type, &p, (union g_addr *)gate,
2472 ifindex, tag, distance, zvrf, &snh_label);
2473
2474 return CMD_SUCCESS;
2475 }
2476
2477 DEFUN (ipv6_route,
2478 ipv6_route_cmd,
2479 "ipv6 route X:X::X:X/M <X:X::X:X|INTERFACE|null0> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
2480 IP_STR
2481 "Establish static routes\n"
2482 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
2483 "IPv6 gateway address\n"
2484 "IPv6 gateway interface name\n"
2485 "Null interface\n"
2486 "Null interface\n"
2487 "Set tag for this route\n"
2488 "Tag value\n"
2489 "Distance value for this prefix\n"
2490 VRF_CMD_HELP_STR
2491 "Specify labels for this route\n"
2492 "One or more labels separated by '/'\n")
2493 {
2494 int idx_ipv6_prefixlen = 2;
2495 int idx_ipv6_ifname = 3;
2496 int idx_curr = 4;
2497 char *tag, *distance, *vrf;
2498
2499 tag = distance = vrf = NULL;
2500 zebra_vty_ip_route_tdv_helper (argc, argv, idx_curr, &tag, &distance, &vrf, NULL);
2501
2502 return static_ipv6_func (vty, 1,
2503 argv[idx_ipv6_prefixlen]->arg,
2504 argv[idx_ipv6_ifname]->arg,
2505 NULL, NULL,
2506 tag, distance, vrf, NULL);
2507 }
2508
2509 DEFUN (ipv6_route_flags,
2510 ipv6_route_flags_cmd,
2511 "ipv6 route X:X::X:X/M <X:X::X:X|INTERFACE> <reject|blackhole> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
2512 IP_STR
2513 "Establish static routes\n"
2514 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
2515 "IPv6 gateway address\n"
2516 "IPv6 gateway interface name\n"
2517 "Emit an ICMP unreachable when matched\n"
2518 "Silently discard pkts when matched\n"
2519 "Silently discard pkts when matched\n"
2520 "Set tag for this route\n"
2521 "Tag value\n"
2522 "Distance value for this prefix\n"
2523 VRF_CMD_HELP_STR
2524 "Specify labels for this route\n"
2525 "One or more labels separated by '/'\n")
2526 {
2527 int idx_ipv6_prefixlen = 2;
2528 int idx_ipv6_ifname = 3;
2529 int idx_reject_blackhole = 4;
2530 int idx_curr = 5;
2531 char *tag, *distance, *vrf;
2532
2533 tag = distance = vrf = NULL;
2534 zebra_vty_ip_route_tdv_helper (argc, argv, idx_curr, &tag, &distance, &vrf, NULL);
2535
2536 return static_ipv6_func (vty, 1,
2537 argv[idx_ipv6_prefixlen]->arg,
2538 argv[idx_ipv6_ifname]->arg,
2539 NULL,
2540 argv[idx_reject_blackhole]->arg,
2541 tag, distance, vrf, NULL);
2542 }
2543
2544 DEFUN (ipv6_route_ifname,
2545 ipv6_route_ifname_cmd,
2546 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE [tag (1-4294967295)] [(1-255)] [vrf NAME]",
2547 IP_STR
2548 "Establish static routes\n"
2549 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
2550 "IPv6 gateway address\n"
2551 "IPv6 gateway interface name\n"
2552 "Set tag for this route\n"
2553 "Tag value\n"
2554 "Distance value for this prefix\n"
2555 VRF_CMD_HELP_STR
2556 "Specify labels for this route\n"
2557 "One or more labels separated by '/'\n")
2558 {
2559 int idx_ipv6_prefixlen = 2;
2560 int idx_ipv6 = 3;
2561 int idx_interface = 4;
2562 int idx_curr = 5;
2563 char *tag, *distance, *vrf;
2564
2565 tag = distance = vrf = NULL;
2566 zebra_vty_ip_route_tdv_helper (argc, argv, idx_curr, &tag, &distance, &vrf, NULL);
2567
2568 return static_ipv6_func (vty, 1,
2569 argv[idx_ipv6_prefixlen]->arg,
2570 argv[idx_ipv6]->arg,
2571 argv[idx_interface]->arg,
2572 NULL,
2573 tag, distance, vrf, NULL);
2574 }
2575
2576 DEFUN (ipv6_route_ifname_flags,
2577 ipv6_route_ifname_flags_cmd,
2578 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE <reject|blackhole> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
2579 IP_STR
2580 "Establish static routes\n"
2581 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
2582 "IPv6 gateway address\n"
2583 "IPv6 gateway interface name\n"
2584 "Emit an ICMP unreachable when matched\n"
2585 "Silently discard pkts when matched\n"
2586 "Set tag for this route\n"
2587 "Tag value\n"
2588 "Distance value for this prefix\n"
2589 VRF_CMD_HELP_STR
2590 "Specify labels for this route\n"
2591 "One or more labels separated by '/'\n")
2592 {
2593 int idx_ipv6_prefixlen = 2;
2594 int idx_ipv6 = 3;
2595 int idx_interface = 4;
2596 int idx_reject_blackhole = 5;
2597 int idx_curr = 6;
2598 char *tag, *distance, *vrf;
2599
2600 tag = distance = vrf = NULL;
2601 zebra_vty_ip_route_tdv_helper (argc, argv, idx_curr, &tag, &distance, &vrf, NULL);
2602
2603 return static_ipv6_func (vty, 1,
2604 argv[idx_ipv6_prefixlen]->arg,
2605 argv[idx_ipv6]->arg,
2606 argv[idx_interface]->arg,
2607 argv[idx_reject_blackhole]->arg,
2608 tag, distance, vrf, NULL);
2609 }
2610
2611 DEFUN (no_ipv6_route,
2612 no_ipv6_route_cmd,
2613 "no ipv6 route X:X::X:X/M <X:X::X:X|INTERFACE|null0> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
2614 NO_STR
2615 IP_STR
2616 "Establish static routes\n"
2617 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
2618 "IPv6 gateway address\n"
2619 "IPv6 gateway interface name\n"
2620 "Null interface\n"
2621 "Set tag for this route\n"
2622 "Tag value\n"
2623 "Distance value for this prefix\n"
2624 VRF_CMD_HELP_STR
2625 "Specify labels for this route\n"
2626 "One or more labels separated by '/'\n")
2627 {
2628 int idx_ipv6_prefixlen = 3;
2629 int idx_ipv6_ifname = 4;
2630 int idx_curr = 5;
2631 char *tag, *distance, *vrf;
2632
2633 tag = distance = vrf = NULL;
2634 zebra_vty_ip_route_tdv_helper (argc, argv, idx_curr, &tag, &distance, &vrf, NULL);
2635
2636 return static_ipv6_func (vty, 0,
2637 argv[idx_ipv6_prefixlen]->arg,
2638 argv[idx_ipv6_ifname]->arg,
2639 NULL, NULL,
2640 tag, distance, vrf, NULL);
2641 }
2642
2643 DEFUN (no_ipv6_route_flags,
2644 no_ipv6_route_flags_cmd,
2645 "no ipv6 route X:X::X:X/M <X:X::X:X|INTERFACE> <reject|blackhole> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
2646 NO_STR
2647 IP_STR
2648 "Establish static routes\n"
2649 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
2650 "IPv6 gateway address\n"
2651 "IPv6 gateway interface name\n"
2652 "Emit an ICMP unreachable when matched\n"
2653 "Silently discard pkts when matched\n"
2654 "Set tag for this route\n"
2655 "Tag value\n"
2656 "Distance value for this prefix\n"
2657 VRF_CMD_HELP_STR
2658 "Specify labels for this route\n"
2659 "One or more labels separated by '/'\n")
2660 {
2661 int idx_ipv6_prefixlen = 3;
2662 int idx_ipv6_ifname = 4;
2663 int idx_reject_blackhole = 5;
2664 int idx_curr = 6;
2665 char *tag, *distance, *vrf;
2666
2667 tag = distance = vrf = NULL;
2668 zebra_vty_ip_route_tdv_helper (argc, argv, idx_curr, &tag, &distance, &vrf, NULL);
2669
2670 return static_ipv6_func (vty, 0,
2671 argv[idx_ipv6_prefixlen]->arg,
2672 argv[idx_ipv6_ifname]->arg,
2673 NULL,
2674 argv[idx_reject_blackhole]->arg,
2675 tag, distance, vrf, NULL);
2676 }
2677
2678 DEFUN (no_ipv6_route_ifname,
2679 no_ipv6_route_ifname_cmd,
2680 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE [tag (1-4294967295)] [(1-255)] [vrf NAME]",
2681 NO_STR
2682 IP_STR
2683 "Establish static routes\n"
2684 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
2685 "IPv6 gateway address\n"
2686 "IPv6 gateway interface name\n"
2687 "Set tag for this route\n"
2688 "Tag value\n"
2689 "Distance value for this prefix\n"
2690 VRF_CMD_HELP_STR
2691 "Specify labels for this route\n"
2692 "One or more labels separated by '/'\n")
2693 {
2694 int idx_ipv6_prefixlen = 3;
2695 int idx_ipv6 = 4;
2696 int idx_interface = 5;
2697 int idx_curr = 6;
2698 char *tag, *distance, *vrf;
2699
2700 tag = distance = vrf = NULL;
2701 zebra_vty_ip_route_tdv_helper (argc, argv, idx_curr, &tag, &distance, &vrf, NULL);
2702
2703 return static_ipv6_func (vty, 0,
2704 argv[idx_ipv6_prefixlen]->arg,
2705 argv[idx_ipv6]->arg,
2706 argv[idx_interface]->arg,
2707 NULL,
2708 tag, distance, vrf, NULL);
2709 }
2710
2711 DEFUN (no_ipv6_route_ifname_flags,
2712 no_ipv6_route_ifname_flags_cmd,
2713 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE <reject|blackhole> [tag (1-4294967295)] [(1-255)] [vrf NAME]",
2714 NO_STR
2715 IP_STR
2716 "Establish static routes\n"
2717 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
2718 "IPv6 gateway address\n"
2719 "IPv6 gateway interface name\n"
2720 "Emit an ICMP unreachable when matched\n"
2721 "Silently discard pkts when matched\n"
2722 "Set tag for this route\n"
2723 "Tag value\n"
2724 "Distance value for this prefix\n"
2725 VRF_CMD_HELP_STR
2726 "Specify labels for this route\n"
2727 "One or more labels separated by '/'\n")
2728 {
2729 int idx_ipv6_prefixlen = 3;
2730 int idx_ipv6 = 4;
2731 int idx_interface = 5;
2732 int idx_reject_blackhole = 6;
2733 int idx_curr = 7;
2734 char *tag, *distance, *vrf;
2735
2736 tag = distance = vrf = NULL;
2737 zebra_vty_ip_route_tdv_helper (argc, argv, idx_curr, &tag, &distance, &vrf, NULL);
2738
2739 return static_ipv6_func (vty, 0,
2740 argv[idx_ipv6_prefixlen]->arg,
2741 argv[idx_ipv6]->arg,
2742 argv[idx_interface]->arg,
2743 argv[idx_reject_blackhole]->arg,
2744 tag, distance, vrf, NULL);
2745 }
2746
2747 DEFUN (show_ipv6_route,
2748 show_ipv6_route_cmd,
2749 "show ipv6 route [vrf NAME] [json]",
2750 SHOW_STR
2751 IP_STR
2752 "IPv6 routing table\n"
2753 VRF_CMD_HELP_STR
2754 "Output JSON\n")
2755 {
2756 struct route_table *table;
2757 struct route_node *rn;
2758 struct rib *rib;
2759 int first = 1;
2760 vrf_id_t vrf_id = VRF_DEFAULT;
2761 struct zebra_vrf *zvrf = NULL;
2762 char buf[BUFSIZ];
2763 json_object *json = NULL;
2764 json_object *json_prefix = NULL;
2765
2766 int vrf = (argc > 3 && strmatch (argv[3]->text, "vrf"));
2767 int uj = vrf ? argc == 6 : argc == 4;
2768 char *vrfname = vrf ? argv[4]->arg : NULL;
2769
2770 if (vrf)
2771 {
2772 if (!(zvrf = zebra_vrf_lookup_by_name (vrfname)))
2773 {
2774 if (uj)
2775 vty_out (vty, "{}%s", VTY_NEWLINE);
2776 else
2777 vty_out (vty, "vrf %s not defined%s", vrfname, VTY_NEWLINE);
2778 return CMD_SUCCESS;
2779 }
2780
2781 if (zvrf_id (zvrf) == VRF_UNKNOWN)
2782 {
2783 if (uj)
2784 vty_out (vty, "{}%s", VTY_NEWLINE);
2785 else
2786 vty_out (vty, "vrf %s inactive%s", vrfname, VTY_NEWLINE);
2787 return CMD_SUCCESS;
2788 }
2789 else
2790 vrf_id = zvrf_id (zvrf);
2791 }
2792
2793 table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
2794 if (!table)
2795 {
2796 if (uj)
2797 vty_out (vty, "{}%s", VTY_NEWLINE);
2798 return CMD_SUCCESS;
2799 }
2800
2801 if (uj)
2802 {
2803 json = json_object_new_object();
2804
2805 /* Show all IPv6 route. */
2806 for (rn = route_top (table); rn; rn = route_next (rn))
2807 {
2808 RNODE_FOREACH_RIB (rn, rib)
2809 {
2810 if (!json_prefix)
2811 json_prefix = json_object_new_array();
2812 vty_show_ip_route (vty, rn, rib, json_prefix);
2813 }
2814
2815 if (json_prefix)
2816 {
2817 prefix2str (&rn->p, buf, sizeof buf);
2818 json_object_object_add(json, buf, json_prefix);
2819 json_prefix = NULL;
2820 }
2821 }
2822
2823 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
2824 json_object_free(json);
2825 }
2826 else
2827 {
2828 /* Show all IPv6 route. */
2829 for (rn = route_top (table); rn; rn = route_next (rn))
2830 {
2831 RNODE_FOREACH_RIB (rn, rib)
2832 {
2833 if (first)
2834 {
2835 vty_out (vty, SHOW_ROUTE_V6_HEADER);
2836 first = 0;
2837 }
2838 vty_show_ip_route (vty, rn, rib, NULL);
2839 }
2840 }
2841 }
2842
2843 return CMD_SUCCESS;
2844 }
2845
2846 DEFUN (show_ipv6_route_tag,
2847 show_ipv6_route_tag_cmd,
2848 "show ipv6 route [vrf NAME] tag (1-4294967295)",
2849 SHOW_STR
2850 IP_STR
2851 "IPv6 routing table\n"
2852 VRF_CMD_HELP_STR
2853 "Show only routes with tag\n"
2854 "Tag value\n")
2855 {
2856 int idx_vrf = 3;
2857 int idx_name = 4;
2858 int idx_tag = 6;
2859 struct route_table *table;
2860 struct route_node *rn;
2861 struct rib *rib;
2862 int first = 1;
2863 route_tag_t tag = 0;
2864 vrf_id_t vrf_id = VRF_DEFAULT;
2865
2866 if (strmatch(argv[idx_vrf]->text, "vrf"))
2867 {
2868 VRF_GET_ID (vrf_id, argv[idx_name]->arg);
2869 VTY_GET_INTEGER_RANGE("tag", tag, argv[idx_tag]->arg, 0, 4294967295);
2870 }
2871 else
2872 {
2873 idx_tag -= 2;
2874 VTY_GET_INTEGER_RANGE("tag", tag, argv[idx_tag]->arg, 0, 4294967295);
2875 }
2876
2877 table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
2878 if (! table)
2879 return CMD_SUCCESS;
2880
2881 /* Show all IPv6 routes with matching tag value. */
2882 for (rn = route_top (table); rn; rn = route_next (rn))
2883 RNODE_FOREACH_RIB (rn, rib)
2884 {
2885 if (rib->tag != tag)
2886 continue;
2887
2888 if (first)
2889 {
2890 vty_out (vty, SHOW_ROUTE_V6_HEADER);
2891 first = 0;
2892 }
2893 vty_show_ip_route (vty, rn, rib, NULL);
2894 }
2895 return CMD_SUCCESS;
2896 }
2897
2898 DEFUN (show_ipv6_route_prefix_longer,
2899 show_ipv6_route_prefix_longer_cmd,
2900 "show ipv6 route [vrf NAME] X:X::X:X/M longer-prefixes",
2901 SHOW_STR
2902 IP_STR
2903 "IPv6 routing table\n"
2904 VRF_CMD_HELP_STR
2905 "IPv6 prefix\n"
2906 "Show route matching the specified Network/Mask pair only\n")
2907 {
2908 struct route_table *table;
2909 struct route_node *rn;
2910 struct rib *rib;
2911 struct prefix p;
2912 int ret;
2913 int first = 1;
2914 vrf_id_t vrf_id = VRF_DEFAULT;
2915
2916 if (strmatch(argv[3]->text, "vrf"))
2917 {
2918 VRF_GET_ID (vrf_id, argv[4]->arg);
2919 ret = str2prefix (argv[5]->arg, &p);
2920 }
2921 else
2922 {
2923 ret = str2prefix (argv[3]->arg, &p);
2924 }
2925
2926 if (! ret)
2927 {
2928 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
2929 return CMD_WARNING;
2930 }
2931
2932 table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
2933 if (! table)
2934 return CMD_SUCCESS;
2935
2936 /* Show matched type IPv6 routes. */
2937 for (rn = route_top (table); rn; rn = route_next (rn))
2938 RNODE_FOREACH_RIB (rn, rib)
2939 if (prefix_match (&p, &rn->p))
2940 {
2941 if (first)
2942 {
2943 vty_out (vty, SHOW_ROUTE_V6_HEADER);
2944 first = 0;
2945 }
2946 vty_show_ip_route (vty, rn, rib, NULL);
2947 }
2948 return CMD_SUCCESS;
2949 }
2950
2951 DEFUN (show_ipv6_route_protocol,
2952 show_ipv6_route_protocol_cmd,
2953 "show ipv6 route [vrf NAME] <kernel|connected|static|ripng|ospf6|isis|bgp|table>",
2954 SHOW_STR
2955 IP_STR
2956 "IP routing table\n"
2957 VRF_CMD_HELP_STR
2958 FRR_IP6_REDIST_HELP_STR_ZEBRA)
2959 {
2960 int type;
2961 struct route_table *table;
2962 struct route_node *rn;
2963 struct rib *rib;
2964 int first = 1;
2965 vrf_id_t vrf_id = VRF_DEFAULT;
2966
2967 int idx = 0;
2968 if (argv_find (argv, argc, "NAME", &idx))
2969 VRF_GET_ID (vrf_id, argv[idx]->arg);
2970
2971 char *proto = argv[argc - 1]->text;
2972 type = proto_redistnum (AFI_IP, proto);
2973
2974 if (type < 0)
2975 {
2976 vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
2977 return CMD_WARNING;
2978 }
2979
2980 table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
2981 if (! table)
2982 return CMD_SUCCESS;
2983
2984 /* Show matched type IPv6 routes. */
2985 for (rn = route_top (table); rn; rn = route_next (rn))
2986 RNODE_FOREACH_RIB (rn, rib)
2987 if (rib->type == type)
2988 {
2989 if (first)
2990 {
2991 vty_out (vty, SHOW_ROUTE_V6_HEADER);
2992 first = 0;
2993 }
2994 vty_show_ip_route (vty, rn, rib, NULL);
2995 }
2996 return CMD_SUCCESS;
2997 }
2998
2999 DEFUN (show_ipv6_route_addr,
3000 show_ipv6_route_addr_cmd,
3001 "show ipv6 route [vrf NAME] X:X::X:X",
3002 SHOW_STR
3003 IP_STR
3004 "IPv6 routing table\n"
3005 VRF_CMD_HELP_STR
3006 "IPv6 Address\n")
3007 {
3008 int ret;
3009 struct prefix_ipv6 p;
3010 struct route_table *table;
3011 struct route_node *rn;
3012 vrf_id_t vrf_id = VRF_DEFAULT;
3013
3014 if (strmatch(argv[3]->text, "vrf"))
3015 {
3016 VRF_GET_ID (vrf_id, argv[4]->arg);
3017 ret = str2prefix_ipv6 (argv[5]->arg, &p);
3018 }
3019 else
3020 {
3021 ret = str2prefix_ipv6 (argv[3]->arg, &p);
3022 }
3023
3024 if (ret <= 0)
3025 {
3026 vty_out (vty, "Malformed IPv6 address%s", VTY_NEWLINE);
3027 return CMD_WARNING;
3028 }
3029
3030 table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
3031 if (! table)
3032 return CMD_SUCCESS;
3033
3034 rn = route_node_match (table, (struct prefix *) &p);
3035 if (! rn)
3036 {
3037 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
3038 return CMD_WARNING;
3039 }
3040
3041 vty_show_ip_route_detail (vty, rn, 0);
3042
3043 route_unlock_node (rn);
3044
3045 return CMD_SUCCESS;
3046 }
3047
3048 DEFUN (show_ipv6_route_prefix,
3049 show_ipv6_route_prefix_cmd,
3050 "show ipv6 route [vrf NAME] X:X::X:X/M",
3051 SHOW_STR
3052 IP_STR
3053 "IPv6 routing table\n"
3054 VRF_CMD_HELP_STR
3055 "IPv6 prefix\n")
3056 {
3057 int ret;
3058 struct prefix_ipv6 p;
3059 struct route_table *table;
3060 struct route_node *rn;
3061 vrf_id_t vrf_id = VRF_DEFAULT;
3062
3063 if (strmatch(argv[3]->text, "vrf"))
3064 {
3065 VRF_GET_ID (vrf_id, argv[4]->arg);
3066 ret = str2prefix_ipv6 (argv[5]->arg, &p);
3067 }
3068 else
3069 ret = str2prefix_ipv6 (argv[3]->arg, &p);
3070
3071 if (ret <= 0)
3072 {
3073 vty_out (vty, "Malformed IPv6 prefix%s", VTY_NEWLINE);
3074 return CMD_WARNING;
3075 }
3076
3077 table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
3078 if (! table)
3079 return CMD_SUCCESS;
3080
3081 rn = route_node_match (table, (struct prefix *) &p);
3082 if (! rn || rn->p.prefixlen != p.prefixlen)
3083 {
3084 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
3085 return CMD_WARNING;
3086 }
3087
3088 vty_show_ip_route_detail (vty, rn, 0);
3089
3090 route_unlock_node (rn);
3091
3092 return CMD_SUCCESS;
3093 }
3094
3095
3096 /* Show route summary. */
3097 DEFUN (show_ipv6_route_summary,
3098 show_ipv6_route_summary_cmd,
3099 "show ipv6 route [vrf NAME] summary",
3100 SHOW_STR
3101 IP_STR
3102 "IPv6 routing table\n"
3103 VRF_CMD_HELP_STR
3104 "Summary of all IPv6 routes\n")
3105 {
3106 struct route_table *table;
3107 vrf_id_t vrf_id = VRF_DEFAULT;
3108
3109 if (strmatch(argv[3]->text, "vrf"))
3110 VRF_GET_ID (vrf_id, argv[4]->arg);
3111
3112 table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
3113 if (! table)
3114 return CMD_SUCCESS;
3115
3116 vty_show_ip_route_summary (vty, table);
3117
3118 return CMD_SUCCESS;
3119 }
3120
3121
3122 /* Show ipv6 route summary prefix. */
3123 DEFUN (show_ipv6_route_summary_prefix,
3124 show_ipv6_route_summary_prefix_cmd,
3125 "show ipv6 route [vrf NAME] summary prefix",
3126 SHOW_STR
3127 IP_STR
3128 "IPv6 routing table\n"
3129 VRF_CMD_HELP_STR
3130 "Summary of all IPv6 routes\n"
3131 "Prefix routes\n")
3132 {
3133 struct route_table *table;
3134 vrf_id_t vrf_id = VRF_DEFAULT;
3135
3136 if (strmatch(argv[3]->text, "vrf"))
3137 VRF_GET_ID (vrf_id, argv[4]->arg);
3138
3139 table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
3140 if (! table)
3141 return CMD_SUCCESS;
3142
3143 vty_show_ip_route_summary_prefix (vty, table);
3144
3145 return CMD_SUCCESS;
3146 }
3147
3148
3149 /*
3150 * Show IPv6 mroute command.Used to dump
3151 * the Multicast routing table.
3152 */
3153 DEFUN (show_ipv6_mroute,
3154 show_ipv6_mroute_cmd,
3155 "show ipv6 mroute [vrf NAME]",
3156 SHOW_STR
3157 IP_STR
3158 "IPv6 Multicast routing table\n"
3159 VRF_CMD_HELP_STR)
3160 {
3161 struct route_table *table;
3162 struct route_node *rn;
3163 struct rib *rib;
3164 int first = 1;
3165 vrf_id_t vrf_id = VRF_DEFAULT;
3166
3167 if (strmatch(argv[3]->text, "vrf"))
3168 VRF_GET_ID (vrf_id, argv[4]->arg);
3169
3170 table = zebra_vrf_table (AFI_IP6, SAFI_MULTICAST, vrf_id);
3171 if (! table)
3172 return CMD_SUCCESS;
3173
3174 /* Show all IPv6 route. */
3175 for (rn = route_top (table); rn; rn = route_next (rn))
3176 RNODE_FOREACH_RIB (rn, rib)
3177 {
3178 if (first)
3179 {
3180 vty_out (vty, SHOW_ROUTE_V6_HEADER);
3181 first = 0;
3182 }
3183 vty_show_ip_route (vty, rn, rib, NULL);
3184 }
3185 return CMD_SUCCESS;
3186 }
3187
3188
3189 DEFUN (show_ipv6_route_vrf_all,
3190 show_ipv6_route_vrf_all_cmd,
3191 "show ipv6 route vrf all",
3192 SHOW_STR
3193 IP_STR
3194 "IPv6 routing table\n"
3195 VRF_ALL_CMD_HELP_STR)
3196 {
3197 struct route_table *table;
3198 struct route_node *rn;
3199 struct rib *rib;
3200 struct vrf *vrf;
3201 struct zebra_vrf *zvrf;
3202 int first = 1;
3203 int vrf_header = 1;
3204
3205 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
3206 {
3207 if ((zvrf = vrf->info) == NULL ||
3208 (table = zvrf->table[AFI_IP6][SAFI_UNICAST]) == NULL)
3209 continue;
3210
3211 /* Show all IPv6 route. */
3212 for (rn = route_top (table); rn; rn = route_next (rn))
3213 RNODE_FOREACH_RIB (rn, rib)
3214 {
3215 if (first)
3216 {
3217 vty_out (vty, SHOW_ROUTE_V6_HEADER);
3218 first = 0;
3219 }
3220
3221 if (vrf_header)
3222 {
3223 vty_out (vty, "%sVRF %s:%s", VTY_NEWLINE, zvrf_name (zvrf), VTY_NEWLINE);
3224 vrf_header = 0;
3225 }
3226 vty_show_ip_route (vty, rn, rib, NULL);
3227 }
3228 vrf_header = 1;
3229 }
3230
3231 return CMD_SUCCESS;
3232 }
3233
3234 DEFUN (show_ipv6_route_vrf_all_tag,
3235 show_ipv6_route_vrf_all_tag_cmd,
3236 "show ipv6 route vrf all tag (1-4294967295)",
3237 SHOW_STR
3238 IP_STR
3239 "IPv6 routing table\n"
3240 VRF_ALL_CMD_HELP_STR
3241 "Show only routes with tag\n"
3242 "Tag value\n")
3243 {
3244 int idx_number = 6;
3245 struct route_table *table;
3246 struct route_node *rn;
3247 struct rib *rib;
3248 struct vrf *vrf;
3249 struct zebra_vrf *zvrf;
3250 int first = 1;
3251 int vrf_header = 1;
3252 route_tag_t tag = 0;
3253
3254 if (argv[idx_number]->arg)
3255 VTY_GET_INTEGER_RANGE("tag", tag, argv[idx_number]->arg, 0, 4294967295);
3256
3257 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
3258 {
3259 if ((zvrf = vrf->info) == NULL ||
3260 (table = zvrf->table[AFI_IP][SAFI_UNICAST]) == NULL)
3261 continue;
3262
3263 /* Show all IPv6 routes with matching tag value. */
3264 for (rn = route_top (table); rn; rn = route_next (rn))
3265 RNODE_FOREACH_RIB (rn, rib)
3266 {
3267 if (rib->tag != tag)
3268 continue;
3269
3270 if (first)
3271 {
3272 vty_out (vty, SHOW_ROUTE_V6_HEADER);
3273 first = 0;
3274 }
3275
3276 if (vrf_header)
3277 {
3278 vty_out (vty, "%sVRF %s:%s", VTY_NEWLINE, zvrf_name (zvrf), VTY_NEWLINE);
3279 vrf_header = 0;
3280 }
3281 vty_show_ip_route (vty, rn, rib, NULL);
3282 }
3283 vrf_header = 1;
3284 }
3285
3286 return CMD_SUCCESS;
3287 }
3288
3289 DEFUN (show_ipv6_route_vrf_all_prefix_longer,
3290 show_ipv6_route_vrf_all_prefix_longer_cmd,
3291 "show ipv6 route vrf all X:X::X:X/M longer-prefixes",
3292 SHOW_STR
3293 IP_STR
3294 "IPv6 routing table\n"
3295 VRF_ALL_CMD_HELP_STR
3296 "IPv6 prefix\n"
3297 "Show route matching the specified Network/Mask pair only\n")
3298 {
3299 int idx_ipv6_prefixlen = 5;
3300 struct route_table *table;
3301 struct route_node *rn;
3302 struct rib *rib;
3303 struct prefix p;
3304 struct vrf *vrf;
3305 struct zebra_vrf *zvrf;
3306 int ret;
3307 int first = 1;
3308 int vrf_header = 1;
3309
3310 ret = str2prefix (argv[idx_ipv6_prefixlen]->arg, &p);
3311 if (! ret)
3312 {
3313 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
3314 return CMD_WARNING;
3315 }
3316
3317 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
3318 {
3319 if ((zvrf = vrf->info) == NULL ||
3320 (table = zvrf->table[AFI_IP6][SAFI_UNICAST]) == NULL)
3321 continue;
3322
3323 /* Show matched type IPv6 routes. */
3324 for (rn = route_top (table); rn; rn = route_next (rn))
3325 RNODE_FOREACH_RIB (rn, rib)
3326 if (prefix_match (&p, &rn->p))
3327 {
3328 if (first)
3329 {
3330 vty_out (vty, SHOW_ROUTE_V6_HEADER);
3331 first = 0;
3332 }
3333
3334 if (vrf_header)
3335 {
3336 vty_out (vty, "%sVRF %s:%s", VTY_NEWLINE, zvrf_name (zvrf), VTY_NEWLINE);
3337 vrf_header = 0;
3338 }
3339 vty_show_ip_route (vty, rn, rib, NULL);
3340 }
3341 vrf_header = 1;
3342 }
3343
3344 return CMD_SUCCESS;
3345 }
3346
3347 DEFUN (show_ipv6_route_vrf_all_protocol,
3348 show_ipv6_route_vrf_all_protocol_cmd,
3349 "show ipv6 route vrf all <kernel|connected|static|ripng|ospf6|isis|bgp|table>",
3350 SHOW_STR
3351 IP_STR
3352 "IP routing table\n"
3353 VRF_ALL_CMD_HELP_STR
3354 FRR_IP6_REDIST_HELP_STR_ZEBRA)
3355 {
3356 int type;
3357 struct route_table *table;
3358 struct route_node *rn;
3359 struct rib *rib;
3360 struct vrf *vrf;
3361 struct zebra_vrf *zvrf;
3362 int first = 1;
3363 int vrf_header = 1;
3364
3365 char *proto = argv[argc - 1]->text;
3366 type = proto_redistnum (AFI_IP, proto);
3367
3368 if (type < 0)
3369 {
3370 vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
3371 return CMD_WARNING;
3372 }
3373
3374 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
3375 {
3376 if ((zvrf = vrf->info) == NULL ||
3377 (table = zvrf->table[AFI_IP6][SAFI_UNICAST]) == NULL)
3378 continue;
3379
3380 /* Show matched type IPv6 routes. */
3381 for (rn = route_top (table); rn; rn = route_next (rn))
3382 RNODE_FOREACH_RIB (rn, rib)
3383 if (rib->type == type)
3384 {
3385 if (first)
3386 {
3387 vty_out (vty, SHOW_ROUTE_V6_HEADER);
3388 first = 0;
3389 }
3390
3391 if (vrf_header)
3392 {
3393 vty_out (vty, "%sVRF %s:%s", VTY_NEWLINE, zvrf_name (zvrf), VTY_NEWLINE);
3394 vrf_header = 0;
3395 }
3396 vty_show_ip_route (vty, rn, rib, NULL);
3397 }
3398 vrf_header = 1;
3399 }
3400
3401 return CMD_SUCCESS;
3402 }
3403
3404 DEFUN (show_ipv6_route_vrf_all_addr,
3405 show_ipv6_route_vrf_all_addr_cmd,
3406 "show ipv6 route vrf all X:X::X:X",
3407 SHOW_STR
3408 IP_STR
3409 "IPv6 routing table\n"
3410 VRF_ALL_CMD_HELP_STR
3411 "IPv6 Address\n")
3412 {
3413 int idx_ipv6 = 5;
3414 int ret;
3415 struct prefix_ipv6 p;
3416 struct route_table *table;
3417 struct route_node *rn;
3418 struct vrf *vrf;
3419 struct zebra_vrf *zvrf;
3420
3421 ret = str2prefix_ipv6 (argv[idx_ipv6]->arg, &p);
3422 if (ret <= 0)
3423 {
3424 vty_out (vty, "Malformed IPv6 address%s", VTY_NEWLINE);
3425 return CMD_WARNING;
3426 }
3427
3428 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
3429 {
3430 if ((zvrf = vrf->info) == NULL ||
3431 (table = zvrf->table[AFI_IP6][SAFI_UNICAST]) == NULL)
3432 continue;
3433
3434 rn = route_node_match (table, (struct prefix *) &p);
3435 if (! rn)
3436 continue;
3437
3438 vty_show_ip_route_detail (vty, rn, 0);
3439
3440 route_unlock_node (rn);
3441 }
3442
3443 return CMD_SUCCESS;
3444 }
3445
3446 DEFUN (show_ipv6_route_vrf_all_prefix,
3447 show_ipv6_route_vrf_all_prefix_cmd,
3448 "show ipv6 route vrf all X:X::X:X/M",
3449 SHOW_STR
3450 IP_STR
3451 "IPv6 routing table\n"
3452 VRF_ALL_CMD_HELP_STR
3453 "IPv6 prefix\n")
3454 {
3455 int idx_ipv6_prefixlen = 5;
3456 int ret;
3457 struct prefix_ipv6 p;
3458 struct route_table *table;
3459 struct route_node *rn;
3460 struct vrf *vrf;
3461 struct zebra_vrf *zvrf;
3462
3463 ret = str2prefix_ipv6 (argv[idx_ipv6_prefixlen]->arg, &p);
3464 if (ret <= 0)
3465 {
3466 vty_out (vty, "Malformed IPv6 prefix%s", VTY_NEWLINE);
3467 return CMD_WARNING;
3468 }
3469
3470 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
3471 {
3472 if ((zvrf = vrf->info) == NULL ||
3473 (table = zvrf->table[AFI_IP6][SAFI_UNICAST]) == NULL)
3474 continue;
3475
3476 rn = route_node_match (table, (struct prefix *) &p);
3477 if (! rn)
3478 continue;
3479 if (rn->p.prefixlen != p.prefixlen)
3480 {
3481 route_unlock_node (rn);
3482 continue;
3483 }
3484
3485 vty_show_ip_route_detail (vty, rn, 0);
3486
3487 route_unlock_node (rn);
3488 }
3489
3490 return CMD_SUCCESS;
3491 }
3492
3493 DEFUN (show_ipv6_route_vrf_all_summary,
3494 show_ipv6_route_vrf_all_summary_cmd,
3495 "show ipv6 route vrf all summary",
3496 SHOW_STR
3497 IP_STR
3498 "IPv6 routing table\n"
3499 VRF_ALL_CMD_HELP_STR
3500 "Summary of all IPv6 routes\n")
3501 {
3502 struct vrf *vrf;
3503 struct zebra_vrf *zvrf;
3504
3505 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
3506 if ((zvrf = vrf->info) != NULL)
3507 vty_show_ip_route_summary (vty, zvrf->table[AFI_IP6][SAFI_UNICAST]);
3508
3509 return CMD_SUCCESS;
3510 }
3511
3512 DEFUN (show_ipv6_mroute_vrf_all,
3513 show_ipv6_mroute_vrf_all_cmd,
3514 "show ipv6 mroute vrf all",
3515 SHOW_STR
3516 IP_STR
3517 "IPv6 Multicast routing table\n"
3518 VRF_ALL_CMD_HELP_STR)
3519 {
3520 struct route_table *table;
3521 struct route_node *rn;
3522 struct rib *rib;
3523 struct vrf *vrf;
3524 struct zebra_vrf *zvrf;
3525 int first = 1;
3526
3527 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
3528 {
3529 if ((zvrf = vrf->info) == NULL ||
3530 (table = zvrf->table[AFI_IP6][SAFI_UNICAST]) == NULL)
3531 continue;
3532
3533 /* Show all IPv6 route. */
3534 for (rn = route_top (table); rn; rn = route_next (rn))
3535 RNODE_FOREACH_RIB (rn, rib)
3536 {
3537 if (first)
3538 {
3539 vty_out (vty, SHOW_ROUTE_V6_HEADER);
3540 first = 0;
3541 }
3542 vty_show_ip_route (vty, rn, rib, NULL);
3543 }
3544 }
3545 return CMD_SUCCESS;
3546 }
3547
3548 DEFUN (show_ipv6_route_vrf_all_summary_prefix,
3549 show_ipv6_route_vrf_all_summary_prefix_cmd,
3550 "show ipv6 route vrf all summary prefix",
3551 SHOW_STR
3552 IP_STR
3553 "IPv6 routing table\n"
3554 VRF_ALL_CMD_HELP_STR
3555 "Summary of all IPv6 routes\n"
3556 "Prefix routes\n")
3557 {
3558 struct vrf *vrf;
3559 struct zebra_vrf *zvrf;
3560
3561 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
3562 if ((zvrf = vrf->info) != NULL)
3563 vty_show_ip_route_summary_prefix (vty, zvrf->table[AFI_IP6][SAFI_UNICAST]);
3564
3565 return CMD_SUCCESS;
3566 }
3567
3568 /* Write IPv6 static route configuration. */
3569 static int
3570 static_config_ipv6 (struct vty *vty)
3571 {
3572 struct route_node *rn;
3573 struct static_route *si;
3574 int write = 0;
3575 char buf[PREFIX_STRLEN];
3576 struct route_table *stable;
3577 struct vrf *vrf;
3578 struct zebra_vrf *zvrf;
3579
3580 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
3581 {
3582 if (!(zvrf = vrf->info))
3583 continue;
3584 if ((stable = zvrf->stable[AFI_IP6][SAFI_UNICAST]) == NULL)
3585 continue;
3586
3587 for (rn = route_top (stable); rn; rn = route_next (rn))
3588 for (si = rn->info; si; si = si->next)
3589 {
3590 vty_out (vty, "ipv6 route %s", prefix2str (&rn->p, buf, sizeof buf));
3591
3592 switch (si->type)
3593 {
3594 case STATIC_IPV6_GATEWAY:
3595 vty_out (vty, " %s", inet_ntop (AF_INET6, &si->addr.ipv6, buf, BUFSIZ));
3596 break;
3597 case STATIC_IFINDEX:
3598 vty_out (vty, " %s", si->ifname);
3599 break;
3600 case STATIC_BLACKHOLE:
3601 vty_out (vty, " Null0" );
3602 break;
3603 case STATIC_IPV6_GATEWAY_IFINDEX:
3604 vty_out (vty, " %s %s",
3605 inet_ntop (AF_INET6, &si->addr.ipv6, buf, BUFSIZ),
3606 ifindex2ifname_vrf (si->ifindex, si->vrf_id));
3607 break;
3608 }
3609
3610 /* flags are incompatible with STATIC_BLACKHOLE */
3611 if (si->type != STATIC_BLACKHOLE)
3612 {
3613 if (CHECK_FLAG(si->flags, ZEBRA_FLAG_REJECT))
3614 vty_out (vty, " %s", "reject");
3615 if (CHECK_FLAG(si->flags, ZEBRA_FLAG_BLACKHOLE))
3616 vty_out (vty, " %s", "blackhole");
3617 }
3618
3619 if (si->tag)
3620 vty_out (vty, " tag %"ROUTE_TAG_PRI, si->tag);
3621
3622 if (si->distance != ZEBRA_STATIC_DISTANCE_DEFAULT)
3623 vty_out (vty, " %d", si->distance);
3624
3625 if (si->vrf_id != VRF_DEFAULT)
3626 {
3627 vty_out (vty, " vrf %s", zvrf_name (zvrf));
3628 }
3629
3630 /* Label information */
3631 if (si->snh_label.num_labels)
3632 vty_out (vty, " label %s",
3633 mpls_label2str (si->snh_label.num_labels,
3634 si->snh_label.label, buf, sizeof buf));
3635
3636 vty_out (vty, "%s", VTY_NEWLINE);
3637
3638 write = 1;
3639 }
3640 }
3641 return write;
3642 }
3643
3644 DEFUN (allow_external_route_update,
3645 allow_external_route_update_cmd,
3646 "allow-external-route-update",
3647 "Allow Quagga routes to be overwritten by external processes")
3648 {
3649 allow_delete = 1;
3650
3651 return CMD_SUCCESS;
3652 }
3653
3654 DEFUN (no_allow_external_route_update,
3655 no_allow_external_route_update_cmd,
3656 "no allow-external-route-update",
3657 "Allow Quagga routes to be overwritten by external processes")
3658 {
3659 allow_delete = 0;
3660
3661 return CMD_SUCCESS;
3662 }
3663
3664 /* show vrf */
3665 DEFUN (show_vrf,
3666 show_vrf_cmd,
3667 "show vrf",
3668 SHOW_STR
3669 "VRF\n")
3670 {
3671 struct vrf *vrf;
3672 struct zebra_vrf *zvrf;
3673
3674 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
3675 {
3676 if (!(zvrf = vrf->info))
3677 continue;
3678 if (!zvrf_id (zvrf))
3679 continue;
3680
3681 vty_out (vty, "vrf %s ", zvrf_name (zvrf));
3682 if (zvrf_id (zvrf) == VRF_UNKNOWN)
3683 vty_out (vty, "inactive");
3684 else
3685 vty_out (vty, "id %u table %u", zvrf_id (zvrf), zvrf->table_id);
3686 vty_out (vty, "%s", VTY_NEWLINE);
3687
3688 }
3689
3690 return CMD_SUCCESS;
3691 }
3692
3693 /* Static ip route configuration write function. */
3694 static int
3695 zebra_ip_config (struct vty *vty)
3696 {
3697 int write = 0;
3698
3699 write += static_config_ipv4 (vty, SAFI_UNICAST, "ip route");
3700 write += static_config_ipv4 (vty, SAFI_MULTICAST, "ip mroute");
3701 write += static_config_ipv6 (vty);
3702
3703 write += zebra_import_table_config (vty);
3704 return write;
3705 }
3706
3707 DEFUN (ip_zebra_import_table_distance,
3708 ip_zebra_import_table_distance_cmd,
3709 "ip import-table (1-252) [distance (1-255)] [route-map WORD]",
3710 IP_STR
3711 "import routes from non-main kernel table\n"
3712 "kernel routing table id\n"
3713 "Distance for imported routes\n"
3714 "Default distance value\n"
3715 "route-map for filtering\n"
3716 "route-map name\n")
3717 {
3718 u_int32_t table_id = 0;
3719
3720 VTY_GET_INTEGER("table", table_id, argv[2]->arg);
3721 int distance = ZEBRA_TABLE_DISTANCE_DEFAULT;
3722 char *rmap = strmatch (argv[argc - 2]->text, "route-map") ?
3723 XSTRDUP(MTYPE_ROUTE_MAP_NAME, argv[argc - 1]->arg) : NULL;
3724 if (argc == 7 || (argc == 5 && !rmap))
3725 VTY_GET_INTEGER_RANGE("distance", distance, argv[4]->arg, 1, 255);
3726
3727 if (!is_zebra_valid_kernel_table(table_id))
3728 {
3729 vty_out(vty, "Invalid routing table ID, %d. Must be in range 1-252%s",
3730 table_id, VTY_NEWLINE);
3731 return CMD_WARNING;
3732 }
3733
3734 if (is_zebra_main_routing_table(table_id))
3735 {
3736 vty_out(vty, "Invalid routing table ID, %d. Must be non-default table%s",
3737 table_id, VTY_NEWLINE);
3738 return CMD_WARNING;
3739 }
3740
3741 return (zebra_import_table(AFI_IP, table_id, distance, rmap, 1));
3742 }
3743
3744 DEFUN (no_ip_zebra_import_table,
3745 no_ip_zebra_import_table_cmd,
3746 "no ip import-table (1-252) [distance (1-255)] [route-map NAME]",
3747 NO_STR
3748 IP_STR
3749 "import routes from non-main kernel table\n"
3750 "kernel routing table id\n"
3751 "Distance for imported routes\n"
3752 "Default distance value\n"
3753 "route-map for filtering\n"
3754 "route-map name\n")
3755 {
3756 u_int32_t table_id = 0;
3757 VTY_GET_INTEGER("table", table_id, argv[3]->arg);
3758
3759 if (!is_zebra_valid_kernel_table(table_id))
3760 {
3761 vty_out(vty, "Invalid routing table ID. Must be in range 1-252%s",
3762 VTY_NEWLINE);
3763 return CMD_WARNING;
3764 }
3765
3766 if (is_zebra_main_routing_table(table_id))
3767 {
3768 vty_out(vty, "Invalid routing table ID, %d. Must be non-default table%s",
3769 table_id, VTY_NEWLINE);
3770 return CMD_WARNING;
3771 }
3772
3773 if (!is_zebra_import_table_enabled(AFI_IP, table_id))
3774 return CMD_SUCCESS;
3775
3776 return (zebra_import_table(AFI_IP, table_id, 0, NULL, 0));
3777 }
3778
3779 static int
3780 config_write_protocol (struct vty *vty)
3781 {
3782 if (allow_delete)
3783 vty_out(vty, "allow-external-route-update%s", VTY_NEWLINE);
3784
3785 if (zebra_rnh_ip_default_route)
3786 vty_out(vty, "ip nht resolve-via-default%s", VTY_NEWLINE);
3787
3788 if (zebra_rnh_ipv6_default_route)
3789 vty_out(vty, "ipv6 nht resolve-via-default%s", VTY_NEWLINE);
3790
3791 enum multicast_mode ipv4_multicast_mode = multicast_mode_ipv4_get ();
3792
3793 if (ipv4_multicast_mode != MCAST_NO_CONFIG)
3794 vty_out (vty, "ip multicast rpf-lookup-mode %s%s",
3795 ipv4_multicast_mode == MCAST_URIB_ONLY ? "urib-only" :
3796 ipv4_multicast_mode == MCAST_MRIB_ONLY ? "mrib-only" :
3797 ipv4_multicast_mode == MCAST_MIX_MRIB_FIRST ? "mrib-then-urib" :
3798 ipv4_multicast_mode == MCAST_MIX_DISTANCE ? "lower-distance" :
3799 "longer-prefix",
3800 VTY_NEWLINE);
3801
3802 zebra_routemap_config_write_protocol(vty);
3803
3804 return 1;
3805 }
3806
3807 /* IP node for static routes. */
3808 static struct cmd_node ip_node = { IP_NODE, "", 1 };
3809 static struct cmd_node protocol_node = { PROTOCOL_NODE, "", 1 };
3810
3811 /* Route VTY. */
3812 void
3813 zebra_vty_init (void)
3814 {
3815 install_node (&ip_node, zebra_ip_config);
3816 install_node (&protocol_node, config_write_protocol);
3817
3818 install_element (CONFIG_NODE, &allow_external_route_update_cmd);
3819 install_element (CONFIG_NODE, &no_allow_external_route_update_cmd);
3820 install_element (CONFIG_NODE, &ip_mroute_dist_cmd);
3821 install_element (CONFIG_NODE, &no_ip_mroute_dist_cmd);
3822 install_element (CONFIG_NODE, &ip_multicast_mode_cmd);
3823 install_element (CONFIG_NODE, &no_ip_multicast_mode_cmd);
3824 install_element (CONFIG_NODE, &ip_route_cmd);
3825 install_element (CONFIG_NODE, &ip_route_flags_cmd);
3826 install_element (CONFIG_NODE, &ip_route_mask_cmd);
3827 install_element (CONFIG_NODE, &ip_route_mask_flags_cmd);
3828 install_element (CONFIG_NODE, &no_ip_route_cmd);
3829 install_element (CONFIG_NODE, &no_ip_route_mask_cmd);
3830 install_element (CONFIG_NODE, &ip_zebra_import_table_distance_cmd);
3831 install_element (CONFIG_NODE, &no_ip_zebra_import_table_cmd);
3832
3833 install_element (VIEW_NODE, &show_vrf_cmd);
3834 install_element (VIEW_NODE, &show_ip_route_cmd);
3835 install_element (VIEW_NODE, &show_ip_route_ospf_instance_cmd);
3836 install_element (VIEW_NODE, &show_ip_route_tag_cmd);
3837 install_element (VIEW_NODE, &show_ip_nht_cmd);
3838 install_element (VIEW_NODE, &show_ip_nht_vrf_all_cmd);
3839 install_element (VIEW_NODE, &show_ipv6_nht_cmd);
3840 install_element (VIEW_NODE, &show_ipv6_nht_vrf_all_cmd);
3841 install_element (VIEW_NODE, &show_ip_route_addr_cmd);
3842 install_element (VIEW_NODE, &show_ip_route_prefix_cmd);
3843 install_element (VIEW_NODE, &show_ip_route_prefix_longer_cmd);
3844 install_element (VIEW_NODE, &show_ip_route_protocol_cmd);
3845 install_element (VIEW_NODE, &show_ip_route_supernets_cmd);
3846 install_element (VIEW_NODE, &show_ip_route_summary_cmd);
3847 install_element (VIEW_NODE, &show_ip_route_summary_prefix_cmd);
3848
3849 install_element (VIEW_NODE, &show_ip_rpf_cmd);
3850 install_element (VIEW_NODE, &show_ip_rpf_addr_cmd);
3851
3852 /* Commands for VRF */
3853
3854 install_element (CONFIG_NODE, &no_ip_route_flags_cmd);
3855 install_element (CONFIG_NODE, &no_ip_route_mask_flags_cmd);
3856
3857 install_element (VIEW_NODE, &show_ip_route_vrf_cmd);
3858
3859 install_element (VIEW_NODE, &show_ip_route_vrf_all_cmd);
3860 install_element (VIEW_NODE, &show_ip_route_vrf_all_tag_cmd);
3861 install_element (VIEW_NODE, &show_ip_route_vrf_all_addr_cmd);
3862 install_element (VIEW_NODE, &show_ip_route_vrf_all_prefix_cmd);
3863 install_element (VIEW_NODE, &show_ip_route_vrf_all_prefix_longer_cmd);
3864 install_element (VIEW_NODE, &show_ip_route_vrf_all_protocol_cmd);
3865 install_element (VIEW_NODE, &show_ip_route_vrf_all_supernets_cmd);
3866 install_element (VIEW_NODE, &show_ip_route_vrf_all_summary_cmd);
3867 install_element (VIEW_NODE, &show_ip_route_vrf_all_summary_prefix_cmd);
3868
3869 install_element (CONFIG_NODE, &ipv6_route_cmd);
3870 install_element (CONFIG_NODE, &ipv6_route_flags_cmd);
3871 install_element (CONFIG_NODE, &ipv6_route_ifname_cmd);
3872 install_element (CONFIG_NODE, &ipv6_route_ifname_flags_cmd);
3873 install_element (CONFIG_NODE, &no_ipv6_route_cmd);
3874 install_element (CONFIG_NODE, &no_ipv6_route_flags_cmd);
3875 install_element (CONFIG_NODE, &no_ipv6_route_ifname_cmd);
3876 install_element (CONFIG_NODE, &no_ipv6_route_ifname_flags_cmd);
3877 install_element (CONFIG_NODE, &ip_nht_default_route_cmd);
3878 install_element (CONFIG_NODE, &no_ip_nht_default_route_cmd);
3879 install_element (CONFIG_NODE, &ipv6_nht_default_route_cmd);
3880 install_element (CONFIG_NODE, &no_ipv6_nht_default_route_cmd);
3881 install_element (VIEW_NODE, &show_ipv6_route_cmd);
3882 install_element (VIEW_NODE, &show_ipv6_route_tag_cmd);
3883 install_element (VIEW_NODE, &show_ipv6_route_summary_cmd);
3884 install_element (VIEW_NODE, &show_ipv6_route_summary_prefix_cmd);
3885 install_element (VIEW_NODE, &show_ipv6_route_protocol_cmd);
3886 install_element (VIEW_NODE, &show_ipv6_route_addr_cmd);
3887 install_element (VIEW_NODE, &show_ipv6_route_prefix_cmd);
3888 install_element (VIEW_NODE, &show_ipv6_route_prefix_longer_cmd);
3889
3890 install_element (VIEW_NODE, &show_ipv6_mroute_cmd);
3891
3892 /* Commands for VRF */
3893 install_element (VIEW_NODE, &show_ipv6_route_vrf_all_cmd);
3894 install_element (VIEW_NODE, &show_ipv6_route_vrf_all_tag_cmd);
3895 install_element (VIEW_NODE, &show_ipv6_route_vrf_all_summary_cmd);
3896 install_element (VIEW_NODE, &show_ipv6_route_vrf_all_summary_prefix_cmd);
3897 install_element (VIEW_NODE, &show_ipv6_route_vrf_all_protocol_cmd);
3898 install_element (VIEW_NODE, &show_ipv6_route_vrf_all_addr_cmd);
3899 install_element (VIEW_NODE, &show_ipv6_route_vrf_all_prefix_cmd);
3900 install_element (VIEW_NODE, &show_ipv6_route_vrf_all_prefix_longer_cmd);
3901
3902 install_element (VIEW_NODE, &show_ipv6_mroute_vrf_all_cmd);
3903 }