1 /* Route map function of bgpd.
2 * Copyright (C) 1998, 1999 Kunihiro Ishiguro
4 * This file is part of GNU Zebra.
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32 #include "frrscript.h"
33 #ifdef HAVE_LIBPCREPOSIX
34 #include <pcreposix.h>
37 #endif /* HAVE_LIBPCREPOSIX */
39 #include "sockunion.h"
44 #include "lib/northbound_cli.h"
46 #include "bgpd/bgpd.h"
47 #include "bgpd/bgp_table.h"
48 #include "bgpd/bgp_attr.h"
49 #include "bgpd/bgp_aspath.h"
50 #include "bgpd/bgp_packet.h"
51 #include "bgpd/bgp_route.h"
52 #include "bgpd/bgp_zebra.h"
53 #include "bgpd/bgp_regex.h"
54 #include "bgpd/bgp_community.h"
55 #include "bgpd/bgp_community_alias.h"
56 #include "bgpd/bgp_clist.h"
57 #include "bgpd/bgp_filter.h"
58 #include "bgpd/bgp_mplsvpn.h"
59 #include "bgpd/bgp_ecommunity.h"
60 #include "bgpd/bgp_lcommunity.h"
61 #include "bgpd/bgp_vty.h"
62 #include "bgpd/bgp_debug.h"
63 #include "bgpd/bgp_evpn.h"
64 #include "bgpd/bgp_evpn_private.h"
65 #include "bgpd/bgp_evpn_vty.h"
66 #include "bgpd/bgp_mplsvpn.h"
67 #include "bgpd/bgp_pbr.h"
68 #include "bgpd/bgp_flowspec_util.h"
69 #include "bgpd/bgp_encap_types.h"
70 #include "bgpd/bgp_mpath.h"
71 #include "bgpd/bgp_script.h"
74 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
77 #include "bgpd/bgp_routemap_clippy.c"
79 /* Memo of route-map commands.
88 ip route-source : Done
92 ipv6 route-source: (This will not be implemented by bgpd)
93 ipv6 prefix-list : Done
94 length : (This will not be implemented by bgpd)
96 route-type : (This will not be implemented by bgpd)
98 local-preference : Done
100 set as-path prepend : Done
101 as-path tag : Not yet
102 automatic-tag : (This will not be implemented by bgpd)
104 large-community : Done
105 large-comm-list : Done
108 default : (This will not be implemented by bgpd)
109 interface : (This will not be implemented by bgpd)
110 ip default : (This will not be implemented by bgpd)
112 ip precedence : (This will not be implemented by bgpd)
113 ip tos : (This will not be implemented by bgpd)
114 level : (This will not be implemented by bgpd)
115 local-preference : Done
117 metric-type : Not yet
125 set ipv6 next-hop global: Done
126 set ipv6 next-hop prefer-global: Done
127 set ipv6 next-hop local : Done
128 set as-path exclude : Done
132 /* generic value manipulation to be shared in multiple rules */
134 #define RMAP_VALUE_SET 0
135 #define RMAP_VALUE_ADD 1
136 #define RMAP_VALUE_SUB 2
144 static int route_value_match(struct rmap_value
*rv
, uint32_t value
)
146 if (rv
->variable
== 0 && value
== rv
->value
)
152 static uint32_t route_value_adjust(struct rmap_value
*rv
, uint32_t current
,
157 switch (rv
->variable
) {
166 switch (rv
->action
) {
168 if (current
> UINT32_MAX
- value
)
170 return current
+ value
;
172 if (current
<= value
)
174 return current
- value
;
180 static void *route_value_compile(const char *arg
)
182 uint8_t action
= RMAP_VALUE_SET
, var
= 0;
183 unsigned long larg
= 0;
185 struct rmap_value
*rv
;
188 action
= RMAP_VALUE_ADD
;
190 } else if (arg
[0] == '-') {
191 action
= RMAP_VALUE_SUB
;
195 if (all_digit(arg
)) {
197 larg
= strtoul(arg
, &endptr
, 10);
198 if (*arg
== 0 || *endptr
!= 0 || errno
|| larg
> UINT32_MAX
)
201 if (strcmp(arg
, "rtt") == 0)
207 rv
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_value
));
215 static void route_value_free(void *rule
)
217 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
220 /* generic as path object to be shared in multiple rules */
222 static void *route_aspath_compile(const char *arg
)
224 struct aspath
*aspath
;
226 aspath
= aspath_str2aspath(arg
);
232 static void route_aspath_free(void *rule
)
234 struct aspath
*aspath
= rule
;
238 struct bgp_match_peer_compiled
{
243 /* 'match peer (A.B.C.D|X:X::X:X|WORD)' */
245 /* Compares the peer specified in the 'match peer' clause with the peer
246 received in bgp_path_info->peer. If it is the same, or if the peer structure
247 received is a peer_group containing it, returns RMAP_MATCH. */
248 static enum route_map_cmd_result_t
249 route_match_peer(void *rule
, const struct prefix
*prefix
, void *object
)
251 struct bgp_match_peer_compiled
*pc
;
253 union sockunion su_def
= {
254 .sin
= {.sin_family
= AF_INET
, .sin_addr
.s_addr
= INADDR_ANY
}};
255 struct peer_group
*group
;
257 struct listnode
*node
, *nnode
;
261 peer
= ((struct bgp_path_info
*)object
)->peer
;
264 if (!peer
->conf_if
|| !peer
->group
)
267 if (peer
->conf_if
&& strcmp(peer
->conf_if
, pc
->interface
) == 0)
271 strcmp(peer
->group
->name
, pc
->interface
) == 0)
277 /* If su='0.0.0.0' (command 'match peer local'), and it's a
279 REDISTRIBUTE, AGGREGATE-ADDRESS or DEFAULT_GENERATED route
282 if (sockunion_same(su
, &su_def
)) {
284 if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_NETWORK
)
285 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_REDISTRIBUTE
)
286 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_AGGREGATE
)
287 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_DEFAULT
))
294 if (!CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
)) {
295 if (sockunion_same(su
, &peer
->su
))
301 for (ALL_LIST_ELEMENTS(group
->peer
, node
, nnode
, peer
)) {
302 if (sockunion_same(su
, &peer
->su
))
311 static void *route_match_peer_compile(const char *arg
)
313 struct bgp_match_peer_compiled
*pc
;
316 pc
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
317 sizeof(struct bgp_match_peer_compiled
));
319 ret
= str2sockunion(strcmp(arg
, "local") ? arg
: "0.0.0.0", &pc
->su
);
321 pc
->interface
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
328 /* Free route map's compiled `ip address' value. */
329 static void route_match_peer_free(void *rule
)
331 struct bgp_match_peer_compiled
*pc
= rule
;
333 XFREE(MTYPE_ROUTE_MAP_COMPILED
, pc
->interface
);
335 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
338 /* Route map commands for ip address matching. */
339 static const struct route_map_rule_cmd route_match_peer_cmd
= {
342 route_match_peer_compile
,
343 route_match_peer_free
346 #ifdef HAVE_SCRIPTING
348 enum frrlua_rm_status
{
350 * Script function run failure. This will translate into a deny
354 * No Match was found for the route map function
358 * Match was found but no changes were made to the incoming data.
362 * Match was found and data was modified, so figure out what changed
364 LUA_RM_MATCH_AND_CHANGE
,
367 static enum route_map_cmd_result_t
368 route_match_script(void *rule
, const struct prefix
*prefix
, void *object
)
370 const char *scriptname
= rule
;
371 const char *routematch_function
= "route_match";
372 struct bgp_path_info
*path
= (struct bgp_path_info
*)object
;
374 struct frrscript
*fs
= frrscript_new(scriptname
);
376 if (frrscript_load(fs
, routematch_function
, NULL
)) {
378 "Issue loading script or function; defaulting to no match");
382 struct attr newattr
= *path
->attr
;
384 int result
= frrscript_call(
385 fs
, routematch_function
, ("prefix", prefix
),
386 ("attributes", &newattr
), ("peer", path
->peer
),
387 ("RM_FAILURE", LUA_RM_FAILURE
), ("RM_NOMATCH", LUA_RM_NOMATCH
),
388 ("RM_MATCH", LUA_RM_MATCH
),
389 ("RM_MATCH_AND_CHANGE", LUA_RM_MATCH_AND_CHANGE
));
392 zlog_err("Issue running script rule; defaulting to no match");
396 long long *action
= frrscript_get_result(fs
, routematch_function
,
397 "action", lua_tointegerp
);
399 int status
= RMAP_NOMATCH
;
404 "Executing route-map match script '%s' failed; defaulting to no match",
406 status
= RMAP_NOMATCH
;
409 status
= RMAP_NOMATCH
;
411 case LUA_RM_MATCH_AND_CHANGE
:
413 zlog_debug("Updating attribute based on script's values");
415 uint32_t locpref
= 0;
417 path
->attr
->med
= newattr
.med
;
419 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
))
420 locpref
= path
->attr
->local_pref
;
421 if (locpref
!= newattr
.local_pref
) {
422 SET_FLAG(path
->attr
->flag
,
423 ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
));
424 path
->attr
->local_pref
= newattr
.local_pref
;
432 XFREE(MTYPE_SCRIPT_RES
, action
);
434 frrscript_delete(fs
);
439 static void *route_match_script_compile(const char *arg
)
443 scriptname
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
448 static void route_match_script_free(void *rule
)
450 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
453 static const struct route_map_rule_cmd route_match_script_cmd
= {
456 route_match_script_compile
,
457 route_match_script_free
460 #endif /* HAVE_SCRIPTING */
462 /* `match ip address IP_ACCESS_LIST' */
464 /* Match function should return 1 if match is success else return
466 static enum route_map_cmd_result_t
467 route_match_ip_address(void *rule
, const struct prefix
*prefix
, void *object
)
469 struct access_list
*alist
;
471 if (prefix
->family
== AF_INET
) {
472 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
476 return (access_list_apply(alist
, prefix
) == FILTER_DENY
483 /* Route map `ip address' match statement. `arg' should be
485 static void *route_match_ip_address_compile(const char *arg
)
487 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
490 /* Free route map's compiled `ip address' value. */
491 static void route_match_ip_address_free(void *rule
)
493 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
496 /* Route map commands for ip address matching. */
497 static const struct route_map_rule_cmd route_match_ip_address_cmd
= {
499 route_match_ip_address
,
500 route_match_ip_address_compile
,
501 route_match_ip_address_free
504 /* `match ip next-hop IP_ADDRESS' */
506 /* Match function return 1 if match is success else return zero. */
507 static enum route_map_cmd_result_t
508 route_match_ip_next_hop(void *rule
, const struct prefix
*prefix
, void *object
)
510 struct access_list
*alist
;
511 struct bgp_path_info
*path
;
512 struct prefix_ipv4 p
;
514 if (prefix
->family
== AF_INET
) {
517 p
.prefix
= path
->attr
->nexthop
;
518 p
.prefixlen
= IPV4_MAX_BITLEN
;
520 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
524 return (access_list_apply(alist
, &p
) == FILTER_DENY
531 /* Route map `ip next-hop' match statement. `arg' is
533 static void *route_match_ip_next_hop_compile(const char *arg
)
535 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
538 /* Free route map's compiled `ip address' value. */
539 static void route_match_ip_next_hop_free(void *rule
)
541 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
544 /* Route map commands for ip next-hop matching. */
545 static const struct route_map_rule_cmd route_match_ip_next_hop_cmd
= {
547 route_match_ip_next_hop
,
548 route_match_ip_next_hop_compile
,
549 route_match_ip_next_hop_free
552 /* `match ip route-source ACCESS-LIST' */
554 /* Match function return 1 if match is success else return zero. */
555 static enum route_map_cmd_result_t
556 route_match_ip_route_source(void *rule
, const struct prefix
*pfx
, void *object
)
558 struct access_list
*alist
;
559 struct bgp_path_info
*path
;
561 struct prefix_ipv4 p
;
563 if (pfx
->family
== AF_INET
) {
567 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
571 p
.prefix
= peer
->su
.sin
.sin_addr
;
572 p
.prefixlen
= IPV4_MAX_BITLEN
;
574 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
578 return (access_list_apply(alist
, &p
) == FILTER_DENY
585 /* Route map `ip route-source' match statement. `arg' is
587 static void *route_match_ip_route_source_compile(const char *arg
)
589 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
592 /* Free route map's compiled `ip address' value. */
593 static void route_match_ip_route_source_free(void *rule
)
595 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
598 /* Route map commands for ip route-source matching. */
599 static const struct route_map_rule_cmd route_match_ip_route_source_cmd
= {
601 route_match_ip_route_source
,
602 route_match_ip_route_source_compile
,
603 route_match_ip_route_source_free
606 static enum route_map_cmd_result_t
607 route_match_prefix_list_flowspec(afi_t afi
, struct prefix_list
*plist
,
608 const struct prefix
*p
)
611 struct bgp_pbr_entry_main api
;
613 memset(&api
, 0, sizeof(api
));
615 if (family2afi(p
->u
.prefix_flowspec
.family
) != afi
)
618 /* extract match from flowspec entries */
619 ret
= bgp_flowspec_match_rules_fill(
620 (uint8_t *)p
->u
.prefix_flowspec
.ptr
,
621 p
->u
.prefix_flowspec
.prefixlen
, &api
,
625 if (api
.match_bitmask
& PREFIX_DST_PRESENT
||
626 api
.match_bitmask_iprule
& PREFIX_DST_PRESENT
) {
627 if (family2afi((&api
.dst_prefix
)->family
) != afi
)
629 return prefix_list_apply(plist
, &api
.dst_prefix
) == PREFIX_DENY
632 } else if (api
.match_bitmask
& PREFIX_SRC_PRESENT
||
633 api
.match_bitmask_iprule
& PREFIX_SRC_PRESENT
) {
634 if (family2afi((&api
.src_prefix
)->family
) != afi
)
636 return (prefix_list_apply(plist
, &api
.src_prefix
) == PREFIX_DENY
643 static enum route_map_cmd_result_t
644 route_match_prefix_list_evpn(afi_t afi
, struct prefix_list
*plist
,
645 const struct prefix
*p
)
647 /* Convert to match a general plist */
650 if (evpn_prefix2prefix(p
, &new))
653 return (prefix_list_apply(plist
, &new) == PREFIX_DENY
? RMAP_NOMATCH
657 static enum route_map_cmd_result_t
658 route_match_address_prefix_list(void *rule
, afi_t afi
,
659 const struct prefix
*prefix
, void *object
)
661 struct prefix_list
*plist
;
663 plist
= prefix_list_lookup(afi
, (char *)rule
);
667 if (prefix
->family
== AF_FLOWSPEC
)
668 return route_match_prefix_list_flowspec(afi
, plist
,
671 else if (prefix
->family
== AF_EVPN
)
672 return route_match_prefix_list_evpn(afi
, plist
, prefix
);
674 return (prefix_list_apply(plist
, prefix
) == PREFIX_DENY
? RMAP_NOMATCH
678 static enum route_map_cmd_result_t
679 route_match_ip_address_prefix_list(void *rule
, const struct prefix
*prefix
,
682 return route_match_address_prefix_list(rule
, AFI_IP
, prefix
, object
);
685 static void *route_match_ip_address_prefix_list_compile(const char *arg
)
687 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
690 static void route_match_ip_address_prefix_list_free(void *rule
)
692 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
695 static const struct route_map_rule_cmd
696 route_match_ip_address_prefix_list_cmd
= {
697 "ip address prefix-list",
698 route_match_ip_address_prefix_list
,
699 route_match_ip_address_prefix_list_compile
,
700 route_match_ip_address_prefix_list_free
703 /* `match ip next-hop prefix-list PREFIX_LIST' */
705 static enum route_map_cmd_result_t
706 route_match_ip_next_hop_prefix_list(void *rule
, const struct prefix
*prefix
,
709 struct prefix_list
*plist
;
710 struct bgp_path_info
*path
;
711 struct prefix_ipv4 p
;
713 if (prefix
->family
== AF_INET
) {
716 p
.prefix
= path
->attr
->nexthop
;
717 p
.prefixlen
= IPV4_MAX_BITLEN
;
719 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
723 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
730 static void *route_match_ip_next_hop_prefix_list_compile(const char *arg
)
732 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
735 static void route_match_ip_next_hop_prefix_list_free(void *rule
)
737 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
740 static const struct route_map_rule_cmd
741 route_match_ip_next_hop_prefix_list_cmd
= {
742 "ip next-hop prefix-list",
743 route_match_ip_next_hop_prefix_list
,
744 route_match_ip_next_hop_prefix_list_compile
,
745 route_match_ip_next_hop_prefix_list_free
748 /* `match ipv6 next-hop prefix-list PREFIXLIST_NAME' */
749 static enum route_map_cmd_result_t
750 route_match_ipv6_next_hop_prefix_list(void *rule
, const struct prefix
*prefix
,
753 struct prefix_list
*plist
;
754 struct bgp_path_info
*path
;
755 struct prefix_ipv6 p
;
757 if (prefix
->family
== AF_INET6
) {
760 p
.prefix
= path
->attr
->mp_nexthop_global
;
761 p
.prefixlen
= IPV6_MAX_BITLEN
;
763 plist
= prefix_list_lookup(AFI_IP6
, (char *)rule
);
767 if (prefix_list_apply(plist
, &p
) == PREFIX_PERMIT
)
770 if (path
->attr
->mp_nexthop_len
771 == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
) {
772 p
.prefix
= path
->attr
->mp_nexthop_local
;
773 if (prefix_list_apply(plist
, &p
) == PREFIX_PERMIT
)
781 static void *route_match_ipv6_next_hop_prefix_list_compile(const char *arg
)
783 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
786 static void route_match_ipv6_next_hop_prefix_list_free(void *rule
)
788 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
791 static const struct route_map_rule_cmd
792 route_match_ipv6_next_hop_prefix_list_cmd
= {
793 "ipv6 next-hop prefix-list",
794 route_match_ipv6_next_hop_prefix_list
,
795 route_match_ipv6_next_hop_prefix_list_compile
,
796 route_match_ipv6_next_hop_prefix_list_free
799 /* `match ip next-hop type <blackhole>' */
801 static enum route_map_cmd_result_t
802 route_match_ip_next_hop_type(void *rule
, const struct prefix
*prefix
,
805 struct bgp_path_info
*path
;
807 if (prefix
->family
== AF_INET
) {
808 path
= (struct bgp_path_info
*)object
;
812 /* If nexthop interface's index can't be resolved and nexthop is
813 set to any address then mark it as type `blackhole`.
814 This logic works for matching kernel/static routes like:
815 `ip route add blackhole 10.0.0.1`. */
816 if (path
->attr
->nexthop
.s_addr
== INADDR_ANY
817 && !path
->attr
->nh_ifindex
)
823 static void *route_match_ip_next_hop_type_compile(const char *arg
)
825 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
828 static void route_match_ip_next_hop_type_free(void *rule
)
830 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
833 static const struct route_map_rule_cmd
834 route_match_ip_next_hop_type_cmd
= {
836 route_match_ip_next_hop_type
,
837 route_match_ip_next_hop_type_compile
,
838 route_match_ip_next_hop_type_free
841 /* `match ip route-source prefix-list PREFIX_LIST' */
843 static enum route_map_cmd_result_t
844 route_match_ip_route_source_prefix_list(void *rule
, const struct prefix
*prefix
,
847 struct prefix_list
*plist
;
848 struct bgp_path_info
*path
;
850 struct prefix_ipv4 p
;
852 if (prefix
->family
== AF_INET
) {
856 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
860 p
.prefix
= peer
->su
.sin
.sin_addr
;
861 p
.prefixlen
= IPV4_MAX_BITLEN
;
863 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
867 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
874 static void *route_match_ip_route_source_prefix_list_compile(const char *arg
)
876 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
879 static void route_match_ip_route_source_prefix_list_free(void *rule
)
881 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
884 static const struct route_map_rule_cmd
885 route_match_ip_route_source_prefix_list_cmd
= {
886 "ip route-source prefix-list",
887 route_match_ip_route_source_prefix_list
,
888 route_match_ip_route_source_prefix_list_compile
,
889 route_match_ip_route_source_prefix_list_free
892 /* `match evpn default-route' */
894 /* Match function should return 1 if match is success else 0 */
895 static enum route_map_cmd_result_t
896 route_match_evpn_default_route(void *rule
, const struct prefix
*p
, void *object
)
898 if (is_evpn_prefix_default(p
))
904 /* Route map commands for default-route matching. */
905 static const struct route_map_rule_cmd
906 route_match_evpn_default_route_cmd
= {
907 "evpn default-route",
908 route_match_evpn_default_route
,
913 /* `match mac address MAC_ACCESS_LIST' */
915 /* Match function should return 1 if match is success else return
917 static enum route_map_cmd_result_t
918 route_match_mac_address(void *rule
, const struct prefix
*prefix
, void *object
)
920 struct access_list
*alist
;
923 alist
= access_list_lookup(AFI_L2VPN
, (char *)rule
);
927 if (prefix
->u
.prefix_evpn
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
930 p
.family
= AF_ETHERNET
;
931 p
.prefixlen
= ETH_ALEN
* 8;
932 p
.u
.prefix_eth
= prefix
->u
.prefix_evpn
.macip_addr
.mac
;
934 return (access_list_apply(alist
, &p
) == FILTER_DENY
? RMAP_NOMATCH
938 /* Route map `mac address' match statement. `arg' should be
940 static void *route_match_mac_address_compile(const char *arg
)
942 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
945 /* Free route map's compiled `ip address' value. */
946 static void route_match_mac_address_free(void *rule
)
948 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
951 /* Route map commands for mac address matching. */
952 static const struct route_map_rule_cmd route_match_mac_address_cmd
= {
954 route_match_mac_address
,
955 route_match_mac_address_compile
,
956 route_match_mac_address_free
960 * Match function returns:
961 * ...RMAP_MATCH if match is found.
962 * ...RMAP_NOMATCH if match is not found.
963 * ...RMAP_NOOP to ignore this match check.
965 static enum route_map_cmd_result_t
966 route_match_vni(void *rule
, const struct prefix
*prefix
, void *object
)
969 unsigned int label_cnt
= 0;
970 struct bgp_path_info
*path
= NULL
;
971 struct prefix_evpn
*evp
= (struct prefix_evpn
*) prefix
;
973 vni
= *((vni_t
*)rule
);
974 path
= (struct bgp_path_info
*)object
;
977 * This rmap filter is valid for vxlan tunnel type only.
978 * For any other tunnel type, return noop to ignore
981 if (path
->attr
->encap_tunneltype
!= BGP_ENCAP_TYPE_VXLAN
)
985 * Apply filter to type 1, 2, 5 routes only.
986 * Other route types do not have vni label.
989 && (evp
->prefix
.route_type
!= BGP_EVPN_AD_ROUTE
990 && evp
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
991 && evp
->prefix
.route_type
!= BGP_EVPN_IP_PREFIX_ROUTE
))
994 if (path
->extra
== NULL
)
998 label_cnt
< BGP_MAX_LABELS
&& label_cnt
< path
->extra
->num_labels
;
1000 if (vni
== label2vni(&path
->extra
->label
[label_cnt
]))
1004 return RMAP_NOMATCH
;
1007 /* Route map `vni' match statement. */
1008 static void *route_match_vni_compile(const char *arg
)
1013 vni
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(vni_t
));
1015 *vni
= strtoul(arg
, &end
, 10);
1017 XFREE(MTYPE_ROUTE_MAP_COMPILED
, vni
);
1024 /* Free route map's compiled `vni' value. */
1025 static void route_match_vni_free(void *rule
)
1027 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1030 /* Route map commands for vni matching. */
1031 static const struct route_map_rule_cmd route_match_evpn_vni_cmd
= {
1034 route_match_vni_compile
,
1035 route_match_vni_free
1038 /* `match evpn route-type' */
1040 /* Match function should return 1 if match is success else return
1042 static enum route_map_cmd_result_t
1043 route_match_evpn_route_type(void *rule
, const struct prefix
*pfx
, void *object
)
1045 uint8_t route_type
= 0;
1047 route_type
= *((uint8_t *)rule
);
1049 if (route_type
== pfx
->u
.prefix_evpn
.route_type
)
1052 return RMAP_NOMATCH
;
1055 /* Route map `route-type' match statement. */
1056 static void *route_match_evpn_route_type_compile(const char *arg
)
1058 uint8_t *route_type
= NULL
;
1060 route_type
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
1062 if (strncmp(arg
, "ea", 2) == 0)
1063 *route_type
= BGP_EVPN_AD_ROUTE
;
1064 else if (strncmp(arg
, "ma", 2) == 0)
1065 *route_type
= BGP_EVPN_MAC_IP_ROUTE
;
1066 else if (strncmp(arg
, "mu", 2) == 0)
1067 *route_type
= BGP_EVPN_IMET_ROUTE
;
1068 else if (strncmp(arg
, "es", 2) == 0)
1069 *route_type
= BGP_EVPN_ES_ROUTE
;
1071 *route_type
= BGP_EVPN_IP_PREFIX_ROUTE
;
1076 /* Free route map's compiled `route-type' value. */
1077 static void route_match_evpn_route_type_free(void *rule
)
1079 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1082 /* Route map commands for evpn route-type matching. */
1083 static const struct route_map_rule_cmd route_match_evpn_route_type_cmd
= {
1085 route_match_evpn_route_type
,
1086 route_match_evpn_route_type_compile
,
1087 route_match_evpn_route_type_free
1092 /* Match function should return 1 if match is success else return zero. */
1093 static enum route_map_cmd_result_t
1094 route_match_rd(void *rule
, const struct prefix
*prefix
, void *object
)
1096 struct prefix_rd
*prd_rule
= NULL
;
1097 const struct prefix_rd
*prd_route
= NULL
;
1098 struct bgp_path_info
*path
= NULL
;
1100 if (prefix
->family
!= AF_EVPN
)
1101 return RMAP_NOMATCH
;
1103 prd_rule
= (struct prefix_rd
*)rule
;
1104 path
= (struct bgp_path_info
*)object
;
1106 if (path
->net
== NULL
|| path
->net
->pdest
== NULL
)
1107 return RMAP_NOMATCH
;
1109 prd_route
= (struct prefix_rd
*)bgp_dest_get_prefix(path
->net
->pdest
);
1110 if (memcmp(prd_route
->val
, prd_rule
->val
, ECOMMUNITY_SIZE
) == 0)
1113 return RMAP_NOMATCH
;
1116 /* Route map `rd' match statement. */
1117 static void *route_match_rd_compile(const char *arg
)
1119 struct prefix_rd
*prd
;
1122 prd
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct prefix_rd
));
1124 ret
= str2prefix_rd(arg
, prd
);
1126 XFREE(MTYPE_ROUTE_MAP_COMPILED
, prd
);
1133 /* Free route map's compiled `rd' value. */
1134 static void route_match_rd_free(void *rule
)
1136 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1139 /* Route map commands for rd matching. */
1140 static const struct route_map_rule_cmd route_match_evpn_rd_cmd
= {
1143 route_match_rd_compile
,
1147 static enum route_map_cmd_result_t
1148 route_set_evpn_gateway_ip(void *rule
, const struct prefix
*prefix
, void *object
)
1150 struct ipaddr
*gw_ip
= rule
;
1151 struct bgp_path_info
*path
;
1152 struct prefix_evpn
*evp
;
1154 if (prefix
->family
!= AF_EVPN
)
1157 evp
= (struct prefix_evpn
*)prefix
;
1158 if (evp
->prefix
.route_type
!= BGP_EVPN_IP_PREFIX_ROUTE
)
1161 if ((is_evpn_prefix_ipaddr_v4(evp
) && IPADDRSZ(gw_ip
) != 4)
1162 || (is_evpn_prefix_ipaddr_v6(evp
) && IPADDRSZ(gw_ip
) != 16))
1167 /* Set gateway-ip value. */
1168 path
->attr
->evpn_overlay
.type
= OVERLAY_INDEX_GATEWAY_IP
;
1169 memcpy(&path
->attr
->evpn_overlay
.gw_ip
, &gw_ip
->ip
.addr
,
1176 * Route map `evpn gateway-ip' compile function.
1177 * Given string is converted to struct ipaddr structure
1179 static void *route_set_evpn_gateway_ip_compile(const char *arg
)
1181 struct ipaddr
*gw_ip
= NULL
;
1184 gw_ip
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct ipaddr
));
1186 ret
= str2ipaddr(arg
, gw_ip
);
1188 XFREE(MTYPE_ROUTE_MAP_COMPILED
, gw_ip
);
1194 /* Free route map's compiled `evpn gateway_ip' value. */
1195 static void route_set_evpn_gateway_ip_free(void *rule
)
1197 struct ipaddr
*gw_ip
= rule
;
1199 XFREE(MTYPE_ROUTE_MAP_COMPILED
, gw_ip
);
1202 /* Route map commands for set evpn gateway-ip ipv4. */
1203 struct route_map_rule_cmd route_set_evpn_gateway_ip_ipv4_cmd
= {
1204 "evpn gateway-ip ipv4", route_set_evpn_gateway_ip
,
1205 route_set_evpn_gateway_ip_compile
, route_set_evpn_gateway_ip_free
};
1207 /* Route map commands for set evpn gateway-ip ipv6. */
1208 struct route_map_rule_cmd route_set_evpn_gateway_ip_ipv6_cmd
= {
1209 "evpn gateway-ip ipv6", route_set_evpn_gateway_ip
,
1210 route_set_evpn_gateway_ip_compile
, route_set_evpn_gateway_ip_free
};
1212 /* Route map commands for VRF route leak with source vrf matching */
1213 static enum route_map_cmd_result_t
1214 route_match_vrl_source_vrf(void *rule
, const struct prefix
*prefix
,
1217 struct bgp_path_info
*path
;
1221 path
= (struct bgp_path_info
*)object
;
1223 if (strncmp(vrf_name
, "n/a", VRF_NAMSIZ
) == 0)
1224 return RMAP_NOMATCH
;
1226 if (path
->extra
== NULL
|| path
->extra
->bgp_orig
== NULL
)
1227 return RMAP_NOMATCH
;
1229 if (strncmp(vrf_name
, vrf_id_to_name(path
->extra
->bgp_orig
->vrf_id
),
1234 return RMAP_NOMATCH
;
1237 static void *route_match_vrl_source_vrf_compile(const char *arg
)
1239 uint8_t *vrf_name
= NULL
;
1241 vrf_name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1246 /* Free route map's compiled `route-type' value. */
1247 static void route_match_vrl_source_vrf_free(void *rule
)
1249 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1252 static const struct route_map_rule_cmd route_match_vrl_source_vrf_cmd
= {
1254 route_match_vrl_source_vrf
,
1255 route_match_vrl_source_vrf_compile
,
1256 route_match_vrl_source_vrf_free
1260 static enum route_map_cmd_result_t
1261 route_match_alias(void *rule
, const struct prefix
*prefix
, void *object
)
1264 struct bgp_path_info
*path
= object
;
1269 if (bgp_attr_get_community(path
->attr
)) {
1271 frrstr_split(bgp_attr_get_community(path
->attr
)->str
, " ",
1272 &communities
, &num
);
1273 for (int i
= 0; i
< num
; i
++) {
1274 const char *com2alias
=
1275 bgp_community2alias(communities
[i
]);
1276 if (!found
&& strcmp(alias
, com2alias
) == 0)
1278 XFREE(MTYPE_TMP
, communities
[i
]);
1280 XFREE(MTYPE_TMP
, communities
);
1285 if (bgp_attr_get_lcommunity(path
->attr
)) {
1287 frrstr_split(bgp_attr_get_lcommunity(path
->attr
)->str
, " ",
1288 &communities
, &num
);
1289 for (int i
= 0; i
< num
; i
++) {
1290 const char *com2alias
=
1291 bgp_community2alias(communities
[i
]);
1292 if (!found
&& strcmp(alias
, com2alias
) == 0)
1294 XFREE(MTYPE_TMP
, communities
[i
]);
1296 XFREE(MTYPE_TMP
, communities
);
1301 return RMAP_NOMATCH
;
1304 static void *route_match_alias_compile(const char *arg
)
1307 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1310 static void route_match_alias_free(void *rule
)
1312 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1315 static const struct route_map_rule_cmd route_match_alias_cmd
= {
1316 "alias", route_match_alias
, route_match_alias_compile
,
1317 route_match_alias_free
};
1319 /* `match local-preference LOCAL-PREF' */
1321 /* Match function return 1 if match is success else return zero. */
1322 static enum route_map_cmd_result_t
1323 route_match_local_pref(void *rule
, const struct prefix
*prefix
, void *object
)
1325 uint32_t *local_pref
;
1326 struct bgp_path_info
*path
;
1331 if (path
->attr
->local_pref
== *local_pref
)
1334 return RMAP_NOMATCH
;
1338 * Route map `match local-preference' match statement.
1339 * `arg' is local-pref value
1341 static void *route_match_local_pref_compile(const char *arg
)
1343 uint32_t *local_pref
;
1344 char *endptr
= NULL
;
1345 unsigned long tmpval
;
1347 /* Locpref value shoud be integer. */
1348 if (!all_digit(arg
))
1352 tmpval
= strtoul(arg
, &endptr
, 10);
1353 if (*endptr
!= '\0' || errno
|| tmpval
> UINT32_MAX
)
1356 local_pref
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint32_t));
1358 *local_pref
= tmpval
;
1362 /* Free route map's compiled `match local-preference' value. */
1363 static void route_match_local_pref_free(void *rule
)
1365 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1368 /* Route map commands for metric matching. */
1369 static const struct route_map_rule_cmd route_match_local_pref_cmd
= {
1371 route_match_local_pref
,
1372 route_match_local_pref_compile
,
1373 route_match_local_pref_free
1376 /* `match metric METRIC' */
1378 /* Match function return 1 if match is success else return zero. */
1379 static enum route_map_cmd_result_t
1380 route_match_metric(void *rule
, const struct prefix
*prefix
, void *object
)
1382 struct rmap_value
*rv
;
1383 struct bgp_path_info
*path
;
1387 return route_value_match(rv
, path
->attr
->med
);
1390 /* Route map commands for metric matching. */
1391 static const struct route_map_rule_cmd route_match_metric_cmd
= {
1394 route_value_compile
,
1398 /* `match as-path ASPATH' */
1400 /* Match function for as-path match. I assume given object is */
1401 static enum route_map_cmd_result_t
1402 route_match_aspath(void *rule
, const struct prefix
*prefix
, void *object
)
1405 struct as_list
*as_list
;
1406 struct bgp_path_info
*path
;
1408 as_list
= as_list_lookup((char *)rule
);
1409 if (as_list
== NULL
)
1410 return RMAP_NOMATCH
;
1414 /* Perform match. */
1415 return ((as_list_apply(as_list
, path
->attr
->aspath
) == AS_FILTER_DENY
)
1420 /* Compile function for as-path match. */
1421 static void *route_match_aspath_compile(const char *arg
)
1423 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1426 /* Compile function for as-path match. */
1427 static void route_match_aspath_free(void *rule
)
1429 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1432 /* Route map commands for aspath matching. */
1433 static const struct route_map_rule_cmd route_match_aspath_cmd
= {
1436 route_match_aspath_compile
,
1437 route_match_aspath_free
1440 /* `match community COMMUNIY' */
1441 struct rmap_community
{
1447 /* Match function for community match. */
1448 static enum route_map_cmd_result_t
1449 route_match_community(void *rule
, const struct prefix
*prefix
, void *object
)
1451 struct community_list
*list
;
1452 struct bgp_path_info
*path
;
1453 struct rmap_community
*rcom
= rule
;
1458 list
= community_list_lookup(bgp_clist
, rcom
->name
, rcom
->name_hash
,
1459 COMMUNITY_LIST_MASTER
);
1461 return RMAP_NOMATCH
;
1464 if (community_list_exact_match(
1465 bgp_attr_get_community(path
->attr
), list
))
1468 if (community_list_match(bgp_attr_get_community(path
->attr
),
1473 return RMAP_NOMATCH
;
1476 /* Compile function for community match. */
1477 static void *route_match_community_compile(const char *arg
)
1479 struct rmap_community
*rcom
;
1483 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1485 p
= strchr(arg
, ' ');
1488 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1489 memcpy(rcom
->name
, arg
, len
);
1492 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1496 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1500 /* Compile function for community match. */
1501 static void route_match_community_free(void *rule
)
1503 struct rmap_community
*rcom
= rule
;
1505 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1506 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1510 * In routemap processing there is a need to add the
1511 * name as a rule_key in the dependency table. Routemap
1512 * lib is unaware of rule_key when exact-match clause
1513 * is in use. routemap lib uses the compiled output to
1514 * get the rule_key value.
1516 static void *route_match_get_community_key(void *rule
)
1518 struct rmap_community
*rcom
;
1525 /* Route map commands for community matching. */
1526 static const struct route_map_rule_cmd route_match_community_cmd
= {
1528 route_match_community
,
1529 route_match_community_compile
,
1530 route_match_community_free
,
1531 route_match_get_community_key
1534 /* Match function for lcommunity match. */
1535 static enum route_map_cmd_result_t
1536 route_match_lcommunity(void *rule
, const struct prefix
*prefix
, void *object
)
1538 struct community_list
*list
;
1539 struct bgp_path_info
*path
;
1540 struct rmap_community
*rcom
= rule
;
1544 list
= community_list_lookup(bgp_clist
, rcom
->name
, rcom
->name_hash
,
1545 LARGE_COMMUNITY_LIST_MASTER
);
1547 return RMAP_NOMATCH
;
1550 if (lcommunity_list_exact_match(
1551 bgp_attr_get_lcommunity(path
->attr
), list
))
1554 if (lcommunity_list_match(bgp_attr_get_lcommunity(path
->attr
),
1559 return RMAP_NOMATCH
;
1562 /* Compile function for community match. */
1563 static void *route_match_lcommunity_compile(const char *arg
)
1565 struct rmap_community
*rcom
;
1569 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1571 p
= strchr(arg
, ' ');
1574 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1575 memcpy(rcom
->name
, arg
, len
);
1578 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1582 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1586 /* Compile function for community match. */
1587 static void route_match_lcommunity_free(void *rule
)
1589 struct rmap_community
*rcom
= rule
;
1591 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1592 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1595 /* Route map commands for community matching. */
1596 static const struct route_map_rule_cmd route_match_lcommunity_cmd
= {
1598 route_match_lcommunity
,
1599 route_match_lcommunity_compile
,
1600 route_match_lcommunity_free
,
1601 route_match_get_community_key
1605 /* Match function for extcommunity match. */
1606 static enum route_map_cmd_result_t
1607 route_match_ecommunity(void *rule
, const struct prefix
*prefix
, void *object
)
1609 struct community_list
*list
;
1610 struct bgp_path_info
*path
;
1611 struct rmap_community
*rcom
= rule
;
1615 list
= community_list_lookup(bgp_clist
, rcom
->name
, rcom
->name_hash
,
1616 EXTCOMMUNITY_LIST_MASTER
);
1618 return RMAP_NOMATCH
;
1620 if (ecommunity_list_match(bgp_attr_get_ecommunity(path
->attr
), list
))
1623 return RMAP_NOMATCH
;
1626 /* Compile function for extcommunity match. */
1627 static void *route_match_ecommunity_compile(const char *arg
)
1629 struct rmap_community
*rcom
;
1631 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1632 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1633 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1638 /* Compile function for extcommunity match. */
1639 static void route_match_ecommunity_free(void *rule
)
1641 struct rmap_community
*rcom
= rule
;
1643 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1644 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1647 /* Route map commands for community matching. */
1648 static const struct route_map_rule_cmd route_match_ecommunity_cmd
= {
1650 route_match_ecommunity
,
1651 route_match_ecommunity_compile
,
1652 route_match_ecommunity_free
1655 /* `match nlri` and `set nlri` are replaced by `address-family ipv4`
1656 and `address-family vpnv4'. */
1658 /* `match origin' */
1659 static enum route_map_cmd_result_t
1660 route_match_origin(void *rule
, const struct prefix
*prefix
, void *object
)
1663 struct bgp_path_info
*path
;
1668 if (path
->attr
->origin
== *origin
)
1671 return RMAP_NOMATCH
;
1674 static void *route_match_origin_compile(const char *arg
)
1678 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
1680 if (strcmp(arg
, "igp") == 0)
1682 else if (strcmp(arg
, "egp") == 0)
1690 /* Free route map's compiled `ip address' value. */
1691 static void route_match_origin_free(void *rule
)
1693 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1696 /* Route map commands for origin matching. */
1697 static const struct route_map_rule_cmd route_match_origin_cmd
= {
1700 route_match_origin_compile
,
1701 route_match_origin_free
1704 /* match probability { */
1706 static enum route_map_cmd_result_t
1707 route_match_probability(void *rule
, const struct prefix
*prefix
, void *object
)
1709 long r
= frr_weak_random();
1711 switch (*(long *)rule
) {
1717 if (r
< *(long *)rule
) {
1722 return RMAP_NOMATCH
;
1725 static void *route_match_probability_compile(const char *arg
)
1731 lobule
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(long));
1741 *lobule
= RAND_MAX
/ 100 * perc
;
1747 static void route_match_probability_free(void *rule
)
1749 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1752 static const struct route_map_rule_cmd route_match_probability_cmd
= {
1754 route_match_probability
,
1755 route_match_probability_compile
,
1756 route_match_probability_free
1759 /* `match interface IFNAME' */
1760 /* Match function should return 1 if match is success else return
1762 static enum route_map_cmd_result_t
1763 route_match_interface(void *rule
, const struct prefix
*prefix
, void *object
)
1765 struct interface
*ifp
;
1766 struct bgp_path_info
*path
;
1770 if (!path
|| !path
->peer
|| !path
->peer
->bgp
)
1771 return RMAP_NOMATCH
;
1773 ifp
= if_lookup_by_name((char *)rule
, path
->peer
->bgp
->vrf_id
);
1775 if (ifp
== NULL
|| ifp
->ifindex
!= path
->attr
->nh_ifindex
)
1776 return RMAP_NOMATCH
;
1781 /* Route map `interface' match statement. `arg' should be
1783 static void *route_match_interface_compile(const char *arg
)
1785 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1788 /* Free route map's compiled `interface' value. */
1789 static void route_match_interface_free(void *rule
)
1791 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1794 /* Route map commands for ip address matching. */
1795 static const struct route_map_rule_cmd route_match_interface_cmd
= {
1797 route_match_interface
,
1798 route_match_interface_compile
,
1799 route_match_interface_free
1804 /* `set ip next-hop IP_ADDRESS' */
1806 /* Match function return 1 if match is success else return zero. */
1807 static enum route_map_cmd_result_t
1808 route_match_tag(void *rule
, const struct prefix
*prefix
, void *object
)
1811 struct bgp_path_info
*path
;
1816 return ((path
->attr
->tag
== *tag
) ? RMAP_MATCH
: RMAP_NOMATCH
);
1820 /* Route map commands for tag matching. */
1821 static const struct route_map_rule_cmd route_match_tag_cmd
= {
1824 route_map_rule_tag_compile
,
1825 route_map_rule_tag_free
,
1828 static enum route_map_cmd_result_t
1829 route_set_srte_color(void *rule
, const struct prefix
*prefix
, void *object
)
1831 uint32_t *srte_color
= rule
;
1832 struct bgp_path_info
*path
;
1836 path
->attr
->srte_color
= *srte_color
;
1837 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_SRTE_COLOR
);
1842 /* Route map `sr-te color' compile function */
1843 static void *route_set_srte_color_compile(const char *arg
)
1847 color
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint32_t));
1853 /* Free route map's compiled `sr-te color' value. */
1854 static void route_set_srte_color_free(void *rule
)
1856 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1859 /* Route map commands for sr-te color set. */
1860 struct route_map_rule_cmd route_set_srte_color_cmd
= {
1861 "sr-te color", route_set_srte_color
, route_set_srte_color_compile
,
1862 route_set_srte_color_free
};
1864 /* Set nexthop to object. object must be pointer to struct attr. */
1865 struct rmap_ip_nexthop_set
{
1866 struct in_addr
*address
;
1871 static enum route_map_cmd_result_t
1872 route_set_ip_nexthop(void *rule
, const struct prefix
*prefix
, void *object
)
1874 struct rmap_ip_nexthop_set
*rins
= rule
;
1875 struct bgp_path_info
*path
;
1878 if (prefix
->family
== AF_INET6
)
1884 if (rins
->unchanged
) {
1885 SET_FLAG(path
->attr
->rmap_change_flags
,
1886 BATTR_RMAP_NEXTHOP_UNCHANGED
);
1887 } else if (rins
->peer_address
) {
1888 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
1889 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
1891 && sockunion_family(peer
->su_remote
) == AF_INET
) {
1892 path
->attr
->nexthop
.s_addr
=
1893 sockunion2ip(peer
->su_remote
);
1894 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1895 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
1896 /* The next hop value will be set as part of
1897 * packet rewrite. Set the flags here to indicate
1898 * that rewrite needs to be done.
1899 * Also, clear the value.
1901 SET_FLAG(path
->attr
->rmap_change_flags
,
1902 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
1903 path
->attr
->nexthop
.s_addr
= INADDR_ANY
;
1906 /* Set next hop value. */
1907 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1908 path
->attr
->nexthop
= *rins
->address
;
1909 SET_FLAG(path
->attr
->rmap_change_flags
,
1910 BATTR_RMAP_IPV4_NHOP_CHANGED
);
1911 /* case for MP-BGP : MPLS VPN */
1912 path
->attr
->mp_nexthop_global_in
= *rins
->address
;
1913 path
->attr
->mp_nexthop_len
= sizeof(*rins
->address
);
1919 /* Route map `ip nexthop' compile function. Given string is converted
1920 to struct in_addr structure. */
1921 static void *route_set_ip_nexthop_compile(const char *arg
)
1923 struct rmap_ip_nexthop_set
*rins
;
1924 struct in_addr
*address
= NULL
;
1925 int peer_address
= 0;
1929 if (strcmp(arg
, "peer-address") == 0)
1931 else if (strcmp(arg
, "unchanged") == 0)
1934 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1935 sizeof(struct in_addr
));
1936 ret
= inet_aton(arg
, address
);
1939 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
1944 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1945 sizeof(struct rmap_ip_nexthop_set
));
1947 rins
->address
= address
;
1948 rins
->peer_address
= peer_address
;
1949 rins
->unchanged
= unchanged
;
1954 /* Free route map's compiled `ip nexthop' value. */
1955 static void route_set_ip_nexthop_free(void *rule
)
1957 struct rmap_ip_nexthop_set
*rins
= rule
;
1959 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
->address
);
1961 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
);
1964 /* Route map commands for ip nexthop set. */
1965 static const struct route_map_rule_cmd route_set_ip_nexthop_cmd
= {
1967 route_set_ip_nexthop
,
1968 route_set_ip_nexthop_compile
,
1969 route_set_ip_nexthop_free
1972 /* `set l3vpn next-hop encapsulation l3vpn gre' */
1974 /* Set nexthop to object */
1975 struct rmap_l3vpn_nexthop_encapsulation_set
{
1979 static enum route_map_cmd_result_t
1980 route_set_l3vpn_nexthop_encapsulation(void *rule
, const struct prefix
*prefix
,
1983 struct rmap_l3vpn_nexthop_encapsulation_set
*rins
= rule
;
1984 struct bgp_path_info
*path
;
1988 if (rins
->protocol
!= IPPROTO_GRE
)
1991 SET_FLAG(path
->attr
->rmap_change_flags
, BATTR_RMAP_L3VPN_ACCEPT_GRE
);
1995 /* Route map `l3vpn nexthop encapsulation' compile function. */
1996 static void *route_set_l3vpn_nexthop_encapsulation_compile(const char *arg
)
1998 struct rmap_l3vpn_nexthop_encapsulation_set
*rins
;
2000 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
2001 sizeof(struct rmap_l3vpn_nexthop_encapsulation_set
));
2003 /* XXX ALL GRE modes are accepted for now: gre or ip6gre */
2004 rins
->protocol
= IPPROTO_GRE
;
2009 /* Free route map's compiled `ip nexthop' value. */
2010 static void route_set_l3vpn_nexthop_encapsulation_free(void *rule
)
2012 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2015 /* Route map commands for l3vpn next-hop encapsulation set. */
2016 static const struct route_map_rule_cmd
2017 route_set_l3vpn_nexthop_encapsulation_cmd
= {
2018 "l3vpn next-hop encapsulation",
2019 route_set_l3vpn_nexthop_encapsulation
,
2020 route_set_l3vpn_nexthop_encapsulation_compile
,
2021 route_set_l3vpn_nexthop_encapsulation_free
};
2023 /* `set local-preference LOCAL_PREF' */
2025 /* Set local preference. */
2026 static enum route_map_cmd_result_t
2027 route_set_local_pref(void *rule
, const struct prefix
*prefix
, void *object
)
2029 struct rmap_value
*rv
;
2030 struct bgp_path_info
*path
;
2031 uint32_t locpref
= 0;
2033 /* Fetch routemap's rule information. */
2037 /* Set local preference value. */
2038 if (path
->attr
->local_pref
)
2039 locpref
= path
->attr
->local_pref
;
2041 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
);
2042 path
->attr
->local_pref
= route_value_adjust(rv
, locpref
, path
->peer
);
2047 /* Set local preference rule structure. */
2048 static const struct route_map_rule_cmd route_set_local_pref_cmd
= {
2050 route_set_local_pref
,
2051 route_value_compile
,
2055 /* `set weight WEIGHT' */
2058 static enum route_map_cmd_result_t
2059 route_set_weight(void *rule
, const struct prefix
*prefix
, void *object
)
2061 struct rmap_value
*rv
;
2062 struct bgp_path_info
*path
;
2064 /* Fetch routemap's rule information. */
2068 /* Set weight value. */
2069 path
->attr
->weight
= route_value_adjust(rv
, 0, path
->peer
);
2074 /* Set local preference rule structure. */
2075 static const struct route_map_rule_cmd route_set_weight_cmd
= {
2078 route_value_compile
,
2082 /* `set distance DISTANCE */
2083 static enum route_map_cmd_result_t
2084 route_set_distance(void *rule
, const struct prefix
*prefix
, void *object
)
2086 struct bgp_path_info
*path
= object
;
2087 struct rmap_value
*rv
= rule
;
2089 path
->attr
->distance
= rv
->value
;
2094 /* set distance rule structure */
2095 static const struct route_map_rule_cmd route_set_distance_cmd
= {
2098 route_value_compile
,
2102 /* `set metric METRIC' */
2104 /* Set metric to attribute. */
2105 static enum route_map_cmd_result_t
2106 route_set_metric(void *rule
, const struct prefix
*prefix
, void *object
)
2108 struct rmap_value
*rv
;
2109 struct bgp_path_info
*path
;
2112 /* Fetch routemap's rule information. */
2116 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
))
2117 med
= path
->attr
->med
;
2119 path
->attr
->med
= route_value_adjust(rv
, med
, path
->peer
);
2120 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
);
2125 /* Set metric rule structure. */
2126 static const struct route_map_rule_cmd route_set_metric_cmd
= {
2129 route_value_compile
,
2133 /* `set table (1-4294967295)' */
2135 static enum route_map_cmd_result_t
2136 route_set_table_id(void *rule
, const struct prefix
*prefix
,
2140 struct rmap_value
*rv
;
2141 struct bgp_path_info
*path
;
2143 /* Fetch routemap's rule information. */
2147 path
->attr
->rmap_table_id
= rv
->value
;
2152 /* Set table_id rule structure. */
2153 static const struct route_map_rule_cmd route_set_table_id_cmd
= {
2156 route_value_compile
,
2160 /* `set as-path prepend ASPATH' */
2162 /* For AS path prepend mechanism. */
2163 static enum route_map_cmd_result_t
2164 route_set_aspath_prepend(void *rule
, const struct prefix
*prefix
, void *object
)
2166 struct aspath
*aspath
;
2168 struct bgp_path_info
*path
;
2172 if (path
->attr
->aspath
->refcnt
)
2173 new = aspath_dup(path
->attr
->aspath
);
2175 new = path
->attr
->aspath
;
2177 if ((uintptr_t)rule
> 10) {
2179 aspath_prepend(aspath
, new);
2181 as_t as
= aspath_leftmost(new);
2183 new = aspath_add_seq_n(new, as
, (uintptr_t)rule
);
2186 path
->attr
->aspath
= new;
2191 static void *route_set_aspath_prepend_compile(const char *arg
)
2195 if (sscanf(arg
, "last-as %u", &num
) == 1 && num
> 0 && num
<= 10)
2196 return (void *)(uintptr_t)num
;
2198 return route_aspath_compile(arg
);
2201 static void route_set_aspath_prepend_free(void *rule
)
2203 if ((uintptr_t)rule
> 10)
2204 route_aspath_free(rule
);
2208 /* Set as-path prepend rule structure. */
2209 static const struct route_map_rule_cmd route_set_aspath_prepend_cmd
= {
2211 route_set_aspath_prepend
,
2212 route_set_aspath_prepend_compile
,
2213 route_set_aspath_prepend_free
,
2216 /* `set as-path exclude ASn' */
2218 /* For ASN exclude mechanism.
2219 * Iterate over ASns requested and filter them from the given AS_PATH one by
2221 * Make a deep copy of existing AS_PATH, but for the first ASn only.
2223 static enum route_map_cmd_result_t
2224 route_set_aspath_exclude(void *rule
, const struct prefix
*dummy
, void *object
)
2226 struct aspath
*new_path
, *exclude_path
;
2227 struct bgp_path_info
*path
;
2229 exclude_path
= rule
;
2231 if (path
->attr
->aspath
->refcnt
)
2232 new_path
= aspath_dup(path
->attr
->aspath
);
2234 new_path
= path
->attr
->aspath
;
2235 path
->attr
->aspath
= aspath_filter_exclude(new_path
, exclude_path
);
2240 /* Set ASn exlude rule structure. */
2241 static const struct route_map_rule_cmd route_set_aspath_exclude_cmd
= {
2243 route_set_aspath_exclude
,
2244 route_aspath_compile
,
2248 /* `set as-path replace AS-PATH` */
2249 static void *route_aspath_replace_compile(const char *arg
)
2251 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2254 static void route_aspath_replace_free(void *rule
)
2256 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2259 static enum route_map_cmd_result_t
2260 route_set_aspath_replace(void *rule
, const struct prefix
*dummy
, void *object
)
2262 struct aspath
*aspath_new
;
2263 const char *replace
= rule
;
2264 struct bgp_path_info
*path
= object
;
2265 as_t own_asn
= path
->peer
->change_local_as
? path
->peer
->change_local_as
2266 : path
->peer
->local_as
;
2268 if (path
->peer
->sort
!= BGP_PEER_EBGP
) {
2270 "`set as-path replace` is supported only for EBGP peers");
2274 if (path
->attr
->aspath
->refcnt
)
2275 aspath_new
= aspath_dup(path
->attr
->aspath
);
2277 aspath_new
= path
->attr
->aspath
;
2279 if (strmatch(replace
, "any")) {
2280 path
->attr
->aspath
=
2281 aspath_replace_all_asn(aspath_new
, own_asn
);
2283 as_t replace_asn
= strtoul(replace
, NULL
, 10);
2285 path
->attr
->aspath
= aspath_replace_specific_asn(
2286 aspath_new
, replace_asn
, own_asn
);
2289 aspath_free(aspath_new
);
2294 static const struct route_map_rule_cmd route_set_aspath_replace_cmd
= {
2296 route_set_aspath_replace
,
2297 route_aspath_replace_compile
,
2298 route_aspath_replace_free
,
2301 /* `set community COMMUNITY' */
2302 struct rmap_com_set
{
2303 struct community
*com
;
2308 /* For community set mechanism. */
2309 static enum route_map_cmd_result_t
2310 route_set_community(void *rule
, const struct prefix
*prefix
, void *object
)
2312 struct rmap_com_set
*rcs
;
2313 struct bgp_path_info
*path
;
2315 struct community
*new = NULL
;
2316 struct community
*old
;
2317 struct community
*merge
;
2322 old
= bgp_attr_get_community(attr
);
2326 bgp_attr_set_community(attr
, NULL
);
2327 /* See the longer comment down below. */
2328 if (old
&& old
->refcnt
== 0)
2329 community_free(&old
);
2333 /* "additive" case. */
2334 if (rcs
->additive
&& old
) {
2335 merge
= community_merge(community_dup(old
), rcs
->com
);
2337 new = community_uniq_sort(merge
);
2338 community_free(&merge
);
2340 new = community_dup(rcs
->com
);
2342 /* HACK: if the old community is not intern'd,
2343 * we should free it here, or all reference to it may be
2345 * Really need to cleanup attribute caching sometime.
2347 if (old
&& old
->refcnt
== 0)
2348 community_free(&old
);
2350 /* will be interned by caller if required */
2351 bgp_attr_set_community(attr
, new);
2356 /* Compile function for set community. */
2357 static void *route_set_community_compile(const char *arg
)
2359 struct rmap_com_set
*rcs
;
2360 struct community
*com
= NULL
;
2365 if (strcmp(arg
, "none") == 0)
2368 sp
= strstr(arg
, "additive");
2370 if (sp
&& sp
> arg
) {
2371 /* "additive" keyword is included. */
2376 com
= community_str2com(arg
);
2385 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
2387 rcs
->additive
= additive
;
2393 /* Free function for set community. */
2394 static void route_set_community_free(void *rule
)
2396 struct rmap_com_set
*rcs
= rule
;
2399 community_free(&rcs
->com
);
2400 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
2403 /* Set community rule structure. */
2404 static const struct route_map_rule_cmd route_set_community_cmd
= {
2406 route_set_community
,
2407 route_set_community_compile
,
2408 route_set_community_free
,
2411 /* `set community COMMUNITY' */
2412 struct rmap_lcom_set
{
2413 struct lcommunity
*lcom
;
2419 /* For lcommunity set mechanism. */
2420 static enum route_map_cmd_result_t
2421 route_set_lcommunity(void *rule
, const struct prefix
*prefix
, void *object
)
2423 struct rmap_lcom_set
*rcs
;
2424 struct bgp_path_info
*path
;
2426 struct lcommunity
*new = NULL
;
2427 struct lcommunity
*old
;
2428 struct lcommunity
*merge
;
2433 old
= bgp_attr_get_lcommunity(attr
);
2437 bgp_attr_set_lcommunity(attr
, NULL
);
2439 /* See the longer comment down below. */
2440 if (old
&& old
->refcnt
== 0)
2441 lcommunity_free(&old
);
2445 if (rcs
->additive
&& old
) {
2446 merge
= lcommunity_merge(lcommunity_dup(old
), rcs
->lcom
);
2448 new = lcommunity_uniq_sort(merge
);
2449 lcommunity_free(&merge
);
2451 new = lcommunity_dup(rcs
->lcom
);
2453 /* HACK: if the old large-community is not intern'd,
2454 * we should free it here, or all reference to it may be
2456 * Really need to cleanup attribute caching sometime.
2458 if (old
&& old
->refcnt
== 0)
2459 lcommunity_free(&old
);
2461 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
2462 bgp_attr_set_lcommunity(attr
, new);
2467 /* Compile function for set community. */
2468 static void *route_set_lcommunity_compile(const char *arg
)
2470 struct rmap_lcom_set
*rcs
;
2471 struct lcommunity
*lcom
= NULL
;
2476 if (strcmp(arg
, "none") == 0)
2479 sp
= strstr(arg
, "additive");
2481 if (sp
&& sp
> arg
) {
2482 /* "additive" keyworkd is included. */
2487 lcom
= lcommunity_str2com(arg
);
2496 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
2498 rcs
->additive
= additive
;
2504 /* Free function for set lcommunity. */
2505 static void route_set_lcommunity_free(void *rule
)
2507 struct rmap_lcom_set
*rcs
= rule
;
2510 lcommunity_free(&rcs
->lcom
);
2512 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
2515 /* Set community rule structure. */
2516 static const struct route_map_rule_cmd route_set_lcommunity_cmd
= {
2518 route_set_lcommunity
,
2519 route_set_lcommunity_compile
,
2520 route_set_lcommunity_free
,
2523 /* `set large-comm-list (<1-99>|<100-500>|WORD) delete' */
2525 /* For large community set mechanism. */
2526 static enum route_map_cmd_result_t
2527 route_set_lcommunity_delete(void *rule
, const struct prefix
*pfx
, void *object
)
2529 struct community_list
*list
;
2530 struct lcommunity
*merge
;
2531 struct lcommunity
*new;
2532 struct lcommunity
*old
;
2533 struct bgp_path_info
*path
;
2534 struct rmap_community
*rcom
= rule
;
2540 list
= community_list_lookup(bgp_clist
, rcom
->name
, rcom
->name_hash
,
2541 LARGE_COMMUNITY_LIST_MASTER
);
2542 old
= bgp_attr_get_lcommunity(path
->attr
);
2545 merge
= lcommunity_list_match_delete(lcommunity_dup(old
), list
);
2546 new = lcommunity_uniq_sort(merge
);
2547 lcommunity_free(&merge
);
2549 /* HACK: if the old community is not intern'd,
2550 * we should free it here, or all reference to it may be
2552 * Really need to cleanup attribute caching sometime.
2554 if (old
->refcnt
== 0)
2555 lcommunity_free(&old
);
2557 if (new->size
== 0) {
2558 bgp_attr_set_lcommunity(path
->attr
, NULL
);
2559 lcommunity_free(&new);
2561 bgp_attr_set_lcommunity(path
->attr
, new);
2568 /* Compile function for set lcommunity. */
2569 static void *route_set_lcommunity_delete_compile(const char *arg
)
2571 struct rmap_community
*rcom
;
2575 frrstr_split(arg
, " ", &splits
, &num
);
2577 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2578 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, splits
[0]);
2579 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2581 for (int i
= 0; i
< num
; i
++)
2582 XFREE(MTYPE_TMP
, splits
[i
]);
2583 XFREE(MTYPE_TMP
, splits
);
2588 /* Free function for set lcommunity. */
2589 static void route_set_lcommunity_delete_free(void *rule
)
2591 struct rmap_community
*rcom
= rule
;
2593 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2594 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2597 /* Set lcommunity rule structure. */
2598 static const struct route_map_rule_cmd route_set_lcommunity_delete_cmd
= {
2600 route_set_lcommunity_delete
,
2601 route_set_lcommunity_delete_compile
,
2602 route_set_lcommunity_delete_free
,
2606 /* `set comm-list (<1-99>|<100-500>|WORD) delete' */
2608 /* For community set mechanism. */
2609 static enum route_map_cmd_result_t
2610 route_set_community_delete(void *rule
, const struct prefix
*prefix
,
2613 struct community_list
*list
;
2614 struct community
*merge
;
2615 struct community
*new;
2616 struct community
*old
;
2617 struct bgp_path_info
*path
;
2618 struct rmap_community
*rcom
= rule
;
2624 list
= community_list_lookup(bgp_clist
, rcom
->name
, rcom
->name_hash
,
2625 COMMUNITY_LIST_MASTER
);
2626 old
= bgp_attr_get_community(path
->attr
);
2629 merge
= community_list_match_delete(community_dup(old
), list
);
2630 new = community_uniq_sort(merge
);
2631 community_free(&merge
);
2633 /* HACK: if the old community is not intern'd,
2634 * we should free it here, or all reference to it may be
2636 * Really need to cleanup attribute caching sometime.
2638 if (old
->refcnt
== 0)
2639 community_free(&old
);
2641 if (new->size
== 0) {
2642 bgp_attr_set_community(path
->attr
, NULL
);
2643 community_free(&new);
2645 bgp_attr_set_community(path
->attr
, new);
2652 /* Compile function for set community. */
2653 static void *route_set_community_delete_compile(const char *arg
)
2655 struct rmap_community
*rcom
;
2659 frrstr_split(arg
, " ", &splits
, &num
);
2661 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2662 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, splits
[0]);
2663 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2665 for (int i
= 0; i
< num
; i
++)
2666 XFREE(MTYPE_TMP
, splits
[i
]);
2667 XFREE(MTYPE_TMP
, splits
);
2672 /* Free function for set community. */
2673 static void route_set_community_delete_free(void *rule
)
2675 struct rmap_community
*rcom
= rule
;
2677 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2678 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2681 /* Set community rule structure. */
2682 static const struct route_map_rule_cmd route_set_community_delete_cmd
= {
2684 route_set_community_delete
,
2685 route_set_community_delete_compile
,
2686 route_set_community_delete_free
,
2689 /* `set extcommunity rt COMMUNITY' */
2691 struct rmap_ecom_set
{
2692 struct ecommunity
*ecom
;
2696 /* For community set mechanism. Used by _rt and _soo. */
2697 static enum route_map_cmd_result_t
2698 route_set_ecommunity(void *rule
, const struct prefix
*prefix
, void *object
)
2700 struct rmap_ecom_set
*rcs
;
2701 struct ecommunity
*new_ecom
;
2702 struct ecommunity
*old_ecom
;
2703 struct bgp_path_info
*path
;
2711 bgp_attr_set_ecommunity(attr
, NULL
);
2718 /* We assume additive for Extended Community. */
2719 old_ecom
= bgp_attr_get_ecommunity(path
->attr
);
2723 ecommunity_merge(ecommunity_dup(old_ecom
), rcs
->ecom
);
2725 /* old_ecom->refcnt = 1 => owned elsewhere, e.g.
2726 * bgp_update_receive()
2727 * ->refcnt = 0 => set by a previous route-map
2729 if (!old_ecom
->refcnt
)
2730 ecommunity_free(&old_ecom
);
2732 new_ecom
= ecommunity_dup(rcs
->ecom
);
2734 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
2735 bgp_attr_set_ecommunity(path
->attr
, new_ecom
);
2740 static void *route_set_ecommunity_none_compile(const char *arg
)
2742 struct rmap_ecom_set
*rcs
;
2745 if (strncmp(arg
, "none", 4) == 0)
2748 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_ecom_set
));
2755 static void *route_set_ecommunity_rt_compile(const char *arg
)
2757 struct rmap_ecom_set
*rcs
;
2758 struct ecommunity
*ecom
;
2760 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_ROUTE_TARGET
, 0);
2764 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_ecom_set
));
2765 rcs
->ecom
= ecommunity_intern(ecom
);
2771 /* Free function for set community. Used by _rt and _soo */
2772 static void route_set_ecommunity_free(void *rule
)
2774 struct rmap_ecom_set
*rcs
= rule
;
2777 ecommunity_unintern(&rcs
->ecom
);
2779 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
2782 static const struct route_map_rule_cmd route_set_ecommunity_none_cmd
= {
2784 route_set_ecommunity
,
2785 route_set_ecommunity_none_compile
,
2786 route_set_ecommunity_free
,
2789 /* Set community rule structure. */
2790 static const struct route_map_rule_cmd route_set_ecommunity_rt_cmd
= {
2792 route_set_ecommunity
,
2793 route_set_ecommunity_rt_compile
,
2794 route_set_ecommunity_free
,
2797 /* `set extcommunity soo COMMUNITY' */
2799 /* Compile function for set community. */
2800 static void *route_set_ecommunity_soo_compile(const char *arg
)
2802 struct rmap_ecom_set
*rcs
;
2803 struct ecommunity
*ecom
;
2805 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_SITE_ORIGIN
, 0);
2809 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_ecom_set
));
2810 rcs
->ecom
= ecommunity_intern(ecom
);
2816 /* Set community rule structure. */
2817 static const struct route_map_rule_cmd route_set_ecommunity_soo_cmd
= {
2819 route_set_ecommunity
,
2820 route_set_ecommunity_soo_compile
,
2821 route_set_ecommunity_free
,
2824 /* `set extcommunity bandwidth' */
2826 struct rmap_ecomm_lb_set
{
2828 #define RMAP_ECOMM_LB_SET_VALUE 1
2829 #define RMAP_ECOMM_LB_SET_CUMUL 2
2830 #define RMAP_ECOMM_LB_SET_NUM_MPATH 3
2835 static enum route_map_cmd_result_t
2836 route_set_ecommunity_lb(void *rule
, const struct prefix
*prefix
, void *object
)
2838 struct rmap_ecomm_lb_set
*rels
= rule
;
2839 struct bgp_path_info
*path
;
2841 struct ecommunity ecom_lb
= {0};
2842 struct ecommunity_val lb_eval
;
2843 uint32_t bw_bytes
= 0;
2844 uint16_t mpath_count
= 0;
2845 struct ecommunity
*new_ecom
;
2846 struct ecommunity
*old_ecom
;
2851 if (!peer
|| !peer
->bgp
)
2854 /* Build link bandwidth extended community */
2855 as
= (peer
->bgp
->as
> BGP_AS_MAX
) ? BGP_AS_TRANS
: peer
->bgp
->as
;
2856 if (rels
->lb_type
== RMAP_ECOMM_LB_SET_VALUE
) {
2857 bw_bytes
= ((uint64_t)rels
->bw
* 1000 * 1000) / 8;
2858 } else if (rels
->lb_type
== RMAP_ECOMM_LB_SET_CUMUL
) {
2859 /* process this only for the best path. */
2860 if (!CHECK_FLAG(path
->flags
, BGP_PATH_SELECTED
))
2863 bw_bytes
= (uint32_t)bgp_path_info_mpath_cumbw(path
);
2867 } else if (rels
->lb_type
== RMAP_ECOMM_LB_SET_NUM_MPATH
) {
2869 /* process this only for the best path. */
2870 if (!CHECK_FLAG(path
->flags
, BGP_PATH_SELECTED
))
2873 bw_bytes
= ((uint64_t)peer
->bgp
->lb_ref_bw
* 1000 * 1000) / 8;
2874 mpath_count
= bgp_path_info_mpath_count(path
) + 1;
2875 bw_bytes
*= mpath_count
;
2878 encode_lb_extcomm(as
, bw_bytes
, rels
->non_trans
, &lb_eval
,
2879 CHECK_FLAG(peer
->flags
,
2880 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE
));
2882 /* add to route or merge with existing */
2883 old_ecom
= bgp_attr_get_ecommunity(path
->attr
);
2885 new_ecom
= ecommunity_dup(old_ecom
);
2886 ecommunity_add_val(new_ecom
, &lb_eval
, true, true);
2887 if (!old_ecom
->refcnt
)
2888 ecommunity_free(&old_ecom
);
2891 ecom_lb
.unit_size
= ECOMMUNITY_SIZE
;
2892 ecom_lb
.val
= (uint8_t *)lb_eval
.val
;
2893 new_ecom
= ecommunity_dup(&ecom_lb
);
2896 /* new_ecom will be intern()'d or attr_flush()'d in call stack */
2897 bgp_attr_set_ecommunity(path
->attr
, new_ecom
);
2899 /* Mark that route-map has set link bandwidth; used in attribute
2900 * setting decisions.
2902 SET_FLAG(path
->attr
->rmap_change_flags
, BATTR_RMAP_LINK_BW_SET
);
2907 static void *route_set_ecommunity_lb_compile(const char *arg
)
2909 struct rmap_ecomm_lb_set
*rels
;
2912 char bw_str
[40] = {0};
2914 bool non_trans
= false;
2917 p
= strchr(arg
, ' ');
2922 memcpy(bw_str
, arg
, len
);
2927 if (strcmp(str
, "cumulative") == 0)
2928 lb_type
= RMAP_ECOMM_LB_SET_CUMUL
;
2929 else if (strcmp(str
, "num-multipaths") == 0)
2930 lb_type
= RMAP_ECOMM_LB_SET_NUM_MPATH
;
2934 bw
= strtoul(str
, &end
, 10);
2937 lb_type
= RMAP_ECOMM_LB_SET_VALUE
;
2940 rels
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
2941 sizeof(struct rmap_ecomm_lb_set
));
2942 rels
->lb_type
= lb_type
;
2944 rels
->non_trans
= non_trans
;
2949 static void route_set_ecommunity_lb_free(void *rule
)
2951 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2954 /* Set community rule structure. */
2955 struct route_map_rule_cmd route_set_ecommunity_lb_cmd
= {
2956 "extcommunity bandwidth",
2957 route_set_ecommunity_lb
,
2958 route_set_ecommunity_lb_compile
,
2959 route_set_ecommunity_lb_free
,
2962 /* `set origin ORIGIN' */
2964 /* For origin set. */
2965 static enum route_map_cmd_result_t
2966 route_set_origin(void *rule
, const struct prefix
*prefix
, void *object
)
2969 struct bgp_path_info
*path
;
2974 path
->attr
->origin
= *origin
;
2979 /* Compile function for origin set. */
2980 static void *route_set_origin_compile(const char *arg
)
2984 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
2986 if (strcmp(arg
, "igp") == 0)
2988 else if (strcmp(arg
, "egp") == 0)
2996 /* Compile function for origin set. */
2997 static void route_set_origin_free(void *rule
)
2999 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3002 /* Set origin rule structure. */
3003 static const struct route_map_rule_cmd route_set_origin_cmd
= {
3006 route_set_origin_compile
,
3007 route_set_origin_free
,
3010 /* `set atomic-aggregate' */
3012 /* For atomic aggregate set. */
3013 static enum route_map_cmd_result_t
3014 route_set_atomic_aggregate(void *rule
, const struct prefix
*pfx
, void *object
)
3016 struct bgp_path_info
*path
;
3019 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE
);
3024 /* Compile function for atomic aggregate. */
3025 static void *route_set_atomic_aggregate_compile(const char *arg
)
3030 /* Compile function for atomic aggregate. */
3031 static void route_set_atomic_aggregate_free(void *rule
)
3036 /* Set atomic aggregate rule structure. */
3037 static const struct route_map_rule_cmd route_set_atomic_aggregate_cmd
= {
3039 route_set_atomic_aggregate
,
3040 route_set_atomic_aggregate_compile
,
3041 route_set_atomic_aggregate_free
,
3044 /* AIGP TLV Metric */
3045 static enum route_map_cmd_result_t
3046 route_set_aigp_metric(void *rule
, const struct prefix
*pfx
, void *object
)
3048 const char *aigp_metric
= rule
;
3049 struct bgp_path_info
*path
= object
;
3052 if (strmatch(aigp_metric
, "igp-metric")) {
3054 return RMAP_NOMATCH
;
3056 bgp_attr_set_aigp_metric(path
->attr
, path
->nexthop
->metric
);
3058 aigp
= atoi(aigp_metric
);
3059 bgp_attr_set_aigp_metric(path
->attr
, aigp
);
3062 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_AIGP
);
3067 static void *route_set_aigp_metric_compile(const char *arg
)
3069 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
3072 static void route_set_aigp_metric_free(void *rule
)
3074 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3077 static const struct route_map_rule_cmd route_set_aigp_metric_cmd
= {
3079 route_set_aigp_metric
,
3080 route_set_aigp_metric_compile
,
3081 route_set_aigp_metric_free
,
3084 /* `set aggregator as AS A.B.C.D' */
3087 struct in_addr address
;
3090 static enum route_map_cmd_result_t
3091 route_set_aggregator_as(void *rule
, const struct prefix
*prefix
, void *object
)
3093 struct bgp_path_info
*path
;
3094 struct aggregator
*aggregator
;
3099 path
->attr
->aggregator_as
= aggregator
->as
;
3100 path
->attr
->aggregator_addr
= aggregator
->address
;
3101 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR
);
3106 static void *route_set_aggregator_as_compile(const char *arg
)
3108 struct aggregator
*aggregator
;
3114 XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct aggregator
));
3115 if (sscanf(arg
, "%s %s", as
, address
) != 2) {
3116 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
3120 aggregator
->as
= strtoul(as
, NULL
, 10);
3121 ret
= inet_aton(address
, &aggregator
->address
);
3123 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
3129 static void route_set_aggregator_as_free(void *rule
)
3131 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3134 static const struct route_map_rule_cmd route_set_aggregator_as_cmd
= {
3136 route_set_aggregator_as
,
3137 route_set_aggregator_as_compile
,
3138 route_set_aggregator_as_free
,
3141 /* Set tag to object. object must be pointer to struct bgp_path_info */
3142 static enum route_map_cmd_result_t
3143 route_set_tag(void *rule
, const struct prefix
*prefix
, void *object
)
3146 struct bgp_path_info
*path
;
3152 path
->attr
->tag
= *tag
;
3157 /* Route map commands for tag set. */
3158 static const struct route_map_rule_cmd route_set_tag_cmd
= {
3161 route_map_rule_tag_compile
,
3162 route_map_rule_tag_free
,
3165 /* Set label-index to object. object must be pointer to struct bgp_path_info */
3166 static enum route_map_cmd_result_t
3167 route_set_label_index(void *rule
, const struct prefix
*prefix
, void *object
)
3169 struct rmap_value
*rv
;
3170 struct bgp_path_info
*path
;
3171 uint32_t label_index
;
3173 /* Fetch routemap's rule information. */
3177 /* Set label-index value. */
3178 label_index
= rv
->value
;
3180 path
->attr
->label_index
= label_index
;
3181 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID
);
3187 /* Route map commands for label-index set. */
3188 static const struct route_map_rule_cmd route_set_label_index_cmd
= {
3190 route_set_label_index
,
3191 route_value_compile
,
3195 /* `match ipv6 address IP_ACCESS_LIST' */
3197 static enum route_map_cmd_result_t
3198 route_match_ipv6_address(void *rule
, const struct prefix
*prefix
, void *object
)
3200 struct access_list
*alist
;
3202 if (prefix
->family
== AF_INET6
) {
3203 alist
= access_list_lookup(AFI_IP6
, (char *)rule
);
3205 return RMAP_NOMATCH
;
3207 return (access_list_apply(alist
, prefix
) == FILTER_DENY
3211 return RMAP_NOMATCH
;
3214 static void *route_match_ipv6_address_compile(const char *arg
)
3216 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
3219 static void route_match_ipv6_address_free(void *rule
)
3221 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3224 /* Route map commands for ip address matching. */
3225 static const struct route_map_rule_cmd route_match_ipv6_address_cmd
= {
3227 route_match_ipv6_address
,
3228 route_match_ipv6_address_compile
,
3229 route_match_ipv6_address_free
3232 /* `match ipv6 next-hop ACCESSLIST6_NAME' */
3233 static enum route_map_cmd_result_t
3234 route_match_ipv6_next_hop(void *rule
, const struct prefix
*prefix
, void *object
)
3236 struct bgp_path_info
*path
;
3237 struct access_list
*alist
;
3238 struct prefix_ipv6 p
;
3240 if (prefix
->family
== AF_INET6
) {
3242 p
.family
= AF_INET6
;
3243 p
.prefix
= path
->attr
->mp_nexthop_global
;
3244 p
.prefixlen
= IPV6_MAX_BITLEN
;
3246 alist
= access_list_lookup(AFI_IP6
, (char *)rule
);
3248 return RMAP_NOMATCH
;
3250 if (access_list_apply(alist
, &p
) == FILTER_PERMIT
)
3253 if (path
->attr
->mp_nexthop_len
3254 == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
) {
3255 p
.prefix
= path
->attr
->mp_nexthop_local
;
3256 if (access_list_apply(alist
, &p
) == FILTER_PERMIT
)
3261 return RMAP_NOMATCH
;
3264 static void *route_match_ipv6_next_hop_compile(const char *arg
)
3266 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
3269 static void route_match_ipv6_next_hop_free(void *rule
)
3271 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3274 static const struct route_map_rule_cmd route_match_ipv6_next_hop_cmd
= {
3276 route_match_ipv6_next_hop
,
3277 route_match_ipv6_next_hop_compile
,
3278 route_match_ipv6_next_hop_free
3281 /* `match ipv6 next-hop IP_ADDRESS' */
3283 static enum route_map_cmd_result_t
3284 route_match_ipv6_next_hop_address(void *rule
, const struct prefix
*prefix
,
3287 struct in6_addr
*addr
= rule
;
3288 struct bgp_path_info
*path
;
3292 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
))
3295 if (path
->attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
3296 && IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_local
, rule
))
3299 return RMAP_NOMATCH
;
3302 static void *route_match_ipv6_next_hop_address_compile(const char *arg
)
3304 struct in6_addr
*address
;
3307 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3309 ret
= inet_pton(AF_INET6
, arg
, address
);
3311 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3318 static void route_match_ipv6_next_hop_address_free(void *rule
)
3320 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3323 static const struct route_map_rule_cmd route_match_ipv6_next_hop_address_cmd
= {
3324 "ipv6 next-hop address",
3325 route_match_ipv6_next_hop_address
,
3326 route_match_ipv6_next_hop_address_compile
,
3327 route_match_ipv6_next_hop_address_free
3330 /* `match ip next-hop IP_ADDRESS' */
3332 static enum route_map_cmd_result_t
3333 route_match_ipv4_next_hop(void *rule
, const struct prefix
*prefix
, void *object
)
3335 struct in_addr
*addr
= rule
;
3336 struct bgp_path_info
*path
;
3340 if (path
->attr
->nexthop
.s_addr
== addr
->s_addr
3341 || (path
->attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV4
3342 && IPV4_ADDR_SAME(&path
->attr
->mp_nexthop_global_in
, addr
)))
3345 return RMAP_NOMATCH
;
3348 static void *route_match_ipv4_next_hop_compile(const char *arg
)
3350 struct in_addr
*address
;
3353 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3355 ret
= inet_pton(AF_INET
, arg
, address
);
3357 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3364 static void route_match_ipv4_next_hop_free(void *rule
)
3366 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3369 static const struct route_map_rule_cmd route_match_ipv4_next_hop_cmd
= {
3370 "ip next-hop address",
3371 route_match_ipv4_next_hop
,
3372 route_match_ipv4_next_hop_compile
,
3373 route_match_ipv4_next_hop_free
3376 /* `match ipv6 address prefix-list PREFIX_LIST' */
3378 static enum route_map_cmd_result_t
3379 route_match_ipv6_address_prefix_list(void *rule
, const struct prefix
*prefix
,
3382 return route_match_address_prefix_list(rule
, AFI_IP6
, prefix
, object
);
3385 static void *route_match_ipv6_address_prefix_list_compile(const char *arg
)
3387 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
3390 static void route_match_ipv6_address_prefix_list_free(void *rule
)
3392 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3395 static const struct route_map_rule_cmd
3396 route_match_ipv6_address_prefix_list_cmd
= {
3397 "ipv6 address prefix-list",
3398 route_match_ipv6_address_prefix_list
,
3399 route_match_ipv6_address_prefix_list_compile
,
3400 route_match_ipv6_address_prefix_list_free
3403 /* `match ipv6 next-hop type <TYPE>' */
3405 static enum route_map_cmd_result_t
3406 route_match_ipv6_next_hop_type(void *rule
, const struct prefix
*prefix
,
3409 struct bgp_path_info
*path
;
3410 struct in6_addr
*addr
= rule
;
3412 if (prefix
->family
== AF_INET6
) {
3413 path
= (struct bgp_path_info
*)object
;
3415 return RMAP_NOMATCH
;
3417 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
)
3418 && !path
->attr
->nh_ifindex
)
3422 return RMAP_NOMATCH
;
3425 static void *route_match_ipv6_next_hop_type_compile(const char *arg
)
3427 struct in6_addr
*address
;
3430 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3432 ret
= inet_pton(AF_INET6
, "::0", address
);
3434 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3441 static void route_match_ipv6_next_hop_type_free(void *rule
)
3443 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3446 static const struct route_map_rule_cmd
3447 route_match_ipv6_next_hop_type_cmd
= {
3448 "ipv6 next-hop type",
3449 route_match_ipv6_next_hop_type
,
3450 route_match_ipv6_next_hop_type_compile
,
3451 route_match_ipv6_next_hop_type_free
3454 /* `set ipv6 nexthop global IP_ADDRESS' */
3456 /* Set nexthop to object. object must be pointer to struct attr. */
3457 static enum route_map_cmd_result_t
3458 route_set_ipv6_nexthop_global(void *rule
, const struct prefix
*p
, void *object
)
3460 struct in6_addr
*address
;
3461 struct bgp_path_info
*path
;
3463 /* Fetch routemap's rule information. */
3467 /* Set next hop value. */
3468 path
->attr
->mp_nexthop_global
= *address
;
3470 /* Set nexthop length. */
3471 if (path
->attr
->mp_nexthop_len
== 0)
3472 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL
;
3474 SET_FLAG(path
->attr
->rmap_change_flags
,
3475 BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED
);
3480 /* Route map `ip next-hop' compile function. Given string is converted
3481 to struct in_addr structure. */
3482 static void *route_set_ipv6_nexthop_global_compile(const char *arg
)
3485 struct in6_addr
*address
;
3487 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3489 ret
= inet_pton(AF_INET6
, arg
, address
);
3492 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3499 /* Free route map's compiled `ip next-hop' value. */
3500 static void route_set_ipv6_nexthop_global_free(void *rule
)
3502 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3505 /* Route map commands for ip nexthop set. */
3506 static const struct route_map_rule_cmd
3507 route_set_ipv6_nexthop_global_cmd
= {
3508 "ipv6 next-hop global",
3509 route_set_ipv6_nexthop_global
,
3510 route_set_ipv6_nexthop_global_compile
,
3511 route_set_ipv6_nexthop_global_free
3514 /* Set next-hop preference value. */
3515 static enum route_map_cmd_result_t
3516 route_set_ipv6_nexthop_prefer_global(void *rule
, const struct prefix
*prefix
,
3519 struct bgp_path_info
*path
;
3522 /* Fetch routemap's rule information. */
3526 if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
3527 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
)) {
3528 /* Set next hop preference to global */
3529 path
->attr
->mp_nexthop_prefer_global
= true;
3530 SET_FLAG(path
->attr
->rmap_change_flags
,
3531 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
3533 path
->attr
->mp_nexthop_prefer_global
= false;
3534 SET_FLAG(path
->attr
->rmap_change_flags
,
3535 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
3541 static void *route_set_ipv6_nexthop_prefer_global_compile(const char *arg
)
3545 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
3551 /* Free route map's compiled `ip next-hop' value. */
3552 static void route_set_ipv6_nexthop_prefer_global_free(void *rule
)
3554 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3557 /* Route map commands for ip nexthop set preferred. */
3558 static const struct route_map_rule_cmd
3559 route_set_ipv6_nexthop_prefer_global_cmd
= {
3560 "ipv6 next-hop prefer-global",
3561 route_set_ipv6_nexthop_prefer_global
,
3562 route_set_ipv6_nexthop_prefer_global_compile
,
3563 route_set_ipv6_nexthop_prefer_global_free
3566 /* `set ipv6 nexthop local IP_ADDRESS' */
3568 /* Set nexthop to object. object must be pointer to struct attr. */
3569 static enum route_map_cmd_result_t
3570 route_set_ipv6_nexthop_local(void *rule
, const struct prefix
*p
, void *object
)
3572 struct in6_addr
*address
;
3573 struct bgp_path_info
*path
;
3575 /* Fetch routemap's rule information. */
3579 /* Set next hop value. */
3580 path
->attr
->mp_nexthop_local
= *address
;
3582 /* Set nexthop length. */
3583 if (path
->attr
->mp_nexthop_len
!= BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
3584 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
3586 SET_FLAG(path
->attr
->rmap_change_flags
,
3587 BATTR_RMAP_IPV6_LL_NHOP_CHANGED
);
3592 /* Route map `ip nexthop' compile function. Given string is converted
3593 to struct in_addr structure. */
3594 static void *route_set_ipv6_nexthop_local_compile(const char *arg
)
3597 struct in6_addr
*address
;
3599 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3601 ret
= inet_pton(AF_INET6
, arg
, address
);
3604 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3611 /* Free route map's compiled `ip nexthop' value. */
3612 static void route_set_ipv6_nexthop_local_free(void *rule
)
3614 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3617 /* Route map commands for ip nexthop set. */
3618 static const struct route_map_rule_cmd
3619 route_set_ipv6_nexthop_local_cmd
= {
3620 "ipv6 next-hop local",
3621 route_set_ipv6_nexthop_local
,
3622 route_set_ipv6_nexthop_local_compile
,
3623 route_set_ipv6_nexthop_local_free
3626 /* `set ipv6 nexthop peer-address' */
3628 /* Set nexthop to object. object must be pointer to struct attr. */
3629 static enum route_map_cmd_result_t
3630 route_set_ipv6_nexthop_peer(void *rule
, const struct prefix
*pfx
, void *object
)
3632 struct in6_addr peer_address
;
3633 struct bgp_path_info
*path
;
3636 /* Fetch routemap's rule information. */
3640 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
3641 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
3643 && sockunion_family(peer
->su_remote
) == AF_INET6
) {
3644 peer_address
= peer
->su_remote
->sin6
.sin6_addr
;
3645 /* Set next hop value and length in attribute. */
3646 if (IN6_IS_ADDR_LINKLOCAL(&peer_address
)) {
3647 path
->attr
->mp_nexthop_local
= peer_address
;
3648 if (path
->attr
->mp_nexthop_len
3649 != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
3650 path
->attr
->mp_nexthop_len
=
3651 BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
3653 path
->attr
->mp_nexthop_global
= peer_address
;
3654 if (path
->attr
->mp_nexthop_len
== 0)
3655 path
->attr
->mp_nexthop_len
=
3656 BGP_ATTR_NHLEN_IPV6_GLOBAL
;
3659 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
3660 /* The next hop value will be set as part of packet
3662 * Set the flags here to indicate that rewrite needs to
3664 * Also, clear the value - we clear both global and
3666 * nexthops, whether we send one or both is determined
3669 SET_FLAG(path
->attr
->rmap_change_flags
,
3670 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
3671 /* clear next hop value. */
3672 memset(&(path
->attr
->mp_nexthop_global
), 0,
3673 sizeof(struct in6_addr
));
3674 memset(&(path
->attr
->mp_nexthop_local
), 0,
3675 sizeof(struct in6_addr
));
3681 /* Route map `ip next-hop' compile function. Given string is converted
3682 to struct in_addr structure. */
3683 static void *route_set_ipv6_nexthop_peer_compile(const char *arg
)
3687 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
3693 /* Free route map's compiled `ip next-hop' value. */
3694 static void route_set_ipv6_nexthop_peer_free(void *rule
)
3696 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3699 /* Route map commands for ip nexthop set. */
3700 static const struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd
= {
3701 "ipv6 next-hop peer-address",
3702 route_set_ipv6_nexthop_peer
,
3703 route_set_ipv6_nexthop_peer_compile
,
3704 route_set_ipv6_nexthop_peer_free
3707 /* `set ipv4 vpn next-hop A.B.C.D' */
3709 static enum route_map_cmd_result_t
3710 route_set_vpnv4_nexthop(void *rule
, const struct prefix
*prefix
, void *object
)
3712 struct in_addr
*address
;
3713 struct bgp_path_info
*path
;
3715 /* Fetch routemap's rule information. */
3719 /* Set next hop value. */
3720 path
->attr
->mp_nexthop_global_in
= *address
;
3721 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV4
;
3726 static void *route_set_vpnv4_nexthop_compile(const char *arg
)
3729 struct in_addr
*address
;
3731 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3733 ret
= inet_aton(arg
, address
);
3736 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3743 /* `set ipv6 vpn next-hop A.B.C.D' */
3745 static enum route_map_cmd_result_t
3746 route_set_vpnv6_nexthop(void *rule
, const struct prefix
*prefix
, void *object
)
3748 struct in6_addr
*address
;
3749 struct bgp_path_info
*path
;
3751 /* Fetch routemap's rule information. */
3755 /* Set next hop value. */
3756 memcpy(&path
->attr
->mp_nexthop_global
, address
,
3757 sizeof(struct in6_addr
));
3758 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_VPNV6_GLOBAL
;
3763 static void *route_set_vpnv6_nexthop_compile(const char *arg
)
3766 struct in6_addr
*address
;
3768 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3769 ret
= inet_pton(AF_INET6
, arg
, address
);
3772 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3779 static void route_set_vpn_nexthop_free(void *rule
)
3781 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3784 /* Route map commands for ipv4 next-hop set. */
3785 static const struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd
= {
3786 "ipv4 vpn next-hop",
3787 route_set_vpnv4_nexthop
,
3788 route_set_vpnv4_nexthop_compile
,
3789 route_set_vpn_nexthop_free
3792 /* Route map commands for ipv6 next-hop set. */
3793 static const struct route_map_rule_cmd route_set_vpnv6_nexthop_cmd
= {
3794 "ipv6 vpn next-hop",
3795 route_set_vpnv6_nexthop
,
3796 route_set_vpnv6_nexthop_compile
,
3797 route_set_vpn_nexthop_free
3800 /* `set originator-id' */
3802 /* For origin set. */
3803 static enum route_map_cmd_result_t
3804 route_set_originator_id(void *rule
, const struct prefix
*prefix
, void *object
)
3806 struct in_addr
*address
;
3807 struct bgp_path_info
*path
;
3812 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
);
3813 path
->attr
->originator_id
= *address
;
3818 /* Compile function for originator-id set. */
3819 static void *route_set_originator_id_compile(const char *arg
)
3822 struct in_addr
*address
;
3824 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3826 ret
= inet_aton(arg
, address
);
3829 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3836 /* Compile function for originator_id set. */
3837 static void route_set_originator_id_free(void *rule
)
3839 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3842 /* Set originator-id rule structure. */
3843 static const struct route_map_rule_cmd route_set_originator_id_cmd
= {
3845 route_set_originator_id
,
3846 route_set_originator_id_compile
,
3847 route_set_originator_id_free
,
3850 static enum route_map_cmd_result_t
3851 route_match_rpki_extcommunity(void *rule
, const struct prefix
*prefix
,
3854 struct bgp_path_info
*path
;
3855 struct ecommunity
*ecomm
;
3856 struct ecommunity_val
*ecomm_val
;
3857 enum rpki_states
*rpki_status
= rule
;
3858 enum rpki_states ecomm_rpki_status
= RPKI_NOT_BEING_USED
;
3862 ecomm
= bgp_attr_get_ecommunity(path
->attr
);
3864 return RMAP_NOMATCH
;
3866 ecomm_val
= ecommunity_lookup(ecomm
, ECOMMUNITY_ENCODE_OPAQUE_NON_TRANS
,
3867 ECOMMUNITY_ORIGIN_VALIDATION_STATE
);
3869 return RMAP_NOMATCH
;
3871 /* The Origin Validation State is encoded in the last octet of
3872 * the extended community.
3874 switch (ecomm_val
->val
[7]) {
3875 case ECOMMUNITY_ORIGIN_VALIDATION_STATE_VALID
:
3876 ecomm_rpki_status
= RPKI_VALID
;
3878 case ECOMMUNITY_ORIGIN_VALIDATION_STATE_NOTFOUND
:
3879 ecomm_rpki_status
= RPKI_NOTFOUND
;
3881 case ECOMMUNITY_ORIGIN_VALIDATION_STATE_INVALID
:
3882 ecomm_rpki_status
= RPKI_INVALID
;
3884 case ECOMMUNITY_ORIGIN_VALIDATION_STATE_NOTUSED
:
3888 if (ecomm_rpki_status
== *rpki_status
)
3891 return RMAP_NOMATCH
;
3894 static void *route_match_extcommunity_compile(const char *arg
)
3898 rpki_status
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
3900 if (strcmp(arg
, "valid") == 0)
3901 *rpki_status
= RPKI_VALID
;
3902 else if (strcmp(arg
, "invalid") == 0)
3903 *rpki_status
= RPKI_INVALID
;
3905 *rpki_status
= RPKI_NOTFOUND
;
3910 static const struct route_map_rule_cmd route_match_rpki_extcommunity_cmd
= {
3911 "rpki-extcommunity",
3912 route_match_rpki_extcommunity
,
3913 route_match_extcommunity_compile
,
3918 * This is the workhorse routine for processing in/out routemap
3921 static void bgp_route_map_process_peer(const char *rmap_name
,
3922 struct route_map
*map
, struct peer
*peer
,
3923 int afi
, int safi
, int route_update
)
3925 struct bgp_filter
*filter
;
3927 if (!peer
|| !rmap_name
)
3930 filter
= &peer
->filter
[afi
][safi
];
3932 * in is for non-route-server clients,
3933 * out is for all peers
3935 if (filter
->map
[RMAP_IN
].name
3936 && (strcmp(rmap_name
, filter
->map
[RMAP_IN
].name
) == 0)) {
3937 filter
->map
[RMAP_IN
].map
= map
;
3939 if (route_update
&& peer_established(peer
)) {
3940 if (CHECK_FLAG(peer
->af_flags
[afi
][safi
],
3941 PEER_FLAG_SOFT_RECONFIG
)) {
3942 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3944 "Processing route_map %s(%s:%s) update on peer %s (inbound, soft-reconfig)",
3945 rmap_name
, afi2str(afi
),
3946 safi2str(safi
), peer
->host
);
3948 bgp_soft_reconfig_in(peer
, afi
, safi
);
3949 } else if (CHECK_FLAG(peer
->cap
,
3950 PEER_CAP_REFRESH_OLD_RCV
)
3951 || CHECK_FLAG(peer
->cap
,
3952 PEER_CAP_REFRESH_NEW_RCV
)) {
3953 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3955 "Processing route_map %s(%s:%s) update on peer %s (inbound, route-refresh)",
3956 rmap_name
, afi2str(afi
),
3957 safi2str(safi
), peer
->host
);
3958 bgp_route_refresh_send(
3959 peer
, afi
, safi
, 0, 0, 0,
3960 BGP_ROUTE_REFRESH_NORMAL
);
3966 * For outbound, unsuppress and default-originate map change (content or
3967 * map created), merely update the "config" here, the actual route
3968 * announcement happens at the group level.
3970 if (filter
->map
[RMAP_OUT
].name
3971 && (strcmp(rmap_name
, filter
->map
[RMAP_OUT
].name
) == 0))
3972 filter
->map
[RMAP_OUT
].map
= map
;
3974 if (filter
->usmap
.name
&& (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3975 filter
->usmap
.map
= map
;
3977 if (filter
->advmap
.aname
3978 && (strcmp(rmap_name
, filter
->advmap
.aname
) == 0)) {
3979 filter
->advmap
.amap
= map
;
3982 if (filter
->advmap
.cname
3983 && (strcmp(rmap_name
, filter
->advmap
.cname
) == 0)) {
3984 filter
->advmap
.cmap
= map
;
3987 if (peer
->default_rmap
[afi
][safi
].name
3988 && (strcmp(rmap_name
, peer
->default_rmap
[afi
][safi
].name
) == 0))
3989 peer
->default_rmap
[afi
][safi
].map
= map
;
3991 /* Notify BGP conditional advertisement scanner percess */
3992 peer
->advmap_config_change
[afi
][safi
] = true;
3995 static void bgp_route_map_update_peer_group(const char *rmap_name
,
3996 struct route_map
*map
,
3999 struct peer_group
*group
;
4000 struct listnode
*node
, *nnode
;
4001 struct bgp_filter
*filter
;
4008 /* All the peers have been updated correctly already. This is
4009 * just updating the placeholder data. No real update required.
4011 for (ALL_LIST_ELEMENTS(bgp
->group
, node
, nnode
, group
)) {
4012 FOREACH_AFI_SAFI (afi
, safi
) {
4013 filter
= &group
->conf
->filter
[afi
][safi
];
4015 for (direct
= RMAP_IN
; direct
< RMAP_MAX
; direct
++) {
4016 if ((filter
->map
[direct
].name
)
4017 && (strcmp(rmap_name
,
4018 filter
->map
[direct
].name
)
4020 filter
->map
[direct
].map
= map
;
4023 if (filter
->usmap
.name
4024 && (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
4025 filter
->usmap
.map
= map
;
4027 if (filter
->advmap
.aname
&&
4028 (strcmp(rmap_name
, filter
->advmap
.aname
) == 0))
4029 filter
->advmap
.amap
= map
;
4031 if (filter
->advmap
.cname
&&
4032 (strcmp(rmap_name
, filter
->advmap
.cname
) == 0))
4033 filter
->advmap
.cmap
= map
;
4039 * Note that if an extreme number (tens of thousands) of route-maps are in use
4040 * and if bgp has an extreme number of peers, network statements, etc then this
4041 * function can consume a lot of cycles. This is due to this function being
4042 * called for each route-map and within this function we walk the list of peers,
4043 * network statements, etc looking to see if they use this route-map.
4045 static void bgp_route_map_process_update(struct bgp
*bgp
, const char *rmap_name
,
4053 struct bgp_dest
*bn
;
4054 struct bgp_static
*bgp_static
;
4055 struct bgp_aggregate
*aggregate
;
4056 struct listnode
*node
, *nnode
;
4057 struct route_map
*map
;
4058 char buf
[INET6_ADDRSTRLEN
];
4060 map
= route_map_lookup_by_name(rmap_name
);
4062 for (ALL_LIST_ELEMENTS(bgp
->peer
, node
, nnode
, peer
)) {
4064 /* Ignore dummy peer-group structure */
4065 if (CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
))
4068 FOREACH_AFI_SAFI (afi
, safi
) {
4069 /* process in/out/import/export/default-orig
4071 bgp_route_map_process_peer(rmap_name
, map
, peer
, afi
,
4072 safi
, route_update
);
4076 /* for outbound/default-orig route-maps, process for groups */
4077 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
, rmap_name
,
4080 /* update peer-group config (template) */
4081 bgp_route_map_update_peer_group(rmap_name
, map
, bgp
);
4083 FOREACH_AFI_SAFI (afi
, safi
) {
4084 /* For table route-map updates. */
4085 if (!bgp_fibupd_safi(safi
))
4088 if (bgp
->table_map
[afi
][safi
].name
4089 && (strcmp(rmap_name
, bgp
->table_map
[afi
][safi
].name
)
4092 /* bgp->table_map[afi][safi].map is NULL.
4093 * i.e Route map creation event.
4094 * So update applied_counter.
4095 * If it is not NULL, i.e It may be routemap updation or
4096 * deletion. so no need to update the counter.
4098 if (!bgp
->table_map
[afi
][safi
].map
)
4099 route_map_counter_increment(map
);
4100 bgp
->table_map
[afi
][safi
].map
= map
;
4102 if (BGP_DEBUG(zebra
, ZEBRA
))
4104 "Processing route_map %s(%s:%s) update on table map",
4105 rmap_name
, afi2str(afi
),
4108 bgp_zebra_announce_table(bgp
, afi
, safi
);
4111 /* For network route-map updates. */
4112 for (bn
= bgp_table_top(bgp
->route
[afi
][safi
]); bn
;
4113 bn
= bgp_route_next(bn
)) {
4114 bgp_static
= bgp_dest_get_bgp_static_info(bn
);
4118 if (!bgp_static
->rmap
.name
4119 || (strcmp(rmap_name
, bgp_static
->rmap
.name
) != 0))
4122 if (!bgp_static
->rmap
.map
)
4123 route_map_counter_increment(map
);
4125 bgp_static
->rmap
.map
= map
;
4127 if (route_update
&& !bgp_static
->backdoor
) {
4128 const struct prefix
*bn_p
=
4129 bgp_dest_get_prefix(bn
);
4131 if (bgp_debug_zebra(bn_p
))
4133 "Processing route_map %s(%s:%s) update on static route %s",
4134 rmap_name
, afi2str(afi
),
4136 inet_ntop(bn_p
->family
,
4137 &bn_p
->u
.prefix
, buf
,
4139 bgp_static_update(bgp
, bn_p
, bgp_static
, afi
,
4144 /* For aggregate-address route-map updates. */
4145 for (bn
= bgp_table_top(bgp
->aggregate
[afi
][safi
]); bn
;
4146 bn
= bgp_route_next(bn
)) {
4147 aggregate
= bgp_dest_get_bgp_aggregate_info(bn
);
4153 /* Update suppress map pointer. */
4154 if (aggregate
->suppress_map_name
4155 && strmatch(aggregate
->suppress_map_name
,
4157 if (aggregate
->rmap
.map
== NULL
)
4158 route_map_counter_increment(map
);
4160 aggregate
->suppress_map
= map
;
4162 bgp_aggregate_toggle_suppressed(
4163 aggregate
, bgp
, bgp_dest_get_prefix(bn
),
4169 if (aggregate
->rmap
.name
4170 && strmatch(rmap_name
, aggregate
->rmap
.name
)) {
4171 if (aggregate
->rmap
.map
== NULL
)
4172 route_map_counter_increment(map
);
4174 aggregate
->rmap
.map
= map
;
4179 if (matched
&& route_update
) {
4180 const struct prefix
*bn_p
=
4181 bgp_dest_get_prefix(bn
);
4183 if (bgp_debug_zebra(bn_p
))
4185 "Processing route_map %s(%s:%s) update on aggregate-address route %s",
4186 rmap_name
, afi2str(afi
),
4188 inet_ntop(bn_p
->family
,
4189 &bn_p
->u
.prefix
, buf
,
4191 bgp_aggregate_route(bgp
, bn_p
, afi
, safi
,
4197 /* For redistribute route-map updates. */
4198 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
4199 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
4200 struct list
*red_list
;
4201 struct bgp_redist
*red
;
4203 red_list
= bgp
->redist
[afi
][i
];
4207 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
4209 || (strcmp(rmap_name
, red
->rmap
.name
) != 0))
4213 route_map_counter_increment(map
);
4215 red
->rmap
.map
= map
;
4220 if (BGP_DEBUG(zebra
, ZEBRA
))
4222 "Processing route_map %s(%s:%s) update on redistributed routes",
4223 rmap_name
, afi2str(afi
),
4226 bgp_redistribute_resend(bgp
, afi
, i
,
4231 /* for type5 command route-maps */
4232 FOREACH_AFI_SAFI (afi
, safi
) {
4233 if (!bgp
->adv_cmd_rmap
[afi
][safi
].name
4234 || strcmp(rmap_name
, bgp
->adv_cmd_rmap
[afi
][safi
].name
)
4238 /* Make sure the route-map is populated here if not already done */
4239 bgp
->adv_cmd_rmap
[afi
][safi
].map
= map
;
4241 if (BGP_DEBUG(zebra
, ZEBRA
))
4243 "Processing route_map %s(%s:%s) update on advertise type5 route command",
4244 rmap_name
, afi2str(afi
), safi2str(safi
));
4246 if (route_update
&& advertise_type5_routes(bgp
, afi
)) {
4247 bgp_evpn_withdraw_type5_routes(bgp
, afi
, safi
);
4248 bgp_evpn_advertise_type5_routes(bgp
, afi
, safi
);
4253 static void bgp_route_map_process_update_cb(char *rmap_name
)
4255 struct listnode
*node
, *nnode
;
4258 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
)) {
4259 bgp_route_map_process_update(bgp
, rmap_name
, true);
4261 #ifdef ENABLE_BGP_VNC
4262 vnc_routemap_update(bgp
, __func__
);
4266 vpn_policy_routemap_event(rmap_name
);
4269 void bgp_route_map_update_timer(struct thread
*thread
)
4271 route_map_walk_update_list(bgp_route_map_process_update_cb
);
4274 static void bgp_route_map_mark_update(const char *rmap_name
)
4276 struct listnode
*node
, *nnode
;
4279 /* If new update is received before the current timer timed out,
4280 * turn it off and start a new timer.
4282 THREAD_OFF(bm
->t_rmap_update
);
4284 /* rmap_update_timer of 0 means don't do route updates */
4285 if (bm
->rmap_update_timer
) {
4286 thread_add_timer(bm
->master
, bgp_route_map_update_timer
,
4287 NULL
, bm
->rmap_update_timer
,
4288 &bm
->t_rmap_update
);
4290 /* Signal the groups that a route-map update event has
4292 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
4293 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
,
4294 rmap_name
, true, 1);
4296 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
)) {
4297 bgp_route_map_process_update(bgp
, rmap_name
, false);
4298 #ifdef ENABLE_BGP_VNC
4299 vnc_routemap_update(bgp
, __func__
);
4303 vpn_policy_routemap_event(rmap_name
);
4307 static void bgp_route_map_add(const char *rmap_name
)
4309 if (route_map_mark_updated(rmap_name
) == 0)
4310 bgp_route_map_mark_update(rmap_name
);
4312 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
4315 static void bgp_route_map_delete(const char *rmap_name
)
4317 if (route_map_mark_updated(rmap_name
) == 0)
4318 bgp_route_map_mark_update(rmap_name
);
4320 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_DELETED
);
4323 static void bgp_route_map_event(const char *rmap_name
)
4325 if (route_map_mark_updated(rmap_name
) == 0)
4326 bgp_route_map_mark_update(rmap_name
);
4328 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
4331 DEFUN_YANG (match_mac_address
,
4332 match_mac_address_cmd
,
4333 "match mac address ACCESSLIST_MAC_NAME",
4336 "Match address of route\n"
4337 "MAC Access-list name\n")
4340 "./match-condition[condition='frr-bgp-route-map:mac-address-list']";
4341 char xpath_value
[XPATH_MAXLEN
];
4343 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4344 snprintf(xpath_value
, sizeof(xpath_value
),
4345 "%s/rmap-match-condition/frr-bgp-route-map:list-name", xpath
);
4346 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[3]->arg
);
4348 return nb_cli_apply_changes(vty
, NULL
);
4351 DEFUN_YANG (no_match_mac_address
,
4352 no_match_mac_address_cmd
,
4353 "no match mac address ACCESSLIST_MAC_NAME",
4357 "Match address of route\n"
4358 "MAC acess-list name\n")
4361 "./match-condition[condition='frr-bgp-route-map:mac-address-list']";
4363 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4364 return nb_cli_apply_changes(vty
, NULL
);
4368 * Helper to handle the case of the user passing in a number or type string
4370 static const char *parse_evpn_rt_type(const char *num_rt_type
)
4372 switch (num_rt_type
[0]) {
4387 /* Was already full type string */
4391 DEFUN_YANG (match_evpn_route_type
,
4392 match_evpn_route_type_cmd
,
4393 "match evpn route-type <ead|1|macip|2|multicast|3|es|4|prefix|5>",
4397 EVPN_TYPE_1_HELP_STR
4398 EVPN_TYPE_1_HELP_STR
4399 EVPN_TYPE_2_HELP_STR
4400 EVPN_TYPE_2_HELP_STR
4401 EVPN_TYPE_3_HELP_STR
4402 EVPN_TYPE_3_HELP_STR
4403 EVPN_TYPE_4_HELP_STR
4404 EVPN_TYPE_4_HELP_STR
4405 EVPN_TYPE_5_HELP_STR
4406 EVPN_TYPE_5_HELP_STR
)
4409 "./match-condition[condition='frr-bgp-route-map:evpn-route-type']";
4410 char xpath_value
[XPATH_MAXLEN
];
4412 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4413 snprintf(xpath_value
, sizeof(xpath_value
),
4414 "%s/rmap-match-condition/frr-bgp-route-map:evpn-route-type",
4416 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4417 parse_evpn_rt_type(argv
[3]->arg
));
4419 return nb_cli_apply_changes(vty
, NULL
);
4422 DEFUN_YANG (no_match_evpn_route_type
,
4423 no_match_evpn_route_type_cmd
,
4424 "no match evpn route-type <ead|1|macip|2|multicast|3|es|4|prefix|5>",
4429 EVPN_TYPE_1_HELP_STR
4430 EVPN_TYPE_1_HELP_STR
4431 EVPN_TYPE_2_HELP_STR
4432 EVPN_TYPE_2_HELP_STR
4433 EVPN_TYPE_3_HELP_STR
4434 EVPN_TYPE_3_HELP_STR
4435 EVPN_TYPE_4_HELP_STR
4436 EVPN_TYPE_4_HELP_STR
4437 EVPN_TYPE_5_HELP_STR
4438 EVPN_TYPE_5_HELP_STR
)
4441 "./match-condition[condition='frr-bgp-route-map:evpn-route-type']";
4443 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4445 return nb_cli_apply_changes(vty
, NULL
);
4449 DEFUN_YANG (match_evpn_vni
,
4451 "match evpn vni " CMD_VNI_RANGE
,
4458 "./match-condition[condition='frr-bgp-route-map:evpn-vni']";
4459 char xpath_value
[XPATH_MAXLEN
];
4461 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4462 snprintf(xpath_value
, sizeof(xpath_value
),
4463 "%s/rmap-match-condition/frr-bgp-route-map:evpn-vni", xpath
);
4464 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[3]->arg
);
4466 return nb_cli_apply_changes(vty
, NULL
);
4469 DEFUN_YANG (no_match_evpn_vni
,
4470 no_match_evpn_vni_cmd
,
4471 "no match evpn vni " CMD_VNI_RANGE
,
4479 "./match-condition[condition='frr-bgp-route-map:evpn-vni']";
4480 char xpath_value
[XPATH_MAXLEN
];
4482 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4483 snprintf(xpath_value
, sizeof(xpath_value
),
4484 "%s/rmap-match-condition/frr-bgp-route-map:evpn-vni", xpath
);
4485 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_DESTROY
, argv
[3]->arg
);
4487 return nb_cli_apply_changes(vty
, NULL
);
4490 DEFUN_YANG (match_evpn_default_route
,
4491 match_evpn_default_route_cmd
,
4492 "match evpn default-route",
4495 "default EVPN type-5 route\n")
4498 "./match-condition[condition='frr-bgp-route-map:evpn-default-route']";
4499 char xpath_value
[XPATH_MAXLEN
];
4501 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4503 snprintf(xpath_value
, sizeof(xpath_value
),
4504 "%s/rmap-match-condition/frr-bgp-route-map:evpn-default-route",
4506 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, NULL
);
4508 return nb_cli_apply_changes(vty
, NULL
);
4511 DEFUN_YANG (no_match_evpn_default_route
,
4512 no_match_evpn_default_route_cmd
,
4513 "no match evpn default-route",
4517 "default EVPN type-5 route\n")
4520 "./match-condition[condition='frr-bgp-route-map:evpn-default-route']";
4522 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4524 return nb_cli_apply_changes(vty
, NULL
);
4527 DEFUN_YANG (match_evpn_rd
,
4529 "match evpn rd ASN:NN_OR_IP-ADDRESS:NN",
4532 "Route Distinguisher\n"
4533 "ASN:XX or A.B.C.D:XX\n")
4536 "./match-condition[condition='frr-bgp-route-map:evpn-rd']";
4537 char xpath_value
[XPATH_MAXLEN
];
4539 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4541 xpath_value
, sizeof(xpath_value
),
4542 "%s/rmap-match-condition/frr-bgp-route-map:route-distinguisher",
4544 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[3]->arg
);
4546 return nb_cli_apply_changes(vty
, NULL
);
4549 DEFUN_YANG (no_match_evpn_rd
,
4550 no_match_evpn_rd_cmd
,
4551 "no match evpn rd ASN:NN_OR_IP-ADDRESS:NN",
4555 "Route Distinguisher\n"
4556 "ASN:XX or A.B.C.D:XX\n")
4559 "./match-condition[condition='frr-bgp-route-map:evpn-rd']";
4561 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4562 return nb_cli_apply_changes(vty
, NULL
);
4565 DEFUN_YANG (set_evpn_gw_ip_ipv4
,
4566 set_evpn_gw_ip_ipv4_cmd
,
4567 "set evpn gateway-ip ipv4 A.B.C.D",
4570 "Set gateway IP for prefix advertisement route\n"
4572 "Gateway IP address in IPv4 format\n")
4577 "./set-action[action='frr-bgp-route-map:set-evpn-gateway-ip-ipv4']";
4578 char xpath_value
[XPATH_MAXLEN
];
4580 ret
= str2sockunion(argv
[4]->arg
, &su
);
4582 vty_out(vty
, "%% Malformed gateway IP\n");
4583 return CMD_WARNING_CONFIG_FAILED
;
4586 if (su
.sin
.sin_addr
.s_addr
== 0 ||
4587 !ipv4_unicast_valid(&su
.sin
.sin_addr
)) {
4589 "%% Gateway IP cannot be 0.0.0.0, multicast or reserved\n");
4590 return CMD_WARNING_CONFIG_FAILED
;
4593 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4595 snprintf(xpath_value
, sizeof(xpath_value
),
4596 "%s/rmap-set-action/frr-bgp-route-map:evpn-gateway-ip-ipv4",
4599 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[4]->arg
);
4600 return nb_cli_apply_changes(vty
, NULL
);
4603 DEFUN_YANG (no_set_evpn_gw_ip_ipv4
,
4604 no_set_evpn_gw_ip_ipv4_cmd
,
4605 "no set evpn gateway-ip ipv4 A.B.C.D",
4609 "Set gateway IP for prefix advertisement route\n"
4611 "Gateway IP address in IPv4 format\n")
4616 "./set-action[action='frr-bgp-route-map:set-evpn-gateway-ip-ipv4']";
4618 ret
= str2sockunion(argv
[5]->arg
, &su
);
4620 vty_out(vty
, "%% Malformed gateway IP\n");
4621 return CMD_WARNING_CONFIG_FAILED
;
4624 if (su
.sin
.sin_addr
.s_addr
== 0 ||
4625 !ipv4_unicast_valid(&su
.sin
.sin_addr
)) {
4627 "%% Gateway IP cannot be 0.0.0.0, multicast or reserved\n");
4628 return CMD_WARNING_CONFIG_FAILED
;
4631 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4633 return nb_cli_apply_changes(vty
, NULL
);
4636 DEFUN_YANG (set_evpn_gw_ip_ipv6
,
4637 set_evpn_gw_ip_ipv6_cmd
,
4638 "set evpn gateway-ip ipv6 X:X::X:X",
4641 "Set gateway IP for prefix advertisement route\n"
4643 "Gateway IP address in IPv6 format\n")
4648 "./set-action[action='frr-bgp-route-map:set-evpn-gateway-ip-ipv6']";
4649 char xpath_value
[XPATH_MAXLEN
];
4651 ret
= str2sockunion(argv
[4]->arg
, &su
);
4653 vty_out(vty
, "%% Malformed gateway IP\n");
4654 return CMD_WARNING_CONFIG_FAILED
;
4657 if (IN6_IS_ADDR_LINKLOCAL(&su
.sin6
.sin6_addr
)
4658 || IN6_IS_ADDR_MULTICAST(&su
.sin6
.sin6_addr
)) {
4660 "%% Gateway IP cannot be a linklocal or multicast address\n");
4661 return CMD_WARNING_CONFIG_FAILED
;
4664 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4666 snprintf(xpath_value
, sizeof(xpath_value
),
4667 "%s/rmap-set-action/frr-bgp-route-map:evpn-gateway-ip-ipv6",
4670 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[4]->arg
);
4671 return nb_cli_apply_changes(vty
, NULL
);
4674 DEFUN_YANG (no_set_evpn_gw_ip_ipv6
,
4675 no_set_evpn_gw_ip_ipv6_cmd
,
4676 "no set evpn gateway-ip ipv6 X:X::X:X",
4680 "Set gateway IP for prefix advertisement route\n"
4682 "Gateway IP address in IPv4 format\n")
4687 "./set-action[action='frr-bgp-route-map:set-evpn-gateway-ip-ipv6']";
4689 ret
= str2sockunion(argv
[5]->arg
, &su
);
4691 vty_out(vty
, "%% Malformed gateway IP\n");
4692 return CMD_WARNING_CONFIG_FAILED
;
4695 if (IN6_IS_ADDR_LINKLOCAL(&su
.sin6
.sin6_addr
)
4696 || IN6_IS_ADDR_MULTICAST(&su
.sin6
.sin6_addr
)) {
4698 "%% Gateway IP cannot be a linklocal or multicast address\n");
4699 return CMD_WARNING_CONFIG_FAILED
;
4702 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4704 return nb_cli_apply_changes(vty
, NULL
);
4707 DEFPY_YANG(match_vrl_source_vrf
,
4708 match_vrl_source_vrf_cmd
,
4709 "match source-vrf NAME$vrf_name",
4715 "./match-condition[condition='frr-bgp-route-map:source-vrf']";
4716 char xpath_value
[XPATH_MAXLEN
];
4718 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4719 snprintf(xpath_value
, sizeof(xpath_value
),
4720 "%s/rmap-match-condition/frr-bgp-route-map:source-vrf", xpath
);
4721 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, vrf_name
);
4723 return nb_cli_apply_changes(vty
, NULL
);
4726 DEFPY_YANG(no_match_vrl_source_vrf
,
4727 no_match_vrl_source_vrf_cmd
,
4728 "no match source-vrf NAME$vrf_name",
4734 "./match-condition[condition='frr-bgp-route-map:source-vrf']";
4736 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4737 return nb_cli_apply_changes(vty
, NULL
);
4740 DEFPY_YANG (match_peer
,
4742 "match peer <A.B.C.D$addrv4|X:X::X:X$addrv6|WORD$intf>",
4744 "Match peer address\n"
4745 "IP address of peer\n"
4746 "IPv6 address of peer\n"
4747 "Interface name of peer or peer group name\n")
4750 "./match-condition[condition='frr-bgp-route-map:peer']";
4751 char xpath_value
[XPATH_MAXLEN
];
4753 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4757 xpath_value
, sizeof(xpath_value
),
4758 "%s/rmap-match-condition/frr-bgp-route-map:peer-ipv4-address",
4760 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4762 } else if (addrv6_str
) {
4764 xpath_value
, sizeof(xpath_value
),
4765 "%s/rmap-match-condition/frr-bgp-route-map:peer-ipv6-address",
4767 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4771 xpath_value
, sizeof(xpath_value
),
4772 "%s/rmap-match-condition/frr-bgp-route-map:peer-interface",
4774 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, intf
);
4777 return nb_cli_apply_changes(vty
, NULL
);
4780 DEFUN_YANG (match_peer_local
,
4781 match_peer_local_cmd
,
4784 "Match peer address\n"
4785 "Static or Redistributed routes\n")
4788 "./match-condition[condition='frr-bgp-route-map:peer']";
4789 char xpath_value
[XPATH_MAXLEN
];
4791 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4793 snprintf(xpath_value
, sizeof(xpath_value
),
4794 "%s/rmap-match-condition/frr-bgp-route-map:peer-local", xpath
);
4795 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
4797 return nb_cli_apply_changes(vty
, NULL
);
4800 DEFUN_YANG (no_match_peer
,
4802 "no match peer [<local|A.B.C.D|X:X::X:X|WORD>]",
4805 "Match peer address\n"
4806 "Static or Redistributed routes\n"
4807 "IP address of peer\n"
4808 "IPv6 address of peer\n"
4809 "Interface name of peer\n")
4812 "./match-condition[condition='frr-bgp-route-map:peer']";
4814 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4816 return nb_cli_apply_changes(vty
, NULL
);
4819 #ifdef HAVE_SCRIPTING
4820 DEFUN_YANG (match_script
,
4822 "[no] match script WORD",
4825 "Execute script to determine match\n"
4826 "The script name to run, without .lua; e.g. 'myroutemap' to run myroutemap.lua\n")
4828 bool no
= strmatch(argv
[0]->text
, "no");
4830 argv_find(argv
, argc
, "WORD", &i
);
4831 const char *script
= argv
[i
]->arg
;
4833 "./match-condition[condition='frr-bgp-route-map:match-script']";
4834 char xpath_value
[XPATH_MAXLEN
];
4837 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4838 snprintf(xpath_value
, sizeof(xpath_value
),
4839 "%s/rmap-match-condition/frr-bgp-route-map:script",
4841 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_DESTROY
,
4844 return nb_cli_apply_changes(vty
, NULL
);
4847 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4848 snprintf(xpath_value
, sizeof(xpath_value
),
4849 "%s/rmap-match-condition/frr-bgp-route-map:script",
4851 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4854 return nb_cli_apply_changes(vty
, NULL
);
4856 #endif /* HAVE_SCRIPTING */
4858 /* match probability */
4859 DEFUN_YANG (match_probability
,
4860 match_probability_cmd
,
4861 "match probability (0-100)",
4863 "Match portion of routes defined by percentage value\n"
4864 "Percentage of routes\n")
4869 "./match-condition[condition='frr-bgp-route-map:probability']";
4870 char xpath_value
[XPATH_MAXLEN
];
4872 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4873 snprintf(xpath_value
, sizeof(xpath_value
),
4874 "%s/rmap-match-condition/frr-bgp-route-map:probability",
4876 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4877 argv
[idx_number
]->arg
);
4879 return nb_cli_apply_changes(vty
, NULL
);
4883 DEFUN_YANG (no_match_probability
,
4884 no_match_probability_cmd
,
4885 "no match probability [(1-99)]",
4888 "Match portion of routes defined by percentage value\n"
4889 "Percentage of routes\n")
4893 "./match-condition[condition='frr-bgp-route-map:probability']";
4894 char xpath_value
[XPATH_MAXLEN
];
4896 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4898 if (argc
<= idx_number
)
4899 return nb_cli_apply_changes(vty
, NULL
);
4901 snprintf(xpath_value
, sizeof(xpath_value
),
4902 "%s/rmap-match-condition/frr-bgp-route-map:probability",
4904 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_DESTROY
,
4905 argv
[idx_number
]->arg
);
4907 return nb_cli_apply_changes(vty
, NULL
);
4911 DEFPY_YANG (match_ip_route_source
,
4912 match_ip_route_source_cmd
,
4913 "match ip route-source ACCESSLIST4_NAME",
4916 "Match advertising source address of route\n"
4917 "IP Access-list name\n")
4920 "./match-condition[condition='frr-bgp-route-map:ip-route-source']";
4921 char xpath_value
[XPATH_MAXLEN
+ 32];
4924 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4925 snprintf(xpath_value
, sizeof(xpath_value
),
4926 "%s/rmap-match-condition/frr-bgp-route-map:list-name",
4928 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4929 argv
[idx_acl
]->arg
);
4931 return nb_cli_apply_changes(vty
, NULL
);
4935 DEFUN_YANG (no_match_ip_route_source
,
4936 no_match_ip_route_source_cmd
,
4937 "no match ip route-source [ACCESSLIST4_NAME]",
4941 "Match advertising source address of route\n"
4942 "IP Access-list name\n")
4945 "./match-condition[condition='frr-bgp-route-map:ip-route-source']";
4947 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4948 return nb_cli_apply_changes(vty
, NULL
);
4951 DEFUN_YANG (match_ip_route_source_prefix_list
,
4952 match_ip_route_source_prefix_list_cmd
,
4953 "match ip route-source prefix-list PREFIXLIST_NAME",
4956 "Match advertising source address of route\n"
4957 "Match entries of prefix-lists\n"
4958 "IP prefix-list name\n")
4962 "./match-condition[condition='frr-bgp-route-map:ip-route-source-prefix-list']";
4963 char xpath_value
[XPATH_MAXLEN
+ 32];
4965 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4966 snprintf(xpath_value
, sizeof(xpath_value
),
4967 "%s/rmap-match-condition/frr-bgp-route-map:list-name", xpath
);
4968 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4969 argv
[idx_word
]->arg
);
4971 return nb_cli_apply_changes(vty
, NULL
);
4975 DEFUN_YANG (no_match_ip_route_source_prefix_list
,
4976 no_match_ip_route_source_prefix_list_cmd
,
4977 "no match ip route-source prefix-list [PREFIXLIST_NAME]",
4981 "Match advertising source address of route\n"
4982 "Match entries of prefix-lists\n"
4983 "IP prefix-list name\n")
4986 "./match-condition[condition='frr-bgp-route-map:ip-route-source-prefix-list']";
4988 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4989 return nb_cli_apply_changes(vty
, NULL
);
4992 DEFUN_YANG (match_local_pref
,
4993 match_local_pref_cmd
,
4994 "match local-preference (0-4294967295)",
4996 "Match local-preference of route\n"
5002 "./match-condition[condition='frr-bgp-route-map:match-local-preference']";
5003 char xpath_value
[XPATH_MAXLEN
];
5005 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5006 snprintf(xpath_value
, sizeof(xpath_value
),
5007 "%s/rmap-match-condition/frr-bgp-route-map:local-preference",
5009 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5010 argv
[idx_number
]->arg
);
5012 return nb_cli_apply_changes(vty
, NULL
);
5016 DEFUN_YANG (no_match_local_pref
,
5017 no_match_local_pref_cmd
,
5018 "no match local-preference [(0-4294967295)]",
5021 "Match local preference of route\n"
5022 "Local preference value\n")
5024 int idx_localpref
= 3;
5026 "./match-condition[condition='frr-bgp-route-map:match-local-preference']";
5027 char xpath_value
[XPATH_MAXLEN
];
5029 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5031 if (argc
<= idx_localpref
)
5032 return nb_cli_apply_changes(vty
, NULL
);
5034 snprintf(xpath_value
, sizeof(xpath_value
),
5035 "%s/rmap-match-condition/frr-bgp-route-map:local-preference",
5037 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_DESTROY
,
5038 argv
[idx_localpref
]->arg
);
5040 return nb_cli_apply_changes(vty
, NULL
);
5043 DEFUN_YANG(match_alias
, match_alias_cmd
, "match alias ALIAS_NAME",
5045 "Match BGP community alias name\n"
5046 "BGP community alias name\n")
5048 const char *alias
= argv
[2]->arg
;
5049 struct community_alias ca1
;
5050 struct community_alias
*lookup_alias
;
5053 "./match-condition[condition='frr-bgp-route-map:match-alias']";
5054 char xpath_value
[XPATH_MAXLEN
];
5056 memset(&ca1
, 0, sizeof(ca1
));
5057 strlcpy(ca1
.alias
, alias
, sizeof(ca1
.alias
));
5058 lookup_alias
= bgp_ca_alias_lookup(&ca1
);
5059 if (!lookup_alias
) {
5060 vty_out(vty
, "%% BGP alias name '%s' does not exist\n", alias
);
5061 return CMD_WARNING_CONFIG_FAILED
;
5064 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5065 snprintf(xpath_value
, sizeof(xpath_value
),
5066 "%s/rmap-match-condition/frr-bgp-route-map:alias", xpath
);
5067 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, alias
);
5069 return nb_cli_apply_changes(vty
, NULL
);
5073 DEFUN_YANG(no_match_alias
, no_match_alias_cmd
, "no match alias [ALIAS_NAME]",
5075 "Match BGP community alias name\n"
5076 "BGP community alias name\n")
5080 "./match-condition[condition='frr-bgp-route-map:match-alias']";
5081 char xpath_value
[XPATH_MAXLEN
];
5083 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5085 if (argc
<= idx_alias
)
5086 return nb_cli_apply_changes(vty
, NULL
);
5088 snprintf(xpath_value
, sizeof(xpath_value
),
5089 "%s/rmap-match-condition/frr-bgp-route-map:alias", xpath
);
5090 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_DESTROY
,
5091 argv
[idx_alias
]->arg
);
5093 return nb_cli_apply_changes(vty
, NULL
);
5096 DEFPY_YANG (match_community
,
5097 match_community_cmd
,
5098 "match community <(1-99)|(100-500)|COMMUNITY_LIST_NAME> [exact-match]",
5100 "Match BGP community list\n"
5101 "Community-list number (standard)\n"
5102 "Community-list number (expanded)\n"
5103 "Community-list name\n"
5104 "Do exact matching of communities\n")
5107 "./match-condition[condition='frr-bgp-route-map:match-community']";
5108 char xpath_value
[XPATH_MAXLEN
];
5109 char xpath_match
[XPATH_MAXLEN
];
5110 int idx_comm_list
= 2;
5112 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5115 xpath_value
, sizeof(xpath_value
),
5116 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name",
5118 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[idx_comm_list
]->arg
);
5122 xpath_match
, sizeof(xpath_match
),
5123 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match",
5125 nb_cli_enqueue_change(vty
, xpath_match
, NB_OP_MODIFY
,
5129 xpath_match
, sizeof(xpath_match
),
5130 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match",
5132 nb_cli_enqueue_change(vty
, xpath_match
, NB_OP_MODIFY
,
5136 return nb_cli_apply_changes(vty
, NULL
);
5139 DEFUN_YANG (no_match_community
,
5140 no_match_community_cmd
,
5141 "no match community [<(1-99)|(100-500)|COMMUNITY_LIST_NAME> [exact-match]]",
5144 "Match BGP community list\n"
5145 "Community-list number (standard)\n"
5146 "Community-list number (expanded)\n"
5147 "Community-list name\n"
5148 "Do exact matching of communities\n")
5151 "./match-condition[condition='frr-bgp-route-map:match-community']";
5153 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5154 return nb_cli_apply_changes(vty
, NULL
);
5157 DEFPY_YANG (match_lcommunity
,
5158 match_lcommunity_cmd
,
5159 "match large-community <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME> [exact-match]",
5161 "Match BGP large community list\n"
5162 "Large Community-list number (standard)\n"
5163 "Large Community-list number (expanded)\n"
5164 "Large Community-list name\n"
5165 "Do exact matching of communities\n")
5168 "./match-condition[condition='frr-bgp-route-map:match-large-community']";
5169 char xpath_value
[XPATH_MAXLEN
];
5170 char xpath_match
[XPATH_MAXLEN
];
5171 int idx_lcomm_list
= 2;
5173 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5176 xpath_value
, sizeof(xpath_value
),
5177 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name",
5179 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[idx_lcomm_list
]->arg
);
5183 xpath_match
, sizeof(xpath_match
),
5184 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match",
5186 nb_cli_enqueue_change(vty
, xpath_match
, NB_OP_MODIFY
,
5190 xpath_match
, sizeof(xpath_match
),
5191 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match",
5193 nb_cli_enqueue_change(vty
, xpath_match
, NB_OP_MODIFY
,
5197 return nb_cli_apply_changes(vty
, NULL
);
5200 DEFUN_YANG (no_match_lcommunity
,
5201 no_match_lcommunity_cmd
,
5202 "no match large-community [<(1-99)|(100-500)|LCOMMUNITY_LIST_NAME> [exact-match]]",
5205 "Match BGP large community list\n"
5206 "Large Community-list number (standard)\n"
5207 "Large Community-list number (expanded)\n"
5208 "Large Community-list name\n"
5209 "Do exact matching of communities\n")
5212 "./match-condition[condition='frr-bgp-route-map:match-large-community']";
5214 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5215 return nb_cli_apply_changes(vty
, NULL
);
5218 DEFPY_YANG (match_ecommunity
,
5219 match_ecommunity_cmd
,
5220 "match extcommunity <(1-99)|(100-500)|EXTCOMMUNITY_LIST_NAME>",
5222 "Match BGP/VPN extended community list\n"
5223 "Extended community-list number (standard)\n"
5224 "Extended community-list number (expanded)\n"
5225 "Extended community-list name\n")
5228 "./match-condition[condition='frr-bgp-route-map:match-extcommunity']";
5229 char xpath_value
[XPATH_MAXLEN
];
5230 int idx_comm_list
= 2;
5232 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5235 xpath_value
, sizeof(xpath_value
),
5236 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name",
5238 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[idx_comm_list
]->arg
);
5240 return nb_cli_apply_changes(vty
, NULL
);
5244 DEFUN_YANG (no_match_ecommunity
,
5245 no_match_ecommunity_cmd
,
5246 "no match extcommunity [<(1-99)|(100-500)|EXTCOMMUNITY_LIST_NAME>]",
5249 "Match BGP/VPN extended community list\n"
5250 "Extended community-list number (standard)\n"
5251 "Extended community-list number (expanded)\n"
5252 "Extended community-list name\n")
5255 "./match-condition[condition='frr-bgp-route-map:match-extcommunity']";
5257 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5258 return nb_cli_apply_changes(vty
, NULL
);
5262 DEFUN_YANG (match_aspath
,
5264 "match as-path AS_PATH_FILTER_NAME",
5266 "Match BGP AS path list\n"
5267 "AS path access-list name\n")
5272 "./match-condition[condition='frr-bgp-route-map:as-path-list']";
5273 char xpath_value
[XPATH_MAXLEN
];
5275 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5276 snprintf(xpath_value
, sizeof(xpath_value
),
5277 "%s/rmap-match-condition/frr-bgp-route-map:list-name", xpath
);
5278 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5279 argv
[idx_word
]->arg
);
5281 return nb_cli_apply_changes(vty
, NULL
);
5285 DEFUN_YANG (no_match_aspath
,
5286 no_match_aspath_cmd
,
5287 "no match as-path [AS_PATH_FILTER_NAME]",
5290 "Match BGP AS path list\n"
5291 "AS path access-list name\n")
5294 "./match-condition[condition='frr-bgp-route-map:as-path-list']";
5296 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5298 return nb_cli_apply_changes(vty
, NULL
);
5301 DEFUN_YANG (match_origin
,
5303 "match origin <egp|igp|incomplete>",
5308 "unknown heritage\n")
5311 const char *origin_type
;
5313 "./match-condition[condition='frr-bgp-route-map:match-origin']";
5314 char xpath_value
[XPATH_MAXLEN
];
5316 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
5317 origin_type
= "igp";
5318 else if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
5319 origin_type
= "egp";
5320 else if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
5321 origin_type
= "incomplete";
5323 vty_out(vty
, "%% Invalid match origin type\n");
5324 return CMD_WARNING_CONFIG_FAILED
;
5327 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5328 snprintf(xpath_value
, sizeof(xpath_value
),
5329 "%s/rmap-match-condition/frr-bgp-route-map:origin", xpath
);
5330 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, origin_type
);
5332 return nb_cli_apply_changes(vty
, NULL
);
5336 DEFUN_YANG (no_match_origin
,
5337 no_match_origin_cmd
,
5338 "no match origin [<egp|igp|incomplete>]",
5344 "unknown heritage\n")
5347 "./match-condition[condition='frr-bgp-route-map:match-origin']";
5348 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5349 return nb_cli_apply_changes(vty
, NULL
);
5352 DEFUN_YANG (set_table_id
,
5354 "set table (1-4294967295)",
5356 "export route to non-main kernel table\n"
5357 "Kernel routing table id\n")
5360 const char *xpath
= "./set-action[action='frr-bgp-route-map:table']";
5361 char xpath_value
[XPATH_MAXLEN
];
5363 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5364 snprintf(xpath_value
, sizeof(xpath_value
),
5365 "%s/rmap-set-action/frr-bgp-route-map:table", xpath
);
5366 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5367 argv
[idx_number
]->arg
);
5368 return nb_cli_apply_changes(vty
, NULL
);
5371 DEFUN_YANG (no_set_table_id
,
5372 no_set_table_id_cmd
,
5376 "export route to non-main kernel table\n")
5378 const char *xpath
= "./set-action[action='frr-bgp-route-map:table']";
5379 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5380 return nb_cli_apply_changes(vty
, NULL
);
5383 DEFUN_YANG (set_ip_nexthop_peer
,
5384 set_ip_nexthop_peer_cmd
,
5385 "[no] set ip next-hop peer-address",
5389 "Next hop address\n"
5390 "Use peer address (for BGP only)\n")
5392 char xpath_value
[XPATH_MAXLEN
];
5394 "./set-action[action='frr-bgp-route-map:set-ipv4-nexthop']";
5396 if (strmatch(argv
[0]->text
, "no"))
5397 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5399 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5400 snprintf(xpath_value
, sizeof(xpath_value
),
5401 "%s/rmap-set-action/frr-bgp-route-map:ipv4-nexthop",
5403 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5406 return nb_cli_apply_changes(vty
, NULL
);
5409 DEFUN_YANG (set_ip_nexthop_unchanged
,
5410 set_ip_nexthop_unchanged_cmd
,
5411 "[no] set ip next-hop unchanged",
5415 "Next hop address\n"
5416 "Don't modify existing Next hop address\n")
5418 char xpath_value
[XPATH_MAXLEN
];
5420 "./set-action[action='frr-bgp-route-map:set-ipv4-nexthop']";
5422 if (strmatch(argv
[0]->text
, "no"))
5423 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5425 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5426 snprintf(xpath_value
, sizeof(xpath_value
),
5427 "%s/rmap-set-action/frr-bgp-route-map:ipv4-nexthop",
5429 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5432 return nb_cli_apply_changes(vty
, NULL
);
5435 DEFUN_YANG (set_distance
,
5437 "set distance (0-255)",
5439 "BGP Administrative Distance to use\n"
5443 const char *xpath
= "./set-action[action='frr-bgp-route-map:distance']";
5444 char xpath_value
[XPATH_MAXLEN
];
5446 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5447 snprintf(xpath_value
, sizeof(xpath_value
),
5448 "%s/rmap-set-action/frr-bgp-route-map:distance", xpath
);
5449 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5450 argv
[idx_number
]->arg
);
5451 return nb_cli_apply_changes(vty
, NULL
);
5454 DEFUN_YANG (no_set_distance
,
5455 no_set_distance_cmd
,
5456 "no set distance [(0-255)]",
5458 "BGP Administrative Distance to use\n"
5461 const char *xpath
= "./set-action[action='frr-bgp-route-map:distance']";
5463 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5464 return nb_cli_apply_changes(vty
, NULL
);
5467 DEFPY_YANG(set_l3vpn_nexthop_encapsulation
, set_l3vpn_nexthop_encapsulation_cmd
,
5468 "[no] set l3vpn next-hop encapsulation gre",
5470 "L3VPN operations\n"
5471 "Next hop Information\n"
5472 "Encapsulation options (for BGP only)\n"
5473 "Accept L3VPN traffic over GRE encapsulation\n")
5476 "./set-action[action='frr-bgp-route-map:set-l3vpn-nexthop-encapsulation']";
5477 const char *xpath_value
=
5478 "./set-action[action='frr-bgp-route-map:set-l3vpn-nexthop-encapsulation']/rmap-set-action/frr-bgp-route-map:l3vpn-nexthop-encapsulation";
5479 enum nb_operation operation
;
5482 operation
= NB_OP_DESTROY
;
5484 operation
= NB_OP_CREATE
;
5486 nb_cli_enqueue_change(vty
, xpath
, operation
, NULL
);
5487 if (operation
== NB_OP_DESTROY
)
5488 return nb_cli_apply_changes(vty
, NULL
);
5490 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "gre");
5492 return nb_cli_apply_changes(vty
, NULL
);
5495 DEFUN_YANG (set_local_pref
,
5497 "set local-preference WORD",
5499 "BGP local preference path attribute\n"
5500 "Preference value (0-4294967295)\n")
5504 "./set-action[action='frr-bgp-route-map:set-local-preference']";
5505 char xpath_value
[XPATH_MAXLEN
];
5507 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5508 snprintf(xpath_value
, sizeof(xpath_value
),
5509 "%s/rmap-set-action/frr-bgp-route-map:local-pref", xpath
);
5510 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5511 argv
[idx_number
]->arg
);
5512 return nb_cli_apply_changes(vty
, NULL
);
5515 DEFUN_YANG (no_set_local_pref
,
5516 no_set_local_pref_cmd
,
5517 "no set local-preference [WORD]",
5520 "BGP local preference path attribute\n"
5521 "Preference value (0-4294967295)\n")
5524 "./set-action[action='frr-bgp-route-map:set-local-preference']";
5526 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5527 return nb_cli_apply_changes(vty
, NULL
);
5530 DEFUN_YANG (set_weight
,
5532 "set weight (0-4294967295)",
5534 "BGP weight for routing table\n"
5538 const char *xpath
= "./set-action[action='frr-bgp-route-map:weight']";
5539 char xpath_value
[XPATH_MAXLEN
];
5541 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5542 snprintf(xpath_value
, sizeof(xpath_value
),
5543 "%s/rmap-set-action/frr-bgp-route-map:weight", xpath
);
5544 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5545 argv
[idx_number
]->arg
);
5546 return nb_cli_apply_changes(vty
, NULL
);
5549 DEFUN_YANG (no_set_weight
,
5551 "no set weight [(0-4294967295)]",
5554 "BGP weight for routing table\n"
5557 const char *xpath
= "./set-action[action='frr-bgp-route-map:weight']";
5559 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5560 return nb_cli_apply_changes(vty
, NULL
);
5563 DEFUN_YANG (set_label_index
,
5564 set_label_index_cmd
,
5565 "set label-index (0-1048560)",
5567 "Label index to associate with the prefix\n"
5568 "Label index value\n")
5572 "./set-action[action='frr-bgp-route-map:label-index']";
5573 char xpath_value
[XPATH_MAXLEN
];
5575 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5576 snprintf(xpath_value
, sizeof(xpath_value
),
5577 "%s/rmap-set-action/frr-bgp-route-map:label-index", xpath
);
5578 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5579 argv
[idx_number
]->arg
);
5580 return nb_cli_apply_changes(vty
, NULL
);
5583 DEFUN_YANG (no_set_label_index
,
5584 no_set_label_index_cmd
,
5585 "no set label-index [(0-1048560)]",
5588 "Label index to associate with the prefix\n"
5589 "Label index value\n")
5592 "./set-action[action='frr-bgp-route-map:label-index']";
5594 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5595 return nb_cli_apply_changes(vty
, NULL
);
5598 DEFUN_YANG (set_aspath_prepend_asn
,
5599 set_aspath_prepend_asn_cmd
,
5600 "set as-path prepend (1-4294967295)...",
5602 "Transform BGP AS_PATH attribute\n"
5603 "Prepend to the as-path\n"
5610 str
= argv_concat(argv
, argc
, idx_asn
);
5613 "./set-action[action='frr-bgp-route-map:as-path-prepend']";
5614 char xpath_value
[XPATH_MAXLEN
];
5616 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5617 snprintf(xpath_value
, sizeof(xpath_value
),
5618 "%s/rmap-set-action/frr-bgp-route-map:prepend-as-path", xpath
);
5619 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
5620 ret
= nb_cli_apply_changes(vty
, NULL
);
5621 XFREE(MTYPE_TMP
, str
);
5625 DEFUN_YANG (set_aspath_prepend_lastas
,
5626 set_aspath_prepend_lastas_cmd
,
5627 "set as-path prepend last-as (1-10)",
5629 "Transform BGP AS_PATH attribute\n"
5630 "Prepend to the as-path\n"
5631 "Use the last AS-number in the as-path\n"
5632 "Number of times to insert\n")
5637 "./set-action[action='frr-bgp-route-map:as-path-prepend']";
5638 char xpath_value
[XPATH_MAXLEN
];
5640 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5641 snprintf(xpath_value
, sizeof(xpath_value
),
5642 "%s/rmap-set-action/frr-bgp-route-map:last-as", xpath
);
5643 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5644 argv
[idx_num
]->arg
);
5645 return nb_cli_apply_changes(vty
, NULL
);
5648 DEFPY_YANG (set_aspath_replace_asn
,
5649 set_aspath_replace_asn_cmd
,
5650 "set as-path replace <any|(1-4294967295)>$replace",
5652 "Transform BGP AS_PATH attribute\n"
5653 "Replace AS number to local AS number\n"
5654 "Replace any AS number to local AS number\n"
5655 "Replace a specific AS number to local AS number\n")
5658 "./set-action[action='frr-bgp-route-map:as-path-replace']";
5659 char xpath_value
[XPATH_MAXLEN
];
5661 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5662 snprintf(xpath_value
, sizeof(xpath_value
),
5663 "%s/rmap-set-action/frr-bgp-route-map:replace-as-path", xpath
);
5664 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, replace
);
5665 return nb_cli_apply_changes(vty
, NULL
);
5668 DEFPY_YANG (no_set_aspath_replace_asn
,
5669 no_set_aspath_replace_asn_cmd
,
5670 "no set as-path replace [<any|(1-4294967295)>]",
5673 "Transform BGP AS_PATH attribute\n"
5674 "Replace AS number to local AS number\n"
5675 "Replace any AS number to local AS number\n"
5676 "Replace a specific AS number to local AS number\n")
5679 "./set-action[action='frr-bgp-route-map:as-path-replace']";
5681 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5682 return nb_cli_apply_changes(vty
, NULL
);
5685 DEFUN_YANG (no_set_aspath_prepend
,
5686 no_set_aspath_prepend_cmd
,
5687 "no set as-path prepend [(1-4294967295)]",
5690 "Transform BGP AS_PATH attribute\n"
5691 "Prepend to the as-path\n"
5695 "./set-action[action='frr-bgp-route-map:as-path-prepend']";
5697 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5698 return nb_cli_apply_changes(vty
, NULL
);
5701 DEFUN_YANG (no_set_aspath_prepend_lastas
,
5702 no_set_aspath_prepend_lastas_cmd
,
5703 "no set as-path prepend last-as [(1-10)]",
5706 "Transform BGP AS_PATH attribute\n"
5707 "Prepend to the as-path\n"
5708 "Use the peers AS-number\n"
5709 "Number of times to insert\n")
5712 "./set-action[action='frr-bgp-route-map:as-path-prepend']";
5714 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5715 return nb_cli_apply_changes(vty
, NULL
);
5718 DEFUN_YANG (set_aspath_exclude
,
5719 set_aspath_exclude_cmd
,
5720 "set as-path exclude (1-4294967295)...",
5722 "Transform BGP AS-path attribute\n"
5723 "Exclude from the as-path\n"
5730 str
= argv_concat(argv
, argc
, idx_asn
);
5733 "./set-action[action='frr-bgp-route-map:as-path-exclude']";
5734 char xpath_value
[XPATH_MAXLEN
];
5736 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5737 snprintf(xpath_value
, sizeof(xpath_value
),
5738 "%s/rmap-set-action/frr-bgp-route-map:exclude-as-path", xpath
);
5739 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
5740 ret
= nb_cli_apply_changes(vty
, NULL
);
5741 XFREE(MTYPE_TMP
, str
);
5745 DEFUN_YANG (no_set_aspath_exclude
,
5746 no_set_aspath_exclude_cmd
,
5747 "no set as-path exclude (1-4294967295)...",
5750 "Transform BGP AS_PATH attribute\n"
5751 "Exclude from the as-path\n"
5755 "./set-action[action='frr-bgp-route-map:as-path-exclude']";
5757 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5758 return nb_cli_apply_changes(vty
, NULL
);
5761 ALIAS_YANG (no_set_aspath_exclude
, no_set_aspath_exclude_all_cmd
,
5762 "no set as-path exclude",
5764 "Transform BGP AS_PATH attribute\n"
5765 "Exclude from the as-path\n")
5767 DEFUN_YANG (set_community
,
5769 "set community AA:NN...",
5771 "BGP community attribute\n"
5779 struct community
*com
= NULL
;
5781 char *argstr
= NULL
;
5785 "./set-action[action='frr-bgp-route-map:set-community']";
5786 char xpath_value
[XPATH_MAXLEN
];
5788 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5789 snprintf(xpath_value
, sizeof(xpath_value
),
5790 "%s/rmap-set-action/frr-bgp-route-map:community-string",
5793 b
= buffer_new(1024);
5795 for (i
= idx_aa_nn
; i
< argc
; i
++) {
5796 if (strncmp(argv
[i
]->arg
, "additive", strlen(argv
[i
]->arg
))
5803 buffer_putc(b
, ' ');
5807 if (strncmp(argv
[i
]->arg
, "internet", strlen(argv
[i
]->arg
))
5809 buffer_putstr(b
, "internet");
5812 if (strncmp(argv
[i
]->arg
, "local-AS", strlen(argv
[i
]->arg
))
5814 buffer_putstr(b
, "local-AS");
5817 if (strncmp(argv
[i
]->arg
, "no-a", strlen("no-a")) == 0
5818 && strncmp(argv
[i
]->arg
, "no-advertise",
5819 strlen(argv
[i
]->arg
))
5821 buffer_putstr(b
, "no-advertise");
5824 if (strncmp(argv
[i
]->arg
, "no-e", strlen("no-e")) == 0
5825 && strncmp(argv
[i
]->arg
, "no-export", strlen(argv
[i
]->arg
))
5827 buffer_putstr(b
, "no-export");
5830 if (strncmp(argv
[i
]->arg
, "blackhole", strlen(argv
[i
]->arg
))
5832 buffer_putstr(b
, "blackhole");
5835 if (strncmp(argv
[i
]->arg
, "graceful-shutdown",
5836 strlen(argv
[i
]->arg
))
5838 buffer_putstr(b
, "graceful-shutdown");
5841 buffer_putstr(b
, argv
[i
]->arg
);
5843 buffer_putc(b
, '\0');
5845 /* Fetch result string then compile it to communities attribute. */
5846 str
= buffer_getstr(b
);
5850 com
= community_str2com(str
);
5852 /* Can't compile user input into communities attribute. */
5854 vty_out(vty
, "%% Malformed communities attribute '%s'\n", str
);
5855 XFREE(MTYPE_TMP
, str
);
5856 return CMD_WARNING_CONFIG_FAILED
;
5858 XFREE(MTYPE_TMP
, str
);
5860 /* Set communites attribute string. */
5861 str
= community_str(com
, false, false);
5864 size_t argstr_sz
= strlen(str
) + strlen(" additive") + 1;
5865 argstr
= XCALLOC(MTYPE_TMP
, argstr_sz
);
5866 strlcpy(argstr
, str
, argstr_sz
);
5867 strlcat(argstr
, " additive", argstr_sz
);
5868 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argstr
);
5870 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
5872 ret
= nb_cli_apply_changes(vty
, NULL
);
5875 XFREE(MTYPE_TMP
, argstr
);
5876 community_free(&com
);
5881 DEFUN_YANG (set_community_none
,
5882 set_community_none_cmd
,
5883 "set community none",
5885 "BGP community attribute\n"
5886 "No community attribute\n")
5889 "./set-action[action='frr-bgp-route-map:set-community']";
5890 char xpath_value
[XPATH_MAXLEN
];
5892 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5894 snprintf(xpath_value
, sizeof(xpath_value
),
5895 "%s/rmap-set-action/frr-bgp-route-map:community-none", xpath
);
5896 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
5897 return nb_cli_apply_changes(vty
, NULL
);
5900 DEFUN_YANG (no_set_community
,
5901 no_set_community_cmd
,
5902 "no set community AA:NN...",
5905 "BGP community attribute\n"
5909 "./set-action[action='frr-bgp-route-map:set-community']";
5911 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5912 return nb_cli_apply_changes(vty
, NULL
);
5915 ALIAS_YANG (no_set_community
,
5916 no_set_community_short_cmd
,
5920 "BGP community attribute\n")
5922 DEFPY_YANG (set_community_delete
,
5923 set_community_delete_cmd
,
5924 "set comm-list <(1-99)|(100-500)|COMMUNITY_LIST_NAME> delete",
5926 "set BGP community list (for deletion)\n"
5927 "Community-list number (standard)\n"
5928 "Community-list number (expanded)\n"
5929 "Community-list name\n"
5930 "Delete matching communities\n")
5933 "./set-action[action='frr-bgp-route-map:comm-list-delete']";
5934 char xpath_value
[XPATH_MAXLEN
];
5935 int idx_comm_list
= 2;
5937 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5939 snprintf(xpath_value
, sizeof(xpath_value
),
5940 "%s/rmap-set-action/frr-bgp-route-map:comm-list-name",
5942 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5943 argv
[idx_comm_list
]->arg
);
5945 return nb_cli_apply_changes(vty
, NULL
);
5949 DEFUN_YANG (no_set_community_delete
,
5950 no_set_community_delete_cmd
,
5951 "no set comm-list [<(1-99)|(100-500)|COMMUNITY_LIST_NAME> delete]",
5954 "set BGP community list (for deletion)\n"
5955 "Community-list number (standard)\n"
5956 "Community-list number (expanded)\n"
5957 "Community-list name\n"
5958 "Delete matching communities\n")
5961 "./set-action[action='frr-bgp-route-map:comm-list-delete']";
5963 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5964 return nb_cli_apply_changes(vty
, NULL
);
5967 DEFUN_YANG (set_lcommunity
,
5969 "set large-community AA:BB:CC...",
5971 "BGP large community attribute\n"
5972 "Large Community number in aa:bb:cc format or additive\n")
5977 "./set-action[action='frr-bgp-route-map:set-large-community']";
5978 char xpath_value
[XPATH_MAXLEN
];
5980 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5982 snprintf(xpath_value
, sizeof(xpath_value
),
5983 "%s/rmap-set-action/frr-bgp-route-map:large-community-string",
5985 str
= argv_concat(argv
, argc
, 2);
5986 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
5987 ret
= nb_cli_apply_changes(vty
, NULL
);
5988 XFREE(MTYPE_TMP
, str
);
5992 DEFUN_YANG (set_lcommunity_none
,
5993 set_lcommunity_none_cmd
,
5994 "set large-community none",
5996 "BGP large community attribute\n"
5997 "No large community attribute\n")
6000 "./set-action[action='frr-bgp-route-map:set-large-community']";
6001 char xpath_value
[XPATH_MAXLEN
];
6003 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6005 snprintf(xpath_value
, sizeof(xpath_value
),
6006 "%s/rmap-set-action/frr-bgp-route-map:large-community-none",
6008 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
6009 return nb_cli_apply_changes(vty
, NULL
);
6012 DEFUN_YANG (no_set_lcommunity
,
6013 no_set_lcommunity_cmd
,
6014 "no set large-community none",
6017 "BGP large community attribute\n"
6018 "No community attribute\n")
6021 "./set-action[action='frr-bgp-route-map:set-large-community']";
6023 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6024 return nb_cli_apply_changes(vty
, NULL
);
6027 DEFUN_YANG (no_set_lcommunity1
,
6028 no_set_lcommunity1_cmd
,
6029 "no set large-community AA:BB:CC...",
6032 "BGP large community attribute\n"
6033 "Large community in AA:BB:CC... format or additive\n")
6036 "./set-action[action='frr-bgp-route-map:set-large-community']";
6038 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6039 return nb_cli_apply_changes(vty
, NULL
);
6042 ALIAS_YANG (no_set_lcommunity1
,
6043 no_set_lcommunity1_short_cmd
,
6044 "no set large-community",
6047 "BGP large community attribute\n")
6049 DEFPY_YANG (set_lcommunity_delete
,
6050 set_lcommunity_delete_cmd
,
6051 "set large-comm-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME> delete",
6053 "set BGP large community list (for deletion)\n"
6054 "Large Community-list number (standard)\n"
6055 "Large Communitly-list number (expanded)\n"
6056 "Large Community-list name\n"
6057 "Delete matching large communities\n")
6060 "./set-action[action='frr-bgp-route-map:large-comm-list-delete']";
6061 char xpath_value
[XPATH_MAXLEN
];
6062 int idx_lcomm_list
= 2;
6064 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6066 snprintf(xpath_value
, sizeof(xpath_value
),
6067 "%s/rmap-set-action/frr-bgp-route-map:comm-list-name",
6069 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6070 argv
[idx_lcomm_list
]->arg
);
6072 return nb_cli_apply_changes(vty
, NULL
);
6075 DEFUN_YANG (no_set_lcommunity_delete
,
6076 no_set_lcommunity_delete_cmd
,
6077 "no set large-comm-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME> [delete]",
6080 "set BGP large community list (for deletion)\n"
6081 "Large Community-list number (standard)\n"
6082 "Large Communitly-list number (expanded)\n"
6083 "Large Community-list name\n"
6084 "Delete matching large communities\n")
6087 "./set-action[action='frr-bgp-route-map:large-comm-list-delete']";
6089 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6090 return nb_cli_apply_changes(vty
, NULL
);
6093 ALIAS_YANG (no_set_lcommunity_delete
,
6094 no_set_lcommunity_delete_short_cmd
,
6095 "no set large-comm-list",
6098 "set BGP large community list (for deletion)\n")
6100 DEFUN_YANG (set_ecommunity_rt
,
6101 set_ecommunity_rt_cmd
,
6102 "set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
6104 "BGP extended community attribute\n"
6105 "Route Target extended community\n"
6106 "VPN extended community\n")
6112 "./set-action[action='frr-bgp-route-map:set-extcommunity-rt']";
6113 char xpath_value
[XPATH_MAXLEN
];
6115 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6117 snprintf(xpath_value
, sizeof(xpath_value
),
6118 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-rt", xpath
);
6119 str
= argv_concat(argv
, argc
, idx_asn_nn
);
6120 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
6121 ret
= nb_cli_apply_changes(vty
, NULL
);
6122 XFREE(MTYPE_TMP
, str
);
6126 DEFUN_YANG (no_set_ecommunity_rt
,
6127 no_set_ecommunity_rt_cmd
,
6128 "no set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
6131 "BGP extended community attribute\n"
6132 "Route Target extended community\n"
6133 "VPN extended community\n")
6136 "./set-action[action='frr-bgp-route-map:set-extcommunity-rt']";
6137 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6138 return nb_cli_apply_changes(vty
, NULL
);
6141 ALIAS_YANG (no_set_ecommunity_rt
,
6142 no_set_ecommunity_rt_short_cmd
,
6143 "no set extcommunity rt",
6146 "BGP extended community attribute\n"
6147 "Route Target extended community\n")
6149 DEFUN_YANG (set_ecommunity_soo
,
6150 set_ecommunity_soo_cmd
,
6151 "set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
6153 "BGP extended community attribute\n"
6154 "Site-of-Origin extended community\n"
6155 "VPN extended community\n")
6161 "./set-action[action='frr-bgp-route-map:set-extcommunity-soo']";
6162 char xpath_value
[XPATH_MAXLEN
];
6164 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6166 snprintf(xpath_value
, sizeof(xpath_value
),
6167 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-soo",
6169 str
= argv_concat(argv
, argc
, idx_asn_nn
);
6170 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
6171 ret
= nb_cli_apply_changes(vty
, NULL
);
6172 XFREE(MTYPE_TMP
, str
);
6176 DEFUN_YANG (no_set_ecommunity_soo
,
6177 no_set_ecommunity_soo_cmd
,
6178 "no set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
6181 "BGP extended community attribute\n"
6182 "Site-of-Origin extended community\n"
6183 "VPN extended community\n")
6186 "./set-action[action='frr-bgp-route-map:set-extcommunity-soo']";
6187 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6188 return nb_cli_apply_changes(vty
, NULL
);
6191 ALIAS_YANG (no_set_ecommunity_soo
,
6192 no_set_ecommunity_soo_short_cmd
,
6193 "no set extcommunity soo",
6196 "GP extended community attribute\n"
6197 "Site-of-Origin extended community\n")
6199 DEFUN_YANG(set_ecommunity_none
, set_ecommunity_none_cmd
,
6200 "set extcommunity none",
6202 "BGP extended community attribute\n"
6203 "No extended community attribute\n")
6206 "./set-action[action='frr-bgp-route-map:set-extcommunity-none']";
6207 char xpath_value
[XPATH_MAXLEN
];
6209 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6211 snprintf(xpath_value
, sizeof(xpath_value
),
6212 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-none",
6214 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
6215 return nb_cli_apply_changes(vty
, NULL
);
6218 DEFUN_YANG(no_set_ecommunity_none
, no_set_ecommunity_none_cmd
,
6219 "no set extcommunity none",
6221 "BGP extended community attribute\n"
6222 "No extended community attribute\n")
6225 "./set-action[action='frr-bgp-route-map:set-extcommunity-none']";
6226 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6227 return nb_cli_apply_changes(vty
, NULL
);
6230 DEFUN_YANG (set_ecommunity_lb
,
6231 set_ecommunity_lb_cmd
,
6232 "set extcommunity bandwidth <(1-25600)|cumulative|num-multipaths> [non-transitive]",
6234 "BGP extended community attribute\n"
6235 "Link bandwidth extended community\n"
6236 "Bandwidth value in Mbps\n"
6237 "Cumulative bandwidth of all multipaths (outbound-only)\n"
6238 "Internally computed bandwidth based on number of multipaths (outbound-only)\n"
6239 "Attribute is set as non-transitive\n")
6242 int idx_non_transitive
= 0;
6244 "./set-action[action='frr-bgp-route-map:set-extcommunity-lb']";
6245 char xpath_lb_type
[XPATH_MAXLEN
];
6246 char xpath_bandwidth
[XPATH_MAXLEN
];
6247 char xpath_non_transitive
[XPATH_MAXLEN
];
6249 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6251 snprintf(xpath_lb_type
, sizeof(xpath_lb_type
),
6252 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-lb/lb-type",
6254 snprintf(xpath_bandwidth
, sizeof(xpath_bandwidth
),
6255 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-lb/bandwidth",
6257 snprintf(xpath_non_transitive
, sizeof(xpath_non_transitive
),
6258 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-lb/two-octet-as-specific",
6261 if ((strcmp(argv
[idx_lb
]->arg
, "cumulative")) == 0)
6262 nb_cli_enqueue_change(vty
, xpath_lb_type
, NB_OP_MODIFY
,
6263 "cumulative-bandwidth");
6264 else if ((strcmp(argv
[idx_lb
]->arg
, "num-multipaths")) == 0)
6265 nb_cli_enqueue_change(vty
, xpath_lb_type
, NB_OP_MODIFY
,
6266 "computed-bandwidth");
6268 nb_cli_enqueue_change(vty
, xpath_lb_type
, NB_OP_MODIFY
,
6269 "explicit-bandwidth");
6270 nb_cli_enqueue_change(vty
, xpath_bandwidth
, NB_OP_MODIFY
,
6274 if (argv_find(argv
, argc
, "non-transitive", &idx_non_transitive
))
6275 nb_cli_enqueue_change(vty
, xpath_non_transitive
, NB_OP_MODIFY
,
6278 nb_cli_enqueue_change(vty
, xpath_non_transitive
, NB_OP_MODIFY
,
6281 return nb_cli_apply_changes(vty
, NULL
);
6284 DEFUN_YANG (no_set_ecommunity_lb
,
6285 no_set_ecommunity_lb_cmd
,
6286 "no set extcommunity bandwidth <(1-25600)|cumulative|num-multipaths> [non-transitive]",
6289 "BGP extended community attribute\n"
6290 "Link bandwidth extended community\n"
6291 "Bandwidth value in Mbps\n"
6292 "Cumulative bandwidth of all multipaths (outbound-only)\n"
6293 "Internally computed bandwidth based on number of multipaths (outbound-only)\n"
6294 "Attribute is set as non-transitive\n")
6297 "./set-action[action='frr-bgp-route-map:set-extcommunity-lb']";
6299 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6300 return nb_cli_apply_changes(vty
, NULL
);
6303 ALIAS_YANG (no_set_ecommunity_lb
,
6304 no_set_ecommunity_lb_short_cmd
,
6305 "no set extcommunity bandwidth",
6308 "BGP extended community attribute\n"
6309 "Link bandwidth extended community\n")
6311 DEFUN_YANG (set_origin
,
6313 "set origin <egp|igp|incomplete>",
6318 "unknown heritage\n")
6321 const char *origin_type
;
6323 "./set-action[action='frr-bgp-route-map:set-origin']";
6324 char xpath_value
[XPATH_MAXLEN
];
6326 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
6327 origin_type
= "igp";
6328 else if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
6329 origin_type
= "egp";
6330 else if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
6331 origin_type
= "incomplete";
6333 vty_out(vty
, "%% Invalid match origin type\n");
6334 return CMD_WARNING_CONFIG_FAILED
;
6337 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6338 snprintf(xpath_value
, sizeof(xpath_value
),
6339 "%s/rmap-set-action/frr-bgp-route-map:origin", xpath
);
6340 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, origin_type
);
6342 return nb_cli_apply_changes(vty
, NULL
);
6345 DEFUN_YANG (no_set_origin
,
6347 "no set origin [<egp|igp|incomplete>]",
6353 "unknown heritage\n")
6356 "./set-action[action='frr-bgp-route-map:set-origin']";
6358 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6359 return nb_cli_apply_changes(vty
, NULL
);
6362 DEFUN_YANG (set_atomic_aggregate
,
6363 set_atomic_aggregate_cmd
,
6364 "set atomic-aggregate",
6366 "BGP atomic aggregate attribute\n" )
6369 "./set-action[action='frr-bgp-route-map:atomic-aggregate']";
6370 char xpath_value
[XPATH_MAXLEN
];
6372 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6373 snprintf(xpath_value
, sizeof(xpath_value
),
6374 "%s/rmap-set-action/frr-bgp-route-map:atomic-aggregate",
6376 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, NULL
);
6378 return nb_cli_apply_changes(vty
, NULL
);
6381 DEFUN_YANG (no_set_atomic_aggregate
,
6382 no_set_atomic_aggregate_cmd
,
6383 "no set atomic-aggregate",
6386 "BGP atomic aggregate attribute\n" )
6389 "./set-action[action='frr-bgp-route-map:atomic-aggregate']";
6391 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6392 return nb_cli_apply_changes(vty
, NULL
);
6395 DEFPY_YANG (set_aigp_metric
,
6396 set_aigp_metric_cmd
,
6397 "set aigp-metric <igp-metric|(1-4294967295)>$aigp_metric",
6399 "BGP AIGP attribute (AIGP Metric TLV)\n"
6400 "AIGP Metric value from IGP protocol\n"
6401 "Manual AIGP Metric value\n")
6404 "./set-action[action='frr-bgp-route-map:aigp-metric']";
6405 char xpath_value
[XPATH_MAXLEN
];
6407 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6408 snprintf(xpath_value
, sizeof(xpath_value
),
6409 "%s/rmap-set-action/frr-bgp-route-map:aigp-metric", xpath
);
6410 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, aigp_metric
);
6412 return nb_cli_apply_changes(vty
, NULL
);
6415 DEFPY_YANG (no_set_aigp_metric
,
6416 no_set_aigp_metric_cmd
,
6417 "no set aigp-metric [<igp-metric|(1-4294967295)>]",
6420 "BGP AIGP attribute (AIGP Metric TLV)\n"
6421 "AIGP Metric value from IGP protocol\n"
6422 "Manual AIGP Metric value\n")
6425 "./set-action[action='frr-bgp-route-map:aigp-metric']";
6427 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6428 return nb_cli_apply_changes(vty
, NULL
);
6431 DEFUN_YANG (set_aggregator_as
,
6432 set_aggregator_as_cmd
,
6433 "set aggregator as (1-4294967295) A.B.C.D",
6435 "BGP aggregator attribute\n"
6436 "AS number of aggregator\n"
6438 "IP address of aggregator\n")
6442 char xpath_asn
[XPATH_MAXLEN
];
6443 char xpath_addr
[XPATH_MAXLEN
];
6445 "./set-action[action='frr-bgp-route-map:aggregator']";
6447 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6450 xpath_asn
, sizeof(xpath_asn
),
6451 "%s/rmap-set-action/frr-bgp-route-map:aggregator/aggregator-asn",
6453 nb_cli_enqueue_change(vty
, xpath_asn
, NB_OP_MODIFY
,
6454 argv
[idx_number
]->arg
);
6457 xpath_addr
, sizeof(xpath_addr
),
6458 "%s/rmap-set-action/frr-bgp-route-map:aggregator/aggregator-address",
6460 nb_cli_enqueue_change(vty
, xpath_addr
, NB_OP_MODIFY
,
6461 argv
[idx_ipv4
]->arg
);
6463 return nb_cli_apply_changes(vty
, NULL
);
6466 DEFUN_YANG (no_set_aggregator_as
,
6467 no_set_aggregator_as_cmd
,
6468 "no set aggregator as [(1-4294967295) A.B.C.D]",
6471 "BGP aggregator attribute\n"
6472 "AS number of aggregator\n"
6474 "IP address of aggregator\n")
6477 "./set-action[action='frr-bgp-route-map:aggregator']";
6479 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6480 return nb_cli_apply_changes(vty
, NULL
);
6483 DEFUN_YANG (match_ipv6_next_hop
,
6484 match_ipv6_next_hop_cmd
,
6485 "match ipv6 next-hop ACCESSLIST6_NAME",
6488 "Match IPv6 next-hop address of route\n"
6489 "IPv6 access-list name\n")
6492 "./match-condition[condition='frr-route-map:ipv6-next-hop-list']";
6493 char xpath_value
[XPATH_MAXLEN
];
6495 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6496 snprintf(xpath_value
, sizeof(xpath_value
),
6497 "%s/rmap-match-condition/list-name", xpath
);
6498 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6499 argv
[argc
- 1]->arg
);
6501 return nb_cli_apply_changes(vty
, NULL
);
6504 DEFUN_YANG (no_match_ipv6_next_hop
,
6505 no_match_ipv6_next_hop_cmd
,
6506 "no match ipv6 next-hop [ACCESSLIST6_NAME]",
6510 "Match IPv6 next-hop address of route\n"
6511 "IPv6 access-list name\n")
6514 "./match-condition[condition='frr-route-map:ipv6-next-hop-list']";
6516 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6517 return nb_cli_apply_changes(vty
, NULL
);
6520 DEFUN_YANG (match_ipv6_next_hop_address
,
6521 match_ipv6_next_hop_address_cmd
,
6522 "match ipv6 next-hop address X:X::X:X",
6525 "Match IPv6 next-hop address of route\n"
6527 "IPv6 address of next hop\n")
6530 "./match-condition[condition='frr-bgp-route-map:ipv6-nexthop']";
6531 char xpath_value
[XPATH_MAXLEN
];
6533 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6534 snprintf(xpath_value
, sizeof(xpath_value
),
6535 "%s/rmap-match-condition/frr-bgp-route-map:ipv6-address",
6537 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6538 argv
[argc
- 1]->arg
);
6540 return nb_cli_apply_changes(vty
, NULL
);
6543 DEFUN_YANG (no_match_ipv6_next_hop_address
,
6544 no_match_ipv6_next_hop_address_cmd
,
6545 "no match ipv6 next-hop address X:X::X:X",
6549 "Match IPv6 next-hop address of route\n"
6551 "IPv6 address of next hop\n")
6554 "./match-condition[condition='frr-bgp-route-map:ipv6-nexthop']";
6556 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6557 return nb_cli_apply_changes(vty
, NULL
);
6560 ALIAS_HIDDEN (match_ipv6_next_hop_address
,
6561 match_ipv6_next_hop_old_cmd
,
6562 "match ipv6 next-hop X:X::X:X",
6565 "Match IPv6 next-hop address of route\n"
6566 "IPv6 address of next hop\n")
6568 ALIAS_HIDDEN (no_match_ipv6_next_hop_address
,
6569 no_match_ipv6_next_hop_old_cmd
,
6570 "no match ipv6 next-hop X:X::X:X",
6574 "Match IPv6 next-hop address of route\n"
6575 "IPv6 address of next hop\n")
6577 DEFUN_YANG (match_ipv6_next_hop_prefix_list
,
6578 match_ipv6_next_hop_prefix_list_cmd
,
6579 "match ipv6 next-hop prefix-list PREFIXLIST_NAME",
6582 "Match IPv6 next-hop address of route\n"
6583 "Match entries by prefix-list\n"
6584 "IPv6 prefix-list name\n")
6587 "./match-condition[condition='frr-route-map:ipv6-next-hop-prefix-list']";
6588 char xpath_value
[XPATH_MAXLEN
];
6590 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6591 snprintf(xpath_value
, sizeof(xpath_value
),
6592 "%s/rmap-match-condition/list-name", xpath
);
6593 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6594 argv
[argc
- 1]->arg
);
6596 return nb_cli_apply_changes(vty
, NULL
);
6599 DEFUN_YANG (no_match_ipv6_next_hop_prefix_list
,
6600 no_match_ipv6_next_hop_prefix_list_cmd
,
6601 "no match ipv6 next-hop prefix-list [PREFIXLIST_NAME]",
6605 "Match IPv6 next-hop address of route\n"
6606 "Match entries by prefix-list\n"
6607 "IPv6 prefix-list name\n")
6610 "./match-condition[condition='frr-route-map:ipv6-next-hop-prefix-list']";
6612 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6613 return nb_cli_apply_changes(vty
, NULL
);
6616 DEFPY_YANG (match_ipv4_next_hop
,
6617 match_ipv4_next_hop_cmd
,
6618 "match ip next-hop address A.B.C.D",
6621 "Match IP next-hop address of route\n"
6623 "IP address of next-hop\n")
6626 "./match-condition[condition='frr-bgp-route-map:ipv4-nexthop']";
6627 char xpath_value
[XPATH_MAXLEN
];
6629 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6630 snprintf(xpath_value
, sizeof(xpath_value
),
6631 "%s/rmap-match-condition/frr-bgp-route-map:ipv4-address",
6633 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[4]->arg
);
6635 return nb_cli_apply_changes(vty
, NULL
);
6638 DEFPY_YANG (no_match_ipv4_next_hop
,
6639 no_match_ipv4_next_hop_cmd
,
6640 "no match ip next-hop address [A.B.C.D]",
6644 "Match IP next-hop address of route\n"
6646 "IP address of next-hop\n")
6649 "./match-condition[condition='frr-bgp-route-map:ipv4-nexthop']";
6651 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6652 return nb_cli_apply_changes(vty
, NULL
);
6655 DEFUN_YANG (set_ipv6_nexthop_peer
,
6656 set_ipv6_nexthop_peer_cmd
,
6657 "set ipv6 next-hop peer-address",
6660 "Next hop address\n"
6661 "Use peer address (for BGP only)\n")
6664 "./set-action[action='frr-bgp-route-map:ipv6-peer-address']";
6665 char xpath_value
[XPATH_MAXLEN
];
6667 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6668 snprintf(xpath_value
, sizeof(xpath_value
),
6669 "%s/rmap-set-action/frr-bgp-route-map:preference", xpath
);
6670 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
6672 return nb_cli_apply_changes(vty
, NULL
);
6675 DEFUN_YANG (no_set_ipv6_nexthop_peer
,
6676 no_set_ipv6_nexthop_peer_cmd
,
6677 "no set ipv6 next-hop peer-address",
6681 "IPv6 next-hop address\n"
6682 "Use peer address (for BGP only)\n")
6685 "./set-action[action='frr-bgp-route-map:ipv6-peer-address']";
6687 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6688 return nb_cli_apply_changes(vty
, NULL
);
6691 DEFUN_YANG (set_ipv6_nexthop_prefer_global
,
6692 set_ipv6_nexthop_prefer_global_cmd
,
6693 "set ipv6 next-hop prefer-global",
6696 "IPv6 next-hop address\n"
6697 "Prefer global over link-local if both exist\n")
6700 "./set-action[action='frr-bgp-route-map:ipv6-prefer-global']";
6701 char xpath_value
[XPATH_MAXLEN
];
6703 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6704 snprintf(xpath_value
, sizeof(xpath_value
),
6705 "%s/rmap-set-action/frr-bgp-route-map:preference", xpath
);
6706 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
6708 return nb_cli_apply_changes(vty
, NULL
);
6711 DEFUN_YANG (no_set_ipv6_nexthop_prefer_global
,
6712 no_set_ipv6_nexthop_prefer_global_cmd
,
6713 "no set ipv6 next-hop prefer-global",
6717 "IPv6 next-hop address\n"
6718 "Prefer global over link-local if both exist\n")
6721 "./set-action[action='frr-bgp-route-map:ipv6-prefer-global']";
6723 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6724 return nb_cli_apply_changes(vty
, NULL
);
6727 DEFUN_YANG (set_ipv6_nexthop_global
,
6728 set_ipv6_nexthop_global_cmd
,
6729 "set ipv6 next-hop global X:X::X:X",
6732 "IPv6 next-hop address\n"
6733 "IPv6 global address\n"
6734 "IPv6 address of next hop\n")
6738 "./set-action[action='frr-bgp-route-map:ipv6-nexthop-global']";
6739 char xpath_value
[XPATH_MAXLEN
];
6741 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6742 snprintf(xpath_value
, sizeof(xpath_value
),
6743 "%s/rmap-set-action/frr-bgp-route-map:ipv6-address", xpath
);
6744 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6745 argv
[idx_ipv6
]->arg
);
6747 return nb_cli_apply_changes(vty
, NULL
);
6750 DEFUN_YANG (no_set_ipv6_nexthop_global
,
6751 no_set_ipv6_nexthop_global_cmd
,
6752 "no set ipv6 next-hop global X:X::X:X",
6756 "IPv6 next-hop address\n"
6757 "IPv6 global address\n"
6758 "IPv6 address of next hop\n")
6761 "./set-action[action='frr-bgp-route-map:ipv6-nexthop-global']";
6763 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6764 return nb_cli_apply_changes(vty
, NULL
);
6767 #ifdef KEEP_OLD_VPN_COMMANDS
6768 DEFUN_YANG (set_vpn_nexthop
,
6769 set_vpn_nexthop_cmd
,
6770 "set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
6772 "VPNv4 information\n"
6773 "VPN next-hop address\n"
6774 "IP address of next hop\n"
6775 "VPNv6 information\n"
6776 "VPN next-hop address\n"
6777 "IPv6 address of next hop\n")
6782 char xpath_value
[XPATH_MAXLEN
];
6784 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
6785 if (afi
== AFI_IP
) {
6787 "./set-action[action='frr-bgp-route-map:ipv4-vpn-address']";
6789 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6791 xpath_value
, sizeof(xpath_value
),
6792 "%s/rmap-set-action/frr-bgp-route-map:ipv4-address",
6796 "./set-action[action='frr-bgp-route-map:ipv6-vpn-address']";
6798 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6800 xpath_value
, sizeof(xpath_value
),
6801 "%s/rmap-set-action/frr-bgp-route-map:ipv6-address",
6805 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6808 return nb_cli_apply_changes(vty
, NULL
);
6814 DEFUN_YANG (no_set_vpn_nexthop
,
6815 no_set_vpn_nexthop_cmd
,
6816 "no set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
6819 "VPNv4 information\n"
6820 "VPN next-hop address\n"
6821 "IP address of next hop\n"
6822 "VPNv6 information\n"
6823 "VPN next-hop address\n"
6824 "IPv6 address of next hop\n")
6829 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
6830 if (afi
== AFI_IP
) {
6832 "./set-action[action='frr-bgp-route-map:ipv4-vpn-address']";
6833 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6836 "./set-action[action='frr-bgp-route-map:ipv6-vpn-address']";
6837 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6839 return nb_cli_apply_changes(vty
, NULL
);
6843 #endif /* KEEP_OLD_VPN_COMMANDS */
6845 DEFUN_YANG (set_ipx_vpn_nexthop
,
6846 set_ipx_vpn_nexthop_cmd
,
6847 "set <ipv4|ipv6> vpn next-hop <A.B.C.D|X:X::X:X>",
6849 "IPv4 information\n"
6850 "IPv6 information\n"
6852 "VPN next-hop address\n"
6853 "IP address of next hop\n"
6854 "IPv6 address of next hop\n")
6859 char xpath_value
[XPATH_MAXLEN
];
6861 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
6862 if (afi
== AFI_IP
) {
6864 "./set-action[action='frr-bgp-route-map:ipv4-vpn-address']";
6866 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6868 xpath_value
, sizeof(xpath_value
),
6869 "%s/rmap-set-action/frr-bgp-route-map:ipv4-address",
6873 "./set-action[action='frr-bgp-route-map:ipv6-vpn-address']";
6875 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6877 xpath_value
, sizeof(xpath_value
),
6878 "%s/rmap-set-action/frr-bgp-route-map:ipv6-address",
6881 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6883 return nb_cli_apply_changes(vty
, NULL
);
6888 DEFUN_YANG (no_set_ipx_vpn_nexthop
,
6889 no_set_ipx_vpn_nexthop_cmd
,
6890 "no set <ipv4|ipv6> vpn next-hop [<A.B.C.D|X:X::X:X>]",
6893 "IPv4 information\n"
6894 "IPv6 information\n"
6896 "VPN next-hop address\n"
6897 "IP address of next hop\n"
6898 "IPv6 address of next hop\n")
6903 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
6904 if (afi
== AFI_IP
) {
6906 "./set-action[action='frr-bgp-route-map:ipv4-vpn-address']";
6907 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6910 "./set-action[action='frr-bgp-route-map:ipv6-vpn-address']";
6911 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6913 return nb_cli_apply_changes(vty
, NULL
);
6918 DEFUN_YANG (set_originator_id
,
6919 set_originator_id_cmd
,
6920 "set originator-id A.B.C.D",
6922 "BGP originator ID attribute\n"
6923 "IP address of originator\n")
6927 "./set-action[action='frr-bgp-route-map:originator-id']";
6928 char xpath_value
[XPATH_MAXLEN
];
6930 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6931 snprintf(xpath_value
, sizeof(xpath_value
),
6932 "%s/rmap-set-action/frr-bgp-route-map:originator-id", xpath
);
6933 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6934 argv
[idx_ipv4
]->arg
);
6936 return nb_cli_apply_changes(vty
, NULL
);
6939 DEFUN_YANG (no_set_originator_id
,
6940 no_set_originator_id_cmd
,
6941 "no set originator-id [A.B.C.D]",
6944 "BGP originator ID attribute\n"
6945 "IP address of originator\n")
6948 "./set-action[action='frr-bgp-route-map:originator-id']";
6950 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6951 return nb_cli_apply_changes(vty
, NULL
);
6954 DEFPY_YANG (match_rpki_extcommunity
,
6955 match_rpki_extcommunity_cmd
,
6956 "[no$no] match rpki-extcommunity <valid|invalid|notfound>",
6959 "BGP RPKI (Origin Validation State) extended community attribute\n"
6962 "Prefix not found\n")
6965 "./match-condition[condition='frr-bgp-route-map:rpki-extcommunity']";
6966 char xpath_value
[XPATH_MAXLEN
];
6968 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6972 xpath_value
, sizeof(xpath_value
),
6973 "%s/rmap-match-condition/frr-bgp-route-map:rpki-extcommunity",
6975 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6979 return nb_cli_apply_changes(vty
, NULL
);
6982 /* Initialization of route map. */
6983 void bgp_route_map_init(void)
6987 route_map_add_hook(bgp_route_map_add
);
6988 route_map_delete_hook(bgp_route_map_delete
);
6989 route_map_event_hook(bgp_route_map_event
);
6991 route_map_match_interface_hook(generic_match_add
);
6992 route_map_no_match_interface_hook(generic_match_delete
);
6994 route_map_match_ip_address_hook(generic_match_add
);
6995 route_map_no_match_ip_address_hook(generic_match_delete
);
6997 route_map_match_ip_address_prefix_list_hook(generic_match_add
);
6998 route_map_no_match_ip_address_prefix_list_hook(generic_match_delete
);
7000 route_map_match_ip_next_hop_hook(generic_match_add
);
7001 route_map_no_match_ip_next_hop_hook(generic_match_delete
);
7003 route_map_match_ipv6_next_hop_hook(generic_match_add
);
7004 route_map_no_match_ipv6_next_hop_hook(generic_match_delete
);
7006 route_map_match_ip_next_hop_prefix_list_hook(generic_match_add
);
7007 route_map_no_match_ip_next_hop_prefix_list_hook(generic_match_delete
);
7009 route_map_match_ip_next_hop_type_hook(generic_match_add
);
7010 route_map_no_match_ip_next_hop_type_hook(generic_match_delete
);
7012 route_map_match_ipv6_address_hook(generic_match_add
);
7013 route_map_no_match_ipv6_address_hook(generic_match_delete
);
7015 route_map_match_ipv6_address_prefix_list_hook(generic_match_add
);
7016 route_map_no_match_ipv6_address_prefix_list_hook(generic_match_delete
);
7018 route_map_match_ipv6_next_hop_type_hook(generic_match_add
);
7019 route_map_no_match_ipv6_next_hop_type_hook(generic_match_delete
);
7021 route_map_match_ipv6_next_hop_prefix_list_hook(generic_match_add
);
7022 route_map_no_match_ipv6_next_hop_prefix_list_hook(generic_match_delete
);
7024 route_map_match_metric_hook(generic_match_add
);
7025 route_map_no_match_metric_hook(generic_match_delete
);
7027 route_map_match_tag_hook(generic_match_add
);
7028 route_map_no_match_tag_hook(generic_match_delete
);
7030 route_map_set_srte_color_hook(generic_set_add
);
7031 route_map_no_set_srte_color_hook(generic_set_delete
);
7033 route_map_set_ip_nexthop_hook(generic_set_add
);
7034 route_map_no_set_ip_nexthop_hook(generic_set_delete
);
7036 route_map_set_ipv6_nexthop_local_hook(generic_set_add
);
7037 route_map_no_set_ipv6_nexthop_local_hook(generic_set_delete
);
7039 route_map_set_metric_hook(generic_set_add
);
7040 route_map_no_set_metric_hook(generic_set_delete
);
7042 route_map_set_tag_hook(generic_set_add
);
7043 route_map_no_set_tag_hook(generic_set_delete
);
7045 route_map_install_match(&route_match_peer_cmd
);
7046 route_map_install_match(&route_match_alias_cmd
);
7047 route_map_install_match(&route_match_local_pref_cmd
);
7048 #ifdef HAVE_SCRIPTING
7049 route_map_install_match(&route_match_script_cmd
);
7051 route_map_install_match(&route_match_ip_address_cmd
);
7052 route_map_install_match(&route_match_ip_next_hop_cmd
);
7053 route_map_install_match(&route_match_ip_route_source_cmd
);
7054 route_map_install_match(&route_match_ip_address_prefix_list_cmd
);
7055 route_map_install_match(&route_match_ip_next_hop_prefix_list_cmd
);
7056 route_map_install_match(&route_match_ip_next_hop_type_cmd
);
7057 route_map_install_match(&route_match_ip_route_source_prefix_list_cmd
);
7058 route_map_install_match(&route_match_aspath_cmd
);
7059 route_map_install_match(&route_match_community_cmd
);
7060 route_map_install_match(&route_match_lcommunity_cmd
);
7061 route_map_install_match(&route_match_ecommunity_cmd
);
7062 route_map_install_match(&route_match_local_pref_cmd
);
7063 route_map_install_match(&route_match_metric_cmd
);
7064 route_map_install_match(&route_match_origin_cmd
);
7065 route_map_install_match(&route_match_probability_cmd
);
7066 route_map_install_match(&route_match_interface_cmd
);
7067 route_map_install_match(&route_match_tag_cmd
);
7068 route_map_install_match(&route_match_mac_address_cmd
);
7069 route_map_install_match(&route_match_evpn_vni_cmd
);
7070 route_map_install_match(&route_match_evpn_route_type_cmd
);
7071 route_map_install_match(&route_match_evpn_rd_cmd
);
7072 route_map_install_match(&route_match_evpn_default_route_cmd
);
7073 route_map_install_match(&route_match_vrl_source_vrf_cmd
);
7075 route_map_install_set(&route_set_evpn_gateway_ip_ipv4_cmd
);
7076 route_map_install_set(&route_set_evpn_gateway_ip_ipv6_cmd
);
7077 route_map_install_set(&route_set_table_id_cmd
);
7078 route_map_install_set(&route_set_srte_color_cmd
);
7079 route_map_install_set(&route_set_ip_nexthop_cmd
);
7080 route_map_install_set(&route_set_local_pref_cmd
);
7081 route_map_install_set(&route_set_weight_cmd
);
7082 route_map_install_set(&route_set_label_index_cmd
);
7083 route_map_install_set(&route_set_metric_cmd
);
7084 route_map_install_set(&route_set_distance_cmd
);
7085 route_map_install_set(&route_set_aspath_prepend_cmd
);
7086 route_map_install_set(&route_set_aspath_exclude_cmd
);
7087 route_map_install_set(&route_set_aspath_replace_cmd
);
7088 route_map_install_set(&route_set_origin_cmd
);
7089 route_map_install_set(&route_set_atomic_aggregate_cmd
);
7090 route_map_install_set(&route_set_aigp_metric_cmd
);
7091 route_map_install_set(&route_set_aggregator_as_cmd
);
7092 route_map_install_set(&route_set_community_cmd
);
7093 route_map_install_set(&route_set_community_delete_cmd
);
7094 route_map_install_set(&route_set_lcommunity_cmd
);
7095 route_map_install_set(&route_set_lcommunity_delete_cmd
);
7096 route_map_install_set(&route_set_vpnv4_nexthop_cmd
);
7097 route_map_install_set(&route_set_vpnv6_nexthop_cmd
);
7098 route_map_install_set(&route_set_originator_id_cmd
);
7099 route_map_install_set(&route_set_ecommunity_rt_cmd
);
7100 route_map_install_set(&route_set_ecommunity_soo_cmd
);
7101 route_map_install_set(&route_set_ecommunity_lb_cmd
);
7102 route_map_install_set(&route_set_ecommunity_none_cmd
);
7103 route_map_install_set(&route_set_tag_cmd
);
7104 route_map_install_set(&route_set_label_index_cmd
);
7105 route_map_install_set(&route_set_l3vpn_nexthop_encapsulation_cmd
);
7107 install_element(RMAP_NODE
, &match_peer_cmd
);
7108 install_element(RMAP_NODE
, &match_peer_local_cmd
);
7109 install_element(RMAP_NODE
, &no_match_peer_cmd
);
7110 install_element(RMAP_NODE
, &match_ip_route_source_cmd
);
7111 install_element(RMAP_NODE
, &no_match_ip_route_source_cmd
);
7112 install_element(RMAP_NODE
, &match_ip_route_source_prefix_list_cmd
);
7113 install_element(RMAP_NODE
, &no_match_ip_route_source_prefix_list_cmd
);
7114 install_element(RMAP_NODE
, &match_mac_address_cmd
);
7115 install_element(RMAP_NODE
, &no_match_mac_address_cmd
);
7116 install_element(RMAP_NODE
, &match_evpn_vni_cmd
);
7117 install_element(RMAP_NODE
, &no_match_evpn_vni_cmd
);
7118 install_element(RMAP_NODE
, &match_evpn_route_type_cmd
);
7119 install_element(RMAP_NODE
, &no_match_evpn_route_type_cmd
);
7120 install_element(RMAP_NODE
, &match_evpn_rd_cmd
);
7121 install_element(RMAP_NODE
, &no_match_evpn_rd_cmd
);
7122 install_element(RMAP_NODE
, &match_evpn_default_route_cmd
);
7123 install_element(RMAP_NODE
, &no_match_evpn_default_route_cmd
);
7124 install_element(RMAP_NODE
, &set_evpn_gw_ip_ipv4_cmd
);
7125 install_element(RMAP_NODE
, &no_set_evpn_gw_ip_ipv4_cmd
);
7126 install_element(RMAP_NODE
, &set_evpn_gw_ip_ipv6_cmd
);
7127 install_element(RMAP_NODE
, &no_set_evpn_gw_ip_ipv6_cmd
);
7128 install_element(RMAP_NODE
, &match_vrl_source_vrf_cmd
);
7129 install_element(RMAP_NODE
, &no_match_vrl_source_vrf_cmd
);
7131 install_element(RMAP_NODE
, &match_aspath_cmd
);
7132 install_element(RMAP_NODE
, &no_match_aspath_cmd
);
7133 install_element(RMAP_NODE
, &match_local_pref_cmd
);
7134 install_element(RMAP_NODE
, &no_match_local_pref_cmd
);
7135 install_element(RMAP_NODE
, &match_alias_cmd
);
7136 install_element(RMAP_NODE
, &no_match_alias_cmd
);
7137 install_element(RMAP_NODE
, &match_community_cmd
);
7138 install_element(RMAP_NODE
, &no_match_community_cmd
);
7139 install_element(RMAP_NODE
, &match_lcommunity_cmd
);
7140 install_element(RMAP_NODE
, &no_match_lcommunity_cmd
);
7141 install_element(RMAP_NODE
, &match_ecommunity_cmd
);
7142 install_element(RMAP_NODE
, &no_match_ecommunity_cmd
);
7143 install_element(RMAP_NODE
, &match_origin_cmd
);
7144 install_element(RMAP_NODE
, &no_match_origin_cmd
);
7145 install_element(RMAP_NODE
, &match_probability_cmd
);
7146 install_element(RMAP_NODE
, &no_match_probability_cmd
);
7148 install_element(RMAP_NODE
, &no_set_table_id_cmd
);
7149 install_element(RMAP_NODE
, &set_table_id_cmd
);
7150 install_element(RMAP_NODE
, &set_ip_nexthop_peer_cmd
);
7151 install_element(RMAP_NODE
, &set_ip_nexthop_unchanged_cmd
);
7152 install_element(RMAP_NODE
, &set_local_pref_cmd
);
7153 install_element(RMAP_NODE
, &set_distance_cmd
);
7154 install_element(RMAP_NODE
, &no_set_distance_cmd
);
7155 install_element(RMAP_NODE
, &no_set_local_pref_cmd
);
7156 install_element(RMAP_NODE
, &set_weight_cmd
);
7157 install_element(RMAP_NODE
, &set_label_index_cmd
);
7158 install_element(RMAP_NODE
, &no_set_weight_cmd
);
7159 install_element(RMAP_NODE
, &no_set_label_index_cmd
);
7160 install_element(RMAP_NODE
, &set_aspath_prepend_asn_cmd
);
7161 install_element(RMAP_NODE
, &set_aspath_prepend_lastas_cmd
);
7162 install_element(RMAP_NODE
, &set_aspath_exclude_cmd
);
7163 install_element(RMAP_NODE
, &set_aspath_replace_asn_cmd
);
7164 install_element(RMAP_NODE
, &no_set_aspath_prepend_cmd
);
7165 install_element(RMAP_NODE
, &no_set_aspath_prepend_lastas_cmd
);
7166 install_element(RMAP_NODE
, &no_set_aspath_exclude_cmd
);
7167 install_element(RMAP_NODE
, &no_set_aspath_exclude_all_cmd
);
7168 install_element(RMAP_NODE
, &no_set_aspath_replace_asn_cmd
);
7169 install_element(RMAP_NODE
, &set_origin_cmd
);
7170 install_element(RMAP_NODE
, &no_set_origin_cmd
);
7171 install_element(RMAP_NODE
, &set_atomic_aggregate_cmd
);
7172 install_element(RMAP_NODE
, &no_set_atomic_aggregate_cmd
);
7173 install_element(RMAP_NODE
, &set_aigp_metric_cmd
);
7174 install_element(RMAP_NODE
, &no_set_aigp_metric_cmd
);
7175 install_element(RMAP_NODE
, &set_aggregator_as_cmd
);
7176 install_element(RMAP_NODE
, &no_set_aggregator_as_cmd
);
7177 install_element(RMAP_NODE
, &set_community_cmd
);
7178 install_element(RMAP_NODE
, &set_community_none_cmd
);
7179 install_element(RMAP_NODE
, &no_set_community_cmd
);
7180 install_element(RMAP_NODE
, &no_set_community_short_cmd
);
7181 install_element(RMAP_NODE
, &set_community_delete_cmd
);
7182 install_element(RMAP_NODE
, &no_set_community_delete_cmd
);
7183 install_element(RMAP_NODE
, &set_lcommunity_cmd
);
7184 install_element(RMAP_NODE
, &set_lcommunity_none_cmd
);
7185 install_element(RMAP_NODE
, &no_set_lcommunity_cmd
);
7186 install_element(RMAP_NODE
, &no_set_lcommunity1_cmd
);
7187 install_element(RMAP_NODE
, &no_set_lcommunity1_short_cmd
);
7188 install_element(RMAP_NODE
, &set_lcommunity_delete_cmd
);
7189 install_element(RMAP_NODE
, &no_set_lcommunity_delete_cmd
);
7190 install_element(RMAP_NODE
, &no_set_lcommunity_delete_short_cmd
);
7191 install_element(RMAP_NODE
, &set_ecommunity_rt_cmd
);
7192 install_element(RMAP_NODE
, &no_set_ecommunity_rt_cmd
);
7193 install_element(RMAP_NODE
, &no_set_ecommunity_rt_short_cmd
);
7194 install_element(RMAP_NODE
, &set_ecommunity_soo_cmd
);
7195 install_element(RMAP_NODE
, &no_set_ecommunity_soo_cmd
);
7196 install_element(RMAP_NODE
, &no_set_ecommunity_soo_short_cmd
);
7197 install_element(RMAP_NODE
, &set_ecommunity_lb_cmd
);
7198 install_element(RMAP_NODE
, &no_set_ecommunity_lb_cmd
);
7199 install_element(RMAP_NODE
, &no_set_ecommunity_lb_short_cmd
);
7200 install_element(RMAP_NODE
, &set_ecommunity_none_cmd
);
7201 install_element(RMAP_NODE
, &no_set_ecommunity_none_cmd
);
7202 #ifdef KEEP_OLD_VPN_COMMANDS
7203 install_element(RMAP_NODE
, &set_vpn_nexthop_cmd
);
7204 install_element(RMAP_NODE
, &no_set_vpn_nexthop_cmd
);
7205 #endif /* KEEP_OLD_VPN_COMMANDS */
7206 install_element(RMAP_NODE
, &set_ipx_vpn_nexthop_cmd
);
7207 install_element(RMAP_NODE
, &no_set_ipx_vpn_nexthop_cmd
);
7208 install_element(RMAP_NODE
, &set_originator_id_cmd
);
7209 install_element(RMAP_NODE
, &no_set_originator_id_cmd
);
7210 install_element(RMAP_NODE
, &set_l3vpn_nexthop_encapsulation_cmd
);
7212 route_map_install_match(&route_match_ipv6_address_cmd
);
7213 route_map_install_match(&route_match_ipv6_next_hop_cmd
);
7214 route_map_install_match(&route_match_ipv6_next_hop_address_cmd
);
7215 route_map_install_match(&route_match_ipv6_next_hop_prefix_list_cmd
);
7216 route_map_install_match(&route_match_ipv4_next_hop_cmd
);
7217 route_map_install_match(&route_match_ipv6_address_prefix_list_cmd
);
7218 route_map_install_match(&route_match_ipv6_next_hop_type_cmd
);
7219 route_map_install_set(&route_set_ipv6_nexthop_global_cmd
);
7220 route_map_install_set(&route_set_ipv6_nexthop_prefer_global_cmd
);
7221 route_map_install_set(&route_set_ipv6_nexthop_local_cmd
);
7222 route_map_install_set(&route_set_ipv6_nexthop_peer_cmd
);
7223 route_map_install_match(&route_match_rpki_extcommunity_cmd
);
7225 install_element(RMAP_NODE
, &match_ipv6_next_hop_cmd
);
7226 install_element(RMAP_NODE
, &match_ipv6_next_hop_address_cmd
);
7227 install_element(RMAP_NODE
, &match_ipv6_next_hop_prefix_list_cmd
);
7228 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_cmd
);
7229 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_address_cmd
);
7230 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_prefix_list_cmd
);
7231 install_element(RMAP_NODE
, &match_ipv6_next_hop_old_cmd
);
7232 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_old_cmd
);
7233 install_element(RMAP_NODE
, &match_ipv4_next_hop_cmd
);
7234 install_element(RMAP_NODE
, &no_match_ipv4_next_hop_cmd
);
7235 install_element(RMAP_NODE
, &set_ipv6_nexthop_global_cmd
);
7236 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_global_cmd
);
7237 install_element(RMAP_NODE
, &set_ipv6_nexthop_prefer_global_cmd
);
7238 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_prefer_global_cmd
);
7239 install_element(RMAP_NODE
, &set_ipv6_nexthop_peer_cmd
);
7240 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_peer_cmd
);
7241 install_element(RMAP_NODE
, &match_rpki_extcommunity_cmd
);
7242 #ifdef HAVE_SCRIPTING
7243 install_element(RMAP_NODE
, &match_script_cmd
);
7247 void bgp_route_map_terminate(void)
7249 /* ToDo: Cleanup all the used memory */