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 (unlikely(CHECK_FLAG(rmap_debug
,
465 DEBUG_ROUTEMAP_DETAIL
)))
467 "%s: Access-List Specified: %s does not exist defaulting to NO_MATCH",
468 __func__
, (char *)rule
);
472 return (access_list_apply(alist
, prefix
) == FILTER_DENY
479 /* Route map `ip address' match statement. `arg' should be
481 static void *route_match_ip_address_compile(const char *arg
)
483 struct access_list
*alist
;
485 alist
= access_list_lookup(AFI_IP
, arg
);
488 "Access List specified %s does not exist yet, default will be NO_MATCH until it is created",
490 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
493 /* Free route map's compiled `ip address' value. */
494 static void route_match_ip_address_free(void *rule
)
496 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
499 /* Route map commands for ip address matching. */
500 static const struct route_map_rule_cmd route_match_ip_address_cmd
= {
502 route_match_ip_address
,
503 route_match_ip_address_compile
,
504 route_match_ip_address_free
507 /* `match ip next-hop <IP_ADDRESS_ACCESS_LIST_NAME>' */
509 /* Match function return 1 if match is success else return zero. */
510 static enum route_map_cmd_result_t
511 route_match_ip_next_hop(void *rule
, const struct prefix
*prefix
, void *object
)
513 struct access_list
*alist
;
514 struct bgp_path_info
*path
;
515 struct prefix_ipv4 p
;
517 if (prefix
->family
== AF_INET
) {
520 p
.prefix
= path
->attr
->nexthop
;
521 p
.prefixlen
= IPV4_MAX_BITLEN
;
523 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
525 if (unlikely(CHECK_FLAG(rmap_debug
,
526 DEBUG_ROUTEMAP_DETAIL
)))
528 "%s: Access-List Specified: %s does not exist defaulting to NO_MATCH",
529 __func__
, (char *)rule
);
534 return (access_list_apply(alist
, &p
) == FILTER_DENY
541 /* Route map `ip next-hop' match statement. `arg' is
543 static void *route_match_ip_next_hop_compile(const char *arg
)
545 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
548 /* Free route map's compiled `ip address' value. */
549 static void route_match_ip_next_hop_free(void *rule
)
551 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
554 /* Route map commands for ip next-hop matching. */
555 static const struct route_map_rule_cmd route_match_ip_next_hop_cmd
= {
557 route_match_ip_next_hop
,
558 route_match_ip_next_hop_compile
,
559 route_match_ip_next_hop_free
562 /* `match ip route-source ACCESS-LIST' */
564 /* Match function return 1 if match is success else return zero. */
565 static enum route_map_cmd_result_t
566 route_match_ip_route_source(void *rule
, const struct prefix
*pfx
, void *object
)
568 struct access_list
*alist
;
569 struct bgp_path_info
*path
;
571 struct prefix_ipv4 p
;
573 if (pfx
->family
== AF_INET
) {
577 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
581 p
.prefix
= peer
->su
.sin
.sin_addr
;
582 p
.prefixlen
= IPV4_MAX_BITLEN
;
584 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
586 if (unlikely(CHECK_FLAG(rmap_debug
,
587 DEBUG_ROUTEMAP_DETAIL
)))
589 "%s: Access-List Specified: %s does not exist defaulting to NO_MATCH",
590 __func__
, (char *)rule
);
595 return (access_list_apply(alist
, &p
) == FILTER_DENY
602 /* Route map `ip route-source' match statement. `arg' is
604 static void *route_match_ip_route_source_compile(const char *arg
)
606 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
609 /* Free route map's compiled `ip address' value. */
610 static void route_match_ip_route_source_free(void *rule
)
612 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
615 /* Route map commands for ip route-source matching. */
616 static const struct route_map_rule_cmd route_match_ip_route_source_cmd
= {
618 route_match_ip_route_source
,
619 route_match_ip_route_source_compile
,
620 route_match_ip_route_source_free
623 static enum route_map_cmd_result_t
624 route_match_prefix_list_flowspec(afi_t afi
, struct prefix_list
*plist
,
625 const struct prefix
*p
)
628 struct bgp_pbr_entry_main api
;
630 memset(&api
, 0, sizeof(api
));
632 if (family2afi(p
->u
.prefix_flowspec
.family
) != afi
)
635 /* extract match from flowspec entries */
636 ret
= bgp_flowspec_match_rules_fill(
637 (uint8_t *)p
->u
.prefix_flowspec
.ptr
,
638 p
->u
.prefix_flowspec
.prefixlen
, &api
,
642 if (api
.match_bitmask
& PREFIX_DST_PRESENT
||
643 api
.match_bitmask_iprule
& PREFIX_DST_PRESENT
) {
644 if (family2afi((&api
.dst_prefix
)->family
) != afi
)
646 return prefix_list_apply(plist
, &api
.dst_prefix
) == PREFIX_DENY
649 } else if (api
.match_bitmask
& PREFIX_SRC_PRESENT
||
650 api
.match_bitmask_iprule
& PREFIX_SRC_PRESENT
) {
651 if (family2afi((&api
.src_prefix
)->family
) != afi
)
653 return (prefix_list_apply(plist
, &api
.src_prefix
) == PREFIX_DENY
660 static enum route_map_cmd_result_t
661 route_match_prefix_list_evpn(afi_t afi
, struct prefix_list
*plist
,
662 const struct prefix
*p
)
664 /* Convert to match a general plist */
667 if (evpn_prefix2prefix(p
, &new))
670 return (prefix_list_apply(plist
, &new) == PREFIX_DENY
? RMAP_NOMATCH
674 static enum route_map_cmd_result_t
675 route_match_address_prefix_list(void *rule
, afi_t afi
,
676 const struct prefix
*prefix
, void *object
)
678 struct prefix_list
*plist
;
680 plist
= prefix_list_lookup(afi
, (char *)rule
);
682 if (unlikely(CHECK_FLAG(rmap_debug
, DEBUG_ROUTEMAP_DETAIL
)))
684 "%s: Prefix List %s specified does not exist defaulting to NO_MATCH",
685 __func__
, (char *)rule
);
689 if (prefix
->family
== AF_FLOWSPEC
)
690 return route_match_prefix_list_flowspec(afi
, plist
,
693 else if (prefix
->family
== AF_EVPN
)
694 return route_match_prefix_list_evpn(afi
, plist
, prefix
);
696 return (prefix_list_apply(plist
, prefix
) == PREFIX_DENY
? RMAP_NOMATCH
700 static enum route_map_cmd_result_t
701 route_match_ip_address_prefix_list(void *rule
, const struct prefix
*prefix
,
704 return route_match_address_prefix_list(rule
, AFI_IP
, prefix
, object
);
707 static void *route_match_ip_address_prefix_list_compile(const char *arg
)
709 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
712 static void route_match_ip_address_prefix_list_free(void *rule
)
714 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
717 static const struct route_map_rule_cmd
718 route_match_ip_address_prefix_list_cmd
= {
719 "ip address prefix-list",
720 route_match_ip_address_prefix_list
,
721 route_match_ip_address_prefix_list_compile
,
722 route_match_ip_address_prefix_list_free
725 /* `match ip next-hop prefix-list PREFIX_LIST' */
727 static enum route_map_cmd_result_t
728 route_match_ip_next_hop_prefix_list(void *rule
, const struct prefix
*prefix
,
731 struct prefix_list
*plist
;
732 struct bgp_path_info
*path
;
733 struct prefix_ipv4 p
;
735 if (prefix
->family
== AF_INET
) {
738 p
.prefix
= path
->attr
->nexthop
;
739 p
.prefixlen
= IPV4_MAX_BITLEN
;
741 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
743 if (unlikely(CHECK_FLAG(rmap_debug
,
744 DEBUG_ROUTEMAP_DETAIL
)))
746 "%s: Prefix List %s specified does not exist defaulting to NO_MATCH",
747 __func__
, (char *)rule
);
751 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
758 static void *route_match_ip_next_hop_prefix_list_compile(const char *arg
)
760 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
763 static void route_match_ip_next_hop_prefix_list_free(void *rule
)
765 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
768 static const struct route_map_rule_cmd
769 route_match_ip_next_hop_prefix_list_cmd
= {
770 "ip next-hop prefix-list",
771 route_match_ip_next_hop_prefix_list
,
772 route_match_ip_next_hop_prefix_list_compile
,
773 route_match_ip_next_hop_prefix_list_free
776 /* `match ipv6 next-hop prefix-list PREFIXLIST_NAME' */
777 static enum route_map_cmd_result_t
778 route_match_ipv6_next_hop_prefix_list(void *rule
, const struct prefix
*prefix
,
781 struct prefix_list
*plist
;
782 struct bgp_path_info
*path
;
783 struct prefix_ipv6 p
;
785 if (prefix
->family
== AF_INET6
) {
788 p
.prefix
= path
->attr
->mp_nexthop_global
;
789 p
.prefixlen
= IPV6_MAX_BITLEN
;
791 plist
= prefix_list_lookup(AFI_IP6
, (char *)rule
);
793 if (unlikely(CHECK_FLAG(rmap_debug
,
794 DEBUG_ROUTEMAP_DETAIL
)))
796 "%s: Prefix List %s specified does not exist defaulting to NO_MATCH",
797 __func__
, (char *)rule
);
801 if (prefix_list_apply(plist
, &p
) == PREFIX_PERMIT
)
804 if (path
->attr
->mp_nexthop_len
805 == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
) {
806 p
.prefix
= path
->attr
->mp_nexthop_local
;
807 if (prefix_list_apply(plist
, &p
) == PREFIX_PERMIT
)
815 static void *route_match_ipv6_next_hop_prefix_list_compile(const char *arg
)
817 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
820 static void route_match_ipv6_next_hop_prefix_list_free(void *rule
)
822 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
825 static const struct route_map_rule_cmd
826 route_match_ipv6_next_hop_prefix_list_cmd
= {
827 "ipv6 next-hop prefix-list",
828 route_match_ipv6_next_hop_prefix_list
,
829 route_match_ipv6_next_hop_prefix_list_compile
,
830 route_match_ipv6_next_hop_prefix_list_free
833 /* `match ip next-hop type <blackhole>' */
835 static enum route_map_cmd_result_t
836 route_match_ip_next_hop_type(void *rule
, const struct prefix
*prefix
,
839 struct bgp_path_info
*path
;
841 if (prefix
->family
== AF_INET
) {
842 path
= (struct bgp_path_info
*)object
;
846 /* If nexthop interface's index can't be resolved and nexthop is
847 set to any address then mark it as type `blackhole`.
848 This logic works for matching kernel/static routes like:
849 `ip route add blackhole 10.0.0.1`. */
850 if (path
->attr
->nexthop
.s_addr
== INADDR_ANY
851 && !path
->attr
->nh_ifindex
)
857 static void *route_match_ip_next_hop_type_compile(const char *arg
)
859 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
862 static void route_match_ip_next_hop_type_free(void *rule
)
864 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
867 static const struct route_map_rule_cmd
868 route_match_ip_next_hop_type_cmd
= {
870 route_match_ip_next_hop_type
,
871 route_match_ip_next_hop_type_compile
,
872 route_match_ip_next_hop_type_free
875 /* `match ip route-source prefix-list PREFIX_LIST' */
877 static enum route_map_cmd_result_t
878 route_match_ip_route_source_prefix_list(void *rule
, const struct prefix
*prefix
,
881 struct prefix_list
*plist
;
882 struct bgp_path_info
*path
;
884 struct prefix_ipv4 p
;
886 if (prefix
->family
== AF_INET
) {
890 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
894 p
.prefix
= peer
->su
.sin
.sin_addr
;
895 p
.prefixlen
= IPV4_MAX_BITLEN
;
897 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
899 if (unlikely(CHECK_FLAG(rmap_debug
,
900 DEBUG_ROUTEMAP_DETAIL
)))
902 "%s: Prefix List %s specified does not exist defaulting to NO_MATCH",
903 __func__
, (char *)rule
);
907 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
914 static void *route_match_ip_route_source_prefix_list_compile(const char *arg
)
916 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
919 static void route_match_ip_route_source_prefix_list_free(void *rule
)
921 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
924 static const struct route_map_rule_cmd
925 route_match_ip_route_source_prefix_list_cmd
= {
926 "ip route-source prefix-list",
927 route_match_ip_route_source_prefix_list
,
928 route_match_ip_route_source_prefix_list_compile
,
929 route_match_ip_route_source_prefix_list_free
932 /* `match evpn default-route' */
934 /* Match function should return 1 if match is success else 0 */
935 static enum route_map_cmd_result_t
936 route_match_evpn_default_route(void *rule
, const struct prefix
*p
, void *object
)
938 if (is_evpn_prefix_default(p
))
944 /* Route map commands for default-route matching. */
945 static const struct route_map_rule_cmd
946 route_match_evpn_default_route_cmd
= {
947 "evpn default-route",
948 route_match_evpn_default_route
,
953 /* `match mac address MAC_ACCESS_LIST' */
955 /* Match function should return 1 if match is success else return
957 static enum route_map_cmd_result_t
958 route_match_mac_address(void *rule
, const struct prefix
*prefix
, void *object
)
960 struct access_list
*alist
;
963 alist
= access_list_lookup(AFI_L2VPN
, (char *)rule
);
965 if (unlikely(CHECK_FLAG(rmap_debug
, DEBUG_ROUTEMAP_DETAIL
)))
967 "%s: Access-List Specified: %s does not exist defaulting to NO_MATCH",
968 __func__
, (char *)rule
);
972 if (prefix
->u
.prefix_evpn
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
) {
973 if (unlikely(CHECK_FLAG(rmap_debug
, DEBUG_ROUTEMAP_DETAIL
)))
975 "%s: Prefix %pFX is not a EVPN MAC IP ROUTE defaulting to NO_MATCH",
980 p
.family
= AF_ETHERNET
;
981 p
.prefixlen
= ETH_ALEN
* 8;
982 p
.u
.prefix_eth
= prefix
->u
.prefix_evpn
.macip_addr
.mac
;
984 return (access_list_apply(alist
, &p
) == FILTER_DENY
? RMAP_NOMATCH
988 /* Route map `mac address' match statement. `arg' should be
990 static void *route_match_mac_address_compile(const char *arg
)
992 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
995 /* Free route map's compiled `ip address' value. */
996 static void route_match_mac_address_free(void *rule
)
998 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1001 /* Route map commands for mac address matching. */
1002 static const struct route_map_rule_cmd route_match_mac_address_cmd
= {
1004 route_match_mac_address
,
1005 route_match_mac_address_compile
,
1006 route_match_mac_address_free
1010 * Match function returns:
1011 * ...RMAP_MATCH if match is found.
1012 * ...RMAP_NOMATCH if match is not found.
1013 * ...RMAP_NOOP to ignore this match check.
1015 static enum route_map_cmd_result_t
1016 route_match_vni(void *rule
, const struct prefix
*prefix
, void *object
)
1019 unsigned int label_cnt
= 0;
1020 struct bgp_path_info
*path
= NULL
;
1021 struct prefix_evpn
*evp
= (struct prefix_evpn
*) prefix
;
1023 vni
= *((vni_t
*)rule
);
1024 path
= (struct bgp_path_info
*)object
;
1027 * This rmap filter is valid for vxlan tunnel type only.
1028 * For any other tunnel type, return noop to ignore
1031 if (path
->attr
->encap_tunneltype
!= BGP_ENCAP_TYPE_VXLAN
)
1035 * Apply filter to type 1, 2, 5 routes only.
1036 * Other route types do not have vni label.
1039 && (evp
->prefix
.route_type
!= BGP_EVPN_AD_ROUTE
1040 && evp
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
1041 && evp
->prefix
.route_type
!= BGP_EVPN_IP_PREFIX_ROUTE
))
1044 if (path
->extra
== NULL
)
1045 return RMAP_NOMATCH
;
1048 label_cnt
< BGP_MAX_LABELS
&& label_cnt
< path
->extra
->num_labels
;
1050 if (vni
== label2vni(&path
->extra
->label
[label_cnt
]))
1054 return RMAP_NOMATCH
;
1057 /* Route map `vni' match statement. */
1058 static void *route_match_vni_compile(const char *arg
)
1063 vni
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(vni_t
));
1065 *vni
= strtoul(arg
, &end
, 10);
1067 XFREE(MTYPE_ROUTE_MAP_COMPILED
, vni
);
1074 /* Free route map's compiled `vni' value. */
1075 static void route_match_vni_free(void *rule
)
1077 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1080 /* Route map commands for vni matching. */
1081 static const struct route_map_rule_cmd route_match_evpn_vni_cmd
= {
1084 route_match_vni_compile
,
1085 route_match_vni_free
1088 /* `match evpn route-type' */
1090 /* Match function should return 1 if match is success else return
1092 static enum route_map_cmd_result_t
1093 route_match_evpn_route_type(void *rule
, const struct prefix
*pfx
, void *object
)
1095 uint8_t route_type
= 0;
1097 route_type
= *((uint8_t *)rule
);
1099 if (route_type
== pfx
->u
.prefix_evpn
.route_type
)
1102 return RMAP_NOMATCH
;
1105 /* Route map `route-type' match statement. */
1106 static void *route_match_evpn_route_type_compile(const char *arg
)
1108 uint8_t *route_type
= NULL
;
1110 route_type
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
1112 if (strncmp(arg
, "ea", 2) == 0)
1113 *route_type
= BGP_EVPN_AD_ROUTE
;
1114 else if (strncmp(arg
, "ma", 2) == 0)
1115 *route_type
= BGP_EVPN_MAC_IP_ROUTE
;
1116 else if (strncmp(arg
, "mu", 2) == 0)
1117 *route_type
= BGP_EVPN_IMET_ROUTE
;
1118 else if (strncmp(arg
, "es", 2) == 0)
1119 *route_type
= BGP_EVPN_ES_ROUTE
;
1121 *route_type
= BGP_EVPN_IP_PREFIX_ROUTE
;
1126 /* Free route map's compiled `route-type' value. */
1127 static void route_match_evpn_route_type_free(void *rule
)
1129 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1132 /* Route map commands for evpn route-type matching. */
1133 static const struct route_map_rule_cmd route_match_evpn_route_type_cmd
= {
1135 route_match_evpn_route_type
,
1136 route_match_evpn_route_type_compile
,
1137 route_match_evpn_route_type_free
1142 /* Match function should return 1 if match is success else return zero. */
1143 static enum route_map_cmd_result_t
1144 route_match_rd(void *rule
, const struct prefix
*prefix
, void *object
)
1146 struct prefix_rd
*prd_rule
= NULL
;
1147 const struct prefix_rd
*prd_route
= NULL
;
1148 struct bgp_path_info
*path
= NULL
;
1150 if (prefix
->family
!= AF_EVPN
)
1151 return RMAP_NOMATCH
;
1153 prd_rule
= (struct prefix_rd
*)rule
;
1154 path
= (struct bgp_path_info
*)object
;
1156 if (path
->net
== NULL
|| path
->net
->pdest
== NULL
)
1157 return RMAP_NOMATCH
;
1159 prd_route
= (struct prefix_rd
*)bgp_dest_get_prefix(path
->net
->pdest
);
1160 if (memcmp(prd_route
->val
, prd_rule
->val
, ECOMMUNITY_SIZE
) == 0)
1163 return RMAP_NOMATCH
;
1166 /* Route map `rd' match statement. */
1167 static void *route_match_rd_compile(const char *arg
)
1169 struct prefix_rd
*prd
;
1172 prd
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct prefix_rd
));
1174 ret
= str2prefix_rd(arg
, prd
);
1176 XFREE(MTYPE_ROUTE_MAP_COMPILED
, prd
);
1183 /* Free route map's compiled `rd' value. */
1184 static void route_match_rd_free(void *rule
)
1186 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1189 /* Route map commands for rd matching. */
1190 static const struct route_map_rule_cmd route_match_evpn_rd_cmd
= {
1193 route_match_rd_compile
,
1197 static enum route_map_cmd_result_t
1198 route_set_evpn_gateway_ip(void *rule
, const struct prefix
*prefix
, void *object
)
1200 struct ipaddr
*gw_ip
= rule
;
1201 struct bgp_path_info
*path
;
1202 struct prefix_evpn
*evp
;
1204 if (prefix
->family
!= AF_EVPN
)
1207 evp
= (struct prefix_evpn
*)prefix
;
1208 if (evp
->prefix
.route_type
!= BGP_EVPN_IP_PREFIX_ROUTE
)
1211 if ((is_evpn_prefix_ipaddr_v4(evp
) && IPADDRSZ(gw_ip
) != 4)
1212 || (is_evpn_prefix_ipaddr_v6(evp
) && IPADDRSZ(gw_ip
) != 16))
1217 /* Set gateway-ip value. */
1218 path
->attr
->evpn_overlay
.type
= OVERLAY_INDEX_GATEWAY_IP
;
1219 memcpy(&path
->attr
->evpn_overlay
.gw_ip
, &gw_ip
->ip
.addr
,
1226 * Route map `evpn gateway-ip' compile function.
1227 * Given string is converted to struct ipaddr structure
1229 static void *route_set_evpn_gateway_ip_compile(const char *arg
)
1231 struct ipaddr
*gw_ip
= NULL
;
1234 gw_ip
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct ipaddr
));
1236 ret
= str2ipaddr(arg
, gw_ip
);
1238 XFREE(MTYPE_ROUTE_MAP_COMPILED
, gw_ip
);
1244 /* Free route map's compiled `evpn gateway_ip' value. */
1245 static void route_set_evpn_gateway_ip_free(void *rule
)
1247 struct ipaddr
*gw_ip
= rule
;
1249 XFREE(MTYPE_ROUTE_MAP_COMPILED
, gw_ip
);
1252 /* Route map commands for set evpn gateway-ip ipv4. */
1253 struct route_map_rule_cmd route_set_evpn_gateway_ip_ipv4_cmd
= {
1254 "evpn gateway-ip ipv4", route_set_evpn_gateway_ip
,
1255 route_set_evpn_gateway_ip_compile
, route_set_evpn_gateway_ip_free
};
1257 /* Route map commands for set evpn gateway-ip ipv6. */
1258 struct route_map_rule_cmd route_set_evpn_gateway_ip_ipv6_cmd
= {
1259 "evpn gateway-ip ipv6", route_set_evpn_gateway_ip
,
1260 route_set_evpn_gateway_ip_compile
, route_set_evpn_gateway_ip_free
};
1262 /* Route map commands for VRF route leak with source vrf matching */
1263 static enum route_map_cmd_result_t
1264 route_match_vrl_source_vrf(void *rule
, const struct prefix
*prefix
,
1267 struct bgp_path_info
*path
;
1271 path
= (struct bgp_path_info
*)object
;
1273 if (strncmp(vrf_name
, "n/a", VRF_NAMSIZ
) == 0)
1274 return RMAP_NOMATCH
;
1276 if (path
->extra
== NULL
|| path
->extra
->bgp_orig
== NULL
)
1277 return RMAP_NOMATCH
;
1279 if (strncmp(vrf_name
, vrf_id_to_name(path
->extra
->bgp_orig
->vrf_id
),
1284 return RMAP_NOMATCH
;
1287 static void *route_match_vrl_source_vrf_compile(const char *arg
)
1289 uint8_t *vrf_name
= NULL
;
1291 vrf_name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1296 /* Free route map's compiled `route-type' value. */
1297 static void route_match_vrl_source_vrf_free(void *rule
)
1299 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1302 static const struct route_map_rule_cmd route_match_vrl_source_vrf_cmd
= {
1304 route_match_vrl_source_vrf
,
1305 route_match_vrl_source_vrf_compile
,
1306 route_match_vrl_source_vrf_free
1310 static enum route_map_cmd_result_t
1311 route_match_alias(void *rule
, const struct prefix
*prefix
, void *object
)
1314 struct bgp_path_info
*path
= object
;
1319 if (bgp_attr_get_community(path
->attr
)) {
1321 frrstr_split(bgp_attr_get_community(path
->attr
)->str
, " ",
1322 &communities
, &num
);
1323 for (int i
= 0; i
< num
; i
++) {
1324 const char *com2alias
=
1325 bgp_community2alias(communities
[i
]);
1326 if (!found
&& strcmp(alias
, com2alias
) == 0)
1328 XFREE(MTYPE_TMP
, communities
[i
]);
1330 XFREE(MTYPE_TMP
, communities
);
1335 if (bgp_attr_get_lcommunity(path
->attr
)) {
1337 frrstr_split(bgp_attr_get_lcommunity(path
->attr
)->str
, " ",
1338 &communities
, &num
);
1339 for (int i
= 0; i
< num
; i
++) {
1340 const char *com2alias
=
1341 bgp_community2alias(communities
[i
]);
1342 if (!found
&& strcmp(alias
, com2alias
) == 0)
1344 XFREE(MTYPE_TMP
, communities
[i
]);
1346 XFREE(MTYPE_TMP
, communities
);
1351 return RMAP_NOMATCH
;
1354 static void *route_match_alias_compile(const char *arg
)
1357 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1360 static void route_match_alias_free(void *rule
)
1362 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1365 static const struct route_map_rule_cmd route_match_alias_cmd
= {
1366 "alias", route_match_alias
, route_match_alias_compile
,
1367 route_match_alias_free
};
1369 /* `match local-preference LOCAL-PREF' */
1371 /* Match function return 1 if match is success else return zero. */
1372 static enum route_map_cmd_result_t
1373 route_match_local_pref(void *rule
, const struct prefix
*prefix
, void *object
)
1375 uint32_t *local_pref
;
1376 struct bgp_path_info
*path
;
1381 if (path
->attr
->local_pref
== *local_pref
)
1384 return RMAP_NOMATCH
;
1388 * Route map `match local-preference' match statement.
1389 * `arg' is local-pref value
1391 static void *route_match_local_pref_compile(const char *arg
)
1393 uint32_t *local_pref
;
1394 char *endptr
= NULL
;
1395 unsigned long tmpval
;
1398 tmpval
= strtoul(arg
, &endptr
, 10);
1399 if (*endptr
!= '\0' || errno
|| tmpval
> UINT32_MAX
)
1402 local_pref
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint32_t));
1404 *local_pref
= tmpval
;
1408 /* Free route map's compiled `match local-preference' value. */
1409 static void route_match_local_pref_free(void *rule
)
1411 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1414 /* Route map commands for metric matching. */
1415 static const struct route_map_rule_cmd route_match_local_pref_cmd
= {
1417 route_match_local_pref
,
1418 route_match_local_pref_compile
,
1419 route_match_local_pref_free
1422 /* `match metric METRIC' */
1424 /* Match function return 1 if match is success else return zero. */
1425 static enum route_map_cmd_result_t
1426 route_match_metric(void *rule
, const struct prefix
*prefix
, void *object
)
1428 struct rmap_value
*rv
;
1429 struct bgp_path_info
*path
;
1433 return route_value_match(rv
, path
->attr
->med
);
1436 /* Route map commands for metric matching. */
1437 static const struct route_map_rule_cmd route_match_metric_cmd
= {
1440 route_value_compile
,
1444 /* `match as-path ASPATH' */
1446 /* Match function for as-path match. I assume given object is */
1447 static enum route_map_cmd_result_t
1448 route_match_aspath(void *rule
, const struct prefix
*prefix
, void *object
)
1451 struct as_list
*as_list
;
1452 struct bgp_path_info
*path
;
1454 as_list
= as_list_lookup((char *)rule
);
1455 if (as_list
== NULL
)
1456 return RMAP_NOMATCH
;
1460 /* Perform match. */
1461 return ((as_list_apply(as_list
, path
->attr
->aspath
) == AS_FILTER_DENY
)
1466 /* Compile function for as-path match. */
1467 static void *route_match_aspath_compile(const char *arg
)
1469 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1472 /* Compile function for as-path match. */
1473 static void route_match_aspath_free(void *rule
)
1475 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1478 /* Route map commands for aspath matching. */
1479 static const struct route_map_rule_cmd route_match_aspath_cmd
= {
1482 route_match_aspath_compile
,
1483 route_match_aspath_free
1486 /* `match community COMMUNIY' */
1487 struct rmap_community
{
1493 /* Match function for community match. */
1494 static enum route_map_cmd_result_t
1495 route_match_community(void *rule
, const struct prefix
*prefix
, void *object
)
1497 struct community_list
*list
;
1498 struct bgp_path_info
*path
;
1499 struct rmap_community
*rcom
= rule
;
1504 list
= community_list_lookup(bgp_clist
, rcom
->name
, rcom
->name_hash
,
1505 COMMUNITY_LIST_MASTER
);
1507 return RMAP_NOMATCH
;
1510 if (community_list_exact_match(
1511 bgp_attr_get_community(path
->attr
), list
))
1514 if (community_list_match(bgp_attr_get_community(path
->attr
),
1519 return RMAP_NOMATCH
;
1522 /* Compile function for community match. */
1523 static void *route_match_community_compile(const char *arg
)
1525 struct rmap_community
*rcom
;
1529 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1531 p
= strchr(arg
, ' ');
1534 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1535 memcpy(rcom
->name
, arg
, len
);
1538 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1542 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1546 /* Compile function for community match. */
1547 static void route_match_community_free(void *rule
)
1549 struct rmap_community
*rcom
= rule
;
1551 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1552 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1556 * In routemap processing there is a need to add the
1557 * name as a rule_key in the dependency table. Routemap
1558 * lib is unaware of rule_key when exact-match clause
1559 * is in use. routemap lib uses the compiled output to
1560 * get the rule_key value.
1562 static void *route_match_get_community_key(void *rule
)
1564 struct rmap_community
*rcom
;
1571 /* Route map commands for community matching. */
1572 static const struct route_map_rule_cmd route_match_community_cmd
= {
1574 route_match_community
,
1575 route_match_community_compile
,
1576 route_match_community_free
,
1577 route_match_get_community_key
1580 /* Match function for lcommunity match. */
1581 static enum route_map_cmd_result_t
1582 route_match_lcommunity(void *rule
, const struct prefix
*prefix
, void *object
)
1584 struct community_list
*list
;
1585 struct bgp_path_info
*path
;
1586 struct rmap_community
*rcom
= rule
;
1590 list
= community_list_lookup(bgp_clist
, rcom
->name
, rcom
->name_hash
,
1591 LARGE_COMMUNITY_LIST_MASTER
);
1593 return RMAP_NOMATCH
;
1596 if (lcommunity_list_exact_match(
1597 bgp_attr_get_lcommunity(path
->attr
), list
))
1600 if (lcommunity_list_match(bgp_attr_get_lcommunity(path
->attr
),
1605 return RMAP_NOMATCH
;
1608 /* Compile function for community match. */
1609 static void *route_match_lcommunity_compile(const char *arg
)
1611 struct rmap_community
*rcom
;
1615 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1617 p
= strchr(arg
, ' ');
1620 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1621 memcpy(rcom
->name
, arg
, len
);
1624 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1628 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1632 /* Compile function for community match. */
1633 static void route_match_lcommunity_free(void *rule
)
1635 struct rmap_community
*rcom
= rule
;
1637 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1638 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1641 /* Route map commands for community matching. */
1642 static const struct route_map_rule_cmd route_match_lcommunity_cmd
= {
1644 route_match_lcommunity
,
1645 route_match_lcommunity_compile
,
1646 route_match_lcommunity_free
,
1647 route_match_get_community_key
1651 /* Match function for extcommunity match. */
1652 static enum route_map_cmd_result_t
1653 route_match_ecommunity(void *rule
, const struct prefix
*prefix
, void *object
)
1655 struct community_list
*list
;
1656 struct bgp_path_info
*path
;
1657 struct rmap_community
*rcom
= rule
;
1661 list
= community_list_lookup(bgp_clist
, rcom
->name
, rcom
->name_hash
,
1662 EXTCOMMUNITY_LIST_MASTER
);
1664 return RMAP_NOMATCH
;
1666 if (ecommunity_list_match(bgp_attr_get_ecommunity(path
->attr
), list
))
1669 return RMAP_NOMATCH
;
1672 /* Compile function for extcommunity match. */
1673 static void *route_match_ecommunity_compile(const char *arg
)
1675 struct rmap_community
*rcom
;
1677 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1678 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1679 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1684 /* Compile function for extcommunity match. */
1685 static void route_match_ecommunity_free(void *rule
)
1687 struct rmap_community
*rcom
= rule
;
1689 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1690 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1693 /* Route map commands for community matching. */
1694 static const struct route_map_rule_cmd route_match_ecommunity_cmd
= {
1696 route_match_ecommunity
,
1697 route_match_ecommunity_compile
,
1698 route_match_ecommunity_free
1701 /* `match nlri` and `set nlri` are replaced by `address-family ipv4`
1702 and `address-family vpnv4'. */
1704 /* `match origin' */
1705 static enum route_map_cmd_result_t
1706 route_match_origin(void *rule
, const struct prefix
*prefix
, void *object
)
1709 struct bgp_path_info
*path
;
1714 if (path
->attr
->origin
== *origin
)
1717 return RMAP_NOMATCH
;
1720 static void *route_match_origin_compile(const char *arg
)
1724 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
1726 if (strcmp(arg
, "igp") == 0)
1728 else if (strcmp(arg
, "egp") == 0)
1736 /* Free route map's compiled `ip address' value. */
1737 static void route_match_origin_free(void *rule
)
1739 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1742 /* Route map commands for origin matching. */
1743 static const struct route_map_rule_cmd route_match_origin_cmd
= {
1746 route_match_origin_compile
,
1747 route_match_origin_free
1750 /* match probability { */
1752 static enum route_map_cmd_result_t
1753 route_match_probability(void *rule
, const struct prefix
*prefix
, void *object
)
1755 long r
= frr_weak_random();
1757 switch (*(long *)rule
) {
1763 if (r
< *(long *)rule
) {
1768 return RMAP_NOMATCH
;
1771 static void *route_match_probability_compile(const char *arg
)
1777 lobule
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(long));
1787 *lobule
= RAND_MAX
/ 100 * perc
;
1793 static void route_match_probability_free(void *rule
)
1795 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1798 static const struct route_map_rule_cmd route_match_probability_cmd
= {
1800 route_match_probability
,
1801 route_match_probability_compile
,
1802 route_match_probability_free
1805 /* `match interface IFNAME' */
1806 /* Match function should return 1 if match is success else return
1808 static enum route_map_cmd_result_t
1809 route_match_interface(void *rule
, const struct prefix
*prefix
, void *object
)
1811 struct interface
*ifp
;
1812 struct bgp_path_info
*path
;
1816 if (!path
|| !path
->peer
|| !path
->peer
->bgp
)
1817 return RMAP_NOMATCH
;
1819 ifp
= if_lookup_by_name((char *)rule
, path
->peer
->bgp
->vrf_id
);
1821 if (ifp
== NULL
|| ifp
->ifindex
!= path
->attr
->nh_ifindex
)
1822 return RMAP_NOMATCH
;
1827 /* Route map `interface' match statement. `arg' should be
1829 static void *route_match_interface_compile(const char *arg
)
1831 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1834 /* Free route map's compiled `interface' value. */
1835 static void route_match_interface_free(void *rule
)
1837 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1840 /* Route map commands for ip address matching. */
1841 static const struct route_map_rule_cmd route_match_interface_cmd
= {
1843 route_match_interface
,
1844 route_match_interface_compile
,
1845 route_match_interface_free
1850 /* `set ip next-hop IP_ADDRESS' */
1852 /* Match function return 1 if match is success else return zero. */
1853 static enum route_map_cmd_result_t
1854 route_match_tag(void *rule
, const struct prefix
*prefix
, void *object
)
1857 struct bgp_path_info
*path
;
1862 return ((path
->attr
->tag
== *tag
) ? RMAP_MATCH
: RMAP_NOMATCH
);
1866 /* Route map commands for tag matching. */
1867 static const struct route_map_rule_cmd route_match_tag_cmd
= {
1870 route_map_rule_tag_compile
,
1871 route_map_rule_tag_free
,
1874 static enum route_map_cmd_result_t
1875 route_set_srte_color(void *rule
, const struct prefix
*prefix
, void *object
)
1877 uint32_t *srte_color
= rule
;
1878 struct bgp_path_info
*path
;
1882 path
->attr
->srte_color
= *srte_color
;
1883 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_SRTE_COLOR
);
1888 /* Route map `sr-te color' compile function */
1889 static void *route_set_srte_color_compile(const char *arg
)
1893 color
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint32_t));
1899 /* Free route map's compiled `sr-te color' value. */
1900 static void route_set_srte_color_free(void *rule
)
1902 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1905 /* Route map commands for sr-te color set. */
1906 struct route_map_rule_cmd route_set_srte_color_cmd
= {
1907 "sr-te color", route_set_srte_color
, route_set_srte_color_compile
,
1908 route_set_srte_color_free
};
1910 /* Set nexthop to object. object must be pointer to struct attr. */
1911 struct rmap_ip_nexthop_set
{
1912 struct in_addr
*address
;
1917 static enum route_map_cmd_result_t
1918 route_set_ip_nexthop(void *rule
, const struct prefix
*prefix
, void *object
)
1920 struct rmap_ip_nexthop_set
*rins
= rule
;
1921 struct bgp_path_info
*path
;
1924 if (prefix
->family
== AF_INET6
)
1930 if (rins
->unchanged
) {
1931 SET_FLAG(path
->attr
->rmap_change_flags
,
1932 BATTR_RMAP_NEXTHOP_UNCHANGED
);
1933 } else if (rins
->peer_address
) {
1934 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
1935 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
1937 && sockunion_family(peer
->su_remote
) == AF_INET
) {
1938 path
->attr
->nexthop
.s_addr
=
1939 sockunion2ip(peer
->su_remote
);
1940 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1941 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
1942 /* The next hop value will be set as part of
1943 * packet rewrite. Set the flags here to indicate
1944 * that rewrite needs to be done.
1945 * Also, clear the value.
1947 SET_FLAG(path
->attr
->rmap_change_flags
,
1948 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
1949 path
->attr
->nexthop
.s_addr
= INADDR_ANY
;
1952 /* Set next hop value. */
1953 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1954 path
->attr
->nexthop
= *rins
->address
;
1955 SET_FLAG(path
->attr
->rmap_change_flags
,
1956 BATTR_RMAP_IPV4_NHOP_CHANGED
);
1957 /* case for MP-BGP : MPLS VPN */
1958 path
->attr
->mp_nexthop_global_in
= *rins
->address
;
1959 path
->attr
->mp_nexthop_len
= sizeof(*rins
->address
);
1965 /* Route map `ip nexthop' compile function. Given string is converted
1966 to struct in_addr structure. */
1967 static void *route_set_ip_nexthop_compile(const char *arg
)
1969 struct rmap_ip_nexthop_set
*rins
;
1970 struct in_addr
*address
= NULL
;
1971 int peer_address
= 0;
1975 if (strcmp(arg
, "peer-address") == 0)
1977 else if (strcmp(arg
, "unchanged") == 0)
1980 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1981 sizeof(struct in_addr
));
1982 ret
= inet_aton(arg
, address
);
1985 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
1990 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1991 sizeof(struct rmap_ip_nexthop_set
));
1993 rins
->address
= address
;
1994 rins
->peer_address
= peer_address
;
1995 rins
->unchanged
= unchanged
;
2000 /* Free route map's compiled `ip nexthop' value. */
2001 static void route_set_ip_nexthop_free(void *rule
)
2003 struct rmap_ip_nexthop_set
*rins
= rule
;
2005 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
->address
);
2007 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
);
2010 /* Route map commands for ip nexthop set. */
2011 static const struct route_map_rule_cmd route_set_ip_nexthop_cmd
= {
2013 route_set_ip_nexthop
,
2014 route_set_ip_nexthop_compile
,
2015 route_set_ip_nexthop_free
2018 /* `set l3vpn next-hop encapsulation l3vpn gre' */
2020 /* Set nexthop to object */
2021 struct rmap_l3vpn_nexthop_encapsulation_set
{
2025 static enum route_map_cmd_result_t
2026 route_set_l3vpn_nexthop_encapsulation(void *rule
, const struct prefix
*prefix
,
2029 struct rmap_l3vpn_nexthop_encapsulation_set
*rins
= rule
;
2030 struct bgp_path_info
*path
;
2034 if (rins
->protocol
!= IPPROTO_GRE
)
2037 SET_FLAG(path
->attr
->rmap_change_flags
, BATTR_RMAP_L3VPN_ACCEPT_GRE
);
2041 /* Route map `l3vpn nexthop encapsulation' compile function. */
2042 static void *route_set_l3vpn_nexthop_encapsulation_compile(const char *arg
)
2044 struct rmap_l3vpn_nexthop_encapsulation_set
*rins
;
2046 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
2047 sizeof(struct rmap_l3vpn_nexthop_encapsulation_set
));
2049 /* XXX ALL GRE modes are accepted for now: gre or ip6gre */
2050 rins
->protocol
= IPPROTO_GRE
;
2055 /* Free route map's compiled `ip nexthop' value. */
2056 static void route_set_l3vpn_nexthop_encapsulation_free(void *rule
)
2058 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2061 /* Route map commands for l3vpn next-hop encapsulation set. */
2062 static const struct route_map_rule_cmd
2063 route_set_l3vpn_nexthop_encapsulation_cmd
= {
2064 "l3vpn next-hop encapsulation",
2065 route_set_l3vpn_nexthop_encapsulation
,
2066 route_set_l3vpn_nexthop_encapsulation_compile
,
2067 route_set_l3vpn_nexthop_encapsulation_free
};
2069 /* `set local-preference LOCAL_PREF' */
2071 /* Set local preference. */
2072 static enum route_map_cmd_result_t
2073 route_set_local_pref(void *rule
, const struct prefix
*prefix
, void *object
)
2075 struct rmap_value
*rv
;
2076 struct bgp_path_info
*path
;
2077 uint32_t locpref
= 0;
2079 /* Fetch routemap's rule information. */
2083 /* Set local preference value. */
2084 if (path
->attr
->local_pref
)
2085 locpref
= path
->attr
->local_pref
;
2087 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
);
2088 path
->attr
->local_pref
= route_value_adjust(rv
, locpref
, path
->peer
);
2093 /* Set local preference rule structure. */
2094 static const struct route_map_rule_cmd route_set_local_pref_cmd
= {
2096 route_set_local_pref
,
2097 route_value_compile
,
2101 /* `set weight WEIGHT' */
2104 static enum route_map_cmd_result_t
2105 route_set_weight(void *rule
, const struct prefix
*prefix
, void *object
)
2107 struct rmap_value
*rv
;
2108 struct bgp_path_info
*path
;
2110 /* Fetch routemap's rule information. */
2114 /* Set weight value. */
2115 path
->attr
->weight
= route_value_adjust(rv
, 0, path
->peer
);
2120 /* Set local preference rule structure. */
2121 static const struct route_map_rule_cmd route_set_weight_cmd
= {
2124 route_value_compile
,
2128 /* `set distance DISTANCE */
2129 static enum route_map_cmd_result_t
2130 route_set_distance(void *rule
, const struct prefix
*prefix
, void *object
)
2132 struct bgp_path_info
*path
= object
;
2133 struct rmap_value
*rv
= rule
;
2135 path
->attr
->distance
= rv
->value
;
2140 /* set distance rule structure */
2141 static const struct route_map_rule_cmd route_set_distance_cmd
= {
2144 route_value_compile
,
2148 /* `set metric METRIC' */
2150 /* Set metric to attribute. */
2151 static enum route_map_cmd_result_t
2152 route_set_metric(void *rule
, const struct prefix
*prefix
, void *object
)
2154 struct rmap_value
*rv
;
2155 struct bgp_path_info
*path
;
2158 /* Fetch routemap's rule information. */
2162 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
))
2163 med
= path
->attr
->med
;
2165 path
->attr
->med
= route_value_adjust(rv
, med
, path
->peer
);
2166 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
);
2171 /* Set metric rule structure. */
2172 static const struct route_map_rule_cmd route_set_metric_cmd
= {
2175 route_value_compile
,
2179 /* `set table (1-4294967295)' */
2181 static enum route_map_cmd_result_t
2182 route_set_table_id(void *rule
, const struct prefix
*prefix
,
2186 struct rmap_value
*rv
;
2187 struct bgp_path_info
*path
;
2189 /* Fetch routemap's rule information. */
2193 path
->attr
->rmap_table_id
= rv
->value
;
2198 /* Set table_id rule structure. */
2199 static const struct route_map_rule_cmd route_set_table_id_cmd
= {
2202 route_value_compile
,
2206 /* `set as-path prepend ASPATH' */
2208 /* For AS path prepend mechanism. */
2209 static enum route_map_cmd_result_t
2210 route_set_aspath_prepend(void *rule
, const struct prefix
*prefix
, void *object
)
2212 struct aspath
*aspath
;
2214 struct bgp_path_info
*path
;
2218 if (path
->attr
->aspath
->refcnt
)
2219 new = aspath_dup(path
->attr
->aspath
);
2221 new = path
->attr
->aspath
;
2223 if ((uintptr_t)rule
> 10) {
2225 aspath_prepend(aspath
, new);
2227 as_t as
= aspath_leftmost(new);
2229 new = aspath_add_seq_n(new, as
, (uintptr_t)rule
);
2232 path
->attr
->aspath
= new;
2237 static void *route_set_aspath_prepend_compile(const char *arg
)
2241 if (sscanf(arg
, "last-as %u", &num
) == 1 && num
> 0 && num
<= 10)
2242 return (void *)(uintptr_t)num
;
2244 return route_aspath_compile(arg
);
2247 static void route_set_aspath_prepend_free(void *rule
)
2249 if ((uintptr_t)rule
> 10)
2250 route_aspath_free(rule
);
2254 /* Set as-path prepend rule structure. */
2255 static const struct route_map_rule_cmd route_set_aspath_prepend_cmd
= {
2257 route_set_aspath_prepend
,
2258 route_set_aspath_prepend_compile
,
2259 route_set_aspath_prepend_free
,
2262 /* `set as-path exclude ASn' */
2264 /* For ASN exclude mechanism.
2265 * Iterate over ASns requested and filter them from the given AS_PATH one by
2267 * Make a deep copy of existing AS_PATH, but for the first ASn only.
2269 static enum route_map_cmd_result_t
2270 route_set_aspath_exclude(void *rule
, const struct prefix
*dummy
, void *object
)
2272 struct aspath
*new_path
, *exclude_path
;
2273 struct bgp_path_info
*path
;
2275 exclude_path
= rule
;
2277 if (path
->attr
->aspath
->refcnt
)
2278 new_path
= aspath_dup(path
->attr
->aspath
);
2280 new_path
= path
->attr
->aspath
;
2281 path
->attr
->aspath
= aspath_filter_exclude(new_path
, exclude_path
);
2286 /* Set ASn exlude rule structure. */
2287 static const struct route_map_rule_cmd route_set_aspath_exclude_cmd
= {
2289 route_set_aspath_exclude
,
2290 route_aspath_compile
,
2294 /* `set as-path replace AS-PATH` */
2295 static void *route_aspath_replace_compile(const char *arg
)
2297 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2300 static void route_aspath_replace_free(void *rule
)
2302 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2305 static enum route_map_cmd_result_t
2306 route_set_aspath_replace(void *rule
, const struct prefix
*dummy
, void *object
)
2308 struct aspath
*aspath_new
;
2309 const char *replace
= rule
;
2310 struct bgp_path_info
*path
= object
;
2311 as_t own_asn
= path
->peer
->change_local_as
? path
->peer
->change_local_as
2312 : path
->peer
->local_as
;
2314 if (path
->peer
->sort
!= BGP_PEER_EBGP
) {
2316 "`set as-path replace` is supported only for EBGP peers");
2320 if (path
->attr
->aspath
->refcnt
)
2321 aspath_new
= aspath_dup(path
->attr
->aspath
);
2323 aspath_new
= path
->attr
->aspath
;
2325 if (strmatch(replace
, "any")) {
2326 path
->attr
->aspath
=
2327 aspath_replace_all_asn(aspath_new
, own_asn
);
2329 as_t replace_asn
= strtoul(replace
, NULL
, 10);
2331 path
->attr
->aspath
= aspath_replace_specific_asn(
2332 aspath_new
, replace_asn
, own_asn
);
2335 aspath_free(aspath_new
);
2340 static const struct route_map_rule_cmd route_set_aspath_replace_cmd
= {
2342 route_set_aspath_replace
,
2343 route_aspath_replace_compile
,
2344 route_aspath_replace_free
,
2347 /* `set community COMMUNITY' */
2348 struct rmap_com_set
{
2349 struct community
*com
;
2354 /* For community set mechanism. */
2355 static enum route_map_cmd_result_t
2356 route_set_community(void *rule
, const struct prefix
*prefix
, void *object
)
2358 struct rmap_com_set
*rcs
;
2359 struct bgp_path_info
*path
;
2361 struct community
*new = NULL
;
2362 struct community
*old
;
2363 struct community
*merge
;
2368 old
= bgp_attr_get_community(attr
);
2372 bgp_attr_set_community(attr
, NULL
);
2373 /* See the longer comment down below. */
2374 if (old
&& old
->refcnt
== 0)
2375 community_free(&old
);
2379 /* "additive" case. */
2380 if (rcs
->additive
&& old
) {
2381 merge
= community_merge(community_dup(old
), rcs
->com
);
2383 new = community_uniq_sort(merge
);
2384 community_free(&merge
);
2386 new = community_dup(rcs
->com
);
2388 /* HACK: if the old community is not intern'd,
2389 * we should free it here, or all reference to it may be
2391 * Really need to cleanup attribute caching sometime.
2393 if (old
&& old
->refcnt
== 0)
2394 community_free(&old
);
2396 /* will be interned by caller if required */
2397 bgp_attr_set_community(attr
, new);
2402 /* Compile function for set community. */
2403 static void *route_set_community_compile(const char *arg
)
2405 struct rmap_com_set
*rcs
;
2406 struct community
*com
= NULL
;
2411 if (strcmp(arg
, "none") == 0)
2414 sp
= strstr(arg
, "additive");
2416 if (sp
&& sp
> arg
) {
2417 /* "additive" keyword is included. */
2422 com
= community_str2com(arg
);
2431 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
2433 rcs
->additive
= additive
;
2439 /* Free function for set community. */
2440 static void route_set_community_free(void *rule
)
2442 struct rmap_com_set
*rcs
= rule
;
2445 community_free(&rcs
->com
);
2446 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
2449 /* Set community rule structure. */
2450 static const struct route_map_rule_cmd route_set_community_cmd
= {
2452 route_set_community
,
2453 route_set_community_compile
,
2454 route_set_community_free
,
2457 /* `set community COMMUNITY' */
2458 struct rmap_lcom_set
{
2459 struct lcommunity
*lcom
;
2465 /* For lcommunity set mechanism. */
2466 static enum route_map_cmd_result_t
2467 route_set_lcommunity(void *rule
, const struct prefix
*prefix
, void *object
)
2469 struct rmap_lcom_set
*rcs
;
2470 struct bgp_path_info
*path
;
2472 struct lcommunity
*new = NULL
;
2473 struct lcommunity
*old
;
2474 struct lcommunity
*merge
;
2479 old
= bgp_attr_get_lcommunity(attr
);
2483 bgp_attr_set_lcommunity(attr
, NULL
);
2485 /* See the longer comment down below. */
2486 if (old
&& old
->refcnt
== 0)
2487 lcommunity_free(&old
);
2491 if (rcs
->additive
&& old
) {
2492 merge
= lcommunity_merge(lcommunity_dup(old
), rcs
->lcom
);
2494 new = lcommunity_uniq_sort(merge
);
2495 lcommunity_free(&merge
);
2497 new = lcommunity_dup(rcs
->lcom
);
2499 /* HACK: if the old large-community is not intern'd,
2500 * we should free it here, or all reference to it may be
2502 * Really need to cleanup attribute caching sometime.
2504 if (old
&& old
->refcnt
== 0)
2505 lcommunity_free(&old
);
2507 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
2508 bgp_attr_set_lcommunity(attr
, new);
2513 /* Compile function for set community. */
2514 static void *route_set_lcommunity_compile(const char *arg
)
2516 struct rmap_lcom_set
*rcs
;
2517 struct lcommunity
*lcom
= NULL
;
2522 if (strcmp(arg
, "none") == 0)
2525 sp
= strstr(arg
, "additive");
2527 if (sp
&& sp
> arg
) {
2528 /* "additive" keyworkd is included. */
2533 lcom
= lcommunity_str2com(arg
);
2542 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
2544 rcs
->additive
= additive
;
2550 /* Free function for set lcommunity. */
2551 static void route_set_lcommunity_free(void *rule
)
2553 struct rmap_lcom_set
*rcs
= rule
;
2556 lcommunity_free(&rcs
->lcom
);
2558 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
2561 /* Set community rule structure. */
2562 static const struct route_map_rule_cmd route_set_lcommunity_cmd
= {
2564 route_set_lcommunity
,
2565 route_set_lcommunity_compile
,
2566 route_set_lcommunity_free
,
2569 /* `set large-comm-list (<1-99>|<100-500>|WORD) delete' */
2571 /* For large community set mechanism. */
2572 static enum route_map_cmd_result_t
2573 route_set_lcommunity_delete(void *rule
, const struct prefix
*pfx
, void *object
)
2575 struct community_list
*list
;
2576 struct lcommunity
*merge
;
2577 struct lcommunity
*new;
2578 struct lcommunity
*old
;
2579 struct bgp_path_info
*path
;
2580 struct rmap_community
*rcom
= rule
;
2586 list
= community_list_lookup(bgp_clist
, rcom
->name
, rcom
->name_hash
,
2587 LARGE_COMMUNITY_LIST_MASTER
);
2588 old
= bgp_attr_get_lcommunity(path
->attr
);
2591 merge
= lcommunity_list_match_delete(lcommunity_dup(old
), list
);
2592 new = lcommunity_uniq_sort(merge
);
2593 lcommunity_free(&merge
);
2595 /* HACK: if the old community is not intern'd,
2596 * we should free it here, or all reference to it may be
2598 * Really need to cleanup attribute caching sometime.
2600 if (old
->refcnt
== 0)
2601 lcommunity_free(&old
);
2603 if (new->size
== 0) {
2604 bgp_attr_set_lcommunity(path
->attr
, NULL
);
2605 lcommunity_free(&new);
2607 bgp_attr_set_lcommunity(path
->attr
, new);
2614 /* Compile function for set lcommunity. */
2615 static void *route_set_lcommunity_delete_compile(const char *arg
)
2617 struct rmap_community
*rcom
;
2621 frrstr_split(arg
, " ", &splits
, &num
);
2623 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2624 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, splits
[0]);
2625 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2627 for (int i
= 0; i
< num
; i
++)
2628 XFREE(MTYPE_TMP
, splits
[i
]);
2629 XFREE(MTYPE_TMP
, splits
);
2634 /* Free function for set lcommunity. */
2635 static void route_set_lcommunity_delete_free(void *rule
)
2637 struct rmap_community
*rcom
= rule
;
2639 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2640 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2643 /* Set lcommunity rule structure. */
2644 static const struct route_map_rule_cmd route_set_lcommunity_delete_cmd
= {
2646 route_set_lcommunity_delete
,
2647 route_set_lcommunity_delete_compile
,
2648 route_set_lcommunity_delete_free
,
2652 /* `set comm-list (<1-99>|<100-500>|WORD) delete' */
2654 /* For community set mechanism. */
2655 static enum route_map_cmd_result_t
2656 route_set_community_delete(void *rule
, const struct prefix
*prefix
,
2659 struct community_list
*list
;
2660 struct community
*merge
;
2661 struct community
*new;
2662 struct community
*old
;
2663 struct bgp_path_info
*path
;
2664 struct rmap_community
*rcom
= rule
;
2670 list
= community_list_lookup(bgp_clist
, rcom
->name
, rcom
->name_hash
,
2671 COMMUNITY_LIST_MASTER
);
2672 old
= bgp_attr_get_community(path
->attr
);
2675 merge
= community_list_match_delete(community_dup(old
), list
);
2676 new = community_uniq_sort(merge
);
2677 community_free(&merge
);
2679 /* HACK: if the old community is not intern'd,
2680 * we should free it here, or all reference to it may be
2682 * Really need to cleanup attribute caching sometime.
2684 if (old
->refcnt
== 0)
2685 community_free(&old
);
2687 if (new->size
== 0) {
2688 bgp_attr_set_community(path
->attr
, NULL
);
2689 community_free(&new);
2691 bgp_attr_set_community(path
->attr
, new);
2698 /* Compile function for set community. */
2699 static void *route_set_community_delete_compile(const char *arg
)
2701 struct rmap_community
*rcom
;
2705 frrstr_split(arg
, " ", &splits
, &num
);
2707 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2708 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, splits
[0]);
2709 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2711 for (int i
= 0; i
< num
; i
++)
2712 XFREE(MTYPE_TMP
, splits
[i
]);
2713 XFREE(MTYPE_TMP
, splits
);
2718 /* Free function for set community. */
2719 static void route_set_community_delete_free(void *rule
)
2721 struct rmap_community
*rcom
= rule
;
2723 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2724 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2727 /* Set community rule structure. */
2728 static const struct route_map_rule_cmd route_set_community_delete_cmd
= {
2730 route_set_community_delete
,
2731 route_set_community_delete_compile
,
2732 route_set_community_delete_free
,
2735 /* `set extcommunity rt COMMUNITY' */
2737 struct rmap_ecom_set
{
2738 struct ecommunity
*ecom
;
2742 /* For community set mechanism. Used by _rt and _soo. */
2743 static enum route_map_cmd_result_t
2744 route_set_ecommunity(void *rule
, const struct prefix
*prefix
, void *object
)
2746 struct rmap_ecom_set
*rcs
;
2747 struct ecommunity
*new_ecom
;
2748 struct ecommunity
*old_ecom
;
2749 struct bgp_path_info
*path
;
2757 bgp_attr_set_ecommunity(attr
, NULL
);
2764 /* We assume additive for Extended Community. */
2765 old_ecom
= bgp_attr_get_ecommunity(path
->attr
);
2769 ecommunity_merge(ecommunity_dup(old_ecom
), rcs
->ecom
);
2771 /* old_ecom->refcnt = 1 => owned elsewhere, e.g.
2772 * bgp_update_receive()
2773 * ->refcnt = 0 => set by a previous route-map
2775 if (!old_ecom
->refcnt
)
2776 ecommunity_free(&old_ecom
);
2778 new_ecom
= ecommunity_dup(rcs
->ecom
);
2780 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
2781 bgp_attr_set_ecommunity(path
->attr
, new_ecom
);
2786 static void *route_set_ecommunity_none_compile(const char *arg
)
2788 struct rmap_ecom_set
*rcs
;
2791 if (strncmp(arg
, "none", 4) == 0)
2794 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_ecom_set
));
2801 static void *route_set_ecommunity_rt_compile(const char *arg
)
2803 struct rmap_ecom_set
*rcs
;
2804 struct ecommunity
*ecom
;
2806 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_ROUTE_TARGET
, 0);
2810 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_ecom_set
));
2811 rcs
->ecom
= ecommunity_intern(ecom
);
2817 /* Free function for set community. Used by _rt and _soo */
2818 static void route_set_ecommunity_free(void *rule
)
2820 struct rmap_ecom_set
*rcs
= rule
;
2823 ecommunity_unintern(&rcs
->ecom
);
2825 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
2828 static const struct route_map_rule_cmd route_set_ecommunity_none_cmd
= {
2830 route_set_ecommunity
,
2831 route_set_ecommunity_none_compile
,
2832 route_set_ecommunity_free
,
2835 /* Set community rule structure. */
2836 static const struct route_map_rule_cmd route_set_ecommunity_rt_cmd
= {
2838 route_set_ecommunity
,
2839 route_set_ecommunity_rt_compile
,
2840 route_set_ecommunity_free
,
2843 /* `set extcommunity soo COMMUNITY' */
2845 /* Compile function for set community. */
2846 static void *route_set_ecommunity_soo_compile(const char *arg
)
2848 struct rmap_ecom_set
*rcs
;
2849 struct ecommunity
*ecom
;
2851 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_SITE_ORIGIN
, 0);
2855 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_ecom_set
));
2856 rcs
->ecom
= ecommunity_intern(ecom
);
2862 /* Set community rule structure. */
2863 static const struct route_map_rule_cmd route_set_ecommunity_soo_cmd
= {
2865 route_set_ecommunity
,
2866 route_set_ecommunity_soo_compile
,
2867 route_set_ecommunity_free
,
2870 /* `set extcommunity bandwidth' */
2872 struct rmap_ecomm_lb_set
{
2874 #define RMAP_ECOMM_LB_SET_VALUE 1
2875 #define RMAP_ECOMM_LB_SET_CUMUL 2
2876 #define RMAP_ECOMM_LB_SET_NUM_MPATH 3
2881 static enum route_map_cmd_result_t
2882 route_set_ecommunity_lb(void *rule
, const struct prefix
*prefix
, void *object
)
2884 struct rmap_ecomm_lb_set
*rels
= rule
;
2885 struct bgp_path_info
*path
;
2887 struct ecommunity ecom_lb
= {0};
2888 struct ecommunity_val lb_eval
;
2889 uint32_t bw_bytes
= 0;
2890 uint16_t mpath_count
= 0;
2891 struct ecommunity
*new_ecom
;
2892 struct ecommunity
*old_ecom
;
2897 if (!peer
|| !peer
->bgp
)
2900 /* Build link bandwidth extended community */
2901 as
= (peer
->bgp
->as
> BGP_AS_MAX
) ? BGP_AS_TRANS
: peer
->bgp
->as
;
2902 if (rels
->lb_type
== RMAP_ECOMM_LB_SET_VALUE
) {
2903 bw_bytes
= ((uint64_t)rels
->bw
* 1000 * 1000) / 8;
2904 } else if (rels
->lb_type
== RMAP_ECOMM_LB_SET_CUMUL
) {
2905 /* process this only for the best path. */
2906 if (!CHECK_FLAG(path
->flags
, BGP_PATH_SELECTED
))
2909 bw_bytes
= (uint32_t)bgp_path_info_mpath_cumbw(path
);
2913 } else if (rels
->lb_type
== RMAP_ECOMM_LB_SET_NUM_MPATH
) {
2915 /* process this only for the best path. */
2916 if (!CHECK_FLAG(path
->flags
, BGP_PATH_SELECTED
))
2919 bw_bytes
= ((uint64_t)peer
->bgp
->lb_ref_bw
* 1000 * 1000) / 8;
2920 mpath_count
= bgp_path_info_mpath_count(path
) + 1;
2921 bw_bytes
*= mpath_count
;
2924 encode_lb_extcomm(as
, bw_bytes
, rels
->non_trans
, &lb_eval
,
2925 CHECK_FLAG(peer
->flags
,
2926 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE
));
2928 /* add to route or merge with existing */
2929 old_ecom
= bgp_attr_get_ecommunity(path
->attr
);
2931 new_ecom
= ecommunity_dup(old_ecom
);
2932 ecommunity_add_val(new_ecom
, &lb_eval
, true, true);
2933 if (!old_ecom
->refcnt
)
2934 ecommunity_free(&old_ecom
);
2937 ecom_lb
.unit_size
= ECOMMUNITY_SIZE
;
2938 ecom_lb
.val
= (uint8_t *)lb_eval
.val
;
2939 new_ecom
= ecommunity_dup(&ecom_lb
);
2942 /* new_ecom will be intern()'d or attr_flush()'d in call stack */
2943 bgp_attr_set_ecommunity(path
->attr
, new_ecom
);
2945 /* Mark that route-map has set link bandwidth; used in attribute
2946 * setting decisions.
2948 SET_FLAG(path
->attr
->rmap_change_flags
, BATTR_RMAP_LINK_BW_SET
);
2953 static void *route_set_ecommunity_lb_compile(const char *arg
)
2955 struct rmap_ecomm_lb_set
*rels
;
2958 char bw_str
[40] = {0};
2960 bool non_trans
= false;
2963 p
= strchr(arg
, ' ');
2968 memcpy(bw_str
, arg
, len
);
2973 if (strcmp(str
, "cumulative") == 0)
2974 lb_type
= RMAP_ECOMM_LB_SET_CUMUL
;
2975 else if (strcmp(str
, "num-multipaths") == 0)
2976 lb_type
= RMAP_ECOMM_LB_SET_NUM_MPATH
;
2980 bw
= strtoul(str
, &end
, 10);
2983 lb_type
= RMAP_ECOMM_LB_SET_VALUE
;
2986 rels
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
2987 sizeof(struct rmap_ecomm_lb_set
));
2988 rels
->lb_type
= lb_type
;
2990 rels
->non_trans
= non_trans
;
2995 static void route_set_ecommunity_lb_free(void *rule
)
2997 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3000 /* Set community rule structure. */
3001 struct route_map_rule_cmd route_set_ecommunity_lb_cmd
= {
3002 "extcommunity bandwidth",
3003 route_set_ecommunity_lb
,
3004 route_set_ecommunity_lb_compile
,
3005 route_set_ecommunity_lb_free
,
3008 /* `set origin ORIGIN' */
3010 /* For origin set. */
3011 static enum route_map_cmd_result_t
3012 route_set_origin(void *rule
, const struct prefix
*prefix
, void *object
)
3015 struct bgp_path_info
*path
;
3020 path
->attr
->origin
= *origin
;
3025 /* Compile function for origin set. */
3026 static void *route_set_origin_compile(const char *arg
)
3030 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
3032 if (strcmp(arg
, "igp") == 0)
3033 *origin
= BGP_ORIGIN_IGP
;
3034 else if (strcmp(arg
, "egp") == 0)
3035 *origin
= BGP_ORIGIN_EGP
;
3037 *origin
= BGP_ORIGIN_INCOMPLETE
;
3042 /* Compile function for origin set. */
3043 static void route_set_origin_free(void *rule
)
3045 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3048 /* Set origin rule structure. */
3049 static const struct route_map_rule_cmd route_set_origin_cmd
= {
3052 route_set_origin_compile
,
3053 route_set_origin_free
,
3056 /* `set atomic-aggregate' */
3058 /* For atomic aggregate set. */
3059 static enum route_map_cmd_result_t
3060 route_set_atomic_aggregate(void *rule
, const struct prefix
*pfx
, void *object
)
3062 struct bgp_path_info
*path
;
3065 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE
);
3070 /* Compile function for atomic aggregate. */
3071 static void *route_set_atomic_aggregate_compile(const char *arg
)
3076 /* Compile function for atomic aggregate. */
3077 static void route_set_atomic_aggregate_free(void *rule
)
3082 /* Set atomic aggregate rule structure. */
3083 static const struct route_map_rule_cmd route_set_atomic_aggregate_cmd
= {
3085 route_set_atomic_aggregate
,
3086 route_set_atomic_aggregate_compile
,
3087 route_set_atomic_aggregate_free
,
3090 /* AIGP TLV Metric */
3091 static enum route_map_cmd_result_t
3092 route_set_aigp_metric(void *rule
, const struct prefix
*pfx
, void *object
)
3094 const char *aigp_metric
= rule
;
3095 struct bgp_path_info
*path
= object
;
3098 if (strmatch(aigp_metric
, "igp-metric")) {
3100 return RMAP_NOMATCH
;
3102 bgp_attr_set_aigp_metric(path
->attr
, path
->nexthop
->metric
);
3104 aigp
= atoi(aigp_metric
);
3105 bgp_attr_set_aigp_metric(path
->attr
, aigp
);
3108 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_AIGP
);
3113 static void *route_set_aigp_metric_compile(const char *arg
)
3115 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
3118 static void route_set_aigp_metric_free(void *rule
)
3120 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3123 static const struct route_map_rule_cmd route_set_aigp_metric_cmd
= {
3125 route_set_aigp_metric
,
3126 route_set_aigp_metric_compile
,
3127 route_set_aigp_metric_free
,
3130 /* `set aggregator as AS A.B.C.D' */
3133 struct in_addr address
;
3136 static enum route_map_cmd_result_t
3137 route_set_aggregator_as(void *rule
, const struct prefix
*prefix
, void *object
)
3139 struct bgp_path_info
*path
;
3140 struct aggregator
*aggregator
;
3145 path
->attr
->aggregator_as
= aggregator
->as
;
3146 path
->attr
->aggregator_addr
= aggregator
->address
;
3147 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR
);
3152 static void *route_set_aggregator_as_compile(const char *arg
)
3154 struct aggregator
*aggregator
;
3160 XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct aggregator
));
3161 if (sscanf(arg
, "%s %s", as
, address
) != 2) {
3162 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
3166 aggregator
->as
= strtoul(as
, NULL
, 10);
3167 ret
= inet_aton(address
, &aggregator
->address
);
3169 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
3175 static void route_set_aggregator_as_free(void *rule
)
3177 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3180 static const struct route_map_rule_cmd route_set_aggregator_as_cmd
= {
3182 route_set_aggregator_as
,
3183 route_set_aggregator_as_compile
,
3184 route_set_aggregator_as_free
,
3187 /* Set tag to object. object must be pointer to struct bgp_path_info */
3188 static enum route_map_cmd_result_t
3189 route_set_tag(void *rule
, const struct prefix
*prefix
, void *object
)
3192 struct bgp_path_info
*path
;
3198 path
->attr
->tag
= *tag
;
3203 /* Route map commands for tag set. */
3204 static const struct route_map_rule_cmd route_set_tag_cmd
= {
3207 route_map_rule_tag_compile
,
3208 route_map_rule_tag_free
,
3211 /* Set label-index to object. object must be pointer to struct bgp_path_info */
3212 static enum route_map_cmd_result_t
3213 route_set_label_index(void *rule
, const struct prefix
*prefix
, void *object
)
3215 struct rmap_value
*rv
;
3216 struct bgp_path_info
*path
;
3217 uint32_t label_index
;
3219 /* Fetch routemap's rule information. */
3223 /* Set label-index value. */
3224 label_index
= rv
->value
;
3226 path
->attr
->label_index
= label_index
;
3227 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID
);
3233 /* Route map commands for label-index set. */
3234 static const struct route_map_rule_cmd route_set_label_index_cmd
= {
3236 route_set_label_index
,
3237 route_value_compile
,
3241 /* `match ipv6 address IP_ACCESS_LIST' */
3243 static enum route_map_cmd_result_t
3244 route_match_ipv6_address(void *rule
, const struct prefix
*prefix
, void *object
)
3246 struct access_list
*alist
;
3248 if (prefix
->family
== AF_INET6
) {
3249 alist
= access_list_lookup(AFI_IP6
, (char *)rule
);
3250 if (alist
== NULL
) {
3251 if (unlikely(CHECK_FLAG(rmap_debug
,
3252 DEBUG_ROUTEMAP_DETAIL
)))
3254 "%s: Access-List Specified: %s does not exist defaulting to NO_MATCH",
3255 __func__
, (char *)rule
);
3257 return RMAP_NOMATCH
;
3260 return (access_list_apply(alist
, prefix
) == FILTER_DENY
3264 return RMAP_NOMATCH
;
3267 static void *route_match_ipv6_address_compile(const char *arg
)
3269 struct access_list
*alist
;
3271 alist
= access_list_lookup(AFI_IP6
, arg
);
3274 "Access List specified %s does not exist yet, default will be NO_MATCH until it is created",
3277 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
3280 static void route_match_ipv6_address_free(void *rule
)
3282 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3285 /* Route map commands for ip address matching. */
3286 static const struct route_map_rule_cmd route_match_ipv6_address_cmd
= {
3288 route_match_ipv6_address
,
3289 route_match_ipv6_address_compile
,
3290 route_match_ipv6_address_free
3293 /* `match ipv6 next-hop ACCESSLIST6_NAME' */
3294 static enum route_map_cmd_result_t
3295 route_match_ipv6_next_hop(void *rule
, const struct prefix
*prefix
, void *object
)
3297 struct bgp_path_info
*path
;
3298 struct access_list
*alist
;
3299 struct prefix_ipv6 p
;
3301 if (prefix
->family
== AF_INET6
) {
3303 p
.family
= AF_INET6
;
3304 p
.prefix
= path
->attr
->mp_nexthop_global
;
3305 p
.prefixlen
= IPV6_MAX_BITLEN
;
3307 alist
= access_list_lookup(AFI_IP6
, (char *)rule
);
3309 if (unlikely(CHECK_FLAG(rmap_debug
,
3310 DEBUG_ROUTEMAP_DETAIL
)))
3312 "%s: Access-List Specified: %s does not exist defaulting to NO_MATCH",
3313 __func__
, (char *)rule
);
3315 return RMAP_NOMATCH
;
3318 if (access_list_apply(alist
, &p
) == FILTER_PERMIT
)
3321 if (path
->attr
->mp_nexthop_len
3322 == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
) {
3323 p
.prefix
= path
->attr
->mp_nexthop_local
;
3324 if (access_list_apply(alist
, &p
) == FILTER_PERMIT
)
3329 return RMAP_NOMATCH
;
3332 static void *route_match_ipv6_next_hop_compile(const char *arg
)
3334 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
3337 static void route_match_ipv6_next_hop_free(void *rule
)
3339 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3342 static const struct route_map_rule_cmd route_match_ipv6_next_hop_cmd
= {
3344 route_match_ipv6_next_hop
,
3345 route_match_ipv6_next_hop_compile
,
3346 route_match_ipv6_next_hop_free
3349 /* `match ipv6 next-hop IP_ADDRESS' */
3351 static enum route_map_cmd_result_t
3352 route_match_ipv6_next_hop_address(void *rule
, const struct prefix
*prefix
,
3355 struct in6_addr
*addr
= rule
;
3356 struct bgp_path_info
*path
;
3360 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
))
3363 if (path
->attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
3364 && IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_local
, rule
))
3367 return RMAP_NOMATCH
;
3370 static void *route_match_ipv6_next_hop_address_compile(const char *arg
)
3372 struct in6_addr
*address
;
3375 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3377 ret
= inet_pton(AF_INET6
, arg
, address
);
3379 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3386 static void route_match_ipv6_next_hop_address_free(void *rule
)
3388 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3391 static const struct route_map_rule_cmd route_match_ipv6_next_hop_address_cmd
= {
3392 "ipv6 next-hop address",
3393 route_match_ipv6_next_hop_address
,
3394 route_match_ipv6_next_hop_address_compile
,
3395 route_match_ipv6_next_hop_address_free
3398 /* `match ip next-hop address IP_ADDRESS' */
3400 static enum route_map_cmd_result_t
3401 route_match_ipv4_next_hop(void *rule
, const struct prefix
*prefix
, void *object
)
3403 struct in_addr
*addr
= rule
;
3404 struct bgp_path_info
*path
;
3408 if (path
->attr
->nexthop
.s_addr
== addr
->s_addr
3409 || (path
->attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV4
3410 && IPV4_ADDR_SAME(&path
->attr
->mp_nexthop_global_in
, addr
)))
3413 return RMAP_NOMATCH
;
3416 static void *route_match_ipv4_next_hop_compile(const char *arg
)
3418 struct in_addr
*address
;
3421 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3423 ret
= inet_pton(AF_INET
, arg
, address
);
3425 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3432 static void route_match_ipv4_next_hop_free(void *rule
)
3434 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3437 static const struct route_map_rule_cmd route_match_ipv4_next_hop_cmd
= {
3438 "ip next-hop address",
3439 route_match_ipv4_next_hop
,
3440 route_match_ipv4_next_hop_compile
,
3441 route_match_ipv4_next_hop_free
3444 /* `match ipv6 address prefix-list PREFIX_LIST' */
3446 static enum route_map_cmd_result_t
3447 route_match_ipv6_address_prefix_list(void *rule
, const struct prefix
*prefix
,
3450 return route_match_address_prefix_list(rule
, AFI_IP6
, prefix
, object
);
3453 static void *route_match_ipv6_address_prefix_list_compile(const char *arg
)
3455 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
3458 static void route_match_ipv6_address_prefix_list_free(void *rule
)
3460 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3463 static const struct route_map_rule_cmd
3464 route_match_ipv6_address_prefix_list_cmd
= {
3465 "ipv6 address prefix-list",
3466 route_match_ipv6_address_prefix_list
,
3467 route_match_ipv6_address_prefix_list_compile
,
3468 route_match_ipv6_address_prefix_list_free
3471 /* `match ipv6 next-hop type <TYPE>' */
3473 static enum route_map_cmd_result_t
3474 route_match_ipv6_next_hop_type(void *rule
, const struct prefix
*prefix
,
3477 struct bgp_path_info
*path
;
3478 struct in6_addr
*addr
= rule
;
3480 if (prefix
->family
== AF_INET6
) {
3481 path
= (struct bgp_path_info
*)object
;
3483 return RMAP_NOMATCH
;
3485 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
)
3486 && !path
->attr
->nh_ifindex
)
3490 return RMAP_NOMATCH
;
3493 static void *route_match_ipv6_next_hop_type_compile(const char *arg
)
3495 struct in6_addr
*address
;
3498 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3500 ret
= inet_pton(AF_INET6
, "::0", address
);
3502 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3509 static void route_match_ipv6_next_hop_type_free(void *rule
)
3511 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3514 static const struct route_map_rule_cmd
3515 route_match_ipv6_next_hop_type_cmd
= {
3516 "ipv6 next-hop type",
3517 route_match_ipv6_next_hop_type
,
3518 route_match_ipv6_next_hop_type_compile
,
3519 route_match_ipv6_next_hop_type_free
3522 /* `set ipv6 nexthop global IP_ADDRESS' */
3524 /* Set nexthop to object. object must be pointer to struct attr. */
3525 static enum route_map_cmd_result_t
3526 route_set_ipv6_nexthop_global(void *rule
, const struct prefix
*p
, void *object
)
3528 struct in6_addr
*address
;
3529 struct bgp_path_info
*path
;
3531 /* Fetch routemap's rule information. */
3535 /* Set next hop value. */
3536 path
->attr
->mp_nexthop_global
= *address
;
3538 /* Set nexthop length. */
3539 if (path
->attr
->mp_nexthop_len
== 0)
3540 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL
;
3542 SET_FLAG(path
->attr
->rmap_change_flags
,
3543 BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED
);
3548 /* Route map `ip next-hop' compile function. Given string is converted
3549 to struct in_addr structure. */
3550 static void *route_set_ipv6_nexthop_global_compile(const char *arg
)
3553 struct in6_addr
*address
;
3555 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3557 ret
= inet_pton(AF_INET6
, arg
, address
);
3560 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3567 /* Free route map's compiled `ip next-hop' value. */
3568 static void route_set_ipv6_nexthop_global_free(void *rule
)
3570 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3573 /* Route map commands for ip nexthop set. */
3574 static const struct route_map_rule_cmd
3575 route_set_ipv6_nexthop_global_cmd
= {
3576 "ipv6 next-hop global",
3577 route_set_ipv6_nexthop_global
,
3578 route_set_ipv6_nexthop_global_compile
,
3579 route_set_ipv6_nexthop_global_free
3582 /* Set next-hop preference value. */
3583 static enum route_map_cmd_result_t
3584 route_set_ipv6_nexthop_prefer_global(void *rule
, const struct prefix
*prefix
,
3587 struct bgp_path_info
*path
;
3590 /* Fetch routemap's rule information. */
3594 if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
3595 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
)) {
3596 /* Set next hop preference to global */
3597 path
->attr
->mp_nexthop_prefer_global
= true;
3598 SET_FLAG(path
->attr
->rmap_change_flags
,
3599 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
3601 path
->attr
->mp_nexthop_prefer_global
= false;
3602 SET_FLAG(path
->attr
->rmap_change_flags
,
3603 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
3609 static void *route_set_ipv6_nexthop_prefer_global_compile(const char *arg
)
3613 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
3619 /* Free route map's compiled `ip next-hop' value. */
3620 static void route_set_ipv6_nexthop_prefer_global_free(void *rule
)
3622 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3625 /* Route map commands for ip nexthop set preferred. */
3626 static const struct route_map_rule_cmd
3627 route_set_ipv6_nexthop_prefer_global_cmd
= {
3628 "ipv6 next-hop prefer-global",
3629 route_set_ipv6_nexthop_prefer_global
,
3630 route_set_ipv6_nexthop_prefer_global_compile
,
3631 route_set_ipv6_nexthop_prefer_global_free
3634 /* `set ipv6 nexthop local IP_ADDRESS' */
3636 /* Set nexthop to object. object must be pointer to struct attr. */
3637 static enum route_map_cmd_result_t
3638 route_set_ipv6_nexthop_local(void *rule
, const struct prefix
*p
, void *object
)
3640 struct in6_addr
*address
;
3641 struct bgp_path_info
*path
;
3642 struct bgp_dest
*dest
;
3643 struct bgp_table
*table
= NULL
;
3645 /* Fetch routemap's rule information. */
3653 table
= bgp_dest_table(dest
);
3657 /* Set next hop value. */
3658 path
->attr
->mp_nexthop_local
= *address
;
3660 /* Set nexthop length. */
3661 if (table
->safi
== SAFI_MPLS_VPN
|| table
->safi
== SAFI_ENCAP
||
3662 table
->safi
== SAFI_EVPN
)
3663 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_VPNV6_GLOBAL_AND_LL
;
3665 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
3667 SET_FLAG(path
->attr
->rmap_change_flags
,
3668 BATTR_RMAP_IPV6_LL_NHOP_CHANGED
);
3673 /* Route map `ip nexthop' compile function. Given string is converted
3674 to struct in_addr structure. */
3675 static void *route_set_ipv6_nexthop_local_compile(const char *arg
)
3678 struct in6_addr
*address
;
3680 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3682 ret
= inet_pton(AF_INET6
, arg
, address
);
3685 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3692 /* Free route map's compiled `ip nexthop' value. */
3693 static void route_set_ipv6_nexthop_local_free(void *rule
)
3695 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3698 /* Route map commands for ip nexthop set. */
3699 static const struct route_map_rule_cmd
3700 route_set_ipv6_nexthop_local_cmd
= {
3701 "ipv6 next-hop local",
3702 route_set_ipv6_nexthop_local
,
3703 route_set_ipv6_nexthop_local_compile
,
3704 route_set_ipv6_nexthop_local_free
3707 /* `set ipv6 nexthop peer-address' */
3709 /* Set nexthop to object. object must be pointer to struct attr. */
3710 static enum route_map_cmd_result_t
3711 route_set_ipv6_nexthop_peer(void *rule
, const struct prefix
*pfx
, void *object
)
3713 struct in6_addr peer_address
;
3714 struct bgp_path_info
*path
;
3717 /* Fetch routemap's rule information. */
3721 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
3722 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
3724 && sockunion_family(peer
->su_remote
) == AF_INET6
) {
3725 peer_address
= peer
->su_remote
->sin6
.sin6_addr
;
3726 /* Set next hop value and length in attribute. */
3727 if (IN6_IS_ADDR_LINKLOCAL(&peer_address
)) {
3728 path
->attr
->mp_nexthop_local
= peer_address
;
3729 if (path
->attr
->mp_nexthop_len
3730 != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
3731 path
->attr
->mp_nexthop_len
=
3732 BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
3734 path
->attr
->mp_nexthop_global
= peer_address
;
3735 if (path
->attr
->mp_nexthop_len
== 0)
3736 path
->attr
->mp_nexthop_len
=
3737 BGP_ATTR_NHLEN_IPV6_GLOBAL
;
3740 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
3741 /* The next hop value will be set as part of packet
3743 * Set the flags here to indicate that rewrite needs to
3745 * Also, clear the value - we clear both global and
3747 * nexthops, whether we send one or both is determined
3750 SET_FLAG(path
->attr
->rmap_change_flags
,
3751 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
3752 /* clear next hop value. */
3753 memset(&(path
->attr
->mp_nexthop_global
), 0,
3754 sizeof(struct in6_addr
));
3755 memset(&(path
->attr
->mp_nexthop_local
), 0,
3756 sizeof(struct in6_addr
));
3762 /* Route map `ip next-hop' compile function. Given string is converted
3763 to struct in_addr structure. */
3764 static void *route_set_ipv6_nexthop_peer_compile(const char *arg
)
3768 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
3774 /* Free route map's compiled `ip next-hop' value. */
3775 static void route_set_ipv6_nexthop_peer_free(void *rule
)
3777 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3780 /* Route map commands for ip nexthop set. */
3781 static const struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd
= {
3782 "ipv6 next-hop peer-address",
3783 route_set_ipv6_nexthop_peer
,
3784 route_set_ipv6_nexthop_peer_compile
,
3785 route_set_ipv6_nexthop_peer_free
3788 /* `set ipv4 vpn next-hop A.B.C.D' */
3790 static enum route_map_cmd_result_t
3791 route_set_vpnv4_nexthop(void *rule
, const struct prefix
*prefix
, void *object
)
3793 struct in_addr
*address
;
3794 struct bgp_path_info
*path
;
3796 /* Fetch routemap's rule information. */
3800 /* Set next hop value. */
3801 path
->attr
->mp_nexthop_global_in
= *address
;
3802 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV4
;
3804 SET_FLAG(path
->attr
->rmap_change_flags
, BATTR_RMAP_VPNV4_NHOP_CHANGED
);
3809 static void *route_set_vpnv4_nexthop_compile(const char *arg
)
3812 struct in_addr
*address
;
3814 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3816 ret
= inet_aton(arg
, address
);
3819 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3826 /* `set ipv6 vpn next-hop A.B.C.D' */
3828 static enum route_map_cmd_result_t
3829 route_set_vpnv6_nexthop(void *rule
, const struct prefix
*prefix
, void *object
)
3831 struct in6_addr
*address
;
3832 struct bgp_path_info
*path
;
3834 /* Fetch routemap's rule information. */
3838 /* Set next hop value. */
3839 memcpy(&path
->attr
->mp_nexthop_global
, address
,
3840 sizeof(struct in6_addr
));
3841 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_VPNV6_GLOBAL
;
3843 SET_FLAG(path
->attr
->rmap_change_flags
,
3844 BATTR_RMAP_VPNV6_GLOBAL_NHOP_CHANGED
);
3849 static void *route_set_vpnv6_nexthop_compile(const char *arg
)
3852 struct in6_addr
*address
;
3854 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3855 ret
= inet_pton(AF_INET6
, arg
, address
);
3858 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3865 static void route_set_vpn_nexthop_free(void *rule
)
3867 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3870 /* Route map commands for ipv4 next-hop set. */
3871 static const struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd
= {
3872 "ipv4 vpn next-hop",
3873 route_set_vpnv4_nexthop
,
3874 route_set_vpnv4_nexthop_compile
,
3875 route_set_vpn_nexthop_free
3878 /* Route map commands for ipv6 next-hop set. */
3879 static const struct route_map_rule_cmd route_set_vpnv6_nexthop_cmd
= {
3880 "ipv6 vpn next-hop",
3881 route_set_vpnv6_nexthop
,
3882 route_set_vpnv6_nexthop_compile
,
3883 route_set_vpn_nexthop_free
3886 /* `set originator-id' */
3888 /* For origin set. */
3889 static enum route_map_cmd_result_t
3890 route_set_originator_id(void *rule
, const struct prefix
*prefix
, void *object
)
3892 struct in_addr
*address
;
3893 struct bgp_path_info
*path
;
3898 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
);
3899 path
->attr
->originator_id
= *address
;
3904 /* Compile function for originator-id set. */
3905 static void *route_set_originator_id_compile(const char *arg
)
3908 struct in_addr
*address
;
3910 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3912 ret
= inet_aton(arg
, address
);
3915 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3922 /* Compile function for originator_id set. */
3923 static void route_set_originator_id_free(void *rule
)
3925 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3928 /* Set originator-id rule structure. */
3929 static const struct route_map_rule_cmd route_set_originator_id_cmd
= {
3931 route_set_originator_id
,
3932 route_set_originator_id_compile
,
3933 route_set_originator_id_free
,
3936 static enum route_map_cmd_result_t
3937 route_match_rpki_extcommunity(void *rule
, const struct prefix
*prefix
,
3940 struct bgp_path_info
*path
;
3941 struct ecommunity
*ecomm
;
3942 struct ecommunity_val
*ecomm_val
;
3943 enum rpki_states
*rpki_status
= rule
;
3944 enum rpki_states ecomm_rpki_status
= RPKI_NOT_BEING_USED
;
3948 ecomm
= bgp_attr_get_ecommunity(path
->attr
);
3950 return RMAP_NOMATCH
;
3952 ecomm_val
= ecommunity_lookup(ecomm
, ECOMMUNITY_ENCODE_OPAQUE_NON_TRANS
,
3953 ECOMMUNITY_ORIGIN_VALIDATION_STATE
);
3955 return RMAP_NOMATCH
;
3957 /* The Origin Validation State is encoded in the last octet of
3958 * the extended community.
3960 switch (ecomm_val
->val
[7]) {
3961 case ECOMMUNITY_ORIGIN_VALIDATION_STATE_VALID
:
3962 ecomm_rpki_status
= RPKI_VALID
;
3964 case ECOMMUNITY_ORIGIN_VALIDATION_STATE_NOTFOUND
:
3965 ecomm_rpki_status
= RPKI_NOTFOUND
;
3967 case ECOMMUNITY_ORIGIN_VALIDATION_STATE_INVALID
:
3968 ecomm_rpki_status
= RPKI_INVALID
;
3970 case ECOMMUNITY_ORIGIN_VALIDATION_STATE_NOTUSED
:
3974 if (ecomm_rpki_status
== *rpki_status
)
3977 return RMAP_NOMATCH
;
3980 static void *route_match_extcommunity_compile(const char *arg
)
3984 rpki_status
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
3986 if (strcmp(arg
, "valid") == 0)
3987 *rpki_status
= RPKI_VALID
;
3988 else if (strcmp(arg
, "invalid") == 0)
3989 *rpki_status
= RPKI_INVALID
;
3991 *rpki_status
= RPKI_NOTFOUND
;
3996 static const struct route_map_rule_cmd route_match_rpki_extcommunity_cmd
= {
3997 "rpki-extcommunity",
3998 route_match_rpki_extcommunity
,
3999 route_match_extcommunity_compile
,
4004 * This is the workhorse routine for processing in/out routemap
4007 static void bgp_route_map_process_peer(const char *rmap_name
,
4008 struct route_map
*map
, struct peer
*peer
,
4009 int afi
, int safi
, int route_update
)
4011 struct bgp_filter
*filter
;
4013 if (!peer
|| !rmap_name
)
4016 filter
= &peer
->filter
[afi
][safi
];
4018 * in is for non-route-server clients,
4019 * out is for all peers
4021 if (filter
->map
[RMAP_IN
].name
4022 && (strcmp(rmap_name
, filter
->map
[RMAP_IN
].name
) == 0)) {
4023 filter
->map
[RMAP_IN
].map
= map
;
4025 if (route_update
&& peer_established(peer
)) {
4026 if (CHECK_FLAG(peer
->af_flags
[afi
][safi
],
4027 PEER_FLAG_SOFT_RECONFIG
)) {
4028 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
4030 "Processing route_map %s(%s:%s) update on peer %s (inbound, soft-reconfig)",
4031 rmap_name
, afi2str(afi
),
4032 safi2str(safi
), peer
->host
);
4034 bgp_soft_reconfig_in(peer
, afi
, safi
);
4035 } else if (CHECK_FLAG(peer
->cap
,
4036 PEER_CAP_REFRESH_OLD_RCV
)
4037 || CHECK_FLAG(peer
->cap
,
4038 PEER_CAP_REFRESH_NEW_RCV
)) {
4039 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
4041 "Processing route_map %s(%s:%s) update on peer %s (inbound, route-refresh)",
4042 rmap_name
, afi2str(afi
),
4043 safi2str(safi
), peer
->host
);
4044 bgp_route_refresh_send(
4045 peer
, afi
, safi
, 0, 0, 0,
4046 BGP_ROUTE_REFRESH_NORMAL
);
4052 * For outbound, unsuppress and default-originate map change (content or
4053 * map created), merely update the "config" here, the actual route
4054 * announcement happens at the group level.
4056 if (filter
->map
[RMAP_OUT
].name
4057 && (strcmp(rmap_name
, filter
->map
[RMAP_OUT
].name
) == 0))
4058 filter
->map
[RMAP_OUT
].map
= map
;
4060 if (filter
->usmap
.name
&& (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
4061 filter
->usmap
.map
= map
;
4063 if (filter
->advmap
.aname
4064 && (strcmp(rmap_name
, filter
->advmap
.aname
) == 0)) {
4065 filter
->advmap
.amap
= map
;
4068 if (filter
->advmap
.cname
4069 && (strcmp(rmap_name
, filter
->advmap
.cname
) == 0)) {
4070 filter
->advmap
.cmap
= map
;
4073 if (peer
->default_rmap
[afi
][safi
].name
4074 && (strcmp(rmap_name
, peer
->default_rmap
[afi
][safi
].name
) == 0))
4075 peer
->default_rmap
[afi
][safi
].map
= map
;
4077 /* Notify BGP conditional advertisement scanner percess */
4078 peer
->advmap_config_change
[afi
][safi
] = true;
4081 static void bgp_route_map_update_peer_group(const char *rmap_name
,
4082 struct route_map
*map
,
4085 struct peer_group
*group
;
4086 struct listnode
*node
, *nnode
;
4087 struct bgp_filter
*filter
;
4094 /* All the peers have been updated correctly already. This is
4095 * just updating the placeholder data. No real update required.
4097 for (ALL_LIST_ELEMENTS(bgp
->group
, node
, nnode
, group
)) {
4098 FOREACH_AFI_SAFI (afi
, safi
) {
4099 filter
= &group
->conf
->filter
[afi
][safi
];
4101 for (direct
= RMAP_IN
; direct
< RMAP_MAX
; direct
++) {
4102 if ((filter
->map
[direct
].name
)
4103 && (strcmp(rmap_name
,
4104 filter
->map
[direct
].name
)
4106 filter
->map
[direct
].map
= map
;
4109 if (filter
->usmap
.name
4110 && (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
4111 filter
->usmap
.map
= map
;
4113 if (filter
->advmap
.aname
&&
4114 (strcmp(rmap_name
, filter
->advmap
.aname
) == 0))
4115 filter
->advmap
.amap
= map
;
4117 if (filter
->advmap
.cname
&&
4118 (strcmp(rmap_name
, filter
->advmap
.cname
) == 0))
4119 filter
->advmap
.cmap
= map
;
4125 * Note that if an extreme number (tens of thousands) of route-maps are in use
4126 * and if bgp has an extreme number of peers, network statements, etc then this
4127 * function can consume a lot of cycles. This is due to this function being
4128 * called for each route-map and within this function we walk the list of peers,
4129 * network statements, etc looking to see if they use this route-map.
4131 static void bgp_route_map_process_update(struct bgp
*bgp
, const char *rmap_name
,
4139 struct bgp_dest
*bn
;
4140 struct bgp_static
*bgp_static
;
4141 struct bgp_aggregate
*aggregate
;
4142 struct listnode
*node
, *nnode
;
4143 struct route_map
*map
;
4144 char buf
[INET6_ADDRSTRLEN
];
4146 map
= route_map_lookup_by_name(rmap_name
);
4148 for (ALL_LIST_ELEMENTS(bgp
->peer
, node
, nnode
, peer
)) {
4150 /* Ignore dummy peer-group structure */
4151 if (CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
))
4154 FOREACH_AFI_SAFI (afi
, safi
) {
4155 /* process in/out/import/export/default-orig
4157 bgp_route_map_process_peer(rmap_name
, map
, peer
, afi
,
4158 safi
, route_update
);
4162 /* for outbound/default-orig route-maps, process for groups */
4163 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
, rmap_name
,
4166 /* update peer-group config (template) */
4167 bgp_route_map_update_peer_group(rmap_name
, map
, bgp
);
4169 FOREACH_AFI_SAFI (afi
, safi
) {
4170 /* For table route-map updates. */
4171 if (!bgp_fibupd_safi(safi
))
4174 if (bgp
->table_map
[afi
][safi
].name
4175 && (strcmp(rmap_name
, bgp
->table_map
[afi
][safi
].name
)
4178 /* bgp->table_map[afi][safi].map is NULL.
4179 * i.e Route map creation event.
4180 * So update applied_counter.
4181 * If it is not NULL, i.e It may be routemap updation or
4182 * deletion. so no need to update the counter.
4184 if (!bgp
->table_map
[afi
][safi
].map
)
4185 route_map_counter_increment(map
);
4186 bgp
->table_map
[afi
][safi
].map
= map
;
4188 if (BGP_DEBUG(zebra
, ZEBRA
))
4190 "Processing route_map %s(%s:%s) update on table map",
4191 rmap_name
, afi2str(afi
),
4194 bgp_zebra_announce_table(bgp
, afi
, safi
);
4197 /* For network route-map updates. */
4198 for (bn
= bgp_table_top(bgp
->route
[afi
][safi
]); bn
;
4199 bn
= bgp_route_next(bn
)) {
4200 bgp_static
= bgp_dest_get_bgp_static_info(bn
);
4204 if (!bgp_static
->rmap
.name
4205 || (strcmp(rmap_name
, bgp_static
->rmap
.name
) != 0))
4208 if (!bgp_static
->rmap
.map
)
4209 route_map_counter_increment(map
);
4211 bgp_static
->rmap
.map
= map
;
4213 if (route_update
&& !bgp_static
->backdoor
) {
4214 const struct prefix
*bn_p
=
4215 bgp_dest_get_prefix(bn
);
4217 if (bgp_debug_zebra(bn_p
))
4219 "Processing route_map %s(%s:%s) update on static route %s",
4220 rmap_name
, afi2str(afi
),
4222 inet_ntop(bn_p
->family
,
4223 &bn_p
->u
.prefix
, buf
,
4225 bgp_static_update(bgp
, bn_p
, bgp_static
, afi
,
4230 /* For aggregate-address route-map updates. */
4231 for (bn
= bgp_table_top(bgp
->aggregate
[afi
][safi
]); bn
;
4232 bn
= bgp_route_next(bn
)) {
4233 aggregate
= bgp_dest_get_bgp_aggregate_info(bn
);
4239 /* Update suppress map pointer. */
4240 if (aggregate
->suppress_map_name
4241 && strmatch(aggregate
->suppress_map_name
,
4243 if (aggregate
->rmap
.map
== NULL
)
4244 route_map_counter_increment(map
);
4246 aggregate
->suppress_map
= map
;
4248 bgp_aggregate_toggle_suppressed(
4249 aggregate
, bgp
, bgp_dest_get_prefix(bn
),
4255 if (aggregate
->rmap
.name
4256 && strmatch(rmap_name
, aggregate
->rmap
.name
)) {
4257 if (aggregate
->rmap
.map
== NULL
)
4258 route_map_counter_increment(map
);
4260 aggregate
->rmap
.map
= map
;
4265 if (matched
&& route_update
) {
4266 const struct prefix
*bn_p
=
4267 bgp_dest_get_prefix(bn
);
4269 if (bgp_debug_zebra(bn_p
))
4271 "Processing route_map %s(%s:%s) update on aggregate-address route %s",
4272 rmap_name
, afi2str(afi
),
4274 inet_ntop(bn_p
->family
,
4275 &bn_p
->u
.prefix
, buf
,
4277 (void)bgp_aggregate_route(bgp
, bn_p
, afi
, safi
,
4283 /* For redistribute route-map updates. */
4284 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
4285 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
4286 struct list
*red_list
;
4287 struct bgp_redist
*red
;
4289 red_list
= bgp
->redist
[afi
][i
];
4293 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
4295 || (strcmp(rmap_name
, red
->rmap
.name
) != 0))
4299 route_map_counter_increment(map
);
4301 red
->rmap
.map
= map
;
4306 if (BGP_DEBUG(zebra
, ZEBRA
))
4308 "Processing route_map %s(%s:%s) update on redistributed routes",
4309 rmap_name
, afi2str(afi
),
4312 bgp_redistribute_resend(bgp
, afi
, i
,
4317 /* for type5 command route-maps */
4318 FOREACH_AFI_SAFI (afi
, safi
) {
4319 if (!bgp
->adv_cmd_rmap
[afi
][safi
].name
4320 || strcmp(rmap_name
, bgp
->adv_cmd_rmap
[afi
][safi
].name
)
4324 /* Make sure the route-map is populated here if not already done */
4325 bgp
->adv_cmd_rmap
[afi
][safi
].map
= map
;
4327 if (BGP_DEBUG(zebra
, ZEBRA
))
4329 "Processing route_map %s(%s:%s) update on advertise type5 route command",
4330 rmap_name
, afi2str(afi
), safi2str(safi
));
4332 if (route_update
&& advertise_type5_routes(bgp
, afi
)) {
4333 bgp_evpn_withdraw_type5_routes(bgp
, afi
, safi
);
4334 bgp_evpn_advertise_type5_routes(bgp
, afi
, safi
);
4339 static void bgp_route_map_process_update_cb(char *rmap_name
)
4341 struct listnode
*node
, *nnode
;
4344 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
)) {
4345 bgp_route_map_process_update(bgp
, rmap_name
, true);
4347 #ifdef ENABLE_BGP_VNC
4348 vnc_routemap_update(bgp
, __func__
);
4352 vpn_policy_routemap_event(rmap_name
);
4355 void bgp_route_map_update_timer(struct thread
*thread
)
4357 route_map_walk_update_list(bgp_route_map_process_update_cb
);
4360 static void bgp_route_map_mark_update(const char *rmap_name
)
4362 struct listnode
*node
, *nnode
;
4365 /* If new update is received before the current timer timed out,
4366 * turn it off and start a new timer.
4368 THREAD_OFF(bm
->t_rmap_update
);
4370 /* rmap_update_timer of 0 means don't do route updates */
4371 if (bm
->rmap_update_timer
) {
4372 thread_add_timer(bm
->master
, bgp_route_map_update_timer
,
4373 NULL
, bm
->rmap_update_timer
,
4374 &bm
->t_rmap_update
);
4376 /* Signal the groups that a route-map update event has
4378 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
4379 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
,
4380 rmap_name
, true, 1);
4382 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
)) {
4383 bgp_route_map_process_update(bgp
, rmap_name
, false);
4384 #ifdef ENABLE_BGP_VNC
4385 vnc_routemap_update(bgp
, __func__
);
4389 vpn_policy_routemap_event(rmap_name
);
4393 static void bgp_route_map_add(const char *rmap_name
)
4395 if (route_map_mark_updated(rmap_name
) == 0)
4396 bgp_route_map_mark_update(rmap_name
);
4398 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
4401 static void bgp_route_map_delete(const char *rmap_name
)
4403 if (route_map_mark_updated(rmap_name
) == 0)
4404 bgp_route_map_mark_update(rmap_name
);
4406 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_DELETED
);
4409 static void bgp_route_map_event(const char *rmap_name
)
4411 if (route_map_mark_updated(rmap_name
) == 0)
4412 bgp_route_map_mark_update(rmap_name
);
4414 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
4417 DEFUN_YANG (match_mac_address
,
4418 match_mac_address_cmd
,
4419 "match mac address ACCESSLIST_MAC_NAME",
4422 "Match address of route\n"
4423 "MAC Access-list name\n")
4426 "./match-condition[condition='frr-bgp-route-map:mac-address-list']";
4427 char xpath_value
[XPATH_MAXLEN
];
4429 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4430 snprintf(xpath_value
, sizeof(xpath_value
),
4431 "%s/rmap-match-condition/frr-bgp-route-map:list-name", xpath
);
4432 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[3]->arg
);
4434 return nb_cli_apply_changes(vty
, NULL
);
4437 DEFUN_YANG (no_match_mac_address
,
4438 no_match_mac_address_cmd
,
4439 "no match mac address ACCESSLIST_MAC_NAME",
4443 "Match address of route\n"
4444 "MAC acess-list name\n")
4447 "./match-condition[condition='frr-bgp-route-map:mac-address-list']";
4449 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4450 return nb_cli_apply_changes(vty
, NULL
);
4454 * Helper to handle the case of the user passing in a number or type string
4456 static const char *parse_evpn_rt_type(const char *num_rt_type
)
4458 switch (num_rt_type
[0]) {
4473 /* Was already full type string */
4477 DEFUN_YANG (match_evpn_route_type
,
4478 match_evpn_route_type_cmd
,
4479 "match evpn route-type <ead|1|macip|2|multicast|3|es|4|prefix|5>",
4483 EVPN_TYPE_1_HELP_STR
4484 EVPN_TYPE_1_HELP_STR
4485 EVPN_TYPE_2_HELP_STR
4486 EVPN_TYPE_2_HELP_STR
4487 EVPN_TYPE_3_HELP_STR
4488 EVPN_TYPE_3_HELP_STR
4489 EVPN_TYPE_4_HELP_STR
4490 EVPN_TYPE_4_HELP_STR
4491 EVPN_TYPE_5_HELP_STR
4492 EVPN_TYPE_5_HELP_STR
)
4495 "./match-condition[condition='frr-bgp-route-map:evpn-route-type']";
4496 char xpath_value
[XPATH_MAXLEN
];
4498 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4499 snprintf(xpath_value
, sizeof(xpath_value
),
4500 "%s/rmap-match-condition/frr-bgp-route-map:evpn-route-type",
4502 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4503 parse_evpn_rt_type(argv
[3]->arg
));
4505 return nb_cli_apply_changes(vty
, NULL
);
4508 DEFUN_YANG (no_match_evpn_route_type
,
4509 no_match_evpn_route_type_cmd
,
4510 "no match evpn route-type <ead|1|macip|2|multicast|3|es|4|prefix|5>",
4515 EVPN_TYPE_1_HELP_STR
4516 EVPN_TYPE_1_HELP_STR
4517 EVPN_TYPE_2_HELP_STR
4518 EVPN_TYPE_2_HELP_STR
4519 EVPN_TYPE_3_HELP_STR
4520 EVPN_TYPE_3_HELP_STR
4521 EVPN_TYPE_4_HELP_STR
4522 EVPN_TYPE_4_HELP_STR
4523 EVPN_TYPE_5_HELP_STR
4524 EVPN_TYPE_5_HELP_STR
)
4527 "./match-condition[condition='frr-bgp-route-map:evpn-route-type']";
4529 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4531 return nb_cli_apply_changes(vty
, NULL
);
4535 DEFUN_YANG (match_evpn_vni
,
4537 "match evpn vni " CMD_VNI_RANGE
,
4544 "./match-condition[condition='frr-bgp-route-map:evpn-vni']";
4545 char xpath_value
[XPATH_MAXLEN
];
4547 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4548 snprintf(xpath_value
, sizeof(xpath_value
),
4549 "%s/rmap-match-condition/frr-bgp-route-map:evpn-vni", xpath
);
4550 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[3]->arg
);
4552 return nb_cli_apply_changes(vty
, NULL
);
4555 DEFUN_YANG (no_match_evpn_vni
,
4556 no_match_evpn_vni_cmd
,
4557 "no match evpn vni " CMD_VNI_RANGE
,
4565 "./match-condition[condition='frr-bgp-route-map:evpn-vni']";
4566 char xpath_value
[XPATH_MAXLEN
];
4568 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4569 snprintf(xpath_value
, sizeof(xpath_value
),
4570 "%s/rmap-match-condition/frr-bgp-route-map:evpn-vni", xpath
);
4571 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_DESTROY
, argv
[3]->arg
);
4573 return nb_cli_apply_changes(vty
, NULL
);
4576 DEFUN_YANG (match_evpn_default_route
,
4577 match_evpn_default_route_cmd
,
4578 "match evpn default-route",
4581 "default EVPN type-5 route\n")
4584 "./match-condition[condition='frr-bgp-route-map:evpn-default-route']";
4585 char xpath_value
[XPATH_MAXLEN
];
4587 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4589 snprintf(xpath_value
, sizeof(xpath_value
),
4590 "%s/rmap-match-condition/frr-bgp-route-map:evpn-default-route",
4592 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, NULL
);
4594 return nb_cli_apply_changes(vty
, NULL
);
4597 DEFUN_YANG (no_match_evpn_default_route
,
4598 no_match_evpn_default_route_cmd
,
4599 "no match evpn default-route",
4603 "default EVPN type-5 route\n")
4606 "./match-condition[condition='frr-bgp-route-map:evpn-default-route']";
4608 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4610 return nb_cli_apply_changes(vty
, NULL
);
4613 DEFUN_YANG (match_evpn_rd
,
4615 "match evpn rd ASN:NN_OR_IP-ADDRESS:NN",
4618 "Route Distinguisher\n"
4619 "ASN:XX or A.B.C.D:XX\n")
4622 "./match-condition[condition='frr-bgp-route-map:evpn-rd']";
4623 char xpath_value
[XPATH_MAXLEN
];
4625 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4627 xpath_value
, sizeof(xpath_value
),
4628 "%s/rmap-match-condition/frr-bgp-route-map:route-distinguisher",
4630 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[3]->arg
);
4632 return nb_cli_apply_changes(vty
, NULL
);
4635 DEFUN_YANG (no_match_evpn_rd
,
4636 no_match_evpn_rd_cmd
,
4637 "no match evpn rd ASN:NN_OR_IP-ADDRESS:NN",
4641 "Route Distinguisher\n"
4642 "ASN:XX or A.B.C.D:XX\n")
4645 "./match-condition[condition='frr-bgp-route-map:evpn-rd']";
4647 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4648 return nb_cli_apply_changes(vty
, NULL
);
4651 DEFUN_YANG (set_evpn_gw_ip_ipv4
,
4652 set_evpn_gw_ip_ipv4_cmd
,
4653 "set evpn gateway-ip ipv4 A.B.C.D",
4656 "Set gateway IP for prefix advertisement route\n"
4658 "Gateway IP address in IPv4 format\n")
4663 "./set-action[action='frr-bgp-route-map:set-evpn-gateway-ip-ipv4']";
4664 char xpath_value
[XPATH_MAXLEN
];
4666 ret
= str2sockunion(argv
[4]->arg
, &su
);
4668 vty_out(vty
, "%% Malformed gateway IP\n");
4669 return CMD_WARNING_CONFIG_FAILED
;
4672 if (su
.sin
.sin_addr
.s_addr
== 0 ||
4673 !ipv4_unicast_valid(&su
.sin
.sin_addr
)) {
4675 "%% Gateway IP cannot be 0.0.0.0, multicast or reserved\n");
4676 return CMD_WARNING_CONFIG_FAILED
;
4679 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4681 snprintf(xpath_value
, sizeof(xpath_value
),
4682 "%s/rmap-set-action/frr-bgp-route-map:evpn-gateway-ip-ipv4",
4685 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[4]->arg
);
4686 return nb_cli_apply_changes(vty
, NULL
);
4689 DEFUN_YANG (no_set_evpn_gw_ip_ipv4
,
4690 no_set_evpn_gw_ip_ipv4_cmd
,
4691 "no set evpn gateway-ip ipv4 A.B.C.D",
4695 "Set gateway IP for prefix advertisement route\n"
4697 "Gateway IP address in IPv4 format\n")
4702 "./set-action[action='frr-bgp-route-map:set-evpn-gateway-ip-ipv4']";
4704 ret
= str2sockunion(argv
[5]->arg
, &su
);
4706 vty_out(vty
, "%% Malformed gateway IP\n");
4707 return CMD_WARNING_CONFIG_FAILED
;
4710 if (su
.sin
.sin_addr
.s_addr
== 0 ||
4711 !ipv4_unicast_valid(&su
.sin
.sin_addr
)) {
4713 "%% Gateway IP cannot be 0.0.0.0, multicast or reserved\n");
4714 return CMD_WARNING_CONFIG_FAILED
;
4717 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4719 return nb_cli_apply_changes(vty
, NULL
);
4722 DEFUN_YANG (set_evpn_gw_ip_ipv6
,
4723 set_evpn_gw_ip_ipv6_cmd
,
4724 "set evpn gateway-ip ipv6 X:X::X:X",
4727 "Set gateway IP for prefix advertisement route\n"
4729 "Gateway IP address in IPv6 format\n")
4734 "./set-action[action='frr-bgp-route-map:set-evpn-gateway-ip-ipv6']";
4735 char xpath_value
[XPATH_MAXLEN
];
4737 ret
= str2sockunion(argv
[4]->arg
, &su
);
4739 vty_out(vty
, "%% Malformed gateway IP\n");
4740 return CMD_WARNING_CONFIG_FAILED
;
4743 if (IN6_IS_ADDR_LINKLOCAL(&su
.sin6
.sin6_addr
)
4744 || IN6_IS_ADDR_MULTICAST(&su
.sin6
.sin6_addr
)) {
4746 "%% Gateway IP cannot be a linklocal or multicast address\n");
4747 return CMD_WARNING_CONFIG_FAILED
;
4750 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4752 snprintf(xpath_value
, sizeof(xpath_value
),
4753 "%s/rmap-set-action/frr-bgp-route-map:evpn-gateway-ip-ipv6",
4756 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[4]->arg
);
4757 return nb_cli_apply_changes(vty
, NULL
);
4760 DEFUN_YANG (no_set_evpn_gw_ip_ipv6
,
4761 no_set_evpn_gw_ip_ipv6_cmd
,
4762 "no set evpn gateway-ip ipv6 X:X::X:X",
4766 "Set gateway IP for prefix advertisement route\n"
4768 "Gateway IP address in IPv4 format\n")
4773 "./set-action[action='frr-bgp-route-map:set-evpn-gateway-ip-ipv6']";
4775 ret
= str2sockunion(argv
[5]->arg
, &su
);
4777 vty_out(vty
, "%% Malformed gateway IP\n");
4778 return CMD_WARNING_CONFIG_FAILED
;
4781 if (IN6_IS_ADDR_LINKLOCAL(&su
.sin6
.sin6_addr
)
4782 || IN6_IS_ADDR_MULTICAST(&su
.sin6
.sin6_addr
)) {
4784 "%% Gateway IP cannot be a linklocal or multicast address\n");
4785 return CMD_WARNING_CONFIG_FAILED
;
4788 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4790 return nb_cli_apply_changes(vty
, NULL
);
4793 DEFPY_YANG(match_vrl_source_vrf
,
4794 match_vrl_source_vrf_cmd
,
4795 "match source-vrf NAME$vrf_name",
4801 "./match-condition[condition='frr-bgp-route-map:source-vrf']";
4802 char xpath_value
[XPATH_MAXLEN
];
4804 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4805 snprintf(xpath_value
, sizeof(xpath_value
),
4806 "%s/rmap-match-condition/frr-bgp-route-map:source-vrf", xpath
);
4807 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, vrf_name
);
4809 return nb_cli_apply_changes(vty
, NULL
);
4812 DEFPY_YANG(no_match_vrl_source_vrf
,
4813 no_match_vrl_source_vrf_cmd
,
4814 "no match source-vrf NAME$vrf_name",
4820 "./match-condition[condition='frr-bgp-route-map:source-vrf']";
4822 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4823 return nb_cli_apply_changes(vty
, NULL
);
4826 DEFPY_YANG (match_peer
,
4828 "match peer <A.B.C.D$addrv4|X:X::X:X$addrv6|WORD$intf>",
4830 "Match peer address\n"
4831 "IP address of peer\n"
4832 "IPv6 address of peer\n"
4833 "Interface name of peer or peer group name\n")
4836 "./match-condition[condition='frr-bgp-route-map:peer']";
4837 char xpath_value
[XPATH_MAXLEN
];
4839 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4843 xpath_value
, sizeof(xpath_value
),
4844 "%s/rmap-match-condition/frr-bgp-route-map:peer-ipv4-address",
4846 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4848 } else if (addrv6_str
) {
4850 xpath_value
, sizeof(xpath_value
),
4851 "%s/rmap-match-condition/frr-bgp-route-map:peer-ipv6-address",
4853 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4857 xpath_value
, sizeof(xpath_value
),
4858 "%s/rmap-match-condition/frr-bgp-route-map:peer-interface",
4860 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, intf
);
4863 return nb_cli_apply_changes(vty
, NULL
);
4866 DEFUN_YANG (match_peer_local
,
4867 match_peer_local_cmd
,
4870 "Match peer address\n"
4871 "Static or Redistributed routes\n")
4874 "./match-condition[condition='frr-bgp-route-map:peer']";
4875 char xpath_value
[XPATH_MAXLEN
];
4877 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4879 snprintf(xpath_value
, sizeof(xpath_value
),
4880 "%s/rmap-match-condition/frr-bgp-route-map:peer-local", xpath
);
4881 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
4883 return nb_cli_apply_changes(vty
, NULL
);
4886 DEFUN_YANG (no_match_peer
,
4888 "no match peer [<local|A.B.C.D|X:X::X:X|WORD>]",
4891 "Match peer address\n"
4892 "Static or Redistributed routes\n"
4893 "IP address of peer\n"
4894 "IPv6 address of peer\n"
4895 "Interface name of peer\n")
4898 "./match-condition[condition='frr-bgp-route-map:peer']";
4900 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4902 return nb_cli_apply_changes(vty
, NULL
);
4905 #ifdef HAVE_SCRIPTING
4906 DEFUN_YANG (match_script
,
4908 "[no] match script WORD",
4911 "Execute script to determine match\n"
4912 "The script name to run, without .lua; e.g. 'myroutemap' to run myroutemap.lua\n")
4914 bool no
= strmatch(argv
[0]->text
, "no");
4916 argv_find(argv
, argc
, "WORD", &i
);
4917 const char *script
= argv
[i
]->arg
;
4919 "./match-condition[condition='frr-bgp-route-map:match-script']";
4920 char xpath_value
[XPATH_MAXLEN
];
4923 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4924 snprintf(xpath_value
, sizeof(xpath_value
),
4925 "%s/rmap-match-condition/frr-bgp-route-map:script",
4927 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_DESTROY
,
4930 return nb_cli_apply_changes(vty
, NULL
);
4933 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4934 snprintf(xpath_value
, sizeof(xpath_value
),
4935 "%s/rmap-match-condition/frr-bgp-route-map:script",
4937 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4940 return nb_cli_apply_changes(vty
, NULL
);
4942 #endif /* HAVE_SCRIPTING */
4944 /* match probability */
4945 DEFUN_YANG (match_probability
,
4946 match_probability_cmd
,
4947 "match probability (0-100)",
4949 "Match portion of routes defined by percentage value\n"
4950 "Percentage of routes\n")
4955 "./match-condition[condition='frr-bgp-route-map:probability']";
4956 char xpath_value
[XPATH_MAXLEN
];
4958 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4959 snprintf(xpath_value
, sizeof(xpath_value
),
4960 "%s/rmap-match-condition/frr-bgp-route-map:probability",
4962 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4963 argv
[idx_number
]->arg
);
4965 return nb_cli_apply_changes(vty
, NULL
);
4969 DEFUN_YANG (no_match_probability
,
4970 no_match_probability_cmd
,
4971 "no match probability [(1-99)]",
4974 "Match portion of routes defined by percentage value\n"
4975 "Percentage of routes\n")
4979 "./match-condition[condition='frr-bgp-route-map:probability']";
4980 char xpath_value
[XPATH_MAXLEN
];
4982 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4984 if (argc
<= idx_number
)
4985 return nb_cli_apply_changes(vty
, NULL
);
4987 snprintf(xpath_value
, sizeof(xpath_value
),
4988 "%s/rmap-match-condition/frr-bgp-route-map:probability",
4990 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_DESTROY
,
4991 argv
[idx_number
]->arg
);
4993 return nb_cli_apply_changes(vty
, NULL
);
4997 DEFPY_YANG (match_ip_route_source
,
4998 match_ip_route_source_cmd
,
4999 "match ip route-source ACCESSLIST4_NAME",
5002 "Match advertising source address of route\n"
5003 "IP Access-list name\n")
5006 "./match-condition[condition='frr-bgp-route-map:ip-route-source']";
5007 char xpath_value
[XPATH_MAXLEN
+ 32];
5010 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5011 snprintf(xpath_value
, sizeof(xpath_value
),
5012 "%s/rmap-match-condition/frr-bgp-route-map:list-name",
5014 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5015 argv
[idx_acl
]->arg
);
5017 return nb_cli_apply_changes(vty
, NULL
);
5021 DEFUN_YANG (no_match_ip_route_source
,
5022 no_match_ip_route_source_cmd
,
5023 "no match ip route-source [ACCESSLIST4_NAME]",
5027 "Match advertising source address of route\n"
5028 "IP Access-list name\n")
5031 "./match-condition[condition='frr-bgp-route-map:ip-route-source']";
5033 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5034 return nb_cli_apply_changes(vty
, NULL
);
5037 DEFUN_YANG (match_ip_route_source_prefix_list
,
5038 match_ip_route_source_prefix_list_cmd
,
5039 "match ip route-source prefix-list PREFIXLIST_NAME",
5042 "Match advertising source address of route\n"
5043 "Match entries of prefix-lists\n"
5044 "IP prefix-list name\n")
5048 "./match-condition[condition='frr-bgp-route-map:ip-route-source-prefix-list']";
5049 char xpath_value
[XPATH_MAXLEN
+ 32];
5051 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5052 snprintf(xpath_value
, sizeof(xpath_value
),
5053 "%s/rmap-match-condition/frr-bgp-route-map:list-name", xpath
);
5054 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5055 argv
[idx_word
]->arg
);
5057 return nb_cli_apply_changes(vty
, NULL
);
5061 DEFUN_YANG (no_match_ip_route_source_prefix_list
,
5062 no_match_ip_route_source_prefix_list_cmd
,
5063 "no match ip route-source prefix-list [PREFIXLIST_NAME]",
5067 "Match advertising source address of route\n"
5068 "Match entries of prefix-lists\n"
5069 "IP prefix-list name\n")
5072 "./match-condition[condition='frr-bgp-route-map:ip-route-source-prefix-list']";
5074 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5075 return nb_cli_apply_changes(vty
, NULL
);
5078 DEFUN_YANG (match_local_pref
,
5079 match_local_pref_cmd
,
5080 "match local-preference (0-4294967295)",
5082 "Match local-preference of route\n"
5088 "./match-condition[condition='frr-bgp-route-map:match-local-preference']";
5089 char xpath_value
[XPATH_MAXLEN
];
5091 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5092 snprintf(xpath_value
, sizeof(xpath_value
),
5093 "%s/rmap-match-condition/frr-bgp-route-map:local-preference",
5095 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5096 argv
[idx_number
]->arg
);
5098 return nb_cli_apply_changes(vty
, NULL
);
5102 DEFUN_YANG (no_match_local_pref
,
5103 no_match_local_pref_cmd
,
5104 "no match local-preference [(0-4294967295)]",
5107 "Match local preference of route\n"
5108 "Local preference value\n")
5110 int idx_localpref
= 3;
5112 "./match-condition[condition='frr-bgp-route-map:match-local-preference']";
5113 char xpath_value
[XPATH_MAXLEN
];
5115 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5117 if (argc
<= idx_localpref
)
5118 return nb_cli_apply_changes(vty
, NULL
);
5120 snprintf(xpath_value
, sizeof(xpath_value
),
5121 "%s/rmap-match-condition/frr-bgp-route-map:local-preference",
5123 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_DESTROY
,
5124 argv
[idx_localpref
]->arg
);
5126 return nb_cli_apply_changes(vty
, NULL
);
5129 DEFUN_YANG(match_alias
, match_alias_cmd
, "match alias ALIAS_NAME",
5131 "Match BGP community alias name\n"
5132 "BGP community alias name\n")
5134 const char *alias
= argv
[2]->arg
;
5135 struct community_alias ca1
;
5136 struct community_alias
*lookup_alias
;
5139 "./match-condition[condition='frr-bgp-route-map:match-alias']";
5140 char xpath_value
[XPATH_MAXLEN
];
5142 memset(&ca1
, 0, sizeof(ca1
));
5143 strlcpy(ca1
.alias
, alias
, sizeof(ca1
.alias
));
5144 lookup_alias
= bgp_ca_alias_lookup(&ca1
);
5145 if (!lookup_alias
) {
5146 vty_out(vty
, "%% BGP alias name '%s' does not exist\n", alias
);
5147 return CMD_WARNING_CONFIG_FAILED
;
5150 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5151 snprintf(xpath_value
, sizeof(xpath_value
),
5152 "%s/rmap-match-condition/frr-bgp-route-map:alias", xpath
);
5153 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, alias
);
5155 return nb_cli_apply_changes(vty
, NULL
);
5159 DEFUN_YANG(no_match_alias
, no_match_alias_cmd
, "no match alias [ALIAS_NAME]",
5161 "Match BGP community alias name\n"
5162 "BGP community alias name\n")
5166 "./match-condition[condition='frr-bgp-route-map:match-alias']";
5167 char xpath_value
[XPATH_MAXLEN
];
5169 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5171 if (argc
<= idx_alias
)
5172 return nb_cli_apply_changes(vty
, NULL
);
5174 snprintf(xpath_value
, sizeof(xpath_value
),
5175 "%s/rmap-match-condition/frr-bgp-route-map:alias", xpath
);
5176 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_DESTROY
,
5177 argv
[idx_alias
]->arg
);
5179 return nb_cli_apply_changes(vty
, NULL
);
5182 DEFPY_YANG (match_community
,
5183 match_community_cmd
,
5184 "match community <(1-99)|(100-500)|COMMUNITY_LIST_NAME> [exact-match]",
5186 "Match BGP community list\n"
5187 "Community-list number (standard)\n"
5188 "Community-list number (expanded)\n"
5189 "Community-list name\n"
5190 "Do exact matching of communities\n")
5193 "./match-condition[condition='frr-bgp-route-map:match-community']";
5194 char xpath_value
[XPATH_MAXLEN
];
5195 char xpath_match
[XPATH_MAXLEN
];
5196 int idx_comm_list
= 2;
5198 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5201 xpath_value
, sizeof(xpath_value
),
5202 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name",
5204 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[idx_comm_list
]->arg
);
5208 xpath_match
, sizeof(xpath_match
),
5209 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match",
5211 nb_cli_enqueue_change(vty
, xpath_match
, NB_OP_MODIFY
,
5215 xpath_match
, sizeof(xpath_match
),
5216 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match",
5218 nb_cli_enqueue_change(vty
, xpath_match
, NB_OP_MODIFY
,
5222 return nb_cli_apply_changes(vty
, NULL
);
5225 DEFUN_YANG (no_match_community
,
5226 no_match_community_cmd
,
5227 "no match community [<(1-99)|(100-500)|COMMUNITY_LIST_NAME> [exact-match]]",
5230 "Match BGP community list\n"
5231 "Community-list number (standard)\n"
5232 "Community-list number (expanded)\n"
5233 "Community-list name\n"
5234 "Do exact matching of communities\n")
5237 "./match-condition[condition='frr-bgp-route-map:match-community']";
5239 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5240 return nb_cli_apply_changes(vty
, NULL
);
5243 DEFPY_YANG (match_lcommunity
,
5244 match_lcommunity_cmd
,
5245 "match large-community <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME> [exact-match]",
5247 "Match BGP large community list\n"
5248 "Large Community-list number (standard)\n"
5249 "Large Community-list number (expanded)\n"
5250 "Large Community-list name\n"
5251 "Do exact matching of communities\n")
5254 "./match-condition[condition='frr-bgp-route-map:match-large-community']";
5255 char xpath_value
[XPATH_MAXLEN
];
5256 char xpath_match
[XPATH_MAXLEN
];
5257 int idx_lcomm_list
= 2;
5259 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5262 xpath_value
, sizeof(xpath_value
),
5263 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name",
5265 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[idx_lcomm_list
]->arg
);
5269 xpath_match
, sizeof(xpath_match
),
5270 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match",
5272 nb_cli_enqueue_change(vty
, xpath_match
, NB_OP_MODIFY
,
5276 xpath_match
, sizeof(xpath_match
),
5277 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match",
5279 nb_cli_enqueue_change(vty
, xpath_match
, NB_OP_MODIFY
,
5283 return nb_cli_apply_changes(vty
, NULL
);
5286 DEFUN_YANG (no_match_lcommunity
,
5287 no_match_lcommunity_cmd
,
5288 "no match large-community [<(1-99)|(100-500)|LCOMMUNITY_LIST_NAME> [exact-match]]",
5291 "Match BGP large community list\n"
5292 "Large Community-list number (standard)\n"
5293 "Large Community-list number (expanded)\n"
5294 "Large Community-list name\n"
5295 "Do exact matching of communities\n")
5298 "./match-condition[condition='frr-bgp-route-map:match-large-community']";
5300 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5301 return nb_cli_apply_changes(vty
, NULL
);
5304 DEFPY_YANG (match_ecommunity
,
5305 match_ecommunity_cmd
,
5306 "match extcommunity <(1-99)|(100-500)|EXTCOMMUNITY_LIST_NAME>",
5308 "Match BGP/VPN extended community list\n"
5309 "Extended community-list number (standard)\n"
5310 "Extended community-list number (expanded)\n"
5311 "Extended community-list name\n")
5314 "./match-condition[condition='frr-bgp-route-map:match-extcommunity']";
5315 char xpath_value
[XPATH_MAXLEN
];
5316 int idx_comm_list
= 2;
5318 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5321 xpath_value
, sizeof(xpath_value
),
5322 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name",
5324 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[idx_comm_list
]->arg
);
5326 return nb_cli_apply_changes(vty
, NULL
);
5330 DEFUN_YANG (no_match_ecommunity
,
5331 no_match_ecommunity_cmd
,
5332 "no match extcommunity [<(1-99)|(100-500)|EXTCOMMUNITY_LIST_NAME>]",
5335 "Match BGP/VPN extended community list\n"
5336 "Extended community-list number (standard)\n"
5337 "Extended community-list number (expanded)\n"
5338 "Extended community-list name\n")
5341 "./match-condition[condition='frr-bgp-route-map:match-extcommunity']";
5343 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5344 return nb_cli_apply_changes(vty
, NULL
);
5348 DEFUN_YANG (match_aspath
,
5350 "match as-path AS_PATH_FILTER_NAME",
5352 "Match BGP AS path list\n"
5353 "AS path access-list name\n")
5358 "./match-condition[condition='frr-bgp-route-map:as-path-list']";
5359 char xpath_value
[XPATH_MAXLEN
];
5361 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5362 snprintf(xpath_value
, sizeof(xpath_value
),
5363 "%s/rmap-match-condition/frr-bgp-route-map:list-name", xpath
);
5364 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5365 argv
[idx_word
]->arg
);
5367 return nb_cli_apply_changes(vty
, NULL
);
5371 DEFUN_YANG (no_match_aspath
,
5372 no_match_aspath_cmd
,
5373 "no match as-path [AS_PATH_FILTER_NAME]",
5376 "Match BGP AS path list\n"
5377 "AS path access-list name\n")
5380 "./match-condition[condition='frr-bgp-route-map:as-path-list']";
5382 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5384 return nb_cli_apply_changes(vty
, NULL
);
5387 DEFUN_YANG (match_origin
,
5389 "match origin <egp|igp|incomplete>",
5394 "unknown heritage\n")
5397 const char *origin_type
;
5399 "./match-condition[condition='frr-bgp-route-map:match-origin']";
5400 char xpath_value
[XPATH_MAXLEN
];
5402 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
5403 origin_type
= "igp";
5404 else if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
5405 origin_type
= "egp";
5406 else if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
5407 origin_type
= "incomplete";
5409 vty_out(vty
, "%% Invalid match origin type\n");
5410 return CMD_WARNING_CONFIG_FAILED
;
5413 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5414 snprintf(xpath_value
, sizeof(xpath_value
),
5415 "%s/rmap-match-condition/frr-bgp-route-map:origin", xpath
);
5416 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, origin_type
);
5418 return nb_cli_apply_changes(vty
, NULL
);
5422 DEFUN_YANG (no_match_origin
,
5423 no_match_origin_cmd
,
5424 "no match origin [<egp|igp|incomplete>]",
5430 "unknown heritage\n")
5433 "./match-condition[condition='frr-bgp-route-map:match-origin']";
5434 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5435 return nb_cli_apply_changes(vty
, NULL
);
5438 DEFUN_YANG (set_table_id
,
5440 "set table (1-4294967295)",
5442 "export route to non-main kernel table\n"
5443 "Kernel routing table id\n")
5446 const char *xpath
= "./set-action[action='frr-bgp-route-map:table']";
5447 char xpath_value
[XPATH_MAXLEN
];
5449 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5450 snprintf(xpath_value
, sizeof(xpath_value
),
5451 "%s/rmap-set-action/frr-bgp-route-map:table", xpath
);
5452 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5453 argv
[idx_number
]->arg
);
5454 return nb_cli_apply_changes(vty
, NULL
);
5457 DEFUN_YANG (no_set_table_id
,
5458 no_set_table_id_cmd
,
5462 "export route to non-main kernel table\n")
5464 const char *xpath
= "./set-action[action='frr-bgp-route-map:table']";
5465 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5466 return nb_cli_apply_changes(vty
, NULL
);
5469 DEFUN_YANG (set_ip_nexthop_peer
,
5470 set_ip_nexthop_peer_cmd
,
5471 "[no] set ip next-hop peer-address",
5475 "Next hop address\n"
5476 "Use peer address (for BGP only)\n")
5478 char xpath_value
[XPATH_MAXLEN
];
5480 "./set-action[action='frr-bgp-route-map:set-ipv4-nexthop']";
5482 if (strmatch(argv
[0]->text
, "no"))
5483 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5485 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5486 snprintf(xpath_value
, sizeof(xpath_value
),
5487 "%s/rmap-set-action/frr-bgp-route-map:ipv4-nexthop",
5489 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5492 return nb_cli_apply_changes(vty
, NULL
);
5495 DEFUN_YANG (set_ip_nexthop_unchanged
,
5496 set_ip_nexthop_unchanged_cmd
,
5497 "[no] set ip next-hop unchanged",
5501 "Next hop address\n"
5502 "Don't modify existing Next hop address\n")
5504 char xpath_value
[XPATH_MAXLEN
];
5506 "./set-action[action='frr-bgp-route-map:set-ipv4-nexthop']";
5508 if (strmatch(argv
[0]->text
, "no"))
5509 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5511 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5512 snprintf(xpath_value
, sizeof(xpath_value
),
5513 "%s/rmap-set-action/frr-bgp-route-map:ipv4-nexthop",
5515 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5518 return nb_cli_apply_changes(vty
, NULL
);
5521 DEFUN_YANG (set_distance
,
5523 "set distance (1-255)",
5525 "BGP Administrative Distance to use\n"
5529 const char *xpath
= "./set-action[action='frr-bgp-route-map:distance']";
5530 char xpath_value
[XPATH_MAXLEN
];
5532 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5533 snprintf(xpath_value
, sizeof(xpath_value
),
5534 "%s/rmap-set-action/frr-bgp-route-map:distance", xpath
);
5535 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5536 argv
[idx_number
]->arg
);
5537 return nb_cli_apply_changes(vty
, NULL
);
5540 DEFUN_YANG (no_set_distance
,
5541 no_set_distance_cmd
,
5542 "no set distance [(1-255)]",
5544 "BGP Administrative Distance to use\n"
5547 const char *xpath
= "./set-action[action='frr-bgp-route-map:distance']";
5549 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5550 return nb_cli_apply_changes(vty
, NULL
);
5553 DEFPY_YANG(set_l3vpn_nexthop_encapsulation
, set_l3vpn_nexthop_encapsulation_cmd
,
5554 "[no] set l3vpn next-hop encapsulation gre",
5556 "L3VPN operations\n"
5557 "Next hop Information\n"
5558 "Encapsulation options (for BGP only)\n"
5559 "Accept L3VPN traffic over GRE encapsulation\n")
5562 "./set-action[action='frr-bgp-route-map:set-l3vpn-nexthop-encapsulation']";
5563 const char *xpath_value
=
5564 "./set-action[action='frr-bgp-route-map:set-l3vpn-nexthop-encapsulation']/rmap-set-action/frr-bgp-route-map:l3vpn-nexthop-encapsulation";
5565 enum nb_operation operation
;
5568 operation
= NB_OP_DESTROY
;
5570 operation
= NB_OP_CREATE
;
5572 nb_cli_enqueue_change(vty
, xpath
, operation
, NULL
);
5573 if (operation
== NB_OP_DESTROY
)
5574 return nb_cli_apply_changes(vty
, NULL
);
5576 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "gre");
5578 return nb_cli_apply_changes(vty
, NULL
);
5581 DEFUN_YANG (set_local_pref
,
5583 "set local-preference WORD",
5585 "BGP local preference path attribute\n"
5586 "Preference value (0-4294967295)\n")
5590 "./set-action[action='frr-bgp-route-map:set-local-preference']";
5591 char xpath_value
[XPATH_MAXLEN
];
5593 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5594 snprintf(xpath_value
, sizeof(xpath_value
),
5595 "%s/rmap-set-action/frr-bgp-route-map:local-pref", xpath
);
5596 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5597 argv
[idx_number
]->arg
);
5598 return nb_cli_apply_changes(vty
, NULL
);
5601 DEFUN_YANG (no_set_local_pref
,
5602 no_set_local_pref_cmd
,
5603 "no set local-preference [WORD]",
5606 "BGP local preference path attribute\n"
5607 "Preference value (0-4294967295)\n")
5610 "./set-action[action='frr-bgp-route-map:set-local-preference']";
5612 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5613 return nb_cli_apply_changes(vty
, NULL
);
5616 DEFUN_YANG (set_weight
,
5618 "set weight (0-4294967295)",
5620 "BGP weight for routing table\n"
5624 const char *xpath
= "./set-action[action='frr-bgp-route-map:weight']";
5625 char xpath_value
[XPATH_MAXLEN
];
5627 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5628 snprintf(xpath_value
, sizeof(xpath_value
),
5629 "%s/rmap-set-action/frr-bgp-route-map:weight", xpath
);
5630 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5631 argv
[idx_number
]->arg
);
5632 return nb_cli_apply_changes(vty
, NULL
);
5635 DEFUN_YANG (no_set_weight
,
5637 "no set weight [(0-4294967295)]",
5640 "BGP weight for routing table\n"
5643 const char *xpath
= "./set-action[action='frr-bgp-route-map:weight']";
5645 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5646 return nb_cli_apply_changes(vty
, NULL
);
5649 DEFUN_YANG (set_label_index
,
5650 set_label_index_cmd
,
5651 "set label-index (0-1048560)",
5653 "Label index to associate with the prefix\n"
5654 "Label index value\n")
5658 "./set-action[action='frr-bgp-route-map:label-index']";
5659 char xpath_value
[XPATH_MAXLEN
];
5661 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5662 snprintf(xpath_value
, sizeof(xpath_value
),
5663 "%s/rmap-set-action/frr-bgp-route-map:label-index", xpath
);
5664 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5665 argv
[idx_number
]->arg
);
5666 return nb_cli_apply_changes(vty
, NULL
);
5669 DEFUN_YANG (no_set_label_index
,
5670 no_set_label_index_cmd
,
5671 "no set label-index [(0-1048560)]",
5674 "Label index to associate with the prefix\n"
5675 "Label index value\n")
5678 "./set-action[action='frr-bgp-route-map:label-index']";
5680 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5681 return nb_cli_apply_changes(vty
, NULL
);
5684 DEFUN_YANG (set_aspath_prepend_asn
,
5685 set_aspath_prepend_asn_cmd
,
5686 "set as-path prepend ASNUM...",
5688 "Transform BGP AS_PATH attribute\n"
5689 "Prepend to the as-path\n"
5695 struct aspath
*aspath
;
5697 str
= argv_concat(argv
, argc
, idx_asn
);
5700 "./set-action[action='frr-bgp-route-map:as-path-prepend']";
5701 char xpath_value
[XPATH_MAXLEN
];
5703 aspath
= route_aspath_compile(str
);
5705 vty_out(vty
, "%% Invalid AS path value %s\n", str
);
5706 return CMD_WARNING_CONFIG_FAILED
;
5708 route_aspath_free(aspath
);
5709 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5710 snprintf(xpath_value
, sizeof(xpath_value
),
5711 "%s/rmap-set-action/frr-bgp-route-map:prepend-as-path", xpath
);
5712 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
5713 ret
= nb_cli_apply_changes(vty
, NULL
);
5714 XFREE(MTYPE_TMP
, str
);
5718 DEFUN_YANG (set_aspath_prepend_lastas
,
5719 set_aspath_prepend_lastas_cmd
,
5720 "set as-path prepend last-as (1-10)",
5722 "Transform BGP AS_PATH attribute\n"
5723 "Prepend to the as-path\n"
5724 "Use the last AS-number in the as-path\n"
5725 "Number of times to insert\n")
5730 "./set-action[action='frr-bgp-route-map:as-path-prepend']";
5731 char xpath_value
[XPATH_MAXLEN
];
5733 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5734 snprintf(xpath_value
, sizeof(xpath_value
),
5735 "%s/rmap-set-action/frr-bgp-route-map:last-as", xpath
);
5736 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5737 argv
[idx_num
]->arg
);
5738 return nb_cli_apply_changes(vty
, NULL
);
5741 DEFPY_YANG (set_aspath_replace_asn
,
5742 set_aspath_replace_asn_cmd
,
5743 "set as-path replace <any|ASNUM>$replace",
5745 "Transform BGP AS_PATH attribute\n"
5746 "Replace AS number to local AS number\n"
5747 "Replace any AS number to local AS number\n"
5748 "Replace a specific AS number in plain or dotted format to local AS number\n")
5751 "./set-action[action='frr-bgp-route-map:as-path-replace']";
5752 char xpath_value
[XPATH_MAXLEN
];
5755 if (!strmatch(replace
, "any") && !asn_str2asn(replace
, &as_value
)) {
5756 vty_out(vty
, "%% Invalid AS value %s\n", replace
);
5757 return CMD_WARNING_CONFIG_FAILED
;
5760 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5761 snprintf(xpath_value
, sizeof(xpath_value
),
5762 "%s/rmap-set-action/frr-bgp-route-map:replace-as-path", xpath
);
5763 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, replace
);
5764 return nb_cli_apply_changes(vty
, NULL
);
5767 DEFPY_YANG (no_set_aspath_replace_asn
,
5768 no_set_aspath_replace_asn_cmd
,
5769 "no set as-path replace [<any|ASNUM>]",
5772 "Transform BGP AS_PATH attribute\n"
5773 "Replace AS number to local AS number\n"
5774 "Replace any AS number to local AS number\n"
5775 "Replace a specific AS number in plain or dotted format to local AS number\n")
5778 "./set-action[action='frr-bgp-route-map:as-path-replace']";
5780 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5781 return nb_cli_apply_changes(vty
, NULL
);
5784 DEFUN_YANG (no_set_aspath_prepend
,
5785 no_set_aspath_prepend_cmd
,
5786 "no set as-path prepend [ASNUM]",
5789 "Transform BGP AS_PATH attribute\n"
5790 "Prepend to the as-path\n"
5794 "./set-action[action='frr-bgp-route-map:as-path-prepend']";
5796 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5797 return nb_cli_apply_changes(vty
, NULL
);
5800 DEFUN_YANG (no_set_aspath_prepend_lastas
,
5801 no_set_aspath_prepend_lastas_cmd
,
5802 "no set as-path prepend last-as [(1-10)]",
5805 "Transform BGP AS_PATH attribute\n"
5806 "Prepend to the as-path\n"
5807 "Use the peers AS-number\n"
5808 "Number of times to insert\n")
5811 "./set-action[action='frr-bgp-route-map:as-path-prepend']";
5813 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5814 return nb_cli_apply_changes(vty
, NULL
);
5817 DEFUN_YANG (set_aspath_exclude
,
5818 set_aspath_exclude_cmd
,
5819 "set as-path exclude ASNUM...",
5821 "Transform BGP AS-path attribute\n"
5822 "Exclude from the as-path\n"
5828 struct aspath
*aspath
;
5830 str
= argv_concat(argv
, argc
, idx_asn
);
5833 "./set-action[action='frr-bgp-route-map:as-path-exclude']";
5834 char xpath_value
[XPATH_MAXLEN
];
5836 aspath
= route_aspath_compile(str
);
5838 vty_out(vty
, "%% Invalid AS path value %s\n", str
);
5839 return CMD_WARNING_CONFIG_FAILED
;
5841 route_aspath_free(aspath
);
5842 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5843 snprintf(xpath_value
, sizeof(xpath_value
),
5844 "%s/rmap-set-action/frr-bgp-route-map:exclude-as-path", xpath
);
5845 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
5846 ret
= nb_cli_apply_changes(vty
, NULL
);
5847 XFREE(MTYPE_TMP
, str
);
5851 DEFUN_YANG (no_set_aspath_exclude
,
5852 no_set_aspath_exclude_cmd
,
5853 "no set as-path exclude ASNUM...",
5856 "Transform BGP AS_PATH attribute\n"
5857 "Exclude from the as-path\n"
5861 "./set-action[action='frr-bgp-route-map:as-path-exclude']";
5863 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5864 return nb_cli_apply_changes(vty
, NULL
);
5867 ALIAS_YANG (no_set_aspath_exclude
, no_set_aspath_exclude_all_cmd
,
5868 "no set as-path exclude",
5870 "Transform BGP AS_PATH attribute\n"
5871 "Exclude from the as-path\n")
5873 DEFUN_YANG (set_community
,
5875 "set community AA:NN...",
5877 "BGP community attribute\n"
5885 struct community
*com
= NULL
;
5887 char *argstr
= NULL
;
5891 "./set-action[action='frr-bgp-route-map:set-community']";
5892 char xpath_value
[XPATH_MAXLEN
];
5894 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5895 snprintf(xpath_value
, sizeof(xpath_value
),
5896 "%s/rmap-set-action/frr-bgp-route-map:community-string",
5899 b
= buffer_new(1024);
5901 for (i
= idx_aa_nn
; i
< argc
; i
++) {
5902 if (strncmp(argv
[i
]->arg
, "additive", strlen(argv
[i
]->arg
))
5909 buffer_putc(b
, ' ');
5913 #if CONFDATE > 20230801
5914 CPP_NOTICE("Deprecate COMMUNITY_INTERNET BGP community")
5916 if (strncmp(argv
[i
]->arg
, "internet", strlen(argv
[i
]->arg
))
5918 buffer_putstr(b
, "internet");
5919 vty_out(vty
, "%% `internet` community is deprecated\n");
5920 zlog_warn("`internet` community is deprecated");
5923 if (strncmp(argv
[i
]->arg
, "local-AS", strlen(argv
[i
]->arg
))
5925 buffer_putstr(b
, "local-AS");
5928 if (strncmp(argv
[i
]->arg
, "no-a", strlen("no-a")) == 0
5929 && strncmp(argv
[i
]->arg
, "no-advertise",
5930 strlen(argv
[i
]->arg
))
5932 buffer_putstr(b
, "no-advertise");
5935 if (strncmp(argv
[i
]->arg
, "no-e", strlen("no-e")) == 0
5936 && strncmp(argv
[i
]->arg
, "no-export", strlen(argv
[i
]->arg
))
5938 buffer_putstr(b
, "no-export");
5941 if (strncmp(argv
[i
]->arg
, "blackhole", strlen(argv
[i
]->arg
))
5943 buffer_putstr(b
, "blackhole");
5946 if (strncmp(argv
[i
]->arg
, "graceful-shutdown",
5947 strlen(argv
[i
]->arg
))
5949 buffer_putstr(b
, "graceful-shutdown");
5952 buffer_putstr(b
, argv
[i
]->arg
);
5954 buffer_putc(b
, '\0');
5956 /* Fetch result string then compile it to communities attribute. */
5957 str
= buffer_getstr(b
);
5961 com
= community_str2com(str
);
5963 /* Can't compile user input into communities attribute. */
5965 vty_out(vty
, "%% Malformed communities attribute '%s'\n", str
);
5966 XFREE(MTYPE_TMP
, str
);
5967 return CMD_WARNING_CONFIG_FAILED
;
5969 XFREE(MTYPE_TMP
, str
);
5971 /* Set communites attribute string. */
5972 str
= community_str(com
, false, false);
5975 size_t argstr_sz
= strlen(str
) + strlen(" additive") + 1;
5976 argstr
= XCALLOC(MTYPE_TMP
, argstr_sz
);
5977 strlcpy(argstr
, str
, argstr_sz
);
5978 strlcat(argstr
, " additive", argstr_sz
);
5979 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argstr
);
5981 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
5983 ret
= nb_cli_apply_changes(vty
, NULL
);
5986 XFREE(MTYPE_TMP
, argstr
);
5987 community_free(&com
);
5992 DEFUN_YANG (set_community_none
,
5993 set_community_none_cmd
,
5994 "set community none",
5996 "BGP community attribute\n"
5997 "No community attribute\n")
6000 "./set-action[action='frr-bgp-route-map:set-community']";
6001 char xpath_value
[XPATH_MAXLEN
];
6003 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6005 snprintf(xpath_value
, sizeof(xpath_value
),
6006 "%s/rmap-set-action/frr-bgp-route-map:community-none", xpath
);
6007 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
6008 return nb_cli_apply_changes(vty
, NULL
);
6011 DEFUN_YANG (no_set_community
,
6012 no_set_community_cmd
,
6013 "no set community AA:NN...",
6016 "BGP community attribute\n"
6020 "./set-action[action='frr-bgp-route-map:set-community']";
6022 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6023 return nb_cli_apply_changes(vty
, NULL
);
6026 ALIAS_YANG (no_set_community
,
6027 no_set_community_short_cmd
,
6031 "BGP community attribute\n")
6033 DEFPY_YANG (set_community_delete
,
6034 set_community_delete_cmd
,
6035 "set comm-list <(1-99)|(100-500)|COMMUNITY_LIST_NAME> delete",
6037 "set BGP community list (for deletion)\n"
6038 "Community-list number (standard)\n"
6039 "Community-list number (expanded)\n"
6040 "Community-list name\n"
6041 "Delete matching communities\n")
6044 "./set-action[action='frr-bgp-route-map:comm-list-delete']";
6045 char xpath_value
[XPATH_MAXLEN
];
6046 int idx_comm_list
= 2;
6048 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6050 snprintf(xpath_value
, sizeof(xpath_value
),
6051 "%s/rmap-set-action/frr-bgp-route-map:comm-list-name",
6053 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6054 argv
[idx_comm_list
]->arg
);
6056 return nb_cli_apply_changes(vty
, NULL
);
6060 DEFUN_YANG (no_set_community_delete
,
6061 no_set_community_delete_cmd
,
6062 "no set comm-list [<(1-99)|(100-500)|COMMUNITY_LIST_NAME> delete]",
6065 "set BGP community list (for deletion)\n"
6066 "Community-list number (standard)\n"
6067 "Community-list number (expanded)\n"
6068 "Community-list name\n"
6069 "Delete matching communities\n")
6072 "./set-action[action='frr-bgp-route-map:comm-list-delete']";
6074 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6075 return nb_cli_apply_changes(vty
, NULL
);
6078 DEFUN_YANG (set_lcommunity
,
6080 "set large-community AA:BB:CC...",
6082 "BGP large community attribute\n"
6083 "Large Community number in aa:bb:cc format or additive\n")
6088 "./set-action[action='frr-bgp-route-map:set-large-community']";
6089 char xpath_value
[XPATH_MAXLEN
];
6091 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6093 snprintf(xpath_value
, sizeof(xpath_value
),
6094 "%s/rmap-set-action/frr-bgp-route-map:large-community-string",
6096 str
= argv_concat(argv
, argc
, 2);
6097 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
6098 ret
= nb_cli_apply_changes(vty
, NULL
);
6099 XFREE(MTYPE_TMP
, str
);
6103 DEFUN_YANG (set_lcommunity_none
,
6104 set_lcommunity_none_cmd
,
6105 "set large-community none",
6107 "BGP large community attribute\n"
6108 "No large community attribute\n")
6111 "./set-action[action='frr-bgp-route-map:set-large-community']";
6112 char xpath_value
[XPATH_MAXLEN
];
6114 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6116 snprintf(xpath_value
, sizeof(xpath_value
),
6117 "%s/rmap-set-action/frr-bgp-route-map:large-community-none",
6119 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
6120 return nb_cli_apply_changes(vty
, NULL
);
6123 DEFUN_YANG (no_set_lcommunity
,
6124 no_set_lcommunity_cmd
,
6125 "no set large-community none",
6128 "BGP large community attribute\n"
6129 "No community attribute\n")
6132 "./set-action[action='frr-bgp-route-map:set-large-community']";
6134 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6135 return nb_cli_apply_changes(vty
, NULL
);
6138 DEFUN_YANG (no_set_lcommunity1
,
6139 no_set_lcommunity1_cmd
,
6140 "no set large-community AA:BB:CC...",
6143 "BGP large community attribute\n"
6144 "Large community in AA:BB:CC... format or additive\n")
6147 "./set-action[action='frr-bgp-route-map:set-large-community']";
6149 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6150 return nb_cli_apply_changes(vty
, NULL
);
6153 ALIAS_YANG (no_set_lcommunity1
,
6154 no_set_lcommunity1_short_cmd
,
6155 "no set large-community",
6158 "BGP large community attribute\n")
6160 DEFPY_YANG (set_lcommunity_delete
,
6161 set_lcommunity_delete_cmd
,
6162 "set large-comm-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME> delete",
6164 "set BGP large community list (for deletion)\n"
6165 "Large Community-list number (standard)\n"
6166 "Large Communitly-list number (expanded)\n"
6167 "Large Community-list name\n"
6168 "Delete matching large communities\n")
6171 "./set-action[action='frr-bgp-route-map:large-comm-list-delete']";
6172 char xpath_value
[XPATH_MAXLEN
];
6173 int idx_lcomm_list
= 2;
6175 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6177 snprintf(xpath_value
, sizeof(xpath_value
),
6178 "%s/rmap-set-action/frr-bgp-route-map:comm-list-name",
6180 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6181 argv
[idx_lcomm_list
]->arg
);
6183 return nb_cli_apply_changes(vty
, NULL
);
6186 DEFUN_YANG (no_set_lcommunity_delete
,
6187 no_set_lcommunity_delete_cmd
,
6188 "no set large-comm-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME> [delete]",
6191 "set BGP large community list (for deletion)\n"
6192 "Large Community-list number (standard)\n"
6193 "Large Communitly-list number (expanded)\n"
6194 "Large Community-list name\n"
6195 "Delete matching large communities\n")
6198 "./set-action[action='frr-bgp-route-map:large-comm-list-delete']";
6200 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6201 return nb_cli_apply_changes(vty
, NULL
);
6204 ALIAS_YANG (no_set_lcommunity_delete
,
6205 no_set_lcommunity_delete_short_cmd
,
6206 "no set large-comm-list",
6209 "set BGP large community list (for deletion)\n")
6211 DEFUN_YANG (set_ecommunity_rt
,
6212 set_ecommunity_rt_cmd
,
6213 "set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
6215 "BGP extended community attribute\n"
6216 "Route Target extended community\n"
6217 "VPN extended community\n")
6223 "./set-action[action='frr-bgp-route-map:set-extcommunity-rt']";
6224 char xpath_value
[XPATH_MAXLEN
];
6226 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6228 snprintf(xpath_value
, sizeof(xpath_value
),
6229 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-rt", xpath
);
6230 str
= argv_concat(argv
, argc
, idx_asn_nn
);
6231 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
6232 ret
= nb_cli_apply_changes(vty
, NULL
);
6233 XFREE(MTYPE_TMP
, str
);
6237 DEFUN_YANG (no_set_ecommunity_rt
,
6238 no_set_ecommunity_rt_cmd
,
6239 "no set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
6242 "BGP extended community attribute\n"
6243 "Route Target extended community\n"
6244 "VPN extended community\n")
6247 "./set-action[action='frr-bgp-route-map:set-extcommunity-rt']";
6248 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6249 return nb_cli_apply_changes(vty
, NULL
);
6252 ALIAS_YANG (no_set_ecommunity_rt
,
6253 no_set_ecommunity_rt_short_cmd
,
6254 "no set extcommunity rt",
6257 "BGP extended community attribute\n"
6258 "Route Target extended community\n")
6260 DEFUN_YANG (set_ecommunity_soo
,
6261 set_ecommunity_soo_cmd
,
6262 "set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
6264 "BGP extended community attribute\n"
6265 "Site-of-Origin extended community\n"
6266 "VPN extended community\n")
6272 "./set-action[action='frr-bgp-route-map:set-extcommunity-soo']";
6273 char xpath_value
[XPATH_MAXLEN
];
6275 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6277 snprintf(xpath_value
, sizeof(xpath_value
),
6278 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-soo",
6280 str
= argv_concat(argv
, argc
, idx_asn_nn
);
6281 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
6282 ret
= nb_cli_apply_changes(vty
, NULL
);
6283 XFREE(MTYPE_TMP
, str
);
6287 DEFUN_YANG (no_set_ecommunity_soo
,
6288 no_set_ecommunity_soo_cmd
,
6289 "no set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
6292 "BGP extended community attribute\n"
6293 "Site-of-Origin extended community\n"
6294 "VPN extended community\n")
6297 "./set-action[action='frr-bgp-route-map:set-extcommunity-soo']";
6298 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6299 return nb_cli_apply_changes(vty
, NULL
);
6302 ALIAS_YANG (no_set_ecommunity_soo
,
6303 no_set_ecommunity_soo_short_cmd
,
6304 "no set extcommunity soo",
6307 "GP extended community attribute\n"
6308 "Site-of-Origin extended community\n")
6310 DEFUN_YANG(set_ecommunity_none
, set_ecommunity_none_cmd
,
6311 "set extcommunity none",
6313 "BGP extended community attribute\n"
6314 "No extended community attribute\n")
6317 "./set-action[action='frr-bgp-route-map:set-extcommunity-none']";
6318 char xpath_value
[XPATH_MAXLEN
];
6320 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6322 snprintf(xpath_value
, sizeof(xpath_value
),
6323 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-none",
6325 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
6326 return nb_cli_apply_changes(vty
, NULL
);
6329 DEFUN_YANG(no_set_ecommunity_none
, no_set_ecommunity_none_cmd
,
6330 "no set extcommunity none",
6332 "BGP extended community attribute\n"
6333 "No extended community attribute\n")
6336 "./set-action[action='frr-bgp-route-map:set-extcommunity-none']";
6337 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6338 return nb_cli_apply_changes(vty
, NULL
);
6341 DEFUN_YANG (set_ecommunity_lb
,
6342 set_ecommunity_lb_cmd
,
6343 "set extcommunity bandwidth <(1-25600)|cumulative|num-multipaths> [non-transitive]",
6345 "BGP extended community attribute\n"
6346 "Link bandwidth extended community\n"
6347 "Bandwidth value in Mbps\n"
6348 "Cumulative bandwidth of all multipaths (outbound-only)\n"
6349 "Internally computed bandwidth based on number of multipaths (outbound-only)\n"
6350 "Attribute is set as non-transitive\n")
6353 int idx_non_transitive
= 0;
6355 "./set-action[action='frr-bgp-route-map:set-extcommunity-lb']";
6356 char xpath_lb_type
[XPATH_MAXLEN
];
6357 char xpath_bandwidth
[XPATH_MAXLEN
];
6358 char xpath_non_transitive
[XPATH_MAXLEN
];
6360 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6362 snprintf(xpath_lb_type
, sizeof(xpath_lb_type
),
6363 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-lb/lb-type",
6365 snprintf(xpath_bandwidth
, sizeof(xpath_bandwidth
),
6366 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-lb/bandwidth",
6368 snprintf(xpath_non_transitive
, sizeof(xpath_non_transitive
),
6369 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-lb/two-octet-as-specific",
6372 if ((strcmp(argv
[idx_lb
]->arg
, "cumulative")) == 0)
6373 nb_cli_enqueue_change(vty
, xpath_lb_type
, NB_OP_MODIFY
,
6374 "cumulative-bandwidth");
6375 else if ((strcmp(argv
[idx_lb
]->arg
, "num-multipaths")) == 0)
6376 nb_cli_enqueue_change(vty
, xpath_lb_type
, NB_OP_MODIFY
,
6377 "computed-bandwidth");
6379 nb_cli_enqueue_change(vty
, xpath_lb_type
, NB_OP_MODIFY
,
6380 "explicit-bandwidth");
6381 nb_cli_enqueue_change(vty
, xpath_bandwidth
, NB_OP_MODIFY
,
6385 if (argv_find(argv
, argc
, "non-transitive", &idx_non_transitive
))
6386 nb_cli_enqueue_change(vty
, xpath_non_transitive
, NB_OP_MODIFY
,
6389 nb_cli_enqueue_change(vty
, xpath_non_transitive
, NB_OP_MODIFY
,
6392 return nb_cli_apply_changes(vty
, NULL
);
6395 DEFUN_YANG (no_set_ecommunity_lb
,
6396 no_set_ecommunity_lb_cmd
,
6397 "no set extcommunity bandwidth <(1-25600)|cumulative|num-multipaths> [non-transitive]",
6400 "BGP extended community attribute\n"
6401 "Link bandwidth extended community\n"
6402 "Bandwidth value in Mbps\n"
6403 "Cumulative bandwidth of all multipaths (outbound-only)\n"
6404 "Internally computed bandwidth based on number of multipaths (outbound-only)\n"
6405 "Attribute is set as non-transitive\n")
6408 "./set-action[action='frr-bgp-route-map:set-extcommunity-lb']";
6410 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6411 return nb_cli_apply_changes(vty
, NULL
);
6414 ALIAS_YANG (no_set_ecommunity_lb
,
6415 no_set_ecommunity_lb_short_cmd
,
6416 "no set extcommunity bandwidth",
6419 "BGP extended community attribute\n"
6420 "Link bandwidth extended community\n")
6422 DEFUN_YANG (set_origin
,
6424 "set origin <egp|igp|incomplete>",
6429 "unknown heritage\n")
6432 const char *origin_type
;
6434 "./set-action[action='frr-bgp-route-map:set-origin']";
6435 char xpath_value
[XPATH_MAXLEN
];
6437 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
6438 origin_type
= "igp";
6439 else if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
6440 origin_type
= "egp";
6441 else if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
6442 origin_type
= "incomplete";
6444 vty_out(vty
, "%% Invalid match origin type\n");
6445 return CMD_WARNING_CONFIG_FAILED
;
6448 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6449 snprintf(xpath_value
, sizeof(xpath_value
),
6450 "%s/rmap-set-action/frr-bgp-route-map:origin", xpath
);
6451 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, origin_type
);
6453 return nb_cli_apply_changes(vty
, NULL
);
6456 DEFUN_YANG (no_set_origin
,
6458 "no set origin [<egp|igp|incomplete>]",
6464 "unknown heritage\n")
6467 "./set-action[action='frr-bgp-route-map:set-origin']";
6469 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6470 return nb_cli_apply_changes(vty
, NULL
);
6473 DEFUN_YANG (set_atomic_aggregate
,
6474 set_atomic_aggregate_cmd
,
6475 "set atomic-aggregate",
6477 "BGP atomic aggregate attribute\n" )
6480 "./set-action[action='frr-bgp-route-map:atomic-aggregate']";
6481 char xpath_value
[XPATH_MAXLEN
];
6483 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6484 snprintf(xpath_value
, sizeof(xpath_value
),
6485 "%s/rmap-set-action/frr-bgp-route-map:atomic-aggregate",
6487 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, NULL
);
6489 return nb_cli_apply_changes(vty
, NULL
);
6492 DEFUN_YANG (no_set_atomic_aggregate
,
6493 no_set_atomic_aggregate_cmd
,
6494 "no set atomic-aggregate",
6497 "BGP atomic aggregate attribute\n" )
6500 "./set-action[action='frr-bgp-route-map:atomic-aggregate']";
6502 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6503 return nb_cli_apply_changes(vty
, NULL
);
6506 DEFPY_YANG (set_aigp_metric
,
6507 set_aigp_metric_cmd
,
6508 "set aigp-metric <igp-metric|(1-4294967295)>$aigp_metric",
6510 "BGP AIGP attribute (AIGP Metric TLV)\n"
6511 "AIGP Metric value from IGP protocol\n"
6512 "Manual AIGP Metric value\n")
6515 "./set-action[action='frr-bgp-route-map:aigp-metric']";
6516 char xpath_value
[XPATH_MAXLEN
];
6518 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6519 snprintf(xpath_value
, sizeof(xpath_value
),
6520 "%s/rmap-set-action/frr-bgp-route-map:aigp-metric", xpath
);
6521 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, aigp_metric
);
6523 return nb_cli_apply_changes(vty
, NULL
);
6526 DEFPY_YANG (no_set_aigp_metric
,
6527 no_set_aigp_metric_cmd
,
6528 "no set aigp-metric [<igp-metric|(1-4294967295)>]",
6531 "BGP AIGP attribute (AIGP Metric TLV)\n"
6532 "AIGP Metric value from IGP protocol\n"
6533 "Manual AIGP Metric value\n")
6536 "./set-action[action='frr-bgp-route-map:aigp-metric']";
6538 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6539 return nb_cli_apply_changes(vty
, NULL
);
6542 DEFUN_YANG (set_aggregator_as
,
6543 set_aggregator_as_cmd
,
6544 "set aggregator as ASNUM A.B.C.D",
6546 "BGP aggregator attribute\n"
6547 "AS number of aggregator\n"
6549 "IP address of aggregator\n")
6553 char xpath_asn
[XPATH_MAXLEN
];
6554 char xpath_addr
[XPATH_MAXLEN
];
6556 "./set-action[action='frr-bgp-route-map:aggregator']";
6559 if (!asn_str2asn(argv
[idx_number
]->arg
, &as_value
)) {
6560 vty_out(vty
, "%% Invalid AS value %s\n", argv
[idx_number
]->arg
);
6561 return CMD_WARNING_CONFIG_FAILED
;
6564 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6567 xpath_asn
, sizeof(xpath_asn
),
6568 "%s/rmap-set-action/frr-bgp-route-map:aggregator/aggregator-asn",
6570 nb_cli_enqueue_change(vty
, xpath_asn
, NB_OP_MODIFY
,
6571 argv
[idx_number
]->arg
);
6574 xpath_addr
, sizeof(xpath_addr
),
6575 "%s/rmap-set-action/frr-bgp-route-map:aggregator/aggregator-address",
6577 nb_cli_enqueue_change(vty
, xpath_addr
, NB_OP_MODIFY
,
6578 argv
[idx_ipv4
]->arg
);
6580 return nb_cli_apply_changes(vty
, NULL
);
6583 DEFUN_YANG (no_set_aggregator_as
,
6584 no_set_aggregator_as_cmd
,
6585 "no set aggregator as [ASNUM A.B.C.D]",
6588 "BGP aggregator attribute\n"
6589 "AS number of aggregator\n"
6591 "IP address of aggregator\n")
6594 "./set-action[action='frr-bgp-route-map:aggregator']";
6596 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6597 return nb_cli_apply_changes(vty
, NULL
);
6600 DEFUN_YANG (match_ipv6_next_hop
,
6601 match_ipv6_next_hop_cmd
,
6602 "match ipv6 next-hop ACCESSLIST6_NAME",
6605 "Match IPv6 next-hop address of route\n"
6606 "IPv6 access-list name\n")
6609 "./match-condition[condition='frr-route-map:ipv6-next-hop-list']";
6610 char xpath_value
[XPATH_MAXLEN
];
6612 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6613 snprintf(xpath_value
, sizeof(xpath_value
),
6614 "%s/rmap-match-condition/list-name", xpath
);
6615 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6616 argv
[argc
- 1]->arg
);
6618 return nb_cli_apply_changes(vty
, NULL
);
6621 DEFUN_YANG (no_match_ipv6_next_hop
,
6622 no_match_ipv6_next_hop_cmd
,
6623 "no match ipv6 next-hop [ACCESSLIST6_NAME]",
6627 "Match IPv6 next-hop address of route\n"
6628 "IPv6 access-list name\n")
6631 "./match-condition[condition='frr-route-map:ipv6-next-hop-list']";
6633 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6634 return nb_cli_apply_changes(vty
, NULL
);
6637 DEFUN_YANG (match_ipv6_next_hop_address
,
6638 match_ipv6_next_hop_address_cmd
,
6639 "match ipv6 next-hop address X:X::X:X",
6642 "Match IPv6 next-hop address of route\n"
6644 "IPv6 address of next hop\n")
6647 "./match-condition[condition='frr-bgp-route-map:ipv6-nexthop']";
6648 char xpath_value
[XPATH_MAXLEN
];
6650 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6651 snprintf(xpath_value
, sizeof(xpath_value
),
6652 "%s/rmap-match-condition/frr-bgp-route-map:ipv6-address",
6654 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6655 argv
[argc
- 1]->arg
);
6657 return nb_cli_apply_changes(vty
, NULL
);
6660 DEFUN_YANG (no_match_ipv6_next_hop_address
,
6661 no_match_ipv6_next_hop_address_cmd
,
6662 "no match ipv6 next-hop address X:X::X:X",
6666 "Match IPv6 next-hop address of route\n"
6668 "IPv6 address of next hop\n")
6671 "./match-condition[condition='frr-bgp-route-map:ipv6-nexthop']";
6673 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6674 return nb_cli_apply_changes(vty
, NULL
);
6677 ALIAS_HIDDEN (match_ipv6_next_hop_address
,
6678 match_ipv6_next_hop_old_cmd
,
6679 "match ipv6 next-hop X:X::X:X",
6682 "Match IPv6 next-hop address of route\n"
6683 "IPv6 address of next hop\n")
6685 ALIAS_HIDDEN (no_match_ipv6_next_hop_address
,
6686 no_match_ipv6_next_hop_old_cmd
,
6687 "no match ipv6 next-hop X:X::X:X",
6691 "Match IPv6 next-hop address of route\n"
6692 "IPv6 address of next hop\n")
6694 DEFUN_YANG (match_ipv6_next_hop_prefix_list
,
6695 match_ipv6_next_hop_prefix_list_cmd
,
6696 "match ipv6 next-hop prefix-list PREFIXLIST_NAME",
6699 "Match IPv6 next-hop address of route\n"
6700 "Match entries by prefix-list\n"
6701 "IPv6 prefix-list name\n")
6704 "./match-condition[condition='frr-route-map:ipv6-next-hop-prefix-list']";
6705 char xpath_value
[XPATH_MAXLEN
];
6707 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6708 snprintf(xpath_value
, sizeof(xpath_value
),
6709 "%s/rmap-match-condition/list-name", xpath
);
6710 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6711 argv
[argc
- 1]->arg
);
6713 return nb_cli_apply_changes(vty
, NULL
);
6716 DEFUN_YANG (no_match_ipv6_next_hop_prefix_list
,
6717 no_match_ipv6_next_hop_prefix_list_cmd
,
6718 "no match ipv6 next-hop prefix-list [PREFIXLIST_NAME]",
6722 "Match IPv6 next-hop address of route\n"
6723 "Match entries by prefix-list\n"
6724 "IPv6 prefix-list name\n")
6727 "./match-condition[condition='frr-route-map:ipv6-next-hop-prefix-list']";
6729 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6730 return nb_cli_apply_changes(vty
, NULL
);
6733 DEFPY_YANG (match_ipv4_next_hop
,
6734 match_ipv4_next_hop_cmd
,
6735 "match ip next-hop address A.B.C.D",
6738 "Match IP next-hop address of route\n"
6740 "IP address of next-hop\n")
6743 "./match-condition[condition='frr-bgp-route-map:ipv4-nexthop']";
6744 char xpath_value
[XPATH_MAXLEN
];
6746 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6747 snprintf(xpath_value
, sizeof(xpath_value
),
6748 "%s/rmap-match-condition/frr-bgp-route-map:ipv4-address",
6750 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[4]->arg
);
6752 return nb_cli_apply_changes(vty
, NULL
);
6755 DEFPY_YANG (no_match_ipv4_next_hop
,
6756 no_match_ipv4_next_hop_cmd
,
6757 "no match ip next-hop address [A.B.C.D]",
6761 "Match IP next-hop address of route\n"
6763 "IP address of next-hop\n")
6766 "./match-condition[condition='frr-bgp-route-map:ipv4-nexthop']";
6768 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6769 return nb_cli_apply_changes(vty
, NULL
);
6772 DEFUN_YANG (set_ipv6_nexthop_peer
,
6773 set_ipv6_nexthop_peer_cmd
,
6774 "set ipv6 next-hop peer-address",
6777 "Next hop address\n"
6778 "Use peer address (for BGP only)\n")
6781 "./set-action[action='frr-bgp-route-map:ipv6-peer-address']";
6782 char xpath_value
[XPATH_MAXLEN
];
6784 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6785 snprintf(xpath_value
, sizeof(xpath_value
),
6786 "%s/rmap-set-action/frr-bgp-route-map:preference", xpath
);
6787 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
6789 return nb_cli_apply_changes(vty
, NULL
);
6792 DEFUN_YANG (no_set_ipv6_nexthop_peer
,
6793 no_set_ipv6_nexthop_peer_cmd
,
6794 "no set ipv6 next-hop peer-address",
6798 "IPv6 next-hop address\n"
6799 "Use peer address (for BGP only)\n")
6802 "./set-action[action='frr-bgp-route-map:ipv6-peer-address']";
6804 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6805 return nb_cli_apply_changes(vty
, NULL
);
6808 DEFUN_YANG (set_ipv6_nexthop_prefer_global
,
6809 set_ipv6_nexthop_prefer_global_cmd
,
6810 "set ipv6 next-hop prefer-global",
6813 "IPv6 next-hop address\n"
6814 "Prefer global over link-local if both exist\n")
6817 "./set-action[action='frr-bgp-route-map:ipv6-prefer-global']";
6818 char xpath_value
[XPATH_MAXLEN
];
6820 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6821 snprintf(xpath_value
, sizeof(xpath_value
),
6822 "%s/rmap-set-action/frr-bgp-route-map:preference", xpath
);
6823 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
6825 return nb_cli_apply_changes(vty
, NULL
);
6828 DEFUN_YANG (no_set_ipv6_nexthop_prefer_global
,
6829 no_set_ipv6_nexthop_prefer_global_cmd
,
6830 "no set ipv6 next-hop prefer-global",
6834 "IPv6 next-hop address\n"
6835 "Prefer global over link-local if both exist\n")
6838 "./set-action[action='frr-bgp-route-map:ipv6-prefer-global']";
6840 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6841 return nb_cli_apply_changes(vty
, NULL
);
6844 DEFUN_YANG (set_ipv6_nexthop_global
,
6845 set_ipv6_nexthop_global_cmd
,
6846 "set ipv6 next-hop global X:X::X:X",
6849 "IPv6 next-hop address\n"
6850 "IPv6 global address\n"
6851 "IPv6 address of next hop\n")
6855 "./set-action[action='frr-bgp-route-map:ipv6-nexthop-global']";
6856 char xpath_value
[XPATH_MAXLEN
];
6858 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6859 snprintf(xpath_value
, sizeof(xpath_value
),
6860 "%s/rmap-set-action/frr-bgp-route-map:ipv6-address", xpath
);
6861 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6862 argv
[idx_ipv6
]->arg
);
6864 return nb_cli_apply_changes(vty
, NULL
);
6867 DEFUN_YANG (no_set_ipv6_nexthop_global
,
6868 no_set_ipv6_nexthop_global_cmd
,
6869 "no set ipv6 next-hop global X:X::X:X",
6873 "IPv6 next-hop address\n"
6874 "IPv6 global address\n"
6875 "IPv6 address of next hop\n")
6878 "./set-action[action='frr-bgp-route-map:ipv6-nexthop-global']";
6880 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6881 return nb_cli_apply_changes(vty
, NULL
);
6884 #ifdef KEEP_OLD_VPN_COMMANDS
6885 DEFUN_YANG (set_vpn_nexthop
,
6886 set_vpn_nexthop_cmd
,
6887 "set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
6889 "VPNv4 information\n"
6890 "VPN next-hop address\n"
6891 "IP address of next hop\n"
6892 "VPNv6 information\n"
6893 "VPN next-hop address\n"
6894 "IPv6 address of next hop\n")
6899 char xpath_value
[XPATH_MAXLEN
];
6901 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
6902 if (afi
== AFI_IP
) {
6904 "./set-action[action='frr-bgp-route-map:ipv4-vpn-address']";
6906 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6908 xpath_value
, sizeof(xpath_value
),
6909 "%s/rmap-set-action/frr-bgp-route-map:ipv4-address",
6913 "./set-action[action='frr-bgp-route-map:ipv6-vpn-address']";
6915 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6917 xpath_value
, sizeof(xpath_value
),
6918 "%s/rmap-set-action/frr-bgp-route-map:ipv6-address",
6922 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6925 return nb_cli_apply_changes(vty
, NULL
);
6931 DEFUN_YANG (no_set_vpn_nexthop
,
6932 no_set_vpn_nexthop_cmd
,
6933 "no set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
6936 "VPNv4 information\n"
6937 "VPN next-hop address\n"
6938 "IP address of next hop\n"
6939 "VPNv6 information\n"
6940 "VPN next-hop address\n"
6941 "IPv6 address of next hop\n")
6946 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
6947 if (afi
== AFI_IP
) {
6949 "./set-action[action='frr-bgp-route-map:ipv4-vpn-address']";
6950 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6953 "./set-action[action='frr-bgp-route-map:ipv6-vpn-address']";
6954 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6956 return nb_cli_apply_changes(vty
, NULL
);
6960 #endif /* KEEP_OLD_VPN_COMMANDS */
6962 DEFPY_YANG (set_ipx_vpn_nexthop
,
6963 set_ipx_vpn_nexthop_cmd
,
6964 "set <ipv4|ipv6> vpn next-hop <A.B.C.D$addrv4|X:X::X:X$addrv6>",
6966 "IPv4 information\n"
6967 "IPv6 information\n"
6969 "VPN next-hop address\n"
6970 "IP address of next hop\n"
6971 "IPv6 address of next hop\n")
6976 char xpath_value
[XPATH_MAXLEN
];
6978 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
6979 if (afi
== AFI_IP
) {
6981 vty_out(vty
, "%% IPv4 next-hop expected\n");
6982 return CMD_WARNING_CONFIG_FAILED
;
6986 "./set-action[action='frr-bgp-route-map:ipv4-vpn-address']";
6988 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6990 xpath_value
, sizeof(xpath_value
),
6991 "%s/rmap-set-action/frr-bgp-route-map:ipv4-address",
6995 vty_out(vty
, "%% IPv6 next-hop expected\n");
6996 return CMD_WARNING_CONFIG_FAILED
;
7000 "./set-action[action='frr-bgp-route-map:ipv6-vpn-address']";
7002 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
7004 xpath_value
, sizeof(xpath_value
),
7005 "%s/rmap-set-action/frr-bgp-route-map:ipv6-address",
7008 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
7010 return nb_cli_apply_changes(vty
, NULL
);
7015 DEFUN_YANG (no_set_ipx_vpn_nexthop
,
7016 no_set_ipx_vpn_nexthop_cmd
,
7017 "no set <ipv4|ipv6> vpn next-hop [<A.B.C.D|X:X::X:X>]",
7020 "IPv4 information\n"
7021 "IPv6 information\n"
7023 "VPN next-hop address\n"
7024 "IP address of next hop\n"
7025 "IPv6 address of next hop\n")
7030 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
7031 if (afi
== AFI_IP
) {
7033 "./set-action[action='frr-bgp-route-map:ipv4-vpn-address']";
7034 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
7037 "./set-action[action='frr-bgp-route-map:ipv6-vpn-address']";
7038 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
7040 return nb_cli_apply_changes(vty
, NULL
);
7045 DEFUN_YANG (set_originator_id
,
7046 set_originator_id_cmd
,
7047 "set originator-id A.B.C.D",
7049 "BGP originator ID attribute\n"
7050 "IP address of originator\n")
7054 "./set-action[action='frr-bgp-route-map:originator-id']";
7055 char xpath_value
[XPATH_MAXLEN
];
7057 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
7058 snprintf(xpath_value
, sizeof(xpath_value
),
7059 "%s/rmap-set-action/frr-bgp-route-map:originator-id", xpath
);
7060 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
7061 argv
[idx_ipv4
]->arg
);
7063 return nb_cli_apply_changes(vty
, NULL
);
7066 DEFUN_YANG (no_set_originator_id
,
7067 no_set_originator_id_cmd
,
7068 "no set originator-id [A.B.C.D]",
7071 "BGP originator ID attribute\n"
7072 "IP address of originator\n")
7075 "./set-action[action='frr-bgp-route-map:originator-id']";
7077 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
7078 return nb_cli_apply_changes(vty
, NULL
);
7081 DEFPY_YANG (match_rpki_extcommunity
,
7082 match_rpki_extcommunity_cmd
,
7083 "[no$no] match rpki-extcommunity <valid|invalid|notfound>",
7086 "BGP RPKI (Origin Validation State) extended community attribute\n"
7089 "Prefix not found\n")
7092 "./match-condition[condition='frr-bgp-route-map:rpki-extcommunity']";
7093 char xpath_value
[XPATH_MAXLEN
];
7095 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
7099 xpath_value
, sizeof(xpath_value
),
7100 "%s/rmap-match-condition/frr-bgp-route-map:rpki-extcommunity",
7102 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
7106 return nb_cli_apply_changes(vty
, NULL
);
7109 /* Initialization of route map. */
7110 void bgp_route_map_init(void)
7114 route_map_add_hook(bgp_route_map_add
);
7115 route_map_delete_hook(bgp_route_map_delete
);
7116 route_map_event_hook(bgp_route_map_event
);
7118 route_map_match_interface_hook(generic_match_add
);
7119 route_map_no_match_interface_hook(generic_match_delete
);
7121 route_map_match_ip_address_hook(generic_match_add
);
7122 route_map_no_match_ip_address_hook(generic_match_delete
);
7124 route_map_match_ip_address_prefix_list_hook(generic_match_add
);
7125 route_map_no_match_ip_address_prefix_list_hook(generic_match_delete
);
7127 route_map_match_ip_next_hop_hook(generic_match_add
);
7128 route_map_no_match_ip_next_hop_hook(generic_match_delete
);
7130 route_map_match_ipv6_next_hop_hook(generic_match_add
);
7131 route_map_no_match_ipv6_next_hop_hook(generic_match_delete
);
7133 route_map_match_ip_next_hop_prefix_list_hook(generic_match_add
);
7134 route_map_no_match_ip_next_hop_prefix_list_hook(generic_match_delete
);
7136 route_map_match_ip_next_hop_type_hook(generic_match_add
);
7137 route_map_no_match_ip_next_hop_type_hook(generic_match_delete
);
7139 route_map_match_ipv6_address_hook(generic_match_add
);
7140 route_map_no_match_ipv6_address_hook(generic_match_delete
);
7142 route_map_match_ipv6_address_prefix_list_hook(generic_match_add
);
7143 route_map_no_match_ipv6_address_prefix_list_hook(generic_match_delete
);
7145 route_map_match_ipv6_next_hop_type_hook(generic_match_add
);
7146 route_map_no_match_ipv6_next_hop_type_hook(generic_match_delete
);
7148 route_map_match_ipv6_next_hop_prefix_list_hook(generic_match_add
);
7149 route_map_no_match_ipv6_next_hop_prefix_list_hook(generic_match_delete
);
7151 route_map_match_metric_hook(generic_match_add
);
7152 route_map_no_match_metric_hook(generic_match_delete
);
7154 route_map_match_tag_hook(generic_match_add
);
7155 route_map_no_match_tag_hook(generic_match_delete
);
7157 route_map_set_srte_color_hook(generic_set_add
);
7158 route_map_no_set_srte_color_hook(generic_set_delete
);
7160 route_map_set_ip_nexthop_hook(generic_set_add
);
7161 route_map_no_set_ip_nexthop_hook(generic_set_delete
);
7163 route_map_set_ipv6_nexthop_local_hook(generic_set_add
);
7164 route_map_no_set_ipv6_nexthop_local_hook(generic_set_delete
);
7166 route_map_set_metric_hook(generic_set_add
);
7167 route_map_no_set_metric_hook(generic_set_delete
);
7169 route_map_set_tag_hook(generic_set_add
);
7170 route_map_no_set_tag_hook(generic_set_delete
);
7172 route_map_install_match(&route_match_peer_cmd
);
7173 route_map_install_match(&route_match_alias_cmd
);
7174 route_map_install_match(&route_match_local_pref_cmd
);
7175 #ifdef HAVE_SCRIPTING
7176 route_map_install_match(&route_match_script_cmd
);
7178 route_map_install_match(&route_match_ip_address_cmd
);
7179 route_map_install_match(&route_match_ip_next_hop_cmd
);
7180 route_map_install_match(&route_match_ip_route_source_cmd
);
7181 route_map_install_match(&route_match_ip_address_prefix_list_cmd
);
7182 route_map_install_match(&route_match_ip_next_hop_prefix_list_cmd
);
7183 route_map_install_match(&route_match_ip_next_hop_type_cmd
);
7184 route_map_install_match(&route_match_ip_route_source_prefix_list_cmd
);
7185 route_map_install_match(&route_match_aspath_cmd
);
7186 route_map_install_match(&route_match_community_cmd
);
7187 route_map_install_match(&route_match_lcommunity_cmd
);
7188 route_map_install_match(&route_match_ecommunity_cmd
);
7189 route_map_install_match(&route_match_local_pref_cmd
);
7190 route_map_install_match(&route_match_metric_cmd
);
7191 route_map_install_match(&route_match_origin_cmd
);
7192 route_map_install_match(&route_match_probability_cmd
);
7193 route_map_install_match(&route_match_interface_cmd
);
7194 route_map_install_match(&route_match_tag_cmd
);
7195 route_map_install_match(&route_match_mac_address_cmd
);
7196 route_map_install_match(&route_match_evpn_vni_cmd
);
7197 route_map_install_match(&route_match_evpn_route_type_cmd
);
7198 route_map_install_match(&route_match_evpn_rd_cmd
);
7199 route_map_install_match(&route_match_evpn_default_route_cmd
);
7200 route_map_install_match(&route_match_vrl_source_vrf_cmd
);
7202 route_map_install_set(&route_set_evpn_gateway_ip_ipv4_cmd
);
7203 route_map_install_set(&route_set_evpn_gateway_ip_ipv6_cmd
);
7204 route_map_install_set(&route_set_table_id_cmd
);
7205 route_map_install_set(&route_set_srte_color_cmd
);
7206 route_map_install_set(&route_set_ip_nexthop_cmd
);
7207 route_map_install_set(&route_set_local_pref_cmd
);
7208 route_map_install_set(&route_set_weight_cmd
);
7209 route_map_install_set(&route_set_label_index_cmd
);
7210 route_map_install_set(&route_set_metric_cmd
);
7211 route_map_install_set(&route_set_distance_cmd
);
7212 route_map_install_set(&route_set_aspath_prepend_cmd
);
7213 route_map_install_set(&route_set_aspath_exclude_cmd
);
7214 route_map_install_set(&route_set_aspath_replace_cmd
);
7215 route_map_install_set(&route_set_origin_cmd
);
7216 route_map_install_set(&route_set_atomic_aggregate_cmd
);
7217 route_map_install_set(&route_set_aigp_metric_cmd
);
7218 route_map_install_set(&route_set_aggregator_as_cmd
);
7219 route_map_install_set(&route_set_community_cmd
);
7220 route_map_install_set(&route_set_community_delete_cmd
);
7221 route_map_install_set(&route_set_lcommunity_cmd
);
7222 route_map_install_set(&route_set_lcommunity_delete_cmd
);
7223 route_map_install_set(&route_set_vpnv4_nexthop_cmd
);
7224 route_map_install_set(&route_set_vpnv6_nexthop_cmd
);
7225 route_map_install_set(&route_set_originator_id_cmd
);
7226 route_map_install_set(&route_set_ecommunity_rt_cmd
);
7227 route_map_install_set(&route_set_ecommunity_soo_cmd
);
7228 route_map_install_set(&route_set_ecommunity_lb_cmd
);
7229 route_map_install_set(&route_set_ecommunity_none_cmd
);
7230 route_map_install_set(&route_set_tag_cmd
);
7231 route_map_install_set(&route_set_label_index_cmd
);
7232 route_map_install_set(&route_set_l3vpn_nexthop_encapsulation_cmd
);
7234 install_element(RMAP_NODE
, &match_peer_cmd
);
7235 install_element(RMAP_NODE
, &match_peer_local_cmd
);
7236 install_element(RMAP_NODE
, &no_match_peer_cmd
);
7237 install_element(RMAP_NODE
, &match_ip_route_source_cmd
);
7238 install_element(RMAP_NODE
, &no_match_ip_route_source_cmd
);
7239 install_element(RMAP_NODE
, &match_ip_route_source_prefix_list_cmd
);
7240 install_element(RMAP_NODE
, &no_match_ip_route_source_prefix_list_cmd
);
7241 install_element(RMAP_NODE
, &match_mac_address_cmd
);
7242 install_element(RMAP_NODE
, &no_match_mac_address_cmd
);
7243 install_element(RMAP_NODE
, &match_evpn_vni_cmd
);
7244 install_element(RMAP_NODE
, &no_match_evpn_vni_cmd
);
7245 install_element(RMAP_NODE
, &match_evpn_route_type_cmd
);
7246 install_element(RMAP_NODE
, &no_match_evpn_route_type_cmd
);
7247 install_element(RMAP_NODE
, &match_evpn_rd_cmd
);
7248 install_element(RMAP_NODE
, &no_match_evpn_rd_cmd
);
7249 install_element(RMAP_NODE
, &match_evpn_default_route_cmd
);
7250 install_element(RMAP_NODE
, &no_match_evpn_default_route_cmd
);
7251 install_element(RMAP_NODE
, &set_evpn_gw_ip_ipv4_cmd
);
7252 install_element(RMAP_NODE
, &no_set_evpn_gw_ip_ipv4_cmd
);
7253 install_element(RMAP_NODE
, &set_evpn_gw_ip_ipv6_cmd
);
7254 install_element(RMAP_NODE
, &no_set_evpn_gw_ip_ipv6_cmd
);
7255 install_element(RMAP_NODE
, &match_vrl_source_vrf_cmd
);
7256 install_element(RMAP_NODE
, &no_match_vrl_source_vrf_cmd
);
7258 install_element(RMAP_NODE
, &match_aspath_cmd
);
7259 install_element(RMAP_NODE
, &no_match_aspath_cmd
);
7260 install_element(RMAP_NODE
, &match_local_pref_cmd
);
7261 install_element(RMAP_NODE
, &no_match_local_pref_cmd
);
7262 install_element(RMAP_NODE
, &match_alias_cmd
);
7263 install_element(RMAP_NODE
, &no_match_alias_cmd
);
7264 install_element(RMAP_NODE
, &match_community_cmd
);
7265 install_element(RMAP_NODE
, &no_match_community_cmd
);
7266 install_element(RMAP_NODE
, &match_lcommunity_cmd
);
7267 install_element(RMAP_NODE
, &no_match_lcommunity_cmd
);
7268 install_element(RMAP_NODE
, &match_ecommunity_cmd
);
7269 install_element(RMAP_NODE
, &no_match_ecommunity_cmd
);
7270 install_element(RMAP_NODE
, &match_origin_cmd
);
7271 install_element(RMAP_NODE
, &no_match_origin_cmd
);
7272 install_element(RMAP_NODE
, &match_probability_cmd
);
7273 install_element(RMAP_NODE
, &no_match_probability_cmd
);
7275 install_element(RMAP_NODE
, &no_set_table_id_cmd
);
7276 install_element(RMAP_NODE
, &set_table_id_cmd
);
7277 install_element(RMAP_NODE
, &set_ip_nexthop_peer_cmd
);
7278 install_element(RMAP_NODE
, &set_ip_nexthop_unchanged_cmd
);
7279 install_element(RMAP_NODE
, &set_local_pref_cmd
);
7280 install_element(RMAP_NODE
, &set_distance_cmd
);
7281 install_element(RMAP_NODE
, &no_set_distance_cmd
);
7282 install_element(RMAP_NODE
, &no_set_local_pref_cmd
);
7283 install_element(RMAP_NODE
, &set_weight_cmd
);
7284 install_element(RMAP_NODE
, &set_label_index_cmd
);
7285 install_element(RMAP_NODE
, &no_set_weight_cmd
);
7286 install_element(RMAP_NODE
, &no_set_label_index_cmd
);
7287 install_element(RMAP_NODE
, &set_aspath_prepend_asn_cmd
);
7288 install_element(RMAP_NODE
, &set_aspath_prepend_lastas_cmd
);
7289 install_element(RMAP_NODE
, &set_aspath_exclude_cmd
);
7290 install_element(RMAP_NODE
, &set_aspath_replace_asn_cmd
);
7291 install_element(RMAP_NODE
, &no_set_aspath_prepend_cmd
);
7292 install_element(RMAP_NODE
, &no_set_aspath_prepend_lastas_cmd
);
7293 install_element(RMAP_NODE
, &no_set_aspath_exclude_cmd
);
7294 install_element(RMAP_NODE
, &no_set_aspath_exclude_all_cmd
);
7295 install_element(RMAP_NODE
, &no_set_aspath_replace_asn_cmd
);
7296 install_element(RMAP_NODE
, &set_origin_cmd
);
7297 install_element(RMAP_NODE
, &no_set_origin_cmd
);
7298 install_element(RMAP_NODE
, &set_atomic_aggregate_cmd
);
7299 install_element(RMAP_NODE
, &no_set_atomic_aggregate_cmd
);
7300 install_element(RMAP_NODE
, &set_aigp_metric_cmd
);
7301 install_element(RMAP_NODE
, &no_set_aigp_metric_cmd
);
7302 install_element(RMAP_NODE
, &set_aggregator_as_cmd
);
7303 install_element(RMAP_NODE
, &no_set_aggregator_as_cmd
);
7304 install_element(RMAP_NODE
, &set_community_cmd
);
7305 install_element(RMAP_NODE
, &set_community_none_cmd
);
7306 install_element(RMAP_NODE
, &no_set_community_cmd
);
7307 install_element(RMAP_NODE
, &no_set_community_short_cmd
);
7308 install_element(RMAP_NODE
, &set_community_delete_cmd
);
7309 install_element(RMAP_NODE
, &no_set_community_delete_cmd
);
7310 install_element(RMAP_NODE
, &set_lcommunity_cmd
);
7311 install_element(RMAP_NODE
, &set_lcommunity_none_cmd
);
7312 install_element(RMAP_NODE
, &no_set_lcommunity_cmd
);
7313 install_element(RMAP_NODE
, &no_set_lcommunity1_cmd
);
7314 install_element(RMAP_NODE
, &no_set_lcommunity1_short_cmd
);
7315 install_element(RMAP_NODE
, &set_lcommunity_delete_cmd
);
7316 install_element(RMAP_NODE
, &no_set_lcommunity_delete_cmd
);
7317 install_element(RMAP_NODE
, &no_set_lcommunity_delete_short_cmd
);
7318 install_element(RMAP_NODE
, &set_ecommunity_rt_cmd
);
7319 install_element(RMAP_NODE
, &no_set_ecommunity_rt_cmd
);
7320 install_element(RMAP_NODE
, &no_set_ecommunity_rt_short_cmd
);
7321 install_element(RMAP_NODE
, &set_ecommunity_soo_cmd
);
7322 install_element(RMAP_NODE
, &no_set_ecommunity_soo_cmd
);
7323 install_element(RMAP_NODE
, &no_set_ecommunity_soo_short_cmd
);
7324 install_element(RMAP_NODE
, &set_ecommunity_lb_cmd
);
7325 install_element(RMAP_NODE
, &no_set_ecommunity_lb_cmd
);
7326 install_element(RMAP_NODE
, &no_set_ecommunity_lb_short_cmd
);
7327 install_element(RMAP_NODE
, &set_ecommunity_none_cmd
);
7328 install_element(RMAP_NODE
, &no_set_ecommunity_none_cmd
);
7329 #ifdef KEEP_OLD_VPN_COMMANDS
7330 install_element(RMAP_NODE
, &set_vpn_nexthop_cmd
);
7331 install_element(RMAP_NODE
, &no_set_vpn_nexthop_cmd
);
7332 #endif /* KEEP_OLD_VPN_COMMANDS */
7333 install_element(RMAP_NODE
, &set_ipx_vpn_nexthop_cmd
);
7334 install_element(RMAP_NODE
, &no_set_ipx_vpn_nexthop_cmd
);
7335 install_element(RMAP_NODE
, &set_originator_id_cmd
);
7336 install_element(RMAP_NODE
, &no_set_originator_id_cmd
);
7337 install_element(RMAP_NODE
, &set_l3vpn_nexthop_encapsulation_cmd
);
7339 route_map_install_match(&route_match_ipv6_address_cmd
);
7340 route_map_install_match(&route_match_ipv6_next_hop_cmd
);
7341 route_map_install_match(&route_match_ipv6_next_hop_address_cmd
);
7342 route_map_install_match(&route_match_ipv6_next_hop_prefix_list_cmd
);
7343 route_map_install_match(&route_match_ipv4_next_hop_cmd
);
7344 route_map_install_match(&route_match_ipv6_address_prefix_list_cmd
);
7345 route_map_install_match(&route_match_ipv6_next_hop_type_cmd
);
7346 route_map_install_set(&route_set_ipv6_nexthop_global_cmd
);
7347 route_map_install_set(&route_set_ipv6_nexthop_prefer_global_cmd
);
7348 route_map_install_set(&route_set_ipv6_nexthop_local_cmd
);
7349 route_map_install_set(&route_set_ipv6_nexthop_peer_cmd
);
7350 route_map_install_match(&route_match_rpki_extcommunity_cmd
);
7352 install_element(RMAP_NODE
, &match_ipv6_next_hop_cmd
);
7353 install_element(RMAP_NODE
, &match_ipv6_next_hop_address_cmd
);
7354 install_element(RMAP_NODE
, &match_ipv6_next_hop_prefix_list_cmd
);
7355 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_cmd
);
7356 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_address_cmd
);
7357 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_prefix_list_cmd
);
7358 install_element(RMAP_NODE
, &match_ipv6_next_hop_old_cmd
);
7359 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_old_cmd
);
7360 install_element(RMAP_NODE
, &match_ipv4_next_hop_cmd
);
7361 install_element(RMAP_NODE
, &no_match_ipv4_next_hop_cmd
);
7362 install_element(RMAP_NODE
, &set_ipv6_nexthop_global_cmd
);
7363 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_global_cmd
);
7364 install_element(RMAP_NODE
, &set_ipv6_nexthop_prefer_global_cmd
);
7365 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_prefer_global_cmd
);
7366 install_element(RMAP_NODE
, &set_ipv6_nexthop_peer_cmd
);
7367 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_peer_cmd
);
7368 install_element(RMAP_NODE
, &match_rpki_extcommunity_cmd
);
7369 #ifdef HAVE_SCRIPTING
7370 install_element(RMAP_NODE
, &match_script_cmd
);
7374 void bgp_route_map_terminate(void)
7376 /* ToDo: Cleanup all the used memory */