blob: bc453de967feed4f8feae5c173fc8df54022ea51 [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"
30
paula1ac18c2005-06-28 17:17:12 +000031#include "zebra/zserv.h"
32
Everton Marques33d86db2014-07-14 11:19:00 -030033static int do_show_ip_route(struct vty *vty, safi_t safi);
David Lamparter3b02fe82015-01-22 19:12:35 +010034static void vty_show_ip_route_detail (struct vty *vty, struct route_node *rn,
35 int mcast);
Everton Marques33d86db2014-07-14 11:19:00 -030036
37/* General function for static route. */
paula1ac18c2005-06-28 17:17:12 +000038static int
Everton Marques33d86db2014-07-14 11:19:00 -030039zebra_static_ipv4_safi (struct vty *vty, safi_t safi, int add_cmd,
40 const char *dest_str, const char *mask_str,
41 const char *gate_str, const char *flag_str,
42 const char *distance_str)
paul718e3742002-12-13 20:15:29 +000043{
44 int ret;
45 u_char distance;
46 struct prefix p;
47 struct in_addr gate;
48 struct in_addr mask;
hasso39db97e2004-10-12 20:50:58 +000049 const char *ifname;
hasso81dfcaa2003-05-25 19:21:25 +000050 u_char flag = 0;
paul718e3742002-12-13 20:15:29 +000051
52 ret = str2prefix (dest_str, &p);
53 if (ret <= 0)
54 {
55 vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
56 return CMD_WARNING;
57 }
58
59 /* Cisco like mask notation. */
60 if (mask_str)
61 {
62 ret = inet_aton (mask_str, &mask);
63 if (ret == 0)
paul595db7f2003-05-25 21:35:06 +000064 {
65 vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
66 return CMD_WARNING;
67 }
paul718e3742002-12-13 20:15:29 +000068 p.prefixlen = ip_masklen (mask);
69 }
70
71 /* Apply mask for given prefix. */
72 apply_mask (&p);
73
paul595db7f2003-05-25 21:35:06 +000074 /* Administrative distance. */
75 if (distance_str)
76 distance = atoi (distance_str);
77 else
78 distance = ZEBRA_STATIC_DISTANCE_DEFAULT;
79
80 /* Null0 static route. */
hasso457ef552003-05-28 12:02:15 +000081 if ((gate_str != NULL) && (strncasecmp (gate_str, "Null0", strlen (gate_str)) == 0))
paul595db7f2003-05-25 21:35:06 +000082 {
83 if (flag_str)
84 {
85 vty_out (vty, "%% can not have flag %s with Null0%s", flag_str, VTY_NEWLINE);
86 return CMD_WARNING;
87 }
88 if (add_cmd)
Everton Marques33d86db2014-07-14 11:19:00 -030089 static_add_ipv4_safi (safi, &p, NULL, NULL, ZEBRA_FLAG_BLACKHOLE, distance, 0);
paul595db7f2003-05-25 21:35:06 +000090 else
Everton Marques33d86db2014-07-14 11:19:00 -030091 static_delete_ipv4_safi (safi, &p, NULL, NULL, distance, 0);
paul595db7f2003-05-25 21:35:06 +000092 return CMD_SUCCESS;
93 }
94
hasso81dfcaa2003-05-25 19:21:25 +000095 /* Route flags */
96 if (flag_str) {
97 switch(flag_str[0]) {
98 case 'r':
99 case 'R': /* XXX */
100 SET_FLAG (flag, ZEBRA_FLAG_REJECT);
101 break;
102 case 'b':
103 case 'B': /* XXX */
104 SET_FLAG (flag, ZEBRA_FLAG_BLACKHOLE);
105 break;
106 default:
107 vty_out (vty, "%% Malformed flag %s %s", flag_str, VTY_NEWLINE);
paul595db7f2003-05-25 21:35:06 +0000108 return CMD_WARNING;
hasso81dfcaa2003-05-25 19:21:25 +0000109 }
110 }
111
hasso457ef552003-05-28 12:02:15 +0000112 if (gate_str == NULL)
113 {
114 if (add_cmd)
Everton Marques33d86db2014-07-14 11:19:00 -0300115 static_add_ipv4_safi (safi, &p, NULL, NULL, flag, distance, 0);
hasso457ef552003-05-28 12:02:15 +0000116 else
Everton Marques33d86db2014-07-14 11:19:00 -0300117 static_delete_ipv4_safi (safi, &p, NULL, NULL, distance, 0);
hasso457ef552003-05-28 12:02:15 +0000118
119 return CMD_SUCCESS;
120 }
121
paul718e3742002-12-13 20:15:29 +0000122 /* When gateway is A.B.C.D format, gate is treated as nexthop
123 address other case gate is treated as interface name. */
124 ret = inet_aton (gate_str, &gate);
125 if (ret)
126 ifname = NULL;
127 else
128 ifname = gate_str;
129
130 if (add_cmd)
Everton Marques33d86db2014-07-14 11:19:00 -0300131 static_add_ipv4_safi (safi, &p, ifname ? NULL : &gate, ifname, flag, distance, 0);
paul718e3742002-12-13 20:15:29 +0000132 else
Everton Marques33d86db2014-07-14 11:19:00 -0300133 static_delete_ipv4_safi (safi, &p, ifname ? NULL : &gate, ifname, distance, 0);
paul718e3742002-12-13 20:15:29 +0000134
135 return CMD_SUCCESS;
136}
137
Everton Marques33d86db2014-07-14 11:19:00 -0300138static int
139zebra_static_ipv4 (struct vty *vty, int add_cmd, const char *dest_str,
140 const char *mask_str, const char *gate_str,
141 const char *flag_str, const char *distance_str)
142{
143 return zebra_static_ipv4_safi(vty, SAFI_UNICAST, add_cmd, dest_str, mask_str, gate_str, flag_str, distance_str);
144}
145
146/* Static unicast routes for multicast RPF lookup. */
David Lampartera76681b2015-01-22 19:03:53 +0100147DEFUN (ip_mroute_dist,
148 ip_mroute_dist_cmd,
149 "ip mroute A.B.C.D/M (A.B.C.D|INTERFACE) <1-255>",
Everton Marques33d86db2014-07-14 11:19:00 -0300150 IP_STR
151 "Configure static unicast route into MRIB for multicast RPF lookup\n"
152 "IP destination prefix (e.g. 10.0.0.0/8)\n"
153 "Nexthop address\n"
154 "Nexthop interface name\n"
155 "Distance\n")
156{
David Lamparter863f20c2015-01-27 20:24:15 +0100157 VTY_WARN_EXPERIMENTAL();
David Lampartera76681b2015-01-22 19:03:53 +0100158 return zebra_static_ipv4_safi(vty, SAFI_MULTICAST, 1, argv[0], NULL, argv[1],
159 NULL, argc > 2 ? argv[2] : NULL);
Everton Marques33d86db2014-07-14 11:19:00 -0300160}
161
David Lampartera76681b2015-01-22 19:03:53 +0100162ALIAS (ip_mroute_dist,
163 ip_mroute_cmd,
164 "ip mroute A.B.C.D/M (A.B.C.D|INTERFACE)",
165 IP_STR
166 "Configure static unicast route into MRIB for multicast RPF lookup\n"
167 "IP destination prefix (e.g. 10.0.0.0/8)\n"
168 "Nexthop address\n"
169 "Nexthop interface name\n")
170
171DEFUN (no_ip_mroute_dist,
172 no_ip_mroute_dist_cmd,
173 "no ip mroute A.B.C.D/M (A.B.C.D|INTERFACE) <1-255>",
Everton Marques33d86db2014-07-14 11:19:00 -0300174 IP_STR
175 "Configure static unicast route into MRIB for multicast RPF lookup\n"
176 "IP destination prefix (e.g. 10.0.0.0/8)\n"
177 "Nexthop address\n"
178 "Nexthop interface name\n"
179 "Distance\n")
180{
David Lamparter863f20c2015-01-27 20:24:15 +0100181 VTY_WARN_EXPERIMENTAL();
David Lampartera76681b2015-01-22 19:03:53 +0100182 return zebra_static_ipv4_safi(vty, SAFI_MULTICAST, 0, argv[0], NULL, argv[1],
183 NULL, argc > 2 ? argv[2] : NULL);
Everton Marques33d86db2014-07-14 11:19:00 -0300184}
185
David Lampartera76681b2015-01-22 19:03:53 +0100186ALIAS (no_ip_mroute_dist,
187 no_ip_mroute_cmd,
188 "no ip mroute A.B.C.D/M (A.B.C.D|INTERFACE)",
189 NO_STR
190 IP_STR
191 "Configure static unicast route into MRIB for multicast RPF lookup\n"
192 "IP destination prefix (e.g. 10.0.0.0/8)\n"
193 "Nexthop address\n"
194 "Nexthop interface name\n")
195
David Lamparterbd078122015-01-06 19:53:24 +0100196DEFUN (ip_multicast_mode,
197 ip_multicast_mode_cmd,
198 "ip multicast rpf-lookup-mode (urib-only|mrib-only|mrib-then-urib|lower-distance|longer-prefix)",
199 IP_STR
200 "Multicast options\n"
201 "RPF lookup behavior\n"
202 "Lookup in unicast RIB only\n"
203 "Lookup in multicast RIB only\n"
204 "Try multicast RIB first, fall back to unicast RIB\n"
205 "Lookup both, use entry with lower distance\n"
206 "Lookup both, use entry with longer prefix\n")
207{
David Lamparter863f20c2015-01-27 20:24:15 +0100208 VTY_WARN_EXPERIMENTAL();
209
David Lamparterbd078122015-01-06 19:53:24 +0100210 if (!strncmp (argv[0], "u", 1))
211 multicast_mode_ipv4_set (MCAST_URIB_ONLY);
212 else if (!strncmp (argv[0], "mrib-o", 6))
213 multicast_mode_ipv4_set (MCAST_MRIB_ONLY);
214 else if (!strncmp (argv[0], "mrib-t", 6))
215 multicast_mode_ipv4_set (MCAST_MIX_MRIB_FIRST);
216 else if (!strncmp (argv[0], "low", 3))
217 multicast_mode_ipv4_set (MCAST_MIX_DISTANCE);
218 else if (!strncmp (argv[0], "lon", 3))
219 multicast_mode_ipv4_set (MCAST_MIX_PFXLEN);
220 else
221 {
222 vty_out (vty, "Invalid mode specified%s", VTY_NEWLINE);
223 return CMD_WARNING;
224 }
225
226 return CMD_SUCCESS;
227}
228
229DEFUN (no_ip_multicast_mode,
230 no_ip_multicast_mode_cmd,
231 "no ip multicast rpf-lookup-mode (urib-only|mrib-only|mrib-then-urib|lower-distance|longer-prefix)",
232 NO_STR
233 IP_STR
234 "Multicast options\n"
235 "RPF lookup behavior\n"
236 "Lookup in unicast RIB only\n"
237 "Lookup in multicast RIB only\n"
238 "Try multicast RIB first, fall back to unicast RIB\n"
239 "Lookup both, use entry with lower distance\n"
240 "Lookup both, use entry with longer prefix\n")
241{
242 multicast_mode_ipv4_set (MCAST_NO_CONFIG);
243 return CMD_SUCCESS;
244}
245
246ALIAS (no_ip_multicast_mode,
247 no_ip_multicast_mode_noarg_cmd,
248 "no ip multicast rpf-lookup-mode",
249 NO_STR
250 IP_STR
251 "Multicast options\n"
252 "RPF lookup behavior\n")
253
Everton Marques33d86db2014-07-14 11:19:00 -0300254DEFUN (show_ip_rpf,
255 show_ip_rpf_cmd,
256 "show ip rpf",
257 SHOW_STR
258 IP_STR
259 "Display RPF information for multicast source\n")
260{
David Lamparter863f20c2015-01-27 20:24:15 +0100261 VTY_WARN_EXPERIMENTAL();
Everton Marques33d86db2014-07-14 11:19:00 -0300262 return do_show_ip_route(vty, SAFI_MULTICAST);
263}
264
David Lamparter3b02fe82015-01-22 19:12:35 +0100265DEFUN (show_ip_rpf_addr,
266 show_ip_rpf_addr_cmd,
267 "show ip rpf A.B.C.D",
268 SHOW_STR
269 IP_STR
270 "Display RPF information for multicast source\n"
271 "IP multicast source address (e.g. 10.0.0.0)\n")
272{
273 struct in_addr addr;
274 struct route_node *rn;
275 struct rib *rib;
276 int ret;
277
David Lamparter863f20c2015-01-27 20:24:15 +0100278 VTY_WARN_EXPERIMENTAL();
279
David Lamparter3b02fe82015-01-22 19:12:35 +0100280 ret = inet_aton (argv[0], &addr);
281 if (ret == 0)
282 {
283 vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
284 return CMD_WARNING;
285 }
286
287 rib = rib_match_ipv4_multicast (addr, &rn);
288
289 if (rib)
290 vty_show_ip_route_detail (vty, rn, 1);
291 else
292 vty_out (vty, "%% No match for RPF lookup%s", VTY_NEWLINE);
293
294 return CMD_SUCCESS;
295}
296
paul718e3742002-12-13 20:15:29 +0000297/* Static route configuration. */
298DEFUN (ip_route,
299 ip_route_cmd,
paul595db7f2003-05-25 21:35:06 +0000300 "ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0)",
hasso81dfcaa2003-05-25 19:21:25 +0000301 IP_STR
302 "Establish static routes\n"
303 "IP destination prefix (e.g. 10.0.0.0/8)\n"
304 "IP gateway address\n"
paul595db7f2003-05-25 21:35:06 +0000305 "IP gateway interface name\n"
306 "Null interface\n")
hasso81dfcaa2003-05-25 19:21:25 +0000307{
308 return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], NULL, NULL);
309}
310
311DEFUN (ip_route_flags,
312 ip_route_flags_cmd,
313 "ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole)",
paul718e3742002-12-13 20:15:29 +0000314 IP_STR
315 "Establish static routes\n"
316 "IP destination prefix (e.g. 10.0.0.0/8)\n"
317 "IP gateway address\n"
318 "IP gateway interface name\n"
hasso81dfcaa2003-05-25 19:21:25 +0000319 "Emit an ICMP unreachable when matched\n"
320 "Silently discard pkts when matched\n")
paul718e3742002-12-13 20:15:29 +0000321{
hasso81dfcaa2003-05-25 19:21:25 +0000322 return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], argv[2], NULL);
paul718e3742002-12-13 20:15:29 +0000323}
324
hasso457ef552003-05-28 12:02:15 +0000325DEFUN (ip_route_flags2,
326 ip_route_flags2_cmd,
327 "ip route A.B.C.D/M (reject|blackhole)",
328 IP_STR
329 "Establish static routes\n"
330 "IP destination prefix (e.g. 10.0.0.0/8)\n"
331 "Emit an ICMP unreachable when matched\n"
332 "Silently discard pkts when matched\n")
333{
334 return zebra_static_ipv4 (vty, 1, argv[0], NULL, NULL, argv[1], NULL);
335}
336
paul718e3742002-12-13 20:15:29 +0000337/* Mask as A.B.C.D format. */
338DEFUN (ip_route_mask,
339 ip_route_mask_cmd,
paul595db7f2003-05-25 21:35:06 +0000340 "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0)",
hasso81dfcaa2003-05-25 19:21:25 +0000341 IP_STR
342 "Establish static routes\n"
343 "IP destination prefix\n"
344 "IP destination prefix mask\n"
345 "IP gateway address\n"
paul595db7f2003-05-25 21:35:06 +0000346 "IP gateway interface name\n"
347 "Null interface\n")
hasso81dfcaa2003-05-25 19:21:25 +0000348{
349 return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], NULL, NULL);
350}
351
352DEFUN (ip_route_mask_flags,
353 ip_route_mask_flags_cmd,
354 "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole)",
paul718e3742002-12-13 20:15:29 +0000355 IP_STR
356 "Establish static routes\n"
357 "IP destination prefix\n"
358 "IP destination prefix mask\n"
359 "IP gateway address\n"
360 "IP gateway interface name\n"
hasso81dfcaa2003-05-25 19:21:25 +0000361 "Emit an ICMP unreachable when matched\n"
362 "Silently discard pkts when matched\n")
paul718e3742002-12-13 20:15:29 +0000363{
hasso81dfcaa2003-05-25 19:21:25 +0000364 return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], argv[3], NULL);
paul718e3742002-12-13 20:15:29 +0000365}
366
hasso457ef552003-05-28 12:02:15 +0000367DEFUN (ip_route_mask_flags2,
368 ip_route_mask_flags2_cmd,
369 "ip route A.B.C.D A.B.C.D (reject|blackhole)",
370 IP_STR
371 "Establish static routes\n"
372 "IP destination prefix\n"
373 "IP destination prefix mask\n"
374 "Emit an ICMP unreachable when matched\n"
375 "Silently discard pkts when matched\n")
376{
377 return zebra_static_ipv4 (vty, 1, argv[0], argv[1], NULL, argv[2], NULL);
378}
379
paul718e3742002-12-13 20:15:29 +0000380/* Distance option value. */
381DEFUN (ip_route_distance,
382 ip_route_distance_cmd,
paul595db7f2003-05-25 21:35:06 +0000383 "ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0) <1-255>",
paul718e3742002-12-13 20:15:29 +0000384 IP_STR
385 "Establish static routes\n"
386 "IP destination prefix (e.g. 10.0.0.0/8)\n"
387 "IP gateway address\n"
388 "IP gateway interface name\n"
paul595db7f2003-05-25 21:35:06 +0000389 "Null interface\n"
paul718e3742002-12-13 20:15:29 +0000390 "Distance value for this route\n")
391{
hasso81dfcaa2003-05-25 19:21:25 +0000392 return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], NULL, argv[2]);
393}
394
395DEFUN (ip_route_flags_distance,
396 ip_route_flags_distance_cmd,
397 "ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
398 IP_STR
399 "Establish static routes\n"
400 "IP destination prefix (e.g. 10.0.0.0/8)\n"
401 "IP gateway address\n"
402 "IP gateway interface name\n"
403 "Emit an ICMP unreachable when matched\n"
404 "Silently discard pkts when matched\n"
405 "Distance value for this route\n")
406{
407 return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], argv[2], argv[3]);
paul718e3742002-12-13 20:15:29 +0000408}
409
hasso457ef552003-05-28 12:02:15 +0000410DEFUN (ip_route_flags_distance2,
411 ip_route_flags_distance2_cmd,
412 "ip route A.B.C.D/M (reject|blackhole) <1-255>",
413 IP_STR
414 "Establish static routes\n"
415 "IP destination prefix (e.g. 10.0.0.0/8)\n"
416 "Emit an ICMP unreachable when matched\n"
417 "Silently discard pkts when matched\n"
418 "Distance value for this route\n")
419{
420 return zebra_static_ipv4 (vty, 1, argv[0], NULL, NULL, argv[1], argv[2]);
421}
422
paul718e3742002-12-13 20:15:29 +0000423DEFUN (ip_route_mask_distance,
424 ip_route_mask_distance_cmd,
paul595db7f2003-05-25 21:35:06 +0000425 "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0) <1-255>",
paul718e3742002-12-13 20:15:29 +0000426 IP_STR
427 "Establish static routes\n"
428 "IP destination prefix\n"
429 "IP destination prefix mask\n"
430 "IP gateway address\n"
431 "IP gateway interface name\n"
paul595db7f2003-05-25 21:35:06 +0000432 "Null interface\n"
paul718e3742002-12-13 20:15:29 +0000433 "Distance value for this route\n")
434{
hasso81dfcaa2003-05-25 19:21:25 +0000435 return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], NULL, argv[3]);
436}
437
438DEFUN (ip_route_mask_flags_distance,
439 ip_route_mask_flags_distance_cmd,
440 "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
441 IP_STR
442 "Establish static routes\n"
443 "IP destination prefix\n"
444 "IP destination prefix mask\n"
445 "IP gateway address\n"
446 "IP gateway interface name\n"
hasso81dfcaa2003-05-25 19:21:25 +0000447 "Emit an ICMP unreachable when matched\n"
Christian Franke2b005152013-09-30 12:27:49 +0000448 "Silently discard pkts when matched\n"
449 "Distance value for this route\n")
hasso81dfcaa2003-05-25 19:21:25 +0000450{
451 return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], argv[3], argv[4]);
paul718e3742002-12-13 20:15:29 +0000452}
453
hasso457ef552003-05-28 12:02:15 +0000454DEFUN (ip_route_mask_flags_distance2,
455 ip_route_mask_flags_distance2_cmd,
456 "ip route A.B.C.D A.B.C.D (reject|blackhole) <1-255>",
457 IP_STR
458 "Establish static routes\n"
459 "IP destination prefix\n"
460 "IP destination prefix mask\n"
hasso457ef552003-05-28 12:02:15 +0000461 "Emit an ICMP unreachable when matched\n"
Christian Franke2b005152013-09-30 12:27:49 +0000462 "Silently discard pkts when matched\n"
463 "Distance value for this route\n")
hasso457ef552003-05-28 12:02:15 +0000464{
465 return zebra_static_ipv4 (vty, 1, argv[0], argv[1], NULL, argv[2], argv[3]);
466}
467
paul718e3742002-12-13 20:15:29 +0000468DEFUN (no_ip_route,
469 no_ip_route_cmd,
paul595db7f2003-05-25 21:35:06 +0000470 "no ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0)",
hasso81dfcaa2003-05-25 19:21:25 +0000471 NO_STR
472 IP_STR
473 "Establish static routes\n"
474 "IP destination prefix (e.g. 10.0.0.0/8)\n"
475 "IP gateway address\n"
paul595db7f2003-05-25 21:35:06 +0000476 "IP gateway interface name\n"
477 "Null interface\n")
hasso81dfcaa2003-05-25 19:21:25 +0000478{
479 return zebra_static_ipv4 (vty, 0, argv[0], NULL, argv[1], NULL, NULL);
480}
481
482ALIAS (no_ip_route,
483 no_ip_route_flags_cmd,
484 "no ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole)",
paul718e3742002-12-13 20:15:29 +0000485 NO_STR
486 IP_STR
487 "Establish static routes\n"
488 "IP destination prefix (e.g. 10.0.0.0/8)\n"
489 "IP gateway address\n"
490 "IP gateway interface name\n"
hasso81dfcaa2003-05-25 19:21:25 +0000491 "Emit an ICMP unreachable when matched\n"
492 "Silently discard pkts when matched\n")
paul718e3742002-12-13 20:15:29 +0000493
hasso457ef552003-05-28 12:02:15 +0000494DEFUN (no_ip_route_flags2,
495 no_ip_route_flags2_cmd,
496 "no ip route A.B.C.D/M (reject|blackhole)",
497 NO_STR
498 IP_STR
499 "Establish static routes\n"
500 "IP destination prefix (e.g. 10.0.0.0/8)\n"
501 "Emit an ICMP unreachable when matched\n"
502 "Silently discard pkts when matched\n")
503{
504 return zebra_static_ipv4 (vty, 0, argv[0], NULL, NULL, NULL, NULL);
505}
506
paul718e3742002-12-13 20:15:29 +0000507DEFUN (no_ip_route_mask,
508 no_ip_route_mask_cmd,
paul595db7f2003-05-25 21:35:06 +0000509 "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0)",
hasso81dfcaa2003-05-25 19:21:25 +0000510 NO_STR
511 IP_STR
512 "Establish static routes\n"
513 "IP destination prefix\n"
514 "IP destination prefix mask\n"
515 "IP gateway address\n"
paul595db7f2003-05-25 21:35:06 +0000516 "IP gateway interface name\n"
517 "Null interface\n")
hasso81dfcaa2003-05-25 19:21:25 +0000518{
519 return zebra_static_ipv4 (vty, 0, argv[0], argv[1], argv[2], NULL, NULL);
520}
521
522ALIAS (no_ip_route_mask,
523 no_ip_route_mask_flags_cmd,
524 "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole)",
paul718e3742002-12-13 20:15:29 +0000525 NO_STR
526 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"
hasso81dfcaa2003-05-25 19:21:25 +0000532 "Emit an ICMP unreachable when matched\n"
533 "Silently discard pkts when matched\n")
paul718e3742002-12-13 20:15:29 +0000534
hasso457ef552003-05-28 12:02:15 +0000535DEFUN (no_ip_route_mask_flags2,
536 no_ip_route_mask_flags2_cmd,
537 "no ip route A.B.C.D A.B.C.D (reject|blackhole)",
538 NO_STR
539 IP_STR
540 "Establish static routes\n"
541 "IP destination prefix\n"
542 "IP destination prefix mask\n"
543 "Emit an ICMP unreachable when matched\n"
544 "Silently discard pkts when matched\n")
545{
546 return zebra_static_ipv4 (vty, 0, argv[0], argv[1], NULL, NULL, NULL);
547}
548
paul718e3742002-12-13 20:15:29 +0000549DEFUN (no_ip_route_distance,
550 no_ip_route_distance_cmd,
paul595db7f2003-05-25 21:35:06 +0000551 "no ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0) <1-255>",
paul718e3742002-12-13 20:15:29 +0000552 NO_STR
553 IP_STR
554 "Establish static routes\n"
555 "IP destination prefix (e.g. 10.0.0.0/8)\n"
556 "IP gateway address\n"
557 "IP gateway interface name\n"
paul595db7f2003-05-25 21:35:06 +0000558 "Null interface\n"
paul718e3742002-12-13 20:15:29 +0000559 "Distance value for this route\n")
560{
hasso81dfcaa2003-05-25 19:21:25 +0000561 return zebra_static_ipv4 (vty, 0, argv[0], NULL, argv[1], NULL, argv[2]);
562}
563
564DEFUN (no_ip_route_flags_distance,
565 no_ip_route_flags_distance_cmd,
566 "no ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
567 NO_STR
568 IP_STR
569 "Establish static routes\n"
570 "IP destination prefix (e.g. 10.0.0.0/8)\n"
571 "IP gateway address\n"
572 "IP gateway interface name\n"
573 "Emit an ICMP unreachable when matched\n"
574 "Silently discard pkts when matched\n"
575 "Distance value for this route\n")
576{
577 return zebra_static_ipv4 (vty, 0, argv[0], NULL, argv[1], argv[2], argv[3]);
paul718e3742002-12-13 20:15:29 +0000578}
579
hasso457ef552003-05-28 12:02:15 +0000580DEFUN (no_ip_route_flags_distance2,
581 no_ip_route_flags_distance2_cmd,
582 "no ip route A.B.C.D/M (reject|blackhole) <1-255>",
583 NO_STR
584 IP_STR
585 "Establish static routes\n"
586 "IP destination prefix (e.g. 10.0.0.0/8)\n"
587 "Emit an ICMP unreachable when matched\n"
588 "Silently discard pkts when matched\n"
589 "Distance value for this route\n")
590{
591 return zebra_static_ipv4 (vty, 0, argv[0], NULL, NULL, argv[1], argv[2]);
592}
593
paul718e3742002-12-13 20:15:29 +0000594DEFUN (no_ip_route_mask_distance,
595 no_ip_route_mask_distance_cmd,
paul595db7f2003-05-25 21:35:06 +0000596 "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 +0000597 NO_STR
598 IP_STR
599 "Establish static routes\n"
600 "IP destination prefix\n"
601 "IP destination prefix mask\n"
602 "IP gateway address\n"
603 "IP gateway interface name\n"
paul595db7f2003-05-25 21:35:06 +0000604 "Null interface\n"
paul718e3742002-12-13 20:15:29 +0000605 "Distance value for this route\n")
606{
hasso81dfcaa2003-05-25 19:21:25 +0000607 return zebra_static_ipv4 (vty, 0, argv[0], argv[1], argv[2], NULL, argv[3]);
608}
609
610DEFUN (no_ip_route_mask_flags_distance,
611 no_ip_route_mask_flags_distance_cmd,
612 "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
613 NO_STR
614 IP_STR
615 "Establish static routes\n"
616 "IP destination prefix\n"
617 "IP destination prefix mask\n"
618 "IP gateway address\n"
619 "IP gateway interface name\n"
620 "Emit an ICMP unreachable when matched\n"
621 "Silently discard pkts when matched\n"
622 "Distance value for this route\n")
623{
624 return zebra_static_ipv4 (vty, 0, argv[0], argv[1], argv[2], argv[3], argv[4]);
paul718e3742002-12-13 20:15:29 +0000625}
626
hasso457ef552003-05-28 12:02:15 +0000627DEFUN (no_ip_route_mask_flags_distance2,
628 no_ip_route_mask_flags_distance2_cmd,
629 "no ip route A.B.C.D A.B.C.D (reject|blackhole) <1-255>",
630 NO_STR
631 IP_STR
632 "Establish static routes\n"
633 "IP destination prefix\n"
634 "IP destination prefix mask\n"
635 "Emit an ICMP unreachable when matched\n"
636 "Silently discard pkts when matched\n"
637 "Distance value for this route\n")
638{
639 return zebra_static_ipv4 (vty, 0, argv[0], argv[1], NULL, argv[2], argv[3]);
640}
641
Paul Jakma7514fb72007-05-02 16:05:35 +0000642char *proto_rm[AFI_MAX][ZEBRA_ROUTE_MAX+1]; /* "any" == ZEBRA_ROUTE_MAX */
643
644DEFUN (ip_protocol,
645 ip_protocol_cmd,
646 "ip protocol PROTO route-map ROUTE-MAP",
647 NO_STR
648 "Apply route map to PROTO\n"
649 "Protocol name\n"
650 "Route map name\n")
651{
652 int i;
653
654 if (strcasecmp(argv[0], "any") == 0)
655 i = ZEBRA_ROUTE_MAX;
656 else
657 i = proto_name2num(argv[0]);
658 if (i < 0)
659 {
660 vty_out (vty, "invalid protocol name \"%s\"%s", argv[0] ? argv[0] : "",
661 VTY_NEWLINE);
662 return CMD_WARNING;
663 }
664 if (proto_rm[AFI_IP][i])
665 XFREE (MTYPE_ROUTE_MAP_NAME, proto_rm[AFI_IP][i]);
666 proto_rm[AFI_IP][i] = XSTRDUP (MTYPE_ROUTE_MAP_NAME, argv[1]);
667 return CMD_SUCCESS;
668}
669
670DEFUN (no_ip_protocol,
671 no_ip_protocol_cmd,
672 "no ip protocol PROTO",
673 NO_STR
674 "Remove route map from PROTO\n"
675 "Protocol name\n")
676{
677 int i;
678
679 if (strcasecmp(argv[0], "any") == 0)
680 i = ZEBRA_ROUTE_MAX;
681 else
682 i = proto_name2num(argv[0]);
683 if (i < 0)
684 {
685 vty_out (vty, "invalid protocol name \"%s\"%s", argv[0] ? argv[0] : "",
686 VTY_NEWLINE);
687 return CMD_WARNING;
688 }
689 if (proto_rm[AFI_IP][i])
690 XFREE (MTYPE_ROUTE_MAP_NAME, proto_rm[AFI_IP][i]);
691 proto_rm[AFI_IP][i] = NULL;
692 return CMD_SUCCESS;
693}
694
paul718e3742002-12-13 20:15:29 +0000695/* New RIB. Detailed information for IPv4 route. */
paula1ac18c2005-06-28 17:17:12 +0000696static void
David Lamparter3b02fe82015-01-22 19:12:35 +0100697vty_show_ip_route_detail (struct vty *vty, struct route_node *rn, int mcast)
paul718e3742002-12-13 20:15:29 +0000698{
699 struct rib *rib;
Christian Frankefa713d92013-07-05 15:35:37 +0000700 struct nexthop *nexthop, *tnexthop;
701 int recursing;
Timo Teräs53a5c392015-05-23 11:08:40 +0300702 char buf[PREFIX_STRLEN];
paul718e3742002-12-13 20:15:29 +0000703
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000704 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +0000705 {
David Lamparterb7cce952015-03-07 08:40:48 +0100706 const char *mcast_info = "";
David Lamparter3b02fe82015-01-22 19:12:35 +0100707 if (mcast)
708 {
709 rib_table_info_t *info = rn->table->info;
710 mcast_info = (info->safi == SAFI_MULTICAST)
711 ? " using Multicast RIB"
712 : " using Unicast RIB";
713 }
Timo Teräs53a5c392015-05-23 11:08:40 +0300714 vty_out (vty, "Routing entry for %s%s%s",
715 prefix2str (&rn->p, buf, sizeof(buf)), mcast_info,
716 VTY_NEWLINE);
ajsf52d13c2005-10-01 17:38:06 +0000717 vty_out (vty, " Known via \"%s\"", zebra_route_string (rib->type));
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +0200718 vty_out (vty, ", distance %u, metric %u", rib->distance, rib->metric);
paul718e3742002-12-13 20:15:29 +0000719 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
Timo Teräs53a5c392015-05-23 11:08:40 +0300720 vty_out (vty, ", best");
paul718e3742002-12-13 20:15:29 +0000721 if (rib->refcnt)
Timo Teräs53a5c392015-05-23 11:08:40 +0300722 vty_out (vty, ", refcnt %ld", rib->refcnt);
hasso81dfcaa2003-05-25 19:21:25 +0000723 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
724 vty_out (vty, ", blackhole");
725 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT))
726 vty_out (vty, ", reject");
paul718e3742002-12-13 20:15:29 +0000727 vty_out (vty, "%s", VTY_NEWLINE);
728
729#define ONE_DAY_SECOND 60*60*24
730#define ONE_WEEK_SECOND 60*60*24*7
731 if (rib->type == ZEBRA_ROUTE_RIP
Timo Teräs53a5c392015-05-23 11:08:40 +0300732 || rib->type == ZEBRA_ROUTE_RIPNG
733 || rib->type == ZEBRA_ROUTE_OSPF
734 || rib->type == ZEBRA_ROUTE_OSPF6
735 || rib->type == ZEBRA_ROUTE_BABEL
736 || rib->type == ZEBRA_ROUTE_ISIS
737 || rib->type == ZEBRA_ROUTE_BGP)
paul718e3742002-12-13 20:15:29 +0000738 {
739 time_t uptime;
740 struct tm *tm;
741
742 uptime = time (NULL);
743 uptime -= rib->uptime;
744 tm = gmtime (&uptime);
745
746 vty_out (vty, " Last update ");
747
748 if (uptime < ONE_DAY_SECOND)
749 vty_out (vty, "%02d:%02d:%02d",
750 tm->tm_hour, tm->tm_min, tm->tm_sec);
751 else if (uptime < ONE_WEEK_SECOND)
752 vty_out (vty, "%dd%02dh%02dm",
753 tm->tm_yday, tm->tm_hour, tm->tm_min);
754 else
755 vty_out (vty, "%02dw%dd%02dh",
756 tm->tm_yday/7,
757 tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
758 vty_out (vty, " ago%s", VTY_NEWLINE);
759 }
760
Christian Frankefa713d92013-07-05 15:35:37 +0000761 for (ALL_NEXTHOPS_RO(rib->nexthop, nexthop, tnexthop, recursing))
Timo Teräs53a5c392015-05-23 11:08:40 +0300762 {
763 vty_out (vty, " %c%s",
764 CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB) ? '*' : ' ',
765 recursing ? " " : "");
Paul Jakma7514fb72007-05-02 16:05:35 +0000766
Timo Teräs53a5c392015-05-23 11:08:40 +0300767 switch (nexthop->type)
768 {
769 case NEXTHOP_TYPE_IPV4:
770 case NEXTHOP_TYPE_IPV4_IFINDEX:
771 vty_out (vty, " %s", inet_ntoa (nexthop->gate.ipv4));
772 if (nexthop->ifindex)
773 vty_out (vty, ", via %s", ifindex2ifname (nexthop->ifindex));
774 break;
775 case NEXTHOP_TYPE_IPV6:
776 case NEXTHOP_TYPE_IPV6_IFINDEX:
777 case NEXTHOP_TYPE_IPV6_IFNAME:
778 vty_out (vty, " %s",
779 inet_ntop (AF_INET6, &nexthop->gate.ipv6, buf, sizeof(buf)));
780 if (nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME)
781 vty_out (vty, ", %s", nexthop->ifname);
782 else if (nexthop->ifindex)
783 vty_out (vty, ", via %s", ifindex2ifname (nexthop->ifindex));
784 break;
785 case NEXTHOP_TYPE_IFINDEX:
786 vty_out (vty, " directly connected, %s",
787 ifindex2ifname (nexthop->ifindex));
788 break;
789 case NEXTHOP_TYPE_IFNAME:
790 vty_out (vty, " directly connected, %s", nexthop->ifname);
791 break;
792 case NEXTHOP_TYPE_BLACKHOLE:
793 vty_out (vty, " directly connected, Null0");
794 break;
795 default:
796 break;
797 }
798 if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
799 vty_out (vty, " inactive");
paul718e3742002-12-13 20:15:29 +0000800
Timo Teräs53a5c392015-05-23 11:08:40 +0300801 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ONLINK))
802 vty_out (vty, " onlink");
paul718e3742002-12-13 20:15:29 +0000803
Timo Teräs53a5c392015-05-23 11:08:40 +0300804 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
805 vty_out (vty, " (recursive)");
Christian Frankee8d3d292013-07-05 15:35:39 +0000806
Timo Teräs53a5c392015-05-23 11:08:40 +0300807 switch (nexthop->type)
Paul Jakma7514fb72007-05-02 16:05:35 +0000808 {
809 case NEXTHOP_TYPE_IPV4:
810 case NEXTHOP_TYPE_IPV4_IFINDEX:
811 case NEXTHOP_TYPE_IPV4_IFNAME:
812 if (nexthop->src.ipv4.s_addr)
813 {
Timo Teräs53a5c392015-05-23 11:08:40 +0300814 if (inet_ntop(AF_INET, &nexthop->src.ipv4, buf, sizeof buf))
815 vty_out (vty, ", src %s", buf);
Paul Jakma7514fb72007-05-02 16:05:35 +0000816 }
817 break;
Andrew J. Schorr09303312007-05-30 20:10:34 +0000818#ifdef HAVE_IPV6
Paul Jakma7514fb72007-05-02 16:05:35 +0000819 case NEXTHOP_TYPE_IPV6:
820 case NEXTHOP_TYPE_IPV6_IFINDEX:
821 case NEXTHOP_TYPE_IPV6_IFNAME:
822 if (!IPV6_ADDR_SAME(&nexthop->src.ipv6, &in6addr_any))
823 {
Timo Teräs53a5c392015-05-23 11:08:40 +0300824 if (inet_ntop(AF_INET6, &nexthop->src.ipv6, buf, sizeof buf))
825 vty_out (vty, ", src %s", buf);
Paul Jakma7514fb72007-05-02 16:05:35 +0000826 }
827 break;
Andrew J. Schorr09303312007-05-30 20:10:34 +0000828#endif /* HAVE_IPV6 */
Paul Jakma7514fb72007-05-02 16:05:35 +0000829 default:
Timo Teräs53a5c392015-05-23 11:08:40 +0300830 break;
Paul Jakma7514fb72007-05-02 16:05:35 +0000831 }
Timo Teräs53a5c392015-05-23 11:08:40 +0300832 vty_out (vty, "%s", VTY_NEWLINE);
833 }
paul718e3742002-12-13 20:15:29 +0000834 vty_out (vty, "%s", VTY_NEWLINE);
835 }
836}
837
paula1ac18c2005-06-28 17:17:12 +0000838static void
paul718e3742002-12-13 20:15:29 +0000839vty_show_ip_route (struct vty *vty, struct route_node *rn, struct rib *rib)
840{
Christian Frankefa713d92013-07-05 15:35:37 +0000841 struct nexthop *nexthop, *tnexthop;
842 int recursing;
paul718e3742002-12-13 20:15:29 +0000843 int len = 0;
844 char buf[BUFSIZ];
845
846 /* Nexthop information. */
Christian Frankefa713d92013-07-05 15:35:37 +0000847 for (ALL_NEXTHOPS_RO(rib->nexthop, nexthop, tnexthop, recursing))
paul718e3742002-12-13 20:15:29 +0000848 {
849 if (nexthop == rib->nexthop)
850 {
851 /* Prefix information. */
Timo Teräs53a5c392015-05-23 11:08:40 +0300852 len = vty_out (vty, "%c%c%c %s",
ajsf52d13c2005-10-01 17:38:06 +0000853 zebra_route_char (rib->type),
paul718e3742002-12-13 20:15:29 +0000854 CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED)
855 ? '>' : ' ',
856 CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
857 ? '*' : ' ',
Timo Teräs53a5c392015-05-23 11:08:40 +0300858 prefix2str (&rn->p, buf, sizeof buf));
paul718e3742002-12-13 20:15:29 +0000859
860 /* Distance and metric display. */
861 if (rib->type != ZEBRA_ROUTE_CONNECT
862 && rib->type != ZEBRA_ROUTE_KERNEL)
863 len += vty_out (vty, " [%d/%d]", rib->distance,
864 rib->metric);
865 }
866 else
867 vty_out (vty, " %c%*c",
868 CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
869 ? '*' : ' ',
Christian Frankefa713d92013-07-05 15:35:37 +0000870 len - 3 + (2 * recursing), ' ');
paul718e3742002-12-13 20:15:29 +0000871
872 switch (nexthop->type)
Timo Teräs53a5c392015-05-23 11:08:40 +0300873 {
874 case NEXTHOP_TYPE_IPV4:
875 case NEXTHOP_TYPE_IPV4_IFINDEX:
876 vty_out (vty, " via %s", inet_ntoa (nexthop->gate.ipv4));
877 if (nexthop->ifindex)
878 vty_out (vty, ", %s", ifindex2ifname (nexthop->ifindex));
879 break;
880 case NEXTHOP_TYPE_IPV6:
881 case NEXTHOP_TYPE_IPV6_IFINDEX:
882 case NEXTHOP_TYPE_IPV6_IFNAME:
883 vty_out (vty, " via %s",
884 inet_ntop (AF_INET6, &nexthop->gate.ipv6, buf, BUFSIZ));
885 if (nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME)
886 vty_out (vty, ", %s", nexthop->ifname);
887 else if (nexthop->ifindex)
888 vty_out (vty, ", %s", ifindex2ifname (nexthop->ifindex));
889 break;
890 case NEXTHOP_TYPE_IFINDEX:
891 vty_out (vty, " is directly connected, %s",
892 ifindex2ifname (nexthop->ifindex));
893 break;
894 case NEXTHOP_TYPE_IFNAME:
895 vty_out (vty, " is directly connected, %s", nexthop->ifname);
896 break;
897 case NEXTHOP_TYPE_BLACKHOLE:
898 vty_out (vty, " is directly connected, Null0");
899 break;
900 default:
901 break;
902 }
paul718e3742002-12-13 20:15:29 +0000903 if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
Timo Teräs53a5c392015-05-23 11:08:40 +0300904 vty_out (vty, " inactive");
paul718e3742002-12-13 20:15:29 +0000905
Christian Frankee8d3d292013-07-05 15:35:39 +0000906 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ONLINK))
Timo Teräs53a5c392015-05-23 11:08:40 +0300907 vty_out (vty, " onlink");
Christian Frankee8d3d292013-07-05 15:35:39 +0000908
paul718e3742002-12-13 20:15:29 +0000909 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
Timo Teräs53a5c392015-05-23 11:08:40 +0300910 vty_out (vty, " (recursive)");
Christian Frankefa713d92013-07-05 15:35:37 +0000911
Paul Jakma7514fb72007-05-02 16:05:35 +0000912 switch (nexthop->type)
913 {
914 case NEXTHOP_TYPE_IPV4:
915 case NEXTHOP_TYPE_IPV4_IFINDEX:
916 case NEXTHOP_TYPE_IPV4_IFNAME:
917 if (nexthop->src.ipv4.s_addr)
918 {
Timo Teräs53a5c392015-05-23 11:08:40 +0300919 if (inet_ntop(AF_INET, &nexthop->src.ipv4, buf, sizeof buf))
Paul Jakma7514fb72007-05-02 16:05:35 +0000920 vty_out (vty, ", src %s", buf);
921 }
922 break;
Andrew J. Schorr09303312007-05-30 20:10:34 +0000923#ifdef HAVE_IPV6
Paul Jakma7514fb72007-05-02 16:05:35 +0000924 case NEXTHOP_TYPE_IPV6:
925 case NEXTHOP_TYPE_IPV6_IFINDEX:
926 case NEXTHOP_TYPE_IPV6_IFNAME:
927 if (!IPV6_ADDR_SAME(&nexthop->src.ipv6, &in6addr_any))
928 {
Timo Teräs53a5c392015-05-23 11:08:40 +0300929 if (inet_ntop(AF_INET6, &nexthop->src.ipv6, buf, sizeof buf))
Paul Jakma7514fb72007-05-02 16:05:35 +0000930 vty_out (vty, ", src %s", buf);
931 }
932 break;
Andrew J. Schorr09303312007-05-30 20:10:34 +0000933#endif /* HAVE_IPV6 */
Paul Jakma7514fb72007-05-02 16:05:35 +0000934 default:
Timo Teräs53a5c392015-05-23 11:08:40 +0300935 break;
Paul Jakma7514fb72007-05-02 16:05:35 +0000936 }
paul718e3742002-12-13 20:15:29 +0000937
hasso81dfcaa2003-05-25 19:21:25 +0000938 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
939 vty_out (vty, ", bh");
940 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT))
941 vty_out (vty, ", rej");
942
paul718e3742002-12-13 20:15:29 +0000943 if (rib->type == ZEBRA_ROUTE_RIP
Timo Teräs53a5c392015-05-23 11:08:40 +0300944 || rib->type == ZEBRA_ROUTE_RIPNG
945 || rib->type == ZEBRA_ROUTE_OSPF
946 || rib->type == ZEBRA_ROUTE_OSPF6
947 || rib->type == ZEBRA_ROUTE_BABEL
948 || rib->type == ZEBRA_ROUTE_ISIS
949 || rib->type == ZEBRA_ROUTE_BGP)
paul718e3742002-12-13 20:15:29 +0000950 {
951 time_t uptime;
952 struct tm *tm;
953
954 uptime = time (NULL);
955 uptime -= rib->uptime;
956 tm = gmtime (&uptime);
957
958#define ONE_DAY_SECOND 60*60*24
959#define ONE_WEEK_SECOND 60*60*24*7
960
961 if (uptime < ONE_DAY_SECOND)
962 vty_out (vty, ", %02d:%02d:%02d",
963 tm->tm_hour, tm->tm_min, tm->tm_sec);
964 else if (uptime < ONE_WEEK_SECOND)
965 vty_out (vty, ", %dd%02dh%02dm",
966 tm->tm_yday, tm->tm_hour, tm->tm_min);
967 else
968 vty_out (vty, ", %02dw%dd%02dh",
969 tm->tm_yday/7,
970 tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
971 }
972 vty_out (vty, "%s", VTY_NEWLINE);
973 }
974}
975
paul718e3742002-12-13 20:15:29 +0000976DEFUN (show_ip_route,
977 show_ip_route_cmd,
978 "show ip route",
979 SHOW_STR
980 IP_STR
981 "IP routing table\n")
982{
Everton Marques33d86db2014-07-14 11:19:00 -0300983 return do_show_ip_route(vty, SAFI_UNICAST);
984}
985
986static int do_show_ip_route(struct vty *vty, safi_t safi) {
paul718e3742002-12-13 20:15:29 +0000987 struct route_table *table;
988 struct route_node *rn;
989 struct rib *rib;
990 int first = 1;
991
Everton Marques33d86db2014-07-14 11:19:00 -0300992 table = vrf_table (AFI_IP, safi, 0);
paul718e3742002-12-13 20:15:29 +0000993 if (! table)
994 return CMD_SUCCESS;
995
996 /* Show all IPv4 routes. */
997 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000998 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +0000999 {
1000 if (first)
1001 {
David Lampartere0ca5fd2009-09-16 01:52:42 +02001002 vty_out (vty, SHOW_ROUTE_V4_HEADER);
paul718e3742002-12-13 20:15:29 +00001003 first = 0;
1004 }
1005 vty_show_ip_route (vty, rn, rib);
1006 }
1007 return CMD_SUCCESS;
1008}
1009
1010DEFUN (show_ip_route_prefix_longer,
1011 show_ip_route_prefix_longer_cmd,
1012 "show ip route A.B.C.D/M longer-prefixes",
1013 SHOW_STR
1014 IP_STR
1015 "IP routing table\n"
1016 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1017 "Show route matching the specified Network/Mask pair only\n")
1018{
1019 struct route_table *table;
1020 struct route_node *rn;
1021 struct rib *rib;
1022 struct prefix p;
1023 int ret;
1024 int first = 1;
1025
1026 ret = str2prefix (argv[0], &p);
1027 if (! ret)
1028 {
1029 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
1030 return CMD_WARNING;
1031 }
1032
1033 table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
1034 if (! table)
1035 return CMD_SUCCESS;
1036
1037 /* Show matched type IPv4 routes. */
1038 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001039 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +00001040 if (prefix_match (&p, &rn->p))
1041 {
1042 if (first)
1043 {
David Lampartere0ca5fd2009-09-16 01:52:42 +02001044 vty_out (vty, SHOW_ROUTE_V4_HEADER);
paul718e3742002-12-13 20:15:29 +00001045 first = 0;
1046 }
1047 vty_show_ip_route (vty, rn, rib);
1048 }
1049 return CMD_SUCCESS;
1050}
1051
1052DEFUN (show_ip_route_supernets,
1053 show_ip_route_supernets_cmd,
1054 "show ip route supernets-only",
1055 SHOW_STR
1056 IP_STR
1057 "IP routing table\n"
1058 "Show supernet entries only\n")
1059{
1060 struct route_table *table;
1061 struct route_node *rn;
1062 struct rib *rib;
1063 u_int32_t addr;
1064 int first = 1;
1065
1066 table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
1067 if (! table)
1068 return CMD_SUCCESS;
1069
1070 /* Show matched type IPv4 routes. */
1071 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001072 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +00001073 {
1074 addr = ntohl (rn->p.u.prefix4.s_addr);
1075
1076 if ((IN_CLASSC (addr) && rn->p.prefixlen < 24)
1077 || (IN_CLASSB (addr) && rn->p.prefixlen < 16)
1078 || (IN_CLASSA (addr) && rn->p.prefixlen < 8))
1079 {
1080 if (first)
1081 {
David Lampartere0ca5fd2009-09-16 01:52:42 +02001082 vty_out (vty, SHOW_ROUTE_V4_HEADER);
paul718e3742002-12-13 20:15:29 +00001083 first = 0;
1084 }
1085 vty_show_ip_route (vty, rn, rib);
1086 }
1087 }
1088 return CMD_SUCCESS;
1089}
1090
1091DEFUN (show_ip_route_protocol,
1092 show_ip_route_protocol_cmd,
David Lampartere0ca5fd2009-09-16 01:52:42 +02001093 "show ip route " QUAGGA_IP_REDIST_STR_ZEBRA,
paul718e3742002-12-13 20:15:29 +00001094 SHOW_STR
1095 IP_STR
1096 "IP routing table\n"
David Lampartere0ca5fd2009-09-16 01:52:42 +02001097 QUAGGA_IP_REDIST_HELP_STR_ZEBRA)
paul718e3742002-12-13 20:15:29 +00001098{
1099 int type;
1100 struct route_table *table;
1101 struct route_node *rn;
1102 struct rib *rib;
1103 int first = 1;
1104
David Lampartere0ca5fd2009-09-16 01:52:42 +02001105 type = proto_redistnum (AFI_IP, argv[0]);
1106 if (type < 0)
paul718e3742002-12-13 20:15:29 +00001107 {
1108 vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
1109 return CMD_WARNING;
1110 }
1111
1112 table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
1113 if (! table)
1114 return CMD_SUCCESS;
1115
1116 /* Show matched type IPv4 routes. */
1117 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001118 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +00001119 if (rib->type == type)
1120 {
1121 if (first)
1122 {
David Lampartere0ca5fd2009-09-16 01:52:42 +02001123 vty_out (vty, SHOW_ROUTE_V4_HEADER);
paul718e3742002-12-13 20:15:29 +00001124 first = 0;
1125 }
1126 vty_show_ip_route (vty, rn, rib);
1127 }
1128 return CMD_SUCCESS;
1129}
1130
1131DEFUN (show_ip_route_addr,
1132 show_ip_route_addr_cmd,
1133 "show ip route A.B.C.D",
1134 SHOW_STR
1135 IP_STR
1136 "IP routing table\n"
1137 "Network in the IP routing table to display\n")
1138{
1139 int ret;
1140 struct prefix_ipv4 p;
1141 struct route_table *table;
1142 struct route_node *rn;
1143
1144 ret = str2prefix_ipv4 (argv[0], &p);
1145 if (ret <= 0)
1146 {
1147 vty_out (vty, "%% Malformed IPv4 address%s", VTY_NEWLINE);
1148 return CMD_WARNING;
1149 }
1150
1151 table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
1152 if (! table)
1153 return CMD_SUCCESS;
1154
1155 rn = route_node_match (table, (struct prefix *) &p);
1156 if (! rn)
1157 {
1158 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
1159 return CMD_WARNING;
1160 }
1161
David Lamparter3b02fe82015-01-22 19:12:35 +01001162 vty_show_ip_route_detail (vty, rn, 0);
paul718e3742002-12-13 20:15:29 +00001163
1164 route_unlock_node (rn);
1165
1166 return CMD_SUCCESS;
1167}
1168
1169DEFUN (show_ip_route_prefix,
1170 show_ip_route_prefix_cmd,
1171 "show ip route A.B.C.D/M",
1172 SHOW_STR
1173 IP_STR
1174 "IP routing table\n"
1175 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
1176{
1177 int ret;
1178 struct prefix_ipv4 p;
1179 struct route_table *table;
1180 struct route_node *rn;
1181
1182 ret = str2prefix_ipv4 (argv[0], &p);
1183 if (ret <= 0)
1184 {
1185 vty_out (vty, "%% Malformed IPv4 address%s", VTY_NEWLINE);
1186 return CMD_WARNING;
1187 }
1188
1189 table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
1190 if (! table)
1191 return CMD_SUCCESS;
1192
1193 rn = route_node_match (table, (struct prefix *) &p);
1194 if (! rn || rn->p.prefixlen != p.prefixlen)
1195 {
1196 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
Lu Feng969d3552014-10-21 06:24:07 +00001197 if (rn)
1198 route_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00001199 return CMD_WARNING;
1200 }
1201
David Lamparter3b02fe82015-01-22 19:12:35 +01001202 vty_show_ip_route_detail (vty, rn, 0);
paul718e3742002-12-13 20:15:29 +00001203
1204 route_unlock_node (rn);
1205
1206 return CMD_SUCCESS;
1207}
1208
paula1ac18c2005-06-28 17:17:12 +00001209static void
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001210vty_show_ip_route_summary (struct vty *vty, struct route_table *table)
paul718e3742002-12-13 20:15:29 +00001211{
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001212 struct route_node *rn;
1213 struct rib *rib;
1214 struct nexthop *nexthop;
1215#define ZEBRA_ROUTE_IBGP ZEBRA_ROUTE_MAX
1216#define ZEBRA_ROUTE_TOTAL (ZEBRA_ROUTE_IBGP + 1)
1217 u_int32_t rib_cnt[ZEBRA_ROUTE_TOTAL + 1];
1218 u_int32_t fib_cnt[ZEBRA_ROUTE_TOTAL + 1];
1219 u_int32_t i;
paul718e3742002-12-13 20:15:29 +00001220
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001221 memset (&rib_cnt, 0, sizeof(rib_cnt));
1222 memset (&fib_cnt, 0, sizeof(fib_cnt));
1223 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001224 RNODE_FOREACH_RIB (rn, rib)
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001225 for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
1226 {
1227 rib_cnt[ZEBRA_ROUTE_TOTAL]++;
1228 rib_cnt[rib->type]++;
Christian Frankefa713d92013-07-05 15:35:37 +00001229 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
1230 || nexthop_has_fib_child(nexthop))
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001231 {
1232 fib_cnt[ZEBRA_ROUTE_TOTAL]++;
1233 fib_cnt[rib->type]++;
1234 }
1235 if (rib->type == ZEBRA_ROUTE_BGP &&
1236 CHECK_FLAG (rib->flags, ZEBRA_FLAG_IBGP))
1237 {
1238 rib_cnt[ZEBRA_ROUTE_IBGP]++;
Christian Frankefa713d92013-07-05 15:35:37 +00001239 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
1240 || nexthop_has_fib_child(nexthop))
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001241 fib_cnt[ZEBRA_ROUTE_IBGP]++;
1242 }
1243 }
paul718e3742002-12-13 20:15:29 +00001244
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001245 vty_out (vty, "%-20s %-20s %-20s %s",
1246 "Route Source", "Routes", "FIB", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001247
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001248 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
1249 {
1250 if (rib_cnt[i] > 0)
1251 {
1252 if (i == ZEBRA_ROUTE_BGP)
1253 {
1254 vty_out (vty, "%-20s %-20d %-20d %s", "ebgp",
1255 rib_cnt[ZEBRA_ROUTE_BGP] - rib_cnt[ZEBRA_ROUTE_IBGP],
1256 fib_cnt[ZEBRA_ROUTE_BGP] - fib_cnt[ZEBRA_ROUTE_IBGP],
1257 VTY_NEWLINE);
1258 vty_out (vty, "%-20s %-20d %-20d %s", "ibgp",
1259 rib_cnt[ZEBRA_ROUTE_IBGP], fib_cnt[ZEBRA_ROUTE_IBGP],
1260 VTY_NEWLINE);
1261 }
1262 else
1263 vty_out (vty, "%-20s %-20d %-20d %s", zebra_route_string(i),
1264 rib_cnt[i], fib_cnt[i], VTY_NEWLINE);
1265 }
1266 }
paul718e3742002-12-13 20:15:29 +00001267
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001268 vty_out (vty, "------%s", VTY_NEWLINE);
1269 vty_out (vty, "%-20s %-20d %-20d %s", "Totals", rib_cnt[ZEBRA_ROUTE_TOTAL],
1270 fib_cnt[ZEBRA_ROUTE_TOTAL], VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001271}
1272
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07001273/*
1274 * Implementation of the ip route summary prefix command.
1275 *
1276 * This command prints the primary prefixes that have been installed by various
1277 * protocols on the box.
1278 *
1279 */
1280static void
1281vty_show_ip_route_summary_prefix (struct vty *vty, struct route_table *table)
1282{
1283 struct route_node *rn;
1284 struct rib *rib;
1285 struct nexthop *nexthop;
1286#define ZEBRA_ROUTE_IBGP ZEBRA_ROUTE_MAX
1287#define ZEBRA_ROUTE_TOTAL (ZEBRA_ROUTE_IBGP + 1)
1288 u_int32_t rib_cnt[ZEBRA_ROUTE_TOTAL + 1];
1289 u_int32_t fib_cnt[ZEBRA_ROUTE_TOTAL + 1];
1290 u_int32_t i;
1291 int cnt;
1292
1293 memset (&rib_cnt, 0, sizeof(rib_cnt));
1294 memset (&fib_cnt, 0, sizeof(fib_cnt));
1295 for (rn = route_top (table); rn; rn = route_next (rn))
1296 RNODE_FOREACH_RIB (rn, rib)
1297 {
1298
1299 /*
1300 * In case of ECMP, count only once.
1301 */
1302 cnt = 0;
1303 for (nexthop = rib->nexthop; (!cnt && nexthop); nexthop = nexthop->next)
1304 {
1305 cnt++;
1306 rib_cnt[ZEBRA_ROUTE_TOTAL]++;
1307 rib_cnt[rib->type]++;
1308 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB))
1309 {
1310 fib_cnt[ZEBRA_ROUTE_TOTAL]++;
1311 fib_cnt[rib->type]++;
1312 }
1313 if (rib->type == ZEBRA_ROUTE_BGP &&
1314 CHECK_FLAG (rib->flags, ZEBRA_FLAG_IBGP))
1315 {
1316 rib_cnt[ZEBRA_ROUTE_IBGP]++;
1317 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB))
1318 fib_cnt[ZEBRA_ROUTE_IBGP]++;
1319 }
1320 }
1321 }
1322
1323 vty_out (vty, "%-20s %-20s %-20s %s",
1324 "Route Source", "Prefix Routes", "FIB", VTY_NEWLINE);
1325
1326 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
1327 {
1328 if (rib_cnt[i] > 0)
1329 {
1330 if (i == ZEBRA_ROUTE_BGP)
1331 {
1332 vty_out (vty, "%-20s %-20d %-20d %s", "ebgp",
1333 rib_cnt[ZEBRA_ROUTE_BGP] - rib_cnt[ZEBRA_ROUTE_IBGP],
1334 fib_cnt[ZEBRA_ROUTE_BGP] - fib_cnt[ZEBRA_ROUTE_IBGP],
1335 VTY_NEWLINE);
1336 vty_out (vty, "%-20s %-20d %-20d %s", "ibgp",
1337 rib_cnt[ZEBRA_ROUTE_IBGP], fib_cnt[ZEBRA_ROUTE_IBGP],
1338 VTY_NEWLINE);
1339 }
1340 else
1341 vty_out (vty, "%-20s %-20d %-20d %s", zebra_route_string(i),
1342 rib_cnt[i], fib_cnt[i], VTY_NEWLINE);
1343 }
1344 }
1345
1346 vty_out (vty, "------%s", VTY_NEWLINE);
1347 vty_out (vty, "%-20s %-20d %-20d %s", "Totals", rib_cnt[ZEBRA_ROUTE_TOTAL],
1348 fib_cnt[ZEBRA_ROUTE_TOTAL], VTY_NEWLINE);
1349}
1350
paul718e3742002-12-13 20:15:29 +00001351/* Show route summary. */
1352DEFUN (show_ip_route_summary,
1353 show_ip_route_summary_cmd,
1354 "show ip route summary",
1355 SHOW_STR
1356 IP_STR
1357 "IP routing table\n"
1358 "Summary of all routes\n")
1359{
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001360 struct route_table *table;
paul718e3742002-12-13 20:15:29 +00001361
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001362 table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
1363 if (! table)
1364 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001365
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001366 vty_show_ip_route_summary (vty, table);
paul718e3742002-12-13 20:15:29 +00001367
1368 return CMD_SUCCESS;
1369}
1370
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07001371/* Show route summary prefix. */
1372DEFUN (show_ip_route_summary_prefix,
1373 show_ip_route_summary_prefix_cmd,
1374 "show ip route summary prefix",
1375 SHOW_STR
1376 IP_STR
1377 "IP routing table\n"
1378 "Summary of all routes\n"
1379 "Prefix routes\n")
1380{
1381 struct route_table *table;
1382
1383 table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
1384 if (! table)
1385 return CMD_SUCCESS;
1386
1387 vty_show_ip_route_summary_prefix (vty, table);
1388
1389 return CMD_SUCCESS;
1390}
1391
paul718e3742002-12-13 20:15:29 +00001392/* Write IPv4 static route configuration. */
paula1ac18c2005-06-28 17:17:12 +00001393static int
Everton Marques33d86db2014-07-14 11:19:00 -03001394static_config_ipv4 (struct vty *vty, safi_t safi, const char *cmd)
paul718e3742002-12-13 20:15:29 +00001395{
1396 struct route_node *rn;
1397 struct static_ipv4 *si;
1398 struct route_table *stable;
Timo Teräs53a5c392015-05-23 11:08:40 +03001399 char buf[PREFIX_STRLEN];
paul718e3742002-12-13 20:15:29 +00001400 int write;
1401
1402 write = 0;
1403
1404 /* Lookup table. */
Everton Marques33d86db2014-07-14 11:19:00 -03001405 stable = vrf_static_table (AFI_IP, safi, 0);
paul718e3742002-12-13 20:15:29 +00001406 if (! stable)
1407 return -1;
1408
1409 for (rn = route_top (stable); rn; rn = route_next (rn))
1410 for (si = rn->info; si; si = si->next)
1411 {
Timo Teräs53a5c392015-05-23 11:08:40 +03001412 vty_out (vty, "%s %s", cmd, prefix2str (&rn->p, buf, sizeof buf));
paul718e3742002-12-13 20:15:29 +00001413
paul7021c422003-07-15 12:52:22 +00001414 switch (si->type)
1415 {
1416 case STATIC_IPV4_GATEWAY:
1417 vty_out (vty, " %s", inet_ntoa (si->gate.ipv4));
1418 break;
1419 case STATIC_IPV4_IFNAME:
1420 vty_out (vty, " %s", si->gate.ifname);
1421 break;
1422 case STATIC_IPV4_BLACKHOLE:
1423 vty_out (vty, " Null0");
1424 break;
1425 }
1426
1427 /* flags are incompatible with STATIC_IPV4_BLACKHOLE */
1428 if (si->type != STATIC_IPV4_BLACKHOLE)
1429 {
1430 if (CHECK_FLAG(si->flags, ZEBRA_FLAG_REJECT))
1431 vty_out (vty, " %s", "reject");
paul718e3742002-12-13 20:15:29 +00001432
paul7021c422003-07-15 12:52:22 +00001433 if (CHECK_FLAG(si->flags, ZEBRA_FLAG_BLACKHOLE))
1434 vty_out (vty, " %s", "blackhole");
1435 }
hasso81dfcaa2003-05-25 19:21:25 +00001436
paul7021c422003-07-15 12:52:22 +00001437 if (si->distance != ZEBRA_STATIC_DISTANCE_DEFAULT)
1438 vty_out (vty, " %d", si->distance);
hasso81dfcaa2003-05-25 19:21:25 +00001439
paul7021c422003-07-15 12:52:22 +00001440 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001441
paul7021c422003-07-15 12:52:22 +00001442 write = 1;
paul718e3742002-12-13 20:15:29 +00001443 }
1444 return write;
1445}
Andrew J. Schorr09303312007-05-30 20:10:34 +00001446
1447DEFUN (show_ip_protocol,
1448 show_ip_protocol_cmd,
1449 "show ip protocol",
1450 SHOW_STR
1451 IP_STR
1452 "IP protocol filtering status\n")
1453{
1454 int i;
1455
1456 vty_out(vty, "Protocol : route-map %s", VTY_NEWLINE);
1457 vty_out(vty, "------------------------%s", VTY_NEWLINE);
1458 for (i=0;i<ZEBRA_ROUTE_MAX;i++)
1459 {
1460 if (proto_rm[AFI_IP][i])
1461 vty_out (vty, "%-10s : %-10s%s", zebra_route_string(i),
1462 proto_rm[AFI_IP][i],
1463 VTY_NEWLINE);
1464 else
1465 vty_out (vty, "%-10s : none%s", zebra_route_string(i), VTY_NEWLINE);
1466 }
1467 if (proto_rm[AFI_IP][i])
1468 vty_out (vty, "%-10s : %-10s%s", "any", proto_rm[AFI_IP][i],
1469 VTY_NEWLINE);
1470 else
1471 vty_out (vty, "%-10s : none%s", "any", VTY_NEWLINE);
1472
1473 return CMD_SUCCESS;
1474}
1475
Joachim Nilsson36735ed2012-05-09 13:38:36 +02001476/*
1477 * Show IP mroute command to dump the BGP Multicast
1478 * routing table
1479 */
1480DEFUN (show_ip_mroute,
1481 show_ip_mroute_cmd,
1482 "show ip mroute",
1483 SHOW_STR
1484 IP_STR
1485 "IP Multicast routing table\n")
1486{
1487 struct route_table *table;
1488 struct route_node *rn;
1489 struct rib *rib;
1490 int first = 1;
1491
1492 table = vrf_table (AFI_IP, SAFI_MULTICAST, 0);
1493 if (! table)
1494 return CMD_SUCCESS;
1495
1496 /* Show all IPv4 routes. */
1497 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001498 RNODE_FOREACH_RIB (rn, rib)
Joachim Nilsson36735ed2012-05-09 13:38:36 +02001499 {
1500 if (first)
1501 {
1502 vty_out (vty, SHOW_ROUTE_V4_HEADER);
1503 first = 0;
1504 }
1505 vty_show_ip_route (vty, rn, rib);
1506 }
1507 return CMD_SUCCESS;
1508}
1509
David Lamparter6b0655a2014-06-04 06:53:35 +02001510
paul718e3742002-12-13 20:15:29 +00001511#ifdef HAVE_IPV6
1512/* General fucntion for IPv6 static route. */
paula1ac18c2005-06-28 17:17:12 +00001513static int
hasso39db97e2004-10-12 20:50:58 +00001514static_ipv6_func (struct vty *vty, int add_cmd, const char *dest_str,
1515 const char *gate_str, const char *ifname,
1516 const char *flag_str, const char *distance_str)
paul718e3742002-12-13 20:15:29 +00001517{
1518 int ret;
1519 u_char distance;
1520 struct prefix p;
1521 struct in6_addr *gate = NULL;
1522 struct in6_addr gate_addr;
1523 u_char type = 0;
1524 int table = 0;
hasso81dfcaa2003-05-25 19:21:25 +00001525 u_char flag = 0;
paul718e3742002-12-13 20:15:29 +00001526
1527 ret = str2prefix (dest_str, &p);
1528 if (ret <= 0)
1529 {
1530 vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
1531 return CMD_WARNING;
1532 }
1533
1534 /* Apply mask for given prefix. */
1535 apply_mask (&p);
1536
hasso81dfcaa2003-05-25 19:21:25 +00001537 /* Route flags */
1538 if (flag_str) {
1539 switch(flag_str[0]) {
1540 case 'r':
1541 case 'R': /* XXX */
1542 SET_FLAG (flag, ZEBRA_FLAG_REJECT);
1543 break;
1544 case 'b':
1545 case 'B': /* XXX */
1546 SET_FLAG (flag, ZEBRA_FLAG_BLACKHOLE);
1547 break;
1548 default:
1549 vty_out (vty, "%% Malformed flag %s %s", flag_str, VTY_NEWLINE);
paul595db7f2003-05-25 21:35:06 +00001550 return CMD_WARNING;
hasso81dfcaa2003-05-25 19:21:25 +00001551 }
1552 }
1553
paul718e3742002-12-13 20:15:29 +00001554 /* Administrative distance. */
1555 if (distance_str)
1556 distance = atoi (distance_str);
1557 else
1558 distance = ZEBRA_STATIC_DISTANCE_DEFAULT;
1559
1560 /* When gateway is valid IPv6 addrees, then gate is treated as
1561 nexthop address other case gate is treated as interface name. */
1562 ret = inet_pton (AF_INET6, gate_str, &gate_addr);
1563
1564 if (ifname)
1565 {
1566 /* When ifname is specified. It must be come with gateway
1567 address. */
1568 if (ret != 1)
1569 {
1570 vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
1571 return CMD_WARNING;
1572 }
1573 type = STATIC_IPV6_GATEWAY_IFNAME;
1574 gate = &gate_addr;
1575 }
1576 else
1577 {
1578 if (ret == 1)
1579 {
1580 type = STATIC_IPV6_GATEWAY;
1581 gate = &gate_addr;
1582 }
1583 else
1584 {
1585 type = STATIC_IPV6_IFNAME;
1586 ifname = gate_str;
1587 }
1588 }
1589
1590 if (add_cmd)
hasso81dfcaa2003-05-25 19:21:25 +00001591 static_add_ipv6 (&p, type, gate, ifname, flag, distance, table);
paul718e3742002-12-13 20:15:29 +00001592 else
1593 static_delete_ipv6 (&p, type, gate, ifname, distance, table);
1594
1595 return CMD_SUCCESS;
1596}
1597
1598DEFUN (ipv6_route,
1599 ipv6_route_cmd,
1600 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE)",
1601 IP_STR
1602 "Establish static routes\n"
1603 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1604 "IPv6 gateway address\n"
1605 "IPv6 gateway interface name\n")
1606{
hasso81dfcaa2003-05-25 19:21:25 +00001607 return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, NULL, NULL);
1608}
1609
1610DEFUN (ipv6_route_flags,
1611 ipv6_route_flags_cmd,
1612 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole)",
1613 IP_STR
1614 "Establish static routes\n"
1615 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1616 "IPv6 gateway address\n"
1617 "IPv6 gateway interface name\n"
1618 "Emit an ICMP unreachable when matched\n"
1619 "Silently discard pkts when matched\n")
1620{
1621 return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, argv[2], NULL);
paul718e3742002-12-13 20:15:29 +00001622}
1623
1624DEFUN (ipv6_route_ifname,
1625 ipv6_route_ifname_cmd,
1626 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE",
1627 IP_STR
1628 "Establish static routes\n"
1629 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1630 "IPv6 gateway address\n"
1631 "IPv6 gateway interface name\n")
1632{
hasso81dfcaa2003-05-25 19:21:25 +00001633 return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], NULL, NULL);
1634}
1635
1636DEFUN (ipv6_route_ifname_flags,
1637 ipv6_route_ifname_flags_cmd,
1638 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole)",
1639 IP_STR
1640 "Establish static routes\n"
1641 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1642 "IPv6 gateway address\n"
1643 "IPv6 gateway interface name\n"
1644 "Emit an ICMP unreachable when matched\n"
1645 "Silently discard pkts when matched\n")
1646{
1647 return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], argv[3], NULL);
paul718e3742002-12-13 20:15:29 +00001648}
1649
1650DEFUN (ipv6_route_pref,
1651 ipv6_route_pref_cmd,
1652 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <1-255>",
1653 IP_STR
1654 "Establish static routes\n"
1655 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1656 "IPv6 gateway address\n"
1657 "IPv6 gateway interface name\n"
1658 "Distance value for this prefix\n")
1659{
hasso81dfcaa2003-05-25 19:21:25 +00001660 return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, NULL, argv[2]);
1661}
1662
1663DEFUN (ipv6_route_flags_pref,
1664 ipv6_route_flags_pref_cmd,
1665 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) <1-255>",
1666 IP_STR
1667 "Establish static routes\n"
1668 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1669 "IPv6 gateway address\n"
1670 "IPv6 gateway interface name\n"
1671 "Emit an ICMP unreachable when matched\n"
1672 "Silently discard pkts when matched\n"
1673 "Distance value for this prefix\n")
1674{
1675 return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, argv[2], argv[3]);
paul718e3742002-12-13 20:15:29 +00001676}
1677
1678DEFUN (ipv6_route_ifname_pref,
1679 ipv6_route_ifname_pref_cmd,
1680 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255>",
1681 IP_STR
1682 "Establish static routes\n"
1683 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1684 "IPv6 gateway address\n"
1685 "IPv6 gateway interface name\n"
1686 "Distance value for this prefix\n")
1687{
hasso81dfcaa2003-05-25 19:21:25 +00001688 return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], NULL, argv[3]);
1689}
1690
1691DEFUN (ipv6_route_ifname_flags_pref,
1692 ipv6_route_ifname_flags_pref_cmd,
1693 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) <1-255>",
1694 IP_STR
1695 "Establish static routes\n"
1696 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1697 "IPv6 gateway address\n"
1698 "IPv6 gateway interface name\n"
1699 "Emit an ICMP unreachable when matched\n"
1700 "Silently discard pkts when matched\n"
1701 "Distance value for this prefix\n")
1702{
1703 return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], argv[3], argv[4]);
paul718e3742002-12-13 20:15:29 +00001704}
1705
1706DEFUN (no_ipv6_route,
1707 no_ipv6_route_cmd,
1708 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE)",
1709 NO_STR
1710 IP_STR
1711 "Establish static routes\n"
1712 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1713 "IPv6 gateway address\n"
1714 "IPv6 gateway interface name\n")
1715{
hasso81dfcaa2003-05-25 19:21:25 +00001716 return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00001717}
1718
hasso81dfcaa2003-05-25 19:21:25 +00001719ALIAS (no_ipv6_route,
1720 no_ipv6_route_flags_cmd,
1721 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole)",
1722 NO_STR
1723 IP_STR
1724 "Establish static routes\n"
1725 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1726 "IPv6 gateway address\n"
1727 "IPv6 gateway interface name\n"
1728 "Emit an ICMP unreachable when matched\n"
1729 "Silently discard pkts when matched\n")
1730
paul718e3742002-12-13 20:15:29 +00001731DEFUN (no_ipv6_route_ifname,
1732 no_ipv6_route_ifname_cmd,
1733 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE",
1734 NO_STR
1735 IP_STR
1736 "Establish static routes\n"
1737 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1738 "IPv6 gateway address\n"
1739 "IPv6 gateway interface name\n")
1740{
hasso81dfcaa2003-05-25 19:21:25 +00001741 return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], NULL, NULL);
paul718e3742002-12-13 20:15:29 +00001742}
1743
hasso81dfcaa2003-05-25 19:21:25 +00001744ALIAS (no_ipv6_route_ifname,
1745 no_ipv6_route_ifname_flags_cmd,
1746 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole)",
1747 NO_STR
1748 IP_STR
1749 "Establish static routes\n"
1750 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1751 "IPv6 gateway address\n"
1752 "IPv6 gateway interface name\n"
1753 "Emit an ICMP unreachable when matched\n"
1754 "Silently discard pkts when matched\n")
1755
paul718e3742002-12-13 20:15:29 +00001756DEFUN (no_ipv6_route_pref,
1757 no_ipv6_route_pref_cmd,
1758 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <1-255>",
1759 NO_STR
1760 IP_STR
1761 "Establish static routes\n"
1762 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1763 "IPv6 gateway address\n"
1764 "IPv6 gateway interface name\n"
1765 "Distance value for this prefix\n")
1766{
hasso81dfcaa2003-05-25 19:21:25 +00001767 return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, NULL, argv[2]);
1768}
1769
1770DEFUN (no_ipv6_route_flags_pref,
1771 no_ipv6_route_flags_pref_cmd,
1772 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) <1-255>",
1773 NO_STR
1774 IP_STR
1775 "Establish static routes\n"
1776 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1777 "IPv6 gateway address\n"
1778 "IPv6 gateway interface name\n"
1779 "Emit an ICMP unreachable when matched\n"
1780 "Silently discard pkts when matched\n"
1781 "Distance value for this prefix\n")
1782{
1783 /* We do not care about argv[2] */
1784 return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, argv[2], argv[3]);
paul718e3742002-12-13 20:15:29 +00001785}
1786
1787DEFUN (no_ipv6_route_ifname_pref,
1788 no_ipv6_route_ifname_pref_cmd,
1789 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255>",
1790 NO_STR
1791 IP_STR
1792 "Establish static routes\n"
1793 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1794 "IPv6 gateway address\n"
1795 "IPv6 gateway interface name\n"
1796 "Distance value for this prefix\n")
1797{
hasso81dfcaa2003-05-25 19:21:25 +00001798 return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], NULL, argv[3]);
1799}
1800
1801DEFUN (no_ipv6_route_ifname_flags_pref,
1802 no_ipv6_route_ifname_flags_pref_cmd,
1803 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) <1-255>",
1804 NO_STR
1805 IP_STR
1806 "Establish static routes\n"
1807 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1808 "IPv6 gateway address\n"
1809 "IPv6 gateway interface name\n"
1810 "Emit an ICMP unreachable when matched\n"
1811 "Silently discard pkts when matched\n"
1812 "Distance value for this prefix\n")
1813{
1814 return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], argv[3], argv[4]);
paul718e3742002-12-13 20:15:29 +00001815}
1816
paul718e3742002-12-13 20:15:29 +00001817DEFUN (show_ipv6_route,
1818 show_ipv6_route_cmd,
1819 "show ipv6 route",
1820 SHOW_STR
1821 IP_STR
1822 "IPv6 routing table\n")
1823{
1824 struct route_table *table;
1825 struct route_node *rn;
1826 struct rib *rib;
1827 int first = 1;
1828
1829 table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
1830 if (! table)
1831 return CMD_SUCCESS;
1832
1833 /* Show all IPv6 route. */
1834 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001835 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +00001836 {
1837 if (first)
1838 {
David Lampartere0ca5fd2009-09-16 01:52:42 +02001839 vty_out (vty, SHOW_ROUTE_V6_HEADER);
paul718e3742002-12-13 20:15:29 +00001840 first = 0;
1841 }
Timo Teräs53a5c392015-05-23 11:08:40 +03001842 vty_show_ip_route (vty, rn, rib);
paul718e3742002-12-13 20:15:29 +00001843 }
1844 return CMD_SUCCESS;
1845}
1846
1847DEFUN (show_ipv6_route_prefix_longer,
1848 show_ipv6_route_prefix_longer_cmd,
1849 "show ipv6 route X:X::X:X/M longer-prefixes",
1850 SHOW_STR
1851 IP_STR
1852 "IPv6 routing table\n"
1853 "IPv6 prefix\n"
1854 "Show route matching the specified Network/Mask pair only\n")
1855{
1856 struct route_table *table;
1857 struct route_node *rn;
1858 struct rib *rib;
1859 struct prefix p;
1860 int ret;
1861 int first = 1;
1862
1863 table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
1864 if (! table)
1865 return CMD_SUCCESS;
1866
1867 ret = str2prefix (argv[0], &p);
1868 if (! ret)
1869 {
1870 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
1871 return CMD_WARNING;
1872 }
1873
1874 /* Show matched type IPv6 routes. */
1875 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001876 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +00001877 if (prefix_match (&p, &rn->p))
1878 {
1879 if (first)
1880 {
David Lampartere0ca5fd2009-09-16 01:52:42 +02001881 vty_out (vty, SHOW_ROUTE_V6_HEADER);
paul718e3742002-12-13 20:15:29 +00001882 first = 0;
1883 }
Timo Teräs53a5c392015-05-23 11:08:40 +03001884 vty_show_ip_route (vty, rn, rib);
paul718e3742002-12-13 20:15:29 +00001885 }
1886 return CMD_SUCCESS;
1887}
1888
1889DEFUN (show_ipv6_route_protocol,
1890 show_ipv6_route_protocol_cmd,
David Lampartere0ca5fd2009-09-16 01:52:42 +02001891 "show ipv6 route " QUAGGA_IP6_REDIST_STR_ZEBRA,
paul718e3742002-12-13 20:15:29 +00001892 SHOW_STR
1893 IP_STR
1894 "IP routing table\n"
David Lampartere0ca5fd2009-09-16 01:52:42 +02001895 QUAGGA_IP6_REDIST_HELP_STR_ZEBRA)
paul718e3742002-12-13 20:15:29 +00001896{
1897 int type;
1898 struct route_table *table;
1899 struct route_node *rn;
1900 struct rib *rib;
1901 int first = 1;
1902
David Lampartere0ca5fd2009-09-16 01:52:42 +02001903 type = proto_redistnum (AFI_IP6, argv[0]);
1904 if (type < 0)
paul718e3742002-12-13 20:15:29 +00001905 {
1906 vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
1907 return CMD_WARNING;
1908 }
1909
1910 table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
1911 if (! table)
1912 return CMD_SUCCESS;
1913
1914 /* Show matched type IPv6 routes. */
1915 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001916 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +00001917 if (rib->type == type)
1918 {
1919 if (first)
1920 {
David Lampartere0ca5fd2009-09-16 01:52:42 +02001921 vty_out (vty, SHOW_ROUTE_V6_HEADER);
paul718e3742002-12-13 20:15:29 +00001922 first = 0;
1923 }
Timo Teräs53a5c392015-05-23 11:08:40 +03001924 vty_show_ip_route (vty, rn, rib);
paul718e3742002-12-13 20:15:29 +00001925 }
1926 return CMD_SUCCESS;
1927}
1928
1929DEFUN (show_ipv6_route_addr,
1930 show_ipv6_route_addr_cmd,
1931 "show ipv6 route X:X::X:X",
1932 SHOW_STR
1933 IP_STR
1934 "IPv6 routing table\n"
1935 "IPv6 Address\n")
1936{
1937 int ret;
1938 struct prefix_ipv6 p;
1939 struct route_table *table;
1940 struct route_node *rn;
1941
1942 ret = str2prefix_ipv6 (argv[0], &p);
1943 if (ret <= 0)
1944 {
1945 vty_out (vty, "Malformed IPv6 address%s", VTY_NEWLINE);
1946 return CMD_WARNING;
1947 }
1948
1949 table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
1950 if (! table)
1951 return CMD_SUCCESS;
1952
1953 rn = route_node_match (table, (struct prefix *) &p);
1954 if (! rn)
1955 {
1956 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
1957 return CMD_WARNING;
1958 }
1959
Timo Teräs53a5c392015-05-23 11:08:40 +03001960 vty_show_ip_route_detail (vty, rn, 0);
paul718e3742002-12-13 20:15:29 +00001961
1962 route_unlock_node (rn);
1963
1964 return CMD_SUCCESS;
1965}
1966
1967DEFUN (show_ipv6_route_prefix,
1968 show_ipv6_route_prefix_cmd,
1969 "show ipv6 route X:X::X:X/M",
1970 SHOW_STR
1971 IP_STR
1972 "IPv6 routing table\n"
1973 "IPv6 prefix\n")
1974{
1975 int ret;
1976 struct prefix_ipv6 p;
1977 struct route_table *table;
1978 struct route_node *rn;
1979
1980 ret = str2prefix_ipv6 (argv[0], &p);
1981 if (ret <= 0)
1982 {
1983 vty_out (vty, "Malformed IPv6 prefix%s", VTY_NEWLINE);
1984 return CMD_WARNING;
1985 }
1986
1987 table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
1988 if (! table)
1989 return CMD_SUCCESS;
1990
1991 rn = route_node_match (table, (struct prefix *) &p);
1992 if (! rn || rn->p.prefixlen != p.prefixlen)
1993 {
1994 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
Lu Feng969d3552014-10-21 06:24:07 +00001995 if (rn)
1996 route_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00001997 return CMD_WARNING;
1998 }
1999
Timo Teräs53a5c392015-05-23 11:08:40 +03002000 vty_show_ip_route_detail (vty, rn, 0);
paul718e3742002-12-13 20:15:29 +00002001
2002 route_unlock_node (rn);
2003
2004 return CMD_SUCCESS;
2005}
2006
Stig Thormodsrud61691c92008-11-04 15:45:07 -08002007/* Show route summary. */
2008DEFUN (show_ipv6_route_summary,
2009 show_ipv6_route_summary_cmd,
2010 "show ipv6 route summary",
2011 SHOW_STR
2012 IP_STR
2013 "IPv6 routing table\n"
2014 "Summary of all IPv6 routes\n")
2015{
2016 struct route_table *table;
2017
2018 table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
2019 if (! table)
2020 return CMD_SUCCESS;
2021
2022 vty_show_ip_route_summary (vty, table);
2023
2024 return CMD_SUCCESS;
2025}
2026
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07002027/* Show ipv6 route summary prefix. */
2028DEFUN (show_ipv6_route_summary_prefix,
2029 show_ipv6_route_summary_prefix_cmd,
2030 "show ipv6 route summary prefix",
2031 SHOW_STR
2032 IP_STR
2033 "IPv6 routing table\n"
2034 "Summary of all IPv6 routes\n"
2035 "Prefix routes\n")
2036{
2037 struct route_table *table;
2038
2039 table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
2040 if (! table)
2041 return CMD_SUCCESS;
2042
2043 vty_show_ip_route_summary_prefix (vty, table);
2044
2045 return CMD_SUCCESS;
2046}
2047
G.Balajicddf3912011-11-26 21:59:32 +04002048/*
G.Balajicddf3912011-11-26 21:59:32 +04002049 * Show IPv6 mroute command.Used to dump
2050 * the Multicast routing table.
2051 */
2052
2053DEFUN (show_ipv6_mroute,
2054 show_ipv6_mroute_cmd,
2055 "show ipv6 mroute",
2056 SHOW_STR
2057 IP_STR
2058 "IPv6 Multicast routing table\n")
2059{
2060 struct route_table *table;
2061 struct route_node *rn;
2062 struct rib *rib;
2063 int first = 1;
2064
2065 table = vrf_table (AFI_IP6, SAFI_MULTICAST, 0);
2066 if (! table)
2067 return CMD_SUCCESS;
2068
2069 /* Show all IPv6 route. */
2070 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00002071 RNODE_FOREACH_RIB (rn, rib)
G.Balajicddf3912011-11-26 21:59:32 +04002072 {
2073 if (first)
2074 {
G.Balajicb32fd62011-11-27 20:09:40 +05302075 vty_out (vty, SHOW_ROUTE_V6_HEADER);
G.Balajicddf3912011-11-26 21:59:32 +04002076 first = 0;
2077 }
Timo Teräs53a5c392015-05-23 11:08:40 +03002078 vty_show_ip_route (vty, rn, rib);
G.Balajicddf3912011-11-26 21:59:32 +04002079 }
2080 return CMD_SUCCESS;
2081}
2082
paul718e3742002-12-13 20:15:29 +00002083/* Write IPv6 static route configuration. */
paula1ac18c2005-06-28 17:17:12 +00002084static int
paul718e3742002-12-13 20:15:29 +00002085static_config_ipv6 (struct vty *vty)
2086{
2087 struct route_node *rn;
2088 struct static_ipv6 *si;
2089 int write;
2090 char buf[BUFSIZ];
2091 struct route_table *stable;
2092
2093 write = 0;
2094
2095 /* Lookup table. */
2096 stable = vrf_static_table (AFI_IP6, SAFI_UNICAST, 0);
2097 if (! stable)
2098 return -1;
2099
2100 for (rn = route_top (stable); rn; rn = route_next (rn))
2101 for (si = rn->info; si; si = si->next)
2102 {
Timo Teräs53a5c392015-05-23 11:08:40 +03002103 vty_out (vty, "ipv6 route %s", prefix2str (&rn->p, buf, sizeof buf));
paul718e3742002-12-13 20:15:29 +00002104
2105 switch (si->type)
2106 {
2107 case STATIC_IPV6_GATEWAY:
2108 vty_out (vty, " %s", inet_ntop (AF_INET6, &si->ipv6, buf, BUFSIZ));
2109 break;
2110 case STATIC_IPV6_IFNAME:
2111 vty_out (vty, " %s", si->ifname);
2112 break;
2113 case STATIC_IPV6_GATEWAY_IFNAME:
2114 vty_out (vty, " %s %s",
2115 inet_ntop (AF_INET6, &si->ipv6, buf, BUFSIZ), si->ifname);
2116 break;
2117 }
2118
hasso81dfcaa2003-05-25 19:21:25 +00002119 if (CHECK_FLAG(si->flags, ZEBRA_FLAG_REJECT))
2120 vty_out (vty, " %s", "reject");
2121
2122 if (CHECK_FLAG(si->flags, ZEBRA_FLAG_BLACKHOLE))
2123 vty_out (vty, " %s", "blackhole");
2124
paul718e3742002-12-13 20:15:29 +00002125 if (si->distance != ZEBRA_STATIC_DISTANCE_DEFAULT)
2126 vty_out (vty, " %d", si->distance);
2127 vty_out (vty, "%s", VTY_NEWLINE);
2128
2129 write = 1;
2130 }
2131 return write;
2132}
2133#endif /* HAVE_IPV6 */
2134
2135/* Static ip route configuration write function. */
paula1ac18c2005-06-28 17:17:12 +00002136static int
paul718e3742002-12-13 20:15:29 +00002137zebra_ip_config (struct vty *vty)
2138{
2139 int write = 0;
2140
Everton Marques33d86db2014-07-14 11:19:00 -03002141 write += static_config_ipv4 (vty, SAFI_UNICAST, "ip route");
2142 write += static_config_ipv4 (vty, SAFI_MULTICAST, "ip mroute");
paul718e3742002-12-13 20:15:29 +00002143#ifdef HAVE_IPV6
2144 write += static_config_ipv6 (vty);
2145#endif /* HAVE_IPV6 */
2146
2147 return write;
2148}
2149
David Lamparterbd078122015-01-06 19:53:24 +01002150static int config_write_vty(struct vty *vty)
2151{
Paul Jakma7514fb72007-05-02 16:05:35 +00002152 int i;
David Lamparterbd078122015-01-06 19:53:24 +01002153 enum multicast_mode ipv4_multicast_mode = multicast_mode_ipv4_get ();
2154
2155 if (ipv4_multicast_mode != MCAST_NO_CONFIG)
2156 vty_out (vty, "ip multicast rpf-lookup-mode %s%s",
2157 ipv4_multicast_mode == MCAST_URIB_ONLY ? "urib-only" :
2158 ipv4_multicast_mode == MCAST_MRIB_ONLY ? "mrib-only" :
2159 ipv4_multicast_mode == MCAST_MIX_MRIB_FIRST ? "mrib-then-urib" :
2160 ipv4_multicast_mode == MCAST_MIX_DISTANCE ? "lower-distance" :
2161 "longer-prefix",
2162 VTY_NEWLINE);
Paul Jakma7514fb72007-05-02 16:05:35 +00002163
2164 for (i=0;i<ZEBRA_ROUTE_MAX;i++)
2165 {
2166 if (proto_rm[AFI_IP][i])
2167 vty_out (vty, "ip protocol %s route-map %s%s", zebra_route_string(i),
2168 proto_rm[AFI_IP][i], VTY_NEWLINE);
2169 }
2170 if (proto_rm[AFI_IP][ZEBRA_ROUTE_MAX])
2171 vty_out (vty, "ip protocol %s route-map %s%s", "any",
2172 proto_rm[AFI_IP][ZEBRA_ROUTE_MAX], VTY_NEWLINE);
2173
2174 return 1;
2175}
2176
2177/* table node for protocol filtering */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -08002178static struct cmd_node protocol_node = { PROTOCOL_NODE, "", 1 };
Paul Jakma7514fb72007-05-02 16:05:35 +00002179
paul718e3742002-12-13 20:15:29 +00002180/* IP node for static routes. */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -08002181static struct cmd_node ip_node = { IP_NODE, "", 1 };
paul718e3742002-12-13 20:15:29 +00002182
2183/* Route VTY. */
2184void
paula1ac18c2005-06-28 17:17:12 +00002185zebra_vty_init (void)
paul718e3742002-12-13 20:15:29 +00002186{
2187 install_node (&ip_node, zebra_ip_config);
David Lamparterbd078122015-01-06 19:53:24 +01002188 install_node (&protocol_node, config_write_vty);
paul718e3742002-12-13 20:15:29 +00002189
Everton Marques33d86db2014-07-14 11:19:00 -03002190 install_element (CONFIG_NODE, &ip_mroute_cmd);
David Lampartera76681b2015-01-22 19:03:53 +01002191 install_element (CONFIG_NODE, &ip_mroute_dist_cmd);
Everton Marques33d86db2014-07-14 11:19:00 -03002192 install_element (CONFIG_NODE, &no_ip_mroute_cmd);
David Lampartera76681b2015-01-22 19:03:53 +01002193 install_element (CONFIG_NODE, &no_ip_mroute_dist_cmd);
David Lamparterbd078122015-01-06 19:53:24 +01002194 install_element (CONFIG_NODE, &ip_multicast_mode_cmd);
2195 install_element (CONFIG_NODE, &no_ip_multicast_mode_cmd);
2196 install_element (CONFIG_NODE, &no_ip_multicast_mode_noarg_cmd);
Paul Jakma7514fb72007-05-02 16:05:35 +00002197 install_element (CONFIG_NODE, &ip_protocol_cmd);
2198 install_element (CONFIG_NODE, &no_ip_protocol_cmd);
2199 install_element (VIEW_NODE, &show_ip_protocol_cmd);
2200 install_element (ENABLE_NODE, &show_ip_protocol_cmd);
paul718e3742002-12-13 20:15:29 +00002201 install_element (CONFIG_NODE, &ip_route_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002202 install_element (CONFIG_NODE, &ip_route_flags_cmd);
hasso457ef552003-05-28 12:02:15 +00002203 install_element (CONFIG_NODE, &ip_route_flags2_cmd);
paul718e3742002-12-13 20:15:29 +00002204 install_element (CONFIG_NODE, &ip_route_mask_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002205 install_element (CONFIG_NODE, &ip_route_mask_flags_cmd);
hasso457ef552003-05-28 12:02:15 +00002206 install_element (CONFIG_NODE, &ip_route_mask_flags2_cmd);
paul718e3742002-12-13 20:15:29 +00002207 install_element (CONFIG_NODE, &no_ip_route_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002208 install_element (CONFIG_NODE, &no_ip_route_flags_cmd);
hasso457ef552003-05-28 12:02:15 +00002209 install_element (CONFIG_NODE, &no_ip_route_flags2_cmd);
paul718e3742002-12-13 20:15:29 +00002210 install_element (CONFIG_NODE, &no_ip_route_mask_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002211 install_element (CONFIG_NODE, &no_ip_route_mask_flags_cmd);
hasso457ef552003-05-28 12:02:15 +00002212 install_element (CONFIG_NODE, &no_ip_route_mask_flags2_cmd);
paul718e3742002-12-13 20:15:29 +00002213 install_element (CONFIG_NODE, &ip_route_distance_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002214 install_element (CONFIG_NODE, &ip_route_flags_distance_cmd);
hasso457ef552003-05-28 12:02:15 +00002215 install_element (CONFIG_NODE, &ip_route_flags_distance2_cmd);
paul718e3742002-12-13 20:15:29 +00002216 install_element (CONFIG_NODE, &ip_route_mask_distance_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002217 install_element (CONFIG_NODE, &ip_route_mask_flags_distance_cmd);
hasso457ef552003-05-28 12:02:15 +00002218 install_element (CONFIG_NODE, &ip_route_mask_flags_distance2_cmd);
paul718e3742002-12-13 20:15:29 +00002219 install_element (CONFIG_NODE, &no_ip_route_distance_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002220 install_element (CONFIG_NODE, &no_ip_route_flags_distance_cmd);
hasso457ef552003-05-28 12:02:15 +00002221 install_element (CONFIG_NODE, &no_ip_route_flags_distance2_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002222 install_element (CONFIG_NODE, &no_ip_route_mask_flags_distance_cmd);
hasso457ef552003-05-28 12:02:15 +00002223 install_element (CONFIG_NODE, &no_ip_route_mask_flags_distance2_cmd);
paul718e3742002-12-13 20:15:29 +00002224
2225 install_element (VIEW_NODE, &show_ip_route_cmd);
2226 install_element (VIEW_NODE, &show_ip_route_addr_cmd);
2227 install_element (VIEW_NODE, &show_ip_route_prefix_cmd);
2228 install_element (VIEW_NODE, &show_ip_route_prefix_longer_cmd);
2229 install_element (VIEW_NODE, &show_ip_route_protocol_cmd);
2230 install_element (VIEW_NODE, &show_ip_route_supernets_cmd);
Stig Thormodsrud61691c92008-11-04 15:45:07 -08002231 install_element (VIEW_NODE, &show_ip_route_summary_cmd);
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07002232 install_element (VIEW_NODE, &show_ip_route_summary_prefix_cmd);
paul718e3742002-12-13 20:15:29 +00002233 install_element (ENABLE_NODE, &show_ip_route_cmd);
2234 install_element (ENABLE_NODE, &show_ip_route_addr_cmd);
2235 install_element (ENABLE_NODE, &show_ip_route_prefix_cmd);
2236 install_element (ENABLE_NODE, &show_ip_route_prefix_longer_cmd);
2237 install_element (ENABLE_NODE, &show_ip_route_protocol_cmd);
2238 install_element (ENABLE_NODE, &show_ip_route_supernets_cmd);
paul718e3742002-12-13 20:15:29 +00002239 install_element (ENABLE_NODE, &show_ip_route_summary_cmd);
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07002240 install_element (ENABLE_NODE, &show_ip_route_summary_prefix_cmd);
paul718e3742002-12-13 20:15:29 +00002241
G.Balajicddf3912011-11-26 21:59:32 +04002242 install_element (VIEW_NODE, &show_ip_mroute_cmd);
2243 install_element (ENABLE_NODE, &show_ip_mroute_cmd);
2244
Everton Marques33d86db2014-07-14 11:19:00 -03002245 install_element (VIEW_NODE, &show_ip_rpf_cmd);
2246 install_element (ENABLE_NODE, &show_ip_rpf_cmd);
David Lamparter3b02fe82015-01-22 19:12:35 +01002247 install_element (VIEW_NODE, &show_ip_rpf_addr_cmd);
2248 install_element (ENABLE_NODE, &show_ip_rpf_addr_cmd);
G.Balajicddf3912011-11-26 21:59:32 +04002249
paul718e3742002-12-13 20:15:29 +00002250#ifdef HAVE_IPV6
2251 install_element (CONFIG_NODE, &ipv6_route_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002252 install_element (CONFIG_NODE, &ipv6_route_flags_cmd);
paul718e3742002-12-13 20:15:29 +00002253 install_element (CONFIG_NODE, &ipv6_route_ifname_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002254 install_element (CONFIG_NODE, &ipv6_route_ifname_flags_cmd);
paul718e3742002-12-13 20:15:29 +00002255 install_element (CONFIG_NODE, &no_ipv6_route_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002256 install_element (CONFIG_NODE, &no_ipv6_route_flags_cmd);
paul718e3742002-12-13 20:15:29 +00002257 install_element (CONFIG_NODE, &no_ipv6_route_ifname_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002258 install_element (CONFIG_NODE, &no_ipv6_route_ifname_flags_cmd);
paul718e3742002-12-13 20:15:29 +00002259 install_element (CONFIG_NODE, &ipv6_route_pref_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002260 install_element (CONFIG_NODE, &ipv6_route_flags_pref_cmd);
paul718e3742002-12-13 20:15:29 +00002261 install_element (CONFIG_NODE, &ipv6_route_ifname_pref_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002262 install_element (CONFIG_NODE, &ipv6_route_ifname_flags_pref_cmd);
paul718e3742002-12-13 20:15:29 +00002263 install_element (CONFIG_NODE, &no_ipv6_route_pref_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002264 install_element (CONFIG_NODE, &no_ipv6_route_flags_pref_cmd);
paul718e3742002-12-13 20:15:29 +00002265 install_element (CONFIG_NODE, &no_ipv6_route_ifname_pref_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002266 install_element (CONFIG_NODE, &no_ipv6_route_ifname_flags_pref_cmd);
paul718e3742002-12-13 20:15:29 +00002267 install_element (VIEW_NODE, &show_ipv6_route_cmd);
Stig Thormodsrud61691c92008-11-04 15:45:07 -08002268 install_element (VIEW_NODE, &show_ipv6_route_summary_cmd);
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07002269 install_element (VIEW_NODE, &show_ipv6_route_summary_prefix_cmd);
paul718e3742002-12-13 20:15:29 +00002270 install_element (VIEW_NODE, &show_ipv6_route_protocol_cmd);
2271 install_element (VIEW_NODE, &show_ipv6_route_addr_cmd);
2272 install_element (VIEW_NODE, &show_ipv6_route_prefix_cmd);
2273 install_element (VIEW_NODE, &show_ipv6_route_prefix_longer_cmd);
2274 install_element (ENABLE_NODE, &show_ipv6_route_cmd);
2275 install_element (ENABLE_NODE, &show_ipv6_route_protocol_cmd);
2276 install_element (ENABLE_NODE, &show_ipv6_route_addr_cmd);
2277 install_element (ENABLE_NODE, &show_ipv6_route_prefix_cmd);
2278 install_element (ENABLE_NODE, &show_ipv6_route_prefix_longer_cmd);
Stig Thormodsrud61691c92008-11-04 15:45:07 -08002279 install_element (ENABLE_NODE, &show_ipv6_route_summary_cmd);
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07002280 install_element (ENABLE_NODE, &show_ipv6_route_summary_prefix_cmd);
G.Balajicddf3912011-11-26 21:59:32 +04002281
2282 install_element (VIEW_NODE, &show_ipv6_mroute_cmd);
2283 install_element (ENABLE_NODE, &show_ipv6_mroute_cmd);
paul718e3742002-12-13 20:15:29 +00002284#endif /* HAVE_IPV6 */
2285}