blob: a4e6af78c8bfa7482c7bd8518a7df28189d1c8fc [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* Zebra VTY functions
2 * Copyright (C) 2002 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with GNU Zebra; see the file COPYING. If not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 */
21
22#include <zebra.h>
23
Paul Jakma7514fb72007-05-02 16:05:35 +000024#include "memory.h"
paul718e3742002-12-13 20:15:29 +000025#include "if.h"
26#include "prefix.h"
27#include "command.h"
28#include "table.h"
29#include "rib.h"
Feng Lu41f44a22015-05-22 11:39:56 +020030#include "vrf.h"
paul718e3742002-12-13 20:15:29 +000031
paula1ac18c2005-06-28 17:17:12 +000032#include "zebra/zserv.h"
33
Everton Marques33d86db2014-07-14 11:19:00 -030034static int do_show_ip_route(struct vty *vty, safi_t safi);
David Lamparter3b02fe82015-01-22 19:12:35 +010035static void vty_show_ip_route_detail (struct vty *vty, struct route_node *rn,
36 int mcast);
Everton Marques33d86db2014-07-14 11:19:00 -030037
38/* General function for static route. */
paula1ac18c2005-06-28 17:17:12 +000039static int
Everton Marques33d86db2014-07-14 11:19:00 -030040zebra_static_ipv4_safi (struct vty *vty, safi_t safi, int add_cmd,
41 const char *dest_str, const char *mask_str,
42 const char *gate_str, const char *flag_str,
43 const char *distance_str)
paul718e3742002-12-13 20:15:29 +000044{
45 int ret;
46 u_char distance;
47 struct prefix p;
48 struct in_addr gate;
49 struct in_addr mask;
hasso39db97e2004-10-12 20:50:58 +000050 const char *ifname;
hasso81dfcaa2003-05-25 19:21:25 +000051 u_char flag = 0;
paul718e3742002-12-13 20:15:29 +000052
53 ret = str2prefix (dest_str, &p);
54 if (ret <= 0)
55 {
56 vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
57 return CMD_WARNING;
58 }
59
60 /* Cisco like mask notation. */
61 if (mask_str)
62 {
63 ret = inet_aton (mask_str, &mask);
64 if (ret == 0)
paul595db7f2003-05-25 21:35:06 +000065 {
66 vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
67 return CMD_WARNING;
68 }
paul718e3742002-12-13 20:15:29 +000069 p.prefixlen = ip_masklen (mask);
70 }
71
72 /* Apply mask for given prefix. */
73 apply_mask (&p);
74
paul595db7f2003-05-25 21:35:06 +000075 /* Administrative distance. */
76 if (distance_str)
77 distance = atoi (distance_str);
78 else
79 distance = ZEBRA_STATIC_DISTANCE_DEFAULT;
80
81 /* Null0 static route. */
hasso457ef552003-05-28 12:02:15 +000082 if ((gate_str != NULL) && (strncasecmp (gate_str, "Null0", strlen (gate_str)) == 0))
paul595db7f2003-05-25 21:35:06 +000083 {
84 if (flag_str)
85 {
86 vty_out (vty, "%% can not have flag %s with Null0%s", flag_str, VTY_NEWLINE);
87 return CMD_WARNING;
88 }
89 if (add_cmd)
Everton Marques33d86db2014-07-14 11:19:00 -030090 static_add_ipv4_safi (safi, &p, NULL, NULL, ZEBRA_FLAG_BLACKHOLE, distance, 0);
paul595db7f2003-05-25 21:35:06 +000091 else
Everton Marques33d86db2014-07-14 11:19:00 -030092 static_delete_ipv4_safi (safi, &p, NULL, NULL, distance, 0);
paul595db7f2003-05-25 21:35:06 +000093 return CMD_SUCCESS;
94 }
95
hasso81dfcaa2003-05-25 19:21:25 +000096 /* Route flags */
97 if (flag_str) {
98 switch(flag_str[0]) {
99 case 'r':
100 case 'R': /* XXX */
101 SET_FLAG (flag, ZEBRA_FLAG_REJECT);
102 break;
103 case 'b':
104 case 'B': /* XXX */
105 SET_FLAG (flag, ZEBRA_FLAG_BLACKHOLE);
106 break;
107 default:
108 vty_out (vty, "%% Malformed flag %s %s", flag_str, VTY_NEWLINE);
paul595db7f2003-05-25 21:35:06 +0000109 return CMD_WARNING;
hasso81dfcaa2003-05-25 19:21:25 +0000110 }
111 }
112
hasso457ef552003-05-28 12:02:15 +0000113 if (gate_str == NULL)
114 {
115 if (add_cmd)
Everton Marques33d86db2014-07-14 11:19:00 -0300116 static_add_ipv4_safi (safi, &p, NULL, NULL, flag, distance, 0);
hasso457ef552003-05-28 12:02:15 +0000117 else
Everton Marques33d86db2014-07-14 11:19:00 -0300118 static_delete_ipv4_safi (safi, &p, NULL, NULL, distance, 0);
hasso457ef552003-05-28 12:02:15 +0000119
120 return CMD_SUCCESS;
121 }
122
paul718e3742002-12-13 20:15:29 +0000123 /* When gateway is A.B.C.D format, gate is treated as nexthop
124 address other case gate is treated as interface name. */
125 ret = inet_aton (gate_str, &gate);
126 if (ret)
127 ifname = NULL;
128 else
129 ifname = gate_str;
130
131 if (add_cmd)
Everton Marques33d86db2014-07-14 11:19:00 -0300132 static_add_ipv4_safi (safi, &p, ifname ? NULL : &gate, ifname, flag, distance, 0);
paul718e3742002-12-13 20:15:29 +0000133 else
Everton Marques33d86db2014-07-14 11:19:00 -0300134 static_delete_ipv4_safi (safi, &p, ifname ? NULL : &gate, ifname, distance, 0);
paul718e3742002-12-13 20:15:29 +0000135
136 return CMD_SUCCESS;
137}
138
Everton Marques33d86db2014-07-14 11:19:00 -0300139static int
140zebra_static_ipv4 (struct vty *vty, int add_cmd, const char *dest_str,
141 const char *mask_str, const char *gate_str,
142 const char *flag_str, const char *distance_str)
143{
144 return zebra_static_ipv4_safi(vty, SAFI_UNICAST, add_cmd, dest_str, mask_str, gate_str, flag_str, distance_str);
145}
146
147/* Static unicast routes for multicast RPF lookup. */
David Lampartera76681b2015-01-22 19:03:53 +0100148DEFUN (ip_mroute_dist,
149 ip_mroute_dist_cmd,
150 "ip mroute A.B.C.D/M (A.B.C.D|INTERFACE) <1-255>",
Everton Marques33d86db2014-07-14 11:19:00 -0300151 IP_STR
152 "Configure static unicast route into MRIB for multicast RPF lookup\n"
153 "IP destination prefix (e.g. 10.0.0.0/8)\n"
154 "Nexthop address\n"
155 "Nexthop interface name\n"
156 "Distance\n")
157{
David Lamparter863f20c2015-01-27 20:24:15 +0100158 VTY_WARN_EXPERIMENTAL();
David Lampartera76681b2015-01-22 19:03:53 +0100159 return zebra_static_ipv4_safi(vty, SAFI_MULTICAST, 1, argv[0], NULL, argv[1],
160 NULL, argc > 2 ? argv[2] : NULL);
Everton Marques33d86db2014-07-14 11:19:00 -0300161}
162
David Lampartera76681b2015-01-22 19:03:53 +0100163ALIAS (ip_mroute_dist,
164 ip_mroute_cmd,
165 "ip mroute A.B.C.D/M (A.B.C.D|INTERFACE)",
166 IP_STR
167 "Configure static unicast route into MRIB for multicast RPF lookup\n"
168 "IP destination prefix (e.g. 10.0.0.0/8)\n"
169 "Nexthop address\n"
170 "Nexthop interface name\n")
171
172DEFUN (no_ip_mroute_dist,
173 no_ip_mroute_dist_cmd,
174 "no ip mroute A.B.C.D/M (A.B.C.D|INTERFACE) <1-255>",
Everton Marques33d86db2014-07-14 11:19:00 -0300175 IP_STR
176 "Configure static unicast route into MRIB for multicast RPF lookup\n"
177 "IP destination prefix (e.g. 10.0.0.0/8)\n"
178 "Nexthop address\n"
179 "Nexthop interface name\n"
180 "Distance\n")
181{
David Lamparter863f20c2015-01-27 20:24:15 +0100182 VTY_WARN_EXPERIMENTAL();
David Lampartera76681b2015-01-22 19:03:53 +0100183 return zebra_static_ipv4_safi(vty, SAFI_MULTICAST, 0, argv[0], NULL, argv[1],
184 NULL, argc > 2 ? argv[2] : NULL);
Everton Marques33d86db2014-07-14 11:19:00 -0300185}
186
David Lampartera76681b2015-01-22 19:03:53 +0100187ALIAS (no_ip_mroute_dist,
188 no_ip_mroute_cmd,
189 "no ip mroute A.B.C.D/M (A.B.C.D|INTERFACE)",
190 NO_STR
191 IP_STR
192 "Configure static unicast route into MRIB for multicast RPF lookup\n"
193 "IP destination prefix (e.g. 10.0.0.0/8)\n"
194 "Nexthop address\n"
195 "Nexthop interface name\n")
196
David Lamparterbd078122015-01-06 19:53:24 +0100197DEFUN (ip_multicast_mode,
198 ip_multicast_mode_cmd,
199 "ip multicast rpf-lookup-mode (urib-only|mrib-only|mrib-then-urib|lower-distance|longer-prefix)",
200 IP_STR
201 "Multicast options\n"
202 "RPF lookup behavior\n"
203 "Lookup in unicast RIB only\n"
204 "Lookup in multicast RIB only\n"
205 "Try multicast RIB first, fall back to unicast RIB\n"
206 "Lookup both, use entry with lower distance\n"
207 "Lookup both, use entry with longer prefix\n")
208{
David Lamparter863f20c2015-01-27 20:24:15 +0100209 VTY_WARN_EXPERIMENTAL();
210
David Lamparterbd078122015-01-06 19:53:24 +0100211 if (!strncmp (argv[0], "u", 1))
212 multicast_mode_ipv4_set (MCAST_URIB_ONLY);
213 else if (!strncmp (argv[0], "mrib-o", 6))
214 multicast_mode_ipv4_set (MCAST_MRIB_ONLY);
215 else if (!strncmp (argv[0], "mrib-t", 6))
216 multicast_mode_ipv4_set (MCAST_MIX_MRIB_FIRST);
217 else if (!strncmp (argv[0], "low", 3))
218 multicast_mode_ipv4_set (MCAST_MIX_DISTANCE);
219 else if (!strncmp (argv[0], "lon", 3))
220 multicast_mode_ipv4_set (MCAST_MIX_PFXLEN);
221 else
222 {
223 vty_out (vty, "Invalid mode specified%s", VTY_NEWLINE);
224 return CMD_WARNING;
225 }
226
227 return CMD_SUCCESS;
228}
229
230DEFUN (no_ip_multicast_mode,
231 no_ip_multicast_mode_cmd,
232 "no ip multicast rpf-lookup-mode (urib-only|mrib-only|mrib-then-urib|lower-distance|longer-prefix)",
233 NO_STR
234 IP_STR
235 "Multicast options\n"
236 "RPF lookup behavior\n"
237 "Lookup in unicast RIB only\n"
238 "Lookup in multicast RIB only\n"
239 "Try multicast RIB first, fall back to unicast RIB\n"
240 "Lookup both, use entry with lower distance\n"
241 "Lookup both, use entry with longer prefix\n")
242{
243 multicast_mode_ipv4_set (MCAST_NO_CONFIG);
244 return CMD_SUCCESS;
245}
246
247ALIAS (no_ip_multicast_mode,
248 no_ip_multicast_mode_noarg_cmd,
249 "no ip multicast rpf-lookup-mode",
250 NO_STR
251 IP_STR
252 "Multicast options\n"
253 "RPF lookup behavior\n")
254
Everton Marques33d86db2014-07-14 11:19:00 -0300255DEFUN (show_ip_rpf,
256 show_ip_rpf_cmd,
257 "show ip rpf",
258 SHOW_STR
259 IP_STR
260 "Display RPF information for multicast source\n")
261{
David Lamparter863f20c2015-01-27 20:24:15 +0100262 VTY_WARN_EXPERIMENTAL();
Everton Marques33d86db2014-07-14 11:19:00 -0300263 return do_show_ip_route(vty, SAFI_MULTICAST);
264}
265
David Lamparter3b02fe82015-01-22 19:12:35 +0100266DEFUN (show_ip_rpf_addr,
267 show_ip_rpf_addr_cmd,
268 "show ip rpf A.B.C.D",
269 SHOW_STR
270 IP_STR
271 "Display RPF information for multicast source\n"
272 "IP multicast source address (e.g. 10.0.0.0)\n")
273{
274 struct in_addr addr;
275 struct route_node *rn;
276 struct rib *rib;
277 int ret;
278
David Lamparter863f20c2015-01-27 20:24:15 +0100279 VTY_WARN_EXPERIMENTAL();
280
David Lamparter3b02fe82015-01-22 19:12:35 +0100281 ret = inet_aton (argv[0], &addr);
282 if (ret == 0)
283 {
284 vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
285 return CMD_WARNING;
286 }
287
288 rib = rib_match_ipv4_multicast (addr, &rn);
289
290 if (rib)
291 vty_show_ip_route_detail (vty, rn, 1);
292 else
293 vty_out (vty, "%% No match for RPF lookup%s", VTY_NEWLINE);
294
295 return CMD_SUCCESS;
296}
297
paul718e3742002-12-13 20:15:29 +0000298/* Static route configuration. */
299DEFUN (ip_route,
300 ip_route_cmd,
paul595db7f2003-05-25 21:35:06 +0000301 "ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0)",
hasso81dfcaa2003-05-25 19:21:25 +0000302 IP_STR
303 "Establish static routes\n"
304 "IP destination prefix (e.g. 10.0.0.0/8)\n"
305 "IP gateway address\n"
paul595db7f2003-05-25 21:35:06 +0000306 "IP gateway interface name\n"
307 "Null interface\n")
hasso81dfcaa2003-05-25 19:21:25 +0000308{
309 return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], NULL, NULL);
310}
311
312DEFUN (ip_route_flags,
313 ip_route_flags_cmd,
314 "ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole)",
paul718e3742002-12-13 20:15:29 +0000315 IP_STR
316 "Establish static routes\n"
317 "IP destination prefix (e.g. 10.0.0.0/8)\n"
318 "IP gateway address\n"
319 "IP gateway interface name\n"
hasso81dfcaa2003-05-25 19:21:25 +0000320 "Emit an ICMP unreachable when matched\n"
321 "Silently discard pkts when matched\n")
paul718e3742002-12-13 20:15:29 +0000322{
hasso81dfcaa2003-05-25 19:21:25 +0000323 return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], argv[2], NULL);
paul718e3742002-12-13 20:15:29 +0000324}
325
hasso457ef552003-05-28 12:02:15 +0000326DEFUN (ip_route_flags2,
327 ip_route_flags2_cmd,
328 "ip route A.B.C.D/M (reject|blackhole)",
329 IP_STR
330 "Establish static routes\n"
331 "IP destination prefix (e.g. 10.0.0.0/8)\n"
332 "Emit an ICMP unreachable when matched\n"
333 "Silently discard pkts when matched\n")
334{
335 return zebra_static_ipv4 (vty, 1, argv[0], NULL, NULL, argv[1], NULL);
336}
337
paul718e3742002-12-13 20:15:29 +0000338/* Mask as A.B.C.D format. */
339DEFUN (ip_route_mask,
340 ip_route_mask_cmd,
paul595db7f2003-05-25 21:35:06 +0000341 "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0)",
hasso81dfcaa2003-05-25 19:21:25 +0000342 IP_STR
343 "Establish static routes\n"
344 "IP destination prefix\n"
345 "IP destination prefix mask\n"
346 "IP gateway address\n"
paul595db7f2003-05-25 21:35:06 +0000347 "IP gateway interface name\n"
348 "Null interface\n")
hasso81dfcaa2003-05-25 19:21:25 +0000349{
350 return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], NULL, NULL);
351}
352
353DEFUN (ip_route_mask_flags,
354 ip_route_mask_flags_cmd,
355 "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole)",
paul718e3742002-12-13 20:15:29 +0000356 IP_STR
357 "Establish static routes\n"
358 "IP destination prefix\n"
359 "IP destination prefix mask\n"
360 "IP gateway address\n"
361 "IP gateway interface name\n"
hasso81dfcaa2003-05-25 19:21:25 +0000362 "Emit an ICMP unreachable when matched\n"
363 "Silently discard pkts when matched\n")
paul718e3742002-12-13 20:15:29 +0000364{
hasso81dfcaa2003-05-25 19:21:25 +0000365 return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], argv[3], NULL);
paul718e3742002-12-13 20:15:29 +0000366}
367
hasso457ef552003-05-28 12:02:15 +0000368DEFUN (ip_route_mask_flags2,
369 ip_route_mask_flags2_cmd,
370 "ip route A.B.C.D A.B.C.D (reject|blackhole)",
371 IP_STR
372 "Establish static routes\n"
373 "IP destination prefix\n"
374 "IP destination prefix mask\n"
375 "Emit an ICMP unreachable when matched\n"
376 "Silently discard pkts when matched\n")
377{
378 return zebra_static_ipv4 (vty, 1, argv[0], argv[1], NULL, argv[2], NULL);
379}
380
paul718e3742002-12-13 20:15:29 +0000381/* Distance option value. */
382DEFUN (ip_route_distance,
383 ip_route_distance_cmd,
paul595db7f2003-05-25 21:35:06 +0000384 "ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0) <1-255>",
paul718e3742002-12-13 20:15:29 +0000385 IP_STR
386 "Establish static routes\n"
387 "IP destination prefix (e.g. 10.0.0.0/8)\n"
388 "IP gateway address\n"
389 "IP gateway interface name\n"
paul595db7f2003-05-25 21:35:06 +0000390 "Null interface\n"
paul718e3742002-12-13 20:15:29 +0000391 "Distance value for this route\n")
392{
hasso81dfcaa2003-05-25 19:21:25 +0000393 return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], NULL, argv[2]);
394}
395
396DEFUN (ip_route_flags_distance,
397 ip_route_flags_distance_cmd,
398 "ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
399 IP_STR
400 "Establish static routes\n"
401 "IP destination prefix (e.g. 10.0.0.0/8)\n"
402 "IP gateway address\n"
403 "IP gateway interface name\n"
404 "Emit an ICMP unreachable when matched\n"
405 "Silently discard pkts when matched\n"
406 "Distance value for this route\n")
407{
408 return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], argv[2], argv[3]);
paul718e3742002-12-13 20:15:29 +0000409}
410
hasso457ef552003-05-28 12:02:15 +0000411DEFUN (ip_route_flags_distance2,
412 ip_route_flags_distance2_cmd,
413 "ip route A.B.C.D/M (reject|blackhole) <1-255>",
414 IP_STR
415 "Establish static routes\n"
416 "IP destination prefix (e.g. 10.0.0.0/8)\n"
417 "Emit an ICMP unreachable when matched\n"
418 "Silently discard pkts when matched\n"
419 "Distance value for this route\n")
420{
421 return zebra_static_ipv4 (vty, 1, argv[0], NULL, NULL, argv[1], argv[2]);
422}
423
paul718e3742002-12-13 20:15:29 +0000424DEFUN (ip_route_mask_distance,
425 ip_route_mask_distance_cmd,
paul595db7f2003-05-25 21:35:06 +0000426 "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0) <1-255>",
paul718e3742002-12-13 20:15:29 +0000427 IP_STR
428 "Establish static routes\n"
429 "IP destination prefix\n"
430 "IP destination prefix mask\n"
431 "IP gateway address\n"
432 "IP gateway interface name\n"
paul595db7f2003-05-25 21:35:06 +0000433 "Null interface\n"
paul718e3742002-12-13 20:15:29 +0000434 "Distance value for this route\n")
435{
hasso81dfcaa2003-05-25 19:21:25 +0000436 return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], NULL, argv[3]);
437}
438
439DEFUN (ip_route_mask_flags_distance,
440 ip_route_mask_flags_distance_cmd,
441 "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
442 IP_STR
443 "Establish static routes\n"
444 "IP destination prefix\n"
445 "IP destination prefix mask\n"
446 "IP gateway address\n"
447 "IP gateway interface name\n"
hasso81dfcaa2003-05-25 19:21:25 +0000448 "Emit an ICMP unreachable when matched\n"
Christian Franke2b005152013-09-30 12:27:49 +0000449 "Silently discard pkts when matched\n"
450 "Distance value for this route\n")
hasso81dfcaa2003-05-25 19:21:25 +0000451{
452 return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], argv[3], argv[4]);
paul718e3742002-12-13 20:15:29 +0000453}
454
hasso457ef552003-05-28 12:02:15 +0000455DEFUN (ip_route_mask_flags_distance2,
456 ip_route_mask_flags_distance2_cmd,
457 "ip route A.B.C.D A.B.C.D (reject|blackhole) <1-255>",
458 IP_STR
459 "Establish static routes\n"
460 "IP destination prefix\n"
461 "IP destination prefix mask\n"
hasso457ef552003-05-28 12:02:15 +0000462 "Emit an ICMP unreachable when matched\n"
Christian Franke2b005152013-09-30 12:27:49 +0000463 "Silently discard pkts when matched\n"
464 "Distance value for this route\n")
hasso457ef552003-05-28 12:02:15 +0000465{
466 return zebra_static_ipv4 (vty, 1, argv[0], argv[1], NULL, argv[2], argv[3]);
467}
468
paul718e3742002-12-13 20:15:29 +0000469DEFUN (no_ip_route,
470 no_ip_route_cmd,
paul595db7f2003-05-25 21:35:06 +0000471 "no ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0)",
hasso81dfcaa2003-05-25 19:21:25 +0000472 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"
paul595db7f2003-05-25 21:35:06 +0000477 "IP gateway interface name\n"
478 "Null interface\n")
hasso81dfcaa2003-05-25 19:21:25 +0000479{
480 return zebra_static_ipv4 (vty, 0, argv[0], NULL, argv[1], NULL, NULL);
481}
482
483ALIAS (no_ip_route,
484 no_ip_route_flags_cmd,
485 "no ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole)",
paul718e3742002-12-13 20:15:29 +0000486 NO_STR
487 IP_STR
488 "Establish static routes\n"
489 "IP destination prefix (e.g. 10.0.0.0/8)\n"
490 "IP gateway address\n"
491 "IP gateway interface name\n"
hasso81dfcaa2003-05-25 19:21:25 +0000492 "Emit an ICMP unreachable when matched\n"
493 "Silently discard pkts when matched\n")
paul718e3742002-12-13 20:15:29 +0000494
hasso457ef552003-05-28 12:02:15 +0000495DEFUN (no_ip_route_flags2,
496 no_ip_route_flags2_cmd,
497 "no ip route A.B.C.D/M (reject|blackhole)",
498 NO_STR
499 IP_STR
500 "Establish static routes\n"
501 "IP destination prefix (e.g. 10.0.0.0/8)\n"
502 "Emit an ICMP unreachable when matched\n"
503 "Silently discard pkts when matched\n")
504{
505 return zebra_static_ipv4 (vty, 0, argv[0], NULL, NULL, NULL, NULL);
506}
507
paul718e3742002-12-13 20:15:29 +0000508DEFUN (no_ip_route_mask,
509 no_ip_route_mask_cmd,
paul595db7f2003-05-25 21:35:06 +0000510 "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0)",
hasso81dfcaa2003-05-25 19:21:25 +0000511 NO_STR
512 IP_STR
513 "Establish static routes\n"
514 "IP destination prefix\n"
515 "IP destination prefix mask\n"
516 "IP gateway address\n"
paul595db7f2003-05-25 21:35:06 +0000517 "IP gateway interface name\n"
518 "Null interface\n")
hasso81dfcaa2003-05-25 19:21:25 +0000519{
520 return zebra_static_ipv4 (vty, 0, argv[0], argv[1], argv[2], NULL, NULL);
521}
522
523ALIAS (no_ip_route_mask,
524 no_ip_route_mask_flags_cmd,
525 "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole)",
paul718e3742002-12-13 20:15:29 +0000526 NO_STR
527 IP_STR
528 "Establish static routes\n"
529 "IP destination prefix\n"
530 "IP destination prefix mask\n"
531 "IP gateway address\n"
532 "IP gateway interface name\n"
hasso81dfcaa2003-05-25 19:21:25 +0000533 "Emit an ICMP unreachable when matched\n"
534 "Silently discard pkts when matched\n")
paul718e3742002-12-13 20:15:29 +0000535
hasso457ef552003-05-28 12:02:15 +0000536DEFUN (no_ip_route_mask_flags2,
537 no_ip_route_mask_flags2_cmd,
538 "no ip route A.B.C.D A.B.C.D (reject|blackhole)",
539 NO_STR
540 IP_STR
541 "Establish static routes\n"
542 "IP destination prefix\n"
543 "IP destination prefix mask\n"
544 "Emit an ICMP unreachable when matched\n"
545 "Silently discard pkts when matched\n")
546{
547 return zebra_static_ipv4 (vty, 0, argv[0], argv[1], NULL, NULL, NULL);
548}
549
paul718e3742002-12-13 20:15:29 +0000550DEFUN (no_ip_route_distance,
551 no_ip_route_distance_cmd,
paul595db7f2003-05-25 21:35:06 +0000552 "no ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0) <1-255>",
paul718e3742002-12-13 20:15:29 +0000553 NO_STR
554 IP_STR
555 "Establish static routes\n"
556 "IP destination prefix (e.g. 10.0.0.0/8)\n"
557 "IP gateway address\n"
558 "IP gateway interface name\n"
paul595db7f2003-05-25 21:35:06 +0000559 "Null interface\n"
paul718e3742002-12-13 20:15:29 +0000560 "Distance value for this route\n")
561{
hasso81dfcaa2003-05-25 19:21:25 +0000562 return zebra_static_ipv4 (vty, 0, argv[0], NULL, argv[1], NULL, argv[2]);
563}
564
565DEFUN (no_ip_route_flags_distance,
566 no_ip_route_flags_distance_cmd,
567 "no ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
568 NO_STR
569 IP_STR
570 "Establish static routes\n"
571 "IP destination prefix (e.g. 10.0.0.0/8)\n"
572 "IP gateway address\n"
573 "IP gateway interface name\n"
574 "Emit an ICMP unreachable when matched\n"
575 "Silently discard pkts when matched\n"
576 "Distance value for this route\n")
577{
578 return zebra_static_ipv4 (vty, 0, argv[0], NULL, argv[1], argv[2], argv[3]);
paul718e3742002-12-13 20:15:29 +0000579}
580
hasso457ef552003-05-28 12:02:15 +0000581DEFUN (no_ip_route_flags_distance2,
582 no_ip_route_flags_distance2_cmd,
583 "no ip route A.B.C.D/M (reject|blackhole) <1-255>",
584 NO_STR
585 IP_STR
586 "Establish static routes\n"
587 "IP destination prefix (e.g. 10.0.0.0/8)\n"
588 "Emit an ICMP unreachable when matched\n"
589 "Silently discard pkts when matched\n"
590 "Distance value for this route\n")
591{
592 return zebra_static_ipv4 (vty, 0, argv[0], NULL, NULL, argv[1], argv[2]);
593}
594
paul718e3742002-12-13 20:15:29 +0000595DEFUN (no_ip_route_mask_distance,
596 no_ip_route_mask_distance_cmd,
paul595db7f2003-05-25 21:35:06 +0000597 "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 +0000598 NO_STR
599 IP_STR
600 "Establish static routes\n"
601 "IP destination prefix\n"
602 "IP destination prefix mask\n"
603 "IP gateway address\n"
604 "IP gateway interface name\n"
paul595db7f2003-05-25 21:35:06 +0000605 "Null interface\n"
paul718e3742002-12-13 20:15:29 +0000606 "Distance value for this route\n")
607{
hasso81dfcaa2003-05-25 19:21:25 +0000608 return zebra_static_ipv4 (vty, 0, argv[0], argv[1], argv[2], NULL, argv[3]);
609}
610
611DEFUN (no_ip_route_mask_flags_distance,
612 no_ip_route_mask_flags_distance_cmd,
613 "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
614 NO_STR
615 IP_STR
616 "Establish static routes\n"
617 "IP destination prefix\n"
618 "IP destination prefix mask\n"
619 "IP gateway address\n"
620 "IP gateway interface name\n"
621 "Emit an ICMP unreachable when matched\n"
622 "Silently discard pkts when matched\n"
623 "Distance value for this route\n")
624{
625 return zebra_static_ipv4 (vty, 0, argv[0], argv[1], argv[2], argv[3], argv[4]);
paul718e3742002-12-13 20:15:29 +0000626}
627
hasso457ef552003-05-28 12:02:15 +0000628DEFUN (no_ip_route_mask_flags_distance2,
629 no_ip_route_mask_flags_distance2_cmd,
630 "no ip route A.B.C.D A.B.C.D (reject|blackhole) <1-255>",
631 NO_STR
632 IP_STR
633 "Establish static routes\n"
634 "IP destination prefix\n"
635 "IP destination prefix mask\n"
636 "Emit an ICMP unreachable when matched\n"
637 "Silently discard pkts when matched\n"
638 "Distance value for this route\n")
639{
640 return zebra_static_ipv4 (vty, 0, argv[0], argv[1], NULL, argv[2], argv[3]);
641}
642
Paul Jakma7514fb72007-05-02 16:05:35 +0000643char *proto_rm[AFI_MAX][ZEBRA_ROUTE_MAX+1]; /* "any" == ZEBRA_ROUTE_MAX */
644
645DEFUN (ip_protocol,
646 ip_protocol_cmd,
647 "ip protocol PROTO route-map ROUTE-MAP",
648 NO_STR
649 "Apply route map to PROTO\n"
650 "Protocol name\n"
651 "Route map name\n")
652{
653 int i;
654
655 if (strcasecmp(argv[0], "any") == 0)
656 i = ZEBRA_ROUTE_MAX;
657 else
658 i = proto_name2num(argv[0]);
659 if (i < 0)
660 {
661 vty_out (vty, "invalid protocol name \"%s\"%s", argv[0] ? argv[0] : "",
662 VTY_NEWLINE);
663 return CMD_WARNING;
664 }
665 if (proto_rm[AFI_IP][i])
666 XFREE (MTYPE_ROUTE_MAP_NAME, proto_rm[AFI_IP][i]);
667 proto_rm[AFI_IP][i] = XSTRDUP (MTYPE_ROUTE_MAP_NAME, argv[1]);
668 return CMD_SUCCESS;
669}
670
671DEFUN (no_ip_protocol,
672 no_ip_protocol_cmd,
673 "no ip protocol PROTO",
674 NO_STR
675 "Remove route map from PROTO\n"
676 "Protocol name\n")
677{
678 int i;
679
680 if (strcasecmp(argv[0], "any") == 0)
681 i = ZEBRA_ROUTE_MAX;
682 else
683 i = proto_name2num(argv[0]);
684 if (i < 0)
685 {
686 vty_out (vty, "invalid protocol name \"%s\"%s", argv[0] ? argv[0] : "",
687 VTY_NEWLINE);
688 return CMD_WARNING;
689 }
690 if (proto_rm[AFI_IP][i])
691 XFREE (MTYPE_ROUTE_MAP_NAME, proto_rm[AFI_IP][i]);
692 proto_rm[AFI_IP][i] = NULL;
693 return CMD_SUCCESS;
694}
695
paul718e3742002-12-13 20:15:29 +0000696/* New RIB. Detailed information for IPv4 route. */
paula1ac18c2005-06-28 17:17:12 +0000697static void
David Lamparter3b02fe82015-01-22 19:12:35 +0100698vty_show_ip_route_detail (struct vty *vty, struct route_node *rn, int mcast)
paul718e3742002-12-13 20:15:29 +0000699{
700 struct rib *rib;
Christian Frankefa713d92013-07-05 15:35:37 +0000701 struct nexthop *nexthop, *tnexthop;
702 int recursing;
Timo Teräs53a5c392015-05-23 11:08:40 +0300703 char buf[PREFIX_STRLEN];
paul718e3742002-12-13 20:15:29 +0000704
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000705 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +0000706 {
David Lamparterb7cce952015-03-07 08:40:48 +0100707 const char *mcast_info = "";
David Lamparter3b02fe82015-01-22 19:12:35 +0100708 if (mcast)
709 {
710 rib_table_info_t *info = rn->table->info;
711 mcast_info = (info->safi == SAFI_MULTICAST)
712 ? " using Multicast RIB"
713 : " using Unicast RIB";
714 }
Timo Teräs53a5c392015-05-23 11:08:40 +0300715 vty_out (vty, "Routing entry for %s%s%s",
716 prefix2str (&rn->p, buf, sizeof(buf)), mcast_info,
717 VTY_NEWLINE);
ajsf52d13c2005-10-01 17:38:06 +0000718 vty_out (vty, " Known via \"%s\"", zebra_route_string (rib->type));
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +0200719 vty_out (vty, ", distance %u, metric %u", rib->distance, rib->metric);
paul718e3742002-12-13 20:15:29 +0000720 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
Timo Teräs53a5c392015-05-23 11:08:40 +0300721 vty_out (vty, ", best");
paul718e3742002-12-13 20:15:29 +0000722 if (rib->refcnt)
Timo Teräs53a5c392015-05-23 11:08:40 +0300723 vty_out (vty, ", refcnt %ld", rib->refcnt);
hasso81dfcaa2003-05-25 19:21:25 +0000724 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
725 vty_out (vty, ", blackhole");
726 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT))
727 vty_out (vty, ", reject");
paul718e3742002-12-13 20:15:29 +0000728 vty_out (vty, "%s", VTY_NEWLINE);
729
730#define ONE_DAY_SECOND 60*60*24
731#define ONE_WEEK_SECOND 60*60*24*7
732 if (rib->type == ZEBRA_ROUTE_RIP
Timo Teräs53a5c392015-05-23 11:08:40 +0300733 || rib->type == ZEBRA_ROUTE_RIPNG
734 || rib->type == ZEBRA_ROUTE_OSPF
735 || rib->type == ZEBRA_ROUTE_OSPF6
736 || rib->type == ZEBRA_ROUTE_BABEL
737 || rib->type == ZEBRA_ROUTE_ISIS
738 || rib->type == ZEBRA_ROUTE_BGP)
paul718e3742002-12-13 20:15:29 +0000739 {
740 time_t uptime;
741 struct tm *tm;
742
743 uptime = time (NULL);
744 uptime -= rib->uptime;
745 tm = gmtime (&uptime);
746
747 vty_out (vty, " Last update ");
748
749 if (uptime < ONE_DAY_SECOND)
750 vty_out (vty, "%02d:%02d:%02d",
751 tm->tm_hour, tm->tm_min, tm->tm_sec);
752 else if (uptime < ONE_WEEK_SECOND)
753 vty_out (vty, "%dd%02dh%02dm",
754 tm->tm_yday, tm->tm_hour, tm->tm_min);
755 else
756 vty_out (vty, "%02dw%dd%02dh",
757 tm->tm_yday/7,
758 tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
759 vty_out (vty, " ago%s", VTY_NEWLINE);
760 }
761
Christian Frankefa713d92013-07-05 15:35:37 +0000762 for (ALL_NEXTHOPS_RO(rib->nexthop, nexthop, tnexthop, recursing))
Timo Teräs53a5c392015-05-23 11:08:40 +0300763 {
764 vty_out (vty, " %c%s",
765 CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB) ? '*' : ' ',
766 recursing ? " " : "");
Paul Jakma7514fb72007-05-02 16:05:35 +0000767
Timo Teräs53a5c392015-05-23 11:08:40 +0300768 switch (nexthop->type)
769 {
770 case NEXTHOP_TYPE_IPV4:
771 case NEXTHOP_TYPE_IPV4_IFINDEX:
772 vty_out (vty, " %s", inet_ntoa (nexthop->gate.ipv4));
773 if (nexthop->ifindex)
774 vty_out (vty, ", via %s", ifindex2ifname (nexthop->ifindex));
775 break;
776 case NEXTHOP_TYPE_IPV6:
777 case NEXTHOP_TYPE_IPV6_IFINDEX:
778 case NEXTHOP_TYPE_IPV6_IFNAME:
779 vty_out (vty, " %s",
780 inet_ntop (AF_INET6, &nexthop->gate.ipv6, buf, sizeof(buf)));
781 if (nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME)
782 vty_out (vty, ", %s", nexthop->ifname);
783 else if (nexthop->ifindex)
784 vty_out (vty, ", via %s", ifindex2ifname (nexthop->ifindex));
785 break;
786 case NEXTHOP_TYPE_IFINDEX:
787 vty_out (vty, " directly connected, %s",
788 ifindex2ifname (nexthop->ifindex));
789 break;
790 case NEXTHOP_TYPE_IFNAME:
791 vty_out (vty, " directly connected, %s", nexthop->ifname);
792 break;
793 case NEXTHOP_TYPE_BLACKHOLE:
794 vty_out (vty, " directly connected, Null0");
795 break;
796 default:
797 break;
798 }
799 if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
800 vty_out (vty, " inactive");
paul718e3742002-12-13 20:15:29 +0000801
Timo Teräs53a5c392015-05-23 11:08:40 +0300802 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ONLINK))
803 vty_out (vty, " onlink");
paul718e3742002-12-13 20:15:29 +0000804
Timo Teräs53a5c392015-05-23 11:08:40 +0300805 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
806 vty_out (vty, " (recursive)");
Christian Frankee8d3d292013-07-05 15:35:39 +0000807
Timo Teräs53a5c392015-05-23 11:08:40 +0300808 switch (nexthop->type)
Paul Jakma7514fb72007-05-02 16:05:35 +0000809 {
810 case NEXTHOP_TYPE_IPV4:
811 case NEXTHOP_TYPE_IPV4_IFINDEX:
812 case NEXTHOP_TYPE_IPV4_IFNAME:
813 if (nexthop->src.ipv4.s_addr)
814 {
Timo Teräs53a5c392015-05-23 11:08:40 +0300815 if (inet_ntop(AF_INET, &nexthop->src.ipv4, buf, sizeof buf))
816 vty_out (vty, ", src %s", buf);
Paul Jakma7514fb72007-05-02 16:05:35 +0000817 }
818 break;
Andrew J. Schorr09303312007-05-30 20:10:34 +0000819#ifdef HAVE_IPV6
Paul Jakma7514fb72007-05-02 16:05:35 +0000820 case NEXTHOP_TYPE_IPV6:
821 case NEXTHOP_TYPE_IPV6_IFINDEX:
822 case NEXTHOP_TYPE_IPV6_IFNAME:
823 if (!IPV6_ADDR_SAME(&nexthop->src.ipv6, &in6addr_any))
824 {
Timo Teräs53a5c392015-05-23 11:08:40 +0300825 if (inet_ntop(AF_INET6, &nexthop->src.ipv6, buf, sizeof buf))
826 vty_out (vty, ", src %s", buf);
Paul Jakma7514fb72007-05-02 16:05:35 +0000827 }
828 break;
Andrew J. Schorr09303312007-05-30 20:10:34 +0000829#endif /* HAVE_IPV6 */
Paul Jakma7514fb72007-05-02 16:05:35 +0000830 default:
Timo Teräs53a5c392015-05-23 11:08:40 +0300831 break;
Paul Jakma7514fb72007-05-02 16:05:35 +0000832 }
Timo Teräs53a5c392015-05-23 11:08:40 +0300833 vty_out (vty, "%s", VTY_NEWLINE);
834 }
paul718e3742002-12-13 20:15:29 +0000835 vty_out (vty, "%s", VTY_NEWLINE);
836 }
837}
838
paula1ac18c2005-06-28 17:17:12 +0000839static void
paul718e3742002-12-13 20:15:29 +0000840vty_show_ip_route (struct vty *vty, struct route_node *rn, struct rib *rib)
841{
Christian Frankefa713d92013-07-05 15:35:37 +0000842 struct nexthop *nexthop, *tnexthop;
843 int recursing;
paul718e3742002-12-13 20:15:29 +0000844 int len = 0;
845 char buf[BUFSIZ];
846
847 /* Nexthop information. */
Christian Frankefa713d92013-07-05 15:35:37 +0000848 for (ALL_NEXTHOPS_RO(rib->nexthop, nexthop, tnexthop, recursing))
paul718e3742002-12-13 20:15:29 +0000849 {
850 if (nexthop == rib->nexthop)
851 {
852 /* Prefix information. */
Timo Teräs53a5c392015-05-23 11:08:40 +0300853 len = vty_out (vty, "%c%c%c %s",
ajsf52d13c2005-10-01 17:38:06 +0000854 zebra_route_char (rib->type),
paul718e3742002-12-13 20:15:29 +0000855 CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED)
856 ? '>' : ' ',
857 CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
858 ? '*' : ' ',
Timo Teräs53a5c392015-05-23 11:08:40 +0300859 prefix2str (&rn->p, buf, sizeof buf));
paul718e3742002-12-13 20:15:29 +0000860
861 /* Distance and metric display. */
862 if (rib->type != ZEBRA_ROUTE_CONNECT
863 && rib->type != ZEBRA_ROUTE_KERNEL)
864 len += vty_out (vty, " [%d/%d]", rib->distance,
865 rib->metric);
866 }
867 else
868 vty_out (vty, " %c%*c",
869 CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
870 ? '*' : ' ',
Christian Frankefa713d92013-07-05 15:35:37 +0000871 len - 3 + (2 * recursing), ' ');
paul718e3742002-12-13 20:15:29 +0000872
873 switch (nexthop->type)
Timo Teräs53a5c392015-05-23 11:08:40 +0300874 {
875 case NEXTHOP_TYPE_IPV4:
876 case NEXTHOP_TYPE_IPV4_IFINDEX:
877 vty_out (vty, " via %s", inet_ntoa (nexthop->gate.ipv4));
878 if (nexthop->ifindex)
879 vty_out (vty, ", %s", ifindex2ifname (nexthop->ifindex));
880 break;
881 case NEXTHOP_TYPE_IPV6:
882 case NEXTHOP_TYPE_IPV6_IFINDEX:
883 case NEXTHOP_TYPE_IPV6_IFNAME:
884 vty_out (vty, " via %s",
885 inet_ntop (AF_INET6, &nexthop->gate.ipv6, buf, BUFSIZ));
886 if (nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME)
887 vty_out (vty, ", %s", nexthop->ifname);
888 else if (nexthop->ifindex)
889 vty_out (vty, ", %s", ifindex2ifname (nexthop->ifindex));
890 break;
891 case NEXTHOP_TYPE_IFINDEX:
892 vty_out (vty, " is directly connected, %s",
893 ifindex2ifname (nexthop->ifindex));
894 break;
895 case NEXTHOP_TYPE_IFNAME:
896 vty_out (vty, " is directly connected, %s", nexthop->ifname);
897 break;
898 case NEXTHOP_TYPE_BLACKHOLE:
899 vty_out (vty, " is directly connected, Null0");
900 break;
901 default:
902 break;
903 }
paul718e3742002-12-13 20:15:29 +0000904 if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
Timo Teräs53a5c392015-05-23 11:08:40 +0300905 vty_out (vty, " inactive");
paul718e3742002-12-13 20:15:29 +0000906
Christian Frankee8d3d292013-07-05 15:35:39 +0000907 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ONLINK))
Timo Teräs53a5c392015-05-23 11:08:40 +0300908 vty_out (vty, " onlink");
Christian Frankee8d3d292013-07-05 15:35:39 +0000909
paul718e3742002-12-13 20:15:29 +0000910 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
Timo Teräs53a5c392015-05-23 11:08:40 +0300911 vty_out (vty, " (recursive)");
Christian Frankefa713d92013-07-05 15:35:37 +0000912
Paul Jakma7514fb72007-05-02 16:05:35 +0000913 switch (nexthop->type)
914 {
915 case NEXTHOP_TYPE_IPV4:
916 case NEXTHOP_TYPE_IPV4_IFINDEX:
917 case NEXTHOP_TYPE_IPV4_IFNAME:
918 if (nexthop->src.ipv4.s_addr)
919 {
Timo Teräs53a5c392015-05-23 11:08:40 +0300920 if (inet_ntop(AF_INET, &nexthop->src.ipv4, buf, sizeof buf))
Paul Jakma7514fb72007-05-02 16:05:35 +0000921 vty_out (vty, ", src %s", buf);
922 }
923 break;
Andrew J. Schorr09303312007-05-30 20:10:34 +0000924#ifdef HAVE_IPV6
Paul Jakma7514fb72007-05-02 16:05:35 +0000925 case NEXTHOP_TYPE_IPV6:
926 case NEXTHOP_TYPE_IPV6_IFINDEX:
927 case NEXTHOP_TYPE_IPV6_IFNAME:
928 if (!IPV6_ADDR_SAME(&nexthop->src.ipv6, &in6addr_any))
929 {
Timo Teräs53a5c392015-05-23 11:08:40 +0300930 if (inet_ntop(AF_INET6, &nexthop->src.ipv6, buf, sizeof buf))
Paul Jakma7514fb72007-05-02 16:05:35 +0000931 vty_out (vty, ", src %s", buf);
932 }
933 break;
Andrew J. Schorr09303312007-05-30 20:10:34 +0000934#endif /* HAVE_IPV6 */
Paul Jakma7514fb72007-05-02 16:05:35 +0000935 default:
Timo Teräs53a5c392015-05-23 11:08:40 +0300936 break;
Paul Jakma7514fb72007-05-02 16:05:35 +0000937 }
paul718e3742002-12-13 20:15:29 +0000938
hasso81dfcaa2003-05-25 19:21:25 +0000939 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
940 vty_out (vty, ", bh");
941 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT))
942 vty_out (vty, ", rej");
943
paul718e3742002-12-13 20:15:29 +0000944 if (rib->type == ZEBRA_ROUTE_RIP
Timo Teräs53a5c392015-05-23 11:08:40 +0300945 || rib->type == ZEBRA_ROUTE_RIPNG
946 || rib->type == ZEBRA_ROUTE_OSPF
947 || rib->type == ZEBRA_ROUTE_OSPF6
948 || rib->type == ZEBRA_ROUTE_BABEL
949 || rib->type == ZEBRA_ROUTE_ISIS
950 || rib->type == ZEBRA_ROUTE_BGP)
paul718e3742002-12-13 20:15:29 +0000951 {
952 time_t uptime;
953 struct tm *tm;
954
955 uptime = time (NULL);
956 uptime -= rib->uptime;
957 tm = gmtime (&uptime);
958
959#define ONE_DAY_SECOND 60*60*24
960#define ONE_WEEK_SECOND 60*60*24*7
961
962 if (uptime < ONE_DAY_SECOND)
963 vty_out (vty, ", %02d:%02d:%02d",
964 tm->tm_hour, tm->tm_min, tm->tm_sec);
965 else if (uptime < ONE_WEEK_SECOND)
966 vty_out (vty, ", %dd%02dh%02dm",
967 tm->tm_yday, tm->tm_hour, tm->tm_min);
968 else
969 vty_out (vty, ", %02dw%dd%02dh",
970 tm->tm_yday/7,
971 tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
972 }
973 vty_out (vty, "%s", VTY_NEWLINE);
974 }
975}
976
paul718e3742002-12-13 20:15:29 +0000977DEFUN (show_ip_route,
978 show_ip_route_cmd,
979 "show ip route",
980 SHOW_STR
981 IP_STR
982 "IP routing table\n")
983{
Everton Marques33d86db2014-07-14 11:19:00 -0300984 return do_show_ip_route(vty, SAFI_UNICAST);
985}
986
987static int do_show_ip_route(struct vty *vty, safi_t safi) {
paul718e3742002-12-13 20:15:29 +0000988 struct route_table *table;
989 struct route_node *rn;
990 struct rib *rib;
991 int first = 1;
992
Feng Lu41f44a22015-05-22 11:39:56 +0200993 table = zebra_vrf_table (AFI_IP, safi, VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +0000994 if (! table)
995 return CMD_SUCCESS;
996
997 /* Show all IPv4 routes. */
998 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000999 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +00001000 {
1001 if (first)
1002 {
David Lampartere0ca5fd2009-09-16 01:52:42 +02001003 vty_out (vty, SHOW_ROUTE_V4_HEADER);
paul718e3742002-12-13 20:15:29 +00001004 first = 0;
1005 }
1006 vty_show_ip_route (vty, rn, rib);
1007 }
1008 return CMD_SUCCESS;
1009}
1010
1011DEFUN (show_ip_route_prefix_longer,
1012 show_ip_route_prefix_longer_cmd,
1013 "show ip route A.B.C.D/M longer-prefixes",
1014 SHOW_STR
1015 IP_STR
1016 "IP routing table\n"
1017 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1018 "Show route matching the specified Network/Mask pair only\n")
1019{
1020 struct route_table *table;
1021 struct route_node *rn;
1022 struct rib *rib;
1023 struct prefix p;
1024 int ret;
1025 int first = 1;
1026
1027 ret = str2prefix (argv[0], &p);
1028 if (! ret)
1029 {
1030 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
1031 return CMD_WARNING;
1032 }
1033
Feng Lu41f44a22015-05-22 11:39:56 +02001034 table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +00001035 if (! table)
1036 return CMD_SUCCESS;
1037
1038 /* Show matched type IPv4 routes. */
1039 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001040 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +00001041 if (prefix_match (&p, &rn->p))
1042 {
1043 if (first)
1044 {
David Lampartere0ca5fd2009-09-16 01:52:42 +02001045 vty_out (vty, SHOW_ROUTE_V4_HEADER);
paul718e3742002-12-13 20:15:29 +00001046 first = 0;
1047 }
1048 vty_show_ip_route (vty, rn, rib);
1049 }
1050 return CMD_SUCCESS;
1051}
1052
1053DEFUN (show_ip_route_supernets,
1054 show_ip_route_supernets_cmd,
1055 "show ip route supernets-only",
1056 SHOW_STR
1057 IP_STR
1058 "IP routing table\n"
1059 "Show supernet entries only\n")
1060{
1061 struct route_table *table;
1062 struct route_node *rn;
1063 struct rib *rib;
1064 u_int32_t addr;
1065 int first = 1;
1066
Feng Lu41f44a22015-05-22 11:39:56 +02001067 table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +00001068 if (! table)
1069 return CMD_SUCCESS;
1070
1071 /* Show matched type IPv4 routes. */
1072 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001073 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +00001074 {
1075 addr = ntohl (rn->p.u.prefix4.s_addr);
1076
1077 if ((IN_CLASSC (addr) && rn->p.prefixlen < 24)
1078 || (IN_CLASSB (addr) && rn->p.prefixlen < 16)
1079 || (IN_CLASSA (addr) && rn->p.prefixlen < 8))
1080 {
1081 if (first)
1082 {
David Lampartere0ca5fd2009-09-16 01:52:42 +02001083 vty_out (vty, SHOW_ROUTE_V4_HEADER);
paul718e3742002-12-13 20:15:29 +00001084 first = 0;
1085 }
1086 vty_show_ip_route (vty, rn, rib);
1087 }
1088 }
1089 return CMD_SUCCESS;
1090}
1091
1092DEFUN (show_ip_route_protocol,
1093 show_ip_route_protocol_cmd,
David Lampartere0ca5fd2009-09-16 01:52:42 +02001094 "show ip route " QUAGGA_IP_REDIST_STR_ZEBRA,
paul718e3742002-12-13 20:15:29 +00001095 SHOW_STR
1096 IP_STR
1097 "IP routing table\n"
David Lampartere0ca5fd2009-09-16 01:52:42 +02001098 QUAGGA_IP_REDIST_HELP_STR_ZEBRA)
paul718e3742002-12-13 20:15:29 +00001099{
1100 int type;
1101 struct route_table *table;
1102 struct route_node *rn;
1103 struct rib *rib;
1104 int first = 1;
1105
David Lampartere0ca5fd2009-09-16 01:52:42 +02001106 type = proto_redistnum (AFI_IP, argv[0]);
1107 if (type < 0)
paul718e3742002-12-13 20:15:29 +00001108 {
1109 vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
1110 return CMD_WARNING;
1111 }
1112
Feng Lu41f44a22015-05-22 11:39:56 +02001113 table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +00001114 if (! table)
1115 return CMD_SUCCESS;
1116
1117 /* Show matched type IPv4 routes. */
1118 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001119 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +00001120 if (rib->type == type)
1121 {
1122 if (first)
1123 {
David Lampartere0ca5fd2009-09-16 01:52:42 +02001124 vty_out (vty, SHOW_ROUTE_V4_HEADER);
paul718e3742002-12-13 20:15:29 +00001125 first = 0;
1126 }
1127 vty_show_ip_route (vty, rn, rib);
1128 }
1129 return CMD_SUCCESS;
1130}
1131
1132DEFUN (show_ip_route_addr,
1133 show_ip_route_addr_cmd,
1134 "show ip route A.B.C.D",
1135 SHOW_STR
1136 IP_STR
1137 "IP routing table\n"
1138 "Network in the IP routing table to display\n")
1139{
1140 int ret;
1141 struct prefix_ipv4 p;
1142 struct route_table *table;
1143 struct route_node *rn;
1144
1145 ret = str2prefix_ipv4 (argv[0], &p);
1146 if (ret <= 0)
1147 {
1148 vty_out (vty, "%% Malformed IPv4 address%s", VTY_NEWLINE);
1149 return CMD_WARNING;
1150 }
1151
Feng Lu41f44a22015-05-22 11:39:56 +02001152 table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +00001153 if (! table)
1154 return CMD_SUCCESS;
1155
1156 rn = route_node_match (table, (struct prefix *) &p);
1157 if (! rn)
1158 {
1159 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
1160 return CMD_WARNING;
1161 }
1162
David Lamparter3b02fe82015-01-22 19:12:35 +01001163 vty_show_ip_route_detail (vty, rn, 0);
paul718e3742002-12-13 20:15:29 +00001164
1165 route_unlock_node (rn);
1166
1167 return CMD_SUCCESS;
1168}
1169
1170DEFUN (show_ip_route_prefix,
1171 show_ip_route_prefix_cmd,
1172 "show ip route A.B.C.D/M",
1173 SHOW_STR
1174 IP_STR
1175 "IP routing table\n"
1176 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
1177{
1178 int ret;
1179 struct prefix_ipv4 p;
1180 struct route_table *table;
1181 struct route_node *rn;
1182
1183 ret = str2prefix_ipv4 (argv[0], &p);
1184 if (ret <= 0)
1185 {
1186 vty_out (vty, "%% Malformed IPv4 address%s", VTY_NEWLINE);
1187 return CMD_WARNING;
1188 }
1189
Feng Lu41f44a22015-05-22 11:39:56 +02001190 table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +00001191 if (! table)
1192 return CMD_SUCCESS;
1193
1194 rn = route_node_match (table, (struct prefix *) &p);
1195 if (! rn || rn->p.prefixlen != p.prefixlen)
1196 {
1197 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
Lu Feng969d3552014-10-21 06:24:07 +00001198 if (rn)
1199 route_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00001200 return CMD_WARNING;
1201 }
1202
David Lamparter3b02fe82015-01-22 19:12:35 +01001203 vty_show_ip_route_detail (vty, rn, 0);
paul718e3742002-12-13 20:15:29 +00001204
1205 route_unlock_node (rn);
1206
1207 return CMD_SUCCESS;
1208}
1209
paula1ac18c2005-06-28 17:17:12 +00001210static void
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001211vty_show_ip_route_summary (struct vty *vty, struct route_table *table)
paul718e3742002-12-13 20:15:29 +00001212{
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001213 struct route_node *rn;
1214 struct rib *rib;
1215 struct nexthop *nexthop;
1216#define ZEBRA_ROUTE_IBGP ZEBRA_ROUTE_MAX
1217#define ZEBRA_ROUTE_TOTAL (ZEBRA_ROUTE_IBGP + 1)
1218 u_int32_t rib_cnt[ZEBRA_ROUTE_TOTAL + 1];
1219 u_int32_t fib_cnt[ZEBRA_ROUTE_TOTAL + 1];
1220 u_int32_t i;
paul718e3742002-12-13 20:15:29 +00001221
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001222 memset (&rib_cnt, 0, sizeof(rib_cnt));
1223 memset (&fib_cnt, 0, sizeof(fib_cnt));
1224 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001225 RNODE_FOREACH_RIB (rn, rib)
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001226 for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
1227 {
1228 rib_cnt[ZEBRA_ROUTE_TOTAL]++;
1229 rib_cnt[rib->type]++;
Christian Frankefa713d92013-07-05 15:35:37 +00001230 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
1231 || nexthop_has_fib_child(nexthop))
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001232 {
1233 fib_cnt[ZEBRA_ROUTE_TOTAL]++;
1234 fib_cnt[rib->type]++;
1235 }
1236 if (rib->type == ZEBRA_ROUTE_BGP &&
1237 CHECK_FLAG (rib->flags, ZEBRA_FLAG_IBGP))
1238 {
1239 rib_cnt[ZEBRA_ROUTE_IBGP]++;
Christian Frankefa713d92013-07-05 15:35:37 +00001240 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
1241 || nexthop_has_fib_child(nexthop))
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001242 fib_cnt[ZEBRA_ROUTE_IBGP]++;
1243 }
1244 }
paul718e3742002-12-13 20:15:29 +00001245
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001246 vty_out (vty, "%-20s %-20s %-20s %s",
1247 "Route Source", "Routes", "FIB", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001248
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001249 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
1250 {
1251 if (rib_cnt[i] > 0)
1252 {
1253 if (i == ZEBRA_ROUTE_BGP)
1254 {
1255 vty_out (vty, "%-20s %-20d %-20d %s", "ebgp",
1256 rib_cnt[ZEBRA_ROUTE_BGP] - rib_cnt[ZEBRA_ROUTE_IBGP],
1257 fib_cnt[ZEBRA_ROUTE_BGP] - fib_cnt[ZEBRA_ROUTE_IBGP],
1258 VTY_NEWLINE);
1259 vty_out (vty, "%-20s %-20d %-20d %s", "ibgp",
1260 rib_cnt[ZEBRA_ROUTE_IBGP], fib_cnt[ZEBRA_ROUTE_IBGP],
1261 VTY_NEWLINE);
1262 }
1263 else
1264 vty_out (vty, "%-20s %-20d %-20d %s", zebra_route_string(i),
1265 rib_cnt[i], fib_cnt[i], VTY_NEWLINE);
1266 }
1267 }
paul718e3742002-12-13 20:15:29 +00001268
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001269 vty_out (vty, "------%s", VTY_NEWLINE);
1270 vty_out (vty, "%-20s %-20d %-20d %s", "Totals", rib_cnt[ZEBRA_ROUTE_TOTAL],
1271 fib_cnt[ZEBRA_ROUTE_TOTAL], VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001272}
1273
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07001274/*
1275 * Implementation of the ip route summary prefix command.
1276 *
1277 * This command prints the primary prefixes that have been installed by various
1278 * protocols on the box.
1279 *
1280 */
1281static void
1282vty_show_ip_route_summary_prefix (struct vty *vty, struct route_table *table)
1283{
1284 struct route_node *rn;
1285 struct rib *rib;
1286 struct nexthop *nexthop;
1287#define ZEBRA_ROUTE_IBGP ZEBRA_ROUTE_MAX
1288#define ZEBRA_ROUTE_TOTAL (ZEBRA_ROUTE_IBGP + 1)
1289 u_int32_t rib_cnt[ZEBRA_ROUTE_TOTAL + 1];
1290 u_int32_t fib_cnt[ZEBRA_ROUTE_TOTAL + 1];
1291 u_int32_t i;
1292 int cnt;
1293
1294 memset (&rib_cnt, 0, sizeof(rib_cnt));
1295 memset (&fib_cnt, 0, sizeof(fib_cnt));
1296 for (rn = route_top (table); rn; rn = route_next (rn))
1297 RNODE_FOREACH_RIB (rn, rib)
1298 {
1299
1300 /*
1301 * In case of ECMP, count only once.
1302 */
1303 cnt = 0;
1304 for (nexthop = rib->nexthop; (!cnt && nexthop); nexthop = nexthop->next)
1305 {
1306 cnt++;
1307 rib_cnt[ZEBRA_ROUTE_TOTAL]++;
1308 rib_cnt[rib->type]++;
1309 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB))
1310 {
1311 fib_cnt[ZEBRA_ROUTE_TOTAL]++;
1312 fib_cnt[rib->type]++;
1313 }
1314 if (rib->type == ZEBRA_ROUTE_BGP &&
1315 CHECK_FLAG (rib->flags, ZEBRA_FLAG_IBGP))
1316 {
1317 rib_cnt[ZEBRA_ROUTE_IBGP]++;
1318 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB))
1319 fib_cnt[ZEBRA_ROUTE_IBGP]++;
1320 }
1321 }
1322 }
1323
1324 vty_out (vty, "%-20s %-20s %-20s %s",
1325 "Route Source", "Prefix Routes", "FIB", VTY_NEWLINE);
1326
1327 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
1328 {
1329 if (rib_cnt[i] > 0)
1330 {
1331 if (i == ZEBRA_ROUTE_BGP)
1332 {
1333 vty_out (vty, "%-20s %-20d %-20d %s", "ebgp",
1334 rib_cnt[ZEBRA_ROUTE_BGP] - rib_cnt[ZEBRA_ROUTE_IBGP],
1335 fib_cnt[ZEBRA_ROUTE_BGP] - fib_cnt[ZEBRA_ROUTE_IBGP],
1336 VTY_NEWLINE);
1337 vty_out (vty, "%-20s %-20d %-20d %s", "ibgp",
1338 rib_cnt[ZEBRA_ROUTE_IBGP], fib_cnt[ZEBRA_ROUTE_IBGP],
1339 VTY_NEWLINE);
1340 }
1341 else
1342 vty_out (vty, "%-20s %-20d %-20d %s", zebra_route_string(i),
1343 rib_cnt[i], fib_cnt[i], VTY_NEWLINE);
1344 }
1345 }
1346
1347 vty_out (vty, "------%s", VTY_NEWLINE);
1348 vty_out (vty, "%-20s %-20d %-20d %s", "Totals", rib_cnt[ZEBRA_ROUTE_TOTAL],
1349 fib_cnt[ZEBRA_ROUTE_TOTAL], VTY_NEWLINE);
1350}
1351
paul718e3742002-12-13 20:15:29 +00001352/* Show route summary. */
1353DEFUN (show_ip_route_summary,
1354 show_ip_route_summary_cmd,
1355 "show ip route summary",
1356 SHOW_STR
1357 IP_STR
1358 "IP routing table\n"
1359 "Summary of all routes\n")
1360{
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001361 struct route_table *table;
paul718e3742002-12-13 20:15:29 +00001362
Feng Lu41f44a22015-05-22 11:39:56 +02001363 table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001364 if (! table)
1365 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001366
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001367 vty_show_ip_route_summary (vty, table);
paul718e3742002-12-13 20:15:29 +00001368
1369 return CMD_SUCCESS;
1370}
1371
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07001372/* Show route summary prefix. */
1373DEFUN (show_ip_route_summary_prefix,
1374 show_ip_route_summary_prefix_cmd,
1375 "show ip route summary prefix",
1376 SHOW_STR
1377 IP_STR
1378 "IP routing table\n"
1379 "Summary of all routes\n"
1380 "Prefix routes\n")
1381{
1382 struct route_table *table;
1383
Feng Lu41f44a22015-05-22 11:39:56 +02001384 table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07001385 if (! table)
1386 return CMD_SUCCESS;
1387
1388 vty_show_ip_route_summary_prefix (vty, table);
1389
1390 return CMD_SUCCESS;
1391}
1392
paul718e3742002-12-13 20:15:29 +00001393/* Write IPv4 static route configuration. */
paula1ac18c2005-06-28 17:17:12 +00001394static int
Everton Marques33d86db2014-07-14 11:19:00 -03001395static_config_ipv4 (struct vty *vty, safi_t safi, const char *cmd)
paul718e3742002-12-13 20:15:29 +00001396{
1397 struct route_node *rn;
1398 struct static_ipv4 *si;
1399 struct route_table *stable;
Timo Teräs53a5c392015-05-23 11:08:40 +03001400 char buf[PREFIX_STRLEN];
paul718e3742002-12-13 20:15:29 +00001401 int write;
1402
1403 write = 0;
1404
1405 /* Lookup table. */
Feng Lu41f44a22015-05-22 11:39:56 +02001406 stable = zebra_vrf_static_table (AFI_IP, safi, VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +00001407 if (! stable)
1408 return -1;
1409
1410 for (rn = route_top (stable); rn; rn = route_next (rn))
1411 for (si = rn->info; si; si = si->next)
1412 {
Timo Teräs53a5c392015-05-23 11:08:40 +03001413 vty_out (vty, "%s %s", cmd, prefix2str (&rn->p, buf, sizeof buf));
paul718e3742002-12-13 20:15:29 +00001414
paul7021c422003-07-15 12:52:22 +00001415 switch (si->type)
1416 {
1417 case STATIC_IPV4_GATEWAY:
1418 vty_out (vty, " %s", inet_ntoa (si->gate.ipv4));
1419 break;
1420 case STATIC_IPV4_IFNAME:
1421 vty_out (vty, " %s", si->gate.ifname);
1422 break;
1423 case STATIC_IPV4_BLACKHOLE:
1424 vty_out (vty, " Null0");
1425 break;
1426 }
1427
1428 /* flags are incompatible with STATIC_IPV4_BLACKHOLE */
1429 if (si->type != STATIC_IPV4_BLACKHOLE)
1430 {
1431 if (CHECK_FLAG(si->flags, ZEBRA_FLAG_REJECT))
1432 vty_out (vty, " %s", "reject");
paul718e3742002-12-13 20:15:29 +00001433
paul7021c422003-07-15 12:52:22 +00001434 if (CHECK_FLAG(si->flags, ZEBRA_FLAG_BLACKHOLE))
1435 vty_out (vty, " %s", "blackhole");
1436 }
hasso81dfcaa2003-05-25 19:21:25 +00001437
paul7021c422003-07-15 12:52:22 +00001438 if (si->distance != ZEBRA_STATIC_DISTANCE_DEFAULT)
1439 vty_out (vty, " %d", si->distance);
hasso81dfcaa2003-05-25 19:21:25 +00001440
paul7021c422003-07-15 12:52:22 +00001441 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001442
paul7021c422003-07-15 12:52:22 +00001443 write = 1;
paul718e3742002-12-13 20:15:29 +00001444 }
1445 return write;
1446}
Andrew J. Schorr09303312007-05-30 20:10:34 +00001447
1448DEFUN (show_ip_protocol,
1449 show_ip_protocol_cmd,
1450 "show ip protocol",
1451 SHOW_STR
1452 IP_STR
1453 "IP protocol filtering status\n")
1454{
1455 int i;
1456
1457 vty_out(vty, "Protocol : route-map %s", VTY_NEWLINE);
1458 vty_out(vty, "------------------------%s", VTY_NEWLINE);
1459 for (i=0;i<ZEBRA_ROUTE_MAX;i++)
1460 {
1461 if (proto_rm[AFI_IP][i])
1462 vty_out (vty, "%-10s : %-10s%s", zebra_route_string(i),
1463 proto_rm[AFI_IP][i],
1464 VTY_NEWLINE);
1465 else
1466 vty_out (vty, "%-10s : none%s", zebra_route_string(i), VTY_NEWLINE);
1467 }
1468 if (proto_rm[AFI_IP][i])
1469 vty_out (vty, "%-10s : %-10s%s", "any", proto_rm[AFI_IP][i],
1470 VTY_NEWLINE);
1471 else
1472 vty_out (vty, "%-10s : none%s", "any", VTY_NEWLINE);
1473
1474 return CMD_SUCCESS;
1475}
1476
Joachim Nilsson36735ed2012-05-09 13:38:36 +02001477/*
1478 * Show IP mroute command to dump the BGP Multicast
1479 * routing table
1480 */
1481DEFUN (show_ip_mroute,
1482 show_ip_mroute_cmd,
1483 "show ip mroute",
1484 SHOW_STR
1485 IP_STR
1486 "IP Multicast routing table\n")
1487{
1488 struct route_table *table;
1489 struct route_node *rn;
1490 struct rib *rib;
1491 int first = 1;
1492
Feng Lu41f44a22015-05-22 11:39:56 +02001493 table = zebra_vrf_table (AFI_IP, SAFI_MULTICAST, VRF_DEFAULT);
Joachim Nilsson36735ed2012-05-09 13:38:36 +02001494 if (! table)
1495 return CMD_SUCCESS;
1496
1497 /* Show all IPv4 routes. */
1498 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001499 RNODE_FOREACH_RIB (rn, rib)
Joachim Nilsson36735ed2012-05-09 13:38:36 +02001500 {
1501 if (first)
1502 {
1503 vty_out (vty, SHOW_ROUTE_V4_HEADER);
1504 first = 0;
1505 }
1506 vty_show_ip_route (vty, rn, rib);
1507 }
1508 return CMD_SUCCESS;
1509}
1510
David Lamparter6b0655a2014-06-04 06:53:35 +02001511
paul718e3742002-12-13 20:15:29 +00001512#ifdef HAVE_IPV6
1513/* General fucntion for IPv6 static route. */
paula1ac18c2005-06-28 17:17:12 +00001514static int
hasso39db97e2004-10-12 20:50:58 +00001515static_ipv6_func (struct vty *vty, int add_cmd, const char *dest_str,
1516 const char *gate_str, const char *ifname,
1517 const char *flag_str, const char *distance_str)
paul718e3742002-12-13 20:15:29 +00001518{
1519 int ret;
1520 u_char distance;
1521 struct prefix p;
1522 struct in6_addr *gate = NULL;
1523 struct in6_addr gate_addr;
1524 u_char type = 0;
1525 int table = 0;
hasso81dfcaa2003-05-25 19:21:25 +00001526 u_char flag = 0;
paul718e3742002-12-13 20:15:29 +00001527
1528 ret = str2prefix (dest_str, &p);
1529 if (ret <= 0)
1530 {
1531 vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
1532 return CMD_WARNING;
1533 }
1534
1535 /* Apply mask for given prefix. */
1536 apply_mask (&p);
1537
hasso81dfcaa2003-05-25 19:21:25 +00001538 /* Route flags */
1539 if (flag_str) {
1540 switch(flag_str[0]) {
1541 case 'r':
1542 case 'R': /* XXX */
1543 SET_FLAG (flag, ZEBRA_FLAG_REJECT);
1544 break;
1545 case 'b':
1546 case 'B': /* XXX */
1547 SET_FLAG (flag, ZEBRA_FLAG_BLACKHOLE);
1548 break;
1549 default:
1550 vty_out (vty, "%% Malformed flag %s %s", flag_str, VTY_NEWLINE);
paul595db7f2003-05-25 21:35:06 +00001551 return CMD_WARNING;
hasso81dfcaa2003-05-25 19:21:25 +00001552 }
1553 }
1554
paul718e3742002-12-13 20:15:29 +00001555 /* Administrative distance. */
1556 if (distance_str)
1557 distance = atoi (distance_str);
1558 else
1559 distance = ZEBRA_STATIC_DISTANCE_DEFAULT;
1560
1561 /* When gateway is valid IPv6 addrees, then gate is treated as
1562 nexthop address other case gate is treated as interface name. */
1563 ret = inet_pton (AF_INET6, gate_str, &gate_addr);
1564
1565 if (ifname)
1566 {
1567 /* When ifname is specified. It must be come with gateway
1568 address. */
1569 if (ret != 1)
1570 {
1571 vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
1572 return CMD_WARNING;
1573 }
1574 type = STATIC_IPV6_GATEWAY_IFNAME;
1575 gate = &gate_addr;
1576 }
1577 else
1578 {
1579 if (ret == 1)
1580 {
1581 type = STATIC_IPV6_GATEWAY;
1582 gate = &gate_addr;
1583 }
1584 else
1585 {
1586 type = STATIC_IPV6_IFNAME;
1587 ifname = gate_str;
1588 }
1589 }
1590
1591 if (add_cmd)
hasso81dfcaa2003-05-25 19:21:25 +00001592 static_add_ipv6 (&p, type, gate, ifname, flag, distance, table);
paul718e3742002-12-13 20:15:29 +00001593 else
1594 static_delete_ipv6 (&p, type, gate, ifname, distance, table);
1595
1596 return CMD_SUCCESS;
1597}
1598
1599DEFUN (ipv6_route,
1600 ipv6_route_cmd,
1601 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE)",
1602 IP_STR
1603 "Establish static routes\n"
1604 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1605 "IPv6 gateway address\n"
1606 "IPv6 gateway interface name\n")
1607{
hasso81dfcaa2003-05-25 19:21:25 +00001608 return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, NULL, NULL);
1609}
1610
1611DEFUN (ipv6_route_flags,
1612 ipv6_route_flags_cmd,
1613 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole)",
1614 IP_STR
1615 "Establish static routes\n"
1616 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1617 "IPv6 gateway address\n"
1618 "IPv6 gateway interface name\n"
1619 "Emit an ICMP unreachable when matched\n"
1620 "Silently discard pkts when matched\n")
1621{
1622 return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, argv[2], NULL);
paul718e3742002-12-13 20:15:29 +00001623}
1624
1625DEFUN (ipv6_route_ifname,
1626 ipv6_route_ifname_cmd,
1627 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE",
1628 IP_STR
1629 "Establish static routes\n"
1630 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1631 "IPv6 gateway address\n"
1632 "IPv6 gateway interface name\n")
1633{
hasso81dfcaa2003-05-25 19:21:25 +00001634 return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], NULL, NULL);
1635}
1636
1637DEFUN (ipv6_route_ifname_flags,
1638 ipv6_route_ifname_flags_cmd,
1639 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole)",
1640 IP_STR
1641 "Establish static routes\n"
1642 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1643 "IPv6 gateway address\n"
1644 "IPv6 gateway interface name\n"
1645 "Emit an ICMP unreachable when matched\n"
1646 "Silently discard pkts when matched\n")
1647{
1648 return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], argv[3], NULL);
paul718e3742002-12-13 20:15:29 +00001649}
1650
1651DEFUN (ipv6_route_pref,
1652 ipv6_route_pref_cmd,
1653 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <1-255>",
1654 IP_STR
1655 "Establish static routes\n"
1656 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1657 "IPv6 gateway address\n"
1658 "IPv6 gateway interface name\n"
1659 "Distance value for this prefix\n")
1660{
hasso81dfcaa2003-05-25 19:21:25 +00001661 return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, NULL, argv[2]);
1662}
1663
1664DEFUN (ipv6_route_flags_pref,
1665 ipv6_route_flags_pref_cmd,
1666 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) <1-255>",
1667 IP_STR
1668 "Establish static routes\n"
1669 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1670 "IPv6 gateway address\n"
1671 "IPv6 gateway interface name\n"
1672 "Emit an ICMP unreachable when matched\n"
1673 "Silently discard pkts when matched\n"
1674 "Distance value for this prefix\n")
1675{
1676 return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, argv[2], argv[3]);
paul718e3742002-12-13 20:15:29 +00001677}
1678
1679DEFUN (ipv6_route_ifname_pref,
1680 ipv6_route_ifname_pref_cmd,
1681 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255>",
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 "Distance value for this prefix\n")
1688{
hasso81dfcaa2003-05-25 19:21:25 +00001689 return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], NULL, argv[3]);
1690}
1691
1692DEFUN (ipv6_route_ifname_flags_pref,
1693 ipv6_route_ifname_flags_pref_cmd,
1694 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) <1-255>",
1695 IP_STR
1696 "Establish static routes\n"
1697 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1698 "IPv6 gateway address\n"
1699 "IPv6 gateway interface name\n"
1700 "Emit an ICMP unreachable when matched\n"
1701 "Silently discard pkts when matched\n"
1702 "Distance value for this prefix\n")
1703{
1704 return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], argv[3], argv[4]);
paul718e3742002-12-13 20:15:29 +00001705}
1706
1707DEFUN (no_ipv6_route,
1708 no_ipv6_route_cmd,
1709 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE)",
1710 NO_STR
1711 IP_STR
1712 "Establish static routes\n"
1713 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1714 "IPv6 gateway address\n"
1715 "IPv6 gateway interface name\n")
1716{
hasso81dfcaa2003-05-25 19:21:25 +00001717 return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00001718}
1719
hasso81dfcaa2003-05-25 19:21:25 +00001720ALIAS (no_ipv6_route,
1721 no_ipv6_route_flags_cmd,
1722 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole)",
1723 NO_STR
1724 IP_STR
1725 "Establish static routes\n"
1726 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1727 "IPv6 gateway address\n"
1728 "IPv6 gateway interface name\n"
1729 "Emit an ICMP unreachable when matched\n"
1730 "Silently discard pkts when matched\n")
1731
paul718e3742002-12-13 20:15:29 +00001732DEFUN (no_ipv6_route_ifname,
1733 no_ipv6_route_ifname_cmd,
1734 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE",
1735 NO_STR
1736 IP_STR
1737 "Establish static routes\n"
1738 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1739 "IPv6 gateway address\n"
1740 "IPv6 gateway interface name\n")
1741{
hasso81dfcaa2003-05-25 19:21:25 +00001742 return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], NULL, NULL);
paul718e3742002-12-13 20:15:29 +00001743}
1744
hasso81dfcaa2003-05-25 19:21:25 +00001745ALIAS (no_ipv6_route_ifname,
1746 no_ipv6_route_ifname_flags_cmd,
1747 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole)",
1748 NO_STR
1749 IP_STR
1750 "Establish static routes\n"
1751 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1752 "IPv6 gateway address\n"
1753 "IPv6 gateway interface name\n"
1754 "Emit an ICMP unreachable when matched\n"
1755 "Silently discard pkts when matched\n")
1756
paul718e3742002-12-13 20:15:29 +00001757DEFUN (no_ipv6_route_pref,
1758 no_ipv6_route_pref_cmd,
1759 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <1-255>",
1760 NO_STR
1761 IP_STR
1762 "Establish static routes\n"
1763 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1764 "IPv6 gateway address\n"
1765 "IPv6 gateway interface name\n"
1766 "Distance value for this prefix\n")
1767{
hasso81dfcaa2003-05-25 19:21:25 +00001768 return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, NULL, argv[2]);
1769}
1770
1771DEFUN (no_ipv6_route_flags_pref,
1772 no_ipv6_route_flags_pref_cmd,
1773 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) <1-255>",
1774 NO_STR
1775 IP_STR
1776 "Establish static routes\n"
1777 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1778 "IPv6 gateway address\n"
1779 "IPv6 gateway interface name\n"
1780 "Emit an ICMP unreachable when matched\n"
1781 "Silently discard pkts when matched\n"
1782 "Distance value for this prefix\n")
1783{
1784 /* We do not care about argv[2] */
1785 return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, argv[2], argv[3]);
paul718e3742002-12-13 20:15:29 +00001786}
1787
1788DEFUN (no_ipv6_route_ifname_pref,
1789 no_ipv6_route_ifname_pref_cmd,
1790 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255>",
1791 NO_STR
1792 IP_STR
1793 "Establish static routes\n"
1794 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1795 "IPv6 gateway address\n"
1796 "IPv6 gateway interface name\n"
1797 "Distance value for this prefix\n")
1798{
hasso81dfcaa2003-05-25 19:21:25 +00001799 return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], NULL, argv[3]);
1800}
1801
1802DEFUN (no_ipv6_route_ifname_flags_pref,
1803 no_ipv6_route_ifname_flags_pref_cmd,
1804 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) <1-255>",
1805 NO_STR
1806 IP_STR
1807 "Establish static routes\n"
1808 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1809 "IPv6 gateway address\n"
1810 "IPv6 gateway interface name\n"
1811 "Emit an ICMP unreachable when matched\n"
1812 "Silently discard pkts when matched\n"
1813 "Distance value for this prefix\n")
1814{
1815 return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], argv[3], argv[4]);
paul718e3742002-12-13 20:15:29 +00001816}
1817
paul718e3742002-12-13 20:15:29 +00001818DEFUN (show_ipv6_route,
1819 show_ipv6_route_cmd,
1820 "show ipv6 route",
1821 SHOW_STR
1822 IP_STR
1823 "IPv6 routing table\n")
1824{
1825 struct route_table *table;
1826 struct route_node *rn;
1827 struct rib *rib;
1828 int first = 1;
1829
Feng Lu41f44a22015-05-22 11:39:56 +02001830 table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +00001831 if (! table)
1832 return CMD_SUCCESS;
1833
1834 /* Show all IPv6 route. */
1835 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001836 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +00001837 {
1838 if (first)
1839 {
David Lampartere0ca5fd2009-09-16 01:52:42 +02001840 vty_out (vty, SHOW_ROUTE_V6_HEADER);
paul718e3742002-12-13 20:15:29 +00001841 first = 0;
1842 }
Timo Teräs53a5c392015-05-23 11:08:40 +03001843 vty_show_ip_route (vty, rn, rib);
paul718e3742002-12-13 20:15:29 +00001844 }
1845 return CMD_SUCCESS;
1846}
1847
1848DEFUN (show_ipv6_route_prefix_longer,
1849 show_ipv6_route_prefix_longer_cmd,
1850 "show ipv6 route X:X::X:X/M longer-prefixes",
1851 SHOW_STR
1852 IP_STR
1853 "IPv6 routing table\n"
1854 "IPv6 prefix\n"
1855 "Show route matching the specified Network/Mask pair only\n")
1856{
1857 struct route_table *table;
1858 struct route_node *rn;
1859 struct rib *rib;
1860 struct prefix p;
1861 int ret;
1862 int first = 1;
1863
Feng Lu41f44a22015-05-22 11:39:56 +02001864 table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +00001865 if (! table)
1866 return CMD_SUCCESS;
1867
1868 ret = str2prefix (argv[0], &p);
1869 if (! ret)
1870 {
1871 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
1872 return CMD_WARNING;
1873 }
1874
1875 /* Show matched type IPv6 routes. */
1876 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001877 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +00001878 if (prefix_match (&p, &rn->p))
1879 {
1880 if (first)
1881 {
David Lampartere0ca5fd2009-09-16 01:52:42 +02001882 vty_out (vty, SHOW_ROUTE_V6_HEADER);
paul718e3742002-12-13 20:15:29 +00001883 first = 0;
1884 }
Timo Teräs53a5c392015-05-23 11:08:40 +03001885 vty_show_ip_route (vty, rn, rib);
paul718e3742002-12-13 20:15:29 +00001886 }
1887 return CMD_SUCCESS;
1888}
1889
1890DEFUN (show_ipv6_route_protocol,
1891 show_ipv6_route_protocol_cmd,
David Lampartere0ca5fd2009-09-16 01:52:42 +02001892 "show ipv6 route " QUAGGA_IP6_REDIST_STR_ZEBRA,
paul718e3742002-12-13 20:15:29 +00001893 SHOW_STR
1894 IP_STR
1895 "IP routing table\n"
David Lampartere0ca5fd2009-09-16 01:52:42 +02001896 QUAGGA_IP6_REDIST_HELP_STR_ZEBRA)
paul718e3742002-12-13 20:15:29 +00001897{
1898 int type;
1899 struct route_table *table;
1900 struct route_node *rn;
1901 struct rib *rib;
1902 int first = 1;
1903
David Lampartere0ca5fd2009-09-16 01:52:42 +02001904 type = proto_redistnum (AFI_IP6, argv[0]);
1905 if (type < 0)
paul718e3742002-12-13 20:15:29 +00001906 {
1907 vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
1908 return CMD_WARNING;
1909 }
1910
Feng Lu41f44a22015-05-22 11:39:56 +02001911 table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +00001912 if (! table)
1913 return CMD_SUCCESS;
1914
1915 /* Show matched type IPv6 routes. */
1916 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001917 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +00001918 if (rib->type == type)
1919 {
1920 if (first)
1921 {
David Lampartere0ca5fd2009-09-16 01:52:42 +02001922 vty_out (vty, SHOW_ROUTE_V6_HEADER);
paul718e3742002-12-13 20:15:29 +00001923 first = 0;
1924 }
Timo Teräs53a5c392015-05-23 11:08:40 +03001925 vty_show_ip_route (vty, rn, rib);
paul718e3742002-12-13 20:15:29 +00001926 }
1927 return CMD_SUCCESS;
1928}
1929
1930DEFUN (show_ipv6_route_addr,
1931 show_ipv6_route_addr_cmd,
1932 "show ipv6 route X:X::X:X",
1933 SHOW_STR
1934 IP_STR
1935 "IPv6 routing table\n"
1936 "IPv6 Address\n")
1937{
1938 int ret;
1939 struct prefix_ipv6 p;
1940 struct route_table *table;
1941 struct route_node *rn;
1942
1943 ret = str2prefix_ipv6 (argv[0], &p);
1944 if (ret <= 0)
1945 {
1946 vty_out (vty, "Malformed IPv6 address%s", VTY_NEWLINE);
1947 return CMD_WARNING;
1948 }
1949
Feng Lu41f44a22015-05-22 11:39:56 +02001950 table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +00001951 if (! table)
1952 return CMD_SUCCESS;
1953
1954 rn = route_node_match (table, (struct prefix *) &p);
1955 if (! rn)
1956 {
1957 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
1958 return CMD_WARNING;
1959 }
1960
Timo Teräs53a5c392015-05-23 11:08:40 +03001961 vty_show_ip_route_detail (vty, rn, 0);
paul718e3742002-12-13 20:15:29 +00001962
1963 route_unlock_node (rn);
1964
1965 return CMD_SUCCESS;
1966}
1967
1968DEFUN (show_ipv6_route_prefix,
1969 show_ipv6_route_prefix_cmd,
1970 "show ipv6 route X:X::X:X/M",
1971 SHOW_STR
1972 IP_STR
1973 "IPv6 routing table\n"
1974 "IPv6 prefix\n")
1975{
1976 int ret;
1977 struct prefix_ipv6 p;
1978 struct route_table *table;
1979 struct route_node *rn;
1980
1981 ret = str2prefix_ipv6 (argv[0], &p);
1982 if (ret <= 0)
1983 {
1984 vty_out (vty, "Malformed IPv6 prefix%s", VTY_NEWLINE);
1985 return CMD_WARNING;
1986 }
1987
Feng Lu41f44a22015-05-22 11:39:56 +02001988 table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +00001989 if (! table)
1990 return CMD_SUCCESS;
1991
1992 rn = route_node_match (table, (struct prefix *) &p);
1993 if (! rn || rn->p.prefixlen != p.prefixlen)
1994 {
1995 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
Lu Feng969d3552014-10-21 06:24:07 +00001996 if (rn)
1997 route_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00001998 return CMD_WARNING;
1999 }
2000
Timo Teräs53a5c392015-05-23 11:08:40 +03002001 vty_show_ip_route_detail (vty, rn, 0);
paul718e3742002-12-13 20:15:29 +00002002
2003 route_unlock_node (rn);
2004
2005 return CMD_SUCCESS;
2006}
2007
Stig Thormodsrud61691c92008-11-04 15:45:07 -08002008/* Show route summary. */
2009DEFUN (show_ipv6_route_summary,
2010 show_ipv6_route_summary_cmd,
2011 "show ipv6 route summary",
2012 SHOW_STR
2013 IP_STR
2014 "IPv6 routing table\n"
2015 "Summary of all IPv6 routes\n")
2016{
2017 struct route_table *table;
2018
Feng Lu41f44a22015-05-22 11:39:56 +02002019 table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
Stig Thormodsrud61691c92008-11-04 15:45:07 -08002020 if (! table)
2021 return CMD_SUCCESS;
2022
2023 vty_show_ip_route_summary (vty, table);
2024
2025 return CMD_SUCCESS;
2026}
2027
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07002028/* Show ipv6 route summary prefix. */
2029DEFUN (show_ipv6_route_summary_prefix,
2030 show_ipv6_route_summary_prefix_cmd,
2031 "show ipv6 route summary prefix",
2032 SHOW_STR
2033 IP_STR
2034 "IPv6 routing table\n"
2035 "Summary of all IPv6 routes\n"
2036 "Prefix routes\n")
2037{
2038 struct route_table *table;
2039
Feng Lu41f44a22015-05-22 11:39:56 +02002040 table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07002041 if (! table)
2042 return CMD_SUCCESS;
2043
2044 vty_show_ip_route_summary_prefix (vty, table);
2045
2046 return CMD_SUCCESS;
2047}
2048
G.Balajicddf3912011-11-26 21:59:32 +04002049/*
G.Balajicddf3912011-11-26 21:59:32 +04002050 * Show IPv6 mroute command.Used to dump
2051 * the Multicast routing table.
2052 */
2053
2054DEFUN (show_ipv6_mroute,
2055 show_ipv6_mroute_cmd,
2056 "show ipv6 mroute",
2057 SHOW_STR
2058 IP_STR
2059 "IPv6 Multicast routing table\n")
2060{
2061 struct route_table *table;
2062 struct route_node *rn;
2063 struct rib *rib;
2064 int first = 1;
2065
Feng Lu41f44a22015-05-22 11:39:56 +02002066 table = zebra_vrf_table (AFI_IP6, SAFI_MULTICAST, VRF_DEFAULT);
G.Balajicddf3912011-11-26 21:59:32 +04002067 if (! table)
2068 return CMD_SUCCESS;
2069
2070 /* Show all IPv6 route. */
2071 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00002072 RNODE_FOREACH_RIB (rn, rib)
G.Balajicddf3912011-11-26 21:59:32 +04002073 {
2074 if (first)
2075 {
G.Balajicb32fd62011-11-27 20:09:40 +05302076 vty_out (vty, SHOW_ROUTE_V6_HEADER);
G.Balajicddf3912011-11-26 21:59:32 +04002077 first = 0;
2078 }
Timo Teräs53a5c392015-05-23 11:08:40 +03002079 vty_show_ip_route (vty, rn, rib);
G.Balajicddf3912011-11-26 21:59:32 +04002080 }
2081 return CMD_SUCCESS;
2082}
2083
paul718e3742002-12-13 20:15:29 +00002084/* Write IPv6 static route configuration. */
paula1ac18c2005-06-28 17:17:12 +00002085static int
paul718e3742002-12-13 20:15:29 +00002086static_config_ipv6 (struct vty *vty)
2087{
2088 struct route_node *rn;
2089 struct static_ipv6 *si;
2090 int write;
2091 char buf[BUFSIZ];
2092 struct route_table *stable;
2093
2094 write = 0;
2095
2096 /* Lookup table. */
Feng Lu41f44a22015-05-22 11:39:56 +02002097 stable = zebra_vrf_static_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +00002098 if (! stable)
2099 return -1;
2100
2101 for (rn = route_top (stable); rn; rn = route_next (rn))
2102 for (si = rn->info; si; si = si->next)
2103 {
Timo Teräs53a5c392015-05-23 11:08:40 +03002104 vty_out (vty, "ipv6 route %s", prefix2str (&rn->p, buf, sizeof buf));
paul718e3742002-12-13 20:15:29 +00002105
2106 switch (si->type)
2107 {
2108 case STATIC_IPV6_GATEWAY:
2109 vty_out (vty, " %s", inet_ntop (AF_INET6, &si->ipv6, buf, BUFSIZ));
2110 break;
2111 case STATIC_IPV6_IFNAME:
2112 vty_out (vty, " %s", si->ifname);
2113 break;
2114 case STATIC_IPV6_GATEWAY_IFNAME:
2115 vty_out (vty, " %s %s",
2116 inet_ntop (AF_INET6, &si->ipv6, buf, BUFSIZ), si->ifname);
2117 break;
2118 }
2119
hasso81dfcaa2003-05-25 19:21:25 +00002120 if (CHECK_FLAG(si->flags, ZEBRA_FLAG_REJECT))
2121 vty_out (vty, " %s", "reject");
2122
2123 if (CHECK_FLAG(si->flags, ZEBRA_FLAG_BLACKHOLE))
2124 vty_out (vty, " %s", "blackhole");
2125
paul718e3742002-12-13 20:15:29 +00002126 if (si->distance != ZEBRA_STATIC_DISTANCE_DEFAULT)
2127 vty_out (vty, " %d", si->distance);
2128 vty_out (vty, "%s", VTY_NEWLINE);
2129
2130 write = 1;
2131 }
2132 return write;
2133}
2134#endif /* HAVE_IPV6 */
2135
2136/* Static ip route configuration write function. */
paula1ac18c2005-06-28 17:17:12 +00002137static int
paul718e3742002-12-13 20:15:29 +00002138zebra_ip_config (struct vty *vty)
2139{
2140 int write = 0;
2141
Everton Marques33d86db2014-07-14 11:19:00 -03002142 write += static_config_ipv4 (vty, SAFI_UNICAST, "ip route");
2143 write += static_config_ipv4 (vty, SAFI_MULTICAST, "ip mroute");
paul718e3742002-12-13 20:15:29 +00002144#ifdef HAVE_IPV6
2145 write += static_config_ipv6 (vty);
2146#endif /* HAVE_IPV6 */
2147
2148 return write;
2149}
2150
David Lamparterbd078122015-01-06 19:53:24 +01002151static int config_write_vty(struct vty *vty)
2152{
Paul Jakma7514fb72007-05-02 16:05:35 +00002153 int i;
David Lamparterbd078122015-01-06 19:53:24 +01002154 enum multicast_mode ipv4_multicast_mode = multicast_mode_ipv4_get ();
2155
2156 if (ipv4_multicast_mode != MCAST_NO_CONFIG)
2157 vty_out (vty, "ip multicast rpf-lookup-mode %s%s",
2158 ipv4_multicast_mode == MCAST_URIB_ONLY ? "urib-only" :
2159 ipv4_multicast_mode == MCAST_MRIB_ONLY ? "mrib-only" :
2160 ipv4_multicast_mode == MCAST_MIX_MRIB_FIRST ? "mrib-then-urib" :
2161 ipv4_multicast_mode == MCAST_MIX_DISTANCE ? "lower-distance" :
2162 "longer-prefix",
2163 VTY_NEWLINE);
Paul Jakma7514fb72007-05-02 16:05:35 +00002164
2165 for (i=0;i<ZEBRA_ROUTE_MAX;i++)
2166 {
2167 if (proto_rm[AFI_IP][i])
2168 vty_out (vty, "ip protocol %s route-map %s%s", zebra_route_string(i),
2169 proto_rm[AFI_IP][i], VTY_NEWLINE);
2170 }
2171 if (proto_rm[AFI_IP][ZEBRA_ROUTE_MAX])
2172 vty_out (vty, "ip protocol %s route-map %s%s", "any",
2173 proto_rm[AFI_IP][ZEBRA_ROUTE_MAX], VTY_NEWLINE);
2174
2175 return 1;
2176}
2177
2178/* table node for protocol filtering */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -08002179static struct cmd_node protocol_node = { PROTOCOL_NODE, "", 1 };
Paul Jakma7514fb72007-05-02 16:05:35 +00002180
paul718e3742002-12-13 20:15:29 +00002181/* IP node for static routes. */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -08002182static struct cmd_node ip_node = { IP_NODE, "", 1 };
paul718e3742002-12-13 20:15:29 +00002183
2184/* Route VTY. */
2185void
paula1ac18c2005-06-28 17:17:12 +00002186zebra_vty_init (void)
paul718e3742002-12-13 20:15:29 +00002187{
2188 install_node (&ip_node, zebra_ip_config);
David Lamparterbd078122015-01-06 19:53:24 +01002189 install_node (&protocol_node, config_write_vty);
paul718e3742002-12-13 20:15:29 +00002190
Everton Marques33d86db2014-07-14 11:19:00 -03002191 install_element (CONFIG_NODE, &ip_mroute_cmd);
David Lampartera76681b2015-01-22 19:03:53 +01002192 install_element (CONFIG_NODE, &ip_mroute_dist_cmd);
Everton Marques33d86db2014-07-14 11:19:00 -03002193 install_element (CONFIG_NODE, &no_ip_mroute_cmd);
David Lampartera76681b2015-01-22 19:03:53 +01002194 install_element (CONFIG_NODE, &no_ip_mroute_dist_cmd);
David Lamparterbd078122015-01-06 19:53:24 +01002195 install_element (CONFIG_NODE, &ip_multicast_mode_cmd);
2196 install_element (CONFIG_NODE, &no_ip_multicast_mode_cmd);
2197 install_element (CONFIG_NODE, &no_ip_multicast_mode_noarg_cmd);
Paul Jakma7514fb72007-05-02 16:05:35 +00002198 install_element (CONFIG_NODE, &ip_protocol_cmd);
2199 install_element (CONFIG_NODE, &no_ip_protocol_cmd);
2200 install_element (VIEW_NODE, &show_ip_protocol_cmd);
2201 install_element (ENABLE_NODE, &show_ip_protocol_cmd);
paul718e3742002-12-13 20:15:29 +00002202 install_element (CONFIG_NODE, &ip_route_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002203 install_element (CONFIG_NODE, &ip_route_flags_cmd);
hasso457ef552003-05-28 12:02:15 +00002204 install_element (CONFIG_NODE, &ip_route_flags2_cmd);
paul718e3742002-12-13 20:15:29 +00002205 install_element (CONFIG_NODE, &ip_route_mask_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002206 install_element (CONFIG_NODE, &ip_route_mask_flags_cmd);
hasso457ef552003-05-28 12:02:15 +00002207 install_element (CONFIG_NODE, &ip_route_mask_flags2_cmd);
paul718e3742002-12-13 20:15:29 +00002208 install_element (CONFIG_NODE, &no_ip_route_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002209 install_element (CONFIG_NODE, &no_ip_route_flags_cmd);
hasso457ef552003-05-28 12:02:15 +00002210 install_element (CONFIG_NODE, &no_ip_route_flags2_cmd);
paul718e3742002-12-13 20:15:29 +00002211 install_element (CONFIG_NODE, &no_ip_route_mask_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002212 install_element (CONFIG_NODE, &no_ip_route_mask_flags_cmd);
hasso457ef552003-05-28 12:02:15 +00002213 install_element (CONFIG_NODE, &no_ip_route_mask_flags2_cmd);
paul718e3742002-12-13 20:15:29 +00002214 install_element (CONFIG_NODE, &ip_route_distance_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002215 install_element (CONFIG_NODE, &ip_route_flags_distance_cmd);
hasso457ef552003-05-28 12:02:15 +00002216 install_element (CONFIG_NODE, &ip_route_flags_distance2_cmd);
paul718e3742002-12-13 20:15:29 +00002217 install_element (CONFIG_NODE, &ip_route_mask_distance_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002218 install_element (CONFIG_NODE, &ip_route_mask_flags_distance_cmd);
hasso457ef552003-05-28 12:02:15 +00002219 install_element (CONFIG_NODE, &ip_route_mask_flags_distance2_cmd);
paul718e3742002-12-13 20:15:29 +00002220 install_element (CONFIG_NODE, &no_ip_route_distance_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002221 install_element (CONFIG_NODE, &no_ip_route_flags_distance_cmd);
hasso457ef552003-05-28 12:02:15 +00002222 install_element (CONFIG_NODE, &no_ip_route_flags_distance2_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002223 install_element (CONFIG_NODE, &no_ip_route_mask_flags_distance_cmd);
hasso457ef552003-05-28 12:02:15 +00002224 install_element (CONFIG_NODE, &no_ip_route_mask_flags_distance2_cmd);
paul718e3742002-12-13 20:15:29 +00002225
2226 install_element (VIEW_NODE, &show_ip_route_cmd);
2227 install_element (VIEW_NODE, &show_ip_route_addr_cmd);
2228 install_element (VIEW_NODE, &show_ip_route_prefix_cmd);
2229 install_element (VIEW_NODE, &show_ip_route_prefix_longer_cmd);
2230 install_element (VIEW_NODE, &show_ip_route_protocol_cmd);
2231 install_element (VIEW_NODE, &show_ip_route_supernets_cmd);
Stig Thormodsrud61691c92008-11-04 15:45:07 -08002232 install_element (VIEW_NODE, &show_ip_route_summary_cmd);
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07002233 install_element (VIEW_NODE, &show_ip_route_summary_prefix_cmd);
paul718e3742002-12-13 20:15:29 +00002234 install_element (ENABLE_NODE, &show_ip_route_cmd);
2235 install_element (ENABLE_NODE, &show_ip_route_addr_cmd);
2236 install_element (ENABLE_NODE, &show_ip_route_prefix_cmd);
2237 install_element (ENABLE_NODE, &show_ip_route_prefix_longer_cmd);
2238 install_element (ENABLE_NODE, &show_ip_route_protocol_cmd);
2239 install_element (ENABLE_NODE, &show_ip_route_supernets_cmd);
paul718e3742002-12-13 20:15:29 +00002240 install_element (ENABLE_NODE, &show_ip_route_summary_cmd);
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07002241 install_element (ENABLE_NODE, &show_ip_route_summary_prefix_cmd);
paul718e3742002-12-13 20:15:29 +00002242
G.Balajicddf3912011-11-26 21:59:32 +04002243 install_element (VIEW_NODE, &show_ip_mroute_cmd);
2244 install_element (ENABLE_NODE, &show_ip_mroute_cmd);
2245
Everton Marques33d86db2014-07-14 11:19:00 -03002246 install_element (VIEW_NODE, &show_ip_rpf_cmd);
2247 install_element (ENABLE_NODE, &show_ip_rpf_cmd);
David Lamparter3b02fe82015-01-22 19:12:35 +01002248 install_element (VIEW_NODE, &show_ip_rpf_addr_cmd);
2249 install_element (ENABLE_NODE, &show_ip_rpf_addr_cmd);
G.Balajicddf3912011-11-26 21:59:32 +04002250
paul718e3742002-12-13 20:15:29 +00002251#ifdef HAVE_IPV6
2252 install_element (CONFIG_NODE, &ipv6_route_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002253 install_element (CONFIG_NODE, &ipv6_route_flags_cmd);
paul718e3742002-12-13 20:15:29 +00002254 install_element (CONFIG_NODE, &ipv6_route_ifname_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002255 install_element (CONFIG_NODE, &ipv6_route_ifname_flags_cmd);
paul718e3742002-12-13 20:15:29 +00002256 install_element (CONFIG_NODE, &no_ipv6_route_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002257 install_element (CONFIG_NODE, &no_ipv6_route_flags_cmd);
paul718e3742002-12-13 20:15:29 +00002258 install_element (CONFIG_NODE, &no_ipv6_route_ifname_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002259 install_element (CONFIG_NODE, &no_ipv6_route_ifname_flags_cmd);
paul718e3742002-12-13 20:15:29 +00002260 install_element (CONFIG_NODE, &ipv6_route_pref_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002261 install_element (CONFIG_NODE, &ipv6_route_flags_pref_cmd);
paul718e3742002-12-13 20:15:29 +00002262 install_element (CONFIG_NODE, &ipv6_route_ifname_pref_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002263 install_element (CONFIG_NODE, &ipv6_route_ifname_flags_pref_cmd);
paul718e3742002-12-13 20:15:29 +00002264 install_element (CONFIG_NODE, &no_ipv6_route_pref_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002265 install_element (CONFIG_NODE, &no_ipv6_route_flags_pref_cmd);
paul718e3742002-12-13 20:15:29 +00002266 install_element (CONFIG_NODE, &no_ipv6_route_ifname_pref_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002267 install_element (CONFIG_NODE, &no_ipv6_route_ifname_flags_pref_cmd);
paul718e3742002-12-13 20:15:29 +00002268 install_element (VIEW_NODE, &show_ipv6_route_cmd);
Stig Thormodsrud61691c92008-11-04 15:45:07 -08002269 install_element (VIEW_NODE, &show_ipv6_route_summary_cmd);
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07002270 install_element (VIEW_NODE, &show_ipv6_route_summary_prefix_cmd);
paul718e3742002-12-13 20:15:29 +00002271 install_element (VIEW_NODE, &show_ipv6_route_protocol_cmd);
2272 install_element (VIEW_NODE, &show_ipv6_route_addr_cmd);
2273 install_element (VIEW_NODE, &show_ipv6_route_prefix_cmd);
2274 install_element (VIEW_NODE, &show_ipv6_route_prefix_longer_cmd);
2275 install_element (ENABLE_NODE, &show_ipv6_route_cmd);
2276 install_element (ENABLE_NODE, &show_ipv6_route_protocol_cmd);
2277 install_element (ENABLE_NODE, &show_ipv6_route_addr_cmd);
2278 install_element (ENABLE_NODE, &show_ipv6_route_prefix_cmd);
2279 install_element (ENABLE_NODE, &show_ipv6_route_prefix_longer_cmd);
Stig Thormodsrud61691c92008-11-04 15:45:07 -08002280 install_element (ENABLE_NODE, &show_ipv6_route_summary_cmd);
Dinesh G Dutt56a5f772014-09-30 12:58:04 -07002281 install_element (ENABLE_NODE, &show_ipv6_route_summary_prefix_cmd);
G.Balajicddf3912011-11-26 21:59:32 +04002282
2283 install_element (VIEW_NODE, &show_ipv6_mroute_cmd);
2284 install_element (ENABLE_NODE, &show_ipv6_mroute_cmd);
paul718e3742002-12-13 20:15:29 +00002285#endif /* HAVE_IPV6 */
2286}