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