blob: 33368b612013eacc83bafaf6fac08146c40b036c [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* 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
Paul Jakma7514fb72007-05-02 16:05:35 +000024#include "memory.h"
paul718e3742002-12-13 20:15:29 +000025#include "if.h"
26#include "prefix.h"
27#include "command.h"
28#include "table.h"
29#include "rib.h"
Feng Lu41f44a22015-05-22 11:39:56 +020030#include "vrf.h"
paul718e3742002-12-13 20:15:29 +000031
paula1ac18c2005-06-28 17:17:12 +000032#include "zebra/zserv.h"
33
Feng Lu4364ee52015-05-22 11:40:03 +020034static int do_show_ip_route(struct vty *vty, safi_t safi, vrf_id_t vrf_id);
David Lamparter3b02fe82015-01-22 19:12:35 +010035static void vty_show_ip_route_detail (struct vty *vty, struct route_node *rn,
36 int mcast);
Feng Lu4364ee52015-05-22 11:40:03 +020037static void vty_show_ip_route (struct vty *vty, struct route_node *rn,
38 struct rib *rib);
Everton Marques33d86db2014-07-14 11:19:00 -030039
40/* General function for static route. */
paula1ac18c2005-06-28 17:17:12 +000041static int
Everton Marques33d86db2014-07-14 11:19:00 -030042zebra_static_ipv4_safi (struct vty *vty, safi_t safi, int add_cmd,
43 const char *dest_str, const char *mask_str,
44 const char *gate_str, const char *flag_str,
45 const char *distance_str)
paul718e3742002-12-13 20:15:29 +000046{
47 int ret;
48 u_char distance;
49 struct prefix p;
50 struct in_addr gate;
51 struct in_addr mask;
hasso39db97e2004-10-12 20:50:58 +000052 const char *ifname;
hasso81dfcaa2003-05-25 19:21:25 +000053 u_char flag = 0;
paul718e3742002-12-13 20:15:29 +000054
55 ret = str2prefix (dest_str, &p);
56 if (ret <= 0)
57 {
58 vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
59 return CMD_WARNING;
60 }
61
62 /* Cisco like mask notation. */
63 if (mask_str)
64 {
65 ret = inet_aton (mask_str, &mask);
66 if (ret == 0)
paul595db7f2003-05-25 21:35:06 +000067 {
68 vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
69 return CMD_WARNING;
70 }
paul718e3742002-12-13 20:15:29 +000071 p.prefixlen = ip_masklen (mask);
72 }
73
74 /* Apply mask for given prefix. */
75 apply_mask (&p);
76
paul595db7f2003-05-25 21:35:06 +000077 /* Administrative distance. */
78 if (distance_str)
79 distance = atoi (distance_str);
80 else
81 distance = ZEBRA_STATIC_DISTANCE_DEFAULT;
82
83 /* Null0 static route. */
hasso457ef552003-05-28 12:02:15 +000084 if ((gate_str != NULL) && (strncasecmp (gate_str, "Null0", strlen (gate_str)) == 0))
paul595db7f2003-05-25 21:35:06 +000085 {
86 if (flag_str)
87 {
88 vty_out (vty, "%% can not have flag %s with Null0%s", flag_str, VTY_NEWLINE);
89 return CMD_WARNING;
90 }
91 if (add_cmd)
Everton Marques33d86db2014-07-14 11:19:00 -030092 static_add_ipv4_safi (safi, &p, NULL, NULL, ZEBRA_FLAG_BLACKHOLE, distance, 0);
paul595db7f2003-05-25 21:35:06 +000093 else
Everton Marques33d86db2014-07-14 11:19:00 -030094 static_delete_ipv4_safi (safi, &p, NULL, NULL, distance, 0);
paul595db7f2003-05-25 21:35:06 +000095 return CMD_SUCCESS;
96 }
97
hasso81dfcaa2003-05-25 19:21:25 +000098 /* Route flags */
99 if (flag_str) {
100 switch(flag_str[0]) {
101 case 'r':
102 case 'R': /* XXX */
103 SET_FLAG (flag, ZEBRA_FLAG_REJECT);
104 break;
105 case 'b':
106 case 'B': /* XXX */
107 SET_FLAG (flag, ZEBRA_FLAG_BLACKHOLE);
108 break;
109 default:
110 vty_out (vty, "%% Malformed flag %s %s", flag_str, VTY_NEWLINE);
paul595db7f2003-05-25 21:35:06 +0000111 return CMD_WARNING;
hasso81dfcaa2003-05-25 19:21:25 +0000112 }
113 }
114
hasso457ef552003-05-28 12:02:15 +0000115 if (gate_str == NULL)
116 {
117 if (add_cmd)
Everton Marques33d86db2014-07-14 11:19:00 -0300118 static_add_ipv4_safi (safi, &p, NULL, NULL, flag, distance, 0);
hasso457ef552003-05-28 12:02:15 +0000119 else
Everton Marques33d86db2014-07-14 11:19:00 -0300120 static_delete_ipv4_safi (safi, &p, NULL, NULL, distance, 0);
hasso457ef552003-05-28 12:02:15 +0000121
122 return CMD_SUCCESS;
123 }
124
paul718e3742002-12-13 20:15:29 +0000125 /* When gateway is A.B.C.D format, gate is treated as nexthop
126 address other case gate is treated as interface name. */
127 ret = inet_aton (gate_str, &gate);
128 if (ret)
129 ifname = NULL;
130 else
131 ifname = gate_str;
132
133 if (add_cmd)
Everton Marques33d86db2014-07-14 11:19:00 -0300134 static_add_ipv4_safi (safi, &p, ifname ? NULL : &gate, ifname, flag, distance, 0);
paul718e3742002-12-13 20:15:29 +0000135 else
Everton Marques33d86db2014-07-14 11:19:00 -0300136 static_delete_ipv4_safi (safi, &p, ifname ? NULL : &gate, ifname, distance, 0);
paul718e3742002-12-13 20:15:29 +0000137
138 return CMD_SUCCESS;
139}
140
Everton Marques33d86db2014-07-14 11:19:00 -0300141static int
142zebra_static_ipv4 (struct vty *vty, int add_cmd, const char *dest_str,
143 const char *mask_str, const char *gate_str,
144 const char *flag_str, const char *distance_str)
145{
146 return zebra_static_ipv4_safi(vty, SAFI_UNICAST, add_cmd, dest_str, mask_str, gate_str, flag_str, distance_str);
147}
148
149/* Static unicast routes for multicast RPF lookup. */
David Lampartera76681b2015-01-22 19:03:53 +0100150DEFUN (ip_mroute_dist,
151 ip_mroute_dist_cmd,
152 "ip mroute A.B.C.D/M (A.B.C.D|INTERFACE) <1-255>",
Everton Marques33d86db2014-07-14 11:19:00 -0300153 IP_STR
154 "Configure static unicast route into MRIB for multicast RPF lookup\n"
155 "IP destination prefix (e.g. 10.0.0.0/8)\n"
156 "Nexthop address\n"
157 "Nexthop interface name\n"
158 "Distance\n")
159{
David Lamparter863f20c2015-01-27 20:24:15 +0100160 VTY_WARN_EXPERIMENTAL();
David Lampartera76681b2015-01-22 19:03:53 +0100161 return zebra_static_ipv4_safi(vty, SAFI_MULTICAST, 1, argv[0], NULL, argv[1],
162 NULL, argc > 2 ? argv[2] : NULL);
Everton Marques33d86db2014-07-14 11:19:00 -0300163}
164
David Lampartera76681b2015-01-22 19:03:53 +0100165ALIAS (ip_mroute_dist,
166 ip_mroute_cmd,
167 "ip mroute A.B.C.D/M (A.B.C.D|INTERFACE)",
168 IP_STR
169 "Configure static unicast route into MRIB for multicast RPF lookup\n"
170 "IP destination prefix (e.g. 10.0.0.0/8)\n"
171 "Nexthop address\n"
172 "Nexthop interface name\n")
173
174DEFUN (no_ip_mroute_dist,
175 no_ip_mroute_dist_cmd,
176 "no ip mroute A.B.C.D/M (A.B.C.D|INTERFACE) <1-255>",
Everton Marques33d86db2014-07-14 11:19:00 -0300177 IP_STR
178 "Configure static unicast route into MRIB for multicast RPF lookup\n"
179 "IP destination prefix (e.g. 10.0.0.0/8)\n"
180 "Nexthop address\n"
181 "Nexthop interface name\n"
182 "Distance\n")
183{
David Lamparter863f20c2015-01-27 20:24:15 +0100184 VTY_WARN_EXPERIMENTAL();
David Lampartera76681b2015-01-22 19:03:53 +0100185 return zebra_static_ipv4_safi(vty, SAFI_MULTICAST, 0, argv[0], NULL, argv[1],
186 NULL, argc > 2 ? argv[2] : NULL);
Everton Marques33d86db2014-07-14 11:19:00 -0300187}
188
David Lampartera76681b2015-01-22 19:03:53 +0100189ALIAS (no_ip_mroute_dist,
190 no_ip_mroute_cmd,
191 "no ip mroute A.B.C.D/M (A.B.C.D|INTERFACE)",
192 NO_STR
193 IP_STR
194 "Configure static unicast route into MRIB for multicast RPF lookup\n"
195 "IP destination prefix (e.g. 10.0.0.0/8)\n"
196 "Nexthop address\n"
197 "Nexthop interface name\n")
198
David Lamparterbd078122015-01-06 19:53:24 +0100199DEFUN (ip_multicast_mode,
200 ip_multicast_mode_cmd,
201 "ip multicast rpf-lookup-mode (urib-only|mrib-only|mrib-then-urib|lower-distance|longer-prefix)",
202 IP_STR
203 "Multicast options\n"
204 "RPF lookup behavior\n"
205 "Lookup in unicast RIB only\n"
206 "Lookup in multicast RIB only\n"
207 "Try multicast RIB first, fall back to unicast RIB\n"
208 "Lookup both, use entry with lower distance\n"
209 "Lookup both, use entry with longer prefix\n")
210{
David Lamparter863f20c2015-01-27 20:24:15 +0100211 VTY_WARN_EXPERIMENTAL();
212
David Lamparterbd078122015-01-06 19:53:24 +0100213 if (!strncmp (argv[0], "u", 1))
214 multicast_mode_ipv4_set (MCAST_URIB_ONLY);
215 else if (!strncmp (argv[0], "mrib-o", 6))
216 multicast_mode_ipv4_set (MCAST_MRIB_ONLY);
217 else if (!strncmp (argv[0], "mrib-t", 6))
218 multicast_mode_ipv4_set (MCAST_MIX_MRIB_FIRST);
219 else if (!strncmp (argv[0], "low", 3))
220 multicast_mode_ipv4_set (MCAST_MIX_DISTANCE);
221 else if (!strncmp (argv[0], "lon", 3))
222 multicast_mode_ipv4_set (MCAST_MIX_PFXLEN);
223 else
224 {
225 vty_out (vty, "Invalid mode specified%s", VTY_NEWLINE);
226 return CMD_WARNING;
227 }
228
229 return CMD_SUCCESS;
230}
231
232DEFUN (no_ip_multicast_mode,
233 no_ip_multicast_mode_cmd,
234 "no ip multicast rpf-lookup-mode (urib-only|mrib-only|mrib-then-urib|lower-distance|longer-prefix)",
235 NO_STR
236 IP_STR
237 "Multicast options\n"
238 "RPF lookup behavior\n"
239 "Lookup in unicast RIB only\n"
240 "Lookup in multicast RIB only\n"
241 "Try multicast RIB first, fall back to unicast RIB\n"
242 "Lookup both, use entry with lower distance\n"
243 "Lookup both, use entry with longer prefix\n")
244{
245 multicast_mode_ipv4_set (MCAST_NO_CONFIG);
246 return CMD_SUCCESS;
247}
248
249ALIAS (no_ip_multicast_mode,
250 no_ip_multicast_mode_noarg_cmd,
251 "no ip multicast rpf-lookup-mode",
252 NO_STR
253 IP_STR
254 "Multicast options\n"
255 "RPF lookup behavior\n")
256
Everton Marques33d86db2014-07-14 11:19:00 -0300257DEFUN (show_ip_rpf,
258 show_ip_rpf_cmd,
259 "show ip rpf",
260 SHOW_STR
261 IP_STR
262 "Display RPF information for multicast source\n")
263{
Feng Lu4364ee52015-05-22 11:40:03 +0200264 vrf_id_t vrf_id = VRF_DEFAULT;
265
266 if (argc > 0)
267 VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
268
David Lamparter863f20c2015-01-27 20:24:15 +0100269 VTY_WARN_EXPERIMENTAL();
Feng Lu4364ee52015-05-22 11:40:03 +0200270 return do_show_ip_route(vty, SAFI_MULTICAST, vrf_id);
Everton Marques33d86db2014-07-14 11:19:00 -0300271}
272
Feng Lu4364ee52015-05-22 11:40:03 +0200273ALIAS (show_ip_rpf,
274 show_ip_rpf_vrf_cmd,
275 "show ip rpf " VRF_CMD_STR,
276 SHOW_STR
277 IP_STR
278 "Display RPF information for multicast source\n"
279 VRF_CMD_HELP_STR)
280
David Lamparter3b02fe82015-01-22 19:12:35 +0100281DEFUN (show_ip_rpf_addr,
282 show_ip_rpf_addr_cmd,
283 "show ip rpf A.B.C.D",
284 SHOW_STR
285 IP_STR
286 "Display RPF information for multicast source\n"
287 "IP multicast source address (e.g. 10.0.0.0)\n")
288{
289 struct in_addr addr;
290 struct route_node *rn;
291 struct rib *rib;
Feng Lu4364ee52015-05-22 11:40:03 +0200292 vrf_id_t vrf_id = VRF_DEFAULT;
293 int ret;
294
295 if (argc > 1)
296 VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]);
297
298 VTY_WARN_EXPERIMENTAL();
299
300 ret = inet_aton (argv[0], &addr);
301 if (ret == 0)
302 {
303 vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
304 return CMD_WARNING;
305 }
306
307 rib = rib_match_ipv4_multicast (addr, &rn, vrf_id);
308
309 if (rib)
310 vty_show_ip_route_detail (vty, rn, 1);
311 else
312 vty_out (vty, "%% No match for RPF lookup%s", VTY_NEWLINE);
313
314 return CMD_SUCCESS;
315}
316
317ALIAS (show_ip_rpf_addr,
318 show_ip_rpf_addr_vrf_cmd,
319 "show ip rpf A.B.C.D " VRF_CMD_STR,
320 SHOW_STR
321 IP_STR
322 "Display RPF information for multicast source\n"
323 "IP multicast source address (e.g. 10.0.0.0)\n"
324 VRF_CMD_HELP_STR)
325
326DEFUN (show_ip_rpf_vrf_all,
327 show_ip_rpf_vrf_all_cmd,
328 "show ip rpf " VRF_ALL_CMD_STR,
329 SHOW_STR
330 IP_STR
331 "Display RPF information for multicast source\n"
332 VRF_ALL_CMD_HELP_STR)
333{
334 struct zebra_vrf *zvrf;
335 struct route_table *table;
336 struct route_node *rn;
337 struct rib *rib;
338 vrf_iter_t iter;
339 int first = 1;
340
341 VTY_WARN_EXPERIMENTAL();
342
343 for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
344 {
345 if ((zvrf = vrf_iter2info (iter)) == NULL ||
346 (table = zvrf->table[AFI_IP][SAFI_MULTICAST]) == NULL)
347 continue;
348
349 /* Show all IPv4 routes. */
350 for (rn = route_top (table); rn; rn = route_next (rn))
351 RNODE_FOREACH_RIB (rn, rib)
352 {
353 if (first)
354 {
355 vty_out (vty, SHOW_ROUTE_V4_HEADER);
356 first = 0;
357 }
358 vty_show_ip_route (vty, rn, rib);
359 }
360 }
361
362 return CMD_SUCCESS;
363}
364
365DEFUN (show_ip_rpf_addr_vrf_all,
366 show_ip_rpf_addr_vrf_all_cmd,
367 "show ip rpf A.B.C.D " VRF_ALL_CMD_STR,
368 SHOW_STR
369 IP_STR
370 "Display RPF information for multicast source\n"
371 "IP multicast source address (e.g. 10.0.0.0)\n"
372 VRF_ALL_CMD_HELP_STR)
373{
374 struct in_addr addr;
375 struct route_node *rn;
376 vrf_iter_t iter;
David Lamparter3b02fe82015-01-22 19:12:35 +0100377 int ret;
378
David Lamparter863f20c2015-01-27 20:24:15 +0100379 VTY_WARN_EXPERIMENTAL();
380
David Lamparter3b02fe82015-01-22 19:12:35 +0100381 ret = inet_aton (argv[0], &addr);
382 if (ret == 0)
383 {
384 vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
385 return CMD_WARNING;
386 }
387
Feng Lu4364ee52015-05-22 11:40:03 +0200388 for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
389 {
390 if (rib_match_ipv4_multicast (addr, &rn, vrf_iter2id (iter)))
391 vty_show_ip_route_detail (vty, rn, 1);
392 }
David Lamparter3b02fe82015-01-22 19:12:35 +0100393
394 return CMD_SUCCESS;
395}
396
paul718e3742002-12-13 20:15:29 +0000397/* Static route configuration. */
398DEFUN (ip_route,
399 ip_route_cmd,
paul595db7f2003-05-25 21:35:06 +0000400 "ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0)",
hasso81dfcaa2003-05-25 19:21:25 +0000401 IP_STR
402 "Establish static routes\n"
403 "IP destination prefix (e.g. 10.0.0.0/8)\n"
404 "IP gateway address\n"
paul595db7f2003-05-25 21:35:06 +0000405 "IP gateway interface name\n"
406 "Null interface\n")
hasso81dfcaa2003-05-25 19:21:25 +0000407{
408 return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], NULL, NULL);
409}
410
411DEFUN (ip_route_flags,
412 ip_route_flags_cmd,
413 "ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole)",
paul718e3742002-12-13 20:15:29 +0000414 IP_STR
415 "Establish static routes\n"
416 "IP destination prefix (e.g. 10.0.0.0/8)\n"
417 "IP gateway address\n"
418 "IP gateway interface name\n"
hasso81dfcaa2003-05-25 19:21:25 +0000419 "Emit an ICMP unreachable when matched\n"
420 "Silently discard pkts when matched\n")
paul718e3742002-12-13 20:15:29 +0000421{
hasso81dfcaa2003-05-25 19:21:25 +0000422 return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], argv[2], NULL);
paul718e3742002-12-13 20:15:29 +0000423}
424
hasso457ef552003-05-28 12:02:15 +0000425DEFUN (ip_route_flags2,
426 ip_route_flags2_cmd,
427 "ip route A.B.C.D/M (reject|blackhole)",
428 IP_STR
429 "Establish static routes\n"
430 "IP destination prefix (e.g. 10.0.0.0/8)\n"
431 "Emit an ICMP unreachable when matched\n"
432 "Silently discard pkts when matched\n")
433{
434 return zebra_static_ipv4 (vty, 1, argv[0], NULL, NULL, argv[1], NULL);
435}
436
paul718e3742002-12-13 20:15:29 +0000437/* Mask as A.B.C.D format. */
438DEFUN (ip_route_mask,
439 ip_route_mask_cmd,
paul595db7f2003-05-25 21:35:06 +0000440 "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0)",
hasso81dfcaa2003-05-25 19:21:25 +0000441 IP_STR
442 "Establish static routes\n"
443 "IP destination prefix\n"
444 "IP destination prefix mask\n"
445 "IP gateway address\n"
paul595db7f2003-05-25 21:35:06 +0000446 "IP gateway interface name\n"
447 "Null interface\n")
hasso81dfcaa2003-05-25 19:21:25 +0000448{
449 return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], NULL, NULL);
450}
451
452DEFUN (ip_route_mask_flags,
453 ip_route_mask_flags_cmd,
454 "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole)",
paul718e3742002-12-13 20:15:29 +0000455 IP_STR
456 "Establish static routes\n"
457 "IP destination prefix\n"
458 "IP destination prefix mask\n"
459 "IP gateway address\n"
460 "IP gateway interface name\n"
hasso81dfcaa2003-05-25 19:21:25 +0000461 "Emit an ICMP unreachable when matched\n"
462 "Silently discard pkts when matched\n")
paul718e3742002-12-13 20:15:29 +0000463{
hasso81dfcaa2003-05-25 19:21:25 +0000464 return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], argv[3], NULL);
paul718e3742002-12-13 20:15:29 +0000465}
466
hasso457ef552003-05-28 12:02:15 +0000467DEFUN (ip_route_mask_flags2,
468 ip_route_mask_flags2_cmd,
469 "ip route A.B.C.D A.B.C.D (reject|blackhole)",
470 IP_STR
471 "Establish static routes\n"
472 "IP destination prefix\n"
473 "IP destination prefix mask\n"
474 "Emit an ICMP unreachable when matched\n"
475 "Silently discard pkts when matched\n")
476{
477 return zebra_static_ipv4 (vty, 1, argv[0], argv[1], NULL, argv[2], NULL);
478}
479
paul718e3742002-12-13 20:15:29 +0000480/* Distance option value. */
481DEFUN (ip_route_distance,
482 ip_route_distance_cmd,
paul595db7f2003-05-25 21:35:06 +0000483 "ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0) <1-255>",
paul718e3742002-12-13 20:15:29 +0000484 IP_STR
485 "Establish static routes\n"
486 "IP destination prefix (e.g. 10.0.0.0/8)\n"
487 "IP gateway address\n"
488 "IP gateway interface name\n"
paul595db7f2003-05-25 21:35:06 +0000489 "Null interface\n"
paul718e3742002-12-13 20:15:29 +0000490 "Distance value for this route\n")
491{
hasso81dfcaa2003-05-25 19:21:25 +0000492 return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], NULL, argv[2]);
493}
494
495DEFUN (ip_route_flags_distance,
496 ip_route_flags_distance_cmd,
497 "ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
498 IP_STR
499 "Establish static routes\n"
500 "IP destination prefix (e.g. 10.0.0.0/8)\n"
501 "IP gateway address\n"
502 "IP gateway interface name\n"
503 "Emit an ICMP unreachable when matched\n"
504 "Silently discard pkts when matched\n"
505 "Distance value for this route\n")
506{
507 return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], argv[2], argv[3]);
paul718e3742002-12-13 20:15:29 +0000508}
509
hasso457ef552003-05-28 12:02:15 +0000510DEFUN (ip_route_flags_distance2,
511 ip_route_flags_distance2_cmd,
512 "ip route A.B.C.D/M (reject|blackhole) <1-255>",
513 IP_STR
514 "Establish static routes\n"
515 "IP destination prefix (e.g. 10.0.0.0/8)\n"
516 "Emit an ICMP unreachable when matched\n"
517 "Silently discard pkts when matched\n"
518 "Distance value for this route\n")
519{
520 return zebra_static_ipv4 (vty, 1, argv[0], NULL, NULL, argv[1], argv[2]);
521}
522
paul718e3742002-12-13 20:15:29 +0000523DEFUN (ip_route_mask_distance,
524 ip_route_mask_distance_cmd,
paul595db7f2003-05-25 21:35:06 +0000525 "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0) <1-255>",
paul718e3742002-12-13 20:15:29 +0000526 IP_STR
527 "Establish static routes\n"
528 "IP destination prefix\n"
529 "IP destination prefix mask\n"
530 "IP gateway address\n"
531 "IP gateway interface name\n"
paul595db7f2003-05-25 21:35:06 +0000532 "Null interface\n"
paul718e3742002-12-13 20:15:29 +0000533 "Distance value for this route\n")
534{
hasso81dfcaa2003-05-25 19:21:25 +0000535 return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], NULL, argv[3]);
536}
537
538DEFUN (ip_route_mask_flags_distance,
539 ip_route_mask_flags_distance_cmd,
540 "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
541 IP_STR
542 "Establish static routes\n"
543 "IP destination prefix\n"
544 "IP destination prefix mask\n"
545 "IP gateway address\n"
546 "IP gateway interface name\n"
hasso81dfcaa2003-05-25 19:21:25 +0000547 "Emit an ICMP unreachable when matched\n"
Christian Franke2b005152013-09-30 12:27:49 +0000548 "Silently discard pkts when matched\n"
549 "Distance value for this route\n")
hasso81dfcaa2003-05-25 19:21:25 +0000550{
551 return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], argv[3], argv[4]);
paul718e3742002-12-13 20:15:29 +0000552}
553
hasso457ef552003-05-28 12:02:15 +0000554DEFUN (ip_route_mask_flags_distance2,
555 ip_route_mask_flags_distance2_cmd,
556 "ip route A.B.C.D A.B.C.D (reject|blackhole) <1-255>",
557 IP_STR
558 "Establish static routes\n"
559 "IP destination prefix\n"
560 "IP destination prefix mask\n"
hasso457ef552003-05-28 12:02:15 +0000561 "Emit an ICMP unreachable when matched\n"
Christian Franke2b005152013-09-30 12:27:49 +0000562 "Silently discard pkts when matched\n"
563 "Distance value for this route\n")
hasso457ef552003-05-28 12:02:15 +0000564{
565 return zebra_static_ipv4 (vty, 1, argv[0], argv[1], NULL, argv[2], argv[3]);
566}
567
paul718e3742002-12-13 20:15:29 +0000568DEFUN (no_ip_route,
569 no_ip_route_cmd,
paul595db7f2003-05-25 21:35:06 +0000570 "no ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0)",
hasso81dfcaa2003-05-25 19:21:25 +0000571 NO_STR
572 IP_STR
573 "Establish static routes\n"
574 "IP destination prefix (e.g. 10.0.0.0/8)\n"
575 "IP gateway address\n"
paul595db7f2003-05-25 21:35:06 +0000576 "IP gateway interface name\n"
577 "Null interface\n")
hasso81dfcaa2003-05-25 19:21:25 +0000578{
579 return zebra_static_ipv4 (vty, 0, argv[0], NULL, argv[1], NULL, NULL);
580}
581
582ALIAS (no_ip_route,
583 no_ip_route_flags_cmd,
584 "no ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole)",
paul718e3742002-12-13 20:15:29 +0000585 NO_STR
586 IP_STR
587 "Establish static routes\n"
588 "IP destination prefix (e.g. 10.0.0.0/8)\n"
589 "IP gateway address\n"
590 "IP gateway interface name\n"
hasso81dfcaa2003-05-25 19:21:25 +0000591 "Emit an ICMP unreachable when matched\n"
592 "Silently discard pkts when matched\n")
paul718e3742002-12-13 20:15:29 +0000593
hasso457ef552003-05-28 12:02:15 +0000594DEFUN (no_ip_route_flags2,
595 no_ip_route_flags2_cmd,
596 "no ip route A.B.C.D/M (reject|blackhole)",
597 NO_STR
598 IP_STR
599 "Establish static routes\n"
600 "IP destination prefix (e.g. 10.0.0.0/8)\n"
601 "Emit an ICMP unreachable when matched\n"
602 "Silently discard pkts when matched\n")
603{
604 return zebra_static_ipv4 (vty, 0, argv[0], NULL, NULL, NULL, NULL);
605}
606
paul718e3742002-12-13 20:15:29 +0000607DEFUN (no_ip_route_mask,
608 no_ip_route_mask_cmd,
paul595db7f2003-05-25 21:35:06 +0000609 "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0)",
hasso81dfcaa2003-05-25 19:21:25 +0000610 NO_STR
611 IP_STR
612 "Establish static routes\n"
613 "IP destination prefix\n"
614 "IP destination prefix mask\n"
615 "IP gateway address\n"
paul595db7f2003-05-25 21:35:06 +0000616 "IP gateway interface name\n"
617 "Null interface\n")
hasso81dfcaa2003-05-25 19:21:25 +0000618{
619 return zebra_static_ipv4 (vty, 0, argv[0], argv[1], argv[2], NULL, NULL);
620}
621
622ALIAS (no_ip_route_mask,
623 no_ip_route_mask_flags_cmd,
624 "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole)",
paul718e3742002-12-13 20:15:29 +0000625 NO_STR
626 IP_STR
627 "Establish static routes\n"
628 "IP destination prefix\n"
629 "IP destination prefix mask\n"
630 "IP gateway address\n"
631 "IP gateway interface name\n"
hasso81dfcaa2003-05-25 19:21:25 +0000632 "Emit an ICMP unreachable when matched\n"
633 "Silently discard pkts when matched\n")
paul718e3742002-12-13 20:15:29 +0000634
hasso457ef552003-05-28 12:02:15 +0000635DEFUN (no_ip_route_mask_flags2,
636 no_ip_route_mask_flags2_cmd,
637 "no ip route A.B.C.D A.B.C.D (reject|blackhole)",
638 NO_STR
639 IP_STR
640 "Establish static routes\n"
641 "IP destination prefix\n"
642 "IP destination prefix mask\n"
643 "Emit an ICMP unreachable when matched\n"
644 "Silently discard pkts when matched\n")
645{
646 return zebra_static_ipv4 (vty, 0, argv[0], argv[1], NULL, NULL, NULL);
647}
648
paul718e3742002-12-13 20:15:29 +0000649DEFUN (no_ip_route_distance,
650 no_ip_route_distance_cmd,
paul595db7f2003-05-25 21:35:06 +0000651 "no ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0) <1-255>",
paul718e3742002-12-13 20:15:29 +0000652 NO_STR
653 IP_STR
654 "Establish static routes\n"
655 "IP destination prefix (e.g. 10.0.0.0/8)\n"
656 "IP gateway address\n"
657 "IP gateway interface name\n"
paul595db7f2003-05-25 21:35:06 +0000658 "Null interface\n"
paul718e3742002-12-13 20:15:29 +0000659 "Distance value for this route\n")
660{
hasso81dfcaa2003-05-25 19:21:25 +0000661 return zebra_static_ipv4 (vty, 0, argv[0], NULL, argv[1], NULL, argv[2]);
662}
663
664DEFUN (no_ip_route_flags_distance,
665 no_ip_route_flags_distance_cmd,
666 "no ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
667 NO_STR
668 IP_STR
669 "Establish static routes\n"
670 "IP destination prefix (e.g. 10.0.0.0/8)\n"
671 "IP gateway address\n"
672 "IP gateway interface name\n"
673 "Emit an ICMP unreachable when matched\n"
674 "Silently discard pkts when matched\n"
675 "Distance value for this route\n")
676{
677 return zebra_static_ipv4 (vty, 0, argv[0], NULL, argv[1], argv[2], argv[3]);
paul718e3742002-12-13 20:15:29 +0000678}
679
hasso457ef552003-05-28 12:02:15 +0000680DEFUN (no_ip_route_flags_distance2,
681 no_ip_route_flags_distance2_cmd,
682 "no ip route A.B.C.D/M (reject|blackhole) <1-255>",
683 NO_STR
684 IP_STR
685 "Establish static routes\n"
686 "IP destination prefix (e.g. 10.0.0.0/8)\n"
687 "Emit an ICMP unreachable when matched\n"
688 "Silently discard pkts when matched\n"
689 "Distance value for this route\n")
690{
691 return zebra_static_ipv4 (vty, 0, argv[0], NULL, NULL, argv[1], argv[2]);
692}
693
paul718e3742002-12-13 20:15:29 +0000694DEFUN (no_ip_route_mask_distance,
695 no_ip_route_mask_distance_cmd,
paul595db7f2003-05-25 21:35:06 +0000696 "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0) <1-255>",
paul718e3742002-12-13 20:15:29 +0000697 NO_STR
698 IP_STR
699 "Establish static routes\n"
700 "IP destination prefix\n"
701 "IP destination prefix mask\n"
702 "IP gateway address\n"
703 "IP gateway interface name\n"
paul595db7f2003-05-25 21:35:06 +0000704 "Null interface\n"
paul718e3742002-12-13 20:15:29 +0000705 "Distance value for this route\n")
706{
hasso81dfcaa2003-05-25 19:21:25 +0000707 return zebra_static_ipv4 (vty, 0, argv[0], argv[1], argv[2], NULL, argv[3]);
708}
709
710DEFUN (no_ip_route_mask_flags_distance,
711 no_ip_route_mask_flags_distance_cmd,
712 "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
713 NO_STR
714 IP_STR
715 "Establish static routes\n"
716 "IP destination prefix\n"
717 "IP destination prefix mask\n"
718 "IP gateway address\n"
719 "IP gateway interface name\n"
720 "Emit an ICMP unreachable when matched\n"
721 "Silently discard pkts when matched\n"
722 "Distance value for this route\n")
723{
724 return zebra_static_ipv4 (vty, 0, argv[0], argv[1], argv[2], argv[3], argv[4]);
paul718e3742002-12-13 20:15:29 +0000725}
726
hasso457ef552003-05-28 12:02:15 +0000727DEFUN (no_ip_route_mask_flags_distance2,
728 no_ip_route_mask_flags_distance2_cmd,
729 "no ip route A.B.C.D A.B.C.D (reject|blackhole) <1-255>",
730 NO_STR
731 IP_STR
732 "Establish static routes\n"
733 "IP destination prefix\n"
734 "IP destination prefix mask\n"
735 "Emit an ICMP unreachable when matched\n"
736 "Silently discard pkts when matched\n"
737 "Distance value for this route\n")
738{
739 return zebra_static_ipv4 (vty, 0, argv[0], argv[1], NULL, argv[2], argv[3]);
740}
741
Paul Jakma7514fb72007-05-02 16:05:35 +0000742char *proto_rm[AFI_MAX][ZEBRA_ROUTE_MAX+1]; /* "any" == ZEBRA_ROUTE_MAX */
743
744DEFUN (ip_protocol,
745 ip_protocol_cmd,
746 "ip protocol PROTO route-map ROUTE-MAP",
747 NO_STR
748 "Apply route map to PROTO\n"
749 "Protocol name\n"
750 "Route map name\n")
751{
752 int i;
753
754 if (strcasecmp(argv[0], "any") == 0)
755 i = ZEBRA_ROUTE_MAX;
756 else
757 i = proto_name2num(argv[0]);
758 if (i < 0)
759 {
760 vty_out (vty, "invalid protocol name \"%s\"%s", argv[0] ? argv[0] : "",
761 VTY_NEWLINE);
762 return CMD_WARNING;
763 }
764 if (proto_rm[AFI_IP][i])
765 XFREE (MTYPE_ROUTE_MAP_NAME, proto_rm[AFI_IP][i]);
766 proto_rm[AFI_IP][i] = XSTRDUP (MTYPE_ROUTE_MAP_NAME, argv[1]);
767 return CMD_SUCCESS;
768}
769
770DEFUN (no_ip_protocol,
771 no_ip_protocol_cmd,
772 "no ip protocol PROTO",
773 NO_STR
774 "Remove route map from PROTO\n"
775 "Protocol name\n")
776{
777 int i;
778
779 if (strcasecmp(argv[0], "any") == 0)
780 i = ZEBRA_ROUTE_MAX;
781 else
782 i = proto_name2num(argv[0]);
783 if (i < 0)
784 {
785 vty_out (vty, "invalid protocol name \"%s\"%s", argv[0] ? argv[0] : "",
786 VTY_NEWLINE);
787 return CMD_WARNING;
788 }
789 if (proto_rm[AFI_IP][i])
790 XFREE (MTYPE_ROUTE_MAP_NAME, proto_rm[AFI_IP][i]);
791 proto_rm[AFI_IP][i] = NULL;
792 return CMD_SUCCESS;
793}
794
paul718e3742002-12-13 20:15:29 +0000795/* New RIB. Detailed information for IPv4 route. */
paula1ac18c2005-06-28 17:17:12 +0000796static void
David Lamparter3b02fe82015-01-22 19:12:35 +0100797vty_show_ip_route_detail (struct vty *vty, struct route_node *rn, int mcast)
paul718e3742002-12-13 20:15:29 +0000798{
799 struct rib *rib;
Christian Frankefa713d92013-07-05 15:35:37 +0000800 struct nexthop *nexthop, *tnexthop;
801 int recursing;
Timo Teräs53a5c392015-05-23 11:08:40 +0300802 char buf[PREFIX_STRLEN];
paul718e3742002-12-13 20:15:29 +0000803
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000804 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +0000805 {
David Lamparterb7cce952015-03-07 08:40:48 +0100806 const char *mcast_info = "";
David Lamparter3b02fe82015-01-22 19:12:35 +0100807 if (mcast)
808 {
809 rib_table_info_t *info = rn->table->info;
810 mcast_info = (info->safi == SAFI_MULTICAST)
811 ? " using Multicast RIB"
812 : " using Unicast RIB";
813 }
Timo Teräs53a5c392015-05-23 11:08:40 +0300814 vty_out (vty, "Routing entry for %s%s%s",
815 prefix2str (&rn->p, buf, sizeof(buf)), mcast_info,
816 VTY_NEWLINE);
ajsf52d13c2005-10-01 17:38:06 +0000817 vty_out (vty, " Known via \"%s\"", zebra_route_string (rib->type));
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +0200818 vty_out (vty, ", distance %u, metric %u", rib->distance, rib->metric);
Feng Lu4364ee52015-05-22 11:40:03 +0200819 vty_out (vty, ", vrf %u", rib->vrf_id);
paul718e3742002-12-13 20:15:29 +0000820 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
Timo Teräs53a5c392015-05-23 11:08:40 +0300821 vty_out (vty, ", best");
paul718e3742002-12-13 20:15:29 +0000822 if (rib->refcnt)
Timo Teräs53a5c392015-05-23 11:08:40 +0300823 vty_out (vty, ", refcnt %ld", rib->refcnt);
hasso81dfcaa2003-05-25 19:21:25 +0000824 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
825 vty_out (vty, ", blackhole");
826 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT))
827 vty_out (vty, ", reject");
paul718e3742002-12-13 20:15:29 +0000828 vty_out (vty, "%s", VTY_NEWLINE);
829
830#define ONE_DAY_SECOND 60*60*24
831#define ONE_WEEK_SECOND 60*60*24*7
832 if (rib->type == ZEBRA_ROUTE_RIP
Timo Teräs53a5c392015-05-23 11:08:40 +0300833 || rib->type == ZEBRA_ROUTE_RIPNG
834 || rib->type == ZEBRA_ROUTE_OSPF
835 || rib->type == ZEBRA_ROUTE_OSPF6
836 || rib->type == ZEBRA_ROUTE_BABEL
837 || rib->type == ZEBRA_ROUTE_ISIS
838 || rib->type == ZEBRA_ROUTE_BGP)
paul718e3742002-12-13 20:15:29 +0000839 {
840 time_t uptime;
841 struct tm *tm;
842
843 uptime = time (NULL);
844 uptime -= rib->uptime;
845 tm = gmtime (&uptime);
846
847 vty_out (vty, " Last update ");
848
849 if (uptime < ONE_DAY_SECOND)
850 vty_out (vty, "%02d:%02d:%02d",
851 tm->tm_hour, tm->tm_min, tm->tm_sec);
852 else if (uptime < ONE_WEEK_SECOND)
853 vty_out (vty, "%dd%02dh%02dm",
854 tm->tm_yday, tm->tm_hour, tm->tm_min);
855 else
856 vty_out (vty, "%02dw%dd%02dh",
857 tm->tm_yday/7,
858 tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
859 vty_out (vty, " ago%s", VTY_NEWLINE);
860 }
861
Christian Frankefa713d92013-07-05 15:35:37 +0000862 for (ALL_NEXTHOPS_RO(rib->nexthop, nexthop, tnexthop, recursing))
Timo Teräs53a5c392015-05-23 11:08:40 +0300863 {
864 vty_out (vty, " %c%s",
865 CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB) ? '*' : ' ',
866 recursing ? " " : "");
Paul Jakma7514fb72007-05-02 16:05:35 +0000867
Timo Teräs53a5c392015-05-23 11:08:40 +0300868 switch (nexthop->type)
869 {
870 case NEXTHOP_TYPE_IPV4:
871 case NEXTHOP_TYPE_IPV4_IFINDEX:
872 vty_out (vty, " %s", inet_ntoa (nexthop->gate.ipv4));
873 if (nexthop->ifindex)
Feng Lu0d0686f2015-05-22 11:40:02 +0200874 vty_out (vty, ", via %s",
875 ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id));
Timo Teräs53a5c392015-05-23 11:08:40 +0300876 break;
877 case NEXTHOP_TYPE_IPV6:
878 case NEXTHOP_TYPE_IPV6_IFINDEX:
879 case NEXTHOP_TYPE_IPV6_IFNAME:
880 vty_out (vty, " %s",
881 inet_ntop (AF_INET6, &nexthop->gate.ipv6, buf, sizeof(buf)));
882 if (nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME)
883 vty_out (vty, ", %s", nexthop->ifname);
884 else if (nexthop->ifindex)
Feng Lu0d0686f2015-05-22 11:40:02 +0200885 vty_out (vty, ", via %s",
886 ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id));
Timo Teräs53a5c392015-05-23 11:08:40 +0300887 break;
888 case NEXTHOP_TYPE_IFINDEX:
889 vty_out (vty, " directly connected, %s",
Feng Lu0d0686f2015-05-22 11:40:02 +0200890 ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id));
Timo Teräs53a5c392015-05-23 11:08:40 +0300891 break;
892 case NEXTHOP_TYPE_IFNAME:
893 vty_out (vty, " directly connected, %s", nexthop->ifname);
894 break;
895 case NEXTHOP_TYPE_BLACKHOLE:
896 vty_out (vty, " directly connected, Null0");
897 break;
898 default:
899 break;
900 }
901 if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
902 vty_out (vty, " inactive");
paul718e3742002-12-13 20:15:29 +0000903
Timo Teräs53a5c392015-05-23 11:08:40 +0300904 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ONLINK))
905 vty_out (vty, " onlink");
paul718e3742002-12-13 20:15:29 +0000906
Timo Teräs53a5c392015-05-23 11:08:40 +0300907 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
908 vty_out (vty, " (recursive)");
Christian Frankee8d3d292013-07-05 15:35:39 +0000909
Timo Teräs53a5c392015-05-23 11:08:40 +0300910 switch (nexthop->type)
Paul Jakma7514fb72007-05-02 16:05:35 +0000911 {
912 case NEXTHOP_TYPE_IPV4:
913 case NEXTHOP_TYPE_IPV4_IFINDEX:
914 case NEXTHOP_TYPE_IPV4_IFNAME:
915 if (nexthop->src.ipv4.s_addr)
916 {
Timo Teräs53a5c392015-05-23 11:08:40 +0300917 if (inet_ntop(AF_INET, &nexthop->src.ipv4, buf, sizeof buf))
918 vty_out (vty, ", src %s", buf);
Paul Jakma7514fb72007-05-02 16:05:35 +0000919 }
920 break;
Andrew J. Schorr09303312007-05-30 20:10:34 +0000921#ifdef HAVE_IPV6
Paul Jakma7514fb72007-05-02 16:05:35 +0000922 case NEXTHOP_TYPE_IPV6:
923 case NEXTHOP_TYPE_IPV6_IFINDEX:
924 case NEXTHOP_TYPE_IPV6_IFNAME:
925 if (!IPV6_ADDR_SAME(&nexthop->src.ipv6, &in6addr_any))
926 {
Timo Teräs53a5c392015-05-23 11:08:40 +0300927 if (inet_ntop(AF_INET6, &nexthop->src.ipv6, buf, sizeof buf))
928 vty_out (vty, ", src %s", buf);
Paul Jakma7514fb72007-05-02 16:05:35 +0000929 }
930 break;
Andrew J. Schorr09303312007-05-30 20:10:34 +0000931#endif /* HAVE_IPV6 */
Paul Jakma7514fb72007-05-02 16:05:35 +0000932 default:
Timo Teräs53a5c392015-05-23 11:08:40 +0300933 break;
Paul Jakma7514fb72007-05-02 16:05:35 +0000934 }
Timo Teräs53a5c392015-05-23 11:08:40 +0300935 vty_out (vty, "%s", VTY_NEWLINE);
936 }
paul718e3742002-12-13 20:15:29 +0000937 vty_out (vty, "%s", VTY_NEWLINE);
938 }
939}
940
paula1ac18c2005-06-28 17:17:12 +0000941static void
paul718e3742002-12-13 20:15:29 +0000942vty_show_ip_route (struct vty *vty, struct route_node *rn, struct rib *rib)
943{
Christian Frankefa713d92013-07-05 15:35:37 +0000944 struct nexthop *nexthop, *tnexthop;
945 int recursing;
paul718e3742002-12-13 20:15:29 +0000946 int len = 0;
947 char buf[BUFSIZ];
948
949 /* Nexthop information. */
Christian Frankefa713d92013-07-05 15:35:37 +0000950 for (ALL_NEXTHOPS_RO(rib->nexthop, nexthop, tnexthop, recursing))
paul718e3742002-12-13 20:15:29 +0000951 {
952 if (nexthop == rib->nexthop)
953 {
954 /* Prefix information. */
Timo Teräs53a5c392015-05-23 11:08:40 +0300955 len = vty_out (vty, "%c%c%c %s",
ajsf52d13c2005-10-01 17:38:06 +0000956 zebra_route_char (rib->type),
paul718e3742002-12-13 20:15:29 +0000957 CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED)
958 ? '>' : ' ',
959 CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
960 ? '*' : ' ',
Timo Teräs53a5c392015-05-23 11:08:40 +0300961 prefix2str (&rn->p, buf, sizeof buf));
paul718e3742002-12-13 20:15:29 +0000962
963 /* Distance and metric display. */
964 if (rib->type != ZEBRA_ROUTE_CONNECT
965 && rib->type != ZEBRA_ROUTE_KERNEL)
966 len += vty_out (vty, " [%d/%d]", rib->distance,
967 rib->metric);
Feng Lu4364ee52015-05-22 11:40:03 +0200968
969 if (rib->vrf_id != VRF_DEFAULT)
970 len += vty_out (vty, " [vrf %u]", rib->vrf_id);
paul718e3742002-12-13 20:15:29 +0000971 }
972 else
973 vty_out (vty, " %c%*c",
974 CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
975 ? '*' : ' ',
Christian Frankefa713d92013-07-05 15:35:37 +0000976 len - 3 + (2 * recursing), ' ');
paul718e3742002-12-13 20:15:29 +0000977
978 switch (nexthop->type)
Timo Teräs53a5c392015-05-23 11:08:40 +0300979 {
980 case NEXTHOP_TYPE_IPV4:
981 case NEXTHOP_TYPE_IPV4_IFINDEX:
982 vty_out (vty, " via %s", inet_ntoa (nexthop->gate.ipv4));
983 if (nexthop->ifindex)
Feng Lu0d0686f2015-05-22 11:40:02 +0200984 vty_out (vty, ", %s",
985 ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id));
Timo Teräs53a5c392015-05-23 11:08:40 +0300986 break;
987 case NEXTHOP_TYPE_IPV6:
988 case NEXTHOP_TYPE_IPV6_IFINDEX:
989 case NEXTHOP_TYPE_IPV6_IFNAME:
990 vty_out (vty, " via %s",
991 inet_ntop (AF_INET6, &nexthop->gate.ipv6, buf, BUFSIZ));
992 if (nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME)
993 vty_out (vty, ", %s", nexthop->ifname);
994 else if (nexthop->ifindex)
Feng Lu0d0686f2015-05-22 11:40:02 +0200995 vty_out (vty, ", %s",
996 ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id));
Timo Teräs53a5c392015-05-23 11:08:40 +0300997 break;
998 case NEXTHOP_TYPE_IFINDEX:
999 vty_out (vty, " is directly connected, %s",
Feng Lu0d0686f2015-05-22 11:40:02 +02001000 ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id));
Timo Teräs53a5c392015-05-23 11:08:40 +03001001 break;
1002 case NEXTHOP_TYPE_IFNAME:
1003 vty_out (vty, " is directly connected, %s", nexthop->ifname);
1004 break;
1005 case NEXTHOP_TYPE_BLACKHOLE:
1006 vty_out (vty, " is directly connected, Null0");
1007 break;
1008 default:
1009 break;
1010 }
paul718e3742002-12-13 20:15:29 +00001011 if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
Timo Teräs53a5c392015-05-23 11:08:40 +03001012 vty_out (vty, " inactive");
paul718e3742002-12-13 20:15:29 +00001013
Christian Frankee8d3d292013-07-05 15:35:39 +00001014 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ONLINK))
Timo Teräs53a5c392015-05-23 11:08:40 +03001015 vty_out (vty, " onlink");
Christian Frankee8d3d292013-07-05 15:35:39 +00001016
paul718e3742002-12-13 20:15:29 +00001017 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
Timo Teräs53a5c392015-05-23 11:08:40 +03001018 vty_out (vty, " (recursive)");
Christian Frankefa713d92013-07-05 15:35:37 +00001019
Paul Jakma7514fb72007-05-02 16:05:35 +00001020 switch (nexthop->type)
1021 {
1022 case NEXTHOP_TYPE_IPV4:
1023 case NEXTHOP_TYPE_IPV4_IFINDEX:
1024 case NEXTHOP_TYPE_IPV4_IFNAME:
1025 if (nexthop->src.ipv4.s_addr)
1026 {
Timo Teräs53a5c392015-05-23 11:08:40 +03001027 if (inet_ntop(AF_INET, &nexthop->src.ipv4, buf, sizeof buf))
Paul Jakma7514fb72007-05-02 16:05:35 +00001028 vty_out (vty, ", src %s", buf);
1029 }
1030 break;
Andrew J. Schorr09303312007-05-30 20:10:34 +00001031#ifdef HAVE_IPV6
Paul Jakma7514fb72007-05-02 16:05:35 +00001032 case NEXTHOP_TYPE_IPV6:
1033 case NEXTHOP_TYPE_IPV6_IFINDEX:
1034 case NEXTHOP_TYPE_IPV6_IFNAME:
1035 if (!IPV6_ADDR_SAME(&nexthop->src.ipv6, &in6addr_any))
1036 {
Timo Teräs53a5c392015-05-23 11:08:40 +03001037 if (inet_ntop(AF_INET6, &nexthop->src.ipv6, buf, sizeof buf))
Paul Jakma7514fb72007-05-02 16:05:35 +00001038 vty_out (vty, ", src %s", buf);
1039 }
1040 break;
Andrew J. Schorr09303312007-05-30 20:10:34 +00001041#endif /* HAVE_IPV6 */
Paul Jakma7514fb72007-05-02 16:05:35 +00001042 default:
Timo Teräs53a5c392015-05-23 11:08:40 +03001043 break;
Paul Jakma7514fb72007-05-02 16:05:35 +00001044 }
paul718e3742002-12-13 20:15:29 +00001045
hasso81dfcaa2003-05-25 19:21:25 +00001046 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
1047 vty_out (vty, ", bh");
1048 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT))
1049 vty_out (vty, ", rej");
1050
paul718e3742002-12-13 20:15:29 +00001051 if (rib->type == ZEBRA_ROUTE_RIP
Timo Teräs53a5c392015-05-23 11:08:40 +03001052 || rib->type == ZEBRA_ROUTE_RIPNG
1053 || rib->type == ZEBRA_ROUTE_OSPF
1054 || rib->type == ZEBRA_ROUTE_OSPF6
1055 || rib->type == ZEBRA_ROUTE_BABEL
1056 || rib->type == ZEBRA_ROUTE_ISIS
1057 || rib->type == ZEBRA_ROUTE_BGP)
paul718e3742002-12-13 20:15:29 +00001058 {
1059 time_t uptime;
1060 struct tm *tm;
1061
1062 uptime = time (NULL);
1063 uptime -= rib->uptime;
1064 tm = gmtime (&uptime);
1065
1066#define ONE_DAY_SECOND 60*60*24
1067#define ONE_WEEK_SECOND 60*60*24*7
1068
1069 if (uptime < ONE_DAY_SECOND)
1070 vty_out (vty, ", %02d:%02d:%02d",
1071 tm->tm_hour, tm->tm_min, tm->tm_sec);
1072 else if (uptime < ONE_WEEK_SECOND)
1073 vty_out (vty, ", %dd%02dh%02dm",
1074 tm->tm_yday, tm->tm_hour, tm->tm_min);
1075 else
1076 vty_out (vty, ", %02dw%dd%02dh",
1077 tm->tm_yday/7,
1078 tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
1079 }
1080 vty_out (vty, "%s", VTY_NEWLINE);
1081 }
1082}
1083
paul718e3742002-12-13 20:15:29 +00001084DEFUN (show_ip_route,
1085 show_ip_route_cmd,
1086 "show ip route",
1087 SHOW_STR
1088 IP_STR
1089 "IP routing table\n")
1090{
Feng Lu4364ee52015-05-22 11:40:03 +02001091 vrf_id_t vrf_id = VRF_DEFAULT;
1092
1093 if (argc > 0)
1094 VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
1095
1096 return do_show_ip_route(vty, SAFI_UNICAST, vrf_id);
Everton Marques33d86db2014-07-14 11:19:00 -03001097}
1098
Feng Lu4364ee52015-05-22 11:40:03 +02001099static int do_show_ip_route(struct vty *vty, safi_t safi, vrf_id_t vrf_id)
1100{
paul718e3742002-12-13 20:15:29 +00001101 struct route_table *table;
1102 struct route_node *rn;
1103 struct rib *rib;
1104 int first = 1;
1105
Feng Lu4364ee52015-05-22 11:40:03 +02001106 table = zebra_vrf_table (AFI_IP, safi, vrf_id);
paul718e3742002-12-13 20:15:29 +00001107 if (! table)
1108 return CMD_SUCCESS;
1109
1110 /* Show all IPv4 routes. */
1111 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001112 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +00001113 {
1114 if (first)
1115 {
David Lampartere0ca5fd2009-09-16 01:52:42 +02001116 vty_out (vty, SHOW_ROUTE_V4_HEADER);
paul718e3742002-12-13 20:15:29 +00001117 first = 0;
1118 }
1119 vty_show_ip_route (vty, rn, rib);
1120 }
1121 return CMD_SUCCESS;
1122}
1123
Feng Lu4364ee52015-05-22 11:40:03 +02001124ALIAS (show_ip_route,
1125 show_ip_route_vrf_cmd,
1126 "show ip route " VRF_CMD_STR,
1127 SHOW_STR
1128 IP_STR
1129 "IP routing table\n"
1130 VRF_CMD_HELP_STR)
1131
paul718e3742002-12-13 20:15:29 +00001132DEFUN (show_ip_route_prefix_longer,
1133 show_ip_route_prefix_longer_cmd,
1134 "show ip route A.B.C.D/M longer-prefixes",
1135 SHOW_STR
1136 IP_STR
1137 "IP routing table\n"
1138 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1139 "Show route matching the specified Network/Mask pair only\n")
1140{
1141 struct route_table *table;
1142 struct route_node *rn;
1143 struct rib *rib;
1144 struct prefix p;
1145 int ret;
1146 int first = 1;
Feng Lu4364ee52015-05-22 11:40:03 +02001147 vrf_id_t vrf_id = VRF_DEFAULT;
paul718e3742002-12-13 20:15:29 +00001148
1149 ret = str2prefix (argv[0], &p);
1150 if (! ret)
1151 {
1152 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
1153 return CMD_WARNING;
1154 }
Feng Lu4364ee52015-05-22 11:40:03 +02001155
1156 if (argc > 1)
1157 VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]);
1158
1159 table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
paul718e3742002-12-13 20:15:29 +00001160 if (! table)
1161 return CMD_SUCCESS;
1162
1163 /* Show matched type IPv4 routes. */
1164 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001165 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +00001166 if (prefix_match (&p, &rn->p))
1167 {
1168 if (first)
1169 {
David Lampartere0ca5fd2009-09-16 01:52:42 +02001170 vty_out (vty, SHOW_ROUTE_V4_HEADER);
paul718e3742002-12-13 20:15:29 +00001171 first = 0;
1172 }
1173 vty_show_ip_route (vty, rn, rib);
1174 }
1175 return CMD_SUCCESS;
1176}
1177
Feng Lu4364ee52015-05-22 11:40:03 +02001178ALIAS (show_ip_route_prefix_longer,
1179 show_ip_route_prefix_longer_vrf_cmd,
1180 "show ip route A.B.C.D/M longer-prefixes " VRF_CMD_STR,
1181 SHOW_STR
1182 IP_STR
1183 "IP routing table\n"
1184 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1185 "Show route matching the specified Network/Mask pair only\n"
1186 VRF_CMD_HELP_STR)
1187
paul718e3742002-12-13 20:15:29 +00001188DEFUN (show_ip_route_supernets,
1189 show_ip_route_supernets_cmd,
1190 "show ip route supernets-only",
1191 SHOW_STR
1192 IP_STR
1193 "IP routing table\n"
1194 "Show supernet entries only\n")
1195{
1196 struct route_table *table;
1197 struct route_node *rn;
1198 struct rib *rib;
Feng Lu4364ee52015-05-22 11:40:03 +02001199 u_int32_t addr;
paul718e3742002-12-13 20:15:29 +00001200 int first = 1;
Feng Lu4364ee52015-05-22 11:40:03 +02001201 vrf_id_t vrf_id = VRF_DEFAULT;
paul718e3742002-12-13 20:15:29 +00001202
Feng Lu4364ee52015-05-22 11:40:03 +02001203 if (argc > 0)
1204 VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
1205
1206 table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
paul718e3742002-12-13 20:15:29 +00001207 if (! table)
1208 return CMD_SUCCESS;
1209
1210 /* Show matched type IPv4 routes. */
1211 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001212 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +00001213 {
1214 addr = ntohl (rn->p.u.prefix4.s_addr);
1215
1216 if ((IN_CLASSC (addr) && rn->p.prefixlen < 24)
1217 || (IN_CLASSB (addr) && rn->p.prefixlen < 16)
Feng Lu4364ee52015-05-22 11:40:03 +02001218 || (IN_CLASSA (addr) && rn->p.prefixlen < 8))
paul718e3742002-12-13 20:15:29 +00001219 {
1220 if (first)
1221 {
David Lampartere0ca5fd2009-09-16 01:52:42 +02001222 vty_out (vty, SHOW_ROUTE_V4_HEADER);
paul718e3742002-12-13 20:15:29 +00001223 first = 0;
1224 }
1225 vty_show_ip_route (vty, rn, rib);
1226 }
1227 }
1228 return CMD_SUCCESS;
1229}
1230
Feng Lu4364ee52015-05-22 11:40:03 +02001231ALIAS (show_ip_route_supernets,
1232 show_ip_route_supernets_vrf_cmd,
1233 "show ip route supernets-only " VRF_CMD_STR,
1234 SHOW_STR
1235 IP_STR
1236 "IP routing table\n"
1237 "Show supernet entries only\n"
1238 VRF_CMD_HELP_STR)
1239
paul718e3742002-12-13 20:15:29 +00001240DEFUN (show_ip_route_protocol,
1241 show_ip_route_protocol_cmd,
David Lampartere0ca5fd2009-09-16 01:52:42 +02001242 "show ip route " QUAGGA_IP_REDIST_STR_ZEBRA,
paul718e3742002-12-13 20:15:29 +00001243 SHOW_STR
1244 IP_STR
1245 "IP routing table\n"
David Lampartere0ca5fd2009-09-16 01:52:42 +02001246 QUAGGA_IP_REDIST_HELP_STR_ZEBRA)
paul718e3742002-12-13 20:15:29 +00001247{
1248 int type;
1249 struct route_table *table;
1250 struct route_node *rn;
1251 struct rib *rib;
1252 int first = 1;
Feng Lu4364ee52015-05-22 11:40:03 +02001253 vrf_id_t vrf_id = VRF_DEFAULT;
paul718e3742002-12-13 20:15:29 +00001254
David Lampartere0ca5fd2009-09-16 01:52:42 +02001255 type = proto_redistnum (AFI_IP, argv[0]);
1256 if (type < 0)
paul718e3742002-12-13 20:15:29 +00001257 {
1258 vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
1259 return CMD_WARNING;
1260 }
Feng Lu4364ee52015-05-22 11:40:03 +02001261
1262 if (argc > 1)
1263 VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]);
1264
1265 table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
paul718e3742002-12-13 20:15:29 +00001266 if (! table)
1267 return CMD_SUCCESS;
1268
1269 /* Show matched type IPv4 routes. */
1270 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001271 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +00001272 if (rib->type == type)
1273 {
1274 if (first)
1275 {
David Lampartere0ca5fd2009-09-16 01:52:42 +02001276 vty_out (vty, SHOW_ROUTE_V4_HEADER);
paul718e3742002-12-13 20:15:29 +00001277 first = 0;
1278 }
1279 vty_show_ip_route (vty, rn, rib);
1280 }
1281 return CMD_SUCCESS;
1282}
1283
Feng Lu4364ee52015-05-22 11:40:03 +02001284ALIAS (show_ip_route_protocol,
1285 show_ip_route_protocol_vrf_cmd,
1286 "show ip route " QUAGGA_IP_REDIST_STR_ZEBRA " " VRF_CMD_STR,
1287 SHOW_STR
1288 IP_STR
1289 "IP routing table\n"
1290 QUAGGA_IP_REDIST_HELP_STR_ZEBRA
1291 VRF_CMD_HELP_STR)
1292
paul718e3742002-12-13 20:15:29 +00001293DEFUN (show_ip_route_addr,
1294 show_ip_route_addr_cmd,
1295 "show ip route A.B.C.D",
1296 SHOW_STR
1297 IP_STR
1298 "IP routing table\n"
1299 "Network in the IP routing table to display\n")
1300{
1301 int ret;
1302 struct prefix_ipv4 p;
1303 struct route_table *table;
1304 struct route_node *rn;
Feng Lu4364ee52015-05-22 11:40:03 +02001305 vrf_id_t vrf_id = VRF_DEFAULT;
paul718e3742002-12-13 20:15:29 +00001306
1307 ret = str2prefix_ipv4 (argv[0], &p);
1308 if (ret <= 0)
1309 {
1310 vty_out (vty, "%% Malformed IPv4 address%s", VTY_NEWLINE);
1311 return CMD_WARNING;
1312 }
1313
Feng Lu4364ee52015-05-22 11:40:03 +02001314 if (argc > 1)
1315 VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]);
1316
1317 table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
paul718e3742002-12-13 20:15:29 +00001318 if (! table)
1319 return CMD_SUCCESS;
1320
1321 rn = route_node_match (table, (struct prefix *) &p);
1322 if (! rn)
1323 {
1324 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
1325 return CMD_WARNING;
1326 }
1327
David Lamparter3b02fe82015-01-22 19:12:35 +01001328 vty_show_ip_route_detail (vty, rn, 0);
paul718e3742002-12-13 20:15:29 +00001329
1330 route_unlock_node (rn);
1331
1332 return CMD_SUCCESS;
1333}
1334
Feng Lu4364ee52015-05-22 11:40:03 +02001335ALIAS (show_ip_route_addr,
1336 show_ip_route_addr_vrf_cmd,
1337 "show ip route A.B.C.D " VRF_CMD_STR,
1338 SHOW_STR
1339 IP_STR
1340 "IP routing table\n"
1341 "Network in the IP routing table to display\n"
1342 VRF_CMD_HELP_STR)
1343
paul718e3742002-12-13 20:15:29 +00001344DEFUN (show_ip_route_prefix,
1345 show_ip_route_prefix_cmd,
1346 "show ip route A.B.C.D/M",
1347 SHOW_STR
1348 IP_STR
1349 "IP routing table\n"
1350 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
1351{
1352 int ret;
1353 struct prefix_ipv4 p;
1354 struct route_table *table;
1355 struct route_node *rn;
Feng Lu4364ee52015-05-22 11:40:03 +02001356 vrf_id_t vrf_id = VRF_DEFAULT;
paul718e3742002-12-13 20:15:29 +00001357
1358 ret = str2prefix_ipv4 (argv[0], &p);
1359 if (ret <= 0)
1360 {
1361 vty_out (vty, "%% Malformed IPv4 address%s", VTY_NEWLINE);
1362 return CMD_WARNING;
1363 }
1364
Feng Lu4364ee52015-05-22 11:40:03 +02001365 if (argc > 1)
1366 VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]);
1367
1368 table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
paul718e3742002-12-13 20:15:29 +00001369 if (! table)
1370 return CMD_SUCCESS;
1371
1372 rn = route_node_match (table, (struct prefix *) &p);
1373 if (! rn || rn->p.prefixlen != p.prefixlen)
1374 {
1375 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
Lu Feng969d3552014-10-21 06:24:07 +00001376 if (rn)
1377 route_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00001378 return CMD_WARNING;
1379 }
1380
David Lamparter3b02fe82015-01-22 19:12:35 +01001381 vty_show_ip_route_detail (vty, rn, 0);
paul718e3742002-12-13 20:15:29 +00001382
1383 route_unlock_node (rn);
1384
1385 return CMD_SUCCESS;
1386}
1387
Feng Lu4364ee52015-05-22 11:40:03 +02001388ALIAS (show_ip_route_prefix,
1389 show_ip_route_prefix_vrf_cmd,
1390 "show ip route A.B.C.D/M " VRF_CMD_STR,
1391 SHOW_STR
1392 IP_STR
1393 "IP routing table\n"
1394 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1395 VRF_CMD_HELP_STR)
1396
paula1ac18c2005-06-28 17:17:12 +00001397static void
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001398vty_show_ip_route_summary (struct vty *vty, struct route_table *table)
paul718e3742002-12-13 20:15:29 +00001399{
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001400 struct route_node *rn;
1401 struct rib *rib;
1402 struct nexthop *nexthop;
1403#define ZEBRA_ROUTE_IBGP ZEBRA_ROUTE_MAX
1404#define ZEBRA_ROUTE_TOTAL (ZEBRA_ROUTE_IBGP + 1)
1405 u_int32_t rib_cnt[ZEBRA_ROUTE_TOTAL + 1];
1406 u_int32_t fib_cnt[ZEBRA_ROUTE_TOTAL + 1];
1407 u_int32_t i;
paul718e3742002-12-13 20:15:29 +00001408
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001409 memset (&rib_cnt, 0, sizeof(rib_cnt));
1410 memset (&fib_cnt, 0, sizeof(fib_cnt));
1411 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001412 RNODE_FOREACH_RIB (rn, rib)
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001413 for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
1414 {
1415 rib_cnt[ZEBRA_ROUTE_TOTAL]++;
1416 rib_cnt[rib->type]++;
Christian Frankefa713d92013-07-05 15:35:37 +00001417 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
1418 || nexthop_has_fib_child(nexthop))
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001419 {
1420 fib_cnt[ZEBRA_ROUTE_TOTAL]++;
1421 fib_cnt[rib->type]++;
1422 }
1423 if (rib->type == ZEBRA_ROUTE_BGP &&
1424 CHECK_FLAG (rib->flags, ZEBRA_FLAG_IBGP))
1425 {
1426 rib_cnt[ZEBRA_ROUTE_IBGP]++;
Christian Frankefa713d92013-07-05 15:35:37 +00001427 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
1428 || nexthop_has_fib_child(nexthop))
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001429 fib_cnt[ZEBRA_ROUTE_IBGP]++;
1430 }
1431 }
paul718e3742002-12-13 20:15:29 +00001432
Feng Lu4364ee52015-05-22 11:40:03 +02001433 vty_out (vty, "%-20s %-20s %s (vrf %u)%s",
1434 "Route Source", "Routes", "FIB",
1435 ((rib_table_info_t *)table->info)->zvrf->vrf_id,
1436 VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001437
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001438 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
1439 {
1440 if (rib_cnt[i] > 0)
1441 {
1442 if (i == ZEBRA_ROUTE_BGP)
1443 {
1444 vty_out (vty, "%-20s %-20d %-20d %s", "ebgp",
1445 rib_cnt[ZEBRA_ROUTE_BGP] - rib_cnt[ZEBRA_ROUTE_IBGP],
1446 fib_cnt[ZEBRA_ROUTE_BGP] - fib_cnt[ZEBRA_ROUTE_IBGP],
1447 VTY_NEWLINE);
1448 vty_out (vty, "%-20s %-20d %-20d %s", "ibgp",
1449 rib_cnt[ZEBRA_ROUTE_IBGP], fib_cnt[ZEBRA_ROUTE_IBGP],
1450 VTY_NEWLINE);
1451 }
1452 else
1453 vty_out (vty, "%-20s %-20d %-20d %s", zebra_route_string(i),
1454 rib_cnt[i], fib_cnt[i], VTY_NEWLINE);
1455 }
1456 }
paul718e3742002-12-13 20:15:29 +00001457
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001458 vty_out (vty, "------%s", VTY_NEWLINE);
1459 vty_out (vty, "%-20s %-20d %-20d %s", "Totals", rib_cnt[ZEBRA_ROUTE_TOTAL],
1460 fib_cnt[ZEBRA_ROUTE_TOTAL], VTY_NEWLINE);
Feng Lu4364ee52015-05-22 11:40:03 +02001461 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001462}
1463
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07001464/*
1465 * Implementation of the ip route summary prefix command.
1466 *
1467 * This command prints the primary prefixes that have been installed by various
1468 * protocols on the box.
1469 *
1470 */
1471static void
1472vty_show_ip_route_summary_prefix (struct vty *vty, struct route_table *table)
1473{
1474 struct route_node *rn;
1475 struct rib *rib;
1476 struct nexthop *nexthop;
1477#define ZEBRA_ROUTE_IBGP ZEBRA_ROUTE_MAX
1478#define ZEBRA_ROUTE_TOTAL (ZEBRA_ROUTE_IBGP + 1)
1479 u_int32_t rib_cnt[ZEBRA_ROUTE_TOTAL + 1];
1480 u_int32_t fib_cnt[ZEBRA_ROUTE_TOTAL + 1];
1481 u_int32_t i;
1482 int cnt;
1483
1484 memset (&rib_cnt, 0, sizeof(rib_cnt));
1485 memset (&fib_cnt, 0, sizeof(fib_cnt));
1486 for (rn = route_top (table); rn; rn = route_next (rn))
1487 RNODE_FOREACH_RIB (rn, rib)
1488 {
1489
1490 /*
1491 * In case of ECMP, count only once.
1492 */
1493 cnt = 0;
1494 for (nexthop = rib->nexthop; (!cnt && nexthop); nexthop = nexthop->next)
1495 {
1496 cnt++;
1497 rib_cnt[ZEBRA_ROUTE_TOTAL]++;
1498 rib_cnt[rib->type]++;
1499 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB))
1500 {
1501 fib_cnt[ZEBRA_ROUTE_TOTAL]++;
1502 fib_cnt[rib->type]++;
1503 }
1504 if (rib->type == ZEBRA_ROUTE_BGP &&
1505 CHECK_FLAG (rib->flags, ZEBRA_FLAG_IBGP))
1506 {
1507 rib_cnt[ZEBRA_ROUTE_IBGP]++;
1508 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB))
1509 fib_cnt[ZEBRA_ROUTE_IBGP]++;
1510 }
1511 }
1512 }
1513
Feng Lu4364ee52015-05-22 11:40:03 +02001514 vty_out (vty, "%-20s %-20s %s (vrf %u)%s",
1515 "Route Source", "Prefix Routes", "FIB",
1516 ((rib_table_info_t *)table->info)->zvrf->vrf_id,
1517 VTY_NEWLINE);
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07001518
1519 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
1520 {
1521 if (rib_cnt[i] > 0)
1522 {
1523 if (i == ZEBRA_ROUTE_BGP)
1524 {
1525 vty_out (vty, "%-20s %-20d %-20d %s", "ebgp",
1526 rib_cnt[ZEBRA_ROUTE_BGP] - rib_cnt[ZEBRA_ROUTE_IBGP],
1527 fib_cnt[ZEBRA_ROUTE_BGP] - fib_cnt[ZEBRA_ROUTE_IBGP],
1528 VTY_NEWLINE);
1529 vty_out (vty, "%-20s %-20d %-20d %s", "ibgp",
1530 rib_cnt[ZEBRA_ROUTE_IBGP], fib_cnt[ZEBRA_ROUTE_IBGP],
1531 VTY_NEWLINE);
1532 }
1533 else
1534 vty_out (vty, "%-20s %-20d %-20d %s", zebra_route_string(i),
1535 rib_cnt[i], fib_cnt[i], VTY_NEWLINE);
1536 }
1537 }
1538
1539 vty_out (vty, "------%s", VTY_NEWLINE);
1540 vty_out (vty, "%-20s %-20d %-20d %s", "Totals", rib_cnt[ZEBRA_ROUTE_TOTAL],
1541 fib_cnt[ZEBRA_ROUTE_TOTAL], VTY_NEWLINE);
Feng Lu4364ee52015-05-22 11:40:03 +02001542 vty_out (vty, "%s", VTY_NEWLINE);
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07001543}
1544
paul718e3742002-12-13 20:15:29 +00001545/* Show route summary. */
1546DEFUN (show_ip_route_summary,
1547 show_ip_route_summary_cmd,
1548 "show ip route summary",
1549 SHOW_STR
1550 IP_STR
1551 "IP routing table\n"
1552 "Summary of all routes\n")
1553{
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001554 struct route_table *table;
Feng Lu4364ee52015-05-22 11:40:03 +02001555 vrf_id_t vrf_id = VRF_DEFAULT;
paul718e3742002-12-13 20:15:29 +00001556
Feng Lu4364ee52015-05-22 11:40:03 +02001557 if (argc > 0)
1558 VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
1559
1560 table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001561 if (! table)
1562 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001563
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001564 vty_show_ip_route_summary (vty, table);
paul718e3742002-12-13 20:15:29 +00001565
1566 return CMD_SUCCESS;
1567}
1568
Feng Lu4364ee52015-05-22 11:40:03 +02001569ALIAS (show_ip_route_summary,
1570 show_ip_route_summary_vrf_cmd,
1571 "show ip route summary " VRF_CMD_STR,
1572 SHOW_STR
1573 IP_STR
1574 "IP routing table\n"
1575 "Summary of all routes\n"
1576 VRF_CMD_HELP_STR)
1577
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07001578/* Show route summary prefix. */
1579DEFUN (show_ip_route_summary_prefix,
1580 show_ip_route_summary_prefix_cmd,
1581 "show ip route summary prefix",
1582 SHOW_STR
1583 IP_STR
1584 "IP routing table\n"
1585 "Summary of all routes\n"
1586 "Prefix routes\n")
1587{
1588 struct route_table *table;
Feng Lu4364ee52015-05-22 11:40:03 +02001589 vrf_id_t vrf_id = VRF_DEFAULT;
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07001590
Feng Lu4364ee52015-05-22 11:40:03 +02001591 if (argc > 0)
1592 VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
1593
1594 table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07001595 if (! table)
1596 return CMD_SUCCESS;
1597
1598 vty_show_ip_route_summary_prefix (vty, table);
1599
1600 return CMD_SUCCESS;
1601}
1602
Feng Lu4364ee52015-05-22 11:40:03 +02001603ALIAS (show_ip_route_summary_prefix,
1604 show_ip_route_summary_prefix_vrf_cmd,
1605 "show ip route summary prefix " VRF_CMD_STR,
1606 SHOW_STR
1607 IP_STR
1608 "IP routing table\n"
1609 "Summary of all routes\n"
1610 "Prefix routes\n"
1611 VRF_CMD_HELP_STR)
1612
1613DEFUN (show_ip_route_vrf_all,
1614 show_ip_route_vrf_all_cmd,
1615 "show ip route " VRF_ALL_CMD_STR,
1616 SHOW_STR
1617 IP_STR
1618 "IP routing table\n"
1619 VRF_ALL_CMD_HELP_STR)
1620{
1621 struct route_table *table;
1622 struct route_node *rn;
1623 struct rib *rib;
1624 struct zebra_vrf *zvrf;
1625 vrf_iter_t iter;
1626 int first = 1;
1627
1628 for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
1629 {
1630 if ((zvrf = vrf_iter2info (iter)) == NULL ||
1631 (table = zvrf->table[AFI_IP][SAFI_UNICAST]) == NULL)
1632 continue;
1633
1634 /* Show all IPv4 routes. */
1635 for (rn = route_top (table); rn; rn = route_next (rn))
1636 RNODE_FOREACH_RIB (rn, rib)
1637 {
1638 if (first)
1639 {
1640 vty_out (vty, SHOW_ROUTE_V4_HEADER);
1641 first = 0;
1642 }
1643 vty_show_ip_route (vty, rn, rib);
1644 }
1645 }
1646
1647 return CMD_SUCCESS;
1648}
1649
1650DEFUN (show_ip_route_prefix_longer_vrf_all,
1651 show_ip_route_prefix_longer_vrf_all_cmd,
1652 "show ip route A.B.C.D/M longer-prefixes " VRF_ALL_CMD_STR,
1653 SHOW_STR
1654 IP_STR
1655 "IP routing table\n"
1656 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1657 "Show route matching the specified Network/Mask pair only\n"
1658 VRF_ALL_CMD_HELP_STR)
1659{
1660 struct route_table *table;
1661 struct route_node *rn;
1662 struct rib *rib;
1663 struct prefix p;
1664 struct zebra_vrf *zvrf;
1665 vrf_iter_t iter;
1666 int ret;
1667 int first = 1;
1668
1669 ret = str2prefix (argv[0], &p);
1670 if (! ret)
1671 {
1672 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
1673 return CMD_WARNING;
1674 }
1675
1676 for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
1677 {
1678 if ((zvrf = vrf_iter2info (iter)) == NULL ||
1679 (table = zvrf->table[AFI_IP][SAFI_UNICAST]) == NULL)
1680 continue;
1681
1682 /* Show matched type IPv4 routes. */
1683 for (rn = route_top (table); rn; rn = route_next (rn))
1684 RNODE_FOREACH_RIB (rn, rib)
1685 if (prefix_match (&p, &rn->p))
1686 {
1687 if (first)
1688 {
1689 vty_out (vty, SHOW_ROUTE_V4_HEADER);
1690 first = 0;
1691 }
1692 vty_show_ip_route (vty, rn, rib);
1693 }
1694 }
1695
1696 return CMD_SUCCESS;
1697}
1698
1699DEFUN (show_ip_route_supernets_vrf_all,
1700 show_ip_route_supernets_vrf_all_cmd,
1701 "show ip route supernets-only " VRF_ALL_CMD_STR,
1702 SHOW_STR
1703 IP_STR
1704 "IP routing table\n"
1705 "Show supernet entries only\n"
1706 VRF_ALL_CMD_HELP_STR)
1707{
1708 struct route_table *table;
1709 struct route_node *rn;
1710 struct rib *rib;
1711 struct zebra_vrf *zvrf;
1712 vrf_iter_t iter;
1713 u_int32_t addr;
1714 int first = 1;
1715
1716 for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
1717 {
1718 if ((zvrf = vrf_iter2info (iter)) == NULL ||
1719 (table = zvrf->table[AFI_IP][SAFI_UNICAST]) == NULL)
1720 continue;
1721
1722 /* Show matched type IPv4 routes. */
1723 for (rn = route_top (table); rn; rn = route_next (rn))
1724 RNODE_FOREACH_RIB (rn, rib)
1725 {
1726 addr = ntohl (rn->p.u.prefix4.s_addr);
1727
1728 if ((IN_CLASSC (addr) && rn->p.prefixlen < 24)
1729 || (IN_CLASSB (addr) && rn->p.prefixlen < 16)
1730 || (IN_CLASSA (addr) && rn->p.prefixlen < 8))
1731 {
1732 if (first)
1733 {
1734 vty_out (vty, SHOW_ROUTE_V4_HEADER);
1735 first = 0;
1736 }
1737 vty_show_ip_route (vty, rn, rib);
1738 }
1739 }
1740 }
1741
1742 return CMD_SUCCESS;
1743}
1744
1745DEFUN (show_ip_route_protocol_vrf_all,
1746 show_ip_route_protocol_vrf_all_cmd,
1747 "show ip route " QUAGGA_IP_REDIST_STR_ZEBRA " " VRF_ALL_CMD_STR,
1748 SHOW_STR
1749 IP_STR
1750 "IP routing table\n"
1751 QUAGGA_IP_REDIST_HELP_STR_ZEBRA
1752 VRF_ALL_CMD_HELP_STR)
1753{
1754 int type;
1755 struct route_table *table;
1756 struct route_node *rn;
1757 struct rib *rib;
1758 struct zebra_vrf *zvrf;
1759 vrf_iter_t iter;
1760 int first = 1;
1761
1762 type = proto_redistnum (AFI_IP, argv[0]);
1763 if (type < 0)
1764 {
1765 vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
1766 return CMD_WARNING;
1767 }
1768
1769 for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
1770 {
1771 if ((zvrf = vrf_iter2info (iter)) == NULL ||
1772 (table = zvrf->table[AFI_IP][SAFI_UNICAST]) == NULL)
1773 continue;
1774
1775 /* Show matched type IPv4 routes. */
1776 for (rn = route_top (table); rn; rn = route_next (rn))
1777 RNODE_FOREACH_RIB (rn, rib)
1778 if (rib->type == type)
1779 {
1780 if (first)
1781 {
1782 vty_out (vty, SHOW_ROUTE_V4_HEADER);
1783 first = 0;
1784 }
1785 vty_show_ip_route (vty, rn, rib);
1786 }
1787 }
1788
1789 return CMD_SUCCESS;
1790}
1791
1792DEFUN (show_ip_route_addr_vrf_all,
1793 show_ip_route_addr_vrf_all_cmd,
1794 "show ip route A.B.C.D " VRF_ALL_CMD_STR,
1795 SHOW_STR
1796 IP_STR
1797 "IP routing table\n"
1798 "Network in the IP routing table to display\n"
1799 VRF_ALL_CMD_HELP_STR)
1800{
1801 int ret;
1802 struct prefix_ipv4 p;
1803 struct route_table *table;
1804 struct route_node *rn;
1805 struct zebra_vrf *zvrf;
1806 vrf_iter_t iter;
1807
1808 ret = str2prefix_ipv4 (argv[0], &p);
1809 if (ret <= 0)
1810 {
1811 vty_out (vty, "%% Malformed IPv4 address%s", VTY_NEWLINE);
1812 return CMD_WARNING;
1813 }
1814
1815 for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
1816 {
1817 if ((zvrf = vrf_iter2info (iter)) == NULL ||
1818 (table = zvrf->table[AFI_IP][SAFI_UNICAST]) == NULL)
1819 continue;
1820
1821 rn = route_node_match (table, (struct prefix *) &p);
1822 if (! rn)
1823 continue;
1824
1825 vty_show_ip_route_detail (vty, rn, 0);
1826
1827 route_unlock_node (rn);
1828 }
1829
1830 return CMD_SUCCESS;
1831}
1832
1833DEFUN (show_ip_route_prefix_vrf_all,
1834 show_ip_route_prefix_vrf_all_cmd,
1835 "show ip route A.B.C.D/M " VRF_ALL_CMD_STR,
1836 SHOW_STR
1837 IP_STR
1838 "IP routing table\n"
1839 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1840 VRF_ALL_CMD_HELP_STR)
1841{
1842 int ret;
1843 struct prefix_ipv4 p;
1844 struct route_table *table;
1845 struct route_node *rn;
1846 struct zebra_vrf *zvrf;
1847 vrf_iter_t iter;
1848
1849 ret = str2prefix_ipv4 (argv[0], &p);
1850 if (ret <= 0)
1851 {
1852 vty_out (vty, "%% Malformed IPv4 address%s", VTY_NEWLINE);
1853 return CMD_WARNING;
1854 }
1855
1856 for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
1857 {
1858 if ((zvrf = vrf_iter2info (iter)) == NULL ||
1859 (table = zvrf->table[AFI_IP][SAFI_UNICAST]) == NULL)
1860 continue;
1861
1862 rn = route_node_match (table, (struct prefix *) &p);
1863 if (! rn)
1864 continue;
1865 if (rn->p.prefixlen != p.prefixlen)
1866 {
1867 route_unlock_node (rn);
1868 continue;
1869 }
1870
1871 vty_show_ip_route_detail (vty, rn, 0);
1872
1873 route_unlock_node (rn);
1874 }
1875
1876 return CMD_SUCCESS;
1877}
1878
1879DEFUN (show_ip_route_summary_vrf_all,
1880 show_ip_route_summary_vrf_all_cmd,
1881 "show ip route summary " VRF_ALL_CMD_STR,
1882 SHOW_STR
1883 IP_STR
1884 "IP routing table\n"
1885 "Summary of all routes\n"
1886 VRF_ALL_CMD_HELP_STR)
1887{
1888 struct zebra_vrf *zvrf;
1889 vrf_iter_t iter;
1890
1891 for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
1892 if ((zvrf = vrf_iter2info (iter)) != NULL)
1893 vty_show_ip_route_summary (vty, zvrf->table[AFI_IP][SAFI_UNICAST]);
1894
1895 return CMD_SUCCESS;
1896}
1897
1898DEFUN (show_ip_route_summary_prefix_vrf_all,
1899 show_ip_route_summary_prefix_vrf_all_cmd,
1900 "show ip route summary prefix " VRF_ALL_CMD_STR,
1901 SHOW_STR
1902 IP_STR
1903 "IP routing table\n"
1904 "Summary of all routes\n"
1905 "Prefix routes\n"
1906 VRF_ALL_CMD_HELP_STR)
1907{
1908 struct zebra_vrf *zvrf;
1909 vrf_iter_t iter;
1910
1911 for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
1912 if ((zvrf = vrf_iter2info (iter)) != NULL)
1913 vty_show_ip_route_summary_prefix (vty, zvrf->table[AFI_IP][SAFI_UNICAST]);
1914
1915 return CMD_SUCCESS;
1916}
1917
paul718e3742002-12-13 20:15:29 +00001918/* Write IPv4 static route configuration. */
paula1ac18c2005-06-28 17:17:12 +00001919static int
Everton Marques33d86db2014-07-14 11:19:00 -03001920static_config_ipv4 (struct vty *vty, safi_t safi, const char *cmd)
paul718e3742002-12-13 20:15:29 +00001921{
1922 struct route_node *rn;
1923 struct static_ipv4 *si;
1924 struct route_table *stable;
1925 int write;
1926
1927 write = 0;
1928
1929 /* Lookup table. */
Feng Lu41f44a22015-05-22 11:39:56 +02001930 stable = zebra_vrf_static_table (AFI_IP, safi, VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +00001931 if (! stable)
1932 return -1;
1933
1934 for (rn = route_top (stable); rn; rn = route_next (rn))
1935 for (si = rn->info; si; si = si->next)
1936 {
Feng Lu4364ee52015-05-22 11:40:03 +02001937 vty_out (vty, "%s %s/%d", cmd, inet_ntoa (rn->p.u.prefix4),
1938 rn->p.prefixlen);
paul718e3742002-12-13 20:15:29 +00001939
paul7021c422003-07-15 12:52:22 +00001940 switch (si->type)
1941 {
1942 case STATIC_IPV4_GATEWAY:
1943 vty_out (vty, " %s", inet_ntoa (si->gate.ipv4));
1944 break;
1945 case STATIC_IPV4_IFNAME:
1946 vty_out (vty, " %s", si->gate.ifname);
1947 break;
1948 case STATIC_IPV4_BLACKHOLE:
1949 vty_out (vty, " Null0");
1950 break;
1951 }
1952
1953 /* flags are incompatible with STATIC_IPV4_BLACKHOLE */
1954 if (si->type != STATIC_IPV4_BLACKHOLE)
1955 {
1956 if (CHECK_FLAG(si->flags, ZEBRA_FLAG_REJECT))
1957 vty_out (vty, " %s", "reject");
paul718e3742002-12-13 20:15:29 +00001958
paul7021c422003-07-15 12:52:22 +00001959 if (CHECK_FLAG(si->flags, ZEBRA_FLAG_BLACKHOLE))
1960 vty_out (vty, " %s", "blackhole");
1961 }
hasso81dfcaa2003-05-25 19:21:25 +00001962
paul7021c422003-07-15 12:52:22 +00001963 if (si->distance != ZEBRA_STATIC_DISTANCE_DEFAULT)
1964 vty_out (vty, " %d", si->distance);
hasso81dfcaa2003-05-25 19:21:25 +00001965
paul7021c422003-07-15 12:52:22 +00001966 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001967
paul7021c422003-07-15 12:52:22 +00001968 write = 1;
paul718e3742002-12-13 20:15:29 +00001969 }
1970 return write;
1971}
Andrew J. Schorr09303312007-05-30 20:10:34 +00001972
1973DEFUN (show_ip_protocol,
1974 show_ip_protocol_cmd,
1975 "show ip protocol",
1976 SHOW_STR
1977 IP_STR
1978 "IP protocol filtering status\n")
1979{
1980 int i;
1981
1982 vty_out(vty, "Protocol : route-map %s", VTY_NEWLINE);
1983 vty_out(vty, "------------------------%s", VTY_NEWLINE);
1984 for (i=0;i<ZEBRA_ROUTE_MAX;i++)
1985 {
1986 if (proto_rm[AFI_IP][i])
1987 vty_out (vty, "%-10s : %-10s%s", zebra_route_string(i),
1988 proto_rm[AFI_IP][i],
1989 VTY_NEWLINE);
1990 else
1991 vty_out (vty, "%-10s : none%s", zebra_route_string(i), VTY_NEWLINE);
1992 }
1993 if (proto_rm[AFI_IP][i])
1994 vty_out (vty, "%-10s : %-10s%s", "any", proto_rm[AFI_IP][i],
1995 VTY_NEWLINE);
1996 else
1997 vty_out (vty, "%-10s : none%s", "any", VTY_NEWLINE);
1998
1999 return CMD_SUCCESS;
2000}
2001
Joachim Nilsson36735ed2012-05-09 13:38:36 +02002002/*
2003 * Show IP mroute command to dump the BGP Multicast
2004 * routing table
2005 */
2006DEFUN (show_ip_mroute,
2007 show_ip_mroute_cmd,
2008 "show ip mroute",
2009 SHOW_STR
2010 IP_STR
2011 "IP Multicast routing table\n")
2012{
2013 struct route_table *table;
2014 struct route_node *rn;
2015 struct rib *rib;
2016 int first = 1;
Feng Lu4364ee52015-05-22 11:40:03 +02002017 vrf_id_t vrf_id = VRF_DEFAULT;
Joachim Nilsson36735ed2012-05-09 13:38:36 +02002018
Feng Lu4364ee52015-05-22 11:40:03 +02002019 if (argc > 0)
2020 VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
2021
2022 table = zebra_vrf_table (AFI_IP, SAFI_MULTICAST, vrf_id);
Joachim Nilsson36735ed2012-05-09 13:38:36 +02002023 if (! table)
2024 return CMD_SUCCESS;
2025
2026 /* Show all IPv4 routes. */
2027 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00002028 RNODE_FOREACH_RIB (rn, rib)
Joachim Nilsson36735ed2012-05-09 13:38:36 +02002029 {
2030 if (first)
2031 {
2032 vty_out (vty, SHOW_ROUTE_V4_HEADER);
2033 first = 0;
2034 }
2035 vty_show_ip_route (vty, rn, rib);
2036 }
2037 return CMD_SUCCESS;
2038}
2039
Feng Lu4364ee52015-05-22 11:40:03 +02002040ALIAS (show_ip_mroute,
2041 show_ip_mroute_vrf_cmd,
2042 "show ip mroute " VRF_CMD_STR,
2043 SHOW_STR
2044 IP_STR
2045 "IP Multicast routing table\n"
2046 VRF_CMD_HELP_STR)
2047
2048DEFUN (show_ip_mroute_vrf_all,
2049 show_ip_mroute_vrf_all_cmd,
2050 "show ip mroute " VRF_ALL_CMD_STR,
2051 SHOW_STR
2052 IP_STR
2053 "IP Multicast routing table\n"
2054 VRF_ALL_CMD_HELP_STR)
2055{
2056 struct route_table *table;
2057 struct route_node *rn;
2058 struct rib *rib;
2059 struct zebra_vrf *zvrf;
2060 vrf_iter_t iter;
2061 int first = 1;
2062
2063 for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
2064 {
2065 if ((zvrf = vrf_iter2info (iter)) == NULL ||
2066 (table = zvrf->table[AFI_IP][SAFI_UNICAST]) == NULL)
2067 continue;
2068
2069 /* Show all IPv4 routes. */
2070 for (rn = route_top (table); rn; rn = route_next (rn))
2071 RNODE_FOREACH_RIB (rn, rib)
2072 {
2073 if (first)
2074 {
2075 vty_out (vty, SHOW_ROUTE_V4_HEADER);
2076 first = 0;
2077 }
2078 vty_show_ip_route (vty, rn, rib);
2079 }
2080 }
2081
2082 return CMD_SUCCESS;
2083}
David Lamparter6b0655a2014-06-04 06:53:35 +02002084
paul718e3742002-12-13 20:15:29 +00002085#ifdef HAVE_IPV6
2086/* General fucntion for IPv6 static route. */
paula1ac18c2005-06-28 17:17:12 +00002087static int
hasso39db97e2004-10-12 20:50:58 +00002088static_ipv6_func (struct vty *vty, int add_cmd, const char *dest_str,
2089 const char *gate_str, const char *ifname,
2090 const char *flag_str, const char *distance_str)
paul718e3742002-12-13 20:15:29 +00002091{
2092 int ret;
2093 u_char distance;
2094 struct prefix p;
2095 struct in6_addr *gate = NULL;
2096 struct in6_addr gate_addr;
2097 u_char type = 0;
2098 int table = 0;
hasso81dfcaa2003-05-25 19:21:25 +00002099 u_char flag = 0;
paul718e3742002-12-13 20:15:29 +00002100
2101 ret = str2prefix (dest_str, &p);
2102 if (ret <= 0)
2103 {
2104 vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
2105 return CMD_WARNING;
2106 }
2107
2108 /* Apply mask for given prefix. */
2109 apply_mask (&p);
2110
hasso81dfcaa2003-05-25 19:21:25 +00002111 /* Route flags */
2112 if (flag_str) {
2113 switch(flag_str[0]) {
2114 case 'r':
2115 case 'R': /* XXX */
2116 SET_FLAG (flag, ZEBRA_FLAG_REJECT);
2117 break;
2118 case 'b':
2119 case 'B': /* XXX */
2120 SET_FLAG (flag, ZEBRA_FLAG_BLACKHOLE);
2121 break;
2122 default:
2123 vty_out (vty, "%% Malformed flag %s %s", flag_str, VTY_NEWLINE);
paul595db7f2003-05-25 21:35:06 +00002124 return CMD_WARNING;
hasso81dfcaa2003-05-25 19:21:25 +00002125 }
2126 }
2127
paul718e3742002-12-13 20:15:29 +00002128 /* Administrative distance. */
2129 if (distance_str)
2130 distance = atoi (distance_str);
2131 else
2132 distance = ZEBRA_STATIC_DISTANCE_DEFAULT;
2133
2134 /* When gateway is valid IPv6 addrees, then gate is treated as
2135 nexthop address other case gate is treated as interface name. */
2136 ret = inet_pton (AF_INET6, gate_str, &gate_addr);
2137
2138 if (ifname)
2139 {
2140 /* When ifname is specified. It must be come with gateway
2141 address. */
2142 if (ret != 1)
2143 {
2144 vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
2145 return CMD_WARNING;
2146 }
2147 type = STATIC_IPV6_GATEWAY_IFNAME;
2148 gate = &gate_addr;
2149 }
2150 else
2151 {
2152 if (ret == 1)
2153 {
2154 type = STATIC_IPV6_GATEWAY;
2155 gate = &gate_addr;
2156 }
2157 else
2158 {
2159 type = STATIC_IPV6_IFNAME;
2160 ifname = gate_str;
2161 }
2162 }
2163
2164 if (add_cmd)
hasso81dfcaa2003-05-25 19:21:25 +00002165 static_add_ipv6 (&p, type, gate, ifname, flag, distance, table);
paul718e3742002-12-13 20:15:29 +00002166 else
2167 static_delete_ipv6 (&p, type, gate, ifname, distance, table);
2168
2169 return CMD_SUCCESS;
2170}
2171
2172DEFUN (ipv6_route,
2173 ipv6_route_cmd,
2174 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE)",
2175 IP_STR
2176 "Establish static routes\n"
2177 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
2178 "IPv6 gateway address\n"
2179 "IPv6 gateway interface name\n")
2180{
hasso81dfcaa2003-05-25 19:21:25 +00002181 return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, NULL, NULL);
2182}
2183
2184DEFUN (ipv6_route_flags,
2185 ipv6_route_flags_cmd,
2186 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole)",
2187 IP_STR
2188 "Establish static routes\n"
2189 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
2190 "IPv6 gateway address\n"
2191 "IPv6 gateway interface name\n"
2192 "Emit an ICMP unreachable when matched\n"
2193 "Silently discard pkts when matched\n")
2194{
2195 return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, argv[2], NULL);
paul718e3742002-12-13 20:15:29 +00002196}
2197
2198DEFUN (ipv6_route_ifname,
2199 ipv6_route_ifname_cmd,
2200 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE",
2201 IP_STR
2202 "Establish static routes\n"
2203 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
2204 "IPv6 gateway address\n"
2205 "IPv6 gateway interface name\n")
2206{
hasso81dfcaa2003-05-25 19:21:25 +00002207 return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], NULL, NULL);
2208}
2209
2210DEFUN (ipv6_route_ifname_flags,
2211 ipv6_route_ifname_flags_cmd,
2212 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole)",
2213 IP_STR
2214 "Establish static routes\n"
2215 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
2216 "IPv6 gateway address\n"
2217 "IPv6 gateway interface name\n"
2218 "Emit an ICMP unreachable when matched\n"
2219 "Silently discard pkts when matched\n")
2220{
2221 return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], argv[3], NULL);
paul718e3742002-12-13 20:15:29 +00002222}
2223
2224DEFUN (ipv6_route_pref,
2225 ipv6_route_pref_cmd,
2226 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <1-255>",
2227 IP_STR
2228 "Establish static routes\n"
2229 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
2230 "IPv6 gateway address\n"
2231 "IPv6 gateway interface name\n"
2232 "Distance value for this prefix\n")
2233{
hasso81dfcaa2003-05-25 19:21:25 +00002234 return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, NULL, argv[2]);
2235}
2236
2237DEFUN (ipv6_route_flags_pref,
2238 ipv6_route_flags_pref_cmd,
2239 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) <1-255>",
2240 IP_STR
2241 "Establish static routes\n"
2242 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
2243 "IPv6 gateway address\n"
2244 "IPv6 gateway interface name\n"
2245 "Emit an ICMP unreachable when matched\n"
2246 "Silently discard pkts when matched\n"
2247 "Distance value for this prefix\n")
2248{
2249 return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, argv[2], argv[3]);
paul718e3742002-12-13 20:15:29 +00002250}
2251
2252DEFUN (ipv6_route_ifname_pref,
2253 ipv6_route_ifname_pref_cmd,
2254 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255>",
2255 IP_STR
2256 "Establish static routes\n"
2257 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
2258 "IPv6 gateway address\n"
2259 "IPv6 gateway interface name\n"
2260 "Distance value for this prefix\n")
2261{
hasso81dfcaa2003-05-25 19:21:25 +00002262 return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], NULL, argv[3]);
2263}
2264
2265DEFUN (ipv6_route_ifname_flags_pref,
2266 ipv6_route_ifname_flags_pref_cmd,
2267 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) <1-255>",
2268 IP_STR
2269 "Establish static routes\n"
2270 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
2271 "IPv6 gateway address\n"
2272 "IPv6 gateway interface name\n"
2273 "Emit an ICMP unreachable when matched\n"
2274 "Silently discard pkts when matched\n"
2275 "Distance value for this prefix\n")
2276{
2277 return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], argv[3], argv[4]);
paul718e3742002-12-13 20:15:29 +00002278}
2279
2280DEFUN (no_ipv6_route,
2281 no_ipv6_route_cmd,
2282 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE)",
2283 NO_STR
2284 IP_STR
2285 "Establish static routes\n"
2286 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
2287 "IPv6 gateway address\n"
2288 "IPv6 gateway interface name\n")
2289{
hasso81dfcaa2003-05-25 19:21:25 +00002290 return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002291}
2292
hasso81dfcaa2003-05-25 19:21:25 +00002293ALIAS (no_ipv6_route,
2294 no_ipv6_route_flags_cmd,
2295 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole)",
2296 NO_STR
2297 IP_STR
2298 "Establish static routes\n"
2299 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
2300 "IPv6 gateway address\n"
2301 "IPv6 gateway interface name\n"
2302 "Emit an ICMP unreachable when matched\n"
2303 "Silently discard pkts when matched\n")
2304
paul718e3742002-12-13 20:15:29 +00002305DEFUN (no_ipv6_route_ifname,
2306 no_ipv6_route_ifname_cmd,
2307 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE",
2308 NO_STR
2309 IP_STR
2310 "Establish static routes\n"
2311 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
2312 "IPv6 gateway address\n"
2313 "IPv6 gateway interface name\n")
2314{
hasso81dfcaa2003-05-25 19:21:25 +00002315 return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002316}
2317
hasso81dfcaa2003-05-25 19:21:25 +00002318ALIAS (no_ipv6_route_ifname,
2319 no_ipv6_route_ifname_flags_cmd,
2320 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole)",
2321 NO_STR
2322 IP_STR
2323 "Establish static routes\n"
2324 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
2325 "IPv6 gateway address\n"
2326 "IPv6 gateway interface name\n"
2327 "Emit an ICMP unreachable when matched\n"
2328 "Silently discard pkts when matched\n")
2329
paul718e3742002-12-13 20:15:29 +00002330DEFUN (no_ipv6_route_pref,
2331 no_ipv6_route_pref_cmd,
2332 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <1-255>",
2333 NO_STR
2334 IP_STR
2335 "Establish static routes\n"
2336 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
2337 "IPv6 gateway address\n"
2338 "IPv6 gateway interface name\n"
2339 "Distance value for this prefix\n")
2340{
hasso81dfcaa2003-05-25 19:21:25 +00002341 return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, NULL, argv[2]);
2342}
2343
2344DEFUN (no_ipv6_route_flags_pref,
2345 no_ipv6_route_flags_pref_cmd,
2346 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) <1-255>",
2347 NO_STR
2348 IP_STR
2349 "Establish static routes\n"
2350 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
2351 "IPv6 gateway address\n"
2352 "IPv6 gateway interface name\n"
2353 "Emit an ICMP unreachable when matched\n"
2354 "Silently discard pkts when matched\n"
2355 "Distance value for this prefix\n")
2356{
2357 /* We do not care about argv[2] */
2358 return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, argv[2], argv[3]);
paul718e3742002-12-13 20:15:29 +00002359}
2360
2361DEFUN (no_ipv6_route_ifname_pref,
2362 no_ipv6_route_ifname_pref_cmd,
2363 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255>",
2364 NO_STR
2365 IP_STR
2366 "Establish static routes\n"
2367 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
2368 "IPv6 gateway address\n"
2369 "IPv6 gateway interface name\n"
2370 "Distance value for this prefix\n")
2371{
hasso81dfcaa2003-05-25 19:21:25 +00002372 return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], NULL, argv[3]);
2373}
2374
2375DEFUN (no_ipv6_route_ifname_flags_pref,
2376 no_ipv6_route_ifname_flags_pref_cmd,
2377 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) <1-255>",
2378 NO_STR
2379 IP_STR
2380 "Establish static routes\n"
2381 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
2382 "IPv6 gateway address\n"
2383 "IPv6 gateway interface name\n"
2384 "Emit an ICMP unreachable when matched\n"
2385 "Silently discard pkts when matched\n"
2386 "Distance value for this prefix\n")
2387{
2388 return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], argv[3], argv[4]);
paul718e3742002-12-13 20:15:29 +00002389}
2390
paul718e3742002-12-13 20:15:29 +00002391DEFUN (show_ipv6_route,
2392 show_ipv6_route_cmd,
2393 "show ipv6 route",
2394 SHOW_STR
2395 IP_STR
2396 "IPv6 routing table\n")
2397{
2398 struct route_table *table;
2399 struct route_node *rn;
2400 struct rib *rib;
2401 int first = 1;
Feng Lu4364ee52015-05-22 11:40:03 +02002402 vrf_id_t vrf_id = VRF_DEFAULT;
paul718e3742002-12-13 20:15:29 +00002403
Feng Lu4364ee52015-05-22 11:40:03 +02002404 if (argc > 0)
2405 VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
2406
2407 table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
paul718e3742002-12-13 20:15:29 +00002408 if (! table)
2409 return CMD_SUCCESS;
2410
2411 /* Show all IPv6 route. */
2412 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00002413 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +00002414 {
2415 if (first)
2416 {
David Lampartere0ca5fd2009-09-16 01:52:42 +02002417 vty_out (vty, SHOW_ROUTE_V6_HEADER);
paul718e3742002-12-13 20:15:29 +00002418 first = 0;
2419 }
Timo Teräs53a5c392015-05-23 11:08:40 +03002420 vty_show_ip_route (vty, rn, rib);
paul718e3742002-12-13 20:15:29 +00002421 }
2422 return CMD_SUCCESS;
2423}
2424
Feng Lu4364ee52015-05-22 11:40:03 +02002425ALIAS (show_ipv6_route,
2426 show_ipv6_route_vrf_cmd,
2427 "show ipv6 route " VRF_CMD_STR,
2428 SHOW_STR
2429 IP_STR
2430 "IPv6 routing table\n"
2431 VRF_CMD_HELP_STR)
2432
paul718e3742002-12-13 20:15:29 +00002433DEFUN (show_ipv6_route_prefix_longer,
2434 show_ipv6_route_prefix_longer_cmd,
2435 "show ipv6 route X:X::X:X/M longer-prefixes",
2436 SHOW_STR
2437 IP_STR
2438 "IPv6 routing table\n"
2439 "IPv6 prefix\n"
2440 "Show route matching the specified Network/Mask pair only\n")
2441{
2442 struct route_table *table;
2443 struct route_node *rn;
2444 struct rib *rib;
2445 struct prefix p;
2446 int ret;
2447 int first = 1;
Feng Lu4364ee52015-05-22 11:40:03 +02002448 vrf_id_t vrf_id = VRF_DEFAULT;
paul718e3742002-12-13 20:15:29 +00002449
2450 ret = str2prefix (argv[0], &p);
2451 if (! ret)
2452 {
2453 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
2454 return CMD_WARNING;
2455 }
2456
Feng Lu4364ee52015-05-22 11:40:03 +02002457 if (argc > 1)
2458 VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]);
2459
2460 table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
2461 if (! table)
2462 return CMD_SUCCESS;
2463
paul718e3742002-12-13 20:15:29 +00002464 /* Show matched type IPv6 routes. */
2465 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00002466 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +00002467 if (prefix_match (&p, &rn->p))
2468 {
2469 if (first)
2470 {
David Lampartere0ca5fd2009-09-16 01:52:42 +02002471 vty_out (vty, SHOW_ROUTE_V6_HEADER);
paul718e3742002-12-13 20:15:29 +00002472 first = 0;
2473 }
Timo Teräs53a5c392015-05-23 11:08:40 +03002474 vty_show_ip_route (vty, rn, rib);
paul718e3742002-12-13 20:15:29 +00002475 }
2476 return CMD_SUCCESS;
2477}
2478
Feng Lu4364ee52015-05-22 11:40:03 +02002479ALIAS (show_ipv6_route_prefix_longer,
2480 show_ipv6_route_prefix_longer_vrf_cmd,
2481 "show ipv6 route X:X::X:X/M longer-prefixes " VRF_CMD_STR,
2482 SHOW_STR
2483 IP_STR
2484 "IPv6 routing table\n"
2485 "IPv6 prefix\n"
2486 "Show route matching the specified Network/Mask pair only\n"
2487 VRF_CMD_HELP_STR)
2488
paul718e3742002-12-13 20:15:29 +00002489DEFUN (show_ipv6_route_protocol,
2490 show_ipv6_route_protocol_cmd,
David Lampartere0ca5fd2009-09-16 01:52:42 +02002491 "show ipv6 route " QUAGGA_IP6_REDIST_STR_ZEBRA,
paul718e3742002-12-13 20:15:29 +00002492 SHOW_STR
2493 IP_STR
2494 "IP routing table\n"
David Lampartere0ca5fd2009-09-16 01:52:42 +02002495 QUAGGA_IP6_REDIST_HELP_STR_ZEBRA)
paul718e3742002-12-13 20:15:29 +00002496{
2497 int type;
2498 struct route_table *table;
2499 struct route_node *rn;
2500 struct rib *rib;
2501 int first = 1;
Feng Lu4364ee52015-05-22 11:40:03 +02002502 vrf_id_t vrf_id = VRF_DEFAULT;
paul718e3742002-12-13 20:15:29 +00002503
David Lampartere0ca5fd2009-09-16 01:52:42 +02002504 type = proto_redistnum (AFI_IP6, argv[0]);
2505 if (type < 0)
paul718e3742002-12-13 20:15:29 +00002506 {
2507 vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
2508 return CMD_WARNING;
2509 }
Feng Lu4364ee52015-05-22 11:40:03 +02002510
2511 if (argc > 1)
2512 VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]);
2513
2514 table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
paul718e3742002-12-13 20:15:29 +00002515 if (! table)
2516 return CMD_SUCCESS;
2517
2518 /* Show matched type IPv6 routes. */
2519 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00002520 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +00002521 if (rib->type == type)
2522 {
2523 if (first)
2524 {
David Lampartere0ca5fd2009-09-16 01:52:42 +02002525 vty_out (vty, SHOW_ROUTE_V6_HEADER);
paul718e3742002-12-13 20:15:29 +00002526 first = 0;
2527 }
Timo Teräs53a5c392015-05-23 11:08:40 +03002528 vty_show_ip_route (vty, rn, rib);
paul718e3742002-12-13 20:15:29 +00002529 }
2530 return CMD_SUCCESS;
2531}
2532
Feng Lu4364ee52015-05-22 11:40:03 +02002533ALIAS (show_ipv6_route_protocol,
2534 show_ipv6_route_protocol_vrf_cmd,
2535 "show ipv6 route " QUAGGA_IP6_REDIST_STR_ZEBRA " " VRF_CMD_STR,
2536 SHOW_STR
2537 IP_STR
2538 "IP routing table\n"
2539 QUAGGA_IP6_REDIST_HELP_STR_ZEBRA
2540 VRF_CMD_HELP_STR)
2541
paul718e3742002-12-13 20:15:29 +00002542DEFUN (show_ipv6_route_addr,
2543 show_ipv6_route_addr_cmd,
2544 "show ipv6 route X:X::X:X",
2545 SHOW_STR
2546 IP_STR
2547 "IPv6 routing table\n"
2548 "IPv6 Address\n")
2549{
2550 int ret;
2551 struct prefix_ipv6 p;
2552 struct route_table *table;
2553 struct route_node *rn;
Feng Lu4364ee52015-05-22 11:40:03 +02002554 vrf_id_t vrf_id = VRF_DEFAULT;
paul718e3742002-12-13 20:15:29 +00002555
2556 ret = str2prefix_ipv6 (argv[0], &p);
2557 if (ret <= 0)
2558 {
2559 vty_out (vty, "Malformed IPv6 address%s", VTY_NEWLINE);
2560 return CMD_WARNING;
2561 }
2562
Feng Lu4364ee52015-05-22 11:40:03 +02002563 if (argc > 1)
2564 VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]);
2565
2566 table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
paul718e3742002-12-13 20:15:29 +00002567 if (! table)
2568 return CMD_SUCCESS;
2569
2570 rn = route_node_match (table, (struct prefix *) &p);
2571 if (! rn)
2572 {
2573 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
2574 return CMD_WARNING;
2575 }
2576
Timo Teräs53a5c392015-05-23 11:08:40 +03002577 vty_show_ip_route_detail (vty, rn, 0);
paul718e3742002-12-13 20:15:29 +00002578
2579 route_unlock_node (rn);
2580
2581 return CMD_SUCCESS;
2582}
2583
Feng Lu4364ee52015-05-22 11:40:03 +02002584ALIAS (show_ipv6_route_addr,
2585 show_ipv6_route_addr_vrf_cmd,
2586 "show ipv6 route X:X::X:X " VRF_CMD_STR,
2587 SHOW_STR
2588 IP_STR
2589 "IPv6 routing table\n"
2590 "IPv6 Address\n"
2591 VRF_CMD_HELP_STR)
2592
paul718e3742002-12-13 20:15:29 +00002593DEFUN (show_ipv6_route_prefix,
2594 show_ipv6_route_prefix_cmd,
2595 "show ipv6 route X:X::X:X/M",
2596 SHOW_STR
2597 IP_STR
2598 "IPv6 routing table\n"
2599 "IPv6 prefix\n")
2600{
2601 int ret;
2602 struct prefix_ipv6 p;
2603 struct route_table *table;
2604 struct route_node *rn;
Feng Lu4364ee52015-05-22 11:40:03 +02002605 vrf_id_t vrf_id = VRF_DEFAULT;
paul718e3742002-12-13 20:15:29 +00002606
2607 ret = str2prefix_ipv6 (argv[0], &p);
2608 if (ret <= 0)
2609 {
2610 vty_out (vty, "Malformed IPv6 prefix%s", VTY_NEWLINE);
2611 return CMD_WARNING;
2612 }
2613
Feng Lu4364ee52015-05-22 11:40:03 +02002614 if (argc > 1)
2615 VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]);
2616
2617 table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
paul718e3742002-12-13 20:15:29 +00002618 if (! table)
2619 return CMD_SUCCESS;
2620
2621 rn = route_node_match (table, (struct prefix *) &p);
2622 if (! rn || rn->p.prefixlen != p.prefixlen)
2623 {
2624 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
Lu Feng969d3552014-10-21 06:24:07 +00002625 if (rn)
2626 route_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00002627 return CMD_WARNING;
2628 }
2629
Timo Teräs53a5c392015-05-23 11:08:40 +03002630 vty_show_ip_route_detail (vty, rn, 0);
paul718e3742002-12-13 20:15:29 +00002631
2632 route_unlock_node (rn);
2633
2634 return CMD_SUCCESS;
2635}
2636
Feng Lu4364ee52015-05-22 11:40:03 +02002637ALIAS (show_ipv6_route_prefix,
2638 show_ipv6_route_prefix_vrf_cmd,
2639 "show ipv6 route X:X::X:X/M " VRF_CMD_STR,
2640 SHOW_STR
2641 IP_STR
2642 "IPv6 routing table\n"
2643 "IPv6 prefix\n"
2644 VRF_CMD_HELP_STR)
2645
Stig Thormodsrud61691c92008-11-04 15:45:07 -08002646/* Show route summary. */
2647DEFUN (show_ipv6_route_summary,
2648 show_ipv6_route_summary_cmd,
2649 "show ipv6 route summary",
2650 SHOW_STR
2651 IP_STR
2652 "IPv6 routing table\n"
2653 "Summary of all IPv6 routes\n")
2654{
2655 struct route_table *table;
Feng Lu4364ee52015-05-22 11:40:03 +02002656 vrf_id_t vrf_id = VRF_DEFAULT;
Stig Thormodsrud61691c92008-11-04 15:45:07 -08002657
Feng Lu4364ee52015-05-22 11:40:03 +02002658 if (argc > 0)
2659 VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
2660
2661 table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
Stig Thormodsrud61691c92008-11-04 15:45:07 -08002662 if (! table)
2663 return CMD_SUCCESS;
2664
2665 vty_show_ip_route_summary (vty, table);
2666
2667 return CMD_SUCCESS;
2668}
2669
Feng Lu4364ee52015-05-22 11:40:03 +02002670ALIAS (show_ipv6_route_summary,
2671 show_ipv6_route_summary_vrf_cmd,
2672 "show ipv6 route summary " VRF_CMD_STR,
2673 SHOW_STR
2674 IP_STR
2675 "IPv6 routing table\n"
2676 "Summary of all IPv6 routes\n"
2677 VRF_CMD_HELP_STR)
2678
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07002679/* Show ipv6 route summary prefix. */
2680DEFUN (show_ipv6_route_summary_prefix,
2681 show_ipv6_route_summary_prefix_cmd,
2682 "show ipv6 route summary prefix",
2683 SHOW_STR
2684 IP_STR
2685 "IPv6 routing table\n"
2686 "Summary of all IPv6 routes\n"
2687 "Prefix routes\n")
2688{
2689 struct route_table *table;
Feng Lu4364ee52015-05-22 11:40:03 +02002690 vrf_id_t vrf_id = VRF_DEFAULT;
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07002691
Feng Lu4364ee52015-05-22 11:40:03 +02002692 if (argc > 0)
2693 VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
2694
2695 table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07002696 if (! table)
2697 return CMD_SUCCESS;
2698
2699 vty_show_ip_route_summary_prefix (vty, table);
2700
2701 return CMD_SUCCESS;
2702}
2703
Feng Lu4364ee52015-05-22 11:40:03 +02002704ALIAS (show_ipv6_route_summary_prefix,
2705 show_ipv6_route_summary_prefix_vrf_cmd,
2706 "show ipv6 route summary prefix " VRF_CMD_STR,
2707 SHOW_STR
2708 IP_STR
2709 "IPv6 routing table\n"
2710 "Summary of all IPv6 routes\n"
2711 "Prefix routes\n"
2712 VRF_CMD_HELP_STR)
2713
G.Balajicddf3912011-11-26 21:59:32 +04002714/*
G.Balajicddf3912011-11-26 21:59:32 +04002715 * Show IPv6 mroute command.Used to dump
2716 * the Multicast routing table.
2717 */
2718
2719DEFUN (show_ipv6_mroute,
2720 show_ipv6_mroute_cmd,
2721 "show ipv6 mroute",
2722 SHOW_STR
2723 IP_STR
2724 "IPv6 Multicast routing table\n")
2725{
2726 struct route_table *table;
2727 struct route_node *rn;
2728 struct rib *rib;
2729 int first = 1;
Feng Lu4364ee52015-05-22 11:40:03 +02002730 vrf_id_t vrf_id = VRF_DEFAULT;
G.Balajicddf3912011-11-26 21:59:32 +04002731
Feng Lu4364ee52015-05-22 11:40:03 +02002732 if (argc > 0)
2733 VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
2734
2735 table = zebra_vrf_table (AFI_IP6, SAFI_MULTICAST, vrf_id);
G.Balajicddf3912011-11-26 21:59:32 +04002736 if (! table)
2737 return CMD_SUCCESS;
2738
2739 /* Show all IPv6 route. */
2740 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00002741 RNODE_FOREACH_RIB (rn, rib)
G.Balajicddf3912011-11-26 21:59:32 +04002742 {
2743 if (first)
2744 {
G.Balajicb32fd62011-11-27 20:09:40 +05302745 vty_out (vty, SHOW_ROUTE_V6_HEADER);
G.Balajicddf3912011-11-26 21:59:32 +04002746 first = 0;
2747 }
Timo Teräs53a5c392015-05-23 11:08:40 +03002748 vty_show_ip_route (vty, rn, rib);
G.Balajicddf3912011-11-26 21:59:32 +04002749 }
2750 return CMD_SUCCESS;
2751}
2752
Feng Lu4364ee52015-05-22 11:40:03 +02002753ALIAS (show_ipv6_mroute,
2754 show_ipv6_mroute_vrf_cmd,
2755 "show ipv6 mroute " VRF_CMD_STR,
2756 SHOW_STR
2757 IP_STR
2758 "IPv6 Multicast routing table\n"
2759 VRF_CMD_HELP_STR)
2760
2761DEFUN (show_ipv6_route_vrf_all,
2762 show_ipv6_route_vrf_all_cmd,
2763 "show ipv6 route " VRF_ALL_CMD_STR,
2764 SHOW_STR
2765 IP_STR
2766 "IPv6 routing table\n"
2767 VRF_ALL_CMD_HELP_STR)
2768{
2769 struct route_table *table;
2770 struct route_node *rn;
2771 struct rib *rib;
2772 struct zebra_vrf *zvrf;
2773 vrf_iter_t iter;
2774 int first = 1;
2775
2776 for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
2777 {
2778 if ((zvrf = vrf_iter2info (iter)) == NULL ||
2779 (table = zvrf->table[AFI_IP6][SAFI_UNICAST]) == NULL)
2780 continue;
2781
2782 /* Show all IPv6 route. */
2783 for (rn = route_top (table); rn; rn = route_next (rn))
2784 RNODE_FOREACH_RIB (rn, rib)
2785 {
2786 if (first)
2787 {
2788 vty_out (vty, SHOW_ROUTE_V6_HEADER);
2789 first = 0;
2790 }
2791 vty_show_ip_route (vty, rn, rib);
2792 }
2793 }
2794
2795 return CMD_SUCCESS;
2796}
2797
2798DEFUN (show_ipv6_route_prefix_longer_vrf_all,
2799 show_ipv6_route_prefix_longer_vrf_all_cmd,
2800 "show ipv6 route X:X::X:X/M longer-prefixes " VRF_ALL_CMD_STR,
2801 SHOW_STR
2802 IP_STR
2803 "IPv6 routing table\n"
2804 "IPv6 prefix\n"
2805 "Show route matching the specified Network/Mask pair only\n"
2806 VRF_ALL_CMD_HELP_STR)
2807{
2808 struct route_table *table;
2809 struct route_node *rn;
2810 struct rib *rib;
2811 struct prefix p;
2812 struct zebra_vrf *zvrf;
2813 vrf_iter_t iter;
2814 int ret;
2815 int first = 1;
2816
2817 ret = str2prefix (argv[0], &p);
2818 if (! ret)
2819 {
2820 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
2821 return CMD_WARNING;
2822 }
2823
2824 for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
2825 {
2826 if ((zvrf = vrf_iter2info (iter)) == NULL ||
2827 (table = zvrf->table[AFI_IP6][SAFI_UNICAST]) == NULL)
2828 continue;
2829
2830 /* Show matched type IPv6 routes. */
2831 for (rn = route_top (table); rn; rn = route_next (rn))
2832 RNODE_FOREACH_RIB (rn, rib)
2833 if (prefix_match (&p, &rn->p))
2834 {
2835 if (first)
2836 {
2837 vty_out (vty, SHOW_ROUTE_V6_HEADER);
2838 first = 0;
2839 }
2840 vty_show_ip_route (vty, rn, rib);
2841 }
2842 }
2843
2844 return CMD_SUCCESS;
2845}
2846
2847DEFUN (show_ipv6_route_protocol_vrf_all,
2848 show_ipv6_route_protocol_vrf_all_cmd,
2849 "show ipv6 route " QUAGGA_IP6_REDIST_STR_ZEBRA " " VRF_ALL_CMD_STR,
2850 SHOW_STR
2851 IP_STR
2852 "IP routing table\n"
2853 QUAGGA_IP6_REDIST_HELP_STR_ZEBRA
2854 VRF_ALL_CMD_HELP_STR)
2855{
2856 int type;
2857 struct route_table *table;
2858 struct route_node *rn;
2859 struct rib *rib;
2860 struct zebra_vrf *zvrf;
2861 vrf_iter_t iter;
2862 int first = 1;
2863
2864 type = proto_redistnum (AFI_IP6, argv[0]);
2865 if (type < 0)
2866 {
2867 vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
2868 return CMD_WARNING;
2869 }
2870
2871 for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
2872 {
2873 if ((zvrf = vrf_iter2info (iter)) == NULL ||
2874 (table = zvrf->table[AFI_IP6][SAFI_UNICAST]) == NULL)
2875 continue;
2876
2877 /* Show matched type IPv6 routes. */
2878 for (rn = route_top (table); rn; rn = route_next (rn))
2879 RNODE_FOREACH_RIB (rn, rib)
2880 if (rib->type == type)
2881 {
2882 if (first)
2883 {
2884 vty_out (vty, SHOW_ROUTE_V6_HEADER);
2885 first = 0;
2886 }
2887 vty_show_ip_route (vty, rn, rib);
2888 }
2889 }
2890
2891 return CMD_SUCCESS;
2892}
2893
2894DEFUN (show_ipv6_route_addr_vrf_all,
2895 show_ipv6_route_addr_vrf_all_cmd,
2896 "show ipv6 route X:X::X:X " VRF_ALL_CMD_STR,
2897 SHOW_STR
2898 IP_STR
2899 "IPv6 routing table\n"
2900 "IPv6 Address\n"
2901 VRF_ALL_CMD_HELP_STR)
2902{
2903 int ret;
2904 struct prefix_ipv6 p;
2905 struct route_table *table;
2906 struct route_node *rn;
2907 struct zebra_vrf *zvrf;
2908 vrf_iter_t iter;
2909
2910 ret = str2prefix_ipv6 (argv[0], &p);
2911 if (ret <= 0)
2912 {
2913 vty_out (vty, "Malformed IPv6 address%s", VTY_NEWLINE);
2914 return CMD_WARNING;
2915 }
2916
2917 for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
2918 {
2919 if ((zvrf = vrf_iter2info (iter)) == NULL ||
2920 (table = zvrf->table[AFI_IP6][SAFI_UNICAST]) == NULL)
2921 continue;
2922
2923 rn = route_node_match (table, (struct prefix *) &p);
2924 if (! rn)
2925 continue;
2926
2927 vty_show_ip_route_detail (vty, rn, 0);
2928
2929 route_unlock_node (rn);
2930 }
2931
2932 return CMD_SUCCESS;
2933}
2934
2935DEFUN (show_ipv6_route_prefix_vrf_all,
2936 show_ipv6_route_prefix_vrf_all_cmd,
2937 "show ipv6 route X:X::X:X/M " VRF_ALL_CMD_STR,
2938 SHOW_STR
2939 IP_STR
2940 "IPv6 routing table\n"
2941 "IPv6 prefix\n"
2942 VRF_ALL_CMD_HELP_STR)
2943{
2944 int ret;
2945 struct prefix_ipv6 p;
2946 struct route_table *table;
2947 struct route_node *rn;
2948 struct zebra_vrf *zvrf;
2949 vrf_iter_t iter;
2950
2951 ret = str2prefix_ipv6 (argv[0], &p);
2952 if (ret <= 0)
2953 {
2954 vty_out (vty, "Malformed IPv6 prefix%s", VTY_NEWLINE);
2955 return CMD_WARNING;
2956 }
2957
2958 for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
2959 {
2960 if ((zvrf = vrf_iter2info (iter)) == NULL ||
2961 (table = zvrf->table[AFI_IP6][SAFI_UNICAST]) == NULL)
2962 continue;
2963
2964 rn = route_node_match (table, (struct prefix *) &p);
2965 if (! rn)
2966 continue;
2967 if (rn->p.prefixlen != p.prefixlen)
2968 {
2969 route_unlock_node (rn);
2970 continue;
2971 }
2972
2973 vty_show_ip_route_detail (vty, rn, 0);
2974
2975 route_unlock_node (rn);
2976 }
2977
2978 return CMD_SUCCESS;
2979}
2980
2981/* Show route summary. */
2982DEFUN (show_ipv6_route_summary_vrf_all,
2983 show_ipv6_route_summary_vrf_all_cmd,
2984 "show ipv6 route summary " VRF_ALL_CMD_STR,
2985 SHOW_STR
2986 IP_STR
2987 "IPv6 routing table\n"
2988 "Summary of all IPv6 routes\n"
2989 VRF_ALL_CMD_HELP_STR)
2990{
2991 struct zebra_vrf *zvrf;
2992 vrf_iter_t iter;
2993
2994 for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
2995 if ((zvrf = vrf_iter2info (iter)) != NULL)
2996 vty_show_ip_route_summary (vty, zvrf->table[AFI_IP6][SAFI_UNICAST]);
2997
2998 return CMD_SUCCESS;
2999}
3000
3001DEFUN (show_ipv6_mroute_vrf_all,
3002 show_ipv6_mroute_vrf_all_cmd,
3003 "show ipv6 mroute " VRF_ALL_CMD_STR,
3004 SHOW_STR
3005 IP_STR
3006 "IPv6 Multicast routing table\n"
3007 VRF_ALL_CMD_HELP_STR)
3008{
3009 struct route_table *table;
3010 struct route_node *rn;
3011 struct rib *rib;
3012 struct zebra_vrf *zvrf;
3013 vrf_iter_t iter;
3014 int first = 1;
3015
3016 for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
3017 {
3018 if ((zvrf = vrf_iter2info (iter)) == NULL ||
3019 (table = zvrf->table[AFI_IP6][SAFI_UNICAST]) == NULL)
3020 continue;
3021
3022 /* Show all IPv6 route. */
3023 for (rn = route_top (table); rn; rn = route_next (rn))
3024 RNODE_FOREACH_RIB (rn, rib)
3025 {
3026 if (first)
3027 {
3028 vty_out (vty, SHOW_ROUTE_V6_HEADER);
3029 first = 0;
3030 }
3031 vty_show_ip_route (vty, rn, rib);
3032 }
3033 }
3034 return CMD_SUCCESS;
3035}
3036
3037DEFUN (show_ipv6_route_summary_prefix_vrf_all,
3038 show_ipv6_route_summary_prefix_vrf_all_cmd,
3039 "show ipv6 route summary prefix " VRF_ALL_CMD_STR,
3040 SHOW_STR
3041 IP_STR
3042 "IPv6 routing table\n"
3043 "Summary of all IPv6 routes\n"
3044 "Prefix routes\n"
3045 VRF_ALL_CMD_HELP_STR)
3046{
3047 struct zebra_vrf *zvrf;
3048 vrf_iter_t iter;
3049
3050 for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
3051 if ((zvrf = vrf_iter2info (iter)) != NULL)
3052 vty_show_ip_route_summary_prefix (vty, zvrf->table[AFI_IP6][SAFI_UNICAST]);
3053
3054 return CMD_SUCCESS;
3055}
3056
paul718e3742002-12-13 20:15:29 +00003057/* Write IPv6 static route configuration. */
paula1ac18c2005-06-28 17:17:12 +00003058static int
paul718e3742002-12-13 20:15:29 +00003059static_config_ipv6 (struct vty *vty)
3060{
3061 struct route_node *rn;
3062 struct static_ipv6 *si;
3063 int write;
3064 char buf[BUFSIZ];
3065 struct route_table *stable;
3066
3067 write = 0;
3068
3069 /* Lookup table. */
Feng Lu41f44a22015-05-22 11:39:56 +02003070 stable = zebra_vrf_static_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +00003071 if (! stable)
3072 return -1;
3073
3074 for (rn = route_top (stable); rn; rn = route_next (rn))
3075 for (si = rn->info; si; si = si->next)
3076 {
Timo Teräs53a5c392015-05-23 11:08:40 +03003077 vty_out (vty, "ipv6 route %s", prefix2str (&rn->p, buf, sizeof buf));
paul718e3742002-12-13 20:15:29 +00003078
3079 switch (si->type)
3080 {
3081 case STATIC_IPV6_GATEWAY:
3082 vty_out (vty, " %s", inet_ntop (AF_INET6, &si->ipv6, buf, BUFSIZ));
3083 break;
3084 case STATIC_IPV6_IFNAME:
3085 vty_out (vty, " %s", si->ifname);
3086 break;
3087 case STATIC_IPV6_GATEWAY_IFNAME:
3088 vty_out (vty, " %s %s",
3089 inet_ntop (AF_INET6, &si->ipv6, buf, BUFSIZ), si->ifname);
3090 break;
3091 }
3092
hasso81dfcaa2003-05-25 19:21:25 +00003093 if (CHECK_FLAG(si->flags, ZEBRA_FLAG_REJECT))
3094 vty_out (vty, " %s", "reject");
3095
3096 if (CHECK_FLAG(si->flags, ZEBRA_FLAG_BLACKHOLE))
3097 vty_out (vty, " %s", "blackhole");
3098
paul718e3742002-12-13 20:15:29 +00003099 if (si->distance != ZEBRA_STATIC_DISTANCE_DEFAULT)
3100 vty_out (vty, " %d", si->distance);
3101 vty_out (vty, "%s", VTY_NEWLINE);
3102
3103 write = 1;
3104 }
3105 return write;
3106}
3107#endif /* HAVE_IPV6 */
3108
3109/* Static ip route configuration write function. */
paula1ac18c2005-06-28 17:17:12 +00003110static int
paul718e3742002-12-13 20:15:29 +00003111zebra_ip_config (struct vty *vty)
3112{
3113 int write = 0;
3114
Everton Marques33d86db2014-07-14 11:19:00 -03003115 write += static_config_ipv4 (vty, SAFI_UNICAST, "ip route");
3116 write += static_config_ipv4 (vty, SAFI_MULTICAST, "ip mroute");
paul718e3742002-12-13 20:15:29 +00003117#ifdef HAVE_IPV6
3118 write += static_config_ipv6 (vty);
3119#endif /* HAVE_IPV6 */
3120
3121 return write;
3122}
3123
David Lamparterbd078122015-01-06 19:53:24 +01003124static int config_write_vty(struct vty *vty)
3125{
Paul Jakma7514fb72007-05-02 16:05:35 +00003126 int i;
David Lamparterbd078122015-01-06 19:53:24 +01003127 enum multicast_mode ipv4_multicast_mode = multicast_mode_ipv4_get ();
3128
3129 if (ipv4_multicast_mode != MCAST_NO_CONFIG)
3130 vty_out (vty, "ip multicast rpf-lookup-mode %s%s",
3131 ipv4_multicast_mode == MCAST_URIB_ONLY ? "urib-only" :
3132 ipv4_multicast_mode == MCAST_MRIB_ONLY ? "mrib-only" :
3133 ipv4_multicast_mode == MCAST_MIX_MRIB_FIRST ? "mrib-then-urib" :
3134 ipv4_multicast_mode == MCAST_MIX_DISTANCE ? "lower-distance" :
3135 "longer-prefix",
3136 VTY_NEWLINE);
Paul Jakma7514fb72007-05-02 16:05:35 +00003137
3138 for (i=0;i<ZEBRA_ROUTE_MAX;i++)
3139 {
3140 if (proto_rm[AFI_IP][i])
3141 vty_out (vty, "ip protocol %s route-map %s%s", zebra_route_string(i),
3142 proto_rm[AFI_IP][i], VTY_NEWLINE);
3143 }
3144 if (proto_rm[AFI_IP][ZEBRA_ROUTE_MAX])
3145 vty_out (vty, "ip protocol %s route-map %s%s", "any",
3146 proto_rm[AFI_IP][ZEBRA_ROUTE_MAX], VTY_NEWLINE);
3147
3148 return 1;
3149}
3150
3151/* table node for protocol filtering */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -08003152static struct cmd_node protocol_node = { PROTOCOL_NODE, "", 1 };
Paul Jakma7514fb72007-05-02 16:05:35 +00003153
paul718e3742002-12-13 20:15:29 +00003154/* IP node for static routes. */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -08003155static struct cmd_node ip_node = { IP_NODE, "", 1 };
paul718e3742002-12-13 20:15:29 +00003156
3157/* Route VTY. */
3158void
paula1ac18c2005-06-28 17:17:12 +00003159zebra_vty_init (void)
paul718e3742002-12-13 20:15:29 +00003160{
3161 install_node (&ip_node, zebra_ip_config);
David Lamparterbd078122015-01-06 19:53:24 +01003162 install_node (&protocol_node, config_write_vty);
paul718e3742002-12-13 20:15:29 +00003163
Everton Marques33d86db2014-07-14 11:19:00 -03003164 install_element (CONFIG_NODE, &ip_mroute_cmd);
David Lampartera76681b2015-01-22 19:03:53 +01003165 install_element (CONFIG_NODE, &ip_mroute_dist_cmd);
Everton Marques33d86db2014-07-14 11:19:00 -03003166 install_element (CONFIG_NODE, &no_ip_mroute_cmd);
David Lampartera76681b2015-01-22 19:03:53 +01003167 install_element (CONFIG_NODE, &no_ip_mroute_dist_cmd);
David Lamparterbd078122015-01-06 19:53:24 +01003168 install_element (CONFIG_NODE, &ip_multicast_mode_cmd);
3169 install_element (CONFIG_NODE, &no_ip_multicast_mode_cmd);
3170 install_element (CONFIG_NODE, &no_ip_multicast_mode_noarg_cmd);
Paul Jakma7514fb72007-05-02 16:05:35 +00003171 install_element (CONFIG_NODE, &ip_protocol_cmd);
3172 install_element (CONFIG_NODE, &no_ip_protocol_cmd);
3173 install_element (VIEW_NODE, &show_ip_protocol_cmd);
3174 install_element (ENABLE_NODE, &show_ip_protocol_cmd);
paul718e3742002-12-13 20:15:29 +00003175 install_element (CONFIG_NODE, &ip_route_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00003176 install_element (CONFIG_NODE, &ip_route_flags_cmd);
hasso457ef552003-05-28 12:02:15 +00003177 install_element (CONFIG_NODE, &ip_route_flags2_cmd);
paul718e3742002-12-13 20:15:29 +00003178 install_element (CONFIG_NODE, &ip_route_mask_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00003179 install_element (CONFIG_NODE, &ip_route_mask_flags_cmd);
hasso457ef552003-05-28 12:02:15 +00003180 install_element (CONFIG_NODE, &ip_route_mask_flags2_cmd);
paul718e3742002-12-13 20:15:29 +00003181 install_element (CONFIG_NODE, &no_ip_route_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00003182 install_element (CONFIG_NODE, &no_ip_route_flags_cmd);
hasso457ef552003-05-28 12:02:15 +00003183 install_element (CONFIG_NODE, &no_ip_route_flags2_cmd);
paul718e3742002-12-13 20:15:29 +00003184 install_element (CONFIG_NODE, &no_ip_route_mask_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00003185 install_element (CONFIG_NODE, &no_ip_route_mask_flags_cmd);
hasso457ef552003-05-28 12:02:15 +00003186 install_element (CONFIG_NODE, &no_ip_route_mask_flags2_cmd);
paul718e3742002-12-13 20:15:29 +00003187 install_element (CONFIG_NODE, &ip_route_distance_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00003188 install_element (CONFIG_NODE, &ip_route_flags_distance_cmd);
hasso457ef552003-05-28 12:02:15 +00003189 install_element (CONFIG_NODE, &ip_route_flags_distance2_cmd);
paul718e3742002-12-13 20:15:29 +00003190 install_element (CONFIG_NODE, &ip_route_mask_distance_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00003191 install_element (CONFIG_NODE, &ip_route_mask_flags_distance_cmd);
hasso457ef552003-05-28 12:02:15 +00003192 install_element (CONFIG_NODE, &ip_route_mask_flags_distance2_cmd);
paul718e3742002-12-13 20:15:29 +00003193 install_element (CONFIG_NODE, &no_ip_route_distance_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00003194 install_element (CONFIG_NODE, &no_ip_route_flags_distance_cmd);
hasso457ef552003-05-28 12:02:15 +00003195 install_element (CONFIG_NODE, &no_ip_route_flags_distance2_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00003196 install_element (CONFIG_NODE, &no_ip_route_mask_flags_distance_cmd);
hasso457ef552003-05-28 12:02:15 +00003197 install_element (CONFIG_NODE, &no_ip_route_mask_flags_distance2_cmd);
paul718e3742002-12-13 20:15:29 +00003198
3199 install_element (VIEW_NODE, &show_ip_route_cmd);
3200 install_element (VIEW_NODE, &show_ip_route_addr_cmd);
3201 install_element (VIEW_NODE, &show_ip_route_prefix_cmd);
3202 install_element (VIEW_NODE, &show_ip_route_prefix_longer_cmd);
3203 install_element (VIEW_NODE, &show_ip_route_protocol_cmd);
3204 install_element (VIEW_NODE, &show_ip_route_supernets_cmd);
Stig Thormodsrud61691c92008-11-04 15:45:07 -08003205 install_element (VIEW_NODE, &show_ip_route_summary_cmd);
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07003206 install_element (VIEW_NODE, &show_ip_route_summary_prefix_cmd);
paul718e3742002-12-13 20:15:29 +00003207 install_element (ENABLE_NODE, &show_ip_route_cmd);
3208 install_element (ENABLE_NODE, &show_ip_route_addr_cmd);
3209 install_element (ENABLE_NODE, &show_ip_route_prefix_cmd);
3210 install_element (ENABLE_NODE, &show_ip_route_prefix_longer_cmd);
3211 install_element (ENABLE_NODE, &show_ip_route_protocol_cmd);
3212 install_element (ENABLE_NODE, &show_ip_route_supernets_cmd);
paul718e3742002-12-13 20:15:29 +00003213 install_element (ENABLE_NODE, &show_ip_route_summary_cmd);
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07003214 install_element (ENABLE_NODE, &show_ip_route_summary_prefix_cmd);
paul718e3742002-12-13 20:15:29 +00003215
G.Balajicddf3912011-11-26 21:59:32 +04003216 install_element (VIEW_NODE, &show_ip_mroute_cmd);
3217 install_element (ENABLE_NODE, &show_ip_mroute_cmd);
3218
Everton Marques33d86db2014-07-14 11:19:00 -03003219 install_element (VIEW_NODE, &show_ip_rpf_cmd);
3220 install_element (ENABLE_NODE, &show_ip_rpf_cmd);
David Lamparter3b02fe82015-01-22 19:12:35 +01003221 install_element (VIEW_NODE, &show_ip_rpf_addr_cmd);
3222 install_element (ENABLE_NODE, &show_ip_rpf_addr_cmd);
G.Balajicddf3912011-11-26 21:59:32 +04003223
Feng Lu4364ee52015-05-22 11:40:03 +02003224 /* Commands for VRF */
3225
3226 install_element (VIEW_NODE, &show_ip_route_vrf_cmd);
3227 install_element (VIEW_NODE, &show_ip_route_addr_vrf_cmd);
3228 install_element (VIEW_NODE, &show_ip_route_prefix_vrf_cmd);
3229 install_element (VIEW_NODE, &show_ip_route_prefix_longer_vrf_cmd);
3230 install_element (VIEW_NODE, &show_ip_route_protocol_vrf_cmd);
3231 install_element (VIEW_NODE, &show_ip_route_supernets_vrf_cmd);
3232 install_element (VIEW_NODE, &show_ip_route_summary_vrf_cmd);
3233 install_element (VIEW_NODE, &show_ip_route_summary_prefix_vrf_cmd);
3234 install_element (ENABLE_NODE, &show_ip_route_vrf_cmd);
3235 install_element (ENABLE_NODE, &show_ip_route_addr_vrf_cmd);
3236 install_element (ENABLE_NODE, &show_ip_route_prefix_vrf_cmd);
3237 install_element (ENABLE_NODE, &show_ip_route_prefix_longer_vrf_cmd);
3238 install_element (ENABLE_NODE, &show_ip_route_protocol_vrf_cmd);
3239 install_element (ENABLE_NODE, &show_ip_route_supernets_vrf_cmd);
3240 install_element (ENABLE_NODE, &show_ip_route_summary_vrf_cmd);
3241 install_element (ENABLE_NODE, &show_ip_route_summary_prefix_vrf_cmd);
3242
3243 install_element (VIEW_NODE, &show_ip_route_vrf_all_cmd);
3244 install_element (VIEW_NODE, &show_ip_route_addr_vrf_all_cmd);
3245 install_element (VIEW_NODE, &show_ip_route_prefix_vrf_all_cmd);
3246 install_element (VIEW_NODE, &show_ip_route_prefix_longer_vrf_all_cmd);
3247 install_element (VIEW_NODE, &show_ip_route_protocol_vrf_all_cmd);
3248 install_element (VIEW_NODE, &show_ip_route_supernets_vrf_all_cmd);
3249 install_element (VIEW_NODE, &show_ip_route_summary_vrf_all_cmd);
3250 install_element (VIEW_NODE, &show_ip_route_summary_prefix_vrf_all_cmd);
3251 install_element (ENABLE_NODE, &show_ip_route_vrf_all_cmd);
3252 install_element (ENABLE_NODE, &show_ip_route_addr_vrf_all_cmd);
3253 install_element (ENABLE_NODE, &show_ip_route_prefix_vrf_all_cmd);
3254 install_element (ENABLE_NODE, &show_ip_route_prefix_longer_vrf_all_cmd);
3255 install_element (ENABLE_NODE, &show_ip_route_protocol_vrf_all_cmd);
3256 install_element (ENABLE_NODE, &show_ip_route_supernets_vrf_all_cmd);
3257 install_element (ENABLE_NODE, &show_ip_route_summary_vrf_all_cmd);
3258 install_element (ENABLE_NODE, &show_ip_route_summary_prefix_vrf_all_cmd);
3259
3260 install_element (VIEW_NODE, &show_ip_mroute_vrf_cmd);
3261 install_element (ENABLE_NODE, &show_ip_mroute_vrf_cmd);
3262
3263 install_element (VIEW_NODE, &show_ip_mroute_vrf_all_cmd);
3264 install_element (ENABLE_NODE, &show_ip_mroute_vrf_all_cmd);
3265
3266 install_element (VIEW_NODE, &show_ip_rpf_vrf_cmd);
3267 install_element (VIEW_NODE, &show_ip_rpf_vrf_all_cmd);
3268 install_element (VIEW_NODE, &show_ip_rpf_addr_vrf_cmd);
3269 install_element (VIEW_NODE, &show_ip_rpf_addr_vrf_all_cmd);
3270 install_element (ENABLE_NODE, &show_ip_rpf_vrf_cmd);
3271 install_element (ENABLE_NODE, &show_ip_rpf_vrf_all_cmd);
3272 install_element (ENABLE_NODE, &show_ip_rpf_addr_vrf_cmd);
3273 install_element (ENABLE_NODE, &show_ip_rpf_addr_vrf_all_cmd);
3274
paul718e3742002-12-13 20:15:29 +00003275#ifdef HAVE_IPV6
3276 install_element (CONFIG_NODE, &ipv6_route_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00003277 install_element (CONFIG_NODE, &ipv6_route_flags_cmd);
paul718e3742002-12-13 20:15:29 +00003278 install_element (CONFIG_NODE, &ipv6_route_ifname_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00003279 install_element (CONFIG_NODE, &ipv6_route_ifname_flags_cmd);
paul718e3742002-12-13 20:15:29 +00003280 install_element (CONFIG_NODE, &no_ipv6_route_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00003281 install_element (CONFIG_NODE, &no_ipv6_route_flags_cmd);
paul718e3742002-12-13 20:15:29 +00003282 install_element (CONFIG_NODE, &no_ipv6_route_ifname_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00003283 install_element (CONFIG_NODE, &no_ipv6_route_ifname_flags_cmd);
paul718e3742002-12-13 20:15:29 +00003284 install_element (CONFIG_NODE, &ipv6_route_pref_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00003285 install_element (CONFIG_NODE, &ipv6_route_flags_pref_cmd);
paul718e3742002-12-13 20:15:29 +00003286 install_element (CONFIG_NODE, &ipv6_route_ifname_pref_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00003287 install_element (CONFIG_NODE, &ipv6_route_ifname_flags_pref_cmd);
paul718e3742002-12-13 20:15:29 +00003288 install_element (CONFIG_NODE, &no_ipv6_route_pref_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00003289 install_element (CONFIG_NODE, &no_ipv6_route_flags_pref_cmd);
paul718e3742002-12-13 20:15:29 +00003290 install_element (CONFIG_NODE, &no_ipv6_route_ifname_pref_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00003291 install_element (CONFIG_NODE, &no_ipv6_route_ifname_flags_pref_cmd);
paul718e3742002-12-13 20:15:29 +00003292 install_element (VIEW_NODE, &show_ipv6_route_cmd);
Stig Thormodsrud61691c92008-11-04 15:45:07 -08003293 install_element (VIEW_NODE, &show_ipv6_route_summary_cmd);
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07003294 install_element (VIEW_NODE, &show_ipv6_route_summary_prefix_cmd);
paul718e3742002-12-13 20:15:29 +00003295 install_element (VIEW_NODE, &show_ipv6_route_protocol_cmd);
3296 install_element (VIEW_NODE, &show_ipv6_route_addr_cmd);
3297 install_element (VIEW_NODE, &show_ipv6_route_prefix_cmd);
3298 install_element (VIEW_NODE, &show_ipv6_route_prefix_longer_cmd);
3299 install_element (ENABLE_NODE, &show_ipv6_route_cmd);
3300 install_element (ENABLE_NODE, &show_ipv6_route_protocol_cmd);
3301 install_element (ENABLE_NODE, &show_ipv6_route_addr_cmd);
3302 install_element (ENABLE_NODE, &show_ipv6_route_prefix_cmd);
3303 install_element (ENABLE_NODE, &show_ipv6_route_prefix_longer_cmd);
Stig Thormodsrud61691c92008-11-04 15:45:07 -08003304 install_element (ENABLE_NODE, &show_ipv6_route_summary_cmd);
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07003305 install_element (ENABLE_NODE, &show_ipv6_route_summary_prefix_cmd);
G.Balajicddf3912011-11-26 21:59:32 +04003306
3307 install_element (VIEW_NODE, &show_ipv6_mroute_cmd);
3308 install_element (ENABLE_NODE, &show_ipv6_mroute_cmd);
Feng Lu4364ee52015-05-22 11:40:03 +02003309
3310 /* Commands for VRF */
3311
3312 install_element (VIEW_NODE, &show_ipv6_route_vrf_cmd);
3313 install_element (VIEW_NODE, &show_ipv6_route_summary_vrf_cmd);
3314 install_element (VIEW_NODE, &show_ipv6_route_summary_prefix_vrf_cmd);
3315 install_element (VIEW_NODE, &show_ipv6_route_protocol_vrf_cmd);
3316 install_element (VIEW_NODE, &show_ipv6_route_addr_vrf_cmd);
3317 install_element (VIEW_NODE, &show_ipv6_route_prefix_vrf_cmd);
3318 install_element (VIEW_NODE, &show_ipv6_route_prefix_longer_vrf_cmd);
3319 install_element (ENABLE_NODE, &show_ipv6_route_vrf_cmd);
3320 install_element (ENABLE_NODE, &show_ipv6_route_protocol_vrf_cmd);
3321 install_element (ENABLE_NODE, &show_ipv6_route_addr_vrf_cmd);
3322 install_element (ENABLE_NODE, &show_ipv6_route_prefix_vrf_cmd);
3323 install_element (ENABLE_NODE, &show_ipv6_route_prefix_longer_vrf_cmd);
3324 install_element (ENABLE_NODE, &show_ipv6_route_summary_vrf_cmd);
3325 install_element (ENABLE_NODE, &show_ipv6_route_summary_prefix_vrf_cmd);
3326
3327 install_element (VIEW_NODE, &show_ipv6_route_vrf_all_cmd);
3328 install_element (VIEW_NODE, &show_ipv6_route_summary_vrf_all_cmd);
3329 install_element (VIEW_NODE, &show_ipv6_route_summary_prefix_vrf_all_cmd);
3330 install_element (VIEW_NODE, &show_ipv6_route_protocol_vrf_all_cmd);
3331 install_element (VIEW_NODE, &show_ipv6_route_addr_vrf_all_cmd);
3332 install_element (VIEW_NODE, &show_ipv6_route_prefix_vrf_all_cmd);
3333 install_element (VIEW_NODE, &show_ipv6_route_prefix_longer_vrf_all_cmd);
3334 install_element (ENABLE_NODE, &show_ipv6_route_vrf_all_cmd);
3335 install_element (ENABLE_NODE, &show_ipv6_route_protocol_vrf_all_cmd);
3336 install_element (ENABLE_NODE, &show_ipv6_route_addr_vrf_all_cmd);
3337 install_element (ENABLE_NODE, &show_ipv6_route_prefix_vrf_all_cmd);
3338 install_element (ENABLE_NODE, &show_ipv6_route_prefix_longer_vrf_all_cmd);
3339 install_element (ENABLE_NODE, &show_ipv6_route_summary_vrf_all_cmd);
3340 install_element (ENABLE_NODE, &show_ipv6_route_summary_prefix_vrf_all_cmd);
3341
3342 install_element (VIEW_NODE, &show_ipv6_mroute_vrf_cmd);
3343 install_element (ENABLE_NODE, &show_ipv6_mroute_vrf_cmd);
3344
3345 install_element (VIEW_NODE, &show_ipv6_mroute_vrf_all_cmd);
3346 install_element (ENABLE_NODE, &show_ipv6_mroute_vrf_all_cmd);
paul718e3742002-12-13 20:15:29 +00003347#endif /* HAVE_IPV6 */
3348}