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