paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Route map function of ospfd. |
| 3 | * Copyright (C) 2000 IP Infusion Inc. |
| 4 | * |
| 5 | * Written by Toshiaki Takada. |
| 6 | * |
| 7 | * This file is part of GNU Zebra. |
| 8 | * |
| 9 | * GNU Zebra is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of the GNU General Public License as published by the |
| 11 | * Free Software Foundation; either version 2, or (at your option) any |
| 12 | * later version. |
| 13 | * |
| 14 | * GNU Zebra is distributed in the hope that it will be useful, but |
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | * General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with GNU Zebra; see the file COPYING. If not, write to the Free |
| 21 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 22 | * 02111-1307, USA. |
| 23 | */ |
| 24 | |
| 25 | #include <zebra.h> |
| 26 | |
| 27 | #include "memory.h" |
| 28 | #include "prefix.h" |
| 29 | #include "table.h" |
| 30 | #include "routemap.h" |
| 31 | #include "command.h" |
| 32 | #include "log.h" |
| 33 | #include "plist.h" |
| 34 | |
| 35 | #include "ospfd/ospfd.h" |
| 36 | #include "ospfd/ospf_asbr.h" |
| 37 | #include "ospfd/ospf_interface.h" |
| 38 | #include "ospfd/ospf_lsa.h" |
| 39 | #include "ospfd/ospf_route.h" |
| 40 | #include "ospfd/ospf_zebra.h" |
| 41 | |
| 42 | /* Hook function for updating route_map assignment. */ |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 43 | static void |
paul | 6c83567 | 2004-10-11 11:00:30 +0000 | [diff] [blame] | 44 | ospf_route_map_update (const char *name) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 45 | { |
paul | 73ffb25 | 2003-04-19 15:49:49 +0000 | [diff] [blame] | 46 | struct ospf *ospf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 47 | int type; |
| 48 | |
| 49 | /* If OSPF instatnce does not exist, return right now. */ |
paul | 73ffb25 | 2003-04-19 15:49:49 +0000 | [diff] [blame] | 50 | ospf = ospf_lookup (); |
| 51 | if (ospf == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 52 | return; |
| 53 | |
| 54 | /* Update route-map */ |
| 55 | for (type = 0; type <= ZEBRA_ROUTE_MAX; type++) |
| 56 | { |
paul | 73ffb25 | 2003-04-19 15:49:49 +0000 | [diff] [blame] | 57 | if (ROUTEMAP_NAME (ospf, type) |
| 58 | && strcmp (ROUTEMAP_NAME (ospf, type), name) == 0) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 59 | { |
| 60 | /* Keep old route-map. */ |
paul | 73ffb25 | 2003-04-19 15:49:49 +0000 | [diff] [blame] | 61 | struct route_map *old = ROUTEMAP (ospf, type); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 62 | |
| 63 | /* Update route-map. */ |
paul | 73ffb25 | 2003-04-19 15:49:49 +0000 | [diff] [blame] | 64 | ROUTEMAP (ospf, type) = |
| 65 | route_map_lookup_by_name (ROUTEMAP_NAME (ospf, type)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 66 | |
| 67 | /* No update for this distribute type. */ |
paul | 73ffb25 | 2003-04-19 15:49:49 +0000 | [diff] [blame] | 68 | if (old == NULL && ROUTEMAP (ospf, type) == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 69 | continue; |
| 70 | |
paul | 73ffb25 | 2003-04-19 15:49:49 +0000 | [diff] [blame] | 71 | ospf_distribute_list_update (ospf, type); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 72 | } |
| 73 | } |
| 74 | } |
| 75 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 76 | static void |
paul | 6c83567 | 2004-10-11 11:00:30 +0000 | [diff] [blame] | 77 | ospf_route_map_event (route_map_event_t event, const char *name) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 78 | { |
paul | 73ffb25 | 2003-04-19 15:49:49 +0000 | [diff] [blame] | 79 | struct ospf *ospf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 80 | int type; |
| 81 | |
| 82 | /* If OSPF instatnce does not exist, return right now. */ |
paul | 73ffb25 | 2003-04-19 15:49:49 +0000 | [diff] [blame] | 83 | ospf = ospf_lookup (); |
| 84 | if (ospf == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 85 | return; |
| 86 | |
| 87 | /* Update route-map. */ |
| 88 | for (type = 0; type <= ZEBRA_ROUTE_MAX; type++) |
| 89 | { |
paul | 73ffb25 | 2003-04-19 15:49:49 +0000 | [diff] [blame] | 90 | if (ROUTEMAP_NAME (ospf, type) && ROUTEMAP (ospf, type) |
| 91 | && !strcmp (ROUTEMAP_NAME (ospf, type), name)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 92 | { |
paul | 73ffb25 | 2003-04-19 15:49:49 +0000 | [diff] [blame] | 93 | ospf_distribute_list_update (ospf, type); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 94 | } |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | /* Delete rip route map rule. */ |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 99 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 100 | ospf_route_match_delete (struct vty *vty, struct route_map_index *index, |
paul | 6c83567 | 2004-10-11 11:00:30 +0000 | [diff] [blame] | 101 | const char *command, const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 102 | { |
| 103 | int ret; |
| 104 | |
| 105 | ret = route_map_delete_match (index, command, arg); |
| 106 | if (ret) |
| 107 | { |
| 108 | switch (ret) |
| 109 | { |
| 110 | case RMAP_RULE_MISSING: |
Daniel Walton | c7f25b9 | 2015-05-19 17:47:22 -0700 | [diff] [blame] | 111 | vty_out (vty, "%% OSPF Can't find rule.%s", VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 112 | return CMD_WARNING; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 113 | case RMAP_COMPILE_ERROR: |
Daniel Walton | c7f25b9 | 2015-05-19 17:47:22 -0700 | [diff] [blame] | 114 | vty_out (vty, "%% OSPF Argument is malformed.%s", VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 115 | return CMD_WARNING; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 116 | } |
| 117 | } |
| 118 | |
| 119 | return CMD_SUCCESS; |
| 120 | } |
| 121 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 122 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 123 | ospf_route_match_add (struct vty *vty, struct route_map_index *index, |
paul | 6c83567 | 2004-10-11 11:00:30 +0000 | [diff] [blame] | 124 | const char *command, const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 125 | { |
| 126 | int ret; |
| 127 | |
| 128 | ret = route_map_add_match (index, command, arg); |
| 129 | if (ret) |
| 130 | { |
| 131 | switch (ret) |
| 132 | { |
| 133 | case RMAP_RULE_MISSING: |
Daniel Walton | c7f25b9 | 2015-05-19 17:47:22 -0700 | [diff] [blame] | 134 | vty_out (vty, "%% OSPF Can't find rule.%s", VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 135 | return CMD_WARNING; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 136 | case RMAP_COMPILE_ERROR: |
Daniel Walton | c7f25b9 | 2015-05-19 17:47:22 -0700 | [diff] [blame] | 137 | vty_out (vty, "%% OSPF Argument is malformed.%s", VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 138 | return CMD_WARNING; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 139 | } |
| 140 | } |
| 141 | |
| 142 | return CMD_SUCCESS; |
| 143 | } |
| 144 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 145 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 146 | ospf_route_set_add (struct vty *vty, struct route_map_index *index, |
paul | 6c83567 | 2004-10-11 11:00:30 +0000 | [diff] [blame] | 147 | const char *command, const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 148 | { |
| 149 | int ret; |
| 150 | |
| 151 | ret = route_map_add_set (index, command, arg); |
| 152 | if (ret) |
| 153 | { |
| 154 | switch (ret) |
| 155 | { |
| 156 | case RMAP_RULE_MISSING: |
Daniel Walton | c7f25b9 | 2015-05-19 17:47:22 -0700 | [diff] [blame] | 157 | vty_out (vty, "%% OSPF Can't find rule.%s", VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 158 | return CMD_WARNING; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 159 | case RMAP_COMPILE_ERROR: |
Daniel Walton | c7f25b9 | 2015-05-19 17:47:22 -0700 | [diff] [blame] | 160 | vty_out (vty, "%% OSPF Argument is malformed.%s", VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 161 | return CMD_WARNING; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 162 | } |
| 163 | } |
| 164 | |
| 165 | return CMD_SUCCESS; |
| 166 | } |
| 167 | |
| 168 | /* Delete rip route map rule. */ |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 169 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 170 | ospf_route_set_delete (struct vty *vty, struct route_map_index *index, |
paul | 6c83567 | 2004-10-11 11:00:30 +0000 | [diff] [blame] | 171 | const char *command, const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 172 | { |
| 173 | int ret; |
| 174 | |
| 175 | ret = route_map_delete_set (index, command, arg); |
| 176 | if (ret) |
| 177 | { |
| 178 | switch (ret) |
| 179 | { |
| 180 | case RMAP_RULE_MISSING: |
Daniel Walton | c7f25b9 | 2015-05-19 17:47:22 -0700 | [diff] [blame] | 181 | vty_out (vty, "%% OSPF Can't find rule.%s", VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 182 | return CMD_WARNING; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 183 | case RMAP_COMPILE_ERROR: |
Daniel Walton | c7f25b9 | 2015-05-19 17:47:22 -0700 | [diff] [blame] | 184 | vty_out (vty, "%% OSPF Argument is malformed.%s", VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 185 | return CMD_WARNING; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 186 | } |
| 187 | } |
| 188 | |
| 189 | return CMD_SUCCESS; |
| 190 | } |
| 191 | |
| 192 | /* `match ip netxthop ' */ |
| 193 | /* Match function return 1 if match is success else return zero. */ |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 194 | static route_map_result_t |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 195 | route_match_ip_nexthop (void *rule, struct prefix *prefix, |
| 196 | route_map_object_t type, void *object) |
| 197 | { |
| 198 | struct access_list *alist; |
| 199 | struct external_info *ei = object; |
| 200 | struct prefix_ipv4 p; |
| 201 | |
| 202 | if (type == RMAP_OSPF) |
| 203 | { |
| 204 | p.family = AF_INET; |
| 205 | p.prefix = ei->nexthop; |
| 206 | p.prefixlen = IPV4_MAX_BITLEN; |
| 207 | |
| 208 | alist = access_list_lookup (AFI_IP, (char *) rule); |
| 209 | if (alist == NULL) |
| 210 | return RMAP_NOMATCH; |
| 211 | |
| 212 | return (access_list_apply (alist, &p) == FILTER_DENY ? |
| 213 | RMAP_NOMATCH : RMAP_MATCH); |
| 214 | } |
| 215 | return RMAP_NOMATCH; |
| 216 | } |
| 217 | |
| 218 | /* Route map `ip next-hop' match statement. `arg' should be |
| 219 | access-list name. */ |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 220 | static void * |
paul | 6c83567 | 2004-10-11 11:00:30 +0000 | [diff] [blame] | 221 | route_match_ip_nexthop_compile (const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 222 | { |
| 223 | return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg); |
| 224 | } |
| 225 | |
| 226 | /* Free route map's compiled `ip address' value. */ |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 227 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 228 | route_match_ip_nexthop_free (void *rule) |
| 229 | { |
| 230 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); |
| 231 | } |
| 232 | |
| 233 | /* Route map commands for metric matching. */ |
| 234 | struct route_map_rule_cmd route_match_ip_nexthop_cmd = |
| 235 | { |
| 236 | "ip next-hop", |
| 237 | route_match_ip_nexthop, |
| 238 | route_match_ip_nexthop_compile, |
| 239 | route_match_ip_nexthop_free |
| 240 | }; |
| 241 | |
| 242 | /* `match ip next-hop prefix-list PREFIX_LIST' */ |
| 243 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 244 | static route_map_result_t |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 245 | route_match_ip_next_hop_prefix_list (void *rule, struct prefix *prefix, |
| 246 | route_map_object_t type, void *object) |
| 247 | { |
| 248 | struct prefix_list *plist; |
| 249 | struct external_info *ei = object; |
| 250 | struct prefix_ipv4 p; |
| 251 | |
| 252 | if (type == RMAP_OSPF) |
| 253 | { |
| 254 | p.family = AF_INET; |
| 255 | p.prefix = ei->nexthop; |
| 256 | p.prefixlen = IPV4_MAX_BITLEN; |
| 257 | |
| 258 | plist = prefix_list_lookup (AFI_IP, (char *) rule); |
| 259 | if (plist == NULL) |
| 260 | return RMAP_NOMATCH; |
| 261 | |
| 262 | return (prefix_list_apply (plist, &p) == PREFIX_DENY ? |
| 263 | RMAP_NOMATCH : RMAP_MATCH); |
| 264 | } |
| 265 | return RMAP_NOMATCH; |
| 266 | } |
| 267 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 268 | static void * |
paul | 6c83567 | 2004-10-11 11:00:30 +0000 | [diff] [blame] | 269 | route_match_ip_next_hop_prefix_list_compile (const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 270 | { |
| 271 | return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg); |
| 272 | } |
| 273 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 274 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 275 | route_match_ip_next_hop_prefix_list_free (void *rule) |
| 276 | { |
| 277 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); |
| 278 | } |
| 279 | |
| 280 | struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd = |
| 281 | { |
| 282 | "ip next-hop prefix-list", |
| 283 | route_match_ip_next_hop_prefix_list, |
| 284 | route_match_ip_next_hop_prefix_list_compile, |
| 285 | route_match_ip_next_hop_prefix_list_free |
| 286 | }; |
| 287 | |
| 288 | /* `match ip address IP_ACCESS_LIST' */ |
| 289 | /* Match function should return 1 if match is success else return |
| 290 | zero. */ |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 291 | static route_map_result_t |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 292 | route_match_ip_address (void *rule, struct prefix *prefix, |
| 293 | route_map_object_t type, void *object) |
| 294 | { |
| 295 | struct access_list *alist; |
| 296 | /* struct prefix_ipv4 match; */ |
| 297 | |
| 298 | if (type == RMAP_OSPF) |
| 299 | { |
| 300 | alist = access_list_lookup (AFI_IP, (char *) rule); |
| 301 | if (alist == NULL) |
| 302 | return RMAP_NOMATCH; |
| 303 | |
| 304 | return (access_list_apply (alist, prefix) == FILTER_DENY ? |
| 305 | RMAP_NOMATCH : RMAP_MATCH); |
| 306 | } |
| 307 | return RMAP_NOMATCH; |
| 308 | } |
| 309 | |
| 310 | /* Route map `ip address' match statement. `arg' should be |
| 311 | access-list name. */ |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 312 | static void * |
paul | 6c83567 | 2004-10-11 11:00:30 +0000 | [diff] [blame] | 313 | route_match_ip_address_compile (const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 314 | { |
| 315 | return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg); |
| 316 | } |
| 317 | |
| 318 | /* Free route map's compiled `ip address' value. */ |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 319 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 320 | route_match_ip_address_free (void *rule) |
| 321 | { |
| 322 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); |
| 323 | } |
| 324 | |
| 325 | /* Route map commands for ip address matching. */ |
| 326 | struct route_map_rule_cmd route_match_ip_address_cmd = |
| 327 | { |
| 328 | "ip address", |
| 329 | route_match_ip_address, |
| 330 | route_match_ip_address_compile, |
| 331 | route_match_ip_address_free |
| 332 | }; |
| 333 | |
| 334 | /* `match ip address prefix-list PREFIX_LIST' */ |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 335 | static route_map_result_t |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 336 | route_match_ip_address_prefix_list (void *rule, struct prefix *prefix, |
| 337 | route_map_object_t type, void *object) |
| 338 | { |
| 339 | struct prefix_list *plist; |
| 340 | |
| 341 | if (type == RMAP_OSPF) |
| 342 | { |
| 343 | plist = prefix_list_lookup (AFI_IP, (char *) rule); |
| 344 | if (plist == NULL) |
| 345 | return RMAP_NOMATCH; |
| 346 | |
| 347 | return (prefix_list_apply (plist, prefix) == PREFIX_DENY ? |
| 348 | RMAP_NOMATCH : RMAP_MATCH); |
| 349 | } |
| 350 | return RMAP_NOMATCH; |
| 351 | } |
| 352 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 353 | static void * |
paul | 6c83567 | 2004-10-11 11:00:30 +0000 | [diff] [blame] | 354 | route_match_ip_address_prefix_list_compile (const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 355 | { |
| 356 | return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg); |
| 357 | } |
| 358 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 359 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 360 | route_match_ip_address_prefix_list_free (void *rule) |
| 361 | { |
| 362 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); |
| 363 | } |
| 364 | |
| 365 | struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd = |
| 366 | { |
| 367 | "ip address prefix-list", |
| 368 | route_match_ip_address_prefix_list, |
| 369 | route_match_ip_address_prefix_list_compile, |
| 370 | route_match_ip_address_prefix_list_free |
| 371 | }; |
| 372 | |
| 373 | /* `match interface IFNAME' */ |
| 374 | /* Match function should return 1 if match is success else return |
| 375 | zero. */ |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 376 | static route_map_result_t |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 377 | route_match_interface (void *rule, struct prefix *prefix, |
| 378 | route_map_object_t type, void *object) |
| 379 | { |
| 380 | struct interface *ifp; |
| 381 | struct external_info *ei; |
| 382 | |
| 383 | if (type == RMAP_OSPF) |
| 384 | { |
| 385 | ei = object; |
| 386 | ifp = if_lookup_by_name ((char *)rule); |
| 387 | |
| 388 | if (ifp == NULL || ifp->ifindex != ei->ifindex) |
| 389 | return RMAP_NOMATCH; |
| 390 | |
| 391 | return RMAP_MATCH; |
| 392 | } |
| 393 | return RMAP_NOMATCH; |
| 394 | } |
| 395 | |
| 396 | /* Route map `interface' match statement. `arg' should be |
| 397 | interface name. */ |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 398 | static void * |
paul | 6c83567 | 2004-10-11 11:00:30 +0000 | [diff] [blame] | 399 | route_match_interface_compile (const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 400 | { |
| 401 | return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg); |
| 402 | } |
| 403 | |
| 404 | /* Free route map's compiled `interface' value. */ |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 405 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 406 | route_match_interface_free (void *rule) |
| 407 | { |
| 408 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); |
| 409 | } |
| 410 | |
| 411 | /* Route map commands for ip address matching. */ |
| 412 | struct route_map_rule_cmd route_match_interface_cmd = |
| 413 | { |
| 414 | "interface", |
| 415 | route_match_interface, |
| 416 | route_match_interface_compile, |
| 417 | route_match_interface_free |
| 418 | }; |
| 419 | |
Piotr Chytła | 2b2e38c | 2015-12-01 10:10:41 -0500 | [diff] [blame] | 420 | /* Match function return 1 if match is success else return zero. */ |
| 421 | static route_map_result_t |
| 422 | route_match_tag (void *rule, struct prefix *prefix, |
| 423 | route_map_object_t type, void *object) |
| 424 | { |
Paul Jakma | 96d1060 | 2016-07-01 14:23:45 +0100 | [diff] [blame] | 425 | route_tag_t *tag; |
Piotr Chytła | 2b2e38c | 2015-12-01 10:10:41 -0500 | [diff] [blame] | 426 | struct external_info *ei; |
| 427 | |
| 428 | if (type == RMAP_OSPF) |
| 429 | { |
| 430 | tag = rule; |
| 431 | ei = object; |
| 432 | |
| 433 | return ((ei->tag == *tag)? RMAP_MATCH : RMAP_NOMATCH); |
| 434 | } |
| 435 | |
| 436 | return RMAP_NOMATCH; |
| 437 | } |
| 438 | |
| 439 | /* Route map `match tag' match statement. `arg' is TAG value */ |
| 440 | static void * |
| 441 | route_match_tag_compile (const char *arg) |
| 442 | { |
Paul Jakma | 96d1060 | 2016-07-01 14:23:45 +0100 | [diff] [blame] | 443 | route_tag_t *tag; |
| 444 | route_tag_t tmp; |
Piotr Chytła | 2b2e38c | 2015-12-01 10:10:41 -0500 | [diff] [blame] | 445 | |
| 446 | /* tag value shoud be integer. */ |
| 447 | if (! all_digit (arg)) |
| 448 | return NULL; |
| 449 | |
| 450 | tmp = atoi(arg); |
| 451 | if (tmp < 1) |
| 452 | return NULL; |
| 453 | |
| 454 | tag = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_short)); |
| 455 | |
| 456 | if (!tag) |
| 457 | return tag; |
| 458 | |
| 459 | *tag = tmp; |
| 460 | |
| 461 | return tag; |
| 462 | } |
| 463 | |
| 464 | /* Free route map's compiled 'match tag' value. */ |
| 465 | static void |
| 466 | route_match_tag_free (void *rule) |
| 467 | { |
| 468 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); |
| 469 | } |
| 470 | |
| 471 | /* Route map commands for tag matching. */ |
| 472 | struct route_map_rule_cmd route_match_tag_cmd = |
| 473 | { |
| 474 | "tag", |
| 475 | route_match_tag, |
| 476 | route_match_tag_compile, |
| 477 | route_match_tag_free, |
| 478 | }; |
| 479 | |
| 480 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 481 | /* `set metric METRIC' */ |
| 482 | /* Set metric to attribute. */ |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 483 | static route_map_result_t |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 484 | route_set_metric (void *rule, struct prefix *prefix, |
| 485 | route_map_object_t type, void *object) |
| 486 | { |
| 487 | u_int32_t *metric; |
| 488 | struct external_info *ei; |
| 489 | |
| 490 | if (type == RMAP_OSPF) |
| 491 | { |
| 492 | /* Fetch routemap's rule information. */ |
| 493 | metric = rule; |
| 494 | ei = object; |
| 495 | |
| 496 | /* Set metric out value. */ |
| 497 | ei->route_map_set.metric = *metric; |
| 498 | } |
| 499 | return RMAP_OKAY; |
| 500 | } |
| 501 | |
| 502 | /* set metric compilation. */ |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 503 | static void * |
paul | 6c83567 | 2004-10-11 11:00:30 +0000 | [diff] [blame] | 504 | route_set_metric_compile (const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 505 | { |
| 506 | u_int32_t *metric; |
Andrew Certain | fbc043a | 2012-12-04 12:54:18 -0800 | [diff] [blame] | 507 | int32_t ret; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 508 | |
Daniel Walton | c7f25b9 | 2015-05-19 17:47:22 -0700 | [diff] [blame] | 509 | /* OSPF doesn't support the +/- in |
| 510 | set metric <+/-metric> check |
| 511 | Ignore the +/- component */ |
| 512 | if (! all_digit (arg)) |
| 513 | { |
| 514 | if ((strncmp (arg, "+", 1) == 0 || strncmp (arg, "-", 1) == 0) && |
| 515 | all_digit (arg+1)) |
| 516 | { |
| 517 | zlog_warn ("OSPF does not support 'set metric +/-'"); |
| 518 | arg++; |
| 519 | } |
| 520 | else |
| 521 | return NULL; |
| 522 | } |
| 523 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 524 | metric = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t)); |
Andrew Certain | fbc043a | 2012-12-04 12:54:18 -0800 | [diff] [blame] | 525 | ret = atoi (arg); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 526 | |
Andrew Certain | fbc043a | 2012-12-04 12:54:18 -0800 | [diff] [blame] | 527 | if (ret >= 0) |
| 528 | { |
| 529 | *metric = (u_int32_t)ret; |
| 530 | return metric; |
| 531 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 532 | |
| 533 | XFREE (MTYPE_ROUTE_MAP_COMPILED, metric); |
| 534 | return NULL; |
| 535 | } |
| 536 | |
| 537 | /* Free route map's compiled `set metric' value. */ |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 538 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 539 | route_set_metric_free (void *rule) |
| 540 | { |
| 541 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); |
| 542 | } |
| 543 | |
| 544 | /* Set metric rule structure. */ |
| 545 | struct route_map_rule_cmd route_set_metric_cmd = |
| 546 | { |
| 547 | "metric", |
| 548 | route_set_metric, |
| 549 | route_set_metric_compile, |
| 550 | route_set_metric_free, |
| 551 | }; |
| 552 | |
| 553 | /* `set metric-type TYPE' */ |
| 554 | /* Set metric-type to attribute. */ |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 555 | static route_map_result_t |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 556 | route_set_metric_type (void *rule, struct prefix *prefix, |
| 557 | route_map_object_t type, void *object) |
| 558 | { |
| 559 | u_int32_t *metric_type; |
| 560 | struct external_info *ei; |
| 561 | |
| 562 | if (type == RMAP_OSPF) |
| 563 | { |
| 564 | /* Fetch routemap's rule information. */ |
| 565 | metric_type = rule; |
| 566 | ei = object; |
| 567 | |
| 568 | /* Set metric out value. */ |
| 569 | ei->route_map_set.metric_type = *metric_type; |
| 570 | } |
| 571 | return RMAP_OKAY; |
| 572 | } |
| 573 | |
| 574 | /* set metric-type compilation. */ |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 575 | static void * |
paul | 6c83567 | 2004-10-11 11:00:30 +0000 | [diff] [blame] | 576 | route_set_metric_type_compile (const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 577 | { |
| 578 | u_int32_t *metric_type; |
| 579 | |
| 580 | metric_type = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t)); |
| 581 | if (strcmp (arg, "type-1") == 0) |
| 582 | *metric_type = EXTERNAL_METRIC_TYPE_1; |
| 583 | else if (strcmp (arg, "type-2") == 0) |
| 584 | *metric_type = EXTERNAL_METRIC_TYPE_2; |
| 585 | |
| 586 | if (*metric_type == EXTERNAL_METRIC_TYPE_1 || |
| 587 | *metric_type == EXTERNAL_METRIC_TYPE_2) |
| 588 | return metric_type; |
| 589 | |
| 590 | XFREE (MTYPE_ROUTE_MAP_COMPILED, metric_type); |
| 591 | return NULL; |
| 592 | } |
| 593 | |
| 594 | /* Free route map's compiled `set metric-type' value. */ |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 595 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 596 | route_set_metric_type_free (void *rule) |
| 597 | { |
| 598 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); |
| 599 | } |
| 600 | |
| 601 | /* Set metric rule structure. */ |
| 602 | struct route_map_rule_cmd route_set_metric_type_cmd = |
| 603 | { |
| 604 | "metric-type", |
| 605 | route_set_metric_type, |
| 606 | route_set_metric_type_compile, |
| 607 | route_set_metric_type_free, |
| 608 | }; |
| 609 | |
Piotr Chytła | 2b2e38c | 2015-12-01 10:10:41 -0500 | [diff] [blame] | 610 | static route_map_result_t |
| 611 | route_set_tag (void *rule, struct prefix *prefix, |
| 612 | route_map_object_t type, void *object) |
| 613 | { |
Paul Jakma | 96d1060 | 2016-07-01 14:23:45 +0100 | [diff] [blame] | 614 | route_tag_t *tag; |
Piotr Chytła | 2b2e38c | 2015-12-01 10:10:41 -0500 | [diff] [blame] | 615 | struct external_info *ei; |
| 616 | |
| 617 | if (type == RMAP_OSPF) |
| 618 | { |
| 619 | tag = rule; |
| 620 | ei = object; |
| 621 | |
| 622 | /* Set tag value */ |
| 623 | ei->tag=*tag; |
| 624 | } |
| 625 | |
| 626 | return RMAP_OKAY; |
| 627 | } |
| 628 | |
| 629 | /* Route map `tag' compile function. Given string is converted to u_short. */ |
| 630 | static void * |
| 631 | route_set_tag_compile (const char *arg) |
| 632 | { |
Paul Jakma | 96d1060 | 2016-07-01 14:23:45 +0100 | [diff] [blame] | 633 | route_tag_t *tag; |
| 634 | route_tag_t tmp; |
Piotr Chytła | 2b2e38c | 2015-12-01 10:10:41 -0500 | [diff] [blame] | 635 | |
| 636 | /* tag value shoud be integer. */ |
| 637 | if (! all_digit (arg)) |
| 638 | return NULL; |
| 639 | |
| 640 | tmp = atoi(arg); |
| 641 | |
| 642 | if (tmp < 1) |
| 643 | return NULL; |
| 644 | |
| 645 | tag = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_short)); |
| 646 | |
| 647 | if (!tag) |
| 648 | return tag; |
| 649 | |
| 650 | *tag = tmp; |
| 651 | |
| 652 | return tag; |
| 653 | } |
| 654 | |
| 655 | /* Free route map's tag value. */ |
| 656 | static void |
| 657 | route_set_tag_free (void *rule) |
| 658 | { |
| 659 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); |
| 660 | } |
| 661 | |
| 662 | /* Route map commands for tag set. */ |
| 663 | struct route_map_rule_cmd route_set_tag_cmd = |
| 664 | { |
| 665 | "tag", |
| 666 | route_set_tag, |
| 667 | route_set_tag_compile, |
| 668 | route_set_tag_free, |
| 669 | }; |
| 670 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 671 | DEFUN (match_ip_nexthop, |
| 672 | match_ip_nexthop_cmd, |
| 673 | "match ip next-hop (<1-199>|<1300-2699>|WORD)", |
| 674 | MATCH_STR |
| 675 | IP_STR |
| 676 | "Match next-hop address of route\n" |
| 677 | "IP access-list number\n" |
| 678 | "IP access-list number (expanded range)\n" |
| 679 | "IP access-list name\n") |
| 680 | { |
| 681 | return ospf_route_match_add (vty, vty->index, "ip next-hop", argv[0]); |
| 682 | } |
| 683 | |
| 684 | DEFUN (no_match_ip_nexthop, |
| 685 | no_match_ip_nexthop_cmd, |
| 686 | "no match ip next-hop", |
| 687 | NO_STR |
| 688 | MATCH_STR |
| 689 | IP_STR |
| 690 | "Match next-hop address of route\n") |
| 691 | { |
| 692 | if (argc == 0) |
| 693 | return ospf_route_match_delete (vty, vty->index, "ip next-hop", NULL); |
| 694 | |
| 695 | return ospf_route_match_delete (vty, vty->index, "ip next-hop", argv[0]); |
| 696 | } |
| 697 | |
| 698 | ALIAS (no_match_ip_nexthop, |
| 699 | no_match_ip_nexthop_val_cmd, |
| 700 | "no match ip next-hop (<1-199>|<1300-2699>|WORD)", |
| 701 | NO_STR |
| 702 | MATCH_STR |
| 703 | IP_STR |
| 704 | "Match next-hop address of route\n" |
| 705 | "IP access-list number\n" |
| 706 | "IP access-list number (expanded range)\n" |
| 707 | "IP access-list name\n") |
| 708 | |
| 709 | DEFUN (match_ip_next_hop_prefix_list, |
| 710 | match_ip_next_hop_prefix_list_cmd, |
| 711 | "match ip next-hop prefix-list WORD", |
| 712 | MATCH_STR |
| 713 | IP_STR |
| 714 | "Match next-hop address of route\n" |
| 715 | "Match entries of prefix-lists\n" |
| 716 | "IP prefix-list name\n") |
| 717 | { |
| 718 | return ospf_route_match_add (vty, vty->index, "ip next-hop prefix-list", |
| 719 | argv[0]); |
| 720 | } |
| 721 | |
| 722 | DEFUN (no_match_ip_next_hop_prefix_list, |
| 723 | no_match_ip_next_hop_prefix_list_cmd, |
| 724 | "no match ip next-hop prefix-list", |
| 725 | NO_STR |
| 726 | MATCH_STR |
| 727 | IP_STR |
| 728 | "Match next-hop address of route\n" |
| 729 | "Match entries of prefix-lists\n") |
| 730 | { |
| 731 | if (argc == 0) |
| 732 | return ospf_route_match_delete (vty, vty->index, "ip next-hop prefix-list", |
| 733 | NULL); |
| 734 | return ospf_route_match_delete (vty, vty->index, "ip next-hop prefix-list", |
| 735 | argv[0]); |
| 736 | } |
| 737 | |
| 738 | ALIAS (no_match_ip_next_hop_prefix_list, |
| 739 | no_match_ip_next_hop_prefix_list_val_cmd, |
| 740 | "no match ip next-hop prefix-list WORD", |
| 741 | NO_STR |
| 742 | MATCH_STR |
| 743 | IP_STR |
| 744 | "Match next-hop address of route\n" |
| 745 | "Match entries of prefix-lists\n" |
| 746 | "IP prefix-list name\n") |
| 747 | |
| 748 | DEFUN (match_ip_address, |
| 749 | match_ip_address_cmd, |
| 750 | "match ip address (<1-199>|<1300-2699>|WORD)", |
| 751 | MATCH_STR |
| 752 | IP_STR |
| 753 | "Match address of route\n" |
| 754 | "IP access-list number\n" |
| 755 | "IP access-list number (expanded range)\n" |
| 756 | "IP access-list name\n") |
| 757 | { |
| 758 | return ospf_route_match_add (vty, vty->index, "ip address", argv[0]); |
| 759 | } |
| 760 | |
| 761 | DEFUN (no_match_ip_address, |
| 762 | no_match_ip_address_cmd, |
| 763 | "no match ip address", |
| 764 | NO_STR |
| 765 | MATCH_STR |
| 766 | IP_STR |
| 767 | "Match address of route\n") |
| 768 | { |
| 769 | if (argc == 0) |
| 770 | return ospf_route_match_delete (vty, vty->index, "ip address", NULL); |
| 771 | |
| 772 | return ospf_route_match_delete (vty, vty->index, "ip address", argv[0]); |
| 773 | } |
| 774 | |
| 775 | ALIAS (no_match_ip_address, |
| 776 | no_match_ip_address_val_cmd, |
| 777 | "no match ip address (<1-199>|<1300-2699>|WORD)", |
| 778 | NO_STR |
| 779 | MATCH_STR |
| 780 | IP_STR |
| 781 | "Match address of route\n" |
| 782 | "IP access-list number\n" |
| 783 | "IP access-list number (expanded range)\n" |
| 784 | "IP access-list name\n") |
| 785 | |
| 786 | DEFUN (match_ip_address_prefix_list, |
| 787 | match_ip_address_prefix_list_cmd, |
| 788 | "match ip address prefix-list WORD", |
| 789 | MATCH_STR |
| 790 | IP_STR |
| 791 | "Match address of route\n" |
| 792 | "Match entries of prefix-lists\n" |
| 793 | "IP prefix-list name\n") |
| 794 | { |
| 795 | return ospf_route_match_add (vty, vty->index, "ip address prefix-list", |
| 796 | argv[0]); |
| 797 | } |
| 798 | |
| 799 | DEFUN (no_match_ip_address_prefix_list, |
| 800 | no_match_ip_address_prefix_list_cmd, |
| 801 | "no match ip address prefix-list", |
| 802 | NO_STR |
| 803 | MATCH_STR |
| 804 | IP_STR |
| 805 | "Match address of route\n" |
| 806 | "Match entries of prefix-lists\n") |
| 807 | { |
| 808 | if (argc == 0) |
| 809 | return ospf_route_match_delete (vty, vty->index, "ip address prefix-list", |
| 810 | NULL); |
| 811 | return ospf_route_match_delete (vty, vty->index, "ip address prefix-list", |
| 812 | argv[0]); |
| 813 | } |
| 814 | |
| 815 | ALIAS (no_match_ip_address_prefix_list, |
| 816 | no_match_ip_address_prefix_list_val_cmd, |
| 817 | "no match ip address prefix-list WORD", |
| 818 | NO_STR |
| 819 | MATCH_STR |
| 820 | IP_STR |
| 821 | "Match address of route\n" |
| 822 | "Match entries of prefix-lists\n" |
| 823 | "IP prefix-list name\n") |
| 824 | |
| 825 | DEFUN (match_interface, |
| 826 | match_interface_cmd, |
| 827 | "match interface WORD", |
| 828 | MATCH_STR |
| 829 | "Match first hop interface of route\n" |
| 830 | "Interface name\n") |
| 831 | { |
| 832 | return ospf_route_match_add (vty, vty->index, "interface", argv[0]); |
| 833 | } |
| 834 | |
| 835 | DEFUN (no_match_interface, |
| 836 | no_match_interface_cmd, |
| 837 | "no match interface", |
| 838 | NO_STR |
| 839 | MATCH_STR |
| 840 | "Match first hop interface of route\n") |
| 841 | { |
| 842 | if (argc == 0) |
| 843 | return ospf_route_match_delete (vty, vty->index, "interface", NULL); |
| 844 | |
| 845 | return ospf_route_match_delete (vty, vty->index, "interface", argv[0]); |
| 846 | } |
| 847 | |
| 848 | ALIAS (no_match_interface, |
| 849 | no_match_interface_val_cmd, |
| 850 | "no match interface WORD", |
| 851 | NO_STR |
| 852 | MATCH_STR |
| 853 | "Match first hop interface of route\n" |
| 854 | "Interface name\n") |
| 855 | |
Piotr Chytła | 2b2e38c | 2015-12-01 10:10:41 -0500 | [diff] [blame] | 856 | DEFUN (match_tag, |
| 857 | match_tag_cmd, |
| 858 | "match tag <1-65535>", |
| 859 | MATCH_STR |
| 860 | "Match tag of route\n" |
| 861 | "Tag value\n") |
| 862 | { |
| 863 | return ospf_route_match_add (vty, vty->index, "tag", argv[0]); |
| 864 | } |
| 865 | |
| 866 | DEFUN (no_match_tag, |
| 867 | no_match_tag_cmd, |
| 868 | "no match tag", |
| 869 | NO_STR |
| 870 | MATCH_STR |
| 871 | "Match tag of route\n") |
| 872 | { |
| 873 | if (argc == 0) |
| 874 | return ospf_route_match_delete (vty, vty->index, "tag", NULL); |
| 875 | |
| 876 | return ospf_route_match_delete (vty, vty->index, "tag", argv[0]); |
| 877 | } |
| 878 | |
| 879 | ALIAS (no_match_tag, |
| 880 | no_match_tag_val_cmd, |
| 881 | "no match tag <1-65535>", |
| 882 | NO_STR |
| 883 | MATCH_STR |
| 884 | "Match tag of route\n" |
| 885 | "Tag value\n") |
| 886 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 887 | DEFUN (set_metric, |
| 888 | set_metric_cmd, |
| 889 | "set metric <0-4294967295>", |
| 890 | SET_STR |
| 891 | "Metric value for destination routing protocol\n" |
| 892 | "Metric value\n") |
| 893 | { |
| 894 | return ospf_route_set_add (vty, vty->index, "metric", argv[0]); |
| 895 | } |
| 896 | |
| 897 | DEFUN (no_set_metric, |
| 898 | no_set_metric_cmd, |
| 899 | "no set metric", |
| 900 | NO_STR |
| 901 | SET_STR |
| 902 | "Metric value for destination routing protocol\n") |
| 903 | { |
| 904 | if (argc == 0) |
| 905 | return ospf_route_set_delete (vty, vty->index, "metric", NULL); |
| 906 | |
| 907 | return ospf_route_set_delete (vty, vty->index, "metric", argv[0]); |
| 908 | } |
| 909 | |
| 910 | ALIAS (no_set_metric, |
| 911 | no_set_metric_val_cmd, |
| 912 | "no set metric <0-4294967295>", |
| 913 | NO_STR |
| 914 | SET_STR |
| 915 | "Metric value for destination routing protocol\n" |
| 916 | "Metric value\n") |
| 917 | |
| 918 | DEFUN (set_metric_type, |
| 919 | set_metric_type_cmd, |
| 920 | "set metric-type (type-1|type-2)", |
| 921 | SET_STR |
| 922 | "Type of metric for destination routing protocol\n" |
paul | 73ffb25 | 2003-04-19 15:49:49 +0000 | [diff] [blame] | 923 | "OSPF[6] external type 1 metric\n" |
| 924 | "OSPF[6] external type 2 metric\n") |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 925 | { |
| 926 | if (strcmp (argv[0], "1") == 0) |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 927 | return ospf_route_set_add (vty, vty->index, "metric-type", "type-1"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 928 | if (strcmp (argv[0], "2") == 0) |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 929 | return ospf_route_set_add (vty, vty->index, "metric-type", "type-2"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 930 | |
| 931 | return ospf_route_set_add (vty, vty->index, "metric-type", argv[0]); |
| 932 | } |
| 933 | |
| 934 | DEFUN (no_set_metric_type, |
| 935 | no_set_metric_type_cmd, |
| 936 | "no set metric-type", |
| 937 | NO_STR |
| 938 | SET_STR |
| 939 | "Type of metric for destination routing protocol\n") |
| 940 | { |
| 941 | if (argc == 0) |
| 942 | return ospf_route_set_delete (vty, vty->index, "metric-type", NULL); |
| 943 | |
| 944 | return ospf_route_set_delete (vty, vty->index, "metric-type", argv[0]); |
| 945 | } |
| 946 | |
| 947 | ALIAS (no_set_metric_type, |
| 948 | no_set_metric_type_val_cmd, |
| 949 | "no set metric-type (type-1|type-2)", |
| 950 | NO_STR |
| 951 | SET_STR |
| 952 | "Type of metric for destination routing protocol\n" |
paul | 73ffb25 | 2003-04-19 15:49:49 +0000 | [diff] [blame] | 953 | "OSPF[6] external type 1 metric\n" |
| 954 | "OSPF[6] external type 2 metric\n") |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 955 | |
Piotr Chytła | 2b2e38c | 2015-12-01 10:10:41 -0500 | [diff] [blame] | 956 | DEFUN (set_tag, |
| 957 | set_tag_cmd, |
| 958 | "set tag <1-65535>", |
| 959 | SET_STR |
| 960 | "Tag value for routing protocol\n" |
| 961 | "Tag value\n") |
| 962 | { |
| 963 | return ospf_route_set_add (vty, vty->index, "tag", argv[0]); |
| 964 | } |
| 965 | |
| 966 | DEFUN (no_set_tag, |
| 967 | no_set_tag_cmd, |
| 968 | "no set tag", |
| 969 | NO_STR |
| 970 | SET_STR |
| 971 | "Tag value for routing protocol\n") |
| 972 | { |
| 973 | if (argc == 0) |
| 974 | ospf_route_set_delete(vty, vty->index, "tag", NULL); |
| 975 | |
| 976 | return ospf_route_set_delete (vty, vty->index, "tag", argv[0]); |
| 977 | } |
| 978 | |
| 979 | ALIAS (no_set_tag, |
| 980 | no_set_tag_val_cmd, |
| 981 | "no set tag <1-65535>", |
| 982 | NO_STR |
| 983 | SET_STR |
| 984 | "Tag value for routing protocol\n" |
| 985 | "Tag value\n") |
| 986 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 987 | /* Route-map init */ |
| 988 | void |
| 989 | ospf_route_map_init (void) |
| 990 | { |
| 991 | route_map_init (); |
| 992 | route_map_init_vty (); |
| 993 | |
| 994 | route_map_add_hook (ospf_route_map_update); |
| 995 | route_map_delete_hook (ospf_route_map_update); |
| 996 | route_map_event_hook (ospf_route_map_event); |
| 997 | |
| 998 | route_map_install_match (&route_match_ip_nexthop_cmd); |
| 999 | route_map_install_match (&route_match_ip_next_hop_prefix_list_cmd); |
| 1000 | route_map_install_match (&route_match_ip_address_cmd); |
| 1001 | route_map_install_match (&route_match_ip_address_prefix_list_cmd); |
| 1002 | route_map_install_match (&route_match_interface_cmd); |
Piotr Chytła | 2b2e38c | 2015-12-01 10:10:41 -0500 | [diff] [blame] | 1003 | route_map_install_match (&route_match_tag_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1004 | |
| 1005 | route_map_install_set (&route_set_metric_cmd); |
| 1006 | route_map_install_set (&route_set_metric_type_cmd); |
Piotr Chytła | 2b2e38c | 2015-12-01 10:10:41 -0500 | [diff] [blame] | 1007 | route_map_install_set (&route_set_tag_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1008 | |
| 1009 | install_element (RMAP_NODE, &match_ip_nexthop_cmd); |
| 1010 | install_element (RMAP_NODE, &no_match_ip_nexthop_cmd); |
| 1011 | install_element (RMAP_NODE, &no_match_ip_nexthop_val_cmd); |
| 1012 | install_element (RMAP_NODE, &match_ip_next_hop_prefix_list_cmd); |
| 1013 | install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_cmd); |
| 1014 | install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_val_cmd); |
| 1015 | install_element (RMAP_NODE, &match_ip_address_cmd); |
| 1016 | install_element (RMAP_NODE, &no_match_ip_address_cmd); |
| 1017 | install_element (RMAP_NODE, &no_match_ip_address_val_cmd); |
| 1018 | install_element (RMAP_NODE, &match_ip_address_prefix_list_cmd); |
| 1019 | install_element (RMAP_NODE, &no_match_ip_address_prefix_list_cmd); |
| 1020 | install_element (RMAP_NODE, &no_match_ip_address_prefix_list_val_cmd); |
| 1021 | install_element (RMAP_NODE, &match_interface_cmd); |
| 1022 | install_element (RMAP_NODE, &no_match_interface_cmd); |
| 1023 | install_element (RMAP_NODE, &no_match_interface_val_cmd); |
Piotr Chytła | 2b2e38c | 2015-12-01 10:10:41 -0500 | [diff] [blame] | 1024 | install_element (RMAP_NODE, &match_tag_cmd); |
| 1025 | install_element (RMAP_NODE, &no_match_tag_cmd); |
| 1026 | install_element (RMAP_NODE, &no_match_tag_val_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1027 | |
| 1028 | install_element (RMAP_NODE, &set_metric_cmd); |
| 1029 | install_element (RMAP_NODE, &no_set_metric_cmd); |
| 1030 | install_element (RMAP_NODE, &no_set_metric_val_cmd); |
| 1031 | install_element (RMAP_NODE, &set_metric_type_cmd); |
| 1032 | install_element (RMAP_NODE, &no_set_metric_type_cmd); |
| 1033 | install_element (RMAP_NODE, &no_set_metric_type_val_cmd); |
Piotr Chytła | 2b2e38c | 2015-12-01 10:10:41 -0500 | [diff] [blame] | 1034 | install_element (RMAP_NODE, &set_tag_cmd); |
| 1035 | install_element (RMAP_NODE, &no_set_tag_cmd); |
| 1036 | install_element (RMAP_NODE, &no_set_tag_val_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1037 | } |