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 #include "frrscript.h"
33 #ifdef HAVE_LIBPCREPOSIX
34 #include <pcreposix.h>
37 #endif /* HAVE_LIBPCREPOSIX */
39 #include "sockunion.h"
44 #include "lib/northbound_cli.h"
46 #include "bgpd/bgpd.h"
47 #include "bgpd/bgp_table.h"
48 #include "bgpd/bgp_attr.h"
49 #include "bgpd/bgp_aspath.h"
50 #include "bgpd/bgp_packet.h"
51 #include "bgpd/bgp_route.h"
52 #include "bgpd/bgp_zebra.h"
53 #include "bgpd/bgp_regex.h"
54 #include "bgpd/bgp_community.h"
55 #include "bgpd/bgp_community_alias.h"
56 #include "bgpd/bgp_clist.h"
57 #include "bgpd/bgp_filter.h"
58 #include "bgpd/bgp_mplsvpn.h"
59 #include "bgpd/bgp_ecommunity.h"
60 #include "bgpd/bgp_lcommunity.h"
61 #include "bgpd/bgp_vty.h"
62 #include "bgpd/bgp_debug.h"
63 #include "bgpd/bgp_evpn.h"
64 #include "bgpd/bgp_evpn_private.h"
65 #include "bgpd/bgp_evpn_vty.h"
66 #include "bgpd/bgp_mplsvpn.h"
67 #include "bgpd/bgp_pbr.h"
68 #include "bgpd/bgp_flowspec_util.h"
69 #include "bgpd/bgp_encap_types.h"
70 #include "bgpd/bgp_mpath.h"
71 #include "bgpd/bgp_script.h"
74 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
77 #ifndef VTYSH_EXTRACT_PL
78 #include "bgpd/bgp_routemap_clippy.c"
81 /* Memo of route-map commands.
90 ip route-source : Done
94 ipv6 route-source: (This will not be implemented by bgpd)
95 ipv6 prefix-list : Done
96 length : (This will not be implemented by bgpd)
98 route-type : (This will not be implemented by bgpd)
100 local-preference : Done
102 set as-path prepend : Done
103 as-path tag : Not yet
104 automatic-tag : (This will not be implemented by bgpd)
106 large-community : Done
107 large-comm-list : Done
110 default : (This will not be implemented by bgpd)
111 interface : (This will not be implemented by bgpd)
112 ip default : (This will not be implemented by bgpd)
114 ip precedence : (This will not be implemented by bgpd)
115 ip tos : (This will not be implemented by bgpd)
116 level : (This will not be implemented by bgpd)
117 local-preference : Done
119 metric-type : Not yet
127 set ipv6 next-hop global: Done
128 set ipv6 next-hop prefer-global: Done
129 set ipv6 next-hop local : Done
130 set as-path exclude : Done
134 /* generic value manipulation to be shared in multiple rules */
136 #define RMAP_VALUE_SET 0
137 #define RMAP_VALUE_ADD 1
138 #define RMAP_VALUE_SUB 2
146 static int route_value_match(struct rmap_value
*rv
, uint32_t value
)
148 if (rv
->variable
== 0 && value
== rv
->value
)
154 static uint32_t route_value_adjust(struct rmap_value
*rv
, uint32_t current
,
159 switch (rv
->variable
) {
168 switch (rv
->action
) {
170 if (current
> UINT32_MAX
- value
)
172 return current
+ value
;
174 if (current
<= value
)
176 return current
- value
;
182 static void *route_value_compile(const char *arg
)
184 uint8_t action
= RMAP_VALUE_SET
, var
= 0;
185 unsigned long larg
= 0;
187 struct rmap_value
*rv
;
190 action
= RMAP_VALUE_ADD
;
192 } else if (arg
[0] == '-') {
193 action
= RMAP_VALUE_SUB
;
197 if (all_digit(arg
)) {
199 larg
= strtoul(arg
, &endptr
, 10);
200 if (*arg
== 0 || *endptr
!= 0 || errno
|| larg
> UINT32_MAX
)
203 if (strcmp(arg
, "rtt") == 0)
209 rv
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_value
));
217 static void route_value_free(void *rule
)
219 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
222 /* generic as path object to be shared in multiple rules */
224 static void *route_aspath_compile(const char *arg
)
226 struct aspath
*aspath
;
228 aspath
= aspath_str2aspath(arg
);
234 static void route_aspath_free(void *rule
)
236 struct aspath
*aspath
= rule
;
240 struct bgp_match_peer_compiled
{
245 /* 'match peer (A.B.C.D|X:X::X:X|WORD)' */
247 /* Compares the peer specified in the 'match peer' clause with the peer
248 received in bgp_path_info->peer. If it is the same, or if the peer structure
249 received is a peer_group containing it, returns RMAP_MATCH. */
250 static enum route_map_cmd_result_t
251 route_match_peer(void *rule
, const struct prefix
*prefix
, void *object
)
253 struct bgp_match_peer_compiled
*pc
;
255 union sockunion su_def
= {
256 .sin
= {.sin_family
= AF_INET
, .sin_addr
.s_addr
= INADDR_ANY
}};
257 struct peer_group
*group
;
259 struct listnode
*node
, *nnode
;
263 peer
= ((struct bgp_path_info
*)object
)->peer
;
266 if (!peer
->conf_if
|| !peer
->group
)
269 if (peer
->conf_if
&& strcmp(peer
->conf_if
, pc
->interface
) == 0)
273 strcmp(peer
->group
->name
, pc
->interface
) == 0)
279 /* If su='0.0.0.0' (command 'match peer local'), and it's a
281 REDISTRIBUTE, AGGREGATE-ADDRESS or DEFAULT_GENERATED route
284 if (sockunion_same(su
, &su_def
)) {
286 if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_NETWORK
)
287 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_REDISTRIBUTE
)
288 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_AGGREGATE
)
289 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_DEFAULT
))
296 if (!CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
)) {
297 if (sockunion_same(su
, &peer
->su
))
303 for (ALL_LIST_ELEMENTS(group
->peer
, node
, nnode
, peer
)) {
304 if (sockunion_same(su
, &peer
->su
))
313 static void *route_match_peer_compile(const char *arg
)
315 struct bgp_match_peer_compiled
*pc
;
318 pc
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
319 sizeof(struct bgp_match_peer_compiled
));
321 ret
= str2sockunion(strcmp(arg
, "local") ? arg
: "0.0.0.0", &pc
->su
);
323 pc
->interface
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
330 /* Free route map's compiled `ip address' value. */
331 static void route_match_peer_free(void *rule
)
333 struct bgp_match_peer_compiled
*pc
= rule
;
335 XFREE(MTYPE_ROUTE_MAP_COMPILED
, pc
->interface
);
337 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
340 /* Route map commands for ip address matching. */
341 static const struct route_map_rule_cmd route_match_peer_cmd
= {
344 route_match_peer_compile
,
345 route_match_peer_free
348 #ifdef HAVE_SCRIPTING
350 enum frrlua_rm_status
{
352 * Script function run failure. This will translate into a deny
356 * No Match was found for the route map function
360 * Match was found but no changes were made to the incoming data.
364 * Match was found and data was modified, so figure out what changed
366 LUA_RM_MATCH_AND_CHANGE
,
369 static enum route_map_cmd_result_t
370 route_match_script(void *rule
, const struct prefix
*prefix
, void *object
)
372 const char *scriptname
= rule
;
373 const char *routematch_function
= "route_match";
374 struct bgp_path_info
*path
= (struct bgp_path_info
*)object
;
376 struct frrscript
*fs
= frrscript_new(scriptname
);
378 if (frrscript_load(fs
, routematch_function
, NULL
)) {
380 "Issue loading script or function; defaulting to no match");
384 struct attr newattr
= *path
->attr
;
386 int result
= frrscript_call(
387 fs
, routematch_function
, ("prefix", prefix
),
388 ("attributes", &newattr
), ("peer", path
->peer
),
389 ("RM_FAILURE", LUA_RM_FAILURE
), ("RM_NOMATCH", LUA_RM_NOMATCH
),
390 ("RM_MATCH", LUA_RM_MATCH
),
391 ("RM_MATCH_AND_CHANGE", LUA_RM_MATCH_AND_CHANGE
));
394 zlog_err("Issue running script rule; defaulting to no match");
398 long long *action
= frrscript_get_result(fs
, routematch_function
,
399 "action", lua_tointegerp
);
401 int status
= RMAP_NOMATCH
;
406 "Executing route-map match script '%s' failed; defaulting to no match",
408 status
= RMAP_NOMATCH
;
411 status
= RMAP_NOMATCH
;
413 case LUA_RM_MATCH_AND_CHANGE
:
415 zlog_debug("Updating attribute based on script's values");
417 uint32_t locpref
= 0;
419 path
->attr
->med
= newattr
.med
;
421 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
))
422 locpref
= path
->attr
->local_pref
;
423 if (locpref
!= newattr
.local_pref
) {
424 SET_FLAG(path
->attr
->flag
,
425 ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
));
426 path
->attr
->local_pref
= newattr
.local_pref
;
434 XFREE(MTYPE_SCRIPT_RES
, action
);
436 frrscript_delete(fs
);
441 static void *route_match_script_compile(const char *arg
)
445 scriptname
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
450 static void route_match_script_free(void *rule
)
452 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
455 static const struct route_map_rule_cmd route_match_script_cmd
= {
458 route_match_script_compile
,
459 route_match_script_free
462 #endif /* HAVE_SCRIPTING */
464 /* `match ip address IP_ACCESS_LIST' */
466 /* Match function should return 1 if match is success else return
468 static enum route_map_cmd_result_t
469 route_match_ip_address(void *rule
, const struct prefix
*prefix
, void *object
)
471 struct access_list
*alist
;
473 if (prefix
->family
== AF_INET
) {
474 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
478 return (access_list_apply(alist
, prefix
) == FILTER_DENY
485 /* Route map `ip address' match statement. `arg' should be
487 static void *route_match_ip_address_compile(const char *arg
)
489 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
492 /* Free route map's compiled `ip address' value. */
493 static void route_match_ip_address_free(void *rule
)
495 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
498 /* Route map commands for ip address matching. */
499 static const struct route_map_rule_cmd route_match_ip_address_cmd
= {
501 route_match_ip_address
,
502 route_match_ip_address_compile
,
503 route_match_ip_address_free
506 /* `match ip next-hop IP_ADDRESS' */
508 /* Match function return 1 if match is success else return zero. */
509 static enum route_map_cmd_result_t
510 route_match_ip_next_hop(void *rule
, const struct prefix
*prefix
, void *object
)
512 struct access_list
*alist
;
513 struct bgp_path_info
*path
;
514 struct prefix_ipv4 p
;
516 if (prefix
->family
== AF_INET
) {
519 p
.prefix
= path
->attr
->nexthop
;
520 p
.prefixlen
= IPV4_MAX_BITLEN
;
522 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
526 return (access_list_apply(alist
, &p
) == FILTER_DENY
533 /* Route map `ip next-hop' match statement. `arg' is
535 static void *route_match_ip_next_hop_compile(const char *arg
)
537 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
540 /* Free route map's compiled `ip address' value. */
541 static void route_match_ip_next_hop_free(void *rule
)
543 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
546 /* Route map commands for ip next-hop matching. */
547 static const struct route_map_rule_cmd route_match_ip_next_hop_cmd
= {
549 route_match_ip_next_hop
,
550 route_match_ip_next_hop_compile
,
551 route_match_ip_next_hop_free
554 /* `match ip route-source ACCESS-LIST' */
556 /* Match function return 1 if match is success else return zero. */
557 static enum route_map_cmd_result_t
558 route_match_ip_route_source(void *rule
, const struct prefix
*pfx
, void *object
)
560 struct access_list
*alist
;
561 struct bgp_path_info
*path
;
563 struct prefix_ipv4 p
;
565 if (pfx
->family
== AF_INET
) {
569 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
573 p
.prefix
= peer
->su
.sin
.sin_addr
;
574 p
.prefixlen
= IPV4_MAX_BITLEN
;
576 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
580 return (access_list_apply(alist
, &p
) == FILTER_DENY
587 /* Route map `ip route-source' match statement. `arg' is
589 static void *route_match_ip_route_source_compile(const char *arg
)
591 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
594 /* Free route map's compiled `ip address' value. */
595 static void route_match_ip_route_source_free(void *rule
)
597 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
600 /* Route map commands for ip route-source matching. */
601 static const struct route_map_rule_cmd route_match_ip_route_source_cmd
= {
603 route_match_ip_route_source
,
604 route_match_ip_route_source_compile
,
605 route_match_ip_route_source_free
608 static enum route_map_cmd_result_t
609 route_match_prefix_list_flowspec(afi_t afi
, struct prefix_list
*plist
,
610 const struct prefix
*p
)
613 struct bgp_pbr_entry_main api
;
615 memset(&api
, 0, sizeof(api
));
617 if (family2afi(p
->u
.prefix_flowspec
.family
) != afi
)
620 /* extract match from flowspec entries */
621 ret
= bgp_flowspec_match_rules_fill(
622 (uint8_t *)p
->u
.prefix_flowspec
.ptr
,
623 p
->u
.prefix_flowspec
.prefixlen
, &api
,
627 if (api
.match_bitmask
& PREFIX_DST_PRESENT
||
628 api
.match_bitmask_iprule
& PREFIX_DST_PRESENT
) {
629 if (family2afi((&api
.dst_prefix
)->family
) != afi
)
631 return prefix_list_apply(plist
, &api
.dst_prefix
) == PREFIX_DENY
634 } else if (api
.match_bitmask
& PREFIX_SRC_PRESENT
||
635 api
.match_bitmask_iprule
& PREFIX_SRC_PRESENT
) {
636 if (family2afi((&api
.src_prefix
)->family
) != afi
)
638 return (prefix_list_apply(plist
, &api
.src_prefix
) == PREFIX_DENY
645 static enum route_map_cmd_result_t
646 route_match_prefix_list_evpn(afi_t afi
, struct prefix_list
*plist
,
647 const struct prefix
*p
)
649 /* Convert to match a general plist */
652 if (evpn_prefix2prefix(p
, &new))
655 return (prefix_list_apply(plist
, &new) == PREFIX_DENY
? RMAP_NOMATCH
659 static enum route_map_cmd_result_t
660 route_match_address_prefix_list(void *rule
, afi_t afi
,
661 const struct prefix
*prefix
, void *object
)
663 struct prefix_list
*plist
;
665 plist
= prefix_list_lookup(afi
, (char *)rule
);
669 if (prefix
->family
== AF_FLOWSPEC
)
670 return route_match_prefix_list_flowspec(afi
, plist
,
673 else if (prefix
->family
== AF_EVPN
)
674 return route_match_prefix_list_evpn(afi
, plist
, prefix
);
676 return (prefix_list_apply(plist
, prefix
) == PREFIX_DENY
? RMAP_NOMATCH
680 static enum route_map_cmd_result_t
681 route_match_ip_address_prefix_list(void *rule
, const struct prefix
*prefix
,
684 return route_match_address_prefix_list(rule
, AFI_IP
, prefix
, object
);
687 static void *route_match_ip_address_prefix_list_compile(const char *arg
)
689 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
692 static void route_match_ip_address_prefix_list_free(void *rule
)
694 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
697 static const struct route_map_rule_cmd
698 route_match_ip_address_prefix_list_cmd
= {
699 "ip address prefix-list",
700 route_match_ip_address_prefix_list
,
701 route_match_ip_address_prefix_list_compile
,
702 route_match_ip_address_prefix_list_free
705 /* `match ip next-hop prefix-list PREFIX_LIST' */
707 static enum route_map_cmd_result_t
708 route_match_ip_next_hop_prefix_list(void *rule
, const struct prefix
*prefix
,
711 struct prefix_list
*plist
;
712 struct bgp_path_info
*path
;
713 struct prefix_ipv4 p
;
715 if (prefix
->family
== AF_INET
) {
718 p
.prefix
= path
->attr
->nexthop
;
719 p
.prefixlen
= IPV4_MAX_BITLEN
;
721 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
725 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
732 static void *route_match_ip_next_hop_prefix_list_compile(const char *arg
)
734 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
737 static void route_match_ip_next_hop_prefix_list_free(void *rule
)
739 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
742 static const struct route_map_rule_cmd
743 route_match_ip_next_hop_prefix_list_cmd
= {
744 "ip next-hop prefix-list",
745 route_match_ip_next_hop_prefix_list
,
746 route_match_ip_next_hop_prefix_list_compile
,
747 route_match_ip_next_hop_prefix_list_free
750 /* `match ipv6 next-hop prefix-list PREFIXLIST_NAME' */
751 static enum route_map_cmd_result_t
752 route_match_ipv6_next_hop_prefix_list(void *rule
, const struct prefix
*prefix
,
755 struct prefix_list
*plist
;
756 struct bgp_path_info
*path
;
757 struct prefix_ipv6 p
;
759 if (prefix
->family
== AF_INET6
) {
762 p
.prefix
= path
->attr
->mp_nexthop_global
;
763 p
.prefixlen
= IPV6_MAX_BITLEN
;
765 plist
= prefix_list_lookup(AFI_IP6
, (char *)rule
);
769 if (prefix_list_apply(plist
, &p
) == PREFIX_PERMIT
)
772 if (path
->attr
->mp_nexthop_len
773 == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
) {
774 p
.prefix
= path
->attr
->mp_nexthop_local
;
775 if (prefix_list_apply(plist
, &p
) == PREFIX_PERMIT
)
783 static void *route_match_ipv6_next_hop_prefix_list_compile(const char *arg
)
785 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
788 static void route_match_ipv6_next_hop_prefix_list_free(void *rule
)
790 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
793 static const struct route_map_rule_cmd
794 route_match_ipv6_next_hop_prefix_list_cmd
= {
795 "ipv6 next-hop prefix-list",
796 route_match_ipv6_next_hop_prefix_list
,
797 route_match_ipv6_next_hop_prefix_list_compile
,
798 route_match_ipv6_next_hop_prefix_list_free
801 /* `match ip next-hop type <blackhole>' */
803 static enum route_map_cmd_result_t
804 route_match_ip_next_hop_type(void *rule
, const struct prefix
*prefix
,
807 struct bgp_path_info
*path
;
809 if (prefix
->family
== AF_INET
) {
810 path
= (struct bgp_path_info
*)object
;
814 /* If nexthop interface's index can't be resolved and nexthop is
815 set to any address then mark it as type `blackhole`.
816 This logic works for matching kernel/static routes like:
817 `ip route add blackhole 10.0.0.1`. */
818 if (path
->attr
->nexthop
.s_addr
== INADDR_ANY
819 && !path
->attr
->nh_ifindex
)
825 static void *route_match_ip_next_hop_type_compile(const char *arg
)
827 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
830 static void route_match_ip_next_hop_type_free(void *rule
)
832 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
835 static const struct route_map_rule_cmd
836 route_match_ip_next_hop_type_cmd
= {
838 route_match_ip_next_hop_type
,
839 route_match_ip_next_hop_type_compile
,
840 route_match_ip_next_hop_type_free
843 /* `match ip route-source prefix-list PREFIX_LIST' */
845 static enum route_map_cmd_result_t
846 route_match_ip_route_source_prefix_list(void *rule
, const struct prefix
*prefix
,
849 struct prefix_list
*plist
;
850 struct bgp_path_info
*path
;
852 struct prefix_ipv4 p
;
854 if (prefix
->family
== AF_INET
) {
858 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
862 p
.prefix
= peer
->su
.sin
.sin_addr
;
863 p
.prefixlen
= IPV4_MAX_BITLEN
;
865 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
869 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
876 static void *route_match_ip_route_source_prefix_list_compile(const char *arg
)
878 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
881 static void route_match_ip_route_source_prefix_list_free(void *rule
)
883 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
886 static const struct route_map_rule_cmd
887 route_match_ip_route_source_prefix_list_cmd
= {
888 "ip route-source prefix-list",
889 route_match_ip_route_source_prefix_list
,
890 route_match_ip_route_source_prefix_list_compile
,
891 route_match_ip_route_source_prefix_list_free
894 /* `match evpn default-route' */
896 /* Match function should return 1 if match is success else 0 */
897 static enum route_map_cmd_result_t
898 route_match_evpn_default_route(void *rule
, const struct prefix
*p
, void *object
)
900 if (is_evpn_prefix_default(p
))
906 /* Route map commands for default-route matching. */
907 static const struct route_map_rule_cmd
908 route_match_evpn_default_route_cmd
= {
909 "evpn default-route",
910 route_match_evpn_default_route
,
915 /* `match mac address MAC_ACCESS_LIST' */
917 /* Match function should return 1 if match is success else return
919 static enum route_map_cmd_result_t
920 route_match_mac_address(void *rule
, const struct prefix
*prefix
, void *object
)
922 struct access_list
*alist
;
925 alist
= access_list_lookup(AFI_L2VPN
, (char *)rule
);
929 if (prefix
->u
.prefix_evpn
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
932 p
.family
= AF_ETHERNET
;
933 p
.prefixlen
= ETH_ALEN
* 8;
934 p
.u
.prefix_eth
= prefix
->u
.prefix_evpn
.macip_addr
.mac
;
936 return (access_list_apply(alist
, &p
) == FILTER_DENY
? RMAP_NOMATCH
940 /* Route map `mac address' match statement. `arg' should be
942 static void *route_match_mac_address_compile(const char *arg
)
944 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
947 /* Free route map's compiled `ip address' value. */
948 static void route_match_mac_address_free(void *rule
)
950 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
953 /* Route map commands for mac address matching. */
954 static const struct route_map_rule_cmd route_match_mac_address_cmd
= {
956 route_match_mac_address
,
957 route_match_mac_address_compile
,
958 route_match_mac_address_free
962 * Match function returns:
963 * ...RMAP_MATCH if match is found.
964 * ...RMAP_NOMATCH if match is not found.
965 * ...RMAP_NOOP to ignore this match check.
967 static enum route_map_cmd_result_t
968 route_match_vni(void *rule
, const struct prefix
*prefix
, void *object
)
971 unsigned int label_cnt
= 0;
972 struct bgp_path_info
*path
= NULL
;
973 struct prefix_evpn
*evp
= (struct prefix_evpn
*) prefix
;
975 vni
= *((vni_t
*)rule
);
976 path
= (struct bgp_path_info
*)object
;
979 * This rmap filter is valid for vxlan tunnel type only.
980 * For any other tunnel type, return noop to ignore
983 if (path
->attr
->encap_tunneltype
!= BGP_ENCAP_TYPE_VXLAN
)
987 * Apply filter to type 1, 2, 5 routes only.
988 * Other route types do not have vni label.
991 && (evp
->prefix
.route_type
!= BGP_EVPN_AD_ROUTE
992 && evp
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
993 && evp
->prefix
.route_type
!= BGP_EVPN_IP_PREFIX_ROUTE
))
996 if (path
->extra
== NULL
)
1000 label_cnt
< BGP_MAX_LABELS
&& label_cnt
< path
->extra
->num_labels
;
1002 if (vni
== label2vni(&path
->extra
->label
[label_cnt
]))
1006 return RMAP_NOMATCH
;
1009 /* Route map `vni' match statement. */
1010 static void *route_match_vni_compile(const char *arg
)
1015 vni
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(vni_t
));
1017 *vni
= strtoul(arg
, &end
, 10);
1019 XFREE(MTYPE_ROUTE_MAP_COMPILED
, vni
);
1026 /* Free route map's compiled `vni' value. */
1027 static void route_match_vni_free(void *rule
)
1029 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1032 /* Route map commands for vni matching. */
1033 static const struct route_map_rule_cmd route_match_evpn_vni_cmd
= {
1036 route_match_vni_compile
,
1037 route_match_vni_free
1040 /* `match evpn route-type' */
1042 /* Match function should return 1 if match is success else return
1044 static enum route_map_cmd_result_t
1045 route_match_evpn_route_type(void *rule
, const struct prefix
*pfx
, void *object
)
1047 uint8_t route_type
= 0;
1049 route_type
= *((uint8_t *)rule
);
1051 if (route_type
== pfx
->u
.prefix_evpn
.route_type
)
1054 return RMAP_NOMATCH
;
1057 /* Route map `route-type' match statement. */
1058 static void *route_match_evpn_route_type_compile(const char *arg
)
1060 uint8_t *route_type
= NULL
;
1062 route_type
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
1064 if (strncmp(arg
, "ea", 2) == 0)
1065 *route_type
= BGP_EVPN_AD_ROUTE
;
1066 else if (strncmp(arg
, "ma", 2) == 0)
1067 *route_type
= BGP_EVPN_MAC_IP_ROUTE
;
1068 else if (strncmp(arg
, "mu", 2) == 0)
1069 *route_type
= BGP_EVPN_IMET_ROUTE
;
1070 else if (strncmp(arg
, "es", 2) == 0)
1071 *route_type
= BGP_EVPN_ES_ROUTE
;
1073 *route_type
= BGP_EVPN_IP_PREFIX_ROUTE
;
1078 /* Free route map's compiled `route-type' value. */
1079 static void route_match_evpn_route_type_free(void *rule
)
1081 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1084 /* Route map commands for evpn route-type matching. */
1085 static const struct route_map_rule_cmd route_match_evpn_route_type_cmd
= {
1087 route_match_evpn_route_type
,
1088 route_match_evpn_route_type_compile
,
1089 route_match_evpn_route_type_free
1094 /* Match function should return 1 if match is success else return zero. */
1095 static enum route_map_cmd_result_t
1096 route_match_rd(void *rule
, const struct prefix
*prefix
, void *object
)
1098 struct prefix_rd
*prd_rule
= NULL
;
1099 const struct prefix_rd
*prd_route
= NULL
;
1100 struct bgp_path_info
*path
= NULL
;
1102 if (prefix
->family
!= AF_EVPN
)
1103 return RMAP_NOMATCH
;
1105 prd_rule
= (struct prefix_rd
*)rule
;
1106 path
= (struct bgp_path_info
*)object
;
1108 if (path
->net
== NULL
|| path
->net
->pdest
== NULL
)
1109 return RMAP_NOMATCH
;
1111 prd_route
= (struct prefix_rd
*)bgp_dest_get_prefix(path
->net
->pdest
);
1112 if (memcmp(prd_route
->val
, prd_rule
->val
, ECOMMUNITY_SIZE
) == 0)
1115 return RMAP_NOMATCH
;
1118 /* Route map `rd' match statement. */
1119 static void *route_match_rd_compile(const char *arg
)
1121 struct prefix_rd
*prd
;
1124 prd
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct prefix_rd
));
1126 ret
= str2prefix_rd(arg
, prd
);
1128 XFREE(MTYPE_ROUTE_MAP_COMPILED
, prd
);
1135 /* Free route map's compiled `rd' value. */
1136 static void route_match_rd_free(void *rule
)
1138 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1141 /* Route map commands for rd matching. */
1142 static const struct route_map_rule_cmd route_match_evpn_rd_cmd
= {
1145 route_match_rd_compile
,
1149 static enum route_map_cmd_result_t
1150 route_set_evpn_gateway_ip(void *rule
, const struct prefix
*prefix
, void *object
)
1152 struct ipaddr
*gw_ip
= rule
;
1153 struct bgp_path_info
*path
;
1154 struct prefix_evpn
*evp
;
1156 if (prefix
->family
!= AF_EVPN
)
1159 evp
= (struct prefix_evpn
*)prefix
;
1160 if (evp
->prefix
.route_type
!= BGP_EVPN_IP_PREFIX_ROUTE
)
1163 if ((is_evpn_prefix_ipaddr_v4(evp
) && IPADDRSZ(gw_ip
) != 4)
1164 || (is_evpn_prefix_ipaddr_v6(evp
) && IPADDRSZ(gw_ip
) != 16))
1169 /* Set gateway-ip value. */
1170 path
->attr
->evpn_overlay
.type
= OVERLAY_INDEX_GATEWAY_IP
;
1171 memcpy(&path
->attr
->evpn_overlay
.gw_ip
, &gw_ip
->ip
.addr
,
1178 * Route map `evpn gateway-ip' compile function.
1179 * Given string is converted to struct ipaddr structure
1181 static void *route_set_evpn_gateway_ip_compile(const char *arg
)
1183 struct ipaddr
*gw_ip
= NULL
;
1186 gw_ip
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct ipaddr
));
1188 ret
= str2ipaddr(arg
, gw_ip
);
1190 XFREE(MTYPE_ROUTE_MAP_COMPILED
, gw_ip
);
1196 /* Free route map's compiled `evpn gateway_ip' value. */
1197 static void route_set_evpn_gateway_ip_free(void *rule
)
1199 struct ipaddr
*gw_ip
= rule
;
1201 XFREE(MTYPE_ROUTE_MAP_COMPILED
, gw_ip
);
1204 /* Route map commands for set evpn gateway-ip ipv4. */
1205 struct route_map_rule_cmd route_set_evpn_gateway_ip_ipv4_cmd
= {
1206 "evpn gateway-ip ipv4", route_set_evpn_gateway_ip
,
1207 route_set_evpn_gateway_ip_compile
, route_set_evpn_gateway_ip_free
};
1209 /* Route map commands for set evpn gateway-ip ipv6. */
1210 struct route_map_rule_cmd route_set_evpn_gateway_ip_ipv6_cmd
= {
1211 "evpn gateway-ip ipv6", route_set_evpn_gateway_ip
,
1212 route_set_evpn_gateway_ip_compile
, route_set_evpn_gateway_ip_free
};
1214 /* Route map commands for VRF route leak with source vrf matching */
1215 static enum route_map_cmd_result_t
1216 route_match_vrl_source_vrf(void *rule
, const struct prefix
*prefix
,
1219 struct bgp_path_info
*path
;
1223 path
= (struct bgp_path_info
*)object
;
1225 if (strncmp(vrf_name
, "n/a", VRF_NAMSIZ
) == 0)
1226 return RMAP_NOMATCH
;
1228 if (path
->extra
== NULL
|| path
->extra
->bgp_orig
== NULL
)
1229 return RMAP_NOMATCH
;
1231 if (strncmp(vrf_name
, vrf_id_to_name(path
->extra
->bgp_orig
->vrf_id
),
1236 return RMAP_NOMATCH
;
1239 static void *route_match_vrl_source_vrf_compile(const char *arg
)
1241 uint8_t *vrf_name
= NULL
;
1243 vrf_name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1248 /* Free route map's compiled `route-type' value. */
1249 static void route_match_vrl_source_vrf_free(void *rule
)
1251 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1254 static const struct route_map_rule_cmd route_match_vrl_source_vrf_cmd
= {
1256 route_match_vrl_source_vrf
,
1257 route_match_vrl_source_vrf_compile
,
1258 route_match_vrl_source_vrf_free
1262 static enum route_map_cmd_result_t
1263 route_match_alias(void *rule
, const struct prefix
*prefix
, void *object
)
1266 struct bgp_path_info
*path
= object
;
1271 if (bgp_attr_get_community(path
->attr
)) {
1273 frrstr_split(bgp_attr_get_community(path
->attr
)->str
, " ",
1274 &communities
, &num
);
1275 for (int i
= 0; i
< num
; i
++) {
1276 const char *com2alias
=
1277 bgp_community2alias(communities
[i
]);
1278 if (!found
&& strcmp(alias
, com2alias
) == 0)
1280 XFREE(MTYPE_TMP
, communities
[i
]);
1282 XFREE(MTYPE_TMP
, communities
);
1287 if (bgp_attr_get_lcommunity(path
->attr
)) {
1289 frrstr_split(bgp_attr_get_lcommunity(path
->attr
)->str
, " ",
1290 &communities
, &num
);
1291 for (int i
= 0; i
< num
; i
++) {
1292 const char *com2alias
=
1293 bgp_community2alias(communities
[i
]);
1294 if (!found
&& strcmp(alias
, com2alias
) == 0)
1296 XFREE(MTYPE_TMP
, communities
[i
]);
1298 XFREE(MTYPE_TMP
, communities
);
1303 return RMAP_NOMATCH
;
1306 static void *route_match_alias_compile(const char *arg
)
1309 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1312 static void route_match_alias_free(void *rule
)
1314 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1317 static const struct route_map_rule_cmd route_match_alias_cmd
= {
1318 "alias", route_match_alias
, route_match_alias_compile
,
1319 route_match_alias_free
};
1321 /* `match local-preference LOCAL-PREF' */
1323 /* Match function return 1 if match is success else return zero. */
1324 static enum route_map_cmd_result_t
1325 route_match_local_pref(void *rule
, const struct prefix
*prefix
, void *object
)
1327 uint32_t *local_pref
;
1328 struct bgp_path_info
*path
;
1333 if (path
->attr
->local_pref
== *local_pref
)
1336 return RMAP_NOMATCH
;
1340 * Route map `match local-preference' match statement.
1341 * `arg' is local-pref value
1343 static void *route_match_local_pref_compile(const char *arg
)
1345 uint32_t *local_pref
;
1346 char *endptr
= NULL
;
1347 unsigned long tmpval
;
1349 /* Locpref value shoud be integer. */
1350 if (!all_digit(arg
))
1354 tmpval
= strtoul(arg
, &endptr
, 10);
1355 if (*endptr
!= '\0' || errno
|| tmpval
> UINT32_MAX
)
1358 local_pref
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint32_t));
1360 *local_pref
= tmpval
;
1364 /* Free route map's compiled `match local-preference' value. */
1365 static void route_match_local_pref_free(void *rule
)
1367 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1370 /* Route map commands for metric matching. */
1371 static const struct route_map_rule_cmd route_match_local_pref_cmd
= {
1373 route_match_local_pref
,
1374 route_match_local_pref_compile
,
1375 route_match_local_pref_free
1378 /* `match metric METRIC' */
1380 /* Match function return 1 if match is success else return zero. */
1381 static enum route_map_cmd_result_t
1382 route_match_metric(void *rule
, const struct prefix
*prefix
, void *object
)
1384 struct rmap_value
*rv
;
1385 struct bgp_path_info
*path
;
1389 return route_value_match(rv
, path
->attr
->med
);
1392 /* Route map commands for metric matching. */
1393 static const struct route_map_rule_cmd route_match_metric_cmd
= {
1396 route_value_compile
,
1400 /* `match as-path ASPATH' */
1402 /* Match function for as-path match. I assume given object is */
1403 static enum route_map_cmd_result_t
1404 route_match_aspath(void *rule
, const struct prefix
*prefix
, void *object
)
1407 struct as_list
*as_list
;
1408 struct bgp_path_info
*path
;
1410 as_list
= as_list_lookup((char *)rule
);
1411 if (as_list
== NULL
)
1412 return RMAP_NOMATCH
;
1416 /* Perform match. */
1417 return ((as_list_apply(as_list
, path
->attr
->aspath
) == AS_FILTER_DENY
)
1422 /* Compile function for as-path match. */
1423 static void *route_match_aspath_compile(const char *arg
)
1425 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1428 /* Compile function for as-path match. */
1429 static void route_match_aspath_free(void *rule
)
1431 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1434 /* Route map commands for aspath matching. */
1435 static const struct route_map_rule_cmd route_match_aspath_cmd
= {
1438 route_match_aspath_compile
,
1439 route_match_aspath_free
1442 /* `match community COMMUNIY' */
1443 struct rmap_community
{
1449 /* Match function for community match. */
1450 static enum route_map_cmd_result_t
1451 route_match_community(void *rule
, const struct prefix
*prefix
, void *object
)
1453 struct community_list
*list
;
1454 struct bgp_path_info
*path
;
1455 struct rmap_community
*rcom
= rule
;
1460 list
= community_list_lookup(bgp_clist
, rcom
->name
, rcom
->name_hash
,
1461 COMMUNITY_LIST_MASTER
);
1463 return RMAP_NOMATCH
;
1466 if (community_list_exact_match(
1467 bgp_attr_get_community(path
->attr
), list
))
1470 if (community_list_match(bgp_attr_get_community(path
->attr
),
1475 return RMAP_NOMATCH
;
1478 /* Compile function for community match. */
1479 static void *route_match_community_compile(const char *arg
)
1481 struct rmap_community
*rcom
;
1485 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1487 p
= strchr(arg
, ' ');
1490 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1491 memcpy(rcom
->name
, arg
, len
);
1494 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1498 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1502 /* Compile function for community match. */
1503 static void route_match_community_free(void *rule
)
1505 struct rmap_community
*rcom
= rule
;
1507 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1508 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1512 * In routemap processing there is a need to add the
1513 * name as a rule_key in the dependency table. Routemap
1514 * lib is unaware of rule_key when exact-match clause
1515 * is in use. routemap lib uses the compiled output to
1516 * get the rule_key value.
1518 static void *route_match_get_community_key(void *rule
)
1520 struct rmap_community
*rcom
;
1527 /* Route map commands for community matching. */
1528 static const struct route_map_rule_cmd route_match_community_cmd
= {
1530 route_match_community
,
1531 route_match_community_compile
,
1532 route_match_community_free
,
1533 route_match_get_community_key
1536 /* Match function for lcommunity match. */
1537 static enum route_map_cmd_result_t
1538 route_match_lcommunity(void *rule
, const struct prefix
*prefix
, void *object
)
1540 struct community_list
*list
;
1541 struct bgp_path_info
*path
;
1542 struct rmap_community
*rcom
= rule
;
1546 list
= community_list_lookup(bgp_clist
, rcom
->name
, rcom
->name_hash
,
1547 LARGE_COMMUNITY_LIST_MASTER
);
1549 return RMAP_NOMATCH
;
1552 if (lcommunity_list_exact_match(
1553 bgp_attr_get_lcommunity(path
->attr
), list
))
1556 if (lcommunity_list_match(bgp_attr_get_lcommunity(path
->attr
),
1561 return RMAP_NOMATCH
;
1564 /* Compile function for community match. */
1565 static void *route_match_lcommunity_compile(const char *arg
)
1567 struct rmap_community
*rcom
;
1571 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1573 p
= strchr(arg
, ' ');
1576 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1577 memcpy(rcom
->name
, arg
, len
);
1580 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1584 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1588 /* Compile function for community match. */
1589 static void route_match_lcommunity_free(void *rule
)
1591 struct rmap_community
*rcom
= rule
;
1593 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1594 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1597 /* Route map commands for community matching. */
1598 static const struct route_map_rule_cmd route_match_lcommunity_cmd
= {
1600 route_match_lcommunity
,
1601 route_match_lcommunity_compile
,
1602 route_match_lcommunity_free
,
1603 route_match_get_community_key
1607 /* Match function for extcommunity match. */
1608 static enum route_map_cmd_result_t
1609 route_match_ecommunity(void *rule
, const struct prefix
*prefix
, void *object
)
1611 struct community_list
*list
;
1612 struct bgp_path_info
*path
;
1613 struct rmap_community
*rcom
= rule
;
1617 list
= community_list_lookup(bgp_clist
, rcom
->name
, rcom
->name_hash
,
1618 EXTCOMMUNITY_LIST_MASTER
);
1620 return RMAP_NOMATCH
;
1622 if (ecommunity_list_match(bgp_attr_get_ecommunity(path
->attr
), list
))
1625 return RMAP_NOMATCH
;
1628 /* Compile function for extcommunity match. */
1629 static void *route_match_ecommunity_compile(const char *arg
)
1631 struct rmap_community
*rcom
;
1633 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1634 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1635 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1640 /* Compile function for extcommunity match. */
1641 static void route_match_ecommunity_free(void *rule
)
1643 struct rmap_community
*rcom
= rule
;
1645 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1646 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1649 /* Route map commands for community matching. */
1650 static const struct route_map_rule_cmd route_match_ecommunity_cmd
= {
1652 route_match_ecommunity
,
1653 route_match_ecommunity_compile
,
1654 route_match_ecommunity_free
1657 /* `match nlri` and `set nlri` are replaced by `address-family ipv4`
1658 and `address-family vpnv4'. */
1660 /* `match origin' */
1661 static enum route_map_cmd_result_t
1662 route_match_origin(void *rule
, const struct prefix
*prefix
, void *object
)
1665 struct bgp_path_info
*path
;
1670 if (path
->attr
->origin
== *origin
)
1673 return RMAP_NOMATCH
;
1676 static void *route_match_origin_compile(const char *arg
)
1680 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
1682 if (strcmp(arg
, "igp") == 0)
1684 else if (strcmp(arg
, "egp") == 0)
1692 /* Free route map's compiled `ip address' value. */
1693 static void route_match_origin_free(void *rule
)
1695 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1698 /* Route map commands for origin matching. */
1699 static const struct route_map_rule_cmd route_match_origin_cmd
= {
1702 route_match_origin_compile
,
1703 route_match_origin_free
1706 /* match probability { */
1708 static enum route_map_cmd_result_t
1709 route_match_probability(void *rule
, const struct prefix
*prefix
, void *object
)
1711 long r
= frr_weak_random();
1713 switch (*(long *)rule
) {
1719 if (r
< *(long *)rule
) {
1724 return RMAP_NOMATCH
;
1727 static void *route_match_probability_compile(const char *arg
)
1733 lobule
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(long));
1743 *lobule
= RAND_MAX
/ 100 * perc
;
1749 static void route_match_probability_free(void *rule
)
1751 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1754 static const struct route_map_rule_cmd route_match_probability_cmd
= {
1756 route_match_probability
,
1757 route_match_probability_compile
,
1758 route_match_probability_free
1761 /* `match interface IFNAME' */
1762 /* Match function should return 1 if match is success else return
1764 static enum route_map_cmd_result_t
1765 route_match_interface(void *rule
, const struct prefix
*prefix
, void *object
)
1767 struct interface
*ifp
;
1768 struct bgp_path_info
*path
;
1772 if (!path
|| !path
->peer
|| !path
->peer
->bgp
)
1773 return RMAP_NOMATCH
;
1775 ifp
= if_lookup_by_name((char *)rule
, path
->peer
->bgp
->vrf_id
);
1777 if (ifp
== NULL
|| ifp
->ifindex
!= path
->attr
->nh_ifindex
)
1778 return RMAP_NOMATCH
;
1783 /* Route map `interface' match statement. `arg' should be
1785 static void *route_match_interface_compile(const char *arg
)
1787 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1790 /* Free route map's compiled `interface' value. */
1791 static void route_match_interface_free(void *rule
)
1793 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1796 /* Route map commands for ip address matching. */
1797 static const struct route_map_rule_cmd route_match_interface_cmd
= {
1799 route_match_interface
,
1800 route_match_interface_compile
,
1801 route_match_interface_free
1806 /* `set ip next-hop IP_ADDRESS' */
1808 /* Match function return 1 if match is success else return zero. */
1809 static enum route_map_cmd_result_t
1810 route_match_tag(void *rule
, const struct prefix
*prefix
, void *object
)
1813 struct bgp_path_info
*path
;
1818 return ((path
->attr
->tag
== *tag
) ? RMAP_MATCH
: RMAP_NOMATCH
);
1822 /* Route map commands for tag matching. */
1823 static const struct route_map_rule_cmd route_match_tag_cmd
= {
1826 route_map_rule_tag_compile
,
1827 route_map_rule_tag_free
,
1830 static enum route_map_cmd_result_t
1831 route_set_srte_color(void *rule
, const struct prefix
*prefix
, void *object
)
1833 uint32_t *srte_color
= rule
;
1834 struct bgp_path_info
*path
;
1838 path
->attr
->srte_color
= *srte_color
;
1839 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_SRTE_COLOR
);
1844 /* Route map `sr-te color' compile function */
1845 static void *route_set_srte_color_compile(const char *arg
)
1849 color
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint32_t));
1855 /* Free route map's compiled `sr-te color' value. */
1856 static void route_set_srte_color_free(void *rule
)
1858 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1861 /* Route map commands for sr-te color set. */
1862 struct route_map_rule_cmd route_set_srte_color_cmd
= {
1863 "sr-te color", route_set_srte_color
, route_set_srte_color_compile
,
1864 route_set_srte_color_free
};
1866 /* Set nexthop to object. object must be pointer to struct attr. */
1867 struct rmap_ip_nexthop_set
{
1868 struct in_addr
*address
;
1873 static enum route_map_cmd_result_t
1874 route_set_ip_nexthop(void *rule
, const struct prefix
*prefix
, void *object
)
1876 struct rmap_ip_nexthop_set
*rins
= rule
;
1877 struct bgp_path_info
*path
;
1880 if (prefix
->family
== AF_INET6
)
1886 if (rins
->unchanged
) {
1887 SET_FLAG(path
->attr
->rmap_change_flags
,
1888 BATTR_RMAP_NEXTHOP_UNCHANGED
);
1889 } else if (rins
->peer_address
) {
1890 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
1891 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
1893 && sockunion_family(peer
->su_remote
) == AF_INET
) {
1894 path
->attr
->nexthop
.s_addr
=
1895 sockunion2ip(peer
->su_remote
);
1896 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1897 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
1898 /* The next hop value will be set as part of
1899 * packet rewrite. Set the flags here to indicate
1900 * that rewrite needs to be done.
1901 * Also, clear the value.
1903 SET_FLAG(path
->attr
->rmap_change_flags
,
1904 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
1905 path
->attr
->nexthop
.s_addr
= INADDR_ANY
;
1908 /* Set next hop value. */
1909 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1910 path
->attr
->nexthop
= *rins
->address
;
1911 SET_FLAG(path
->attr
->rmap_change_flags
,
1912 BATTR_RMAP_IPV4_NHOP_CHANGED
);
1913 /* case for MP-BGP : MPLS VPN */
1914 path
->attr
->mp_nexthop_global_in
= *rins
->address
;
1915 path
->attr
->mp_nexthop_len
= sizeof(*rins
->address
);
1921 /* Route map `ip nexthop' compile function. Given string is converted
1922 to struct in_addr structure. */
1923 static void *route_set_ip_nexthop_compile(const char *arg
)
1925 struct rmap_ip_nexthop_set
*rins
;
1926 struct in_addr
*address
= NULL
;
1927 int peer_address
= 0;
1931 if (strcmp(arg
, "peer-address") == 0)
1933 else if (strcmp(arg
, "unchanged") == 0)
1936 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1937 sizeof(struct in_addr
));
1938 ret
= inet_aton(arg
, address
);
1941 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
1946 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1947 sizeof(struct rmap_ip_nexthop_set
));
1949 rins
->address
= address
;
1950 rins
->peer_address
= peer_address
;
1951 rins
->unchanged
= unchanged
;
1956 /* Free route map's compiled `ip nexthop' value. */
1957 static void route_set_ip_nexthop_free(void *rule
)
1959 struct rmap_ip_nexthop_set
*rins
= rule
;
1961 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
->address
);
1963 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
);
1966 /* Route map commands for ip nexthop set. */
1967 static const struct route_map_rule_cmd route_set_ip_nexthop_cmd
= {
1969 route_set_ip_nexthop
,
1970 route_set_ip_nexthop_compile
,
1971 route_set_ip_nexthop_free
1974 /* `set l3vpn next-hop encapsulation l3vpn gre' */
1976 /* Set nexthop to object */
1977 struct rmap_l3vpn_nexthop_encapsulation_set
{
1981 static enum route_map_cmd_result_t
1982 route_set_l3vpn_nexthop_encapsulation(void *rule
, const struct prefix
*prefix
,
1985 struct rmap_l3vpn_nexthop_encapsulation_set
*rins
= rule
;
1986 struct bgp_path_info
*path
;
1990 if (rins
->protocol
!= IPPROTO_GRE
)
1993 SET_FLAG(path
->attr
->rmap_change_flags
, BATTR_RMAP_L3VPN_ACCEPT_GRE
);
1997 /* Route map `l3vpn nexthop encapsulation' compile function. */
1998 static void *route_set_l3vpn_nexthop_encapsulation_compile(const char *arg
)
2000 struct rmap_l3vpn_nexthop_encapsulation_set
*rins
;
2002 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
2003 sizeof(struct rmap_l3vpn_nexthop_encapsulation_set
));
2005 /* XXX ALL GRE modes are accepted for now: gre or ip6gre */
2006 rins
->protocol
= IPPROTO_GRE
;
2011 /* Free route map's compiled `ip nexthop' value. */
2012 static void route_set_l3vpn_nexthop_encapsulation_free(void *rule
)
2014 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2017 /* Route map commands for l3vpn next-hop encapsulation set. */
2018 static const struct route_map_rule_cmd
2019 route_set_l3vpn_nexthop_encapsulation_cmd
= {
2020 "l3vpn next-hop encapsulation",
2021 route_set_l3vpn_nexthop_encapsulation
,
2022 route_set_l3vpn_nexthop_encapsulation_compile
,
2023 route_set_l3vpn_nexthop_encapsulation_free
};
2025 /* `set local-preference LOCAL_PREF' */
2027 /* Set local preference. */
2028 static enum route_map_cmd_result_t
2029 route_set_local_pref(void *rule
, const struct prefix
*prefix
, void *object
)
2031 struct rmap_value
*rv
;
2032 struct bgp_path_info
*path
;
2033 uint32_t locpref
= 0;
2035 /* Fetch routemap's rule information. */
2039 /* Set local preference value. */
2040 if (path
->attr
->local_pref
)
2041 locpref
= path
->attr
->local_pref
;
2043 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
);
2044 path
->attr
->local_pref
= route_value_adjust(rv
, locpref
, path
->peer
);
2049 /* Set local preference rule structure. */
2050 static const struct route_map_rule_cmd route_set_local_pref_cmd
= {
2052 route_set_local_pref
,
2053 route_value_compile
,
2057 /* `set weight WEIGHT' */
2060 static enum route_map_cmd_result_t
2061 route_set_weight(void *rule
, const struct prefix
*prefix
, void *object
)
2063 struct rmap_value
*rv
;
2064 struct bgp_path_info
*path
;
2066 /* Fetch routemap's rule information. */
2070 /* Set weight value. */
2071 path
->attr
->weight
= route_value_adjust(rv
, 0, path
->peer
);
2076 /* Set local preference rule structure. */
2077 static const struct route_map_rule_cmd route_set_weight_cmd
= {
2080 route_value_compile
,
2084 /* `set distance DISTANCE */
2085 static enum route_map_cmd_result_t
2086 route_set_distance(void *rule
, const struct prefix
*prefix
, void *object
)
2088 struct bgp_path_info
*path
= object
;
2089 struct rmap_value
*rv
= rule
;
2091 path
->attr
->distance
= rv
->value
;
2096 /* set distance rule structure */
2097 static const struct route_map_rule_cmd route_set_distance_cmd
= {
2100 route_value_compile
,
2104 /* `set metric METRIC' */
2106 /* Set metric to attribute. */
2107 static enum route_map_cmd_result_t
2108 route_set_metric(void *rule
, const struct prefix
*prefix
, void *object
)
2110 struct rmap_value
*rv
;
2111 struct bgp_path_info
*path
;
2114 /* Fetch routemap's rule information. */
2118 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
))
2119 med
= path
->attr
->med
;
2121 path
->attr
->med
= route_value_adjust(rv
, med
, path
->peer
);
2122 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
);
2127 /* Set metric rule structure. */
2128 static const struct route_map_rule_cmd route_set_metric_cmd
= {
2131 route_value_compile
,
2135 /* `set table (1-4294967295)' */
2137 static enum route_map_cmd_result_t
2138 route_set_table_id(void *rule
, const struct prefix
*prefix
,
2142 struct rmap_value
*rv
;
2143 struct bgp_path_info
*path
;
2145 /* Fetch routemap's rule information. */
2149 path
->attr
->rmap_table_id
= rv
->value
;
2154 /* Set table_id rule structure. */
2155 static const struct route_map_rule_cmd route_set_table_id_cmd
= {
2158 route_value_compile
,
2162 /* `set as-path prepend ASPATH' */
2164 /* For AS path prepend mechanism. */
2165 static enum route_map_cmd_result_t
2166 route_set_aspath_prepend(void *rule
, const struct prefix
*prefix
, void *object
)
2168 struct aspath
*aspath
;
2170 struct bgp_path_info
*path
;
2174 if (path
->attr
->aspath
->refcnt
)
2175 new = aspath_dup(path
->attr
->aspath
);
2177 new = path
->attr
->aspath
;
2179 if ((uintptr_t)rule
> 10) {
2181 aspath_prepend(aspath
, new);
2183 as_t as
= aspath_leftmost(new);
2185 new = aspath_add_seq_n(new, as
, (uintptr_t)rule
);
2188 path
->attr
->aspath
= new;
2193 static void *route_set_aspath_prepend_compile(const char *arg
)
2197 if (sscanf(arg
, "last-as %u", &num
) == 1 && num
> 0 && num
<= 10)
2198 return (void *)(uintptr_t)num
;
2200 return route_aspath_compile(arg
);
2203 static void route_set_aspath_prepend_free(void *rule
)
2205 if ((uintptr_t)rule
> 10)
2206 route_aspath_free(rule
);
2210 /* Set as-path prepend rule structure. */
2211 static const struct route_map_rule_cmd route_set_aspath_prepend_cmd
= {
2213 route_set_aspath_prepend
,
2214 route_set_aspath_prepend_compile
,
2215 route_set_aspath_prepend_free
,
2218 /* `set as-path exclude ASn' */
2220 /* For ASN exclude mechanism.
2221 * Iterate over ASns requested and filter them from the given AS_PATH one by
2223 * Make a deep copy of existing AS_PATH, but for the first ASn only.
2225 static enum route_map_cmd_result_t
2226 route_set_aspath_exclude(void *rule
, const struct prefix
*dummy
, void *object
)
2228 struct aspath
*new_path
, *exclude_path
;
2229 struct bgp_path_info
*path
;
2231 exclude_path
= rule
;
2233 if (path
->attr
->aspath
->refcnt
)
2234 new_path
= aspath_dup(path
->attr
->aspath
);
2236 new_path
= path
->attr
->aspath
;
2237 path
->attr
->aspath
= aspath_filter_exclude(new_path
, exclude_path
);
2242 /* Set ASn exlude rule structure. */
2243 static const struct route_map_rule_cmd route_set_aspath_exclude_cmd
= {
2245 route_set_aspath_exclude
,
2246 route_aspath_compile
,
2250 /* `set as-path replace AS-PATH` */
2251 static void *route_aspath_replace_compile(const char *arg
)
2253 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2256 static void route_aspath_replace_free(void *rule
)
2258 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2261 static enum route_map_cmd_result_t
2262 route_set_aspath_replace(void *rule
, const struct prefix
*dummy
, void *object
)
2264 struct aspath
*aspath_new
;
2265 const char *replace
= rule
;
2266 struct bgp_path_info
*path
= object
;
2267 as_t own_asn
= path
->peer
->change_local_as
? path
->peer
->change_local_as
2268 : path
->peer
->local_as
;
2270 if (path
->peer
->sort
!= BGP_PEER_EBGP
) {
2272 "`set as-path replace` is supported only for EBGP peers");
2276 if (path
->attr
->aspath
->refcnt
)
2277 aspath_new
= aspath_dup(path
->attr
->aspath
);
2279 aspath_new
= path
->attr
->aspath
;
2281 if (strmatch(replace
, "any")) {
2282 path
->attr
->aspath
=
2283 aspath_replace_all_asn(aspath_new
, own_asn
);
2285 as_t replace_asn
= strtoul(replace
, NULL
, 10);
2287 path
->attr
->aspath
= aspath_replace_specific_asn(
2288 aspath_new
, replace_asn
, own_asn
);
2291 aspath_free(aspath_new
);
2296 static const struct route_map_rule_cmd route_set_aspath_replace_cmd
= {
2298 route_set_aspath_replace
,
2299 route_aspath_replace_compile
,
2300 route_aspath_replace_free
,
2303 /* `set community COMMUNITY' */
2304 struct rmap_com_set
{
2305 struct community
*com
;
2310 /* For community set mechanism. */
2311 static enum route_map_cmd_result_t
2312 route_set_community(void *rule
, const struct prefix
*prefix
, void *object
)
2314 struct rmap_com_set
*rcs
;
2315 struct bgp_path_info
*path
;
2317 struct community
*new = NULL
;
2318 struct community
*old
;
2319 struct community
*merge
;
2324 old
= bgp_attr_get_community(attr
);
2328 bgp_attr_set_community(attr
, NULL
);
2329 /* See the longer comment down below. */
2330 if (old
&& old
->refcnt
== 0)
2331 community_free(&old
);
2335 /* "additive" case. */
2336 if (rcs
->additive
&& old
) {
2337 merge
= community_merge(community_dup(old
), rcs
->com
);
2339 new = community_uniq_sort(merge
);
2340 community_free(&merge
);
2342 new = community_dup(rcs
->com
);
2344 /* HACK: if the old community is not intern'd,
2345 * we should free it here, or all reference to it may be
2347 * Really need to cleanup attribute caching sometime.
2349 if (old
&& old
->refcnt
== 0)
2350 community_free(&old
);
2352 /* will be interned by caller if required */
2353 bgp_attr_set_community(attr
, new);
2358 /* Compile function for set community. */
2359 static void *route_set_community_compile(const char *arg
)
2361 struct rmap_com_set
*rcs
;
2362 struct community
*com
= NULL
;
2367 if (strcmp(arg
, "none") == 0)
2370 sp
= strstr(arg
, "additive");
2372 if (sp
&& sp
> arg
) {
2373 /* "additive" keyword is included. */
2378 com
= community_str2com(arg
);
2387 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
2389 rcs
->additive
= additive
;
2395 /* Free function for set community. */
2396 static void route_set_community_free(void *rule
)
2398 struct rmap_com_set
*rcs
= rule
;
2401 community_free(&rcs
->com
);
2402 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
2405 /* Set community rule structure. */
2406 static const struct route_map_rule_cmd route_set_community_cmd
= {
2408 route_set_community
,
2409 route_set_community_compile
,
2410 route_set_community_free
,
2413 /* `set community COMMUNITY' */
2414 struct rmap_lcom_set
{
2415 struct lcommunity
*lcom
;
2421 /* For lcommunity set mechanism. */
2422 static enum route_map_cmd_result_t
2423 route_set_lcommunity(void *rule
, const struct prefix
*prefix
, void *object
)
2425 struct rmap_lcom_set
*rcs
;
2426 struct bgp_path_info
*path
;
2428 struct lcommunity
*new = NULL
;
2429 struct lcommunity
*old
;
2430 struct lcommunity
*merge
;
2435 old
= bgp_attr_get_lcommunity(attr
);
2439 bgp_attr_set_lcommunity(attr
, NULL
);
2441 /* See the longer comment down below. */
2442 if (old
&& old
->refcnt
== 0)
2443 lcommunity_free(&old
);
2447 if (rcs
->additive
&& old
) {
2448 merge
= lcommunity_merge(lcommunity_dup(old
), rcs
->lcom
);
2450 new = lcommunity_uniq_sort(merge
);
2451 lcommunity_free(&merge
);
2453 new = lcommunity_dup(rcs
->lcom
);
2455 /* HACK: if the old large-community is not intern'd,
2456 * we should free it here, or all reference to it may be
2458 * Really need to cleanup attribute caching sometime.
2460 if (old
&& old
->refcnt
== 0)
2461 lcommunity_free(&old
);
2463 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
2464 bgp_attr_set_lcommunity(attr
, new);
2469 /* Compile function for set community. */
2470 static void *route_set_lcommunity_compile(const char *arg
)
2472 struct rmap_lcom_set
*rcs
;
2473 struct lcommunity
*lcom
= NULL
;
2478 if (strcmp(arg
, "none") == 0)
2481 sp
= strstr(arg
, "additive");
2483 if (sp
&& sp
> arg
) {
2484 /* "additive" keyworkd is included. */
2489 lcom
= lcommunity_str2com(arg
);
2498 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
2500 rcs
->additive
= additive
;
2506 /* Free function for set lcommunity. */
2507 static void route_set_lcommunity_free(void *rule
)
2509 struct rmap_lcom_set
*rcs
= rule
;
2512 lcommunity_free(&rcs
->lcom
);
2514 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
2517 /* Set community rule structure. */
2518 static const struct route_map_rule_cmd route_set_lcommunity_cmd
= {
2520 route_set_lcommunity
,
2521 route_set_lcommunity_compile
,
2522 route_set_lcommunity_free
,
2525 /* `set large-comm-list (<1-99>|<100-500>|WORD) delete' */
2527 /* For large community set mechanism. */
2528 static enum route_map_cmd_result_t
2529 route_set_lcommunity_delete(void *rule
, const struct prefix
*pfx
, void *object
)
2531 struct community_list
*list
;
2532 struct lcommunity
*merge
;
2533 struct lcommunity
*new;
2534 struct lcommunity
*old
;
2535 struct bgp_path_info
*path
;
2536 struct rmap_community
*rcom
= rule
;
2542 list
= community_list_lookup(bgp_clist
, rcom
->name
, rcom
->name_hash
,
2543 LARGE_COMMUNITY_LIST_MASTER
);
2544 old
= bgp_attr_get_lcommunity(path
->attr
);
2547 merge
= lcommunity_list_match_delete(lcommunity_dup(old
), list
);
2548 new = lcommunity_uniq_sort(merge
);
2549 lcommunity_free(&merge
);
2551 /* HACK: if the old community is not intern'd,
2552 * we should free it here, or all reference to it may be
2554 * Really need to cleanup attribute caching sometime.
2556 if (old
->refcnt
== 0)
2557 lcommunity_free(&old
);
2559 if (new->size
== 0) {
2560 bgp_attr_set_lcommunity(path
->attr
, NULL
);
2561 lcommunity_free(&new);
2563 bgp_attr_set_lcommunity(path
->attr
, new);
2570 /* Compile function for set lcommunity. */
2571 static void *route_set_lcommunity_delete_compile(const char *arg
)
2573 struct rmap_community
*rcom
;
2577 frrstr_split(arg
, " ", &splits
, &num
);
2579 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2580 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, splits
[0]);
2581 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2583 for (int i
= 0; i
< num
; i
++)
2584 XFREE(MTYPE_TMP
, splits
[i
]);
2585 XFREE(MTYPE_TMP
, splits
);
2590 /* Free function for set lcommunity. */
2591 static void route_set_lcommunity_delete_free(void *rule
)
2593 struct rmap_community
*rcom
= rule
;
2595 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2596 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2599 /* Set lcommunity rule structure. */
2600 static const struct route_map_rule_cmd route_set_lcommunity_delete_cmd
= {
2602 route_set_lcommunity_delete
,
2603 route_set_lcommunity_delete_compile
,
2604 route_set_lcommunity_delete_free
,
2608 /* `set comm-list (<1-99>|<100-500>|WORD) delete' */
2610 /* For community set mechanism. */
2611 static enum route_map_cmd_result_t
2612 route_set_community_delete(void *rule
, const struct prefix
*prefix
,
2615 struct community_list
*list
;
2616 struct community
*merge
;
2617 struct community
*new;
2618 struct community
*old
;
2619 struct bgp_path_info
*path
;
2620 struct rmap_community
*rcom
= rule
;
2626 list
= community_list_lookup(bgp_clist
, rcom
->name
, rcom
->name_hash
,
2627 COMMUNITY_LIST_MASTER
);
2628 old
= bgp_attr_get_community(path
->attr
);
2631 merge
= community_list_match_delete(community_dup(old
), list
);
2632 new = community_uniq_sort(merge
);
2633 community_free(&merge
);
2635 /* HACK: if the old community is not intern'd,
2636 * we should free it here, or all reference to it may be
2638 * Really need to cleanup attribute caching sometime.
2640 if (old
->refcnt
== 0)
2641 community_free(&old
);
2643 if (new->size
== 0) {
2644 bgp_attr_set_community(path
->attr
, NULL
);
2645 community_free(&new);
2647 bgp_attr_set_community(path
->attr
, new);
2654 /* Compile function for set community. */
2655 static void *route_set_community_delete_compile(const char *arg
)
2657 struct rmap_community
*rcom
;
2661 frrstr_split(arg
, " ", &splits
, &num
);
2663 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2664 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, splits
[0]);
2665 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2667 for (int i
= 0; i
< num
; i
++)
2668 XFREE(MTYPE_TMP
, splits
[i
]);
2669 XFREE(MTYPE_TMP
, splits
);
2674 /* Free function for set community. */
2675 static void route_set_community_delete_free(void *rule
)
2677 struct rmap_community
*rcom
= rule
;
2679 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2680 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2683 /* Set community rule structure. */
2684 static const struct route_map_rule_cmd route_set_community_delete_cmd
= {
2686 route_set_community_delete
,
2687 route_set_community_delete_compile
,
2688 route_set_community_delete_free
,
2691 /* `set extcommunity rt COMMUNITY' */
2693 struct rmap_ecom_set
{
2694 struct ecommunity
*ecom
;
2698 /* For community set mechanism. Used by _rt and _soo. */
2699 static enum route_map_cmd_result_t
2700 route_set_ecommunity(void *rule
, const struct prefix
*prefix
, void *object
)
2702 struct rmap_ecom_set
*rcs
;
2703 struct ecommunity
*new_ecom
;
2704 struct ecommunity
*old_ecom
;
2705 struct bgp_path_info
*path
;
2713 bgp_attr_set_ecommunity(attr
, NULL
);
2720 /* We assume additive for Extended Community. */
2721 old_ecom
= bgp_attr_get_ecommunity(path
->attr
);
2725 ecommunity_merge(ecommunity_dup(old_ecom
), rcs
->ecom
);
2727 /* old_ecom->refcnt = 1 => owned elsewhere, e.g.
2728 * bgp_update_receive()
2729 * ->refcnt = 0 => set by a previous route-map
2731 if (!old_ecom
->refcnt
)
2732 ecommunity_free(&old_ecom
);
2734 new_ecom
= ecommunity_dup(rcs
->ecom
);
2736 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
2737 bgp_attr_set_ecommunity(path
->attr
, new_ecom
);
2742 static void *route_set_ecommunity_none_compile(const char *arg
)
2744 struct rmap_ecom_set
*rcs
;
2747 if (strncmp(arg
, "none", 4) == 0)
2750 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_ecom_set
));
2757 static void *route_set_ecommunity_rt_compile(const char *arg
)
2759 struct rmap_ecom_set
*rcs
;
2760 struct ecommunity
*ecom
;
2762 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_ROUTE_TARGET
, 0);
2766 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_ecom_set
));
2767 rcs
->ecom
= ecommunity_intern(ecom
);
2773 /* Free function for set community. Used by _rt and _soo */
2774 static void route_set_ecommunity_free(void *rule
)
2776 struct rmap_ecom_set
*rcs
= rule
;
2779 ecommunity_unintern(&rcs
->ecom
);
2781 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
2784 static const struct route_map_rule_cmd route_set_ecommunity_none_cmd
= {
2786 route_set_ecommunity
,
2787 route_set_ecommunity_none_compile
,
2788 route_set_ecommunity_free
,
2791 /* Set community rule structure. */
2792 static const struct route_map_rule_cmd route_set_ecommunity_rt_cmd
= {
2794 route_set_ecommunity
,
2795 route_set_ecommunity_rt_compile
,
2796 route_set_ecommunity_free
,
2799 /* `set extcommunity soo COMMUNITY' */
2801 /* Compile function for set community. */
2802 static void *route_set_ecommunity_soo_compile(const char *arg
)
2804 struct rmap_ecom_set
*rcs
;
2805 struct ecommunity
*ecom
;
2807 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_SITE_ORIGIN
, 0);
2811 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_ecom_set
));
2812 rcs
->ecom
= ecommunity_intern(ecom
);
2818 /* Set community rule structure. */
2819 static const struct route_map_rule_cmd route_set_ecommunity_soo_cmd
= {
2821 route_set_ecommunity
,
2822 route_set_ecommunity_soo_compile
,
2823 route_set_ecommunity_free
,
2826 /* `set extcommunity bandwidth' */
2828 struct rmap_ecomm_lb_set
{
2830 #define RMAP_ECOMM_LB_SET_VALUE 1
2831 #define RMAP_ECOMM_LB_SET_CUMUL 2
2832 #define RMAP_ECOMM_LB_SET_NUM_MPATH 3
2837 static enum route_map_cmd_result_t
2838 route_set_ecommunity_lb(void *rule
, const struct prefix
*prefix
, void *object
)
2840 struct rmap_ecomm_lb_set
*rels
= rule
;
2841 struct bgp_path_info
*path
;
2843 struct ecommunity ecom_lb
= {0};
2844 struct ecommunity_val lb_eval
;
2845 uint32_t bw_bytes
= 0;
2846 uint16_t mpath_count
= 0;
2847 struct ecommunity
*new_ecom
;
2848 struct ecommunity
*old_ecom
;
2853 if (!peer
|| !peer
->bgp
)
2856 /* Build link bandwidth extended community */
2857 as
= (peer
->bgp
->as
> BGP_AS_MAX
) ? BGP_AS_TRANS
: peer
->bgp
->as
;
2858 if (rels
->lb_type
== RMAP_ECOMM_LB_SET_VALUE
) {
2859 bw_bytes
= ((uint64_t)rels
->bw
* 1000 * 1000) / 8;
2860 } else if (rels
->lb_type
== RMAP_ECOMM_LB_SET_CUMUL
) {
2861 /* process this only for the best path. */
2862 if (!CHECK_FLAG(path
->flags
, BGP_PATH_SELECTED
))
2865 bw_bytes
= (uint32_t)bgp_path_info_mpath_cumbw(path
);
2869 } else if (rels
->lb_type
== RMAP_ECOMM_LB_SET_NUM_MPATH
) {
2871 /* process this only for the best path. */
2872 if (!CHECK_FLAG(path
->flags
, BGP_PATH_SELECTED
))
2875 bw_bytes
= ((uint64_t)peer
->bgp
->lb_ref_bw
* 1000 * 1000) / 8;
2876 mpath_count
= bgp_path_info_mpath_count(path
) + 1;
2877 bw_bytes
*= mpath_count
;
2880 encode_lb_extcomm(as
, bw_bytes
, rels
->non_trans
, &lb_eval
,
2881 CHECK_FLAG(peer
->flags
,
2882 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE
));
2884 /* add to route or merge with existing */
2885 old_ecom
= bgp_attr_get_ecommunity(path
->attr
);
2887 new_ecom
= ecommunity_dup(old_ecom
);
2888 ecommunity_add_val(new_ecom
, &lb_eval
, true, true);
2889 if (!old_ecom
->refcnt
)
2890 ecommunity_free(&old_ecom
);
2893 ecom_lb
.unit_size
= ECOMMUNITY_SIZE
;
2894 ecom_lb
.val
= (uint8_t *)lb_eval
.val
;
2895 new_ecom
= ecommunity_dup(&ecom_lb
);
2898 /* new_ecom will be intern()'d or attr_flush()'d in call stack */
2899 bgp_attr_set_ecommunity(path
->attr
, new_ecom
);
2901 /* Mark that route-map has set link bandwidth; used in attribute
2902 * setting decisions.
2904 SET_FLAG(path
->attr
->rmap_change_flags
, BATTR_RMAP_LINK_BW_SET
);
2909 static void *route_set_ecommunity_lb_compile(const char *arg
)
2911 struct rmap_ecomm_lb_set
*rels
;
2914 char bw_str
[40] = {0};
2916 bool non_trans
= false;
2919 p
= strchr(arg
, ' ');
2924 memcpy(bw_str
, arg
, len
);
2929 if (strcmp(str
, "cumulative") == 0)
2930 lb_type
= RMAP_ECOMM_LB_SET_CUMUL
;
2931 else if (strcmp(str
, "num-multipaths") == 0)
2932 lb_type
= RMAP_ECOMM_LB_SET_NUM_MPATH
;
2936 bw
= strtoul(str
, &end
, 10);
2939 lb_type
= RMAP_ECOMM_LB_SET_VALUE
;
2942 rels
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
2943 sizeof(struct rmap_ecomm_lb_set
));
2944 rels
->lb_type
= lb_type
;
2946 rels
->non_trans
= non_trans
;
2951 static void route_set_ecommunity_lb_free(void *rule
)
2953 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2956 /* Set community rule structure. */
2957 struct route_map_rule_cmd route_set_ecommunity_lb_cmd
= {
2958 "extcommunity bandwidth",
2959 route_set_ecommunity_lb
,
2960 route_set_ecommunity_lb_compile
,
2961 route_set_ecommunity_lb_free
,
2964 /* `set origin ORIGIN' */
2966 /* For origin set. */
2967 static enum route_map_cmd_result_t
2968 route_set_origin(void *rule
, const struct prefix
*prefix
, void *object
)
2971 struct bgp_path_info
*path
;
2976 path
->attr
->origin
= *origin
;
2981 /* Compile function for origin set. */
2982 static void *route_set_origin_compile(const char *arg
)
2986 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
2988 if (strcmp(arg
, "igp") == 0)
2990 else if (strcmp(arg
, "egp") == 0)
2998 /* Compile function for origin set. */
2999 static void route_set_origin_free(void *rule
)
3001 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3004 /* Set origin rule structure. */
3005 static const struct route_map_rule_cmd route_set_origin_cmd
= {
3008 route_set_origin_compile
,
3009 route_set_origin_free
,
3012 /* `set atomic-aggregate' */
3014 /* For atomic aggregate set. */
3015 static enum route_map_cmd_result_t
3016 route_set_atomic_aggregate(void *rule
, const struct prefix
*pfx
, void *object
)
3018 struct bgp_path_info
*path
;
3021 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE
);
3026 /* Compile function for atomic aggregate. */
3027 static void *route_set_atomic_aggregate_compile(const char *arg
)
3032 /* Compile function for atomic aggregate. */
3033 static void route_set_atomic_aggregate_free(void *rule
)
3038 /* Set atomic aggregate rule structure. */
3039 static const struct route_map_rule_cmd route_set_atomic_aggregate_cmd
= {
3041 route_set_atomic_aggregate
,
3042 route_set_atomic_aggregate_compile
,
3043 route_set_atomic_aggregate_free
,
3046 /* `set aggregator as AS A.B.C.D' */
3049 struct in_addr address
;
3052 static enum route_map_cmd_result_t
3053 route_set_aggregator_as(void *rule
, const struct prefix
*prefix
, void *object
)
3055 struct bgp_path_info
*path
;
3056 struct aggregator
*aggregator
;
3061 path
->attr
->aggregator_as
= aggregator
->as
;
3062 path
->attr
->aggregator_addr
= aggregator
->address
;
3063 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR
);
3068 static void *route_set_aggregator_as_compile(const char *arg
)
3070 struct aggregator
*aggregator
;
3076 XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct aggregator
));
3077 if (sscanf(arg
, "%s %s", as
, address
) != 2) {
3078 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
3082 aggregator
->as
= strtoul(as
, NULL
, 10);
3083 ret
= inet_aton(address
, &aggregator
->address
);
3085 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
3091 static void route_set_aggregator_as_free(void *rule
)
3093 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3096 static const struct route_map_rule_cmd route_set_aggregator_as_cmd
= {
3098 route_set_aggregator_as
,
3099 route_set_aggregator_as_compile
,
3100 route_set_aggregator_as_free
,
3103 /* Set tag to object. object must be pointer to struct bgp_path_info */
3104 static enum route_map_cmd_result_t
3105 route_set_tag(void *rule
, const struct prefix
*prefix
, void *object
)
3108 struct bgp_path_info
*path
;
3114 path
->attr
->tag
= *tag
;
3119 /* Route map commands for tag set. */
3120 static const struct route_map_rule_cmd route_set_tag_cmd
= {
3123 route_map_rule_tag_compile
,
3124 route_map_rule_tag_free
,
3127 /* Set label-index to object. object must be pointer to struct bgp_path_info */
3128 static enum route_map_cmd_result_t
3129 route_set_label_index(void *rule
, const struct prefix
*prefix
, void *object
)
3131 struct rmap_value
*rv
;
3132 struct bgp_path_info
*path
;
3133 uint32_t label_index
;
3135 /* Fetch routemap's rule information. */
3139 /* Set label-index value. */
3140 label_index
= rv
->value
;
3142 path
->attr
->label_index
= label_index
;
3143 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID
);
3149 /* Route map commands for label-index set. */
3150 static const struct route_map_rule_cmd route_set_label_index_cmd
= {
3152 route_set_label_index
,
3153 route_value_compile
,
3157 /* `match ipv6 address IP_ACCESS_LIST' */
3159 static enum route_map_cmd_result_t
3160 route_match_ipv6_address(void *rule
, const struct prefix
*prefix
, void *object
)
3162 struct access_list
*alist
;
3164 if (prefix
->family
== AF_INET6
) {
3165 alist
= access_list_lookup(AFI_IP6
, (char *)rule
);
3167 return RMAP_NOMATCH
;
3169 return (access_list_apply(alist
, prefix
) == FILTER_DENY
3173 return RMAP_NOMATCH
;
3176 static void *route_match_ipv6_address_compile(const char *arg
)
3178 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
3181 static void route_match_ipv6_address_free(void *rule
)
3183 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3186 /* Route map commands for ip address matching. */
3187 static const struct route_map_rule_cmd route_match_ipv6_address_cmd
= {
3189 route_match_ipv6_address
,
3190 route_match_ipv6_address_compile
,
3191 route_match_ipv6_address_free
3194 /* `match ipv6 next-hop ACCESSLIST6_NAME' */
3195 static enum route_map_cmd_result_t
3196 route_match_ipv6_next_hop(void *rule
, const struct prefix
*prefix
, void *object
)
3198 struct bgp_path_info
*path
;
3199 struct access_list
*alist
;
3200 struct prefix_ipv6 p
;
3202 if (prefix
->family
== AF_INET6
) {
3204 p
.family
= AF_INET6
;
3205 p
.prefix
= path
->attr
->mp_nexthop_global
;
3206 p
.prefixlen
= IPV6_MAX_BITLEN
;
3208 alist
= access_list_lookup(AFI_IP6
, (char *)rule
);
3210 return RMAP_NOMATCH
;
3212 if (access_list_apply(alist
, &p
) == FILTER_PERMIT
)
3215 if (path
->attr
->mp_nexthop_len
3216 == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
) {
3217 p
.prefix
= path
->attr
->mp_nexthop_local
;
3218 if (access_list_apply(alist
, &p
) == FILTER_PERMIT
)
3223 return RMAP_NOMATCH
;
3226 static void *route_match_ipv6_next_hop_compile(const char *arg
)
3228 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
3231 static void route_match_ipv6_next_hop_free(void *rule
)
3233 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3236 static const struct route_map_rule_cmd route_match_ipv6_next_hop_cmd
= {
3238 route_match_ipv6_next_hop
,
3239 route_match_ipv6_next_hop_compile
,
3240 route_match_ipv6_next_hop_free
3243 /* `match ipv6 next-hop IP_ADDRESS' */
3245 static enum route_map_cmd_result_t
3246 route_match_ipv6_next_hop_address(void *rule
, const struct prefix
*prefix
,
3249 struct in6_addr
*addr
= rule
;
3250 struct bgp_path_info
*path
;
3254 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
))
3257 if (path
->attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
3258 && IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_local
, rule
))
3261 return RMAP_NOMATCH
;
3264 static void *route_match_ipv6_next_hop_address_compile(const char *arg
)
3266 struct in6_addr
*address
;
3269 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3271 ret
= inet_pton(AF_INET6
, arg
, address
);
3273 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3280 static void route_match_ipv6_next_hop_address_free(void *rule
)
3282 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3285 static const struct route_map_rule_cmd route_match_ipv6_next_hop_address_cmd
= {
3286 "ipv6 next-hop address",
3287 route_match_ipv6_next_hop_address
,
3288 route_match_ipv6_next_hop_address_compile
,
3289 route_match_ipv6_next_hop_address_free
3292 /* `match ip next-hop IP_ADDRESS' */
3294 static enum route_map_cmd_result_t
3295 route_match_ipv4_next_hop(void *rule
, const struct prefix
*prefix
, void *object
)
3297 struct in_addr
*addr
= rule
;
3298 struct bgp_path_info
*path
;
3302 if (path
->attr
->nexthop
.s_addr
== addr
->s_addr
3303 || (path
->attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV4
3304 && IPV4_ADDR_SAME(&path
->attr
->mp_nexthop_global_in
, addr
)))
3307 return RMAP_NOMATCH
;
3310 static void *route_match_ipv4_next_hop_compile(const char *arg
)
3312 struct in_addr
*address
;
3315 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3317 ret
= inet_pton(AF_INET
, arg
, address
);
3319 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3326 static void route_match_ipv4_next_hop_free(void *rule
)
3328 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3331 static const struct route_map_rule_cmd route_match_ipv4_next_hop_cmd
= {
3332 "ip next-hop address",
3333 route_match_ipv4_next_hop
,
3334 route_match_ipv4_next_hop_compile
,
3335 route_match_ipv4_next_hop_free
3338 /* `match ipv6 address prefix-list PREFIX_LIST' */
3340 static enum route_map_cmd_result_t
3341 route_match_ipv6_address_prefix_list(void *rule
, const struct prefix
*prefix
,
3344 return route_match_address_prefix_list(rule
, AFI_IP6
, prefix
, object
);
3347 static void *route_match_ipv6_address_prefix_list_compile(const char *arg
)
3349 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
3352 static void route_match_ipv6_address_prefix_list_free(void *rule
)
3354 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3357 static const struct route_map_rule_cmd
3358 route_match_ipv6_address_prefix_list_cmd
= {
3359 "ipv6 address prefix-list",
3360 route_match_ipv6_address_prefix_list
,
3361 route_match_ipv6_address_prefix_list_compile
,
3362 route_match_ipv6_address_prefix_list_free
3365 /* `match ipv6 next-hop type <TYPE>' */
3367 static enum route_map_cmd_result_t
3368 route_match_ipv6_next_hop_type(void *rule
, const struct prefix
*prefix
,
3371 struct bgp_path_info
*path
;
3372 struct in6_addr
*addr
= rule
;
3374 if (prefix
->family
== AF_INET6
) {
3375 path
= (struct bgp_path_info
*)object
;
3377 return RMAP_NOMATCH
;
3379 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
)
3380 && !path
->attr
->nh_ifindex
)
3384 return RMAP_NOMATCH
;
3387 static void *route_match_ipv6_next_hop_type_compile(const char *arg
)
3389 struct in6_addr
*address
;
3392 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3394 ret
= inet_pton(AF_INET6
, "::0", address
);
3396 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3403 static void route_match_ipv6_next_hop_type_free(void *rule
)
3405 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3408 static const struct route_map_rule_cmd
3409 route_match_ipv6_next_hop_type_cmd
= {
3410 "ipv6 next-hop type",
3411 route_match_ipv6_next_hop_type
,
3412 route_match_ipv6_next_hop_type_compile
,
3413 route_match_ipv6_next_hop_type_free
3416 /* `set ipv6 nexthop global IP_ADDRESS' */
3418 /* Set nexthop to object. object must be pointer to struct attr. */
3419 static enum route_map_cmd_result_t
3420 route_set_ipv6_nexthop_global(void *rule
, const struct prefix
*p
, void *object
)
3422 struct in6_addr
*address
;
3423 struct bgp_path_info
*path
;
3425 /* Fetch routemap's rule information. */
3429 /* Set next hop value. */
3430 path
->attr
->mp_nexthop_global
= *address
;
3432 /* Set nexthop length. */
3433 if (path
->attr
->mp_nexthop_len
== 0)
3434 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL
;
3436 SET_FLAG(path
->attr
->rmap_change_flags
,
3437 BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED
);
3442 /* Route map `ip next-hop' compile function. Given string is converted
3443 to struct in_addr structure. */
3444 static void *route_set_ipv6_nexthop_global_compile(const char *arg
)
3447 struct in6_addr
*address
;
3449 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3451 ret
= inet_pton(AF_INET6
, arg
, address
);
3454 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3461 /* Free route map's compiled `ip next-hop' value. */
3462 static void route_set_ipv6_nexthop_global_free(void *rule
)
3464 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3467 /* Route map commands for ip nexthop set. */
3468 static const struct route_map_rule_cmd
3469 route_set_ipv6_nexthop_global_cmd
= {
3470 "ipv6 next-hop global",
3471 route_set_ipv6_nexthop_global
,
3472 route_set_ipv6_nexthop_global_compile
,
3473 route_set_ipv6_nexthop_global_free
3476 /* Set next-hop preference value. */
3477 static enum route_map_cmd_result_t
3478 route_set_ipv6_nexthop_prefer_global(void *rule
, const struct prefix
*prefix
,
3481 struct bgp_path_info
*path
;
3484 /* Fetch routemap's rule information. */
3488 if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
3489 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
)) {
3490 /* Set next hop preference to global */
3491 path
->attr
->mp_nexthop_prefer_global
= true;
3492 SET_FLAG(path
->attr
->rmap_change_flags
,
3493 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
3495 path
->attr
->mp_nexthop_prefer_global
= false;
3496 SET_FLAG(path
->attr
->rmap_change_flags
,
3497 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
3503 static void *route_set_ipv6_nexthop_prefer_global_compile(const char *arg
)
3507 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
3513 /* Free route map's compiled `ip next-hop' value. */
3514 static void route_set_ipv6_nexthop_prefer_global_free(void *rule
)
3516 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3519 /* Route map commands for ip nexthop set preferred. */
3520 static const struct route_map_rule_cmd
3521 route_set_ipv6_nexthop_prefer_global_cmd
= {
3522 "ipv6 next-hop prefer-global",
3523 route_set_ipv6_nexthop_prefer_global
,
3524 route_set_ipv6_nexthop_prefer_global_compile
,
3525 route_set_ipv6_nexthop_prefer_global_free
3528 /* `set ipv6 nexthop local IP_ADDRESS' */
3530 /* Set nexthop to object. object must be pointer to struct attr. */
3531 static enum route_map_cmd_result_t
3532 route_set_ipv6_nexthop_local(void *rule
, const struct prefix
*p
, void *object
)
3534 struct in6_addr
*address
;
3535 struct bgp_path_info
*path
;
3537 /* Fetch routemap's rule information. */
3541 /* Set next hop value. */
3542 path
->attr
->mp_nexthop_local
= *address
;
3544 /* Set nexthop length. */
3545 if (path
->attr
->mp_nexthop_len
!= BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
3546 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
3548 SET_FLAG(path
->attr
->rmap_change_flags
,
3549 BATTR_RMAP_IPV6_LL_NHOP_CHANGED
);
3554 /* Route map `ip nexthop' compile function. Given string is converted
3555 to struct in_addr structure. */
3556 static void *route_set_ipv6_nexthop_local_compile(const char *arg
)
3559 struct in6_addr
*address
;
3561 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3563 ret
= inet_pton(AF_INET6
, arg
, address
);
3566 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3573 /* Free route map's compiled `ip nexthop' value. */
3574 static void route_set_ipv6_nexthop_local_free(void *rule
)
3576 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3579 /* Route map commands for ip nexthop set. */
3580 static const struct route_map_rule_cmd
3581 route_set_ipv6_nexthop_local_cmd
= {
3582 "ipv6 next-hop local",
3583 route_set_ipv6_nexthop_local
,
3584 route_set_ipv6_nexthop_local_compile
,
3585 route_set_ipv6_nexthop_local_free
3588 /* `set ipv6 nexthop peer-address' */
3590 /* Set nexthop to object. object must be pointer to struct attr. */
3591 static enum route_map_cmd_result_t
3592 route_set_ipv6_nexthop_peer(void *rule
, const struct prefix
*pfx
, void *object
)
3594 struct in6_addr peer_address
;
3595 struct bgp_path_info
*path
;
3598 /* Fetch routemap's rule information. */
3602 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
3603 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
3605 && sockunion_family(peer
->su_remote
) == AF_INET6
) {
3606 peer_address
= peer
->su_remote
->sin6
.sin6_addr
;
3607 /* Set next hop value and length in attribute. */
3608 if (IN6_IS_ADDR_LINKLOCAL(&peer_address
)) {
3609 path
->attr
->mp_nexthop_local
= peer_address
;
3610 if (path
->attr
->mp_nexthop_len
3611 != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
3612 path
->attr
->mp_nexthop_len
=
3613 BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
3615 path
->attr
->mp_nexthop_global
= peer_address
;
3616 if (path
->attr
->mp_nexthop_len
== 0)
3617 path
->attr
->mp_nexthop_len
=
3618 BGP_ATTR_NHLEN_IPV6_GLOBAL
;
3621 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
3622 /* The next hop value will be set as part of packet
3624 * Set the flags here to indicate that rewrite needs to
3626 * Also, clear the value - we clear both global and
3628 * nexthops, whether we send one or both is determined
3631 SET_FLAG(path
->attr
->rmap_change_flags
,
3632 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
3633 /* clear next hop value. */
3634 memset(&(path
->attr
->mp_nexthop_global
), 0,
3635 sizeof(struct in6_addr
));
3636 memset(&(path
->attr
->mp_nexthop_local
), 0,
3637 sizeof(struct in6_addr
));
3643 /* Route map `ip next-hop' compile function. Given string is converted
3644 to struct in_addr structure. */
3645 static void *route_set_ipv6_nexthop_peer_compile(const char *arg
)
3649 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
3655 /* Free route map's compiled `ip next-hop' value. */
3656 static void route_set_ipv6_nexthop_peer_free(void *rule
)
3658 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3661 /* Route map commands for ip nexthop set. */
3662 static const struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd
= {
3663 "ipv6 next-hop peer-address",
3664 route_set_ipv6_nexthop_peer
,
3665 route_set_ipv6_nexthop_peer_compile
,
3666 route_set_ipv6_nexthop_peer_free
3669 /* `set ipv4 vpn next-hop A.B.C.D' */
3671 static enum route_map_cmd_result_t
3672 route_set_vpnv4_nexthop(void *rule
, const struct prefix
*prefix
, void *object
)
3674 struct in_addr
*address
;
3675 struct bgp_path_info
*path
;
3677 /* Fetch routemap's rule information. */
3681 /* Set next hop value. */
3682 path
->attr
->mp_nexthop_global_in
= *address
;
3683 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV4
;
3688 static void *route_set_vpnv4_nexthop_compile(const char *arg
)
3691 struct in_addr
*address
;
3693 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3695 ret
= inet_aton(arg
, address
);
3698 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3705 /* `set ipv6 vpn next-hop A.B.C.D' */
3707 static enum route_map_cmd_result_t
3708 route_set_vpnv6_nexthop(void *rule
, const struct prefix
*prefix
, void *object
)
3710 struct in6_addr
*address
;
3711 struct bgp_path_info
*path
;
3713 /* Fetch routemap's rule information. */
3717 /* Set next hop value. */
3718 memcpy(&path
->attr
->mp_nexthop_global
, address
,
3719 sizeof(struct in6_addr
));
3720 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_VPNV6_GLOBAL
;
3725 static void *route_set_vpnv6_nexthop_compile(const char *arg
)
3728 struct in6_addr
*address
;
3730 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3731 ret
= inet_pton(AF_INET6
, arg
, address
);
3734 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3741 static void route_set_vpn_nexthop_free(void *rule
)
3743 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3746 /* Route map commands for ipv4 next-hop set. */
3747 static const struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd
= {
3748 "ipv4 vpn next-hop",
3749 route_set_vpnv4_nexthop
,
3750 route_set_vpnv4_nexthop_compile
,
3751 route_set_vpn_nexthop_free
3754 /* Route map commands for ipv6 next-hop set. */
3755 static const struct route_map_rule_cmd route_set_vpnv6_nexthop_cmd
= {
3756 "ipv6 vpn next-hop",
3757 route_set_vpnv6_nexthop
,
3758 route_set_vpnv6_nexthop_compile
,
3759 route_set_vpn_nexthop_free
3762 /* `set originator-id' */
3764 /* For origin set. */
3765 static enum route_map_cmd_result_t
3766 route_set_originator_id(void *rule
, const struct prefix
*prefix
, void *object
)
3768 struct in_addr
*address
;
3769 struct bgp_path_info
*path
;
3774 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
);
3775 path
->attr
->originator_id
= *address
;
3780 /* Compile function for originator-id set. */
3781 static void *route_set_originator_id_compile(const char *arg
)
3784 struct in_addr
*address
;
3786 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3788 ret
= inet_aton(arg
, address
);
3791 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3798 /* Compile function for originator_id set. */
3799 static void route_set_originator_id_free(void *rule
)
3801 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3804 /* Set originator-id rule structure. */
3805 static const struct route_map_rule_cmd route_set_originator_id_cmd
= {
3807 route_set_originator_id
,
3808 route_set_originator_id_compile
,
3809 route_set_originator_id_free
,
3812 static enum route_map_cmd_result_t
3813 route_match_rpki_extcommunity(void *rule
, const struct prefix
*prefix
,
3816 struct bgp_path_info
*path
;
3817 struct ecommunity
*ecomm
;
3818 struct ecommunity_val
*ecomm_val
;
3819 enum rpki_states
*rpki_status
= rule
;
3820 enum rpki_states ecomm_rpki_status
= RPKI_NOT_BEING_USED
;
3824 ecomm
= bgp_attr_get_ecommunity(path
->attr
);
3826 return RMAP_NOMATCH
;
3828 ecomm_val
= ecommunity_lookup(ecomm
, ECOMMUNITY_ENCODE_OPAQUE_NON_TRANS
,
3829 ECOMMUNITY_ORIGIN_VALIDATION_STATE
);
3831 return RMAP_NOMATCH
;
3833 /* The Origin Validation State is encoded in the last octet of
3834 * the extended community.
3836 switch (ecomm_val
->val
[7]) {
3837 case ECOMMUNITY_ORIGIN_VALIDATION_STATE_VALID
:
3838 ecomm_rpki_status
= RPKI_VALID
;
3840 case ECOMMUNITY_ORIGIN_VALIDATION_STATE_NOTFOUND
:
3841 ecomm_rpki_status
= RPKI_NOTFOUND
;
3843 case ECOMMUNITY_ORIGIN_VALIDATION_STATE_INVALID
:
3844 ecomm_rpki_status
= RPKI_INVALID
;
3846 case ECOMMUNITY_ORIGIN_VALIDATION_STATE_NOTUSED
:
3850 if (ecomm_rpki_status
== *rpki_status
)
3853 return RMAP_NOMATCH
;
3856 static void *route_match_extcommunity_compile(const char *arg
)
3860 rpki_status
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
3862 if (strcmp(arg
, "valid") == 0)
3863 *rpki_status
= RPKI_VALID
;
3864 else if (strcmp(arg
, "invalid") == 0)
3865 *rpki_status
= RPKI_INVALID
;
3867 *rpki_status
= RPKI_NOTFOUND
;
3872 static const struct route_map_rule_cmd route_match_rpki_extcommunity_cmd
= {
3873 "rpki-extcommunity",
3874 route_match_rpki_extcommunity
,
3875 route_match_extcommunity_compile
,
3880 * This is the workhorse routine for processing in/out routemap
3883 static void bgp_route_map_process_peer(const char *rmap_name
,
3884 struct route_map
*map
, struct peer
*peer
,
3885 int afi
, int safi
, int route_update
)
3887 struct bgp_filter
*filter
;
3889 if (!peer
|| !rmap_name
)
3892 filter
= &peer
->filter
[afi
][safi
];
3894 * in is for non-route-server clients,
3895 * out is for all peers
3897 if (filter
->map
[RMAP_IN
].name
3898 && (strcmp(rmap_name
, filter
->map
[RMAP_IN
].name
) == 0)) {
3899 filter
->map
[RMAP_IN
].map
= map
;
3901 if (route_update
&& peer_established(peer
)) {
3902 if (CHECK_FLAG(peer
->af_flags
[afi
][safi
],
3903 PEER_FLAG_SOFT_RECONFIG
)) {
3904 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3906 "Processing route_map %s(%s:%s) update on peer %s (inbound, soft-reconfig)",
3907 rmap_name
, afi2str(afi
),
3908 safi2str(safi
), peer
->host
);
3910 bgp_soft_reconfig_in(peer
, afi
, safi
);
3911 } else if (CHECK_FLAG(peer
->cap
,
3912 PEER_CAP_REFRESH_OLD_RCV
)
3913 || CHECK_FLAG(peer
->cap
,
3914 PEER_CAP_REFRESH_NEW_RCV
)) {
3915 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3917 "Processing route_map %s(%s:%s) update on peer %s (inbound, route-refresh)",
3918 rmap_name
, afi2str(afi
),
3919 safi2str(safi
), peer
->host
);
3920 bgp_route_refresh_send(
3921 peer
, afi
, safi
, 0, 0, 0,
3922 BGP_ROUTE_REFRESH_NORMAL
);
3928 * For outbound, unsuppress and default-originate map change (content or
3929 * map created), merely update the "config" here, the actual route
3930 * announcement happens at the group level.
3932 if (filter
->map
[RMAP_OUT
].name
3933 && (strcmp(rmap_name
, filter
->map
[RMAP_OUT
].name
) == 0))
3934 filter
->map
[RMAP_OUT
].map
= map
;
3936 if (filter
->usmap
.name
&& (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3937 filter
->usmap
.map
= map
;
3939 if (filter
->advmap
.aname
3940 && (strcmp(rmap_name
, filter
->advmap
.aname
) == 0)) {
3941 filter
->advmap
.amap
= map
;
3944 if (filter
->advmap
.cname
3945 && (strcmp(rmap_name
, filter
->advmap
.cname
) == 0)) {
3946 filter
->advmap
.cmap
= map
;
3949 if (peer
->default_rmap
[afi
][safi
].name
3950 && (strcmp(rmap_name
, peer
->default_rmap
[afi
][safi
].name
) == 0))
3951 peer
->default_rmap
[afi
][safi
].map
= map
;
3953 /* Notify BGP conditional advertisement scanner percess */
3954 peer
->advmap_config_change
[afi
][safi
] = true;
3957 static void bgp_route_map_update_peer_group(const char *rmap_name
,
3958 struct route_map
*map
,
3961 struct peer_group
*group
;
3962 struct listnode
*node
, *nnode
;
3963 struct bgp_filter
*filter
;
3970 /* All the peers have been updated correctly already. This is
3971 * just updating the placeholder data. No real update required.
3973 for (ALL_LIST_ELEMENTS(bgp
->group
, node
, nnode
, group
)) {
3974 FOREACH_AFI_SAFI (afi
, safi
) {
3975 filter
= &group
->conf
->filter
[afi
][safi
];
3977 for (direct
= RMAP_IN
; direct
< RMAP_MAX
; direct
++) {
3978 if ((filter
->map
[direct
].name
)
3979 && (strcmp(rmap_name
,
3980 filter
->map
[direct
].name
)
3982 filter
->map
[direct
].map
= map
;
3985 if (filter
->usmap
.name
3986 && (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3987 filter
->usmap
.map
= map
;
3989 if (filter
->advmap
.aname
&&
3990 (strcmp(rmap_name
, filter
->advmap
.aname
) == 0))
3991 filter
->advmap
.amap
= map
;
3993 if (filter
->advmap
.cname
&&
3994 (strcmp(rmap_name
, filter
->advmap
.cname
) == 0))
3995 filter
->advmap
.cmap
= map
;
4001 * Note that if an extreme number (tens of thousands) of route-maps are in use
4002 * and if bgp has an extreme number of peers, network statements, etc then this
4003 * function can consume a lot of cycles. This is due to this function being
4004 * called for each route-map and within this function we walk the list of peers,
4005 * network statements, etc looking to see if they use this route-map.
4007 static void bgp_route_map_process_update(struct bgp
*bgp
, const char *rmap_name
,
4015 struct bgp_dest
*bn
;
4016 struct bgp_static
*bgp_static
;
4017 struct bgp_aggregate
*aggregate
;
4018 struct listnode
*node
, *nnode
;
4019 struct route_map
*map
;
4020 char buf
[INET6_ADDRSTRLEN
];
4022 map
= route_map_lookup_by_name(rmap_name
);
4024 for (ALL_LIST_ELEMENTS(bgp
->peer
, node
, nnode
, peer
)) {
4026 /* Ignore dummy peer-group structure */
4027 if (CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
))
4030 FOREACH_AFI_SAFI (afi
, safi
) {
4031 /* process in/out/import/export/default-orig
4033 bgp_route_map_process_peer(rmap_name
, map
, peer
, afi
,
4034 safi
, route_update
);
4038 /* for outbound/default-orig route-maps, process for groups */
4039 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
, rmap_name
,
4042 /* update peer-group config (template) */
4043 bgp_route_map_update_peer_group(rmap_name
, map
, bgp
);
4045 FOREACH_AFI_SAFI (afi
, safi
) {
4046 /* For table route-map updates. */
4047 if (!bgp_fibupd_safi(safi
))
4050 if (bgp
->table_map
[afi
][safi
].name
4051 && (strcmp(rmap_name
, bgp
->table_map
[afi
][safi
].name
)
4054 /* bgp->table_map[afi][safi].map is NULL.
4055 * i.e Route map creation event.
4056 * So update applied_counter.
4057 * If it is not NULL, i.e It may be routemap updation or
4058 * deletion. so no need to update the counter.
4060 if (!bgp
->table_map
[afi
][safi
].map
)
4061 route_map_counter_increment(map
);
4062 bgp
->table_map
[afi
][safi
].map
= map
;
4064 if (BGP_DEBUG(zebra
, ZEBRA
))
4066 "Processing route_map %s(%s:%s) update on table map",
4067 rmap_name
, afi2str(afi
),
4070 bgp_zebra_announce_table(bgp
, afi
, safi
);
4073 /* For network route-map updates. */
4074 for (bn
= bgp_table_top(bgp
->route
[afi
][safi
]); bn
;
4075 bn
= bgp_route_next(bn
)) {
4076 bgp_static
= bgp_dest_get_bgp_static_info(bn
);
4080 if (!bgp_static
->rmap
.name
4081 || (strcmp(rmap_name
, bgp_static
->rmap
.name
) != 0))
4084 if (!bgp_static
->rmap
.map
)
4085 route_map_counter_increment(map
);
4087 bgp_static
->rmap
.map
= map
;
4089 if (route_update
&& !bgp_static
->backdoor
) {
4090 const struct prefix
*bn_p
=
4091 bgp_dest_get_prefix(bn
);
4093 if (bgp_debug_zebra(bn_p
))
4095 "Processing route_map %s(%s:%s) update on static route %s",
4096 rmap_name
, afi2str(afi
),
4098 inet_ntop(bn_p
->family
,
4099 &bn_p
->u
.prefix
, buf
,
4101 bgp_static_update(bgp
, bn_p
, bgp_static
, afi
,
4106 /* For aggregate-address route-map updates. */
4107 for (bn
= bgp_table_top(bgp
->aggregate
[afi
][safi
]); bn
;
4108 bn
= bgp_route_next(bn
)) {
4109 aggregate
= bgp_dest_get_bgp_aggregate_info(bn
);
4115 /* Update suppress map pointer. */
4116 if (aggregate
->suppress_map_name
4117 && strmatch(aggregate
->suppress_map_name
,
4119 if (aggregate
->rmap
.map
== NULL
)
4120 route_map_counter_increment(map
);
4122 aggregate
->suppress_map
= map
;
4124 bgp_aggregate_toggle_suppressed(
4125 aggregate
, bgp
, bgp_dest_get_prefix(bn
),
4131 if (aggregate
->rmap
.name
4132 && strmatch(rmap_name
, aggregate
->rmap
.name
)) {
4133 if (aggregate
->rmap
.map
== NULL
)
4134 route_map_counter_increment(map
);
4136 aggregate
->rmap
.map
= map
;
4141 if (matched
&& route_update
) {
4142 const struct prefix
*bn_p
=
4143 bgp_dest_get_prefix(bn
);
4145 if (bgp_debug_zebra(bn_p
))
4147 "Processing route_map %s(%s:%s) update on aggregate-address route %s",
4148 rmap_name
, afi2str(afi
),
4150 inet_ntop(bn_p
->family
,
4151 &bn_p
->u
.prefix
, buf
,
4153 bgp_aggregate_route(bgp
, bn_p
, afi
, safi
,
4159 /* For redistribute route-map updates. */
4160 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
4161 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
4162 struct list
*red_list
;
4163 struct bgp_redist
*red
;
4165 red_list
= bgp
->redist
[afi
][i
];
4169 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
4171 || (strcmp(rmap_name
, red
->rmap
.name
) != 0))
4175 route_map_counter_increment(map
);
4177 red
->rmap
.map
= map
;
4182 if (BGP_DEBUG(zebra
, ZEBRA
))
4184 "Processing route_map %s(%s:%s) update on redistributed routes",
4185 rmap_name
, afi2str(afi
),
4188 bgp_redistribute_resend(bgp
, afi
, i
,
4193 /* for type5 command route-maps */
4194 FOREACH_AFI_SAFI (afi
, safi
) {
4195 if (!bgp
->adv_cmd_rmap
[afi
][safi
].name
4196 || strcmp(rmap_name
, bgp
->adv_cmd_rmap
[afi
][safi
].name
)
4200 /* Make sure the route-map is populated here if not already done */
4201 bgp
->adv_cmd_rmap
[afi
][safi
].map
= map
;
4203 if (BGP_DEBUG(zebra
, ZEBRA
))
4205 "Processing route_map %s(%s:%s) update on advertise type5 route command",
4206 rmap_name
, afi2str(afi
), safi2str(safi
));
4208 if (route_update
&& advertise_type5_routes(bgp
, afi
)) {
4209 bgp_evpn_withdraw_type5_routes(bgp
, afi
, safi
);
4210 bgp_evpn_advertise_type5_routes(bgp
, afi
, safi
);
4215 static void bgp_route_map_process_update_cb(char *rmap_name
)
4217 struct listnode
*node
, *nnode
;
4220 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
)) {
4221 bgp_route_map_process_update(bgp
, rmap_name
, true);
4223 #ifdef ENABLE_BGP_VNC
4224 vnc_routemap_update(bgp
, __func__
);
4228 vpn_policy_routemap_event(rmap_name
);
4231 void bgp_route_map_update_timer(struct thread
*thread
)
4233 route_map_walk_update_list(bgp_route_map_process_update_cb
);
4236 static void bgp_route_map_mark_update(const char *rmap_name
)
4238 struct listnode
*node
, *nnode
;
4241 /* If new update is received before the current timer timed out,
4242 * turn it off and start a new timer.
4244 THREAD_OFF(bm
->t_rmap_update
);
4246 /* rmap_update_timer of 0 means don't do route updates */
4247 if (bm
->rmap_update_timer
) {
4248 thread_add_timer(bm
->master
, bgp_route_map_update_timer
,
4249 NULL
, bm
->rmap_update_timer
,
4250 &bm
->t_rmap_update
);
4252 /* Signal the groups that a route-map update event has
4254 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
4255 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
,
4256 rmap_name
, true, 1);
4258 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
)) {
4259 bgp_route_map_process_update(bgp
, rmap_name
, false);
4260 #ifdef ENABLE_BGP_VNC
4261 vnc_routemap_update(bgp
, __func__
);
4265 vpn_policy_routemap_event(rmap_name
);
4269 static void bgp_route_map_add(const char *rmap_name
)
4271 if (route_map_mark_updated(rmap_name
) == 0)
4272 bgp_route_map_mark_update(rmap_name
);
4274 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
4277 static void bgp_route_map_delete(const char *rmap_name
)
4279 if (route_map_mark_updated(rmap_name
) == 0)
4280 bgp_route_map_mark_update(rmap_name
);
4282 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_DELETED
);
4285 static void bgp_route_map_event(const char *rmap_name
)
4287 if (route_map_mark_updated(rmap_name
) == 0)
4288 bgp_route_map_mark_update(rmap_name
);
4290 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
4293 DEFUN_YANG (match_mac_address
,
4294 match_mac_address_cmd
,
4295 "match mac address ACCESSLIST_MAC_NAME",
4298 "Match address of route\n"
4299 "MAC Access-list name\n")
4302 "./match-condition[condition='frr-bgp-route-map:mac-address-list']";
4303 char xpath_value
[XPATH_MAXLEN
];
4305 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4306 snprintf(xpath_value
, sizeof(xpath_value
),
4307 "%s/rmap-match-condition/frr-bgp-route-map:list-name", xpath
);
4308 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[3]->arg
);
4310 return nb_cli_apply_changes(vty
, NULL
);
4313 DEFUN_YANG (no_match_mac_address
,
4314 no_match_mac_address_cmd
,
4315 "no match mac address ACCESSLIST_MAC_NAME",
4319 "Match address of route\n"
4320 "MAC acess-list name\n")
4323 "./match-condition[condition='frr-bgp-route-map:mac-address-list']";
4325 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4326 return nb_cli_apply_changes(vty
, NULL
);
4330 * Helper to handle the case of the user passing in a number or type string
4332 static const char *parse_evpn_rt_type(const char *num_rt_type
)
4334 switch (num_rt_type
[0]) {
4349 /* Was already full type string */
4353 DEFUN_YANG (match_evpn_route_type
,
4354 match_evpn_route_type_cmd
,
4355 "match evpn route-type <ead|1|macip|2|multicast|3|es|4|prefix|5>",
4359 EVPN_TYPE_1_HELP_STR
4360 EVPN_TYPE_1_HELP_STR
4361 EVPN_TYPE_2_HELP_STR
4362 EVPN_TYPE_2_HELP_STR
4363 EVPN_TYPE_3_HELP_STR
4364 EVPN_TYPE_3_HELP_STR
4365 EVPN_TYPE_4_HELP_STR
4366 EVPN_TYPE_4_HELP_STR
4367 EVPN_TYPE_5_HELP_STR
4368 EVPN_TYPE_5_HELP_STR
)
4371 "./match-condition[condition='frr-bgp-route-map:evpn-route-type']";
4372 char xpath_value
[XPATH_MAXLEN
];
4374 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4375 snprintf(xpath_value
, sizeof(xpath_value
),
4376 "%s/rmap-match-condition/frr-bgp-route-map:evpn-route-type",
4378 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4379 parse_evpn_rt_type(argv
[3]->arg
));
4381 return nb_cli_apply_changes(vty
, NULL
);
4384 DEFUN_YANG (no_match_evpn_route_type
,
4385 no_match_evpn_route_type_cmd
,
4386 "no match evpn route-type <ead|1|macip|2|multicast|3|es|4|prefix|5>",
4391 EVPN_TYPE_1_HELP_STR
4392 EVPN_TYPE_1_HELP_STR
4393 EVPN_TYPE_2_HELP_STR
4394 EVPN_TYPE_2_HELP_STR
4395 EVPN_TYPE_3_HELP_STR
4396 EVPN_TYPE_3_HELP_STR
4397 EVPN_TYPE_4_HELP_STR
4398 EVPN_TYPE_4_HELP_STR
4399 EVPN_TYPE_5_HELP_STR
4400 EVPN_TYPE_5_HELP_STR
)
4403 "./match-condition[condition='frr-bgp-route-map:evpn-route-type']";
4405 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4407 return nb_cli_apply_changes(vty
, NULL
);
4411 DEFUN_YANG (match_evpn_vni
,
4413 "match evpn vni " CMD_VNI_RANGE
,
4420 "./match-condition[condition='frr-bgp-route-map:evpn-vni']";
4421 char xpath_value
[XPATH_MAXLEN
];
4423 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4424 snprintf(xpath_value
, sizeof(xpath_value
),
4425 "%s/rmap-match-condition/frr-bgp-route-map:evpn-vni", xpath
);
4426 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[3]->arg
);
4428 return nb_cli_apply_changes(vty
, NULL
);
4431 DEFUN_YANG (no_match_evpn_vni
,
4432 no_match_evpn_vni_cmd
,
4433 "no match evpn vni " CMD_VNI_RANGE
,
4441 "./match-condition[condition='frr-bgp-route-map:evpn-vni']";
4442 char xpath_value
[XPATH_MAXLEN
];
4444 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4445 snprintf(xpath_value
, sizeof(xpath_value
),
4446 "%s/rmap-match-condition/frr-bgp-route-map:evpn-vni", xpath
);
4447 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_DESTROY
, argv
[3]->arg
);
4449 return nb_cli_apply_changes(vty
, NULL
);
4452 DEFUN_YANG (match_evpn_default_route
,
4453 match_evpn_default_route_cmd
,
4454 "match evpn default-route",
4457 "default EVPN type-5 route\n")
4460 "./match-condition[condition='frr-bgp-route-map:evpn-default-route']";
4461 char xpath_value
[XPATH_MAXLEN
];
4463 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4465 snprintf(xpath_value
, sizeof(xpath_value
),
4466 "%s/rmap-match-condition/frr-bgp-route-map:evpn-default-route",
4468 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, NULL
);
4470 return nb_cli_apply_changes(vty
, NULL
);
4473 DEFUN_YANG (no_match_evpn_default_route
,
4474 no_match_evpn_default_route_cmd
,
4475 "no match evpn default-route",
4479 "default EVPN type-5 route\n")
4482 "./match-condition[condition='frr-bgp-route-map:evpn-default-route']";
4484 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4486 return nb_cli_apply_changes(vty
, NULL
);
4489 DEFUN_YANG (match_evpn_rd
,
4491 "match evpn rd ASN:NN_OR_IP-ADDRESS:NN",
4494 "Route Distinguisher\n"
4495 "ASN:XX or A.B.C.D:XX\n")
4498 "./match-condition[condition='frr-bgp-route-map:evpn-rd']";
4499 char xpath_value
[XPATH_MAXLEN
];
4501 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4503 xpath_value
, sizeof(xpath_value
),
4504 "%s/rmap-match-condition/frr-bgp-route-map:route-distinguisher",
4506 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[3]->arg
);
4508 return nb_cli_apply_changes(vty
, NULL
);
4511 DEFUN_YANG (no_match_evpn_rd
,
4512 no_match_evpn_rd_cmd
,
4513 "no match evpn rd ASN:NN_OR_IP-ADDRESS:NN",
4517 "Route Distinguisher\n"
4518 "ASN:XX or A.B.C.D:XX\n")
4521 "./match-condition[condition='frr-bgp-route-map:evpn-rd']";
4523 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4524 return nb_cli_apply_changes(vty
, NULL
);
4527 DEFUN_YANG (set_evpn_gw_ip_ipv4
,
4528 set_evpn_gw_ip_ipv4_cmd
,
4529 "set evpn gateway-ip ipv4 A.B.C.D",
4532 "Set gateway IP for prefix advertisement route\n"
4534 "Gateway IP address in IPv4 format\n")
4539 "./set-action[action='frr-bgp-route-map:set-evpn-gateway-ip-ipv4']";
4540 char xpath_value
[XPATH_MAXLEN
];
4542 ret
= str2sockunion(argv
[4]->arg
, &su
);
4544 vty_out(vty
, "%% Malformed gateway IP\n");
4545 return CMD_WARNING_CONFIG_FAILED
;
4548 if (su
.sin
.sin_addr
.s_addr
== 0 ||
4549 !ipv4_unicast_valid(&su
.sin
.sin_addr
)) {
4551 "%% Gateway IP cannot be 0.0.0.0, multicast or reserved\n");
4552 return CMD_WARNING_CONFIG_FAILED
;
4555 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4557 snprintf(xpath_value
, sizeof(xpath_value
),
4558 "%s/rmap-set-action/frr-bgp-route-map:evpn-gateway-ip-ipv4",
4561 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[4]->arg
);
4562 return nb_cli_apply_changes(vty
, NULL
);
4565 DEFUN_YANG (no_set_evpn_gw_ip_ipv4
,
4566 no_set_evpn_gw_ip_ipv4_cmd
,
4567 "no set evpn gateway-ip ipv4 A.B.C.D",
4571 "Set gateway IP for prefix advertisement route\n"
4573 "Gateway IP address in IPv4 format\n")
4578 "./set-action[action='frr-bgp-route-map:set-evpn-gateway-ip-ipv4']";
4580 ret
= str2sockunion(argv
[5]->arg
, &su
);
4582 vty_out(vty
, "%% Malformed gateway IP\n");
4583 return CMD_WARNING_CONFIG_FAILED
;
4586 if (su
.sin
.sin_addr
.s_addr
== 0 ||
4587 !ipv4_unicast_valid(&su
.sin
.sin_addr
)) {
4589 "%% Gateway IP cannot be 0.0.0.0, multicast or reserved\n");
4590 return CMD_WARNING_CONFIG_FAILED
;
4593 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4595 return nb_cli_apply_changes(vty
, NULL
);
4598 DEFUN_YANG (set_evpn_gw_ip_ipv6
,
4599 set_evpn_gw_ip_ipv6_cmd
,
4600 "set evpn gateway-ip ipv6 X:X::X:X",
4603 "Set gateway IP for prefix advertisement route\n"
4605 "Gateway IP address in IPv6 format\n")
4610 "./set-action[action='frr-bgp-route-map:set-evpn-gateway-ip-ipv6']";
4611 char xpath_value
[XPATH_MAXLEN
];
4613 ret
= str2sockunion(argv
[4]->arg
, &su
);
4615 vty_out(vty
, "%% Malformed gateway IP\n");
4616 return CMD_WARNING_CONFIG_FAILED
;
4619 if (IN6_IS_ADDR_LINKLOCAL(&su
.sin6
.sin6_addr
)
4620 || IN6_IS_ADDR_MULTICAST(&su
.sin6
.sin6_addr
)) {
4622 "%% Gateway IP cannot be a linklocal or multicast address\n");
4623 return CMD_WARNING_CONFIG_FAILED
;
4626 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4628 snprintf(xpath_value
, sizeof(xpath_value
),
4629 "%s/rmap-set-action/frr-bgp-route-map:evpn-gateway-ip-ipv6",
4632 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[4]->arg
);
4633 return nb_cli_apply_changes(vty
, NULL
);
4636 DEFUN_YANG (no_set_evpn_gw_ip_ipv6
,
4637 no_set_evpn_gw_ip_ipv6_cmd
,
4638 "no set evpn gateway-ip ipv6 X:X::X:X",
4642 "Set gateway IP for prefix advertisement route\n"
4644 "Gateway IP address in IPv4 format\n")
4649 "./set-action[action='frr-bgp-route-map:set-evpn-gateway-ip-ipv6']";
4651 ret
= str2sockunion(argv
[5]->arg
, &su
);
4653 vty_out(vty
, "%% Malformed gateway IP\n");
4654 return CMD_WARNING_CONFIG_FAILED
;
4657 if (IN6_IS_ADDR_LINKLOCAL(&su
.sin6
.sin6_addr
)
4658 || IN6_IS_ADDR_MULTICAST(&su
.sin6
.sin6_addr
)) {
4660 "%% Gateway IP cannot be a linklocal or multicast address\n");
4661 return CMD_WARNING_CONFIG_FAILED
;
4664 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4666 return nb_cli_apply_changes(vty
, NULL
);
4669 DEFPY_YANG(match_vrl_source_vrf
,
4670 match_vrl_source_vrf_cmd
,
4671 "match source-vrf NAME$vrf_name",
4677 "./match-condition[condition='frr-bgp-route-map:source-vrf']";
4678 char xpath_value
[XPATH_MAXLEN
];
4680 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4681 snprintf(xpath_value
, sizeof(xpath_value
),
4682 "%s/rmap-match-condition/frr-bgp-route-map:source-vrf", xpath
);
4683 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, vrf_name
);
4685 return nb_cli_apply_changes(vty
, NULL
);
4688 DEFPY_YANG(no_match_vrl_source_vrf
,
4689 no_match_vrl_source_vrf_cmd
,
4690 "no match source-vrf NAME$vrf_name",
4696 "./match-condition[condition='frr-bgp-route-map:source-vrf']";
4698 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4699 return nb_cli_apply_changes(vty
, NULL
);
4702 DEFPY_YANG (match_peer
,
4704 "match peer <A.B.C.D$addrv4|X:X::X:X$addrv6|WORD$intf>",
4706 "Match peer address\n"
4707 "IP address of peer\n"
4708 "IPv6 address of peer\n"
4709 "Interface name of peer or peer group name\n")
4712 "./match-condition[condition='frr-bgp-route-map:peer']";
4713 char xpath_value
[XPATH_MAXLEN
];
4715 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4719 xpath_value
, sizeof(xpath_value
),
4720 "%s/rmap-match-condition/frr-bgp-route-map:peer-ipv4-address",
4722 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4724 } else if (addrv6_str
) {
4726 xpath_value
, sizeof(xpath_value
),
4727 "%s/rmap-match-condition/frr-bgp-route-map:peer-ipv6-address",
4729 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4733 xpath_value
, sizeof(xpath_value
),
4734 "%s/rmap-match-condition/frr-bgp-route-map:peer-interface",
4736 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, intf
);
4739 return nb_cli_apply_changes(vty
, NULL
);
4742 DEFUN_YANG (match_peer_local
,
4743 match_peer_local_cmd
,
4746 "Match peer address\n"
4747 "Static or Redistributed routes\n")
4750 "./match-condition[condition='frr-bgp-route-map:peer']";
4751 char xpath_value
[XPATH_MAXLEN
];
4753 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4755 snprintf(xpath_value
, sizeof(xpath_value
),
4756 "%s/rmap-match-condition/frr-bgp-route-map:peer-local", xpath
);
4757 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
4759 return nb_cli_apply_changes(vty
, NULL
);
4762 DEFUN_YANG (no_match_peer
,
4764 "no match peer [<local|A.B.C.D|X:X::X:X|WORD>]",
4767 "Match peer address\n"
4768 "Static or Redistributed routes\n"
4769 "IP address of peer\n"
4770 "IPv6 address of peer\n"
4771 "Interface name of peer\n")
4774 "./match-condition[condition='frr-bgp-route-map:peer']";
4776 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4778 return nb_cli_apply_changes(vty
, NULL
);
4781 #ifdef HAVE_SCRIPTING
4782 DEFUN_YANG (match_script
,
4784 "[no] match script WORD",
4787 "Execute script to determine match\n"
4788 "The script name to run, without .lua; e.g. 'myroutemap' to run myroutemap.lua\n")
4790 bool no
= strmatch(argv
[0]->text
, "no");
4792 argv_find(argv
, argc
, "WORD", &i
);
4793 const char *script
= argv
[i
]->arg
;
4795 "./match-condition[condition='frr-bgp-route-map:match-script']";
4796 char xpath_value
[XPATH_MAXLEN
];
4799 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4800 snprintf(xpath_value
, sizeof(xpath_value
),
4801 "%s/rmap-match-condition/frr-bgp-route-map:script",
4803 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_DESTROY
,
4806 return nb_cli_apply_changes(vty
, NULL
);
4809 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4810 snprintf(xpath_value
, sizeof(xpath_value
),
4811 "%s/rmap-match-condition/frr-bgp-route-map:script",
4813 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4816 return nb_cli_apply_changes(vty
, NULL
);
4818 #endif /* HAVE_SCRIPTING */
4820 /* match probability */
4821 DEFUN_YANG (match_probability
,
4822 match_probability_cmd
,
4823 "match probability (0-100)",
4825 "Match portion of routes defined by percentage value\n"
4826 "Percentage of routes\n")
4831 "./match-condition[condition='frr-bgp-route-map:probability']";
4832 char xpath_value
[XPATH_MAXLEN
];
4834 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4835 snprintf(xpath_value
, sizeof(xpath_value
),
4836 "%s/rmap-match-condition/frr-bgp-route-map:probability",
4838 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4839 argv
[idx_number
]->arg
);
4841 return nb_cli_apply_changes(vty
, NULL
);
4845 DEFUN_YANG (no_match_probability
,
4846 no_match_probability_cmd
,
4847 "no match probability [(1-99)]",
4850 "Match portion of routes defined by percentage value\n"
4851 "Percentage of routes\n")
4855 "./match-condition[condition='frr-bgp-route-map:probability']";
4856 char xpath_value
[XPATH_MAXLEN
];
4858 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4860 if (argc
<= idx_number
)
4861 return nb_cli_apply_changes(vty
, NULL
);
4863 snprintf(xpath_value
, sizeof(xpath_value
),
4864 "%s/rmap-match-condition/frr-bgp-route-map:probability",
4866 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_DESTROY
,
4867 argv
[idx_number
]->arg
);
4869 return nb_cli_apply_changes(vty
, NULL
);
4873 DEFPY_YANG (match_ip_route_source
,
4874 match_ip_route_source_cmd
,
4875 "match ip route-source ACCESSLIST4_NAME",
4878 "Match advertising source address of route\n"
4879 "IP Access-list name\n")
4882 "./match-condition[condition='frr-bgp-route-map:ip-route-source']";
4883 char xpath_value
[XPATH_MAXLEN
+ 32];
4886 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4887 snprintf(xpath_value
, sizeof(xpath_value
),
4888 "%s/rmap-match-condition/frr-bgp-route-map:list-name",
4890 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4891 argv
[idx_acl
]->arg
);
4893 return nb_cli_apply_changes(vty
, NULL
);
4897 DEFUN_YANG (no_match_ip_route_source
,
4898 no_match_ip_route_source_cmd
,
4899 "no match ip route-source [ACCESSLIST4_NAME]",
4903 "Match advertising source address of route\n"
4904 "IP Access-list name\n")
4907 "./match-condition[condition='frr-bgp-route-map:ip-route-source']";
4909 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4910 return nb_cli_apply_changes(vty
, NULL
);
4913 DEFUN_YANG (match_ip_route_source_prefix_list
,
4914 match_ip_route_source_prefix_list_cmd
,
4915 "match ip route-source prefix-list PREFIXLIST_NAME",
4918 "Match advertising source address of route\n"
4919 "Match entries of prefix-lists\n"
4920 "IP prefix-list name\n")
4924 "./match-condition[condition='frr-bgp-route-map:ip-route-source-prefix-list']";
4925 char xpath_value
[XPATH_MAXLEN
+ 32];
4927 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4928 snprintf(xpath_value
, sizeof(xpath_value
),
4929 "%s/rmap-match-condition/frr-bgp-route-map:list-name", xpath
);
4930 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4931 argv
[idx_word
]->arg
);
4933 return nb_cli_apply_changes(vty
, NULL
);
4937 DEFUN_YANG (no_match_ip_route_source_prefix_list
,
4938 no_match_ip_route_source_prefix_list_cmd
,
4939 "no match ip route-source prefix-list [PREFIXLIST_NAME]",
4943 "Match advertising source address of route\n"
4944 "Match entries of prefix-lists\n"
4945 "IP prefix-list name\n")
4948 "./match-condition[condition='frr-bgp-route-map:ip-route-source-prefix-list']";
4950 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4951 return nb_cli_apply_changes(vty
, NULL
);
4954 DEFUN_YANG (match_local_pref
,
4955 match_local_pref_cmd
,
4956 "match local-preference (0-4294967295)",
4958 "Match local-preference of route\n"
4964 "./match-condition[condition='frr-bgp-route-map:match-local-preference']";
4965 char xpath_value
[XPATH_MAXLEN
];
4967 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4968 snprintf(xpath_value
, sizeof(xpath_value
),
4969 "%s/rmap-match-condition/frr-bgp-route-map:local-preference",
4971 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4972 argv
[idx_number
]->arg
);
4974 return nb_cli_apply_changes(vty
, NULL
);
4978 DEFUN_YANG (no_match_local_pref
,
4979 no_match_local_pref_cmd
,
4980 "no match local-preference [(0-4294967295)]",
4983 "Match local preference of route\n"
4984 "Local preference value\n")
4986 int idx_localpref
= 3;
4988 "./match-condition[condition='frr-bgp-route-map:match-local-preference']";
4989 char xpath_value
[XPATH_MAXLEN
];
4991 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4993 if (argc
<= idx_localpref
)
4994 return nb_cli_apply_changes(vty
, NULL
);
4996 snprintf(xpath_value
, sizeof(xpath_value
),
4997 "%s/rmap-match-condition/frr-bgp-route-map:local-preference",
4999 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_DESTROY
,
5000 argv
[idx_localpref
]->arg
);
5002 return nb_cli_apply_changes(vty
, NULL
);
5005 DEFUN_YANG(match_alias
, match_alias_cmd
, "match alias ALIAS_NAME",
5007 "Match BGP community alias name\n"
5008 "BGP community alias name\n")
5010 const char *alias
= argv
[2]->arg
;
5011 struct community_alias ca1
;
5012 struct community_alias
*lookup_alias
;
5015 "./match-condition[condition='frr-bgp-route-map:match-alias']";
5016 char xpath_value
[XPATH_MAXLEN
];
5018 memset(&ca1
, 0, sizeof(ca1
));
5019 strlcpy(ca1
.alias
, alias
, sizeof(ca1
.alias
));
5020 lookup_alias
= bgp_ca_alias_lookup(&ca1
);
5021 if (!lookup_alias
) {
5022 vty_out(vty
, "%% BGP alias name '%s' does not exist\n", alias
);
5023 return CMD_WARNING_CONFIG_FAILED
;
5026 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5027 snprintf(xpath_value
, sizeof(xpath_value
),
5028 "%s/rmap-match-condition/frr-bgp-route-map:alias", xpath
);
5029 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, alias
);
5031 return nb_cli_apply_changes(vty
, NULL
);
5035 DEFUN_YANG(no_match_alias
, no_match_alias_cmd
, "no match alias [ALIAS_NAME]",
5037 "Match BGP community alias name\n"
5038 "BGP community alias name\n")
5042 "./match-condition[condition='frr-bgp-route-map:match-alias']";
5043 char xpath_value
[XPATH_MAXLEN
];
5045 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5047 if (argc
<= idx_alias
)
5048 return nb_cli_apply_changes(vty
, NULL
);
5050 snprintf(xpath_value
, sizeof(xpath_value
),
5051 "%s/rmap-match-condition/frr-bgp-route-map:alias", xpath
);
5052 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_DESTROY
,
5053 argv
[idx_alias
]->arg
);
5055 return nb_cli_apply_changes(vty
, NULL
);
5058 DEFPY_YANG (match_community
,
5059 match_community_cmd
,
5060 "match community <(1-99)|(100-500)|COMMUNITY_LIST_NAME> [exact-match]",
5062 "Match BGP community list\n"
5063 "Community-list number (standard)\n"
5064 "Community-list number (expanded)\n"
5065 "Community-list name\n"
5066 "Do exact matching of communities\n")
5069 "./match-condition[condition='frr-bgp-route-map:match-community']";
5070 char xpath_value
[XPATH_MAXLEN
];
5071 char xpath_match
[XPATH_MAXLEN
];
5072 int idx_comm_list
= 2;
5074 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5077 xpath_value
, sizeof(xpath_value
),
5078 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name",
5080 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[idx_comm_list
]->arg
);
5084 xpath_match
, sizeof(xpath_match
),
5085 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match",
5087 nb_cli_enqueue_change(vty
, xpath_match
, NB_OP_MODIFY
,
5091 xpath_match
, sizeof(xpath_match
),
5092 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match",
5094 nb_cli_enqueue_change(vty
, xpath_match
, NB_OP_MODIFY
,
5098 return nb_cli_apply_changes(vty
, NULL
);
5101 DEFUN_YANG (no_match_community
,
5102 no_match_community_cmd
,
5103 "no match community [<(1-99)|(100-500)|COMMUNITY_LIST_NAME> [exact-match]]",
5106 "Match BGP community list\n"
5107 "Community-list number (standard)\n"
5108 "Community-list number (expanded)\n"
5109 "Community-list name\n"
5110 "Do exact matching of communities\n")
5113 "./match-condition[condition='frr-bgp-route-map:match-community']";
5115 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5116 return nb_cli_apply_changes(vty
, NULL
);
5119 DEFPY_YANG (match_lcommunity
,
5120 match_lcommunity_cmd
,
5121 "match large-community <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME> [exact-match]",
5123 "Match BGP large community list\n"
5124 "Large Community-list number (standard)\n"
5125 "Large Community-list number (expanded)\n"
5126 "Large Community-list name\n"
5127 "Do exact matching of communities\n")
5130 "./match-condition[condition='frr-bgp-route-map:match-large-community']";
5131 char xpath_value
[XPATH_MAXLEN
];
5132 char xpath_match
[XPATH_MAXLEN
];
5133 int idx_lcomm_list
= 2;
5135 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5138 xpath_value
, sizeof(xpath_value
),
5139 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name",
5141 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[idx_lcomm_list
]->arg
);
5145 xpath_match
, sizeof(xpath_match
),
5146 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match",
5148 nb_cli_enqueue_change(vty
, xpath_match
, NB_OP_MODIFY
,
5152 xpath_match
, sizeof(xpath_match
),
5153 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match",
5155 nb_cli_enqueue_change(vty
, xpath_match
, NB_OP_MODIFY
,
5159 return nb_cli_apply_changes(vty
, NULL
);
5162 DEFUN_YANG (no_match_lcommunity
,
5163 no_match_lcommunity_cmd
,
5164 "no match large-community [<(1-99)|(100-500)|LCOMMUNITY_LIST_NAME> [exact-match]]",
5167 "Match BGP large community list\n"
5168 "Large Community-list number (standard)\n"
5169 "Large Community-list number (expanded)\n"
5170 "Large Community-list name\n"
5171 "Do exact matching of communities\n")
5174 "./match-condition[condition='frr-bgp-route-map:match-large-community']";
5176 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5177 return nb_cli_apply_changes(vty
, NULL
);
5180 DEFPY_YANG (match_ecommunity
,
5181 match_ecommunity_cmd
,
5182 "match extcommunity <(1-99)|(100-500)|EXTCOMMUNITY_LIST_NAME>",
5184 "Match BGP/VPN extended community list\n"
5185 "Extended community-list number (standard)\n"
5186 "Extended community-list number (expanded)\n"
5187 "Extended community-list name\n")
5190 "./match-condition[condition='frr-bgp-route-map:match-extcommunity']";
5191 char xpath_value
[XPATH_MAXLEN
];
5192 int idx_comm_list
= 2;
5194 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5197 xpath_value
, sizeof(xpath_value
),
5198 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name",
5200 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[idx_comm_list
]->arg
);
5202 return nb_cli_apply_changes(vty
, NULL
);
5206 DEFUN_YANG (no_match_ecommunity
,
5207 no_match_ecommunity_cmd
,
5208 "no match extcommunity [<(1-99)|(100-500)|EXTCOMMUNITY_LIST_NAME>]",
5211 "Match BGP/VPN extended community list\n"
5212 "Extended community-list number (standard)\n"
5213 "Extended community-list number (expanded)\n"
5214 "Extended community-list name\n")
5217 "./match-condition[condition='frr-bgp-route-map:match-extcommunity']";
5219 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5220 return nb_cli_apply_changes(vty
, NULL
);
5224 DEFUN_YANG (match_aspath
,
5226 "match as-path AS_PATH_FILTER_NAME",
5228 "Match BGP AS path list\n"
5229 "AS path access-list name\n")
5234 "./match-condition[condition='frr-bgp-route-map:as-path-list']";
5235 char xpath_value
[XPATH_MAXLEN
];
5237 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5238 snprintf(xpath_value
, sizeof(xpath_value
),
5239 "%s/rmap-match-condition/frr-bgp-route-map:list-name", xpath
);
5240 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5241 argv
[idx_word
]->arg
);
5243 return nb_cli_apply_changes(vty
, NULL
);
5247 DEFUN_YANG (no_match_aspath
,
5248 no_match_aspath_cmd
,
5249 "no match as-path [AS_PATH_FILTER_NAME]",
5252 "Match BGP AS path list\n"
5253 "AS path access-list name\n")
5256 "./match-condition[condition='frr-bgp-route-map:as-path-list']";
5258 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5260 return nb_cli_apply_changes(vty
, NULL
);
5263 DEFUN_YANG (match_origin
,
5265 "match origin <egp|igp|incomplete>",
5270 "unknown heritage\n")
5273 const char *origin_type
;
5275 "./match-condition[condition='frr-bgp-route-map:match-origin']";
5276 char xpath_value
[XPATH_MAXLEN
];
5278 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
5279 origin_type
= "igp";
5280 else if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
5281 origin_type
= "egp";
5282 else if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
5283 origin_type
= "incomplete";
5285 vty_out(vty
, "%% Invalid match origin type\n");
5286 return CMD_WARNING_CONFIG_FAILED
;
5289 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5290 snprintf(xpath_value
, sizeof(xpath_value
),
5291 "%s/rmap-match-condition/frr-bgp-route-map:origin", xpath
);
5292 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, origin_type
);
5294 return nb_cli_apply_changes(vty
, NULL
);
5298 DEFUN_YANG (no_match_origin
,
5299 no_match_origin_cmd
,
5300 "no match origin [<egp|igp|incomplete>]",
5306 "unknown heritage\n")
5309 "./match-condition[condition='frr-bgp-route-map:match-origin']";
5310 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5311 return nb_cli_apply_changes(vty
, NULL
);
5314 DEFUN_YANG (set_table_id
,
5316 "set table (1-4294967295)",
5318 "export route to non-main kernel table\n"
5319 "Kernel routing table id\n")
5322 const char *xpath
= "./set-action[action='frr-bgp-route-map:table']";
5323 char xpath_value
[XPATH_MAXLEN
];
5325 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5326 snprintf(xpath_value
, sizeof(xpath_value
),
5327 "%s/rmap-set-action/frr-bgp-route-map:table", xpath
);
5328 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5329 argv
[idx_number
]->arg
);
5330 return nb_cli_apply_changes(vty
, NULL
);
5333 DEFUN_YANG (no_set_table_id
,
5334 no_set_table_id_cmd
,
5338 "export route to non-main kernel table\n")
5340 const char *xpath
= "./set-action[action='frr-bgp-route-map:table']";
5341 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5342 return nb_cli_apply_changes(vty
, NULL
);
5345 DEFUN_YANG (set_ip_nexthop_peer
,
5346 set_ip_nexthop_peer_cmd
,
5347 "[no] set ip next-hop peer-address",
5351 "Next hop address\n"
5352 "Use peer address (for BGP only)\n")
5354 char xpath_value
[XPATH_MAXLEN
];
5356 "./set-action[action='frr-bgp-route-map:set-ipv4-nexthop']";
5358 if (strmatch(argv
[0]->text
, "no"))
5359 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5361 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5362 snprintf(xpath_value
, sizeof(xpath_value
),
5363 "%s/rmap-set-action/frr-bgp-route-map:ipv4-nexthop",
5365 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5368 return nb_cli_apply_changes(vty
, NULL
);
5371 DEFUN_YANG (set_ip_nexthop_unchanged
,
5372 set_ip_nexthop_unchanged_cmd
,
5373 "[no] set ip next-hop unchanged",
5377 "Next hop address\n"
5378 "Don't modify existing Next hop address\n")
5380 char xpath_value
[XPATH_MAXLEN
];
5382 "./set-action[action='frr-bgp-route-map:set-ipv4-nexthop']";
5384 if (strmatch(argv
[0]->text
, "no"))
5385 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5387 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5388 snprintf(xpath_value
, sizeof(xpath_value
),
5389 "%s/rmap-set-action/frr-bgp-route-map:ipv4-nexthop",
5391 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5394 return nb_cli_apply_changes(vty
, NULL
);
5397 DEFUN_YANG (set_distance
,
5399 "set distance (0-255)",
5401 "BGP Administrative Distance to use\n"
5405 const char *xpath
= "./set-action[action='frr-bgp-route-map:distance']";
5406 char xpath_value
[XPATH_MAXLEN
];
5408 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5409 snprintf(xpath_value
, sizeof(xpath_value
),
5410 "%s/rmap-set-action/frr-bgp-route-map:distance", xpath
);
5411 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5412 argv
[idx_number
]->arg
);
5413 return nb_cli_apply_changes(vty
, NULL
);
5416 DEFUN_YANG (no_set_distance
,
5417 no_set_distance_cmd
,
5418 "no set distance [(0-255)]",
5420 "BGP Administrative Distance to use\n"
5423 const char *xpath
= "./set-action[action='frr-bgp-route-map:distance']";
5425 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5426 return nb_cli_apply_changes(vty
, NULL
);
5429 DEFPY_YANG(set_l3vpn_nexthop_encapsulation
, set_l3vpn_nexthop_encapsulation_cmd
,
5430 "[no] set l3vpn next-hop encapsulation gre",
5432 "L3VPN operations\n"
5433 "Next hop Information\n"
5434 "Encapsulation options (for BGP only)\n"
5435 "Accept L3VPN traffic over GRE encapsulation\n")
5438 "./set-action[action='frr-bgp-route-map:set-l3vpn-nexthop-encapsulation']";
5439 const char *xpath_value
=
5440 "./set-action[action='frr-bgp-route-map:set-l3vpn-nexthop-encapsulation']/rmap-set-action/frr-bgp-route-map:l3vpn-nexthop-encapsulation";
5441 enum nb_operation operation
;
5444 operation
= NB_OP_DESTROY
;
5446 operation
= NB_OP_CREATE
;
5448 nb_cli_enqueue_change(vty
, xpath
, operation
, NULL
);
5449 if (operation
== NB_OP_DESTROY
)
5450 return nb_cli_apply_changes(vty
, NULL
);
5452 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "gre");
5454 return nb_cli_apply_changes(vty
, NULL
);
5457 DEFUN_YANG (set_local_pref
,
5459 "set local-preference WORD",
5461 "BGP local preference path attribute\n"
5462 "Preference value (0-4294967295)\n")
5466 "./set-action[action='frr-bgp-route-map:set-local-preference']";
5467 char xpath_value
[XPATH_MAXLEN
];
5469 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5470 snprintf(xpath_value
, sizeof(xpath_value
),
5471 "%s/rmap-set-action/frr-bgp-route-map:local-pref", xpath
);
5472 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5473 argv
[idx_number
]->arg
);
5474 return nb_cli_apply_changes(vty
, NULL
);
5477 DEFUN_YANG (no_set_local_pref
,
5478 no_set_local_pref_cmd
,
5479 "no set local-preference [WORD]",
5482 "BGP local preference path attribute\n"
5483 "Preference value (0-4294967295)\n")
5486 "./set-action[action='frr-bgp-route-map:set-local-preference']";
5488 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5489 return nb_cli_apply_changes(vty
, NULL
);
5492 DEFUN_YANG (set_weight
,
5494 "set weight (0-4294967295)",
5496 "BGP weight for routing table\n"
5500 const char *xpath
= "./set-action[action='frr-bgp-route-map:weight']";
5501 char xpath_value
[XPATH_MAXLEN
];
5503 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5504 snprintf(xpath_value
, sizeof(xpath_value
),
5505 "%s/rmap-set-action/frr-bgp-route-map:weight", xpath
);
5506 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5507 argv
[idx_number
]->arg
);
5508 return nb_cli_apply_changes(vty
, NULL
);
5511 DEFUN_YANG (no_set_weight
,
5513 "no set weight [(0-4294967295)]",
5516 "BGP weight for routing table\n"
5519 const char *xpath
= "./set-action[action='frr-bgp-route-map:weight']";
5521 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5522 return nb_cli_apply_changes(vty
, NULL
);
5525 DEFUN_YANG (set_label_index
,
5526 set_label_index_cmd
,
5527 "set label-index (0-1048560)",
5529 "Label index to associate with the prefix\n"
5530 "Label index value\n")
5534 "./set-action[action='frr-bgp-route-map:label-index']";
5535 char xpath_value
[XPATH_MAXLEN
];
5537 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5538 snprintf(xpath_value
, sizeof(xpath_value
),
5539 "%s/rmap-set-action/frr-bgp-route-map:label-index", xpath
);
5540 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5541 argv
[idx_number
]->arg
);
5542 return nb_cli_apply_changes(vty
, NULL
);
5545 DEFUN_YANG (no_set_label_index
,
5546 no_set_label_index_cmd
,
5547 "no set label-index [(0-1048560)]",
5550 "Label index to associate with the prefix\n"
5551 "Label index value\n")
5554 "./set-action[action='frr-bgp-route-map:label-index']";
5556 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5557 return nb_cli_apply_changes(vty
, NULL
);
5560 DEFUN_YANG (set_aspath_prepend_asn
,
5561 set_aspath_prepend_asn_cmd
,
5562 "set as-path prepend (1-4294967295)...",
5564 "Transform BGP AS_PATH attribute\n"
5565 "Prepend to the as-path\n"
5572 str
= argv_concat(argv
, argc
, idx_asn
);
5575 "./set-action[action='frr-bgp-route-map:as-path-prepend']";
5576 char xpath_value
[XPATH_MAXLEN
];
5578 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5579 snprintf(xpath_value
, sizeof(xpath_value
),
5580 "%s/rmap-set-action/frr-bgp-route-map:prepend-as-path", xpath
);
5581 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
5582 ret
= nb_cli_apply_changes(vty
, NULL
);
5583 XFREE(MTYPE_TMP
, str
);
5587 DEFUN_YANG (set_aspath_prepend_lastas
,
5588 set_aspath_prepend_lastas_cmd
,
5589 "set as-path prepend last-as (1-10)",
5591 "Transform BGP AS_PATH attribute\n"
5592 "Prepend to the as-path\n"
5593 "Use the last AS-number in the as-path\n"
5594 "Number of times to insert\n")
5599 "./set-action[action='frr-bgp-route-map:as-path-prepend']";
5600 char xpath_value
[XPATH_MAXLEN
];
5602 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5603 snprintf(xpath_value
, sizeof(xpath_value
),
5604 "%s/rmap-set-action/frr-bgp-route-map:last-as", xpath
);
5605 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5606 argv
[idx_num
]->arg
);
5607 return nb_cli_apply_changes(vty
, NULL
);
5610 DEFPY_YANG (set_aspath_replace_asn
,
5611 set_aspath_replace_asn_cmd
,
5612 "set as-path replace <any|(1-4294967295)>$replace",
5614 "Transform BGP AS_PATH attribute\n"
5615 "Replace AS number to local AS number\n"
5616 "Replace any AS number to local AS number\n"
5617 "Replace a specific AS number to local AS number\n")
5620 "./set-action[action='frr-bgp-route-map:as-path-replace']";
5621 char xpath_value
[XPATH_MAXLEN
];
5623 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5624 snprintf(xpath_value
, sizeof(xpath_value
),
5625 "%s/rmap-set-action/frr-bgp-route-map:replace-as-path", xpath
);
5626 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, replace
);
5627 return nb_cli_apply_changes(vty
, NULL
);
5630 DEFPY_YANG (no_set_aspath_replace_asn
,
5631 no_set_aspath_replace_asn_cmd
,
5632 "no set as-path replace [<any|(1-4294967295)>]",
5635 "Transform BGP AS_PATH attribute\n"
5636 "Replace AS number to local AS number\n"
5637 "Replace any AS number to local AS number\n"
5638 "Replace a specific AS number to local AS number\n")
5641 "./set-action[action='frr-bgp-route-map:as-path-replace']";
5643 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5644 return nb_cli_apply_changes(vty
, NULL
);
5647 DEFUN_YANG (no_set_aspath_prepend
,
5648 no_set_aspath_prepend_cmd
,
5649 "no set as-path prepend [(1-4294967295)]",
5652 "Transform BGP AS_PATH attribute\n"
5653 "Prepend to the as-path\n"
5657 "./set-action[action='frr-bgp-route-map:as-path-prepend']";
5659 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5660 return nb_cli_apply_changes(vty
, NULL
);
5663 DEFUN_YANG (no_set_aspath_prepend_lastas
,
5664 no_set_aspath_prepend_lastas_cmd
,
5665 "no set as-path prepend last-as [(1-10)]",
5668 "Transform BGP AS_PATH attribute\n"
5669 "Prepend to the as-path\n"
5670 "Use the peers AS-number\n"
5671 "Number of times to insert\n")
5674 "./set-action[action='frr-bgp-route-map:as-path-prepend']";
5676 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5677 return nb_cli_apply_changes(vty
, NULL
);
5680 DEFUN_YANG (set_aspath_exclude
,
5681 set_aspath_exclude_cmd
,
5682 "set as-path exclude (1-4294967295)...",
5684 "Transform BGP AS-path attribute\n"
5685 "Exclude from the as-path\n"
5692 str
= argv_concat(argv
, argc
, idx_asn
);
5695 "./set-action[action='frr-bgp-route-map:as-path-exclude']";
5696 char xpath_value
[XPATH_MAXLEN
];
5698 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5699 snprintf(xpath_value
, sizeof(xpath_value
),
5700 "%s/rmap-set-action/frr-bgp-route-map:exclude-as-path", xpath
);
5701 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
5702 ret
= nb_cli_apply_changes(vty
, NULL
);
5703 XFREE(MTYPE_TMP
, str
);
5707 DEFUN_YANG (no_set_aspath_exclude
,
5708 no_set_aspath_exclude_cmd
,
5709 "no set as-path exclude (1-4294967295)...",
5712 "Transform BGP AS_PATH attribute\n"
5713 "Exclude from the as-path\n"
5717 "./set-action[action='frr-bgp-route-map:as-path-exclude']";
5719 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5720 return nb_cli_apply_changes(vty
, NULL
);
5723 ALIAS_YANG (no_set_aspath_exclude
, no_set_aspath_exclude_all_cmd
,
5724 "no set as-path exclude",
5726 "Transform BGP AS_PATH attribute\n"
5727 "Exclude from the as-path\n")
5729 DEFUN_YANG (set_community
,
5731 "set community AA:NN...",
5733 "BGP community attribute\n"
5741 struct community
*com
= NULL
;
5743 char *argstr
= NULL
;
5747 "./set-action[action='frr-bgp-route-map:set-community']";
5748 char xpath_value
[XPATH_MAXLEN
];
5750 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5751 snprintf(xpath_value
, sizeof(xpath_value
),
5752 "%s/rmap-set-action/frr-bgp-route-map:community-string",
5755 b
= buffer_new(1024);
5757 for (i
= idx_aa_nn
; i
< argc
; i
++) {
5758 if (strncmp(argv
[i
]->arg
, "additive", strlen(argv
[i
]->arg
))
5765 buffer_putc(b
, ' ');
5769 if (strncmp(argv
[i
]->arg
, "internet", strlen(argv
[i
]->arg
))
5771 buffer_putstr(b
, "internet");
5774 if (strncmp(argv
[i
]->arg
, "local-AS", strlen(argv
[i
]->arg
))
5776 buffer_putstr(b
, "local-AS");
5779 if (strncmp(argv
[i
]->arg
, "no-a", strlen("no-a")) == 0
5780 && strncmp(argv
[i
]->arg
, "no-advertise",
5781 strlen(argv
[i
]->arg
))
5783 buffer_putstr(b
, "no-advertise");
5786 if (strncmp(argv
[i
]->arg
, "no-e", strlen("no-e")) == 0
5787 && strncmp(argv
[i
]->arg
, "no-export", strlen(argv
[i
]->arg
))
5789 buffer_putstr(b
, "no-export");
5792 if (strncmp(argv
[i
]->arg
, "blackhole", strlen(argv
[i
]->arg
))
5794 buffer_putstr(b
, "blackhole");
5797 if (strncmp(argv
[i
]->arg
, "graceful-shutdown",
5798 strlen(argv
[i
]->arg
))
5800 buffer_putstr(b
, "graceful-shutdown");
5803 buffer_putstr(b
, argv
[i
]->arg
);
5805 buffer_putc(b
, '\0');
5807 /* Fetch result string then compile it to communities attribute. */
5808 str
= buffer_getstr(b
);
5812 com
= community_str2com(str
);
5814 /* Can't compile user input into communities attribute. */
5816 vty_out(vty
, "%% Malformed communities attribute '%s'\n", str
);
5817 XFREE(MTYPE_TMP
, str
);
5818 return CMD_WARNING_CONFIG_FAILED
;
5820 XFREE(MTYPE_TMP
, str
);
5822 /* Set communites attribute string. */
5823 str
= community_str(com
, false, false);
5826 size_t argstr_sz
= strlen(str
) + strlen(" additive") + 1;
5827 argstr
= XCALLOC(MTYPE_TMP
, argstr_sz
);
5828 strlcpy(argstr
, str
, argstr_sz
);
5829 strlcat(argstr
, " additive", argstr_sz
);
5830 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argstr
);
5832 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
5834 ret
= nb_cli_apply_changes(vty
, NULL
);
5837 XFREE(MTYPE_TMP
, argstr
);
5838 community_free(&com
);
5843 DEFUN_YANG (set_community_none
,
5844 set_community_none_cmd
,
5845 "set community none",
5847 "BGP community attribute\n"
5848 "No community attribute\n")
5851 "./set-action[action='frr-bgp-route-map:set-community']";
5852 char xpath_value
[XPATH_MAXLEN
];
5854 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5856 snprintf(xpath_value
, sizeof(xpath_value
),
5857 "%s/rmap-set-action/frr-bgp-route-map:community-none", xpath
);
5858 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
5859 return nb_cli_apply_changes(vty
, NULL
);
5862 DEFUN_YANG (no_set_community
,
5863 no_set_community_cmd
,
5864 "no set community AA:NN...",
5867 "BGP community attribute\n"
5871 "./set-action[action='frr-bgp-route-map:set-community']";
5873 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5874 return nb_cli_apply_changes(vty
, NULL
);
5877 ALIAS_YANG (no_set_community
,
5878 no_set_community_short_cmd
,
5882 "BGP community attribute\n")
5884 DEFPY_YANG (set_community_delete
,
5885 set_community_delete_cmd
,
5886 "set comm-list <(1-99)|(100-500)|COMMUNITY_LIST_NAME> delete",
5888 "set BGP community list (for deletion)\n"
5889 "Community-list number (standard)\n"
5890 "Community-list number (expanded)\n"
5891 "Community-list name\n"
5892 "Delete matching communities\n")
5895 "./set-action[action='frr-bgp-route-map:comm-list-delete']";
5896 char xpath_value
[XPATH_MAXLEN
];
5897 int idx_comm_list
= 2;
5899 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5901 snprintf(xpath_value
, sizeof(xpath_value
),
5902 "%s/rmap-set-action/frr-bgp-route-map:comm-list-name",
5904 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5905 argv
[idx_comm_list
]->arg
);
5907 return nb_cli_apply_changes(vty
, NULL
);
5911 DEFUN_YANG (no_set_community_delete
,
5912 no_set_community_delete_cmd
,
5913 "no set comm-list [<(1-99)|(100-500)|COMMUNITY_LIST_NAME> delete]",
5916 "set BGP community list (for deletion)\n"
5917 "Community-list number (standard)\n"
5918 "Community-list number (expanded)\n"
5919 "Community-list name\n"
5920 "Delete matching communities\n")
5923 "./set-action[action='frr-bgp-route-map:comm-list-delete']";
5925 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5926 return nb_cli_apply_changes(vty
, NULL
);
5929 DEFUN_YANG (set_lcommunity
,
5931 "set large-community AA:BB:CC...",
5933 "BGP large community attribute\n"
5934 "Large Community number in aa:bb:cc format or additive\n")
5939 "./set-action[action='frr-bgp-route-map:set-large-community']";
5940 char xpath_value
[XPATH_MAXLEN
];
5942 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5944 snprintf(xpath_value
, sizeof(xpath_value
),
5945 "%s/rmap-set-action/frr-bgp-route-map:large-community-string",
5947 str
= argv_concat(argv
, argc
, 2);
5948 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
5949 ret
= nb_cli_apply_changes(vty
, NULL
);
5950 XFREE(MTYPE_TMP
, str
);
5954 DEFUN_YANG (set_lcommunity_none
,
5955 set_lcommunity_none_cmd
,
5956 "set large-community none",
5958 "BGP large community attribute\n"
5959 "No large community attribute\n")
5962 "./set-action[action='frr-bgp-route-map:set-large-community']";
5963 char xpath_value
[XPATH_MAXLEN
];
5965 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5967 snprintf(xpath_value
, sizeof(xpath_value
),
5968 "%s/rmap-set-action/frr-bgp-route-map:large-community-none",
5970 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
5971 return nb_cli_apply_changes(vty
, NULL
);
5974 DEFUN_YANG (no_set_lcommunity
,
5975 no_set_lcommunity_cmd
,
5976 "no set large-community none",
5979 "BGP large community attribute\n"
5980 "No community attribute\n")
5983 "./set-action[action='frr-bgp-route-map:set-large-community']";
5985 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5986 return nb_cli_apply_changes(vty
, NULL
);
5989 DEFUN_YANG (no_set_lcommunity1
,
5990 no_set_lcommunity1_cmd
,
5991 "no set large-community AA:BB:CC...",
5994 "BGP large community attribute\n"
5995 "Large community in AA:BB:CC... format or additive\n")
5998 "./set-action[action='frr-bgp-route-map:set-large-community']";
6000 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6001 return nb_cli_apply_changes(vty
, NULL
);
6004 ALIAS_YANG (no_set_lcommunity1
,
6005 no_set_lcommunity1_short_cmd
,
6006 "no set large-community",
6009 "BGP large community attribute\n")
6011 DEFPY_YANG (set_lcommunity_delete
,
6012 set_lcommunity_delete_cmd
,
6013 "set large-comm-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME> delete",
6015 "set BGP large community list (for deletion)\n"
6016 "Large Community-list number (standard)\n"
6017 "Large Communitly-list number (expanded)\n"
6018 "Large Community-list name\n"
6019 "Delete matching large communities\n")
6022 "./set-action[action='frr-bgp-route-map:large-comm-list-delete']";
6023 char xpath_value
[XPATH_MAXLEN
];
6024 int idx_lcomm_list
= 2;
6026 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6028 snprintf(xpath_value
, sizeof(xpath_value
),
6029 "%s/rmap-set-action/frr-bgp-route-map:comm-list-name",
6031 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6032 argv
[idx_lcomm_list
]->arg
);
6034 return nb_cli_apply_changes(vty
, NULL
);
6037 DEFUN_YANG (no_set_lcommunity_delete
,
6038 no_set_lcommunity_delete_cmd
,
6039 "no set large-comm-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME> [delete]",
6042 "set BGP large community list (for deletion)\n"
6043 "Large Community-list number (standard)\n"
6044 "Large Communitly-list number (expanded)\n"
6045 "Large Community-list name\n"
6046 "Delete matching large communities\n")
6049 "./set-action[action='frr-bgp-route-map:large-comm-list-delete']";
6051 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6052 return nb_cli_apply_changes(vty
, NULL
);
6055 ALIAS_YANG (no_set_lcommunity_delete
,
6056 no_set_lcommunity_delete_short_cmd
,
6057 "no set large-comm-list",
6060 "set BGP large community list (for deletion)\n")
6062 DEFUN_YANG (set_ecommunity_rt
,
6063 set_ecommunity_rt_cmd
,
6064 "set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
6066 "BGP extended community attribute\n"
6067 "Route Target extended community\n"
6068 "VPN extended community\n")
6074 "./set-action[action='frr-bgp-route-map:set-extcommunity-rt']";
6075 char xpath_value
[XPATH_MAXLEN
];
6077 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6079 snprintf(xpath_value
, sizeof(xpath_value
),
6080 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-rt", xpath
);
6081 str
= argv_concat(argv
, argc
, idx_asn_nn
);
6082 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
6083 ret
= nb_cli_apply_changes(vty
, NULL
);
6084 XFREE(MTYPE_TMP
, str
);
6088 DEFUN_YANG (no_set_ecommunity_rt
,
6089 no_set_ecommunity_rt_cmd
,
6090 "no set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
6093 "BGP extended community attribute\n"
6094 "Route Target extended community\n"
6095 "VPN extended community\n")
6098 "./set-action[action='frr-bgp-route-map:set-extcommunity-rt']";
6099 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6100 return nb_cli_apply_changes(vty
, NULL
);
6103 ALIAS_YANG (no_set_ecommunity_rt
,
6104 no_set_ecommunity_rt_short_cmd
,
6105 "no set extcommunity rt",
6108 "BGP extended community attribute\n"
6109 "Route Target extended community\n")
6111 DEFUN_YANG (set_ecommunity_soo
,
6112 set_ecommunity_soo_cmd
,
6113 "set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
6115 "BGP extended community attribute\n"
6116 "Site-of-Origin extended community\n"
6117 "VPN extended community\n")
6123 "./set-action[action='frr-bgp-route-map:set-extcommunity-soo']";
6124 char xpath_value
[XPATH_MAXLEN
];
6126 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6128 snprintf(xpath_value
, sizeof(xpath_value
),
6129 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-soo",
6131 str
= argv_concat(argv
, argc
, idx_asn_nn
);
6132 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
6133 ret
= nb_cli_apply_changes(vty
, NULL
);
6134 XFREE(MTYPE_TMP
, str
);
6138 DEFUN_YANG (no_set_ecommunity_soo
,
6139 no_set_ecommunity_soo_cmd
,
6140 "no set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
6143 "BGP extended community attribute\n"
6144 "Site-of-Origin extended community\n"
6145 "VPN extended community\n")
6148 "./set-action[action='frr-bgp-route-map:set-extcommunity-soo']";
6149 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6150 return nb_cli_apply_changes(vty
, NULL
);
6153 ALIAS_YANG (no_set_ecommunity_soo
,
6154 no_set_ecommunity_soo_short_cmd
,
6155 "no set extcommunity soo",
6158 "GP extended community attribute\n"
6159 "Site-of-Origin extended community\n")
6161 DEFUN_YANG(set_ecommunity_none
, set_ecommunity_none_cmd
,
6162 "set extcommunity none",
6164 "BGP extended community attribute\n"
6165 "No extended community attribute\n")
6168 "./set-action[action='frr-bgp-route-map:set-extcommunity-none']";
6169 char xpath_value
[XPATH_MAXLEN
];
6171 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6173 snprintf(xpath_value
, sizeof(xpath_value
),
6174 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-none",
6176 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
6177 return nb_cli_apply_changes(vty
, NULL
);
6180 DEFUN_YANG(no_set_ecommunity_none
, no_set_ecommunity_none_cmd
,
6181 "no set extcommunity none",
6183 "BGP extended community attribute\n"
6184 "No extended community attribute\n")
6187 "./set-action[action='frr-bgp-route-map:set-extcommunity-none']";
6188 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6189 return nb_cli_apply_changes(vty
, NULL
);
6192 DEFUN_YANG (set_ecommunity_lb
,
6193 set_ecommunity_lb_cmd
,
6194 "set extcommunity bandwidth <(1-25600)|cumulative|num-multipaths> [non-transitive]",
6196 "BGP extended community attribute\n"
6197 "Link bandwidth extended community\n"
6198 "Bandwidth value in Mbps\n"
6199 "Cumulative bandwidth of all multipaths (outbound-only)\n"
6200 "Internally computed bandwidth based on number of multipaths (outbound-only)\n"
6201 "Attribute is set as non-transitive\n")
6204 int idx_non_transitive
= 0;
6206 "./set-action[action='frr-bgp-route-map:set-extcommunity-lb']";
6207 char xpath_lb_type
[XPATH_MAXLEN
];
6208 char xpath_bandwidth
[XPATH_MAXLEN
];
6209 char xpath_non_transitive
[XPATH_MAXLEN
];
6211 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6213 snprintf(xpath_lb_type
, sizeof(xpath_lb_type
),
6214 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-lb/lb-type",
6216 snprintf(xpath_bandwidth
, sizeof(xpath_bandwidth
),
6217 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-lb/bandwidth",
6219 snprintf(xpath_non_transitive
, sizeof(xpath_non_transitive
),
6220 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-lb/two-octet-as-specific",
6223 if ((strcmp(argv
[idx_lb
]->arg
, "cumulative")) == 0)
6224 nb_cli_enqueue_change(vty
, xpath_lb_type
, NB_OP_MODIFY
,
6225 "cumulative-bandwidth");
6226 else if ((strcmp(argv
[idx_lb
]->arg
, "num-multipaths")) == 0)
6227 nb_cli_enqueue_change(vty
, xpath_lb_type
, NB_OP_MODIFY
,
6228 "computed-bandwidth");
6230 nb_cli_enqueue_change(vty
, xpath_lb_type
, NB_OP_MODIFY
,
6231 "explicit-bandwidth");
6232 nb_cli_enqueue_change(vty
, xpath_bandwidth
, NB_OP_MODIFY
,
6236 if (argv_find(argv
, argc
, "non-transitive", &idx_non_transitive
))
6237 nb_cli_enqueue_change(vty
, xpath_non_transitive
, NB_OP_MODIFY
,
6240 nb_cli_enqueue_change(vty
, xpath_non_transitive
, NB_OP_MODIFY
,
6243 return nb_cli_apply_changes(vty
, NULL
);
6246 DEFUN_YANG (no_set_ecommunity_lb
,
6247 no_set_ecommunity_lb_cmd
,
6248 "no set extcommunity bandwidth <(1-25600)|cumulative|num-multipaths> [non-transitive]",
6251 "BGP extended community attribute\n"
6252 "Link bandwidth extended community\n"
6253 "Bandwidth value in Mbps\n"
6254 "Cumulative bandwidth of all multipaths (outbound-only)\n"
6255 "Internally computed bandwidth based on number of multipaths (outbound-only)\n"
6256 "Attribute is set as non-transitive\n")
6259 "./set-action[action='frr-bgp-route-map:set-extcommunity-lb']";
6261 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6262 return nb_cli_apply_changes(vty
, NULL
);
6265 ALIAS_YANG (no_set_ecommunity_lb
,
6266 no_set_ecommunity_lb_short_cmd
,
6267 "no set extcommunity bandwidth",
6270 "BGP extended community attribute\n"
6271 "Link bandwidth extended community\n")
6273 DEFUN_YANG (set_origin
,
6275 "set origin <egp|igp|incomplete>",
6280 "unknown heritage\n")
6283 const char *origin_type
;
6285 "./set-action[action='frr-bgp-route-map:set-origin']";
6286 char xpath_value
[XPATH_MAXLEN
];
6288 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
6289 origin_type
= "igp";
6290 else if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
6291 origin_type
= "egp";
6292 else if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
6293 origin_type
= "incomplete";
6295 vty_out(vty
, "%% Invalid match origin type\n");
6296 return CMD_WARNING_CONFIG_FAILED
;
6299 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6300 snprintf(xpath_value
, sizeof(xpath_value
),
6301 "%s/rmap-set-action/frr-bgp-route-map:origin", xpath
);
6302 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, origin_type
);
6304 return nb_cli_apply_changes(vty
, NULL
);
6307 DEFUN_YANG (no_set_origin
,
6309 "no set origin [<egp|igp|incomplete>]",
6315 "unknown heritage\n")
6318 "./set-action[action='frr-bgp-route-map:set-origin']";
6320 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6321 return nb_cli_apply_changes(vty
, NULL
);
6324 DEFUN_YANG (set_atomic_aggregate
,
6325 set_atomic_aggregate_cmd
,
6326 "set atomic-aggregate",
6328 "BGP atomic aggregate attribute\n" )
6331 "./set-action[action='frr-bgp-route-map:atomic-aggregate']";
6332 char xpath_value
[XPATH_MAXLEN
];
6334 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6335 snprintf(xpath_value
, sizeof(xpath_value
),
6336 "%s/rmap-set-action/frr-bgp-route-map:atomic-aggregate",
6338 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, NULL
);
6340 return nb_cli_apply_changes(vty
, NULL
);
6343 DEFUN_YANG (no_set_atomic_aggregate
,
6344 no_set_atomic_aggregate_cmd
,
6345 "no set atomic-aggregate",
6348 "BGP atomic aggregate attribute\n" )
6351 "./set-action[action='frr-bgp-route-map:atomic-aggregate']";
6353 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6354 return nb_cli_apply_changes(vty
, NULL
);
6357 DEFUN_YANG (set_aggregator_as
,
6358 set_aggregator_as_cmd
,
6359 "set aggregator as (1-4294967295) A.B.C.D",
6361 "BGP aggregator attribute\n"
6362 "AS number of aggregator\n"
6364 "IP address of aggregator\n")
6368 char xpath_asn
[XPATH_MAXLEN
];
6369 char xpath_addr
[XPATH_MAXLEN
];
6371 "./set-action[action='frr-bgp-route-map:aggregator']";
6373 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6376 xpath_asn
, sizeof(xpath_asn
),
6377 "%s/rmap-set-action/frr-bgp-route-map:aggregator/aggregator-asn",
6379 nb_cli_enqueue_change(vty
, xpath_asn
, NB_OP_MODIFY
,
6380 argv
[idx_number
]->arg
);
6383 xpath_addr
, sizeof(xpath_addr
),
6384 "%s/rmap-set-action/frr-bgp-route-map:aggregator/aggregator-address",
6386 nb_cli_enqueue_change(vty
, xpath_addr
, NB_OP_MODIFY
,
6387 argv
[idx_ipv4
]->arg
);
6389 return nb_cli_apply_changes(vty
, NULL
);
6392 DEFUN_YANG (no_set_aggregator_as
,
6393 no_set_aggregator_as_cmd
,
6394 "no set aggregator as [(1-4294967295) A.B.C.D]",
6397 "BGP aggregator attribute\n"
6398 "AS number of aggregator\n"
6400 "IP address of aggregator\n")
6403 "./set-action[action='frr-bgp-route-map:aggregator']";
6405 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6406 return nb_cli_apply_changes(vty
, NULL
);
6409 DEFUN_YANG (match_ipv6_next_hop
,
6410 match_ipv6_next_hop_cmd
,
6411 "match ipv6 next-hop ACCESSLIST6_NAME",
6414 "Match IPv6 next-hop address of route\n"
6415 "IPv6 access-list name\n")
6418 "./match-condition[condition='frr-route-map:ipv6-next-hop-list']";
6419 char xpath_value
[XPATH_MAXLEN
];
6421 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6422 snprintf(xpath_value
, sizeof(xpath_value
),
6423 "%s/rmap-match-condition/list-name", xpath
);
6424 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6425 argv
[argc
- 1]->arg
);
6427 return nb_cli_apply_changes(vty
, NULL
);
6430 DEFUN_YANG (no_match_ipv6_next_hop
,
6431 no_match_ipv6_next_hop_cmd
,
6432 "no match ipv6 next-hop [ACCESSLIST6_NAME]",
6436 "Match IPv6 next-hop address of route\n"
6437 "IPv6 access-list name\n")
6440 "./match-condition[condition='frr-route-map:ipv6-next-hop-list']";
6442 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6443 return nb_cli_apply_changes(vty
, NULL
);
6446 DEFUN_YANG (match_ipv6_next_hop_address
,
6447 match_ipv6_next_hop_address_cmd
,
6448 "match ipv6 next-hop address X:X::X:X",
6451 "Match IPv6 next-hop address of route\n"
6453 "IPv6 address of next hop\n")
6456 "./match-condition[condition='frr-bgp-route-map:ipv6-nexthop']";
6457 char xpath_value
[XPATH_MAXLEN
];
6459 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6460 snprintf(xpath_value
, sizeof(xpath_value
),
6461 "%s/rmap-match-condition/frr-bgp-route-map:ipv6-address",
6463 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6464 argv
[argc
- 1]->arg
);
6466 return nb_cli_apply_changes(vty
, NULL
);
6469 DEFUN_YANG (no_match_ipv6_next_hop_address
,
6470 no_match_ipv6_next_hop_address_cmd
,
6471 "no match ipv6 next-hop address X:X::X:X",
6475 "Match IPv6 next-hop address of route\n"
6477 "IPv6 address of next hop\n")
6480 "./match-condition[condition='frr-bgp-route-map:ipv6-nexthop']";
6482 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6483 return nb_cli_apply_changes(vty
, NULL
);
6486 ALIAS_HIDDEN (match_ipv6_next_hop_address
,
6487 match_ipv6_next_hop_old_cmd
,
6488 "match ipv6 next-hop X:X::X:X",
6491 "Match IPv6 next-hop address of route\n"
6492 "IPv6 address of next hop\n")
6494 ALIAS_HIDDEN (no_match_ipv6_next_hop_address
,
6495 no_match_ipv6_next_hop_old_cmd
,
6496 "no match ipv6 next-hop X:X::X:X",
6500 "Match IPv6 next-hop address of route\n"
6501 "IPv6 address of next hop\n")
6503 DEFUN_YANG (match_ipv6_next_hop_prefix_list
,
6504 match_ipv6_next_hop_prefix_list_cmd
,
6505 "match ipv6 next-hop prefix-list PREFIXLIST_NAME",
6508 "Match IPv6 next-hop address of route\n"
6509 "Match entries by prefix-list\n"
6510 "IPv6 prefix-list name\n")
6513 "./match-condition[condition='frr-route-map:ipv6-next-hop-prefix-list']";
6514 char xpath_value
[XPATH_MAXLEN
];
6516 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6517 snprintf(xpath_value
, sizeof(xpath_value
),
6518 "%s/rmap-match-condition/list-name", xpath
);
6519 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6520 argv
[argc
- 1]->arg
);
6522 return nb_cli_apply_changes(vty
, NULL
);
6525 DEFUN_YANG (no_match_ipv6_next_hop_prefix_list
,
6526 no_match_ipv6_next_hop_prefix_list_cmd
,
6527 "no match ipv6 next-hop prefix-list [PREFIXLIST_NAME]",
6531 "Match IPv6 next-hop address of route\n"
6532 "Match entries by prefix-list\n"
6533 "IPv6 prefix-list name\n")
6536 "./match-condition[condition='frr-route-map:ipv6-next-hop-prefix-list']";
6538 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6539 return nb_cli_apply_changes(vty
, NULL
);
6542 DEFPY_YANG (match_ipv4_next_hop
,
6543 match_ipv4_next_hop_cmd
,
6544 "match ip next-hop address A.B.C.D",
6547 "Match IP next-hop address of route\n"
6549 "IP address of next-hop\n")
6552 "./match-condition[condition='frr-bgp-route-map:ipv4-nexthop']";
6553 char xpath_value
[XPATH_MAXLEN
];
6555 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6556 snprintf(xpath_value
, sizeof(xpath_value
),
6557 "%s/rmap-match-condition/frr-bgp-route-map:ipv4-address",
6559 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[4]->arg
);
6561 return nb_cli_apply_changes(vty
, NULL
);
6564 DEFPY_YANG (no_match_ipv4_next_hop
,
6565 no_match_ipv4_next_hop_cmd
,
6566 "no match ip next-hop address [A.B.C.D]",
6570 "Match IP next-hop address of route\n"
6572 "IP address of next-hop\n")
6575 "./match-condition[condition='frr-bgp-route-map:ipv4-nexthop']";
6577 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6578 return nb_cli_apply_changes(vty
, NULL
);
6581 DEFUN_YANG (set_ipv6_nexthop_peer
,
6582 set_ipv6_nexthop_peer_cmd
,
6583 "set ipv6 next-hop peer-address",
6586 "Next hop address\n"
6587 "Use peer address (for BGP only)\n")
6590 "./set-action[action='frr-bgp-route-map:ipv6-peer-address']";
6591 char xpath_value
[XPATH_MAXLEN
];
6593 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6594 snprintf(xpath_value
, sizeof(xpath_value
),
6595 "%s/rmap-set-action/frr-bgp-route-map:preference", xpath
);
6596 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
6598 return nb_cli_apply_changes(vty
, NULL
);
6601 DEFUN_YANG (no_set_ipv6_nexthop_peer
,
6602 no_set_ipv6_nexthop_peer_cmd
,
6603 "no set ipv6 next-hop peer-address",
6607 "IPv6 next-hop address\n"
6608 "Use peer address (for BGP only)\n")
6611 "./set-action[action='frr-bgp-route-map:ipv6-peer-address']";
6613 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6614 return nb_cli_apply_changes(vty
, NULL
);
6617 DEFUN_YANG (set_ipv6_nexthop_prefer_global
,
6618 set_ipv6_nexthop_prefer_global_cmd
,
6619 "set ipv6 next-hop prefer-global",
6622 "IPv6 next-hop address\n"
6623 "Prefer global over link-local if both exist\n")
6626 "./set-action[action='frr-bgp-route-map:ipv6-prefer-global']";
6627 char xpath_value
[XPATH_MAXLEN
];
6629 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6630 snprintf(xpath_value
, sizeof(xpath_value
),
6631 "%s/rmap-set-action/frr-bgp-route-map:preference", xpath
);
6632 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
6634 return nb_cli_apply_changes(vty
, NULL
);
6637 DEFUN_YANG (no_set_ipv6_nexthop_prefer_global
,
6638 no_set_ipv6_nexthop_prefer_global_cmd
,
6639 "no set ipv6 next-hop prefer-global",
6643 "IPv6 next-hop address\n"
6644 "Prefer global over link-local if both exist\n")
6647 "./set-action[action='frr-bgp-route-map:ipv6-prefer-global']";
6649 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6650 return nb_cli_apply_changes(vty
, NULL
);
6653 DEFUN_YANG (set_ipv6_nexthop_global
,
6654 set_ipv6_nexthop_global_cmd
,
6655 "set ipv6 next-hop global X:X::X:X",
6658 "IPv6 next-hop address\n"
6659 "IPv6 global address\n"
6660 "IPv6 address of next hop\n")
6664 "./set-action[action='frr-bgp-route-map:ipv6-nexthop-global']";
6665 char xpath_value
[XPATH_MAXLEN
];
6667 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6668 snprintf(xpath_value
, sizeof(xpath_value
),
6669 "%s/rmap-set-action/frr-bgp-route-map:ipv6-address", xpath
);
6670 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6671 argv
[idx_ipv6
]->arg
);
6673 return nb_cli_apply_changes(vty
, NULL
);
6676 DEFUN_YANG (no_set_ipv6_nexthop_global
,
6677 no_set_ipv6_nexthop_global_cmd
,
6678 "no set ipv6 next-hop global X:X::X:X",
6682 "IPv6 next-hop address\n"
6683 "IPv6 global address\n"
6684 "IPv6 address of next hop\n")
6687 "./set-action[action='frr-bgp-route-map:ipv6-nexthop-global']";
6689 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6690 return nb_cli_apply_changes(vty
, NULL
);
6693 #ifdef KEEP_OLD_VPN_COMMANDS
6694 DEFUN_YANG (set_vpn_nexthop
,
6695 set_vpn_nexthop_cmd
,
6696 "set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
6698 "VPNv4 information\n"
6699 "VPN next-hop address\n"
6700 "IP address of next hop\n"
6701 "VPNv6 information\n"
6702 "VPN next-hop address\n"
6703 "IPv6 address of next hop\n")
6708 char xpath_value
[XPATH_MAXLEN
];
6710 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
6711 if (afi
== AFI_IP
) {
6713 "./set-action[action='frr-bgp-route-map:ipv4-vpn-address']";
6715 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6717 xpath_value
, sizeof(xpath_value
),
6718 "%s/rmap-set-action/frr-bgp-route-map:ipv4-address",
6722 "./set-action[action='frr-bgp-route-map:ipv6-vpn-address']";
6724 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6726 xpath_value
, sizeof(xpath_value
),
6727 "%s/rmap-set-action/frr-bgp-route-map:ipv6-address",
6731 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6734 return nb_cli_apply_changes(vty
, NULL
);
6740 DEFUN_YANG (no_set_vpn_nexthop
,
6741 no_set_vpn_nexthop_cmd
,
6742 "no set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
6745 "VPNv4 information\n"
6746 "VPN next-hop address\n"
6747 "IP address of next hop\n"
6748 "VPNv6 information\n"
6749 "VPN next-hop address\n"
6750 "IPv6 address of next hop\n")
6755 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
6756 if (afi
== AFI_IP
) {
6758 "./set-action[action='frr-bgp-route-map:ipv4-vpn-address']";
6759 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6762 "./set-action[action='frr-bgp-route-map:ipv6-vpn-address']";
6763 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6765 return nb_cli_apply_changes(vty
, NULL
);
6769 #endif /* KEEP_OLD_VPN_COMMANDS */
6771 DEFUN_YANG (set_ipx_vpn_nexthop
,
6772 set_ipx_vpn_nexthop_cmd
,
6773 "set <ipv4|ipv6> vpn next-hop <A.B.C.D|X:X::X:X>",
6775 "IPv4 information\n"
6776 "IPv6 information\n"
6778 "VPN next-hop address\n"
6779 "IP address of next hop\n"
6780 "IPv6 address of next hop\n")
6785 char xpath_value
[XPATH_MAXLEN
];
6787 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
6788 if (afi
== AFI_IP
) {
6790 "./set-action[action='frr-bgp-route-map:ipv4-vpn-address']";
6792 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6794 xpath_value
, sizeof(xpath_value
),
6795 "%s/rmap-set-action/frr-bgp-route-map:ipv4-address",
6799 "./set-action[action='frr-bgp-route-map:ipv6-vpn-address']";
6801 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6803 xpath_value
, sizeof(xpath_value
),
6804 "%s/rmap-set-action/frr-bgp-route-map:ipv6-address",
6807 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6809 return nb_cli_apply_changes(vty
, NULL
);
6814 DEFUN_YANG (no_set_ipx_vpn_nexthop
,
6815 no_set_ipx_vpn_nexthop_cmd
,
6816 "no set <ipv4|ipv6> vpn next-hop [<A.B.C.D|X:X::X:X>]",
6819 "IPv4 information\n"
6820 "IPv6 information\n"
6822 "VPN next-hop address\n"
6823 "IP address of next hop\n"
6824 "IPv6 address of next hop\n")
6829 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
6830 if (afi
== AFI_IP
) {
6832 "./set-action[action='frr-bgp-route-map:ipv4-vpn-address']";
6833 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6836 "./set-action[action='frr-bgp-route-map:ipv6-vpn-address']";
6837 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6839 return nb_cli_apply_changes(vty
, NULL
);
6844 DEFUN_YANG (set_originator_id
,
6845 set_originator_id_cmd
,
6846 "set originator-id A.B.C.D",
6848 "BGP originator ID attribute\n"
6849 "IP address of originator\n")
6853 "./set-action[action='frr-bgp-route-map:originator-id']";
6854 char xpath_value
[XPATH_MAXLEN
];
6856 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6857 snprintf(xpath_value
, sizeof(xpath_value
),
6858 "%s/rmap-set-action/frr-bgp-route-map:originator-id", xpath
);
6859 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6860 argv
[idx_ipv4
]->arg
);
6862 return nb_cli_apply_changes(vty
, NULL
);
6865 DEFUN_YANG (no_set_originator_id
,
6866 no_set_originator_id_cmd
,
6867 "no set originator-id [A.B.C.D]",
6870 "BGP originator ID attribute\n"
6871 "IP address of originator\n")
6874 "./set-action[action='frr-bgp-route-map:originator-id']";
6876 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6877 return nb_cli_apply_changes(vty
, NULL
);
6880 DEFPY_YANG (match_rpki_extcommunity
,
6881 match_rpki_extcommunity_cmd
,
6882 "[no$no] match rpki-extcommunity <valid|invalid|notfound>",
6885 "BGP RPKI (Origin Validation State) extended community attribute\n"
6888 "Prefix not found\n")
6891 "./match-condition[condition='frr-bgp-route-map:rpki-extcommunity']";
6892 char xpath_value
[XPATH_MAXLEN
];
6894 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6898 xpath_value
, sizeof(xpath_value
),
6899 "%s/rmap-match-condition/frr-bgp-route-map:rpki-extcommunity",
6901 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6905 return nb_cli_apply_changes(vty
, NULL
);
6908 /* Initialization of route map. */
6909 void bgp_route_map_init(void)
6913 route_map_add_hook(bgp_route_map_add
);
6914 route_map_delete_hook(bgp_route_map_delete
);
6915 route_map_event_hook(bgp_route_map_event
);
6917 route_map_match_interface_hook(generic_match_add
);
6918 route_map_no_match_interface_hook(generic_match_delete
);
6920 route_map_match_ip_address_hook(generic_match_add
);
6921 route_map_no_match_ip_address_hook(generic_match_delete
);
6923 route_map_match_ip_address_prefix_list_hook(generic_match_add
);
6924 route_map_no_match_ip_address_prefix_list_hook(generic_match_delete
);
6926 route_map_match_ip_next_hop_hook(generic_match_add
);
6927 route_map_no_match_ip_next_hop_hook(generic_match_delete
);
6929 route_map_match_ipv6_next_hop_hook(generic_match_add
);
6930 route_map_no_match_ipv6_next_hop_hook(generic_match_delete
);
6932 route_map_match_ip_next_hop_prefix_list_hook(generic_match_add
);
6933 route_map_no_match_ip_next_hop_prefix_list_hook(generic_match_delete
);
6935 route_map_match_ip_next_hop_type_hook(generic_match_add
);
6936 route_map_no_match_ip_next_hop_type_hook(generic_match_delete
);
6938 route_map_match_ipv6_address_hook(generic_match_add
);
6939 route_map_no_match_ipv6_address_hook(generic_match_delete
);
6941 route_map_match_ipv6_address_prefix_list_hook(generic_match_add
);
6942 route_map_no_match_ipv6_address_prefix_list_hook(generic_match_delete
);
6944 route_map_match_ipv6_next_hop_type_hook(generic_match_add
);
6945 route_map_no_match_ipv6_next_hop_type_hook(generic_match_delete
);
6947 route_map_match_ipv6_next_hop_prefix_list_hook(generic_match_add
);
6948 route_map_no_match_ipv6_next_hop_prefix_list_hook(generic_match_delete
);
6950 route_map_match_metric_hook(generic_match_add
);
6951 route_map_no_match_metric_hook(generic_match_delete
);
6953 route_map_match_tag_hook(generic_match_add
);
6954 route_map_no_match_tag_hook(generic_match_delete
);
6956 route_map_set_srte_color_hook(generic_set_add
);
6957 route_map_no_set_srte_color_hook(generic_set_delete
);
6959 route_map_set_ip_nexthop_hook(generic_set_add
);
6960 route_map_no_set_ip_nexthop_hook(generic_set_delete
);
6962 route_map_set_ipv6_nexthop_local_hook(generic_set_add
);
6963 route_map_no_set_ipv6_nexthop_local_hook(generic_set_delete
);
6965 route_map_set_metric_hook(generic_set_add
);
6966 route_map_no_set_metric_hook(generic_set_delete
);
6968 route_map_set_tag_hook(generic_set_add
);
6969 route_map_no_set_tag_hook(generic_set_delete
);
6971 route_map_install_match(&route_match_peer_cmd
);
6972 route_map_install_match(&route_match_alias_cmd
);
6973 route_map_install_match(&route_match_local_pref_cmd
);
6974 #ifdef HAVE_SCRIPTING
6975 route_map_install_match(&route_match_script_cmd
);
6977 route_map_install_match(&route_match_ip_address_cmd
);
6978 route_map_install_match(&route_match_ip_next_hop_cmd
);
6979 route_map_install_match(&route_match_ip_route_source_cmd
);
6980 route_map_install_match(&route_match_ip_address_prefix_list_cmd
);
6981 route_map_install_match(&route_match_ip_next_hop_prefix_list_cmd
);
6982 route_map_install_match(&route_match_ip_next_hop_type_cmd
);
6983 route_map_install_match(&route_match_ip_route_source_prefix_list_cmd
);
6984 route_map_install_match(&route_match_aspath_cmd
);
6985 route_map_install_match(&route_match_community_cmd
);
6986 route_map_install_match(&route_match_lcommunity_cmd
);
6987 route_map_install_match(&route_match_ecommunity_cmd
);
6988 route_map_install_match(&route_match_local_pref_cmd
);
6989 route_map_install_match(&route_match_metric_cmd
);
6990 route_map_install_match(&route_match_origin_cmd
);
6991 route_map_install_match(&route_match_probability_cmd
);
6992 route_map_install_match(&route_match_interface_cmd
);
6993 route_map_install_match(&route_match_tag_cmd
);
6994 route_map_install_match(&route_match_mac_address_cmd
);
6995 route_map_install_match(&route_match_evpn_vni_cmd
);
6996 route_map_install_match(&route_match_evpn_route_type_cmd
);
6997 route_map_install_match(&route_match_evpn_rd_cmd
);
6998 route_map_install_match(&route_match_evpn_default_route_cmd
);
6999 route_map_install_match(&route_match_vrl_source_vrf_cmd
);
7001 route_map_install_set(&route_set_evpn_gateway_ip_ipv4_cmd
);
7002 route_map_install_set(&route_set_evpn_gateway_ip_ipv6_cmd
);
7003 route_map_install_set(&route_set_table_id_cmd
);
7004 route_map_install_set(&route_set_srte_color_cmd
);
7005 route_map_install_set(&route_set_ip_nexthop_cmd
);
7006 route_map_install_set(&route_set_local_pref_cmd
);
7007 route_map_install_set(&route_set_weight_cmd
);
7008 route_map_install_set(&route_set_label_index_cmd
);
7009 route_map_install_set(&route_set_metric_cmd
);
7010 route_map_install_set(&route_set_distance_cmd
);
7011 route_map_install_set(&route_set_aspath_prepend_cmd
);
7012 route_map_install_set(&route_set_aspath_exclude_cmd
);
7013 route_map_install_set(&route_set_aspath_replace_cmd
);
7014 route_map_install_set(&route_set_origin_cmd
);
7015 route_map_install_set(&route_set_atomic_aggregate_cmd
);
7016 route_map_install_set(&route_set_aggregator_as_cmd
);
7017 route_map_install_set(&route_set_community_cmd
);
7018 route_map_install_set(&route_set_community_delete_cmd
);
7019 route_map_install_set(&route_set_lcommunity_cmd
);
7020 route_map_install_set(&route_set_lcommunity_delete_cmd
);
7021 route_map_install_set(&route_set_vpnv4_nexthop_cmd
);
7022 route_map_install_set(&route_set_vpnv6_nexthop_cmd
);
7023 route_map_install_set(&route_set_originator_id_cmd
);
7024 route_map_install_set(&route_set_ecommunity_rt_cmd
);
7025 route_map_install_set(&route_set_ecommunity_soo_cmd
);
7026 route_map_install_set(&route_set_ecommunity_lb_cmd
);
7027 route_map_install_set(&route_set_ecommunity_none_cmd
);
7028 route_map_install_set(&route_set_tag_cmd
);
7029 route_map_install_set(&route_set_label_index_cmd
);
7030 route_map_install_set(&route_set_l3vpn_nexthop_encapsulation_cmd
);
7032 install_element(RMAP_NODE
, &match_peer_cmd
);
7033 install_element(RMAP_NODE
, &match_peer_local_cmd
);
7034 install_element(RMAP_NODE
, &no_match_peer_cmd
);
7035 install_element(RMAP_NODE
, &match_ip_route_source_cmd
);
7036 install_element(RMAP_NODE
, &no_match_ip_route_source_cmd
);
7037 install_element(RMAP_NODE
, &match_ip_route_source_prefix_list_cmd
);
7038 install_element(RMAP_NODE
, &no_match_ip_route_source_prefix_list_cmd
);
7039 install_element(RMAP_NODE
, &match_mac_address_cmd
);
7040 install_element(RMAP_NODE
, &no_match_mac_address_cmd
);
7041 install_element(RMAP_NODE
, &match_evpn_vni_cmd
);
7042 install_element(RMAP_NODE
, &no_match_evpn_vni_cmd
);
7043 install_element(RMAP_NODE
, &match_evpn_route_type_cmd
);
7044 install_element(RMAP_NODE
, &no_match_evpn_route_type_cmd
);
7045 install_element(RMAP_NODE
, &match_evpn_rd_cmd
);
7046 install_element(RMAP_NODE
, &no_match_evpn_rd_cmd
);
7047 install_element(RMAP_NODE
, &match_evpn_default_route_cmd
);
7048 install_element(RMAP_NODE
, &no_match_evpn_default_route_cmd
);
7049 install_element(RMAP_NODE
, &set_evpn_gw_ip_ipv4_cmd
);
7050 install_element(RMAP_NODE
, &no_set_evpn_gw_ip_ipv4_cmd
);
7051 install_element(RMAP_NODE
, &set_evpn_gw_ip_ipv6_cmd
);
7052 install_element(RMAP_NODE
, &no_set_evpn_gw_ip_ipv6_cmd
);
7053 install_element(RMAP_NODE
, &match_vrl_source_vrf_cmd
);
7054 install_element(RMAP_NODE
, &no_match_vrl_source_vrf_cmd
);
7056 install_element(RMAP_NODE
, &match_aspath_cmd
);
7057 install_element(RMAP_NODE
, &no_match_aspath_cmd
);
7058 install_element(RMAP_NODE
, &match_local_pref_cmd
);
7059 install_element(RMAP_NODE
, &no_match_local_pref_cmd
);
7060 install_element(RMAP_NODE
, &match_alias_cmd
);
7061 install_element(RMAP_NODE
, &no_match_alias_cmd
);
7062 install_element(RMAP_NODE
, &match_community_cmd
);
7063 install_element(RMAP_NODE
, &no_match_community_cmd
);
7064 install_element(RMAP_NODE
, &match_lcommunity_cmd
);
7065 install_element(RMAP_NODE
, &no_match_lcommunity_cmd
);
7066 install_element(RMAP_NODE
, &match_ecommunity_cmd
);
7067 install_element(RMAP_NODE
, &no_match_ecommunity_cmd
);
7068 install_element(RMAP_NODE
, &match_origin_cmd
);
7069 install_element(RMAP_NODE
, &no_match_origin_cmd
);
7070 install_element(RMAP_NODE
, &match_probability_cmd
);
7071 install_element(RMAP_NODE
, &no_match_probability_cmd
);
7073 install_element(RMAP_NODE
, &no_set_table_id_cmd
);
7074 install_element(RMAP_NODE
, &set_table_id_cmd
);
7075 install_element(RMAP_NODE
, &set_ip_nexthop_peer_cmd
);
7076 install_element(RMAP_NODE
, &set_ip_nexthop_unchanged_cmd
);
7077 install_element(RMAP_NODE
, &set_local_pref_cmd
);
7078 install_element(RMAP_NODE
, &set_distance_cmd
);
7079 install_element(RMAP_NODE
, &no_set_distance_cmd
);
7080 install_element(RMAP_NODE
, &no_set_local_pref_cmd
);
7081 install_element(RMAP_NODE
, &set_weight_cmd
);
7082 install_element(RMAP_NODE
, &set_label_index_cmd
);
7083 install_element(RMAP_NODE
, &no_set_weight_cmd
);
7084 install_element(RMAP_NODE
, &no_set_label_index_cmd
);
7085 install_element(RMAP_NODE
, &set_aspath_prepend_asn_cmd
);
7086 install_element(RMAP_NODE
, &set_aspath_prepend_lastas_cmd
);
7087 install_element(RMAP_NODE
, &set_aspath_exclude_cmd
);
7088 install_element(RMAP_NODE
, &set_aspath_replace_asn_cmd
);
7089 install_element(RMAP_NODE
, &no_set_aspath_prepend_cmd
);
7090 install_element(RMAP_NODE
, &no_set_aspath_prepend_lastas_cmd
);
7091 install_element(RMAP_NODE
, &no_set_aspath_exclude_cmd
);
7092 install_element(RMAP_NODE
, &no_set_aspath_exclude_all_cmd
);
7093 install_element(RMAP_NODE
, &no_set_aspath_replace_asn_cmd
);
7094 install_element(RMAP_NODE
, &set_origin_cmd
);
7095 install_element(RMAP_NODE
, &no_set_origin_cmd
);
7096 install_element(RMAP_NODE
, &set_atomic_aggregate_cmd
);
7097 install_element(RMAP_NODE
, &no_set_atomic_aggregate_cmd
);
7098 install_element(RMAP_NODE
, &set_aggregator_as_cmd
);
7099 install_element(RMAP_NODE
, &no_set_aggregator_as_cmd
);
7100 install_element(RMAP_NODE
, &set_community_cmd
);
7101 install_element(RMAP_NODE
, &set_community_none_cmd
);
7102 install_element(RMAP_NODE
, &no_set_community_cmd
);
7103 install_element(RMAP_NODE
, &no_set_community_short_cmd
);
7104 install_element(RMAP_NODE
, &set_community_delete_cmd
);
7105 install_element(RMAP_NODE
, &no_set_community_delete_cmd
);
7106 install_element(RMAP_NODE
, &set_lcommunity_cmd
);
7107 install_element(RMAP_NODE
, &set_lcommunity_none_cmd
);
7108 install_element(RMAP_NODE
, &no_set_lcommunity_cmd
);
7109 install_element(RMAP_NODE
, &no_set_lcommunity1_cmd
);
7110 install_element(RMAP_NODE
, &no_set_lcommunity1_short_cmd
);
7111 install_element(RMAP_NODE
, &set_lcommunity_delete_cmd
);
7112 install_element(RMAP_NODE
, &no_set_lcommunity_delete_cmd
);
7113 install_element(RMAP_NODE
, &no_set_lcommunity_delete_short_cmd
);
7114 install_element(RMAP_NODE
, &set_ecommunity_rt_cmd
);
7115 install_element(RMAP_NODE
, &no_set_ecommunity_rt_cmd
);
7116 install_element(RMAP_NODE
, &no_set_ecommunity_rt_short_cmd
);
7117 install_element(RMAP_NODE
, &set_ecommunity_soo_cmd
);
7118 install_element(RMAP_NODE
, &no_set_ecommunity_soo_cmd
);
7119 install_element(RMAP_NODE
, &no_set_ecommunity_soo_short_cmd
);
7120 install_element(RMAP_NODE
, &set_ecommunity_lb_cmd
);
7121 install_element(RMAP_NODE
, &no_set_ecommunity_lb_cmd
);
7122 install_element(RMAP_NODE
, &no_set_ecommunity_lb_short_cmd
);
7123 install_element(RMAP_NODE
, &set_ecommunity_none_cmd
);
7124 install_element(RMAP_NODE
, &no_set_ecommunity_none_cmd
);
7125 #ifdef KEEP_OLD_VPN_COMMANDS
7126 install_element(RMAP_NODE
, &set_vpn_nexthop_cmd
);
7127 install_element(RMAP_NODE
, &no_set_vpn_nexthop_cmd
);
7128 #endif /* KEEP_OLD_VPN_COMMANDS */
7129 install_element(RMAP_NODE
, &set_ipx_vpn_nexthop_cmd
);
7130 install_element(RMAP_NODE
, &no_set_ipx_vpn_nexthop_cmd
);
7131 install_element(RMAP_NODE
, &set_originator_id_cmd
);
7132 install_element(RMAP_NODE
, &no_set_originator_id_cmd
);
7133 install_element(RMAP_NODE
, &set_l3vpn_nexthop_encapsulation_cmd
);
7135 route_map_install_match(&route_match_ipv6_address_cmd
);
7136 route_map_install_match(&route_match_ipv6_next_hop_cmd
);
7137 route_map_install_match(&route_match_ipv6_next_hop_address_cmd
);
7138 route_map_install_match(&route_match_ipv6_next_hop_prefix_list_cmd
);
7139 route_map_install_match(&route_match_ipv4_next_hop_cmd
);
7140 route_map_install_match(&route_match_ipv6_address_prefix_list_cmd
);
7141 route_map_install_match(&route_match_ipv6_next_hop_type_cmd
);
7142 route_map_install_set(&route_set_ipv6_nexthop_global_cmd
);
7143 route_map_install_set(&route_set_ipv6_nexthop_prefer_global_cmd
);
7144 route_map_install_set(&route_set_ipv6_nexthop_local_cmd
);
7145 route_map_install_set(&route_set_ipv6_nexthop_peer_cmd
);
7146 route_map_install_match(&route_match_rpki_extcommunity_cmd
);
7148 install_element(RMAP_NODE
, &match_ipv6_next_hop_cmd
);
7149 install_element(RMAP_NODE
, &match_ipv6_next_hop_address_cmd
);
7150 install_element(RMAP_NODE
, &match_ipv6_next_hop_prefix_list_cmd
);
7151 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_cmd
);
7152 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_address_cmd
);
7153 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_prefix_list_cmd
);
7154 install_element(RMAP_NODE
, &match_ipv6_next_hop_old_cmd
);
7155 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_old_cmd
);
7156 install_element(RMAP_NODE
, &match_ipv4_next_hop_cmd
);
7157 install_element(RMAP_NODE
, &no_match_ipv4_next_hop_cmd
);
7158 install_element(RMAP_NODE
, &set_ipv6_nexthop_global_cmd
);
7159 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_global_cmd
);
7160 install_element(RMAP_NODE
, &set_ipv6_nexthop_prefer_global_cmd
);
7161 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_prefer_global_cmd
);
7162 install_element(RMAP_NODE
, &set_ipv6_nexthop_peer_cmd
);
7163 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_peer_cmd
);
7164 install_element(RMAP_NODE
, &match_rpki_extcommunity_cmd
);
7165 #ifdef HAVE_SCRIPTING
7166 install_element(RMAP_NODE
, &match_script_cmd
);
7170 void bgp_route_map_terminate(void)
7172 /* ToDo: Cleanup all the used memory */