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