blob: 6802eceb5c119438251e056c64e84c86b7456f90 [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);
34
35/* General function for static route. */
paula1ac18c2005-06-28 17:17:12 +000036static int
Everton Marques33d86db2014-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 Marques33d86db2014-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 Marques33d86db2014-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 Marques33d86db2014-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 Marques33d86db2014-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 Marques33d86db2014-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 Marques33d86db2014-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 Marques33d86db2014-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. */
145DEFUN (ip_mroute,
146 ip_mroute_cmd,
147 "ip mroute A.B.C.D/M (A.B.C.D|INTERFACE) [<1-255>]",
148 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{
155 return zebra_static_ipv4_safi(vty, SAFI_MULTICAST, 1, argv[0], NULL, argv[1], NULL, argv[2]);
156}
157
158DEFUN (no_ip_mroute,
159 no_ip_mroute_cmd,
160 "no ip mroute A.B.C.D/M (A.B.C.D|INTERFACE) [<1-255>]",
161 IP_STR
162 "Configure static unicast route into MRIB for multicast RPF lookup\n"
163 "IP destination prefix (e.g. 10.0.0.0/8)\n"
164 "Nexthop address\n"
165 "Nexthop interface name\n"
166 "Distance\n")
167{
168 return zebra_static_ipv4_safi(vty, SAFI_MULTICAST, 0, argv[0], NULL, argv[1], NULL, argv[2]);
169}
170
171DEFUN (show_ip_rpf,
172 show_ip_rpf_cmd,
173 "show ip rpf",
174 SHOW_STR
175 IP_STR
176 "Display RPF information for multicast source\n")
177{
178 return do_show_ip_route(vty, SAFI_MULTICAST);
179}
180
paul718e3742002-12-13 20:15:29 +0000181/* Static route configuration. */
182DEFUN (ip_route,
183 ip_route_cmd,
paul595db7f2003-05-25 21:35:06 +0000184 "ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0)",
hasso81dfcaa2003-05-25 19:21:25 +0000185 IP_STR
186 "Establish static routes\n"
187 "IP destination prefix (e.g. 10.0.0.0/8)\n"
188 "IP gateway address\n"
paul595db7f2003-05-25 21:35:06 +0000189 "IP gateway interface name\n"
190 "Null interface\n")
hasso81dfcaa2003-05-25 19:21:25 +0000191{
192 return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], NULL, NULL);
193}
194
195DEFUN (ip_route_flags,
196 ip_route_flags_cmd,
197 "ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole)",
paul718e3742002-12-13 20:15:29 +0000198 IP_STR
199 "Establish static routes\n"
200 "IP destination prefix (e.g. 10.0.0.0/8)\n"
201 "IP gateway address\n"
202 "IP gateway interface name\n"
hasso81dfcaa2003-05-25 19:21:25 +0000203 "Emit an ICMP unreachable when matched\n"
204 "Silently discard pkts when matched\n")
paul718e3742002-12-13 20:15:29 +0000205{
hasso81dfcaa2003-05-25 19:21:25 +0000206 return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], argv[2], NULL);
paul718e3742002-12-13 20:15:29 +0000207}
208
hasso457ef552003-05-28 12:02:15 +0000209DEFUN (ip_route_flags2,
210 ip_route_flags2_cmd,
211 "ip route A.B.C.D/M (reject|blackhole)",
212 IP_STR
213 "Establish static routes\n"
214 "IP destination prefix (e.g. 10.0.0.0/8)\n"
215 "Emit an ICMP unreachable when matched\n"
216 "Silently discard pkts when matched\n")
217{
218 return zebra_static_ipv4 (vty, 1, argv[0], NULL, NULL, argv[1], NULL);
219}
220
paul718e3742002-12-13 20:15:29 +0000221/* Mask as A.B.C.D format. */
222DEFUN (ip_route_mask,
223 ip_route_mask_cmd,
paul595db7f2003-05-25 21:35:06 +0000224 "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0)",
hasso81dfcaa2003-05-25 19:21:25 +0000225 IP_STR
226 "Establish static routes\n"
227 "IP destination prefix\n"
228 "IP destination prefix mask\n"
229 "IP gateway address\n"
paul595db7f2003-05-25 21:35:06 +0000230 "IP gateway interface name\n"
231 "Null interface\n")
hasso81dfcaa2003-05-25 19:21:25 +0000232{
233 return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], NULL, NULL);
234}
235
236DEFUN (ip_route_mask_flags,
237 ip_route_mask_flags_cmd,
238 "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole)",
paul718e3742002-12-13 20:15:29 +0000239 IP_STR
240 "Establish static routes\n"
241 "IP destination prefix\n"
242 "IP destination prefix mask\n"
243 "IP gateway address\n"
244 "IP gateway interface name\n"
hasso81dfcaa2003-05-25 19:21:25 +0000245 "Emit an ICMP unreachable when matched\n"
246 "Silently discard pkts when matched\n")
paul718e3742002-12-13 20:15:29 +0000247{
hasso81dfcaa2003-05-25 19:21:25 +0000248 return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], argv[3], NULL);
paul718e3742002-12-13 20:15:29 +0000249}
250
hasso457ef552003-05-28 12:02:15 +0000251DEFUN (ip_route_mask_flags2,
252 ip_route_mask_flags2_cmd,
253 "ip route A.B.C.D A.B.C.D (reject|blackhole)",
254 IP_STR
255 "Establish static routes\n"
256 "IP destination prefix\n"
257 "IP destination prefix mask\n"
258 "Emit an ICMP unreachable when matched\n"
259 "Silently discard pkts when matched\n")
260{
261 return zebra_static_ipv4 (vty, 1, argv[0], argv[1], NULL, argv[2], NULL);
262}
263
paul718e3742002-12-13 20:15:29 +0000264/* Distance option value. */
265DEFUN (ip_route_distance,
266 ip_route_distance_cmd,
paul595db7f2003-05-25 21:35:06 +0000267 "ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0) <1-255>",
paul718e3742002-12-13 20:15:29 +0000268 IP_STR
269 "Establish static routes\n"
270 "IP destination prefix (e.g. 10.0.0.0/8)\n"
271 "IP gateway address\n"
272 "IP gateway interface name\n"
paul595db7f2003-05-25 21:35:06 +0000273 "Null interface\n"
paul718e3742002-12-13 20:15:29 +0000274 "Distance value for this route\n")
275{
hasso81dfcaa2003-05-25 19:21:25 +0000276 return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], NULL, argv[2]);
277}
278
279DEFUN (ip_route_flags_distance,
280 ip_route_flags_distance_cmd,
281 "ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
282 IP_STR
283 "Establish static routes\n"
284 "IP destination prefix (e.g. 10.0.0.0/8)\n"
285 "IP gateway address\n"
286 "IP gateway interface name\n"
287 "Emit an ICMP unreachable when matched\n"
288 "Silently discard pkts when matched\n"
289 "Distance value for this route\n")
290{
291 return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], argv[2], argv[3]);
paul718e3742002-12-13 20:15:29 +0000292}
293
hasso457ef552003-05-28 12:02:15 +0000294DEFUN (ip_route_flags_distance2,
295 ip_route_flags_distance2_cmd,
296 "ip route A.B.C.D/M (reject|blackhole) <1-255>",
297 IP_STR
298 "Establish static routes\n"
299 "IP destination prefix (e.g. 10.0.0.0/8)\n"
300 "Emit an ICMP unreachable when matched\n"
301 "Silently discard pkts when matched\n"
302 "Distance value for this route\n")
303{
304 return zebra_static_ipv4 (vty, 1, argv[0], NULL, NULL, argv[1], argv[2]);
305}
306
paul718e3742002-12-13 20:15:29 +0000307DEFUN (ip_route_mask_distance,
308 ip_route_mask_distance_cmd,
paul595db7f2003-05-25 21:35:06 +0000309 "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0) <1-255>",
paul718e3742002-12-13 20:15:29 +0000310 IP_STR
311 "Establish static routes\n"
312 "IP destination prefix\n"
313 "IP destination prefix mask\n"
314 "IP gateway address\n"
315 "IP gateway interface name\n"
paul595db7f2003-05-25 21:35:06 +0000316 "Null interface\n"
paul718e3742002-12-13 20:15:29 +0000317 "Distance value for this route\n")
318{
hasso81dfcaa2003-05-25 19:21:25 +0000319 return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], NULL, argv[3]);
320}
321
322DEFUN (ip_route_mask_flags_distance,
323 ip_route_mask_flags_distance_cmd,
324 "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
325 IP_STR
326 "Establish static routes\n"
327 "IP destination prefix\n"
328 "IP destination prefix mask\n"
329 "IP gateway address\n"
330 "IP gateway interface name\n"
hasso81dfcaa2003-05-25 19:21:25 +0000331 "Emit an ICMP unreachable when matched\n"
Christian Franke2b005152013-09-30 12:27:49 +0000332 "Silently discard pkts when matched\n"
333 "Distance value for this route\n")
hasso81dfcaa2003-05-25 19:21:25 +0000334{
335 return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], argv[3], argv[4]);
paul718e3742002-12-13 20:15:29 +0000336}
337
hasso457ef552003-05-28 12:02:15 +0000338DEFUN (ip_route_mask_flags_distance2,
339 ip_route_mask_flags_distance2_cmd,
340 "ip route A.B.C.D A.B.C.D (reject|blackhole) <1-255>",
341 IP_STR
342 "Establish static routes\n"
343 "IP destination prefix\n"
344 "IP destination prefix mask\n"
hasso457ef552003-05-28 12:02:15 +0000345 "Emit an ICMP unreachable when matched\n"
Christian Franke2b005152013-09-30 12:27:49 +0000346 "Silently discard pkts when matched\n"
347 "Distance value for this route\n")
hasso457ef552003-05-28 12:02:15 +0000348{
349 return zebra_static_ipv4 (vty, 1, argv[0], argv[1], NULL, argv[2], argv[3]);
350}
351
paul718e3742002-12-13 20:15:29 +0000352DEFUN (no_ip_route,
353 no_ip_route_cmd,
paul595db7f2003-05-25 21:35:06 +0000354 "no ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0)",
hasso81dfcaa2003-05-25 19:21:25 +0000355 NO_STR
356 IP_STR
357 "Establish static routes\n"
358 "IP destination prefix (e.g. 10.0.0.0/8)\n"
359 "IP gateway address\n"
paul595db7f2003-05-25 21:35:06 +0000360 "IP gateway interface name\n"
361 "Null interface\n")
hasso81dfcaa2003-05-25 19:21:25 +0000362{
363 return zebra_static_ipv4 (vty, 0, argv[0], NULL, argv[1], NULL, NULL);
364}
365
366ALIAS (no_ip_route,
367 no_ip_route_flags_cmd,
368 "no ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole)",
paul718e3742002-12-13 20:15:29 +0000369 NO_STR
370 IP_STR
371 "Establish static routes\n"
372 "IP destination prefix (e.g. 10.0.0.0/8)\n"
373 "IP gateway address\n"
374 "IP gateway interface name\n"
hasso81dfcaa2003-05-25 19:21:25 +0000375 "Emit an ICMP unreachable when matched\n"
376 "Silently discard pkts when matched\n")
paul718e3742002-12-13 20:15:29 +0000377
hasso457ef552003-05-28 12:02:15 +0000378DEFUN (no_ip_route_flags2,
379 no_ip_route_flags2_cmd,
380 "no ip route A.B.C.D/M (reject|blackhole)",
381 NO_STR
382 IP_STR
383 "Establish static routes\n"
384 "IP destination prefix (e.g. 10.0.0.0/8)\n"
385 "Emit an ICMP unreachable when matched\n"
386 "Silently discard pkts when matched\n")
387{
388 return zebra_static_ipv4 (vty, 0, argv[0], NULL, NULL, NULL, NULL);
389}
390
paul718e3742002-12-13 20:15:29 +0000391DEFUN (no_ip_route_mask,
392 no_ip_route_mask_cmd,
paul595db7f2003-05-25 21:35:06 +0000393 "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0)",
hasso81dfcaa2003-05-25 19:21:25 +0000394 NO_STR
395 IP_STR
396 "Establish static routes\n"
397 "IP destination prefix\n"
398 "IP destination prefix mask\n"
399 "IP gateway address\n"
paul595db7f2003-05-25 21:35:06 +0000400 "IP gateway interface name\n"
401 "Null interface\n")
hasso81dfcaa2003-05-25 19:21:25 +0000402{
403 return zebra_static_ipv4 (vty, 0, argv[0], argv[1], argv[2], NULL, NULL);
404}
405
406ALIAS (no_ip_route_mask,
407 no_ip_route_mask_flags_cmd,
408 "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole)",
paul718e3742002-12-13 20:15:29 +0000409 NO_STR
410 IP_STR
411 "Establish static routes\n"
412 "IP destination prefix\n"
413 "IP destination prefix mask\n"
414 "IP gateway address\n"
415 "IP gateway interface name\n"
hasso81dfcaa2003-05-25 19:21:25 +0000416 "Emit an ICMP unreachable when matched\n"
417 "Silently discard pkts when matched\n")
paul718e3742002-12-13 20:15:29 +0000418
hasso457ef552003-05-28 12:02:15 +0000419DEFUN (no_ip_route_mask_flags2,
420 no_ip_route_mask_flags2_cmd,
421 "no ip route A.B.C.D A.B.C.D (reject|blackhole)",
422 NO_STR
423 IP_STR
424 "Establish static routes\n"
425 "IP destination prefix\n"
426 "IP destination prefix mask\n"
427 "Emit an ICMP unreachable when matched\n"
428 "Silently discard pkts when matched\n")
429{
430 return zebra_static_ipv4 (vty, 0, argv[0], argv[1], NULL, NULL, NULL);
431}
432
paul718e3742002-12-13 20:15:29 +0000433DEFUN (no_ip_route_distance,
434 no_ip_route_distance_cmd,
paul595db7f2003-05-25 21:35:06 +0000435 "no ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0) <1-255>",
paul718e3742002-12-13 20:15:29 +0000436 NO_STR
437 IP_STR
438 "Establish static routes\n"
439 "IP destination prefix (e.g. 10.0.0.0/8)\n"
440 "IP gateway address\n"
441 "IP gateway interface name\n"
paul595db7f2003-05-25 21:35:06 +0000442 "Null interface\n"
paul718e3742002-12-13 20:15:29 +0000443 "Distance value for this route\n")
444{
hasso81dfcaa2003-05-25 19:21:25 +0000445 return zebra_static_ipv4 (vty, 0, argv[0], NULL, argv[1], NULL, argv[2]);
446}
447
448DEFUN (no_ip_route_flags_distance,
449 no_ip_route_flags_distance_cmd,
450 "no ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
451 NO_STR
452 IP_STR
453 "Establish static routes\n"
454 "IP destination prefix (e.g. 10.0.0.0/8)\n"
455 "IP gateway address\n"
456 "IP gateway interface name\n"
457 "Emit an ICMP unreachable when matched\n"
458 "Silently discard pkts when matched\n"
459 "Distance value for this route\n")
460{
461 return zebra_static_ipv4 (vty, 0, argv[0], NULL, argv[1], argv[2], argv[3]);
paul718e3742002-12-13 20:15:29 +0000462}
463
hasso457ef552003-05-28 12:02:15 +0000464DEFUN (no_ip_route_flags_distance2,
465 no_ip_route_flags_distance2_cmd,
466 "no ip route A.B.C.D/M (reject|blackhole) <1-255>",
467 NO_STR
468 IP_STR
469 "Establish static routes\n"
470 "IP destination prefix (e.g. 10.0.0.0/8)\n"
471 "Emit an ICMP unreachable when matched\n"
472 "Silently discard pkts when matched\n"
473 "Distance value for this route\n")
474{
475 return zebra_static_ipv4 (vty, 0, argv[0], NULL, NULL, argv[1], argv[2]);
476}
477
paul718e3742002-12-13 20:15:29 +0000478DEFUN (no_ip_route_mask_distance,
479 no_ip_route_mask_distance_cmd,
paul595db7f2003-05-25 21:35:06 +0000480 "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 +0000481 NO_STR
482 IP_STR
483 "Establish static routes\n"
484 "IP destination prefix\n"
485 "IP destination prefix mask\n"
486 "IP gateway address\n"
487 "IP gateway interface name\n"
paul595db7f2003-05-25 21:35:06 +0000488 "Null interface\n"
paul718e3742002-12-13 20:15:29 +0000489 "Distance value for this route\n")
490{
hasso81dfcaa2003-05-25 19:21:25 +0000491 return zebra_static_ipv4 (vty, 0, argv[0], argv[1], argv[2], NULL, argv[3]);
492}
493
494DEFUN (no_ip_route_mask_flags_distance,
495 no_ip_route_mask_flags_distance_cmd,
496 "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
497 NO_STR
498 IP_STR
499 "Establish static routes\n"
500 "IP destination prefix\n"
501 "IP destination prefix mask\n"
502 "IP gateway address\n"
503 "IP gateway interface name\n"
504 "Emit an ICMP unreachable when matched\n"
505 "Silently discard pkts when matched\n"
506 "Distance value for this route\n")
507{
508 return zebra_static_ipv4 (vty, 0, argv[0], argv[1], argv[2], argv[3], argv[4]);
paul718e3742002-12-13 20:15:29 +0000509}
510
hasso457ef552003-05-28 12:02:15 +0000511DEFUN (no_ip_route_mask_flags_distance2,
512 no_ip_route_mask_flags_distance2_cmd,
513 "no ip route A.B.C.D A.B.C.D (reject|blackhole) <1-255>",
514 NO_STR
515 IP_STR
516 "Establish static routes\n"
517 "IP destination prefix\n"
518 "IP destination prefix mask\n"
519 "Emit an ICMP unreachable when matched\n"
520 "Silently discard pkts when matched\n"
521 "Distance value for this route\n")
522{
523 return zebra_static_ipv4 (vty, 0, argv[0], argv[1], NULL, argv[2], argv[3]);
524}
525
Paul Jakma7514fb72007-05-02 16:05:35 +0000526char *proto_rm[AFI_MAX][ZEBRA_ROUTE_MAX+1]; /* "any" == ZEBRA_ROUTE_MAX */
527
528DEFUN (ip_protocol,
529 ip_protocol_cmd,
530 "ip protocol PROTO route-map ROUTE-MAP",
531 NO_STR
532 "Apply route map to PROTO\n"
533 "Protocol name\n"
534 "Route map name\n")
535{
536 int i;
537
538 if (strcasecmp(argv[0], "any") == 0)
539 i = ZEBRA_ROUTE_MAX;
540 else
541 i = proto_name2num(argv[0]);
542 if (i < 0)
543 {
544 vty_out (vty, "invalid protocol name \"%s\"%s", argv[0] ? argv[0] : "",
545 VTY_NEWLINE);
546 return CMD_WARNING;
547 }
548 if (proto_rm[AFI_IP][i])
549 XFREE (MTYPE_ROUTE_MAP_NAME, proto_rm[AFI_IP][i]);
550 proto_rm[AFI_IP][i] = XSTRDUP (MTYPE_ROUTE_MAP_NAME, argv[1]);
551 return CMD_SUCCESS;
552}
553
554DEFUN (no_ip_protocol,
555 no_ip_protocol_cmd,
556 "no ip protocol PROTO",
557 NO_STR
558 "Remove route map from PROTO\n"
559 "Protocol name\n")
560{
561 int i;
562
563 if (strcasecmp(argv[0], "any") == 0)
564 i = ZEBRA_ROUTE_MAX;
565 else
566 i = proto_name2num(argv[0]);
567 if (i < 0)
568 {
569 vty_out (vty, "invalid protocol name \"%s\"%s", argv[0] ? argv[0] : "",
570 VTY_NEWLINE);
571 return CMD_WARNING;
572 }
573 if (proto_rm[AFI_IP][i])
574 XFREE (MTYPE_ROUTE_MAP_NAME, proto_rm[AFI_IP][i]);
575 proto_rm[AFI_IP][i] = NULL;
576 return CMD_SUCCESS;
577}
578
paul718e3742002-12-13 20:15:29 +0000579/* New RIB. Detailed information for IPv4 route. */
paula1ac18c2005-06-28 17:17:12 +0000580static void
paul718e3742002-12-13 20:15:29 +0000581vty_show_ip_route_detail (struct vty *vty, struct route_node *rn)
582{
583 struct rib *rib;
Christian Frankefa713d92013-07-05 15:35:37 +0000584 struct nexthop *nexthop, *tnexthop;
585 int recursing;
paul718e3742002-12-13 20:15:29 +0000586
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000587 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +0000588 {
589 vty_out (vty, "Routing entry for %s/%d%s",
590 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
591 VTY_NEWLINE);
ajsf52d13c2005-10-01 17:38:06 +0000592 vty_out (vty, " Known via \"%s\"", zebra_route_string (rib->type));
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +0200593 vty_out (vty, ", distance %u, metric %u", rib->distance, rib->metric);
paul718e3742002-12-13 20:15:29 +0000594 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
595 vty_out (vty, ", best");
596 if (rib->refcnt)
597 vty_out (vty, ", refcnt %ld", rib->refcnt);
hasso81dfcaa2003-05-25 19:21:25 +0000598 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
599 vty_out (vty, ", blackhole");
600 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT))
601 vty_out (vty, ", reject");
paul718e3742002-12-13 20:15:29 +0000602 vty_out (vty, "%s", VTY_NEWLINE);
603
604#define ONE_DAY_SECOND 60*60*24
605#define ONE_WEEK_SECOND 60*60*24*7
606 if (rib->type == ZEBRA_ROUTE_RIP
607 || rib->type == ZEBRA_ROUTE_OSPF
Juliusz Chroboczek578ce372012-02-09 13:42:28 +0100608 || rib->type == ZEBRA_ROUTE_BABEL
jardin9e867fe2003-12-23 08:56:18 +0000609 || rib->type == ZEBRA_ROUTE_ISIS
paul718e3742002-12-13 20:15:29 +0000610 || rib->type == ZEBRA_ROUTE_BGP)
611 {
612 time_t uptime;
613 struct tm *tm;
614
615 uptime = time (NULL);
616 uptime -= rib->uptime;
617 tm = gmtime (&uptime);
618
619 vty_out (vty, " Last update ");
620
621 if (uptime < ONE_DAY_SECOND)
622 vty_out (vty, "%02d:%02d:%02d",
623 tm->tm_hour, tm->tm_min, tm->tm_sec);
624 else if (uptime < ONE_WEEK_SECOND)
625 vty_out (vty, "%dd%02dh%02dm",
626 tm->tm_yday, tm->tm_hour, tm->tm_min);
627 else
628 vty_out (vty, "%02dw%dd%02dh",
629 tm->tm_yday/7,
630 tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
631 vty_out (vty, " ago%s", VTY_NEWLINE);
632 }
633
Christian Frankefa713d92013-07-05 15:35:37 +0000634 for (ALL_NEXTHOPS_RO(rib->nexthop, nexthop, tnexthop, recursing))
paul718e3742002-12-13 20:15:29 +0000635 {
Paul Jakma7514fb72007-05-02 16:05:35 +0000636 char addrstr[32];
637
Christian Frankefa713d92013-07-05 15:35:37 +0000638 vty_out (vty, " %c%s",
639 CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB) ? '*' : ' ',
640 recursing ? " " : "");
paul718e3742002-12-13 20:15:29 +0000641
642 switch (nexthop->type)
643 {
644 case NEXTHOP_TYPE_IPV4:
645 case NEXTHOP_TYPE_IPV4_IFINDEX:
646 vty_out (vty, " %s", inet_ntoa (nexthop->gate.ipv4));
647 if (nexthop->ifindex)
648 vty_out (vty, ", via %s", ifindex2ifname (nexthop->ifindex));
649 break;
650 case NEXTHOP_TYPE_IFINDEX:
651 vty_out (vty, " directly connected, %s",
652 ifindex2ifname (nexthop->ifindex));
653 break;
654 case NEXTHOP_TYPE_IFNAME:
655 vty_out (vty, " directly connected, %s", nexthop->ifname);
656 break;
paul595db7f2003-05-25 21:35:06 +0000657 case NEXTHOP_TYPE_BLACKHOLE:
paul7021c422003-07-15 12:52:22 +0000658 vty_out (vty, " directly connected, Null0");
paul595db7f2003-05-25 21:35:06 +0000659 break;
paul7021c422003-07-15 12:52:22 +0000660 default:
paul718e3742002-12-13 20:15:29 +0000661 break;
662 }
663 if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
664 vty_out (vty, " inactive");
665
Christian Frankee8d3d292013-07-05 15:35:39 +0000666 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ONLINK))
667 vty_out (vty, " onlink");
668
paul718e3742002-12-13 20:15:29 +0000669 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
Christian Frankefa713d92013-07-05 15:35:37 +0000670 vty_out (vty, " (recursive)");
Christian Franke5b9f5182013-05-25 14:01:34 +0000671
Paul Jakma7514fb72007-05-02 16:05:35 +0000672 switch (nexthop->type)
673 {
674 case NEXTHOP_TYPE_IPV4:
675 case NEXTHOP_TYPE_IPV4_IFINDEX:
676 case NEXTHOP_TYPE_IPV4_IFNAME:
677 if (nexthop->src.ipv4.s_addr)
678 {
679 if (inet_ntop(AF_INET, &nexthop->src.ipv4, addrstr,
680 sizeof addrstr))
681 vty_out (vty, ", src %s", addrstr);
682 }
683 break;
Andrew J. Schorr09303312007-05-30 20:10:34 +0000684#ifdef HAVE_IPV6
Paul Jakma7514fb72007-05-02 16:05:35 +0000685 case NEXTHOP_TYPE_IPV6:
686 case NEXTHOP_TYPE_IPV6_IFINDEX:
687 case NEXTHOP_TYPE_IPV6_IFNAME:
688 if (!IPV6_ADDR_SAME(&nexthop->src.ipv6, &in6addr_any))
689 {
690 if (inet_ntop(AF_INET6, &nexthop->src.ipv6, addrstr,
691 sizeof addrstr))
692 vty_out (vty, ", src %s", addrstr);
693 }
694 break;
Andrew J. Schorr09303312007-05-30 20:10:34 +0000695#endif /* HAVE_IPV6 */
Paul Jakma7514fb72007-05-02 16:05:35 +0000696 default:
697 break;
698 }
paul718e3742002-12-13 20:15:29 +0000699 vty_out (vty, "%s", VTY_NEWLINE);
700 }
701 vty_out (vty, "%s", VTY_NEWLINE);
702 }
703}
704
paula1ac18c2005-06-28 17:17:12 +0000705static void
paul718e3742002-12-13 20:15:29 +0000706vty_show_ip_route (struct vty *vty, struct route_node *rn, struct rib *rib)
707{
Christian Frankefa713d92013-07-05 15:35:37 +0000708 struct nexthop *nexthop, *tnexthop;
709 int recursing;
paul718e3742002-12-13 20:15:29 +0000710 int len = 0;
711 char buf[BUFSIZ];
712
713 /* Nexthop information. */
Christian Frankefa713d92013-07-05 15:35:37 +0000714 for (ALL_NEXTHOPS_RO(rib->nexthop, nexthop, tnexthop, recursing))
paul718e3742002-12-13 20:15:29 +0000715 {
716 if (nexthop == rib->nexthop)
717 {
718 /* Prefix information. */
719 len = vty_out (vty, "%c%c%c %s/%d",
ajsf52d13c2005-10-01 17:38:06 +0000720 zebra_route_char (rib->type),
paul718e3742002-12-13 20:15:29 +0000721 CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED)
722 ? '>' : ' ',
723 CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
724 ? '*' : ' ',
725 inet_ntop (AF_INET, &rn->p.u.prefix, buf, BUFSIZ),
726 rn->p.prefixlen);
727
728 /* Distance and metric display. */
729 if (rib->type != ZEBRA_ROUTE_CONNECT
730 && rib->type != ZEBRA_ROUTE_KERNEL)
731 len += vty_out (vty, " [%d/%d]", rib->distance,
732 rib->metric);
733 }
734 else
735 vty_out (vty, " %c%*c",
736 CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
737 ? '*' : ' ',
Christian Frankefa713d92013-07-05 15:35:37 +0000738 len - 3 + (2 * recursing), ' ');
paul718e3742002-12-13 20:15:29 +0000739
740 switch (nexthop->type)
741 {
742 case NEXTHOP_TYPE_IPV4:
743 case NEXTHOP_TYPE_IPV4_IFINDEX:
744 vty_out (vty, " via %s", inet_ntoa (nexthop->gate.ipv4));
745 if (nexthop->ifindex)
746 vty_out (vty, ", %s", ifindex2ifname (nexthop->ifindex));
747 break;
748 case NEXTHOP_TYPE_IFINDEX:
749 vty_out (vty, " is directly connected, %s",
750 ifindex2ifname (nexthop->ifindex));
751 break;
752 case NEXTHOP_TYPE_IFNAME:
753 vty_out (vty, " is directly connected, %s", nexthop->ifname);
754 break;
paul595db7f2003-05-25 21:35:06 +0000755 case NEXTHOP_TYPE_BLACKHOLE:
paul7021c422003-07-15 12:52:22 +0000756 vty_out (vty, " is directly connected, Null0");
paul595db7f2003-05-25 21:35:06 +0000757 break;
paul7021c422003-07-15 12:52:22 +0000758 default:
paul718e3742002-12-13 20:15:29 +0000759 break;
760 }
761 if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
762 vty_out (vty, " inactive");
763
Christian Frankee8d3d292013-07-05 15:35:39 +0000764 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ONLINK))
765 vty_out (vty, " onlink");
766
paul718e3742002-12-13 20:15:29 +0000767 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
Christian Frankefa713d92013-07-05 15:35:37 +0000768 vty_out (vty, " (recursive)");
769
Paul Jakma7514fb72007-05-02 16:05:35 +0000770 switch (nexthop->type)
771 {
772 case NEXTHOP_TYPE_IPV4:
773 case NEXTHOP_TYPE_IPV4_IFINDEX:
774 case NEXTHOP_TYPE_IPV4_IFNAME:
775 if (nexthop->src.ipv4.s_addr)
776 {
777 if (inet_ntop(AF_INET, &nexthop->src.ipv4, buf, sizeof buf))
778 vty_out (vty, ", src %s", buf);
779 }
780 break;
Andrew J. Schorr09303312007-05-30 20:10:34 +0000781#ifdef HAVE_IPV6
Paul Jakma7514fb72007-05-02 16:05:35 +0000782 case NEXTHOP_TYPE_IPV6:
783 case NEXTHOP_TYPE_IPV6_IFINDEX:
784 case NEXTHOP_TYPE_IPV6_IFNAME:
785 if (!IPV6_ADDR_SAME(&nexthop->src.ipv6, &in6addr_any))
786 {
787 if (inet_ntop(AF_INET6, &nexthop->src.ipv6, buf, sizeof buf))
788 vty_out (vty, ", src %s", buf);
789 }
790 break;
Andrew J. Schorr09303312007-05-30 20:10:34 +0000791#endif /* HAVE_IPV6 */
Paul Jakma7514fb72007-05-02 16:05:35 +0000792 default:
793 break;
794 }
paul718e3742002-12-13 20:15:29 +0000795
hasso81dfcaa2003-05-25 19:21:25 +0000796 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
797 vty_out (vty, ", bh");
798 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT))
799 vty_out (vty, ", rej");
800
paul718e3742002-12-13 20:15:29 +0000801 if (rib->type == ZEBRA_ROUTE_RIP
802 || rib->type == ZEBRA_ROUTE_OSPF
Juliusz Chroboczek578ce372012-02-09 13:42:28 +0100803 || rib->type == ZEBRA_ROUTE_BABEL
jardin9e867fe2003-12-23 08:56:18 +0000804 || rib->type == ZEBRA_ROUTE_ISIS
paul718e3742002-12-13 20:15:29 +0000805 || rib->type == ZEBRA_ROUTE_BGP)
806 {
807 time_t uptime;
808 struct tm *tm;
809
810 uptime = time (NULL);
811 uptime -= rib->uptime;
812 tm = gmtime (&uptime);
813
814#define ONE_DAY_SECOND 60*60*24
815#define ONE_WEEK_SECOND 60*60*24*7
816
817 if (uptime < ONE_DAY_SECOND)
818 vty_out (vty, ", %02d:%02d:%02d",
819 tm->tm_hour, tm->tm_min, tm->tm_sec);
820 else if (uptime < ONE_WEEK_SECOND)
821 vty_out (vty, ", %dd%02dh%02dm",
822 tm->tm_yday, tm->tm_hour, tm->tm_min);
823 else
824 vty_out (vty, ", %02dw%dd%02dh",
825 tm->tm_yday/7,
826 tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
827 }
828 vty_out (vty, "%s", VTY_NEWLINE);
829 }
830}
831
paul718e3742002-12-13 20:15:29 +0000832DEFUN (show_ip_route,
833 show_ip_route_cmd,
834 "show ip route",
835 SHOW_STR
836 IP_STR
837 "IP routing table\n")
838{
Everton Marques33d86db2014-07-14 11:19:00 -0300839 return do_show_ip_route(vty, SAFI_UNICAST);
840}
841
842static int do_show_ip_route(struct vty *vty, safi_t safi) {
paul718e3742002-12-13 20:15:29 +0000843 struct route_table *table;
844 struct route_node *rn;
845 struct rib *rib;
846 int first = 1;
847
Everton Marques33d86db2014-07-14 11:19:00 -0300848 table = vrf_table (AFI_IP, safi, 0);
paul718e3742002-12-13 20:15:29 +0000849 if (! table)
850 return CMD_SUCCESS;
851
852 /* Show all IPv4 routes. */
853 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000854 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +0000855 {
856 if (first)
857 {
David Lampartere0ca5fd2009-09-16 01:52:42 +0200858 vty_out (vty, SHOW_ROUTE_V4_HEADER);
paul718e3742002-12-13 20:15:29 +0000859 first = 0;
860 }
861 vty_show_ip_route (vty, rn, rib);
862 }
863 return CMD_SUCCESS;
864}
865
866DEFUN (show_ip_route_prefix_longer,
867 show_ip_route_prefix_longer_cmd,
868 "show ip route A.B.C.D/M longer-prefixes",
869 SHOW_STR
870 IP_STR
871 "IP routing table\n"
872 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
873 "Show route matching the specified Network/Mask pair only\n")
874{
875 struct route_table *table;
876 struct route_node *rn;
877 struct rib *rib;
878 struct prefix p;
879 int ret;
880 int first = 1;
881
882 ret = str2prefix (argv[0], &p);
883 if (! ret)
884 {
885 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
886 return CMD_WARNING;
887 }
888
889 table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
890 if (! table)
891 return CMD_SUCCESS;
892
893 /* Show matched type IPv4 routes. */
894 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000895 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +0000896 if (prefix_match (&p, &rn->p))
897 {
898 if (first)
899 {
David Lampartere0ca5fd2009-09-16 01:52:42 +0200900 vty_out (vty, SHOW_ROUTE_V4_HEADER);
paul718e3742002-12-13 20:15:29 +0000901 first = 0;
902 }
903 vty_show_ip_route (vty, rn, rib);
904 }
905 return CMD_SUCCESS;
906}
907
908DEFUN (show_ip_route_supernets,
909 show_ip_route_supernets_cmd,
910 "show ip route supernets-only",
911 SHOW_STR
912 IP_STR
913 "IP routing table\n"
914 "Show supernet entries only\n")
915{
916 struct route_table *table;
917 struct route_node *rn;
918 struct rib *rib;
919 u_int32_t addr;
920 int first = 1;
921
922 table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
923 if (! table)
924 return CMD_SUCCESS;
925
926 /* Show matched type IPv4 routes. */
927 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000928 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +0000929 {
930 addr = ntohl (rn->p.u.prefix4.s_addr);
931
932 if ((IN_CLASSC (addr) && rn->p.prefixlen < 24)
933 || (IN_CLASSB (addr) && rn->p.prefixlen < 16)
934 || (IN_CLASSA (addr) && rn->p.prefixlen < 8))
935 {
936 if (first)
937 {
David Lampartere0ca5fd2009-09-16 01:52:42 +0200938 vty_out (vty, SHOW_ROUTE_V4_HEADER);
paul718e3742002-12-13 20:15:29 +0000939 first = 0;
940 }
941 vty_show_ip_route (vty, rn, rib);
942 }
943 }
944 return CMD_SUCCESS;
945}
946
947DEFUN (show_ip_route_protocol,
948 show_ip_route_protocol_cmd,
David Lampartere0ca5fd2009-09-16 01:52:42 +0200949 "show ip route " QUAGGA_IP_REDIST_STR_ZEBRA,
paul718e3742002-12-13 20:15:29 +0000950 SHOW_STR
951 IP_STR
952 "IP routing table\n"
David Lampartere0ca5fd2009-09-16 01:52:42 +0200953 QUAGGA_IP_REDIST_HELP_STR_ZEBRA)
paul718e3742002-12-13 20:15:29 +0000954{
955 int type;
956 struct route_table *table;
957 struct route_node *rn;
958 struct rib *rib;
959 int first = 1;
960
David Lampartere0ca5fd2009-09-16 01:52:42 +0200961 type = proto_redistnum (AFI_IP, argv[0]);
962 if (type < 0)
paul718e3742002-12-13 20:15:29 +0000963 {
964 vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
965 return CMD_WARNING;
966 }
967
968 table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
969 if (! table)
970 return CMD_SUCCESS;
971
972 /* Show matched type IPv4 routes. */
973 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000974 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +0000975 if (rib->type == type)
976 {
977 if (first)
978 {
David Lampartere0ca5fd2009-09-16 01:52:42 +0200979 vty_out (vty, SHOW_ROUTE_V4_HEADER);
paul718e3742002-12-13 20:15:29 +0000980 first = 0;
981 }
982 vty_show_ip_route (vty, rn, rib);
983 }
984 return CMD_SUCCESS;
985}
986
987DEFUN (show_ip_route_addr,
988 show_ip_route_addr_cmd,
989 "show ip route A.B.C.D",
990 SHOW_STR
991 IP_STR
992 "IP routing table\n"
993 "Network in the IP routing table to display\n")
994{
995 int ret;
996 struct prefix_ipv4 p;
997 struct route_table *table;
998 struct route_node *rn;
999
1000 ret = str2prefix_ipv4 (argv[0], &p);
1001 if (ret <= 0)
1002 {
1003 vty_out (vty, "%% Malformed IPv4 address%s", VTY_NEWLINE);
1004 return CMD_WARNING;
1005 }
1006
1007 table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
1008 if (! table)
1009 return CMD_SUCCESS;
1010
1011 rn = route_node_match (table, (struct prefix *) &p);
1012 if (! rn)
1013 {
1014 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
1015 return CMD_WARNING;
1016 }
1017
1018 vty_show_ip_route_detail (vty, rn);
1019
1020 route_unlock_node (rn);
1021
1022 return CMD_SUCCESS;
1023}
1024
1025DEFUN (show_ip_route_prefix,
1026 show_ip_route_prefix_cmd,
1027 "show ip route A.B.C.D/M",
1028 SHOW_STR
1029 IP_STR
1030 "IP routing table\n"
1031 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
1032{
1033 int ret;
1034 struct prefix_ipv4 p;
1035 struct route_table *table;
1036 struct route_node *rn;
1037
1038 ret = str2prefix_ipv4 (argv[0], &p);
1039 if (ret <= 0)
1040 {
1041 vty_out (vty, "%% Malformed IPv4 address%s", VTY_NEWLINE);
1042 return CMD_WARNING;
1043 }
1044
1045 table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
1046 if (! table)
1047 return CMD_SUCCESS;
1048
1049 rn = route_node_match (table, (struct prefix *) &p);
1050 if (! rn || rn->p.prefixlen != p.prefixlen)
1051 {
1052 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
Lu Feng969d3552014-10-21 06:24:07 +00001053 if (rn)
1054 route_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00001055 return CMD_WARNING;
1056 }
1057
1058 vty_show_ip_route_detail (vty, rn);
1059
1060 route_unlock_node (rn);
1061
1062 return CMD_SUCCESS;
1063}
1064
paula1ac18c2005-06-28 17:17:12 +00001065static void
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001066vty_show_ip_route_summary (struct vty *vty, struct route_table *table)
paul718e3742002-12-13 20:15:29 +00001067{
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001068 struct route_node *rn;
1069 struct rib *rib;
1070 struct nexthop *nexthop;
1071#define ZEBRA_ROUTE_IBGP ZEBRA_ROUTE_MAX
1072#define ZEBRA_ROUTE_TOTAL (ZEBRA_ROUTE_IBGP + 1)
1073 u_int32_t rib_cnt[ZEBRA_ROUTE_TOTAL + 1];
1074 u_int32_t fib_cnt[ZEBRA_ROUTE_TOTAL + 1];
1075 u_int32_t i;
paul718e3742002-12-13 20:15:29 +00001076
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001077 memset (&rib_cnt, 0, sizeof(rib_cnt));
1078 memset (&fib_cnt, 0, sizeof(fib_cnt));
1079 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001080 RNODE_FOREACH_RIB (rn, rib)
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001081 for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
1082 {
1083 rib_cnt[ZEBRA_ROUTE_TOTAL]++;
1084 rib_cnt[rib->type]++;
Christian Frankefa713d92013-07-05 15:35:37 +00001085 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
1086 || nexthop_has_fib_child(nexthop))
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001087 {
1088 fib_cnt[ZEBRA_ROUTE_TOTAL]++;
1089 fib_cnt[rib->type]++;
1090 }
1091 if (rib->type == ZEBRA_ROUTE_BGP &&
1092 CHECK_FLAG (rib->flags, ZEBRA_FLAG_IBGP))
1093 {
1094 rib_cnt[ZEBRA_ROUTE_IBGP]++;
Christian Frankefa713d92013-07-05 15:35:37 +00001095 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
1096 || nexthop_has_fib_child(nexthop))
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001097 fib_cnt[ZEBRA_ROUTE_IBGP]++;
1098 }
1099 }
paul718e3742002-12-13 20:15:29 +00001100
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001101 vty_out (vty, "%-20s %-20s %-20s %s",
1102 "Route Source", "Routes", "FIB", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001103
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001104 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
1105 {
1106 if (rib_cnt[i] > 0)
1107 {
1108 if (i == ZEBRA_ROUTE_BGP)
1109 {
1110 vty_out (vty, "%-20s %-20d %-20d %s", "ebgp",
1111 rib_cnt[ZEBRA_ROUTE_BGP] - rib_cnt[ZEBRA_ROUTE_IBGP],
1112 fib_cnt[ZEBRA_ROUTE_BGP] - fib_cnt[ZEBRA_ROUTE_IBGP],
1113 VTY_NEWLINE);
1114 vty_out (vty, "%-20s %-20d %-20d %s", "ibgp",
1115 rib_cnt[ZEBRA_ROUTE_IBGP], fib_cnt[ZEBRA_ROUTE_IBGP],
1116 VTY_NEWLINE);
1117 }
1118 else
1119 vty_out (vty, "%-20s %-20d %-20d %s", zebra_route_string(i),
1120 rib_cnt[i], fib_cnt[i], VTY_NEWLINE);
1121 }
1122 }
paul718e3742002-12-13 20:15:29 +00001123
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001124 vty_out (vty, "------%s", VTY_NEWLINE);
1125 vty_out (vty, "%-20s %-20d %-20d %s", "Totals", rib_cnt[ZEBRA_ROUTE_TOTAL],
1126 fib_cnt[ZEBRA_ROUTE_TOTAL], VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001127}
1128
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07001129/*
1130 * Implementation of the ip route summary prefix command.
1131 *
1132 * This command prints the primary prefixes that have been installed by various
1133 * protocols on the box.
1134 *
1135 */
1136static void
1137vty_show_ip_route_summary_prefix (struct vty *vty, struct route_table *table)
1138{
1139 struct route_node *rn;
1140 struct rib *rib;
1141 struct nexthop *nexthop;
1142#define ZEBRA_ROUTE_IBGP ZEBRA_ROUTE_MAX
1143#define ZEBRA_ROUTE_TOTAL (ZEBRA_ROUTE_IBGP + 1)
1144 u_int32_t rib_cnt[ZEBRA_ROUTE_TOTAL + 1];
1145 u_int32_t fib_cnt[ZEBRA_ROUTE_TOTAL + 1];
1146 u_int32_t i;
1147 int cnt;
1148
1149 memset (&rib_cnt, 0, sizeof(rib_cnt));
1150 memset (&fib_cnt, 0, sizeof(fib_cnt));
1151 for (rn = route_top (table); rn; rn = route_next (rn))
1152 RNODE_FOREACH_RIB (rn, rib)
1153 {
1154
1155 /*
1156 * In case of ECMP, count only once.
1157 */
1158 cnt = 0;
1159 for (nexthop = rib->nexthop; (!cnt && nexthop); nexthop = nexthop->next)
1160 {
1161 cnt++;
1162 rib_cnt[ZEBRA_ROUTE_TOTAL]++;
1163 rib_cnt[rib->type]++;
1164 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB))
1165 {
1166 fib_cnt[ZEBRA_ROUTE_TOTAL]++;
1167 fib_cnt[rib->type]++;
1168 }
1169 if (rib->type == ZEBRA_ROUTE_BGP &&
1170 CHECK_FLAG (rib->flags, ZEBRA_FLAG_IBGP))
1171 {
1172 rib_cnt[ZEBRA_ROUTE_IBGP]++;
1173 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB))
1174 fib_cnt[ZEBRA_ROUTE_IBGP]++;
1175 }
1176 }
1177 }
1178
1179 vty_out (vty, "%-20s %-20s %-20s %s",
1180 "Route Source", "Prefix Routes", "FIB", VTY_NEWLINE);
1181
1182 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
1183 {
1184 if (rib_cnt[i] > 0)
1185 {
1186 if (i == ZEBRA_ROUTE_BGP)
1187 {
1188 vty_out (vty, "%-20s %-20d %-20d %s", "ebgp",
1189 rib_cnt[ZEBRA_ROUTE_BGP] - rib_cnt[ZEBRA_ROUTE_IBGP],
1190 fib_cnt[ZEBRA_ROUTE_BGP] - fib_cnt[ZEBRA_ROUTE_IBGP],
1191 VTY_NEWLINE);
1192 vty_out (vty, "%-20s %-20d %-20d %s", "ibgp",
1193 rib_cnt[ZEBRA_ROUTE_IBGP], fib_cnt[ZEBRA_ROUTE_IBGP],
1194 VTY_NEWLINE);
1195 }
1196 else
1197 vty_out (vty, "%-20s %-20d %-20d %s", zebra_route_string(i),
1198 rib_cnt[i], fib_cnt[i], VTY_NEWLINE);
1199 }
1200 }
1201
1202 vty_out (vty, "------%s", VTY_NEWLINE);
1203 vty_out (vty, "%-20s %-20d %-20d %s", "Totals", rib_cnt[ZEBRA_ROUTE_TOTAL],
1204 fib_cnt[ZEBRA_ROUTE_TOTAL], VTY_NEWLINE);
1205}
1206
paul718e3742002-12-13 20:15:29 +00001207/* Show route summary. */
1208DEFUN (show_ip_route_summary,
1209 show_ip_route_summary_cmd,
1210 "show ip route summary",
1211 SHOW_STR
1212 IP_STR
1213 "IP routing table\n"
1214 "Summary of all routes\n")
1215{
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001216 struct route_table *table;
paul718e3742002-12-13 20:15:29 +00001217
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001218 table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
1219 if (! table)
1220 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001221
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001222 vty_show_ip_route_summary (vty, table);
paul718e3742002-12-13 20:15:29 +00001223
1224 return CMD_SUCCESS;
1225}
1226
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07001227/* Show route summary prefix. */
1228DEFUN (show_ip_route_summary_prefix,
1229 show_ip_route_summary_prefix_cmd,
1230 "show ip route summary prefix",
1231 SHOW_STR
1232 IP_STR
1233 "IP routing table\n"
1234 "Summary of all routes\n"
1235 "Prefix routes\n")
1236{
1237 struct route_table *table;
1238
1239 table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
1240 if (! table)
1241 return CMD_SUCCESS;
1242
1243 vty_show_ip_route_summary_prefix (vty, table);
1244
1245 return CMD_SUCCESS;
1246}
1247
paul718e3742002-12-13 20:15:29 +00001248/* Write IPv4 static route configuration. */
paula1ac18c2005-06-28 17:17:12 +00001249static int
Everton Marques33d86db2014-07-14 11:19:00 -03001250static_config_ipv4 (struct vty *vty, safi_t safi, const char *cmd)
paul718e3742002-12-13 20:15:29 +00001251{
1252 struct route_node *rn;
1253 struct static_ipv4 *si;
1254 struct route_table *stable;
1255 int write;
1256
1257 write = 0;
1258
1259 /* Lookup table. */
Everton Marques33d86db2014-07-14 11:19:00 -03001260 stable = vrf_static_table (AFI_IP, safi, 0);
paul718e3742002-12-13 20:15:29 +00001261 if (! stable)
1262 return -1;
1263
1264 for (rn = route_top (stable); rn; rn = route_next (rn))
1265 for (si = rn->info; si; si = si->next)
1266 {
Everton Marques33d86db2014-07-14 11:19:00 -03001267 vty_out (vty, "%s %s/%d", cmd, inet_ntoa (rn->p.u.prefix4),
paul7021c422003-07-15 12:52:22 +00001268 rn->p.prefixlen);
paul718e3742002-12-13 20:15:29 +00001269
paul7021c422003-07-15 12:52:22 +00001270 switch (si->type)
1271 {
1272 case STATIC_IPV4_GATEWAY:
1273 vty_out (vty, " %s", inet_ntoa (si->gate.ipv4));
1274 break;
1275 case STATIC_IPV4_IFNAME:
1276 vty_out (vty, " %s", si->gate.ifname);
1277 break;
1278 case STATIC_IPV4_BLACKHOLE:
1279 vty_out (vty, " Null0");
1280 break;
1281 }
1282
1283 /* flags are incompatible with STATIC_IPV4_BLACKHOLE */
1284 if (si->type != STATIC_IPV4_BLACKHOLE)
1285 {
1286 if (CHECK_FLAG(si->flags, ZEBRA_FLAG_REJECT))
1287 vty_out (vty, " %s", "reject");
paul718e3742002-12-13 20:15:29 +00001288
paul7021c422003-07-15 12:52:22 +00001289 if (CHECK_FLAG(si->flags, ZEBRA_FLAG_BLACKHOLE))
1290 vty_out (vty, " %s", "blackhole");
1291 }
hasso81dfcaa2003-05-25 19:21:25 +00001292
paul7021c422003-07-15 12:52:22 +00001293 if (si->distance != ZEBRA_STATIC_DISTANCE_DEFAULT)
1294 vty_out (vty, " %d", si->distance);
hasso81dfcaa2003-05-25 19:21:25 +00001295
paul7021c422003-07-15 12:52:22 +00001296 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001297
paul7021c422003-07-15 12:52:22 +00001298 write = 1;
paul718e3742002-12-13 20:15:29 +00001299 }
1300 return write;
1301}
Andrew J. Schorr09303312007-05-30 20:10:34 +00001302
1303DEFUN (show_ip_protocol,
1304 show_ip_protocol_cmd,
1305 "show ip protocol",
1306 SHOW_STR
1307 IP_STR
1308 "IP protocol filtering status\n")
1309{
1310 int i;
1311
1312 vty_out(vty, "Protocol : route-map %s", VTY_NEWLINE);
1313 vty_out(vty, "------------------------%s", VTY_NEWLINE);
1314 for (i=0;i<ZEBRA_ROUTE_MAX;i++)
1315 {
1316 if (proto_rm[AFI_IP][i])
1317 vty_out (vty, "%-10s : %-10s%s", zebra_route_string(i),
1318 proto_rm[AFI_IP][i],
1319 VTY_NEWLINE);
1320 else
1321 vty_out (vty, "%-10s : none%s", zebra_route_string(i), VTY_NEWLINE);
1322 }
1323 if (proto_rm[AFI_IP][i])
1324 vty_out (vty, "%-10s : %-10s%s", "any", proto_rm[AFI_IP][i],
1325 VTY_NEWLINE);
1326 else
1327 vty_out (vty, "%-10s : none%s", "any", VTY_NEWLINE);
1328
1329 return CMD_SUCCESS;
1330}
1331
Joachim Nilsson36735ed2012-05-09 13:38:36 +02001332/*
1333 * Show IP mroute command to dump the BGP Multicast
1334 * routing table
1335 */
1336DEFUN (show_ip_mroute,
1337 show_ip_mroute_cmd,
1338 "show ip mroute",
1339 SHOW_STR
1340 IP_STR
1341 "IP Multicast routing table\n")
1342{
1343 struct route_table *table;
1344 struct route_node *rn;
1345 struct rib *rib;
1346 int first = 1;
1347
1348 table = vrf_table (AFI_IP, SAFI_MULTICAST, 0);
1349 if (! table)
1350 return CMD_SUCCESS;
1351
1352 /* Show all IPv4 routes. */
1353 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001354 RNODE_FOREACH_RIB (rn, rib)
Joachim Nilsson36735ed2012-05-09 13:38:36 +02001355 {
1356 if (first)
1357 {
1358 vty_out (vty, SHOW_ROUTE_V4_HEADER);
1359 first = 0;
1360 }
1361 vty_show_ip_route (vty, rn, rib);
1362 }
1363 return CMD_SUCCESS;
1364}
1365
David Lamparter6b0655a2014-06-04 06:53:35 +02001366
paul718e3742002-12-13 20:15:29 +00001367#ifdef HAVE_IPV6
1368/* General fucntion for IPv6 static route. */
paula1ac18c2005-06-28 17:17:12 +00001369static int
hasso39db97e2004-10-12 20:50:58 +00001370static_ipv6_func (struct vty *vty, int add_cmd, const char *dest_str,
1371 const char *gate_str, const char *ifname,
1372 const char *flag_str, const char *distance_str)
paul718e3742002-12-13 20:15:29 +00001373{
1374 int ret;
1375 u_char distance;
1376 struct prefix p;
1377 struct in6_addr *gate = NULL;
1378 struct in6_addr gate_addr;
1379 u_char type = 0;
1380 int table = 0;
hasso81dfcaa2003-05-25 19:21:25 +00001381 u_char flag = 0;
paul718e3742002-12-13 20:15:29 +00001382
1383 ret = str2prefix (dest_str, &p);
1384 if (ret <= 0)
1385 {
1386 vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
1387 return CMD_WARNING;
1388 }
1389
1390 /* Apply mask for given prefix. */
1391 apply_mask (&p);
1392
hasso81dfcaa2003-05-25 19:21:25 +00001393 /* Route flags */
1394 if (flag_str) {
1395 switch(flag_str[0]) {
1396 case 'r':
1397 case 'R': /* XXX */
1398 SET_FLAG (flag, ZEBRA_FLAG_REJECT);
1399 break;
1400 case 'b':
1401 case 'B': /* XXX */
1402 SET_FLAG (flag, ZEBRA_FLAG_BLACKHOLE);
1403 break;
1404 default:
1405 vty_out (vty, "%% Malformed flag %s %s", flag_str, VTY_NEWLINE);
paul595db7f2003-05-25 21:35:06 +00001406 return CMD_WARNING;
hasso81dfcaa2003-05-25 19:21:25 +00001407 }
1408 }
1409
paul718e3742002-12-13 20:15:29 +00001410 /* Administrative distance. */
1411 if (distance_str)
1412 distance = atoi (distance_str);
1413 else
1414 distance = ZEBRA_STATIC_DISTANCE_DEFAULT;
1415
1416 /* When gateway is valid IPv6 addrees, then gate is treated as
1417 nexthop address other case gate is treated as interface name. */
1418 ret = inet_pton (AF_INET6, gate_str, &gate_addr);
1419
1420 if (ifname)
1421 {
1422 /* When ifname is specified. It must be come with gateway
1423 address. */
1424 if (ret != 1)
1425 {
1426 vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
1427 return CMD_WARNING;
1428 }
1429 type = STATIC_IPV6_GATEWAY_IFNAME;
1430 gate = &gate_addr;
1431 }
1432 else
1433 {
1434 if (ret == 1)
1435 {
1436 type = STATIC_IPV6_GATEWAY;
1437 gate = &gate_addr;
1438 }
1439 else
1440 {
1441 type = STATIC_IPV6_IFNAME;
1442 ifname = gate_str;
1443 }
1444 }
1445
1446 if (add_cmd)
hasso81dfcaa2003-05-25 19:21:25 +00001447 static_add_ipv6 (&p, type, gate, ifname, flag, distance, table);
paul718e3742002-12-13 20:15:29 +00001448 else
1449 static_delete_ipv6 (&p, type, gate, ifname, distance, table);
1450
1451 return CMD_SUCCESS;
1452}
1453
1454DEFUN (ipv6_route,
1455 ipv6_route_cmd,
1456 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE)",
1457 IP_STR
1458 "Establish static routes\n"
1459 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1460 "IPv6 gateway address\n"
1461 "IPv6 gateway interface name\n")
1462{
hasso81dfcaa2003-05-25 19:21:25 +00001463 return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, NULL, NULL);
1464}
1465
1466DEFUN (ipv6_route_flags,
1467 ipv6_route_flags_cmd,
1468 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole)",
1469 IP_STR
1470 "Establish static routes\n"
1471 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1472 "IPv6 gateway address\n"
1473 "IPv6 gateway interface name\n"
1474 "Emit an ICMP unreachable when matched\n"
1475 "Silently discard pkts when matched\n")
1476{
1477 return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, argv[2], NULL);
paul718e3742002-12-13 20:15:29 +00001478}
1479
1480DEFUN (ipv6_route_ifname,
1481 ipv6_route_ifname_cmd,
1482 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE",
1483 IP_STR
1484 "Establish static routes\n"
1485 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1486 "IPv6 gateway address\n"
1487 "IPv6 gateway interface name\n")
1488{
hasso81dfcaa2003-05-25 19:21:25 +00001489 return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], NULL, NULL);
1490}
1491
1492DEFUN (ipv6_route_ifname_flags,
1493 ipv6_route_ifname_flags_cmd,
1494 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole)",
1495 IP_STR
1496 "Establish static routes\n"
1497 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1498 "IPv6 gateway address\n"
1499 "IPv6 gateway interface name\n"
1500 "Emit an ICMP unreachable when matched\n"
1501 "Silently discard pkts when matched\n")
1502{
1503 return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], argv[3], NULL);
paul718e3742002-12-13 20:15:29 +00001504}
1505
1506DEFUN (ipv6_route_pref,
1507 ipv6_route_pref_cmd,
1508 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <1-255>",
1509 IP_STR
1510 "Establish static routes\n"
1511 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1512 "IPv6 gateway address\n"
1513 "IPv6 gateway interface name\n"
1514 "Distance value for this prefix\n")
1515{
hasso81dfcaa2003-05-25 19:21:25 +00001516 return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, NULL, argv[2]);
1517}
1518
1519DEFUN (ipv6_route_flags_pref,
1520 ipv6_route_flags_pref_cmd,
1521 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) <1-255>",
1522 IP_STR
1523 "Establish static routes\n"
1524 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1525 "IPv6 gateway address\n"
1526 "IPv6 gateway interface name\n"
1527 "Emit an ICMP unreachable when matched\n"
1528 "Silently discard pkts when matched\n"
1529 "Distance value for this prefix\n")
1530{
1531 return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, argv[2], argv[3]);
paul718e3742002-12-13 20:15:29 +00001532}
1533
1534DEFUN (ipv6_route_ifname_pref,
1535 ipv6_route_ifname_pref_cmd,
1536 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255>",
1537 IP_STR
1538 "Establish static routes\n"
1539 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1540 "IPv6 gateway address\n"
1541 "IPv6 gateway interface name\n"
1542 "Distance value for this prefix\n")
1543{
hasso81dfcaa2003-05-25 19:21:25 +00001544 return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], NULL, argv[3]);
1545}
1546
1547DEFUN (ipv6_route_ifname_flags_pref,
1548 ipv6_route_ifname_flags_pref_cmd,
1549 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) <1-255>",
1550 IP_STR
1551 "Establish static routes\n"
1552 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1553 "IPv6 gateway address\n"
1554 "IPv6 gateway interface name\n"
1555 "Emit an ICMP unreachable when matched\n"
1556 "Silently discard pkts when matched\n"
1557 "Distance value for this prefix\n")
1558{
1559 return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], argv[3], argv[4]);
paul718e3742002-12-13 20:15:29 +00001560}
1561
1562DEFUN (no_ipv6_route,
1563 no_ipv6_route_cmd,
1564 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE)",
1565 NO_STR
1566 IP_STR
1567 "Establish static routes\n"
1568 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1569 "IPv6 gateway address\n"
1570 "IPv6 gateway interface name\n")
1571{
hasso81dfcaa2003-05-25 19:21:25 +00001572 return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00001573}
1574
hasso81dfcaa2003-05-25 19:21:25 +00001575ALIAS (no_ipv6_route,
1576 no_ipv6_route_flags_cmd,
1577 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole)",
1578 NO_STR
1579 IP_STR
1580 "Establish static routes\n"
1581 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1582 "IPv6 gateway address\n"
1583 "IPv6 gateway interface name\n"
1584 "Emit an ICMP unreachable when matched\n"
1585 "Silently discard pkts when matched\n")
1586
paul718e3742002-12-13 20:15:29 +00001587DEFUN (no_ipv6_route_ifname,
1588 no_ipv6_route_ifname_cmd,
1589 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE",
1590 NO_STR
1591 IP_STR
1592 "Establish static routes\n"
1593 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1594 "IPv6 gateway address\n"
1595 "IPv6 gateway interface name\n")
1596{
hasso81dfcaa2003-05-25 19:21:25 +00001597 return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], NULL, NULL);
paul718e3742002-12-13 20:15:29 +00001598}
1599
hasso81dfcaa2003-05-25 19:21:25 +00001600ALIAS (no_ipv6_route_ifname,
1601 no_ipv6_route_ifname_flags_cmd,
1602 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole)",
1603 NO_STR
1604 IP_STR
1605 "Establish static routes\n"
1606 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1607 "IPv6 gateway address\n"
1608 "IPv6 gateway interface name\n"
1609 "Emit an ICMP unreachable when matched\n"
1610 "Silently discard pkts when matched\n")
1611
paul718e3742002-12-13 20:15:29 +00001612DEFUN (no_ipv6_route_pref,
1613 no_ipv6_route_pref_cmd,
1614 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <1-255>",
1615 NO_STR
1616 IP_STR
1617 "Establish static routes\n"
1618 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1619 "IPv6 gateway address\n"
1620 "IPv6 gateway interface name\n"
1621 "Distance value for this prefix\n")
1622{
hasso81dfcaa2003-05-25 19:21:25 +00001623 return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, NULL, argv[2]);
1624}
1625
1626DEFUN (no_ipv6_route_flags_pref,
1627 no_ipv6_route_flags_pref_cmd,
1628 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) <1-255>",
1629 NO_STR
1630 IP_STR
1631 "Establish static routes\n"
1632 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1633 "IPv6 gateway address\n"
1634 "IPv6 gateway interface name\n"
1635 "Emit an ICMP unreachable when matched\n"
1636 "Silently discard pkts when matched\n"
1637 "Distance value for this prefix\n")
1638{
1639 /* We do not care about argv[2] */
1640 return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, argv[2], argv[3]);
paul718e3742002-12-13 20:15:29 +00001641}
1642
1643DEFUN (no_ipv6_route_ifname_pref,
1644 no_ipv6_route_ifname_pref_cmd,
1645 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255>",
1646 NO_STR
1647 IP_STR
1648 "Establish static routes\n"
1649 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1650 "IPv6 gateway address\n"
1651 "IPv6 gateway interface name\n"
1652 "Distance value for this prefix\n")
1653{
hasso81dfcaa2003-05-25 19:21:25 +00001654 return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], NULL, argv[3]);
1655}
1656
1657DEFUN (no_ipv6_route_ifname_flags_pref,
1658 no_ipv6_route_ifname_flags_pref_cmd,
1659 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) <1-255>",
1660 NO_STR
1661 IP_STR
1662 "Establish static routes\n"
1663 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1664 "IPv6 gateway address\n"
1665 "IPv6 gateway interface name\n"
1666 "Emit an ICMP unreachable when matched\n"
1667 "Silently discard pkts when matched\n"
1668 "Distance value for this prefix\n")
1669{
1670 return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], argv[3], argv[4]);
paul718e3742002-12-13 20:15:29 +00001671}
1672
paul595db7f2003-05-25 21:35:06 +00001673/* New RIB. Detailed information for IPv6 route. */
paula1ac18c2005-06-28 17:17:12 +00001674static void
paul718e3742002-12-13 20:15:29 +00001675vty_show_ipv6_route_detail (struct vty *vty, struct route_node *rn)
1676{
1677 struct rib *rib;
Christian Frankefa713d92013-07-05 15:35:37 +00001678 struct nexthop *nexthop, *tnexthop;
1679 int recursing;
paul718e3742002-12-13 20:15:29 +00001680 char buf[BUFSIZ];
1681
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001682 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +00001683 {
1684 vty_out (vty, "Routing entry for %s/%d%s",
1685 inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, BUFSIZ),
1686 rn->p.prefixlen,
1687 VTY_NEWLINE);
ajsf52d13c2005-10-01 17:38:06 +00001688 vty_out (vty, " Known via \"%s\"", zebra_route_string (rib->type));
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02001689 vty_out (vty, ", distance %u, metric %u", rib->distance, rib->metric);
paul718e3742002-12-13 20:15:29 +00001690 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
1691 vty_out (vty, ", best");
1692 if (rib->refcnt)
1693 vty_out (vty, ", refcnt %ld", rib->refcnt);
hasso81dfcaa2003-05-25 19:21:25 +00001694 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
1695 vty_out (vty, ", blackhole");
1696 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT))
1697 vty_out (vty, ", reject");
paul718e3742002-12-13 20:15:29 +00001698 vty_out (vty, "%s", VTY_NEWLINE);
1699
1700#define ONE_DAY_SECOND 60*60*24
1701#define ONE_WEEK_SECOND 60*60*24*7
1702 if (rib->type == ZEBRA_ROUTE_RIPNG
1703 || rib->type == ZEBRA_ROUTE_OSPF6
Juliusz Chroboczek578ce372012-02-09 13:42:28 +01001704 || rib->type == ZEBRA_ROUTE_BABEL
jardin9e867fe2003-12-23 08:56:18 +00001705 || rib->type == ZEBRA_ROUTE_ISIS
paul718e3742002-12-13 20:15:29 +00001706 || rib->type == ZEBRA_ROUTE_BGP)
1707 {
1708 time_t uptime;
1709 struct tm *tm;
1710
1711 uptime = time (NULL);
1712 uptime -= rib->uptime;
1713 tm = gmtime (&uptime);
1714
1715 vty_out (vty, " Last update ");
1716
1717 if (uptime < ONE_DAY_SECOND)
1718 vty_out (vty, "%02d:%02d:%02d",
1719 tm->tm_hour, tm->tm_min, tm->tm_sec);
1720 else if (uptime < ONE_WEEK_SECOND)
1721 vty_out (vty, "%dd%02dh%02dm",
1722 tm->tm_yday, tm->tm_hour, tm->tm_min);
1723 else
1724 vty_out (vty, "%02dw%dd%02dh",
1725 tm->tm_yday/7,
1726 tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
1727 vty_out (vty, " ago%s", VTY_NEWLINE);
1728 }
1729
Christian Frankefa713d92013-07-05 15:35:37 +00001730 for (ALL_NEXTHOPS_RO(rib->nexthop, nexthop, tnexthop, recursing))
paul718e3742002-12-13 20:15:29 +00001731 {
Christian Frankefa713d92013-07-05 15:35:37 +00001732 vty_out (vty, " %c%s",
1733 CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB) ? '*' : ' ',
1734 recursing ? " " : "");
paul718e3742002-12-13 20:15:29 +00001735
1736 switch (nexthop->type)
1737 {
1738 case NEXTHOP_TYPE_IPV6:
1739 case NEXTHOP_TYPE_IPV6_IFINDEX:
1740 case NEXTHOP_TYPE_IPV6_IFNAME:
1741 vty_out (vty, " %s",
1742 inet_ntop (AF_INET6, &nexthop->gate.ipv6, buf, BUFSIZ));
1743 if (nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME)
1744 vty_out (vty, ", %s", nexthop->ifname);
1745 else if (nexthop->ifindex)
1746 vty_out (vty, ", via %s", ifindex2ifname (nexthop->ifindex));
1747 break;
1748 case NEXTHOP_TYPE_IFINDEX:
1749 vty_out (vty, " directly connected, %s",
1750 ifindex2ifname (nexthop->ifindex));
1751 break;
1752 case NEXTHOP_TYPE_IFNAME:
1753 vty_out (vty, " directly connected, %s",
1754 nexthop->ifname);
1755 break;
1756 default:
1757 break;
1758 }
1759 if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
1760 vty_out (vty, " inactive");
1761
Christian Frankee8d3d292013-07-05 15:35:39 +00001762 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ONLINK))
1763 vty_out (vty, " onlink");
1764
paul718e3742002-12-13 20:15:29 +00001765 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
Christian Frankefa713d92013-07-05 15:35:37 +00001766 vty_out (vty, " (recursive)");
1767
paul718e3742002-12-13 20:15:29 +00001768 vty_out (vty, "%s", VTY_NEWLINE);
1769 }
1770 vty_out (vty, "%s", VTY_NEWLINE);
1771 }
1772}
1773
paula1ac18c2005-06-28 17:17:12 +00001774static void
paul718e3742002-12-13 20:15:29 +00001775vty_show_ipv6_route (struct vty *vty, struct route_node *rn,
1776 struct rib *rib)
1777{
Christian Frankefa713d92013-07-05 15:35:37 +00001778 struct nexthop *nexthop, *tnexthop;
1779 int recursing;
paul718e3742002-12-13 20:15:29 +00001780 int len = 0;
1781 char buf[BUFSIZ];
1782
1783 /* Nexthop information. */
Christian Frankefa713d92013-07-05 15:35:37 +00001784 for (ALL_NEXTHOPS_RO(rib->nexthop, nexthop, tnexthop, recursing))
paul718e3742002-12-13 20:15:29 +00001785 {
1786 if (nexthop == rib->nexthop)
1787 {
1788 /* Prefix information. */
1789 len = vty_out (vty, "%c%c%c %s/%d",
ajsf52d13c2005-10-01 17:38:06 +00001790 zebra_route_char (rib->type),
paul718e3742002-12-13 20:15:29 +00001791 CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED)
1792 ? '>' : ' ',
1793 CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
1794 ? '*' : ' ',
1795 inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, BUFSIZ),
1796 rn->p.prefixlen);
1797
1798 /* Distance and metric display. */
1799 if (rib->type != ZEBRA_ROUTE_CONNECT
1800 && rib->type != ZEBRA_ROUTE_KERNEL)
1801 len += vty_out (vty, " [%d/%d]", rib->distance,
1802 rib->metric);
1803 }
1804 else
1805 vty_out (vty, " %c%*c",
1806 CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
1807 ? '*' : ' ',
Christian Frankefa713d92013-07-05 15:35:37 +00001808 len - 3 + (2 * recursing), ' ');
paul718e3742002-12-13 20:15:29 +00001809
1810 switch (nexthop->type)
1811 {
1812 case NEXTHOP_TYPE_IPV6:
1813 case NEXTHOP_TYPE_IPV6_IFINDEX:
1814 case NEXTHOP_TYPE_IPV6_IFNAME:
1815 vty_out (vty, " via %s",
1816 inet_ntop (AF_INET6, &nexthop->gate.ipv6, buf, BUFSIZ));
1817 if (nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME)
1818 vty_out (vty, ", %s", nexthop->ifname);
1819 else if (nexthop->ifindex)
1820 vty_out (vty, ", %s", ifindex2ifname (nexthop->ifindex));
1821 break;
1822 case NEXTHOP_TYPE_IFINDEX:
1823 vty_out (vty, " is directly connected, %s",
1824 ifindex2ifname (nexthop->ifindex));
1825 break;
1826 case NEXTHOP_TYPE_IFNAME:
1827 vty_out (vty, " is directly connected, %s",
1828 nexthop->ifname);
1829 break;
1830 default:
1831 break;
1832 }
1833 if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
1834 vty_out (vty, " inactive");
1835
1836 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
Christian Frankefa713d92013-07-05 15:35:37 +00001837 vty_out (vty, " (recursive)");
paul718e3742002-12-13 20:15:29 +00001838
hasso81dfcaa2003-05-25 19:21:25 +00001839 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
1840 vty_out (vty, ", bh");
1841 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT))
1842 vty_out (vty, ", rej");
1843
paul718e3742002-12-13 20:15:29 +00001844 if (rib->type == ZEBRA_ROUTE_RIPNG
1845 || rib->type == ZEBRA_ROUTE_OSPF6
Juliusz Chroboczek578ce372012-02-09 13:42:28 +01001846 || rib->type == ZEBRA_ROUTE_BABEL
jardin9e867fe2003-12-23 08:56:18 +00001847 || rib->type == ZEBRA_ROUTE_ISIS
paul718e3742002-12-13 20:15:29 +00001848 || rib->type == ZEBRA_ROUTE_BGP)
1849 {
1850 time_t uptime;
1851 struct tm *tm;
1852
1853 uptime = time (NULL);
1854 uptime -= rib->uptime;
1855 tm = gmtime (&uptime);
1856
1857#define ONE_DAY_SECOND 60*60*24
1858#define ONE_WEEK_SECOND 60*60*24*7
1859
1860 if (uptime < ONE_DAY_SECOND)
1861 vty_out (vty, ", %02d:%02d:%02d",
1862 tm->tm_hour, tm->tm_min, tm->tm_sec);
1863 else if (uptime < ONE_WEEK_SECOND)
1864 vty_out (vty, ", %dd%02dh%02dm",
1865 tm->tm_yday, tm->tm_hour, tm->tm_min);
1866 else
1867 vty_out (vty, ", %02dw%dd%02dh",
1868 tm->tm_yday/7,
1869 tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
1870 }
1871 vty_out (vty, "%s", VTY_NEWLINE);
1872 }
1873}
1874
paul718e3742002-12-13 20:15:29 +00001875DEFUN (show_ipv6_route,
1876 show_ipv6_route_cmd,
1877 "show ipv6 route",
1878 SHOW_STR
1879 IP_STR
1880 "IPv6 routing table\n")
1881{
1882 struct route_table *table;
1883 struct route_node *rn;
1884 struct rib *rib;
1885 int first = 1;
1886
1887 table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
1888 if (! table)
1889 return CMD_SUCCESS;
1890
1891 /* Show all IPv6 route. */
1892 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001893 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +00001894 {
1895 if (first)
1896 {
David Lampartere0ca5fd2009-09-16 01:52:42 +02001897 vty_out (vty, SHOW_ROUTE_V6_HEADER);
paul718e3742002-12-13 20:15:29 +00001898 first = 0;
1899 }
1900 vty_show_ipv6_route (vty, rn, rib);
1901 }
1902 return CMD_SUCCESS;
1903}
1904
1905DEFUN (show_ipv6_route_prefix_longer,
1906 show_ipv6_route_prefix_longer_cmd,
1907 "show ipv6 route X:X::X:X/M longer-prefixes",
1908 SHOW_STR
1909 IP_STR
1910 "IPv6 routing table\n"
1911 "IPv6 prefix\n"
1912 "Show route matching the specified Network/Mask pair only\n")
1913{
1914 struct route_table *table;
1915 struct route_node *rn;
1916 struct rib *rib;
1917 struct prefix p;
1918 int ret;
1919 int first = 1;
1920
1921 table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
1922 if (! table)
1923 return CMD_SUCCESS;
1924
1925 ret = str2prefix (argv[0], &p);
1926 if (! ret)
1927 {
1928 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
1929 return CMD_WARNING;
1930 }
1931
1932 /* Show matched type IPv6 routes. */
1933 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001934 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +00001935 if (prefix_match (&p, &rn->p))
1936 {
1937 if (first)
1938 {
David Lampartere0ca5fd2009-09-16 01:52:42 +02001939 vty_out (vty, SHOW_ROUTE_V6_HEADER);
paul718e3742002-12-13 20:15:29 +00001940 first = 0;
1941 }
1942 vty_show_ipv6_route (vty, rn, rib);
1943 }
1944 return CMD_SUCCESS;
1945}
1946
1947DEFUN (show_ipv6_route_protocol,
1948 show_ipv6_route_protocol_cmd,
David Lampartere0ca5fd2009-09-16 01:52:42 +02001949 "show ipv6 route " QUAGGA_IP6_REDIST_STR_ZEBRA,
paul718e3742002-12-13 20:15:29 +00001950 SHOW_STR
1951 IP_STR
1952 "IP routing table\n"
David Lampartere0ca5fd2009-09-16 01:52:42 +02001953 QUAGGA_IP6_REDIST_HELP_STR_ZEBRA)
paul718e3742002-12-13 20:15:29 +00001954{
1955 int type;
1956 struct route_table *table;
1957 struct route_node *rn;
1958 struct rib *rib;
1959 int first = 1;
1960
David Lampartere0ca5fd2009-09-16 01:52:42 +02001961 type = proto_redistnum (AFI_IP6, argv[0]);
1962 if (type < 0)
paul718e3742002-12-13 20:15:29 +00001963 {
1964 vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
1965 return CMD_WARNING;
1966 }
1967
1968 table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
1969 if (! table)
1970 return CMD_SUCCESS;
1971
1972 /* Show matched type IPv6 routes. */
1973 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001974 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +00001975 if (rib->type == type)
1976 {
1977 if (first)
1978 {
David Lampartere0ca5fd2009-09-16 01:52:42 +02001979 vty_out (vty, SHOW_ROUTE_V6_HEADER);
paul718e3742002-12-13 20:15:29 +00001980 first = 0;
1981 }
1982 vty_show_ipv6_route (vty, rn, rib);
1983 }
1984 return CMD_SUCCESS;
1985}
1986
1987DEFUN (show_ipv6_route_addr,
1988 show_ipv6_route_addr_cmd,
1989 "show ipv6 route X:X::X:X",
1990 SHOW_STR
1991 IP_STR
1992 "IPv6 routing table\n"
1993 "IPv6 Address\n")
1994{
1995 int ret;
1996 struct prefix_ipv6 p;
1997 struct route_table *table;
1998 struct route_node *rn;
1999
2000 ret = str2prefix_ipv6 (argv[0], &p);
2001 if (ret <= 0)
2002 {
2003 vty_out (vty, "Malformed IPv6 address%s", VTY_NEWLINE);
2004 return CMD_WARNING;
2005 }
2006
2007 table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
2008 if (! table)
2009 return CMD_SUCCESS;
2010
2011 rn = route_node_match (table, (struct prefix *) &p);
2012 if (! rn)
2013 {
2014 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
2015 return CMD_WARNING;
2016 }
2017
2018 vty_show_ipv6_route_detail (vty, rn);
2019
2020 route_unlock_node (rn);
2021
2022 return CMD_SUCCESS;
2023}
2024
2025DEFUN (show_ipv6_route_prefix,
2026 show_ipv6_route_prefix_cmd,
2027 "show ipv6 route X:X::X:X/M",
2028 SHOW_STR
2029 IP_STR
2030 "IPv6 routing table\n"
2031 "IPv6 prefix\n")
2032{
2033 int ret;
2034 struct prefix_ipv6 p;
2035 struct route_table *table;
2036 struct route_node *rn;
2037
2038 ret = str2prefix_ipv6 (argv[0], &p);
2039 if (ret <= 0)
2040 {
2041 vty_out (vty, "Malformed IPv6 prefix%s", VTY_NEWLINE);
2042 return CMD_WARNING;
2043 }
2044
2045 table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
2046 if (! table)
2047 return CMD_SUCCESS;
2048
2049 rn = route_node_match (table, (struct prefix *) &p);
2050 if (! rn || rn->p.prefixlen != p.prefixlen)
2051 {
2052 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
Lu Feng969d3552014-10-21 06:24:07 +00002053 if (rn)
2054 route_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00002055 return CMD_WARNING;
2056 }
2057
2058 vty_show_ipv6_route_detail (vty, rn);
2059
2060 route_unlock_node (rn);
2061
2062 return CMD_SUCCESS;
2063}
2064
Stig Thormodsrud61691c92008-11-04 15:45:07 -08002065/* Show route summary. */
2066DEFUN (show_ipv6_route_summary,
2067 show_ipv6_route_summary_cmd,
2068 "show ipv6 route summary",
2069 SHOW_STR
2070 IP_STR
2071 "IPv6 routing table\n"
2072 "Summary of all IPv6 routes\n")
2073{
2074 struct route_table *table;
2075
2076 table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
2077 if (! table)
2078 return CMD_SUCCESS;
2079
2080 vty_show_ip_route_summary (vty, table);
2081
2082 return CMD_SUCCESS;
2083}
2084
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07002085/* Show ipv6 route summary prefix. */
2086DEFUN (show_ipv6_route_summary_prefix,
2087 show_ipv6_route_summary_prefix_cmd,
2088 "show ipv6 route summary prefix",
2089 SHOW_STR
2090 IP_STR
2091 "IPv6 routing table\n"
2092 "Summary of all IPv6 routes\n"
2093 "Prefix 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_prefix (vty, table);
2102
2103 return CMD_SUCCESS;
2104}
2105
G.Balajicddf3912011-11-26 21:59:32 +04002106/*
G.Balajicddf3912011-11-26 21:59:32 +04002107 * Show IPv6 mroute command.Used to dump
2108 * the Multicast routing table.
2109 */
2110
2111DEFUN (show_ipv6_mroute,
2112 show_ipv6_mroute_cmd,
2113 "show ipv6 mroute",
2114 SHOW_STR
2115 IP_STR
2116 "IPv6 Multicast routing table\n")
2117{
2118 struct route_table *table;
2119 struct route_node *rn;
2120 struct rib *rib;
2121 int first = 1;
2122
2123 table = vrf_table (AFI_IP6, SAFI_MULTICAST, 0);
2124 if (! table)
2125 return CMD_SUCCESS;
2126
2127 /* Show all IPv6 route. */
2128 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00002129 RNODE_FOREACH_RIB (rn, rib)
G.Balajicddf3912011-11-26 21:59:32 +04002130 {
2131 if (first)
2132 {
G.Balajicb32fd62011-11-27 20:09:40 +05302133 vty_out (vty, SHOW_ROUTE_V6_HEADER);
G.Balajicddf3912011-11-26 21:59:32 +04002134 first = 0;
2135 }
2136 vty_show_ipv6_route (vty, rn, rib);
2137 }
2138 return CMD_SUCCESS;
2139}
2140
paul718e3742002-12-13 20:15:29 +00002141/* Write IPv6 static route configuration. */
paula1ac18c2005-06-28 17:17:12 +00002142static int
paul718e3742002-12-13 20:15:29 +00002143static_config_ipv6 (struct vty *vty)
2144{
2145 struct route_node *rn;
2146 struct static_ipv6 *si;
2147 int write;
2148 char buf[BUFSIZ];
2149 struct route_table *stable;
2150
2151 write = 0;
2152
2153 /* Lookup table. */
2154 stable = vrf_static_table (AFI_IP6, SAFI_UNICAST, 0);
2155 if (! stable)
2156 return -1;
2157
2158 for (rn = route_top (stable); rn; rn = route_next (rn))
2159 for (si = rn->info; si; si = si->next)
2160 {
2161 vty_out (vty, "ipv6 route %s/%d",
2162 inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, BUFSIZ),
2163 rn->p.prefixlen);
2164
2165 switch (si->type)
2166 {
2167 case STATIC_IPV6_GATEWAY:
2168 vty_out (vty, " %s", inet_ntop (AF_INET6, &si->ipv6, buf, BUFSIZ));
2169 break;
2170 case STATIC_IPV6_IFNAME:
2171 vty_out (vty, " %s", si->ifname);
2172 break;
2173 case STATIC_IPV6_GATEWAY_IFNAME:
2174 vty_out (vty, " %s %s",
2175 inet_ntop (AF_INET6, &si->ipv6, buf, BUFSIZ), si->ifname);
2176 break;
2177 }
2178
hasso81dfcaa2003-05-25 19:21:25 +00002179 if (CHECK_FLAG(si->flags, ZEBRA_FLAG_REJECT))
2180 vty_out (vty, " %s", "reject");
2181
2182 if (CHECK_FLAG(si->flags, ZEBRA_FLAG_BLACKHOLE))
2183 vty_out (vty, " %s", "blackhole");
2184
paul718e3742002-12-13 20:15:29 +00002185 if (si->distance != ZEBRA_STATIC_DISTANCE_DEFAULT)
2186 vty_out (vty, " %d", si->distance);
2187 vty_out (vty, "%s", VTY_NEWLINE);
2188
2189 write = 1;
2190 }
2191 return write;
2192}
2193#endif /* HAVE_IPV6 */
2194
2195/* Static ip route configuration write function. */
paula1ac18c2005-06-28 17:17:12 +00002196static int
paul718e3742002-12-13 20:15:29 +00002197zebra_ip_config (struct vty *vty)
2198{
2199 int write = 0;
2200
Everton Marques33d86db2014-07-14 11:19:00 -03002201 write += static_config_ipv4 (vty, SAFI_UNICAST, "ip route");
2202 write += static_config_ipv4 (vty, SAFI_MULTICAST, "ip mroute");
paul718e3742002-12-13 20:15:29 +00002203#ifdef HAVE_IPV6
2204 write += static_config_ipv6 (vty);
2205#endif /* HAVE_IPV6 */
2206
2207 return write;
2208}
2209
Paul Jakma7514fb72007-05-02 16:05:35 +00002210/* ip protocol configuration write function */
2211static int config_write_protocol(struct vty *vty)
2212{
2213 int i;
2214
2215 for (i=0;i<ZEBRA_ROUTE_MAX;i++)
2216 {
2217 if (proto_rm[AFI_IP][i])
2218 vty_out (vty, "ip protocol %s route-map %s%s", zebra_route_string(i),
2219 proto_rm[AFI_IP][i], VTY_NEWLINE);
2220 }
2221 if (proto_rm[AFI_IP][ZEBRA_ROUTE_MAX])
2222 vty_out (vty, "ip protocol %s route-map %s%s", "any",
2223 proto_rm[AFI_IP][ZEBRA_ROUTE_MAX], VTY_NEWLINE);
2224
2225 return 1;
2226}
2227
2228/* table node for protocol filtering */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -08002229static struct cmd_node protocol_node = { PROTOCOL_NODE, "", 1 };
Paul Jakma7514fb72007-05-02 16:05:35 +00002230
paul718e3742002-12-13 20:15:29 +00002231/* IP node for static routes. */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -08002232static struct cmd_node ip_node = { IP_NODE, "", 1 };
paul718e3742002-12-13 20:15:29 +00002233
2234/* Route VTY. */
2235void
paula1ac18c2005-06-28 17:17:12 +00002236zebra_vty_init (void)
paul718e3742002-12-13 20:15:29 +00002237{
2238 install_node (&ip_node, zebra_ip_config);
Paul Jakma7514fb72007-05-02 16:05:35 +00002239 install_node (&protocol_node, config_write_protocol);
paul718e3742002-12-13 20:15:29 +00002240
Everton Marques33d86db2014-07-14 11:19:00 -03002241 install_element (CONFIG_NODE, &ip_mroute_cmd);
2242 install_element (CONFIG_NODE, &no_ip_mroute_cmd);
Paul Jakma7514fb72007-05-02 16:05:35 +00002243 install_element (CONFIG_NODE, &ip_protocol_cmd);
2244 install_element (CONFIG_NODE, &no_ip_protocol_cmd);
2245 install_element (VIEW_NODE, &show_ip_protocol_cmd);
2246 install_element (ENABLE_NODE, &show_ip_protocol_cmd);
paul718e3742002-12-13 20:15:29 +00002247 install_element (CONFIG_NODE, &ip_route_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002248 install_element (CONFIG_NODE, &ip_route_flags_cmd);
hasso457ef552003-05-28 12:02:15 +00002249 install_element (CONFIG_NODE, &ip_route_flags2_cmd);
paul718e3742002-12-13 20:15:29 +00002250 install_element (CONFIG_NODE, &ip_route_mask_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002251 install_element (CONFIG_NODE, &ip_route_mask_flags_cmd);
hasso457ef552003-05-28 12:02:15 +00002252 install_element (CONFIG_NODE, &ip_route_mask_flags2_cmd);
paul718e3742002-12-13 20:15:29 +00002253 install_element (CONFIG_NODE, &no_ip_route_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002254 install_element (CONFIG_NODE, &no_ip_route_flags_cmd);
hasso457ef552003-05-28 12:02:15 +00002255 install_element (CONFIG_NODE, &no_ip_route_flags2_cmd);
paul718e3742002-12-13 20:15:29 +00002256 install_element (CONFIG_NODE, &no_ip_route_mask_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002257 install_element (CONFIG_NODE, &no_ip_route_mask_flags_cmd);
hasso457ef552003-05-28 12:02:15 +00002258 install_element (CONFIG_NODE, &no_ip_route_mask_flags2_cmd);
paul718e3742002-12-13 20:15:29 +00002259 install_element (CONFIG_NODE, &ip_route_distance_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002260 install_element (CONFIG_NODE, &ip_route_flags_distance_cmd);
hasso457ef552003-05-28 12:02:15 +00002261 install_element (CONFIG_NODE, &ip_route_flags_distance2_cmd);
paul718e3742002-12-13 20:15:29 +00002262 install_element (CONFIG_NODE, &ip_route_mask_distance_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002263 install_element (CONFIG_NODE, &ip_route_mask_flags_distance_cmd);
hasso457ef552003-05-28 12:02:15 +00002264 install_element (CONFIG_NODE, &ip_route_mask_flags_distance2_cmd);
paul718e3742002-12-13 20:15:29 +00002265 install_element (CONFIG_NODE, &no_ip_route_distance_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002266 install_element (CONFIG_NODE, &no_ip_route_flags_distance_cmd);
hasso457ef552003-05-28 12:02:15 +00002267 install_element (CONFIG_NODE, &no_ip_route_flags_distance2_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002268 install_element (CONFIG_NODE, &no_ip_route_mask_flags_distance_cmd);
hasso457ef552003-05-28 12:02:15 +00002269 install_element (CONFIG_NODE, &no_ip_route_mask_flags_distance2_cmd);
paul718e3742002-12-13 20:15:29 +00002270
2271 install_element (VIEW_NODE, &show_ip_route_cmd);
2272 install_element (VIEW_NODE, &show_ip_route_addr_cmd);
2273 install_element (VIEW_NODE, &show_ip_route_prefix_cmd);
2274 install_element (VIEW_NODE, &show_ip_route_prefix_longer_cmd);
2275 install_element (VIEW_NODE, &show_ip_route_protocol_cmd);
2276 install_element (VIEW_NODE, &show_ip_route_supernets_cmd);
Stig Thormodsrud61691c92008-11-04 15:45:07 -08002277 install_element (VIEW_NODE, &show_ip_route_summary_cmd);
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07002278 install_element (VIEW_NODE, &show_ip_route_summary_prefix_cmd);
paul718e3742002-12-13 20:15:29 +00002279 install_element (ENABLE_NODE, &show_ip_route_cmd);
2280 install_element (ENABLE_NODE, &show_ip_route_addr_cmd);
2281 install_element (ENABLE_NODE, &show_ip_route_prefix_cmd);
2282 install_element (ENABLE_NODE, &show_ip_route_prefix_longer_cmd);
2283 install_element (ENABLE_NODE, &show_ip_route_protocol_cmd);
2284 install_element (ENABLE_NODE, &show_ip_route_supernets_cmd);
paul718e3742002-12-13 20:15:29 +00002285 install_element (ENABLE_NODE, &show_ip_route_summary_cmd);
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07002286 install_element (ENABLE_NODE, &show_ip_route_summary_prefix_cmd);
paul718e3742002-12-13 20:15:29 +00002287
G.Balajicddf3912011-11-26 21:59:32 +04002288 install_element (VIEW_NODE, &show_ip_mroute_cmd);
2289 install_element (ENABLE_NODE, &show_ip_mroute_cmd);
2290
Everton Marques33d86db2014-07-14 11:19:00 -03002291 install_element (VIEW_NODE, &show_ip_rpf_cmd);
2292 install_element (ENABLE_NODE, &show_ip_rpf_cmd);
G.Balajicddf3912011-11-26 21:59:32 +04002293
paul718e3742002-12-13 20:15:29 +00002294#ifdef HAVE_IPV6
2295 install_element (CONFIG_NODE, &ipv6_route_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002296 install_element (CONFIG_NODE, &ipv6_route_flags_cmd);
paul718e3742002-12-13 20:15:29 +00002297 install_element (CONFIG_NODE, &ipv6_route_ifname_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002298 install_element (CONFIG_NODE, &ipv6_route_ifname_flags_cmd);
paul718e3742002-12-13 20:15:29 +00002299 install_element (CONFIG_NODE, &no_ipv6_route_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002300 install_element (CONFIG_NODE, &no_ipv6_route_flags_cmd);
paul718e3742002-12-13 20:15:29 +00002301 install_element (CONFIG_NODE, &no_ipv6_route_ifname_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002302 install_element (CONFIG_NODE, &no_ipv6_route_ifname_flags_cmd);
paul718e3742002-12-13 20:15:29 +00002303 install_element (CONFIG_NODE, &ipv6_route_pref_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002304 install_element (CONFIG_NODE, &ipv6_route_flags_pref_cmd);
paul718e3742002-12-13 20:15:29 +00002305 install_element (CONFIG_NODE, &ipv6_route_ifname_pref_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002306 install_element (CONFIG_NODE, &ipv6_route_ifname_flags_pref_cmd);
paul718e3742002-12-13 20:15:29 +00002307 install_element (CONFIG_NODE, &no_ipv6_route_pref_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002308 install_element (CONFIG_NODE, &no_ipv6_route_flags_pref_cmd);
paul718e3742002-12-13 20:15:29 +00002309 install_element (CONFIG_NODE, &no_ipv6_route_ifname_pref_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002310 install_element (CONFIG_NODE, &no_ipv6_route_ifname_flags_pref_cmd);
paul718e3742002-12-13 20:15:29 +00002311 install_element (VIEW_NODE, &show_ipv6_route_cmd);
Stig Thormodsrud61691c92008-11-04 15:45:07 -08002312 install_element (VIEW_NODE, &show_ipv6_route_summary_cmd);
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07002313 install_element (VIEW_NODE, &show_ipv6_route_summary_prefix_cmd);
paul718e3742002-12-13 20:15:29 +00002314 install_element (VIEW_NODE, &show_ipv6_route_protocol_cmd);
2315 install_element (VIEW_NODE, &show_ipv6_route_addr_cmd);
2316 install_element (VIEW_NODE, &show_ipv6_route_prefix_cmd);
2317 install_element (VIEW_NODE, &show_ipv6_route_prefix_longer_cmd);
2318 install_element (ENABLE_NODE, &show_ipv6_route_cmd);
2319 install_element (ENABLE_NODE, &show_ipv6_route_protocol_cmd);
2320 install_element (ENABLE_NODE, &show_ipv6_route_addr_cmd);
2321 install_element (ENABLE_NODE, &show_ipv6_route_prefix_cmd);
2322 install_element (ENABLE_NODE, &show_ipv6_route_prefix_longer_cmd);
Stig Thormodsrud61691c92008-11-04 15:45:07 -08002323 install_element (ENABLE_NODE, &show_ipv6_route_summary_cmd);
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07002324 install_element (ENABLE_NODE, &show_ipv6_route_summary_prefix_cmd);
G.Balajicddf3912011-11-26 21:59:32 +04002325
2326 install_element (VIEW_NODE, &show_ipv6_mroute_cmd);
2327 install_element (ENABLE_NODE, &show_ipv6_mroute_cmd);
paul718e3742002-12-13 20:15:29 +00002328#endif /* HAVE_IPV6 */
2329}