1 /* Route map function of bgpd.
2 * Copyright (C) 1998, 1999 Kunihiro Ishiguro
4 * This file is part of GNU Zebra.
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
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.
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
32 #ifdef HAVE_LIBPCREPOSIX
33 #include <pcreposix.h>
36 #endif /* HAVE_LIBPCREPOSIX */
38 #include "sockunion.h"
44 #include "bgpd/bgpd.h"
45 #include "bgpd/bgp_table.h"
46 #include "bgpd/bgp_attr.h"
47 #include "bgpd/bgp_aspath.h"
48 #include "bgpd/bgp_packet.h"
49 #include "bgpd/bgp_route.h"
50 #include "bgpd/bgp_zebra.h"
51 #include "bgpd/bgp_regex.h"
52 #include "bgpd/bgp_community.h"
53 #include "bgpd/bgp_clist.h"
54 #include "bgpd/bgp_filter.h"
55 #include "bgpd/bgp_mplsvpn.h"
56 #include "bgpd/bgp_ecommunity.h"
57 #include "bgpd/bgp_lcommunity.h"
58 #include "bgpd/bgp_vty.h"
59 #include "bgpd/bgp_debug.h"
60 #include "bgpd/bgp_evpn.h"
61 #include "bgpd/bgp_evpn_private.h"
62 #include "bgpd/bgp_evpn_vty.h"
63 #include "bgpd/bgp_mplsvpn.h"
64 #include "bgpd/bgp_pbr.h"
65 #include "bgpd/bgp_flowspec_util.h"
66 #include "bgpd/bgp_encap_types.h"
67 #include "bgpd/bgp_mpath.h"
70 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
73 #ifndef VTYSH_EXTRACT_PL
74 #include "bgpd/bgp_routemap_clippy.c"
77 /* Memo of route-map commands.
86 ip route-source : Done
90 ipv6 route-source: (This will not be implemented by bgpd)
91 ipv6 prefix-list : Done
92 length : (This will not be implemented by bgpd)
94 route-type : (This will not be implemented by bgpd)
96 local-preference : Done
98 set as-path prepend : Done
100 automatic-tag : (This will not be implemented by bgpd)
102 large-community : Done
103 large-comm-list : Done
106 default : (This will not be implemented by bgpd)
107 interface : (This will not be implemented by bgpd)
108 ip default : (This will not be implemented by bgpd)
110 ip precedence : (This will not be implemented by bgpd)
111 ip tos : (This will not be implemented by bgpd)
112 level : (This will not be implemented by bgpd)
113 local-preference : Done
115 metric-type : Not yet
123 set ipv6 next-hop global: Done
124 set ipv6 next-hop prefer-global: Done
125 set ipv6 next-hop local : Done
126 set as-path exclude : Done
130 /* generic value manipulation to be shared in multiple rules */
132 #define RMAP_VALUE_SET 0
133 #define RMAP_VALUE_ADD 1
134 #define RMAP_VALUE_SUB 2
142 static int route_value_match(struct rmap_value
*rv
, uint32_t value
)
144 if (rv
->variable
== 0 && value
== rv
->value
)
150 static uint32_t route_value_adjust(struct rmap_value
*rv
, uint32_t current
,
155 switch (rv
->variable
) {
164 switch (rv
->action
) {
166 if (current
> UINT32_MAX
- value
)
168 return current
+ value
;
170 if (current
<= value
)
172 return current
- value
;
178 static void *route_value_compile(const char *arg
)
180 uint8_t action
= RMAP_VALUE_SET
, var
= 0;
181 unsigned long larg
= 0;
183 struct rmap_value
*rv
;
186 action
= RMAP_VALUE_ADD
;
188 } else if (arg
[0] == '-') {
189 action
= RMAP_VALUE_SUB
;
193 if (all_digit(arg
)) {
195 larg
= strtoul(arg
, &endptr
, 10);
196 if (*arg
== 0 || *endptr
!= 0 || errno
|| larg
> UINT32_MAX
)
199 if (strcmp(arg
, "rtt") == 0)
205 rv
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_value
));
213 static void route_value_free(void *rule
)
215 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
218 /* generic as path object to be shared in multiple rules */
220 static void *route_aspath_compile(const char *arg
)
222 struct aspath
*aspath
;
224 aspath
= aspath_str2aspath(arg
);
230 static void route_aspath_free(void *rule
)
232 struct aspath
*aspath
= rule
;
236 struct bgp_match_peer_compiled
{
241 /* 'match peer (A.B.C.D|X:X::X:X|WORD)' */
243 /* Compares the peer specified in the 'match peer' clause with the peer
244 received in bgp_path_info->peer. If it is the same, or if the peer structure
245 received is a peer_group containing it, returns RMAP_MATCH. */
246 static enum route_map_cmd_result_t
247 route_match_peer(void *rule
, const struct prefix
*prefix
,
248 route_map_object_t type
, void *object
)
250 struct bgp_match_peer_compiled
*pc
;
252 union sockunion su_def
= {
253 .sin
= {.sin_family
= AF_INET
, .sin_addr
.s_addr
= INADDR_ANY
}};
254 struct peer_group
*group
;
256 struct listnode
*node
, *nnode
;
258 if (type
== RMAP_BGP
) {
261 peer
= ((struct bgp_path_info
*)object
)->peer
;
267 if (strcmp(peer
->conf_if
, pc
->interface
) == 0)
273 /* If su='0.0.0.0' (command 'match peer local'), and it's a
275 REDISTRIBUTE, AGGREGATE-ADDRESS or DEFAULT_GENERATED route
278 if (sockunion_same(su
, &su_def
)) {
280 if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_NETWORK
)
281 || CHECK_FLAG(peer
->rmap_type
,
282 PEER_RMAP_TYPE_REDISTRIBUTE
)
283 || CHECK_FLAG(peer
->rmap_type
,
284 PEER_RMAP_TYPE_AGGREGATE
)
285 || CHECK_FLAG(peer
->rmap_type
,
286 PEER_RMAP_TYPE_DEFAULT
))
293 if (!CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
)) {
294 if (sockunion_same(su
, &peer
->su
))
300 for (ALL_LIST_ELEMENTS(group
->peer
, node
, nnode
,
302 if (sockunion_same(su
, &peer
->su
))
311 static void *route_match_peer_compile(const char *arg
)
313 struct bgp_match_peer_compiled
*pc
;
316 pc
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
317 sizeof(struct bgp_match_peer_compiled
));
319 ret
= str2sockunion(strcmp(arg
, "local") ? arg
: "0.0.0.0", &pc
->su
);
321 pc
->interface
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
328 /* Free route map's compiled `ip address' value. */
329 static void route_match_peer_free(void *rule
)
331 struct bgp_match_peer_compiled
*pc
= rule
;
333 XFREE(MTYPE_ROUTE_MAP_COMPILED
, pc
->interface
);
335 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
338 /* Route map commands for ip address matching. */
339 static const struct route_map_rule_cmd route_match_peer_cmd
= {
342 route_match_peer_compile
,
343 route_match_peer_free
346 #if defined(HAVE_LUA)
347 static enum route_map_cmd_result_t
348 route_match_command(void *rule
, const struct prefix
*prefix
,
349 route_map_object_t type
, void *object
)
351 int status
= RMAP_NOMATCH
;
352 u_int32_t locpref
= 0;
353 u_int32_t newlocpref
= 0;
354 enum lua_rm_status lrm_status
;
355 struct bgp_path_info
*path
= (struct bgp_path_info
*)object
;
356 lua_State
*L
= lua_initialize("/etc/frr/lua.scr");
362 * Setup the prefix information to pass in
364 lua_setup_prefix_table(L
, prefix
);
366 zlog_debug("Set up prefix table");
368 * Setup the bgp_path_info information
371 lua_pushinteger(L
, path
->attr
->med
);
372 lua_setfield(L
, -2, "metric");
373 lua_pushinteger(L
, path
->attr
->nh_ifindex
);
374 lua_setfield(L
, -2, "ifindex");
375 lua_pushstring(L
, path
->attr
->aspath
->str
);
376 lua_setfield(L
, -2, "aspath");
377 lua_pushinteger(L
, path
->attr
->local_pref
);
378 lua_setfield(L
, -2, "localpref");
379 zlog_debug("%s %d", path
->attr
->aspath
->str
, path
->attr
->nh_ifindex
);
380 lua_setglobal(L
, "nexthop");
382 zlog_debug("Set up nexthop information");
386 lrm_status
= lua_run_rm_rule(L
, rule
);
387 switch (lrm_status
) {
389 zlog_debug("RM_FAILURE");
392 zlog_debug("RM_NOMATCH");
394 case LUA_RM_MATCH_AND_CHANGE
:
395 zlog_debug("MATCH AND CHANGE");
396 lua_getglobal(L
, "nexthop");
397 path
->attr
->med
= get_integer(L
, "metric");
399 * This needs to be abstraced with the set function
401 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
))
402 locpref
= path
->attr
->local_pref
;
403 newlocpref
= get_integer(L
, "localpref");
404 if (newlocpref
!= locpref
) {
405 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
);
406 path
->attr
->local_pref
= newlocpref
;
411 zlog_debug("MATCH ONLY");
419 static void *route_match_command_compile(const char *arg
)
423 command
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
428 route_match_command_free(void *rule
)
430 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
433 static const struct route_map_rule_cmd route_match_command_cmd
= {
436 route_match_command_compile
,
437 route_match_command_free
441 /* `match ip address IP_ACCESS_LIST' */
443 /* Match function should return 1 if match is success else return
445 static enum route_map_cmd_result_t
446 route_match_ip_address(void *rule
, const struct prefix
*prefix
,
447 route_map_object_t type
, void *object
)
449 struct access_list
*alist
;
451 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
452 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
456 return (access_list_apply(alist
, prefix
) == FILTER_DENY
463 /* Route map `ip address' match statement. `arg' should be
465 static void *route_match_ip_address_compile(const char *arg
)
467 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
470 /* Free route map's compiled `ip address' value. */
471 static void route_match_ip_address_free(void *rule
)
473 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
476 /* Route map commands for ip address matching. */
477 static const struct route_map_rule_cmd route_match_ip_address_cmd
= {
479 route_match_ip_address
,
480 route_match_ip_address_compile
,
481 route_match_ip_address_free
484 /* `match ip next-hop IP_ADDRESS' */
486 /* Match function return 1 if match is success else return zero. */
487 static enum route_map_cmd_result_t
488 route_match_ip_next_hop(void *rule
, const struct prefix
*prefix
,
489 route_map_object_t type
, void *object
)
491 struct access_list
*alist
;
492 struct bgp_path_info
*path
;
493 struct prefix_ipv4 p
;
495 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
498 p
.prefix
= path
->attr
->nexthop
;
499 p
.prefixlen
= IPV4_MAX_BITLEN
;
501 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
505 return (access_list_apply(alist
, &p
) == FILTER_DENY
512 /* Route map `ip next-hop' match statement. `arg' is
514 static void *route_match_ip_next_hop_compile(const char *arg
)
516 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
519 /* Free route map's compiled `ip address' value. */
520 static void route_match_ip_next_hop_free(void *rule
)
522 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
525 /* Route map commands for ip next-hop matching. */
526 static const struct route_map_rule_cmd route_match_ip_next_hop_cmd
= {
528 route_match_ip_next_hop
,
529 route_match_ip_next_hop_compile
,
530 route_match_ip_next_hop_free
533 /* `match ip route-source ACCESS-LIST' */
535 /* Match function return 1 if match is success else return zero. */
536 static enum route_map_cmd_result_t
537 route_match_ip_route_source(void *rule
, const struct prefix
*pfx
,
538 route_map_object_t type
, void *object
)
540 struct access_list
*alist
;
541 struct bgp_path_info
*path
;
543 struct prefix_ipv4 p
;
545 if (type
== RMAP_BGP
&& pfx
->family
== AF_INET
) {
549 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
553 p
.prefix
= peer
->su
.sin
.sin_addr
;
554 p
.prefixlen
= IPV4_MAX_BITLEN
;
556 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
560 return (access_list_apply(alist
, &p
) == FILTER_DENY
567 /* Route map `ip route-source' match statement. `arg' is
569 static void *route_match_ip_route_source_compile(const char *arg
)
571 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
574 /* Free route map's compiled `ip address' value. */
575 static void route_match_ip_route_source_free(void *rule
)
577 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
580 /* Route map commands for ip route-source matching. */
581 static const struct route_map_rule_cmd route_match_ip_route_source_cmd
= {
583 route_match_ip_route_source
,
584 route_match_ip_route_source_compile
,
585 route_match_ip_route_source_free
588 static enum route_map_cmd_result_t
589 route_match_prefix_list_flowspec(afi_t afi
, struct prefix_list
*plist
,
590 const struct prefix
*p
)
593 struct bgp_pbr_entry_main api
;
595 memset(&api
, 0, sizeof(api
));
597 if (family2afi(p
->u
.prefix_flowspec
.family
) != afi
)
600 /* extract match from flowspec entries */
601 ret
= bgp_flowspec_match_rules_fill(
602 (uint8_t *)p
->u
.prefix_flowspec
.ptr
,
603 p
->u
.prefix_flowspec
.prefixlen
, &api
,
607 if (api
.match_bitmask
& PREFIX_DST_PRESENT
||
608 api
.match_bitmask_iprule
& PREFIX_DST_PRESENT
) {
609 if (family2afi((&api
.dst_prefix
)->family
) != afi
)
611 return prefix_list_apply(plist
, &api
.dst_prefix
) == PREFIX_DENY
614 } else if (api
.match_bitmask
& PREFIX_SRC_PRESENT
||
615 api
.match_bitmask_iprule
& PREFIX_SRC_PRESENT
) {
616 if (family2afi((&api
.src_prefix
)->family
) != afi
)
618 return (prefix_list_apply(plist
, &api
.src_prefix
) == PREFIX_DENY
625 static enum route_map_cmd_result_t
626 route_match_address_prefix_list(void *rule
, afi_t afi
,
627 const struct prefix
*prefix
,
628 route_map_object_t type
, void *object
)
630 struct prefix_list
*plist
;
632 if (type
!= RMAP_BGP
)
635 plist
= prefix_list_lookup(afi
, (char *)rule
);
639 if (prefix
->family
== AF_FLOWSPEC
)
640 return route_match_prefix_list_flowspec(afi
, plist
,
642 return (prefix_list_apply(plist
, prefix
) == PREFIX_DENY
? RMAP_NOMATCH
646 static enum route_map_cmd_result_t
647 route_match_ip_address_prefix_list(void *rule
, const struct prefix
*prefix
,
648 route_map_object_t type
, void *object
)
650 return route_match_address_prefix_list(rule
, AFI_IP
, prefix
, type
,
654 static void *route_match_ip_address_prefix_list_compile(const char *arg
)
656 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
659 static void route_match_ip_address_prefix_list_free(void *rule
)
661 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
664 static const struct route_map_rule_cmd
665 route_match_ip_address_prefix_list_cmd
= {
666 "ip address prefix-list",
667 route_match_ip_address_prefix_list
,
668 route_match_ip_address_prefix_list_compile
,
669 route_match_ip_address_prefix_list_free
672 /* `match ip next-hop prefix-list PREFIX_LIST' */
674 static enum route_map_cmd_result_t
675 route_match_ip_next_hop_prefix_list(void *rule
, const struct prefix
*prefix
,
676 route_map_object_t type
, void *object
)
678 struct prefix_list
*plist
;
679 struct bgp_path_info
*path
;
680 struct prefix_ipv4 p
;
682 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
685 p
.prefix
= path
->attr
->nexthop
;
686 p
.prefixlen
= IPV4_MAX_BITLEN
;
688 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
692 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
699 static void *route_match_ip_next_hop_prefix_list_compile(const char *arg
)
701 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
704 static void route_match_ip_next_hop_prefix_list_free(void *rule
)
706 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
709 static const struct route_map_rule_cmd
710 route_match_ip_next_hop_prefix_list_cmd
= {
711 "ip next-hop prefix-list",
712 route_match_ip_next_hop_prefix_list
,
713 route_match_ip_next_hop_prefix_list_compile
,
714 route_match_ip_next_hop_prefix_list_free
717 /* `match ip next-hop type <blackhole>' */
719 static enum route_map_cmd_result_t
720 route_match_ip_next_hop_type(void *rule
, const struct prefix
*prefix
,
721 route_map_object_t type
, void *object
)
723 struct bgp_path_info
*path
;
725 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
726 path
= (struct bgp_path_info
*)object
;
730 /* If nexthop interface's index can't be resolved and nexthop is
731 set to any address then mark it as type `blackhole`.
732 This logic works for matching kernel/static routes like:
733 `ip route add blackhole 10.0.0.1`. */
734 if (path
->attr
->nexthop
.s_addr
== INADDR_ANY
735 && !path
->attr
->nh_ifindex
)
741 static void *route_match_ip_next_hop_type_compile(const char *arg
)
743 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
746 static void route_match_ip_next_hop_type_free(void *rule
)
748 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
751 static const struct route_map_rule_cmd
752 route_match_ip_next_hop_type_cmd
= {
754 route_match_ip_next_hop_type
,
755 route_match_ip_next_hop_type_compile
,
756 route_match_ip_next_hop_type_free
759 /* `match ip route-source prefix-list PREFIX_LIST' */
761 static enum route_map_cmd_result_t
762 route_match_ip_route_source_prefix_list(void *rule
,
763 const struct prefix
*prefix
,
764 route_map_object_t type
, void *object
)
766 struct prefix_list
*plist
;
767 struct bgp_path_info
*path
;
769 struct prefix_ipv4 p
;
771 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
775 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
779 p
.prefix
= peer
->su
.sin
.sin_addr
;
780 p
.prefixlen
= IPV4_MAX_BITLEN
;
782 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
786 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
793 static void *route_match_ip_route_source_prefix_list_compile(const char *arg
)
795 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
798 static void route_match_ip_route_source_prefix_list_free(void *rule
)
800 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
803 static const struct route_map_rule_cmd
804 route_match_ip_route_source_prefix_list_cmd
= {
805 "ip route-source prefix-list",
806 route_match_ip_route_source_prefix_list
,
807 route_match_ip_route_source_prefix_list_compile
,
808 route_match_ip_route_source_prefix_list_free
811 /* `match evpn default-route' */
813 /* Match function should return 1 if match is success else 0 */
814 static enum route_map_cmd_result_t
815 route_match_evpn_default_route(void *rule
, const struct prefix
*p
,
816 route_map_object_t type
, void *object
)
818 if (type
== RMAP_BGP
&& is_evpn_prefix_default(p
))
824 /* Route map commands for default-route matching. */
825 static const struct route_map_rule_cmd
826 route_match_evpn_default_route_cmd
= {
827 "evpn default-route",
828 route_match_evpn_default_route
,
833 /* `match mac address MAC_ACCESS_LIST' */
835 /* Match function should return 1 if match is success else return
837 static enum route_map_cmd_result_t
838 route_match_mac_address(void *rule
, const struct prefix
*prefix
,
839 route_map_object_t type
, void *object
)
841 struct access_list
*alist
;
844 if (type
== RMAP_BGP
) {
845 alist
= access_list_lookup(AFI_L2VPN
, (char *)rule
);
849 if (prefix
->u
.prefix_evpn
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
852 p
.family
= AF_ETHERNET
;
853 p
.prefixlen
= ETH_ALEN
* 8;
854 p
.u
.prefix_eth
= prefix
->u
.prefix_evpn
.macip_addr
.mac
;
856 return (access_list_apply(alist
, &p
) == FILTER_DENY
864 /* Route map `mac address' match statement. `arg' should be
866 static void *route_match_mac_address_compile(const char *arg
)
868 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
871 /* Free route map's compiled `ip address' value. */
872 static void route_match_mac_address_free(void *rule
)
874 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
877 /* Route map commands for mac address matching. */
878 static const struct route_map_rule_cmd route_match_mac_address_cmd
= {
880 route_match_mac_address
,
881 route_match_mac_address_compile
,
882 route_match_mac_address_free
886 * Match function returns:
887 * ...RMAP_MATCH if match is found.
888 * ...RMAP_NOMATCH if match is not found.
889 * ...RMAP_NOOP to ignore this match check.
891 static enum route_map_cmd_result_t
892 route_match_vni(void *rule
, const struct prefix
*prefix
,
893 route_map_object_t type
, void *object
)
896 unsigned int label_cnt
= 0;
897 struct bgp_path_info
*path
= NULL
;
898 struct prefix_evpn
*evp
= (struct prefix_evpn
*) prefix
;
900 if (type
== RMAP_BGP
) {
901 vni
= *((vni_t
*)rule
);
902 path
= (struct bgp_path_info
*)object
;
905 * This rmap filter is valid for vxlan tunnel type only.
906 * For any other tunnel type, return noop to ignore
909 if (path
->attr
->encap_tunneltype
!= BGP_ENCAP_TYPE_VXLAN
)
913 * Apply filter to type 1, 2, 5 routes only.
914 * Other route types do not have vni label.
916 if (evp
&& (evp
->prefix
.route_type
!= BGP_EVPN_AD_ROUTE
&&
917 evp
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
&&
918 evp
->prefix
.route_type
!= BGP_EVPN_IP_PREFIX_ROUTE
))
921 if (path
->extra
== NULL
)
924 for ( ; label_cnt
< BGP_MAX_LABELS
&&
925 label_cnt
< path
->extra
->num_labels
; label_cnt
++) {
926 if (vni
== label2vni(&path
->extra
->label
[label_cnt
]))
934 /* Route map `vni' match statement. */
935 static void *route_match_vni_compile(const char *arg
)
940 vni
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(vni_t
));
942 *vni
= strtoul(arg
, &end
, 10);
944 XFREE(MTYPE_ROUTE_MAP_COMPILED
, vni
);
951 /* Free route map's compiled `vni' value. */
952 static void route_match_vni_free(void *rule
)
954 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
957 /* Route map commands for vni matching. */
958 static const struct route_map_rule_cmd route_match_evpn_vni_cmd
= {
961 route_match_vni_compile
,
965 /* `match evpn route-type' */
967 /* Match function should return 1 if match is success else return
969 static enum route_map_cmd_result_t
970 route_match_evpn_route_type(void *rule
, const struct prefix
*pfx
,
971 route_map_object_t type
, void *object
)
973 uint8_t route_type
= 0;
975 if (type
== RMAP_BGP
) {
976 route_type
= *((uint8_t *)rule
);
978 if (route_type
== pfx
->u
.prefix_evpn
.route_type
)
985 /* Route map `route-type' match statement. */
986 static void *route_match_evpn_route_type_compile(const char *arg
)
988 uint8_t *route_type
= NULL
;
990 route_type
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
992 if (strncmp(arg
, "ma", 2) == 0)
993 *route_type
= BGP_EVPN_MAC_IP_ROUTE
;
994 else if (strncmp(arg
, "mu", 2) == 0)
995 *route_type
= BGP_EVPN_IMET_ROUTE
;
997 *route_type
= BGP_EVPN_IP_PREFIX_ROUTE
;
1002 /* Free route map's compiled `route-type' value. */
1003 static void route_match_evpn_route_type_free(void *rule
)
1005 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1008 /* Route map commands for evpn route-type matching. */
1009 static const struct route_map_rule_cmd route_match_evpn_route_type_cmd
= {
1011 route_match_evpn_route_type
,
1012 route_match_evpn_route_type_compile
,
1013 route_match_evpn_route_type_free
1018 /* Match function should return 1 if match is success else return zero. */
1019 static enum route_map_cmd_result_t
1020 route_match_rd(void *rule
, const struct prefix
*prefix
,
1021 route_map_object_t type
, void *object
)
1023 struct prefix_rd
*prd_rule
= NULL
;
1024 const struct prefix_rd
*prd_route
= NULL
;
1025 struct bgp_path_info
*path
= NULL
;
1027 if (type
== RMAP_BGP
) {
1028 if (prefix
->family
!= AF_EVPN
)
1029 return RMAP_NOMATCH
;
1031 prd_rule
= (struct prefix_rd
*)rule
;
1032 path
= (struct bgp_path_info
*)object
;
1034 if (path
->net
== NULL
|| path
->net
->pdest
== NULL
)
1035 return RMAP_NOMATCH
;
1037 prd_route
= (struct prefix_rd
*)bgp_dest_get_prefix(
1039 if (memcmp(prd_route
->val
, prd_rule
->val
, ECOMMUNITY_SIZE
) == 0)
1043 return RMAP_NOMATCH
;
1046 /* Route map `rd' match statement. */
1047 static void *route_match_rd_compile(const char *arg
)
1049 struct prefix_rd
*prd
;
1052 prd
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct prefix_rd
));
1054 ret
= str2prefix_rd(arg
, prd
);
1056 XFREE(MTYPE_ROUTE_MAP_COMPILED
, prd
);
1063 /* Free route map's compiled `rd' value. */
1064 static void route_match_rd_free(void *rule
)
1066 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1069 /* Route map commands for rd matching. */
1070 static const struct route_map_rule_cmd route_match_evpn_rd_cmd
= {
1073 route_match_rd_compile
,
1077 /* Route map commands for VRF route leak with source vrf matching */
1078 static enum route_map_cmd_result_t
1079 route_match_vrl_source_vrf(void *rule
, const struct prefix
*prefix
,
1080 route_map_object_t type
, void *object
)
1082 struct bgp_path_info
*path
;
1085 if (type
== RMAP_BGP
) {
1087 path
= (struct bgp_path_info
*)object
;
1089 if (strncmp(vrf_name
, "n/a", VRF_NAMSIZ
) == 0)
1090 return RMAP_NOMATCH
;
1092 if (path
->extra
== NULL
)
1093 return RMAP_NOMATCH
;
1095 if (strncmp(vrf_name
, vrf_id_to_name(
1096 path
->extra
->bgp_orig
->vrf_id
), VRF_NAMSIZ
)
1101 return RMAP_NOMATCH
;
1104 static void *route_match_vrl_source_vrf_compile(const char *arg
)
1106 uint8_t *vrf_name
= NULL
;
1108 vrf_name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1113 /* Free route map's compiled `route-type' value. */
1114 static void route_match_vrl_source_vrf_free(void *rule
)
1116 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1119 static const struct route_map_rule_cmd route_match_vrl_source_vrf_cmd
= {
1121 route_match_vrl_source_vrf
,
1122 route_match_vrl_source_vrf_compile
,
1123 route_match_vrl_source_vrf_free
1126 /* `match local-preference LOCAL-PREF' */
1128 /* Match function return 1 if match is success else return zero. */
1129 static enum route_map_cmd_result_t
1130 route_match_local_pref(void *rule
, const struct prefix
*prefix
,
1131 route_map_object_t type
, void *object
)
1133 uint32_t *local_pref
;
1134 struct bgp_path_info
*path
;
1136 if (type
== RMAP_BGP
) {
1140 if (path
->attr
->local_pref
== *local_pref
)
1143 return RMAP_NOMATCH
;
1145 return RMAP_NOMATCH
;
1149 * Route map `match local-preference' match statement.
1150 * `arg' is local-pref value
1152 static void *route_match_local_pref_compile(const char *arg
)
1154 uint32_t *local_pref
;
1155 char *endptr
= NULL
;
1156 unsigned long tmpval
;
1158 /* Locpref value shoud be integer. */
1159 if (!all_digit(arg
))
1163 tmpval
= strtoul(arg
, &endptr
, 10);
1164 if (*endptr
!= '\0' || errno
|| tmpval
> UINT32_MAX
)
1167 local_pref
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint32_t));
1169 *local_pref
= tmpval
;
1173 /* Free route map's compiled `match local-preference' value. */
1174 static void route_match_local_pref_free(void *rule
)
1176 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1179 /* Route map commands for metric matching. */
1180 static const struct route_map_rule_cmd route_match_local_pref_cmd
= {
1182 route_match_local_pref
,
1183 route_match_local_pref_compile
,
1184 route_match_local_pref_free
1187 /* `match metric METRIC' */
1189 /* Match function return 1 if match is success else return zero. */
1190 static enum route_map_cmd_result_t
1191 route_match_metric(void *rule
, const struct prefix
*prefix
,
1192 route_map_object_t type
, void *object
)
1194 struct rmap_value
*rv
;
1195 struct bgp_path_info
*path
;
1197 if (type
== RMAP_BGP
) {
1200 return route_value_match(rv
, path
->attr
->med
);
1202 return RMAP_NOMATCH
;
1205 /* Route map commands for metric matching. */
1206 static const struct route_map_rule_cmd route_match_metric_cmd
= {
1209 route_value_compile
,
1213 /* `match as-path ASPATH' */
1215 /* Match function for as-path match. I assume given object is */
1216 static enum route_map_cmd_result_t
1217 route_match_aspath(void *rule
, const struct prefix
*prefix
,
1218 route_map_object_t type
, void *object
)
1221 struct as_list
*as_list
;
1222 struct bgp_path_info
*path
;
1224 if (type
== RMAP_BGP
) {
1225 as_list
= as_list_lookup((char *)rule
);
1226 if (as_list
== NULL
)
1227 return RMAP_NOMATCH
;
1231 /* Perform match. */
1232 return ((as_list_apply(as_list
, path
->attr
->aspath
)
1237 return RMAP_NOMATCH
;
1240 /* Compile function for as-path match. */
1241 static void *route_match_aspath_compile(const char *arg
)
1243 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1246 /* Compile function for as-path match. */
1247 static void route_match_aspath_free(void *rule
)
1249 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1252 /* Route map commands for aspath matching. */
1253 static const struct route_map_rule_cmd route_match_aspath_cmd
= {
1256 route_match_aspath_compile
,
1257 route_match_aspath_free
1260 /* `match community COMMUNIY' */
1261 struct rmap_community
{
1267 /* Match function for community match. */
1268 static enum route_map_cmd_result_t
1269 route_match_community(void *rule
, const struct prefix
*prefix
,
1270 route_map_object_t type
, void *object
)
1272 struct community_list
*list
;
1273 struct bgp_path_info
*path
;
1274 struct rmap_community
*rcom
= rule
;
1276 if (type
== RMAP_BGP
) {
1280 list
= community_list_lookup(bgp_clist
, rcom
->name
,
1282 COMMUNITY_LIST_MASTER
);
1284 return RMAP_NOMATCH
;
1287 if (community_list_exact_match(path
->attr
->community
,
1291 if (community_list_match(path
->attr
->community
, list
))
1295 return RMAP_NOMATCH
;
1298 /* Compile function for community match. */
1299 static void *route_match_community_compile(const char *arg
)
1301 struct rmap_community
*rcom
;
1305 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1307 p
= strchr(arg
, ' ');
1310 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1311 memcpy(rcom
->name
, arg
, len
);
1314 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1318 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1322 /* Compile function for community match. */
1323 static void route_match_community_free(void *rule
)
1325 struct rmap_community
*rcom
= rule
;
1327 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1328 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1332 * In routemap processing there is a need to add the
1333 * name as a rule_key in the dependency table. Routemap
1334 * lib is unaware of rule_key when exact-match clause
1335 * is in use. routemap lib uses the compiled output to
1336 * get the rule_key value.
1338 static void *route_match_get_community_key(void *rule
)
1340 struct rmap_community
*rcom
;
1347 /* Route map commands for community matching. */
1348 static const struct route_map_rule_cmd route_match_community_cmd
= {
1350 route_match_community
,
1351 route_match_community_compile
,
1352 route_match_community_free
,
1353 route_match_get_community_key
1356 /* Match function for lcommunity match. */
1357 static enum route_map_cmd_result_t
1358 route_match_lcommunity(void *rule
, const struct prefix
*prefix
,
1359 route_map_object_t type
, void *object
)
1361 struct community_list
*list
;
1362 struct bgp_path_info
*path
;
1363 struct rmap_community
*rcom
= rule
;
1365 if (type
== RMAP_BGP
) {
1368 list
= community_list_lookup(bgp_clist
, rcom
->name
,
1370 LARGE_COMMUNITY_LIST_MASTER
);
1372 return RMAP_NOMATCH
;
1375 if (lcommunity_list_exact_match(
1376 path
->attr
->lcommunity
,
1380 if (lcommunity_list_match(
1381 path
->attr
->lcommunity
,
1386 return RMAP_NOMATCH
;
1389 /* Compile function for community match. */
1390 static void *route_match_lcommunity_compile(const char *arg
)
1392 struct rmap_community
*rcom
;
1396 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1398 p
= strchr(arg
, ' ');
1401 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1402 memcpy(rcom
->name
, arg
, len
);
1405 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1409 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1413 /* Compile function for community match. */
1414 static void route_match_lcommunity_free(void *rule
)
1416 struct rmap_community
*rcom
= rule
;
1418 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1419 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1422 /* Route map commands for community matching. */
1423 static const struct route_map_rule_cmd route_match_lcommunity_cmd
= {
1425 route_match_lcommunity
,
1426 route_match_lcommunity_compile
,
1427 route_match_lcommunity_free
,
1428 route_match_get_community_key
1432 /* Match function for extcommunity match. */
1433 static enum route_map_cmd_result_t
1434 route_match_ecommunity(void *rule
, const struct prefix
*prefix
,
1435 route_map_object_t type
, void *object
)
1437 struct community_list
*list
;
1438 struct bgp_path_info
*path
;
1439 struct rmap_community
*rcom
= rule
;
1441 if (type
== RMAP_BGP
) {
1444 list
= community_list_lookup(bgp_clist
, rcom
->name
,
1446 EXTCOMMUNITY_LIST_MASTER
);
1448 return RMAP_NOMATCH
;
1450 if (ecommunity_list_match(path
->attr
->ecommunity
, list
))
1453 return RMAP_NOMATCH
;
1456 /* Compile function for extcommunity match. */
1457 static void *route_match_ecommunity_compile(const char *arg
)
1459 struct rmap_community
*rcom
;
1461 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1462 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1463 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1468 /* Compile function for extcommunity match. */
1469 static void route_match_ecommunity_free(void *rule
)
1471 struct rmap_community
*rcom
= rule
;
1473 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1474 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1477 /* Route map commands for community matching. */
1478 static const struct route_map_rule_cmd route_match_ecommunity_cmd
= {
1480 route_match_ecommunity
,
1481 route_match_ecommunity_compile
,
1482 route_match_ecommunity_free
1485 /* `match nlri` and `set nlri` are replaced by `address-family ipv4`
1486 and `address-family vpnv4'. */
1488 /* `match origin' */
1489 static enum route_map_cmd_result_t
1490 route_match_origin(void *rule
, const struct prefix
*prefix
,
1491 route_map_object_t type
, void *object
)
1494 struct bgp_path_info
*path
;
1496 if (type
== RMAP_BGP
) {
1500 if (path
->attr
->origin
== *origin
)
1504 return RMAP_NOMATCH
;
1507 static void *route_match_origin_compile(const char *arg
)
1511 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
1513 if (strcmp(arg
, "igp") == 0)
1515 else if (strcmp(arg
, "egp") == 0)
1523 /* Free route map's compiled `ip address' value. */
1524 static void route_match_origin_free(void *rule
)
1526 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1529 /* Route map commands for origin matching. */
1530 static const struct route_map_rule_cmd route_match_origin_cmd
= {
1533 route_match_origin_compile
,
1534 route_match_origin_free
1537 /* match probability { */
1539 static enum route_map_cmd_result_t
1540 route_match_probability(void *rule
, const struct prefix
*prefix
,
1541 route_map_object_t type
, void *object
)
1543 long r
= frr_weak_random();
1545 switch (*(long *)rule
) {
1551 if (r
< *(long *)rule
) {
1556 return RMAP_NOMATCH
;
1559 static void *route_match_probability_compile(const char *arg
)
1565 lobule
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(long));
1575 *lobule
= RAND_MAX
/ 100 * perc
;
1581 static void route_match_probability_free(void *rule
)
1583 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1586 static const struct route_map_rule_cmd route_match_probability_cmd
= {
1588 route_match_probability
,
1589 route_match_probability_compile
,
1590 route_match_probability_free
1593 /* `match interface IFNAME' */
1594 /* Match function should return 1 if match is success else return
1596 static enum route_map_cmd_result_t
1597 route_match_interface(void *rule
, const struct prefix
*prefix
,
1598 route_map_object_t type
, void *object
)
1600 struct interface
*ifp
;
1601 struct bgp_path_info
*path
;
1603 if (type
== RMAP_BGP
) {
1607 return RMAP_NOMATCH
;
1609 ifp
= if_lookup_by_name_all_vrf((char *)rule
);
1611 if (ifp
== NULL
|| ifp
->ifindex
!= path
->attr
->nh_ifindex
)
1612 return RMAP_NOMATCH
;
1616 return RMAP_NOMATCH
;
1619 /* Route map `interface' match statement. `arg' should be
1621 static void *route_match_interface_compile(const char *arg
)
1623 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1626 /* Free route map's compiled `interface' value. */
1627 static void route_match_interface_free(void *rule
)
1629 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1632 /* Route map commands for ip address matching. */
1633 static const struct route_map_rule_cmd route_match_interface_cmd
= {
1635 route_match_interface
,
1636 route_match_interface_compile
,
1637 route_match_interface_free
1642 /* `set ip next-hop IP_ADDRESS' */
1644 /* Match function return 1 if match is success else return zero. */
1645 static enum route_map_cmd_result_t
1646 route_match_tag(void *rule
, const struct prefix
*prefix
,
1647 route_map_object_t type
, void *object
)
1650 struct bgp_path_info
*path
;
1652 if (type
== RMAP_BGP
) {
1656 return ((path
->attr
->tag
== *tag
) ? RMAP_MATCH
: RMAP_NOMATCH
);
1659 return RMAP_NOMATCH
;
1663 /* Route map commands for tag matching. */
1664 static const struct route_map_rule_cmd route_match_tag_cmd
= {
1667 route_map_rule_tag_compile
,
1668 route_map_rule_tag_free
,
1671 static enum route_map_cmd_result_t
1672 route_set_srte_color(void *rule
, const struct prefix
*prefix
,
1673 route_map_object_t type
, void *object
)
1675 uint32_t *srte_color
= rule
;
1676 struct bgp_path_info
*path
;
1678 if (type
!= RMAP_BGP
)
1683 path
->attr
->srte_color
= *srte_color
;
1684 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_SRTE_COLOR
);
1689 /* Route map `sr-te color' compile function */
1690 static void *route_set_srte_color_compile(const char *arg
)
1694 color
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint32_t));
1700 /* Free route map's compiled `sr-te color' value. */
1701 static void route_set_srte_color_free(void *rule
)
1703 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1706 /* Route map commands for sr-te color set. */
1707 struct route_map_rule_cmd route_set_srte_color_cmd
= {
1708 "sr-te color", route_set_srte_color
, route_set_srte_color_compile
,
1709 route_set_srte_color_free
};
1711 /* Set nexthop to object. ojbect must be pointer to struct attr. */
1712 struct rmap_ip_nexthop_set
{
1713 struct in_addr
*address
;
1718 static enum route_map_cmd_result_t
1719 route_set_ip_nexthop(void *rule
, const struct prefix
*prefix
,
1720 route_map_object_t type
, void *object
)
1722 struct rmap_ip_nexthop_set
*rins
= rule
;
1723 struct bgp_path_info
*path
;
1726 if (type
!= RMAP_BGP
)
1729 if (prefix
->family
== AF_INET6
)
1735 if (rins
->unchanged
) {
1736 SET_FLAG(path
->attr
->rmap_change_flags
,
1737 BATTR_RMAP_NEXTHOP_UNCHANGED
);
1738 } else if (rins
->peer_address
) {
1739 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
1740 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
1742 && sockunion_family(peer
->su_remote
) == AF_INET
) {
1743 path
->attr
->nexthop
.s_addr
=
1744 sockunion2ip(peer
->su_remote
);
1745 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1746 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
1747 /* The next hop value will be set as part of
1748 * packet rewrite. Set the flags here to indicate
1749 * that rewrite needs to be done.
1750 * Also, clear the value.
1752 SET_FLAG(path
->attr
->rmap_change_flags
,
1753 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
1754 path
->attr
->nexthop
.s_addr
= INADDR_ANY
;
1757 /* Set next hop value. */
1758 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1759 path
->attr
->nexthop
= *rins
->address
;
1760 SET_FLAG(path
->attr
->rmap_change_flags
,
1761 BATTR_RMAP_IPV4_NHOP_CHANGED
);
1762 /* case for MP-BGP : MPLS VPN */
1763 path
->attr
->mp_nexthop_global_in
= *rins
->address
;
1764 path
->attr
->mp_nexthop_len
= sizeof(*rins
->address
);
1770 /* Route map `ip nexthop' compile function. Given string is converted
1771 to struct in_addr structure. */
1772 static void *route_set_ip_nexthop_compile(const char *arg
)
1774 struct rmap_ip_nexthop_set
*rins
;
1775 struct in_addr
*address
= NULL
;
1776 int peer_address
= 0;
1780 if (strcmp(arg
, "peer-address") == 0)
1782 else if (strcmp(arg
, "unchanged") == 0)
1785 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1786 sizeof(struct in_addr
));
1787 ret
= inet_aton(arg
, address
);
1790 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
1795 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1796 sizeof(struct rmap_ip_nexthop_set
));
1798 rins
->address
= address
;
1799 rins
->peer_address
= peer_address
;
1800 rins
->unchanged
= unchanged
;
1805 /* Free route map's compiled `ip nexthop' value. */
1806 static void route_set_ip_nexthop_free(void *rule
)
1808 struct rmap_ip_nexthop_set
*rins
= rule
;
1810 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
->address
);
1812 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
);
1815 /* Route map commands for ip nexthop set. */
1816 static const struct route_map_rule_cmd route_set_ip_nexthop_cmd
= {
1818 route_set_ip_nexthop
,
1819 route_set_ip_nexthop_compile
,
1820 route_set_ip_nexthop_free
1823 /* `set local-preference LOCAL_PREF' */
1825 /* Set local preference. */
1826 static enum route_map_cmd_result_t
1827 route_set_local_pref(void *rule
, const struct prefix
*prefix
,
1828 route_map_object_t type
, void *object
)
1830 struct rmap_value
*rv
;
1831 struct bgp_path_info
*path
;
1832 uint32_t locpref
= 0;
1834 if (type
== RMAP_BGP
) {
1835 /* Fetch routemap's rule information. */
1839 /* Set local preference value. */
1840 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
))
1841 locpref
= path
->attr
->local_pref
;
1843 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
);
1844 path
->attr
->local_pref
=
1845 route_value_adjust(rv
, locpref
, path
->peer
);
1851 /* Set local preference rule structure. */
1852 static const struct route_map_rule_cmd route_set_local_pref_cmd
= {
1854 route_set_local_pref
,
1855 route_value_compile
,
1859 /* `set weight WEIGHT' */
1862 static enum route_map_cmd_result_t
1863 route_set_weight(void *rule
, const struct prefix
*prefix
,
1864 route_map_object_t type
, void *object
)
1866 struct rmap_value
*rv
;
1867 struct bgp_path_info
*path
;
1869 if (type
== RMAP_BGP
) {
1870 /* Fetch routemap's rule information. */
1874 /* Set weight value. */
1875 path
->attr
->weight
= route_value_adjust(rv
, 0, path
->peer
);
1881 /* Set local preference rule structure. */
1882 static const struct route_map_rule_cmd route_set_weight_cmd
= {
1885 route_value_compile
,
1889 /* `set distance DISTANCE */
1890 static enum route_map_cmd_result_t
1891 route_set_distance(void *rule
, const struct prefix
*prefix
,
1892 route_map_object_t type
, void *object
)
1894 struct bgp_path_info
*path
= object
;
1895 struct rmap_value
*rv
= rule
;
1897 if (type
!= RMAP_BGP
)
1900 path
->attr
->distance
= rv
->value
;
1905 /* set distance rule structure */
1906 static const struct route_map_rule_cmd route_set_distance_cmd
= {
1909 route_value_compile
,
1913 /* `set metric METRIC' */
1915 /* Set metric to attribute. */
1916 static enum route_map_cmd_result_t
1917 route_set_metric(void *rule
, const struct prefix
*prefix
,
1918 route_map_object_t type
, void *object
)
1920 struct rmap_value
*rv
;
1921 struct bgp_path_info
*path
;
1924 if (type
== RMAP_BGP
) {
1925 /* Fetch routemap's rule information. */
1929 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
))
1930 med
= path
->attr
->med
;
1932 path
->attr
->med
= route_value_adjust(rv
, med
, path
->peer
);
1933 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
);
1938 /* Set metric rule structure. */
1939 static const struct route_map_rule_cmd route_set_metric_cmd
= {
1942 route_value_compile
,
1946 /* `set table (1-4294967295)' */
1948 static enum route_map_cmd_result_t
route_set_table_id(void *rule
,
1949 const struct prefix
*prefix
,
1950 route_map_object_t type
,
1953 struct rmap_value
*rv
;
1954 struct bgp_path_info
*path
;
1956 if (type
== RMAP_BGP
) {
1957 /* Fetch routemap's rule information. */
1961 path
->attr
->rmap_table_id
= rv
->value
;
1966 /* Set table_id rule structure. */
1967 static const struct route_map_rule_cmd route_set_table_id_cmd
= {
1970 route_value_compile
,
1974 /* `set as-path prepend ASPATH' */
1976 /* For AS path prepend mechanism. */
1977 static enum route_map_cmd_result_t
1978 route_set_aspath_prepend(void *rule
, const struct prefix
*prefix
,
1979 route_map_object_t type
, void *object
)
1981 struct aspath
*aspath
;
1983 struct bgp_path_info
*path
;
1985 if (type
== RMAP_BGP
) {
1988 if (path
->attr
->aspath
->refcnt
)
1989 new = aspath_dup(path
->attr
->aspath
);
1991 new = path
->attr
->aspath
;
1993 if ((uintptr_t)rule
> 10) {
1995 aspath_prepend(aspath
, new);
1997 as_t as
= aspath_leftmost(new);
1999 as
= path
->peer
->as
;
2000 new = aspath_add_seq_n(new, as
, (uintptr_t)rule
);
2003 path
->attr
->aspath
= new;
2009 static void *route_set_aspath_prepend_compile(const char *arg
)
2013 if (sscanf(arg
, "last-as %u", &num
) == 1 && num
> 0 && num
<= 10)
2014 return (void *)(uintptr_t)num
;
2016 return route_aspath_compile(arg
);
2019 static void route_set_aspath_prepend_free(void *rule
)
2021 if ((uintptr_t)rule
> 10)
2022 route_aspath_free(rule
);
2026 /* Set as-path prepend rule structure. */
2027 static const struct route_map_rule_cmd route_set_aspath_prepend_cmd
= {
2029 route_set_aspath_prepend
,
2030 route_set_aspath_prepend_compile
,
2031 route_set_aspath_prepend_free
,
2034 /* `set as-path exclude ASn' */
2036 /* For ASN exclude mechanism.
2037 * Iterate over ASns requested and filter them from the given AS_PATH one by
2039 * Make a deep copy of existing AS_PATH, but for the first ASn only.
2041 static enum route_map_cmd_result_t
2042 route_set_aspath_exclude(void *rule
, const struct prefix
*dummy
,
2043 route_map_object_t type
, void *object
)
2045 struct aspath
*new_path
, *exclude_path
;
2046 struct bgp_path_info
*path
;
2048 if (type
== RMAP_BGP
) {
2049 exclude_path
= rule
;
2051 if (path
->attr
->aspath
->refcnt
)
2052 new_path
= aspath_dup(path
->attr
->aspath
);
2054 new_path
= path
->attr
->aspath
;
2055 path
->attr
->aspath
=
2056 aspath_filter_exclude(new_path
, exclude_path
);
2061 /* Set ASn exlude rule structure. */
2062 static const struct route_map_rule_cmd route_set_aspath_exclude_cmd
= {
2064 route_set_aspath_exclude
,
2065 route_aspath_compile
,
2069 /* `set community COMMUNITY' */
2070 struct rmap_com_set
{
2071 struct community
*com
;
2076 /* For community set mechanism. */
2077 static enum route_map_cmd_result_t
2078 route_set_community(void *rule
, const struct prefix
*prefix
,
2079 route_map_object_t type
, void *object
)
2081 struct rmap_com_set
*rcs
;
2082 struct bgp_path_info
*path
;
2084 struct community
*new = NULL
;
2085 struct community
*old
;
2086 struct community
*merge
;
2088 if (type
== RMAP_BGP
) {
2092 old
= attr
->community
;
2096 attr
->flag
&= ~(ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
));
2097 attr
->community
= NULL
;
2098 /* See the longer comment down below. */
2099 if (old
&& old
->refcnt
== 0)
2100 community_free(&old
);
2104 /* "additive" case. */
2105 if (rcs
->additive
&& old
) {
2106 merge
= community_merge(community_dup(old
), rcs
->com
);
2108 new = community_uniq_sort(merge
);
2109 community_free(&merge
);
2111 new = community_dup(rcs
->com
);
2113 /* HACK: if the old community is not intern'd,
2114 * we should free it here, or all reference to it may be
2116 * Really need to cleanup attribute caching sometime.
2118 if (old
&& old
->refcnt
== 0)
2119 community_free(&old
);
2121 /* will be interned by caller if required */
2122 attr
->community
= new;
2124 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
2130 /* Compile function for set community. */
2131 static void *route_set_community_compile(const char *arg
)
2133 struct rmap_com_set
*rcs
;
2134 struct community
*com
= NULL
;
2139 if (strcmp(arg
, "none") == 0)
2142 sp
= strstr(arg
, "additive");
2144 if (sp
&& sp
> arg
) {
2145 /* "additive" keyword is included. */
2150 com
= community_str2com(arg
);
2159 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
2161 rcs
->additive
= additive
;
2167 /* Free function for set community. */
2168 static void route_set_community_free(void *rule
)
2170 struct rmap_com_set
*rcs
= rule
;
2173 community_free(&rcs
->com
);
2174 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
2177 /* Set community rule structure. */
2178 static const struct route_map_rule_cmd route_set_community_cmd
= {
2180 route_set_community
,
2181 route_set_community_compile
,
2182 route_set_community_free
,
2185 /* `set community COMMUNITY' */
2186 struct rmap_lcom_set
{
2187 struct lcommunity
*lcom
;
2193 /* For lcommunity set mechanism. */
2194 static enum route_map_cmd_result_t
2195 route_set_lcommunity(void *rule
, const struct prefix
*prefix
,
2196 route_map_object_t type
, void *object
)
2198 struct rmap_lcom_set
*rcs
;
2199 struct bgp_path_info
*path
;
2201 struct lcommunity
*new = NULL
;
2202 struct lcommunity
*old
;
2203 struct lcommunity
*merge
;
2205 if (type
== RMAP_BGP
) {
2209 old
= attr
->lcommunity
;
2214 ~(ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
));
2215 attr
->lcommunity
= NULL
;
2217 /* See the longer comment down below. */
2218 if (old
&& old
->refcnt
== 0)
2219 lcommunity_free(&old
);
2223 if (rcs
->additive
&& old
) {
2224 merge
= lcommunity_merge(lcommunity_dup(old
),
2227 new = lcommunity_uniq_sort(merge
);
2228 lcommunity_free(&merge
);
2230 new = lcommunity_dup(rcs
->lcom
);
2232 /* HACK: if the old large-community is not intern'd,
2233 * we should free it here, or all reference to it may be
2235 * Really need to cleanup attribute caching sometime.
2237 if (old
&& old
->refcnt
== 0)
2238 lcommunity_free(&old
);
2240 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
2241 attr
->lcommunity
= new;
2243 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
);
2249 /* Compile function for set community. */
2250 static void *route_set_lcommunity_compile(const char *arg
)
2252 struct rmap_lcom_set
*rcs
;
2253 struct lcommunity
*lcom
= NULL
;
2258 if (strcmp(arg
, "none") == 0)
2261 sp
= strstr(arg
, "additive");
2263 if (sp
&& sp
> arg
) {
2264 /* "additive" keyworkd is included. */
2269 lcom
= lcommunity_str2com(arg
);
2278 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
2280 rcs
->additive
= additive
;
2286 /* Free function for set lcommunity. */
2287 static void route_set_lcommunity_free(void *rule
)
2289 struct rmap_lcom_set
*rcs
= rule
;
2292 lcommunity_free(&rcs
->lcom
);
2294 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
2297 /* Set community rule structure. */
2298 static const struct route_map_rule_cmd route_set_lcommunity_cmd
= {
2300 route_set_lcommunity
,
2301 route_set_lcommunity_compile
,
2302 route_set_lcommunity_free
,
2305 /* `set large-comm-list (<1-99>|<100-500>|WORD) delete' */
2307 /* For large community set mechanism. */
2308 static enum route_map_cmd_result_t
2309 route_set_lcommunity_delete(void *rule
, const struct prefix
*pfx
,
2310 route_map_object_t type
, void *object
)
2312 struct community_list
*list
;
2313 struct lcommunity
*merge
;
2314 struct lcommunity
*new;
2315 struct lcommunity
*old
;
2316 struct bgp_path_info
*path
;
2317 struct rmap_community
*rcom
= rule
;
2319 if (type
== RMAP_BGP
) {
2324 list
= community_list_lookup(bgp_clist
, rcom
->name
,
2326 LARGE_COMMUNITY_LIST_MASTER
);
2327 old
= path
->attr
->lcommunity
;
2330 merge
= lcommunity_list_match_delete(
2331 lcommunity_dup(old
), list
);
2332 new = lcommunity_uniq_sort(merge
);
2333 lcommunity_free(&merge
);
2335 /* HACK: if the old community is not intern'd,
2336 * we should free it here, or all reference to it may be
2338 * Really need to cleanup attribute caching sometime.
2340 if (old
->refcnt
== 0)
2341 lcommunity_free(&old
);
2343 if (new->size
== 0) {
2344 path
->attr
->lcommunity
= NULL
;
2345 path
->attr
->flag
&= ~ATTR_FLAG_BIT(
2346 BGP_ATTR_LARGE_COMMUNITIES
);
2347 lcommunity_free(&new);
2349 path
->attr
->lcommunity
= new;
2350 path
->attr
->flag
|= ATTR_FLAG_BIT(
2351 BGP_ATTR_LARGE_COMMUNITIES
);
2359 /* Compile function for set lcommunity. */
2360 static void *route_set_lcommunity_delete_compile(const char *arg
)
2362 struct rmap_community
*rcom
;
2366 frrstr_split(arg
, " ", &splits
, &num
);
2368 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2369 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, splits
[0]);
2370 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2372 for (int i
= 0; i
< num
; i
++)
2373 XFREE(MTYPE_TMP
, splits
[i
]);
2374 XFREE(MTYPE_TMP
, splits
);
2379 /* Free function for set lcommunity. */
2380 static void route_set_lcommunity_delete_free(void *rule
)
2382 struct rmap_community
*rcom
= rule
;
2384 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2385 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2388 /* Set lcommunity rule structure. */
2389 static const struct route_map_rule_cmd route_set_lcommunity_delete_cmd
= {
2391 route_set_lcommunity_delete
,
2392 route_set_lcommunity_delete_compile
,
2393 route_set_lcommunity_delete_free
,
2397 /* `set comm-list (<1-99>|<100-500>|WORD) delete' */
2399 /* For community set mechanism. */
2400 static enum route_map_cmd_result_t
2401 route_set_community_delete(void *rule
, const struct prefix
*prefix
,
2402 route_map_object_t type
, void *object
)
2404 struct community_list
*list
;
2405 struct community
*merge
;
2406 struct community
*new;
2407 struct community
*old
;
2408 struct bgp_path_info
*path
;
2409 struct rmap_community
*rcom
= rule
;
2411 if (type
== RMAP_BGP
) {
2416 list
= community_list_lookup(bgp_clist
, rcom
->name
,
2418 COMMUNITY_LIST_MASTER
);
2419 old
= path
->attr
->community
;
2422 merge
= community_list_match_delete(community_dup(old
),
2424 new = community_uniq_sort(merge
);
2425 community_free(&merge
);
2427 /* HACK: if the old community is not intern'd,
2428 * we should free it here, or all reference to it may be
2430 * Really need to cleanup attribute caching sometime.
2432 if (old
->refcnt
== 0)
2433 community_free(&old
);
2435 if (new->size
== 0) {
2436 path
->attr
->community
= NULL
;
2438 ~ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
2439 community_free(&new);
2441 path
->attr
->community
= new;
2443 ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
2451 /* Compile function for set community. */
2452 static void *route_set_community_delete_compile(const char *arg
)
2454 struct rmap_community
*rcom
;
2458 frrstr_split(arg
, " ", &splits
, &num
);
2460 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2461 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, splits
[0]);
2462 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2464 for (int i
= 0; i
< num
; i
++)
2465 XFREE(MTYPE_TMP
, splits
[i
]);
2466 XFREE(MTYPE_TMP
, splits
);
2471 /* Free function for set community. */
2472 static void route_set_community_delete_free(void *rule
)
2474 struct rmap_community
*rcom
= rule
;
2476 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2477 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2480 /* Set community rule structure. */
2481 static const struct route_map_rule_cmd route_set_community_delete_cmd
= {
2483 route_set_community_delete
,
2484 route_set_community_delete_compile
,
2485 route_set_community_delete_free
,
2488 /* `set extcommunity rt COMMUNITY' */
2490 /* For community set mechanism. Used by _rt and _soo. */
2491 static enum route_map_cmd_result_t
2492 route_set_ecommunity(void *rule
, const struct prefix
*prefix
,
2493 route_map_object_t type
, void *object
)
2495 struct ecommunity
*ecom
;
2496 struct ecommunity
*new_ecom
;
2497 struct ecommunity
*old_ecom
;
2498 struct bgp_path_info
*path
;
2500 if (type
== RMAP_BGP
) {
2507 /* We assume additive for Extended Community. */
2508 old_ecom
= path
->attr
->ecommunity
;
2511 new_ecom
= ecommunity_merge(ecommunity_dup(old_ecom
),
2514 /* old_ecom->refcnt = 1 => owned elsewhere, e.g.
2515 * bgp_update_receive()
2516 * ->refcnt = 0 => set by a previous route-map
2518 if (!old_ecom
->refcnt
)
2519 ecommunity_free(&old_ecom
);
2521 new_ecom
= ecommunity_dup(ecom
);
2523 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
2524 path
->attr
->ecommunity
= new_ecom
;
2526 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
);
2531 /* Compile function for set community. */
2532 static void *route_set_ecommunity_rt_compile(const char *arg
)
2534 struct ecommunity
*ecom
;
2536 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_ROUTE_TARGET
, 0);
2539 return ecommunity_intern(ecom
);
2542 /* Free function for set community. Used by _rt and _soo */
2543 static void route_set_ecommunity_free(void *rule
)
2545 struct ecommunity
*ecom
= rule
;
2546 ecommunity_unintern(&ecom
);
2549 /* Set community rule structure. */
2550 static const struct route_map_rule_cmd route_set_ecommunity_rt_cmd
= {
2552 route_set_ecommunity
,
2553 route_set_ecommunity_rt_compile
,
2554 route_set_ecommunity_free
,
2557 /* `set extcommunity soo COMMUNITY' */
2559 /* Compile function for set community. */
2560 static void *route_set_ecommunity_soo_compile(const char *arg
)
2562 struct ecommunity
*ecom
;
2564 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_SITE_ORIGIN
, 0);
2568 return ecommunity_intern(ecom
);
2571 /* Set community rule structure. */
2572 static const struct route_map_rule_cmd route_set_ecommunity_soo_cmd
= {
2574 route_set_ecommunity
,
2575 route_set_ecommunity_soo_compile
,
2576 route_set_ecommunity_free
,
2579 /* `set extcommunity bandwidth' */
2581 struct rmap_ecomm_lb_set
{
2583 #define RMAP_ECOMM_LB_SET_VALUE 1
2584 #define RMAP_ECOMM_LB_SET_CUMUL 2
2585 #define RMAP_ECOMM_LB_SET_NUM_MPATH 3
2590 static enum route_map_cmd_result_t
2591 route_set_ecommunity_lb(void *rule
, const struct prefix
*prefix
,
2592 route_map_object_t type
, void *object
)
2594 struct rmap_ecomm_lb_set
*rels
= rule
;
2595 struct bgp_path_info
*path
;
2597 struct ecommunity ecom_lb
= {0};
2598 struct ecommunity_val lb_eval
;
2599 uint32_t bw_bytes
= 0;
2600 uint16_t mpath_count
= 0;
2601 struct ecommunity
*new_ecom
;
2602 struct ecommunity
*old_ecom
;
2605 if (type
!= RMAP_BGP
)
2610 if (!peer
|| !peer
->bgp
)
2613 /* Build link bandwidth extended community */
2614 as
= (peer
->bgp
->as
> BGP_AS_MAX
) ? BGP_AS_TRANS
: peer
->bgp
->as
;
2615 if (rels
->lb_type
== RMAP_ECOMM_LB_SET_VALUE
) {
2616 bw_bytes
= ((uint64_t)rels
->bw
* 1000 * 1000) / 8;
2617 } else if (rels
->lb_type
== RMAP_ECOMM_LB_SET_CUMUL
) {
2618 /* process this only for the best path. */
2619 if (!CHECK_FLAG(path
->flags
, BGP_PATH_SELECTED
))
2622 bw_bytes
= (uint32_t)bgp_path_info_mpath_cumbw(path
);
2626 } else if (rels
->lb_type
== RMAP_ECOMM_LB_SET_NUM_MPATH
) {
2628 /* process this only for the best path. */
2629 if (!CHECK_FLAG(path
->flags
, BGP_PATH_SELECTED
))
2632 bw_bytes
= ((uint64_t)peer
->bgp
->lb_ref_bw
* 1000 * 1000) / 8;
2633 mpath_count
= bgp_path_info_mpath_count(path
) + 1;
2634 bw_bytes
*= mpath_count
;
2637 encode_lb_extcomm(as
, bw_bytes
, rels
->non_trans
, &lb_eval
);
2639 /* add to route or merge with existing */
2640 old_ecom
= path
->attr
->ecommunity
;
2642 new_ecom
= ecommunity_dup(old_ecom
);
2643 ecommunity_add_val(new_ecom
, &lb_eval
, true, true);
2644 if (!old_ecom
->refcnt
)
2645 ecommunity_free(&old_ecom
);
2648 ecom_lb
.unit_size
= ECOMMUNITY_SIZE
;
2649 ecom_lb
.val
= (uint8_t *)lb_eval
.val
;
2650 new_ecom
= ecommunity_dup(&ecom_lb
);
2653 /* new_ecom will be intern()'d or attr_flush()'d in call stack */
2654 path
->attr
->ecommunity
= new_ecom
;
2655 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
);
2657 /* Mark that route-map has set link bandwidth; used in attribute
2658 * setting decisions.
2660 SET_FLAG(path
->attr
->rmap_change_flags
, BATTR_RMAP_LINK_BW_SET
);
2665 static void *route_set_ecommunity_lb_compile(const char *arg
)
2667 struct rmap_ecomm_lb_set
*rels
;
2670 char bw_str
[40] = {0};
2672 bool non_trans
= false;
2675 p
= strchr(arg
, ' ');
2680 memcpy(bw_str
, arg
, len
);
2685 if (strcmp(str
, "cumulative") == 0)
2686 lb_type
= RMAP_ECOMM_LB_SET_CUMUL
;
2687 else if (strcmp(str
, "num-multipaths") == 0)
2688 lb_type
= RMAP_ECOMM_LB_SET_NUM_MPATH
;
2692 bw
= strtoul(str
, &end
, 10);
2695 lb_type
= RMAP_ECOMM_LB_SET_VALUE
;
2698 rels
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
2699 sizeof(struct rmap_ecomm_lb_set
));
2700 rels
->lb_type
= lb_type
;
2702 rels
->non_trans
= non_trans
;
2707 static void route_set_ecommunity_lb_free(void *rule
)
2709 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2712 /* Set community rule structure. */
2713 struct route_map_rule_cmd route_set_ecommunity_lb_cmd
= {
2714 "extcommunity bandwidth",
2715 route_set_ecommunity_lb
,
2716 route_set_ecommunity_lb_compile
,
2717 route_set_ecommunity_lb_free
,
2720 /* `set origin ORIGIN' */
2722 /* For origin set. */
2723 static enum route_map_cmd_result_t
2724 route_set_origin(void *rule
, const struct prefix
*prefix
,
2725 route_map_object_t type
, void *object
)
2728 struct bgp_path_info
*path
;
2730 if (type
== RMAP_BGP
) {
2734 path
->attr
->origin
= *origin
;
2740 /* Compile function for origin set. */
2741 static void *route_set_origin_compile(const char *arg
)
2745 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
2747 if (strcmp(arg
, "igp") == 0)
2749 else if (strcmp(arg
, "egp") == 0)
2757 /* Compile function for origin set. */
2758 static void route_set_origin_free(void *rule
)
2760 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2763 /* Set origin rule structure. */
2764 static const struct route_map_rule_cmd route_set_origin_cmd
= {
2767 route_set_origin_compile
,
2768 route_set_origin_free
,
2771 /* `set atomic-aggregate' */
2773 /* For atomic aggregate set. */
2774 static enum route_map_cmd_result_t
2775 route_set_atomic_aggregate(void *rule
, const struct prefix
*pfx
,
2776 route_map_object_t type
, void *object
)
2778 struct bgp_path_info
*path
;
2780 if (type
== RMAP_BGP
) {
2782 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE
);
2788 /* Compile function for atomic aggregate. */
2789 static void *route_set_atomic_aggregate_compile(const char *arg
)
2794 /* Compile function for atomic aggregate. */
2795 static void route_set_atomic_aggregate_free(void *rule
)
2800 /* Set atomic aggregate rule structure. */
2801 static const struct route_map_rule_cmd route_set_atomic_aggregate_cmd
= {
2803 route_set_atomic_aggregate
,
2804 route_set_atomic_aggregate_compile
,
2805 route_set_atomic_aggregate_free
,
2808 /* `set aggregator as AS A.B.C.D' */
2811 struct in_addr address
;
2814 static enum route_map_cmd_result_t
2815 route_set_aggregator_as(void *rule
, const struct prefix
*prefix
,
2816 route_map_object_t type
, void *object
)
2818 struct bgp_path_info
*path
;
2819 struct aggregator
*aggregator
;
2821 if (type
== RMAP_BGP
) {
2825 path
->attr
->aggregator_as
= aggregator
->as
;
2826 path
->attr
->aggregator_addr
= aggregator
->address
;
2827 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR
);
2833 static void *route_set_aggregator_as_compile(const char *arg
)
2835 struct aggregator
*aggregator
;
2841 XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct aggregator
));
2842 if (sscanf(arg
, "%s %s", as
, address
) != 2) {
2843 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
2847 aggregator
->as
= strtoul(as
, NULL
, 10);
2848 ret
= inet_aton(address
, &aggregator
->address
);
2850 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
2856 static void route_set_aggregator_as_free(void *rule
)
2858 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2861 static const struct route_map_rule_cmd route_set_aggregator_as_cmd
= {
2863 route_set_aggregator_as
,
2864 route_set_aggregator_as_compile
,
2865 route_set_aggregator_as_free
,
2868 /* Set tag to object. object must be pointer to struct bgp_path_info */
2869 static enum route_map_cmd_result_t
2870 route_set_tag(void *rule
, const struct prefix
*prefix
,
2871 route_map_object_t type
, void *object
)
2874 struct bgp_path_info
*path
;
2876 if (type
== RMAP_BGP
) {
2881 path
->attr
->tag
= *tag
;
2887 /* Route map commands for tag set. */
2888 static const struct route_map_rule_cmd route_set_tag_cmd
= {
2891 route_map_rule_tag_compile
,
2892 route_map_rule_tag_free
,
2895 /* Set label-index to object. object must be pointer to struct bgp_path_info */
2896 static enum route_map_cmd_result_t
2897 route_set_label_index(void *rule
, const struct prefix
*prefix
,
2898 route_map_object_t type
, void *object
)
2900 struct rmap_value
*rv
;
2901 struct bgp_path_info
*path
;
2902 uint32_t label_index
;
2904 if (type
== RMAP_BGP
) {
2905 /* Fetch routemap's rule information. */
2909 /* Set label-index value. */
2910 label_index
= rv
->value
;
2912 path
->attr
->label_index
= label_index
;
2913 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID
);
2920 /* Route map commands for label-index set. */
2921 static const struct route_map_rule_cmd route_set_label_index_cmd
= {
2923 route_set_label_index
,
2924 route_value_compile
,
2928 /* `match ipv6 address IP_ACCESS_LIST' */
2930 static enum route_map_cmd_result_t
2931 route_match_ipv6_address(void *rule
, const struct prefix
*prefix
,
2932 route_map_object_t type
, void *object
)
2934 struct access_list
*alist
;
2936 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET6
) {
2937 alist
= access_list_lookup(AFI_IP6
, (char *)rule
);
2939 return RMAP_NOMATCH
;
2941 return (access_list_apply(alist
, prefix
) == FILTER_DENY
2945 return RMAP_NOMATCH
;
2948 static void *route_match_ipv6_address_compile(const char *arg
)
2950 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2953 static void route_match_ipv6_address_free(void *rule
)
2955 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2958 /* Route map commands for ip address matching. */
2959 static const struct route_map_rule_cmd route_match_ipv6_address_cmd
= {
2961 route_match_ipv6_address
,
2962 route_match_ipv6_address_compile
,
2963 route_match_ipv6_address_free
2966 /* `match ipv6 next-hop IP_ADDRESS' */
2968 static enum route_map_cmd_result_t
2969 route_match_ipv6_next_hop(void *rule
, const struct prefix
*prefix
,
2970 route_map_object_t type
, void *object
)
2972 struct in6_addr
*addr
= rule
;
2973 struct bgp_path_info
*path
;
2975 if (type
== RMAP_BGP
) {
2978 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
))
2981 if (path
->attr
->mp_nexthop_len
2982 == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
2983 && IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_local
, rule
))
2986 return RMAP_NOMATCH
;
2989 return RMAP_NOMATCH
;
2992 static void *route_match_ipv6_next_hop_compile(const char *arg
)
2994 struct in6_addr
*address
;
2997 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2999 ret
= inet_pton(AF_INET6
, arg
, address
);
3001 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3008 static void route_match_ipv6_next_hop_free(void *rule
)
3010 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3013 static const struct route_map_rule_cmd route_match_ipv6_next_hop_cmd
= {
3015 route_match_ipv6_next_hop
,
3016 route_match_ipv6_next_hop_compile
,
3017 route_match_ipv6_next_hop_free
3020 /* `match ip next-hop IP_ADDRESS' */
3022 static enum route_map_cmd_result_t
3023 route_match_ipv4_next_hop(void *rule
, const struct prefix
*prefix
,
3024 route_map_object_t type
, void *object
)
3026 struct in_addr
*addr
= rule
;
3027 struct bgp_path_info
*path
;
3029 if (type
== RMAP_BGP
) {
3032 if (path
->attr
->nexthop
.s_addr
== addr
->s_addr
||
3033 (path
->attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV4
&&
3034 IPV4_ADDR_SAME(&path
->attr
->mp_nexthop_global_in
, addr
)))
3037 return RMAP_NOMATCH
;
3040 return RMAP_NOMATCH
;
3043 static void *route_match_ipv4_next_hop_compile(const char *arg
)
3045 struct in_addr
*address
;
3048 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3050 ret
= inet_pton(AF_INET
, arg
, address
);
3052 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3059 static void route_match_ipv4_next_hop_free(void *rule
)
3061 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3064 static const struct route_map_rule_cmd route_match_ipv4_next_hop_cmd
= {
3065 "ip next-hop address",
3066 route_match_ipv4_next_hop
,
3067 route_match_ipv4_next_hop_compile
,
3068 route_match_ipv4_next_hop_free
3071 /* `match ipv6 address prefix-list PREFIX_LIST' */
3073 static enum route_map_cmd_result_t
3074 route_match_ipv6_address_prefix_list(void *rule
, const struct prefix
*prefix
,
3075 route_map_object_t type
, void *object
)
3077 return route_match_address_prefix_list(rule
, AFI_IP6
, prefix
, type
,
3081 static void *route_match_ipv6_address_prefix_list_compile(const char *arg
)
3083 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
3086 static void route_match_ipv6_address_prefix_list_free(void *rule
)
3088 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3091 static const struct route_map_rule_cmd
3092 route_match_ipv6_address_prefix_list_cmd
= {
3093 "ipv6 address prefix-list",
3094 route_match_ipv6_address_prefix_list
,
3095 route_match_ipv6_address_prefix_list_compile
,
3096 route_match_ipv6_address_prefix_list_free
3099 /* `match ipv6 next-hop type <TYPE>' */
3101 static enum route_map_cmd_result_t
3102 route_match_ipv6_next_hop_type(void *rule
, const struct prefix
*prefix
,
3103 route_map_object_t type
, void *object
)
3105 struct bgp_path_info
*path
;
3106 struct in6_addr
*addr
= rule
;
3108 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET6
) {
3109 path
= (struct bgp_path_info
*)object
;
3111 return RMAP_NOMATCH
;
3113 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
)
3114 && !path
->attr
->nh_ifindex
)
3117 return RMAP_NOMATCH
;
3120 static void *route_match_ipv6_next_hop_type_compile(const char *arg
)
3122 struct in6_addr
*address
;
3125 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3127 ret
= inet_pton(AF_INET6
, "::0", address
);
3129 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3136 static void route_match_ipv6_next_hop_type_free(void *rule
)
3138 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3141 static const struct route_map_rule_cmd
3142 route_match_ipv6_next_hop_type_cmd
= {
3143 "ipv6 next-hop type",
3144 route_match_ipv6_next_hop_type
,
3145 route_match_ipv6_next_hop_type_compile
,
3146 route_match_ipv6_next_hop_type_free
3149 /* `set ipv6 nexthop global IP_ADDRESS' */
3151 /* Set nexthop to object. ojbect must be pointer to struct attr. */
3152 static enum route_map_cmd_result_t
3153 route_set_ipv6_nexthop_global(void *rule
, const struct prefix
*p
,
3154 route_map_object_t type
, void *object
)
3156 struct in6_addr
*address
;
3157 struct bgp_path_info
*path
;
3159 if (type
== RMAP_BGP
) {
3160 /* Fetch routemap's rule information. */
3164 /* Set next hop value. */
3165 path
->attr
->mp_nexthop_global
= *address
;
3167 /* Set nexthop length. */
3168 if (path
->attr
->mp_nexthop_len
== 0)
3169 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL
;
3171 SET_FLAG(path
->attr
->rmap_change_flags
,
3172 BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED
);
3178 /* Route map `ip next-hop' compile function. Given string is converted
3179 to struct in_addr structure. */
3180 static void *route_set_ipv6_nexthop_global_compile(const char *arg
)
3183 struct in6_addr
*address
;
3185 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3187 ret
= inet_pton(AF_INET6
, arg
, address
);
3190 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3197 /* Free route map's compiled `ip next-hop' value. */
3198 static void route_set_ipv6_nexthop_global_free(void *rule
)
3200 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3203 /* Route map commands for ip nexthop set. */
3204 static const struct route_map_rule_cmd
3205 route_set_ipv6_nexthop_global_cmd
= {
3206 "ipv6 next-hop global",
3207 route_set_ipv6_nexthop_global
,
3208 route_set_ipv6_nexthop_global_compile
,
3209 route_set_ipv6_nexthop_global_free
3212 /* Set next-hop preference value. */
3213 static enum route_map_cmd_result_t
3214 route_set_ipv6_nexthop_prefer_global(void *rule
, const struct prefix
*prefix
,
3215 route_map_object_t type
, void *object
)
3217 struct bgp_path_info
*path
;
3220 if (type
== RMAP_BGP
) {
3221 /* Fetch routemap's rule information. */
3225 if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
3226 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
)) {
3227 /* Set next hop preference to global */
3228 path
->attr
->mp_nexthop_prefer_global
= true;
3229 SET_FLAG(path
->attr
->rmap_change_flags
,
3230 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
3232 path
->attr
->mp_nexthop_prefer_global
= false;
3233 SET_FLAG(path
->attr
->rmap_change_flags
,
3234 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
3240 static void *route_set_ipv6_nexthop_prefer_global_compile(const char *arg
)
3244 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
3250 /* Free route map's compiled `ip next-hop' value. */
3251 static void route_set_ipv6_nexthop_prefer_global_free(void *rule
)
3253 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3256 /* Route map commands for ip nexthop set preferred. */
3257 static const struct route_map_rule_cmd
3258 route_set_ipv6_nexthop_prefer_global_cmd
= {
3259 "ipv6 next-hop prefer-global",
3260 route_set_ipv6_nexthop_prefer_global
,
3261 route_set_ipv6_nexthop_prefer_global_compile
,
3262 route_set_ipv6_nexthop_prefer_global_free
3265 /* `set ipv6 nexthop local IP_ADDRESS' */
3267 /* Set nexthop to object. ojbect must be pointer to struct attr. */
3268 static enum route_map_cmd_result_t
3269 route_set_ipv6_nexthop_local(void *rule
, const struct prefix
*p
,
3270 route_map_object_t type
, void *object
)
3272 struct in6_addr
*address
;
3273 struct bgp_path_info
*path
;
3275 if (type
== RMAP_BGP
) {
3276 /* Fetch routemap's rule information. */
3280 /* Set next hop value. */
3281 path
->attr
->mp_nexthop_local
= *address
;
3283 /* Set nexthop length. */
3284 if (path
->attr
->mp_nexthop_len
3285 != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
3286 path
->attr
->mp_nexthop_len
=
3287 BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
3289 SET_FLAG(path
->attr
->rmap_change_flags
,
3290 BATTR_RMAP_IPV6_LL_NHOP_CHANGED
);
3296 /* Route map `ip nexthop' compile function. Given string is converted
3297 to struct in_addr structure. */
3298 static void *route_set_ipv6_nexthop_local_compile(const char *arg
)
3301 struct in6_addr
*address
;
3303 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3305 ret
= inet_pton(AF_INET6
, arg
, address
);
3308 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3315 /* Free route map's compiled `ip nexthop' value. */
3316 static void route_set_ipv6_nexthop_local_free(void *rule
)
3318 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3321 /* Route map commands for ip nexthop set. */
3322 static const struct route_map_rule_cmd
3323 route_set_ipv6_nexthop_local_cmd
= {
3324 "ipv6 next-hop local",
3325 route_set_ipv6_nexthop_local
,
3326 route_set_ipv6_nexthop_local_compile
,
3327 route_set_ipv6_nexthop_local_free
3330 /* `set ipv6 nexthop peer-address' */
3332 /* Set nexthop to object. ojbect must be pointer to struct attr. */
3333 static enum route_map_cmd_result_t
3334 route_set_ipv6_nexthop_peer(void *rule
, const struct prefix
*pfx
,
3335 route_map_object_t type
, void *object
)
3337 struct in6_addr peer_address
;
3338 struct bgp_path_info
*path
;
3341 if (type
== RMAP_BGP
) {
3342 /* Fetch routemap's rule information. */
3346 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
3347 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
3349 && sockunion_family(peer
->su_remote
) == AF_INET6
) {
3350 peer_address
= peer
->su_remote
->sin6
.sin6_addr
;
3351 /* Set next hop value and length in attribute. */
3352 if (IN6_IS_ADDR_LINKLOCAL(&peer_address
)) {
3353 path
->attr
->mp_nexthop_local
= peer_address
;
3354 if (path
->attr
->mp_nexthop_len
3355 != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
3356 path
->attr
->mp_nexthop_len
=
3357 BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
3359 path
->attr
->mp_nexthop_global
= peer_address
;
3360 if (path
->attr
->mp_nexthop_len
== 0)
3361 path
->attr
->mp_nexthop_len
=
3362 BGP_ATTR_NHLEN_IPV6_GLOBAL
;
3365 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
3366 /* The next hop value will be set as part of packet
3368 * Set the flags here to indicate that rewrite needs to
3370 * Also, clear the value - we clear both global and
3372 * nexthops, whether we send one or both is determined
3375 SET_FLAG(path
->attr
->rmap_change_flags
,
3376 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
3377 /* clear next hop value. */
3378 memset(&(path
->attr
->mp_nexthop_global
), 0,
3379 sizeof(struct in6_addr
));
3380 memset(&(path
->attr
->mp_nexthop_local
), 0,
3381 sizeof(struct in6_addr
));
3388 /* Route map `ip next-hop' compile function. Given string is converted
3389 to struct in_addr structure. */
3390 static void *route_set_ipv6_nexthop_peer_compile(const char *arg
)
3394 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
3400 /* Free route map's compiled `ip next-hop' value. */
3401 static void route_set_ipv6_nexthop_peer_free(void *rule
)
3403 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3406 /* Route map commands for ip nexthop set. */
3407 static const struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd
= {
3408 "ipv6 next-hop peer-address",
3409 route_set_ipv6_nexthop_peer
,
3410 route_set_ipv6_nexthop_peer_compile
,
3411 route_set_ipv6_nexthop_peer_free
3414 /* `set ipv4 vpn next-hop A.B.C.D' */
3416 static enum route_map_cmd_result_t
3417 route_set_vpnv4_nexthop(void *rule
, const struct prefix
*prefix
,
3418 route_map_object_t type
, void *object
)
3420 struct in_addr
*address
;
3421 struct bgp_path_info
*path
;
3423 if (type
== RMAP_BGP
) {
3424 /* Fetch routemap's rule information. */
3428 /* Set next hop value. */
3429 path
->attr
->mp_nexthop_global_in
= *address
;
3430 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV4
;
3436 static void *route_set_vpnv4_nexthop_compile(const char *arg
)
3439 struct in_addr
*address
;
3441 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3443 ret
= inet_aton(arg
, address
);
3446 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3453 /* `set ipv6 vpn next-hop A.B.C.D' */
3455 static enum route_map_cmd_result_t
3456 route_set_vpnv6_nexthop(void *rule
, const struct prefix
*prefix
,
3457 route_map_object_t type
, void *object
)
3459 struct in6_addr
*address
;
3460 struct bgp_path_info
*path
;
3462 if (type
== RMAP_BGP
) {
3463 /* Fetch routemap's rule information. */
3467 /* Set next hop value. */
3468 memcpy(&path
->attr
->mp_nexthop_global
, address
,
3469 sizeof(struct in6_addr
));
3470 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_VPNV6_GLOBAL
;
3476 static void *route_set_vpnv6_nexthop_compile(const char *arg
)
3479 struct in6_addr
*address
;
3481 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3482 ret
= inet_pton(AF_INET6
, arg
, address
);
3485 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3492 static void route_set_vpn_nexthop_free(void *rule
)
3494 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3497 /* Route map commands for ipv4 next-hop set. */
3498 static const struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd
= {
3499 "ipv4 vpn next-hop",
3500 route_set_vpnv4_nexthop
,
3501 route_set_vpnv4_nexthop_compile
,
3502 route_set_vpn_nexthop_free
3505 /* Route map commands for ipv6 next-hop set. */
3506 static const struct route_map_rule_cmd route_set_vpnv6_nexthop_cmd
= {
3507 "ipv6 vpn next-hop",
3508 route_set_vpnv6_nexthop
,
3509 route_set_vpnv6_nexthop_compile
,
3510 route_set_vpn_nexthop_free
3513 /* `set originator-id' */
3515 /* For origin set. */
3516 static enum route_map_cmd_result_t
3517 route_set_originator_id(void *rule
, const struct prefix
*prefix
,
3518 route_map_object_t type
, void *object
)
3520 struct in_addr
*address
;
3521 struct bgp_path_info
*path
;
3523 if (type
== RMAP_BGP
) {
3527 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
);
3528 path
->attr
->originator_id
= *address
;
3534 /* Compile function for originator-id set. */
3535 static void *route_set_originator_id_compile(const char *arg
)
3538 struct in_addr
*address
;
3540 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3542 ret
= inet_aton(arg
, address
);
3545 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3552 /* Compile function for originator_id set. */
3553 static void route_set_originator_id_free(void *rule
)
3555 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3558 /* Set originator-id rule structure. */
3559 static const struct route_map_rule_cmd route_set_originator_id_cmd
= {
3561 route_set_originator_id
,
3562 route_set_originator_id_compile
,
3563 route_set_originator_id_free
,
3566 /* Add bgp route map rule. */
3567 static int bgp_route_match_add(struct vty
*vty
, const char *command
,
3568 const char *arg
, route_map_event_t type
)
3570 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
3571 int retval
= CMD_SUCCESS
;
3572 enum rmap_compile_rets ret
;
3574 ret
= route_map_add_match(index
, command
, arg
, type
);
3576 case RMAP_RULE_MISSING
:
3577 vty_out(vty
, "%% BGP Can't find rule.\n");
3578 retval
= CMD_WARNING_CONFIG_FAILED
;
3580 case RMAP_COMPILE_ERROR
:
3581 vty_out(vty
, "%% BGP Argument is malformed.\n");
3582 retval
= CMD_WARNING_CONFIG_FAILED
;
3584 case RMAP_COMPILE_SUCCESS
:
3586 * Intentionally doing nothing here.
3594 /* Delete bgp route map rule. */
3595 static int bgp_route_match_delete(struct vty
*vty
, const char *command
,
3596 const char *arg
, route_map_event_t type
)
3598 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
3599 enum rmap_compile_rets ret
;
3600 int retval
= CMD_SUCCESS
;
3601 char *dep_name
= NULL
;
3603 char *rmap_name
= NULL
;
3605 if (type
!= RMAP_EVENT_MATCH_DELETED
) {
3606 /* ignore the mundane, the types without any dependency */
3608 if ((tmpstr
= route_map_get_match_arg(index
, command
))
3611 XSTRDUP(MTYPE_ROUTE_MAP_RULE
, tmpstr
);
3613 dep_name
= XSTRDUP(MTYPE_ROUTE_MAP_RULE
, arg
);
3615 rmap_name
= XSTRDUP(MTYPE_ROUTE_MAP_NAME
, index
->map
->name
);
3618 ret
= route_map_delete_match(index
, command
, dep_name
, type
);
3620 case RMAP_RULE_MISSING
:
3621 vty_out(vty
, "%% BGP Can't find rule.\n");
3622 retval
= CMD_WARNING_CONFIG_FAILED
;
3624 case RMAP_COMPILE_ERROR
:
3625 vty_out(vty
, "%% BGP Argument is malformed.\n");
3626 retval
= CMD_WARNING_CONFIG_FAILED
;
3628 case RMAP_COMPILE_SUCCESS
:
3630 * Nothing to do here
3635 XFREE(MTYPE_ROUTE_MAP_RULE
, dep_name
);
3636 XFREE(MTYPE_ROUTE_MAP_NAME
, rmap_name
);
3642 * This is the workhorse routine for processing in/out routemap
3645 static void bgp_route_map_process_peer(const char *rmap_name
,
3646 struct route_map
*map
, struct peer
*peer
,
3647 int afi
, int safi
, int route_update
)
3649 struct bgp_filter
*filter
;
3651 if (!peer
|| !rmap_name
)
3654 filter
= &peer
->filter
[afi
][safi
];
3656 * in is for non-route-server clients,
3657 * out is for all peers
3659 if (filter
->map
[RMAP_IN
].name
3660 && (strcmp(rmap_name
, filter
->map
[RMAP_IN
].name
) == 0)) {
3661 filter
->map
[RMAP_IN
].map
= map
;
3663 if (route_update
&& peer
->status
== Established
) {
3664 if (CHECK_FLAG(peer
->af_flags
[afi
][safi
],
3665 PEER_FLAG_SOFT_RECONFIG
)) {
3666 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3668 "Processing route_map %s update on peer %s (inbound, soft-reconfig)",
3669 rmap_name
, peer
->host
);
3671 bgp_soft_reconfig_in(peer
, afi
, safi
);
3672 } else if (CHECK_FLAG(peer
->cap
,
3673 PEER_CAP_REFRESH_OLD_RCV
)
3674 || CHECK_FLAG(peer
->cap
,
3675 PEER_CAP_REFRESH_NEW_RCV
)) {
3676 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3678 "Processing route_map %s update on peer %s (inbound, route-refresh)",
3679 rmap_name
, peer
->host
);
3680 bgp_route_refresh_send(peer
, afi
, safi
, 0, 0,
3687 * For outbound, unsuppress and default-originate map change (content or
3688 * map created), merely update the "config" here, the actual route
3689 * announcement happens at the group level.
3691 if (filter
->map
[RMAP_OUT
].name
3692 && (strcmp(rmap_name
, filter
->map
[RMAP_OUT
].name
) == 0))
3693 filter
->map
[RMAP_OUT
].map
= map
;
3695 if (filter
->usmap
.name
&& (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3696 filter
->usmap
.map
= map
;
3698 if (filter
->advmap
.aname
3699 && (strcmp(rmap_name
, filter
->advmap
.aname
) == 0)) {
3700 filter
->advmap
.amap
= map
;
3703 if (filter
->advmap
.cname
3704 && (strcmp(rmap_name
, filter
->advmap
.cname
) == 0)) {
3705 filter
->advmap
.cmap
= map
;
3708 if (peer
->default_rmap
[afi
][safi
].name
3709 && (strcmp(rmap_name
, peer
->default_rmap
[afi
][safi
].name
) == 0))
3710 peer
->default_rmap
[afi
][safi
].map
= map
;
3712 /* Notify BGP conditional advertisement scanner percess */
3713 peer
->advmap_info
[afi
][safi
].config_change
= true;
3716 static void bgp_route_map_update_peer_group(const char *rmap_name
,
3717 struct route_map
*map
,
3720 struct peer_group
*group
;
3721 struct listnode
*node
, *nnode
;
3722 struct bgp_filter
*filter
;
3729 /* All the peers have been updated correctly already. This is
3730 * just updating the placeholder data. No real update required.
3732 for (ALL_LIST_ELEMENTS(bgp
->group
, node
, nnode
, group
)) {
3733 FOREACH_AFI_SAFI (afi
, safi
) {
3734 filter
= &group
->conf
->filter
[afi
][safi
];
3736 for (direct
= RMAP_IN
; direct
< RMAP_MAX
; direct
++) {
3737 if ((filter
->map
[direct
].name
)
3738 && (strcmp(rmap_name
,
3739 filter
->map
[direct
].name
)
3741 filter
->map
[direct
].map
= map
;
3744 if (filter
->usmap
.name
3745 && (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3746 filter
->usmap
.map
= map
;
3752 * Note that if an extreme number (tens of thousands) of route-maps are in use
3753 * and if bgp has an extreme number of peers, network statements, etc then this
3754 * function can consume a lot of cycles. This is due to this function being
3755 * called for each route-map and within this function we walk the list of peers,
3756 * network statements, etc looking to see if they use this route-map.
3758 static void bgp_route_map_process_update(struct bgp
*bgp
, const char *rmap_name
,
3766 struct bgp_dest
*bn
;
3767 struct bgp_static
*bgp_static
;
3768 struct bgp_aggregate
*aggregate
;
3769 struct listnode
*node
, *nnode
;
3770 struct route_map
*map
;
3771 char buf
[INET6_ADDRSTRLEN
];
3773 map
= route_map_lookup_by_name(rmap_name
);
3775 for (ALL_LIST_ELEMENTS(bgp
->peer
, node
, nnode
, peer
)) {
3777 /* Ignore dummy peer-group structure */
3778 if (CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
))
3781 FOREACH_AFI_SAFI (afi
, safi
) {
3782 /* process in/out/import/export/default-orig
3784 bgp_route_map_process_peer(rmap_name
, map
, peer
, afi
,
3785 safi
, route_update
);
3789 /* for outbound/default-orig route-maps, process for groups */
3790 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
, rmap_name
,
3793 /* update peer-group config (template) */
3794 bgp_route_map_update_peer_group(rmap_name
, map
, bgp
);
3796 FOREACH_AFI_SAFI (afi
, safi
) {
3797 /* For table route-map updates. */
3798 if (!bgp_fibupd_safi(safi
))
3801 if (bgp
->table_map
[afi
][safi
].name
3802 && (strcmp(rmap_name
, bgp
->table_map
[afi
][safi
].name
)
3805 /* bgp->table_map[afi][safi].map is NULL.
3806 * i.e Route map creation event.
3807 * So update applied_counter.
3808 * If it is not NULL, i.e It may be routemap updation or
3809 * deletion. so no need to update the counter.
3811 if (!bgp
->table_map
[afi
][safi
].map
)
3812 route_map_counter_increment(map
);
3813 bgp
->table_map
[afi
][safi
].map
= map
;
3815 if (BGP_DEBUG(zebra
, ZEBRA
))
3817 "Processing route_map %s update on table map",
3820 bgp_zebra_announce_table(bgp
, afi
, safi
);
3823 /* For network route-map updates. */
3824 for (bn
= bgp_table_top(bgp
->route
[afi
][safi
]); bn
;
3825 bn
= bgp_route_next(bn
)) {
3826 bgp_static
= bgp_dest_get_bgp_static_info(bn
);
3830 if (!bgp_static
->rmap
.name
3831 || (strcmp(rmap_name
, bgp_static
->rmap
.name
) != 0))
3834 if (!bgp_static
->rmap
.map
)
3835 route_map_counter_increment(map
);
3837 bgp_static
->rmap
.map
= map
;
3839 if (route_update
&& !bgp_static
->backdoor
) {
3840 const struct prefix
*bn_p
=
3841 bgp_dest_get_prefix(bn
);
3843 if (bgp_debug_zebra(bn_p
))
3845 "Processing route_map %s update on static route %s",
3847 inet_ntop(bn_p
->family
,
3848 &bn_p
->u
.prefix
, buf
,
3850 bgp_static_update(bgp
, bn_p
, bgp_static
, afi
,
3855 /* For aggregate-address route-map updates. */
3856 for (bn
= bgp_table_top(bgp
->aggregate
[afi
][safi
]); bn
;
3857 bn
= bgp_route_next(bn
)) {
3858 aggregate
= bgp_dest_get_bgp_aggregate_info(bn
);
3864 /* Update suppress map pointer. */
3865 if (aggregate
->suppress_map_name
3866 && strmatch(aggregate
->suppress_map_name
,
3868 if (aggregate
->rmap
.map
== NULL
)
3869 route_map_counter_increment(map
);
3871 aggregate
->suppress_map
= map
;
3873 bgp_aggregate_toggle_suppressed(
3874 aggregate
, bgp
, bgp_dest_get_prefix(bn
),
3880 if (aggregate
->rmap
.name
3881 && strmatch(rmap_name
, aggregate
->rmap
.name
)) {
3882 if (aggregate
->rmap
.map
== NULL
)
3883 route_map_counter_increment(map
);
3885 aggregate
->rmap
.map
= map
;
3890 if (matched
&& route_update
) {
3891 const struct prefix
*bn_p
=
3892 bgp_dest_get_prefix(bn
);
3894 if (bgp_debug_zebra(bn_p
))
3896 "Processing route_map %s update on aggregate-address route %s",
3898 inet_ntop(bn_p
->family
,
3899 &bn_p
->u
.prefix
, buf
,
3901 bgp_aggregate_route(bgp
, bn_p
, afi
, safi
,
3907 /* For redistribute route-map updates. */
3908 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
3909 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
3910 struct list
*red_list
;
3911 struct bgp_redist
*red
;
3913 red_list
= bgp
->redist
[afi
][i
];
3917 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
3919 || (strcmp(rmap_name
, red
->rmap
.name
) != 0))
3923 route_map_counter_increment(map
);
3925 red
->rmap
.map
= map
;
3930 if (BGP_DEBUG(zebra
, ZEBRA
))
3932 "Processing route_map %s update on redistributed routes",
3935 bgp_redistribute_resend(bgp
, afi
, i
,
3940 /* for type5 command route-maps */
3941 FOREACH_AFI_SAFI (afi
, safi
) {
3942 if (!bgp
->adv_cmd_rmap
[afi
][safi
].name
3943 || strcmp(rmap_name
, bgp
->adv_cmd_rmap
[afi
][safi
].name
)
3947 /* Make sure the route-map is populated here if not already done */
3948 bgp
->adv_cmd_rmap
[afi
][safi
].map
= map
;
3950 if (BGP_DEBUG(zebra
, ZEBRA
))
3952 "Processing route_map %s update on advertise type5 route command",
3955 if (route_update
&& advertise_type5_routes(bgp
, afi
)) {
3956 bgp_evpn_withdraw_type5_routes(bgp
, afi
, safi
);
3957 bgp_evpn_advertise_type5_routes(bgp
, afi
, safi
);
3962 static void bgp_route_map_process_update_cb(char *rmap_name
)
3964 struct listnode
*node
, *nnode
;
3967 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
)) {
3968 bgp_route_map_process_update(bgp
, rmap_name
, 1);
3970 #ifdef ENABLE_BGP_VNC
3971 /* zlog_debug("%s: calling vnc_routemap_update", __func__); */
3972 vnc_routemap_update(bgp
, __func__
);
3976 vpn_policy_routemap_event(rmap_name
);
3979 int bgp_route_map_update_timer(struct thread
*thread
)
3981 bm
->t_rmap_update
= NULL
;
3983 route_map_walk_update_list(bgp_route_map_process_update_cb
);
3988 static void bgp_route_map_mark_update(const char *rmap_name
)
3990 struct listnode
*node
, *nnode
;
3993 /* If new update is received before the current timer timed out,
3994 * turn it off and start a new timer.
3996 THREAD_OFF(bm
->t_rmap_update
);
3998 /* rmap_update_timer of 0 means don't do route updates */
3999 if (bm
->rmap_update_timer
) {
4000 thread_add_timer(bm
->master
, bgp_route_map_update_timer
,
4001 NULL
, bm
->rmap_update_timer
,
4002 &bm
->t_rmap_update
);
4004 /* Signal the groups that a route-map update event has
4006 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
4007 update_group_policy_update(bgp
,
4008 BGP_POLICY_ROUTE_MAP
,
4011 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
4012 bgp_route_map_process_update(bgp
, rmap_name
, 0);
4013 #ifdef ENABLE_BGP_VNC
4014 zlog_debug("%s: calling vnc_routemap_update", __func__
);
4015 vnc_routemap_update(bgp
, __func__
);
4020 static void bgp_route_map_add(const char *rmap_name
)
4022 if (route_map_mark_updated(rmap_name
) == 0)
4023 bgp_route_map_mark_update(rmap_name
);
4025 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
4028 static void bgp_route_map_delete(const char *rmap_name
)
4030 if (route_map_mark_updated(rmap_name
) == 0)
4031 bgp_route_map_mark_update(rmap_name
);
4033 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_DELETED
);
4036 static void bgp_route_map_event(const char *rmap_name
)
4038 if (route_map_mark_updated(rmap_name
) == 0)
4039 bgp_route_map_mark_update(rmap_name
);
4041 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
4044 DEFUN (match_mac_address
,
4045 match_mac_address_cmd
,
4046 "match mac address WORD",
4049 "Match address of route\n"
4050 "MAC Access-list name\n")
4052 return bgp_route_match_add(vty
, "mac address", argv
[3]->arg
,
4053 RMAP_EVENT_FILTER_ADDED
);
4056 DEFUN (no_match_mac_address
,
4057 no_match_mac_address_cmd
,
4058 "no match mac address WORD",
4062 "Match address of route\n"
4063 "MAC acess-list name\n")
4065 return bgp_route_match_delete(vty
, "mac address", argv
[4]->arg
,
4066 RMAP_EVENT_FILTER_DELETED
);
4070 * Helper to handle the case of the user passing in a number or type string
4072 static const char *parse_evpn_rt_type(const char *num_rt_type
)
4074 switch (num_rt_type
[0]) {
4089 /* Was already full type string */
4093 DEFUN (match_evpn_route_type
,
4094 match_evpn_route_type_cmd
,
4095 "match evpn route-type <macip|2|multicast|3|prefix|5>",
4099 EVPN_TYPE_2_HELP_STR
4100 EVPN_TYPE_2_HELP_STR
4101 EVPN_TYPE_3_HELP_STR
4102 EVPN_TYPE_3_HELP_STR
4103 EVPN_TYPE_5_HELP_STR
4104 EVPN_TYPE_5_HELP_STR
)
4106 return bgp_route_match_add(vty
, "evpn route-type",
4107 parse_evpn_rt_type(argv
[3]->arg
),
4108 RMAP_EVENT_MATCH_ADDED
);
4111 DEFUN (no_match_evpn_route_type
,
4112 no_match_evpn_route_type_cmd
,
4113 "no match evpn route-type <macip|2|multicast|3|prefix|5>",
4118 EVPN_TYPE_2_HELP_STR
4119 EVPN_TYPE_2_HELP_STR
4120 EVPN_TYPE_3_HELP_STR
4121 EVPN_TYPE_3_HELP_STR
4122 EVPN_TYPE_5_HELP_STR
4123 EVPN_TYPE_5_HELP_STR
)
4125 return bgp_route_match_delete(vty
, "evpn route-type",
4126 parse_evpn_rt_type(argv
[4]->arg
),
4127 RMAP_EVENT_MATCH_DELETED
);
4131 DEFUN (match_evpn_vni
,
4133 "match evpn vni " CMD_VNI_RANGE
,
4139 return bgp_route_match_add(vty
, "evpn vni", argv
[3]->arg
,
4140 RMAP_EVENT_MATCH_ADDED
);
4143 DEFUN (no_match_evpn_vni
,
4144 no_match_evpn_vni_cmd
,
4145 "no match evpn vni " CMD_VNI_RANGE
,
4152 return bgp_route_match_delete(vty
, "evpn vni", argv
[4]->arg
,
4153 RMAP_EVENT_MATCH_DELETED
);
4156 DEFUN (match_evpn_default_route
,
4157 match_evpn_default_route_cmd
,
4158 "match evpn default-route",
4161 "default EVPN type-5 route\n")
4163 return bgp_route_match_add(vty
, "evpn default-route", NULL
,
4164 RMAP_EVENT_MATCH_ADDED
);
4167 DEFUN (no_match_evpn_default_route
,
4168 no_match_evpn_default_route_cmd
,
4169 "no match evpn default-route",
4173 "default EVPN type-5 route\n")
4175 return bgp_route_match_delete(vty
, "evpn default-route", NULL
,
4176 RMAP_EVENT_MATCH_DELETED
);
4179 DEFUN (match_evpn_rd
,
4181 "match evpn rd ASN:NN_OR_IP-ADDRESS:NN",
4184 "Route Distinguisher\n"
4185 "ASN:XX or A.B.C.D:XX\n")
4187 return bgp_route_match_add(vty
, "evpn rd", argv
[3]->arg
,
4188 RMAP_EVENT_MATCH_ADDED
);
4191 DEFUN (no_match_evpn_rd
,
4192 no_match_evpn_rd_cmd
,
4193 "no match evpn rd ASN:NN_OR_IP-ADDRESS:NN",
4197 "Route Distinguisher\n"
4198 "ASN:XX or A.B.C.D:XX\n")
4200 return bgp_route_match_delete(vty
, "evpn rd", argv
[4]->arg
,
4201 RMAP_EVENT_MATCH_DELETED
);
4204 DEFPY(match_vrl_source_vrf
,
4205 match_vrl_source_vrf_cmd
,
4206 "match source-vrf NAME$vrf_name",
4211 return bgp_route_match_add(vty
, "source-vrf", vrf_name
,
4212 RMAP_EVENT_MATCH_ADDED
);
4215 DEFPY(no_match_vrl_source_vrf
,
4216 no_match_vrl_source_vrf_cmd
,
4217 "no match source-vrf NAME$vrf_name",
4223 return bgp_route_match_delete(vty
, "source-vrf", vrf_name
,
4224 RMAP_EVENT_MATCH_DELETED
);
4229 "match peer <A.B.C.D|X:X::X:X|WORD>",
4231 "Match peer address\n"
4232 "IP address of peer\n"
4233 "IPv6 address of peer\n"
4234 "Interface name of peer\n")
4237 return bgp_route_match_add(vty
, "peer", argv
[idx_ip
]->arg
,
4238 RMAP_EVENT_MATCH_ADDED
);
4241 DEFUN (match_peer_local
,
4242 match_peer_local_cmd
,
4245 "Match peer address\n"
4246 "Static or Redistributed routes\n")
4248 return bgp_route_match_add(vty
, "peer", "local",
4249 RMAP_EVENT_MATCH_DELETED
);
4252 DEFUN (no_match_peer
,
4254 "no match peer [<local|A.B.C.D|X:X::X:X|WORD>]",
4257 "Match peer address\n"
4258 "Static or Redistributed routes\n"
4259 "IP address of peer\n"
4260 "IPv6 address of peer\n"
4261 "Interface name of peer\n")
4265 if (argc
<= idx_peer
)
4266 return bgp_route_match_delete(vty
, "peer", NULL
,
4267 RMAP_EVENT_MATCH_DELETED
);
4268 return bgp_route_match_delete(vty
, "peer", argv
[idx_peer
]->arg
,
4269 RMAP_EVENT_MATCH_DELETED
);
4272 #if defined(HAVE_LUA)
4273 DEFUN (match_command
,
4275 "match command WORD",
4277 "Run a command to match\n"
4278 "The command to run\n")
4280 return bgp_route_match_add(vty
, "command", argv
[2]->arg
,
4281 RMAP_EVENT_FILTER_ADDED
);
4284 DEFUN (no_match_command
,
4285 no_match_command_cmd
,
4286 "no match command WORD",
4289 "Run a command to match\n"
4290 "The command to run\n")
4292 return bgp_route_match_delete(vty
, "command", argv
[3]->arg
,
4293 RMAP_EVENT_FILTER_DELETED
);
4297 /* match probability */
4298 DEFUN (match_probability
,
4299 match_probability_cmd
,
4300 "match probability (0-100)",
4302 "Match portion of routes defined by percentage value\n"
4303 "Percentage of routes\n")
4306 return bgp_route_match_add(vty
, "probability", argv
[idx_number
]->arg
,
4307 RMAP_EVENT_MATCH_ADDED
);
4311 DEFUN (no_match_probability
,
4312 no_match_probability_cmd
,
4313 "no match probability [(1-99)]",
4316 "Match portion of routes defined by percentage value\n"
4317 "Percentage of routes\n")
4320 if (argc
<= idx_number
)
4321 return bgp_route_match_delete(vty
, "probability", NULL
,
4322 RMAP_EVENT_MATCH_DELETED
);
4323 return bgp_route_match_delete(vty
, "probability", argv
[idx_number
]->arg
,
4324 RMAP_EVENT_MATCH_DELETED
);
4328 DEFUN (match_ip_route_source
,
4329 match_ip_route_source_cmd
,
4330 "match ip route-source <(1-199)|(1300-2699)|WORD>",
4333 "Match advertising source address of route\n"
4334 "IP access-list number\n"
4335 "IP access-list number (expanded range)\n"
4336 "IP standard access-list name\n")
4339 return bgp_route_match_add(vty
, "ip route-source", argv
[idx_acl
]->arg
,
4340 RMAP_EVENT_FILTER_ADDED
);
4344 DEFUN (no_match_ip_route_source
,
4345 no_match_ip_route_source_cmd
,
4346 "no match ip route-source [<(1-199)|(1300-2699)|WORD>]",
4350 "Match advertising source address of route\n"
4351 "IP access-list number\n"
4352 "IP access-list number (expanded range)\n"
4353 "IP standard access-list name\n")
4356 if (argc
<= idx_number
)
4357 return bgp_route_match_delete(vty
, "ip route-source", NULL
,
4358 RMAP_EVENT_FILTER_DELETED
);
4359 return bgp_route_match_delete(vty
, "ip route-source",
4360 argv
[idx_number
]->arg
,
4361 RMAP_EVENT_FILTER_DELETED
);
4365 DEFUN (match_ip_route_source_prefix_list
,
4366 match_ip_route_source_prefix_list_cmd
,
4367 "match ip route-source prefix-list WORD",
4370 "Match advertising source address of route\n"
4371 "Match entries of prefix-lists\n"
4372 "IP prefix-list name\n")
4375 return bgp_route_match_add(vty
, "ip route-source prefix-list",
4376 argv
[idx_word
]->arg
, RMAP_EVENT_PLIST_ADDED
);
4380 DEFUN (no_match_ip_route_source_prefix_list
,
4381 no_match_ip_route_source_prefix_list_cmd
,
4382 "no match ip route-source prefix-list [WORD]",
4386 "Match advertising source address of route\n"
4387 "Match entries of prefix-lists\n"
4388 "IP prefix-list name\n")
4391 if (argc
<= idx_word
)
4392 return bgp_route_match_delete(vty
,
4393 "ip route-source prefix-list",
4394 NULL
, RMAP_EVENT_PLIST_DELETED
);
4395 return bgp_route_match_delete(vty
, "ip route-source prefix-list",
4396 argv
[idx_word
]->arg
,
4397 RMAP_EVENT_PLIST_DELETED
);
4401 DEFUN (match_local_pref
,
4402 match_local_pref_cmd
,
4403 "match local-preference (0-4294967295)",
4405 "Match local-preference of route\n"
4409 return bgp_route_match_add(vty
, "local-preference",
4410 argv
[idx_number
]->arg
,
4411 RMAP_EVENT_MATCH_ADDED
);
4415 DEFUN (no_match_local_pref
,
4416 no_match_local_pref_cmd
,
4417 "no match local-preference [(0-4294967295)]",
4420 "Match local preference of route\n"
4421 "Local preference value\n")
4423 int idx_localpref
= 3;
4424 if (argc
<= idx_localpref
)
4425 return bgp_route_match_delete(vty
, "local-preference", NULL
,
4426 RMAP_EVENT_MATCH_DELETED
);
4427 return bgp_route_match_delete(vty
, "local-preference",
4428 argv
[idx_localpref
]->arg
,
4429 RMAP_EVENT_MATCH_DELETED
);
4433 DEFUN (match_community
,
4434 match_community_cmd
,
4435 "match community <(1-99)|(100-500)|WORD> [exact-match]",
4437 "Match BGP community list\n"
4438 "Community-list number (standard)\n"
4439 "Community-list number (expanded)\n"
4440 "Community-list name\n"
4441 "Do exact matching of communities\n")
4443 int idx_comm_list
= 2;
4448 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
4449 strlen(argv
[idx_comm_list
]->arg
)
4450 + strlen("exact-match") + 2);
4452 sprintf(argstr
, "%s exact-match", argv
[idx_comm_list
]->arg
);
4454 argstr
= argv
[idx_comm_list
]->arg
;
4456 ret
= bgp_route_match_add(vty
, "community", argstr
,
4457 RMAP_EVENT_CLIST_ADDED
);
4459 if (argstr
!= argv
[idx_comm_list
]->arg
)
4460 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4465 DEFUN (no_match_community
,
4466 no_match_community_cmd
,
4467 "no match community [<(1-99)|(100-500)|WORD> [exact-match]]",
4470 "Match BGP community list\n"
4471 "Community-list number (standard)\n"
4472 "Community-list number (expanded)\n"
4473 "Community-list name\n"
4474 "Do exact matching of communities\n")
4476 return bgp_route_match_delete(vty
, "community", NULL
,
4477 RMAP_EVENT_CLIST_DELETED
);
4480 DEFUN (match_lcommunity
,
4481 match_lcommunity_cmd
,
4482 "match large-community <(1-99)|(100-500)|WORD> [exact-match]",
4484 "Match BGP large community list\n"
4485 "Large Community-list number (standard)\n"
4486 "Large Community-list number (expanded)\n"
4487 "Large Community-list name\n"
4488 "Do exact matching of communities\n")
4490 int idx_lcomm_list
= 2;
4495 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
4496 strlen(argv
[idx_lcomm_list
]->arg
)
4497 + strlen("exact-match") + 2);
4499 sprintf(argstr
, "%s exact-match", argv
[idx_lcomm_list
]->arg
);
4501 argstr
= argv
[idx_lcomm_list
]->arg
;
4503 ret
= bgp_route_match_add(vty
, "large-community", argstr
,
4504 RMAP_EVENT_LLIST_ADDED
);
4505 if (argstr
!= argv
[idx_lcomm_list
]->arg
)
4506 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4511 DEFUN (no_match_lcommunity
,
4512 no_match_lcommunity_cmd
,
4513 "no match large-community [<(1-99)|(100-500)|WORD> [exact-match]]",
4516 "Match BGP large community list\n"
4517 "Large Community-list number (standard)\n"
4518 "Large Community-list number (expanded)\n"
4519 "Large Community-list name\n"
4520 "Do exact matching of communities\n")
4522 return bgp_route_match_delete(vty
, "large-community", NULL
,
4523 RMAP_EVENT_LLIST_DELETED
);
4526 DEFUN (match_ecommunity
,
4527 match_ecommunity_cmd
,
4528 "match extcommunity <(1-99)|(100-500)|WORD>",
4530 "Match BGP/VPN extended community list\n"
4531 "Extended community-list number (standard)\n"
4532 "Extended community-list number (expanded)\n"
4533 "Extended community-list name\n")
4535 int idx_comm_list
= 2;
4536 return bgp_route_match_add(vty
, "extcommunity",
4537 argv
[idx_comm_list
]->arg
,
4538 RMAP_EVENT_ECLIST_ADDED
);
4542 DEFUN (no_match_ecommunity
,
4543 no_match_ecommunity_cmd
,
4544 "no match extcommunity [<(1-99)|(100-500)|WORD>]",
4547 "Match BGP/VPN extended community list\n"
4548 "Extended community-list number (standard)\n"
4549 "Extended community-list number (expanded)\n"
4550 "Extended community-list name\n")
4552 return bgp_route_match_delete(vty
, "extcommunity", NULL
,
4553 RMAP_EVENT_ECLIST_DELETED
);
4557 DEFUN (match_aspath
,
4559 "match as-path WORD",
4561 "Match BGP AS path list\n"
4562 "AS path access-list name\n")
4565 return bgp_route_match_add(vty
, "as-path", argv
[idx_word
]->arg
,
4566 RMAP_EVENT_ASLIST_ADDED
);
4570 DEFUN (no_match_aspath
,
4571 no_match_aspath_cmd
,
4572 "no match as-path [WORD]",
4575 "Match BGP AS path list\n"
4576 "AS path access-list name\n")
4578 return bgp_route_match_delete(vty
, "as-path", NULL
,
4579 RMAP_EVENT_ASLIST_DELETED
);
4583 DEFUN (match_origin
,
4585 "match origin <egp|igp|incomplete>",
4590 "unknown heritage\n")
4593 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
4594 return bgp_route_match_add(vty
, "origin", "igp",
4595 RMAP_EVENT_MATCH_ADDED
);
4596 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
4597 return bgp_route_match_add(vty
, "origin", "egp",
4598 RMAP_EVENT_MATCH_ADDED
);
4599 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
4600 return bgp_route_match_add(vty
, "origin", "incomplete",
4601 RMAP_EVENT_MATCH_ADDED
);
4603 vty_out(vty
, "%% Invalid match origin type\n");
4604 return CMD_WARNING_CONFIG_FAILED
;
4608 DEFUN (no_match_origin
,
4609 no_match_origin_cmd
,
4610 "no match origin [<egp|igp|incomplete>]",
4616 "unknown heritage\n")
4618 return bgp_route_match_delete(vty
, "origin", NULL
,
4619 RMAP_EVENT_MATCH_DELETED
);
4622 DEFUN (set_table_id
,
4624 "set table (1-4294967295)",
4626 "export route to non-main kernel table\n"
4627 "Kernel routing table id\n")
4631 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
4633 return generic_set_add(vty
, index
, "table", argv
[idx_id
]->arg
);
4636 DEFUN (no_set_table_id
,
4637 no_set_table_id_cmd
,
4641 "export route to non-main kernel table\n")
4643 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
4645 return generic_set_delete(vty
, index
, "table", NULL
);
4648 DEFUN (set_ip_nexthop_peer
,
4649 set_ip_nexthop_peer_cmd
,
4650 "[no] set ip next-hop peer-address",
4654 "Next hop address\n"
4655 "Use peer address (for BGP only)\n")
4657 int (*func
)(struct vty
*, struct route_map_index
*, const char *,
4658 const char *) = strmatch(argv
[0]->text
, "no")
4659 ? generic_set_delete
4662 return func(vty
, VTY_GET_CONTEXT(route_map_index
), "ip next-hop",
4666 DEFUN (set_ip_nexthop_unchanged
,
4667 set_ip_nexthop_unchanged_cmd
,
4668 "[no] set ip next-hop unchanged",
4672 "Next hop address\n"
4673 "Don't modify existing Next hop address\n")
4675 int (*func
)(struct vty
*, struct route_map_index
*, const char *,
4676 const char *) = strmatch(argv
[0]->text
, "no")
4677 ? generic_set_delete
4680 return func(vty
, VTY_GET_CONTEXT(route_map_index
), "ip next-hop",
4684 DEFUN (set_distance
,
4686 "set distance (0-255)",
4688 "BGP Administrative Distance to use\n"
4693 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4694 "distance", argv
[idx_number
]->arg
);
4697 DEFUN (no_set_distance
,
4698 no_set_distance_cmd
,
4699 "no set distance [(0-255)]",
4701 "BGP Administrative Distance to use\n"
4704 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4708 DEFUN (set_local_pref
,
4710 "set local-preference WORD",
4712 "BGP local preference path attribute\n"
4713 "Preference value (0-4294967295)\n")
4716 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4717 "local-preference", argv
[idx_number
]->arg
);
4721 DEFUN (no_set_local_pref
,
4722 no_set_local_pref_cmd
,
4723 "no set local-preference [WORD]",
4726 "BGP local preference path attribute\n"
4727 "Preference value (0-4294967295)\n")
4729 int idx_localpref
= 3;
4730 if (argc
<= idx_localpref
)
4731 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4732 "local-preference", NULL
);
4733 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4734 "local-preference", argv
[idx_localpref
]->arg
);
4740 "set weight (0-4294967295)",
4742 "BGP weight for routing table\n"
4746 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "weight",
4747 argv
[idx_number
]->arg
);
4751 DEFUN (no_set_weight
,
4753 "no set weight [(0-4294967295)]",
4756 "BGP weight for routing table\n"
4760 if (argc
<= idx_weight
)
4761 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4763 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4764 "weight", argv
[idx_weight
]->arg
);
4767 DEFUN (set_label_index
,
4768 set_label_index_cmd
,
4769 "set label-index (0-1048560)",
4771 "Label index to associate with the prefix\n"
4772 "Label index value\n")
4775 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4776 "label-index", argv
[idx_number
]->arg
);
4779 DEFUN (no_set_label_index
,
4780 no_set_label_index_cmd
,
4781 "no set label-index [(0-1048560)]",
4784 "Label index to associate with the prefix\n"
4785 "Label index value\n")
4787 int idx_label_index
= 3;
4788 if (argc
<= idx_label_index
)
4789 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4790 "label-index", NULL
);
4791 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4792 "label-index", argv
[idx_label_index
]->arg
);
4795 DEFUN (set_aspath_prepend_asn
,
4796 set_aspath_prepend_asn_cmd
,
4797 "set as-path prepend (1-4294967295)...",
4799 "Transform BGP AS_PATH attribute\n"
4800 "Prepend to the as-path\n"
4807 str
= argv_concat(argv
, argc
, idx_asn
);
4808 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4809 "as-path prepend", str
);
4810 XFREE(MTYPE_TMP
, str
);
4815 DEFUN (set_aspath_prepend_lastas
,
4816 set_aspath_prepend_lastas_cmd
,
4817 "set as-path prepend last-as (1-10)",
4819 "Transform BGP AS_PATH attribute\n"
4820 "Prepend to the as-path\n"
4821 "Use the peer's AS-number\n"
4822 "Number of times to insert\n")
4824 return set_aspath_prepend_asn(self
, vty
, argc
, argv
);
4827 DEFUN (no_set_aspath_prepend
,
4828 no_set_aspath_prepend_cmd
,
4829 "no set as-path prepend [(1-4294967295)]",
4832 "Transform BGP AS_PATH attribute\n"
4833 "Prepend to the as-path\n"
4840 str
= argv_concat(argv
, argc
, idx_asn
);
4841 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4842 "as-path prepend", str
);
4843 XFREE(MTYPE_TMP
, str
);
4847 DEFUN (no_set_aspath_prepend_lastas
,
4848 no_set_aspath_prepend_lastas_cmd
,
4849 "no set as-path prepend last-as [(1-10)]",
4852 "Transform BGP AS_PATH attribute\n"
4853 "Prepend to the as-path\n"
4854 "Use the peers AS-number\n"
4855 "Number of times to insert\n")
4857 return no_set_aspath_prepend(self
, vty
, argc
, argv
);
4860 DEFUN (set_aspath_exclude
,
4861 set_aspath_exclude_cmd
,
4862 "set as-path exclude (1-4294967295)...",
4864 "Transform BGP AS-path attribute\n"
4865 "Exclude from the as-path\n"
4872 str
= argv_concat(argv
, argc
, idx_asn
);
4873 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4874 "as-path exclude", str
);
4875 XFREE(MTYPE_TMP
, str
);
4879 DEFUN (no_set_aspath_exclude
,
4880 no_set_aspath_exclude_cmd
,
4881 "no set as-path exclude (1-4294967295)...",
4884 "Transform BGP AS_PATH attribute\n"
4885 "Exclude from the as-path\n"
4892 str
= argv_concat(argv
, argc
, idx_asn
);
4893 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4894 "as-path exclude", str
);
4895 XFREE(MTYPE_TMP
, str
);
4899 ALIAS(no_set_aspath_exclude
, no_set_aspath_exclude_all_cmd
,
4900 "no set as-path exclude",
4902 "Transform BGP AS_PATH attribute\n"
4903 "Exclude from the as-path\n")
4905 DEFUN (set_community
,
4907 "set community AA:NN...",
4909 "BGP community attribute\n"
4917 struct community
*com
= NULL
;
4922 b
= buffer_new(1024);
4924 for (i
= idx_aa_nn
; i
< argc
; i
++) {
4925 if (strncmp(argv
[i
]->arg
, "additive", strlen(argv
[i
]->arg
))
4932 buffer_putc(b
, ' ');
4936 if (strncmp(argv
[i
]->arg
, "internet", strlen(argv
[i
]->arg
))
4938 buffer_putstr(b
, "internet");
4941 if (strncmp(argv
[i
]->arg
, "local-AS", strlen(argv
[i
]->arg
))
4943 buffer_putstr(b
, "local-AS");
4946 if (strncmp(argv
[i
]->arg
, "no-a", strlen("no-a")) == 0
4947 && strncmp(argv
[i
]->arg
, "no-advertise",
4948 strlen(argv
[i
]->arg
))
4950 buffer_putstr(b
, "no-advertise");
4953 if (strncmp(argv
[i
]->arg
, "no-e", strlen("no-e")) == 0
4954 && strncmp(argv
[i
]->arg
, "no-export", strlen(argv
[i
]->arg
))
4956 buffer_putstr(b
, "no-export");
4959 if (strncmp(argv
[i
]->arg
, "graceful-shutdown",
4960 strlen(argv
[i
]->arg
))
4962 buffer_putstr(b
, "graceful-shutdown");
4965 buffer_putstr(b
, argv
[i
]->arg
);
4967 buffer_putc(b
, '\0');
4969 /* Fetch result string then compile it to communities attribute. */
4970 str
= buffer_getstr(b
);
4974 com
= community_str2com(str
);
4975 XFREE(MTYPE_TMP
, str
);
4978 /* Can't compile user input into communities attribute. */
4980 vty_out(vty
, "%% Malformed communities attribute\n");
4981 return CMD_WARNING_CONFIG_FAILED
;
4984 /* Set communites attribute string. */
4985 str
= community_str(com
, false);
4988 size_t argstr_sz
= strlen(str
) + strlen(" additive") + 1;
4989 argstr
= XCALLOC(MTYPE_TMP
, argstr_sz
);
4990 strlcpy(argstr
, str
, argstr_sz
);
4991 strlcat(argstr
, " additive", argstr_sz
);
4992 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4993 "community", argstr
);
4994 XFREE(MTYPE_TMP
, argstr
);
4996 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4999 community_free(&com
);
5004 DEFUN (set_community_none
,
5005 set_community_none_cmd
,
5006 "set community none",
5008 "BGP community attribute\n"
5009 "No community attribute\n")
5011 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5012 "community", "none");
5015 DEFUN (no_set_community
,
5016 no_set_community_cmd
,
5017 "no set community AA:NN...",
5020 "BGP community attribute\n"
5023 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5027 ALIAS (no_set_community
,
5028 no_set_community_short_cmd
,
5032 "BGP community attribute\n")
5035 DEFUN (set_community_delete
,
5036 set_community_delete_cmd
,
5037 "set comm-list <(1-99)|(100-500)|WORD> delete",
5039 "set BGP community list (for deletion)\n"
5040 "Community-list number (standard)\n"
5041 "Community-list number (expanded)\n"
5042 "Community-list name\n"
5043 "Delete matching communities\n")
5045 int idx_comm_list
= 2;
5048 args
= argv_concat(argv
, argc
, idx_comm_list
);
5049 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "comm-list",
5051 XFREE(MTYPE_TMP
, args
);
5056 DEFUN (no_set_community_delete
,
5057 no_set_community_delete_cmd
,
5058 "no set comm-list [<(1-99)|(100-500)|WORD> delete]",
5061 "set BGP community list (for deletion)\n"
5062 "Community-list number (standard)\n"
5063 "Community-list number (expanded)\n"
5064 "Community-list name\n"
5065 "Delete matching communities\n")
5067 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5071 DEFUN (set_lcommunity
,
5073 "set large-community AA:BB:CC...",
5075 "BGP large community attribute\n"
5076 "Large Community number in aa:bb:cc format or additive\n")
5081 str
= argv_concat(argv
, argc
, 2);
5082 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5083 "large-community", str
);
5084 XFREE(MTYPE_TMP
, str
);
5089 DEFUN (set_lcommunity_none
,
5090 set_lcommunity_none_cmd
,
5091 "set large-community none",
5093 "BGP large community attribute\n"
5094 "No large community attribute\n")
5096 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5097 "large-community", "none");
5100 DEFUN (no_set_lcommunity
,
5101 no_set_lcommunity_cmd
,
5102 "no set large-community none",
5105 "BGP large community attribute\n"
5106 "No community attribute\n")
5108 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5109 "large-community", NULL
);
5112 DEFUN (no_set_lcommunity1
,
5113 no_set_lcommunity1_cmd
,
5114 "no set large-community AA:BB:CC...",
5117 "BGP large community attribute\n"
5118 "Large community in AA:BB:CC... format or additive\n")
5120 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5121 "large-community", NULL
);
5124 ALIAS (no_set_lcommunity1
,
5125 no_set_lcommunity1_short_cmd
,
5126 "no set large-community",
5129 "BGP large community attribute\n")
5131 DEFUN (set_lcommunity_delete
,
5132 set_lcommunity_delete_cmd
,
5133 "set large-comm-list <(1-99)|(100-500)|WORD> delete",
5135 "set BGP large community list (for deletion)\n"
5136 "Large Community-list number (standard)\n"
5137 "Large Communitly-list number (expanded)\n"
5138 "Large Community-list name\n"
5139 "Delete matching large communities\n")
5141 int idx_lcomm_list
= 2;
5144 args
= argv_concat(argv
, argc
, idx_lcomm_list
);
5145 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5146 "large-comm-list", args
);
5147 XFREE(MTYPE_TMP
, args
);
5152 DEFUN (no_set_lcommunity_delete
,
5153 no_set_lcommunity_delete_cmd
,
5154 "no set large-comm-list <(1-99)|(100-500)|WORD> [delete]",
5157 "set BGP large community list (for deletion)\n"
5158 "Large Community-list number (standard)\n"
5159 "Large Communitly-list number (expanded)\n"
5160 "Large Community-list name\n"
5161 "Delete matching large communities\n")
5163 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5164 "large-comm-list", NULL
);
5167 ALIAS (no_set_lcommunity_delete
,
5168 no_set_lcommunity_delete_short_cmd
,
5169 "no set large-comm-list",
5172 "set BGP large community list (for deletion)\n")
5174 DEFUN (set_ecommunity_rt
,
5175 set_ecommunity_rt_cmd
,
5176 "set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
5178 "BGP extended community attribute\n"
5179 "Route Target extended community\n"
5180 "VPN extended community\n")
5186 str
= argv_concat(argv
, argc
, idx_asn_nn
);
5187 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5188 "extcommunity rt", str
);
5189 XFREE(MTYPE_TMP
, str
);
5194 DEFUN (no_set_ecommunity_rt
,
5195 no_set_ecommunity_rt_cmd
,
5196 "no set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
5199 "BGP extended community attribute\n"
5200 "Route Target extended community\n"
5201 "VPN extended community\n")
5203 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5204 "extcommunity rt", NULL
);
5207 ALIAS (no_set_ecommunity_rt
,
5208 no_set_ecommunity_rt_short_cmd
,
5209 "no set extcommunity rt",
5212 "BGP extended community attribute\n"
5213 "Route Target extended community\n")
5215 DEFUN (set_ecommunity_soo
,
5216 set_ecommunity_soo_cmd
,
5217 "set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
5219 "BGP extended community attribute\n"
5220 "Site-of-Origin extended community\n"
5221 "VPN extended community\n")
5227 str
= argv_concat(argv
, argc
, idx_asn_nn
);
5228 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5229 "extcommunity soo", str
);
5230 XFREE(MTYPE_TMP
, str
);
5235 DEFUN (no_set_ecommunity_soo
,
5236 no_set_ecommunity_soo_cmd
,
5237 "no set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
5240 "BGP extended community attribute\n"
5241 "Site-of-Origin extended community\n"
5242 "VPN extended community\n")
5244 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5245 "extcommunity soo", NULL
);
5248 ALIAS (no_set_ecommunity_soo
,
5249 no_set_ecommunity_soo_short_cmd
,
5250 "no set extcommunity soo",
5253 "GP extended community attribute\n"
5254 "Site-of-Origin extended community\n")
5256 DEFUN (set_ecommunity_lb
,
5257 set_ecommunity_lb_cmd
,
5258 "set extcommunity bandwidth <(1-25600)|cumulative|num-multipaths> [non-transitive]",
5260 "BGP extended community attribute\n"
5261 "Link bandwidth extended community\n"
5262 "Bandwidth value in Mbps\n"
5263 "Cumulative bandwidth of all multipaths (outbound-only)\n"
5264 "Internally computed bandwidth based on number of multipaths (outbound-only)\n"
5265 "Attribute is set as non-transitive\n")
5271 str
= argv_concat(argv
, argc
, idx_lb
);
5272 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5273 "extcommunity bandwidth", str
);
5274 XFREE(MTYPE_TMP
, str
);
5279 DEFUN (no_set_ecommunity_lb
,
5280 no_set_ecommunity_lb_cmd
,
5281 "no set extcommunity bandwidth <(1-25600)|cumulative|num-multipaths> [non-transitive]",
5284 "BGP extended community attribute\n"
5285 "Link bandwidth extended community\n"
5286 "Bandwidth value in Mbps\n"
5287 "Cumulative bandwidth of all multipaths (outbound-only)\n"
5288 "Internally computed bandwidth based on number of multipaths (outbound-only)\n"
5289 "Attribute is set as non-transitive\n")
5291 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5292 "extcommunity bandwidth", NULL
);
5295 ALIAS (no_set_ecommunity_lb
,
5296 no_set_ecommunity_lb_short_cmd
,
5297 "no set extcommunity bandwidth",
5300 "BGP extended community attribute\n"
5301 "Link bandwidth extended community\n")
5305 "set origin <egp|igp|incomplete>",
5310 "unknown heritage\n")
5313 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
5314 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5316 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
5317 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5319 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
5320 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5321 "origin", "incomplete");
5323 vty_out(vty
, "%% Invalid set origin type\n");
5324 return CMD_WARNING_CONFIG_FAILED
;
5328 DEFUN (no_set_origin
,
5330 "no set origin [<egp|igp|incomplete>]",
5336 "unknown heritage\n")
5338 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5343 DEFUN (set_atomic_aggregate
,
5344 set_atomic_aggregate_cmd
,
5345 "set atomic-aggregate",
5347 "BGP atomic aggregate attribute\n" )
5349 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5350 "atomic-aggregate", NULL
);
5353 DEFUN (no_set_atomic_aggregate
,
5354 no_set_atomic_aggregate_cmd
,
5355 "no set atomic-aggregate",
5358 "BGP atomic aggregate attribute\n" )
5360 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5361 "atomic-aggregate", NULL
);
5364 DEFUN (set_aggregator_as
,
5365 set_aggregator_as_cmd
,
5366 "set aggregator as (1-4294967295) A.B.C.D",
5368 "BGP aggregator attribute\n"
5369 "AS number of aggregator\n"
5371 "IP address of aggregator\n")
5376 struct in_addr address
;
5379 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &address
);
5381 vty_out(vty
, "Aggregator IP address is invalid\n");
5382 return CMD_WARNING_CONFIG_FAILED
;
5385 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
5386 strlen(argv
[idx_number
]->arg
)
5387 + strlen(argv
[idx_ipv4
]->arg
) + 2);
5389 sprintf(argstr
, "%s %s", argv
[idx_number
]->arg
, argv
[idx_ipv4
]->arg
);
5391 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5392 "aggregator as", argstr
);
5394 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
5400 DEFUN (no_set_aggregator_as
,
5401 no_set_aggregator_as_cmd
,
5402 "no set aggregator as [(1-4294967295) A.B.C.D]",
5405 "BGP aggregator attribute\n"
5406 "AS number of aggregator\n"
5408 "IP address of aggregator\n")
5413 struct in_addr address
;
5416 if (argc
<= idx_asn
)
5417 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5418 "aggregator as", NULL
);
5420 ret
= inet_aton(argv
[idx_ip
]->arg
, &address
);
5422 vty_out(vty
, "Aggregator IP address is invalid\n");
5423 return CMD_WARNING_CONFIG_FAILED
;
5426 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
5427 strlen(argv
[idx_asn
]->arg
) + strlen(argv
[idx_ip
]->arg
)
5430 sprintf(argstr
, "%s %s", argv
[idx_asn
]->arg
, argv
[idx_ip
]->arg
);
5432 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5433 "aggregator as", argstr
);
5435 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
5440 DEFUN (match_ipv6_next_hop
,
5441 match_ipv6_next_hop_cmd
,
5442 "match ipv6 next-hop X:X::X:X",
5445 "Match IPv6 next-hop address of route\n"
5446 "IPv6 address of next hop\n")
5449 return bgp_route_match_add(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
5450 RMAP_EVENT_MATCH_ADDED
);
5453 DEFUN (no_match_ipv6_next_hop
,
5454 no_match_ipv6_next_hop_cmd
,
5455 "no match ipv6 next-hop X:X::X:X",
5459 "Match IPv6 next-hop address of route\n"
5460 "IPv6 address of next hop\n")
5463 return bgp_route_match_delete(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
5464 RMAP_EVENT_MATCH_DELETED
);
5467 DEFPY (match_ipv4_next_hop
,
5468 match_ipv4_next_hop_cmd
,
5469 "match ip next-hop address A.B.C.D",
5472 "Match IP next-hop address of route\n"
5474 "IP address of next-hop\n")
5478 return bgp_route_match_add(vty
, "ip next-hop address",
5479 argv
[idx_ipv4
]->arg
, RMAP_EVENT_MATCH_ADDED
);
5482 DEFPY (no_match_ipv4_next_hop
,
5483 no_match_ipv4_next_hop_cmd
,
5484 "no match ip next-hop address [A.B.C.D]",
5488 "Match IP next-hop address of route\n"
5490 "IP address of next-hop\n")
5492 return bgp_route_match_delete(vty
, "ip next-hop address", NULL
,
5493 RMAP_EVENT_MATCH_DELETED
);
5496 DEFUN (set_ipv6_nexthop_peer
,
5497 set_ipv6_nexthop_peer_cmd
,
5498 "set ipv6 next-hop peer-address",
5501 "Next hop address\n"
5502 "Use peer address (for BGP only)\n")
5504 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5505 "ipv6 next-hop peer-address", NULL
);
5508 DEFUN (no_set_ipv6_nexthop_peer
,
5509 no_set_ipv6_nexthop_peer_cmd
,
5510 "no set ipv6 next-hop peer-address",
5514 "IPv6 next-hop address\n"
5515 "Use peer address (for BGP only)\n")
5517 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5518 "ipv6 next-hop peer-address", NULL
);
5521 DEFUN (set_ipv6_nexthop_prefer_global
,
5522 set_ipv6_nexthop_prefer_global_cmd
,
5523 "set ipv6 next-hop prefer-global",
5526 "IPv6 next-hop address\n"
5527 "Prefer global over link-local if both exist\n")
5529 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5530 "ipv6 next-hop prefer-global", NULL
);
5534 DEFUN (no_set_ipv6_nexthop_prefer_global
,
5535 no_set_ipv6_nexthop_prefer_global_cmd
,
5536 "no set ipv6 next-hop prefer-global",
5540 "IPv6 next-hop address\n"
5541 "Prefer global over link-local if both exist\n")
5543 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5544 "ipv6 next-hop prefer-global", NULL
);
5547 DEFUN (set_ipv6_nexthop_global
,
5548 set_ipv6_nexthop_global_cmd
,
5549 "set ipv6 next-hop global X:X::X:X",
5552 "IPv6 next-hop address\n"
5553 "IPv6 global address\n"
5554 "IPv6 address of next hop\n")
5557 struct in6_addr addr
;
5560 ret
= inet_pton(AF_INET6
, argv
[idx_ipv6
]->arg
, &addr
);
5562 vty_out(vty
, "%% Malformed nexthop address\n");
5563 return CMD_WARNING_CONFIG_FAILED
;
5565 if (IN6_IS_ADDR_UNSPECIFIED(&addr
) || IN6_IS_ADDR_LOOPBACK(&addr
)
5566 || IN6_IS_ADDR_MULTICAST(&addr
) || IN6_IS_ADDR_LINKLOCAL(&addr
)) {
5567 vty_out(vty
, "%% Invalid global nexthop address\n");
5568 return CMD_WARNING_CONFIG_FAILED
;
5571 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5572 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
5576 DEFUN (no_set_ipv6_nexthop_global
,
5577 no_set_ipv6_nexthop_global_cmd
,
5578 "no set ipv6 next-hop global X:X::X:X",
5582 "IPv6 next-hop address\n"
5583 "IPv6 global address\n"
5584 "IPv6 address of next hop\n")
5587 if (argc
<= idx_ipv6
)
5588 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5589 "ipv6 next-hop global", NULL
);
5590 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5591 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
5594 #ifdef KEEP_OLD_VPN_COMMANDS
5595 DEFUN (set_vpn_nexthop
,
5596 set_vpn_nexthop_cmd
,
5597 "set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
5599 "VPNv4 information\n"
5600 "VPN next-hop address\n"
5601 "IP address of next hop\n"
5602 "VPNv6 information\n"
5603 "VPN next-hop address\n"
5604 "IPv6 address of next hop\n")
5610 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
5612 return generic_set_add(
5613 vty
, VTY_GET_CONTEXT(route_map_index
),
5614 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
5616 return generic_set_add(
5617 vty
, VTY_GET_CONTEXT(route_map_index
),
5618 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
5623 DEFUN (no_set_vpn_nexthop
,
5624 no_set_vpn_nexthop_cmd
,
5625 "no set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
5628 "VPNv4 information\n"
5629 "VPN next-hop address\n"
5630 "IP address of next hop\n"
5631 "VPNv6 information\n"
5632 "VPN next-hop address\n"
5633 "IPv6 address of next hop\n")
5643 arg
= argv
[idx_ip
]->arg
;
5644 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
5646 return generic_set_delete(
5647 vty
, VTY_GET_CONTEXT(route_map_index
),
5648 "ipv4 vpn next-hop", arg
);
5650 return generic_set_delete(
5651 vty
, VTY_GET_CONTEXT(route_map_index
),
5652 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
5656 #endif /* KEEP_OLD_VPN_COMMANDS */
5658 DEFUN (set_ipx_vpn_nexthop
,
5659 set_ipx_vpn_nexthop_cmd
,
5660 "set <ipv4|ipv6> vpn next-hop <A.B.C.D|X:X::X:X>",
5662 "IPv4 information\n"
5663 "IPv6 information\n"
5665 "VPN next-hop address\n"
5666 "IP address of next hop\n"
5667 "IPv6 address of next hop\n")
5673 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
5675 return generic_set_add(
5676 vty
, VTY_GET_CONTEXT(route_map_index
),
5677 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
5679 return generic_set_add(
5680 vty
, VTY_GET_CONTEXT(route_map_index
),
5681 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
5686 DEFUN (no_set_ipx_vpn_nexthop
,
5687 no_set_ipx_vpn_nexthop_cmd
,
5688 "no set <ipv4|ipv6> vpn next-hop [<A.B.C.D|X:X::X:X>]",
5691 "IPv4 information\n"
5692 "IPv6 information\n"
5694 "VPN next-hop address\n"
5695 "IP address of next hop\n"
5696 "IPv6 address of next hop\n")
5706 arg
= argv
[idx_ip
]->arg
;
5707 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
5709 return generic_set_delete(
5710 vty
, VTY_GET_CONTEXT(route_map_index
),
5711 "ipv4 vpn next-hop", arg
);
5713 return generic_set_delete(
5714 vty
, VTY_GET_CONTEXT(route_map_index
),
5715 "ipv6 vpn next-hop", arg
);
5720 DEFUN (set_originator_id
,
5721 set_originator_id_cmd
,
5722 "set originator-id A.B.C.D",
5724 "BGP originator ID attribute\n"
5725 "IP address of originator\n")
5728 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5729 "originator-id", argv
[idx_ipv4
]->arg
);
5733 DEFUN (no_set_originator_id
,
5734 no_set_originator_id_cmd
,
5735 "no set originator-id [A.B.C.D]",
5738 "BGP originator ID attribute\n"
5739 "IP address of originator\n")
5743 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
5745 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5746 "originator-id", arg
);
5750 /* Initialization of route map. */
5751 void bgp_route_map_init(void)
5755 route_map_add_hook(bgp_route_map_add
);
5756 route_map_delete_hook(bgp_route_map_delete
);
5757 route_map_event_hook(bgp_route_map_event
);
5759 route_map_match_interface_hook(generic_match_add
);
5760 route_map_no_match_interface_hook(generic_match_delete
);
5762 route_map_match_ip_address_hook(generic_match_add
);
5763 route_map_no_match_ip_address_hook(generic_match_delete
);
5765 route_map_match_ip_address_prefix_list_hook(generic_match_add
);
5766 route_map_no_match_ip_address_prefix_list_hook(generic_match_delete
);
5768 route_map_match_ip_next_hop_hook(generic_match_add
);
5769 route_map_no_match_ip_next_hop_hook(generic_match_delete
);
5771 route_map_match_ip_next_hop_prefix_list_hook(generic_match_add
);
5772 route_map_no_match_ip_next_hop_prefix_list_hook(generic_match_delete
);
5774 route_map_match_ip_next_hop_type_hook(generic_match_add
);
5775 route_map_no_match_ip_next_hop_type_hook(generic_match_delete
);
5777 route_map_match_ipv6_address_hook(generic_match_add
);
5778 route_map_no_match_ipv6_address_hook(generic_match_delete
);
5780 route_map_match_ipv6_address_prefix_list_hook(generic_match_add
);
5781 route_map_no_match_ipv6_address_prefix_list_hook(generic_match_delete
);
5783 route_map_match_ipv6_next_hop_type_hook(generic_match_add
);
5784 route_map_no_match_ipv6_next_hop_type_hook(generic_match_delete
);
5786 route_map_match_metric_hook(generic_match_add
);
5787 route_map_no_match_metric_hook(generic_match_delete
);
5789 route_map_match_tag_hook(generic_match_add
);
5790 route_map_no_match_tag_hook(generic_match_delete
);
5792 route_map_set_srte_color_hook(generic_set_add
);
5793 route_map_no_set_srte_color_hook(generic_set_delete
);
5795 route_map_set_ip_nexthop_hook(generic_set_add
);
5796 route_map_no_set_ip_nexthop_hook(generic_set_delete
);
5798 route_map_set_ipv6_nexthop_local_hook(generic_set_add
);
5799 route_map_no_set_ipv6_nexthop_local_hook(generic_set_delete
);
5801 route_map_set_metric_hook(generic_set_add
);
5802 route_map_no_set_metric_hook(generic_set_delete
);
5804 route_map_set_tag_hook(generic_set_add
);
5805 route_map_no_set_tag_hook(generic_set_delete
);
5807 route_map_install_match(&route_match_peer_cmd
);
5808 route_map_install_match(&route_match_local_pref_cmd
);
5809 #if defined(HAVE_LUA)
5810 route_map_install_match(&route_match_command_cmd
);
5812 route_map_install_match(&route_match_ip_address_cmd
);
5813 route_map_install_match(&route_match_ip_next_hop_cmd
);
5814 route_map_install_match(&route_match_ip_route_source_cmd
);
5815 route_map_install_match(&route_match_ip_address_prefix_list_cmd
);
5816 route_map_install_match(&route_match_ip_next_hop_prefix_list_cmd
);
5817 route_map_install_match(&route_match_ip_next_hop_type_cmd
);
5818 route_map_install_match(&route_match_ip_route_source_prefix_list_cmd
);
5819 route_map_install_match(&route_match_aspath_cmd
);
5820 route_map_install_match(&route_match_community_cmd
);
5821 route_map_install_match(&route_match_lcommunity_cmd
);
5822 route_map_install_match(&route_match_ecommunity_cmd
);
5823 route_map_install_match(&route_match_local_pref_cmd
);
5824 route_map_install_match(&route_match_metric_cmd
);
5825 route_map_install_match(&route_match_origin_cmd
);
5826 route_map_install_match(&route_match_probability_cmd
);
5827 route_map_install_match(&route_match_interface_cmd
);
5828 route_map_install_match(&route_match_tag_cmd
);
5829 route_map_install_match(&route_match_mac_address_cmd
);
5830 route_map_install_match(&route_match_evpn_vni_cmd
);
5831 route_map_install_match(&route_match_evpn_route_type_cmd
);
5832 route_map_install_match(&route_match_evpn_rd_cmd
);
5833 route_map_install_match(&route_match_evpn_default_route_cmd
);
5834 route_map_install_match(&route_match_vrl_source_vrf_cmd
);
5836 route_map_install_set(&route_set_table_id_cmd
);
5837 route_map_install_set(&route_set_srte_color_cmd
);
5838 route_map_install_set(&route_set_ip_nexthop_cmd
);
5839 route_map_install_set(&route_set_local_pref_cmd
);
5840 route_map_install_set(&route_set_weight_cmd
);
5841 route_map_install_set(&route_set_label_index_cmd
);
5842 route_map_install_set(&route_set_metric_cmd
);
5843 route_map_install_set(&route_set_distance_cmd
);
5844 route_map_install_set(&route_set_aspath_prepend_cmd
);
5845 route_map_install_set(&route_set_aspath_exclude_cmd
);
5846 route_map_install_set(&route_set_origin_cmd
);
5847 route_map_install_set(&route_set_atomic_aggregate_cmd
);
5848 route_map_install_set(&route_set_aggregator_as_cmd
);
5849 route_map_install_set(&route_set_community_cmd
);
5850 route_map_install_set(&route_set_community_delete_cmd
);
5851 route_map_install_set(&route_set_lcommunity_cmd
);
5852 route_map_install_set(&route_set_lcommunity_delete_cmd
);
5853 route_map_install_set(&route_set_vpnv4_nexthop_cmd
);
5854 route_map_install_set(&route_set_vpnv6_nexthop_cmd
);
5855 route_map_install_set(&route_set_originator_id_cmd
);
5856 route_map_install_set(&route_set_ecommunity_rt_cmd
);
5857 route_map_install_set(&route_set_ecommunity_soo_cmd
);
5858 route_map_install_set(&route_set_ecommunity_lb_cmd
);
5859 route_map_install_set(&route_set_tag_cmd
);
5860 route_map_install_set(&route_set_label_index_cmd
);
5862 install_element(RMAP_NODE
, &match_peer_cmd
);
5863 install_element(RMAP_NODE
, &match_peer_local_cmd
);
5864 install_element(RMAP_NODE
, &no_match_peer_cmd
);
5865 install_element(RMAP_NODE
, &match_ip_route_source_cmd
);
5866 install_element(RMAP_NODE
, &no_match_ip_route_source_cmd
);
5867 install_element(RMAP_NODE
, &match_ip_route_source_prefix_list_cmd
);
5868 install_element(RMAP_NODE
, &no_match_ip_route_source_prefix_list_cmd
);
5869 install_element(RMAP_NODE
, &match_mac_address_cmd
);
5870 install_element(RMAP_NODE
, &no_match_mac_address_cmd
);
5871 install_element(RMAP_NODE
, &match_evpn_vni_cmd
);
5872 install_element(RMAP_NODE
, &no_match_evpn_vni_cmd
);
5873 install_element(RMAP_NODE
, &match_evpn_route_type_cmd
);
5874 install_element(RMAP_NODE
, &no_match_evpn_route_type_cmd
);
5875 install_element(RMAP_NODE
, &match_evpn_rd_cmd
);
5876 install_element(RMAP_NODE
, &no_match_evpn_rd_cmd
);
5877 install_element(RMAP_NODE
, &match_evpn_default_route_cmd
);
5878 install_element(RMAP_NODE
, &no_match_evpn_default_route_cmd
);
5879 install_element(RMAP_NODE
, &match_vrl_source_vrf_cmd
);
5880 install_element(RMAP_NODE
, &no_match_vrl_source_vrf_cmd
);
5882 install_element(RMAP_NODE
, &match_aspath_cmd
);
5883 install_element(RMAP_NODE
, &no_match_aspath_cmd
);
5884 install_element(RMAP_NODE
, &match_local_pref_cmd
);
5885 install_element(RMAP_NODE
, &no_match_local_pref_cmd
);
5886 install_element(RMAP_NODE
, &match_community_cmd
);
5887 install_element(RMAP_NODE
, &no_match_community_cmd
);
5888 install_element(RMAP_NODE
, &match_lcommunity_cmd
);
5889 install_element(RMAP_NODE
, &no_match_lcommunity_cmd
);
5890 install_element(RMAP_NODE
, &match_ecommunity_cmd
);
5891 install_element(RMAP_NODE
, &no_match_ecommunity_cmd
);
5892 install_element(RMAP_NODE
, &match_origin_cmd
);
5893 install_element(RMAP_NODE
, &no_match_origin_cmd
);
5894 install_element(RMAP_NODE
, &match_probability_cmd
);
5895 install_element(RMAP_NODE
, &no_match_probability_cmd
);
5897 install_element(RMAP_NODE
, &no_set_table_id_cmd
);
5898 install_element(RMAP_NODE
, &set_table_id_cmd
);
5899 install_element(RMAP_NODE
, &set_ip_nexthop_peer_cmd
);
5900 install_element(RMAP_NODE
, &set_ip_nexthop_unchanged_cmd
);
5901 install_element(RMAP_NODE
, &set_local_pref_cmd
);
5902 install_element(RMAP_NODE
, &set_distance_cmd
);
5903 install_element(RMAP_NODE
, &no_set_distance_cmd
);
5904 install_element(RMAP_NODE
, &no_set_local_pref_cmd
);
5905 install_element(RMAP_NODE
, &set_weight_cmd
);
5906 install_element(RMAP_NODE
, &set_label_index_cmd
);
5907 install_element(RMAP_NODE
, &no_set_weight_cmd
);
5908 install_element(RMAP_NODE
, &no_set_label_index_cmd
);
5909 install_element(RMAP_NODE
, &set_aspath_prepend_asn_cmd
);
5910 install_element(RMAP_NODE
, &set_aspath_prepend_lastas_cmd
);
5911 install_element(RMAP_NODE
, &set_aspath_exclude_cmd
);
5912 install_element(RMAP_NODE
, &no_set_aspath_prepend_cmd
);
5913 install_element(RMAP_NODE
, &no_set_aspath_prepend_lastas_cmd
);
5914 install_element(RMAP_NODE
, &no_set_aspath_exclude_cmd
);
5915 install_element(RMAP_NODE
, &no_set_aspath_exclude_all_cmd
);
5916 install_element(RMAP_NODE
, &set_origin_cmd
);
5917 install_element(RMAP_NODE
, &no_set_origin_cmd
);
5918 install_element(RMAP_NODE
, &set_atomic_aggregate_cmd
);
5919 install_element(RMAP_NODE
, &no_set_atomic_aggregate_cmd
);
5920 install_element(RMAP_NODE
, &set_aggregator_as_cmd
);
5921 install_element(RMAP_NODE
, &no_set_aggregator_as_cmd
);
5922 install_element(RMAP_NODE
, &set_community_cmd
);
5923 install_element(RMAP_NODE
, &set_community_none_cmd
);
5924 install_element(RMAP_NODE
, &no_set_community_cmd
);
5925 install_element(RMAP_NODE
, &no_set_community_short_cmd
);
5926 install_element(RMAP_NODE
, &set_community_delete_cmd
);
5927 install_element(RMAP_NODE
, &no_set_community_delete_cmd
);
5928 install_element(RMAP_NODE
, &set_lcommunity_cmd
);
5929 install_element(RMAP_NODE
, &set_lcommunity_none_cmd
);
5930 install_element(RMAP_NODE
, &no_set_lcommunity_cmd
);
5931 install_element(RMAP_NODE
, &no_set_lcommunity1_cmd
);
5932 install_element(RMAP_NODE
, &no_set_lcommunity1_short_cmd
);
5933 install_element(RMAP_NODE
, &set_lcommunity_delete_cmd
);
5934 install_element(RMAP_NODE
, &no_set_lcommunity_delete_cmd
);
5935 install_element(RMAP_NODE
, &no_set_lcommunity_delete_short_cmd
);
5936 install_element(RMAP_NODE
, &set_ecommunity_rt_cmd
);
5937 install_element(RMAP_NODE
, &no_set_ecommunity_rt_cmd
);
5938 install_element(RMAP_NODE
, &no_set_ecommunity_rt_short_cmd
);
5939 install_element(RMAP_NODE
, &set_ecommunity_soo_cmd
);
5940 install_element(RMAP_NODE
, &no_set_ecommunity_soo_cmd
);
5941 install_element(RMAP_NODE
, &no_set_ecommunity_soo_short_cmd
);
5942 install_element(RMAP_NODE
, &set_ecommunity_lb_cmd
);
5943 install_element(RMAP_NODE
, &no_set_ecommunity_lb_cmd
);
5944 install_element(RMAP_NODE
, &no_set_ecommunity_lb_short_cmd
);
5945 #ifdef KEEP_OLD_VPN_COMMANDS
5946 install_element(RMAP_NODE
, &set_vpn_nexthop_cmd
);
5947 install_element(RMAP_NODE
, &no_set_vpn_nexthop_cmd
);
5948 #endif /* KEEP_OLD_VPN_COMMANDS */
5949 install_element(RMAP_NODE
, &set_ipx_vpn_nexthop_cmd
);
5950 install_element(RMAP_NODE
, &no_set_ipx_vpn_nexthop_cmd
);
5951 install_element(RMAP_NODE
, &set_originator_id_cmd
);
5952 install_element(RMAP_NODE
, &no_set_originator_id_cmd
);
5954 route_map_install_match(&route_match_ipv6_address_cmd
);
5955 route_map_install_match(&route_match_ipv6_next_hop_cmd
);
5956 route_map_install_match(&route_match_ipv4_next_hop_cmd
);
5957 route_map_install_match(&route_match_ipv6_address_prefix_list_cmd
);
5958 route_map_install_match(&route_match_ipv6_next_hop_type_cmd
);
5959 route_map_install_set(&route_set_ipv6_nexthop_global_cmd
);
5960 route_map_install_set(&route_set_ipv6_nexthop_prefer_global_cmd
);
5961 route_map_install_set(&route_set_ipv6_nexthop_local_cmd
);
5962 route_map_install_set(&route_set_ipv6_nexthop_peer_cmd
);
5964 install_element(RMAP_NODE
, &match_ipv6_next_hop_cmd
);
5965 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_cmd
);
5966 install_element(RMAP_NODE
, &match_ipv4_next_hop_cmd
);
5967 install_element(RMAP_NODE
, &no_match_ipv4_next_hop_cmd
);
5968 install_element(RMAP_NODE
, &set_ipv6_nexthop_global_cmd
);
5969 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_global_cmd
);
5970 install_element(RMAP_NODE
, &set_ipv6_nexthop_prefer_global_cmd
);
5971 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_prefer_global_cmd
);
5972 install_element(RMAP_NODE
, &set_ipv6_nexthop_peer_cmd
);
5973 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_peer_cmd
);
5974 #if defined(HAVE_LUA)
5975 install_element(RMAP_NODE
, &match_command_cmd
);
5976 install_element(RMAP_NODE
, &no_match_command_cmd
);
5980 void bgp_route_map_terminate(void)
5982 /* ToDo: Cleanup all the used memory */