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