blob: 69245a54aad6248b131858be8fb24e533b2fe4c6 [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 Marques96bb2662014-07-14 11:19:00 -030033static int do_show_ip_route(struct vty *vty, safi_t safi);
34
35/* General function for static route. */
paula1ac18c2005-06-28 17:17:12 +000036static int
Everton Marques96bb2662014-07-14 11:19:00 -030037zebra_static_ipv4_safi (struct vty *vty, safi_t safi, int add_cmd,
38 const char *dest_str, const char *mask_str,
39 const char *gate_str, const char *flag_str,
40 const char *distance_str)
paul718e3742002-12-13 20:15:29 +000041{
42 int ret;
43 u_char distance;
44 struct prefix p;
45 struct in_addr gate;
46 struct in_addr mask;
hasso39db97e2004-10-12 20:50:58 +000047 const char *ifname;
hasso81dfcaa2003-05-25 19:21:25 +000048 u_char flag = 0;
paul718e3742002-12-13 20:15:29 +000049
50 ret = str2prefix (dest_str, &p);
51 if (ret <= 0)
52 {
53 vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
54 return CMD_WARNING;
55 }
56
57 /* Cisco like mask notation. */
58 if (mask_str)
59 {
60 ret = inet_aton (mask_str, &mask);
61 if (ret == 0)
paul595db7f2003-05-25 21:35:06 +000062 {
63 vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
64 return CMD_WARNING;
65 }
paul718e3742002-12-13 20:15:29 +000066 p.prefixlen = ip_masklen (mask);
67 }
68
69 /* Apply mask for given prefix. */
70 apply_mask (&p);
71
paul595db7f2003-05-25 21:35:06 +000072 /* Administrative distance. */
73 if (distance_str)
74 distance = atoi (distance_str);
75 else
76 distance = ZEBRA_STATIC_DISTANCE_DEFAULT;
77
78 /* Null0 static route. */
hasso457ef552003-05-28 12:02:15 +000079 if ((gate_str != NULL) && (strncasecmp (gate_str, "Null0", strlen (gate_str)) == 0))
paul595db7f2003-05-25 21:35:06 +000080 {
81 if (flag_str)
82 {
83 vty_out (vty, "%% can not have flag %s with Null0%s", flag_str, VTY_NEWLINE);
84 return CMD_WARNING;
85 }
86 if (add_cmd)
Everton Marques96bb2662014-07-14 11:19:00 -030087 static_add_ipv4_safi (safi, &p, NULL, NULL, ZEBRA_FLAG_BLACKHOLE, distance, 0);
paul595db7f2003-05-25 21:35:06 +000088 else
Everton Marques96bb2662014-07-14 11:19:00 -030089 static_delete_ipv4_safi (safi, &p, NULL, NULL, distance, 0);
paul595db7f2003-05-25 21:35:06 +000090 return CMD_SUCCESS;
91 }
92
hasso81dfcaa2003-05-25 19:21:25 +000093 /* Route flags */
94 if (flag_str) {
95 switch(flag_str[0]) {
96 case 'r':
97 case 'R': /* XXX */
98 SET_FLAG (flag, ZEBRA_FLAG_REJECT);
99 break;
100 case 'b':
101 case 'B': /* XXX */
102 SET_FLAG (flag, ZEBRA_FLAG_BLACKHOLE);
103 break;
104 default:
105 vty_out (vty, "%% Malformed flag %s %s", flag_str, VTY_NEWLINE);
paul595db7f2003-05-25 21:35:06 +0000106 return CMD_WARNING;
hasso81dfcaa2003-05-25 19:21:25 +0000107 }
108 }
109
hasso457ef552003-05-28 12:02:15 +0000110 if (gate_str == NULL)
111 {
112 if (add_cmd)
Everton Marques96bb2662014-07-14 11:19:00 -0300113 static_add_ipv4_safi (safi, &p, NULL, NULL, flag, distance, 0);
hasso457ef552003-05-28 12:02:15 +0000114 else
Everton Marques96bb2662014-07-14 11:19:00 -0300115 static_delete_ipv4_safi (safi, &p, NULL, NULL, distance, 0);
hasso457ef552003-05-28 12:02:15 +0000116
117 return CMD_SUCCESS;
118 }
119
paul718e3742002-12-13 20:15:29 +0000120 /* When gateway is A.B.C.D format, gate is treated as nexthop
121 address other case gate is treated as interface name. */
122 ret = inet_aton (gate_str, &gate);
123 if (ret)
124 ifname = NULL;
125 else
126 ifname = gate_str;
127
128 if (add_cmd)
Everton Marques96bb2662014-07-14 11:19:00 -0300129 static_add_ipv4_safi (safi, &p, ifname ? NULL : &gate, ifname, flag, distance, 0);
paul718e3742002-12-13 20:15:29 +0000130 else
Everton Marques96bb2662014-07-14 11:19:00 -0300131 static_delete_ipv4_safi (safi, &p, ifname ? NULL : &gate, ifname, distance, 0);
paul718e3742002-12-13 20:15:29 +0000132
133 return CMD_SUCCESS;
134}
135
Everton Marques96bb2662014-07-14 11:19:00 -0300136static int
137zebra_static_ipv4 (struct vty *vty, int add_cmd, const char *dest_str,
138 const char *mask_str, const char *gate_str,
139 const char *flag_str, const char *distance_str)
140{
141 return zebra_static_ipv4_safi(vty, SAFI_UNICAST, add_cmd, dest_str, mask_str, gate_str, flag_str, distance_str);
142}
143
144/* Static unicast routes for multicast RPF lookup. */
David Lamparter9e6366d2015-01-22 19:03:53 +0100145DEFUN (ip_mroute_dist,
146 ip_mroute_dist_cmd,
147 "ip mroute A.B.C.D/M (A.B.C.D|INTERFACE) <1-255>",
Everton Marques96bb2662014-07-14 11:19:00 -0300148 IP_STR
149 "Configure static unicast route into MRIB for multicast RPF lookup\n"
150 "IP destination prefix (e.g. 10.0.0.0/8)\n"
151 "Nexthop address\n"
152 "Nexthop interface name\n"
153 "Distance\n")
154{
David Lamparter9e6366d2015-01-22 19:03:53 +0100155 return zebra_static_ipv4_safi(vty, SAFI_MULTICAST, 1, argv[0], NULL, argv[1],
156 NULL, argc > 2 ? argv[2] : NULL);
Everton Marques96bb2662014-07-14 11:19:00 -0300157}
158
David Lamparter9e6366d2015-01-22 19:03:53 +0100159ALIAS (ip_mroute_dist,
160 ip_mroute_cmd,
161 "ip mroute A.B.C.D/M (A.B.C.D|INTERFACE)",
162 IP_STR
163 "Configure static unicast route into MRIB for multicast RPF lookup\n"
164 "IP destination prefix (e.g. 10.0.0.0/8)\n"
165 "Nexthop address\n"
166 "Nexthop interface name\n")
167
168DEFUN (no_ip_mroute_dist,
169 no_ip_mroute_dist_cmd,
170 "no ip mroute A.B.C.D/M (A.B.C.D|INTERFACE) <1-255>",
Everton Marques96bb2662014-07-14 11:19:00 -0300171 IP_STR
172 "Configure static unicast route into MRIB for multicast RPF lookup\n"
173 "IP destination prefix (e.g. 10.0.0.0/8)\n"
174 "Nexthop address\n"
175 "Nexthop interface name\n"
176 "Distance\n")
177{
David Lamparter9e6366d2015-01-22 19:03:53 +0100178 return zebra_static_ipv4_safi(vty, SAFI_MULTICAST, 0, argv[0], NULL, argv[1],
179 NULL, argc > 2 ? argv[2] : NULL);
Everton Marques96bb2662014-07-14 11:19:00 -0300180}
181
David Lamparter9e6366d2015-01-22 19:03:53 +0100182ALIAS (no_ip_mroute_dist,
183 no_ip_mroute_cmd,
184 "no ip mroute A.B.C.D/M (A.B.C.D|INTERFACE)",
185 NO_STR
186 IP_STR
187 "Configure static unicast route into MRIB for multicast RPF lookup\n"
188 "IP destination prefix (e.g. 10.0.0.0/8)\n"
189 "Nexthop address\n"
190 "Nexthop interface name\n")
191
Everton Marques96bb2662014-07-14 11:19:00 -0300192DEFUN (show_ip_rpf,
193 show_ip_rpf_cmd,
194 "show ip rpf",
195 SHOW_STR
196 IP_STR
197 "Display RPF information for multicast source\n")
198{
199 return do_show_ip_route(vty, SAFI_MULTICAST);
200}
201
paul718e3742002-12-13 20:15:29 +0000202/* Static route configuration. */
203DEFUN (ip_route,
204 ip_route_cmd,
paul595db7f2003-05-25 21:35:06 +0000205 "ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0)",
hasso81dfcaa2003-05-25 19:21:25 +0000206 IP_STR
207 "Establish static routes\n"
208 "IP destination prefix (e.g. 10.0.0.0/8)\n"
209 "IP gateway address\n"
paul595db7f2003-05-25 21:35:06 +0000210 "IP gateway interface name\n"
211 "Null interface\n")
hasso81dfcaa2003-05-25 19:21:25 +0000212{
213 return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], NULL, NULL);
214}
215
216DEFUN (ip_route_flags,
217 ip_route_flags_cmd,
218 "ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole)",
paul718e3742002-12-13 20:15:29 +0000219 IP_STR
220 "Establish static routes\n"
221 "IP destination prefix (e.g. 10.0.0.0/8)\n"
222 "IP gateway address\n"
223 "IP gateway interface name\n"
hasso81dfcaa2003-05-25 19:21:25 +0000224 "Emit an ICMP unreachable when matched\n"
225 "Silently discard pkts when matched\n")
paul718e3742002-12-13 20:15:29 +0000226{
hasso81dfcaa2003-05-25 19:21:25 +0000227 return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], argv[2], NULL);
paul718e3742002-12-13 20:15:29 +0000228}
229
hasso457ef552003-05-28 12:02:15 +0000230DEFUN (ip_route_flags2,
231 ip_route_flags2_cmd,
232 "ip route A.B.C.D/M (reject|blackhole)",
233 IP_STR
234 "Establish static routes\n"
235 "IP destination prefix (e.g. 10.0.0.0/8)\n"
236 "Emit an ICMP unreachable when matched\n"
237 "Silently discard pkts when matched\n")
238{
239 return zebra_static_ipv4 (vty, 1, argv[0], NULL, NULL, argv[1], NULL);
240}
241
paul718e3742002-12-13 20:15:29 +0000242/* Mask as A.B.C.D format. */
243DEFUN (ip_route_mask,
244 ip_route_mask_cmd,
paul595db7f2003-05-25 21:35:06 +0000245 "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0)",
hasso81dfcaa2003-05-25 19:21:25 +0000246 IP_STR
247 "Establish static routes\n"
248 "IP destination prefix\n"
249 "IP destination prefix mask\n"
250 "IP gateway address\n"
paul595db7f2003-05-25 21:35:06 +0000251 "IP gateway interface name\n"
252 "Null interface\n")
hasso81dfcaa2003-05-25 19:21:25 +0000253{
254 return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], NULL, NULL);
255}
256
257DEFUN (ip_route_mask_flags,
258 ip_route_mask_flags_cmd,
259 "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole)",
paul718e3742002-12-13 20:15:29 +0000260 IP_STR
261 "Establish static routes\n"
262 "IP destination prefix\n"
263 "IP destination prefix mask\n"
264 "IP gateway address\n"
265 "IP gateway interface name\n"
hasso81dfcaa2003-05-25 19:21:25 +0000266 "Emit an ICMP unreachable when matched\n"
267 "Silently discard pkts when matched\n")
paul718e3742002-12-13 20:15:29 +0000268{
hasso81dfcaa2003-05-25 19:21:25 +0000269 return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], argv[3], NULL);
paul718e3742002-12-13 20:15:29 +0000270}
271
hasso457ef552003-05-28 12:02:15 +0000272DEFUN (ip_route_mask_flags2,
273 ip_route_mask_flags2_cmd,
274 "ip route A.B.C.D A.B.C.D (reject|blackhole)",
275 IP_STR
276 "Establish static routes\n"
277 "IP destination prefix\n"
278 "IP destination prefix mask\n"
279 "Emit an ICMP unreachable when matched\n"
280 "Silently discard pkts when matched\n")
281{
282 return zebra_static_ipv4 (vty, 1, argv[0], argv[1], NULL, argv[2], NULL);
283}
284
paul718e3742002-12-13 20:15:29 +0000285/* Distance option value. */
286DEFUN (ip_route_distance,
287 ip_route_distance_cmd,
paul595db7f2003-05-25 21:35:06 +0000288 "ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0) <1-255>",
paul718e3742002-12-13 20:15:29 +0000289 IP_STR
290 "Establish static routes\n"
291 "IP destination prefix (e.g. 10.0.0.0/8)\n"
292 "IP gateway address\n"
293 "IP gateway interface name\n"
paul595db7f2003-05-25 21:35:06 +0000294 "Null interface\n"
paul718e3742002-12-13 20:15:29 +0000295 "Distance value for this route\n")
296{
hasso81dfcaa2003-05-25 19:21:25 +0000297 return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], NULL, argv[2]);
298}
299
300DEFUN (ip_route_flags_distance,
301 ip_route_flags_distance_cmd,
302 "ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
303 IP_STR
304 "Establish static routes\n"
305 "IP destination prefix (e.g. 10.0.0.0/8)\n"
306 "IP gateway address\n"
307 "IP gateway interface name\n"
308 "Emit an ICMP unreachable when matched\n"
309 "Silently discard pkts when matched\n"
310 "Distance value for this route\n")
311{
312 return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], argv[2], argv[3]);
paul718e3742002-12-13 20:15:29 +0000313}
314
hasso457ef552003-05-28 12:02:15 +0000315DEFUN (ip_route_flags_distance2,
316 ip_route_flags_distance2_cmd,
317 "ip route A.B.C.D/M (reject|blackhole) <1-255>",
318 IP_STR
319 "Establish static routes\n"
320 "IP destination prefix (e.g. 10.0.0.0/8)\n"
321 "Emit an ICMP unreachable when matched\n"
322 "Silently discard pkts when matched\n"
323 "Distance value for this route\n")
324{
325 return zebra_static_ipv4 (vty, 1, argv[0], NULL, NULL, argv[1], argv[2]);
326}
327
paul718e3742002-12-13 20:15:29 +0000328DEFUN (ip_route_mask_distance,
329 ip_route_mask_distance_cmd,
paul595db7f2003-05-25 21:35:06 +0000330 "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0) <1-255>",
paul718e3742002-12-13 20:15:29 +0000331 IP_STR
332 "Establish static routes\n"
333 "IP destination prefix\n"
334 "IP destination prefix mask\n"
335 "IP gateway address\n"
336 "IP gateway interface name\n"
paul595db7f2003-05-25 21:35:06 +0000337 "Null interface\n"
paul718e3742002-12-13 20:15:29 +0000338 "Distance value for this route\n")
339{
hasso81dfcaa2003-05-25 19:21:25 +0000340 return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], NULL, argv[3]);
341}
342
343DEFUN (ip_route_mask_flags_distance,
344 ip_route_mask_flags_distance_cmd,
345 "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
346 IP_STR
347 "Establish static routes\n"
348 "IP destination prefix\n"
349 "IP destination prefix mask\n"
350 "IP gateway address\n"
351 "IP gateway interface name\n"
hasso81dfcaa2003-05-25 19:21:25 +0000352 "Emit an ICMP unreachable when matched\n"
Christian Franke2b005152013-09-30 12:27:49 +0000353 "Silently discard pkts when matched\n"
354 "Distance value for this route\n")
hasso81dfcaa2003-05-25 19:21:25 +0000355{
356 return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], argv[3], argv[4]);
paul718e3742002-12-13 20:15:29 +0000357}
358
hasso457ef552003-05-28 12:02:15 +0000359DEFUN (ip_route_mask_flags_distance2,
360 ip_route_mask_flags_distance2_cmd,
361 "ip route A.B.C.D A.B.C.D (reject|blackhole) <1-255>",
362 IP_STR
363 "Establish static routes\n"
364 "IP destination prefix\n"
365 "IP destination prefix mask\n"
hasso457ef552003-05-28 12:02:15 +0000366 "Emit an ICMP unreachable when matched\n"
Christian Franke2b005152013-09-30 12:27:49 +0000367 "Silently discard pkts when matched\n"
368 "Distance value for this route\n")
hasso457ef552003-05-28 12:02:15 +0000369{
370 return zebra_static_ipv4 (vty, 1, argv[0], argv[1], NULL, argv[2], argv[3]);
371}
372
paul718e3742002-12-13 20:15:29 +0000373DEFUN (no_ip_route,
374 no_ip_route_cmd,
paul595db7f2003-05-25 21:35:06 +0000375 "no ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0)",
hasso81dfcaa2003-05-25 19:21:25 +0000376 NO_STR
377 IP_STR
378 "Establish static routes\n"
379 "IP destination prefix (e.g. 10.0.0.0/8)\n"
380 "IP gateway address\n"
paul595db7f2003-05-25 21:35:06 +0000381 "IP gateway interface name\n"
382 "Null interface\n")
hasso81dfcaa2003-05-25 19:21:25 +0000383{
384 return zebra_static_ipv4 (vty, 0, argv[0], NULL, argv[1], NULL, NULL);
385}
386
387ALIAS (no_ip_route,
388 no_ip_route_flags_cmd,
389 "no ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole)",
paul718e3742002-12-13 20:15:29 +0000390 NO_STR
391 IP_STR
392 "Establish static routes\n"
393 "IP destination prefix (e.g. 10.0.0.0/8)\n"
394 "IP gateway address\n"
395 "IP gateway interface name\n"
hasso81dfcaa2003-05-25 19:21:25 +0000396 "Emit an ICMP unreachable when matched\n"
397 "Silently discard pkts when matched\n")
paul718e3742002-12-13 20:15:29 +0000398
hasso457ef552003-05-28 12:02:15 +0000399DEFUN (no_ip_route_flags2,
400 no_ip_route_flags2_cmd,
401 "no ip route A.B.C.D/M (reject|blackhole)",
402 NO_STR
403 IP_STR
404 "Establish static routes\n"
405 "IP destination prefix (e.g. 10.0.0.0/8)\n"
406 "Emit an ICMP unreachable when matched\n"
407 "Silently discard pkts when matched\n")
408{
409 return zebra_static_ipv4 (vty, 0, argv[0], NULL, NULL, NULL, NULL);
410}
411
paul718e3742002-12-13 20:15:29 +0000412DEFUN (no_ip_route_mask,
413 no_ip_route_mask_cmd,
paul595db7f2003-05-25 21:35:06 +0000414 "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0)",
hasso81dfcaa2003-05-25 19:21:25 +0000415 NO_STR
416 IP_STR
417 "Establish static routes\n"
418 "IP destination prefix\n"
419 "IP destination prefix mask\n"
420 "IP gateway address\n"
paul595db7f2003-05-25 21:35:06 +0000421 "IP gateway interface name\n"
422 "Null interface\n")
hasso81dfcaa2003-05-25 19:21:25 +0000423{
424 return zebra_static_ipv4 (vty, 0, argv[0], argv[1], argv[2], NULL, NULL);
425}
426
427ALIAS (no_ip_route_mask,
428 no_ip_route_mask_flags_cmd,
429 "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole)",
paul718e3742002-12-13 20:15:29 +0000430 NO_STR
431 IP_STR
432 "Establish static routes\n"
433 "IP destination prefix\n"
434 "IP destination prefix mask\n"
435 "IP gateway address\n"
436 "IP gateway interface name\n"
hasso81dfcaa2003-05-25 19:21:25 +0000437 "Emit an ICMP unreachable when matched\n"
438 "Silently discard pkts when matched\n")
paul718e3742002-12-13 20:15:29 +0000439
hasso457ef552003-05-28 12:02:15 +0000440DEFUN (no_ip_route_mask_flags2,
441 no_ip_route_mask_flags2_cmd,
442 "no ip route A.B.C.D A.B.C.D (reject|blackhole)",
443 NO_STR
444 IP_STR
445 "Establish static routes\n"
446 "IP destination prefix\n"
447 "IP destination prefix mask\n"
448 "Emit an ICMP unreachable when matched\n"
449 "Silently discard pkts when matched\n")
450{
451 return zebra_static_ipv4 (vty, 0, argv[0], argv[1], NULL, NULL, NULL);
452}
453
paul718e3742002-12-13 20:15:29 +0000454DEFUN (no_ip_route_distance,
455 no_ip_route_distance_cmd,
paul595db7f2003-05-25 21:35:06 +0000456 "no ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0) <1-255>",
paul718e3742002-12-13 20:15:29 +0000457 NO_STR
458 IP_STR
459 "Establish static routes\n"
460 "IP destination prefix (e.g. 10.0.0.0/8)\n"
461 "IP gateway address\n"
462 "IP gateway interface name\n"
paul595db7f2003-05-25 21:35:06 +0000463 "Null interface\n"
paul718e3742002-12-13 20:15:29 +0000464 "Distance value for this route\n")
465{
hasso81dfcaa2003-05-25 19:21:25 +0000466 return zebra_static_ipv4 (vty, 0, argv[0], NULL, argv[1], NULL, argv[2]);
467}
468
469DEFUN (no_ip_route_flags_distance,
470 no_ip_route_flags_distance_cmd,
471 "no ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
472 NO_STR
473 IP_STR
474 "Establish static routes\n"
475 "IP destination prefix (e.g. 10.0.0.0/8)\n"
476 "IP gateway address\n"
477 "IP gateway interface name\n"
478 "Emit an ICMP unreachable when matched\n"
479 "Silently discard pkts when matched\n"
480 "Distance value for this route\n")
481{
482 return zebra_static_ipv4 (vty, 0, argv[0], NULL, argv[1], argv[2], argv[3]);
paul718e3742002-12-13 20:15:29 +0000483}
484
hasso457ef552003-05-28 12:02:15 +0000485DEFUN (no_ip_route_flags_distance2,
486 no_ip_route_flags_distance2_cmd,
487 "no ip route A.B.C.D/M (reject|blackhole) <1-255>",
488 NO_STR
489 IP_STR
490 "Establish static routes\n"
491 "IP destination prefix (e.g. 10.0.0.0/8)\n"
492 "Emit an ICMP unreachable when matched\n"
493 "Silently discard pkts when matched\n"
494 "Distance value for this route\n")
495{
496 return zebra_static_ipv4 (vty, 0, argv[0], NULL, NULL, argv[1], argv[2]);
497}
498
paul718e3742002-12-13 20:15:29 +0000499DEFUN (no_ip_route_mask_distance,
500 no_ip_route_mask_distance_cmd,
paul595db7f2003-05-25 21:35:06 +0000501 "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 +0000502 NO_STR
503 IP_STR
504 "Establish static routes\n"
505 "IP destination prefix\n"
506 "IP destination prefix mask\n"
507 "IP gateway address\n"
508 "IP gateway interface name\n"
paul595db7f2003-05-25 21:35:06 +0000509 "Null interface\n"
paul718e3742002-12-13 20:15:29 +0000510 "Distance value for this route\n")
511{
hasso81dfcaa2003-05-25 19:21:25 +0000512 return zebra_static_ipv4 (vty, 0, argv[0], argv[1], argv[2], NULL, argv[3]);
513}
514
515DEFUN (no_ip_route_mask_flags_distance,
516 no_ip_route_mask_flags_distance_cmd,
517 "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
518 NO_STR
519 IP_STR
520 "Establish static routes\n"
521 "IP destination prefix\n"
522 "IP destination prefix mask\n"
523 "IP gateway address\n"
524 "IP gateway interface name\n"
525 "Emit an ICMP unreachable when matched\n"
526 "Silently discard pkts when matched\n"
527 "Distance value for this route\n")
528{
529 return zebra_static_ipv4 (vty, 0, argv[0], argv[1], argv[2], argv[3], argv[4]);
paul718e3742002-12-13 20:15:29 +0000530}
531
hasso457ef552003-05-28 12:02:15 +0000532DEFUN (no_ip_route_mask_flags_distance2,
533 no_ip_route_mask_flags_distance2_cmd,
534 "no ip route A.B.C.D A.B.C.D (reject|blackhole) <1-255>",
535 NO_STR
536 IP_STR
537 "Establish static routes\n"
538 "IP destination prefix\n"
539 "IP destination prefix mask\n"
540 "Emit an ICMP unreachable when matched\n"
541 "Silently discard pkts when matched\n"
542 "Distance value for this route\n")
543{
544 return zebra_static_ipv4 (vty, 0, argv[0], argv[1], NULL, argv[2], argv[3]);
545}
546
Paul Jakma7514fb72007-05-02 16:05:35 +0000547char *proto_rm[AFI_MAX][ZEBRA_ROUTE_MAX+1]; /* "any" == ZEBRA_ROUTE_MAX */
548
549DEFUN (ip_protocol,
550 ip_protocol_cmd,
551 "ip protocol PROTO route-map ROUTE-MAP",
552 NO_STR
553 "Apply route map to PROTO\n"
554 "Protocol name\n"
555 "Route map name\n")
556{
557 int i;
558
559 if (strcasecmp(argv[0], "any") == 0)
560 i = ZEBRA_ROUTE_MAX;
561 else
562 i = proto_name2num(argv[0]);
563 if (i < 0)
564 {
565 vty_out (vty, "invalid protocol name \"%s\"%s", argv[0] ? argv[0] : "",
566 VTY_NEWLINE);
567 return CMD_WARNING;
568 }
569 if (proto_rm[AFI_IP][i])
570 XFREE (MTYPE_ROUTE_MAP_NAME, proto_rm[AFI_IP][i]);
571 proto_rm[AFI_IP][i] = XSTRDUP (MTYPE_ROUTE_MAP_NAME, argv[1]);
572 return CMD_SUCCESS;
573}
574
575DEFUN (no_ip_protocol,
576 no_ip_protocol_cmd,
577 "no ip protocol PROTO",
578 NO_STR
579 "Remove route map from PROTO\n"
580 "Protocol name\n")
581{
582 int i;
583
584 if (strcasecmp(argv[0], "any") == 0)
585 i = ZEBRA_ROUTE_MAX;
586 else
587 i = proto_name2num(argv[0]);
588 if (i < 0)
589 {
590 vty_out (vty, "invalid protocol name \"%s\"%s", argv[0] ? argv[0] : "",
591 VTY_NEWLINE);
592 return CMD_WARNING;
593 }
594 if (proto_rm[AFI_IP][i])
595 XFREE (MTYPE_ROUTE_MAP_NAME, proto_rm[AFI_IP][i]);
596 proto_rm[AFI_IP][i] = NULL;
597 return CMD_SUCCESS;
598}
599
paul718e3742002-12-13 20:15:29 +0000600/* New RIB. Detailed information for IPv4 route. */
paula1ac18c2005-06-28 17:17:12 +0000601static void
paul718e3742002-12-13 20:15:29 +0000602vty_show_ip_route_detail (struct vty *vty, struct route_node *rn)
603{
604 struct rib *rib;
Christian Frankefa713d92013-07-05 15:35:37 +0000605 struct nexthop *nexthop, *tnexthop;
606 int recursing;
paul718e3742002-12-13 20:15:29 +0000607
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000608 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +0000609 {
610 vty_out (vty, "Routing entry for %s/%d%s",
611 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
612 VTY_NEWLINE);
ajsf52d13c2005-10-01 17:38:06 +0000613 vty_out (vty, " Known via \"%s\"", zebra_route_string (rib->type));
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +0200614 vty_out (vty, ", distance %u, metric %u", rib->distance, rib->metric);
paul718e3742002-12-13 20:15:29 +0000615 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
616 vty_out (vty, ", best");
617 if (rib->refcnt)
618 vty_out (vty, ", refcnt %ld", rib->refcnt);
hasso81dfcaa2003-05-25 19:21:25 +0000619 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
620 vty_out (vty, ", blackhole");
621 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT))
622 vty_out (vty, ", reject");
paul718e3742002-12-13 20:15:29 +0000623 vty_out (vty, "%s", VTY_NEWLINE);
624
625#define ONE_DAY_SECOND 60*60*24
626#define ONE_WEEK_SECOND 60*60*24*7
627 if (rib->type == ZEBRA_ROUTE_RIP
628 || rib->type == ZEBRA_ROUTE_OSPF
Juliusz Chroboczek578ce372012-02-09 13:42:28 +0100629 || rib->type == ZEBRA_ROUTE_BABEL
jardin9e867fe2003-12-23 08:56:18 +0000630 || rib->type == ZEBRA_ROUTE_ISIS
paul718e3742002-12-13 20:15:29 +0000631 || rib->type == ZEBRA_ROUTE_BGP)
632 {
633 time_t uptime;
634 struct tm *tm;
635
636 uptime = time (NULL);
637 uptime -= rib->uptime;
638 tm = gmtime (&uptime);
639
640 vty_out (vty, " Last update ");
641
642 if (uptime < ONE_DAY_SECOND)
643 vty_out (vty, "%02d:%02d:%02d",
644 tm->tm_hour, tm->tm_min, tm->tm_sec);
645 else if (uptime < ONE_WEEK_SECOND)
646 vty_out (vty, "%dd%02dh%02dm",
647 tm->tm_yday, tm->tm_hour, tm->tm_min);
648 else
649 vty_out (vty, "%02dw%dd%02dh",
650 tm->tm_yday/7,
651 tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
652 vty_out (vty, " ago%s", VTY_NEWLINE);
653 }
654
Christian Frankefa713d92013-07-05 15:35:37 +0000655 for (ALL_NEXTHOPS_RO(rib->nexthop, nexthop, tnexthop, recursing))
paul718e3742002-12-13 20:15:29 +0000656 {
Paul Jakma7514fb72007-05-02 16:05:35 +0000657 char addrstr[32];
658
Christian Frankefa713d92013-07-05 15:35:37 +0000659 vty_out (vty, " %c%s",
660 CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB) ? '*' : ' ',
661 recursing ? " " : "");
paul718e3742002-12-13 20:15:29 +0000662
663 switch (nexthop->type)
664 {
665 case NEXTHOP_TYPE_IPV4:
666 case NEXTHOP_TYPE_IPV4_IFINDEX:
667 vty_out (vty, " %s", inet_ntoa (nexthop->gate.ipv4));
668 if (nexthop->ifindex)
669 vty_out (vty, ", via %s", ifindex2ifname (nexthop->ifindex));
670 break;
671 case NEXTHOP_TYPE_IFINDEX:
672 vty_out (vty, " directly connected, %s",
673 ifindex2ifname (nexthop->ifindex));
674 break;
675 case NEXTHOP_TYPE_IFNAME:
676 vty_out (vty, " directly connected, %s", nexthop->ifname);
677 break;
paul595db7f2003-05-25 21:35:06 +0000678 case NEXTHOP_TYPE_BLACKHOLE:
paul7021c422003-07-15 12:52:22 +0000679 vty_out (vty, " directly connected, Null0");
paul595db7f2003-05-25 21:35:06 +0000680 break;
paul7021c422003-07-15 12:52:22 +0000681 default:
paul718e3742002-12-13 20:15:29 +0000682 break;
683 }
684 if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
685 vty_out (vty, " inactive");
686
Christian Frankee8d3d292013-07-05 15:35:39 +0000687 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ONLINK))
688 vty_out (vty, " onlink");
689
paul718e3742002-12-13 20:15:29 +0000690 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
Christian Frankefa713d92013-07-05 15:35:37 +0000691 vty_out (vty, " (recursive)");
Christian Franke5b9f5182013-05-25 14:01:34 +0000692
Paul Jakma7514fb72007-05-02 16:05:35 +0000693 switch (nexthop->type)
694 {
695 case NEXTHOP_TYPE_IPV4:
696 case NEXTHOP_TYPE_IPV4_IFINDEX:
697 case NEXTHOP_TYPE_IPV4_IFNAME:
698 if (nexthop->src.ipv4.s_addr)
699 {
700 if (inet_ntop(AF_INET, &nexthop->src.ipv4, addrstr,
701 sizeof addrstr))
702 vty_out (vty, ", src %s", addrstr);
703 }
704 break;
Andrew J. Schorr09303312007-05-30 20:10:34 +0000705#ifdef HAVE_IPV6
Paul Jakma7514fb72007-05-02 16:05:35 +0000706 case NEXTHOP_TYPE_IPV6:
707 case NEXTHOP_TYPE_IPV6_IFINDEX:
708 case NEXTHOP_TYPE_IPV6_IFNAME:
709 if (!IPV6_ADDR_SAME(&nexthop->src.ipv6, &in6addr_any))
710 {
711 if (inet_ntop(AF_INET6, &nexthop->src.ipv6, addrstr,
712 sizeof addrstr))
713 vty_out (vty, ", src %s", addrstr);
714 }
715 break;
Andrew J. Schorr09303312007-05-30 20:10:34 +0000716#endif /* HAVE_IPV6 */
Paul Jakma7514fb72007-05-02 16:05:35 +0000717 default:
718 break;
719 }
paul718e3742002-12-13 20:15:29 +0000720 vty_out (vty, "%s", VTY_NEWLINE);
721 }
722 vty_out (vty, "%s", VTY_NEWLINE);
723 }
724}
725
paula1ac18c2005-06-28 17:17:12 +0000726static void
paul718e3742002-12-13 20:15:29 +0000727vty_show_ip_route (struct vty *vty, struct route_node *rn, struct rib *rib)
728{
Christian Frankefa713d92013-07-05 15:35:37 +0000729 struct nexthop *nexthop, *tnexthop;
730 int recursing;
paul718e3742002-12-13 20:15:29 +0000731 int len = 0;
732 char buf[BUFSIZ];
733
734 /* Nexthop information. */
Christian Frankefa713d92013-07-05 15:35:37 +0000735 for (ALL_NEXTHOPS_RO(rib->nexthop, nexthop, tnexthop, recursing))
paul718e3742002-12-13 20:15:29 +0000736 {
737 if (nexthop == rib->nexthop)
738 {
739 /* Prefix information. */
740 len = vty_out (vty, "%c%c%c %s/%d",
ajsf52d13c2005-10-01 17:38:06 +0000741 zebra_route_char (rib->type),
paul718e3742002-12-13 20:15:29 +0000742 CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED)
743 ? '>' : ' ',
744 CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
745 ? '*' : ' ',
746 inet_ntop (AF_INET, &rn->p.u.prefix, buf, BUFSIZ),
747 rn->p.prefixlen);
748
749 /* Distance and metric display. */
750 if (rib->type != ZEBRA_ROUTE_CONNECT
751 && rib->type != ZEBRA_ROUTE_KERNEL)
752 len += vty_out (vty, " [%d/%d]", rib->distance,
753 rib->metric);
754 }
755 else
756 vty_out (vty, " %c%*c",
757 CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
758 ? '*' : ' ',
Christian Frankefa713d92013-07-05 15:35:37 +0000759 len - 3 + (2 * recursing), ' ');
paul718e3742002-12-13 20:15:29 +0000760
761 switch (nexthop->type)
762 {
763 case NEXTHOP_TYPE_IPV4:
764 case NEXTHOP_TYPE_IPV4_IFINDEX:
765 vty_out (vty, " via %s", inet_ntoa (nexthop->gate.ipv4));
766 if (nexthop->ifindex)
767 vty_out (vty, ", %s", ifindex2ifname (nexthop->ifindex));
768 break;
769 case NEXTHOP_TYPE_IFINDEX:
770 vty_out (vty, " is directly connected, %s",
771 ifindex2ifname (nexthop->ifindex));
772 break;
773 case NEXTHOP_TYPE_IFNAME:
774 vty_out (vty, " is directly connected, %s", nexthop->ifname);
775 break;
paul595db7f2003-05-25 21:35:06 +0000776 case NEXTHOP_TYPE_BLACKHOLE:
paul7021c422003-07-15 12:52:22 +0000777 vty_out (vty, " is directly connected, Null0");
paul595db7f2003-05-25 21:35:06 +0000778 break;
paul7021c422003-07-15 12:52:22 +0000779 default:
paul718e3742002-12-13 20:15:29 +0000780 break;
781 }
782 if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
783 vty_out (vty, " inactive");
784
Christian Frankee8d3d292013-07-05 15:35:39 +0000785 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ONLINK))
786 vty_out (vty, " onlink");
787
paul718e3742002-12-13 20:15:29 +0000788 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
Christian Frankefa713d92013-07-05 15:35:37 +0000789 vty_out (vty, " (recursive)");
790
Paul Jakma7514fb72007-05-02 16:05:35 +0000791 switch (nexthop->type)
792 {
793 case NEXTHOP_TYPE_IPV4:
794 case NEXTHOP_TYPE_IPV4_IFINDEX:
795 case NEXTHOP_TYPE_IPV4_IFNAME:
796 if (nexthop->src.ipv4.s_addr)
797 {
798 if (inet_ntop(AF_INET, &nexthop->src.ipv4, buf, sizeof buf))
799 vty_out (vty, ", src %s", buf);
800 }
801 break;
Andrew J. Schorr09303312007-05-30 20:10:34 +0000802#ifdef HAVE_IPV6
Paul Jakma7514fb72007-05-02 16:05:35 +0000803 case NEXTHOP_TYPE_IPV6:
804 case NEXTHOP_TYPE_IPV6_IFINDEX:
805 case NEXTHOP_TYPE_IPV6_IFNAME:
806 if (!IPV6_ADDR_SAME(&nexthop->src.ipv6, &in6addr_any))
807 {
808 if (inet_ntop(AF_INET6, &nexthop->src.ipv6, buf, sizeof buf))
809 vty_out (vty, ", src %s", buf);
810 }
811 break;
Andrew J. Schorr09303312007-05-30 20:10:34 +0000812#endif /* HAVE_IPV6 */
Paul Jakma7514fb72007-05-02 16:05:35 +0000813 default:
814 break;
815 }
paul718e3742002-12-13 20:15:29 +0000816
hasso81dfcaa2003-05-25 19:21:25 +0000817 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
818 vty_out (vty, ", bh");
819 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT))
820 vty_out (vty, ", rej");
821
paul718e3742002-12-13 20:15:29 +0000822 if (rib->type == ZEBRA_ROUTE_RIP
823 || rib->type == ZEBRA_ROUTE_OSPF
Juliusz Chroboczek578ce372012-02-09 13:42:28 +0100824 || rib->type == ZEBRA_ROUTE_BABEL
jardin9e867fe2003-12-23 08:56:18 +0000825 || rib->type == ZEBRA_ROUTE_ISIS
paul718e3742002-12-13 20:15:29 +0000826 || rib->type == ZEBRA_ROUTE_BGP)
827 {
828 time_t uptime;
829 struct tm *tm;
830
831 uptime = time (NULL);
832 uptime -= rib->uptime;
833 tm = gmtime (&uptime);
834
835#define ONE_DAY_SECOND 60*60*24
836#define ONE_WEEK_SECOND 60*60*24*7
837
838 if (uptime < ONE_DAY_SECOND)
839 vty_out (vty, ", %02d:%02d:%02d",
840 tm->tm_hour, tm->tm_min, tm->tm_sec);
841 else if (uptime < ONE_WEEK_SECOND)
842 vty_out (vty, ", %dd%02dh%02dm",
843 tm->tm_yday, tm->tm_hour, tm->tm_min);
844 else
845 vty_out (vty, ", %02dw%dd%02dh",
846 tm->tm_yday/7,
847 tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
848 }
849 vty_out (vty, "%s", VTY_NEWLINE);
850 }
851}
852
paul718e3742002-12-13 20:15:29 +0000853DEFUN (show_ip_route,
854 show_ip_route_cmd,
855 "show ip route",
856 SHOW_STR
857 IP_STR
858 "IP routing table\n")
859{
Everton Marques96bb2662014-07-14 11:19:00 -0300860 return do_show_ip_route(vty, SAFI_UNICAST);
861}
862
863static int do_show_ip_route(struct vty *vty, safi_t safi) {
paul718e3742002-12-13 20:15:29 +0000864 struct route_table *table;
865 struct route_node *rn;
866 struct rib *rib;
867 int first = 1;
868
Everton Marques96bb2662014-07-14 11:19:00 -0300869 table = vrf_table (AFI_IP, safi, 0);
paul718e3742002-12-13 20:15:29 +0000870 if (! table)
871 return CMD_SUCCESS;
872
873 /* Show all IPv4 routes. */
874 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000875 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +0000876 {
877 if (first)
878 {
David Lampartere0ca5fd2009-09-16 01:52:42 +0200879 vty_out (vty, SHOW_ROUTE_V4_HEADER);
paul718e3742002-12-13 20:15:29 +0000880 first = 0;
881 }
882 vty_show_ip_route (vty, rn, rib);
883 }
884 return CMD_SUCCESS;
885}
886
887DEFUN (show_ip_route_prefix_longer,
888 show_ip_route_prefix_longer_cmd,
889 "show ip route A.B.C.D/M longer-prefixes",
890 SHOW_STR
891 IP_STR
892 "IP routing table\n"
893 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
894 "Show route matching the specified Network/Mask pair only\n")
895{
896 struct route_table *table;
897 struct route_node *rn;
898 struct rib *rib;
899 struct prefix p;
900 int ret;
901 int first = 1;
902
903 ret = str2prefix (argv[0], &p);
904 if (! ret)
905 {
906 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
907 return CMD_WARNING;
908 }
909
910 table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
911 if (! table)
912 return CMD_SUCCESS;
913
914 /* Show matched type IPv4 routes. */
915 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000916 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +0000917 if (prefix_match (&p, &rn->p))
918 {
919 if (first)
920 {
David Lampartere0ca5fd2009-09-16 01:52:42 +0200921 vty_out (vty, SHOW_ROUTE_V4_HEADER);
paul718e3742002-12-13 20:15:29 +0000922 first = 0;
923 }
924 vty_show_ip_route (vty, rn, rib);
925 }
926 return CMD_SUCCESS;
927}
928
929DEFUN (show_ip_route_supernets,
930 show_ip_route_supernets_cmd,
931 "show ip route supernets-only",
932 SHOW_STR
933 IP_STR
934 "IP routing table\n"
935 "Show supernet entries only\n")
936{
937 struct route_table *table;
938 struct route_node *rn;
939 struct rib *rib;
940 u_int32_t addr;
941 int first = 1;
942
943 table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
944 if (! table)
945 return CMD_SUCCESS;
946
947 /* Show matched type IPv4 routes. */
948 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000949 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +0000950 {
951 addr = ntohl (rn->p.u.prefix4.s_addr);
952
953 if ((IN_CLASSC (addr) && rn->p.prefixlen < 24)
954 || (IN_CLASSB (addr) && rn->p.prefixlen < 16)
955 || (IN_CLASSA (addr) && rn->p.prefixlen < 8))
956 {
957 if (first)
958 {
David Lampartere0ca5fd2009-09-16 01:52:42 +0200959 vty_out (vty, SHOW_ROUTE_V4_HEADER);
paul718e3742002-12-13 20:15:29 +0000960 first = 0;
961 }
962 vty_show_ip_route (vty, rn, rib);
963 }
964 }
965 return CMD_SUCCESS;
966}
967
968DEFUN (show_ip_route_protocol,
969 show_ip_route_protocol_cmd,
David Lampartere0ca5fd2009-09-16 01:52:42 +0200970 "show ip route " QUAGGA_IP_REDIST_STR_ZEBRA,
paul718e3742002-12-13 20:15:29 +0000971 SHOW_STR
972 IP_STR
973 "IP routing table\n"
David Lampartere0ca5fd2009-09-16 01:52:42 +0200974 QUAGGA_IP_REDIST_HELP_STR_ZEBRA)
paul718e3742002-12-13 20:15:29 +0000975{
976 int type;
977 struct route_table *table;
978 struct route_node *rn;
979 struct rib *rib;
980 int first = 1;
981
David Lampartere0ca5fd2009-09-16 01:52:42 +0200982 type = proto_redistnum (AFI_IP, argv[0]);
983 if (type < 0)
paul718e3742002-12-13 20:15:29 +0000984 {
985 vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
986 return CMD_WARNING;
987 }
988
989 table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
990 if (! table)
991 return CMD_SUCCESS;
992
993 /* Show matched type IPv4 routes. */
994 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000995 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +0000996 if (rib->type == type)
997 {
998 if (first)
999 {
David Lampartere0ca5fd2009-09-16 01:52:42 +02001000 vty_out (vty, SHOW_ROUTE_V4_HEADER);
paul718e3742002-12-13 20:15:29 +00001001 first = 0;
1002 }
1003 vty_show_ip_route (vty, rn, rib);
1004 }
1005 return CMD_SUCCESS;
1006}
1007
1008DEFUN (show_ip_route_addr,
1009 show_ip_route_addr_cmd,
1010 "show ip route A.B.C.D",
1011 SHOW_STR
1012 IP_STR
1013 "IP routing table\n"
1014 "Network in the IP routing table to display\n")
1015{
1016 int ret;
1017 struct prefix_ipv4 p;
1018 struct route_table *table;
1019 struct route_node *rn;
1020
1021 ret = str2prefix_ipv4 (argv[0], &p);
1022 if (ret <= 0)
1023 {
1024 vty_out (vty, "%% Malformed IPv4 address%s", VTY_NEWLINE);
1025 return CMD_WARNING;
1026 }
1027
1028 table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
1029 if (! table)
1030 return CMD_SUCCESS;
1031
1032 rn = route_node_match (table, (struct prefix *) &p);
1033 if (! rn)
1034 {
1035 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
1036 return CMD_WARNING;
1037 }
1038
1039 vty_show_ip_route_detail (vty, rn);
1040
1041 route_unlock_node (rn);
1042
1043 return CMD_SUCCESS;
1044}
1045
1046DEFUN (show_ip_route_prefix,
1047 show_ip_route_prefix_cmd,
1048 "show ip route A.B.C.D/M",
1049 SHOW_STR
1050 IP_STR
1051 "IP routing table\n"
1052 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
1053{
1054 int ret;
1055 struct prefix_ipv4 p;
1056 struct route_table *table;
1057 struct route_node *rn;
1058
1059 ret = str2prefix_ipv4 (argv[0], &p);
1060 if (ret <= 0)
1061 {
1062 vty_out (vty, "%% Malformed IPv4 address%s", VTY_NEWLINE);
1063 return CMD_WARNING;
1064 }
1065
1066 table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
1067 if (! table)
1068 return CMD_SUCCESS;
1069
1070 rn = route_node_match (table, (struct prefix *) &p);
1071 if (! rn || rn->p.prefixlen != p.prefixlen)
1072 {
1073 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
Lu Feng969d3552014-10-21 06:24:07 +00001074 if (rn)
1075 route_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00001076 return CMD_WARNING;
1077 }
1078
1079 vty_show_ip_route_detail (vty, rn);
1080
1081 route_unlock_node (rn);
1082
1083 return CMD_SUCCESS;
1084}
1085
paula1ac18c2005-06-28 17:17:12 +00001086static void
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001087vty_show_ip_route_summary (struct vty *vty, struct route_table *table)
paul718e3742002-12-13 20:15:29 +00001088{
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001089 struct route_node *rn;
1090 struct rib *rib;
1091 struct nexthop *nexthop;
1092#define ZEBRA_ROUTE_IBGP ZEBRA_ROUTE_MAX
1093#define ZEBRA_ROUTE_TOTAL (ZEBRA_ROUTE_IBGP + 1)
1094 u_int32_t rib_cnt[ZEBRA_ROUTE_TOTAL + 1];
1095 u_int32_t fib_cnt[ZEBRA_ROUTE_TOTAL + 1];
1096 u_int32_t i;
paul718e3742002-12-13 20:15:29 +00001097
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001098 memset (&rib_cnt, 0, sizeof(rib_cnt));
1099 memset (&fib_cnt, 0, sizeof(fib_cnt));
1100 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001101 RNODE_FOREACH_RIB (rn, rib)
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001102 for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
1103 {
1104 rib_cnt[ZEBRA_ROUTE_TOTAL]++;
1105 rib_cnt[rib->type]++;
Christian Frankefa713d92013-07-05 15:35:37 +00001106 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
1107 || nexthop_has_fib_child(nexthop))
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001108 {
1109 fib_cnt[ZEBRA_ROUTE_TOTAL]++;
1110 fib_cnt[rib->type]++;
1111 }
1112 if (rib->type == ZEBRA_ROUTE_BGP &&
1113 CHECK_FLAG (rib->flags, ZEBRA_FLAG_IBGP))
1114 {
1115 rib_cnt[ZEBRA_ROUTE_IBGP]++;
Christian Frankefa713d92013-07-05 15:35:37 +00001116 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
1117 || nexthop_has_fib_child(nexthop))
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001118 fib_cnt[ZEBRA_ROUTE_IBGP]++;
1119 }
1120 }
paul718e3742002-12-13 20:15:29 +00001121
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001122 vty_out (vty, "%-20s %-20s %-20s %s",
1123 "Route Source", "Routes", "FIB", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001124
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001125 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
1126 {
1127 if (rib_cnt[i] > 0)
1128 {
1129 if (i == ZEBRA_ROUTE_BGP)
1130 {
1131 vty_out (vty, "%-20s %-20d %-20d %s", "ebgp",
1132 rib_cnt[ZEBRA_ROUTE_BGP] - rib_cnt[ZEBRA_ROUTE_IBGP],
1133 fib_cnt[ZEBRA_ROUTE_BGP] - fib_cnt[ZEBRA_ROUTE_IBGP],
1134 VTY_NEWLINE);
1135 vty_out (vty, "%-20s %-20d %-20d %s", "ibgp",
1136 rib_cnt[ZEBRA_ROUTE_IBGP], fib_cnt[ZEBRA_ROUTE_IBGP],
1137 VTY_NEWLINE);
1138 }
1139 else
1140 vty_out (vty, "%-20s %-20d %-20d %s", zebra_route_string(i),
1141 rib_cnt[i], fib_cnt[i], VTY_NEWLINE);
1142 }
1143 }
paul718e3742002-12-13 20:15:29 +00001144
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001145 vty_out (vty, "------%s", VTY_NEWLINE);
1146 vty_out (vty, "%-20s %-20d %-20d %s", "Totals", rib_cnt[ZEBRA_ROUTE_TOTAL],
1147 fib_cnt[ZEBRA_ROUTE_TOTAL], VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001148}
1149
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07001150/*
1151 * Implementation of the ip route summary prefix command.
1152 *
1153 * This command prints the primary prefixes that have been installed by various
1154 * protocols on the box.
1155 *
1156 */
1157static void
1158vty_show_ip_route_summary_prefix (struct vty *vty, struct route_table *table)
1159{
1160 struct route_node *rn;
1161 struct rib *rib;
1162 struct nexthop *nexthop;
1163#define ZEBRA_ROUTE_IBGP ZEBRA_ROUTE_MAX
1164#define ZEBRA_ROUTE_TOTAL (ZEBRA_ROUTE_IBGP + 1)
1165 u_int32_t rib_cnt[ZEBRA_ROUTE_TOTAL + 1];
1166 u_int32_t fib_cnt[ZEBRA_ROUTE_TOTAL + 1];
1167 u_int32_t i;
1168 int cnt;
1169
1170 memset (&rib_cnt, 0, sizeof(rib_cnt));
1171 memset (&fib_cnt, 0, sizeof(fib_cnt));
1172 for (rn = route_top (table); rn; rn = route_next (rn))
1173 RNODE_FOREACH_RIB (rn, rib)
1174 {
1175
1176 /*
1177 * In case of ECMP, count only once.
1178 */
1179 cnt = 0;
1180 for (nexthop = rib->nexthop; (!cnt && nexthop); nexthop = nexthop->next)
1181 {
1182 cnt++;
1183 rib_cnt[ZEBRA_ROUTE_TOTAL]++;
1184 rib_cnt[rib->type]++;
1185 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB))
1186 {
1187 fib_cnt[ZEBRA_ROUTE_TOTAL]++;
1188 fib_cnt[rib->type]++;
1189 }
1190 if (rib->type == ZEBRA_ROUTE_BGP &&
1191 CHECK_FLAG (rib->flags, ZEBRA_FLAG_IBGP))
1192 {
1193 rib_cnt[ZEBRA_ROUTE_IBGP]++;
1194 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB))
1195 fib_cnt[ZEBRA_ROUTE_IBGP]++;
1196 }
1197 }
1198 }
1199
1200 vty_out (vty, "%-20s %-20s %-20s %s",
1201 "Route Source", "Prefix Routes", "FIB", VTY_NEWLINE);
1202
1203 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
1204 {
1205 if (rib_cnt[i] > 0)
1206 {
1207 if (i == ZEBRA_ROUTE_BGP)
1208 {
1209 vty_out (vty, "%-20s %-20d %-20d %s", "ebgp",
1210 rib_cnt[ZEBRA_ROUTE_BGP] - rib_cnt[ZEBRA_ROUTE_IBGP],
1211 fib_cnt[ZEBRA_ROUTE_BGP] - fib_cnt[ZEBRA_ROUTE_IBGP],
1212 VTY_NEWLINE);
1213 vty_out (vty, "%-20s %-20d %-20d %s", "ibgp",
1214 rib_cnt[ZEBRA_ROUTE_IBGP], fib_cnt[ZEBRA_ROUTE_IBGP],
1215 VTY_NEWLINE);
1216 }
1217 else
1218 vty_out (vty, "%-20s %-20d %-20d %s", zebra_route_string(i),
1219 rib_cnt[i], fib_cnt[i], VTY_NEWLINE);
1220 }
1221 }
1222
1223 vty_out (vty, "------%s", VTY_NEWLINE);
1224 vty_out (vty, "%-20s %-20d %-20d %s", "Totals", rib_cnt[ZEBRA_ROUTE_TOTAL],
1225 fib_cnt[ZEBRA_ROUTE_TOTAL], VTY_NEWLINE);
1226}
1227
paul718e3742002-12-13 20:15:29 +00001228/* Show route summary. */
1229DEFUN (show_ip_route_summary,
1230 show_ip_route_summary_cmd,
1231 "show ip route summary",
1232 SHOW_STR
1233 IP_STR
1234 "IP routing table\n"
1235 "Summary of all routes\n")
1236{
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001237 struct route_table *table;
paul718e3742002-12-13 20:15:29 +00001238
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001239 table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
1240 if (! table)
1241 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001242
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001243 vty_show_ip_route_summary (vty, table);
paul718e3742002-12-13 20:15:29 +00001244
1245 return CMD_SUCCESS;
1246}
1247
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07001248/* Show route summary prefix. */
1249DEFUN (show_ip_route_summary_prefix,
1250 show_ip_route_summary_prefix_cmd,
1251 "show ip route summary prefix",
1252 SHOW_STR
1253 IP_STR
1254 "IP routing table\n"
1255 "Summary of all routes\n"
1256 "Prefix routes\n")
1257{
1258 struct route_table *table;
1259
1260 table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
1261 if (! table)
1262 return CMD_SUCCESS;
1263
1264 vty_show_ip_route_summary_prefix (vty, table);
1265
1266 return CMD_SUCCESS;
1267}
1268
paul718e3742002-12-13 20:15:29 +00001269/* Write IPv4 static route configuration. */
paula1ac18c2005-06-28 17:17:12 +00001270static int
Everton Marques96bb2662014-07-14 11:19:00 -03001271static_config_ipv4 (struct vty *vty, safi_t safi, const char *cmd)
paul718e3742002-12-13 20:15:29 +00001272{
1273 struct route_node *rn;
1274 struct static_ipv4 *si;
1275 struct route_table *stable;
1276 int write;
1277
1278 write = 0;
1279
1280 /* Lookup table. */
Everton Marques96bb2662014-07-14 11:19:00 -03001281 stable = vrf_static_table (AFI_IP, safi, 0);
paul718e3742002-12-13 20:15:29 +00001282 if (! stable)
1283 return -1;
1284
1285 for (rn = route_top (stable); rn; rn = route_next (rn))
1286 for (si = rn->info; si; si = si->next)
1287 {
Everton Marques96bb2662014-07-14 11:19:00 -03001288 vty_out (vty, "%s %s/%d", cmd, inet_ntoa (rn->p.u.prefix4),
paul7021c422003-07-15 12:52:22 +00001289 rn->p.prefixlen);
paul718e3742002-12-13 20:15:29 +00001290
paul7021c422003-07-15 12:52:22 +00001291 switch (si->type)
1292 {
1293 case STATIC_IPV4_GATEWAY:
1294 vty_out (vty, " %s", inet_ntoa (si->gate.ipv4));
1295 break;
1296 case STATIC_IPV4_IFNAME:
1297 vty_out (vty, " %s", si->gate.ifname);
1298 break;
1299 case STATIC_IPV4_BLACKHOLE:
1300 vty_out (vty, " Null0");
1301 break;
1302 }
1303
1304 /* flags are incompatible with STATIC_IPV4_BLACKHOLE */
1305 if (si->type != STATIC_IPV4_BLACKHOLE)
1306 {
1307 if (CHECK_FLAG(si->flags, ZEBRA_FLAG_REJECT))
1308 vty_out (vty, " %s", "reject");
paul718e3742002-12-13 20:15:29 +00001309
paul7021c422003-07-15 12:52:22 +00001310 if (CHECK_FLAG(si->flags, ZEBRA_FLAG_BLACKHOLE))
1311 vty_out (vty, " %s", "blackhole");
1312 }
hasso81dfcaa2003-05-25 19:21:25 +00001313
paul7021c422003-07-15 12:52:22 +00001314 if (si->distance != ZEBRA_STATIC_DISTANCE_DEFAULT)
1315 vty_out (vty, " %d", si->distance);
hasso81dfcaa2003-05-25 19:21:25 +00001316
paul7021c422003-07-15 12:52:22 +00001317 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001318
paul7021c422003-07-15 12:52:22 +00001319 write = 1;
paul718e3742002-12-13 20:15:29 +00001320 }
1321 return write;
1322}
Andrew J. Schorr09303312007-05-30 20:10:34 +00001323
1324DEFUN (show_ip_protocol,
1325 show_ip_protocol_cmd,
1326 "show ip protocol",
1327 SHOW_STR
1328 IP_STR
1329 "IP protocol filtering status\n")
1330{
1331 int i;
1332
1333 vty_out(vty, "Protocol : route-map %s", VTY_NEWLINE);
1334 vty_out(vty, "------------------------%s", VTY_NEWLINE);
1335 for (i=0;i<ZEBRA_ROUTE_MAX;i++)
1336 {
1337 if (proto_rm[AFI_IP][i])
1338 vty_out (vty, "%-10s : %-10s%s", zebra_route_string(i),
1339 proto_rm[AFI_IP][i],
1340 VTY_NEWLINE);
1341 else
1342 vty_out (vty, "%-10s : none%s", zebra_route_string(i), VTY_NEWLINE);
1343 }
1344 if (proto_rm[AFI_IP][i])
1345 vty_out (vty, "%-10s : %-10s%s", "any", proto_rm[AFI_IP][i],
1346 VTY_NEWLINE);
1347 else
1348 vty_out (vty, "%-10s : none%s", "any", VTY_NEWLINE);
1349
1350 return CMD_SUCCESS;
1351}
1352
Joachim Nilsson36735ed2012-05-09 13:38:36 +02001353/*
1354 * Show IP mroute command to dump the BGP Multicast
1355 * routing table
1356 */
1357DEFUN (show_ip_mroute,
1358 show_ip_mroute_cmd,
1359 "show ip mroute",
1360 SHOW_STR
1361 IP_STR
1362 "IP Multicast routing table\n")
1363{
1364 struct route_table *table;
1365 struct route_node *rn;
1366 struct rib *rib;
1367 int first = 1;
1368
1369 table = vrf_table (AFI_IP, SAFI_MULTICAST, 0);
1370 if (! table)
1371 return CMD_SUCCESS;
1372
1373 /* Show all IPv4 routes. */
1374 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001375 RNODE_FOREACH_RIB (rn, rib)
Joachim Nilsson36735ed2012-05-09 13:38:36 +02001376 {
1377 if (first)
1378 {
1379 vty_out (vty, SHOW_ROUTE_V4_HEADER);
1380 first = 0;
1381 }
1382 vty_show_ip_route (vty, rn, rib);
1383 }
1384 return CMD_SUCCESS;
1385}
1386
David Lamparter6b0655a2014-06-04 06:53:35 +02001387
paul718e3742002-12-13 20:15:29 +00001388#ifdef HAVE_IPV6
1389/* General fucntion for IPv6 static route. */
paula1ac18c2005-06-28 17:17:12 +00001390static int
hasso39db97e2004-10-12 20:50:58 +00001391static_ipv6_func (struct vty *vty, int add_cmd, const char *dest_str,
1392 const char *gate_str, const char *ifname,
1393 const char *flag_str, const char *distance_str)
paul718e3742002-12-13 20:15:29 +00001394{
1395 int ret;
1396 u_char distance;
1397 struct prefix p;
1398 struct in6_addr *gate = NULL;
1399 struct in6_addr gate_addr;
1400 u_char type = 0;
1401 int table = 0;
hasso81dfcaa2003-05-25 19:21:25 +00001402 u_char flag = 0;
paul718e3742002-12-13 20:15:29 +00001403
1404 ret = str2prefix (dest_str, &p);
1405 if (ret <= 0)
1406 {
1407 vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
1408 return CMD_WARNING;
1409 }
1410
1411 /* Apply mask for given prefix. */
1412 apply_mask (&p);
1413
hasso81dfcaa2003-05-25 19:21:25 +00001414 /* Route flags */
1415 if (flag_str) {
1416 switch(flag_str[0]) {
1417 case 'r':
1418 case 'R': /* XXX */
1419 SET_FLAG (flag, ZEBRA_FLAG_REJECT);
1420 break;
1421 case 'b':
1422 case 'B': /* XXX */
1423 SET_FLAG (flag, ZEBRA_FLAG_BLACKHOLE);
1424 break;
1425 default:
1426 vty_out (vty, "%% Malformed flag %s %s", flag_str, VTY_NEWLINE);
paul595db7f2003-05-25 21:35:06 +00001427 return CMD_WARNING;
hasso81dfcaa2003-05-25 19:21:25 +00001428 }
1429 }
1430
paul718e3742002-12-13 20:15:29 +00001431 /* Administrative distance. */
1432 if (distance_str)
1433 distance = atoi (distance_str);
1434 else
1435 distance = ZEBRA_STATIC_DISTANCE_DEFAULT;
1436
1437 /* When gateway is valid IPv6 addrees, then gate is treated as
1438 nexthop address other case gate is treated as interface name. */
1439 ret = inet_pton (AF_INET6, gate_str, &gate_addr);
1440
1441 if (ifname)
1442 {
1443 /* When ifname is specified. It must be come with gateway
1444 address. */
1445 if (ret != 1)
1446 {
1447 vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
1448 return CMD_WARNING;
1449 }
1450 type = STATIC_IPV6_GATEWAY_IFNAME;
1451 gate = &gate_addr;
1452 }
1453 else
1454 {
1455 if (ret == 1)
1456 {
1457 type = STATIC_IPV6_GATEWAY;
1458 gate = &gate_addr;
1459 }
1460 else
1461 {
1462 type = STATIC_IPV6_IFNAME;
1463 ifname = gate_str;
1464 }
1465 }
1466
1467 if (add_cmd)
hasso81dfcaa2003-05-25 19:21:25 +00001468 static_add_ipv6 (&p, type, gate, ifname, flag, distance, table);
paul718e3742002-12-13 20:15:29 +00001469 else
1470 static_delete_ipv6 (&p, type, gate, ifname, distance, table);
1471
1472 return CMD_SUCCESS;
1473}
1474
1475DEFUN (ipv6_route,
1476 ipv6_route_cmd,
1477 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE)",
1478 IP_STR
1479 "Establish static routes\n"
1480 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1481 "IPv6 gateway address\n"
1482 "IPv6 gateway interface name\n")
1483{
hasso81dfcaa2003-05-25 19:21:25 +00001484 return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, NULL, NULL);
1485}
1486
1487DEFUN (ipv6_route_flags,
1488 ipv6_route_flags_cmd,
1489 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole)",
1490 IP_STR
1491 "Establish static routes\n"
1492 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1493 "IPv6 gateway address\n"
1494 "IPv6 gateway interface name\n"
1495 "Emit an ICMP unreachable when matched\n"
1496 "Silently discard pkts when matched\n")
1497{
1498 return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, argv[2], NULL);
paul718e3742002-12-13 20:15:29 +00001499}
1500
1501DEFUN (ipv6_route_ifname,
1502 ipv6_route_ifname_cmd,
1503 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE",
1504 IP_STR
1505 "Establish static routes\n"
1506 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1507 "IPv6 gateway address\n"
1508 "IPv6 gateway interface name\n")
1509{
hasso81dfcaa2003-05-25 19:21:25 +00001510 return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], NULL, NULL);
1511}
1512
1513DEFUN (ipv6_route_ifname_flags,
1514 ipv6_route_ifname_flags_cmd,
1515 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole)",
1516 IP_STR
1517 "Establish static routes\n"
1518 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1519 "IPv6 gateway address\n"
1520 "IPv6 gateway interface name\n"
1521 "Emit an ICMP unreachable when matched\n"
1522 "Silently discard pkts when matched\n")
1523{
1524 return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], argv[3], NULL);
paul718e3742002-12-13 20:15:29 +00001525}
1526
1527DEFUN (ipv6_route_pref,
1528 ipv6_route_pref_cmd,
1529 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <1-255>",
1530 IP_STR
1531 "Establish static routes\n"
1532 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1533 "IPv6 gateway address\n"
1534 "IPv6 gateway interface name\n"
1535 "Distance value for this prefix\n")
1536{
hasso81dfcaa2003-05-25 19:21:25 +00001537 return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, NULL, argv[2]);
1538}
1539
1540DEFUN (ipv6_route_flags_pref,
1541 ipv6_route_flags_pref_cmd,
1542 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) <1-255>",
1543 IP_STR
1544 "Establish static routes\n"
1545 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1546 "IPv6 gateway address\n"
1547 "IPv6 gateway interface name\n"
1548 "Emit an ICMP unreachable when matched\n"
1549 "Silently discard pkts when matched\n"
1550 "Distance value for this prefix\n")
1551{
1552 return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, argv[2], argv[3]);
paul718e3742002-12-13 20:15:29 +00001553}
1554
1555DEFUN (ipv6_route_ifname_pref,
1556 ipv6_route_ifname_pref_cmd,
1557 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255>",
1558 IP_STR
1559 "Establish static routes\n"
1560 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1561 "IPv6 gateway address\n"
1562 "IPv6 gateway interface name\n"
1563 "Distance value for this prefix\n")
1564{
hasso81dfcaa2003-05-25 19:21:25 +00001565 return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], NULL, argv[3]);
1566}
1567
1568DEFUN (ipv6_route_ifname_flags_pref,
1569 ipv6_route_ifname_flags_pref_cmd,
1570 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) <1-255>",
1571 IP_STR
1572 "Establish static routes\n"
1573 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1574 "IPv6 gateway address\n"
1575 "IPv6 gateway interface name\n"
1576 "Emit an ICMP unreachable when matched\n"
1577 "Silently discard pkts when matched\n"
1578 "Distance value for this prefix\n")
1579{
1580 return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], argv[3], argv[4]);
paul718e3742002-12-13 20:15:29 +00001581}
1582
1583DEFUN (no_ipv6_route,
1584 no_ipv6_route_cmd,
1585 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE)",
1586 NO_STR
1587 IP_STR
1588 "Establish static routes\n"
1589 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1590 "IPv6 gateway address\n"
1591 "IPv6 gateway interface name\n")
1592{
hasso81dfcaa2003-05-25 19:21:25 +00001593 return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00001594}
1595
hasso81dfcaa2003-05-25 19:21:25 +00001596ALIAS (no_ipv6_route,
1597 no_ipv6_route_flags_cmd,
1598 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole)",
1599 NO_STR
1600 IP_STR
1601 "Establish static routes\n"
1602 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1603 "IPv6 gateway address\n"
1604 "IPv6 gateway interface name\n"
1605 "Emit an ICMP unreachable when matched\n"
1606 "Silently discard pkts when matched\n")
1607
paul718e3742002-12-13 20:15:29 +00001608DEFUN (no_ipv6_route_ifname,
1609 no_ipv6_route_ifname_cmd,
1610 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE",
1611 NO_STR
1612 IP_STR
1613 "Establish static routes\n"
1614 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1615 "IPv6 gateway address\n"
1616 "IPv6 gateway interface name\n")
1617{
hasso81dfcaa2003-05-25 19:21:25 +00001618 return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], NULL, NULL);
paul718e3742002-12-13 20:15:29 +00001619}
1620
hasso81dfcaa2003-05-25 19:21:25 +00001621ALIAS (no_ipv6_route_ifname,
1622 no_ipv6_route_ifname_flags_cmd,
1623 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole)",
1624 NO_STR
1625 IP_STR
1626 "Establish static routes\n"
1627 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1628 "IPv6 gateway address\n"
1629 "IPv6 gateway interface name\n"
1630 "Emit an ICMP unreachable when matched\n"
1631 "Silently discard pkts when matched\n")
1632
paul718e3742002-12-13 20:15:29 +00001633DEFUN (no_ipv6_route_pref,
1634 no_ipv6_route_pref_cmd,
1635 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <1-255>",
1636 NO_STR
1637 IP_STR
1638 "Establish static routes\n"
1639 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1640 "IPv6 gateway address\n"
1641 "IPv6 gateway interface name\n"
1642 "Distance value for this prefix\n")
1643{
hasso81dfcaa2003-05-25 19:21:25 +00001644 return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, NULL, argv[2]);
1645}
1646
1647DEFUN (no_ipv6_route_flags_pref,
1648 no_ipv6_route_flags_pref_cmd,
1649 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) <1-255>",
1650 NO_STR
1651 IP_STR
1652 "Establish static routes\n"
1653 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1654 "IPv6 gateway address\n"
1655 "IPv6 gateway interface name\n"
1656 "Emit an ICMP unreachable when matched\n"
1657 "Silently discard pkts when matched\n"
1658 "Distance value for this prefix\n")
1659{
1660 /* We do not care about argv[2] */
1661 return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, argv[2], argv[3]);
paul718e3742002-12-13 20:15:29 +00001662}
1663
1664DEFUN (no_ipv6_route_ifname_pref,
1665 no_ipv6_route_ifname_pref_cmd,
1666 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255>",
1667 NO_STR
1668 IP_STR
1669 "Establish static routes\n"
1670 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1671 "IPv6 gateway address\n"
1672 "IPv6 gateway interface name\n"
1673 "Distance value for this prefix\n")
1674{
hasso81dfcaa2003-05-25 19:21:25 +00001675 return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], NULL, argv[3]);
1676}
1677
1678DEFUN (no_ipv6_route_ifname_flags_pref,
1679 no_ipv6_route_ifname_flags_pref_cmd,
1680 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) <1-255>",
1681 NO_STR
1682 IP_STR
1683 "Establish static routes\n"
1684 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1685 "IPv6 gateway address\n"
1686 "IPv6 gateway interface name\n"
1687 "Emit an ICMP unreachable when matched\n"
1688 "Silently discard pkts when matched\n"
1689 "Distance value for this prefix\n")
1690{
1691 return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], argv[3], argv[4]);
paul718e3742002-12-13 20:15:29 +00001692}
1693
paul595db7f2003-05-25 21:35:06 +00001694/* New RIB. Detailed information for IPv6 route. */
paula1ac18c2005-06-28 17:17:12 +00001695static void
paul718e3742002-12-13 20:15:29 +00001696vty_show_ipv6_route_detail (struct vty *vty, struct route_node *rn)
1697{
1698 struct rib *rib;
Christian Frankefa713d92013-07-05 15:35:37 +00001699 struct nexthop *nexthop, *tnexthop;
1700 int recursing;
paul718e3742002-12-13 20:15:29 +00001701 char buf[BUFSIZ];
1702
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001703 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +00001704 {
1705 vty_out (vty, "Routing entry for %s/%d%s",
1706 inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, BUFSIZ),
1707 rn->p.prefixlen,
1708 VTY_NEWLINE);
ajsf52d13c2005-10-01 17:38:06 +00001709 vty_out (vty, " Known via \"%s\"", zebra_route_string (rib->type));
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02001710 vty_out (vty, ", distance %u, metric %u", rib->distance, rib->metric);
paul718e3742002-12-13 20:15:29 +00001711 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
1712 vty_out (vty, ", best");
1713 if (rib->refcnt)
1714 vty_out (vty, ", refcnt %ld", rib->refcnt);
hasso81dfcaa2003-05-25 19:21:25 +00001715 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
1716 vty_out (vty, ", blackhole");
1717 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT))
1718 vty_out (vty, ", reject");
paul718e3742002-12-13 20:15:29 +00001719 vty_out (vty, "%s", VTY_NEWLINE);
1720
1721#define ONE_DAY_SECOND 60*60*24
1722#define ONE_WEEK_SECOND 60*60*24*7
1723 if (rib->type == ZEBRA_ROUTE_RIPNG
1724 || rib->type == ZEBRA_ROUTE_OSPF6
Juliusz Chroboczek578ce372012-02-09 13:42:28 +01001725 || rib->type == ZEBRA_ROUTE_BABEL
jardin9e867fe2003-12-23 08:56:18 +00001726 || rib->type == ZEBRA_ROUTE_ISIS
paul718e3742002-12-13 20:15:29 +00001727 || rib->type == ZEBRA_ROUTE_BGP)
1728 {
1729 time_t uptime;
1730 struct tm *tm;
1731
1732 uptime = time (NULL);
1733 uptime -= rib->uptime;
1734 tm = gmtime (&uptime);
1735
1736 vty_out (vty, " Last update ");
1737
1738 if (uptime < ONE_DAY_SECOND)
1739 vty_out (vty, "%02d:%02d:%02d",
1740 tm->tm_hour, tm->tm_min, tm->tm_sec);
1741 else if (uptime < ONE_WEEK_SECOND)
1742 vty_out (vty, "%dd%02dh%02dm",
1743 tm->tm_yday, tm->tm_hour, tm->tm_min);
1744 else
1745 vty_out (vty, "%02dw%dd%02dh",
1746 tm->tm_yday/7,
1747 tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
1748 vty_out (vty, " ago%s", VTY_NEWLINE);
1749 }
1750
Christian Frankefa713d92013-07-05 15:35:37 +00001751 for (ALL_NEXTHOPS_RO(rib->nexthop, nexthop, tnexthop, recursing))
paul718e3742002-12-13 20:15:29 +00001752 {
Christian Frankefa713d92013-07-05 15:35:37 +00001753 vty_out (vty, " %c%s",
1754 CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB) ? '*' : ' ',
1755 recursing ? " " : "");
paul718e3742002-12-13 20:15:29 +00001756
1757 switch (nexthop->type)
1758 {
1759 case NEXTHOP_TYPE_IPV6:
1760 case NEXTHOP_TYPE_IPV6_IFINDEX:
1761 case NEXTHOP_TYPE_IPV6_IFNAME:
1762 vty_out (vty, " %s",
1763 inet_ntop (AF_INET6, &nexthop->gate.ipv6, buf, BUFSIZ));
1764 if (nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME)
1765 vty_out (vty, ", %s", nexthop->ifname);
1766 else if (nexthop->ifindex)
1767 vty_out (vty, ", via %s", ifindex2ifname (nexthop->ifindex));
1768 break;
1769 case NEXTHOP_TYPE_IFINDEX:
1770 vty_out (vty, " directly connected, %s",
1771 ifindex2ifname (nexthop->ifindex));
1772 break;
1773 case NEXTHOP_TYPE_IFNAME:
1774 vty_out (vty, " directly connected, %s",
1775 nexthop->ifname);
1776 break;
1777 default:
1778 break;
1779 }
1780 if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
1781 vty_out (vty, " inactive");
1782
Christian Frankee8d3d292013-07-05 15:35:39 +00001783 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ONLINK))
1784 vty_out (vty, " onlink");
1785
paul718e3742002-12-13 20:15:29 +00001786 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
Christian Frankefa713d92013-07-05 15:35:37 +00001787 vty_out (vty, " (recursive)");
1788
paul718e3742002-12-13 20:15:29 +00001789 vty_out (vty, "%s", VTY_NEWLINE);
1790 }
1791 vty_out (vty, "%s", VTY_NEWLINE);
1792 }
1793}
1794
paula1ac18c2005-06-28 17:17:12 +00001795static void
paul718e3742002-12-13 20:15:29 +00001796vty_show_ipv6_route (struct vty *vty, struct route_node *rn,
1797 struct rib *rib)
1798{
Christian Frankefa713d92013-07-05 15:35:37 +00001799 struct nexthop *nexthop, *tnexthop;
1800 int recursing;
paul718e3742002-12-13 20:15:29 +00001801 int len = 0;
1802 char buf[BUFSIZ];
1803
1804 /* Nexthop information. */
Christian Frankefa713d92013-07-05 15:35:37 +00001805 for (ALL_NEXTHOPS_RO(rib->nexthop, nexthop, tnexthop, recursing))
paul718e3742002-12-13 20:15:29 +00001806 {
1807 if (nexthop == rib->nexthop)
1808 {
1809 /* Prefix information. */
1810 len = vty_out (vty, "%c%c%c %s/%d",
ajsf52d13c2005-10-01 17:38:06 +00001811 zebra_route_char (rib->type),
paul718e3742002-12-13 20:15:29 +00001812 CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED)
1813 ? '>' : ' ',
1814 CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
1815 ? '*' : ' ',
1816 inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, BUFSIZ),
1817 rn->p.prefixlen);
1818
1819 /* Distance and metric display. */
1820 if (rib->type != ZEBRA_ROUTE_CONNECT
1821 && rib->type != ZEBRA_ROUTE_KERNEL)
1822 len += vty_out (vty, " [%d/%d]", rib->distance,
1823 rib->metric);
1824 }
1825 else
1826 vty_out (vty, " %c%*c",
1827 CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
1828 ? '*' : ' ',
Christian Frankefa713d92013-07-05 15:35:37 +00001829 len - 3 + (2 * recursing), ' ');
paul718e3742002-12-13 20:15:29 +00001830
1831 switch (nexthop->type)
1832 {
1833 case NEXTHOP_TYPE_IPV6:
1834 case NEXTHOP_TYPE_IPV6_IFINDEX:
1835 case NEXTHOP_TYPE_IPV6_IFNAME:
1836 vty_out (vty, " via %s",
1837 inet_ntop (AF_INET6, &nexthop->gate.ipv6, buf, BUFSIZ));
1838 if (nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME)
1839 vty_out (vty, ", %s", nexthop->ifname);
1840 else if (nexthop->ifindex)
1841 vty_out (vty, ", %s", ifindex2ifname (nexthop->ifindex));
1842 break;
1843 case NEXTHOP_TYPE_IFINDEX:
1844 vty_out (vty, " is directly connected, %s",
1845 ifindex2ifname (nexthop->ifindex));
1846 break;
1847 case NEXTHOP_TYPE_IFNAME:
1848 vty_out (vty, " is directly connected, %s",
1849 nexthop->ifname);
1850 break;
1851 default:
1852 break;
1853 }
1854 if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
1855 vty_out (vty, " inactive");
1856
1857 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
Christian Frankefa713d92013-07-05 15:35:37 +00001858 vty_out (vty, " (recursive)");
paul718e3742002-12-13 20:15:29 +00001859
hasso81dfcaa2003-05-25 19:21:25 +00001860 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
1861 vty_out (vty, ", bh");
1862 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT))
1863 vty_out (vty, ", rej");
1864
paul718e3742002-12-13 20:15:29 +00001865 if (rib->type == ZEBRA_ROUTE_RIPNG
1866 || rib->type == ZEBRA_ROUTE_OSPF6
Juliusz Chroboczek578ce372012-02-09 13:42:28 +01001867 || rib->type == ZEBRA_ROUTE_BABEL
jardin9e867fe2003-12-23 08:56:18 +00001868 || rib->type == ZEBRA_ROUTE_ISIS
paul718e3742002-12-13 20:15:29 +00001869 || rib->type == ZEBRA_ROUTE_BGP)
1870 {
1871 time_t uptime;
1872 struct tm *tm;
1873
1874 uptime = time (NULL);
1875 uptime -= rib->uptime;
1876 tm = gmtime (&uptime);
1877
1878#define ONE_DAY_SECOND 60*60*24
1879#define ONE_WEEK_SECOND 60*60*24*7
1880
1881 if (uptime < ONE_DAY_SECOND)
1882 vty_out (vty, ", %02d:%02d:%02d",
1883 tm->tm_hour, tm->tm_min, tm->tm_sec);
1884 else if (uptime < ONE_WEEK_SECOND)
1885 vty_out (vty, ", %dd%02dh%02dm",
1886 tm->tm_yday, tm->tm_hour, tm->tm_min);
1887 else
1888 vty_out (vty, ", %02dw%dd%02dh",
1889 tm->tm_yday/7,
1890 tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
1891 }
1892 vty_out (vty, "%s", VTY_NEWLINE);
1893 }
1894}
1895
paul718e3742002-12-13 20:15:29 +00001896DEFUN (show_ipv6_route,
1897 show_ipv6_route_cmd,
1898 "show ipv6 route",
1899 SHOW_STR
1900 IP_STR
1901 "IPv6 routing table\n")
1902{
1903 struct route_table *table;
1904 struct route_node *rn;
1905 struct rib *rib;
1906 int first = 1;
1907
1908 table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
1909 if (! table)
1910 return CMD_SUCCESS;
1911
1912 /* Show all IPv6 route. */
1913 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001914 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +00001915 {
1916 if (first)
1917 {
David Lampartere0ca5fd2009-09-16 01:52:42 +02001918 vty_out (vty, SHOW_ROUTE_V6_HEADER);
paul718e3742002-12-13 20:15:29 +00001919 first = 0;
1920 }
1921 vty_show_ipv6_route (vty, rn, rib);
1922 }
1923 return CMD_SUCCESS;
1924}
1925
1926DEFUN (show_ipv6_route_prefix_longer,
1927 show_ipv6_route_prefix_longer_cmd,
1928 "show ipv6 route X:X::X:X/M longer-prefixes",
1929 SHOW_STR
1930 IP_STR
1931 "IPv6 routing table\n"
1932 "IPv6 prefix\n"
1933 "Show route matching the specified Network/Mask pair only\n")
1934{
1935 struct route_table *table;
1936 struct route_node *rn;
1937 struct rib *rib;
1938 struct prefix p;
1939 int ret;
1940 int first = 1;
1941
1942 table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
1943 if (! table)
1944 return CMD_SUCCESS;
1945
1946 ret = str2prefix (argv[0], &p);
1947 if (! ret)
1948 {
1949 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
1950 return CMD_WARNING;
1951 }
1952
1953 /* Show matched type IPv6 routes. */
1954 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001955 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +00001956 if (prefix_match (&p, &rn->p))
1957 {
1958 if (first)
1959 {
David Lampartere0ca5fd2009-09-16 01:52:42 +02001960 vty_out (vty, SHOW_ROUTE_V6_HEADER);
paul718e3742002-12-13 20:15:29 +00001961 first = 0;
1962 }
1963 vty_show_ipv6_route (vty, rn, rib);
1964 }
1965 return CMD_SUCCESS;
1966}
1967
1968DEFUN (show_ipv6_route_protocol,
1969 show_ipv6_route_protocol_cmd,
David Lampartere0ca5fd2009-09-16 01:52:42 +02001970 "show ipv6 route " QUAGGA_IP6_REDIST_STR_ZEBRA,
paul718e3742002-12-13 20:15:29 +00001971 SHOW_STR
1972 IP_STR
1973 "IP routing table\n"
David Lampartere0ca5fd2009-09-16 01:52:42 +02001974 QUAGGA_IP6_REDIST_HELP_STR_ZEBRA)
paul718e3742002-12-13 20:15:29 +00001975{
1976 int type;
1977 struct route_table *table;
1978 struct route_node *rn;
1979 struct rib *rib;
1980 int first = 1;
1981
David Lampartere0ca5fd2009-09-16 01:52:42 +02001982 type = proto_redistnum (AFI_IP6, argv[0]);
1983 if (type < 0)
paul718e3742002-12-13 20:15:29 +00001984 {
1985 vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
1986 return CMD_WARNING;
1987 }
1988
1989 table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
1990 if (! table)
1991 return CMD_SUCCESS;
1992
1993 /* Show matched type IPv6 routes. */
1994 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001995 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +00001996 if (rib->type == type)
1997 {
1998 if (first)
1999 {
David Lampartere0ca5fd2009-09-16 01:52:42 +02002000 vty_out (vty, SHOW_ROUTE_V6_HEADER);
paul718e3742002-12-13 20:15:29 +00002001 first = 0;
2002 }
2003 vty_show_ipv6_route (vty, rn, rib);
2004 }
2005 return CMD_SUCCESS;
2006}
2007
2008DEFUN (show_ipv6_route_addr,
2009 show_ipv6_route_addr_cmd,
2010 "show ipv6 route X:X::X:X",
2011 SHOW_STR
2012 IP_STR
2013 "IPv6 routing table\n"
2014 "IPv6 Address\n")
2015{
2016 int ret;
2017 struct prefix_ipv6 p;
2018 struct route_table *table;
2019 struct route_node *rn;
2020
2021 ret = str2prefix_ipv6 (argv[0], &p);
2022 if (ret <= 0)
2023 {
2024 vty_out (vty, "Malformed IPv6 address%s", VTY_NEWLINE);
2025 return CMD_WARNING;
2026 }
2027
2028 table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
2029 if (! table)
2030 return CMD_SUCCESS;
2031
2032 rn = route_node_match (table, (struct prefix *) &p);
2033 if (! rn)
2034 {
2035 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
2036 return CMD_WARNING;
2037 }
2038
2039 vty_show_ipv6_route_detail (vty, rn);
2040
2041 route_unlock_node (rn);
2042
2043 return CMD_SUCCESS;
2044}
2045
2046DEFUN (show_ipv6_route_prefix,
2047 show_ipv6_route_prefix_cmd,
2048 "show ipv6 route X:X::X:X/M",
2049 SHOW_STR
2050 IP_STR
2051 "IPv6 routing table\n"
2052 "IPv6 prefix\n")
2053{
2054 int ret;
2055 struct prefix_ipv6 p;
2056 struct route_table *table;
2057 struct route_node *rn;
2058
2059 ret = str2prefix_ipv6 (argv[0], &p);
2060 if (ret <= 0)
2061 {
2062 vty_out (vty, "Malformed IPv6 prefix%s", VTY_NEWLINE);
2063 return CMD_WARNING;
2064 }
2065
2066 table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
2067 if (! table)
2068 return CMD_SUCCESS;
2069
2070 rn = route_node_match (table, (struct prefix *) &p);
2071 if (! rn || rn->p.prefixlen != p.prefixlen)
2072 {
2073 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
Lu Feng969d3552014-10-21 06:24:07 +00002074 if (rn)
2075 route_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00002076 return CMD_WARNING;
2077 }
2078
2079 vty_show_ipv6_route_detail (vty, rn);
2080
2081 route_unlock_node (rn);
2082
2083 return CMD_SUCCESS;
2084}
2085
Stig Thormodsrud61691c92008-11-04 15:45:07 -08002086/* Show route summary. */
2087DEFUN (show_ipv6_route_summary,
2088 show_ipv6_route_summary_cmd,
2089 "show ipv6 route summary",
2090 SHOW_STR
2091 IP_STR
2092 "IPv6 routing table\n"
2093 "Summary of all IPv6 routes\n")
2094{
2095 struct route_table *table;
2096
2097 table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
2098 if (! table)
2099 return CMD_SUCCESS;
2100
2101 vty_show_ip_route_summary (vty, table);
2102
2103 return CMD_SUCCESS;
2104}
2105
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07002106/* Show ipv6 route summary prefix. */
2107DEFUN (show_ipv6_route_summary_prefix,
2108 show_ipv6_route_summary_prefix_cmd,
2109 "show ipv6 route summary prefix",
2110 SHOW_STR
2111 IP_STR
2112 "IPv6 routing table\n"
2113 "Summary of all IPv6 routes\n"
2114 "Prefix routes\n")
2115{
2116 struct route_table *table;
2117
2118 table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
2119 if (! table)
2120 return CMD_SUCCESS;
2121
2122 vty_show_ip_route_summary_prefix (vty, table);
2123
2124 return CMD_SUCCESS;
2125}
2126
G.Balajicddf3912011-11-26 21:59:32 +04002127/*
G.Balajicddf3912011-11-26 21:59:32 +04002128 * Show IPv6 mroute command.Used to dump
2129 * the Multicast routing table.
2130 */
2131
2132DEFUN (show_ipv6_mroute,
2133 show_ipv6_mroute_cmd,
2134 "show ipv6 mroute",
2135 SHOW_STR
2136 IP_STR
2137 "IPv6 Multicast routing table\n")
2138{
2139 struct route_table *table;
2140 struct route_node *rn;
2141 struct rib *rib;
2142 int first = 1;
2143
2144 table = vrf_table (AFI_IP6, SAFI_MULTICAST, 0);
2145 if (! table)
2146 return CMD_SUCCESS;
2147
2148 /* Show all IPv6 route. */
2149 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00002150 RNODE_FOREACH_RIB (rn, rib)
G.Balajicddf3912011-11-26 21:59:32 +04002151 {
2152 if (first)
2153 {
G.Balajicb32fd62011-11-27 20:09:40 +05302154 vty_out (vty, SHOW_ROUTE_V6_HEADER);
G.Balajicddf3912011-11-26 21:59:32 +04002155 first = 0;
2156 }
2157 vty_show_ipv6_route (vty, rn, rib);
2158 }
2159 return CMD_SUCCESS;
2160}
2161
paul718e3742002-12-13 20:15:29 +00002162/* Write IPv6 static route configuration. */
paula1ac18c2005-06-28 17:17:12 +00002163static int
paul718e3742002-12-13 20:15:29 +00002164static_config_ipv6 (struct vty *vty)
2165{
2166 struct route_node *rn;
2167 struct static_ipv6 *si;
2168 int write;
2169 char buf[BUFSIZ];
2170 struct route_table *stable;
2171
2172 write = 0;
2173
2174 /* Lookup table. */
2175 stable = vrf_static_table (AFI_IP6, SAFI_UNICAST, 0);
2176 if (! stable)
2177 return -1;
2178
2179 for (rn = route_top (stable); rn; rn = route_next (rn))
2180 for (si = rn->info; si; si = si->next)
2181 {
2182 vty_out (vty, "ipv6 route %s/%d",
2183 inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, BUFSIZ),
2184 rn->p.prefixlen);
2185
2186 switch (si->type)
2187 {
2188 case STATIC_IPV6_GATEWAY:
2189 vty_out (vty, " %s", inet_ntop (AF_INET6, &si->ipv6, buf, BUFSIZ));
2190 break;
2191 case STATIC_IPV6_IFNAME:
2192 vty_out (vty, " %s", si->ifname);
2193 break;
2194 case STATIC_IPV6_GATEWAY_IFNAME:
2195 vty_out (vty, " %s %s",
2196 inet_ntop (AF_INET6, &si->ipv6, buf, BUFSIZ), si->ifname);
2197 break;
2198 }
2199
hasso81dfcaa2003-05-25 19:21:25 +00002200 if (CHECK_FLAG(si->flags, ZEBRA_FLAG_REJECT))
2201 vty_out (vty, " %s", "reject");
2202
2203 if (CHECK_FLAG(si->flags, ZEBRA_FLAG_BLACKHOLE))
2204 vty_out (vty, " %s", "blackhole");
2205
paul718e3742002-12-13 20:15:29 +00002206 if (si->distance != ZEBRA_STATIC_DISTANCE_DEFAULT)
2207 vty_out (vty, " %d", si->distance);
2208 vty_out (vty, "%s", VTY_NEWLINE);
2209
2210 write = 1;
2211 }
2212 return write;
2213}
2214#endif /* HAVE_IPV6 */
2215
2216/* Static ip route configuration write function. */
paula1ac18c2005-06-28 17:17:12 +00002217static int
paul718e3742002-12-13 20:15:29 +00002218zebra_ip_config (struct vty *vty)
2219{
2220 int write = 0;
2221
Everton Marques96bb2662014-07-14 11:19:00 -03002222 write += static_config_ipv4 (vty, SAFI_UNICAST, "ip route");
2223 write += static_config_ipv4 (vty, SAFI_MULTICAST, "ip mroute");
paul718e3742002-12-13 20:15:29 +00002224#ifdef HAVE_IPV6
2225 write += static_config_ipv6 (vty);
2226#endif /* HAVE_IPV6 */
2227
2228 return write;
2229}
2230
Paul Jakma7514fb72007-05-02 16:05:35 +00002231/* ip protocol configuration write function */
2232static int config_write_protocol(struct vty *vty)
2233{
2234 int i;
2235
2236 for (i=0;i<ZEBRA_ROUTE_MAX;i++)
2237 {
2238 if (proto_rm[AFI_IP][i])
2239 vty_out (vty, "ip protocol %s route-map %s%s", zebra_route_string(i),
2240 proto_rm[AFI_IP][i], VTY_NEWLINE);
2241 }
2242 if (proto_rm[AFI_IP][ZEBRA_ROUTE_MAX])
2243 vty_out (vty, "ip protocol %s route-map %s%s", "any",
2244 proto_rm[AFI_IP][ZEBRA_ROUTE_MAX], VTY_NEWLINE);
2245
2246 return 1;
2247}
2248
2249/* table node for protocol filtering */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -08002250static struct cmd_node protocol_node = { PROTOCOL_NODE, "", 1 };
Paul Jakma7514fb72007-05-02 16:05:35 +00002251
paul718e3742002-12-13 20:15:29 +00002252/* IP node for static routes. */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -08002253static struct cmd_node ip_node = { IP_NODE, "", 1 };
paul718e3742002-12-13 20:15:29 +00002254
2255/* Route VTY. */
2256void
paula1ac18c2005-06-28 17:17:12 +00002257zebra_vty_init (void)
paul718e3742002-12-13 20:15:29 +00002258{
2259 install_node (&ip_node, zebra_ip_config);
Paul Jakma7514fb72007-05-02 16:05:35 +00002260 install_node (&protocol_node, config_write_protocol);
paul718e3742002-12-13 20:15:29 +00002261
Everton Marques96bb2662014-07-14 11:19:00 -03002262 install_element (CONFIG_NODE, &ip_mroute_cmd);
David Lamparter9e6366d2015-01-22 19:03:53 +01002263 install_element (CONFIG_NODE, &ip_mroute_dist_cmd);
Everton Marques96bb2662014-07-14 11:19:00 -03002264 install_element (CONFIG_NODE, &no_ip_mroute_cmd);
David Lamparter9e6366d2015-01-22 19:03:53 +01002265 install_element (CONFIG_NODE, &no_ip_mroute_dist_cmd);
Paul Jakma7514fb72007-05-02 16:05:35 +00002266 install_element (CONFIG_NODE, &ip_protocol_cmd);
2267 install_element (CONFIG_NODE, &no_ip_protocol_cmd);
2268 install_element (VIEW_NODE, &show_ip_protocol_cmd);
2269 install_element (ENABLE_NODE, &show_ip_protocol_cmd);
paul718e3742002-12-13 20:15:29 +00002270 install_element (CONFIG_NODE, &ip_route_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002271 install_element (CONFIG_NODE, &ip_route_flags_cmd);
hasso457ef552003-05-28 12:02:15 +00002272 install_element (CONFIG_NODE, &ip_route_flags2_cmd);
paul718e3742002-12-13 20:15:29 +00002273 install_element (CONFIG_NODE, &ip_route_mask_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002274 install_element (CONFIG_NODE, &ip_route_mask_flags_cmd);
hasso457ef552003-05-28 12:02:15 +00002275 install_element (CONFIG_NODE, &ip_route_mask_flags2_cmd);
paul718e3742002-12-13 20:15:29 +00002276 install_element (CONFIG_NODE, &no_ip_route_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002277 install_element (CONFIG_NODE, &no_ip_route_flags_cmd);
hasso457ef552003-05-28 12:02:15 +00002278 install_element (CONFIG_NODE, &no_ip_route_flags2_cmd);
paul718e3742002-12-13 20:15:29 +00002279 install_element (CONFIG_NODE, &no_ip_route_mask_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002280 install_element (CONFIG_NODE, &no_ip_route_mask_flags_cmd);
hasso457ef552003-05-28 12:02:15 +00002281 install_element (CONFIG_NODE, &no_ip_route_mask_flags2_cmd);
paul718e3742002-12-13 20:15:29 +00002282 install_element (CONFIG_NODE, &ip_route_distance_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002283 install_element (CONFIG_NODE, &ip_route_flags_distance_cmd);
hasso457ef552003-05-28 12:02:15 +00002284 install_element (CONFIG_NODE, &ip_route_flags_distance2_cmd);
paul718e3742002-12-13 20:15:29 +00002285 install_element (CONFIG_NODE, &ip_route_mask_distance_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002286 install_element (CONFIG_NODE, &ip_route_mask_flags_distance_cmd);
hasso457ef552003-05-28 12:02:15 +00002287 install_element (CONFIG_NODE, &ip_route_mask_flags_distance2_cmd);
paul718e3742002-12-13 20:15:29 +00002288 install_element (CONFIG_NODE, &no_ip_route_distance_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002289 install_element (CONFIG_NODE, &no_ip_route_flags_distance_cmd);
hasso457ef552003-05-28 12:02:15 +00002290 install_element (CONFIG_NODE, &no_ip_route_flags_distance2_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002291 install_element (CONFIG_NODE, &no_ip_route_mask_flags_distance_cmd);
hasso457ef552003-05-28 12:02:15 +00002292 install_element (CONFIG_NODE, &no_ip_route_mask_flags_distance2_cmd);
paul718e3742002-12-13 20:15:29 +00002293
2294 install_element (VIEW_NODE, &show_ip_route_cmd);
2295 install_element (VIEW_NODE, &show_ip_route_addr_cmd);
2296 install_element (VIEW_NODE, &show_ip_route_prefix_cmd);
2297 install_element (VIEW_NODE, &show_ip_route_prefix_longer_cmd);
2298 install_element (VIEW_NODE, &show_ip_route_protocol_cmd);
2299 install_element (VIEW_NODE, &show_ip_route_supernets_cmd);
Stig Thormodsrud61691c92008-11-04 15:45:07 -08002300 install_element (VIEW_NODE, &show_ip_route_summary_cmd);
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07002301 install_element (VIEW_NODE, &show_ip_route_summary_prefix_cmd);
paul718e3742002-12-13 20:15:29 +00002302 install_element (ENABLE_NODE, &show_ip_route_cmd);
2303 install_element (ENABLE_NODE, &show_ip_route_addr_cmd);
2304 install_element (ENABLE_NODE, &show_ip_route_prefix_cmd);
2305 install_element (ENABLE_NODE, &show_ip_route_prefix_longer_cmd);
2306 install_element (ENABLE_NODE, &show_ip_route_protocol_cmd);
2307 install_element (ENABLE_NODE, &show_ip_route_supernets_cmd);
paul718e3742002-12-13 20:15:29 +00002308 install_element (ENABLE_NODE, &show_ip_route_summary_cmd);
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07002309 install_element (ENABLE_NODE, &show_ip_route_summary_prefix_cmd);
paul718e3742002-12-13 20:15:29 +00002310
G.Balajicddf3912011-11-26 21:59:32 +04002311 install_element (VIEW_NODE, &show_ip_mroute_cmd);
2312 install_element (ENABLE_NODE, &show_ip_mroute_cmd);
2313
Everton Marques96bb2662014-07-14 11:19:00 -03002314 install_element (VIEW_NODE, &show_ip_rpf_cmd);
2315 install_element (ENABLE_NODE, &show_ip_rpf_cmd);
G.Balajicddf3912011-11-26 21:59:32 +04002316
paul718e3742002-12-13 20:15:29 +00002317#ifdef HAVE_IPV6
2318 install_element (CONFIG_NODE, &ipv6_route_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002319 install_element (CONFIG_NODE, &ipv6_route_flags_cmd);
paul718e3742002-12-13 20:15:29 +00002320 install_element (CONFIG_NODE, &ipv6_route_ifname_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002321 install_element (CONFIG_NODE, &ipv6_route_ifname_flags_cmd);
paul718e3742002-12-13 20:15:29 +00002322 install_element (CONFIG_NODE, &no_ipv6_route_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002323 install_element (CONFIG_NODE, &no_ipv6_route_flags_cmd);
paul718e3742002-12-13 20:15:29 +00002324 install_element (CONFIG_NODE, &no_ipv6_route_ifname_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002325 install_element (CONFIG_NODE, &no_ipv6_route_ifname_flags_cmd);
paul718e3742002-12-13 20:15:29 +00002326 install_element (CONFIG_NODE, &ipv6_route_pref_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002327 install_element (CONFIG_NODE, &ipv6_route_flags_pref_cmd);
paul718e3742002-12-13 20:15:29 +00002328 install_element (CONFIG_NODE, &ipv6_route_ifname_pref_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002329 install_element (CONFIG_NODE, &ipv6_route_ifname_flags_pref_cmd);
paul718e3742002-12-13 20:15:29 +00002330 install_element (CONFIG_NODE, &no_ipv6_route_pref_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002331 install_element (CONFIG_NODE, &no_ipv6_route_flags_pref_cmd);
paul718e3742002-12-13 20:15:29 +00002332 install_element (CONFIG_NODE, &no_ipv6_route_ifname_pref_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002333 install_element (CONFIG_NODE, &no_ipv6_route_ifname_flags_pref_cmd);
paul718e3742002-12-13 20:15:29 +00002334 install_element (VIEW_NODE, &show_ipv6_route_cmd);
Stig Thormodsrud61691c92008-11-04 15:45:07 -08002335 install_element (VIEW_NODE, &show_ipv6_route_summary_cmd);
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07002336 install_element (VIEW_NODE, &show_ipv6_route_summary_prefix_cmd);
paul718e3742002-12-13 20:15:29 +00002337 install_element (VIEW_NODE, &show_ipv6_route_protocol_cmd);
2338 install_element (VIEW_NODE, &show_ipv6_route_addr_cmd);
2339 install_element (VIEW_NODE, &show_ipv6_route_prefix_cmd);
2340 install_element (VIEW_NODE, &show_ipv6_route_prefix_longer_cmd);
2341 install_element (ENABLE_NODE, &show_ipv6_route_cmd);
2342 install_element (ENABLE_NODE, &show_ipv6_route_protocol_cmd);
2343 install_element (ENABLE_NODE, &show_ipv6_route_addr_cmd);
2344 install_element (ENABLE_NODE, &show_ipv6_route_prefix_cmd);
2345 install_element (ENABLE_NODE, &show_ipv6_route_prefix_longer_cmd);
Stig Thormodsrud61691c92008-11-04 15:45:07 -08002346 install_element (ENABLE_NODE, &show_ipv6_route_summary_cmd);
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07002347 install_element (ENABLE_NODE, &show_ipv6_route_summary_prefix_cmd);
G.Balajicddf3912011-11-26 21:59:32 +04002348
2349 install_element (VIEW_NODE, &show_ipv6_mroute_cmd);
2350 install_element (ENABLE_NODE, &show_ipv6_mroute_cmd);
paul718e3742002-12-13 20:15:29 +00002351#endif /* HAVE_IPV6 */
2352}