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 | |
Everton Marques | 33d86db | 2014-07-14 11:19:00 -0300 | [diff] [blame] | 33 | static int do_show_ip_route(struct vty *vty, safi_t safi); |
| 34 | |
| 35 | /* General function for static route. */ |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 36 | static int |
Everton Marques | 33d86db | 2014-07-14 11:19:00 -0300 | [diff] [blame] | 37 | zebra_static_ipv4_safi (struct vty *vty, safi_t safi, int add_cmd, |
| 38 | const char *dest_str, const char *mask_str, |
| 39 | const char *gate_str, const char *flag_str, |
| 40 | const char *distance_str) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 41 | { |
| 42 | int ret; |
| 43 | u_char distance; |
| 44 | struct prefix p; |
| 45 | struct in_addr gate; |
| 46 | struct in_addr mask; |
hasso | 39db97e | 2004-10-12 20:50:58 +0000 | [diff] [blame] | 47 | const char *ifname; |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 48 | u_char flag = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 49 | |
| 50 | ret = str2prefix (dest_str, &p); |
| 51 | if (ret <= 0) |
| 52 | { |
| 53 | vty_out (vty, "%% Malformed address%s", VTY_NEWLINE); |
| 54 | return CMD_WARNING; |
| 55 | } |
| 56 | |
| 57 | /* Cisco like mask notation. */ |
| 58 | if (mask_str) |
| 59 | { |
| 60 | ret = inet_aton (mask_str, &mask); |
| 61 | if (ret == 0) |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 62 | { |
| 63 | vty_out (vty, "%% Malformed address%s", VTY_NEWLINE); |
| 64 | return CMD_WARNING; |
| 65 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 66 | p.prefixlen = ip_masklen (mask); |
| 67 | } |
| 68 | |
| 69 | /* Apply mask for given prefix. */ |
| 70 | apply_mask (&p); |
| 71 | |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 72 | /* Administrative distance. */ |
| 73 | if (distance_str) |
| 74 | distance = atoi (distance_str); |
| 75 | else |
| 76 | distance = ZEBRA_STATIC_DISTANCE_DEFAULT; |
| 77 | |
| 78 | /* Null0 static route. */ |
hasso | 457ef55 | 2003-05-28 12:02:15 +0000 | [diff] [blame] | 79 | if ((gate_str != NULL) && (strncasecmp (gate_str, "Null0", strlen (gate_str)) == 0)) |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 80 | { |
| 81 | if (flag_str) |
| 82 | { |
| 83 | vty_out (vty, "%% can not have flag %s with Null0%s", flag_str, VTY_NEWLINE); |
| 84 | return CMD_WARNING; |
| 85 | } |
| 86 | if (add_cmd) |
Everton Marques | 33d86db | 2014-07-14 11:19:00 -0300 | [diff] [blame] | 87 | static_add_ipv4_safi (safi, &p, NULL, NULL, ZEBRA_FLAG_BLACKHOLE, distance, 0); |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 88 | else |
Everton Marques | 33d86db | 2014-07-14 11:19:00 -0300 | [diff] [blame] | 89 | static_delete_ipv4_safi (safi, &p, NULL, NULL, distance, 0); |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 90 | return CMD_SUCCESS; |
| 91 | } |
| 92 | |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 93 | /* Route flags */ |
| 94 | if (flag_str) { |
| 95 | switch(flag_str[0]) { |
| 96 | case 'r': |
| 97 | case 'R': /* XXX */ |
| 98 | SET_FLAG (flag, ZEBRA_FLAG_REJECT); |
| 99 | break; |
| 100 | case 'b': |
| 101 | case 'B': /* XXX */ |
| 102 | SET_FLAG (flag, ZEBRA_FLAG_BLACKHOLE); |
| 103 | break; |
| 104 | default: |
| 105 | vty_out (vty, "%% Malformed flag %s %s", flag_str, VTY_NEWLINE); |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 106 | return CMD_WARNING; |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 107 | } |
| 108 | } |
| 109 | |
hasso | 457ef55 | 2003-05-28 12:02:15 +0000 | [diff] [blame] | 110 | if (gate_str == NULL) |
| 111 | { |
| 112 | if (add_cmd) |
Everton Marques | 33d86db | 2014-07-14 11:19:00 -0300 | [diff] [blame] | 113 | static_add_ipv4_safi (safi, &p, NULL, NULL, flag, distance, 0); |
hasso | 457ef55 | 2003-05-28 12:02:15 +0000 | [diff] [blame] | 114 | else |
Everton Marques | 33d86db | 2014-07-14 11:19:00 -0300 | [diff] [blame] | 115 | static_delete_ipv4_safi (safi, &p, NULL, NULL, distance, 0); |
hasso | 457ef55 | 2003-05-28 12:02:15 +0000 | [diff] [blame] | 116 | |
| 117 | return CMD_SUCCESS; |
| 118 | } |
| 119 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 120 | /* When gateway is A.B.C.D format, gate is treated as nexthop |
| 121 | address other case gate is treated as interface name. */ |
| 122 | ret = inet_aton (gate_str, &gate); |
| 123 | if (ret) |
| 124 | ifname = NULL; |
| 125 | else |
| 126 | ifname = gate_str; |
| 127 | |
| 128 | if (add_cmd) |
Everton Marques | 33d86db | 2014-07-14 11:19:00 -0300 | [diff] [blame] | 129 | static_add_ipv4_safi (safi, &p, ifname ? NULL : &gate, ifname, flag, distance, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 130 | else |
Everton Marques | 33d86db | 2014-07-14 11:19:00 -0300 | [diff] [blame] | 131 | static_delete_ipv4_safi (safi, &p, ifname ? NULL : &gate, ifname, distance, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 132 | |
| 133 | return CMD_SUCCESS; |
| 134 | } |
| 135 | |
Everton Marques | 33d86db | 2014-07-14 11:19:00 -0300 | [diff] [blame] | 136 | static int |
| 137 | zebra_static_ipv4 (struct vty *vty, int add_cmd, const char *dest_str, |
| 138 | const char *mask_str, const char *gate_str, |
| 139 | const char *flag_str, const char *distance_str) |
| 140 | { |
| 141 | return zebra_static_ipv4_safi(vty, SAFI_UNICAST, add_cmd, dest_str, mask_str, gate_str, flag_str, distance_str); |
| 142 | } |
| 143 | |
| 144 | /* Static unicast routes for multicast RPF lookup. */ |
David Lamparter | a76681b | 2015-01-22 19:03:53 +0100 | [diff] [blame] | 145 | DEFUN (ip_mroute_dist, |
| 146 | ip_mroute_dist_cmd, |
| 147 | "ip mroute A.B.C.D/M (A.B.C.D|INTERFACE) <1-255>", |
Everton Marques | 33d86db | 2014-07-14 11:19:00 -0300 | [diff] [blame] | 148 | IP_STR |
| 149 | "Configure static unicast route into MRIB for multicast RPF lookup\n" |
| 150 | "IP destination prefix (e.g. 10.0.0.0/8)\n" |
| 151 | "Nexthop address\n" |
| 152 | "Nexthop interface name\n" |
| 153 | "Distance\n") |
| 154 | { |
David Lamparter | a76681b | 2015-01-22 19:03:53 +0100 | [diff] [blame] | 155 | return zebra_static_ipv4_safi(vty, SAFI_MULTICAST, 1, argv[0], NULL, argv[1], |
| 156 | NULL, argc > 2 ? argv[2] : NULL); |
Everton Marques | 33d86db | 2014-07-14 11:19:00 -0300 | [diff] [blame] | 157 | } |
| 158 | |
David Lamparter | a76681b | 2015-01-22 19:03:53 +0100 | [diff] [blame] | 159 | ALIAS (ip_mroute_dist, |
| 160 | ip_mroute_cmd, |
| 161 | "ip mroute A.B.C.D/M (A.B.C.D|INTERFACE)", |
| 162 | IP_STR |
| 163 | "Configure static unicast route into MRIB for multicast RPF lookup\n" |
| 164 | "IP destination prefix (e.g. 10.0.0.0/8)\n" |
| 165 | "Nexthop address\n" |
| 166 | "Nexthop interface name\n") |
| 167 | |
| 168 | DEFUN (no_ip_mroute_dist, |
| 169 | no_ip_mroute_dist_cmd, |
| 170 | "no ip mroute A.B.C.D/M (A.B.C.D|INTERFACE) <1-255>", |
Everton Marques | 33d86db | 2014-07-14 11:19:00 -0300 | [diff] [blame] | 171 | IP_STR |
| 172 | "Configure static unicast route into MRIB for multicast RPF lookup\n" |
| 173 | "IP destination prefix (e.g. 10.0.0.0/8)\n" |
| 174 | "Nexthop address\n" |
| 175 | "Nexthop interface name\n" |
| 176 | "Distance\n") |
| 177 | { |
David Lamparter | a76681b | 2015-01-22 19:03:53 +0100 | [diff] [blame] | 178 | return zebra_static_ipv4_safi(vty, SAFI_MULTICAST, 0, argv[0], NULL, argv[1], |
| 179 | NULL, argc > 2 ? argv[2] : NULL); |
Everton Marques | 33d86db | 2014-07-14 11:19:00 -0300 | [diff] [blame] | 180 | } |
| 181 | |
David Lamparter | a76681b | 2015-01-22 19:03:53 +0100 | [diff] [blame] | 182 | ALIAS (no_ip_mroute_dist, |
| 183 | no_ip_mroute_cmd, |
| 184 | "no ip mroute A.B.C.D/M (A.B.C.D|INTERFACE)", |
| 185 | NO_STR |
| 186 | IP_STR |
| 187 | "Configure static unicast route into MRIB for multicast RPF lookup\n" |
| 188 | "IP destination prefix (e.g. 10.0.0.0/8)\n" |
| 189 | "Nexthop address\n" |
| 190 | "Nexthop interface name\n") |
| 191 | |
David Lamparter | bd07812 | 2015-01-06 19:53:24 +0100 | [diff] [blame^] | 192 | DEFUN (ip_multicast_mode, |
| 193 | ip_multicast_mode_cmd, |
| 194 | "ip multicast rpf-lookup-mode (urib-only|mrib-only|mrib-then-urib|lower-distance|longer-prefix)", |
| 195 | IP_STR |
| 196 | "Multicast options\n" |
| 197 | "RPF lookup behavior\n" |
| 198 | "Lookup in unicast RIB only\n" |
| 199 | "Lookup in multicast RIB only\n" |
| 200 | "Try multicast RIB first, fall back to unicast RIB\n" |
| 201 | "Lookup both, use entry with lower distance\n" |
| 202 | "Lookup both, use entry with longer prefix\n") |
| 203 | { |
| 204 | if (!strncmp (argv[0], "u", 1)) |
| 205 | multicast_mode_ipv4_set (MCAST_URIB_ONLY); |
| 206 | else if (!strncmp (argv[0], "mrib-o", 6)) |
| 207 | multicast_mode_ipv4_set (MCAST_MRIB_ONLY); |
| 208 | else if (!strncmp (argv[0], "mrib-t", 6)) |
| 209 | multicast_mode_ipv4_set (MCAST_MIX_MRIB_FIRST); |
| 210 | else if (!strncmp (argv[0], "low", 3)) |
| 211 | multicast_mode_ipv4_set (MCAST_MIX_DISTANCE); |
| 212 | else if (!strncmp (argv[0], "lon", 3)) |
| 213 | multicast_mode_ipv4_set (MCAST_MIX_PFXLEN); |
| 214 | else |
| 215 | { |
| 216 | vty_out (vty, "Invalid mode specified%s", VTY_NEWLINE); |
| 217 | return CMD_WARNING; |
| 218 | } |
| 219 | |
| 220 | return CMD_SUCCESS; |
| 221 | } |
| 222 | |
| 223 | DEFUN (no_ip_multicast_mode, |
| 224 | no_ip_multicast_mode_cmd, |
| 225 | "no ip multicast rpf-lookup-mode (urib-only|mrib-only|mrib-then-urib|lower-distance|longer-prefix)", |
| 226 | NO_STR |
| 227 | IP_STR |
| 228 | "Multicast options\n" |
| 229 | "RPF lookup behavior\n" |
| 230 | "Lookup in unicast RIB only\n" |
| 231 | "Lookup in multicast RIB only\n" |
| 232 | "Try multicast RIB first, fall back to unicast RIB\n" |
| 233 | "Lookup both, use entry with lower distance\n" |
| 234 | "Lookup both, use entry with longer prefix\n") |
| 235 | { |
| 236 | multicast_mode_ipv4_set (MCAST_NO_CONFIG); |
| 237 | return CMD_SUCCESS; |
| 238 | } |
| 239 | |
| 240 | ALIAS (no_ip_multicast_mode, |
| 241 | no_ip_multicast_mode_noarg_cmd, |
| 242 | "no ip multicast rpf-lookup-mode", |
| 243 | NO_STR |
| 244 | IP_STR |
| 245 | "Multicast options\n" |
| 246 | "RPF lookup behavior\n") |
| 247 | |
Everton Marques | 33d86db | 2014-07-14 11:19:00 -0300 | [diff] [blame] | 248 | DEFUN (show_ip_rpf, |
| 249 | show_ip_rpf_cmd, |
| 250 | "show ip rpf", |
| 251 | SHOW_STR |
| 252 | IP_STR |
| 253 | "Display RPF information for multicast source\n") |
| 254 | { |
| 255 | return do_show_ip_route(vty, SAFI_MULTICAST); |
| 256 | } |
| 257 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 258 | /* Static route configuration. */ |
| 259 | DEFUN (ip_route, |
| 260 | ip_route_cmd, |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 261 | "ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0)", |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 262 | IP_STR |
| 263 | "Establish static routes\n" |
| 264 | "IP destination prefix (e.g. 10.0.0.0/8)\n" |
| 265 | "IP gateway address\n" |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 266 | "IP gateway interface name\n" |
| 267 | "Null interface\n") |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 268 | { |
| 269 | return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], NULL, NULL); |
| 270 | } |
| 271 | |
| 272 | DEFUN (ip_route_flags, |
| 273 | ip_route_flags_cmd, |
| 274 | "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] | 275 | IP_STR |
| 276 | "Establish static routes\n" |
| 277 | "IP destination prefix (e.g. 10.0.0.0/8)\n" |
| 278 | "IP gateway address\n" |
| 279 | "IP gateway interface name\n" |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 280 | "Emit an ICMP unreachable when matched\n" |
| 281 | "Silently discard pkts when matched\n") |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 282 | { |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 283 | 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] | 284 | } |
| 285 | |
hasso | 457ef55 | 2003-05-28 12:02:15 +0000 | [diff] [blame] | 286 | DEFUN (ip_route_flags2, |
| 287 | ip_route_flags2_cmd, |
| 288 | "ip route A.B.C.D/M (reject|blackhole)", |
| 289 | IP_STR |
| 290 | "Establish static routes\n" |
| 291 | "IP destination prefix (e.g. 10.0.0.0/8)\n" |
| 292 | "Emit an ICMP unreachable when matched\n" |
| 293 | "Silently discard pkts when matched\n") |
| 294 | { |
| 295 | return zebra_static_ipv4 (vty, 1, argv[0], NULL, NULL, argv[1], NULL); |
| 296 | } |
| 297 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 298 | /* Mask as A.B.C.D format. */ |
| 299 | DEFUN (ip_route_mask, |
| 300 | ip_route_mask_cmd, |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 301 | "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] | 302 | IP_STR |
| 303 | "Establish static routes\n" |
| 304 | "IP destination prefix\n" |
| 305 | "IP destination prefix mask\n" |
| 306 | "IP gateway address\n" |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 307 | "IP gateway interface name\n" |
| 308 | "Null interface\n") |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 309 | { |
| 310 | return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], NULL, NULL); |
| 311 | } |
| 312 | |
| 313 | DEFUN (ip_route_mask_flags, |
| 314 | ip_route_mask_flags_cmd, |
| 315 | "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] | 316 | IP_STR |
| 317 | "Establish static routes\n" |
| 318 | "IP destination prefix\n" |
| 319 | "IP destination prefix mask\n" |
| 320 | "IP gateway address\n" |
| 321 | "IP gateway interface name\n" |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 322 | "Emit an ICMP unreachable when matched\n" |
| 323 | "Silently discard pkts when matched\n") |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 324 | { |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 325 | 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] | 326 | } |
| 327 | |
hasso | 457ef55 | 2003-05-28 12:02:15 +0000 | [diff] [blame] | 328 | DEFUN (ip_route_mask_flags2, |
| 329 | ip_route_mask_flags2_cmd, |
| 330 | "ip route A.B.C.D A.B.C.D (reject|blackhole)", |
| 331 | IP_STR |
| 332 | "Establish static routes\n" |
| 333 | "IP destination prefix\n" |
| 334 | "IP destination prefix mask\n" |
| 335 | "Emit an ICMP unreachable when matched\n" |
| 336 | "Silently discard pkts when matched\n") |
| 337 | { |
| 338 | return zebra_static_ipv4 (vty, 1, argv[0], argv[1], NULL, argv[2], NULL); |
| 339 | } |
| 340 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 341 | /* Distance option value. */ |
| 342 | DEFUN (ip_route_distance, |
| 343 | ip_route_distance_cmd, |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 344 | "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] | 345 | IP_STR |
| 346 | "Establish static routes\n" |
| 347 | "IP destination prefix (e.g. 10.0.0.0/8)\n" |
| 348 | "IP gateway address\n" |
| 349 | "IP gateway interface name\n" |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 350 | "Null interface\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 351 | "Distance value for this route\n") |
| 352 | { |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 353 | return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], NULL, argv[2]); |
| 354 | } |
| 355 | |
| 356 | DEFUN (ip_route_flags_distance, |
| 357 | ip_route_flags_distance_cmd, |
| 358 | "ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>", |
| 359 | IP_STR |
| 360 | "Establish static routes\n" |
| 361 | "IP destination prefix (e.g. 10.0.0.0/8)\n" |
| 362 | "IP gateway address\n" |
| 363 | "IP gateway interface name\n" |
| 364 | "Emit an ICMP unreachable when matched\n" |
| 365 | "Silently discard pkts when matched\n" |
| 366 | "Distance value for this route\n") |
| 367 | { |
| 368 | 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] | 369 | } |
| 370 | |
hasso | 457ef55 | 2003-05-28 12:02:15 +0000 | [diff] [blame] | 371 | DEFUN (ip_route_flags_distance2, |
| 372 | ip_route_flags_distance2_cmd, |
| 373 | "ip route A.B.C.D/M (reject|blackhole) <1-255>", |
| 374 | IP_STR |
| 375 | "Establish static routes\n" |
| 376 | "IP destination prefix (e.g. 10.0.0.0/8)\n" |
| 377 | "Emit an ICMP unreachable when matched\n" |
| 378 | "Silently discard pkts when matched\n" |
| 379 | "Distance value for this route\n") |
| 380 | { |
| 381 | return zebra_static_ipv4 (vty, 1, argv[0], NULL, NULL, argv[1], argv[2]); |
| 382 | } |
| 383 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 384 | DEFUN (ip_route_mask_distance, |
| 385 | ip_route_mask_distance_cmd, |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 386 | "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] | 387 | IP_STR |
| 388 | "Establish static routes\n" |
| 389 | "IP destination prefix\n" |
| 390 | "IP destination prefix mask\n" |
| 391 | "IP gateway address\n" |
| 392 | "IP gateway interface name\n" |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 393 | "Null interface\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 394 | "Distance value for this route\n") |
| 395 | { |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 396 | return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], NULL, argv[3]); |
| 397 | } |
| 398 | |
| 399 | DEFUN (ip_route_mask_flags_distance, |
| 400 | ip_route_mask_flags_distance_cmd, |
| 401 | "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>", |
| 402 | IP_STR |
| 403 | "Establish static routes\n" |
| 404 | "IP destination prefix\n" |
| 405 | "IP destination prefix mask\n" |
| 406 | "IP gateway address\n" |
| 407 | "IP gateway interface name\n" |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 408 | "Emit an ICMP unreachable when matched\n" |
Christian Franke | 2b00515 | 2013-09-30 12:27:49 +0000 | [diff] [blame] | 409 | "Silently discard pkts when matched\n" |
| 410 | "Distance value for this route\n") |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 411 | { |
| 412 | 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] | 413 | } |
| 414 | |
hasso | 457ef55 | 2003-05-28 12:02:15 +0000 | [diff] [blame] | 415 | DEFUN (ip_route_mask_flags_distance2, |
| 416 | ip_route_mask_flags_distance2_cmd, |
| 417 | "ip route A.B.C.D A.B.C.D (reject|blackhole) <1-255>", |
| 418 | IP_STR |
| 419 | "Establish static routes\n" |
| 420 | "IP destination prefix\n" |
| 421 | "IP destination prefix mask\n" |
hasso | 457ef55 | 2003-05-28 12:02:15 +0000 | [diff] [blame] | 422 | "Emit an ICMP unreachable when matched\n" |
Christian Franke | 2b00515 | 2013-09-30 12:27:49 +0000 | [diff] [blame] | 423 | "Silently discard pkts when matched\n" |
| 424 | "Distance value for this route\n") |
hasso | 457ef55 | 2003-05-28 12:02:15 +0000 | [diff] [blame] | 425 | { |
| 426 | return zebra_static_ipv4 (vty, 1, argv[0], argv[1], NULL, argv[2], argv[3]); |
| 427 | } |
| 428 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 429 | DEFUN (no_ip_route, |
| 430 | no_ip_route_cmd, |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 431 | "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] | 432 | NO_STR |
| 433 | IP_STR |
| 434 | "Establish static routes\n" |
| 435 | "IP destination prefix (e.g. 10.0.0.0/8)\n" |
| 436 | "IP gateway address\n" |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 437 | "IP gateway interface name\n" |
| 438 | "Null interface\n") |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 439 | { |
| 440 | return zebra_static_ipv4 (vty, 0, argv[0], NULL, argv[1], NULL, NULL); |
| 441 | } |
| 442 | |
| 443 | ALIAS (no_ip_route, |
| 444 | no_ip_route_flags_cmd, |
| 445 | "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] | 446 | NO_STR |
| 447 | IP_STR |
| 448 | "Establish static routes\n" |
| 449 | "IP destination prefix (e.g. 10.0.0.0/8)\n" |
| 450 | "IP gateway address\n" |
| 451 | "IP gateway interface name\n" |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 452 | "Emit an ICMP unreachable when matched\n" |
| 453 | "Silently discard pkts when matched\n") |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 454 | |
hasso | 457ef55 | 2003-05-28 12:02:15 +0000 | [diff] [blame] | 455 | DEFUN (no_ip_route_flags2, |
| 456 | no_ip_route_flags2_cmd, |
| 457 | "no ip route A.B.C.D/M (reject|blackhole)", |
| 458 | NO_STR |
| 459 | IP_STR |
| 460 | "Establish static routes\n" |
| 461 | "IP destination prefix (e.g. 10.0.0.0/8)\n" |
| 462 | "Emit an ICMP unreachable when matched\n" |
| 463 | "Silently discard pkts when matched\n") |
| 464 | { |
| 465 | return zebra_static_ipv4 (vty, 0, argv[0], NULL, NULL, NULL, NULL); |
| 466 | } |
| 467 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 468 | DEFUN (no_ip_route_mask, |
| 469 | no_ip_route_mask_cmd, |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 470 | "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] | 471 | NO_STR |
| 472 | IP_STR |
| 473 | "Establish static routes\n" |
| 474 | "IP destination prefix\n" |
| 475 | "IP destination prefix mask\n" |
| 476 | "IP gateway address\n" |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 477 | "IP gateway interface name\n" |
| 478 | "Null interface\n") |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 479 | { |
| 480 | return zebra_static_ipv4 (vty, 0, argv[0], argv[1], argv[2], NULL, NULL); |
| 481 | } |
| 482 | |
| 483 | ALIAS (no_ip_route_mask, |
| 484 | no_ip_route_mask_flags_cmd, |
| 485 | "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] | 486 | NO_STR |
| 487 | IP_STR |
| 488 | "Establish static routes\n" |
| 489 | "IP destination prefix\n" |
| 490 | "IP destination prefix mask\n" |
| 491 | "IP gateway address\n" |
| 492 | "IP gateway interface name\n" |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 493 | "Emit an ICMP unreachable when matched\n" |
| 494 | "Silently discard pkts when matched\n") |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 495 | |
hasso | 457ef55 | 2003-05-28 12:02:15 +0000 | [diff] [blame] | 496 | DEFUN (no_ip_route_mask_flags2, |
| 497 | no_ip_route_mask_flags2_cmd, |
| 498 | "no ip route A.B.C.D A.B.C.D (reject|blackhole)", |
| 499 | NO_STR |
| 500 | IP_STR |
| 501 | "Establish static routes\n" |
| 502 | "IP destination prefix\n" |
| 503 | "IP destination prefix mask\n" |
| 504 | "Emit an ICMP unreachable when matched\n" |
| 505 | "Silently discard pkts when matched\n") |
| 506 | { |
| 507 | return zebra_static_ipv4 (vty, 0, argv[0], argv[1], NULL, NULL, NULL); |
| 508 | } |
| 509 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 510 | DEFUN (no_ip_route_distance, |
| 511 | no_ip_route_distance_cmd, |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 512 | "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] | 513 | NO_STR |
| 514 | IP_STR |
| 515 | "Establish static routes\n" |
| 516 | "IP destination prefix (e.g. 10.0.0.0/8)\n" |
| 517 | "IP gateway address\n" |
| 518 | "IP gateway interface name\n" |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 519 | "Null interface\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 520 | "Distance value for this route\n") |
| 521 | { |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 522 | return zebra_static_ipv4 (vty, 0, argv[0], NULL, argv[1], NULL, argv[2]); |
| 523 | } |
| 524 | |
| 525 | DEFUN (no_ip_route_flags_distance, |
| 526 | no_ip_route_flags_distance_cmd, |
| 527 | "no ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>", |
| 528 | NO_STR |
| 529 | IP_STR |
| 530 | "Establish static routes\n" |
| 531 | "IP destination prefix (e.g. 10.0.0.0/8)\n" |
| 532 | "IP gateway address\n" |
| 533 | "IP gateway interface name\n" |
| 534 | "Emit an ICMP unreachable when matched\n" |
| 535 | "Silently discard pkts when matched\n" |
| 536 | "Distance value for this route\n") |
| 537 | { |
| 538 | 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] | 539 | } |
| 540 | |
hasso | 457ef55 | 2003-05-28 12:02:15 +0000 | [diff] [blame] | 541 | DEFUN (no_ip_route_flags_distance2, |
| 542 | no_ip_route_flags_distance2_cmd, |
| 543 | "no ip route A.B.C.D/M (reject|blackhole) <1-255>", |
| 544 | NO_STR |
| 545 | IP_STR |
| 546 | "Establish static routes\n" |
| 547 | "IP destination prefix (e.g. 10.0.0.0/8)\n" |
| 548 | "Emit an ICMP unreachable when matched\n" |
| 549 | "Silently discard pkts when matched\n" |
| 550 | "Distance value for this route\n") |
| 551 | { |
| 552 | return zebra_static_ipv4 (vty, 0, argv[0], NULL, NULL, argv[1], argv[2]); |
| 553 | } |
| 554 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 555 | DEFUN (no_ip_route_mask_distance, |
| 556 | no_ip_route_mask_distance_cmd, |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 557 | "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] | 558 | NO_STR |
| 559 | IP_STR |
| 560 | "Establish static routes\n" |
| 561 | "IP destination prefix\n" |
| 562 | "IP destination prefix mask\n" |
| 563 | "IP gateway address\n" |
| 564 | "IP gateway interface name\n" |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 565 | "Null interface\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 566 | "Distance value for this route\n") |
| 567 | { |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 568 | return zebra_static_ipv4 (vty, 0, argv[0], argv[1], argv[2], NULL, argv[3]); |
| 569 | } |
| 570 | |
| 571 | DEFUN (no_ip_route_mask_flags_distance, |
| 572 | no_ip_route_mask_flags_distance_cmd, |
| 573 | "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>", |
| 574 | NO_STR |
| 575 | IP_STR |
| 576 | "Establish static routes\n" |
| 577 | "IP destination prefix\n" |
| 578 | "IP destination prefix mask\n" |
| 579 | "IP gateway address\n" |
| 580 | "IP gateway interface name\n" |
| 581 | "Emit an ICMP unreachable when matched\n" |
| 582 | "Silently discard pkts when matched\n" |
| 583 | "Distance value for this route\n") |
| 584 | { |
| 585 | 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] | 586 | } |
| 587 | |
hasso | 457ef55 | 2003-05-28 12:02:15 +0000 | [diff] [blame] | 588 | DEFUN (no_ip_route_mask_flags_distance2, |
| 589 | no_ip_route_mask_flags_distance2_cmd, |
| 590 | "no ip route A.B.C.D A.B.C.D (reject|blackhole) <1-255>", |
| 591 | NO_STR |
| 592 | IP_STR |
| 593 | "Establish static routes\n" |
| 594 | "IP destination prefix\n" |
| 595 | "IP destination prefix mask\n" |
| 596 | "Emit an ICMP unreachable when matched\n" |
| 597 | "Silently discard pkts when matched\n" |
| 598 | "Distance value for this route\n") |
| 599 | { |
| 600 | return zebra_static_ipv4 (vty, 0, argv[0], argv[1], NULL, argv[2], argv[3]); |
| 601 | } |
| 602 | |
Paul Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 603 | char *proto_rm[AFI_MAX][ZEBRA_ROUTE_MAX+1]; /* "any" == ZEBRA_ROUTE_MAX */ |
| 604 | |
| 605 | DEFUN (ip_protocol, |
| 606 | ip_protocol_cmd, |
| 607 | "ip protocol PROTO route-map ROUTE-MAP", |
| 608 | NO_STR |
| 609 | "Apply route map to PROTO\n" |
| 610 | "Protocol name\n" |
| 611 | "Route map name\n") |
| 612 | { |
| 613 | int i; |
| 614 | |
| 615 | if (strcasecmp(argv[0], "any") == 0) |
| 616 | i = ZEBRA_ROUTE_MAX; |
| 617 | else |
| 618 | i = proto_name2num(argv[0]); |
| 619 | if (i < 0) |
| 620 | { |
| 621 | vty_out (vty, "invalid protocol name \"%s\"%s", argv[0] ? argv[0] : "", |
| 622 | VTY_NEWLINE); |
| 623 | return CMD_WARNING; |
| 624 | } |
| 625 | if (proto_rm[AFI_IP][i]) |
| 626 | XFREE (MTYPE_ROUTE_MAP_NAME, proto_rm[AFI_IP][i]); |
| 627 | proto_rm[AFI_IP][i] = XSTRDUP (MTYPE_ROUTE_MAP_NAME, argv[1]); |
| 628 | return CMD_SUCCESS; |
| 629 | } |
| 630 | |
| 631 | DEFUN (no_ip_protocol, |
| 632 | no_ip_protocol_cmd, |
| 633 | "no ip protocol PROTO", |
| 634 | NO_STR |
| 635 | "Remove route map from PROTO\n" |
| 636 | "Protocol name\n") |
| 637 | { |
| 638 | int i; |
| 639 | |
| 640 | if (strcasecmp(argv[0], "any") == 0) |
| 641 | i = ZEBRA_ROUTE_MAX; |
| 642 | else |
| 643 | i = proto_name2num(argv[0]); |
| 644 | if (i < 0) |
| 645 | { |
| 646 | vty_out (vty, "invalid protocol name \"%s\"%s", argv[0] ? argv[0] : "", |
| 647 | VTY_NEWLINE); |
| 648 | return CMD_WARNING; |
| 649 | } |
| 650 | if (proto_rm[AFI_IP][i]) |
| 651 | XFREE (MTYPE_ROUTE_MAP_NAME, proto_rm[AFI_IP][i]); |
| 652 | proto_rm[AFI_IP][i] = NULL; |
| 653 | return CMD_SUCCESS; |
| 654 | } |
| 655 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 656 | /* New RIB. Detailed information for IPv4 route. */ |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 657 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 658 | vty_show_ip_route_detail (struct vty *vty, struct route_node *rn) |
| 659 | { |
| 660 | struct rib *rib; |
Christian Franke | fa713d9 | 2013-07-05 15:35:37 +0000 | [diff] [blame] | 661 | struct nexthop *nexthop, *tnexthop; |
| 662 | int recursing; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 663 | |
Avneesh Sachdev | 9fd92e3 | 2012-11-13 22:48:53 +0000 | [diff] [blame] | 664 | RNODE_FOREACH_RIB (rn, rib) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 665 | { |
| 666 | vty_out (vty, "Routing entry for %s/%d%s", |
| 667 | inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen, |
| 668 | VTY_NEWLINE); |
ajs | f52d13c | 2005-10-01 17:38:06 +0000 | [diff] [blame] | 669 | vty_out (vty, " Known via \"%s\"", zebra_route_string (rib->type)); |
Jorge Boncompte [DTI2] | ddc943d | 2012-04-13 13:46:07 +0200 | [diff] [blame] | 670 | vty_out (vty, ", distance %u, metric %u", rib->distance, rib->metric); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 671 | if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED)) |
| 672 | vty_out (vty, ", best"); |
| 673 | if (rib->refcnt) |
| 674 | vty_out (vty, ", refcnt %ld", rib->refcnt); |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 675 | if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE)) |
| 676 | vty_out (vty, ", blackhole"); |
| 677 | if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT)) |
| 678 | vty_out (vty, ", reject"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 679 | vty_out (vty, "%s", VTY_NEWLINE); |
| 680 | |
| 681 | #define ONE_DAY_SECOND 60*60*24 |
| 682 | #define ONE_WEEK_SECOND 60*60*24*7 |
| 683 | if (rib->type == ZEBRA_ROUTE_RIP |
| 684 | || rib->type == ZEBRA_ROUTE_OSPF |
Juliusz Chroboczek | 578ce37 | 2012-02-09 13:42:28 +0100 | [diff] [blame] | 685 | || rib->type == ZEBRA_ROUTE_BABEL |
jardin | 9e867fe | 2003-12-23 08:56:18 +0000 | [diff] [blame] | 686 | || rib->type == ZEBRA_ROUTE_ISIS |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 687 | || rib->type == ZEBRA_ROUTE_BGP) |
| 688 | { |
| 689 | time_t uptime; |
| 690 | struct tm *tm; |
| 691 | |
| 692 | uptime = time (NULL); |
| 693 | uptime -= rib->uptime; |
| 694 | tm = gmtime (&uptime); |
| 695 | |
| 696 | vty_out (vty, " Last update "); |
| 697 | |
| 698 | if (uptime < ONE_DAY_SECOND) |
| 699 | vty_out (vty, "%02d:%02d:%02d", |
| 700 | tm->tm_hour, tm->tm_min, tm->tm_sec); |
| 701 | else if (uptime < ONE_WEEK_SECOND) |
| 702 | vty_out (vty, "%dd%02dh%02dm", |
| 703 | tm->tm_yday, tm->tm_hour, tm->tm_min); |
| 704 | else |
| 705 | vty_out (vty, "%02dw%dd%02dh", |
| 706 | tm->tm_yday/7, |
| 707 | tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour); |
| 708 | vty_out (vty, " ago%s", VTY_NEWLINE); |
| 709 | } |
| 710 | |
Christian Franke | fa713d9 | 2013-07-05 15:35:37 +0000 | [diff] [blame] | 711 | for (ALL_NEXTHOPS_RO(rib->nexthop, nexthop, tnexthop, recursing)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 712 | { |
Paul Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 713 | char addrstr[32]; |
| 714 | |
Christian Franke | fa713d9 | 2013-07-05 15:35:37 +0000 | [diff] [blame] | 715 | vty_out (vty, " %c%s", |
| 716 | CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB) ? '*' : ' ', |
| 717 | recursing ? " " : ""); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 718 | |
| 719 | switch (nexthop->type) |
| 720 | { |
| 721 | case NEXTHOP_TYPE_IPV4: |
| 722 | case NEXTHOP_TYPE_IPV4_IFINDEX: |
| 723 | vty_out (vty, " %s", inet_ntoa (nexthop->gate.ipv4)); |
| 724 | if (nexthop->ifindex) |
| 725 | vty_out (vty, ", via %s", ifindex2ifname (nexthop->ifindex)); |
| 726 | break; |
| 727 | case NEXTHOP_TYPE_IFINDEX: |
| 728 | vty_out (vty, " directly connected, %s", |
| 729 | ifindex2ifname (nexthop->ifindex)); |
| 730 | break; |
| 731 | case NEXTHOP_TYPE_IFNAME: |
| 732 | vty_out (vty, " directly connected, %s", nexthop->ifname); |
| 733 | break; |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 734 | case NEXTHOP_TYPE_BLACKHOLE: |
paul | 7021c42 | 2003-07-15 12:52:22 +0000 | [diff] [blame] | 735 | vty_out (vty, " directly connected, Null0"); |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 736 | break; |
paul | 7021c42 | 2003-07-15 12:52:22 +0000 | [diff] [blame] | 737 | default: |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 738 | break; |
| 739 | } |
| 740 | if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE)) |
| 741 | vty_out (vty, " inactive"); |
| 742 | |
Christian Franke | e8d3d29 | 2013-07-05 15:35:39 +0000 | [diff] [blame] | 743 | if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ONLINK)) |
| 744 | vty_out (vty, " onlink"); |
| 745 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 746 | if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE)) |
Christian Franke | fa713d9 | 2013-07-05 15:35:37 +0000 | [diff] [blame] | 747 | vty_out (vty, " (recursive)"); |
Christian Franke | 5b9f518 | 2013-05-25 14:01:34 +0000 | [diff] [blame] | 748 | |
Paul Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 749 | switch (nexthop->type) |
| 750 | { |
| 751 | case NEXTHOP_TYPE_IPV4: |
| 752 | case NEXTHOP_TYPE_IPV4_IFINDEX: |
| 753 | case NEXTHOP_TYPE_IPV4_IFNAME: |
| 754 | if (nexthop->src.ipv4.s_addr) |
| 755 | { |
| 756 | if (inet_ntop(AF_INET, &nexthop->src.ipv4, addrstr, |
| 757 | sizeof addrstr)) |
| 758 | vty_out (vty, ", src %s", addrstr); |
| 759 | } |
| 760 | break; |
Andrew J. Schorr | 0930331 | 2007-05-30 20:10:34 +0000 | [diff] [blame] | 761 | #ifdef HAVE_IPV6 |
Paul Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 762 | case NEXTHOP_TYPE_IPV6: |
| 763 | case NEXTHOP_TYPE_IPV6_IFINDEX: |
| 764 | case NEXTHOP_TYPE_IPV6_IFNAME: |
| 765 | if (!IPV6_ADDR_SAME(&nexthop->src.ipv6, &in6addr_any)) |
| 766 | { |
| 767 | if (inet_ntop(AF_INET6, &nexthop->src.ipv6, addrstr, |
| 768 | sizeof addrstr)) |
| 769 | vty_out (vty, ", src %s", addrstr); |
| 770 | } |
| 771 | break; |
Andrew J. Schorr | 0930331 | 2007-05-30 20:10:34 +0000 | [diff] [blame] | 772 | #endif /* HAVE_IPV6 */ |
Paul Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 773 | default: |
| 774 | break; |
| 775 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 776 | vty_out (vty, "%s", VTY_NEWLINE); |
| 777 | } |
| 778 | vty_out (vty, "%s", VTY_NEWLINE); |
| 779 | } |
| 780 | } |
| 781 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 782 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 783 | vty_show_ip_route (struct vty *vty, struct route_node *rn, struct rib *rib) |
| 784 | { |
Christian Franke | fa713d9 | 2013-07-05 15:35:37 +0000 | [diff] [blame] | 785 | struct nexthop *nexthop, *tnexthop; |
| 786 | int recursing; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 787 | int len = 0; |
| 788 | char buf[BUFSIZ]; |
| 789 | |
| 790 | /* Nexthop information. */ |
Christian Franke | fa713d9 | 2013-07-05 15:35:37 +0000 | [diff] [blame] | 791 | for (ALL_NEXTHOPS_RO(rib->nexthop, nexthop, tnexthop, recursing)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 792 | { |
| 793 | if (nexthop == rib->nexthop) |
| 794 | { |
| 795 | /* Prefix information. */ |
| 796 | len = vty_out (vty, "%c%c%c %s/%d", |
ajs | f52d13c | 2005-10-01 17:38:06 +0000 | [diff] [blame] | 797 | zebra_route_char (rib->type), |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 798 | CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED) |
| 799 | ? '>' : ' ', |
| 800 | CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB) |
| 801 | ? '*' : ' ', |
| 802 | inet_ntop (AF_INET, &rn->p.u.prefix, buf, BUFSIZ), |
| 803 | rn->p.prefixlen); |
| 804 | |
| 805 | /* Distance and metric display. */ |
| 806 | if (rib->type != ZEBRA_ROUTE_CONNECT |
| 807 | && rib->type != ZEBRA_ROUTE_KERNEL) |
| 808 | len += vty_out (vty, " [%d/%d]", rib->distance, |
| 809 | rib->metric); |
| 810 | } |
| 811 | else |
| 812 | vty_out (vty, " %c%*c", |
| 813 | CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB) |
| 814 | ? '*' : ' ', |
Christian Franke | fa713d9 | 2013-07-05 15:35:37 +0000 | [diff] [blame] | 815 | len - 3 + (2 * recursing), ' '); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 816 | |
| 817 | switch (nexthop->type) |
| 818 | { |
| 819 | case NEXTHOP_TYPE_IPV4: |
| 820 | case NEXTHOP_TYPE_IPV4_IFINDEX: |
| 821 | vty_out (vty, " via %s", inet_ntoa (nexthop->gate.ipv4)); |
| 822 | if (nexthop->ifindex) |
| 823 | vty_out (vty, ", %s", ifindex2ifname (nexthop->ifindex)); |
| 824 | break; |
| 825 | case NEXTHOP_TYPE_IFINDEX: |
| 826 | vty_out (vty, " is directly connected, %s", |
| 827 | ifindex2ifname (nexthop->ifindex)); |
| 828 | break; |
| 829 | case NEXTHOP_TYPE_IFNAME: |
| 830 | vty_out (vty, " is directly connected, %s", nexthop->ifname); |
| 831 | break; |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 832 | case NEXTHOP_TYPE_BLACKHOLE: |
paul | 7021c42 | 2003-07-15 12:52:22 +0000 | [diff] [blame] | 833 | vty_out (vty, " is directly connected, Null0"); |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 834 | break; |
paul | 7021c42 | 2003-07-15 12:52:22 +0000 | [diff] [blame] | 835 | default: |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 836 | break; |
| 837 | } |
| 838 | if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE)) |
| 839 | vty_out (vty, " inactive"); |
| 840 | |
Christian Franke | e8d3d29 | 2013-07-05 15:35:39 +0000 | [diff] [blame] | 841 | if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ONLINK)) |
| 842 | vty_out (vty, " onlink"); |
| 843 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 844 | if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE)) |
Christian Franke | fa713d9 | 2013-07-05 15:35:37 +0000 | [diff] [blame] | 845 | vty_out (vty, " (recursive)"); |
| 846 | |
Paul Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 847 | switch (nexthop->type) |
| 848 | { |
| 849 | case NEXTHOP_TYPE_IPV4: |
| 850 | case NEXTHOP_TYPE_IPV4_IFINDEX: |
| 851 | case NEXTHOP_TYPE_IPV4_IFNAME: |
| 852 | if (nexthop->src.ipv4.s_addr) |
| 853 | { |
| 854 | if (inet_ntop(AF_INET, &nexthop->src.ipv4, buf, sizeof buf)) |
| 855 | vty_out (vty, ", src %s", buf); |
| 856 | } |
| 857 | break; |
Andrew J. Schorr | 0930331 | 2007-05-30 20:10:34 +0000 | [diff] [blame] | 858 | #ifdef HAVE_IPV6 |
Paul Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 859 | case NEXTHOP_TYPE_IPV6: |
| 860 | case NEXTHOP_TYPE_IPV6_IFINDEX: |
| 861 | case NEXTHOP_TYPE_IPV6_IFNAME: |
| 862 | if (!IPV6_ADDR_SAME(&nexthop->src.ipv6, &in6addr_any)) |
| 863 | { |
| 864 | if (inet_ntop(AF_INET6, &nexthop->src.ipv6, buf, sizeof buf)) |
| 865 | vty_out (vty, ", src %s", buf); |
| 866 | } |
| 867 | break; |
Andrew J. Schorr | 0930331 | 2007-05-30 20:10:34 +0000 | [diff] [blame] | 868 | #endif /* HAVE_IPV6 */ |
Paul Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 869 | default: |
| 870 | break; |
| 871 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 872 | |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 873 | if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE)) |
| 874 | vty_out (vty, ", bh"); |
| 875 | if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT)) |
| 876 | vty_out (vty, ", rej"); |
| 877 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 878 | if (rib->type == ZEBRA_ROUTE_RIP |
| 879 | || rib->type == ZEBRA_ROUTE_OSPF |
Juliusz Chroboczek | 578ce37 | 2012-02-09 13:42:28 +0100 | [diff] [blame] | 880 | || rib->type == ZEBRA_ROUTE_BABEL |
jardin | 9e867fe | 2003-12-23 08:56:18 +0000 | [diff] [blame] | 881 | || rib->type == ZEBRA_ROUTE_ISIS |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 882 | || rib->type == ZEBRA_ROUTE_BGP) |
| 883 | { |
| 884 | time_t uptime; |
| 885 | struct tm *tm; |
| 886 | |
| 887 | uptime = time (NULL); |
| 888 | uptime -= rib->uptime; |
| 889 | tm = gmtime (&uptime); |
| 890 | |
| 891 | #define ONE_DAY_SECOND 60*60*24 |
| 892 | #define ONE_WEEK_SECOND 60*60*24*7 |
| 893 | |
| 894 | if (uptime < ONE_DAY_SECOND) |
| 895 | vty_out (vty, ", %02d:%02d:%02d", |
| 896 | tm->tm_hour, tm->tm_min, tm->tm_sec); |
| 897 | else if (uptime < ONE_WEEK_SECOND) |
| 898 | vty_out (vty, ", %dd%02dh%02dm", |
| 899 | tm->tm_yday, tm->tm_hour, tm->tm_min); |
| 900 | else |
| 901 | vty_out (vty, ", %02dw%dd%02dh", |
| 902 | tm->tm_yday/7, |
| 903 | tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour); |
| 904 | } |
| 905 | vty_out (vty, "%s", VTY_NEWLINE); |
| 906 | } |
| 907 | } |
| 908 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 909 | DEFUN (show_ip_route, |
| 910 | show_ip_route_cmd, |
| 911 | "show ip route", |
| 912 | SHOW_STR |
| 913 | IP_STR |
| 914 | "IP routing table\n") |
| 915 | { |
Everton Marques | 33d86db | 2014-07-14 11:19:00 -0300 | [diff] [blame] | 916 | return do_show_ip_route(vty, SAFI_UNICAST); |
| 917 | } |
| 918 | |
| 919 | static int do_show_ip_route(struct vty *vty, safi_t safi) { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 920 | struct route_table *table; |
| 921 | struct route_node *rn; |
| 922 | struct rib *rib; |
| 923 | int first = 1; |
| 924 | |
Everton Marques | 33d86db | 2014-07-14 11:19:00 -0300 | [diff] [blame] | 925 | table = vrf_table (AFI_IP, safi, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 926 | if (! table) |
| 927 | return CMD_SUCCESS; |
| 928 | |
| 929 | /* Show all IPv4 routes. */ |
| 930 | for (rn = route_top (table); rn; rn = route_next (rn)) |
Avneesh Sachdev | 9fd92e3 | 2012-11-13 22:48:53 +0000 | [diff] [blame] | 931 | RNODE_FOREACH_RIB (rn, rib) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 932 | { |
| 933 | if (first) |
| 934 | { |
David Lamparter | e0ca5fd | 2009-09-16 01:52:42 +0200 | [diff] [blame] | 935 | vty_out (vty, SHOW_ROUTE_V4_HEADER); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 936 | first = 0; |
| 937 | } |
| 938 | vty_show_ip_route (vty, rn, rib); |
| 939 | } |
| 940 | return CMD_SUCCESS; |
| 941 | } |
| 942 | |
| 943 | DEFUN (show_ip_route_prefix_longer, |
| 944 | show_ip_route_prefix_longer_cmd, |
| 945 | "show ip route A.B.C.D/M longer-prefixes", |
| 946 | SHOW_STR |
| 947 | IP_STR |
| 948 | "IP routing table\n" |
| 949 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" |
| 950 | "Show route matching the specified Network/Mask pair only\n") |
| 951 | { |
| 952 | struct route_table *table; |
| 953 | struct route_node *rn; |
| 954 | struct rib *rib; |
| 955 | struct prefix p; |
| 956 | int ret; |
| 957 | int first = 1; |
| 958 | |
| 959 | ret = str2prefix (argv[0], &p); |
| 960 | if (! ret) |
| 961 | { |
| 962 | vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE); |
| 963 | return CMD_WARNING; |
| 964 | } |
| 965 | |
| 966 | table = vrf_table (AFI_IP, SAFI_UNICAST, 0); |
| 967 | if (! table) |
| 968 | return CMD_SUCCESS; |
| 969 | |
| 970 | /* Show matched type IPv4 routes. */ |
| 971 | for (rn = route_top (table); rn; rn = route_next (rn)) |
Avneesh Sachdev | 9fd92e3 | 2012-11-13 22:48:53 +0000 | [diff] [blame] | 972 | RNODE_FOREACH_RIB (rn, rib) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 973 | if (prefix_match (&p, &rn->p)) |
| 974 | { |
| 975 | if (first) |
| 976 | { |
David Lamparter | e0ca5fd | 2009-09-16 01:52:42 +0200 | [diff] [blame] | 977 | vty_out (vty, SHOW_ROUTE_V4_HEADER); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 978 | first = 0; |
| 979 | } |
| 980 | vty_show_ip_route (vty, rn, rib); |
| 981 | } |
| 982 | return CMD_SUCCESS; |
| 983 | } |
| 984 | |
| 985 | DEFUN (show_ip_route_supernets, |
| 986 | show_ip_route_supernets_cmd, |
| 987 | "show ip route supernets-only", |
| 988 | SHOW_STR |
| 989 | IP_STR |
| 990 | "IP routing table\n" |
| 991 | "Show supernet entries only\n") |
| 992 | { |
| 993 | struct route_table *table; |
| 994 | struct route_node *rn; |
| 995 | struct rib *rib; |
| 996 | u_int32_t addr; |
| 997 | int first = 1; |
| 998 | |
| 999 | table = vrf_table (AFI_IP, SAFI_UNICAST, 0); |
| 1000 | if (! table) |
| 1001 | return CMD_SUCCESS; |
| 1002 | |
| 1003 | /* Show matched type IPv4 routes. */ |
| 1004 | for (rn = route_top (table); rn; rn = route_next (rn)) |
Avneesh Sachdev | 9fd92e3 | 2012-11-13 22:48:53 +0000 | [diff] [blame] | 1005 | RNODE_FOREACH_RIB (rn, rib) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1006 | { |
| 1007 | addr = ntohl (rn->p.u.prefix4.s_addr); |
| 1008 | |
| 1009 | if ((IN_CLASSC (addr) && rn->p.prefixlen < 24) |
| 1010 | || (IN_CLASSB (addr) && rn->p.prefixlen < 16) |
| 1011 | || (IN_CLASSA (addr) && rn->p.prefixlen < 8)) |
| 1012 | { |
| 1013 | if (first) |
| 1014 | { |
David Lamparter | e0ca5fd | 2009-09-16 01:52:42 +0200 | [diff] [blame] | 1015 | vty_out (vty, SHOW_ROUTE_V4_HEADER); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1016 | first = 0; |
| 1017 | } |
| 1018 | vty_show_ip_route (vty, rn, rib); |
| 1019 | } |
| 1020 | } |
| 1021 | return CMD_SUCCESS; |
| 1022 | } |
| 1023 | |
| 1024 | DEFUN (show_ip_route_protocol, |
| 1025 | show_ip_route_protocol_cmd, |
David Lamparter | e0ca5fd | 2009-09-16 01:52:42 +0200 | [diff] [blame] | 1026 | "show ip route " QUAGGA_IP_REDIST_STR_ZEBRA, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1027 | SHOW_STR |
| 1028 | IP_STR |
| 1029 | "IP routing table\n" |
David Lamparter | e0ca5fd | 2009-09-16 01:52:42 +0200 | [diff] [blame] | 1030 | QUAGGA_IP_REDIST_HELP_STR_ZEBRA) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1031 | { |
| 1032 | int type; |
| 1033 | struct route_table *table; |
| 1034 | struct route_node *rn; |
| 1035 | struct rib *rib; |
| 1036 | int first = 1; |
| 1037 | |
David Lamparter | e0ca5fd | 2009-09-16 01:52:42 +0200 | [diff] [blame] | 1038 | type = proto_redistnum (AFI_IP, argv[0]); |
| 1039 | if (type < 0) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1040 | { |
| 1041 | vty_out (vty, "Unknown route type%s", VTY_NEWLINE); |
| 1042 | return CMD_WARNING; |
| 1043 | } |
| 1044 | |
| 1045 | table = vrf_table (AFI_IP, SAFI_UNICAST, 0); |
| 1046 | if (! table) |
| 1047 | return CMD_SUCCESS; |
| 1048 | |
| 1049 | /* Show matched type IPv4 routes. */ |
| 1050 | for (rn = route_top (table); rn; rn = route_next (rn)) |
Avneesh Sachdev | 9fd92e3 | 2012-11-13 22:48:53 +0000 | [diff] [blame] | 1051 | RNODE_FOREACH_RIB (rn, rib) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1052 | if (rib->type == type) |
| 1053 | { |
| 1054 | if (first) |
| 1055 | { |
David Lamparter | e0ca5fd | 2009-09-16 01:52:42 +0200 | [diff] [blame] | 1056 | vty_out (vty, SHOW_ROUTE_V4_HEADER); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1057 | first = 0; |
| 1058 | } |
| 1059 | vty_show_ip_route (vty, rn, rib); |
| 1060 | } |
| 1061 | return CMD_SUCCESS; |
| 1062 | } |
| 1063 | |
| 1064 | DEFUN (show_ip_route_addr, |
| 1065 | show_ip_route_addr_cmd, |
| 1066 | "show ip route A.B.C.D", |
| 1067 | SHOW_STR |
| 1068 | IP_STR |
| 1069 | "IP routing table\n" |
| 1070 | "Network in the IP routing table to display\n") |
| 1071 | { |
| 1072 | int ret; |
| 1073 | struct prefix_ipv4 p; |
| 1074 | struct route_table *table; |
| 1075 | struct route_node *rn; |
| 1076 | |
| 1077 | ret = str2prefix_ipv4 (argv[0], &p); |
| 1078 | if (ret <= 0) |
| 1079 | { |
| 1080 | vty_out (vty, "%% Malformed IPv4 address%s", VTY_NEWLINE); |
| 1081 | return CMD_WARNING; |
| 1082 | } |
| 1083 | |
| 1084 | table = vrf_table (AFI_IP, SAFI_UNICAST, 0); |
| 1085 | if (! table) |
| 1086 | return CMD_SUCCESS; |
| 1087 | |
| 1088 | rn = route_node_match (table, (struct prefix *) &p); |
| 1089 | if (! rn) |
| 1090 | { |
| 1091 | vty_out (vty, "%% Network not in table%s", VTY_NEWLINE); |
| 1092 | return CMD_WARNING; |
| 1093 | } |
| 1094 | |
| 1095 | vty_show_ip_route_detail (vty, rn); |
| 1096 | |
| 1097 | route_unlock_node (rn); |
| 1098 | |
| 1099 | return CMD_SUCCESS; |
| 1100 | } |
| 1101 | |
| 1102 | DEFUN (show_ip_route_prefix, |
| 1103 | show_ip_route_prefix_cmd, |
| 1104 | "show ip route A.B.C.D/M", |
| 1105 | SHOW_STR |
| 1106 | IP_STR |
| 1107 | "IP routing table\n" |
| 1108 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n") |
| 1109 | { |
| 1110 | int ret; |
| 1111 | struct prefix_ipv4 p; |
| 1112 | struct route_table *table; |
| 1113 | struct route_node *rn; |
| 1114 | |
| 1115 | ret = str2prefix_ipv4 (argv[0], &p); |
| 1116 | if (ret <= 0) |
| 1117 | { |
| 1118 | vty_out (vty, "%% Malformed IPv4 address%s", VTY_NEWLINE); |
| 1119 | return CMD_WARNING; |
| 1120 | } |
| 1121 | |
| 1122 | table = vrf_table (AFI_IP, SAFI_UNICAST, 0); |
| 1123 | if (! table) |
| 1124 | return CMD_SUCCESS; |
| 1125 | |
| 1126 | rn = route_node_match (table, (struct prefix *) &p); |
| 1127 | if (! rn || rn->p.prefixlen != p.prefixlen) |
| 1128 | { |
| 1129 | vty_out (vty, "%% Network not in table%s", VTY_NEWLINE); |
Lu Feng | 969d355 | 2014-10-21 06:24:07 +0000 | [diff] [blame] | 1130 | if (rn) |
| 1131 | route_unlock_node (rn); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1132 | return CMD_WARNING; |
| 1133 | } |
| 1134 | |
| 1135 | vty_show_ip_route_detail (vty, rn); |
| 1136 | |
| 1137 | route_unlock_node (rn); |
| 1138 | |
| 1139 | return CMD_SUCCESS; |
| 1140 | } |
| 1141 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 1142 | static void |
Stig Thormodsrud | 61691c9 | 2008-11-04 15:45:07 -0800 | [diff] [blame] | 1143 | vty_show_ip_route_summary (struct vty *vty, struct route_table *table) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1144 | { |
Stig Thormodsrud | 61691c9 | 2008-11-04 15:45:07 -0800 | [diff] [blame] | 1145 | struct route_node *rn; |
| 1146 | struct rib *rib; |
| 1147 | struct nexthop *nexthop; |
| 1148 | #define ZEBRA_ROUTE_IBGP ZEBRA_ROUTE_MAX |
| 1149 | #define ZEBRA_ROUTE_TOTAL (ZEBRA_ROUTE_IBGP + 1) |
| 1150 | u_int32_t rib_cnt[ZEBRA_ROUTE_TOTAL + 1]; |
| 1151 | u_int32_t fib_cnt[ZEBRA_ROUTE_TOTAL + 1]; |
| 1152 | u_int32_t i; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1153 | |
Stig Thormodsrud | 61691c9 | 2008-11-04 15:45:07 -0800 | [diff] [blame] | 1154 | memset (&rib_cnt, 0, sizeof(rib_cnt)); |
| 1155 | memset (&fib_cnt, 0, sizeof(fib_cnt)); |
| 1156 | for (rn = route_top (table); rn; rn = route_next (rn)) |
Avneesh Sachdev | 9fd92e3 | 2012-11-13 22:48:53 +0000 | [diff] [blame] | 1157 | RNODE_FOREACH_RIB (rn, rib) |
Stig Thormodsrud | 61691c9 | 2008-11-04 15:45:07 -0800 | [diff] [blame] | 1158 | for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next) |
| 1159 | { |
| 1160 | rib_cnt[ZEBRA_ROUTE_TOTAL]++; |
| 1161 | rib_cnt[rib->type]++; |
Christian Franke | fa713d9 | 2013-07-05 15:35:37 +0000 | [diff] [blame] | 1162 | if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB) |
| 1163 | || nexthop_has_fib_child(nexthop)) |
Stig Thormodsrud | 61691c9 | 2008-11-04 15:45:07 -0800 | [diff] [blame] | 1164 | { |
| 1165 | fib_cnt[ZEBRA_ROUTE_TOTAL]++; |
| 1166 | fib_cnt[rib->type]++; |
| 1167 | } |
| 1168 | if (rib->type == ZEBRA_ROUTE_BGP && |
| 1169 | CHECK_FLAG (rib->flags, ZEBRA_FLAG_IBGP)) |
| 1170 | { |
| 1171 | rib_cnt[ZEBRA_ROUTE_IBGP]++; |
Christian Franke | fa713d9 | 2013-07-05 15:35:37 +0000 | [diff] [blame] | 1172 | if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB) |
| 1173 | || nexthop_has_fib_child(nexthop)) |
Stig Thormodsrud | 61691c9 | 2008-11-04 15:45:07 -0800 | [diff] [blame] | 1174 | fib_cnt[ZEBRA_ROUTE_IBGP]++; |
| 1175 | } |
| 1176 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1177 | |
Stig Thormodsrud | 61691c9 | 2008-11-04 15:45:07 -0800 | [diff] [blame] | 1178 | vty_out (vty, "%-20s %-20s %-20s %s", |
| 1179 | "Route Source", "Routes", "FIB", VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1180 | |
Stig Thormodsrud | 61691c9 | 2008-11-04 15:45:07 -0800 | [diff] [blame] | 1181 | for (i = 0; i < ZEBRA_ROUTE_MAX; i++) |
| 1182 | { |
| 1183 | if (rib_cnt[i] > 0) |
| 1184 | { |
| 1185 | if (i == ZEBRA_ROUTE_BGP) |
| 1186 | { |
| 1187 | vty_out (vty, "%-20s %-20d %-20d %s", "ebgp", |
| 1188 | rib_cnt[ZEBRA_ROUTE_BGP] - rib_cnt[ZEBRA_ROUTE_IBGP], |
| 1189 | fib_cnt[ZEBRA_ROUTE_BGP] - fib_cnt[ZEBRA_ROUTE_IBGP], |
| 1190 | VTY_NEWLINE); |
| 1191 | vty_out (vty, "%-20s %-20d %-20d %s", "ibgp", |
| 1192 | rib_cnt[ZEBRA_ROUTE_IBGP], fib_cnt[ZEBRA_ROUTE_IBGP], |
| 1193 | VTY_NEWLINE); |
| 1194 | } |
| 1195 | else |
| 1196 | vty_out (vty, "%-20s %-20d %-20d %s", zebra_route_string(i), |
| 1197 | rib_cnt[i], fib_cnt[i], VTY_NEWLINE); |
| 1198 | } |
| 1199 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1200 | |
Stig Thormodsrud | 61691c9 | 2008-11-04 15:45:07 -0800 | [diff] [blame] | 1201 | vty_out (vty, "------%s", VTY_NEWLINE); |
| 1202 | vty_out (vty, "%-20s %-20d %-20d %s", "Totals", rib_cnt[ZEBRA_ROUTE_TOTAL], |
| 1203 | fib_cnt[ZEBRA_ROUTE_TOTAL], VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1204 | } |
| 1205 | |
Dinesh G Dutt | 56a5f77 | 2014-09-30 12:58:04 -0700 | [diff] [blame] | 1206 | /* |
| 1207 | * Implementation of the ip route summary prefix command. |
| 1208 | * |
| 1209 | * This command prints the primary prefixes that have been installed by various |
| 1210 | * protocols on the box. |
| 1211 | * |
| 1212 | */ |
| 1213 | static void |
| 1214 | vty_show_ip_route_summary_prefix (struct vty *vty, struct route_table *table) |
| 1215 | { |
| 1216 | struct route_node *rn; |
| 1217 | struct rib *rib; |
| 1218 | struct nexthop *nexthop; |
| 1219 | #define ZEBRA_ROUTE_IBGP ZEBRA_ROUTE_MAX |
| 1220 | #define ZEBRA_ROUTE_TOTAL (ZEBRA_ROUTE_IBGP + 1) |
| 1221 | u_int32_t rib_cnt[ZEBRA_ROUTE_TOTAL + 1]; |
| 1222 | u_int32_t fib_cnt[ZEBRA_ROUTE_TOTAL + 1]; |
| 1223 | u_int32_t i; |
| 1224 | int cnt; |
| 1225 | |
| 1226 | memset (&rib_cnt, 0, sizeof(rib_cnt)); |
| 1227 | memset (&fib_cnt, 0, sizeof(fib_cnt)); |
| 1228 | for (rn = route_top (table); rn; rn = route_next (rn)) |
| 1229 | RNODE_FOREACH_RIB (rn, rib) |
| 1230 | { |
| 1231 | |
| 1232 | /* |
| 1233 | * In case of ECMP, count only once. |
| 1234 | */ |
| 1235 | cnt = 0; |
| 1236 | for (nexthop = rib->nexthop; (!cnt && nexthop); nexthop = nexthop->next) |
| 1237 | { |
| 1238 | cnt++; |
| 1239 | rib_cnt[ZEBRA_ROUTE_TOTAL]++; |
| 1240 | rib_cnt[rib->type]++; |
| 1241 | if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)) |
| 1242 | { |
| 1243 | fib_cnt[ZEBRA_ROUTE_TOTAL]++; |
| 1244 | fib_cnt[rib->type]++; |
| 1245 | } |
| 1246 | if (rib->type == ZEBRA_ROUTE_BGP && |
| 1247 | CHECK_FLAG (rib->flags, ZEBRA_FLAG_IBGP)) |
| 1248 | { |
| 1249 | rib_cnt[ZEBRA_ROUTE_IBGP]++; |
| 1250 | if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)) |
| 1251 | fib_cnt[ZEBRA_ROUTE_IBGP]++; |
| 1252 | } |
| 1253 | } |
| 1254 | } |
| 1255 | |
| 1256 | vty_out (vty, "%-20s %-20s %-20s %s", |
| 1257 | "Route Source", "Prefix Routes", "FIB", VTY_NEWLINE); |
| 1258 | |
| 1259 | for (i = 0; i < ZEBRA_ROUTE_MAX; i++) |
| 1260 | { |
| 1261 | if (rib_cnt[i] > 0) |
| 1262 | { |
| 1263 | if (i == ZEBRA_ROUTE_BGP) |
| 1264 | { |
| 1265 | vty_out (vty, "%-20s %-20d %-20d %s", "ebgp", |
| 1266 | rib_cnt[ZEBRA_ROUTE_BGP] - rib_cnt[ZEBRA_ROUTE_IBGP], |
| 1267 | fib_cnt[ZEBRA_ROUTE_BGP] - fib_cnt[ZEBRA_ROUTE_IBGP], |
| 1268 | VTY_NEWLINE); |
| 1269 | vty_out (vty, "%-20s %-20d %-20d %s", "ibgp", |
| 1270 | rib_cnt[ZEBRA_ROUTE_IBGP], fib_cnt[ZEBRA_ROUTE_IBGP], |
| 1271 | VTY_NEWLINE); |
| 1272 | } |
| 1273 | else |
| 1274 | vty_out (vty, "%-20s %-20d %-20d %s", zebra_route_string(i), |
| 1275 | rib_cnt[i], fib_cnt[i], VTY_NEWLINE); |
| 1276 | } |
| 1277 | } |
| 1278 | |
| 1279 | vty_out (vty, "------%s", VTY_NEWLINE); |
| 1280 | vty_out (vty, "%-20s %-20d %-20d %s", "Totals", rib_cnt[ZEBRA_ROUTE_TOTAL], |
| 1281 | fib_cnt[ZEBRA_ROUTE_TOTAL], VTY_NEWLINE); |
| 1282 | } |
| 1283 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1284 | /* Show route summary. */ |
| 1285 | DEFUN (show_ip_route_summary, |
| 1286 | show_ip_route_summary_cmd, |
| 1287 | "show ip route summary", |
| 1288 | SHOW_STR |
| 1289 | IP_STR |
| 1290 | "IP routing table\n" |
| 1291 | "Summary of all routes\n") |
| 1292 | { |
Stig Thormodsrud | 61691c9 | 2008-11-04 15:45:07 -0800 | [diff] [blame] | 1293 | struct route_table *table; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1294 | |
Stig Thormodsrud | 61691c9 | 2008-11-04 15:45:07 -0800 | [diff] [blame] | 1295 | table = vrf_table (AFI_IP, SAFI_UNICAST, 0); |
| 1296 | if (! table) |
| 1297 | return CMD_SUCCESS; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1298 | |
Stig Thormodsrud | 61691c9 | 2008-11-04 15:45:07 -0800 | [diff] [blame] | 1299 | vty_show_ip_route_summary (vty, table); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1300 | |
| 1301 | return CMD_SUCCESS; |
| 1302 | } |
| 1303 | |
Dinesh G Dutt | 56a5f77 | 2014-09-30 12:58:04 -0700 | [diff] [blame] | 1304 | /* Show route summary prefix. */ |
| 1305 | DEFUN (show_ip_route_summary_prefix, |
| 1306 | show_ip_route_summary_prefix_cmd, |
| 1307 | "show ip route summary prefix", |
| 1308 | SHOW_STR |
| 1309 | IP_STR |
| 1310 | "IP routing table\n" |
| 1311 | "Summary of all routes\n" |
| 1312 | "Prefix routes\n") |
| 1313 | { |
| 1314 | struct route_table *table; |
| 1315 | |
| 1316 | table = vrf_table (AFI_IP, SAFI_UNICAST, 0); |
| 1317 | if (! table) |
| 1318 | return CMD_SUCCESS; |
| 1319 | |
| 1320 | vty_show_ip_route_summary_prefix (vty, table); |
| 1321 | |
| 1322 | return CMD_SUCCESS; |
| 1323 | } |
| 1324 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1325 | /* Write IPv4 static route configuration. */ |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 1326 | static int |
Everton Marques | 33d86db | 2014-07-14 11:19:00 -0300 | [diff] [blame] | 1327 | static_config_ipv4 (struct vty *vty, safi_t safi, const char *cmd) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1328 | { |
| 1329 | struct route_node *rn; |
| 1330 | struct static_ipv4 *si; |
| 1331 | struct route_table *stable; |
| 1332 | int write; |
| 1333 | |
| 1334 | write = 0; |
| 1335 | |
| 1336 | /* Lookup table. */ |
Everton Marques | 33d86db | 2014-07-14 11:19:00 -0300 | [diff] [blame] | 1337 | stable = vrf_static_table (AFI_IP, safi, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1338 | if (! stable) |
| 1339 | return -1; |
| 1340 | |
| 1341 | for (rn = route_top (stable); rn; rn = route_next (rn)) |
| 1342 | for (si = rn->info; si; si = si->next) |
| 1343 | { |
Everton Marques | 33d86db | 2014-07-14 11:19:00 -0300 | [diff] [blame] | 1344 | vty_out (vty, "%s %s/%d", cmd, inet_ntoa (rn->p.u.prefix4), |
paul | 7021c42 | 2003-07-15 12:52:22 +0000 | [diff] [blame] | 1345 | rn->p.prefixlen); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1346 | |
paul | 7021c42 | 2003-07-15 12:52:22 +0000 | [diff] [blame] | 1347 | switch (si->type) |
| 1348 | { |
| 1349 | case STATIC_IPV4_GATEWAY: |
| 1350 | vty_out (vty, " %s", inet_ntoa (si->gate.ipv4)); |
| 1351 | break; |
| 1352 | case STATIC_IPV4_IFNAME: |
| 1353 | vty_out (vty, " %s", si->gate.ifname); |
| 1354 | break; |
| 1355 | case STATIC_IPV4_BLACKHOLE: |
| 1356 | vty_out (vty, " Null0"); |
| 1357 | break; |
| 1358 | } |
| 1359 | |
| 1360 | /* flags are incompatible with STATIC_IPV4_BLACKHOLE */ |
| 1361 | if (si->type != STATIC_IPV4_BLACKHOLE) |
| 1362 | { |
| 1363 | if (CHECK_FLAG(si->flags, ZEBRA_FLAG_REJECT)) |
| 1364 | vty_out (vty, " %s", "reject"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1365 | |
paul | 7021c42 | 2003-07-15 12:52:22 +0000 | [diff] [blame] | 1366 | if (CHECK_FLAG(si->flags, ZEBRA_FLAG_BLACKHOLE)) |
| 1367 | vty_out (vty, " %s", "blackhole"); |
| 1368 | } |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 1369 | |
paul | 7021c42 | 2003-07-15 12:52:22 +0000 | [diff] [blame] | 1370 | if (si->distance != ZEBRA_STATIC_DISTANCE_DEFAULT) |
| 1371 | vty_out (vty, " %d", si->distance); |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 1372 | |
paul | 7021c42 | 2003-07-15 12:52:22 +0000 | [diff] [blame] | 1373 | vty_out (vty, "%s", VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1374 | |
paul | 7021c42 | 2003-07-15 12:52:22 +0000 | [diff] [blame] | 1375 | write = 1; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1376 | } |
| 1377 | return write; |
| 1378 | } |
Andrew J. Schorr | 0930331 | 2007-05-30 20:10:34 +0000 | [diff] [blame] | 1379 | |
| 1380 | DEFUN (show_ip_protocol, |
| 1381 | show_ip_protocol_cmd, |
| 1382 | "show ip protocol", |
| 1383 | SHOW_STR |
| 1384 | IP_STR |
| 1385 | "IP protocol filtering status\n") |
| 1386 | { |
| 1387 | int i; |
| 1388 | |
| 1389 | vty_out(vty, "Protocol : route-map %s", VTY_NEWLINE); |
| 1390 | vty_out(vty, "------------------------%s", VTY_NEWLINE); |
| 1391 | for (i=0;i<ZEBRA_ROUTE_MAX;i++) |
| 1392 | { |
| 1393 | if (proto_rm[AFI_IP][i]) |
| 1394 | vty_out (vty, "%-10s : %-10s%s", zebra_route_string(i), |
| 1395 | proto_rm[AFI_IP][i], |
| 1396 | VTY_NEWLINE); |
| 1397 | else |
| 1398 | vty_out (vty, "%-10s : none%s", zebra_route_string(i), VTY_NEWLINE); |
| 1399 | } |
| 1400 | if (proto_rm[AFI_IP][i]) |
| 1401 | vty_out (vty, "%-10s : %-10s%s", "any", proto_rm[AFI_IP][i], |
| 1402 | VTY_NEWLINE); |
| 1403 | else |
| 1404 | vty_out (vty, "%-10s : none%s", "any", VTY_NEWLINE); |
| 1405 | |
| 1406 | return CMD_SUCCESS; |
| 1407 | } |
| 1408 | |
Joachim Nilsson | 36735ed | 2012-05-09 13:38:36 +0200 | [diff] [blame] | 1409 | /* |
| 1410 | * Show IP mroute command to dump the BGP Multicast |
| 1411 | * routing table |
| 1412 | */ |
| 1413 | DEFUN (show_ip_mroute, |
| 1414 | show_ip_mroute_cmd, |
| 1415 | "show ip mroute", |
| 1416 | SHOW_STR |
| 1417 | IP_STR |
| 1418 | "IP Multicast routing table\n") |
| 1419 | { |
| 1420 | struct route_table *table; |
| 1421 | struct route_node *rn; |
| 1422 | struct rib *rib; |
| 1423 | int first = 1; |
| 1424 | |
| 1425 | table = vrf_table (AFI_IP, SAFI_MULTICAST, 0); |
| 1426 | if (! table) |
| 1427 | return CMD_SUCCESS; |
| 1428 | |
| 1429 | /* Show all IPv4 routes. */ |
| 1430 | for (rn = route_top (table); rn; rn = route_next (rn)) |
Avneesh Sachdev | 9fd92e3 | 2012-11-13 22:48:53 +0000 | [diff] [blame] | 1431 | RNODE_FOREACH_RIB (rn, rib) |
Joachim Nilsson | 36735ed | 2012-05-09 13:38:36 +0200 | [diff] [blame] | 1432 | { |
| 1433 | if (first) |
| 1434 | { |
| 1435 | vty_out (vty, SHOW_ROUTE_V4_HEADER); |
| 1436 | first = 0; |
| 1437 | } |
| 1438 | vty_show_ip_route (vty, rn, rib); |
| 1439 | } |
| 1440 | return CMD_SUCCESS; |
| 1441 | } |
| 1442 | |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 1443 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1444 | #ifdef HAVE_IPV6 |
| 1445 | /* General fucntion for IPv6 static route. */ |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 1446 | static int |
hasso | 39db97e | 2004-10-12 20:50:58 +0000 | [diff] [blame] | 1447 | static_ipv6_func (struct vty *vty, int add_cmd, const char *dest_str, |
| 1448 | const char *gate_str, const char *ifname, |
| 1449 | const char *flag_str, const char *distance_str) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1450 | { |
| 1451 | int ret; |
| 1452 | u_char distance; |
| 1453 | struct prefix p; |
| 1454 | struct in6_addr *gate = NULL; |
| 1455 | struct in6_addr gate_addr; |
| 1456 | u_char type = 0; |
| 1457 | int table = 0; |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 1458 | u_char flag = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1459 | |
| 1460 | ret = str2prefix (dest_str, &p); |
| 1461 | if (ret <= 0) |
| 1462 | { |
| 1463 | vty_out (vty, "%% Malformed address%s", VTY_NEWLINE); |
| 1464 | return CMD_WARNING; |
| 1465 | } |
| 1466 | |
| 1467 | /* Apply mask for given prefix. */ |
| 1468 | apply_mask (&p); |
| 1469 | |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 1470 | /* Route flags */ |
| 1471 | if (flag_str) { |
| 1472 | switch(flag_str[0]) { |
| 1473 | case 'r': |
| 1474 | case 'R': /* XXX */ |
| 1475 | SET_FLAG (flag, ZEBRA_FLAG_REJECT); |
| 1476 | break; |
| 1477 | case 'b': |
| 1478 | case 'B': /* XXX */ |
| 1479 | SET_FLAG (flag, ZEBRA_FLAG_BLACKHOLE); |
| 1480 | break; |
| 1481 | default: |
| 1482 | vty_out (vty, "%% Malformed flag %s %s", flag_str, VTY_NEWLINE); |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 1483 | return CMD_WARNING; |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 1484 | } |
| 1485 | } |
| 1486 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1487 | /* Administrative distance. */ |
| 1488 | if (distance_str) |
| 1489 | distance = atoi (distance_str); |
| 1490 | else |
| 1491 | distance = ZEBRA_STATIC_DISTANCE_DEFAULT; |
| 1492 | |
| 1493 | /* When gateway is valid IPv6 addrees, then gate is treated as |
| 1494 | nexthop address other case gate is treated as interface name. */ |
| 1495 | ret = inet_pton (AF_INET6, gate_str, &gate_addr); |
| 1496 | |
| 1497 | if (ifname) |
| 1498 | { |
| 1499 | /* When ifname is specified. It must be come with gateway |
| 1500 | address. */ |
| 1501 | if (ret != 1) |
| 1502 | { |
| 1503 | vty_out (vty, "%% Malformed address%s", VTY_NEWLINE); |
| 1504 | return CMD_WARNING; |
| 1505 | } |
| 1506 | type = STATIC_IPV6_GATEWAY_IFNAME; |
| 1507 | gate = &gate_addr; |
| 1508 | } |
| 1509 | else |
| 1510 | { |
| 1511 | if (ret == 1) |
| 1512 | { |
| 1513 | type = STATIC_IPV6_GATEWAY; |
| 1514 | gate = &gate_addr; |
| 1515 | } |
| 1516 | else |
| 1517 | { |
| 1518 | type = STATIC_IPV6_IFNAME; |
| 1519 | ifname = gate_str; |
| 1520 | } |
| 1521 | } |
| 1522 | |
| 1523 | if (add_cmd) |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 1524 | static_add_ipv6 (&p, type, gate, ifname, flag, distance, table); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1525 | else |
| 1526 | static_delete_ipv6 (&p, type, gate, ifname, distance, table); |
| 1527 | |
| 1528 | return CMD_SUCCESS; |
| 1529 | } |
| 1530 | |
| 1531 | DEFUN (ipv6_route, |
| 1532 | ipv6_route_cmd, |
| 1533 | "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE)", |
| 1534 | IP_STR |
| 1535 | "Establish static routes\n" |
| 1536 | "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" |
| 1537 | "IPv6 gateway address\n" |
| 1538 | "IPv6 gateway interface name\n") |
| 1539 | { |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 1540 | return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, NULL, NULL); |
| 1541 | } |
| 1542 | |
| 1543 | DEFUN (ipv6_route_flags, |
| 1544 | ipv6_route_flags_cmd, |
| 1545 | "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole)", |
| 1546 | IP_STR |
| 1547 | "Establish static routes\n" |
| 1548 | "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" |
| 1549 | "IPv6 gateway address\n" |
| 1550 | "IPv6 gateway interface name\n" |
| 1551 | "Emit an ICMP unreachable when matched\n" |
| 1552 | "Silently discard pkts when matched\n") |
| 1553 | { |
| 1554 | 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] | 1555 | } |
| 1556 | |
| 1557 | DEFUN (ipv6_route_ifname, |
| 1558 | ipv6_route_ifname_cmd, |
| 1559 | "ipv6 route X:X::X:X/M X:X::X:X INTERFACE", |
| 1560 | IP_STR |
| 1561 | "Establish static routes\n" |
| 1562 | "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" |
| 1563 | "IPv6 gateway address\n" |
| 1564 | "IPv6 gateway interface name\n") |
| 1565 | { |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 1566 | return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], NULL, NULL); |
| 1567 | } |
| 1568 | |
| 1569 | DEFUN (ipv6_route_ifname_flags, |
| 1570 | ipv6_route_ifname_flags_cmd, |
| 1571 | "ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole)", |
| 1572 | IP_STR |
| 1573 | "Establish static routes\n" |
| 1574 | "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" |
| 1575 | "IPv6 gateway address\n" |
| 1576 | "IPv6 gateway interface name\n" |
| 1577 | "Emit an ICMP unreachable when matched\n" |
| 1578 | "Silently discard pkts when matched\n") |
| 1579 | { |
| 1580 | 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] | 1581 | } |
| 1582 | |
| 1583 | DEFUN (ipv6_route_pref, |
| 1584 | ipv6_route_pref_cmd, |
| 1585 | "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <1-255>", |
| 1586 | IP_STR |
| 1587 | "Establish static routes\n" |
| 1588 | "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" |
| 1589 | "IPv6 gateway address\n" |
| 1590 | "IPv6 gateway interface name\n" |
| 1591 | "Distance value for this prefix\n") |
| 1592 | { |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 1593 | return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, NULL, argv[2]); |
| 1594 | } |
| 1595 | |
| 1596 | DEFUN (ipv6_route_flags_pref, |
| 1597 | ipv6_route_flags_pref_cmd, |
| 1598 | "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) <1-255>", |
| 1599 | IP_STR |
| 1600 | "Establish static routes\n" |
| 1601 | "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" |
| 1602 | "IPv6 gateway address\n" |
| 1603 | "IPv6 gateway interface name\n" |
| 1604 | "Emit an ICMP unreachable when matched\n" |
| 1605 | "Silently discard pkts when matched\n" |
| 1606 | "Distance value for this prefix\n") |
| 1607 | { |
| 1608 | 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] | 1609 | } |
| 1610 | |
| 1611 | DEFUN (ipv6_route_ifname_pref, |
| 1612 | ipv6_route_ifname_pref_cmd, |
| 1613 | "ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255>", |
| 1614 | IP_STR |
| 1615 | "Establish static routes\n" |
| 1616 | "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" |
| 1617 | "IPv6 gateway address\n" |
| 1618 | "IPv6 gateway interface name\n" |
| 1619 | "Distance value for this prefix\n") |
| 1620 | { |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 1621 | return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], NULL, argv[3]); |
| 1622 | } |
| 1623 | |
| 1624 | DEFUN (ipv6_route_ifname_flags_pref, |
| 1625 | ipv6_route_ifname_flags_pref_cmd, |
| 1626 | "ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) <1-255>", |
| 1627 | IP_STR |
| 1628 | "Establish static routes\n" |
| 1629 | "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" |
| 1630 | "IPv6 gateway address\n" |
| 1631 | "IPv6 gateway interface name\n" |
| 1632 | "Emit an ICMP unreachable when matched\n" |
| 1633 | "Silently discard pkts when matched\n" |
| 1634 | "Distance value for this prefix\n") |
| 1635 | { |
| 1636 | 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] | 1637 | } |
| 1638 | |
| 1639 | DEFUN (no_ipv6_route, |
| 1640 | no_ipv6_route_cmd, |
| 1641 | "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE)", |
| 1642 | NO_STR |
| 1643 | IP_STR |
| 1644 | "Establish static routes\n" |
| 1645 | "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" |
| 1646 | "IPv6 gateway address\n" |
| 1647 | "IPv6 gateway interface name\n") |
| 1648 | { |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 1649 | return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, NULL, NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1650 | } |
| 1651 | |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 1652 | ALIAS (no_ipv6_route, |
| 1653 | no_ipv6_route_flags_cmd, |
| 1654 | "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole)", |
| 1655 | NO_STR |
| 1656 | IP_STR |
| 1657 | "Establish static routes\n" |
| 1658 | "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" |
| 1659 | "IPv6 gateway address\n" |
| 1660 | "IPv6 gateway interface name\n" |
| 1661 | "Emit an ICMP unreachable when matched\n" |
| 1662 | "Silently discard pkts when matched\n") |
| 1663 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1664 | DEFUN (no_ipv6_route_ifname, |
| 1665 | no_ipv6_route_ifname_cmd, |
| 1666 | "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE", |
| 1667 | NO_STR |
| 1668 | IP_STR |
| 1669 | "Establish static routes\n" |
| 1670 | "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" |
| 1671 | "IPv6 gateway address\n" |
| 1672 | "IPv6 gateway interface name\n") |
| 1673 | { |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 1674 | 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] | 1675 | } |
| 1676 | |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 1677 | ALIAS (no_ipv6_route_ifname, |
| 1678 | no_ipv6_route_ifname_flags_cmd, |
| 1679 | "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole)", |
| 1680 | NO_STR |
| 1681 | IP_STR |
| 1682 | "Establish static routes\n" |
| 1683 | "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" |
| 1684 | "IPv6 gateway address\n" |
| 1685 | "IPv6 gateway interface name\n" |
| 1686 | "Emit an ICMP unreachable when matched\n" |
| 1687 | "Silently discard pkts when matched\n") |
| 1688 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1689 | DEFUN (no_ipv6_route_pref, |
| 1690 | no_ipv6_route_pref_cmd, |
| 1691 | "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <1-255>", |
| 1692 | NO_STR |
| 1693 | IP_STR |
| 1694 | "Establish static routes\n" |
| 1695 | "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" |
| 1696 | "IPv6 gateway address\n" |
| 1697 | "IPv6 gateway interface name\n" |
| 1698 | "Distance value for this prefix\n") |
| 1699 | { |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 1700 | return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, NULL, argv[2]); |
| 1701 | } |
| 1702 | |
| 1703 | DEFUN (no_ipv6_route_flags_pref, |
| 1704 | no_ipv6_route_flags_pref_cmd, |
| 1705 | "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) <1-255>", |
| 1706 | NO_STR |
| 1707 | IP_STR |
| 1708 | "Establish static routes\n" |
| 1709 | "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" |
| 1710 | "IPv6 gateway address\n" |
| 1711 | "IPv6 gateway interface name\n" |
| 1712 | "Emit an ICMP unreachable when matched\n" |
| 1713 | "Silently discard pkts when matched\n" |
| 1714 | "Distance value for this prefix\n") |
| 1715 | { |
| 1716 | /* We do not care about argv[2] */ |
| 1717 | 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] | 1718 | } |
| 1719 | |
| 1720 | DEFUN (no_ipv6_route_ifname_pref, |
| 1721 | no_ipv6_route_ifname_pref_cmd, |
| 1722 | "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255>", |
| 1723 | NO_STR |
| 1724 | IP_STR |
| 1725 | "Establish static routes\n" |
| 1726 | "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" |
| 1727 | "IPv6 gateway address\n" |
| 1728 | "IPv6 gateway interface name\n" |
| 1729 | "Distance value for this prefix\n") |
| 1730 | { |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 1731 | return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], NULL, argv[3]); |
| 1732 | } |
| 1733 | |
| 1734 | DEFUN (no_ipv6_route_ifname_flags_pref, |
| 1735 | no_ipv6_route_ifname_flags_pref_cmd, |
| 1736 | "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) <1-255>", |
| 1737 | NO_STR |
| 1738 | IP_STR |
| 1739 | "Establish static routes\n" |
| 1740 | "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" |
| 1741 | "IPv6 gateway address\n" |
| 1742 | "IPv6 gateway interface name\n" |
| 1743 | "Emit an ICMP unreachable when matched\n" |
| 1744 | "Silently discard pkts when matched\n" |
| 1745 | "Distance value for this prefix\n") |
| 1746 | { |
| 1747 | 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] | 1748 | } |
| 1749 | |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 1750 | /* New RIB. Detailed information for IPv6 route. */ |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 1751 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1752 | vty_show_ipv6_route_detail (struct vty *vty, struct route_node *rn) |
| 1753 | { |
| 1754 | struct rib *rib; |
Christian Franke | fa713d9 | 2013-07-05 15:35:37 +0000 | [diff] [blame] | 1755 | struct nexthop *nexthop, *tnexthop; |
| 1756 | int recursing; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1757 | char buf[BUFSIZ]; |
| 1758 | |
Avneesh Sachdev | 9fd92e3 | 2012-11-13 22:48:53 +0000 | [diff] [blame] | 1759 | RNODE_FOREACH_RIB (rn, rib) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1760 | { |
| 1761 | vty_out (vty, "Routing entry for %s/%d%s", |
| 1762 | inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, BUFSIZ), |
| 1763 | rn->p.prefixlen, |
| 1764 | VTY_NEWLINE); |
ajs | f52d13c | 2005-10-01 17:38:06 +0000 | [diff] [blame] | 1765 | vty_out (vty, " Known via \"%s\"", zebra_route_string (rib->type)); |
Jorge Boncompte [DTI2] | ddc943d | 2012-04-13 13:46:07 +0200 | [diff] [blame] | 1766 | vty_out (vty, ", distance %u, metric %u", rib->distance, rib->metric); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1767 | if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED)) |
| 1768 | vty_out (vty, ", best"); |
| 1769 | if (rib->refcnt) |
| 1770 | vty_out (vty, ", refcnt %ld", rib->refcnt); |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 1771 | if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE)) |
| 1772 | vty_out (vty, ", blackhole"); |
| 1773 | if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT)) |
| 1774 | vty_out (vty, ", reject"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1775 | vty_out (vty, "%s", VTY_NEWLINE); |
| 1776 | |
| 1777 | #define ONE_DAY_SECOND 60*60*24 |
| 1778 | #define ONE_WEEK_SECOND 60*60*24*7 |
| 1779 | if (rib->type == ZEBRA_ROUTE_RIPNG |
| 1780 | || rib->type == ZEBRA_ROUTE_OSPF6 |
Juliusz Chroboczek | 578ce37 | 2012-02-09 13:42:28 +0100 | [diff] [blame] | 1781 | || rib->type == ZEBRA_ROUTE_BABEL |
jardin | 9e867fe | 2003-12-23 08:56:18 +0000 | [diff] [blame] | 1782 | || rib->type == ZEBRA_ROUTE_ISIS |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1783 | || rib->type == ZEBRA_ROUTE_BGP) |
| 1784 | { |
| 1785 | time_t uptime; |
| 1786 | struct tm *tm; |
| 1787 | |
| 1788 | uptime = time (NULL); |
| 1789 | uptime -= rib->uptime; |
| 1790 | tm = gmtime (&uptime); |
| 1791 | |
| 1792 | vty_out (vty, " Last update "); |
| 1793 | |
| 1794 | if (uptime < ONE_DAY_SECOND) |
| 1795 | vty_out (vty, "%02d:%02d:%02d", |
| 1796 | tm->tm_hour, tm->tm_min, tm->tm_sec); |
| 1797 | else if (uptime < ONE_WEEK_SECOND) |
| 1798 | vty_out (vty, "%dd%02dh%02dm", |
| 1799 | tm->tm_yday, tm->tm_hour, tm->tm_min); |
| 1800 | else |
| 1801 | vty_out (vty, "%02dw%dd%02dh", |
| 1802 | tm->tm_yday/7, |
| 1803 | tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour); |
| 1804 | vty_out (vty, " ago%s", VTY_NEWLINE); |
| 1805 | } |
| 1806 | |
Christian Franke | fa713d9 | 2013-07-05 15:35:37 +0000 | [diff] [blame] | 1807 | for (ALL_NEXTHOPS_RO(rib->nexthop, nexthop, tnexthop, recursing)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1808 | { |
Christian Franke | fa713d9 | 2013-07-05 15:35:37 +0000 | [diff] [blame] | 1809 | vty_out (vty, " %c%s", |
| 1810 | CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB) ? '*' : ' ', |
| 1811 | recursing ? " " : ""); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1812 | |
| 1813 | switch (nexthop->type) |
| 1814 | { |
| 1815 | case NEXTHOP_TYPE_IPV6: |
| 1816 | case NEXTHOP_TYPE_IPV6_IFINDEX: |
| 1817 | case NEXTHOP_TYPE_IPV6_IFNAME: |
| 1818 | vty_out (vty, " %s", |
| 1819 | inet_ntop (AF_INET6, &nexthop->gate.ipv6, buf, BUFSIZ)); |
| 1820 | if (nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME) |
| 1821 | vty_out (vty, ", %s", nexthop->ifname); |
| 1822 | else if (nexthop->ifindex) |
| 1823 | vty_out (vty, ", via %s", ifindex2ifname (nexthop->ifindex)); |
| 1824 | break; |
| 1825 | case NEXTHOP_TYPE_IFINDEX: |
| 1826 | vty_out (vty, " directly connected, %s", |
| 1827 | ifindex2ifname (nexthop->ifindex)); |
| 1828 | break; |
| 1829 | case NEXTHOP_TYPE_IFNAME: |
| 1830 | vty_out (vty, " directly connected, %s", |
| 1831 | nexthop->ifname); |
| 1832 | break; |
| 1833 | default: |
| 1834 | break; |
| 1835 | } |
| 1836 | if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE)) |
| 1837 | vty_out (vty, " inactive"); |
| 1838 | |
Christian Franke | e8d3d29 | 2013-07-05 15:35:39 +0000 | [diff] [blame] | 1839 | if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ONLINK)) |
| 1840 | vty_out (vty, " onlink"); |
| 1841 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1842 | if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE)) |
Christian Franke | fa713d9 | 2013-07-05 15:35:37 +0000 | [diff] [blame] | 1843 | vty_out (vty, " (recursive)"); |
| 1844 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1845 | vty_out (vty, "%s", VTY_NEWLINE); |
| 1846 | } |
| 1847 | vty_out (vty, "%s", VTY_NEWLINE); |
| 1848 | } |
| 1849 | } |
| 1850 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 1851 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1852 | vty_show_ipv6_route (struct vty *vty, struct route_node *rn, |
| 1853 | struct rib *rib) |
| 1854 | { |
Christian Franke | fa713d9 | 2013-07-05 15:35:37 +0000 | [diff] [blame] | 1855 | struct nexthop *nexthop, *tnexthop; |
| 1856 | int recursing; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1857 | int len = 0; |
| 1858 | char buf[BUFSIZ]; |
| 1859 | |
| 1860 | /* Nexthop information. */ |
Christian Franke | fa713d9 | 2013-07-05 15:35:37 +0000 | [diff] [blame] | 1861 | for (ALL_NEXTHOPS_RO(rib->nexthop, nexthop, tnexthop, recursing)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1862 | { |
| 1863 | if (nexthop == rib->nexthop) |
| 1864 | { |
| 1865 | /* Prefix information. */ |
| 1866 | len = vty_out (vty, "%c%c%c %s/%d", |
ajs | f52d13c | 2005-10-01 17:38:06 +0000 | [diff] [blame] | 1867 | zebra_route_char (rib->type), |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1868 | CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED) |
| 1869 | ? '>' : ' ', |
| 1870 | CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB) |
| 1871 | ? '*' : ' ', |
| 1872 | inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, BUFSIZ), |
| 1873 | rn->p.prefixlen); |
| 1874 | |
| 1875 | /* Distance and metric display. */ |
| 1876 | if (rib->type != ZEBRA_ROUTE_CONNECT |
| 1877 | && rib->type != ZEBRA_ROUTE_KERNEL) |
| 1878 | len += vty_out (vty, " [%d/%d]", rib->distance, |
| 1879 | rib->metric); |
| 1880 | } |
| 1881 | else |
| 1882 | vty_out (vty, " %c%*c", |
| 1883 | CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB) |
| 1884 | ? '*' : ' ', |
Christian Franke | fa713d9 | 2013-07-05 15:35:37 +0000 | [diff] [blame] | 1885 | len - 3 + (2 * recursing), ' '); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1886 | |
| 1887 | switch (nexthop->type) |
| 1888 | { |
| 1889 | case NEXTHOP_TYPE_IPV6: |
| 1890 | case NEXTHOP_TYPE_IPV6_IFINDEX: |
| 1891 | case NEXTHOP_TYPE_IPV6_IFNAME: |
| 1892 | vty_out (vty, " via %s", |
| 1893 | inet_ntop (AF_INET6, &nexthop->gate.ipv6, buf, BUFSIZ)); |
| 1894 | if (nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME) |
| 1895 | vty_out (vty, ", %s", nexthop->ifname); |
| 1896 | else if (nexthop->ifindex) |
| 1897 | vty_out (vty, ", %s", ifindex2ifname (nexthop->ifindex)); |
| 1898 | break; |
| 1899 | case NEXTHOP_TYPE_IFINDEX: |
| 1900 | vty_out (vty, " is directly connected, %s", |
| 1901 | ifindex2ifname (nexthop->ifindex)); |
| 1902 | break; |
| 1903 | case NEXTHOP_TYPE_IFNAME: |
| 1904 | vty_out (vty, " is directly connected, %s", |
| 1905 | nexthop->ifname); |
| 1906 | break; |
| 1907 | default: |
| 1908 | break; |
| 1909 | } |
| 1910 | if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE)) |
| 1911 | vty_out (vty, " inactive"); |
| 1912 | |
| 1913 | if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE)) |
Christian Franke | fa713d9 | 2013-07-05 15:35:37 +0000 | [diff] [blame] | 1914 | vty_out (vty, " (recursive)"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1915 | |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 1916 | if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE)) |
| 1917 | vty_out (vty, ", bh"); |
| 1918 | if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT)) |
| 1919 | vty_out (vty, ", rej"); |
| 1920 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1921 | if (rib->type == ZEBRA_ROUTE_RIPNG |
| 1922 | || rib->type == ZEBRA_ROUTE_OSPF6 |
Juliusz Chroboczek | 578ce37 | 2012-02-09 13:42:28 +0100 | [diff] [blame] | 1923 | || rib->type == ZEBRA_ROUTE_BABEL |
jardin | 9e867fe | 2003-12-23 08:56:18 +0000 | [diff] [blame] | 1924 | || rib->type == ZEBRA_ROUTE_ISIS |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1925 | || rib->type == ZEBRA_ROUTE_BGP) |
| 1926 | { |
| 1927 | time_t uptime; |
| 1928 | struct tm *tm; |
| 1929 | |
| 1930 | uptime = time (NULL); |
| 1931 | uptime -= rib->uptime; |
| 1932 | tm = gmtime (&uptime); |
| 1933 | |
| 1934 | #define ONE_DAY_SECOND 60*60*24 |
| 1935 | #define ONE_WEEK_SECOND 60*60*24*7 |
| 1936 | |
| 1937 | if (uptime < ONE_DAY_SECOND) |
| 1938 | vty_out (vty, ", %02d:%02d:%02d", |
| 1939 | tm->tm_hour, tm->tm_min, tm->tm_sec); |
| 1940 | else if (uptime < ONE_WEEK_SECOND) |
| 1941 | vty_out (vty, ", %dd%02dh%02dm", |
| 1942 | tm->tm_yday, tm->tm_hour, tm->tm_min); |
| 1943 | else |
| 1944 | vty_out (vty, ", %02dw%dd%02dh", |
| 1945 | tm->tm_yday/7, |
| 1946 | tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour); |
| 1947 | } |
| 1948 | vty_out (vty, "%s", VTY_NEWLINE); |
| 1949 | } |
| 1950 | } |
| 1951 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1952 | DEFUN (show_ipv6_route, |
| 1953 | show_ipv6_route_cmd, |
| 1954 | "show ipv6 route", |
| 1955 | SHOW_STR |
| 1956 | IP_STR |
| 1957 | "IPv6 routing table\n") |
| 1958 | { |
| 1959 | struct route_table *table; |
| 1960 | struct route_node *rn; |
| 1961 | struct rib *rib; |
| 1962 | int first = 1; |
| 1963 | |
| 1964 | table = vrf_table (AFI_IP6, SAFI_UNICAST, 0); |
| 1965 | if (! table) |
| 1966 | return CMD_SUCCESS; |
| 1967 | |
| 1968 | /* Show all IPv6 route. */ |
| 1969 | for (rn = route_top (table); rn; rn = route_next (rn)) |
Avneesh Sachdev | 9fd92e3 | 2012-11-13 22:48:53 +0000 | [diff] [blame] | 1970 | RNODE_FOREACH_RIB (rn, rib) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1971 | { |
| 1972 | if (first) |
| 1973 | { |
David Lamparter | e0ca5fd | 2009-09-16 01:52:42 +0200 | [diff] [blame] | 1974 | vty_out (vty, SHOW_ROUTE_V6_HEADER); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1975 | first = 0; |
| 1976 | } |
| 1977 | vty_show_ipv6_route (vty, rn, rib); |
| 1978 | } |
| 1979 | return CMD_SUCCESS; |
| 1980 | } |
| 1981 | |
| 1982 | DEFUN (show_ipv6_route_prefix_longer, |
| 1983 | show_ipv6_route_prefix_longer_cmd, |
| 1984 | "show ipv6 route X:X::X:X/M longer-prefixes", |
| 1985 | SHOW_STR |
| 1986 | IP_STR |
| 1987 | "IPv6 routing table\n" |
| 1988 | "IPv6 prefix\n" |
| 1989 | "Show route matching the specified Network/Mask pair only\n") |
| 1990 | { |
| 1991 | struct route_table *table; |
| 1992 | struct route_node *rn; |
| 1993 | struct rib *rib; |
| 1994 | struct prefix p; |
| 1995 | int ret; |
| 1996 | int first = 1; |
| 1997 | |
| 1998 | table = vrf_table (AFI_IP6, SAFI_UNICAST, 0); |
| 1999 | if (! table) |
| 2000 | return CMD_SUCCESS; |
| 2001 | |
| 2002 | ret = str2prefix (argv[0], &p); |
| 2003 | if (! ret) |
| 2004 | { |
| 2005 | vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE); |
| 2006 | return CMD_WARNING; |
| 2007 | } |
| 2008 | |
| 2009 | /* Show matched type IPv6 routes. */ |
| 2010 | for (rn = route_top (table); rn; rn = route_next (rn)) |
Avneesh Sachdev | 9fd92e3 | 2012-11-13 22:48:53 +0000 | [diff] [blame] | 2011 | RNODE_FOREACH_RIB (rn, rib) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2012 | if (prefix_match (&p, &rn->p)) |
| 2013 | { |
| 2014 | if (first) |
| 2015 | { |
David Lamparter | e0ca5fd | 2009-09-16 01:52:42 +0200 | [diff] [blame] | 2016 | vty_out (vty, SHOW_ROUTE_V6_HEADER); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2017 | first = 0; |
| 2018 | } |
| 2019 | vty_show_ipv6_route (vty, rn, rib); |
| 2020 | } |
| 2021 | return CMD_SUCCESS; |
| 2022 | } |
| 2023 | |
| 2024 | DEFUN (show_ipv6_route_protocol, |
| 2025 | show_ipv6_route_protocol_cmd, |
David Lamparter | e0ca5fd | 2009-09-16 01:52:42 +0200 | [diff] [blame] | 2026 | "show ipv6 route " QUAGGA_IP6_REDIST_STR_ZEBRA, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2027 | SHOW_STR |
| 2028 | IP_STR |
| 2029 | "IP routing table\n" |
David Lamparter | e0ca5fd | 2009-09-16 01:52:42 +0200 | [diff] [blame] | 2030 | QUAGGA_IP6_REDIST_HELP_STR_ZEBRA) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2031 | { |
| 2032 | int type; |
| 2033 | struct route_table *table; |
| 2034 | struct route_node *rn; |
| 2035 | struct rib *rib; |
| 2036 | int first = 1; |
| 2037 | |
David Lamparter | e0ca5fd | 2009-09-16 01:52:42 +0200 | [diff] [blame] | 2038 | type = proto_redistnum (AFI_IP6, argv[0]); |
| 2039 | if (type < 0) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2040 | { |
| 2041 | vty_out (vty, "Unknown route type%s", VTY_NEWLINE); |
| 2042 | return CMD_WARNING; |
| 2043 | } |
| 2044 | |
| 2045 | table = vrf_table (AFI_IP6, SAFI_UNICAST, 0); |
| 2046 | if (! table) |
| 2047 | return CMD_SUCCESS; |
| 2048 | |
| 2049 | /* Show matched type IPv6 routes. */ |
| 2050 | for (rn = route_top (table); rn; rn = route_next (rn)) |
Avneesh Sachdev | 9fd92e3 | 2012-11-13 22:48:53 +0000 | [diff] [blame] | 2051 | RNODE_FOREACH_RIB (rn, rib) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2052 | if (rib->type == type) |
| 2053 | { |
| 2054 | if (first) |
| 2055 | { |
David Lamparter | e0ca5fd | 2009-09-16 01:52:42 +0200 | [diff] [blame] | 2056 | vty_out (vty, SHOW_ROUTE_V6_HEADER); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2057 | first = 0; |
| 2058 | } |
| 2059 | vty_show_ipv6_route (vty, rn, rib); |
| 2060 | } |
| 2061 | return CMD_SUCCESS; |
| 2062 | } |
| 2063 | |
| 2064 | DEFUN (show_ipv6_route_addr, |
| 2065 | show_ipv6_route_addr_cmd, |
| 2066 | "show ipv6 route X:X::X:X", |
| 2067 | SHOW_STR |
| 2068 | IP_STR |
| 2069 | "IPv6 routing table\n" |
| 2070 | "IPv6 Address\n") |
| 2071 | { |
| 2072 | int ret; |
| 2073 | struct prefix_ipv6 p; |
| 2074 | struct route_table *table; |
| 2075 | struct route_node *rn; |
| 2076 | |
| 2077 | ret = str2prefix_ipv6 (argv[0], &p); |
| 2078 | if (ret <= 0) |
| 2079 | { |
| 2080 | vty_out (vty, "Malformed IPv6 address%s", VTY_NEWLINE); |
| 2081 | return CMD_WARNING; |
| 2082 | } |
| 2083 | |
| 2084 | table = vrf_table (AFI_IP6, SAFI_UNICAST, 0); |
| 2085 | if (! table) |
| 2086 | return CMD_SUCCESS; |
| 2087 | |
| 2088 | rn = route_node_match (table, (struct prefix *) &p); |
| 2089 | if (! rn) |
| 2090 | { |
| 2091 | vty_out (vty, "%% Network not in table%s", VTY_NEWLINE); |
| 2092 | return CMD_WARNING; |
| 2093 | } |
| 2094 | |
| 2095 | vty_show_ipv6_route_detail (vty, rn); |
| 2096 | |
| 2097 | route_unlock_node (rn); |
| 2098 | |
| 2099 | return CMD_SUCCESS; |
| 2100 | } |
| 2101 | |
| 2102 | DEFUN (show_ipv6_route_prefix, |
| 2103 | show_ipv6_route_prefix_cmd, |
| 2104 | "show ipv6 route X:X::X:X/M", |
| 2105 | SHOW_STR |
| 2106 | IP_STR |
| 2107 | "IPv6 routing table\n" |
| 2108 | "IPv6 prefix\n") |
| 2109 | { |
| 2110 | int ret; |
| 2111 | struct prefix_ipv6 p; |
| 2112 | struct route_table *table; |
| 2113 | struct route_node *rn; |
| 2114 | |
| 2115 | ret = str2prefix_ipv6 (argv[0], &p); |
| 2116 | if (ret <= 0) |
| 2117 | { |
| 2118 | vty_out (vty, "Malformed IPv6 prefix%s", VTY_NEWLINE); |
| 2119 | return CMD_WARNING; |
| 2120 | } |
| 2121 | |
| 2122 | table = vrf_table (AFI_IP6, SAFI_UNICAST, 0); |
| 2123 | if (! table) |
| 2124 | return CMD_SUCCESS; |
| 2125 | |
| 2126 | rn = route_node_match (table, (struct prefix *) &p); |
| 2127 | if (! rn || rn->p.prefixlen != p.prefixlen) |
| 2128 | { |
| 2129 | vty_out (vty, "%% Network not in table%s", VTY_NEWLINE); |
Lu Feng | 969d355 | 2014-10-21 06:24:07 +0000 | [diff] [blame] | 2130 | if (rn) |
| 2131 | route_unlock_node (rn); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2132 | return CMD_WARNING; |
| 2133 | } |
| 2134 | |
| 2135 | vty_show_ipv6_route_detail (vty, rn); |
| 2136 | |
| 2137 | route_unlock_node (rn); |
| 2138 | |
| 2139 | return CMD_SUCCESS; |
| 2140 | } |
| 2141 | |
Stig Thormodsrud | 61691c9 | 2008-11-04 15:45:07 -0800 | [diff] [blame] | 2142 | /* Show route summary. */ |
| 2143 | DEFUN (show_ipv6_route_summary, |
| 2144 | show_ipv6_route_summary_cmd, |
| 2145 | "show ipv6 route summary", |
| 2146 | SHOW_STR |
| 2147 | IP_STR |
| 2148 | "IPv6 routing table\n" |
| 2149 | "Summary of all IPv6 routes\n") |
| 2150 | { |
| 2151 | struct route_table *table; |
| 2152 | |
| 2153 | table = vrf_table (AFI_IP6, SAFI_UNICAST, 0); |
| 2154 | if (! table) |
| 2155 | return CMD_SUCCESS; |
| 2156 | |
| 2157 | vty_show_ip_route_summary (vty, table); |
| 2158 | |
| 2159 | return CMD_SUCCESS; |
| 2160 | } |
| 2161 | |
Dinesh G Dutt | 56a5f77 | 2014-09-30 12:58:04 -0700 | [diff] [blame] | 2162 | /* Show ipv6 route summary prefix. */ |
| 2163 | DEFUN (show_ipv6_route_summary_prefix, |
| 2164 | show_ipv6_route_summary_prefix_cmd, |
| 2165 | "show ipv6 route summary prefix", |
| 2166 | SHOW_STR |
| 2167 | IP_STR |
| 2168 | "IPv6 routing table\n" |
| 2169 | "Summary of all IPv6 routes\n" |
| 2170 | "Prefix routes\n") |
| 2171 | { |
| 2172 | struct route_table *table; |
| 2173 | |
| 2174 | table = vrf_table (AFI_IP6, SAFI_UNICAST, 0); |
| 2175 | if (! table) |
| 2176 | return CMD_SUCCESS; |
| 2177 | |
| 2178 | vty_show_ip_route_summary_prefix (vty, table); |
| 2179 | |
| 2180 | return CMD_SUCCESS; |
| 2181 | } |
| 2182 | |
G.Balaji | cddf391 | 2011-11-26 21:59:32 +0400 | [diff] [blame] | 2183 | /* |
G.Balaji | cddf391 | 2011-11-26 21:59:32 +0400 | [diff] [blame] | 2184 | * Show IPv6 mroute command.Used to dump |
| 2185 | * the Multicast routing table. |
| 2186 | */ |
| 2187 | |
| 2188 | DEFUN (show_ipv6_mroute, |
| 2189 | show_ipv6_mroute_cmd, |
| 2190 | "show ipv6 mroute", |
| 2191 | SHOW_STR |
| 2192 | IP_STR |
| 2193 | "IPv6 Multicast routing table\n") |
| 2194 | { |
| 2195 | struct route_table *table; |
| 2196 | struct route_node *rn; |
| 2197 | struct rib *rib; |
| 2198 | int first = 1; |
| 2199 | |
| 2200 | table = vrf_table (AFI_IP6, SAFI_MULTICAST, 0); |
| 2201 | if (! table) |
| 2202 | return CMD_SUCCESS; |
| 2203 | |
| 2204 | /* Show all IPv6 route. */ |
| 2205 | for (rn = route_top (table); rn; rn = route_next (rn)) |
Avneesh Sachdev | 9fd92e3 | 2012-11-13 22:48:53 +0000 | [diff] [blame] | 2206 | RNODE_FOREACH_RIB (rn, rib) |
G.Balaji | cddf391 | 2011-11-26 21:59:32 +0400 | [diff] [blame] | 2207 | { |
| 2208 | if (first) |
| 2209 | { |
G.Balaji | cb32fd6 | 2011-11-27 20:09:40 +0530 | [diff] [blame] | 2210 | vty_out (vty, SHOW_ROUTE_V6_HEADER); |
G.Balaji | cddf391 | 2011-11-26 21:59:32 +0400 | [diff] [blame] | 2211 | first = 0; |
| 2212 | } |
| 2213 | vty_show_ipv6_route (vty, rn, rib); |
| 2214 | } |
| 2215 | return CMD_SUCCESS; |
| 2216 | } |
| 2217 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2218 | /* Write IPv6 static route configuration. */ |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 2219 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2220 | static_config_ipv6 (struct vty *vty) |
| 2221 | { |
| 2222 | struct route_node *rn; |
| 2223 | struct static_ipv6 *si; |
| 2224 | int write; |
| 2225 | char buf[BUFSIZ]; |
| 2226 | struct route_table *stable; |
| 2227 | |
| 2228 | write = 0; |
| 2229 | |
| 2230 | /* Lookup table. */ |
| 2231 | stable = vrf_static_table (AFI_IP6, SAFI_UNICAST, 0); |
| 2232 | if (! stable) |
| 2233 | return -1; |
| 2234 | |
| 2235 | for (rn = route_top (stable); rn; rn = route_next (rn)) |
| 2236 | for (si = rn->info; si; si = si->next) |
| 2237 | { |
| 2238 | vty_out (vty, "ipv6 route %s/%d", |
| 2239 | inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, BUFSIZ), |
| 2240 | rn->p.prefixlen); |
| 2241 | |
| 2242 | switch (si->type) |
| 2243 | { |
| 2244 | case STATIC_IPV6_GATEWAY: |
| 2245 | vty_out (vty, " %s", inet_ntop (AF_INET6, &si->ipv6, buf, BUFSIZ)); |
| 2246 | break; |
| 2247 | case STATIC_IPV6_IFNAME: |
| 2248 | vty_out (vty, " %s", si->ifname); |
| 2249 | break; |
| 2250 | case STATIC_IPV6_GATEWAY_IFNAME: |
| 2251 | vty_out (vty, " %s %s", |
| 2252 | inet_ntop (AF_INET6, &si->ipv6, buf, BUFSIZ), si->ifname); |
| 2253 | break; |
| 2254 | } |
| 2255 | |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 2256 | if (CHECK_FLAG(si->flags, ZEBRA_FLAG_REJECT)) |
| 2257 | vty_out (vty, " %s", "reject"); |
| 2258 | |
| 2259 | if (CHECK_FLAG(si->flags, ZEBRA_FLAG_BLACKHOLE)) |
| 2260 | vty_out (vty, " %s", "blackhole"); |
| 2261 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2262 | if (si->distance != ZEBRA_STATIC_DISTANCE_DEFAULT) |
| 2263 | vty_out (vty, " %d", si->distance); |
| 2264 | vty_out (vty, "%s", VTY_NEWLINE); |
| 2265 | |
| 2266 | write = 1; |
| 2267 | } |
| 2268 | return write; |
| 2269 | } |
| 2270 | #endif /* HAVE_IPV6 */ |
| 2271 | |
| 2272 | /* Static ip route configuration write function. */ |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 2273 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2274 | zebra_ip_config (struct vty *vty) |
| 2275 | { |
| 2276 | int write = 0; |
| 2277 | |
Everton Marques | 33d86db | 2014-07-14 11:19:00 -0300 | [diff] [blame] | 2278 | write += static_config_ipv4 (vty, SAFI_UNICAST, "ip route"); |
| 2279 | write += static_config_ipv4 (vty, SAFI_MULTICAST, "ip mroute"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2280 | #ifdef HAVE_IPV6 |
| 2281 | write += static_config_ipv6 (vty); |
| 2282 | #endif /* HAVE_IPV6 */ |
| 2283 | |
| 2284 | return write; |
| 2285 | } |
| 2286 | |
David Lamparter | bd07812 | 2015-01-06 19:53:24 +0100 | [diff] [blame^] | 2287 | static int config_write_vty(struct vty *vty) |
| 2288 | { |
Paul Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 2289 | int i; |
David Lamparter | bd07812 | 2015-01-06 19:53:24 +0100 | [diff] [blame^] | 2290 | enum multicast_mode ipv4_multicast_mode = multicast_mode_ipv4_get (); |
| 2291 | |
| 2292 | if (ipv4_multicast_mode != MCAST_NO_CONFIG) |
| 2293 | vty_out (vty, "ip multicast rpf-lookup-mode %s%s", |
| 2294 | ipv4_multicast_mode == MCAST_URIB_ONLY ? "urib-only" : |
| 2295 | ipv4_multicast_mode == MCAST_MRIB_ONLY ? "mrib-only" : |
| 2296 | ipv4_multicast_mode == MCAST_MIX_MRIB_FIRST ? "mrib-then-urib" : |
| 2297 | ipv4_multicast_mode == MCAST_MIX_DISTANCE ? "lower-distance" : |
| 2298 | "longer-prefix", |
| 2299 | VTY_NEWLINE); |
Paul Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 2300 | |
| 2301 | for (i=0;i<ZEBRA_ROUTE_MAX;i++) |
| 2302 | { |
| 2303 | if (proto_rm[AFI_IP][i]) |
| 2304 | vty_out (vty, "ip protocol %s route-map %s%s", zebra_route_string(i), |
| 2305 | proto_rm[AFI_IP][i], VTY_NEWLINE); |
| 2306 | } |
| 2307 | if (proto_rm[AFI_IP][ZEBRA_ROUTE_MAX]) |
| 2308 | vty_out (vty, "ip protocol %s route-map %s%s", "any", |
| 2309 | proto_rm[AFI_IP][ZEBRA_ROUTE_MAX], VTY_NEWLINE); |
| 2310 | |
| 2311 | return 1; |
| 2312 | } |
| 2313 | |
| 2314 | /* table node for protocol filtering */ |
Stephen Hemminger | 7fc626d | 2008-12-01 11:10:34 -0800 | [diff] [blame] | 2315 | static struct cmd_node protocol_node = { PROTOCOL_NODE, "", 1 }; |
Paul Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 2316 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2317 | /* IP node for static routes. */ |
Stephen Hemminger | 7fc626d | 2008-12-01 11:10:34 -0800 | [diff] [blame] | 2318 | static struct cmd_node ip_node = { IP_NODE, "", 1 }; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2319 | |
| 2320 | /* Route VTY. */ |
| 2321 | void |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 2322 | zebra_vty_init (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2323 | { |
| 2324 | install_node (&ip_node, zebra_ip_config); |
David Lamparter | bd07812 | 2015-01-06 19:53:24 +0100 | [diff] [blame^] | 2325 | install_node (&protocol_node, config_write_vty); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2326 | |
Everton Marques | 33d86db | 2014-07-14 11:19:00 -0300 | [diff] [blame] | 2327 | install_element (CONFIG_NODE, &ip_mroute_cmd); |
David Lamparter | a76681b | 2015-01-22 19:03:53 +0100 | [diff] [blame] | 2328 | install_element (CONFIG_NODE, &ip_mroute_dist_cmd); |
Everton Marques | 33d86db | 2014-07-14 11:19:00 -0300 | [diff] [blame] | 2329 | install_element (CONFIG_NODE, &no_ip_mroute_cmd); |
David Lamparter | a76681b | 2015-01-22 19:03:53 +0100 | [diff] [blame] | 2330 | install_element (CONFIG_NODE, &no_ip_mroute_dist_cmd); |
David Lamparter | bd07812 | 2015-01-06 19:53:24 +0100 | [diff] [blame^] | 2331 | install_element (CONFIG_NODE, &ip_multicast_mode_cmd); |
| 2332 | install_element (CONFIG_NODE, &no_ip_multicast_mode_cmd); |
| 2333 | install_element (CONFIG_NODE, &no_ip_multicast_mode_noarg_cmd); |
Paul Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 2334 | install_element (CONFIG_NODE, &ip_protocol_cmd); |
| 2335 | install_element (CONFIG_NODE, &no_ip_protocol_cmd); |
| 2336 | install_element (VIEW_NODE, &show_ip_protocol_cmd); |
| 2337 | install_element (ENABLE_NODE, &show_ip_protocol_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2338 | install_element (CONFIG_NODE, &ip_route_cmd); |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 2339 | install_element (CONFIG_NODE, &ip_route_flags_cmd); |
hasso | 457ef55 | 2003-05-28 12:02:15 +0000 | [diff] [blame] | 2340 | install_element (CONFIG_NODE, &ip_route_flags2_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2341 | install_element (CONFIG_NODE, &ip_route_mask_cmd); |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 2342 | install_element (CONFIG_NODE, &ip_route_mask_flags_cmd); |
hasso | 457ef55 | 2003-05-28 12:02:15 +0000 | [diff] [blame] | 2343 | install_element (CONFIG_NODE, &ip_route_mask_flags2_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2344 | install_element (CONFIG_NODE, &no_ip_route_cmd); |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 2345 | install_element (CONFIG_NODE, &no_ip_route_flags_cmd); |
hasso | 457ef55 | 2003-05-28 12:02:15 +0000 | [diff] [blame] | 2346 | install_element (CONFIG_NODE, &no_ip_route_flags2_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2347 | install_element (CONFIG_NODE, &no_ip_route_mask_cmd); |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 2348 | install_element (CONFIG_NODE, &no_ip_route_mask_flags_cmd); |
hasso | 457ef55 | 2003-05-28 12:02:15 +0000 | [diff] [blame] | 2349 | install_element (CONFIG_NODE, &no_ip_route_mask_flags2_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2350 | install_element (CONFIG_NODE, &ip_route_distance_cmd); |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 2351 | install_element (CONFIG_NODE, &ip_route_flags_distance_cmd); |
hasso | 457ef55 | 2003-05-28 12:02:15 +0000 | [diff] [blame] | 2352 | install_element (CONFIG_NODE, &ip_route_flags_distance2_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2353 | install_element (CONFIG_NODE, &ip_route_mask_distance_cmd); |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 2354 | install_element (CONFIG_NODE, &ip_route_mask_flags_distance_cmd); |
hasso | 457ef55 | 2003-05-28 12:02:15 +0000 | [diff] [blame] | 2355 | install_element (CONFIG_NODE, &ip_route_mask_flags_distance2_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2356 | install_element (CONFIG_NODE, &no_ip_route_distance_cmd); |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 2357 | install_element (CONFIG_NODE, &no_ip_route_flags_distance_cmd); |
hasso | 457ef55 | 2003-05-28 12:02:15 +0000 | [diff] [blame] | 2358 | install_element (CONFIG_NODE, &no_ip_route_flags_distance2_cmd); |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 2359 | install_element (CONFIG_NODE, &no_ip_route_mask_flags_distance_cmd); |
hasso | 457ef55 | 2003-05-28 12:02:15 +0000 | [diff] [blame] | 2360 | install_element (CONFIG_NODE, &no_ip_route_mask_flags_distance2_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2361 | |
| 2362 | install_element (VIEW_NODE, &show_ip_route_cmd); |
| 2363 | install_element (VIEW_NODE, &show_ip_route_addr_cmd); |
| 2364 | install_element (VIEW_NODE, &show_ip_route_prefix_cmd); |
| 2365 | install_element (VIEW_NODE, &show_ip_route_prefix_longer_cmd); |
| 2366 | install_element (VIEW_NODE, &show_ip_route_protocol_cmd); |
| 2367 | install_element (VIEW_NODE, &show_ip_route_supernets_cmd); |
Stig Thormodsrud | 61691c9 | 2008-11-04 15:45:07 -0800 | [diff] [blame] | 2368 | install_element (VIEW_NODE, &show_ip_route_summary_cmd); |
Dinesh G Dutt | 56a5f77 | 2014-09-30 12:58:04 -0700 | [diff] [blame] | 2369 | install_element (VIEW_NODE, &show_ip_route_summary_prefix_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2370 | install_element (ENABLE_NODE, &show_ip_route_cmd); |
| 2371 | install_element (ENABLE_NODE, &show_ip_route_addr_cmd); |
| 2372 | install_element (ENABLE_NODE, &show_ip_route_prefix_cmd); |
| 2373 | install_element (ENABLE_NODE, &show_ip_route_prefix_longer_cmd); |
| 2374 | install_element (ENABLE_NODE, &show_ip_route_protocol_cmd); |
| 2375 | install_element (ENABLE_NODE, &show_ip_route_supernets_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2376 | install_element (ENABLE_NODE, &show_ip_route_summary_cmd); |
Dinesh G Dutt | 56a5f77 | 2014-09-30 12:58:04 -0700 | [diff] [blame] | 2377 | install_element (ENABLE_NODE, &show_ip_route_summary_prefix_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2378 | |
G.Balaji | cddf391 | 2011-11-26 21:59:32 +0400 | [diff] [blame] | 2379 | install_element (VIEW_NODE, &show_ip_mroute_cmd); |
| 2380 | install_element (ENABLE_NODE, &show_ip_mroute_cmd); |
| 2381 | |
Everton Marques | 33d86db | 2014-07-14 11:19:00 -0300 | [diff] [blame] | 2382 | install_element (VIEW_NODE, &show_ip_rpf_cmd); |
| 2383 | install_element (ENABLE_NODE, &show_ip_rpf_cmd); |
G.Balaji | cddf391 | 2011-11-26 21:59:32 +0400 | [diff] [blame] | 2384 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2385 | #ifdef HAVE_IPV6 |
| 2386 | install_element (CONFIG_NODE, &ipv6_route_cmd); |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 2387 | install_element (CONFIG_NODE, &ipv6_route_flags_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2388 | install_element (CONFIG_NODE, &ipv6_route_ifname_cmd); |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 2389 | install_element (CONFIG_NODE, &ipv6_route_ifname_flags_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2390 | install_element (CONFIG_NODE, &no_ipv6_route_cmd); |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 2391 | install_element (CONFIG_NODE, &no_ipv6_route_flags_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2392 | install_element (CONFIG_NODE, &no_ipv6_route_ifname_cmd); |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 2393 | install_element (CONFIG_NODE, &no_ipv6_route_ifname_flags_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2394 | install_element (CONFIG_NODE, &ipv6_route_pref_cmd); |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 2395 | install_element (CONFIG_NODE, &ipv6_route_flags_pref_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2396 | install_element (CONFIG_NODE, &ipv6_route_ifname_pref_cmd); |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 2397 | install_element (CONFIG_NODE, &ipv6_route_ifname_flags_pref_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2398 | install_element (CONFIG_NODE, &no_ipv6_route_pref_cmd); |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 2399 | install_element (CONFIG_NODE, &no_ipv6_route_flags_pref_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2400 | install_element (CONFIG_NODE, &no_ipv6_route_ifname_pref_cmd); |
hasso | 81dfcaa | 2003-05-25 19:21:25 +0000 | [diff] [blame] | 2401 | install_element (CONFIG_NODE, &no_ipv6_route_ifname_flags_pref_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2402 | install_element (VIEW_NODE, &show_ipv6_route_cmd); |
Stig Thormodsrud | 61691c9 | 2008-11-04 15:45:07 -0800 | [diff] [blame] | 2403 | install_element (VIEW_NODE, &show_ipv6_route_summary_cmd); |
Dinesh G Dutt | 56a5f77 | 2014-09-30 12:58:04 -0700 | [diff] [blame] | 2404 | install_element (VIEW_NODE, &show_ipv6_route_summary_prefix_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2405 | install_element (VIEW_NODE, &show_ipv6_route_protocol_cmd); |
| 2406 | install_element (VIEW_NODE, &show_ipv6_route_addr_cmd); |
| 2407 | install_element (VIEW_NODE, &show_ipv6_route_prefix_cmd); |
| 2408 | install_element (VIEW_NODE, &show_ipv6_route_prefix_longer_cmd); |
| 2409 | install_element (ENABLE_NODE, &show_ipv6_route_cmd); |
| 2410 | install_element (ENABLE_NODE, &show_ipv6_route_protocol_cmd); |
| 2411 | install_element (ENABLE_NODE, &show_ipv6_route_addr_cmd); |
| 2412 | install_element (ENABLE_NODE, &show_ipv6_route_prefix_cmd); |
| 2413 | install_element (ENABLE_NODE, &show_ipv6_route_prefix_longer_cmd); |
Stig Thormodsrud | 61691c9 | 2008-11-04 15:45:07 -0800 | [diff] [blame] | 2414 | install_element (ENABLE_NODE, &show_ipv6_route_summary_cmd); |
Dinesh G Dutt | 56a5f77 | 2014-09-30 12:58:04 -0700 | [diff] [blame] | 2415 | install_element (ENABLE_NODE, &show_ipv6_route_summary_prefix_cmd); |
G.Balaji | cddf391 | 2011-11-26 21:59:32 +0400 | [diff] [blame] | 2416 | |
| 2417 | install_element (VIEW_NODE, &show_ipv6_mroute_cmd); |
| 2418 | install_element (ENABLE_NODE, &show_ipv6_mroute_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2419 | #endif /* HAVE_IPV6 */ |
| 2420 | } |