paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* 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 Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 24 | #include "memory.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 25 | #include "if.h" |
| 26 | #include "prefix.h" |
| 27 | #include "command.h" |
| 28 | #include "table.h" |
| 29 | #include "rib.h" |
| 30 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 31 | #include "zebra/zserv.h" |
| 32 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 33 | /* General fucntion for static route. */ |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 34 | static int |
hasso | 39db97e | 2004-10-12 20:50:58 +0000 | [diff] [blame] | 35 | zebra_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) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 38 | { |
| 39 | int ret; |
| 40 | u_char distance; |
| 41 | struct prefix p; |
| 42 | struct in_addr gate; |
| 43 | struct in_addr mask; |
hasso | 39db97e | 2004-10-12 20:50:58 +0000 | [diff] [blame] | 44 | const char *ifname; |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 45 | u_char flag = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 46 | |
| 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) |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 59 | { |
| 60 | vty_out (vty, "%% Malformed address%s", VTY_NEWLINE); |
| 61 | return CMD_WARNING; |
| 62 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 63 | p.prefixlen = ip_masklen (mask); |
| 64 | } |
| 65 | |
| 66 | /* Apply mask for given prefix. */ |
| 67 | apply_mask (&p); |
| 68 | |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 69 | /* Administrative distance. */ |
| 70 | if (distance_str) |
| 71 | distance = atoi (distance_str); |
| 72 | else |
| 73 | distance = ZEBRA_STATIC_DISTANCE_DEFAULT; |
| 74 | |
| 75 | /* Null0 static route. */ |
hasso | 457ef55 | 2003-05-28 12:02:15 +0000 | [diff] [blame] | 76 | if ((gate_str != NULL) && (strncasecmp (gate_str, "Null0", strlen (gate_str)) == 0)) |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 77 | { |
| 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) |
paul | 7021c42 | 2003-07-15 12:52:22 +0000 | [diff] [blame] | 84 | static_add_ipv4 (&p, NULL, NULL, ZEBRA_FLAG_BLACKHOLE, distance, 0); |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 85 | else |
| 86 | static_delete_ipv4 (&p, NULL, NULL, distance, 0); |
| 87 | return CMD_SUCCESS; |
| 88 | } |
| 89 | |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 90 | /* 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); |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 103 | return CMD_WARNING; |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 104 | } |
| 105 | } |
| 106 | |
hasso | 457ef55 | 2003-05-28 12:02:15 +0000 | [diff] [blame] | 107 | 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 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 117 | /* 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) |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 126 | static_add_ipv4 (&p, ifname ? NULL : &gate, ifname, flag, distance, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 127 | else |
| 128 | static_delete_ipv4 (&p, ifname ? NULL : &gate, ifname, distance, 0); |
| 129 | |
| 130 | return CMD_SUCCESS; |
| 131 | } |
| 132 | |
| 133 | /* Static route configuration. */ |
| 134 | DEFUN (ip_route, |
| 135 | ip_route_cmd, |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 136 | "ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0)", |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 137 | IP_STR |
| 138 | "Establish static routes\n" |
| 139 | "IP destination prefix (e.g. 10.0.0.0/8)\n" |
| 140 | "IP gateway address\n" |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 141 | "IP gateway interface name\n" |
| 142 | "Null interface\n") |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 143 | { |
| 144 | return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], NULL, NULL); |
| 145 | } |
| 146 | |
| 147 | DEFUN (ip_route_flags, |
| 148 | ip_route_flags_cmd, |
| 149 | "ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole)", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 150 | 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" |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 155 | "Emit an ICMP unreachable when matched\n" |
| 156 | "Silently discard pkts when matched\n") |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 157 | { |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 158 | return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], argv[2], NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 159 | } |
| 160 | |
hasso | 457ef55 | 2003-05-28 12:02:15 +0000 | [diff] [blame] | 161 | DEFUN (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 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 173 | /* Mask as A.B.C.D format. */ |
| 174 | DEFUN (ip_route_mask, |
| 175 | ip_route_mask_cmd, |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 176 | "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0)", |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 177 | IP_STR |
| 178 | "Establish static routes\n" |
| 179 | "IP destination prefix\n" |
| 180 | "IP destination prefix mask\n" |
| 181 | "IP gateway address\n" |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 182 | "IP gateway interface name\n" |
| 183 | "Null interface\n") |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 184 | { |
| 185 | return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], NULL, NULL); |
| 186 | } |
| 187 | |
| 188 | DEFUN (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)", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 191 | 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" |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 197 | "Emit an ICMP unreachable when matched\n" |
| 198 | "Silently discard pkts when matched\n") |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 199 | { |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 200 | return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], argv[3], NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 201 | } |
| 202 | |
hasso | 457ef55 | 2003-05-28 12:02:15 +0000 | [diff] [blame] | 203 | DEFUN (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 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 216 | /* Distance option value. */ |
| 217 | DEFUN (ip_route_distance, |
| 218 | ip_route_distance_cmd, |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 219 | "ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0) <1-255>", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 220 | 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" |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 225 | "Null interface\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 226 | "Distance value for this route\n") |
| 227 | { |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 228 | return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], NULL, argv[2]); |
| 229 | } |
| 230 | |
| 231 | DEFUN (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]); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 244 | } |
| 245 | |
hasso | 457ef55 | 2003-05-28 12:02:15 +0000 | [diff] [blame] | 246 | DEFUN (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 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 259 | DEFUN (ip_route_mask_distance, |
| 260 | ip_route_mask_distance_cmd, |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 261 | "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0) <1-255>", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 262 | 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" |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 268 | "Null interface\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 269 | "Distance value for this route\n") |
| 270 | { |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 271 | return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], NULL, argv[3]); |
| 272 | } |
| 273 | |
| 274 | DEFUN (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]); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 288 | } |
| 289 | |
hasso | 457ef55 | 2003-05-28 12:02:15 +0000 | [diff] [blame] | 290 | DEFUN (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 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 304 | DEFUN (no_ip_route, |
| 305 | no_ip_route_cmd, |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 306 | "no ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0)", |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 307 | 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" |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 312 | "IP gateway interface name\n" |
| 313 | "Null interface\n") |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 314 | { |
| 315 | return zebra_static_ipv4 (vty, 0, argv[0], NULL, argv[1], NULL, NULL); |
| 316 | } |
| 317 | |
| 318 | ALIAS (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)", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 321 | 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" |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 327 | "Emit an ICMP unreachable when matched\n" |
| 328 | "Silently discard pkts when matched\n") |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 329 | |
hasso | 457ef55 | 2003-05-28 12:02:15 +0000 | [diff] [blame] | 330 | DEFUN (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 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 343 | DEFUN (no_ip_route_mask, |
| 344 | no_ip_route_mask_cmd, |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 345 | "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0)", |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 346 | 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" |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 352 | "IP gateway interface name\n" |
| 353 | "Null interface\n") |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 354 | { |
| 355 | return zebra_static_ipv4 (vty, 0, argv[0], argv[1], argv[2], NULL, NULL); |
| 356 | } |
| 357 | |
| 358 | ALIAS (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)", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 361 | 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" |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 368 | "Emit an ICMP unreachable when matched\n" |
| 369 | "Silently discard pkts when matched\n") |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 370 | |
hasso | 457ef55 | 2003-05-28 12:02:15 +0000 | [diff] [blame] | 371 | DEFUN (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 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 385 | DEFUN (no_ip_route_distance, |
| 386 | no_ip_route_distance_cmd, |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 387 | "no ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0) <1-255>", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 388 | 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" |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 394 | "Null interface\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 395 | "Distance value for this route\n") |
| 396 | { |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 397 | return zebra_static_ipv4 (vty, 0, argv[0], NULL, argv[1], NULL, argv[2]); |
| 398 | } |
| 399 | |
| 400 | DEFUN (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]); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 414 | } |
| 415 | |
hasso | 457ef55 | 2003-05-28 12:02:15 +0000 | [diff] [blame] | 416 | DEFUN (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 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 430 | DEFUN (no_ip_route_mask_distance, |
| 431 | no_ip_route_mask_distance_cmd, |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 432 | "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0) <1-255>", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 433 | 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" |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 440 | "Null interface\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 441 | "Distance value for this route\n") |
| 442 | { |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 443 | return zebra_static_ipv4 (vty, 0, argv[0], argv[1], argv[2], NULL, argv[3]); |
| 444 | } |
| 445 | |
| 446 | DEFUN (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]); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 461 | } |
| 462 | |
hasso | 457ef55 | 2003-05-28 12:02:15 +0000 | [diff] [blame] | 463 | DEFUN (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 Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 478 | char *proto_rm[AFI_MAX][ZEBRA_ROUTE_MAX+1]; /* "any" == ZEBRA_ROUTE_MAX */ |
| 479 | |
| 480 | DEFUN (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 | |
| 506 | DEFUN (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 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 531 | /* New RIB. Detailed information for IPv4 route. */ |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 532 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 533 | vty_show_ip_route_detail (struct vty *vty, struct route_node *rn) |
| 534 | { |
| 535 | struct rib *rib; |
| 536 | struct nexthop *nexthop; |
| 537 | |
Avneesh Sachdev | 9fd92e3 | 2012-11-13 22:48:53 +0000 | [diff] [blame] | 538 | RNODE_FOREACH_RIB (rn, rib) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 539 | { |
| 540 | vty_out (vty, "Routing entry for %s/%d%s", |
| 541 | inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen, |
| 542 | VTY_NEWLINE); |
ajs | f52d13c | 2005-10-01 17:38:06 +0000 | [diff] [blame] | 543 | vty_out (vty, " Known via \"%s\"", zebra_route_string (rib->type)); |
Jorge Boncompte [DTI2] | ddc943d | 2012-04-13 13:46:07 +0200 | [diff] [blame] | 544 | vty_out (vty, ", distance %u, metric %u", rib->distance, rib->metric); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 545 | 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); |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 549 | 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"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 553 | 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 Chroboczek | 578ce37 | 2012-02-09 13:42:28 +0100 | [diff] [blame] | 559 | || rib->type == ZEBRA_ROUTE_BABEL |
jardin | 9e867fe | 2003-12-23 08:56:18 +0000 | [diff] [blame] | 560 | || rib->type == ZEBRA_ROUTE_ISIS |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 561 | || 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 Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 587 | char addrstr[32]; |
| 588 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 589 | 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; |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 607 | case NEXTHOP_TYPE_BLACKHOLE: |
paul | 7021c42 | 2003-07-15 12:52:22 +0000 | [diff] [blame] | 608 | vty_out (vty, " directly connected, Null0"); |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 609 | break; |
paul | 7021c42 | 2003-07-15 12:52:22 +0000 | [diff] [blame] | 610 | default: |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 611 | 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 Franke | 5b9f518 | 2013-05-25 14:01:34 +0000 | [diff] [blame^] | 624 | 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 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 629 | 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 Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 639 | 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. Schorr | 0930331 | 2007-05-30 20:10:34 +0000 | [diff] [blame] | 651 | #ifdef HAVE_IPV6 |
Paul Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 652 | 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. Schorr | 0930331 | 2007-05-30 20:10:34 +0000 | [diff] [blame] | 662 | #endif /* HAVE_IPV6 */ |
Paul Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 663 | default: |
| 664 | break; |
| 665 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 666 | vty_out (vty, "%s", VTY_NEWLINE); |
| 667 | } |
| 668 | vty_out (vty, "%s", VTY_NEWLINE); |
| 669 | } |
| 670 | } |
| 671 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 672 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 673 | vty_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", |
ajs | f52d13c | 2005-10-01 17:38:06 +0000 | [diff] [blame] | 686 | zebra_route_char (rib->type), |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 687 | 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; |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 721 | case NEXTHOP_TYPE_BLACKHOLE: |
paul | 7021c42 | 2003-07-15 12:52:22 +0000 | [diff] [blame] | 722 | vty_out (vty, " is directly connected, Null0"); |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 723 | break; |
paul | 7021c42 | 2003-07-15 12:52:22 +0000 | [diff] [blame] | 724 | default: |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 725 | 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 Franke | 5b9f518 | 2013-05-25 14:01:34 +0000 | [diff] [blame^] | 738 | 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, ")"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 742 | 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 Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 752 | 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. Schorr | 0930331 | 2007-05-30 20:10:34 +0000 | [diff] [blame] | 763 | #ifdef HAVE_IPV6 |
Paul Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 764 | 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. Schorr | 0930331 | 2007-05-30 20:10:34 +0000 | [diff] [blame] | 773 | #endif /* HAVE_IPV6 */ |
Paul Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 774 | default: |
| 775 | break; |
| 776 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 777 | |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 778 | 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 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 783 | if (rib->type == ZEBRA_ROUTE_RIP |
| 784 | || rib->type == ZEBRA_ROUTE_OSPF |
Juliusz Chroboczek | 578ce37 | 2012-02-09 13:42:28 +0100 | [diff] [blame] | 785 | || rib->type == ZEBRA_ROUTE_BABEL |
jardin | 9e867fe | 2003-12-23 08:56:18 +0000 | [diff] [blame] | 786 | || rib->type == ZEBRA_ROUTE_ISIS |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 787 | || 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 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 814 | DEFUN (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 Sachdev | 9fd92e3 | 2012-11-13 22:48:53 +0000 | [diff] [blame] | 832 | RNODE_FOREACH_RIB (rn, rib) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 833 | { |
| 834 | if (first) |
| 835 | { |
David Lamparter | e0ca5fd | 2009-09-16 01:52:42 +0200 | [diff] [blame] | 836 | vty_out (vty, SHOW_ROUTE_V4_HEADER); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 837 | first = 0; |
| 838 | } |
| 839 | vty_show_ip_route (vty, rn, rib); |
| 840 | } |
| 841 | return CMD_SUCCESS; |
| 842 | } |
| 843 | |
| 844 | DEFUN (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 Sachdev | 9fd92e3 | 2012-11-13 22:48:53 +0000 | [diff] [blame] | 873 | RNODE_FOREACH_RIB (rn, rib) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 874 | if (prefix_match (&p, &rn->p)) |
| 875 | { |
| 876 | if (first) |
| 877 | { |
David Lamparter | e0ca5fd | 2009-09-16 01:52:42 +0200 | [diff] [blame] | 878 | vty_out (vty, SHOW_ROUTE_V4_HEADER); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 879 | first = 0; |
| 880 | } |
| 881 | vty_show_ip_route (vty, rn, rib); |
| 882 | } |
| 883 | return CMD_SUCCESS; |
| 884 | } |
| 885 | |
| 886 | DEFUN (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 Sachdev | 9fd92e3 | 2012-11-13 22:48:53 +0000 | [diff] [blame] | 906 | RNODE_FOREACH_RIB (rn, rib) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 907 | { |
| 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 Lamparter | e0ca5fd | 2009-09-16 01:52:42 +0200 | [diff] [blame] | 916 | vty_out (vty, SHOW_ROUTE_V4_HEADER); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 917 | first = 0; |
| 918 | } |
| 919 | vty_show_ip_route (vty, rn, rib); |
| 920 | } |
| 921 | } |
| 922 | return CMD_SUCCESS; |
| 923 | } |
| 924 | |
| 925 | DEFUN (show_ip_route_protocol, |
| 926 | show_ip_route_protocol_cmd, |
David Lamparter | e0ca5fd | 2009-09-16 01:52:42 +0200 | [diff] [blame] | 927 | "show ip route " QUAGGA_IP_REDIST_STR_ZEBRA, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 928 | SHOW_STR |
| 929 | IP_STR |
| 930 | "IP routing table\n" |
David Lamparter | e0ca5fd | 2009-09-16 01:52:42 +0200 | [diff] [blame] | 931 | QUAGGA_IP_REDIST_HELP_STR_ZEBRA) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 932 | { |
| 933 | int type; |
| 934 | struct route_table *table; |
| 935 | struct route_node *rn; |
| 936 | struct rib *rib; |
| 937 | int first = 1; |
| 938 | |
David Lamparter | e0ca5fd | 2009-09-16 01:52:42 +0200 | [diff] [blame] | 939 | type = proto_redistnum (AFI_IP, argv[0]); |
| 940 | if (type < 0) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 941 | { |
| 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 Sachdev | 9fd92e3 | 2012-11-13 22:48:53 +0000 | [diff] [blame] | 952 | RNODE_FOREACH_RIB (rn, rib) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 953 | if (rib->type == type) |
| 954 | { |
| 955 | if (first) |
| 956 | { |
David Lamparter | e0ca5fd | 2009-09-16 01:52:42 +0200 | [diff] [blame] | 957 | vty_out (vty, SHOW_ROUTE_V4_HEADER); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 958 | first = 0; |
| 959 | } |
| 960 | vty_show_ip_route (vty, rn, rib); |
| 961 | } |
| 962 | return CMD_SUCCESS; |
| 963 | } |
| 964 | |
| 965 | DEFUN (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 | |
| 1003 | DEFUN (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 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 1041 | static void |
Stig Thormodsrud | 61691c9 | 2008-11-04 15:45:07 -0800 | [diff] [blame] | 1042 | vty_show_ip_route_summary (struct vty *vty, struct route_table *table) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1043 | { |
Stig Thormodsrud | 61691c9 | 2008-11-04 15:45:07 -0800 | [diff] [blame] | 1044 | 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; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1052 | |
Stig Thormodsrud | 61691c9 | 2008-11-04 15:45:07 -0800 | [diff] [blame] | 1053 | 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 Sachdev | 9fd92e3 | 2012-11-13 22:48:53 +0000 | [diff] [blame] | 1056 | RNODE_FOREACH_RIB (rn, rib) |
Stig Thormodsrud | 61691c9 | 2008-11-04 15:45:07 -0800 | [diff] [blame] | 1057 | 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 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1074 | |
Stig Thormodsrud | 61691c9 | 2008-11-04 15:45:07 -0800 | [diff] [blame] | 1075 | vty_out (vty, "%-20s %-20s %-20s %s", |
| 1076 | "Route Source", "Routes", "FIB", VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1077 | |
Stig Thormodsrud | 61691c9 | 2008-11-04 15:45:07 -0800 | [diff] [blame] | 1078 | 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 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1097 | |
Stig Thormodsrud | 61691c9 | 2008-11-04 15:45:07 -0800 | [diff] [blame] | 1098 | 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); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1101 | } |
| 1102 | |
| 1103 | /* Show route summary. */ |
| 1104 | DEFUN (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 Thormodsrud | 61691c9 | 2008-11-04 15:45:07 -0800 | [diff] [blame] | 1112 | struct route_table *table; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1113 | |
Stig Thormodsrud | 61691c9 | 2008-11-04 15:45:07 -0800 | [diff] [blame] | 1114 | table = vrf_table (AFI_IP, SAFI_UNICAST, 0); |
| 1115 | if (! table) |
| 1116 | return CMD_SUCCESS; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1117 | |
Stig Thormodsrud | 61691c9 | 2008-11-04 15:45:07 -0800 | [diff] [blame] | 1118 | vty_show_ip_route_summary (vty, table); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1119 | |
| 1120 | return CMD_SUCCESS; |
| 1121 | } |
| 1122 | |
| 1123 | /* Write IPv4 static route configuration. */ |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 1124 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1125 | static_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 | { |
paul | 7021c42 | 2003-07-15 12:52:22 +0000 | [diff] [blame] | 1142 | vty_out (vty, "ip route %s/%d", inet_ntoa (rn->p.u.prefix4), |
| 1143 | rn->p.prefixlen); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1144 | |
paul | 7021c42 | 2003-07-15 12:52:22 +0000 | [diff] [blame] | 1145 | 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"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1163 | |
paul | 7021c42 | 2003-07-15 12:52:22 +0000 | [diff] [blame] | 1164 | if (CHECK_FLAG(si->flags, ZEBRA_FLAG_BLACKHOLE)) |
| 1165 | vty_out (vty, " %s", "blackhole"); |
| 1166 | } |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 1167 | |
paul | 7021c42 | 2003-07-15 12:52:22 +0000 | [diff] [blame] | 1168 | if (si->distance != ZEBRA_STATIC_DISTANCE_DEFAULT) |
| 1169 | vty_out (vty, " %d", si->distance); |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 1170 | |
paul | 7021c42 | 2003-07-15 12:52:22 +0000 | [diff] [blame] | 1171 | vty_out (vty, "%s", VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1172 | |
paul | 7021c42 | 2003-07-15 12:52:22 +0000 | [diff] [blame] | 1173 | write = 1; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1174 | } |
| 1175 | return write; |
| 1176 | } |
Andrew J. Schorr | 0930331 | 2007-05-30 20:10:34 +0000 | [diff] [blame] | 1177 | |
| 1178 | DEFUN (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 Nilsson | 36735ed | 2012-05-09 13:38:36 +0200 | [diff] [blame] | 1207 | /* |
| 1208 | * Show IP mroute command to dump the BGP Multicast |
| 1209 | * routing table |
| 1210 | */ |
| 1211 | DEFUN (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 Sachdev | 9fd92e3 | 2012-11-13 22:48:53 +0000 | [diff] [blame] | 1229 | RNODE_FOREACH_RIB (rn, rib) |
Joachim Nilsson | 36735ed | 2012-05-09 13:38:36 +0200 | [diff] [blame] | 1230 | { |
| 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 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1241 | |
| 1242 | #ifdef HAVE_IPV6 |
| 1243 | /* General fucntion for IPv6 static route. */ |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 1244 | static int |
hasso | 39db97e | 2004-10-12 20:50:58 +0000 | [diff] [blame] | 1245 | static_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) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1248 | { |
| 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; |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 1256 | u_char flag = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1257 | |
| 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 | |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 1268 | /* 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); |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 1281 | return CMD_WARNING; |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 1282 | } |
| 1283 | } |
| 1284 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1285 | /* 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) |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 1322 | static_add_ipv6 (&p, type, gate, ifname, flag, distance, table); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1323 | else |
| 1324 | static_delete_ipv6 (&p, type, gate, ifname, distance, table); |
| 1325 | |
| 1326 | return CMD_SUCCESS; |
| 1327 | } |
| 1328 | |
| 1329 | DEFUN (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 | { |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 1338 | return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, NULL, NULL); |
| 1339 | } |
| 1340 | |
| 1341 | DEFUN (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); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1353 | } |
| 1354 | |
| 1355 | DEFUN (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 | { |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 1364 | return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], NULL, NULL); |
| 1365 | } |
| 1366 | |
| 1367 | DEFUN (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); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1379 | } |
| 1380 | |
| 1381 | DEFUN (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 | { |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 1391 | return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, NULL, argv[2]); |
| 1392 | } |
| 1393 | |
| 1394 | DEFUN (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]); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1407 | } |
| 1408 | |
| 1409 | DEFUN (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 | { |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 1419 | return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], NULL, argv[3]); |
| 1420 | } |
| 1421 | |
| 1422 | DEFUN (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]); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1435 | } |
| 1436 | |
| 1437 | DEFUN (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 | { |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 1447 | return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, NULL, NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1448 | } |
| 1449 | |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 1450 | ALIAS (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 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1462 | DEFUN (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 | { |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 1472 | return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], NULL, NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1473 | } |
| 1474 | |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 1475 | ALIAS (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 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1487 | DEFUN (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 | { |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 1498 | return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, NULL, argv[2]); |
| 1499 | } |
| 1500 | |
| 1501 | DEFUN (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]); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1516 | } |
| 1517 | |
| 1518 | DEFUN (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 | { |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 1529 | return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], NULL, argv[3]); |
| 1530 | } |
| 1531 | |
| 1532 | DEFUN (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]); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1546 | } |
| 1547 | |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 1548 | /* New RIB. Detailed information for IPv6 route. */ |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 1549 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1550 | vty_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 Sachdev | 9fd92e3 | 2012-11-13 22:48:53 +0000 | [diff] [blame] | 1556 | RNODE_FOREACH_RIB (rn, rib) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1557 | { |
| 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); |
ajs | f52d13c | 2005-10-01 17:38:06 +0000 | [diff] [blame] | 1562 | vty_out (vty, " Known via \"%s\"", zebra_route_string (rib->type)); |
Jorge Boncompte [DTI2] | ddc943d | 2012-04-13 13:46:07 +0200 | [diff] [blame] | 1563 | vty_out (vty, ", distance %u, metric %u", rib->distance, rib->metric); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1564 | 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); |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 1568 | 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"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1572 | 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 Chroboczek | 578ce37 | 2012-02-09 13:42:28 +0100 | [diff] [blame] | 1578 | || rib->type == ZEBRA_ROUTE_BABEL |
jardin | 9e867fe | 2003-12-23 08:56:18 +0000 | [diff] [blame] | 1579 | || rib->type == ZEBRA_ROUTE_ISIS |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1580 | || 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 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 1665 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1666 | vty_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", |
ajs | f52d13c | 2005-10-01 17:38:06 +0000 | [diff] [blame] | 1680 | zebra_route_char (rib->type), |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1681 | 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 | |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 1751 | 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 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1756 | if (rib->type == ZEBRA_ROUTE_RIPNG |
| 1757 | || rib->type == ZEBRA_ROUTE_OSPF6 |
Juliusz Chroboczek | 578ce37 | 2012-02-09 13:42:28 +0100 | [diff] [blame] | 1758 | || rib->type == ZEBRA_ROUTE_BABEL |
jardin | 9e867fe | 2003-12-23 08:56:18 +0000 | [diff] [blame] | 1759 | || rib->type == ZEBRA_ROUTE_ISIS |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1760 | || 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 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1787 | DEFUN (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 Sachdev | 9fd92e3 | 2012-11-13 22:48:53 +0000 | [diff] [blame] | 1805 | RNODE_FOREACH_RIB (rn, rib) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1806 | { |
| 1807 | if (first) |
| 1808 | { |
David Lamparter | e0ca5fd | 2009-09-16 01:52:42 +0200 | [diff] [blame] | 1809 | vty_out (vty, SHOW_ROUTE_V6_HEADER); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1810 | first = 0; |
| 1811 | } |
| 1812 | vty_show_ipv6_route (vty, rn, rib); |
| 1813 | } |
| 1814 | return CMD_SUCCESS; |
| 1815 | } |
| 1816 | |
| 1817 | DEFUN (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 Sachdev | 9fd92e3 | 2012-11-13 22:48:53 +0000 | [diff] [blame] | 1846 | RNODE_FOREACH_RIB (rn, rib) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1847 | if (prefix_match (&p, &rn->p)) |
| 1848 | { |
| 1849 | if (first) |
| 1850 | { |
David Lamparter | e0ca5fd | 2009-09-16 01:52:42 +0200 | [diff] [blame] | 1851 | vty_out (vty, SHOW_ROUTE_V6_HEADER); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1852 | first = 0; |
| 1853 | } |
| 1854 | vty_show_ipv6_route (vty, rn, rib); |
| 1855 | } |
| 1856 | return CMD_SUCCESS; |
| 1857 | } |
| 1858 | |
| 1859 | DEFUN (show_ipv6_route_protocol, |
| 1860 | show_ipv6_route_protocol_cmd, |
David Lamparter | e0ca5fd | 2009-09-16 01:52:42 +0200 | [diff] [blame] | 1861 | "show ipv6 route " QUAGGA_IP6_REDIST_STR_ZEBRA, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1862 | SHOW_STR |
| 1863 | IP_STR |
| 1864 | "IP routing table\n" |
David Lamparter | e0ca5fd | 2009-09-16 01:52:42 +0200 | [diff] [blame] | 1865 | QUAGGA_IP6_REDIST_HELP_STR_ZEBRA) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1866 | { |
| 1867 | int type; |
| 1868 | struct route_table *table; |
| 1869 | struct route_node *rn; |
| 1870 | struct rib *rib; |
| 1871 | int first = 1; |
| 1872 | |
David Lamparter | e0ca5fd | 2009-09-16 01:52:42 +0200 | [diff] [blame] | 1873 | type = proto_redistnum (AFI_IP6, argv[0]); |
| 1874 | if (type < 0) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1875 | { |
| 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 Sachdev | 9fd92e3 | 2012-11-13 22:48:53 +0000 | [diff] [blame] | 1886 | RNODE_FOREACH_RIB (rn, rib) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1887 | if (rib->type == type) |
| 1888 | { |
| 1889 | if (first) |
| 1890 | { |
David Lamparter | e0ca5fd | 2009-09-16 01:52:42 +0200 | [diff] [blame] | 1891 | vty_out (vty, SHOW_ROUTE_V6_HEADER); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1892 | first = 0; |
| 1893 | } |
| 1894 | vty_show_ipv6_route (vty, rn, rib); |
| 1895 | } |
| 1896 | return CMD_SUCCESS; |
| 1897 | } |
| 1898 | |
| 1899 | DEFUN (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 | |
| 1937 | DEFUN (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 Thormodsrud | 61691c9 | 2008-11-04 15:45:07 -0800 | [diff] [blame] | 1975 | /* Show route summary. */ |
| 1976 | DEFUN (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.Balaji | cddf391 | 2011-11-26 21:59:32 +0400 | [diff] [blame] | 1995 | /* |
G.Balaji | cddf391 | 2011-11-26 21:59:32 +0400 | [diff] [blame] | 1996 | * Show IPv6 mroute command.Used to dump |
| 1997 | * the Multicast routing table. |
| 1998 | */ |
| 1999 | |
| 2000 | DEFUN (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 Sachdev | 9fd92e3 | 2012-11-13 22:48:53 +0000 | [diff] [blame] | 2018 | RNODE_FOREACH_RIB (rn, rib) |
G.Balaji | cddf391 | 2011-11-26 21:59:32 +0400 | [diff] [blame] | 2019 | { |
| 2020 | if (first) |
| 2021 | { |
G.Balaji | cb32fd6 | 2011-11-27 20:09:40 +0530 | [diff] [blame] | 2022 | vty_out (vty, SHOW_ROUTE_V6_HEADER); |
G.Balaji | cddf391 | 2011-11-26 21:59:32 +0400 | [diff] [blame] | 2023 | first = 0; |
| 2024 | } |
| 2025 | vty_show_ipv6_route (vty, rn, rib); |
| 2026 | } |
| 2027 | return CMD_SUCCESS; |
| 2028 | } |
| 2029 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2030 | /* Write IPv6 static route configuration. */ |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 2031 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2032 | static_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 | |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 2068 | 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 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2074 | 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. */ |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 2085 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2086 | zebra_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 Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 2098 | /* ip protocol configuration write function */ |
| 2099 | static 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 Hemminger | 7fc626d | 2008-12-01 11:10:34 -0800 | [diff] [blame] | 2117 | static struct cmd_node protocol_node = { PROTOCOL_NODE, "", 1 }; |
Paul Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 2118 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2119 | /* IP node for static routes. */ |
Stephen Hemminger | 7fc626d | 2008-12-01 11:10:34 -0800 | [diff] [blame] | 2120 | static struct cmd_node ip_node = { IP_NODE, "", 1 }; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2121 | |
| 2122 | /* Route VTY. */ |
| 2123 | void |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 2124 | zebra_vty_init (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2125 | { |
| 2126 | install_node (&ip_node, zebra_ip_config); |
Paul Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 2127 | install_node (&protocol_node, config_write_protocol); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2128 | |
Paul Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 2129 | 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); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2133 | install_element (CONFIG_NODE, &ip_route_cmd); |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 2134 | install_element (CONFIG_NODE, &ip_route_flags_cmd); |
hasso | 457ef55 | 2003-05-28 12:02:15 +0000 | [diff] [blame] | 2135 | install_element (CONFIG_NODE, &ip_route_flags2_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2136 | install_element (CONFIG_NODE, &ip_route_mask_cmd); |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 2137 | install_element (CONFIG_NODE, &ip_route_mask_flags_cmd); |
hasso | 457ef55 | 2003-05-28 12:02:15 +0000 | [diff] [blame] | 2138 | install_element (CONFIG_NODE, &ip_route_mask_flags2_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2139 | install_element (CONFIG_NODE, &no_ip_route_cmd); |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 2140 | install_element (CONFIG_NODE, &no_ip_route_flags_cmd); |
hasso | 457ef55 | 2003-05-28 12:02:15 +0000 | [diff] [blame] | 2141 | install_element (CONFIG_NODE, &no_ip_route_flags2_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2142 | install_element (CONFIG_NODE, &no_ip_route_mask_cmd); |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 2143 | install_element (CONFIG_NODE, &no_ip_route_mask_flags_cmd); |
hasso | 457ef55 | 2003-05-28 12:02:15 +0000 | [diff] [blame] | 2144 | install_element (CONFIG_NODE, &no_ip_route_mask_flags2_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2145 | install_element (CONFIG_NODE, &ip_route_distance_cmd); |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 2146 | install_element (CONFIG_NODE, &ip_route_flags_distance_cmd); |
hasso | 457ef55 | 2003-05-28 12:02:15 +0000 | [diff] [blame] | 2147 | install_element (CONFIG_NODE, &ip_route_flags_distance2_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2148 | install_element (CONFIG_NODE, &ip_route_mask_distance_cmd); |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 2149 | install_element (CONFIG_NODE, &ip_route_mask_flags_distance_cmd); |
hasso | 457ef55 | 2003-05-28 12:02:15 +0000 | [diff] [blame] | 2150 | install_element (CONFIG_NODE, &ip_route_mask_flags_distance2_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2151 | install_element (CONFIG_NODE, &no_ip_route_distance_cmd); |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 2152 | install_element (CONFIG_NODE, &no_ip_route_flags_distance_cmd); |
hasso | 457ef55 | 2003-05-28 12:02:15 +0000 | [diff] [blame] | 2153 | install_element (CONFIG_NODE, &no_ip_route_flags_distance2_cmd); |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 2154 | install_element (CONFIG_NODE, &no_ip_route_mask_flags_distance_cmd); |
hasso | 457ef55 | 2003-05-28 12:02:15 +0000 | [diff] [blame] | 2155 | install_element (CONFIG_NODE, &no_ip_route_mask_flags_distance2_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2156 | |
| 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 Thormodsrud | 61691c9 | 2008-11-04 15:45:07 -0800 | [diff] [blame] | 2163 | install_element (VIEW_NODE, &show_ip_route_summary_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2164 | 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); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2170 | install_element (ENABLE_NODE, &show_ip_route_summary_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2171 | |
G.Balaji | cddf391 | 2011-11-26 21:59:32 +0400 | [diff] [blame] | 2172 | install_element (VIEW_NODE, &show_ip_mroute_cmd); |
| 2173 | install_element (ENABLE_NODE, &show_ip_mroute_cmd); |
| 2174 | |
| 2175 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2176 | #ifdef HAVE_IPV6 |
| 2177 | install_element (CONFIG_NODE, &ipv6_route_cmd); |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 2178 | install_element (CONFIG_NODE, &ipv6_route_flags_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2179 | install_element (CONFIG_NODE, &ipv6_route_ifname_cmd); |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 2180 | install_element (CONFIG_NODE, &ipv6_route_ifname_flags_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2181 | install_element (CONFIG_NODE, &no_ipv6_route_cmd); |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 2182 | install_element (CONFIG_NODE, &no_ipv6_route_flags_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2183 | install_element (CONFIG_NODE, &no_ipv6_route_ifname_cmd); |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 2184 | install_element (CONFIG_NODE, &no_ipv6_route_ifname_flags_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2185 | install_element (CONFIG_NODE, &ipv6_route_pref_cmd); |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 2186 | install_element (CONFIG_NODE, &ipv6_route_flags_pref_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2187 | install_element (CONFIG_NODE, &ipv6_route_ifname_pref_cmd); |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 2188 | install_element (CONFIG_NODE, &ipv6_route_ifname_flags_pref_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2189 | install_element (CONFIG_NODE, &no_ipv6_route_pref_cmd); |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 2190 | install_element (CONFIG_NODE, &no_ipv6_route_flags_pref_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2191 | install_element (CONFIG_NODE, &no_ipv6_route_ifname_pref_cmd); |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 2192 | install_element (CONFIG_NODE, &no_ipv6_route_ifname_flags_pref_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2193 | install_element (VIEW_NODE, &show_ipv6_route_cmd); |
Stig Thormodsrud | 61691c9 | 2008-11-04 15:45:07 -0800 | [diff] [blame] | 2194 | install_element (VIEW_NODE, &show_ipv6_route_summary_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2195 | 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 Thormodsrud | 61691c9 | 2008-11-04 15:45:07 -0800 | [diff] [blame] | 2204 | install_element (ENABLE_NODE, &show_ipv6_route_summary_cmd); |
G.Balaji | cddf391 | 2011-11-26 21:59:32 +0400 | [diff] [blame] | 2205 | |
| 2206 | install_element (VIEW_NODE, &show_ipv6_mroute_cmd); |
| 2207 | install_element (ENABLE_NODE, &show_ipv6_mroute_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2208 | #endif /* HAVE_IPV6 */ |
| 2209 | } |