]>
Commit | Line | Data |
---|---|---|
718e3744 | 1 | /* Route map function of bgpd. |
896014f4 DL |
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 along | |
17 | * with this program; see the file COPYING; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
19 | */ | |
718e3744 | 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" | |
1d7c7ace | 31 | #include "lua.h" |
25f45887 | 32 | #ifdef HAVE_LIBPCREPOSIX |
d62a17ae | 33 | #include <pcreposix.h> |
718e3744 | 34 | #else |
d62a17ae | 35 | #include <regex.h> |
25f45887 | 36 | #endif /* HAVE_LIBPCREPOSIX */ |
718e3744 | 37 | #include "buffer.h" |
38 | #include "sockunion.h" | |
518f0eb1 | 39 | #include "hash.h" |
3f9c7369 | 40 | #include "queue.h" |
5d5ba018 | 41 | #include "frrstr.h" |
718e3744 | 42 | |
43 | #include "bgpd/bgpd.h" | |
44 | #include "bgpd/bgp_table.h" | |
45 | #include "bgpd/bgp_attr.h" | |
46 | #include "bgpd/bgp_aspath.h" | |
518f0eb1 | 47 | #include "bgpd/bgp_packet.h" |
718e3744 | 48 | #include "bgpd/bgp_route.h" |
73ac8160 | 49 | #include "bgpd/bgp_zebra.h" |
718e3744 | 50 | #include "bgpd/bgp_regex.h" |
51 | #include "bgpd/bgp_community.h" | |
52 | #include "bgpd/bgp_clist.h" | |
53 | #include "bgpd/bgp_filter.h" | |
54 | #include "bgpd/bgp_mplsvpn.h" | |
55 | #include "bgpd/bgp_ecommunity.h" | |
57d187bc | 56 | #include "bgpd/bgp_lcommunity.h" |
320da874 | 57 | #include "bgpd/bgp_vty.h" |
73ac8160 | 58 | #include "bgpd/bgp_debug.h" |
d37ba549 MK |
59 | #include "bgpd/bgp_evpn.h" |
60 | #include "bgpd/bgp_evpn_private.h" | |
62982d5a | 61 | #include "bgpd/bgp_evpn_vty.h" |
ddb5b488 | 62 | #include "bgpd/bgp_mplsvpn.h" |
718e3744 | 63 | |
65efcfce | 64 | #if ENABLE_BGP_VNC |
d62a17ae | 65 | #include "bgpd/rfapi/bgp_rfapi_cfg.h" |
65efcfce | 66 | #endif |
518f0eb1 | 67 | |
718e3744 | 68 | /* Memo of route-map commands. |
69 | ||
70 | o Cisco route-map | |
71 | ||
72 | match as-path : Done | |
73 | community : Done | |
bc413143 | 74 | interface : Done |
718e3744 | 75 | ip address : Done |
76 | ip next-hop : Done | |
c1643bb7 | 77 | ip route-source : Done |
718e3744 | 78 | ip prefix-list : Done |
79 | ipv6 address : Done | |
80 | ipv6 next-hop : Done | |
81 | ipv6 route-source: (This will not be implemented by bgpd) | |
82 | ipv6 prefix-list : Done | |
83 | length : (This will not be implemented by bgpd) | |
84 | metric : Done | |
85 | route-type : (This will not be implemented by bgpd) | |
0d9551dc | 86 | tag : Done |
af291c15 | 87 | local-preference : Done |
718e3744 | 88 | |
89 | set as-path prepend : Done | |
90 | as-path tag : Not yet | |
91 | automatic-tag : (This will not be implemented by bgpd) | |
92 | community : Done | |
57d187bc JS |
93 | large-community : Done |
94 | large-comm-list : Done | |
718e3744 | 95 | comm-list : Not yet |
96 | dampning : Not yet | |
97 | default : (This will not be implemented by bgpd) | |
98 | interface : (This will not be implemented by bgpd) | |
99 | ip default : (This will not be implemented by bgpd) | |
100 | ip next-hop : Done | |
101 | ip precedence : (This will not be implemented by bgpd) | |
102 | ip tos : (This will not be implemented by bgpd) | |
103 | level : (This will not be implemented by bgpd) | |
104 | local-preference : Done | |
105 | metric : Done | |
106 | metric-type : Not yet | |
107 | origin : Done | |
0d9551dc | 108 | tag : Done |
718e3744 | 109 | weight : Done |
110 | ||
515e500c | 111 | o Local extensions |
718e3744 | 112 | |
113 | set ipv6 next-hop global: Done | |
161995ea | 114 | set ipv6 next-hop prefer-global: Done |
718e3744 | 115 | set ipv6 next-hop local : Done |
841f7a57 | 116 | set as-path exclude : Done |
718e3744 | 117 | |
e52702f2 | 118 | */ |
6b0655a2 | 119 | |
d62a17ae | 120 | /* generic value manipulation to be shared in multiple rules */ |
76759f4f TT |
121 | |
122 | #define RMAP_VALUE_SET 0 | |
123 | #define RMAP_VALUE_ADD 1 | |
124 | #define RMAP_VALUE_SUB 2 | |
125 | ||
d62a17ae | 126 | struct rmap_value { |
d7c0a89a QY |
127 | uint8_t action; |
128 | uint8_t variable; | |
129 | uint32_t value; | |
76759f4f TT |
130 | }; |
131 | ||
d7c0a89a | 132 | static int route_value_match(struct rmap_value *rv, uint32_t value) |
d62a17ae | 133 | { |
134 | if (rv->variable == 0 && value == rv->value) | |
135 | return RMAP_MATCH; | |
76759f4f | 136 | |
d62a17ae | 137 | return RMAP_NOMATCH; |
76759f4f TT |
138 | } |
139 | ||
d7c0a89a QY |
140 | static uint32_t route_value_adjust(struct rmap_value *rv, uint32_t current, |
141 | struct peer *peer) | |
76759f4f | 142 | { |
d7c0a89a | 143 | uint32_t value; |
baa376fc | 144 | |
d62a17ae | 145 | switch (rv->variable) { |
146 | case 1: | |
147 | value = peer->rtt; | |
148 | break; | |
149 | default: | |
150 | value = rv->value; | |
151 | break; | |
152 | } | |
76759f4f | 153 | |
d62a17ae | 154 | switch (rv->action) { |
155 | case RMAP_VALUE_ADD: | |
156 | if (current > UINT32_MAX - value) | |
157 | return UINT32_MAX; | |
158 | return current + value; | |
159 | case RMAP_VALUE_SUB: | |
160 | if (current <= value) | |
161 | return 0; | |
162 | return current - value; | |
163 | default: | |
164 | return value; | |
165 | } | |
76759f4f TT |
166 | } |
167 | ||
d62a17ae | 168 | static void *route_value_compile(const char *arg) |
76759f4f | 169 | { |
d7c0a89a | 170 | uint8_t action = RMAP_VALUE_SET, var = 0; |
d62a17ae | 171 | unsigned long larg = 0; |
172 | char *endptr = NULL; | |
173 | struct rmap_value *rv; | |
76759f4f | 174 | |
d62a17ae | 175 | if (arg[0] == '+') { |
176 | action = RMAP_VALUE_ADD; | |
177 | arg++; | |
178 | } else if (arg[0] == '-') { | |
179 | action = RMAP_VALUE_SUB; | |
180 | arg++; | |
181 | } | |
76759f4f | 182 | |
d62a17ae | 183 | if (all_digit(arg)) { |
184 | errno = 0; | |
185 | larg = strtoul(arg, &endptr, 10); | |
186 | if (*arg == 0 || *endptr != 0 || errno || larg > UINT32_MAX) | |
187 | return NULL; | |
188 | } else { | |
189 | if (strcmp(arg, "rtt") == 0) | |
190 | var = 1; | |
191 | else | |
192 | return NULL; | |
193 | } | |
76759f4f | 194 | |
d62a17ae | 195 | rv = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct rmap_value)); |
196 | if (!rv) | |
197 | return NULL; | |
76759f4f | 198 | |
d62a17ae | 199 | rv->action = action; |
200 | rv->variable = var; | |
201 | rv->value = larg; | |
202 | return rv; | |
76759f4f TT |
203 | } |
204 | ||
d62a17ae | 205 | static void route_value_free(void *rule) |
76759f4f | 206 | { |
d62a17ae | 207 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
76759f4f TT |
208 | } |
209 | ||
d62a17ae | 210 | /* generic as path object to be shared in multiple rules */ |
374f12f9 | 211 | |
d62a17ae | 212 | static void *route_aspath_compile(const char *arg) |
374f12f9 | 213 | { |
d62a17ae | 214 | struct aspath *aspath; |
374f12f9 | 215 | |
d62a17ae | 216 | aspath = aspath_str2aspath(arg); |
217 | if (!aspath) | |
218 | return NULL; | |
219 | return aspath; | |
374f12f9 TT |
220 | } |
221 | ||
d62a17ae | 222 | static void route_aspath_free(void *rule) |
374f12f9 | 223 | { |
d62a17ae | 224 | struct aspath *aspath = rule; |
225 | aspath_free(aspath); | |
374f12f9 TT |
226 | } |
227 | ||
8c3433e4 DS |
228 | struct bgp_match_peer_compiled { |
229 | char *interface; | |
230 | union sockunion su; | |
231 | }; | |
232 | ||
233 | /* 'match peer (A.B.C.D|X:X::X:X|WORD)' */ | |
fee0f4c6 | 234 | |
235 | /* Compares the peer specified in the 'match peer' clause with the peer | |
18ee8310 | 236 | received in bgp_path_info->peer. If it is the same, or if the peer structure |
fee0f4c6 | 237 | received is a peer_group containing it, returns RMAP_MATCH. */ |
123214ef MS |
238 | static route_map_result_t route_match_peer(void *rule, |
239 | const struct prefix *prefix, | |
d62a17ae | 240 | route_map_object_t type, |
241 | void *object) | |
242 | { | |
8c3433e4 | 243 | struct bgp_match_peer_compiled *pc; |
d62a17ae | 244 | union sockunion *su; |
245 | union sockunion su_def = { | |
246 | .sin = {.sin_family = AF_INET, .sin_addr.s_addr = INADDR_ANY}}; | |
247 | struct peer_group *group; | |
248 | struct peer *peer; | |
249 | struct listnode *node, *nnode; | |
250 | ||
251 | if (type == RMAP_BGP) { | |
8c3433e4 DS |
252 | pc = rule; |
253 | su = &pc->su; | |
4b7e6066 | 254 | peer = ((struct bgp_path_info *)object)->peer; |
d62a17ae | 255 | |
8c3433e4 DS |
256 | if (pc->interface) { |
257 | if (!peer->conf_if) | |
258 | return RMAP_NOMATCH; | |
259 | ||
260 | if (strcmp(peer->conf_if, pc->interface) == 0) | |
261 | return RMAP_MATCH; | |
262 | ||
263 | return RMAP_NOMATCH; | |
264 | } | |
265 | ||
d62a17ae | 266 | /* If su='0.0.0.0' (command 'match peer local'), and it's a |
267 | NETWORK, | |
268 | REDISTRIBUTE or DEFAULT_GENERATED route => return RMAP_MATCH | |
269 | */ | |
270 | if (sockunion_same(su, &su_def)) { | |
271 | int ret; | |
272 | if (CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_NETWORK) | |
273 | || CHECK_FLAG(peer->rmap_type, | |
274 | PEER_RMAP_TYPE_REDISTRIBUTE) | |
275 | || CHECK_FLAG(peer->rmap_type, | |
276 | PEER_RMAP_TYPE_DEFAULT)) | |
277 | ret = RMAP_MATCH; | |
278 | else | |
279 | ret = RMAP_NOMATCH; | |
280 | return ret; | |
281 | } | |
282 | ||
283 | if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) { | |
284 | if (sockunion_same(su, &peer->su)) | |
285 | return RMAP_MATCH; | |
286 | ||
287 | return RMAP_NOMATCH; | |
288 | } else { | |
289 | group = peer->group; | |
290 | for (ALL_LIST_ELEMENTS(group->peer, node, nnode, | |
291 | peer)) { | |
292 | if (sockunion_same(su, &peer->su)) | |
293 | return RMAP_MATCH; | |
294 | } | |
295 | return RMAP_NOMATCH; | |
296 | } | |
297 | } | |
298 | return RMAP_NOMATCH; | |
299 | } | |
300 | ||
301 | static void *route_match_peer_compile(const char *arg) | |
302 | { | |
8c3433e4 | 303 | struct bgp_match_peer_compiled *pc; |
d62a17ae | 304 | int ret; |
305 | ||
a633d869 | 306 | pc = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, |
8c3433e4 | 307 | sizeof(struct bgp_match_peer_compiled)); |
d62a17ae | 308 | |
8c3433e4 | 309 | ret = str2sockunion(strcmp(arg, "local") ? arg : "0.0.0.0", &pc->su); |
d62a17ae | 310 | if (ret < 0) { |
8c3433e4 DS |
311 | pc->interface = XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); |
312 | return pc; | |
d62a17ae | 313 | } |
314 | ||
8c3433e4 | 315 | return pc; |
fee0f4c6 | 316 | } |
317 | ||
318 | /* Free route map's compiled `ip address' value. */ | |
d62a17ae | 319 | static void route_match_peer_free(void *rule) |
fee0f4c6 | 320 | { |
8c3433e4 DS |
321 | struct bgp_match_peer_compiled *pc = rule; |
322 | ||
323 | if (pc->interface) | |
324 | XFREE(MTYPE_ROUTE_MAP_COMPILED, pc->interface); | |
325 | ||
d62a17ae | 326 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
fee0f4c6 | 327 | } |
328 | ||
329 | /* Route map commands for ip address matching. */ | |
d62a17ae | 330 | struct route_map_rule_cmd route_match_peer_cmd = {"peer", route_match_peer, |
331 | route_match_peer_compile, | |
332 | route_match_peer_free}; | |
fee0f4c6 | 333 | |
1d7c7ace DS |
334 | #if defined(HAVE_LUA) |
335 | static route_map_result_t route_match_command(void *rule, | |
336 | const struct prefix *prefix, | |
337 | route_map_object_t type, | |
338 | void *object) | |
339 | { | |
340 | int status = RMAP_NOMATCH; | |
341 | u_int32_t locpref = 0; | |
342 | u_int32_t newlocpref = 0; | |
343 | enum lua_rm_status lrm_status; | |
40381db7 | 344 | struct bgp_path_info *path = (struct bgp_path_info *)object; |
1d7c7ace DS |
345 | lua_State *L = lua_initialize("/etc/frr/lua.scr"); |
346 | ||
347 | if (L == NULL) | |
348 | return status; | |
349 | ||
350 | /* | |
351 | * Setup the prefix information to pass in | |
352 | */ | |
353 | lua_setup_prefix_table(L, prefix); | |
354 | ||
355 | zlog_debug("Set up prefix table"); | |
356 | /* | |
18ee8310 | 357 | * Setup the bgp_path_info information |
1d7c7ace DS |
358 | */ |
359 | lua_newtable(L); | |
40381db7 | 360 | lua_pushinteger(L, path->attr->med); |
1d7c7ace | 361 | lua_setfield(L, -2, "metric"); |
40381db7 | 362 | lua_pushinteger(L, path->attr->nh_ifindex); |
1d7c7ace | 363 | lua_setfield(L, -2, "ifindex"); |
40381db7 | 364 | lua_pushstring(L, path->attr->aspath->str); |
1d7c7ace | 365 | lua_setfield(L, -2, "aspath"); |
40381db7 | 366 | lua_pushinteger(L, path->attr->local_pref); |
1d7c7ace | 367 | lua_setfield(L, -2, "localpref"); |
40381db7 | 368 | zlog_debug("%s %d", path->attr->aspath->str, path->attr->nh_ifindex); |
1d7c7ace DS |
369 | lua_setglobal(L, "nexthop"); |
370 | ||
371 | zlog_debug("Set up nexthop information"); | |
372 | /* | |
373 | * Run the rule | |
374 | */ | |
375 | lrm_status = lua_run_rm_rule(L, rule); | |
376 | switch (lrm_status) { | |
377 | case LUA_RM_FAILURE: | |
378 | zlog_debug("RM_FAILURE"); | |
379 | break; | |
380 | case LUA_RM_NOMATCH: | |
381 | zlog_debug("RM_NOMATCH"); | |
382 | break; | |
383 | case LUA_RM_MATCH_AND_CHANGE: | |
384 | zlog_debug("MATCH AND CHANGE"); | |
385 | lua_getglobal(L, "nexthop"); | |
40381db7 | 386 | path->attr->med = get_integer(L, "metric"); |
1d7c7ace DS |
387 | /* |
388 | * This needs to be abstraced with the set function | |
389 | */ | |
40381db7 DS |
390 | if (path->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF)) |
391 | locpref = path->attr->local_pref; | |
1d7c7ace DS |
392 | newlocpref = get_integer(L, "localpref"); |
393 | if (newlocpref != locpref) { | |
40381db7 DS |
394 | path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF); |
395 | path->attr->local_pref = newlocpref; | |
1d7c7ace DS |
396 | } |
397 | status = RMAP_MATCH; | |
398 | break; | |
399 | case LUA_RM_MATCH: | |
400 | zlog_debug("MATCH ONLY"); | |
401 | status = RMAP_MATCH; | |
402 | break; | |
403 | } | |
404 | lua_close(L); | |
405 | return status; | |
406 | } | |
407 | ||
408 | static void *route_match_command_compile(const char *arg) | |
409 | { | |
410 | char *command; | |
411 | ||
412 | command = XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); | |
413 | return command; | |
414 | } | |
415 | ||
416 | static void | |
417 | route_match_command_free(void *rule) | |
418 | { | |
419 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); | |
420 | } | |
421 | ||
422 | struct route_map_rule_cmd route_match_command_cmd = { | |
423 | "command", | |
424 | route_match_command, | |
425 | route_match_command_compile, | |
426 | route_match_command_free | |
427 | }; | |
428 | #endif | |
429 | ||
718e3744 | 430 | /* `match ip address IP_ACCESS_LIST' */ |
431 | ||
432 | /* Match function should return 1 if match is success else return | |
433 | zero. */ | |
d62a17ae | 434 | static route_map_result_t route_match_ip_address(void *rule, |
123214ef | 435 | const struct prefix *prefix, |
d62a17ae | 436 | route_map_object_t type, |
437 | void *object) | |
438 | { | |
439 | struct access_list *alist; | |
d62a17ae | 440 | |
09cd98eb | 441 | if (type == RMAP_BGP && prefix->family == AF_INET) { |
d62a17ae | 442 | alist = access_list_lookup(AFI_IP, (char *)rule); |
443 | if (alist == NULL) | |
444 | return RMAP_NOMATCH; | |
445 | ||
446 | return (access_list_apply(alist, prefix) == FILTER_DENY | |
447 | ? RMAP_NOMATCH | |
448 | : RMAP_MATCH); | |
449 | } | |
718e3744 | 450 | return RMAP_NOMATCH; |
718e3744 | 451 | } |
452 | ||
453 | /* Route map `ip address' match statement. `arg' should be | |
454 | access-list name. */ | |
d62a17ae | 455 | static void *route_match_ip_address_compile(const char *arg) |
718e3744 | 456 | { |
d62a17ae | 457 | return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); |
718e3744 | 458 | } |
459 | ||
460 | /* Free route map's compiled `ip address' value. */ | |
d62a17ae | 461 | static void route_match_ip_address_free(void *rule) |
718e3744 | 462 | { |
d62a17ae | 463 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
718e3744 | 464 | } |
465 | ||
466 | /* Route map commands for ip address matching. */ | |
d62a17ae | 467 | struct route_map_rule_cmd route_match_ip_address_cmd = { |
468 | "ip address", route_match_ip_address, route_match_ip_address_compile, | |
469 | route_match_ip_address_free}; | |
6b0655a2 | 470 | |
718e3744 | 471 | /* `match ip next-hop IP_ADDRESS' */ |
472 | ||
473 | /* Match function return 1 if match is success else return zero. */ | |
d62a17ae | 474 | static route_map_result_t route_match_ip_next_hop(void *rule, |
123214ef | 475 | const struct prefix *prefix, |
d62a17ae | 476 | route_map_object_t type, |
477 | void *object) | |
478 | { | |
479 | struct access_list *alist; | |
9b6d8fcf | 480 | struct bgp_path_info *path; |
d62a17ae | 481 | struct prefix_ipv4 p; |
482 | ||
09cd98eb | 483 | if (type == RMAP_BGP && prefix->family == AF_INET) { |
9b6d8fcf | 484 | path = object; |
d62a17ae | 485 | p.family = AF_INET; |
9b6d8fcf | 486 | p.prefix = path->attr->nexthop; |
d62a17ae | 487 | p.prefixlen = IPV4_MAX_BITLEN; |
488 | ||
489 | alist = access_list_lookup(AFI_IP, (char *)rule); | |
490 | if (alist == NULL) | |
491 | return RMAP_NOMATCH; | |
492 | ||
493 | return (access_list_apply(alist, &p) == FILTER_DENY | |
494 | ? RMAP_NOMATCH | |
495 | : RMAP_MATCH); | |
496 | } | |
718e3744 | 497 | return RMAP_NOMATCH; |
718e3744 | 498 | } |
499 | ||
500 | /* Route map `ip next-hop' match statement. `arg' is | |
501 | access-list name. */ | |
d62a17ae | 502 | static void *route_match_ip_next_hop_compile(const char *arg) |
718e3744 | 503 | { |
d62a17ae | 504 | return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); |
718e3744 | 505 | } |
506 | ||
507 | /* Free route map's compiled `ip address' value. */ | |
d62a17ae | 508 | static void route_match_ip_next_hop_free(void *rule) |
718e3744 | 509 | { |
d62a17ae | 510 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
718e3744 | 511 | } |
512 | ||
513 | /* Route map commands for ip next-hop matching. */ | |
d62a17ae | 514 | struct route_map_rule_cmd route_match_ip_next_hop_cmd = { |
515 | "ip next-hop", route_match_ip_next_hop, route_match_ip_next_hop_compile, | |
516 | route_match_ip_next_hop_free}; | |
6b0655a2 | 517 | |
c1643bb7 | 518 | /* `match ip route-source ACCESS-LIST' */ |
519 | ||
520 | /* Match function return 1 if match is success else return zero. */ | |
d62a17ae | 521 | static route_map_result_t route_match_ip_route_source(void *rule, |
123214ef | 522 | const struct prefix *pfx, |
d62a17ae | 523 | route_map_object_t type, |
524 | void *object) | |
525 | { | |
526 | struct access_list *alist; | |
9b6d8fcf | 527 | struct bgp_path_info *path; |
d62a17ae | 528 | struct peer *peer; |
529 | struct prefix_ipv4 p; | |
530 | ||
123214ef | 531 | if (type == RMAP_BGP && pfx->family == AF_INET) { |
9b6d8fcf DS |
532 | path = object; |
533 | peer = path->peer; | |
d62a17ae | 534 | |
535 | if (!peer || sockunion_family(&peer->su) != AF_INET) | |
536 | return RMAP_NOMATCH; | |
537 | ||
538 | p.family = AF_INET; | |
539 | p.prefix = peer->su.sin.sin_addr; | |
540 | p.prefixlen = IPV4_MAX_BITLEN; | |
541 | ||
542 | alist = access_list_lookup(AFI_IP, (char *)rule); | |
543 | if (alist == NULL) | |
544 | return RMAP_NOMATCH; | |
545 | ||
546 | return (access_list_apply(alist, &p) == FILTER_DENY | |
547 | ? RMAP_NOMATCH | |
548 | : RMAP_MATCH); | |
549 | } | |
c1643bb7 | 550 | return RMAP_NOMATCH; |
c1643bb7 | 551 | } |
552 | ||
553 | /* Route map `ip route-source' match statement. `arg' is | |
554 | access-list name. */ | |
d62a17ae | 555 | static void *route_match_ip_route_source_compile(const char *arg) |
c1643bb7 | 556 | { |
d62a17ae | 557 | return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); |
c1643bb7 | 558 | } |
559 | ||
560 | /* Free route map's compiled `ip address' value. */ | |
d62a17ae | 561 | static void route_match_ip_route_source_free(void *rule) |
c1643bb7 | 562 | { |
d62a17ae | 563 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
c1643bb7 | 564 | } |
565 | ||
566 | /* Route map commands for ip route-source matching. */ | |
d62a17ae | 567 | struct route_map_rule_cmd route_match_ip_route_source_cmd = { |
568 | "ip route-source", route_match_ip_route_source, | |
569 | route_match_ip_route_source_compile, route_match_ip_route_source_free}; | |
6b0655a2 | 570 | |
718e3744 | 571 | /* `match ip address prefix-list PREFIX_LIST' */ |
572 | ||
94f2b392 | 573 | static route_map_result_t |
123214ef | 574 | route_match_ip_address_prefix_list(void *rule, const struct prefix *prefix, |
d62a17ae | 575 | route_map_object_t type, void *object) |
718e3744 | 576 | { |
d62a17ae | 577 | struct prefix_list *plist; |
718e3744 | 578 | |
09cd98eb | 579 | if (type == RMAP_BGP && prefix->family == AF_INET) { |
d62a17ae | 580 | plist = prefix_list_lookup(AFI_IP, (char *)rule); |
581 | if (plist == NULL) | |
582 | return RMAP_NOMATCH; | |
e52702f2 | 583 | |
d62a17ae | 584 | return (prefix_list_apply(plist, prefix) == PREFIX_DENY |
585 | ? RMAP_NOMATCH | |
586 | : RMAP_MATCH); | |
587 | } | |
588 | return RMAP_NOMATCH; | |
718e3744 | 589 | } |
590 | ||
d62a17ae | 591 | static void *route_match_ip_address_prefix_list_compile(const char *arg) |
718e3744 | 592 | { |
d62a17ae | 593 | return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); |
718e3744 | 594 | } |
595 | ||
d62a17ae | 596 | static void route_match_ip_address_prefix_list_free(void *rule) |
718e3744 | 597 | { |
d62a17ae | 598 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
718e3744 | 599 | } |
600 | ||
d62a17ae | 601 | struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd = { |
602 | "ip address prefix-list", route_match_ip_address_prefix_list, | |
603 | route_match_ip_address_prefix_list_compile, | |
604 | route_match_ip_address_prefix_list_free}; | |
6b0655a2 | 605 | |
718e3744 | 606 | /* `match ip next-hop prefix-list PREFIX_LIST' */ |
607 | ||
94f2b392 | 608 | static route_map_result_t |
123214ef | 609 | route_match_ip_next_hop_prefix_list(void *rule, const struct prefix *prefix, |
d62a17ae | 610 | route_map_object_t type, void *object) |
718e3744 | 611 | { |
d62a17ae | 612 | struct prefix_list *plist; |
9b6d8fcf | 613 | struct bgp_path_info *path; |
d62a17ae | 614 | struct prefix_ipv4 p; |
718e3744 | 615 | |
09cd98eb | 616 | if (type == RMAP_BGP && prefix->family == AF_INET) { |
9b6d8fcf | 617 | path = object; |
d62a17ae | 618 | p.family = AF_INET; |
9b6d8fcf | 619 | p.prefix = path->attr->nexthop; |
d62a17ae | 620 | p.prefixlen = IPV4_MAX_BITLEN; |
718e3744 | 621 | |
d62a17ae | 622 | plist = prefix_list_lookup(AFI_IP, (char *)rule); |
623 | if (plist == NULL) | |
624 | return RMAP_NOMATCH; | |
718e3744 | 625 | |
d62a17ae | 626 | return (prefix_list_apply(plist, &p) == PREFIX_DENY |
627 | ? RMAP_NOMATCH | |
628 | : RMAP_MATCH); | |
629 | } | |
630 | return RMAP_NOMATCH; | |
718e3744 | 631 | } |
632 | ||
d62a17ae | 633 | static void *route_match_ip_next_hop_prefix_list_compile(const char *arg) |
718e3744 | 634 | { |
d62a17ae | 635 | return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); |
718e3744 | 636 | } |
637 | ||
d62a17ae | 638 | static void route_match_ip_next_hop_prefix_list_free(void *rule) |
718e3744 | 639 | { |
d62a17ae | 640 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
718e3744 | 641 | } |
642 | ||
d62a17ae | 643 | struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd = { |
644 | "ip next-hop prefix-list", route_match_ip_next_hop_prefix_list, | |
645 | route_match_ip_next_hop_prefix_list_compile, | |
646 | route_match_ip_next_hop_prefix_list_free}; | |
6b0655a2 | 647 | |
61ad901e DA |
648 | /* `match ip next-hop type <blackhole>' */ |
649 | ||
650 | static route_map_result_t | |
651 | route_match_ip_next_hop_type(void *rule, const struct prefix *prefix, | |
652 | route_map_object_t type, void *object) | |
653 | { | |
9b6d8fcf | 654 | struct bgp_path_info *path; |
61ad901e DA |
655 | |
656 | if (type == RMAP_BGP && prefix->family == AF_INET) { | |
9b6d8fcf DS |
657 | path = (struct bgp_path_info *)object; |
658 | if (!path || !path->attr) | |
61ad901e DA |
659 | return RMAP_DENYMATCH; |
660 | ||
661 | /* If nexthop interface's index can't be resolved and nexthop is | |
662 | set to any address then mark it as type `blackhole`. | |
663 | This logic works for matching kernel/static routes like: | |
664 | `ip route add blackhole 10.0.0.1`. */ | |
9b6d8fcf DS |
665 | if (path->attr->nexthop.s_addr == INADDR_ANY |
666 | && !path->attr->nh_ifindex) | |
61ad901e DA |
667 | return RMAP_MATCH; |
668 | } | |
669 | return RMAP_NOMATCH; | |
670 | } | |
671 | ||
672 | static void *route_match_ip_next_hop_type_compile(const char *arg) | |
673 | { | |
674 | return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); | |
675 | } | |
676 | ||
677 | static void route_match_ip_next_hop_type_free(void *rule) | |
678 | { | |
679 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); | |
680 | } | |
681 | ||
682 | static struct route_map_rule_cmd route_match_ip_next_hop_type_cmd = { | |
683 | "ip next-hop type", route_match_ip_next_hop_type, | |
684 | route_match_ip_next_hop_type_compile, | |
685 | route_match_ip_next_hop_type_free}; | |
686 | ||
c1643bb7 | 687 | /* `match ip route-source prefix-list PREFIX_LIST' */ |
688 | ||
94f2b392 | 689 | static route_map_result_t |
123214ef MS |
690 | route_match_ip_route_source_prefix_list(void *rule, |
691 | const struct prefix *prefix, | |
d62a17ae | 692 | route_map_object_t type, void *object) |
c1643bb7 | 693 | { |
d62a17ae | 694 | struct prefix_list *plist; |
9b6d8fcf | 695 | struct bgp_path_info *path; |
d62a17ae | 696 | struct peer *peer; |
697 | struct prefix_ipv4 p; | |
c1643bb7 | 698 | |
09cd98eb | 699 | if (type == RMAP_BGP && prefix->family == AF_INET) { |
9b6d8fcf DS |
700 | path = object; |
701 | peer = path->peer; | |
c1643bb7 | 702 | |
d62a17ae | 703 | if (!peer || sockunion_family(&peer->su) != AF_INET) |
704 | return RMAP_NOMATCH; | |
c1643bb7 | 705 | |
d62a17ae | 706 | p.family = AF_INET; |
707 | p.prefix = peer->su.sin.sin_addr; | |
708 | p.prefixlen = IPV4_MAX_BITLEN; | |
c1643bb7 | 709 | |
d62a17ae | 710 | plist = prefix_list_lookup(AFI_IP, (char *)rule); |
711 | if (plist == NULL) | |
712 | return RMAP_NOMATCH; | |
c1643bb7 | 713 | |
d62a17ae | 714 | return (prefix_list_apply(plist, &p) == PREFIX_DENY |
715 | ? RMAP_NOMATCH | |
716 | : RMAP_MATCH); | |
717 | } | |
718 | return RMAP_NOMATCH; | |
c1643bb7 | 719 | } |
720 | ||
d62a17ae | 721 | static void *route_match_ip_route_source_prefix_list_compile(const char *arg) |
c1643bb7 | 722 | { |
d62a17ae | 723 | return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); |
c1643bb7 | 724 | } |
725 | ||
d62a17ae | 726 | static void route_match_ip_route_source_prefix_list_free(void *rule) |
c1643bb7 | 727 | { |
d62a17ae | 728 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
c1643bb7 | 729 | } |
730 | ||
d62a17ae | 731 | struct route_map_rule_cmd route_match_ip_route_source_prefix_list_cmd = { |
732 | "ip route-source prefix-list", route_match_ip_route_source_prefix_list, | |
733 | route_match_ip_route_source_prefix_list_compile, | |
734 | route_match_ip_route_source_prefix_list_free}; | |
6b0655a2 | 735 | |
6fb219da MK |
736 | /* `match evpn default-route' */ |
737 | ||
738 | /* Match function should return 1 if match is success else 0 */ | |
739 | static route_map_result_t route_match_evpn_default_route(void *rule, | |
123214ef | 740 | const struct prefix *p, |
6fb219da MK |
741 | route_map_object_t |
742 | type, void *object) | |
743 | { | |
744 | if (type == RMAP_BGP && is_evpn_prefix_default(p)) | |
745 | return RMAP_MATCH; | |
746 | ||
747 | return RMAP_NOMATCH; | |
748 | } | |
749 | ||
750 | /* Route map commands for default-route matching. */ | |
751 | struct route_map_rule_cmd route_match_evpn_default_route_cmd = { | |
752 | "evpn default-route", route_match_evpn_default_route, NULL, NULL}; | |
753 | ||
d37ba549 MK |
754 | /* `match mac address MAC_ACCESS_LIST' */ |
755 | ||
756 | /* Match function should return 1 if match is success else return | |
757 | zero. */ | |
758 | static route_map_result_t route_match_mac_address(void *rule, | |
123214ef | 759 | const struct prefix *prefix, |
d37ba549 MK |
760 | route_map_object_t type, |
761 | void *object) | |
762 | { | |
763 | struct access_list *alist; | |
0f6476cc | 764 | struct prefix p; |
d37ba549 MK |
765 | |
766 | if (type == RMAP_BGP) { | |
767 | alist = access_list_lookup(AFI_L2VPN, (char *)rule); | |
768 | if (alist == NULL) | |
769 | return RMAP_NOMATCH; | |
770 | ||
771 | if (prefix->u.prefix_evpn.route_type != BGP_EVPN_MAC_IP_ROUTE) | |
772 | return RMAP_NOMATCH; | |
773 | ||
0f6476cc DS |
774 | p.family = AF_ETHERNET; |
775 | p.prefixlen = ETH_ALEN * 8; | |
3714a385 | 776 | p.u.prefix_eth = prefix->u.prefix_evpn.macip_addr.mac; |
0f6476cc | 777 | |
a4d82a8a | 778 | return (access_list_apply(alist, &p) == FILTER_DENY |
d37ba549 MK |
779 | ? RMAP_NOMATCH |
780 | : RMAP_MATCH); | |
781 | } | |
782 | ||
783 | return RMAP_NOMATCH; | |
784 | } | |
785 | ||
786 | /* Route map `mac address' match statement. `arg' should be | |
787 | access-list name. */ | |
788 | static void *route_match_mac_address_compile(const char *arg) | |
789 | { | |
790 | return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); | |
791 | } | |
792 | ||
793 | /* Free route map's compiled `ip address' value. */ | |
794 | static void route_match_mac_address_free(void *rule) | |
795 | { | |
796 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); | |
797 | } | |
798 | ||
799 | /* Route map commands for mac address matching. */ | |
800 | struct route_map_rule_cmd route_match_mac_address_cmd = { | |
801 | "mac address", route_match_mac_address, route_match_mac_address_compile, | |
802 | route_match_mac_address_free}; | |
803 | ||
16f7ce2b MK |
804 | /* `match vni' */ |
805 | ||
806 | /* Match function should return 1 if match is success else return | |
807 | zero. */ | |
123214ef MS |
808 | static route_map_result_t route_match_vni(void *rule, |
809 | const struct prefix *prefix, | |
16f7ce2b MK |
810 | route_map_object_t type, void *object) |
811 | { | |
812 | vni_t vni = 0; | |
9b6d8fcf | 813 | struct bgp_path_info *path = NULL; |
16f7ce2b MK |
814 | |
815 | if (type == RMAP_BGP) { | |
816 | vni = *((vni_t *)rule); | |
9b6d8fcf | 817 | path = (struct bgp_path_info *)object; |
16f7ce2b | 818 | |
9b6d8fcf | 819 | if (path->extra == NULL) |
80ced710 CS |
820 | return RMAP_NOMATCH; |
821 | ||
9b6d8fcf | 822 | if (vni == label2vni(&path->extra->label[0])) |
16f7ce2b MK |
823 | return RMAP_MATCH; |
824 | } | |
825 | ||
826 | return RMAP_NOMATCH; | |
827 | } | |
828 | ||
829 | /* Route map `vni' match statement. */ | |
830 | static void *route_match_vni_compile(const char *arg) | |
831 | { | |
832 | vni_t *vni = NULL; | |
833 | char *end = NULL; | |
834 | ||
835 | vni = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(vni_t)); | |
836 | if (!vni) | |
837 | return NULL; | |
838 | ||
839 | *vni = strtoul(arg, &end, 10); | |
0af35d90 RW |
840 | if (*end != '\0') { |
841 | XFREE(MTYPE_ROUTE_MAP_COMPILED, vni); | |
16f7ce2b | 842 | return NULL; |
0af35d90 | 843 | } |
16f7ce2b MK |
844 | |
845 | return vni; | |
846 | } | |
847 | ||
848 | /* Free route map's compiled `vni' value. */ | |
849 | static void route_match_vni_free(void *rule) | |
850 | { | |
851 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); | |
852 | } | |
853 | ||
854 | /* Route map commands for vni matching. */ | |
855 | struct route_map_rule_cmd route_match_evpn_vni_cmd = { | |
646050e5 MK |
856 | "evpn vni", route_match_vni, route_match_vni_compile, |
857 | route_match_vni_free}; | |
16f7ce2b | 858 | |
33c2ff62 MK |
859 | /* `match evpn route-type' */ |
860 | ||
861 | /* Match function should return 1 if match is success else return | |
862 | zero. */ | |
863 | static route_map_result_t route_match_evpn_route_type(void *rule, | |
123214ef | 864 | const struct prefix *pfx, |
33c2ff62 MK |
865 | route_map_object_t type, |
866 | void *object) | |
867 | { | |
d7c0a89a | 868 | uint8_t route_type = 0; |
33c2ff62 MK |
869 | |
870 | if (type == RMAP_BGP) { | |
d7c0a89a | 871 | route_type = *((uint8_t *)rule); |
33c2ff62 | 872 | |
123214ef | 873 | if (route_type == pfx->u.prefix_evpn.route_type) |
33c2ff62 MK |
874 | return RMAP_MATCH; |
875 | } | |
876 | ||
877 | return RMAP_NOMATCH; | |
878 | } | |
879 | ||
880 | /* Route map `route-type' match statement. */ | |
881 | static void *route_match_evpn_route_type_compile(const char *arg) | |
882 | { | |
d7c0a89a | 883 | uint8_t *route_type = NULL; |
33c2ff62 | 884 | |
d7c0a89a | 885 | route_type = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(uint8_t)); |
33c2ff62 MK |
886 | |
887 | if (strncmp(arg, "ma", 2) == 0) | |
888 | *route_type = BGP_EVPN_MAC_IP_ROUTE; | |
889 | else if (strncmp(arg, "mu", 2) == 0) | |
890 | *route_type = BGP_EVPN_IMET_ROUTE; | |
891 | else | |
892 | *route_type = BGP_EVPN_IP_PREFIX_ROUTE; | |
893 | ||
894 | return route_type; | |
895 | } | |
896 | ||
897 | /* Free route map's compiled `route-type' value. */ | |
898 | static void route_match_evpn_route_type_free(void *rule) | |
899 | { | |
900 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); | |
901 | } | |
902 | ||
903 | /* Route map commands for evpn route-type matching. */ | |
904 | struct route_map_rule_cmd route_match_evpn_route_type_cmd = { | |
905 | "evpn route-type", route_match_evpn_route_type, | |
996c9314 | 906 | route_match_evpn_route_type_compile, route_match_evpn_route_type_free}; |
33c2ff62 | 907 | |
af291c15 DS |
908 | /* `match local-preference LOCAL-PREF' */ |
909 | ||
910 | /* Match function return 1 if match is success else return zero. */ | |
d62a17ae | 911 | static route_map_result_t route_match_local_pref(void *rule, |
123214ef | 912 | const struct prefix *prefix, |
d62a17ae | 913 | route_map_object_t type, |
914 | void *object) | |
915 | { | |
d7c0a89a | 916 | uint32_t *local_pref; |
9b6d8fcf | 917 | struct bgp_path_info *path; |
d62a17ae | 918 | |
919 | if (type == RMAP_BGP) { | |
920 | local_pref = rule; | |
9b6d8fcf | 921 | path = object; |
d62a17ae | 922 | |
9b6d8fcf | 923 | if (path->attr->local_pref == *local_pref) |
d62a17ae | 924 | return RMAP_MATCH; |
925 | else | |
926 | return RMAP_NOMATCH; | |
927 | } | |
af291c15 | 928 | return RMAP_NOMATCH; |
af291c15 DS |
929 | } |
930 | ||
931 | /* Route map `match local-preference' match statement. | |
932 | `arg' is local-pref value */ | |
d62a17ae | 933 | static void *route_match_local_pref_compile(const char *arg) |
af291c15 | 934 | { |
d7c0a89a | 935 | uint32_t *local_pref; |
d62a17ae | 936 | char *endptr = NULL; |
937 | unsigned long tmpval; | |
af291c15 | 938 | |
d62a17ae | 939 | /* Locpref value shoud be integer. */ |
940 | if (!all_digit(arg)) | |
941 | return NULL; | |
af291c15 | 942 | |
d62a17ae | 943 | errno = 0; |
944 | tmpval = strtoul(arg, &endptr, 10); | |
945 | if (*endptr != '\0' || errno || tmpval > UINT32_MAX) | |
946 | return NULL; | |
af291c15 | 947 | |
d7c0a89a | 948 | local_pref = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(uint32_t)); |
af291c15 | 949 | |
d62a17ae | 950 | if (!local_pref) |
951 | return local_pref; | |
af291c15 | 952 | |
d62a17ae | 953 | *local_pref = tmpval; |
954 | return local_pref; | |
af291c15 DS |
955 | } |
956 | ||
957 | /* Free route map's compiled `match local-preference' value. */ | |
d62a17ae | 958 | static void route_match_local_pref_free(void *rule) |
af291c15 | 959 | { |
d62a17ae | 960 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
af291c15 DS |
961 | } |
962 | ||
963 | /* Route map commands for metric matching. */ | |
d62a17ae | 964 | struct route_map_rule_cmd route_match_local_pref_cmd = { |
965 | "local-preference", route_match_local_pref, | |
966 | route_match_local_pref_compile, route_match_local_pref_free}; | |
af291c15 | 967 | |
718e3744 | 968 | /* `match metric METRIC' */ |
969 | ||
970 | /* Match function return 1 if match is success else return zero. */ | |
123214ef MS |
971 | static route_map_result_t route_match_metric(void *rule, |
972 | const struct prefix *prefix, | |
d62a17ae | 973 | route_map_object_t type, |
974 | void *object) | |
718e3744 | 975 | { |
d62a17ae | 976 | struct rmap_value *rv; |
9b6d8fcf | 977 | struct bgp_path_info *path; |
718e3744 | 978 | |
d62a17ae | 979 | if (type == RMAP_BGP) { |
980 | rv = rule; | |
9b6d8fcf DS |
981 | path = object; |
982 | return route_value_match(rv, path->attr->med); | |
d62a17ae | 983 | } |
984 | return RMAP_NOMATCH; | |
718e3744 | 985 | } |
986 | ||
718e3744 | 987 | /* Route map commands for metric matching. */ |
d62a17ae | 988 | struct route_map_rule_cmd route_match_metric_cmd = { |
9d303b37 | 989 | "metric", route_match_metric, route_value_compile, route_value_free, |
718e3744 | 990 | }; |
6b0655a2 | 991 | |
718e3744 | 992 | /* `match as-path ASPATH' */ |
993 | ||
994 | /* Match function for as-path match. I assume given object is */ | |
123214ef MS |
995 | static route_map_result_t route_match_aspath(void *rule, |
996 | const struct prefix *prefix, | |
d62a17ae | 997 | route_map_object_t type, |
998 | void *object) | |
718e3744 | 999 | { |
e52702f2 | 1000 | |
d62a17ae | 1001 | struct as_list *as_list; |
9b6d8fcf | 1002 | struct bgp_path_info *path; |
718e3744 | 1003 | |
d62a17ae | 1004 | if (type == RMAP_BGP) { |
1005 | as_list = as_list_lookup((char *)rule); | |
1006 | if (as_list == NULL) | |
1007 | return RMAP_NOMATCH; | |
518f0eb1 | 1008 | |
9b6d8fcf | 1009 | path = object; |
518f0eb1 | 1010 | |
d62a17ae | 1011 | /* Perform match. */ |
9b6d8fcf | 1012 | return ((as_list_apply(as_list, path->attr->aspath) |
d62a17ae | 1013 | == AS_FILTER_DENY) |
1014 | ? RMAP_NOMATCH | |
1015 | : RMAP_MATCH); | |
1016 | } | |
1017 | return RMAP_NOMATCH; | |
718e3744 | 1018 | } |
1019 | ||
1020 | /* Compile function for as-path match. */ | |
d62a17ae | 1021 | static void *route_match_aspath_compile(const char *arg) |
718e3744 | 1022 | { |
d62a17ae | 1023 | return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); |
718e3744 | 1024 | } |
1025 | ||
1026 | /* Compile function for as-path match. */ | |
d62a17ae | 1027 | static void route_match_aspath_free(void *rule) |
718e3744 | 1028 | { |
d62a17ae | 1029 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
718e3744 | 1030 | } |
1031 | ||
1032 | /* Route map commands for aspath matching. */ | |
d62a17ae | 1033 | struct route_map_rule_cmd route_match_aspath_cmd = { |
1034 | "as-path", route_match_aspath, route_match_aspath_compile, | |
1035 | route_match_aspath_free}; | |
6b0655a2 | 1036 | |
718e3744 | 1037 | /* `match community COMMUNIY' */ |
d62a17ae | 1038 | struct rmap_community { |
1039 | char *name; | |
1040 | int exact; | |
718e3744 | 1041 | }; |
1042 | ||
1043 | /* Match function for community match. */ | |
d62a17ae | 1044 | static route_map_result_t route_match_community(void *rule, |
123214ef | 1045 | const struct prefix *prefix, |
d62a17ae | 1046 | route_map_object_t type, |
1047 | void *object) | |
1048 | { | |
1049 | struct community_list *list; | |
9b6d8fcf | 1050 | struct bgp_path_info *path; |
d62a17ae | 1051 | struct rmap_community *rcom; |
1052 | ||
1053 | if (type == RMAP_BGP) { | |
9b6d8fcf | 1054 | path = object; |
d62a17ae | 1055 | rcom = rule; |
1056 | ||
1057 | list = community_list_lookup(bgp_clist, rcom->name, | |
1058 | COMMUNITY_LIST_MASTER); | |
1059 | if (!list) | |
1060 | return RMAP_NOMATCH; | |
1061 | ||
1062 | if (rcom->exact) { | |
9b6d8fcf DS |
1063 | if (community_list_exact_match(path->attr->community, |
1064 | list)) | |
d62a17ae | 1065 | return RMAP_MATCH; |
1066 | } else { | |
9b6d8fcf | 1067 | if (community_list_match(path->attr->community, list)) |
d62a17ae | 1068 | return RMAP_MATCH; |
1069 | } | |
718e3744 | 1070 | } |
d62a17ae | 1071 | return RMAP_NOMATCH; |
718e3744 | 1072 | } |
1073 | ||
1074 | /* Compile function for community match. */ | |
d62a17ae | 1075 | static void *route_match_community_compile(const char *arg) |
1076 | { | |
1077 | struct rmap_community *rcom; | |
1078 | int len; | |
1079 | char *p; | |
1080 | ||
1081 | rcom = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct rmap_community)); | |
1082 | ||
1083 | p = strchr(arg, ' '); | |
1084 | if (p) { | |
1085 | len = p - arg; | |
1086 | rcom->name = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, len + 1); | |
1087 | memcpy(rcom->name, arg, len); | |
1088 | rcom->exact = 1; | |
1089 | } else { | |
1090 | rcom->name = XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); | |
1091 | rcom->exact = 0; | |
1092 | } | |
1093 | return rcom; | |
718e3744 | 1094 | } |
1095 | ||
1096 | /* Compile function for community match. */ | |
d62a17ae | 1097 | static void route_match_community_free(void *rule) |
718e3744 | 1098 | { |
d62a17ae | 1099 | struct rmap_community *rcom = rule; |
718e3744 | 1100 | |
d62a17ae | 1101 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rcom->name); |
1102 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rcom); | |
718e3744 | 1103 | } |
1104 | ||
1105 | /* Route map commands for community matching. */ | |
d62a17ae | 1106 | struct route_map_rule_cmd route_match_community_cmd = { |
1107 | "community", route_match_community, route_match_community_compile, | |
1108 | route_match_community_free}; | |
6b0655a2 | 1109 | |
57d187bc | 1110 | /* Match function for lcommunity match. */ |
d62a17ae | 1111 | static route_map_result_t route_match_lcommunity(void *rule, |
123214ef | 1112 | const struct prefix *prefix, |
d62a17ae | 1113 | route_map_object_t type, |
1114 | void *object) | |
1115 | { | |
1116 | struct community_list *list; | |
9b6d8fcf | 1117 | struct bgp_path_info *path; |
d62a17ae | 1118 | struct rmap_community *rcom; |
1119 | ||
1120 | if (type == RMAP_BGP) { | |
9b6d8fcf | 1121 | path = object; |
d62a17ae | 1122 | rcom = rule; |
1123 | ||
1124 | list = community_list_lookup(bgp_clist, rcom->name, | |
1125 | LARGE_COMMUNITY_LIST_MASTER); | |
1126 | if (!list) | |
1127 | return RMAP_NOMATCH; | |
1128 | ||
9b6d8fcf | 1129 | if (lcommunity_list_match(path->attr->lcommunity, list)) |
d62a17ae | 1130 | return RMAP_MATCH; |
1131 | } | |
1132 | return RMAP_NOMATCH; | |
57d187bc JS |
1133 | } |
1134 | ||
1135 | /* Compile function for community match. */ | |
d62a17ae | 1136 | static void *route_match_lcommunity_compile(const char *arg) |
1137 | { | |
1138 | struct rmap_community *rcom; | |
1139 | int len; | |
1140 | char *p; | |
1141 | ||
1142 | rcom = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct rmap_community)); | |
1143 | ||
1144 | p = strchr(arg, ' '); | |
1145 | if (p) { | |
1146 | len = p - arg; | |
1147 | rcom->name = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, len + 1); | |
1148 | memcpy(rcom->name, arg, len); | |
1149 | } else { | |
1150 | rcom->name = XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); | |
1151 | rcom->exact = 0; | |
1152 | } | |
1153 | return rcom; | |
57d187bc JS |
1154 | } |
1155 | ||
1156 | /* Compile function for community match. */ | |
d62a17ae | 1157 | static void route_match_lcommunity_free(void *rule) |
57d187bc | 1158 | { |
d62a17ae | 1159 | struct rmap_community *rcom = rule; |
57d187bc | 1160 | |
d62a17ae | 1161 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rcom->name); |
1162 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rcom); | |
57d187bc JS |
1163 | } |
1164 | ||
1165 | /* Route map commands for community matching. */ | |
d62a17ae | 1166 | struct route_map_rule_cmd route_match_lcommunity_cmd = { |
1167 | "large-community", route_match_lcommunity, | |
1168 | route_match_lcommunity_compile, route_match_lcommunity_free}; | |
57d187bc JS |
1169 | |
1170 | ||
73ffb25b | 1171 | /* Match function for extcommunity match. */ |
d62a17ae | 1172 | static route_map_result_t route_match_ecommunity(void *rule, |
123214ef | 1173 | const struct prefix *prefix, |
d62a17ae | 1174 | route_map_object_t type, |
1175 | void *object) | |
73ffb25b | 1176 | { |
d62a17ae | 1177 | struct community_list *list; |
9b6d8fcf | 1178 | struct bgp_path_info *path; |
73ffb25b | 1179 | |
d62a17ae | 1180 | if (type == RMAP_BGP) { |
9b6d8fcf | 1181 | path = object; |
e52702f2 | 1182 | |
d62a17ae | 1183 | list = community_list_lookup(bgp_clist, (char *)rule, |
1184 | EXTCOMMUNITY_LIST_MASTER); | |
1185 | if (!list) | |
1186 | return RMAP_NOMATCH; | |
73ffb25b | 1187 | |
9b6d8fcf | 1188 | if (ecommunity_list_match(path->attr->ecommunity, list)) |
d62a17ae | 1189 | return RMAP_MATCH; |
1190 | } | |
1191 | return RMAP_NOMATCH; | |
73ffb25b | 1192 | } |
1193 | ||
1194 | /* Compile function for extcommunity match. */ | |
d62a17ae | 1195 | static void *route_match_ecommunity_compile(const char *arg) |
73ffb25b | 1196 | { |
d62a17ae | 1197 | return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); |
73ffb25b | 1198 | } |
1199 | ||
1200 | /* Compile function for extcommunity match. */ | |
d62a17ae | 1201 | static void route_match_ecommunity_free(void *rule) |
73ffb25b | 1202 | { |
d62a17ae | 1203 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
73ffb25b | 1204 | } |
1205 | ||
1206 | /* Route map commands for community matching. */ | |
d62a17ae | 1207 | struct route_map_rule_cmd route_match_ecommunity_cmd = { |
1208 | "extcommunity", route_match_ecommunity, route_match_ecommunity_compile, | |
1209 | route_match_ecommunity_free}; | |
6b0655a2 | 1210 | |
718e3744 | 1211 | /* `match nlri` and `set nlri` are replaced by `address-family ipv4` |
1212 | and `address-family vpnv4'. */ | |
6b0655a2 | 1213 | |
718e3744 | 1214 | /* `match origin' */ |
123214ef MS |
1215 | static route_map_result_t route_match_origin(void *rule, |
1216 | const struct prefix *prefix, | |
d62a17ae | 1217 | route_map_object_t type, |
1218 | void *object) | |
718e3744 | 1219 | { |
d7c0a89a | 1220 | uint8_t *origin; |
9b6d8fcf | 1221 | struct bgp_path_info *path; |
718e3744 | 1222 | |
d62a17ae | 1223 | if (type == RMAP_BGP) { |
1224 | origin = rule; | |
9b6d8fcf | 1225 | path = object; |
e52702f2 | 1226 | |
9b6d8fcf | 1227 | if (path->attr->origin == *origin) |
d62a17ae | 1228 | return RMAP_MATCH; |
1229 | } | |
718e3744 | 1230 | |
d62a17ae | 1231 | return RMAP_NOMATCH; |
718e3744 | 1232 | } |
1233 | ||
d62a17ae | 1234 | static void *route_match_origin_compile(const char *arg) |
718e3744 | 1235 | { |
d7c0a89a | 1236 | uint8_t *origin; |
718e3744 | 1237 | |
d7c0a89a | 1238 | origin = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(uint8_t)); |
718e3744 | 1239 | |
d62a17ae | 1240 | if (strcmp(arg, "igp") == 0) |
1241 | *origin = 0; | |
1242 | else if (strcmp(arg, "egp") == 0) | |
1243 | *origin = 1; | |
1244 | else | |
1245 | *origin = 2; | |
718e3744 | 1246 | |
d62a17ae | 1247 | return origin; |
718e3744 | 1248 | } |
1249 | ||
1250 | /* Free route map's compiled `ip address' value. */ | |
d62a17ae | 1251 | static void route_match_origin_free(void *rule) |
718e3744 | 1252 | { |
d62a17ae | 1253 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
718e3744 | 1254 | } |
1255 | ||
1256 | /* Route map commands for origin matching. */ | |
d62a17ae | 1257 | struct route_map_rule_cmd route_match_origin_cmd = { |
1258 | "origin", route_match_origin, route_match_origin_compile, | |
1259 | route_match_origin_free}; | |
1add115a VT |
1260 | |
1261 | /* match probability { */ | |
1262 | ||
d62a17ae | 1263 | static route_map_result_t route_match_probability(void *rule, |
123214ef | 1264 | const struct prefix *prefix, |
d62a17ae | 1265 | route_map_object_t type, |
1266 | void *object) | |
1267 | { | |
1268 | long r = random(); | |
1269 | ||
1270 | switch (*(long *)rule) { | |
1271 | case 0: | |
1272 | break; | |
1273 | case RAND_MAX: | |
1274 | return RMAP_MATCH; | |
1275 | default: | |
1276 | if (r < *(long *)rule) { | |
1277 | return RMAP_MATCH; | |
1278 | } | |
1279 | } | |
1add115a | 1280 | |
d62a17ae | 1281 | return RMAP_NOMATCH; |
1add115a VT |
1282 | } |
1283 | ||
d62a17ae | 1284 | static void *route_match_probability_compile(const char *arg) |
1add115a | 1285 | { |
d62a17ae | 1286 | long *lobule; |
1287 | unsigned perc; | |
1add115a | 1288 | |
d62a17ae | 1289 | perc = atoi(arg); |
1290 | lobule = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(long)); | |
1add115a | 1291 | |
d62a17ae | 1292 | switch (perc) { |
1293 | case 0: | |
1294 | *lobule = 0; | |
1295 | break; | |
1296 | case 100: | |
1297 | *lobule = RAND_MAX; | |
1298 | break; | |
1299 | default: | |
1300 | *lobule = RAND_MAX / 100 * perc; | |
1301 | } | |
1add115a | 1302 | |
d62a17ae | 1303 | return lobule; |
1add115a VT |
1304 | } |
1305 | ||
d62a17ae | 1306 | static void route_match_probability_free(void *rule) |
1add115a | 1307 | { |
d62a17ae | 1308 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
1add115a VT |
1309 | } |
1310 | ||
d62a17ae | 1311 | struct route_map_rule_cmd route_match_probability_cmd = { |
1312 | "probability", route_match_probability, route_match_probability_compile, | |
1313 | route_match_probability_free}; | |
1add115a | 1314 | |
bc413143 DS |
1315 | /* `match interface IFNAME' */ |
1316 | /* Match function should return 1 if match is success else return | |
1317 | zero. */ | |
d62a17ae | 1318 | static route_map_result_t route_match_interface(void *rule, |
123214ef | 1319 | const struct prefix *prefix, |
d62a17ae | 1320 | route_map_object_t type, |
1321 | void *object) | |
bc413143 | 1322 | { |
d62a17ae | 1323 | struct interface *ifp; |
40381db7 | 1324 | struct bgp_path_info *path; |
bc413143 | 1325 | |
d62a17ae | 1326 | if (type == RMAP_BGP) { |
40381db7 | 1327 | path = object; |
bc413143 | 1328 | |
40381db7 | 1329 | if (!path || !path->attr) |
d62a17ae | 1330 | return RMAP_NOMATCH; |
bc413143 | 1331 | |
d62a17ae | 1332 | ifp = if_lookup_by_name_all_vrf((char *)rule); |
bc413143 | 1333 | |
40381db7 | 1334 | if (ifp == NULL || ifp->ifindex != path->attr->nh_ifindex) |
d62a17ae | 1335 | return RMAP_NOMATCH; |
bc413143 | 1336 | |
d62a17ae | 1337 | return RMAP_MATCH; |
1338 | } | |
1339 | return RMAP_NOMATCH; | |
bc413143 DS |
1340 | } |
1341 | ||
1342 | /* Route map `interface' match statement. `arg' should be | |
1343 | interface name. */ | |
d62a17ae | 1344 | static void *route_match_interface_compile(const char *arg) |
bc413143 | 1345 | { |
d62a17ae | 1346 | return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); |
bc413143 DS |
1347 | } |
1348 | ||
1349 | /* Free route map's compiled `interface' value. */ | |
d62a17ae | 1350 | static void route_match_interface_free(void *rule) |
bc413143 | 1351 | { |
d62a17ae | 1352 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
bc413143 DS |
1353 | } |
1354 | ||
1355 | /* Route map commands for ip address matching. */ | |
d62a17ae | 1356 | struct route_map_rule_cmd route_match_interface_cmd = { |
1357 | "interface", route_match_interface, route_match_interface_compile, | |
1358 | route_match_interface_free}; | |
bc413143 | 1359 | |
1add115a VT |
1360 | /* } */ |
1361 | ||
718e3744 | 1362 | /* `set ip next-hop IP_ADDRESS' */ |
1363 | ||
0d9551dc | 1364 | /* Match function return 1 if match is success else return zero. */ |
123214ef MS |
1365 | static route_map_result_t route_match_tag(void *rule, |
1366 | const struct prefix *prefix, | |
d62a17ae | 1367 | route_map_object_t type, void *object) |
0d9551dc | 1368 | { |
d62a17ae | 1369 | route_tag_t *tag; |
9b6d8fcf | 1370 | struct bgp_path_info *path; |
0d9551dc | 1371 | |
d62a17ae | 1372 | if (type == RMAP_BGP) { |
1373 | tag = rule; | |
9b6d8fcf | 1374 | path = object; |
0d9551dc | 1375 | |
9b6d8fcf | 1376 | return ((path->attr->tag == *tag) ? RMAP_MATCH : RMAP_NOMATCH); |
d62a17ae | 1377 | } |
0d9551dc | 1378 | |
d62a17ae | 1379 | return RMAP_NOMATCH; |
0d9551dc DS |
1380 | } |
1381 | ||
1382 | ||
0d9551dc | 1383 | /* Route map commands for tag matching. */ |
d62a17ae | 1384 | static struct route_map_rule_cmd route_match_tag_cmd = { |
9d303b37 | 1385 | "tag", route_match_tag, route_map_rule_tag_compile, |
d62a17ae | 1386 | route_map_rule_tag_free, |
0d9551dc DS |
1387 | }; |
1388 | ||
1389 | ||
718e3744 | 1390 | /* Set nexthop to object. ojbect must be pointer to struct attr. */ |
d62a17ae | 1391 | struct rmap_ip_nexthop_set { |
1392 | struct in_addr *address; | |
1393 | int peer_address; | |
1394 | int unchanged; | |
ac41b2a2 | 1395 | }; |
1396 | ||
d62a17ae | 1397 | static route_map_result_t route_set_ip_nexthop(void *rule, |
123214ef | 1398 | const struct prefix *prefix, |
d62a17ae | 1399 | route_map_object_t type, |
1400 | void *object) | |
1401 | { | |
1402 | struct rmap_ip_nexthop_set *rins = rule; | |
9b6d8fcf | 1403 | struct bgp_path_info *path; |
d62a17ae | 1404 | struct peer *peer; |
1405 | ||
2b67b6f1 DS |
1406 | if (type != RMAP_BGP) |
1407 | return RMAP_OKAY; | |
1408 | ||
77f4dfb9 DS |
1409 | if (prefix->family == AF_INET6) |
1410 | return RMAP_OKAY; | |
1411 | ||
2b67b6f1 DS |
1412 | path = object; |
1413 | peer = path->peer; | |
1414 | ||
1415 | if (rins->unchanged) { | |
1416 | SET_FLAG(path->attr->rmap_change_flags, | |
1417 | BATTR_RMAP_NEXTHOP_UNCHANGED); | |
1418 | } else if (rins->peer_address) { | |
1419 | if ((CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_IN) | |
1420 | || CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_IMPORT)) | |
1421 | && peer->su_remote | |
1422 | && sockunion_family(peer->su_remote) == AF_INET) { | |
1423 | path->attr->nexthop.s_addr = | |
1424 | sockunion2ip(peer->su_remote); | |
9b6d8fcf | 1425 | path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP); |
2b67b6f1 DS |
1426 | } else if (CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_OUT)) { |
1427 | /* The next hop value will be set as part of | |
1428 | * packet rewrite. Set the flags here to indicate | |
1429 | * that rewrite needs to be done. | |
1430 | * Also, clear the value. | |
1431 | */ | |
9b6d8fcf | 1432 | SET_FLAG(path->attr->rmap_change_flags, |
2b67b6f1 DS |
1433 | BATTR_RMAP_NEXTHOP_PEER_ADDRESS); |
1434 | path->attr->nexthop.s_addr = 0; | |
d62a17ae | 1435 | } |
2b67b6f1 DS |
1436 | } else { |
1437 | /* Set next hop value. */ | |
1438 | path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP); | |
1439 | path->attr->nexthop = *rins->address; | |
1440 | SET_FLAG(path->attr->rmap_change_flags, | |
1441 | BATTR_RMAP_IPV4_NHOP_CHANGED); | |
1442 | /* case for MP-BGP : MPLS VPN */ | |
1443 | path->attr->mp_nexthop_global_in = *rins->address; | |
1444 | path->attr->mp_nexthop_len = sizeof(*rins->address); | |
ac41b2a2 | 1445 | } |
718e3744 | 1446 | |
d62a17ae | 1447 | return RMAP_OKAY; |
718e3744 | 1448 | } |
1449 | ||
1450 | /* Route map `ip nexthop' compile function. Given string is converted | |
1451 | to struct in_addr structure. */ | |
d62a17ae | 1452 | static void *route_set_ip_nexthop_compile(const char *arg) |
1453 | { | |
1454 | struct rmap_ip_nexthop_set *rins; | |
1455 | struct in_addr *address = NULL; | |
1456 | int peer_address = 0; | |
1457 | int unchanged = 0; | |
1458 | int ret; | |
1459 | ||
1460 | if (strcmp(arg, "peer-address") == 0) | |
1461 | peer_address = 1; | |
1462 | else if (strcmp(arg, "unchanged") == 0) | |
1463 | unchanged = 1; | |
1464 | else { | |
1465 | address = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, | |
1466 | sizeof(struct in_addr)); | |
1467 | ret = inet_aton(arg, address); | |
1468 | ||
1469 | if (ret == 0) { | |
1470 | XFREE(MTYPE_ROUTE_MAP_COMPILED, address); | |
1471 | return NULL; | |
1472 | } | |
ac41b2a2 | 1473 | } |
718e3744 | 1474 | |
d62a17ae | 1475 | rins = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, |
1476 | sizeof(struct rmap_ip_nexthop_set)); | |
ac41b2a2 | 1477 | |
d62a17ae | 1478 | rins->address = address; |
1479 | rins->peer_address = peer_address; | |
1480 | rins->unchanged = unchanged; | |
ac41b2a2 | 1481 | |
d62a17ae | 1482 | return rins; |
718e3744 | 1483 | } |
1484 | ||
1485 | /* Free route map's compiled `ip nexthop' value. */ | |
d62a17ae | 1486 | static void route_set_ip_nexthop_free(void *rule) |
718e3744 | 1487 | { |
d62a17ae | 1488 | struct rmap_ip_nexthop_set *rins = rule; |
ac41b2a2 | 1489 | |
d62a17ae | 1490 | if (rins->address) |
1491 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rins->address); | |
e52702f2 | 1492 | |
d62a17ae | 1493 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rins); |
718e3744 | 1494 | } |
1495 | ||
1496 | /* Route map commands for ip nexthop set. */ | |
d62a17ae | 1497 | struct route_map_rule_cmd route_set_ip_nexthop_cmd = { |
1498 | "ip next-hop", route_set_ip_nexthop, route_set_ip_nexthop_compile, | |
1499 | route_set_ip_nexthop_free}; | |
6b0655a2 | 1500 | |
718e3744 | 1501 | /* `set local-preference LOCAL_PREF' */ |
1502 | ||
1503 | /* Set local preference. */ | |
d62a17ae | 1504 | static route_map_result_t route_set_local_pref(void *rule, |
123214ef | 1505 | const struct prefix *prefix, |
d62a17ae | 1506 | route_map_object_t type, |
1507 | void *object) | |
1508 | { | |
1509 | struct rmap_value *rv; | |
9b6d8fcf | 1510 | struct bgp_path_info *path; |
d7c0a89a | 1511 | uint32_t locpref = 0; |
d62a17ae | 1512 | |
1513 | if (type == RMAP_BGP) { | |
1514 | /* Fetch routemap's rule information. */ | |
1515 | rv = rule; | |
9b6d8fcf | 1516 | path = object; |
d62a17ae | 1517 | |
1518 | /* Set local preference value. */ | |
9b6d8fcf DS |
1519 | if (path->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF)) |
1520 | locpref = path->attr->local_pref; | |
d62a17ae | 1521 | |
9b6d8fcf DS |
1522 | path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF); |
1523 | path->attr->local_pref = | |
1524 | route_value_adjust(rv, locpref, path->peer); | |
d62a17ae | 1525 | } |
718e3744 | 1526 | |
d62a17ae | 1527 | return RMAP_OKAY; |
718e3744 | 1528 | } |
1529 | ||
718e3744 | 1530 | /* Set local preference rule structure. */ |
d62a17ae | 1531 | struct route_map_rule_cmd route_set_local_pref_cmd = { |
9d303b37 | 1532 | "local-preference", route_set_local_pref, route_value_compile, |
d62a17ae | 1533 | route_value_free, |
718e3744 | 1534 | }; |
6b0655a2 | 1535 | |
718e3744 | 1536 | /* `set weight WEIGHT' */ |
1537 | ||
1538 | /* Set weight. */ | |
123214ef MS |
1539 | static route_map_result_t route_set_weight(void *rule, |
1540 | const struct prefix *prefix, | |
d62a17ae | 1541 | route_map_object_t type, |
1542 | void *object) | |
718e3744 | 1543 | { |
d62a17ae | 1544 | struct rmap_value *rv; |
9b6d8fcf | 1545 | struct bgp_path_info *path; |
718e3744 | 1546 | |
d62a17ae | 1547 | if (type == RMAP_BGP) { |
1548 | /* Fetch routemap's rule information. */ | |
1549 | rv = rule; | |
9b6d8fcf | 1550 | path = object; |
e52702f2 | 1551 | |
d62a17ae | 1552 | /* Set weight value. */ |
9b6d8fcf | 1553 | path->attr->weight = route_value_adjust(rv, 0, path->peer); |
d62a17ae | 1554 | } |
718e3744 | 1555 | |
d62a17ae | 1556 | return RMAP_OKAY; |
718e3744 | 1557 | } |
1558 | ||
718e3744 | 1559 | /* Set local preference rule structure. */ |
d62a17ae | 1560 | struct route_map_rule_cmd route_set_weight_cmd = { |
9d303b37 | 1561 | "weight", route_set_weight, route_value_compile, route_value_free, |
718e3744 | 1562 | }; |
6b0655a2 | 1563 | |
718e3744 | 1564 | /* `set metric METRIC' */ |
1565 | ||
1566 | /* Set metric to attribute. */ | |
123214ef MS |
1567 | static route_map_result_t route_set_metric(void *rule, |
1568 | const struct prefix *prefix, | |
d62a17ae | 1569 | route_map_object_t type, |
1570 | void *object) | |
1571 | { | |
1572 | struct rmap_value *rv; | |
9b6d8fcf | 1573 | struct bgp_path_info *path; |
d7c0a89a | 1574 | uint32_t med = 0; |
d62a17ae | 1575 | |
1576 | if (type == RMAP_BGP) { | |
1577 | /* Fetch routemap's rule information. */ | |
1578 | rv = rule; | |
9b6d8fcf | 1579 | path = object; |
d62a17ae | 1580 | |
9b6d8fcf DS |
1581 | if (path->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC)) |
1582 | med = path->attr->med; | |
d62a17ae | 1583 | |
9b6d8fcf DS |
1584 | path->attr->med = route_value_adjust(rv, med, path->peer); |
1585 | path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC); | |
d62a17ae | 1586 | } |
1587 | return RMAP_OKAY; | |
718e3744 | 1588 | } |
1589 | ||
718e3744 | 1590 | /* Set metric rule structure. */ |
d62a17ae | 1591 | struct route_map_rule_cmd route_set_metric_cmd = { |
9d303b37 | 1592 | "metric", route_set_metric, route_value_compile, route_value_free, |
718e3744 | 1593 | }; |
6b0655a2 | 1594 | |
718e3744 | 1595 | /* `set as-path prepend ASPATH' */ |
1596 | ||
1597 | /* For AS path prepend mechanism. */ | |
d62a17ae | 1598 | static route_map_result_t route_set_aspath_prepend(void *rule, |
123214ef | 1599 | const struct prefix *prefix, |
d62a17ae | 1600 | route_map_object_t type, |
1601 | void *object) | |
1602 | { | |
1603 | struct aspath *aspath; | |
1604 | struct aspath *new; | |
9b6d8fcf | 1605 | struct bgp_path_info *path; |
d62a17ae | 1606 | |
1607 | if (type == RMAP_BGP) { | |
9b6d8fcf | 1608 | path = object; |
d62a17ae | 1609 | |
9b6d8fcf DS |
1610 | if (path->attr->aspath->refcnt) |
1611 | new = aspath_dup(path->attr->aspath); | |
d62a17ae | 1612 | else |
9b6d8fcf | 1613 | new = path->attr->aspath; |
d62a17ae | 1614 | |
1615 | if ((uintptr_t)rule > 10) { | |
1616 | aspath = rule; | |
1617 | aspath_prepend(aspath, new); | |
1618 | } else { | |
1619 | as_t as = aspath_leftmost(new); | |
1620 | if (!as) | |
9b6d8fcf | 1621 | as = path->peer->as; |
d62a17ae | 1622 | new = aspath_add_seq_n(new, as, (uintptr_t)rule); |
1623 | } | |
bc3dd427 | 1624 | |
9b6d8fcf | 1625 | path->attr->aspath = new; |
d62a17ae | 1626 | } |
718e3744 | 1627 | |
d62a17ae | 1628 | return RMAP_OKAY; |
718e3744 | 1629 | } |
1630 | ||
d62a17ae | 1631 | static void *route_set_aspath_prepend_compile(const char *arg) |
bc3dd427 | 1632 | { |
d62a17ae | 1633 | unsigned int num; |
bc3dd427 | 1634 | |
d62a17ae | 1635 | if (sscanf(arg, "last-as %u", &num) == 1 && num > 0 && num <= 10) |
1636 | return (void *)(uintptr_t)num; | |
bc3dd427 | 1637 | |
d62a17ae | 1638 | return route_aspath_compile(arg); |
bc3dd427 DW |
1639 | } |
1640 | ||
d62a17ae | 1641 | static void route_set_aspath_prepend_free(void *rule) |
bc3dd427 | 1642 | { |
d62a17ae | 1643 | if ((uintptr_t)rule > 10) |
1644 | route_aspath_free(rule); | |
bc3dd427 DW |
1645 | } |
1646 | ||
1647 | ||
515e500c | 1648 | /* Set as-path prepend rule structure. */ |
d62a17ae | 1649 | struct route_map_rule_cmd route_set_aspath_prepend_cmd = { |
9d303b37 DL |
1650 | "as-path prepend", route_set_aspath_prepend, |
1651 | route_set_aspath_prepend_compile, route_set_aspath_prepend_free, | |
718e3744 | 1652 | }; |
6b0655a2 | 1653 | |
841f7a57 DO |
1654 | /* `set as-path exclude ASn' */ |
1655 | ||
1656 | /* For ASN exclude mechanism. | |
d62a17ae | 1657 | * Iterate over ASns requested and filter them from the given AS_PATH one by |
1658 | * one. | |
841f7a57 DO |
1659 | * Make a deep copy of existing AS_PATH, but for the first ASn only. |
1660 | */ | |
d62a17ae | 1661 | static route_map_result_t route_set_aspath_exclude(void *rule, |
123214ef | 1662 | const struct prefix *dummy, |
d62a17ae | 1663 | route_map_object_t type, |
1664 | void *object) | |
1665 | { | |
1666 | struct aspath *new_path, *exclude_path; | |
9b6d8fcf | 1667 | struct bgp_path_info *path; |
d62a17ae | 1668 | |
1669 | if (type == RMAP_BGP) { | |
1670 | exclude_path = rule; | |
9b6d8fcf DS |
1671 | path = object; |
1672 | if (path->attr->aspath->refcnt) | |
1673 | new_path = aspath_dup(path->attr->aspath); | |
d62a17ae | 1674 | else |
9b6d8fcf DS |
1675 | new_path = path->attr->aspath; |
1676 | path->attr->aspath = | |
d62a17ae | 1677 | aspath_filter_exclude(new_path, exclude_path); |
1678 | } | |
1679 | return RMAP_OKAY; | |
841f7a57 DO |
1680 | } |
1681 | ||
841f7a57 | 1682 | /* Set ASn exlude rule structure. */ |
d62a17ae | 1683 | struct route_map_rule_cmd route_set_aspath_exclude_cmd = { |
9d303b37 | 1684 | "as-path exclude", route_set_aspath_exclude, route_aspath_compile, |
d62a17ae | 1685 | route_aspath_free, |
841f7a57 | 1686 | }; |
6b0655a2 | 1687 | |
718e3744 | 1688 | /* `set community COMMUNITY' */ |
d62a17ae | 1689 | struct rmap_com_set { |
1690 | struct community *com; | |
1691 | int additive; | |
1692 | int none; | |
718e3744 | 1693 | }; |
1694 | ||
1695 | /* For community set mechanism. */ | |
123214ef MS |
1696 | static route_map_result_t route_set_community(void *rule, |
1697 | const struct prefix *prefix, | |
d62a17ae | 1698 | route_map_object_t type, |
1699 | void *object) | |
1700 | { | |
1701 | struct rmap_com_set *rcs; | |
9b6d8fcf | 1702 | struct bgp_path_info *path; |
d62a17ae | 1703 | struct attr *attr; |
1704 | struct community *new = NULL; | |
1705 | struct community *old; | |
1706 | struct community *merge; | |
1707 | ||
1708 | if (type == RMAP_BGP) { | |
1709 | rcs = rule; | |
9b6d8fcf DS |
1710 | path = object; |
1711 | attr = path->attr; | |
d62a17ae | 1712 | old = attr->community; |
1713 | ||
1714 | /* "none" case. */ | |
1715 | if (rcs->none) { | |
1716 | attr->flag &= ~(ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES)); | |
1717 | attr->community = NULL; | |
1718 | /* See the longer comment down below. */ | |
1719 | if (old && old->refcnt == 0) | |
3c1f53de | 1720 | community_free(&old); |
d62a17ae | 1721 | return RMAP_OKAY; |
1722 | } | |
718e3744 | 1723 | |
d62a17ae | 1724 | /* "additive" case. */ |
1725 | if (rcs->additive && old) { | |
1726 | merge = community_merge(community_dup(old), rcs->com); | |
1727 | ||
d62a17ae | 1728 | new = community_uniq_sort(merge); |
3c1f53de | 1729 | community_free(&merge); |
d62a17ae | 1730 | } else |
1731 | new = community_dup(rcs->com); | |
1732 | ||
f24804f4 NK |
1733 | /* HACK: if the old community is not intern'd, |
1734 | * we should free it here, or all reference to it may be | |
1735 | * lost. | |
1736 | * Really need to cleanup attribute caching sometime. | |
1737 | */ | |
1738 | if (old && old->refcnt == 0) | |
3c1f53de | 1739 | community_free(&old); |
f24804f4 | 1740 | |
d62a17ae | 1741 | /* will be interned by caller if required */ |
1742 | attr->community = new; | |
1743 | ||
1744 | attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES); | |
718e3744 | 1745 | } |
718e3744 | 1746 | |
d62a17ae | 1747 | return RMAP_OKAY; |
718e3744 | 1748 | } |
1749 | ||
1750 | /* Compile function for set community. */ | |
d62a17ae | 1751 | static void *route_set_community_compile(const char *arg) |
1752 | { | |
1753 | struct rmap_com_set *rcs; | |
1754 | struct community *com = NULL; | |
1755 | char *sp; | |
1756 | int additive = 0; | |
1757 | int none = 0; | |
1758 | ||
1759 | if (strcmp(arg, "none") == 0) | |
1760 | none = 1; | |
1761 | else { | |
1762 | sp = strstr(arg, "additive"); | |
1763 | ||
1764 | if (sp && sp > arg) { | |
770817b4 | 1765 | /* "additive" keyword is included. */ |
d62a17ae | 1766 | additive = 1; |
1767 | *(sp - 1) = '\0'; | |
1768 | } | |
718e3744 | 1769 | |
d62a17ae | 1770 | com = community_str2com(arg); |
718e3744 | 1771 | |
d62a17ae | 1772 | if (additive) |
1773 | *(sp - 1) = ' '; | |
718e3744 | 1774 | |
d62a17ae | 1775 | if (!com) |
1776 | return NULL; | |
1777 | } | |
e52702f2 | 1778 | |
d62a17ae | 1779 | rcs = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct rmap_com_set)); |
1780 | rcs->com = com; | |
1781 | rcs->additive = additive; | |
1782 | rcs->none = none; | |
e52702f2 | 1783 | |
d62a17ae | 1784 | return rcs; |
718e3744 | 1785 | } |
1786 | ||
1787 | /* Free function for set community. */ | |
d62a17ae | 1788 | static void route_set_community_free(void *rule) |
718e3744 | 1789 | { |
d62a17ae | 1790 | struct rmap_com_set *rcs = rule; |
718e3744 | 1791 | |
d62a17ae | 1792 | if (rcs->com) |
3c1f53de | 1793 | community_free(&rcs->com); |
d62a17ae | 1794 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rcs); |
718e3744 | 1795 | } |
1796 | ||
1797 | /* Set community rule structure. */ | |
d62a17ae | 1798 | struct route_map_rule_cmd route_set_community_cmd = { |
9d303b37 | 1799 | "community", route_set_community, route_set_community_compile, |
d62a17ae | 1800 | route_set_community_free, |
718e3744 | 1801 | }; |
6b0655a2 | 1802 | |
57d187bc | 1803 | /* `set community COMMUNITY' */ |
d62a17ae | 1804 | struct rmap_lcom_set { |
1805 | struct lcommunity *lcom; | |
1806 | int additive; | |
1807 | int none; | |
57d187bc JS |
1808 | }; |
1809 | ||
1810 | ||
1811 | /* For lcommunity set mechanism. */ | |
d62a17ae | 1812 | static route_map_result_t route_set_lcommunity(void *rule, |
123214ef | 1813 | const struct prefix *prefix, |
d62a17ae | 1814 | route_map_object_t type, |
1815 | void *object) | |
1816 | { | |
1817 | struct rmap_lcom_set *rcs; | |
9b6d8fcf | 1818 | struct bgp_path_info *path; |
d62a17ae | 1819 | struct attr *attr; |
1820 | struct lcommunity *new = NULL; | |
1821 | struct lcommunity *old; | |
1822 | struct lcommunity *merge; | |
1823 | ||
1824 | if (type == RMAP_BGP) { | |
1825 | rcs = rule; | |
9b6d8fcf DS |
1826 | path = object; |
1827 | attr = path->attr; | |
d62a17ae | 1828 | old = attr->lcommunity; |
1829 | ||
1830 | /* "none" case. */ | |
1831 | if (rcs->none) { | |
1832 | attr->flag &= | |
1833 | ~(ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES)); | |
1834 | attr->lcommunity = NULL; | |
1835 | ||
1836 | /* See the longer comment down below. */ | |
1837 | if (old && old->refcnt == 0) | |
1838 | lcommunity_free(&old); | |
1839 | return RMAP_OKAY; | |
1840 | } | |
57d187bc | 1841 | |
d62a17ae | 1842 | if (rcs->additive && old) { |
1843 | merge = lcommunity_merge(lcommunity_dup(old), | |
1844 | rcs->lcom); | |
1845 | ||
d62a17ae | 1846 | new = lcommunity_uniq_sort(merge); |
1847 | lcommunity_free(&merge); | |
1848 | } else | |
1849 | new = lcommunity_dup(rcs->lcom); | |
1850 | ||
4265a53e NK |
1851 | /* HACK: if the old large-community is not intern'd, |
1852 | * we should free it here, or all reference to it may be | |
1853 | * lost. | |
1854 | * Really need to cleanup attribute caching sometime. | |
1855 | */ | |
1856 | if (old && old->refcnt == 0) | |
1857 | lcommunity_free(&old); | |
1858 | ||
d62a17ae | 1859 | /* will be intern()'d or attr_flush()'d by bgp_update_main() */ |
1860 | attr->lcommunity = new; | |
1861 | ||
1862 | attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES); | |
1863 | } | |
57d187bc | 1864 | |
d62a17ae | 1865 | return RMAP_OKAY; |
1866 | } | |
57d187bc | 1867 | |
d62a17ae | 1868 | /* Compile function for set community. */ |
1869 | static void *route_set_lcommunity_compile(const char *arg) | |
1870 | { | |
1871 | struct rmap_lcom_set *rcs; | |
1872 | struct lcommunity *lcom = NULL; | |
1873 | char *sp; | |
1874 | int additive = 0; | |
1875 | int none = 0; | |
1876 | ||
1877 | if (strcmp(arg, "none") == 0) | |
1878 | none = 1; | |
1879 | else { | |
1880 | sp = strstr(arg, "additive"); | |
1881 | ||
1882 | if (sp && sp > arg) { | |
1883 | /* "additive" keyworkd is included. */ | |
1884 | additive = 1; | |
1885 | *(sp - 1) = '\0'; | |
1886 | } | |
57d187bc | 1887 | |
d62a17ae | 1888 | lcom = lcommunity_str2com(arg); |
57d187bc | 1889 | |
d62a17ae | 1890 | if (additive) |
1891 | *(sp - 1) = ' '; | |
57d187bc | 1892 | |
d62a17ae | 1893 | if (!lcom) |
1894 | return NULL; | |
1895 | } | |
57d187bc | 1896 | |
d62a17ae | 1897 | rcs = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct rmap_com_set)); |
1898 | rcs->lcom = lcom; | |
1899 | rcs->additive = additive; | |
1900 | rcs->none = none; | |
57d187bc | 1901 | |
d62a17ae | 1902 | return rcs; |
57d187bc JS |
1903 | } |
1904 | ||
1905 | /* Free function for set lcommunity. */ | |
d62a17ae | 1906 | static void route_set_lcommunity_free(void *rule) |
57d187bc | 1907 | { |
d62a17ae | 1908 | struct rmap_lcom_set *rcs = rule; |
57d187bc | 1909 | |
d62a17ae | 1910 | if (rcs->lcom) { |
1911 | lcommunity_free(&rcs->lcom); | |
1912 | } | |
1913 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rcs); | |
57d187bc JS |
1914 | } |
1915 | ||
1916 | /* Set community rule structure. */ | |
d62a17ae | 1917 | struct route_map_rule_cmd route_set_lcommunity_cmd = { |
9d303b37 | 1918 | "large-community", route_set_lcommunity, route_set_lcommunity_compile, |
d62a17ae | 1919 | route_set_lcommunity_free, |
57d187bc JS |
1920 | }; |
1921 | ||
1922 | /* `set large-comm-list (<1-99>|<100-500>|WORD) delete' */ | |
1923 | ||
1924 | /* For large community set mechanism. */ | |
d62a17ae | 1925 | static route_map_result_t route_set_lcommunity_delete(void *rule, |
123214ef | 1926 | const struct prefix *pfx, |
d62a17ae | 1927 | route_map_object_t type, |
1928 | void *object) | |
1929 | { | |
1930 | struct community_list *list; | |
1931 | struct lcommunity *merge; | |
1932 | struct lcommunity *new; | |
1933 | struct lcommunity *old; | |
9b6d8fcf | 1934 | struct bgp_path_info *path; |
d62a17ae | 1935 | |
1936 | if (type == RMAP_BGP) { | |
1937 | if (!rule) | |
1938 | return RMAP_OKAY; | |
1939 | ||
9b6d8fcf | 1940 | path = object; |
d62a17ae | 1941 | list = community_list_lookup(bgp_clist, rule, |
1942 | LARGE_COMMUNITY_LIST_MASTER); | |
9b6d8fcf | 1943 | old = path->attr->lcommunity; |
d62a17ae | 1944 | |
1945 | if (list && old) { | |
1946 | merge = lcommunity_list_match_delete( | |
1947 | lcommunity_dup(old), list); | |
1948 | new = lcommunity_uniq_sort(merge); | |
1949 | lcommunity_free(&merge); | |
1950 | ||
1951 | /* HACK: if the old community is not intern'd, | |
1952 | * we should free it here, or all reference to it may be | |
1953 | * lost. | |
1954 | * Really need to cleanup attribute caching sometime. | |
1955 | */ | |
1956 | if (old->refcnt == 0) | |
1957 | lcommunity_free(&old); | |
1958 | ||
1959 | if (new->size == 0) { | |
9b6d8fcf DS |
1960 | path->attr->lcommunity = NULL; |
1961 | path->attr->flag &= ~ATTR_FLAG_BIT( | |
d62a17ae | 1962 | BGP_ATTR_LARGE_COMMUNITIES); |
1963 | lcommunity_free(&new); | |
1964 | } else { | |
9b6d8fcf DS |
1965 | path->attr->lcommunity = new; |
1966 | path->attr->flag |= ATTR_FLAG_BIT( | |
d62a17ae | 1967 | BGP_ATTR_LARGE_COMMUNITIES); |
1968 | } | |
1969 | } | |
1970 | } | |
1971 | ||
1972 | return RMAP_OKAY; | |
57d187bc JS |
1973 | } |
1974 | ||
1975 | /* Compile function for set lcommunity. */ | |
d62a17ae | 1976 | static void *route_set_lcommunity_delete_compile(const char *arg) |
57d187bc | 1977 | { |
d62a17ae | 1978 | char *p; |
1979 | char *str; | |
1980 | int len; | |
57d187bc | 1981 | |
d62a17ae | 1982 | p = strchr(arg, ' '); |
1983 | if (p) { | |
1984 | len = p - arg; | |
1985 | str = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, len + 1); | |
1986 | memcpy(str, arg, len); | |
1987 | } else | |
1988 | str = NULL; | |
57d187bc | 1989 | |
d62a17ae | 1990 | return str; |
57d187bc JS |
1991 | } |
1992 | ||
1993 | /* Free function for set lcommunity. */ | |
d62a17ae | 1994 | static void route_set_lcommunity_delete_free(void *rule) |
57d187bc | 1995 | { |
d62a17ae | 1996 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
57d187bc JS |
1997 | } |
1998 | ||
1999 | /* Set lcommunity rule structure. */ | |
d62a17ae | 2000 | struct route_map_rule_cmd route_set_lcommunity_delete_cmd = { |
9d303b37 DL |
2001 | "large-comm-list", route_set_lcommunity_delete, |
2002 | route_set_lcommunity_delete_compile, route_set_lcommunity_delete_free, | |
57d187bc JS |
2003 | }; |
2004 | ||
2005 | ||
fee6e4e4 | 2006 | /* `set comm-list (<1-99>|<100-500>|WORD) delete' */ |
718e3744 | 2007 | |
2008 | /* For community set mechanism. */ | |
123214ef MS |
2009 | static route_map_result_t route_set_community_delete( |
2010 | void *rule, | |
2011 | const struct prefix *prefix, | |
2012 | route_map_object_t type, | |
2013 | void *object) | |
d62a17ae | 2014 | { |
2015 | struct community_list *list; | |
2016 | struct community *merge; | |
2017 | struct community *new; | |
2018 | struct community *old; | |
9b6d8fcf | 2019 | struct bgp_path_info *path; |
d62a17ae | 2020 | |
2021 | if (type == RMAP_BGP) { | |
2022 | if (!rule) | |
2023 | return RMAP_OKAY; | |
2024 | ||
9b6d8fcf | 2025 | path = object; |
d62a17ae | 2026 | list = community_list_lookup(bgp_clist, rule, |
2027 | COMMUNITY_LIST_MASTER); | |
9b6d8fcf | 2028 | old = path->attr->community; |
d62a17ae | 2029 | |
2030 | if (list && old) { | |
2031 | merge = community_list_match_delete(community_dup(old), | |
2032 | list); | |
2033 | new = community_uniq_sort(merge); | |
3c1f53de | 2034 | community_free(&merge); |
d62a17ae | 2035 | |
2036 | /* HACK: if the old community is not intern'd, | |
2037 | * we should free it here, or all reference to it may be | |
2038 | * lost. | |
2039 | * Really need to cleanup attribute caching sometime. | |
2040 | */ | |
2041 | if (old->refcnt == 0) | |
3c1f53de | 2042 | community_free(&old); |
d62a17ae | 2043 | |
2044 | if (new->size == 0) { | |
9b6d8fcf DS |
2045 | path->attr->community = NULL; |
2046 | path->attr->flag &= | |
d62a17ae | 2047 | ~ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES); |
3c1f53de | 2048 | community_free(&new); |
d62a17ae | 2049 | } else { |
9b6d8fcf DS |
2050 | path->attr->community = new; |
2051 | path->attr->flag |= | |
d62a17ae | 2052 | ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES); |
2053 | } | |
2054 | } | |
718e3744 | 2055 | } |
718e3744 | 2056 | |
d62a17ae | 2057 | return RMAP_OKAY; |
718e3744 | 2058 | } |
2059 | ||
2060 | /* Compile function for set community. */ | |
d62a17ae | 2061 | static void *route_set_community_delete_compile(const char *arg) |
718e3744 | 2062 | { |
d62a17ae | 2063 | char *p; |
2064 | char *str; | |
2065 | int len; | |
718e3744 | 2066 | |
d62a17ae | 2067 | p = strchr(arg, ' '); |
2068 | if (p) { | |
2069 | len = p - arg; | |
2070 | str = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, len + 1); | |
2071 | memcpy(str, arg, len); | |
2072 | } else | |
2073 | str = NULL; | |
718e3744 | 2074 | |
d62a17ae | 2075 | return str; |
718e3744 | 2076 | } |
2077 | ||
2078 | /* Free function for set community. */ | |
d62a17ae | 2079 | static void route_set_community_delete_free(void *rule) |
718e3744 | 2080 | { |
d62a17ae | 2081 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
718e3744 | 2082 | } |
2083 | ||
2084 | /* Set community rule structure. */ | |
d62a17ae | 2085 | struct route_map_rule_cmd route_set_community_delete_cmd = { |
9d303b37 DL |
2086 | "comm-list", route_set_community_delete, |
2087 | route_set_community_delete_compile, route_set_community_delete_free, | |
718e3744 | 2088 | }; |
6b0655a2 | 2089 | |
718e3744 | 2090 | /* `set extcommunity rt COMMUNITY' */ |
2091 | ||
73d78ea0 | 2092 | /* For community set mechanism. Used by _rt and _soo. */ |
d62a17ae | 2093 | static route_map_result_t route_set_ecommunity(void *rule, |
123214ef | 2094 | const struct prefix *prefix, |
d62a17ae | 2095 | route_map_object_t type, |
2096 | void *object) | |
2097 | { | |
2098 | struct ecommunity *ecom; | |
2099 | struct ecommunity *new_ecom; | |
2100 | struct ecommunity *old_ecom; | |
9b6d8fcf | 2101 | struct bgp_path_info *path; |
d62a17ae | 2102 | |
2103 | if (type == RMAP_BGP) { | |
2104 | ecom = rule; | |
9b6d8fcf | 2105 | path = object; |
d62a17ae | 2106 | |
2107 | if (!ecom) | |
2108 | return RMAP_OKAY; | |
2109 | ||
2110 | /* We assume additive for Extended Community. */ | |
9b6d8fcf | 2111 | old_ecom = path->attr->ecommunity; |
d62a17ae | 2112 | |
2113 | if (old_ecom) { | |
2114 | new_ecom = ecommunity_merge(ecommunity_dup(old_ecom), | |
2115 | ecom); | |
2116 | ||
2117 | /* old_ecom->refcnt = 1 => owned elsewhere, e.g. | |
2118 | * bgp_update_receive() | |
2119 | * ->refcnt = 0 => set by a previous route-map | |
2120 | * statement */ | |
2121 | if (!old_ecom->refcnt) | |
2122 | ecommunity_free(&old_ecom); | |
2123 | } else | |
2124 | new_ecom = ecommunity_dup(ecom); | |
2125 | ||
2126 | /* will be intern()'d or attr_flush()'d by bgp_update_main() */ | |
9b6d8fcf | 2127 | path->attr->ecommunity = new_ecom; |
d62a17ae | 2128 | |
9b6d8fcf | 2129 | path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES); |
27bf90a1 | 2130 | } |
d62a17ae | 2131 | return RMAP_OKAY; |
718e3744 | 2132 | } |
2133 | ||
2134 | /* Compile function for set community. */ | |
d62a17ae | 2135 | static void *route_set_ecommunity_rt_compile(const char *arg) |
718e3744 | 2136 | { |
d62a17ae | 2137 | struct ecommunity *ecom; |
718e3744 | 2138 | |
d62a17ae | 2139 | ecom = ecommunity_str2com(arg, ECOMMUNITY_ROUTE_TARGET, 0); |
2140 | if (!ecom) | |
2141 | return NULL; | |
2142 | return ecommunity_intern(ecom); | |
718e3744 | 2143 | } |
2144 | ||
73d78ea0 | 2145 | /* Free function for set community. Used by _rt and _soo */ |
d62a17ae | 2146 | static void route_set_ecommunity_free(void *rule) |
718e3744 | 2147 | { |
d62a17ae | 2148 | struct ecommunity *ecom = rule; |
2149 | ecommunity_unintern(&ecom); | |
718e3744 | 2150 | } |
2151 | ||
2152 | /* Set community rule structure. */ | |
d62a17ae | 2153 | struct route_map_rule_cmd route_set_ecommunity_rt_cmd = { |
9d303b37 DL |
2154 | "extcommunity rt", route_set_ecommunity, |
2155 | route_set_ecommunity_rt_compile, route_set_ecommunity_free, | |
718e3744 | 2156 | }; |
2157 | ||
2158 | /* `set extcommunity soo COMMUNITY' */ | |
2159 | ||
718e3744 | 2160 | /* Compile function for set community. */ |
d62a17ae | 2161 | static void *route_set_ecommunity_soo_compile(const char *arg) |
718e3744 | 2162 | { |
d62a17ae | 2163 | struct ecommunity *ecom; |
718e3744 | 2164 | |
d62a17ae | 2165 | ecom = ecommunity_str2com(arg, ECOMMUNITY_SITE_ORIGIN, 0); |
2166 | if (!ecom) | |
2167 | return NULL; | |
e52702f2 | 2168 | |
d62a17ae | 2169 | return ecommunity_intern(ecom); |
718e3744 | 2170 | } |
2171 | ||
718e3744 | 2172 | /* Set community rule structure. */ |
d62a17ae | 2173 | struct route_map_rule_cmd route_set_ecommunity_soo_cmd = { |
9d303b37 DL |
2174 | "extcommunity soo", route_set_ecommunity, |
2175 | route_set_ecommunity_soo_compile, route_set_ecommunity_free, | |
718e3744 | 2176 | }; |
6b0655a2 | 2177 | |
718e3744 | 2178 | /* `set origin ORIGIN' */ |
2179 | ||
2180 | /* For origin set. */ | |
123214ef MS |
2181 | static route_map_result_t route_set_origin(void *rule, |
2182 | const struct prefix *prefix, | |
d62a17ae | 2183 | route_map_object_t type, |
2184 | void *object) | |
718e3744 | 2185 | { |
d7c0a89a | 2186 | uint8_t *origin; |
9b6d8fcf | 2187 | struct bgp_path_info *path; |
718e3744 | 2188 | |
d62a17ae | 2189 | if (type == RMAP_BGP) { |
2190 | origin = rule; | |
9b6d8fcf | 2191 | path = object; |
e52702f2 | 2192 | |
9b6d8fcf | 2193 | path->attr->origin = *origin; |
d62a17ae | 2194 | } |
718e3744 | 2195 | |
d62a17ae | 2196 | return RMAP_OKAY; |
718e3744 | 2197 | } |
2198 | ||
2199 | /* Compile function for origin set. */ | |
d62a17ae | 2200 | static void *route_set_origin_compile(const char *arg) |
718e3744 | 2201 | { |
d7c0a89a | 2202 | uint8_t *origin; |
718e3744 | 2203 | |
d7c0a89a | 2204 | origin = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(uint8_t)); |
718e3744 | 2205 | |
d62a17ae | 2206 | if (strcmp(arg, "igp") == 0) |
2207 | *origin = 0; | |
2208 | else if (strcmp(arg, "egp") == 0) | |
2209 | *origin = 1; | |
2210 | else | |
2211 | *origin = 2; | |
718e3744 | 2212 | |
d62a17ae | 2213 | return origin; |
718e3744 | 2214 | } |
2215 | ||
2216 | /* Compile function for origin set. */ | |
d62a17ae | 2217 | static void route_set_origin_free(void *rule) |
718e3744 | 2218 | { |
d62a17ae | 2219 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
718e3744 | 2220 | } |
2221 | ||
515e500c | 2222 | /* Set origin rule structure. */ |
d62a17ae | 2223 | struct route_map_rule_cmd route_set_origin_cmd = { |
9d303b37 | 2224 | "origin", route_set_origin, route_set_origin_compile, |
d62a17ae | 2225 | route_set_origin_free, |
718e3744 | 2226 | }; |
6b0655a2 | 2227 | |
718e3744 | 2228 | /* `set atomic-aggregate' */ |
2229 | ||
2230 | /* For atomic aggregate set. */ | |
d62a17ae | 2231 | static route_map_result_t route_set_atomic_aggregate(void *rule, |
123214ef | 2232 | const struct prefix *pfx, |
d62a17ae | 2233 | route_map_object_t type, |
2234 | void *object) | |
718e3744 | 2235 | { |
9b6d8fcf | 2236 | struct bgp_path_info *path; |
718e3744 | 2237 | |
d62a17ae | 2238 | if (type == RMAP_BGP) { |
9b6d8fcf DS |
2239 | path = object; |
2240 | path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE); | |
d62a17ae | 2241 | } |
718e3744 | 2242 | |
d62a17ae | 2243 | return RMAP_OKAY; |
718e3744 | 2244 | } |
2245 | ||
2246 | /* Compile function for atomic aggregate. */ | |
d62a17ae | 2247 | static void *route_set_atomic_aggregate_compile(const char *arg) |
718e3744 | 2248 | { |
d62a17ae | 2249 | return (void *)1; |
718e3744 | 2250 | } |
2251 | ||
2252 | /* Compile function for atomic aggregate. */ | |
d62a17ae | 2253 | static void route_set_atomic_aggregate_free(void *rule) |
718e3744 | 2254 | { |
d62a17ae | 2255 | return; |
718e3744 | 2256 | } |
2257 | ||
2258 | /* Set atomic aggregate rule structure. */ | |
d62a17ae | 2259 | struct route_map_rule_cmd route_set_atomic_aggregate_cmd = { |
9d303b37 DL |
2260 | "atomic-aggregate", route_set_atomic_aggregate, |
2261 | route_set_atomic_aggregate_compile, route_set_atomic_aggregate_free, | |
718e3744 | 2262 | }; |
6b0655a2 | 2263 | |
718e3744 | 2264 | /* `set aggregator as AS A.B.C.D' */ |
d62a17ae | 2265 | struct aggregator { |
2266 | as_t as; | |
2267 | struct in_addr address; | |
718e3744 | 2268 | }; |
2269 | ||
d62a17ae | 2270 | static route_map_result_t route_set_aggregator_as(void *rule, |
123214ef | 2271 | const struct prefix *prefix, |
d62a17ae | 2272 | route_map_object_t type, |
2273 | void *object) | |
718e3744 | 2274 | { |
9b6d8fcf | 2275 | struct bgp_path_info *path; |
d62a17ae | 2276 | struct aggregator *aggregator; |
718e3744 | 2277 | |
d62a17ae | 2278 | if (type == RMAP_BGP) { |
9b6d8fcf | 2279 | path = object; |
d62a17ae | 2280 | aggregator = rule; |
e52702f2 | 2281 | |
9b6d8fcf DS |
2282 | path->attr->aggregator_as = aggregator->as; |
2283 | path->attr->aggregator_addr = aggregator->address; | |
2284 | path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR); | |
d62a17ae | 2285 | } |
718e3744 | 2286 | |
d62a17ae | 2287 | return RMAP_OKAY; |
718e3744 | 2288 | } |
2289 | ||
d62a17ae | 2290 | static void *route_set_aggregator_as_compile(const char *arg) |
718e3744 | 2291 | { |
d62a17ae | 2292 | struct aggregator *aggregator; |
2293 | char as[10]; | |
2294 | char address[20]; | |
2295 | int ret; | |
718e3744 | 2296 | |
d62a17ae | 2297 | aggregator = |
2298 | XCALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct aggregator)); | |
116e176d DS |
2299 | if (sscanf(arg, "%s %s", as, address) != 2) { |
2300 | XFREE(MTYPE_ROUTE_MAP_COMPILED, aggregator); | |
2301 | return NULL; | |
2302 | } | |
718e3744 | 2303 | |
d62a17ae | 2304 | aggregator->as = strtoul(as, NULL, 10); |
2305 | ret = inet_aton(address, &aggregator->address); | |
2306 | if (ret == 0) { | |
2307 | XFREE(MTYPE_ROUTE_MAP_COMPILED, aggregator); | |
2308 | return NULL; | |
2309 | } | |
2310 | return aggregator; | |
718e3744 | 2311 | } |
2312 | ||
d62a17ae | 2313 | static void route_set_aggregator_as_free(void *rule) |
718e3744 | 2314 | { |
d62a17ae | 2315 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
718e3744 | 2316 | } |
2317 | ||
d62a17ae | 2318 | struct route_map_rule_cmd route_set_aggregator_as_cmd = { |
9d303b37 DL |
2319 | "aggregator as", route_set_aggregator_as, |
2320 | route_set_aggregator_as_compile, route_set_aggregator_as_free, | |
718e3744 | 2321 | }; |
6b0655a2 | 2322 | |
4b7e6066 | 2323 | /* Set tag to object. object must be pointer to struct bgp_path_info */ |
123214ef MS |
2324 | static route_map_result_t route_set_tag(void *rule, |
2325 | const struct prefix *prefix, | |
d62a17ae | 2326 | route_map_object_t type, void *object) |
0d9551dc | 2327 | { |
d62a17ae | 2328 | route_tag_t *tag; |
9b6d8fcf | 2329 | struct bgp_path_info *path; |
0d9551dc | 2330 | |
d62a17ae | 2331 | if (type == RMAP_BGP) { |
2332 | tag = rule; | |
9b6d8fcf | 2333 | path = object; |
0d9551dc | 2334 | |
d62a17ae | 2335 | /* Set tag value */ |
9b6d8fcf | 2336 | path->attr->tag = *tag; |
d62a17ae | 2337 | } |
0d9551dc | 2338 | |
d62a17ae | 2339 | return RMAP_OKAY; |
0d9551dc DS |
2340 | } |
2341 | ||
0d9551dc | 2342 | /* Route map commands for tag set. */ |
d62a17ae | 2343 | static struct route_map_rule_cmd route_set_tag_cmd = { |
9d303b37 | 2344 | "tag", route_set_tag, route_map_rule_tag_compile, |
d62a17ae | 2345 | route_map_rule_tag_free, |
0d9551dc DS |
2346 | }; |
2347 | ||
4b7e6066 | 2348 | /* Set label-index to object. object must be pointer to struct bgp_path_info */ |
d62a17ae | 2349 | static route_map_result_t route_set_label_index(void *rule, |
123214ef | 2350 | const struct prefix *prefix, |
d62a17ae | 2351 | route_map_object_t type, |
2352 | void *object) | |
2353 | { | |
2354 | struct rmap_value *rv; | |
9b6d8fcf | 2355 | struct bgp_path_info *path; |
d7c0a89a | 2356 | uint32_t label_index; |
d62a17ae | 2357 | |
2358 | if (type == RMAP_BGP) { | |
2359 | /* Fetch routemap's rule information. */ | |
2360 | rv = rule; | |
9b6d8fcf | 2361 | path = object; |
d62a17ae | 2362 | |
2363 | /* Set label-index value. */ | |
2364 | label_index = rv->value; | |
2365 | if (label_index) { | |
9b6d8fcf DS |
2366 | path->attr->label_index = label_index; |
2367 | path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID); | |
d62a17ae | 2368 | } |
2369 | } | |
d990e384 | 2370 | |
d62a17ae | 2371 | return RMAP_OKAY; |
d990e384 DS |
2372 | } |
2373 | ||
2374 | /* Route map commands for label-index set. */ | |
d62a17ae | 2375 | static struct route_map_rule_cmd route_set_label_index_cmd = { |
9d303b37 | 2376 | "label-index", route_set_label_index, route_value_compile, |
d62a17ae | 2377 | route_value_free, |
d990e384 | 2378 | }; |
0d9551dc | 2379 | |
718e3744 | 2380 | /* `match ipv6 address IP_ACCESS_LIST' */ |
2381 | ||
d62a17ae | 2382 | static route_map_result_t route_match_ipv6_address(void *rule, |
123214ef | 2383 | const struct prefix *prefix, |
d62a17ae | 2384 | route_map_object_t type, |
2385 | void *object) | |
718e3744 | 2386 | { |
d62a17ae | 2387 | struct access_list *alist; |
718e3744 | 2388 | |
09cd98eb | 2389 | if (type == RMAP_BGP && prefix->family == AF_INET6) { |
d62a17ae | 2390 | alist = access_list_lookup(AFI_IP6, (char *)rule); |
2391 | if (alist == NULL) | |
2392 | return RMAP_NOMATCH; | |
e52702f2 | 2393 | |
d62a17ae | 2394 | return (access_list_apply(alist, prefix) == FILTER_DENY |
2395 | ? RMAP_NOMATCH | |
2396 | : RMAP_MATCH); | |
2397 | } | |
2398 | return RMAP_NOMATCH; | |
718e3744 | 2399 | } |
2400 | ||
d62a17ae | 2401 | static void *route_match_ipv6_address_compile(const char *arg) |
718e3744 | 2402 | { |
d62a17ae | 2403 | return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); |
718e3744 | 2404 | } |
2405 | ||
d62a17ae | 2406 | static void route_match_ipv6_address_free(void *rule) |
718e3744 | 2407 | { |
d62a17ae | 2408 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
718e3744 | 2409 | } |
2410 | ||
2411 | /* Route map commands for ip address matching. */ | |
d62a17ae | 2412 | struct route_map_rule_cmd route_match_ipv6_address_cmd = { |
2413 | "ipv6 address", route_match_ipv6_address, | |
2414 | route_match_ipv6_address_compile, route_match_ipv6_address_free}; | |
6b0655a2 | 2415 | |
718e3744 | 2416 | /* `match ipv6 next-hop IP_ADDRESS' */ |
2417 | ||
d62a17ae | 2418 | static route_map_result_t route_match_ipv6_next_hop(void *rule, |
123214ef | 2419 | const struct prefix *prefix, |
d62a17ae | 2420 | route_map_object_t type, |
2421 | void *object) | |
718e3744 | 2422 | { |
d62a17ae | 2423 | struct in6_addr *addr = rule; |
9b6d8fcf | 2424 | struct bgp_path_info *path; |
718e3744 | 2425 | |
d62a17ae | 2426 | if (type == RMAP_BGP) { |
9b6d8fcf | 2427 | path = object; |
e52702f2 | 2428 | |
9b6d8fcf | 2429 | if (IPV6_ADDR_SAME(&path->attr->mp_nexthop_global, addr)) |
d62a17ae | 2430 | return RMAP_MATCH; |
718e3744 | 2431 | |
9b6d8fcf | 2432 | if (path->attr->mp_nexthop_len |
d62a17ae | 2433 | == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL |
9b6d8fcf | 2434 | && IPV6_ADDR_SAME(&path->attr->mp_nexthop_local, rule)) |
d62a17ae | 2435 | return RMAP_MATCH; |
718e3744 | 2436 | |
d62a17ae | 2437 | return RMAP_NOMATCH; |
2438 | } | |
718e3744 | 2439 | |
d62a17ae | 2440 | return RMAP_NOMATCH; |
718e3744 | 2441 | } |
2442 | ||
d62a17ae | 2443 | static void *route_match_ipv6_next_hop_compile(const char *arg) |
718e3744 | 2444 | { |
d62a17ae | 2445 | struct in6_addr *address; |
2446 | int ret; | |
718e3744 | 2447 | |
d62a17ae | 2448 | address = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct in6_addr)); |
718e3744 | 2449 | |
d62a17ae | 2450 | ret = inet_pton(AF_INET6, arg, address); |
2451 | if (!ret) { | |
2452 | XFREE(MTYPE_ROUTE_MAP_COMPILED, address); | |
2453 | return NULL; | |
2454 | } | |
718e3744 | 2455 | |
d62a17ae | 2456 | return address; |
718e3744 | 2457 | } |
2458 | ||
d62a17ae | 2459 | static void route_match_ipv6_next_hop_free(void *rule) |
718e3744 | 2460 | { |
d62a17ae | 2461 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
718e3744 | 2462 | } |
2463 | ||
d62a17ae | 2464 | struct route_map_rule_cmd route_match_ipv6_next_hop_cmd = { |
2465 | "ipv6 next-hop", route_match_ipv6_next_hop, | |
2466 | route_match_ipv6_next_hop_compile, route_match_ipv6_next_hop_free}; | |
6b0655a2 | 2467 | |
718e3744 | 2468 | /* `match ipv6 address prefix-list PREFIX_LIST' */ |
2469 | ||
94f2b392 | 2470 | static route_map_result_t |
123214ef | 2471 | route_match_ipv6_address_prefix_list(void *rule, const struct prefix *prefix, |
d62a17ae | 2472 | route_map_object_t type, void *object) |
718e3744 | 2473 | { |
d62a17ae | 2474 | struct prefix_list *plist; |
718e3744 | 2475 | |
09cd98eb | 2476 | if (type == RMAP_BGP && prefix->family == AF_INET6) { |
d62a17ae | 2477 | plist = prefix_list_lookup(AFI_IP6, (char *)rule); |
2478 | if (plist == NULL) | |
2479 | return RMAP_NOMATCH; | |
e52702f2 | 2480 | |
d62a17ae | 2481 | return (prefix_list_apply(plist, prefix) == PREFIX_DENY |
2482 | ? RMAP_NOMATCH | |
2483 | : RMAP_MATCH); | |
2484 | } | |
2485 | return RMAP_NOMATCH; | |
718e3744 | 2486 | } |
2487 | ||
d62a17ae | 2488 | static void *route_match_ipv6_address_prefix_list_compile(const char *arg) |
718e3744 | 2489 | { |
d62a17ae | 2490 | return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); |
718e3744 | 2491 | } |
2492 | ||
d62a17ae | 2493 | static void route_match_ipv6_address_prefix_list_free(void *rule) |
718e3744 | 2494 | { |
d62a17ae | 2495 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
718e3744 | 2496 | } |
2497 | ||
d62a17ae | 2498 | struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd = { |
2499 | "ipv6 address prefix-list", route_match_ipv6_address_prefix_list, | |
2500 | route_match_ipv6_address_prefix_list_compile, | |
2501 | route_match_ipv6_address_prefix_list_free}; | |
6b0655a2 | 2502 | |
61ad901e DA |
2503 | /* `match ipv6 next-hop type <TYPE>' */ |
2504 | ||
2505 | static route_map_result_t | |
2506 | route_match_ipv6_next_hop_type(void *rule, const struct prefix *prefix, | |
2507 | route_map_object_t type, void *object) | |
2508 | { | |
9b6d8fcf | 2509 | struct bgp_path_info *path; |
61ad901e DA |
2510 | struct in6_addr *addr = rule; |
2511 | ||
2512 | if (type == RMAP_BGP && prefix->family == AF_INET6) { | |
9b6d8fcf DS |
2513 | path = (struct bgp_path_info *)object; |
2514 | if (!path || !path->attr) | |
61ad901e DA |
2515 | return RMAP_DENYMATCH; |
2516 | ||
9b6d8fcf DS |
2517 | if (IPV6_ADDR_SAME(&path->attr->mp_nexthop_global, addr) |
2518 | && !path->attr->nh_ifindex) | |
61ad901e DA |
2519 | return RMAP_MATCH; |
2520 | } | |
2521 | return RMAP_NOMATCH; | |
2522 | } | |
2523 | ||
2524 | static void *route_match_ipv6_next_hop_type_compile(const char *arg) | |
2525 | { | |
2526 | struct in6_addr *address; | |
2527 | int ret; | |
2528 | ||
2529 | address = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct in6_addr)); | |
2530 | ||
2531 | ret = inet_pton(AF_INET6, "::0", address); | |
2532 | if (!ret) { | |
2533 | XFREE(MTYPE_ROUTE_MAP_COMPILED, address); | |
2534 | return NULL; | |
2535 | } | |
2536 | ||
2537 | return address; | |
2538 | } | |
2539 | ||
2540 | static void route_match_ipv6_next_hop_type_free(void *rule) | |
2541 | { | |
2542 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); | |
2543 | } | |
2544 | ||
2545 | struct route_map_rule_cmd route_match_ipv6_next_hop_type_cmd = { | |
2546 | "ipv6 next-hop type", route_match_ipv6_next_hop_type, | |
2547 | route_match_ipv6_next_hop_type_compile, | |
2548 | route_match_ipv6_next_hop_type_free}; | |
2549 | ||
718e3744 | 2550 | /* `set ipv6 nexthop global IP_ADDRESS' */ |
2551 | ||
2552 | /* Set nexthop to object. ojbect must be pointer to struct attr. */ | |
d62a17ae | 2553 | static route_map_result_t route_set_ipv6_nexthop_global(void *rule, |
123214ef | 2554 | const struct prefix *p, |
d62a17ae | 2555 | route_map_object_t type, |
2556 | void *object) | |
718e3744 | 2557 | { |
d62a17ae | 2558 | struct in6_addr *address; |
9b6d8fcf | 2559 | struct bgp_path_info *path; |
718e3744 | 2560 | |
d62a17ae | 2561 | if (type == RMAP_BGP) { |
2562 | /* Fetch routemap's rule information. */ | |
2563 | address = rule; | |
9b6d8fcf | 2564 | path = object; |
e52702f2 | 2565 | |
d62a17ae | 2566 | /* Set next hop value. */ |
9b6d8fcf | 2567 | path->attr->mp_nexthop_global = *address; |
3f9c7369 | 2568 | |
d62a17ae | 2569 | /* Set nexthop length. */ |
9b6d8fcf DS |
2570 | if (path->attr->mp_nexthop_len == 0) |
2571 | path->attr->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL; | |
3f9c7369 | 2572 | |
9b6d8fcf | 2573 | SET_FLAG(path->attr->rmap_change_flags, |
d62a17ae | 2574 | BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED); |
2575 | } | |
718e3744 | 2576 | |
d62a17ae | 2577 | return RMAP_OKAY; |
718e3744 | 2578 | } |
2579 | ||
2580 | /* Route map `ip next-hop' compile function. Given string is converted | |
2581 | to struct in_addr structure. */ | |
d62a17ae | 2582 | static void *route_set_ipv6_nexthop_global_compile(const char *arg) |
718e3744 | 2583 | { |
d62a17ae | 2584 | int ret; |
2585 | struct in6_addr *address; | |
718e3744 | 2586 | |
d62a17ae | 2587 | address = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct in6_addr)); |
718e3744 | 2588 | |
d62a17ae | 2589 | ret = inet_pton(AF_INET6, arg, address); |
718e3744 | 2590 | |
d62a17ae | 2591 | if (ret == 0) { |
2592 | XFREE(MTYPE_ROUTE_MAP_COMPILED, address); | |
2593 | return NULL; | |
2594 | } | |
718e3744 | 2595 | |
d62a17ae | 2596 | return address; |
718e3744 | 2597 | } |
2598 | ||
2599 | /* Free route map's compiled `ip next-hop' value. */ | |
d62a17ae | 2600 | static void route_set_ipv6_nexthop_global_free(void *rule) |
718e3744 | 2601 | { |
d62a17ae | 2602 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
718e3744 | 2603 | } |
2604 | ||
2605 | /* Route map commands for ip nexthop set. */ | |
d62a17ae | 2606 | struct route_map_rule_cmd route_set_ipv6_nexthop_global_cmd = { |
2607 | "ipv6 next-hop global", route_set_ipv6_nexthop_global, | |
2608 | route_set_ipv6_nexthop_global_compile, | |
2609 | route_set_ipv6_nexthop_global_free}; | |
6b0655a2 | 2610 | |
161995ea DS |
2611 | /* Set next-hop preference value. */ |
2612 | static route_map_result_t | |
123214ef | 2613 | route_set_ipv6_nexthop_prefer_global(void *rule, const struct prefix *prefix, |
d62a17ae | 2614 | route_map_object_t type, void *object) |
2615 | { | |
9b6d8fcf | 2616 | struct bgp_path_info *path; |
d62a17ae | 2617 | struct peer *peer; |
2618 | ||
2619 | if (type == RMAP_BGP) { | |
2620 | /* Fetch routemap's rule information. */ | |
9b6d8fcf DS |
2621 | path = object; |
2622 | peer = path->peer; | |
d62a17ae | 2623 | |
2624 | if ((CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_IN) | |
2625 | || CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_IMPORT)) | |
2626 | && peer->su_remote | |
2627 | && sockunion_family(peer->su_remote) == AF_INET6) { | |
2628 | /* Set next hop preference to global */ | |
9b6d8fcf DS |
2629 | path->attr->mp_nexthop_prefer_global = TRUE; |
2630 | SET_FLAG(path->attr->rmap_change_flags, | |
d62a17ae | 2631 | BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED); |
2632 | } else { | |
9b6d8fcf DS |
2633 | path->attr->mp_nexthop_prefer_global = FALSE; |
2634 | SET_FLAG(path->attr->rmap_change_flags, | |
d62a17ae | 2635 | BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED); |
2636 | } | |
161995ea | 2637 | } |
d62a17ae | 2638 | return RMAP_OKAY; |
161995ea DS |
2639 | } |
2640 | ||
d62a17ae | 2641 | static void *route_set_ipv6_nexthop_prefer_global_compile(const char *arg) |
161995ea | 2642 | { |
d62a17ae | 2643 | int *rins = NULL; |
161995ea | 2644 | |
d62a17ae | 2645 | rins = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(int)); |
2646 | *rins = 1; | |
161995ea | 2647 | |
d62a17ae | 2648 | return rins; |
161995ea DS |
2649 | } |
2650 | ||
2651 | /* Free route map's compiled `ip next-hop' value. */ | |
d62a17ae | 2652 | static void route_set_ipv6_nexthop_prefer_global_free(void *rule) |
161995ea | 2653 | { |
d62a17ae | 2654 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
161995ea DS |
2655 | } |
2656 | ||
2657 | /* Route map commands for ip nexthop set preferred. */ | |
d62a17ae | 2658 | struct route_map_rule_cmd route_set_ipv6_nexthop_prefer_global_cmd = { |
2659 | "ipv6 next-hop prefer-global", route_set_ipv6_nexthop_prefer_global, | |
2660 | route_set_ipv6_nexthop_prefer_global_compile, | |
2661 | route_set_ipv6_nexthop_prefer_global_free}; | |
161995ea | 2662 | |
718e3744 | 2663 | /* `set ipv6 nexthop local IP_ADDRESS' */ |
2664 | ||
2665 | /* Set nexthop to object. ojbect must be pointer to struct attr. */ | |
d62a17ae | 2666 | static route_map_result_t route_set_ipv6_nexthop_local(void *rule, |
123214ef | 2667 | const struct prefix *p, |
d62a17ae | 2668 | route_map_object_t type, |
2669 | void *object) | |
2670 | { | |
2671 | struct in6_addr *address; | |
9b6d8fcf | 2672 | struct bgp_path_info *path; |
d62a17ae | 2673 | |
2674 | if (type == RMAP_BGP) { | |
2675 | /* Fetch routemap's rule information. */ | |
2676 | address = rule; | |
9b6d8fcf | 2677 | path = object; |
d62a17ae | 2678 | |
2679 | /* Set next hop value. */ | |
9b6d8fcf | 2680 | path->attr->mp_nexthop_local = *address; |
d62a17ae | 2681 | |
2682 | /* Set nexthop length. */ | |
9b6d8fcf | 2683 | if (path->attr->mp_nexthop_len |
d62a17ae | 2684 | != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL) |
9b6d8fcf | 2685 | path->attr->mp_nexthop_len = |
d62a17ae | 2686 | BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL; |
2687 | ||
9b6d8fcf | 2688 | SET_FLAG(path->attr->rmap_change_flags, |
d62a17ae | 2689 | BATTR_RMAP_IPV6_LL_NHOP_CHANGED); |
2690 | } | |
718e3744 | 2691 | |
d62a17ae | 2692 | return RMAP_OKAY; |
718e3744 | 2693 | } |
2694 | ||
2695 | /* Route map `ip nexthop' compile function. Given string is converted | |
2696 | to struct in_addr structure. */ | |
d62a17ae | 2697 | static void *route_set_ipv6_nexthop_local_compile(const char *arg) |
718e3744 | 2698 | { |
d62a17ae | 2699 | int ret; |
2700 | struct in6_addr *address; | |
718e3744 | 2701 | |
d62a17ae | 2702 | address = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct in6_addr)); |
718e3744 | 2703 | |
d62a17ae | 2704 | ret = inet_pton(AF_INET6, arg, address); |
718e3744 | 2705 | |
d62a17ae | 2706 | if (ret == 0) { |
2707 | XFREE(MTYPE_ROUTE_MAP_COMPILED, address); | |
2708 | return NULL; | |
2709 | } | |
718e3744 | 2710 | |
d62a17ae | 2711 | return address; |
718e3744 | 2712 | } |
2713 | ||
2714 | /* Free route map's compiled `ip nexthop' value. */ | |
d62a17ae | 2715 | static void route_set_ipv6_nexthop_local_free(void *rule) |
718e3744 | 2716 | { |
d62a17ae | 2717 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
718e3744 | 2718 | } |
2719 | ||
2720 | /* Route map commands for ip nexthop set. */ | |
d62a17ae | 2721 | struct route_map_rule_cmd route_set_ipv6_nexthop_local_cmd = { |
2722 | "ipv6 next-hop local", route_set_ipv6_nexthop_local, | |
2723 | route_set_ipv6_nexthop_local_compile, | |
2724 | route_set_ipv6_nexthop_local_free}; | |
90916ac2 DS |
2725 | |
2726 | /* `set ipv6 nexthop peer-address' */ | |
2727 | ||
2728 | /* Set nexthop to object. ojbect must be pointer to struct attr. */ | |
d62a17ae | 2729 | static route_map_result_t route_set_ipv6_nexthop_peer(void *rule, |
123214ef | 2730 | const struct prefix *pfx, |
d62a17ae | 2731 | route_map_object_t type, |
2732 | void *object) | |
2733 | { | |
2734 | struct in6_addr peer_address; | |
9b6d8fcf | 2735 | struct bgp_path_info *path; |
d62a17ae | 2736 | struct peer *peer; |
2737 | ||
2738 | if (type == RMAP_BGP) { | |
2739 | /* Fetch routemap's rule information. */ | |
9b6d8fcf DS |
2740 | path = object; |
2741 | peer = path->peer; | |
d62a17ae | 2742 | |
2743 | if ((CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_IN) | |
2744 | || CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_IMPORT)) | |
2745 | && peer->su_remote | |
2746 | && sockunion_family(peer->su_remote) == AF_INET6) { | |
2747 | peer_address = peer->su_remote->sin6.sin6_addr; | |
2748 | /* Set next hop value and length in attribute. */ | |
2749 | if (IN6_IS_ADDR_LINKLOCAL(&peer_address)) { | |
9b6d8fcf DS |
2750 | path->attr->mp_nexthop_local = peer_address; |
2751 | if (path->attr->mp_nexthop_len != 32) | |
2752 | path->attr->mp_nexthop_len = 32; | |
d62a17ae | 2753 | } else { |
9b6d8fcf DS |
2754 | path->attr->mp_nexthop_global = peer_address; |
2755 | if (path->attr->mp_nexthop_len == 0) | |
2756 | path->attr->mp_nexthop_len = 16; | |
d62a17ae | 2757 | } |
2758 | ||
2759 | } else if (CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_OUT)) { | |
2760 | /* The next hop value will be set as part of packet | |
2761 | * rewrite. | |
2762 | * Set the flags here to indicate that rewrite needs to | |
2763 | * be done. | |
2764 | * Also, clear the value - we clear both global and | |
2765 | * link-local | |
2766 | * nexthops, whether we send one or both is determined | |
2767 | * elsewhere. | |
2768 | */ | |
9b6d8fcf | 2769 | SET_FLAG(path->attr->rmap_change_flags, |
d62a17ae | 2770 | BATTR_RMAP_NEXTHOP_PEER_ADDRESS); |
2771 | /* clear next hop value. */ | |
9b6d8fcf | 2772 | memset(&(path->attr->mp_nexthop_global), 0, |
d62a17ae | 2773 | sizeof(struct in6_addr)); |
9b6d8fcf | 2774 | memset(&(path->attr->mp_nexthop_local), 0, |
d62a17ae | 2775 | sizeof(struct in6_addr)); |
2776 | } | |
90916ac2 | 2777 | } |
90916ac2 | 2778 | |
d62a17ae | 2779 | return RMAP_OKAY; |
90916ac2 DS |
2780 | } |
2781 | ||
2782 | /* Route map `ip next-hop' compile function. Given string is converted | |
2783 | to struct in_addr structure. */ | |
d62a17ae | 2784 | static void *route_set_ipv6_nexthop_peer_compile(const char *arg) |
90916ac2 | 2785 | { |
d62a17ae | 2786 | int *rins = NULL; |
90916ac2 | 2787 | |
d62a17ae | 2788 | rins = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(int)); |
2789 | *rins = 1; | |
90916ac2 | 2790 | |
d62a17ae | 2791 | return rins; |
90916ac2 DS |
2792 | } |
2793 | ||
2794 | /* Free route map's compiled `ip next-hop' value. */ | |
d62a17ae | 2795 | static void route_set_ipv6_nexthop_peer_free(void *rule) |
90916ac2 | 2796 | { |
d62a17ae | 2797 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
90916ac2 DS |
2798 | } |
2799 | ||
2800 | /* Route map commands for ip nexthop set. */ | |
d62a17ae | 2801 | struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd = { |
2802 | "ipv6 next-hop peer-address", route_set_ipv6_nexthop_peer, | |
2803 | route_set_ipv6_nexthop_peer_compile, route_set_ipv6_nexthop_peer_free}; | |
90916ac2 | 2804 | |
69ba6dd7 | 2805 | /* `set ipv4 vpn next-hop A.B.C.D' */ |
718e3744 | 2806 | |
d62a17ae | 2807 | static route_map_result_t route_set_vpnv4_nexthop(void *rule, |
123214ef | 2808 | const struct prefix *prefix, |
d62a17ae | 2809 | route_map_object_t type, |
2810 | void *object) | |
718e3744 | 2811 | { |
d62a17ae | 2812 | struct in_addr *address; |
9b6d8fcf | 2813 | struct bgp_path_info *path; |
718e3744 | 2814 | |
d62a17ae | 2815 | if (type == RMAP_BGP) { |
2816 | /* Fetch routemap's rule information. */ | |
2817 | address = rule; | |
9b6d8fcf | 2818 | path = object; |
e52702f2 | 2819 | |
d62a17ae | 2820 | /* Set next hop value. */ |
9b6d8fcf DS |
2821 | path->attr->mp_nexthop_global_in = *address; |
2822 | path->attr->mp_nexthop_len = 4; | |
d62a17ae | 2823 | } |
718e3744 | 2824 | |
d62a17ae | 2825 | return RMAP_OKAY; |
718e3744 | 2826 | } |
2827 | ||
d62a17ae | 2828 | static void *route_set_vpnv4_nexthop_compile(const char *arg) |
718e3744 | 2829 | { |
d62a17ae | 2830 | int ret; |
2831 | struct in_addr *address; | |
718e3744 | 2832 | |
d62a17ae | 2833 | address = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct in_addr)); |
718e3744 | 2834 | |
d62a17ae | 2835 | ret = inet_aton(arg, address); |
718e3744 | 2836 | |
d62a17ae | 2837 | if (ret == 0) { |
2838 | XFREE(MTYPE_ROUTE_MAP_COMPILED, address); | |
2839 | return NULL; | |
2840 | } | |
718e3744 | 2841 | |
d62a17ae | 2842 | return address; |
718e3744 | 2843 | } |
2844 | ||
69ba6dd7 | 2845 | /* `set ipv6 vpn next-hop A.B.C.D' */ |
d6902373 | 2846 | |
d62a17ae | 2847 | static route_map_result_t route_set_vpnv6_nexthop(void *rule, |
123214ef | 2848 | const struct prefix *prefix, |
d62a17ae | 2849 | route_map_object_t type, |
2850 | void *object) | |
d6902373 | 2851 | { |
d62a17ae | 2852 | struct in6_addr *address; |
9b6d8fcf | 2853 | struct bgp_path_info *path; |
d6902373 | 2854 | |
d62a17ae | 2855 | if (type == RMAP_BGP) { |
2856 | /* Fetch routemap's rule information. */ | |
2857 | address = rule; | |
9b6d8fcf | 2858 | path = object; |
d6902373 | 2859 | |
d62a17ae | 2860 | /* Set next hop value. */ |
9b6d8fcf | 2861 | memcpy(&path->attr->mp_nexthop_global, address, |
d62a17ae | 2862 | sizeof(struct in6_addr)); |
9b6d8fcf | 2863 | path->attr->mp_nexthop_len = BGP_ATTR_NHLEN_VPNV6_GLOBAL; |
d62a17ae | 2864 | } |
d6902373 | 2865 | |
d62a17ae | 2866 | return RMAP_OKAY; |
d6902373 PG |
2867 | } |
2868 | ||
d62a17ae | 2869 | static void *route_set_vpnv6_nexthop_compile(const char *arg) |
d6902373 | 2870 | { |
d62a17ae | 2871 | int ret; |
2872 | struct in6_addr *address; | |
d6902373 | 2873 | |
d62a17ae | 2874 | address = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct in6_addr)); |
2875 | ret = inet_pton(AF_INET6, arg, address); | |
d6902373 | 2876 | |
d62a17ae | 2877 | if (ret == 0) { |
2878 | XFREE(MTYPE_ROUTE_MAP_COMPILED, address); | |
2879 | return NULL; | |
2880 | } | |
d6902373 | 2881 | |
d62a17ae | 2882 | return address; |
d6902373 PG |
2883 | } |
2884 | ||
d62a17ae | 2885 | static void route_set_vpn_nexthop_free(void *rule) |
718e3744 | 2886 | { |
d62a17ae | 2887 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
718e3744 | 2888 | } |
2889 | ||
69ba6dd7 | 2890 | /* Route map commands for ipv4 next-hop set. */ |
d62a17ae | 2891 | struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd = { |
2892 | "ipv4 vpn next-hop", route_set_vpnv4_nexthop, | |
2893 | route_set_vpnv4_nexthop_compile, route_set_vpn_nexthop_free}; | |
d6902373 | 2894 | |
69ba6dd7 | 2895 | /* Route map commands for ipv6 next-hop set. */ |
d62a17ae | 2896 | struct route_map_rule_cmd route_set_vpnv6_nexthop_cmd = { |
2897 | "ipv6 vpn next-hop", route_set_vpnv6_nexthop, | |
2898 | route_set_vpnv6_nexthop_compile, route_set_vpn_nexthop_free}; | |
6b0655a2 | 2899 | |
718e3744 | 2900 | /* `set originator-id' */ |
2901 | ||
2902 | /* For origin set. */ | |
d62a17ae | 2903 | static route_map_result_t route_set_originator_id(void *rule, |
123214ef | 2904 | const struct prefix *prefix, |
d62a17ae | 2905 | route_map_object_t type, |
2906 | void *object) | |
718e3744 | 2907 | { |
d62a17ae | 2908 | struct in_addr *address; |
9b6d8fcf | 2909 | struct bgp_path_info *path; |
718e3744 | 2910 | |
d62a17ae | 2911 | if (type == RMAP_BGP) { |
2912 | address = rule; | |
9b6d8fcf | 2913 | path = object; |
e52702f2 | 2914 | |
9b6d8fcf DS |
2915 | path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID); |
2916 | path->attr->originator_id = *address; | |
d62a17ae | 2917 | } |
718e3744 | 2918 | |
d62a17ae | 2919 | return RMAP_OKAY; |
718e3744 | 2920 | } |
2921 | ||
2922 | /* Compile function for originator-id set. */ | |
d62a17ae | 2923 | static void *route_set_originator_id_compile(const char *arg) |
718e3744 | 2924 | { |
d62a17ae | 2925 | int ret; |
2926 | struct in_addr *address; | |
718e3744 | 2927 | |
d62a17ae | 2928 | address = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct in_addr)); |
718e3744 | 2929 | |
d62a17ae | 2930 | ret = inet_aton(arg, address); |
718e3744 | 2931 | |
d62a17ae | 2932 | if (ret == 0) { |
2933 | XFREE(MTYPE_ROUTE_MAP_COMPILED, address); | |
2934 | return NULL; | |
2935 | } | |
718e3744 | 2936 | |
d62a17ae | 2937 | return address; |
718e3744 | 2938 | } |
2939 | ||
2940 | /* Compile function for originator_id set. */ | |
d62a17ae | 2941 | static void route_set_originator_id_free(void *rule) |
718e3744 | 2942 | { |
d62a17ae | 2943 | XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); |
718e3744 | 2944 | } |
2945 | ||
515e500c | 2946 | /* Set originator-id rule structure. */ |
d62a17ae | 2947 | struct route_map_rule_cmd route_set_originator_id_cmd = { |
9d303b37 DL |
2948 | "originator-id", route_set_originator_id, |
2949 | route_set_originator_id_compile, route_set_originator_id_free, | |
718e3744 | 2950 | }; |
6b0655a2 | 2951 | |
718e3744 | 2952 | /* Add bgp route map rule. */ |
d62a17ae | 2953 | static int bgp_route_match_add(struct vty *vty, const char *command, |
2954 | const char *arg, route_map_event_t type) | |
2955 | { | |
2956 | VTY_DECLVAR_CONTEXT(route_map_index, index); | |
9ca25fed | 2957 | int retval = CMD_SUCCESS; |
d62a17ae | 2958 | int ret; |
2959 | ||
2960 | ret = route_map_add_match(index, command, arg); | |
9ca25fed DS |
2961 | switch (ret) { |
2962 | case RMAP_RULE_MISSING: | |
2963 | vty_out(vty, "%% BGP Can't find rule.\n"); | |
2964 | retval = CMD_WARNING_CONFIG_FAILED; | |
2965 | break; | |
2966 | case RMAP_COMPILE_ERROR: | |
2967 | vty_out(vty, "%% BGP Argument is malformed.\n"); | |
2968 | retval = CMD_WARNING_CONFIG_FAILED; | |
2969 | break; | |
2970 | case RMAP_COMPILE_SUCCESS: | |
2971 | if (type != RMAP_EVENT_MATCH_ADDED) { | |
2972 | route_map_upd8_dependency(type, arg, index->map->name); | |
d62a17ae | 2973 | } |
9ca25fed | 2974 | break; |
718e3744 | 2975 | } |
518f0eb1 | 2976 | |
9ca25fed | 2977 | return retval; |
718e3744 | 2978 | } |
2979 | ||
2980 | /* Delete bgp route map rule. */ | |
d62a17ae | 2981 | static int bgp_route_match_delete(struct vty *vty, const char *command, |
2982 | const char *arg, route_map_event_t type) | |
2983 | { | |
2984 | VTY_DECLVAR_CONTEXT(route_map_index, index); | |
2985 | int ret; | |
9ca25fed | 2986 | int retval = CMD_SUCCESS; |
d62a17ae | 2987 | char *dep_name = NULL; |
2988 | const char *tmpstr; | |
2989 | char *rmap_name = NULL; | |
2990 | ||
2991 | if (type != RMAP_EVENT_MATCH_DELETED) { | |
2992 | /* ignore the mundane, the types without any dependency */ | |
2993 | if (arg == NULL) { | |
2994 | if ((tmpstr = route_map_get_match_arg(index, command)) | |
2995 | != NULL) | |
2996 | dep_name = | |
2997 | XSTRDUP(MTYPE_ROUTE_MAP_RULE, tmpstr); | |
2998 | } else { | |
2999 | dep_name = XSTRDUP(MTYPE_ROUTE_MAP_RULE, arg); | |
3000 | } | |
3001 | rmap_name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, index->map->name); | |
ffd0c037 | 3002 | } |
d62a17ae | 3003 | |
3004 | ret = route_map_delete_match(index, command, dep_name); | |
9ca25fed DS |
3005 | switch (ret) { |
3006 | case RMAP_RULE_MISSING: | |
3007 | vty_out(vty, "%% BGP Can't find rule.\n"); | |
3008 | retval = CMD_WARNING_CONFIG_FAILED; | |
3009 | break; | |
3010 | case RMAP_COMPILE_ERROR: | |
3011 | vty_out(vty, "%% BGP Argument is malformed.\n"); | |
3012 | retval = CMD_WARNING_CONFIG_FAILED; | |
3013 | break; | |
3014 | case RMAP_COMPILE_SUCCESS: | |
3015 | if (type != RMAP_EVENT_MATCH_DELETED && dep_name) | |
3016 | route_map_upd8_dependency(type, dep_name, rmap_name); | |
3017 | break; | |
718e3744 | 3018 | } |
518f0eb1 | 3019 | |
d62a17ae | 3020 | if (dep_name) |
3021 | XFREE(MTYPE_ROUTE_MAP_RULE, dep_name); | |
3022 | if (rmap_name) | |
3023 | XFREE(MTYPE_ROUTE_MAP_NAME, rmap_name); | |
518f0eb1 | 3024 | |
9ca25fed | 3025 | return retval; |
718e3744 | 3026 | } |
3027 | ||
518f0eb1 | 3028 | /* |
2a3d5731 | 3029 | * This is the workhorse routine for processing in/out routemap |
518f0eb1 DS |
3030 | * modifications. |
3031 | */ | |
d62a17ae | 3032 | static void bgp_route_map_process_peer(const char *rmap_name, |
3033 | struct route_map *map, struct peer *peer, | |
3034 | int afi, int safi, int route_update) | |
3035 | { | |
3036 | ||
3037 | int update; | |
3038 | struct bgp_filter *filter; | |
3039 | ||
3040 | if (!peer || !rmap_name) | |
3041 | return; | |
3042 | ||
3043 | filter = &peer->filter[afi][safi]; | |
3044 | /* | |
3045 | * in is for non-route-server clients, | |
3046 | * out is for all peers | |
3047 | */ | |
3048 | if (!CHECK_FLAG(peer->flags, PEER_FLAG_RSERVER_CLIENT)) { | |
3049 | if (filter->map[RMAP_IN].name | |
3050 | && (strcmp(rmap_name, filter->map[RMAP_IN].name) == 0)) { | |
3051 | filter->map[RMAP_IN].map = map; | |
3052 | ||
3053 | if (route_update && peer->status == Established) { | |
3054 | if (CHECK_FLAG(peer->af_flags[afi][safi], | |
3055 | PEER_FLAG_SOFT_RECONFIG)) { | |
3056 | if (bgp_debug_update(peer, NULL, NULL, | |
3057 | 1)) | |
3058 | zlog_debug( | |
3059 | "Processing route_map %s update on " | |
3060 | "peer %s (inbound, soft-reconfig)", | |
3061 | rmap_name, peer->host); | |
3062 | ||
3063 | bgp_soft_reconfig_in(peer, afi, safi); | |
3064 | } else if ( | |
3065 | CHECK_FLAG(peer->cap, | |
3066 | PEER_CAP_REFRESH_OLD_RCV) | |
3067 | || CHECK_FLAG( | |
3068 | peer->cap, | |
3069 | PEER_CAP_REFRESH_NEW_RCV)) { | |
3070 | ||
3071 | if (bgp_debug_update(peer, NULL, NULL, | |
3072 | 1)) | |
3073 | zlog_debug( | |
3074 | "Processing route_map %s update on " | |
3075 | "peer %s (inbound, route-refresh)", | |
3076 | rmap_name, peer->host); | |
3077 | bgp_route_refresh_send(peer, afi, safi, | |
3078 | 0, 0, 0); | |
3079 | } | |
3080 | } | |
518f0eb1 | 3081 | } |
718e3744 | 3082 | } |
d62a17ae | 3083 | |
3084 | if (CHECK_FLAG(peer->flags, PEER_FLAG_RSERVER_CLIENT)) { | |
3085 | update = 0; | |
3086 | ||
3087 | if (update && route_update && peer->status == Established) { | |
3088 | if (CHECK_FLAG(peer->af_flags[afi][safi], | |
3089 | PEER_FLAG_SOFT_RECONFIG)) { | |
3090 | if (bgp_debug_update(peer, NULL, NULL, 1)) | |
3091 | zlog_debug( | |
3092 | "Processing route_map %s update on " | |
3093 | "peer %s (import, soft-reconfig)", | |
3094 | rmap_name, peer->host); | |
3095 | ||
3096 | bgp_soft_reconfig_in(peer, afi, safi); | |
3097 | } else if (CHECK_FLAG(peer->cap, | |
3098 | PEER_CAP_REFRESH_OLD_RCV) | |
3099 | || CHECK_FLAG(peer->cap, | |
3100 | PEER_CAP_REFRESH_NEW_RCV)) { | |
3101 | if (bgp_debug_update(peer, NULL, NULL, 1)) | |
3102 | zlog_debug( | |
3103 | "Processing route_map %s update on " | |
3104 | "peer %s (import, route-refresh)", | |
3105 | rmap_name, peer->host); | |
3106 | bgp_route_refresh_send(peer, afi, safi, 0, 0, | |
3107 | 0); | |
3108 | } | |
3109 | /* DD: Else, what else do we do ? Reset peer ? */ | |
3110 | } | |
518f0eb1 | 3111 | } |
d62a17ae | 3112 | |
3113 | /* | |
3114 | * For outbound, unsuppress and default-originate map change (content or | |
3115 | * map created), merely update the "config" here, the actual route | |
3116 | * announcement happens at the group level. | |
3117 | */ | |
3118 | if (filter->map[RMAP_OUT].name | |
3119 | && (strcmp(rmap_name, filter->map[RMAP_OUT].name) == 0)) | |
3120 | filter->map[RMAP_OUT].map = map; | |
3121 | ||
3122 | if (filter->usmap.name && (strcmp(rmap_name, filter->usmap.name) == 0)) | |
3123 | filter->usmap.map = map; | |
3124 | ||
3125 | if (peer->default_rmap[afi][safi].name | |
3126 | && (strcmp(rmap_name, peer->default_rmap[afi][safi].name) == 0)) | |
3127 | peer->default_rmap[afi][safi].map = map; | |
3128 | } | |
3129 | ||
3130 | static void bgp_route_map_update_peer_group(const char *rmap_name, | |
3131 | struct route_map *map, | |
3132 | struct bgp *bgp) | |
3133 | { | |
3134 | struct peer_group *group; | |
3135 | struct listnode *node, *nnode; | |
3136 | struct bgp_filter *filter; | |
3137 | int afi, safi; | |
3138 | int direct; | |
3139 | ||
3140 | if (!bgp) | |
3141 | return; | |
3142 | ||
3143 | /* All the peers have been updated correctly already. This is | |
3144 | * just updating the placeholder data. No real update required. | |
3145 | */ | |
05c7a1cc QY |
3146 | for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) { |
3147 | FOREACH_AFI_SAFI (afi, safi) { | |
3148 | filter = &group->conf->filter[afi][safi]; | |
3149 | ||
3150 | for (direct = RMAP_IN; direct < RMAP_MAX; direct++) { | |
3151 | if ((filter->map[direct].name) | |
3152 | && (strcmp(rmap_name, | |
3153 | filter->map[direct].name) | |
d62a17ae | 3154 | == 0)) |
05c7a1cc | 3155 | filter->map[direct].map = map; |
d62a17ae | 3156 | } |
05c7a1cc QY |
3157 | |
3158 | if (filter->usmap.name | |
3159 | && (strcmp(rmap_name, filter->usmap.name) == 0)) | |
3160 | filter->usmap.map = map; | |
3161 | } | |
3162 | } | |
518f0eb1 DS |
3163 | } |
3164 | ||
a6e0d253 DW |
3165 | /* |
3166 | * Note that if an extreme number (tens of thousands) of route-maps are in use | |
3167 | * and if bgp has an extreme number of peers, network statements, etc then this | |
3168 | * function can consume a lot of cycles. This is due to this function being | |
3169 | * called for each route-map and within this function we walk the list of peers, | |
3170 | * network statements, etc looking to see if they use this route-map. | |
3171 | */ | |
d62a17ae | 3172 | static void bgp_route_map_process_update(struct bgp *bgp, const char *rmap_name, |
3173 | int route_update) | |
3174 | { | |
3175 | int i; | |
3176 | afi_t afi; | |
3177 | safi_t safi; | |
3178 | struct peer *peer; | |
3179 | struct bgp_node *bn; | |
3180 | struct bgp_static *bgp_static; | |
3181 | struct listnode *node, *nnode; | |
3182 | struct route_map *map; | |
3183 | char buf[INET6_ADDRSTRLEN]; | |
3184 | ||
3185 | map = route_map_lookup_by_name(rmap_name); | |
3186 | ||
3187 | for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) { | |
3188 | ||
3189 | /* Ignore dummy peer-group structure */ | |
3190 | if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) | |
3191 | continue; | |
3192 | ||
05c7a1cc QY |
3193 | FOREACH_AFI_SAFI (afi, safi) { |
3194 | /* process in/out/import/export/default-orig | |
3195 | * route-maps */ | |
3196 | bgp_route_map_process_peer(rmap_name, map, peer, afi, | |
3197 | safi, route_update); | |
3198 | } | |
d62a17ae | 3199 | } |
3200 | ||
3201 | /* for outbound/default-orig route-maps, process for groups */ | |
3202 | update_group_policy_update(bgp, BGP_POLICY_ROUTE_MAP, rmap_name, | |
3203 | route_update, 0); | |
3204 | ||
3205 | /* update peer-group config (template) */ | |
3206 | bgp_route_map_update_peer_group(rmap_name, map, bgp); | |
3207 | ||
05c7a1cc QY |
3208 | FOREACH_AFI_SAFI (afi, safi) { |
3209 | /* For table route-map updates. */ | |
3210 | if (!bgp_fibupd_safi(safi)) | |
3211 | continue; | |
d62a17ae | 3212 | |
05c7a1cc QY |
3213 | if (bgp->table_map[afi][safi].name |
3214 | && (strcmp(rmap_name, bgp->table_map[afi][safi].name) | |
3215 | == 0)) { | |
3216 | bgp->table_map[afi][safi].map = map; | |
3217 | ||
3218 | if (BGP_DEBUG(zebra, ZEBRA)) | |
3219 | zlog_debug( | |
3220 | "Processing route_map %s update on " | |
3221 | "table map", | |
3222 | rmap_name); | |
3223 | if (route_update) | |
3224 | bgp_zebra_announce_table(bgp, afi, safi); | |
3225 | } | |
d62a17ae | 3226 | |
05c7a1cc QY |
3227 | /* For network route-map updates. */ |
3228 | for (bn = bgp_table_top(bgp->route[afi][safi]); bn; | |
96f10e1e DS |
3229 | bn = bgp_route_next(bn)) { |
3230 | bgp_static = bgp_static_get_node_info(bn); | |
3231 | if (bgp_static != NULL) { | |
05c7a1cc QY |
3232 | if (bgp_static->rmap.name |
3233 | && (strcmp(rmap_name, bgp_static->rmap.name) | |
3234 | == 0)) { | |
96f10e1e | 3235 | |
05c7a1cc QY |
3236 | bgp_static->rmap.map = map; |
3237 | ||
3238 | if (route_update) | |
3239 | if (!bgp_static->backdoor) { | |
3240 | if (bgp_debug_zebra( | |
3241 | &bn->p)) | |
3242 | zlog_debug( | |
3243 | "Processing route_map %s update on " | |
3244 | "static route %s", | |
3245 | rmap_name, | |
3246 | inet_ntop( | |
3247 | bn->p.family, | |
3248 | &bn->p.u.prefix, | |
3249 | buf, | |
3250 | INET6_ADDRSTRLEN)); | |
3251 | bgp_static_update( | |
3252 | bgp, &bn->p, | |
3253 | bgp_static, afi, | |
3254 | safi); | |
3255 | } | |
d62a17ae | 3256 | } |
05c7a1cc | 3257 | } |
96f10e1e | 3258 | } |
05c7a1cc | 3259 | } |
d62a17ae | 3260 | |
3261 | /* For redistribute route-map updates. */ | |
3262 | for (afi = AFI_IP; afi < AFI_MAX; afi++) | |
3263 | for (i = 0; i < ZEBRA_ROUTE_MAX; i++) { | |
3264 | struct list *red_list; | |
d62a17ae | 3265 | struct bgp_redist *red; |
3266 | ||
3267 | red_list = bgp->redist[afi][i]; | |
3268 | if (!red_list) | |
3269 | continue; | |
3270 | ||
3271 | for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) { | |
3272 | if (red->rmap.name | |
3273 | && (strcmp(rmap_name, red->rmap.name) | |
3274 | == 0)) { | |
3275 | red->rmap.map = map; | |
3276 | ||
3277 | if (route_update) { | |
3278 | if (BGP_DEBUG(zebra, ZEBRA)) | |
3279 | zlog_debug( | |
3280 | "Processing route_map %s update on " | |
3281 | "redistributed routes", | |
3282 | rmap_name); | |
3283 | ||
3284 | bgp_redistribute_resend( | |
3285 | bgp, afi, i, | |
3286 | red->instance); | |
3287 | } | |
3288 | } | |
3289 | } | |
3290 | } | |
53c84f78 MK |
3291 | |
3292 | /* for type5 command route-maps */ | |
3293 | FOREACH_AFI_SAFI (afi, safi) { | |
996c9314 LB |
3294 | if (bgp->adv_cmd_rmap[afi][safi].name |
3295 | && strcmp(rmap_name, bgp->adv_cmd_rmap[afi][safi].name) | |
3296 | == 0) { | |
53c84f78 MK |
3297 | if (BGP_DEBUG(zebra, ZEBRA)) |
3298 | zlog_debug( | |
996c9314 LB |
3299 | "Processing route_map %s update on advertise type5 route command", |
3300 | rmap_name); | |
53c84f78 MK |
3301 | bgp_evpn_withdraw_type5_routes(bgp, afi, safi); |
3302 | bgp_evpn_advertise_type5_routes(bgp, afi, safi); | |
3303 | } | |
3304 | } | |
d62a17ae | 3305 | } |
3306 | ||
46a69f10 | 3307 | static void bgp_route_map_process_update_cb(char *rmap_name) |
d62a17ae | 3308 | { |
3309 | struct listnode *node, *nnode; | |
3310 | struct bgp *bgp; | |
3311 | ||
ddb5b488 | 3312 | for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) { |
d62a17ae | 3313 | bgp_route_map_process_update(bgp, rmap_name, 1); |
5fe9f963 | 3314 | |
65efcfce | 3315 | #if ENABLE_BGP_VNC |
ddb5b488 PZ |
3316 | /* zlog_debug("%s: calling vnc_routemap_update", __func__); */ |
3317 | vnc_routemap_update(bgp, __func__); | |
65efcfce | 3318 | #endif |
ddb5b488 PZ |
3319 | } |
3320 | ||
3321 | vpn_policy_routemap_event(rmap_name); | |
518f0eb1 DS |
3322 | } |
3323 | ||
d62a17ae | 3324 | int bgp_route_map_update_timer(struct thread *thread) |
518f0eb1 | 3325 | { |
d62a17ae | 3326 | bm->t_rmap_update = NULL; |
518f0eb1 | 3327 | |
d62a17ae | 3328 | route_map_walk_update_list(bgp_route_map_process_update_cb); |
518f0eb1 | 3329 | |
d62a17ae | 3330 | return (0); |
518f0eb1 DS |
3331 | } |
3332 | ||
d62a17ae | 3333 | static void bgp_route_map_mark_update(const char *rmap_name) |
518f0eb1 | 3334 | { |
d62a17ae | 3335 | if (bm->t_rmap_update == NULL) { |
3336 | struct listnode *node, *nnode; | |
3337 | struct bgp *bgp; | |
3f9c7369 | 3338 | |
d62a17ae | 3339 | /* rmap_update_timer of 0 means don't do route updates */ |
3340 | if (bm->rmap_update_timer) { | |
3341 | bm->t_rmap_update = NULL; | |
3342 | thread_add_timer(bm->master, bgp_route_map_update_timer, | |
3343 | NULL, bm->rmap_update_timer, | |
3344 | &bm->t_rmap_update); | |
5fe9f963 | 3345 | |
d62a17ae | 3346 | /* Signal the groups that a route-map update event has |
3347 | * started */ | |
3348 | for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) | |
3349 | update_group_policy_update(bgp, | |
3350 | BGP_POLICY_ROUTE_MAP, | |
3351 | rmap_name, 1, 1); | |
3352 | } else { | |
3353 | for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) | |
3354 | bgp_route_map_process_update(bgp, rmap_name, 0); | |
3355 | #if ENABLE_BGP_VNC | |
3356 | zlog_debug("%s: calling vnc_routemap_update", __func__); | |
3357 | vnc_routemap_update(bgp, __func__); | |
65efcfce | 3358 | #endif |
d62a17ae | 3359 | } |
3360 | } | |
718e3744 | 3361 | } |
6b0655a2 | 3362 | |
d62a17ae | 3363 | static void bgp_route_map_add(const char *rmap_name) |
73ac8160 | 3364 | { |
7096e938 | 3365 | if (route_map_mark_updated(rmap_name) == 0) |
d62a17ae | 3366 | bgp_route_map_mark_update(rmap_name); |
73ac8160 | 3367 | |
d62a17ae | 3368 | route_map_notify_dependencies(rmap_name, RMAP_EVENT_MATCH_ADDED); |
73ac8160 | 3369 | } |
518f0eb1 | 3370 | |
d62a17ae | 3371 | static void bgp_route_map_delete(const char *rmap_name) |
73ac8160 | 3372 | { |
7096e938 | 3373 | if (route_map_mark_updated(rmap_name) == 0) |
d62a17ae | 3374 | bgp_route_map_mark_update(rmap_name); |
73ac8160 | 3375 | |
d62a17ae | 3376 | route_map_notify_dependencies(rmap_name, RMAP_EVENT_MATCH_DELETED); |
73ac8160 | 3377 | } |
518f0eb1 | 3378 | |
d62a17ae | 3379 | static void bgp_route_map_event(route_map_event_t event, const char *rmap_name) |
73ac8160 | 3380 | { |
7096e938 | 3381 | if (route_map_mark_updated(rmap_name) == 0) |
d62a17ae | 3382 | bgp_route_map_mark_update(rmap_name); |
518f0eb1 | 3383 | |
d62a17ae | 3384 | route_map_notify_dependencies(rmap_name, RMAP_EVENT_MATCH_ADDED); |
73ac8160 DS |
3385 | } |
3386 | ||
d37ba549 MK |
3387 | DEFUN (match_mac_address, |
3388 | match_mac_address_cmd, | |
3389 | "match mac address WORD", | |
3390 | MATCH_STR | |
3391 | "mac address\n" | |
3392 | "Match address of route\n" | |
3393 | "MAC Access-list name\n") | |
3394 | { | |
3395 | return bgp_route_match_add(vty, "mac address", argv[3]->arg, | |
3396 | RMAP_EVENT_FILTER_ADDED); | |
3397 | } | |
3398 | ||
3399 | DEFUN (no_match_mac_address, | |
3400 | no_match_mac_address_cmd, | |
646050e5 | 3401 | "no match mac address WORD", |
d37ba549 MK |
3402 | NO_STR |
3403 | MATCH_STR | |
3404 | "mac\n" | |
646050e5 MK |
3405 | "Match address of route\n" |
3406 | "MAC acess-list name\n") | |
d37ba549 | 3407 | { |
d37ba549 MK |
3408 | return bgp_route_match_delete(vty, "mac address", argv[4]->arg, |
3409 | RMAP_EVENT_FILTER_DELETED); | |
3410 | } | |
73ac8160 | 3411 | |
33c2ff62 MK |
3412 | DEFUN (match_evpn_route_type, |
3413 | match_evpn_route_type_cmd, | |
d4ef18b6 | 3414 | "match evpn route-type <macip | multicast | prefix>", |
33c2ff62 MK |
3415 | MATCH_STR |
3416 | EVPN_HELP_STR | |
3417 | "Match route-type\n" | |
3418 | "mac-ip route\n" | |
3419 | "IMET route\n" | |
3420 | "prefix route\n") | |
3421 | { | |
3422 | return bgp_route_match_add(vty, "evpn route-type", argv[3]->arg, | |
3423 | RMAP_EVENT_MATCH_ADDED); | |
3424 | } | |
3425 | ||
3426 | DEFUN (no_match_evpn_route_type, | |
3427 | no_match_evpn_route_type_cmd, | |
d4ef18b6 | 3428 | "no match evpn route-type <macip | multicast | prefix>", |
33c2ff62 MK |
3429 | NO_STR |
3430 | MATCH_STR | |
3431 | EVPN_HELP_STR | |
3432 | "Match route-type\n" | |
3433 | "mac-ip route\n" | |
3434 | "IMET route\n" | |
3435 | "prefix route\n") | |
3436 | { | |
3437 | return bgp_route_match_delete(vty, "evpn route-type", argv[4]->arg, | |
3438 | RMAP_EVENT_MATCH_DELETED); | |
3439 | } | |
3440 | ||
3441 | ||
16f7ce2b MK |
3442 | DEFUN (match_evpn_vni, |
3443 | match_evpn_vni_cmd, | |
093e3f23 | 3444 | "match evpn vni " CMD_VNI_RANGE, |
16f7ce2b | 3445 | MATCH_STR |
62982d5a | 3446 | EVPN_HELP_STR |
16f7ce2b MK |
3447 | "Match VNI\n" |
3448 | "VNI ID\n") | |
3449 | { | |
646050e5 | 3450 | return bgp_route_match_add(vty, "evpn vni", argv[3]->arg, |
16f7ce2b MK |
3451 | RMAP_EVENT_MATCH_ADDED); |
3452 | } | |
3453 | ||
3454 | DEFUN (no_match_evpn_vni, | |
3455 | no_match_evpn_vni_cmd, | |
093e3f23 | 3456 | "no match evpn vni " CMD_VNI_RANGE, |
16f7ce2b MK |
3457 | NO_STR |
3458 | MATCH_STR | |
62982d5a | 3459 | EVPN_HELP_STR |
16f7ce2b MK |
3460 | "Match VNI\n" |
3461 | "VNI ID\n") | |
3462 | { | |
646050e5 | 3463 | return bgp_route_match_delete(vty, "evpn vni", argv[4]->arg, |
16f7ce2b MK |
3464 | RMAP_EVENT_MATCH_DELETED); |
3465 | } | |
3466 | ||
6fb219da MK |
3467 | DEFUN (match_evpn_default_route, |
3468 | match_evpn_default_route_cmd, | |
3469 | "match evpn default-route", | |
3470 | MATCH_STR | |
3471 | EVPN_HELP_STR | |
3472 | "default EVPN type-5 route\n") | |
3473 | { | |
3474 | return bgp_route_match_add(vty, "evpn default-route", NULL, | |
3475 | RMAP_EVENT_MATCH_ADDED); | |
3476 | } | |
3477 | ||
3478 | DEFUN (no_match_evpn_default_route, | |
3479 | no_match_evpn_default_route_cmd, | |
3480 | "no match evpn default-route", | |
3481 | NO_STR | |
3482 | MATCH_STR | |
3483 | EVPN_HELP_STR | |
3484 | "default EVPN type-5 route\n") | |
3485 | { | |
3486 | return bgp_route_match_delete(vty, "evpn default-route", NULL, | |
3487 | RMAP_EVENT_MATCH_DELETED); | |
3488 | } | |
3489 | ||
fee0f4c6 | 3490 | DEFUN (match_peer, |
3491 | match_peer_cmd, | |
8c3433e4 | 3492 | "match peer <A.B.C.D|X:X::X:X|WORD>", |
fee0f4c6 | 3493 | MATCH_STR |
3494 | "Match peer address\n" | |
6e13ed4a | 3495 | "IP address of peer\n" |
8c3433e4 DS |
3496 | "IPv6 address of peer\n" |
3497 | "Interface name of peer\n") | |
fee0f4c6 | 3498 | { |
d62a17ae | 3499 | int idx_ip = 2; |
3500 | return bgp_route_match_add(vty, "peer", argv[idx_ip]->arg, | |
3501 | RMAP_EVENT_MATCH_ADDED); | |
fee0f4c6 | 3502 | } |
3503 | ||
3504 | DEFUN (match_peer_local, | |
f412b39a | 3505 | match_peer_local_cmd, |
fee0f4c6 | 3506 | "match peer local", |
3507 | MATCH_STR | |
3508 | "Match peer address\n" | |
3509 | "Static or Redistributed routes\n") | |
3510 | { | |
d62a17ae | 3511 | return bgp_route_match_add(vty, "peer", "local", |
3512 | RMAP_EVENT_MATCH_DELETED); | |
fee0f4c6 | 3513 | } |
3514 | ||
3515 | DEFUN (no_match_peer, | |
3516 | no_match_peer_cmd, | |
8c3433e4 | 3517 | "no match peer [<local|A.B.C.D|X:X::X:X|WORD>]", |
fee0f4c6 | 3518 | NO_STR |
3519 | MATCH_STR | |
4c9bd275 DW |
3520 | "Match peer address\n" |
3521 | "Static or Redistributed routes\n" | |
3522 | "IP address of peer\n" | |
8c3433e4 DS |
3523 | "IPv6 address of peer\n" |
3524 | "Interface name of peer\n") | |
fee0f4c6 | 3525 | { |
d62a17ae | 3526 | int idx_peer = 3; |
4c9bd275 | 3527 | |
d62a17ae | 3528 | if (argc <= idx_peer) |
3529 | return bgp_route_match_delete(vty, "peer", NULL, | |
3530 | RMAP_EVENT_MATCH_DELETED); | |
3531 | return bgp_route_match_delete(vty, "peer", argv[idx_peer]->arg, | |
3532 | RMAP_EVENT_MATCH_DELETED); | |
fee0f4c6 | 3533 | } |
3534 | ||
1d7c7ace DS |
3535 | #if defined(HAVE_LUA) |
3536 | DEFUN (match_command, | |
3537 | match_command_cmd, | |
3538 | "match command WORD", | |
3539 | MATCH_STR | |
3540 | "Run a command to match\n" | |
3541 | "The command to run\n") | |
3542 | { | |
3543 | return bgp_route_match_add(vty, "command", argv[2]->arg, | |
3544 | RMAP_EVENT_FILTER_ADDED); | |
3545 | } | |
3546 | ||
3547 | DEFUN (no_match_command, | |
3548 | no_match_command_cmd, | |
3549 | "no match command WORD", | |
3550 | NO_STR | |
3551 | MATCH_STR | |
3552 | "Run a command to match\n" | |
3553 | "The command to run\n") | |
3554 | { | |
3555 | return bgp_route_match_delete(vty, "command", argv[3]->arg, | |
3556 | RMAP_EVENT_FILTER_DELETED); | |
3557 | } | |
3558 | #endif | |
fee0f4c6 | 3559 | |
4c9bd275 | 3560 | /* match probability */ |
1add115a VT |
3561 | DEFUN (match_probability, |
3562 | match_probability_cmd, | |
6147e2c6 | 3563 | "match probability (0-100)", |
1add115a VT |
3564 | MATCH_STR |
3565 | "Match portion of routes defined by percentage value\n" | |
3566 | "Percentage of routes\n") | |
3567 | { | |
d62a17ae | 3568 | int idx_number = 2; |
3569 | return bgp_route_match_add(vty, "probability", argv[idx_number]->arg, | |
3570 | RMAP_EVENT_MATCH_ADDED); | |
1add115a VT |
3571 | } |
3572 | ||
4c9bd275 | 3573 | |
1add115a VT |
3574 | DEFUN (no_match_probability, |
3575 | no_match_probability_cmd, | |
4c9bd275 | 3576 | "no match probability [(1-99)]", |
1add115a VT |
3577 | NO_STR |
3578 | MATCH_STR | |
4c9bd275 DW |
3579 | "Match portion of routes defined by percentage value\n" |
3580 | "Percentage of routes\n") | |
1add115a | 3581 | { |
d62a17ae | 3582 | int idx_number = 3; |
3583 | if (argc <= idx_number) | |
3584 | return bgp_route_match_delete(vty, "probability", NULL, | |
3585 | RMAP_EVENT_MATCH_DELETED); | |
3586 | return bgp_route_match_delete(vty, "probability", argv[idx_number]->arg, | |
3587 | RMAP_EVENT_MATCH_DELETED); | |
1add115a VT |
3588 | } |
3589 | ||
1add115a | 3590 | |
f412b39a | 3591 | DEFUN (match_ip_route_source, |
c1643bb7 | 3592 | match_ip_route_source_cmd, |
6147e2c6 | 3593 | "match ip route-source <(1-199)|(1300-2699)|WORD>", |
c1643bb7 | 3594 | MATCH_STR |
3595 | IP_STR | |
3596 | "Match advertising source address of route\n" | |
3597 | "IP access-list number\n" | |
3598 | "IP access-list number (expanded range)\n" | |
3599 | "IP standard access-list name\n") | |
3600 | { | |
d62a17ae | 3601 | int idx_acl = 3; |
3602 | return bgp_route_match_add(vty, "ip route-source", argv[idx_acl]->arg, | |
3603 | RMAP_EVENT_FILTER_ADDED); | |
c1643bb7 | 3604 | } |
3605 | ||
4c9bd275 | 3606 | |
c1643bb7 | 3607 | DEFUN (no_match_ip_route_source, |
3608 | no_match_ip_route_source_cmd, | |
6de69f83 | 3609 | "no match ip route-source [<(1-199)|(1300-2699)|WORD>]", |
c1643bb7 | 3610 | NO_STR |
3611 | MATCH_STR | |
3612 | IP_STR | |
4c9bd275 DW |
3613 | "Match advertising source address of route\n" |
3614 | "IP access-list number\n" | |
3615 | "IP access-list number (expanded range)\n" | |
3616 | "IP standard access-list name\n") | |
c1643bb7 | 3617 | { |
d62a17ae | 3618 | int idx_number = 4; |
3619 | if (argc <= idx_number) | |
3620 | return bgp_route_match_delete(vty, "ip route-source", NULL, | |
3621 | RMAP_EVENT_FILTER_DELETED); | |
3622 | return bgp_route_match_delete(vty, "ip route-source", | |
3623 | argv[idx_number]->arg, | |
3624 | RMAP_EVENT_FILTER_DELETED); | |
c1643bb7 | 3625 | } |
3626 | ||
c1643bb7 | 3627 | |
f412b39a | 3628 | DEFUN (match_ip_route_source_prefix_list, |
c1643bb7 | 3629 | match_ip_route_source_prefix_list_cmd, |
3630 | "match ip route-source prefix-list WORD", | |
3631 | MATCH_STR | |
3632 | IP_STR | |
3633 | "Match advertising source address of route\n" | |
3634 | "Match entries of prefix-lists\n" | |
3635 | "IP prefix-list name\n") | |
3636 | { | |
d62a17ae | 3637 | int idx_word = 4; |
3638 | return bgp_route_match_add(vty, "ip route-source prefix-list", | |
3639 | argv[idx_word]->arg, RMAP_EVENT_PLIST_ADDED); | |
c1643bb7 | 3640 | } |
3641 | ||
4c9bd275 | 3642 | |
c1643bb7 | 3643 | DEFUN (no_match_ip_route_source_prefix_list, |
3644 | no_match_ip_route_source_prefix_list_cmd, | |
4c9bd275 | 3645 | "no match ip route-source prefix-list [WORD]", |
c1643bb7 | 3646 | NO_STR |
3647 | MATCH_STR | |
3648 | IP_STR | |
3649 | "Match advertising source address of route\n" | |
4c9bd275 DW |
3650 | "Match entries of prefix-lists\n" |
3651 | "IP prefix-list name\n") | |
c1643bb7 | 3652 | { |
d62a17ae | 3653 | int idx_word = 5; |
3654 | if (argc <= idx_word) | |
3655 | return bgp_route_match_delete(vty, | |
3656 | "ip route-source prefix-list", | |
3657 | NULL, RMAP_EVENT_PLIST_DELETED); | |
3658 | return bgp_route_match_delete(vty, "ip route-source prefix-list", | |
3659 | argv[idx_word]->arg, | |
3660 | RMAP_EVENT_PLIST_DELETED); | |
c1643bb7 | 3661 | } |
3662 | ||
c1643bb7 | 3663 | |
af291c15 DS |
3664 | DEFUN (match_local_pref, |
3665 | match_local_pref_cmd, | |
6147e2c6 | 3666 | "match local-preference (0-4294967295)", |
af291c15 DS |
3667 | MATCH_STR |
3668 | "Match local-preference of route\n" | |
3669 | "Metric value\n") | |
3670 | { | |
d62a17ae | 3671 | int idx_number = 2; |
3672 | return bgp_route_match_add(vty, "local-preference", | |
3673 | argv[idx_number]->arg, | |
3674 | RMAP_EVENT_MATCH_ADDED); | |
af291c15 DS |
3675 | } |
3676 | ||
4c9bd275 | 3677 | |
af291c15 DS |
3678 | DEFUN (no_match_local_pref, |
3679 | no_match_local_pref_cmd, | |
4c9bd275 | 3680 | "no match local-preference [(0-4294967295)]", |
af291c15 DS |
3681 | NO_STR |
3682 | MATCH_STR | |
4c9bd275 DW |
3683 | "Match local preference of route\n" |
3684 | "Local preference value\n") | |
af291c15 | 3685 | { |
d62a17ae | 3686 | int idx_localpref = 3; |
3687 | if (argc <= idx_localpref) | |
3688 | return bgp_route_match_delete(vty, "local-preference", NULL, | |
3689 | RMAP_EVENT_MATCH_DELETED); | |
3690 | return bgp_route_match_delete(vty, "local-preference", | |
3691 | argv[idx_localpref]->arg, | |
3692 | RMAP_EVENT_MATCH_DELETED); | |
af291c15 DS |
3693 | } |
3694 | ||
af291c15 | 3695 | |
f412b39a | 3696 | DEFUN (match_community, |
718e3744 | 3697 | match_community_cmd, |
0d702986 | 3698 | "match community <(1-99)|(100-500)|WORD> [exact-match]", |
718e3744 | 3699 | MATCH_STR |
3700 | "Match BGP community list\n" | |
3701 | "Community-list number (standard)\n" | |
3702 | "Community-list number (expanded)\n" | |
3703 | "Community-list name\n" | |
3704 | "Do exact matching of communities\n") | |
3705 | { | |
d62a17ae | 3706 | int idx_comm_list = 2; |
3707 | int ret; | |
3708 | char *argstr; | |
718e3744 | 3709 | |
d62a17ae | 3710 | if (argc == 4) { |
3711 | argstr = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, | |
3712 | strlen(argv[idx_comm_list]->arg) | |
3713 | + strlen("exact-match") + 2); | |
718e3744 | 3714 | |
d62a17ae | 3715 | sprintf(argstr, "%s exact-match", argv[idx_comm_list]->arg); |
3716 | } else | |
3717 | argstr = argv[idx_comm_list]->arg; | |
718e3744 | 3718 | |
d62a17ae | 3719 | ret = bgp_route_match_add(vty, "community", argstr, |
3720 | RMAP_EVENT_CLIST_ADDED); | |
718e3744 | 3721 | |
d62a17ae | 3722 | if (argstr != argv[idx_comm_list]->arg) |
3723 | XFREE(MTYPE_ROUTE_MAP_COMPILED, argstr); | |
718e3744 | 3724 | |
d62a17ae | 3725 | return ret; |
718e3744 | 3726 | } |
3727 | ||
3728 | DEFUN (no_match_community, | |
3729 | no_match_community_cmd, | |
4c9bd275 | 3730 | "no match community [<(1-99)|(100-500)|WORD> [exact-match]]", |
718e3744 | 3731 | NO_STR |
3732 | MATCH_STR | |
4c9bd275 DW |
3733 | "Match BGP community list\n" |
3734 | "Community-list number (standard)\n" | |
3735 | "Community-list number (expanded)\n" | |
3736 | "Community-list name\n" | |
3737 | "Do exact matching of communities\n") | |
718e3744 | 3738 | { |
d62a17ae | 3739 | return bgp_route_match_delete(vty, "community", NULL, |
3740 | RMAP_EVENT_CLIST_DELETED); | |
718e3744 | 3741 | } |
3742 | ||
57d187bc JS |
3743 | DEFUN (match_lcommunity, |
3744 | match_lcommunity_cmd, | |
0d702986 | 3745 | "match large-community <(1-99)|(100-500)|WORD>", |
57d187bc JS |
3746 | MATCH_STR |
3747 | "Match BGP large community list\n" | |
3748 | "Large Community-list number (standard)\n" | |
3749 | "Large Community-list number (expanded)\n" | |
3750 | "Large Community-list name\n") | |
3751 | { | |
d62a17ae | 3752 | return bgp_route_match_add(vty, "large-community", argv[2]->arg, |
3753 | RMAP_EVENT_LLIST_ADDED); | |
57d187bc | 3754 | } |
718e3744 | 3755 | |
57d187bc JS |
3756 | DEFUN (no_match_lcommunity, |
3757 | no_match_lcommunity_cmd, | |
52951b63 | 3758 | "no match large-community [<(1-99)|(100-500)|WORD>]", |
57d187bc JS |
3759 | NO_STR |
3760 | MATCH_STR | |
3761 | "Match BGP large community list\n" | |
3762 | "Large Community-list number (standard)\n" | |
3763 | "Large Community-list number (expanded)\n" | |
3764 | "Large Community-list name\n") | |
3765 | { | |
d62a17ae | 3766 | return bgp_route_match_delete(vty, "large-community", NULL, |
3767 | RMAP_EVENT_LLIST_DELETED); | |
57d187bc | 3768 | } |
718e3744 | 3769 | |
f412b39a | 3770 | DEFUN (match_ecommunity, |
73ffb25b | 3771 | match_ecommunity_cmd, |
6147e2c6 | 3772 | "match extcommunity <(1-99)|(100-500)|WORD>", |
73ffb25b | 3773 | MATCH_STR |
3774 | "Match BGP/VPN extended community list\n" | |
3775 | "Extended community-list number (standard)\n" | |
3776 | "Extended community-list number (expanded)\n" | |
3777 | "Extended community-list name\n") | |
3778 | { | |
d62a17ae | 3779 | int idx_comm_list = 2; |
3780 | return bgp_route_match_add(vty, "extcommunity", | |
3781 | argv[idx_comm_list]->arg, | |
3782 | RMAP_EVENT_ECLIST_ADDED); | |
73ffb25b | 3783 | } |
3784 | ||
4c9bd275 | 3785 | |
73ffb25b | 3786 | DEFUN (no_match_ecommunity, |
3787 | no_match_ecommunity_cmd, | |
4c9bd275 | 3788 | "no match extcommunity [<(1-99)|(100-500)|WORD>]", |
73ffb25b | 3789 | NO_STR |
3790 | MATCH_STR | |
4c9bd275 DW |
3791 | "Match BGP/VPN extended community list\n" |
3792 | "Extended community-list number (standard)\n" | |
3793 | "Extended community-list number (expanded)\n" | |
3794 | "Extended community-list name\n") | |
73ffb25b | 3795 | { |
d62a17ae | 3796 | return bgp_route_match_delete(vty, "extcommunity", NULL, |
3797 | RMAP_EVENT_ECLIST_DELETED); | |
73ffb25b | 3798 | } |
3799 | ||
73ffb25b | 3800 | |
718e3744 | 3801 | DEFUN (match_aspath, |
3802 | match_aspath_cmd, | |
3803 | "match as-path WORD", | |
3804 | MATCH_STR | |
3805 | "Match BGP AS path list\n" | |
3806 | "AS path access-list name\n") | |
3807 | { | |
d62a17ae | 3808 | int idx_word = 2; |
3809 | return bgp_route_match_add(vty, "as-path", argv[idx_word]->arg, | |
3810 | RMAP_EVENT_ASLIST_ADDED); | |
718e3744 | 3811 | } |
3812 | ||
4c9bd275 | 3813 | |
718e3744 | 3814 | DEFUN (no_match_aspath, |
3815 | no_match_aspath_cmd, | |
4c9bd275 | 3816 | "no match as-path [WORD]", |
718e3744 | 3817 | NO_STR |
3818 | MATCH_STR | |
4c9bd275 DW |
3819 | "Match BGP AS path list\n" |
3820 | "AS path access-list name\n") | |
718e3744 | 3821 | { |
d62a17ae | 3822 | return bgp_route_match_delete(vty, "as-path", NULL, |
3823 | RMAP_EVENT_ASLIST_DELETED); | |
718e3744 | 3824 | } |
3825 | ||
718e3744 | 3826 | |
3827 | DEFUN (match_origin, | |
3828 | match_origin_cmd, | |
6147e2c6 | 3829 | "match origin <egp|igp|incomplete>", |
718e3744 | 3830 | MATCH_STR |
3831 | "BGP origin code\n" | |
3832 | "remote EGP\n" | |
3833 | "local IGP\n" | |
3834 | "unknown heritage\n") | |
3835 | { | |
d62a17ae | 3836 | int idx_origin = 2; |
3837 | if (strncmp(argv[idx_origin]->arg, "igp", 2) == 0) | |
3838 | return bgp_route_match_add(vty, "origin", "igp", | |
3839 | RMAP_EVENT_MATCH_ADDED); | |
3840 | if (strncmp(argv[idx_origin]->arg, "egp", 1) == 0) | |
3841 | return bgp_route_match_add(vty, "origin", "egp", | |
3842 | RMAP_EVENT_MATCH_ADDED); | |
3843 | if (strncmp(argv[idx_origin]->arg, "incomplete", 2) == 0) | |
3844 | return bgp_route_match_add(vty, "origin", "incomplete", | |
3845 | RMAP_EVENT_MATCH_ADDED); | |
718e3744 | 3846 | |
d62a17ae | 3847 | vty_out(vty, "%% Invalid match origin type\n"); |
3848 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 3849 | } |
3850 | ||
4c9bd275 | 3851 | |
718e3744 | 3852 | DEFUN (no_match_origin, |
3853 | no_match_origin_cmd, | |
4c9bd275 | 3854 | "no match origin [<egp|igp|incomplete>]", |
718e3744 | 3855 | NO_STR |
3856 | MATCH_STR | |
4c9bd275 DW |
3857 | "BGP origin code\n" |
3858 | "remote EGP\n" | |
3859 | "local IGP\n" | |
3860 | "unknown heritage\n") | |
718e3744 | 3861 | { |
d62a17ae | 3862 | return bgp_route_match_delete(vty, "origin", NULL, |
3863 | RMAP_EVENT_MATCH_DELETED); | |
718e3744 | 3864 | } |
3865 | ||
af5cd0a5 | 3866 | DEFUN (set_ip_nexthop_peer, |
3867 | set_ip_nexthop_peer_cmd, | |
89602edb QY |
3868 | "[no] set ip next-hop peer-address", |
3869 | NO_STR | |
af5cd0a5 | 3870 | SET_STR |
3871 | IP_STR | |
3872 | "Next hop address\n" | |
3873 | "Use peer address (for BGP only)\n") | |
3874 | { | |
89602edb | 3875 | int (*func)(struct vty *, struct route_map_index *, const char *, |
a4d82a8a PZ |
3876 | const char *) = strmatch(argv[0]->text, "no") |
3877 | ? generic_set_delete | |
3878 | : generic_set_add; | |
89602edb QY |
3879 | |
3880 | return func(vty, VTY_GET_CONTEXT(route_map_index), "ip next-hop", | |
3881 | "peer-address"); | |
af5cd0a5 | 3882 | } |
3883 | ||
316e074d DS |
3884 | DEFUN (set_ip_nexthop_unchanged, |
3885 | set_ip_nexthop_unchanged_cmd, | |
cca30ba8 QY |
3886 | "[no] set ip next-hop unchanged", |
3887 | NO_STR | |
316e074d DS |
3888 | SET_STR |
3889 | IP_STR | |
3890 | "Next hop address\n" | |
3891 | "Don't modify existing Next hop address\n") | |
3892 | { | |
cca30ba8 | 3893 | int (*func)(struct vty *, struct route_map_index *, const char *, |
a4d82a8a PZ |
3894 | const char *) = strmatch(argv[0]->text, "no") |
3895 | ? generic_set_delete | |
3896 | : generic_set_add; | |
cca30ba8 QY |
3897 | |
3898 | return func(vty, VTY_GET_CONTEXT(route_map_index), "ip next-hop", | |
3899 | "unchanged"); | |
718e3744 | 3900 | } |
3901 | ||
718e3744 | 3902 | |
3903 | DEFUN (set_local_pref, | |
3904 | set_local_pref_cmd, | |
6147e2c6 | 3905 | "set local-preference (0-4294967295)", |
718e3744 | 3906 | SET_STR |
3907 | "BGP local preference path attribute\n" | |
3908 | "Preference value\n") | |
3909 | { | |
d62a17ae | 3910 | int idx_number = 2; |
3911 | return generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), | |
3912 | "local-preference", argv[idx_number]->arg); | |
718e3744 | 3913 | } |
3914 | ||
4c9bd275 | 3915 | |
718e3744 | 3916 | DEFUN (no_set_local_pref, |
3917 | no_set_local_pref_cmd, | |
4c9bd275 | 3918 | "no set local-preference [(0-4294967295)]", |
718e3744 | 3919 | NO_STR |
3920 | SET_STR | |
4c9bd275 DW |
3921 | "BGP local preference path attribute\n" |
3922 | "Preference value\n") | |
718e3744 | 3923 | { |
d62a17ae | 3924 | int idx_localpref = 3; |
3925 | if (argc <= idx_localpref) | |
3926 | return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), | |
3927 | "local-preference", NULL); | |
3928 | return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), | |
3929 | "local-preference", argv[idx_localpref]->arg); | |
718e3744 | 3930 | } |
3931 | ||
718e3744 | 3932 | |
3933 | DEFUN (set_weight, | |
3934 | set_weight_cmd, | |
6147e2c6 | 3935 | "set weight (0-4294967295)", |
718e3744 | 3936 | SET_STR |
3937 | "BGP weight for routing table\n" | |
3938 | "Weight value\n") | |
3939 | { | |
d62a17ae | 3940 | int idx_number = 2; |
3941 | return generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), "weight", | |
3942 | argv[idx_number]->arg); | |
718e3744 | 3943 | } |
3944 | ||
4c9bd275 | 3945 | |
718e3744 | 3946 | DEFUN (no_set_weight, |
3947 | no_set_weight_cmd, | |
4c9bd275 | 3948 | "no set weight [(0-4294967295)]", |
718e3744 | 3949 | NO_STR |
3950 | SET_STR | |
4c9bd275 DW |
3951 | "BGP weight for routing table\n" |
3952 | "Weight value\n") | |
718e3744 | 3953 | { |
d62a17ae | 3954 | int idx_weight = 3; |
3955 | if (argc <= idx_weight) | |
3956 | return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), | |
3957 | "weight", NULL); | |
3958 | return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), | |
3959 | "weight", argv[idx_weight]->arg); | |
718e3744 | 3960 | } |
3961 | ||
d990e384 DS |
3962 | DEFUN (set_label_index, |
3963 | set_label_index_cmd, | |
8b81993e | 3964 | "set label-index (0-1048560)", |
d990e384 DS |
3965 | SET_STR |
3966 | "Label index to associate with the prefix\n" | |
3967 | "Label index value\n") | |
3968 | { | |
d62a17ae | 3969 | int idx_number = 2; |
3970 | return generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), | |
3971 | "label-index", argv[idx_number]->arg); | |
d990e384 DS |
3972 | } |
3973 | ||
3974 | DEFUN (no_set_label_index, | |
3975 | no_set_label_index_cmd, | |
8b81993e | 3976 | "no set label-index [(0-1048560)]", |
d990e384 DS |
3977 | NO_STR |
3978 | SET_STR | |
3979 | "Label index to associate with the prefix\n" | |
3980 | "Label index value\n") | |
3981 | { | |
d62a17ae | 3982 | int idx_label_index = 3; |
3983 | if (argc <= idx_label_index) | |
3984 | return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), | |
3985 | "label-index", NULL); | |
3986 | return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), | |
3987 | "label-index", argv[idx_label_index]->arg); | |
d990e384 | 3988 | } |
718e3744 | 3989 | |
12dcf78e QY |
3990 | DEFUN (set_aspath_prepend_asn, |
3991 | set_aspath_prepend_asn_cmd, | |
3992 | "set as-path prepend (1-4294967295)...", | |
718e3744 | 3993 | SET_STR |
841f7a57 | 3994 | "Transform BGP AS_PATH attribute\n" |
718e3744 | 3995 | "Prepend to the as-path\n" |
12dcf78e | 3996 | "AS number\n") |
718e3744 | 3997 | { |
d62a17ae | 3998 | int idx_asn = 3; |
3999 | int ret; | |
4000 | char *str; | |
718e3744 | 4001 | |
d62a17ae | 4002 | str = argv_concat(argv, argc, idx_asn); |
4003 | ret = generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), | |
4004 | "as-path prepend", str); | |
4005 | XFREE(MTYPE_TMP, str); | |
718e3744 | 4006 | |
d62a17ae | 4007 | return ret; |
718e3744 | 4008 | } |
4009 | ||
12dcf78e QY |
4010 | DEFUN (set_aspath_prepend_lastas, |
4011 | set_aspath_prepend_lastas_cmd, | |
b6ab2929 | 4012 | "set as-path prepend last-as (1-10)", |
12dcf78e QY |
4013 | SET_STR |
4014 | "Transform BGP AS_PATH attribute\n" | |
4015 | "Prepend to the as-path\n" | |
4016 | "Use the peer's AS-number\n" | |
b6ab2929 | 4017 | "Number of times to insert\n") |
12dcf78e | 4018 | { |
d62a17ae | 4019 | return set_aspath_prepend_asn(self, vty, argc, argv); |
12dcf78e | 4020 | } |
bc3dd427 | 4021 | |
718e3744 | 4022 | DEFUN (no_set_aspath_prepend, |
4023 | no_set_aspath_prepend_cmd, | |
a4b2b610 | 4024 | "no set as-path prepend [(1-4294967295)]", |
718e3744 | 4025 | NO_STR |
4026 | SET_STR | |
841f7a57 | 4027 | "Transform BGP AS_PATH attribute\n" |
a4b2b610 DW |
4028 | "Prepend to the as-path\n" |
4029 | "AS number\n") | |
718e3744 | 4030 | { |
d62a17ae | 4031 | int idx_asn = 4; |
4032 | int ret; | |
4033 | char *str; | |
a7f93f3e | 4034 | |
d62a17ae | 4035 | str = argv_concat(argv, argc, idx_asn); |
4036 | ret = generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), | |
4037 | "as-path prepend", str); | |
4038 | XFREE(MTYPE_TMP, str); | |
4039 | return ret; | |
718e3744 | 4040 | } |
4041 | ||
718e3744 | 4042 | |
841f7a57 DO |
4043 | DEFUN (set_aspath_exclude, |
4044 | set_aspath_exclude_cmd, | |
a4b2b610 | 4045 | "set as-path exclude (1-4294967295)...", |
841f7a57 DO |
4046 | SET_STR |
4047 | "Transform BGP AS-path attribute\n" | |
4048 | "Exclude from the as-path\n" | |
4049 | "AS number\n") | |
4050 | { | |
d62a17ae | 4051 | int idx_asn = 3; |
4052 | int ret; | |
4053 | char *str; | |
841f7a57 | 4054 | |
d62a17ae | 4055 | str = argv_concat(argv, argc, idx_asn); |
4056 | ret = generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), | |
4057 | "as-path exclude", str); | |
4058 | XFREE(MTYPE_TMP, str); | |
4059 | return ret; | |
841f7a57 DO |
4060 | } |
4061 | ||
4062 | DEFUN (no_set_aspath_exclude, | |
4063 | no_set_aspath_exclude_cmd, | |
a4b2b610 | 4064 | "no set as-path exclude (1-4294967295)...", |
841f7a57 DO |
4065 | NO_STR |
4066 | SET_STR | |
4067 | "Transform BGP AS_PATH attribute\n" | |
a4b2b610 DW |
4068 | "Exclude from the as-path\n" |
4069 | "AS number\n") | |
841f7a57 | 4070 | { |
d62a17ae | 4071 | int idx_asn = 4; |
4072 | int ret; | |
4073 | char *str; | |
841f7a57 | 4074 | |
d62a17ae | 4075 | str = argv_concat(argv, argc, idx_asn); |
4076 | ret = generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), | |
4077 | "as-path exclude", str); | |
4078 | XFREE(MTYPE_TMP, str); | |
4079 | return ret; | |
841f7a57 DO |
4080 | } |
4081 | ||
841f7a57 | 4082 | |
718e3744 | 4083 | DEFUN (set_community, |
4084 | set_community_cmd, | |
e961923c | 4085 | "set community AA:NN...", |
718e3744 | 4086 | SET_STR |
4087 | "BGP community attribute\n" | |
859d388e | 4088 | COMMUNITY_VAL_STR) |
718e3744 | 4089 | { |
d62a17ae | 4090 | int idx_aa_nn = 2; |
4091 | int i; | |
4092 | int first = 0; | |
4093 | int additive = 0; | |
4094 | struct buffer *b; | |
4095 | struct community *com = NULL; | |
4096 | char *str; | |
4097 | char *argstr; | |
4098 | int ret; | |
4099 | ||
4100 | b = buffer_new(1024); | |
4101 | ||
4102 | for (i = idx_aa_nn; i < argc; i++) { | |
4103 | if (strncmp(argv[i]->arg, "additive", strlen(argv[i]->arg)) | |
4104 | == 0) { | |
4105 | additive = 1; | |
4106 | continue; | |
4107 | } | |
4108 | ||
4109 | if (first) | |
4110 | buffer_putc(b, ' '); | |
4111 | else | |
4112 | first = 1; | |
4113 | ||
4114 | if (strncmp(argv[i]->arg, "internet", strlen(argv[i]->arg)) | |
4115 | == 0) { | |
4116 | buffer_putstr(b, "internet"); | |
4117 | continue; | |
4118 | } | |
4119 | if (strncmp(argv[i]->arg, "local-AS", strlen(argv[i]->arg)) | |
4120 | == 0) { | |
4121 | buffer_putstr(b, "local-AS"); | |
4122 | continue; | |
4123 | } | |
4124 | if (strncmp(argv[i]->arg, "no-a", strlen("no-a")) == 0 | |
4125 | && strncmp(argv[i]->arg, "no-advertise", | |
4126 | strlen(argv[i]->arg)) | |
4127 | == 0) { | |
4128 | buffer_putstr(b, "no-advertise"); | |
4129 | continue; | |
4130 | } | |
4131 | if (strncmp(argv[i]->arg, "no-e", strlen("no-e")) == 0 | |
4132 | && strncmp(argv[i]->arg, "no-export", strlen(argv[i]->arg)) | |
4133 | == 0) { | |
4134 | buffer_putstr(b, "no-export"); | |
4135 | continue; | |
4136 | } | |
a4d82a8a PZ |
4137 | if (strncmp(argv[i]->arg, "graceful-shutdown", |
4138 | strlen(argv[i]->arg)) | |
7f323236 DW |
4139 | == 0) { |
4140 | buffer_putstr(b, "graceful-shutdown"); | |
4141 | continue; | |
4142 | } | |
d62a17ae | 4143 | buffer_putstr(b, argv[i]->arg); |
4144 | } | |
4145 | buffer_putc(b, '\0'); | |
4146 | ||
4147 | /* Fetch result string then compile it to communities attribute. */ | |
4148 | str = buffer_getstr(b); | |
4149 | buffer_free(b); | |
4150 | ||
4151 | if (str) { | |
4152 | com = community_str2com(str); | |
4153 | XFREE(MTYPE_TMP, str); | |
4154 | } | |
4155 | ||
4156 | /* Can't compile user input into communities attribute. */ | |
4157 | if (!com) { | |
4158 | vty_out(vty, "%% Malformed communities attribute\n"); | |
4159 | return CMD_WARNING_CONFIG_FAILED; | |
4160 | } | |
4161 | ||
4162 | /* Set communites attribute string. */ | |
a69ea8ae | 4163 | str = community_str(com, false); |
d62a17ae | 4164 | |
4165 | if (additive) { | |
4166 | argstr = XCALLOC(MTYPE_TMP, | |
4167 | strlen(str) + strlen(" additive") + 1); | |
4168 | strcpy(argstr, str); | |
4169 | strcpy(argstr + strlen(str), " additive"); | |
4170 | ret = generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), | |
4171 | "community", argstr); | |
4172 | XFREE(MTYPE_TMP, argstr); | |
4173 | } else | |
4174 | ret = generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), | |
4175 | "community", str); | |
4176 | ||
3c1f53de | 4177 | community_free(&com); |
d62a17ae | 4178 | |
4179 | return ret; | |
718e3744 | 4180 | } |
4181 | ||
4182 | DEFUN (set_community_none, | |
4183 | set_community_none_cmd, | |
4184 | "set community none", | |
4185 | SET_STR | |
4186 | "BGP community attribute\n" | |
4187 | "No community attribute\n") | |
4188 | { | |
d62a17ae | 4189 | return generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), |
4190 | "community", "none"); | |
718e3744 | 4191 | } |
4192 | ||
4193 | DEFUN (no_set_community, | |
4194 | no_set_community_cmd, | |
a4b2b610 | 4195 | "no set community AA:NN...", |
718e3744 | 4196 | NO_STR |
4197 | SET_STR | |
d7fa34c1 QY |
4198 | "BGP community attribute\n" |
4199 | COMMUNITY_VAL_STR) | |
718e3744 | 4200 | { |
d62a17ae | 4201 | return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), |
4202 | "community", NULL); | |
718e3744 | 4203 | } |
4204 | ||
718e3744 | 4205 | |
718e3744 | 4206 | DEFUN (set_community_delete, |
4207 | set_community_delete_cmd, | |
6147e2c6 | 4208 | "set comm-list <(1-99)|(100-500)|WORD> delete", |
718e3744 | 4209 | SET_STR |
4210 | "set BGP community list (for deletion)\n" | |
4211 | "Community-list number (standard)\n" | |
5e3edbf5 | 4212 | "Community-list number (expanded)\n" |
718e3744 | 4213 | "Community-list name\n" |
4214 | "Delete matching communities\n") | |
4215 | { | |
d62a17ae | 4216 | int idx_comm_list = 2; |
4217 | char *str; | |
718e3744 | 4218 | |
d62a17ae | 4219 | str = XCALLOC(MTYPE_TMP, |
4220 | strlen(argv[idx_comm_list]->arg) + strlen(" delete") + 1); | |
4221 | strcpy(str, argv[idx_comm_list]->arg); | |
4222 | strcpy(str + strlen(argv[idx_comm_list]->arg), " delete"); | |
718e3744 | 4223 | |
d62a17ae | 4224 | generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), "comm-list", |
4225 | str); | |
718e3744 | 4226 | |
d62a17ae | 4227 | XFREE(MTYPE_TMP, str); |
4228 | return CMD_SUCCESS; | |
718e3744 | 4229 | } |
4230 | ||
4231 | DEFUN (no_set_community_delete, | |
4232 | no_set_community_delete_cmd, | |
a4b2b610 | 4233 | "no set comm-list [<(1-99)|(100-500)|WORD> delete]", |
718e3744 | 4234 | NO_STR |
4235 | SET_STR | |
d7fa34c1 QY |
4236 | "set BGP community list (for deletion)\n" |
4237 | "Community-list number (standard)\n" | |
4238 | "Community-list number (expanded)\n" | |
4239 | "Community-list name\n" | |
4240 | "Delete matching communities\n") | |
718e3744 | 4241 | { |
d62a17ae | 4242 | return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), |
4243 | "comm-list", NULL); | |
718e3744 | 4244 | } |
4245 | ||
57d187bc JS |
4246 | DEFUN (set_lcommunity, |
4247 | set_lcommunity_cmd, | |
4248 | "set large-community AA:BB:CC...", | |
4249 | SET_STR | |
4250 | "BGP large community attribute\n" | |
4251 | "Large Community number in aa:bb:cc format or additive\n") | |
4252 | { | |
d62a17ae | 4253 | int ret; |
4254 | char *str; | |
57d187bc | 4255 | |
d62a17ae | 4256 | str = argv_concat(argv, argc, 2); |
4257 | ret = generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), | |
4258 | "large-community", str); | |
4259 | XFREE(MTYPE_TMP, str); | |
57d187bc | 4260 | |
d62a17ae | 4261 | return ret; |
57d187bc JS |
4262 | } |
4263 | ||
4264 | DEFUN (set_lcommunity_none, | |
4265 | set_lcommunity_none_cmd, | |
4266 | "set large-community none", | |
4267 | SET_STR | |
4268 | "BGP large community attribute\n" | |
4269 | "No large community attribute\n") | |
4270 | { | |
d62a17ae | 4271 | return generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), |
4272 | "large-community", "none"); | |
57d187bc JS |
4273 | } |
4274 | ||
4275 | DEFUN (no_set_lcommunity, | |
4276 | no_set_lcommunity_cmd, | |
52951b63 | 4277 | "no set large-community none", |
57d187bc JS |
4278 | NO_STR |
4279 | SET_STR | |
4280 | "BGP large community attribute\n" | |
52951b63 | 4281 | "No community attribute\n") |
57d187bc | 4282 | { |
d62a17ae | 4283 | return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), |
4284 | "large-community", NULL); | |
57d187bc JS |
4285 | } |
4286 | ||
52951b63 DS |
4287 | DEFUN (no_set_lcommunity1, |
4288 | no_set_lcommunity1_cmd, | |
4289 | "no set large-community AA:BB:CC...", | |
4290 | NO_STR | |
4291 | SET_STR | |
4292 | "BGP large community attribute\n" | |
4293 | "Large community in AA:BB:CC... format or additive\n") | |
4294 | { | |
d62a17ae | 4295 | return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), |
4296 | "large-community", NULL); | |
52951b63 | 4297 | } |
57d187bc JS |
4298 | |
4299 | DEFUN (set_lcommunity_delete, | |
4300 | set_lcommunity_delete_cmd, | |
4301 | "set large-comm-list <(1-99)|(100-500)|WORD> delete", | |
4302 | SET_STR | |
4303 | "set BGP large community list (for deletion)\n" | |
4304 | "Large Community-list number (standard)\n" | |
4305 | "Large Communitly-list number (expanded)\n" | |
4306 | "Large Community-list name\n" | |
4307 | "Delete matching large communities\n") | |
4308 | { | |
d62a17ae | 4309 | char *str; |
57d187bc | 4310 | |
d62a17ae | 4311 | str = XCALLOC(MTYPE_TMP, strlen(argv[2]->arg) + strlen(" delete") + 1); |
4312 | strcpy(str, argv[2]->arg); | |
4313 | strcpy(str + strlen(argv[2]->arg), " delete"); | |
57d187bc | 4314 | |
d62a17ae | 4315 | generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), |
4316 | "large-comm-list", str); | |
57d187bc | 4317 | |
d62a17ae | 4318 | XFREE(MTYPE_TMP, str); |
4319 | return CMD_SUCCESS; | |
57d187bc JS |
4320 | } |
4321 | ||
4322 | DEFUN (no_set_lcommunity_delete, | |
4323 | no_set_lcommunity_delete_cmd, | |
db4f7086 | 4324 | "no set large-comm-list <(1-99)|(100-500)|WORD> [delete]", |
57d187bc JS |
4325 | NO_STR |
4326 | SET_STR | |
4327 | "set BGP large community list (for deletion)\n" | |
4328 | "Large Community-list number (standard)\n" | |
4329 | "Large Communitly-list number (expanded)\n" | |
4330 | "Large Community-list name\n" | |
4331 | "Delete matching large communities\n") | |
4332 | { | |
d62a17ae | 4333 | return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), |
4334 | "large-comm-list", NULL); | |
57d187bc | 4335 | } |
718e3744 | 4336 | |
4337 | DEFUN (set_ecommunity_rt, | |
4338 | set_ecommunity_rt_cmd, | |
d114b977 | 4339 | "set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...", |
718e3744 | 4340 | SET_STR |
4341 | "BGP extended community attribute\n" | |
e6b6a564 | 4342 | "Route Target extended community\n" |
718e3744 | 4343 | "VPN extended community\n") |
4344 | { | |
d62a17ae | 4345 | int idx_asn_nn = 3; |
4346 | int ret; | |
4347 | char *str; | |
718e3744 | 4348 | |
d62a17ae | 4349 | str = argv_concat(argv, argc, idx_asn_nn); |
4350 | ret = generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), | |
4351 | "extcommunity rt", str); | |
4352 | XFREE(MTYPE_TMP, str); | |
718e3744 | 4353 | |
d62a17ae | 4354 | return ret; |
718e3744 | 4355 | } |
4356 | ||
4357 | DEFUN (no_set_ecommunity_rt, | |
4358 | no_set_ecommunity_rt_cmd, | |
d114b977 | 4359 | "no set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...", |
718e3744 | 4360 | NO_STR |
4361 | SET_STR | |
4362 | "BGP extended community attribute\n" | |
3a2d747c QY |
4363 | "Route Target extended community\n" |
4364 | "VPN extended community\n") | |
718e3744 | 4365 | { |
d62a17ae | 4366 | return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), |
4367 | "extcommunity rt", NULL); | |
718e3744 | 4368 | } |
4369 | ||
718e3744 | 4370 | |
4371 | DEFUN (set_ecommunity_soo, | |
4372 | set_ecommunity_soo_cmd, | |
d114b977 | 4373 | "set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...", |
718e3744 | 4374 | SET_STR |
4375 | "BGP extended community attribute\n" | |
4376 | "Site-of-Origin extended community\n" | |
4377 | "VPN extended community\n") | |
4378 | { | |
d62a17ae | 4379 | int idx_asn_nn = 3; |
4380 | int ret; | |
4381 | char *str; | |
718e3744 | 4382 | |
d62a17ae | 4383 | str = argv_concat(argv, argc, idx_asn_nn); |
4384 | ret = generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), | |
4385 | "extcommunity soo", str); | |
4386 | XFREE(MTYPE_TMP, str); | |
4387 | return ret; | |
718e3744 | 4388 | } |
4389 | ||
a4b2b610 | 4390 | |
718e3744 | 4391 | DEFUN (no_set_ecommunity_soo, |
4392 | no_set_ecommunity_soo_cmd, | |
d114b977 | 4393 | "no set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...", |
718e3744 | 4394 | NO_STR |
4395 | SET_STR | |
4396 | "BGP extended community attribute\n" | |
3a2d747c QY |
4397 | "Site-of-Origin extended community\n" |
4398 | "VPN extended community\n") | |
718e3744 | 4399 | { |
d62a17ae | 4400 | return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), |
4401 | "extcommunity soo", NULL); | |
718e3744 | 4402 | } |
4403 | ||
718e3744 | 4404 | |
4405 | DEFUN (set_origin, | |
4406 | set_origin_cmd, | |
6147e2c6 | 4407 | "set origin <egp|igp|incomplete>", |
718e3744 | 4408 | SET_STR |
4409 | "BGP origin code\n" | |
4410 | "remote EGP\n" | |
4411 | "local IGP\n" | |
4412 | "unknown heritage\n") | |
4413 | { | |
d62a17ae | 4414 | int idx_origin = 2; |
4415 | if (strncmp(argv[idx_origin]->arg, "igp", 2) == 0) | |
4416 | return generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), | |
4417 | "origin", "igp"); | |
4418 | if (strncmp(argv[idx_origin]->arg, "egp", 1) == 0) | |
4419 | return generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), | |
4420 | "origin", "egp"); | |
4421 | if (strncmp(argv[idx_origin]->arg, "incomplete", 2) == 0) | |
4422 | return generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), | |
4423 | "origin", "incomplete"); | |
718e3744 | 4424 | |
d62a17ae | 4425 | vty_out(vty, "%% Invalid set origin type\n"); |
4426 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 4427 | } |
4428 | ||
a4b2b610 | 4429 | |
718e3744 | 4430 | DEFUN (no_set_origin, |
4431 | no_set_origin_cmd, | |
a4b2b610 | 4432 | "no set origin [<egp|igp|incomplete>]", |
718e3744 | 4433 | NO_STR |
4434 | SET_STR | |
d7fa34c1 QY |
4435 | "BGP origin code\n" |
4436 | "remote EGP\n" | |
4437 | "local IGP\n" | |
4438 | "unknown heritage\n") | |
718e3744 | 4439 | { |
d62a17ae | 4440 | return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), |
4441 | "origin", NULL); | |
718e3744 | 4442 | } |
4443 | ||
718e3744 | 4444 | |
4445 | DEFUN (set_atomic_aggregate, | |
4446 | set_atomic_aggregate_cmd, | |
4447 | "set atomic-aggregate", | |
4448 | SET_STR | |
4449 | "BGP atomic aggregate attribute\n" ) | |
4450 | { | |
d62a17ae | 4451 | return generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), |
4452 | "atomic-aggregate", NULL); | |
718e3744 | 4453 | } |
4454 | ||
4455 | DEFUN (no_set_atomic_aggregate, | |
4456 | no_set_atomic_aggregate_cmd, | |
4457 | "no set atomic-aggregate", | |
4458 | NO_STR | |
4459 | SET_STR | |
4460 | "BGP atomic aggregate attribute\n" ) | |
4461 | { | |
d62a17ae | 4462 | return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), |
4463 | "atomic-aggregate", NULL); | |
718e3744 | 4464 | } |
4465 | ||
4466 | DEFUN (set_aggregator_as, | |
4467 | set_aggregator_as_cmd, | |
9ccf14f7 | 4468 | "set aggregator as (1-4294967295) A.B.C.D", |
718e3744 | 4469 | SET_STR |
4470 | "BGP aggregator attribute\n" | |
4471 | "AS number of aggregator\n" | |
4472 | "AS number\n" | |
4473 | "IP address of aggregator\n") | |
4474 | { | |
d62a17ae | 4475 | int idx_number = 3; |
4476 | int idx_ipv4 = 4; | |
4477 | int ret; | |
4478 | struct in_addr address; | |
4479 | char *argstr; | |
e52702f2 | 4480 | |
d62a17ae | 4481 | ret = inet_aton(argv[idx_ipv4]->arg, &address); |
4482 | if (ret == 0) { | |
4483 | vty_out(vty, "Aggregator IP address is invalid\n"); | |
4484 | return CMD_WARNING_CONFIG_FAILED; | |
4485 | } | |
718e3744 | 4486 | |
d62a17ae | 4487 | argstr = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, |
4488 | strlen(argv[idx_number]->arg) | |
4489 | + strlen(argv[idx_ipv4]->arg) + 2); | |
718e3744 | 4490 | |
d62a17ae | 4491 | sprintf(argstr, "%s %s", argv[idx_number]->arg, argv[idx_ipv4]->arg); |
718e3744 | 4492 | |
d62a17ae | 4493 | ret = generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), |
4494 | "aggregator as", argstr); | |
718e3744 | 4495 | |
d62a17ae | 4496 | XFREE(MTYPE_ROUTE_MAP_COMPILED, argstr); |
718e3744 | 4497 | |
d62a17ae | 4498 | return ret; |
718e3744 | 4499 | } |
4500 | ||
a4b2b610 | 4501 | |
718e3744 | 4502 | DEFUN (no_set_aggregator_as, |
4503 | no_set_aggregator_as_cmd, | |
a4b2b610 | 4504 | "no set aggregator as [(1-4294967295) A.B.C.D]", |
718e3744 | 4505 | NO_STR |
4506 | SET_STR | |
4507 | "BGP aggregator attribute\n" | |
a4b2b610 DW |
4508 | "AS number of aggregator\n" |
4509 | "AS number\n" | |
4510 | "IP address of aggregator\n") | |
718e3744 | 4511 | { |
d62a17ae | 4512 | int idx_asn = 4; |
4513 | int idx_ip = 5; | |
4514 | int ret; | |
4515 | struct in_addr address; | |
4516 | char *argstr; | |
718e3744 | 4517 | |
d62a17ae | 4518 | if (argc <= idx_asn) |
4519 | return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), | |
4520 | "aggregator as", NULL); | |
e52702f2 | 4521 | |
d62a17ae | 4522 | ret = inet_aton(argv[idx_ip]->arg, &address); |
4523 | if (ret == 0) { | |
4524 | vty_out(vty, "Aggregator IP address is invalid\n"); | |
4525 | return CMD_WARNING_CONFIG_FAILED; | |
4526 | } | |
718e3744 | 4527 | |
d62a17ae | 4528 | argstr = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, |
4529 | strlen(argv[idx_asn]->arg) + strlen(argv[idx_ip]->arg) | |
4530 | + 2); | |
718e3744 | 4531 | |
d62a17ae | 4532 | sprintf(argstr, "%s %s", argv[idx_asn]->arg, argv[idx_ip]->arg); |
718e3744 | 4533 | |
d62a17ae | 4534 | ret = generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), |
4535 | "aggregator as", argstr); | |
718e3744 | 4536 | |
d62a17ae | 4537 | XFREE(MTYPE_ROUTE_MAP_COMPILED, argstr); |
718e3744 | 4538 | |
d62a17ae | 4539 | return ret; |
718e3744 | 4540 | } |
4541 | ||
f412b39a | 4542 | DEFUN (match_ipv6_next_hop, |
718e3744 | 4543 | match_ipv6_next_hop_cmd, |
4544 | "match ipv6 next-hop X:X::X:X", | |
4545 | MATCH_STR | |
4546 | IPV6_STR | |
4547 | "Match IPv6 next-hop address of route\n" | |
4548 | "IPv6 address of next hop\n") | |
4549 | { | |
d62a17ae | 4550 | int idx_ipv6 = 3; |
4551 | return bgp_route_match_add(vty, "ipv6 next-hop", argv[idx_ipv6]->arg, | |
4552 | RMAP_EVENT_MATCH_ADDED); | |
718e3744 | 4553 | } |
4554 | ||
4555 | DEFUN (no_match_ipv6_next_hop, | |
4556 | no_match_ipv6_next_hop_cmd, | |
4557 | "no match ipv6 next-hop X:X::X:X", | |
4558 | NO_STR | |
4559 | MATCH_STR | |
4560 | IPV6_STR | |
4561 | "Match IPv6 next-hop address of route\n" | |
4562 | "IPv6 address of next hop\n") | |
4563 | { | |
d62a17ae | 4564 | int idx_ipv6 = 4; |
4565 | return bgp_route_match_delete(vty, "ipv6 next-hop", argv[idx_ipv6]->arg, | |
4566 | RMAP_EVENT_MATCH_DELETED); | |
718e3744 | 4567 | } |
4568 | ||
718e3744 | 4569 | |
90916ac2 DS |
4570 | DEFUN (set_ipv6_nexthop_peer, |
4571 | set_ipv6_nexthop_peer_cmd, | |
4572 | "set ipv6 next-hop peer-address", | |
4573 | SET_STR | |
4574 | IPV6_STR | |
4575 | "Next hop address\n" | |
4576 | "Use peer address (for BGP only)\n") | |
4577 | { | |
d62a17ae | 4578 | return generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), |
4579 | "ipv6 next-hop peer-address", NULL); | |
90916ac2 DS |
4580 | } |
4581 | ||
4582 | DEFUN (no_set_ipv6_nexthop_peer, | |
4583 | no_set_ipv6_nexthop_peer_cmd, | |
4584 | "no set ipv6 next-hop peer-address", | |
4585 | NO_STR | |
4586 | SET_STR | |
4587 | IPV6_STR | |
4588 | "IPv6 next-hop address\n" | |
161995ea | 4589 | "Use peer address (for BGP only)\n") |
90916ac2 | 4590 | { |
d62a17ae | 4591 | return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), |
4592 | "ipv6 next-hop peer-address", NULL); | |
90916ac2 DS |
4593 | } |
4594 | ||
161995ea DS |
4595 | DEFUN (set_ipv6_nexthop_prefer_global, |
4596 | set_ipv6_nexthop_prefer_global_cmd, | |
4597 | "set ipv6 next-hop prefer-global", | |
4598 | SET_STR | |
4599 | IPV6_STR | |
4600 | "IPv6 next-hop address\n" | |
4601 | "Prefer global over link-local if both exist\n") | |
4602 | { | |
d62a17ae | 4603 | return generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), |
4604 | "ipv6 next-hop prefer-global", NULL); | |
4605 | ; | |
161995ea DS |
4606 | } |
4607 | ||
4608 | DEFUN (no_set_ipv6_nexthop_prefer_global, | |
4609 | no_set_ipv6_nexthop_prefer_global_cmd, | |
4610 | "no set ipv6 next-hop prefer-global", | |
4611 | NO_STR | |
4612 | SET_STR | |
4613 | IPV6_STR | |
4614 | "IPv6 next-hop address\n" | |
4615 | "Prefer global over link-local if both exist\n") | |
4616 | { | |
d62a17ae | 4617 | return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), |
4618 | "ipv6 next-hop prefer-global", NULL); | |
161995ea DS |
4619 | } |
4620 | ||
718e3744 | 4621 | DEFUN (set_ipv6_nexthop_global, |
4622 | set_ipv6_nexthop_global_cmd, | |
4623 | "set ipv6 next-hop global X:X::X:X", | |
4624 | SET_STR | |
4625 | IPV6_STR | |
4626 | "IPv6 next-hop address\n" | |
4627 | "IPv6 global address\n" | |
4628 | "IPv6 address of next hop\n") | |
4629 | { | |
d62a17ae | 4630 | int idx_ipv6 = 4; |
4631 | struct in6_addr addr; | |
4632 | int ret; | |
bf8b3d27 | 4633 | |
d62a17ae | 4634 | ret = inet_pton(AF_INET6, argv[idx_ipv6]->arg, &addr); |
4635 | if (!ret) { | |
4636 | vty_out(vty, "%% Malformed nexthop address\n"); | |
4637 | return CMD_WARNING_CONFIG_FAILED; | |
4638 | } | |
4639 | if (IN6_IS_ADDR_UNSPECIFIED(&addr) || IN6_IS_ADDR_LOOPBACK(&addr) | |
4640 | || IN6_IS_ADDR_MULTICAST(&addr) || IN6_IS_ADDR_LINKLOCAL(&addr)) { | |
4641 | vty_out(vty, "%% Invalid global nexthop address\n"); | |
4642 | return CMD_WARNING_CONFIG_FAILED; | |
4643 | } | |
bf8b3d27 | 4644 | |
d62a17ae | 4645 | return generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), |
4646 | "ipv6 next-hop global", argv[idx_ipv6]->arg); | |
718e3744 | 4647 | } |
4648 | ||
a4b2b610 | 4649 | |
718e3744 | 4650 | DEFUN (no_set_ipv6_nexthop_global, |
4651 | no_set_ipv6_nexthop_global_cmd, | |
a4b2b610 | 4652 | "no set ipv6 next-hop global X:X::X:X", |
718e3744 | 4653 | NO_STR |
4654 | SET_STR | |
4655 | IPV6_STR | |
4656 | "IPv6 next-hop address\n" | |
a4b2b610 DW |
4657 | "IPv6 global address\n" |
4658 | "IPv6 address of next hop\n") | |
718e3744 | 4659 | { |
d62a17ae | 4660 | int idx_ipv6 = 5; |
4661 | if (argc <= idx_ipv6) | |
4662 | return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), | |
4663 | "ipv6 next-hop global", NULL); | |
4664 | return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), | |
4665 | "ipv6 next-hop global", argv[idx_ipv6]->arg); | |
718e3744 | 4666 | } |
718e3744 | 4667 | |
d6902373 PG |
4668 | #ifdef KEEP_OLD_VPN_COMMANDS |
4669 | DEFUN (set_vpn_nexthop, | |
4670 | set_vpn_nexthop_cmd, | |
a13c883e | 4671 | "set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>", |
718e3744 | 4672 | SET_STR |
4673 | "VPNv4 information\n" | |
d6902373 PG |
4674 | "VPN next-hop address\n" |
4675 | "IP address of next hop\n" | |
a13c883e QY |
4676 | "VPNv6 information\n" |
4677 | "VPN next-hop address\n" | |
d6902373 | 4678 | "IPv6 address of next hop\n") |
718e3744 | 4679 | { |
d62a17ae | 4680 | int idx_ip = 3; |
4681 | afi_t afi; | |
4682 | int idx = 0; | |
4683 | ||
4684 | if (argv_find_and_parse_vpnvx(argv, argc, &idx, &afi)) { | |
4685 | if (afi == AFI_IP) | |
4686 | return generic_set_add( | |
4687 | vty, VTY_GET_CONTEXT(route_map_index), | |
4688 | "ipv4 vpn next-hop", argv[idx_ip]->arg); | |
4689 | else | |
4690 | return generic_set_add( | |
4691 | vty, VTY_GET_CONTEXT(route_map_index), | |
4692 | "ipv6 vpn next-hop", argv[idx_ip]->arg); | |
4693 | } | |
4694 | return CMD_SUCCESS; | |
d6902373 | 4695 | } |
a4b2b610 | 4696 | |
d6902373 PG |
4697 | DEFUN (no_set_vpn_nexthop, |
4698 | no_set_vpn_nexthop_cmd, | |
a13c883e | 4699 | "no set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>", |
718e3744 | 4700 | NO_STR |
4701 | SET_STR | |
a13c883e | 4702 | "VPNv4 information\n" |
d6902373 PG |
4703 | "VPN next-hop address\n" |
4704 | "IP address of next hop\n" | |
a13c883e QY |
4705 | "VPNv6 information\n" |
4706 | "VPN next-hop address\n" | |
d6902373 | 4707 | "IPv6 address of next hop\n") |
718e3744 | 4708 | { |
d62a17ae | 4709 | int idx_ip = 4; |
4710 | char *arg; | |
4711 | afi_t afi; | |
4712 | int idx = 0; | |
4713 | ||
4714 | if (argc <= idx_ip) | |
4715 | arg = NULL; | |
4716 | else | |
4717 | arg = argv[idx_ip]->arg; | |
4718 | if (argv_find_and_parse_vpnvx(argv, argc, &idx, &afi)) { | |
4719 | if (afi == AFI_IP) | |
4720 | return generic_set_delete( | |
4721 | vty, VTY_GET_CONTEXT(route_map_index), | |
4722 | "ipv4 vpn next-hop", arg); | |
4723 | else | |
4724 | return generic_set_delete( | |
4725 | vty, VTY_GET_CONTEXT(route_map_index), | |
4726 | "ipv6 vpn next-hop", argv[idx_ip]->arg); | |
4727 | } | |
4728 | return CMD_SUCCESS; | |
d6902373 PG |
4729 | } |
4730 | #endif /* KEEP_OLD_VPN_COMMANDS */ | |
4731 | ||
4732 | DEFUN (set_ipx_vpn_nexthop, | |
4733 | set_ipx_vpn_nexthop_cmd, | |
0d702986 | 4734 | "set <ipv4|ipv6> vpn next-hop <A.B.C.D|X:X::X:X>", |
d6902373 PG |
4735 | SET_STR |
4736 | "IPv4 information\n" | |
4737 | "IPv6 information\n" | |
4738 | "VPN information\n" | |
4739 | "VPN next-hop address\n" | |
4740 | "IP address of next hop\n" | |
4741 | "IPv6 address of next hop\n") | |
4742 | { | |
d62a17ae | 4743 | int idx_ip = 4; |
4744 | afi_t afi; | |
4745 | int idx = 0; | |
4746 | ||
4747 | if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) { | |
4748 | if (afi == AFI_IP) | |
4749 | return generic_set_add( | |
4750 | vty, VTY_GET_CONTEXT(route_map_index), | |
4751 | "ipv4 vpn next-hop", argv[idx_ip]->arg); | |
4752 | else | |
4753 | return generic_set_add( | |
4754 | vty, VTY_GET_CONTEXT(route_map_index), | |
4755 | "ipv6 vpn next-hop", argv[idx_ip]->arg); | |
4756 | } | |
4757 | return CMD_SUCCESS; | |
718e3744 | 4758 | } |
4759 | ||
d6902373 PG |
4760 | DEFUN (no_set_ipx_vpn_nexthop, |
4761 | no_set_ipx_vpn_nexthop_cmd, | |
9fa4d336 | 4762 | "no set <ipv4|ipv6> vpn next-hop [<A.B.C.D|X:X::X:X>]", |
d6902373 PG |
4763 | NO_STR |
4764 | SET_STR | |
4765 | "IPv4 information\n" | |
4766 | "IPv6 information\n" | |
4767 | "VPN information\n" | |
4768 | "VPN next-hop address\n" | |
4769 | "IP address of next hop\n" | |
4770 | "IPv6 address of next hop\n") | |
4771 | { | |
d62a17ae | 4772 | int idx_ip = 5; |
4773 | char *arg; | |
4774 | afi_t afi; | |
4775 | int idx = 0; | |
4776 | ||
4777 | if (argc <= idx_ip) | |
4778 | arg = NULL; | |
4779 | else | |
4780 | arg = argv[idx_ip]->arg; | |
4781 | if (argv_find_and_parse_afi(argv, argc, &idx, &afi)) { | |
4782 | if (afi == AFI_IP) | |
4783 | return generic_set_delete( | |
4784 | vty, VTY_GET_CONTEXT(route_map_index), | |
4785 | "ipv4 vpn next-hop", arg); | |
4786 | else | |
4787 | return generic_set_delete( | |
4788 | vty, VTY_GET_CONTEXT(route_map_index), | |
4789 | "ipv6 vpn next-hop", arg); | |
4790 | } | |
4791 | return CMD_SUCCESS; | |
d6902373 | 4792 | } |
718e3744 | 4793 | |
4794 | DEFUN (set_originator_id, | |
4795 | set_originator_id_cmd, | |
4796 | "set originator-id A.B.C.D", | |
4797 | SET_STR | |
4798 | "BGP originator ID attribute\n" | |
4799 | "IP address of originator\n") | |
4800 | { | |
d62a17ae | 4801 | int idx_ipv4 = 2; |
4802 | return generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), | |
4803 | "originator-id", argv[idx_ipv4]->arg); | |
718e3744 | 4804 | } |
4805 | ||
4c9bd275 | 4806 | |
718e3744 | 4807 | DEFUN (no_set_originator_id, |
4808 | no_set_originator_id_cmd, | |
4c9bd275 | 4809 | "no set originator-id [A.B.C.D]", |
718e3744 | 4810 | NO_STR |
4811 | SET_STR | |
4c9bd275 DW |
4812 | "BGP originator ID attribute\n" |
4813 | "IP address of originator\n") | |
718e3744 | 4814 | { |
d62a17ae | 4815 | int idx = 0; |
4816 | char *arg = | |
4817 | argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; | |
0d702986 | 4818 | |
d62a17ae | 4819 | return generic_set_delete(vty, VTY_GET_CONTEXT(route_map_index), |
4820 | "originator-id", arg); | |
718e3744 | 4821 | } |
4822 | ||
718e3744 | 4823 | |
718e3744 | 4824 | /* Initialization of route map. */ |
d62a17ae | 4825 | void bgp_route_map_init(void) |
4826 | { | |
4827 | route_map_init(); | |
4828 | ||
4829 | route_map_add_hook(bgp_route_map_add); | |
4830 | route_map_delete_hook(bgp_route_map_delete); | |
4831 | route_map_event_hook(bgp_route_map_event); | |
4832 | ||
4833 | route_map_match_interface_hook(generic_match_add); | |
4834 | route_map_no_match_interface_hook(generic_match_delete); | |
4835 | ||
4836 | route_map_match_ip_address_hook(generic_match_add); | |
4837 | route_map_no_match_ip_address_hook(generic_match_delete); | |
4838 | ||
4839 | route_map_match_ip_address_prefix_list_hook(generic_match_add); | |
4840 | route_map_no_match_ip_address_prefix_list_hook(generic_match_delete); | |
4841 | ||
4842 | route_map_match_ip_next_hop_hook(generic_match_add); | |
4843 | route_map_no_match_ip_next_hop_hook(generic_match_delete); | |
4844 | ||
4845 | route_map_match_ip_next_hop_prefix_list_hook(generic_match_add); | |
4846 | route_map_no_match_ip_next_hop_prefix_list_hook(generic_match_delete); | |
4847 | ||
61ad901e DA |
4848 | route_map_match_ip_next_hop_type_hook(generic_match_add); |
4849 | route_map_no_match_ip_next_hop_type_hook(generic_match_delete); | |
4850 | ||
d62a17ae | 4851 | route_map_match_ipv6_address_hook(generic_match_add); |
4852 | route_map_no_match_ipv6_address_hook(generic_match_delete); | |
4853 | ||
4854 | route_map_match_ipv6_address_prefix_list_hook(generic_match_add); | |
4855 | route_map_no_match_ipv6_address_prefix_list_hook(generic_match_delete); | |
4856 | ||
61ad901e DA |
4857 | route_map_match_ipv6_next_hop_type_hook(generic_match_add); |
4858 | route_map_no_match_ipv6_next_hop_type_hook(generic_match_delete); | |
4859 | ||
d62a17ae | 4860 | route_map_match_metric_hook(generic_match_add); |
4861 | route_map_no_match_metric_hook(generic_match_delete); | |
4862 | ||
4863 | route_map_match_tag_hook(generic_match_add); | |
4864 | route_map_no_match_tag_hook(generic_match_delete); | |
4865 | ||
4866 | route_map_set_ip_nexthop_hook(generic_set_add); | |
4867 | route_map_no_set_ip_nexthop_hook(generic_set_delete); | |
4868 | ||
4869 | route_map_set_ipv6_nexthop_local_hook(generic_set_add); | |
4870 | route_map_no_set_ipv6_nexthop_local_hook(generic_set_delete); | |
4871 | ||
4872 | route_map_set_metric_hook(generic_set_add); | |
4873 | route_map_no_set_metric_hook(generic_set_delete); | |
4874 | ||
4875 | route_map_set_tag_hook(generic_set_add); | |
4876 | route_map_no_set_tag_hook(generic_set_delete); | |
4877 | ||
4878 | route_map_install_match(&route_match_peer_cmd); | |
4879 | route_map_install_match(&route_match_local_pref_cmd); | |
1d7c7ace DS |
4880 | #if defined(HAVE_LUA) |
4881 | route_map_install_match(&route_match_command_cmd); | |
4882 | #endif | |
d62a17ae | 4883 | route_map_install_match(&route_match_ip_address_cmd); |
4884 | route_map_install_match(&route_match_ip_next_hop_cmd); | |
4885 | route_map_install_match(&route_match_ip_route_source_cmd); | |
4886 | route_map_install_match(&route_match_ip_address_prefix_list_cmd); | |
4887 | route_map_install_match(&route_match_ip_next_hop_prefix_list_cmd); | |
61ad901e | 4888 | route_map_install_match(&route_match_ip_next_hop_type_cmd); |
d62a17ae | 4889 | route_map_install_match(&route_match_ip_route_source_prefix_list_cmd); |
4890 | route_map_install_match(&route_match_aspath_cmd); | |
4891 | route_map_install_match(&route_match_community_cmd); | |
4892 | route_map_install_match(&route_match_lcommunity_cmd); | |
4893 | route_map_install_match(&route_match_ecommunity_cmd); | |
4894 | route_map_install_match(&route_match_local_pref_cmd); | |
4895 | route_map_install_match(&route_match_metric_cmd); | |
4896 | route_map_install_match(&route_match_origin_cmd); | |
4897 | route_map_install_match(&route_match_probability_cmd); | |
4898 | route_map_install_match(&route_match_interface_cmd); | |
4899 | route_map_install_match(&route_match_tag_cmd); | |
d37ba549 | 4900 | route_map_install_match(&route_match_mac_address_cmd); |
16f7ce2b | 4901 | route_map_install_match(&route_match_evpn_vni_cmd); |
33c2ff62 | 4902 | route_map_install_match(&route_match_evpn_route_type_cmd); |
6fb219da | 4903 | route_map_install_match(&route_match_evpn_default_route_cmd); |
d62a17ae | 4904 | |
4905 | route_map_install_set(&route_set_ip_nexthop_cmd); | |
4906 | route_map_install_set(&route_set_local_pref_cmd); | |
4907 | route_map_install_set(&route_set_weight_cmd); | |
4908 | route_map_install_set(&route_set_label_index_cmd); | |
4909 | route_map_install_set(&route_set_metric_cmd); | |
4910 | route_map_install_set(&route_set_aspath_prepend_cmd); | |
4911 | route_map_install_set(&route_set_aspath_exclude_cmd); | |
4912 | route_map_install_set(&route_set_origin_cmd); | |
4913 | route_map_install_set(&route_set_atomic_aggregate_cmd); | |
4914 | route_map_install_set(&route_set_aggregator_as_cmd); | |
4915 | route_map_install_set(&route_set_community_cmd); | |
4916 | route_map_install_set(&route_set_community_delete_cmd); | |
4917 | route_map_install_set(&route_set_lcommunity_cmd); | |
4918 | route_map_install_set(&route_set_lcommunity_delete_cmd); | |
4919 | route_map_install_set(&route_set_vpnv4_nexthop_cmd); | |
4920 | route_map_install_set(&route_set_vpnv6_nexthop_cmd); | |
4921 | route_map_install_set(&route_set_originator_id_cmd); | |
4922 | route_map_install_set(&route_set_ecommunity_rt_cmd); | |
4923 | route_map_install_set(&route_set_ecommunity_soo_cmd); | |
4924 | route_map_install_set(&route_set_tag_cmd); | |
4925 | route_map_install_set(&route_set_label_index_cmd); | |
4926 | ||
4927 | install_element(RMAP_NODE, &match_peer_cmd); | |
4928 | install_element(RMAP_NODE, &match_peer_local_cmd); | |
4929 | install_element(RMAP_NODE, &no_match_peer_cmd); | |
4930 | install_element(RMAP_NODE, &match_ip_route_source_cmd); | |
4931 | install_element(RMAP_NODE, &no_match_ip_route_source_cmd); | |
4932 | install_element(RMAP_NODE, &match_ip_route_source_prefix_list_cmd); | |
4933 | install_element(RMAP_NODE, &no_match_ip_route_source_prefix_list_cmd); | |
d37ba549 MK |
4934 | install_element(RMAP_NODE, &match_mac_address_cmd); |
4935 | install_element(RMAP_NODE, &no_match_mac_address_cmd); | |
16f7ce2b MK |
4936 | install_element(RMAP_NODE, &match_evpn_vni_cmd); |
4937 | install_element(RMAP_NODE, &no_match_evpn_vni_cmd); | |
33c2ff62 MK |
4938 | install_element(RMAP_NODE, &match_evpn_route_type_cmd); |
4939 | install_element(RMAP_NODE, &no_match_evpn_route_type_cmd); | |
6fb219da MK |
4940 | install_element(RMAP_NODE, &match_evpn_default_route_cmd); |
4941 | install_element(RMAP_NODE, &no_match_evpn_default_route_cmd); | |
d62a17ae | 4942 | |
4943 | install_element(RMAP_NODE, &match_aspath_cmd); | |
4944 | install_element(RMAP_NODE, &no_match_aspath_cmd); | |
4945 | install_element(RMAP_NODE, &match_local_pref_cmd); | |
4946 | install_element(RMAP_NODE, &no_match_local_pref_cmd); | |
4947 | install_element(RMAP_NODE, &match_community_cmd); | |
4948 | install_element(RMAP_NODE, &no_match_community_cmd); | |
4949 | install_element(RMAP_NODE, &match_lcommunity_cmd); | |
4950 | install_element(RMAP_NODE, &no_match_lcommunity_cmd); | |
4951 | install_element(RMAP_NODE, &match_ecommunity_cmd); | |
4952 | install_element(RMAP_NODE, &no_match_ecommunity_cmd); | |
4953 | install_element(RMAP_NODE, &match_origin_cmd); | |
4954 | install_element(RMAP_NODE, &no_match_origin_cmd); | |
4955 | install_element(RMAP_NODE, &match_probability_cmd); | |
4956 | install_element(RMAP_NODE, &no_match_probability_cmd); | |
4957 | ||
4958 | install_element(RMAP_NODE, &set_ip_nexthop_peer_cmd); | |
4959 | install_element(RMAP_NODE, &set_ip_nexthop_unchanged_cmd); | |
4960 | install_element(RMAP_NODE, &set_local_pref_cmd); | |
4961 | install_element(RMAP_NODE, &no_set_local_pref_cmd); | |
4962 | install_element(RMAP_NODE, &set_weight_cmd); | |
4963 | install_element(RMAP_NODE, &set_label_index_cmd); | |
4964 | install_element(RMAP_NODE, &no_set_weight_cmd); | |
4965 | install_element(RMAP_NODE, &no_set_label_index_cmd); | |
4966 | install_element(RMAP_NODE, &set_aspath_prepend_asn_cmd); | |
4967 | install_element(RMAP_NODE, &set_aspath_prepend_lastas_cmd); | |
4968 | install_element(RMAP_NODE, &set_aspath_exclude_cmd); | |
4969 | install_element(RMAP_NODE, &no_set_aspath_prepend_cmd); | |
4970 | install_element(RMAP_NODE, &no_set_aspath_exclude_cmd); | |
4971 | install_element(RMAP_NODE, &set_origin_cmd); | |
4972 | install_element(RMAP_NODE, &no_set_origin_cmd); | |
4973 | install_element(RMAP_NODE, &set_atomic_aggregate_cmd); | |
4974 | install_element(RMAP_NODE, &no_set_atomic_aggregate_cmd); | |
4975 | install_element(RMAP_NODE, &set_aggregator_as_cmd); | |
4976 | install_element(RMAP_NODE, &no_set_aggregator_as_cmd); | |
4977 | install_element(RMAP_NODE, &set_community_cmd); | |
4978 | install_element(RMAP_NODE, &set_community_none_cmd); | |
4979 | install_element(RMAP_NODE, &no_set_community_cmd); | |
4980 | install_element(RMAP_NODE, &set_community_delete_cmd); | |
4981 | install_element(RMAP_NODE, &no_set_community_delete_cmd); | |
4982 | install_element(RMAP_NODE, &set_lcommunity_cmd); | |
4983 | install_element(RMAP_NODE, &set_lcommunity_none_cmd); | |
4984 | install_element(RMAP_NODE, &no_set_lcommunity_cmd); | |
4985 | install_element(RMAP_NODE, &no_set_lcommunity1_cmd); | |
4986 | install_element(RMAP_NODE, &set_lcommunity_delete_cmd); | |
4987 | install_element(RMAP_NODE, &no_set_lcommunity_delete_cmd); | |
4988 | install_element(RMAP_NODE, &set_ecommunity_rt_cmd); | |
4989 | install_element(RMAP_NODE, &no_set_ecommunity_rt_cmd); | |
4990 | install_element(RMAP_NODE, &set_ecommunity_soo_cmd); | |
4991 | install_element(RMAP_NODE, &no_set_ecommunity_soo_cmd); | |
d6902373 | 4992 | #ifdef KEEP_OLD_VPN_COMMANDS |
d62a17ae | 4993 | install_element(RMAP_NODE, &set_vpn_nexthop_cmd); |
4994 | install_element(RMAP_NODE, &no_set_vpn_nexthop_cmd); | |
d6902373 | 4995 | #endif /* KEEP_OLD_VPN_COMMANDS */ |
d62a17ae | 4996 | install_element(RMAP_NODE, &set_ipx_vpn_nexthop_cmd); |
4997 | install_element(RMAP_NODE, &no_set_ipx_vpn_nexthop_cmd); | |
4998 | install_element(RMAP_NODE, &set_originator_id_cmd); | |
4999 | install_element(RMAP_NODE, &no_set_originator_id_cmd); | |
5000 | ||
5001 | route_map_install_match(&route_match_ipv6_address_cmd); | |
5002 | route_map_install_match(&route_match_ipv6_next_hop_cmd); | |
5003 | route_map_install_match(&route_match_ipv6_address_prefix_list_cmd); | |
61ad901e | 5004 | route_map_install_match(&route_match_ipv6_next_hop_type_cmd); |
d62a17ae | 5005 | route_map_install_set(&route_set_ipv6_nexthop_global_cmd); |
5006 | route_map_install_set(&route_set_ipv6_nexthop_prefer_global_cmd); | |
5007 | route_map_install_set(&route_set_ipv6_nexthop_local_cmd); | |
5008 | route_map_install_set(&route_set_ipv6_nexthop_peer_cmd); | |
5009 | ||
5010 | install_element(RMAP_NODE, &match_ipv6_next_hop_cmd); | |
5011 | install_element(RMAP_NODE, &no_match_ipv6_next_hop_cmd); | |
5012 | install_element(RMAP_NODE, &set_ipv6_nexthop_global_cmd); | |
5013 | install_element(RMAP_NODE, &no_set_ipv6_nexthop_global_cmd); | |
5014 | install_element(RMAP_NODE, &set_ipv6_nexthop_prefer_global_cmd); | |
5015 | install_element(RMAP_NODE, &no_set_ipv6_nexthop_prefer_global_cmd); | |
5016 | install_element(RMAP_NODE, &set_ipv6_nexthop_peer_cmd); | |
5017 | install_element(RMAP_NODE, &no_set_ipv6_nexthop_peer_cmd); | |
1d7c7ace DS |
5018 | #if defined(HAVE_LUA) |
5019 | install_element(RMAP_NODE, &match_command_cmd); | |
5020 | install_element(RMAP_NODE, &no_match_command_cmd); | |
5021 | #endif | |
d62a17ae | 5022 | } |
5023 | ||
5024 | void bgp_route_map_terminate(void) | |
5025 | { | |
5026 | /* ToDo: Cleanup all the used memory */ | |
d62a17ae | 5027 | route_map_finish(); |
518f0eb1 | 5028 | } |