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