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 #ifdef HAVE_LIBPCREPOSIX
33 #include <pcreposix.h>
36 #endif /* HAVE_LIBPCREPOSIX */
38 #include "sockunion.h"
43 #include "lib/northbound_cli.h"
45 #include "bgpd/bgpd.h"
46 #include "bgpd/bgp_table.h"
47 #include "bgpd/bgp_attr.h"
48 #include "bgpd/bgp_aspath.h"
49 #include "bgpd/bgp_packet.h"
50 #include "bgpd/bgp_route.h"
51 #include "bgpd/bgp_zebra.h"
52 #include "bgpd/bgp_regex.h"
53 #include "bgpd/bgp_community.h"
54 #include "bgpd/bgp_clist.h"
55 #include "bgpd/bgp_filter.h"
56 #include "bgpd/bgp_mplsvpn.h"
57 #include "bgpd/bgp_ecommunity.h"
58 #include "bgpd/bgp_lcommunity.h"
59 #include "bgpd/bgp_vty.h"
60 #include "bgpd/bgp_debug.h"
61 #include "bgpd/bgp_evpn.h"
62 #include "bgpd/bgp_evpn_private.h"
63 #include "bgpd/bgp_evpn_vty.h"
64 #include "bgpd/bgp_mplsvpn.h"
65 #include "bgpd/bgp_pbr.h"
66 #include "bgpd/bgp_flowspec_util.h"
67 #include "bgpd/bgp_encap_types.h"
68 #include "bgpd/bgp_mpath.h"
69 #include "bgpd/bgp_script.h"
72 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
75 #ifndef VTYSH_EXTRACT_PL
76 #include "bgpd/bgp_routemap_clippy.c"
79 /* Memo of route-map commands.
88 ip route-source : Done
92 ipv6 route-source: (This will not be implemented by bgpd)
93 ipv6 prefix-list : Done
94 length : (This will not be implemented by bgpd)
96 route-type : (This will not be implemented by bgpd)
98 local-preference : Done
100 set as-path prepend : Done
101 as-path tag : Not yet
102 automatic-tag : (This will not be implemented by bgpd)
104 large-community : Done
105 large-comm-list : Done
108 default : (This will not be implemented by bgpd)
109 interface : (This will not be implemented by bgpd)
110 ip default : (This will not be implemented by bgpd)
112 ip precedence : (This will not be implemented by bgpd)
113 ip tos : (This will not be implemented by bgpd)
114 level : (This will not be implemented by bgpd)
115 local-preference : Done
117 metric-type : Not yet
125 set ipv6 next-hop global: Done
126 set ipv6 next-hop prefer-global: Done
127 set ipv6 next-hop local : Done
128 set as-path exclude : Done
132 /* generic value manipulation to be shared in multiple rules */
134 #define RMAP_VALUE_SET 0
135 #define RMAP_VALUE_ADD 1
136 #define RMAP_VALUE_SUB 2
144 static int route_value_match(struct rmap_value
*rv
, uint32_t value
)
146 if (rv
->variable
== 0 && value
== rv
->value
)
152 static uint32_t route_value_adjust(struct rmap_value
*rv
, uint32_t current
,
157 switch (rv
->variable
) {
166 switch (rv
->action
) {
168 if (current
> UINT32_MAX
- value
)
170 return current
+ value
;
172 if (current
<= value
)
174 return current
- value
;
180 static void *route_value_compile(const char *arg
)
182 uint8_t action
= RMAP_VALUE_SET
, var
= 0;
183 unsigned long larg
= 0;
185 struct rmap_value
*rv
;
188 action
= RMAP_VALUE_ADD
;
190 } else if (arg
[0] == '-') {
191 action
= RMAP_VALUE_SUB
;
195 if (all_digit(arg
)) {
197 larg
= strtoul(arg
, &endptr
, 10);
198 if (*arg
== 0 || *endptr
!= 0 || errno
|| larg
> UINT32_MAX
)
201 if (strcmp(arg
, "rtt") == 0)
207 rv
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_value
));
215 static void route_value_free(void *rule
)
217 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
220 /* generic as path object to be shared in multiple rules */
222 static void *route_aspath_compile(const char *arg
)
224 struct aspath
*aspath
;
226 aspath
= aspath_str2aspath(arg
);
232 static void route_aspath_free(void *rule
)
234 struct aspath
*aspath
= rule
;
238 struct bgp_match_peer_compiled
{
243 /* 'match peer (A.B.C.D|X:X::X:X|WORD)' */
245 /* Compares the peer specified in the 'match peer' clause with the peer
246 received in bgp_path_info->peer. If it is the same, or if the peer structure
247 received is a peer_group containing it, returns RMAP_MATCH. */
248 static enum route_map_cmd_result_t
249 route_match_peer(void *rule
, const struct prefix
*prefix
, void *object
)
251 struct bgp_match_peer_compiled
*pc
;
253 union sockunion su_def
= {
254 .sin
= {.sin_family
= AF_INET
, .sin_addr
.s_addr
= INADDR_ANY
}};
255 struct peer_group
*group
;
257 struct listnode
*node
, *nnode
;
261 peer
= ((struct bgp_path_info
*)object
)->peer
;
267 if (strcmp(peer
->conf_if
, pc
->interface
) == 0)
273 /* If su='0.0.0.0' (command 'match peer local'), and it's a
275 REDISTRIBUTE, AGGREGATE-ADDRESS or DEFAULT_GENERATED route
278 if (sockunion_same(su
, &su_def
)) {
280 if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_NETWORK
)
281 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_REDISTRIBUTE
)
282 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_AGGREGATE
)
283 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_DEFAULT
))
290 if (!CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
)) {
291 if (sockunion_same(su
, &peer
->su
))
297 for (ALL_LIST_ELEMENTS(group
->peer
, node
, nnode
, peer
)) {
298 if (sockunion_same(su
, &peer
->su
))
307 static void *route_match_peer_compile(const char *arg
)
309 struct bgp_match_peer_compiled
*pc
;
312 pc
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
313 sizeof(struct bgp_match_peer_compiled
));
315 ret
= str2sockunion(strcmp(arg
, "local") ? arg
: "0.0.0.0", &pc
->su
);
317 pc
->interface
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
324 /* Free route map's compiled `ip address' value. */
325 static void route_match_peer_free(void *rule
)
327 struct bgp_match_peer_compiled
*pc
= rule
;
329 XFREE(MTYPE_ROUTE_MAP_COMPILED
, pc
->interface
);
331 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
334 /* Route map commands for ip address matching. */
335 static const struct route_map_rule_cmd route_match_peer_cmd
= {
338 route_match_peer_compile
,
339 route_match_peer_free
342 #ifdef HAVE_SCRIPTING
344 enum frrlua_rm_status
{
346 * Script function run failure. This will translate into a deny
350 * No Match was found for the route map function
354 * Match was found but no changes were made to the incoming data.
358 * Match was found and data was modified, so figure out what changed
360 LUA_RM_MATCH_AND_CHANGE
,
363 static enum route_map_cmd_result_t
364 route_match_script(void *rule
, const struct prefix
*prefix
, void *object
)
366 const char *scriptname
= rule
;
367 struct bgp_path_info
*path
= (struct bgp_path_info
*)object
;
369 struct frrscript
*fs
= frrscript_load(scriptname
, NULL
);
372 zlog_err("Issue loading script rule; defaulting to no match");
376 enum frrlua_rm_status status_failure
= LUA_RM_FAILURE
,
377 status_nomatch
= LUA_RM_NOMATCH
,
378 status_match
= LUA_RM_MATCH
,
379 status_match_and_change
= LUA_RM_MATCH_AND_CHANGE
;
381 /* Make result values available */
382 struct frrscript_env env
[] = {
383 {"integer", "RM_FAILURE", &status_failure
},
384 {"integer", "RM_NOMATCH", &status_nomatch
},
385 {"integer", "RM_MATCH", &status_match
},
386 {"integer", "RM_MATCH_AND_CHANGE", &status_match_and_change
},
387 {"integer", "action", &status_failure
},
388 {"prefix", "prefix", prefix
},
389 {"attr", "attributes", path
->attr
},
390 {"peer", "peer", path
->peer
},
393 struct frrscript_env results
[] = {
394 {"integer", "action"},
395 {"attr", "attributes"},
399 int result
= frrscript_call(fs
, env
);
402 zlog_err("Issue running script rule; defaulting to no match");
406 enum frrlua_rm_status
*lrm_status
=
407 frrscript_get_result(fs
, &results
[0]);
409 int status
= RMAP_NOMATCH
;
411 switch (*lrm_status
) {
414 "Executing route-map match script '%s' failed; defaulting to no match",
416 status
= RMAP_NOMATCH
;
419 status
= RMAP_NOMATCH
;
421 case LUA_RM_MATCH_AND_CHANGE
:
423 zlog_debug("Updating attribute based on script's values");
425 uint32_t locpref
= 0;
426 struct attr
*newattr
= frrscript_get_result(fs
, &results
[1]);
428 path
->attr
->med
= newattr
->med
;
430 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
))
431 locpref
= path
->attr
->local_pref
;
432 if (locpref
!= newattr
->local_pref
) {
433 SET_FLAG(path
->attr
->flag
,
434 ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
));
435 path
->attr
->local_pref
= newattr
->local_pref
;
438 aspath_free(newattr
->aspath
);
439 XFREE(MTYPE_TMP
, newattr
);
446 XFREE(MTYPE_TMP
, lrm_status
);
447 frrscript_unload(fs
);
452 static void *route_match_script_compile(const char *arg
)
456 scriptname
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
461 static void route_match_script_free(void *rule
)
463 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
466 static const struct route_map_rule_cmd route_match_script_cmd
= {
469 route_match_script_compile
,
470 route_match_script_free
473 #endif /* HAVE_SCRIPTING */
475 /* `match ip address IP_ACCESS_LIST' */
477 /* Match function should return 1 if match is success else return
479 static enum route_map_cmd_result_t
480 route_match_ip_address(void *rule
, const struct prefix
*prefix
, void *object
)
482 struct access_list
*alist
;
484 if (prefix
->family
== AF_INET
) {
485 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
489 return (access_list_apply(alist
, prefix
) == FILTER_DENY
496 /* Route map `ip address' match statement. `arg' should be
498 static void *route_match_ip_address_compile(const char *arg
)
500 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
503 /* Free route map's compiled `ip address' value. */
504 static void route_match_ip_address_free(void *rule
)
506 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
509 /* Route map commands for ip address matching. */
510 static const struct route_map_rule_cmd route_match_ip_address_cmd
= {
512 route_match_ip_address
,
513 route_match_ip_address_compile
,
514 route_match_ip_address_free
517 /* `match ip next-hop IP_ADDRESS' */
519 /* Match function return 1 if match is success else return zero. */
520 static enum route_map_cmd_result_t
521 route_match_ip_next_hop(void *rule
, const struct prefix
*prefix
, void *object
)
523 struct access_list
*alist
;
524 struct bgp_path_info
*path
;
525 struct prefix_ipv4 p
;
527 if (prefix
->family
== AF_INET
) {
530 p
.prefix
= path
->attr
->nexthop
;
531 p
.prefixlen
= IPV4_MAX_BITLEN
;
533 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
537 return (access_list_apply(alist
, &p
) == FILTER_DENY
544 /* Route map `ip next-hop' match statement. `arg' is
546 static void *route_match_ip_next_hop_compile(const char *arg
)
548 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
551 /* Free route map's compiled `ip address' value. */
552 static void route_match_ip_next_hop_free(void *rule
)
554 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
557 /* Route map commands for ip next-hop matching. */
558 static const struct route_map_rule_cmd route_match_ip_next_hop_cmd
= {
560 route_match_ip_next_hop
,
561 route_match_ip_next_hop_compile
,
562 route_match_ip_next_hop_free
565 /* `match ip route-source ACCESS-LIST' */
567 /* Match function return 1 if match is success else return zero. */
568 static enum route_map_cmd_result_t
569 route_match_ip_route_source(void *rule
, const struct prefix
*pfx
, void *object
)
571 struct access_list
*alist
;
572 struct bgp_path_info
*path
;
574 struct prefix_ipv4 p
;
576 if (pfx
->family
== AF_INET
) {
580 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
584 p
.prefix
= peer
->su
.sin
.sin_addr
;
585 p
.prefixlen
= IPV4_MAX_BITLEN
;
587 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
591 return (access_list_apply(alist
, &p
) == FILTER_DENY
598 /* Route map `ip route-source' match statement. `arg' is
600 static void *route_match_ip_route_source_compile(const char *arg
)
602 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
605 /* Free route map's compiled `ip address' value. */
606 static void route_match_ip_route_source_free(void *rule
)
608 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
611 /* Route map commands for ip route-source matching. */
612 static const struct route_map_rule_cmd route_match_ip_route_source_cmd
= {
614 route_match_ip_route_source
,
615 route_match_ip_route_source_compile
,
616 route_match_ip_route_source_free
619 static enum route_map_cmd_result_t
620 route_match_prefix_list_flowspec(afi_t afi
, struct prefix_list
*plist
,
621 const struct prefix
*p
)
624 struct bgp_pbr_entry_main api
;
626 memset(&api
, 0, sizeof(api
));
628 if (family2afi(p
->u
.prefix_flowspec
.family
) != afi
)
631 /* extract match from flowspec entries */
632 ret
= bgp_flowspec_match_rules_fill(
633 (uint8_t *)p
->u
.prefix_flowspec
.ptr
,
634 p
->u
.prefix_flowspec
.prefixlen
, &api
,
638 if (api
.match_bitmask
& PREFIX_DST_PRESENT
||
639 api
.match_bitmask_iprule
& PREFIX_DST_PRESENT
) {
640 if (family2afi((&api
.dst_prefix
)->family
) != afi
)
642 return prefix_list_apply(plist
, &api
.dst_prefix
) == PREFIX_DENY
645 } else if (api
.match_bitmask
& PREFIX_SRC_PRESENT
||
646 api
.match_bitmask_iprule
& PREFIX_SRC_PRESENT
) {
647 if (family2afi((&api
.src_prefix
)->family
) != afi
)
649 return (prefix_list_apply(plist
, &api
.src_prefix
) == PREFIX_DENY
656 static enum route_map_cmd_result_t
657 route_match_address_prefix_list(void *rule
, afi_t afi
,
658 const struct prefix
*prefix
, void *object
)
660 struct prefix_list
*plist
;
662 plist
= prefix_list_lookup(afi
, (char *)rule
);
666 if (prefix
->family
== AF_FLOWSPEC
)
667 return route_match_prefix_list_flowspec(afi
, plist
,
669 return (prefix_list_apply(plist
, prefix
) == PREFIX_DENY
? RMAP_NOMATCH
673 static enum route_map_cmd_result_t
674 route_match_ip_address_prefix_list(void *rule
, const struct prefix
*prefix
,
677 return route_match_address_prefix_list(rule
, AFI_IP
, prefix
, object
);
680 static void *route_match_ip_address_prefix_list_compile(const char *arg
)
682 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
685 static void route_match_ip_address_prefix_list_free(void *rule
)
687 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
690 static const struct route_map_rule_cmd
691 route_match_ip_address_prefix_list_cmd
= {
692 "ip address prefix-list",
693 route_match_ip_address_prefix_list
,
694 route_match_ip_address_prefix_list_compile
,
695 route_match_ip_address_prefix_list_free
698 /* `match ip next-hop prefix-list PREFIX_LIST' */
700 static enum route_map_cmd_result_t
701 route_match_ip_next_hop_prefix_list(void *rule
, const struct prefix
*prefix
,
704 struct prefix_list
*plist
;
705 struct bgp_path_info
*path
;
706 struct prefix_ipv4 p
;
708 if (prefix
->family
== AF_INET
) {
711 p
.prefix
= path
->attr
->nexthop
;
712 p
.prefixlen
= IPV4_MAX_BITLEN
;
714 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
718 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
725 static void *route_match_ip_next_hop_prefix_list_compile(const char *arg
)
727 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
730 static void route_match_ip_next_hop_prefix_list_free(void *rule
)
732 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
735 static const struct route_map_rule_cmd
736 route_match_ip_next_hop_prefix_list_cmd
= {
737 "ip next-hop prefix-list",
738 route_match_ip_next_hop_prefix_list
,
739 route_match_ip_next_hop_prefix_list_compile
,
740 route_match_ip_next_hop_prefix_list_free
743 /* `match ip next-hop type <blackhole>' */
745 static enum route_map_cmd_result_t
746 route_match_ip_next_hop_type(void *rule
, const struct prefix
*prefix
,
749 struct bgp_path_info
*path
;
751 if (prefix
->family
== AF_INET
) {
752 path
= (struct bgp_path_info
*)object
;
756 /* If nexthop interface's index can't be resolved and nexthop is
757 set to any address then mark it as type `blackhole`.
758 This logic works for matching kernel/static routes like:
759 `ip route add blackhole 10.0.0.1`. */
760 if (path
->attr
->nexthop
.s_addr
== INADDR_ANY
761 && !path
->attr
->nh_ifindex
)
767 static void *route_match_ip_next_hop_type_compile(const char *arg
)
769 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
772 static void route_match_ip_next_hop_type_free(void *rule
)
774 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
777 static const struct route_map_rule_cmd
778 route_match_ip_next_hop_type_cmd
= {
780 route_match_ip_next_hop_type
,
781 route_match_ip_next_hop_type_compile
,
782 route_match_ip_next_hop_type_free
785 /* `match ip route-source prefix-list PREFIX_LIST' */
787 static enum route_map_cmd_result_t
788 route_match_ip_route_source_prefix_list(void *rule
, const struct prefix
*prefix
,
791 struct prefix_list
*plist
;
792 struct bgp_path_info
*path
;
794 struct prefix_ipv4 p
;
796 if (prefix
->family
== AF_INET
) {
800 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
804 p
.prefix
= peer
->su
.sin
.sin_addr
;
805 p
.prefixlen
= IPV4_MAX_BITLEN
;
807 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
811 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
818 static void *route_match_ip_route_source_prefix_list_compile(const char *arg
)
820 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
823 static void route_match_ip_route_source_prefix_list_free(void *rule
)
825 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
828 static const struct route_map_rule_cmd
829 route_match_ip_route_source_prefix_list_cmd
= {
830 "ip route-source prefix-list",
831 route_match_ip_route_source_prefix_list
,
832 route_match_ip_route_source_prefix_list_compile
,
833 route_match_ip_route_source_prefix_list_free
836 /* `match evpn default-route' */
838 /* Match function should return 1 if match is success else 0 */
839 static enum route_map_cmd_result_t
840 route_match_evpn_default_route(void *rule
, const struct prefix
*p
, void *object
)
842 if (is_evpn_prefix_default(p
))
848 /* Route map commands for default-route matching. */
849 static const struct route_map_rule_cmd
850 route_match_evpn_default_route_cmd
= {
851 "evpn default-route",
852 route_match_evpn_default_route
,
857 /* `match mac address MAC_ACCESS_LIST' */
859 /* Match function should return 1 if match is success else return
861 static enum route_map_cmd_result_t
862 route_match_mac_address(void *rule
, const struct prefix
*prefix
, void *object
)
864 struct access_list
*alist
;
867 alist
= access_list_lookup(AFI_L2VPN
, (char *)rule
);
871 if (prefix
->u
.prefix_evpn
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
874 p
.family
= AF_ETHERNET
;
875 p
.prefixlen
= ETH_ALEN
* 8;
876 p
.u
.prefix_eth
= prefix
->u
.prefix_evpn
.macip_addr
.mac
;
878 return (access_list_apply(alist
, &p
) == FILTER_DENY
? RMAP_NOMATCH
882 /* Route map `mac address' match statement. `arg' should be
884 static void *route_match_mac_address_compile(const char *arg
)
886 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
889 /* Free route map's compiled `ip address' value. */
890 static void route_match_mac_address_free(void *rule
)
892 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
895 /* Route map commands for mac address matching. */
896 static const struct route_map_rule_cmd route_match_mac_address_cmd
= {
898 route_match_mac_address
,
899 route_match_mac_address_compile
,
900 route_match_mac_address_free
904 * Match function returns:
905 * ...RMAP_MATCH if match is found.
906 * ...RMAP_NOMATCH if match is not found.
907 * ...RMAP_NOOP to ignore this match check.
909 static enum route_map_cmd_result_t
910 route_match_vni(void *rule
, const struct prefix
*prefix
, void *object
)
913 unsigned int label_cnt
= 0;
914 struct bgp_path_info
*path
= NULL
;
915 struct prefix_evpn
*evp
= (struct prefix_evpn
*) prefix
;
917 vni
= *((vni_t
*)rule
);
918 path
= (struct bgp_path_info
*)object
;
921 * This rmap filter is valid for vxlan tunnel type only.
922 * For any other tunnel type, return noop to ignore
925 if (path
->attr
->encap_tunneltype
!= BGP_ENCAP_TYPE_VXLAN
)
929 * Apply filter to type 1, 2, 5 routes only.
930 * Other route types do not have vni label.
933 && (evp
->prefix
.route_type
!= BGP_EVPN_AD_ROUTE
934 && evp
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
935 && evp
->prefix
.route_type
!= BGP_EVPN_IP_PREFIX_ROUTE
))
938 if (path
->extra
== NULL
)
942 label_cnt
< BGP_MAX_LABELS
&& label_cnt
< path
->extra
->num_labels
;
944 if (vni
== label2vni(&path
->extra
->label
[label_cnt
]))
951 /* Route map `vni' match statement. */
952 static void *route_match_vni_compile(const char *arg
)
957 vni
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(vni_t
));
959 *vni
= strtoul(arg
, &end
, 10);
961 XFREE(MTYPE_ROUTE_MAP_COMPILED
, vni
);
968 /* Free route map's compiled `vni' value. */
969 static void route_match_vni_free(void *rule
)
971 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
974 /* Route map commands for vni matching. */
975 static const struct route_map_rule_cmd route_match_evpn_vni_cmd
= {
978 route_match_vni_compile
,
982 /* `match evpn route-type' */
984 /* Match function should return 1 if match is success else return
986 static enum route_map_cmd_result_t
987 route_match_evpn_route_type(void *rule
, const struct prefix
*pfx
, void *object
)
989 uint8_t route_type
= 0;
991 route_type
= *((uint8_t *)rule
);
993 if (route_type
== pfx
->u
.prefix_evpn
.route_type
)
999 /* Route map `route-type' match statement. */
1000 static void *route_match_evpn_route_type_compile(const char *arg
)
1002 uint8_t *route_type
= NULL
;
1004 route_type
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
1006 if (strncmp(arg
, "ma", 2) == 0)
1007 *route_type
= BGP_EVPN_MAC_IP_ROUTE
;
1008 else if (strncmp(arg
, "mu", 2) == 0)
1009 *route_type
= BGP_EVPN_IMET_ROUTE
;
1011 *route_type
= BGP_EVPN_IP_PREFIX_ROUTE
;
1016 /* Free route map's compiled `route-type' value. */
1017 static void route_match_evpn_route_type_free(void *rule
)
1019 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1022 /* Route map commands for evpn route-type matching. */
1023 static const struct route_map_rule_cmd route_match_evpn_route_type_cmd
= {
1025 route_match_evpn_route_type
,
1026 route_match_evpn_route_type_compile
,
1027 route_match_evpn_route_type_free
1032 /* Match function should return 1 if match is success else return zero. */
1033 static enum route_map_cmd_result_t
1034 route_match_rd(void *rule
, const struct prefix
*prefix
, void *object
)
1036 struct prefix_rd
*prd_rule
= NULL
;
1037 const struct prefix_rd
*prd_route
= NULL
;
1038 struct bgp_path_info
*path
= NULL
;
1040 if (prefix
->family
!= AF_EVPN
)
1041 return RMAP_NOMATCH
;
1043 prd_rule
= (struct prefix_rd
*)rule
;
1044 path
= (struct bgp_path_info
*)object
;
1046 if (path
->net
== NULL
|| path
->net
->pdest
== NULL
)
1047 return RMAP_NOMATCH
;
1049 prd_route
= (struct prefix_rd
*)bgp_dest_get_prefix(path
->net
->pdest
);
1050 if (memcmp(prd_route
->val
, prd_rule
->val
, ECOMMUNITY_SIZE
) == 0)
1053 return RMAP_NOMATCH
;
1056 /* Route map `rd' match statement. */
1057 static void *route_match_rd_compile(const char *arg
)
1059 struct prefix_rd
*prd
;
1062 prd
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct prefix_rd
));
1064 ret
= str2prefix_rd(arg
, prd
);
1066 XFREE(MTYPE_ROUTE_MAP_COMPILED
, prd
);
1073 /* Free route map's compiled `rd' value. */
1074 static void route_match_rd_free(void *rule
)
1076 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1079 /* Route map commands for rd matching. */
1080 static const struct route_map_rule_cmd route_match_evpn_rd_cmd
= {
1083 route_match_rd_compile
,
1087 /* Route map commands for VRF route leak with source vrf matching */
1088 static enum route_map_cmd_result_t
1089 route_match_vrl_source_vrf(void *rule
, const struct prefix
*prefix
,
1092 struct bgp_path_info
*path
;
1096 path
= (struct bgp_path_info
*)object
;
1098 if (strncmp(vrf_name
, "n/a", VRF_NAMSIZ
) == 0)
1099 return RMAP_NOMATCH
;
1101 if (path
->extra
== NULL
)
1102 return RMAP_NOMATCH
;
1104 if (strncmp(vrf_name
, vrf_id_to_name(path
->extra
->bgp_orig
->vrf_id
),
1109 return RMAP_NOMATCH
;
1112 static void *route_match_vrl_source_vrf_compile(const char *arg
)
1114 uint8_t *vrf_name
= NULL
;
1116 vrf_name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1121 /* Free route map's compiled `route-type' value. */
1122 static void route_match_vrl_source_vrf_free(void *rule
)
1124 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1127 static const struct route_map_rule_cmd route_match_vrl_source_vrf_cmd
= {
1129 route_match_vrl_source_vrf
,
1130 route_match_vrl_source_vrf_compile
,
1131 route_match_vrl_source_vrf_free
1134 /* `match local-preference LOCAL-PREF' */
1136 /* Match function return 1 if match is success else return zero. */
1137 static enum route_map_cmd_result_t
1138 route_match_local_pref(void *rule
, const struct prefix
*prefix
, void *object
)
1140 uint32_t *local_pref
;
1141 struct bgp_path_info
*path
;
1146 if (path
->attr
->local_pref
== *local_pref
)
1149 return RMAP_NOMATCH
;
1153 * Route map `match local-preference' match statement.
1154 * `arg' is local-pref value
1156 static void *route_match_local_pref_compile(const char *arg
)
1158 uint32_t *local_pref
;
1159 char *endptr
= NULL
;
1160 unsigned long tmpval
;
1162 /* Locpref value shoud be integer. */
1163 if (!all_digit(arg
))
1167 tmpval
= strtoul(arg
, &endptr
, 10);
1168 if (*endptr
!= '\0' || errno
|| tmpval
> UINT32_MAX
)
1171 local_pref
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint32_t));
1173 *local_pref
= tmpval
;
1177 /* Free route map's compiled `match local-preference' value. */
1178 static void route_match_local_pref_free(void *rule
)
1180 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1183 /* Route map commands for metric matching. */
1184 static const struct route_map_rule_cmd route_match_local_pref_cmd
= {
1186 route_match_local_pref
,
1187 route_match_local_pref_compile
,
1188 route_match_local_pref_free
1191 /* `match metric METRIC' */
1193 /* Match function return 1 if match is success else return zero. */
1194 static enum route_map_cmd_result_t
1195 route_match_metric(void *rule
, const struct prefix
*prefix
, void *object
)
1197 struct rmap_value
*rv
;
1198 struct bgp_path_info
*path
;
1202 return route_value_match(rv
, path
->attr
->med
);
1205 /* Route map commands for metric matching. */
1206 static const struct route_map_rule_cmd route_match_metric_cmd
= {
1209 route_value_compile
,
1213 /* `match as-path ASPATH' */
1215 /* Match function for as-path match. I assume given object is */
1216 static enum route_map_cmd_result_t
1217 route_match_aspath(void *rule
, const struct prefix
*prefix
, void *object
)
1220 struct as_list
*as_list
;
1221 struct bgp_path_info
*path
;
1223 as_list
= as_list_lookup((char *)rule
);
1224 if (as_list
== NULL
)
1225 return RMAP_NOMATCH
;
1229 /* Perform match. */
1230 return ((as_list_apply(as_list
, path
->attr
->aspath
) == AS_FILTER_DENY
)
1235 /* Compile function for as-path match. */
1236 static void *route_match_aspath_compile(const char *arg
)
1238 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1241 /* Compile function for as-path match. */
1242 static void route_match_aspath_free(void *rule
)
1244 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1247 /* Route map commands for aspath matching. */
1248 static const struct route_map_rule_cmd route_match_aspath_cmd
= {
1251 route_match_aspath_compile
,
1252 route_match_aspath_free
1255 /* `match community COMMUNIY' */
1256 struct rmap_community
{
1262 /* Match function for community match. */
1263 static enum route_map_cmd_result_t
1264 route_match_community(void *rule
, const struct prefix
*prefix
, void *object
)
1266 struct community_list
*list
;
1267 struct bgp_path_info
*path
;
1268 struct rmap_community
*rcom
= rule
;
1273 list
= community_list_lookup(bgp_clist
, rcom
->name
, rcom
->name_hash
,
1274 COMMUNITY_LIST_MASTER
);
1276 return RMAP_NOMATCH
;
1279 if (community_list_exact_match(path
->attr
->community
, list
))
1282 if (community_list_match(path
->attr
->community
, list
))
1286 return RMAP_NOMATCH
;
1289 /* Compile function for community match. */
1290 static void *route_match_community_compile(const char *arg
)
1292 struct rmap_community
*rcom
;
1296 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1298 p
= strchr(arg
, ' ');
1301 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1302 memcpy(rcom
->name
, arg
, len
);
1305 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1309 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1313 /* Compile function for community match. */
1314 static void route_match_community_free(void *rule
)
1316 struct rmap_community
*rcom
= rule
;
1318 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1319 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1323 * In routemap processing there is a need to add the
1324 * name as a rule_key in the dependency table. Routemap
1325 * lib is unaware of rule_key when exact-match clause
1326 * is in use. routemap lib uses the compiled output to
1327 * get the rule_key value.
1329 static void *route_match_get_community_key(void *rule
)
1331 struct rmap_community
*rcom
;
1338 /* Route map commands for community matching. */
1339 static const struct route_map_rule_cmd route_match_community_cmd
= {
1341 route_match_community
,
1342 route_match_community_compile
,
1343 route_match_community_free
,
1344 route_match_get_community_key
1347 /* Match function for lcommunity match. */
1348 static enum route_map_cmd_result_t
1349 route_match_lcommunity(void *rule
, const struct prefix
*prefix
, void *object
)
1351 struct community_list
*list
;
1352 struct bgp_path_info
*path
;
1353 struct rmap_community
*rcom
= rule
;
1357 list
= community_list_lookup(bgp_clist
, rcom
->name
, rcom
->name_hash
,
1358 LARGE_COMMUNITY_LIST_MASTER
);
1360 return RMAP_NOMATCH
;
1363 if (lcommunity_list_exact_match(path
->attr
->lcommunity
, list
))
1366 if (lcommunity_list_match(path
->attr
->lcommunity
, list
))
1370 return RMAP_NOMATCH
;
1373 /* Compile function for community match. */
1374 static void *route_match_lcommunity_compile(const char *arg
)
1376 struct rmap_community
*rcom
;
1380 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1382 p
= strchr(arg
, ' ');
1385 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1386 memcpy(rcom
->name
, arg
, len
);
1389 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1393 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1397 /* Compile function for community match. */
1398 static void route_match_lcommunity_free(void *rule
)
1400 struct rmap_community
*rcom
= rule
;
1402 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1403 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1406 /* Route map commands for community matching. */
1407 static const struct route_map_rule_cmd route_match_lcommunity_cmd
= {
1409 route_match_lcommunity
,
1410 route_match_lcommunity_compile
,
1411 route_match_lcommunity_free
,
1412 route_match_get_community_key
1416 /* Match function for extcommunity match. */
1417 static enum route_map_cmd_result_t
1418 route_match_ecommunity(void *rule
, const struct prefix
*prefix
, void *object
)
1420 struct community_list
*list
;
1421 struct bgp_path_info
*path
;
1422 struct rmap_community
*rcom
= rule
;
1426 list
= community_list_lookup(bgp_clist
, rcom
->name
, rcom
->name_hash
,
1427 EXTCOMMUNITY_LIST_MASTER
);
1429 return RMAP_NOMATCH
;
1431 if (ecommunity_list_match(path
->attr
->ecommunity
, list
))
1434 return RMAP_NOMATCH
;
1437 /* Compile function for extcommunity match. */
1438 static void *route_match_ecommunity_compile(const char *arg
)
1440 struct rmap_community
*rcom
;
1442 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1443 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1444 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1449 /* Compile function for extcommunity match. */
1450 static void route_match_ecommunity_free(void *rule
)
1452 struct rmap_community
*rcom
= rule
;
1454 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1455 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1458 /* Route map commands for community matching. */
1459 static const struct route_map_rule_cmd route_match_ecommunity_cmd
= {
1461 route_match_ecommunity
,
1462 route_match_ecommunity_compile
,
1463 route_match_ecommunity_free
1466 /* `match nlri` and `set nlri` are replaced by `address-family ipv4`
1467 and `address-family vpnv4'. */
1469 /* `match origin' */
1470 static enum route_map_cmd_result_t
1471 route_match_origin(void *rule
, const struct prefix
*prefix
, void *object
)
1474 struct bgp_path_info
*path
;
1479 if (path
->attr
->origin
== *origin
)
1482 return RMAP_NOMATCH
;
1485 static void *route_match_origin_compile(const char *arg
)
1489 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
1491 if (strcmp(arg
, "igp") == 0)
1493 else if (strcmp(arg
, "egp") == 0)
1501 /* Free route map's compiled `ip address' value. */
1502 static void route_match_origin_free(void *rule
)
1504 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1507 /* Route map commands for origin matching. */
1508 static const struct route_map_rule_cmd route_match_origin_cmd
= {
1511 route_match_origin_compile
,
1512 route_match_origin_free
1515 /* match probability { */
1517 static enum route_map_cmd_result_t
1518 route_match_probability(void *rule
, const struct prefix
*prefix
, void *object
)
1520 long r
= frr_weak_random();
1522 switch (*(long *)rule
) {
1528 if (r
< *(long *)rule
) {
1533 return RMAP_NOMATCH
;
1536 static void *route_match_probability_compile(const char *arg
)
1542 lobule
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(long));
1552 *lobule
= RAND_MAX
/ 100 * perc
;
1558 static void route_match_probability_free(void *rule
)
1560 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1563 static const struct route_map_rule_cmd route_match_probability_cmd
= {
1565 route_match_probability
,
1566 route_match_probability_compile
,
1567 route_match_probability_free
1570 /* `match interface IFNAME' */
1571 /* Match function should return 1 if match is success else return
1573 static enum route_map_cmd_result_t
1574 route_match_interface(void *rule
, const struct prefix
*prefix
, void *object
)
1576 struct interface
*ifp
;
1577 struct bgp_path_info
*path
;
1582 return RMAP_NOMATCH
;
1584 ifp
= if_lookup_by_name_all_vrf((char *)rule
);
1586 if (ifp
== NULL
|| ifp
->ifindex
!= path
->attr
->nh_ifindex
)
1587 return RMAP_NOMATCH
;
1592 /* Route map `interface' match statement. `arg' should be
1594 static void *route_match_interface_compile(const char *arg
)
1596 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1599 /* Free route map's compiled `interface' value. */
1600 static void route_match_interface_free(void *rule
)
1602 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1605 /* Route map commands for ip address matching. */
1606 static const struct route_map_rule_cmd route_match_interface_cmd
= {
1608 route_match_interface
,
1609 route_match_interface_compile
,
1610 route_match_interface_free
1615 /* `set ip next-hop IP_ADDRESS' */
1617 /* Match function return 1 if match is success else return zero. */
1618 static enum route_map_cmd_result_t
1619 route_match_tag(void *rule
, const struct prefix
*prefix
, void *object
)
1622 struct bgp_path_info
*path
;
1627 return ((path
->attr
->tag
== *tag
) ? RMAP_MATCH
: RMAP_NOMATCH
);
1631 /* Route map commands for tag matching. */
1632 static const struct route_map_rule_cmd route_match_tag_cmd
= {
1635 route_map_rule_tag_compile
,
1636 route_map_rule_tag_free
,
1639 static enum route_map_cmd_result_t
1640 route_set_srte_color(void *rule
, const struct prefix
*prefix
, void *object
)
1642 uint32_t *srte_color
= rule
;
1643 struct bgp_path_info
*path
;
1647 path
->attr
->srte_color
= *srte_color
;
1648 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_SRTE_COLOR
);
1653 /* Route map `sr-te color' compile function */
1654 static void *route_set_srte_color_compile(const char *arg
)
1658 color
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint32_t));
1664 /* Free route map's compiled `sr-te color' value. */
1665 static void route_set_srte_color_free(void *rule
)
1667 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1670 /* Route map commands for sr-te color set. */
1671 struct route_map_rule_cmd route_set_srte_color_cmd
= {
1672 "sr-te color", route_set_srte_color
, route_set_srte_color_compile
,
1673 route_set_srte_color_free
};
1675 /* Set nexthop to object. ojbect must be pointer to struct attr. */
1676 struct rmap_ip_nexthop_set
{
1677 struct in_addr
*address
;
1682 static enum route_map_cmd_result_t
1683 route_set_ip_nexthop(void *rule
, const struct prefix
*prefix
, void *object
)
1685 struct rmap_ip_nexthop_set
*rins
= rule
;
1686 struct bgp_path_info
*path
;
1689 if (prefix
->family
== AF_INET6
)
1695 if (rins
->unchanged
) {
1696 SET_FLAG(path
->attr
->rmap_change_flags
,
1697 BATTR_RMAP_NEXTHOP_UNCHANGED
);
1698 } else if (rins
->peer_address
) {
1699 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
1700 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
1702 && sockunion_family(peer
->su_remote
) == AF_INET
) {
1703 path
->attr
->nexthop
.s_addr
=
1704 sockunion2ip(peer
->su_remote
);
1705 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1706 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
1707 /* The next hop value will be set as part of
1708 * packet rewrite. Set the flags here to indicate
1709 * that rewrite needs to be done.
1710 * Also, clear the value.
1712 SET_FLAG(path
->attr
->rmap_change_flags
,
1713 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
1714 path
->attr
->nexthop
.s_addr
= INADDR_ANY
;
1717 /* Set next hop value. */
1718 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1719 path
->attr
->nexthop
= *rins
->address
;
1720 SET_FLAG(path
->attr
->rmap_change_flags
,
1721 BATTR_RMAP_IPV4_NHOP_CHANGED
);
1722 /* case for MP-BGP : MPLS VPN */
1723 path
->attr
->mp_nexthop_global_in
= *rins
->address
;
1724 path
->attr
->mp_nexthop_len
= sizeof(*rins
->address
);
1730 /* Route map `ip nexthop' compile function. Given string is converted
1731 to struct in_addr structure. */
1732 static void *route_set_ip_nexthop_compile(const char *arg
)
1734 struct rmap_ip_nexthop_set
*rins
;
1735 struct in_addr
*address
= NULL
;
1736 int peer_address
= 0;
1740 if (strcmp(arg
, "peer-address") == 0)
1742 else if (strcmp(arg
, "unchanged") == 0)
1745 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1746 sizeof(struct in_addr
));
1747 ret
= inet_aton(arg
, address
);
1750 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
1755 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1756 sizeof(struct rmap_ip_nexthop_set
));
1758 rins
->address
= address
;
1759 rins
->peer_address
= peer_address
;
1760 rins
->unchanged
= unchanged
;
1765 /* Free route map's compiled `ip nexthop' value. */
1766 static void route_set_ip_nexthop_free(void *rule
)
1768 struct rmap_ip_nexthop_set
*rins
= rule
;
1770 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
->address
);
1772 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
);
1775 /* Route map commands for ip nexthop set. */
1776 static const struct route_map_rule_cmd route_set_ip_nexthop_cmd
= {
1778 route_set_ip_nexthop
,
1779 route_set_ip_nexthop_compile
,
1780 route_set_ip_nexthop_free
1783 /* `set local-preference LOCAL_PREF' */
1785 /* Set local preference. */
1786 static enum route_map_cmd_result_t
1787 route_set_local_pref(void *rule
, const struct prefix
*prefix
, void *object
)
1789 struct rmap_value
*rv
;
1790 struct bgp_path_info
*path
;
1791 uint32_t locpref
= 0;
1793 /* Fetch routemap's rule information. */
1797 /* Set local preference value. */
1798 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
))
1799 locpref
= path
->attr
->local_pref
;
1801 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
);
1802 path
->attr
->local_pref
= route_value_adjust(rv
, locpref
, path
->peer
);
1807 /* Set local preference rule structure. */
1808 static const struct route_map_rule_cmd route_set_local_pref_cmd
= {
1810 route_set_local_pref
,
1811 route_value_compile
,
1815 /* `set weight WEIGHT' */
1818 static enum route_map_cmd_result_t
1819 route_set_weight(void *rule
, const struct prefix
*prefix
, void *object
)
1821 struct rmap_value
*rv
;
1822 struct bgp_path_info
*path
;
1824 /* Fetch routemap's rule information. */
1828 /* Set weight value. */
1829 path
->attr
->weight
= route_value_adjust(rv
, 0, path
->peer
);
1834 /* Set local preference rule structure. */
1835 static const struct route_map_rule_cmd route_set_weight_cmd
= {
1838 route_value_compile
,
1842 /* `set distance DISTANCE */
1843 static enum route_map_cmd_result_t
1844 route_set_distance(void *rule
, const struct prefix
*prefix
, void *object
)
1846 struct bgp_path_info
*path
= object
;
1847 struct rmap_value
*rv
= rule
;
1849 path
->attr
->distance
= rv
->value
;
1854 /* set distance rule structure */
1855 static const struct route_map_rule_cmd route_set_distance_cmd
= {
1858 route_value_compile
,
1862 /* `set metric METRIC' */
1864 /* Set metric to attribute. */
1865 static enum route_map_cmd_result_t
1866 route_set_metric(void *rule
, const struct prefix
*prefix
, void *object
)
1868 struct rmap_value
*rv
;
1869 struct bgp_path_info
*path
;
1872 /* Fetch routemap's rule information. */
1876 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
))
1877 med
= path
->attr
->med
;
1879 path
->attr
->med
= route_value_adjust(rv
, med
, path
->peer
);
1880 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
);
1885 /* Set metric rule structure. */
1886 static const struct route_map_rule_cmd route_set_metric_cmd
= {
1889 route_value_compile
,
1893 /* `set table (1-4294967295)' */
1895 static enum route_map_cmd_result_t
1896 route_set_table_id(void *rule
, const struct prefix
*prefix
,
1900 struct rmap_value
*rv
;
1901 struct bgp_path_info
*path
;
1903 /* Fetch routemap's rule information. */
1907 path
->attr
->rmap_table_id
= rv
->value
;
1912 /* Set table_id rule structure. */
1913 static const struct route_map_rule_cmd route_set_table_id_cmd
= {
1916 route_value_compile
,
1920 /* `set as-path prepend ASPATH' */
1922 /* For AS path prepend mechanism. */
1923 static enum route_map_cmd_result_t
1924 route_set_aspath_prepend(void *rule
, const struct prefix
*prefix
, void *object
)
1926 struct aspath
*aspath
;
1928 struct bgp_path_info
*path
;
1932 if (path
->attr
->aspath
->refcnt
)
1933 new = aspath_dup(path
->attr
->aspath
);
1935 new = path
->attr
->aspath
;
1937 if ((uintptr_t)rule
> 10) {
1939 aspath_prepend(aspath
, new);
1941 as_t as
= aspath_leftmost(new);
1943 as
= path
->peer
->as
;
1944 new = aspath_add_seq_n(new, as
, (uintptr_t)rule
);
1947 path
->attr
->aspath
= new;
1952 static void *route_set_aspath_prepend_compile(const char *arg
)
1956 if (sscanf(arg
, "last-as %u", &num
) == 1 && num
> 0 && num
<= 10)
1957 return (void *)(uintptr_t)num
;
1959 return route_aspath_compile(arg
);
1962 static void route_set_aspath_prepend_free(void *rule
)
1964 if ((uintptr_t)rule
> 10)
1965 route_aspath_free(rule
);
1969 /* Set as-path prepend rule structure. */
1970 static const struct route_map_rule_cmd route_set_aspath_prepend_cmd
= {
1972 route_set_aspath_prepend
,
1973 route_set_aspath_prepend_compile
,
1974 route_set_aspath_prepend_free
,
1977 /* `set as-path exclude ASn' */
1979 /* For ASN exclude mechanism.
1980 * Iterate over ASns requested and filter them from the given AS_PATH one by
1982 * Make a deep copy of existing AS_PATH, but for the first ASn only.
1984 static enum route_map_cmd_result_t
1985 route_set_aspath_exclude(void *rule
, const struct prefix
*dummy
, void *object
)
1987 struct aspath
*new_path
, *exclude_path
;
1988 struct bgp_path_info
*path
;
1990 exclude_path
= rule
;
1992 if (path
->attr
->aspath
->refcnt
)
1993 new_path
= aspath_dup(path
->attr
->aspath
);
1995 new_path
= path
->attr
->aspath
;
1996 path
->attr
->aspath
= aspath_filter_exclude(new_path
, exclude_path
);
2001 /* Set ASn exlude rule structure. */
2002 static const struct route_map_rule_cmd route_set_aspath_exclude_cmd
= {
2004 route_set_aspath_exclude
,
2005 route_aspath_compile
,
2009 /* `set community COMMUNITY' */
2010 struct rmap_com_set
{
2011 struct community
*com
;
2016 /* For community set mechanism. */
2017 static enum route_map_cmd_result_t
2018 route_set_community(void *rule
, const struct prefix
*prefix
, void *object
)
2020 struct rmap_com_set
*rcs
;
2021 struct bgp_path_info
*path
;
2023 struct community
*new = NULL
;
2024 struct community
*old
;
2025 struct community
*merge
;
2030 old
= attr
->community
;
2034 attr
->flag
&= ~(ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
));
2035 attr
->community
= NULL
;
2036 /* See the longer comment down below. */
2037 if (old
&& old
->refcnt
== 0)
2038 community_free(&old
);
2042 /* "additive" case. */
2043 if (rcs
->additive
&& old
) {
2044 merge
= community_merge(community_dup(old
), rcs
->com
);
2046 new = community_uniq_sort(merge
);
2047 community_free(&merge
);
2049 new = community_dup(rcs
->com
);
2051 /* HACK: if the old community is not intern'd,
2052 * we should free it here, or all reference to it may be
2054 * Really need to cleanup attribute caching sometime.
2056 if (old
&& old
->refcnt
== 0)
2057 community_free(&old
);
2059 /* will be interned by caller if required */
2060 attr
->community
= new;
2062 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
2067 /* Compile function for set community. */
2068 static void *route_set_community_compile(const char *arg
)
2070 struct rmap_com_set
*rcs
;
2071 struct community
*com
= NULL
;
2076 if (strcmp(arg
, "none") == 0)
2079 sp
= strstr(arg
, "additive");
2081 if (sp
&& sp
> arg
) {
2082 /* "additive" keyword is included. */
2087 com
= community_str2com(arg
);
2096 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
2098 rcs
->additive
= additive
;
2104 /* Free function for set community. */
2105 static void route_set_community_free(void *rule
)
2107 struct rmap_com_set
*rcs
= rule
;
2110 community_free(&rcs
->com
);
2111 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
2114 /* Set community rule structure. */
2115 static const struct route_map_rule_cmd route_set_community_cmd
= {
2117 route_set_community
,
2118 route_set_community_compile
,
2119 route_set_community_free
,
2122 /* `set community COMMUNITY' */
2123 struct rmap_lcom_set
{
2124 struct lcommunity
*lcom
;
2130 /* For lcommunity set mechanism. */
2131 static enum route_map_cmd_result_t
2132 route_set_lcommunity(void *rule
, const struct prefix
*prefix
, void *object
)
2134 struct rmap_lcom_set
*rcs
;
2135 struct bgp_path_info
*path
;
2137 struct lcommunity
*new = NULL
;
2138 struct lcommunity
*old
;
2139 struct lcommunity
*merge
;
2144 old
= attr
->lcommunity
;
2148 attr
->flag
&= ~(ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
));
2149 attr
->lcommunity
= NULL
;
2151 /* See the longer comment down below. */
2152 if (old
&& old
->refcnt
== 0)
2153 lcommunity_free(&old
);
2157 if (rcs
->additive
&& old
) {
2158 merge
= lcommunity_merge(lcommunity_dup(old
), rcs
->lcom
);
2160 new = lcommunity_uniq_sort(merge
);
2161 lcommunity_free(&merge
);
2163 new = lcommunity_dup(rcs
->lcom
);
2165 /* HACK: if the old large-community is not intern'd,
2166 * we should free it here, or all reference to it may be
2168 * Really need to cleanup attribute caching sometime.
2170 if (old
&& old
->refcnt
== 0)
2171 lcommunity_free(&old
);
2173 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
2174 attr
->lcommunity
= new;
2176 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
);
2181 /* Compile function for set community. */
2182 static void *route_set_lcommunity_compile(const char *arg
)
2184 struct rmap_lcom_set
*rcs
;
2185 struct lcommunity
*lcom
= NULL
;
2190 if (strcmp(arg
, "none") == 0)
2193 sp
= strstr(arg
, "additive");
2195 if (sp
&& sp
> arg
) {
2196 /* "additive" keyworkd is included. */
2201 lcom
= lcommunity_str2com(arg
);
2210 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
2212 rcs
->additive
= additive
;
2218 /* Free function for set lcommunity. */
2219 static void route_set_lcommunity_free(void *rule
)
2221 struct rmap_lcom_set
*rcs
= rule
;
2224 lcommunity_free(&rcs
->lcom
);
2226 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
2229 /* Set community rule structure. */
2230 static const struct route_map_rule_cmd route_set_lcommunity_cmd
= {
2232 route_set_lcommunity
,
2233 route_set_lcommunity_compile
,
2234 route_set_lcommunity_free
,
2237 /* `set large-comm-list (<1-99>|<100-500>|WORD) delete' */
2239 /* For large community set mechanism. */
2240 static enum route_map_cmd_result_t
2241 route_set_lcommunity_delete(void *rule
, const struct prefix
*pfx
, void *object
)
2243 struct community_list
*list
;
2244 struct lcommunity
*merge
;
2245 struct lcommunity
*new;
2246 struct lcommunity
*old
;
2247 struct bgp_path_info
*path
;
2248 struct rmap_community
*rcom
= rule
;
2254 list
= community_list_lookup(bgp_clist
, rcom
->name
, rcom
->name_hash
,
2255 LARGE_COMMUNITY_LIST_MASTER
);
2256 old
= path
->attr
->lcommunity
;
2259 merge
= lcommunity_list_match_delete(lcommunity_dup(old
), list
);
2260 new = lcommunity_uniq_sort(merge
);
2261 lcommunity_free(&merge
);
2263 /* HACK: if the old community is not intern'd,
2264 * we should free it here, or all reference to it may be
2266 * Really need to cleanup attribute caching sometime.
2268 if (old
->refcnt
== 0)
2269 lcommunity_free(&old
);
2271 if (new->size
== 0) {
2272 path
->attr
->lcommunity
= NULL
;
2274 ~ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
);
2275 lcommunity_free(&new);
2277 path
->attr
->lcommunity
= new;
2279 ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
);
2286 /* Compile function for set lcommunity. */
2287 static void *route_set_lcommunity_delete_compile(const char *arg
)
2289 struct rmap_community
*rcom
;
2293 frrstr_split(arg
, " ", &splits
, &num
);
2295 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2296 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, splits
[0]);
2297 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2299 for (int i
= 0; i
< num
; i
++)
2300 XFREE(MTYPE_TMP
, splits
[i
]);
2301 XFREE(MTYPE_TMP
, splits
);
2306 /* Free function for set lcommunity. */
2307 static void route_set_lcommunity_delete_free(void *rule
)
2309 struct rmap_community
*rcom
= rule
;
2311 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2312 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2315 /* Set lcommunity rule structure. */
2316 static const struct route_map_rule_cmd route_set_lcommunity_delete_cmd
= {
2318 route_set_lcommunity_delete
,
2319 route_set_lcommunity_delete_compile
,
2320 route_set_lcommunity_delete_free
,
2324 /* `set comm-list (<1-99>|<100-500>|WORD) delete' */
2326 /* For community set mechanism. */
2327 static enum route_map_cmd_result_t
2328 route_set_community_delete(void *rule
, const struct prefix
*prefix
,
2331 struct community_list
*list
;
2332 struct community
*merge
;
2333 struct community
*new;
2334 struct community
*old
;
2335 struct bgp_path_info
*path
;
2336 struct rmap_community
*rcom
= rule
;
2342 list
= community_list_lookup(bgp_clist
, rcom
->name
, rcom
->name_hash
,
2343 COMMUNITY_LIST_MASTER
);
2344 old
= path
->attr
->community
;
2347 merge
= community_list_match_delete(community_dup(old
), list
);
2348 new = community_uniq_sort(merge
);
2349 community_free(&merge
);
2351 /* HACK: if the old community is not intern'd,
2352 * we should free it here, or all reference to it may be
2354 * Really need to cleanup attribute caching sometime.
2356 if (old
->refcnt
== 0)
2357 community_free(&old
);
2359 if (new->size
== 0) {
2360 path
->attr
->community
= NULL
;
2362 ~ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
2363 community_free(&new);
2365 path
->attr
->community
= new;
2366 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
2373 /* Compile function for set community. */
2374 static void *route_set_community_delete_compile(const char *arg
)
2376 struct rmap_community
*rcom
;
2380 frrstr_split(arg
, " ", &splits
, &num
);
2382 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2383 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, splits
[0]);
2384 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2386 for (int i
= 0; i
< num
; i
++)
2387 XFREE(MTYPE_TMP
, splits
[i
]);
2388 XFREE(MTYPE_TMP
, splits
);
2393 /* Free function for set community. */
2394 static void route_set_community_delete_free(void *rule
)
2396 struct rmap_community
*rcom
= rule
;
2398 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2399 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2402 /* Set community rule structure. */
2403 static const struct route_map_rule_cmd route_set_community_delete_cmd
= {
2405 route_set_community_delete
,
2406 route_set_community_delete_compile
,
2407 route_set_community_delete_free
,
2410 /* `set extcommunity rt COMMUNITY' */
2412 /* For community set mechanism. Used by _rt and _soo. */
2413 static enum route_map_cmd_result_t
2414 route_set_ecommunity(void *rule
, const struct prefix
*prefix
, void *object
)
2416 struct ecommunity
*ecom
;
2417 struct ecommunity
*new_ecom
;
2418 struct ecommunity
*old_ecom
;
2419 struct bgp_path_info
*path
;
2427 /* We assume additive for Extended Community. */
2428 old_ecom
= path
->attr
->ecommunity
;
2431 new_ecom
= ecommunity_merge(ecommunity_dup(old_ecom
), ecom
);
2433 /* old_ecom->refcnt = 1 => owned elsewhere, e.g.
2434 * bgp_update_receive()
2435 * ->refcnt = 0 => set by a previous route-map
2437 if (!old_ecom
->refcnt
)
2438 ecommunity_free(&old_ecom
);
2440 new_ecom
= ecommunity_dup(ecom
);
2442 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
2443 path
->attr
->ecommunity
= new_ecom
;
2445 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
);
2450 /* Compile function for set community. */
2451 static void *route_set_ecommunity_rt_compile(const char *arg
)
2453 struct ecommunity
*ecom
;
2455 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_ROUTE_TARGET
, 0);
2458 return ecommunity_intern(ecom
);
2461 /* Free function for set community. Used by _rt and _soo */
2462 static void route_set_ecommunity_free(void *rule
)
2464 struct ecommunity
*ecom
= rule
;
2465 ecommunity_unintern(&ecom
);
2468 /* Set community rule structure. */
2469 static const struct route_map_rule_cmd route_set_ecommunity_rt_cmd
= {
2471 route_set_ecommunity
,
2472 route_set_ecommunity_rt_compile
,
2473 route_set_ecommunity_free
,
2476 /* `set extcommunity soo COMMUNITY' */
2478 /* Compile function for set community. */
2479 static void *route_set_ecommunity_soo_compile(const char *arg
)
2481 struct ecommunity
*ecom
;
2483 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_SITE_ORIGIN
, 0);
2487 return ecommunity_intern(ecom
);
2490 /* Set community rule structure. */
2491 static const struct route_map_rule_cmd route_set_ecommunity_soo_cmd
= {
2493 route_set_ecommunity
,
2494 route_set_ecommunity_soo_compile
,
2495 route_set_ecommunity_free
,
2498 /* `set extcommunity bandwidth' */
2500 struct rmap_ecomm_lb_set
{
2502 #define RMAP_ECOMM_LB_SET_VALUE 1
2503 #define RMAP_ECOMM_LB_SET_CUMUL 2
2504 #define RMAP_ECOMM_LB_SET_NUM_MPATH 3
2509 static enum route_map_cmd_result_t
2510 route_set_ecommunity_lb(void *rule
, const struct prefix
*prefix
, void *object
)
2512 struct rmap_ecomm_lb_set
*rels
= rule
;
2513 struct bgp_path_info
*path
;
2515 struct ecommunity ecom_lb
= {0};
2516 struct ecommunity_val lb_eval
;
2517 uint32_t bw_bytes
= 0;
2518 uint16_t mpath_count
= 0;
2519 struct ecommunity
*new_ecom
;
2520 struct ecommunity
*old_ecom
;
2525 if (!peer
|| !peer
->bgp
)
2528 /* Build link bandwidth extended community */
2529 as
= (peer
->bgp
->as
> BGP_AS_MAX
) ? BGP_AS_TRANS
: peer
->bgp
->as
;
2530 if (rels
->lb_type
== RMAP_ECOMM_LB_SET_VALUE
) {
2531 bw_bytes
= ((uint64_t)rels
->bw
* 1000 * 1000) / 8;
2532 } else if (rels
->lb_type
== RMAP_ECOMM_LB_SET_CUMUL
) {
2533 /* process this only for the best path. */
2534 if (!CHECK_FLAG(path
->flags
, BGP_PATH_SELECTED
))
2537 bw_bytes
= (uint32_t)bgp_path_info_mpath_cumbw(path
);
2541 } else if (rels
->lb_type
== RMAP_ECOMM_LB_SET_NUM_MPATH
) {
2543 /* process this only for the best path. */
2544 if (!CHECK_FLAG(path
->flags
, BGP_PATH_SELECTED
))
2547 bw_bytes
= ((uint64_t)peer
->bgp
->lb_ref_bw
* 1000 * 1000) / 8;
2548 mpath_count
= bgp_path_info_mpath_count(path
) + 1;
2549 bw_bytes
*= mpath_count
;
2552 encode_lb_extcomm(as
, bw_bytes
, rels
->non_trans
, &lb_eval
);
2554 /* add to route or merge with existing */
2555 old_ecom
= path
->attr
->ecommunity
;
2557 new_ecom
= ecommunity_dup(old_ecom
);
2558 ecommunity_add_val(new_ecom
, &lb_eval
, true, true);
2559 if (!old_ecom
->refcnt
)
2560 ecommunity_free(&old_ecom
);
2563 ecom_lb
.unit_size
= ECOMMUNITY_SIZE
;
2564 ecom_lb
.val
= (uint8_t *)lb_eval
.val
;
2565 new_ecom
= ecommunity_dup(&ecom_lb
);
2568 /* new_ecom will be intern()'d or attr_flush()'d in call stack */
2569 path
->attr
->ecommunity
= new_ecom
;
2570 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
);
2572 /* Mark that route-map has set link bandwidth; used in attribute
2573 * setting decisions.
2575 SET_FLAG(path
->attr
->rmap_change_flags
, BATTR_RMAP_LINK_BW_SET
);
2580 static void *route_set_ecommunity_lb_compile(const char *arg
)
2582 struct rmap_ecomm_lb_set
*rels
;
2585 char bw_str
[40] = {0};
2587 bool non_trans
= false;
2590 p
= strchr(arg
, ' ');
2595 memcpy(bw_str
, arg
, len
);
2600 if (strcmp(str
, "cumulative") == 0)
2601 lb_type
= RMAP_ECOMM_LB_SET_CUMUL
;
2602 else if (strcmp(str
, "num-multipaths") == 0)
2603 lb_type
= RMAP_ECOMM_LB_SET_NUM_MPATH
;
2607 bw
= strtoul(str
, &end
, 10);
2610 lb_type
= RMAP_ECOMM_LB_SET_VALUE
;
2613 rels
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
2614 sizeof(struct rmap_ecomm_lb_set
));
2615 rels
->lb_type
= lb_type
;
2617 rels
->non_trans
= non_trans
;
2622 static void route_set_ecommunity_lb_free(void *rule
)
2624 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2627 /* Set community rule structure. */
2628 struct route_map_rule_cmd route_set_ecommunity_lb_cmd
= {
2629 "extcommunity bandwidth",
2630 route_set_ecommunity_lb
,
2631 route_set_ecommunity_lb_compile
,
2632 route_set_ecommunity_lb_free
,
2635 /* `set origin ORIGIN' */
2637 /* For origin set. */
2638 static enum route_map_cmd_result_t
2639 route_set_origin(void *rule
, const struct prefix
*prefix
, void *object
)
2642 struct bgp_path_info
*path
;
2647 path
->attr
->origin
= *origin
;
2652 /* Compile function for origin set. */
2653 static void *route_set_origin_compile(const char *arg
)
2657 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
2659 if (strcmp(arg
, "igp") == 0)
2661 else if (strcmp(arg
, "egp") == 0)
2669 /* Compile function for origin set. */
2670 static void route_set_origin_free(void *rule
)
2672 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2675 /* Set origin rule structure. */
2676 static const struct route_map_rule_cmd route_set_origin_cmd
= {
2679 route_set_origin_compile
,
2680 route_set_origin_free
,
2683 /* `set atomic-aggregate' */
2685 /* For atomic aggregate set. */
2686 static enum route_map_cmd_result_t
2687 route_set_atomic_aggregate(void *rule
, const struct prefix
*pfx
, void *object
)
2689 struct bgp_path_info
*path
;
2692 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE
);
2697 /* Compile function for atomic aggregate. */
2698 static void *route_set_atomic_aggregate_compile(const char *arg
)
2703 /* Compile function for atomic aggregate. */
2704 static void route_set_atomic_aggregate_free(void *rule
)
2709 /* Set atomic aggregate rule structure. */
2710 static const struct route_map_rule_cmd route_set_atomic_aggregate_cmd
= {
2712 route_set_atomic_aggregate
,
2713 route_set_atomic_aggregate_compile
,
2714 route_set_atomic_aggregate_free
,
2717 /* `set aggregator as AS A.B.C.D' */
2720 struct in_addr address
;
2723 static enum route_map_cmd_result_t
2724 route_set_aggregator_as(void *rule
, const struct prefix
*prefix
, void *object
)
2726 struct bgp_path_info
*path
;
2727 struct aggregator
*aggregator
;
2732 path
->attr
->aggregator_as
= aggregator
->as
;
2733 path
->attr
->aggregator_addr
= aggregator
->address
;
2734 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR
);
2739 static void *route_set_aggregator_as_compile(const char *arg
)
2741 struct aggregator
*aggregator
;
2747 XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct aggregator
));
2748 if (sscanf(arg
, "%s %s", as
, address
) != 2) {
2749 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
2753 aggregator
->as
= strtoul(as
, NULL
, 10);
2754 ret
= inet_aton(address
, &aggregator
->address
);
2756 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
2762 static void route_set_aggregator_as_free(void *rule
)
2764 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2767 static const struct route_map_rule_cmd route_set_aggregator_as_cmd
= {
2769 route_set_aggregator_as
,
2770 route_set_aggregator_as_compile
,
2771 route_set_aggregator_as_free
,
2774 /* Set tag to object. object must be pointer to struct bgp_path_info */
2775 static enum route_map_cmd_result_t
2776 route_set_tag(void *rule
, const struct prefix
*prefix
, void *object
)
2779 struct bgp_path_info
*path
;
2785 path
->attr
->tag
= *tag
;
2790 /* Route map commands for tag set. */
2791 static const struct route_map_rule_cmd route_set_tag_cmd
= {
2794 route_map_rule_tag_compile
,
2795 route_map_rule_tag_free
,
2798 /* Set label-index to object. object must be pointer to struct bgp_path_info */
2799 static enum route_map_cmd_result_t
2800 route_set_label_index(void *rule
, const struct prefix
*prefix
, void *object
)
2802 struct rmap_value
*rv
;
2803 struct bgp_path_info
*path
;
2804 uint32_t label_index
;
2806 /* Fetch routemap's rule information. */
2810 /* Set label-index value. */
2811 label_index
= rv
->value
;
2813 path
->attr
->label_index
= label_index
;
2814 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID
);
2820 /* Route map commands for label-index set. */
2821 static const struct route_map_rule_cmd route_set_label_index_cmd
= {
2823 route_set_label_index
,
2824 route_value_compile
,
2828 /* `match ipv6 address IP_ACCESS_LIST' */
2830 static enum route_map_cmd_result_t
2831 route_match_ipv6_address(void *rule
, const struct prefix
*prefix
, void *object
)
2833 struct access_list
*alist
;
2835 if (prefix
->family
== AF_INET6
) {
2836 alist
= access_list_lookup(AFI_IP6
, (char *)rule
);
2838 return RMAP_NOMATCH
;
2840 return (access_list_apply(alist
, prefix
) == FILTER_DENY
2844 return RMAP_NOMATCH
;
2847 static void *route_match_ipv6_address_compile(const char *arg
)
2849 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2852 static void route_match_ipv6_address_free(void *rule
)
2854 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2857 /* Route map commands for ip address matching. */
2858 static const struct route_map_rule_cmd route_match_ipv6_address_cmd
= {
2860 route_match_ipv6_address
,
2861 route_match_ipv6_address_compile
,
2862 route_match_ipv6_address_free
2865 /* `match ipv6 next-hop IP_ADDRESS' */
2867 static enum route_map_cmd_result_t
2868 route_match_ipv6_next_hop(void *rule
, const struct prefix
*prefix
, void *object
)
2870 struct in6_addr
*addr
= rule
;
2871 struct bgp_path_info
*path
;
2875 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
))
2878 if (path
->attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
2879 && IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_local
, rule
))
2882 return RMAP_NOMATCH
;
2885 static void *route_match_ipv6_next_hop_compile(const char *arg
)
2887 struct in6_addr
*address
;
2890 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2892 ret
= inet_pton(AF_INET6
, arg
, address
);
2894 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2901 static void route_match_ipv6_next_hop_free(void *rule
)
2903 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2906 static const struct route_map_rule_cmd route_match_ipv6_next_hop_cmd
= {
2908 route_match_ipv6_next_hop
,
2909 route_match_ipv6_next_hop_compile
,
2910 route_match_ipv6_next_hop_free
2913 /* `match ip next-hop IP_ADDRESS' */
2915 static enum route_map_cmd_result_t
2916 route_match_ipv4_next_hop(void *rule
, const struct prefix
*prefix
, void *object
)
2918 struct in_addr
*addr
= rule
;
2919 struct bgp_path_info
*path
;
2923 if (path
->attr
->nexthop
.s_addr
== addr
->s_addr
2924 || (path
->attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV4
2925 && IPV4_ADDR_SAME(&path
->attr
->mp_nexthop_global_in
, addr
)))
2928 return RMAP_NOMATCH
;
2931 static void *route_match_ipv4_next_hop_compile(const char *arg
)
2933 struct in_addr
*address
;
2936 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
2938 ret
= inet_pton(AF_INET
, arg
, address
);
2940 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2947 static void route_match_ipv4_next_hop_free(void *rule
)
2949 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2952 static const struct route_map_rule_cmd route_match_ipv4_next_hop_cmd
= {
2953 "ip next-hop address",
2954 route_match_ipv4_next_hop
,
2955 route_match_ipv4_next_hop_compile
,
2956 route_match_ipv4_next_hop_free
2959 /* `match ipv6 address prefix-list PREFIX_LIST' */
2961 static enum route_map_cmd_result_t
2962 route_match_ipv6_address_prefix_list(void *rule
, const struct prefix
*prefix
,
2965 return route_match_address_prefix_list(rule
, AFI_IP6
, prefix
, object
);
2968 static void *route_match_ipv6_address_prefix_list_compile(const char *arg
)
2970 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2973 static void route_match_ipv6_address_prefix_list_free(void *rule
)
2975 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2978 static const struct route_map_rule_cmd
2979 route_match_ipv6_address_prefix_list_cmd
= {
2980 "ipv6 address prefix-list",
2981 route_match_ipv6_address_prefix_list
,
2982 route_match_ipv6_address_prefix_list_compile
,
2983 route_match_ipv6_address_prefix_list_free
2986 /* `match ipv6 next-hop type <TYPE>' */
2988 static enum route_map_cmd_result_t
2989 route_match_ipv6_next_hop_type(void *rule
, const struct prefix
*prefix
,
2992 struct bgp_path_info
*path
;
2993 struct in6_addr
*addr
= rule
;
2995 if (prefix
->family
== AF_INET6
) {
2996 path
= (struct bgp_path_info
*)object
;
2998 return RMAP_NOMATCH
;
3000 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
)
3001 && !path
->attr
->nh_ifindex
)
3005 return RMAP_NOMATCH
;
3008 static void *route_match_ipv6_next_hop_type_compile(const char *arg
)
3010 struct in6_addr
*address
;
3013 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3015 ret
= inet_pton(AF_INET6
, "::0", address
);
3017 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3024 static void route_match_ipv6_next_hop_type_free(void *rule
)
3026 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3029 static const struct route_map_rule_cmd
3030 route_match_ipv6_next_hop_type_cmd
= {
3031 "ipv6 next-hop type",
3032 route_match_ipv6_next_hop_type
,
3033 route_match_ipv6_next_hop_type_compile
,
3034 route_match_ipv6_next_hop_type_free
3037 /* `set ipv6 nexthop global IP_ADDRESS' */
3039 /* Set nexthop to object. ojbect must be pointer to struct attr. */
3040 static enum route_map_cmd_result_t
3041 route_set_ipv6_nexthop_global(void *rule
, const struct prefix
*p
, void *object
)
3043 struct in6_addr
*address
;
3044 struct bgp_path_info
*path
;
3046 /* Fetch routemap's rule information. */
3050 /* Set next hop value. */
3051 path
->attr
->mp_nexthop_global
= *address
;
3053 /* Set nexthop length. */
3054 if (path
->attr
->mp_nexthop_len
== 0)
3055 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL
;
3057 SET_FLAG(path
->attr
->rmap_change_flags
,
3058 BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED
);
3063 /* Route map `ip next-hop' compile function. Given string is converted
3064 to struct in_addr structure. */
3065 static void *route_set_ipv6_nexthop_global_compile(const char *arg
)
3068 struct in6_addr
*address
;
3070 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3072 ret
= inet_pton(AF_INET6
, arg
, address
);
3075 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3082 /* Free route map's compiled `ip next-hop' value. */
3083 static void route_set_ipv6_nexthop_global_free(void *rule
)
3085 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3088 /* Route map commands for ip nexthop set. */
3089 static const struct route_map_rule_cmd
3090 route_set_ipv6_nexthop_global_cmd
= {
3091 "ipv6 next-hop global",
3092 route_set_ipv6_nexthop_global
,
3093 route_set_ipv6_nexthop_global_compile
,
3094 route_set_ipv6_nexthop_global_free
3097 /* Set next-hop preference value. */
3098 static enum route_map_cmd_result_t
3099 route_set_ipv6_nexthop_prefer_global(void *rule
, const struct prefix
*prefix
,
3102 struct bgp_path_info
*path
;
3105 /* Fetch routemap's rule information. */
3109 if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
3110 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
)) {
3111 /* Set next hop preference to global */
3112 path
->attr
->mp_nexthop_prefer_global
= true;
3113 SET_FLAG(path
->attr
->rmap_change_flags
,
3114 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
3116 path
->attr
->mp_nexthop_prefer_global
= false;
3117 SET_FLAG(path
->attr
->rmap_change_flags
,
3118 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
3124 static void *route_set_ipv6_nexthop_prefer_global_compile(const char *arg
)
3128 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
3134 /* Free route map's compiled `ip next-hop' value. */
3135 static void route_set_ipv6_nexthop_prefer_global_free(void *rule
)
3137 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3140 /* Route map commands for ip nexthop set preferred. */
3141 static const struct route_map_rule_cmd
3142 route_set_ipv6_nexthop_prefer_global_cmd
= {
3143 "ipv6 next-hop prefer-global",
3144 route_set_ipv6_nexthop_prefer_global
,
3145 route_set_ipv6_nexthop_prefer_global_compile
,
3146 route_set_ipv6_nexthop_prefer_global_free
3149 /* `set ipv6 nexthop local IP_ADDRESS' */
3151 /* Set nexthop to object. ojbect must be pointer to struct attr. */
3152 static enum route_map_cmd_result_t
3153 route_set_ipv6_nexthop_local(void *rule
, const struct prefix
*p
, void *object
)
3155 struct in6_addr
*address
;
3156 struct bgp_path_info
*path
;
3158 /* Fetch routemap's rule information. */
3162 /* Set next hop value. */
3163 path
->attr
->mp_nexthop_local
= *address
;
3165 /* Set nexthop length. */
3166 if (path
->attr
->mp_nexthop_len
!= BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
3167 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
3169 SET_FLAG(path
->attr
->rmap_change_flags
,
3170 BATTR_RMAP_IPV6_LL_NHOP_CHANGED
);
3175 /* Route map `ip nexthop' compile function. Given string is converted
3176 to struct in_addr structure. */
3177 static void *route_set_ipv6_nexthop_local_compile(const char *arg
)
3180 struct in6_addr
*address
;
3182 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3184 ret
= inet_pton(AF_INET6
, arg
, address
);
3187 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3194 /* Free route map's compiled `ip nexthop' value. */
3195 static void route_set_ipv6_nexthop_local_free(void *rule
)
3197 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3200 /* Route map commands for ip nexthop set. */
3201 static const struct route_map_rule_cmd
3202 route_set_ipv6_nexthop_local_cmd
= {
3203 "ipv6 next-hop local",
3204 route_set_ipv6_nexthop_local
,
3205 route_set_ipv6_nexthop_local_compile
,
3206 route_set_ipv6_nexthop_local_free
3209 /* `set ipv6 nexthop peer-address' */
3211 /* Set nexthop to object. ojbect must be pointer to struct attr. */
3212 static enum route_map_cmd_result_t
3213 route_set_ipv6_nexthop_peer(void *rule
, const struct prefix
*pfx
, void *object
)
3215 struct in6_addr peer_address
;
3216 struct bgp_path_info
*path
;
3219 /* Fetch routemap's rule information. */
3223 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
3224 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
3226 && sockunion_family(peer
->su_remote
) == AF_INET6
) {
3227 peer_address
= peer
->su_remote
->sin6
.sin6_addr
;
3228 /* Set next hop value and length in attribute. */
3229 if (IN6_IS_ADDR_LINKLOCAL(&peer_address
)) {
3230 path
->attr
->mp_nexthop_local
= peer_address
;
3231 if (path
->attr
->mp_nexthop_len
3232 != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
3233 path
->attr
->mp_nexthop_len
=
3234 BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
3236 path
->attr
->mp_nexthop_global
= peer_address
;
3237 if (path
->attr
->mp_nexthop_len
== 0)
3238 path
->attr
->mp_nexthop_len
=
3239 BGP_ATTR_NHLEN_IPV6_GLOBAL
;
3242 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
3243 /* The next hop value will be set as part of packet
3245 * Set the flags here to indicate that rewrite needs to
3247 * Also, clear the value - we clear both global and
3249 * nexthops, whether we send one or both is determined
3252 SET_FLAG(path
->attr
->rmap_change_flags
,
3253 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
3254 /* clear next hop value. */
3255 memset(&(path
->attr
->mp_nexthop_global
), 0,
3256 sizeof(struct in6_addr
));
3257 memset(&(path
->attr
->mp_nexthop_local
), 0,
3258 sizeof(struct in6_addr
));
3264 /* Route map `ip next-hop' compile function. Given string is converted
3265 to struct in_addr structure. */
3266 static void *route_set_ipv6_nexthop_peer_compile(const char *arg
)
3270 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
3276 /* Free route map's compiled `ip next-hop' value. */
3277 static void route_set_ipv6_nexthop_peer_free(void *rule
)
3279 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3282 /* Route map commands for ip nexthop set. */
3283 static const struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd
= {
3284 "ipv6 next-hop peer-address",
3285 route_set_ipv6_nexthop_peer
,
3286 route_set_ipv6_nexthop_peer_compile
,
3287 route_set_ipv6_nexthop_peer_free
3290 /* `set ipv4 vpn next-hop A.B.C.D' */
3292 static enum route_map_cmd_result_t
3293 route_set_vpnv4_nexthop(void *rule
, const struct prefix
*prefix
, void *object
)
3295 struct in_addr
*address
;
3296 struct bgp_path_info
*path
;
3298 /* Fetch routemap's rule information. */
3302 /* Set next hop value. */
3303 path
->attr
->mp_nexthop_global_in
= *address
;
3304 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV4
;
3309 static void *route_set_vpnv4_nexthop_compile(const char *arg
)
3312 struct in_addr
*address
;
3314 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3316 ret
= inet_aton(arg
, address
);
3319 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3326 /* `set ipv6 vpn next-hop A.B.C.D' */
3328 static enum route_map_cmd_result_t
3329 route_set_vpnv6_nexthop(void *rule
, const struct prefix
*prefix
, void *object
)
3331 struct in6_addr
*address
;
3332 struct bgp_path_info
*path
;
3334 /* Fetch routemap's rule information. */
3338 /* Set next hop value. */
3339 memcpy(&path
->attr
->mp_nexthop_global
, address
,
3340 sizeof(struct in6_addr
));
3341 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_VPNV6_GLOBAL
;
3346 static void *route_set_vpnv6_nexthop_compile(const char *arg
)
3349 struct in6_addr
*address
;
3351 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3352 ret
= inet_pton(AF_INET6
, arg
, address
);
3355 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3362 static void route_set_vpn_nexthop_free(void *rule
)
3364 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3367 /* Route map commands for ipv4 next-hop set. */
3368 static const struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd
= {
3369 "ipv4 vpn next-hop",
3370 route_set_vpnv4_nexthop
,
3371 route_set_vpnv4_nexthop_compile
,
3372 route_set_vpn_nexthop_free
3375 /* Route map commands for ipv6 next-hop set. */
3376 static const struct route_map_rule_cmd route_set_vpnv6_nexthop_cmd
= {
3377 "ipv6 vpn next-hop",
3378 route_set_vpnv6_nexthop
,
3379 route_set_vpnv6_nexthop_compile
,
3380 route_set_vpn_nexthop_free
3383 /* `set originator-id' */
3385 /* For origin set. */
3386 static enum route_map_cmd_result_t
3387 route_set_originator_id(void *rule
, const struct prefix
*prefix
, void *object
)
3389 struct in_addr
*address
;
3390 struct bgp_path_info
*path
;
3395 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
);
3396 path
->attr
->originator_id
= *address
;
3401 /* Compile function for originator-id set. */
3402 static void *route_set_originator_id_compile(const char *arg
)
3405 struct in_addr
*address
;
3407 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3409 ret
= inet_aton(arg
, address
);
3412 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3419 /* Compile function for originator_id set. */
3420 static void route_set_originator_id_free(void *rule
)
3422 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3425 /* Set originator-id rule structure. */
3426 static const struct route_map_rule_cmd route_set_originator_id_cmd
= {
3428 route_set_originator_id
,
3429 route_set_originator_id_compile
,
3430 route_set_originator_id_free
,
3434 * This is the workhorse routine for processing in/out routemap
3437 static void bgp_route_map_process_peer(const char *rmap_name
,
3438 struct route_map
*map
, struct peer
*peer
,
3439 int afi
, int safi
, int route_update
)
3441 struct bgp_filter
*filter
;
3443 if (!peer
|| !rmap_name
)
3446 filter
= &peer
->filter
[afi
][safi
];
3448 * in is for non-route-server clients,
3449 * out is for all peers
3451 if (filter
->map
[RMAP_IN
].name
3452 && (strcmp(rmap_name
, filter
->map
[RMAP_IN
].name
) == 0)) {
3453 filter
->map
[RMAP_IN
].map
= map
;
3455 if (route_update
&& peer_established(peer
)) {
3456 if (CHECK_FLAG(peer
->af_flags
[afi
][safi
],
3457 PEER_FLAG_SOFT_RECONFIG
)) {
3458 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3460 "Processing route_map %s(%s:%s) update on peer %s (inbound, soft-reconfig)",
3461 rmap_name
, afi2str(afi
),
3462 safi2str(safi
), peer
->host
);
3464 bgp_soft_reconfig_in(peer
, afi
, safi
);
3465 } else if (CHECK_FLAG(peer
->cap
,
3466 PEER_CAP_REFRESH_OLD_RCV
)
3467 || CHECK_FLAG(peer
->cap
,
3468 PEER_CAP_REFRESH_NEW_RCV
)) {
3469 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3471 "Processing route_map %s(%s:%s) update on peer %s (inbound, route-refresh)",
3472 rmap_name
, afi2str(afi
),
3473 safi2str(safi
), peer
->host
);
3474 bgp_route_refresh_send(
3475 peer
, afi
, safi
, 0, 0, 0,
3476 BGP_ROUTE_REFRESH_NORMAL
);
3482 * For outbound, unsuppress and default-originate map change (content or
3483 * map created), merely update the "config" here, the actual route
3484 * announcement happens at the group level.
3486 if (filter
->map
[RMAP_OUT
].name
3487 && (strcmp(rmap_name
, filter
->map
[RMAP_OUT
].name
) == 0))
3488 filter
->map
[RMAP_OUT
].map
= map
;
3490 if (filter
->usmap
.name
&& (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3491 filter
->usmap
.map
= map
;
3493 if (filter
->advmap
.aname
3494 && (strcmp(rmap_name
, filter
->advmap
.aname
) == 0)) {
3495 filter
->advmap
.amap
= map
;
3498 if (filter
->advmap
.cname
3499 && (strcmp(rmap_name
, filter
->advmap
.cname
) == 0)) {
3500 filter
->advmap
.cmap
= map
;
3503 if (peer
->default_rmap
[afi
][safi
].name
3504 && (strcmp(rmap_name
, peer
->default_rmap
[afi
][safi
].name
) == 0))
3505 peer
->default_rmap
[afi
][safi
].map
= map
;
3507 /* Notify BGP conditional advertisement scanner percess */
3508 peer
->advmap_config_change
[afi
][safi
] = true;
3511 static void bgp_route_map_update_peer_group(const char *rmap_name
,
3512 struct route_map
*map
,
3515 struct peer_group
*group
;
3516 struct listnode
*node
, *nnode
;
3517 struct bgp_filter
*filter
;
3524 /* All the peers have been updated correctly already. This is
3525 * just updating the placeholder data. No real update required.
3527 for (ALL_LIST_ELEMENTS(bgp
->group
, node
, nnode
, group
)) {
3528 FOREACH_AFI_SAFI (afi
, safi
) {
3529 filter
= &group
->conf
->filter
[afi
][safi
];
3531 for (direct
= RMAP_IN
; direct
< RMAP_MAX
; direct
++) {
3532 if ((filter
->map
[direct
].name
)
3533 && (strcmp(rmap_name
,
3534 filter
->map
[direct
].name
)
3536 filter
->map
[direct
].map
= map
;
3539 if (filter
->usmap
.name
3540 && (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3541 filter
->usmap
.map
= map
;
3547 * Note that if an extreme number (tens of thousands) of route-maps are in use
3548 * and if bgp has an extreme number of peers, network statements, etc then this
3549 * function can consume a lot of cycles. This is due to this function being
3550 * called for each route-map and within this function we walk the list of peers,
3551 * network statements, etc looking to see if they use this route-map.
3553 static void bgp_route_map_process_update(struct bgp
*bgp
, const char *rmap_name
,
3561 struct bgp_dest
*bn
;
3562 struct bgp_static
*bgp_static
;
3563 struct bgp_aggregate
*aggregate
;
3564 struct listnode
*node
, *nnode
;
3565 struct route_map
*map
;
3566 char buf
[INET6_ADDRSTRLEN
];
3568 map
= route_map_lookup_by_name(rmap_name
);
3570 for (ALL_LIST_ELEMENTS(bgp
->peer
, node
, nnode
, peer
)) {
3572 /* Ignore dummy peer-group structure */
3573 if (CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
))
3576 FOREACH_AFI_SAFI (afi
, safi
) {
3577 /* process in/out/import/export/default-orig
3579 bgp_route_map_process_peer(rmap_name
, map
, peer
, afi
,
3580 safi
, route_update
);
3584 /* for outbound/default-orig route-maps, process for groups */
3585 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
, rmap_name
,
3588 /* update peer-group config (template) */
3589 bgp_route_map_update_peer_group(rmap_name
, map
, bgp
);
3591 FOREACH_AFI_SAFI (afi
, safi
) {
3592 /* For table route-map updates. */
3593 if (!bgp_fibupd_safi(safi
))
3596 if (bgp
->table_map
[afi
][safi
].name
3597 && (strcmp(rmap_name
, bgp
->table_map
[afi
][safi
].name
)
3600 /* bgp->table_map[afi][safi].map is NULL.
3601 * i.e Route map creation event.
3602 * So update applied_counter.
3603 * If it is not NULL, i.e It may be routemap updation or
3604 * deletion. so no need to update the counter.
3606 if (!bgp
->table_map
[afi
][safi
].map
)
3607 route_map_counter_increment(map
);
3608 bgp
->table_map
[afi
][safi
].map
= map
;
3610 if (BGP_DEBUG(zebra
, ZEBRA
))
3612 "Processing route_map %s(%s:%s) update on table map",
3613 rmap_name
, afi2str(afi
),
3616 bgp_zebra_announce_table(bgp
, afi
, safi
);
3619 /* For network route-map updates. */
3620 for (bn
= bgp_table_top(bgp
->route
[afi
][safi
]); bn
;
3621 bn
= bgp_route_next(bn
)) {
3622 bgp_static
= bgp_dest_get_bgp_static_info(bn
);
3626 if (!bgp_static
->rmap
.name
3627 || (strcmp(rmap_name
, bgp_static
->rmap
.name
) != 0))
3630 if (!bgp_static
->rmap
.map
)
3631 route_map_counter_increment(map
);
3633 bgp_static
->rmap
.map
= map
;
3635 if (route_update
&& !bgp_static
->backdoor
) {
3636 const struct prefix
*bn_p
=
3637 bgp_dest_get_prefix(bn
);
3639 if (bgp_debug_zebra(bn_p
))
3641 "Processing route_map %s(%s:%s) update on static route %s",
3642 rmap_name
, afi2str(afi
),
3644 inet_ntop(bn_p
->family
,
3645 &bn_p
->u
.prefix
, buf
,
3647 bgp_static_update(bgp
, bn_p
, bgp_static
, afi
,
3652 /* For aggregate-address route-map updates. */
3653 for (bn
= bgp_table_top(bgp
->aggregate
[afi
][safi
]); bn
;
3654 bn
= bgp_route_next(bn
)) {
3655 aggregate
= bgp_dest_get_bgp_aggregate_info(bn
);
3661 /* Update suppress map pointer. */
3662 if (aggregate
->suppress_map_name
3663 && strmatch(aggregate
->suppress_map_name
,
3665 if (aggregate
->rmap
.map
== NULL
)
3666 route_map_counter_increment(map
);
3668 aggregate
->suppress_map
= map
;
3670 bgp_aggregate_toggle_suppressed(
3671 aggregate
, bgp
, bgp_dest_get_prefix(bn
),
3677 if (aggregate
->rmap
.name
3678 && strmatch(rmap_name
, aggregate
->rmap
.name
)) {
3679 if (aggregate
->rmap
.map
== NULL
)
3680 route_map_counter_increment(map
);
3682 aggregate
->rmap
.map
= map
;
3687 if (matched
&& route_update
) {
3688 const struct prefix
*bn_p
=
3689 bgp_dest_get_prefix(bn
);
3691 if (bgp_debug_zebra(bn_p
))
3693 "Processing route_map %s(%s:%s) update on aggregate-address route %s",
3694 rmap_name
, afi2str(afi
),
3696 inet_ntop(bn_p
->family
,
3697 &bn_p
->u
.prefix
, buf
,
3699 bgp_aggregate_route(bgp
, bn_p
, afi
, safi
,
3705 /* For redistribute route-map updates. */
3706 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
3707 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
3708 struct list
*red_list
;
3709 struct bgp_redist
*red
;
3711 red_list
= bgp
->redist
[afi
][i
];
3715 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
3717 || (strcmp(rmap_name
, red
->rmap
.name
) != 0))
3721 route_map_counter_increment(map
);
3723 red
->rmap
.map
= map
;
3728 if (BGP_DEBUG(zebra
, ZEBRA
))
3730 "Processing route_map %s(%s:%s) update on redistributed routes",
3731 rmap_name
, afi2str(afi
),
3734 bgp_redistribute_resend(bgp
, afi
, i
,
3739 /* for type5 command route-maps */
3740 FOREACH_AFI_SAFI (afi
, safi
) {
3741 if (!bgp
->adv_cmd_rmap
[afi
][safi
].name
3742 || strcmp(rmap_name
, bgp
->adv_cmd_rmap
[afi
][safi
].name
)
3746 /* Make sure the route-map is populated here if not already done */
3747 bgp
->adv_cmd_rmap
[afi
][safi
].map
= map
;
3749 if (BGP_DEBUG(zebra
, ZEBRA
))
3751 "Processing route_map %s(%s:%s) update on advertise type5 route command",
3752 rmap_name
, afi2str(afi
), safi2str(safi
));
3754 if (route_update
&& advertise_type5_routes(bgp
, afi
)) {
3755 bgp_evpn_withdraw_type5_routes(bgp
, afi
, safi
);
3756 bgp_evpn_advertise_type5_routes(bgp
, afi
, safi
);
3761 static void bgp_route_map_process_update_cb(char *rmap_name
)
3763 struct listnode
*node
, *nnode
;
3766 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
)) {
3767 bgp_route_map_process_update(bgp
, rmap_name
, 1);
3769 #ifdef ENABLE_BGP_VNC
3770 /* zlog_debug("%s: calling vnc_routemap_update", __func__); */
3771 vnc_routemap_update(bgp
, __func__
);
3775 vpn_policy_routemap_event(rmap_name
);
3778 int bgp_route_map_update_timer(struct thread
*thread
)
3780 bm
->t_rmap_update
= NULL
;
3782 route_map_walk_update_list(bgp_route_map_process_update_cb
);
3787 static void bgp_route_map_mark_update(const char *rmap_name
)
3789 struct listnode
*node
, *nnode
;
3792 /* If new update is received before the current timer timed out,
3793 * turn it off and start a new timer.
3795 THREAD_OFF(bm
->t_rmap_update
);
3797 /* rmap_update_timer of 0 means don't do route updates */
3798 if (bm
->rmap_update_timer
) {
3799 thread_add_timer(bm
->master
, bgp_route_map_update_timer
,
3800 NULL
, bm
->rmap_update_timer
,
3801 &bm
->t_rmap_update
);
3803 /* Signal the groups that a route-map update event has
3805 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3806 update_group_policy_update(bgp
,
3807 BGP_POLICY_ROUTE_MAP
,
3810 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3811 bgp_route_map_process_update(bgp
, rmap_name
, 0);
3812 #ifdef ENABLE_BGP_VNC
3813 zlog_debug("%s: calling vnc_routemap_update", __func__
);
3814 vnc_routemap_update(bgp
, __func__
);
3819 static void bgp_route_map_add(const char *rmap_name
)
3821 if (route_map_mark_updated(rmap_name
) == 0)
3822 bgp_route_map_mark_update(rmap_name
);
3824 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3827 static void bgp_route_map_delete(const char *rmap_name
)
3829 if (route_map_mark_updated(rmap_name
) == 0)
3830 bgp_route_map_mark_update(rmap_name
);
3832 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_DELETED
);
3835 static void bgp_route_map_event(const char *rmap_name
)
3837 if (route_map_mark_updated(rmap_name
) == 0)
3838 bgp_route_map_mark_update(rmap_name
);
3840 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3843 DEFUN_YANG (match_mac_address
,
3844 match_mac_address_cmd
,
3845 "match mac address WORD",
3848 "Match address of route\n"
3849 "MAC Access-list name\n")
3852 "./match-condition[condition='frr-bgp-route-map:mac-address-list']";
3853 char xpath_value
[XPATH_MAXLEN
];
3855 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
3856 snprintf(xpath_value
, sizeof(xpath_value
),
3857 "%s/rmap-match-condition/frr-bgp-route-map:list-name", xpath
);
3858 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[3]->arg
);
3860 return nb_cli_apply_changes(vty
, NULL
);
3863 DEFUN_YANG (no_match_mac_address
,
3864 no_match_mac_address_cmd
,
3865 "no match mac address WORD",
3869 "Match address of route\n"
3870 "MAC acess-list name\n")
3873 "./match-condition[condition='frr-bgp-route-map:mac-address-list']";
3875 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
3876 return nb_cli_apply_changes(vty
, NULL
);
3880 * Helper to handle the case of the user passing in a number or type string
3882 static const char *parse_evpn_rt_type(const char *num_rt_type
)
3884 switch (num_rt_type
[0]) {
3899 /* Was already full type string */
3903 DEFUN_YANG (match_evpn_route_type
,
3904 match_evpn_route_type_cmd
,
3905 "match evpn route-type <macip|2|multicast|3|prefix|5>",
3909 EVPN_TYPE_2_HELP_STR
3910 EVPN_TYPE_2_HELP_STR
3911 EVPN_TYPE_3_HELP_STR
3912 EVPN_TYPE_3_HELP_STR
3913 EVPN_TYPE_5_HELP_STR
3914 EVPN_TYPE_5_HELP_STR
)
3917 "./match-condition[condition='frr-bgp-route-map:evpn-route-type']";
3918 char xpath_value
[XPATH_MAXLEN
];
3920 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
3921 snprintf(xpath_value
, sizeof(xpath_value
),
3922 "%s/rmap-match-condition/frr-bgp-route-map:evpn-route-type",
3924 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
3925 parse_evpn_rt_type(argv
[3]->arg
));
3927 return nb_cli_apply_changes(vty
, NULL
);
3930 DEFUN_YANG (no_match_evpn_route_type
,
3931 no_match_evpn_route_type_cmd
,
3932 "no match evpn route-type <macip|2|multicast|3|prefix|5>",
3937 EVPN_TYPE_2_HELP_STR
3938 EVPN_TYPE_2_HELP_STR
3939 EVPN_TYPE_3_HELP_STR
3940 EVPN_TYPE_3_HELP_STR
3941 EVPN_TYPE_5_HELP_STR
3942 EVPN_TYPE_5_HELP_STR
)
3945 "./match-condition[condition='frr-bgp-route-map:evpn-route-type']";
3947 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
3949 return nb_cli_apply_changes(vty
, NULL
);
3953 DEFUN_YANG (match_evpn_vni
,
3955 "match evpn vni " CMD_VNI_RANGE
,
3962 "./match-condition[condition='frr-bgp-route-map:evpn-vni']";
3963 char xpath_value
[XPATH_MAXLEN
];
3965 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
3966 snprintf(xpath_value
, sizeof(xpath_value
),
3967 "%s/rmap-match-condition/frr-bgp-route-map:evpn-vni", xpath
);
3968 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[3]->arg
);
3970 return nb_cli_apply_changes(vty
, NULL
);
3973 DEFUN_YANG (no_match_evpn_vni
,
3974 no_match_evpn_vni_cmd
,
3975 "no match evpn vni " CMD_VNI_RANGE
,
3983 "./match-condition[condition='frr-bgp-route-map:evpn-vni']";
3984 char xpath_value
[XPATH_MAXLEN
];
3986 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
3987 snprintf(xpath_value
, sizeof(xpath_value
),
3988 "%s/rmap-match-condition/frr-bgp-route-map:evpn-vni", xpath
);
3989 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_DESTROY
, argv
[3]->arg
);
3991 return nb_cli_apply_changes(vty
, NULL
);
3994 DEFUN_YANG (match_evpn_default_route
,
3995 match_evpn_default_route_cmd
,
3996 "match evpn default-route",
3999 "default EVPN type-5 route\n")
4002 "./match-condition[condition='frr-bgp-route-map:evpn-default-route']";
4003 char xpath_value
[XPATH_MAXLEN
];
4005 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4007 snprintf(xpath_value
, sizeof(xpath_value
),
4008 "%s/rmap-match-condition/frr-bgp-route-map:evpn-default-route",
4010 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, NULL
);
4012 return nb_cli_apply_changes(vty
, NULL
);
4015 DEFUN_YANG (no_match_evpn_default_route
,
4016 no_match_evpn_default_route_cmd
,
4017 "no match evpn default-route",
4021 "default EVPN type-5 route\n")
4024 "./match-condition[condition='frr-bgp-route-map:evpn-default-route']";
4026 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4028 return nb_cli_apply_changes(vty
, NULL
);
4031 DEFUN_YANG (match_evpn_rd
,
4033 "match evpn rd ASN:NN_OR_IP-ADDRESS:NN",
4036 "Route Distinguisher\n"
4037 "ASN:XX or A.B.C.D:XX\n")
4040 "./match-condition[condition='frr-bgp-route-map:evpn-rd']";
4041 char xpath_value
[XPATH_MAXLEN
];
4043 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4045 xpath_value
, sizeof(xpath_value
),
4046 "%s/rmap-match-condition/frr-bgp-route-map:route-distinguisher",
4048 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[3]->arg
);
4050 return nb_cli_apply_changes(vty
, NULL
);
4053 DEFUN_YANG (no_match_evpn_rd
,
4054 no_match_evpn_rd_cmd
,
4055 "no match evpn rd ASN:NN_OR_IP-ADDRESS:NN",
4059 "Route Distinguisher\n"
4060 "ASN:XX or A.B.C.D:XX\n")
4063 "./match-condition[condition='frr-bgp-route-map:evpn-rd']";
4065 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4066 return nb_cli_apply_changes(vty
, NULL
);
4069 DEFPY_YANG(match_vrl_source_vrf
,
4070 match_vrl_source_vrf_cmd
,
4071 "match source-vrf NAME$vrf_name",
4077 "./match-condition[condition='frr-bgp-route-map:source-vrf']";
4078 char xpath_value
[XPATH_MAXLEN
];
4080 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4081 snprintf(xpath_value
, sizeof(xpath_value
),
4082 "%s/rmap-match-condition/frr-bgp-route-map:source-vrf", xpath
);
4083 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, vrf_name
);
4085 return nb_cli_apply_changes(vty
, NULL
);
4088 DEFPY_YANG(no_match_vrl_source_vrf
,
4089 no_match_vrl_source_vrf_cmd
,
4090 "no match source-vrf NAME$vrf_name",
4096 "./match-condition[condition='frr-bgp-route-map:source-vrf']";
4098 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4099 return nb_cli_apply_changes(vty
, NULL
);
4102 DEFPY_YANG (match_peer
,
4104 "match peer <A.B.C.D$addrv4|X:X::X:X$addrv6|WORD$intf>",
4106 "Match peer address\n"
4107 "IP address of peer\n"
4108 "IPv6 address of peer\n"
4109 "Interface name of peer\n")
4112 "./match-condition[condition='frr-bgp-route-map:peer']";
4113 char xpath_value
[XPATH_MAXLEN
];
4115 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4119 xpath_value
, sizeof(xpath_value
),
4120 "%s/rmap-match-condition/frr-bgp-route-map:peer-ipv4-address",
4122 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4124 } else if (addrv6_str
) {
4126 xpath_value
, sizeof(xpath_value
),
4127 "%s/rmap-match-condition/frr-bgp-route-map:peer-ipv6-address",
4129 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4133 xpath_value
, sizeof(xpath_value
),
4134 "%s/rmap-match-condition/frr-bgp-route-map:peer-interface",
4136 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, intf
);
4139 return nb_cli_apply_changes(vty
, NULL
);
4142 DEFUN_YANG (match_peer_local
,
4143 match_peer_local_cmd
,
4146 "Match peer address\n"
4147 "Static or Redistributed routes\n")
4150 "./match-condition[condition='frr-bgp-route-map:peer']";
4151 char xpath_value
[XPATH_MAXLEN
];
4153 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4155 snprintf(xpath_value
, sizeof(xpath_value
),
4156 "%s/rmap-match-condition/frr-bgp-route-map:peer-local", xpath
);
4157 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
4159 return nb_cli_apply_changes(vty
, NULL
);
4162 DEFUN_YANG (no_match_peer
,
4164 "no match peer [<local|A.B.C.D|X:X::X:X|WORD>]",
4167 "Match peer address\n"
4168 "Static or Redistributed routes\n"
4169 "IP address of peer\n"
4170 "IPv6 address of peer\n"
4171 "Interface name of peer\n")
4174 "./match-condition[condition='frr-bgp-route-map:peer']";
4176 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4178 return nb_cli_apply_changes(vty
, NULL
);
4181 #ifdef HAVE_SCRIPTING
4182 DEFUN_YANG (match_script
,
4184 "[no] match script WORD",
4187 "Execute script to determine match\n"
4188 "The script name to run, without .lua; e.g. 'myroutemap' to run myroutemap.lua\n")
4190 bool no
= strmatch(argv
[0]->text
, "no");
4192 argv_find(argv
, argc
, "WORD", &i
);
4193 const char *script
= argv
[i
]->arg
;
4195 "./match-condition[condition='frr-bgp-route-map:match-script']";
4196 char xpath_value
[XPATH_MAXLEN
];
4199 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4200 snprintf(xpath_value
, sizeof(xpath_value
),
4201 "%s/rmap-match-condition/frr-bgp-route-map:script",
4203 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_DESTROY
,
4206 return nb_cli_apply_changes(vty
, NULL
);
4209 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4210 snprintf(xpath_value
, sizeof(xpath_value
),
4211 "%s/rmap-match-condition/frr-bgp-route-map:script",
4213 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4216 return nb_cli_apply_changes(vty
, NULL
);
4218 #endif /* HAVE_SCRIPTING */
4220 /* match probability */
4221 DEFUN_YANG (match_probability
,
4222 match_probability_cmd
,
4223 "match probability (0-100)",
4225 "Match portion of routes defined by percentage value\n"
4226 "Percentage of routes\n")
4231 "./match-condition[condition='frr-bgp-route-map:probability']";
4232 char xpath_value
[XPATH_MAXLEN
];
4234 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4235 snprintf(xpath_value
, sizeof(xpath_value
),
4236 "%s/rmap-match-condition/frr-bgp-route-map:probability",
4238 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4239 argv
[idx_number
]->arg
);
4241 return nb_cli_apply_changes(vty
, NULL
);
4245 DEFUN_YANG (no_match_probability
,
4246 no_match_probability_cmd
,
4247 "no match probability [(1-99)]",
4250 "Match portion of routes defined by percentage value\n"
4251 "Percentage of routes\n")
4255 "./match-condition[condition='frr-bgp-route-map:probability']";
4256 char xpath_value
[XPATH_MAXLEN
];
4258 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4260 if (argc
<= idx_number
)
4261 return nb_cli_apply_changes(vty
, NULL
);
4263 snprintf(xpath_value
, sizeof(xpath_value
),
4264 "%s/rmap-match-condition/frr-bgp-route-map:probability",
4266 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_DESTROY
,
4267 argv
[idx_number
]->arg
);
4269 return nb_cli_apply_changes(vty
, NULL
);
4273 DEFPY_YANG (match_ip_route_source
,
4274 match_ip_route_source_cmd
,
4275 "match ip route-source <(1-199)|(1300-2699)|WORD>",
4278 "Match advertising source address of route\n"
4279 "IP access-list number\n"
4280 "IP access-list number (expanded range)\n"
4281 "IP standard access-list name\n")
4284 "./match-condition[condition='frr-bgp-route-map:ip-route-source']";
4285 char xpath_value
[XPATH_MAXLEN
+ 32];
4288 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4289 snprintf(xpath_value
, sizeof(xpath_value
),
4290 "%s/rmap-match-condition/frr-bgp-route-map:list-name",
4292 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4293 argv
[idx_acl
]->arg
);
4295 return nb_cli_apply_changes(vty
, NULL
);
4299 DEFUN_YANG (no_match_ip_route_source
,
4300 no_match_ip_route_source_cmd
,
4301 "no match ip route-source [<(1-199)|(1300-2699)|WORD>]",
4305 "Match advertising source address of route\n"
4306 "IP access-list number\n"
4307 "IP access-list number (expanded range)\n"
4308 "IP standard access-list name\n")
4311 "./match-condition[condition='frr-bgp-route-map:ip-route-source']";
4313 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4314 return nb_cli_apply_changes(vty
, NULL
);
4317 DEFUN_YANG (match_ip_route_source_prefix_list
,
4318 match_ip_route_source_prefix_list_cmd
,
4319 "match ip route-source prefix-list WORD",
4322 "Match advertising source address of route\n"
4323 "Match entries of prefix-lists\n"
4324 "IP prefix-list name\n")
4328 "./match-condition[condition='frr-bgp-route-map:ip-route-source-prefix-list']";
4329 char xpath_value
[XPATH_MAXLEN
+ 32];
4331 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4332 snprintf(xpath_value
, sizeof(xpath_value
),
4333 "%s/rmap-match-condition/frr-bgp-route-map:list-name", xpath
);
4334 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4335 argv
[idx_word
]->arg
);
4337 return nb_cli_apply_changes(vty
, NULL
);
4341 DEFUN_YANG (no_match_ip_route_source_prefix_list
,
4342 no_match_ip_route_source_prefix_list_cmd
,
4343 "no match ip route-source prefix-list [WORD]",
4347 "Match advertising source address of route\n"
4348 "Match entries of prefix-lists\n"
4349 "IP prefix-list name\n")
4352 "./match-condition[condition='frr-bgp-route-map:ip-route-source-prefix-list']";
4354 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4355 return nb_cli_apply_changes(vty
, NULL
);
4358 DEFUN_YANG (match_local_pref
,
4359 match_local_pref_cmd
,
4360 "match local-preference (0-4294967295)",
4362 "Match local-preference of route\n"
4368 "./match-condition[condition='frr-bgp-route-map:match-local-preference']";
4369 char xpath_value
[XPATH_MAXLEN
];
4371 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4372 snprintf(xpath_value
, sizeof(xpath_value
),
4373 "%s/rmap-match-condition/frr-bgp-route-map:local-preference",
4375 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4376 argv
[idx_number
]->arg
);
4378 return nb_cli_apply_changes(vty
, NULL
);
4382 DEFUN_YANG (no_match_local_pref
,
4383 no_match_local_pref_cmd
,
4384 "no match local-preference [(0-4294967295)]",
4387 "Match local preference of route\n"
4388 "Local preference value\n")
4390 int idx_localpref
= 3;
4392 "./match-condition[condition='frr-bgp-route-map:match-local-preference']";
4393 char xpath_value
[XPATH_MAXLEN
];
4395 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4397 if (argc
<= idx_localpref
)
4398 return nb_cli_apply_changes(vty
, NULL
);
4400 snprintf(xpath_value
, sizeof(xpath_value
),
4401 "%s/rmap-match-condition/frr-bgp-route-map:local-preference",
4403 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_DESTROY
,
4404 argv
[idx_localpref
]->arg
);
4406 return nb_cli_apply_changes(vty
, NULL
);
4410 DEFPY_YANG (match_community
,
4411 match_community_cmd
,
4412 "match community <(1-99)|(100-500)|WORD> [exact-match]",
4414 "Match BGP community list\n"
4415 "Community-list number (standard)\n"
4416 "Community-list number (expanded)\n"
4417 "Community-list name\n"
4418 "Do exact matching of communities\n")
4421 "./match-condition[condition='frr-bgp-route-map:match-community']";
4422 char xpath_value
[XPATH_MAXLEN
];
4423 char xpath_match
[XPATH_MAXLEN
];
4424 int idx_comm_list
= 2;
4426 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4429 xpath_value
, sizeof(xpath_value
),
4430 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name",
4432 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[idx_comm_list
]->arg
);
4436 xpath_match
, sizeof(xpath_match
),
4437 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match",
4439 nb_cli_enqueue_change(vty
, xpath_match
, NB_OP_MODIFY
,
4443 xpath_match
, sizeof(xpath_match
),
4444 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match",
4446 nb_cli_enqueue_change(vty
, xpath_match
, NB_OP_MODIFY
,
4450 return nb_cli_apply_changes(vty
, NULL
);
4453 DEFUN_YANG (no_match_community
,
4454 no_match_community_cmd
,
4455 "no match community [<(1-99)|(100-500)|WORD> [exact-match]]",
4458 "Match BGP community list\n"
4459 "Community-list number (standard)\n"
4460 "Community-list number (expanded)\n"
4461 "Community-list name\n"
4462 "Do exact matching of communities\n")
4465 "./match-condition[condition='frr-bgp-route-map:match-community']";
4467 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4468 return nb_cli_apply_changes(vty
, NULL
);
4471 DEFPY_YANG (match_lcommunity
,
4472 match_lcommunity_cmd
,
4473 "match large-community <(1-99)|(100-500)|WORD> [exact-match]",
4475 "Match BGP large community list\n"
4476 "Large Community-list number (standard)\n"
4477 "Large Community-list number (expanded)\n"
4478 "Large Community-list name\n"
4479 "Do exact matching of communities\n")
4482 "./match-condition[condition='frr-bgp-route-map:match-large-community']";
4483 char xpath_value
[XPATH_MAXLEN
];
4484 char xpath_match
[XPATH_MAXLEN
];
4485 int idx_lcomm_list
= 2;
4487 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4490 xpath_value
, sizeof(xpath_value
),
4491 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name",
4493 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[idx_lcomm_list
]->arg
);
4497 xpath_match
, sizeof(xpath_match
),
4498 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match",
4500 nb_cli_enqueue_change(vty
, xpath_match
, NB_OP_MODIFY
,
4504 xpath_match
, sizeof(xpath_match
),
4505 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match",
4507 nb_cli_enqueue_change(vty
, xpath_match
, NB_OP_MODIFY
,
4511 return nb_cli_apply_changes(vty
, NULL
);
4514 DEFUN_YANG (no_match_lcommunity
,
4515 no_match_lcommunity_cmd
,
4516 "no match large-community [<(1-99)|(100-500)|WORD> [exact-match]]",
4519 "Match BGP large community list\n"
4520 "Large Community-list number (standard)\n"
4521 "Large Community-list number (expanded)\n"
4522 "Large Community-list name\n"
4523 "Do exact matching of communities\n")
4526 "./match-condition[condition='frr-bgp-route-map:match-large-community']";
4528 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4529 return nb_cli_apply_changes(vty
, NULL
);
4532 DEFPY_YANG (match_ecommunity
,
4533 match_ecommunity_cmd
,
4534 "match extcommunity <(1-99)|(100-500)|WORD>",
4536 "Match BGP/VPN extended community list\n"
4537 "Extended community-list number (standard)\n"
4538 "Extended community-list number (expanded)\n"
4539 "Extended community-list name\n")
4542 "./match-condition[condition='frr-bgp-route-map:match-extcommunity']";
4543 char xpath_value
[XPATH_MAXLEN
];
4544 int idx_comm_list
= 2;
4546 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4549 xpath_value
, sizeof(xpath_value
),
4550 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name",
4552 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[idx_comm_list
]->arg
);
4554 return nb_cli_apply_changes(vty
, NULL
);
4558 DEFUN_YANG (no_match_ecommunity
,
4559 no_match_ecommunity_cmd
,
4560 "no match extcommunity [<(1-99)|(100-500)|WORD>]",
4563 "Match BGP/VPN extended community list\n"
4564 "Extended community-list number (standard)\n"
4565 "Extended community-list number (expanded)\n"
4566 "Extended community-list name\n")
4569 "./match-condition[condition='frr-bgp-route-map:match-extcommunity']";
4571 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4572 return nb_cli_apply_changes(vty
, NULL
);
4576 DEFUN_YANG (match_aspath
,
4578 "match as-path WORD",
4580 "Match BGP AS path list\n"
4581 "AS path access-list name\n")
4586 "./match-condition[condition='frr-bgp-route-map:as-path-list']";
4587 char xpath_value
[XPATH_MAXLEN
];
4589 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4590 snprintf(xpath_value
, sizeof(xpath_value
),
4591 "%s/rmap-match-condition/frr-bgp-route-map:list-name", xpath
);
4592 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4593 argv
[idx_word
]->arg
);
4595 return nb_cli_apply_changes(vty
, NULL
);
4599 DEFUN_YANG (no_match_aspath
,
4600 no_match_aspath_cmd
,
4601 "no match as-path [WORD]",
4604 "Match BGP AS path list\n"
4605 "AS path access-list name\n")
4608 "./match-condition[condition='frr-bgp-route-map:as-path-list']";
4610 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4612 return nb_cli_apply_changes(vty
, NULL
);
4615 DEFUN_YANG (match_origin
,
4617 "match origin <egp|igp|incomplete>",
4622 "unknown heritage\n")
4625 const char *origin_type
;
4627 "./match-condition[condition='frr-bgp-route-map:match-origin']";
4628 char xpath_value
[XPATH_MAXLEN
];
4630 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
4631 origin_type
= "igp";
4632 else if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
4633 origin_type
= "egp";
4634 else if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
4635 origin_type
= "incomplete";
4637 vty_out(vty
, "%% Invalid match origin type\n");
4638 return CMD_WARNING_CONFIG_FAILED
;
4641 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4642 snprintf(xpath_value
, sizeof(xpath_value
),
4643 "%s/rmap-match-condition/frr-bgp-route-map:origin", xpath
);
4644 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, origin_type
);
4646 return nb_cli_apply_changes(vty
, NULL
);
4650 DEFUN_YANG (no_match_origin
,
4651 no_match_origin_cmd
,
4652 "no match origin [<egp|igp|incomplete>]",
4658 "unknown heritage\n")
4661 "./match-condition[condition='frr-bgp-route-map:match-origin']";
4662 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4663 return nb_cli_apply_changes(vty
, NULL
);
4666 DEFUN_YANG (set_table_id
,
4668 "set table (1-4294967295)",
4670 "export route to non-main kernel table\n"
4671 "Kernel routing table id\n")
4674 const char *xpath
= "./set-action[action='frr-bgp-route-map:table']";
4675 char xpath_value
[XPATH_MAXLEN
];
4677 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4678 snprintf(xpath_value
, sizeof(xpath_value
),
4679 "%s/rmap-set-action/frr-bgp-route-map:table", xpath
);
4680 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4681 argv
[idx_number
]->arg
);
4682 return nb_cli_apply_changes(vty
, NULL
);
4685 DEFUN_YANG (no_set_table_id
,
4686 no_set_table_id_cmd
,
4690 "export route to non-main kernel table\n")
4692 const char *xpath
= "./set-action[action='frr-bgp-route-map:table']";
4693 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4694 return nb_cli_apply_changes(vty
, NULL
);
4697 DEFUN_YANG (set_ip_nexthop_peer
,
4698 set_ip_nexthop_peer_cmd
,
4699 "[no] set ip next-hop peer-address",
4703 "Next hop address\n"
4704 "Use peer address (for BGP only)\n")
4706 char xpath_value
[XPATH_MAXLEN
];
4708 "./set-action[action='frr-bgp-route-map:set-ipv4-nexthop']";
4710 if (strmatch(argv
[0]->text
, "no"))
4711 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4713 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4714 snprintf(xpath_value
, sizeof(xpath_value
),
4715 "%s/rmap-set-action/frr-bgp-route-map:ipv4-nexthop",
4717 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4720 return nb_cli_apply_changes(vty
, NULL
);
4723 DEFUN_YANG (set_ip_nexthop_unchanged
,
4724 set_ip_nexthop_unchanged_cmd
,
4725 "[no] set ip next-hop unchanged",
4729 "Next hop address\n"
4730 "Don't modify existing Next hop address\n")
4732 char xpath_value
[XPATH_MAXLEN
];
4734 "./set-action[action='frr-bgp-route-map:set-ipv4-nexthop']";
4736 if (strmatch(argv
[0]->text
, "no"))
4737 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4739 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4740 snprintf(xpath_value
, sizeof(xpath_value
),
4741 "%s/rmap-set-action/frr-bgp-route-map:ipv4-nexthop",
4743 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4746 return nb_cli_apply_changes(vty
, NULL
);
4749 DEFUN_YANG (set_distance
,
4751 "set distance (0-255)",
4753 "BGP Administrative Distance to use\n"
4757 const char *xpath
= "./set-action[action='frr-bgp-route-map:distance']";
4758 char xpath_value
[XPATH_MAXLEN
];
4760 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4761 snprintf(xpath_value
, sizeof(xpath_value
),
4762 "%s/rmap-set-action/frr-bgp-route-map:distance", xpath
);
4763 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4764 argv
[idx_number
]->arg
);
4765 return nb_cli_apply_changes(vty
, NULL
);
4768 DEFUN_YANG (no_set_distance
,
4769 no_set_distance_cmd
,
4770 "no set distance [(0-255)]",
4772 "BGP Administrative Distance to use\n"
4775 const char *xpath
= "./set-action[action='frr-bgp-route-map:distance']";
4777 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4778 return nb_cli_apply_changes(vty
, NULL
);
4781 DEFUN_YANG (set_local_pref
,
4783 "set local-preference WORD",
4785 "BGP local preference path attribute\n"
4786 "Preference value (0-4294967295)\n")
4790 "./set-action[action='frr-bgp-route-map:set-local-preference']";
4791 char xpath_value
[XPATH_MAXLEN
];
4793 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4794 snprintf(xpath_value
, sizeof(xpath_value
),
4795 "%s/rmap-set-action/frr-bgp-route-map:local-pref", xpath
);
4796 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4797 argv
[idx_number
]->arg
);
4798 return nb_cli_apply_changes(vty
, NULL
);
4801 DEFUN_YANG (no_set_local_pref
,
4802 no_set_local_pref_cmd
,
4803 "no set local-preference [WORD]",
4806 "BGP local preference path attribute\n"
4807 "Preference value (0-4294967295)\n")
4810 "./set-action[action='frr-bgp-route-map:set-local-preference']";
4812 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4813 return nb_cli_apply_changes(vty
, NULL
);
4816 DEFUN_YANG (set_weight
,
4818 "set weight (0-4294967295)",
4820 "BGP weight for routing table\n"
4824 const char *xpath
= "./set-action[action='frr-bgp-route-map:weight']";
4825 char xpath_value
[XPATH_MAXLEN
];
4827 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4828 snprintf(xpath_value
, sizeof(xpath_value
),
4829 "%s/rmap-set-action/frr-bgp-route-map:weight", xpath
);
4830 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4831 argv
[idx_number
]->arg
);
4832 return nb_cli_apply_changes(vty
, NULL
);
4835 DEFUN_YANG (no_set_weight
,
4837 "no set weight [(0-4294967295)]",
4840 "BGP weight for routing table\n"
4843 const char *xpath
= "./set-action[action='frr-bgp-route-map:weight']";
4845 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4846 return nb_cli_apply_changes(vty
, NULL
);
4849 DEFUN_YANG (set_label_index
,
4850 set_label_index_cmd
,
4851 "set label-index (0-1048560)",
4853 "Label index to associate with the prefix\n"
4854 "Label index value\n")
4858 "./set-action[action='frr-bgp-route-map:label-index']";
4859 char xpath_value
[XPATH_MAXLEN
];
4861 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4862 snprintf(xpath_value
, sizeof(xpath_value
),
4863 "%s/rmap-set-action/frr-bgp-route-map:label-index", xpath
);
4864 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4865 argv
[idx_number
]->arg
);
4866 return nb_cli_apply_changes(vty
, NULL
);
4869 DEFUN_YANG (no_set_label_index
,
4870 no_set_label_index_cmd
,
4871 "no set label-index [(0-1048560)]",
4874 "Label index to associate with the prefix\n"
4875 "Label index value\n")
4878 "./set-action[action='frr-bgp-route-map:label-index']";
4880 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4881 return nb_cli_apply_changes(vty
, NULL
);
4884 DEFUN_YANG (set_aspath_prepend_asn
,
4885 set_aspath_prepend_asn_cmd
,
4886 "set as-path prepend (1-4294967295)...",
4888 "Transform BGP AS_PATH attribute\n"
4889 "Prepend to the as-path\n"
4896 str
= argv_concat(argv
, argc
, idx_asn
);
4899 "./set-action[action='frr-bgp-route-map:as-path-prepend']";
4900 char xpath_value
[XPATH_MAXLEN
];
4902 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4903 snprintf(xpath_value
, sizeof(xpath_value
),
4904 "%s/rmap-set-action/frr-bgp-route-map:prepend-as-path", xpath
);
4905 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
4906 ret
= nb_cli_apply_changes(vty
, NULL
);
4907 XFREE(MTYPE_TMP
, str
);
4911 DEFUN_YANG (set_aspath_prepend_lastas
,
4912 set_aspath_prepend_lastas_cmd
,
4913 "set as-path prepend last-as (1-10)",
4915 "Transform BGP AS_PATH attribute\n"
4916 "Prepend to the as-path\n"
4917 "Use the peer's AS-number\n"
4918 "Number of times to insert\n")
4923 "./set-action[action='frr-bgp-route-map:as-path-prepend']";
4924 char xpath_value
[XPATH_MAXLEN
];
4926 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4927 snprintf(xpath_value
, sizeof(xpath_value
),
4928 "%s/rmap-set-action/frr-bgp-route-map:last-as", xpath
);
4929 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4930 argv
[idx_num
]->arg
);
4931 return nb_cli_apply_changes(vty
, NULL
);
4934 DEFUN_YANG (no_set_aspath_prepend
,
4935 no_set_aspath_prepend_cmd
,
4936 "no set as-path prepend [(1-4294967295)]",
4939 "Transform BGP AS_PATH attribute\n"
4940 "Prepend to the as-path\n"
4944 "./set-action[action='frr-bgp-route-map:as-path-prepend']";
4946 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4947 return nb_cli_apply_changes(vty
, NULL
);
4950 DEFUN_YANG (no_set_aspath_prepend_lastas
,
4951 no_set_aspath_prepend_lastas_cmd
,
4952 "no set as-path prepend last-as [(1-10)]",
4955 "Transform BGP AS_PATH attribute\n"
4956 "Prepend to the as-path\n"
4957 "Use the peers AS-number\n"
4958 "Number of times to insert\n")
4961 "./set-action[action='frr-bgp-route-map:as-path-prepend']";
4963 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4964 return nb_cli_apply_changes(vty
, NULL
);
4967 DEFUN_YANG (set_aspath_exclude
,
4968 set_aspath_exclude_cmd
,
4969 "set as-path exclude (1-4294967295)...",
4971 "Transform BGP AS-path attribute\n"
4972 "Exclude from the as-path\n"
4979 str
= argv_concat(argv
, argc
, idx_asn
);
4982 "./set-action[action='frr-bgp-route-map:as-path-exclude']";
4983 char xpath_value
[XPATH_MAXLEN
];
4985 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4986 snprintf(xpath_value
, sizeof(xpath_value
),
4987 "%s/rmap-set-action/frr-bgp-route-map:exclude-as-path", xpath
);
4988 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
4989 ret
= nb_cli_apply_changes(vty
, NULL
);
4990 XFREE(MTYPE_TMP
, str
);
4994 DEFUN_YANG (no_set_aspath_exclude
,
4995 no_set_aspath_exclude_cmd
,
4996 "no set as-path exclude (1-4294967295)...",
4999 "Transform BGP AS_PATH attribute\n"
5000 "Exclude from the as-path\n"
5004 "./set-action[action='frr-bgp-route-map:as-path-exclude']";
5006 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5007 return nb_cli_apply_changes(vty
, NULL
);
5010 ALIAS_YANG (no_set_aspath_exclude
, no_set_aspath_exclude_all_cmd
,
5011 "no set as-path exclude",
5013 "Transform BGP AS_PATH attribute\n"
5014 "Exclude from the as-path\n")
5016 DEFUN_YANG (set_community
,
5018 "set community AA:NN...",
5020 "BGP community attribute\n"
5028 struct community
*com
= NULL
;
5030 char *argstr
= NULL
;
5034 "./set-action[action='frr-bgp-route-map:set-community']";
5035 char xpath_value
[XPATH_MAXLEN
];
5037 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5038 snprintf(xpath_value
, sizeof(xpath_value
),
5039 "%s/rmap-set-action/frr-bgp-route-map:community-string",
5042 b
= buffer_new(1024);
5044 for (i
= idx_aa_nn
; i
< argc
; i
++) {
5045 if (strncmp(argv
[i
]->arg
, "additive", strlen(argv
[i
]->arg
))
5052 buffer_putc(b
, ' ');
5056 if (strncmp(argv
[i
]->arg
, "internet", strlen(argv
[i
]->arg
))
5058 buffer_putstr(b
, "internet");
5061 if (strncmp(argv
[i
]->arg
, "local-AS", strlen(argv
[i
]->arg
))
5063 buffer_putstr(b
, "local-AS");
5066 if (strncmp(argv
[i
]->arg
, "no-a", strlen("no-a")) == 0
5067 && strncmp(argv
[i
]->arg
, "no-advertise",
5068 strlen(argv
[i
]->arg
))
5070 buffer_putstr(b
, "no-advertise");
5073 if (strncmp(argv
[i
]->arg
, "no-e", strlen("no-e")) == 0
5074 && strncmp(argv
[i
]->arg
, "no-export", strlen(argv
[i
]->arg
))
5076 buffer_putstr(b
, "no-export");
5079 if (strncmp(argv
[i
]->arg
, "blackhole", strlen(argv
[i
]->arg
))
5081 buffer_putstr(b
, "blackhole");
5084 if (strncmp(argv
[i
]->arg
, "graceful-shutdown",
5085 strlen(argv
[i
]->arg
))
5087 buffer_putstr(b
, "graceful-shutdown");
5090 buffer_putstr(b
, argv
[i
]->arg
);
5092 buffer_putc(b
, '\0');
5094 /* Fetch result string then compile it to communities attribute. */
5095 str
= buffer_getstr(b
);
5099 com
= community_str2com(str
);
5100 XFREE(MTYPE_TMP
, str
);
5103 /* Can't compile user input into communities attribute. */
5105 vty_out(vty
, "%% Malformed communities attribute\n");
5106 return CMD_WARNING_CONFIG_FAILED
;
5109 /* Set communites attribute string. */
5110 str
= community_str(com
, false);
5113 size_t argstr_sz
= strlen(str
) + strlen(" additive") + 1;
5114 argstr
= XCALLOC(MTYPE_TMP
, argstr_sz
);
5115 strlcpy(argstr
, str
, argstr_sz
);
5116 strlcat(argstr
, " additive", argstr_sz
);
5117 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argstr
);
5119 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
5121 ret
= nb_cli_apply_changes(vty
, NULL
);
5124 XFREE(MTYPE_TMP
, argstr
);
5125 community_free(&com
);
5130 DEFUN_YANG (set_community_none
,
5131 set_community_none_cmd
,
5132 "set community none",
5134 "BGP community attribute\n"
5135 "No community attribute\n")
5138 "./set-action[action='frr-bgp-route-map:set-community']";
5139 char xpath_value
[XPATH_MAXLEN
];
5141 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5143 snprintf(xpath_value
, sizeof(xpath_value
),
5144 "%s/rmap-set-action/frr-bgp-route-map:community-none", xpath
);
5145 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
5146 return nb_cli_apply_changes(vty
, NULL
);
5149 DEFUN_YANG (no_set_community
,
5150 no_set_community_cmd
,
5151 "no set community AA:NN...",
5154 "BGP community attribute\n"
5158 "./set-action[action='frr-bgp-route-map:set-community']";
5160 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5161 return nb_cli_apply_changes(vty
, NULL
);
5164 ALIAS_YANG (no_set_community
,
5165 no_set_community_short_cmd
,
5169 "BGP community attribute\n")
5171 DEFPY_YANG (set_community_delete
,
5172 set_community_delete_cmd
,
5173 "set comm-list <(1-99)|(100-500)|WORD> delete",
5175 "set BGP community list (for deletion)\n"
5176 "Community-list number (standard)\n"
5177 "Community-list number (expanded)\n"
5178 "Community-list name\n"
5179 "Delete matching communities\n")
5182 "./set-action[action='frr-bgp-route-map:comm-list-delete']";
5183 char xpath_value
[XPATH_MAXLEN
];
5184 int idx_comm_list
= 2;
5186 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5188 snprintf(xpath_value
, sizeof(xpath_value
),
5189 "%s/rmap-set-action/frr-bgp-route-map:comm-list-name",
5191 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5192 argv
[idx_comm_list
]->arg
);
5194 return nb_cli_apply_changes(vty
, NULL
);
5198 DEFUN_YANG (no_set_community_delete
,
5199 no_set_community_delete_cmd
,
5200 "no set comm-list [<(1-99)|(100-500)|WORD> delete]",
5203 "set BGP community list (for deletion)\n"
5204 "Community-list number (standard)\n"
5205 "Community-list number (expanded)\n"
5206 "Community-list name\n"
5207 "Delete matching communities\n")
5210 "./set-action[action='frr-bgp-route-map:comm-list-delete']";
5212 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5213 return nb_cli_apply_changes(vty
, NULL
);
5216 DEFUN_YANG (set_lcommunity
,
5218 "set large-community AA:BB:CC...",
5220 "BGP large community attribute\n"
5221 "Large Community number in aa:bb:cc format or additive\n")
5226 "./set-action[action='frr-bgp-route-map:set-large-community']";
5227 char xpath_value
[XPATH_MAXLEN
];
5229 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5231 snprintf(xpath_value
, sizeof(xpath_value
),
5232 "%s/rmap-set-action/frr-bgp-route-map:large-community-string",
5234 str
= argv_concat(argv
, argc
, 2);
5235 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
5236 ret
= nb_cli_apply_changes(vty
, NULL
);
5237 XFREE(MTYPE_TMP
, str
);
5241 DEFUN_YANG (set_lcommunity_none
,
5242 set_lcommunity_none_cmd
,
5243 "set large-community none",
5245 "BGP large community attribute\n"
5246 "No large community attribute\n")
5249 "./set-action[action='frr-bgp-route-map:set-large-community']";
5250 char xpath_value
[XPATH_MAXLEN
];
5252 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5254 snprintf(xpath_value
, sizeof(xpath_value
),
5255 "%s/rmap-set-action/frr-bgp-route-map:large-community-none",
5257 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
5258 return nb_cli_apply_changes(vty
, NULL
);
5261 DEFUN_YANG (no_set_lcommunity
,
5262 no_set_lcommunity_cmd
,
5263 "no set large-community none",
5266 "BGP large community attribute\n"
5267 "No community attribute\n")
5270 "./set-action[action='frr-bgp-route-map:set-large-community']";
5272 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5273 return nb_cli_apply_changes(vty
, NULL
);
5276 DEFUN_YANG (no_set_lcommunity1
,
5277 no_set_lcommunity1_cmd
,
5278 "no set large-community AA:BB:CC...",
5281 "BGP large community attribute\n"
5282 "Large community in AA:BB:CC... format or additive\n")
5285 "./set-action[action='frr-bgp-route-map:set-large-community']";
5287 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5288 return nb_cli_apply_changes(vty
, NULL
);
5291 ALIAS_YANG (no_set_lcommunity1
,
5292 no_set_lcommunity1_short_cmd
,
5293 "no set large-community",
5296 "BGP large community attribute\n")
5298 DEFPY_YANG (set_lcommunity_delete
,
5299 set_lcommunity_delete_cmd
,
5300 "set large-comm-list <(1-99)|(100-500)|WORD> delete",
5302 "set BGP large community list (for deletion)\n"
5303 "Large Community-list number (standard)\n"
5304 "Large Communitly-list number (expanded)\n"
5305 "Large Community-list name\n"
5306 "Delete matching large communities\n")
5309 "./set-action[action='frr-bgp-route-map:large-comm-list-delete']";
5310 char xpath_value
[XPATH_MAXLEN
];
5311 int idx_lcomm_list
= 2;
5313 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5315 snprintf(xpath_value
, sizeof(xpath_value
),
5316 "%s/rmap-set-action/frr-bgp-route-map:comm-list-name",
5318 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5319 argv
[idx_lcomm_list
]->arg
);
5321 return nb_cli_apply_changes(vty
, NULL
);
5324 DEFUN_YANG (no_set_lcommunity_delete
,
5325 no_set_lcommunity_delete_cmd
,
5326 "no set large-comm-list <(1-99)|(100-500)|WORD> [delete]",
5329 "set BGP large community list (for deletion)\n"
5330 "Large Community-list number (standard)\n"
5331 "Large Communitly-list number (expanded)\n"
5332 "Large Community-list name\n"
5333 "Delete matching large communities\n")
5336 "./set-action[action='frr-bgp-route-map:large-comm-list-delete']";
5338 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5339 return nb_cli_apply_changes(vty
, NULL
);
5342 ALIAS_YANG (no_set_lcommunity_delete
,
5343 no_set_lcommunity_delete_short_cmd
,
5344 "no set large-comm-list",
5347 "set BGP large community list (for deletion)\n")
5349 DEFUN_YANG (set_ecommunity_rt
,
5350 set_ecommunity_rt_cmd
,
5351 "set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
5353 "BGP extended community attribute\n"
5354 "Route Target extended community\n"
5355 "VPN extended community\n")
5361 "./set-action[action='frr-bgp-route-map:set-extcommunity-rt']";
5362 char xpath_value
[XPATH_MAXLEN
];
5364 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5366 snprintf(xpath_value
, sizeof(xpath_value
),
5367 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-rt", xpath
);
5368 str
= argv_concat(argv
, argc
, idx_asn_nn
);
5369 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
5370 ret
= nb_cli_apply_changes(vty
, NULL
);
5371 XFREE(MTYPE_TMP
, str
);
5375 DEFUN_YANG (no_set_ecommunity_rt
,
5376 no_set_ecommunity_rt_cmd
,
5377 "no set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
5380 "BGP extended community attribute\n"
5381 "Route Target extended community\n"
5382 "VPN extended community\n")
5385 "./set-action[action='frr-bgp-route-map:set-extcommunity-rt']";
5386 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5387 return nb_cli_apply_changes(vty
, NULL
);
5390 ALIAS_YANG (no_set_ecommunity_rt
,
5391 no_set_ecommunity_rt_short_cmd
,
5392 "no set extcommunity rt",
5395 "BGP extended community attribute\n"
5396 "Route Target extended community\n")
5398 DEFUN_YANG (set_ecommunity_soo
,
5399 set_ecommunity_soo_cmd
,
5400 "set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
5402 "BGP extended community attribute\n"
5403 "Site-of-Origin extended community\n"
5404 "VPN extended community\n")
5410 "./set-action[action='frr-bgp-route-map:set-extcommunity-soo']";
5411 char xpath_value
[XPATH_MAXLEN
];
5413 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5415 snprintf(xpath_value
, sizeof(xpath_value
),
5416 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-soo",
5418 str
= argv_concat(argv
, argc
, idx_asn_nn
);
5419 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
5420 ret
= nb_cli_apply_changes(vty
, NULL
);
5421 XFREE(MTYPE_TMP
, str
);
5425 DEFUN_YANG (no_set_ecommunity_soo
,
5426 no_set_ecommunity_soo_cmd
,
5427 "no set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
5430 "BGP extended community attribute\n"
5431 "Site-of-Origin extended community\n"
5432 "VPN extended community\n")
5435 "./set-action[action='frr-bgp-route-map:set-extcommunity-soo']";
5436 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5437 return nb_cli_apply_changes(vty
, NULL
);
5440 ALIAS_YANG (no_set_ecommunity_soo
,
5441 no_set_ecommunity_soo_short_cmd
,
5442 "no set extcommunity soo",
5445 "GP extended community attribute\n"
5446 "Site-of-Origin extended community\n")
5448 DEFUN_YANG (set_ecommunity_lb
,
5449 set_ecommunity_lb_cmd
,
5450 "set extcommunity bandwidth <(1-25600)|cumulative|num-multipaths> [non-transitive]",
5452 "BGP extended community attribute\n"
5453 "Link bandwidth extended community\n"
5454 "Bandwidth value in Mbps\n"
5455 "Cumulative bandwidth of all multipaths (outbound-only)\n"
5456 "Internally computed bandwidth based on number of multipaths (outbound-only)\n"
5457 "Attribute is set as non-transitive\n")
5460 int idx_non_transitive
= 4;
5462 "./set-action[action='frr-bgp-route-map:set-extcommunity-lb']";
5463 char xpath_lb_type
[XPATH_MAXLEN
];
5464 char xpath_bandwidth
[XPATH_MAXLEN
];
5465 char xpath_non_transitive
[XPATH_MAXLEN
];
5467 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5469 snprintf(xpath_lb_type
, sizeof(xpath_lb_type
),
5470 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-lb/lb-type",
5472 snprintf(xpath_bandwidth
, sizeof(xpath_bandwidth
),
5473 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-lb/bandwidth",
5475 snprintf(xpath_non_transitive
, sizeof(xpath_non_transitive
),
5476 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-lb/two-octet-as-specific",
5479 if ((strcmp(argv
[idx_lb
]->arg
, "cumulative")) == 0)
5480 nb_cli_enqueue_change(vty
, xpath_lb_type
, NB_OP_MODIFY
,
5481 "cumulative-bandwidth");
5482 else if ((strcmp(argv
[idx_lb
]->arg
, "num-multipaths")) == 0)
5483 nb_cli_enqueue_change(vty
, xpath_lb_type
, NB_OP_MODIFY
,
5484 "computed-bandwidth");
5486 nb_cli_enqueue_change(vty
, xpath_lb_type
, NB_OP_MODIFY
,
5487 "explicit-bandwidth");
5488 nb_cli_enqueue_change(vty
, xpath_bandwidth
, NB_OP_MODIFY
,
5492 if (argv
[idx_non_transitive
])
5493 nb_cli_enqueue_change(vty
, xpath_non_transitive
, NB_OP_MODIFY
,
5496 nb_cli_enqueue_change(vty
, xpath_non_transitive
, NB_OP_MODIFY
,
5499 return nb_cli_apply_changes(vty
, NULL
);
5502 DEFUN_YANG (no_set_ecommunity_lb
,
5503 no_set_ecommunity_lb_cmd
,
5504 "no set extcommunity bandwidth <(1-25600)|cumulative|num-multipaths> [non-transitive]",
5507 "BGP extended community attribute\n"
5508 "Link bandwidth extended community\n"
5509 "Bandwidth value in Mbps\n"
5510 "Cumulative bandwidth of all multipaths (outbound-only)\n"
5511 "Internally computed bandwidth based on number of multipaths (outbound-only)\n"
5512 "Attribute is set as non-transitive\n")
5515 "./set-action[action='frr-bgp-route-map:set-extcommunity-lb']";
5517 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5518 return nb_cli_apply_changes(vty
, NULL
);
5521 ALIAS_YANG (no_set_ecommunity_lb
,
5522 no_set_ecommunity_lb_short_cmd
,
5523 "no set extcommunity bandwidth",
5526 "BGP extended community attribute\n"
5527 "Link bandwidth extended community\n")
5529 DEFUN_YANG (set_origin
,
5531 "set origin <egp|igp|incomplete>",
5536 "unknown heritage\n")
5539 const char *origin_type
;
5541 "./set-action[action='frr-bgp-route-map:set-origin']";
5542 char xpath_value
[XPATH_MAXLEN
];
5544 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
5545 origin_type
= "igp";
5546 else if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
5547 origin_type
= "egp";
5548 else if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
5549 origin_type
= "incomplete";
5551 vty_out(vty
, "%% Invalid match origin type\n");
5552 return CMD_WARNING_CONFIG_FAILED
;
5555 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5556 snprintf(xpath_value
, sizeof(xpath_value
),
5557 "%s/rmap-set-action/frr-bgp-route-map:origin", xpath
);
5558 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, origin_type
);
5560 return nb_cli_apply_changes(vty
, NULL
);
5563 DEFUN_YANG (no_set_origin
,
5565 "no set origin [<egp|igp|incomplete>]",
5571 "unknown heritage\n")
5574 "./set-action[action='frr-bgp-route-map:set-origin']";
5576 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5577 return nb_cli_apply_changes(vty
, NULL
);
5580 DEFUN_YANG (set_atomic_aggregate
,
5581 set_atomic_aggregate_cmd
,
5582 "set atomic-aggregate",
5584 "BGP atomic aggregate attribute\n" )
5587 "./set-action[action='frr-bgp-route-map:atomic-aggregate']";
5588 char xpath_value
[XPATH_MAXLEN
];
5590 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5591 snprintf(xpath_value
, sizeof(xpath_value
),
5592 "%s/rmap-set-action/frr-bgp-route-map:atomic-aggregate",
5594 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, NULL
);
5596 return nb_cli_apply_changes(vty
, NULL
);
5599 DEFUN_YANG (no_set_atomic_aggregate
,
5600 no_set_atomic_aggregate_cmd
,
5601 "no set atomic-aggregate",
5604 "BGP atomic aggregate attribute\n" )
5607 "./set-action[action='frr-bgp-route-map:atomic-aggregate']";
5609 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5610 return nb_cli_apply_changes(vty
, NULL
);
5613 DEFUN_YANG (set_aggregator_as
,
5614 set_aggregator_as_cmd
,
5615 "set aggregator as (1-4294967295) A.B.C.D",
5617 "BGP aggregator attribute\n"
5618 "AS number of aggregator\n"
5620 "IP address of aggregator\n")
5624 char xpath_asn
[XPATH_MAXLEN
];
5625 char xpath_addr
[XPATH_MAXLEN
];
5627 "./set-action[action='frr-bgp-route-map:aggregator']";
5629 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5632 xpath_asn
, sizeof(xpath_asn
),
5633 "%s/rmap-set-action/frr-bgp-route-map:aggregator/aggregator-asn",
5635 nb_cli_enqueue_change(vty
, xpath_asn
, NB_OP_MODIFY
,
5636 argv
[idx_number
]->arg
);
5639 xpath_addr
, sizeof(xpath_addr
),
5640 "%s/rmap-set-action/frr-bgp-route-map:aggregator/aggregator-address",
5642 nb_cli_enqueue_change(vty
, xpath_addr
, NB_OP_MODIFY
,
5643 argv
[idx_ipv4
]->arg
);
5645 return nb_cli_apply_changes(vty
, NULL
);
5648 DEFUN_YANG (no_set_aggregator_as
,
5649 no_set_aggregator_as_cmd
,
5650 "no set aggregator as [(1-4294967295) A.B.C.D]",
5653 "BGP aggregator attribute\n"
5654 "AS number of aggregator\n"
5656 "IP address of aggregator\n")
5659 "./set-action[action='frr-bgp-route-map:aggregator']";
5661 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5662 return nb_cli_apply_changes(vty
, NULL
);
5665 DEFUN_YANG (match_ipv6_next_hop
,
5666 match_ipv6_next_hop_cmd
,
5667 "match ipv6 next-hop X:X::X:X",
5670 "Match IPv6 next-hop address of route\n"
5671 "IPv6 address of next hop\n")
5674 "./match-condition[condition='frr-bgp-route-map:ipv6-nexthop']";
5675 char xpath_value
[XPATH_MAXLEN
];
5677 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5678 snprintf(xpath_value
, sizeof(xpath_value
),
5679 "%s/rmap-match-condition/frr-bgp-route-map:ipv6-address",
5681 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[3]->arg
);
5683 return nb_cli_apply_changes(vty
, NULL
);
5686 DEFUN_YANG (no_match_ipv6_next_hop
,
5687 no_match_ipv6_next_hop_cmd
,
5688 "no match ipv6 next-hop X:X::X:X",
5692 "Match IPv6 next-hop address of route\n"
5693 "IPv6 address of next hop\n")
5696 "./match-condition[condition='frr-bgp-route-map:ipv6-nexthop']";
5698 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5699 return nb_cli_apply_changes(vty
, NULL
);
5702 DEFPY_YANG (match_ipv4_next_hop
,
5703 match_ipv4_next_hop_cmd
,
5704 "match ip next-hop address A.B.C.D",
5707 "Match IP next-hop address of route\n"
5709 "IP address of next-hop\n")
5712 "./match-condition[condition='frr-bgp-route-map:ipv4-nexthop']";
5713 char xpath_value
[XPATH_MAXLEN
];
5715 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5716 snprintf(xpath_value
, sizeof(xpath_value
),
5717 "%s/rmap-match-condition/frr-bgp-route-map:ipv4-address",
5719 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[4]->arg
);
5721 return nb_cli_apply_changes(vty
, NULL
);
5724 DEFPY_YANG (no_match_ipv4_next_hop
,
5725 no_match_ipv4_next_hop_cmd
,
5726 "no match ip next-hop address [A.B.C.D]",
5730 "Match IP next-hop address of route\n"
5732 "IP address of next-hop\n")
5735 "./match-condition[condition='frr-bgp-route-map:ipv4-nexthop']";
5737 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5738 return nb_cli_apply_changes(vty
, NULL
);
5741 DEFUN_YANG (set_ipv6_nexthop_peer
,
5742 set_ipv6_nexthop_peer_cmd
,
5743 "set ipv6 next-hop peer-address",
5746 "Next hop address\n"
5747 "Use peer address (for BGP only)\n")
5750 "./set-action[action='frr-bgp-route-map:ipv6-peer-address']";
5751 char xpath_value
[XPATH_MAXLEN
];
5753 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5754 snprintf(xpath_value
, sizeof(xpath_value
),
5755 "%s/rmap-set-action/frr-bgp-route-map:preference", xpath
);
5756 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
5758 return nb_cli_apply_changes(vty
, NULL
);
5761 DEFUN_YANG (no_set_ipv6_nexthop_peer
,
5762 no_set_ipv6_nexthop_peer_cmd
,
5763 "no set ipv6 next-hop peer-address",
5767 "IPv6 next-hop address\n"
5768 "Use peer address (for BGP only)\n")
5771 "./set-action[action='frr-bgp-route-map:ipv6-peer-address']";
5773 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5774 return nb_cli_apply_changes(vty
, NULL
);
5777 DEFUN_YANG (set_ipv6_nexthop_prefer_global
,
5778 set_ipv6_nexthop_prefer_global_cmd
,
5779 "set ipv6 next-hop prefer-global",
5782 "IPv6 next-hop address\n"
5783 "Prefer global over link-local if both exist\n")
5786 "./set-action[action='frr-bgp-route-map:ipv6-prefer-global']";
5787 char xpath_value
[XPATH_MAXLEN
];
5789 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5790 snprintf(xpath_value
, sizeof(xpath_value
),
5791 "%s/rmap-set-action/frr-bgp-route-map:preference", xpath
);
5792 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
5794 return nb_cli_apply_changes(vty
, NULL
);
5797 DEFUN_YANG (no_set_ipv6_nexthop_prefer_global
,
5798 no_set_ipv6_nexthop_prefer_global_cmd
,
5799 "no set ipv6 next-hop prefer-global",
5803 "IPv6 next-hop address\n"
5804 "Prefer global over link-local if both exist\n")
5807 "./set-action[action='frr-bgp-route-map:ipv6-prefer-global']";
5809 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5810 return nb_cli_apply_changes(vty
, NULL
);
5813 DEFUN_YANG (set_ipv6_nexthop_global
,
5814 set_ipv6_nexthop_global_cmd
,
5815 "set ipv6 next-hop global X:X::X:X",
5818 "IPv6 next-hop address\n"
5819 "IPv6 global address\n"
5820 "IPv6 address of next hop\n")
5824 "./set-action[action='frr-bgp-route-map:ipv6-nexthop-global']";
5825 char xpath_value
[XPATH_MAXLEN
];
5827 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5828 snprintf(xpath_value
, sizeof(xpath_value
),
5829 "%s/rmap-set-action/frr-bgp-route-map:ipv6-address", xpath
);
5830 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5831 argv
[idx_ipv6
]->arg
);
5833 return nb_cli_apply_changes(vty
, NULL
);
5836 DEFUN_YANG (no_set_ipv6_nexthop_global
,
5837 no_set_ipv6_nexthop_global_cmd
,
5838 "no set ipv6 next-hop global X:X::X:X",
5842 "IPv6 next-hop address\n"
5843 "IPv6 global address\n"
5844 "IPv6 address of next hop\n")
5847 "./set-action[action='frr-bgp-route-map:ipv6-nexthop-global']";
5849 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5850 return nb_cli_apply_changes(vty
, NULL
);
5853 #ifdef KEEP_OLD_VPN_COMMANDS
5854 DEFUN_YANG (set_vpn_nexthop
,
5855 set_vpn_nexthop_cmd
,
5856 "set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
5858 "VPNv4 information\n"
5859 "VPN next-hop address\n"
5860 "IP address of next hop\n"
5861 "VPNv6 information\n"
5862 "VPN next-hop address\n"
5863 "IPv6 address of next hop\n")
5868 char xpath_value
[XPATH_MAXLEN
];
5870 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
5871 if (afi
== AFI_IP
) {
5873 "./set-action[action='frr-bgp-route-map:ipv4-vpn-address']";
5875 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5877 xpath_value
, sizeof(xpath_value
),
5878 "%s/rmap-set-action/frr-bgp-route-map:ipv4-address",
5882 "./set-action[action='frr-bgp-route-map:ipv6-vpn-address']";
5884 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5886 xpath_value
, sizeof(xpath_value
),
5887 "%s/rmap-set-action/frr-bgp-route-map:ipv6-address",
5891 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5894 return nb_cli_apply_changes(vty
, NULL
);
5900 DEFUN_YANG (no_set_vpn_nexthop
,
5901 no_set_vpn_nexthop_cmd
,
5902 "no set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
5905 "VPNv4 information\n"
5906 "VPN next-hop address\n"
5907 "IP address of next hop\n"
5908 "VPNv6 information\n"
5909 "VPN next-hop address\n"
5910 "IPv6 address of next hop\n")
5915 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
5916 if (afi
== AFI_IP
) {
5918 "./set-action[action='frr-bgp-route-map:ipv4-vpn-address']";
5919 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5922 "./set-action[action='frr-bgp-route-map:ipv6-vpn-address']";
5923 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5925 return nb_cli_apply_changes(vty
, NULL
);
5929 #endif /* KEEP_OLD_VPN_COMMANDS */
5931 DEFUN_YANG (set_ipx_vpn_nexthop
,
5932 set_ipx_vpn_nexthop_cmd
,
5933 "set <ipv4|ipv6> vpn next-hop <A.B.C.D|X:X::X:X>",
5935 "IPv4 information\n"
5936 "IPv6 information\n"
5938 "VPN next-hop address\n"
5939 "IP address of next hop\n"
5940 "IPv6 address of next hop\n")
5945 char xpath_value
[XPATH_MAXLEN
];
5947 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
5948 if (afi
== AFI_IP
) {
5950 "./set-action[action='frr-bgp-route-map:ipv4-vpn-address']";
5952 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5954 xpath_value
, sizeof(xpath_value
),
5955 "%s/rmap-set-action/frr-bgp-route-map:ipv4-address",
5959 "./set-action[action='frr-bgp-route-map:ipv6-vpn-address']";
5961 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5963 xpath_value
, sizeof(xpath_value
),
5964 "%s/rmap-set-action/frr-bgp-route-map:ipv6-address",
5967 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5969 return nb_cli_apply_changes(vty
, NULL
);
5974 DEFUN_YANG (no_set_ipx_vpn_nexthop
,
5975 no_set_ipx_vpn_nexthop_cmd
,
5976 "no set <ipv4|ipv6> vpn next-hop [<A.B.C.D|X:X::X:X>]",
5979 "IPv4 information\n"
5980 "IPv6 information\n"
5982 "VPN next-hop address\n"
5983 "IP address of next hop\n"
5984 "IPv6 address of next hop\n")
5989 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
5990 if (afi
== AFI_IP
) {
5992 "./set-action[action='frr-bgp-route-map:ipv4-vpn-address']";
5993 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5996 "./set-action[action='frr-bgp-route-map:ipv6-vpn-address']";
5997 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5999 return nb_cli_apply_changes(vty
, NULL
);
6004 DEFUN_YANG (set_originator_id
,
6005 set_originator_id_cmd
,
6006 "set originator-id A.B.C.D",
6008 "BGP originator ID attribute\n"
6009 "IP address of originator\n")
6013 "./set-action[action='frr-bgp-route-map:originator-id']";
6014 char xpath_value
[XPATH_MAXLEN
];
6016 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6017 snprintf(xpath_value
, sizeof(xpath_value
),
6018 "%s/rmap-set-action/frr-bgp-route-map:originator-id", xpath
);
6019 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6020 argv
[idx_ipv4
]->arg
);
6022 return nb_cli_apply_changes(vty
, NULL
);
6025 DEFUN_YANG (no_set_originator_id
,
6026 no_set_originator_id_cmd
,
6027 "no set originator-id [A.B.C.D]",
6030 "BGP originator ID attribute\n"
6031 "IP address of originator\n")
6034 "./set-action[action='frr-bgp-route-map:originator-id']";
6036 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6037 return nb_cli_apply_changes(vty
, NULL
);
6040 /* Initialization of route map. */
6041 void bgp_route_map_init(void)
6045 route_map_add_hook(bgp_route_map_add
);
6046 route_map_delete_hook(bgp_route_map_delete
);
6047 route_map_event_hook(bgp_route_map_event
);
6049 route_map_match_interface_hook(generic_match_add
);
6050 route_map_no_match_interface_hook(generic_match_delete
);
6052 route_map_match_ip_address_hook(generic_match_add
);
6053 route_map_no_match_ip_address_hook(generic_match_delete
);
6055 route_map_match_ip_address_prefix_list_hook(generic_match_add
);
6056 route_map_no_match_ip_address_prefix_list_hook(generic_match_delete
);
6058 route_map_match_ip_next_hop_hook(generic_match_add
);
6059 route_map_no_match_ip_next_hop_hook(generic_match_delete
);
6061 route_map_match_ip_next_hop_prefix_list_hook(generic_match_add
);
6062 route_map_no_match_ip_next_hop_prefix_list_hook(generic_match_delete
);
6064 route_map_match_ip_next_hop_type_hook(generic_match_add
);
6065 route_map_no_match_ip_next_hop_type_hook(generic_match_delete
);
6067 route_map_match_ipv6_address_hook(generic_match_add
);
6068 route_map_no_match_ipv6_address_hook(generic_match_delete
);
6070 route_map_match_ipv6_address_prefix_list_hook(generic_match_add
);
6071 route_map_no_match_ipv6_address_prefix_list_hook(generic_match_delete
);
6073 route_map_match_ipv6_next_hop_type_hook(generic_match_add
);
6074 route_map_no_match_ipv6_next_hop_type_hook(generic_match_delete
);
6076 route_map_match_metric_hook(generic_match_add
);
6077 route_map_no_match_metric_hook(generic_match_delete
);
6079 route_map_match_tag_hook(generic_match_add
);
6080 route_map_no_match_tag_hook(generic_match_delete
);
6082 route_map_set_srte_color_hook(generic_set_add
);
6083 route_map_no_set_srte_color_hook(generic_set_delete
);
6085 route_map_set_ip_nexthop_hook(generic_set_add
);
6086 route_map_no_set_ip_nexthop_hook(generic_set_delete
);
6088 route_map_set_ipv6_nexthop_local_hook(generic_set_add
);
6089 route_map_no_set_ipv6_nexthop_local_hook(generic_set_delete
);
6091 route_map_set_metric_hook(generic_set_add
);
6092 route_map_no_set_metric_hook(generic_set_delete
);
6094 route_map_set_tag_hook(generic_set_add
);
6095 route_map_no_set_tag_hook(generic_set_delete
);
6097 route_map_install_match(&route_match_peer_cmd
);
6098 route_map_install_match(&route_match_local_pref_cmd
);
6099 #ifdef HAVE_SCRIPTING
6100 route_map_install_match(&route_match_script_cmd
);
6102 route_map_install_match(&route_match_ip_address_cmd
);
6103 route_map_install_match(&route_match_ip_next_hop_cmd
);
6104 route_map_install_match(&route_match_ip_route_source_cmd
);
6105 route_map_install_match(&route_match_ip_address_prefix_list_cmd
);
6106 route_map_install_match(&route_match_ip_next_hop_prefix_list_cmd
);
6107 route_map_install_match(&route_match_ip_next_hop_type_cmd
);
6108 route_map_install_match(&route_match_ip_route_source_prefix_list_cmd
);
6109 route_map_install_match(&route_match_aspath_cmd
);
6110 route_map_install_match(&route_match_community_cmd
);
6111 route_map_install_match(&route_match_lcommunity_cmd
);
6112 route_map_install_match(&route_match_ecommunity_cmd
);
6113 route_map_install_match(&route_match_local_pref_cmd
);
6114 route_map_install_match(&route_match_metric_cmd
);
6115 route_map_install_match(&route_match_origin_cmd
);
6116 route_map_install_match(&route_match_probability_cmd
);
6117 route_map_install_match(&route_match_interface_cmd
);
6118 route_map_install_match(&route_match_tag_cmd
);
6119 route_map_install_match(&route_match_mac_address_cmd
);
6120 route_map_install_match(&route_match_evpn_vni_cmd
);
6121 route_map_install_match(&route_match_evpn_route_type_cmd
);
6122 route_map_install_match(&route_match_evpn_rd_cmd
);
6123 route_map_install_match(&route_match_evpn_default_route_cmd
);
6124 route_map_install_match(&route_match_vrl_source_vrf_cmd
);
6126 route_map_install_set(&route_set_table_id_cmd
);
6127 route_map_install_set(&route_set_srte_color_cmd
);
6128 route_map_install_set(&route_set_ip_nexthop_cmd
);
6129 route_map_install_set(&route_set_local_pref_cmd
);
6130 route_map_install_set(&route_set_weight_cmd
);
6131 route_map_install_set(&route_set_label_index_cmd
);
6132 route_map_install_set(&route_set_metric_cmd
);
6133 route_map_install_set(&route_set_distance_cmd
);
6134 route_map_install_set(&route_set_aspath_prepend_cmd
);
6135 route_map_install_set(&route_set_aspath_exclude_cmd
);
6136 route_map_install_set(&route_set_origin_cmd
);
6137 route_map_install_set(&route_set_atomic_aggregate_cmd
);
6138 route_map_install_set(&route_set_aggregator_as_cmd
);
6139 route_map_install_set(&route_set_community_cmd
);
6140 route_map_install_set(&route_set_community_delete_cmd
);
6141 route_map_install_set(&route_set_lcommunity_cmd
);
6142 route_map_install_set(&route_set_lcommunity_delete_cmd
);
6143 route_map_install_set(&route_set_vpnv4_nexthop_cmd
);
6144 route_map_install_set(&route_set_vpnv6_nexthop_cmd
);
6145 route_map_install_set(&route_set_originator_id_cmd
);
6146 route_map_install_set(&route_set_ecommunity_rt_cmd
);
6147 route_map_install_set(&route_set_ecommunity_soo_cmd
);
6148 route_map_install_set(&route_set_ecommunity_lb_cmd
);
6149 route_map_install_set(&route_set_tag_cmd
);
6150 route_map_install_set(&route_set_label_index_cmd
);
6152 install_element(RMAP_NODE
, &match_peer_cmd
);
6153 install_element(RMAP_NODE
, &match_peer_local_cmd
);
6154 install_element(RMAP_NODE
, &no_match_peer_cmd
);
6155 install_element(RMAP_NODE
, &match_ip_route_source_cmd
);
6156 install_element(RMAP_NODE
, &no_match_ip_route_source_cmd
);
6157 install_element(RMAP_NODE
, &match_ip_route_source_prefix_list_cmd
);
6158 install_element(RMAP_NODE
, &no_match_ip_route_source_prefix_list_cmd
);
6159 install_element(RMAP_NODE
, &match_mac_address_cmd
);
6160 install_element(RMAP_NODE
, &no_match_mac_address_cmd
);
6161 install_element(RMAP_NODE
, &match_evpn_vni_cmd
);
6162 install_element(RMAP_NODE
, &no_match_evpn_vni_cmd
);
6163 install_element(RMAP_NODE
, &match_evpn_route_type_cmd
);
6164 install_element(RMAP_NODE
, &no_match_evpn_route_type_cmd
);
6165 install_element(RMAP_NODE
, &match_evpn_rd_cmd
);
6166 install_element(RMAP_NODE
, &no_match_evpn_rd_cmd
);
6167 install_element(RMAP_NODE
, &match_evpn_default_route_cmd
);
6168 install_element(RMAP_NODE
, &no_match_evpn_default_route_cmd
);
6169 install_element(RMAP_NODE
, &match_vrl_source_vrf_cmd
);
6170 install_element(RMAP_NODE
, &no_match_vrl_source_vrf_cmd
);
6172 install_element(RMAP_NODE
, &match_aspath_cmd
);
6173 install_element(RMAP_NODE
, &no_match_aspath_cmd
);
6174 install_element(RMAP_NODE
, &match_local_pref_cmd
);
6175 install_element(RMAP_NODE
, &no_match_local_pref_cmd
);
6176 install_element(RMAP_NODE
, &match_community_cmd
);
6177 install_element(RMAP_NODE
, &no_match_community_cmd
);
6178 install_element(RMAP_NODE
, &match_lcommunity_cmd
);
6179 install_element(RMAP_NODE
, &no_match_lcommunity_cmd
);
6180 install_element(RMAP_NODE
, &match_ecommunity_cmd
);
6181 install_element(RMAP_NODE
, &no_match_ecommunity_cmd
);
6182 install_element(RMAP_NODE
, &match_origin_cmd
);
6183 install_element(RMAP_NODE
, &no_match_origin_cmd
);
6184 install_element(RMAP_NODE
, &match_probability_cmd
);
6185 install_element(RMAP_NODE
, &no_match_probability_cmd
);
6187 install_element(RMAP_NODE
, &no_set_table_id_cmd
);
6188 install_element(RMAP_NODE
, &set_table_id_cmd
);
6189 install_element(RMAP_NODE
, &set_ip_nexthop_peer_cmd
);
6190 install_element(RMAP_NODE
, &set_ip_nexthop_unchanged_cmd
);
6191 install_element(RMAP_NODE
, &set_local_pref_cmd
);
6192 install_element(RMAP_NODE
, &set_distance_cmd
);
6193 install_element(RMAP_NODE
, &no_set_distance_cmd
);
6194 install_element(RMAP_NODE
, &no_set_local_pref_cmd
);
6195 install_element(RMAP_NODE
, &set_weight_cmd
);
6196 install_element(RMAP_NODE
, &set_label_index_cmd
);
6197 install_element(RMAP_NODE
, &no_set_weight_cmd
);
6198 install_element(RMAP_NODE
, &no_set_label_index_cmd
);
6199 install_element(RMAP_NODE
, &set_aspath_prepend_asn_cmd
);
6200 install_element(RMAP_NODE
, &set_aspath_prepend_lastas_cmd
);
6201 install_element(RMAP_NODE
, &set_aspath_exclude_cmd
);
6202 install_element(RMAP_NODE
, &no_set_aspath_prepend_cmd
);
6203 install_element(RMAP_NODE
, &no_set_aspath_prepend_lastas_cmd
);
6204 install_element(RMAP_NODE
, &no_set_aspath_exclude_cmd
);
6205 install_element(RMAP_NODE
, &no_set_aspath_exclude_all_cmd
);
6206 install_element(RMAP_NODE
, &set_origin_cmd
);
6207 install_element(RMAP_NODE
, &no_set_origin_cmd
);
6208 install_element(RMAP_NODE
, &set_atomic_aggregate_cmd
);
6209 install_element(RMAP_NODE
, &no_set_atomic_aggregate_cmd
);
6210 install_element(RMAP_NODE
, &set_aggregator_as_cmd
);
6211 install_element(RMAP_NODE
, &no_set_aggregator_as_cmd
);
6212 install_element(RMAP_NODE
, &set_community_cmd
);
6213 install_element(RMAP_NODE
, &set_community_none_cmd
);
6214 install_element(RMAP_NODE
, &no_set_community_cmd
);
6215 install_element(RMAP_NODE
, &no_set_community_short_cmd
);
6216 install_element(RMAP_NODE
, &set_community_delete_cmd
);
6217 install_element(RMAP_NODE
, &no_set_community_delete_cmd
);
6218 install_element(RMAP_NODE
, &set_lcommunity_cmd
);
6219 install_element(RMAP_NODE
, &set_lcommunity_none_cmd
);
6220 install_element(RMAP_NODE
, &no_set_lcommunity_cmd
);
6221 install_element(RMAP_NODE
, &no_set_lcommunity1_cmd
);
6222 install_element(RMAP_NODE
, &no_set_lcommunity1_short_cmd
);
6223 install_element(RMAP_NODE
, &set_lcommunity_delete_cmd
);
6224 install_element(RMAP_NODE
, &no_set_lcommunity_delete_cmd
);
6225 install_element(RMAP_NODE
, &no_set_lcommunity_delete_short_cmd
);
6226 install_element(RMAP_NODE
, &set_ecommunity_rt_cmd
);
6227 install_element(RMAP_NODE
, &no_set_ecommunity_rt_cmd
);
6228 install_element(RMAP_NODE
, &no_set_ecommunity_rt_short_cmd
);
6229 install_element(RMAP_NODE
, &set_ecommunity_soo_cmd
);
6230 install_element(RMAP_NODE
, &no_set_ecommunity_soo_cmd
);
6231 install_element(RMAP_NODE
, &no_set_ecommunity_soo_short_cmd
);
6232 install_element(RMAP_NODE
, &set_ecommunity_lb_cmd
);
6233 install_element(RMAP_NODE
, &no_set_ecommunity_lb_cmd
);
6234 install_element(RMAP_NODE
, &no_set_ecommunity_lb_short_cmd
);
6235 #ifdef KEEP_OLD_VPN_COMMANDS
6236 install_element(RMAP_NODE
, &set_vpn_nexthop_cmd
);
6237 install_element(RMAP_NODE
, &no_set_vpn_nexthop_cmd
);
6238 #endif /* KEEP_OLD_VPN_COMMANDS */
6239 install_element(RMAP_NODE
, &set_ipx_vpn_nexthop_cmd
);
6240 install_element(RMAP_NODE
, &no_set_ipx_vpn_nexthop_cmd
);
6241 install_element(RMAP_NODE
, &set_originator_id_cmd
);
6242 install_element(RMAP_NODE
, &no_set_originator_id_cmd
);
6244 route_map_install_match(&route_match_ipv6_address_cmd
);
6245 route_map_install_match(&route_match_ipv6_next_hop_cmd
);
6246 route_map_install_match(&route_match_ipv4_next_hop_cmd
);
6247 route_map_install_match(&route_match_ipv6_address_prefix_list_cmd
);
6248 route_map_install_match(&route_match_ipv6_next_hop_type_cmd
);
6249 route_map_install_set(&route_set_ipv6_nexthop_global_cmd
);
6250 route_map_install_set(&route_set_ipv6_nexthop_prefer_global_cmd
);
6251 route_map_install_set(&route_set_ipv6_nexthop_local_cmd
);
6252 route_map_install_set(&route_set_ipv6_nexthop_peer_cmd
);
6254 install_element(RMAP_NODE
, &match_ipv6_next_hop_cmd
);
6255 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_cmd
);
6256 install_element(RMAP_NODE
, &match_ipv4_next_hop_cmd
);
6257 install_element(RMAP_NODE
, &no_match_ipv4_next_hop_cmd
);
6258 install_element(RMAP_NODE
, &set_ipv6_nexthop_global_cmd
);
6259 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_global_cmd
);
6260 install_element(RMAP_NODE
, &set_ipv6_nexthop_prefer_global_cmd
);
6261 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_prefer_global_cmd
);
6262 install_element(RMAP_NODE
, &set_ipv6_nexthop_peer_cmd
);
6263 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_peer_cmd
);
6264 #ifdef HAVE_SCRIPTING
6265 install_element(RMAP_NODE
, &match_script_cmd
);
6269 void bgp_route_map_terminate(void)
6271 /* ToDo: Cleanup all the used memory */