1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Route map function of bgpd.
3 * Copyright (C) 1998, 1999 Kunihiro Ishiguro
17 #include "frrscript.h"
18 #ifdef HAVE_LIBPCRE2_POSIX
19 #ifndef _FRR_PCRE2_POSIX
20 #define _FRR_PCRE2_POSIX
21 #include <pcre2posix.h>
22 #endif /* _FRR_PCRE2_POSIX */
23 #elif defined(HAVE_LIBPCREPOSIX)
24 #include <pcreposix.h>
27 #endif /* HAVE_LIBPCRE2_POSIX */
29 #include "sockunion.h"
34 #include "lib/northbound_cli.h"
36 #include "bgpd/bgpd.h"
37 #include "bgpd/bgp_table.h"
38 #include "bgpd/bgp_attr.h"
39 #include "bgpd/bgp_aspath.h"
40 #include "bgpd/bgp_packet.h"
41 #include "bgpd/bgp_route.h"
42 #include "bgpd/bgp_zebra.h"
43 #include "bgpd/bgp_regex.h"
44 #include "bgpd/bgp_community.h"
45 #include "bgpd/bgp_community_alias.h"
46 #include "bgpd/bgp_clist.h"
47 #include "bgpd/bgp_filter.h"
48 #include "bgpd/bgp_mplsvpn.h"
49 #include "bgpd/bgp_ecommunity.h"
50 #include "bgpd/bgp_lcommunity.h"
51 #include "bgpd/bgp_vty.h"
52 #include "bgpd/bgp_debug.h"
53 #include "bgpd/bgp_evpn.h"
54 #include "bgpd/bgp_evpn_private.h"
55 #include "bgpd/bgp_evpn_vty.h"
56 #include "bgpd/bgp_mplsvpn.h"
57 #include "bgpd/bgp_pbr.h"
58 #include "bgpd/bgp_flowspec_util.h"
59 #include "bgpd/bgp_encap_types.h"
60 #include "bgpd/bgp_mpath.h"
61 #include "bgpd/bgp_script.h"
64 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
67 #include "bgpd/bgp_routemap_clippy.c"
69 /* Memo of route-map commands.
78 ip route-source : Done
82 ipv6 route-source: (This will not be implemented by bgpd)
83 ipv6 prefix-list : Done
84 length : (This will not be implemented by bgpd)
86 route-type : (This will not be implemented by bgpd)
88 local-preference : Done
90 set as-path prepend : Done
92 automatic-tag : (This will not be implemented by bgpd)
94 large-community : Done
95 large-comm-list : Done
98 default : (This will not be implemented by bgpd)
99 interface : (This will not be implemented by bgpd)
100 ip default : (This will not be implemented by bgpd)
102 ip precedence : (This will not be implemented by bgpd)
103 ip tos : (This will not be implemented by bgpd)
104 level : (This will not be implemented by bgpd)
105 local-preference : Done
107 metric-type : Not yet
115 set ipv6 next-hop global: Done
116 set ipv6 next-hop prefer-global: Done
117 set ipv6 next-hop local : Done
118 set as-path exclude : Done
122 /* generic value manipulation to be shared in multiple rules */
124 #define RMAP_VALUE_SET 0
125 #define RMAP_VALUE_ADD 1
126 #define RMAP_VALUE_SUB 2
134 static int route_value_match(struct rmap_value
*rv
, uint32_t value
)
136 if (rv
->variable
== 0 && value
== rv
->value
)
142 static uint32_t route_value_adjust(struct rmap_value
*rv
, uint32_t current
,
147 switch (rv
->variable
) {
156 switch (rv
->action
) {
158 if (current
> UINT32_MAX
- value
)
160 return current
+ value
;
162 if (current
<= value
)
164 return current
- value
;
170 static void *route_value_compile(const char *arg
)
172 uint8_t action
= RMAP_VALUE_SET
, var
= 0;
173 unsigned long larg
= 0;
175 struct rmap_value
*rv
;
178 action
= RMAP_VALUE_ADD
;
180 } else if (arg
[0] == '-') {
181 action
= RMAP_VALUE_SUB
;
185 if (all_digit(arg
)) {
187 larg
= strtoul(arg
, &endptr
, 10);
188 if (*arg
== 0 || *endptr
!= 0 || errno
|| larg
> UINT32_MAX
)
191 if (strcmp(arg
, "rtt") == 0)
197 rv
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_value
));
205 static void route_value_free(void *rule
)
207 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
210 /* generic as path object to be shared in multiple rules */
212 static void *route_aspath_compile(const char *arg
)
214 struct aspath
*aspath
;
216 aspath
= aspath_str2aspath(arg
, bgp_get_asnotation(NULL
));
222 static void route_aspath_free(void *rule
)
224 struct aspath
*aspath
= rule
;
228 struct bgp_match_peer_compiled
{
233 /* 'match peer (A.B.C.D|X:X::X:X|WORD)' */
235 /* Compares the peer specified in the 'match peer' clause with the peer
236 received in bgp_path_info->peer. If it is the same, or if the peer structure
237 received is a peer_group containing it, returns RMAP_MATCH. */
238 static enum route_map_cmd_result_t
239 route_match_peer(void *rule
, const struct prefix
*prefix
, void *object
)
241 struct bgp_match_peer_compiled
*pc
;
243 union sockunion su_def
= {
244 .sin
= {.sin_family
= AF_INET
, .sin_addr
.s_addr
= INADDR_ANY
}};
245 struct peer_group
*group
;
247 struct listnode
*node
, *nnode
;
251 peer
= ((struct bgp_path_info
*)object
)->peer
;
254 if (!peer
->conf_if
|| !peer
->group
)
257 if (peer
->conf_if
&& strcmp(peer
->conf_if
, pc
->interface
) == 0)
261 strcmp(peer
->group
->name
, pc
->interface
) == 0)
267 /* If su='0.0.0.0' (command 'match peer local'), and it's a
269 REDISTRIBUTE, AGGREGATE-ADDRESS or DEFAULT_GENERATED route
272 if (sockunion_same(su
, &su_def
)) {
274 if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_NETWORK
)
275 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_REDISTRIBUTE
)
276 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_AGGREGATE
)
277 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_DEFAULT
))
284 if (!CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
)) {
285 if (sockunion_same(su
, &peer
->su
))
291 for (ALL_LIST_ELEMENTS(group
->peer
, node
, nnode
, peer
)) {
292 if (sockunion_same(su
, &peer
->su
))
301 static void *route_match_peer_compile(const char *arg
)
303 struct bgp_match_peer_compiled
*pc
;
306 pc
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
307 sizeof(struct bgp_match_peer_compiled
));
309 ret
= str2sockunion(strcmp(arg
, "local") ? arg
: "0.0.0.0", &pc
->su
);
311 pc
->interface
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
318 /* Free route map's compiled `ip address' value. */
319 static void route_match_peer_free(void *rule
)
321 struct bgp_match_peer_compiled
*pc
= rule
;
323 XFREE(MTYPE_ROUTE_MAP_COMPILED
, pc
->interface
);
325 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
328 /* Route map commands for ip address matching. */
329 static const struct route_map_rule_cmd route_match_peer_cmd
= {
332 route_match_peer_compile
,
333 route_match_peer_free
336 #ifdef HAVE_SCRIPTING
338 enum frrlua_rm_status
{
340 * Script function run failure. This will translate into a deny
344 * No Match was found for the route map function
348 * Match was found but no changes were made to the incoming data.
352 * Match was found and data was modified, so figure out what changed
354 LUA_RM_MATCH_AND_CHANGE
,
357 static enum route_map_cmd_result_t
358 route_match_script(void *rule
, const struct prefix
*prefix
, void *object
)
360 const char *scriptname
= rule
;
361 const char *routematch_function
= "route_match";
362 struct bgp_path_info
*path
= (struct bgp_path_info
*)object
;
364 struct frrscript
*fs
= frrscript_new(scriptname
);
366 if (frrscript_load(fs
, routematch_function
, NULL
)) {
368 "Issue loading script or function; defaulting to no match");
372 struct attr newattr
= *path
->attr
;
374 int result
= frrscript_call(
375 fs
, routematch_function
, ("prefix", prefix
),
376 ("attributes", &newattr
), ("peer", path
->peer
),
377 ("RM_FAILURE", LUA_RM_FAILURE
), ("RM_NOMATCH", LUA_RM_NOMATCH
),
378 ("RM_MATCH", LUA_RM_MATCH
),
379 ("RM_MATCH_AND_CHANGE", LUA_RM_MATCH_AND_CHANGE
));
382 zlog_err("Issue running script rule; defaulting to no match");
386 long long *action
= frrscript_get_result(fs
, routematch_function
,
387 "action", lua_tointegerp
);
389 int status
= RMAP_NOMATCH
;
394 "Executing route-map match script '%s' failed; defaulting to no match",
396 status
= RMAP_NOMATCH
;
399 status
= RMAP_NOMATCH
;
401 case LUA_RM_MATCH_AND_CHANGE
:
403 zlog_debug("Updating attribute based on script's values");
405 uint32_t locpref
= 0;
407 path
->attr
->med
= newattr
.med
;
409 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
))
410 locpref
= path
->attr
->local_pref
;
411 if (locpref
!= newattr
.local_pref
) {
412 SET_FLAG(path
->attr
->flag
,
413 ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
));
414 path
->attr
->local_pref
= newattr
.local_pref
;
422 XFREE(MTYPE_SCRIPT_RES
, action
);
424 frrscript_delete(fs
);
429 static void *route_match_script_compile(const char *arg
)
433 scriptname
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
438 static void route_match_script_free(void *rule
)
440 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
443 static const struct route_map_rule_cmd route_match_script_cmd
= {
446 route_match_script_compile
,
447 route_match_script_free
450 #endif /* HAVE_SCRIPTING */
452 /* `match ip address IP_ACCESS_LIST' */
454 /* Match function should return 1 if match is success else return
456 static enum route_map_cmd_result_t
457 route_match_ip_address(void *rule
, const struct prefix
*prefix
, void *object
)
459 struct access_list
*alist
;
461 if (prefix
->family
== AF_INET
) {
462 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
464 if (CHECK_FLAG(rmap_debug
, DEBUG_ROUTEMAP_DETAIL
))
466 "%s: Access-List Specified: %s does not exist defaulting to NO_MATCH",
467 __func__
, (char *)rule
);
471 return (access_list_apply(alist
, prefix
) == FILTER_DENY
478 /* Route map `ip address' match statement. `arg' should be
480 static void *route_match_ip_address_compile(const char *arg
)
482 struct access_list
*alist
;
484 alist
= access_list_lookup(AFI_IP
, arg
);
487 "Access List specified %s does not exist yet, default will be NO_MATCH until it is created",
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_ACCESS_LIST_NAME>' */
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
);
524 if (CHECK_FLAG(rmap_debug
, DEBUG_ROUTEMAP_DETAIL
))
526 "%s: Access-List Specified: %s does not exist defaulting to NO_MATCH",
527 __func__
, (char *)rule
);
532 return (access_list_apply(alist
, &p
) == FILTER_DENY
539 /* Route map `ip next-hop' match statement. `arg' is
541 static void *route_match_ip_next_hop_compile(const char *arg
)
543 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
546 /* Free route map's compiled `ip address' value. */
547 static void route_match_ip_next_hop_free(void *rule
)
549 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
552 /* Route map commands for ip next-hop matching. */
553 static const struct route_map_rule_cmd route_match_ip_next_hop_cmd
= {
555 route_match_ip_next_hop
,
556 route_match_ip_next_hop_compile
,
557 route_match_ip_next_hop_free
560 /* `match ip route-source ACCESS-LIST' */
562 /* Match function return 1 if match is success else return zero. */
563 static enum route_map_cmd_result_t
564 route_match_ip_route_source(void *rule
, const struct prefix
*pfx
, void *object
)
566 struct access_list
*alist
;
567 struct bgp_path_info
*path
;
569 struct prefix_ipv4 p
;
571 if (pfx
->family
== AF_INET
) {
575 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
579 p
.prefix
= peer
->su
.sin
.sin_addr
;
580 p
.prefixlen
= IPV4_MAX_BITLEN
;
582 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
584 if (CHECK_FLAG(rmap_debug
, DEBUG_ROUTEMAP_DETAIL
))
586 "%s: Access-List Specified: %s does not exist defaulting to NO_MATCH",
587 __func__
, (char *)rule
);
592 return (access_list_apply(alist
, &p
) == FILTER_DENY
599 /* Route map `ip route-source' match statement. `arg' is
601 static void *route_match_ip_route_source_compile(const char *arg
)
603 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
606 /* Free route map's compiled `ip address' value. */
607 static void route_match_ip_route_source_free(void *rule
)
609 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
612 /* Route map commands for ip route-source matching. */
613 static const struct route_map_rule_cmd route_match_ip_route_source_cmd
= {
615 route_match_ip_route_source
,
616 route_match_ip_route_source_compile
,
617 route_match_ip_route_source_free
620 static enum route_map_cmd_result_t
621 route_match_prefix_list_flowspec(afi_t afi
, struct prefix_list
*plist
,
622 const struct prefix
*p
)
625 struct bgp_pbr_entry_main api
;
627 memset(&api
, 0, sizeof(api
));
629 if (family2afi(p
->u
.prefix_flowspec
.family
) != afi
)
632 /* extract match from flowspec entries */
633 ret
= bgp_flowspec_match_rules_fill(
634 (uint8_t *)p
->u
.prefix_flowspec
.ptr
,
635 p
->u
.prefix_flowspec
.prefixlen
, &api
,
639 if (api
.match_bitmask
& PREFIX_DST_PRESENT
||
640 api
.match_bitmask_iprule
& PREFIX_DST_PRESENT
) {
641 if (family2afi((&api
.dst_prefix
)->family
) != afi
)
643 return prefix_list_apply(plist
, &api
.dst_prefix
) == PREFIX_DENY
646 } else if (api
.match_bitmask
& PREFIX_SRC_PRESENT
||
647 api
.match_bitmask_iprule
& PREFIX_SRC_PRESENT
) {
648 if (family2afi((&api
.src_prefix
)->family
) != afi
)
650 return (prefix_list_apply(plist
, &api
.src_prefix
) == PREFIX_DENY
657 static enum route_map_cmd_result_t
658 route_match_prefix_list_evpn(afi_t afi
, struct prefix_list
*plist
,
659 const struct prefix
*p
)
661 /* Convert to match a general plist */
664 if (evpn_prefix2prefix(p
, &new))
667 return (prefix_list_apply(plist
, &new) == PREFIX_DENY
? RMAP_NOMATCH
671 static enum route_map_cmd_result_t
672 route_match_address_prefix_list(void *rule
, afi_t afi
,
673 const struct prefix
*prefix
, void *object
)
675 struct prefix_list
*plist
;
677 plist
= prefix_list_lookup(afi
, (char *)rule
);
679 if (CHECK_FLAG(rmap_debug
, DEBUG_ROUTEMAP_DETAIL
))
681 "%s: Prefix List %s specified does not exist defaulting to NO_MATCH",
682 __func__
, (char *)rule
);
686 if (prefix
->family
== AF_FLOWSPEC
)
687 return route_match_prefix_list_flowspec(afi
, plist
,
690 else if (prefix
->family
== AF_EVPN
)
691 return route_match_prefix_list_evpn(afi
, plist
, prefix
);
693 return (prefix_list_apply(plist
, prefix
) == PREFIX_DENY
? RMAP_NOMATCH
697 static enum route_map_cmd_result_t
698 route_match_ip_address_prefix_list(void *rule
, const struct prefix
*prefix
,
701 return route_match_address_prefix_list(rule
, AFI_IP
, prefix
, object
);
704 static void *route_match_ip_address_prefix_list_compile(const char *arg
)
706 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
709 static void route_match_ip_address_prefix_list_free(void *rule
)
711 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
714 static const struct route_map_rule_cmd
715 route_match_ip_address_prefix_list_cmd
= {
716 "ip address prefix-list",
717 route_match_ip_address_prefix_list
,
718 route_match_ip_address_prefix_list_compile
,
719 route_match_ip_address_prefix_list_free
722 /* `match ip next-hop prefix-list PREFIX_LIST' */
724 static enum route_map_cmd_result_t
725 route_match_ip_next_hop_prefix_list(void *rule
, const struct prefix
*prefix
,
728 struct prefix_list
*plist
;
729 struct bgp_path_info
*path
;
730 struct prefix_ipv4 p
;
732 if (prefix
->family
== AF_INET
) {
735 p
.prefix
= path
->attr
->nexthop
;
736 p
.prefixlen
= IPV4_MAX_BITLEN
;
738 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
740 if (CHECK_FLAG(rmap_debug
, DEBUG_ROUTEMAP_DETAIL
))
742 "%s: Prefix List %s specified does not exist defaulting to NO_MATCH",
743 __func__
, (char *)rule
);
747 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
754 static void *route_match_ip_next_hop_prefix_list_compile(const char *arg
)
756 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
759 static void route_match_ip_next_hop_prefix_list_free(void *rule
)
761 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
764 static const struct route_map_rule_cmd
765 route_match_ip_next_hop_prefix_list_cmd
= {
766 "ip next-hop prefix-list",
767 route_match_ip_next_hop_prefix_list
,
768 route_match_ip_next_hop_prefix_list_compile
,
769 route_match_ip_next_hop_prefix_list_free
772 /* `match ipv6 next-hop prefix-list PREFIXLIST_NAME' */
773 static enum route_map_cmd_result_t
774 route_match_ipv6_next_hop_prefix_list(void *rule
, const struct prefix
*prefix
,
777 struct prefix_list
*plist
;
778 struct bgp_path_info
*path
;
779 struct prefix_ipv6 p
;
781 if (prefix
->family
== AF_INET6
) {
784 p
.prefix
= path
->attr
->mp_nexthop_global
;
785 p
.prefixlen
= IPV6_MAX_BITLEN
;
787 plist
= prefix_list_lookup(AFI_IP6
, (char *)rule
);
789 if (CHECK_FLAG(rmap_debug
, DEBUG_ROUTEMAP_DETAIL
))
791 "%s: Prefix List %s specified does not exist defaulting to NO_MATCH",
792 __func__
, (char *)rule
);
796 if (prefix_list_apply(plist
, &p
) == PREFIX_PERMIT
)
799 if (path
->attr
->mp_nexthop_len
800 == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
) {
801 p
.prefix
= path
->attr
->mp_nexthop_local
;
802 if (prefix_list_apply(plist
, &p
) == PREFIX_PERMIT
)
810 static void *route_match_ipv6_next_hop_prefix_list_compile(const char *arg
)
812 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
815 static void route_match_ipv6_next_hop_prefix_list_free(void *rule
)
817 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
820 static const struct route_map_rule_cmd
821 route_match_ipv6_next_hop_prefix_list_cmd
= {
822 "ipv6 next-hop prefix-list",
823 route_match_ipv6_next_hop_prefix_list
,
824 route_match_ipv6_next_hop_prefix_list_compile
,
825 route_match_ipv6_next_hop_prefix_list_free
828 /* `match ip next-hop type <blackhole>' */
830 static enum route_map_cmd_result_t
831 route_match_ip_next_hop_type(void *rule
, const struct prefix
*prefix
,
834 struct bgp_path_info
*path
;
836 if (prefix
->family
== AF_INET
) {
837 path
= (struct bgp_path_info
*)object
;
841 /* If nexthop interface's index can't be resolved and nexthop is
842 set to any address then mark it as type `blackhole`.
843 This logic works for matching kernel/static routes like:
844 `ip route add blackhole 10.0.0.1`. */
845 if (path
->attr
->nexthop
.s_addr
== INADDR_ANY
846 && !path
->attr
->nh_ifindex
)
852 static void *route_match_ip_next_hop_type_compile(const char *arg
)
854 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
857 static void route_match_ip_next_hop_type_free(void *rule
)
859 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
862 static const struct route_map_rule_cmd
863 route_match_ip_next_hop_type_cmd
= {
865 route_match_ip_next_hop_type
,
866 route_match_ip_next_hop_type_compile
,
867 route_match_ip_next_hop_type_free
870 /* `match ip route-source prefix-list PREFIX_LIST' */
872 static enum route_map_cmd_result_t
873 route_match_ip_route_source_prefix_list(void *rule
, const struct prefix
*prefix
,
876 struct prefix_list
*plist
;
877 struct bgp_path_info
*path
;
879 struct prefix_ipv4 p
;
881 if (prefix
->family
== AF_INET
) {
885 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
889 p
.prefix
= peer
->su
.sin
.sin_addr
;
890 p
.prefixlen
= IPV4_MAX_BITLEN
;
892 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
894 if (CHECK_FLAG(rmap_debug
, DEBUG_ROUTEMAP_DETAIL
))
896 "%s: Prefix List %s specified does not exist defaulting to NO_MATCH",
897 __func__
, (char *)rule
);
901 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
908 static void *route_match_ip_route_source_prefix_list_compile(const char *arg
)
910 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
913 static void route_match_ip_route_source_prefix_list_free(void *rule
)
915 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
918 static const struct route_map_rule_cmd
919 route_match_ip_route_source_prefix_list_cmd
= {
920 "ip route-source prefix-list",
921 route_match_ip_route_source_prefix_list
,
922 route_match_ip_route_source_prefix_list_compile
,
923 route_match_ip_route_source_prefix_list_free
926 /* `match evpn default-route' */
928 /* Match function should return 1 if match is success else 0 */
929 static enum route_map_cmd_result_t
930 route_match_evpn_default_route(void *rule
, const struct prefix
*p
, void *object
)
932 if (is_evpn_prefix_default(p
))
938 /* Route map commands for default-route matching. */
939 static const struct route_map_rule_cmd
940 route_match_evpn_default_route_cmd
= {
941 "evpn default-route",
942 route_match_evpn_default_route
,
947 /* `match mac address MAC_ACCESS_LIST' */
949 /* Match function should return 1 if match is success else return
951 static enum route_map_cmd_result_t
952 route_match_mac_address(void *rule
, const struct prefix
*prefix
, void *object
)
954 struct access_list
*alist
;
957 alist
= access_list_lookup(AFI_L2VPN
, (char *)rule
);
959 if (CHECK_FLAG(rmap_debug
, DEBUG_ROUTEMAP_DETAIL
))
961 "%s: Access-List Specified: %s does not exist defaulting to NO_MATCH",
962 __func__
, (char *)rule
);
966 if (prefix
->u
.prefix_evpn
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
) {
967 if (CHECK_FLAG(rmap_debug
, DEBUG_ROUTEMAP_DETAIL
))
969 "%s: Prefix %pFX is not a EVPN MAC IP ROUTE defaulting to NO_MATCH",
974 p
.family
= AF_ETHERNET
;
975 p
.prefixlen
= ETH_ALEN
* 8;
976 p
.u
.prefix_eth
= prefix
->u
.prefix_evpn
.macip_addr
.mac
;
978 return (access_list_apply(alist
, &p
) == FILTER_DENY
? RMAP_NOMATCH
982 /* Route map `mac address' match statement. `arg' should be
984 static void *route_match_mac_address_compile(const char *arg
)
986 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
989 /* Free route map's compiled `ip address' value. */
990 static void route_match_mac_address_free(void *rule
)
992 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
995 /* Route map commands for mac address matching. */
996 static const struct route_map_rule_cmd route_match_mac_address_cmd
= {
998 route_match_mac_address
,
999 route_match_mac_address_compile
,
1000 route_match_mac_address_free
1004 * Match function returns:
1005 * ...RMAP_MATCH if match is found.
1006 * ...RMAP_NOMATCH if match is not found.
1007 * ...RMAP_NOOP to ignore this match check.
1009 static enum route_map_cmd_result_t
1010 route_match_vni(void *rule
, const struct prefix
*prefix
, void *object
)
1013 unsigned int label_cnt
= 0;
1014 struct bgp_path_info
*path
= NULL
;
1015 struct prefix_evpn
*evp
= (struct prefix_evpn
*) prefix
;
1017 vni
= *((vni_t
*)rule
);
1018 path
= (struct bgp_path_info
*)object
;
1021 * This rmap filter is valid for vxlan tunnel type only.
1022 * For any other tunnel type, return noop to ignore
1025 if (path
->attr
->encap_tunneltype
!= BGP_ENCAP_TYPE_VXLAN
)
1029 * Apply filter to type 1, 2, 5 routes only.
1030 * Other route types do not have vni label.
1033 && (evp
->prefix
.route_type
!= BGP_EVPN_AD_ROUTE
1034 && evp
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
1035 && evp
->prefix
.route_type
!= BGP_EVPN_IP_PREFIX_ROUTE
))
1038 if (path
->extra
== NULL
)
1039 return RMAP_NOMATCH
;
1042 label_cnt
< BGP_MAX_LABELS
&& label_cnt
< path
->extra
->num_labels
;
1044 if (vni
== label2vni(&path
->extra
->label
[label_cnt
]))
1048 return RMAP_NOMATCH
;
1051 /* Route map `vni' match statement. */
1052 static void *route_match_vni_compile(const char *arg
)
1057 vni
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(vni_t
));
1059 *vni
= strtoul(arg
, &end
, 10);
1061 XFREE(MTYPE_ROUTE_MAP_COMPILED
, vni
);
1068 /* Free route map's compiled `vni' value. */
1069 static void route_match_vni_free(void *rule
)
1071 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1074 /* Route map commands for vni matching. */
1075 static const struct route_map_rule_cmd route_match_evpn_vni_cmd
= {
1078 route_match_vni_compile
,
1079 route_match_vni_free
1082 /* `match evpn route-type' */
1084 /* Match function should return 1 if match is success else return
1086 static enum route_map_cmd_result_t
1087 route_match_evpn_route_type(void *rule
, const struct prefix
*pfx
, void *object
)
1089 uint8_t route_type
= 0;
1091 route_type
= *((uint8_t *)rule
);
1093 if (route_type
== pfx
->u
.prefix_evpn
.route_type
)
1096 return RMAP_NOMATCH
;
1099 /* Route map `route-type' match statement. */
1100 static void *route_match_evpn_route_type_compile(const char *arg
)
1102 uint8_t *route_type
= NULL
;
1104 route_type
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
1106 if (strncmp(arg
, "ea", 2) == 0)
1107 *route_type
= BGP_EVPN_AD_ROUTE
;
1108 else if (strncmp(arg
, "ma", 2) == 0)
1109 *route_type
= BGP_EVPN_MAC_IP_ROUTE
;
1110 else if (strncmp(arg
, "mu", 2) == 0)
1111 *route_type
= BGP_EVPN_IMET_ROUTE
;
1112 else if (strncmp(arg
, "es", 2) == 0)
1113 *route_type
= BGP_EVPN_ES_ROUTE
;
1115 *route_type
= BGP_EVPN_IP_PREFIX_ROUTE
;
1120 /* Free route map's compiled `route-type' value. */
1121 static void route_match_evpn_route_type_free(void *rule
)
1123 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1126 /* Route map commands for evpn route-type matching. */
1127 static const struct route_map_rule_cmd route_match_evpn_route_type_cmd
= {
1129 route_match_evpn_route_type
,
1130 route_match_evpn_route_type_compile
,
1131 route_match_evpn_route_type_free
1136 /* Match function should return 1 if match is success else return zero. */
1137 static enum route_map_cmd_result_t
1138 route_match_rd(void *rule
, const struct prefix
*prefix
, void *object
)
1140 struct prefix_rd
*prd_rule
= NULL
;
1141 const struct prefix_rd
*prd_route
= NULL
;
1142 struct bgp_path_info
*path
= NULL
;
1144 if (prefix
->family
!= AF_EVPN
)
1145 return RMAP_NOMATCH
;
1147 prd_rule
= (struct prefix_rd
*)rule
;
1148 path
= (struct bgp_path_info
*)object
;
1150 if (path
->net
== NULL
|| path
->net
->pdest
== NULL
)
1151 return RMAP_NOMATCH
;
1153 prd_route
= (struct prefix_rd
*)bgp_dest_get_prefix(path
->net
->pdest
);
1154 if (memcmp(prd_route
->val
, prd_rule
->val
, ECOMMUNITY_SIZE
) == 0)
1157 return RMAP_NOMATCH
;
1160 /* Route map `rd' match statement. */
1161 static void *route_match_rd_compile(const char *arg
)
1163 struct prefix_rd
*prd
;
1166 prd
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct prefix_rd
));
1168 ret
= str2prefix_rd(arg
, prd
);
1170 XFREE(MTYPE_ROUTE_MAP_COMPILED
, prd
);
1177 /* Free route map's compiled `rd' value. */
1178 static void route_match_rd_free(void *rule
)
1180 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1183 /* Route map commands for rd matching. */
1184 static const struct route_map_rule_cmd route_match_evpn_rd_cmd
= {
1187 route_match_rd_compile
,
1191 static enum route_map_cmd_result_t
1192 route_set_evpn_gateway_ip(void *rule
, const struct prefix
*prefix
, void *object
)
1194 struct ipaddr
*gw_ip
= rule
;
1195 struct bgp_path_info
*path
;
1196 struct prefix_evpn
*evp
;
1198 if (prefix
->family
!= AF_EVPN
)
1201 evp
= (struct prefix_evpn
*)prefix
;
1202 if (evp
->prefix
.route_type
!= BGP_EVPN_IP_PREFIX_ROUTE
)
1205 if ((is_evpn_prefix_ipaddr_v4(evp
) && IPADDRSZ(gw_ip
) != 4)
1206 || (is_evpn_prefix_ipaddr_v6(evp
) && IPADDRSZ(gw_ip
) != 16))
1211 /* Set gateway-ip value. */
1212 path
->attr
->evpn_overlay
.type
= OVERLAY_INDEX_GATEWAY_IP
;
1213 memcpy(&path
->attr
->evpn_overlay
.gw_ip
, &gw_ip
->ip
.addr
,
1220 * Route map `evpn gateway-ip' compile function.
1221 * Given string is converted to struct ipaddr structure
1223 static void *route_set_evpn_gateway_ip_compile(const char *arg
)
1225 struct ipaddr
*gw_ip
= NULL
;
1228 gw_ip
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct ipaddr
));
1230 ret
= str2ipaddr(arg
, gw_ip
);
1232 XFREE(MTYPE_ROUTE_MAP_COMPILED
, gw_ip
);
1238 /* Free route map's compiled `evpn gateway_ip' value. */
1239 static void route_set_evpn_gateway_ip_free(void *rule
)
1241 struct ipaddr
*gw_ip
= rule
;
1243 XFREE(MTYPE_ROUTE_MAP_COMPILED
, gw_ip
);
1246 /* Route map commands for set evpn gateway-ip ipv4. */
1247 struct route_map_rule_cmd route_set_evpn_gateway_ip_ipv4_cmd
= {
1248 "evpn gateway-ip ipv4", route_set_evpn_gateway_ip
,
1249 route_set_evpn_gateway_ip_compile
, route_set_evpn_gateway_ip_free
};
1251 /* Route map commands for set evpn gateway-ip ipv6. */
1252 struct route_map_rule_cmd route_set_evpn_gateway_ip_ipv6_cmd
= {
1253 "evpn gateway-ip ipv6", route_set_evpn_gateway_ip
,
1254 route_set_evpn_gateway_ip_compile
, route_set_evpn_gateway_ip_free
};
1256 /* Route map commands for VRF route leak with source vrf matching */
1257 static enum route_map_cmd_result_t
1258 route_match_vrl_source_vrf(void *rule
, const struct prefix
*prefix
,
1261 struct bgp_path_info
*path
;
1265 path
= (struct bgp_path_info
*)object
;
1267 if (strncmp(vrf_name
, "n/a", VRF_NAMSIZ
) == 0)
1268 return RMAP_NOMATCH
;
1270 if (path
->extra
== NULL
|| path
->extra
->bgp_orig
== NULL
)
1271 return RMAP_NOMATCH
;
1273 if (strncmp(vrf_name
, vrf_id_to_name(path
->extra
->bgp_orig
->vrf_id
),
1278 return RMAP_NOMATCH
;
1281 static void *route_match_vrl_source_vrf_compile(const char *arg
)
1283 uint8_t *vrf_name
= NULL
;
1285 vrf_name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1290 /* Free route map's compiled `route-type' value. */
1291 static void route_match_vrl_source_vrf_free(void *rule
)
1293 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1296 static const struct route_map_rule_cmd route_match_vrl_source_vrf_cmd
= {
1298 route_match_vrl_source_vrf
,
1299 route_match_vrl_source_vrf_compile
,
1300 route_match_vrl_source_vrf_free
1304 static enum route_map_cmd_result_t
1305 route_match_alias(void *rule
, const struct prefix
*prefix
, void *object
)
1308 struct bgp_path_info
*path
= object
;
1313 if (bgp_attr_get_community(path
->attr
)) {
1315 frrstr_split(bgp_attr_get_community(path
->attr
)->str
, " ",
1316 &communities
, &num
);
1317 for (int i
= 0; i
< num
; i
++) {
1318 const char *com2alias
=
1319 bgp_community2alias(communities
[i
]);
1320 if (!found
&& strcmp(alias
, com2alias
) == 0)
1322 XFREE(MTYPE_TMP
, communities
[i
]);
1324 XFREE(MTYPE_TMP
, communities
);
1329 if (bgp_attr_get_lcommunity(path
->attr
)) {
1331 frrstr_split(bgp_attr_get_lcommunity(path
->attr
)->str
, " ",
1332 &communities
, &num
);
1333 for (int i
= 0; i
< num
; i
++) {
1334 const char *com2alias
=
1335 bgp_community2alias(communities
[i
]);
1336 if (!found
&& strcmp(alias
, com2alias
) == 0)
1338 XFREE(MTYPE_TMP
, communities
[i
]);
1340 XFREE(MTYPE_TMP
, communities
);
1345 return RMAP_NOMATCH
;
1348 static void *route_match_alias_compile(const char *arg
)
1351 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1354 static void route_match_alias_free(void *rule
)
1356 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1359 static const struct route_map_rule_cmd route_match_alias_cmd
= {
1360 "alias", route_match_alias
, route_match_alias_compile
,
1361 route_match_alias_free
};
1363 /* `match local-preference LOCAL-PREF' */
1365 /* Match function return 1 if match is success else return zero. */
1366 static enum route_map_cmd_result_t
1367 route_match_local_pref(void *rule
, const struct prefix
*prefix
, void *object
)
1369 uint32_t *local_pref
;
1370 struct bgp_path_info
*path
;
1375 if (path
->attr
->local_pref
== *local_pref
)
1378 return RMAP_NOMATCH
;
1382 * Route map `match local-preference' match statement.
1383 * `arg' is local-pref value
1385 static void *route_match_local_pref_compile(const char *arg
)
1387 uint32_t *local_pref
;
1388 char *endptr
= NULL
;
1389 unsigned long tmpval
;
1392 tmpval
= strtoul(arg
, &endptr
, 10);
1393 if (*endptr
!= '\0' || errno
|| tmpval
> UINT32_MAX
)
1396 local_pref
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint32_t));
1398 *local_pref
= tmpval
;
1402 /* Free route map's compiled `match local-preference' value. */
1403 static void route_match_local_pref_free(void *rule
)
1405 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1408 /* Route map commands for metric matching. */
1409 static const struct route_map_rule_cmd route_match_local_pref_cmd
= {
1411 route_match_local_pref
,
1412 route_match_local_pref_compile
,
1413 route_match_local_pref_free
1416 /* `match metric METRIC' */
1418 /* Match function return 1 if match is success else return zero. */
1419 static enum route_map_cmd_result_t
1420 route_match_metric(void *rule
, const struct prefix
*prefix
, void *object
)
1422 struct rmap_value
*rv
;
1423 struct bgp_path_info
*path
;
1427 return route_value_match(rv
, path
->attr
->med
);
1430 /* Route map commands for metric matching. */
1431 static const struct route_map_rule_cmd route_match_metric_cmd
= {
1434 route_value_compile
,
1438 /* `match as-path ASPATH' */
1440 /* Match function for as-path match. I assume given object is */
1441 static enum route_map_cmd_result_t
1442 route_match_aspath(void *rule
, const struct prefix
*prefix
, void *object
)
1445 struct as_list
*as_list
;
1446 struct bgp_path_info
*path
;
1448 as_list
= as_list_lookup((char *)rule
);
1449 if (as_list
== NULL
)
1450 return RMAP_NOMATCH
;
1454 /* Perform match. */
1455 return ((as_list_apply(as_list
, path
->attr
->aspath
) == AS_FILTER_DENY
)
1460 /* Compile function for as-path match. */
1461 static void *route_match_aspath_compile(const char *arg
)
1463 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1466 /* Compile function for as-path match. */
1467 static void route_match_aspath_free(void *rule
)
1469 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1472 /* Route map commands for aspath matching. */
1473 static const struct route_map_rule_cmd route_match_aspath_cmd
= {
1476 route_match_aspath_compile
,
1477 route_match_aspath_free
1480 /* `match community COMMUNIY' */
1481 struct rmap_community
{
1487 /* Match function for community match. */
1488 static enum route_map_cmd_result_t
1489 route_match_community(void *rule
, const struct prefix
*prefix
, void *object
)
1491 struct community_list
*list
;
1492 struct bgp_path_info
*path
;
1493 struct rmap_community
*rcom
= rule
;
1498 list
= community_list_lookup(bgp_clist
, rcom
->name
, rcom
->name_hash
,
1499 COMMUNITY_LIST_MASTER
);
1501 return RMAP_NOMATCH
;
1504 if (community_list_exact_match(
1505 bgp_attr_get_community(path
->attr
), list
))
1508 if (community_list_match(bgp_attr_get_community(path
->attr
),
1513 return RMAP_NOMATCH
;
1516 /* Compile function for community match. */
1517 static void *route_match_community_compile(const char *arg
)
1519 struct rmap_community
*rcom
;
1523 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1525 p
= strchr(arg
, ' ');
1528 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1529 memcpy(rcom
->name
, arg
, len
);
1532 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1536 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1540 /* Compile function for community match. */
1541 static void route_match_community_free(void *rule
)
1543 struct rmap_community
*rcom
= rule
;
1545 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1546 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1550 * In routemap processing there is a need to add the
1551 * name as a rule_key in the dependency table. Routemap
1552 * lib is unaware of rule_key when exact-match clause
1553 * is in use. routemap lib uses the compiled output to
1554 * get the rule_key value.
1556 static void *route_match_get_community_key(void *rule
)
1558 struct rmap_community
*rcom
;
1565 /* Route map commands for community matching. */
1566 static const struct route_map_rule_cmd route_match_community_cmd
= {
1568 route_match_community
,
1569 route_match_community_compile
,
1570 route_match_community_free
,
1571 route_match_get_community_key
1574 /* Match function for lcommunity match. */
1575 static enum route_map_cmd_result_t
1576 route_match_lcommunity(void *rule
, const struct prefix
*prefix
, void *object
)
1578 struct community_list
*list
;
1579 struct bgp_path_info
*path
;
1580 struct rmap_community
*rcom
= rule
;
1584 list
= community_list_lookup(bgp_clist
, rcom
->name
, rcom
->name_hash
,
1585 LARGE_COMMUNITY_LIST_MASTER
);
1587 return RMAP_NOMATCH
;
1590 if (lcommunity_list_exact_match(
1591 bgp_attr_get_lcommunity(path
->attr
), list
))
1594 if (lcommunity_list_match(bgp_attr_get_lcommunity(path
->attr
),
1599 return RMAP_NOMATCH
;
1602 /* Compile function for community match. */
1603 static void *route_match_lcommunity_compile(const char *arg
)
1605 struct rmap_community
*rcom
;
1609 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1611 p
= strchr(arg
, ' ');
1614 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1615 memcpy(rcom
->name
, arg
, len
);
1618 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1622 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1626 /* Compile function for community match. */
1627 static void route_match_lcommunity_free(void *rule
)
1629 struct rmap_community
*rcom
= rule
;
1631 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1632 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1635 /* Route map commands for community matching. */
1636 static const struct route_map_rule_cmd route_match_lcommunity_cmd
= {
1638 route_match_lcommunity
,
1639 route_match_lcommunity_compile
,
1640 route_match_lcommunity_free
,
1641 route_match_get_community_key
1645 /* Match function for extcommunity match. */
1646 static enum route_map_cmd_result_t
1647 route_match_ecommunity(void *rule
, const struct prefix
*prefix
, void *object
)
1649 struct community_list
*list
;
1650 struct bgp_path_info
*path
;
1651 struct rmap_community
*rcom
= rule
;
1655 list
= community_list_lookup(bgp_clist
, rcom
->name
, rcom
->name_hash
,
1656 EXTCOMMUNITY_LIST_MASTER
);
1658 return RMAP_NOMATCH
;
1660 if (ecommunity_list_match(bgp_attr_get_ecommunity(path
->attr
), list
))
1663 return RMAP_NOMATCH
;
1666 /* Compile function for extcommunity match. */
1667 static void *route_match_ecommunity_compile(const char *arg
)
1669 struct rmap_community
*rcom
;
1671 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1672 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1673 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1678 /* Compile function for extcommunity match. */
1679 static void route_match_ecommunity_free(void *rule
)
1681 struct rmap_community
*rcom
= rule
;
1683 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1684 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1687 /* Route map commands for community matching. */
1688 static const struct route_map_rule_cmd route_match_ecommunity_cmd
= {
1690 route_match_ecommunity
,
1691 route_match_ecommunity_compile
,
1692 route_match_ecommunity_free
1695 /* `match nlri` and `set nlri` are replaced by `address-family ipv4`
1696 and `address-family vpnv4'. */
1698 /* `match origin' */
1699 static enum route_map_cmd_result_t
1700 route_match_origin(void *rule
, const struct prefix
*prefix
, void *object
)
1703 struct bgp_path_info
*path
;
1708 if (path
->attr
->origin
== *origin
)
1711 return RMAP_NOMATCH
;
1714 static void *route_match_origin_compile(const char *arg
)
1718 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
1720 if (strcmp(arg
, "igp") == 0)
1722 else if (strcmp(arg
, "egp") == 0)
1730 /* Free route map's compiled `ip address' value. */
1731 static void route_match_origin_free(void *rule
)
1733 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1736 /* Route map commands for origin matching. */
1737 static const struct route_map_rule_cmd route_match_origin_cmd
= {
1740 route_match_origin_compile
,
1741 route_match_origin_free
1744 /* match probability { */
1746 static enum route_map_cmd_result_t
1747 route_match_probability(void *rule
, const struct prefix
*prefix
, void *object
)
1749 long r
= frr_weak_random();
1751 switch (*(long *)rule
) {
1757 if (r
< *(long *)rule
) {
1762 return RMAP_NOMATCH
;
1765 static void *route_match_probability_compile(const char *arg
)
1771 lobule
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(long));
1781 *lobule
= RAND_MAX
/ 100 * perc
;
1787 static void route_match_probability_free(void *rule
)
1789 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1792 static const struct route_map_rule_cmd route_match_probability_cmd
= {
1794 route_match_probability
,
1795 route_match_probability_compile
,
1796 route_match_probability_free
1799 /* `match interface IFNAME' */
1800 /* Match function should return 1 if match is success else return
1802 static enum route_map_cmd_result_t
1803 route_match_interface(void *rule
, const struct prefix
*prefix
, void *object
)
1805 struct interface
*ifp
;
1806 struct bgp_path_info
*path
;
1810 if (!path
|| !path
->peer
|| !path
->peer
->bgp
)
1811 return RMAP_NOMATCH
;
1813 ifp
= if_lookup_by_name((char *)rule
, path
->peer
->bgp
->vrf_id
);
1815 if (ifp
== NULL
|| ifp
->ifindex
!= path
->attr
->nh_ifindex
)
1816 return RMAP_NOMATCH
;
1821 /* Route map `interface' match statement. `arg' should be
1823 static void *route_match_interface_compile(const char *arg
)
1825 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1828 /* Free route map's compiled `interface' value. */
1829 static void route_match_interface_free(void *rule
)
1831 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1834 /* Route map commands for ip address matching. */
1835 static const struct route_map_rule_cmd route_match_interface_cmd
= {
1837 route_match_interface
,
1838 route_match_interface_compile
,
1839 route_match_interface_free
1844 /* `set ip next-hop IP_ADDRESS' */
1846 /* Match function return 1 if match is success else return zero. */
1847 static enum route_map_cmd_result_t
1848 route_match_tag(void *rule
, const struct prefix
*prefix
, void *object
)
1851 struct bgp_path_info
*path
;
1856 return ((path
->attr
->tag
== *tag
) ? RMAP_MATCH
: RMAP_NOMATCH
);
1860 /* Route map commands for tag matching. */
1861 static const struct route_map_rule_cmd route_match_tag_cmd
= {
1864 route_map_rule_tag_compile
,
1865 route_map_rule_tag_free
,
1868 static enum route_map_cmd_result_t
1869 route_set_srte_color(void *rule
, const struct prefix
*prefix
, void *object
)
1871 uint32_t *srte_color
= rule
;
1872 struct bgp_path_info
*path
;
1876 path
->attr
->srte_color
= *srte_color
;
1877 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_SRTE_COLOR
);
1882 /* Route map `sr-te color' compile function */
1883 static void *route_set_srte_color_compile(const char *arg
)
1887 color
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint32_t));
1893 /* Free route map's compiled `sr-te color' value. */
1894 static void route_set_srte_color_free(void *rule
)
1896 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1899 /* Route map commands for sr-te color set. */
1900 struct route_map_rule_cmd route_set_srte_color_cmd
= {
1901 "sr-te color", route_set_srte_color
, route_set_srte_color_compile
,
1902 route_set_srte_color_free
};
1904 /* Set nexthop to object. object must be pointer to struct attr. */
1905 struct rmap_ip_nexthop_set
{
1906 struct in_addr
*address
;
1911 static enum route_map_cmd_result_t
1912 route_set_ip_nexthop(void *rule
, const struct prefix
*prefix
, void *object
)
1914 struct rmap_ip_nexthop_set
*rins
= rule
;
1915 struct bgp_path_info
*path
;
1918 if (prefix
->family
== AF_INET6
)
1924 if (rins
->unchanged
) {
1925 SET_FLAG(path
->attr
->rmap_change_flags
,
1926 BATTR_RMAP_NEXTHOP_UNCHANGED
);
1927 } else if (rins
->peer_address
) {
1928 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
1929 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
1931 && sockunion_family(peer
->su_remote
) == AF_INET
) {
1932 path
->attr
->nexthop
.s_addr
=
1933 sockunion2ip(peer
->su_remote
);
1934 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1935 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
1936 /* The next hop value will be set as part of
1937 * packet rewrite. Set the flags here to indicate
1938 * that rewrite needs to be done.
1939 * Also, clear the value.
1941 SET_FLAG(path
->attr
->rmap_change_flags
,
1942 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
1943 path
->attr
->nexthop
.s_addr
= INADDR_ANY
;
1946 /* Set next hop value. */
1947 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1948 path
->attr
->nexthop
= *rins
->address
;
1949 SET_FLAG(path
->attr
->rmap_change_flags
,
1950 BATTR_RMAP_IPV4_NHOP_CHANGED
);
1951 /* case for MP-BGP : MPLS VPN */
1952 path
->attr
->mp_nexthop_global_in
= *rins
->address
;
1953 path
->attr
->mp_nexthop_len
= sizeof(*rins
->address
);
1959 /* Route map `ip nexthop' compile function. Given string is converted
1960 to struct in_addr structure. */
1961 static void *route_set_ip_nexthop_compile(const char *arg
)
1963 struct rmap_ip_nexthop_set
*rins
;
1964 struct in_addr
*address
= NULL
;
1965 int peer_address
= 0;
1969 if (strcmp(arg
, "peer-address") == 0)
1971 else if (strcmp(arg
, "unchanged") == 0)
1974 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1975 sizeof(struct in_addr
));
1976 ret
= inet_aton(arg
, address
);
1979 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
1984 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1985 sizeof(struct rmap_ip_nexthop_set
));
1987 rins
->address
= address
;
1988 rins
->peer_address
= peer_address
;
1989 rins
->unchanged
= unchanged
;
1994 /* Free route map's compiled `ip nexthop' value. */
1995 static void route_set_ip_nexthop_free(void *rule
)
1997 struct rmap_ip_nexthop_set
*rins
= rule
;
1999 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
->address
);
2001 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
);
2004 /* Route map commands for ip nexthop set. */
2005 static const struct route_map_rule_cmd route_set_ip_nexthop_cmd
= {
2007 route_set_ip_nexthop
,
2008 route_set_ip_nexthop_compile
,
2009 route_set_ip_nexthop_free
2012 /* `set l3vpn next-hop encapsulation l3vpn gre' */
2014 /* Set nexthop to object */
2015 struct rmap_l3vpn_nexthop_encapsulation_set
{
2019 static enum route_map_cmd_result_t
2020 route_set_l3vpn_nexthop_encapsulation(void *rule
, const struct prefix
*prefix
,
2023 struct rmap_l3vpn_nexthop_encapsulation_set
*rins
= rule
;
2024 struct bgp_path_info
*path
;
2028 if (rins
->protocol
!= IPPROTO_GRE
)
2031 SET_FLAG(path
->attr
->rmap_change_flags
, BATTR_RMAP_L3VPN_ACCEPT_GRE
);
2035 /* Route map `l3vpn nexthop encapsulation' compile function. */
2036 static void *route_set_l3vpn_nexthop_encapsulation_compile(const char *arg
)
2038 struct rmap_l3vpn_nexthop_encapsulation_set
*rins
;
2040 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
2041 sizeof(struct rmap_l3vpn_nexthop_encapsulation_set
));
2043 /* XXX ALL GRE modes are accepted for now: gre or ip6gre */
2044 rins
->protocol
= IPPROTO_GRE
;
2049 /* Free route map's compiled `ip nexthop' value. */
2050 static void route_set_l3vpn_nexthop_encapsulation_free(void *rule
)
2052 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2055 /* Route map commands for l3vpn next-hop encapsulation set. */
2056 static const struct route_map_rule_cmd
2057 route_set_l3vpn_nexthop_encapsulation_cmd
= {
2058 "l3vpn next-hop encapsulation",
2059 route_set_l3vpn_nexthop_encapsulation
,
2060 route_set_l3vpn_nexthop_encapsulation_compile
,
2061 route_set_l3vpn_nexthop_encapsulation_free
};
2063 /* `set local-preference LOCAL_PREF' */
2065 /* Set local preference. */
2066 static enum route_map_cmd_result_t
2067 route_set_local_pref(void *rule
, const struct prefix
*prefix
, void *object
)
2069 struct rmap_value
*rv
;
2070 struct bgp_path_info
*path
;
2071 uint32_t locpref
= 0;
2073 /* Fetch routemap's rule information. */
2077 /* Set local preference value. */
2078 if (path
->attr
->local_pref
)
2079 locpref
= path
->attr
->local_pref
;
2081 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
);
2082 path
->attr
->local_pref
= route_value_adjust(rv
, locpref
, path
->peer
);
2087 /* Set local preference rule structure. */
2088 static const struct route_map_rule_cmd route_set_local_pref_cmd
= {
2090 route_set_local_pref
,
2091 route_value_compile
,
2095 /* `set weight WEIGHT' */
2098 static enum route_map_cmd_result_t
2099 route_set_weight(void *rule
, const struct prefix
*prefix
, void *object
)
2101 struct rmap_value
*rv
;
2102 struct bgp_path_info
*path
;
2104 /* Fetch routemap's rule information. */
2108 /* Set weight value. */
2109 path
->attr
->weight
= route_value_adjust(rv
, 0, path
->peer
);
2114 /* Set local preference rule structure. */
2115 static const struct route_map_rule_cmd route_set_weight_cmd
= {
2118 route_value_compile
,
2122 /* `set distance DISTANCE */
2123 static enum route_map_cmd_result_t
2124 route_set_distance(void *rule
, const struct prefix
*prefix
, void *object
)
2126 struct bgp_path_info
*path
= object
;
2127 struct rmap_value
*rv
= rule
;
2129 path
->attr
->distance
= rv
->value
;
2134 /* set distance rule structure */
2135 static const struct route_map_rule_cmd route_set_distance_cmd
= {
2138 route_value_compile
,
2142 /* `set metric METRIC' */
2144 /* Set metric to attribute. */
2145 static enum route_map_cmd_result_t
2146 route_set_metric(void *rule
, const struct prefix
*prefix
, void *object
)
2148 struct rmap_value
*rv
;
2149 struct bgp_path_info
*path
;
2152 /* Fetch routemap's rule information. */
2156 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
))
2157 med
= path
->attr
->med
;
2159 path
->attr
->med
= route_value_adjust(rv
, med
, path
->peer
);
2160 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
);
2165 /* Set metric rule structure. */
2166 static const struct route_map_rule_cmd route_set_metric_cmd
= {
2169 route_value_compile
,
2173 /* `set table (1-4294967295)' */
2175 static enum route_map_cmd_result_t
2176 route_set_table_id(void *rule
, const struct prefix
*prefix
,
2180 struct rmap_value
*rv
;
2181 struct bgp_path_info
*path
;
2183 /* Fetch routemap's rule information. */
2187 path
->attr
->rmap_table_id
= rv
->value
;
2192 /* Set table_id rule structure. */
2193 static const struct route_map_rule_cmd route_set_table_id_cmd
= {
2196 route_value_compile
,
2200 /* `set as-path prepend ASPATH' */
2202 /* For AS path prepend mechanism. */
2203 static enum route_map_cmd_result_t
2204 route_set_aspath_prepend(void *rule
, const struct prefix
*prefix
, void *object
)
2206 struct aspath
*aspath
;
2208 struct bgp_path_info
*path
;
2212 if (path
->attr
->aspath
->refcnt
)
2213 new = aspath_dup(path
->attr
->aspath
);
2215 new = path
->attr
->aspath
;
2217 if ((uintptr_t)rule
> 10) {
2219 aspath_prepend(aspath
, new);
2221 as_t as
= aspath_leftmost(new);
2223 new = aspath_add_seq_n(new, as
, (uintptr_t)rule
);
2226 path
->attr
->aspath
= new;
2231 static void *route_set_aspath_prepend_compile(const char *arg
)
2235 if (sscanf(arg
, "last-as %u", &num
) == 1 && num
> 0 && num
<= 10)
2236 return (void *)(uintptr_t)num
;
2238 return route_aspath_compile(arg
);
2241 static void route_set_aspath_prepend_free(void *rule
)
2243 if ((uintptr_t)rule
> 10)
2244 route_aspath_free(rule
);
2248 /* Set as-path prepend rule structure. */
2249 static const struct route_map_rule_cmd route_set_aspath_prepend_cmd
= {
2251 route_set_aspath_prepend
,
2252 route_set_aspath_prepend_compile
,
2253 route_set_aspath_prepend_free
,
2256 /* `set as-path exclude ASn' */
2258 /* For ASN exclude mechanism.
2259 * Iterate over ASns requested and filter them from the given AS_PATH one by
2261 * Make a deep copy of existing AS_PATH, but for the first ASn only.
2263 static enum route_map_cmd_result_t
2264 route_set_aspath_exclude(void *rule
, const struct prefix
*dummy
, void *object
)
2266 struct aspath
*new_path
, *exclude_path
;
2267 struct bgp_path_info
*path
;
2269 exclude_path
= rule
;
2271 if (path
->attr
->aspath
->refcnt
)
2272 new_path
= aspath_dup(path
->attr
->aspath
);
2274 new_path
= path
->attr
->aspath
;
2275 path
->attr
->aspath
= aspath_filter_exclude(new_path
, exclude_path
);
2280 /* Set ASn exlude rule structure. */
2281 static const struct route_map_rule_cmd route_set_aspath_exclude_cmd
= {
2283 route_set_aspath_exclude
,
2284 route_aspath_compile
,
2288 /* `set as-path replace AS-PATH` */
2289 static void *route_aspath_replace_compile(const char *arg
)
2291 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2294 static void route_aspath_replace_free(void *rule
)
2296 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2299 static enum route_map_cmd_result_t
2300 route_set_aspath_replace(void *rule
, const struct prefix
*dummy
, void *object
)
2302 struct aspath
*aspath_new
;
2303 const char *replace
= rule
;
2304 struct bgp_path_info
*path
= object
;
2305 as_t own_asn
= path
->peer
->change_local_as
? path
->peer
->change_local_as
2306 : path
->peer
->local_as
;
2308 if (path
->peer
->sort
!= BGP_PEER_EBGP
) {
2310 "`set as-path replace` is supported only for EBGP peers");
2314 if (path
->attr
->aspath
->refcnt
)
2315 aspath_new
= aspath_dup(path
->attr
->aspath
);
2317 aspath_new
= path
->attr
->aspath
;
2319 if (strmatch(replace
, "any")) {
2320 path
->attr
->aspath
=
2321 aspath_replace_all_asn(aspath_new
, own_asn
);
2323 as_t replace_asn
= strtoul(replace
, NULL
, 10);
2325 path
->attr
->aspath
= aspath_replace_specific_asn(
2326 aspath_new
, replace_asn
, own_asn
);
2329 aspath_free(aspath_new
);
2334 static const struct route_map_rule_cmd route_set_aspath_replace_cmd
= {
2336 route_set_aspath_replace
,
2337 route_aspath_replace_compile
,
2338 route_aspath_replace_free
,
2341 /* `set community COMMUNITY' */
2342 struct rmap_com_set
{
2343 struct community
*com
;
2348 /* For community set mechanism. */
2349 static enum route_map_cmd_result_t
2350 route_set_community(void *rule
, const struct prefix
*prefix
, void *object
)
2352 struct rmap_com_set
*rcs
;
2353 struct bgp_path_info
*path
;
2355 struct community
*new = NULL
;
2356 struct community
*old
;
2357 struct community
*merge
;
2362 old
= bgp_attr_get_community(attr
);
2366 bgp_attr_set_community(attr
, NULL
);
2367 /* See the longer comment down below. */
2368 if (old
&& old
->refcnt
== 0)
2369 community_free(&old
);
2373 /* "additive" case. */
2374 if (rcs
->additive
&& old
) {
2375 merge
= community_merge(community_dup(old
), rcs
->com
);
2377 new = community_uniq_sort(merge
);
2378 community_free(&merge
);
2380 new = community_dup(rcs
->com
);
2382 /* HACK: if the old community is not intern'd,
2383 * we should free it here, or all reference to it may be
2385 * Really need to cleanup attribute caching sometime.
2387 if (old
&& old
->refcnt
== 0)
2388 community_free(&old
);
2390 /* will be interned by caller if required */
2391 bgp_attr_set_community(attr
, new);
2396 /* Compile function for set community. */
2397 static void *route_set_community_compile(const char *arg
)
2399 struct rmap_com_set
*rcs
;
2400 struct community
*com
= NULL
;
2405 if (strcmp(arg
, "none") == 0)
2408 sp
= strstr(arg
, "additive");
2410 if (sp
&& sp
> arg
) {
2411 /* "additive" keyword is included. */
2416 com
= community_str2com(arg
);
2425 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
2427 rcs
->additive
= additive
;
2433 /* Free function for set community. */
2434 static void route_set_community_free(void *rule
)
2436 struct rmap_com_set
*rcs
= rule
;
2439 community_free(&rcs
->com
);
2440 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
2443 /* Set community rule structure. */
2444 static const struct route_map_rule_cmd route_set_community_cmd
= {
2446 route_set_community
,
2447 route_set_community_compile
,
2448 route_set_community_free
,
2451 /* `set community COMMUNITY' */
2452 struct rmap_lcom_set
{
2453 struct lcommunity
*lcom
;
2459 /* For lcommunity set mechanism. */
2460 static enum route_map_cmd_result_t
2461 route_set_lcommunity(void *rule
, const struct prefix
*prefix
, void *object
)
2463 struct rmap_lcom_set
*rcs
;
2464 struct bgp_path_info
*path
;
2466 struct lcommunity
*new = NULL
;
2467 struct lcommunity
*old
;
2468 struct lcommunity
*merge
;
2473 old
= bgp_attr_get_lcommunity(attr
);
2477 bgp_attr_set_lcommunity(attr
, NULL
);
2479 /* See the longer comment down below. */
2480 if (old
&& old
->refcnt
== 0)
2481 lcommunity_free(&old
);
2485 if (rcs
->additive
&& old
) {
2486 merge
= lcommunity_merge(lcommunity_dup(old
), rcs
->lcom
);
2488 new = lcommunity_uniq_sort(merge
);
2489 lcommunity_free(&merge
);
2491 new = lcommunity_dup(rcs
->lcom
);
2493 /* HACK: if the old large-community is not intern'd,
2494 * we should free it here, or all reference to it may be
2496 * Really need to cleanup attribute caching sometime.
2498 if (old
&& old
->refcnt
== 0)
2499 lcommunity_free(&old
);
2501 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
2502 bgp_attr_set_lcommunity(attr
, new);
2507 /* Compile function for set community. */
2508 static void *route_set_lcommunity_compile(const char *arg
)
2510 struct rmap_lcom_set
*rcs
;
2511 struct lcommunity
*lcom
= NULL
;
2516 if (strcmp(arg
, "none") == 0)
2519 sp
= strstr(arg
, "additive");
2521 if (sp
&& sp
> arg
) {
2522 /* "additive" keyworkd is included. */
2527 lcom
= lcommunity_str2com(arg
);
2536 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
2538 rcs
->additive
= additive
;
2544 /* Free function for set lcommunity. */
2545 static void route_set_lcommunity_free(void *rule
)
2547 struct rmap_lcom_set
*rcs
= rule
;
2550 lcommunity_free(&rcs
->lcom
);
2552 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
2555 /* Set community rule structure. */
2556 static const struct route_map_rule_cmd route_set_lcommunity_cmd
= {
2558 route_set_lcommunity
,
2559 route_set_lcommunity_compile
,
2560 route_set_lcommunity_free
,
2563 /* `set large-comm-list (<1-99>|<100-500>|WORD) delete' */
2565 /* For large community set mechanism. */
2566 static enum route_map_cmd_result_t
2567 route_set_lcommunity_delete(void *rule
, const struct prefix
*pfx
, void *object
)
2569 struct community_list
*list
;
2570 struct lcommunity
*merge
;
2571 struct lcommunity
*new;
2572 struct lcommunity
*old
;
2573 struct bgp_path_info
*path
;
2574 struct rmap_community
*rcom
= rule
;
2580 list
= community_list_lookup(bgp_clist
, rcom
->name
, rcom
->name_hash
,
2581 LARGE_COMMUNITY_LIST_MASTER
);
2582 old
= bgp_attr_get_lcommunity(path
->attr
);
2585 merge
= lcommunity_list_match_delete(lcommunity_dup(old
), list
);
2586 new = lcommunity_uniq_sort(merge
);
2587 lcommunity_free(&merge
);
2589 /* HACK: if the old community is not intern'd,
2590 * we should free it here, or all reference to it may be
2592 * Really need to cleanup attribute caching sometime.
2594 if (old
->refcnt
== 0)
2595 lcommunity_free(&old
);
2597 if (new->size
== 0) {
2598 bgp_attr_set_lcommunity(path
->attr
, NULL
);
2599 lcommunity_free(&new);
2601 bgp_attr_set_lcommunity(path
->attr
, new);
2608 /* Compile function for set lcommunity. */
2609 static void *route_set_lcommunity_delete_compile(const char *arg
)
2611 struct rmap_community
*rcom
;
2615 frrstr_split(arg
, " ", &splits
, &num
);
2617 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2618 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, splits
[0]);
2619 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2621 for (int i
= 0; i
< num
; i
++)
2622 XFREE(MTYPE_TMP
, splits
[i
]);
2623 XFREE(MTYPE_TMP
, splits
);
2628 /* Free function for set lcommunity. */
2629 static void route_set_lcommunity_delete_free(void *rule
)
2631 struct rmap_community
*rcom
= rule
;
2633 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2634 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2637 /* Set lcommunity rule structure. */
2638 static const struct route_map_rule_cmd route_set_lcommunity_delete_cmd
= {
2640 route_set_lcommunity_delete
,
2641 route_set_lcommunity_delete_compile
,
2642 route_set_lcommunity_delete_free
,
2646 /* `set comm-list (<1-99>|<100-500>|WORD) delete' */
2648 /* For community set mechanism. */
2649 static enum route_map_cmd_result_t
2650 route_set_community_delete(void *rule
, const struct prefix
*prefix
,
2653 struct community_list
*list
;
2654 struct community
*merge
;
2655 struct community
*new;
2656 struct community
*old
;
2657 struct bgp_path_info
*path
;
2658 struct rmap_community
*rcom
= rule
;
2664 list
= community_list_lookup(bgp_clist
, rcom
->name
, rcom
->name_hash
,
2665 COMMUNITY_LIST_MASTER
);
2666 old
= bgp_attr_get_community(path
->attr
);
2669 merge
= community_list_match_delete(community_dup(old
), list
);
2670 new = community_uniq_sort(merge
);
2671 community_free(&merge
);
2673 /* HACK: if the old community is not intern'd,
2674 * we should free it here, or all reference to it may be
2676 * Really need to cleanup attribute caching sometime.
2678 if (old
->refcnt
== 0)
2679 community_free(&old
);
2681 if (new->size
== 0) {
2682 bgp_attr_set_community(path
->attr
, NULL
);
2683 community_free(&new);
2685 bgp_attr_set_community(path
->attr
, new);
2692 /* Compile function for set community. */
2693 static void *route_set_community_delete_compile(const char *arg
)
2695 struct rmap_community
*rcom
;
2699 frrstr_split(arg
, " ", &splits
, &num
);
2701 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2702 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, splits
[0]);
2703 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2705 for (int i
= 0; i
< num
; i
++)
2706 XFREE(MTYPE_TMP
, splits
[i
]);
2707 XFREE(MTYPE_TMP
, splits
);
2712 /* Free function for set community. */
2713 static void route_set_community_delete_free(void *rule
)
2715 struct rmap_community
*rcom
= rule
;
2717 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2718 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2721 /* Set community rule structure. */
2722 static const struct route_map_rule_cmd route_set_community_delete_cmd
= {
2724 route_set_community_delete
,
2725 route_set_community_delete_compile
,
2726 route_set_community_delete_free
,
2729 /* `set extcommunity rt COMMUNITY' */
2731 struct rmap_ecom_set
{
2732 struct ecommunity
*ecom
;
2736 /* For community set mechanism. Used by _rt and _soo. */
2737 static enum route_map_cmd_result_t
2738 route_set_ecommunity(void *rule
, const struct prefix
*prefix
, void *object
)
2740 struct rmap_ecom_set
*rcs
;
2741 struct ecommunity
*new_ecom
;
2742 struct ecommunity
*old_ecom
;
2743 struct bgp_path_info
*path
;
2751 bgp_attr_set_ecommunity(attr
, NULL
);
2758 /* We assume additive for Extended Community. */
2759 old_ecom
= bgp_attr_get_ecommunity(path
->attr
);
2763 ecommunity_merge(ecommunity_dup(old_ecom
), rcs
->ecom
);
2765 /* old_ecom->refcnt = 1 => owned elsewhere, e.g.
2766 * bgp_update_receive()
2767 * ->refcnt = 0 => set by a previous route-map
2769 if (!old_ecom
->refcnt
)
2770 ecommunity_free(&old_ecom
);
2772 new_ecom
= ecommunity_dup(rcs
->ecom
);
2774 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
2775 bgp_attr_set_ecommunity(path
->attr
, new_ecom
);
2780 static void *route_set_ecommunity_none_compile(const char *arg
)
2782 struct rmap_ecom_set
*rcs
;
2785 if (strncmp(arg
, "none", 4) == 0)
2788 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_ecom_set
));
2795 static void *route_set_ecommunity_rt_compile(const char *arg
)
2797 struct rmap_ecom_set
*rcs
;
2798 struct ecommunity
*ecom
;
2800 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_ROUTE_TARGET
, 0);
2804 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_ecom_set
));
2805 rcs
->ecom
= ecommunity_intern(ecom
);
2811 /* Free function for set community. Used by _rt and _soo */
2812 static void route_set_ecommunity_free(void *rule
)
2814 struct rmap_ecom_set
*rcs
= rule
;
2817 ecommunity_unintern(&rcs
->ecom
);
2819 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
2822 static const struct route_map_rule_cmd route_set_ecommunity_none_cmd
= {
2824 route_set_ecommunity
,
2825 route_set_ecommunity_none_compile
,
2826 route_set_ecommunity_free
,
2829 /* Set community rule structure. */
2830 static const struct route_map_rule_cmd route_set_ecommunity_rt_cmd
= {
2832 route_set_ecommunity
,
2833 route_set_ecommunity_rt_compile
,
2834 route_set_ecommunity_free
,
2837 /* `set extcommunity soo COMMUNITY' */
2839 /* Compile function for set community. */
2840 static void *route_set_ecommunity_soo_compile(const char *arg
)
2842 struct rmap_ecom_set
*rcs
;
2843 struct ecommunity
*ecom
;
2845 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_SITE_ORIGIN
, 0);
2849 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_ecom_set
));
2850 rcs
->ecom
= ecommunity_intern(ecom
);
2856 /* Set community rule structure. */
2857 static const struct route_map_rule_cmd route_set_ecommunity_soo_cmd
= {
2859 route_set_ecommunity
,
2860 route_set_ecommunity_soo_compile
,
2861 route_set_ecommunity_free
,
2864 /* `set extcommunity bandwidth' */
2866 struct rmap_ecomm_lb_set
{
2868 #define RMAP_ECOMM_LB_SET_VALUE 1
2869 #define RMAP_ECOMM_LB_SET_CUMUL 2
2870 #define RMAP_ECOMM_LB_SET_NUM_MPATH 3
2875 static enum route_map_cmd_result_t
2876 route_set_ecommunity_lb(void *rule
, const struct prefix
*prefix
, void *object
)
2878 struct rmap_ecomm_lb_set
*rels
= rule
;
2879 struct bgp_path_info
*path
;
2881 struct ecommunity ecom_lb
= {0};
2882 struct ecommunity_val lb_eval
;
2883 uint32_t bw_bytes
= 0;
2884 uint16_t mpath_count
= 0;
2885 struct ecommunity
*new_ecom
;
2886 struct ecommunity
*old_ecom
;
2891 if (!peer
|| !peer
->bgp
)
2894 /* Build link bandwidth extended community */
2895 as
= (peer
->bgp
->as
> BGP_AS_MAX
) ? BGP_AS_TRANS
: peer
->bgp
->as
;
2896 if (rels
->lb_type
== RMAP_ECOMM_LB_SET_VALUE
) {
2897 bw_bytes
= ((uint64_t)rels
->bw
* 1000 * 1000) / 8;
2898 } else if (rels
->lb_type
== RMAP_ECOMM_LB_SET_CUMUL
) {
2899 /* process this only for the best path. */
2900 if (!CHECK_FLAG(path
->flags
, BGP_PATH_SELECTED
))
2903 bw_bytes
= (uint32_t)bgp_path_info_mpath_cumbw(path
);
2907 } else if (rels
->lb_type
== RMAP_ECOMM_LB_SET_NUM_MPATH
) {
2909 /* process this only for the best path. */
2910 if (!CHECK_FLAG(path
->flags
, BGP_PATH_SELECTED
))
2913 bw_bytes
= ((uint64_t)peer
->bgp
->lb_ref_bw
* 1000 * 1000) / 8;
2914 mpath_count
= bgp_path_info_mpath_count(path
) + 1;
2915 bw_bytes
*= mpath_count
;
2918 encode_lb_extcomm(as
, bw_bytes
, rels
->non_trans
, &lb_eval
,
2919 CHECK_FLAG(peer
->flags
,
2920 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE
));
2922 /* add to route or merge with existing */
2923 old_ecom
= bgp_attr_get_ecommunity(path
->attr
);
2925 new_ecom
= ecommunity_dup(old_ecom
);
2926 ecommunity_add_val(new_ecom
, &lb_eval
, true, true);
2927 if (!old_ecom
->refcnt
)
2928 ecommunity_free(&old_ecom
);
2931 ecom_lb
.unit_size
= ECOMMUNITY_SIZE
;
2932 ecom_lb
.val
= (uint8_t *)lb_eval
.val
;
2933 new_ecom
= ecommunity_dup(&ecom_lb
);
2936 /* new_ecom will be intern()'d or attr_flush()'d in call stack */
2937 bgp_attr_set_ecommunity(path
->attr
, new_ecom
);
2939 /* Mark that route-map has set link bandwidth; used in attribute
2940 * setting decisions.
2942 SET_FLAG(path
->attr
->rmap_change_flags
, BATTR_RMAP_LINK_BW_SET
);
2947 static void *route_set_ecommunity_lb_compile(const char *arg
)
2949 struct rmap_ecomm_lb_set
*rels
;
2952 char bw_str
[40] = {0};
2954 bool non_trans
= false;
2957 p
= strchr(arg
, ' ');
2962 memcpy(bw_str
, arg
, len
);
2967 if (strcmp(str
, "cumulative") == 0)
2968 lb_type
= RMAP_ECOMM_LB_SET_CUMUL
;
2969 else if (strcmp(str
, "num-multipaths") == 0)
2970 lb_type
= RMAP_ECOMM_LB_SET_NUM_MPATH
;
2974 bw
= strtoul(str
, &end
, 10);
2977 lb_type
= RMAP_ECOMM_LB_SET_VALUE
;
2980 rels
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
2981 sizeof(struct rmap_ecomm_lb_set
));
2982 rels
->lb_type
= lb_type
;
2984 rels
->non_trans
= non_trans
;
2989 static void route_set_ecommunity_lb_free(void *rule
)
2991 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2994 /* Set community rule structure. */
2995 struct route_map_rule_cmd route_set_ecommunity_lb_cmd
= {
2996 "extcommunity bandwidth",
2997 route_set_ecommunity_lb
,
2998 route_set_ecommunity_lb_compile
,
2999 route_set_ecommunity_lb_free
,
3002 /* `set origin ORIGIN' */
3004 /* For origin set. */
3005 static enum route_map_cmd_result_t
3006 route_set_origin(void *rule
, const struct prefix
*prefix
, void *object
)
3009 struct bgp_path_info
*path
;
3014 path
->attr
->origin
= *origin
;
3019 /* Compile function for origin set. */
3020 static void *route_set_origin_compile(const char *arg
)
3024 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
3026 if (strcmp(arg
, "igp") == 0)
3027 *origin
= BGP_ORIGIN_IGP
;
3028 else if (strcmp(arg
, "egp") == 0)
3029 *origin
= BGP_ORIGIN_EGP
;
3031 *origin
= BGP_ORIGIN_INCOMPLETE
;
3036 /* Compile function for origin set. */
3037 static void route_set_origin_free(void *rule
)
3039 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3042 /* Set origin rule structure. */
3043 static const struct route_map_rule_cmd route_set_origin_cmd
= {
3046 route_set_origin_compile
,
3047 route_set_origin_free
,
3050 /* `set atomic-aggregate' */
3052 /* For atomic aggregate set. */
3053 static enum route_map_cmd_result_t
3054 route_set_atomic_aggregate(void *rule
, const struct prefix
*pfx
, void *object
)
3056 struct bgp_path_info
*path
;
3059 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE
);
3064 /* Compile function for atomic aggregate. */
3065 static void *route_set_atomic_aggregate_compile(const char *arg
)
3070 /* Compile function for atomic aggregate. */
3071 static void route_set_atomic_aggregate_free(void *rule
)
3076 /* Set atomic aggregate rule structure. */
3077 static const struct route_map_rule_cmd route_set_atomic_aggregate_cmd
= {
3079 route_set_atomic_aggregate
,
3080 route_set_atomic_aggregate_compile
,
3081 route_set_atomic_aggregate_free
,
3084 /* AIGP TLV Metric */
3085 static enum route_map_cmd_result_t
3086 route_set_aigp_metric(void *rule
, const struct prefix
*pfx
, void *object
)
3088 const char *aigp_metric
= rule
;
3089 struct bgp_path_info
*path
= object
;
3092 if (strmatch(aigp_metric
, "igp-metric")) {
3094 return RMAP_NOMATCH
;
3096 bgp_attr_set_aigp_metric(path
->attr
, path
->nexthop
->metric
);
3098 aigp
= atoi(aigp_metric
);
3099 bgp_attr_set_aigp_metric(path
->attr
, aigp
);
3102 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_AIGP
);
3107 static void *route_set_aigp_metric_compile(const char *arg
)
3109 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
3112 static void route_set_aigp_metric_free(void *rule
)
3114 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3117 static const struct route_map_rule_cmd route_set_aigp_metric_cmd
= {
3119 route_set_aigp_metric
,
3120 route_set_aigp_metric_compile
,
3121 route_set_aigp_metric_free
,
3124 /* `set aggregator as AS A.B.C.D' */
3127 struct in_addr address
;
3130 static enum route_map_cmd_result_t
3131 route_set_aggregator_as(void *rule
, const struct prefix
*prefix
, void *object
)
3133 struct bgp_path_info
*path
;
3134 struct aggregator
*aggregator
;
3139 path
->attr
->aggregator_as
= aggregator
->as
;
3140 path
->attr
->aggregator_addr
= aggregator
->address
;
3141 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR
);
3146 static void *route_set_aggregator_as_compile(const char *arg
)
3148 struct aggregator
*aggregator
;
3154 XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct aggregator
));
3155 if (sscanf(arg
, "%s %s", as
, address
) != 2) {
3156 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
3160 aggregator
->as
= strtoul(as
, NULL
, 10);
3161 ret
= inet_aton(address
, &aggregator
->address
);
3163 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
3169 static void route_set_aggregator_as_free(void *rule
)
3171 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3174 static const struct route_map_rule_cmd route_set_aggregator_as_cmd
= {
3176 route_set_aggregator_as
,
3177 route_set_aggregator_as_compile
,
3178 route_set_aggregator_as_free
,
3181 /* Set tag to object. object must be pointer to struct bgp_path_info */
3182 static enum route_map_cmd_result_t
3183 route_set_tag(void *rule
, const struct prefix
*prefix
, void *object
)
3186 struct bgp_path_info
*path
;
3192 path
->attr
->tag
= *tag
;
3197 /* Route map commands for tag set. */
3198 static const struct route_map_rule_cmd route_set_tag_cmd
= {
3201 route_map_rule_tag_compile
,
3202 route_map_rule_tag_free
,
3205 /* Set label-index to object. object must be pointer to struct bgp_path_info */
3206 static enum route_map_cmd_result_t
3207 route_set_label_index(void *rule
, const struct prefix
*prefix
, void *object
)
3209 struct rmap_value
*rv
;
3210 struct bgp_path_info
*path
;
3211 uint32_t label_index
;
3213 /* Fetch routemap's rule information. */
3217 /* Set label-index value. */
3218 label_index
= rv
->value
;
3220 path
->attr
->label_index
= label_index
;
3221 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID
);
3227 /* Route map commands for label-index set. */
3228 static const struct route_map_rule_cmd route_set_label_index_cmd
= {
3230 route_set_label_index
,
3231 route_value_compile
,
3235 /* `match ipv6 address IP_ACCESS_LIST' */
3237 static enum route_map_cmd_result_t
3238 route_match_ipv6_address(void *rule
, const struct prefix
*prefix
, void *object
)
3240 struct access_list
*alist
;
3242 if (prefix
->family
== AF_INET6
) {
3243 alist
= access_list_lookup(AFI_IP6
, (char *)rule
);
3244 if (alist
== NULL
) {
3245 if (CHECK_FLAG(rmap_debug
, DEBUG_ROUTEMAP_DETAIL
))
3247 "%s: Access-List Specified: %s does not exist defaulting to NO_MATCH",
3248 __func__
, (char *)rule
);
3250 return RMAP_NOMATCH
;
3253 return (access_list_apply(alist
, prefix
) == FILTER_DENY
3257 return RMAP_NOMATCH
;
3260 static void *route_match_ipv6_address_compile(const char *arg
)
3262 struct access_list
*alist
;
3264 alist
= access_list_lookup(AFI_IP6
, arg
);
3267 "Access List specified %s does not exist yet, default will be NO_MATCH until it is created",
3270 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
3273 static void route_match_ipv6_address_free(void *rule
)
3275 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3278 /* Route map commands for ip address matching. */
3279 static const struct route_map_rule_cmd route_match_ipv6_address_cmd
= {
3281 route_match_ipv6_address
,
3282 route_match_ipv6_address_compile
,
3283 route_match_ipv6_address_free
3286 /* `match ipv6 next-hop ACCESSLIST6_NAME' */
3287 static enum route_map_cmd_result_t
3288 route_match_ipv6_next_hop(void *rule
, const struct prefix
*prefix
, void *object
)
3290 struct bgp_path_info
*path
;
3291 struct access_list
*alist
;
3292 struct prefix_ipv6 p
;
3294 if (prefix
->family
== AF_INET6
) {
3296 p
.family
= AF_INET6
;
3297 p
.prefix
= path
->attr
->mp_nexthop_global
;
3298 p
.prefixlen
= IPV6_MAX_BITLEN
;
3300 alist
= access_list_lookup(AFI_IP6
, (char *)rule
);
3302 if (CHECK_FLAG(rmap_debug
, DEBUG_ROUTEMAP_DETAIL
))
3304 "%s: Access-List Specified: %s does not exist defaulting to NO_MATCH",
3305 __func__
, (char *)rule
);
3307 return RMAP_NOMATCH
;
3310 if (access_list_apply(alist
, &p
) == FILTER_PERMIT
)
3313 if (path
->attr
->mp_nexthop_len
3314 == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
) {
3315 p
.prefix
= path
->attr
->mp_nexthop_local
;
3316 if (access_list_apply(alist
, &p
) == FILTER_PERMIT
)
3321 return RMAP_NOMATCH
;
3324 static void *route_match_ipv6_next_hop_compile(const char *arg
)
3326 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
3329 static void route_match_ipv6_next_hop_free(void *rule
)
3331 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3334 static const struct route_map_rule_cmd route_match_ipv6_next_hop_cmd
= {
3336 route_match_ipv6_next_hop
,
3337 route_match_ipv6_next_hop_compile
,
3338 route_match_ipv6_next_hop_free
3341 /* `match ipv6 next-hop IP_ADDRESS' */
3343 static enum route_map_cmd_result_t
3344 route_match_ipv6_next_hop_address(void *rule
, const struct prefix
*prefix
,
3347 struct in6_addr
*addr
= rule
;
3348 struct bgp_path_info
*path
;
3352 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
))
3355 if (path
->attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
3356 && IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_local
, rule
))
3359 return RMAP_NOMATCH
;
3362 static void *route_match_ipv6_next_hop_address_compile(const char *arg
)
3364 struct in6_addr
*address
;
3367 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3369 ret
= inet_pton(AF_INET6
, arg
, address
);
3371 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3378 static void route_match_ipv6_next_hop_address_free(void *rule
)
3380 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3383 static const struct route_map_rule_cmd route_match_ipv6_next_hop_address_cmd
= {
3384 "ipv6 next-hop address",
3385 route_match_ipv6_next_hop_address
,
3386 route_match_ipv6_next_hop_address_compile
,
3387 route_match_ipv6_next_hop_address_free
3390 /* `match ip next-hop address IP_ADDRESS' */
3392 static enum route_map_cmd_result_t
3393 route_match_ipv4_next_hop(void *rule
, const struct prefix
*prefix
, void *object
)
3395 struct in_addr
*addr
= rule
;
3396 struct bgp_path_info
*path
;
3400 if (path
->attr
->nexthop
.s_addr
== addr
->s_addr
3401 || (path
->attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV4
3402 && IPV4_ADDR_SAME(&path
->attr
->mp_nexthop_global_in
, addr
)))
3405 return RMAP_NOMATCH
;
3408 static void *route_match_ipv4_next_hop_compile(const char *arg
)
3410 struct in_addr
*address
;
3413 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3415 ret
= inet_pton(AF_INET
, arg
, address
);
3417 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3424 static void route_match_ipv4_next_hop_free(void *rule
)
3426 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3429 static const struct route_map_rule_cmd route_match_ipv4_next_hop_cmd
= {
3430 "ip next-hop address",
3431 route_match_ipv4_next_hop
,
3432 route_match_ipv4_next_hop_compile
,
3433 route_match_ipv4_next_hop_free
3436 /* `match ipv6 address prefix-list PREFIX_LIST' */
3438 static enum route_map_cmd_result_t
3439 route_match_ipv6_address_prefix_list(void *rule
, const struct prefix
*prefix
,
3442 return route_match_address_prefix_list(rule
, AFI_IP6
, prefix
, object
);
3445 static void *route_match_ipv6_address_prefix_list_compile(const char *arg
)
3447 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
3450 static void route_match_ipv6_address_prefix_list_free(void *rule
)
3452 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3455 static const struct route_map_rule_cmd
3456 route_match_ipv6_address_prefix_list_cmd
= {
3457 "ipv6 address prefix-list",
3458 route_match_ipv6_address_prefix_list
,
3459 route_match_ipv6_address_prefix_list_compile
,
3460 route_match_ipv6_address_prefix_list_free
3463 /* `match ipv6 next-hop type <TYPE>' */
3465 static enum route_map_cmd_result_t
3466 route_match_ipv6_next_hop_type(void *rule
, const struct prefix
*prefix
,
3469 struct bgp_path_info
*path
;
3470 struct in6_addr
*addr
= rule
;
3472 if (prefix
->family
== AF_INET6
) {
3473 path
= (struct bgp_path_info
*)object
;
3475 return RMAP_NOMATCH
;
3477 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
)
3478 && !path
->attr
->nh_ifindex
)
3482 return RMAP_NOMATCH
;
3485 static void *route_match_ipv6_next_hop_type_compile(const char *arg
)
3487 struct in6_addr
*address
;
3490 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3492 ret
= inet_pton(AF_INET6
, "::0", address
);
3494 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3501 static void route_match_ipv6_next_hop_type_free(void *rule
)
3503 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3506 static const struct route_map_rule_cmd
3507 route_match_ipv6_next_hop_type_cmd
= {
3508 "ipv6 next-hop type",
3509 route_match_ipv6_next_hop_type
,
3510 route_match_ipv6_next_hop_type_compile
,
3511 route_match_ipv6_next_hop_type_free
3514 /* `set ipv6 nexthop global IP_ADDRESS' */
3516 /* Set nexthop to object. object must be pointer to struct attr. */
3517 static enum route_map_cmd_result_t
3518 route_set_ipv6_nexthop_global(void *rule
, const struct prefix
*p
, void *object
)
3520 struct in6_addr
*address
;
3521 struct bgp_path_info
*path
;
3523 /* Fetch routemap's rule information. */
3527 /* Set next hop value. */
3528 path
->attr
->mp_nexthop_global
= *address
;
3530 /* Set nexthop length. */
3531 if (path
->attr
->mp_nexthop_len
== 0)
3532 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL
;
3534 SET_FLAG(path
->attr
->rmap_change_flags
,
3535 BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED
);
3540 /* Route map `ip next-hop' compile function. Given string is converted
3541 to struct in_addr structure. */
3542 static void *route_set_ipv6_nexthop_global_compile(const char *arg
)
3545 struct in6_addr
*address
;
3547 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3549 ret
= inet_pton(AF_INET6
, arg
, address
);
3552 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3559 /* Free route map's compiled `ip next-hop' value. */
3560 static void route_set_ipv6_nexthop_global_free(void *rule
)
3562 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3565 /* Route map commands for ip nexthop set. */
3566 static const struct route_map_rule_cmd
3567 route_set_ipv6_nexthop_global_cmd
= {
3568 "ipv6 next-hop global",
3569 route_set_ipv6_nexthop_global
,
3570 route_set_ipv6_nexthop_global_compile
,
3571 route_set_ipv6_nexthop_global_free
3574 /* Set next-hop preference value. */
3575 static enum route_map_cmd_result_t
3576 route_set_ipv6_nexthop_prefer_global(void *rule
, const struct prefix
*prefix
,
3579 struct bgp_path_info
*path
;
3582 /* Fetch routemap's rule information. */
3586 if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
3587 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
)) {
3588 /* Set next hop preference to global */
3589 path
->attr
->mp_nexthop_prefer_global
= true;
3590 SET_FLAG(path
->attr
->rmap_change_flags
,
3591 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
3593 path
->attr
->mp_nexthop_prefer_global
= false;
3594 SET_FLAG(path
->attr
->rmap_change_flags
,
3595 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
3601 static void *route_set_ipv6_nexthop_prefer_global_compile(const char *arg
)
3605 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
3611 /* Free route map's compiled `ip next-hop' value. */
3612 static void route_set_ipv6_nexthop_prefer_global_free(void *rule
)
3614 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3617 /* Route map commands for ip nexthop set preferred. */
3618 static const struct route_map_rule_cmd
3619 route_set_ipv6_nexthop_prefer_global_cmd
= {
3620 "ipv6 next-hop prefer-global",
3621 route_set_ipv6_nexthop_prefer_global
,
3622 route_set_ipv6_nexthop_prefer_global_compile
,
3623 route_set_ipv6_nexthop_prefer_global_free
3626 /* `set ipv6 nexthop local IP_ADDRESS' */
3628 /* Set nexthop to object. object must be pointer to struct attr. */
3629 static enum route_map_cmd_result_t
3630 route_set_ipv6_nexthop_local(void *rule
, const struct prefix
*p
, void *object
)
3632 struct in6_addr
*address
;
3633 struct bgp_path_info
*path
;
3635 /* Fetch routemap's rule information. */
3639 /* Set next hop value. */
3640 path
->attr
->mp_nexthop_local
= *address
;
3642 /* Set nexthop length. */
3643 if (path
->attr
->mp_nexthop_len
!= BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
&&
3644 path
->attr
->mp_nexthop_len
!= BGP_ATTR_NHLEN_VPNV6_GLOBAL_AND_LL
)
3645 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
3647 SET_FLAG(path
->attr
->rmap_change_flags
,
3648 BATTR_RMAP_IPV6_LL_NHOP_CHANGED
);
3653 /* Route map `ip nexthop' compile function. Given string is converted
3654 to struct in_addr structure. */
3655 static void *route_set_ipv6_nexthop_local_compile(const char *arg
)
3658 struct in6_addr
*address
;
3660 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3662 ret
= inet_pton(AF_INET6
, arg
, address
);
3665 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3672 /* Free route map's compiled `ip nexthop' value. */
3673 static void route_set_ipv6_nexthop_local_free(void *rule
)
3675 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3678 /* Route map commands for ip nexthop set. */
3679 static const struct route_map_rule_cmd
3680 route_set_ipv6_nexthop_local_cmd
= {
3681 "ipv6 next-hop local",
3682 route_set_ipv6_nexthop_local
,
3683 route_set_ipv6_nexthop_local_compile
,
3684 route_set_ipv6_nexthop_local_free
3687 /* `set ipv6 nexthop peer-address' */
3689 /* Set nexthop to object. object must be pointer to struct attr. */
3690 static enum route_map_cmd_result_t
3691 route_set_ipv6_nexthop_peer(void *rule
, const struct prefix
*pfx
, void *object
)
3693 struct in6_addr peer_address
;
3694 struct bgp_path_info
*path
;
3697 /* Fetch routemap's rule information. */
3701 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
3702 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
3704 && sockunion_family(peer
->su_remote
) == AF_INET6
) {
3705 peer_address
= peer
->su_remote
->sin6
.sin6_addr
;
3706 /* Set next hop value and length in attribute. */
3707 if (IN6_IS_ADDR_LINKLOCAL(&peer_address
)) {
3708 path
->attr
->mp_nexthop_local
= peer_address
;
3709 if (path
->attr
->mp_nexthop_len
3710 != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
3711 path
->attr
->mp_nexthop_len
=
3712 BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
3714 path
->attr
->mp_nexthop_global
= peer_address
;
3715 if (path
->attr
->mp_nexthop_len
== 0)
3716 path
->attr
->mp_nexthop_len
=
3717 BGP_ATTR_NHLEN_IPV6_GLOBAL
;
3720 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
3721 /* The next hop value will be set as part of packet
3723 * Set the flags here to indicate that rewrite needs to
3725 * Also, clear the value - we clear both global and
3727 * nexthops, whether we send one or both is determined
3730 SET_FLAG(path
->attr
->rmap_change_flags
,
3731 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
3732 /* clear next hop value. */
3733 memset(&(path
->attr
->mp_nexthop_global
), 0,
3734 sizeof(struct in6_addr
));
3735 memset(&(path
->attr
->mp_nexthop_local
), 0,
3736 sizeof(struct in6_addr
));
3742 /* Route map `ip next-hop' compile function. Given string is converted
3743 to struct in_addr structure. */
3744 static void *route_set_ipv6_nexthop_peer_compile(const char *arg
)
3748 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
3754 /* Free route map's compiled `ip next-hop' value. */
3755 static void route_set_ipv6_nexthop_peer_free(void *rule
)
3757 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3760 /* Route map commands for ip nexthop set. */
3761 static const struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd
= {
3762 "ipv6 next-hop peer-address",
3763 route_set_ipv6_nexthop_peer
,
3764 route_set_ipv6_nexthop_peer_compile
,
3765 route_set_ipv6_nexthop_peer_free
3768 /* `set ipv4 vpn next-hop A.B.C.D' */
3770 static enum route_map_cmd_result_t
3771 route_set_vpnv4_nexthop(void *rule
, const struct prefix
*prefix
, void *object
)
3773 struct in_addr
*address
;
3774 struct bgp_path_info
*path
;
3776 /* Fetch routemap's rule information. */
3780 /* Set next hop value. */
3781 path
->attr
->mp_nexthop_global_in
= *address
;
3782 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV4
;
3784 SET_FLAG(path
->attr
->rmap_change_flags
, BATTR_RMAP_VPNV4_NHOP_CHANGED
);
3789 static void *route_set_vpnv4_nexthop_compile(const char *arg
)
3792 struct in_addr
*address
;
3794 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3796 ret
= inet_aton(arg
, address
);
3799 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3806 /* `set ipv6 vpn next-hop A.B.C.D' */
3808 static enum route_map_cmd_result_t
3809 route_set_vpnv6_nexthop(void *rule
, const struct prefix
*prefix
, void *object
)
3811 struct in6_addr
*address
;
3812 struct bgp_path_info
*path
;
3814 /* Fetch routemap's rule information. */
3818 /* Set next hop value. */
3819 memcpy(&path
->attr
->mp_nexthop_global
, address
,
3820 sizeof(struct in6_addr
));
3821 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_VPNV6_GLOBAL
;
3823 SET_FLAG(path
->attr
->rmap_change_flags
,
3824 BATTR_RMAP_VPNV6_GLOBAL_NHOP_CHANGED
);
3829 static void *route_set_vpnv6_nexthop_compile(const char *arg
)
3832 struct in6_addr
*address
;
3834 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3835 ret
= inet_pton(AF_INET6
, arg
, address
);
3838 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3845 static void route_set_vpn_nexthop_free(void *rule
)
3847 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3850 /* Route map commands for ipv4 next-hop set. */
3851 static const struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd
= {
3852 "ipv4 vpn next-hop",
3853 route_set_vpnv4_nexthop
,
3854 route_set_vpnv4_nexthop_compile
,
3855 route_set_vpn_nexthop_free
3858 /* Route map commands for ipv6 next-hop set. */
3859 static const struct route_map_rule_cmd route_set_vpnv6_nexthop_cmd
= {
3860 "ipv6 vpn next-hop",
3861 route_set_vpnv6_nexthop
,
3862 route_set_vpnv6_nexthop_compile
,
3863 route_set_vpn_nexthop_free
3866 /* `set originator-id' */
3868 /* For origin set. */
3869 static enum route_map_cmd_result_t
3870 route_set_originator_id(void *rule
, const struct prefix
*prefix
, void *object
)
3872 struct in_addr
*address
;
3873 struct bgp_path_info
*path
;
3878 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
);
3879 path
->attr
->originator_id
= *address
;
3884 /* Compile function for originator-id set. */
3885 static void *route_set_originator_id_compile(const char *arg
)
3888 struct in_addr
*address
;
3890 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3892 ret
= inet_aton(arg
, address
);
3895 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3902 /* Compile function for originator_id set. */
3903 static void route_set_originator_id_free(void *rule
)
3905 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3908 /* Set originator-id rule structure. */
3909 static const struct route_map_rule_cmd route_set_originator_id_cmd
= {
3911 route_set_originator_id
,
3912 route_set_originator_id_compile
,
3913 route_set_originator_id_free
,
3916 static enum route_map_cmd_result_t
3917 route_match_rpki_extcommunity(void *rule
, const struct prefix
*prefix
,
3920 struct bgp_path_info
*path
;
3921 struct ecommunity
*ecomm
;
3922 struct ecommunity_val
*ecomm_val
;
3923 enum rpki_states
*rpki_status
= rule
;
3924 enum rpki_states ecomm_rpki_status
= RPKI_NOT_BEING_USED
;
3928 ecomm
= bgp_attr_get_ecommunity(path
->attr
);
3930 return RMAP_NOMATCH
;
3932 ecomm_val
= ecommunity_lookup(ecomm
, ECOMMUNITY_ENCODE_OPAQUE_NON_TRANS
,
3933 ECOMMUNITY_ORIGIN_VALIDATION_STATE
);
3935 return RMAP_NOMATCH
;
3937 /* The Origin Validation State is encoded in the last octet of
3938 * the extended community.
3940 switch (ecomm_val
->val
[7]) {
3941 case ECOMMUNITY_ORIGIN_VALIDATION_STATE_VALID
:
3942 ecomm_rpki_status
= RPKI_VALID
;
3944 case ECOMMUNITY_ORIGIN_VALIDATION_STATE_NOTFOUND
:
3945 ecomm_rpki_status
= RPKI_NOTFOUND
;
3947 case ECOMMUNITY_ORIGIN_VALIDATION_STATE_INVALID
:
3948 ecomm_rpki_status
= RPKI_INVALID
;
3950 case ECOMMUNITY_ORIGIN_VALIDATION_STATE_NOTUSED
:
3954 if (ecomm_rpki_status
== *rpki_status
)
3957 return RMAP_NOMATCH
;
3960 static void *route_match_extcommunity_compile(const char *arg
)
3964 rpki_status
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
3966 if (strcmp(arg
, "valid") == 0)
3967 *rpki_status
= RPKI_VALID
;
3968 else if (strcmp(arg
, "invalid") == 0)
3969 *rpki_status
= RPKI_INVALID
;
3971 *rpki_status
= RPKI_NOTFOUND
;
3976 static const struct route_map_rule_cmd route_match_rpki_extcommunity_cmd
= {
3977 "rpki-extcommunity",
3978 route_match_rpki_extcommunity
,
3979 route_match_extcommunity_compile
,
3984 * This is the workhorse routine for processing in/out routemap
3987 static void bgp_route_map_process_peer(const char *rmap_name
,
3988 struct route_map
*map
, struct peer
*peer
,
3989 int afi
, int safi
, int route_update
)
3991 struct bgp_filter
*filter
;
3993 if (!peer
|| !rmap_name
)
3996 filter
= &peer
->filter
[afi
][safi
];
3998 * in is for non-route-server clients,
3999 * out is for all peers
4001 if (filter
->map
[RMAP_IN
].name
4002 && (strcmp(rmap_name
, filter
->map
[RMAP_IN
].name
) == 0)) {
4003 filter
->map
[RMAP_IN
].map
= map
;
4005 if (route_update
&& peer_established(peer
)) {
4006 if (CHECK_FLAG(peer
->af_flags
[afi
][safi
],
4007 PEER_FLAG_SOFT_RECONFIG
)) {
4008 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
4010 "Processing route_map %s(%s:%s) update on peer %s (inbound, soft-reconfig)",
4011 rmap_name
, afi2str(afi
),
4012 safi2str(safi
), peer
->host
);
4014 bgp_soft_reconfig_in(peer
, afi
, safi
);
4015 } else if (CHECK_FLAG(peer
->cap
,
4016 PEER_CAP_REFRESH_OLD_RCV
)
4017 || CHECK_FLAG(peer
->cap
,
4018 PEER_CAP_REFRESH_NEW_RCV
)) {
4019 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
4021 "Processing route_map %s(%s:%s) update on peer %s (inbound, route-refresh)",
4022 rmap_name
, afi2str(afi
),
4023 safi2str(safi
), peer
->host
);
4024 bgp_route_refresh_send(
4025 peer
, afi
, safi
, 0, 0, 0,
4026 BGP_ROUTE_REFRESH_NORMAL
);
4032 * For outbound, unsuppress and default-originate map change (content or
4033 * map created), merely update the "config" here, the actual route
4034 * announcement happens at the group level.
4036 if (filter
->map
[RMAP_OUT
].name
4037 && (strcmp(rmap_name
, filter
->map
[RMAP_OUT
].name
) == 0))
4038 filter
->map
[RMAP_OUT
].map
= map
;
4040 if (filter
->usmap
.name
&& (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
4041 filter
->usmap
.map
= map
;
4043 if (filter
->advmap
.aname
4044 && (strcmp(rmap_name
, filter
->advmap
.aname
) == 0)) {
4045 filter
->advmap
.amap
= map
;
4048 if (filter
->advmap
.cname
4049 && (strcmp(rmap_name
, filter
->advmap
.cname
) == 0)) {
4050 filter
->advmap
.cmap
= map
;
4053 if (peer
->default_rmap
[afi
][safi
].name
4054 && (strcmp(rmap_name
, peer
->default_rmap
[afi
][safi
].name
) == 0))
4055 peer
->default_rmap
[afi
][safi
].map
= map
;
4057 /* Notify BGP conditional advertisement scanner percess */
4058 peer
->advmap_config_change
[afi
][safi
] = true;
4061 static void bgp_route_map_update_peer_group(const char *rmap_name
,
4062 struct route_map
*map
,
4065 struct peer_group
*group
;
4066 struct listnode
*node
, *nnode
;
4067 struct bgp_filter
*filter
;
4074 /* All the peers have been updated correctly already. This is
4075 * just updating the placeholder data. No real update required.
4077 for (ALL_LIST_ELEMENTS(bgp
->group
, node
, nnode
, group
)) {
4078 FOREACH_AFI_SAFI (afi
, safi
) {
4079 filter
= &group
->conf
->filter
[afi
][safi
];
4081 for (direct
= RMAP_IN
; direct
< RMAP_MAX
; direct
++) {
4082 if ((filter
->map
[direct
].name
)
4083 && (strcmp(rmap_name
,
4084 filter
->map
[direct
].name
)
4086 filter
->map
[direct
].map
= map
;
4089 if (filter
->usmap
.name
4090 && (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
4091 filter
->usmap
.map
= map
;
4093 if (filter
->advmap
.aname
&&
4094 (strcmp(rmap_name
, filter
->advmap
.aname
) == 0))
4095 filter
->advmap
.amap
= map
;
4097 if (filter
->advmap
.cname
&&
4098 (strcmp(rmap_name
, filter
->advmap
.cname
) == 0))
4099 filter
->advmap
.cmap
= map
;
4105 * Note that if an extreme number (tens of thousands) of route-maps are in use
4106 * and if bgp has an extreme number of peers, network statements, etc then this
4107 * function can consume a lot of cycles. This is due to this function being
4108 * called for each route-map and within this function we walk the list of peers,
4109 * network statements, etc looking to see if they use this route-map.
4111 static void bgp_route_map_process_update(struct bgp
*bgp
, const char *rmap_name
,
4119 struct bgp_dest
*bn
;
4120 struct bgp_static
*bgp_static
;
4121 struct bgp_aggregate
*aggregate
;
4122 struct listnode
*node
, *nnode
;
4123 struct route_map
*map
;
4124 char buf
[INET6_ADDRSTRLEN
];
4126 map
= route_map_lookup_by_name(rmap_name
);
4128 for (ALL_LIST_ELEMENTS(bgp
->peer
, node
, nnode
, peer
)) {
4130 /* Ignore dummy peer-group structure */
4131 if (CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
))
4134 FOREACH_AFI_SAFI (afi
, safi
) {
4135 /* process in/out/import/export/default-orig
4137 bgp_route_map_process_peer(rmap_name
, map
, peer
, afi
,
4138 safi
, route_update
);
4142 /* for outbound/default-orig route-maps, process for groups */
4143 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
, rmap_name
,
4146 /* update peer-group config (template) */
4147 bgp_route_map_update_peer_group(rmap_name
, map
, bgp
);
4149 FOREACH_AFI_SAFI (afi
, safi
) {
4150 /* For table route-map updates. */
4151 if (!bgp_fibupd_safi(safi
))
4154 if (bgp
->table_map
[afi
][safi
].name
4155 && (strcmp(rmap_name
, bgp
->table_map
[afi
][safi
].name
)
4158 /* bgp->table_map[afi][safi].map is NULL.
4159 * i.e Route map creation event.
4160 * So update applied_counter.
4161 * If it is not NULL, i.e It may be routemap updation or
4162 * deletion. so no need to update the counter.
4164 if (!bgp
->table_map
[afi
][safi
].map
)
4165 route_map_counter_increment(map
);
4166 bgp
->table_map
[afi
][safi
].map
= map
;
4168 if (BGP_DEBUG(zebra
, ZEBRA
))
4170 "Processing route_map %s(%s:%s) update on table map",
4171 rmap_name
, afi2str(afi
),
4174 bgp_zebra_announce_table(bgp
, afi
, safi
);
4177 /* For network route-map updates. */
4178 for (bn
= bgp_table_top(bgp
->route
[afi
][safi
]); bn
;
4179 bn
= bgp_route_next(bn
)) {
4180 bgp_static
= bgp_dest_get_bgp_static_info(bn
);
4184 if (!bgp_static
->rmap
.name
4185 || (strcmp(rmap_name
, bgp_static
->rmap
.name
) != 0))
4188 if (!bgp_static
->rmap
.map
)
4189 route_map_counter_increment(map
);
4191 bgp_static
->rmap
.map
= map
;
4193 if (route_update
&& !bgp_static
->backdoor
) {
4194 const struct prefix
*bn_p
=
4195 bgp_dest_get_prefix(bn
);
4197 if (bgp_debug_zebra(bn_p
))
4199 "Processing route_map %s(%s:%s) update on static route %s",
4200 rmap_name
, afi2str(afi
),
4202 inet_ntop(bn_p
->family
,
4203 &bn_p
->u
.prefix
, buf
,
4205 bgp_static_update(bgp
, bn_p
, bgp_static
, afi
,
4210 /* For aggregate-address route-map updates. */
4211 for (bn
= bgp_table_top(bgp
->aggregate
[afi
][safi
]); bn
;
4212 bn
= bgp_route_next(bn
)) {
4213 aggregate
= bgp_dest_get_bgp_aggregate_info(bn
);
4219 /* Update suppress map pointer. */
4220 if (aggregate
->suppress_map_name
4221 && strmatch(aggregate
->suppress_map_name
,
4223 if (aggregate
->rmap
.map
== NULL
)
4224 route_map_counter_increment(map
);
4226 aggregate
->suppress_map
= map
;
4228 bgp_aggregate_toggle_suppressed(
4229 aggregate
, bgp
, bgp_dest_get_prefix(bn
),
4235 if (aggregate
->rmap
.name
4236 && strmatch(rmap_name
, aggregate
->rmap
.name
)) {
4237 if (aggregate
->rmap
.map
== NULL
)
4238 route_map_counter_increment(map
);
4240 aggregate
->rmap
.map
= map
;
4245 if (matched
&& route_update
) {
4246 const struct prefix
*bn_p
=
4247 bgp_dest_get_prefix(bn
);
4249 if (bgp_debug_zebra(bn_p
))
4251 "Processing route_map %s(%s:%s) update on aggregate-address route %s",
4252 rmap_name
, afi2str(afi
),
4254 inet_ntop(bn_p
->family
,
4255 &bn_p
->u
.prefix
, buf
,
4257 bgp_aggregate_route(bgp
, bn_p
, afi
, safi
,
4263 /* For redistribute route-map updates. */
4264 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
4265 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
4266 struct list
*red_list
;
4267 struct bgp_redist
*red
;
4269 red_list
= bgp
->redist
[afi
][i
];
4273 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
4275 || (strcmp(rmap_name
, red
->rmap
.name
) != 0))
4279 route_map_counter_increment(map
);
4281 red
->rmap
.map
= map
;
4286 if (BGP_DEBUG(zebra
, ZEBRA
))
4288 "Processing route_map %s(%s:%s) update on redistributed routes",
4289 rmap_name
, afi2str(afi
),
4292 bgp_redistribute_resend(bgp
, afi
, i
,
4297 /* for type5 command route-maps */
4298 FOREACH_AFI_SAFI (afi
, safi
) {
4299 if (!bgp
->adv_cmd_rmap
[afi
][safi
].name
4300 || strcmp(rmap_name
, bgp
->adv_cmd_rmap
[afi
][safi
].name
)
4304 /* Make sure the route-map is populated here if not already done */
4305 bgp
->adv_cmd_rmap
[afi
][safi
].map
= map
;
4307 if (BGP_DEBUG(zebra
, ZEBRA
))
4309 "Processing route_map %s(%s:%s) update on advertise type5 route command",
4310 rmap_name
, afi2str(afi
), safi2str(safi
));
4312 if (route_update
&& advertise_type5_routes(bgp
, afi
)) {
4313 bgp_evpn_withdraw_type5_routes(bgp
, afi
, safi
);
4314 bgp_evpn_advertise_type5_routes(bgp
, afi
, safi
);
4319 static void bgp_route_map_process_update_cb(char *rmap_name
)
4321 struct listnode
*node
, *nnode
;
4324 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
)) {
4325 bgp_route_map_process_update(bgp
, rmap_name
, true);
4327 #ifdef ENABLE_BGP_VNC
4328 vnc_routemap_update(bgp
, __func__
);
4332 vpn_policy_routemap_event(rmap_name
);
4335 void bgp_route_map_update_timer(struct thread
*thread
)
4337 route_map_walk_update_list(bgp_route_map_process_update_cb
);
4340 static void bgp_route_map_mark_update(const char *rmap_name
)
4342 struct listnode
*node
, *nnode
;
4345 /* If new update is received before the current timer timed out,
4346 * turn it off and start a new timer.
4348 THREAD_OFF(bm
->t_rmap_update
);
4350 /* rmap_update_timer of 0 means don't do route updates */
4351 if (bm
->rmap_update_timer
) {
4352 thread_add_timer(bm
->master
, bgp_route_map_update_timer
,
4353 NULL
, bm
->rmap_update_timer
,
4354 &bm
->t_rmap_update
);
4356 /* Signal the groups that a route-map update event has
4358 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
4359 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
,
4360 rmap_name
, true, 1);
4362 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
)) {
4363 bgp_route_map_process_update(bgp
, rmap_name
, false);
4364 #ifdef ENABLE_BGP_VNC
4365 vnc_routemap_update(bgp
, __func__
);
4369 vpn_policy_routemap_event(rmap_name
);
4373 static void bgp_route_map_add(const char *rmap_name
)
4375 if (route_map_mark_updated(rmap_name
) == 0)
4376 bgp_route_map_mark_update(rmap_name
);
4378 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
4381 static void bgp_route_map_delete(const char *rmap_name
)
4383 if (route_map_mark_updated(rmap_name
) == 0)
4384 bgp_route_map_mark_update(rmap_name
);
4386 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_DELETED
);
4389 static void bgp_route_map_event(const char *rmap_name
)
4391 if (route_map_mark_updated(rmap_name
) == 0)
4392 bgp_route_map_mark_update(rmap_name
);
4394 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
4397 DEFUN_YANG (match_mac_address
,
4398 match_mac_address_cmd
,
4399 "match mac address ACCESSLIST_MAC_NAME",
4402 "Match address of route\n"
4403 "MAC Access-list name\n")
4406 "./match-condition[condition='frr-bgp-route-map:mac-address-list']";
4407 char xpath_value
[XPATH_MAXLEN
];
4409 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4410 snprintf(xpath_value
, sizeof(xpath_value
),
4411 "%s/rmap-match-condition/frr-bgp-route-map:list-name", xpath
);
4412 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[3]->arg
);
4414 return nb_cli_apply_changes(vty
, NULL
);
4417 DEFUN_YANG (no_match_mac_address
,
4418 no_match_mac_address_cmd
,
4419 "no match mac address ACCESSLIST_MAC_NAME",
4423 "Match address of route\n"
4424 "MAC acess-list name\n")
4427 "./match-condition[condition='frr-bgp-route-map:mac-address-list']";
4429 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4430 return nb_cli_apply_changes(vty
, NULL
);
4434 * Helper to handle the case of the user passing in a number or type string
4436 static const char *parse_evpn_rt_type(const char *num_rt_type
)
4438 switch (num_rt_type
[0]) {
4453 /* Was already full type string */
4457 DEFUN_YANG (match_evpn_route_type
,
4458 match_evpn_route_type_cmd
,
4459 "match evpn route-type <ead|1|macip|2|multicast|3|es|4|prefix|5>",
4463 EVPN_TYPE_1_HELP_STR
4464 EVPN_TYPE_1_HELP_STR
4465 EVPN_TYPE_2_HELP_STR
4466 EVPN_TYPE_2_HELP_STR
4467 EVPN_TYPE_3_HELP_STR
4468 EVPN_TYPE_3_HELP_STR
4469 EVPN_TYPE_4_HELP_STR
4470 EVPN_TYPE_4_HELP_STR
4471 EVPN_TYPE_5_HELP_STR
4472 EVPN_TYPE_5_HELP_STR
)
4475 "./match-condition[condition='frr-bgp-route-map:evpn-route-type']";
4476 char xpath_value
[XPATH_MAXLEN
];
4478 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4479 snprintf(xpath_value
, sizeof(xpath_value
),
4480 "%s/rmap-match-condition/frr-bgp-route-map:evpn-route-type",
4482 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4483 parse_evpn_rt_type(argv
[3]->arg
));
4485 return nb_cli_apply_changes(vty
, NULL
);
4488 DEFUN_YANG (no_match_evpn_route_type
,
4489 no_match_evpn_route_type_cmd
,
4490 "no match evpn route-type <ead|1|macip|2|multicast|3|es|4|prefix|5>",
4495 EVPN_TYPE_1_HELP_STR
4496 EVPN_TYPE_1_HELP_STR
4497 EVPN_TYPE_2_HELP_STR
4498 EVPN_TYPE_2_HELP_STR
4499 EVPN_TYPE_3_HELP_STR
4500 EVPN_TYPE_3_HELP_STR
4501 EVPN_TYPE_4_HELP_STR
4502 EVPN_TYPE_4_HELP_STR
4503 EVPN_TYPE_5_HELP_STR
4504 EVPN_TYPE_5_HELP_STR
)
4507 "./match-condition[condition='frr-bgp-route-map:evpn-route-type']";
4509 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4511 return nb_cli_apply_changes(vty
, NULL
);
4515 DEFUN_YANG (match_evpn_vni
,
4517 "match evpn vni " CMD_VNI_RANGE
,
4524 "./match-condition[condition='frr-bgp-route-map:evpn-vni']";
4525 char xpath_value
[XPATH_MAXLEN
];
4527 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4528 snprintf(xpath_value
, sizeof(xpath_value
),
4529 "%s/rmap-match-condition/frr-bgp-route-map:evpn-vni", xpath
);
4530 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[3]->arg
);
4532 return nb_cli_apply_changes(vty
, NULL
);
4535 DEFUN_YANG (no_match_evpn_vni
,
4536 no_match_evpn_vni_cmd
,
4537 "no match evpn vni " CMD_VNI_RANGE
,
4545 "./match-condition[condition='frr-bgp-route-map:evpn-vni']";
4546 char xpath_value
[XPATH_MAXLEN
];
4548 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4549 snprintf(xpath_value
, sizeof(xpath_value
),
4550 "%s/rmap-match-condition/frr-bgp-route-map:evpn-vni", xpath
);
4551 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_DESTROY
, argv
[3]->arg
);
4553 return nb_cli_apply_changes(vty
, NULL
);
4556 DEFUN_YANG (match_evpn_default_route
,
4557 match_evpn_default_route_cmd
,
4558 "match evpn default-route",
4561 "default EVPN type-5 route\n")
4564 "./match-condition[condition='frr-bgp-route-map:evpn-default-route']";
4565 char xpath_value
[XPATH_MAXLEN
];
4567 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4569 snprintf(xpath_value
, sizeof(xpath_value
),
4570 "%s/rmap-match-condition/frr-bgp-route-map:evpn-default-route",
4572 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, NULL
);
4574 return nb_cli_apply_changes(vty
, NULL
);
4577 DEFUN_YANG (no_match_evpn_default_route
,
4578 no_match_evpn_default_route_cmd
,
4579 "no match evpn default-route",
4583 "default EVPN type-5 route\n")
4586 "./match-condition[condition='frr-bgp-route-map:evpn-default-route']";
4588 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4590 return nb_cli_apply_changes(vty
, NULL
);
4593 DEFUN_YANG (match_evpn_rd
,
4595 "match evpn rd ASN:NN_OR_IP-ADDRESS:NN",
4598 "Route Distinguisher\n"
4599 "ASN:XX or A.B.C.D:XX\n")
4602 "./match-condition[condition='frr-bgp-route-map:evpn-rd']";
4603 char xpath_value
[XPATH_MAXLEN
];
4605 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4607 xpath_value
, sizeof(xpath_value
),
4608 "%s/rmap-match-condition/frr-bgp-route-map:route-distinguisher",
4610 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[3]->arg
);
4612 return nb_cli_apply_changes(vty
, NULL
);
4615 DEFUN_YANG (no_match_evpn_rd
,
4616 no_match_evpn_rd_cmd
,
4617 "no match evpn rd ASN:NN_OR_IP-ADDRESS:NN",
4621 "Route Distinguisher\n"
4622 "ASN:XX or A.B.C.D:XX\n")
4625 "./match-condition[condition='frr-bgp-route-map:evpn-rd']";
4627 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4628 return nb_cli_apply_changes(vty
, NULL
);
4631 DEFUN_YANG (set_evpn_gw_ip_ipv4
,
4632 set_evpn_gw_ip_ipv4_cmd
,
4633 "set evpn gateway-ip ipv4 A.B.C.D",
4636 "Set gateway IP for prefix advertisement route\n"
4638 "Gateway IP address in IPv4 format\n")
4643 "./set-action[action='frr-bgp-route-map:set-evpn-gateway-ip-ipv4']";
4644 char xpath_value
[XPATH_MAXLEN
];
4646 ret
= str2sockunion(argv
[4]->arg
, &su
);
4648 vty_out(vty
, "%% Malformed gateway IP\n");
4649 return CMD_WARNING_CONFIG_FAILED
;
4652 if (su
.sin
.sin_addr
.s_addr
== 0 ||
4653 !ipv4_unicast_valid(&su
.sin
.sin_addr
)) {
4655 "%% Gateway IP cannot be 0.0.0.0, multicast or reserved\n");
4656 return CMD_WARNING_CONFIG_FAILED
;
4659 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4661 snprintf(xpath_value
, sizeof(xpath_value
),
4662 "%s/rmap-set-action/frr-bgp-route-map:evpn-gateway-ip-ipv4",
4665 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[4]->arg
);
4666 return nb_cli_apply_changes(vty
, NULL
);
4669 DEFUN_YANG (no_set_evpn_gw_ip_ipv4
,
4670 no_set_evpn_gw_ip_ipv4_cmd
,
4671 "no set evpn gateway-ip ipv4 A.B.C.D",
4675 "Set gateway IP for prefix advertisement route\n"
4677 "Gateway IP address in IPv4 format\n")
4682 "./set-action[action='frr-bgp-route-map:set-evpn-gateway-ip-ipv4']";
4684 ret
= str2sockunion(argv
[5]->arg
, &su
);
4686 vty_out(vty
, "%% Malformed gateway IP\n");
4687 return CMD_WARNING_CONFIG_FAILED
;
4690 if (su
.sin
.sin_addr
.s_addr
== 0 ||
4691 !ipv4_unicast_valid(&su
.sin
.sin_addr
)) {
4693 "%% Gateway IP cannot be 0.0.0.0, multicast or reserved\n");
4694 return CMD_WARNING_CONFIG_FAILED
;
4697 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4699 return nb_cli_apply_changes(vty
, NULL
);
4702 DEFUN_YANG (set_evpn_gw_ip_ipv6
,
4703 set_evpn_gw_ip_ipv6_cmd
,
4704 "set evpn gateway-ip ipv6 X:X::X:X",
4707 "Set gateway IP for prefix advertisement route\n"
4709 "Gateway IP address in IPv6 format\n")
4714 "./set-action[action='frr-bgp-route-map:set-evpn-gateway-ip-ipv6']";
4715 char xpath_value
[XPATH_MAXLEN
];
4717 ret
= str2sockunion(argv
[4]->arg
, &su
);
4719 vty_out(vty
, "%% Malformed gateway IP\n");
4720 return CMD_WARNING_CONFIG_FAILED
;
4723 if (IN6_IS_ADDR_LINKLOCAL(&su
.sin6
.sin6_addr
)
4724 || IN6_IS_ADDR_MULTICAST(&su
.sin6
.sin6_addr
)) {
4726 "%% Gateway IP cannot be a linklocal or multicast address\n");
4727 return CMD_WARNING_CONFIG_FAILED
;
4730 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4732 snprintf(xpath_value
, sizeof(xpath_value
),
4733 "%s/rmap-set-action/frr-bgp-route-map:evpn-gateway-ip-ipv6",
4736 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[4]->arg
);
4737 return nb_cli_apply_changes(vty
, NULL
);
4740 DEFUN_YANG (no_set_evpn_gw_ip_ipv6
,
4741 no_set_evpn_gw_ip_ipv6_cmd
,
4742 "no set evpn gateway-ip ipv6 X:X::X:X",
4746 "Set gateway IP for prefix advertisement route\n"
4748 "Gateway IP address in IPv4 format\n")
4753 "./set-action[action='frr-bgp-route-map:set-evpn-gateway-ip-ipv6']";
4755 ret
= str2sockunion(argv
[5]->arg
, &su
);
4757 vty_out(vty
, "%% Malformed gateway IP\n");
4758 return CMD_WARNING_CONFIG_FAILED
;
4761 if (IN6_IS_ADDR_LINKLOCAL(&su
.sin6
.sin6_addr
)
4762 || IN6_IS_ADDR_MULTICAST(&su
.sin6
.sin6_addr
)) {
4764 "%% Gateway IP cannot be a linklocal or multicast address\n");
4765 return CMD_WARNING_CONFIG_FAILED
;
4768 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4770 return nb_cli_apply_changes(vty
, NULL
);
4773 DEFPY_YANG(match_vrl_source_vrf
,
4774 match_vrl_source_vrf_cmd
,
4775 "match source-vrf NAME$vrf_name",
4781 "./match-condition[condition='frr-bgp-route-map:source-vrf']";
4782 char xpath_value
[XPATH_MAXLEN
];
4784 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4785 snprintf(xpath_value
, sizeof(xpath_value
),
4786 "%s/rmap-match-condition/frr-bgp-route-map:source-vrf", xpath
);
4787 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, vrf_name
);
4789 return nb_cli_apply_changes(vty
, NULL
);
4792 DEFPY_YANG(no_match_vrl_source_vrf
,
4793 no_match_vrl_source_vrf_cmd
,
4794 "no match source-vrf NAME$vrf_name",
4800 "./match-condition[condition='frr-bgp-route-map:source-vrf']";
4802 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4803 return nb_cli_apply_changes(vty
, NULL
);
4806 DEFPY_YANG (match_peer
,
4808 "match peer <A.B.C.D$addrv4|X:X::X:X$addrv6|WORD$intf>",
4810 "Match peer address\n"
4811 "IP address of peer\n"
4812 "IPv6 address of peer\n"
4813 "Interface name of peer or peer group name\n")
4816 "./match-condition[condition='frr-bgp-route-map:peer']";
4817 char xpath_value
[XPATH_MAXLEN
];
4819 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4823 xpath_value
, sizeof(xpath_value
),
4824 "%s/rmap-match-condition/frr-bgp-route-map:peer-ipv4-address",
4826 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4828 } else if (addrv6_str
) {
4830 xpath_value
, sizeof(xpath_value
),
4831 "%s/rmap-match-condition/frr-bgp-route-map:peer-ipv6-address",
4833 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4837 xpath_value
, sizeof(xpath_value
),
4838 "%s/rmap-match-condition/frr-bgp-route-map:peer-interface",
4840 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, intf
);
4843 return nb_cli_apply_changes(vty
, NULL
);
4846 DEFUN_YANG (match_peer_local
,
4847 match_peer_local_cmd
,
4850 "Match peer address\n"
4851 "Static or Redistributed routes\n")
4854 "./match-condition[condition='frr-bgp-route-map:peer']";
4855 char xpath_value
[XPATH_MAXLEN
];
4857 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4859 snprintf(xpath_value
, sizeof(xpath_value
),
4860 "%s/rmap-match-condition/frr-bgp-route-map:peer-local", xpath
);
4861 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
4863 return nb_cli_apply_changes(vty
, NULL
);
4866 DEFUN_YANG (no_match_peer
,
4868 "no match peer [<local|A.B.C.D|X:X::X:X|WORD>]",
4871 "Match peer address\n"
4872 "Static or Redistributed routes\n"
4873 "IP address of peer\n"
4874 "IPv6 address of peer\n"
4875 "Interface name of peer\n")
4878 "./match-condition[condition='frr-bgp-route-map:peer']";
4880 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4882 return nb_cli_apply_changes(vty
, NULL
);
4885 #ifdef HAVE_SCRIPTING
4886 DEFUN_YANG (match_script
,
4888 "[no] match script WORD",
4891 "Execute script to determine match\n"
4892 "The script name to run, without .lua; e.g. 'myroutemap' to run myroutemap.lua\n")
4894 bool no
= strmatch(argv
[0]->text
, "no");
4896 argv_find(argv
, argc
, "WORD", &i
);
4897 const char *script
= argv
[i
]->arg
;
4899 "./match-condition[condition='frr-bgp-route-map:match-script']";
4900 char xpath_value
[XPATH_MAXLEN
];
4903 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4904 snprintf(xpath_value
, sizeof(xpath_value
),
4905 "%s/rmap-match-condition/frr-bgp-route-map:script",
4907 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_DESTROY
,
4910 return nb_cli_apply_changes(vty
, NULL
);
4913 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4914 snprintf(xpath_value
, sizeof(xpath_value
),
4915 "%s/rmap-match-condition/frr-bgp-route-map:script",
4917 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4920 return nb_cli_apply_changes(vty
, NULL
);
4922 #endif /* HAVE_SCRIPTING */
4924 /* match probability */
4925 DEFUN_YANG (match_probability
,
4926 match_probability_cmd
,
4927 "match probability (0-100)",
4929 "Match portion of routes defined by percentage value\n"
4930 "Percentage of routes\n")
4935 "./match-condition[condition='frr-bgp-route-map:probability']";
4936 char xpath_value
[XPATH_MAXLEN
];
4938 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4939 snprintf(xpath_value
, sizeof(xpath_value
),
4940 "%s/rmap-match-condition/frr-bgp-route-map:probability",
4942 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4943 argv
[idx_number
]->arg
);
4945 return nb_cli_apply_changes(vty
, NULL
);
4949 DEFUN_YANG (no_match_probability
,
4950 no_match_probability_cmd
,
4951 "no match probability [(1-99)]",
4954 "Match portion of routes defined by percentage value\n"
4955 "Percentage of routes\n")
4959 "./match-condition[condition='frr-bgp-route-map:probability']";
4960 char xpath_value
[XPATH_MAXLEN
];
4962 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4964 if (argc
<= idx_number
)
4965 return nb_cli_apply_changes(vty
, NULL
);
4967 snprintf(xpath_value
, sizeof(xpath_value
),
4968 "%s/rmap-match-condition/frr-bgp-route-map:probability",
4970 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_DESTROY
,
4971 argv
[idx_number
]->arg
);
4973 return nb_cli_apply_changes(vty
, NULL
);
4977 DEFPY_YANG (match_ip_route_source
,
4978 match_ip_route_source_cmd
,
4979 "match ip route-source ACCESSLIST4_NAME",
4982 "Match advertising source address of route\n"
4983 "IP Access-list name\n")
4986 "./match-condition[condition='frr-bgp-route-map:ip-route-source']";
4987 char xpath_value
[XPATH_MAXLEN
+ 32];
4990 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4991 snprintf(xpath_value
, sizeof(xpath_value
),
4992 "%s/rmap-match-condition/frr-bgp-route-map:list-name",
4994 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4995 argv
[idx_acl
]->arg
);
4997 return nb_cli_apply_changes(vty
, NULL
);
5001 DEFUN_YANG (no_match_ip_route_source
,
5002 no_match_ip_route_source_cmd
,
5003 "no match ip route-source [ACCESSLIST4_NAME]",
5007 "Match advertising source address of route\n"
5008 "IP Access-list name\n")
5011 "./match-condition[condition='frr-bgp-route-map:ip-route-source']";
5013 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5014 return nb_cli_apply_changes(vty
, NULL
);
5017 DEFUN_YANG (match_ip_route_source_prefix_list
,
5018 match_ip_route_source_prefix_list_cmd
,
5019 "match ip route-source prefix-list PREFIXLIST_NAME",
5022 "Match advertising source address of route\n"
5023 "Match entries of prefix-lists\n"
5024 "IP prefix-list name\n")
5028 "./match-condition[condition='frr-bgp-route-map:ip-route-source-prefix-list']";
5029 char xpath_value
[XPATH_MAXLEN
+ 32];
5031 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5032 snprintf(xpath_value
, sizeof(xpath_value
),
5033 "%s/rmap-match-condition/frr-bgp-route-map:list-name", xpath
);
5034 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5035 argv
[idx_word
]->arg
);
5037 return nb_cli_apply_changes(vty
, NULL
);
5041 DEFUN_YANG (no_match_ip_route_source_prefix_list
,
5042 no_match_ip_route_source_prefix_list_cmd
,
5043 "no match ip route-source prefix-list [PREFIXLIST_NAME]",
5047 "Match advertising source address of route\n"
5048 "Match entries of prefix-lists\n"
5049 "IP prefix-list name\n")
5052 "./match-condition[condition='frr-bgp-route-map:ip-route-source-prefix-list']";
5054 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5055 return nb_cli_apply_changes(vty
, NULL
);
5058 DEFUN_YANG (match_local_pref
,
5059 match_local_pref_cmd
,
5060 "match local-preference (0-4294967295)",
5062 "Match local-preference of route\n"
5068 "./match-condition[condition='frr-bgp-route-map:match-local-preference']";
5069 char xpath_value
[XPATH_MAXLEN
];
5071 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5072 snprintf(xpath_value
, sizeof(xpath_value
),
5073 "%s/rmap-match-condition/frr-bgp-route-map:local-preference",
5075 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5076 argv
[idx_number
]->arg
);
5078 return nb_cli_apply_changes(vty
, NULL
);
5082 DEFUN_YANG (no_match_local_pref
,
5083 no_match_local_pref_cmd
,
5084 "no match local-preference [(0-4294967295)]",
5087 "Match local preference of route\n"
5088 "Local preference value\n")
5090 int idx_localpref
= 3;
5092 "./match-condition[condition='frr-bgp-route-map:match-local-preference']";
5093 char xpath_value
[XPATH_MAXLEN
];
5095 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5097 if (argc
<= idx_localpref
)
5098 return nb_cli_apply_changes(vty
, NULL
);
5100 snprintf(xpath_value
, sizeof(xpath_value
),
5101 "%s/rmap-match-condition/frr-bgp-route-map:local-preference",
5103 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_DESTROY
,
5104 argv
[idx_localpref
]->arg
);
5106 return nb_cli_apply_changes(vty
, NULL
);
5109 DEFUN_YANG(match_alias
, match_alias_cmd
, "match alias ALIAS_NAME",
5111 "Match BGP community alias name\n"
5112 "BGP community alias name\n")
5114 const char *alias
= argv
[2]->arg
;
5115 struct community_alias ca1
;
5116 struct community_alias
*lookup_alias
;
5119 "./match-condition[condition='frr-bgp-route-map:match-alias']";
5120 char xpath_value
[XPATH_MAXLEN
];
5122 memset(&ca1
, 0, sizeof(ca1
));
5123 strlcpy(ca1
.alias
, alias
, sizeof(ca1
.alias
));
5124 lookup_alias
= bgp_ca_alias_lookup(&ca1
);
5125 if (!lookup_alias
) {
5126 vty_out(vty
, "%% BGP alias name '%s' does not exist\n", alias
);
5127 return CMD_WARNING_CONFIG_FAILED
;
5130 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5131 snprintf(xpath_value
, sizeof(xpath_value
),
5132 "%s/rmap-match-condition/frr-bgp-route-map:alias", xpath
);
5133 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, alias
);
5135 return nb_cli_apply_changes(vty
, NULL
);
5139 DEFUN_YANG(no_match_alias
, no_match_alias_cmd
, "no match alias [ALIAS_NAME]",
5141 "Match BGP community alias name\n"
5142 "BGP community alias name\n")
5146 "./match-condition[condition='frr-bgp-route-map:match-alias']";
5147 char xpath_value
[XPATH_MAXLEN
];
5149 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5151 if (argc
<= idx_alias
)
5152 return nb_cli_apply_changes(vty
, NULL
);
5154 snprintf(xpath_value
, sizeof(xpath_value
),
5155 "%s/rmap-match-condition/frr-bgp-route-map:alias", xpath
);
5156 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_DESTROY
,
5157 argv
[idx_alias
]->arg
);
5159 return nb_cli_apply_changes(vty
, NULL
);
5162 DEFPY_YANG (match_community
,
5163 match_community_cmd
,
5164 "match community <(1-99)|(100-500)|COMMUNITY_LIST_NAME> [exact-match]",
5166 "Match BGP community list\n"
5167 "Community-list number (standard)\n"
5168 "Community-list number (expanded)\n"
5169 "Community-list name\n"
5170 "Do exact matching of communities\n")
5173 "./match-condition[condition='frr-bgp-route-map:match-community']";
5174 char xpath_value
[XPATH_MAXLEN
];
5175 char xpath_match
[XPATH_MAXLEN
];
5176 int idx_comm_list
= 2;
5178 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5181 xpath_value
, sizeof(xpath_value
),
5182 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name",
5184 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[idx_comm_list
]->arg
);
5188 xpath_match
, sizeof(xpath_match
),
5189 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match",
5191 nb_cli_enqueue_change(vty
, xpath_match
, NB_OP_MODIFY
,
5195 xpath_match
, sizeof(xpath_match
),
5196 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match",
5198 nb_cli_enqueue_change(vty
, xpath_match
, NB_OP_MODIFY
,
5202 return nb_cli_apply_changes(vty
, NULL
);
5205 DEFUN_YANG (no_match_community
,
5206 no_match_community_cmd
,
5207 "no match community [<(1-99)|(100-500)|COMMUNITY_LIST_NAME> [exact-match]]",
5210 "Match BGP community list\n"
5211 "Community-list number (standard)\n"
5212 "Community-list number (expanded)\n"
5213 "Community-list name\n"
5214 "Do exact matching of communities\n")
5217 "./match-condition[condition='frr-bgp-route-map:match-community']";
5219 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5220 return nb_cli_apply_changes(vty
, NULL
);
5223 DEFPY_YANG (match_lcommunity
,
5224 match_lcommunity_cmd
,
5225 "match large-community <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME> [exact-match]",
5227 "Match BGP large community list\n"
5228 "Large Community-list number (standard)\n"
5229 "Large Community-list number (expanded)\n"
5230 "Large Community-list name\n"
5231 "Do exact matching of communities\n")
5234 "./match-condition[condition='frr-bgp-route-map:match-large-community']";
5235 char xpath_value
[XPATH_MAXLEN
];
5236 char xpath_match
[XPATH_MAXLEN
];
5237 int idx_lcomm_list
= 2;
5239 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5242 xpath_value
, sizeof(xpath_value
),
5243 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name",
5245 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[idx_lcomm_list
]->arg
);
5249 xpath_match
, sizeof(xpath_match
),
5250 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match",
5252 nb_cli_enqueue_change(vty
, xpath_match
, NB_OP_MODIFY
,
5256 xpath_match
, sizeof(xpath_match
),
5257 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match",
5259 nb_cli_enqueue_change(vty
, xpath_match
, NB_OP_MODIFY
,
5263 return nb_cli_apply_changes(vty
, NULL
);
5266 DEFUN_YANG (no_match_lcommunity
,
5267 no_match_lcommunity_cmd
,
5268 "no match large-community [<(1-99)|(100-500)|LCOMMUNITY_LIST_NAME> [exact-match]]",
5271 "Match BGP large community list\n"
5272 "Large Community-list number (standard)\n"
5273 "Large Community-list number (expanded)\n"
5274 "Large Community-list name\n"
5275 "Do exact matching of communities\n")
5278 "./match-condition[condition='frr-bgp-route-map:match-large-community']";
5280 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5281 return nb_cli_apply_changes(vty
, NULL
);
5284 DEFPY_YANG (match_ecommunity
,
5285 match_ecommunity_cmd
,
5286 "match extcommunity <(1-99)|(100-500)|EXTCOMMUNITY_LIST_NAME>",
5288 "Match BGP/VPN extended community list\n"
5289 "Extended community-list number (standard)\n"
5290 "Extended community-list number (expanded)\n"
5291 "Extended community-list name\n")
5294 "./match-condition[condition='frr-bgp-route-map:match-extcommunity']";
5295 char xpath_value
[XPATH_MAXLEN
];
5296 int idx_comm_list
= 2;
5298 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5301 xpath_value
, sizeof(xpath_value
),
5302 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name",
5304 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[idx_comm_list
]->arg
);
5306 return nb_cli_apply_changes(vty
, NULL
);
5310 DEFUN_YANG (no_match_ecommunity
,
5311 no_match_ecommunity_cmd
,
5312 "no match extcommunity [<(1-99)|(100-500)|EXTCOMMUNITY_LIST_NAME>]",
5315 "Match BGP/VPN extended community list\n"
5316 "Extended community-list number (standard)\n"
5317 "Extended community-list number (expanded)\n"
5318 "Extended community-list name\n")
5321 "./match-condition[condition='frr-bgp-route-map:match-extcommunity']";
5323 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5324 return nb_cli_apply_changes(vty
, NULL
);
5328 DEFUN_YANG (match_aspath
,
5330 "match as-path AS_PATH_FILTER_NAME",
5332 "Match BGP AS path list\n"
5333 "AS path access-list name\n")
5338 "./match-condition[condition='frr-bgp-route-map:as-path-list']";
5339 char xpath_value
[XPATH_MAXLEN
];
5341 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5342 snprintf(xpath_value
, sizeof(xpath_value
),
5343 "%s/rmap-match-condition/frr-bgp-route-map:list-name", xpath
);
5344 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5345 argv
[idx_word
]->arg
);
5347 return nb_cli_apply_changes(vty
, NULL
);
5351 DEFUN_YANG (no_match_aspath
,
5352 no_match_aspath_cmd
,
5353 "no match as-path [AS_PATH_FILTER_NAME]",
5356 "Match BGP AS path list\n"
5357 "AS path access-list name\n")
5360 "./match-condition[condition='frr-bgp-route-map:as-path-list']";
5362 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5364 return nb_cli_apply_changes(vty
, NULL
);
5367 DEFUN_YANG (match_origin
,
5369 "match origin <egp|igp|incomplete>",
5374 "unknown heritage\n")
5377 const char *origin_type
;
5379 "./match-condition[condition='frr-bgp-route-map:match-origin']";
5380 char xpath_value
[XPATH_MAXLEN
];
5382 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
5383 origin_type
= "igp";
5384 else if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
5385 origin_type
= "egp";
5386 else if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
5387 origin_type
= "incomplete";
5389 vty_out(vty
, "%% Invalid match origin type\n");
5390 return CMD_WARNING_CONFIG_FAILED
;
5393 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5394 snprintf(xpath_value
, sizeof(xpath_value
),
5395 "%s/rmap-match-condition/frr-bgp-route-map:origin", xpath
);
5396 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, origin_type
);
5398 return nb_cli_apply_changes(vty
, NULL
);
5402 DEFUN_YANG (no_match_origin
,
5403 no_match_origin_cmd
,
5404 "no match origin [<egp|igp|incomplete>]",
5410 "unknown heritage\n")
5413 "./match-condition[condition='frr-bgp-route-map:match-origin']";
5414 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5415 return nb_cli_apply_changes(vty
, NULL
);
5418 DEFUN_YANG (set_table_id
,
5420 "set table (1-4294967295)",
5422 "export route to non-main kernel table\n"
5423 "Kernel routing table id\n")
5426 const char *xpath
= "./set-action[action='frr-bgp-route-map:table']";
5427 char xpath_value
[XPATH_MAXLEN
];
5429 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5430 snprintf(xpath_value
, sizeof(xpath_value
),
5431 "%s/rmap-set-action/frr-bgp-route-map:table", xpath
);
5432 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5433 argv
[idx_number
]->arg
);
5434 return nb_cli_apply_changes(vty
, NULL
);
5437 DEFUN_YANG (no_set_table_id
,
5438 no_set_table_id_cmd
,
5442 "export route to non-main kernel table\n")
5444 const char *xpath
= "./set-action[action='frr-bgp-route-map:table']";
5445 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5446 return nb_cli_apply_changes(vty
, NULL
);
5449 DEFUN_YANG (set_ip_nexthop_peer
,
5450 set_ip_nexthop_peer_cmd
,
5451 "[no] set ip next-hop peer-address",
5455 "Next hop address\n"
5456 "Use peer address (for BGP only)\n")
5458 char xpath_value
[XPATH_MAXLEN
];
5460 "./set-action[action='frr-bgp-route-map:set-ipv4-nexthop']";
5462 if (strmatch(argv
[0]->text
, "no"))
5463 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5465 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5466 snprintf(xpath_value
, sizeof(xpath_value
),
5467 "%s/rmap-set-action/frr-bgp-route-map:ipv4-nexthop",
5469 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5472 return nb_cli_apply_changes(vty
, NULL
);
5475 DEFUN_YANG (set_ip_nexthop_unchanged
,
5476 set_ip_nexthop_unchanged_cmd
,
5477 "[no] set ip next-hop unchanged",
5481 "Next hop address\n"
5482 "Don't modify existing Next hop address\n")
5484 char xpath_value
[XPATH_MAXLEN
];
5486 "./set-action[action='frr-bgp-route-map:set-ipv4-nexthop']";
5488 if (strmatch(argv
[0]->text
, "no"))
5489 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5491 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5492 snprintf(xpath_value
, sizeof(xpath_value
),
5493 "%s/rmap-set-action/frr-bgp-route-map:ipv4-nexthop",
5495 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5498 return nb_cli_apply_changes(vty
, NULL
);
5501 DEFUN_YANG (set_distance
,
5503 "set distance (0-255)",
5505 "BGP Administrative Distance to use\n"
5509 const char *xpath
= "./set-action[action='frr-bgp-route-map:distance']";
5510 char xpath_value
[XPATH_MAXLEN
];
5512 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5513 snprintf(xpath_value
, sizeof(xpath_value
),
5514 "%s/rmap-set-action/frr-bgp-route-map:distance", xpath
);
5515 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5516 argv
[idx_number
]->arg
);
5517 return nb_cli_apply_changes(vty
, NULL
);
5520 DEFUN_YANG (no_set_distance
,
5521 no_set_distance_cmd
,
5522 "no set distance [(0-255)]",
5524 "BGP Administrative Distance to use\n"
5527 const char *xpath
= "./set-action[action='frr-bgp-route-map:distance']";
5529 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5530 return nb_cli_apply_changes(vty
, NULL
);
5533 DEFPY_YANG(set_l3vpn_nexthop_encapsulation
, set_l3vpn_nexthop_encapsulation_cmd
,
5534 "[no] set l3vpn next-hop encapsulation gre",
5536 "L3VPN operations\n"
5537 "Next hop Information\n"
5538 "Encapsulation options (for BGP only)\n"
5539 "Accept L3VPN traffic over GRE encapsulation\n")
5542 "./set-action[action='frr-bgp-route-map:set-l3vpn-nexthop-encapsulation']";
5543 const char *xpath_value
=
5544 "./set-action[action='frr-bgp-route-map:set-l3vpn-nexthop-encapsulation']/rmap-set-action/frr-bgp-route-map:l3vpn-nexthop-encapsulation";
5545 enum nb_operation operation
;
5548 operation
= NB_OP_DESTROY
;
5550 operation
= NB_OP_CREATE
;
5552 nb_cli_enqueue_change(vty
, xpath
, operation
, NULL
);
5553 if (operation
== NB_OP_DESTROY
)
5554 return nb_cli_apply_changes(vty
, NULL
);
5556 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "gre");
5558 return nb_cli_apply_changes(vty
, NULL
);
5561 DEFUN_YANG (set_local_pref
,
5563 "set local-preference WORD",
5565 "BGP local preference path attribute\n"
5566 "Preference value (0-4294967295)\n")
5570 "./set-action[action='frr-bgp-route-map:set-local-preference']";
5571 char xpath_value
[XPATH_MAXLEN
];
5573 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5574 snprintf(xpath_value
, sizeof(xpath_value
),
5575 "%s/rmap-set-action/frr-bgp-route-map:local-pref", xpath
);
5576 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5577 argv
[idx_number
]->arg
);
5578 return nb_cli_apply_changes(vty
, NULL
);
5581 DEFUN_YANG (no_set_local_pref
,
5582 no_set_local_pref_cmd
,
5583 "no set local-preference [WORD]",
5586 "BGP local preference path attribute\n"
5587 "Preference value (0-4294967295)\n")
5590 "./set-action[action='frr-bgp-route-map:set-local-preference']";
5592 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5593 return nb_cli_apply_changes(vty
, NULL
);
5596 DEFUN_YANG (set_weight
,
5598 "set weight (0-4294967295)",
5600 "BGP weight for routing table\n"
5604 const char *xpath
= "./set-action[action='frr-bgp-route-map:weight']";
5605 char xpath_value
[XPATH_MAXLEN
];
5607 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5608 snprintf(xpath_value
, sizeof(xpath_value
),
5609 "%s/rmap-set-action/frr-bgp-route-map:weight", xpath
);
5610 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5611 argv
[idx_number
]->arg
);
5612 return nb_cli_apply_changes(vty
, NULL
);
5615 DEFUN_YANG (no_set_weight
,
5617 "no set weight [(0-4294967295)]",
5620 "BGP weight for routing table\n"
5623 const char *xpath
= "./set-action[action='frr-bgp-route-map:weight']";
5625 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5626 return nb_cli_apply_changes(vty
, NULL
);
5629 DEFUN_YANG (set_label_index
,
5630 set_label_index_cmd
,
5631 "set label-index (0-1048560)",
5633 "Label index to associate with the prefix\n"
5634 "Label index value\n")
5638 "./set-action[action='frr-bgp-route-map:label-index']";
5639 char xpath_value
[XPATH_MAXLEN
];
5641 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5642 snprintf(xpath_value
, sizeof(xpath_value
),
5643 "%s/rmap-set-action/frr-bgp-route-map:label-index", xpath
);
5644 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5645 argv
[idx_number
]->arg
);
5646 return nb_cli_apply_changes(vty
, NULL
);
5649 DEFUN_YANG (no_set_label_index
,
5650 no_set_label_index_cmd
,
5651 "no set label-index [(0-1048560)]",
5654 "Label index to associate with the prefix\n"
5655 "Label index value\n")
5658 "./set-action[action='frr-bgp-route-map:label-index']";
5660 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5661 return nb_cli_apply_changes(vty
, NULL
);
5664 DEFUN_YANG (set_aspath_prepend_asn
,
5665 set_aspath_prepend_asn_cmd
,
5666 "set as-path prepend ASNUM...",
5668 "Transform BGP AS_PATH attribute\n"
5669 "Prepend to the as-path\n"
5675 struct aspath
*aspath
;
5677 str
= argv_concat(argv
, argc
, idx_asn
);
5680 "./set-action[action='frr-bgp-route-map:as-path-prepend']";
5681 char xpath_value
[XPATH_MAXLEN
];
5683 aspath
= route_aspath_compile(str
);
5685 vty_out(vty
, "%% Invalid AS path value %s\n", str
);
5686 return CMD_WARNING_CONFIG_FAILED
;
5688 route_aspath_free(aspath
);
5689 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5690 snprintf(xpath_value
, sizeof(xpath_value
),
5691 "%s/rmap-set-action/frr-bgp-route-map:prepend-as-path", xpath
);
5692 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
5693 ret
= nb_cli_apply_changes(vty
, NULL
);
5694 XFREE(MTYPE_TMP
, str
);
5698 DEFUN_YANG (set_aspath_prepend_lastas
,
5699 set_aspath_prepend_lastas_cmd
,
5700 "set as-path prepend last-as (1-10)",
5702 "Transform BGP AS_PATH attribute\n"
5703 "Prepend to the as-path\n"
5704 "Use the last AS-number in the as-path\n"
5705 "Number of times to insert\n")
5710 "./set-action[action='frr-bgp-route-map:as-path-prepend']";
5711 char xpath_value
[XPATH_MAXLEN
];
5713 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5714 snprintf(xpath_value
, sizeof(xpath_value
),
5715 "%s/rmap-set-action/frr-bgp-route-map:last-as", xpath
);
5716 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5717 argv
[idx_num
]->arg
);
5718 return nb_cli_apply_changes(vty
, NULL
);
5721 DEFPY_YANG (set_aspath_replace_asn
,
5722 set_aspath_replace_asn_cmd
,
5723 "set as-path replace <any|ASNUM>$replace",
5725 "Transform BGP AS_PATH attribute\n"
5726 "Replace AS number to local AS number\n"
5727 "Replace any AS number to local AS number\n"
5728 "Replace a specific AS number in plain or dotted format to local AS number\n")
5731 "./set-action[action='frr-bgp-route-map:as-path-replace']";
5732 char xpath_value
[XPATH_MAXLEN
];
5735 if (!strmatch(replace
, "any") && !asn_str2asn(replace
, &as_value
)) {
5736 vty_out(vty
, "%% Invalid AS value %s\n", replace
);
5737 return CMD_WARNING_CONFIG_FAILED
;
5740 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5741 snprintf(xpath_value
, sizeof(xpath_value
),
5742 "%s/rmap-set-action/frr-bgp-route-map:replace-as-path", xpath
);
5743 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, replace
);
5744 return nb_cli_apply_changes(vty
, NULL
);
5747 DEFPY_YANG (no_set_aspath_replace_asn
,
5748 no_set_aspath_replace_asn_cmd
,
5749 "no set as-path replace [<any|ASNUM>]",
5752 "Transform BGP AS_PATH attribute\n"
5753 "Replace AS number to local AS number\n"
5754 "Replace any AS number to local AS number\n"
5755 "Replace a specific AS number in plain or dotted format to local AS number\n")
5758 "./set-action[action='frr-bgp-route-map:as-path-replace']";
5760 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5761 return nb_cli_apply_changes(vty
, NULL
);
5764 DEFUN_YANG (no_set_aspath_prepend
,
5765 no_set_aspath_prepend_cmd
,
5766 "no set as-path prepend [ASNUM]",
5769 "Transform BGP AS_PATH attribute\n"
5770 "Prepend to the as-path\n"
5774 "./set-action[action='frr-bgp-route-map:as-path-prepend']";
5776 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5777 return nb_cli_apply_changes(vty
, NULL
);
5780 DEFUN_YANG (no_set_aspath_prepend_lastas
,
5781 no_set_aspath_prepend_lastas_cmd
,
5782 "no set as-path prepend last-as [(1-10)]",
5785 "Transform BGP AS_PATH attribute\n"
5786 "Prepend to the as-path\n"
5787 "Use the peers AS-number\n"
5788 "Number of times to insert\n")
5791 "./set-action[action='frr-bgp-route-map:as-path-prepend']";
5793 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5794 return nb_cli_apply_changes(vty
, NULL
);
5797 DEFUN_YANG (set_aspath_exclude
,
5798 set_aspath_exclude_cmd
,
5799 "set as-path exclude ASNUM...",
5801 "Transform BGP AS-path attribute\n"
5802 "Exclude from the as-path\n"
5808 struct aspath
*aspath
;
5810 str
= argv_concat(argv
, argc
, idx_asn
);
5813 "./set-action[action='frr-bgp-route-map:as-path-exclude']";
5814 char xpath_value
[XPATH_MAXLEN
];
5816 aspath
= route_aspath_compile(str
);
5818 vty_out(vty
, "%% Invalid AS path value %s\n", str
);
5819 return CMD_WARNING_CONFIG_FAILED
;
5821 route_aspath_free(aspath
);
5822 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5823 snprintf(xpath_value
, sizeof(xpath_value
),
5824 "%s/rmap-set-action/frr-bgp-route-map:exclude-as-path", xpath
);
5825 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
5826 ret
= nb_cli_apply_changes(vty
, NULL
);
5827 XFREE(MTYPE_TMP
, str
);
5831 DEFUN_YANG (no_set_aspath_exclude
,
5832 no_set_aspath_exclude_cmd
,
5833 "no set as-path exclude ASNUM...",
5836 "Transform BGP AS_PATH attribute\n"
5837 "Exclude from the as-path\n"
5841 "./set-action[action='frr-bgp-route-map:as-path-exclude']";
5843 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5844 return nb_cli_apply_changes(vty
, NULL
);
5847 ALIAS_YANG (no_set_aspath_exclude
, no_set_aspath_exclude_all_cmd
,
5848 "no set as-path exclude",
5850 "Transform BGP AS_PATH attribute\n"
5851 "Exclude from the as-path\n")
5853 DEFUN_YANG (set_community
,
5855 "set community AA:NN...",
5857 "BGP community attribute\n"
5865 struct community
*com
= NULL
;
5867 char *argstr
= NULL
;
5871 "./set-action[action='frr-bgp-route-map:set-community']";
5872 char xpath_value
[XPATH_MAXLEN
];
5874 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5875 snprintf(xpath_value
, sizeof(xpath_value
),
5876 "%s/rmap-set-action/frr-bgp-route-map:community-string",
5879 b
= buffer_new(1024);
5881 for (i
= idx_aa_nn
; i
< argc
; i
++) {
5882 if (strncmp(argv
[i
]->arg
, "additive", strlen(argv
[i
]->arg
))
5889 buffer_putc(b
, ' ');
5893 if (strncmp(argv
[i
]->arg
, "internet", strlen(argv
[i
]->arg
))
5895 buffer_putstr(b
, "internet");
5898 if (strncmp(argv
[i
]->arg
, "local-AS", strlen(argv
[i
]->arg
))
5900 buffer_putstr(b
, "local-AS");
5903 if (strncmp(argv
[i
]->arg
, "no-a", strlen("no-a")) == 0
5904 && strncmp(argv
[i
]->arg
, "no-advertise",
5905 strlen(argv
[i
]->arg
))
5907 buffer_putstr(b
, "no-advertise");
5910 if (strncmp(argv
[i
]->arg
, "no-e", strlen("no-e")) == 0
5911 && strncmp(argv
[i
]->arg
, "no-export", strlen(argv
[i
]->arg
))
5913 buffer_putstr(b
, "no-export");
5916 if (strncmp(argv
[i
]->arg
, "blackhole", strlen(argv
[i
]->arg
))
5918 buffer_putstr(b
, "blackhole");
5921 if (strncmp(argv
[i
]->arg
, "graceful-shutdown",
5922 strlen(argv
[i
]->arg
))
5924 buffer_putstr(b
, "graceful-shutdown");
5927 buffer_putstr(b
, argv
[i
]->arg
);
5929 buffer_putc(b
, '\0');
5931 /* Fetch result string then compile it to communities attribute. */
5932 str
= buffer_getstr(b
);
5936 com
= community_str2com(str
);
5938 /* Can't compile user input into communities attribute. */
5940 vty_out(vty
, "%% Malformed communities attribute '%s'\n", str
);
5941 XFREE(MTYPE_TMP
, str
);
5942 return CMD_WARNING_CONFIG_FAILED
;
5944 XFREE(MTYPE_TMP
, str
);
5946 /* Set communites attribute string. */
5947 str
= community_str(com
, false, false);
5950 size_t argstr_sz
= strlen(str
) + strlen(" additive") + 1;
5951 argstr
= XCALLOC(MTYPE_TMP
, argstr_sz
);
5952 strlcpy(argstr
, str
, argstr_sz
);
5953 strlcat(argstr
, " additive", argstr_sz
);
5954 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argstr
);
5956 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
5958 ret
= nb_cli_apply_changes(vty
, NULL
);
5961 XFREE(MTYPE_TMP
, argstr
);
5962 community_free(&com
);
5967 DEFUN_YANG (set_community_none
,
5968 set_community_none_cmd
,
5969 "set community none",
5971 "BGP community attribute\n"
5972 "No community attribute\n")
5975 "./set-action[action='frr-bgp-route-map:set-community']";
5976 char xpath_value
[XPATH_MAXLEN
];
5978 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5980 snprintf(xpath_value
, sizeof(xpath_value
),
5981 "%s/rmap-set-action/frr-bgp-route-map:community-none", xpath
);
5982 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
5983 return nb_cli_apply_changes(vty
, NULL
);
5986 DEFUN_YANG (no_set_community
,
5987 no_set_community_cmd
,
5988 "no set community AA:NN...",
5991 "BGP community attribute\n"
5995 "./set-action[action='frr-bgp-route-map:set-community']";
5997 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5998 return nb_cli_apply_changes(vty
, NULL
);
6001 ALIAS_YANG (no_set_community
,
6002 no_set_community_short_cmd
,
6006 "BGP community attribute\n")
6008 DEFPY_YANG (set_community_delete
,
6009 set_community_delete_cmd
,
6010 "set comm-list <(1-99)|(100-500)|COMMUNITY_LIST_NAME> delete",
6012 "set BGP community list (for deletion)\n"
6013 "Community-list number (standard)\n"
6014 "Community-list number (expanded)\n"
6015 "Community-list name\n"
6016 "Delete matching communities\n")
6019 "./set-action[action='frr-bgp-route-map:comm-list-delete']";
6020 char xpath_value
[XPATH_MAXLEN
];
6021 int idx_comm_list
= 2;
6023 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6025 snprintf(xpath_value
, sizeof(xpath_value
),
6026 "%s/rmap-set-action/frr-bgp-route-map:comm-list-name",
6028 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6029 argv
[idx_comm_list
]->arg
);
6031 return nb_cli_apply_changes(vty
, NULL
);
6035 DEFUN_YANG (no_set_community_delete
,
6036 no_set_community_delete_cmd
,
6037 "no set comm-list [<(1-99)|(100-500)|COMMUNITY_LIST_NAME> delete]",
6040 "set BGP community list (for deletion)\n"
6041 "Community-list number (standard)\n"
6042 "Community-list number (expanded)\n"
6043 "Community-list name\n"
6044 "Delete matching communities\n")
6047 "./set-action[action='frr-bgp-route-map:comm-list-delete']";
6049 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6050 return nb_cli_apply_changes(vty
, NULL
);
6053 DEFUN_YANG (set_lcommunity
,
6055 "set large-community AA:BB:CC...",
6057 "BGP large community attribute\n"
6058 "Large Community number in aa:bb:cc format or additive\n")
6063 "./set-action[action='frr-bgp-route-map:set-large-community']";
6064 char xpath_value
[XPATH_MAXLEN
];
6066 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6068 snprintf(xpath_value
, sizeof(xpath_value
),
6069 "%s/rmap-set-action/frr-bgp-route-map:large-community-string",
6071 str
= argv_concat(argv
, argc
, 2);
6072 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
6073 ret
= nb_cli_apply_changes(vty
, NULL
);
6074 XFREE(MTYPE_TMP
, str
);
6078 DEFUN_YANG (set_lcommunity_none
,
6079 set_lcommunity_none_cmd
,
6080 "set large-community none",
6082 "BGP large community attribute\n"
6083 "No large community attribute\n")
6086 "./set-action[action='frr-bgp-route-map:set-large-community']";
6087 char xpath_value
[XPATH_MAXLEN
];
6089 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6091 snprintf(xpath_value
, sizeof(xpath_value
),
6092 "%s/rmap-set-action/frr-bgp-route-map:large-community-none",
6094 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
6095 return nb_cli_apply_changes(vty
, NULL
);
6098 DEFUN_YANG (no_set_lcommunity
,
6099 no_set_lcommunity_cmd
,
6100 "no set large-community none",
6103 "BGP large community attribute\n"
6104 "No community attribute\n")
6107 "./set-action[action='frr-bgp-route-map:set-large-community']";
6109 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6110 return nb_cli_apply_changes(vty
, NULL
);
6113 DEFUN_YANG (no_set_lcommunity1
,
6114 no_set_lcommunity1_cmd
,
6115 "no set large-community AA:BB:CC...",
6118 "BGP large community attribute\n"
6119 "Large community in AA:BB:CC... format or additive\n")
6122 "./set-action[action='frr-bgp-route-map:set-large-community']";
6124 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6125 return nb_cli_apply_changes(vty
, NULL
);
6128 ALIAS_YANG (no_set_lcommunity1
,
6129 no_set_lcommunity1_short_cmd
,
6130 "no set large-community",
6133 "BGP large community attribute\n")
6135 DEFPY_YANG (set_lcommunity_delete
,
6136 set_lcommunity_delete_cmd
,
6137 "set large-comm-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME> delete",
6139 "set BGP large community list (for deletion)\n"
6140 "Large Community-list number (standard)\n"
6141 "Large Communitly-list number (expanded)\n"
6142 "Large Community-list name\n"
6143 "Delete matching large communities\n")
6146 "./set-action[action='frr-bgp-route-map:large-comm-list-delete']";
6147 char xpath_value
[XPATH_MAXLEN
];
6148 int idx_lcomm_list
= 2;
6150 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6152 snprintf(xpath_value
, sizeof(xpath_value
),
6153 "%s/rmap-set-action/frr-bgp-route-map:comm-list-name",
6155 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6156 argv
[idx_lcomm_list
]->arg
);
6158 return nb_cli_apply_changes(vty
, NULL
);
6161 DEFUN_YANG (no_set_lcommunity_delete
,
6162 no_set_lcommunity_delete_cmd
,
6163 "no set large-comm-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME> [delete]",
6166 "set BGP large community list (for deletion)\n"
6167 "Large Community-list number (standard)\n"
6168 "Large Communitly-list number (expanded)\n"
6169 "Large Community-list name\n"
6170 "Delete matching large communities\n")
6173 "./set-action[action='frr-bgp-route-map:large-comm-list-delete']";
6175 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6176 return nb_cli_apply_changes(vty
, NULL
);
6179 ALIAS_YANG (no_set_lcommunity_delete
,
6180 no_set_lcommunity_delete_short_cmd
,
6181 "no set large-comm-list",
6184 "set BGP large community list (for deletion)\n")
6186 DEFUN_YANG (set_ecommunity_rt
,
6187 set_ecommunity_rt_cmd
,
6188 "set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
6190 "BGP extended community attribute\n"
6191 "Route Target extended community\n"
6192 "VPN extended community\n")
6198 "./set-action[action='frr-bgp-route-map:set-extcommunity-rt']";
6199 char xpath_value
[XPATH_MAXLEN
];
6201 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6203 snprintf(xpath_value
, sizeof(xpath_value
),
6204 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-rt", xpath
);
6205 str
= argv_concat(argv
, argc
, idx_asn_nn
);
6206 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
6207 ret
= nb_cli_apply_changes(vty
, NULL
);
6208 XFREE(MTYPE_TMP
, str
);
6212 DEFUN_YANG (no_set_ecommunity_rt
,
6213 no_set_ecommunity_rt_cmd
,
6214 "no set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
6217 "BGP extended community attribute\n"
6218 "Route Target extended community\n"
6219 "VPN extended community\n")
6222 "./set-action[action='frr-bgp-route-map:set-extcommunity-rt']";
6223 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6224 return nb_cli_apply_changes(vty
, NULL
);
6227 ALIAS_YANG (no_set_ecommunity_rt
,
6228 no_set_ecommunity_rt_short_cmd
,
6229 "no set extcommunity rt",
6232 "BGP extended community attribute\n"
6233 "Route Target extended community\n")
6235 DEFUN_YANG (set_ecommunity_soo
,
6236 set_ecommunity_soo_cmd
,
6237 "set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
6239 "BGP extended community attribute\n"
6240 "Site-of-Origin extended community\n"
6241 "VPN extended community\n")
6247 "./set-action[action='frr-bgp-route-map:set-extcommunity-soo']";
6248 char xpath_value
[XPATH_MAXLEN
];
6250 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6252 snprintf(xpath_value
, sizeof(xpath_value
),
6253 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-soo",
6255 str
= argv_concat(argv
, argc
, idx_asn_nn
);
6256 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
6257 ret
= nb_cli_apply_changes(vty
, NULL
);
6258 XFREE(MTYPE_TMP
, str
);
6262 DEFUN_YANG (no_set_ecommunity_soo
,
6263 no_set_ecommunity_soo_cmd
,
6264 "no set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
6267 "BGP extended community attribute\n"
6268 "Site-of-Origin extended community\n"
6269 "VPN extended community\n")
6272 "./set-action[action='frr-bgp-route-map:set-extcommunity-soo']";
6273 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6274 return nb_cli_apply_changes(vty
, NULL
);
6277 ALIAS_YANG (no_set_ecommunity_soo
,
6278 no_set_ecommunity_soo_short_cmd
,
6279 "no set extcommunity soo",
6282 "GP extended community attribute\n"
6283 "Site-of-Origin extended community\n")
6285 DEFUN_YANG(set_ecommunity_none
, set_ecommunity_none_cmd
,
6286 "set extcommunity none",
6288 "BGP extended community attribute\n"
6289 "No extended community attribute\n")
6292 "./set-action[action='frr-bgp-route-map:set-extcommunity-none']";
6293 char xpath_value
[XPATH_MAXLEN
];
6295 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6297 snprintf(xpath_value
, sizeof(xpath_value
),
6298 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-none",
6300 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
6301 return nb_cli_apply_changes(vty
, NULL
);
6304 DEFUN_YANG(no_set_ecommunity_none
, no_set_ecommunity_none_cmd
,
6305 "no set extcommunity none",
6307 "BGP extended community attribute\n"
6308 "No extended community attribute\n")
6311 "./set-action[action='frr-bgp-route-map:set-extcommunity-none']";
6312 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6313 return nb_cli_apply_changes(vty
, NULL
);
6316 DEFUN_YANG (set_ecommunity_lb
,
6317 set_ecommunity_lb_cmd
,
6318 "set extcommunity bandwidth <(1-25600)|cumulative|num-multipaths> [non-transitive]",
6320 "BGP extended community attribute\n"
6321 "Link bandwidth extended community\n"
6322 "Bandwidth value in Mbps\n"
6323 "Cumulative bandwidth of all multipaths (outbound-only)\n"
6324 "Internally computed bandwidth based on number of multipaths (outbound-only)\n"
6325 "Attribute is set as non-transitive\n")
6328 int idx_non_transitive
= 0;
6330 "./set-action[action='frr-bgp-route-map:set-extcommunity-lb']";
6331 char xpath_lb_type
[XPATH_MAXLEN
];
6332 char xpath_bandwidth
[XPATH_MAXLEN
];
6333 char xpath_non_transitive
[XPATH_MAXLEN
];
6335 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6337 snprintf(xpath_lb_type
, sizeof(xpath_lb_type
),
6338 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-lb/lb-type",
6340 snprintf(xpath_bandwidth
, sizeof(xpath_bandwidth
),
6341 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-lb/bandwidth",
6343 snprintf(xpath_non_transitive
, sizeof(xpath_non_transitive
),
6344 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-lb/two-octet-as-specific",
6347 if ((strcmp(argv
[idx_lb
]->arg
, "cumulative")) == 0)
6348 nb_cli_enqueue_change(vty
, xpath_lb_type
, NB_OP_MODIFY
,
6349 "cumulative-bandwidth");
6350 else if ((strcmp(argv
[idx_lb
]->arg
, "num-multipaths")) == 0)
6351 nb_cli_enqueue_change(vty
, xpath_lb_type
, NB_OP_MODIFY
,
6352 "computed-bandwidth");
6354 nb_cli_enqueue_change(vty
, xpath_lb_type
, NB_OP_MODIFY
,
6355 "explicit-bandwidth");
6356 nb_cli_enqueue_change(vty
, xpath_bandwidth
, NB_OP_MODIFY
,
6360 if (argv_find(argv
, argc
, "non-transitive", &idx_non_transitive
))
6361 nb_cli_enqueue_change(vty
, xpath_non_transitive
, NB_OP_MODIFY
,
6364 nb_cli_enqueue_change(vty
, xpath_non_transitive
, NB_OP_MODIFY
,
6367 return nb_cli_apply_changes(vty
, NULL
);
6370 DEFUN_YANG (no_set_ecommunity_lb
,
6371 no_set_ecommunity_lb_cmd
,
6372 "no set extcommunity bandwidth <(1-25600)|cumulative|num-multipaths> [non-transitive]",
6375 "BGP extended community attribute\n"
6376 "Link bandwidth extended community\n"
6377 "Bandwidth value in Mbps\n"
6378 "Cumulative bandwidth of all multipaths (outbound-only)\n"
6379 "Internally computed bandwidth based on number of multipaths (outbound-only)\n"
6380 "Attribute is set as non-transitive\n")
6383 "./set-action[action='frr-bgp-route-map:set-extcommunity-lb']";
6385 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6386 return nb_cli_apply_changes(vty
, NULL
);
6389 ALIAS_YANG (no_set_ecommunity_lb
,
6390 no_set_ecommunity_lb_short_cmd
,
6391 "no set extcommunity bandwidth",
6394 "BGP extended community attribute\n"
6395 "Link bandwidth extended community\n")
6397 DEFUN_YANG (set_origin
,
6399 "set origin <egp|igp|incomplete>",
6404 "unknown heritage\n")
6407 const char *origin_type
;
6409 "./set-action[action='frr-bgp-route-map:set-origin']";
6410 char xpath_value
[XPATH_MAXLEN
];
6412 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
6413 origin_type
= "igp";
6414 else if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
6415 origin_type
= "egp";
6416 else if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
6417 origin_type
= "incomplete";
6419 vty_out(vty
, "%% Invalid match origin type\n");
6420 return CMD_WARNING_CONFIG_FAILED
;
6423 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6424 snprintf(xpath_value
, sizeof(xpath_value
),
6425 "%s/rmap-set-action/frr-bgp-route-map:origin", xpath
);
6426 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, origin_type
);
6428 return nb_cli_apply_changes(vty
, NULL
);
6431 DEFUN_YANG (no_set_origin
,
6433 "no set origin [<egp|igp|incomplete>]",
6439 "unknown heritage\n")
6442 "./set-action[action='frr-bgp-route-map:set-origin']";
6444 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6445 return nb_cli_apply_changes(vty
, NULL
);
6448 DEFUN_YANG (set_atomic_aggregate
,
6449 set_atomic_aggregate_cmd
,
6450 "set atomic-aggregate",
6452 "BGP atomic aggregate attribute\n" )
6455 "./set-action[action='frr-bgp-route-map:atomic-aggregate']";
6456 char xpath_value
[XPATH_MAXLEN
];
6458 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6459 snprintf(xpath_value
, sizeof(xpath_value
),
6460 "%s/rmap-set-action/frr-bgp-route-map:atomic-aggregate",
6462 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, NULL
);
6464 return nb_cli_apply_changes(vty
, NULL
);
6467 DEFUN_YANG (no_set_atomic_aggregate
,
6468 no_set_atomic_aggregate_cmd
,
6469 "no set atomic-aggregate",
6472 "BGP atomic aggregate attribute\n" )
6475 "./set-action[action='frr-bgp-route-map:atomic-aggregate']";
6477 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6478 return nb_cli_apply_changes(vty
, NULL
);
6481 DEFPY_YANG (set_aigp_metric
,
6482 set_aigp_metric_cmd
,
6483 "set aigp-metric <igp-metric|(1-4294967295)>$aigp_metric",
6485 "BGP AIGP attribute (AIGP Metric TLV)\n"
6486 "AIGP Metric value from IGP protocol\n"
6487 "Manual AIGP Metric value\n")
6490 "./set-action[action='frr-bgp-route-map:aigp-metric']";
6491 char xpath_value
[XPATH_MAXLEN
];
6493 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6494 snprintf(xpath_value
, sizeof(xpath_value
),
6495 "%s/rmap-set-action/frr-bgp-route-map:aigp-metric", xpath
);
6496 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, aigp_metric
);
6498 return nb_cli_apply_changes(vty
, NULL
);
6501 DEFPY_YANG (no_set_aigp_metric
,
6502 no_set_aigp_metric_cmd
,
6503 "no set aigp-metric [<igp-metric|(1-4294967295)>]",
6506 "BGP AIGP attribute (AIGP Metric TLV)\n"
6507 "AIGP Metric value from IGP protocol\n"
6508 "Manual AIGP Metric value\n")
6511 "./set-action[action='frr-bgp-route-map:aigp-metric']";
6513 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6514 return nb_cli_apply_changes(vty
, NULL
);
6517 DEFUN_YANG (set_aggregator_as
,
6518 set_aggregator_as_cmd
,
6519 "set aggregator as ASNUM A.B.C.D",
6521 "BGP aggregator attribute\n"
6522 "AS number of aggregator\n"
6524 "IP address of aggregator\n")
6528 char xpath_asn
[XPATH_MAXLEN
];
6529 char xpath_addr
[XPATH_MAXLEN
];
6531 "./set-action[action='frr-bgp-route-map:aggregator']";
6534 if (!asn_str2asn(argv
[idx_number
]->arg
, &as_value
)) {
6535 vty_out(vty
, "%% Invalid AS value %s\n", argv
[idx_number
]->arg
);
6536 return CMD_WARNING_CONFIG_FAILED
;
6539 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6542 xpath_asn
, sizeof(xpath_asn
),
6543 "%s/rmap-set-action/frr-bgp-route-map:aggregator/aggregator-asn",
6545 nb_cli_enqueue_change(vty
, xpath_asn
, NB_OP_MODIFY
,
6546 argv
[idx_number
]->arg
);
6549 xpath_addr
, sizeof(xpath_addr
),
6550 "%s/rmap-set-action/frr-bgp-route-map:aggregator/aggregator-address",
6552 nb_cli_enqueue_change(vty
, xpath_addr
, NB_OP_MODIFY
,
6553 argv
[idx_ipv4
]->arg
);
6555 return nb_cli_apply_changes(vty
, NULL
);
6558 DEFUN_YANG (no_set_aggregator_as
,
6559 no_set_aggregator_as_cmd
,
6560 "no set aggregator as [ASNUM A.B.C.D]",
6563 "BGP aggregator attribute\n"
6564 "AS number of aggregator\n"
6566 "IP address of aggregator\n")
6569 "./set-action[action='frr-bgp-route-map:aggregator']";
6571 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6572 return nb_cli_apply_changes(vty
, NULL
);
6575 DEFUN_YANG (match_ipv6_next_hop
,
6576 match_ipv6_next_hop_cmd
,
6577 "match ipv6 next-hop ACCESSLIST6_NAME",
6580 "Match IPv6 next-hop address of route\n"
6581 "IPv6 access-list name\n")
6584 "./match-condition[condition='frr-route-map:ipv6-next-hop-list']";
6585 char xpath_value
[XPATH_MAXLEN
];
6587 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6588 snprintf(xpath_value
, sizeof(xpath_value
),
6589 "%s/rmap-match-condition/list-name", xpath
);
6590 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6591 argv
[argc
- 1]->arg
);
6593 return nb_cli_apply_changes(vty
, NULL
);
6596 DEFUN_YANG (no_match_ipv6_next_hop
,
6597 no_match_ipv6_next_hop_cmd
,
6598 "no match ipv6 next-hop [ACCESSLIST6_NAME]",
6602 "Match IPv6 next-hop address of route\n"
6603 "IPv6 access-list name\n")
6606 "./match-condition[condition='frr-route-map:ipv6-next-hop-list']";
6608 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6609 return nb_cli_apply_changes(vty
, NULL
);
6612 DEFUN_YANG (match_ipv6_next_hop_address
,
6613 match_ipv6_next_hop_address_cmd
,
6614 "match ipv6 next-hop address X:X::X:X",
6617 "Match IPv6 next-hop address of route\n"
6619 "IPv6 address of next hop\n")
6622 "./match-condition[condition='frr-bgp-route-map:ipv6-nexthop']";
6623 char xpath_value
[XPATH_MAXLEN
];
6625 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6626 snprintf(xpath_value
, sizeof(xpath_value
),
6627 "%s/rmap-match-condition/frr-bgp-route-map:ipv6-address",
6629 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6630 argv
[argc
- 1]->arg
);
6632 return nb_cli_apply_changes(vty
, NULL
);
6635 DEFUN_YANG (no_match_ipv6_next_hop_address
,
6636 no_match_ipv6_next_hop_address_cmd
,
6637 "no match ipv6 next-hop address X:X::X:X",
6641 "Match IPv6 next-hop address of route\n"
6643 "IPv6 address of next hop\n")
6646 "./match-condition[condition='frr-bgp-route-map:ipv6-nexthop']";
6648 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6649 return nb_cli_apply_changes(vty
, NULL
);
6652 ALIAS_HIDDEN (match_ipv6_next_hop_address
,
6653 match_ipv6_next_hop_old_cmd
,
6654 "match ipv6 next-hop X:X::X:X",
6657 "Match IPv6 next-hop address of route\n"
6658 "IPv6 address of next hop\n")
6660 ALIAS_HIDDEN (no_match_ipv6_next_hop_address
,
6661 no_match_ipv6_next_hop_old_cmd
,
6662 "no match ipv6 next-hop X:X::X:X",
6666 "Match IPv6 next-hop address of route\n"
6667 "IPv6 address of next hop\n")
6669 DEFUN_YANG (match_ipv6_next_hop_prefix_list
,
6670 match_ipv6_next_hop_prefix_list_cmd
,
6671 "match ipv6 next-hop prefix-list PREFIXLIST_NAME",
6674 "Match IPv6 next-hop address of route\n"
6675 "Match entries by prefix-list\n"
6676 "IPv6 prefix-list name\n")
6679 "./match-condition[condition='frr-route-map:ipv6-next-hop-prefix-list']";
6680 char xpath_value
[XPATH_MAXLEN
];
6682 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6683 snprintf(xpath_value
, sizeof(xpath_value
),
6684 "%s/rmap-match-condition/list-name", xpath
);
6685 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6686 argv
[argc
- 1]->arg
);
6688 return nb_cli_apply_changes(vty
, NULL
);
6691 DEFUN_YANG (no_match_ipv6_next_hop_prefix_list
,
6692 no_match_ipv6_next_hop_prefix_list_cmd
,
6693 "no match ipv6 next-hop prefix-list [PREFIXLIST_NAME]",
6697 "Match IPv6 next-hop address of route\n"
6698 "Match entries by prefix-list\n"
6699 "IPv6 prefix-list name\n")
6702 "./match-condition[condition='frr-route-map:ipv6-next-hop-prefix-list']";
6704 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6705 return nb_cli_apply_changes(vty
, NULL
);
6708 DEFPY_YANG (match_ipv4_next_hop
,
6709 match_ipv4_next_hop_cmd
,
6710 "match ip next-hop address A.B.C.D",
6713 "Match IP next-hop address of route\n"
6715 "IP address of next-hop\n")
6718 "./match-condition[condition='frr-bgp-route-map:ipv4-nexthop']";
6719 char xpath_value
[XPATH_MAXLEN
];
6721 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6722 snprintf(xpath_value
, sizeof(xpath_value
),
6723 "%s/rmap-match-condition/frr-bgp-route-map:ipv4-address",
6725 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[4]->arg
);
6727 return nb_cli_apply_changes(vty
, NULL
);
6730 DEFPY_YANG (no_match_ipv4_next_hop
,
6731 no_match_ipv4_next_hop_cmd
,
6732 "no match ip next-hop address [A.B.C.D]",
6736 "Match IP next-hop address of route\n"
6738 "IP address of next-hop\n")
6741 "./match-condition[condition='frr-bgp-route-map:ipv4-nexthop']";
6743 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6744 return nb_cli_apply_changes(vty
, NULL
);
6747 DEFUN_YANG (set_ipv6_nexthop_peer
,
6748 set_ipv6_nexthop_peer_cmd
,
6749 "set ipv6 next-hop peer-address",
6752 "Next hop address\n"
6753 "Use peer address (for BGP only)\n")
6756 "./set-action[action='frr-bgp-route-map:ipv6-peer-address']";
6757 char xpath_value
[XPATH_MAXLEN
];
6759 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6760 snprintf(xpath_value
, sizeof(xpath_value
),
6761 "%s/rmap-set-action/frr-bgp-route-map:preference", xpath
);
6762 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
6764 return nb_cli_apply_changes(vty
, NULL
);
6767 DEFUN_YANG (no_set_ipv6_nexthop_peer
,
6768 no_set_ipv6_nexthop_peer_cmd
,
6769 "no set ipv6 next-hop peer-address",
6773 "IPv6 next-hop address\n"
6774 "Use peer address (for BGP only)\n")
6777 "./set-action[action='frr-bgp-route-map:ipv6-peer-address']";
6779 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6780 return nb_cli_apply_changes(vty
, NULL
);
6783 DEFUN_YANG (set_ipv6_nexthop_prefer_global
,
6784 set_ipv6_nexthop_prefer_global_cmd
,
6785 "set ipv6 next-hop prefer-global",
6788 "IPv6 next-hop address\n"
6789 "Prefer global over link-local if both exist\n")
6792 "./set-action[action='frr-bgp-route-map:ipv6-prefer-global']";
6793 char xpath_value
[XPATH_MAXLEN
];
6795 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6796 snprintf(xpath_value
, sizeof(xpath_value
),
6797 "%s/rmap-set-action/frr-bgp-route-map:preference", xpath
);
6798 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
6800 return nb_cli_apply_changes(vty
, NULL
);
6803 DEFUN_YANG (no_set_ipv6_nexthop_prefer_global
,
6804 no_set_ipv6_nexthop_prefer_global_cmd
,
6805 "no set ipv6 next-hop prefer-global",
6809 "IPv6 next-hop address\n"
6810 "Prefer global over link-local if both exist\n")
6813 "./set-action[action='frr-bgp-route-map:ipv6-prefer-global']";
6815 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6816 return nb_cli_apply_changes(vty
, NULL
);
6819 DEFUN_YANG (set_ipv6_nexthop_global
,
6820 set_ipv6_nexthop_global_cmd
,
6821 "set ipv6 next-hop global X:X::X:X",
6824 "IPv6 next-hop address\n"
6825 "IPv6 global address\n"
6826 "IPv6 address of next hop\n")
6830 "./set-action[action='frr-bgp-route-map:ipv6-nexthop-global']";
6831 char xpath_value
[XPATH_MAXLEN
];
6833 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6834 snprintf(xpath_value
, sizeof(xpath_value
),
6835 "%s/rmap-set-action/frr-bgp-route-map:ipv6-address", xpath
);
6836 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6837 argv
[idx_ipv6
]->arg
);
6839 return nb_cli_apply_changes(vty
, NULL
);
6842 DEFUN_YANG (no_set_ipv6_nexthop_global
,
6843 no_set_ipv6_nexthop_global_cmd
,
6844 "no set ipv6 next-hop global X:X::X:X",
6848 "IPv6 next-hop address\n"
6849 "IPv6 global address\n"
6850 "IPv6 address of next hop\n")
6853 "./set-action[action='frr-bgp-route-map:ipv6-nexthop-global']";
6855 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6856 return nb_cli_apply_changes(vty
, NULL
);
6859 #ifdef KEEP_OLD_VPN_COMMANDS
6860 DEFUN_YANG (set_vpn_nexthop
,
6861 set_vpn_nexthop_cmd
,
6862 "set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
6864 "VPNv4 information\n"
6865 "VPN next-hop address\n"
6866 "IP address of next hop\n"
6867 "VPNv6 information\n"
6868 "VPN next-hop address\n"
6869 "IPv6 address of next hop\n")
6874 char xpath_value
[XPATH_MAXLEN
];
6876 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
6877 if (afi
== AFI_IP
) {
6879 "./set-action[action='frr-bgp-route-map:ipv4-vpn-address']";
6881 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6883 xpath_value
, sizeof(xpath_value
),
6884 "%s/rmap-set-action/frr-bgp-route-map:ipv4-address",
6888 "./set-action[action='frr-bgp-route-map:ipv6-vpn-address']";
6890 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6892 xpath_value
, sizeof(xpath_value
),
6893 "%s/rmap-set-action/frr-bgp-route-map:ipv6-address",
6897 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6900 return nb_cli_apply_changes(vty
, NULL
);
6906 DEFUN_YANG (no_set_vpn_nexthop
,
6907 no_set_vpn_nexthop_cmd
,
6908 "no set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
6911 "VPNv4 information\n"
6912 "VPN next-hop address\n"
6913 "IP address of next hop\n"
6914 "VPNv6 information\n"
6915 "VPN next-hop address\n"
6916 "IPv6 address of next hop\n")
6921 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
6922 if (afi
== AFI_IP
) {
6924 "./set-action[action='frr-bgp-route-map:ipv4-vpn-address']";
6925 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6928 "./set-action[action='frr-bgp-route-map:ipv6-vpn-address']";
6929 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6931 return nb_cli_apply_changes(vty
, NULL
);
6935 #endif /* KEEP_OLD_VPN_COMMANDS */
6937 DEFPY_YANG (set_ipx_vpn_nexthop
,
6938 set_ipx_vpn_nexthop_cmd
,
6939 "set <ipv4|ipv6> vpn next-hop <A.B.C.D$addrv4|X:X::X:X$addrv6>",
6941 "IPv4 information\n"
6942 "IPv6 information\n"
6944 "VPN next-hop address\n"
6945 "IP address of next hop\n"
6946 "IPv6 address of next hop\n")
6951 char xpath_value
[XPATH_MAXLEN
];
6953 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
6954 if (afi
== AFI_IP
) {
6956 vty_out(vty
, "%% IPv4 next-hop expected\n");
6957 return CMD_WARNING_CONFIG_FAILED
;
6961 "./set-action[action='frr-bgp-route-map:ipv4-vpn-address']";
6963 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6965 xpath_value
, sizeof(xpath_value
),
6966 "%s/rmap-set-action/frr-bgp-route-map:ipv4-address",
6970 vty_out(vty
, "%% IPv6 next-hop expected\n");
6971 return CMD_WARNING_CONFIG_FAILED
;
6975 "./set-action[action='frr-bgp-route-map:ipv6-vpn-address']";
6977 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6979 xpath_value
, sizeof(xpath_value
),
6980 "%s/rmap-set-action/frr-bgp-route-map:ipv6-address",
6983 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6985 return nb_cli_apply_changes(vty
, NULL
);
6990 DEFUN_YANG (no_set_ipx_vpn_nexthop
,
6991 no_set_ipx_vpn_nexthop_cmd
,
6992 "no set <ipv4|ipv6> vpn next-hop [<A.B.C.D|X:X::X:X>]",
6995 "IPv4 information\n"
6996 "IPv6 information\n"
6998 "VPN next-hop address\n"
6999 "IP address of next hop\n"
7000 "IPv6 address of next hop\n")
7005 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
7006 if (afi
== AFI_IP
) {
7008 "./set-action[action='frr-bgp-route-map:ipv4-vpn-address']";
7009 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
7012 "./set-action[action='frr-bgp-route-map:ipv6-vpn-address']";
7013 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
7015 return nb_cli_apply_changes(vty
, NULL
);
7020 DEFUN_YANG (set_originator_id
,
7021 set_originator_id_cmd
,
7022 "set originator-id A.B.C.D",
7024 "BGP originator ID attribute\n"
7025 "IP address of originator\n")
7029 "./set-action[action='frr-bgp-route-map:originator-id']";
7030 char xpath_value
[XPATH_MAXLEN
];
7032 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
7033 snprintf(xpath_value
, sizeof(xpath_value
),
7034 "%s/rmap-set-action/frr-bgp-route-map:originator-id", xpath
);
7035 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
7036 argv
[idx_ipv4
]->arg
);
7038 return nb_cli_apply_changes(vty
, NULL
);
7041 DEFUN_YANG (no_set_originator_id
,
7042 no_set_originator_id_cmd
,
7043 "no set originator-id [A.B.C.D]",
7046 "BGP originator ID attribute\n"
7047 "IP address of originator\n")
7050 "./set-action[action='frr-bgp-route-map:originator-id']";
7052 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
7053 return nb_cli_apply_changes(vty
, NULL
);
7056 DEFPY_YANG (match_rpki_extcommunity
,
7057 match_rpki_extcommunity_cmd
,
7058 "[no$no] match rpki-extcommunity <valid|invalid|notfound>",
7061 "BGP RPKI (Origin Validation State) extended community attribute\n"
7064 "Prefix not found\n")
7067 "./match-condition[condition='frr-bgp-route-map:rpki-extcommunity']";
7068 char xpath_value
[XPATH_MAXLEN
];
7070 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
7074 xpath_value
, sizeof(xpath_value
),
7075 "%s/rmap-match-condition/frr-bgp-route-map:rpki-extcommunity",
7077 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
7081 return nb_cli_apply_changes(vty
, NULL
);
7084 /* Initialization of route map. */
7085 void bgp_route_map_init(void)
7089 route_map_add_hook(bgp_route_map_add
);
7090 route_map_delete_hook(bgp_route_map_delete
);
7091 route_map_event_hook(bgp_route_map_event
);
7093 route_map_match_interface_hook(generic_match_add
);
7094 route_map_no_match_interface_hook(generic_match_delete
);
7096 route_map_match_ip_address_hook(generic_match_add
);
7097 route_map_no_match_ip_address_hook(generic_match_delete
);
7099 route_map_match_ip_address_prefix_list_hook(generic_match_add
);
7100 route_map_no_match_ip_address_prefix_list_hook(generic_match_delete
);
7102 route_map_match_ip_next_hop_hook(generic_match_add
);
7103 route_map_no_match_ip_next_hop_hook(generic_match_delete
);
7105 route_map_match_ipv6_next_hop_hook(generic_match_add
);
7106 route_map_no_match_ipv6_next_hop_hook(generic_match_delete
);
7108 route_map_match_ip_next_hop_prefix_list_hook(generic_match_add
);
7109 route_map_no_match_ip_next_hop_prefix_list_hook(generic_match_delete
);
7111 route_map_match_ip_next_hop_type_hook(generic_match_add
);
7112 route_map_no_match_ip_next_hop_type_hook(generic_match_delete
);
7114 route_map_match_ipv6_address_hook(generic_match_add
);
7115 route_map_no_match_ipv6_address_hook(generic_match_delete
);
7117 route_map_match_ipv6_address_prefix_list_hook(generic_match_add
);
7118 route_map_no_match_ipv6_address_prefix_list_hook(generic_match_delete
);
7120 route_map_match_ipv6_next_hop_type_hook(generic_match_add
);
7121 route_map_no_match_ipv6_next_hop_type_hook(generic_match_delete
);
7123 route_map_match_ipv6_next_hop_prefix_list_hook(generic_match_add
);
7124 route_map_no_match_ipv6_next_hop_prefix_list_hook(generic_match_delete
);
7126 route_map_match_metric_hook(generic_match_add
);
7127 route_map_no_match_metric_hook(generic_match_delete
);
7129 route_map_match_tag_hook(generic_match_add
);
7130 route_map_no_match_tag_hook(generic_match_delete
);
7132 route_map_set_srte_color_hook(generic_set_add
);
7133 route_map_no_set_srte_color_hook(generic_set_delete
);
7135 route_map_set_ip_nexthop_hook(generic_set_add
);
7136 route_map_no_set_ip_nexthop_hook(generic_set_delete
);
7138 route_map_set_ipv6_nexthop_local_hook(generic_set_add
);
7139 route_map_no_set_ipv6_nexthop_local_hook(generic_set_delete
);
7141 route_map_set_metric_hook(generic_set_add
);
7142 route_map_no_set_metric_hook(generic_set_delete
);
7144 route_map_set_tag_hook(generic_set_add
);
7145 route_map_no_set_tag_hook(generic_set_delete
);
7147 route_map_install_match(&route_match_peer_cmd
);
7148 route_map_install_match(&route_match_alias_cmd
);
7149 route_map_install_match(&route_match_local_pref_cmd
);
7150 #ifdef HAVE_SCRIPTING
7151 route_map_install_match(&route_match_script_cmd
);
7153 route_map_install_match(&route_match_ip_address_cmd
);
7154 route_map_install_match(&route_match_ip_next_hop_cmd
);
7155 route_map_install_match(&route_match_ip_route_source_cmd
);
7156 route_map_install_match(&route_match_ip_address_prefix_list_cmd
);
7157 route_map_install_match(&route_match_ip_next_hop_prefix_list_cmd
);
7158 route_map_install_match(&route_match_ip_next_hop_type_cmd
);
7159 route_map_install_match(&route_match_ip_route_source_prefix_list_cmd
);
7160 route_map_install_match(&route_match_aspath_cmd
);
7161 route_map_install_match(&route_match_community_cmd
);
7162 route_map_install_match(&route_match_lcommunity_cmd
);
7163 route_map_install_match(&route_match_ecommunity_cmd
);
7164 route_map_install_match(&route_match_local_pref_cmd
);
7165 route_map_install_match(&route_match_metric_cmd
);
7166 route_map_install_match(&route_match_origin_cmd
);
7167 route_map_install_match(&route_match_probability_cmd
);
7168 route_map_install_match(&route_match_interface_cmd
);
7169 route_map_install_match(&route_match_tag_cmd
);
7170 route_map_install_match(&route_match_mac_address_cmd
);
7171 route_map_install_match(&route_match_evpn_vni_cmd
);
7172 route_map_install_match(&route_match_evpn_route_type_cmd
);
7173 route_map_install_match(&route_match_evpn_rd_cmd
);
7174 route_map_install_match(&route_match_evpn_default_route_cmd
);
7175 route_map_install_match(&route_match_vrl_source_vrf_cmd
);
7177 route_map_install_set(&route_set_evpn_gateway_ip_ipv4_cmd
);
7178 route_map_install_set(&route_set_evpn_gateway_ip_ipv6_cmd
);
7179 route_map_install_set(&route_set_table_id_cmd
);
7180 route_map_install_set(&route_set_srte_color_cmd
);
7181 route_map_install_set(&route_set_ip_nexthop_cmd
);
7182 route_map_install_set(&route_set_local_pref_cmd
);
7183 route_map_install_set(&route_set_weight_cmd
);
7184 route_map_install_set(&route_set_label_index_cmd
);
7185 route_map_install_set(&route_set_metric_cmd
);
7186 route_map_install_set(&route_set_distance_cmd
);
7187 route_map_install_set(&route_set_aspath_prepend_cmd
);
7188 route_map_install_set(&route_set_aspath_exclude_cmd
);
7189 route_map_install_set(&route_set_aspath_replace_cmd
);
7190 route_map_install_set(&route_set_origin_cmd
);
7191 route_map_install_set(&route_set_atomic_aggregate_cmd
);
7192 route_map_install_set(&route_set_aigp_metric_cmd
);
7193 route_map_install_set(&route_set_aggregator_as_cmd
);
7194 route_map_install_set(&route_set_community_cmd
);
7195 route_map_install_set(&route_set_community_delete_cmd
);
7196 route_map_install_set(&route_set_lcommunity_cmd
);
7197 route_map_install_set(&route_set_lcommunity_delete_cmd
);
7198 route_map_install_set(&route_set_vpnv4_nexthop_cmd
);
7199 route_map_install_set(&route_set_vpnv6_nexthop_cmd
);
7200 route_map_install_set(&route_set_originator_id_cmd
);
7201 route_map_install_set(&route_set_ecommunity_rt_cmd
);
7202 route_map_install_set(&route_set_ecommunity_soo_cmd
);
7203 route_map_install_set(&route_set_ecommunity_lb_cmd
);
7204 route_map_install_set(&route_set_ecommunity_none_cmd
);
7205 route_map_install_set(&route_set_tag_cmd
);
7206 route_map_install_set(&route_set_label_index_cmd
);
7207 route_map_install_set(&route_set_l3vpn_nexthop_encapsulation_cmd
);
7209 install_element(RMAP_NODE
, &match_peer_cmd
);
7210 install_element(RMAP_NODE
, &match_peer_local_cmd
);
7211 install_element(RMAP_NODE
, &no_match_peer_cmd
);
7212 install_element(RMAP_NODE
, &match_ip_route_source_cmd
);
7213 install_element(RMAP_NODE
, &no_match_ip_route_source_cmd
);
7214 install_element(RMAP_NODE
, &match_ip_route_source_prefix_list_cmd
);
7215 install_element(RMAP_NODE
, &no_match_ip_route_source_prefix_list_cmd
);
7216 install_element(RMAP_NODE
, &match_mac_address_cmd
);
7217 install_element(RMAP_NODE
, &no_match_mac_address_cmd
);
7218 install_element(RMAP_NODE
, &match_evpn_vni_cmd
);
7219 install_element(RMAP_NODE
, &no_match_evpn_vni_cmd
);
7220 install_element(RMAP_NODE
, &match_evpn_route_type_cmd
);
7221 install_element(RMAP_NODE
, &no_match_evpn_route_type_cmd
);
7222 install_element(RMAP_NODE
, &match_evpn_rd_cmd
);
7223 install_element(RMAP_NODE
, &no_match_evpn_rd_cmd
);
7224 install_element(RMAP_NODE
, &match_evpn_default_route_cmd
);
7225 install_element(RMAP_NODE
, &no_match_evpn_default_route_cmd
);
7226 install_element(RMAP_NODE
, &set_evpn_gw_ip_ipv4_cmd
);
7227 install_element(RMAP_NODE
, &no_set_evpn_gw_ip_ipv4_cmd
);
7228 install_element(RMAP_NODE
, &set_evpn_gw_ip_ipv6_cmd
);
7229 install_element(RMAP_NODE
, &no_set_evpn_gw_ip_ipv6_cmd
);
7230 install_element(RMAP_NODE
, &match_vrl_source_vrf_cmd
);
7231 install_element(RMAP_NODE
, &no_match_vrl_source_vrf_cmd
);
7233 install_element(RMAP_NODE
, &match_aspath_cmd
);
7234 install_element(RMAP_NODE
, &no_match_aspath_cmd
);
7235 install_element(RMAP_NODE
, &match_local_pref_cmd
);
7236 install_element(RMAP_NODE
, &no_match_local_pref_cmd
);
7237 install_element(RMAP_NODE
, &match_alias_cmd
);
7238 install_element(RMAP_NODE
, &no_match_alias_cmd
);
7239 install_element(RMAP_NODE
, &match_community_cmd
);
7240 install_element(RMAP_NODE
, &no_match_community_cmd
);
7241 install_element(RMAP_NODE
, &match_lcommunity_cmd
);
7242 install_element(RMAP_NODE
, &no_match_lcommunity_cmd
);
7243 install_element(RMAP_NODE
, &match_ecommunity_cmd
);
7244 install_element(RMAP_NODE
, &no_match_ecommunity_cmd
);
7245 install_element(RMAP_NODE
, &match_origin_cmd
);
7246 install_element(RMAP_NODE
, &no_match_origin_cmd
);
7247 install_element(RMAP_NODE
, &match_probability_cmd
);
7248 install_element(RMAP_NODE
, &no_match_probability_cmd
);
7250 install_element(RMAP_NODE
, &no_set_table_id_cmd
);
7251 install_element(RMAP_NODE
, &set_table_id_cmd
);
7252 install_element(RMAP_NODE
, &set_ip_nexthop_peer_cmd
);
7253 install_element(RMAP_NODE
, &set_ip_nexthop_unchanged_cmd
);
7254 install_element(RMAP_NODE
, &set_local_pref_cmd
);
7255 install_element(RMAP_NODE
, &set_distance_cmd
);
7256 install_element(RMAP_NODE
, &no_set_distance_cmd
);
7257 install_element(RMAP_NODE
, &no_set_local_pref_cmd
);
7258 install_element(RMAP_NODE
, &set_weight_cmd
);
7259 install_element(RMAP_NODE
, &set_label_index_cmd
);
7260 install_element(RMAP_NODE
, &no_set_weight_cmd
);
7261 install_element(RMAP_NODE
, &no_set_label_index_cmd
);
7262 install_element(RMAP_NODE
, &set_aspath_prepend_asn_cmd
);
7263 install_element(RMAP_NODE
, &set_aspath_prepend_lastas_cmd
);
7264 install_element(RMAP_NODE
, &set_aspath_exclude_cmd
);
7265 install_element(RMAP_NODE
, &set_aspath_replace_asn_cmd
);
7266 install_element(RMAP_NODE
, &no_set_aspath_prepend_cmd
);
7267 install_element(RMAP_NODE
, &no_set_aspath_prepend_lastas_cmd
);
7268 install_element(RMAP_NODE
, &no_set_aspath_exclude_cmd
);
7269 install_element(RMAP_NODE
, &no_set_aspath_exclude_all_cmd
);
7270 install_element(RMAP_NODE
, &no_set_aspath_replace_asn_cmd
);
7271 install_element(RMAP_NODE
, &set_origin_cmd
);
7272 install_element(RMAP_NODE
, &no_set_origin_cmd
);
7273 install_element(RMAP_NODE
, &set_atomic_aggregate_cmd
);
7274 install_element(RMAP_NODE
, &no_set_atomic_aggregate_cmd
);
7275 install_element(RMAP_NODE
, &set_aigp_metric_cmd
);
7276 install_element(RMAP_NODE
, &no_set_aigp_metric_cmd
);
7277 install_element(RMAP_NODE
, &set_aggregator_as_cmd
);
7278 install_element(RMAP_NODE
, &no_set_aggregator_as_cmd
);
7279 install_element(RMAP_NODE
, &set_community_cmd
);
7280 install_element(RMAP_NODE
, &set_community_none_cmd
);
7281 install_element(RMAP_NODE
, &no_set_community_cmd
);
7282 install_element(RMAP_NODE
, &no_set_community_short_cmd
);
7283 install_element(RMAP_NODE
, &set_community_delete_cmd
);
7284 install_element(RMAP_NODE
, &no_set_community_delete_cmd
);
7285 install_element(RMAP_NODE
, &set_lcommunity_cmd
);
7286 install_element(RMAP_NODE
, &set_lcommunity_none_cmd
);
7287 install_element(RMAP_NODE
, &no_set_lcommunity_cmd
);
7288 install_element(RMAP_NODE
, &no_set_lcommunity1_cmd
);
7289 install_element(RMAP_NODE
, &no_set_lcommunity1_short_cmd
);
7290 install_element(RMAP_NODE
, &set_lcommunity_delete_cmd
);
7291 install_element(RMAP_NODE
, &no_set_lcommunity_delete_cmd
);
7292 install_element(RMAP_NODE
, &no_set_lcommunity_delete_short_cmd
);
7293 install_element(RMAP_NODE
, &set_ecommunity_rt_cmd
);
7294 install_element(RMAP_NODE
, &no_set_ecommunity_rt_cmd
);
7295 install_element(RMAP_NODE
, &no_set_ecommunity_rt_short_cmd
);
7296 install_element(RMAP_NODE
, &set_ecommunity_soo_cmd
);
7297 install_element(RMAP_NODE
, &no_set_ecommunity_soo_cmd
);
7298 install_element(RMAP_NODE
, &no_set_ecommunity_soo_short_cmd
);
7299 install_element(RMAP_NODE
, &set_ecommunity_lb_cmd
);
7300 install_element(RMAP_NODE
, &no_set_ecommunity_lb_cmd
);
7301 install_element(RMAP_NODE
, &no_set_ecommunity_lb_short_cmd
);
7302 install_element(RMAP_NODE
, &set_ecommunity_none_cmd
);
7303 install_element(RMAP_NODE
, &no_set_ecommunity_none_cmd
);
7304 #ifdef KEEP_OLD_VPN_COMMANDS
7305 install_element(RMAP_NODE
, &set_vpn_nexthop_cmd
);
7306 install_element(RMAP_NODE
, &no_set_vpn_nexthop_cmd
);
7307 #endif /* KEEP_OLD_VPN_COMMANDS */
7308 install_element(RMAP_NODE
, &set_ipx_vpn_nexthop_cmd
);
7309 install_element(RMAP_NODE
, &no_set_ipx_vpn_nexthop_cmd
);
7310 install_element(RMAP_NODE
, &set_originator_id_cmd
);
7311 install_element(RMAP_NODE
, &no_set_originator_id_cmd
);
7312 install_element(RMAP_NODE
, &set_l3vpn_nexthop_encapsulation_cmd
);
7314 route_map_install_match(&route_match_ipv6_address_cmd
);
7315 route_map_install_match(&route_match_ipv6_next_hop_cmd
);
7316 route_map_install_match(&route_match_ipv6_next_hop_address_cmd
);
7317 route_map_install_match(&route_match_ipv6_next_hop_prefix_list_cmd
);
7318 route_map_install_match(&route_match_ipv4_next_hop_cmd
);
7319 route_map_install_match(&route_match_ipv6_address_prefix_list_cmd
);
7320 route_map_install_match(&route_match_ipv6_next_hop_type_cmd
);
7321 route_map_install_set(&route_set_ipv6_nexthop_global_cmd
);
7322 route_map_install_set(&route_set_ipv6_nexthop_prefer_global_cmd
);
7323 route_map_install_set(&route_set_ipv6_nexthop_local_cmd
);
7324 route_map_install_set(&route_set_ipv6_nexthop_peer_cmd
);
7325 route_map_install_match(&route_match_rpki_extcommunity_cmd
);
7327 install_element(RMAP_NODE
, &match_ipv6_next_hop_cmd
);
7328 install_element(RMAP_NODE
, &match_ipv6_next_hop_address_cmd
);
7329 install_element(RMAP_NODE
, &match_ipv6_next_hop_prefix_list_cmd
);
7330 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_cmd
);
7331 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_address_cmd
);
7332 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_prefix_list_cmd
);
7333 install_element(RMAP_NODE
, &match_ipv6_next_hop_old_cmd
);
7334 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_old_cmd
);
7335 install_element(RMAP_NODE
, &match_ipv4_next_hop_cmd
);
7336 install_element(RMAP_NODE
, &no_match_ipv4_next_hop_cmd
);
7337 install_element(RMAP_NODE
, &set_ipv6_nexthop_global_cmd
);
7338 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_global_cmd
);
7339 install_element(RMAP_NODE
, &set_ipv6_nexthop_prefer_global_cmd
);
7340 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_prefer_global_cmd
);
7341 install_element(RMAP_NODE
, &set_ipv6_nexthop_peer_cmd
);
7342 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_peer_cmd
);
7343 install_element(RMAP_NODE
, &match_rpki_extcommunity_cmd
);
7344 #ifdef HAVE_SCRIPTING
7345 install_element(RMAP_NODE
, &match_script_cmd
);
7349 void bgp_route_map_terminate(void)
7351 /* ToDo: Cleanup all the used memory */