1 /* Route map function of bgpd.
2 * Copyright (C) 1998, 1999 Kunihiro Ishiguro
4 * This file is part of GNU Zebra.
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32 #include "frrscript.h"
33 #ifdef HAVE_LIBPCRE2_POSIX
34 #ifndef _FRR_PCRE2_POSIX
35 #define _FRR_PCRE2_POSIX
36 #include <pcre2posix.h>
37 #endif /* _FRR_PCRE2_POSIX */
38 #elif defined(HAVE_LIBPCREPOSIX)
39 #include <pcreposix.h>
42 #endif /* HAVE_LIBPCRE2_POSIX */
44 #include "sockunion.h"
49 #include "lib/northbound_cli.h"
51 #include "bgpd/bgpd.h"
52 #include "bgpd/bgp_table.h"
53 #include "bgpd/bgp_attr.h"
54 #include "bgpd/bgp_aspath.h"
55 #include "bgpd/bgp_packet.h"
56 #include "bgpd/bgp_route.h"
57 #include "bgpd/bgp_zebra.h"
58 #include "bgpd/bgp_regex.h"
59 #include "bgpd/bgp_community.h"
60 #include "bgpd/bgp_community_alias.h"
61 #include "bgpd/bgp_clist.h"
62 #include "bgpd/bgp_filter.h"
63 #include "bgpd/bgp_mplsvpn.h"
64 #include "bgpd/bgp_ecommunity.h"
65 #include "bgpd/bgp_lcommunity.h"
66 #include "bgpd/bgp_vty.h"
67 #include "bgpd/bgp_debug.h"
68 #include "bgpd/bgp_evpn.h"
69 #include "bgpd/bgp_evpn_private.h"
70 #include "bgpd/bgp_evpn_vty.h"
71 #include "bgpd/bgp_mplsvpn.h"
72 #include "bgpd/bgp_pbr.h"
73 #include "bgpd/bgp_flowspec_util.h"
74 #include "bgpd/bgp_encap_types.h"
75 #include "bgpd/bgp_mpath.h"
76 #include "bgpd/bgp_script.h"
79 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
82 #include "bgpd/bgp_routemap_clippy.c"
84 /* Memo of route-map commands.
93 ip route-source : Done
97 ipv6 route-source: (This will not be implemented by bgpd)
98 ipv6 prefix-list : Done
99 length : (This will not be implemented by bgpd)
101 route-type : (This will not be implemented by bgpd)
103 local-preference : Done
105 set as-path prepend : Done
106 as-path tag : Not yet
107 automatic-tag : (This will not be implemented by bgpd)
109 large-community : Done
110 large-comm-list : Done
113 default : (This will not be implemented by bgpd)
114 interface : (This will not be implemented by bgpd)
115 ip default : (This will not be implemented by bgpd)
117 ip precedence : (This will not be implemented by bgpd)
118 ip tos : (This will not be implemented by bgpd)
119 level : (This will not be implemented by bgpd)
120 local-preference : Done
122 metric-type : Not yet
130 set ipv6 next-hop global: Done
131 set ipv6 next-hop prefer-global: Done
132 set ipv6 next-hop local : Done
133 set as-path exclude : Done
137 /* generic value manipulation to be shared in multiple rules */
139 #define RMAP_VALUE_SET 0
140 #define RMAP_VALUE_ADD 1
141 #define RMAP_VALUE_SUB 2
149 static int route_value_match(struct rmap_value
*rv
, uint32_t value
)
151 if (rv
->variable
== 0 && value
== rv
->value
)
157 static uint32_t route_value_adjust(struct rmap_value
*rv
, uint32_t current
,
162 switch (rv
->variable
) {
171 switch (rv
->action
) {
173 if (current
> UINT32_MAX
- value
)
175 return current
+ value
;
177 if (current
<= value
)
179 return current
- value
;
185 static void *route_value_compile(const char *arg
)
187 uint8_t action
= RMAP_VALUE_SET
, var
= 0;
188 unsigned long larg
= 0;
190 struct rmap_value
*rv
;
193 action
= RMAP_VALUE_ADD
;
195 } else if (arg
[0] == '-') {
196 action
= RMAP_VALUE_SUB
;
200 if (all_digit(arg
)) {
202 larg
= strtoul(arg
, &endptr
, 10);
203 if (*arg
== 0 || *endptr
!= 0 || errno
|| larg
> UINT32_MAX
)
206 if (strcmp(arg
, "rtt") == 0)
212 rv
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_value
));
220 static void route_value_free(void *rule
)
222 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
225 /* generic as path object to be shared in multiple rules */
227 static void *route_aspath_compile(const char *arg
)
229 struct aspath
*aspath
;
231 aspath
= aspath_str2aspath(arg
);
237 static void route_aspath_free(void *rule
)
239 struct aspath
*aspath
= rule
;
243 struct bgp_match_peer_compiled
{
248 /* 'match peer (A.B.C.D|X:X::X:X|WORD)' */
250 /* Compares the peer specified in the 'match peer' clause with the peer
251 received in bgp_path_info->peer. If it is the same, or if the peer structure
252 received is a peer_group containing it, returns RMAP_MATCH. */
253 static enum route_map_cmd_result_t
254 route_match_peer(void *rule
, const struct prefix
*prefix
, void *object
)
256 struct bgp_match_peer_compiled
*pc
;
258 union sockunion su_def
= {
259 .sin
= {.sin_family
= AF_INET
, .sin_addr
.s_addr
= INADDR_ANY
}};
260 struct peer_group
*group
;
262 struct listnode
*node
, *nnode
;
266 peer
= ((struct bgp_path_info
*)object
)->peer
;
269 if (!peer
->conf_if
|| !peer
->group
)
272 if (peer
->conf_if
&& strcmp(peer
->conf_if
, pc
->interface
) == 0)
276 strcmp(peer
->group
->name
, pc
->interface
) == 0)
282 /* If su='0.0.0.0' (command 'match peer local'), and it's a
284 REDISTRIBUTE, AGGREGATE-ADDRESS or DEFAULT_GENERATED route
287 if (sockunion_same(su
, &su_def
)) {
289 if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_NETWORK
)
290 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_REDISTRIBUTE
)
291 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_AGGREGATE
)
292 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_DEFAULT
))
299 if (!CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
)) {
300 if (sockunion_same(su
, &peer
->su
))
306 for (ALL_LIST_ELEMENTS(group
->peer
, node
, nnode
, peer
)) {
307 if (sockunion_same(su
, &peer
->su
))
316 static void *route_match_peer_compile(const char *arg
)
318 struct bgp_match_peer_compiled
*pc
;
321 pc
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
322 sizeof(struct bgp_match_peer_compiled
));
324 ret
= str2sockunion(strcmp(arg
, "local") ? arg
: "0.0.0.0", &pc
->su
);
326 pc
->interface
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
333 /* Free route map's compiled `ip address' value. */
334 static void route_match_peer_free(void *rule
)
336 struct bgp_match_peer_compiled
*pc
= rule
;
338 XFREE(MTYPE_ROUTE_MAP_COMPILED
, pc
->interface
);
340 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
343 /* Route map commands for ip address matching. */
344 static const struct route_map_rule_cmd route_match_peer_cmd
= {
347 route_match_peer_compile
,
348 route_match_peer_free
351 #ifdef HAVE_SCRIPTING
353 enum frrlua_rm_status
{
355 * Script function run failure. This will translate into a deny
359 * No Match was found for the route map function
363 * Match was found but no changes were made to the incoming data.
367 * Match was found and data was modified, so figure out what changed
369 LUA_RM_MATCH_AND_CHANGE
,
372 static enum route_map_cmd_result_t
373 route_match_script(void *rule
, const struct prefix
*prefix
, void *object
)
375 const char *scriptname
= rule
;
376 const char *routematch_function
= "route_match";
377 struct bgp_path_info
*path
= (struct bgp_path_info
*)object
;
379 struct frrscript
*fs
= frrscript_new(scriptname
);
381 if (frrscript_load(fs
, routematch_function
, NULL
)) {
383 "Issue loading script or function; defaulting to no match");
387 struct attr newattr
= *path
->attr
;
389 int result
= frrscript_call(
390 fs
, routematch_function
, ("prefix", prefix
),
391 ("attributes", &newattr
), ("peer", path
->peer
),
392 ("RM_FAILURE", LUA_RM_FAILURE
), ("RM_NOMATCH", LUA_RM_NOMATCH
),
393 ("RM_MATCH", LUA_RM_MATCH
),
394 ("RM_MATCH_AND_CHANGE", LUA_RM_MATCH_AND_CHANGE
));
397 zlog_err("Issue running script rule; defaulting to no match");
401 long long *action
= frrscript_get_result(fs
, routematch_function
,
402 "action", lua_tointegerp
);
404 int status
= RMAP_NOMATCH
;
409 "Executing route-map match script '%s' failed; defaulting to no match",
411 status
= RMAP_NOMATCH
;
414 status
= RMAP_NOMATCH
;
416 case LUA_RM_MATCH_AND_CHANGE
:
418 zlog_debug("Updating attribute based on script's values");
420 uint32_t locpref
= 0;
422 path
->attr
->med
= newattr
.med
;
424 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
))
425 locpref
= path
->attr
->local_pref
;
426 if (locpref
!= newattr
.local_pref
) {
427 SET_FLAG(path
->attr
->flag
,
428 ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
));
429 path
->attr
->local_pref
= newattr
.local_pref
;
437 XFREE(MTYPE_SCRIPT_RES
, action
);
439 frrscript_delete(fs
);
444 static void *route_match_script_compile(const char *arg
)
448 scriptname
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
453 static void route_match_script_free(void *rule
)
455 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
458 static const struct route_map_rule_cmd route_match_script_cmd
= {
461 route_match_script_compile
,
462 route_match_script_free
465 #endif /* HAVE_SCRIPTING */
467 /* `match ip address IP_ACCESS_LIST' */
469 /* Match function should return 1 if match is success else return
471 static enum route_map_cmd_result_t
472 route_match_ip_address(void *rule
, const struct prefix
*prefix
, void *object
)
474 struct access_list
*alist
;
476 if (prefix
->family
== AF_INET
) {
477 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
481 return (access_list_apply(alist
, prefix
) == FILTER_DENY
488 /* Route map `ip address' match statement. `arg' should be
490 static void *route_match_ip_address_compile(const char *arg
)
492 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
495 /* Free route map's compiled `ip address' value. */
496 static void route_match_ip_address_free(void *rule
)
498 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
501 /* Route map commands for ip address matching. */
502 static const struct route_map_rule_cmd route_match_ip_address_cmd
= {
504 route_match_ip_address
,
505 route_match_ip_address_compile
,
506 route_match_ip_address_free
509 /* `match ip next-hop IP_ADDRESS' */
511 /* Match function return 1 if match is success else return zero. */
512 static enum route_map_cmd_result_t
513 route_match_ip_next_hop(void *rule
, const struct prefix
*prefix
, void *object
)
515 struct access_list
*alist
;
516 struct bgp_path_info
*path
;
517 struct prefix_ipv4 p
;
519 if (prefix
->family
== AF_INET
) {
522 p
.prefix
= path
->attr
->nexthop
;
523 p
.prefixlen
= IPV4_MAX_BITLEN
;
525 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
529 return (access_list_apply(alist
, &p
) == FILTER_DENY
536 /* Route map `ip next-hop' match statement. `arg' is
538 static void *route_match_ip_next_hop_compile(const char *arg
)
540 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
543 /* Free route map's compiled `ip address' value. */
544 static void route_match_ip_next_hop_free(void *rule
)
546 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
549 /* Route map commands for ip next-hop matching. */
550 static const struct route_map_rule_cmd route_match_ip_next_hop_cmd
= {
552 route_match_ip_next_hop
,
553 route_match_ip_next_hop_compile
,
554 route_match_ip_next_hop_free
557 /* `match ip route-source ACCESS-LIST' */
559 /* Match function return 1 if match is success else return zero. */
560 static enum route_map_cmd_result_t
561 route_match_ip_route_source(void *rule
, const struct prefix
*pfx
, void *object
)
563 struct access_list
*alist
;
564 struct bgp_path_info
*path
;
566 struct prefix_ipv4 p
;
568 if (pfx
->family
== AF_INET
) {
572 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
576 p
.prefix
= peer
->su
.sin
.sin_addr
;
577 p
.prefixlen
= IPV4_MAX_BITLEN
;
579 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
583 return (access_list_apply(alist
, &p
) == FILTER_DENY
590 /* Route map `ip route-source' match statement. `arg' is
592 static void *route_match_ip_route_source_compile(const char *arg
)
594 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
597 /* Free route map's compiled `ip address' value. */
598 static void route_match_ip_route_source_free(void *rule
)
600 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
603 /* Route map commands for ip route-source matching. */
604 static const struct route_map_rule_cmd route_match_ip_route_source_cmd
= {
606 route_match_ip_route_source
,
607 route_match_ip_route_source_compile
,
608 route_match_ip_route_source_free
611 static enum route_map_cmd_result_t
612 route_match_prefix_list_flowspec(afi_t afi
, struct prefix_list
*plist
,
613 const struct prefix
*p
)
616 struct bgp_pbr_entry_main api
;
618 memset(&api
, 0, sizeof(api
));
620 if (family2afi(p
->u
.prefix_flowspec
.family
) != afi
)
623 /* extract match from flowspec entries */
624 ret
= bgp_flowspec_match_rules_fill(
625 (uint8_t *)p
->u
.prefix_flowspec
.ptr
,
626 p
->u
.prefix_flowspec
.prefixlen
, &api
,
630 if (api
.match_bitmask
& PREFIX_DST_PRESENT
||
631 api
.match_bitmask_iprule
& PREFIX_DST_PRESENT
) {
632 if (family2afi((&api
.dst_prefix
)->family
) != afi
)
634 return prefix_list_apply(plist
, &api
.dst_prefix
) == PREFIX_DENY
637 } else if (api
.match_bitmask
& PREFIX_SRC_PRESENT
||
638 api
.match_bitmask_iprule
& PREFIX_SRC_PRESENT
) {
639 if (family2afi((&api
.src_prefix
)->family
) != afi
)
641 return (prefix_list_apply(plist
, &api
.src_prefix
) == PREFIX_DENY
648 static enum route_map_cmd_result_t
649 route_match_prefix_list_evpn(afi_t afi
, struct prefix_list
*plist
,
650 const struct prefix
*p
)
652 /* Convert to match a general plist */
655 if (evpn_prefix2prefix(p
, &new))
658 return (prefix_list_apply(plist
, &new) == PREFIX_DENY
? RMAP_NOMATCH
662 static enum route_map_cmd_result_t
663 route_match_address_prefix_list(void *rule
, afi_t afi
,
664 const struct prefix
*prefix
, void *object
)
666 struct prefix_list
*plist
;
668 plist
= prefix_list_lookup(afi
, (char *)rule
);
672 if (prefix
->family
== AF_FLOWSPEC
)
673 return route_match_prefix_list_flowspec(afi
, plist
,
676 else if (prefix
->family
== AF_EVPN
)
677 return route_match_prefix_list_evpn(afi
, plist
, prefix
);
679 return (prefix_list_apply(plist
, prefix
) == PREFIX_DENY
? RMAP_NOMATCH
683 static enum route_map_cmd_result_t
684 route_match_ip_address_prefix_list(void *rule
, const struct prefix
*prefix
,
687 return route_match_address_prefix_list(rule
, AFI_IP
, prefix
, object
);
690 static void *route_match_ip_address_prefix_list_compile(const char *arg
)
692 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
695 static void route_match_ip_address_prefix_list_free(void *rule
)
697 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
700 static const struct route_map_rule_cmd
701 route_match_ip_address_prefix_list_cmd
= {
702 "ip address prefix-list",
703 route_match_ip_address_prefix_list
,
704 route_match_ip_address_prefix_list_compile
,
705 route_match_ip_address_prefix_list_free
708 /* `match ip next-hop prefix-list PREFIX_LIST' */
710 static enum route_map_cmd_result_t
711 route_match_ip_next_hop_prefix_list(void *rule
, const struct prefix
*prefix
,
714 struct prefix_list
*plist
;
715 struct bgp_path_info
*path
;
716 struct prefix_ipv4 p
;
718 if (prefix
->family
== AF_INET
) {
721 p
.prefix
= path
->attr
->nexthop
;
722 p
.prefixlen
= IPV4_MAX_BITLEN
;
724 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
728 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
735 static void *route_match_ip_next_hop_prefix_list_compile(const char *arg
)
737 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
740 static void route_match_ip_next_hop_prefix_list_free(void *rule
)
742 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
745 static const struct route_map_rule_cmd
746 route_match_ip_next_hop_prefix_list_cmd
= {
747 "ip next-hop prefix-list",
748 route_match_ip_next_hop_prefix_list
,
749 route_match_ip_next_hop_prefix_list_compile
,
750 route_match_ip_next_hop_prefix_list_free
753 /* `match ipv6 next-hop prefix-list PREFIXLIST_NAME' */
754 static enum route_map_cmd_result_t
755 route_match_ipv6_next_hop_prefix_list(void *rule
, const struct prefix
*prefix
,
758 struct prefix_list
*plist
;
759 struct bgp_path_info
*path
;
760 struct prefix_ipv6 p
;
762 if (prefix
->family
== AF_INET6
) {
765 p
.prefix
= path
->attr
->mp_nexthop_global
;
766 p
.prefixlen
= IPV6_MAX_BITLEN
;
768 plist
= prefix_list_lookup(AFI_IP6
, (char *)rule
);
772 if (prefix_list_apply(plist
, &p
) == PREFIX_PERMIT
)
775 if (path
->attr
->mp_nexthop_len
776 == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
) {
777 p
.prefix
= path
->attr
->mp_nexthop_local
;
778 if (prefix_list_apply(plist
, &p
) == PREFIX_PERMIT
)
786 static void *route_match_ipv6_next_hop_prefix_list_compile(const char *arg
)
788 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
791 static void route_match_ipv6_next_hop_prefix_list_free(void *rule
)
793 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
796 static const struct route_map_rule_cmd
797 route_match_ipv6_next_hop_prefix_list_cmd
= {
798 "ipv6 next-hop prefix-list",
799 route_match_ipv6_next_hop_prefix_list
,
800 route_match_ipv6_next_hop_prefix_list_compile
,
801 route_match_ipv6_next_hop_prefix_list_free
804 /* `match ip next-hop type <blackhole>' */
806 static enum route_map_cmd_result_t
807 route_match_ip_next_hop_type(void *rule
, const struct prefix
*prefix
,
810 struct bgp_path_info
*path
;
812 if (prefix
->family
== AF_INET
) {
813 path
= (struct bgp_path_info
*)object
;
817 /* If nexthop interface's index can't be resolved and nexthop is
818 set to any address then mark it as type `blackhole`.
819 This logic works for matching kernel/static routes like:
820 `ip route add blackhole 10.0.0.1`. */
821 if (path
->attr
->nexthop
.s_addr
== INADDR_ANY
822 && !path
->attr
->nh_ifindex
)
828 static void *route_match_ip_next_hop_type_compile(const char *arg
)
830 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
833 static void route_match_ip_next_hop_type_free(void *rule
)
835 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
838 static const struct route_map_rule_cmd
839 route_match_ip_next_hop_type_cmd
= {
841 route_match_ip_next_hop_type
,
842 route_match_ip_next_hop_type_compile
,
843 route_match_ip_next_hop_type_free
846 /* `match ip route-source prefix-list PREFIX_LIST' */
848 static enum route_map_cmd_result_t
849 route_match_ip_route_source_prefix_list(void *rule
, const struct prefix
*prefix
,
852 struct prefix_list
*plist
;
853 struct bgp_path_info
*path
;
855 struct prefix_ipv4 p
;
857 if (prefix
->family
== AF_INET
) {
861 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
865 p
.prefix
= peer
->su
.sin
.sin_addr
;
866 p
.prefixlen
= IPV4_MAX_BITLEN
;
868 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
872 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
879 static void *route_match_ip_route_source_prefix_list_compile(const char *arg
)
881 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
884 static void route_match_ip_route_source_prefix_list_free(void *rule
)
886 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
889 static const struct route_map_rule_cmd
890 route_match_ip_route_source_prefix_list_cmd
= {
891 "ip route-source prefix-list",
892 route_match_ip_route_source_prefix_list
,
893 route_match_ip_route_source_prefix_list_compile
,
894 route_match_ip_route_source_prefix_list_free
897 /* `match evpn default-route' */
899 /* Match function should return 1 if match is success else 0 */
900 static enum route_map_cmd_result_t
901 route_match_evpn_default_route(void *rule
, const struct prefix
*p
, void *object
)
903 if (is_evpn_prefix_default(p
))
909 /* Route map commands for default-route matching. */
910 static const struct route_map_rule_cmd
911 route_match_evpn_default_route_cmd
= {
912 "evpn default-route",
913 route_match_evpn_default_route
,
918 /* `match mac address MAC_ACCESS_LIST' */
920 /* Match function should return 1 if match is success else return
922 static enum route_map_cmd_result_t
923 route_match_mac_address(void *rule
, const struct prefix
*prefix
, void *object
)
925 struct access_list
*alist
;
928 alist
= access_list_lookup(AFI_L2VPN
, (char *)rule
);
932 if (prefix
->u
.prefix_evpn
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
935 p
.family
= AF_ETHERNET
;
936 p
.prefixlen
= ETH_ALEN
* 8;
937 p
.u
.prefix_eth
= prefix
->u
.prefix_evpn
.macip_addr
.mac
;
939 return (access_list_apply(alist
, &p
) == FILTER_DENY
? RMAP_NOMATCH
943 /* Route map `mac address' match statement. `arg' should be
945 static void *route_match_mac_address_compile(const char *arg
)
947 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
950 /* Free route map's compiled `ip address' value. */
951 static void route_match_mac_address_free(void *rule
)
953 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
956 /* Route map commands for mac address matching. */
957 static const struct route_map_rule_cmd route_match_mac_address_cmd
= {
959 route_match_mac_address
,
960 route_match_mac_address_compile
,
961 route_match_mac_address_free
965 * Match function returns:
966 * ...RMAP_MATCH if match is found.
967 * ...RMAP_NOMATCH if match is not found.
968 * ...RMAP_NOOP to ignore this match check.
970 static enum route_map_cmd_result_t
971 route_match_vni(void *rule
, const struct prefix
*prefix
, void *object
)
974 unsigned int label_cnt
= 0;
975 struct bgp_path_info
*path
= NULL
;
976 struct prefix_evpn
*evp
= (struct prefix_evpn
*) prefix
;
978 vni
= *((vni_t
*)rule
);
979 path
= (struct bgp_path_info
*)object
;
982 * This rmap filter is valid for vxlan tunnel type only.
983 * For any other tunnel type, return noop to ignore
986 if (path
->attr
->encap_tunneltype
!= BGP_ENCAP_TYPE_VXLAN
)
990 * Apply filter to type 1, 2, 5 routes only.
991 * Other route types do not have vni label.
994 && (evp
->prefix
.route_type
!= BGP_EVPN_AD_ROUTE
995 && evp
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
996 && evp
->prefix
.route_type
!= BGP_EVPN_IP_PREFIX_ROUTE
))
999 if (path
->extra
== NULL
)
1000 return RMAP_NOMATCH
;
1003 label_cnt
< BGP_MAX_LABELS
&& label_cnt
< path
->extra
->num_labels
;
1005 if (vni
== label2vni(&path
->extra
->label
[label_cnt
]))
1009 return RMAP_NOMATCH
;
1012 /* Route map `vni' match statement. */
1013 static void *route_match_vni_compile(const char *arg
)
1018 vni
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(vni_t
));
1020 *vni
= strtoul(arg
, &end
, 10);
1022 XFREE(MTYPE_ROUTE_MAP_COMPILED
, vni
);
1029 /* Free route map's compiled `vni' value. */
1030 static void route_match_vni_free(void *rule
)
1032 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1035 /* Route map commands for vni matching. */
1036 static const struct route_map_rule_cmd route_match_evpn_vni_cmd
= {
1039 route_match_vni_compile
,
1040 route_match_vni_free
1043 /* `match evpn route-type' */
1045 /* Match function should return 1 if match is success else return
1047 static enum route_map_cmd_result_t
1048 route_match_evpn_route_type(void *rule
, const struct prefix
*pfx
, void *object
)
1050 uint8_t route_type
= 0;
1052 route_type
= *((uint8_t *)rule
);
1054 if (route_type
== pfx
->u
.prefix_evpn
.route_type
)
1057 return RMAP_NOMATCH
;
1060 /* Route map `route-type' match statement. */
1061 static void *route_match_evpn_route_type_compile(const char *arg
)
1063 uint8_t *route_type
= NULL
;
1065 route_type
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
1067 if (strncmp(arg
, "ea", 2) == 0)
1068 *route_type
= BGP_EVPN_AD_ROUTE
;
1069 else if (strncmp(arg
, "ma", 2) == 0)
1070 *route_type
= BGP_EVPN_MAC_IP_ROUTE
;
1071 else if (strncmp(arg
, "mu", 2) == 0)
1072 *route_type
= BGP_EVPN_IMET_ROUTE
;
1073 else if (strncmp(arg
, "es", 2) == 0)
1074 *route_type
= BGP_EVPN_ES_ROUTE
;
1076 *route_type
= BGP_EVPN_IP_PREFIX_ROUTE
;
1081 /* Free route map's compiled `route-type' value. */
1082 static void route_match_evpn_route_type_free(void *rule
)
1084 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1087 /* Route map commands for evpn route-type matching. */
1088 static const struct route_map_rule_cmd route_match_evpn_route_type_cmd
= {
1090 route_match_evpn_route_type
,
1091 route_match_evpn_route_type_compile
,
1092 route_match_evpn_route_type_free
1097 /* Match function should return 1 if match is success else return zero. */
1098 static enum route_map_cmd_result_t
1099 route_match_rd(void *rule
, const struct prefix
*prefix
, void *object
)
1101 struct prefix_rd
*prd_rule
= NULL
;
1102 const struct prefix_rd
*prd_route
= NULL
;
1103 struct bgp_path_info
*path
= NULL
;
1105 if (prefix
->family
!= AF_EVPN
)
1106 return RMAP_NOMATCH
;
1108 prd_rule
= (struct prefix_rd
*)rule
;
1109 path
= (struct bgp_path_info
*)object
;
1111 if (path
->net
== NULL
|| path
->net
->pdest
== NULL
)
1112 return RMAP_NOMATCH
;
1114 prd_route
= (struct prefix_rd
*)bgp_dest_get_prefix(path
->net
->pdest
);
1115 if (memcmp(prd_route
->val
, prd_rule
->val
, ECOMMUNITY_SIZE
) == 0)
1118 return RMAP_NOMATCH
;
1121 /* Route map `rd' match statement. */
1122 static void *route_match_rd_compile(const char *arg
)
1124 struct prefix_rd
*prd
;
1127 prd
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct prefix_rd
));
1129 ret
= str2prefix_rd(arg
, prd
);
1131 XFREE(MTYPE_ROUTE_MAP_COMPILED
, prd
);
1138 /* Free route map's compiled `rd' value. */
1139 static void route_match_rd_free(void *rule
)
1141 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1144 /* Route map commands for rd matching. */
1145 static const struct route_map_rule_cmd route_match_evpn_rd_cmd
= {
1148 route_match_rd_compile
,
1152 static enum route_map_cmd_result_t
1153 route_set_evpn_gateway_ip(void *rule
, const struct prefix
*prefix
, void *object
)
1155 struct ipaddr
*gw_ip
= rule
;
1156 struct bgp_path_info
*path
;
1157 struct prefix_evpn
*evp
;
1159 if (prefix
->family
!= AF_EVPN
)
1162 evp
= (struct prefix_evpn
*)prefix
;
1163 if (evp
->prefix
.route_type
!= BGP_EVPN_IP_PREFIX_ROUTE
)
1166 if ((is_evpn_prefix_ipaddr_v4(evp
) && IPADDRSZ(gw_ip
) != 4)
1167 || (is_evpn_prefix_ipaddr_v6(evp
) && IPADDRSZ(gw_ip
) != 16))
1172 /* Set gateway-ip value. */
1173 path
->attr
->evpn_overlay
.type
= OVERLAY_INDEX_GATEWAY_IP
;
1174 memcpy(&path
->attr
->evpn_overlay
.gw_ip
, &gw_ip
->ip
.addr
,
1181 * Route map `evpn gateway-ip' compile function.
1182 * Given string is converted to struct ipaddr structure
1184 static void *route_set_evpn_gateway_ip_compile(const char *arg
)
1186 struct ipaddr
*gw_ip
= NULL
;
1189 gw_ip
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct ipaddr
));
1191 ret
= str2ipaddr(arg
, gw_ip
);
1193 XFREE(MTYPE_ROUTE_MAP_COMPILED
, gw_ip
);
1199 /* Free route map's compiled `evpn gateway_ip' value. */
1200 static void route_set_evpn_gateway_ip_free(void *rule
)
1202 struct ipaddr
*gw_ip
= rule
;
1204 XFREE(MTYPE_ROUTE_MAP_COMPILED
, gw_ip
);
1207 /* Route map commands for set evpn gateway-ip ipv4. */
1208 struct route_map_rule_cmd route_set_evpn_gateway_ip_ipv4_cmd
= {
1209 "evpn gateway-ip ipv4", route_set_evpn_gateway_ip
,
1210 route_set_evpn_gateway_ip_compile
, route_set_evpn_gateway_ip_free
};
1212 /* Route map commands for set evpn gateway-ip ipv6. */
1213 struct route_map_rule_cmd route_set_evpn_gateway_ip_ipv6_cmd
= {
1214 "evpn gateway-ip ipv6", route_set_evpn_gateway_ip
,
1215 route_set_evpn_gateway_ip_compile
, route_set_evpn_gateway_ip_free
};
1217 /* Route map commands for VRF route leak with source vrf matching */
1218 static enum route_map_cmd_result_t
1219 route_match_vrl_source_vrf(void *rule
, const struct prefix
*prefix
,
1222 struct bgp_path_info
*path
;
1226 path
= (struct bgp_path_info
*)object
;
1228 if (strncmp(vrf_name
, "n/a", VRF_NAMSIZ
) == 0)
1229 return RMAP_NOMATCH
;
1231 if (path
->extra
== NULL
|| path
->extra
->bgp_orig
== NULL
)
1232 return RMAP_NOMATCH
;
1234 if (strncmp(vrf_name
, vrf_id_to_name(path
->extra
->bgp_orig
->vrf_id
),
1239 return RMAP_NOMATCH
;
1242 static void *route_match_vrl_source_vrf_compile(const char *arg
)
1244 uint8_t *vrf_name
= NULL
;
1246 vrf_name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1251 /* Free route map's compiled `route-type' value. */
1252 static void route_match_vrl_source_vrf_free(void *rule
)
1254 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1257 static const struct route_map_rule_cmd route_match_vrl_source_vrf_cmd
= {
1259 route_match_vrl_source_vrf
,
1260 route_match_vrl_source_vrf_compile
,
1261 route_match_vrl_source_vrf_free
1265 static enum route_map_cmd_result_t
1266 route_match_alias(void *rule
, const struct prefix
*prefix
, void *object
)
1269 struct bgp_path_info
*path
= object
;
1274 if (bgp_attr_get_community(path
->attr
)) {
1276 frrstr_split(bgp_attr_get_community(path
->attr
)->str
, " ",
1277 &communities
, &num
);
1278 for (int i
= 0; i
< num
; i
++) {
1279 const char *com2alias
=
1280 bgp_community2alias(communities
[i
]);
1281 if (!found
&& strcmp(alias
, com2alias
) == 0)
1283 XFREE(MTYPE_TMP
, communities
[i
]);
1285 XFREE(MTYPE_TMP
, communities
);
1290 if (bgp_attr_get_lcommunity(path
->attr
)) {
1292 frrstr_split(bgp_attr_get_lcommunity(path
->attr
)->str
, " ",
1293 &communities
, &num
);
1294 for (int i
= 0; i
< num
; i
++) {
1295 const char *com2alias
=
1296 bgp_community2alias(communities
[i
]);
1297 if (!found
&& strcmp(alias
, com2alias
) == 0)
1299 XFREE(MTYPE_TMP
, communities
[i
]);
1301 XFREE(MTYPE_TMP
, communities
);
1306 return RMAP_NOMATCH
;
1309 static void *route_match_alias_compile(const char *arg
)
1312 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1315 static void route_match_alias_free(void *rule
)
1317 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1320 static const struct route_map_rule_cmd route_match_alias_cmd
= {
1321 "alias", route_match_alias
, route_match_alias_compile
,
1322 route_match_alias_free
};
1324 /* `match local-preference LOCAL-PREF' */
1326 /* Match function return 1 if match is success else return zero. */
1327 static enum route_map_cmd_result_t
1328 route_match_local_pref(void *rule
, const struct prefix
*prefix
, void *object
)
1330 uint32_t *local_pref
;
1331 struct bgp_path_info
*path
;
1336 if (path
->attr
->local_pref
== *local_pref
)
1339 return RMAP_NOMATCH
;
1343 * Route map `match local-preference' match statement.
1344 * `arg' is local-pref value
1346 static void *route_match_local_pref_compile(const char *arg
)
1348 uint32_t *local_pref
;
1349 char *endptr
= NULL
;
1350 unsigned long tmpval
;
1352 /* Locpref value shoud be integer. */
1353 if (!all_digit(arg
))
1357 tmpval
= strtoul(arg
, &endptr
, 10);
1358 if (*endptr
!= '\0' || errno
|| tmpval
> UINT32_MAX
)
1361 local_pref
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint32_t));
1363 *local_pref
= tmpval
;
1367 /* Free route map's compiled `match local-preference' value. */
1368 static void route_match_local_pref_free(void *rule
)
1370 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1373 /* Route map commands for metric matching. */
1374 static const struct route_map_rule_cmd route_match_local_pref_cmd
= {
1376 route_match_local_pref
,
1377 route_match_local_pref_compile
,
1378 route_match_local_pref_free
1381 /* `match metric METRIC' */
1383 /* Match function return 1 if match is success else return zero. */
1384 static enum route_map_cmd_result_t
1385 route_match_metric(void *rule
, const struct prefix
*prefix
, void *object
)
1387 struct rmap_value
*rv
;
1388 struct bgp_path_info
*path
;
1392 return route_value_match(rv
, path
->attr
->med
);
1395 /* Route map commands for metric matching. */
1396 static const struct route_map_rule_cmd route_match_metric_cmd
= {
1399 route_value_compile
,
1403 /* `match as-path ASPATH' */
1405 /* Match function for as-path match. I assume given object is */
1406 static enum route_map_cmd_result_t
1407 route_match_aspath(void *rule
, const struct prefix
*prefix
, void *object
)
1410 struct as_list
*as_list
;
1411 struct bgp_path_info
*path
;
1413 as_list
= as_list_lookup((char *)rule
);
1414 if (as_list
== NULL
)
1415 return RMAP_NOMATCH
;
1419 /* Perform match. */
1420 return ((as_list_apply(as_list
, path
->attr
->aspath
) == AS_FILTER_DENY
)
1425 /* Compile function for as-path match. */
1426 static void *route_match_aspath_compile(const char *arg
)
1428 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1431 /* Compile function for as-path match. */
1432 static void route_match_aspath_free(void *rule
)
1434 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1437 /* Route map commands for aspath matching. */
1438 static const struct route_map_rule_cmd route_match_aspath_cmd
= {
1441 route_match_aspath_compile
,
1442 route_match_aspath_free
1445 /* `match community COMMUNIY' */
1446 struct rmap_community
{
1452 /* Match function for community match. */
1453 static enum route_map_cmd_result_t
1454 route_match_community(void *rule
, const struct prefix
*prefix
, void *object
)
1456 struct community_list
*list
;
1457 struct bgp_path_info
*path
;
1458 struct rmap_community
*rcom
= rule
;
1463 list
= community_list_lookup(bgp_clist
, rcom
->name
, rcom
->name_hash
,
1464 COMMUNITY_LIST_MASTER
);
1466 return RMAP_NOMATCH
;
1469 if (community_list_exact_match(
1470 bgp_attr_get_community(path
->attr
), list
))
1473 if (community_list_match(bgp_attr_get_community(path
->attr
),
1478 return RMAP_NOMATCH
;
1481 /* Compile function for community match. */
1482 static void *route_match_community_compile(const char *arg
)
1484 struct rmap_community
*rcom
;
1488 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1490 p
= strchr(arg
, ' ');
1493 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1494 memcpy(rcom
->name
, arg
, len
);
1497 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1501 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1505 /* Compile function for community match. */
1506 static void route_match_community_free(void *rule
)
1508 struct rmap_community
*rcom
= rule
;
1510 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1511 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1515 * In routemap processing there is a need to add the
1516 * name as a rule_key in the dependency table. Routemap
1517 * lib is unaware of rule_key when exact-match clause
1518 * is in use. routemap lib uses the compiled output to
1519 * get the rule_key value.
1521 static void *route_match_get_community_key(void *rule
)
1523 struct rmap_community
*rcom
;
1530 /* Route map commands for community matching. */
1531 static const struct route_map_rule_cmd route_match_community_cmd
= {
1533 route_match_community
,
1534 route_match_community_compile
,
1535 route_match_community_free
,
1536 route_match_get_community_key
1539 /* Match function for lcommunity match. */
1540 static enum route_map_cmd_result_t
1541 route_match_lcommunity(void *rule
, const struct prefix
*prefix
, void *object
)
1543 struct community_list
*list
;
1544 struct bgp_path_info
*path
;
1545 struct rmap_community
*rcom
= rule
;
1549 list
= community_list_lookup(bgp_clist
, rcom
->name
, rcom
->name_hash
,
1550 LARGE_COMMUNITY_LIST_MASTER
);
1552 return RMAP_NOMATCH
;
1555 if (lcommunity_list_exact_match(
1556 bgp_attr_get_lcommunity(path
->attr
), list
))
1559 if (lcommunity_list_match(bgp_attr_get_lcommunity(path
->attr
),
1564 return RMAP_NOMATCH
;
1567 /* Compile function for community match. */
1568 static void *route_match_lcommunity_compile(const char *arg
)
1570 struct rmap_community
*rcom
;
1574 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1576 p
= strchr(arg
, ' ');
1579 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1580 memcpy(rcom
->name
, arg
, len
);
1583 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1587 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1591 /* Compile function for community match. */
1592 static void route_match_lcommunity_free(void *rule
)
1594 struct rmap_community
*rcom
= rule
;
1596 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1597 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1600 /* Route map commands for community matching. */
1601 static const struct route_map_rule_cmd route_match_lcommunity_cmd
= {
1603 route_match_lcommunity
,
1604 route_match_lcommunity_compile
,
1605 route_match_lcommunity_free
,
1606 route_match_get_community_key
1610 /* Match function for extcommunity match. */
1611 static enum route_map_cmd_result_t
1612 route_match_ecommunity(void *rule
, const struct prefix
*prefix
, void *object
)
1614 struct community_list
*list
;
1615 struct bgp_path_info
*path
;
1616 struct rmap_community
*rcom
= rule
;
1620 list
= community_list_lookup(bgp_clist
, rcom
->name
, rcom
->name_hash
,
1621 EXTCOMMUNITY_LIST_MASTER
);
1623 return RMAP_NOMATCH
;
1625 if (ecommunity_list_match(bgp_attr_get_ecommunity(path
->attr
), list
))
1628 return RMAP_NOMATCH
;
1631 /* Compile function for extcommunity match. */
1632 static void *route_match_ecommunity_compile(const char *arg
)
1634 struct rmap_community
*rcom
;
1636 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1637 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1638 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1643 /* Compile function for extcommunity match. */
1644 static void route_match_ecommunity_free(void *rule
)
1646 struct rmap_community
*rcom
= rule
;
1648 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1649 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1652 /* Route map commands for community matching. */
1653 static const struct route_map_rule_cmd route_match_ecommunity_cmd
= {
1655 route_match_ecommunity
,
1656 route_match_ecommunity_compile
,
1657 route_match_ecommunity_free
1660 /* `match nlri` and `set nlri` are replaced by `address-family ipv4`
1661 and `address-family vpnv4'. */
1663 /* `match origin' */
1664 static enum route_map_cmd_result_t
1665 route_match_origin(void *rule
, const struct prefix
*prefix
, void *object
)
1668 struct bgp_path_info
*path
;
1673 if (path
->attr
->origin
== *origin
)
1676 return RMAP_NOMATCH
;
1679 static void *route_match_origin_compile(const char *arg
)
1683 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
1685 if (strcmp(arg
, "igp") == 0)
1687 else if (strcmp(arg
, "egp") == 0)
1695 /* Free route map's compiled `ip address' value. */
1696 static void route_match_origin_free(void *rule
)
1698 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1701 /* Route map commands for origin matching. */
1702 static const struct route_map_rule_cmd route_match_origin_cmd
= {
1705 route_match_origin_compile
,
1706 route_match_origin_free
1709 /* match probability { */
1711 static enum route_map_cmd_result_t
1712 route_match_probability(void *rule
, const struct prefix
*prefix
, void *object
)
1714 long r
= frr_weak_random();
1716 switch (*(long *)rule
) {
1722 if (r
< *(long *)rule
) {
1727 return RMAP_NOMATCH
;
1730 static void *route_match_probability_compile(const char *arg
)
1736 lobule
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(long));
1746 *lobule
= RAND_MAX
/ 100 * perc
;
1752 static void route_match_probability_free(void *rule
)
1754 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1757 static const struct route_map_rule_cmd route_match_probability_cmd
= {
1759 route_match_probability
,
1760 route_match_probability_compile
,
1761 route_match_probability_free
1764 /* `match interface IFNAME' */
1765 /* Match function should return 1 if match is success else return
1767 static enum route_map_cmd_result_t
1768 route_match_interface(void *rule
, const struct prefix
*prefix
, void *object
)
1770 struct interface
*ifp
;
1771 struct bgp_path_info
*path
;
1775 if (!path
|| !path
->peer
|| !path
->peer
->bgp
)
1776 return RMAP_NOMATCH
;
1778 ifp
= if_lookup_by_name((char *)rule
, path
->peer
->bgp
->vrf_id
);
1780 if (ifp
== NULL
|| ifp
->ifindex
!= path
->attr
->nh_ifindex
)
1781 return RMAP_NOMATCH
;
1786 /* Route map `interface' match statement. `arg' should be
1788 static void *route_match_interface_compile(const char *arg
)
1790 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1793 /* Free route map's compiled `interface' value. */
1794 static void route_match_interface_free(void *rule
)
1796 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1799 /* Route map commands for ip address matching. */
1800 static const struct route_map_rule_cmd route_match_interface_cmd
= {
1802 route_match_interface
,
1803 route_match_interface_compile
,
1804 route_match_interface_free
1809 /* `set ip next-hop IP_ADDRESS' */
1811 /* Match function return 1 if match is success else return zero. */
1812 static enum route_map_cmd_result_t
1813 route_match_tag(void *rule
, const struct prefix
*prefix
, void *object
)
1816 struct bgp_path_info
*path
;
1821 return ((path
->attr
->tag
== *tag
) ? RMAP_MATCH
: RMAP_NOMATCH
);
1825 /* Route map commands for tag matching. */
1826 static const struct route_map_rule_cmd route_match_tag_cmd
= {
1829 route_map_rule_tag_compile
,
1830 route_map_rule_tag_free
,
1833 static enum route_map_cmd_result_t
1834 route_set_srte_color(void *rule
, const struct prefix
*prefix
, void *object
)
1836 uint32_t *srte_color
= rule
;
1837 struct bgp_path_info
*path
;
1841 path
->attr
->srte_color
= *srte_color
;
1842 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_SRTE_COLOR
);
1847 /* Route map `sr-te color' compile function */
1848 static void *route_set_srte_color_compile(const char *arg
)
1852 color
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint32_t));
1858 /* Free route map's compiled `sr-te color' value. */
1859 static void route_set_srte_color_free(void *rule
)
1861 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1864 /* Route map commands for sr-te color set. */
1865 struct route_map_rule_cmd route_set_srte_color_cmd
= {
1866 "sr-te color", route_set_srte_color
, route_set_srte_color_compile
,
1867 route_set_srte_color_free
};
1869 /* Set nexthop to object. object must be pointer to struct attr. */
1870 struct rmap_ip_nexthop_set
{
1871 struct in_addr
*address
;
1876 static enum route_map_cmd_result_t
1877 route_set_ip_nexthop(void *rule
, const struct prefix
*prefix
, void *object
)
1879 struct rmap_ip_nexthop_set
*rins
= rule
;
1880 struct bgp_path_info
*path
;
1883 if (prefix
->family
== AF_INET6
)
1889 if (rins
->unchanged
) {
1890 SET_FLAG(path
->attr
->rmap_change_flags
,
1891 BATTR_RMAP_NEXTHOP_UNCHANGED
);
1892 } else if (rins
->peer_address
) {
1893 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
1894 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
1896 && sockunion_family(peer
->su_remote
) == AF_INET
) {
1897 path
->attr
->nexthop
.s_addr
=
1898 sockunion2ip(peer
->su_remote
);
1899 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1900 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
1901 /* The next hop value will be set as part of
1902 * packet rewrite. Set the flags here to indicate
1903 * that rewrite needs to be done.
1904 * Also, clear the value.
1906 SET_FLAG(path
->attr
->rmap_change_flags
,
1907 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
1908 path
->attr
->nexthop
.s_addr
= INADDR_ANY
;
1911 /* Set next hop value. */
1912 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1913 path
->attr
->nexthop
= *rins
->address
;
1914 SET_FLAG(path
->attr
->rmap_change_flags
,
1915 BATTR_RMAP_IPV4_NHOP_CHANGED
);
1916 /* case for MP-BGP : MPLS VPN */
1917 path
->attr
->mp_nexthop_global_in
= *rins
->address
;
1918 path
->attr
->mp_nexthop_len
= sizeof(*rins
->address
);
1924 /* Route map `ip nexthop' compile function. Given string is converted
1925 to struct in_addr structure. */
1926 static void *route_set_ip_nexthop_compile(const char *arg
)
1928 struct rmap_ip_nexthop_set
*rins
;
1929 struct in_addr
*address
= NULL
;
1930 int peer_address
= 0;
1934 if (strcmp(arg
, "peer-address") == 0)
1936 else if (strcmp(arg
, "unchanged") == 0)
1939 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1940 sizeof(struct in_addr
));
1941 ret
= inet_aton(arg
, address
);
1944 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
1949 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1950 sizeof(struct rmap_ip_nexthop_set
));
1952 rins
->address
= address
;
1953 rins
->peer_address
= peer_address
;
1954 rins
->unchanged
= unchanged
;
1959 /* Free route map's compiled `ip nexthop' value. */
1960 static void route_set_ip_nexthop_free(void *rule
)
1962 struct rmap_ip_nexthop_set
*rins
= rule
;
1964 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
->address
);
1966 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
);
1969 /* Route map commands for ip nexthop set. */
1970 static const struct route_map_rule_cmd route_set_ip_nexthop_cmd
= {
1972 route_set_ip_nexthop
,
1973 route_set_ip_nexthop_compile
,
1974 route_set_ip_nexthop_free
1977 /* `set l3vpn next-hop encapsulation l3vpn gre' */
1979 /* Set nexthop to object */
1980 struct rmap_l3vpn_nexthop_encapsulation_set
{
1984 static enum route_map_cmd_result_t
1985 route_set_l3vpn_nexthop_encapsulation(void *rule
, const struct prefix
*prefix
,
1988 struct rmap_l3vpn_nexthop_encapsulation_set
*rins
= rule
;
1989 struct bgp_path_info
*path
;
1993 if (rins
->protocol
!= IPPROTO_GRE
)
1996 SET_FLAG(path
->attr
->rmap_change_flags
, BATTR_RMAP_L3VPN_ACCEPT_GRE
);
2000 /* Route map `l3vpn nexthop encapsulation' compile function. */
2001 static void *route_set_l3vpn_nexthop_encapsulation_compile(const char *arg
)
2003 struct rmap_l3vpn_nexthop_encapsulation_set
*rins
;
2005 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
2006 sizeof(struct rmap_l3vpn_nexthop_encapsulation_set
));
2008 /* XXX ALL GRE modes are accepted for now: gre or ip6gre */
2009 rins
->protocol
= IPPROTO_GRE
;
2014 /* Free route map's compiled `ip nexthop' value. */
2015 static void route_set_l3vpn_nexthop_encapsulation_free(void *rule
)
2017 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2020 /* Route map commands for l3vpn next-hop encapsulation set. */
2021 static const struct route_map_rule_cmd
2022 route_set_l3vpn_nexthop_encapsulation_cmd
= {
2023 "l3vpn next-hop encapsulation",
2024 route_set_l3vpn_nexthop_encapsulation
,
2025 route_set_l3vpn_nexthop_encapsulation_compile
,
2026 route_set_l3vpn_nexthop_encapsulation_free
};
2028 /* `set local-preference LOCAL_PREF' */
2030 /* Set local preference. */
2031 static enum route_map_cmd_result_t
2032 route_set_local_pref(void *rule
, const struct prefix
*prefix
, void *object
)
2034 struct rmap_value
*rv
;
2035 struct bgp_path_info
*path
;
2036 uint32_t locpref
= 0;
2038 /* Fetch routemap's rule information. */
2042 /* Set local preference value. */
2043 if (path
->attr
->local_pref
)
2044 locpref
= path
->attr
->local_pref
;
2046 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
);
2047 path
->attr
->local_pref
= route_value_adjust(rv
, locpref
, path
->peer
);
2052 /* Set local preference rule structure. */
2053 static const struct route_map_rule_cmd route_set_local_pref_cmd
= {
2055 route_set_local_pref
,
2056 route_value_compile
,
2060 /* `set weight WEIGHT' */
2063 static enum route_map_cmd_result_t
2064 route_set_weight(void *rule
, const struct prefix
*prefix
, void *object
)
2066 struct rmap_value
*rv
;
2067 struct bgp_path_info
*path
;
2069 /* Fetch routemap's rule information. */
2073 /* Set weight value. */
2074 path
->attr
->weight
= route_value_adjust(rv
, 0, path
->peer
);
2079 /* Set local preference rule structure. */
2080 static const struct route_map_rule_cmd route_set_weight_cmd
= {
2083 route_value_compile
,
2087 /* `set distance DISTANCE */
2088 static enum route_map_cmd_result_t
2089 route_set_distance(void *rule
, const struct prefix
*prefix
, void *object
)
2091 struct bgp_path_info
*path
= object
;
2092 struct rmap_value
*rv
= rule
;
2094 path
->attr
->distance
= rv
->value
;
2099 /* set distance rule structure */
2100 static const struct route_map_rule_cmd route_set_distance_cmd
= {
2103 route_value_compile
,
2107 /* `set metric METRIC' */
2109 /* Set metric to attribute. */
2110 static enum route_map_cmd_result_t
2111 route_set_metric(void *rule
, const struct prefix
*prefix
, void *object
)
2113 struct rmap_value
*rv
;
2114 struct bgp_path_info
*path
;
2117 /* Fetch routemap's rule information. */
2121 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
))
2122 med
= path
->attr
->med
;
2124 path
->attr
->med
= route_value_adjust(rv
, med
, path
->peer
);
2125 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
);
2130 /* Set metric rule structure. */
2131 static const struct route_map_rule_cmd route_set_metric_cmd
= {
2134 route_value_compile
,
2138 /* `set table (1-4294967295)' */
2140 static enum route_map_cmd_result_t
2141 route_set_table_id(void *rule
, const struct prefix
*prefix
,
2145 struct rmap_value
*rv
;
2146 struct bgp_path_info
*path
;
2148 /* Fetch routemap's rule information. */
2152 path
->attr
->rmap_table_id
= rv
->value
;
2157 /* Set table_id rule structure. */
2158 static const struct route_map_rule_cmd route_set_table_id_cmd
= {
2161 route_value_compile
,
2165 /* `set as-path prepend ASPATH' */
2167 /* For AS path prepend mechanism. */
2168 static enum route_map_cmd_result_t
2169 route_set_aspath_prepend(void *rule
, const struct prefix
*prefix
, void *object
)
2171 struct aspath
*aspath
;
2173 struct bgp_path_info
*path
;
2177 if (path
->attr
->aspath
->refcnt
)
2178 new = aspath_dup(path
->attr
->aspath
);
2180 new = path
->attr
->aspath
;
2182 if ((uintptr_t)rule
> 10) {
2184 aspath_prepend(aspath
, new);
2186 as_t as
= aspath_leftmost(new);
2188 new = aspath_add_seq_n(new, as
, (uintptr_t)rule
);
2191 path
->attr
->aspath
= new;
2196 static void *route_set_aspath_prepend_compile(const char *arg
)
2200 if (sscanf(arg
, "last-as %u", &num
) == 1 && num
> 0 && num
<= 10)
2201 return (void *)(uintptr_t)num
;
2203 return route_aspath_compile(arg
);
2206 static void route_set_aspath_prepend_free(void *rule
)
2208 if ((uintptr_t)rule
> 10)
2209 route_aspath_free(rule
);
2213 /* Set as-path prepend rule structure. */
2214 static const struct route_map_rule_cmd route_set_aspath_prepend_cmd
= {
2216 route_set_aspath_prepend
,
2217 route_set_aspath_prepend_compile
,
2218 route_set_aspath_prepend_free
,
2221 /* `set as-path exclude ASn' */
2223 /* For ASN exclude mechanism.
2224 * Iterate over ASns requested and filter them from the given AS_PATH one by
2226 * Make a deep copy of existing AS_PATH, but for the first ASn only.
2228 static enum route_map_cmd_result_t
2229 route_set_aspath_exclude(void *rule
, const struct prefix
*dummy
, void *object
)
2231 struct aspath
*new_path
, *exclude_path
;
2232 struct bgp_path_info
*path
;
2234 exclude_path
= rule
;
2236 if (path
->attr
->aspath
->refcnt
)
2237 new_path
= aspath_dup(path
->attr
->aspath
);
2239 new_path
= path
->attr
->aspath
;
2240 path
->attr
->aspath
= aspath_filter_exclude(new_path
, exclude_path
);
2245 /* Set ASn exlude rule structure. */
2246 static const struct route_map_rule_cmd route_set_aspath_exclude_cmd
= {
2248 route_set_aspath_exclude
,
2249 route_aspath_compile
,
2253 /* `set as-path replace AS-PATH` */
2254 static void *route_aspath_replace_compile(const char *arg
)
2256 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2259 static void route_aspath_replace_free(void *rule
)
2261 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2264 static enum route_map_cmd_result_t
2265 route_set_aspath_replace(void *rule
, const struct prefix
*dummy
, void *object
)
2267 struct aspath
*aspath_new
;
2268 const char *replace
= rule
;
2269 struct bgp_path_info
*path
= object
;
2270 as_t own_asn
= path
->peer
->change_local_as
? path
->peer
->change_local_as
2271 : path
->peer
->local_as
;
2273 if (path
->peer
->sort
!= BGP_PEER_EBGP
) {
2275 "`set as-path replace` is supported only for EBGP peers");
2279 if (path
->attr
->aspath
->refcnt
)
2280 aspath_new
= aspath_dup(path
->attr
->aspath
);
2282 aspath_new
= path
->attr
->aspath
;
2284 if (strmatch(replace
, "any")) {
2285 path
->attr
->aspath
=
2286 aspath_replace_all_asn(aspath_new
, own_asn
);
2288 as_t replace_asn
= strtoul(replace
, NULL
, 10);
2290 path
->attr
->aspath
= aspath_replace_specific_asn(
2291 aspath_new
, replace_asn
, own_asn
);
2294 aspath_free(aspath_new
);
2299 static const struct route_map_rule_cmd route_set_aspath_replace_cmd
= {
2301 route_set_aspath_replace
,
2302 route_aspath_replace_compile
,
2303 route_aspath_replace_free
,
2306 /* `set community COMMUNITY' */
2307 struct rmap_com_set
{
2308 struct community
*com
;
2313 /* For community set mechanism. */
2314 static enum route_map_cmd_result_t
2315 route_set_community(void *rule
, const struct prefix
*prefix
, void *object
)
2317 struct rmap_com_set
*rcs
;
2318 struct bgp_path_info
*path
;
2320 struct community
*new = NULL
;
2321 struct community
*old
;
2322 struct community
*merge
;
2327 old
= bgp_attr_get_community(attr
);
2331 bgp_attr_set_community(attr
, NULL
);
2332 /* See the longer comment down below. */
2333 if (old
&& old
->refcnt
== 0)
2334 community_free(&old
);
2338 /* "additive" case. */
2339 if (rcs
->additive
&& old
) {
2340 merge
= community_merge(community_dup(old
), rcs
->com
);
2342 new = community_uniq_sort(merge
);
2343 community_free(&merge
);
2345 new = community_dup(rcs
->com
);
2347 /* HACK: if the old community is not intern'd,
2348 * we should free it here, or all reference to it may be
2350 * Really need to cleanup attribute caching sometime.
2352 if (old
&& old
->refcnt
== 0)
2353 community_free(&old
);
2355 /* will be interned by caller if required */
2356 bgp_attr_set_community(attr
, new);
2361 /* Compile function for set community. */
2362 static void *route_set_community_compile(const char *arg
)
2364 struct rmap_com_set
*rcs
;
2365 struct community
*com
= NULL
;
2370 if (strcmp(arg
, "none") == 0)
2373 sp
= strstr(arg
, "additive");
2375 if (sp
&& sp
> arg
) {
2376 /* "additive" keyword is included. */
2381 com
= community_str2com(arg
);
2390 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
2392 rcs
->additive
= additive
;
2398 /* Free function for set community. */
2399 static void route_set_community_free(void *rule
)
2401 struct rmap_com_set
*rcs
= rule
;
2404 community_free(&rcs
->com
);
2405 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
2408 /* Set community rule structure. */
2409 static const struct route_map_rule_cmd route_set_community_cmd
= {
2411 route_set_community
,
2412 route_set_community_compile
,
2413 route_set_community_free
,
2416 /* `set community COMMUNITY' */
2417 struct rmap_lcom_set
{
2418 struct lcommunity
*lcom
;
2424 /* For lcommunity set mechanism. */
2425 static enum route_map_cmd_result_t
2426 route_set_lcommunity(void *rule
, const struct prefix
*prefix
, void *object
)
2428 struct rmap_lcom_set
*rcs
;
2429 struct bgp_path_info
*path
;
2431 struct lcommunity
*new = NULL
;
2432 struct lcommunity
*old
;
2433 struct lcommunity
*merge
;
2438 old
= bgp_attr_get_lcommunity(attr
);
2442 bgp_attr_set_lcommunity(attr
, NULL
);
2444 /* See the longer comment down below. */
2445 if (old
&& old
->refcnt
== 0)
2446 lcommunity_free(&old
);
2450 if (rcs
->additive
&& old
) {
2451 merge
= lcommunity_merge(lcommunity_dup(old
), rcs
->lcom
);
2453 new = lcommunity_uniq_sort(merge
);
2454 lcommunity_free(&merge
);
2456 new = lcommunity_dup(rcs
->lcom
);
2458 /* HACK: if the old large-community is not intern'd,
2459 * we should free it here, or all reference to it may be
2461 * Really need to cleanup attribute caching sometime.
2463 if (old
&& old
->refcnt
== 0)
2464 lcommunity_free(&old
);
2466 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
2467 bgp_attr_set_lcommunity(attr
, new);
2472 /* Compile function for set community. */
2473 static void *route_set_lcommunity_compile(const char *arg
)
2475 struct rmap_lcom_set
*rcs
;
2476 struct lcommunity
*lcom
= NULL
;
2481 if (strcmp(arg
, "none") == 0)
2484 sp
= strstr(arg
, "additive");
2486 if (sp
&& sp
> arg
) {
2487 /* "additive" keyworkd is included. */
2492 lcom
= lcommunity_str2com(arg
);
2501 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
2503 rcs
->additive
= additive
;
2509 /* Free function for set lcommunity. */
2510 static void route_set_lcommunity_free(void *rule
)
2512 struct rmap_lcom_set
*rcs
= rule
;
2515 lcommunity_free(&rcs
->lcom
);
2517 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
2520 /* Set community rule structure. */
2521 static const struct route_map_rule_cmd route_set_lcommunity_cmd
= {
2523 route_set_lcommunity
,
2524 route_set_lcommunity_compile
,
2525 route_set_lcommunity_free
,
2528 /* `set large-comm-list (<1-99>|<100-500>|WORD) delete' */
2530 /* For large community set mechanism. */
2531 static enum route_map_cmd_result_t
2532 route_set_lcommunity_delete(void *rule
, const struct prefix
*pfx
, void *object
)
2534 struct community_list
*list
;
2535 struct lcommunity
*merge
;
2536 struct lcommunity
*new;
2537 struct lcommunity
*old
;
2538 struct bgp_path_info
*path
;
2539 struct rmap_community
*rcom
= rule
;
2545 list
= community_list_lookup(bgp_clist
, rcom
->name
, rcom
->name_hash
,
2546 LARGE_COMMUNITY_LIST_MASTER
);
2547 old
= bgp_attr_get_lcommunity(path
->attr
);
2550 merge
= lcommunity_list_match_delete(lcommunity_dup(old
), list
);
2551 new = lcommunity_uniq_sort(merge
);
2552 lcommunity_free(&merge
);
2554 /* HACK: if the old community is not intern'd,
2555 * we should free it here, or all reference to it may be
2557 * Really need to cleanup attribute caching sometime.
2559 if (old
->refcnt
== 0)
2560 lcommunity_free(&old
);
2562 if (new->size
== 0) {
2563 bgp_attr_set_lcommunity(path
->attr
, NULL
);
2564 lcommunity_free(&new);
2566 bgp_attr_set_lcommunity(path
->attr
, new);
2573 /* Compile function for set lcommunity. */
2574 static void *route_set_lcommunity_delete_compile(const char *arg
)
2576 struct rmap_community
*rcom
;
2580 frrstr_split(arg
, " ", &splits
, &num
);
2582 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2583 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, splits
[0]);
2584 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2586 for (int i
= 0; i
< num
; i
++)
2587 XFREE(MTYPE_TMP
, splits
[i
]);
2588 XFREE(MTYPE_TMP
, splits
);
2593 /* Free function for set lcommunity. */
2594 static void route_set_lcommunity_delete_free(void *rule
)
2596 struct rmap_community
*rcom
= rule
;
2598 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2599 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2602 /* Set lcommunity rule structure. */
2603 static const struct route_map_rule_cmd route_set_lcommunity_delete_cmd
= {
2605 route_set_lcommunity_delete
,
2606 route_set_lcommunity_delete_compile
,
2607 route_set_lcommunity_delete_free
,
2611 /* `set comm-list (<1-99>|<100-500>|WORD) delete' */
2613 /* For community set mechanism. */
2614 static enum route_map_cmd_result_t
2615 route_set_community_delete(void *rule
, const struct prefix
*prefix
,
2618 struct community_list
*list
;
2619 struct community
*merge
;
2620 struct community
*new;
2621 struct community
*old
;
2622 struct bgp_path_info
*path
;
2623 struct rmap_community
*rcom
= rule
;
2629 list
= community_list_lookup(bgp_clist
, rcom
->name
, rcom
->name_hash
,
2630 COMMUNITY_LIST_MASTER
);
2631 old
= bgp_attr_get_community(path
->attr
);
2634 merge
= community_list_match_delete(community_dup(old
), list
);
2635 new = community_uniq_sort(merge
);
2636 community_free(&merge
);
2638 /* HACK: if the old community is not intern'd,
2639 * we should free it here, or all reference to it may be
2641 * Really need to cleanup attribute caching sometime.
2643 if (old
->refcnt
== 0)
2644 community_free(&old
);
2646 if (new->size
== 0) {
2647 bgp_attr_set_community(path
->attr
, NULL
);
2648 community_free(&new);
2650 bgp_attr_set_community(path
->attr
, new);
2657 /* Compile function for set community. */
2658 static void *route_set_community_delete_compile(const char *arg
)
2660 struct rmap_community
*rcom
;
2664 frrstr_split(arg
, " ", &splits
, &num
);
2666 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2667 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, splits
[0]);
2668 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2670 for (int i
= 0; i
< num
; i
++)
2671 XFREE(MTYPE_TMP
, splits
[i
]);
2672 XFREE(MTYPE_TMP
, splits
);
2677 /* Free function for set community. */
2678 static void route_set_community_delete_free(void *rule
)
2680 struct rmap_community
*rcom
= rule
;
2682 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2683 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2686 /* Set community rule structure. */
2687 static const struct route_map_rule_cmd route_set_community_delete_cmd
= {
2689 route_set_community_delete
,
2690 route_set_community_delete_compile
,
2691 route_set_community_delete_free
,
2694 /* `set extcommunity rt COMMUNITY' */
2696 struct rmap_ecom_set
{
2697 struct ecommunity
*ecom
;
2701 /* For community set mechanism. Used by _rt and _soo. */
2702 static enum route_map_cmd_result_t
2703 route_set_ecommunity(void *rule
, const struct prefix
*prefix
, void *object
)
2705 struct rmap_ecom_set
*rcs
;
2706 struct ecommunity
*new_ecom
;
2707 struct ecommunity
*old_ecom
;
2708 struct bgp_path_info
*path
;
2716 bgp_attr_set_ecommunity(attr
, NULL
);
2723 /* We assume additive for Extended Community. */
2724 old_ecom
= bgp_attr_get_ecommunity(path
->attr
);
2728 ecommunity_merge(ecommunity_dup(old_ecom
), rcs
->ecom
);
2730 /* old_ecom->refcnt = 1 => owned elsewhere, e.g.
2731 * bgp_update_receive()
2732 * ->refcnt = 0 => set by a previous route-map
2734 if (!old_ecom
->refcnt
)
2735 ecommunity_free(&old_ecom
);
2737 new_ecom
= ecommunity_dup(rcs
->ecom
);
2739 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
2740 bgp_attr_set_ecommunity(path
->attr
, new_ecom
);
2745 static void *route_set_ecommunity_none_compile(const char *arg
)
2747 struct rmap_ecom_set
*rcs
;
2750 if (strncmp(arg
, "none", 4) == 0)
2753 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_ecom_set
));
2760 static void *route_set_ecommunity_rt_compile(const char *arg
)
2762 struct rmap_ecom_set
*rcs
;
2763 struct ecommunity
*ecom
;
2765 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_ROUTE_TARGET
, 0);
2769 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_ecom_set
));
2770 rcs
->ecom
= ecommunity_intern(ecom
);
2776 /* Free function for set community. Used by _rt and _soo */
2777 static void route_set_ecommunity_free(void *rule
)
2779 struct rmap_ecom_set
*rcs
= rule
;
2782 ecommunity_unintern(&rcs
->ecom
);
2784 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
2787 static const struct route_map_rule_cmd route_set_ecommunity_none_cmd
= {
2789 route_set_ecommunity
,
2790 route_set_ecommunity_none_compile
,
2791 route_set_ecommunity_free
,
2794 /* Set community rule structure. */
2795 static const struct route_map_rule_cmd route_set_ecommunity_rt_cmd
= {
2797 route_set_ecommunity
,
2798 route_set_ecommunity_rt_compile
,
2799 route_set_ecommunity_free
,
2802 /* `set extcommunity soo COMMUNITY' */
2804 /* Compile function for set community. */
2805 static void *route_set_ecommunity_soo_compile(const char *arg
)
2807 struct rmap_ecom_set
*rcs
;
2808 struct ecommunity
*ecom
;
2810 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_SITE_ORIGIN
, 0);
2814 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_ecom_set
));
2815 rcs
->ecom
= ecommunity_intern(ecom
);
2821 /* Set community rule structure. */
2822 static const struct route_map_rule_cmd route_set_ecommunity_soo_cmd
= {
2824 route_set_ecommunity
,
2825 route_set_ecommunity_soo_compile
,
2826 route_set_ecommunity_free
,
2829 /* `set extcommunity bandwidth' */
2831 struct rmap_ecomm_lb_set
{
2833 #define RMAP_ECOMM_LB_SET_VALUE 1
2834 #define RMAP_ECOMM_LB_SET_CUMUL 2
2835 #define RMAP_ECOMM_LB_SET_NUM_MPATH 3
2840 static enum route_map_cmd_result_t
2841 route_set_ecommunity_lb(void *rule
, const struct prefix
*prefix
, void *object
)
2843 struct rmap_ecomm_lb_set
*rels
= rule
;
2844 struct bgp_path_info
*path
;
2846 struct ecommunity ecom_lb
= {0};
2847 struct ecommunity_val lb_eval
;
2848 uint32_t bw_bytes
= 0;
2849 uint16_t mpath_count
= 0;
2850 struct ecommunity
*new_ecom
;
2851 struct ecommunity
*old_ecom
;
2856 if (!peer
|| !peer
->bgp
)
2859 /* Build link bandwidth extended community */
2860 as
= (peer
->bgp
->as
> BGP_AS_MAX
) ? BGP_AS_TRANS
: peer
->bgp
->as
;
2861 if (rels
->lb_type
== RMAP_ECOMM_LB_SET_VALUE
) {
2862 bw_bytes
= ((uint64_t)rels
->bw
* 1000 * 1000) / 8;
2863 } else if (rels
->lb_type
== RMAP_ECOMM_LB_SET_CUMUL
) {
2864 /* process this only for the best path. */
2865 if (!CHECK_FLAG(path
->flags
, BGP_PATH_SELECTED
))
2868 bw_bytes
= (uint32_t)bgp_path_info_mpath_cumbw(path
);
2872 } else if (rels
->lb_type
== RMAP_ECOMM_LB_SET_NUM_MPATH
) {
2874 /* process this only for the best path. */
2875 if (!CHECK_FLAG(path
->flags
, BGP_PATH_SELECTED
))
2878 bw_bytes
= ((uint64_t)peer
->bgp
->lb_ref_bw
* 1000 * 1000) / 8;
2879 mpath_count
= bgp_path_info_mpath_count(path
) + 1;
2880 bw_bytes
*= mpath_count
;
2883 encode_lb_extcomm(as
, bw_bytes
, rels
->non_trans
, &lb_eval
,
2884 CHECK_FLAG(peer
->flags
,
2885 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE
));
2887 /* add to route or merge with existing */
2888 old_ecom
= bgp_attr_get_ecommunity(path
->attr
);
2890 new_ecom
= ecommunity_dup(old_ecom
);
2891 ecommunity_add_val(new_ecom
, &lb_eval
, true, true);
2892 if (!old_ecom
->refcnt
)
2893 ecommunity_free(&old_ecom
);
2896 ecom_lb
.unit_size
= ECOMMUNITY_SIZE
;
2897 ecom_lb
.val
= (uint8_t *)lb_eval
.val
;
2898 new_ecom
= ecommunity_dup(&ecom_lb
);
2901 /* new_ecom will be intern()'d or attr_flush()'d in call stack */
2902 bgp_attr_set_ecommunity(path
->attr
, new_ecom
);
2904 /* Mark that route-map has set link bandwidth; used in attribute
2905 * setting decisions.
2907 SET_FLAG(path
->attr
->rmap_change_flags
, BATTR_RMAP_LINK_BW_SET
);
2912 static void *route_set_ecommunity_lb_compile(const char *arg
)
2914 struct rmap_ecomm_lb_set
*rels
;
2917 char bw_str
[40] = {0};
2919 bool non_trans
= false;
2922 p
= strchr(arg
, ' ');
2927 memcpy(bw_str
, arg
, len
);
2932 if (strcmp(str
, "cumulative") == 0)
2933 lb_type
= RMAP_ECOMM_LB_SET_CUMUL
;
2934 else if (strcmp(str
, "num-multipaths") == 0)
2935 lb_type
= RMAP_ECOMM_LB_SET_NUM_MPATH
;
2939 bw
= strtoul(str
, &end
, 10);
2942 lb_type
= RMAP_ECOMM_LB_SET_VALUE
;
2945 rels
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
2946 sizeof(struct rmap_ecomm_lb_set
));
2947 rels
->lb_type
= lb_type
;
2949 rels
->non_trans
= non_trans
;
2954 static void route_set_ecommunity_lb_free(void *rule
)
2956 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2959 /* Set community rule structure. */
2960 struct route_map_rule_cmd route_set_ecommunity_lb_cmd
= {
2961 "extcommunity bandwidth",
2962 route_set_ecommunity_lb
,
2963 route_set_ecommunity_lb_compile
,
2964 route_set_ecommunity_lb_free
,
2967 /* `set origin ORIGIN' */
2969 /* For origin set. */
2970 static enum route_map_cmd_result_t
2971 route_set_origin(void *rule
, const struct prefix
*prefix
, void *object
)
2974 struct bgp_path_info
*path
;
2979 path
->attr
->origin
= *origin
;
2984 /* Compile function for origin set. */
2985 static void *route_set_origin_compile(const char *arg
)
2989 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
2991 if (strcmp(arg
, "igp") == 0)
2993 else if (strcmp(arg
, "egp") == 0)
3001 /* Compile function for origin set. */
3002 static void route_set_origin_free(void *rule
)
3004 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3007 /* Set origin rule structure. */
3008 static const struct route_map_rule_cmd route_set_origin_cmd
= {
3011 route_set_origin_compile
,
3012 route_set_origin_free
,
3015 /* `set atomic-aggregate' */
3017 /* For atomic aggregate set. */
3018 static enum route_map_cmd_result_t
3019 route_set_atomic_aggregate(void *rule
, const struct prefix
*pfx
, void *object
)
3021 struct bgp_path_info
*path
;
3024 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE
);
3029 /* Compile function for atomic aggregate. */
3030 static void *route_set_atomic_aggregate_compile(const char *arg
)
3035 /* Compile function for atomic aggregate. */
3036 static void route_set_atomic_aggregate_free(void *rule
)
3041 /* Set atomic aggregate rule structure. */
3042 static const struct route_map_rule_cmd route_set_atomic_aggregate_cmd
= {
3044 route_set_atomic_aggregate
,
3045 route_set_atomic_aggregate_compile
,
3046 route_set_atomic_aggregate_free
,
3049 /* AIGP TLV Metric */
3050 static enum route_map_cmd_result_t
3051 route_set_aigp_metric(void *rule
, const struct prefix
*pfx
, void *object
)
3053 const char *aigp_metric
= rule
;
3054 struct bgp_path_info
*path
= object
;
3057 if (strmatch(aigp_metric
, "igp-metric")) {
3059 return RMAP_NOMATCH
;
3061 bgp_attr_set_aigp_metric(path
->attr
, path
->nexthop
->metric
);
3063 aigp
= atoi(aigp_metric
);
3064 bgp_attr_set_aigp_metric(path
->attr
, aigp
);
3067 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_AIGP
);
3072 static void *route_set_aigp_metric_compile(const char *arg
)
3074 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
3077 static void route_set_aigp_metric_free(void *rule
)
3079 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3082 static const struct route_map_rule_cmd route_set_aigp_metric_cmd
= {
3084 route_set_aigp_metric
,
3085 route_set_aigp_metric_compile
,
3086 route_set_aigp_metric_free
,
3089 /* `set aggregator as AS A.B.C.D' */
3092 struct in_addr address
;
3095 static enum route_map_cmd_result_t
3096 route_set_aggregator_as(void *rule
, const struct prefix
*prefix
, void *object
)
3098 struct bgp_path_info
*path
;
3099 struct aggregator
*aggregator
;
3104 path
->attr
->aggregator_as
= aggregator
->as
;
3105 path
->attr
->aggregator_addr
= aggregator
->address
;
3106 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR
);
3111 static void *route_set_aggregator_as_compile(const char *arg
)
3113 struct aggregator
*aggregator
;
3119 XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct aggregator
));
3120 if (sscanf(arg
, "%s %s", as
, address
) != 2) {
3121 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
3125 aggregator
->as
= strtoul(as
, NULL
, 10);
3126 ret
= inet_aton(address
, &aggregator
->address
);
3128 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
3134 static void route_set_aggregator_as_free(void *rule
)
3136 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3139 static const struct route_map_rule_cmd route_set_aggregator_as_cmd
= {
3141 route_set_aggregator_as
,
3142 route_set_aggregator_as_compile
,
3143 route_set_aggregator_as_free
,
3146 /* Set tag to object. object must be pointer to struct bgp_path_info */
3147 static enum route_map_cmd_result_t
3148 route_set_tag(void *rule
, const struct prefix
*prefix
, void *object
)
3151 struct bgp_path_info
*path
;
3157 path
->attr
->tag
= *tag
;
3162 /* Route map commands for tag set. */
3163 static const struct route_map_rule_cmd route_set_tag_cmd
= {
3166 route_map_rule_tag_compile
,
3167 route_map_rule_tag_free
,
3170 /* Set label-index to object. object must be pointer to struct bgp_path_info */
3171 static enum route_map_cmd_result_t
3172 route_set_label_index(void *rule
, const struct prefix
*prefix
, void *object
)
3174 struct rmap_value
*rv
;
3175 struct bgp_path_info
*path
;
3176 uint32_t label_index
;
3178 /* Fetch routemap's rule information. */
3182 /* Set label-index value. */
3183 label_index
= rv
->value
;
3185 path
->attr
->label_index
= label_index
;
3186 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID
);
3192 /* Route map commands for label-index set. */
3193 static const struct route_map_rule_cmd route_set_label_index_cmd
= {
3195 route_set_label_index
,
3196 route_value_compile
,
3200 /* `match ipv6 address IP_ACCESS_LIST' */
3202 static enum route_map_cmd_result_t
3203 route_match_ipv6_address(void *rule
, const struct prefix
*prefix
, void *object
)
3205 struct access_list
*alist
;
3207 if (prefix
->family
== AF_INET6
) {
3208 alist
= access_list_lookup(AFI_IP6
, (char *)rule
);
3210 return RMAP_NOMATCH
;
3212 return (access_list_apply(alist
, prefix
) == FILTER_DENY
3216 return RMAP_NOMATCH
;
3219 static void *route_match_ipv6_address_compile(const char *arg
)
3221 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
3224 static void route_match_ipv6_address_free(void *rule
)
3226 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3229 /* Route map commands for ip address matching. */
3230 static const struct route_map_rule_cmd route_match_ipv6_address_cmd
= {
3232 route_match_ipv6_address
,
3233 route_match_ipv6_address_compile
,
3234 route_match_ipv6_address_free
3237 /* `match ipv6 next-hop ACCESSLIST6_NAME' */
3238 static enum route_map_cmd_result_t
3239 route_match_ipv6_next_hop(void *rule
, const struct prefix
*prefix
, void *object
)
3241 struct bgp_path_info
*path
;
3242 struct access_list
*alist
;
3243 struct prefix_ipv6 p
;
3245 if (prefix
->family
== AF_INET6
) {
3247 p
.family
= AF_INET6
;
3248 p
.prefix
= path
->attr
->mp_nexthop_global
;
3249 p
.prefixlen
= IPV6_MAX_BITLEN
;
3251 alist
= access_list_lookup(AFI_IP6
, (char *)rule
);
3253 return RMAP_NOMATCH
;
3255 if (access_list_apply(alist
, &p
) == FILTER_PERMIT
)
3258 if (path
->attr
->mp_nexthop_len
3259 == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
) {
3260 p
.prefix
= path
->attr
->mp_nexthop_local
;
3261 if (access_list_apply(alist
, &p
) == FILTER_PERMIT
)
3266 return RMAP_NOMATCH
;
3269 static void *route_match_ipv6_next_hop_compile(const char *arg
)
3271 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
3274 static void route_match_ipv6_next_hop_free(void *rule
)
3276 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3279 static const struct route_map_rule_cmd route_match_ipv6_next_hop_cmd
= {
3281 route_match_ipv6_next_hop
,
3282 route_match_ipv6_next_hop_compile
,
3283 route_match_ipv6_next_hop_free
3286 /* `match ipv6 next-hop IP_ADDRESS' */
3288 static enum route_map_cmd_result_t
3289 route_match_ipv6_next_hop_address(void *rule
, const struct prefix
*prefix
,
3292 struct in6_addr
*addr
= rule
;
3293 struct bgp_path_info
*path
;
3297 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
))
3300 if (path
->attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
3301 && IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_local
, rule
))
3304 return RMAP_NOMATCH
;
3307 static void *route_match_ipv6_next_hop_address_compile(const char *arg
)
3309 struct in6_addr
*address
;
3312 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3314 ret
= inet_pton(AF_INET6
, arg
, address
);
3316 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3323 static void route_match_ipv6_next_hop_address_free(void *rule
)
3325 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3328 static const struct route_map_rule_cmd route_match_ipv6_next_hop_address_cmd
= {
3329 "ipv6 next-hop address",
3330 route_match_ipv6_next_hop_address
,
3331 route_match_ipv6_next_hop_address_compile
,
3332 route_match_ipv6_next_hop_address_free
3335 /* `match ip next-hop IP_ADDRESS' */
3337 static enum route_map_cmd_result_t
3338 route_match_ipv4_next_hop(void *rule
, const struct prefix
*prefix
, void *object
)
3340 struct in_addr
*addr
= rule
;
3341 struct bgp_path_info
*path
;
3345 if (path
->attr
->nexthop
.s_addr
== addr
->s_addr
3346 || (path
->attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV4
3347 && IPV4_ADDR_SAME(&path
->attr
->mp_nexthop_global_in
, addr
)))
3350 return RMAP_NOMATCH
;
3353 static void *route_match_ipv4_next_hop_compile(const char *arg
)
3355 struct in_addr
*address
;
3358 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3360 ret
= inet_pton(AF_INET
, arg
, address
);
3362 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3369 static void route_match_ipv4_next_hop_free(void *rule
)
3371 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3374 static const struct route_map_rule_cmd route_match_ipv4_next_hop_cmd
= {
3375 "ip next-hop address",
3376 route_match_ipv4_next_hop
,
3377 route_match_ipv4_next_hop_compile
,
3378 route_match_ipv4_next_hop_free
3381 /* `match ipv6 address prefix-list PREFIX_LIST' */
3383 static enum route_map_cmd_result_t
3384 route_match_ipv6_address_prefix_list(void *rule
, const struct prefix
*prefix
,
3387 return route_match_address_prefix_list(rule
, AFI_IP6
, prefix
, object
);
3390 static void *route_match_ipv6_address_prefix_list_compile(const char *arg
)
3392 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
3395 static void route_match_ipv6_address_prefix_list_free(void *rule
)
3397 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3400 static const struct route_map_rule_cmd
3401 route_match_ipv6_address_prefix_list_cmd
= {
3402 "ipv6 address prefix-list",
3403 route_match_ipv6_address_prefix_list
,
3404 route_match_ipv6_address_prefix_list_compile
,
3405 route_match_ipv6_address_prefix_list_free
3408 /* `match ipv6 next-hop type <TYPE>' */
3410 static enum route_map_cmd_result_t
3411 route_match_ipv6_next_hop_type(void *rule
, const struct prefix
*prefix
,
3414 struct bgp_path_info
*path
;
3415 struct in6_addr
*addr
= rule
;
3417 if (prefix
->family
== AF_INET6
) {
3418 path
= (struct bgp_path_info
*)object
;
3420 return RMAP_NOMATCH
;
3422 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
)
3423 && !path
->attr
->nh_ifindex
)
3427 return RMAP_NOMATCH
;
3430 static void *route_match_ipv6_next_hop_type_compile(const char *arg
)
3432 struct in6_addr
*address
;
3435 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3437 ret
= inet_pton(AF_INET6
, "::0", address
);
3439 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3446 static void route_match_ipv6_next_hop_type_free(void *rule
)
3448 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3451 static const struct route_map_rule_cmd
3452 route_match_ipv6_next_hop_type_cmd
= {
3453 "ipv6 next-hop type",
3454 route_match_ipv6_next_hop_type
,
3455 route_match_ipv6_next_hop_type_compile
,
3456 route_match_ipv6_next_hop_type_free
3459 /* `set ipv6 nexthop global IP_ADDRESS' */
3461 /* Set nexthop to object. object must be pointer to struct attr. */
3462 static enum route_map_cmd_result_t
3463 route_set_ipv6_nexthop_global(void *rule
, const struct prefix
*p
, void *object
)
3465 struct in6_addr
*address
;
3466 struct bgp_path_info
*path
;
3468 /* Fetch routemap's rule information. */
3472 /* Set next hop value. */
3473 path
->attr
->mp_nexthop_global
= *address
;
3475 /* Set nexthop length. */
3476 if (path
->attr
->mp_nexthop_len
== 0)
3477 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL
;
3479 SET_FLAG(path
->attr
->rmap_change_flags
,
3480 BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED
);
3485 /* Route map `ip next-hop' compile function. Given string is converted
3486 to struct in_addr structure. */
3487 static void *route_set_ipv6_nexthop_global_compile(const char *arg
)
3490 struct in6_addr
*address
;
3492 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3494 ret
= inet_pton(AF_INET6
, arg
, address
);
3497 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3504 /* Free route map's compiled `ip next-hop' value. */
3505 static void route_set_ipv6_nexthop_global_free(void *rule
)
3507 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3510 /* Route map commands for ip nexthop set. */
3511 static const struct route_map_rule_cmd
3512 route_set_ipv6_nexthop_global_cmd
= {
3513 "ipv6 next-hop global",
3514 route_set_ipv6_nexthop_global
,
3515 route_set_ipv6_nexthop_global_compile
,
3516 route_set_ipv6_nexthop_global_free
3519 /* Set next-hop preference value. */
3520 static enum route_map_cmd_result_t
3521 route_set_ipv6_nexthop_prefer_global(void *rule
, const struct prefix
*prefix
,
3524 struct bgp_path_info
*path
;
3527 /* Fetch routemap's rule information. */
3531 if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
3532 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
)) {
3533 /* Set next hop preference to global */
3534 path
->attr
->mp_nexthop_prefer_global
= true;
3535 SET_FLAG(path
->attr
->rmap_change_flags
,
3536 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
3538 path
->attr
->mp_nexthop_prefer_global
= false;
3539 SET_FLAG(path
->attr
->rmap_change_flags
,
3540 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
3546 static void *route_set_ipv6_nexthop_prefer_global_compile(const char *arg
)
3550 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
3556 /* Free route map's compiled `ip next-hop' value. */
3557 static void route_set_ipv6_nexthop_prefer_global_free(void *rule
)
3559 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3562 /* Route map commands for ip nexthop set preferred. */
3563 static const struct route_map_rule_cmd
3564 route_set_ipv6_nexthop_prefer_global_cmd
= {
3565 "ipv6 next-hop prefer-global",
3566 route_set_ipv6_nexthop_prefer_global
,
3567 route_set_ipv6_nexthop_prefer_global_compile
,
3568 route_set_ipv6_nexthop_prefer_global_free
3571 /* `set ipv6 nexthop local IP_ADDRESS' */
3573 /* Set nexthop to object. object must be pointer to struct attr. */
3574 static enum route_map_cmd_result_t
3575 route_set_ipv6_nexthop_local(void *rule
, const struct prefix
*p
, void *object
)
3577 struct in6_addr
*address
;
3578 struct bgp_path_info
*path
;
3580 /* Fetch routemap's rule information. */
3584 /* Set next hop value. */
3585 path
->attr
->mp_nexthop_local
= *address
;
3587 /* Set nexthop length. */
3588 if (path
->attr
->mp_nexthop_len
!= BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
&&
3589 path
->attr
->mp_nexthop_len
!= BGP_ATTR_NHLEN_VPNV6_GLOBAL_AND_LL
)
3590 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
3592 SET_FLAG(path
->attr
->rmap_change_flags
,
3593 BATTR_RMAP_IPV6_LL_NHOP_CHANGED
);
3598 /* Route map `ip nexthop' compile function. Given string is converted
3599 to struct in_addr structure. */
3600 static void *route_set_ipv6_nexthop_local_compile(const char *arg
)
3603 struct in6_addr
*address
;
3605 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3607 ret
= inet_pton(AF_INET6
, arg
, address
);
3610 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3617 /* Free route map's compiled `ip nexthop' value. */
3618 static void route_set_ipv6_nexthop_local_free(void *rule
)
3620 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3623 /* Route map commands for ip nexthop set. */
3624 static const struct route_map_rule_cmd
3625 route_set_ipv6_nexthop_local_cmd
= {
3626 "ipv6 next-hop local",
3627 route_set_ipv6_nexthop_local
,
3628 route_set_ipv6_nexthop_local_compile
,
3629 route_set_ipv6_nexthop_local_free
3632 /* `set ipv6 nexthop peer-address' */
3634 /* Set nexthop to object. object must be pointer to struct attr. */
3635 static enum route_map_cmd_result_t
3636 route_set_ipv6_nexthop_peer(void *rule
, const struct prefix
*pfx
, void *object
)
3638 struct in6_addr peer_address
;
3639 struct bgp_path_info
*path
;
3642 /* Fetch routemap's rule information. */
3646 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
3647 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
3649 && sockunion_family(peer
->su_remote
) == AF_INET6
) {
3650 peer_address
= peer
->su_remote
->sin6
.sin6_addr
;
3651 /* Set next hop value and length in attribute. */
3652 if (IN6_IS_ADDR_LINKLOCAL(&peer_address
)) {
3653 path
->attr
->mp_nexthop_local
= peer_address
;
3654 if (path
->attr
->mp_nexthop_len
3655 != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
3656 path
->attr
->mp_nexthop_len
=
3657 BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
3659 path
->attr
->mp_nexthop_global
= peer_address
;
3660 if (path
->attr
->mp_nexthop_len
== 0)
3661 path
->attr
->mp_nexthop_len
=
3662 BGP_ATTR_NHLEN_IPV6_GLOBAL
;
3665 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
3666 /* The next hop value will be set as part of packet
3668 * Set the flags here to indicate that rewrite needs to
3670 * Also, clear the value - we clear both global and
3672 * nexthops, whether we send one or both is determined
3675 SET_FLAG(path
->attr
->rmap_change_flags
,
3676 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
3677 /* clear next hop value. */
3678 memset(&(path
->attr
->mp_nexthop_global
), 0,
3679 sizeof(struct in6_addr
));
3680 memset(&(path
->attr
->mp_nexthop_local
), 0,
3681 sizeof(struct in6_addr
));
3687 /* Route map `ip next-hop' compile function. Given string is converted
3688 to struct in_addr structure. */
3689 static void *route_set_ipv6_nexthop_peer_compile(const char *arg
)
3693 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
3699 /* Free route map's compiled `ip next-hop' value. */
3700 static void route_set_ipv6_nexthop_peer_free(void *rule
)
3702 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3705 /* Route map commands for ip nexthop set. */
3706 static const struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd
= {
3707 "ipv6 next-hop peer-address",
3708 route_set_ipv6_nexthop_peer
,
3709 route_set_ipv6_nexthop_peer_compile
,
3710 route_set_ipv6_nexthop_peer_free
3713 /* `set ipv4 vpn next-hop A.B.C.D' */
3715 static enum route_map_cmd_result_t
3716 route_set_vpnv4_nexthop(void *rule
, const struct prefix
*prefix
, void *object
)
3718 struct in_addr
*address
;
3719 struct bgp_path_info
*path
;
3721 /* Fetch routemap's rule information. */
3725 /* Set next hop value. */
3726 path
->attr
->mp_nexthop_global_in
= *address
;
3727 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV4
;
3729 SET_FLAG(path
->attr
->rmap_change_flags
, BATTR_RMAP_VPNV4_NHOP_CHANGED
);
3734 static void *route_set_vpnv4_nexthop_compile(const char *arg
)
3737 struct in_addr
*address
;
3739 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3741 ret
= inet_aton(arg
, address
);
3744 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3751 /* `set ipv6 vpn next-hop A.B.C.D' */
3753 static enum route_map_cmd_result_t
3754 route_set_vpnv6_nexthop(void *rule
, const struct prefix
*prefix
, void *object
)
3756 struct in6_addr
*address
;
3757 struct bgp_path_info
*path
;
3759 /* Fetch routemap's rule information. */
3763 /* Set next hop value. */
3764 memcpy(&path
->attr
->mp_nexthop_global
, address
,
3765 sizeof(struct in6_addr
));
3766 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_VPNV6_GLOBAL
;
3768 SET_FLAG(path
->attr
->rmap_change_flags
,
3769 BATTR_RMAP_VPNV6_GLOBAL_NHOP_CHANGED
);
3774 static void *route_set_vpnv6_nexthop_compile(const char *arg
)
3777 struct in6_addr
*address
;
3779 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3780 ret
= inet_pton(AF_INET6
, arg
, address
);
3783 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3790 static void route_set_vpn_nexthop_free(void *rule
)
3792 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3795 /* Route map commands for ipv4 next-hop set. */
3796 static const struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd
= {
3797 "ipv4 vpn next-hop",
3798 route_set_vpnv4_nexthop
,
3799 route_set_vpnv4_nexthop_compile
,
3800 route_set_vpn_nexthop_free
3803 /* Route map commands for ipv6 next-hop set. */
3804 static const struct route_map_rule_cmd route_set_vpnv6_nexthop_cmd
= {
3805 "ipv6 vpn next-hop",
3806 route_set_vpnv6_nexthop
,
3807 route_set_vpnv6_nexthop_compile
,
3808 route_set_vpn_nexthop_free
3811 /* `set originator-id' */
3813 /* For origin set. */
3814 static enum route_map_cmd_result_t
3815 route_set_originator_id(void *rule
, const struct prefix
*prefix
, void *object
)
3817 struct in_addr
*address
;
3818 struct bgp_path_info
*path
;
3823 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
);
3824 path
->attr
->originator_id
= *address
;
3829 /* Compile function for originator-id set. */
3830 static void *route_set_originator_id_compile(const char *arg
)
3833 struct in_addr
*address
;
3835 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3837 ret
= inet_aton(arg
, address
);
3840 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3847 /* Compile function for originator_id set. */
3848 static void route_set_originator_id_free(void *rule
)
3850 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3853 /* Set originator-id rule structure. */
3854 static const struct route_map_rule_cmd route_set_originator_id_cmd
= {
3856 route_set_originator_id
,
3857 route_set_originator_id_compile
,
3858 route_set_originator_id_free
,
3861 static enum route_map_cmd_result_t
3862 route_match_rpki_extcommunity(void *rule
, const struct prefix
*prefix
,
3865 struct bgp_path_info
*path
;
3866 struct ecommunity
*ecomm
;
3867 struct ecommunity_val
*ecomm_val
;
3868 enum rpki_states
*rpki_status
= rule
;
3869 enum rpki_states ecomm_rpki_status
= RPKI_NOT_BEING_USED
;
3873 ecomm
= bgp_attr_get_ecommunity(path
->attr
);
3875 return RMAP_NOMATCH
;
3877 ecomm_val
= ecommunity_lookup(ecomm
, ECOMMUNITY_ENCODE_OPAQUE_NON_TRANS
,
3878 ECOMMUNITY_ORIGIN_VALIDATION_STATE
);
3880 return RMAP_NOMATCH
;
3882 /* The Origin Validation State is encoded in the last octet of
3883 * the extended community.
3885 switch (ecomm_val
->val
[7]) {
3886 case ECOMMUNITY_ORIGIN_VALIDATION_STATE_VALID
:
3887 ecomm_rpki_status
= RPKI_VALID
;
3889 case ECOMMUNITY_ORIGIN_VALIDATION_STATE_NOTFOUND
:
3890 ecomm_rpki_status
= RPKI_NOTFOUND
;
3892 case ECOMMUNITY_ORIGIN_VALIDATION_STATE_INVALID
:
3893 ecomm_rpki_status
= RPKI_INVALID
;
3895 case ECOMMUNITY_ORIGIN_VALIDATION_STATE_NOTUSED
:
3899 if (ecomm_rpki_status
== *rpki_status
)
3902 return RMAP_NOMATCH
;
3905 static void *route_match_extcommunity_compile(const char *arg
)
3909 rpki_status
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
3911 if (strcmp(arg
, "valid") == 0)
3912 *rpki_status
= RPKI_VALID
;
3913 else if (strcmp(arg
, "invalid") == 0)
3914 *rpki_status
= RPKI_INVALID
;
3916 *rpki_status
= RPKI_NOTFOUND
;
3921 static const struct route_map_rule_cmd route_match_rpki_extcommunity_cmd
= {
3922 "rpki-extcommunity",
3923 route_match_rpki_extcommunity
,
3924 route_match_extcommunity_compile
,
3929 * This is the workhorse routine for processing in/out routemap
3932 static void bgp_route_map_process_peer(const char *rmap_name
,
3933 struct route_map
*map
, struct peer
*peer
,
3934 int afi
, int safi
, int route_update
)
3936 struct bgp_filter
*filter
;
3938 if (!peer
|| !rmap_name
)
3941 filter
= &peer
->filter
[afi
][safi
];
3943 * in is for non-route-server clients,
3944 * out is for all peers
3946 if (filter
->map
[RMAP_IN
].name
3947 && (strcmp(rmap_name
, filter
->map
[RMAP_IN
].name
) == 0)) {
3948 filter
->map
[RMAP_IN
].map
= map
;
3950 if (route_update
&& peer_established(peer
)) {
3951 if (CHECK_FLAG(peer
->af_flags
[afi
][safi
],
3952 PEER_FLAG_SOFT_RECONFIG
)) {
3953 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3955 "Processing route_map %s(%s:%s) update on peer %s (inbound, soft-reconfig)",
3956 rmap_name
, afi2str(afi
),
3957 safi2str(safi
), peer
->host
);
3959 bgp_soft_reconfig_in(peer
, afi
, safi
);
3960 } else if (CHECK_FLAG(peer
->cap
,
3961 PEER_CAP_REFRESH_OLD_RCV
)
3962 || CHECK_FLAG(peer
->cap
,
3963 PEER_CAP_REFRESH_NEW_RCV
)) {
3964 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3966 "Processing route_map %s(%s:%s) update on peer %s (inbound, route-refresh)",
3967 rmap_name
, afi2str(afi
),
3968 safi2str(safi
), peer
->host
);
3969 bgp_route_refresh_send(
3970 peer
, afi
, safi
, 0, 0, 0,
3971 BGP_ROUTE_REFRESH_NORMAL
);
3977 * For outbound, unsuppress and default-originate map change (content or
3978 * map created), merely update the "config" here, the actual route
3979 * announcement happens at the group level.
3981 if (filter
->map
[RMAP_OUT
].name
3982 && (strcmp(rmap_name
, filter
->map
[RMAP_OUT
].name
) == 0))
3983 filter
->map
[RMAP_OUT
].map
= map
;
3985 if (filter
->usmap
.name
&& (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3986 filter
->usmap
.map
= map
;
3988 if (filter
->advmap
.aname
3989 && (strcmp(rmap_name
, filter
->advmap
.aname
) == 0)) {
3990 filter
->advmap
.amap
= map
;
3993 if (filter
->advmap
.cname
3994 && (strcmp(rmap_name
, filter
->advmap
.cname
) == 0)) {
3995 filter
->advmap
.cmap
= map
;
3998 if (peer
->default_rmap
[afi
][safi
].name
3999 && (strcmp(rmap_name
, peer
->default_rmap
[afi
][safi
].name
) == 0))
4000 peer
->default_rmap
[afi
][safi
].map
= map
;
4002 /* Notify BGP conditional advertisement scanner percess */
4003 peer
->advmap_config_change
[afi
][safi
] = true;
4006 static void bgp_route_map_update_peer_group(const char *rmap_name
,
4007 struct route_map
*map
,
4010 struct peer_group
*group
;
4011 struct listnode
*node
, *nnode
;
4012 struct bgp_filter
*filter
;
4019 /* All the peers have been updated correctly already. This is
4020 * just updating the placeholder data. No real update required.
4022 for (ALL_LIST_ELEMENTS(bgp
->group
, node
, nnode
, group
)) {
4023 FOREACH_AFI_SAFI (afi
, safi
) {
4024 filter
= &group
->conf
->filter
[afi
][safi
];
4026 for (direct
= RMAP_IN
; direct
< RMAP_MAX
; direct
++) {
4027 if ((filter
->map
[direct
].name
)
4028 && (strcmp(rmap_name
,
4029 filter
->map
[direct
].name
)
4031 filter
->map
[direct
].map
= map
;
4034 if (filter
->usmap
.name
4035 && (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
4036 filter
->usmap
.map
= map
;
4038 if (filter
->advmap
.aname
&&
4039 (strcmp(rmap_name
, filter
->advmap
.aname
) == 0))
4040 filter
->advmap
.amap
= map
;
4042 if (filter
->advmap
.cname
&&
4043 (strcmp(rmap_name
, filter
->advmap
.cname
) == 0))
4044 filter
->advmap
.cmap
= map
;
4050 * Note that if an extreme number (tens of thousands) of route-maps are in use
4051 * and if bgp has an extreme number of peers, network statements, etc then this
4052 * function can consume a lot of cycles. This is due to this function being
4053 * called for each route-map and within this function we walk the list of peers,
4054 * network statements, etc looking to see if they use this route-map.
4056 static void bgp_route_map_process_update(struct bgp
*bgp
, const char *rmap_name
,
4064 struct bgp_dest
*bn
;
4065 struct bgp_static
*bgp_static
;
4066 struct bgp_aggregate
*aggregate
;
4067 struct listnode
*node
, *nnode
;
4068 struct route_map
*map
;
4069 char buf
[INET6_ADDRSTRLEN
];
4071 map
= route_map_lookup_by_name(rmap_name
);
4073 for (ALL_LIST_ELEMENTS(bgp
->peer
, node
, nnode
, peer
)) {
4075 /* Ignore dummy peer-group structure */
4076 if (CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
))
4079 FOREACH_AFI_SAFI (afi
, safi
) {
4080 /* process in/out/import/export/default-orig
4082 bgp_route_map_process_peer(rmap_name
, map
, peer
, afi
,
4083 safi
, route_update
);
4087 /* for outbound/default-orig route-maps, process for groups */
4088 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
, rmap_name
,
4091 /* update peer-group config (template) */
4092 bgp_route_map_update_peer_group(rmap_name
, map
, bgp
);
4094 FOREACH_AFI_SAFI (afi
, safi
) {
4095 /* For table route-map updates. */
4096 if (!bgp_fibupd_safi(safi
))
4099 if (bgp
->table_map
[afi
][safi
].name
4100 && (strcmp(rmap_name
, bgp
->table_map
[afi
][safi
].name
)
4103 /* bgp->table_map[afi][safi].map is NULL.
4104 * i.e Route map creation event.
4105 * So update applied_counter.
4106 * If it is not NULL, i.e It may be routemap updation or
4107 * deletion. so no need to update the counter.
4109 if (!bgp
->table_map
[afi
][safi
].map
)
4110 route_map_counter_increment(map
);
4111 bgp
->table_map
[afi
][safi
].map
= map
;
4113 if (BGP_DEBUG(zebra
, ZEBRA
))
4115 "Processing route_map %s(%s:%s) update on table map",
4116 rmap_name
, afi2str(afi
),
4119 bgp_zebra_announce_table(bgp
, afi
, safi
);
4122 /* For network route-map updates. */
4123 for (bn
= bgp_table_top(bgp
->route
[afi
][safi
]); bn
;
4124 bn
= bgp_route_next(bn
)) {
4125 bgp_static
= bgp_dest_get_bgp_static_info(bn
);
4129 if (!bgp_static
->rmap
.name
4130 || (strcmp(rmap_name
, bgp_static
->rmap
.name
) != 0))
4133 if (!bgp_static
->rmap
.map
)
4134 route_map_counter_increment(map
);
4136 bgp_static
->rmap
.map
= map
;
4138 if (route_update
&& !bgp_static
->backdoor
) {
4139 const struct prefix
*bn_p
=
4140 bgp_dest_get_prefix(bn
);
4142 if (bgp_debug_zebra(bn_p
))
4144 "Processing route_map %s(%s:%s) update on static route %s",
4145 rmap_name
, afi2str(afi
),
4147 inet_ntop(bn_p
->family
,
4148 &bn_p
->u
.prefix
, buf
,
4150 bgp_static_update(bgp
, bn_p
, bgp_static
, afi
,
4155 /* For aggregate-address route-map updates. */
4156 for (bn
= bgp_table_top(bgp
->aggregate
[afi
][safi
]); bn
;
4157 bn
= bgp_route_next(bn
)) {
4158 aggregate
= bgp_dest_get_bgp_aggregate_info(bn
);
4164 /* Update suppress map pointer. */
4165 if (aggregate
->suppress_map_name
4166 && strmatch(aggregate
->suppress_map_name
,
4168 if (aggregate
->rmap
.map
== NULL
)
4169 route_map_counter_increment(map
);
4171 aggregate
->suppress_map
= map
;
4173 bgp_aggregate_toggle_suppressed(
4174 aggregate
, bgp
, bgp_dest_get_prefix(bn
),
4180 if (aggregate
->rmap
.name
4181 && strmatch(rmap_name
, aggregate
->rmap
.name
)) {
4182 if (aggregate
->rmap
.map
== NULL
)
4183 route_map_counter_increment(map
);
4185 aggregate
->rmap
.map
= map
;
4190 if (matched
&& route_update
) {
4191 const struct prefix
*bn_p
=
4192 bgp_dest_get_prefix(bn
);
4194 if (bgp_debug_zebra(bn_p
))
4196 "Processing route_map %s(%s:%s) update on aggregate-address route %s",
4197 rmap_name
, afi2str(afi
),
4199 inet_ntop(bn_p
->family
,
4200 &bn_p
->u
.prefix
, buf
,
4202 bgp_aggregate_route(bgp
, bn_p
, afi
, safi
,
4208 /* For redistribute route-map updates. */
4209 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
4210 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
4211 struct list
*red_list
;
4212 struct bgp_redist
*red
;
4214 red_list
= bgp
->redist
[afi
][i
];
4218 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
4220 || (strcmp(rmap_name
, red
->rmap
.name
) != 0))
4224 route_map_counter_increment(map
);
4226 red
->rmap
.map
= map
;
4231 if (BGP_DEBUG(zebra
, ZEBRA
))
4233 "Processing route_map %s(%s:%s) update on redistributed routes",
4234 rmap_name
, afi2str(afi
),
4237 bgp_redistribute_resend(bgp
, afi
, i
,
4242 /* for type5 command route-maps */
4243 FOREACH_AFI_SAFI (afi
, safi
) {
4244 if (!bgp
->adv_cmd_rmap
[afi
][safi
].name
4245 || strcmp(rmap_name
, bgp
->adv_cmd_rmap
[afi
][safi
].name
)
4249 /* Make sure the route-map is populated here if not already done */
4250 bgp
->adv_cmd_rmap
[afi
][safi
].map
= map
;
4252 if (BGP_DEBUG(zebra
, ZEBRA
))
4254 "Processing route_map %s(%s:%s) update on advertise type5 route command",
4255 rmap_name
, afi2str(afi
), safi2str(safi
));
4257 if (route_update
&& advertise_type5_routes(bgp
, afi
)) {
4258 bgp_evpn_withdraw_type5_routes(bgp
, afi
, safi
);
4259 bgp_evpn_advertise_type5_routes(bgp
, afi
, safi
);
4264 static void bgp_route_map_process_update_cb(char *rmap_name
)
4266 struct listnode
*node
, *nnode
;
4269 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
)) {
4270 bgp_route_map_process_update(bgp
, rmap_name
, true);
4272 #ifdef ENABLE_BGP_VNC
4273 vnc_routemap_update(bgp
, __func__
);
4277 vpn_policy_routemap_event(rmap_name
);
4280 void bgp_route_map_update_timer(struct thread
*thread
)
4282 route_map_walk_update_list(bgp_route_map_process_update_cb
);
4285 static void bgp_route_map_mark_update(const char *rmap_name
)
4287 struct listnode
*node
, *nnode
;
4290 /* If new update is received before the current timer timed out,
4291 * turn it off and start a new timer.
4293 THREAD_OFF(bm
->t_rmap_update
);
4295 /* rmap_update_timer of 0 means don't do route updates */
4296 if (bm
->rmap_update_timer
) {
4297 thread_add_timer(bm
->master
, bgp_route_map_update_timer
,
4298 NULL
, bm
->rmap_update_timer
,
4299 &bm
->t_rmap_update
);
4301 /* Signal the groups that a route-map update event has
4303 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
4304 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
,
4305 rmap_name
, true, 1);
4307 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
)) {
4308 bgp_route_map_process_update(bgp
, rmap_name
, false);
4309 #ifdef ENABLE_BGP_VNC
4310 vnc_routemap_update(bgp
, __func__
);
4314 vpn_policy_routemap_event(rmap_name
);
4318 static void bgp_route_map_add(const char *rmap_name
)
4320 if (route_map_mark_updated(rmap_name
) == 0)
4321 bgp_route_map_mark_update(rmap_name
);
4323 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
4326 static void bgp_route_map_delete(const char *rmap_name
)
4328 if (route_map_mark_updated(rmap_name
) == 0)
4329 bgp_route_map_mark_update(rmap_name
);
4331 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_DELETED
);
4334 static void bgp_route_map_event(const char *rmap_name
)
4336 if (route_map_mark_updated(rmap_name
) == 0)
4337 bgp_route_map_mark_update(rmap_name
);
4339 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
4342 DEFUN_YANG (match_mac_address
,
4343 match_mac_address_cmd
,
4344 "match mac address ACCESSLIST_MAC_NAME",
4347 "Match address of route\n"
4348 "MAC Access-list name\n")
4351 "./match-condition[condition='frr-bgp-route-map:mac-address-list']";
4352 char xpath_value
[XPATH_MAXLEN
];
4354 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4355 snprintf(xpath_value
, sizeof(xpath_value
),
4356 "%s/rmap-match-condition/frr-bgp-route-map:list-name", xpath
);
4357 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[3]->arg
);
4359 return nb_cli_apply_changes(vty
, NULL
);
4362 DEFUN_YANG (no_match_mac_address
,
4363 no_match_mac_address_cmd
,
4364 "no match mac address ACCESSLIST_MAC_NAME",
4368 "Match address of route\n"
4369 "MAC acess-list name\n")
4372 "./match-condition[condition='frr-bgp-route-map:mac-address-list']";
4374 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4375 return nb_cli_apply_changes(vty
, NULL
);
4379 * Helper to handle the case of the user passing in a number or type string
4381 static const char *parse_evpn_rt_type(const char *num_rt_type
)
4383 switch (num_rt_type
[0]) {
4398 /* Was already full type string */
4402 DEFUN_YANG (match_evpn_route_type
,
4403 match_evpn_route_type_cmd
,
4404 "match evpn route-type <ead|1|macip|2|multicast|3|es|4|prefix|5>",
4408 EVPN_TYPE_1_HELP_STR
4409 EVPN_TYPE_1_HELP_STR
4410 EVPN_TYPE_2_HELP_STR
4411 EVPN_TYPE_2_HELP_STR
4412 EVPN_TYPE_3_HELP_STR
4413 EVPN_TYPE_3_HELP_STR
4414 EVPN_TYPE_4_HELP_STR
4415 EVPN_TYPE_4_HELP_STR
4416 EVPN_TYPE_5_HELP_STR
4417 EVPN_TYPE_5_HELP_STR
)
4420 "./match-condition[condition='frr-bgp-route-map:evpn-route-type']";
4421 char xpath_value
[XPATH_MAXLEN
];
4423 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4424 snprintf(xpath_value
, sizeof(xpath_value
),
4425 "%s/rmap-match-condition/frr-bgp-route-map:evpn-route-type",
4427 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4428 parse_evpn_rt_type(argv
[3]->arg
));
4430 return nb_cli_apply_changes(vty
, NULL
);
4433 DEFUN_YANG (no_match_evpn_route_type
,
4434 no_match_evpn_route_type_cmd
,
4435 "no match evpn route-type <ead|1|macip|2|multicast|3|es|4|prefix|5>",
4440 EVPN_TYPE_1_HELP_STR
4441 EVPN_TYPE_1_HELP_STR
4442 EVPN_TYPE_2_HELP_STR
4443 EVPN_TYPE_2_HELP_STR
4444 EVPN_TYPE_3_HELP_STR
4445 EVPN_TYPE_3_HELP_STR
4446 EVPN_TYPE_4_HELP_STR
4447 EVPN_TYPE_4_HELP_STR
4448 EVPN_TYPE_5_HELP_STR
4449 EVPN_TYPE_5_HELP_STR
)
4452 "./match-condition[condition='frr-bgp-route-map:evpn-route-type']";
4454 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4456 return nb_cli_apply_changes(vty
, NULL
);
4460 DEFUN_YANG (match_evpn_vni
,
4462 "match evpn vni " CMD_VNI_RANGE
,
4469 "./match-condition[condition='frr-bgp-route-map:evpn-vni']";
4470 char xpath_value
[XPATH_MAXLEN
];
4472 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4473 snprintf(xpath_value
, sizeof(xpath_value
),
4474 "%s/rmap-match-condition/frr-bgp-route-map:evpn-vni", xpath
);
4475 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[3]->arg
);
4477 return nb_cli_apply_changes(vty
, NULL
);
4480 DEFUN_YANG (no_match_evpn_vni
,
4481 no_match_evpn_vni_cmd
,
4482 "no match evpn vni " CMD_VNI_RANGE
,
4490 "./match-condition[condition='frr-bgp-route-map:evpn-vni']";
4491 char xpath_value
[XPATH_MAXLEN
];
4493 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4494 snprintf(xpath_value
, sizeof(xpath_value
),
4495 "%s/rmap-match-condition/frr-bgp-route-map:evpn-vni", xpath
);
4496 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_DESTROY
, argv
[3]->arg
);
4498 return nb_cli_apply_changes(vty
, NULL
);
4501 DEFUN_YANG (match_evpn_default_route
,
4502 match_evpn_default_route_cmd
,
4503 "match evpn default-route",
4506 "default EVPN type-5 route\n")
4509 "./match-condition[condition='frr-bgp-route-map:evpn-default-route']";
4510 char xpath_value
[XPATH_MAXLEN
];
4512 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4514 snprintf(xpath_value
, sizeof(xpath_value
),
4515 "%s/rmap-match-condition/frr-bgp-route-map:evpn-default-route",
4517 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, NULL
);
4519 return nb_cli_apply_changes(vty
, NULL
);
4522 DEFUN_YANG (no_match_evpn_default_route
,
4523 no_match_evpn_default_route_cmd
,
4524 "no match evpn default-route",
4528 "default EVPN type-5 route\n")
4531 "./match-condition[condition='frr-bgp-route-map:evpn-default-route']";
4533 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4535 return nb_cli_apply_changes(vty
, NULL
);
4538 DEFUN_YANG (match_evpn_rd
,
4540 "match evpn rd ASN:NN_OR_IP-ADDRESS:NN",
4543 "Route Distinguisher\n"
4544 "ASN:XX or A.B.C.D:XX\n")
4547 "./match-condition[condition='frr-bgp-route-map:evpn-rd']";
4548 char xpath_value
[XPATH_MAXLEN
];
4550 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4552 xpath_value
, sizeof(xpath_value
),
4553 "%s/rmap-match-condition/frr-bgp-route-map:route-distinguisher",
4555 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[3]->arg
);
4557 return nb_cli_apply_changes(vty
, NULL
);
4560 DEFUN_YANG (no_match_evpn_rd
,
4561 no_match_evpn_rd_cmd
,
4562 "no match evpn rd ASN:NN_OR_IP-ADDRESS:NN",
4566 "Route Distinguisher\n"
4567 "ASN:XX or A.B.C.D:XX\n")
4570 "./match-condition[condition='frr-bgp-route-map:evpn-rd']";
4572 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4573 return nb_cli_apply_changes(vty
, NULL
);
4576 DEFUN_YANG (set_evpn_gw_ip_ipv4
,
4577 set_evpn_gw_ip_ipv4_cmd
,
4578 "set evpn gateway-ip ipv4 A.B.C.D",
4581 "Set gateway IP for prefix advertisement route\n"
4583 "Gateway IP address in IPv4 format\n")
4588 "./set-action[action='frr-bgp-route-map:set-evpn-gateway-ip-ipv4']";
4589 char xpath_value
[XPATH_MAXLEN
];
4591 ret
= str2sockunion(argv
[4]->arg
, &su
);
4593 vty_out(vty
, "%% Malformed gateway IP\n");
4594 return CMD_WARNING_CONFIG_FAILED
;
4597 if (su
.sin
.sin_addr
.s_addr
== 0 ||
4598 !ipv4_unicast_valid(&su
.sin
.sin_addr
)) {
4600 "%% Gateway IP cannot be 0.0.0.0, multicast or reserved\n");
4601 return CMD_WARNING_CONFIG_FAILED
;
4604 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4606 snprintf(xpath_value
, sizeof(xpath_value
),
4607 "%s/rmap-set-action/frr-bgp-route-map:evpn-gateway-ip-ipv4",
4610 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[4]->arg
);
4611 return nb_cli_apply_changes(vty
, NULL
);
4614 DEFUN_YANG (no_set_evpn_gw_ip_ipv4
,
4615 no_set_evpn_gw_ip_ipv4_cmd
,
4616 "no set evpn gateway-ip ipv4 A.B.C.D",
4620 "Set gateway IP for prefix advertisement route\n"
4622 "Gateway IP address in IPv4 format\n")
4627 "./set-action[action='frr-bgp-route-map:set-evpn-gateway-ip-ipv4']";
4629 ret
= str2sockunion(argv
[5]->arg
, &su
);
4631 vty_out(vty
, "%% Malformed gateway IP\n");
4632 return CMD_WARNING_CONFIG_FAILED
;
4635 if (su
.sin
.sin_addr
.s_addr
== 0 ||
4636 !ipv4_unicast_valid(&su
.sin
.sin_addr
)) {
4638 "%% Gateway IP cannot be 0.0.0.0, multicast or reserved\n");
4639 return CMD_WARNING_CONFIG_FAILED
;
4642 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4644 return nb_cli_apply_changes(vty
, NULL
);
4647 DEFUN_YANG (set_evpn_gw_ip_ipv6
,
4648 set_evpn_gw_ip_ipv6_cmd
,
4649 "set evpn gateway-ip ipv6 X:X::X:X",
4652 "Set gateway IP for prefix advertisement route\n"
4654 "Gateway IP address in IPv6 format\n")
4659 "./set-action[action='frr-bgp-route-map:set-evpn-gateway-ip-ipv6']";
4660 char xpath_value
[XPATH_MAXLEN
];
4662 ret
= str2sockunion(argv
[4]->arg
, &su
);
4664 vty_out(vty
, "%% Malformed gateway IP\n");
4665 return CMD_WARNING_CONFIG_FAILED
;
4668 if (IN6_IS_ADDR_LINKLOCAL(&su
.sin6
.sin6_addr
)
4669 || IN6_IS_ADDR_MULTICAST(&su
.sin6
.sin6_addr
)) {
4671 "%% Gateway IP cannot be a linklocal or multicast address\n");
4672 return CMD_WARNING_CONFIG_FAILED
;
4675 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4677 snprintf(xpath_value
, sizeof(xpath_value
),
4678 "%s/rmap-set-action/frr-bgp-route-map:evpn-gateway-ip-ipv6",
4681 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[4]->arg
);
4682 return nb_cli_apply_changes(vty
, NULL
);
4685 DEFUN_YANG (no_set_evpn_gw_ip_ipv6
,
4686 no_set_evpn_gw_ip_ipv6_cmd
,
4687 "no set evpn gateway-ip ipv6 X:X::X:X",
4691 "Set gateway IP for prefix advertisement route\n"
4693 "Gateway IP address in IPv4 format\n")
4698 "./set-action[action='frr-bgp-route-map:set-evpn-gateway-ip-ipv6']";
4700 ret
= str2sockunion(argv
[5]->arg
, &su
);
4702 vty_out(vty
, "%% Malformed gateway IP\n");
4703 return CMD_WARNING_CONFIG_FAILED
;
4706 if (IN6_IS_ADDR_LINKLOCAL(&su
.sin6
.sin6_addr
)
4707 || IN6_IS_ADDR_MULTICAST(&su
.sin6
.sin6_addr
)) {
4709 "%% Gateway IP cannot be a linklocal or multicast address\n");
4710 return CMD_WARNING_CONFIG_FAILED
;
4713 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4715 return nb_cli_apply_changes(vty
, NULL
);
4718 DEFPY_YANG(match_vrl_source_vrf
,
4719 match_vrl_source_vrf_cmd
,
4720 "match source-vrf NAME$vrf_name",
4726 "./match-condition[condition='frr-bgp-route-map:source-vrf']";
4727 char xpath_value
[XPATH_MAXLEN
];
4729 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4730 snprintf(xpath_value
, sizeof(xpath_value
),
4731 "%s/rmap-match-condition/frr-bgp-route-map:source-vrf", xpath
);
4732 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, vrf_name
);
4734 return nb_cli_apply_changes(vty
, NULL
);
4737 DEFPY_YANG(no_match_vrl_source_vrf
,
4738 no_match_vrl_source_vrf_cmd
,
4739 "no match source-vrf NAME$vrf_name",
4745 "./match-condition[condition='frr-bgp-route-map:source-vrf']";
4747 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4748 return nb_cli_apply_changes(vty
, NULL
);
4751 DEFPY_YANG (match_peer
,
4753 "match peer <A.B.C.D$addrv4|X:X::X:X$addrv6|WORD$intf>",
4755 "Match peer address\n"
4756 "IP address of peer\n"
4757 "IPv6 address of peer\n"
4758 "Interface name of peer or peer group name\n")
4761 "./match-condition[condition='frr-bgp-route-map:peer']";
4762 char xpath_value
[XPATH_MAXLEN
];
4764 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4768 xpath_value
, sizeof(xpath_value
),
4769 "%s/rmap-match-condition/frr-bgp-route-map:peer-ipv4-address",
4771 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4773 } else if (addrv6_str
) {
4775 xpath_value
, sizeof(xpath_value
),
4776 "%s/rmap-match-condition/frr-bgp-route-map:peer-ipv6-address",
4778 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4782 xpath_value
, sizeof(xpath_value
),
4783 "%s/rmap-match-condition/frr-bgp-route-map:peer-interface",
4785 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, intf
);
4788 return nb_cli_apply_changes(vty
, NULL
);
4791 DEFUN_YANG (match_peer_local
,
4792 match_peer_local_cmd
,
4795 "Match peer address\n"
4796 "Static or Redistributed routes\n")
4799 "./match-condition[condition='frr-bgp-route-map:peer']";
4800 char xpath_value
[XPATH_MAXLEN
];
4802 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4804 snprintf(xpath_value
, sizeof(xpath_value
),
4805 "%s/rmap-match-condition/frr-bgp-route-map:peer-local", xpath
);
4806 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
4808 return nb_cli_apply_changes(vty
, NULL
);
4811 DEFUN_YANG (no_match_peer
,
4813 "no match peer [<local|A.B.C.D|X:X::X:X|WORD>]",
4816 "Match peer address\n"
4817 "Static or Redistributed routes\n"
4818 "IP address of peer\n"
4819 "IPv6 address of peer\n"
4820 "Interface name of peer\n")
4823 "./match-condition[condition='frr-bgp-route-map:peer']";
4825 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4827 return nb_cli_apply_changes(vty
, NULL
);
4830 #ifdef HAVE_SCRIPTING
4831 DEFUN_YANG (match_script
,
4833 "[no] match script WORD",
4836 "Execute script to determine match\n"
4837 "The script name to run, without .lua; e.g. 'myroutemap' to run myroutemap.lua\n")
4839 bool no
= strmatch(argv
[0]->text
, "no");
4841 argv_find(argv
, argc
, "WORD", &i
);
4842 const char *script
= argv
[i
]->arg
;
4844 "./match-condition[condition='frr-bgp-route-map:match-script']";
4845 char xpath_value
[XPATH_MAXLEN
];
4848 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4849 snprintf(xpath_value
, sizeof(xpath_value
),
4850 "%s/rmap-match-condition/frr-bgp-route-map:script",
4852 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_DESTROY
,
4855 return nb_cli_apply_changes(vty
, NULL
);
4858 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4859 snprintf(xpath_value
, sizeof(xpath_value
),
4860 "%s/rmap-match-condition/frr-bgp-route-map:script",
4862 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4865 return nb_cli_apply_changes(vty
, NULL
);
4867 #endif /* HAVE_SCRIPTING */
4869 /* match probability */
4870 DEFUN_YANG (match_probability
,
4871 match_probability_cmd
,
4872 "match probability (0-100)",
4874 "Match portion of routes defined by percentage value\n"
4875 "Percentage of routes\n")
4880 "./match-condition[condition='frr-bgp-route-map:probability']";
4881 char xpath_value
[XPATH_MAXLEN
];
4883 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4884 snprintf(xpath_value
, sizeof(xpath_value
),
4885 "%s/rmap-match-condition/frr-bgp-route-map:probability",
4887 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4888 argv
[idx_number
]->arg
);
4890 return nb_cli_apply_changes(vty
, NULL
);
4894 DEFUN_YANG (no_match_probability
,
4895 no_match_probability_cmd
,
4896 "no match probability [(1-99)]",
4899 "Match portion of routes defined by percentage value\n"
4900 "Percentage of routes\n")
4904 "./match-condition[condition='frr-bgp-route-map:probability']";
4905 char xpath_value
[XPATH_MAXLEN
];
4907 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4909 if (argc
<= idx_number
)
4910 return nb_cli_apply_changes(vty
, NULL
);
4912 snprintf(xpath_value
, sizeof(xpath_value
),
4913 "%s/rmap-match-condition/frr-bgp-route-map:probability",
4915 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_DESTROY
,
4916 argv
[idx_number
]->arg
);
4918 return nb_cli_apply_changes(vty
, NULL
);
4922 DEFPY_YANG (match_ip_route_source
,
4923 match_ip_route_source_cmd
,
4924 "match ip route-source ACCESSLIST4_NAME",
4927 "Match advertising source address of route\n"
4928 "IP Access-list name\n")
4931 "./match-condition[condition='frr-bgp-route-map:ip-route-source']";
4932 char xpath_value
[XPATH_MAXLEN
+ 32];
4935 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4936 snprintf(xpath_value
, sizeof(xpath_value
),
4937 "%s/rmap-match-condition/frr-bgp-route-map:list-name",
4939 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4940 argv
[idx_acl
]->arg
);
4942 return nb_cli_apply_changes(vty
, NULL
);
4946 DEFUN_YANG (no_match_ip_route_source
,
4947 no_match_ip_route_source_cmd
,
4948 "no match ip route-source [ACCESSLIST4_NAME]",
4952 "Match advertising source address of route\n"
4953 "IP Access-list name\n")
4956 "./match-condition[condition='frr-bgp-route-map:ip-route-source']";
4958 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4959 return nb_cli_apply_changes(vty
, NULL
);
4962 DEFUN_YANG (match_ip_route_source_prefix_list
,
4963 match_ip_route_source_prefix_list_cmd
,
4964 "match ip route-source prefix-list PREFIXLIST_NAME",
4967 "Match advertising source address of route\n"
4968 "Match entries of prefix-lists\n"
4969 "IP prefix-list name\n")
4973 "./match-condition[condition='frr-bgp-route-map:ip-route-source-prefix-list']";
4974 char xpath_value
[XPATH_MAXLEN
+ 32];
4976 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4977 snprintf(xpath_value
, sizeof(xpath_value
),
4978 "%s/rmap-match-condition/frr-bgp-route-map:list-name", xpath
);
4979 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4980 argv
[idx_word
]->arg
);
4982 return nb_cli_apply_changes(vty
, NULL
);
4986 DEFUN_YANG (no_match_ip_route_source_prefix_list
,
4987 no_match_ip_route_source_prefix_list_cmd
,
4988 "no match ip route-source prefix-list [PREFIXLIST_NAME]",
4992 "Match advertising source address of route\n"
4993 "Match entries of prefix-lists\n"
4994 "IP prefix-list name\n")
4997 "./match-condition[condition='frr-bgp-route-map:ip-route-source-prefix-list']";
4999 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5000 return nb_cli_apply_changes(vty
, NULL
);
5003 DEFUN_YANG (match_local_pref
,
5004 match_local_pref_cmd
,
5005 "match local-preference (0-4294967295)",
5007 "Match local-preference of route\n"
5013 "./match-condition[condition='frr-bgp-route-map:match-local-preference']";
5014 char xpath_value
[XPATH_MAXLEN
];
5016 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5017 snprintf(xpath_value
, sizeof(xpath_value
),
5018 "%s/rmap-match-condition/frr-bgp-route-map:local-preference",
5020 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5021 argv
[idx_number
]->arg
);
5023 return nb_cli_apply_changes(vty
, NULL
);
5027 DEFUN_YANG (no_match_local_pref
,
5028 no_match_local_pref_cmd
,
5029 "no match local-preference [(0-4294967295)]",
5032 "Match local preference of route\n"
5033 "Local preference value\n")
5035 int idx_localpref
= 3;
5037 "./match-condition[condition='frr-bgp-route-map:match-local-preference']";
5038 char xpath_value
[XPATH_MAXLEN
];
5040 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5042 if (argc
<= idx_localpref
)
5043 return nb_cli_apply_changes(vty
, NULL
);
5045 snprintf(xpath_value
, sizeof(xpath_value
),
5046 "%s/rmap-match-condition/frr-bgp-route-map:local-preference",
5048 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_DESTROY
,
5049 argv
[idx_localpref
]->arg
);
5051 return nb_cli_apply_changes(vty
, NULL
);
5054 DEFUN_YANG(match_alias
, match_alias_cmd
, "match alias ALIAS_NAME",
5056 "Match BGP community alias name\n"
5057 "BGP community alias name\n")
5059 const char *alias
= argv
[2]->arg
;
5060 struct community_alias ca1
;
5061 struct community_alias
*lookup_alias
;
5064 "./match-condition[condition='frr-bgp-route-map:match-alias']";
5065 char xpath_value
[XPATH_MAXLEN
];
5067 memset(&ca1
, 0, sizeof(ca1
));
5068 strlcpy(ca1
.alias
, alias
, sizeof(ca1
.alias
));
5069 lookup_alias
= bgp_ca_alias_lookup(&ca1
);
5070 if (!lookup_alias
) {
5071 vty_out(vty
, "%% BGP alias name '%s' does not exist\n", alias
);
5072 return CMD_WARNING_CONFIG_FAILED
;
5075 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5076 snprintf(xpath_value
, sizeof(xpath_value
),
5077 "%s/rmap-match-condition/frr-bgp-route-map:alias", xpath
);
5078 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, alias
);
5080 return nb_cli_apply_changes(vty
, NULL
);
5084 DEFUN_YANG(no_match_alias
, no_match_alias_cmd
, "no match alias [ALIAS_NAME]",
5086 "Match BGP community alias name\n"
5087 "BGP community alias name\n")
5091 "./match-condition[condition='frr-bgp-route-map:match-alias']";
5092 char xpath_value
[XPATH_MAXLEN
];
5094 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5096 if (argc
<= idx_alias
)
5097 return nb_cli_apply_changes(vty
, NULL
);
5099 snprintf(xpath_value
, sizeof(xpath_value
),
5100 "%s/rmap-match-condition/frr-bgp-route-map:alias", xpath
);
5101 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_DESTROY
,
5102 argv
[idx_alias
]->arg
);
5104 return nb_cli_apply_changes(vty
, NULL
);
5107 DEFPY_YANG (match_community
,
5108 match_community_cmd
,
5109 "match community <(1-99)|(100-500)|COMMUNITY_LIST_NAME> [exact-match]",
5111 "Match BGP community list\n"
5112 "Community-list number (standard)\n"
5113 "Community-list number (expanded)\n"
5114 "Community-list name\n"
5115 "Do exact matching of communities\n")
5118 "./match-condition[condition='frr-bgp-route-map:match-community']";
5119 char xpath_value
[XPATH_MAXLEN
];
5120 char xpath_match
[XPATH_MAXLEN
];
5121 int idx_comm_list
= 2;
5123 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5126 xpath_value
, sizeof(xpath_value
),
5127 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name",
5129 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[idx_comm_list
]->arg
);
5133 xpath_match
, sizeof(xpath_match
),
5134 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match",
5136 nb_cli_enqueue_change(vty
, xpath_match
, NB_OP_MODIFY
,
5140 xpath_match
, sizeof(xpath_match
),
5141 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match",
5143 nb_cli_enqueue_change(vty
, xpath_match
, NB_OP_MODIFY
,
5147 return nb_cli_apply_changes(vty
, NULL
);
5150 DEFUN_YANG (no_match_community
,
5151 no_match_community_cmd
,
5152 "no match community [<(1-99)|(100-500)|COMMUNITY_LIST_NAME> [exact-match]]",
5155 "Match BGP community list\n"
5156 "Community-list number (standard)\n"
5157 "Community-list number (expanded)\n"
5158 "Community-list name\n"
5159 "Do exact matching of communities\n")
5162 "./match-condition[condition='frr-bgp-route-map:match-community']";
5164 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5165 return nb_cli_apply_changes(vty
, NULL
);
5168 DEFPY_YANG (match_lcommunity
,
5169 match_lcommunity_cmd
,
5170 "match large-community <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME> [exact-match]",
5172 "Match BGP large community list\n"
5173 "Large Community-list number (standard)\n"
5174 "Large Community-list number (expanded)\n"
5175 "Large Community-list name\n"
5176 "Do exact matching of communities\n")
5179 "./match-condition[condition='frr-bgp-route-map:match-large-community']";
5180 char xpath_value
[XPATH_MAXLEN
];
5181 char xpath_match
[XPATH_MAXLEN
];
5182 int idx_lcomm_list
= 2;
5184 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5187 xpath_value
, sizeof(xpath_value
),
5188 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name",
5190 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[idx_lcomm_list
]->arg
);
5194 xpath_match
, sizeof(xpath_match
),
5195 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match",
5197 nb_cli_enqueue_change(vty
, xpath_match
, NB_OP_MODIFY
,
5201 xpath_match
, sizeof(xpath_match
),
5202 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match",
5204 nb_cli_enqueue_change(vty
, xpath_match
, NB_OP_MODIFY
,
5208 return nb_cli_apply_changes(vty
, NULL
);
5211 DEFUN_YANG (no_match_lcommunity
,
5212 no_match_lcommunity_cmd
,
5213 "no match large-community [<(1-99)|(100-500)|LCOMMUNITY_LIST_NAME> [exact-match]]",
5216 "Match BGP large community list\n"
5217 "Large Community-list number (standard)\n"
5218 "Large Community-list number (expanded)\n"
5219 "Large Community-list name\n"
5220 "Do exact matching of communities\n")
5223 "./match-condition[condition='frr-bgp-route-map:match-large-community']";
5225 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5226 return nb_cli_apply_changes(vty
, NULL
);
5229 DEFPY_YANG (match_ecommunity
,
5230 match_ecommunity_cmd
,
5231 "match extcommunity <(1-99)|(100-500)|EXTCOMMUNITY_LIST_NAME>",
5233 "Match BGP/VPN extended community list\n"
5234 "Extended community-list number (standard)\n"
5235 "Extended community-list number (expanded)\n"
5236 "Extended community-list name\n")
5239 "./match-condition[condition='frr-bgp-route-map:match-extcommunity']";
5240 char xpath_value
[XPATH_MAXLEN
];
5241 int idx_comm_list
= 2;
5243 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5246 xpath_value
, sizeof(xpath_value
),
5247 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name",
5249 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[idx_comm_list
]->arg
);
5251 return nb_cli_apply_changes(vty
, NULL
);
5255 DEFUN_YANG (no_match_ecommunity
,
5256 no_match_ecommunity_cmd
,
5257 "no match extcommunity [<(1-99)|(100-500)|EXTCOMMUNITY_LIST_NAME>]",
5260 "Match BGP/VPN extended community list\n"
5261 "Extended community-list number (standard)\n"
5262 "Extended community-list number (expanded)\n"
5263 "Extended community-list name\n")
5266 "./match-condition[condition='frr-bgp-route-map:match-extcommunity']";
5268 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5269 return nb_cli_apply_changes(vty
, NULL
);
5273 DEFUN_YANG (match_aspath
,
5275 "match as-path AS_PATH_FILTER_NAME",
5277 "Match BGP AS path list\n"
5278 "AS path access-list name\n")
5283 "./match-condition[condition='frr-bgp-route-map:as-path-list']";
5284 char xpath_value
[XPATH_MAXLEN
];
5286 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5287 snprintf(xpath_value
, sizeof(xpath_value
),
5288 "%s/rmap-match-condition/frr-bgp-route-map:list-name", xpath
);
5289 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5290 argv
[idx_word
]->arg
);
5292 return nb_cli_apply_changes(vty
, NULL
);
5296 DEFUN_YANG (no_match_aspath
,
5297 no_match_aspath_cmd
,
5298 "no match as-path [AS_PATH_FILTER_NAME]",
5301 "Match BGP AS path list\n"
5302 "AS path access-list name\n")
5305 "./match-condition[condition='frr-bgp-route-map:as-path-list']";
5307 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5309 return nb_cli_apply_changes(vty
, NULL
);
5312 DEFUN_YANG (match_origin
,
5314 "match origin <egp|igp|incomplete>",
5319 "unknown heritage\n")
5322 const char *origin_type
;
5324 "./match-condition[condition='frr-bgp-route-map:match-origin']";
5325 char xpath_value
[XPATH_MAXLEN
];
5327 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
5328 origin_type
= "igp";
5329 else if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
5330 origin_type
= "egp";
5331 else if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
5332 origin_type
= "incomplete";
5334 vty_out(vty
, "%% Invalid match origin type\n");
5335 return CMD_WARNING_CONFIG_FAILED
;
5338 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5339 snprintf(xpath_value
, sizeof(xpath_value
),
5340 "%s/rmap-match-condition/frr-bgp-route-map:origin", xpath
);
5341 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, origin_type
);
5343 return nb_cli_apply_changes(vty
, NULL
);
5347 DEFUN_YANG (no_match_origin
,
5348 no_match_origin_cmd
,
5349 "no match origin [<egp|igp|incomplete>]",
5355 "unknown heritage\n")
5358 "./match-condition[condition='frr-bgp-route-map:match-origin']";
5359 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5360 return nb_cli_apply_changes(vty
, NULL
);
5363 DEFUN_YANG (set_table_id
,
5365 "set table (1-4294967295)",
5367 "export route to non-main kernel table\n"
5368 "Kernel routing table id\n")
5371 const char *xpath
= "./set-action[action='frr-bgp-route-map:table']";
5372 char xpath_value
[XPATH_MAXLEN
];
5374 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5375 snprintf(xpath_value
, sizeof(xpath_value
),
5376 "%s/rmap-set-action/frr-bgp-route-map:table", xpath
);
5377 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5378 argv
[idx_number
]->arg
);
5379 return nb_cli_apply_changes(vty
, NULL
);
5382 DEFUN_YANG (no_set_table_id
,
5383 no_set_table_id_cmd
,
5387 "export route to non-main kernel table\n")
5389 const char *xpath
= "./set-action[action='frr-bgp-route-map:table']";
5390 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5391 return nb_cli_apply_changes(vty
, NULL
);
5394 DEFUN_YANG (set_ip_nexthop_peer
,
5395 set_ip_nexthop_peer_cmd
,
5396 "[no] set ip next-hop peer-address",
5400 "Next hop address\n"
5401 "Use peer address (for BGP only)\n")
5403 char xpath_value
[XPATH_MAXLEN
];
5405 "./set-action[action='frr-bgp-route-map:set-ipv4-nexthop']";
5407 if (strmatch(argv
[0]->text
, "no"))
5408 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5410 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5411 snprintf(xpath_value
, sizeof(xpath_value
),
5412 "%s/rmap-set-action/frr-bgp-route-map:ipv4-nexthop",
5414 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5417 return nb_cli_apply_changes(vty
, NULL
);
5420 DEFUN_YANG (set_ip_nexthop_unchanged
,
5421 set_ip_nexthop_unchanged_cmd
,
5422 "[no] set ip next-hop unchanged",
5426 "Next hop address\n"
5427 "Don't modify existing Next hop address\n")
5429 char xpath_value
[XPATH_MAXLEN
];
5431 "./set-action[action='frr-bgp-route-map:set-ipv4-nexthop']";
5433 if (strmatch(argv
[0]->text
, "no"))
5434 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5436 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5437 snprintf(xpath_value
, sizeof(xpath_value
),
5438 "%s/rmap-set-action/frr-bgp-route-map:ipv4-nexthop",
5440 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5443 return nb_cli_apply_changes(vty
, NULL
);
5446 DEFUN_YANG (set_distance
,
5448 "set distance (0-255)",
5450 "BGP Administrative Distance to use\n"
5454 const char *xpath
= "./set-action[action='frr-bgp-route-map:distance']";
5455 char xpath_value
[XPATH_MAXLEN
];
5457 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5458 snprintf(xpath_value
, sizeof(xpath_value
),
5459 "%s/rmap-set-action/frr-bgp-route-map:distance", xpath
);
5460 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5461 argv
[idx_number
]->arg
);
5462 return nb_cli_apply_changes(vty
, NULL
);
5465 DEFUN_YANG (no_set_distance
,
5466 no_set_distance_cmd
,
5467 "no set distance [(0-255)]",
5469 "BGP Administrative Distance to use\n"
5472 const char *xpath
= "./set-action[action='frr-bgp-route-map:distance']";
5474 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5475 return nb_cli_apply_changes(vty
, NULL
);
5478 DEFPY_YANG(set_l3vpn_nexthop_encapsulation
, set_l3vpn_nexthop_encapsulation_cmd
,
5479 "[no] set l3vpn next-hop encapsulation gre",
5481 "L3VPN operations\n"
5482 "Next hop Information\n"
5483 "Encapsulation options (for BGP only)\n"
5484 "Accept L3VPN traffic over GRE encapsulation\n")
5487 "./set-action[action='frr-bgp-route-map:set-l3vpn-nexthop-encapsulation']";
5488 const char *xpath_value
=
5489 "./set-action[action='frr-bgp-route-map:set-l3vpn-nexthop-encapsulation']/rmap-set-action/frr-bgp-route-map:l3vpn-nexthop-encapsulation";
5490 enum nb_operation operation
;
5493 operation
= NB_OP_DESTROY
;
5495 operation
= NB_OP_CREATE
;
5497 nb_cli_enqueue_change(vty
, xpath
, operation
, NULL
);
5498 if (operation
== NB_OP_DESTROY
)
5499 return nb_cli_apply_changes(vty
, NULL
);
5501 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "gre");
5503 return nb_cli_apply_changes(vty
, NULL
);
5506 DEFUN_YANG (set_local_pref
,
5508 "set local-preference WORD",
5510 "BGP local preference path attribute\n"
5511 "Preference value (0-4294967295)\n")
5515 "./set-action[action='frr-bgp-route-map:set-local-preference']";
5516 char xpath_value
[XPATH_MAXLEN
];
5518 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5519 snprintf(xpath_value
, sizeof(xpath_value
),
5520 "%s/rmap-set-action/frr-bgp-route-map:local-pref", xpath
);
5521 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5522 argv
[idx_number
]->arg
);
5523 return nb_cli_apply_changes(vty
, NULL
);
5526 DEFUN_YANG (no_set_local_pref
,
5527 no_set_local_pref_cmd
,
5528 "no set local-preference [WORD]",
5531 "BGP local preference path attribute\n"
5532 "Preference value (0-4294967295)\n")
5535 "./set-action[action='frr-bgp-route-map:set-local-preference']";
5537 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5538 return nb_cli_apply_changes(vty
, NULL
);
5541 DEFUN_YANG (set_weight
,
5543 "set weight (0-4294967295)",
5545 "BGP weight for routing table\n"
5549 const char *xpath
= "./set-action[action='frr-bgp-route-map:weight']";
5550 char xpath_value
[XPATH_MAXLEN
];
5552 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5553 snprintf(xpath_value
, sizeof(xpath_value
),
5554 "%s/rmap-set-action/frr-bgp-route-map:weight", xpath
);
5555 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5556 argv
[idx_number
]->arg
);
5557 return nb_cli_apply_changes(vty
, NULL
);
5560 DEFUN_YANG (no_set_weight
,
5562 "no set weight [(0-4294967295)]",
5565 "BGP weight for routing table\n"
5568 const char *xpath
= "./set-action[action='frr-bgp-route-map:weight']";
5570 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5571 return nb_cli_apply_changes(vty
, NULL
);
5574 DEFUN_YANG (set_label_index
,
5575 set_label_index_cmd
,
5576 "set label-index (0-1048560)",
5578 "Label index to associate with the prefix\n"
5579 "Label index value\n")
5583 "./set-action[action='frr-bgp-route-map:label-index']";
5584 char xpath_value
[XPATH_MAXLEN
];
5586 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5587 snprintf(xpath_value
, sizeof(xpath_value
),
5588 "%s/rmap-set-action/frr-bgp-route-map:label-index", xpath
);
5589 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5590 argv
[idx_number
]->arg
);
5591 return nb_cli_apply_changes(vty
, NULL
);
5594 DEFUN_YANG (no_set_label_index
,
5595 no_set_label_index_cmd
,
5596 "no set label-index [(0-1048560)]",
5599 "Label index to associate with the prefix\n"
5600 "Label index value\n")
5603 "./set-action[action='frr-bgp-route-map:label-index']";
5605 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5606 return nb_cli_apply_changes(vty
, NULL
);
5609 DEFUN_YANG (set_aspath_prepend_asn
,
5610 set_aspath_prepend_asn_cmd
,
5611 "set as-path prepend (1-4294967295)...",
5613 "Transform BGP AS_PATH attribute\n"
5614 "Prepend to the as-path\n"
5621 str
= argv_concat(argv
, argc
, idx_asn
);
5624 "./set-action[action='frr-bgp-route-map:as-path-prepend']";
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:prepend-as-path", xpath
);
5630 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
5631 ret
= nb_cli_apply_changes(vty
, NULL
);
5632 XFREE(MTYPE_TMP
, str
);
5636 DEFUN_YANG (set_aspath_prepend_lastas
,
5637 set_aspath_prepend_lastas_cmd
,
5638 "set as-path prepend last-as (1-10)",
5640 "Transform BGP AS_PATH attribute\n"
5641 "Prepend to the as-path\n"
5642 "Use the last AS-number in the as-path\n"
5643 "Number of times to insert\n")
5648 "./set-action[action='frr-bgp-route-map:as-path-prepend']";
5649 char xpath_value
[XPATH_MAXLEN
];
5651 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5652 snprintf(xpath_value
, sizeof(xpath_value
),
5653 "%s/rmap-set-action/frr-bgp-route-map:last-as", xpath
);
5654 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5655 argv
[idx_num
]->arg
);
5656 return nb_cli_apply_changes(vty
, NULL
);
5659 DEFPY_YANG (set_aspath_replace_asn
,
5660 set_aspath_replace_asn_cmd
,
5661 "set as-path replace <any|(1-4294967295)>$replace",
5663 "Transform BGP AS_PATH attribute\n"
5664 "Replace AS number to local AS number\n"
5665 "Replace any AS number to local AS number\n"
5666 "Replace a specific AS number to local AS number\n")
5669 "./set-action[action='frr-bgp-route-map:as-path-replace']";
5670 char xpath_value
[XPATH_MAXLEN
];
5672 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5673 snprintf(xpath_value
, sizeof(xpath_value
),
5674 "%s/rmap-set-action/frr-bgp-route-map:replace-as-path", xpath
);
5675 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, replace
);
5676 return nb_cli_apply_changes(vty
, NULL
);
5679 DEFPY_YANG (no_set_aspath_replace_asn
,
5680 no_set_aspath_replace_asn_cmd
,
5681 "no set as-path replace [<any|(1-4294967295)>]",
5684 "Transform BGP AS_PATH attribute\n"
5685 "Replace AS number to local AS number\n"
5686 "Replace any AS number to local AS number\n"
5687 "Replace a specific AS number to local AS number\n")
5690 "./set-action[action='frr-bgp-route-map:as-path-replace']";
5692 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5693 return nb_cli_apply_changes(vty
, NULL
);
5696 DEFUN_YANG (no_set_aspath_prepend
,
5697 no_set_aspath_prepend_cmd
,
5698 "no set as-path prepend [(1-4294967295)]",
5701 "Transform BGP AS_PATH attribute\n"
5702 "Prepend to the as-path\n"
5706 "./set-action[action='frr-bgp-route-map:as-path-prepend']";
5708 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5709 return nb_cli_apply_changes(vty
, NULL
);
5712 DEFUN_YANG (no_set_aspath_prepend_lastas
,
5713 no_set_aspath_prepend_lastas_cmd
,
5714 "no set as-path prepend last-as [(1-10)]",
5717 "Transform BGP AS_PATH attribute\n"
5718 "Prepend to the as-path\n"
5719 "Use the peers AS-number\n"
5720 "Number of times to insert\n")
5723 "./set-action[action='frr-bgp-route-map:as-path-prepend']";
5725 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5726 return nb_cli_apply_changes(vty
, NULL
);
5729 DEFUN_YANG (set_aspath_exclude
,
5730 set_aspath_exclude_cmd
,
5731 "set as-path exclude (1-4294967295)...",
5733 "Transform BGP AS-path attribute\n"
5734 "Exclude from the as-path\n"
5741 str
= argv_concat(argv
, argc
, idx_asn
);
5744 "./set-action[action='frr-bgp-route-map:as-path-exclude']";
5745 char xpath_value
[XPATH_MAXLEN
];
5747 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5748 snprintf(xpath_value
, sizeof(xpath_value
),
5749 "%s/rmap-set-action/frr-bgp-route-map:exclude-as-path", xpath
);
5750 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
5751 ret
= nb_cli_apply_changes(vty
, NULL
);
5752 XFREE(MTYPE_TMP
, str
);
5756 DEFUN_YANG (no_set_aspath_exclude
,
5757 no_set_aspath_exclude_cmd
,
5758 "no set as-path exclude (1-4294967295)...",
5761 "Transform BGP AS_PATH attribute\n"
5762 "Exclude from the as-path\n"
5766 "./set-action[action='frr-bgp-route-map:as-path-exclude']";
5768 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5769 return nb_cli_apply_changes(vty
, NULL
);
5772 ALIAS_YANG (no_set_aspath_exclude
, no_set_aspath_exclude_all_cmd
,
5773 "no set as-path exclude",
5775 "Transform BGP AS_PATH attribute\n"
5776 "Exclude from the as-path\n")
5778 DEFUN_YANG (set_community
,
5780 "set community AA:NN...",
5782 "BGP community attribute\n"
5790 struct community
*com
= NULL
;
5792 char *argstr
= NULL
;
5796 "./set-action[action='frr-bgp-route-map:set-community']";
5797 char xpath_value
[XPATH_MAXLEN
];
5799 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5800 snprintf(xpath_value
, sizeof(xpath_value
),
5801 "%s/rmap-set-action/frr-bgp-route-map:community-string",
5804 b
= buffer_new(1024);
5806 for (i
= idx_aa_nn
; i
< argc
; i
++) {
5807 if (strncmp(argv
[i
]->arg
, "additive", strlen(argv
[i
]->arg
))
5814 buffer_putc(b
, ' ');
5818 if (strncmp(argv
[i
]->arg
, "internet", strlen(argv
[i
]->arg
))
5820 buffer_putstr(b
, "internet");
5823 if (strncmp(argv
[i
]->arg
, "local-AS", strlen(argv
[i
]->arg
))
5825 buffer_putstr(b
, "local-AS");
5828 if (strncmp(argv
[i
]->arg
, "no-a", strlen("no-a")) == 0
5829 && strncmp(argv
[i
]->arg
, "no-advertise",
5830 strlen(argv
[i
]->arg
))
5832 buffer_putstr(b
, "no-advertise");
5835 if (strncmp(argv
[i
]->arg
, "no-e", strlen("no-e")) == 0
5836 && strncmp(argv
[i
]->arg
, "no-export", strlen(argv
[i
]->arg
))
5838 buffer_putstr(b
, "no-export");
5841 if (strncmp(argv
[i
]->arg
, "blackhole", strlen(argv
[i
]->arg
))
5843 buffer_putstr(b
, "blackhole");
5846 if (strncmp(argv
[i
]->arg
, "graceful-shutdown",
5847 strlen(argv
[i
]->arg
))
5849 buffer_putstr(b
, "graceful-shutdown");
5852 buffer_putstr(b
, argv
[i
]->arg
);
5854 buffer_putc(b
, '\0');
5856 /* Fetch result string then compile it to communities attribute. */
5857 str
= buffer_getstr(b
);
5861 com
= community_str2com(str
);
5863 /* Can't compile user input into communities attribute. */
5865 vty_out(vty
, "%% Malformed communities attribute '%s'\n", str
);
5866 XFREE(MTYPE_TMP
, str
);
5867 return CMD_WARNING_CONFIG_FAILED
;
5869 XFREE(MTYPE_TMP
, str
);
5871 /* Set communites attribute string. */
5872 str
= community_str(com
, false, false);
5875 size_t argstr_sz
= strlen(str
) + strlen(" additive") + 1;
5876 argstr
= XCALLOC(MTYPE_TMP
, argstr_sz
);
5877 strlcpy(argstr
, str
, argstr_sz
);
5878 strlcat(argstr
, " additive", argstr_sz
);
5879 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argstr
);
5881 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
5883 ret
= nb_cli_apply_changes(vty
, NULL
);
5886 XFREE(MTYPE_TMP
, argstr
);
5887 community_free(&com
);
5892 DEFUN_YANG (set_community_none
,
5893 set_community_none_cmd
,
5894 "set community none",
5896 "BGP community attribute\n"
5897 "No community attribute\n")
5900 "./set-action[action='frr-bgp-route-map:set-community']";
5901 char xpath_value
[XPATH_MAXLEN
];
5903 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5905 snprintf(xpath_value
, sizeof(xpath_value
),
5906 "%s/rmap-set-action/frr-bgp-route-map:community-none", xpath
);
5907 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
5908 return nb_cli_apply_changes(vty
, NULL
);
5911 DEFUN_YANG (no_set_community
,
5912 no_set_community_cmd
,
5913 "no set community AA:NN...",
5916 "BGP community attribute\n"
5920 "./set-action[action='frr-bgp-route-map:set-community']";
5922 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5923 return nb_cli_apply_changes(vty
, NULL
);
5926 ALIAS_YANG (no_set_community
,
5927 no_set_community_short_cmd
,
5931 "BGP community attribute\n")
5933 DEFPY_YANG (set_community_delete
,
5934 set_community_delete_cmd
,
5935 "set comm-list <(1-99)|(100-500)|COMMUNITY_LIST_NAME> delete",
5937 "set BGP community list (for deletion)\n"
5938 "Community-list number (standard)\n"
5939 "Community-list number (expanded)\n"
5940 "Community-list name\n"
5941 "Delete matching communities\n")
5944 "./set-action[action='frr-bgp-route-map:comm-list-delete']";
5945 char xpath_value
[XPATH_MAXLEN
];
5946 int idx_comm_list
= 2;
5948 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5950 snprintf(xpath_value
, sizeof(xpath_value
),
5951 "%s/rmap-set-action/frr-bgp-route-map:comm-list-name",
5953 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5954 argv
[idx_comm_list
]->arg
);
5956 return nb_cli_apply_changes(vty
, NULL
);
5960 DEFUN_YANG (no_set_community_delete
,
5961 no_set_community_delete_cmd
,
5962 "no set comm-list [<(1-99)|(100-500)|COMMUNITY_LIST_NAME> delete]",
5965 "set BGP community list (for deletion)\n"
5966 "Community-list number (standard)\n"
5967 "Community-list number (expanded)\n"
5968 "Community-list name\n"
5969 "Delete matching communities\n")
5972 "./set-action[action='frr-bgp-route-map:comm-list-delete']";
5974 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5975 return nb_cli_apply_changes(vty
, NULL
);
5978 DEFUN_YANG (set_lcommunity
,
5980 "set large-community AA:BB:CC...",
5982 "BGP large community attribute\n"
5983 "Large Community number in aa:bb:cc format or additive\n")
5988 "./set-action[action='frr-bgp-route-map:set-large-community']";
5989 char xpath_value
[XPATH_MAXLEN
];
5991 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5993 snprintf(xpath_value
, sizeof(xpath_value
),
5994 "%s/rmap-set-action/frr-bgp-route-map:large-community-string",
5996 str
= argv_concat(argv
, argc
, 2);
5997 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
5998 ret
= nb_cli_apply_changes(vty
, NULL
);
5999 XFREE(MTYPE_TMP
, str
);
6003 DEFUN_YANG (set_lcommunity_none
,
6004 set_lcommunity_none_cmd
,
6005 "set large-community none",
6007 "BGP large community attribute\n"
6008 "No large community attribute\n")
6011 "./set-action[action='frr-bgp-route-map:set-large-community']";
6012 char xpath_value
[XPATH_MAXLEN
];
6014 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6016 snprintf(xpath_value
, sizeof(xpath_value
),
6017 "%s/rmap-set-action/frr-bgp-route-map:large-community-none",
6019 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
6020 return nb_cli_apply_changes(vty
, NULL
);
6023 DEFUN_YANG (no_set_lcommunity
,
6024 no_set_lcommunity_cmd
,
6025 "no set large-community none",
6028 "BGP large community attribute\n"
6029 "No community attribute\n")
6032 "./set-action[action='frr-bgp-route-map:set-large-community']";
6034 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6035 return nb_cli_apply_changes(vty
, NULL
);
6038 DEFUN_YANG (no_set_lcommunity1
,
6039 no_set_lcommunity1_cmd
,
6040 "no set large-community AA:BB:CC...",
6043 "BGP large community attribute\n"
6044 "Large community in AA:BB:CC... format or additive\n")
6047 "./set-action[action='frr-bgp-route-map:set-large-community']";
6049 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6050 return nb_cli_apply_changes(vty
, NULL
);
6053 ALIAS_YANG (no_set_lcommunity1
,
6054 no_set_lcommunity1_short_cmd
,
6055 "no set large-community",
6058 "BGP large community attribute\n")
6060 DEFPY_YANG (set_lcommunity_delete
,
6061 set_lcommunity_delete_cmd
,
6062 "set large-comm-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME> delete",
6064 "set BGP large community list (for deletion)\n"
6065 "Large Community-list number (standard)\n"
6066 "Large Communitly-list number (expanded)\n"
6067 "Large Community-list name\n"
6068 "Delete matching large communities\n")
6071 "./set-action[action='frr-bgp-route-map:large-comm-list-delete']";
6072 char xpath_value
[XPATH_MAXLEN
];
6073 int idx_lcomm_list
= 2;
6075 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6077 snprintf(xpath_value
, sizeof(xpath_value
),
6078 "%s/rmap-set-action/frr-bgp-route-map:comm-list-name",
6080 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6081 argv
[idx_lcomm_list
]->arg
);
6083 return nb_cli_apply_changes(vty
, NULL
);
6086 DEFUN_YANG (no_set_lcommunity_delete
,
6087 no_set_lcommunity_delete_cmd
,
6088 "no set large-comm-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME> [delete]",
6091 "set BGP large community list (for deletion)\n"
6092 "Large Community-list number (standard)\n"
6093 "Large Communitly-list number (expanded)\n"
6094 "Large Community-list name\n"
6095 "Delete matching large communities\n")
6098 "./set-action[action='frr-bgp-route-map:large-comm-list-delete']";
6100 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6101 return nb_cli_apply_changes(vty
, NULL
);
6104 ALIAS_YANG (no_set_lcommunity_delete
,
6105 no_set_lcommunity_delete_short_cmd
,
6106 "no set large-comm-list",
6109 "set BGP large community list (for deletion)\n")
6111 DEFUN_YANG (set_ecommunity_rt
,
6112 set_ecommunity_rt_cmd
,
6113 "set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
6115 "BGP extended community attribute\n"
6116 "Route Target extended community\n"
6117 "VPN extended community\n")
6123 "./set-action[action='frr-bgp-route-map:set-extcommunity-rt']";
6124 char xpath_value
[XPATH_MAXLEN
];
6126 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6128 snprintf(xpath_value
, sizeof(xpath_value
),
6129 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-rt", xpath
);
6130 str
= argv_concat(argv
, argc
, idx_asn_nn
);
6131 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
6132 ret
= nb_cli_apply_changes(vty
, NULL
);
6133 XFREE(MTYPE_TMP
, str
);
6137 DEFUN_YANG (no_set_ecommunity_rt
,
6138 no_set_ecommunity_rt_cmd
,
6139 "no set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
6142 "BGP extended community attribute\n"
6143 "Route Target extended community\n"
6144 "VPN extended community\n")
6147 "./set-action[action='frr-bgp-route-map:set-extcommunity-rt']";
6148 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6149 return nb_cli_apply_changes(vty
, NULL
);
6152 ALIAS_YANG (no_set_ecommunity_rt
,
6153 no_set_ecommunity_rt_short_cmd
,
6154 "no set extcommunity rt",
6157 "BGP extended community attribute\n"
6158 "Route Target extended community\n")
6160 DEFUN_YANG (set_ecommunity_soo
,
6161 set_ecommunity_soo_cmd
,
6162 "set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
6164 "BGP extended community attribute\n"
6165 "Site-of-Origin extended community\n"
6166 "VPN extended community\n")
6172 "./set-action[action='frr-bgp-route-map:set-extcommunity-soo']";
6173 char xpath_value
[XPATH_MAXLEN
];
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:extcommunity-soo",
6180 str
= argv_concat(argv
, argc
, idx_asn_nn
);
6181 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
6182 ret
= nb_cli_apply_changes(vty
, NULL
);
6183 XFREE(MTYPE_TMP
, str
);
6187 DEFUN_YANG (no_set_ecommunity_soo
,
6188 no_set_ecommunity_soo_cmd
,
6189 "no set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
6192 "BGP extended community attribute\n"
6193 "Site-of-Origin extended community\n"
6194 "VPN extended community\n")
6197 "./set-action[action='frr-bgp-route-map:set-extcommunity-soo']";
6198 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6199 return nb_cli_apply_changes(vty
, NULL
);
6202 ALIAS_YANG (no_set_ecommunity_soo
,
6203 no_set_ecommunity_soo_short_cmd
,
6204 "no set extcommunity soo",
6207 "GP extended community attribute\n"
6208 "Site-of-Origin extended community\n")
6210 DEFUN_YANG(set_ecommunity_none
, set_ecommunity_none_cmd
,
6211 "set extcommunity none",
6213 "BGP extended community attribute\n"
6214 "No extended community attribute\n")
6217 "./set-action[action='frr-bgp-route-map:set-extcommunity-none']";
6218 char xpath_value
[XPATH_MAXLEN
];
6220 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6222 snprintf(xpath_value
, sizeof(xpath_value
),
6223 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-none",
6225 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
6226 return nb_cli_apply_changes(vty
, NULL
);
6229 DEFUN_YANG(no_set_ecommunity_none
, no_set_ecommunity_none_cmd
,
6230 "no set extcommunity none",
6232 "BGP extended community attribute\n"
6233 "No extended community attribute\n")
6236 "./set-action[action='frr-bgp-route-map:set-extcommunity-none']";
6237 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6238 return nb_cli_apply_changes(vty
, NULL
);
6241 DEFUN_YANG (set_ecommunity_lb
,
6242 set_ecommunity_lb_cmd
,
6243 "set extcommunity bandwidth <(1-25600)|cumulative|num-multipaths> [non-transitive]",
6245 "BGP extended community attribute\n"
6246 "Link bandwidth extended community\n"
6247 "Bandwidth value in Mbps\n"
6248 "Cumulative bandwidth of all multipaths (outbound-only)\n"
6249 "Internally computed bandwidth based on number of multipaths (outbound-only)\n"
6250 "Attribute is set as non-transitive\n")
6253 int idx_non_transitive
= 0;
6255 "./set-action[action='frr-bgp-route-map:set-extcommunity-lb']";
6256 char xpath_lb_type
[XPATH_MAXLEN
];
6257 char xpath_bandwidth
[XPATH_MAXLEN
];
6258 char xpath_non_transitive
[XPATH_MAXLEN
];
6260 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6262 snprintf(xpath_lb_type
, sizeof(xpath_lb_type
),
6263 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-lb/lb-type",
6265 snprintf(xpath_bandwidth
, sizeof(xpath_bandwidth
),
6266 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-lb/bandwidth",
6268 snprintf(xpath_non_transitive
, sizeof(xpath_non_transitive
),
6269 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-lb/two-octet-as-specific",
6272 if ((strcmp(argv
[idx_lb
]->arg
, "cumulative")) == 0)
6273 nb_cli_enqueue_change(vty
, xpath_lb_type
, NB_OP_MODIFY
,
6274 "cumulative-bandwidth");
6275 else if ((strcmp(argv
[idx_lb
]->arg
, "num-multipaths")) == 0)
6276 nb_cli_enqueue_change(vty
, xpath_lb_type
, NB_OP_MODIFY
,
6277 "computed-bandwidth");
6279 nb_cli_enqueue_change(vty
, xpath_lb_type
, NB_OP_MODIFY
,
6280 "explicit-bandwidth");
6281 nb_cli_enqueue_change(vty
, xpath_bandwidth
, NB_OP_MODIFY
,
6285 if (argv_find(argv
, argc
, "non-transitive", &idx_non_transitive
))
6286 nb_cli_enqueue_change(vty
, xpath_non_transitive
, NB_OP_MODIFY
,
6289 nb_cli_enqueue_change(vty
, xpath_non_transitive
, NB_OP_MODIFY
,
6292 return nb_cli_apply_changes(vty
, NULL
);
6295 DEFUN_YANG (no_set_ecommunity_lb
,
6296 no_set_ecommunity_lb_cmd
,
6297 "no set extcommunity bandwidth <(1-25600)|cumulative|num-multipaths> [non-transitive]",
6300 "BGP extended community attribute\n"
6301 "Link bandwidth extended community\n"
6302 "Bandwidth value in Mbps\n"
6303 "Cumulative bandwidth of all multipaths (outbound-only)\n"
6304 "Internally computed bandwidth based on number of multipaths (outbound-only)\n"
6305 "Attribute is set as non-transitive\n")
6308 "./set-action[action='frr-bgp-route-map:set-extcommunity-lb']";
6310 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6311 return nb_cli_apply_changes(vty
, NULL
);
6314 ALIAS_YANG (no_set_ecommunity_lb
,
6315 no_set_ecommunity_lb_short_cmd
,
6316 "no set extcommunity bandwidth",
6319 "BGP extended community attribute\n"
6320 "Link bandwidth extended community\n")
6322 DEFUN_YANG (set_origin
,
6324 "set origin <egp|igp|incomplete>",
6329 "unknown heritage\n")
6332 const char *origin_type
;
6334 "./set-action[action='frr-bgp-route-map:set-origin']";
6335 char xpath_value
[XPATH_MAXLEN
];
6337 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
6338 origin_type
= "igp";
6339 else if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
6340 origin_type
= "egp";
6341 else if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
6342 origin_type
= "incomplete";
6344 vty_out(vty
, "%% Invalid match origin type\n");
6345 return CMD_WARNING_CONFIG_FAILED
;
6348 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6349 snprintf(xpath_value
, sizeof(xpath_value
),
6350 "%s/rmap-set-action/frr-bgp-route-map:origin", xpath
);
6351 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, origin_type
);
6353 return nb_cli_apply_changes(vty
, NULL
);
6356 DEFUN_YANG (no_set_origin
,
6358 "no set origin [<egp|igp|incomplete>]",
6364 "unknown heritage\n")
6367 "./set-action[action='frr-bgp-route-map:set-origin']";
6369 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6370 return nb_cli_apply_changes(vty
, NULL
);
6373 DEFUN_YANG (set_atomic_aggregate
,
6374 set_atomic_aggregate_cmd
,
6375 "set atomic-aggregate",
6377 "BGP atomic aggregate attribute\n" )
6380 "./set-action[action='frr-bgp-route-map:atomic-aggregate']";
6381 char xpath_value
[XPATH_MAXLEN
];
6383 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6384 snprintf(xpath_value
, sizeof(xpath_value
),
6385 "%s/rmap-set-action/frr-bgp-route-map:atomic-aggregate",
6387 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, NULL
);
6389 return nb_cli_apply_changes(vty
, NULL
);
6392 DEFUN_YANG (no_set_atomic_aggregate
,
6393 no_set_atomic_aggregate_cmd
,
6394 "no set atomic-aggregate",
6397 "BGP atomic aggregate attribute\n" )
6400 "./set-action[action='frr-bgp-route-map:atomic-aggregate']";
6402 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6403 return nb_cli_apply_changes(vty
, NULL
);
6406 DEFPY_YANG (set_aigp_metric
,
6407 set_aigp_metric_cmd
,
6408 "set aigp-metric <igp-metric|(1-4294967295)>$aigp_metric",
6410 "BGP AIGP attribute (AIGP Metric TLV)\n"
6411 "AIGP Metric value from IGP protocol\n"
6412 "Manual AIGP Metric value\n")
6415 "./set-action[action='frr-bgp-route-map:aigp-metric']";
6416 char xpath_value
[XPATH_MAXLEN
];
6418 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6419 snprintf(xpath_value
, sizeof(xpath_value
),
6420 "%s/rmap-set-action/frr-bgp-route-map:aigp-metric", xpath
);
6421 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, aigp_metric
);
6423 return nb_cli_apply_changes(vty
, NULL
);
6426 DEFPY_YANG (no_set_aigp_metric
,
6427 no_set_aigp_metric_cmd
,
6428 "no set aigp-metric [<igp-metric|(1-4294967295)>]",
6431 "BGP AIGP attribute (AIGP Metric TLV)\n"
6432 "AIGP Metric value from IGP protocol\n"
6433 "Manual AIGP Metric value\n")
6436 "./set-action[action='frr-bgp-route-map:aigp-metric']";
6438 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6439 return nb_cli_apply_changes(vty
, NULL
);
6442 DEFUN_YANG (set_aggregator_as
,
6443 set_aggregator_as_cmd
,
6444 "set aggregator as (1-4294967295) A.B.C.D",
6446 "BGP aggregator attribute\n"
6447 "AS number of aggregator\n"
6449 "IP address of aggregator\n")
6453 char xpath_asn
[XPATH_MAXLEN
];
6454 char xpath_addr
[XPATH_MAXLEN
];
6456 "./set-action[action='frr-bgp-route-map:aggregator']";
6458 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6461 xpath_asn
, sizeof(xpath_asn
),
6462 "%s/rmap-set-action/frr-bgp-route-map:aggregator/aggregator-asn",
6464 nb_cli_enqueue_change(vty
, xpath_asn
, NB_OP_MODIFY
,
6465 argv
[idx_number
]->arg
);
6468 xpath_addr
, sizeof(xpath_addr
),
6469 "%s/rmap-set-action/frr-bgp-route-map:aggregator/aggregator-address",
6471 nb_cli_enqueue_change(vty
, xpath_addr
, NB_OP_MODIFY
,
6472 argv
[idx_ipv4
]->arg
);
6474 return nb_cli_apply_changes(vty
, NULL
);
6477 DEFUN_YANG (no_set_aggregator_as
,
6478 no_set_aggregator_as_cmd
,
6479 "no set aggregator as [(1-4294967295) A.B.C.D]",
6482 "BGP aggregator attribute\n"
6483 "AS number of aggregator\n"
6485 "IP address of aggregator\n")
6488 "./set-action[action='frr-bgp-route-map:aggregator']";
6490 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6491 return nb_cli_apply_changes(vty
, NULL
);
6494 DEFUN_YANG (match_ipv6_next_hop
,
6495 match_ipv6_next_hop_cmd
,
6496 "match ipv6 next-hop ACCESSLIST6_NAME",
6499 "Match IPv6 next-hop address of route\n"
6500 "IPv6 access-list name\n")
6503 "./match-condition[condition='frr-route-map:ipv6-next-hop-list']";
6504 char xpath_value
[XPATH_MAXLEN
];
6506 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6507 snprintf(xpath_value
, sizeof(xpath_value
),
6508 "%s/rmap-match-condition/list-name", xpath
);
6509 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6510 argv
[argc
- 1]->arg
);
6512 return nb_cli_apply_changes(vty
, NULL
);
6515 DEFUN_YANG (no_match_ipv6_next_hop
,
6516 no_match_ipv6_next_hop_cmd
,
6517 "no match ipv6 next-hop [ACCESSLIST6_NAME]",
6521 "Match IPv6 next-hop address of route\n"
6522 "IPv6 access-list name\n")
6525 "./match-condition[condition='frr-route-map:ipv6-next-hop-list']";
6527 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6528 return nb_cli_apply_changes(vty
, NULL
);
6531 DEFUN_YANG (match_ipv6_next_hop_address
,
6532 match_ipv6_next_hop_address_cmd
,
6533 "match ipv6 next-hop address X:X::X:X",
6536 "Match IPv6 next-hop address of route\n"
6538 "IPv6 address of next hop\n")
6541 "./match-condition[condition='frr-bgp-route-map:ipv6-nexthop']";
6542 char xpath_value
[XPATH_MAXLEN
];
6544 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6545 snprintf(xpath_value
, sizeof(xpath_value
),
6546 "%s/rmap-match-condition/frr-bgp-route-map:ipv6-address",
6548 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6549 argv
[argc
- 1]->arg
);
6551 return nb_cli_apply_changes(vty
, NULL
);
6554 DEFUN_YANG (no_match_ipv6_next_hop_address
,
6555 no_match_ipv6_next_hop_address_cmd
,
6556 "no match ipv6 next-hop address X:X::X:X",
6560 "Match IPv6 next-hop address of route\n"
6562 "IPv6 address of next hop\n")
6565 "./match-condition[condition='frr-bgp-route-map:ipv6-nexthop']";
6567 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6568 return nb_cli_apply_changes(vty
, NULL
);
6571 ALIAS_HIDDEN (match_ipv6_next_hop_address
,
6572 match_ipv6_next_hop_old_cmd
,
6573 "match ipv6 next-hop X:X::X:X",
6576 "Match IPv6 next-hop address of route\n"
6577 "IPv6 address of next hop\n")
6579 ALIAS_HIDDEN (no_match_ipv6_next_hop_address
,
6580 no_match_ipv6_next_hop_old_cmd
,
6581 "no match ipv6 next-hop X:X::X:X",
6585 "Match IPv6 next-hop address of route\n"
6586 "IPv6 address of next hop\n")
6588 DEFUN_YANG (match_ipv6_next_hop_prefix_list
,
6589 match_ipv6_next_hop_prefix_list_cmd
,
6590 "match ipv6 next-hop prefix-list PREFIXLIST_NAME",
6593 "Match IPv6 next-hop address of route\n"
6594 "Match entries by prefix-list\n"
6595 "IPv6 prefix-list name\n")
6598 "./match-condition[condition='frr-route-map:ipv6-next-hop-prefix-list']";
6599 char xpath_value
[XPATH_MAXLEN
];
6601 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6602 snprintf(xpath_value
, sizeof(xpath_value
),
6603 "%s/rmap-match-condition/list-name", xpath
);
6604 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6605 argv
[argc
- 1]->arg
);
6607 return nb_cli_apply_changes(vty
, NULL
);
6610 DEFUN_YANG (no_match_ipv6_next_hop_prefix_list
,
6611 no_match_ipv6_next_hop_prefix_list_cmd
,
6612 "no match ipv6 next-hop prefix-list [PREFIXLIST_NAME]",
6616 "Match IPv6 next-hop address of route\n"
6617 "Match entries by prefix-list\n"
6618 "IPv6 prefix-list name\n")
6621 "./match-condition[condition='frr-route-map:ipv6-next-hop-prefix-list']";
6623 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6624 return nb_cli_apply_changes(vty
, NULL
);
6627 DEFPY_YANG (match_ipv4_next_hop
,
6628 match_ipv4_next_hop_cmd
,
6629 "match ip next-hop address A.B.C.D",
6632 "Match IP next-hop address of route\n"
6634 "IP address of next-hop\n")
6637 "./match-condition[condition='frr-bgp-route-map:ipv4-nexthop']";
6638 char xpath_value
[XPATH_MAXLEN
];
6640 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6641 snprintf(xpath_value
, sizeof(xpath_value
),
6642 "%s/rmap-match-condition/frr-bgp-route-map:ipv4-address",
6644 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[4]->arg
);
6646 return nb_cli_apply_changes(vty
, NULL
);
6649 DEFPY_YANG (no_match_ipv4_next_hop
,
6650 no_match_ipv4_next_hop_cmd
,
6651 "no match ip next-hop address [A.B.C.D]",
6655 "Match IP next-hop address of route\n"
6657 "IP address of next-hop\n")
6660 "./match-condition[condition='frr-bgp-route-map:ipv4-nexthop']";
6662 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6663 return nb_cli_apply_changes(vty
, NULL
);
6666 DEFUN_YANG (set_ipv6_nexthop_peer
,
6667 set_ipv6_nexthop_peer_cmd
,
6668 "set ipv6 next-hop peer-address",
6671 "Next hop address\n"
6672 "Use peer address (for BGP only)\n")
6675 "./set-action[action='frr-bgp-route-map:ipv6-peer-address']";
6676 char xpath_value
[XPATH_MAXLEN
];
6678 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6679 snprintf(xpath_value
, sizeof(xpath_value
),
6680 "%s/rmap-set-action/frr-bgp-route-map:preference", xpath
);
6681 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
6683 return nb_cli_apply_changes(vty
, NULL
);
6686 DEFUN_YANG (no_set_ipv6_nexthop_peer
,
6687 no_set_ipv6_nexthop_peer_cmd
,
6688 "no set ipv6 next-hop peer-address",
6692 "IPv6 next-hop address\n"
6693 "Use peer address (for BGP only)\n")
6696 "./set-action[action='frr-bgp-route-map:ipv6-peer-address']";
6698 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6699 return nb_cli_apply_changes(vty
, NULL
);
6702 DEFUN_YANG (set_ipv6_nexthop_prefer_global
,
6703 set_ipv6_nexthop_prefer_global_cmd
,
6704 "set ipv6 next-hop prefer-global",
6707 "IPv6 next-hop address\n"
6708 "Prefer global over link-local if both exist\n")
6711 "./set-action[action='frr-bgp-route-map:ipv6-prefer-global']";
6712 char xpath_value
[XPATH_MAXLEN
];
6714 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6715 snprintf(xpath_value
, sizeof(xpath_value
),
6716 "%s/rmap-set-action/frr-bgp-route-map:preference", xpath
);
6717 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
6719 return nb_cli_apply_changes(vty
, NULL
);
6722 DEFUN_YANG (no_set_ipv6_nexthop_prefer_global
,
6723 no_set_ipv6_nexthop_prefer_global_cmd
,
6724 "no set ipv6 next-hop prefer-global",
6728 "IPv6 next-hop address\n"
6729 "Prefer global over link-local if both exist\n")
6732 "./set-action[action='frr-bgp-route-map:ipv6-prefer-global']";
6734 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6735 return nb_cli_apply_changes(vty
, NULL
);
6738 DEFUN_YANG (set_ipv6_nexthop_global
,
6739 set_ipv6_nexthop_global_cmd
,
6740 "set ipv6 next-hop global X:X::X:X",
6743 "IPv6 next-hop address\n"
6744 "IPv6 global address\n"
6745 "IPv6 address of next hop\n")
6749 "./set-action[action='frr-bgp-route-map:ipv6-nexthop-global']";
6750 char xpath_value
[XPATH_MAXLEN
];
6752 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6753 snprintf(xpath_value
, sizeof(xpath_value
),
6754 "%s/rmap-set-action/frr-bgp-route-map:ipv6-address", xpath
);
6755 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6756 argv
[idx_ipv6
]->arg
);
6758 return nb_cli_apply_changes(vty
, NULL
);
6761 DEFUN_YANG (no_set_ipv6_nexthop_global
,
6762 no_set_ipv6_nexthop_global_cmd
,
6763 "no set ipv6 next-hop global X:X::X:X",
6767 "IPv6 next-hop address\n"
6768 "IPv6 global address\n"
6769 "IPv6 address of next hop\n")
6772 "./set-action[action='frr-bgp-route-map:ipv6-nexthop-global']";
6774 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6775 return nb_cli_apply_changes(vty
, NULL
);
6778 #ifdef KEEP_OLD_VPN_COMMANDS
6779 DEFUN_YANG (set_vpn_nexthop
,
6780 set_vpn_nexthop_cmd
,
6781 "set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
6783 "VPNv4 information\n"
6784 "VPN next-hop address\n"
6785 "IP address of next hop\n"
6786 "VPNv6 information\n"
6787 "VPN next-hop address\n"
6788 "IPv6 address of next hop\n")
6793 char xpath_value
[XPATH_MAXLEN
];
6795 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
6796 if (afi
== AFI_IP
) {
6798 "./set-action[action='frr-bgp-route-map:ipv4-vpn-address']";
6800 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6802 xpath_value
, sizeof(xpath_value
),
6803 "%s/rmap-set-action/frr-bgp-route-map:ipv4-address",
6807 "./set-action[action='frr-bgp-route-map:ipv6-vpn-address']";
6809 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6811 xpath_value
, sizeof(xpath_value
),
6812 "%s/rmap-set-action/frr-bgp-route-map:ipv6-address",
6816 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6819 return nb_cli_apply_changes(vty
, NULL
);
6825 DEFUN_YANG (no_set_vpn_nexthop
,
6826 no_set_vpn_nexthop_cmd
,
6827 "no set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
6830 "VPNv4 information\n"
6831 "VPN next-hop address\n"
6832 "IP address of next hop\n"
6833 "VPNv6 information\n"
6834 "VPN next-hop address\n"
6835 "IPv6 address of next hop\n")
6840 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
6841 if (afi
== AFI_IP
) {
6843 "./set-action[action='frr-bgp-route-map:ipv4-vpn-address']";
6844 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6847 "./set-action[action='frr-bgp-route-map:ipv6-vpn-address']";
6848 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6850 return nb_cli_apply_changes(vty
, NULL
);
6854 #endif /* KEEP_OLD_VPN_COMMANDS */
6856 DEFPY_YANG (set_ipx_vpn_nexthop
,
6857 set_ipx_vpn_nexthop_cmd
,
6858 "set <ipv4|ipv6> vpn next-hop <A.B.C.D$addrv4|X:X::X:X$addrv6>",
6860 "IPv4 information\n"
6861 "IPv6 information\n"
6863 "VPN next-hop address\n"
6864 "IP address of next hop\n"
6865 "IPv6 address of next hop\n")
6870 char xpath_value
[XPATH_MAXLEN
];
6872 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
6873 if (afi
== AFI_IP
) {
6875 vty_out(vty
, "%% IPv4 next-hop expected\n");
6876 return CMD_WARNING_CONFIG_FAILED
;
6880 "./set-action[action='frr-bgp-route-map:ipv4-vpn-address']";
6882 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6884 xpath_value
, sizeof(xpath_value
),
6885 "%s/rmap-set-action/frr-bgp-route-map:ipv4-address",
6889 vty_out(vty
, "%% IPv6 next-hop expected\n");
6890 return CMD_WARNING_CONFIG_FAILED
;
6894 "./set-action[action='frr-bgp-route-map:ipv6-vpn-address']";
6896 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6898 xpath_value
, sizeof(xpath_value
),
6899 "%s/rmap-set-action/frr-bgp-route-map:ipv6-address",
6902 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6904 return nb_cli_apply_changes(vty
, NULL
);
6909 DEFUN_YANG (no_set_ipx_vpn_nexthop
,
6910 no_set_ipx_vpn_nexthop_cmd
,
6911 "no set <ipv4|ipv6> vpn next-hop [<A.B.C.D|X:X::X:X>]",
6914 "IPv4 information\n"
6915 "IPv6 information\n"
6917 "VPN next-hop address\n"
6918 "IP address of next hop\n"
6919 "IPv6 address of next hop\n")
6924 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
6925 if (afi
== AFI_IP
) {
6927 "./set-action[action='frr-bgp-route-map:ipv4-vpn-address']";
6928 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6931 "./set-action[action='frr-bgp-route-map:ipv6-vpn-address']";
6932 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6934 return nb_cli_apply_changes(vty
, NULL
);
6939 DEFUN_YANG (set_originator_id
,
6940 set_originator_id_cmd
,
6941 "set originator-id A.B.C.D",
6943 "BGP originator ID attribute\n"
6944 "IP address of originator\n")
6948 "./set-action[action='frr-bgp-route-map:originator-id']";
6949 char xpath_value
[XPATH_MAXLEN
];
6951 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6952 snprintf(xpath_value
, sizeof(xpath_value
),
6953 "%s/rmap-set-action/frr-bgp-route-map:originator-id", xpath
);
6954 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6955 argv
[idx_ipv4
]->arg
);
6957 return nb_cli_apply_changes(vty
, NULL
);
6960 DEFUN_YANG (no_set_originator_id
,
6961 no_set_originator_id_cmd
,
6962 "no set originator-id [A.B.C.D]",
6965 "BGP originator ID attribute\n"
6966 "IP address of originator\n")
6969 "./set-action[action='frr-bgp-route-map:originator-id']";
6971 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6972 return nb_cli_apply_changes(vty
, NULL
);
6975 DEFPY_YANG (match_rpki_extcommunity
,
6976 match_rpki_extcommunity_cmd
,
6977 "[no$no] match rpki-extcommunity <valid|invalid|notfound>",
6980 "BGP RPKI (Origin Validation State) extended community attribute\n"
6983 "Prefix not found\n")
6986 "./match-condition[condition='frr-bgp-route-map:rpki-extcommunity']";
6987 char xpath_value
[XPATH_MAXLEN
];
6989 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6993 xpath_value
, sizeof(xpath_value
),
6994 "%s/rmap-match-condition/frr-bgp-route-map:rpki-extcommunity",
6996 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
7000 return nb_cli_apply_changes(vty
, NULL
);
7003 /* Initialization of route map. */
7004 void bgp_route_map_init(void)
7008 route_map_add_hook(bgp_route_map_add
);
7009 route_map_delete_hook(bgp_route_map_delete
);
7010 route_map_event_hook(bgp_route_map_event
);
7012 route_map_match_interface_hook(generic_match_add
);
7013 route_map_no_match_interface_hook(generic_match_delete
);
7015 route_map_match_ip_address_hook(generic_match_add
);
7016 route_map_no_match_ip_address_hook(generic_match_delete
);
7018 route_map_match_ip_address_prefix_list_hook(generic_match_add
);
7019 route_map_no_match_ip_address_prefix_list_hook(generic_match_delete
);
7021 route_map_match_ip_next_hop_hook(generic_match_add
);
7022 route_map_no_match_ip_next_hop_hook(generic_match_delete
);
7024 route_map_match_ipv6_next_hop_hook(generic_match_add
);
7025 route_map_no_match_ipv6_next_hop_hook(generic_match_delete
);
7027 route_map_match_ip_next_hop_prefix_list_hook(generic_match_add
);
7028 route_map_no_match_ip_next_hop_prefix_list_hook(generic_match_delete
);
7030 route_map_match_ip_next_hop_type_hook(generic_match_add
);
7031 route_map_no_match_ip_next_hop_type_hook(generic_match_delete
);
7033 route_map_match_ipv6_address_hook(generic_match_add
);
7034 route_map_no_match_ipv6_address_hook(generic_match_delete
);
7036 route_map_match_ipv6_address_prefix_list_hook(generic_match_add
);
7037 route_map_no_match_ipv6_address_prefix_list_hook(generic_match_delete
);
7039 route_map_match_ipv6_next_hop_type_hook(generic_match_add
);
7040 route_map_no_match_ipv6_next_hop_type_hook(generic_match_delete
);
7042 route_map_match_ipv6_next_hop_prefix_list_hook(generic_match_add
);
7043 route_map_no_match_ipv6_next_hop_prefix_list_hook(generic_match_delete
);
7045 route_map_match_metric_hook(generic_match_add
);
7046 route_map_no_match_metric_hook(generic_match_delete
);
7048 route_map_match_tag_hook(generic_match_add
);
7049 route_map_no_match_tag_hook(generic_match_delete
);
7051 route_map_set_srte_color_hook(generic_set_add
);
7052 route_map_no_set_srte_color_hook(generic_set_delete
);
7054 route_map_set_ip_nexthop_hook(generic_set_add
);
7055 route_map_no_set_ip_nexthop_hook(generic_set_delete
);
7057 route_map_set_ipv6_nexthop_local_hook(generic_set_add
);
7058 route_map_no_set_ipv6_nexthop_local_hook(generic_set_delete
);
7060 route_map_set_metric_hook(generic_set_add
);
7061 route_map_no_set_metric_hook(generic_set_delete
);
7063 route_map_set_tag_hook(generic_set_add
);
7064 route_map_no_set_tag_hook(generic_set_delete
);
7066 route_map_install_match(&route_match_peer_cmd
);
7067 route_map_install_match(&route_match_alias_cmd
);
7068 route_map_install_match(&route_match_local_pref_cmd
);
7069 #ifdef HAVE_SCRIPTING
7070 route_map_install_match(&route_match_script_cmd
);
7072 route_map_install_match(&route_match_ip_address_cmd
);
7073 route_map_install_match(&route_match_ip_next_hop_cmd
);
7074 route_map_install_match(&route_match_ip_route_source_cmd
);
7075 route_map_install_match(&route_match_ip_address_prefix_list_cmd
);
7076 route_map_install_match(&route_match_ip_next_hop_prefix_list_cmd
);
7077 route_map_install_match(&route_match_ip_next_hop_type_cmd
);
7078 route_map_install_match(&route_match_ip_route_source_prefix_list_cmd
);
7079 route_map_install_match(&route_match_aspath_cmd
);
7080 route_map_install_match(&route_match_community_cmd
);
7081 route_map_install_match(&route_match_lcommunity_cmd
);
7082 route_map_install_match(&route_match_ecommunity_cmd
);
7083 route_map_install_match(&route_match_local_pref_cmd
);
7084 route_map_install_match(&route_match_metric_cmd
);
7085 route_map_install_match(&route_match_origin_cmd
);
7086 route_map_install_match(&route_match_probability_cmd
);
7087 route_map_install_match(&route_match_interface_cmd
);
7088 route_map_install_match(&route_match_tag_cmd
);
7089 route_map_install_match(&route_match_mac_address_cmd
);
7090 route_map_install_match(&route_match_evpn_vni_cmd
);
7091 route_map_install_match(&route_match_evpn_route_type_cmd
);
7092 route_map_install_match(&route_match_evpn_rd_cmd
);
7093 route_map_install_match(&route_match_evpn_default_route_cmd
);
7094 route_map_install_match(&route_match_vrl_source_vrf_cmd
);
7096 route_map_install_set(&route_set_evpn_gateway_ip_ipv4_cmd
);
7097 route_map_install_set(&route_set_evpn_gateway_ip_ipv6_cmd
);
7098 route_map_install_set(&route_set_table_id_cmd
);
7099 route_map_install_set(&route_set_srte_color_cmd
);
7100 route_map_install_set(&route_set_ip_nexthop_cmd
);
7101 route_map_install_set(&route_set_local_pref_cmd
);
7102 route_map_install_set(&route_set_weight_cmd
);
7103 route_map_install_set(&route_set_label_index_cmd
);
7104 route_map_install_set(&route_set_metric_cmd
);
7105 route_map_install_set(&route_set_distance_cmd
);
7106 route_map_install_set(&route_set_aspath_prepend_cmd
);
7107 route_map_install_set(&route_set_aspath_exclude_cmd
);
7108 route_map_install_set(&route_set_aspath_replace_cmd
);
7109 route_map_install_set(&route_set_origin_cmd
);
7110 route_map_install_set(&route_set_atomic_aggregate_cmd
);
7111 route_map_install_set(&route_set_aigp_metric_cmd
);
7112 route_map_install_set(&route_set_aggregator_as_cmd
);
7113 route_map_install_set(&route_set_community_cmd
);
7114 route_map_install_set(&route_set_community_delete_cmd
);
7115 route_map_install_set(&route_set_lcommunity_cmd
);
7116 route_map_install_set(&route_set_lcommunity_delete_cmd
);
7117 route_map_install_set(&route_set_vpnv4_nexthop_cmd
);
7118 route_map_install_set(&route_set_vpnv6_nexthop_cmd
);
7119 route_map_install_set(&route_set_originator_id_cmd
);
7120 route_map_install_set(&route_set_ecommunity_rt_cmd
);
7121 route_map_install_set(&route_set_ecommunity_soo_cmd
);
7122 route_map_install_set(&route_set_ecommunity_lb_cmd
);
7123 route_map_install_set(&route_set_ecommunity_none_cmd
);
7124 route_map_install_set(&route_set_tag_cmd
);
7125 route_map_install_set(&route_set_label_index_cmd
);
7126 route_map_install_set(&route_set_l3vpn_nexthop_encapsulation_cmd
);
7128 install_element(RMAP_NODE
, &match_peer_cmd
);
7129 install_element(RMAP_NODE
, &match_peer_local_cmd
);
7130 install_element(RMAP_NODE
, &no_match_peer_cmd
);
7131 install_element(RMAP_NODE
, &match_ip_route_source_cmd
);
7132 install_element(RMAP_NODE
, &no_match_ip_route_source_cmd
);
7133 install_element(RMAP_NODE
, &match_ip_route_source_prefix_list_cmd
);
7134 install_element(RMAP_NODE
, &no_match_ip_route_source_prefix_list_cmd
);
7135 install_element(RMAP_NODE
, &match_mac_address_cmd
);
7136 install_element(RMAP_NODE
, &no_match_mac_address_cmd
);
7137 install_element(RMAP_NODE
, &match_evpn_vni_cmd
);
7138 install_element(RMAP_NODE
, &no_match_evpn_vni_cmd
);
7139 install_element(RMAP_NODE
, &match_evpn_route_type_cmd
);
7140 install_element(RMAP_NODE
, &no_match_evpn_route_type_cmd
);
7141 install_element(RMAP_NODE
, &match_evpn_rd_cmd
);
7142 install_element(RMAP_NODE
, &no_match_evpn_rd_cmd
);
7143 install_element(RMAP_NODE
, &match_evpn_default_route_cmd
);
7144 install_element(RMAP_NODE
, &no_match_evpn_default_route_cmd
);
7145 install_element(RMAP_NODE
, &set_evpn_gw_ip_ipv4_cmd
);
7146 install_element(RMAP_NODE
, &no_set_evpn_gw_ip_ipv4_cmd
);
7147 install_element(RMAP_NODE
, &set_evpn_gw_ip_ipv6_cmd
);
7148 install_element(RMAP_NODE
, &no_set_evpn_gw_ip_ipv6_cmd
);
7149 install_element(RMAP_NODE
, &match_vrl_source_vrf_cmd
);
7150 install_element(RMAP_NODE
, &no_match_vrl_source_vrf_cmd
);
7152 install_element(RMAP_NODE
, &match_aspath_cmd
);
7153 install_element(RMAP_NODE
, &no_match_aspath_cmd
);
7154 install_element(RMAP_NODE
, &match_local_pref_cmd
);
7155 install_element(RMAP_NODE
, &no_match_local_pref_cmd
);
7156 install_element(RMAP_NODE
, &match_alias_cmd
);
7157 install_element(RMAP_NODE
, &no_match_alias_cmd
);
7158 install_element(RMAP_NODE
, &match_community_cmd
);
7159 install_element(RMAP_NODE
, &no_match_community_cmd
);
7160 install_element(RMAP_NODE
, &match_lcommunity_cmd
);
7161 install_element(RMAP_NODE
, &no_match_lcommunity_cmd
);
7162 install_element(RMAP_NODE
, &match_ecommunity_cmd
);
7163 install_element(RMAP_NODE
, &no_match_ecommunity_cmd
);
7164 install_element(RMAP_NODE
, &match_origin_cmd
);
7165 install_element(RMAP_NODE
, &no_match_origin_cmd
);
7166 install_element(RMAP_NODE
, &match_probability_cmd
);
7167 install_element(RMAP_NODE
, &no_match_probability_cmd
);
7169 install_element(RMAP_NODE
, &no_set_table_id_cmd
);
7170 install_element(RMAP_NODE
, &set_table_id_cmd
);
7171 install_element(RMAP_NODE
, &set_ip_nexthop_peer_cmd
);
7172 install_element(RMAP_NODE
, &set_ip_nexthop_unchanged_cmd
);
7173 install_element(RMAP_NODE
, &set_local_pref_cmd
);
7174 install_element(RMAP_NODE
, &set_distance_cmd
);
7175 install_element(RMAP_NODE
, &no_set_distance_cmd
);
7176 install_element(RMAP_NODE
, &no_set_local_pref_cmd
);
7177 install_element(RMAP_NODE
, &set_weight_cmd
);
7178 install_element(RMAP_NODE
, &set_label_index_cmd
);
7179 install_element(RMAP_NODE
, &no_set_weight_cmd
);
7180 install_element(RMAP_NODE
, &no_set_label_index_cmd
);
7181 install_element(RMAP_NODE
, &set_aspath_prepend_asn_cmd
);
7182 install_element(RMAP_NODE
, &set_aspath_prepend_lastas_cmd
);
7183 install_element(RMAP_NODE
, &set_aspath_exclude_cmd
);
7184 install_element(RMAP_NODE
, &set_aspath_replace_asn_cmd
);
7185 install_element(RMAP_NODE
, &no_set_aspath_prepend_cmd
);
7186 install_element(RMAP_NODE
, &no_set_aspath_prepend_lastas_cmd
);
7187 install_element(RMAP_NODE
, &no_set_aspath_exclude_cmd
);
7188 install_element(RMAP_NODE
, &no_set_aspath_exclude_all_cmd
);
7189 install_element(RMAP_NODE
, &no_set_aspath_replace_asn_cmd
);
7190 install_element(RMAP_NODE
, &set_origin_cmd
);
7191 install_element(RMAP_NODE
, &no_set_origin_cmd
);
7192 install_element(RMAP_NODE
, &set_atomic_aggregate_cmd
);
7193 install_element(RMAP_NODE
, &no_set_atomic_aggregate_cmd
);
7194 install_element(RMAP_NODE
, &set_aigp_metric_cmd
);
7195 install_element(RMAP_NODE
, &no_set_aigp_metric_cmd
);
7196 install_element(RMAP_NODE
, &set_aggregator_as_cmd
);
7197 install_element(RMAP_NODE
, &no_set_aggregator_as_cmd
);
7198 install_element(RMAP_NODE
, &set_community_cmd
);
7199 install_element(RMAP_NODE
, &set_community_none_cmd
);
7200 install_element(RMAP_NODE
, &no_set_community_cmd
);
7201 install_element(RMAP_NODE
, &no_set_community_short_cmd
);
7202 install_element(RMAP_NODE
, &set_community_delete_cmd
);
7203 install_element(RMAP_NODE
, &no_set_community_delete_cmd
);
7204 install_element(RMAP_NODE
, &set_lcommunity_cmd
);
7205 install_element(RMAP_NODE
, &set_lcommunity_none_cmd
);
7206 install_element(RMAP_NODE
, &no_set_lcommunity_cmd
);
7207 install_element(RMAP_NODE
, &no_set_lcommunity1_cmd
);
7208 install_element(RMAP_NODE
, &no_set_lcommunity1_short_cmd
);
7209 install_element(RMAP_NODE
, &set_lcommunity_delete_cmd
);
7210 install_element(RMAP_NODE
, &no_set_lcommunity_delete_cmd
);
7211 install_element(RMAP_NODE
, &no_set_lcommunity_delete_short_cmd
);
7212 install_element(RMAP_NODE
, &set_ecommunity_rt_cmd
);
7213 install_element(RMAP_NODE
, &no_set_ecommunity_rt_cmd
);
7214 install_element(RMAP_NODE
, &no_set_ecommunity_rt_short_cmd
);
7215 install_element(RMAP_NODE
, &set_ecommunity_soo_cmd
);
7216 install_element(RMAP_NODE
, &no_set_ecommunity_soo_cmd
);
7217 install_element(RMAP_NODE
, &no_set_ecommunity_soo_short_cmd
);
7218 install_element(RMAP_NODE
, &set_ecommunity_lb_cmd
);
7219 install_element(RMAP_NODE
, &no_set_ecommunity_lb_cmd
);
7220 install_element(RMAP_NODE
, &no_set_ecommunity_lb_short_cmd
);
7221 install_element(RMAP_NODE
, &set_ecommunity_none_cmd
);
7222 install_element(RMAP_NODE
, &no_set_ecommunity_none_cmd
);
7223 #ifdef KEEP_OLD_VPN_COMMANDS
7224 install_element(RMAP_NODE
, &set_vpn_nexthop_cmd
);
7225 install_element(RMAP_NODE
, &no_set_vpn_nexthop_cmd
);
7226 #endif /* KEEP_OLD_VPN_COMMANDS */
7227 install_element(RMAP_NODE
, &set_ipx_vpn_nexthop_cmd
);
7228 install_element(RMAP_NODE
, &no_set_ipx_vpn_nexthop_cmd
);
7229 install_element(RMAP_NODE
, &set_originator_id_cmd
);
7230 install_element(RMAP_NODE
, &no_set_originator_id_cmd
);
7231 install_element(RMAP_NODE
, &set_l3vpn_nexthop_encapsulation_cmd
);
7233 route_map_install_match(&route_match_ipv6_address_cmd
);
7234 route_map_install_match(&route_match_ipv6_next_hop_cmd
);
7235 route_map_install_match(&route_match_ipv6_next_hop_address_cmd
);
7236 route_map_install_match(&route_match_ipv6_next_hop_prefix_list_cmd
);
7237 route_map_install_match(&route_match_ipv4_next_hop_cmd
);
7238 route_map_install_match(&route_match_ipv6_address_prefix_list_cmd
);
7239 route_map_install_match(&route_match_ipv6_next_hop_type_cmd
);
7240 route_map_install_set(&route_set_ipv6_nexthop_global_cmd
);
7241 route_map_install_set(&route_set_ipv6_nexthop_prefer_global_cmd
);
7242 route_map_install_set(&route_set_ipv6_nexthop_local_cmd
);
7243 route_map_install_set(&route_set_ipv6_nexthop_peer_cmd
);
7244 route_map_install_match(&route_match_rpki_extcommunity_cmd
);
7246 install_element(RMAP_NODE
, &match_ipv6_next_hop_cmd
);
7247 install_element(RMAP_NODE
, &match_ipv6_next_hop_address_cmd
);
7248 install_element(RMAP_NODE
, &match_ipv6_next_hop_prefix_list_cmd
);
7249 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_cmd
);
7250 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_address_cmd
);
7251 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_prefix_list_cmd
);
7252 install_element(RMAP_NODE
, &match_ipv6_next_hop_old_cmd
);
7253 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_old_cmd
);
7254 install_element(RMAP_NODE
, &match_ipv4_next_hop_cmd
);
7255 install_element(RMAP_NODE
, &no_match_ipv4_next_hop_cmd
);
7256 install_element(RMAP_NODE
, &set_ipv6_nexthop_global_cmd
);
7257 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_global_cmd
);
7258 install_element(RMAP_NODE
, &set_ipv6_nexthop_prefer_global_cmd
);
7259 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_prefer_global_cmd
);
7260 install_element(RMAP_NODE
, &set_ipv6_nexthop_peer_cmd
);
7261 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_peer_cmd
);
7262 install_element(RMAP_NODE
, &match_rpki_extcommunity_cmd
);
7263 #ifdef HAVE_SCRIPTING
7264 install_element(RMAP_NODE
, &match_script_cmd
);
7268 void bgp_route_map_terminate(void)
7270 /* ToDo: Cleanup all the used memory */