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