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