blob: a672d42224726a8aea941bbfa34b411e84a5167d [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
paul718e3742002-12-13 20:15:29 +000033/* General fucntion for static route. */
paula1ac18c2005-06-28 17:17:12 +000034static int
hasso39db97e2004-10-12 20:50:58 +000035zebra_static_ipv4 (struct vty *vty, int add_cmd, const char *dest_str,
36 const char *mask_str, const char *gate_str,
37 const char *flag_str, const char *distance_str)
paul718e3742002-12-13 20:15:29 +000038{
39 int ret;
40 u_char distance;
41 struct prefix p;
42 struct in_addr gate;
43 struct in_addr mask;
hasso39db97e2004-10-12 20:50:58 +000044 const char *ifname;
hasso81dfcaa2003-05-25 19:21:25 +000045 u_char flag = 0;
paul718e3742002-12-13 20:15:29 +000046
47 ret = str2prefix (dest_str, &p);
48 if (ret <= 0)
49 {
50 vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
51 return CMD_WARNING;
52 }
53
54 /* Cisco like mask notation. */
55 if (mask_str)
56 {
57 ret = inet_aton (mask_str, &mask);
58 if (ret == 0)
paul595db7f2003-05-25 21:35:06 +000059 {
60 vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
61 return CMD_WARNING;
62 }
paul718e3742002-12-13 20:15:29 +000063 p.prefixlen = ip_masklen (mask);
64 }
65
66 /* Apply mask for given prefix. */
67 apply_mask (&p);
68
paul595db7f2003-05-25 21:35:06 +000069 /* Administrative distance. */
70 if (distance_str)
71 distance = atoi (distance_str);
72 else
73 distance = ZEBRA_STATIC_DISTANCE_DEFAULT;
74
75 /* Null0 static route. */
hasso457ef552003-05-28 12:02:15 +000076 if ((gate_str != NULL) && (strncasecmp (gate_str, "Null0", strlen (gate_str)) == 0))
paul595db7f2003-05-25 21:35:06 +000077 {
78 if (flag_str)
79 {
80 vty_out (vty, "%% can not have flag %s with Null0%s", flag_str, VTY_NEWLINE);
81 return CMD_WARNING;
82 }
83 if (add_cmd)
paul7021c422003-07-15 12:52:22 +000084 static_add_ipv4 (&p, NULL, NULL, ZEBRA_FLAG_BLACKHOLE, distance, 0);
paul595db7f2003-05-25 21:35:06 +000085 else
86 static_delete_ipv4 (&p, NULL, NULL, distance, 0);
87 return CMD_SUCCESS;
88 }
89
hasso81dfcaa2003-05-25 19:21:25 +000090 /* Route flags */
91 if (flag_str) {
92 switch(flag_str[0]) {
93 case 'r':
94 case 'R': /* XXX */
95 SET_FLAG (flag, ZEBRA_FLAG_REJECT);
96 break;
97 case 'b':
98 case 'B': /* XXX */
99 SET_FLAG (flag, ZEBRA_FLAG_BLACKHOLE);
100 break;
101 default:
102 vty_out (vty, "%% Malformed flag %s %s", flag_str, VTY_NEWLINE);
paul595db7f2003-05-25 21:35:06 +0000103 return CMD_WARNING;
hasso81dfcaa2003-05-25 19:21:25 +0000104 }
105 }
106
hasso457ef552003-05-28 12:02:15 +0000107 if (gate_str == NULL)
108 {
109 if (add_cmd)
110 static_add_ipv4 (&p, NULL, NULL, flag, distance, 0);
111 else
112 static_delete_ipv4 (&p, NULL, NULL, distance, 0);
113
114 return CMD_SUCCESS;
115 }
116
paul718e3742002-12-13 20:15:29 +0000117 /* When gateway is A.B.C.D format, gate is treated as nexthop
118 address other case gate is treated as interface name. */
119 ret = inet_aton (gate_str, &gate);
120 if (ret)
121 ifname = NULL;
122 else
123 ifname = gate_str;
124
125 if (add_cmd)
hasso81dfcaa2003-05-25 19:21:25 +0000126 static_add_ipv4 (&p, ifname ? NULL : &gate, ifname, flag, distance, 0);
paul718e3742002-12-13 20:15:29 +0000127 else
128 static_delete_ipv4 (&p, ifname ? NULL : &gate, ifname, distance, 0);
129
130 return CMD_SUCCESS;
131}
132
133/* Static route configuration. */
134DEFUN (ip_route,
135 ip_route_cmd,
paul595db7f2003-05-25 21:35:06 +0000136 "ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0)",
hasso81dfcaa2003-05-25 19:21:25 +0000137 IP_STR
138 "Establish static routes\n"
139 "IP destination prefix (e.g. 10.0.0.0/8)\n"
140 "IP gateway address\n"
paul595db7f2003-05-25 21:35:06 +0000141 "IP gateway interface name\n"
142 "Null interface\n")
hasso81dfcaa2003-05-25 19:21:25 +0000143{
144 return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], NULL, NULL);
145}
146
147DEFUN (ip_route_flags,
148 ip_route_flags_cmd,
149 "ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole)",
paul718e3742002-12-13 20:15:29 +0000150 IP_STR
151 "Establish static routes\n"
152 "IP destination prefix (e.g. 10.0.0.0/8)\n"
153 "IP gateway address\n"
154 "IP gateway interface name\n"
hasso81dfcaa2003-05-25 19:21:25 +0000155 "Emit an ICMP unreachable when matched\n"
156 "Silently discard pkts when matched\n")
paul718e3742002-12-13 20:15:29 +0000157{
hasso81dfcaa2003-05-25 19:21:25 +0000158 return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], argv[2], NULL);
paul718e3742002-12-13 20:15:29 +0000159}
160
hasso457ef552003-05-28 12:02:15 +0000161DEFUN (ip_route_flags2,
162 ip_route_flags2_cmd,
163 "ip route A.B.C.D/M (reject|blackhole)",
164 IP_STR
165 "Establish static routes\n"
166 "IP destination prefix (e.g. 10.0.0.0/8)\n"
167 "Emit an ICMP unreachable when matched\n"
168 "Silently discard pkts when matched\n")
169{
170 return zebra_static_ipv4 (vty, 1, argv[0], NULL, NULL, argv[1], NULL);
171}
172
paul718e3742002-12-13 20:15:29 +0000173/* Mask as A.B.C.D format. */
174DEFUN (ip_route_mask,
175 ip_route_mask_cmd,
paul595db7f2003-05-25 21:35:06 +0000176 "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0)",
hasso81dfcaa2003-05-25 19:21:25 +0000177 IP_STR
178 "Establish static routes\n"
179 "IP destination prefix\n"
180 "IP destination prefix mask\n"
181 "IP gateway address\n"
paul595db7f2003-05-25 21:35:06 +0000182 "IP gateway interface name\n"
183 "Null interface\n")
hasso81dfcaa2003-05-25 19:21:25 +0000184{
185 return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], NULL, NULL);
186}
187
188DEFUN (ip_route_mask_flags,
189 ip_route_mask_flags_cmd,
190 "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole)",
paul718e3742002-12-13 20:15:29 +0000191 IP_STR
192 "Establish static routes\n"
193 "IP destination prefix\n"
194 "IP destination prefix mask\n"
195 "IP gateway address\n"
196 "IP gateway interface name\n"
hasso81dfcaa2003-05-25 19:21:25 +0000197 "Emit an ICMP unreachable when matched\n"
198 "Silently discard pkts when matched\n")
paul718e3742002-12-13 20:15:29 +0000199{
hasso81dfcaa2003-05-25 19:21:25 +0000200 return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], argv[3], NULL);
paul718e3742002-12-13 20:15:29 +0000201}
202
hasso457ef552003-05-28 12:02:15 +0000203DEFUN (ip_route_mask_flags2,
204 ip_route_mask_flags2_cmd,
205 "ip route A.B.C.D A.B.C.D (reject|blackhole)",
206 IP_STR
207 "Establish static routes\n"
208 "IP destination prefix\n"
209 "IP destination prefix mask\n"
210 "Emit an ICMP unreachable when matched\n"
211 "Silently discard pkts when matched\n")
212{
213 return zebra_static_ipv4 (vty, 1, argv[0], argv[1], NULL, argv[2], NULL);
214}
215
paul718e3742002-12-13 20:15:29 +0000216/* Distance option value. */
217DEFUN (ip_route_distance,
218 ip_route_distance_cmd,
paul595db7f2003-05-25 21:35:06 +0000219 "ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0) <1-255>",
paul718e3742002-12-13 20:15:29 +0000220 IP_STR
221 "Establish static routes\n"
222 "IP destination prefix (e.g. 10.0.0.0/8)\n"
223 "IP gateway address\n"
224 "IP gateway interface name\n"
paul595db7f2003-05-25 21:35:06 +0000225 "Null interface\n"
paul718e3742002-12-13 20:15:29 +0000226 "Distance value for this route\n")
227{
hasso81dfcaa2003-05-25 19:21:25 +0000228 return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], NULL, argv[2]);
229}
230
231DEFUN (ip_route_flags_distance,
232 ip_route_flags_distance_cmd,
233 "ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
234 IP_STR
235 "Establish static routes\n"
236 "IP destination prefix (e.g. 10.0.0.0/8)\n"
237 "IP gateway address\n"
238 "IP gateway interface name\n"
239 "Emit an ICMP unreachable when matched\n"
240 "Silently discard pkts when matched\n"
241 "Distance value for this route\n")
242{
243 return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], argv[2], argv[3]);
paul718e3742002-12-13 20:15:29 +0000244}
245
hasso457ef552003-05-28 12:02:15 +0000246DEFUN (ip_route_flags_distance2,
247 ip_route_flags_distance2_cmd,
248 "ip route A.B.C.D/M (reject|blackhole) <1-255>",
249 IP_STR
250 "Establish static routes\n"
251 "IP destination prefix (e.g. 10.0.0.0/8)\n"
252 "Emit an ICMP unreachable when matched\n"
253 "Silently discard pkts when matched\n"
254 "Distance value for this route\n")
255{
256 return zebra_static_ipv4 (vty, 1, argv[0], NULL, NULL, argv[1], argv[2]);
257}
258
paul718e3742002-12-13 20:15:29 +0000259DEFUN (ip_route_mask_distance,
260 ip_route_mask_distance_cmd,
paul595db7f2003-05-25 21:35:06 +0000261 "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0) <1-255>",
paul718e3742002-12-13 20:15:29 +0000262 IP_STR
263 "Establish static routes\n"
264 "IP destination prefix\n"
265 "IP destination prefix mask\n"
266 "IP gateway address\n"
267 "IP gateway interface name\n"
paul595db7f2003-05-25 21:35:06 +0000268 "Null interface\n"
paul718e3742002-12-13 20:15:29 +0000269 "Distance value for this route\n")
270{
hasso81dfcaa2003-05-25 19:21:25 +0000271 return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], NULL, argv[3]);
272}
273
274DEFUN (ip_route_mask_flags_distance,
275 ip_route_mask_flags_distance_cmd,
276 "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
277 IP_STR
278 "Establish static routes\n"
279 "IP destination prefix\n"
280 "IP destination prefix mask\n"
281 "IP gateway address\n"
282 "IP gateway interface name\n"
283 "Distance value for this route\n"
284 "Emit an ICMP unreachable when matched\n"
285 "Silently discard pkts when matched\n")
286{
287 return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], argv[3], argv[4]);
paul718e3742002-12-13 20:15:29 +0000288}
289
hasso457ef552003-05-28 12:02:15 +0000290DEFUN (ip_route_mask_flags_distance2,
291 ip_route_mask_flags_distance2_cmd,
292 "ip route A.B.C.D A.B.C.D (reject|blackhole) <1-255>",
293 IP_STR
294 "Establish static routes\n"
295 "IP destination prefix\n"
296 "IP destination prefix mask\n"
297 "Distance value for this route\n"
298 "Emit an ICMP unreachable when matched\n"
299 "Silently discard pkts when matched\n")
300{
301 return zebra_static_ipv4 (vty, 1, argv[0], argv[1], NULL, argv[2], argv[3]);
302}
303
paul718e3742002-12-13 20:15:29 +0000304DEFUN (no_ip_route,
305 no_ip_route_cmd,
paul595db7f2003-05-25 21:35:06 +0000306 "no ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0)",
hasso81dfcaa2003-05-25 19:21:25 +0000307 NO_STR
308 IP_STR
309 "Establish static routes\n"
310 "IP destination prefix (e.g. 10.0.0.0/8)\n"
311 "IP gateway address\n"
paul595db7f2003-05-25 21:35:06 +0000312 "IP gateway interface name\n"
313 "Null interface\n")
hasso81dfcaa2003-05-25 19:21:25 +0000314{
315 return zebra_static_ipv4 (vty, 0, argv[0], NULL, argv[1], NULL, NULL);
316}
317
318ALIAS (no_ip_route,
319 no_ip_route_flags_cmd,
320 "no ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole)",
paul718e3742002-12-13 20:15:29 +0000321 NO_STR
322 IP_STR
323 "Establish static routes\n"
324 "IP destination prefix (e.g. 10.0.0.0/8)\n"
325 "IP gateway address\n"
326 "IP gateway interface name\n"
hasso81dfcaa2003-05-25 19:21:25 +0000327 "Emit an ICMP unreachable when matched\n"
328 "Silently discard pkts when matched\n")
paul718e3742002-12-13 20:15:29 +0000329
hasso457ef552003-05-28 12:02:15 +0000330DEFUN (no_ip_route_flags2,
331 no_ip_route_flags2_cmd,
332 "no ip route A.B.C.D/M (reject|blackhole)",
333 NO_STR
334 IP_STR
335 "Establish static routes\n"
336 "IP destination prefix (e.g. 10.0.0.0/8)\n"
337 "Emit an ICMP unreachable when matched\n"
338 "Silently discard pkts when matched\n")
339{
340 return zebra_static_ipv4 (vty, 0, argv[0], NULL, NULL, NULL, NULL);
341}
342
paul718e3742002-12-13 20:15:29 +0000343DEFUN (no_ip_route_mask,
344 no_ip_route_mask_cmd,
paul595db7f2003-05-25 21:35:06 +0000345 "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0)",
hasso81dfcaa2003-05-25 19:21:25 +0000346 NO_STR
347 IP_STR
348 "Establish static routes\n"
349 "IP destination prefix\n"
350 "IP destination prefix mask\n"
351 "IP gateway address\n"
paul595db7f2003-05-25 21:35:06 +0000352 "IP gateway interface name\n"
353 "Null interface\n")
hasso81dfcaa2003-05-25 19:21:25 +0000354{
355 return zebra_static_ipv4 (vty, 0, argv[0], argv[1], argv[2], NULL, NULL);
356}
357
358ALIAS (no_ip_route_mask,
359 no_ip_route_mask_flags_cmd,
360 "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole)",
paul718e3742002-12-13 20:15:29 +0000361 NO_STR
362 IP_STR
363 "Establish static routes\n"
364 "IP destination prefix\n"
365 "IP destination prefix mask\n"
366 "IP gateway address\n"
367 "IP gateway interface name\n"
hasso81dfcaa2003-05-25 19:21:25 +0000368 "Emit an ICMP unreachable when matched\n"
369 "Silently discard pkts when matched\n")
paul718e3742002-12-13 20:15:29 +0000370
hasso457ef552003-05-28 12:02:15 +0000371DEFUN (no_ip_route_mask_flags2,
372 no_ip_route_mask_flags2_cmd,
373 "no ip route A.B.C.D A.B.C.D (reject|blackhole)",
374 NO_STR
375 IP_STR
376 "Establish static routes\n"
377 "IP destination prefix\n"
378 "IP destination prefix mask\n"
379 "Emit an ICMP unreachable when matched\n"
380 "Silently discard pkts when matched\n")
381{
382 return zebra_static_ipv4 (vty, 0, argv[0], argv[1], NULL, NULL, NULL);
383}
384
paul718e3742002-12-13 20:15:29 +0000385DEFUN (no_ip_route_distance,
386 no_ip_route_distance_cmd,
paul595db7f2003-05-25 21:35:06 +0000387 "no ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0) <1-255>",
paul718e3742002-12-13 20:15:29 +0000388 NO_STR
389 IP_STR
390 "Establish static routes\n"
391 "IP destination prefix (e.g. 10.0.0.0/8)\n"
392 "IP gateway address\n"
393 "IP gateway interface name\n"
paul595db7f2003-05-25 21:35:06 +0000394 "Null interface\n"
paul718e3742002-12-13 20:15:29 +0000395 "Distance value for this route\n")
396{
hasso81dfcaa2003-05-25 19:21:25 +0000397 return zebra_static_ipv4 (vty, 0, argv[0], NULL, argv[1], NULL, argv[2]);
398}
399
400DEFUN (no_ip_route_flags_distance,
401 no_ip_route_flags_distance_cmd,
402 "no ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
403 NO_STR
404 IP_STR
405 "Establish static routes\n"
406 "IP destination prefix (e.g. 10.0.0.0/8)\n"
407 "IP gateway address\n"
408 "IP gateway interface name\n"
409 "Emit an ICMP unreachable when matched\n"
410 "Silently discard pkts when matched\n"
411 "Distance value for this route\n")
412{
413 return zebra_static_ipv4 (vty, 0, argv[0], NULL, argv[1], argv[2], argv[3]);
paul718e3742002-12-13 20:15:29 +0000414}
415
hasso457ef552003-05-28 12:02:15 +0000416DEFUN (no_ip_route_flags_distance2,
417 no_ip_route_flags_distance2_cmd,
418 "no ip route A.B.C.D/M (reject|blackhole) <1-255>",
419 NO_STR
420 IP_STR
421 "Establish static routes\n"
422 "IP destination prefix (e.g. 10.0.0.0/8)\n"
423 "Emit an ICMP unreachable when matched\n"
424 "Silently discard pkts when matched\n"
425 "Distance value for this route\n")
426{
427 return zebra_static_ipv4 (vty, 0, argv[0], NULL, NULL, argv[1], argv[2]);
428}
429
paul718e3742002-12-13 20:15:29 +0000430DEFUN (no_ip_route_mask_distance,
431 no_ip_route_mask_distance_cmd,
paul595db7f2003-05-25 21:35:06 +0000432 "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 +0000433 NO_STR
434 IP_STR
435 "Establish static routes\n"
436 "IP destination prefix\n"
437 "IP destination prefix mask\n"
438 "IP gateway address\n"
439 "IP gateway interface name\n"
paul595db7f2003-05-25 21:35:06 +0000440 "Null interface\n"
paul718e3742002-12-13 20:15:29 +0000441 "Distance value for this route\n")
442{
hasso81dfcaa2003-05-25 19:21:25 +0000443 return zebra_static_ipv4 (vty, 0, argv[0], argv[1], argv[2], NULL, argv[3]);
444}
445
446DEFUN (no_ip_route_mask_flags_distance,
447 no_ip_route_mask_flags_distance_cmd,
448 "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
449 NO_STR
450 IP_STR
451 "Establish static routes\n"
452 "IP destination prefix\n"
453 "IP destination prefix mask\n"
454 "IP gateway address\n"
455 "IP gateway interface name\n"
456 "Emit an ICMP unreachable when matched\n"
457 "Silently discard pkts when matched\n"
458 "Distance value for this route\n")
459{
460 return zebra_static_ipv4 (vty, 0, argv[0], argv[1], argv[2], argv[3], argv[4]);
paul718e3742002-12-13 20:15:29 +0000461}
462
hasso457ef552003-05-28 12:02:15 +0000463DEFUN (no_ip_route_mask_flags_distance2,
464 no_ip_route_mask_flags_distance2_cmd,
465 "no ip route A.B.C.D A.B.C.D (reject|blackhole) <1-255>",
466 NO_STR
467 IP_STR
468 "Establish static routes\n"
469 "IP destination prefix\n"
470 "IP destination prefix mask\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], argv[1], NULL, argv[2], argv[3]);
476}
477
Paul Jakma7514fb72007-05-02 16:05:35 +0000478char *proto_rm[AFI_MAX][ZEBRA_ROUTE_MAX+1]; /* "any" == ZEBRA_ROUTE_MAX */
479
480DEFUN (ip_protocol,
481 ip_protocol_cmd,
482 "ip protocol PROTO route-map ROUTE-MAP",
483 NO_STR
484 "Apply route map to PROTO\n"
485 "Protocol name\n"
486 "Route map name\n")
487{
488 int i;
489
490 if (strcasecmp(argv[0], "any") == 0)
491 i = ZEBRA_ROUTE_MAX;
492 else
493 i = proto_name2num(argv[0]);
494 if (i < 0)
495 {
496 vty_out (vty, "invalid protocol name \"%s\"%s", argv[0] ? argv[0] : "",
497 VTY_NEWLINE);
498 return CMD_WARNING;
499 }
500 if (proto_rm[AFI_IP][i])
501 XFREE (MTYPE_ROUTE_MAP_NAME, proto_rm[AFI_IP][i]);
502 proto_rm[AFI_IP][i] = XSTRDUP (MTYPE_ROUTE_MAP_NAME, argv[1]);
503 return CMD_SUCCESS;
504}
505
506DEFUN (no_ip_protocol,
507 no_ip_protocol_cmd,
508 "no ip protocol PROTO",
509 NO_STR
510 "Remove route map from PROTO\n"
511 "Protocol name\n")
512{
513 int i;
514
515 if (strcasecmp(argv[0], "any") == 0)
516 i = ZEBRA_ROUTE_MAX;
517 else
518 i = proto_name2num(argv[0]);
519 if (i < 0)
520 {
521 vty_out (vty, "invalid protocol name \"%s\"%s", argv[0] ? argv[0] : "",
522 VTY_NEWLINE);
523 return CMD_WARNING;
524 }
525 if (proto_rm[AFI_IP][i])
526 XFREE (MTYPE_ROUTE_MAP_NAME, proto_rm[AFI_IP][i]);
527 proto_rm[AFI_IP][i] = NULL;
528 return CMD_SUCCESS;
529}
530
paul718e3742002-12-13 20:15:29 +0000531/* New RIB. Detailed information for IPv4 route. */
paula1ac18c2005-06-28 17:17:12 +0000532static void
paul718e3742002-12-13 20:15:29 +0000533vty_show_ip_route_detail (struct vty *vty, struct route_node *rn)
534{
535 struct rib *rib;
536 struct nexthop *nexthop;
537
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000538 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +0000539 {
540 vty_out (vty, "Routing entry for %s/%d%s",
541 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
542 VTY_NEWLINE);
ajsf52d13c2005-10-01 17:38:06 +0000543 vty_out (vty, " Known via \"%s\"", zebra_route_string (rib->type));
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +0200544 vty_out (vty, ", distance %u, metric %u", rib->distance, rib->metric);
paul718e3742002-12-13 20:15:29 +0000545 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
546 vty_out (vty, ", best");
547 if (rib->refcnt)
548 vty_out (vty, ", refcnt %ld", rib->refcnt);
hasso81dfcaa2003-05-25 19:21:25 +0000549 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
550 vty_out (vty, ", blackhole");
551 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT))
552 vty_out (vty, ", reject");
paul718e3742002-12-13 20:15:29 +0000553 vty_out (vty, "%s", VTY_NEWLINE);
554
555#define ONE_DAY_SECOND 60*60*24
556#define ONE_WEEK_SECOND 60*60*24*7
557 if (rib->type == ZEBRA_ROUTE_RIP
558 || rib->type == ZEBRA_ROUTE_OSPF
Juliusz Chroboczek578ce372012-02-09 13:42:28 +0100559 || rib->type == ZEBRA_ROUTE_BABEL
jardin9e867fe2003-12-23 08:56:18 +0000560 || rib->type == ZEBRA_ROUTE_ISIS
paul718e3742002-12-13 20:15:29 +0000561 || rib->type == ZEBRA_ROUTE_BGP)
562 {
563 time_t uptime;
564 struct tm *tm;
565
566 uptime = time (NULL);
567 uptime -= rib->uptime;
568 tm = gmtime (&uptime);
569
570 vty_out (vty, " Last update ");
571
572 if (uptime < ONE_DAY_SECOND)
573 vty_out (vty, "%02d:%02d:%02d",
574 tm->tm_hour, tm->tm_min, tm->tm_sec);
575 else if (uptime < ONE_WEEK_SECOND)
576 vty_out (vty, "%dd%02dh%02dm",
577 tm->tm_yday, tm->tm_hour, tm->tm_min);
578 else
579 vty_out (vty, "%02dw%dd%02dh",
580 tm->tm_yday/7,
581 tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
582 vty_out (vty, " ago%s", VTY_NEWLINE);
583 }
584
585 for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
586 {
Paul Jakma7514fb72007-05-02 16:05:35 +0000587 char addrstr[32];
588
paul718e3742002-12-13 20:15:29 +0000589 vty_out (vty, " %c",
590 CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB) ? '*' : ' ');
591
592 switch (nexthop->type)
593 {
594 case NEXTHOP_TYPE_IPV4:
595 case NEXTHOP_TYPE_IPV4_IFINDEX:
596 vty_out (vty, " %s", inet_ntoa (nexthop->gate.ipv4));
597 if (nexthop->ifindex)
598 vty_out (vty, ", via %s", ifindex2ifname (nexthop->ifindex));
599 break;
600 case NEXTHOP_TYPE_IFINDEX:
601 vty_out (vty, " directly connected, %s",
602 ifindex2ifname (nexthop->ifindex));
603 break;
604 case NEXTHOP_TYPE_IFNAME:
605 vty_out (vty, " directly connected, %s", nexthop->ifname);
606 break;
paul595db7f2003-05-25 21:35:06 +0000607 case NEXTHOP_TYPE_BLACKHOLE:
paul7021c422003-07-15 12:52:22 +0000608 vty_out (vty, " directly connected, Null0");
paul595db7f2003-05-25 21:35:06 +0000609 break;
paul7021c422003-07-15 12:52:22 +0000610 default:
paul718e3742002-12-13 20:15:29 +0000611 break;
612 }
613 if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
614 vty_out (vty, " inactive");
615
616 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
617 {
618 vty_out (vty, " (recursive");
619
620 switch (nexthop->rtype)
621 {
622 case NEXTHOP_TYPE_IPV4:
623 case NEXTHOP_TYPE_IPV4_IFINDEX:
Christian Franke5b9f5182013-05-25 14:01:34 +0000624 vty_out (vty, " via %s", inet_ntoa (nexthop->rgate.ipv4));
625 if (nexthop->rifindex)
626 vty_out (vty, ", %s", ifindex2ifname (nexthop->rifindex));
627 vty_out (vty, ")");
628
paul718e3742002-12-13 20:15:29 +0000629 break;
630 case NEXTHOP_TYPE_IFINDEX:
631 case NEXTHOP_TYPE_IFNAME:
632 vty_out (vty, " is directly connected, %s)",
633 ifindex2ifname (nexthop->rifindex));
634 break;
635 default:
636 break;
637 }
638 }
Paul Jakma7514fb72007-05-02 16:05:35 +0000639 switch (nexthop->type)
640 {
641 case NEXTHOP_TYPE_IPV4:
642 case NEXTHOP_TYPE_IPV4_IFINDEX:
643 case NEXTHOP_TYPE_IPV4_IFNAME:
644 if (nexthop->src.ipv4.s_addr)
645 {
646 if (inet_ntop(AF_INET, &nexthop->src.ipv4, addrstr,
647 sizeof addrstr))
648 vty_out (vty, ", src %s", addrstr);
649 }
650 break;
Andrew J. Schorr09303312007-05-30 20:10:34 +0000651#ifdef HAVE_IPV6
Paul Jakma7514fb72007-05-02 16:05:35 +0000652 case NEXTHOP_TYPE_IPV6:
653 case NEXTHOP_TYPE_IPV6_IFINDEX:
654 case NEXTHOP_TYPE_IPV6_IFNAME:
655 if (!IPV6_ADDR_SAME(&nexthop->src.ipv6, &in6addr_any))
656 {
657 if (inet_ntop(AF_INET6, &nexthop->src.ipv6, addrstr,
658 sizeof addrstr))
659 vty_out (vty, ", src %s", addrstr);
660 }
661 break;
Andrew J. Schorr09303312007-05-30 20:10:34 +0000662#endif /* HAVE_IPV6 */
Paul Jakma7514fb72007-05-02 16:05:35 +0000663 default:
664 break;
665 }
paul718e3742002-12-13 20:15:29 +0000666 vty_out (vty, "%s", VTY_NEWLINE);
667 }
668 vty_out (vty, "%s", VTY_NEWLINE);
669 }
670}
671
paula1ac18c2005-06-28 17:17:12 +0000672static void
paul718e3742002-12-13 20:15:29 +0000673vty_show_ip_route (struct vty *vty, struct route_node *rn, struct rib *rib)
674{
675 struct nexthop *nexthop;
676 int len = 0;
677 char buf[BUFSIZ];
678
679 /* Nexthop information. */
680 for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
681 {
682 if (nexthop == rib->nexthop)
683 {
684 /* Prefix information. */
685 len = vty_out (vty, "%c%c%c %s/%d",
ajsf52d13c2005-10-01 17:38:06 +0000686 zebra_route_char (rib->type),
paul718e3742002-12-13 20:15:29 +0000687 CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED)
688 ? '>' : ' ',
689 CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
690 ? '*' : ' ',
691 inet_ntop (AF_INET, &rn->p.u.prefix, buf, BUFSIZ),
692 rn->p.prefixlen);
693
694 /* Distance and metric display. */
695 if (rib->type != ZEBRA_ROUTE_CONNECT
696 && rib->type != ZEBRA_ROUTE_KERNEL)
697 len += vty_out (vty, " [%d/%d]", rib->distance,
698 rib->metric);
699 }
700 else
701 vty_out (vty, " %c%*c",
702 CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
703 ? '*' : ' ',
704 len - 3, ' ');
705
706 switch (nexthop->type)
707 {
708 case NEXTHOP_TYPE_IPV4:
709 case NEXTHOP_TYPE_IPV4_IFINDEX:
710 vty_out (vty, " via %s", inet_ntoa (nexthop->gate.ipv4));
711 if (nexthop->ifindex)
712 vty_out (vty, ", %s", ifindex2ifname (nexthop->ifindex));
713 break;
714 case NEXTHOP_TYPE_IFINDEX:
715 vty_out (vty, " is directly connected, %s",
716 ifindex2ifname (nexthop->ifindex));
717 break;
718 case NEXTHOP_TYPE_IFNAME:
719 vty_out (vty, " is directly connected, %s", nexthop->ifname);
720 break;
paul595db7f2003-05-25 21:35:06 +0000721 case NEXTHOP_TYPE_BLACKHOLE:
paul7021c422003-07-15 12:52:22 +0000722 vty_out (vty, " is directly connected, Null0");
paul595db7f2003-05-25 21:35:06 +0000723 break;
paul7021c422003-07-15 12:52:22 +0000724 default:
paul718e3742002-12-13 20:15:29 +0000725 break;
726 }
727 if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
728 vty_out (vty, " inactive");
729
730 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
731 {
732 vty_out (vty, " (recursive");
733
734 switch (nexthop->rtype)
735 {
736 case NEXTHOP_TYPE_IPV4:
737 case NEXTHOP_TYPE_IPV4_IFINDEX:
Christian Franke5b9f5182013-05-25 14:01:34 +0000738 vty_out (vty, " via %s", inet_ntoa (nexthop->rgate.ipv4));
739 if (nexthop->rifindex)
740 vty_out (vty, ", %s", ifindex2ifname (nexthop->rifindex));
741 vty_out (vty, ")");
paul718e3742002-12-13 20:15:29 +0000742 break;
743 case NEXTHOP_TYPE_IFINDEX:
744 case NEXTHOP_TYPE_IFNAME:
745 vty_out (vty, " is directly connected, %s)",
746 ifindex2ifname (nexthop->rifindex));
747 break;
748 default:
749 break;
750 }
751 }
Paul Jakma7514fb72007-05-02 16:05:35 +0000752 switch (nexthop->type)
753 {
754 case NEXTHOP_TYPE_IPV4:
755 case NEXTHOP_TYPE_IPV4_IFINDEX:
756 case NEXTHOP_TYPE_IPV4_IFNAME:
757 if (nexthop->src.ipv4.s_addr)
758 {
759 if (inet_ntop(AF_INET, &nexthop->src.ipv4, buf, sizeof buf))
760 vty_out (vty, ", src %s", buf);
761 }
762 break;
Andrew J. Schorr09303312007-05-30 20:10:34 +0000763#ifdef HAVE_IPV6
Paul Jakma7514fb72007-05-02 16:05:35 +0000764 case NEXTHOP_TYPE_IPV6:
765 case NEXTHOP_TYPE_IPV6_IFINDEX:
766 case NEXTHOP_TYPE_IPV6_IFNAME:
767 if (!IPV6_ADDR_SAME(&nexthop->src.ipv6, &in6addr_any))
768 {
769 if (inet_ntop(AF_INET6, &nexthop->src.ipv6, buf, sizeof buf))
770 vty_out (vty, ", src %s", buf);
771 }
772 break;
Andrew J. Schorr09303312007-05-30 20:10:34 +0000773#endif /* HAVE_IPV6 */
Paul Jakma7514fb72007-05-02 16:05:35 +0000774 default:
775 break;
776 }
paul718e3742002-12-13 20:15:29 +0000777
hasso81dfcaa2003-05-25 19:21:25 +0000778 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
779 vty_out (vty, ", bh");
780 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT))
781 vty_out (vty, ", rej");
782
paul718e3742002-12-13 20:15:29 +0000783 if (rib->type == ZEBRA_ROUTE_RIP
784 || rib->type == ZEBRA_ROUTE_OSPF
Juliusz Chroboczek578ce372012-02-09 13:42:28 +0100785 || rib->type == ZEBRA_ROUTE_BABEL
jardin9e867fe2003-12-23 08:56:18 +0000786 || rib->type == ZEBRA_ROUTE_ISIS
paul718e3742002-12-13 20:15:29 +0000787 || rib->type == ZEBRA_ROUTE_BGP)
788 {
789 time_t uptime;
790 struct tm *tm;
791
792 uptime = time (NULL);
793 uptime -= rib->uptime;
794 tm = gmtime (&uptime);
795
796#define ONE_DAY_SECOND 60*60*24
797#define ONE_WEEK_SECOND 60*60*24*7
798
799 if (uptime < ONE_DAY_SECOND)
800 vty_out (vty, ", %02d:%02d:%02d",
801 tm->tm_hour, tm->tm_min, tm->tm_sec);
802 else if (uptime < ONE_WEEK_SECOND)
803 vty_out (vty, ", %dd%02dh%02dm",
804 tm->tm_yday, tm->tm_hour, tm->tm_min);
805 else
806 vty_out (vty, ", %02dw%dd%02dh",
807 tm->tm_yday/7,
808 tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
809 }
810 vty_out (vty, "%s", VTY_NEWLINE);
811 }
812}
813
paul718e3742002-12-13 20:15:29 +0000814DEFUN (show_ip_route,
815 show_ip_route_cmd,
816 "show ip route",
817 SHOW_STR
818 IP_STR
819 "IP routing table\n")
820{
821 struct route_table *table;
822 struct route_node *rn;
823 struct rib *rib;
824 int first = 1;
825
826 table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
827 if (! table)
828 return CMD_SUCCESS;
829
830 /* Show all IPv4 routes. */
831 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000832 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +0000833 {
834 if (first)
835 {
David Lampartere0ca5fd2009-09-16 01:52:42 +0200836 vty_out (vty, SHOW_ROUTE_V4_HEADER);
paul718e3742002-12-13 20:15:29 +0000837 first = 0;
838 }
839 vty_show_ip_route (vty, rn, rib);
840 }
841 return CMD_SUCCESS;
842}
843
844DEFUN (show_ip_route_prefix_longer,
845 show_ip_route_prefix_longer_cmd,
846 "show ip route A.B.C.D/M longer-prefixes",
847 SHOW_STR
848 IP_STR
849 "IP routing table\n"
850 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
851 "Show route matching the specified Network/Mask pair only\n")
852{
853 struct route_table *table;
854 struct route_node *rn;
855 struct rib *rib;
856 struct prefix p;
857 int ret;
858 int first = 1;
859
860 ret = str2prefix (argv[0], &p);
861 if (! ret)
862 {
863 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
864 return CMD_WARNING;
865 }
866
867 table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
868 if (! table)
869 return CMD_SUCCESS;
870
871 /* Show matched type IPv4 routes. */
872 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000873 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +0000874 if (prefix_match (&p, &rn->p))
875 {
876 if (first)
877 {
David Lampartere0ca5fd2009-09-16 01:52:42 +0200878 vty_out (vty, SHOW_ROUTE_V4_HEADER);
paul718e3742002-12-13 20:15:29 +0000879 first = 0;
880 }
881 vty_show_ip_route (vty, rn, rib);
882 }
883 return CMD_SUCCESS;
884}
885
886DEFUN (show_ip_route_supernets,
887 show_ip_route_supernets_cmd,
888 "show ip route supernets-only",
889 SHOW_STR
890 IP_STR
891 "IP routing table\n"
892 "Show supernet entries only\n")
893{
894 struct route_table *table;
895 struct route_node *rn;
896 struct rib *rib;
897 u_int32_t addr;
898 int first = 1;
899
900 table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
901 if (! table)
902 return CMD_SUCCESS;
903
904 /* Show matched type IPv4 routes. */
905 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000906 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +0000907 {
908 addr = ntohl (rn->p.u.prefix4.s_addr);
909
910 if ((IN_CLASSC (addr) && rn->p.prefixlen < 24)
911 || (IN_CLASSB (addr) && rn->p.prefixlen < 16)
912 || (IN_CLASSA (addr) && rn->p.prefixlen < 8))
913 {
914 if (first)
915 {
David Lampartere0ca5fd2009-09-16 01:52:42 +0200916 vty_out (vty, SHOW_ROUTE_V4_HEADER);
paul718e3742002-12-13 20:15:29 +0000917 first = 0;
918 }
919 vty_show_ip_route (vty, rn, rib);
920 }
921 }
922 return CMD_SUCCESS;
923}
924
925DEFUN (show_ip_route_protocol,
926 show_ip_route_protocol_cmd,
David Lampartere0ca5fd2009-09-16 01:52:42 +0200927 "show ip route " QUAGGA_IP_REDIST_STR_ZEBRA,
paul718e3742002-12-13 20:15:29 +0000928 SHOW_STR
929 IP_STR
930 "IP routing table\n"
David Lampartere0ca5fd2009-09-16 01:52:42 +0200931 QUAGGA_IP_REDIST_HELP_STR_ZEBRA)
paul718e3742002-12-13 20:15:29 +0000932{
933 int type;
934 struct route_table *table;
935 struct route_node *rn;
936 struct rib *rib;
937 int first = 1;
938
David Lampartere0ca5fd2009-09-16 01:52:42 +0200939 type = proto_redistnum (AFI_IP, argv[0]);
940 if (type < 0)
paul718e3742002-12-13 20:15:29 +0000941 {
942 vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
943 return CMD_WARNING;
944 }
945
946 table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
947 if (! table)
948 return CMD_SUCCESS;
949
950 /* Show matched type IPv4 routes. */
951 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000952 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +0000953 if (rib->type == type)
954 {
955 if (first)
956 {
David Lampartere0ca5fd2009-09-16 01:52:42 +0200957 vty_out (vty, SHOW_ROUTE_V4_HEADER);
paul718e3742002-12-13 20:15:29 +0000958 first = 0;
959 }
960 vty_show_ip_route (vty, rn, rib);
961 }
962 return CMD_SUCCESS;
963}
964
965DEFUN (show_ip_route_addr,
966 show_ip_route_addr_cmd,
967 "show ip route A.B.C.D",
968 SHOW_STR
969 IP_STR
970 "IP routing table\n"
971 "Network in the IP routing table to display\n")
972{
973 int ret;
974 struct prefix_ipv4 p;
975 struct route_table *table;
976 struct route_node *rn;
977
978 ret = str2prefix_ipv4 (argv[0], &p);
979 if (ret <= 0)
980 {
981 vty_out (vty, "%% Malformed IPv4 address%s", VTY_NEWLINE);
982 return CMD_WARNING;
983 }
984
985 table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
986 if (! table)
987 return CMD_SUCCESS;
988
989 rn = route_node_match (table, (struct prefix *) &p);
990 if (! rn)
991 {
992 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
993 return CMD_WARNING;
994 }
995
996 vty_show_ip_route_detail (vty, rn);
997
998 route_unlock_node (rn);
999
1000 return CMD_SUCCESS;
1001}
1002
1003DEFUN (show_ip_route_prefix,
1004 show_ip_route_prefix_cmd,
1005 "show ip route A.B.C.D/M",
1006 SHOW_STR
1007 IP_STR
1008 "IP routing table\n"
1009 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
1010{
1011 int ret;
1012 struct prefix_ipv4 p;
1013 struct route_table *table;
1014 struct route_node *rn;
1015
1016 ret = str2prefix_ipv4 (argv[0], &p);
1017 if (ret <= 0)
1018 {
1019 vty_out (vty, "%% Malformed IPv4 address%s", VTY_NEWLINE);
1020 return CMD_WARNING;
1021 }
1022
1023 table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
1024 if (! table)
1025 return CMD_SUCCESS;
1026
1027 rn = route_node_match (table, (struct prefix *) &p);
1028 if (! rn || rn->p.prefixlen != p.prefixlen)
1029 {
1030 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
1031 return CMD_WARNING;
1032 }
1033
1034 vty_show_ip_route_detail (vty, rn);
1035
1036 route_unlock_node (rn);
1037
1038 return CMD_SUCCESS;
1039}
1040
paula1ac18c2005-06-28 17:17:12 +00001041static void
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001042vty_show_ip_route_summary (struct vty *vty, struct route_table *table)
paul718e3742002-12-13 20:15:29 +00001043{
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001044 struct route_node *rn;
1045 struct rib *rib;
1046 struct nexthop *nexthop;
1047#define ZEBRA_ROUTE_IBGP ZEBRA_ROUTE_MAX
1048#define ZEBRA_ROUTE_TOTAL (ZEBRA_ROUTE_IBGP + 1)
1049 u_int32_t rib_cnt[ZEBRA_ROUTE_TOTAL + 1];
1050 u_int32_t fib_cnt[ZEBRA_ROUTE_TOTAL + 1];
1051 u_int32_t i;
paul718e3742002-12-13 20:15:29 +00001052
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001053 memset (&rib_cnt, 0, sizeof(rib_cnt));
1054 memset (&fib_cnt, 0, sizeof(fib_cnt));
1055 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001056 RNODE_FOREACH_RIB (rn, rib)
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001057 for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
1058 {
1059 rib_cnt[ZEBRA_ROUTE_TOTAL]++;
1060 rib_cnt[rib->type]++;
1061 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB))
1062 {
1063 fib_cnt[ZEBRA_ROUTE_TOTAL]++;
1064 fib_cnt[rib->type]++;
1065 }
1066 if (rib->type == ZEBRA_ROUTE_BGP &&
1067 CHECK_FLAG (rib->flags, ZEBRA_FLAG_IBGP))
1068 {
1069 rib_cnt[ZEBRA_ROUTE_IBGP]++;
1070 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB))
1071 fib_cnt[ZEBRA_ROUTE_IBGP]++;
1072 }
1073 }
paul718e3742002-12-13 20:15:29 +00001074
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001075 vty_out (vty, "%-20s %-20s %-20s %s",
1076 "Route Source", "Routes", "FIB", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001077
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001078 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
1079 {
1080 if (rib_cnt[i] > 0)
1081 {
1082 if (i == ZEBRA_ROUTE_BGP)
1083 {
1084 vty_out (vty, "%-20s %-20d %-20d %s", "ebgp",
1085 rib_cnt[ZEBRA_ROUTE_BGP] - rib_cnt[ZEBRA_ROUTE_IBGP],
1086 fib_cnt[ZEBRA_ROUTE_BGP] - fib_cnt[ZEBRA_ROUTE_IBGP],
1087 VTY_NEWLINE);
1088 vty_out (vty, "%-20s %-20d %-20d %s", "ibgp",
1089 rib_cnt[ZEBRA_ROUTE_IBGP], fib_cnt[ZEBRA_ROUTE_IBGP],
1090 VTY_NEWLINE);
1091 }
1092 else
1093 vty_out (vty, "%-20s %-20d %-20d %s", zebra_route_string(i),
1094 rib_cnt[i], fib_cnt[i], VTY_NEWLINE);
1095 }
1096 }
paul718e3742002-12-13 20:15:29 +00001097
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001098 vty_out (vty, "------%s", VTY_NEWLINE);
1099 vty_out (vty, "%-20s %-20d %-20d %s", "Totals", rib_cnt[ZEBRA_ROUTE_TOTAL],
1100 fib_cnt[ZEBRA_ROUTE_TOTAL], VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001101}
1102
1103/* Show route summary. */
1104DEFUN (show_ip_route_summary,
1105 show_ip_route_summary_cmd,
1106 "show ip route summary",
1107 SHOW_STR
1108 IP_STR
1109 "IP routing table\n"
1110 "Summary of all routes\n")
1111{
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001112 struct route_table *table;
paul718e3742002-12-13 20:15:29 +00001113
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001114 table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
1115 if (! table)
1116 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001117
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001118 vty_show_ip_route_summary (vty, table);
paul718e3742002-12-13 20:15:29 +00001119
1120 return CMD_SUCCESS;
1121}
1122
1123/* Write IPv4 static route configuration. */
paula1ac18c2005-06-28 17:17:12 +00001124static int
paul718e3742002-12-13 20:15:29 +00001125static_config_ipv4 (struct vty *vty)
1126{
1127 struct route_node *rn;
1128 struct static_ipv4 *si;
1129 struct route_table *stable;
1130 int write;
1131
1132 write = 0;
1133
1134 /* Lookup table. */
1135 stable = vrf_static_table (AFI_IP, SAFI_UNICAST, 0);
1136 if (! stable)
1137 return -1;
1138
1139 for (rn = route_top (stable); rn; rn = route_next (rn))
1140 for (si = rn->info; si; si = si->next)
1141 {
paul7021c422003-07-15 12:52:22 +00001142 vty_out (vty, "ip route %s/%d", inet_ntoa (rn->p.u.prefix4),
1143 rn->p.prefixlen);
paul718e3742002-12-13 20:15:29 +00001144
paul7021c422003-07-15 12:52:22 +00001145 switch (si->type)
1146 {
1147 case STATIC_IPV4_GATEWAY:
1148 vty_out (vty, " %s", inet_ntoa (si->gate.ipv4));
1149 break;
1150 case STATIC_IPV4_IFNAME:
1151 vty_out (vty, " %s", si->gate.ifname);
1152 break;
1153 case STATIC_IPV4_BLACKHOLE:
1154 vty_out (vty, " Null0");
1155 break;
1156 }
1157
1158 /* flags are incompatible with STATIC_IPV4_BLACKHOLE */
1159 if (si->type != STATIC_IPV4_BLACKHOLE)
1160 {
1161 if (CHECK_FLAG(si->flags, ZEBRA_FLAG_REJECT))
1162 vty_out (vty, " %s", "reject");
paul718e3742002-12-13 20:15:29 +00001163
paul7021c422003-07-15 12:52:22 +00001164 if (CHECK_FLAG(si->flags, ZEBRA_FLAG_BLACKHOLE))
1165 vty_out (vty, " %s", "blackhole");
1166 }
hasso81dfcaa2003-05-25 19:21:25 +00001167
paul7021c422003-07-15 12:52:22 +00001168 if (si->distance != ZEBRA_STATIC_DISTANCE_DEFAULT)
1169 vty_out (vty, " %d", si->distance);
hasso81dfcaa2003-05-25 19:21:25 +00001170
paul7021c422003-07-15 12:52:22 +00001171 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001172
paul7021c422003-07-15 12:52:22 +00001173 write = 1;
paul718e3742002-12-13 20:15:29 +00001174 }
1175 return write;
1176}
Andrew J. Schorr09303312007-05-30 20:10:34 +00001177
1178DEFUN (show_ip_protocol,
1179 show_ip_protocol_cmd,
1180 "show ip protocol",
1181 SHOW_STR
1182 IP_STR
1183 "IP protocol filtering status\n")
1184{
1185 int i;
1186
1187 vty_out(vty, "Protocol : route-map %s", VTY_NEWLINE);
1188 vty_out(vty, "------------------------%s", VTY_NEWLINE);
1189 for (i=0;i<ZEBRA_ROUTE_MAX;i++)
1190 {
1191 if (proto_rm[AFI_IP][i])
1192 vty_out (vty, "%-10s : %-10s%s", zebra_route_string(i),
1193 proto_rm[AFI_IP][i],
1194 VTY_NEWLINE);
1195 else
1196 vty_out (vty, "%-10s : none%s", zebra_route_string(i), VTY_NEWLINE);
1197 }
1198 if (proto_rm[AFI_IP][i])
1199 vty_out (vty, "%-10s : %-10s%s", "any", proto_rm[AFI_IP][i],
1200 VTY_NEWLINE);
1201 else
1202 vty_out (vty, "%-10s : none%s", "any", VTY_NEWLINE);
1203
1204 return CMD_SUCCESS;
1205}
1206
Joachim Nilsson36735ed2012-05-09 13:38:36 +02001207/*
1208 * Show IP mroute command to dump the BGP Multicast
1209 * routing table
1210 */
1211DEFUN (show_ip_mroute,
1212 show_ip_mroute_cmd,
1213 "show ip mroute",
1214 SHOW_STR
1215 IP_STR
1216 "IP Multicast routing table\n")
1217{
1218 struct route_table *table;
1219 struct route_node *rn;
1220 struct rib *rib;
1221 int first = 1;
1222
1223 table = vrf_table (AFI_IP, SAFI_MULTICAST, 0);
1224 if (! table)
1225 return CMD_SUCCESS;
1226
1227 /* Show all IPv4 routes. */
1228 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001229 RNODE_FOREACH_RIB (rn, rib)
Joachim Nilsson36735ed2012-05-09 13:38:36 +02001230 {
1231 if (first)
1232 {
1233 vty_out (vty, SHOW_ROUTE_V4_HEADER);
1234 first = 0;
1235 }
1236 vty_show_ip_route (vty, rn, rib);
1237 }
1238 return CMD_SUCCESS;
1239}
1240
paul718e3742002-12-13 20:15:29 +00001241
1242#ifdef HAVE_IPV6
1243/* General fucntion for IPv6 static route. */
paula1ac18c2005-06-28 17:17:12 +00001244static int
hasso39db97e2004-10-12 20:50:58 +00001245static_ipv6_func (struct vty *vty, int add_cmd, const char *dest_str,
1246 const char *gate_str, const char *ifname,
1247 const char *flag_str, const char *distance_str)
paul718e3742002-12-13 20:15:29 +00001248{
1249 int ret;
1250 u_char distance;
1251 struct prefix p;
1252 struct in6_addr *gate = NULL;
1253 struct in6_addr gate_addr;
1254 u_char type = 0;
1255 int table = 0;
hasso81dfcaa2003-05-25 19:21:25 +00001256 u_char flag = 0;
paul718e3742002-12-13 20:15:29 +00001257
1258 ret = str2prefix (dest_str, &p);
1259 if (ret <= 0)
1260 {
1261 vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
1262 return CMD_WARNING;
1263 }
1264
1265 /* Apply mask for given prefix. */
1266 apply_mask (&p);
1267
hasso81dfcaa2003-05-25 19:21:25 +00001268 /* Route flags */
1269 if (flag_str) {
1270 switch(flag_str[0]) {
1271 case 'r':
1272 case 'R': /* XXX */
1273 SET_FLAG (flag, ZEBRA_FLAG_REJECT);
1274 break;
1275 case 'b':
1276 case 'B': /* XXX */
1277 SET_FLAG (flag, ZEBRA_FLAG_BLACKHOLE);
1278 break;
1279 default:
1280 vty_out (vty, "%% Malformed flag %s %s", flag_str, VTY_NEWLINE);
paul595db7f2003-05-25 21:35:06 +00001281 return CMD_WARNING;
hasso81dfcaa2003-05-25 19:21:25 +00001282 }
1283 }
1284
paul718e3742002-12-13 20:15:29 +00001285 /* Administrative distance. */
1286 if (distance_str)
1287 distance = atoi (distance_str);
1288 else
1289 distance = ZEBRA_STATIC_DISTANCE_DEFAULT;
1290
1291 /* When gateway is valid IPv6 addrees, then gate is treated as
1292 nexthop address other case gate is treated as interface name. */
1293 ret = inet_pton (AF_INET6, gate_str, &gate_addr);
1294
1295 if (ifname)
1296 {
1297 /* When ifname is specified. It must be come with gateway
1298 address. */
1299 if (ret != 1)
1300 {
1301 vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
1302 return CMD_WARNING;
1303 }
1304 type = STATIC_IPV6_GATEWAY_IFNAME;
1305 gate = &gate_addr;
1306 }
1307 else
1308 {
1309 if (ret == 1)
1310 {
1311 type = STATIC_IPV6_GATEWAY;
1312 gate = &gate_addr;
1313 }
1314 else
1315 {
1316 type = STATIC_IPV6_IFNAME;
1317 ifname = gate_str;
1318 }
1319 }
1320
1321 if (add_cmd)
hasso81dfcaa2003-05-25 19:21:25 +00001322 static_add_ipv6 (&p, type, gate, ifname, flag, distance, table);
paul718e3742002-12-13 20:15:29 +00001323 else
1324 static_delete_ipv6 (&p, type, gate, ifname, distance, table);
1325
1326 return CMD_SUCCESS;
1327}
1328
1329DEFUN (ipv6_route,
1330 ipv6_route_cmd,
1331 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE)",
1332 IP_STR
1333 "Establish static routes\n"
1334 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1335 "IPv6 gateway address\n"
1336 "IPv6 gateway interface name\n")
1337{
hasso81dfcaa2003-05-25 19:21:25 +00001338 return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, NULL, NULL);
1339}
1340
1341DEFUN (ipv6_route_flags,
1342 ipv6_route_flags_cmd,
1343 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole)",
1344 IP_STR
1345 "Establish static routes\n"
1346 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1347 "IPv6 gateway address\n"
1348 "IPv6 gateway interface name\n"
1349 "Emit an ICMP unreachable when matched\n"
1350 "Silently discard pkts when matched\n")
1351{
1352 return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, argv[2], NULL);
paul718e3742002-12-13 20:15:29 +00001353}
1354
1355DEFUN (ipv6_route_ifname,
1356 ipv6_route_ifname_cmd,
1357 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE",
1358 IP_STR
1359 "Establish static routes\n"
1360 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1361 "IPv6 gateway address\n"
1362 "IPv6 gateway interface name\n")
1363{
hasso81dfcaa2003-05-25 19:21:25 +00001364 return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], NULL, NULL);
1365}
1366
1367DEFUN (ipv6_route_ifname_flags,
1368 ipv6_route_ifname_flags_cmd,
1369 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole)",
1370 IP_STR
1371 "Establish static routes\n"
1372 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1373 "IPv6 gateway address\n"
1374 "IPv6 gateway interface name\n"
1375 "Emit an ICMP unreachable when matched\n"
1376 "Silently discard pkts when matched\n")
1377{
1378 return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], argv[3], NULL);
paul718e3742002-12-13 20:15:29 +00001379}
1380
1381DEFUN (ipv6_route_pref,
1382 ipv6_route_pref_cmd,
1383 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <1-255>",
1384 IP_STR
1385 "Establish static routes\n"
1386 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1387 "IPv6 gateway address\n"
1388 "IPv6 gateway interface name\n"
1389 "Distance value for this prefix\n")
1390{
hasso81dfcaa2003-05-25 19:21:25 +00001391 return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, NULL, argv[2]);
1392}
1393
1394DEFUN (ipv6_route_flags_pref,
1395 ipv6_route_flags_pref_cmd,
1396 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) <1-255>",
1397 IP_STR
1398 "Establish static routes\n"
1399 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1400 "IPv6 gateway address\n"
1401 "IPv6 gateway interface name\n"
1402 "Emit an ICMP unreachable when matched\n"
1403 "Silently discard pkts when matched\n"
1404 "Distance value for this prefix\n")
1405{
1406 return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, argv[2], argv[3]);
paul718e3742002-12-13 20:15:29 +00001407}
1408
1409DEFUN (ipv6_route_ifname_pref,
1410 ipv6_route_ifname_pref_cmd,
1411 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255>",
1412 IP_STR
1413 "Establish static routes\n"
1414 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1415 "IPv6 gateway address\n"
1416 "IPv6 gateway interface name\n"
1417 "Distance value for this prefix\n")
1418{
hasso81dfcaa2003-05-25 19:21:25 +00001419 return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], NULL, argv[3]);
1420}
1421
1422DEFUN (ipv6_route_ifname_flags_pref,
1423 ipv6_route_ifname_flags_pref_cmd,
1424 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) <1-255>",
1425 IP_STR
1426 "Establish static routes\n"
1427 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1428 "IPv6 gateway address\n"
1429 "IPv6 gateway interface name\n"
1430 "Emit an ICMP unreachable when matched\n"
1431 "Silently discard pkts when matched\n"
1432 "Distance value for this prefix\n")
1433{
1434 return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], argv[3], argv[4]);
paul718e3742002-12-13 20:15:29 +00001435}
1436
1437DEFUN (no_ipv6_route,
1438 no_ipv6_route_cmd,
1439 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE)",
1440 NO_STR
1441 IP_STR
1442 "Establish static routes\n"
1443 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1444 "IPv6 gateway address\n"
1445 "IPv6 gateway interface name\n")
1446{
hasso81dfcaa2003-05-25 19:21:25 +00001447 return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00001448}
1449
hasso81dfcaa2003-05-25 19:21:25 +00001450ALIAS (no_ipv6_route,
1451 no_ipv6_route_flags_cmd,
1452 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole)",
1453 NO_STR
1454 IP_STR
1455 "Establish static routes\n"
1456 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1457 "IPv6 gateway address\n"
1458 "IPv6 gateway interface name\n"
1459 "Emit an ICMP unreachable when matched\n"
1460 "Silently discard pkts when matched\n")
1461
paul718e3742002-12-13 20:15:29 +00001462DEFUN (no_ipv6_route_ifname,
1463 no_ipv6_route_ifname_cmd,
1464 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE",
1465 NO_STR
1466 IP_STR
1467 "Establish static routes\n"
1468 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1469 "IPv6 gateway address\n"
1470 "IPv6 gateway interface name\n")
1471{
hasso81dfcaa2003-05-25 19:21:25 +00001472 return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], NULL, NULL);
paul718e3742002-12-13 20:15:29 +00001473}
1474
hasso81dfcaa2003-05-25 19:21:25 +00001475ALIAS (no_ipv6_route_ifname,
1476 no_ipv6_route_ifname_flags_cmd,
1477 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole)",
1478 NO_STR
1479 IP_STR
1480 "Establish static routes\n"
1481 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1482 "IPv6 gateway address\n"
1483 "IPv6 gateway interface name\n"
1484 "Emit an ICMP unreachable when matched\n"
1485 "Silently discard pkts when matched\n")
1486
paul718e3742002-12-13 20:15:29 +00001487DEFUN (no_ipv6_route_pref,
1488 no_ipv6_route_pref_cmd,
1489 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <1-255>",
1490 NO_STR
1491 IP_STR
1492 "Establish static routes\n"
1493 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1494 "IPv6 gateway address\n"
1495 "IPv6 gateway interface name\n"
1496 "Distance value for this prefix\n")
1497{
hasso81dfcaa2003-05-25 19:21:25 +00001498 return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, NULL, argv[2]);
1499}
1500
1501DEFUN (no_ipv6_route_flags_pref,
1502 no_ipv6_route_flags_pref_cmd,
1503 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) <1-255>",
1504 NO_STR
1505 IP_STR
1506 "Establish static routes\n"
1507 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1508 "IPv6 gateway address\n"
1509 "IPv6 gateway interface name\n"
1510 "Emit an ICMP unreachable when matched\n"
1511 "Silently discard pkts when matched\n"
1512 "Distance value for this prefix\n")
1513{
1514 /* We do not care about argv[2] */
1515 return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, argv[2], argv[3]);
paul718e3742002-12-13 20:15:29 +00001516}
1517
1518DEFUN (no_ipv6_route_ifname_pref,
1519 no_ipv6_route_ifname_pref_cmd,
1520 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255>",
1521 NO_STR
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 "Distance value for this prefix\n")
1528{
hasso81dfcaa2003-05-25 19:21:25 +00001529 return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], NULL, argv[3]);
1530}
1531
1532DEFUN (no_ipv6_route_ifname_flags_pref,
1533 no_ipv6_route_ifname_flags_pref_cmd,
1534 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) <1-255>",
1535 NO_STR
1536 IP_STR
1537 "Establish static routes\n"
1538 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1539 "IPv6 gateway address\n"
1540 "IPv6 gateway interface name\n"
1541 "Emit an ICMP unreachable when matched\n"
1542 "Silently discard pkts when matched\n"
1543 "Distance value for this prefix\n")
1544{
1545 return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], argv[3], argv[4]);
paul718e3742002-12-13 20:15:29 +00001546}
1547
paul595db7f2003-05-25 21:35:06 +00001548/* New RIB. Detailed information for IPv6 route. */
paula1ac18c2005-06-28 17:17:12 +00001549static void
paul718e3742002-12-13 20:15:29 +00001550vty_show_ipv6_route_detail (struct vty *vty, struct route_node *rn)
1551{
1552 struct rib *rib;
1553 struct nexthop *nexthop;
1554 char buf[BUFSIZ];
1555
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001556 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +00001557 {
1558 vty_out (vty, "Routing entry for %s/%d%s",
1559 inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, BUFSIZ),
1560 rn->p.prefixlen,
1561 VTY_NEWLINE);
ajsf52d13c2005-10-01 17:38:06 +00001562 vty_out (vty, " Known via \"%s\"", zebra_route_string (rib->type));
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02001563 vty_out (vty, ", distance %u, metric %u", rib->distance, rib->metric);
paul718e3742002-12-13 20:15:29 +00001564 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
1565 vty_out (vty, ", best");
1566 if (rib->refcnt)
1567 vty_out (vty, ", refcnt %ld", rib->refcnt);
hasso81dfcaa2003-05-25 19:21:25 +00001568 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
1569 vty_out (vty, ", blackhole");
1570 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT))
1571 vty_out (vty, ", reject");
paul718e3742002-12-13 20:15:29 +00001572 vty_out (vty, "%s", VTY_NEWLINE);
1573
1574#define ONE_DAY_SECOND 60*60*24
1575#define ONE_WEEK_SECOND 60*60*24*7
1576 if (rib->type == ZEBRA_ROUTE_RIPNG
1577 || rib->type == ZEBRA_ROUTE_OSPF6
Juliusz Chroboczek578ce372012-02-09 13:42:28 +01001578 || rib->type == ZEBRA_ROUTE_BABEL
jardin9e867fe2003-12-23 08:56:18 +00001579 || rib->type == ZEBRA_ROUTE_ISIS
paul718e3742002-12-13 20:15:29 +00001580 || rib->type == ZEBRA_ROUTE_BGP)
1581 {
1582 time_t uptime;
1583 struct tm *tm;
1584
1585 uptime = time (NULL);
1586 uptime -= rib->uptime;
1587 tm = gmtime (&uptime);
1588
1589 vty_out (vty, " Last update ");
1590
1591 if (uptime < ONE_DAY_SECOND)
1592 vty_out (vty, "%02d:%02d:%02d",
1593 tm->tm_hour, tm->tm_min, tm->tm_sec);
1594 else if (uptime < ONE_WEEK_SECOND)
1595 vty_out (vty, "%dd%02dh%02dm",
1596 tm->tm_yday, tm->tm_hour, tm->tm_min);
1597 else
1598 vty_out (vty, "%02dw%dd%02dh",
1599 tm->tm_yday/7,
1600 tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
1601 vty_out (vty, " ago%s", VTY_NEWLINE);
1602 }
1603
1604 for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
1605 {
1606 vty_out (vty, " %c",
1607 CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB) ? '*' : ' ');
1608
1609 switch (nexthop->type)
1610 {
1611 case NEXTHOP_TYPE_IPV6:
1612 case NEXTHOP_TYPE_IPV6_IFINDEX:
1613 case NEXTHOP_TYPE_IPV6_IFNAME:
1614 vty_out (vty, " %s",
1615 inet_ntop (AF_INET6, &nexthop->gate.ipv6, buf, BUFSIZ));
1616 if (nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME)
1617 vty_out (vty, ", %s", nexthop->ifname);
1618 else if (nexthop->ifindex)
1619 vty_out (vty, ", via %s", ifindex2ifname (nexthop->ifindex));
1620 break;
1621 case NEXTHOP_TYPE_IFINDEX:
1622 vty_out (vty, " directly connected, %s",
1623 ifindex2ifname (nexthop->ifindex));
1624 break;
1625 case NEXTHOP_TYPE_IFNAME:
1626 vty_out (vty, " directly connected, %s",
1627 nexthop->ifname);
1628 break;
1629 default:
1630 break;
1631 }
1632 if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
1633 vty_out (vty, " inactive");
1634
1635 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
1636 {
1637 vty_out (vty, " (recursive");
1638
1639 switch (nexthop->rtype)
1640 {
1641 case NEXTHOP_TYPE_IPV6:
1642 case NEXTHOP_TYPE_IPV6_IFINDEX:
1643 case NEXTHOP_TYPE_IPV6_IFNAME:
1644 vty_out (vty, " via %s)",
1645 inet_ntop (AF_INET6, &nexthop->rgate.ipv6,
1646 buf, BUFSIZ));
1647 if (nexthop->rifindex)
1648 vty_out (vty, ", %s", ifindex2ifname (nexthop->rifindex));
1649 break;
1650 case NEXTHOP_TYPE_IFINDEX:
1651 case NEXTHOP_TYPE_IFNAME:
1652 vty_out (vty, " is directly connected, %s)",
1653 ifindex2ifname (nexthop->rifindex));
1654 break;
1655 default:
1656 break;
1657 }
1658 }
1659 vty_out (vty, "%s", VTY_NEWLINE);
1660 }
1661 vty_out (vty, "%s", VTY_NEWLINE);
1662 }
1663}
1664
paula1ac18c2005-06-28 17:17:12 +00001665static void
paul718e3742002-12-13 20:15:29 +00001666vty_show_ipv6_route (struct vty *vty, struct route_node *rn,
1667 struct rib *rib)
1668{
1669 struct nexthop *nexthop;
1670 int len = 0;
1671 char buf[BUFSIZ];
1672
1673 /* Nexthop information. */
1674 for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
1675 {
1676 if (nexthop == rib->nexthop)
1677 {
1678 /* Prefix information. */
1679 len = vty_out (vty, "%c%c%c %s/%d",
ajsf52d13c2005-10-01 17:38:06 +00001680 zebra_route_char (rib->type),
paul718e3742002-12-13 20:15:29 +00001681 CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED)
1682 ? '>' : ' ',
1683 CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
1684 ? '*' : ' ',
1685 inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, BUFSIZ),
1686 rn->p.prefixlen);
1687
1688 /* Distance and metric display. */
1689 if (rib->type != ZEBRA_ROUTE_CONNECT
1690 && rib->type != ZEBRA_ROUTE_KERNEL)
1691 len += vty_out (vty, " [%d/%d]", rib->distance,
1692 rib->metric);
1693 }
1694 else
1695 vty_out (vty, " %c%*c",
1696 CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
1697 ? '*' : ' ',
1698 len - 3, ' ');
1699
1700 switch (nexthop->type)
1701 {
1702 case NEXTHOP_TYPE_IPV6:
1703 case NEXTHOP_TYPE_IPV6_IFINDEX:
1704 case NEXTHOP_TYPE_IPV6_IFNAME:
1705 vty_out (vty, " via %s",
1706 inet_ntop (AF_INET6, &nexthop->gate.ipv6, buf, BUFSIZ));
1707 if (nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME)
1708 vty_out (vty, ", %s", nexthop->ifname);
1709 else if (nexthop->ifindex)
1710 vty_out (vty, ", %s", ifindex2ifname (nexthop->ifindex));
1711 break;
1712 case NEXTHOP_TYPE_IFINDEX:
1713 vty_out (vty, " is directly connected, %s",
1714 ifindex2ifname (nexthop->ifindex));
1715 break;
1716 case NEXTHOP_TYPE_IFNAME:
1717 vty_out (vty, " is directly connected, %s",
1718 nexthop->ifname);
1719 break;
1720 default:
1721 break;
1722 }
1723 if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
1724 vty_out (vty, " inactive");
1725
1726 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
1727 {
1728 vty_out (vty, " (recursive");
1729
1730 switch (nexthop->rtype)
1731 {
1732 case NEXTHOP_TYPE_IPV6:
1733 case NEXTHOP_TYPE_IPV6_IFINDEX:
1734 case NEXTHOP_TYPE_IPV6_IFNAME:
1735 vty_out (vty, " via %s)",
1736 inet_ntop (AF_INET6, &nexthop->rgate.ipv6,
1737 buf, BUFSIZ));
1738 if (nexthop->rifindex)
1739 vty_out (vty, ", %s", ifindex2ifname (nexthop->rifindex));
1740 break;
1741 case NEXTHOP_TYPE_IFINDEX:
1742 case NEXTHOP_TYPE_IFNAME:
1743 vty_out (vty, " is directly connected, %s)",
1744 ifindex2ifname (nexthop->rifindex));
1745 break;
1746 default:
1747 break;
1748 }
1749 }
1750
hasso81dfcaa2003-05-25 19:21:25 +00001751 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
1752 vty_out (vty, ", bh");
1753 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT))
1754 vty_out (vty, ", rej");
1755
paul718e3742002-12-13 20:15:29 +00001756 if (rib->type == ZEBRA_ROUTE_RIPNG
1757 || rib->type == ZEBRA_ROUTE_OSPF6
Juliusz Chroboczek578ce372012-02-09 13:42:28 +01001758 || rib->type == ZEBRA_ROUTE_BABEL
jardin9e867fe2003-12-23 08:56:18 +00001759 || rib->type == ZEBRA_ROUTE_ISIS
paul718e3742002-12-13 20:15:29 +00001760 || rib->type == ZEBRA_ROUTE_BGP)
1761 {
1762 time_t uptime;
1763 struct tm *tm;
1764
1765 uptime = time (NULL);
1766 uptime -= rib->uptime;
1767 tm = gmtime (&uptime);
1768
1769#define ONE_DAY_SECOND 60*60*24
1770#define ONE_WEEK_SECOND 60*60*24*7
1771
1772 if (uptime < ONE_DAY_SECOND)
1773 vty_out (vty, ", %02d:%02d:%02d",
1774 tm->tm_hour, tm->tm_min, tm->tm_sec);
1775 else if (uptime < ONE_WEEK_SECOND)
1776 vty_out (vty, ", %dd%02dh%02dm",
1777 tm->tm_yday, tm->tm_hour, tm->tm_min);
1778 else
1779 vty_out (vty, ", %02dw%dd%02dh",
1780 tm->tm_yday/7,
1781 tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
1782 }
1783 vty_out (vty, "%s", VTY_NEWLINE);
1784 }
1785}
1786
paul718e3742002-12-13 20:15:29 +00001787DEFUN (show_ipv6_route,
1788 show_ipv6_route_cmd,
1789 "show ipv6 route",
1790 SHOW_STR
1791 IP_STR
1792 "IPv6 routing table\n")
1793{
1794 struct route_table *table;
1795 struct route_node *rn;
1796 struct rib *rib;
1797 int first = 1;
1798
1799 table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
1800 if (! table)
1801 return CMD_SUCCESS;
1802
1803 /* Show all IPv6 route. */
1804 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001805 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +00001806 {
1807 if (first)
1808 {
David Lampartere0ca5fd2009-09-16 01:52:42 +02001809 vty_out (vty, SHOW_ROUTE_V6_HEADER);
paul718e3742002-12-13 20:15:29 +00001810 first = 0;
1811 }
1812 vty_show_ipv6_route (vty, rn, rib);
1813 }
1814 return CMD_SUCCESS;
1815}
1816
1817DEFUN (show_ipv6_route_prefix_longer,
1818 show_ipv6_route_prefix_longer_cmd,
1819 "show ipv6 route X:X::X:X/M longer-prefixes",
1820 SHOW_STR
1821 IP_STR
1822 "IPv6 routing table\n"
1823 "IPv6 prefix\n"
1824 "Show route matching the specified Network/Mask pair only\n")
1825{
1826 struct route_table *table;
1827 struct route_node *rn;
1828 struct rib *rib;
1829 struct prefix p;
1830 int ret;
1831 int first = 1;
1832
1833 table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
1834 if (! table)
1835 return CMD_SUCCESS;
1836
1837 ret = str2prefix (argv[0], &p);
1838 if (! ret)
1839 {
1840 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
1841 return CMD_WARNING;
1842 }
1843
1844 /* Show matched type IPv6 routes. */
1845 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001846 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +00001847 if (prefix_match (&p, &rn->p))
1848 {
1849 if (first)
1850 {
David Lampartere0ca5fd2009-09-16 01:52:42 +02001851 vty_out (vty, SHOW_ROUTE_V6_HEADER);
paul718e3742002-12-13 20:15:29 +00001852 first = 0;
1853 }
1854 vty_show_ipv6_route (vty, rn, rib);
1855 }
1856 return CMD_SUCCESS;
1857}
1858
1859DEFUN (show_ipv6_route_protocol,
1860 show_ipv6_route_protocol_cmd,
David Lampartere0ca5fd2009-09-16 01:52:42 +02001861 "show ipv6 route " QUAGGA_IP6_REDIST_STR_ZEBRA,
paul718e3742002-12-13 20:15:29 +00001862 SHOW_STR
1863 IP_STR
1864 "IP routing table\n"
David Lampartere0ca5fd2009-09-16 01:52:42 +02001865 QUAGGA_IP6_REDIST_HELP_STR_ZEBRA)
paul718e3742002-12-13 20:15:29 +00001866{
1867 int type;
1868 struct route_table *table;
1869 struct route_node *rn;
1870 struct rib *rib;
1871 int first = 1;
1872
David Lampartere0ca5fd2009-09-16 01:52:42 +02001873 type = proto_redistnum (AFI_IP6, argv[0]);
1874 if (type < 0)
paul718e3742002-12-13 20:15:29 +00001875 {
1876 vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
1877 return CMD_WARNING;
1878 }
1879
1880 table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
1881 if (! table)
1882 return CMD_SUCCESS;
1883
1884 /* Show matched type IPv6 routes. */
1885 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001886 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +00001887 if (rib->type == type)
1888 {
1889 if (first)
1890 {
David Lampartere0ca5fd2009-09-16 01:52:42 +02001891 vty_out (vty, SHOW_ROUTE_V6_HEADER);
paul718e3742002-12-13 20:15:29 +00001892 first = 0;
1893 }
1894 vty_show_ipv6_route (vty, rn, rib);
1895 }
1896 return CMD_SUCCESS;
1897}
1898
1899DEFUN (show_ipv6_route_addr,
1900 show_ipv6_route_addr_cmd,
1901 "show ipv6 route X:X::X:X",
1902 SHOW_STR
1903 IP_STR
1904 "IPv6 routing table\n"
1905 "IPv6 Address\n")
1906{
1907 int ret;
1908 struct prefix_ipv6 p;
1909 struct route_table *table;
1910 struct route_node *rn;
1911
1912 ret = str2prefix_ipv6 (argv[0], &p);
1913 if (ret <= 0)
1914 {
1915 vty_out (vty, "Malformed IPv6 address%s", VTY_NEWLINE);
1916 return CMD_WARNING;
1917 }
1918
1919 table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
1920 if (! table)
1921 return CMD_SUCCESS;
1922
1923 rn = route_node_match (table, (struct prefix *) &p);
1924 if (! rn)
1925 {
1926 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
1927 return CMD_WARNING;
1928 }
1929
1930 vty_show_ipv6_route_detail (vty, rn);
1931
1932 route_unlock_node (rn);
1933
1934 return CMD_SUCCESS;
1935}
1936
1937DEFUN (show_ipv6_route_prefix,
1938 show_ipv6_route_prefix_cmd,
1939 "show ipv6 route X:X::X:X/M",
1940 SHOW_STR
1941 IP_STR
1942 "IPv6 routing table\n"
1943 "IPv6 prefix\n")
1944{
1945 int ret;
1946 struct prefix_ipv6 p;
1947 struct route_table *table;
1948 struct route_node *rn;
1949
1950 ret = str2prefix_ipv6 (argv[0], &p);
1951 if (ret <= 0)
1952 {
1953 vty_out (vty, "Malformed IPv6 prefix%s", VTY_NEWLINE);
1954 return CMD_WARNING;
1955 }
1956
1957 table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
1958 if (! table)
1959 return CMD_SUCCESS;
1960
1961 rn = route_node_match (table, (struct prefix *) &p);
1962 if (! rn || rn->p.prefixlen != p.prefixlen)
1963 {
1964 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
1965 return CMD_WARNING;
1966 }
1967
1968 vty_show_ipv6_route_detail (vty, rn);
1969
1970 route_unlock_node (rn);
1971
1972 return CMD_SUCCESS;
1973}
1974
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001975/* Show route summary. */
1976DEFUN (show_ipv6_route_summary,
1977 show_ipv6_route_summary_cmd,
1978 "show ipv6 route summary",
1979 SHOW_STR
1980 IP_STR
1981 "IPv6 routing table\n"
1982 "Summary of all IPv6 routes\n")
1983{
1984 struct route_table *table;
1985
1986 table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
1987 if (! table)
1988 return CMD_SUCCESS;
1989
1990 vty_show_ip_route_summary (vty, table);
1991
1992 return CMD_SUCCESS;
1993}
1994
G.Balajicddf3912011-11-26 21:59:32 +04001995/*
G.Balajicddf3912011-11-26 21:59:32 +04001996 * Show IPv6 mroute command.Used to dump
1997 * the Multicast routing table.
1998 */
1999
2000DEFUN (show_ipv6_mroute,
2001 show_ipv6_mroute_cmd,
2002 "show ipv6 mroute",
2003 SHOW_STR
2004 IP_STR
2005 "IPv6 Multicast routing table\n")
2006{
2007 struct route_table *table;
2008 struct route_node *rn;
2009 struct rib *rib;
2010 int first = 1;
2011
2012 table = vrf_table (AFI_IP6, SAFI_MULTICAST, 0);
2013 if (! table)
2014 return CMD_SUCCESS;
2015
2016 /* Show all IPv6 route. */
2017 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00002018 RNODE_FOREACH_RIB (rn, rib)
G.Balajicddf3912011-11-26 21:59:32 +04002019 {
2020 if (first)
2021 {
G.Balajicb32fd62011-11-27 20:09:40 +05302022 vty_out (vty, SHOW_ROUTE_V6_HEADER);
G.Balajicddf3912011-11-26 21:59:32 +04002023 first = 0;
2024 }
2025 vty_show_ipv6_route (vty, rn, rib);
2026 }
2027 return CMD_SUCCESS;
2028}
2029
paul718e3742002-12-13 20:15:29 +00002030/* Write IPv6 static route configuration. */
paula1ac18c2005-06-28 17:17:12 +00002031static int
paul718e3742002-12-13 20:15:29 +00002032static_config_ipv6 (struct vty *vty)
2033{
2034 struct route_node *rn;
2035 struct static_ipv6 *si;
2036 int write;
2037 char buf[BUFSIZ];
2038 struct route_table *stable;
2039
2040 write = 0;
2041
2042 /* Lookup table. */
2043 stable = vrf_static_table (AFI_IP6, SAFI_UNICAST, 0);
2044 if (! stable)
2045 return -1;
2046
2047 for (rn = route_top (stable); rn; rn = route_next (rn))
2048 for (si = rn->info; si; si = si->next)
2049 {
2050 vty_out (vty, "ipv6 route %s/%d",
2051 inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, BUFSIZ),
2052 rn->p.prefixlen);
2053
2054 switch (si->type)
2055 {
2056 case STATIC_IPV6_GATEWAY:
2057 vty_out (vty, " %s", inet_ntop (AF_INET6, &si->ipv6, buf, BUFSIZ));
2058 break;
2059 case STATIC_IPV6_IFNAME:
2060 vty_out (vty, " %s", si->ifname);
2061 break;
2062 case STATIC_IPV6_GATEWAY_IFNAME:
2063 vty_out (vty, " %s %s",
2064 inet_ntop (AF_INET6, &si->ipv6, buf, BUFSIZ), si->ifname);
2065 break;
2066 }
2067
hasso81dfcaa2003-05-25 19:21:25 +00002068 if (CHECK_FLAG(si->flags, ZEBRA_FLAG_REJECT))
2069 vty_out (vty, " %s", "reject");
2070
2071 if (CHECK_FLAG(si->flags, ZEBRA_FLAG_BLACKHOLE))
2072 vty_out (vty, " %s", "blackhole");
2073
paul718e3742002-12-13 20:15:29 +00002074 if (si->distance != ZEBRA_STATIC_DISTANCE_DEFAULT)
2075 vty_out (vty, " %d", si->distance);
2076 vty_out (vty, "%s", VTY_NEWLINE);
2077
2078 write = 1;
2079 }
2080 return write;
2081}
2082#endif /* HAVE_IPV6 */
2083
2084/* Static ip route configuration write function. */
paula1ac18c2005-06-28 17:17:12 +00002085static int
paul718e3742002-12-13 20:15:29 +00002086zebra_ip_config (struct vty *vty)
2087{
2088 int write = 0;
2089
2090 write += static_config_ipv4 (vty);
2091#ifdef HAVE_IPV6
2092 write += static_config_ipv6 (vty);
2093#endif /* HAVE_IPV6 */
2094
2095 return write;
2096}
2097
Paul Jakma7514fb72007-05-02 16:05:35 +00002098/* ip protocol configuration write function */
2099static int config_write_protocol(struct vty *vty)
2100{
2101 int i;
2102
2103 for (i=0;i<ZEBRA_ROUTE_MAX;i++)
2104 {
2105 if (proto_rm[AFI_IP][i])
2106 vty_out (vty, "ip protocol %s route-map %s%s", zebra_route_string(i),
2107 proto_rm[AFI_IP][i], VTY_NEWLINE);
2108 }
2109 if (proto_rm[AFI_IP][ZEBRA_ROUTE_MAX])
2110 vty_out (vty, "ip protocol %s route-map %s%s", "any",
2111 proto_rm[AFI_IP][ZEBRA_ROUTE_MAX], VTY_NEWLINE);
2112
2113 return 1;
2114}
2115
2116/* table node for protocol filtering */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -08002117static struct cmd_node protocol_node = { PROTOCOL_NODE, "", 1 };
Paul Jakma7514fb72007-05-02 16:05:35 +00002118
paul718e3742002-12-13 20:15:29 +00002119/* IP node for static routes. */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -08002120static struct cmd_node ip_node = { IP_NODE, "", 1 };
paul718e3742002-12-13 20:15:29 +00002121
2122/* Route VTY. */
2123void
paula1ac18c2005-06-28 17:17:12 +00002124zebra_vty_init (void)
paul718e3742002-12-13 20:15:29 +00002125{
2126 install_node (&ip_node, zebra_ip_config);
Paul Jakma7514fb72007-05-02 16:05:35 +00002127 install_node (&protocol_node, config_write_protocol);
paul718e3742002-12-13 20:15:29 +00002128
Paul Jakma7514fb72007-05-02 16:05:35 +00002129 install_element (CONFIG_NODE, &ip_protocol_cmd);
2130 install_element (CONFIG_NODE, &no_ip_protocol_cmd);
2131 install_element (VIEW_NODE, &show_ip_protocol_cmd);
2132 install_element (ENABLE_NODE, &show_ip_protocol_cmd);
paul718e3742002-12-13 20:15:29 +00002133 install_element (CONFIG_NODE, &ip_route_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002134 install_element (CONFIG_NODE, &ip_route_flags_cmd);
hasso457ef552003-05-28 12:02:15 +00002135 install_element (CONFIG_NODE, &ip_route_flags2_cmd);
paul718e3742002-12-13 20:15:29 +00002136 install_element (CONFIG_NODE, &ip_route_mask_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002137 install_element (CONFIG_NODE, &ip_route_mask_flags_cmd);
hasso457ef552003-05-28 12:02:15 +00002138 install_element (CONFIG_NODE, &ip_route_mask_flags2_cmd);
paul718e3742002-12-13 20:15:29 +00002139 install_element (CONFIG_NODE, &no_ip_route_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002140 install_element (CONFIG_NODE, &no_ip_route_flags_cmd);
hasso457ef552003-05-28 12:02:15 +00002141 install_element (CONFIG_NODE, &no_ip_route_flags2_cmd);
paul718e3742002-12-13 20:15:29 +00002142 install_element (CONFIG_NODE, &no_ip_route_mask_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002143 install_element (CONFIG_NODE, &no_ip_route_mask_flags_cmd);
hasso457ef552003-05-28 12:02:15 +00002144 install_element (CONFIG_NODE, &no_ip_route_mask_flags2_cmd);
paul718e3742002-12-13 20:15:29 +00002145 install_element (CONFIG_NODE, &ip_route_distance_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002146 install_element (CONFIG_NODE, &ip_route_flags_distance_cmd);
hasso457ef552003-05-28 12:02:15 +00002147 install_element (CONFIG_NODE, &ip_route_flags_distance2_cmd);
paul718e3742002-12-13 20:15:29 +00002148 install_element (CONFIG_NODE, &ip_route_mask_distance_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002149 install_element (CONFIG_NODE, &ip_route_mask_flags_distance_cmd);
hasso457ef552003-05-28 12:02:15 +00002150 install_element (CONFIG_NODE, &ip_route_mask_flags_distance2_cmd);
paul718e3742002-12-13 20:15:29 +00002151 install_element (CONFIG_NODE, &no_ip_route_distance_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002152 install_element (CONFIG_NODE, &no_ip_route_flags_distance_cmd);
hasso457ef552003-05-28 12:02:15 +00002153 install_element (CONFIG_NODE, &no_ip_route_flags_distance2_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002154 install_element (CONFIG_NODE, &no_ip_route_mask_flags_distance_cmd);
hasso457ef552003-05-28 12:02:15 +00002155 install_element (CONFIG_NODE, &no_ip_route_mask_flags_distance2_cmd);
paul718e3742002-12-13 20:15:29 +00002156
2157 install_element (VIEW_NODE, &show_ip_route_cmd);
2158 install_element (VIEW_NODE, &show_ip_route_addr_cmd);
2159 install_element (VIEW_NODE, &show_ip_route_prefix_cmd);
2160 install_element (VIEW_NODE, &show_ip_route_prefix_longer_cmd);
2161 install_element (VIEW_NODE, &show_ip_route_protocol_cmd);
2162 install_element (VIEW_NODE, &show_ip_route_supernets_cmd);
Stig Thormodsrud61691c92008-11-04 15:45:07 -08002163 install_element (VIEW_NODE, &show_ip_route_summary_cmd);
paul718e3742002-12-13 20:15:29 +00002164 install_element (ENABLE_NODE, &show_ip_route_cmd);
2165 install_element (ENABLE_NODE, &show_ip_route_addr_cmd);
2166 install_element (ENABLE_NODE, &show_ip_route_prefix_cmd);
2167 install_element (ENABLE_NODE, &show_ip_route_prefix_longer_cmd);
2168 install_element (ENABLE_NODE, &show_ip_route_protocol_cmd);
2169 install_element (ENABLE_NODE, &show_ip_route_supernets_cmd);
paul718e3742002-12-13 20:15:29 +00002170 install_element (ENABLE_NODE, &show_ip_route_summary_cmd);
paul718e3742002-12-13 20:15:29 +00002171
G.Balajicddf3912011-11-26 21:59:32 +04002172 install_element (VIEW_NODE, &show_ip_mroute_cmd);
2173 install_element (ENABLE_NODE, &show_ip_mroute_cmd);
2174
2175
paul718e3742002-12-13 20:15:29 +00002176#ifdef HAVE_IPV6
2177 install_element (CONFIG_NODE, &ipv6_route_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002178 install_element (CONFIG_NODE, &ipv6_route_flags_cmd);
paul718e3742002-12-13 20:15:29 +00002179 install_element (CONFIG_NODE, &ipv6_route_ifname_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002180 install_element (CONFIG_NODE, &ipv6_route_ifname_flags_cmd);
paul718e3742002-12-13 20:15:29 +00002181 install_element (CONFIG_NODE, &no_ipv6_route_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002182 install_element (CONFIG_NODE, &no_ipv6_route_flags_cmd);
paul718e3742002-12-13 20:15:29 +00002183 install_element (CONFIG_NODE, &no_ipv6_route_ifname_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002184 install_element (CONFIG_NODE, &no_ipv6_route_ifname_flags_cmd);
paul718e3742002-12-13 20:15:29 +00002185 install_element (CONFIG_NODE, &ipv6_route_pref_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002186 install_element (CONFIG_NODE, &ipv6_route_flags_pref_cmd);
paul718e3742002-12-13 20:15:29 +00002187 install_element (CONFIG_NODE, &ipv6_route_ifname_pref_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002188 install_element (CONFIG_NODE, &ipv6_route_ifname_flags_pref_cmd);
paul718e3742002-12-13 20:15:29 +00002189 install_element (CONFIG_NODE, &no_ipv6_route_pref_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002190 install_element (CONFIG_NODE, &no_ipv6_route_flags_pref_cmd);
paul718e3742002-12-13 20:15:29 +00002191 install_element (CONFIG_NODE, &no_ipv6_route_ifname_pref_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002192 install_element (CONFIG_NODE, &no_ipv6_route_ifname_flags_pref_cmd);
paul718e3742002-12-13 20:15:29 +00002193 install_element (VIEW_NODE, &show_ipv6_route_cmd);
Stig Thormodsrud61691c92008-11-04 15:45:07 -08002194 install_element (VIEW_NODE, &show_ipv6_route_summary_cmd);
paul718e3742002-12-13 20:15:29 +00002195 install_element (VIEW_NODE, &show_ipv6_route_protocol_cmd);
2196 install_element (VIEW_NODE, &show_ipv6_route_addr_cmd);
2197 install_element (VIEW_NODE, &show_ipv6_route_prefix_cmd);
2198 install_element (VIEW_NODE, &show_ipv6_route_prefix_longer_cmd);
2199 install_element (ENABLE_NODE, &show_ipv6_route_cmd);
2200 install_element (ENABLE_NODE, &show_ipv6_route_protocol_cmd);
2201 install_element (ENABLE_NODE, &show_ipv6_route_addr_cmd);
2202 install_element (ENABLE_NODE, &show_ipv6_route_prefix_cmd);
2203 install_element (ENABLE_NODE, &show_ipv6_route_prefix_longer_cmd);
Stig Thormodsrud61691c92008-11-04 15:45:07 -08002204 install_element (ENABLE_NODE, &show_ipv6_route_summary_cmd);
G.Balajicddf3912011-11-26 21:59:32 +04002205
2206 install_element (VIEW_NODE, &show_ipv6_mroute_cmd);
2207 install_element (ENABLE_NODE, &show_ipv6_mroute_cmd);
paul718e3742002-12-13 20:15:29 +00002208#endif /* HAVE_IPV6 */
2209}