blob: 1d12ac5f1ddfe81105f8d715c19cbbc382832d4c [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"
hasso81dfcaa2003-05-25 19:21:25 +0000283 "Emit an ICMP unreachable when matched\n"
Christian Franke2b005152013-09-30 12:27:49 +0000284 "Silently discard pkts when matched\n"
285 "Distance value for this route\n")
hasso81dfcaa2003-05-25 19:21:25 +0000286{
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"
hasso457ef552003-05-28 12:02:15 +0000297 "Emit an ICMP unreachable when matched\n"
Christian Franke2b005152013-09-30 12:27:49 +0000298 "Silently discard pkts when matched\n"
299 "Distance value for this route\n")
hasso457ef552003-05-28 12:02:15 +0000300{
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;
Christian Frankefa713d92013-07-05 15:35:37 +0000536 struct nexthop *nexthop, *tnexthop;
537 int recursing;
paul718e3742002-12-13 20:15:29 +0000538
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000539 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +0000540 {
541 vty_out (vty, "Routing entry for %s/%d%s",
542 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
543 VTY_NEWLINE);
ajsf52d13c2005-10-01 17:38:06 +0000544 vty_out (vty, " Known via \"%s\"", zebra_route_string (rib->type));
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +0200545 vty_out (vty, ", distance %u, metric %u", rib->distance, rib->metric);
paul718e3742002-12-13 20:15:29 +0000546 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
547 vty_out (vty, ", best");
548 if (rib->refcnt)
549 vty_out (vty, ", refcnt %ld", rib->refcnt);
hasso81dfcaa2003-05-25 19:21:25 +0000550 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
551 vty_out (vty, ", blackhole");
552 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT))
553 vty_out (vty, ", reject");
paul718e3742002-12-13 20:15:29 +0000554 vty_out (vty, "%s", VTY_NEWLINE);
555
556#define ONE_DAY_SECOND 60*60*24
557#define ONE_WEEK_SECOND 60*60*24*7
558 if (rib->type == ZEBRA_ROUTE_RIP
559 || rib->type == ZEBRA_ROUTE_OSPF
Juliusz Chroboczek578ce372012-02-09 13:42:28 +0100560 || rib->type == ZEBRA_ROUTE_BABEL
jardin9e867fe2003-12-23 08:56:18 +0000561 || rib->type == ZEBRA_ROUTE_ISIS
paul718e3742002-12-13 20:15:29 +0000562 || rib->type == ZEBRA_ROUTE_BGP)
563 {
564 time_t uptime;
565 struct tm *tm;
566
567 uptime = time (NULL);
568 uptime -= rib->uptime;
569 tm = gmtime (&uptime);
570
571 vty_out (vty, " Last update ");
572
573 if (uptime < ONE_DAY_SECOND)
574 vty_out (vty, "%02d:%02d:%02d",
575 tm->tm_hour, tm->tm_min, tm->tm_sec);
576 else if (uptime < ONE_WEEK_SECOND)
577 vty_out (vty, "%dd%02dh%02dm",
578 tm->tm_yday, tm->tm_hour, tm->tm_min);
579 else
580 vty_out (vty, "%02dw%dd%02dh",
581 tm->tm_yday/7,
582 tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
583 vty_out (vty, " ago%s", VTY_NEWLINE);
584 }
585
Christian Frankefa713d92013-07-05 15:35:37 +0000586 for (ALL_NEXTHOPS_RO(rib->nexthop, nexthop, tnexthop, recursing))
paul718e3742002-12-13 20:15:29 +0000587 {
Paul Jakma7514fb72007-05-02 16:05:35 +0000588 char addrstr[32];
589
Christian Frankefa713d92013-07-05 15:35:37 +0000590 vty_out (vty, " %c%s",
591 CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB) ? '*' : ' ',
592 recursing ? " " : "");
paul718e3742002-12-13 20:15:29 +0000593
594 switch (nexthop->type)
595 {
596 case NEXTHOP_TYPE_IPV4:
597 case NEXTHOP_TYPE_IPV4_IFINDEX:
598 vty_out (vty, " %s", inet_ntoa (nexthop->gate.ipv4));
599 if (nexthop->ifindex)
600 vty_out (vty, ", via %s", ifindex2ifname (nexthop->ifindex));
601 break;
602 case NEXTHOP_TYPE_IFINDEX:
603 vty_out (vty, " directly connected, %s",
604 ifindex2ifname (nexthop->ifindex));
605 break;
606 case NEXTHOP_TYPE_IFNAME:
607 vty_out (vty, " directly connected, %s", nexthop->ifname);
608 break;
paul595db7f2003-05-25 21:35:06 +0000609 case NEXTHOP_TYPE_BLACKHOLE:
paul7021c422003-07-15 12:52:22 +0000610 vty_out (vty, " directly connected, Null0");
paul595db7f2003-05-25 21:35:06 +0000611 break;
paul7021c422003-07-15 12:52:22 +0000612 default:
paul718e3742002-12-13 20:15:29 +0000613 break;
614 }
615 if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
616 vty_out (vty, " inactive");
617
Christian Frankee8d3d292013-07-05 15:35:39 +0000618 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ONLINK))
619 vty_out (vty, " onlink");
620
paul718e3742002-12-13 20:15:29 +0000621 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
Christian Frankefa713d92013-07-05 15:35:37 +0000622 vty_out (vty, " (recursive)");
Christian Franke5b9f5182013-05-25 14:01:34 +0000623
Paul Jakma7514fb72007-05-02 16:05:35 +0000624 switch (nexthop->type)
625 {
626 case NEXTHOP_TYPE_IPV4:
627 case NEXTHOP_TYPE_IPV4_IFINDEX:
628 case NEXTHOP_TYPE_IPV4_IFNAME:
629 if (nexthop->src.ipv4.s_addr)
630 {
631 if (inet_ntop(AF_INET, &nexthop->src.ipv4, addrstr,
632 sizeof addrstr))
633 vty_out (vty, ", src %s", addrstr);
634 }
635 break;
Andrew J. Schorr09303312007-05-30 20:10:34 +0000636#ifdef HAVE_IPV6
Paul Jakma7514fb72007-05-02 16:05:35 +0000637 case NEXTHOP_TYPE_IPV6:
638 case NEXTHOP_TYPE_IPV6_IFINDEX:
639 case NEXTHOP_TYPE_IPV6_IFNAME:
640 if (!IPV6_ADDR_SAME(&nexthop->src.ipv6, &in6addr_any))
641 {
642 if (inet_ntop(AF_INET6, &nexthop->src.ipv6, addrstr,
643 sizeof addrstr))
644 vty_out (vty, ", src %s", addrstr);
645 }
646 break;
Andrew J. Schorr09303312007-05-30 20:10:34 +0000647#endif /* HAVE_IPV6 */
Paul Jakma7514fb72007-05-02 16:05:35 +0000648 default:
649 break;
650 }
paul718e3742002-12-13 20:15:29 +0000651 vty_out (vty, "%s", VTY_NEWLINE);
652 }
653 vty_out (vty, "%s", VTY_NEWLINE);
654 }
655}
656
paula1ac18c2005-06-28 17:17:12 +0000657static void
paul718e3742002-12-13 20:15:29 +0000658vty_show_ip_route (struct vty *vty, struct route_node *rn, struct rib *rib)
659{
Christian Frankefa713d92013-07-05 15:35:37 +0000660 struct nexthop *nexthop, *tnexthop;
661 int recursing;
paul718e3742002-12-13 20:15:29 +0000662 int len = 0;
663 char buf[BUFSIZ];
664
665 /* Nexthop information. */
Christian Frankefa713d92013-07-05 15:35:37 +0000666 for (ALL_NEXTHOPS_RO(rib->nexthop, nexthop, tnexthop, recursing))
paul718e3742002-12-13 20:15:29 +0000667 {
668 if (nexthop == rib->nexthop)
669 {
670 /* Prefix information. */
671 len = vty_out (vty, "%c%c%c %s/%d",
ajsf52d13c2005-10-01 17:38:06 +0000672 zebra_route_char (rib->type),
paul718e3742002-12-13 20:15:29 +0000673 CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED)
674 ? '>' : ' ',
675 CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
676 ? '*' : ' ',
677 inet_ntop (AF_INET, &rn->p.u.prefix, buf, BUFSIZ),
678 rn->p.prefixlen);
679
680 /* Distance and metric display. */
681 if (rib->type != ZEBRA_ROUTE_CONNECT
682 && rib->type != ZEBRA_ROUTE_KERNEL)
683 len += vty_out (vty, " [%d/%d]", rib->distance,
684 rib->metric);
685 }
686 else
687 vty_out (vty, " %c%*c",
688 CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
689 ? '*' : ' ',
Christian Frankefa713d92013-07-05 15:35:37 +0000690 len - 3 + (2 * recursing), ' ');
paul718e3742002-12-13 20:15:29 +0000691
692 switch (nexthop->type)
693 {
694 case NEXTHOP_TYPE_IPV4:
695 case NEXTHOP_TYPE_IPV4_IFINDEX:
696 vty_out (vty, " via %s", inet_ntoa (nexthop->gate.ipv4));
697 if (nexthop->ifindex)
698 vty_out (vty, ", %s", ifindex2ifname (nexthop->ifindex));
699 break;
700 case NEXTHOP_TYPE_IFINDEX:
701 vty_out (vty, " is directly connected, %s",
702 ifindex2ifname (nexthop->ifindex));
703 break;
704 case NEXTHOP_TYPE_IFNAME:
705 vty_out (vty, " is directly connected, %s", nexthop->ifname);
706 break;
paul595db7f2003-05-25 21:35:06 +0000707 case NEXTHOP_TYPE_BLACKHOLE:
paul7021c422003-07-15 12:52:22 +0000708 vty_out (vty, " is directly connected, Null0");
paul595db7f2003-05-25 21:35:06 +0000709 break;
paul7021c422003-07-15 12:52:22 +0000710 default:
paul718e3742002-12-13 20:15:29 +0000711 break;
712 }
713 if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
714 vty_out (vty, " inactive");
715
Christian Frankee8d3d292013-07-05 15:35:39 +0000716 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ONLINK))
717 vty_out (vty, " onlink");
718
paul718e3742002-12-13 20:15:29 +0000719 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
Christian Frankefa713d92013-07-05 15:35:37 +0000720 vty_out (vty, " (recursive)");
721
Paul Jakma7514fb72007-05-02 16:05:35 +0000722 switch (nexthop->type)
723 {
724 case NEXTHOP_TYPE_IPV4:
725 case NEXTHOP_TYPE_IPV4_IFINDEX:
726 case NEXTHOP_TYPE_IPV4_IFNAME:
727 if (nexthop->src.ipv4.s_addr)
728 {
729 if (inet_ntop(AF_INET, &nexthop->src.ipv4, buf, sizeof buf))
730 vty_out (vty, ", src %s", buf);
731 }
732 break;
Andrew J. Schorr09303312007-05-30 20:10:34 +0000733#ifdef HAVE_IPV6
Paul Jakma7514fb72007-05-02 16:05:35 +0000734 case NEXTHOP_TYPE_IPV6:
735 case NEXTHOP_TYPE_IPV6_IFINDEX:
736 case NEXTHOP_TYPE_IPV6_IFNAME:
737 if (!IPV6_ADDR_SAME(&nexthop->src.ipv6, &in6addr_any))
738 {
739 if (inet_ntop(AF_INET6, &nexthop->src.ipv6, buf, sizeof buf))
740 vty_out (vty, ", src %s", buf);
741 }
742 break;
Andrew J. Schorr09303312007-05-30 20:10:34 +0000743#endif /* HAVE_IPV6 */
Paul Jakma7514fb72007-05-02 16:05:35 +0000744 default:
745 break;
746 }
paul718e3742002-12-13 20:15:29 +0000747
hasso81dfcaa2003-05-25 19:21:25 +0000748 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
749 vty_out (vty, ", bh");
750 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT))
751 vty_out (vty, ", rej");
752
paul718e3742002-12-13 20:15:29 +0000753 if (rib->type == ZEBRA_ROUTE_RIP
754 || rib->type == ZEBRA_ROUTE_OSPF
Juliusz Chroboczek578ce372012-02-09 13:42:28 +0100755 || rib->type == ZEBRA_ROUTE_BABEL
jardin9e867fe2003-12-23 08:56:18 +0000756 || rib->type == ZEBRA_ROUTE_ISIS
paul718e3742002-12-13 20:15:29 +0000757 || rib->type == ZEBRA_ROUTE_BGP)
758 {
759 time_t uptime;
760 struct tm *tm;
761
762 uptime = time (NULL);
763 uptime -= rib->uptime;
764 tm = gmtime (&uptime);
765
766#define ONE_DAY_SECOND 60*60*24
767#define ONE_WEEK_SECOND 60*60*24*7
768
769 if (uptime < ONE_DAY_SECOND)
770 vty_out (vty, ", %02d:%02d:%02d",
771 tm->tm_hour, tm->tm_min, tm->tm_sec);
772 else if (uptime < ONE_WEEK_SECOND)
773 vty_out (vty, ", %dd%02dh%02dm",
774 tm->tm_yday, tm->tm_hour, tm->tm_min);
775 else
776 vty_out (vty, ", %02dw%dd%02dh",
777 tm->tm_yday/7,
778 tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
779 }
780 vty_out (vty, "%s", VTY_NEWLINE);
781 }
782}
783
paul718e3742002-12-13 20:15:29 +0000784DEFUN (show_ip_route,
785 show_ip_route_cmd,
786 "show ip route",
787 SHOW_STR
788 IP_STR
789 "IP routing table\n")
790{
791 struct route_table *table;
792 struct route_node *rn;
793 struct rib *rib;
794 int first = 1;
795
796 table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
797 if (! table)
798 return CMD_SUCCESS;
799
800 /* Show all IPv4 routes. */
801 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000802 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +0000803 {
804 if (first)
805 {
David Lampartere0ca5fd2009-09-16 01:52:42 +0200806 vty_out (vty, SHOW_ROUTE_V4_HEADER);
paul718e3742002-12-13 20:15:29 +0000807 first = 0;
808 }
809 vty_show_ip_route (vty, rn, rib);
810 }
811 return CMD_SUCCESS;
812}
813
814DEFUN (show_ip_route_prefix_longer,
815 show_ip_route_prefix_longer_cmd,
816 "show ip route A.B.C.D/M longer-prefixes",
817 SHOW_STR
818 IP_STR
819 "IP routing table\n"
820 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
821 "Show route matching the specified Network/Mask pair only\n")
822{
823 struct route_table *table;
824 struct route_node *rn;
825 struct rib *rib;
826 struct prefix p;
827 int ret;
828 int first = 1;
829
830 ret = str2prefix (argv[0], &p);
831 if (! ret)
832 {
833 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
834 return CMD_WARNING;
835 }
836
837 table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
838 if (! table)
839 return CMD_SUCCESS;
840
841 /* Show matched type IPv4 routes. */
842 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000843 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +0000844 if (prefix_match (&p, &rn->p))
845 {
846 if (first)
847 {
David Lampartere0ca5fd2009-09-16 01:52:42 +0200848 vty_out (vty, SHOW_ROUTE_V4_HEADER);
paul718e3742002-12-13 20:15:29 +0000849 first = 0;
850 }
851 vty_show_ip_route (vty, rn, rib);
852 }
853 return CMD_SUCCESS;
854}
855
856DEFUN (show_ip_route_supernets,
857 show_ip_route_supernets_cmd,
858 "show ip route supernets-only",
859 SHOW_STR
860 IP_STR
861 "IP routing table\n"
862 "Show supernet entries only\n")
863{
864 struct route_table *table;
865 struct route_node *rn;
866 struct rib *rib;
867 u_int32_t addr;
868 int first = 1;
869
870 table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
871 if (! table)
872 return CMD_SUCCESS;
873
874 /* Show matched type IPv4 routes. */
875 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000876 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +0000877 {
878 addr = ntohl (rn->p.u.prefix4.s_addr);
879
880 if ((IN_CLASSC (addr) && rn->p.prefixlen < 24)
881 || (IN_CLASSB (addr) && rn->p.prefixlen < 16)
882 || (IN_CLASSA (addr) && rn->p.prefixlen < 8))
883 {
884 if (first)
885 {
David Lampartere0ca5fd2009-09-16 01:52:42 +0200886 vty_out (vty, SHOW_ROUTE_V4_HEADER);
paul718e3742002-12-13 20:15:29 +0000887 first = 0;
888 }
889 vty_show_ip_route (vty, rn, rib);
890 }
891 }
892 return CMD_SUCCESS;
893}
894
895DEFUN (show_ip_route_protocol,
896 show_ip_route_protocol_cmd,
David Lampartere0ca5fd2009-09-16 01:52:42 +0200897 "show ip route " QUAGGA_IP_REDIST_STR_ZEBRA,
paul718e3742002-12-13 20:15:29 +0000898 SHOW_STR
899 IP_STR
900 "IP routing table\n"
David Lampartere0ca5fd2009-09-16 01:52:42 +0200901 QUAGGA_IP_REDIST_HELP_STR_ZEBRA)
paul718e3742002-12-13 20:15:29 +0000902{
903 int type;
904 struct route_table *table;
905 struct route_node *rn;
906 struct rib *rib;
907 int first = 1;
908
David Lampartere0ca5fd2009-09-16 01:52:42 +0200909 type = proto_redistnum (AFI_IP, argv[0]);
910 if (type < 0)
paul718e3742002-12-13 20:15:29 +0000911 {
912 vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
913 return CMD_WARNING;
914 }
915
916 table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
917 if (! table)
918 return CMD_SUCCESS;
919
920 /* Show matched type IPv4 routes. */
921 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +0000922 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +0000923 if (rib->type == type)
924 {
925 if (first)
926 {
David Lampartere0ca5fd2009-09-16 01:52:42 +0200927 vty_out (vty, SHOW_ROUTE_V4_HEADER);
paul718e3742002-12-13 20:15:29 +0000928 first = 0;
929 }
930 vty_show_ip_route (vty, rn, rib);
931 }
932 return CMD_SUCCESS;
933}
934
935DEFUN (show_ip_route_addr,
936 show_ip_route_addr_cmd,
937 "show ip route A.B.C.D",
938 SHOW_STR
939 IP_STR
940 "IP routing table\n"
941 "Network in the IP routing table to display\n")
942{
943 int ret;
944 struct prefix_ipv4 p;
945 struct route_table *table;
946 struct route_node *rn;
947
948 ret = str2prefix_ipv4 (argv[0], &p);
949 if (ret <= 0)
950 {
951 vty_out (vty, "%% Malformed IPv4 address%s", VTY_NEWLINE);
952 return CMD_WARNING;
953 }
954
955 table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
956 if (! table)
957 return CMD_SUCCESS;
958
959 rn = route_node_match (table, (struct prefix *) &p);
960 if (! rn)
961 {
962 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
963 return CMD_WARNING;
964 }
965
966 vty_show_ip_route_detail (vty, rn);
967
968 route_unlock_node (rn);
969
970 return CMD_SUCCESS;
971}
972
973DEFUN (show_ip_route_prefix,
974 show_ip_route_prefix_cmd,
975 "show ip route A.B.C.D/M",
976 SHOW_STR
977 IP_STR
978 "IP routing table\n"
979 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
980{
981 int ret;
982 struct prefix_ipv4 p;
983 struct route_table *table;
984 struct route_node *rn;
985
986 ret = str2prefix_ipv4 (argv[0], &p);
987 if (ret <= 0)
988 {
989 vty_out (vty, "%% Malformed IPv4 address%s", VTY_NEWLINE);
990 return CMD_WARNING;
991 }
992
993 table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
994 if (! table)
995 return CMD_SUCCESS;
996
997 rn = route_node_match (table, (struct prefix *) &p);
998 if (! rn || rn->p.prefixlen != p.prefixlen)
999 {
1000 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
Lu Feng969d3552014-10-21 06:24:07 +00001001 if (rn)
1002 route_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00001003 return CMD_WARNING;
1004 }
1005
1006 vty_show_ip_route_detail (vty, rn);
1007
1008 route_unlock_node (rn);
1009
1010 return CMD_SUCCESS;
1011}
1012
paula1ac18c2005-06-28 17:17:12 +00001013static void
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001014vty_show_ip_route_summary (struct vty *vty, struct route_table *table)
paul718e3742002-12-13 20:15:29 +00001015{
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001016 struct route_node *rn;
1017 struct rib *rib;
1018 struct nexthop *nexthop;
1019#define ZEBRA_ROUTE_IBGP ZEBRA_ROUTE_MAX
1020#define ZEBRA_ROUTE_TOTAL (ZEBRA_ROUTE_IBGP + 1)
1021 u_int32_t rib_cnt[ZEBRA_ROUTE_TOTAL + 1];
1022 u_int32_t fib_cnt[ZEBRA_ROUTE_TOTAL + 1];
1023 u_int32_t i;
paul718e3742002-12-13 20:15:29 +00001024
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001025 memset (&rib_cnt, 0, sizeof(rib_cnt));
1026 memset (&fib_cnt, 0, sizeof(fib_cnt));
1027 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001028 RNODE_FOREACH_RIB (rn, rib)
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001029 for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
1030 {
1031 rib_cnt[ZEBRA_ROUTE_TOTAL]++;
1032 rib_cnt[rib->type]++;
Christian Frankefa713d92013-07-05 15:35:37 +00001033 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
1034 || nexthop_has_fib_child(nexthop))
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001035 {
1036 fib_cnt[ZEBRA_ROUTE_TOTAL]++;
1037 fib_cnt[rib->type]++;
1038 }
1039 if (rib->type == ZEBRA_ROUTE_BGP &&
1040 CHECK_FLAG (rib->flags, ZEBRA_FLAG_IBGP))
1041 {
1042 rib_cnt[ZEBRA_ROUTE_IBGP]++;
Christian Frankefa713d92013-07-05 15:35:37 +00001043 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
1044 || nexthop_has_fib_child(nexthop))
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001045 fib_cnt[ZEBRA_ROUTE_IBGP]++;
1046 }
1047 }
paul718e3742002-12-13 20:15:29 +00001048
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001049 vty_out (vty, "%-20s %-20s %-20s %s",
1050 "Route Source", "Routes", "FIB", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001051
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001052 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
1053 {
1054 if (rib_cnt[i] > 0)
1055 {
1056 if (i == ZEBRA_ROUTE_BGP)
1057 {
1058 vty_out (vty, "%-20s %-20d %-20d %s", "ebgp",
1059 rib_cnt[ZEBRA_ROUTE_BGP] - rib_cnt[ZEBRA_ROUTE_IBGP],
1060 fib_cnt[ZEBRA_ROUTE_BGP] - fib_cnt[ZEBRA_ROUTE_IBGP],
1061 VTY_NEWLINE);
1062 vty_out (vty, "%-20s %-20d %-20d %s", "ibgp",
1063 rib_cnt[ZEBRA_ROUTE_IBGP], fib_cnt[ZEBRA_ROUTE_IBGP],
1064 VTY_NEWLINE);
1065 }
1066 else
1067 vty_out (vty, "%-20s %-20d %-20d %s", zebra_route_string(i),
1068 rib_cnt[i], fib_cnt[i], VTY_NEWLINE);
1069 }
1070 }
paul718e3742002-12-13 20:15:29 +00001071
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001072 vty_out (vty, "------%s", VTY_NEWLINE);
1073 vty_out (vty, "%-20s %-20d %-20d %s", "Totals", rib_cnt[ZEBRA_ROUTE_TOTAL],
1074 fib_cnt[ZEBRA_ROUTE_TOTAL], VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001075}
1076
1077/* Show route summary. */
1078DEFUN (show_ip_route_summary,
1079 show_ip_route_summary_cmd,
1080 "show ip route summary",
1081 SHOW_STR
1082 IP_STR
1083 "IP routing table\n"
1084 "Summary of all routes\n")
1085{
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001086 struct route_table *table;
paul718e3742002-12-13 20:15:29 +00001087
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001088 table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
1089 if (! table)
1090 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001091
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001092 vty_show_ip_route_summary (vty, table);
paul718e3742002-12-13 20:15:29 +00001093
1094 return CMD_SUCCESS;
1095}
1096
1097/* Write IPv4 static route configuration. */
paula1ac18c2005-06-28 17:17:12 +00001098static int
paul718e3742002-12-13 20:15:29 +00001099static_config_ipv4 (struct vty *vty)
1100{
1101 struct route_node *rn;
1102 struct static_ipv4 *si;
1103 struct route_table *stable;
1104 int write;
1105
1106 write = 0;
1107
1108 /* Lookup table. */
1109 stable = vrf_static_table (AFI_IP, SAFI_UNICAST, 0);
1110 if (! stable)
1111 return -1;
1112
1113 for (rn = route_top (stable); rn; rn = route_next (rn))
1114 for (si = rn->info; si; si = si->next)
1115 {
paul7021c422003-07-15 12:52:22 +00001116 vty_out (vty, "ip route %s/%d", inet_ntoa (rn->p.u.prefix4),
1117 rn->p.prefixlen);
paul718e3742002-12-13 20:15:29 +00001118
paul7021c422003-07-15 12:52:22 +00001119 switch (si->type)
1120 {
1121 case STATIC_IPV4_GATEWAY:
1122 vty_out (vty, " %s", inet_ntoa (si->gate.ipv4));
1123 break;
1124 case STATIC_IPV4_IFNAME:
1125 vty_out (vty, " %s", si->gate.ifname);
1126 break;
1127 case STATIC_IPV4_BLACKHOLE:
1128 vty_out (vty, " Null0");
1129 break;
1130 }
1131
1132 /* flags are incompatible with STATIC_IPV4_BLACKHOLE */
1133 if (si->type != STATIC_IPV4_BLACKHOLE)
1134 {
1135 if (CHECK_FLAG(si->flags, ZEBRA_FLAG_REJECT))
1136 vty_out (vty, " %s", "reject");
paul718e3742002-12-13 20:15:29 +00001137
paul7021c422003-07-15 12:52:22 +00001138 if (CHECK_FLAG(si->flags, ZEBRA_FLAG_BLACKHOLE))
1139 vty_out (vty, " %s", "blackhole");
1140 }
hasso81dfcaa2003-05-25 19:21:25 +00001141
paul7021c422003-07-15 12:52:22 +00001142 if (si->distance != ZEBRA_STATIC_DISTANCE_DEFAULT)
1143 vty_out (vty, " %d", si->distance);
hasso81dfcaa2003-05-25 19:21:25 +00001144
paul7021c422003-07-15 12:52:22 +00001145 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00001146
paul7021c422003-07-15 12:52:22 +00001147 write = 1;
paul718e3742002-12-13 20:15:29 +00001148 }
1149 return write;
1150}
Andrew J. Schorr09303312007-05-30 20:10:34 +00001151
1152DEFUN (show_ip_protocol,
1153 show_ip_protocol_cmd,
1154 "show ip protocol",
1155 SHOW_STR
1156 IP_STR
1157 "IP protocol filtering status\n")
1158{
1159 int i;
1160
1161 vty_out(vty, "Protocol : route-map %s", VTY_NEWLINE);
1162 vty_out(vty, "------------------------%s", VTY_NEWLINE);
1163 for (i=0;i<ZEBRA_ROUTE_MAX;i++)
1164 {
1165 if (proto_rm[AFI_IP][i])
1166 vty_out (vty, "%-10s : %-10s%s", zebra_route_string(i),
1167 proto_rm[AFI_IP][i],
1168 VTY_NEWLINE);
1169 else
1170 vty_out (vty, "%-10s : none%s", zebra_route_string(i), VTY_NEWLINE);
1171 }
1172 if (proto_rm[AFI_IP][i])
1173 vty_out (vty, "%-10s : %-10s%s", "any", proto_rm[AFI_IP][i],
1174 VTY_NEWLINE);
1175 else
1176 vty_out (vty, "%-10s : none%s", "any", VTY_NEWLINE);
1177
1178 return CMD_SUCCESS;
1179}
1180
Joachim Nilsson36735ed2012-05-09 13:38:36 +02001181/*
1182 * Show IP mroute command to dump the BGP Multicast
1183 * routing table
1184 */
1185DEFUN (show_ip_mroute,
1186 show_ip_mroute_cmd,
1187 "show ip mroute",
1188 SHOW_STR
1189 IP_STR
1190 "IP Multicast routing table\n")
1191{
1192 struct route_table *table;
1193 struct route_node *rn;
1194 struct rib *rib;
1195 int first = 1;
1196
1197 table = vrf_table (AFI_IP, SAFI_MULTICAST, 0);
1198 if (! table)
1199 return CMD_SUCCESS;
1200
1201 /* Show all IPv4 routes. */
1202 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001203 RNODE_FOREACH_RIB (rn, rib)
Joachim Nilsson36735ed2012-05-09 13:38:36 +02001204 {
1205 if (first)
1206 {
1207 vty_out (vty, SHOW_ROUTE_V4_HEADER);
1208 first = 0;
1209 }
1210 vty_show_ip_route (vty, rn, rib);
1211 }
1212 return CMD_SUCCESS;
1213}
1214
David Lamparter6b0655a2014-06-04 06:53:35 +02001215
paul718e3742002-12-13 20:15:29 +00001216#ifdef HAVE_IPV6
1217/* General fucntion for IPv6 static route. */
paula1ac18c2005-06-28 17:17:12 +00001218static int
hasso39db97e2004-10-12 20:50:58 +00001219static_ipv6_func (struct vty *vty, int add_cmd, const char *dest_str,
1220 const char *gate_str, const char *ifname,
1221 const char *flag_str, const char *distance_str)
paul718e3742002-12-13 20:15:29 +00001222{
1223 int ret;
1224 u_char distance;
1225 struct prefix p;
1226 struct in6_addr *gate = NULL;
1227 struct in6_addr gate_addr;
1228 u_char type = 0;
1229 int table = 0;
hasso81dfcaa2003-05-25 19:21:25 +00001230 u_char flag = 0;
paul718e3742002-12-13 20:15:29 +00001231
1232 ret = str2prefix (dest_str, &p);
1233 if (ret <= 0)
1234 {
1235 vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
1236 return CMD_WARNING;
1237 }
1238
1239 /* Apply mask for given prefix. */
1240 apply_mask (&p);
1241
hasso81dfcaa2003-05-25 19:21:25 +00001242 /* Route flags */
1243 if (flag_str) {
1244 switch(flag_str[0]) {
1245 case 'r':
1246 case 'R': /* XXX */
1247 SET_FLAG (flag, ZEBRA_FLAG_REJECT);
1248 break;
1249 case 'b':
1250 case 'B': /* XXX */
1251 SET_FLAG (flag, ZEBRA_FLAG_BLACKHOLE);
1252 break;
1253 default:
1254 vty_out (vty, "%% Malformed flag %s %s", flag_str, VTY_NEWLINE);
paul595db7f2003-05-25 21:35:06 +00001255 return CMD_WARNING;
hasso81dfcaa2003-05-25 19:21:25 +00001256 }
1257 }
1258
paul718e3742002-12-13 20:15:29 +00001259 /* Administrative distance. */
1260 if (distance_str)
1261 distance = atoi (distance_str);
1262 else
1263 distance = ZEBRA_STATIC_DISTANCE_DEFAULT;
1264
1265 /* When gateway is valid IPv6 addrees, then gate is treated as
1266 nexthop address other case gate is treated as interface name. */
1267 ret = inet_pton (AF_INET6, gate_str, &gate_addr);
1268
1269 if (ifname)
1270 {
1271 /* When ifname is specified. It must be come with gateway
1272 address. */
1273 if (ret != 1)
1274 {
1275 vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
1276 return CMD_WARNING;
1277 }
1278 type = STATIC_IPV6_GATEWAY_IFNAME;
1279 gate = &gate_addr;
1280 }
1281 else
1282 {
1283 if (ret == 1)
1284 {
1285 type = STATIC_IPV6_GATEWAY;
1286 gate = &gate_addr;
1287 }
1288 else
1289 {
1290 type = STATIC_IPV6_IFNAME;
1291 ifname = gate_str;
1292 }
1293 }
1294
1295 if (add_cmd)
hasso81dfcaa2003-05-25 19:21:25 +00001296 static_add_ipv6 (&p, type, gate, ifname, flag, distance, table);
paul718e3742002-12-13 20:15:29 +00001297 else
1298 static_delete_ipv6 (&p, type, gate, ifname, distance, table);
1299
1300 return CMD_SUCCESS;
1301}
1302
1303DEFUN (ipv6_route,
1304 ipv6_route_cmd,
1305 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE)",
1306 IP_STR
1307 "Establish static routes\n"
1308 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1309 "IPv6 gateway address\n"
1310 "IPv6 gateway interface name\n")
1311{
hasso81dfcaa2003-05-25 19:21:25 +00001312 return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, NULL, NULL);
1313}
1314
1315DEFUN (ipv6_route_flags,
1316 ipv6_route_flags_cmd,
1317 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole)",
1318 IP_STR
1319 "Establish static routes\n"
1320 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1321 "IPv6 gateway address\n"
1322 "IPv6 gateway interface name\n"
1323 "Emit an ICMP unreachable when matched\n"
1324 "Silently discard pkts when matched\n")
1325{
1326 return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, argv[2], NULL);
paul718e3742002-12-13 20:15:29 +00001327}
1328
1329DEFUN (ipv6_route_ifname,
1330 ipv6_route_ifname_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], argv[2], NULL, NULL);
1339}
1340
1341DEFUN (ipv6_route_ifname_flags,
1342 ipv6_route_ifname_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], argv[2], argv[3], NULL);
paul718e3742002-12-13 20:15:29 +00001353}
1354
1355DEFUN (ipv6_route_pref,
1356 ipv6_route_pref_cmd,
1357 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <1-255>",
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 "Distance value for this prefix\n")
1364{
hasso81dfcaa2003-05-25 19:21:25 +00001365 return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, NULL, argv[2]);
1366}
1367
1368DEFUN (ipv6_route_flags_pref,
1369 ipv6_route_flags_pref_cmd,
1370 "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) <1-255>",
1371 IP_STR
1372 "Establish static routes\n"
1373 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1374 "IPv6 gateway address\n"
1375 "IPv6 gateway interface name\n"
1376 "Emit an ICMP unreachable when matched\n"
1377 "Silently discard pkts when matched\n"
1378 "Distance value for this prefix\n")
1379{
1380 return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, argv[2], argv[3]);
paul718e3742002-12-13 20:15:29 +00001381}
1382
1383DEFUN (ipv6_route_ifname_pref,
1384 ipv6_route_ifname_pref_cmd,
1385 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255>",
1386 IP_STR
1387 "Establish static routes\n"
1388 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1389 "IPv6 gateway address\n"
1390 "IPv6 gateway interface name\n"
1391 "Distance value for this prefix\n")
1392{
hasso81dfcaa2003-05-25 19:21:25 +00001393 return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], NULL, argv[3]);
1394}
1395
1396DEFUN (ipv6_route_ifname_flags_pref,
1397 ipv6_route_ifname_flags_pref_cmd,
1398 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) <1-255>",
1399 IP_STR
1400 "Establish static routes\n"
1401 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1402 "IPv6 gateway address\n"
1403 "IPv6 gateway interface name\n"
1404 "Emit an ICMP unreachable when matched\n"
1405 "Silently discard pkts when matched\n"
1406 "Distance value for this prefix\n")
1407{
1408 return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], argv[3], argv[4]);
paul718e3742002-12-13 20:15:29 +00001409}
1410
1411DEFUN (no_ipv6_route,
1412 no_ipv6_route_cmd,
1413 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE)",
1414 NO_STR
1415 IP_STR
1416 "Establish static routes\n"
1417 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1418 "IPv6 gateway address\n"
1419 "IPv6 gateway interface name\n")
1420{
hasso81dfcaa2003-05-25 19:21:25 +00001421 return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00001422}
1423
hasso81dfcaa2003-05-25 19:21:25 +00001424ALIAS (no_ipv6_route,
1425 no_ipv6_route_flags_cmd,
1426 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole)",
1427 NO_STR
1428 IP_STR
1429 "Establish static routes\n"
1430 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1431 "IPv6 gateway address\n"
1432 "IPv6 gateway interface name\n"
1433 "Emit an ICMP unreachable when matched\n"
1434 "Silently discard pkts when matched\n")
1435
paul718e3742002-12-13 20:15:29 +00001436DEFUN (no_ipv6_route_ifname,
1437 no_ipv6_route_ifname_cmd,
1438 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE",
1439 NO_STR
1440 IP_STR
1441 "Establish static routes\n"
1442 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1443 "IPv6 gateway address\n"
1444 "IPv6 gateway interface name\n")
1445{
hasso81dfcaa2003-05-25 19:21:25 +00001446 return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], NULL, NULL);
paul718e3742002-12-13 20:15:29 +00001447}
1448
hasso81dfcaa2003-05-25 19:21:25 +00001449ALIAS (no_ipv6_route_ifname,
1450 no_ipv6_route_ifname_flags_cmd,
1451 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole)",
1452 NO_STR
1453 IP_STR
1454 "Establish static routes\n"
1455 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1456 "IPv6 gateway address\n"
1457 "IPv6 gateway interface name\n"
1458 "Emit an ICMP unreachable when matched\n"
1459 "Silently discard pkts when matched\n")
1460
paul718e3742002-12-13 20:15:29 +00001461DEFUN (no_ipv6_route_pref,
1462 no_ipv6_route_pref_cmd,
1463 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <1-255>",
1464 NO_STR
1465 IP_STR
1466 "Establish static routes\n"
1467 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1468 "IPv6 gateway address\n"
1469 "IPv6 gateway interface name\n"
1470 "Distance value for this prefix\n")
1471{
hasso81dfcaa2003-05-25 19:21:25 +00001472 return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, NULL, argv[2]);
1473}
1474
1475DEFUN (no_ipv6_route_flags_pref,
1476 no_ipv6_route_flags_pref_cmd,
1477 "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) <1-255>",
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 "Distance value for this prefix\n")
1487{
1488 /* We do not care about argv[2] */
1489 return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, argv[2], argv[3]);
paul718e3742002-12-13 20:15:29 +00001490}
1491
1492DEFUN (no_ipv6_route_ifname_pref,
1493 no_ipv6_route_ifname_pref_cmd,
1494 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255>",
1495 NO_STR
1496 IP_STR
1497 "Establish static routes\n"
1498 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1499 "IPv6 gateway address\n"
1500 "IPv6 gateway interface name\n"
1501 "Distance value for this prefix\n")
1502{
hasso81dfcaa2003-05-25 19:21:25 +00001503 return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], NULL, argv[3]);
1504}
1505
1506DEFUN (no_ipv6_route_ifname_flags_pref,
1507 no_ipv6_route_ifname_flags_pref_cmd,
1508 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) <1-255>",
1509 NO_STR
1510 IP_STR
1511 "Establish static routes\n"
1512 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
1513 "IPv6 gateway address\n"
1514 "IPv6 gateway interface name\n"
1515 "Emit an ICMP unreachable when matched\n"
1516 "Silently discard pkts when matched\n"
1517 "Distance value for this prefix\n")
1518{
1519 return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], argv[3], argv[4]);
paul718e3742002-12-13 20:15:29 +00001520}
1521
paul595db7f2003-05-25 21:35:06 +00001522/* New RIB. Detailed information for IPv6 route. */
paula1ac18c2005-06-28 17:17:12 +00001523static void
paul718e3742002-12-13 20:15:29 +00001524vty_show_ipv6_route_detail (struct vty *vty, struct route_node *rn)
1525{
1526 struct rib *rib;
Christian Frankefa713d92013-07-05 15:35:37 +00001527 struct nexthop *nexthop, *tnexthop;
1528 int recursing;
paul718e3742002-12-13 20:15:29 +00001529 char buf[BUFSIZ];
1530
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001531 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +00001532 {
1533 vty_out (vty, "Routing entry for %s/%d%s",
1534 inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, BUFSIZ),
1535 rn->p.prefixlen,
1536 VTY_NEWLINE);
ajsf52d13c2005-10-01 17:38:06 +00001537 vty_out (vty, " Known via \"%s\"", zebra_route_string (rib->type));
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02001538 vty_out (vty, ", distance %u, metric %u", rib->distance, rib->metric);
paul718e3742002-12-13 20:15:29 +00001539 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
1540 vty_out (vty, ", best");
1541 if (rib->refcnt)
1542 vty_out (vty, ", refcnt %ld", rib->refcnt);
hasso81dfcaa2003-05-25 19:21:25 +00001543 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
1544 vty_out (vty, ", blackhole");
1545 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT))
1546 vty_out (vty, ", reject");
paul718e3742002-12-13 20:15:29 +00001547 vty_out (vty, "%s", VTY_NEWLINE);
1548
1549#define ONE_DAY_SECOND 60*60*24
1550#define ONE_WEEK_SECOND 60*60*24*7
1551 if (rib->type == ZEBRA_ROUTE_RIPNG
1552 || rib->type == ZEBRA_ROUTE_OSPF6
Juliusz Chroboczek578ce372012-02-09 13:42:28 +01001553 || rib->type == ZEBRA_ROUTE_BABEL
jardin9e867fe2003-12-23 08:56:18 +00001554 || rib->type == ZEBRA_ROUTE_ISIS
paul718e3742002-12-13 20:15:29 +00001555 || rib->type == ZEBRA_ROUTE_BGP)
1556 {
1557 time_t uptime;
1558 struct tm *tm;
1559
1560 uptime = time (NULL);
1561 uptime -= rib->uptime;
1562 tm = gmtime (&uptime);
1563
1564 vty_out (vty, " Last update ");
1565
1566 if (uptime < ONE_DAY_SECOND)
1567 vty_out (vty, "%02d:%02d:%02d",
1568 tm->tm_hour, tm->tm_min, tm->tm_sec);
1569 else if (uptime < ONE_WEEK_SECOND)
1570 vty_out (vty, "%dd%02dh%02dm",
1571 tm->tm_yday, tm->tm_hour, tm->tm_min);
1572 else
1573 vty_out (vty, "%02dw%dd%02dh",
1574 tm->tm_yday/7,
1575 tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
1576 vty_out (vty, " ago%s", VTY_NEWLINE);
1577 }
1578
Christian Frankefa713d92013-07-05 15:35:37 +00001579 for (ALL_NEXTHOPS_RO(rib->nexthop, nexthop, tnexthop, recursing))
paul718e3742002-12-13 20:15:29 +00001580 {
Christian Frankefa713d92013-07-05 15:35:37 +00001581 vty_out (vty, " %c%s",
1582 CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB) ? '*' : ' ',
1583 recursing ? " " : "");
paul718e3742002-12-13 20:15:29 +00001584
1585 switch (nexthop->type)
1586 {
1587 case NEXTHOP_TYPE_IPV6:
1588 case NEXTHOP_TYPE_IPV6_IFINDEX:
1589 case NEXTHOP_TYPE_IPV6_IFNAME:
1590 vty_out (vty, " %s",
1591 inet_ntop (AF_INET6, &nexthop->gate.ipv6, buf, BUFSIZ));
1592 if (nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME)
1593 vty_out (vty, ", %s", nexthop->ifname);
1594 else if (nexthop->ifindex)
1595 vty_out (vty, ", via %s", ifindex2ifname (nexthop->ifindex));
1596 break;
1597 case NEXTHOP_TYPE_IFINDEX:
1598 vty_out (vty, " directly connected, %s",
1599 ifindex2ifname (nexthop->ifindex));
1600 break;
1601 case NEXTHOP_TYPE_IFNAME:
1602 vty_out (vty, " directly connected, %s",
1603 nexthop->ifname);
1604 break;
1605 default:
1606 break;
1607 }
1608 if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
1609 vty_out (vty, " inactive");
1610
Christian Frankee8d3d292013-07-05 15:35:39 +00001611 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ONLINK))
1612 vty_out (vty, " onlink");
1613
paul718e3742002-12-13 20:15:29 +00001614 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
Christian Frankefa713d92013-07-05 15:35:37 +00001615 vty_out (vty, " (recursive)");
1616
paul718e3742002-12-13 20:15:29 +00001617 vty_out (vty, "%s", VTY_NEWLINE);
1618 }
1619 vty_out (vty, "%s", VTY_NEWLINE);
1620 }
1621}
1622
paula1ac18c2005-06-28 17:17:12 +00001623static void
paul718e3742002-12-13 20:15:29 +00001624vty_show_ipv6_route (struct vty *vty, struct route_node *rn,
1625 struct rib *rib)
1626{
Christian Frankefa713d92013-07-05 15:35:37 +00001627 struct nexthop *nexthop, *tnexthop;
1628 int recursing;
paul718e3742002-12-13 20:15:29 +00001629 int len = 0;
1630 char buf[BUFSIZ];
1631
1632 /* Nexthop information. */
Christian Frankefa713d92013-07-05 15:35:37 +00001633 for (ALL_NEXTHOPS_RO(rib->nexthop, nexthop, tnexthop, recursing))
paul718e3742002-12-13 20:15:29 +00001634 {
1635 if (nexthop == rib->nexthop)
1636 {
1637 /* Prefix information. */
1638 len = vty_out (vty, "%c%c%c %s/%d",
ajsf52d13c2005-10-01 17:38:06 +00001639 zebra_route_char (rib->type),
paul718e3742002-12-13 20:15:29 +00001640 CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED)
1641 ? '>' : ' ',
1642 CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
1643 ? '*' : ' ',
1644 inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, BUFSIZ),
1645 rn->p.prefixlen);
1646
1647 /* Distance and metric display. */
1648 if (rib->type != ZEBRA_ROUTE_CONNECT
1649 && rib->type != ZEBRA_ROUTE_KERNEL)
1650 len += vty_out (vty, " [%d/%d]", rib->distance,
1651 rib->metric);
1652 }
1653 else
1654 vty_out (vty, " %c%*c",
1655 CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
1656 ? '*' : ' ',
Christian Frankefa713d92013-07-05 15:35:37 +00001657 len - 3 + (2 * recursing), ' ');
paul718e3742002-12-13 20:15:29 +00001658
1659 switch (nexthop->type)
1660 {
1661 case NEXTHOP_TYPE_IPV6:
1662 case NEXTHOP_TYPE_IPV6_IFINDEX:
1663 case NEXTHOP_TYPE_IPV6_IFNAME:
1664 vty_out (vty, " via %s",
1665 inet_ntop (AF_INET6, &nexthop->gate.ipv6, buf, BUFSIZ));
1666 if (nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME)
1667 vty_out (vty, ", %s", nexthop->ifname);
1668 else if (nexthop->ifindex)
1669 vty_out (vty, ", %s", ifindex2ifname (nexthop->ifindex));
1670 break;
1671 case NEXTHOP_TYPE_IFINDEX:
1672 vty_out (vty, " is directly connected, %s",
1673 ifindex2ifname (nexthop->ifindex));
1674 break;
1675 case NEXTHOP_TYPE_IFNAME:
1676 vty_out (vty, " is directly connected, %s",
1677 nexthop->ifname);
1678 break;
1679 default:
1680 break;
1681 }
1682 if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
1683 vty_out (vty, " inactive");
1684
1685 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
Christian Frankefa713d92013-07-05 15:35:37 +00001686 vty_out (vty, " (recursive)");
paul718e3742002-12-13 20:15:29 +00001687
hasso81dfcaa2003-05-25 19:21:25 +00001688 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
1689 vty_out (vty, ", bh");
1690 if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT))
1691 vty_out (vty, ", rej");
1692
paul718e3742002-12-13 20:15:29 +00001693 if (rib->type == ZEBRA_ROUTE_RIPNG
1694 || rib->type == ZEBRA_ROUTE_OSPF6
Juliusz Chroboczek578ce372012-02-09 13:42:28 +01001695 || rib->type == ZEBRA_ROUTE_BABEL
jardin9e867fe2003-12-23 08:56:18 +00001696 || rib->type == ZEBRA_ROUTE_ISIS
paul718e3742002-12-13 20:15:29 +00001697 || rib->type == ZEBRA_ROUTE_BGP)
1698 {
1699 time_t uptime;
1700 struct tm *tm;
1701
1702 uptime = time (NULL);
1703 uptime -= rib->uptime;
1704 tm = gmtime (&uptime);
1705
1706#define ONE_DAY_SECOND 60*60*24
1707#define ONE_WEEK_SECOND 60*60*24*7
1708
1709 if (uptime < ONE_DAY_SECOND)
1710 vty_out (vty, ", %02d:%02d:%02d",
1711 tm->tm_hour, tm->tm_min, tm->tm_sec);
1712 else if (uptime < ONE_WEEK_SECOND)
1713 vty_out (vty, ", %dd%02dh%02dm",
1714 tm->tm_yday, tm->tm_hour, tm->tm_min);
1715 else
1716 vty_out (vty, ", %02dw%dd%02dh",
1717 tm->tm_yday/7,
1718 tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
1719 }
1720 vty_out (vty, "%s", VTY_NEWLINE);
1721 }
1722}
1723
paul718e3742002-12-13 20:15:29 +00001724DEFUN (show_ipv6_route,
1725 show_ipv6_route_cmd,
1726 "show ipv6 route",
1727 SHOW_STR
1728 IP_STR
1729 "IPv6 routing table\n")
1730{
1731 struct route_table *table;
1732 struct route_node *rn;
1733 struct rib *rib;
1734 int first = 1;
1735
1736 table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
1737 if (! table)
1738 return CMD_SUCCESS;
1739
1740 /* Show all IPv6 route. */
1741 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001742 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +00001743 {
1744 if (first)
1745 {
David Lampartere0ca5fd2009-09-16 01:52:42 +02001746 vty_out (vty, SHOW_ROUTE_V6_HEADER);
paul718e3742002-12-13 20:15:29 +00001747 first = 0;
1748 }
1749 vty_show_ipv6_route (vty, rn, rib);
1750 }
1751 return CMD_SUCCESS;
1752}
1753
1754DEFUN (show_ipv6_route_prefix_longer,
1755 show_ipv6_route_prefix_longer_cmd,
1756 "show ipv6 route X:X::X:X/M longer-prefixes",
1757 SHOW_STR
1758 IP_STR
1759 "IPv6 routing table\n"
1760 "IPv6 prefix\n"
1761 "Show route matching the specified Network/Mask pair only\n")
1762{
1763 struct route_table *table;
1764 struct route_node *rn;
1765 struct rib *rib;
1766 struct prefix p;
1767 int ret;
1768 int first = 1;
1769
1770 table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
1771 if (! table)
1772 return CMD_SUCCESS;
1773
1774 ret = str2prefix (argv[0], &p);
1775 if (! ret)
1776 {
1777 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
1778 return CMD_WARNING;
1779 }
1780
1781 /* Show matched type IPv6 routes. */
1782 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001783 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +00001784 if (prefix_match (&p, &rn->p))
1785 {
1786 if (first)
1787 {
David Lampartere0ca5fd2009-09-16 01:52:42 +02001788 vty_out (vty, SHOW_ROUTE_V6_HEADER);
paul718e3742002-12-13 20:15:29 +00001789 first = 0;
1790 }
1791 vty_show_ipv6_route (vty, rn, rib);
1792 }
1793 return CMD_SUCCESS;
1794}
1795
1796DEFUN (show_ipv6_route_protocol,
1797 show_ipv6_route_protocol_cmd,
David Lampartere0ca5fd2009-09-16 01:52:42 +02001798 "show ipv6 route " QUAGGA_IP6_REDIST_STR_ZEBRA,
paul718e3742002-12-13 20:15:29 +00001799 SHOW_STR
1800 IP_STR
1801 "IP routing table\n"
David Lampartere0ca5fd2009-09-16 01:52:42 +02001802 QUAGGA_IP6_REDIST_HELP_STR_ZEBRA)
paul718e3742002-12-13 20:15:29 +00001803{
1804 int type;
1805 struct route_table *table;
1806 struct route_node *rn;
1807 struct rib *rib;
1808 int first = 1;
1809
David Lampartere0ca5fd2009-09-16 01:52:42 +02001810 type = proto_redistnum (AFI_IP6, argv[0]);
1811 if (type < 0)
paul718e3742002-12-13 20:15:29 +00001812 {
1813 vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
1814 return CMD_WARNING;
1815 }
1816
1817 table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
1818 if (! table)
1819 return CMD_SUCCESS;
1820
1821 /* Show matched type IPv6 routes. */
1822 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001823 RNODE_FOREACH_RIB (rn, rib)
paul718e3742002-12-13 20:15:29 +00001824 if (rib->type == type)
1825 {
1826 if (first)
1827 {
David Lampartere0ca5fd2009-09-16 01:52:42 +02001828 vty_out (vty, SHOW_ROUTE_V6_HEADER);
paul718e3742002-12-13 20:15:29 +00001829 first = 0;
1830 }
1831 vty_show_ipv6_route (vty, rn, rib);
1832 }
1833 return CMD_SUCCESS;
1834}
1835
1836DEFUN (show_ipv6_route_addr,
1837 show_ipv6_route_addr_cmd,
1838 "show ipv6 route X:X::X:X",
1839 SHOW_STR
1840 IP_STR
1841 "IPv6 routing table\n"
1842 "IPv6 Address\n")
1843{
1844 int ret;
1845 struct prefix_ipv6 p;
1846 struct route_table *table;
1847 struct route_node *rn;
1848
1849 ret = str2prefix_ipv6 (argv[0], &p);
1850 if (ret <= 0)
1851 {
1852 vty_out (vty, "Malformed IPv6 address%s", VTY_NEWLINE);
1853 return CMD_WARNING;
1854 }
1855
1856 table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
1857 if (! table)
1858 return CMD_SUCCESS;
1859
1860 rn = route_node_match (table, (struct prefix *) &p);
1861 if (! rn)
1862 {
1863 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
1864 return CMD_WARNING;
1865 }
1866
1867 vty_show_ipv6_route_detail (vty, rn);
1868
1869 route_unlock_node (rn);
1870
1871 return CMD_SUCCESS;
1872}
1873
1874DEFUN (show_ipv6_route_prefix,
1875 show_ipv6_route_prefix_cmd,
1876 "show ipv6 route X:X::X:X/M",
1877 SHOW_STR
1878 IP_STR
1879 "IPv6 routing table\n"
1880 "IPv6 prefix\n")
1881{
1882 int ret;
1883 struct prefix_ipv6 p;
1884 struct route_table *table;
1885 struct route_node *rn;
1886
1887 ret = str2prefix_ipv6 (argv[0], &p);
1888 if (ret <= 0)
1889 {
1890 vty_out (vty, "Malformed IPv6 prefix%s", VTY_NEWLINE);
1891 return CMD_WARNING;
1892 }
1893
1894 table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
1895 if (! table)
1896 return CMD_SUCCESS;
1897
1898 rn = route_node_match (table, (struct prefix *) &p);
1899 if (! rn || rn->p.prefixlen != p.prefixlen)
1900 {
1901 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
Lu Feng969d3552014-10-21 06:24:07 +00001902 if (rn)
1903 route_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00001904 return CMD_WARNING;
1905 }
1906
1907 vty_show_ipv6_route_detail (vty, rn);
1908
1909 route_unlock_node (rn);
1910
1911 return CMD_SUCCESS;
1912}
1913
Stig Thormodsrud61691c92008-11-04 15:45:07 -08001914/* Show route summary. */
1915DEFUN (show_ipv6_route_summary,
1916 show_ipv6_route_summary_cmd,
1917 "show ipv6 route summary",
1918 SHOW_STR
1919 IP_STR
1920 "IPv6 routing table\n"
1921 "Summary of all IPv6 routes\n")
1922{
1923 struct route_table *table;
1924
1925 table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
1926 if (! table)
1927 return CMD_SUCCESS;
1928
1929 vty_show_ip_route_summary (vty, table);
1930
1931 return CMD_SUCCESS;
1932}
1933
G.Balajicddf3912011-11-26 21:59:32 +04001934/*
G.Balajicddf3912011-11-26 21:59:32 +04001935 * Show IPv6 mroute command.Used to dump
1936 * the Multicast routing table.
1937 */
1938
1939DEFUN (show_ipv6_mroute,
1940 show_ipv6_mroute_cmd,
1941 "show ipv6 mroute",
1942 SHOW_STR
1943 IP_STR
1944 "IPv6 Multicast routing table\n")
1945{
1946 struct route_table *table;
1947 struct route_node *rn;
1948 struct rib *rib;
1949 int first = 1;
1950
1951 table = vrf_table (AFI_IP6, SAFI_MULTICAST, 0);
1952 if (! table)
1953 return CMD_SUCCESS;
1954
1955 /* Show all IPv6 route. */
1956 for (rn = route_top (table); rn; rn = route_next (rn))
Avneesh Sachdev9fd92e32012-11-13 22:48:53 +00001957 RNODE_FOREACH_RIB (rn, rib)
G.Balajicddf3912011-11-26 21:59:32 +04001958 {
1959 if (first)
1960 {
G.Balajicb32fd62011-11-27 20:09:40 +05301961 vty_out (vty, SHOW_ROUTE_V6_HEADER);
G.Balajicddf3912011-11-26 21:59:32 +04001962 first = 0;
1963 }
1964 vty_show_ipv6_route (vty, rn, rib);
1965 }
1966 return CMD_SUCCESS;
1967}
1968
paul718e3742002-12-13 20:15:29 +00001969/* Write IPv6 static route configuration. */
paula1ac18c2005-06-28 17:17:12 +00001970static int
paul718e3742002-12-13 20:15:29 +00001971static_config_ipv6 (struct vty *vty)
1972{
1973 struct route_node *rn;
1974 struct static_ipv6 *si;
1975 int write;
1976 char buf[BUFSIZ];
1977 struct route_table *stable;
1978
1979 write = 0;
1980
1981 /* Lookup table. */
1982 stable = vrf_static_table (AFI_IP6, SAFI_UNICAST, 0);
1983 if (! stable)
1984 return -1;
1985
1986 for (rn = route_top (stable); rn; rn = route_next (rn))
1987 for (si = rn->info; si; si = si->next)
1988 {
1989 vty_out (vty, "ipv6 route %s/%d",
1990 inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, BUFSIZ),
1991 rn->p.prefixlen);
1992
1993 switch (si->type)
1994 {
1995 case STATIC_IPV6_GATEWAY:
1996 vty_out (vty, " %s", inet_ntop (AF_INET6, &si->ipv6, buf, BUFSIZ));
1997 break;
1998 case STATIC_IPV6_IFNAME:
1999 vty_out (vty, " %s", si->ifname);
2000 break;
2001 case STATIC_IPV6_GATEWAY_IFNAME:
2002 vty_out (vty, " %s %s",
2003 inet_ntop (AF_INET6, &si->ipv6, buf, BUFSIZ), si->ifname);
2004 break;
2005 }
2006
hasso81dfcaa2003-05-25 19:21:25 +00002007 if (CHECK_FLAG(si->flags, ZEBRA_FLAG_REJECT))
2008 vty_out (vty, " %s", "reject");
2009
2010 if (CHECK_FLAG(si->flags, ZEBRA_FLAG_BLACKHOLE))
2011 vty_out (vty, " %s", "blackhole");
2012
paul718e3742002-12-13 20:15:29 +00002013 if (si->distance != ZEBRA_STATIC_DISTANCE_DEFAULT)
2014 vty_out (vty, " %d", si->distance);
2015 vty_out (vty, "%s", VTY_NEWLINE);
2016
2017 write = 1;
2018 }
2019 return write;
2020}
2021#endif /* HAVE_IPV6 */
2022
2023/* Static ip route configuration write function. */
paula1ac18c2005-06-28 17:17:12 +00002024static int
paul718e3742002-12-13 20:15:29 +00002025zebra_ip_config (struct vty *vty)
2026{
2027 int write = 0;
2028
2029 write += static_config_ipv4 (vty);
2030#ifdef HAVE_IPV6
2031 write += static_config_ipv6 (vty);
2032#endif /* HAVE_IPV6 */
2033
2034 return write;
2035}
2036
Paul Jakma7514fb72007-05-02 16:05:35 +00002037/* ip protocol configuration write function */
2038static int config_write_protocol(struct vty *vty)
2039{
2040 int i;
2041
2042 for (i=0;i<ZEBRA_ROUTE_MAX;i++)
2043 {
2044 if (proto_rm[AFI_IP][i])
2045 vty_out (vty, "ip protocol %s route-map %s%s", zebra_route_string(i),
2046 proto_rm[AFI_IP][i], VTY_NEWLINE);
2047 }
2048 if (proto_rm[AFI_IP][ZEBRA_ROUTE_MAX])
2049 vty_out (vty, "ip protocol %s route-map %s%s", "any",
2050 proto_rm[AFI_IP][ZEBRA_ROUTE_MAX], VTY_NEWLINE);
2051
2052 return 1;
2053}
2054
2055/* table node for protocol filtering */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -08002056static struct cmd_node protocol_node = { PROTOCOL_NODE, "", 1 };
Paul Jakma7514fb72007-05-02 16:05:35 +00002057
paul718e3742002-12-13 20:15:29 +00002058/* IP node for static routes. */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -08002059static struct cmd_node ip_node = { IP_NODE, "", 1 };
paul718e3742002-12-13 20:15:29 +00002060
2061/* Route VTY. */
2062void
paula1ac18c2005-06-28 17:17:12 +00002063zebra_vty_init (void)
paul718e3742002-12-13 20:15:29 +00002064{
2065 install_node (&ip_node, zebra_ip_config);
Paul Jakma7514fb72007-05-02 16:05:35 +00002066 install_node (&protocol_node, config_write_protocol);
paul718e3742002-12-13 20:15:29 +00002067
Paul Jakma7514fb72007-05-02 16:05:35 +00002068 install_element (CONFIG_NODE, &ip_protocol_cmd);
2069 install_element (CONFIG_NODE, &no_ip_protocol_cmd);
2070 install_element (VIEW_NODE, &show_ip_protocol_cmd);
2071 install_element (ENABLE_NODE, &show_ip_protocol_cmd);
paul718e3742002-12-13 20:15:29 +00002072 install_element (CONFIG_NODE, &ip_route_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002073 install_element (CONFIG_NODE, &ip_route_flags_cmd);
hasso457ef552003-05-28 12:02:15 +00002074 install_element (CONFIG_NODE, &ip_route_flags2_cmd);
paul718e3742002-12-13 20:15:29 +00002075 install_element (CONFIG_NODE, &ip_route_mask_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002076 install_element (CONFIG_NODE, &ip_route_mask_flags_cmd);
hasso457ef552003-05-28 12:02:15 +00002077 install_element (CONFIG_NODE, &ip_route_mask_flags2_cmd);
paul718e3742002-12-13 20:15:29 +00002078 install_element (CONFIG_NODE, &no_ip_route_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002079 install_element (CONFIG_NODE, &no_ip_route_flags_cmd);
hasso457ef552003-05-28 12:02:15 +00002080 install_element (CONFIG_NODE, &no_ip_route_flags2_cmd);
paul718e3742002-12-13 20:15:29 +00002081 install_element (CONFIG_NODE, &no_ip_route_mask_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002082 install_element (CONFIG_NODE, &no_ip_route_mask_flags_cmd);
hasso457ef552003-05-28 12:02:15 +00002083 install_element (CONFIG_NODE, &no_ip_route_mask_flags2_cmd);
paul718e3742002-12-13 20:15:29 +00002084 install_element (CONFIG_NODE, &ip_route_distance_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002085 install_element (CONFIG_NODE, &ip_route_flags_distance_cmd);
hasso457ef552003-05-28 12:02:15 +00002086 install_element (CONFIG_NODE, &ip_route_flags_distance2_cmd);
paul718e3742002-12-13 20:15:29 +00002087 install_element (CONFIG_NODE, &ip_route_mask_distance_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002088 install_element (CONFIG_NODE, &ip_route_mask_flags_distance_cmd);
hasso457ef552003-05-28 12:02:15 +00002089 install_element (CONFIG_NODE, &ip_route_mask_flags_distance2_cmd);
paul718e3742002-12-13 20:15:29 +00002090 install_element (CONFIG_NODE, &no_ip_route_distance_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002091 install_element (CONFIG_NODE, &no_ip_route_flags_distance_cmd);
hasso457ef552003-05-28 12:02:15 +00002092 install_element (CONFIG_NODE, &no_ip_route_flags_distance2_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002093 install_element (CONFIG_NODE, &no_ip_route_mask_flags_distance_cmd);
hasso457ef552003-05-28 12:02:15 +00002094 install_element (CONFIG_NODE, &no_ip_route_mask_flags_distance2_cmd);
paul718e3742002-12-13 20:15:29 +00002095
2096 install_element (VIEW_NODE, &show_ip_route_cmd);
2097 install_element (VIEW_NODE, &show_ip_route_addr_cmd);
2098 install_element (VIEW_NODE, &show_ip_route_prefix_cmd);
2099 install_element (VIEW_NODE, &show_ip_route_prefix_longer_cmd);
2100 install_element (VIEW_NODE, &show_ip_route_protocol_cmd);
2101 install_element (VIEW_NODE, &show_ip_route_supernets_cmd);
Stig Thormodsrud61691c92008-11-04 15:45:07 -08002102 install_element (VIEW_NODE, &show_ip_route_summary_cmd);
paul718e3742002-12-13 20:15:29 +00002103 install_element (ENABLE_NODE, &show_ip_route_cmd);
2104 install_element (ENABLE_NODE, &show_ip_route_addr_cmd);
2105 install_element (ENABLE_NODE, &show_ip_route_prefix_cmd);
2106 install_element (ENABLE_NODE, &show_ip_route_prefix_longer_cmd);
2107 install_element (ENABLE_NODE, &show_ip_route_protocol_cmd);
2108 install_element (ENABLE_NODE, &show_ip_route_supernets_cmd);
paul718e3742002-12-13 20:15:29 +00002109 install_element (ENABLE_NODE, &show_ip_route_summary_cmd);
paul718e3742002-12-13 20:15:29 +00002110
G.Balajicddf3912011-11-26 21:59:32 +04002111 install_element (VIEW_NODE, &show_ip_mroute_cmd);
2112 install_element (ENABLE_NODE, &show_ip_mroute_cmd);
2113
2114
paul718e3742002-12-13 20:15:29 +00002115#ifdef HAVE_IPV6
2116 install_element (CONFIG_NODE, &ipv6_route_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002117 install_element (CONFIG_NODE, &ipv6_route_flags_cmd);
paul718e3742002-12-13 20:15:29 +00002118 install_element (CONFIG_NODE, &ipv6_route_ifname_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002119 install_element (CONFIG_NODE, &ipv6_route_ifname_flags_cmd);
paul718e3742002-12-13 20:15:29 +00002120 install_element (CONFIG_NODE, &no_ipv6_route_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002121 install_element (CONFIG_NODE, &no_ipv6_route_flags_cmd);
paul718e3742002-12-13 20:15:29 +00002122 install_element (CONFIG_NODE, &no_ipv6_route_ifname_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002123 install_element (CONFIG_NODE, &no_ipv6_route_ifname_flags_cmd);
paul718e3742002-12-13 20:15:29 +00002124 install_element (CONFIG_NODE, &ipv6_route_pref_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002125 install_element (CONFIG_NODE, &ipv6_route_flags_pref_cmd);
paul718e3742002-12-13 20:15:29 +00002126 install_element (CONFIG_NODE, &ipv6_route_ifname_pref_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002127 install_element (CONFIG_NODE, &ipv6_route_ifname_flags_pref_cmd);
paul718e3742002-12-13 20:15:29 +00002128 install_element (CONFIG_NODE, &no_ipv6_route_pref_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002129 install_element (CONFIG_NODE, &no_ipv6_route_flags_pref_cmd);
paul718e3742002-12-13 20:15:29 +00002130 install_element (CONFIG_NODE, &no_ipv6_route_ifname_pref_cmd);
hasso81dfcaa2003-05-25 19:21:25 +00002131 install_element (CONFIG_NODE, &no_ipv6_route_ifname_flags_pref_cmd);
paul718e3742002-12-13 20:15:29 +00002132 install_element (VIEW_NODE, &show_ipv6_route_cmd);
Stig Thormodsrud61691c92008-11-04 15:45:07 -08002133 install_element (VIEW_NODE, &show_ipv6_route_summary_cmd);
paul718e3742002-12-13 20:15:29 +00002134 install_element (VIEW_NODE, &show_ipv6_route_protocol_cmd);
2135 install_element (VIEW_NODE, &show_ipv6_route_addr_cmd);
2136 install_element (VIEW_NODE, &show_ipv6_route_prefix_cmd);
2137 install_element (VIEW_NODE, &show_ipv6_route_prefix_longer_cmd);
2138 install_element (ENABLE_NODE, &show_ipv6_route_cmd);
2139 install_element (ENABLE_NODE, &show_ipv6_route_protocol_cmd);
2140 install_element (ENABLE_NODE, &show_ipv6_route_addr_cmd);
2141 install_element (ENABLE_NODE, &show_ipv6_route_prefix_cmd);
2142 install_element (ENABLE_NODE, &show_ipv6_route_prefix_longer_cmd);
Stig Thormodsrud61691c92008-11-04 15:45:07 -08002143 install_element (ENABLE_NODE, &show_ipv6_route_summary_cmd);
G.Balajicddf3912011-11-26 21:59:32 +04002144
2145 install_element (VIEW_NODE, &show_ipv6_mroute_cmd);
2146 install_element (ENABLE_NODE, &show_ipv6_mroute_cmd);
paul718e3742002-12-13 20:15:29 +00002147#endif /* HAVE_IPV6 */
2148}