paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* Route map function of bgpd. |
| 2 | Copyright (C) 1998, 1999 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 Free |
| 18 | Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 19 | 02111-1307, USA. */ |
| 20 | |
| 21 | #include <zebra.h> |
| 22 | |
| 23 | #include "prefix.h" |
| 24 | #include "filter.h" |
| 25 | #include "routemap.h" |
| 26 | #include "command.h" |
| 27 | #include "linklist.h" |
| 28 | #include "plist.h" |
| 29 | #include "memory.h" |
| 30 | #include "log.h" |
Jeremy Jackson | 25f4588 | 2009-01-12 16:06:12 -0500 | [diff] [blame] | 31 | #ifdef HAVE_LIBPCREPOSIX |
| 32 | # include <pcreposix.h> |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 33 | #else |
Jeremy Jackson | 25f4588 | 2009-01-12 16:06:12 -0500 | [diff] [blame] | 34 | # ifdef HAVE_GNU_REGEX |
| 35 | # include <regex.h> |
| 36 | # else |
| 37 | # include "regex-gnu.h" |
| 38 | # endif /* HAVE_GNU_REGEX */ |
| 39 | #endif /* HAVE_LIBPCREPOSIX */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 40 | #include "buffer.h" |
| 41 | #include "sockunion.h" |
| 42 | |
| 43 | #include "bgpd/bgpd.h" |
| 44 | #include "bgpd/bgp_table.h" |
| 45 | #include "bgpd/bgp_attr.h" |
| 46 | #include "bgpd/bgp_aspath.h" |
| 47 | #include "bgpd/bgp_route.h" |
| 48 | #include "bgpd/bgp_regex.h" |
| 49 | #include "bgpd/bgp_community.h" |
| 50 | #include "bgpd/bgp_clist.h" |
| 51 | #include "bgpd/bgp_filter.h" |
| 52 | #include "bgpd/bgp_mplsvpn.h" |
| 53 | #include "bgpd/bgp_ecommunity.h" |
Paul Jakma | 320da87 | 2008-07-02 13:40:33 +0000 | [diff] [blame] | 54 | #include "bgpd/bgp_vty.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 55 | |
| 56 | /* Memo of route-map commands. |
| 57 | |
| 58 | o Cisco route-map |
| 59 | |
| 60 | match as-path : Done |
| 61 | community : Done |
| 62 | interface : Not yet |
| 63 | ip address : Done |
| 64 | ip next-hop : Done |
hasso | c1643bb | 2005-02-02 16:43:17 +0000 | [diff] [blame] | 65 | ip route-source : Done |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 66 | ip prefix-list : Done |
| 67 | ipv6 address : Done |
| 68 | ipv6 next-hop : Done |
| 69 | ipv6 route-source: (This will not be implemented by bgpd) |
| 70 | ipv6 prefix-list : Done |
| 71 | length : (This will not be implemented by bgpd) |
| 72 | metric : Done |
| 73 | route-type : (This will not be implemented by bgpd) |
| 74 | tag : (This will not be implemented by bgpd) |
| 75 | |
| 76 | set as-path prepend : Done |
| 77 | as-path tag : Not yet |
| 78 | automatic-tag : (This will not be implemented by bgpd) |
| 79 | community : Done |
| 80 | comm-list : Not yet |
| 81 | dampning : Not yet |
| 82 | default : (This will not be implemented by bgpd) |
| 83 | interface : (This will not be implemented by bgpd) |
| 84 | ip default : (This will not be implemented by bgpd) |
| 85 | ip next-hop : Done |
| 86 | ip precedence : (This will not be implemented by bgpd) |
| 87 | ip tos : (This will not be implemented by bgpd) |
| 88 | level : (This will not be implemented by bgpd) |
| 89 | local-preference : Done |
| 90 | metric : Done |
| 91 | metric-type : Not yet |
| 92 | origin : Done |
| 93 | tag : (This will not be implemented by bgpd) |
| 94 | weight : Done |
| 95 | |
| 96 | o Local extention |
| 97 | |
| 98 | set ipv6 next-hop global: Done |
| 99 | set ipv6 next-hop local : Done |
Denis Ovsienko | 841f7a5 | 2008-04-10 11:47:45 +0000 | [diff] [blame] | 100 | set as-path exclude : Done |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 101 | |
| 102 | */ |
| 103 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 104 | /* 'match peer (A.B.C.D|X:X::X:X)' */ |
| 105 | |
| 106 | /* Compares the peer specified in the 'match peer' clause with the peer |
| 107 | received in bgp_info->peer. If it is the same, or if the peer structure |
| 108 | received is a peer_group containing it, returns RMAP_MATCH. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 109 | static route_map_result_t |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 110 | route_match_peer (void *rule, struct prefix *prefix, route_map_object_t type, |
| 111 | void *object) |
| 112 | { |
| 113 | union sockunion *su; |
| 114 | union sockunion *su2; |
| 115 | struct peer_group *group; |
| 116 | struct peer *peer; |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 117 | struct listnode *node, *nnode; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 118 | |
| 119 | if (type == RMAP_BGP) |
| 120 | { |
| 121 | su = rule; |
| 122 | peer = ((struct bgp_info *) object)->peer; |
| 123 | |
| 124 | if ( ! CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT) && |
| 125 | ! CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_EXPORT) ) |
| 126 | return RMAP_NOMATCH; |
| 127 | |
| 128 | /* If su='0.0.0.0' (command 'match peer local'), and it's a NETWORK, |
| 129 | REDISTRIBUTE or DEFAULT_GENERATED route => return RMAP_MATCH */ |
| 130 | su2 = sockunion_str2su ("0.0.0.0"); |
| 131 | if ( sockunion_same (su, su2) ) |
| 132 | { |
paul | 22db9de | 2005-05-19 01:50:11 +0000 | [diff] [blame] | 133 | int ret; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 134 | if ( CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_NETWORK) || |
| 135 | CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE) || |
| 136 | CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_DEFAULT)) |
paul | 22db9de | 2005-05-19 01:50:11 +0000 | [diff] [blame] | 137 | ret = RMAP_MATCH; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 138 | else |
paul | 22db9de | 2005-05-19 01:50:11 +0000 | [diff] [blame] | 139 | ret = RMAP_NOMATCH; |
| 140 | |
| 141 | sockunion_free (su2); |
| 142 | return ret; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 143 | } |
paul | 22db9de | 2005-05-19 01:50:11 +0000 | [diff] [blame] | 144 | sockunion_free (su2); |
| 145 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 146 | if (! CHECK_FLAG (peer->sflags, PEER_STATUS_GROUP)) |
| 147 | { |
| 148 | if (sockunion_same (su, &peer->su)) |
| 149 | return RMAP_MATCH; |
| 150 | |
| 151 | return RMAP_NOMATCH; |
| 152 | } |
| 153 | else |
| 154 | { |
| 155 | group = peer->group; |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 156 | for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer)) |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 157 | { |
| 158 | if (sockunion_same (su, &peer->su)) |
| 159 | return RMAP_MATCH; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 160 | } |
Paul Jakma | 30a2231 | 2008-08-15 14:05:22 +0100 | [diff] [blame] | 161 | return RMAP_NOMATCH; |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 162 | } |
| 163 | } |
| 164 | return RMAP_NOMATCH; |
| 165 | } |
| 166 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 167 | static void * |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 168 | route_match_peer_compile (const char *arg) |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 169 | { |
| 170 | union sockunion *su; |
| 171 | int ret; |
| 172 | |
| 173 | su = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (union sockunion)); |
| 174 | |
| 175 | ret = str2sockunion ( (arg)? arg : "0.0.0.0", su); |
| 176 | if (ret < 0) { |
| 177 | XFREE (MTYPE_ROUTE_MAP_COMPILED, su); |
| 178 | return NULL; |
| 179 | } |
| 180 | |
| 181 | return su; |
| 182 | } |
| 183 | |
| 184 | /* Free route map's compiled `ip address' value. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 185 | static void |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 186 | route_match_peer_free (void *rule) |
| 187 | { |
| 188 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); |
| 189 | } |
| 190 | |
| 191 | /* Route map commands for ip address matching. */ |
| 192 | struct route_map_rule_cmd route_match_peer_cmd = |
| 193 | { |
| 194 | "peer", |
| 195 | route_match_peer, |
| 196 | route_match_peer_compile, |
| 197 | route_match_peer_free |
| 198 | }; |
| 199 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 200 | /* `match ip address IP_ACCESS_LIST' */ |
| 201 | |
| 202 | /* Match function should return 1 if match is success else return |
| 203 | zero. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 204 | static route_map_result_t |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 205 | route_match_ip_address (void *rule, struct prefix *prefix, |
| 206 | route_map_object_t type, void *object) |
| 207 | { |
| 208 | struct access_list *alist; |
| 209 | /* struct prefix_ipv4 match; */ |
| 210 | |
| 211 | if (type == RMAP_BGP) |
| 212 | { |
| 213 | alist = access_list_lookup (AFI_IP, (char *) rule); |
| 214 | if (alist == NULL) |
| 215 | return RMAP_NOMATCH; |
| 216 | |
| 217 | return (access_list_apply (alist, prefix) == FILTER_DENY ? |
| 218 | RMAP_NOMATCH : RMAP_MATCH); |
| 219 | } |
| 220 | return RMAP_NOMATCH; |
| 221 | } |
| 222 | |
| 223 | /* Route map `ip address' match statement. `arg' should be |
| 224 | access-list name. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 225 | static void * |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 226 | route_match_ip_address_compile (const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 227 | { |
| 228 | return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg); |
| 229 | } |
| 230 | |
| 231 | /* Free route map's compiled `ip address' value. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 232 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 233 | route_match_ip_address_free (void *rule) |
| 234 | { |
| 235 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); |
| 236 | } |
| 237 | |
| 238 | /* Route map commands for ip address matching. */ |
| 239 | struct route_map_rule_cmd route_match_ip_address_cmd = |
| 240 | { |
| 241 | "ip address", |
| 242 | route_match_ip_address, |
| 243 | route_match_ip_address_compile, |
| 244 | route_match_ip_address_free |
| 245 | }; |
| 246 | |
| 247 | /* `match ip next-hop IP_ADDRESS' */ |
| 248 | |
| 249 | /* Match function return 1 if match is success else return zero. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 250 | static route_map_result_t |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 251 | route_match_ip_next_hop (void *rule, struct prefix *prefix, |
| 252 | route_map_object_t type, void *object) |
| 253 | { |
| 254 | struct access_list *alist; |
| 255 | struct bgp_info *bgp_info; |
| 256 | struct prefix_ipv4 p; |
| 257 | |
| 258 | if (type == RMAP_BGP) |
| 259 | { |
| 260 | bgp_info = object; |
| 261 | p.family = AF_INET; |
| 262 | p.prefix = bgp_info->attr->nexthop; |
| 263 | p.prefixlen = IPV4_MAX_BITLEN; |
| 264 | |
| 265 | alist = access_list_lookup (AFI_IP, (char *) rule); |
| 266 | if (alist == NULL) |
| 267 | return RMAP_NOMATCH; |
| 268 | |
| 269 | return (access_list_apply (alist, &p) == FILTER_DENY ? |
| 270 | RMAP_NOMATCH : RMAP_MATCH); |
| 271 | } |
| 272 | return RMAP_NOMATCH; |
| 273 | } |
| 274 | |
| 275 | /* Route map `ip next-hop' match statement. `arg' is |
| 276 | access-list name. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 277 | static void * |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 278 | route_match_ip_next_hop_compile (const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 279 | { |
| 280 | return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg); |
| 281 | } |
| 282 | |
| 283 | /* Free route map's compiled `ip address' value. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 284 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 285 | route_match_ip_next_hop_free (void *rule) |
| 286 | { |
| 287 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); |
| 288 | } |
| 289 | |
| 290 | /* Route map commands for ip next-hop matching. */ |
| 291 | struct route_map_rule_cmd route_match_ip_next_hop_cmd = |
| 292 | { |
| 293 | "ip next-hop", |
| 294 | route_match_ip_next_hop, |
| 295 | route_match_ip_next_hop_compile, |
| 296 | route_match_ip_next_hop_free |
| 297 | }; |
| 298 | |
hasso | c1643bb | 2005-02-02 16:43:17 +0000 | [diff] [blame] | 299 | /* `match ip route-source ACCESS-LIST' */ |
| 300 | |
| 301 | /* Match function return 1 if match is success else return zero. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 302 | static route_map_result_t |
hasso | c1643bb | 2005-02-02 16:43:17 +0000 | [diff] [blame] | 303 | route_match_ip_route_source (void *rule, struct prefix *prefix, |
| 304 | route_map_object_t type, void *object) |
| 305 | { |
| 306 | struct access_list *alist; |
| 307 | struct bgp_info *bgp_info; |
| 308 | struct peer *peer; |
| 309 | struct prefix_ipv4 p; |
| 310 | |
| 311 | if (type == RMAP_BGP) |
| 312 | { |
| 313 | bgp_info = object; |
| 314 | peer = bgp_info->peer; |
| 315 | |
| 316 | if (! peer || sockunion_family (&peer->su) != AF_INET) |
| 317 | return RMAP_NOMATCH; |
| 318 | |
| 319 | p.family = AF_INET; |
| 320 | p.prefix = peer->su.sin.sin_addr; |
| 321 | p.prefixlen = IPV4_MAX_BITLEN; |
| 322 | |
| 323 | alist = access_list_lookup (AFI_IP, (char *) rule); |
| 324 | if (alist == NULL) |
| 325 | return RMAP_NOMATCH; |
| 326 | |
| 327 | return (access_list_apply (alist, &p) == FILTER_DENY ? |
| 328 | RMAP_NOMATCH : RMAP_MATCH); |
| 329 | } |
| 330 | return RMAP_NOMATCH; |
| 331 | } |
| 332 | |
| 333 | /* Route map `ip route-source' match statement. `arg' is |
| 334 | access-list name. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 335 | static void * |
hasso | c1643bb | 2005-02-02 16:43:17 +0000 | [diff] [blame] | 336 | route_match_ip_route_source_compile (const char *arg) |
| 337 | { |
| 338 | return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg); |
| 339 | } |
| 340 | |
| 341 | /* Free route map's compiled `ip address' value. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 342 | static void |
hasso | c1643bb | 2005-02-02 16:43:17 +0000 | [diff] [blame] | 343 | route_match_ip_route_source_free (void *rule) |
| 344 | { |
| 345 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); |
| 346 | } |
| 347 | |
| 348 | /* Route map commands for ip route-source matching. */ |
| 349 | struct route_map_rule_cmd route_match_ip_route_source_cmd = |
| 350 | { |
| 351 | "ip route-source", |
| 352 | route_match_ip_route_source, |
| 353 | route_match_ip_route_source_compile, |
| 354 | route_match_ip_route_source_free |
| 355 | }; |
| 356 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 357 | /* `match ip address prefix-list PREFIX_LIST' */ |
| 358 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 359 | static route_map_result_t |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 360 | route_match_ip_address_prefix_list (void *rule, struct prefix *prefix, |
| 361 | route_map_object_t type, void *object) |
| 362 | { |
| 363 | struct prefix_list *plist; |
| 364 | |
| 365 | if (type == RMAP_BGP) |
| 366 | { |
| 367 | plist = prefix_list_lookup (AFI_IP, (char *) rule); |
| 368 | if (plist == NULL) |
| 369 | return RMAP_NOMATCH; |
| 370 | |
| 371 | return (prefix_list_apply (plist, prefix) == PREFIX_DENY ? |
| 372 | RMAP_NOMATCH : RMAP_MATCH); |
| 373 | } |
| 374 | return RMAP_NOMATCH; |
| 375 | } |
| 376 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 377 | static void * |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 378 | route_match_ip_address_prefix_list_compile (const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 379 | { |
| 380 | return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg); |
| 381 | } |
| 382 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 383 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 384 | route_match_ip_address_prefix_list_free (void *rule) |
| 385 | { |
| 386 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); |
| 387 | } |
| 388 | |
| 389 | struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd = |
| 390 | { |
| 391 | "ip address prefix-list", |
| 392 | route_match_ip_address_prefix_list, |
| 393 | route_match_ip_address_prefix_list_compile, |
| 394 | route_match_ip_address_prefix_list_free |
| 395 | }; |
| 396 | |
| 397 | /* `match ip next-hop prefix-list PREFIX_LIST' */ |
| 398 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 399 | static route_map_result_t |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 400 | route_match_ip_next_hop_prefix_list (void *rule, struct prefix *prefix, |
| 401 | route_map_object_t type, void *object) |
| 402 | { |
| 403 | struct prefix_list *plist; |
| 404 | struct bgp_info *bgp_info; |
| 405 | struct prefix_ipv4 p; |
| 406 | |
| 407 | if (type == RMAP_BGP) |
| 408 | { |
| 409 | bgp_info = object; |
| 410 | p.family = AF_INET; |
| 411 | p.prefix = bgp_info->attr->nexthop; |
| 412 | p.prefixlen = IPV4_MAX_BITLEN; |
| 413 | |
| 414 | plist = prefix_list_lookup (AFI_IP, (char *) rule); |
| 415 | if (plist == NULL) |
| 416 | return RMAP_NOMATCH; |
| 417 | |
| 418 | return (prefix_list_apply (plist, &p) == PREFIX_DENY ? |
| 419 | RMAP_NOMATCH : RMAP_MATCH); |
| 420 | } |
| 421 | return RMAP_NOMATCH; |
| 422 | } |
| 423 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 424 | static void * |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 425 | route_match_ip_next_hop_prefix_list_compile (const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 426 | { |
| 427 | return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg); |
| 428 | } |
| 429 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 430 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 431 | route_match_ip_next_hop_prefix_list_free (void *rule) |
| 432 | { |
| 433 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); |
| 434 | } |
| 435 | |
| 436 | struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd = |
| 437 | { |
| 438 | "ip next-hop prefix-list", |
| 439 | route_match_ip_next_hop_prefix_list, |
| 440 | route_match_ip_next_hop_prefix_list_compile, |
| 441 | route_match_ip_next_hop_prefix_list_free |
| 442 | }; |
| 443 | |
hasso | c1643bb | 2005-02-02 16:43:17 +0000 | [diff] [blame] | 444 | /* `match ip route-source prefix-list PREFIX_LIST' */ |
| 445 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 446 | static route_map_result_t |
hasso | c1643bb | 2005-02-02 16:43:17 +0000 | [diff] [blame] | 447 | route_match_ip_route_source_prefix_list (void *rule, struct prefix *prefix, |
| 448 | route_map_object_t type, void *object) |
| 449 | { |
| 450 | struct prefix_list *plist; |
| 451 | struct bgp_info *bgp_info; |
| 452 | struct peer *peer; |
| 453 | struct prefix_ipv4 p; |
| 454 | |
| 455 | if (type == RMAP_BGP) |
| 456 | { |
| 457 | bgp_info = object; |
| 458 | peer = bgp_info->peer; |
| 459 | |
| 460 | if (! peer || sockunion_family (&peer->su) != AF_INET) |
| 461 | return RMAP_NOMATCH; |
| 462 | |
| 463 | p.family = AF_INET; |
| 464 | p.prefix = peer->su.sin.sin_addr; |
| 465 | p.prefixlen = IPV4_MAX_BITLEN; |
| 466 | |
| 467 | plist = prefix_list_lookup (AFI_IP, (char *) rule); |
| 468 | if (plist == NULL) |
| 469 | return RMAP_NOMATCH; |
| 470 | |
| 471 | return (prefix_list_apply (plist, &p) == PREFIX_DENY ? |
| 472 | RMAP_NOMATCH : RMAP_MATCH); |
| 473 | } |
| 474 | return RMAP_NOMATCH; |
| 475 | } |
| 476 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 477 | static void * |
hasso | c1643bb | 2005-02-02 16:43:17 +0000 | [diff] [blame] | 478 | route_match_ip_route_source_prefix_list_compile (const char *arg) |
| 479 | { |
| 480 | return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg); |
| 481 | } |
| 482 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 483 | static void |
hasso | c1643bb | 2005-02-02 16:43:17 +0000 | [diff] [blame] | 484 | route_match_ip_route_source_prefix_list_free (void *rule) |
| 485 | { |
| 486 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); |
| 487 | } |
| 488 | |
| 489 | struct route_map_rule_cmd route_match_ip_route_source_prefix_list_cmd = |
| 490 | { |
| 491 | "ip route-source prefix-list", |
| 492 | route_match_ip_route_source_prefix_list, |
| 493 | route_match_ip_route_source_prefix_list_compile, |
| 494 | route_match_ip_route_source_prefix_list_free |
| 495 | }; |
| 496 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 497 | /* `match metric METRIC' */ |
| 498 | |
| 499 | /* Match function return 1 if match is success else return zero. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 500 | static route_map_result_t |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 501 | route_match_metric (void *rule, struct prefix *prefix, |
| 502 | route_map_object_t type, void *object) |
| 503 | { |
| 504 | u_int32_t *med; |
| 505 | struct bgp_info *bgp_info; |
| 506 | |
| 507 | if (type == RMAP_BGP) |
| 508 | { |
| 509 | med = rule; |
| 510 | bgp_info = object; |
| 511 | |
| 512 | if (bgp_info->attr->med == *med) |
| 513 | return RMAP_MATCH; |
| 514 | else |
| 515 | return RMAP_NOMATCH; |
| 516 | } |
| 517 | return RMAP_NOMATCH; |
| 518 | } |
| 519 | |
| 520 | /* Route map `match metric' match statement. `arg' is MED value */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 521 | static void * |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 522 | route_match_metric_compile (const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 523 | { |
| 524 | u_int32_t *med; |
| 525 | char *endptr = NULL; |
paul | 3b42497 | 2003-10-13 09:47:32 +0000 | [diff] [blame] | 526 | unsigned long tmpval; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 527 | |
paul | 3b42497 | 2003-10-13 09:47:32 +0000 | [diff] [blame] | 528 | tmpval = strtoul (arg, &endptr, 10); |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 529 | if (*endptr != '\0' || tmpval == ULONG_MAX || tmpval > UINT32_MAX) |
paul | 3b42497 | 2003-10-13 09:47:32 +0000 | [diff] [blame] | 530 | return NULL; |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 531 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 532 | med = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t)); |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 533 | |
| 534 | if (!med) |
| 535 | return med; |
| 536 | |
paul | 3b42497 | 2003-10-13 09:47:32 +0000 | [diff] [blame] | 537 | *med = tmpval; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 538 | return med; |
| 539 | } |
| 540 | |
| 541 | /* Free route map's compiled `match metric' value. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 542 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 543 | route_match_metric_free (void *rule) |
| 544 | { |
| 545 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); |
| 546 | } |
| 547 | |
| 548 | /* Route map commands for metric matching. */ |
| 549 | struct route_map_rule_cmd route_match_metric_cmd = |
| 550 | { |
| 551 | "metric", |
| 552 | route_match_metric, |
| 553 | route_match_metric_compile, |
| 554 | route_match_metric_free |
| 555 | }; |
| 556 | |
| 557 | /* `match as-path ASPATH' */ |
| 558 | |
| 559 | /* Match function for as-path match. I assume given object is */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 560 | static route_map_result_t |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 561 | route_match_aspath (void *rule, struct prefix *prefix, |
| 562 | route_map_object_t type, void *object) |
| 563 | { |
| 564 | |
| 565 | struct as_list *as_list; |
| 566 | struct bgp_info *bgp_info; |
| 567 | |
| 568 | if (type == RMAP_BGP) |
| 569 | { |
| 570 | as_list = as_list_lookup ((char *) rule); |
| 571 | if (as_list == NULL) |
| 572 | return RMAP_NOMATCH; |
| 573 | |
| 574 | bgp_info = object; |
| 575 | |
| 576 | /* Perform match. */ |
| 577 | return ((as_list_apply (as_list, bgp_info->attr->aspath) == AS_FILTER_DENY) ? RMAP_NOMATCH : RMAP_MATCH); |
| 578 | } |
| 579 | return RMAP_NOMATCH; |
| 580 | } |
| 581 | |
| 582 | /* Compile function for as-path match. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 583 | static void * |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 584 | route_match_aspath_compile (const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 585 | { |
| 586 | return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg); |
| 587 | } |
| 588 | |
| 589 | /* Compile function for as-path match. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 590 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 591 | route_match_aspath_free (void *rule) |
| 592 | { |
| 593 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); |
| 594 | } |
| 595 | |
| 596 | /* Route map commands for aspath matching. */ |
| 597 | struct route_map_rule_cmd route_match_aspath_cmd = |
| 598 | { |
| 599 | "as-path", |
| 600 | route_match_aspath, |
| 601 | route_match_aspath_compile, |
| 602 | route_match_aspath_free |
| 603 | }; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 604 | |
| 605 | /* `match community COMMUNIY' */ |
| 606 | struct rmap_community |
| 607 | { |
| 608 | char *name; |
| 609 | int exact; |
| 610 | }; |
| 611 | |
| 612 | /* Match function for community match. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 613 | static route_map_result_t |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 614 | route_match_community (void *rule, struct prefix *prefix, |
| 615 | route_map_object_t type, void *object) |
| 616 | { |
| 617 | struct community_list *list; |
| 618 | struct bgp_info *bgp_info; |
| 619 | struct rmap_community *rcom; |
| 620 | |
| 621 | if (type == RMAP_BGP) |
| 622 | { |
| 623 | bgp_info = object; |
| 624 | rcom = rule; |
| 625 | |
hasso | fee6e4e | 2005-02-02 16:29:31 +0000 | [diff] [blame] | 626 | list = community_list_lookup (bgp_clist, rcom->name, COMMUNITY_LIST_MASTER); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 627 | if (! list) |
| 628 | return RMAP_NOMATCH; |
| 629 | |
| 630 | if (rcom->exact) |
| 631 | { |
| 632 | if (community_list_exact_match (bgp_info->attr->community, list)) |
| 633 | return RMAP_MATCH; |
| 634 | } |
| 635 | else |
| 636 | { |
| 637 | if (community_list_match (bgp_info->attr->community, list)) |
| 638 | return RMAP_MATCH; |
| 639 | } |
| 640 | } |
| 641 | return RMAP_NOMATCH; |
| 642 | } |
| 643 | |
| 644 | /* Compile function for community match. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 645 | static void * |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 646 | route_match_community_compile (const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 647 | { |
| 648 | struct rmap_community *rcom; |
| 649 | int len; |
| 650 | char *p; |
| 651 | |
| 652 | rcom = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct rmap_community)); |
| 653 | |
| 654 | p = strchr (arg, ' '); |
| 655 | if (p) |
| 656 | { |
| 657 | len = p - arg; |
| 658 | rcom->name = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, len + 1); |
| 659 | memcpy (rcom->name, arg, len); |
| 660 | rcom->exact = 1; |
| 661 | } |
| 662 | else |
| 663 | { |
| 664 | rcom->name = XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg); |
| 665 | rcom->exact = 0; |
| 666 | } |
| 667 | return rcom; |
| 668 | } |
| 669 | |
| 670 | /* Compile function for community match. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 671 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 672 | route_match_community_free (void *rule) |
| 673 | { |
| 674 | struct rmap_community *rcom = rule; |
| 675 | |
| 676 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rcom->name); |
| 677 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rcom); |
| 678 | } |
| 679 | |
| 680 | /* Route map commands for community matching. */ |
| 681 | struct route_map_rule_cmd route_match_community_cmd = |
| 682 | { |
| 683 | "community", |
| 684 | route_match_community, |
| 685 | route_match_community_compile, |
| 686 | route_match_community_free |
| 687 | }; |
| 688 | |
paul | 73ffb25 | 2003-04-19 15:49:49 +0000 | [diff] [blame] | 689 | /* Match function for extcommunity match. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 690 | static route_map_result_t |
paul | 73ffb25 | 2003-04-19 15:49:49 +0000 | [diff] [blame] | 691 | route_match_ecommunity (void *rule, struct prefix *prefix, |
| 692 | route_map_object_t type, void *object) |
| 693 | { |
| 694 | struct community_list *list; |
| 695 | struct bgp_info *bgp_info; |
| 696 | |
| 697 | if (type == RMAP_BGP) |
| 698 | { |
| 699 | bgp_info = object; |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 700 | |
| 701 | if (!bgp_info->attr->extra) |
| 702 | return RMAP_NOMATCH; |
| 703 | |
paul | 73ffb25 | 2003-04-19 15:49:49 +0000 | [diff] [blame] | 704 | list = community_list_lookup (bgp_clist, (char *) rule, |
hasso | fee6e4e | 2005-02-02 16:29:31 +0000 | [diff] [blame] | 705 | EXTCOMMUNITY_LIST_MASTER); |
paul | 73ffb25 | 2003-04-19 15:49:49 +0000 | [diff] [blame] | 706 | if (! list) |
| 707 | return RMAP_NOMATCH; |
| 708 | |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 709 | if (ecommunity_list_match (bgp_info->attr->extra->ecommunity, list)) |
paul | 73ffb25 | 2003-04-19 15:49:49 +0000 | [diff] [blame] | 710 | return RMAP_MATCH; |
| 711 | } |
| 712 | return RMAP_NOMATCH; |
| 713 | } |
| 714 | |
| 715 | /* Compile function for extcommunity match. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 716 | static void * |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 717 | route_match_ecommunity_compile (const char *arg) |
paul | 73ffb25 | 2003-04-19 15:49:49 +0000 | [diff] [blame] | 718 | { |
| 719 | return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg); |
| 720 | } |
| 721 | |
| 722 | /* Compile function for extcommunity match. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 723 | static void |
paul | 73ffb25 | 2003-04-19 15:49:49 +0000 | [diff] [blame] | 724 | route_match_ecommunity_free (void *rule) |
| 725 | { |
| 726 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); |
| 727 | } |
| 728 | |
| 729 | /* Route map commands for community matching. */ |
| 730 | struct route_map_rule_cmd route_match_ecommunity_cmd = |
| 731 | { |
| 732 | "extcommunity", |
| 733 | route_match_ecommunity, |
| 734 | route_match_ecommunity_compile, |
| 735 | route_match_ecommunity_free |
| 736 | }; |
| 737 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 738 | /* `match nlri` and `set nlri` are replaced by `address-family ipv4` |
| 739 | and `address-family vpnv4'. */ |
| 740 | |
| 741 | /* `match origin' */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 742 | static route_map_result_t |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 743 | route_match_origin (void *rule, struct prefix *prefix, |
| 744 | route_map_object_t type, void *object) |
| 745 | { |
| 746 | u_char *origin; |
| 747 | struct bgp_info *bgp_info; |
| 748 | |
| 749 | if (type == RMAP_BGP) |
| 750 | { |
| 751 | origin = rule; |
| 752 | bgp_info = object; |
| 753 | |
| 754 | if (bgp_info->attr->origin == *origin) |
| 755 | return RMAP_MATCH; |
| 756 | } |
| 757 | |
| 758 | return RMAP_NOMATCH; |
| 759 | } |
| 760 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 761 | static void * |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 762 | route_match_origin_compile (const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 763 | { |
| 764 | u_char *origin; |
| 765 | |
| 766 | origin = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_char)); |
| 767 | |
| 768 | if (strcmp (arg, "igp") == 0) |
| 769 | *origin = 0; |
| 770 | else if (strcmp (arg, "egp") == 0) |
| 771 | *origin = 1; |
| 772 | else |
| 773 | *origin = 2; |
| 774 | |
| 775 | return origin; |
| 776 | } |
| 777 | |
| 778 | /* Free route map's compiled `ip address' value. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 779 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 780 | route_match_origin_free (void *rule) |
| 781 | { |
| 782 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); |
| 783 | } |
| 784 | |
| 785 | /* Route map commands for origin matching. */ |
| 786 | struct route_map_rule_cmd route_match_origin_cmd = |
| 787 | { |
| 788 | "origin", |
| 789 | route_match_origin, |
| 790 | route_match_origin_compile, |
| 791 | route_match_origin_free |
| 792 | }; |
Vyacheslav Trushkin | 1c8afb7 | 2011-11-22 20:15:10 +0400 | [diff] [blame] | 793 | |
| 794 | /* match probability { */ |
| 795 | |
| 796 | static route_map_result_t |
| 797 | route_match_probability (void *rule, struct prefix *prefix, |
| 798 | route_map_object_t type, void *object) |
| 799 | { |
| 800 | long r; |
| 801 | #if _SVID_SOURCE || _BSD_SOURCE || _XOPEN_SOURCE >= 500 |
| 802 | r = random(); |
| 803 | #else |
| 804 | r = (long) rand(); |
| 805 | #endif |
| 806 | |
| 807 | switch (*(unsigned *) rule) |
| 808 | { |
| 809 | case 0: break; |
| 810 | case RAND_MAX: return RMAP_MATCH; |
| 811 | default: |
| 812 | if (r < *(unsigned *) rule) |
| 813 | { |
| 814 | return RMAP_MATCH; |
| 815 | } |
| 816 | } |
| 817 | |
| 818 | return RMAP_NOMATCH; |
| 819 | } |
| 820 | |
| 821 | static void * |
| 822 | route_match_probability_compile (const char *arg) |
| 823 | { |
| 824 | unsigned *lobule; |
| 825 | unsigned perc; |
| 826 | |
| 827 | #if _SVID_SOURCE || _BSD_SOURCE || _XOPEN_SOURCE >= 500 |
| 828 | srandom (time (NULL)); |
| 829 | #else |
| 830 | srand (time (NULL)); |
| 831 | #endif |
| 832 | |
| 833 | perc = atoi (arg); |
| 834 | lobule = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (unsigned)); |
| 835 | |
| 836 | switch (perc) |
| 837 | { |
| 838 | case 0: *lobule = 0; break; |
| 839 | case 100: *lobule = RAND_MAX; break; |
| 840 | default: *lobule = RAND_MAX / 100 * perc; |
| 841 | } |
| 842 | |
| 843 | return lobule; |
| 844 | } |
| 845 | |
| 846 | static void |
| 847 | route_match_probability_free (void *rule) |
| 848 | { |
| 849 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); |
| 850 | } |
| 851 | |
| 852 | struct route_map_rule_cmd route_match_probability_cmd = |
| 853 | { |
| 854 | "probability", |
| 855 | route_match_probability, |
| 856 | route_match_probability_compile, |
| 857 | route_match_probability_free |
| 858 | }; |
| 859 | |
| 860 | /* } */ |
| 861 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 862 | /* `set ip next-hop IP_ADDRESS' */ |
| 863 | |
| 864 | /* Set nexthop to object. ojbect must be pointer to struct attr. */ |
paul | ac41b2a | 2003-08-12 05:32:27 +0000 | [diff] [blame] | 865 | struct rmap_ip_nexthop_set |
| 866 | { |
| 867 | struct in_addr *address; |
| 868 | int peer_address; |
| 869 | }; |
| 870 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 871 | static route_map_result_t |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 872 | route_set_ip_nexthop (void *rule, struct prefix *prefix, |
| 873 | route_map_object_t type, void *object) |
| 874 | { |
paul | ac41b2a | 2003-08-12 05:32:27 +0000 | [diff] [blame] | 875 | struct rmap_ip_nexthop_set *rins = rule; |
| 876 | struct in_addr peer_address; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 877 | struct bgp_info *bgp_info; |
paul | ac41b2a | 2003-08-12 05:32:27 +0000 | [diff] [blame] | 878 | struct peer *peer; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 879 | |
| 880 | if (type == RMAP_BGP) |
| 881 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 882 | bgp_info = object; |
paul | ac41b2a | 2003-08-12 05:32:27 +0000 | [diff] [blame] | 883 | peer = bgp_info->peer; |
| 884 | |
| 885 | if (rins->peer_address) |
| 886 | { |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 887 | if ((CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN) || |
| 888 | CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT)) |
paul | ac41b2a | 2003-08-12 05:32:27 +0000 | [diff] [blame] | 889 | && peer->su_remote |
| 890 | && sockunion_family (peer->su_remote) == AF_INET) |
| 891 | { |
| 892 | inet_aton (sockunion_su2str (peer->su_remote), &peer_address); |
| 893 | bgp_info->attr->nexthop = peer_address; |
| 894 | bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP); |
| 895 | } |
| 896 | else if (CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT) |
| 897 | && peer->su_local |
| 898 | && sockunion_family (peer->su_local) == AF_INET) |
| 899 | { |
| 900 | inet_aton (sockunion_su2str (peer->su_local), &peer_address); |
| 901 | bgp_info->attr->nexthop = peer_address; |
| 902 | bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP); |
| 903 | } |
| 904 | } |
| 905 | else |
| 906 | { |
| 907 | /* Set next hop value. */ |
| 908 | bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP); |
| 909 | bgp_info->attr->nexthop = *rins->address; |
| 910 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | return RMAP_OKAY; |
| 914 | } |
| 915 | |
| 916 | /* Route map `ip nexthop' compile function. Given string is converted |
| 917 | to struct in_addr structure. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 918 | static void * |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 919 | route_set_ip_nexthop_compile (const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 920 | { |
paul | ac41b2a | 2003-08-12 05:32:27 +0000 | [diff] [blame] | 921 | struct rmap_ip_nexthop_set *rins; |
| 922 | struct in_addr *address = NULL; |
| 923 | int peer_address = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 924 | int ret; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 925 | |
paul | ac41b2a | 2003-08-12 05:32:27 +0000 | [diff] [blame] | 926 | if (strcmp (arg, "peer-address") == 0) |
| 927 | peer_address = 1; |
| 928 | else |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 929 | { |
paul | ac41b2a | 2003-08-12 05:32:27 +0000 | [diff] [blame] | 930 | address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr)); |
| 931 | ret = inet_aton (arg, address); |
| 932 | |
| 933 | if (ret == 0) |
| 934 | { |
| 935 | XFREE (MTYPE_ROUTE_MAP_COMPILED, address); |
| 936 | return NULL; |
| 937 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 938 | } |
| 939 | |
Stephen Hemminger | 393deb9 | 2008-08-18 14:13:29 -0700 | [diff] [blame] | 940 | rins = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct rmap_ip_nexthop_set)); |
paul | ac41b2a | 2003-08-12 05:32:27 +0000 | [diff] [blame] | 941 | |
| 942 | rins->address = address; |
| 943 | rins->peer_address = peer_address; |
| 944 | |
| 945 | return rins; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | /* Free route map's compiled `ip nexthop' value. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 949 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 950 | route_set_ip_nexthop_free (void *rule) |
| 951 | { |
paul | ac41b2a | 2003-08-12 05:32:27 +0000 | [diff] [blame] | 952 | struct rmap_ip_nexthop_set *rins = rule; |
| 953 | |
| 954 | if (rins->address) |
| 955 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rins->address); |
| 956 | |
| 957 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rins); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 958 | } |
| 959 | |
| 960 | /* Route map commands for ip nexthop set. */ |
| 961 | struct route_map_rule_cmd route_set_ip_nexthop_cmd = |
| 962 | { |
| 963 | "ip next-hop", |
| 964 | route_set_ip_nexthop, |
| 965 | route_set_ip_nexthop_compile, |
| 966 | route_set_ip_nexthop_free |
| 967 | }; |
| 968 | |
| 969 | /* `set local-preference LOCAL_PREF' */ |
| 970 | |
| 971 | /* Set local preference. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 972 | static route_map_result_t |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 973 | route_set_local_pref (void *rule, struct prefix *prefix, |
| 974 | route_map_object_t type, void *object) |
| 975 | { |
| 976 | u_int32_t *local_pref; |
| 977 | struct bgp_info *bgp_info; |
| 978 | |
| 979 | if (type == RMAP_BGP) |
| 980 | { |
| 981 | /* Fetch routemap's rule information. */ |
| 982 | local_pref = rule; |
| 983 | bgp_info = object; |
| 984 | |
| 985 | /* Set local preference value. */ |
| 986 | bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF); |
| 987 | bgp_info->attr->local_pref = *local_pref; |
| 988 | } |
| 989 | |
| 990 | return RMAP_OKAY; |
| 991 | } |
| 992 | |
| 993 | /* set local preference compilation. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 994 | static void * |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 995 | route_set_local_pref_compile (const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 996 | { |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 997 | unsigned long tmp; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 998 | u_int32_t *local_pref; |
| 999 | char *endptr = NULL; |
| 1000 | |
| 1001 | /* Local preference value shoud be integer. */ |
| 1002 | if (! all_digit (arg)) |
| 1003 | return NULL; |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 1004 | |
| 1005 | tmp = strtoul (arg, &endptr, 10); |
| 1006 | if (*endptr != '\0' || tmp == ULONG_MAX || tmp > UINT32_MAX) |
| 1007 | return NULL; |
| 1008 | |
| 1009 | local_pref = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t)); |
| 1010 | |
| 1011 | if (!local_pref) |
| 1012 | return local_pref; |
| 1013 | |
| 1014 | *local_pref = tmp; |
| 1015 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1016 | return local_pref; |
| 1017 | } |
| 1018 | |
| 1019 | /* Free route map's local preference value. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1020 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1021 | route_set_local_pref_free (void *rule) |
| 1022 | { |
| 1023 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); |
| 1024 | } |
| 1025 | |
| 1026 | /* Set local preference rule structure. */ |
| 1027 | struct route_map_rule_cmd route_set_local_pref_cmd = |
| 1028 | { |
| 1029 | "local-preference", |
| 1030 | route_set_local_pref, |
| 1031 | route_set_local_pref_compile, |
| 1032 | route_set_local_pref_free, |
| 1033 | }; |
| 1034 | |
| 1035 | /* `set weight WEIGHT' */ |
| 1036 | |
| 1037 | /* Set weight. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1038 | static route_map_result_t |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1039 | route_set_weight (void *rule, struct prefix *prefix, route_map_object_t type, |
| 1040 | void *object) |
| 1041 | { |
| 1042 | u_int32_t *weight; |
| 1043 | struct bgp_info *bgp_info; |
| 1044 | |
| 1045 | if (type == RMAP_BGP) |
| 1046 | { |
| 1047 | /* Fetch routemap's rule information. */ |
| 1048 | weight = rule; |
| 1049 | bgp_info = object; |
| 1050 | |
| 1051 | /* Set weight value. */ |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1052 | if (*weight) |
| 1053 | (bgp_attr_extra_get (bgp_info->attr))->weight = *weight; |
| 1054 | else if (bgp_info->attr->extra) |
| 1055 | bgp_info->attr->extra->weight = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | return RMAP_OKAY; |
| 1059 | } |
| 1060 | |
| 1061 | /* set local preference compilation. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1062 | static void * |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 1063 | route_set_weight_compile (const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1064 | { |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 1065 | unsigned long tmp; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1066 | u_int32_t *weight; |
| 1067 | char *endptr = NULL; |
| 1068 | |
| 1069 | /* Local preference value shoud be integer. */ |
| 1070 | if (! all_digit (arg)) |
| 1071 | return NULL; |
| 1072 | |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 1073 | |
| 1074 | tmp = strtoul (arg, &endptr, 10); |
| 1075 | if (*endptr != '\0' || tmp == ULONG_MAX || tmp > UINT32_MAX) |
| 1076 | return NULL; |
| 1077 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1078 | weight = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t)); |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 1079 | |
| 1080 | if (weight == NULL) |
| 1081 | return weight; |
| 1082 | |
| 1083 | *weight = tmp; |
| 1084 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1085 | return weight; |
| 1086 | } |
| 1087 | |
| 1088 | /* Free route map's local preference value. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1089 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1090 | route_set_weight_free (void *rule) |
| 1091 | { |
| 1092 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); |
| 1093 | } |
| 1094 | |
| 1095 | /* Set local preference rule structure. */ |
| 1096 | struct route_map_rule_cmd route_set_weight_cmd = |
| 1097 | { |
| 1098 | "weight", |
| 1099 | route_set_weight, |
| 1100 | route_set_weight_compile, |
| 1101 | route_set_weight_free, |
| 1102 | }; |
| 1103 | |
| 1104 | /* `set metric METRIC' */ |
| 1105 | |
| 1106 | /* Set metric to attribute. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1107 | static route_map_result_t |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1108 | route_set_metric (void *rule, struct prefix *prefix, |
| 1109 | route_map_object_t type, void *object) |
| 1110 | { |
| 1111 | char *metric; |
| 1112 | u_int32_t metric_val; |
| 1113 | struct bgp_info *bgp_info; |
| 1114 | |
| 1115 | if (type == RMAP_BGP) |
| 1116 | { |
| 1117 | /* Fetch routemap's rule information. */ |
| 1118 | metric = rule; |
| 1119 | bgp_info = object; |
| 1120 | |
| 1121 | if (! (bgp_info->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))) |
| 1122 | bgp_info->attr->med = 0; |
| 1123 | bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC); |
| 1124 | |
| 1125 | if (all_digit (metric)) |
| 1126 | { |
| 1127 | metric_val = strtoul (metric, (char **)NULL, 10); |
| 1128 | bgp_info->attr->med = metric_val; |
| 1129 | } |
| 1130 | else |
| 1131 | { |
| 1132 | metric_val = strtoul (metric+1, (char **)NULL, 10); |
| 1133 | |
| 1134 | if (strncmp (metric, "+", 1) == 0) |
| 1135 | { |
paul | 3b42497 | 2003-10-13 09:47:32 +0000 | [diff] [blame] | 1136 | if (bgp_info->attr->med/2 + metric_val/2 > BGP_MED_MAX/2) |
| 1137 | bgp_info->attr->med = BGP_MED_MAX - 1; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1138 | else |
paul | 537d8ea | 2003-08-27 06:45:32 +0000 | [diff] [blame] | 1139 | bgp_info->attr->med += metric_val; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1140 | } |
| 1141 | else if (strncmp (metric, "-", 1) == 0) |
| 1142 | { |
paul | 537d8ea | 2003-08-27 06:45:32 +0000 | [diff] [blame] | 1143 | if (bgp_info->attr->med <= metric_val) |
| 1144 | bgp_info->attr->med = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1145 | else |
paul | 537d8ea | 2003-08-27 06:45:32 +0000 | [diff] [blame] | 1146 | bgp_info->attr->med -= metric_val; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1147 | } |
| 1148 | } |
| 1149 | } |
| 1150 | return RMAP_OKAY; |
| 1151 | } |
| 1152 | |
| 1153 | /* set metric compilation. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1154 | static void * |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 1155 | route_set_metric_compile (const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1156 | { |
| 1157 | u_int32_t metric; |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1158 | unsigned long larg; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1159 | char *endptr = NULL; |
| 1160 | |
| 1161 | if (all_digit (arg)) |
| 1162 | { |
| 1163 | /* set metric value check*/ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1164 | larg = strtoul (arg, &endptr, 10); |
| 1165 | if (*endptr != '\0' || larg == ULONG_MAX || larg > UINT32_MAX) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1166 | return NULL; |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1167 | metric = larg; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1168 | } |
| 1169 | else |
| 1170 | { |
| 1171 | /* set metric +/-value check */ |
| 1172 | if ((strncmp (arg, "+", 1) != 0 |
| 1173 | && strncmp (arg, "-", 1) != 0) |
| 1174 | || (! all_digit (arg+1))) |
| 1175 | return NULL; |
| 1176 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1177 | larg = strtoul (arg+1, &endptr, 10); |
| 1178 | if (*endptr != '\0' || larg == ULONG_MAX || larg > UINT32_MAX) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1179 | return NULL; |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1180 | metric = larg; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1181 | } |
| 1182 | |
| 1183 | return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg); |
| 1184 | } |
| 1185 | |
| 1186 | /* Free route map's compiled `set metric' value. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1187 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1188 | route_set_metric_free (void *rule) |
| 1189 | { |
| 1190 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); |
| 1191 | } |
| 1192 | |
| 1193 | /* Set metric rule structure. */ |
| 1194 | struct route_map_rule_cmd route_set_metric_cmd = |
| 1195 | { |
| 1196 | "metric", |
| 1197 | route_set_metric, |
| 1198 | route_set_metric_compile, |
| 1199 | route_set_metric_free, |
| 1200 | }; |
| 1201 | |
| 1202 | /* `set as-path prepend ASPATH' */ |
| 1203 | |
| 1204 | /* For AS path prepend mechanism. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1205 | static route_map_result_t |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1206 | route_set_aspath_prepend (void *rule, struct prefix *prefix, route_map_object_t type, void *object) |
| 1207 | { |
| 1208 | struct aspath *aspath; |
| 1209 | struct aspath *new; |
| 1210 | struct bgp_info *binfo; |
| 1211 | |
| 1212 | if (type == RMAP_BGP) |
| 1213 | { |
| 1214 | aspath = rule; |
| 1215 | binfo = object; |
| 1216 | |
| 1217 | if (binfo->attr->aspath->refcnt) |
| 1218 | new = aspath_dup (binfo->attr->aspath); |
| 1219 | else |
| 1220 | new = binfo->attr->aspath; |
| 1221 | |
| 1222 | aspath_prepend (aspath, new); |
| 1223 | binfo->attr->aspath = new; |
| 1224 | } |
| 1225 | |
| 1226 | return RMAP_OKAY; |
| 1227 | } |
| 1228 | |
| 1229 | /* Compile function for as-path prepend. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1230 | static void * |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 1231 | route_set_aspath_prepend_compile (const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1232 | { |
| 1233 | struct aspath *aspath; |
| 1234 | |
| 1235 | aspath = aspath_str2aspath (arg); |
| 1236 | if (! aspath) |
| 1237 | return NULL; |
| 1238 | return aspath; |
| 1239 | } |
| 1240 | |
| 1241 | /* Compile function for as-path prepend. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1242 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1243 | route_set_aspath_prepend_free (void *rule) |
| 1244 | { |
| 1245 | struct aspath *aspath = rule; |
| 1246 | aspath_free (aspath); |
| 1247 | } |
| 1248 | |
| 1249 | /* Set metric rule structure. */ |
| 1250 | struct route_map_rule_cmd route_set_aspath_prepend_cmd = |
| 1251 | { |
| 1252 | "as-path prepend", |
| 1253 | route_set_aspath_prepend, |
| 1254 | route_set_aspath_prepend_compile, |
| 1255 | route_set_aspath_prepend_free, |
| 1256 | }; |
| 1257 | |
Denis Ovsienko | 841f7a5 | 2008-04-10 11:47:45 +0000 | [diff] [blame] | 1258 | /* `set as-path exclude ASn' */ |
| 1259 | |
| 1260 | /* For ASN exclude mechanism. |
| 1261 | * Iterate over ASns requested and filter them from the given AS_PATH one by one. |
| 1262 | * Make a deep copy of existing AS_PATH, but for the first ASn only. |
| 1263 | */ |
| 1264 | static route_map_result_t |
| 1265 | route_set_aspath_exclude (void *rule, struct prefix *dummy, route_map_object_t type, void *object) |
| 1266 | { |
| 1267 | struct aspath * new_path, * exclude_path; |
| 1268 | struct bgp_info *binfo; |
| 1269 | |
| 1270 | if (type == RMAP_BGP) |
| 1271 | { |
| 1272 | exclude_path = rule; |
| 1273 | binfo = object; |
| 1274 | if (binfo->attr->aspath->refcnt) |
| 1275 | new_path = aspath_dup (binfo->attr->aspath); |
| 1276 | else |
| 1277 | new_path = binfo->attr->aspath; |
| 1278 | binfo->attr->aspath = aspath_filter_exclude (new_path, exclude_path); |
| 1279 | } |
| 1280 | return RMAP_OKAY; |
| 1281 | } |
| 1282 | |
| 1283 | /* FIXME: consider using route_set_aspath_prepend_compile() and |
| 1284 | * route_set_aspath_prepend_free(), which two below function are |
| 1285 | * exact clones of. |
| 1286 | */ |
| 1287 | |
| 1288 | /* Compile function for as-path exclude. */ |
| 1289 | static void * |
| 1290 | route_set_aspath_exclude_compile (const char *arg) |
| 1291 | { |
| 1292 | struct aspath *aspath; |
| 1293 | |
| 1294 | aspath = aspath_str2aspath (arg); |
| 1295 | if (! aspath) |
| 1296 | return NULL; |
| 1297 | return aspath; |
| 1298 | } |
| 1299 | |
| 1300 | static void |
| 1301 | route_set_aspath_exclude_free (void *rule) |
| 1302 | { |
| 1303 | struct aspath *aspath = rule; |
| 1304 | aspath_free (aspath); |
| 1305 | } |
| 1306 | |
| 1307 | /* Set ASn exlude rule structure. */ |
| 1308 | struct route_map_rule_cmd route_set_aspath_exclude_cmd = |
| 1309 | { |
| 1310 | "as-path exclude", |
| 1311 | route_set_aspath_exclude, |
| 1312 | route_set_aspath_exclude_compile, |
| 1313 | route_set_aspath_exclude_free, |
| 1314 | }; |
| 1315 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1316 | /* `set community COMMUNITY' */ |
| 1317 | struct rmap_com_set |
| 1318 | { |
| 1319 | struct community *com; |
| 1320 | int additive; |
| 1321 | int none; |
| 1322 | }; |
| 1323 | |
| 1324 | /* For community set mechanism. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1325 | static route_map_result_t |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1326 | route_set_community (void *rule, struct prefix *prefix, |
| 1327 | route_map_object_t type, void *object) |
| 1328 | { |
| 1329 | struct rmap_com_set *rcs; |
| 1330 | struct bgp_info *binfo; |
| 1331 | struct attr *attr; |
| 1332 | struct community *new = NULL; |
| 1333 | struct community *old; |
| 1334 | struct community *merge; |
Paul Jakma | aa94ca8 | 2006-02-18 10:49:04 +0000 | [diff] [blame] | 1335 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1336 | if (type == RMAP_BGP) |
| 1337 | { |
| 1338 | rcs = rule; |
| 1339 | binfo = object; |
| 1340 | attr = binfo->attr; |
| 1341 | old = attr->community; |
| 1342 | |
| 1343 | /* "none" case. */ |
| 1344 | if (rcs->none) |
| 1345 | { |
| 1346 | attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES)); |
| 1347 | attr->community = NULL; |
| 1348 | return RMAP_OKAY; |
| 1349 | } |
| 1350 | |
| 1351 | /* "additive" case. */ |
| 1352 | if (rcs->additive && old) |
| 1353 | { |
| 1354 | merge = community_merge (community_dup (old), rcs->com); |
Paul Jakma | aa94ca8 | 2006-02-18 10:49:04 +0000 | [diff] [blame] | 1355 | |
| 1356 | /* HACK: if the old community is not intern'd, |
| 1357 | * we should free it here, or all reference to it may be lost. |
| 1358 | * Really need to cleanup attribute caching sometime. |
| 1359 | */ |
| 1360 | if (old->refcnt == 0) |
| 1361 | community_free (old); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1362 | new = community_uniq_sort (merge); |
| 1363 | community_free (merge); |
| 1364 | } |
| 1365 | else |
| 1366 | new = community_dup (rcs->com); |
Paul Jakma | aa94ca8 | 2006-02-18 10:49:04 +0000 | [diff] [blame] | 1367 | |
| 1368 | /* will be interned by caller if required */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1369 | attr->community = new; |
hasso | 70601e0 | 2005-05-27 03:26:57 +0000 | [diff] [blame] | 1370 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1371 | attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES); |
| 1372 | } |
| 1373 | |
| 1374 | return RMAP_OKAY; |
| 1375 | } |
| 1376 | |
| 1377 | /* Compile function for set community. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1378 | static void * |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 1379 | route_set_community_compile (const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1380 | { |
| 1381 | struct rmap_com_set *rcs; |
| 1382 | struct community *com = NULL; |
| 1383 | char *sp; |
| 1384 | int additive = 0; |
| 1385 | int none = 0; |
| 1386 | |
| 1387 | if (strcmp (arg, "none") == 0) |
| 1388 | none = 1; |
| 1389 | else |
| 1390 | { |
| 1391 | sp = strstr (arg, "additive"); |
| 1392 | |
| 1393 | if (sp && sp > arg) |
| 1394 | { |
| 1395 | /* "additive" keyworkd is included. */ |
| 1396 | additive = 1; |
| 1397 | *(sp - 1) = '\0'; |
| 1398 | } |
| 1399 | |
| 1400 | com = community_str2com (arg); |
| 1401 | |
| 1402 | if (additive) |
| 1403 | *(sp - 1) = ' '; |
| 1404 | |
| 1405 | if (! com) |
| 1406 | return NULL; |
| 1407 | } |
| 1408 | |
Stephen Hemminger | 393deb9 | 2008-08-18 14:13:29 -0700 | [diff] [blame] | 1409 | rcs = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct rmap_com_set)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1410 | rcs->com = com; |
| 1411 | rcs->additive = additive; |
| 1412 | rcs->none = none; |
| 1413 | |
| 1414 | return rcs; |
| 1415 | } |
| 1416 | |
| 1417 | /* Free function for set community. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1418 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1419 | route_set_community_free (void *rule) |
| 1420 | { |
| 1421 | struct rmap_com_set *rcs = rule; |
| 1422 | |
| 1423 | if (rcs->com) |
| 1424 | community_free (rcs->com); |
| 1425 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rcs); |
| 1426 | } |
| 1427 | |
| 1428 | /* Set community rule structure. */ |
| 1429 | struct route_map_rule_cmd route_set_community_cmd = |
| 1430 | { |
| 1431 | "community", |
| 1432 | route_set_community, |
| 1433 | route_set_community_compile, |
| 1434 | route_set_community_free, |
| 1435 | }; |
| 1436 | |
hasso | fee6e4e | 2005-02-02 16:29:31 +0000 | [diff] [blame] | 1437 | /* `set comm-list (<1-99>|<100-500>|WORD) delete' */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1438 | |
| 1439 | /* For community set mechanism. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1440 | static route_map_result_t |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1441 | route_set_community_delete (void *rule, struct prefix *prefix, |
| 1442 | route_map_object_t type, void *object) |
| 1443 | { |
| 1444 | struct community_list *list; |
| 1445 | struct community *merge; |
| 1446 | struct community *new; |
| 1447 | struct community *old; |
| 1448 | struct bgp_info *binfo; |
| 1449 | |
| 1450 | if (type == RMAP_BGP) |
| 1451 | { |
| 1452 | if (! rule) |
| 1453 | return RMAP_OKAY; |
| 1454 | |
| 1455 | binfo = object; |
hasso | fee6e4e | 2005-02-02 16:29:31 +0000 | [diff] [blame] | 1456 | list = community_list_lookup (bgp_clist, rule, COMMUNITY_LIST_MASTER); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1457 | old = binfo->attr->community; |
| 1458 | |
| 1459 | if (list && old) |
| 1460 | { |
| 1461 | merge = community_list_match_delete (community_dup (old), list); |
| 1462 | new = community_uniq_sort (merge); |
| 1463 | community_free (merge); |
| 1464 | |
| 1465 | if (new->size == 0) |
| 1466 | { |
| 1467 | binfo->attr->community = NULL; |
| 1468 | binfo->attr->flag &= ~ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES); |
| 1469 | community_free (new); |
| 1470 | } |
| 1471 | else |
| 1472 | { |
| 1473 | binfo->attr->community = new; |
| 1474 | binfo->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES); |
| 1475 | } |
| 1476 | } |
| 1477 | } |
| 1478 | |
| 1479 | return RMAP_OKAY; |
| 1480 | } |
| 1481 | |
| 1482 | /* Compile function for set community. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1483 | static void * |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 1484 | route_set_community_delete_compile (const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1485 | { |
| 1486 | char *p; |
| 1487 | char *str; |
| 1488 | int len; |
| 1489 | |
| 1490 | p = strchr (arg, ' '); |
| 1491 | if (p) |
| 1492 | { |
| 1493 | len = p - arg; |
| 1494 | str = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, len + 1); |
| 1495 | memcpy (str, arg, len); |
| 1496 | } |
| 1497 | else |
| 1498 | str = NULL; |
| 1499 | |
| 1500 | return str; |
| 1501 | } |
| 1502 | |
| 1503 | /* Free function for set community. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1504 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1505 | route_set_community_delete_free (void *rule) |
| 1506 | { |
| 1507 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); |
| 1508 | } |
| 1509 | |
| 1510 | /* Set community rule structure. */ |
| 1511 | struct route_map_rule_cmd route_set_community_delete_cmd = |
| 1512 | { |
| 1513 | "comm-list", |
| 1514 | route_set_community_delete, |
| 1515 | route_set_community_delete_compile, |
| 1516 | route_set_community_delete_free, |
| 1517 | }; |
| 1518 | |
| 1519 | /* `set extcommunity rt COMMUNITY' */ |
| 1520 | |
| 1521 | /* For community set mechanism. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1522 | static route_map_result_t |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1523 | route_set_ecommunity_rt (void *rule, struct prefix *prefix, |
| 1524 | route_map_object_t type, void *object) |
| 1525 | { |
| 1526 | struct ecommunity *ecom; |
| 1527 | struct ecommunity *new_ecom; |
| 1528 | struct ecommunity *old_ecom; |
| 1529 | struct bgp_info *bgp_info; |
| 1530 | |
| 1531 | if (type == RMAP_BGP) |
| 1532 | { |
| 1533 | ecom = rule; |
| 1534 | bgp_info = object; |
| 1535 | |
| 1536 | if (! ecom) |
| 1537 | return RMAP_OKAY; |
| 1538 | |
| 1539 | /* We assume additive for Extended Community. */ |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1540 | old_ecom = (bgp_attr_extra_get (bgp_info->attr))->ecommunity; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1541 | |
| 1542 | if (old_ecom) |
| 1543 | new_ecom = ecommunity_merge (ecommunity_dup (old_ecom), ecom); |
| 1544 | else |
| 1545 | new_ecom = ecommunity_dup (ecom); |
| 1546 | |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1547 | bgp_info->attr->extra->ecommunity = new_ecom; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1548 | |
hasso | 70601e0 | 2005-05-27 03:26:57 +0000 | [diff] [blame] | 1549 | if (old_ecom) |
| 1550 | ecommunity_free (old_ecom); |
| 1551 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1552 | bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_EXT_COMMUNITIES); |
| 1553 | } |
| 1554 | return RMAP_OKAY; |
| 1555 | } |
| 1556 | |
| 1557 | /* Compile function for set community. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1558 | static void * |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 1559 | route_set_ecommunity_rt_compile (const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1560 | { |
| 1561 | struct ecommunity *ecom; |
| 1562 | |
| 1563 | ecom = ecommunity_str2com (arg, ECOMMUNITY_ROUTE_TARGET, 0); |
| 1564 | if (! ecom) |
| 1565 | return NULL; |
| 1566 | return ecom; |
| 1567 | } |
| 1568 | |
| 1569 | /* Free function for set community. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1570 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1571 | route_set_ecommunity_rt_free (void *rule) |
| 1572 | { |
| 1573 | struct ecommunity *ecom = rule; |
| 1574 | ecommunity_free (ecom); |
| 1575 | } |
| 1576 | |
| 1577 | /* Set community rule structure. */ |
| 1578 | struct route_map_rule_cmd route_set_ecommunity_rt_cmd = |
| 1579 | { |
| 1580 | "extcommunity rt", |
| 1581 | route_set_ecommunity_rt, |
| 1582 | route_set_ecommunity_rt_compile, |
| 1583 | route_set_ecommunity_rt_free, |
| 1584 | }; |
| 1585 | |
| 1586 | /* `set extcommunity soo COMMUNITY' */ |
| 1587 | |
| 1588 | /* For community set mechanism. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1589 | static route_map_result_t |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1590 | route_set_ecommunity_soo (void *rule, struct prefix *prefix, |
| 1591 | route_map_object_t type, void *object) |
| 1592 | { |
| 1593 | struct ecommunity *ecom; |
| 1594 | struct bgp_info *bgp_info; |
| 1595 | |
| 1596 | if (type == RMAP_BGP) |
| 1597 | { |
| 1598 | ecom = rule; |
| 1599 | bgp_info = object; |
| 1600 | |
| 1601 | if (! ecom) |
| 1602 | return RMAP_OKAY; |
| 1603 | |
| 1604 | bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_EXT_COMMUNITIES); |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1605 | (bgp_attr_extra_get (bgp_info->attr))->ecommunity = ecommunity_dup (ecom); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1606 | } |
| 1607 | return RMAP_OKAY; |
| 1608 | } |
| 1609 | |
| 1610 | /* Compile function for set community. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1611 | static void * |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 1612 | route_set_ecommunity_soo_compile (const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1613 | { |
| 1614 | struct ecommunity *ecom; |
| 1615 | |
| 1616 | ecom = ecommunity_str2com (arg, ECOMMUNITY_SITE_ORIGIN, 0); |
| 1617 | if (! ecom) |
| 1618 | return NULL; |
| 1619 | |
| 1620 | return ecom; |
| 1621 | } |
| 1622 | |
| 1623 | /* Free function for set community. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1624 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1625 | route_set_ecommunity_soo_free (void *rule) |
| 1626 | { |
| 1627 | struct ecommunity *ecom = rule; |
| 1628 | ecommunity_free (ecom); |
| 1629 | } |
| 1630 | |
| 1631 | /* Set community rule structure. */ |
| 1632 | struct route_map_rule_cmd route_set_ecommunity_soo_cmd = |
| 1633 | { |
| 1634 | "extcommunity soo", |
| 1635 | route_set_ecommunity_soo, |
| 1636 | route_set_ecommunity_soo_compile, |
| 1637 | route_set_ecommunity_soo_free, |
| 1638 | }; |
| 1639 | |
| 1640 | /* `set origin ORIGIN' */ |
| 1641 | |
| 1642 | /* For origin set. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1643 | static route_map_result_t |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1644 | route_set_origin (void *rule, struct prefix *prefix, route_map_object_t type, void *object) |
| 1645 | { |
| 1646 | u_char *origin; |
| 1647 | struct bgp_info *bgp_info; |
| 1648 | |
| 1649 | if (type == RMAP_BGP) |
| 1650 | { |
| 1651 | origin = rule; |
| 1652 | bgp_info = object; |
| 1653 | |
| 1654 | bgp_info->attr->origin = *origin; |
| 1655 | } |
| 1656 | |
| 1657 | return RMAP_OKAY; |
| 1658 | } |
| 1659 | |
| 1660 | /* Compile function for origin set. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1661 | static void * |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 1662 | route_set_origin_compile (const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1663 | { |
| 1664 | u_char *origin; |
| 1665 | |
| 1666 | origin = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_char)); |
| 1667 | |
| 1668 | if (strcmp (arg, "igp") == 0) |
| 1669 | *origin = 0; |
| 1670 | else if (strcmp (arg, "egp") == 0) |
| 1671 | *origin = 1; |
| 1672 | else |
| 1673 | *origin = 2; |
| 1674 | |
| 1675 | return origin; |
| 1676 | } |
| 1677 | |
| 1678 | /* Compile function for origin set. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1679 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1680 | route_set_origin_free (void *rule) |
| 1681 | { |
| 1682 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); |
| 1683 | } |
| 1684 | |
| 1685 | /* Set metric rule structure. */ |
| 1686 | struct route_map_rule_cmd route_set_origin_cmd = |
| 1687 | { |
| 1688 | "origin", |
| 1689 | route_set_origin, |
| 1690 | route_set_origin_compile, |
| 1691 | route_set_origin_free, |
| 1692 | }; |
| 1693 | |
| 1694 | /* `set atomic-aggregate' */ |
| 1695 | |
| 1696 | /* For atomic aggregate set. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1697 | static route_map_result_t |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1698 | route_set_atomic_aggregate (void *rule, struct prefix *prefix, |
| 1699 | route_map_object_t type, void *object) |
| 1700 | { |
| 1701 | struct bgp_info *bgp_info; |
| 1702 | |
| 1703 | if (type == RMAP_BGP) |
| 1704 | { |
| 1705 | bgp_info = object; |
| 1706 | bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE); |
| 1707 | } |
| 1708 | |
| 1709 | return RMAP_OKAY; |
| 1710 | } |
| 1711 | |
| 1712 | /* Compile function for atomic aggregate. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1713 | static void * |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 1714 | route_set_atomic_aggregate_compile (const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1715 | { |
| 1716 | return (void *)1; |
| 1717 | } |
| 1718 | |
| 1719 | /* Compile function for atomic aggregate. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1720 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1721 | route_set_atomic_aggregate_free (void *rule) |
| 1722 | { |
| 1723 | return; |
| 1724 | } |
| 1725 | |
| 1726 | /* Set atomic aggregate rule structure. */ |
| 1727 | struct route_map_rule_cmd route_set_atomic_aggregate_cmd = |
| 1728 | { |
| 1729 | "atomic-aggregate", |
| 1730 | route_set_atomic_aggregate, |
| 1731 | route_set_atomic_aggregate_compile, |
| 1732 | route_set_atomic_aggregate_free, |
| 1733 | }; |
| 1734 | |
| 1735 | /* `set aggregator as AS A.B.C.D' */ |
| 1736 | struct aggregator |
| 1737 | { |
| 1738 | as_t as; |
| 1739 | struct in_addr address; |
| 1740 | }; |
| 1741 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1742 | static route_map_result_t |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1743 | route_set_aggregator_as (void *rule, struct prefix *prefix, |
| 1744 | route_map_object_t type, void *object) |
| 1745 | { |
| 1746 | struct bgp_info *bgp_info; |
| 1747 | struct aggregator *aggregator; |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1748 | struct attr_extra *ae; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1749 | |
| 1750 | if (type == RMAP_BGP) |
| 1751 | { |
| 1752 | bgp_info = object; |
| 1753 | aggregator = rule; |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1754 | ae = bgp_attr_extra_get (bgp_info->attr); |
| 1755 | |
| 1756 | ae->aggregator_as = aggregator->as; |
| 1757 | ae->aggregator_addr = aggregator->address; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1758 | bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR); |
| 1759 | } |
| 1760 | |
| 1761 | return RMAP_OKAY; |
| 1762 | } |
| 1763 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1764 | static void * |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 1765 | route_set_aggregator_as_compile (const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1766 | { |
| 1767 | struct aggregator *aggregator; |
| 1768 | char as[10]; |
| 1769 | char address[20]; |
| 1770 | |
Stephen Hemminger | 393deb9 | 2008-08-18 14:13:29 -0700 | [diff] [blame] | 1771 | aggregator = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct aggregator)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1772 | sscanf (arg, "%s %s", as, address); |
| 1773 | |
| 1774 | aggregator->as = strtoul (as, NULL, 10); |
| 1775 | inet_aton (address, &aggregator->address); |
| 1776 | |
| 1777 | return aggregator; |
| 1778 | } |
| 1779 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1780 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1781 | route_set_aggregator_as_free (void *rule) |
| 1782 | { |
| 1783 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); |
| 1784 | } |
| 1785 | |
| 1786 | struct route_map_rule_cmd route_set_aggregator_as_cmd = |
| 1787 | { |
| 1788 | "aggregator as", |
| 1789 | route_set_aggregator_as, |
| 1790 | route_set_aggregator_as_compile, |
| 1791 | route_set_aggregator_as_free, |
| 1792 | }; |
| 1793 | |
| 1794 | #ifdef HAVE_IPV6 |
| 1795 | /* `match ipv6 address IP_ACCESS_LIST' */ |
| 1796 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1797 | static route_map_result_t |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1798 | route_match_ipv6_address (void *rule, struct prefix *prefix, |
| 1799 | route_map_object_t type, void *object) |
| 1800 | { |
| 1801 | struct access_list *alist; |
| 1802 | |
| 1803 | if (type == RMAP_BGP) |
| 1804 | { |
| 1805 | alist = access_list_lookup (AFI_IP6, (char *) rule); |
| 1806 | if (alist == NULL) |
| 1807 | return RMAP_NOMATCH; |
| 1808 | |
| 1809 | return (access_list_apply (alist, prefix) == FILTER_DENY ? |
| 1810 | RMAP_NOMATCH : RMAP_MATCH); |
| 1811 | } |
| 1812 | return RMAP_NOMATCH; |
| 1813 | } |
| 1814 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1815 | static void * |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 1816 | route_match_ipv6_address_compile (const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1817 | { |
| 1818 | return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg); |
| 1819 | } |
| 1820 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1821 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1822 | route_match_ipv6_address_free (void *rule) |
| 1823 | { |
| 1824 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); |
| 1825 | } |
| 1826 | |
| 1827 | /* Route map commands for ip address matching. */ |
| 1828 | struct route_map_rule_cmd route_match_ipv6_address_cmd = |
| 1829 | { |
| 1830 | "ipv6 address", |
| 1831 | route_match_ipv6_address, |
| 1832 | route_match_ipv6_address_compile, |
| 1833 | route_match_ipv6_address_free |
| 1834 | }; |
| 1835 | |
| 1836 | /* `match ipv6 next-hop IP_ADDRESS' */ |
| 1837 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1838 | static route_map_result_t |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1839 | route_match_ipv6_next_hop (void *rule, struct prefix *prefix, |
| 1840 | route_map_object_t type, void *object) |
| 1841 | { |
| 1842 | struct in6_addr *addr; |
| 1843 | struct bgp_info *bgp_info; |
| 1844 | |
| 1845 | if (type == RMAP_BGP) |
| 1846 | { |
| 1847 | addr = rule; |
| 1848 | bgp_info = object; |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1849 | |
| 1850 | if (!bgp_info->attr->extra) |
| 1851 | return RMAP_NOMATCH; |
| 1852 | |
| 1853 | if (IPV6_ADDR_SAME (&bgp_info->attr->extra->mp_nexthop_global, rule)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1854 | return RMAP_MATCH; |
| 1855 | |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1856 | if (bgp_info->attr->extra->mp_nexthop_len == 32 && |
| 1857 | IPV6_ADDR_SAME (&bgp_info->attr->extra->mp_nexthop_local, rule)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1858 | return RMAP_MATCH; |
| 1859 | |
| 1860 | return RMAP_NOMATCH; |
| 1861 | } |
| 1862 | |
| 1863 | return RMAP_NOMATCH; |
| 1864 | } |
| 1865 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1866 | static void * |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 1867 | route_match_ipv6_next_hop_compile (const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1868 | { |
| 1869 | struct in6_addr *address; |
| 1870 | int ret; |
| 1871 | |
| 1872 | address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr)); |
| 1873 | |
| 1874 | ret = inet_pton (AF_INET6, arg, address); |
| 1875 | if (!ret) |
| 1876 | { |
| 1877 | XFREE (MTYPE_ROUTE_MAP_COMPILED, address); |
| 1878 | return NULL; |
| 1879 | } |
| 1880 | |
| 1881 | return address; |
| 1882 | } |
| 1883 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1884 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1885 | route_match_ipv6_next_hop_free (void *rule) |
| 1886 | { |
| 1887 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); |
| 1888 | } |
| 1889 | |
| 1890 | struct route_map_rule_cmd route_match_ipv6_next_hop_cmd = |
| 1891 | { |
| 1892 | "ipv6 next-hop", |
| 1893 | route_match_ipv6_next_hop, |
| 1894 | route_match_ipv6_next_hop_compile, |
| 1895 | route_match_ipv6_next_hop_free |
| 1896 | }; |
| 1897 | |
| 1898 | /* `match ipv6 address prefix-list PREFIX_LIST' */ |
| 1899 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1900 | static route_map_result_t |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1901 | route_match_ipv6_address_prefix_list (void *rule, struct prefix *prefix, |
| 1902 | route_map_object_t type, void *object) |
| 1903 | { |
| 1904 | struct prefix_list *plist; |
| 1905 | |
| 1906 | if (type == RMAP_BGP) |
| 1907 | { |
| 1908 | plist = prefix_list_lookup (AFI_IP6, (char *) rule); |
| 1909 | if (plist == NULL) |
| 1910 | return RMAP_NOMATCH; |
| 1911 | |
| 1912 | return (prefix_list_apply (plist, prefix) == PREFIX_DENY ? |
| 1913 | RMAP_NOMATCH : RMAP_MATCH); |
| 1914 | } |
| 1915 | return RMAP_NOMATCH; |
| 1916 | } |
| 1917 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1918 | static void * |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 1919 | route_match_ipv6_address_prefix_list_compile (const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1920 | { |
| 1921 | return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg); |
| 1922 | } |
| 1923 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1924 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1925 | route_match_ipv6_address_prefix_list_free (void *rule) |
| 1926 | { |
| 1927 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); |
| 1928 | } |
| 1929 | |
| 1930 | struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd = |
| 1931 | { |
| 1932 | "ipv6 address prefix-list", |
| 1933 | route_match_ipv6_address_prefix_list, |
| 1934 | route_match_ipv6_address_prefix_list_compile, |
| 1935 | route_match_ipv6_address_prefix_list_free |
| 1936 | }; |
| 1937 | |
| 1938 | /* `set ipv6 nexthop global IP_ADDRESS' */ |
| 1939 | |
| 1940 | /* Set nexthop to object. ojbect must be pointer to struct attr. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1941 | static route_map_result_t |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1942 | route_set_ipv6_nexthop_global (void *rule, struct prefix *prefix, |
| 1943 | route_map_object_t type, void *object) |
| 1944 | { |
| 1945 | struct in6_addr *address; |
| 1946 | struct bgp_info *bgp_info; |
| 1947 | |
| 1948 | if (type == RMAP_BGP) |
| 1949 | { |
| 1950 | /* Fetch routemap's rule information. */ |
| 1951 | address = rule; |
| 1952 | bgp_info = object; |
| 1953 | |
| 1954 | /* Set next hop value. */ |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1955 | (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_global = *address; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1956 | |
| 1957 | /* Set nexthop length. */ |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 1958 | if (bgp_info->attr->extra->mp_nexthop_len == 0) |
| 1959 | bgp_info->attr->extra->mp_nexthop_len = 16; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1960 | } |
| 1961 | |
| 1962 | return RMAP_OKAY; |
| 1963 | } |
| 1964 | |
| 1965 | /* Route map `ip next-hop' compile function. Given string is converted |
| 1966 | to struct in_addr structure. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1967 | static void * |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 1968 | route_set_ipv6_nexthop_global_compile (const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1969 | { |
| 1970 | int ret; |
| 1971 | struct in6_addr *address; |
| 1972 | |
| 1973 | address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr)); |
| 1974 | |
| 1975 | ret = inet_pton (AF_INET6, arg, address); |
| 1976 | |
| 1977 | if (ret == 0) |
| 1978 | { |
| 1979 | XFREE (MTYPE_ROUTE_MAP_COMPILED, address); |
| 1980 | return NULL; |
| 1981 | } |
| 1982 | |
| 1983 | return address; |
| 1984 | } |
| 1985 | |
| 1986 | /* Free route map's compiled `ip next-hop' value. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1987 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1988 | route_set_ipv6_nexthop_global_free (void *rule) |
| 1989 | { |
| 1990 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); |
| 1991 | } |
| 1992 | |
| 1993 | /* Route map commands for ip nexthop set. */ |
| 1994 | struct route_map_rule_cmd route_set_ipv6_nexthop_global_cmd = |
| 1995 | { |
| 1996 | "ipv6 next-hop global", |
| 1997 | route_set_ipv6_nexthop_global, |
| 1998 | route_set_ipv6_nexthop_global_compile, |
| 1999 | route_set_ipv6_nexthop_global_free |
| 2000 | }; |
| 2001 | |
| 2002 | /* `set ipv6 nexthop local IP_ADDRESS' */ |
| 2003 | |
| 2004 | /* Set nexthop to object. ojbect must be pointer to struct attr. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 2005 | static route_map_result_t |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2006 | route_set_ipv6_nexthop_local (void *rule, struct prefix *prefix, |
| 2007 | route_map_object_t type, void *object) |
| 2008 | { |
| 2009 | struct in6_addr *address; |
| 2010 | struct bgp_info *bgp_info; |
| 2011 | |
| 2012 | if (type == RMAP_BGP) |
| 2013 | { |
| 2014 | /* Fetch routemap's rule information. */ |
| 2015 | address = rule; |
| 2016 | bgp_info = object; |
| 2017 | |
| 2018 | /* Set next hop value. */ |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 2019 | (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_local = *address; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2020 | |
| 2021 | /* Set nexthop length. */ |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 2022 | if (bgp_info->attr->extra->mp_nexthop_len != 32) |
| 2023 | bgp_info->attr->extra->mp_nexthop_len = 32; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2024 | } |
| 2025 | |
| 2026 | return RMAP_OKAY; |
| 2027 | } |
| 2028 | |
| 2029 | /* Route map `ip nexthop' compile function. Given string is converted |
| 2030 | to struct in_addr structure. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 2031 | static void * |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 2032 | route_set_ipv6_nexthop_local_compile (const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2033 | { |
| 2034 | int ret; |
| 2035 | struct in6_addr *address; |
| 2036 | |
| 2037 | address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr)); |
| 2038 | |
| 2039 | ret = inet_pton (AF_INET6, arg, address); |
| 2040 | |
| 2041 | if (ret == 0) |
| 2042 | { |
| 2043 | XFREE (MTYPE_ROUTE_MAP_COMPILED, address); |
| 2044 | return NULL; |
| 2045 | } |
| 2046 | |
| 2047 | return address; |
| 2048 | } |
| 2049 | |
| 2050 | /* Free route map's compiled `ip nexthop' value. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 2051 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2052 | route_set_ipv6_nexthop_local_free (void *rule) |
| 2053 | { |
| 2054 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); |
| 2055 | } |
| 2056 | |
| 2057 | /* Route map commands for ip nexthop set. */ |
| 2058 | struct route_map_rule_cmd route_set_ipv6_nexthop_local_cmd = |
| 2059 | { |
| 2060 | "ipv6 next-hop local", |
| 2061 | route_set_ipv6_nexthop_local, |
| 2062 | route_set_ipv6_nexthop_local_compile, |
| 2063 | route_set_ipv6_nexthop_local_free |
| 2064 | }; |
| 2065 | #endif /* HAVE_IPV6 */ |
| 2066 | |
| 2067 | /* `set vpnv4 nexthop A.B.C.D' */ |
| 2068 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 2069 | static route_map_result_t |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2070 | route_set_vpnv4_nexthop (void *rule, struct prefix *prefix, |
| 2071 | route_map_object_t type, void *object) |
| 2072 | { |
| 2073 | struct in_addr *address; |
| 2074 | struct bgp_info *bgp_info; |
| 2075 | |
| 2076 | if (type == RMAP_BGP) |
| 2077 | { |
| 2078 | /* Fetch routemap's rule information. */ |
| 2079 | address = rule; |
| 2080 | bgp_info = object; |
| 2081 | |
| 2082 | /* Set next hop value. */ |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 2083 | (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_global_in = *address; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2084 | } |
| 2085 | |
| 2086 | return RMAP_OKAY; |
| 2087 | } |
| 2088 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 2089 | static void * |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 2090 | route_set_vpnv4_nexthop_compile (const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2091 | { |
| 2092 | int ret; |
| 2093 | struct in_addr *address; |
| 2094 | |
| 2095 | address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr)); |
| 2096 | |
| 2097 | ret = inet_aton (arg, address); |
| 2098 | |
| 2099 | if (ret == 0) |
| 2100 | { |
| 2101 | XFREE (MTYPE_ROUTE_MAP_COMPILED, address); |
| 2102 | return NULL; |
| 2103 | } |
| 2104 | |
| 2105 | return address; |
| 2106 | } |
| 2107 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 2108 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2109 | route_set_vpnv4_nexthop_free (void *rule) |
| 2110 | { |
| 2111 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); |
| 2112 | } |
| 2113 | |
| 2114 | /* Route map commands for ip nexthop set. */ |
| 2115 | struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd = |
| 2116 | { |
| 2117 | "vpnv4 next-hop", |
| 2118 | route_set_vpnv4_nexthop, |
| 2119 | route_set_vpnv4_nexthop_compile, |
| 2120 | route_set_vpnv4_nexthop_free |
| 2121 | }; |
| 2122 | |
| 2123 | /* `set originator-id' */ |
| 2124 | |
| 2125 | /* For origin set. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 2126 | static route_map_result_t |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2127 | route_set_originator_id (void *rule, struct prefix *prefix, route_map_object_t type, void *object) |
| 2128 | { |
| 2129 | struct in_addr *address; |
| 2130 | struct bgp_info *bgp_info; |
| 2131 | |
| 2132 | if (type == RMAP_BGP) |
| 2133 | { |
| 2134 | address = rule; |
| 2135 | bgp_info = object; |
| 2136 | |
| 2137 | bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID); |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 2138 | (bgp_attr_extra_get (bgp_info->attr))->originator_id = *address; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2139 | } |
| 2140 | |
| 2141 | return RMAP_OKAY; |
| 2142 | } |
| 2143 | |
| 2144 | /* Compile function for originator-id set. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 2145 | static void * |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 2146 | route_set_originator_id_compile (const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2147 | { |
| 2148 | int ret; |
| 2149 | struct in_addr *address; |
| 2150 | |
| 2151 | address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr)); |
| 2152 | |
| 2153 | ret = inet_aton (arg, address); |
| 2154 | |
| 2155 | if (ret == 0) |
| 2156 | { |
| 2157 | XFREE (MTYPE_ROUTE_MAP_COMPILED, address); |
| 2158 | return NULL; |
| 2159 | } |
| 2160 | |
| 2161 | return address; |
| 2162 | } |
| 2163 | |
| 2164 | /* Compile function for originator_id set. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 2165 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2166 | route_set_originator_id_free (void *rule) |
| 2167 | { |
| 2168 | XFREE (MTYPE_ROUTE_MAP_COMPILED, rule); |
| 2169 | } |
| 2170 | |
| 2171 | /* Set metric rule structure. */ |
| 2172 | struct route_map_rule_cmd route_set_originator_id_cmd = |
| 2173 | { |
| 2174 | "originator-id", |
| 2175 | route_set_originator_id, |
| 2176 | route_set_originator_id_compile, |
| 2177 | route_set_originator_id_free, |
| 2178 | }; |
| 2179 | |
| 2180 | /* Add bgp route map rule. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 2181 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2182 | bgp_route_match_add (struct vty *vty, struct route_map_index *index, |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 2183 | const char *command, const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2184 | { |
| 2185 | int ret; |
| 2186 | |
| 2187 | ret = route_map_add_match (index, command, arg); |
| 2188 | if (ret) |
| 2189 | { |
| 2190 | switch (ret) |
| 2191 | { |
| 2192 | case RMAP_RULE_MISSING: |
| 2193 | vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE); |
| 2194 | return CMD_WARNING; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2195 | case RMAP_COMPILE_ERROR: |
| 2196 | vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE); |
| 2197 | return CMD_WARNING; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2198 | } |
| 2199 | } |
| 2200 | return CMD_SUCCESS; |
| 2201 | } |
| 2202 | |
| 2203 | /* Delete bgp route map rule. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 2204 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2205 | bgp_route_match_delete (struct vty *vty, struct route_map_index *index, |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 2206 | const char *command, const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2207 | { |
| 2208 | int ret; |
| 2209 | |
| 2210 | ret = route_map_delete_match (index, command, arg); |
| 2211 | if (ret) |
| 2212 | { |
| 2213 | switch (ret) |
| 2214 | { |
| 2215 | case RMAP_RULE_MISSING: |
| 2216 | vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE); |
| 2217 | return CMD_WARNING; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2218 | case RMAP_COMPILE_ERROR: |
| 2219 | vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE); |
| 2220 | return CMD_WARNING; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2221 | } |
| 2222 | } |
| 2223 | return CMD_SUCCESS; |
| 2224 | } |
| 2225 | |
| 2226 | /* Add bgp route map rule. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 2227 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2228 | bgp_route_set_add (struct vty *vty, struct route_map_index *index, |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 2229 | const char *command, const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2230 | { |
| 2231 | int ret; |
| 2232 | |
| 2233 | ret = route_map_add_set (index, command, arg); |
| 2234 | if (ret) |
| 2235 | { |
| 2236 | switch (ret) |
| 2237 | { |
| 2238 | case RMAP_RULE_MISSING: |
| 2239 | vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE); |
| 2240 | return CMD_WARNING; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2241 | case RMAP_COMPILE_ERROR: |
| 2242 | vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE); |
| 2243 | return CMD_WARNING; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2244 | } |
| 2245 | } |
| 2246 | return CMD_SUCCESS; |
| 2247 | } |
| 2248 | |
| 2249 | /* Delete bgp route map rule. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 2250 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2251 | bgp_route_set_delete (struct vty *vty, struct route_map_index *index, |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 2252 | const char *command, const char *arg) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2253 | { |
| 2254 | int ret; |
| 2255 | |
| 2256 | ret = route_map_delete_set (index, command, arg); |
| 2257 | if (ret) |
| 2258 | { |
| 2259 | switch (ret) |
| 2260 | { |
| 2261 | case RMAP_RULE_MISSING: |
| 2262 | vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE); |
| 2263 | return CMD_WARNING; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2264 | case RMAP_COMPILE_ERROR: |
| 2265 | vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE); |
| 2266 | return CMD_WARNING; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2267 | } |
| 2268 | } |
| 2269 | return CMD_SUCCESS; |
| 2270 | } |
| 2271 | |
| 2272 | /* Hook function for updating route_map assignment. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 2273 | static void |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 2274 | bgp_route_map_update (const char *unused) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2275 | { |
| 2276 | int i; |
| 2277 | afi_t afi; |
| 2278 | safi_t safi; |
| 2279 | int direct; |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 2280 | struct listnode *node, *nnode; |
| 2281 | struct listnode *mnode, *mnnode; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2282 | struct bgp *bgp; |
| 2283 | struct peer *peer; |
| 2284 | struct peer_group *group; |
| 2285 | struct bgp_filter *filter; |
| 2286 | struct bgp_node *bn; |
| 2287 | struct bgp_static *bgp_static; |
| 2288 | |
| 2289 | /* For neighbor route-map updates. */ |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 2290 | for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2291 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 2292 | for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2293 | { |
| 2294 | for (afi = AFI_IP; afi < AFI_MAX; afi++) |
| 2295 | for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) |
| 2296 | { |
| 2297 | filter = &peer->filter[afi][safi]; |
| 2298 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2299 | for (direct = RMAP_IN; direct < RMAP_MAX; direct++) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2300 | { |
| 2301 | if (filter->map[direct].name) |
| 2302 | filter->map[direct].map = |
| 2303 | route_map_lookup_by_name (filter->map[direct].name); |
| 2304 | else |
| 2305 | filter->map[direct].map = NULL; |
| 2306 | } |
| 2307 | |
| 2308 | if (filter->usmap.name) |
| 2309 | filter->usmap.map = route_map_lookup_by_name (filter->usmap.name); |
| 2310 | else |
| 2311 | filter->usmap.map = NULL; |
| 2312 | } |
| 2313 | } |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 2314 | for (ALL_LIST_ELEMENTS (bgp->group, node, nnode, group)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2315 | { |
| 2316 | for (afi = AFI_IP; afi < AFI_MAX; afi++) |
| 2317 | for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) |
| 2318 | { |
| 2319 | filter = &group->conf->filter[afi][safi]; |
| 2320 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2321 | for (direct = RMAP_IN; direct < RMAP_MAX; direct++) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2322 | { |
| 2323 | if (filter->map[direct].name) |
| 2324 | filter->map[direct].map = |
| 2325 | route_map_lookup_by_name (filter->map[direct].name); |
| 2326 | else |
| 2327 | filter->map[direct].map = NULL; |
| 2328 | } |
| 2329 | |
| 2330 | if (filter->usmap.name) |
| 2331 | filter->usmap.map = route_map_lookup_by_name (filter->usmap.name); |
| 2332 | else |
| 2333 | filter->usmap.map = NULL; |
| 2334 | } |
| 2335 | } |
| 2336 | } |
| 2337 | |
| 2338 | /* For default-originate route-map updates. */ |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 2339 | for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2340 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 2341 | for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2342 | { |
| 2343 | for (afi = AFI_IP; afi < AFI_MAX; afi++) |
| 2344 | for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) |
| 2345 | { |
| 2346 | if (peer->default_rmap[afi][safi].name) |
| 2347 | peer->default_rmap[afi][safi].map = |
| 2348 | route_map_lookup_by_name (peer->default_rmap[afi][safi].name); |
| 2349 | else |
| 2350 | peer->default_rmap[afi][safi].map = NULL; |
| 2351 | } |
| 2352 | } |
| 2353 | } |
| 2354 | |
| 2355 | /* For network route-map updates. */ |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 2356 | for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2357 | { |
| 2358 | for (afi = AFI_IP; afi < AFI_MAX; afi++) |
| 2359 | for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) |
| 2360 | for (bn = bgp_table_top (bgp->route[afi][safi]); bn; |
| 2361 | bn = bgp_route_next (bn)) |
| 2362 | if ((bgp_static = bn->info) != NULL) |
| 2363 | { |
| 2364 | if (bgp_static->rmap.name) |
| 2365 | bgp_static->rmap.map = |
| 2366 | route_map_lookup_by_name (bgp_static->rmap.name); |
| 2367 | else |
| 2368 | bgp_static->rmap.map = NULL; |
| 2369 | } |
| 2370 | } |
| 2371 | |
| 2372 | /* For redistribute route-map updates. */ |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 2373 | for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2374 | { |
| 2375 | for (i = 0; i < ZEBRA_ROUTE_MAX; i++) |
| 2376 | { |
| 2377 | if (bgp->rmap[ZEBRA_FAMILY_IPV4][i].name) |
| 2378 | bgp->rmap[ZEBRA_FAMILY_IPV4][i].map = |
| 2379 | route_map_lookup_by_name (bgp->rmap[ZEBRA_FAMILY_IPV4][i].name); |
| 2380 | #ifdef HAVE_IPV6 |
| 2381 | if (bgp->rmap[ZEBRA_FAMILY_IPV6][i].name) |
| 2382 | bgp->rmap[ZEBRA_FAMILY_IPV6][i].map = |
| 2383 | route_map_lookup_by_name (bgp->rmap[ZEBRA_FAMILY_IPV6][i].name); |
| 2384 | #endif /* HAVE_IPV6 */ |
| 2385 | } |
| 2386 | } |
| 2387 | } |
| 2388 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 2389 | DEFUN (match_peer, |
| 2390 | match_peer_cmd, |
| 2391 | "match peer (A.B.C.D|X:X::X:X)", |
| 2392 | MATCH_STR |
| 2393 | "Match peer address\n" |
| 2394 | "IPv6 address of peer\n" |
| 2395 | "IP address of peer\n") |
| 2396 | { |
| 2397 | return bgp_route_match_add (vty, vty->index, "peer", argv[0]); |
| 2398 | } |
| 2399 | |
| 2400 | DEFUN (match_peer_local, |
| 2401 | match_peer_local_cmd, |
| 2402 | "match peer local", |
| 2403 | MATCH_STR |
| 2404 | "Match peer address\n" |
| 2405 | "Static or Redistributed routes\n") |
| 2406 | { |
| 2407 | return bgp_route_match_add (vty, vty->index, "peer", NULL); |
| 2408 | } |
| 2409 | |
| 2410 | DEFUN (no_match_peer, |
| 2411 | no_match_peer_cmd, |
| 2412 | "no match peer", |
| 2413 | NO_STR |
| 2414 | MATCH_STR |
| 2415 | "Match peer address\n") |
| 2416 | { |
| 2417 | if (argc == 0) |
| 2418 | return bgp_route_match_delete (vty, vty->index, "peer", NULL); |
| 2419 | |
| 2420 | return bgp_route_match_delete (vty, vty->index, "peer", argv[0]); |
| 2421 | } |
| 2422 | |
| 2423 | ALIAS (no_match_peer, |
| 2424 | no_match_peer_val_cmd, |
| 2425 | "no match peer (A.B.C.D|X:X::X:X)", |
| 2426 | NO_STR |
| 2427 | MATCH_STR |
| 2428 | "Match peer address\n" |
| 2429 | "IPv6 address of peer\n" |
| 2430 | "IP address of peer\n") |
| 2431 | |
| 2432 | ALIAS (no_match_peer, |
| 2433 | no_match_peer_local_cmd, |
| 2434 | "no match peer local", |
| 2435 | NO_STR |
| 2436 | MATCH_STR |
| 2437 | "Match peer address\n" |
| 2438 | "Static or Redistributed routes\n") |
| 2439 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2440 | DEFUN (match_ip_address, |
| 2441 | match_ip_address_cmd, |
| 2442 | "match ip address (<1-199>|<1300-2699>|WORD)", |
| 2443 | MATCH_STR |
| 2444 | IP_STR |
| 2445 | "Match address of route\n" |
| 2446 | "IP access-list number\n" |
| 2447 | "IP access-list number (expanded range)\n" |
| 2448 | "IP Access-list name\n") |
| 2449 | { |
| 2450 | return bgp_route_match_add (vty, vty->index, "ip address", argv[0]); |
| 2451 | } |
| 2452 | |
| 2453 | DEFUN (no_match_ip_address, |
| 2454 | no_match_ip_address_cmd, |
| 2455 | "no match ip address", |
| 2456 | NO_STR |
| 2457 | MATCH_STR |
| 2458 | IP_STR |
| 2459 | "Match address of route\n") |
| 2460 | { |
| 2461 | if (argc == 0) |
| 2462 | return bgp_route_match_delete (vty, vty->index, "ip address", NULL); |
| 2463 | |
| 2464 | return bgp_route_match_delete (vty, vty->index, "ip address", argv[0]); |
| 2465 | } |
| 2466 | |
| 2467 | ALIAS (no_match_ip_address, |
| 2468 | no_match_ip_address_val_cmd, |
| 2469 | "no match ip address (<1-199>|<1300-2699>|WORD)", |
| 2470 | NO_STR |
| 2471 | MATCH_STR |
| 2472 | IP_STR |
| 2473 | "Match address of route\n" |
| 2474 | "IP access-list number\n" |
| 2475 | "IP access-list number (expanded range)\n" |
| 2476 | "IP Access-list name\n") |
| 2477 | |
| 2478 | DEFUN (match_ip_next_hop, |
| 2479 | match_ip_next_hop_cmd, |
| 2480 | "match ip next-hop (<1-199>|<1300-2699>|WORD)", |
| 2481 | MATCH_STR |
| 2482 | IP_STR |
| 2483 | "Match next-hop address of route\n" |
| 2484 | "IP access-list number\n" |
| 2485 | "IP access-list number (expanded range)\n" |
| 2486 | "IP Access-list name\n") |
| 2487 | { |
| 2488 | return bgp_route_match_add (vty, vty->index, "ip next-hop", argv[0]); |
| 2489 | } |
| 2490 | |
| 2491 | DEFUN (no_match_ip_next_hop, |
| 2492 | no_match_ip_next_hop_cmd, |
| 2493 | "no match ip next-hop", |
| 2494 | NO_STR |
| 2495 | MATCH_STR |
| 2496 | IP_STR |
| 2497 | "Match next-hop address of route\n") |
| 2498 | { |
| 2499 | if (argc == 0) |
| 2500 | return bgp_route_match_delete (vty, vty->index, "ip next-hop", NULL); |
| 2501 | |
| 2502 | return bgp_route_match_delete (vty, vty->index, "ip next-hop", argv[0]); |
| 2503 | } |
| 2504 | |
| 2505 | ALIAS (no_match_ip_next_hop, |
| 2506 | no_match_ip_next_hop_val_cmd, |
| 2507 | "no match ip next-hop (<1-199>|<1300-2699>|WORD)", |
| 2508 | NO_STR |
| 2509 | MATCH_STR |
| 2510 | IP_STR |
| 2511 | "Match next-hop address of route\n" |
| 2512 | "IP access-list number\n" |
| 2513 | "IP access-list number (expanded range)\n" |
| 2514 | "IP Access-list name\n") |
| 2515 | |
Vyacheslav Trushkin | 1c8afb7 | 2011-11-22 20:15:10 +0400 | [diff] [blame] | 2516 | /* match probability { */ |
| 2517 | |
| 2518 | DEFUN (match_probability, |
| 2519 | match_probability_cmd, |
| 2520 | "match probability <0-100>", |
| 2521 | MATCH_STR |
| 2522 | "Match portion of routes defined by percentage value\n" |
| 2523 | "Percentage of routes\n") |
| 2524 | { |
| 2525 | return bgp_route_match_add (vty, vty->index, "probability", argv[0]); |
| 2526 | } |
| 2527 | |
| 2528 | DEFUN (no_match_probability, |
| 2529 | no_match_probability_cmd, |
| 2530 | "no match probability", |
| 2531 | NO_STR |
| 2532 | MATCH_STR |
| 2533 | "Match portion of routes defined by percentage value\n") |
| 2534 | { |
| 2535 | return bgp_route_match_delete (vty, vty->index, "probability", argc ? argv[0] : NULL); |
| 2536 | } |
| 2537 | |
| 2538 | ALIAS (no_match_probability, |
| 2539 | no_match_probability_val_cmd, |
| 2540 | "no match probability <1-99>", |
| 2541 | NO_STR |
| 2542 | MATCH_STR |
| 2543 | "Match portion of routes defined by percentage value\n" |
| 2544 | "Percentage of routes\n") |
| 2545 | |
| 2546 | /* } */ |
| 2547 | |
hasso | c1643bb | 2005-02-02 16:43:17 +0000 | [diff] [blame] | 2548 | DEFUN (match_ip_route_source, |
| 2549 | match_ip_route_source_cmd, |
| 2550 | "match ip route-source (<1-199>|<1300-2699>|WORD)", |
| 2551 | MATCH_STR |
| 2552 | IP_STR |
| 2553 | "Match advertising source address of route\n" |
| 2554 | "IP access-list number\n" |
| 2555 | "IP access-list number (expanded range)\n" |
| 2556 | "IP standard access-list name\n") |
| 2557 | { |
| 2558 | return bgp_route_match_add (vty, vty->index, "ip route-source", argv[0]); |
| 2559 | } |
| 2560 | |
| 2561 | DEFUN (no_match_ip_route_source, |
| 2562 | no_match_ip_route_source_cmd, |
| 2563 | "no match ip route-source", |
| 2564 | NO_STR |
| 2565 | MATCH_STR |
| 2566 | IP_STR |
| 2567 | "Match advertising source address of route\n") |
| 2568 | { |
| 2569 | if (argc == 0) |
| 2570 | return bgp_route_match_delete (vty, vty->index, "ip route-source", NULL); |
| 2571 | |
| 2572 | return bgp_route_match_delete (vty, vty->index, "ip route-source", argv[0]); |
| 2573 | } |
| 2574 | |
| 2575 | ALIAS (no_match_ip_route_source, |
| 2576 | no_match_ip_route_source_val_cmd, |
| 2577 | "no match ip route-source (<1-199>|<1300-2699>|WORD)", |
| 2578 | NO_STR |
| 2579 | MATCH_STR |
| 2580 | IP_STR |
| 2581 | "Match advertising source address of route\n" |
| 2582 | "IP access-list number\n" |
| 2583 | "IP access-list number (expanded range)\n" |
Paul Jakma | 30a2231 | 2008-08-15 14:05:22 +0100 | [diff] [blame] | 2584 | "IP standard access-list name\n") |
hasso | c1643bb | 2005-02-02 16:43:17 +0000 | [diff] [blame] | 2585 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2586 | DEFUN (match_ip_address_prefix_list, |
| 2587 | match_ip_address_prefix_list_cmd, |
| 2588 | "match ip address prefix-list WORD", |
| 2589 | MATCH_STR |
| 2590 | IP_STR |
| 2591 | "Match address of route\n" |
| 2592 | "Match entries of prefix-lists\n" |
| 2593 | "IP prefix-list name\n") |
| 2594 | { |
| 2595 | return bgp_route_match_add (vty, vty->index, "ip address prefix-list", argv[0]); |
| 2596 | } |
| 2597 | |
| 2598 | DEFUN (no_match_ip_address_prefix_list, |
| 2599 | no_match_ip_address_prefix_list_cmd, |
| 2600 | "no match ip address prefix-list", |
| 2601 | NO_STR |
| 2602 | MATCH_STR |
| 2603 | IP_STR |
| 2604 | "Match address of route\n" |
| 2605 | "Match entries of prefix-lists\n") |
| 2606 | { |
| 2607 | if (argc == 0) |
| 2608 | return bgp_route_match_delete (vty, vty->index, "ip address prefix-list", NULL); |
| 2609 | |
| 2610 | return bgp_route_match_delete (vty, vty->index, "ip address prefix-list", argv[0]); |
| 2611 | } |
| 2612 | |
| 2613 | ALIAS (no_match_ip_address_prefix_list, |
| 2614 | no_match_ip_address_prefix_list_val_cmd, |
| 2615 | "no match ip address prefix-list WORD", |
| 2616 | NO_STR |
| 2617 | MATCH_STR |
| 2618 | IP_STR |
| 2619 | "Match address of route\n" |
| 2620 | "Match entries of prefix-lists\n" |
| 2621 | "IP prefix-list name\n") |
| 2622 | |
| 2623 | DEFUN (match_ip_next_hop_prefix_list, |
| 2624 | match_ip_next_hop_prefix_list_cmd, |
| 2625 | "match ip next-hop prefix-list WORD", |
| 2626 | MATCH_STR |
| 2627 | IP_STR |
| 2628 | "Match next-hop address of route\n" |
| 2629 | "Match entries of prefix-lists\n" |
| 2630 | "IP prefix-list name\n") |
| 2631 | { |
| 2632 | return bgp_route_match_add (vty, vty->index, "ip next-hop prefix-list", argv[0]); |
| 2633 | } |
| 2634 | |
| 2635 | DEFUN (no_match_ip_next_hop_prefix_list, |
| 2636 | no_match_ip_next_hop_prefix_list_cmd, |
| 2637 | "no match ip next-hop prefix-list", |
| 2638 | NO_STR |
| 2639 | MATCH_STR |
| 2640 | IP_STR |
| 2641 | "Match next-hop address of route\n" |
| 2642 | "Match entries of prefix-lists\n") |
| 2643 | { |
| 2644 | if (argc == 0) |
| 2645 | return bgp_route_match_delete (vty, vty->index, "ip next-hop prefix-list", NULL); |
| 2646 | |
| 2647 | return bgp_route_match_delete (vty, vty->index, "ip next-hop prefix-list", argv[0]); |
| 2648 | } |
| 2649 | |
| 2650 | ALIAS (no_match_ip_next_hop_prefix_list, |
| 2651 | no_match_ip_next_hop_prefix_list_val_cmd, |
| 2652 | "no match ip next-hop prefix-list WORD", |
| 2653 | NO_STR |
| 2654 | MATCH_STR |
| 2655 | IP_STR |
| 2656 | "Match next-hop address of route\n" |
| 2657 | "Match entries of prefix-lists\n" |
| 2658 | "IP prefix-list name\n") |
| 2659 | |
hasso | c1643bb | 2005-02-02 16:43:17 +0000 | [diff] [blame] | 2660 | DEFUN (match_ip_route_source_prefix_list, |
| 2661 | match_ip_route_source_prefix_list_cmd, |
| 2662 | "match ip route-source prefix-list WORD", |
| 2663 | MATCH_STR |
| 2664 | IP_STR |
| 2665 | "Match advertising source address of route\n" |
| 2666 | "Match entries of prefix-lists\n" |
| 2667 | "IP prefix-list name\n") |
| 2668 | { |
| 2669 | return bgp_route_match_add (vty, vty->index, "ip route-source prefix-list", argv[0]); |
| 2670 | } |
| 2671 | |
| 2672 | DEFUN (no_match_ip_route_source_prefix_list, |
| 2673 | no_match_ip_route_source_prefix_list_cmd, |
| 2674 | "no match ip route-source prefix-list", |
| 2675 | NO_STR |
| 2676 | MATCH_STR |
| 2677 | IP_STR |
| 2678 | "Match advertising source address of route\n" |
| 2679 | "Match entries of prefix-lists\n") |
| 2680 | { |
| 2681 | if (argc == 0) |
| 2682 | return bgp_route_match_delete (vty, vty->index, "ip route-source prefix-list", NULL); |
| 2683 | |
| 2684 | return bgp_route_match_delete (vty, vty->index, "ip route-source prefix-list", argv[0]); |
| 2685 | } |
| 2686 | |
| 2687 | ALIAS (no_match_ip_route_source_prefix_list, |
| 2688 | no_match_ip_route_source_prefix_list_val_cmd, |
| 2689 | "no match ip route-source prefix-list WORD", |
| 2690 | NO_STR |
| 2691 | MATCH_STR |
| 2692 | IP_STR |
| 2693 | "Match advertising source address of route\n" |
| 2694 | "Match entries of prefix-lists\n" |
Paul Jakma | 30a2231 | 2008-08-15 14:05:22 +0100 | [diff] [blame] | 2695 | "IP prefix-list name\n") |
hasso | c1643bb | 2005-02-02 16:43:17 +0000 | [diff] [blame] | 2696 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2697 | DEFUN (match_metric, |
| 2698 | match_metric_cmd, |
| 2699 | "match metric <0-4294967295>", |
| 2700 | MATCH_STR |
| 2701 | "Match metric of route\n" |
| 2702 | "Metric value\n") |
| 2703 | { |
| 2704 | return bgp_route_match_add (vty, vty->index, "metric", argv[0]); |
| 2705 | } |
| 2706 | |
| 2707 | DEFUN (no_match_metric, |
| 2708 | no_match_metric_cmd, |
| 2709 | "no match metric", |
| 2710 | NO_STR |
| 2711 | MATCH_STR |
| 2712 | "Match metric of route\n") |
| 2713 | { |
| 2714 | if (argc == 0) |
| 2715 | return bgp_route_match_delete (vty, vty->index, "metric", NULL); |
| 2716 | |
| 2717 | return bgp_route_match_delete (vty, vty->index, "metric", argv[0]); |
| 2718 | } |
| 2719 | |
| 2720 | ALIAS (no_match_metric, |
| 2721 | no_match_metric_val_cmd, |
| 2722 | "no match metric <0-4294967295>", |
| 2723 | NO_STR |
| 2724 | MATCH_STR |
| 2725 | "Match metric of route\n" |
| 2726 | "Metric value\n") |
| 2727 | |
| 2728 | DEFUN (match_community, |
| 2729 | match_community_cmd, |
hasso | fee6e4e | 2005-02-02 16:29:31 +0000 | [diff] [blame] | 2730 | "match community (<1-99>|<100-500>|WORD)", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2731 | MATCH_STR |
| 2732 | "Match BGP community list\n" |
| 2733 | "Community-list number (standard)\n" |
| 2734 | "Community-list number (expanded)\n" |
| 2735 | "Community-list name\n") |
| 2736 | { |
| 2737 | return bgp_route_match_add (vty, vty->index, "community", argv[0]); |
| 2738 | } |
| 2739 | |
| 2740 | DEFUN (match_community_exact, |
| 2741 | match_community_exact_cmd, |
hasso | fee6e4e | 2005-02-02 16:29:31 +0000 | [diff] [blame] | 2742 | "match community (<1-99>|<100-500>|WORD) exact-match", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2743 | MATCH_STR |
| 2744 | "Match BGP community list\n" |
| 2745 | "Community-list number (standard)\n" |
| 2746 | "Community-list number (expanded)\n" |
| 2747 | "Community-list name\n" |
| 2748 | "Do exact matching of communities\n") |
| 2749 | { |
| 2750 | int ret; |
| 2751 | char *argstr; |
| 2752 | |
| 2753 | argstr = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, |
| 2754 | strlen (argv[0]) + strlen ("exact-match") + 2); |
| 2755 | |
| 2756 | sprintf (argstr, "%s exact-match", argv[0]); |
| 2757 | |
| 2758 | ret = bgp_route_match_add (vty, vty->index, "community", argstr); |
| 2759 | |
| 2760 | XFREE (MTYPE_ROUTE_MAP_COMPILED, argstr); |
| 2761 | |
| 2762 | return ret; |
| 2763 | } |
| 2764 | |
| 2765 | DEFUN (no_match_community, |
| 2766 | no_match_community_cmd, |
| 2767 | "no match community", |
| 2768 | NO_STR |
| 2769 | MATCH_STR |
| 2770 | "Match BGP community list\n") |
| 2771 | { |
| 2772 | return bgp_route_match_delete (vty, vty->index, "community", NULL); |
| 2773 | } |
| 2774 | |
| 2775 | ALIAS (no_match_community, |
| 2776 | no_match_community_val_cmd, |
hasso | fee6e4e | 2005-02-02 16:29:31 +0000 | [diff] [blame] | 2777 | "no match community (<1-99>|<100-500>|WORD)", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2778 | NO_STR |
| 2779 | MATCH_STR |
| 2780 | "Match BGP community list\n" |
| 2781 | "Community-list number (standard)\n" |
| 2782 | "Community-list number (expanded)\n" |
| 2783 | "Community-list name\n") |
| 2784 | |
| 2785 | ALIAS (no_match_community, |
| 2786 | no_match_community_exact_cmd, |
hasso | fee6e4e | 2005-02-02 16:29:31 +0000 | [diff] [blame] | 2787 | "no match community (<1-99>|<100-500>|WORD) exact-match", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2788 | NO_STR |
| 2789 | MATCH_STR |
| 2790 | "Match BGP community list\n" |
| 2791 | "Community-list number (standard)\n" |
| 2792 | "Community-list number (expanded)\n" |
| 2793 | "Community-list name\n" |
| 2794 | "Do exact matching of communities\n") |
| 2795 | |
paul | 73ffb25 | 2003-04-19 15:49:49 +0000 | [diff] [blame] | 2796 | DEFUN (match_ecommunity, |
| 2797 | match_ecommunity_cmd, |
hasso | fee6e4e | 2005-02-02 16:29:31 +0000 | [diff] [blame] | 2798 | "match extcommunity (<1-99>|<100-500>|WORD)", |
paul | 73ffb25 | 2003-04-19 15:49:49 +0000 | [diff] [blame] | 2799 | MATCH_STR |
| 2800 | "Match BGP/VPN extended community list\n" |
| 2801 | "Extended community-list number (standard)\n" |
| 2802 | "Extended community-list number (expanded)\n" |
| 2803 | "Extended community-list name\n") |
| 2804 | { |
| 2805 | return bgp_route_match_add (vty, vty->index, "extcommunity", argv[0]); |
| 2806 | } |
| 2807 | |
| 2808 | DEFUN (no_match_ecommunity, |
| 2809 | no_match_ecommunity_cmd, |
| 2810 | "no match extcommunity", |
| 2811 | NO_STR |
| 2812 | MATCH_STR |
| 2813 | "Match BGP/VPN extended community list\n") |
| 2814 | { |
| 2815 | return bgp_route_match_delete (vty, vty->index, "extcommunity", NULL); |
| 2816 | } |
| 2817 | |
| 2818 | ALIAS (no_match_ecommunity, |
| 2819 | no_match_ecommunity_val_cmd, |
hasso | fee6e4e | 2005-02-02 16:29:31 +0000 | [diff] [blame] | 2820 | "no match extcommunity (<1-99>|<100-500>|WORD)", |
paul | 73ffb25 | 2003-04-19 15:49:49 +0000 | [diff] [blame] | 2821 | NO_STR |
| 2822 | MATCH_STR |
| 2823 | "Match BGP/VPN extended community list\n" |
| 2824 | "Extended community-list number (standard)\n" |
| 2825 | "Extended community-list number (expanded)\n" |
| 2826 | "Extended community-list name\n") |
| 2827 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2828 | DEFUN (match_aspath, |
| 2829 | match_aspath_cmd, |
| 2830 | "match as-path WORD", |
| 2831 | MATCH_STR |
| 2832 | "Match BGP AS path list\n" |
| 2833 | "AS path access-list name\n") |
| 2834 | { |
| 2835 | return bgp_route_match_add (vty, vty->index, "as-path", argv[0]); |
| 2836 | } |
| 2837 | |
| 2838 | DEFUN (no_match_aspath, |
| 2839 | no_match_aspath_cmd, |
| 2840 | "no match as-path", |
| 2841 | NO_STR |
| 2842 | MATCH_STR |
| 2843 | "Match BGP AS path list\n") |
| 2844 | { |
| 2845 | return bgp_route_match_delete (vty, vty->index, "as-path", NULL); |
| 2846 | } |
| 2847 | |
| 2848 | ALIAS (no_match_aspath, |
| 2849 | no_match_aspath_val_cmd, |
| 2850 | "no match as-path WORD", |
| 2851 | NO_STR |
| 2852 | MATCH_STR |
| 2853 | "Match BGP AS path list\n" |
| 2854 | "AS path access-list name\n") |
| 2855 | |
| 2856 | DEFUN (match_origin, |
| 2857 | match_origin_cmd, |
| 2858 | "match origin (egp|igp|incomplete)", |
| 2859 | MATCH_STR |
| 2860 | "BGP origin code\n" |
| 2861 | "remote EGP\n" |
| 2862 | "local IGP\n" |
| 2863 | "unknown heritage\n") |
| 2864 | { |
| 2865 | if (strncmp (argv[0], "igp", 2) == 0) |
| 2866 | return bgp_route_match_add (vty, vty->index, "origin", "igp"); |
| 2867 | if (strncmp (argv[0], "egp", 1) == 0) |
| 2868 | return bgp_route_match_add (vty, vty->index, "origin", "egp"); |
| 2869 | if (strncmp (argv[0], "incomplete", 2) == 0) |
| 2870 | return bgp_route_match_add (vty, vty->index, "origin", "incomplete"); |
| 2871 | |
| 2872 | return CMD_WARNING; |
| 2873 | } |
| 2874 | |
| 2875 | DEFUN (no_match_origin, |
| 2876 | no_match_origin_cmd, |
| 2877 | "no match origin", |
| 2878 | NO_STR |
| 2879 | MATCH_STR |
| 2880 | "BGP origin code\n") |
| 2881 | { |
| 2882 | return bgp_route_match_delete (vty, vty->index, "origin", NULL); |
| 2883 | } |
| 2884 | |
| 2885 | ALIAS (no_match_origin, |
| 2886 | no_match_origin_val_cmd, |
| 2887 | "no match origin (egp|igp|incomplete)", |
| 2888 | NO_STR |
| 2889 | MATCH_STR |
| 2890 | "BGP origin code\n" |
| 2891 | "remote EGP\n" |
| 2892 | "local IGP\n" |
| 2893 | "unknown heritage\n") |
| 2894 | |
| 2895 | DEFUN (set_ip_nexthop, |
| 2896 | set_ip_nexthop_cmd, |
paul | af5cd0a | 2003-11-02 07:24:40 +0000 | [diff] [blame] | 2897 | "set ip next-hop A.B.C.D", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2898 | SET_STR |
| 2899 | IP_STR |
| 2900 | "Next hop address\n" |
paul | af5cd0a | 2003-11-02 07:24:40 +0000 | [diff] [blame] | 2901 | "IP address of next hop\n") |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2902 | { |
| 2903 | union sockunion su; |
| 2904 | int ret; |
| 2905 | |
| 2906 | ret = str2sockunion (argv[0], &su); |
| 2907 | if (ret < 0) |
| 2908 | { |
| 2909 | vty_out (vty, "%% Malformed Next-hop address%s", VTY_NEWLINE); |
| 2910 | return CMD_WARNING; |
| 2911 | } |
| 2912 | |
| 2913 | return bgp_route_set_add (vty, vty->index, "ip next-hop", argv[0]); |
| 2914 | } |
| 2915 | |
paul | af5cd0a | 2003-11-02 07:24:40 +0000 | [diff] [blame] | 2916 | DEFUN (set_ip_nexthop_peer, |
| 2917 | set_ip_nexthop_peer_cmd, |
| 2918 | "set ip next-hop peer-address", |
| 2919 | SET_STR |
| 2920 | IP_STR |
| 2921 | "Next hop address\n" |
| 2922 | "Use peer address (for BGP only)\n") |
| 2923 | { |
| 2924 | return bgp_route_set_add (vty, vty->index, "ip next-hop", "peer-address"); |
| 2925 | } |
| 2926 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 2927 | DEFUN_DEPRECATED (no_set_ip_nexthop_peer, |
paul | af5cd0a | 2003-11-02 07:24:40 +0000 | [diff] [blame] | 2928 | no_set_ip_nexthop_peer_cmd, |
| 2929 | "no set ip next-hop peer-address", |
| 2930 | NO_STR |
| 2931 | SET_STR |
| 2932 | IP_STR |
| 2933 | "Next hop address\n" |
| 2934 | "Use peer address (for BGP only)\n") |
| 2935 | { |
| 2936 | return bgp_route_set_delete (vty, vty->index, "ip next-hop", NULL); |
| 2937 | } |
| 2938 | |
| 2939 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2940 | DEFUN (no_set_ip_nexthop, |
| 2941 | no_set_ip_nexthop_cmd, |
| 2942 | "no set ip next-hop", |
| 2943 | NO_STR |
| 2944 | SET_STR |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2945 | "Next hop address\n") |
| 2946 | { |
paul | af5cd0a | 2003-11-02 07:24:40 +0000 | [diff] [blame] | 2947 | if (argc == 0) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2948 | return bgp_route_set_delete (vty, vty->index, "ip next-hop", NULL); |
| 2949 | |
| 2950 | return bgp_route_set_delete (vty, vty->index, "ip next-hop", argv[0]); |
| 2951 | } |
| 2952 | |
| 2953 | ALIAS (no_set_ip_nexthop, |
| 2954 | no_set_ip_nexthop_val_cmd, |
paul | af5cd0a | 2003-11-02 07:24:40 +0000 | [diff] [blame] | 2955 | "no set ip next-hop A.B.C.D", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2956 | NO_STR |
| 2957 | SET_STR |
| 2958 | IP_STR |
| 2959 | "Next hop address\n" |
paul | af5cd0a | 2003-11-02 07:24:40 +0000 | [diff] [blame] | 2960 | "IP address of next hop\n") |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2961 | |
| 2962 | DEFUN (set_metric, |
| 2963 | set_metric_cmd, |
paul | 73ffb25 | 2003-04-19 15:49:49 +0000 | [diff] [blame] | 2964 | "set metric <0-4294967295>", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2965 | SET_STR |
| 2966 | "Metric value for destination routing protocol\n" |
paul | 73ffb25 | 2003-04-19 15:49:49 +0000 | [diff] [blame] | 2967 | "Metric value\n") |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2968 | { |
| 2969 | return bgp_route_set_add (vty, vty->index, "metric", argv[0]); |
| 2970 | } |
| 2971 | |
paul | 73ffb25 | 2003-04-19 15:49:49 +0000 | [diff] [blame] | 2972 | ALIAS (set_metric, |
| 2973 | set_metric_addsub_cmd, |
| 2974 | "set metric <+/-metric>", |
| 2975 | SET_STR |
| 2976 | "Metric value for destination routing protocol\n" |
hasso | 033e861 | 2005-05-28 04:50:54 +0000 | [diff] [blame] | 2977 | "Add or subtract metric\n") |
paul | 73ffb25 | 2003-04-19 15:49:49 +0000 | [diff] [blame] | 2978 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2979 | DEFUN (no_set_metric, |
| 2980 | no_set_metric_cmd, |
| 2981 | "no set metric", |
| 2982 | NO_STR |
| 2983 | SET_STR |
| 2984 | "Metric value for destination routing protocol\n") |
| 2985 | { |
| 2986 | if (argc == 0) |
| 2987 | return bgp_route_set_delete (vty, vty->index, "metric", NULL); |
| 2988 | |
| 2989 | return bgp_route_set_delete (vty, vty->index, "metric", argv[0]); |
| 2990 | } |
| 2991 | |
| 2992 | ALIAS (no_set_metric, |
| 2993 | no_set_metric_val_cmd, |
| 2994 | "no set metric <0-4294967295>", |
| 2995 | NO_STR |
| 2996 | SET_STR |
| 2997 | "Metric value for destination routing protocol\n" |
| 2998 | "Metric value\n") |
| 2999 | |
| 3000 | DEFUN (set_local_pref, |
| 3001 | set_local_pref_cmd, |
| 3002 | "set local-preference <0-4294967295>", |
| 3003 | SET_STR |
| 3004 | "BGP local preference path attribute\n" |
| 3005 | "Preference value\n") |
| 3006 | { |
| 3007 | return bgp_route_set_add (vty, vty->index, "local-preference", argv[0]); |
| 3008 | } |
| 3009 | |
| 3010 | DEFUN (no_set_local_pref, |
| 3011 | no_set_local_pref_cmd, |
| 3012 | "no set local-preference", |
| 3013 | NO_STR |
| 3014 | SET_STR |
| 3015 | "BGP local preference path attribute\n") |
| 3016 | { |
| 3017 | if (argc == 0) |
| 3018 | return bgp_route_set_delete (vty, vty->index, "local-preference", NULL); |
| 3019 | |
| 3020 | return bgp_route_set_delete (vty, vty->index, "local-preference", argv[0]); |
| 3021 | } |
| 3022 | |
| 3023 | ALIAS (no_set_local_pref, |
| 3024 | no_set_local_pref_val_cmd, |
| 3025 | "no set local-preference <0-4294967295>", |
| 3026 | NO_STR |
| 3027 | SET_STR |
| 3028 | "BGP local preference path attribute\n" |
| 3029 | "Preference value\n") |
| 3030 | |
| 3031 | DEFUN (set_weight, |
| 3032 | set_weight_cmd, |
| 3033 | "set weight <0-4294967295>", |
| 3034 | SET_STR |
| 3035 | "BGP weight for routing table\n" |
| 3036 | "Weight value\n") |
| 3037 | { |
| 3038 | return bgp_route_set_add (vty, vty->index, "weight", argv[0]); |
| 3039 | } |
| 3040 | |
| 3041 | DEFUN (no_set_weight, |
| 3042 | no_set_weight_cmd, |
| 3043 | "no set weight", |
| 3044 | NO_STR |
| 3045 | SET_STR |
| 3046 | "BGP weight for routing table\n") |
| 3047 | { |
| 3048 | if (argc == 0) |
| 3049 | return bgp_route_set_delete (vty, vty->index, "weight", NULL); |
| 3050 | |
| 3051 | return bgp_route_set_delete (vty, vty->index, "weight", argv[0]); |
| 3052 | } |
| 3053 | |
| 3054 | ALIAS (no_set_weight, |
| 3055 | no_set_weight_val_cmd, |
| 3056 | "no set weight <0-4294967295>", |
| 3057 | NO_STR |
| 3058 | SET_STR |
| 3059 | "BGP weight for routing table\n" |
| 3060 | "Weight value\n") |
| 3061 | |
| 3062 | DEFUN (set_aspath_prepend, |
| 3063 | set_aspath_prepend_cmd, |
Denis Ovsienko | 10819ec | 2009-06-09 15:15:33 +0400 | [diff] [blame] | 3064 | "set as-path prepend ." CMD_AS_RANGE, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3065 | SET_STR |
Denis Ovsienko | 841f7a5 | 2008-04-10 11:47:45 +0000 | [diff] [blame] | 3066 | "Transform BGP AS_PATH attribute\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3067 | "Prepend to the as-path\n" |
| 3068 | "AS number\n") |
| 3069 | { |
| 3070 | int ret; |
| 3071 | char *str; |
| 3072 | |
| 3073 | str = argv_concat (argv, argc, 0); |
| 3074 | ret = bgp_route_set_add (vty, vty->index, "as-path prepend", str); |
| 3075 | XFREE (MTYPE_TMP, str); |
| 3076 | |
| 3077 | return ret; |
| 3078 | } |
| 3079 | |
| 3080 | DEFUN (no_set_aspath_prepend, |
| 3081 | no_set_aspath_prepend_cmd, |
| 3082 | "no set as-path prepend", |
| 3083 | NO_STR |
| 3084 | SET_STR |
Denis Ovsienko | 841f7a5 | 2008-04-10 11:47:45 +0000 | [diff] [blame] | 3085 | "Transform BGP AS_PATH attribute\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3086 | "Prepend to the as-path\n") |
| 3087 | { |
Denis Ovsienko | a7f93f3 | 2007-12-18 15:13:06 +0000 | [diff] [blame] | 3088 | int ret; |
| 3089 | char *str; |
| 3090 | |
| 3091 | if (argc == 0) |
| 3092 | return bgp_route_set_delete (vty, vty->index, "as-path prepend", NULL); |
| 3093 | |
| 3094 | str = argv_concat (argv, argc, 0); |
| 3095 | ret = bgp_route_set_delete (vty, vty->index, "as-path prepend", str); |
| 3096 | XFREE (MTYPE_TMP, str); |
| 3097 | return ret; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3098 | } |
| 3099 | |
| 3100 | ALIAS (no_set_aspath_prepend, |
| 3101 | no_set_aspath_prepend_val_cmd, |
Denis Ovsienko | 10819ec | 2009-06-09 15:15:33 +0400 | [diff] [blame] | 3102 | "no set as-path prepend ." CMD_AS_RANGE, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3103 | NO_STR |
| 3104 | SET_STR |
Denis Ovsienko | 841f7a5 | 2008-04-10 11:47:45 +0000 | [diff] [blame] | 3105 | "Transform BGP AS_PATH attribute\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3106 | "Prepend to the as-path\n" |
| 3107 | "AS number\n") |
| 3108 | |
Denis Ovsienko | 841f7a5 | 2008-04-10 11:47:45 +0000 | [diff] [blame] | 3109 | DEFUN (set_aspath_exclude, |
| 3110 | set_aspath_exclude_cmd, |
Denis Ovsienko | 10819ec | 2009-06-09 15:15:33 +0400 | [diff] [blame] | 3111 | "set as-path exclude ." CMD_AS_RANGE, |
Denis Ovsienko | 841f7a5 | 2008-04-10 11:47:45 +0000 | [diff] [blame] | 3112 | SET_STR |
| 3113 | "Transform BGP AS-path attribute\n" |
| 3114 | "Exclude from the as-path\n" |
| 3115 | "AS number\n") |
| 3116 | { |
| 3117 | int ret; |
| 3118 | char *str; |
| 3119 | |
| 3120 | str = argv_concat (argv, argc, 0); |
| 3121 | ret = bgp_route_set_add (vty, vty->index, "as-path exclude", str); |
| 3122 | XFREE (MTYPE_TMP, str); |
| 3123 | return ret; |
| 3124 | } |
| 3125 | |
| 3126 | DEFUN (no_set_aspath_exclude, |
| 3127 | no_set_aspath_exclude_cmd, |
| 3128 | "no set as-path exclude", |
| 3129 | NO_STR |
| 3130 | SET_STR |
| 3131 | "Transform BGP AS_PATH attribute\n" |
| 3132 | "Exclude from the as-path\n") |
| 3133 | { |
| 3134 | int ret; |
| 3135 | char *str; |
| 3136 | |
| 3137 | if (argc == 0) |
| 3138 | return bgp_route_set_delete (vty, vty->index, "as-path exclude", NULL); |
| 3139 | |
| 3140 | str = argv_concat (argv, argc, 0); |
| 3141 | ret = bgp_route_set_delete (vty, vty->index, "as-path exclude", str); |
| 3142 | XFREE (MTYPE_TMP, str); |
| 3143 | return ret; |
| 3144 | } |
| 3145 | |
| 3146 | ALIAS (no_set_aspath_exclude, |
| 3147 | no_set_aspath_exclude_val_cmd, |
Denis Ovsienko | 10819ec | 2009-06-09 15:15:33 +0400 | [diff] [blame] | 3148 | "no set as-path exclude ." CMD_AS_RANGE, |
Denis Ovsienko | 841f7a5 | 2008-04-10 11:47:45 +0000 | [diff] [blame] | 3149 | NO_STR |
| 3150 | SET_STR |
| 3151 | "Transform BGP AS_PATH attribute\n" |
| 3152 | "Exclude from the as-path\n" |
| 3153 | "AS number\n") |
| 3154 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3155 | DEFUN (set_community, |
| 3156 | set_community_cmd, |
| 3157 | "set community .AA:NN", |
| 3158 | SET_STR |
| 3159 | "BGP community attribute\n" |
| 3160 | "Community number in aa:nn format or local-AS|no-advertise|no-export|internet or additive\n") |
| 3161 | { |
| 3162 | int i; |
| 3163 | int first = 0; |
| 3164 | int additive = 0; |
| 3165 | struct buffer *b; |
| 3166 | struct community *com = NULL; |
| 3167 | char *str; |
| 3168 | char *argstr; |
| 3169 | int ret; |
| 3170 | |
| 3171 | b = buffer_new (1024); |
| 3172 | |
| 3173 | for (i = 0; i < argc; i++) |
| 3174 | { |
| 3175 | if (strncmp (argv[i], "additive", strlen (argv[i])) == 0) |
| 3176 | { |
| 3177 | additive = 1; |
| 3178 | continue; |
| 3179 | } |
| 3180 | |
| 3181 | if (first) |
| 3182 | buffer_putc (b, ' '); |
| 3183 | else |
| 3184 | first = 1; |
| 3185 | |
| 3186 | if (strncmp (argv[i], "internet", strlen (argv[i])) == 0) |
| 3187 | { |
| 3188 | buffer_putstr (b, "internet"); |
| 3189 | continue; |
| 3190 | } |
| 3191 | if (strncmp (argv[i], "local-AS", strlen (argv[i])) == 0) |
| 3192 | { |
| 3193 | buffer_putstr (b, "local-AS"); |
| 3194 | continue; |
| 3195 | } |
| 3196 | if (strncmp (argv[i], "no-a", strlen ("no-a")) == 0 |
| 3197 | && strncmp (argv[i], "no-advertise", strlen (argv[i])) == 0) |
| 3198 | { |
| 3199 | buffer_putstr (b, "no-advertise"); |
| 3200 | continue; |
| 3201 | } |
| 3202 | if (strncmp (argv[i], "no-e", strlen ("no-e"))== 0 |
| 3203 | && strncmp (argv[i], "no-export", strlen (argv[i])) == 0) |
| 3204 | { |
| 3205 | buffer_putstr (b, "no-export"); |
| 3206 | continue; |
| 3207 | } |
| 3208 | buffer_putstr (b, argv[i]); |
| 3209 | } |
| 3210 | buffer_putc (b, '\0'); |
| 3211 | |
| 3212 | /* Fetch result string then compile it to communities attribute. */ |
| 3213 | str = buffer_getstr (b); |
| 3214 | buffer_free (b); |
| 3215 | |
| 3216 | if (str) |
| 3217 | { |
| 3218 | com = community_str2com (str); |
ajs | 3b8b185 | 2005-01-29 18:19:13 +0000 | [diff] [blame] | 3219 | XFREE (MTYPE_TMP, str); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3220 | } |
| 3221 | |
| 3222 | /* Can't compile user input into communities attribute. */ |
| 3223 | if (! com) |
| 3224 | { |
| 3225 | vty_out (vty, "%% Malformed communities attribute%s", VTY_NEWLINE); |
| 3226 | return CMD_WARNING; |
| 3227 | } |
| 3228 | |
| 3229 | /* Set communites attribute string. */ |
| 3230 | str = community_str (com); |
| 3231 | |
| 3232 | if (additive) |
| 3233 | { |
| 3234 | argstr = XCALLOC (MTYPE_TMP, strlen (str) + strlen (" additive") + 1); |
| 3235 | strcpy (argstr, str); |
| 3236 | strcpy (argstr + strlen (str), " additive"); |
| 3237 | ret = bgp_route_set_add (vty, vty->index, "community", argstr); |
| 3238 | XFREE (MTYPE_TMP, argstr); |
| 3239 | } |
| 3240 | else |
| 3241 | ret = bgp_route_set_add (vty, vty->index, "community", str); |
| 3242 | |
| 3243 | community_free (com); |
| 3244 | |
| 3245 | return ret; |
| 3246 | } |
| 3247 | |
| 3248 | DEFUN (set_community_none, |
| 3249 | set_community_none_cmd, |
| 3250 | "set community none", |
| 3251 | SET_STR |
| 3252 | "BGP community attribute\n" |
| 3253 | "No community attribute\n") |
| 3254 | { |
| 3255 | return bgp_route_set_add (vty, vty->index, "community", "none"); |
| 3256 | } |
| 3257 | |
| 3258 | DEFUN (no_set_community, |
| 3259 | no_set_community_cmd, |
| 3260 | "no set community", |
| 3261 | NO_STR |
| 3262 | SET_STR |
| 3263 | "BGP community attribute\n") |
| 3264 | { |
| 3265 | return bgp_route_set_delete (vty, vty->index, "community", NULL); |
| 3266 | } |
| 3267 | |
| 3268 | ALIAS (no_set_community, |
| 3269 | no_set_community_val_cmd, |
| 3270 | "no set community .AA:NN", |
| 3271 | NO_STR |
| 3272 | SET_STR |
| 3273 | "BGP community attribute\n" |
| 3274 | "Community number in aa:nn format or local-AS|no-advertise|no-export|internet or additive\n") |
| 3275 | |
| 3276 | ALIAS (no_set_community, |
| 3277 | no_set_community_none_cmd, |
| 3278 | "no set community none", |
| 3279 | NO_STR |
| 3280 | SET_STR |
| 3281 | "BGP community attribute\n" |
| 3282 | "No community attribute\n") |
| 3283 | |
| 3284 | DEFUN (set_community_delete, |
| 3285 | set_community_delete_cmd, |
hasso | fee6e4e | 2005-02-02 16:29:31 +0000 | [diff] [blame] | 3286 | "set comm-list (<1-99>|<100-500>|WORD) delete", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3287 | SET_STR |
| 3288 | "set BGP community list (for deletion)\n" |
| 3289 | "Community-list number (standard)\n" |
| 3290 | "Communitly-list number (expanded)\n" |
| 3291 | "Community-list name\n" |
| 3292 | "Delete matching communities\n") |
| 3293 | { |
| 3294 | char *str; |
| 3295 | |
| 3296 | str = XCALLOC (MTYPE_TMP, strlen (argv[0]) + strlen (" delete") + 1); |
| 3297 | strcpy (str, argv[0]); |
| 3298 | strcpy (str + strlen (argv[0]), " delete"); |
| 3299 | |
| 3300 | bgp_route_set_add (vty, vty->index, "comm-list", str); |
| 3301 | |
| 3302 | XFREE (MTYPE_TMP, str); |
| 3303 | return CMD_SUCCESS; |
| 3304 | } |
| 3305 | |
| 3306 | DEFUN (no_set_community_delete, |
| 3307 | no_set_community_delete_cmd, |
| 3308 | "no set comm-list", |
| 3309 | NO_STR |
| 3310 | SET_STR |
| 3311 | "set BGP community list (for deletion)\n") |
| 3312 | { |
| 3313 | return bgp_route_set_delete (vty, vty->index, "comm-list", NULL); |
| 3314 | } |
| 3315 | |
| 3316 | ALIAS (no_set_community_delete, |
| 3317 | no_set_community_delete_val_cmd, |
hasso | fee6e4e | 2005-02-02 16:29:31 +0000 | [diff] [blame] | 3318 | "no set comm-list (<1-99>|<100-500>|WORD) delete", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3319 | NO_STR |
| 3320 | SET_STR |
| 3321 | "set BGP community list (for deletion)\n" |
| 3322 | "Community-list number (standard)\n" |
| 3323 | "Communitly-list number (expanded)\n" |
| 3324 | "Community-list name\n" |
| 3325 | "Delete matching communities\n") |
| 3326 | |
| 3327 | DEFUN (set_ecommunity_rt, |
| 3328 | set_ecommunity_rt_cmd, |
| 3329 | "set extcommunity rt .ASN:nn_or_IP-address:nn", |
| 3330 | SET_STR |
| 3331 | "BGP extended community attribute\n" |
Denis Ovsienko | e6b6a56 | 2009-06-01 20:20:36 +0400 | [diff] [blame] | 3332 | "Route Target extended community\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3333 | "VPN extended community\n") |
| 3334 | { |
| 3335 | int ret; |
| 3336 | char *str; |
| 3337 | |
| 3338 | str = argv_concat (argv, argc, 0); |
| 3339 | ret = bgp_route_set_add (vty, vty->index, "extcommunity rt", str); |
| 3340 | XFREE (MTYPE_TMP, str); |
| 3341 | |
| 3342 | return ret; |
| 3343 | } |
| 3344 | |
| 3345 | DEFUN (no_set_ecommunity_rt, |
| 3346 | no_set_ecommunity_rt_cmd, |
| 3347 | "no set extcommunity rt", |
| 3348 | NO_STR |
| 3349 | SET_STR |
| 3350 | "BGP extended community attribute\n" |
Denis Ovsienko | e6b6a56 | 2009-06-01 20:20:36 +0400 | [diff] [blame] | 3351 | "Route Target extended community\n") |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3352 | { |
| 3353 | return bgp_route_set_delete (vty, vty->index, "extcommunity rt", NULL); |
| 3354 | } |
| 3355 | |
| 3356 | ALIAS (no_set_ecommunity_rt, |
| 3357 | no_set_ecommunity_rt_val_cmd, |
| 3358 | "no set extcommunity rt .ASN:nn_or_IP-address:nn", |
| 3359 | NO_STR |
| 3360 | SET_STR |
| 3361 | "BGP extended community attribute\n" |
Denis Ovsienko | e6b6a56 | 2009-06-01 20:20:36 +0400 | [diff] [blame] | 3362 | "Route Target extended community\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3363 | "VPN extended community\n") |
| 3364 | |
| 3365 | DEFUN (set_ecommunity_soo, |
| 3366 | set_ecommunity_soo_cmd, |
| 3367 | "set extcommunity soo .ASN:nn_or_IP-address:nn", |
| 3368 | SET_STR |
| 3369 | "BGP extended community attribute\n" |
| 3370 | "Site-of-Origin extended community\n" |
| 3371 | "VPN extended community\n") |
| 3372 | { |
| 3373 | int ret; |
| 3374 | char *str; |
| 3375 | |
| 3376 | str = argv_concat (argv, argc, 0); |
| 3377 | ret = bgp_route_set_add (vty, vty->index, "extcommunity soo", str); |
| 3378 | XFREE (MTYPE_TMP, str); |
| 3379 | return ret; |
| 3380 | } |
| 3381 | |
| 3382 | DEFUN (no_set_ecommunity_soo, |
| 3383 | no_set_ecommunity_soo_cmd, |
| 3384 | "no set extcommunity soo", |
| 3385 | NO_STR |
| 3386 | SET_STR |
| 3387 | "BGP extended community attribute\n" |
| 3388 | "Site-of-Origin extended community\n") |
| 3389 | { |
| 3390 | return bgp_route_set_delete (vty, vty->index, "extcommunity soo", NULL); |
| 3391 | } |
| 3392 | |
| 3393 | ALIAS (no_set_ecommunity_soo, |
| 3394 | no_set_ecommunity_soo_val_cmd, |
| 3395 | "no set extcommunity soo .ASN:nn_or_IP-address:nn", |
| 3396 | NO_STR |
| 3397 | SET_STR |
| 3398 | "BGP extended community attribute\n" |
| 3399 | "Site-of-Origin extended community\n" |
| 3400 | "VPN extended community\n") |
| 3401 | |
| 3402 | DEFUN (set_origin, |
| 3403 | set_origin_cmd, |
| 3404 | "set origin (egp|igp|incomplete)", |
| 3405 | SET_STR |
| 3406 | "BGP origin code\n" |
| 3407 | "remote EGP\n" |
| 3408 | "local IGP\n" |
| 3409 | "unknown heritage\n") |
| 3410 | { |
| 3411 | if (strncmp (argv[0], "igp", 2) == 0) |
| 3412 | return bgp_route_set_add (vty, vty->index, "origin", "igp"); |
| 3413 | if (strncmp (argv[0], "egp", 1) == 0) |
| 3414 | return bgp_route_set_add (vty, vty->index, "origin", "egp"); |
| 3415 | if (strncmp (argv[0], "incomplete", 2) == 0) |
| 3416 | return bgp_route_set_add (vty, vty->index, "origin", "incomplete"); |
| 3417 | |
| 3418 | return CMD_WARNING; |
| 3419 | } |
| 3420 | |
| 3421 | DEFUN (no_set_origin, |
| 3422 | no_set_origin_cmd, |
| 3423 | "no set origin", |
| 3424 | NO_STR |
| 3425 | SET_STR |
| 3426 | "BGP origin code\n") |
| 3427 | { |
| 3428 | return bgp_route_set_delete (vty, vty->index, "origin", NULL); |
| 3429 | } |
| 3430 | |
| 3431 | ALIAS (no_set_origin, |
| 3432 | no_set_origin_val_cmd, |
| 3433 | "no set origin (egp|igp|incomplete)", |
| 3434 | NO_STR |
| 3435 | SET_STR |
| 3436 | "BGP origin code\n" |
| 3437 | "remote EGP\n" |
| 3438 | "local IGP\n" |
| 3439 | "unknown heritage\n") |
| 3440 | |
| 3441 | DEFUN (set_atomic_aggregate, |
| 3442 | set_atomic_aggregate_cmd, |
| 3443 | "set atomic-aggregate", |
| 3444 | SET_STR |
| 3445 | "BGP atomic aggregate attribute\n" ) |
| 3446 | { |
| 3447 | return bgp_route_set_add (vty, vty->index, "atomic-aggregate", NULL); |
| 3448 | } |
| 3449 | |
| 3450 | DEFUN (no_set_atomic_aggregate, |
| 3451 | no_set_atomic_aggregate_cmd, |
| 3452 | "no set atomic-aggregate", |
| 3453 | NO_STR |
| 3454 | SET_STR |
| 3455 | "BGP atomic aggregate attribute\n" ) |
| 3456 | { |
| 3457 | return bgp_route_set_delete (vty, vty->index, "atomic-aggregate", NULL); |
| 3458 | } |
| 3459 | |
| 3460 | DEFUN (set_aggregator_as, |
| 3461 | set_aggregator_as_cmd, |
Paul Jakma | 320da87 | 2008-07-02 13:40:33 +0000 | [diff] [blame] | 3462 | "set aggregator as " CMD_AS_RANGE " A.B.C.D", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3463 | SET_STR |
| 3464 | "BGP aggregator attribute\n" |
| 3465 | "AS number of aggregator\n" |
| 3466 | "AS number\n" |
| 3467 | "IP address of aggregator\n") |
| 3468 | { |
| 3469 | int ret; |
| 3470 | as_t as; |
| 3471 | struct in_addr address; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3472 | char *argstr; |
| 3473 | |
Paul Jakma | 0b2aa3a | 2007-10-14 22:32:21 +0000 | [diff] [blame] | 3474 | VTY_GET_INTEGER_RANGE ("AS", as, argv[0], 1, BGP_AS4_MAX); |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 3475 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3476 | ret = inet_aton (argv[1], &address); |
| 3477 | if (ret == 0) |
| 3478 | { |
| 3479 | vty_out (vty, "Aggregator IP address is invalid%s", VTY_NEWLINE); |
| 3480 | return CMD_WARNING; |
| 3481 | } |
| 3482 | |
| 3483 | argstr = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, |
| 3484 | strlen (argv[0]) + strlen (argv[1]) + 2); |
| 3485 | |
| 3486 | sprintf (argstr, "%s %s", argv[0], argv[1]); |
| 3487 | |
| 3488 | ret = bgp_route_set_add (vty, vty->index, "aggregator as", argstr); |
| 3489 | |
| 3490 | XFREE (MTYPE_ROUTE_MAP_COMPILED, argstr); |
| 3491 | |
| 3492 | return ret; |
| 3493 | } |
| 3494 | |
| 3495 | DEFUN (no_set_aggregator_as, |
| 3496 | no_set_aggregator_as_cmd, |
| 3497 | "no set aggregator as", |
| 3498 | NO_STR |
| 3499 | SET_STR |
| 3500 | "BGP aggregator attribute\n" |
| 3501 | "AS number of aggregator\n") |
| 3502 | { |
| 3503 | int ret; |
| 3504 | as_t as; |
| 3505 | struct in_addr address; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3506 | char *argstr; |
| 3507 | |
| 3508 | if (argv == 0) |
| 3509 | return bgp_route_set_delete (vty, vty->index, "aggregator as", NULL); |
| 3510 | |
Paul Jakma | 0b2aa3a | 2007-10-14 22:32:21 +0000 | [diff] [blame] | 3511 | VTY_GET_INTEGER_RANGE ("AS", as, argv[0], 1, BGP_AS4_MAX); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3512 | |
| 3513 | ret = inet_aton (argv[1], &address); |
| 3514 | if (ret == 0) |
| 3515 | { |
| 3516 | vty_out (vty, "Aggregator IP address is invalid%s", VTY_NEWLINE); |
| 3517 | return CMD_WARNING; |
| 3518 | } |
| 3519 | |
| 3520 | argstr = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, |
| 3521 | strlen (argv[0]) + strlen (argv[1]) + 2); |
| 3522 | |
| 3523 | sprintf (argstr, "%s %s", argv[0], argv[1]); |
| 3524 | |
| 3525 | ret = bgp_route_set_delete (vty, vty->index, "aggregator as", argstr); |
| 3526 | |
| 3527 | XFREE (MTYPE_ROUTE_MAP_COMPILED, argstr); |
| 3528 | |
| 3529 | return ret; |
| 3530 | } |
| 3531 | |
| 3532 | ALIAS (no_set_aggregator_as, |
| 3533 | no_set_aggregator_as_val_cmd, |
Paul Jakma | 320da87 | 2008-07-02 13:40:33 +0000 | [diff] [blame] | 3534 | "no set aggregator as " CMD_AS_RANGE " A.B.C.D", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3535 | NO_STR |
| 3536 | SET_STR |
| 3537 | "BGP aggregator attribute\n" |
| 3538 | "AS number of aggregator\n" |
| 3539 | "AS number\n" |
| 3540 | "IP address of aggregator\n") |
| 3541 | |
| 3542 | |
| 3543 | #ifdef HAVE_IPV6 |
| 3544 | DEFUN (match_ipv6_address, |
| 3545 | match_ipv6_address_cmd, |
| 3546 | "match ipv6 address WORD", |
| 3547 | MATCH_STR |
| 3548 | IPV6_STR |
| 3549 | "Match IPv6 address of route\n" |
| 3550 | "IPv6 access-list name\n") |
| 3551 | { |
| 3552 | return bgp_route_match_add (vty, vty->index, "ipv6 address", argv[0]); |
| 3553 | } |
| 3554 | |
| 3555 | DEFUN (no_match_ipv6_address, |
| 3556 | no_match_ipv6_address_cmd, |
| 3557 | "no match ipv6 address WORD", |
| 3558 | NO_STR |
| 3559 | MATCH_STR |
| 3560 | IPV6_STR |
| 3561 | "Match IPv6 address of route\n" |
| 3562 | "IPv6 access-list name\n") |
| 3563 | { |
| 3564 | return bgp_route_match_delete (vty, vty->index, "ipv6 address", argv[0]); |
| 3565 | } |
| 3566 | |
| 3567 | DEFUN (match_ipv6_next_hop, |
| 3568 | match_ipv6_next_hop_cmd, |
| 3569 | "match ipv6 next-hop X:X::X:X", |
| 3570 | MATCH_STR |
| 3571 | IPV6_STR |
| 3572 | "Match IPv6 next-hop address of route\n" |
| 3573 | "IPv6 address of next hop\n") |
| 3574 | { |
| 3575 | return bgp_route_match_add (vty, vty->index, "ipv6 next-hop", argv[0]); |
| 3576 | } |
| 3577 | |
| 3578 | DEFUN (no_match_ipv6_next_hop, |
| 3579 | no_match_ipv6_next_hop_cmd, |
| 3580 | "no match ipv6 next-hop X:X::X:X", |
| 3581 | NO_STR |
| 3582 | MATCH_STR |
| 3583 | IPV6_STR |
| 3584 | "Match IPv6 next-hop address of route\n" |
| 3585 | "IPv6 address of next hop\n") |
| 3586 | { |
| 3587 | return bgp_route_match_delete (vty, vty->index, "ipv6 next-hop", argv[0]); |
| 3588 | } |
| 3589 | |
| 3590 | DEFUN (match_ipv6_address_prefix_list, |
| 3591 | match_ipv6_address_prefix_list_cmd, |
| 3592 | "match ipv6 address prefix-list WORD", |
| 3593 | MATCH_STR |
| 3594 | IPV6_STR |
| 3595 | "Match address of route\n" |
| 3596 | "Match entries of prefix-lists\n" |
| 3597 | "IP prefix-list name\n") |
| 3598 | { |
| 3599 | return bgp_route_match_add (vty, vty->index, "ipv6 address prefix-list", argv[0]); |
| 3600 | } |
| 3601 | |
| 3602 | DEFUN (no_match_ipv6_address_prefix_list, |
| 3603 | no_match_ipv6_address_prefix_list_cmd, |
| 3604 | "no match ipv6 address prefix-list WORD", |
| 3605 | NO_STR |
| 3606 | MATCH_STR |
| 3607 | IPV6_STR |
| 3608 | "Match address of route\n" |
| 3609 | "Match entries of prefix-lists\n" |
| 3610 | "IP prefix-list name\n") |
| 3611 | { |
| 3612 | return bgp_route_match_delete (vty, vty->index, "ipv6 address prefix-list", argv[0]); |
| 3613 | } |
| 3614 | |
| 3615 | DEFUN (set_ipv6_nexthop_global, |
| 3616 | set_ipv6_nexthop_global_cmd, |
| 3617 | "set ipv6 next-hop global X:X::X:X", |
| 3618 | SET_STR |
| 3619 | IPV6_STR |
| 3620 | "IPv6 next-hop address\n" |
| 3621 | "IPv6 global address\n" |
| 3622 | "IPv6 address of next hop\n") |
| 3623 | { |
| 3624 | return bgp_route_set_add (vty, vty->index, "ipv6 next-hop global", argv[0]); |
| 3625 | } |
| 3626 | |
| 3627 | DEFUN (no_set_ipv6_nexthop_global, |
| 3628 | no_set_ipv6_nexthop_global_cmd, |
| 3629 | "no set ipv6 next-hop global", |
| 3630 | NO_STR |
| 3631 | SET_STR |
| 3632 | IPV6_STR |
| 3633 | "IPv6 next-hop address\n" |
| 3634 | "IPv6 global address\n") |
| 3635 | { |
| 3636 | if (argc == 0) |
| 3637 | return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop global", NULL); |
| 3638 | |
| 3639 | return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop global", argv[0]); |
| 3640 | } |
| 3641 | |
| 3642 | ALIAS (no_set_ipv6_nexthop_global, |
| 3643 | no_set_ipv6_nexthop_global_val_cmd, |
| 3644 | "no set ipv6 next-hop global X:X::X:X", |
| 3645 | NO_STR |
| 3646 | SET_STR |
| 3647 | IPV6_STR |
| 3648 | "IPv6 next-hop address\n" |
| 3649 | "IPv6 global address\n" |
| 3650 | "IPv6 address of next hop\n") |
| 3651 | |
| 3652 | DEFUN (set_ipv6_nexthop_local, |
| 3653 | set_ipv6_nexthop_local_cmd, |
| 3654 | "set ipv6 next-hop local X:X::X:X", |
| 3655 | SET_STR |
| 3656 | IPV6_STR |
| 3657 | "IPv6 next-hop address\n" |
| 3658 | "IPv6 local address\n" |
| 3659 | "IPv6 address of next hop\n") |
| 3660 | { |
| 3661 | return bgp_route_set_add (vty, vty->index, "ipv6 next-hop local", argv[0]); |
| 3662 | } |
| 3663 | |
| 3664 | DEFUN (no_set_ipv6_nexthop_local, |
| 3665 | no_set_ipv6_nexthop_local_cmd, |
| 3666 | "no set ipv6 next-hop local", |
| 3667 | NO_STR |
| 3668 | SET_STR |
| 3669 | IPV6_STR |
| 3670 | "IPv6 next-hop address\n" |
| 3671 | "IPv6 local address\n") |
| 3672 | { |
| 3673 | if (argc == 0) |
| 3674 | return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop local", NULL); |
| 3675 | |
| 3676 | return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop local", argv[0]); |
| 3677 | } |
| 3678 | |
| 3679 | ALIAS (no_set_ipv6_nexthop_local, |
| 3680 | no_set_ipv6_nexthop_local_val_cmd, |
| 3681 | "no set ipv6 next-hop local X:X::X:X", |
| 3682 | NO_STR |
| 3683 | SET_STR |
| 3684 | IPV6_STR |
| 3685 | "IPv6 next-hop address\n" |
| 3686 | "IPv6 local address\n" |
| 3687 | "IPv6 address of next hop\n") |
| 3688 | #endif /* HAVE_IPV6 */ |
| 3689 | |
| 3690 | DEFUN (set_vpnv4_nexthop, |
| 3691 | set_vpnv4_nexthop_cmd, |
| 3692 | "set vpnv4 next-hop A.B.C.D", |
| 3693 | SET_STR |
| 3694 | "VPNv4 information\n" |
| 3695 | "VPNv4 next-hop address\n" |
| 3696 | "IP address of next hop\n") |
| 3697 | { |
| 3698 | return bgp_route_set_add (vty, vty->index, "vpnv4 next-hop", argv[0]); |
| 3699 | } |
| 3700 | |
| 3701 | DEFUN (no_set_vpnv4_nexthop, |
| 3702 | no_set_vpnv4_nexthop_cmd, |
| 3703 | "no set vpnv4 next-hop", |
| 3704 | NO_STR |
| 3705 | SET_STR |
| 3706 | "VPNv4 information\n" |
| 3707 | "VPNv4 next-hop address\n") |
| 3708 | { |
| 3709 | if (argc == 0) |
| 3710 | return bgp_route_set_delete (vty, vty->index, "vpnv4 next-hop", NULL); |
| 3711 | |
| 3712 | return bgp_route_set_delete (vty, vty->index, "vpnv4 next-hop", argv[0]); |
| 3713 | } |
| 3714 | |
| 3715 | ALIAS (no_set_vpnv4_nexthop, |
| 3716 | no_set_vpnv4_nexthop_val_cmd, |
| 3717 | "no set vpnv4 next-hop A.B.C.D", |
| 3718 | NO_STR |
| 3719 | SET_STR |
| 3720 | "VPNv4 information\n" |
| 3721 | "VPNv4 next-hop address\n" |
| 3722 | "IP address of next hop\n") |
| 3723 | |
| 3724 | DEFUN (set_originator_id, |
| 3725 | set_originator_id_cmd, |
| 3726 | "set originator-id A.B.C.D", |
| 3727 | SET_STR |
| 3728 | "BGP originator ID attribute\n" |
| 3729 | "IP address of originator\n") |
| 3730 | { |
| 3731 | return bgp_route_set_add (vty, vty->index, "originator-id", argv[0]); |
| 3732 | } |
| 3733 | |
| 3734 | DEFUN (no_set_originator_id, |
| 3735 | no_set_originator_id_cmd, |
| 3736 | "no set originator-id", |
| 3737 | NO_STR |
| 3738 | SET_STR |
| 3739 | "BGP originator ID attribute\n") |
| 3740 | { |
| 3741 | if (argc == 0) |
| 3742 | return bgp_route_set_delete (vty, vty->index, "originator-id", NULL); |
| 3743 | |
| 3744 | return bgp_route_set_delete (vty, vty->index, "originator-id", argv[0]); |
| 3745 | } |
| 3746 | |
| 3747 | ALIAS (no_set_originator_id, |
| 3748 | no_set_originator_id_val_cmd, |
| 3749 | "no set originator-id A.B.C.D", |
| 3750 | NO_STR |
| 3751 | SET_STR |
| 3752 | "BGP originator ID attribute\n" |
| 3753 | "IP address of originator\n") |
| 3754 | |
Paul Jakma | e70e575 | 2011-07-05 00:41:59 +0400 | [diff] [blame] | 3755 | DEFUN_DEPRECATED (set_pathlimit_ttl, |
Paul Jakma | 4136717 | 2007-08-06 15:24:51 +0000 | [diff] [blame] | 3756 | set_pathlimit_ttl_cmd, |
| 3757 | "set pathlimit ttl <1-255>", |
| 3758 | SET_STR |
| 3759 | "BGP AS-Pathlimit attribute\n" |
| 3760 | "Set AS-Path Hop-count TTL\n") |
| 3761 | { |
Paul Jakma | e70e575 | 2011-07-05 00:41:59 +0400 | [diff] [blame] | 3762 | return CMD_SUCCESS; |
Paul Jakma | 4136717 | 2007-08-06 15:24:51 +0000 | [diff] [blame] | 3763 | } |
| 3764 | |
Paul Jakma | e70e575 | 2011-07-05 00:41:59 +0400 | [diff] [blame] | 3765 | DEFUN_DEPRECATED (no_set_pathlimit_ttl, |
Paul Jakma | 4136717 | 2007-08-06 15:24:51 +0000 | [diff] [blame] | 3766 | no_set_pathlimit_ttl_cmd, |
| 3767 | "no set pathlimit ttl", |
| 3768 | NO_STR |
| 3769 | SET_STR |
| 3770 | "BGP AS-Pathlimit attribute\n" |
| 3771 | "Set AS-Path Hop-count TTL\n") |
| 3772 | { |
Paul Jakma | e70e575 | 2011-07-05 00:41:59 +0400 | [diff] [blame] | 3773 | return CMD_SUCCESS; |
Paul Jakma | 4136717 | 2007-08-06 15:24:51 +0000 | [diff] [blame] | 3774 | } |
| 3775 | |
| 3776 | ALIAS (no_set_pathlimit_ttl, |
| 3777 | no_set_pathlimit_ttl_val_cmd, |
| 3778 | "no set pathlimit ttl <1-255>", |
| 3779 | NO_STR |
| 3780 | MATCH_STR |
| 3781 | "BGP AS-Pathlimit attribute\n" |
| 3782 | "Set AS-Path Hop-count TTL\n") |
| 3783 | |
Paul Jakma | e70e575 | 2011-07-05 00:41:59 +0400 | [diff] [blame] | 3784 | DEFUN_DEPRECATED (match_pathlimit_as, |
Paul Jakma | 4136717 | 2007-08-06 15:24:51 +0000 | [diff] [blame] | 3785 | match_pathlimit_as_cmd, |
| 3786 | "match pathlimit as <1-65535>", |
| 3787 | MATCH_STR |
| 3788 | "BGP AS-Pathlimit attribute\n" |
| 3789 | "Match Pathlimit AS number\n") |
| 3790 | { |
Paul Jakma | e70e575 | 2011-07-05 00:41:59 +0400 | [diff] [blame] | 3791 | return CMD_SUCCESS; |
Paul Jakma | 4136717 | 2007-08-06 15:24:51 +0000 | [diff] [blame] | 3792 | } |
| 3793 | |
Paul Jakma | e70e575 | 2011-07-05 00:41:59 +0400 | [diff] [blame] | 3794 | DEFUN_DEPRECATED (no_match_pathlimit_as, |
Paul Jakma | 4136717 | 2007-08-06 15:24:51 +0000 | [diff] [blame] | 3795 | no_match_pathlimit_as_cmd, |
| 3796 | "no match pathlimit as", |
| 3797 | NO_STR |
| 3798 | MATCH_STR |
| 3799 | "BGP AS-Pathlimit attribute\n" |
| 3800 | "Match Pathlimit AS number\n") |
| 3801 | { |
Paul Jakma | e70e575 | 2011-07-05 00:41:59 +0400 | [diff] [blame] | 3802 | return CMD_SUCCESS; |
Paul Jakma | 4136717 | 2007-08-06 15:24:51 +0000 | [diff] [blame] | 3803 | } |
| 3804 | |
| 3805 | ALIAS (no_match_pathlimit_as, |
| 3806 | no_match_pathlimit_as_val_cmd, |
| 3807 | "no match pathlimit as <1-65535>", |
| 3808 | NO_STR |
| 3809 | MATCH_STR |
| 3810 | "BGP AS-Pathlimit attribute\n" |
| 3811 | "Match Pathlimit ASN\n") |
| 3812 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3813 | |
| 3814 | /* Initialization of route map. */ |
| 3815 | void |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 3816 | bgp_route_map_init (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3817 | { |
| 3818 | route_map_init (); |
| 3819 | route_map_init_vty (); |
| 3820 | route_map_add_hook (bgp_route_map_update); |
| 3821 | route_map_delete_hook (bgp_route_map_update); |
| 3822 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3823 | route_map_install_match (&route_match_peer_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3824 | route_map_install_match (&route_match_ip_address_cmd); |
| 3825 | route_map_install_match (&route_match_ip_next_hop_cmd); |
hasso | c1643bb | 2005-02-02 16:43:17 +0000 | [diff] [blame] | 3826 | route_map_install_match (&route_match_ip_route_source_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3827 | route_map_install_match (&route_match_ip_address_prefix_list_cmd); |
| 3828 | route_map_install_match (&route_match_ip_next_hop_prefix_list_cmd); |
hasso | c1643bb | 2005-02-02 16:43:17 +0000 | [diff] [blame] | 3829 | route_map_install_match (&route_match_ip_route_source_prefix_list_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3830 | route_map_install_match (&route_match_aspath_cmd); |
| 3831 | route_map_install_match (&route_match_community_cmd); |
paul | 73ffb25 | 2003-04-19 15:49:49 +0000 | [diff] [blame] | 3832 | route_map_install_match (&route_match_ecommunity_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3833 | route_map_install_match (&route_match_metric_cmd); |
| 3834 | route_map_install_match (&route_match_origin_cmd); |
Vyacheslav Trushkin | 1c8afb7 | 2011-11-22 20:15:10 +0400 | [diff] [blame] | 3835 | route_map_install_match (&route_match_probability_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3836 | |
| 3837 | route_map_install_set (&route_set_ip_nexthop_cmd); |
| 3838 | route_map_install_set (&route_set_local_pref_cmd); |
| 3839 | route_map_install_set (&route_set_weight_cmd); |
| 3840 | route_map_install_set (&route_set_metric_cmd); |
| 3841 | route_map_install_set (&route_set_aspath_prepend_cmd); |
Denis Ovsienko | 841f7a5 | 2008-04-10 11:47:45 +0000 | [diff] [blame] | 3842 | route_map_install_set (&route_set_aspath_exclude_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3843 | route_map_install_set (&route_set_origin_cmd); |
| 3844 | route_map_install_set (&route_set_atomic_aggregate_cmd); |
| 3845 | route_map_install_set (&route_set_aggregator_as_cmd); |
| 3846 | route_map_install_set (&route_set_community_cmd); |
| 3847 | route_map_install_set (&route_set_community_delete_cmd); |
| 3848 | route_map_install_set (&route_set_vpnv4_nexthop_cmd); |
| 3849 | route_map_install_set (&route_set_originator_id_cmd); |
| 3850 | route_map_install_set (&route_set_ecommunity_rt_cmd); |
| 3851 | route_map_install_set (&route_set_ecommunity_soo_cmd); |
| 3852 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 3853 | install_element (RMAP_NODE, &match_peer_cmd); |
| 3854 | install_element (RMAP_NODE, &match_peer_local_cmd); |
| 3855 | install_element (RMAP_NODE, &no_match_peer_cmd); |
| 3856 | install_element (RMAP_NODE, &no_match_peer_val_cmd); |
| 3857 | install_element (RMAP_NODE, &no_match_peer_local_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3858 | install_element (RMAP_NODE, &match_ip_address_cmd); |
| 3859 | install_element (RMAP_NODE, &no_match_ip_address_cmd); |
| 3860 | install_element (RMAP_NODE, &no_match_ip_address_val_cmd); |
| 3861 | install_element (RMAP_NODE, &match_ip_next_hop_cmd); |
| 3862 | install_element (RMAP_NODE, &no_match_ip_next_hop_cmd); |
| 3863 | install_element (RMAP_NODE, &no_match_ip_next_hop_val_cmd); |
hasso | c1643bb | 2005-02-02 16:43:17 +0000 | [diff] [blame] | 3864 | install_element (RMAP_NODE, &match_ip_route_source_cmd); |
| 3865 | install_element (RMAP_NODE, &no_match_ip_route_source_cmd); |
| 3866 | install_element (RMAP_NODE, &no_match_ip_route_source_val_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3867 | install_element (RMAP_NODE, &match_ip_address_prefix_list_cmd); |
| 3868 | install_element (RMAP_NODE, &no_match_ip_address_prefix_list_cmd); |
| 3869 | install_element (RMAP_NODE, &no_match_ip_address_prefix_list_val_cmd); |
| 3870 | install_element (RMAP_NODE, &match_ip_next_hop_prefix_list_cmd); |
| 3871 | install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_cmd); |
| 3872 | install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_val_cmd); |
hasso | c1643bb | 2005-02-02 16:43:17 +0000 | [diff] [blame] | 3873 | install_element (RMAP_NODE, &match_ip_route_source_prefix_list_cmd); |
| 3874 | install_element (RMAP_NODE, &no_match_ip_route_source_prefix_list_cmd); |
| 3875 | install_element (RMAP_NODE, &no_match_ip_route_source_prefix_list_val_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3876 | |
| 3877 | install_element (RMAP_NODE, &match_aspath_cmd); |
| 3878 | install_element (RMAP_NODE, &no_match_aspath_cmd); |
| 3879 | install_element (RMAP_NODE, &no_match_aspath_val_cmd); |
| 3880 | install_element (RMAP_NODE, &match_metric_cmd); |
| 3881 | install_element (RMAP_NODE, &no_match_metric_cmd); |
| 3882 | install_element (RMAP_NODE, &no_match_metric_val_cmd); |
| 3883 | install_element (RMAP_NODE, &match_community_cmd); |
| 3884 | install_element (RMAP_NODE, &match_community_exact_cmd); |
| 3885 | install_element (RMAP_NODE, &no_match_community_cmd); |
| 3886 | install_element (RMAP_NODE, &no_match_community_val_cmd); |
| 3887 | install_element (RMAP_NODE, &no_match_community_exact_cmd); |
paul | 73ffb25 | 2003-04-19 15:49:49 +0000 | [diff] [blame] | 3888 | install_element (RMAP_NODE, &match_ecommunity_cmd); |
| 3889 | install_element (RMAP_NODE, &no_match_ecommunity_cmd); |
| 3890 | install_element (RMAP_NODE, &no_match_ecommunity_val_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3891 | install_element (RMAP_NODE, &match_origin_cmd); |
| 3892 | install_element (RMAP_NODE, &no_match_origin_cmd); |
| 3893 | install_element (RMAP_NODE, &no_match_origin_val_cmd); |
Vyacheslav Trushkin | 1c8afb7 | 2011-11-22 20:15:10 +0400 | [diff] [blame] | 3894 | install_element (RMAP_NODE, &match_probability_cmd); |
| 3895 | install_element (RMAP_NODE, &no_match_probability_cmd); |
| 3896 | install_element (RMAP_NODE, &no_match_probability_val_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3897 | |
| 3898 | install_element (RMAP_NODE, &set_ip_nexthop_cmd); |
paul | af5cd0a | 2003-11-02 07:24:40 +0000 | [diff] [blame] | 3899 | install_element (RMAP_NODE, &set_ip_nexthop_peer_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3900 | install_element (RMAP_NODE, &no_set_ip_nexthop_cmd); |
| 3901 | install_element (RMAP_NODE, &no_set_ip_nexthop_val_cmd); |
| 3902 | install_element (RMAP_NODE, &set_local_pref_cmd); |
| 3903 | install_element (RMAP_NODE, &no_set_local_pref_cmd); |
| 3904 | install_element (RMAP_NODE, &no_set_local_pref_val_cmd); |
| 3905 | install_element (RMAP_NODE, &set_weight_cmd); |
| 3906 | install_element (RMAP_NODE, &no_set_weight_cmd); |
| 3907 | install_element (RMAP_NODE, &no_set_weight_val_cmd); |
| 3908 | install_element (RMAP_NODE, &set_metric_cmd); |
paul | 73ffb25 | 2003-04-19 15:49:49 +0000 | [diff] [blame] | 3909 | install_element (RMAP_NODE, &set_metric_addsub_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3910 | install_element (RMAP_NODE, &no_set_metric_cmd); |
| 3911 | install_element (RMAP_NODE, &no_set_metric_val_cmd); |
| 3912 | install_element (RMAP_NODE, &set_aspath_prepend_cmd); |
Denis Ovsienko | 841f7a5 | 2008-04-10 11:47:45 +0000 | [diff] [blame] | 3913 | install_element (RMAP_NODE, &set_aspath_exclude_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3914 | install_element (RMAP_NODE, &no_set_aspath_prepend_cmd); |
| 3915 | install_element (RMAP_NODE, &no_set_aspath_prepend_val_cmd); |
Denis Ovsienko | 841f7a5 | 2008-04-10 11:47:45 +0000 | [diff] [blame] | 3916 | install_element (RMAP_NODE, &no_set_aspath_exclude_cmd); |
| 3917 | install_element (RMAP_NODE, &no_set_aspath_exclude_val_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3918 | install_element (RMAP_NODE, &set_origin_cmd); |
| 3919 | install_element (RMAP_NODE, &no_set_origin_cmd); |
| 3920 | install_element (RMAP_NODE, &no_set_origin_val_cmd); |
| 3921 | install_element (RMAP_NODE, &set_atomic_aggregate_cmd); |
| 3922 | install_element (RMAP_NODE, &no_set_atomic_aggregate_cmd); |
| 3923 | install_element (RMAP_NODE, &set_aggregator_as_cmd); |
| 3924 | install_element (RMAP_NODE, &no_set_aggregator_as_cmd); |
| 3925 | install_element (RMAP_NODE, &no_set_aggregator_as_val_cmd); |
| 3926 | install_element (RMAP_NODE, &set_community_cmd); |
| 3927 | install_element (RMAP_NODE, &set_community_none_cmd); |
| 3928 | install_element (RMAP_NODE, &no_set_community_cmd); |
| 3929 | install_element (RMAP_NODE, &no_set_community_val_cmd); |
| 3930 | install_element (RMAP_NODE, &no_set_community_none_cmd); |
| 3931 | install_element (RMAP_NODE, &set_community_delete_cmd); |
| 3932 | install_element (RMAP_NODE, &no_set_community_delete_cmd); |
| 3933 | install_element (RMAP_NODE, &no_set_community_delete_val_cmd); |
| 3934 | install_element (RMAP_NODE, &set_ecommunity_rt_cmd); |
| 3935 | install_element (RMAP_NODE, &no_set_ecommunity_rt_cmd); |
| 3936 | install_element (RMAP_NODE, &no_set_ecommunity_rt_val_cmd); |
| 3937 | install_element (RMAP_NODE, &set_ecommunity_soo_cmd); |
| 3938 | install_element (RMAP_NODE, &no_set_ecommunity_soo_cmd); |
| 3939 | install_element (RMAP_NODE, &no_set_ecommunity_soo_val_cmd); |
| 3940 | install_element (RMAP_NODE, &set_vpnv4_nexthop_cmd); |
| 3941 | install_element (RMAP_NODE, &no_set_vpnv4_nexthop_cmd); |
| 3942 | install_element (RMAP_NODE, &no_set_vpnv4_nexthop_val_cmd); |
| 3943 | install_element (RMAP_NODE, &set_originator_id_cmd); |
| 3944 | install_element (RMAP_NODE, &no_set_originator_id_cmd); |
| 3945 | install_element (RMAP_NODE, &no_set_originator_id_val_cmd); |
| 3946 | |
| 3947 | #ifdef HAVE_IPV6 |
| 3948 | route_map_install_match (&route_match_ipv6_address_cmd); |
| 3949 | route_map_install_match (&route_match_ipv6_next_hop_cmd); |
| 3950 | route_map_install_match (&route_match_ipv6_address_prefix_list_cmd); |
| 3951 | route_map_install_set (&route_set_ipv6_nexthop_global_cmd); |
| 3952 | route_map_install_set (&route_set_ipv6_nexthop_local_cmd); |
Paul Jakma | 4136717 | 2007-08-06 15:24:51 +0000 | [diff] [blame] | 3953 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3954 | install_element (RMAP_NODE, &match_ipv6_address_cmd); |
| 3955 | install_element (RMAP_NODE, &no_match_ipv6_address_cmd); |
| 3956 | install_element (RMAP_NODE, &match_ipv6_next_hop_cmd); |
| 3957 | install_element (RMAP_NODE, &no_match_ipv6_next_hop_cmd); |
| 3958 | install_element (RMAP_NODE, &match_ipv6_address_prefix_list_cmd); |
| 3959 | install_element (RMAP_NODE, &no_match_ipv6_address_prefix_list_cmd); |
| 3960 | install_element (RMAP_NODE, &set_ipv6_nexthop_global_cmd); |
| 3961 | install_element (RMAP_NODE, &no_set_ipv6_nexthop_global_cmd); |
| 3962 | install_element (RMAP_NODE, &no_set_ipv6_nexthop_global_val_cmd); |
| 3963 | install_element (RMAP_NODE, &set_ipv6_nexthop_local_cmd); |
| 3964 | install_element (RMAP_NODE, &no_set_ipv6_nexthop_local_cmd); |
| 3965 | install_element (RMAP_NODE, &no_set_ipv6_nexthop_local_val_cmd); |
| 3966 | #endif /* HAVE_IPV6 */ |
Paul Jakma | 4136717 | 2007-08-06 15:24:51 +0000 | [diff] [blame] | 3967 | |
Paul Jakma | e70e575 | 2011-07-05 00:41:59 +0400 | [diff] [blame] | 3968 | /* AS-Pathlimit: functionality removed, commands kept for |
| 3969 | * compatibility. |
| 3970 | */ |
Paul Jakma | 4136717 | 2007-08-06 15:24:51 +0000 | [diff] [blame] | 3971 | install_element (RMAP_NODE, &set_pathlimit_ttl_cmd); |
| 3972 | install_element (RMAP_NODE, &no_set_pathlimit_ttl_cmd); |
| 3973 | install_element (RMAP_NODE, &no_set_pathlimit_ttl_val_cmd); |
| 3974 | install_element (RMAP_NODE, &match_pathlimit_as_cmd); |
| 3975 | install_element (RMAP_NODE, &no_match_pathlimit_as_cmd); |
| 3976 | install_element (RMAP_NODE, &no_match_pathlimit_as_val_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3977 | } |