1 /* Route map function of bgpd.
2 * Copyright (C) 1998, 1999 Kunihiro Ishiguro
4 * This file is part of GNU Zebra.
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32 #include "frrscript.h"
33 #ifdef HAVE_LIBPCRE2_POSIX
34 #ifndef _FRR_PCRE2_POSIX
35 #define _FRR_PCRE2_POSIX
36 #include <pcre2posix.h>
37 #endif /* _FRR_PCRE2_POSIX */
38 #elif defined(HAVE_LIBPCREPOSIX)
39 #include <pcreposix.h>
42 #endif /* HAVE_LIBPCRE2_POSIX */
44 #include "sockunion.h"
49 #include "lib/northbound_cli.h"
51 #include "bgpd/bgpd.h"
52 #include "bgpd/bgp_table.h"
53 #include "bgpd/bgp_attr.h"
54 #include "bgpd/bgp_aspath.h"
55 #include "bgpd/bgp_packet.h"
56 #include "bgpd/bgp_route.h"
57 #include "bgpd/bgp_zebra.h"
58 #include "bgpd/bgp_regex.h"
59 #include "bgpd/bgp_community.h"
60 #include "bgpd/bgp_community_alias.h"
61 #include "bgpd/bgp_clist.h"
62 #include "bgpd/bgp_filter.h"
63 #include "bgpd/bgp_mplsvpn.h"
64 #include "bgpd/bgp_ecommunity.h"
65 #include "bgpd/bgp_lcommunity.h"
66 #include "bgpd/bgp_vty.h"
67 #include "bgpd/bgp_debug.h"
68 #include "bgpd/bgp_evpn.h"
69 #include "bgpd/bgp_evpn_private.h"
70 #include "bgpd/bgp_evpn_vty.h"
71 #include "bgpd/bgp_mplsvpn.h"
72 #include "bgpd/bgp_pbr.h"
73 #include "bgpd/bgp_flowspec_util.h"
74 #include "bgpd/bgp_encap_types.h"
75 #include "bgpd/bgp_mpath.h"
76 #include "bgpd/bgp_script.h"
79 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
82 #include "bgpd/bgp_routemap_clippy.c"
84 /* Memo of route-map commands.
93 ip route-source : Done
97 ipv6 route-source: (This will not be implemented by bgpd)
98 ipv6 prefix-list : Done
99 length : (This will not be implemented by bgpd)
101 route-type : (This will not be implemented by bgpd)
103 local-preference : Done
105 set as-path prepend : Done
106 as-path tag : Not yet
107 automatic-tag : (This will not be implemented by bgpd)
109 large-community : Done
110 large-comm-list : Done
113 default : (This will not be implemented by bgpd)
114 interface : (This will not be implemented by bgpd)
115 ip default : (This will not be implemented by bgpd)
117 ip precedence : (This will not be implemented by bgpd)
118 ip tos : (This will not be implemented by bgpd)
119 level : (This will not be implemented by bgpd)
120 local-preference : Done
122 metric-type : Not yet
130 set ipv6 next-hop global: Done
131 set ipv6 next-hop prefer-global: Done
132 set ipv6 next-hop local : Done
133 set as-path exclude : Done
137 /* generic value manipulation to be shared in multiple rules */
139 #define RMAP_VALUE_SET 0
140 #define RMAP_VALUE_ADD 1
141 #define RMAP_VALUE_SUB 2
149 static int route_value_match(struct rmap_value
*rv
, uint32_t value
)
151 if (rv
->variable
== 0 && value
== rv
->value
)
157 static uint32_t route_value_adjust(struct rmap_value
*rv
, uint32_t current
,
162 switch (rv
->variable
) {
171 switch (rv
->action
) {
173 if (current
> UINT32_MAX
- value
)
175 return current
+ value
;
177 if (current
<= value
)
179 return current
- value
;
185 static void *route_value_compile(const char *arg
)
187 uint8_t action
= RMAP_VALUE_SET
, var
= 0;
188 unsigned long larg
= 0;
190 struct rmap_value
*rv
;
193 action
= RMAP_VALUE_ADD
;
195 } else if (arg
[0] == '-') {
196 action
= RMAP_VALUE_SUB
;
200 if (all_digit(arg
)) {
202 larg
= strtoul(arg
, &endptr
, 10);
203 if (*arg
== 0 || *endptr
!= 0 || errno
|| larg
> UINT32_MAX
)
206 if (strcmp(arg
, "rtt") == 0)
212 rv
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_value
));
220 static void route_value_free(void *rule
)
222 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
225 /* generic as path object to be shared in multiple rules */
227 static void *route_aspath_compile(const char *arg
)
229 struct aspath
*aspath
;
231 aspath
= aspath_str2aspath(arg
);
237 static void route_aspath_free(void *rule
)
239 struct aspath
*aspath
= rule
;
243 struct bgp_match_peer_compiled
{
248 /* 'match peer (A.B.C.D|X:X::X:X|WORD)' */
250 /* Compares the peer specified in the 'match peer' clause with the peer
251 received in bgp_path_info->peer. If it is the same, or if the peer structure
252 received is a peer_group containing it, returns RMAP_MATCH. */
253 static enum route_map_cmd_result_t
254 route_match_peer(void *rule
, const struct prefix
*prefix
, void *object
)
256 struct bgp_match_peer_compiled
*pc
;
258 union sockunion su_def
= {
259 .sin
= {.sin_family
= AF_INET
, .sin_addr
.s_addr
= INADDR_ANY
}};
260 struct peer_group
*group
;
262 struct listnode
*node
, *nnode
;
266 peer
= ((struct bgp_path_info
*)object
)->peer
;
269 if (!peer
->conf_if
|| !peer
->group
)
272 if (peer
->conf_if
&& strcmp(peer
->conf_if
, pc
->interface
) == 0)
276 strcmp(peer
->group
->name
, pc
->interface
) == 0)
282 /* If su='0.0.0.0' (command 'match peer local'), and it's a
284 REDISTRIBUTE, AGGREGATE-ADDRESS or DEFAULT_GENERATED route
287 if (sockunion_same(su
, &su_def
)) {
289 if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_NETWORK
)
290 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_REDISTRIBUTE
)
291 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_AGGREGATE
)
292 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_DEFAULT
))
299 if (!CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
)) {
300 if (sockunion_same(su
, &peer
->su
))
306 for (ALL_LIST_ELEMENTS(group
->peer
, node
, nnode
, peer
)) {
307 if (sockunion_same(su
, &peer
->su
))
316 static void *route_match_peer_compile(const char *arg
)
318 struct bgp_match_peer_compiled
*pc
;
321 pc
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
322 sizeof(struct bgp_match_peer_compiled
));
324 ret
= str2sockunion(strcmp(arg
, "local") ? arg
: "0.0.0.0", &pc
->su
);
326 pc
->interface
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
333 /* Free route map's compiled `ip address' value. */
334 static void route_match_peer_free(void *rule
)
336 struct bgp_match_peer_compiled
*pc
= rule
;
338 XFREE(MTYPE_ROUTE_MAP_COMPILED
, pc
->interface
);
340 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
343 /* Route map commands for ip address matching. */
344 static const struct route_map_rule_cmd route_match_peer_cmd
= {
347 route_match_peer_compile
,
348 route_match_peer_free
351 #ifdef HAVE_SCRIPTING
353 enum frrlua_rm_status
{
355 * Script function run failure. This will translate into a deny
359 * No Match was found for the route map function
363 * Match was found but no changes were made to the incoming data.
367 * Match was found and data was modified, so figure out what changed
369 LUA_RM_MATCH_AND_CHANGE
,
372 static enum route_map_cmd_result_t
373 route_match_script(void *rule
, const struct prefix
*prefix
, void *object
)
375 const char *scriptname
= rule
;
376 const char *routematch_function
= "route_match";
377 struct bgp_path_info
*path
= (struct bgp_path_info
*)object
;
379 struct frrscript
*fs
= frrscript_new(scriptname
);
381 if (frrscript_load(fs
, routematch_function
, NULL
)) {
383 "Issue loading script or function; defaulting to no match");
387 struct attr newattr
= *path
->attr
;
389 int result
= frrscript_call(
390 fs
, routematch_function
, ("prefix", prefix
),
391 ("attributes", &newattr
), ("peer", path
->peer
),
392 ("RM_FAILURE", LUA_RM_FAILURE
), ("RM_NOMATCH", LUA_RM_NOMATCH
),
393 ("RM_MATCH", LUA_RM_MATCH
),
394 ("RM_MATCH_AND_CHANGE", LUA_RM_MATCH_AND_CHANGE
));
397 zlog_err("Issue running script rule; defaulting to no match");
401 long long *action
= frrscript_get_result(fs
, routematch_function
,
402 "action", lua_tointegerp
);
404 int status
= RMAP_NOMATCH
;
409 "Executing route-map match script '%s' failed; defaulting to no match",
411 status
= RMAP_NOMATCH
;
414 status
= RMAP_NOMATCH
;
416 case LUA_RM_MATCH_AND_CHANGE
:
418 zlog_debug("Updating attribute based on script's values");
420 uint32_t locpref
= 0;
422 path
->attr
->med
= newattr
.med
;
424 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
))
425 locpref
= path
->attr
->local_pref
;
426 if (locpref
!= newattr
.local_pref
) {
427 SET_FLAG(path
->attr
->flag
,
428 ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
));
429 path
->attr
->local_pref
= newattr
.local_pref
;
437 XFREE(MTYPE_SCRIPT_RES
, action
);
439 frrscript_delete(fs
);
444 static void *route_match_script_compile(const char *arg
)
448 scriptname
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
453 static void route_match_script_free(void *rule
)
455 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
458 static const struct route_map_rule_cmd route_match_script_cmd
= {
461 route_match_script_compile
,
462 route_match_script_free
465 #endif /* HAVE_SCRIPTING */
467 /* `match ip address IP_ACCESS_LIST' */
469 /* Match function should return 1 if match is success else return
471 static enum route_map_cmd_result_t
472 route_match_ip_address(void *rule
, const struct prefix
*prefix
, void *object
)
474 struct access_list
*alist
;
476 if (prefix
->family
== AF_INET
) {
477 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
479 if (CHECK_FLAG(rmap_debug
, DEBUG_ROUTEMAP_DETAIL
))
481 "%s: Access-List Specified: %s does not exist defaulting to NO_MATCH",
482 __func__
, (char *)rule
);
486 return (access_list_apply(alist
, prefix
) == FILTER_DENY
493 /* Route map `ip address' match statement. `arg' should be
495 static void *route_match_ip_address_compile(const char *arg
)
497 struct access_list
*alist
;
499 alist
= access_list_lookup(AFI_IP
, arg
);
502 "Access List specified %s does not exist yet, default will be NO_MATCH until it is created",
504 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
507 /* Free route map's compiled `ip address' value. */
508 static void route_match_ip_address_free(void *rule
)
510 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
513 /* Route map commands for ip address matching. */
514 static const struct route_map_rule_cmd route_match_ip_address_cmd
= {
516 route_match_ip_address
,
517 route_match_ip_address_compile
,
518 route_match_ip_address_free
521 /* `match ip next-hop <IP_ADDRESS_ACCESS_LIST_NAME>' */
523 /* Match function return 1 if match is success else return zero. */
524 static enum route_map_cmd_result_t
525 route_match_ip_next_hop(void *rule
, const struct prefix
*prefix
, void *object
)
527 struct access_list
*alist
;
528 struct bgp_path_info
*path
;
529 struct prefix_ipv4 p
;
531 if (prefix
->family
== AF_INET
) {
534 p
.prefix
= path
->attr
->nexthop
;
535 p
.prefixlen
= IPV4_MAX_BITLEN
;
537 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
539 if (CHECK_FLAG(rmap_debug
, DEBUG_ROUTEMAP_DETAIL
))
541 "%s: Access-List Specified: %s does not exist defaulting to NO_MATCH",
542 __func__
, (char *)rule
);
547 return (access_list_apply(alist
, &p
) == FILTER_DENY
554 /* Route map `ip next-hop' match statement. `arg' is
556 static void *route_match_ip_next_hop_compile(const char *arg
)
558 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
561 /* Free route map's compiled `ip address' value. */
562 static void route_match_ip_next_hop_free(void *rule
)
564 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
567 /* Route map commands for ip next-hop matching. */
568 static const struct route_map_rule_cmd route_match_ip_next_hop_cmd
= {
570 route_match_ip_next_hop
,
571 route_match_ip_next_hop_compile
,
572 route_match_ip_next_hop_free
575 /* `match ip route-source ACCESS-LIST' */
577 /* Match function return 1 if match is success else return zero. */
578 static enum route_map_cmd_result_t
579 route_match_ip_route_source(void *rule
, const struct prefix
*pfx
, void *object
)
581 struct access_list
*alist
;
582 struct bgp_path_info
*path
;
584 struct prefix_ipv4 p
;
586 if (pfx
->family
== AF_INET
) {
590 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
594 p
.prefix
= peer
->su
.sin
.sin_addr
;
595 p
.prefixlen
= IPV4_MAX_BITLEN
;
597 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
599 if (CHECK_FLAG(rmap_debug
, DEBUG_ROUTEMAP_DETAIL
))
601 "%s: Access-List Specified: %s does not exist defaulting to NO_MATCH",
602 __func__
, (char *)rule
);
607 return (access_list_apply(alist
, &p
) == FILTER_DENY
614 /* Route map `ip route-source' match statement. `arg' is
616 static void *route_match_ip_route_source_compile(const char *arg
)
618 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
621 /* Free route map's compiled `ip address' value. */
622 static void route_match_ip_route_source_free(void *rule
)
624 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
627 /* Route map commands for ip route-source matching. */
628 static const struct route_map_rule_cmd route_match_ip_route_source_cmd
= {
630 route_match_ip_route_source
,
631 route_match_ip_route_source_compile
,
632 route_match_ip_route_source_free
635 static enum route_map_cmd_result_t
636 route_match_prefix_list_flowspec(afi_t afi
, struct prefix_list
*plist
,
637 const struct prefix
*p
)
640 struct bgp_pbr_entry_main api
;
642 memset(&api
, 0, sizeof(api
));
644 if (family2afi(p
->u
.prefix_flowspec
.family
) != afi
)
647 /* extract match from flowspec entries */
648 ret
= bgp_flowspec_match_rules_fill(
649 (uint8_t *)p
->u
.prefix_flowspec
.ptr
,
650 p
->u
.prefix_flowspec
.prefixlen
, &api
,
654 if (api
.match_bitmask
& PREFIX_DST_PRESENT
||
655 api
.match_bitmask_iprule
& PREFIX_DST_PRESENT
) {
656 if (family2afi((&api
.dst_prefix
)->family
) != afi
)
658 return prefix_list_apply(plist
, &api
.dst_prefix
) == PREFIX_DENY
661 } else if (api
.match_bitmask
& PREFIX_SRC_PRESENT
||
662 api
.match_bitmask_iprule
& PREFIX_SRC_PRESENT
) {
663 if (family2afi((&api
.src_prefix
)->family
) != afi
)
665 return (prefix_list_apply(plist
, &api
.src_prefix
) == PREFIX_DENY
672 static enum route_map_cmd_result_t
673 route_match_prefix_list_evpn(afi_t afi
, struct prefix_list
*plist
,
674 const struct prefix
*p
)
676 /* Convert to match a general plist */
679 if (evpn_prefix2prefix(p
, &new))
682 return (prefix_list_apply(plist
, &new) == PREFIX_DENY
? RMAP_NOMATCH
686 static enum route_map_cmd_result_t
687 route_match_address_prefix_list(void *rule
, afi_t afi
,
688 const struct prefix
*prefix
, void *object
)
690 struct prefix_list
*plist
;
692 plist
= prefix_list_lookup(afi
, (char *)rule
);
694 if (CHECK_FLAG(rmap_debug
, DEBUG_ROUTEMAP_DETAIL
))
696 "%s: Prefix List %s specified does not exist defaulting to NO_MATCH",
697 __func__
, (char *)rule
);
701 if (prefix
->family
== AF_FLOWSPEC
)
702 return route_match_prefix_list_flowspec(afi
, plist
,
705 else if (prefix
->family
== AF_EVPN
)
706 return route_match_prefix_list_evpn(afi
, plist
, prefix
);
708 return (prefix_list_apply(plist
, prefix
) == PREFIX_DENY
? RMAP_NOMATCH
712 static enum route_map_cmd_result_t
713 route_match_ip_address_prefix_list(void *rule
, const struct prefix
*prefix
,
716 return route_match_address_prefix_list(rule
, AFI_IP
, prefix
, object
);
719 static void *route_match_ip_address_prefix_list_compile(const char *arg
)
721 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
724 static void route_match_ip_address_prefix_list_free(void *rule
)
726 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
729 static const struct route_map_rule_cmd
730 route_match_ip_address_prefix_list_cmd
= {
731 "ip address prefix-list",
732 route_match_ip_address_prefix_list
,
733 route_match_ip_address_prefix_list_compile
,
734 route_match_ip_address_prefix_list_free
737 /* `match ip next-hop prefix-list PREFIX_LIST' */
739 static enum route_map_cmd_result_t
740 route_match_ip_next_hop_prefix_list(void *rule
, const struct prefix
*prefix
,
743 struct prefix_list
*plist
;
744 struct bgp_path_info
*path
;
745 struct prefix_ipv4 p
;
747 if (prefix
->family
== AF_INET
) {
750 p
.prefix
= path
->attr
->nexthop
;
751 p
.prefixlen
= IPV4_MAX_BITLEN
;
753 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
755 if (CHECK_FLAG(rmap_debug
, DEBUG_ROUTEMAP_DETAIL
))
757 "%s: Prefix List %s specified does not exist defaulting to NO_MATCH",
758 __func__
, (char *)rule
);
762 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
769 static void *route_match_ip_next_hop_prefix_list_compile(const char *arg
)
771 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
774 static void route_match_ip_next_hop_prefix_list_free(void *rule
)
776 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
779 static const struct route_map_rule_cmd
780 route_match_ip_next_hop_prefix_list_cmd
= {
781 "ip next-hop prefix-list",
782 route_match_ip_next_hop_prefix_list
,
783 route_match_ip_next_hop_prefix_list_compile
,
784 route_match_ip_next_hop_prefix_list_free
787 /* `match ipv6 next-hop prefix-list PREFIXLIST_NAME' */
788 static enum route_map_cmd_result_t
789 route_match_ipv6_next_hop_prefix_list(void *rule
, const struct prefix
*prefix
,
792 struct prefix_list
*plist
;
793 struct bgp_path_info
*path
;
794 struct prefix_ipv6 p
;
796 if (prefix
->family
== AF_INET6
) {
799 p
.prefix
= path
->attr
->mp_nexthop_global
;
800 p
.prefixlen
= IPV6_MAX_BITLEN
;
802 plist
= prefix_list_lookup(AFI_IP6
, (char *)rule
);
804 if (CHECK_FLAG(rmap_debug
, DEBUG_ROUTEMAP_DETAIL
))
806 "%s: Prefix List %s specified does not exist defaulting to NO_MATCH",
807 __func__
, (char *)rule
);
811 if (prefix_list_apply(plist
, &p
) == PREFIX_PERMIT
)
814 if (path
->attr
->mp_nexthop_len
815 == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
) {
816 p
.prefix
= path
->attr
->mp_nexthop_local
;
817 if (prefix_list_apply(plist
, &p
) == PREFIX_PERMIT
)
825 static void *route_match_ipv6_next_hop_prefix_list_compile(const char *arg
)
827 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
830 static void route_match_ipv6_next_hop_prefix_list_free(void *rule
)
832 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
835 static const struct route_map_rule_cmd
836 route_match_ipv6_next_hop_prefix_list_cmd
= {
837 "ipv6 next-hop prefix-list",
838 route_match_ipv6_next_hop_prefix_list
,
839 route_match_ipv6_next_hop_prefix_list_compile
,
840 route_match_ipv6_next_hop_prefix_list_free
843 /* `match ip next-hop type <blackhole>' */
845 static enum route_map_cmd_result_t
846 route_match_ip_next_hop_type(void *rule
, const struct prefix
*prefix
,
849 struct bgp_path_info
*path
;
851 if (prefix
->family
== AF_INET
) {
852 path
= (struct bgp_path_info
*)object
;
856 /* If nexthop interface's index can't be resolved and nexthop is
857 set to any address then mark it as type `blackhole`.
858 This logic works for matching kernel/static routes like:
859 `ip route add blackhole 10.0.0.1`. */
860 if (path
->attr
->nexthop
.s_addr
== INADDR_ANY
861 && !path
->attr
->nh_ifindex
)
867 static void *route_match_ip_next_hop_type_compile(const char *arg
)
869 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
872 static void route_match_ip_next_hop_type_free(void *rule
)
874 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
877 static const struct route_map_rule_cmd
878 route_match_ip_next_hop_type_cmd
= {
880 route_match_ip_next_hop_type
,
881 route_match_ip_next_hop_type_compile
,
882 route_match_ip_next_hop_type_free
885 /* `match ip route-source prefix-list PREFIX_LIST' */
887 static enum route_map_cmd_result_t
888 route_match_ip_route_source_prefix_list(void *rule
, const struct prefix
*prefix
,
891 struct prefix_list
*plist
;
892 struct bgp_path_info
*path
;
894 struct prefix_ipv4 p
;
896 if (prefix
->family
== AF_INET
) {
900 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
904 p
.prefix
= peer
->su
.sin
.sin_addr
;
905 p
.prefixlen
= IPV4_MAX_BITLEN
;
907 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
909 if (CHECK_FLAG(rmap_debug
, DEBUG_ROUTEMAP_DETAIL
))
911 "%s: Prefix List %s specified does not exist defaulting to NO_MATCH",
912 __func__
, (char *)rule
);
916 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
923 static void *route_match_ip_route_source_prefix_list_compile(const char *arg
)
925 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
928 static void route_match_ip_route_source_prefix_list_free(void *rule
)
930 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
933 static const struct route_map_rule_cmd
934 route_match_ip_route_source_prefix_list_cmd
= {
935 "ip route-source prefix-list",
936 route_match_ip_route_source_prefix_list
,
937 route_match_ip_route_source_prefix_list_compile
,
938 route_match_ip_route_source_prefix_list_free
941 /* `match evpn default-route' */
943 /* Match function should return 1 if match is success else 0 */
944 static enum route_map_cmd_result_t
945 route_match_evpn_default_route(void *rule
, const struct prefix
*p
, void *object
)
947 if (is_evpn_prefix_default(p
))
953 /* Route map commands for default-route matching. */
954 static const struct route_map_rule_cmd
955 route_match_evpn_default_route_cmd
= {
956 "evpn default-route",
957 route_match_evpn_default_route
,
962 /* `match mac address MAC_ACCESS_LIST' */
964 /* Match function should return 1 if match is success else return
966 static enum route_map_cmd_result_t
967 route_match_mac_address(void *rule
, const struct prefix
*prefix
, void *object
)
969 struct access_list
*alist
;
972 alist
= access_list_lookup(AFI_L2VPN
, (char *)rule
);
974 if (CHECK_FLAG(rmap_debug
, DEBUG_ROUTEMAP_DETAIL
))
976 "%s: Access-List Specified: %s does not exist defaulting to NO_MATCH",
977 __func__
, (char *)rule
);
981 if (prefix
->u
.prefix_evpn
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
) {
982 if (CHECK_FLAG(rmap_debug
, DEBUG_ROUTEMAP_DETAIL
))
984 "%s: Prefix %pFX is not a EVPN MAC IP ROUTE defaulting to NO_MATCH",
989 p
.family
= AF_ETHERNET
;
990 p
.prefixlen
= ETH_ALEN
* 8;
991 p
.u
.prefix_eth
= prefix
->u
.prefix_evpn
.macip_addr
.mac
;
993 return (access_list_apply(alist
, &p
) == FILTER_DENY
? RMAP_NOMATCH
997 /* Route map `mac address' match statement. `arg' should be
999 static void *route_match_mac_address_compile(const char *arg
)
1001 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1004 /* Free route map's compiled `ip address' value. */
1005 static void route_match_mac_address_free(void *rule
)
1007 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1010 /* Route map commands for mac address matching. */
1011 static const struct route_map_rule_cmd route_match_mac_address_cmd
= {
1013 route_match_mac_address
,
1014 route_match_mac_address_compile
,
1015 route_match_mac_address_free
1019 * Match function returns:
1020 * ...RMAP_MATCH if match is found.
1021 * ...RMAP_NOMATCH if match is not found.
1022 * ...RMAP_NOOP to ignore this match check.
1024 static enum route_map_cmd_result_t
1025 route_match_vni(void *rule
, const struct prefix
*prefix
, void *object
)
1028 unsigned int label_cnt
= 0;
1029 struct bgp_path_info
*path
= NULL
;
1030 struct prefix_evpn
*evp
= (struct prefix_evpn
*) prefix
;
1032 vni
= *((vni_t
*)rule
);
1033 path
= (struct bgp_path_info
*)object
;
1036 * This rmap filter is valid for vxlan tunnel type only.
1037 * For any other tunnel type, return noop to ignore
1040 if (path
->attr
->encap_tunneltype
!= BGP_ENCAP_TYPE_VXLAN
)
1044 * Apply filter to type 1, 2, 5 routes only.
1045 * Other route types do not have vni label.
1048 && (evp
->prefix
.route_type
!= BGP_EVPN_AD_ROUTE
1049 && evp
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
1050 && evp
->prefix
.route_type
!= BGP_EVPN_IP_PREFIX_ROUTE
))
1053 if (path
->extra
== NULL
)
1054 return RMAP_NOMATCH
;
1057 label_cnt
< BGP_MAX_LABELS
&& label_cnt
< path
->extra
->num_labels
;
1059 if (vni
== label2vni(&path
->extra
->label
[label_cnt
]))
1063 return RMAP_NOMATCH
;
1066 /* Route map `vni' match statement. */
1067 static void *route_match_vni_compile(const char *arg
)
1072 vni
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(vni_t
));
1074 *vni
= strtoul(arg
, &end
, 10);
1076 XFREE(MTYPE_ROUTE_MAP_COMPILED
, vni
);
1083 /* Free route map's compiled `vni' value. */
1084 static void route_match_vni_free(void *rule
)
1086 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1089 /* Route map commands for vni matching. */
1090 static const struct route_map_rule_cmd route_match_evpn_vni_cmd
= {
1093 route_match_vni_compile
,
1094 route_match_vni_free
1097 /* `match evpn route-type' */
1099 /* Match function should return 1 if match is success else return
1101 static enum route_map_cmd_result_t
1102 route_match_evpn_route_type(void *rule
, const struct prefix
*pfx
, void *object
)
1104 uint8_t route_type
= 0;
1106 route_type
= *((uint8_t *)rule
);
1108 if (route_type
== pfx
->u
.prefix_evpn
.route_type
)
1111 return RMAP_NOMATCH
;
1114 /* Route map `route-type' match statement. */
1115 static void *route_match_evpn_route_type_compile(const char *arg
)
1117 uint8_t *route_type
= NULL
;
1119 route_type
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
1121 if (strncmp(arg
, "ea", 2) == 0)
1122 *route_type
= BGP_EVPN_AD_ROUTE
;
1123 else if (strncmp(arg
, "ma", 2) == 0)
1124 *route_type
= BGP_EVPN_MAC_IP_ROUTE
;
1125 else if (strncmp(arg
, "mu", 2) == 0)
1126 *route_type
= BGP_EVPN_IMET_ROUTE
;
1127 else if (strncmp(arg
, "es", 2) == 0)
1128 *route_type
= BGP_EVPN_ES_ROUTE
;
1130 *route_type
= BGP_EVPN_IP_PREFIX_ROUTE
;
1135 /* Free route map's compiled `route-type' value. */
1136 static void route_match_evpn_route_type_free(void *rule
)
1138 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1141 /* Route map commands for evpn route-type matching. */
1142 static const struct route_map_rule_cmd route_match_evpn_route_type_cmd
= {
1144 route_match_evpn_route_type
,
1145 route_match_evpn_route_type_compile
,
1146 route_match_evpn_route_type_free
1151 /* Match function should return 1 if match is success else return zero. */
1152 static enum route_map_cmd_result_t
1153 route_match_rd(void *rule
, const struct prefix
*prefix
, void *object
)
1155 struct prefix_rd
*prd_rule
= NULL
;
1156 const struct prefix_rd
*prd_route
= NULL
;
1157 struct bgp_path_info
*path
= NULL
;
1159 if (prefix
->family
!= AF_EVPN
)
1160 return RMAP_NOMATCH
;
1162 prd_rule
= (struct prefix_rd
*)rule
;
1163 path
= (struct bgp_path_info
*)object
;
1165 if (path
->net
== NULL
|| path
->net
->pdest
== NULL
)
1166 return RMAP_NOMATCH
;
1168 prd_route
= (struct prefix_rd
*)bgp_dest_get_prefix(path
->net
->pdest
);
1169 if (memcmp(prd_route
->val
, prd_rule
->val
, ECOMMUNITY_SIZE
) == 0)
1172 return RMAP_NOMATCH
;
1175 /* Route map `rd' match statement. */
1176 static void *route_match_rd_compile(const char *arg
)
1178 struct prefix_rd
*prd
;
1181 prd
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct prefix_rd
));
1183 ret
= str2prefix_rd(arg
, prd
);
1185 XFREE(MTYPE_ROUTE_MAP_COMPILED
, prd
);
1192 /* Free route map's compiled `rd' value. */
1193 static void route_match_rd_free(void *rule
)
1195 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1198 /* Route map commands for rd matching. */
1199 static const struct route_map_rule_cmd route_match_evpn_rd_cmd
= {
1202 route_match_rd_compile
,
1206 static enum route_map_cmd_result_t
1207 route_set_evpn_gateway_ip(void *rule
, const struct prefix
*prefix
, void *object
)
1209 struct ipaddr
*gw_ip
= rule
;
1210 struct bgp_path_info
*path
;
1211 struct prefix_evpn
*evp
;
1213 if (prefix
->family
!= AF_EVPN
)
1216 evp
= (struct prefix_evpn
*)prefix
;
1217 if (evp
->prefix
.route_type
!= BGP_EVPN_IP_PREFIX_ROUTE
)
1220 if ((is_evpn_prefix_ipaddr_v4(evp
) && IPADDRSZ(gw_ip
) != 4)
1221 || (is_evpn_prefix_ipaddr_v6(evp
) && IPADDRSZ(gw_ip
) != 16))
1226 /* Set gateway-ip value. */
1227 path
->attr
->evpn_overlay
.type
= OVERLAY_INDEX_GATEWAY_IP
;
1228 memcpy(&path
->attr
->evpn_overlay
.gw_ip
, &gw_ip
->ip
.addr
,
1235 * Route map `evpn gateway-ip' compile function.
1236 * Given string is converted to struct ipaddr structure
1238 static void *route_set_evpn_gateway_ip_compile(const char *arg
)
1240 struct ipaddr
*gw_ip
= NULL
;
1243 gw_ip
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct ipaddr
));
1245 ret
= str2ipaddr(arg
, gw_ip
);
1247 XFREE(MTYPE_ROUTE_MAP_COMPILED
, gw_ip
);
1253 /* Free route map's compiled `evpn gateway_ip' value. */
1254 static void route_set_evpn_gateway_ip_free(void *rule
)
1256 struct ipaddr
*gw_ip
= rule
;
1258 XFREE(MTYPE_ROUTE_MAP_COMPILED
, gw_ip
);
1261 /* Route map commands for set evpn gateway-ip ipv4. */
1262 struct route_map_rule_cmd route_set_evpn_gateway_ip_ipv4_cmd
= {
1263 "evpn gateway-ip ipv4", route_set_evpn_gateway_ip
,
1264 route_set_evpn_gateway_ip_compile
, route_set_evpn_gateway_ip_free
};
1266 /* Route map commands for set evpn gateway-ip ipv6. */
1267 struct route_map_rule_cmd route_set_evpn_gateway_ip_ipv6_cmd
= {
1268 "evpn gateway-ip ipv6", route_set_evpn_gateway_ip
,
1269 route_set_evpn_gateway_ip_compile
, route_set_evpn_gateway_ip_free
};
1271 /* Route map commands for VRF route leak with source vrf matching */
1272 static enum route_map_cmd_result_t
1273 route_match_vrl_source_vrf(void *rule
, const struct prefix
*prefix
,
1276 struct bgp_path_info
*path
;
1280 path
= (struct bgp_path_info
*)object
;
1282 if (strncmp(vrf_name
, "n/a", VRF_NAMSIZ
) == 0)
1283 return RMAP_NOMATCH
;
1285 if (path
->extra
== NULL
|| path
->extra
->bgp_orig
== NULL
)
1286 return RMAP_NOMATCH
;
1288 if (strncmp(vrf_name
, vrf_id_to_name(path
->extra
->bgp_orig
->vrf_id
),
1293 return RMAP_NOMATCH
;
1296 static void *route_match_vrl_source_vrf_compile(const char *arg
)
1298 uint8_t *vrf_name
= NULL
;
1300 vrf_name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1305 /* Free route map's compiled `route-type' value. */
1306 static void route_match_vrl_source_vrf_free(void *rule
)
1308 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1311 static const struct route_map_rule_cmd route_match_vrl_source_vrf_cmd
= {
1313 route_match_vrl_source_vrf
,
1314 route_match_vrl_source_vrf_compile
,
1315 route_match_vrl_source_vrf_free
1319 static enum route_map_cmd_result_t
1320 route_match_alias(void *rule
, const struct prefix
*prefix
, void *object
)
1323 struct bgp_path_info
*path
= object
;
1328 if (bgp_attr_get_community(path
->attr
)) {
1330 frrstr_split(bgp_attr_get_community(path
->attr
)->str
, " ",
1331 &communities
, &num
);
1332 for (int i
= 0; i
< num
; i
++) {
1333 const char *com2alias
=
1334 bgp_community2alias(communities
[i
]);
1335 if (!found
&& strcmp(alias
, com2alias
) == 0)
1337 XFREE(MTYPE_TMP
, communities
[i
]);
1339 XFREE(MTYPE_TMP
, communities
);
1344 if (bgp_attr_get_lcommunity(path
->attr
)) {
1346 frrstr_split(bgp_attr_get_lcommunity(path
->attr
)->str
, " ",
1347 &communities
, &num
);
1348 for (int i
= 0; i
< num
; i
++) {
1349 const char *com2alias
=
1350 bgp_community2alias(communities
[i
]);
1351 if (!found
&& strcmp(alias
, com2alias
) == 0)
1353 XFREE(MTYPE_TMP
, communities
[i
]);
1355 XFREE(MTYPE_TMP
, communities
);
1360 return RMAP_NOMATCH
;
1363 static void *route_match_alias_compile(const char *arg
)
1366 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1369 static void route_match_alias_free(void *rule
)
1371 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1374 static const struct route_map_rule_cmd route_match_alias_cmd
= {
1375 "alias", route_match_alias
, route_match_alias_compile
,
1376 route_match_alias_free
};
1378 /* `match local-preference LOCAL-PREF' */
1380 /* Match function return 1 if match is success else return zero. */
1381 static enum route_map_cmd_result_t
1382 route_match_local_pref(void *rule
, const struct prefix
*prefix
, void *object
)
1384 uint32_t *local_pref
;
1385 struct bgp_path_info
*path
;
1390 if (path
->attr
->local_pref
== *local_pref
)
1393 return RMAP_NOMATCH
;
1397 * Route map `match local-preference' match statement.
1398 * `arg' is local-pref value
1400 static void *route_match_local_pref_compile(const char *arg
)
1402 uint32_t *local_pref
;
1403 char *endptr
= NULL
;
1404 unsigned long tmpval
;
1406 /* Locpref value shoud be integer. */
1407 if (!all_digit(arg
))
1411 tmpval
= strtoul(arg
, &endptr
, 10);
1412 if (*endptr
!= '\0' || errno
|| tmpval
> UINT32_MAX
)
1415 local_pref
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint32_t));
1417 *local_pref
= tmpval
;
1421 /* Free route map's compiled `match local-preference' value. */
1422 static void route_match_local_pref_free(void *rule
)
1424 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1427 /* Route map commands for metric matching. */
1428 static const struct route_map_rule_cmd route_match_local_pref_cmd
= {
1430 route_match_local_pref
,
1431 route_match_local_pref_compile
,
1432 route_match_local_pref_free
1435 /* `match metric METRIC' */
1437 /* Match function return 1 if match is success else return zero. */
1438 static enum route_map_cmd_result_t
1439 route_match_metric(void *rule
, const struct prefix
*prefix
, void *object
)
1441 struct rmap_value
*rv
;
1442 struct bgp_path_info
*path
;
1446 return route_value_match(rv
, path
->attr
->med
);
1449 /* Route map commands for metric matching. */
1450 static const struct route_map_rule_cmd route_match_metric_cmd
= {
1453 route_value_compile
,
1457 /* `match as-path ASPATH' */
1459 /* Match function for as-path match. I assume given object is */
1460 static enum route_map_cmd_result_t
1461 route_match_aspath(void *rule
, const struct prefix
*prefix
, void *object
)
1464 struct as_list
*as_list
;
1465 struct bgp_path_info
*path
;
1467 as_list
= as_list_lookup((char *)rule
);
1468 if (as_list
== NULL
)
1469 return RMAP_NOMATCH
;
1473 /* Perform match. */
1474 return ((as_list_apply(as_list
, path
->attr
->aspath
) == AS_FILTER_DENY
)
1479 /* Compile function for as-path match. */
1480 static void *route_match_aspath_compile(const char *arg
)
1482 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1485 /* Compile function for as-path match. */
1486 static void route_match_aspath_free(void *rule
)
1488 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1491 /* Route map commands for aspath matching. */
1492 static const struct route_map_rule_cmd route_match_aspath_cmd
= {
1495 route_match_aspath_compile
,
1496 route_match_aspath_free
1499 /* `match community COMMUNIY' */
1500 struct rmap_community
{
1506 /* Match function for community match. */
1507 static enum route_map_cmd_result_t
1508 route_match_community(void *rule
, const struct prefix
*prefix
, void *object
)
1510 struct community_list
*list
;
1511 struct bgp_path_info
*path
;
1512 struct rmap_community
*rcom
= rule
;
1517 list
= community_list_lookup(bgp_clist
, rcom
->name
, rcom
->name_hash
,
1518 COMMUNITY_LIST_MASTER
);
1520 return RMAP_NOMATCH
;
1523 if (community_list_exact_match(
1524 bgp_attr_get_community(path
->attr
), list
))
1527 if (community_list_match(bgp_attr_get_community(path
->attr
),
1532 return RMAP_NOMATCH
;
1535 /* Compile function for community match. */
1536 static void *route_match_community_compile(const char *arg
)
1538 struct rmap_community
*rcom
;
1542 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1544 p
= strchr(arg
, ' ');
1547 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1548 memcpy(rcom
->name
, arg
, len
);
1551 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1555 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1559 /* Compile function for community match. */
1560 static void route_match_community_free(void *rule
)
1562 struct rmap_community
*rcom
= rule
;
1564 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1565 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1569 * In routemap processing there is a need to add the
1570 * name as a rule_key in the dependency table. Routemap
1571 * lib is unaware of rule_key when exact-match clause
1572 * is in use. routemap lib uses the compiled output to
1573 * get the rule_key value.
1575 static void *route_match_get_community_key(void *rule
)
1577 struct rmap_community
*rcom
;
1584 /* Route map commands for community matching. */
1585 static const struct route_map_rule_cmd route_match_community_cmd
= {
1587 route_match_community
,
1588 route_match_community_compile
,
1589 route_match_community_free
,
1590 route_match_get_community_key
1593 /* Match function for lcommunity match. */
1594 static enum route_map_cmd_result_t
1595 route_match_lcommunity(void *rule
, const struct prefix
*prefix
, void *object
)
1597 struct community_list
*list
;
1598 struct bgp_path_info
*path
;
1599 struct rmap_community
*rcom
= rule
;
1603 list
= community_list_lookup(bgp_clist
, rcom
->name
, rcom
->name_hash
,
1604 LARGE_COMMUNITY_LIST_MASTER
);
1606 return RMAP_NOMATCH
;
1609 if (lcommunity_list_exact_match(
1610 bgp_attr_get_lcommunity(path
->attr
), list
))
1613 if (lcommunity_list_match(bgp_attr_get_lcommunity(path
->attr
),
1618 return RMAP_NOMATCH
;
1621 /* Compile function for community match. */
1622 static void *route_match_lcommunity_compile(const char *arg
)
1624 struct rmap_community
*rcom
;
1628 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1630 p
= strchr(arg
, ' ');
1633 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1634 memcpy(rcom
->name
, arg
, len
);
1637 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1641 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1645 /* Compile function for community match. */
1646 static void route_match_lcommunity_free(void *rule
)
1648 struct rmap_community
*rcom
= rule
;
1650 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1651 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1654 /* Route map commands for community matching. */
1655 static const struct route_map_rule_cmd route_match_lcommunity_cmd
= {
1657 route_match_lcommunity
,
1658 route_match_lcommunity_compile
,
1659 route_match_lcommunity_free
,
1660 route_match_get_community_key
1664 /* Match function for extcommunity match. */
1665 static enum route_map_cmd_result_t
1666 route_match_ecommunity(void *rule
, const struct prefix
*prefix
, void *object
)
1668 struct community_list
*list
;
1669 struct bgp_path_info
*path
;
1670 struct rmap_community
*rcom
= rule
;
1674 list
= community_list_lookup(bgp_clist
, rcom
->name
, rcom
->name_hash
,
1675 EXTCOMMUNITY_LIST_MASTER
);
1677 return RMAP_NOMATCH
;
1679 if (ecommunity_list_match(bgp_attr_get_ecommunity(path
->attr
), list
))
1682 return RMAP_NOMATCH
;
1685 /* Compile function for extcommunity match. */
1686 static void *route_match_ecommunity_compile(const char *arg
)
1688 struct rmap_community
*rcom
;
1690 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1691 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1692 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1697 /* Compile function for extcommunity match. */
1698 static void route_match_ecommunity_free(void *rule
)
1700 struct rmap_community
*rcom
= rule
;
1702 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1703 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1706 /* Route map commands for community matching. */
1707 static const struct route_map_rule_cmd route_match_ecommunity_cmd
= {
1709 route_match_ecommunity
,
1710 route_match_ecommunity_compile
,
1711 route_match_ecommunity_free
1714 /* `match nlri` and `set nlri` are replaced by `address-family ipv4`
1715 and `address-family vpnv4'. */
1717 /* `match origin' */
1718 static enum route_map_cmd_result_t
1719 route_match_origin(void *rule
, const struct prefix
*prefix
, void *object
)
1722 struct bgp_path_info
*path
;
1727 if (path
->attr
->origin
== *origin
)
1730 return RMAP_NOMATCH
;
1733 static void *route_match_origin_compile(const char *arg
)
1737 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
1739 if (strcmp(arg
, "igp") == 0)
1741 else if (strcmp(arg
, "egp") == 0)
1749 /* Free route map's compiled `ip address' value. */
1750 static void route_match_origin_free(void *rule
)
1752 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1755 /* Route map commands for origin matching. */
1756 static const struct route_map_rule_cmd route_match_origin_cmd
= {
1759 route_match_origin_compile
,
1760 route_match_origin_free
1763 /* match probability { */
1765 static enum route_map_cmd_result_t
1766 route_match_probability(void *rule
, const struct prefix
*prefix
, void *object
)
1768 long r
= frr_weak_random();
1770 switch (*(long *)rule
) {
1776 if (r
< *(long *)rule
) {
1781 return RMAP_NOMATCH
;
1784 static void *route_match_probability_compile(const char *arg
)
1790 lobule
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(long));
1800 *lobule
= RAND_MAX
/ 100 * perc
;
1806 static void route_match_probability_free(void *rule
)
1808 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1811 static const struct route_map_rule_cmd route_match_probability_cmd
= {
1813 route_match_probability
,
1814 route_match_probability_compile
,
1815 route_match_probability_free
1818 /* `match interface IFNAME' */
1819 /* Match function should return 1 if match is success else return
1821 static enum route_map_cmd_result_t
1822 route_match_interface(void *rule
, const struct prefix
*prefix
, void *object
)
1824 struct interface
*ifp
;
1825 struct bgp_path_info
*path
;
1829 if (!path
|| !path
->peer
|| !path
->peer
->bgp
)
1830 return RMAP_NOMATCH
;
1832 ifp
= if_lookup_by_name((char *)rule
, path
->peer
->bgp
->vrf_id
);
1834 if (ifp
== NULL
|| ifp
->ifindex
!= path
->attr
->nh_ifindex
)
1835 return RMAP_NOMATCH
;
1840 /* Route map `interface' match statement. `arg' should be
1842 static void *route_match_interface_compile(const char *arg
)
1844 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1847 /* Free route map's compiled `interface' value. */
1848 static void route_match_interface_free(void *rule
)
1850 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1853 /* Route map commands for ip address matching. */
1854 static const struct route_map_rule_cmd route_match_interface_cmd
= {
1856 route_match_interface
,
1857 route_match_interface_compile
,
1858 route_match_interface_free
1863 /* `set ip next-hop IP_ADDRESS' */
1865 /* Match function return 1 if match is success else return zero. */
1866 static enum route_map_cmd_result_t
1867 route_match_tag(void *rule
, const struct prefix
*prefix
, void *object
)
1870 struct bgp_path_info
*path
;
1875 return ((path
->attr
->tag
== *tag
) ? RMAP_MATCH
: RMAP_NOMATCH
);
1879 /* Route map commands for tag matching. */
1880 static const struct route_map_rule_cmd route_match_tag_cmd
= {
1883 route_map_rule_tag_compile
,
1884 route_map_rule_tag_free
,
1887 static enum route_map_cmd_result_t
1888 route_set_srte_color(void *rule
, const struct prefix
*prefix
, void *object
)
1890 uint32_t *srte_color
= rule
;
1891 struct bgp_path_info
*path
;
1895 path
->attr
->srte_color
= *srte_color
;
1896 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_SRTE_COLOR
);
1901 /* Route map `sr-te color' compile function */
1902 static void *route_set_srte_color_compile(const char *arg
)
1906 color
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint32_t));
1912 /* Free route map's compiled `sr-te color' value. */
1913 static void route_set_srte_color_free(void *rule
)
1915 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1918 /* Route map commands for sr-te color set. */
1919 struct route_map_rule_cmd route_set_srte_color_cmd
= {
1920 "sr-te color", route_set_srte_color
, route_set_srte_color_compile
,
1921 route_set_srte_color_free
};
1923 /* Set nexthop to object. object must be pointer to struct attr. */
1924 struct rmap_ip_nexthop_set
{
1925 struct in_addr
*address
;
1930 static enum route_map_cmd_result_t
1931 route_set_ip_nexthop(void *rule
, const struct prefix
*prefix
, void *object
)
1933 struct rmap_ip_nexthop_set
*rins
= rule
;
1934 struct bgp_path_info
*path
;
1937 if (prefix
->family
== AF_INET6
)
1943 if (rins
->unchanged
) {
1944 SET_FLAG(path
->attr
->rmap_change_flags
,
1945 BATTR_RMAP_NEXTHOP_UNCHANGED
);
1946 } else if (rins
->peer_address
) {
1947 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
1948 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
1950 && sockunion_family(peer
->su_remote
) == AF_INET
) {
1951 path
->attr
->nexthop
.s_addr
=
1952 sockunion2ip(peer
->su_remote
);
1953 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1954 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
1955 /* The next hop value will be set as part of
1956 * packet rewrite. Set the flags here to indicate
1957 * that rewrite needs to be done.
1958 * Also, clear the value.
1960 SET_FLAG(path
->attr
->rmap_change_flags
,
1961 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
1962 path
->attr
->nexthop
.s_addr
= INADDR_ANY
;
1965 /* Set next hop value. */
1966 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1967 path
->attr
->nexthop
= *rins
->address
;
1968 SET_FLAG(path
->attr
->rmap_change_flags
,
1969 BATTR_RMAP_IPV4_NHOP_CHANGED
);
1970 /* case for MP-BGP : MPLS VPN */
1971 path
->attr
->mp_nexthop_global_in
= *rins
->address
;
1972 path
->attr
->mp_nexthop_len
= sizeof(*rins
->address
);
1978 /* Route map `ip nexthop' compile function. Given string is converted
1979 to struct in_addr structure. */
1980 static void *route_set_ip_nexthop_compile(const char *arg
)
1982 struct rmap_ip_nexthop_set
*rins
;
1983 struct in_addr
*address
= NULL
;
1984 int peer_address
= 0;
1988 if (strcmp(arg
, "peer-address") == 0)
1990 else if (strcmp(arg
, "unchanged") == 0)
1993 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1994 sizeof(struct in_addr
));
1995 ret
= inet_aton(arg
, address
);
1998 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2003 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
2004 sizeof(struct rmap_ip_nexthop_set
));
2006 rins
->address
= address
;
2007 rins
->peer_address
= peer_address
;
2008 rins
->unchanged
= unchanged
;
2013 /* Free route map's compiled `ip nexthop' value. */
2014 static void route_set_ip_nexthop_free(void *rule
)
2016 struct rmap_ip_nexthop_set
*rins
= rule
;
2018 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
->address
);
2020 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
);
2023 /* Route map commands for ip nexthop set. */
2024 static const struct route_map_rule_cmd route_set_ip_nexthop_cmd
= {
2026 route_set_ip_nexthop
,
2027 route_set_ip_nexthop_compile
,
2028 route_set_ip_nexthop_free
2031 /* `set l3vpn next-hop encapsulation l3vpn gre' */
2033 /* Set nexthop to object */
2034 struct rmap_l3vpn_nexthop_encapsulation_set
{
2038 static enum route_map_cmd_result_t
2039 route_set_l3vpn_nexthop_encapsulation(void *rule
, const struct prefix
*prefix
,
2042 struct rmap_l3vpn_nexthop_encapsulation_set
*rins
= rule
;
2043 struct bgp_path_info
*path
;
2047 if (rins
->protocol
!= IPPROTO_GRE
)
2050 SET_FLAG(path
->attr
->rmap_change_flags
, BATTR_RMAP_L3VPN_ACCEPT_GRE
);
2054 /* Route map `l3vpn nexthop encapsulation' compile function. */
2055 static void *route_set_l3vpn_nexthop_encapsulation_compile(const char *arg
)
2057 struct rmap_l3vpn_nexthop_encapsulation_set
*rins
;
2059 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
2060 sizeof(struct rmap_l3vpn_nexthop_encapsulation_set
));
2062 /* XXX ALL GRE modes are accepted for now: gre or ip6gre */
2063 rins
->protocol
= IPPROTO_GRE
;
2068 /* Free route map's compiled `ip nexthop' value. */
2069 static void route_set_l3vpn_nexthop_encapsulation_free(void *rule
)
2071 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2074 /* Route map commands for l3vpn next-hop encapsulation set. */
2075 static const struct route_map_rule_cmd
2076 route_set_l3vpn_nexthop_encapsulation_cmd
= {
2077 "l3vpn next-hop encapsulation",
2078 route_set_l3vpn_nexthop_encapsulation
,
2079 route_set_l3vpn_nexthop_encapsulation_compile
,
2080 route_set_l3vpn_nexthop_encapsulation_free
};
2082 /* `set local-preference LOCAL_PREF' */
2084 /* Set local preference. */
2085 static enum route_map_cmd_result_t
2086 route_set_local_pref(void *rule
, const struct prefix
*prefix
, void *object
)
2088 struct rmap_value
*rv
;
2089 struct bgp_path_info
*path
;
2090 uint32_t locpref
= 0;
2092 /* Fetch routemap's rule information. */
2096 /* Set local preference value. */
2097 if (path
->attr
->local_pref
)
2098 locpref
= path
->attr
->local_pref
;
2100 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
);
2101 path
->attr
->local_pref
= route_value_adjust(rv
, locpref
, path
->peer
);
2106 /* Set local preference rule structure. */
2107 static const struct route_map_rule_cmd route_set_local_pref_cmd
= {
2109 route_set_local_pref
,
2110 route_value_compile
,
2114 /* `set weight WEIGHT' */
2117 static enum route_map_cmd_result_t
2118 route_set_weight(void *rule
, const struct prefix
*prefix
, void *object
)
2120 struct rmap_value
*rv
;
2121 struct bgp_path_info
*path
;
2123 /* Fetch routemap's rule information. */
2127 /* Set weight value. */
2128 path
->attr
->weight
= route_value_adjust(rv
, 0, path
->peer
);
2133 /* Set local preference rule structure. */
2134 static const struct route_map_rule_cmd route_set_weight_cmd
= {
2137 route_value_compile
,
2141 /* `set distance DISTANCE */
2142 static enum route_map_cmd_result_t
2143 route_set_distance(void *rule
, const struct prefix
*prefix
, void *object
)
2145 struct bgp_path_info
*path
= object
;
2146 struct rmap_value
*rv
= rule
;
2148 path
->attr
->distance
= rv
->value
;
2153 /* set distance rule structure */
2154 static const struct route_map_rule_cmd route_set_distance_cmd
= {
2157 route_value_compile
,
2161 /* `set metric METRIC' */
2163 /* Set metric to attribute. */
2164 static enum route_map_cmd_result_t
2165 route_set_metric(void *rule
, const struct prefix
*prefix
, void *object
)
2167 struct rmap_value
*rv
;
2168 struct bgp_path_info
*path
;
2171 /* Fetch routemap's rule information. */
2175 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
))
2176 med
= path
->attr
->med
;
2178 path
->attr
->med
= route_value_adjust(rv
, med
, path
->peer
);
2179 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
);
2184 /* Set metric rule structure. */
2185 static const struct route_map_rule_cmd route_set_metric_cmd
= {
2188 route_value_compile
,
2192 /* `set table (1-4294967295)' */
2194 static enum route_map_cmd_result_t
2195 route_set_table_id(void *rule
, const struct prefix
*prefix
,
2199 struct rmap_value
*rv
;
2200 struct bgp_path_info
*path
;
2202 /* Fetch routemap's rule information. */
2206 path
->attr
->rmap_table_id
= rv
->value
;
2211 /* Set table_id rule structure. */
2212 static const struct route_map_rule_cmd route_set_table_id_cmd
= {
2215 route_value_compile
,
2219 /* `set as-path prepend ASPATH' */
2221 /* For AS path prepend mechanism. */
2222 static enum route_map_cmd_result_t
2223 route_set_aspath_prepend(void *rule
, const struct prefix
*prefix
, void *object
)
2225 struct aspath
*aspath
;
2227 struct bgp_path_info
*path
;
2231 if (path
->attr
->aspath
->refcnt
)
2232 new = aspath_dup(path
->attr
->aspath
);
2234 new = path
->attr
->aspath
;
2236 if ((uintptr_t)rule
> 10) {
2238 aspath_prepend(aspath
, new);
2240 as_t as
= aspath_leftmost(new);
2242 new = aspath_add_seq_n(new, as
, (uintptr_t)rule
);
2245 path
->attr
->aspath
= new;
2250 static void *route_set_aspath_prepend_compile(const char *arg
)
2254 if (sscanf(arg
, "last-as %u", &num
) == 1 && num
> 0 && num
<= 10)
2255 return (void *)(uintptr_t)num
;
2257 return route_aspath_compile(arg
);
2260 static void route_set_aspath_prepend_free(void *rule
)
2262 if ((uintptr_t)rule
> 10)
2263 route_aspath_free(rule
);
2267 /* Set as-path prepend rule structure. */
2268 static const struct route_map_rule_cmd route_set_aspath_prepend_cmd
= {
2270 route_set_aspath_prepend
,
2271 route_set_aspath_prepend_compile
,
2272 route_set_aspath_prepend_free
,
2275 /* `set as-path exclude ASn' */
2277 /* For ASN exclude mechanism.
2278 * Iterate over ASns requested and filter them from the given AS_PATH one by
2280 * Make a deep copy of existing AS_PATH, but for the first ASn only.
2282 static enum route_map_cmd_result_t
2283 route_set_aspath_exclude(void *rule
, const struct prefix
*dummy
, void *object
)
2285 struct aspath
*new_path
, *exclude_path
;
2286 struct bgp_path_info
*path
;
2288 exclude_path
= rule
;
2290 if (path
->attr
->aspath
->refcnt
)
2291 new_path
= aspath_dup(path
->attr
->aspath
);
2293 new_path
= path
->attr
->aspath
;
2294 path
->attr
->aspath
= aspath_filter_exclude(new_path
, exclude_path
);
2299 /* Set ASn exlude rule structure. */
2300 static const struct route_map_rule_cmd route_set_aspath_exclude_cmd
= {
2302 route_set_aspath_exclude
,
2303 route_aspath_compile
,
2307 /* `set as-path replace AS-PATH` */
2308 static void *route_aspath_replace_compile(const char *arg
)
2310 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2313 static void route_aspath_replace_free(void *rule
)
2315 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2318 static enum route_map_cmd_result_t
2319 route_set_aspath_replace(void *rule
, const struct prefix
*dummy
, void *object
)
2321 struct aspath
*aspath_new
;
2322 const char *replace
= rule
;
2323 struct bgp_path_info
*path
= object
;
2324 as_t own_asn
= path
->peer
->change_local_as
? path
->peer
->change_local_as
2325 : path
->peer
->local_as
;
2327 if (path
->peer
->sort
!= BGP_PEER_EBGP
) {
2329 "`set as-path replace` is supported only for EBGP peers");
2333 if (path
->attr
->aspath
->refcnt
)
2334 aspath_new
= aspath_dup(path
->attr
->aspath
);
2336 aspath_new
= path
->attr
->aspath
;
2338 if (strmatch(replace
, "any")) {
2339 path
->attr
->aspath
=
2340 aspath_replace_all_asn(aspath_new
, own_asn
);
2342 as_t replace_asn
= strtoul(replace
, NULL
, 10);
2344 path
->attr
->aspath
= aspath_replace_specific_asn(
2345 aspath_new
, replace_asn
, own_asn
);
2348 aspath_free(aspath_new
);
2353 static const struct route_map_rule_cmd route_set_aspath_replace_cmd
= {
2355 route_set_aspath_replace
,
2356 route_aspath_replace_compile
,
2357 route_aspath_replace_free
,
2360 /* `set community COMMUNITY' */
2361 struct rmap_com_set
{
2362 struct community
*com
;
2367 /* For community set mechanism. */
2368 static enum route_map_cmd_result_t
2369 route_set_community(void *rule
, const struct prefix
*prefix
, void *object
)
2371 struct rmap_com_set
*rcs
;
2372 struct bgp_path_info
*path
;
2374 struct community
*new = NULL
;
2375 struct community
*old
;
2376 struct community
*merge
;
2381 old
= bgp_attr_get_community(attr
);
2385 bgp_attr_set_community(attr
, NULL
);
2386 /* See the longer comment down below. */
2387 if (old
&& old
->refcnt
== 0)
2388 community_free(&old
);
2392 /* "additive" case. */
2393 if (rcs
->additive
&& old
) {
2394 merge
= community_merge(community_dup(old
), rcs
->com
);
2396 new = community_uniq_sort(merge
);
2397 community_free(&merge
);
2399 new = community_dup(rcs
->com
);
2401 /* HACK: if the old community is not intern'd,
2402 * we should free it here, or all reference to it may be
2404 * Really need to cleanup attribute caching sometime.
2406 if (old
&& old
->refcnt
== 0)
2407 community_free(&old
);
2409 /* will be interned by caller if required */
2410 bgp_attr_set_community(attr
, new);
2415 /* Compile function for set community. */
2416 static void *route_set_community_compile(const char *arg
)
2418 struct rmap_com_set
*rcs
;
2419 struct community
*com
= NULL
;
2424 if (strcmp(arg
, "none") == 0)
2427 sp
= strstr(arg
, "additive");
2429 if (sp
&& sp
> arg
) {
2430 /* "additive" keyword is included. */
2435 com
= community_str2com(arg
);
2444 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
2446 rcs
->additive
= additive
;
2452 /* Free function for set community. */
2453 static void route_set_community_free(void *rule
)
2455 struct rmap_com_set
*rcs
= rule
;
2458 community_free(&rcs
->com
);
2459 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
2462 /* Set community rule structure. */
2463 static const struct route_map_rule_cmd route_set_community_cmd
= {
2465 route_set_community
,
2466 route_set_community_compile
,
2467 route_set_community_free
,
2470 /* `set community COMMUNITY' */
2471 struct rmap_lcom_set
{
2472 struct lcommunity
*lcom
;
2478 /* For lcommunity set mechanism. */
2479 static enum route_map_cmd_result_t
2480 route_set_lcommunity(void *rule
, const struct prefix
*prefix
, void *object
)
2482 struct rmap_lcom_set
*rcs
;
2483 struct bgp_path_info
*path
;
2485 struct lcommunity
*new = NULL
;
2486 struct lcommunity
*old
;
2487 struct lcommunity
*merge
;
2492 old
= bgp_attr_get_lcommunity(attr
);
2496 bgp_attr_set_lcommunity(attr
, NULL
);
2498 /* See the longer comment down below. */
2499 if (old
&& old
->refcnt
== 0)
2500 lcommunity_free(&old
);
2504 if (rcs
->additive
&& old
) {
2505 merge
= lcommunity_merge(lcommunity_dup(old
), rcs
->lcom
);
2507 new = lcommunity_uniq_sort(merge
);
2508 lcommunity_free(&merge
);
2510 new = lcommunity_dup(rcs
->lcom
);
2512 /* HACK: if the old large-community is not intern'd,
2513 * we should free it here, or all reference to it may be
2515 * Really need to cleanup attribute caching sometime.
2517 if (old
&& old
->refcnt
== 0)
2518 lcommunity_free(&old
);
2520 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
2521 bgp_attr_set_lcommunity(attr
, new);
2526 /* Compile function for set community. */
2527 static void *route_set_lcommunity_compile(const char *arg
)
2529 struct rmap_lcom_set
*rcs
;
2530 struct lcommunity
*lcom
= NULL
;
2535 if (strcmp(arg
, "none") == 0)
2538 sp
= strstr(arg
, "additive");
2540 if (sp
&& sp
> arg
) {
2541 /* "additive" keyworkd is included. */
2546 lcom
= lcommunity_str2com(arg
);
2555 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
2557 rcs
->additive
= additive
;
2563 /* Free function for set lcommunity. */
2564 static void route_set_lcommunity_free(void *rule
)
2566 struct rmap_lcom_set
*rcs
= rule
;
2569 lcommunity_free(&rcs
->lcom
);
2571 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
2574 /* Set community rule structure. */
2575 static const struct route_map_rule_cmd route_set_lcommunity_cmd
= {
2577 route_set_lcommunity
,
2578 route_set_lcommunity_compile
,
2579 route_set_lcommunity_free
,
2582 /* `set large-comm-list (<1-99>|<100-500>|WORD) delete' */
2584 /* For large community set mechanism. */
2585 static enum route_map_cmd_result_t
2586 route_set_lcommunity_delete(void *rule
, const struct prefix
*pfx
, void *object
)
2588 struct community_list
*list
;
2589 struct lcommunity
*merge
;
2590 struct lcommunity
*new;
2591 struct lcommunity
*old
;
2592 struct bgp_path_info
*path
;
2593 struct rmap_community
*rcom
= rule
;
2599 list
= community_list_lookup(bgp_clist
, rcom
->name
, rcom
->name_hash
,
2600 LARGE_COMMUNITY_LIST_MASTER
);
2601 old
= bgp_attr_get_lcommunity(path
->attr
);
2604 merge
= lcommunity_list_match_delete(lcommunity_dup(old
), list
);
2605 new = lcommunity_uniq_sort(merge
);
2606 lcommunity_free(&merge
);
2608 /* HACK: if the old community is not intern'd,
2609 * we should free it here, or all reference to it may be
2611 * Really need to cleanup attribute caching sometime.
2613 if (old
->refcnt
== 0)
2614 lcommunity_free(&old
);
2616 if (new->size
== 0) {
2617 bgp_attr_set_lcommunity(path
->attr
, NULL
);
2618 lcommunity_free(&new);
2620 bgp_attr_set_lcommunity(path
->attr
, new);
2627 /* Compile function for set lcommunity. */
2628 static void *route_set_lcommunity_delete_compile(const char *arg
)
2630 struct rmap_community
*rcom
;
2634 frrstr_split(arg
, " ", &splits
, &num
);
2636 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2637 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, splits
[0]);
2638 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2640 for (int i
= 0; i
< num
; i
++)
2641 XFREE(MTYPE_TMP
, splits
[i
]);
2642 XFREE(MTYPE_TMP
, splits
);
2647 /* Free function for set lcommunity. */
2648 static void route_set_lcommunity_delete_free(void *rule
)
2650 struct rmap_community
*rcom
= rule
;
2652 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2653 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2656 /* Set lcommunity rule structure. */
2657 static const struct route_map_rule_cmd route_set_lcommunity_delete_cmd
= {
2659 route_set_lcommunity_delete
,
2660 route_set_lcommunity_delete_compile
,
2661 route_set_lcommunity_delete_free
,
2665 /* `set comm-list (<1-99>|<100-500>|WORD) delete' */
2667 /* For community set mechanism. */
2668 static enum route_map_cmd_result_t
2669 route_set_community_delete(void *rule
, const struct prefix
*prefix
,
2672 struct community_list
*list
;
2673 struct community
*merge
;
2674 struct community
*new;
2675 struct community
*old
;
2676 struct bgp_path_info
*path
;
2677 struct rmap_community
*rcom
= rule
;
2683 list
= community_list_lookup(bgp_clist
, rcom
->name
, rcom
->name_hash
,
2684 COMMUNITY_LIST_MASTER
);
2685 old
= bgp_attr_get_community(path
->attr
);
2688 merge
= community_list_match_delete(community_dup(old
), list
);
2689 new = community_uniq_sort(merge
);
2690 community_free(&merge
);
2692 /* HACK: if the old community is not intern'd,
2693 * we should free it here, or all reference to it may be
2695 * Really need to cleanup attribute caching sometime.
2697 if (old
->refcnt
== 0)
2698 community_free(&old
);
2700 if (new->size
== 0) {
2701 bgp_attr_set_community(path
->attr
, NULL
);
2702 community_free(&new);
2704 bgp_attr_set_community(path
->attr
, new);
2711 /* Compile function for set community. */
2712 static void *route_set_community_delete_compile(const char *arg
)
2714 struct rmap_community
*rcom
;
2718 frrstr_split(arg
, " ", &splits
, &num
);
2720 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2721 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, splits
[0]);
2722 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2724 for (int i
= 0; i
< num
; i
++)
2725 XFREE(MTYPE_TMP
, splits
[i
]);
2726 XFREE(MTYPE_TMP
, splits
);
2731 /* Free function for set community. */
2732 static void route_set_community_delete_free(void *rule
)
2734 struct rmap_community
*rcom
= rule
;
2736 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2737 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2740 /* Set community rule structure. */
2741 static const struct route_map_rule_cmd route_set_community_delete_cmd
= {
2743 route_set_community_delete
,
2744 route_set_community_delete_compile
,
2745 route_set_community_delete_free
,
2748 /* `set extcommunity rt COMMUNITY' */
2750 struct rmap_ecom_set
{
2751 struct ecommunity
*ecom
;
2755 /* For community set mechanism. Used by _rt and _soo. */
2756 static enum route_map_cmd_result_t
2757 route_set_ecommunity(void *rule
, const struct prefix
*prefix
, void *object
)
2759 struct rmap_ecom_set
*rcs
;
2760 struct ecommunity
*new_ecom
;
2761 struct ecommunity
*old_ecom
;
2762 struct bgp_path_info
*path
;
2770 bgp_attr_set_ecommunity(attr
, NULL
);
2777 /* We assume additive for Extended Community. */
2778 old_ecom
= bgp_attr_get_ecommunity(path
->attr
);
2782 ecommunity_merge(ecommunity_dup(old_ecom
), rcs
->ecom
);
2784 /* old_ecom->refcnt = 1 => owned elsewhere, e.g.
2785 * bgp_update_receive()
2786 * ->refcnt = 0 => set by a previous route-map
2788 if (!old_ecom
->refcnt
)
2789 ecommunity_free(&old_ecom
);
2791 new_ecom
= ecommunity_dup(rcs
->ecom
);
2793 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
2794 bgp_attr_set_ecommunity(path
->attr
, new_ecom
);
2799 static void *route_set_ecommunity_none_compile(const char *arg
)
2801 struct rmap_ecom_set
*rcs
;
2804 if (strncmp(arg
, "none", 4) == 0)
2807 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_ecom_set
));
2814 static void *route_set_ecommunity_rt_compile(const char *arg
)
2816 struct rmap_ecom_set
*rcs
;
2817 struct ecommunity
*ecom
;
2819 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_ROUTE_TARGET
, 0);
2823 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_ecom_set
));
2824 rcs
->ecom
= ecommunity_intern(ecom
);
2830 /* Free function for set community. Used by _rt and _soo */
2831 static void route_set_ecommunity_free(void *rule
)
2833 struct rmap_ecom_set
*rcs
= rule
;
2836 ecommunity_unintern(&rcs
->ecom
);
2838 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
2841 static const struct route_map_rule_cmd route_set_ecommunity_none_cmd
= {
2843 route_set_ecommunity
,
2844 route_set_ecommunity_none_compile
,
2845 route_set_ecommunity_free
,
2848 /* Set community rule structure. */
2849 static const struct route_map_rule_cmd route_set_ecommunity_rt_cmd
= {
2851 route_set_ecommunity
,
2852 route_set_ecommunity_rt_compile
,
2853 route_set_ecommunity_free
,
2856 /* `set extcommunity soo COMMUNITY' */
2858 /* Compile function for set community. */
2859 static void *route_set_ecommunity_soo_compile(const char *arg
)
2861 struct rmap_ecom_set
*rcs
;
2862 struct ecommunity
*ecom
;
2864 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_SITE_ORIGIN
, 0);
2868 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_ecom_set
));
2869 rcs
->ecom
= ecommunity_intern(ecom
);
2875 /* Set community rule structure. */
2876 static const struct route_map_rule_cmd route_set_ecommunity_soo_cmd
= {
2878 route_set_ecommunity
,
2879 route_set_ecommunity_soo_compile
,
2880 route_set_ecommunity_free
,
2883 /* `set extcommunity bandwidth' */
2885 struct rmap_ecomm_lb_set
{
2887 #define RMAP_ECOMM_LB_SET_VALUE 1
2888 #define RMAP_ECOMM_LB_SET_CUMUL 2
2889 #define RMAP_ECOMM_LB_SET_NUM_MPATH 3
2894 static enum route_map_cmd_result_t
2895 route_set_ecommunity_lb(void *rule
, const struct prefix
*prefix
, void *object
)
2897 struct rmap_ecomm_lb_set
*rels
= rule
;
2898 struct bgp_path_info
*path
;
2900 struct ecommunity ecom_lb
= {0};
2901 struct ecommunity_val lb_eval
;
2902 uint32_t bw_bytes
= 0;
2903 uint16_t mpath_count
= 0;
2904 struct ecommunity
*new_ecom
;
2905 struct ecommunity
*old_ecom
;
2910 if (!peer
|| !peer
->bgp
)
2913 /* Build link bandwidth extended community */
2914 as
= (peer
->bgp
->as
> BGP_AS_MAX
) ? BGP_AS_TRANS
: peer
->bgp
->as
;
2915 if (rels
->lb_type
== RMAP_ECOMM_LB_SET_VALUE
) {
2916 bw_bytes
= ((uint64_t)rels
->bw
* 1000 * 1000) / 8;
2917 } else if (rels
->lb_type
== RMAP_ECOMM_LB_SET_CUMUL
) {
2918 /* process this only for the best path. */
2919 if (!CHECK_FLAG(path
->flags
, BGP_PATH_SELECTED
))
2922 bw_bytes
= (uint32_t)bgp_path_info_mpath_cumbw(path
);
2926 } else if (rels
->lb_type
== RMAP_ECOMM_LB_SET_NUM_MPATH
) {
2928 /* process this only for the best path. */
2929 if (!CHECK_FLAG(path
->flags
, BGP_PATH_SELECTED
))
2932 bw_bytes
= ((uint64_t)peer
->bgp
->lb_ref_bw
* 1000 * 1000) / 8;
2933 mpath_count
= bgp_path_info_mpath_count(path
) + 1;
2934 bw_bytes
*= mpath_count
;
2937 encode_lb_extcomm(as
, bw_bytes
, rels
->non_trans
, &lb_eval
,
2938 CHECK_FLAG(peer
->flags
,
2939 PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE
));
2941 /* add to route or merge with existing */
2942 old_ecom
= bgp_attr_get_ecommunity(path
->attr
);
2944 new_ecom
= ecommunity_dup(old_ecom
);
2945 ecommunity_add_val(new_ecom
, &lb_eval
, true, true);
2946 if (!old_ecom
->refcnt
)
2947 ecommunity_free(&old_ecom
);
2950 ecom_lb
.unit_size
= ECOMMUNITY_SIZE
;
2951 ecom_lb
.val
= (uint8_t *)lb_eval
.val
;
2952 new_ecom
= ecommunity_dup(&ecom_lb
);
2955 /* new_ecom will be intern()'d or attr_flush()'d in call stack */
2956 bgp_attr_set_ecommunity(path
->attr
, new_ecom
);
2958 /* Mark that route-map has set link bandwidth; used in attribute
2959 * setting decisions.
2961 SET_FLAG(path
->attr
->rmap_change_flags
, BATTR_RMAP_LINK_BW_SET
);
2966 static void *route_set_ecommunity_lb_compile(const char *arg
)
2968 struct rmap_ecomm_lb_set
*rels
;
2971 char bw_str
[40] = {0};
2973 bool non_trans
= false;
2976 p
= strchr(arg
, ' ');
2981 memcpy(bw_str
, arg
, len
);
2986 if (strcmp(str
, "cumulative") == 0)
2987 lb_type
= RMAP_ECOMM_LB_SET_CUMUL
;
2988 else if (strcmp(str
, "num-multipaths") == 0)
2989 lb_type
= RMAP_ECOMM_LB_SET_NUM_MPATH
;
2993 bw
= strtoul(str
, &end
, 10);
2996 lb_type
= RMAP_ECOMM_LB_SET_VALUE
;
2999 rels
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
3000 sizeof(struct rmap_ecomm_lb_set
));
3001 rels
->lb_type
= lb_type
;
3003 rels
->non_trans
= non_trans
;
3008 static void route_set_ecommunity_lb_free(void *rule
)
3010 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3013 /* Set community rule structure. */
3014 struct route_map_rule_cmd route_set_ecommunity_lb_cmd
= {
3015 "extcommunity bandwidth",
3016 route_set_ecommunity_lb
,
3017 route_set_ecommunity_lb_compile
,
3018 route_set_ecommunity_lb_free
,
3021 /* `set origin ORIGIN' */
3023 /* For origin set. */
3024 static enum route_map_cmd_result_t
3025 route_set_origin(void *rule
, const struct prefix
*prefix
, void *object
)
3028 struct bgp_path_info
*path
;
3033 path
->attr
->origin
= *origin
;
3038 /* Compile function for origin set. */
3039 static void *route_set_origin_compile(const char *arg
)
3043 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
3045 if (strcmp(arg
, "igp") == 0)
3047 else if (strcmp(arg
, "egp") == 0)
3055 /* Compile function for origin set. */
3056 static void route_set_origin_free(void *rule
)
3058 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3061 /* Set origin rule structure. */
3062 static const struct route_map_rule_cmd route_set_origin_cmd
= {
3065 route_set_origin_compile
,
3066 route_set_origin_free
,
3069 /* `set atomic-aggregate' */
3071 /* For atomic aggregate set. */
3072 static enum route_map_cmd_result_t
3073 route_set_atomic_aggregate(void *rule
, const struct prefix
*pfx
, void *object
)
3075 struct bgp_path_info
*path
;
3078 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE
);
3083 /* Compile function for atomic aggregate. */
3084 static void *route_set_atomic_aggregate_compile(const char *arg
)
3089 /* Compile function for atomic aggregate. */
3090 static void route_set_atomic_aggregate_free(void *rule
)
3095 /* Set atomic aggregate rule structure. */
3096 static const struct route_map_rule_cmd route_set_atomic_aggregate_cmd
= {
3098 route_set_atomic_aggregate
,
3099 route_set_atomic_aggregate_compile
,
3100 route_set_atomic_aggregate_free
,
3103 /* AIGP TLV Metric */
3104 static enum route_map_cmd_result_t
3105 route_set_aigp_metric(void *rule
, const struct prefix
*pfx
, void *object
)
3107 const char *aigp_metric
= rule
;
3108 struct bgp_path_info
*path
= object
;
3111 if (strmatch(aigp_metric
, "igp-metric")) {
3113 return RMAP_NOMATCH
;
3115 bgp_attr_set_aigp_metric(path
->attr
, path
->nexthop
->metric
);
3117 aigp
= atoi(aigp_metric
);
3118 bgp_attr_set_aigp_metric(path
->attr
, aigp
);
3121 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_AIGP
);
3126 static void *route_set_aigp_metric_compile(const char *arg
)
3128 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
3131 static void route_set_aigp_metric_free(void *rule
)
3133 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3136 static const struct route_map_rule_cmd route_set_aigp_metric_cmd
= {
3138 route_set_aigp_metric
,
3139 route_set_aigp_metric_compile
,
3140 route_set_aigp_metric_free
,
3143 /* `set aggregator as AS A.B.C.D' */
3146 struct in_addr address
;
3149 static enum route_map_cmd_result_t
3150 route_set_aggregator_as(void *rule
, const struct prefix
*prefix
, void *object
)
3152 struct bgp_path_info
*path
;
3153 struct aggregator
*aggregator
;
3158 path
->attr
->aggregator_as
= aggregator
->as
;
3159 path
->attr
->aggregator_addr
= aggregator
->address
;
3160 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR
);
3165 static void *route_set_aggregator_as_compile(const char *arg
)
3167 struct aggregator
*aggregator
;
3173 XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct aggregator
));
3174 if (sscanf(arg
, "%s %s", as
, address
) != 2) {
3175 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
3179 aggregator
->as
= strtoul(as
, NULL
, 10);
3180 ret
= inet_aton(address
, &aggregator
->address
);
3182 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
3188 static void route_set_aggregator_as_free(void *rule
)
3190 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3193 static const struct route_map_rule_cmd route_set_aggregator_as_cmd
= {
3195 route_set_aggregator_as
,
3196 route_set_aggregator_as_compile
,
3197 route_set_aggregator_as_free
,
3200 /* Set tag to object. object must be pointer to struct bgp_path_info */
3201 static enum route_map_cmd_result_t
3202 route_set_tag(void *rule
, const struct prefix
*prefix
, void *object
)
3205 struct bgp_path_info
*path
;
3211 path
->attr
->tag
= *tag
;
3216 /* Route map commands for tag set. */
3217 static const struct route_map_rule_cmd route_set_tag_cmd
= {
3220 route_map_rule_tag_compile
,
3221 route_map_rule_tag_free
,
3224 /* Set label-index to object. object must be pointer to struct bgp_path_info */
3225 static enum route_map_cmd_result_t
3226 route_set_label_index(void *rule
, const struct prefix
*prefix
, void *object
)
3228 struct rmap_value
*rv
;
3229 struct bgp_path_info
*path
;
3230 uint32_t label_index
;
3232 /* Fetch routemap's rule information. */
3236 /* Set label-index value. */
3237 label_index
= rv
->value
;
3239 path
->attr
->label_index
= label_index
;
3240 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID
);
3246 /* Route map commands for label-index set. */
3247 static const struct route_map_rule_cmd route_set_label_index_cmd
= {
3249 route_set_label_index
,
3250 route_value_compile
,
3254 /* `match ipv6 address IP_ACCESS_LIST' */
3256 static enum route_map_cmd_result_t
3257 route_match_ipv6_address(void *rule
, const struct prefix
*prefix
, void *object
)
3259 struct access_list
*alist
;
3261 if (prefix
->family
== AF_INET6
) {
3262 alist
= access_list_lookup(AFI_IP6
, (char *)rule
);
3263 if (alist
== NULL
) {
3264 if (CHECK_FLAG(rmap_debug
, DEBUG_ROUTEMAP_DETAIL
))
3266 "%s: Access-List Specified: %s does not exist defaulting to NO_MATCH",
3267 __func__
, (char *)rule
);
3269 return RMAP_NOMATCH
;
3272 return (access_list_apply(alist
, prefix
) == FILTER_DENY
3276 return RMAP_NOMATCH
;
3279 static void *route_match_ipv6_address_compile(const char *arg
)
3281 struct access_list
*alist
;
3283 alist
= access_list_lookup(AFI_IP6
, arg
);
3286 "Access List specified %s does not exist yet, default will be NO_MATCH until it is created",
3289 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
3292 static void route_match_ipv6_address_free(void *rule
)
3294 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3297 /* Route map commands for ip address matching. */
3298 static const struct route_map_rule_cmd route_match_ipv6_address_cmd
= {
3300 route_match_ipv6_address
,
3301 route_match_ipv6_address_compile
,
3302 route_match_ipv6_address_free
3305 /* `match ipv6 next-hop ACCESSLIST6_NAME' */
3306 static enum route_map_cmd_result_t
3307 route_match_ipv6_next_hop(void *rule
, const struct prefix
*prefix
, void *object
)
3309 struct bgp_path_info
*path
;
3310 struct access_list
*alist
;
3311 struct prefix_ipv6 p
;
3313 if (prefix
->family
== AF_INET6
) {
3315 p
.family
= AF_INET6
;
3316 p
.prefix
= path
->attr
->mp_nexthop_global
;
3317 p
.prefixlen
= IPV6_MAX_BITLEN
;
3319 alist
= access_list_lookup(AFI_IP6
, (char *)rule
);
3321 if (CHECK_FLAG(rmap_debug
, DEBUG_ROUTEMAP_DETAIL
))
3323 "%s: Access-List Specified: %s does not exist defaulting to NO_MATCH",
3324 __func__
, (char *)rule
);
3326 return RMAP_NOMATCH
;
3329 if (access_list_apply(alist
, &p
) == FILTER_PERMIT
)
3332 if (path
->attr
->mp_nexthop_len
3333 == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
) {
3334 p
.prefix
= path
->attr
->mp_nexthop_local
;
3335 if (access_list_apply(alist
, &p
) == FILTER_PERMIT
)
3340 return RMAP_NOMATCH
;
3343 static void *route_match_ipv6_next_hop_compile(const char *arg
)
3345 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
3348 static void route_match_ipv6_next_hop_free(void *rule
)
3350 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3353 static const struct route_map_rule_cmd route_match_ipv6_next_hop_cmd
= {
3355 route_match_ipv6_next_hop
,
3356 route_match_ipv6_next_hop_compile
,
3357 route_match_ipv6_next_hop_free
3360 /* `match ipv6 next-hop IP_ADDRESS' */
3362 static enum route_map_cmd_result_t
3363 route_match_ipv6_next_hop_address(void *rule
, const struct prefix
*prefix
,
3366 struct in6_addr
*addr
= rule
;
3367 struct bgp_path_info
*path
;
3371 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
))
3374 if (path
->attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
3375 && IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_local
, rule
))
3378 return RMAP_NOMATCH
;
3381 static void *route_match_ipv6_next_hop_address_compile(const char *arg
)
3383 struct in6_addr
*address
;
3386 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3388 ret
= inet_pton(AF_INET6
, arg
, address
);
3390 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3397 static void route_match_ipv6_next_hop_address_free(void *rule
)
3399 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3402 static const struct route_map_rule_cmd route_match_ipv6_next_hop_address_cmd
= {
3403 "ipv6 next-hop address",
3404 route_match_ipv6_next_hop_address
,
3405 route_match_ipv6_next_hop_address_compile
,
3406 route_match_ipv6_next_hop_address_free
3409 /* `match ip next-hop address IP_ADDRESS' */
3411 static enum route_map_cmd_result_t
3412 route_match_ipv4_next_hop(void *rule
, const struct prefix
*prefix
, void *object
)
3414 struct in_addr
*addr
= rule
;
3415 struct bgp_path_info
*path
;
3419 if (path
->attr
->nexthop
.s_addr
== addr
->s_addr
3420 || (path
->attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV4
3421 && IPV4_ADDR_SAME(&path
->attr
->mp_nexthop_global_in
, addr
)))
3424 return RMAP_NOMATCH
;
3427 static void *route_match_ipv4_next_hop_compile(const char *arg
)
3429 struct in_addr
*address
;
3432 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3434 ret
= inet_pton(AF_INET
, arg
, address
);
3436 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3443 static void route_match_ipv4_next_hop_free(void *rule
)
3445 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3448 static const struct route_map_rule_cmd route_match_ipv4_next_hop_cmd
= {
3449 "ip next-hop address",
3450 route_match_ipv4_next_hop
,
3451 route_match_ipv4_next_hop_compile
,
3452 route_match_ipv4_next_hop_free
3455 /* `match ipv6 address prefix-list PREFIX_LIST' */
3457 static enum route_map_cmd_result_t
3458 route_match_ipv6_address_prefix_list(void *rule
, const struct prefix
*prefix
,
3461 return route_match_address_prefix_list(rule
, AFI_IP6
, prefix
, object
);
3464 static void *route_match_ipv6_address_prefix_list_compile(const char *arg
)
3466 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
3469 static void route_match_ipv6_address_prefix_list_free(void *rule
)
3471 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3474 static const struct route_map_rule_cmd
3475 route_match_ipv6_address_prefix_list_cmd
= {
3476 "ipv6 address prefix-list",
3477 route_match_ipv6_address_prefix_list
,
3478 route_match_ipv6_address_prefix_list_compile
,
3479 route_match_ipv6_address_prefix_list_free
3482 /* `match ipv6 next-hop type <TYPE>' */
3484 static enum route_map_cmd_result_t
3485 route_match_ipv6_next_hop_type(void *rule
, const struct prefix
*prefix
,
3488 struct bgp_path_info
*path
;
3489 struct in6_addr
*addr
= rule
;
3491 if (prefix
->family
== AF_INET6
) {
3492 path
= (struct bgp_path_info
*)object
;
3494 return RMAP_NOMATCH
;
3496 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
)
3497 && !path
->attr
->nh_ifindex
)
3501 return RMAP_NOMATCH
;
3504 static void *route_match_ipv6_next_hop_type_compile(const char *arg
)
3506 struct in6_addr
*address
;
3509 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3511 ret
= inet_pton(AF_INET6
, "::0", address
);
3513 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3520 static void route_match_ipv6_next_hop_type_free(void *rule
)
3522 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3525 static const struct route_map_rule_cmd
3526 route_match_ipv6_next_hop_type_cmd
= {
3527 "ipv6 next-hop type",
3528 route_match_ipv6_next_hop_type
,
3529 route_match_ipv6_next_hop_type_compile
,
3530 route_match_ipv6_next_hop_type_free
3533 /* `set ipv6 nexthop global IP_ADDRESS' */
3535 /* Set nexthop to object. object must be pointer to struct attr. */
3536 static enum route_map_cmd_result_t
3537 route_set_ipv6_nexthop_global(void *rule
, const struct prefix
*p
, void *object
)
3539 struct in6_addr
*address
;
3540 struct bgp_path_info
*path
;
3542 /* Fetch routemap's rule information. */
3546 /* Set next hop value. */
3547 path
->attr
->mp_nexthop_global
= *address
;
3549 /* Set nexthop length. */
3550 if (path
->attr
->mp_nexthop_len
== 0)
3551 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL
;
3553 SET_FLAG(path
->attr
->rmap_change_flags
,
3554 BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED
);
3559 /* Route map `ip next-hop' compile function. Given string is converted
3560 to struct in_addr structure. */
3561 static void *route_set_ipv6_nexthop_global_compile(const char *arg
)
3564 struct in6_addr
*address
;
3566 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3568 ret
= inet_pton(AF_INET6
, arg
, address
);
3571 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3578 /* Free route map's compiled `ip next-hop' value. */
3579 static void route_set_ipv6_nexthop_global_free(void *rule
)
3581 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3584 /* Route map commands for ip nexthop set. */
3585 static const struct route_map_rule_cmd
3586 route_set_ipv6_nexthop_global_cmd
= {
3587 "ipv6 next-hop global",
3588 route_set_ipv6_nexthop_global
,
3589 route_set_ipv6_nexthop_global_compile
,
3590 route_set_ipv6_nexthop_global_free
3593 /* Set next-hop preference value. */
3594 static enum route_map_cmd_result_t
3595 route_set_ipv6_nexthop_prefer_global(void *rule
, const struct prefix
*prefix
,
3598 struct bgp_path_info
*path
;
3601 /* Fetch routemap's rule information. */
3605 if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
3606 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
)) {
3607 /* Set next hop preference to global */
3608 path
->attr
->mp_nexthop_prefer_global
= true;
3609 SET_FLAG(path
->attr
->rmap_change_flags
,
3610 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
3612 path
->attr
->mp_nexthop_prefer_global
= false;
3613 SET_FLAG(path
->attr
->rmap_change_flags
,
3614 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
3620 static void *route_set_ipv6_nexthop_prefer_global_compile(const char *arg
)
3624 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
3630 /* Free route map's compiled `ip next-hop' value. */
3631 static void route_set_ipv6_nexthop_prefer_global_free(void *rule
)
3633 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3636 /* Route map commands for ip nexthop set preferred. */
3637 static const struct route_map_rule_cmd
3638 route_set_ipv6_nexthop_prefer_global_cmd
= {
3639 "ipv6 next-hop prefer-global",
3640 route_set_ipv6_nexthop_prefer_global
,
3641 route_set_ipv6_nexthop_prefer_global_compile
,
3642 route_set_ipv6_nexthop_prefer_global_free
3645 /* `set ipv6 nexthop local IP_ADDRESS' */
3647 /* Set nexthop to object. object must be pointer to struct attr. */
3648 static enum route_map_cmd_result_t
3649 route_set_ipv6_nexthop_local(void *rule
, const struct prefix
*p
, void *object
)
3651 struct in6_addr
*address
;
3652 struct bgp_path_info
*path
;
3654 /* Fetch routemap's rule information. */
3658 /* Set next hop value. */
3659 path
->attr
->mp_nexthop_local
= *address
;
3661 /* Set nexthop length. */
3662 if (path
->attr
->mp_nexthop_len
!= BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
&&
3663 path
->attr
->mp_nexthop_len
!= BGP_ATTR_NHLEN_VPNV6_GLOBAL_AND_LL
)
3664 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
3666 SET_FLAG(path
->attr
->rmap_change_flags
,
3667 BATTR_RMAP_IPV6_LL_NHOP_CHANGED
);
3672 /* Route map `ip nexthop' compile function. Given string is converted
3673 to struct in_addr structure. */
3674 static void *route_set_ipv6_nexthop_local_compile(const char *arg
)
3677 struct in6_addr
*address
;
3679 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3681 ret
= inet_pton(AF_INET6
, arg
, address
);
3684 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3691 /* Free route map's compiled `ip nexthop' value. */
3692 static void route_set_ipv6_nexthop_local_free(void *rule
)
3694 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3697 /* Route map commands for ip nexthop set. */
3698 static const struct route_map_rule_cmd
3699 route_set_ipv6_nexthop_local_cmd
= {
3700 "ipv6 next-hop local",
3701 route_set_ipv6_nexthop_local
,
3702 route_set_ipv6_nexthop_local_compile
,
3703 route_set_ipv6_nexthop_local_free
3706 /* `set ipv6 nexthop peer-address' */
3708 /* Set nexthop to object. object must be pointer to struct attr. */
3709 static enum route_map_cmd_result_t
3710 route_set_ipv6_nexthop_peer(void *rule
, const struct prefix
*pfx
, void *object
)
3712 struct in6_addr peer_address
;
3713 struct bgp_path_info
*path
;
3716 /* Fetch routemap's rule information. */
3720 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
3721 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
3723 && sockunion_family(peer
->su_remote
) == AF_INET6
) {
3724 peer_address
= peer
->su_remote
->sin6
.sin6_addr
;
3725 /* Set next hop value and length in attribute. */
3726 if (IN6_IS_ADDR_LINKLOCAL(&peer_address
)) {
3727 path
->attr
->mp_nexthop_local
= peer_address
;
3728 if (path
->attr
->mp_nexthop_len
3729 != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
3730 path
->attr
->mp_nexthop_len
=
3731 BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
3733 path
->attr
->mp_nexthop_global
= peer_address
;
3734 if (path
->attr
->mp_nexthop_len
== 0)
3735 path
->attr
->mp_nexthop_len
=
3736 BGP_ATTR_NHLEN_IPV6_GLOBAL
;
3739 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
3740 /* The next hop value will be set as part of packet
3742 * Set the flags here to indicate that rewrite needs to
3744 * Also, clear the value - we clear both global and
3746 * nexthops, whether we send one or both is determined
3749 SET_FLAG(path
->attr
->rmap_change_flags
,
3750 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
3751 /* clear next hop value. */
3752 memset(&(path
->attr
->mp_nexthop_global
), 0,
3753 sizeof(struct in6_addr
));
3754 memset(&(path
->attr
->mp_nexthop_local
), 0,
3755 sizeof(struct in6_addr
));
3761 /* Route map `ip next-hop' compile function. Given string is converted
3762 to struct in_addr structure. */
3763 static void *route_set_ipv6_nexthop_peer_compile(const char *arg
)
3767 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
3773 /* Free route map's compiled `ip next-hop' value. */
3774 static void route_set_ipv6_nexthop_peer_free(void *rule
)
3776 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3779 /* Route map commands for ip nexthop set. */
3780 static const struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd
= {
3781 "ipv6 next-hop peer-address",
3782 route_set_ipv6_nexthop_peer
,
3783 route_set_ipv6_nexthop_peer_compile
,
3784 route_set_ipv6_nexthop_peer_free
3787 /* `set ipv4 vpn next-hop A.B.C.D' */
3789 static enum route_map_cmd_result_t
3790 route_set_vpnv4_nexthop(void *rule
, const struct prefix
*prefix
, void *object
)
3792 struct in_addr
*address
;
3793 struct bgp_path_info
*path
;
3795 /* Fetch routemap's rule information. */
3799 /* Set next hop value. */
3800 path
->attr
->mp_nexthop_global_in
= *address
;
3801 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV4
;
3803 SET_FLAG(path
->attr
->rmap_change_flags
, BATTR_RMAP_VPNV4_NHOP_CHANGED
);
3808 static void *route_set_vpnv4_nexthop_compile(const char *arg
)
3811 struct in_addr
*address
;
3813 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3815 ret
= inet_aton(arg
, address
);
3818 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3825 /* `set ipv6 vpn next-hop A.B.C.D' */
3827 static enum route_map_cmd_result_t
3828 route_set_vpnv6_nexthop(void *rule
, const struct prefix
*prefix
, void *object
)
3830 struct in6_addr
*address
;
3831 struct bgp_path_info
*path
;
3833 /* Fetch routemap's rule information. */
3837 /* Set next hop value. */
3838 memcpy(&path
->attr
->mp_nexthop_global
, address
,
3839 sizeof(struct in6_addr
));
3840 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_VPNV6_GLOBAL
;
3842 SET_FLAG(path
->attr
->rmap_change_flags
,
3843 BATTR_RMAP_VPNV6_GLOBAL_NHOP_CHANGED
);
3848 static void *route_set_vpnv6_nexthop_compile(const char *arg
)
3851 struct in6_addr
*address
;
3853 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3854 ret
= inet_pton(AF_INET6
, arg
, address
);
3857 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3864 static void route_set_vpn_nexthop_free(void *rule
)
3866 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3869 /* Route map commands for ipv4 next-hop set. */
3870 static const struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd
= {
3871 "ipv4 vpn next-hop",
3872 route_set_vpnv4_nexthop
,
3873 route_set_vpnv4_nexthop_compile
,
3874 route_set_vpn_nexthop_free
3877 /* Route map commands for ipv6 next-hop set. */
3878 static const struct route_map_rule_cmd route_set_vpnv6_nexthop_cmd
= {
3879 "ipv6 vpn next-hop",
3880 route_set_vpnv6_nexthop
,
3881 route_set_vpnv6_nexthop_compile
,
3882 route_set_vpn_nexthop_free
3885 /* `set originator-id' */
3887 /* For origin set. */
3888 static enum route_map_cmd_result_t
3889 route_set_originator_id(void *rule
, const struct prefix
*prefix
, void *object
)
3891 struct in_addr
*address
;
3892 struct bgp_path_info
*path
;
3897 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
);
3898 path
->attr
->originator_id
= *address
;
3903 /* Compile function for originator-id set. */
3904 static void *route_set_originator_id_compile(const char *arg
)
3907 struct in_addr
*address
;
3909 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3911 ret
= inet_aton(arg
, address
);
3914 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3921 /* Compile function for originator_id set. */
3922 static void route_set_originator_id_free(void *rule
)
3924 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3927 /* Set originator-id rule structure. */
3928 static const struct route_map_rule_cmd route_set_originator_id_cmd
= {
3930 route_set_originator_id
,
3931 route_set_originator_id_compile
,
3932 route_set_originator_id_free
,
3935 static enum route_map_cmd_result_t
3936 route_match_rpki_extcommunity(void *rule
, const struct prefix
*prefix
,
3939 struct bgp_path_info
*path
;
3940 struct ecommunity
*ecomm
;
3941 struct ecommunity_val
*ecomm_val
;
3942 enum rpki_states
*rpki_status
= rule
;
3943 enum rpki_states ecomm_rpki_status
= RPKI_NOT_BEING_USED
;
3947 ecomm
= bgp_attr_get_ecommunity(path
->attr
);
3949 return RMAP_NOMATCH
;
3951 ecomm_val
= ecommunity_lookup(ecomm
, ECOMMUNITY_ENCODE_OPAQUE_NON_TRANS
,
3952 ECOMMUNITY_ORIGIN_VALIDATION_STATE
);
3954 return RMAP_NOMATCH
;
3956 /* The Origin Validation State is encoded in the last octet of
3957 * the extended community.
3959 switch (ecomm_val
->val
[7]) {
3960 case ECOMMUNITY_ORIGIN_VALIDATION_STATE_VALID
:
3961 ecomm_rpki_status
= RPKI_VALID
;
3963 case ECOMMUNITY_ORIGIN_VALIDATION_STATE_NOTFOUND
:
3964 ecomm_rpki_status
= RPKI_NOTFOUND
;
3966 case ECOMMUNITY_ORIGIN_VALIDATION_STATE_INVALID
:
3967 ecomm_rpki_status
= RPKI_INVALID
;
3969 case ECOMMUNITY_ORIGIN_VALIDATION_STATE_NOTUSED
:
3973 if (ecomm_rpki_status
== *rpki_status
)
3976 return RMAP_NOMATCH
;
3979 static void *route_match_extcommunity_compile(const char *arg
)
3983 rpki_status
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
3985 if (strcmp(arg
, "valid") == 0)
3986 *rpki_status
= RPKI_VALID
;
3987 else if (strcmp(arg
, "invalid") == 0)
3988 *rpki_status
= RPKI_INVALID
;
3990 *rpki_status
= RPKI_NOTFOUND
;
3995 static const struct route_map_rule_cmd route_match_rpki_extcommunity_cmd
= {
3996 "rpki-extcommunity",
3997 route_match_rpki_extcommunity
,
3998 route_match_extcommunity_compile
,
4003 * This is the workhorse routine for processing in/out routemap
4006 static void bgp_route_map_process_peer(const char *rmap_name
,
4007 struct route_map
*map
, struct peer
*peer
,
4008 int afi
, int safi
, int route_update
)
4010 struct bgp_filter
*filter
;
4012 if (!peer
|| !rmap_name
)
4015 filter
= &peer
->filter
[afi
][safi
];
4017 * in is for non-route-server clients,
4018 * out is for all peers
4020 if (filter
->map
[RMAP_IN
].name
4021 && (strcmp(rmap_name
, filter
->map
[RMAP_IN
].name
) == 0)) {
4022 filter
->map
[RMAP_IN
].map
= map
;
4024 if (route_update
&& peer_established(peer
)) {
4025 if (CHECK_FLAG(peer
->af_flags
[afi
][safi
],
4026 PEER_FLAG_SOFT_RECONFIG
)) {
4027 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
4029 "Processing route_map %s(%s:%s) update on peer %s (inbound, soft-reconfig)",
4030 rmap_name
, afi2str(afi
),
4031 safi2str(safi
), peer
->host
);
4033 bgp_soft_reconfig_in(peer
, afi
, safi
);
4034 } else if (CHECK_FLAG(peer
->cap
,
4035 PEER_CAP_REFRESH_OLD_RCV
)
4036 || CHECK_FLAG(peer
->cap
,
4037 PEER_CAP_REFRESH_NEW_RCV
)) {
4038 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
4040 "Processing route_map %s(%s:%s) update on peer %s (inbound, route-refresh)",
4041 rmap_name
, afi2str(afi
),
4042 safi2str(safi
), peer
->host
);
4043 bgp_route_refresh_send(
4044 peer
, afi
, safi
, 0, 0, 0,
4045 BGP_ROUTE_REFRESH_NORMAL
);
4051 * For outbound, unsuppress and default-originate map change (content or
4052 * map created), merely update the "config" here, the actual route
4053 * announcement happens at the group level.
4055 if (filter
->map
[RMAP_OUT
].name
4056 && (strcmp(rmap_name
, filter
->map
[RMAP_OUT
].name
) == 0))
4057 filter
->map
[RMAP_OUT
].map
= map
;
4059 if (filter
->usmap
.name
&& (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
4060 filter
->usmap
.map
= map
;
4062 if (filter
->advmap
.aname
4063 && (strcmp(rmap_name
, filter
->advmap
.aname
) == 0)) {
4064 filter
->advmap
.amap
= map
;
4067 if (filter
->advmap
.cname
4068 && (strcmp(rmap_name
, filter
->advmap
.cname
) == 0)) {
4069 filter
->advmap
.cmap
= map
;
4072 if (peer
->default_rmap
[afi
][safi
].name
4073 && (strcmp(rmap_name
, peer
->default_rmap
[afi
][safi
].name
) == 0))
4074 peer
->default_rmap
[afi
][safi
].map
= map
;
4076 /* Notify BGP conditional advertisement scanner percess */
4077 peer
->advmap_config_change
[afi
][safi
] = true;
4080 static void bgp_route_map_update_peer_group(const char *rmap_name
,
4081 struct route_map
*map
,
4084 struct peer_group
*group
;
4085 struct listnode
*node
, *nnode
;
4086 struct bgp_filter
*filter
;
4093 /* All the peers have been updated correctly already. This is
4094 * just updating the placeholder data. No real update required.
4096 for (ALL_LIST_ELEMENTS(bgp
->group
, node
, nnode
, group
)) {
4097 FOREACH_AFI_SAFI (afi
, safi
) {
4098 filter
= &group
->conf
->filter
[afi
][safi
];
4100 for (direct
= RMAP_IN
; direct
< RMAP_MAX
; direct
++) {
4101 if ((filter
->map
[direct
].name
)
4102 && (strcmp(rmap_name
,
4103 filter
->map
[direct
].name
)
4105 filter
->map
[direct
].map
= map
;
4108 if (filter
->usmap
.name
4109 && (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
4110 filter
->usmap
.map
= map
;
4112 if (filter
->advmap
.aname
&&
4113 (strcmp(rmap_name
, filter
->advmap
.aname
) == 0))
4114 filter
->advmap
.amap
= map
;
4116 if (filter
->advmap
.cname
&&
4117 (strcmp(rmap_name
, filter
->advmap
.cname
) == 0))
4118 filter
->advmap
.cmap
= map
;
4124 * Note that if an extreme number (tens of thousands) of route-maps are in use
4125 * and if bgp has an extreme number of peers, network statements, etc then this
4126 * function can consume a lot of cycles. This is due to this function being
4127 * called for each route-map and within this function we walk the list of peers,
4128 * network statements, etc looking to see if they use this route-map.
4130 static void bgp_route_map_process_update(struct bgp
*bgp
, const char *rmap_name
,
4138 struct bgp_dest
*bn
;
4139 struct bgp_static
*bgp_static
;
4140 struct bgp_aggregate
*aggregate
;
4141 struct listnode
*node
, *nnode
;
4142 struct route_map
*map
;
4143 char buf
[INET6_ADDRSTRLEN
];
4145 map
= route_map_lookup_by_name(rmap_name
);
4147 for (ALL_LIST_ELEMENTS(bgp
->peer
, node
, nnode
, peer
)) {
4149 /* Ignore dummy peer-group structure */
4150 if (CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
))
4153 FOREACH_AFI_SAFI (afi
, safi
) {
4154 /* process in/out/import/export/default-orig
4156 bgp_route_map_process_peer(rmap_name
, map
, peer
, afi
,
4157 safi
, route_update
);
4161 /* for outbound/default-orig route-maps, process for groups */
4162 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
, rmap_name
,
4165 /* update peer-group config (template) */
4166 bgp_route_map_update_peer_group(rmap_name
, map
, bgp
);
4168 FOREACH_AFI_SAFI (afi
, safi
) {
4169 /* For table route-map updates. */
4170 if (!bgp_fibupd_safi(safi
))
4173 if (bgp
->table_map
[afi
][safi
].name
4174 && (strcmp(rmap_name
, bgp
->table_map
[afi
][safi
].name
)
4177 /* bgp->table_map[afi][safi].map is NULL.
4178 * i.e Route map creation event.
4179 * So update applied_counter.
4180 * If it is not NULL, i.e It may be routemap updation or
4181 * deletion. so no need to update the counter.
4183 if (!bgp
->table_map
[afi
][safi
].map
)
4184 route_map_counter_increment(map
);
4185 bgp
->table_map
[afi
][safi
].map
= map
;
4187 if (BGP_DEBUG(zebra
, ZEBRA
))
4189 "Processing route_map %s(%s:%s) update on table map",
4190 rmap_name
, afi2str(afi
),
4193 bgp_zebra_announce_table(bgp
, afi
, safi
);
4196 /* For network route-map updates. */
4197 for (bn
= bgp_table_top(bgp
->route
[afi
][safi
]); bn
;
4198 bn
= bgp_route_next(bn
)) {
4199 bgp_static
= bgp_dest_get_bgp_static_info(bn
);
4203 if (!bgp_static
->rmap
.name
4204 || (strcmp(rmap_name
, bgp_static
->rmap
.name
) != 0))
4207 if (!bgp_static
->rmap
.map
)
4208 route_map_counter_increment(map
);
4210 bgp_static
->rmap
.map
= map
;
4212 if (route_update
&& !bgp_static
->backdoor
) {
4213 const struct prefix
*bn_p
=
4214 bgp_dest_get_prefix(bn
);
4216 if (bgp_debug_zebra(bn_p
))
4218 "Processing route_map %s(%s:%s) update on static route %s",
4219 rmap_name
, afi2str(afi
),
4221 inet_ntop(bn_p
->family
,
4222 &bn_p
->u
.prefix
, buf
,
4224 bgp_static_update(bgp
, bn_p
, bgp_static
, afi
,
4229 /* For aggregate-address route-map updates. */
4230 for (bn
= bgp_table_top(bgp
->aggregate
[afi
][safi
]); bn
;
4231 bn
= bgp_route_next(bn
)) {
4232 aggregate
= bgp_dest_get_bgp_aggregate_info(bn
);
4238 /* Update suppress map pointer. */
4239 if (aggregate
->suppress_map_name
4240 && strmatch(aggregate
->suppress_map_name
,
4242 if (aggregate
->rmap
.map
== NULL
)
4243 route_map_counter_increment(map
);
4245 aggregate
->suppress_map
= map
;
4247 bgp_aggregate_toggle_suppressed(
4248 aggregate
, bgp
, bgp_dest_get_prefix(bn
),
4254 if (aggregate
->rmap
.name
4255 && strmatch(rmap_name
, aggregate
->rmap
.name
)) {
4256 if (aggregate
->rmap
.map
== NULL
)
4257 route_map_counter_increment(map
);
4259 aggregate
->rmap
.map
= map
;
4264 if (matched
&& route_update
) {
4265 const struct prefix
*bn_p
=
4266 bgp_dest_get_prefix(bn
);
4268 if (bgp_debug_zebra(bn_p
))
4270 "Processing route_map %s(%s:%s) update on aggregate-address route %s",
4271 rmap_name
, afi2str(afi
),
4273 inet_ntop(bn_p
->family
,
4274 &bn_p
->u
.prefix
, buf
,
4276 bgp_aggregate_route(bgp
, bn_p
, afi
, safi
,
4282 /* For redistribute route-map updates. */
4283 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
4284 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
4285 struct list
*red_list
;
4286 struct bgp_redist
*red
;
4288 red_list
= bgp
->redist
[afi
][i
];
4292 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
4294 || (strcmp(rmap_name
, red
->rmap
.name
) != 0))
4298 route_map_counter_increment(map
);
4300 red
->rmap
.map
= map
;
4305 if (BGP_DEBUG(zebra
, ZEBRA
))
4307 "Processing route_map %s(%s:%s) update on redistributed routes",
4308 rmap_name
, afi2str(afi
),
4311 bgp_redistribute_resend(bgp
, afi
, i
,
4316 /* for type5 command route-maps */
4317 FOREACH_AFI_SAFI (afi
, safi
) {
4318 if (!bgp
->adv_cmd_rmap
[afi
][safi
].name
4319 || strcmp(rmap_name
, bgp
->adv_cmd_rmap
[afi
][safi
].name
)
4323 /* Make sure the route-map is populated here if not already done */
4324 bgp
->adv_cmd_rmap
[afi
][safi
].map
= map
;
4326 if (BGP_DEBUG(zebra
, ZEBRA
))
4328 "Processing route_map %s(%s:%s) update on advertise type5 route command",
4329 rmap_name
, afi2str(afi
), safi2str(safi
));
4331 if (route_update
&& advertise_type5_routes(bgp
, afi
)) {
4332 bgp_evpn_withdraw_type5_routes(bgp
, afi
, safi
);
4333 bgp_evpn_advertise_type5_routes(bgp
, afi
, safi
);
4338 static void bgp_route_map_process_update_cb(char *rmap_name
)
4340 struct listnode
*node
, *nnode
;
4343 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
)) {
4344 bgp_route_map_process_update(bgp
, rmap_name
, true);
4346 #ifdef ENABLE_BGP_VNC
4347 vnc_routemap_update(bgp
, __func__
);
4351 vpn_policy_routemap_event(rmap_name
);
4354 void bgp_route_map_update_timer(struct thread
*thread
)
4356 route_map_walk_update_list(bgp_route_map_process_update_cb
);
4359 static void bgp_route_map_mark_update(const char *rmap_name
)
4361 struct listnode
*node
, *nnode
;
4364 /* If new update is received before the current timer timed out,
4365 * turn it off and start a new timer.
4367 THREAD_OFF(bm
->t_rmap_update
);
4369 /* rmap_update_timer of 0 means don't do route updates */
4370 if (bm
->rmap_update_timer
) {
4371 thread_add_timer(bm
->master
, bgp_route_map_update_timer
,
4372 NULL
, bm
->rmap_update_timer
,
4373 &bm
->t_rmap_update
);
4375 /* Signal the groups that a route-map update event has
4377 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
4378 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
,
4379 rmap_name
, true, 1);
4381 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
)) {
4382 bgp_route_map_process_update(bgp
, rmap_name
, false);
4383 #ifdef ENABLE_BGP_VNC
4384 vnc_routemap_update(bgp
, __func__
);
4388 vpn_policy_routemap_event(rmap_name
);
4392 static void bgp_route_map_add(const char *rmap_name
)
4394 if (route_map_mark_updated(rmap_name
) == 0)
4395 bgp_route_map_mark_update(rmap_name
);
4397 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
4400 static void bgp_route_map_delete(const char *rmap_name
)
4402 if (route_map_mark_updated(rmap_name
) == 0)
4403 bgp_route_map_mark_update(rmap_name
);
4405 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_DELETED
);
4408 static void bgp_route_map_event(const char *rmap_name
)
4410 if (route_map_mark_updated(rmap_name
) == 0)
4411 bgp_route_map_mark_update(rmap_name
);
4413 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
4416 DEFUN_YANG (match_mac_address
,
4417 match_mac_address_cmd
,
4418 "match mac address ACCESSLIST_MAC_NAME",
4421 "Match address of route\n"
4422 "MAC Access-list name\n")
4425 "./match-condition[condition='frr-bgp-route-map:mac-address-list']";
4426 char xpath_value
[XPATH_MAXLEN
];
4428 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4429 snprintf(xpath_value
, sizeof(xpath_value
),
4430 "%s/rmap-match-condition/frr-bgp-route-map:list-name", xpath
);
4431 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[3]->arg
);
4433 return nb_cli_apply_changes(vty
, NULL
);
4436 DEFUN_YANG (no_match_mac_address
,
4437 no_match_mac_address_cmd
,
4438 "no match mac address ACCESSLIST_MAC_NAME",
4442 "Match address of route\n"
4443 "MAC acess-list name\n")
4446 "./match-condition[condition='frr-bgp-route-map:mac-address-list']";
4448 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4449 return nb_cli_apply_changes(vty
, NULL
);
4453 * Helper to handle the case of the user passing in a number or type string
4455 static const char *parse_evpn_rt_type(const char *num_rt_type
)
4457 switch (num_rt_type
[0]) {
4472 /* Was already full type string */
4476 DEFUN_YANG (match_evpn_route_type
,
4477 match_evpn_route_type_cmd
,
4478 "match evpn route-type <ead|1|macip|2|multicast|3|es|4|prefix|5>",
4482 EVPN_TYPE_1_HELP_STR
4483 EVPN_TYPE_1_HELP_STR
4484 EVPN_TYPE_2_HELP_STR
4485 EVPN_TYPE_2_HELP_STR
4486 EVPN_TYPE_3_HELP_STR
4487 EVPN_TYPE_3_HELP_STR
4488 EVPN_TYPE_4_HELP_STR
4489 EVPN_TYPE_4_HELP_STR
4490 EVPN_TYPE_5_HELP_STR
4491 EVPN_TYPE_5_HELP_STR
)
4494 "./match-condition[condition='frr-bgp-route-map:evpn-route-type']";
4495 char xpath_value
[XPATH_MAXLEN
];
4497 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4498 snprintf(xpath_value
, sizeof(xpath_value
),
4499 "%s/rmap-match-condition/frr-bgp-route-map:evpn-route-type",
4501 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4502 parse_evpn_rt_type(argv
[3]->arg
));
4504 return nb_cli_apply_changes(vty
, NULL
);
4507 DEFUN_YANG (no_match_evpn_route_type
,
4508 no_match_evpn_route_type_cmd
,
4509 "no match evpn route-type <ead|1|macip|2|multicast|3|es|4|prefix|5>",
4514 EVPN_TYPE_1_HELP_STR
4515 EVPN_TYPE_1_HELP_STR
4516 EVPN_TYPE_2_HELP_STR
4517 EVPN_TYPE_2_HELP_STR
4518 EVPN_TYPE_3_HELP_STR
4519 EVPN_TYPE_3_HELP_STR
4520 EVPN_TYPE_4_HELP_STR
4521 EVPN_TYPE_4_HELP_STR
4522 EVPN_TYPE_5_HELP_STR
4523 EVPN_TYPE_5_HELP_STR
)
4526 "./match-condition[condition='frr-bgp-route-map:evpn-route-type']";
4528 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4530 return nb_cli_apply_changes(vty
, NULL
);
4534 DEFUN_YANG (match_evpn_vni
,
4536 "match evpn vni " CMD_VNI_RANGE
,
4543 "./match-condition[condition='frr-bgp-route-map:evpn-vni']";
4544 char xpath_value
[XPATH_MAXLEN
];
4546 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4547 snprintf(xpath_value
, sizeof(xpath_value
),
4548 "%s/rmap-match-condition/frr-bgp-route-map:evpn-vni", xpath
);
4549 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[3]->arg
);
4551 return nb_cli_apply_changes(vty
, NULL
);
4554 DEFUN_YANG (no_match_evpn_vni
,
4555 no_match_evpn_vni_cmd
,
4556 "no match evpn vni " CMD_VNI_RANGE
,
4564 "./match-condition[condition='frr-bgp-route-map:evpn-vni']";
4565 char xpath_value
[XPATH_MAXLEN
];
4567 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4568 snprintf(xpath_value
, sizeof(xpath_value
),
4569 "%s/rmap-match-condition/frr-bgp-route-map:evpn-vni", xpath
);
4570 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_DESTROY
, argv
[3]->arg
);
4572 return nb_cli_apply_changes(vty
, NULL
);
4575 DEFUN_YANG (match_evpn_default_route
,
4576 match_evpn_default_route_cmd
,
4577 "match evpn default-route",
4580 "default EVPN type-5 route\n")
4583 "./match-condition[condition='frr-bgp-route-map:evpn-default-route']";
4584 char xpath_value
[XPATH_MAXLEN
];
4586 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4588 snprintf(xpath_value
, sizeof(xpath_value
),
4589 "%s/rmap-match-condition/frr-bgp-route-map:evpn-default-route",
4591 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, NULL
);
4593 return nb_cli_apply_changes(vty
, NULL
);
4596 DEFUN_YANG (no_match_evpn_default_route
,
4597 no_match_evpn_default_route_cmd
,
4598 "no match evpn default-route",
4602 "default EVPN type-5 route\n")
4605 "./match-condition[condition='frr-bgp-route-map:evpn-default-route']";
4607 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4609 return nb_cli_apply_changes(vty
, NULL
);
4612 DEFUN_YANG (match_evpn_rd
,
4614 "match evpn rd ASN:NN_OR_IP-ADDRESS:NN",
4617 "Route Distinguisher\n"
4618 "ASN:XX or A.B.C.D:XX\n")
4621 "./match-condition[condition='frr-bgp-route-map:evpn-rd']";
4622 char xpath_value
[XPATH_MAXLEN
];
4624 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4626 xpath_value
, sizeof(xpath_value
),
4627 "%s/rmap-match-condition/frr-bgp-route-map:route-distinguisher",
4629 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[3]->arg
);
4631 return nb_cli_apply_changes(vty
, NULL
);
4634 DEFUN_YANG (no_match_evpn_rd
,
4635 no_match_evpn_rd_cmd
,
4636 "no match evpn rd ASN:NN_OR_IP-ADDRESS:NN",
4640 "Route Distinguisher\n"
4641 "ASN:XX or A.B.C.D:XX\n")
4644 "./match-condition[condition='frr-bgp-route-map:evpn-rd']";
4646 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4647 return nb_cli_apply_changes(vty
, NULL
);
4650 DEFUN_YANG (set_evpn_gw_ip_ipv4
,
4651 set_evpn_gw_ip_ipv4_cmd
,
4652 "set evpn gateway-ip ipv4 A.B.C.D",
4655 "Set gateway IP for prefix advertisement route\n"
4657 "Gateway IP address in IPv4 format\n")
4662 "./set-action[action='frr-bgp-route-map:set-evpn-gateway-ip-ipv4']";
4663 char xpath_value
[XPATH_MAXLEN
];
4665 ret
= str2sockunion(argv
[4]->arg
, &su
);
4667 vty_out(vty
, "%% Malformed gateway IP\n");
4668 return CMD_WARNING_CONFIG_FAILED
;
4671 if (su
.sin
.sin_addr
.s_addr
== 0 ||
4672 !ipv4_unicast_valid(&su
.sin
.sin_addr
)) {
4674 "%% Gateway IP cannot be 0.0.0.0, multicast or reserved\n");
4675 return CMD_WARNING_CONFIG_FAILED
;
4678 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4680 snprintf(xpath_value
, sizeof(xpath_value
),
4681 "%s/rmap-set-action/frr-bgp-route-map:evpn-gateway-ip-ipv4",
4684 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[4]->arg
);
4685 return nb_cli_apply_changes(vty
, NULL
);
4688 DEFUN_YANG (no_set_evpn_gw_ip_ipv4
,
4689 no_set_evpn_gw_ip_ipv4_cmd
,
4690 "no set evpn gateway-ip ipv4 A.B.C.D",
4694 "Set gateway IP for prefix advertisement route\n"
4696 "Gateway IP address in IPv4 format\n")
4701 "./set-action[action='frr-bgp-route-map:set-evpn-gateway-ip-ipv4']";
4703 ret
= str2sockunion(argv
[5]->arg
, &su
);
4705 vty_out(vty
, "%% Malformed gateway IP\n");
4706 return CMD_WARNING_CONFIG_FAILED
;
4709 if (su
.sin
.sin_addr
.s_addr
== 0 ||
4710 !ipv4_unicast_valid(&su
.sin
.sin_addr
)) {
4712 "%% Gateway IP cannot be 0.0.0.0, multicast or reserved\n");
4713 return CMD_WARNING_CONFIG_FAILED
;
4716 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4718 return nb_cli_apply_changes(vty
, NULL
);
4721 DEFUN_YANG (set_evpn_gw_ip_ipv6
,
4722 set_evpn_gw_ip_ipv6_cmd
,
4723 "set evpn gateway-ip ipv6 X:X::X:X",
4726 "Set gateway IP for prefix advertisement route\n"
4728 "Gateway IP address in IPv6 format\n")
4733 "./set-action[action='frr-bgp-route-map:set-evpn-gateway-ip-ipv6']";
4734 char xpath_value
[XPATH_MAXLEN
];
4736 ret
= str2sockunion(argv
[4]->arg
, &su
);
4738 vty_out(vty
, "%% Malformed gateway IP\n");
4739 return CMD_WARNING_CONFIG_FAILED
;
4742 if (IN6_IS_ADDR_LINKLOCAL(&su
.sin6
.sin6_addr
)
4743 || IN6_IS_ADDR_MULTICAST(&su
.sin6
.sin6_addr
)) {
4745 "%% Gateway IP cannot be a linklocal or multicast address\n");
4746 return CMD_WARNING_CONFIG_FAILED
;
4749 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4751 snprintf(xpath_value
, sizeof(xpath_value
),
4752 "%s/rmap-set-action/frr-bgp-route-map:evpn-gateway-ip-ipv6",
4755 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[4]->arg
);
4756 return nb_cli_apply_changes(vty
, NULL
);
4759 DEFUN_YANG (no_set_evpn_gw_ip_ipv6
,
4760 no_set_evpn_gw_ip_ipv6_cmd
,
4761 "no set evpn gateway-ip ipv6 X:X::X:X",
4765 "Set gateway IP for prefix advertisement route\n"
4767 "Gateway IP address in IPv4 format\n")
4772 "./set-action[action='frr-bgp-route-map:set-evpn-gateway-ip-ipv6']";
4774 ret
= str2sockunion(argv
[5]->arg
, &su
);
4776 vty_out(vty
, "%% Malformed gateway IP\n");
4777 return CMD_WARNING_CONFIG_FAILED
;
4780 if (IN6_IS_ADDR_LINKLOCAL(&su
.sin6
.sin6_addr
)
4781 || IN6_IS_ADDR_MULTICAST(&su
.sin6
.sin6_addr
)) {
4783 "%% Gateway IP cannot be a linklocal or multicast address\n");
4784 return CMD_WARNING_CONFIG_FAILED
;
4787 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4789 return nb_cli_apply_changes(vty
, NULL
);
4792 DEFPY_YANG(match_vrl_source_vrf
,
4793 match_vrl_source_vrf_cmd
,
4794 "match source-vrf NAME$vrf_name",
4800 "./match-condition[condition='frr-bgp-route-map:source-vrf']";
4801 char xpath_value
[XPATH_MAXLEN
];
4803 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4804 snprintf(xpath_value
, sizeof(xpath_value
),
4805 "%s/rmap-match-condition/frr-bgp-route-map:source-vrf", xpath
);
4806 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, vrf_name
);
4808 return nb_cli_apply_changes(vty
, NULL
);
4811 DEFPY_YANG(no_match_vrl_source_vrf
,
4812 no_match_vrl_source_vrf_cmd
,
4813 "no match source-vrf NAME$vrf_name",
4819 "./match-condition[condition='frr-bgp-route-map:source-vrf']";
4821 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4822 return nb_cli_apply_changes(vty
, NULL
);
4825 DEFPY_YANG (match_peer
,
4827 "match peer <A.B.C.D$addrv4|X:X::X:X$addrv6|WORD$intf>",
4829 "Match peer address\n"
4830 "IP address of peer\n"
4831 "IPv6 address of peer\n"
4832 "Interface name of peer or peer group name\n")
4835 "./match-condition[condition='frr-bgp-route-map:peer']";
4836 char xpath_value
[XPATH_MAXLEN
];
4838 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4842 xpath_value
, sizeof(xpath_value
),
4843 "%s/rmap-match-condition/frr-bgp-route-map:peer-ipv4-address",
4845 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4847 } else if (addrv6_str
) {
4849 xpath_value
, sizeof(xpath_value
),
4850 "%s/rmap-match-condition/frr-bgp-route-map:peer-ipv6-address",
4852 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4856 xpath_value
, sizeof(xpath_value
),
4857 "%s/rmap-match-condition/frr-bgp-route-map:peer-interface",
4859 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, intf
);
4862 return nb_cli_apply_changes(vty
, NULL
);
4865 DEFUN_YANG (match_peer_local
,
4866 match_peer_local_cmd
,
4869 "Match peer address\n"
4870 "Static or Redistributed routes\n")
4873 "./match-condition[condition='frr-bgp-route-map:peer']";
4874 char xpath_value
[XPATH_MAXLEN
];
4876 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4878 snprintf(xpath_value
, sizeof(xpath_value
),
4879 "%s/rmap-match-condition/frr-bgp-route-map:peer-local", xpath
);
4880 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
4882 return nb_cli_apply_changes(vty
, NULL
);
4885 DEFUN_YANG (no_match_peer
,
4887 "no match peer [<local|A.B.C.D|X:X::X:X|WORD>]",
4890 "Match peer address\n"
4891 "Static or Redistributed routes\n"
4892 "IP address of peer\n"
4893 "IPv6 address of peer\n"
4894 "Interface name of peer\n")
4897 "./match-condition[condition='frr-bgp-route-map:peer']";
4899 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4901 return nb_cli_apply_changes(vty
, NULL
);
4904 #ifdef HAVE_SCRIPTING
4905 DEFUN_YANG (match_script
,
4907 "[no] match script WORD",
4910 "Execute script to determine match\n"
4911 "The script name to run, without .lua; e.g. 'myroutemap' to run myroutemap.lua\n")
4913 bool no
= strmatch(argv
[0]->text
, "no");
4915 argv_find(argv
, argc
, "WORD", &i
);
4916 const char *script
= argv
[i
]->arg
;
4918 "./match-condition[condition='frr-bgp-route-map:match-script']";
4919 char xpath_value
[XPATH_MAXLEN
];
4922 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4923 snprintf(xpath_value
, sizeof(xpath_value
),
4924 "%s/rmap-match-condition/frr-bgp-route-map:script",
4926 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_DESTROY
,
4929 return nb_cli_apply_changes(vty
, NULL
);
4932 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4933 snprintf(xpath_value
, sizeof(xpath_value
),
4934 "%s/rmap-match-condition/frr-bgp-route-map:script",
4936 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4939 return nb_cli_apply_changes(vty
, NULL
);
4941 #endif /* HAVE_SCRIPTING */
4943 /* match probability */
4944 DEFUN_YANG (match_probability
,
4945 match_probability_cmd
,
4946 "match probability (0-100)",
4948 "Match portion of routes defined by percentage value\n"
4949 "Percentage of routes\n")
4954 "./match-condition[condition='frr-bgp-route-map:probability']";
4955 char xpath_value
[XPATH_MAXLEN
];
4957 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4958 snprintf(xpath_value
, sizeof(xpath_value
),
4959 "%s/rmap-match-condition/frr-bgp-route-map:probability",
4961 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4962 argv
[idx_number
]->arg
);
4964 return nb_cli_apply_changes(vty
, NULL
);
4968 DEFUN_YANG (no_match_probability
,
4969 no_match_probability_cmd
,
4970 "no match probability [(1-99)]",
4973 "Match portion of routes defined by percentage value\n"
4974 "Percentage of routes\n")
4978 "./match-condition[condition='frr-bgp-route-map:probability']";
4979 char xpath_value
[XPATH_MAXLEN
];
4981 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4983 if (argc
<= idx_number
)
4984 return nb_cli_apply_changes(vty
, NULL
);
4986 snprintf(xpath_value
, sizeof(xpath_value
),
4987 "%s/rmap-match-condition/frr-bgp-route-map:probability",
4989 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_DESTROY
,
4990 argv
[idx_number
]->arg
);
4992 return nb_cli_apply_changes(vty
, NULL
);
4996 DEFPY_YANG (match_ip_route_source
,
4997 match_ip_route_source_cmd
,
4998 "match ip route-source ACCESSLIST4_NAME",
5001 "Match advertising source address of route\n"
5002 "IP Access-list name\n")
5005 "./match-condition[condition='frr-bgp-route-map:ip-route-source']";
5006 char xpath_value
[XPATH_MAXLEN
+ 32];
5009 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5010 snprintf(xpath_value
, sizeof(xpath_value
),
5011 "%s/rmap-match-condition/frr-bgp-route-map:list-name",
5013 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5014 argv
[idx_acl
]->arg
);
5016 return nb_cli_apply_changes(vty
, NULL
);
5020 DEFUN_YANG (no_match_ip_route_source
,
5021 no_match_ip_route_source_cmd
,
5022 "no match ip route-source [ACCESSLIST4_NAME]",
5026 "Match advertising source address of route\n"
5027 "IP Access-list name\n")
5030 "./match-condition[condition='frr-bgp-route-map:ip-route-source']";
5032 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5033 return nb_cli_apply_changes(vty
, NULL
);
5036 DEFUN_YANG (match_ip_route_source_prefix_list
,
5037 match_ip_route_source_prefix_list_cmd
,
5038 "match ip route-source prefix-list PREFIXLIST_NAME",
5041 "Match advertising source address of route\n"
5042 "Match entries of prefix-lists\n"
5043 "IP prefix-list name\n")
5047 "./match-condition[condition='frr-bgp-route-map:ip-route-source-prefix-list']";
5048 char xpath_value
[XPATH_MAXLEN
+ 32];
5050 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5051 snprintf(xpath_value
, sizeof(xpath_value
),
5052 "%s/rmap-match-condition/frr-bgp-route-map:list-name", xpath
);
5053 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5054 argv
[idx_word
]->arg
);
5056 return nb_cli_apply_changes(vty
, NULL
);
5060 DEFUN_YANG (no_match_ip_route_source_prefix_list
,
5061 no_match_ip_route_source_prefix_list_cmd
,
5062 "no match ip route-source prefix-list [PREFIXLIST_NAME]",
5066 "Match advertising source address of route\n"
5067 "Match entries of prefix-lists\n"
5068 "IP prefix-list name\n")
5071 "./match-condition[condition='frr-bgp-route-map:ip-route-source-prefix-list']";
5073 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5074 return nb_cli_apply_changes(vty
, NULL
);
5077 DEFUN_YANG (match_local_pref
,
5078 match_local_pref_cmd
,
5079 "match local-preference (0-4294967295)",
5081 "Match local-preference of route\n"
5087 "./match-condition[condition='frr-bgp-route-map:match-local-preference']";
5088 char xpath_value
[XPATH_MAXLEN
];
5090 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5091 snprintf(xpath_value
, sizeof(xpath_value
),
5092 "%s/rmap-match-condition/frr-bgp-route-map:local-preference",
5094 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5095 argv
[idx_number
]->arg
);
5097 return nb_cli_apply_changes(vty
, NULL
);
5101 DEFUN_YANG (no_match_local_pref
,
5102 no_match_local_pref_cmd
,
5103 "no match local-preference [(0-4294967295)]",
5106 "Match local preference of route\n"
5107 "Local preference value\n")
5109 int idx_localpref
= 3;
5111 "./match-condition[condition='frr-bgp-route-map:match-local-preference']";
5112 char xpath_value
[XPATH_MAXLEN
];
5114 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5116 if (argc
<= idx_localpref
)
5117 return nb_cli_apply_changes(vty
, NULL
);
5119 snprintf(xpath_value
, sizeof(xpath_value
),
5120 "%s/rmap-match-condition/frr-bgp-route-map:local-preference",
5122 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_DESTROY
,
5123 argv
[idx_localpref
]->arg
);
5125 return nb_cli_apply_changes(vty
, NULL
);
5128 DEFUN_YANG(match_alias
, match_alias_cmd
, "match alias ALIAS_NAME",
5130 "Match BGP community alias name\n"
5131 "BGP community alias name\n")
5133 const char *alias
= argv
[2]->arg
;
5134 struct community_alias ca1
;
5135 struct community_alias
*lookup_alias
;
5138 "./match-condition[condition='frr-bgp-route-map:match-alias']";
5139 char xpath_value
[XPATH_MAXLEN
];
5141 memset(&ca1
, 0, sizeof(ca1
));
5142 strlcpy(ca1
.alias
, alias
, sizeof(ca1
.alias
));
5143 lookup_alias
= bgp_ca_alias_lookup(&ca1
);
5144 if (!lookup_alias
) {
5145 vty_out(vty
, "%% BGP alias name '%s' does not exist\n", alias
);
5146 return CMD_WARNING_CONFIG_FAILED
;
5149 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5150 snprintf(xpath_value
, sizeof(xpath_value
),
5151 "%s/rmap-match-condition/frr-bgp-route-map:alias", xpath
);
5152 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, alias
);
5154 return nb_cli_apply_changes(vty
, NULL
);
5158 DEFUN_YANG(no_match_alias
, no_match_alias_cmd
, "no match alias [ALIAS_NAME]",
5160 "Match BGP community alias name\n"
5161 "BGP community alias name\n")
5165 "./match-condition[condition='frr-bgp-route-map:match-alias']";
5166 char xpath_value
[XPATH_MAXLEN
];
5168 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5170 if (argc
<= idx_alias
)
5171 return nb_cli_apply_changes(vty
, NULL
);
5173 snprintf(xpath_value
, sizeof(xpath_value
),
5174 "%s/rmap-match-condition/frr-bgp-route-map:alias", xpath
);
5175 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_DESTROY
,
5176 argv
[idx_alias
]->arg
);
5178 return nb_cli_apply_changes(vty
, NULL
);
5181 DEFPY_YANG (match_community
,
5182 match_community_cmd
,
5183 "match community <(1-99)|(100-500)|COMMUNITY_LIST_NAME> [exact-match]",
5185 "Match BGP community list\n"
5186 "Community-list number (standard)\n"
5187 "Community-list number (expanded)\n"
5188 "Community-list name\n"
5189 "Do exact matching of communities\n")
5192 "./match-condition[condition='frr-bgp-route-map:match-community']";
5193 char xpath_value
[XPATH_MAXLEN
];
5194 char xpath_match
[XPATH_MAXLEN
];
5195 int idx_comm_list
= 2;
5197 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5200 xpath_value
, sizeof(xpath_value
),
5201 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name",
5203 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[idx_comm_list
]->arg
);
5207 xpath_match
, sizeof(xpath_match
),
5208 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match",
5210 nb_cli_enqueue_change(vty
, xpath_match
, NB_OP_MODIFY
,
5214 xpath_match
, sizeof(xpath_match
),
5215 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match",
5217 nb_cli_enqueue_change(vty
, xpath_match
, NB_OP_MODIFY
,
5221 return nb_cli_apply_changes(vty
, NULL
);
5224 DEFUN_YANG (no_match_community
,
5225 no_match_community_cmd
,
5226 "no match community [<(1-99)|(100-500)|COMMUNITY_LIST_NAME> [exact-match]]",
5229 "Match BGP community list\n"
5230 "Community-list number (standard)\n"
5231 "Community-list number (expanded)\n"
5232 "Community-list name\n"
5233 "Do exact matching of communities\n")
5236 "./match-condition[condition='frr-bgp-route-map:match-community']";
5238 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5239 return nb_cli_apply_changes(vty
, NULL
);
5242 DEFPY_YANG (match_lcommunity
,
5243 match_lcommunity_cmd
,
5244 "match large-community <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME> [exact-match]",
5246 "Match BGP large community list\n"
5247 "Large Community-list number (standard)\n"
5248 "Large Community-list number (expanded)\n"
5249 "Large Community-list name\n"
5250 "Do exact matching of communities\n")
5253 "./match-condition[condition='frr-bgp-route-map:match-large-community']";
5254 char xpath_value
[XPATH_MAXLEN
];
5255 char xpath_match
[XPATH_MAXLEN
];
5256 int idx_lcomm_list
= 2;
5258 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5261 xpath_value
, sizeof(xpath_value
),
5262 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name",
5264 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[idx_lcomm_list
]->arg
);
5268 xpath_match
, sizeof(xpath_match
),
5269 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match",
5271 nb_cli_enqueue_change(vty
, xpath_match
, NB_OP_MODIFY
,
5275 xpath_match
, sizeof(xpath_match
),
5276 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match",
5278 nb_cli_enqueue_change(vty
, xpath_match
, NB_OP_MODIFY
,
5282 return nb_cli_apply_changes(vty
, NULL
);
5285 DEFUN_YANG (no_match_lcommunity
,
5286 no_match_lcommunity_cmd
,
5287 "no match large-community [<(1-99)|(100-500)|LCOMMUNITY_LIST_NAME> [exact-match]]",
5290 "Match BGP large community list\n"
5291 "Large Community-list number (standard)\n"
5292 "Large Community-list number (expanded)\n"
5293 "Large Community-list name\n"
5294 "Do exact matching of communities\n")
5297 "./match-condition[condition='frr-bgp-route-map:match-large-community']";
5299 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5300 return nb_cli_apply_changes(vty
, NULL
);
5303 DEFPY_YANG (match_ecommunity
,
5304 match_ecommunity_cmd
,
5305 "match extcommunity <(1-99)|(100-500)|EXTCOMMUNITY_LIST_NAME>",
5307 "Match BGP/VPN extended community list\n"
5308 "Extended community-list number (standard)\n"
5309 "Extended community-list number (expanded)\n"
5310 "Extended community-list name\n")
5313 "./match-condition[condition='frr-bgp-route-map:match-extcommunity']";
5314 char xpath_value
[XPATH_MAXLEN
];
5315 int idx_comm_list
= 2;
5317 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5320 xpath_value
, sizeof(xpath_value
),
5321 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name",
5323 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[idx_comm_list
]->arg
);
5325 return nb_cli_apply_changes(vty
, NULL
);
5329 DEFUN_YANG (no_match_ecommunity
,
5330 no_match_ecommunity_cmd
,
5331 "no match extcommunity [<(1-99)|(100-500)|EXTCOMMUNITY_LIST_NAME>]",
5334 "Match BGP/VPN extended community list\n"
5335 "Extended community-list number (standard)\n"
5336 "Extended community-list number (expanded)\n"
5337 "Extended community-list name\n")
5340 "./match-condition[condition='frr-bgp-route-map:match-extcommunity']";
5342 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5343 return nb_cli_apply_changes(vty
, NULL
);
5347 DEFUN_YANG (match_aspath
,
5349 "match as-path AS_PATH_FILTER_NAME",
5351 "Match BGP AS path list\n"
5352 "AS path access-list name\n")
5357 "./match-condition[condition='frr-bgp-route-map:as-path-list']";
5358 char xpath_value
[XPATH_MAXLEN
];
5360 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5361 snprintf(xpath_value
, sizeof(xpath_value
),
5362 "%s/rmap-match-condition/frr-bgp-route-map:list-name", xpath
);
5363 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5364 argv
[idx_word
]->arg
);
5366 return nb_cli_apply_changes(vty
, NULL
);
5370 DEFUN_YANG (no_match_aspath
,
5371 no_match_aspath_cmd
,
5372 "no match as-path [AS_PATH_FILTER_NAME]",
5375 "Match BGP AS path list\n"
5376 "AS path access-list name\n")
5379 "./match-condition[condition='frr-bgp-route-map:as-path-list']";
5381 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5383 return nb_cli_apply_changes(vty
, NULL
);
5386 DEFUN_YANG (match_origin
,
5388 "match origin <egp|igp|incomplete>",
5393 "unknown heritage\n")
5396 const char *origin_type
;
5398 "./match-condition[condition='frr-bgp-route-map:match-origin']";
5399 char xpath_value
[XPATH_MAXLEN
];
5401 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
5402 origin_type
= "igp";
5403 else if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
5404 origin_type
= "egp";
5405 else if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
5406 origin_type
= "incomplete";
5408 vty_out(vty
, "%% Invalid match origin type\n");
5409 return CMD_WARNING_CONFIG_FAILED
;
5412 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5413 snprintf(xpath_value
, sizeof(xpath_value
),
5414 "%s/rmap-match-condition/frr-bgp-route-map:origin", xpath
);
5415 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, origin_type
);
5417 return nb_cli_apply_changes(vty
, NULL
);
5421 DEFUN_YANG (no_match_origin
,
5422 no_match_origin_cmd
,
5423 "no match origin [<egp|igp|incomplete>]",
5429 "unknown heritage\n")
5432 "./match-condition[condition='frr-bgp-route-map:match-origin']";
5433 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5434 return nb_cli_apply_changes(vty
, NULL
);
5437 DEFUN_YANG (set_table_id
,
5439 "set table (1-4294967295)",
5441 "export route to non-main kernel table\n"
5442 "Kernel routing table id\n")
5445 const char *xpath
= "./set-action[action='frr-bgp-route-map:table']";
5446 char xpath_value
[XPATH_MAXLEN
];
5448 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5449 snprintf(xpath_value
, sizeof(xpath_value
),
5450 "%s/rmap-set-action/frr-bgp-route-map:table", xpath
);
5451 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5452 argv
[idx_number
]->arg
);
5453 return nb_cli_apply_changes(vty
, NULL
);
5456 DEFUN_YANG (no_set_table_id
,
5457 no_set_table_id_cmd
,
5461 "export route to non-main kernel table\n")
5463 const char *xpath
= "./set-action[action='frr-bgp-route-map:table']";
5464 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5465 return nb_cli_apply_changes(vty
, NULL
);
5468 DEFUN_YANG (set_ip_nexthop_peer
,
5469 set_ip_nexthop_peer_cmd
,
5470 "[no] set ip next-hop peer-address",
5474 "Next hop address\n"
5475 "Use peer address (for BGP only)\n")
5477 char xpath_value
[XPATH_MAXLEN
];
5479 "./set-action[action='frr-bgp-route-map:set-ipv4-nexthop']";
5481 if (strmatch(argv
[0]->text
, "no"))
5482 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5484 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5485 snprintf(xpath_value
, sizeof(xpath_value
),
5486 "%s/rmap-set-action/frr-bgp-route-map:ipv4-nexthop",
5488 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5491 return nb_cli_apply_changes(vty
, NULL
);
5494 DEFUN_YANG (set_ip_nexthop_unchanged
,
5495 set_ip_nexthop_unchanged_cmd
,
5496 "[no] set ip next-hop unchanged",
5500 "Next hop address\n"
5501 "Don't modify existing Next hop address\n")
5503 char xpath_value
[XPATH_MAXLEN
];
5505 "./set-action[action='frr-bgp-route-map:set-ipv4-nexthop']";
5507 if (strmatch(argv
[0]->text
, "no"))
5508 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5510 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5511 snprintf(xpath_value
, sizeof(xpath_value
),
5512 "%s/rmap-set-action/frr-bgp-route-map:ipv4-nexthop",
5514 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5517 return nb_cli_apply_changes(vty
, NULL
);
5520 DEFUN_YANG (set_distance
,
5522 "set distance (0-255)",
5524 "BGP Administrative Distance to use\n"
5528 const char *xpath
= "./set-action[action='frr-bgp-route-map:distance']";
5529 char xpath_value
[XPATH_MAXLEN
];
5531 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5532 snprintf(xpath_value
, sizeof(xpath_value
),
5533 "%s/rmap-set-action/frr-bgp-route-map:distance", xpath
);
5534 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5535 argv
[idx_number
]->arg
);
5536 return nb_cli_apply_changes(vty
, NULL
);
5539 DEFUN_YANG (no_set_distance
,
5540 no_set_distance_cmd
,
5541 "no set distance [(0-255)]",
5543 "BGP Administrative Distance to use\n"
5546 const char *xpath
= "./set-action[action='frr-bgp-route-map:distance']";
5548 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5549 return nb_cli_apply_changes(vty
, NULL
);
5552 DEFPY_YANG(set_l3vpn_nexthop_encapsulation
, set_l3vpn_nexthop_encapsulation_cmd
,
5553 "[no] set l3vpn next-hop encapsulation gre",
5555 "L3VPN operations\n"
5556 "Next hop Information\n"
5557 "Encapsulation options (for BGP only)\n"
5558 "Accept L3VPN traffic over GRE encapsulation\n")
5561 "./set-action[action='frr-bgp-route-map:set-l3vpn-nexthop-encapsulation']";
5562 const char *xpath_value
=
5563 "./set-action[action='frr-bgp-route-map:set-l3vpn-nexthop-encapsulation']/rmap-set-action/frr-bgp-route-map:l3vpn-nexthop-encapsulation";
5564 enum nb_operation operation
;
5567 operation
= NB_OP_DESTROY
;
5569 operation
= NB_OP_CREATE
;
5571 nb_cli_enqueue_change(vty
, xpath
, operation
, NULL
);
5572 if (operation
== NB_OP_DESTROY
)
5573 return nb_cli_apply_changes(vty
, NULL
);
5575 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "gre");
5577 return nb_cli_apply_changes(vty
, NULL
);
5580 DEFUN_YANG (set_local_pref
,
5582 "set local-preference WORD",
5584 "BGP local preference path attribute\n"
5585 "Preference value (0-4294967295)\n")
5589 "./set-action[action='frr-bgp-route-map:set-local-preference']";
5590 char xpath_value
[XPATH_MAXLEN
];
5592 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5593 snprintf(xpath_value
, sizeof(xpath_value
),
5594 "%s/rmap-set-action/frr-bgp-route-map:local-pref", xpath
);
5595 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5596 argv
[idx_number
]->arg
);
5597 return nb_cli_apply_changes(vty
, NULL
);
5600 DEFUN_YANG (no_set_local_pref
,
5601 no_set_local_pref_cmd
,
5602 "no set local-preference [WORD]",
5605 "BGP local preference path attribute\n"
5606 "Preference value (0-4294967295)\n")
5609 "./set-action[action='frr-bgp-route-map:set-local-preference']";
5611 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5612 return nb_cli_apply_changes(vty
, NULL
);
5615 DEFUN_YANG (set_weight
,
5617 "set weight (0-4294967295)",
5619 "BGP weight for routing table\n"
5623 const char *xpath
= "./set-action[action='frr-bgp-route-map:weight']";
5624 char xpath_value
[XPATH_MAXLEN
];
5626 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5627 snprintf(xpath_value
, sizeof(xpath_value
),
5628 "%s/rmap-set-action/frr-bgp-route-map:weight", xpath
);
5629 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5630 argv
[idx_number
]->arg
);
5631 return nb_cli_apply_changes(vty
, NULL
);
5634 DEFUN_YANG (no_set_weight
,
5636 "no set weight [(0-4294967295)]",
5639 "BGP weight for routing table\n"
5642 const char *xpath
= "./set-action[action='frr-bgp-route-map:weight']";
5644 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5645 return nb_cli_apply_changes(vty
, NULL
);
5648 DEFUN_YANG (set_label_index
,
5649 set_label_index_cmd
,
5650 "set label-index (0-1048560)",
5652 "Label index to associate with the prefix\n"
5653 "Label index value\n")
5657 "./set-action[action='frr-bgp-route-map:label-index']";
5658 char xpath_value
[XPATH_MAXLEN
];
5660 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5661 snprintf(xpath_value
, sizeof(xpath_value
),
5662 "%s/rmap-set-action/frr-bgp-route-map:label-index", xpath
);
5663 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5664 argv
[idx_number
]->arg
);
5665 return nb_cli_apply_changes(vty
, NULL
);
5668 DEFUN_YANG (no_set_label_index
,
5669 no_set_label_index_cmd
,
5670 "no set label-index [(0-1048560)]",
5673 "Label index to associate with the prefix\n"
5674 "Label index value\n")
5677 "./set-action[action='frr-bgp-route-map:label-index']";
5679 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5680 return nb_cli_apply_changes(vty
, NULL
);
5683 DEFUN_YANG (set_aspath_prepend_asn
,
5684 set_aspath_prepend_asn_cmd
,
5685 "set as-path prepend (1-4294967295)...",
5687 "Transform BGP AS_PATH attribute\n"
5688 "Prepend to the as-path\n"
5695 str
= argv_concat(argv
, argc
, idx_asn
);
5698 "./set-action[action='frr-bgp-route-map:as-path-prepend']";
5699 char xpath_value
[XPATH_MAXLEN
];
5701 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5702 snprintf(xpath_value
, sizeof(xpath_value
),
5703 "%s/rmap-set-action/frr-bgp-route-map:prepend-as-path", xpath
);
5704 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
5705 ret
= nb_cli_apply_changes(vty
, NULL
);
5706 XFREE(MTYPE_TMP
, str
);
5710 DEFUN_YANG (set_aspath_prepend_lastas
,
5711 set_aspath_prepend_lastas_cmd
,
5712 "set as-path prepend last-as (1-10)",
5714 "Transform BGP AS_PATH attribute\n"
5715 "Prepend to the as-path\n"
5716 "Use the last AS-number in the as-path\n"
5717 "Number of times to insert\n")
5722 "./set-action[action='frr-bgp-route-map:as-path-prepend']";
5723 char xpath_value
[XPATH_MAXLEN
];
5725 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5726 snprintf(xpath_value
, sizeof(xpath_value
),
5727 "%s/rmap-set-action/frr-bgp-route-map:last-as", xpath
);
5728 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5729 argv
[idx_num
]->arg
);
5730 return nb_cli_apply_changes(vty
, NULL
);
5733 DEFPY_YANG (set_aspath_replace_asn
,
5734 set_aspath_replace_asn_cmd
,
5735 "set as-path replace <any|(1-4294967295)>$replace",
5737 "Transform BGP AS_PATH attribute\n"
5738 "Replace AS number to local AS number\n"
5739 "Replace any AS number to local AS number\n"
5740 "Replace a specific AS number to local AS number\n")
5743 "./set-action[action='frr-bgp-route-map:as-path-replace']";
5744 char xpath_value
[XPATH_MAXLEN
];
5746 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5747 snprintf(xpath_value
, sizeof(xpath_value
),
5748 "%s/rmap-set-action/frr-bgp-route-map:replace-as-path", xpath
);
5749 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, replace
);
5750 return nb_cli_apply_changes(vty
, NULL
);
5753 DEFPY_YANG (no_set_aspath_replace_asn
,
5754 no_set_aspath_replace_asn_cmd
,
5755 "no set as-path replace [<any|(1-4294967295)>]",
5758 "Transform BGP AS_PATH attribute\n"
5759 "Replace AS number to local AS number\n"
5760 "Replace any AS number to local AS number\n"
5761 "Replace a specific AS number to local AS number\n")
5764 "./set-action[action='frr-bgp-route-map:as-path-replace']";
5766 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5767 return nb_cli_apply_changes(vty
, NULL
);
5770 DEFUN_YANG (no_set_aspath_prepend
,
5771 no_set_aspath_prepend_cmd
,
5772 "no set as-path prepend [(1-4294967295)]",
5775 "Transform BGP AS_PATH attribute\n"
5776 "Prepend to the as-path\n"
5780 "./set-action[action='frr-bgp-route-map:as-path-prepend']";
5782 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5783 return nb_cli_apply_changes(vty
, NULL
);
5786 DEFUN_YANG (no_set_aspath_prepend_lastas
,
5787 no_set_aspath_prepend_lastas_cmd
,
5788 "no set as-path prepend last-as [(1-10)]",
5791 "Transform BGP AS_PATH attribute\n"
5792 "Prepend to the as-path\n"
5793 "Use the peers AS-number\n"
5794 "Number of times to insert\n")
5797 "./set-action[action='frr-bgp-route-map:as-path-prepend']";
5799 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5800 return nb_cli_apply_changes(vty
, NULL
);
5803 DEFUN_YANG (set_aspath_exclude
,
5804 set_aspath_exclude_cmd
,
5805 "set as-path exclude (1-4294967295)...",
5807 "Transform BGP AS-path attribute\n"
5808 "Exclude from the as-path\n"
5815 str
= argv_concat(argv
, argc
, idx_asn
);
5818 "./set-action[action='frr-bgp-route-map:as-path-exclude']";
5819 char xpath_value
[XPATH_MAXLEN
];
5821 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5822 snprintf(xpath_value
, sizeof(xpath_value
),
5823 "%s/rmap-set-action/frr-bgp-route-map:exclude-as-path", xpath
);
5824 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
5825 ret
= nb_cli_apply_changes(vty
, NULL
);
5826 XFREE(MTYPE_TMP
, str
);
5830 DEFUN_YANG (no_set_aspath_exclude
,
5831 no_set_aspath_exclude_cmd
,
5832 "no set as-path exclude (1-4294967295)...",
5835 "Transform BGP AS_PATH attribute\n"
5836 "Exclude from the as-path\n"
5840 "./set-action[action='frr-bgp-route-map:as-path-exclude']";
5842 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5843 return nb_cli_apply_changes(vty
, NULL
);
5846 ALIAS_YANG (no_set_aspath_exclude
, no_set_aspath_exclude_all_cmd
,
5847 "no set as-path exclude",
5849 "Transform BGP AS_PATH attribute\n"
5850 "Exclude from the as-path\n")
5852 DEFUN_YANG (set_community
,
5854 "set community AA:NN...",
5856 "BGP community attribute\n"
5864 struct community
*com
= NULL
;
5866 char *argstr
= NULL
;
5870 "./set-action[action='frr-bgp-route-map:set-community']";
5871 char xpath_value
[XPATH_MAXLEN
];
5873 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5874 snprintf(xpath_value
, sizeof(xpath_value
),
5875 "%s/rmap-set-action/frr-bgp-route-map:community-string",
5878 b
= buffer_new(1024);
5880 for (i
= idx_aa_nn
; i
< argc
; i
++) {
5881 if (strncmp(argv
[i
]->arg
, "additive", strlen(argv
[i
]->arg
))
5888 buffer_putc(b
, ' ');
5892 if (strncmp(argv
[i
]->arg
, "internet", strlen(argv
[i
]->arg
))
5894 buffer_putstr(b
, "internet");
5897 if (strncmp(argv
[i
]->arg
, "local-AS", strlen(argv
[i
]->arg
))
5899 buffer_putstr(b
, "local-AS");
5902 if (strncmp(argv
[i
]->arg
, "no-a", strlen("no-a")) == 0
5903 && strncmp(argv
[i
]->arg
, "no-advertise",
5904 strlen(argv
[i
]->arg
))
5906 buffer_putstr(b
, "no-advertise");
5909 if (strncmp(argv
[i
]->arg
, "no-e", strlen("no-e")) == 0
5910 && strncmp(argv
[i
]->arg
, "no-export", strlen(argv
[i
]->arg
))
5912 buffer_putstr(b
, "no-export");
5915 if (strncmp(argv
[i
]->arg
, "blackhole", strlen(argv
[i
]->arg
))
5917 buffer_putstr(b
, "blackhole");
5920 if (strncmp(argv
[i
]->arg
, "graceful-shutdown",
5921 strlen(argv
[i
]->arg
))
5923 buffer_putstr(b
, "graceful-shutdown");
5926 buffer_putstr(b
, argv
[i
]->arg
);
5928 buffer_putc(b
, '\0');
5930 /* Fetch result string then compile it to communities attribute. */
5931 str
= buffer_getstr(b
);
5935 com
= community_str2com(str
);
5937 /* Can't compile user input into communities attribute. */
5939 vty_out(vty
, "%% Malformed communities attribute '%s'\n", str
);
5940 XFREE(MTYPE_TMP
, str
);
5941 return CMD_WARNING_CONFIG_FAILED
;
5943 XFREE(MTYPE_TMP
, str
);
5945 /* Set communites attribute string. */
5946 str
= community_str(com
, false, false);
5949 size_t argstr_sz
= strlen(str
) + strlen(" additive") + 1;
5950 argstr
= XCALLOC(MTYPE_TMP
, argstr_sz
);
5951 strlcpy(argstr
, str
, argstr_sz
);
5952 strlcat(argstr
, " additive", argstr_sz
);
5953 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argstr
);
5955 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
5957 ret
= nb_cli_apply_changes(vty
, NULL
);
5960 XFREE(MTYPE_TMP
, argstr
);
5961 community_free(&com
);
5966 DEFUN_YANG (set_community_none
,
5967 set_community_none_cmd
,
5968 "set community none",
5970 "BGP community attribute\n"
5971 "No community attribute\n")
5974 "./set-action[action='frr-bgp-route-map:set-community']";
5975 char xpath_value
[XPATH_MAXLEN
];
5977 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5979 snprintf(xpath_value
, sizeof(xpath_value
),
5980 "%s/rmap-set-action/frr-bgp-route-map:community-none", xpath
);
5981 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
5982 return nb_cli_apply_changes(vty
, NULL
);
5985 DEFUN_YANG (no_set_community
,
5986 no_set_community_cmd
,
5987 "no set community AA:NN...",
5990 "BGP community attribute\n"
5994 "./set-action[action='frr-bgp-route-map:set-community']";
5996 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5997 return nb_cli_apply_changes(vty
, NULL
);
6000 ALIAS_YANG (no_set_community
,
6001 no_set_community_short_cmd
,
6005 "BGP community attribute\n")
6007 DEFPY_YANG (set_community_delete
,
6008 set_community_delete_cmd
,
6009 "set comm-list <(1-99)|(100-500)|COMMUNITY_LIST_NAME> delete",
6011 "set BGP community list (for deletion)\n"
6012 "Community-list number (standard)\n"
6013 "Community-list number (expanded)\n"
6014 "Community-list name\n"
6015 "Delete matching communities\n")
6018 "./set-action[action='frr-bgp-route-map:comm-list-delete']";
6019 char xpath_value
[XPATH_MAXLEN
];
6020 int idx_comm_list
= 2;
6022 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6024 snprintf(xpath_value
, sizeof(xpath_value
),
6025 "%s/rmap-set-action/frr-bgp-route-map:comm-list-name",
6027 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6028 argv
[idx_comm_list
]->arg
);
6030 return nb_cli_apply_changes(vty
, NULL
);
6034 DEFUN_YANG (no_set_community_delete
,
6035 no_set_community_delete_cmd
,
6036 "no set comm-list [<(1-99)|(100-500)|COMMUNITY_LIST_NAME> delete]",
6039 "set BGP community list (for deletion)\n"
6040 "Community-list number (standard)\n"
6041 "Community-list number (expanded)\n"
6042 "Community-list name\n"
6043 "Delete matching communities\n")
6046 "./set-action[action='frr-bgp-route-map:comm-list-delete']";
6048 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6049 return nb_cli_apply_changes(vty
, NULL
);
6052 DEFUN_YANG (set_lcommunity
,
6054 "set large-community AA:BB:CC...",
6056 "BGP large community attribute\n"
6057 "Large Community number in aa:bb:cc format or additive\n")
6062 "./set-action[action='frr-bgp-route-map:set-large-community']";
6063 char xpath_value
[XPATH_MAXLEN
];
6065 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6067 snprintf(xpath_value
, sizeof(xpath_value
),
6068 "%s/rmap-set-action/frr-bgp-route-map:large-community-string",
6070 str
= argv_concat(argv
, argc
, 2);
6071 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
6072 ret
= nb_cli_apply_changes(vty
, NULL
);
6073 XFREE(MTYPE_TMP
, str
);
6077 DEFUN_YANG (set_lcommunity_none
,
6078 set_lcommunity_none_cmd
,
6079 "set large-community none",
6081 "BGP large community attribute\n"
6082 "No large community attribute\n")
6085 "./set-action[action='frr-bgp-route-map:set-large-community']";
6086 char xpath_value
[XPATH_MAXLEN
];
6088 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6090 snprintf(xpath_value
, sizeof(xpath_value
),
6091 "%s/rmap-set-action/frr-bgp-route-map:large-community-none",
6093 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
6094 return nb_cli_apply_changes(vty
, NULL
);
6097 DEFUN_YANG (no_set_lcommunity
,
6098 no_set_lcommunity_cmd
,
6099 "no set large-community none",
6102 "BGP large community attribute\n"
6103 "No community attribute\n")
6106 "./set-action[action='frr-bgp-route-map:set-large-community']";
6108 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6109 return nb_cli_apply_changes(vty
, NULL
);
6112 DEFUN_YANG (no_set_lcommunity1
,
6113 no_set_lcommunity1_cmd
,
6114 "no set large-community AA:BB:CC...",
6117 "BGP large community attribute\n"
6118 "Large community in AA:BB:CC... format or additive\n")
6121 "./set-action[action='frr-bgp-route-map:set-large-community']";
6123 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6124 return nb_cli_apply_changes(vty
, NULL
);
6127 ALIAS_YANG (no_set_lcommunity1
,
6128 no_set_lcommunity1_short_cmd
,
6129 "no set large-community",
6132 "BGP large community attribute\n")
6134 DEFPY_YANG (set_lcommunity_delete
,
6135 set_lcommunity_delete_cmd
,
6136 "set large-comm-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME> delete",
6138 "set BGP large community list (for deletion)\n"
6139 "Large Community-list number (standard)\n"
6140 "Large Communitly-list number (expanded)\n"
6141 "Large Community-list name\n"
6142 "Delete matching large communities\n")
6145 "./set-action[action='frr-bgp-route-map:large-comm-list-delete']";
6146 char xpath_value
[XPATH_MAXLEN
];
6147 int idx_lcomm_list
= 2;
6149 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6151 snprintf(xpath_value
, sizeof(xpath_value
),
6152 "%s/rmap-set-action/frr-bgp-route-map:comm-list-name",
6154 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6155 argv
[idx_lcomm_list
]->arg
);
6157 return nb_cli_apply_changes(vty
, NULL
);
6160 DEFUN_YANG (no_set_lcommunity_delete
,
6161 no_set_lcommunity_delete_cmd
,
6162 "no set large-comm-list <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME> [delete]",
6165 "set BGP large community list (for deletion)\n"
6166 "Large Community-list number (standard)\n"
6167 "Large Communitly-list number (expanded)\n"
6168 "Large Community-list name\n"
6169 "Delete matching large communities\n")
6172 "./set-action[action='frr-bgp-route-map:large-comm-list-delete']";
6174 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6175 return nb_cli_apply_changes(vty
, NULL
);
6178 ALIAS_YANG (no_set_lcommunity_delete
,
6179 no_set_lcommunity_delete_short_cmd
,
6180 "no set large-comm-list",
6183 "set BGP large community list (for deletion)\n")
6185 DEFUN_YANG (set_ecommunity_rt
,
6186 set_ecommunity_rt_cmd
,
6187 "set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
6189 "BGP extended community attribute\n"
6190 "Route Target extended community\n"
6191 "VPN extended community\n")
6197 "./set-action[action='frr-bgp-route-map:set-extcommunity-rt']";
6198 char xpath_value
[XPATH_MAXLEN
];
6200 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6202 snprintf(xpath_value
, sizeof(xpath_value
),
6203 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-rt", xpath
);
6204 str
= argv_concat(argv
, argc
, idx_asn_nn
);
6205 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
6206 ret
= nb_cli_apply_changes(vty
, NULL
);
6207 XFREE(MTYPE_TMP
, str
);
6211 DEFUN_YANG (no_set_ecommunity_rt
,
6212 no_set_ecommunity_rt_cmd
,
6213 "no set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
6216 "BGP extended community attribute\n"
6217 "Route Target extended community\n"
6218 "VPN extended community\n")
6221 "./set-action[action='frr-bgp-route-map:set-extcommunity-rt']";
6222 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6223 return nb_cli_apply_changes(vty
, NULL
);
6226 ALIAS_YANG (no_set_ecommunity_rt
,
6227 no_set_ecommunity_rt_short_cmd
,
6228 "no set extcommunity rt",
6231 "BGP extended community attribute\n"
6232 "Route Target extended community\n")
6234 DEFUN_YANG (set_ecommunity_soo
,
6235 set_ecommunity_soo_cmd
,
6236 "set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
6238 "BGP extended community attribute\n"
6239 "Site-of-Origin extended community\n"
6240 "VPN extended community\n")
6246 "./set-action[action='frr-bgp-route-map:set-extcommunity-soo']";
6247 char xpath_value
[XPATH_MAXLEN
];
6249 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6251 snprintf(xpath_value
, sizeof(xpath_value
),
6252 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-soo",
6254 str
= argv_concat(argv
, argc
, idx_asn_nn
);
6255 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
6256 ret
= nb_cli_apply_changes(vty
, NULL
);
6257 XFREE(MTYPE_TMP
, str
);
6261 DEFUN_YANG (no_set_ecommunity_soo
,
6262 no_set_ecommunity_soo_cmd
,
6263 "no set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
6266 "BGP extended community attribute\n"
6267 "Site-of-Origin extended community\n"
6268 "VPN extended community\n")
6271 "./set-action[action='frr-bgp-route-map:set-extcommunity-soo']";
6272 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6273 return nb_cli_apply_changes(vty
, NULL
);
6276 ALIAS_YANG (no_set_ecommunity_soo
,
6277 no_set_ecommunity_soo_short_cmd
,
6278 "no set extcommunity soo",
6281 "GP extended community attribute\n"
6282 "Site-of-Origin extended community\n")
6284 DEFUN_YANG(set_ecommunity_none
, set_ecommunity_none_cmd
,
6285 "set extcommunity none",
6287 "BGP extended community attribute\n"
6288 "No extended community attribute\n")
6291 "./set-action[action='frr-bgp-route-map:set-extcommunity-none']";
6292 char xpath_value
[XPATH_MAXLEN
];
6294 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6296 snprintf(xpath_value
, sizeof(xpath_value
),
6297 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-none",
6299 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
6300 return nb_cli_apply_changes(vty
, NULL
);
6303 DEFUN_YANG(no_set_ecommunity_none
, no_set_ecommunity_none_cmd
,
6304 "no set extcommunity none",
6306 "BGP extended community attribute\n"
6307 "No extended community attribute\n")
6310 "./set-action[action='frr-bgp-route-map:set-extcommunity-none']";
6311 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6312 return nb_cli_apply_changes(vty
, NULL
);
6315 DEFUN_YANG (set_ecommunity_lb
,
6316 set_ecommunity_lb_cmd
,
6317 "set extcommunity bandwidth <(1-25600)|cumulative|num-multipaths> [non-transitive]",
6319 "BGP extended community attribute\n"
6320 "Link bandwidth extended community\n"
6321 "Bandwidth value in Mbps\n"
6322 "Cumulative bandwidth of all multipaths (outbound-only)\n"
6323 "Internally computed bandwidth based on number of multipaths (outbound-only)\n"
6324 "Attribute is set as non-transitive\n")
6327 int idx_non_transitive
= 0;
6329 "./set-action[action='frr-bgp-route-map:set-extcommunity-lb']";
6330 char xpath_lb_type
[XPATH_MAXLEN
];
6331 char xpath_bandwidth
[XPATH_MAXLEN
];
6332 char xpath_non_transitive
[XPATH_MAXLEN
];
6334 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6336 snprintf(xpath_lb_type
, sizeof(xpath_lb_type
),
6337 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-lb/lb-type",
6339 snprintf(xpath_bandwidth
, sizeof(xpath_bandwidth
),
6340 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-lb/bandwidth",
6342 snprintf(xpath_non_transitive
, sizeof(xpath_non_transitive
),
6343 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-lb/two-octet-as-specific",
6346 if ((strcmp(argv
[idx_lb
]->arg
, "cumulative")) == 0)
6347 nb_cli_enqueue_change(vty
, xpath_lb_type
, NB_OP_MODIFY
,
6348 "cumulative-bandwidth");
6349 else if ((strcmp(argv
[idx_lb
]->arg
, "num-multipaths")) == 0)
6350 nb_cli_enqueue_change(vty
, xpath_lb_type
, NB_OP_MODIFY
,
6351 "computed-bandwidth");
6353 nb_cli_enqueue_change(vty
, xpath_lb_type
, NB_OP_MODIFY
,
6354 "explicit-bandwidth");
6355 nb_cli_enqueue_change(vty
, xpath_bandwidth
, NB_OP_MODIFY
,
6359 if (argv_find(argv
, argc
, "non-transitive", &idx_non_transitive
))
6360 nb_cli_enqueue_change(vty
, xpath_non_transitive
, NB_OP_MODIFY
,
6363 nb_cli_enqueue_change(vty
, xpath_non_transitive
, NB_OP_MODIFY
,
6366 return nb_cli_apply_changes(vty
, NULL
);
6369 DEFUN_YANG (no_set_ecommunity_lb
,
6370 no_set_ecommunity_lb_cmd
,
6371 "no set extcommunity bandwidth <(1-25600)|cumulative|num-multipaths> [non-transitive]",
6374 "BGP extended community attribute\n"
6375 "Link bandwidth extended community\n"
6376 "Bandwidth value in Mbps\n"
6377 "Cumulative bandwidth of all multipaths (outbound-only)\n"
6378 "Internally computed bandwidth based on number of multipaths (outbound-only)\n"
6379 "Attribute is set as non-transitive\n")
6382 "./set-action[action='frr-bgp-route-map:set-extcommunity-lb']";
6384 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6385 return nb_cli_apply_changes(vty
, NULL
);
6388 ALIAS_YANG (no_set_ecommunity_lb
,
6389 no_set_ecommunity_lb_short_cmd
,
6390 "no set extcommunity bandwidth",
6393 "BGP extended community attribute\n"
6394 "Link bandwidth extended community\n")
6396 DEFUN_YANG (set_origin
,
6398 "set origin <egp|igp|incomplete>",
6403 "unknown heritage\n")
6406 const char *origin_type
;
6408 "./set-action[action='frr-bgp-route-map:set-origin']";
6409 char xpath_value
[XPATH_MAXLEN
];
6411 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
6412 origin_type
= "igp";
6413 else if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
6414 origin_type
= "egp";
6415 else if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
6416 origin_type
= "incomplete";
6418 vty_out(vty
, "%% Invalid match origin type\n");
6419 return CMD_WARNING_CONFIG_FAILED
;
6422 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6423 snprintf(xpath_value
, sizeof(xpath_value
),
6424 "%s/rmap-set-action/frr-bgp-route-map:origin", xpath
);
6425 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, origin_type
);
6427 return nb_cli_apply_changes(vty
, NULL
);
6430 DEFUN_YANG (no_set_origin
,
6432 "no set origin [<egp|igp|incomplete>]",
6438 "unknown heritage\n")
6441 "./set-action[action='frr-bgp-route-map:set-origin']";
6443 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6444 return nb_cli_apply_changes(vty
, NULL
);
6447 DEFUN_YANG (set_atomic_aggregate
,
6448 set_atomic_aggregate_cmd
,
6449 "set atomic-aggregate",
6451 "BGP atomic aggregate attribute\n" )
6454 "./set-action[action='frr-bgp-route-map:atomic-aggregate']";
6455 char xpath_value
[XPATH_MAXLEN
];
6457 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6458 snprintf(xpath_value
, sizeof(xpath_value
),
6459 "%s/rmap-set-action/frr-bgp-route-map:atomic-aggregate",
6461 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, NULL
);
6463 return nb_cli_apply_changes(vty
, NULL
);
6466 DEFUN_YANG (no_set_atomic_aggregate
,
6467 no_set_atomic_aggregate_cmd
,
6468 "no set atomic-aggregate",
6471 "BGP atomic aggregate attribute\n" )
6474 "./set-action[action='frr-bgp-route-map:atomic-aggregate']";
6476 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6477 return nb_cli_apply_changes(vty
, NULL
);
6480 DEFPY_YANG (set_aigp_metric
,
6481 set_aigp_metric_cmd
,
6482 "set aigp-metric <igp-metric|(1-4294967295)>$aigp_metric",
6484 "BGP AIGP attribute (AIGP Metric TLV)\n"
6485 "AIGP Metric value from IGP protocol\n"
6486 "Manual AIGP Metric value\n")
6489 "./set-action[action='frr-bgp-route-map:aigp-metric']";
6490 char xpath_value
[XPATH_MAXLEN
];
6492 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6493 snprintf(xpath_value
, sizeof(xpath_value
),
6494 "%s/rmap-set-action/frr-bgp-route-map:aigp-metric", xpath
);
6495 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, aigp_metric
);
6497 return nb_cli_apply_changes(vty
, NULL
);
6500 DEFPY_YANG (no_set_aigp_metric
,
6501 no_set_aigp_metric_cmd
,
6502 "no set aigp-metric [<igp-metric|(1-4294967295)>]",
6505 "BGP AIGP attribute (AIGP Metric TLV)\n"
6506 "AIGP Metric value from IGP protocol\n"
6507 "Manual AIGP Metric value\n")
6510 "./set-action[action='frr-bgp-route-map:aigp-metric']";
6512 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6513 return nb_cli_apply_changes(vty
, NULL
);
6516 DEFUN_YANG (set_aggregator_as
,
6517 set_aggregator_as_cmd
,
6518 "set aggregator as (1-4294967295) A.B.C.D",
6520 "BGP aggregator attribute\n"
6521 "AS number of aggregator\n"
6523 "IP address of aggregator\n")
6527 char xpath_asn
[XPATH_MAXLEN
];
6528 char xpath_addr
[XPATH_MAXLEN
];
6530 "./set-action[action='frr-bgp-route-map:aggregator']";
6532 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6535 xpath_asn
, sizeof(xpath_asn
),
6536 "%s/rmap-set-action/frr-bgp-route-map:aggregator/aggregator-asn",
6538 nb_cli_enqueue_change(vty
, xpath_asn
, NB_OP_MODIFY
,
6539 argv
[idx_number
]->arg
);
6542 xpath_addr
, sizeof(xpath_addr
),
6543 "%s/rmap-set-action/frr-bgp-route-map:aggregator/aggregator-address",
6545 nb_cli_enqueue_change(vty
, xpath_addr
, NB_OP_MODIFY
,
6546 argv
[idx_ipv4
]->arg
);
6548 return nb_cli_apply_changes(vty
, NULL
);
6551 DEFUN_YANG (no_set_aggregator_as
,
6552 no_set_aggregator_as_cmd
,
6553 "no set aggregator as [(1-4294967295) A.B.C.D]",
6556 "BGP aggregator attribute\n"
6557 "AS number of aggregator\n"
6559 "IP address of aggregator\n")
6562 "./set-action[action='frr-bgp-route-map:aggregator']";
6564 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6565 return nb_cli_apply_changes(vty
, NULL
);
6568 DEFUN_YANG (match_ipv6_next_hop
,
6569 match_ipv6_next_hop_cmd
,
6570 "match ipv6 next-hop ACCESSLIST6_NAME",
6573 "Match IPv6 next-hop address of route\n"
6574 "IPv6 access-list name\n")
6577 "./match-condition[condition='frr-route-map:ipv6-next-hop-list']";
6578 char xpath_value
[XPATH_MAXLEN
];
6580 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6581 snprintf(xpath_value
, sizeof(xpath_value
),
6582 "%s/rmap-match-condition/list-name", xpath
);
6583 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6584 argv
[argc
- 1]->arg
);
6586 return nb_cli_apply_changes(vty
, NULL
);
6589 DEFUN_YANG (no_match_ipv6_next_hop
,
6590 no_match_ipv6_next_hop_cmd
,
6591 "no match ipv6 next-hop [ACCESSLIST6_NAME]",
6595 "Match IPv6 next-hop address of route\n"
6596 "IPv6 access-list name\n")
6599 "./match-condition[condition='frr-route-map:ipv6-next-hop-list']";
6601 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6602 return nb_cli_apply_changes(vty
, NULL
);
6605 DEFUN_YANG (match_ipv6_next_hop_address
,
6606 match_ipv6_next_hop_address_cmd
,
6607 "match ipv6 next-hop address X:X::X:X",
6610 "Match IPv6 next-hop address of route\n"
6612 "IPv6 address of next hop\n")
6615 "./match-condition[condition='frr-bgp-route-map:ipv6-nexthop']";
6616 char xpath_value
[XPATH_MAXLEN
];
6618 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6619 snprintf(xpath_value
, sizeof(xpath_value
),
6620 "%s/rmap-match-condition/frr-bgp-route-map:ipv6-address",
6622 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6623 argv
[argc
- 1]->arg
);
6625 return nb_cli_apply_changes(vty
, NULL
);
6628 DEFUN_YANG (no_match_ipv6_next_hop_address
,
6629 no_match_ipv6_next_hop_address_cmd
,
6630 "no match ipv6 next-hop address X:X::X:X",
6634 "Match IPv6 next-hop address of route\n"
6636 "IPv6 address of next hop\n")
6639 "./match-condition[condition='frr-bgp-route-map:ipv6-nexthop']";
6641 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6642 return nb_cli_apply_changes(vty
, NULL
);
6645 ALIAS_HIDDEN (match_ipv6_next_hop_address
,
6646 match_ipv6_next_hop_old_cmd
,
6647 "match ipv6 next-hop X:X::X:X",
6650 "Match IPv6 next-hop address of route\n"
6651 "IPv6 address of next hop\n")
6653 ALIAS_HIDDEN (no_match_ipv6_next_hop_address
,
6654 no_match_ipv6_next_hop_old_cmd
,
6655 "no match ipv6 next-hop X:X::X:X",
6659 "Match IPv6 next-hop address of route\n"
6660 "IPv6 address of next hop\n")
6662 DEFUN_YANG (match_ipv6_next_hop_prefix_list
,
6663 match_ipv6_next_hop_prefix_list_cmd
,
6664 "match ipv6 next-hop prefix-list PREFIXLIST_NAME",
6667 "Match IPv6 next-hop address of route\n"
6668 "Match entries by prefix-list\n"
6669 "IPv6 prefix-list name\n")
6672 "./match-condition[condition='frr-route-map:ipv6-next-hop-prefix-list']";
6673 char xpath_value
[XPATH_MAXLEN
];
6675 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6676 snprintf(xpath_value
, sizeof(xpath_value
),
6677 "%s/rmap-match-condition/list-name", xpath
);
6678 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6679 argv
[argc
- 1]->arg
);
6681 return nb_cli_apply_changes(vty
, NULL
);
6684 DEFUN_YANG (no_match_ipv6_next_hop_prefix_list
,
6685 no_match_ipv6_next_hop_prefix_list_cmd
,
6686 "no match ipv6 next-hop prefix-list [PREFIXLIST_NAME]",
6690 "Match IPv6 next-hop address of route\n"
6691 "Match entries by prefix-list\n"
6692 "IPv6 prefix-list name\n")
6695 "./match-condition[condition='frr-route-map:ipv6-next-hop-prefix-list']";
6697 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6698 return nb_cli_apply_changes(vty
, NULL
);
6701 DEFPY_YANG (match_ipv4_next_hop
,
6702 match_ipv4_next_hop_cmd
,
6703 "match ip next-hop address A.B.C.D",
6706 "Match IP next-hop address of route\n"
6708 "IP address of next-hop\n")
6711 "./match-condition[condition='frr-bgp-route-map:ipv4-nexthop']";
6712 char xpath_value
[XPATH_MAXLEN
];
6714 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6715 snprintf(xpath_value
, sizeof(xpath_value
),
6716 "%s/rmap-match-condition/frr-bgp-route-map:ipv4-address",
6718 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[4]->arg
);
6720 return nb_cli_apply_changes(vty
, NULL
);
6723 DEFPY_YANG (no_match_ipv4_next_hop
,
6724 no_match_ipv4_next_hop_cmd
,
6725 "no match ip next-hop address [A.B.C.D]",
6729 "Match IP next-hop address of route\n"
6731 "IP address of next-hop\n")
6734 "./match-condition[condition='frr-bgp-route-map:ipv4-nexthop']";
6736 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6737 return nb_cli_apply_changes(vty
, NULL
);
6740 DEFUN_YANG (set_ipv6_nexthop_peer
,
6741 set_ipv6_nexthop_peer_cmd
,
6742 "set ipv6 next-hop peer-address",
6745 "Next hop address\n"
6746 "Use peer address (for BGP only)\n")
6749 "./set-action[action='frr-bgp-route-map:ipv6-peer-address']";
6750 char xpath_value
[XPATH_MAXLEN
];
6752 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6753 snprintf(xpath_value
, sizeof(xpath_value
),
6754 "%s/rmap-set-action/frr-bgp-route-map:preference", xpath
);
6755 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
6757 return nb_cli_apply_changes(vty
, NULL
);
6760 DEFUN_YANG (no_set_ipv6_nexthop_peer
,
6761 no_set_ipv6_nexthop_peer_cmd
,
6762 "no set ipv6 next-hop peer-address",
6766 "IPv6 next-hop address\n"
6767 "Use peer address (for BGP only)\n")
6770 "./set-action[action='frr-bgp-route-map:ipv6-peer-address']";
6772 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6773 return nb_cli_apply_changes(vty
, NULL
);
6776 DEFUN_YANG (set_ipv6_nexthop_prefer_global
,
6777 set_ipv6_nexthop_prefer_global_cmd
,
6778 "set ipv6 next-hop prefer-global",
6781 "IPv6 next-hop address\n"
6782 "Prefer global over link-local if both exist\n")
6785 "./set-action[action='frr-bgp-route-map:ipv6-prefer-global']";
6786 char xpath_value
[XPATH_MAXLEN
];
6788 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6789 snprintf(xpath_value
, sizeof(xpath_value
),
6790 "%s/rmap-set-action/frr-bgp-route-map:preference", xpath
);
6791 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
6793 return nb_cli_apply_changes(vty
, NULL
);
6796 DEFUN_YANG (no_set_ipv6_nexthop_prefer_global
,
6797 no_set_ipv6_nexthop_prefer_global_cmd
,
6798 "no set ipv6 next-hop prefer-global",
6802 "IPv6 next-hop address\n"
6803 "Prefer global over link-local if both exist\n")
6806 "./set-action[action='frr-bgp-route-map:ipv6-prefer-global']";
6808 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6809 return nb_cli_apply_changes(vty
, NULL
);
6812 DEFUN_YANG (set_ipv6_nexthop_global
,
6813 set_ipv6_nexthop_global_cmd
,
6814 "set ipv6 next-hop global X:X::X:X",
6817 "IPv6 next-hop address\n"
6818 "IPv6 global address\n"
6819 "IPv6 address of next hop\n")
6823 "./set-action[action='frr-bgp-route-map:ipv6-nexthop-global']";
6824 char xpath_value
[XPATH_MAXLEN
];
6826 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6827 snprintf(xpath_value
, sizeof(xpath_value
),
6828 "%s/rmap-set-action/frr-bgp-route-map:ipv6-address", xpath
);
6829 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6830 argv
[idx_ipv6
]->arg
);
6832 return nb_cli_apply_changes(vty
, NULL
);
6835 DEFUN_YANG (no_set_ipv6_nexthop_global
,
6836 no_set_ipv6_nexthop_global_cmd
,
6837 "no set ipv6 next-hop global X:X::X:X",
6841 "IPv6 next-hop address\n"
6842 "IPv6 global address\n"
6843 "IPv6 address of next hop\n")
6846 "./set-action[action='frr-bgp-route-map:ipv6-nexthop-global']";
6848 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6849 return nb_cli_apply_changes(vty
, NULL
);
6852 #ifdef KEEP_OLD_VPN_COMMANDS
6853 DEFUN_YANG (set_vpn_nexthop
,
6854 set_vpn_nexthop_cmd
,
6855 "set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
6857 "VPNv4 information\n"
6858 "VPN next-hop address\n"
6859 "IP address of next hop\n"
6860 "VPNv6 information\n"
6861 "VPN next-hop address\n"
6862 "IPv6 address of next hop\n")
6867 char xpath_value
[XPATH_MAXLEN
];
6869 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
6870 if (afi
== AFI_IP
) {
6872 "./set-action[action='frr-bgp-route-map:ipv4-vpn-address']";
6874 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6876 xpath_value
, sizeof(xpath_value
),
6877 "%s/rmap-set-action/frr-bgp-route-map:ipv4-address",
6881 "./set-action[action='frr-bgp-route-map:ipv6-vpn-address']";
6883 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6885 xpath_value
, sizeof(xpath_value
),
6886 "%s/rmap-set-action/frr-bgp-route-map:ipv6-address",
6890 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6893 return nb_cli_apply_changes(vty
, NULL
);
6899 DEFUN_YANG (no_set_vpn_nexthop
,
6900 no_set_vpn_nexthop_cmd
,
6901 "no set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
6904 "VPNv4 information\n"
6905 "VPN next-hop address\n"
6906 "IP address of next hop\n"
6907 "VPNv6 information\n"
6908 "VPN next-hop address\n"
6909 "IPv6 address of next hop\n")
6914 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
6915 if (afi
== AFI_IP
) {
6917 "./set-action[action='frr-bgp-route-map:ipv4-vpn-address']";
6918 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6921 "./set-action[action='frr-bgp-route-map:ipv6-vpn-address']";
6922 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6924 return nb_cli_apply_changes(vty
, NULL
);
6928 #endif /* KEEP_OLD_VPN_COMMANDS */
6930 DEFPY_YANG (set_ipx_vpn_nexthop
,
6931 set_ipx_vpn_nexthop_cmd
,
6932 "set <ipv4|ipv6> vpn next-hop <A.B.C.D$addrv4|X:X::X:X$addrv6>",
6934 "IPv4 information\n"
6935 "IPv6 information\n"
6937 "VPN next-hop address\n"
6938 "IP address of next hop\n"
6939 "IPv6 address of next hop\n")
6944 char xpath_value
[XPATH_MAXLEN
];
6946 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
6947 if (afi
== AFI_IP
) {
6949 vty_out(vty
, "%% IPv4 next-hop expected\n");
6950 return CMD_WARNING_CONFIG_FAILED
;
6954 "./set-action[action='frr-bgp-route-map:ipv4-vpn-address']";
6956 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6958 xpath_value
, sizeof(xpath_value
),
6959 "%s/rmap-set-action/frr-bgp-route-map:ipv4-address",
6963 vty_out(vty
, "%% IPv6 next-hop expected\n");
6964 return CMD_WARNING_CONFIG_FAILED
;
6968 "./set-action[action='frr-bgp-route-map:ipv6-vpn-address']";
6970 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6972 xpath_value
, sizeof(xpath_value
),
6973 "%s/rmap-set-action/frr-bgp-route-map:ipv6-address",
6976 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6978 return nb_cli_apply_changes(vty
, NULL
);
6983 DEFUN_YANG (no_set_ipx_vpn_nexthop
,
6984 no_set_ipx_vpn_nexthop_cmd
,
6985 "no set <ipv4|ipv6> vpn next-hop [<A.B.C.D|X:X::X:X>]",
6988 "IPv4 information\n"
6989 "IPv6 information\n"
6991 "VPN next-hop address\n"
6992 "IP address of next hop\n"
6993 "IPv6 address of next hop\n")
6998 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
6999 if (afi
== AFI_IP
) {
7001 "./set-action[action='frr-bgp-route-map:ipv4-vpn-address']";
7002 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
7005 "./set-action[action='frr-bgp-route-map:ipv6-vpn-address']";
7006 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
7008 return nb_cli_apply_changes(vty
, NULL
);
7013 DEFUN_YANG (set_originator_id
,
7014 set_originator_id_cmd
,
7015 "set originator-id A.B.C.D",
7017 "BGP originator ID attribute\n"
7018 "IP address of originator\n")
7022 "./set-action[action='frr-bgp-route-map:originator-id']";
7023 char xpath_value
[XPATH_MAXLEN
];
7025 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
7026 snprintf(xpath_value
, sizeof(xpath_value
),
7027 "%s/rmap-set-action/frr-bgp-route-map:originator-id", xpath
);
7028 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
7029 argv
[idx_ipv4
]->arg
);
7031 return nb_cli_apply_changes(vty
, NULL
);
7034 DEFUN_YANG (no_set_originator_id
,
7035 no_set_originator_id_cmd
,
7036 "no set originator-id [A.B.C.D]",
7039 "BGP originator ID attribute\n"
7040 "IP address of originator\n")
7043 "./set-action[action='frr-bgp-route-map:originator-id']";
7045 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
7046 return nb_cli_apply_changes(vty
, NULL
);
7049 DEFPY_YANG (match_rpki_extcommunity
,
7050 match_rpki_extcommunity_cmd
,
7051 "[no$no] match rpki-extcommunity <valid|invalid|notfound>",
7054 "BGP RPKI (Origin Validation State) extended community attribute\n"
7057 "Prefix not found\n")
7060 "./match-condition[condition='frr-bgp-route-map:rpki-extcommunity']";
7061 char xpath_value
[XPATH_MAXLEN
];
7063 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
7067 xpath_value
, sizeof(xpath_value
),
7068 "%s/rmap-match-condition/frr-bgp-route-map:rpki-extcommunity",
7070 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
7074 return nb_cli_apply_changes(vty
, NULL
);
7077 /* Initialization of route map. */
7078 void bgp_route_map_init(void)
7082 route_map_add_hook(bgp_route_map_add
);
7083 route_map_delete_hook(bgp_route_map_delete
);
7084 route_map_event_hook(bgp_route_map_event
);
7086 route_map_match_interface_hook(generic_match_add
);
7087 route_map_no_match_interface_hook(generic_match_delete
);
7089 route_map_match_ip_address_hook(generic_match_add
);
7090 route_map_no_match_ip_address_hook(generic_match_delete
);
7092 route_map_match_ip_address_prefix_list_hook(generic_match_add
);
7093 route_map_no_match_ip_address_prefix_list_hook(generic_match_delete
);
7095 route_map_match_ip_next_hop_hook(generic_match_add
);
7096 route_map_no_match_ip_next_hop_hook(generic_match_delete
);
7098 route_map_match_ipv6_next_hop_hook(generic_match_add
);
7099 route_map_no_match_ipv6_next_hop_hook(generic_match_delete
);
7101 route_map_match_ip_next_hop_prefix_list_hook(generic_match_add
);
7102 route_map_no_match_ip_next_hop_prefix_list_hook(generic_match_delete
);
7104 route_map_match_ip_next_hop_type_hook(generic_match_add
);
7105 route_map_no_match_ip_next_hop_type_hook(generic_match_delete
);
7107 route_map_match_ipv6_address_hook(generic_match_add
);
7108 route_map_no_match_ipv6_address_hook(generic_match_delete
);
7110 route_map_match_ipv6_address_prefix_list_hook(generic_match_add
);
7111 route_map_no_match_ipv6_address_prefix_list_hook(generic_match_delete
);
7113 route_map_match_ipv6_next_hop_type_hook(generic_match_add
);
7114 route_map_no_match_ipv6_next_hop_type_hook(generic_match_delete
);
7116 route_map_match_ipv6_next_hop_prefix_list_hook(generic_match_add
);
7117 route_map_no_match_ipv6_next_hop_prefix_list_hook(generic_match_delete
);
7119 route_map_match_metric_hook(generic_match_add
);
7120 route_map_no_match_metric_hook(generic_match_delete
);
7122 route_map_match_tag_hook(generic_match_add
);
7123 route_map_no_match_tag_hook(generic_match_delete
);
7125 route_map_set_srte_color_hook(generic_set_add
);
7126 route_map_no_set_srte_color_hook(generic_set_delete
);
7128 route_map_set_ip_nexthop_hook(generic_set_add
);
7129 route_map_no_set_ip_nexthop_hook(generic_set_delete
);
7131 route_map_set_ipv6_nexthop_local_hook(generic_set_add
);
7132 route_map_no_set_ipv6_nexthop_local_hook(generic_set_delete
);
7134 route_map_set_metric_hook(generic_set_add
);
7135 route_map_no_set_metric_hook(generic_set_delete
);
7137 route_map_set_tag_hook(generic_set_add
);
7138 route_map_no_set_tag_hook(generic_set_delete
);
7140 route_map_install_match(&route_match_peer_cmd
);
7141 route_map_install_match(&route_match_alias_cmd
);
7142 route_map_install_match(&route_match_local_pref_cmd
);
7143 #ifdef HAVE_SCRIPTING
7144 route_map_install_match(&route_match_script_cmd
);
7146 route_map_install_match(&route_match_ip_address_cmd
);
7147 route_map_install_match(&route_match_ip_next_hop_cmd
);
7148 route_map_install_match(&route_match_ip_route_source_cmd
);
7149 route_map_install_match(&route_match_ip_address_prefix_list_cmd
);
7150 route_map_install_match(&route_match_ip_next_hop_prefix_list_cmd
);
7151 route_map_install_match(&route_match_ip_next_hop_type_cmd
);
7152 route_map_install_match(&route_match_ip_route_source_prefix_list_cmd
);
7153 route_map_install_match(&route_match_aspath_cmd
);
7154 route_map_install_match(&route_match_community_cmd
);
7155 route_map_install_match(&route_match_lcommunity_cmd
);
7156 route_map_install_match(&route_match_ecommunity_cmd
);
7157 route_map_install_match(&route_match_local_pref_cmd
);
7158 route_map_install_match(&route_match_metric_cmd
);
7159 route_map_install_match(&route_match_origin_cmd
);
7160 route_map_install_match(&route_match_probability_cmd
);
7161 route_map_install_match(&route_match_interface_cmd
);
7162 route_map_install_match(&route_match_tag_cmd
);
7163 route_map_install_match(&route_match_mac_address_cmd
);
7164 route_map_install_match(&route_match_evpn_vni_cmd
);
7165 route_map_install_match(&route_match_evpn_route_type_cmd
);
7166 route_map_install_match(&route_match_evpn_rd_cmd
);
7167 route_map_install_match(&route_match_evpn_default_route_cmd
);
7168 route_map_install_match(&route_match_vrl_source_vrf_cmd
);
7170 route_map_install_set(&route_set_evpn_gateway_ip_ipv4_cmd
);
7171 route_map_install_set(&route_set_evpn_gateway_ip_ipv6_cmd
);
7172 route_map_install_set(&route_set_table_id_cmd
);
7173 route_map_install_set(&route_set_srte_color_cmd
);
7174 route_map_install_set(&route_set_ip_nexthop_cmd
);
7175 route_map_install_set(&route_set_local_pref_cmd
);
7176 route_map_install_set(&route_set_weight_cmd
);
7177 route_map_install_set(&route_set_label_index_cmd
);
7178 route_map_install_set(&route_set_metric_cmd
);
7179 route_map_install_set(&route_set_distance_cmd
);
7180 route_map_install_set(&route_set_aspath_prepend_cmd
);
7181 route_map_install_set(&route_set_aspath_exclude_cmd
);
7182 route_map_install_set(&route_set_aspath_replace_cmd
);
7183 route_map_install_set(&route_set_origin_cmd
);
7184 route_map_install_set(&route_set_atomic_aggregate_cmd
);
7185 route_map_install_set(&route_set_aigp_metric_cmd
);
7186 route_map_install_set(&route_set_aggregator_as_cmd
);
7187 route_map_install_set(&route_set_community_cmd
);
7188 route_map_install_set(&route_set_community_delete_cmd
);
7189 route_map_install_set(&route_set_lcommunity_cmd
);
7190 route_map_install_set(&route_set_lcommunity_delete_cmd
);
7191 route_map_install_set(&route_set_vpnv4_nexthop_cmd
);
7192 route_map_install_set(&route_set_vpnv6_nexthop_cmd
);
7193 route_map_install_set(&route_set_originator_id_cmd
);
7194 route_map_install_set(&route_set_ecommunity_rt_cmd
);
7195 route_map_install_set(&route_set_ecommunity_soo_cmd
);
7196 route_map_install_set(&route_set_ecommunity_lb_cmd
);
7197 route_map_install_set(&route_set_ecommunity_none_cmd
);
7198 route_map_install_set(&route_set_tag_cmd
);
7199 route_map_install_set(&route_set_label_index_cmd
);
7200 route_map_install_set(&route_set_l3vpn_nexthop_encapsulation_cmd
);
7202 install_element(RMAP_NODE
, &match_peer_cmd
);
7203 install_element(RMAP_NODE
, &match_peer_local_cmd
);
7204 install_element(RMAP_NODE
, &no_match_peer_cmd
);
7205 install_element(RMAP_NODE
, &match_ip_route_source_cmd
);
7206 install_element(RMAP_NODE
, &no_match_ip_route_source_cmd
);
7207 install_element(RMAP_NODE
, &match_ip_route_source_prefix_list_cmd
);
7208 install_element(RMAP_NODE
, &no_match_ip_route_source_prefix_list_cmd
);
7209 install_element(RMAP_NODE
, &match_mac_address_cmd
);
7210 install_element(RMAP_NODE
, &no_match_mac_address_cmd
);
7211 install_element(RMAP_NODE
, &match_evpn_vni_cmd
);
7212 install_element(RMAP_NODE
, &no_match_evpn_vni_cmd
);
7213 install_element(RMAP_NODE
, &match_evpn_route_type_cmd
);
7214 install_element(RMAP_NODE
, &no_match_evpn_route_type_cmd
);
7215 install_element(RMAP_NODE
, &match_evpn_rd_cmd
);
7216 install_element(RMAP_NODE
, &no_match_evpn_rd_cmd
);
7217 install_element(RMAP_NODE
, &match_evpn_default_route_cmd
);
7218 install_element(RMAP_NODE
, &no_match_evpn_default_route_cmd
);
7219 install_element(RMAP_NODE
, &set_evpn_gw_ip_ipv4_cmd
);
7220 install_element(RMAP_NODE
, &no_set_evpn_gw_ip_ipv4_cmd
);
7221 install_element(RMAP_NODE
, &set_evpn_gw_ip_ipv6_cmd
);
7222 install_element(RMAP_NODE
, &no_set_evpn_gw_ip_ipv6_cmd
);
7223 install_element(RMAP_NODE
, &match_vrl_source_vrf_cmd
);
7224 install_element(RMAP_NODE
, &no_match_vrl_source_vrf_cmd
);
7226 install_element(RMAP_NODE
, &match_aspath_cmd
);
7227 install_element(RMAP_NODE
, &no_match_aspath_cmd
);
7228 install_element(RMAP_NODE
, &match_local_pref_cmd
);
7229 install_element(RMAP_NODE
, &no_match_local_pref_cmd
);
7230 install_element(RMAP_NODE
, &match_alias_cmd
);
7231 install_element(RMAP_NODE
, &no_match_alias_cmd
);
7232 install_element(RMAP_NODE
, &match_community_cmd
);
7233 install_element(RMAP_NODE
, &no_match_community_cmd
);
7234 install_element(RMAP_NODE
, &match_lcommunity_cmd
);
7235 install_element(RMAP_NODE
, &no_match_lcommunity_cmd
);
7236 install_element(RMAP_NODE
, &match_ecommunity_cmd
);
7237 install_element(RMAP_NODE
, &no_match_ecommunity_cmd
);
7238 install_element(RMAP_NODE
, &match_origin_cmd
);
7239 install_element(RMAP_NODE
, &no_match_origin_cmd
);
7240 install_element(RMAP_NODE
, &match_probability_cmd
);
7241 install_element(RMAP_NODE
, &no_match_probability_cmd
);
7243 install_element(RMAP_NODE
, &no_set_table_id_cmd
);
7244 install_element(RMAP_NODE
, &set_table_id_cmd
);
7245 install_element(RMAP_NODE
, &set_ip_nexthop_peer_cmd
);
7246 install_element(RMAP_NODE
, &set_ip_nexthop_unchanged_cmd
);
7247 install_element(RMAP_NODE
, &set_local_pref_cmd
);
7248 install_element(RMAP_NODE
, &set_distance_cmd
);
7249 install_element(RMAP_NODE
, &no_set_distance_cmd
);
7250 install_element(RMAP_NODE
, &no_set_local_pref_cmd
);
7251 install_element(RMAP_NODE
, &set_weight_cmd
);
7252 install_element(RMAP_NODE
, &set_label_index_cmd
);
7253 install_element(RMAP_NODE
, &no_set_weight_cmd
);
7254 install_element(RMAP_NODE
, &no_set_label_index_cmd
);
7255 install_element(RMAP_NODE
, &set_aspath_prepend_asn_cmd
);
7256 install_element(RMAP_NODE
, &set_aspath_prepend_lastas_cmd
);
7257 install_element(RMAP_NODE
, &set_aspath_exclude_cmd
);
7258 install_element(RMAP_NODE
, &set_aspath_replace_asn_cmd
);
7259 install_element(RMAP_NODE
, &no_set_aspath_prepend_cmd
);
7260 install_element(RMAP_NODE
, &no_set_aspath_prepend_lastas_cmd
);
7261 install_element(RMAP_NODE
, &no_set_aspath_exclude_cmd
);
7262 install_element(RMAP_NODE
, &no_set_aspath_exclude_all_cmd
);
7263 install_element(RMAP_NODE
, &no_set_aspath_replace_asn_cmd
);
7264 install_element(RMAP_NODE
, &set_origin_cmd
);
7265 install_element(RMAP_NODE
, &no_set_origin_cmd
);
7266 install_element(RMAP_NODE
, &set_atomic_aggregate_cmd
);
7267 install_element(RMAP_NODE
, &no_set_atomic_aggregate_cmd
);
7268 install_element(RMAP_NODE
, &set_aigp_metric_cmd
);
7269 install_element(RMAP_NODE
, &no_set_aigp_metric_cmd
);
7270 install_element(RMAP_NODE
, &set_aggregator_as_cmd
);
7271 install_element(RMAP_NODE
, &no_set_aggregator_as_cmd
);
7272 install_element(RMAP_NODE
, &set_community_cmd
);
7273 install_element(RMAP_NODE
, &set_community_none_cmd
);
7274 install_element(RMAP_NODE
, &no_set_community_cmd
);
7275 install_element(RMAP_NODE
, &no_set_community_short_cmd
);
7276 install_element(RMAP_NODE
, &set_community_delete_cmd
);
7277 install_element(RMAP_NODE
, &no_set_community_delete_cmd
);
7278 install_element(RMAP_NODE
, &set_lcommunity_cmd
);
7279 install_element(RMAP_NODE
, &set_lcommunity_none_cmd
);
7280 install_element(RMAP_NODE
, &no_set_lcommunity_cmd
);
7281 install_element(RMAP_NODE
, &no_set_lcommunity1_cmd
);
7282 install_element(RMAP_NODE
, &no_set_lcommunity1_short_cmd
);
7283 install_element(RMAP_NODE
, &set_lcommunity_delete_cmd
);
7284 install_element(RMAP_NODE
, &no_set_lcommunity_delete_cmd
);
7285 install_element(RMAP_NODE
, &no_set_lcommunity_delete_short_cmd
);
7286 install_element(RMAP_NODE
, &set_ecommunity_rt_cmd
);
7287 install_element(RMAP_NODE
, &no_set_ecommunity_rt_cmd
);
7288 install_element(RMAP_NODE
, &no_set_ecommunity_rt_short_cmd
);
7289 install_element(RMAP_NODE
, &set_ecommunity_soo_cmd
);
7290 install_element(RMAP_NODE
, &no_set_ecommunity_soo_cmd
);
7291 install_element(RMAP_NODE
, &no_set_ecommunity_soo_short_cmd
);
7292 install_element(RMAP_NODE
, &set_ecommunity_lb_cmd
);
7293 install_element(RMAP_NODE
, &no_set_ecommunity_lb_cmd
);
7294 install_element(RMAP_NODE
, &no_set_ecommunity_lb_short_cmd
);
7295 install_element(RMAP_NODE
, &set_ecommunity_none_cmd
);
7296 install_element(RMAP_NODE
, &no_set_ecommunity_none_cmd
);
7297 #ifdef KEEP_OLD_VPN_COMMANDS
7298 install_element(RMAP_NODE
, &set_vpn_nexthop_cmd
);
7299 install_element(RMAP_NODE
, &no_set_vpn_nexthop_cmd
);
7300 #endif /* KEEP_OLD_VPN_COMMANDS */
7301 install_element(RMAP_NODE
, &set_ipx_vpn_nexthop_cmd
);
7302 install_element(RMAP_NODE
, &no_set_ipx_vpn_nexthop_cmd
);
7303 install_element(RMAP_NODE
, &set_originator_id_cmd
);
7304 install_element(RMAP_NODE
, &no_set_originator_id_cmd
);
7305 install_element(RMAP_NODE
, &set_l3vpn_nexthop_encapsulation_cmd
);
7307 route_map_install_match(&route_match_ipv6_address_cmd
);
7308 route_map_install_match(&route_match_ipv6_next_hop_cmd
);
7309 route_map_install_match(&route_match_ipv6_next_hop_address_cmd
);
7310 route_map_install_match(&route_match_ipv6_next_hop_prefix_list_cmd
);
7311 route_map_install_match(&route_match_ipv4_next_hop_cmd
);
7312 route_map_install_match(&route_match_ipv6_address_prefix_list_cmd
);
7313 route_map_install_match(&route_match_ipv6_next_hop_type_cmd
);
7314 route_map_install_set(&route_set_ipv6_nexthop_global_cmd
);
7315 route_map_install_set(&route_set_ipv6_nexthop_prefer_global_cmd
);
7316 route_map_install_set(&route_set_ipv6_nexthop_local_cmd
);
7317 route_map_install_set(&route_set_ipv6_nexthop_peer_cmd
);
7318 route_map_install_match(&route_match_rpki_extcommunity_cmd
);
7320 install_element(RMAP_NODE
, &match_ipv6_next_hop_cmd
);
7321 install_element(RMAP_NODE
, &match_ipv6_next_hop_address_cmd
);
7322 install_element(RMAP_NODE
, &match_ipv6_next_hop_prefix_list_cmd
);
7323 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_cmd
);
7324 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_address_cmd
);
7325 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_prefix_list_cmd
);
7326 install_element(RMAP_NODE
, &match_ipv6_next_hop_old_cmd
);
7327 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_old_cmd
);
7328 install_element(RMAP_NODE
, &match_ipv4_next_hop_cmd
);
7329 install_element(RMAP_NODE
, &no_match_ipv4_next_hop_cmd
);
7330 install_element(RMAP_NODE
, &set_ipv6_nexthop_global_cmd
);
7331 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_global_cmd
);
7332 install_element(RMAP_NODE
, &set_ipv6_nexthop_prefer_global_cmd
);
7333 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_prefer_global_cmd
);
7334 install_element(RMAP_NODE
, &set_ipv6_nexthop_peer_cmd
);
7335 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_peer_cmd
);
7336 install_element(RMAP_NODE
, &match_rpki_extcommunity_cmd
);
7337 #ifdef HAVE_SCRIPTING
7338 install_element(RMAP_NODE
, &match_script_cmd
);
7342 void bgp_route_map_terminate(void)
7344 /* ToDo: Cleanup all the used memory */